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