0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
119
|
13 |
SimpleView subclass:#PullDownMenu
|
91
|
14 |
instanceVariableNames:'menus titles selectors activeMenuNumber
|
59
|
15 |
showSeparatingLines topMargin
|
|
16 |
fgColor bgColor activeFgColor activeBgColor
|
63
|
17 |
onLevel offLevel edgeStyle
|
110
|
18 |
keepMenu toggleKeep'
|
59
|
19 |
classVariableNames:'DefaultFont
|
|
20 |
DefaultViewBackground
|
|
21 |
DefaultForegroundColor
|
|
22 |
DefaultBackgroundColor
|
|
23 |
DefaultHilightForegroundColor
|
|
24 |
DefaultHilightBackgroundColor
|
|
25 |
DefaultLevel DefaultHilightLevel
|
63
|
26 |
DefaultShadowColor DefaultLightColor
|
110
|
27 |
DefaultEdgeStyle DefaultKeepMenu DefaultToggleKeep'
|
0
|
28 |
poolDictionaries:''
|
|
29 |
category:'Views-Menus'
|
|
30 |
!
|
|
31 |
|
|
32 |
PullDownMenu comment:'
|
5
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
34 |
All Rights Reserved
|
0
|
35 |
|
119
|
36 |
$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.17 1995-05-03 00:37:05 claus Exp $
|
3
|
37 |
'!
|
0
|
38 |
|
3
|
39 |
!PullDownMenu class methodsFor:'documentation'!
|
|
40 |
|
38
|
41 |
copyright
|
|
42 |
"
|
|
43 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
44 |
All Rights Reserved
|
38
|
45 |
|
|
46 |
This software is furnished under a license and may be used
|
|
47 |
only in accordance with the terms of that license and with the
|
|
48 |
inclusion of the above copyright notice. This software may not
|
|
49 |
be provided or otherwise made available to, or used by, any
|
|
50 |
other person. No title to or ownership of the software is
|
|
51 |
hereby transferred.
|
|
52 |
"
|
|
53 |
!
|
|
54 |
|
|
55 |
version
|
|
56 |
"
|
119
|
57 |
$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.17 1995-05-03 00:37:05 claus Exp $
|
38
|
58 |
"
|
|
59 |
!
|
|
60 |
|
3
|
61 |
documentation
|
|
62 |
"
|
38
|
63 |
PullDown menu provides the top (always visible) part of these menus.
|
|
64 |
It controls display of its menus, which become visible when one of the
|
|
65 |
PullDownMenus entries is pressed.
|
0
|
66 |
|
38
|
67 |
Instance variables:
|
0
|
68 |
|
110
|
69 |
menus <aCollection> the sub menus
|
|
70 |
titles <aCollection> the strings in the menu
|
|
71 |
activeMenuNumber <Number> the index of the currently active menu
|
|
72 |
showSeparatingLines <Boolean> show separating lines between my menu-strings
|
|
73 |
topMargin <Number> number of pixels at top
|
|
74 |
fgColor <Color> color to draw passive menu-titles
|
|
75 |
bgColor <Color> color to draw passive menu-titles
|
|
76 |
activeFgColor <Color> color to draw activated menu-titles
|
|
77 |
activeBgColor <Color> color to draw activated menu-titles
|
|
78 |
onLevel <Integer> level of entry-buttons when pressed
|
|
79 |
offLevel <Integer> level of entry-buttons when released
|
|
80 |
keepmenu <Boolean> if on, pulled menu stays on click,
|
|
81 |
till clicked again (motif & windows behavior)
|
77
|
82 |
|
|
83 |
|
|
84 |
StyleSheet values:
|
|
85 |
|
110
|
86 |
pullDownMenuViewBackground view background Color for the menu bar
|
|
87 |
default: menuViewBackground
|
|
88 |
|
|
89 |
pullDownMenuForegroundColor foreground drawing color for the menu bar
|
|
90 |
default: menuForegroundColor
|
|
91 |
|
|
92 |
pullDownMenuBackgroundColor background drawing color for the menu bar
|
|
93 |
default: menuBackgroundColor
|
|
94 |
|
|
95 |
pullDownMenuHilightForegroundColor active foreground drawing color for the menu bar
|
|
96 |
default: menuHilightForegroundColor
|
|
97 |
|
|
98 |
pullDownMenuHilightBackgroundColor active background drawing color for the menu bar
|
|
99 |
default: menuHilightBackgroundColor
|
|
100 |
|
|
101 |
pullDownMenuHilightLevel level (3D only) when active
|
|
102 |
default: menuHilightLevel
|
77
|
103 |
|
110
|
104 |
pullDownMenuEdgeStyle edge style (nil or #soft)
|
|
105 |
|
|
106 |
pullDownMenuKeepMenu if true, pulled menu stays open until button
|
|
107 |
is pressed again (motif behavior)
|
|
108 |
if false, menu closes on release (default)
|
|
109 |
|
|
110 |
pullDownMenuToggleKeep if true, pulled menu closes when an entry is pressed
|
|
111 |
again. Otherwise, only press outside outside of
|
|
112 |
the entry hides it.
|
|
113 |
default is false
|
|
114 |
|
|
115 |
pullDownMenuLevel level (3D only)
|
|
116 |
|
|
117 |
pullDownMenuFont font to use for the menu bar
|
|
118 |
default: menuFont
|
|
119 |
"
|
|
120 |
!
|
77
|
121 |
|
110
|
122 |
examples
|
|
123 |
"
|
|
124 |
|top menu|
|
|
125 |
|
|
126 |
top := StandardSystemView new.
|
|
127 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
128 |
menu labels:#('foo' 'bar').
|
|
129 |
menu selectors:#(foo bar).
|
|
130 |
menu at:#foo
|
|
131 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
132 |
selectors:#(foo1 foo2 foo3)
|
|
133 |
receiver:nil.
|
|
134 |
menu at:#bar
|
|
135 |
putLabels:#('bar1' 'bar2' 'bar3')
|
|
136 |
selectors:#(bar1 bar2 bar3)
|
|
137 |
receiver:nil.
|
|
138 |
top open
|
|
139 |
|
|
140 |
|
77
|
141 |
|
110
|
142 |
'empty entries are possible ...'
|
|
143 |
|
|
144 |
|top menu|
|
|
145 |
|
|
146 |
top := StandardSystemView new.
|
|
147 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
148 |
menu labels:#('foo' 'bar').
|
|
149 |
menu selectors:#(foo bar).
|
|
150 |
menu at:#foo
|
|
151 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
152 |
selectors:#(foo1 foo2 foo3)
|
|
153 |
receiver:nil.
|
|
154 |
top open
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
'... for example as separators'
|
|
159 |
|
|
160 |
|top menu|
|
77
|
161 |
|
110
|
162 |
top := StandardSystemView new.
|
|
163 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
164 |
menu labels:#('foo' ' ' 'bar' ' baz' ' ' 'moreFoo' 'moreBar' 'moreBaz').
|
|
165 |
menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
|
|
166 |
menu showSeparatingLines:true.
|
|
167 |
menu at:#foo
|
|
168 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
169 |
selectors:#(foo1 foo2 foo3)
|
|
170 |
receiver:nil.
|
|
171 |
menu at:#bar
|
|
172 |
putLabels:#('bar1' 'bar2' 'bar3')
|
|
173 |
selectors:#(bar1 bar2 bar3)
|
|
174 |
receiver:nil.
|
|
175 |
menu at:#baz
|
|
176 |
putLabels:#('baz1' 'baz2' 'baz3')
|
|
177 |
selectors:#(baz1 baz2 baz3)
|
|
178 |
receiver:nil.
|
|
179 |
top open
|
|
180 |
|
77
|
181 |
|
110
|
182 |
|
|
183 |
|
|
184 |
'use menus default height'
|
|
185 |
|
|
186 |
|top menu|
|
77
|
187 |
|
110
|
188 |
top := StandardSystemView new.
|
|
189 |
menu := PullDownMenu in:top.
|
|
190 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
191 |
menu labels:#('foo' 'bar').
|
|
192 |
menu selectors:#(foo bar).
|
|
193 |
menu at:#foo
|
|
194 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
195 |
selectors:#(foo1 foo2 foo3)
|
|
196 |
receiver:nil.
|
|
197 |
top open
|
|
198 |
|
|
199 |
|
|
200 |
|
77
|
201 |
|
110
|
202 |
'although you can change the font, colors etc (as shown below)
|
|
203 |
you should NOT do it - since if you do so, the styleSheet settings
|
|
204 |
are ineffective (which users wont like probably)
|
|
205 |
BTW: The styleSheet entries for below are pullDownMenuForegroundColor,
|
|
206 |
pullDownMenuBackgroundColor and pullDownMenuFont'
|
|
207 |
|
|
208 |
|top menu|
|
|
209 |
|
|
210 |
top := StandardSystemView new.
|
|
211 |
menu := PullDownMenu in:top.
|
|
212 |
menu font:(Font family:'courier' size:20).
|
|
213 |
menu foregroundColor:Color red.
|
|
214 |
menu backgroundColor:Color yellow.
|
|
215 |
menu viewBackground:Color yellow.
|
|
216 |
menu showSeparatingLines:true.
|
77
|
217 |
|
110
|
218 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
219 |
menu labels:#('foo' 'bar').
|
|
220 |
menu selectors:#(foo bar).
|
|
221 |
menu at:#foo
|
|
222 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
223 |
selectors:#(foo1 foo2 foo3)
|
|
224 |
receiver:nil.
|
|
225 |
(menu menuAt:#foo) font:(Font family:'courier' size:36).
|
|
226 |
top open
|
|
227 |
|
|
228 |
|
|
229 |
|
|
230 |
'you can use icons, too ...'
|
|
231 |
|
|
232 |
|labels top menu|
|
77
|
233 |
|
110
|
234 |
top := StandardSystemView new.
|
|
235 |
menu := PullDownMenu in:top.
|
|
236 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
237 |
labels := Array with:(Image fromFile:'SmalltalkX.xbm')
|
|
238 |
with:'foo'
|
|
239 |
with:'bar'.
|
|
240 |
menu labels:labels.
|
|
241 |
menu selectors:#(about foo bar).
|
|
242 |
menu at:#about
|
|
243 |
putLabels:#('about PullDownMenus')
|
|
244 |
selectors:#(aboutMenus)
|
|
245 |
receiver:nil.
|
|
246 |
menu at:#foo
|
|
247 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
248 |
selectors:#(foo1 foo2 foo3)
|
|
249 |
receiver:nil.
|
|
250 |
top open
|
3
|
251 |
"
|
|
252 |
! !
|
0
|
253 |
|
59
|
254 |
!PullDownMenu class methodsFor:'defaults'!
|
|
255 |
|
|
256 |
updateStyleCache
|
110
|
257 |
"extract values from the styleSheet and cache them in class variables"
|
|
258 |
|
60
|
259 |
DefaultViewBackground := StyleSheet colorAt:'pullDownMenuViewBackground'.
|
|
260 |
DefaultViewBackground isNil ifTrue:[
|
|
261 |
DefaultViewBackground := StyleSheet colorAt:'menuViewBackground'.
|
59
|
262 |
].
|
60
|
263 |
DefaultForegroundColor := StyleSheet colorAt:'pullDownMenuForegroundColor'.
|
|
264 |
DefaultForegroundColor isNil ifTrue:[
|
|
265 |
DefaultForegroundColor := StyleSheet colorAt:'menuForegroundColor'.
|
|
266 |
].
|
|
267 |
DefaultBackgroundColor := StyleSheet colorAt:'pullDownMenuBackgroundColor'.
|
|
268 |
DefaultBackgroundColor isNil ifTrue:[
|
77
|
269 |
DefaultViewBackground notNil ifTrue:[
|
|
270 |
DefaultBackgroundColor := DefaultViewBackground
|
|
271 |
] ifFalse:[
|
|
272 |
DefaultBackgroundColor := StyleSheet colorAt:'menuBackgroundColor'.
|
|
273 |
]
|
59
|
274 |
].
|
60
|
275 |
DefaultHilightForegroundColor := StyleSheet colorAt:'pullDownMenuHilightForegroundColor'.
|
|
276 |
DefaultHilightForegroundColor isNil ifTrue:[
|
|
277 |
DefaultHilightForegroundColor := StyleSheet colorAt:'menuHilightForegroundColor'.
|
59
|
278 |
].
|
60
|
279 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'pullDownMenuHilightBackgroundColor'.
|
|
280 |
DefaultHilightBackgroundColor isNil ifTrue:[
|
|
281 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'menuHilightBackgroundColor'.
|
59
|
282 |
].
|
60
|
283 |
DefaultHilightLevel := StyleSheet at:'pullDownMenuHilightLevel'.
|
|
284 |
DefaultHilightLevel isNil ifTrue:[
|
|
285 |
DefaultHilightLevel := StyleSheet at:'menuHilightLevel' default:0.
|
59
|
286 |
].
|
63
|
287 |
DefaultEdgeStyle := StyleSheet at:'pullDownMenuEdgeStyle'.
|
77
|
288 |
DefaultKeepMenu := StyleSheet at:'pullDownMenuKeepMenu' default:false.
|
110
|
289 |
DefaultToggleKeep := StyleSheet at:'pullDownMenuToggleKeep' default:false.
|
60
|
290 |
DefaultLevel := StyleSheet at:'pullDownMenuLevel' default:1.
|
|
291 |
DefaultFont := StyleSheet fontAt:'pullDownMenuFont'.
|
|
292 |
DefaultFont isNil ifTrue:[
|
|
293 |
DefaultFont := StyleSheet fontAt:'menuFont'.
|
59
|
294 |
].
|
110
|
295 |
|
|
296 |
"
|
|
297 |
PullDownMenu updateStyleCache
|
|
298 |
"
|
59
|
299 |
! !
|
|
300 |
|
0
|
301 |
!PullDownMenu class methodsFor:'instance creation'!
|
|
302 |
|
|
303 |
labels:titleArray
|
|
304 |
"create and return a new PullDownMenu"
|
|
305 |
|
|
306 |
^ self new labels:titleArray
|
|
307 |
! !
|
|
308 |
|
77
|
309 |
!PullDownMenu methodsFor:'initialize / release'!
|
0
|
310 |
|
|
311 |
initialize
|
|
312 |
super initialize.
|
|
313 |
|
|
314 |
font := font on:device.
|
|
315 |
self origin:(0.0 @ 0.0)
|
59
|
316 |
extent:(1.0 @ (font height + (font descent * 2) + topMargin)).
|
0
|
317 |
!
|
|
318 |
|
|
319 |
initStyle
|
|
320 |
super initStyle.
|
|
321 |
|
|
322 |
showSeparatingLines := false.
|
59
|
323 |
DefaultViewBackground notNil ifTrue:[
|
60
|
324 |
viewBackground := DefaultViewBackground on:device
|
59
|
325 |
].
|
|
326 |
|
60
|
327 |
DefaultFont notNil ifTrue:[
|
|
328 |
font := DefaultFont on:device
|
|
329 |
].
|
59
|
330 |
DefaultForegroundColor notNil ifTrue:[
|
|
331 |
fgColor := DefaultForegroundColor
|
|
332 |
] ifFalse:[
|
|
333 |
fgColor := Black.
|
|
334 |
].
|
|
335 |
DefaultBackgroundColor notNil ifTrue:[
|
|
336 |
bgColor := DefaultBackgroundColor
|
|
337 |
] ifFalse:[
|
|
338 |
bgColor := viewBackground.
|
|
339 |
].
|
|
340 |
onLevel := DefaultHilightLevel.
|
|
341 |
offLevel := DefaultLevel.
|
21
|
342 |
|
0
|
343 |
self is3D ifTrue:[
|
59
|
344 |
device hasColors ifTrue:[
|
|
345 |
activeFgColor := Color name:'yellow'
|
|
346 |
] ifFalse:[
|
|
347 |
activeFgColor := White
|
|
348 |
].
|
|
349 |
device hasGreyscales ifTrue:[
|
|
350 |
activeBgColor := bgColor.
|
|
351 |
] ifFalse:[
|
|
352 |
activeBgColor := fgColor.
|
|
353 |
].
|
|
354 |
topMargin := 2.
|
21
|
355 |
|
77
|
356 |
((StyleSheet name == #iris) or:[StyleSheet name == #motif]) ifTrue:[
|
59
|
357 |
self level:2.
|
|
358 |
onLevel := 2.
|
|
359 |
offLevel := 0.
|
|
360 |
activeFgColor := fgColor
|
|
361 |
]
|
0
|
362 |
] ifFalse:[
|
59
|
363 |
activeFgColor := bgColor.
|
|
364 |
activeBgColor := fgColor.
|
|
365 |
topMargin := 0
|
|
366 |
].
|
|
367 |
|
63
|
368 |
edgeStyle := DefaultEdgeStyle.
|
|
369 |
keepMenu := DefaultKeepMenu.
|
110
|
370 |
toggleKeep := DefaultToggleKeep.
|
63
|
371 |
|
59
|
372 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
373 |
activeFgColor := DefaultHilightForegroundColor
|
|
374 |
].
|
|
375 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
376 |
activeBgColor := DefaultHilightBackgroundColor
|
0
|
377 |
].
|
59
|
378 |
DefaultShadowColor notNil ifTrue:[
|
|
379 |
shadowColor := DefaultShadowColor on:device
|
|
380 |
].
|
|
381 |
DefaultLightColor notNil ifTrue:[
|
|
382 |
lightColor := DefaultLightColor on:device
|
|
383 |
].
|
|
384 |
|
|
385 |
bgColor := bgColor on:device.
|
|
386 |
fgColor := fgColor on:device.
|
|
387 |
activeBgColor := activeBgColor on:device.
|
|
388 |
activeFgColor := activeFgColor on:device.
|
0
|
389 |
!
|
|
390 |
|
|
391 |
recreate
|
115
|
392 |
"if saved with an active menu, hide it"
|
|
393 |
|
|
394 |
activeMenuNumber notNil ifTrue:[
|
|
395 |
(menus at:activeMenuNumber) unrealize.
|
|
396 |
activeMenuNumber := nil.
|
|
397 |
].
|
|
398 |
super recreate.
|
0
|
399 |
self setMenuOrigins
|
|
400 |
!
|
|
401 |
|
|
402 |
create
|
|
403 |
super create.
|
|
404 |
self setMenuOrigins
|
77
|
405 |
!
|
|
406 |
|
|
407 |
destroy
|
|
408 |
"
|
|
409 |
have to destroy the menus manually here,
|
|
410 |
since they are no real subviews of myself
|
|
411 |
"
|
|
412 |
menus notNil ifTrue:[
|
|
413 |
menus do:[:m |
|
|
414 |
m notNil ifTrue:[m destroy]
|
|
415 |
].
|
|
416 |
menus := nil
|
110
|
417 |
].
|
115
|
418 |
activeMenuNumber := nil.
|
|
419 |
super destroy.
|
0
|
420 |
! !
|
|
421 |
|
|
422 |
!PullDownMenu methodsFor:'accessing'!
|
|
423 |
|
|
424 |
showSeparatingLines:aBoolean
|
|
425 |
"turn on/off drawing of separating lines"
|
|
426 |
|
|
427 |
showSeparatingLines := aBoolean.
|
|
428 |
shown ifTrue:[
|
59
|
429 |
self redraw
|
0
|
430 |
]
|
|
431 |
!
|
|
432 |
|
|
433 |
numberOfTitles:n
|
|
434 |
"setup blank title-space to be filled in later"
|
|
435 |
|
|
436 |
menus := Array new:n.
|
|
437 |
titles := Array new:n
|
|
438 |
!
|
|
439 |
|
|
440 |
labels:titleArray
|
|
441 |
"define the menu-titles (group-headers)"
|
|
442 |
|
|
443 |
|numberOfLabels|
|
|
444 |
|
|
445 |
numberOfLabels := titleArray size.
|
|
446 |
menus := Array new:numberOfLabels.
|
|
447 |
titles := Array new:numberOfLabels.
|
110
|
448 |
|
|
449 |
titleArray keysAndValuesDo:[:index :entry |
|
|
450 |
|e|
|
|
451 |
|
|
452 |
entry isImage ifTrue:[
|
|
453 |
e := entry on:device
|
|
454 |
] ifFalse:[
|
|
455 |
e := entry printString
|
|
456 |
].
|
|
457 |
titles at:index put:e
|
0
|
458 |
].
|
|
459 |
shown ifTrue:[
|
59
|
460 |
self clear.
|
|
461 |
self redraw
|
0
|
462 |
]
|
|
463 |
!
|
|
464 |
|
|
465 |
labels
|
|
466 |
"return the menu-titles (group-headers)"
|
|
467 |
|
|
468 |
^ titles
|
|
469 |
!
|
|
470 |
|
91
|
471 |
selectors:selectorArray
|
|
472 |
"define the menu-selectors. These are used as accesskey only
|
|
473 |
in menuAt: accesses. This makes PullDownMenu accesss
|
|
474 |
somewhat more compatible to PopUpMenus."
|
|
475 |
|
|
476 |
selectors := selectorArray.
|
|
477 |
!
|
|
478 |
|
0
|
479 |
font:aFont
|
|
480 |
"adjust menu-origins when font changes"
|
|
481 |
|
3
|
482 |
super font:(aFont on:device).
|
|
483 |
self height:(font height + (font descent * 2)).
|
110
|
484 |
shown ifTrue:[
|
|
485 |
self setMenuOrigins
|
|
486 |
]
|
|
487 |
!
|
|
488 |
|
|
489 |
foregroundColor:aColor
|
|
490 |
fgColor := aColor on:device
|
|
491 |
!
|
|
492 |
|
|
493 |
backgroundColor:aColor
|
|
494 |
bgColor := aColor on:device
|
0
|
495 |
!
|
|
496 |
|
|
497 |
menuAt:string
|
|
498 |
"return the menu with the title; return nil if not found"
|
|
499 |
|
|
500 |
|index|
|
|
501 |
|
|
502 |
index := self indexOf:string.
|
|
503 |
(index == 0) ifTrue:[^ nil].
|
|
504 |
^ menus at:index
|
|
505 |
!
|
|
506 |
|
|
507 |
at:aString putMenu:aMenu
|
|
508 |
"set the menu under the title, aString"
|
|
509 |
|
|
510 |
|index|
|
|
511 |
|
|
512 |
index := self indexOf:aString.
|
|
513 |
(index == 0) ifTrue:[^ nil].
|
112
|
514 |
|
|
515 |
"/ not needed:
|
|
516 |
"/ aMenu origin:((left + (self titleLenUpTo:index))
|
|
517 |
"/ @
|
|
518 |
"/ (height + aMenu borderWidth)).
|
0
|
519 |
aMenu hidden:true.
|
77
|
520 |
menus at:index put:aMenu.
|
|
521 |
aMenu masterView:self.
|
0
|
522 |
!
|
|
523 |
|
|
524 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject
|
|
525 |
"create and set the menu under the title, aString"
|
|
526 |
|
|
527 |
|menuView|
|
|
528 |
|
|
529 |
menuView := MenuView labels:labels
|
59
|
530 |
selectors:selectors
|
|
531 |
args:args
|
|
532 |
receiver:anObject
|
|
533 |
for:self.
|
0
|
534 |
self at:aString putMenu:menuView
|
|
535 |
!
|
|
536 |
|
|
537 |
at:aString putLabels:labels selector:selector args:args receiver:anObject
|
|
538 |
"create and set the menu under the title, aString"
|
|
539 |
|
|
540 |
|menuView|
|
|
541 |
|
|
542 |
menuView := MenuView labels:labels
|
59
|
543 |
selector:selector
|
|
544 |
args:args
|
|
545 |
receiver:anObject
|
|
546 |
for:self.
|
0
|
547 |
self at:aString putMenu:menuView
|
|
548 |
!
|
|
549 |
|
|
550 |
at:aString putLabels:labels selectors:selectors receiver:anObject
|
|
551 |
"create and set the menu under the title, aString"
|
|
552 |
|
|
553 |
|menuView|
|
|
554 |
|
|
555 |
menuView := MenuView labels:labels
|
59
|
556 |
selectors:selectors
|
|
557 |
receiver:anObject
|
|
558 |
for:self.
|
0
|
559 |
self at:aString putMenu:menuView
|
|
560 |
! !
|
|
561 |
|
|
562 |
!PullDownMenu methodsFor:'private'!
|
|
563 |
|
|
564 |
titleLenUpTo:index
|
110
|
565 |
"answer len (in pixels) of all title-strings up-to
|
|
566 |
(but excluding) title-index. Used to compute x-position when drawing
|
|
567 |
individual entries."
|
0
|
568 |
|
110
|
569 |
|len "{ Class: SmallInteger }"
|
|
570 |
wSpace wSep|
|
0
|
571 |
|
|
572 |
(index <= 1) ifTrue:[^ 0].
|
110
|
573 |
wSpace := (font widthOf:' ').
|
|
574 |
showSeparatingLines ifTrue:[
|
|
575 |
self is3D ifTrue:[
|
|
576 |
wSep := 2
|
|
577 |
] ifFalse:[
|
|
578 |
wSep := 1
|
|
579 |
]
|
|
580 |
] ifFalse:[
|
|
581 |
wSep := 0
|
|
582 |
].
|
|
583 |
|
0
|
584 |
len := 0.
|
110
|
585 |
titles from:1 to:(index - 1) do:[:entry |
|
|
586 |
|thisLength|
|
|
587 |
|
|
588 |
entry isString ifTrue:[
|
|
589 |
thisLength := (font widthOf:entry).
|
|
590 |
] ifFalse:[
|
|
591 |
thisLength := entry width
|
|
592 |
].
|
|
593 |
len := len + thisLength + wSpace + wSep + wSpace.
|
0
|
594 |
].
|
|
595 |
^ len
|
|
596 |
!
|
|
597 |
|
|
598 |
indexOf:stringOrNumber
|
91
|
599 |
"return the index of the menu with title; return 0 if not found.
|
|
600 |
stringOrNumber may be a number, a selector from the selectorArray
|
|
601 |
or a string from the title array."
|
|
602 |
|
|
603 |
|idx|
|
0
|
604 |
|
91
|
605 |
stringOrNumber isNumber ifTrue:[
|
59
|
606 |
^ stringOrNumber
|
0
|
607 |
].
|
91
|
608 |
selectors notNil ifTrue:[
|
|
609 |
idx := selectors indexOf:stringOrNumber.
|
|
610 |
idx ~~ 0 ifTrue:[^ idx].
|
|
611 |
].
|
0
|
612 |
^ titles indexOf:stringOrNumber
|
|
613 |
!
|
|
614 |
|
|
615 |
setMenuOrigins
|
|
616 |
"adjust origins of menus when font changes"
|
|
617 |
|
|
618 |
(font device == device) ifTrue:[
|
119
|
619 |
menus keysAndValuesDo:[:index :aMenu |
|
59
|
620 |
aMenu notNil ifTrue:[
|
|
621 |
aMenu origin:((left + (self titleLenUpTo:index))
|
|
622 |
@
|
|
623 |
(height + aMenu borderWidth))
|
|
624 |
].
|
|
625 |
]
|
0
|
626 |
]
|
110
|
627 |
!
|
|
628 |
|
|
629 |
titleIndexForX:x
|
|
630 |
"given a click x-position, return index in title or nil"
|
|
631 |
|
|
632 |
|xstart "{ Class: SmallInteger }"
|
|
633 |
xend "{ Class: SmallInteger }"
|
|
634 |
wSpace wSep|
|
|
635 |
|
|
636 |
wSpace := (font widthOf:' ') * 2.
|
|
637 |
showSeparatingLines ifTrue:[
|
|
638 |
self is3D ifTrue:[
|
|
639 |
wSep := 2
|
|
640 |
] ifFalse:[
|
|
641 |
wSep := 1
|
|
642 |
]
|
|
643 |
] ifFalse:[
|
|
644 |
wSep := 0
|
|
645 |
].
|
|
646 |
xstart := 0.
|
|
647 |
1 to:(titles size) do:[:index |
|
|
648 |
|entry thisLength|
|
|
649 |
|
|
650 |
entry := titles at:index.
|
|
651 |
entry isString ifTrue:[
|
|
652 |
thisLength := font widthOf:entry.
|
|
653 |
] ifFalse:[
|
|
654 |
thisLength := entry width
|
|
655 |
].
|
|
656 |
xend := xstart + thisLength + wSpace + wSep.
|
|
657 |
(x between:xstart and:xend) ifTrue:[^ index].
|
|
658 |
xstart := xend
|
|
659 |
].
|
|
660 |
^ nil
|
0
|
661 |
! !
|
|
662 |
|
|
663 |
!PullDownMenu methodsFor:'hiding/showing menus'!
|
|
664 |
|
110
|
665 |
hideActiveMenuRelease:aBoolean
|
|
666 |
"hide currently active menu - release grab if aBoolean is true
|
|
667 |
and a grab was set (keepMenu)"
|
|
668 |
|
|
669 |
activeMenuNumber notNil ifTrue:[
|
|
670 |
(menus at:activeMenuNumber) unrealize.
|
|
671 |
self unHighlightActiveTitle.
|
|
672 |
activeMenuNumber := nil
|
|
673 |
].
|
|
674 |
aBoolean ifTrue:[
|
|
675 |
device ungrabPointer.
|
|
676 |
self cursor:Cursor normal
|
|
677 |
].
|
|
678 |
!
|
|
679 |
|
|
680 |
hideActiveMenu
|
|
681 |
"hide currently active menu - release grab if there is any grab (keepMenu)"
|
|
682 |
|
|
683 |
^ self hideActiveMenuRelease:true
|
|
684 |
!
|
|
685 |
|
|
686 |
pullMenu:aNumber
|
|
687 |
"activate a menu, return it or nil"
|
|
688 |
|
|
689 |
|subMenu|
|
|
690 |
|
|
691 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
|
|
692 |
subMenu := menus at:aNumber.
|
|
693 |
subMenu notNil ifTrue:[
|
|
694 |
activeMenuNumber := aNumber.
|
|
695 |
self highlightActiveTitle.
|
|
696 |
subMenu deselect.
|
|
697 |
subMenu create.
|
|
698 |
subMenu saveUnder:true.
|
|
699 |
subMenu superMenu:self.
|
|
700 |
subMenu raise show
|
|
701 |
].
|
|
702 |
^ subMenu
|
|
703 |
!
|
|
704 |
|
|
705 |
regainControl
|
|
706 |
keepMenu ifTrue:[
|
|
707 |
device grabPointerInView:self.
|
|
708 |
self cursor:Cursor upRightArrow
|
|
709 |
]
|
|
710 |
! !
|
|
711 |
|
|
712 |
!PullDownMenu methodsFor:'drawing '!
|
0
|
713 |
|
110
|
714 |
redraw
|
|
715 |
|string
|
|
716 |
x "{ Class: SmallInteger }"
|
|
717 |
y "{ Class: SmallInteger }"
|
|
718 |
index "{ Class: SmallInteger }"
|
|
719 |
wSpace|
|
|
720 |
|
|
721 |
shown ifFalse: [ ^ self ].
|
|
722 |
titles isNil ifTrue:[^ self].
|
|
723 |
|
|
724 |
wSpace := (font widthOf:' ').
|
|
725 |
x := 0.
|
|
726 |
y := height "- 1".
|
|
727 |
index := 1.
|
|
728 |
titles do:[:title |
|
|
729 |
self drawTitle:title x:x selected:(index == activeMenuNumber).
|
|
730 |
|
|
731 |
title isString ifTrue:[
|
|
732 |
x := x + (font widthOf:title).
|
|
733 |
] ifFalse:[
|
|
734 |
x := x + title width
|
|
735 |
].
|
|
736 |
x := x + wSpace + wSpace.
|
|
737 |
showSeparatingLines ifTrue:[
|
|
738 |
self is3D ifTrue:[
|
|
739 |
self paint:shadowColor.
|
|
740 |
self displayLineFromX:x y:0 toX:x y:y.
|
|
741 |
x := x + 1.
|
|
742 |
self paint:lightColor.
|
|
743 |
] ifFalse:[
|
|
744 |
self paint:fgColor.
|
|
745 |
].
|
|
746 |
self displayLineFromX:x y:0 toX:x y:y.
|
|
747 |
x := x + 1
|
|
748 |
].
|
|
749 |
index := index + 1
|
|
750 |
]
|
|
751 |
!
|
|
752 |
|
|
753 |
drawTitle:stringOrImage x:x0 selected:selected
|
|
754 |
|y w x wSpace|
|
|
755 |
|
|
756 |
wSpace := font widthOf:' '.
|
|
757 |
x := x0.
|
|
758 |
stringOrImage isString ifTrue:[
|
|
759 |
y := ((height - (font height)) // 2) + (font ascent) "+ topMargin".
|
|
760 |
w := font widthOf:stringOrImage.
|
|
761 |
] ifFalse:[
|
|
762 |
y := ((height - stringOrImage height) // 2) max:0.
|
|
763 |
w := stringOrImage width
|
|
764 |
].
|
|
765 |
w := w + (wSpace * 2).
|
|
766 |
|
0
|
767 |
selected ifTrue:[
|
59
|
768 |
self paint:activeBgColor
|
0
|
769 |
] ifFalse:[
|
59
|
770 |
self paint:bgColor
|
0
|
771 |
].
|
|
772 |
self fillRectangleX:x y:0 width:w height:height.
|
|
773 |
|
|
774 |
self is3D ifTrue:[
|
59
|
775 |
self drawEdgesForX:x y:0
|
|
776 |
width:w
|
|
777 |
height:height
|
|
778 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel])
|
0
|
779 |
].
|
|
780 |
selected ifTrue:[
|
59
|
781 |
self paint:activeFgColor
|
0
|
782 |
] ifFalse:[
|
59
|
783 |
self paint:fgColor
|
0
|
784 |
].
|
110
|
785 |
x := x + wSpace.
|
|
786 |
stringOrImage isString ifTrue:[
|
|
787 |
self displayString:stringOrImage x:x y:y
|
|
788 |
] ifFalse:[
|
|
789 |
self displayForm:stringOrImage x:x y:y
|
|
790 |
]
|
0
|
791 |
!
|
|
792 |
|
|
793 |
highlightActiveTitle
|
110
|
794 |
|x|
|
0
|
795 |
activeMenuNumber notNil ifTrue:[
|
59
|
796 |
x := self titleLenUpTo:activeMenuNumber.
|
110
|
797 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:true
|
0
|
798 |
]
|
|
799 |
!
|
|
800 |
|
|
801 |
unHighlightActiveTitle
|
110
|
802 |
|x|
|
0
|
803 |
activeMenuNumber notNil ifTrue:[
|
59
|
804 |
x := self titleLenUpTo:activeMenuNumber.
|
110
|
805 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:false
|
0
|
806 |
]
|
110
|
807 |
! !
|
0
|
808 |
|
110
|
809 |
!PullDownMenu methodsFor:'submenu notifications'!
|
0
|
810 |
|
110
|
811 |
showActive
|
|
812 |
"sent by a submenu to tell me that it started to perform
|
|
813 |
its menu action"
|
38
|
814 |
!
|
|
815 |
|
110
|
816 |
showPassive
|
|
817 |
"sent by a submenu to tell me that it finished its menu-action."
|
0
|
818 |
|
110
|
819 |
self hideActiveMenu
|
77
|
820 |
!
|
|
821 |
|
110
|
822 |
submenuTriggered
|
|
823 |
"sent by a sub-submenu to tell me that it finished its menu-action."
|
|
824 |
|
|
825 |
self showPassive
|
0
|
826 |
! !
|
|
827 |
|
70
|
828 |
!PullDownMenu methodsFor:'event handling'!
|
0
|
829 |
|
112
|
830 |
keyPress:key x:x y:y
|
|
831 |
|index m|
|
|
832 |
|
|
833 |
"
|
|
834 |
handle CursorLeft/Right for non-mouse operation
|
|
835 |
(once it has the explicit focus)
|
|
836 |
"
|
|
837 |
((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[
|
|
838 |
activeMenuNumber isNil ifTrue:[
|
|
839 |
index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size].
|
|
840 |
] ifFalse:[
|
|
841 |
(key == #CursorRight) ifTrue:[
|
|
842 |
index := activeMenuNumber+1
|
|
843 |
] ifFalse:[
|
|
844 |
index := activeMenuNumber-1
|
|
845 |
].
|
|
846 |
index == 0 ifTrue:[index := menus size]
|
|
847 |
ifFalse:[
|
|
848 |
index > menus size ifTrue:[index := 1]
|
|
849 |
]
|
|
850 |
].
|
|
851 |
m := self pullMenu:index.
|
|
852 |
^ self
|
|
853 |
].
|
|
854 |
|
|
855 |
activeMenuNumber isNil ifTrue:[^self].
|
|
856 |
|
|
857 |
"
|
|
858 |
pass it on to the active menu
|
|
859 |
"
|
|
860 |
m := menus at:activeMenuNumber.
|
|
861 |
m keyPress:key x:0 y:0.
|
|
862 |
^ self
|
|
863 |
!
|
|
864 |
|
110
|
865 |
buttonPress:button x:x y:y
|
|
866 |
|titleIndex activeMenu activeLeft activeTop m|
|
0
|
867 |
|
110
|
868 |
device ungrabPointer.
|
38
|
869 |
|
|
870 |
(y between:0 and:height) ifTrue:[
|
59
|
871 |
titleIndex := self titleIndexForX:x.
|
38
|
872 |
].
|
0
|
873 |
|
38
|
874 |
"
|
|
875 |
now, titleIndex is non-nil if pressed within myself
|
|
876 |
"
|
|
877 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
|
110
|
878 |
m := self pullMenu:titleIndex.
|
|
879 |
(keepMenu and:[m notNil]) ifTrue:[
|
77
|
880 |
device grabPointerInView:self.
|
59
|
881 |
self cursor:Cursor upRightArrow
|
|
882 |
]
|
38
|
883 |
] ifFalse:[
|
110
|
884 |
(keepMenu and:[toggleKeep not]) ifTrue:[
|
59
|
885 |
titleIndex == activeMenuNumber ifTrue:[
|
|
886 |
"same pressed again ... stay"
|
110
|
887 |
device grabPointerInView:self.
|
59
|
888 |
^ self
|
|
889 |
].
|
|
890 |
"moving around below"
|
|
891 |
activeMenuNumber isNil ifTrue:[^self].
|
|
892 |
activeMenu := menus at:activeMenuNumber.
|
|
893 |
activeLeft := activeMenu left.
|
|
894 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
895 |
activeTop := activeMenu top.
|
|
896 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
897 |
"moving around in menu"
|
|
898 |
activeMenu buttonPress:button
|
|
899 |
x:(x - activeLeft)
|
|
900 |
y:(y - activeTop).
|
|
901 |
^ self
|
|
902 |
]
|
|
903 |
].
|
|
904 |
].
|
|
905 |
self hideActiveMenu
|
0
|
906 |
]
|
|
907 |
!
|
|
908 |
|
|
909 |
buttonMotion:button x:x y:y
|
|
910 |
|titleIndex activeMenu activeLeft activeTop|
|
|
911 |
|
116
|
912 |
activeMenuNumber notNil ifTrue:[
|
|
913 |
activeMenu := menus at:activeMenuNumber.
|
|
914 |
].
|
|
915 |
|
0
|
916 |
(y < height) ifTrue:[
|
59
|
917 |
"moving around in title line"
|
116
|
918 |
activeMenu notNil ifTrue:[
|
|
919 |
activeMenu selection:nil
|
59
|
920 |
].
|
|
921 |
titleIndex := self titleIndexForX:x.
|
|
922 |
titleIndex notNil ifTrue:[
|
|
923 |
(titleIndex ~~ activeMenuNumber) ifTrue:[
|
|
924 |
self pullMenu:titleIndex
|
|
925 |
]
|
|
926 |
]
|
0
|
927 |
] ifFalse:[
|
59
|
928 |
"moving around below"
|
116
|
929 |
activeMenu isNil ifTrue:[^self].
|
59
|
930 |
activeLeft := activeMenu left.
|
|
931 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
932 |
activeTop := activeMenu top.
|
|
933 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
934 |
"moving around in menu"
|
|
935 |
activeMenu buttonMotion:button
|
|
936 |
x:(x - activeLeft)
|
|
937 |
y:(y - activeTop).
|
|
938 |
^ self
|
|
939 |
]
|
|
940 |
].
|
|
941 |
"moved outside menu"
|
|
942 |
activeMenu selection:nil
|
0
|
943 |
]
|
|
944 |
!
|
|
945 |
|
|
946 |
buttonRelease:button x:x y:y
|
38
|
947 |
|activeMenu activeLeft activeTop hideMenu|
|
0
|
948 |
|
38
|
949 |
hideMenu := false.
|
0
|
950 |
(y >= height) ifTrue:[
|
59
|
951 |
"release below title-line"
|
|
952 |
activeMenuNumber isNil ifTrue:[^self].
|
|
953 |
activeMenu := menus at:activeMenuNumber.
|
|
954 |
activeLeft := activeMenu left.
|
|
955 |
"
|
|
956 |
released in a submenu ?
|
|
957 |
"
|
|
958 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
959 |
activeTop := activeMenu top.
|
|
960 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
961 |
"release in menu"
|
|
962 |
self hideActiveMenu.
|
|
963 |
activeMenu buttonRelease:button
|
|
964 |
x:(x - activeLeft)
|
|
965 |
y:(y - activeTop).
|
|
966 |
^ self
|
|
967 |
]
|
|
968 |
].
|
|
969 |
hideMenu := true.
|
38
|
970 |
] ifFalse:[
|
59
|
971 |
y < 0 ifTrue:[
|
|
972 |
hideMenu := true
|
|
973 |
] ifFalse:[
|
|
974 |
keepMenu ifFalse:[
|
|
975 |
hideMenu := true
|
|
976 |
]
|
|
977 |
]
|
38
|
978 |
].
|
|
979 |
hideMenu ifTrue:[
|
|
980 |
self hideActiveMenu.
|
|
981 |
]
|
0
|
982 |
! !
|