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
|
105
|
15 |
actionLabels actionLines actionValues
|
|
16 |
hideOnRelease defaultHideOnRelease'
|
119
|
17 |
classVariableNames:'DefaultHideOnRelease'
|
0
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Menus'
|
|
20 |
!
|
|
21 |
|
|
22 |
PopUpMenu comment:'
|
5
|
23 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
24 |
All Rights Reserved
|
0
|
25 |
|
161
|
26 |
$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.25 1995-09-15 23:51:37 claus Exp $
|
0
|
27 |
'!
|
|
28 |
|
38
|
29 |
!PopUpMenu class methodsFor:'documentation'!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
34 |
All Rights Reserved
|
38
|
35 |
|
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
161
|
47 |
$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.25 1995-09-15 23:51:37 claus Exp $
|
38
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
|
53 |
This class provides PopUpMenu functionality; Actually, this class
|
|
54 |
only provides the popup and shadow functionality and wraps another
|
|
55 |
view, which is the actual menu-list (usually an instance of MenuView).
|
|
56 |
|
|
57 |
PopUpMenus are usually created with a list of labels, selectors and a
|
|
58 |
receivier. Once activated, the specified receiver will be sent a
|
|
59 |
'selector'-message.
|
112
|
60 |
|
|
61 |
PopupMenus may be either assigned statically to a view (via the #middleButtonMenu:
|
|
62 |
message) or created dynamically as required.
|
|
63 |
Static definition makes sense, if the menu stays constant and you want to
|
|
64 |
assign it once for the lifetime of the view.
|
|
65 |
|
|
66 |
Dynamic menus are easier to use, if the number of or look of the entries has to
|
|
67 |
change according the internal state of some model. Also, this is the ST-80 way
|
|
68 |
of using popupMenus. For dynamic popups, the views model is asked for a menu
|
|
69 |
via the #menuSelector each time a button press occurs.
|
|
70 |
|
|
71 |
See examples section for more.
|
63
|
72 |
"
|
|
73 |
!
|
38
|
74 |
|
63
|
75 |
examples
|
|
76 |
"
|
38
|
77 |
Examples:
|
|
78 |
|
59
|
79 |
|p|
|
|
80 |
p := PopUpMenu
|
|
81 |
labels:#('foo'
|
|
82 |
'bar'
|
|
83 |
'baz')
|
|
84 |
selectors:#(
|
|
85 |
#foo
|
|
86 |
#bar
|
|
87 |
#baz)
|
|
88 |
receiver:nil.
|
|
89 |
p showAtPointer
|
38
|
90 |
|
|
91 |
|
|
92 |
sometimes, you want to specify both selectors and some arguments
|
|
93 |
to be sent; this is done by:
|
|
94 |
|
59
|
95 |
|p|
|
|
96 |
p := PopUpMenu
|
|
97 |
labels:#('foo' 'bar' 'baz')
|
|
98 |
selectors:#(#foo: #bar: #foo:)
|
|
99 |
args:#(1 2 3)
|
|
100 |
receiver:nil.
|
|
101 |
p showAtPointer
|
38
|
102 |
|
|
103 |
or, the same selector but different arguments:
|
|
104 |
|
59
|
105 |
|p|
|
|
106 |
p := PopUpMenu
|
|
107 |
labels:#('foo' 'bar' 'baz')
|
|
108 |
selectors:#foo:
|
|
109 |
args:#(1 2 3)
|
|
110 |
receiver:nil.
|
|
111 |
p showAtPointer
|
38
|
112 |
|
|
113 |
Normally, you do not show the menu explicitely, but install
|
112
|
114 |
it as a either as middleButtonMenu of some view or return it from
|
|
115 |
a model.
|
|
116 |
(Views/Controllers button-event handler will show it when the middle
|
|
117 |
button is pressed ...)
|
|
118 |
Static menu:
|
38
|
119 |
|
59
|
120 |
|v m|
|
38
|
121 |
|
59
|
122 |
v := View new.
|
|
123 |
m := PopUpMenu
|
|
124 |
labels:#('lower'
|
|
125 |
'raise'
|
|
126 |
'-'
|
|
127 |
'destroy')
|
|
128 |
selectors:#(#lower #raise nil #destroy)
|
|
129 |
receiver:v.
|
|
130 |
v middleButtonMenu:m.
|
|
131 |
v open
|
38
|
132 |
|
112
|
133 |
Dynamic menu:
|
|
134 |
(since we need some model which responds to a menu-message,
|
|
135 |
we use a plug in the example below; normally, this would be your model)
|
|
136 |
|
|
137 |
|v model|
|
|
138 |
|
|
139 |
model := Plug new.
|
119
|
140 |
model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar')
|
|
141 |
selectors:#(foo bar)].
|
112
|
142 |
model respondTo:#foo with:[Transcript showCr:'models foo called'].
|
|
143 |
model respondTo:#bar with:[Transcript showCr:'models bar called'].
|
|
144 |
|
|
145 |
v := View new.
|
|
146 |
v model:model; menu:#getMenu.
|
|
147 |
v open
|
|
148 |
|
|
149 |
Dynamic menus are the MVC-way (i.e. ST-80) way of doing things.
|
|
150 |
They are usually easier to use, if the menu changes depending on the models
|
|
151 |
state. (for example, see the systemBrowsers menus being different when
|
|
152 |
things are selected ...)
|
|
153 |
|
38
|
154 |
It is also possible, to add check-mark entries, with an entry string
|
|
155 |
starting with the special sequence '\c' (for check-mark). The value
|
|
156 |
passed will be the truth-state of the check-mark.
|
|
157 |
|
59
|
158 |
|m v|
|
38
|
159 |
|
59
|
160 |
v := View new.
|
|
161 |
m := PopUpMenu
|
|
162 |
labels:#('\c foo'
|
|
163 |
'\c bar')
|
|
164 |
selectors:#(#value: #value:)
|
|
165 |
receiver:[:v | Transcript show:'arg: '; showCr:v].
|
|
166 |
v middleButtonMenu:m.
|
|
167 |
v open
|
38
|
168 |
|
|
169 |
Finally, you can wrap other views into a popup menu (for example,
|
|
170 |
to implement menus with icons or other components).
|
|
171 |
The view should respond to some messages sent from here (for
|
|
172 |
example: #hideSubmenus, #deselectWithoutRedraw and others).
|
|
173 |
Currently there is only one class in the system, which can be used
|
|
174 |
this way (PatternMenu in the DrawTool demo):
|
|
175 |
|
59
|
176 |
|v p|
|
38
|
177 |
|
59
|
178 |
v := View new.
|
|
179 |
p := PatternMenu new.
|
|
180 |
p patterns:(Array with:Color red
|
|
181 |
with:Color green
|
|
182 |
with:Color blue).
|
|
183 |
v middleButtonMenu:(PopUpMenu forMenu:p).
|
|
184 |
v open
|
38
|
185 |
|
|
186 |
or try:
|
|
187 |
|
59
|
188 |
|v p|
|
38
|
189 |
|
59
|
190 |
v := View new.
|
|
191 |
p := PatternMenu new.
|
|
192 |
p patterns:(Array with:Color red
|
|
193 |
with:Color green
|
|
194 |
with:Color blue).
|
|
195 |
p selectors:#value:.
|
|
196 |
p receiver:[:val | v viewBackground:val. v clear].
|
|
197 |
p args:(Array with:Color red
|
|
198 |
with:Color green
|
|
199 |
with:Color blue).
|
|
200 |
v middleButtonMenu:(PopUpMenu forMenu:p).
|
|
201 |
v open
|
38
|
202 |
|
|
203 |
|
|
204 |
ST-80 style:
|
|
205 |
|
|
206 |
The above menus all did some message send on selection; it is
|
|
207 |
also possible, to use Smalltalk-80 style menus (which return some value
|
|
208 |
from their startup method):
|
|
209 |
|
59
|
210 |
|m selection|
|
38
|
211 |
|
59
|
212 |
m := PopUpMenu
|
|
213 |
labels:#('one' 'two' 'three').
|
|
214 |
selection := m startUp.
|
|
215 |
Transcript show:'the selection was: '; showCr:selection
|
38
|
216 |
|
|
217 |
startUp will return the entries index, or 0 if there was no selection.
|
|
218 |
You can also specify an array of values to be returned instead of the
|
|
219 |
index:
|
|
220 |
|
59
|
221 |
|m selection|
|
38
|
222 |
|
59
|
223 |
m := PopUpMenu
|
|
224 |
labels:#('one' 'two' 'three')
|
|
225 |
values:#(10 20 30).
|
|
226 |
selection := m startUp.
|
|
227 |
Transcript show:'the value was: '; showCr:selection
|
38
|
228 |
|
|
229 |
In ST/X style menus, separating lines between entries are created
|
|
230 |
by a '-'-string as its label text (and corresponding nil-entries in the
|
|
231 |
selectors- and args-arrays).
|
|
232 |
In ST-80, you have to pass the indices of the lines in an extra array:
|
|
233 |
|
59
|
234 |
|m selection|
|
38
|
235 |
|
59
|
236 |
m := PopUpMenu
|
|
237 |
labels:#('one' 'two' 'three' 'four' 'five')
|
|
238 |
lines:#(2 4).
|
|
239 |
selection := m startUp.
|
|
240 |
Transcript show:'the value was: '; showCr:selection
|
38
|
241 |
|
|
242 |
or:
|
59
|
243 |
|m selection|
|
38
|
244 |
|
59
|
245 |
m := PopUpMenu
|
|
246 |
labels:#('one' 'two' 'three')
|
|
247 |
lines:#(2)
|
|
248 |
values:#(10 20 30).
|
|
249 |
selection := m startUp.
|
|
250 |
Transcript show:'the value was: '; showCr:selection
|
38
|
251 |
|
|
252 |
Use whichever interface you prefer.
|
|
253 |
"
|
|
254 |
! !
|
|
255 |
|
119
|
256 |
!PopUpMenu class methodsFor:'defaults'!
|
38
|
257 |
|
119
|
258 |
updateStyleCache
|
|
259 |
DefaultHideOnRelease := StyleSheet at:#popupHideOnRelease default:true.
|
|
260 |
! !
|
|
261 |
|
|
262 |
!PopUpMenu class methodsFor:'instance creation'!
|
38
|
263 |
|
|
264 |
forMenu:aMenuView
|
|
265 |
"this wraps an already existing menu - allowing to put any
|
|
266 |
view (not just MenuViews) into popups (for example, menus
|
|
267 |
with icons, or other components).
|
|
268 |
Currently, there is only one example of different menus in
|
|
269 |
the system (PatternMenu in the DrawTool) which could be used
|
|
270 |
this way.
|
|
271 |
The view should respond to some of the menuView messages
|
|
272 |
(such as hideSubmenu, deselectWithoutRedraw etc.)"
|
|
273 |
|
|
274 |
|newMenu|
|
|
275 |
|
|
276 |
newMenu := self onSameDeviceAs:aMenuView.
|
|
277 |
newMenu addSubView:aMenuView.
|
|
278 |
newMenu menu:aMenuView.
|
|
279 |
^ newMenu
|
|
280 |
!
|
|
281 |
|
|
282 |
labels:labels selectors:selectors args:args receiver:anObject for:aView
|
63
|
283 |
"create and return a popup menu with labels as entries.
|
|
284 |
Each item will send a corresponding selector:argument from the selectors-
|
|
285 |
and args array to anObject. The menu is created on the same physical device
|
|
286 |
as aView (which is only of interrest in multi-Display applications;
|
|
287 |
typical applications can use the sibbling message without the for: argument)."
|
|
288 |
|
38
|
289 |
|newMenu|
|
|
290 |
|
|
291 |
newMenu := self onSameDeviceAs:aView.
|
|
292 |
newMenu menu:(MenuView
|
59
|
293 |
labels:labels
|
|
294 |
selectors:selectors
|
|
295 |
args:args
|
|
296 |
receiver:anObject
|
|
297 |
in:newMenu).
|
38
|
298 |
^ newMenu
|
|
299 |
!
|
|
300 |
|
119
|
301 |
labels:labels selectors:selectors receiver:anObject for:aView
|
63
|
302 |
"create and return a popup menu with labels as entries.
|
119
|
303 |
Each item will send a corresponding selector from the selectors-array
|
|
304 |
to anObject. The menu is created on the same physical device
|
|
305 |
as aView (which is only of interrest in multi-Display applications;
|
|
306 |
typical applications can use the sibbling message without the for: argument)."
|
63
|
307 |
|
119
|
308 |
^ self labels:labels selectors:selectors args:nil receiver:anObject for:aView
|
38
|
309 |
!
|
|
310 |
|
63
|
311 |
labels:labels selector:aSelector args:args receiver:anObject for:aView
|
|
312 |
"create and return a popup menu with labels as entries.
|
|
313 |
Each item will send aSelector with a corresponding argument from the
|
|
314 |
args array to anObject. The menu is created on the same physical device
|
|
315 |
as aView (which is only of interrest in multi-Display applications;
|
|
316 |
typical applications can use the sibbling message without the for: argument)."
|
38
|
317 |
|
119
|
318 |
"
|
|
319 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg
|
|
320 |
"
|
|
321 |
^ self labels:labels selectors:aSelector args:args receiver:anObject for:aView
|
|
322 |
!
|
38
|
323 |
|
119
|
324 |
labels:labels selectors:selectors args:args receiver:anObject
|
|
325 |
"create and return a popup menu with labels as entries.
|
|
326 |
Each item will send a corresponding selector:argument from the selectors-
|
|
327 |
and args array to anObject. The menu is created on the default Display"
|
|
328 |
|
|
329 |
^ self labels:labels selectors:selectors args:args receiver:anObject for:nil
|
63
|
330 |
!
|
|
331 |
|
|
332 |
labels:labels selector:aSelector args:args receiver:anObject
|
|
333 |
"create and return a popup menu with labels as entries.
|
|
334 |
Each item will send aSelector with a corresponding argument from the
|
|
335 |
args array to anObject. The menu is created on the default DIsplay"
|
|
336 |
|
119
|
337 |
"
|
|
338 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg
|
|
339 |
"
|
|
340 |
^ self labels:labels selectors:aSelector args:args receiver:anObject
|
|
341 |
!
|
|
342 |
|
|
343 |
labels:labels selectors:selectors receiver:anObject
|
|
344 |
"create and return a popup menu with labels as entries.
|
|
345 |
Each item will send a message with a selector from the corresponding
|
|
346 |
selectors-array.
|
|
347 |
The menu is created on the default Display."
|
|
348 |
|
|
349 |
^ self labels:labels selectors:selectors args:nil receiver:anObject for:nil
|
63
|
350 |
!
|
|
351 |
|
|
352 |
labels:labels selectors:selectors
|
|
353 |
"create and return a menu with label-items and selectors. The receiver
|
|
354 |
will either be defined later, or not used at all (if opened via startUp)"
|
|
355 |
|
119
|
356 |
^ self labels:labels selectors:selectors args:nil receiver:nil for:nil
|
|
357 |
!
|
|
358 |
|
|
359 |
labels:labels selectors:selectors args:argArray
|
|
360 |
"create and return a menu with label-items and selectors. The receiver
|
|
361 |
will either be defined later, or not used at all (if opened via startUp)"
|
|
362 |
|
|
363 |
^ self labels:labels selectors:selectors args:argArray receiver:nil for:nil
|
0
|
364 |
! !
|
|
365 |
|
|
366 |
!PopUpMenu class methodsFor:'ST-80 instance creation'!
|
|
367 |
|
|
368 |
labels:labels
|
119
|
369 |
"ST80R2 compatibility"
|
|
370 |
|
0
|
371 |
^ self labels:labels lines:nil values:nil
|
|
372 |
!
|
|
373 |
|
|
374 |
labels:labels values:values
|
119
|
375 |
"ST80R2 compatibility"
|
|
376 |
|
0
|
377 |
^ self labels:labels lines:nil values:values
|
|
378 |
!
|
|
379 |
|
|
380 |
labels:labels lines:lines
|
119
|
381 |
"ST80R2 compatibility"
|
|
382 |
|
0
|
383 |
^ self labels:labels lines:lines values:nil
|
|
384 |
!
|
|
385 |
|
|
386 |
labels:labels lines:lines values:values
|
119
|
387 |
"ST80R2 compatibility"
|
|
388 |
|
0
|
389 |
^ (self new) labels:labels lines:lines values:values
|
|
390 |
!
|
|
391 |
|
119
|
392 |
labelArray:labels values:values
|
|
393 |
"ST80R4 compatibility"
|
|
394 |
|
|
395 |
^ self labels:labels lines:nil values:values
|
|
396 |
!
|
|
397 |
|
|
398 |
labelArray:labels lines:lines values:values
|
|
399 |
"ST80R4 compatibility"
|
|
400 |
|
|
401 |
^ self labels:labels lines:lines values:values
|
|
402 |
!
|
|
403 |
|
0
|
404 |
labelList:labels values:values
|
119
|
405 |
"ST80R4 compatibility:
|
|
406 |
given a list consisting of group label entries (to be separated by
|
|
407 |
lines), convert into standard form (using '-' for lines.
|
|
408 |
"
|
|
409 |
|
|
410 |
|newLabels newValues lS vS first|
|
|
411 |
|
|
412 |
newLabels := OrderedCollection new.
|
|
413 |
newValues := OrderedCollection new.
|
|
414 |
lS := ReadStream on:labels.
|
|
415 |
values notNil ifTrue:[vS := ReadStream on:values].
|
|
416 |
first := true.
|
|
417 |
[lS atEnd] whileFalse:[
|
|
418 |
|entry|
|
|
419 |
|
|
420 |
entry := lS next.
|
|
421 |
entry isCollection ifTrue:[
|
|
422 |
first ifFalse:[
|
|
423 |
newLabels add:'-'.
|
|
424 |
values notNil ifTrue:[newValues add:nil]
|
|
425 |
].
|
|
426 |
newLabels addAll:entry.
|
|
427 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)]
|
|
428 |
] ifFalse:[
|
|
429 |
newLabels add:entry.
|
|
430 |
values notNil ifTrue:[newValues add:(vS next)]
|
|
431 |
].
|
|
432 |
first := false.
|
|
433 |
].
|
|
434 |
values isNil ifTrue:[
|
|
435 |
^ self labels:newLabels
|
|
436 |
].
|
|
437 |
^ self labels:newLabels values:newValues
|
|
438 |
|
|
439 |
"
|
|
440 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer
|
|
441 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer
|
|
442 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer
|
|
443 |
"
|
|
444 |
!
|
|
445 |
|
|
446 |
labelList:labels
|
|
447 |
"ST80R4 compatibility:
|
|
448 |
given a list consisting of group label entries (to be separated by
|
|
449 |
lines), convert into standard form (using '-' for lines.
|
|
450 |
"
|
|
451 |
|
|
452 |
^ self labelList:labels values:nil
|
|
453 |
|
|
454 |
"
|
|
455 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer
|
|
456 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer
|
|
457 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer
|
|
458 |
"
|
0
|
459 |
!
|
|
460 |
|
|
461 |
labelList:labels lines:lines values:values
|
119
|
462 |
"mhmh what is that ?"
|
|
463 |
|
0
|
464 |
^ (self new) labels:labels lines:lines values:values
|
|
465 |
! !
|
|
466 |
|
|
467 |
!PopUpMenu methodsFor:'initialization'!
|
|
468 |
|
|
469 |
initialize
|
|
470 |
super initialize.
|
59
|
471 |
|
0
|
472 |
memorize := true.
|
21
|
473 |
hideOnLeave := false.
|
119
|
474 |
defaultHideOnRelease := DefaultHideOnRelease.
|
0
|
475 |
!
|
|
476 |
|
|
477 |
initEvents
|
|
478 |
super initEvents.
|
|
479 |
self enableEnterLeaveEvents.
|
|
480 |
self enableMotionEvents.
|
|
481 |
! !
|
|
482 |
|
|
483 |
!PopUpMenu methodsFor:'realization'!
|
|
484 |
|
|
485 |
fixSize
|
119
|
486 |
"called right before the view is made visible.
|
|
487 |
adjust my size to the size of the actual menu"
|
0
|
488 |
|
|
489 |
|extra newWidth newHeight|
|
|
490 |
|
|
491 |
extra := margin * 2.
|
119
|
492 |
menuView resizeIfChanged.
|
0
|
493 |
newWidth := menuView width + extra.
|
|
494 |
newHeight := menuView height + extra.
|
|
495 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[
|
59
|
496 |
self extent:(menuView width + extra) @ (menuView height + extra)
|
0
|
497 |
].
|
|
498 |
super fixSize
|
|
499 |
!
|
|
500 |
|
|
501 |
realize
|
|
502 |
menuView deselectWithoutRedraw.
|
|
503 |
super realize.
|
105
|
504 |
hideOnRelease := defaultHideOnRelease.
|
0
|
505 |
! !
|
|
506 |
|
|
507 |
!PopUpMenu methodsFor:'private accessing'!
|
|
508 |
|
|
509 |
menu:aMenu
|
|
510 |
"set the actual menu"
|
|
511 |
|
|
512 |
menuView := aMenu.
|
|
513 |
menuView origin:(margin @ margin).
|
70
|
514 |
menuView borderWidth:0.
|
|
515 |
menuView masterView:self
|
0
|
516 |
!
|
|
517 |
|
|
518 |
menuView
|
|
519 |
"return the actual menu"
|
|
520 |
|
|
521 |
^ menuView
|
7
|
522 |
!
|
|
523 |
|
|
524 |
superMenu:aMenu
|
|
525 |
"return the superMenu"
|
|
526 |
|
|
527 |
menuView superMenu:aMenu
|
127
|
528 |
! !
|
|
529 |
|
|
530 |
!PopUpMenu methodsFor:'accessing-mvc'!
|
77
|
531 |
|
127
|
532 |
changeMessage:aSymbol
|
|
533 |
"forward to my menu"
|
|
534 |
|
|
535 |
menuView changeMessage:aSymbol
|
77
|
536 |
!
|
|
537 |
|
120
|
538 |
changeMessage
|
127
|
539 |
"forward from my menu"
|
|
540 |
|
120
|
541 |
^ menuView changeMessage
|
77
|
542 |
!
|
|
543 |
|
|
544 |
model
|
|
545 |
^ menuView model
|
|
546 |
!
|
|
547 |
|
|
548 |
model:aModel
|
|
549 |
menuView model:aModel
|
0
|
550 |
! !
|
|
551 |
|
59
|
552 |
!PopUpMenu methodsFor:'menuview messages'!
|
|
553 |
|
|
554 |
doesNotUnderstand:aMessage
|
|
555 |
"forward all menu-view messages"
|
|
556 |
|
|
557 |
(menuView respondsTo:(aMessage selector)) ifTrue:[
|
|
558 |
^ aMessage sendTo:menuView
|
|
559 |
].
|
|
560 |
^ super doesNotUnderstand:aMessage
|
|
561 |
! !
|
|
562 |
|
127
|
563 |
!PopUpMenu methodsFor:'accessing-behavior'!
|
|
564 |
|
|
565 |
hideOnLeave:aBoolean
|
|
566 |
"set/clear the hideOnLeave attribute, which controls
|
|
567 |
if the menu should be hidden when the pointer leaves
|
|
568 |
the view (used with multiple-menus)"
|
|
569 |
|
|
570 |
hideOnLeave := aBoolean
|
137
|
571 |
!
|
|
572 |
|
|
573 |
hideOnRelease:aBoolean
|
|
574 |
"set/clear the hideOnRelease attribute, which controls
|
|
575 |
if the menu should be hidden when the button is released"
|
|
576 |
|
|
577 |
hideOnRelease := aBoolean.
|
|
578 |
menuView hideOnRelease:aBoolean
|
127
|
579 |
! !
|
|
580 |
|
|
581 |
!PopUpMenu methodsFor:'accessing-look'!
|
0
|
582 |
|
|
583 |
viewBackground:aColor
|
|
584 |
"this is a kludge and will vanish ..."
|
|
585 |
|
|
586 |
super viewBackground:aColor.
|
|
587 |
menuView viewBackground:aColor
|
|
588 |
!
|
|
589 |
|
21
|
590 |
font:aFont
|
|
591 |
menuView font:aFont
|
127
|
592 |
! !
|
|
593 |
|
|
594 |
!PopUpMenu methodsFor:'accessing-items'!
|
21
|
595 |
|
|
596 |
labels
|
|
597 |
"return the list of labels"
|
|
598 |
|
|
599 |
actionLabels notNil ifTrue:[
|
81
|
600 |
^ actionLabels asStringCollection
|
21
|
601 |
].
|
|
602 |
^ menuView list
|
|
603 |
!
|
|
604 |
|
38
|
605 |
indexOf:indexOrName
|
|
606 |
"return the index of a submenu - or 0 if there is none"
|
|
607 |
|
|
608 |
^ menuView indexOf:indexOrName
|
|
609 |
!
|
|
610 |
|
|
611 |
remove:indexOrName
|
|
612 |
"remove a menu entry"
|
|
613 |
|
|
614 |
menuView remove:indexOrName
|
|
615 |
!
|
|
616 |
|
0
|
617 |
subMenuAt:indexOrName put:aMenu
|
|
618 |
"define a submenu to be shown for entry indexOrName"
|
|
619 |
|
7
|
620 |
"
|
0
|
621 |
aMenu hideOnLeave:true.
|
7
|
622 |
"
|
|
623 |
menuView subMenuAt:indexOrName put:aMenu.
|
|
624 |
"tell the submenu to notify me when action is performed"
|
|
625 |
aMenu superMenu:self.
|
0
|
626 |
|
112
|
627 |
"
|
|
628 |
|v m someObject|
|
|
629 |
|
0
|
630 |
v := View new.
|
|
631 |
m := PopUpMenu labels:#('1' '2' '3')
|
59
|
632 |
selectors:#(one two nil)
|
112
|
633 |
receiver:someObject
|
59
|
634 |
for:nil.
|
0
|
635 |
m subMenuAt:3 put:(PopUpMenu
|
59
|
636 |
labels:#('a' 'b' 'c')
|
|
637 |
selectors:#(a b c)
|
112
|
638 |
receiver:someObject
|
59
|
639 |
for:nil).
|
0
|
640 |
v middleButtonMenu:m.
|
112
|
641 |
v realize
|
|
642 |
"
|
0
|
643 |
!
|
|
644 |
|
|
645 |
numberOfItems
|
21
|
646 |
"return the number of items in the menu"
|
0
|
647 |
|
21
|
648 |
actionLabels notNil ifTrue:[
|
81
|
649 |
^ actionLabels asStringCollection size
|
21
|
650 |
].
|
|
651 |
^ menuView list size
|
0
|
652 |
!
|
|
653 |
|
|
654 |
values
|
21
|
655 |
"st-80 compatibility"
|
|
656 |
|
0
|
657 |
^ actionValues
|
|
658 |
!
|
|
659 |
|
133
|
660 |
values:aValueArray
|
|
661 |
"st-80 compatibility"
|
|
662 |
|
|
663 |
actionValues := aValueArray
|
|
664 |
!
|
|
665 |
|
0
|
666 |
lines
|
21
|
667 |
"st-80 compatibility"
|
|
668 |
|
0
|
669 |
^ actionLines
|
|
670 |
!
|
|
671 |
|
|
672 |
labels:labelString lines:lineArray values:valueArray
|
21
|
673 |
"define the menu the ST-80 way (with labels and lines defined separately)"
|
0
|
674 |
|
|
675 |
|labelArray argArray convertedLabels
|
|
676 |
offs dstOffs linePos|
|
|
677 |
|
|
678 |
actionLabels := labelString.
|
|
679 |
actionLines := lineArray.
|
|
680 |
actionValues := valueArray.
|
|
681 |
|
81
|
682 |
labelArray := labelString asStringCollection.
|
0
|
683 |
|
|
684 |
convertedLabels := Array new:(labelArray size + lineArray size).
|
|
685 |
argArray := Array new:(labelArray size + lineArray size).
|
|
686 |
|
|
687 |
offs := 1.
|
|
688 |
dstOffs := 1.
|
|
689 |
1 to:lineArray size do:[:lineIndex |
|
59
|
690 |
linePos := lineArray at:lineIndex.
|
|
691 |
[offs <= linePos] whileTrue:[
|
|
692 |
convertedLabels at:dstOffs put:(labelArray at:offs).
|
|
693 |
argArray at:dstOffs put:offs.
|
|
694 |
offs := offs + 1.
|
|
695 |
dstOffs := dstOffs + 1
|
|
696 |
].
|
|
697 |
convertedLabels at:dstOffs put:'-'.
|
|
698 |
argArray at:dstOffs put:nil.
|
|
699 |
dstOffs := dstOffs + 1
|
0
|
700 |
].
|
|
701 |
[offs <= labelArray size] whileTrue:[
|
59
|
702 |
convertedLabels at:dstOffs put:(labelArray at:offs).
|
|
703 |
argArray at:dstOffs put:offs.
|
|
704 |
offs := offs + 1.
|
|
705 |
dstOffs := dstOffs + 1
|
0
|
706 |
].
|
|
707 |
self menu:(MenuView
|
59
|
708 |
labels:convertedLabels
|
126
|
709 |
selectors:nil
|
59
|
710 |
args:argArray
|
|
711 |
receiver:nil
|
|
712 |
in:self)
|
0
|
713 |
! !
|
|
714 |
|
105
|
715 |
!PopUpMenu methodsFor:'deactivation'!
|
0
|
716 |
|
|
717 |
hide
|
7
|
718 |
"hide the menu - if there are any pop-up-submenus, hide them also"
|
|
719 |
|
|
720 |
menuView hideSubmenu.
|
38
|
721 |
windowGroup notNil ifTrue:[
|
70
|
722 |
windowGroup removeView:menuView.
|
38
|
723 |
].
|
77
|
724 |
super hide.
|
70
|
725 |
menuView superMenu notNil ifTrue:[
|
|
726 |
menuView superMenu regainControl
|
|
727 |
].
|
0
|
728 |
! !
|
|
729 |
|
|
730 |
!PopUpMenu methodsFor:'ST-80 activation'!
|
|
731 |
|
|
732 |
startUp
|
38
|
733 |
"start the menu modal - return the selected value,
|
|
734 |
or - if no values where specified - return the index.
|
0
|
735 |
If nothing was selected, return 0.
|
38
|
736 |
Modal - i.e. stay in the menu until finished.
|
|
737 |
This is the ST-80 way of launching a menu."
|
0
|
738 |
|
96
|
739 |
|return rec sel0 sel1 arg|
|
63
|
740 |
|
119
|
741 |
return := 0.
|
|
742 |
|
0
|
743 |
menuView action:[:selected |
|
63
|
744 |
|actionIndex value sel retVal|
|
38
|
745 |
|
63
|
746 |
retVal := 0.
|
95
|
747 |
|
59
|
748 |
menuView args isNil ifTrue:[
|
63
|
749 |
menuView selectors notNil ifTrue:[
|
119
|
750 |
"/ sel := menuView selectors at:selected.
|
|
751 |
"/ sel notNil ifTrue:[sel0 := sel].
|
|
752 |
|
|
753 |
"/ (arg := menuView checkFlags at:selected) isNil ifTrue:[
|
|
754 |
sel0 := menuView selectors at:selected.
|
|
755 |
"/ ] ifFalse:[
|
|
756 |
"/ sel1 := menuView selectors at:selected.
|
|
757 |
"/ ].
|
|
758 |
"/ retVal := nil.
|
63
|
759 |
]
|
|
760 |
] ifFalse:[
|
|
761 |
actionIndex := menuView args at:selected.
|
|
762 |
actionIndex notNil ifTrue:[
|
|
763 |
actionValues isNil ifTrue:[
|
95
|
764 |
menuView selectors notNil ifTrue:[
|
|
765 |
"/ mhmh an ST/X menu started the ST-80 way
|
96
|
766 |
sel1 := menuView selectors at:selected.
|
|
767 |
arg := actionIndex.
|
119
|
768 |
"/ retVal := nil.
|
95
|
769 |
] ifFalse:[
|
|
770 |
retVal := actionIndex
|
|
771 |
]
|
63
|
772 |
] ifFalse:[
|
|
773 |
retVal := actionValues at:actionIndex.
|
|
774 |
(retVal isKindOf:PopUpMenu) ifTrue:[
|
|
775 |
retVal := retVal startUp
|
|
776 |
]
|
|
777 |
]
|
95
|
778 |
] ifFalse:[
|
|
779 |
"/ mhmh an ST/X menu started the ST-80 way
|
|
780 |
menuView selectors notNil ifTrue:[
|
119
|
781 |
"/ (arg := menuView checkFlags at:selected) isNil ifTrue:[
|
|
782 |
sel0 := menuView selectors at:selected.
|
|
783 |
"/ ] ifFalse:[
|
|
784 |
"/ sel1 := menuView selectors at:selected.
|
|
785 |
"/ ].
|
|
786 |
"/ retVal := nil.
|
95
|
787 |
]
|
63
|
788 |
]
|
59
|
789 |
].
|
63
|
790 |
return := retVal
|
0
|
791 |
].
|
|
792 |
self showAtPointer.
|
96
|
793 |
|
|
794 |
"/
|
|
795 |
"/ mhmh an ST/X menu started the ST-80 way
|
|
796 |
"/
|
|
797 |
(sel0 notNil or:[sel1 notNil]) ifTrue:[
|
|
798 |
rec := menuView receiver.
|
|
799 |
sel0 notNil ifTrue:[
|
131
|
800 |
^ sel0
|
|
801 |
"/ rec perform:sel0
|
96
|
802 |
] ifFalse:[
|
131
|
803 |
^ Array with:sel1 with:arg.
|
|
804 |
"/ rec perform:sel1 with:arg.
|
96
|
805 |
]
|
95
|
806 |
].
|
63
|
807 |
^ return
|
38
|
808 |
|
|
809 |
"
|
63
|
810 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp
|
38
|
811 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')
|
59
|
812 |
values:#(foo bar baz)) startUp
|
38
|
813 |
"
|
110
|
814 |
!
|
|
815 |
|
|
816 |
startUpWithHeading:aString
|
|
817 |
"start the menu modal - return the selected value,
|
|
818 |
or - if no values where specified - return the index.
|
|
819 |
If nothing was selected, return 0.
|
|
820 |
Modal - i.e. stay in the menu until finished.
|
|
821 |
This is the ST-80 way of launching a menu."
|
|
822 |
|
|
823 |
defaultHideOnRelease := false.
|
|
824 |
menuView labels notNil ifTrue:[
|
|
825 |
menuView labels:(Array with:aString with:'=') , menuView labels.
|
|
826 |
].
|
|
827 |
menuView selectors notNil ifTrue:[
|
|
828 |
menuView selectors:(Array with:nil with:nil) , menuView selectors.
|
|
829 |
].
|
|
830 |
"/ menuView disable:1; disable:2.
|
|
831 |
|
|
832 |
^ self startUp.
|
|
833 |
|
|
834 |
"
|
|
835 |
(PopUpMenu
|
|
836 |
labels:#('foo' 'bar'))
|
|
837 |
startUp
|
|
838 |
"
|
|
839 |
"
|
|
840 |
(PopUpMenu
|
|
841 |
labels:#('foo' 'bar'))
|
|
842 |
startUpWithHeading:'hello'
|
|
843 |
"
|
0
|
844 |
! !
|
|
845 |
|
70
|
846 |
!PopUpMenu methodsFor:'event handling'!
|
0
|
847 |
|
161
|
848 |
buttonMotion:state x:x y:y
|
70
|
849 |
|p superMenu|
|
7
|
850 |
|
161
|
851 |
state == 0 ifTrue:[^ self].
|
|
852 |
|
38
|
853 |
((x >= 0) and:[x < width]) ifTrue:[
|
59
|
854 |
((y >= 0) and:[y < height]) ifTrue:[
|
105
|
855 |
hideOnRelease := true.
|
161
|
856 |
menuView buttonMotion:state x:x y:y.
|
59
|
857 |
^ self
|
|
858 |
]
|
0
|
859 |
].
|
7
|
860 |
|
|
861 |
"outside of myself"
|
70
|
862 |
superMenu := menuView superMenu.
|
|
863 |
superMenu notNil ifTrue:[
|
59
|
864 |
p := device translatePoint:(x @ y)
|
|
865 |
from:drawableId
|
|
866 |
to:(menuView superMenu id).
|
161
|
867 |
superMenu buttonMotion:state x:p x y:p y
|
7
|
868 |
].
|
|
869 |
|
|
870 |
menuView subMenuShown isNil ifTrue:[
|
161
|
871 |
menuView pointerLeave:state.
|
7
|
872 |
].
|
|
873 |
|
0
|
874 |
hideOnLeave ifTrue:[
|
59
|
875 |
self hide
|
38
|
876 |
].
|
0
|
877 |
!
|
|
878 |
|
7
|
879 |
pointerEnter:state x:x y:y
|
|
880 |
"catch quick release of button"
|
|
881 |
|
112
|
882 |
hideOnLeave ifTrue:[
|
|
883 |
state == 0 ifTrue:[^ self hide].
|
|
884 |
]
|
7
|
885 |
!
|
|
886 |
|
0
|
887 |
pointerLeave:state
|
38
|
888 |
"/ menuView pointerLeave:state.
|
|
889 |
"/ hideOnLeave ifTrue:[
|
|
890 |
"/ self hide
|
|
891 |
"/ ].
|
|
892 |
"/ menuView superMenu notNil ifTrue:[
|
|
893 |
"/ menuView superMenu regainControl
|
|
894 |
"/ ]
|
0
|
895 |
!
|
|
896 |
|
105
|
897 |
buttonPress:button x:x y:y
|
|
898 |
hideOnRelease ifTrue:[
|
|
899 |
self hide.
|
|
900 |
"
|
|
901 |
menuView buttonRelease:button x:x y:y.
|
|
902 |
"
|
|
903 |
menuView superMenu notNil ifTrue:[
|
|
904 |
menuView superMenu submenuTriggered
|
|
905 |
].
|
|
906 |
menuView buttonRelease:button x:x y:y.
|
|
907 |
] ifFalse:[
|
|
908 |
hideOnRelease := true.
|
|
909 |
((x >= 0) and:[x < width]) ifTrue:[
|
|
910 |
((y >= 0) and:[y < height]) ifTrue:[
|
|
911 |
menuView buttonPress:button x:x y:y.
|
|
912 |
^ self
|
|
913 |
]
|
|
914 |
].
|
|
915 |
].
|
|
916 |
!
|
|
917 |
|
0
|
918 |
buttonRelease:button x:x y:y
|
105
|
919 |
hideOnRelease ifFalse:[
|
|
920 |
^ self
|
|
921 |
].
|
|
922 |
|
0
|
923 |
self hide.
|
7
|
924 |
"
|
|
925 |
menuView buttonRelease:button x:x y:y.
|
|
926 |
"
|
|
927 |
menuView superMenu notNil ifTrue:[
|
59
|
928 |
menuView superMenu submenuTriggered
|
7
|
929 |
].
|
|
930 |
menuView buttonRelease:button x:x y:y.
|
112
|
931 |
!
|
|
932 |
|
|
933 |
keyPress:key x:x y:y
|
|
934 |
"/ hideOnRelease := true.
|
|
935 |
menuView keyPress:key x:x y:y.
|
0
|
936 |
! !
|