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 |
|
|
13 |
PopUpView subclass:#PopUpMenu
|
|
14 |
instanceVariableNames:'menuView lastSelection memorize hideOnLeave
|
59
|
15 |
actionLabels actionLines actionValues'
|
0
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Menus'
|
|
19 |
!
|
|
20 |
|
|
21 |
PopUpMenu comment:'
|
5
|
22 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
23 |
All Rights Reserved
|
0
|
24 |
|
59
|
25 |
$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.8 1994-10-10 03:02:35 claus Exp $
|
0
|
26 |
'!
|
|
27 |
|
38
|
28 |
!PopUpMenu class methodsFor:'documentation'!
|
|
29 |
|
|
30 |
copyright
|
|
31 |
"
|
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
33 |
All Rights Reserved
|
38
|
34 |
|
|
35 |
This software is furnished under a license and may be used
|
|
36 |
only in accordance with the terms of that license and with the
|
|
37 |
inclusion of the above copyright notice. This software may not
|
|
38 |
be provided or otherwise made available to, or used by, any
|
|
39 |
other person. No title to or ownership of the software is
|
|
40 |
hereby transferred.
|
|
41 |
"
|
|
42 |
!
|
|
43 |
|
|
44 |
version
|
|
45 |
"
|
59
|
46 |
$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.8 1994-10-10 03:02:35 claus Exp $
|
38
|
47 |
"
|
|
48 |
!
|
|
49 |
|
|
50 |
documentation
|
|
51 |
"
|
|
52 |
This class provides PopUpMenu functionality; Actually, this class
|
|
53 |
only provides the popup and shadow functionality and wraps another
|
|
54 |
view, which is the actual menu-list (usually an instance of MenuView).
|
|
55 |
|
|
56 |
PopUpMenus are usually created with a list of labels, selectors and a
|
|
57 |
receivier. Once activated, the specified receiver will be sent a
|
|
58 |
'selector'-message.
|
|
59 |
|
|
60 |
Examples:
|
|
61 |
|
59
|
62 |
|p|
|
|
63 |
p := PopUpMenu
|
|
64 |
labels:#('foo'
|
|
65 |
'bar'
|
|
66 |
'baz')
|
|
67 |
selectors:#(
|
|
68 |
#foo
|
|
69 |
#bar
|
|
70 |
#baz)
|
|
71 |
receiver:nil.
|
|
72 |
p showAtPointer
|
38
|
73 |
|
|
74 |
|
|
75 |
sometimes, you want to specify both selectors and some arguments
|
|
76 |
to be sent; this is done by:
|
|
77 |
|
59
|
78 |
|p|
|
|
79 |
p := PopUpMenu
|
|
80 |
labels:#('foo' 'bar' 'baz')
|
|
81 |
selectors:#(#foo: #bar: #foo:)
|
|
82 |
args:#(1 2 3)
|
|
83 |
receiver:nil.
|
|
84 |
p showAtPointer
|
38
|
85 |
|
|
86 |
or, the same selector but different arguments:
|
|
87 |
|
59
|
88 |
|p|
|
|
89 |
p := PopUpMenu
|
|
90 |
labels:#('foo' 'bar' 'baz')
|
|
91 |
selectors:#foo:
|
|
92 |
args:#(1 2 3)
|
|
93 |
receiver:nil.
|
|
94 |
p showAtPointer
|
38
|
95 |
|
|
96 |
Normally, you do not show the menu explicitely, but install
|
|
97 |
it as a middleButtonMenu of some view. (Views button-event handler
|
|
98 |
will show it when the button is pressed ...)
|
|
99 |
|
59
|
100 |
|v m|
|
38
|
101 |
|
59
|
102 |
v := View new.
|
|
103 |
m := PopUpMenu
|
|
104 |
labels:#('lower'
|
|
105 |
'raise'
|
|
106 |
'-'
|
|
107 |
'destroy')
|
|
108 |
selectors:#(#lower #raise nil #destroy)
|
|
109 |
receiver:v.
|
|
110 |
v middleButtonMenu:m.
|
|
111 |
v open
|
38
|
112 |
|
|
113 |
It is also possible, to add check-mark entries, with an entry string
|
|
114 |
starting with the special sequence '\c' (for check-mark). The value
|
|
115 |
passed will be the truth-state of the check-mark.
|
|
116 |
|
59
|
117 |
|m v|
|
38
|
118 |
|
59
|
119 |
v := View new.
|
|
120 |
m := PopUpMenu
|
|
121 |
labels:#('\c foo'
|
|
122 |
'\c bar')
|
|
123 |
selectors:#(#value: #value:)
|
|
124 |
receiver:[:v | Transcript show:'arg: '; showCr:v].
|
|
125 |
v middleButtonMenu:m.
|
|
126 |
v open
|
38
|
127 |
|
|
128 |
|
|
129 |
Finally, you can wrap other views into a popup menu (for example,
|
|
130 |
to implement menus with icons or other components).
|
|
131 |
The view should respond to some messages sent from here (for
|
|
132 |
example: #hideSubmenus, #deselectWithoutRedraw and others).
|
|
133 |
Currently there is only one class in the system, which can be used
|
|
134 |
this way (PatternMenu in the DrawTool demo):
|
|
135 |
|
59
|
136 |
|v p|
|
38
|
137 |
|
59
|
138 |
v := View new.
|
|
139 |
p := PatternMenu new.
|
|
140 |
p patterns:(Array with:Color red
|
|
141 |
with:Color green
|
|
142 |
with:Color blue).
|
|
143 |
v middleButtonMenu:(PopUpMenu forMenu:p).
|
|
144 |
v open
|
38
|
145 |
|
|
146 |
or try:
|
|
147 |
|
59
|
148 |
|v p|
|
38
|
149 |
|
59
|
150 |
v := View new.
|
|
151 |
p := PatternMenu new.
|
|
152 |
p patterns:(Array with:Color red
|
|
153 |
with:Color green
|
|
154 |
with:Color blue).
|
|
155 |
p selectors:#value:.
|
|
156 |
p receiver:[:val | v viewBackground:val. v clear].
|
|
157 |
p args:(Array with:Color red
|
|
158 |
with:Color green
|
|
159 |
with:Color blue).
|
|
160 |
v middleButtonMenu:(PopUpMenu forMenu:p).
|
|
161 |
v open
|
38
|
162 |
|
|
163 |
|
|
164 |
ST-80 style:
|
|
165 |
|
|
166 |
The above menus all did some message send on selection; it is
|
|
167 |
also possible, to use Smalltalk-80 style menus (which return some value
|
|
168 |
from their startup method):
|
|
169 |
|
59
|
170 |
|m selection|
|
38
|
171 |
|
59
|
172 |
m := PopUpMenu
|
|
173 |
labels:#('one' 'two' 'three').
|
|
174 |
selection := m startUp.
|
|
175 |
Transcript show:'the selection was: '; showCr:selection
|
38
|
176 |
|
|
177 |
startUp will return the entries index, or 0 if there was no selection.
|
|
178 |
You can also specify an array of values to be returned instead of the
|
|
179 |
index:
|
|
180 |
|
59
|
181 |
|m selection|
|
38
|
182 |
|
59
|
183 |
m := PopUpMenu
|
|
184 |
labels:#('one' 'two' 'three')
|
|
185 |
values:#(10 20 30).
|
|
186 |
selection := m startUp.
|
|
187 |
Transcript show:'the value was: '; showCr:selection
|
38
|
188 |
|
|
189 |
In ST/X style menus, separating lines between entries are created
|
|
190 |
by a '-'-string as its label text (and corresponding nil-entries in the
|
|
191 |
selectors- and args-arrays).
|
|
192 |
In ST-80, you have to pass the indices of the lines in an extra array:
|
|
193 |
|
59
|
194 |
|m selection|
|
38
|
195 |
|
59
|
196 |
m := PopUpMenu
|
|
197 |
labels:#('one' 'two' 'three' 'four' 'five')
|
|
198 |
lines:#(2 4).
|
|
199 |
selection := m startUp.
|
|
200 |
Transcript show:'the value was: '; showCr:selection
|
38
|
201 |
|
|
202 |
or:
|
59
|
203 |
|m selection|
|
38
|
204 |
|
59
|
205 |
m := PopUpMenu
|
|
206 |
labels:#('one' 'two' 'three')
|
|
207 |
lines:#(2)
|
|
208 |
values:#(10 20 30).
|
|
209 |
selection := m startUp.
|
|
210 |
Transcript show:'the value was: '; showCr:selection
|
38
|
211 |
|
|
212 |
Use whichever interface you prefer.
|
|
213 |
"
|
|
214 |
! !
|
|
215 |
|
0
|
216 |
!PopUpMenu class methodsFor:'instance creation'!
|
|
217 |
|
38
|
218 |
onSameDeviceAs:aView
|
|
219 |
"this takes care of the device on which the view (for which
|
|
220 |
the popup-menu is to be created) is located."
|
|
221 |
|
|
222 |
aView isNil ifTrue:[
|
59
|
223 |
^ self on:Display
|
38
|
224 |
].
|
|
225 |
^ self on:(aView device)
|
|
226 |
!
|
|
227 |
|
|
228 |
forMenu:aMenuView
|
|
229 |
"this wraps an already existing menu - allowing to put any
|
|
230 |
view (not just MenuViews) into popups (for example, menus
|
|
231 |
with icons, or other components).
|
|
232 |
Currently, there is only one example of different menus in
|
|
233 |
the system (PatternMenu in the DrawTool) which could be used
|
|
234 |
this way.
|
|
235 |
The view should respond to some of the menuView messages
|
|
236 |
(such as hideSubmenu, deselectWithoutRedraw etc.)"
|
|
237 |
|
|
238 |
|newMenu|
|
|
239 |
|
|
240 |
newMenu := self onSameDeviceAs:aMenuView.
|
|
241 |
newMenu addSubView:aMenuView.
|
|
242 |
newMenu menu:aMenuView.
|
|
243 |
^ newMenu
|
|
244 |
!
|
|
245 |
|
0
|
246 |
labels:labels selectors:selectors receiver:anObject for:aView
|
|
247 |
|newMenu|
|
|
248 |
|
38
|
249 |
newMenu := self onSameDeviceAs:aView.
|
|
250 |
newMenu menu:(MenuView
|
59
|
251 |
labels:labels
|
|
252 |
selectors:selectors
|
|
253 |
receiver:anObject
|
|
254 |
in:newMenu).
|
38
|
255 |
^ newMenu
|
0
|
256 |
!
|
|
257 |
|
|
258 |
labels:labels selectors:selectors args:args receiver:anObject
|
|
259 |
^ self labels:labels
|
59
|
260 |
selectors:selectors
|
|
261 |
args:args
|
|
262 |
receiver:anObject
|
|
263 |
for:nil
|
38
|
264 |
!
|
|
265 |
|
|
266 |
labels:labels selectors:selectors args:args receiver:anObject for:aView
|
|
267 |
|newMenu|
|
|
268 |
|
|
269 |
newMenu := self onSameDeviceAs:aView.
|
|
270 |
newMenu menu:(MenuView
|
59
|
271 |
labels:labels
|
|
272 |
selectors:selectors
|
|
273 |
args:args
|
|
274 |
receiver:anObject
|
|
275 |
in:newMenu).
|
38
|
276 |
^ newMenu
|
|
277 |
!
|
|
278 |
|
|
279 |
labels:labels selector:aSelector args:args receiver:anObject
|
|
280 |
^ self labels:labels
|
59
|
281 |
selector:aSelector
|
|
282 |
args:args
|
|
283 |
receiver:anObject
|
|
284 |
for:nil
|
38
|
285 |
!
|
|
286 |
|
|
287 |
labels:labels selectors:selectors receiver:anObject
|
|
288 |
^ self labels:labels selectors:selectors receiver:anObject for:nil
|
|
289 |
!
|
|
290 |
|
|
291 |
labels:labels selector:aSelector args:args receiver:anObject for:aView
|
|
292 |
|newMenu|
|
|
293 |
|
|
294 |
newMenu := self onSameDeviceAs:aView.
|
|
295 |
newMenu menu:(MenuView
|
59
|
296 |
labels:labels
|
|
297 |
selector:aSelector
|
|
298 |
args:args
|
|
299 |
receiver:anObject
|
|
300 |
in:newMenu).
|
38
|
301 |
^ newMenu
|
0
|
302 |
! !
|
|
303 |
|
|
304 |
!PopUpMenu class methodsFor:'ST-80 instance creation'!
|
|
305 |
|
|
306 |
labels:labels
|
|
307 |
^ self labels:labels lines:nil values:nil
|
|
308 |
!
|
|
309 |
|
|
310 |
labels:labels values:values
|
|
311 |
^ self labels:labels lines:nil values:values
|
|
312 |
!
|
|
313 |
|
|
314 |
labels:labels lines:lines
|
|
315 |
^ self labels:labels lines:lines values:nil
|
|
316 |
!
|
|
317 |
|
|
318 |
labels:labels lines:lines values:values
|
|
319 |
^ (self new) labels:labels lines:lines values:values
|
|
320 |
!
|
|
321 |
|
|
322 |
labelList:labels values:values
|
|
323 |
^ self labels:labels lines:nil values:values
|
|
324 |
!
|
|
325 |
|
|
326 |
labelList:labels lines:lines values:values
|
|
327 |
^ (self new) labels:labels lines:lines values:values
|
|
328 |
! !
|
|
329 |
|
|
330 |
!PopUpMenu methodsFor:'initialization'!
|
|
331 |
|
|
332 |
initialize
|
|
333 |
super initialize.
|
59
|
334 |
|
|
335 |
"dont need any fancy colors"
|
|
336 |
"/ viewBackground := White on:device.
|
|
337 |
|
0
|
338 |
memorize := true.
|
21
|
339 |
hideOnLeave := false.
|
|
340 |
style == #iris ifTrue:[
|
59
|
341 |
borderWidth := 1
|
21
|
342 |
].
|
38
|
343 |
(style == #st80) ifTrue:[
|
59
|
344 |
"/ viewBackground := White.
|
|
345 |
borderWidth := 1.
|
|
346 |
level := 0.
|
|
347 |
margin := 0.
|
|
348 |
shadowView := nil
|
38
|
349 |
].
|
0
|
350 |
!
|
|
351 |
|
|
352 |
initEvents
|
|
353 |
super initEvents.
|
|
354 |
self enableEnterLeaveEvents.
|
|
355 |
self enableButtonMotionEvents.
|
|
356 |
self enableMotionEvents.
|
|
357 |
self enableButtonEvents
|
|
358 |
! !
|
|
359 |
|
|
360 |
!PopUpMenu methodsFor:'realization'!
|
|
361 |
|
|
362 |
fixSize
|
|
363 |
"adjust my size to the size of the actual menu"
|
|
364 |
|
|
365 |
|extra newWidth newHeight|
|
|
366 |
|
|
367 |
extra := margin * 2.
|
|
368 |
newWidth := menuView width + extra.
|
|
369 |
newHeight := menuView height + extra.
|
|
370 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[
|
59
|
371 |
self extent:(menuView width + extra) @ (menuView height + extra)
|
0
|
372 |
].
|
|
373 |
super fixSize
|
|
374 |
!
|
|
375 |
|
|
376 |
realize
|
38
|
377 |
"/ windowGroup notNil ifTrue:[
|
|
378 |
"/ windowGroup sensor compressMotionEvents:true
|
|
379 |
"/ ].
|
|
380 |
|
0
|
381 |
menuView deselectWithoutRedraw.
|
38
|
382 |
"/ self enableEnterLeaveEvents.
|
0
|
383 |
super realize.
|
|
384 |
|
38
|
385 |
"/ menuView disableButtonMotionEvents.
|
|
386 |
"/ menuView disableMotionEvents.
|
|
387 |
"/ menuView disableButtonEvents.
|
|
388 |
"/ menuView disableEnterLeaveEvents
|
0
|
389 |
! !
|
|
390 |
|
|
391 |
!PopUpMenu methodsFor:'private accessing'!
|
|
392 |
|
|
393 |
menu:aMenu
|
|
394 |
"set the actual menu"
|
|
395 |
|
|
396 |
menuView := aMenu.
|
|
397 |
menuView origin:(margin @ margin).
|
|
398 |
menuView borderWidth:0
|
|
399 |
!
|
|
400 |
|
|
401 |
menuView
|
|
402 |
"return the actual menu"
|
|
403 |
|
|
404 |
^ menuView
|
7
|
405 |
!
|
|
406 |
|
|
407 |
superMenu:aMenu
|
|
408 |
"return the superMenu"
|
|
409 |
|
|
410 |
menuView superMenu:aMenu
|
0
|
411 |
! !
|
|
412 |
|
59
|
413 |
!PopUpMenu methodsFor:'menuview messages'!
|
|
414 |
|
|
415 |
doesNotUnderstand:aMessage
|
|
416 |
"forward all menu-view messages"
|
|
417 |
|
|
418 |
(menuView respondsTo:(aMessage selector)) ifTrue:[
|
|
419 |
^ aMessage sendTo:menuView
|
|
420 |
].
|
|
421 |
^ super doesNotUnderstand:aMessage
|
|
422 |
! !
|
|
423 |
|
0
|
424 |
!PopUpMenu methodsFor:'accessing'!
|
|
425 |
|
|
426 |
viewBackground:aColor
|
|
427 |
"this is a kludge and will vanish ..."
|
|
428 |
|
|
429 |
super viewBackground:aColor.
|
|
430 |
menuView viewBackground:aColor
|
|
431 |
!
|
|
432 |
|
|
433 |
hideOnLeave:aBoolean
|
|
434 |
"set/clear the hideOnLeave attribute, which controls
|
|
435 |
if the menu should be hidden when the pointer leaves
|
|
436 |
the view (used with multiple-menus)"
|
|
437 |
|
|
438 |
hideOnLeave := aBoolean
|
|
439 |
!
|
|
440 |
|
21
|
441 |
font:aFont
|
|
442 |
menuView font:aFont
|
|
443 |
!
|
|
444 |
|
|
445 |
labels
|
|
446 |
"return the list of labels"
|
|
447 |
|
|
448 |
actionLabels notNil ifTrue:[
|
59
|
449 |
^ actionLabels asText
|
21
|
450 |
].
|
|
451 |
^ menuView list
|
|
452 |
!
|
|
453 |
|
38
|
454 |
indexOf:indexOrName
|
|
455 |
"return the index of a submenu - or 0 if there is none"
|
|
456 |
|
|
457 |
^ menuView indexOf:indexOrName
|
|
458 |
!
|
|
459 |
|
|
460 |
remove:indexOrName
|
|
461 |
"remove a menu entry"
|
|
462 |
|
|
463 |
menuView remove:indexOrName
|
|
464 |
!
|
|
465 |
|
0
|
466 |
subMenuAt:indexOrName put:aMenu
|
|
467 |
"define a submenu to be shown for entry indexOrName"
|
|
468 |
|
7
|
469 |
"
|
0
|
470 |
aMenu hideOnLeave:true.
|
7
|
471 |
"
|
|
472 |
menuView subMenuAt:indexOrName put:aMenu.
|
|
473 |
"tell the submenu to notify me when action is performed"
|
|
474 |
aMenu superMenu:self.
|
0
|
475 |
|
|
476 |
"|v m|
|
|
477 |
v := View new.
|
|
478 |
m := PopUpMenu labels:#('1' '2' '3')
|
59
|
479 |
selectors:#(one two nil)
|
|
480 |
receiver:v
|
|
481 |
for:nil.
|
0
|
482 |
m subMenuAt:3 put:(PopUpMenu
|
59
|
483 |
labels:#('a' 'b' 'c')
|
|
484 |
selectors:#(a b c)
|
|
485 |
receiver:v
|
|
486 |
for:nil).
|
0
|
487 |
v middleButtonMenu:m.
|
|
488 |
v realize"
|
|
489 |
!
|
|
490 |
|
|
491 |
numberOfItems
|
21
|
492 |
"return the number of items in the menu"
|
0
|
493 |
|
21
|
494 |
actionLabels notNil ifTrue:[
|
59
|
495 |
^ actionLabels asText size
|
21
|
496 |
].
|
|
497 |
^ menuView list size
|
0
|
498 |
!
|
|
499 |
|
|
500 |
values
|
21
|
501 |
"st-80 compatibility"
|
|
502 |
|
0
|
503 |
^ actionValues
|
|
504 |
!
|
|
505 |
|
|
506 |
lines
|
21
|
507 |
"st-80 compatibility"
|
|
508 |
|
0
|
509 |
^ actionLines
|
|
510 |
!
|
|
511 |
|
|
512 |
labels:labelString lines:lineArray values:valueArray
|
21
|
513 |
"define the menu the ST-80 way (with labels and lines defined separately)"
|
0
|
514 |
|
|
515 |
|labelArray argArray convertedLabels
|
|
516 |
offs dstOffs linePos|
|
|
517 |
|
|
518 |
actionLabels := labelString.
|
|
519 |
actionLines := lineArray.
|
|
520 |
actionValues := valueArray.
|
|
521 |
|
|
522 |
labelArray := labelString asText.
|
|
523 |
|
|
524 |
convertedLabels := Array new:(labelArray size + lineArray size).
|
|
525 |
argArray := Array new:(labelArray size + lineArray size).
|
|
526 |
|
|
527 |
offs := 1.
|
|
528 |
dstOffs := 1.
|
|
529 |
1 to:lineArray size do:[:lineIndex |
|
59
|
530 |
linePos := lineArray at:lineIndex.
|
|
531 |
[offs <= linePos] whileTrue:[
|
|
532 |
convertedLabels at:dstOffs put:(labelArray at:offs).
|
|
533 |
argArray at:dstOffs put:offs.
|
|
534 |
offs := offs + 1.
|
|
535 |
dstOffs := dstOffs + 1
|
|
536 |
].
|
|
537 |
convertedLabels at:dstOffs put:'-'.
|
|
538 |
argArray at:dstOffs put:nil.
|
|
539 |
dstOffs := dstOffs + 1
|
0
|
540 |
].
|
|
541 |
[offs <= labelArray size] whileTrue:[
|
59
|
542 |
convertedLabels at:dstOffs put:(labelArray at:offs).
|
|
543 |
argArray at:dstOffs put:offs.
|
|
544 |
offs := offs + 1.
|
|
545 |
dstOffs := dstOffs + 1
|
0
|
546 |
].
|
|
547 |
self menu:(MenuView
|
59
|
548 |
labels:convertedLabels
|
|
549 |
selector:nil
|
|
550 |
args:argArray
|
|
551 |
receiver:nil
|
|
552 |
in:self)
|
0
|
553 |
! !
|
|
554 |
|
|
555 |
!PopUpMenu methodsFor:'activation'!
|
|
556 |
|
21
|
557 |
showAt:aPoint resizing:aBoolean
|
|
558 |
"realize the menu at aPoint"
|
0
|
559 |
|
21
|
560 |
aBoolean ifTrue:[
|
59
|
561 |
self fixSize.
|
21
|
562 |
].
|
0
|
563 |
self origin:aPoint.
|
38
|
564 |
self makeFullyVisible.
|
|
565 |
self openModal:[true] "realize "
|
0
|
566 |
!
|
|
567 |
|
21
|
568 |
showAt:aPoint
|
|
569 |
"realize the menu at aPoint"
|
|
570 |
|
|
571 |
self showAt:aPoint resizing:true
|
|
572 |
!
|
|
573 |
|
0
|
574 |
showAtPointer
|
21
|
575 |
"realize the menu at the current pointer position"
|
0
|
576 |
|
21
|
577 |
self showAt:(device pointerPosition) resizing:true
|
0
|
578 |
!
|
|
579 |
|
|
580 |
show
|
21
|
581 |
"realize the menu at its last position"
|
0
|
582 |
|
|
583 |
self fixSize.
|
38
|
584 |
self openModal:[true] "realize "
|
0
|
585 |
!
|
|
586 |
|
|
587 |
hide
|
7
|
588 |
"hide the menu - if there are any pop-up-submenus, hide them also"
|
|
589 |
|
|
590 |
menuView hideSubmenu.
|
38
|
591 |
windowGroup notNil ifTrue:[
|
59
|
592 |
windowGroup removeView:self.
|
|
593 |
windowGroup := nil.
|
38
|
594 |
].
|
|
595 |
self unrealize.
|
7
|
596 |
!
|
0
|
597 |
|
38
|
598 |
XXregainControl
|
|
599 |
" "
|
7
|
600 |
device ungrabPointer.
|
|
601 |
device grabPointerIn:drawableId
|
38
|
602 |
" "
|
0
|
603 |
! !
|
|
604 |
|
|
605 |
!PopUpMenu methodsFor:'ST-80 activation'!
|
|
606 |
|
|
607 |
startUp
|
38
|
608 |
"start the menu modal - return the selected value,
|
|
609 |
or - if no values where specified - return the index.
|
0
|
610 |
If nothing was selected, return 0.
|
38
|
611 |
Modal - i.e. stay in the menu until finished.
|
|
612 |
This is the ST-80 way of launching a menu."
|
0
|
613 |
|
|
614 |
menuView action:[:selected |
|
59
|
615 |
|actionIndex value|
|
38
|
616 |
|
59
|
617 |
menuView args isNil ifTrue:[
|
|
618 |
menuView selectors isNil ifTrue:[
|
|
619 |
^ 0
|
|
620 |
].
|
|
621 |
^ menuView receiver perform:(menuView selectors at:selected)
|
|
622 |
].
|
|
623 |
actionIndex := menuView args at:selected.
|
|
624 |
actionIndex isNil ifTrue:[^ 0].
|
|
625 |
actionValues isNil ifTrue:[^ actionIndex].
|
|
626 |
value := actionValues at:actionIndex.
|
|
627 |
(value isKindOf:PopUpMenu) ifTrue:[
|
|
628 |
^ value startUp
|
|
629 |
].
|
|
630 |
^ value
|
0
|
631 |
].
|
|
632 |
self showAtPointer.
|
|
633 |
^ 0
|
38
|
634 |
|
|
635 |
"
|
|
636 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp
|
|
637 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')
|
59
|
638 |
values:#(foo bar baz)) startUp
|
38
|
639 |
"
|
0
|
640 |
! !
|
|
641 |
|
|
642 |
!PopUpMenu methodsFor:'events'!
|
|
643 |
|
|
644 |
buttonMotion:button x:x y:y
|
7
|
645 |
|p|
|
|
646 |
|
38
|
647 |
((x >= 0) and:[x < width]) ifTrue:[
|
59
|
648 |
((y >= 0) and:[y < height]) ifTrue:[
|
|
649 |
menuView buttonMotion:button x:x y:y.
|
|
650 |
^ self
|
|
651 |
]
|
0
|
652 |
].
|
7
|
653 |
|
|
654 |
"outside of myself"
|
|
655 |
menuView superMenu notNil ifTrue:[
|
59
|
656 |
p := device translatePoint:(x @ y)
|
|
657 |
from:drawableId
|
|
658 |
to:(menuView superMenu id).
|
|
659 |
menuView superMenu buttonMotion:button x:p x y:p y
|
7
|
660 |
].
|
|
661 |
|
|
662 |
menuView subMenuShown isNil ifTrue:[
|
59
|
663 |
menuView pointerLeave:button.
|
7
|
664 |
].
|
|
665 |
|
0
|
666 |
hideOnLeave ifTrue:[
|
59
|
667 |
self hide
|
38
|
668 |
].
|
|
669 |
|
|
670 |
"/ menuView superMenu notNil ifTrue:[
|
|
671 |
"/ menuView superMenu regainControl.
|
|
672 |
"/ ].
|
0
|
673 |
!
|
|
674 |
|
7
|
675 |
pointerEnter:state x:x y:y
|
|
676 |
"catch quick release of button"
|
|
677 |
|
|
678 |
state == 0 ifTrue:[^ self hide].
|
|
679 |
!
|
|
680 |
|
0
|
681 |
pointerLeave:state
|
38
|
682 |
"/ menuView pointerLeave:state.
|
|
683 |
"/ hideOnLeave ifTrue:[
|
|
684 |
"/ self hide
|
|
685 |
"/ ].
|
|
686 |
"/ menuView superMenu notNil ifTrue:[
|
|
687 |
"/ menuView superMenu regainControl
|
|
688 |
"/ ]
|
0
|
689 |
!
|
|
690 |
|
|
691 |
buttonRelease:button x:x y:y
|
|
692 |
self hide.
|
7
|
693 |
"
|
|
694 |
menuView buttonRelease:button x:x y:y.
|
|
695 |
"
|
|
696 |
menuView superMenu notNil ifTrue:[
|
59
|
697 |
menuView superMenu submenuTriggered
|
7
|
698 |
].
|
|
699 |
menuView buttonRelease:button x:x y:y.
|
0
|
700 |
! !
|