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
|
128
|
14 |
instanceVariableNames:'receiver menus titles selectors activeMenuNumber
|
59
|
15 |
showSeparatingLines topMargin
|
|
16 |
fgColor bgColor activeFgColor activeBgColor
|
63
|
17 |
onLevel offLevel edgeStyle
|
133
|
18 |
keepMenu toggleKeep raiseTopWhenActivated'
|
59
|
19 |
classVariableNames:'DefaultFont
|
|
20 |
DefaultViewBackground
|
|
21 |
DefaultForegroundColor
|
|
22 |
DefaultBackgroundColor
|
|
23 |
DefaultHilightForegroundColor
|
|
24 |
DefaultHilightBackgroundColor
|
|
25 |
DefaultLevel DefaultHilightLevel
|
63
|
26 |
DefaultShadowColor DefaultLightColor
|
128
|
27 |
DefaultEdgeStyle DefaultKeepMenu DefaultToggleKeep
|
|
28 |
DefaultSeparatingLines'
|
0
|
29 |
poolDictionaries:''
|
|
30 |
category:'Views-Menus'
|
|
31 |
!
|
|
32 |
|
|
33 |
PullDownMenu comment:'
|
5
|
34 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
35 |
All Rights Reserved
|
0
|
36 |
|
133
|
37 |
$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.21 1995-07-23 03:02:18 claus Exp $
|
3
|
38 |
'!
|
0
|
39 |
|
3
|
40 |
!PullDownMenu class methodsFor:'documentation'!
|
|
41 |
|
38
|
42 |
copyright
|
|
43 |
"
|
|
44 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
45 |
All Rights Reserved
|
38
|
46 |
|
|
47 |
This software is furnished under a license and may be used
|
|
48 |
only in accordance with the terms of that license and with the
|
|
49 |
inclusion of the above copyright notice. This software may not
|
|
50 |
be provided or otherwise made available to, or used by, any
|
|
51 |
other person. No title to or ownership of the software is
|
|
52 |
hereby transferred.
|
|
53 |
"
|
|
54 |
!
|
|
55 |
|
|
56 |
version
|
|
57 |
"
|
133
|
58 |
$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.21 1995-07-23 03:02:18 claus Exp $
|
38
|
59 |
"
|
|
60 |
!
|
|
61 |
|
3
|
62 |
documentation
|
|
63 |
"
|
38
|
64 |
PullDown menu provides the top (always visible) part of these menus.
|
|
65 |
It controls display of its menus, which become visible when one of the
|
|
66 |
PullDownMenus entries is pressed.
|
0
|
67 |
|
128
|
68 |
A PullDownMenu itself consists of a single row of labels, which activate
|
|
69 |
a pulled menu when clicked. Entries may be empty (i.e. have no menu)
|
|
70 |
and empty entries may (optionally) also perform some action when clicked.
|
|
71 |
An entries selector is used as the key to define and access submenus
|
|
72 |
and (for empty entries:) the selector sent to the receiver of the menu.
|
|
73 |
|
38
|
74 |
Instance variables:
|
0
|
75 |
|
128
|
76 |
menus <Collection> the sub menus
|
|
77 |
|
|
78 |
titles <Collection> the strings in the menu
|
|
79 |
|
|
80 |
selectors <Collection> the selectors to send to the menu-
|
|
81 |
receiver (for empty pull-menus)
|
|
82 |
if nil (the default), title entries
|
|
83 |
do not send anything.
|
|
84 |
|
110
|
85 |
activeMenuNumber <Number> the index of the currently active menu
|
128
|
86 |
|
110
|
87 |
showSeparatingLines <Boolean> show separating lines between my menu-strings
|
128
|
88 |
|
110
|
89 |
topMargin <Number> number of pixels at top
|
128
|
90 |
|
|
91 |
fgColor <Color> fg color to draw passive menu-titles
|
|
92 |
bgColor <Color> bg color to draw passive menu-titles
|
|
93 |
|
|
94 |
activeFgColor <Color> fg color to draw activated menu-titles
|
|
95 |
activeBgColor <Color> bg color to draw activated menu-titles
|
|
96 |
|
|
97 |
onLevel <Integer> 3D level of entry-buttons when pressed
|
|
98 |
offLevel <Integer> 3D level of entry-buttons when released
|
|
99 |
|
|
100 |
edgeStyle <Symbol> how to draw edges
|
|
101 |
|
110
|
102 |
keepmenu <Boolean> if on, pulled menu stays on click,
|
|
103 |
till clicked again (motif & windows behavior)
|
77
|
104 |
|
128
|
105 |
toggleKeep <Boolean> if on and keepMenu is on,
|
|
106 |
clicking again on label closes menu
|
|
107 |
|
|
108 |
except menus, titles and selectors, instvars are usually defined from
|
|
109 |
defaults in the styleSheet; you should not care for them.
|
|
110 |
|
77
|
111 |
|
|
112 |
StyleSheet values:
|
|
113 |
|
110
|
114 |
pullDownMenuViewBackground view background Color for the menu bar
|
|
115 |
default: menuViewBackground
|
|
116 |
|
|
117 |
pullDownMenuForegroundColor foreground drawing color for the menu bar
|
|
118 |
default: menuForegroundColor
|
|
119 |
|
|
120 |
pullDownMenuBackgroundColor background drawing color for the menu bar
|
|
121 |
default: menuBackgroundColor
|
|
122 |
|
|
123 |
pullDownMenuHilightForegroundColor active foreground drawing color for the menu bar
|
|
124 |
default: menuHilightForegroundColor
|
|
125 |
|
|
126 |
pullDownMenuHilightBackgroundColor active background drawing color for the menu bar
|
|
127 |
default: menuHilightBackgroundColor
|
|
128 |
|
|
129 |
pullDownMenuHilightLevel level (3D only) when active
|
|
130 |
default: menuHilightLevel
|
77
|
131 |
|
110
|
132 |
pullDownMenuEdgeStyle edge style (nil or #soft)
|
|
133 |
|
|
134 |
pullDownMenuKeepMenu if true, pulled menu stays open until button
|
128
|
135 |
is pressed again outside of the item-area (motif behavior)
|
110
|
136 |
if false, menu closes on release (default)
|
|
137 |
|
|
138 |
pullDownMenuToggleKeep if true, pulled menu closes when an entry is pressed
|
128
|
139 |
again. Otherwise, only press outside of the items area
|
|
140 |
hides it. default is false
|
110
|
141 |
|
|
142 |
pullDownMenuLevel level (3D only)
|
|
143 |
|
|
144 |
pullDownMenuFont font to use for the menu bar
|
|
145 |
default: menuFont
|
128
|
146 |
|
|
147 |
pullDownMenuShowSeparatingLines if true, lines are drawn between items.
|
|
148 |
default: false
|
133
|
149 |
|
|
150 |
pullDownMenuRaiseTop if true, topview is raised whenever an entry
|
|
151 |
is activated.
|
|
152 |
default: true
|
110
|
153 |
"
|
|
154 |
!
|
77
|
155 |
|
110
|
156 |
examples
|
|
157 |
"
|
128
|
158 |
|top menu|
|
|
159 |
|
|
160 |
top := StandardSystemView new.
|
|
161 |
top extent:300@300.
|
|
162 |
|
|
163 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
164 |
menu labels:#('foo' 'bar').
|
|
165 |
menu selectors:#(foo bar).
|
|
166 |
menu at:#foo
|
|
167 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
168 |
selectors:#(foo1 foo2 foo3)
|
|
169 |
receiver:nil.
|
|
170 |
menu at:#bar
|
|
171 |
putLabels:#('bar1' 'bar2' 'bar3')
|
|
172 |
selectors:#(bar1 bar2 bar3)
|
|
173 |
receiver:nil.
|
|
174 |
top open
|
|
175 |
|
|
176 |
|
110
|
177 |
|
128
|
178 |
empty entries are possible as selectable items (with non-nil seletor) ...
|
|
179 |
|
|
180 |
|top menu|
|
|
181 |
|
|
182 |
top := StandardSystemView new.
|
|
183 |
top extent:300@300.
|
|
184 |
|
|
185 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
186 |
menu labels:#('foo' 'bar' 'baz').
|
|
187 |
menu selectors:#(foo bar baz).
|
|
188 |
menu at:#foo
|
|
189 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
190 |
selectors:#(foo1 foo2 foo3)
|
|
191 |
receiver:nil.
|
|
192 |
menu at:#baz
|
|
193 |
putLabels:#('baz1' 'baz2' 'baz3')
|
|
194 |
selectors:#(baz1 baz2 baz3)
|
|
195 |
receiver:nil.
|
|
196 |
top open
|
110
|
197 |
|
|
198 |
|
77
|
199 |
|
128
|
200 |
... or as separators (with nil selector)
|
110
|
201 |
|
128
|
202 |
|top menu|
|
|
203 |
|
|
204 |
top := StandardSystemView new.
|
|
205 |
top extent:500@200.
|
110
|
206 |
|
128
|
207 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top.
|
|
208 |
menu labels:#('foo' ' ' 'bar' ' baz' ' ' 'moreFoo' 'moreBar' 'moreBaz').
|
|
209 |
menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz).
|
|
210 |
menu at:#foo
|
|
211 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
212 |
selectors:#(foo1 foo2 foo3)
|
|
213 |
receiver:nil.
|
|
214 |
menu at:#bar
|
|
215 |
putLabels:#('bar1' 'bar2' 'bar3')
|
|
216 |
selectors:#(bar1 bar2 bar3)
|
|
217 |
receiver:nil.
|
|
218 |
menu at:#baz
|
|
219 |
putLabels:#('baz1' 'baz2' 'baz3')
|
|
220 |
selectors:#(baz1 baz2 baz3)
|
|
221 |
receiver:nil.
|
|
222 |
top open
|
110
|
223 |
|
|
224 |
|
|
225 |
|
128
|
226 |
|
|
227 |
use the menus default height
|
110
|
228 |
|
128
|
229 |
|top menu|
|
|
230 |
|
|
231 |
top := StandardSystemView new.
|
|
232 |
top extent:300@300.
|
77
|
233 |
|
128
|
234 |
menu := PullDownMenu in:top.
|
|
235 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
236 |
menu labels:#('foo' 'bar').
|
|
237 |
menu selectors:#(foo bar).
|
|
238 |
menu at:#foo
|
|
239 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
240 |
selectors:#(foo1 foo2 foo3)
|
|
241 |
receiver:nil.
|
|
242 |
top open
|
110
|
243 |
|
77
|
244 |
|
110
|
245 |
|
|
246 |
|
128
|
247 |
although you can change the font, colors etc (as shown below)
|
|
248 |
you should NOT do it - since if you do so, the styleSheet settings
|
|
249 |
are ineffective (which users wont like probably)
|
|
250 |
BTW: The styleSheet entries for below are pullDownMenuForegroundColor,
|
|
251 |
pullDownMenuBackgroundColor and pullDownMenuFont
|
110
|
252 |
|
128
|
253 |
|top menu|
|
77
|
254 |
|
128
|
255 |
top := StandardSystemView new.
|
|
256 |
menu := PullDownMenu in:top.
|
|
257 |
menu font:(Font family:'courier' size:20).
|
|
258 |
menu foregroundColor:Color red.
|
|
259 |
menu backgroundColor:Color yellow.
|
|
260 |
menu viewBackground:Color yellow.
|
|
261 |
menu showSeparatingLines:true.
|
110
|
262 |
|
128
|
263 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
264 |
menu labels:#('foo' 'bar').
|
|
265 |
menu selectors:#(foo bar).
|
|
266 |
menu at:#foo
|
|
267 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
268 |
selectors:#(foo1 foo2 foo3)
|
|
269 |
receiver:nil.
|
|
270 |
(menu menuAt:#foo) font:(Font family:'courier' size:36).
|
|
271 |
top open
|
110
|
272 |
|
|
273 |
|
77
|
274 |
|
128
|
275 |
you can use icons, too ...
|
110
|
276 |
|
128
|
277 |
|labels top menu|
|
|
278 |
|
|
279 |
top := StandardSystemView new.
|
|
280 |
top extent:300@300.
|
110
|
281 |
|
128
|
282 |
menu := PullDownMenu in:top.
|
|
283 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
|
284 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
|
|
285 |
with:'foo'
|
|
286 |
with:'bar'.
|
|
287 |
menu labels:labels.
|
|
288 |
menu selectors:#(about foo bar).
|
|
289 |
menu at:#about
|
|
290 |
putLabels:#('about PullDownMenus')
|
|
291 |
selectors:#(aboutMenus)
|
|
292 |
receiver:nil.
|
|
293 |
menu at:#foo
|
|
294 |
putLabels:#('foo1' 'foo2' 'foo3')
|
|
295 |
selectors:#(foo1 foo2 foo3)
|
|
296 |
receiver:nil.
|
|
297 |
top open
|
110
|
298 |
|
|
299 |
|
|
300 |
|
128
|
301 |
a concrete example (combining things described above)
|
|
302 |
(using a Plug, since we have no application class here):
|
|
303 |
|
|
304 |
|labels top menu textView appModel|
|
110
|
305 |
|
128
|
306 |
appModel := Plug new.
|
|
307 |
appModel respondTo:#quit with:[top destroy].
|
|
308 |
appModel respondTo:#showAbout with:[self information:'some info here ...'].
|
|
309 |
appModel respondTo:#help with:[self information:'some help here ...'].
|
|
310 |
|
|
311 |
top := StandardSystemView new.
|
|
312 |
top extent:300@300.
|
|
313 |
|
|
314 |
menu := PullDownMenu in:top.
|
|
315 |
menu receiver:appModel.
|
|
316 |
menu origin:0.0@0.0 corner:1.0@(menu height).
|
77
|
317 |
|
128
|
318 |
textView := ScrollableView forView:(EditTextView new).
|
|
319 |
textView origin:0.0@menu height corner:1.0@1.0.
|
|
320 |
top addSubView:textView.
|
|
321 |
|
|
322 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16)
|
|
323 |
with:'file'
|
|
324 |
with:'edit'
|
|
325 |
with:'help'.
|
|
326 |
menu labels:labels.
|
|
327 |
menu selectors:#(about file edit help).
|
|
328 |
menu at:#about
|
|
329 |
putLabels:#('about PullDownMenus')
|
|
330 |
selectors:#(showAbout)
|
|
331 |
receiver:appModel.
|
|
332 |
menu at:#file
|
|
333 |
putLabels:#('quit')
|
|
334 |
selectors:#(quit)
|
|
335 |
receiver:appModel.
|
|
336 |
menu at:#edit
|
|
337 |
putLabels:#('copy' 'cut' 'paste')
|
|
338 |
selectors:#(copySelection cut paste)
|
|
339 |
receiver:textView.
|
|
340 |
top open
|
3
|
341 |
"
|
|
342 |
! !
|
0
|
343 |
|
59
|
344 |
!PullDownMenu class methodsFor:'defaults'!
|
|
345 |
|
|
346 |
updateStyleCache
|
110
|
347 |
"extract values from the styleSheet and cache them in class variables"
|
|
348 |
|
133
|
349 |
|styleSheet|
|
|
350 |
|
|
351 |
styleSheet := StyleSheet.
|
|
352 |
|
|
353 |
DefaultViewBackground := styleSheet colorAt:'pullDownMenuViewBackground'.
|
60
|
354 |
DefaultViewBackground isNil ifTrue:[
|
133
|
355 |
DefaultViewBackground := styleSheet colorAt:'menuViewBackground'.
|
59
|
356 |
].
|
133
|
357 |
DefaultForegroundColor := styleSheet colorAt:'pullDownMenuForegroundColor'.
|
60
|
358 |
DefaultForegroundColor isNil ifTrue:[
|
133
|
359 |
DefaultForegroundColor := styleSheet colorAt:'menuForegroundColor'.
|
60
|
360 |
].
|
133
|
361 |
DefaultBackgroundColor := styleSheet colorAt:'pullDownMenuBackgroundColor'.
|
60
|
362 |
DefaultBackgroundColor isNil ifTrue:[
|
77
|
363 |
DefaultViewBackground notNil ifTrue:[
|
|
364 |
DefaultBackgroundColor := DefaultViewBackground
|
|
365 |
] ifFalse:[
|
133
|
366 |
DefaultBackgroundColor := styleSheet colorAt:'menuBackgroundColor'.
|
77
|
367 |
]
|
59
|
368 |
].
|
133
|
369 |
DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenuHilightForegroundColor'.
|
60
|
370 |
DefaultHilightForegroundColor isNil ifTrue:[
|
133
|
371 |
DefaultHilightForegroundColor := styleSheet colorAt:'menuHilightForegroundColor'.
|
59
|
372 |
].
|
133
|
373 |
DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenuHilightBackgroundColor'.
|
60
|
374 |
DefaultHilightBackgroundColor isNil ifTrue:[
|
133
|
375 |
DefaultHilightBackgroundColor := styleSheet colorAt:'menuHilightBackgroundColor'.
|
59
|
376 |
].
|
133
|
377 |
DefaultHilightLevel := styleSheet at:'pullDownMenuHilightLevel'.
|
60
|
378 |
DefaultHilightLevel isNil ifTrue:[
|
133
|
379 |
DefaultHilightLevel := styleSheet at:'menuHilightLevel' default:0.
|
59
|
380 |
].
|
133
|
381 |
DefaultEdgeStyle := styleSheet at:'pullDownMenuEdgeStyle'.
|
|
382 |
DefaultKeepMenu := styleSheet at:'pullDownMenuKeepMenu' default:false.
|
|
383 |
DefaultToggleKeep := styleSheet at:'pullDownMenuToggleKeep' default:false.
|
|
384 |
DefaultLevel := styleSheet at:'pullDownMenuLevel' default:1.
|
|
385 |
DefaultFont := styleSheet fontAt:'pullDownMenuFont'.
|
60
|
386 |
DefaultFont isNil ifTrue:[
|
133
|
387 |
DefaultFont := styleSheet fontAt:'menuFont'.
|
59
|
388 |
].
|
133
|
389 |
DefaultSeparatingLines := styleSheet at:'pullDownMenuSeparatingLines' default:false.
|
110
|
390 |
|
|
391 |
"
|
|
392 |
PullDownMenu updateStyleCache
|
|
393 |
"
|
59
|
394 |
! !
|
|
395 |
|
0
|
396 |
!PullDownMenu class methodsFor:'instance creation'!
|
|
397 |
|
|
398 |
labels:titleArray
|
|
399 |
"create and return a new PullDownMenu"
|
|
400 |
|
|
401 |
^ self new labels:titleArray
|
|
402 |
! !
|
|
403 |
|
77
|
404 |
!PullDownMenu methodsFor:'initialize / release'!
|
0
|
405 |
|
|
406 |
initialize
|
|
407 |
super initialize.
|
|
408 |
|
|
409 |
font := font on:device.
|
|
410 |
self origin:(0.0 @ 0.0)
|
131
|
411 |
extent:(self preferredExtent)
|
|
412 |
"/ extent:(1.0 @ (font height + (font descent * 2) + topMargin)).
|
0
|
413 |
!
|
|
414 |
|
|
415 |
initStyle
|
130
|
416 |
|style|
|
|
417 |
|
0
|
418 |
super initStyle.
|
|
419 |
|
128
|
420 |
showSeparatingLines := DefaultSeparatingLines. "/ false.
|
59
|
421 |
DefaultViewBackground notNil ifTrue:[
|
60
|
422 |
viewBackground := DefaultViewBackground on:device
|
59
|
423 |
].
|
|
424 |
|
60
|
425 |
DefaultFont notNil ifTrue:[
|
|
426 |
font := DefaultFont on:device
|
|
427 |
].
|
59
|
428 |
DefaultForegroundColor notNil ifTrue:[
|
|
429 |
fgColor := DefaultForegroundColor
|
|
430 |
] ifFalse:[
|
|
431 |
fgColor := Black.
|
|
432 |
].
|
|
433 |
DefaultBackgroundColor notNil ifTrue:[
|
|
434 |
bgColor := DefaultBackgroundColor
|
|
435 |
] ifFalse:[
|
|
436 |
bgColor := viewBackground.
|
|
437 |
].
|
|
438 |
onLevel := DefaultHilightLevel.
|
|
439 |
offLevel := DefaultLevel.
|
21
|
440 |
|
0
|
441 |
self is3D ifTrue:[
|
59
|
442 |
device hasColors ifTrue:[
|
|
443 |
activeFgColor := Color name:'yellow'
|
|
444 |
] ifFalse:[
|
|
445 |
activeFgColor := White
|
|
446 |
].
|
|
447 |
device hasGreyscales ifTrue:[
|
|
448 |
activeBgColor := bgColor.
|
|
449 |
] ifFalse:[
|
|
450 |
activeBgColor := fgColor.
|
|
451 |
].
|
|
452 |
topMargin := 2.
|
21
|
453 |
|
130
|
454 |
style := styleSheet name.
|
|
455 |
((style == #iris) or:[style == #motif]) ifTrue:[
|
59
|
456 |
self level:2.
|
|
457 |
onLevel := 2.
|
|
458 |
offLevel := 0.
|
|
459 |
activeFgColor := fgColor
|
|
460 |
]
|
0
|
461 |
] ifFalse:[
|
59
|
462 |
activeFgColor := bgColor.
|
|
463 |
activeBgColor := fgColor.
|
|
464 |
topMargin := 0
|
|
465 |
].
|
|
466 |
|
63
|
467 |
edgeStyle := DefaultEdgeStyle.
|
|
468 |
keepMenu := DefaultKeepMenu.
|
110
|
469 |
toggleKeep := DefaultToggleKeep.
|
63
|
470 |
|
59
|
471 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
472 |
activeFgColor := DefaultHilightForegroundColor
|
|
473 |
].
|
|
474 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
475 |
activeBgColor := DefaultHilightBackgroundColor
|
0
|
476 |
].
|
59
|
477 |
DefaultShadowColor notNil ifTrue:[
|
|
478 |
shadowColor := DefaultShadowColor on:device
|
|
479 |
].
|
|
480 |
DefaultLightColor notNil ifTrue:[
|
|
481 |
lightColor := DefaultLightColor on:device
|
|
482 |
].
|
|
483 |
|
|
484 |
bgColor := bgColor on:device.
|
|
485 |
fgColor := fgColor on:device.
|
|
486 |
activeBgColor := activeBgColor on:device.
|
|
487 |
activeFgColor := activeFgColor on:device.
|
133
|
488 |
|
|
489 |
raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true.
|
|
490 |
!
|
|
491 |
|
|
492 |
initCursor
|
|
493 |
"set up a hand cursor"
|
|
494 |
|
|
495 |
cursor := Cursor hand
|
0
|
496 |
!
|
|
497 |
|
|
498 |
recreate
|
128
|
499 |
"if the image was saved with an active menu, hide it"
|
|
500 |
|
|
501 |
|m|
|
115
|
502 |
|
|
503 |
activeMenuNumber notNil ifTrue:[
|
128
|
504 |
(m := menus at:activeMenuNumber) notNil ifTrue:[
|
|
505 |
m unrealize.
|
|
506 |
].
|
115
|
507 |
activeMenuNumber := nil.
|
|
508 |
].
|
|
509 |
super recreate.
|
0
|
510 |
self setMenuOrigins
|
|
511 |
!
|
|
512 |
|
|
513 |
create
|
|
514 |
super create.
|
|
515 |
self setMenuOrigins
|
77
|
516 |
!
|
|
517 |
|
|
518 |
destroy
|
128
|
519 |
"have to destroy the menus manually here,
|
|
520 |
since they are no real subviews of myself"
|
|
521 |
|
77
|
522 |
menus notNil ifTrue:[
|
|
523 |
menus do:[:m |
|
|
524 |
m notNil ifTrue:[m destroy]
|
|
525 |
].
|
|
526 |
menus := nil
|
110
|
527 |
].
|
115
|
528 |
activeMenuNumber := nil.
|
|
529 |
super destroy.
|
133
|
530 |
!
|
|
531 |
|
|
532 |
superView:aView
|
|
533 |
"when my superView changes, all of my menus must change as well"
|
|
534 |
|
|
535 |
super superView:aView.
|
|
536 |
menus notNil ifTrue:[
|
|
537 |
menus do:[:aMenu |
|
|
538 |
aMenu notNil ifTrue:[
|
|
539 |
aMenu superView:aView
|
|
540 |
]
|
|
541 |
]
|
|
542 |
]
|
0
|
543 |
! !
|
|
544 |
|
128
|
545 |
!PullDownMenu methodsFor:'accessing-look'!
|
0
|
546 |
|
|
547 |
showSeparatingLines:aBoolean
|
128
|
548 |
"turn on/off drawing of separating lines.
|
|
549 |
You should not use this method; instead leave the value as
|
130
|
550 |
defined in the styleSheet."
|
0
|
551 |
|
|
552 |
showSeparatingLines := aBoolean.
|
|
553 |
shown ifTrue:[
|
128
|
554 |
self setMenuOrigins.
|
59
|
555 |
self redraw
|
0
|
556 |
]
|
|
557 |
!
|
|
558 |
|
128
|
559 |
font:aFont
|
|
560 |
"set the menus font.
|
|
561 |
adjusts menu-origins when font changes.
|
|
562 |
You should not use this method; instead leave the value as
|
130
|
563 |
defined in the styleSheet."
|
128
|
564 |
|
|
565 |
aFont ~~ font ifTrue:[
|
|
566 |
super font:(aFont on:device).
|
|
567 |
self height:(font height + (font descent * 2)).
|
|
568 |
shown ifTrue:[
|
|
569 |
self setMenuOrigins
|
|
570 |
]
|
|
571 |
]
|
|
572 |
!
|
|
573 |
|
|
574 |
foregroundColor:aColor
|
|
575 |
"set the foreground drawing color.
|
|
576 |
You should not use this method; instead leave the value as
|
130
|
577 |
defined in the styleSheet."
|
128
|
578 |
|
|
579 |
fgColor := aColor on:device
|
|
580 |
!
|
|
581 |
|
|
582 |
backgroundColor:aColor
|
|
583 |
"set the background drawing color.
|
|
584 |
You should not use this method; instead leave the value as
|
130
|
585 |
defined in the styleSheet."
|
128
|
586 |
|
|
587 |
bgColor := aColor on:device
|
|
588 |
! !
|
|
589 |
|
|
590 |
|
|
591 |
!PullDownMenu methodsFor:'accessing'!
|
|
592 |
|
|
593 |
receiver:anObject
|
|
594 |
"set the menu-receiver. Thats the one who gets the
|
|
595 |
messages (both from myself and from my submenus).
|
|
596 |
This only sets the receiver for menus which are already
|
|
597 |
created - menus added later should get their receiver in
|
|
598 |
the creation send."
|
|
599 |
|
|
600 |
receiver := anObject.
|
|
601 |
menus notNil ifTrue:[
|
|
602 |
menus do:[:aMenu |
|
131
|
603 |
aMenu notNil ifTrue:[
|
|
604 |
aMenu receiver:anObject
|
|
605 |
]
|
128
|
606 |
]
|
|
607 |
]
|
|
608 |
!
|
|
609 |
|
0
|
610 |
numberOfTitles:n
|
|
611 |
"setup blank title-space to be filled in later"
|
|
612 |
|
|
613 |
menus := Array new:n.
|
|
614 |
titles := Array new:n
|
|
615 |
!
|
|
616 |
|
|
617 |
labels:titleArray
|
|
618 |
"define the menu-titles (group-headers)"
|
|
619 |
|
|
620 |
|numberOfLabels|
|
|
621 |
|
|
622 |
numberOfLabels := titleArray size.
|
|
623 |
menus := Array new:numberOfLabels.
|
|
624 |
titles := Array new:numberOfLabels.
|
110
|
625 |
|
|
626 |
titleArray keysAndValuesDo:[:index :entry |
|
|
627 |
|e|
|
|
628 |
|
|
629 |
entry isImage ifTrue:[
|
|
630 |
e := entry on:device
|
|
631 |
] ifFalse:[
|
|
632 |
e := entry printString
|
|
633 |
].
|
|
634 |
titles at:index put:e
|
0
|
635 |
].
|
|
636 |
shown ifTrue:[
|
59
|
637 |
self clear.
|
|
638 |
self redraw
|
0
|
639 |
]
|
|
640 |
!
|
|
641 |
|
|
642 |
labels
|
|
643 |
"return the menu-titles (group-headers)"
|
|
644 |
|
|
645 |
^ titles
|
|
646 |
!
|
|
647 |
|
91
|
648 |
selectors:selectorArray
|
|
649 |
"define the menu-selectors. These are used as accesskey only
|
|
650 |
in menuAt: accesses. This makes PullDownMenu accesss
|
|
651 |
somewhat more compatible to PopUpMenus."
|
|
652 |
|
|
653 |
selectors := selectorArray.
|
|
654 |
!
|
|
655 |
|
0
|
656 |
menuAt:string
|
|
657 |
"return the menu with the title; return nil if not found"
|
|
658 |
|
|
659 |
|index|
|
|
660 |
|
|
661 |
index := self indexOf:string.
|
|
662 |
(index == 0) ifTrue:[^ nil].
|
|
663 |
^ menus at:index
|
|
664 |
!
|
|
665 |
|
|
666 |
at:aString putMenu:aMenu
|
|
667 |
"set the menu under the title, aString"
|
|
668 |
|
|
669 |
|index|
|
|
670 |
|
|
671 |
index := self indexOf:aString.
|
|
672 |
(index == 0) ifTrue:[^ nil].
|
112
|
673 |
|
|
674 |
"/ not needed:
|
|
675 |
"/ aMenu origin:((left + (self titleLenUpTo:index))
|
|
676 |
"/ @
|
|
677 |
"/ (height + aMenu borderWidth)).
|
130
|
678 |
aMenu hiddenOnRealize:true.
|
77
|
679 |
menus at:index put:aMenu.
|
|
680 |
aMenu masterView:self.
|
0
|
681 |
!
|
|
682 |
|
|
683 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject
|
|
684 |
"create and set the menu under the title, aString"
|
|
685 |
|
|
686 |
|menuView|
|
|
687 |
|
|
688 |
menuView := MenuView labels:labels
|
59
|
689 |
selectors:selectors
|
|
690 |
args:args
|
|
691 |
receiver:anObject
|
|
692 |
for:self.
|
0
|
693 |
self at:aString putMenu:menuView
|
|
694 |
!
|
|
695 |
|
|
696 |
at:aString putLabels:labels selector:selector args:args receiver:anObject
|
|
697 |
"create and set the menu under the title, aString"
|
|
698 |
|
|
699 |
|menuView|
|
|
700 |
|
|
701 |
menuView := MenuView labels:labels
|
59
|
702 |
selector:selector
|
|
703 |
args:args
|
|
704 |
receiver:anObject
|
|
705 |
for:self.
|
0
|
706 |
self at:aString putMenu:menuView
|
|
707 |
!
|
|
708 |
|
|
709 |
at:aString putLabels:labels selectors:selectors receiver:anObject
|
|
710 |
"create and set the menu under the title, aString"
|
|
711 |
|
|
712 |
|menuView|
|
|
713 |
|
|
714 |
menuView := MenuView labels:labels
|
59
|
715 |
selectors:selectors
|
|
716 |
receiver:anObject
|
|
717 |
for:self.
|
0
|
718 |
self at:aString putMenu:menuView
|
|
719 |
! !
|
|
720 |
|
131
|
721 |
!PullDownMenu methodsFor:'queries'!
|
|
722 |
|
|
723 |
preferredExtent
|
|
724 |
^ 1.0 @ (font height + (font descent * 2) "+ topMargin" + (margin*2)).
|
|
725 |
! !
|
|
726 |
|
0
|
727 |
!PullDownMenu methodsFor:'private'!
|
|
728 |
|
|
729 |
titleLenUpTo:index
|
110
|
730 |
"answer len (in pixels) of all title-strings up-to
|
|
731 |
(but excluding) title-index. Used to compute x-position when drawing
|
|
732 |
individual entries."
|
0
|
733 |
|
110
|
734 |
|len "{ Class: SmallInteger }"
|
|
735 |
wSpace wSep|
|
0
|
736 |
|
|
737 |
(index <= 1) ifTrue:[^ 0].
|
110
|
738 |
wSpace := (font widthOf:' ').
|
|
739 |
showSeparatingLines ifTrue:[
|
|
740 |
self is3D ifTrue:[
|
|
741 |
wSep := 2
|
|
742 |
] ifFalse:[
|
|
743 |
wSep := 1
|
|
744 |
]
|
|
745 |
] ifFalse:[
|
|
746 |
wSep := 0
|
|
747 |
].
|
|
748 |
|
0
|
749 |
len := 0.
|
110
|
750 |
titles from:1 to:(index - 1) do:[:entry |
|
|
751 |
|thisLength|
|
|
752 |
|
|
753 |
entry isString ifTrue:[
|
|
754 |
thisLength := (font widthOf:entry).
|
|
755 |
] ifFalse:[
|
|
756 |
thisLength := entry width
|
|
757 |
].
|
|
758 |
len := len + thisLength + wSpace + wSep + wSpace.
|
0
|
759 |
].
|
|
760 |
^ len
|
|
761 |
!
|
|
762 |
|
|
763 |
indexOf:stringOrNumber
|
91
|
764 |
"return the index of the menu with title; return 0 if not found.
|
|
765 |
stringOrNumber may be a number, a selector from the selectorArray
|
|
766 |
or a string from the title array."
|
|
767 |
|
|
768 |
|idx|
|
0
|
769 |
|
91
|
770 |
stringOrNumber isNumber ifTrue:[
|
59
|
771 |
^ stringOrNumber
|
0
|
772 |
].
|
91
|
773 |
selectors notNil ifTrue:[
|
|
774 |
idx := selectors indexOf:stringOrNumber.
|
|
775 |
idx ~~ 0 ifTrue:[^ idx].
|
|
776 |
].
|
0
|
777 |
^ titles indexOf:stringOrNumber
|
|
778 |
!
|
|
779 |
|
133
|
780 |
someMenuItemLabeled:aLabel
|
|
781 |
"find a menu item.
|
|
782 |
Currently, in ST/X, instances of MenuItem are only created as dummy"
|
|
783 |
|
|
784 |
|idx|
|
|
785 |
|
|
786 |
idx := self indexOf:aLabel.
|
|
787 |
idx ~~ 0 ifTrue:[
|
|
788 |
^ MenuItem new menu:self index:idx
|
|
789 |
].
|
|
790 |
menus notNil ifTrue:[
|
|
791 |
menus do:[:aMenu |
|
|
792 |
|item|
|
|
793 |
|
|
794 |
aMenu notNil ifTrue:[
|
|
795 |
(item := aMenu someMenuItemLabeled:aLabel) notNil ifTrue:[
|
|
796 |
^ item
|
|
797 |
]
|
|
798 |
]
|
|
799 |
]
|
|
800 |
].
|
|
801 |
^ nil
|
|
802 |
!
|
|
803 |
|
0
|
804 |
setMenuOrigins
|
|
805 |
"adjust origins of menus when font changes"
|
|
806 |
|
|
807 |
(font device == device) ifTrue:[
|
119
|
808 |
menus keysAndValuesDo:[:index :aMenu |
|
59
|
809 |
aMenu notNil ifTrue:[
|
|
810 |
aMenu origin:((left + (self titleLenUpTo:index))
|
|
811 |
@
|
|
812 |
(height + aMenu borderWidth))
|
|
813 |
].
|
|
814 |
]
|
0
|
815 |
]
|
110
|
816 |
!
|
|
817 |
|
|
818 |
titleIndexForX:x
|
|
819 |
"given a click x-position, return index in title or nil"
|
|
820 |
|
|
821 |
|xstart "{ Class: SmallInteger }"
|
|
822 |
xend "{ Class: SmallInteger }"
|
|
823 |
wSpace wSep|
|
|
824 |
|
|
825 |
wSpace := (font widthOf:' ') * 2.
|
|
826 |
showSeparatingLines ifTrue:[
|
|
827 |
self is3D ifTrue:[
|
|
828 |
wSep := 2
|
|
829 |
] ifFalse:[
|
|
830 |
wSep := 1
|
|
831 |
]
|
|
832 |
] ifFalse:[
|
|
833 |
wSep := 0
|
|
834 |
].
|
|
835 |
xstart := 0.
|
|
836 |
1 to:(titles size) do:[:index |
|
|
837 |
|entry thisLength|
|
|
838 |
|
|
839 |
entry := titles at:index.
|
|
840 |
entry isString ifTrue:[
|
|
841 |
thisLength := font widthOf:entry.
|
|
842 |
] ifFalse:[
|
|
843 |
thisLength := entry width
|
|
844 |
].
|
|
845 |
xend := xstart + thisLength + wSpace + wSep.
|
|
846 |
(x between:xstart and:xend) ifTrue:[^ index].
|
|
847 |
xstart := xend
|
|
848 |
].
|
|
849 |
^ nil
|
0
|
850 |
! !
|
|
851 |
|
|
852 |
!PullDownMenu methodsFor:'hiding/showing menus'!
|
|
853 |
|
110
|
854 |
hideActiveMenuRelease:aBoolean
|
|
855 |
"hide currently active menu - release grab if aBoolean is true
|
|
856 |
and a grab was set (keepMenu)"
|
|
857 |
|
128
|
858 |
|m|
|
|
859 |
|
110
|
860 |
activeMenuNumber notNil ifTrue:[
|
128
|
861 |
(m := menus at:activeMenuNumber) notNil ifTrue:[
|
131
|
862 |
m hiddenOnRealize:true.
|
128
|
863 |
m unrealize.
|
|
864 |
].
|
110
|
865 |
self unHighlightActiveTitle.
|
|
866 |
activeMenuNumber := nil
|
|
867 |
].
|
|
868 |
aBoolean ifTrue:[
|
|
869 |
device ungrabPointer.
|
|
870 |
self cursor:Cursor normal
|
|
871 |
].
|
|
872 |
!
|
|
873 |
|
|
874 |
hideActiveMenu
|
|
875 |
"hide currently active menu - release grab if there is any grab (keepMenu)"
|
|
876 |
|
|
877 |
^ self hideActiveMenuRelease:true
|
|
878 |
!
|
|
879 |
|
|
880 |
pullMenu:aNumber
|
|
881 |
"activate a menu, return it or nil"
|
|
882 |
|
131
|
883 |
|subMenu r posY|
|
110
|
884 |
|
|
885 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
|
128
|
886 |
activeMenuNumber := aNumber.
|
110
|
887 |
subMenu := menus at:aNumber.
|
128
|
888 |
|
133
|
889 |
raiseTopWhenActivated ifTrue:[
|
|
890 |
self topView raise.
|
|
891 |
].
|
|
892 |
|
128
|
893 |
(activeMenuNumber notNil
|
|
894 |
and:[
|
|
895 |
subMenu notNil
|
131
|
896 |
or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[
|
128
|
897 |
self highlightActiveTitle.
|
|
898 |
].
|
|
899 |
|
110
|
900 |
subMenu notNil ifTrue:[
|
131
|
901 |
subMenu origin:((left + (self titleLenUpTo:aNumber))
|
|
902 |
@
|
|
903 |
(posY := height + subMenu borderWidth)).
|
|
904 |
subMenu hiddenOnRealize:false.
|
110
|
905 |
subMenu deselect.
|
|
906 |
subMenu create.
|
|
907 |
subMenu saveUnder:true.
|
|
908 |
subMenu superMenu:self.
|
131
|
909 |
|
|
910 |
subMenu right > (r := self right) ifTrue:[
|
|
911 |
subMenu origin:((r - subMenu width) @ posY).
|
|
912 |
].
|
|
913 |
subMenu raise show.
|
110
|
914 |
].
|
|
915 |
^ subMenu
|
|
916 |
!
|
|
917 |
|
|
918 |
regainControl
|
|
919 |
keepMenu ifTrue:[
|
|
920 |
device grabPointerInView:self.
|
|
921 |
self cursor:Cursor upRightArrow
|
|
922 |
]
|
|
923 |
! !
|
|
924 |
|
|
925 |
!PullDownMenu methodsFor:'drawing '!
|
0
|
926 |
|
110
|
927 |
redraw
|
128
|
928 |
|x "{ Class: SmallInteger }"
|
110
|
929 |
y "{ Class: SmallInteger }"
|
|
930 |
index "{ Class: SmallInteger }"
|
133
|
931 |
wSpace clr|
|
110
|
932 |
|
|
933 |
shown ifFalse: [ ^ self ].
|
|
934 |
titles isNil ifTrue:[^ self].
|
|
935 |
|
|
936 |
wSpace := (font widthOf:' ').
|
|
937 |
x := 0.
|
|
938 |
y := height "- 1".
|
|
939 |
index := 1.
|
|
940 |
titles do:[:title |
|
|
941 |
self drawTitle:title x:x selected:(index == activeMenuNumber).
|
|
942 |
|
|
943 |
title isString ifTrue:[
|
|
944 |
x := x + (font widthOf:title).
|
|
945 |
] ifFalse:[
|
|
946 |
x := x + title width
|
|
947 |
].
|
|
948 |
x := x + wSpace + wSpace.
|
|
949 |
showSeparatingLines ifTrue:[
|
|
950 |
self is3D ifTrue:[
|
|
951 |
self paint:shadowColor.
|
|
952 |
self displayLineFromX:x y:0 toX:x y:y.
|
|
953 |
x := x + 1.
|
133
|
954 |
clr := lightColor.
|
110
|
955 |
] ifFalse:[
|
133
|
956 |
clr := fgColor.
|
110
|
957 |
].
|
133
|
958 |
self paint:clr.
|
110
|
959 |
self displayLineFromX:x y:0 toX:x y:y.
|
|
960 |
x := x + 1
|
|
961 |
].
|
|
962 |
index := index + 1
|
|
963 |
]
|
|
964 |
!
|
|
965 |
|
|
966 |
drawTitle:stringOrImage x:x0 selected:selected
|
133
|
967 |
|y w x wSpace fg bg|
|
|
968 |
|
|
969 |
selected ifTrue:[
|
|
970 |
fg := activeFgColor.
|
|
971 |
bg := activeBgColor
|
|
972 |
] ifFalse:[
|
|
973 |
fg := fgColor.
|
|
974 |
bg := bgColor
|
|
975 |
].
|
110
|
976 |
|
|
977 |
wSpace := font widthOf:' '.
|
|
978 |
x := x0.
|
|
979 |
stringOrImage isString ifTrue:[
|
|
980 |
y := ((height - (font height)) // 2) + (font ascent) "+ topMargin".
|
|
981 |
w := font widthOf:stringOrImage.
|
|
982 |
] ifFalse:[
|
|
983 |
y := ((height - stringOrImage height) // 2) max:0.
|
|
984 |
w := stringOrImage width
|
|
985 |
].
|
|
986 |
w := w + (wSpace * 2).
|
|
987 |
|
133
|
988 |
self paint:bg.
|
0
|
989 |
self fillRectangleX:x y:0 width:w height:height.
|
|
990 |
|
|
991 |
self is3D ifTrue:[
|
59
|
992 |
self drawEdgesForX:x y:0
|
|
993 |
width:w
|
|
994 |
height:height
|
|
995 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel])
|
0
|
996 |
].
|
133
|
997 |
self paint:fg.
|
110
|
998 |
x := x + wSpace.
|
|
999 |
stringOrImage isString ifTrue:[
|
|
1000 |
self displayString:stringOrImage x:x y:y
|
|
1001 |
] ifFalse:[
|
|
1002 |
self displayForm:stringOrImage x:x y:y
|
|
1003 |
]
|
0
|
1004 |
!
|
|
1005 |
|
133
|
1006 |
drawActiveTitleSelected:selected
|
110
|
1007 |
|x|
|
0
|
1008 |
activeMenuNumber notNil ifTrue:[
|
59
|
1009 |
x := self titleLenUpTo:activeMenuNumber.
|
133
|
1010 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:selected
|
0
|
1011 |
]
|
|
1012 |
!
|
|
1013 |
|
133
|
1014 |
highlightActiveTitle
|
|
1015 |
self drawActiveTitleSelected:true
|
|
1016 |
!
|
|
1017 |
|
0
|
1018 |
unHighlightActiveTitle
|
133
|
1019 |
self drawActiveTitleSelected:false
|
110
|
1020 |
! !
|
0
|
1021 |
|
110
|
1022 |
!PullDownMenu methodsFor:'submenu notifications'!
|
0
|
1023 |
|
110
|
1024 |
showActive
|
128
|
1025 |
"sent by a menu to tell me that it starts to perform
|
|
1026 |
its menu action."
|
131
|
1027 |
|
|
1028 |
windowGroup notNil ifTrue:[windowGroup showCursor:Cursor wait]
|
38
|
1029 |
!
|
|
1030 |
|
110
|
1031 |
showPassive
|
128
|
1032 |
"sent by a menu to tell me that it finished its menu-action.
|
|
1033 |
Here, we hide the currently active menu."
|
0
|
1034 |
|
131
|
1035 |
self hideActiveMenu.
|
|
1036 |
windowGroup notNil ifTrue:[windowGroup restoreCursors]
|
77
|
1037 |
!
|
|
1038 |
|
110
|
1039 |
submenuTriggered
|
|
1040 |
"sent by a sub-submenu to tell me that it finished its menu-action."
|
|
1041 |
|
|
1042 |
self showPassive
|
0
|
1043 |
! !
|
|
1044 |
|
70
|
1045 |
!PullDownMenu methodsFor:'event handling'!
|
0
|
1046 |
|
128
|
1047 |
showNoFocus
|
|
1048 |
"when stepping focus, hide any active menu"
|
|
1049 |
|
|
1050 |
self hideActiveMenu.
|
|
1051 |
super showNoFocus
|
|
1052 |
!
|
|
1053 |
|
112
|
1054 |
keyPress:key x:x y:y
|
128
|
1055 |
|index m sel|
|
112
|
1056 |
|
|
1057 |
"
|
|
1058 |
handle CursorLeft/Right for non-mouse operation
|
133
|
1059 |
(for example, if it has the explicit focus)
|
|
1060 |
These will pull the previous/next menu
|
112
|
1061 |
"
|
|
1062 |
((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[
|
|
1063 |
activeMenuNumber isNil ifTrue:[
|
|
1064 |
index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size].
|
|
1065 |
] ifFalse:[
|
|
1066 |
(key == #CursorRight) ifTrue:[
|
|
1067 |
index := activeMenuNumber+1
|
|
1068 |
] ifFalse:[
|
|
1069 |
index := activeMenuNumber-1
|
|
1070 |
].
|
|
1071 |
index == 0 ifTrue:[index := menus size]
|
|
1072 |
ifFalse:[
|
|
1073 |
index > menus size ifTrue:[index := 1]
|
|
1074 |
]
|
|
1075 |
].
|
128
|
1076 |
self pullMenu:index.
|
112
|
1077 |
^ self
|
|
1078 |
].
|
|
1079 |
|
|
1080 |
activeMenuNumber isNil ifTrue:[^self].
|
|
1081 |
|
|
1082 |
"
|
133
|
1083 |
Return, space or the (virtual) MenuSelect key trigger
|
|
1084 |
a menu entry (for non-submenu entries).
|
|
1085 |
Otherwise, if we have a submenu open,
|
|
1086 |
pass the key on to it ...
|
112
|
1087 |
"
|
|
1088 |
m := menus at:activeMenuNumber.
|
128
|
1089 |
m isNil ifTrue:[
|
133
|
1090 |
(key == #Return
|
|
1091 |
or:[key == #MenuSelect
|
|
1092 |
or:[key == Character space]]) ifTrue:[
|
128
|
1093 |
sel := selectors at:activeMenuNumber.
|
|
1094 |
sel notNil ifTrue:[
|
|
1095 |
receiver perform:sel
|
|
1096 |
]
|
|
1097 |
].
|
|
1098 |
] ifFalse:[
|
|
1099 |
m keyPress:key x:0 y:0.
|
|
1100 |
].
|
112
|
1101 |
!
|
|
1102 |
|
110
|
1103 |
buttonPress:button x:x y:y
|
|
1104 |
|titleIndex activeMenu activeLeft activeTop m|
|
0
|
1105 |
|
110
|
1106 |
device ungrabPointer.
|
38
|
1107 |
|
|
1108 |
(y between:0 and:height) ifTrue:[
|
59
|
1109 |
titleIndex := self titleIndexForX:x.
|
38
|
1110 |
].
|
0
|
1111 |
|
38
|
1112 |
"
|
|
1113 |
now, titleIndex is non-nil if pressed within myself
|
|
1114 |
"
|
|
1115 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
|
110
|
1116 |
m := self pullMenu:titleIndex.
|
|
1117 |
(keepMenu and:[m notNil]) ifTrue:[
|
77
|
1118 |
device grabPointerInView:self.
|
59
|
1119 |
self cursor:Cursor upRightArrow
|
|
1120 |
]
|
38
|
1121 |
] ifFalse:[
|
110
|
1122 |
(keepMenu and:[toggleKeep not]) ifTrue:[
|
59
|
1123 |
titleIndex == activeMenuNumber ifTrue:[
|
|
1124 |
"same pressed again ... stay"
|
110
|
1125 |
device grabPointerInView:self.
|
59
|
1126 |
^ self
|
|
1127 |
].
|
|
1128 |
"moving around below"
|
|
1129 |
activeMenuNumber isNil ifTrue:[^self].
|
|
1130 |
activeMenu := menus at:activeMenuNumber.
|
|
1131 |
activeLeft := activeMenu left.
|
|
1132 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
1133 |
activeTop := activeMenu top.
|
|
1134 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
1135 |
"moving around in menu"
|
|
1136 |
activeMenu buttonPress:button
|
|
1137 |
x:(x - activeLeft)
|
|
1138 |
y:(y - activeTop).
|
|
1139 |
^ self
|
|
1140 |
]
|
|
1141 |
].
|
|
1142 |
].
|
|
1143 |
self hideActiveMenu
|
0
|
1144 |
]
|
|
1145 |
!
|
|
1146 |
|
|
1147 |
buttonMotion:button x:x y:y
|
|
1148 |
|titleIndex activeMenu activeLeft activeTop|
|
|
1149 |
|
116
|
1150 |
activeMenuNumber notNil ifTrue:[
|
|
1151 |
activeMenu := menus at:activeMenuNumber.
|
|
1152 |
].
|
|
1153 |
|
0
|
1154 |
(y < height) ifTrue:[
|
59
|
1155 |
"moving around in title line"
|
116
|
1156 |
activeMenu notNil ifTrue:[
|
|
1157 |
activeMenu selection:nil
|
59
|
1158 |
].
|
|
1159 |
titleIndex := self titleIndexForX:x.
|
|
1160 |
titleIndex notNil ifTrue:[
|
|
1161 |
(titleIndex ~~ activeMenuNumber) ifTrue:[
|
|
1162 |
self pullMenu:titleIndex
|
|
1163 |
]
|
128
|
1164 |
] ifFalse:[
|
|
1165 |
self hideActiveMenu
|
59
|
1166 |
]
|
0
|
1167 |
] ifFalse:[
|
59
|
1168 |
"moving around below"
|
116
|
1169 |
activeMenu isNil ifTrue:[^self].
|
59
|
1170 |
activeLeft := activeMenu left.
|
|
1171 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
1172 |
activeTop := activeMenu top.
|
|
1173 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
1174 |
"moving around in menu"
|
|
1175 |
activeMenu buttonMotion:button
|
|
1176 |
x:(x - activeLeft)
|
|
1177 |
y:(y - activeTop).
|
|
1178 |
^ self
|
|
1179 |
]
|
|
1180 |
].
|
|
1181 |
"moved outside menu"
|
|
1182 |
activeMenu selection:nil
|
0
|
1183 |
]
|
|
1184 |
!
|
|
1185 |
|
|
1186 |
buttonRelease:button x:x y:y
|
128
|
1187 |
|activeMenu activeLeft activeTop hideMenu sel|
|
|
1188 |
|
|
1189 |
activeMenuNumber isNil ifTrue:[^self].
|
|
1190 |
activeMenu := menus at:activeMenuNumber.
|
0
|
1191 |
|
38
|
1192 |
hideMenu := false.
|
0
|
1193 |
(y >= height) ifTrue:[
|
59
|
1194 |
"release below title-line"
|
|
1195 |
activeLeft := activeMenu left.
|
|
1196 |
"
|
|
1197 |
released in a submenu ?
|
|
1198 |
"
|
|
1199 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
1200 |
activeTop := activeMenu top.
|
|
1201 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
1202 |
"release in menu"
|
|
1203 |
self hideActiveMenu.
|
|
1204 |
activeMenu buttonRelease:button
|
|
1205 |
x:(x - activeLeft)
|
|
1206 |
y:(y - activeTop).
|
|
1207 |
^ self
|
|
1208 |
]
|
|
1209 |
].
|
|
1210 |
hideMenu := true.
|
38
|
1211 |
] ifFalse:[
|
59
|
1212 |
y < 0 ifTrue:[
|
|
1213 |
hideMenu := true
|
|
1214 |
] ifFalse:[
|
128
|
1215 |
activeMenu isNil ifTrue:[
|
131
|
1216 |
selectors notNil ifTrue:[
|
|
1217 |
sel := selectors at:activeMenuNumber.
|
|
1218 |
sel notNil ifTrue:[
|
|
1219 |
receiver perform:sel
|
|
1220 |
].
|
128
|
1221 |
].
|
|
1222 |
hideMenu := true.
|
|
1223 |
] ifFalse:[
|
|
1224 |
keepMenu ifFalse:[
|
|
1225 |
hideMenu := true
|
|
1226 |
]
|
59
|
1227 |
]
|
|
1228 |
]
|
38
|
1229 |
].
|
|
1230 |
hideMenu ifTrue:[
|
|
1231 |
self hideActiveMenu.
|
|
1232 |
]
|
0
|
1233 |
! !
|