author | Claus Gittinger <cg@exept.de> |
Thu, 30 May 1996 09:17:48 +0200 | |
changeset 726 | bef52bf8f6c3 |
parent 692 | 65c5499f4cea |
child 753 | 40b85851bffb |
permissions | -rw-r--r-- |
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 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
14 |
instanceVariableNames:'menuView lastSelection memorize hideOnLeave actionLabels |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
15 |
actionLines actionValues hideOnRelease defaultHideOnRelease' |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
16 |
classVariableNames:'DefaultHideOnRelease' |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
17 |
poolDictionaries:'' |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
18 |
category:'Views-Menus' |
0 | 19 |
! |
20 |
||
38 | 21 |
!PopUpMenu class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 26 |
All Rights Reserved |
38 | 27 |
|
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
692 | 39 |
This class provides PopUpMenu functionality; |
40 |
-> Actually, this class only provides the popup and shadow functionality |
|
41 |
and wraps ANOTHER view, which shows the actual menu-list |
|
42 |
(usually an instance of MenuView). |
|
38 | 43 |
|
44 |
PopUpMenus are usually created with a list of labels, selectors and a |
|
45 |
receivier. Once activated, the specified receiver will be sent a |
|
46 |
'selector'-message. |
|
112 | 47 |
|
48 |
PopupMenus may be either assigned statically to a view (via the #middleButtonMenu: |
|
49 |
message) or created dynamically as required. |
|
50 |
Static definition makes sense, if the menu stays constant and you want to |
|
51 |
assign it once for the lifetime of the view. |
|
52 |
||
53 |
Dynamic menus are easier to use, if the number of or look of the entries has to |
|
54 |
change according the internal state of some model. Also, this is the ST-80 way |
|
55 |
of using popupMenus. For dynamic popups, the views model is asked for a menu |
|
56 |
via the #menuSelector each time a button press occurs. |
|
57 |
||
58 |
See examples section for more. |
|
586 | 59 |
|
60 |
[author:] |
|
61 |
Claus Gittinger |
|
692 | 62 |
|
63 |
[see also:] |
|
64 |
PullDownMenu MenuView |
|
63 | 65 |
" |
66 |
! |
|
38 | 67 |
|
63 | 68 |
examples |
69 |
" |
|
692 | 70 |
The ST-80 way of opening menus is to startUp a menu, |
71 |
and use the returned value: |
|
72 |
[exBegin] |
|
73 |
|p| |
|
284 | 74 |
|
692 | 75 |
p := PopUpMenu |
76 |
labels:#('foo' 'bar' 'baz'). |
|
77 |
Transcript showCR:p startUp |
|
78 |
[exEnd] |
|
79 |
It returns the index of the selected item or 0 if nothing was selected. |
|
80 |
This opening is done by either the controller or the view (if it has |
|
81 |
a middleButtonMenu and/or a menuHolder). |
|
82 |
||
83 |
If the numeric index is inconvenient, alternative values may be specified |
|
84 |
as in (here, nil is returned if nothing was selected): |
|
85 |
[exBegin] |
|
86 |
|p| |
|
87 |
||
88 |
p := PopUpMenu |
|
89 |
labels:#('foo' 'bar' 'baz') |
|
90 |
values:#('hello foo' 'hello bar' 'hello baz'). |
|
91 |
Transcript showCR:p startUp |
|
92 |
[exEnd] |
|
93 |
In ST/X, the above is actually done by a mimicri method (#startUp) |
|
94 |
and menus are typically created in one of the following ways: |
|
95 |
||
96 |
-> With a single actionBlock. |
|
97 |
This is convenient, if all actions shall perform a similar task, |
|
98 |
but require different arguments. |
|
99 |
||
100 |
this is evaluated, passing the selections index or value as argument. |
|
101 |
The action block is NOT evaluated, if nothing was selected. |
|
102 |
With index: |
|
593 | 103 |
[exBegin] |
692 | 104 |
|p| |
105 |
||
106 |
p := PopUpMenu |
|
107 |
labels:#('foo' 'bar' 'baz'). |
|
108 |
p action:[:item | Transcript showCR:item]. |
|
109 |
p showAtPointer |
|
110 |
[exEnd] |
|
111 |
With individual arguments: |
|
112 |
[exBegin] |
|
113 |
|p| |
|
114 |
||
115 |
p := PopUpMenu |
|
116 |
labels:#('foo' 'bar' 'baz') |
|
117 |
args:#('hello foo' 'hello bar' 'hello baz'). |
|
118 |
p action:[:item | Transcript showCR:item]. |
|
119 |
p showAtPointer |
|
120 |
[exEnd] |
|
121 |
||
122 |
-> With an explicit receiver and different selectors. |
|
123 |
This is convenient, if you have to send per-item messages |
|
124 |
to some object (typically, the receiver is the view or a model) |
|
125 |
[exBegin] |
|
126 |
|p m| |
|
127 |
||
128 |
m := Plug new. |
|
129 |
m respondTo:#foo with:[Transcript showCR:'foo received']. |
|
130 |
m respondTo:#bar with:[Transcript showCR:'bar received']. |
|
131 |
m respondTo:#maz with:[Transcript showCR:'maz received']. |
|
132 |
||
133 |
p := PopUpMenu |
|
134 |
labels:#('foo' 'bar' 'baz') |
|
135 |
selectors:#(#foo #bar #baz) |
|
136 |
receiver:m. |
|
137 |
p showAtPointer |
|
593 | 138 |
[exEnd] |
38 | 139 |
|
140 |
||
692 | 141 |
More examples: |
459 | 142 |
dynamic with action instead of selector being sent: |
593 | 143 |
[exBegin] |
459 | 144 |
|p| |
145 |
||
146 |
p := PopUpMenu |
|
147 |
labels:(($a to: $d) collect:[:char | char asString]) |
|
148 |
selectors:nil |
|
149 |
receiver:nil. |
|
655 | 150 |
p action:[:idx | Transcript showCR:'selected index is '; showCR:idx]. |
459 | 151 |
p showAtPointer |
593 | 152 |
[exEnd] |
459 | 153 |
|
154 |
||
545 | 155 |
individual actions: |
593 | 156 |
[exBegin] |
545 | 157 |
|p| |
158 |
p := PopUpMenu |
|
159 |
labels:#('foo' |
|
160 |
'bar' |
|
161 |
'baz') |
|
162 |
selectors:#( |
|
163 |
#foo |
|
164 |
#bar |
|
165 |
#baz). |
|
655 | 166 |
p actionAt:#foo put:[Transcript showCR:'foo']. |
167 |
p actionAt:#bar put:[Transcript showCR:'bar']. |
|
168 |
p actionAt:#baz put:[Transcript showCR:'baz']. |
|
545 | 169 |
p showAtPointer |
593 | 170 |
[exEnd] |
545 | 171 |
|
38 | 172 |
sometimes, you want to specify both selectors and some arguments |
173 |
to be sent; this is done by: |
|
593 | 174 |
[exBegin] |
284 | 175 |
|p| |
176 |
p := PopUpMenu |
|
177 |
labels:#('foo' 'bar' 'baz') |
|
178 |
selectors:#(#foo: #bar: #foo:) |
|
179 |
args:#(1 2 3) |
|
180 |
receiver:nil. |
|
181 |
p showAtPointer |
|
593 | 182 |
[exEnd] |
38 | 183 |
|
184 |
or, the same selector but different arguments: |
|
593 | 185 |
[exBegin] |
284 | 186 |
|p| |
187 |
p := PopUpMenu |
|
188 |
labels:#('foo' 'bar' 'baz') |
|
189 |
selectors:#foo: |
|
190 |
args:#(1 2 3) |
|
191 |
receiver:nil. |
|
192 |
p showAtPointer |
|
593 | 193 |
[exEnd] |
38 | 194 |
|
195 |
Normally, you do not show the menu explicitely, but install |
|
112 | 196 |
it as a either as middleButtonMenu of some view or return it from |
197 |
a model. |
|
198 |
(Views/Controllers button-event handler will show it when the middle |
|
199 |
button is pressed ...) |
|
200 |
Static menu: |
|
593 | 201 |
[exBegin] |
284 | 202 |
|v m| |
38 | 203 |
|
284 | 204 |
v := View new. |
205 |
m := PopUpMenu |
|
206 |
labels:#('lower' |
|
207 |
'raise' |
|
208 |
'-' |
|
209 |
'destroy') |
|
210 |
selectors:#(#lower #raise nil #destroy) |
|
211 |
receiver:v. |
|
212 |
v middleButtonMenu:m. |
|
213 |
v open |
|
593 | 214 |
[exEnd] |
38 | 215 |
|
112 | 216 |
Dynamic menu: |
217 |
(since we need some model which responds to a menu-message, |
|
218 |
we use a plug in the example below; normally, this would be your model) |
|
593 | 219 |
[exBegin] |
284 | 220 |
|v model| |
112 | 221 |
|
284 | 222 |
model := Plug new. |
223 |
model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar') |
|
224 |
selectors:#(foo bar)]. |
|
655 | 225 |
model respondTo:#foo with:[Transcript showCR:'models foo called']. |
226 |
model respondTo:#bar with:[Transcript showCR:'models bar called']. |
|
112 | 227 |
|
284 | 228 |
v := View new. |
229 |
v model:model; menu:#getMenu. |
|
230 |
v open |
|
593 | 231 |
[exEnd] |
112 | 232 |
|
233 |
Dynamic menus are the MVC-way (i.e. ST-80) way of doing things. |
|
234 |
They are usually easier to use, if the menu changes depending on the models |
|
235 |
state. (for example, see the systemBrowsers menus being different when |
|
236 |
things are selected ...) |
|
237 |
||
38 | 238 |
It is also possible, to add check-mark entries, with an entry string |
239 |
starting with the special sequence '\c' (for check-mark). The value |
|
240 |
passed will be the truth-state of the check-mark. |
|
593 | 241 |
[exBegin] |
284 | 242 |
|m v| |
38 | 243 |
|
284 | 244 |
v := View new. |
245 |
m := PopUpMenu |
|
246 |
labels:#('\c foo' |
|
247 |
'\c bar') |
|
248 |
selectors:#(#value: #value:) |
|
655 | 249 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
284 | 250 |
v middleButtonMenu:m. |
251 |
v open |
|
593 | 252 |
[exEnd] |
38 | 253 |
|
404 | 254 |
The style of the checkmark can be: check (\c), box (\b) or thumbs (\t): |
593 | 255 |
[exBegin] |
404 | 256 |
|m v| |
257 |
||
258 |
v := View new. |
|
259 |
m := PopUpMenu |
|
260 |
labels:#('\c foo' |
|
261 |
'\b bar' |
|
262 |
'\t baz') |
|
263 |
selectors:#(#value: #value: #value:) |
|
655 | 264 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
404 | 265 |
v middleButtonMenu:m. |
266 |
v open |
|
593 | 267 |
[exEnd] |
404 | 268 |
|
406 | 269 |
or at the end (looks better with variable fonts): |
593 | 270 |
[exBegin] |
406 | 271 |
|m v| |
272 |
||
273 |
v := View new. |
|
274 |
m := PopUpMenu |
|
275 |
labels:#('foo \c' |
|
276 |
'bar \b' |
|
277 |
'baz \t') |
|
278 |
selectors:#(#value: #value: #value:) |
|
655 | 279 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
406 | 280 |
v middleButtonMenu:m. |
281 |
v open |
|
593 | 282 |
[exEnd] |
406 | 283 |
|
38 | 284 |
Finally, you can wrap other views into a popup menu (for example, |
285 |
to implement menus with icons or other components). |
|
286 |
The view should respond to some messages sent from here (for |
|
287 |
example: #hideSubmenus, #deselectWithoutRedraw and others). |
|
288 |
Currently there is only one class in the system, which can be used |
|
289 |
this way (PatternMenu in the DrawTool demo): |
|
593 | 290 |
[exBegin] |
284 | 291 |
|v p| |
38 | 292 |
|
284 | 293 |
v := View new. |
294 |
p := PatternMenu new. |
|
295 |
p patterns:(Array with:Color red |
|
296 |
with:Color green |
|
297 |
with:Color blue). |
|
298 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
299 |
v open |
|
593 | 300 |
[exEnd] |
38 | 301 |
|
302 |
or try: |
|
593 | 303 |
[exBegin] |
284 | 304 |
|v p| |
38 | 305 |
|
284 | 306 |
v := View new. |
307 |
p := PatternMenu new. |
|
308 |
p patterns:(Array with:Color red |
|
309 |
with:Color green |
|
310 |
with:Color blue). |
|
311 |
p selectors:#value:. |
|
312 |
p receiver:[:val | v viewBackground:val. v clear]. |
|
313 |
p args:(Array with:Color red |
|
314 |
with:Color green |
|
315 |
with:Color blue). |
|
316 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
317 |
v open |
|
593 | 318 |
[exEnd] |
38 | 319 |
|
320 |
||
321 |
ST-80 style: |
|
322 |
||
323 |
The above menus all did some message send on selection; it is |
|
324 |
also possible, to use Smalltalk-80 style menus (which return some value |
|
325 |
from their startup method): |
|
593 | 326 |
[exBegin] |
284 | 327 |
|m selection| |
38 | 328 |
|
284 | 329 |
m := PopUpMenu |
330 |
labels:#('one' 'two' 'three'). |
|
331 |
selection := m startUp. |
|
655 | 332 |
Transcript show:'the selection was: '; showCR:selection |
593 | 333 |
[exEnd] |
38 | 334 |
|
335 |
startUp will return the entries index, or 0 if there was no selection. |
|
336 |
You can also specify an array of values to be returned instead of the |
|
337 |
index: |
|
593 | 338 |
[exBegin] |
284 | 339 |
|m selection| |
38 | 340 |
|
284 | 341 |
m := PopUpMenu |
342 |
labels:#('one' 'two' 'three') |
|
343 |
values:#(10 20 30). |
|
344 |
selection := m startUp. |
|
655 | 345 |
Transcript show:'the value was: '; showCR:selection |
593 | 346 |
[exEnd] |
38 | 347 |
|
348 |
In ST/X style menus, separating lines between entries are created |
|
349 |
by a '-'-string as its label text (and corresponding nil-entries in the |
|
350 |
selectors- and args-arrays). |
|
351 |
In ST-80, you have to pass the indices of the lines in an extra array: |
|
593 | 352 |
[exBegin] |
284 | 353 |
|m selection| |
38 | 354 |
|
284 | 355 |
m := PopUpMenu |
356 |
labels:#('one' 'two' 'three' 'four' 'five') |
|
357 |
lines:#(2 4). |
|
358 |
selection := m startUp. |
|
655 | 359 |
Transcript show:'the value was: '; showCR:selection |
593 | 360 |
[exEnd] |
38 | 361 |
|
362 |
or: |
|
593 | 363 |
[exBegin] |
284 | 364 |
|m selection| |
38 | 365 |
|
284 | 366 |
m := PopUpMenu |
367 |
labels:#('one' 'two' 'three') |
|
368 |
lines:#(2) |
|
369 |
values:#(10 20 30). |
|
370 |
selection := m startUp. |
|
655 | 371 |
Transcript show:'the value was: '; showCR:selection |
593 | 372 |
[exEnd] |
38 | 373 |
|
374 |
Use whichever interface you prefer. |
|
375 |
" |
|
119 | 376 |
! ! |
377 |
||
378 |
!PopUpMenu class methodsFor:'instance creation'! |
|
38 | 379 |
|
380 |
forMenu:aMenuView |
|
381 |
"this wraps an already existing menu - allowing to put any |
|
382 |
view (not just MenuViews) into popups (for example, menus |
|
383 |
with icons, or other components). |
|
384 |
Currently, there is only one example of different menus in |
|
385 |
the system (PatternMenu in the DrawTool) which could be used |
|
386 |
this way. |
|
387 |
The view should respond to some of the menuView messages |
|
388 |
(such as hideSubmenu, deselectWithoutRedraw etc.)" |
|
389 |
||
390 |
|newMenu| |
|
391 |
||
392 |
newMenu := self onSameDeviceAs:aMenuView. |
|
393 |
newMenu addSubView:aMenuView. |
|
394 |
newMenu menu:aMenuView. |
|
395 |
^ newMenu |
|
396 |
! |
|
397 |
||
692 | 398 |
labels:labels args:args |
399 |
"create and return a menu with label-items and args. |
|
400 |
The actionBlock has to be defined later" |
|
401 |
||
402 |
^ self labels:labels selectors:nil accelerators:nil args:args receiver:nil for:nil |
|
403 |
||
404 |
" |
|
405 |
|m| |
|
406 |
||
407 |
m := PopUpMenu labels:#('foo' 'bar') |
|
408 |
args:#('hello world' 'how about this'). |
|
409 |
m action:[:arg | |
|
410 |
Transcript showCR:arg |
|
411 |
]. |
|
412 |
||
413 |
m showAtPointer |
|
414 |
" |
|
415 |
||
416 |
"Modified: 25.5.1996 / 17:01:43 / cg" |
|
417 |
! |
|
418 |
||
202 | 419 |
labels:labels selector:aSelector args:args receiver:anObject |
420 |
"create and return a popup menu with labels as entries. |
|
421 |
Each item will send aSelector with a corresponding argument from the |
|
422 |
args array to anObject. The menu is created on the default DIsplay" |
|
423 |
||
424 |
" |
|
425 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
426 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
427 |
^ self labels:labels selectors:aSelector accelerators:nil args:args receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
428 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
429 |
"Modified: 28.2.1996 / 19:01:12 / cg" |
202 | 430 |
! |
431 |
||
432 |
labels:labels selector:aSelector args:args receiver:anObject for:aView |
|
433 |
"create and return a popup menu with labels as entries. |
|
434 |
Each item will send aSelector with a corresponding argument from the |
|
435 |
args array to anObject. The menu is created on the same physical device |
|
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
436 |
as aView (which is only of interest in multi-Display applications; |
202 | 437 |
typical applications can use the sibbling message without the for: argument)." |
438 |
||
439 |
" |
|
440 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
441 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
442 |
^ self labels:labels selectors:aSelector accelerators:nil args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
443 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
444 |
"Modified: 28.2.1996 / 19:01:29 / cg" |
202 | 445 |
! |
446 |
||
447 |
labels:labels selectors:selectors |
|
448 |
"create and return a menu with label-items and selectors. The receiver |
|
449 |
will either be defined later, or not used at all (if opened via startUp)" |
|
450 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
451 |
^ self labels:labels selectors:selectors accelerators:nil args:nil receiver:nil for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
452 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
453 |
"Modified: 28.2.1996 / 19:01:35 / cg" |
202 | 454 |
! |
455 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
456 |
labels:labels selectors:selectors accelerators:shorties |
202 | 457 |
"create and return a menu with label-items and selectors. The receiver |
458 |
will either be defined later, or not used at all (if opened via startUp)" |
|
459 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
460 |
^ self labels:labels selectors:selectors accelerators:shorties args:nil receiver:nil for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
461 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
462 |
"Created: 28.2.1996 / 18:58:52 / cg" |
202 | 463 |
! |
464 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
465 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject |
202 | 466 |
"create and return a popup menu with labels as entries. |
467 |
Each item will send a corresponding selector:argument from the selectors- |
|
468 |
and args array to anObject. The menu is created on the default Display" |
|
469 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
470 |
^ self labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
471 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
472 |
"Created: 28.2.1996 / 18:59:03 / cg" |
202 | 473 |
! |
474 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
475 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject for:aView |
63 | 476 |
"create and return a popup menu with labels as entries. |
477 |
Each item will send a corresponding selector:argument from the selectors- |
|
478 |
and args array to anObject. The menu is created on the same physical device |
|
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
479 |
as aView (which is only of interest in multi-Display applications; |
63 | 480 |
typical applications can use the sibbling message without the for: argument)." |
481 |
||
38 | 482 |
|newMenu| |
483 |
||
484 |
newMenu := self onSameDeviceAs:aView. |
|
485 |
newMenu menu:(MenuView |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
486 |
labels:labels |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
487 |
selectors:selectors |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
488 |
accelerators:shorties |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
489 |
args:args |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
490 |
receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
491 |
in:newMenu). |
38 | 492 |
^ newMenu |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
493 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
494 |
"Created: 28.2.1996 / 18:59:25 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
495 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
496 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
497 |
labels:labels selectors:selectors accelerators:shorties receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
498 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
499 |
Each item will send a message with a selector from the corresponding |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
500 |
selectors-array. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
501 |
The menu is created on the default Display." |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
502 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
503 |
^ self labels:labels selectors:selectors accelerators:shorties args:nil receiver:anObject for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
504 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
505 |
"Created: 28.2.1996 / 19:00:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
506 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
507 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
508 |
labels:labels selectors:selectors args:argArray |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
509 |
"create and return a menu with label-items and selectors. The receiver |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
510 |
will either be defined later, or not used at all (if opened via startUp)" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
511 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
512 |
^ self labels:labels selectors:selectors accelerators:nil args:argArray receiver:nil for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
513 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
514 |
"Modified: 28.2.1996 / 19:01:45 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
515 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
516 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
517 |
labels:labels selectors:selectors args:args receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
518 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
519 |
Each item will send a corresponding selector:argument from the selectors- |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
520 |
and args array to anObject. The menu is created on the default Display" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
521 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
522 |
^ self labels:labels selectors:selectors accelerators:nil args:args receiver:anObject for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
523 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
524 |
"Modified: 28.2.1996 / 19:01:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
525 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
526 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
527 |
labels:labels selectors:selectors args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
528 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
529 |
Each item will send a corresponding selector:argument from the selectors- |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
530 |
and args array to anObject. The menu is created on the same physical device |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
531 |
as aView (which is only of interest in multi-Display applications; |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
532 |
typical applications can use the sibbling message without the for: argument)." |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
533 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
534 |
^ self labels:labels selectors:selectors accelerators:nil args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
535 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
536 |
"Modified: 28.2.1996 / 19:03:58 / cg" |
38 | 537 |
! |
538 |
||
119 | 539 |
labels:labels selectors:selectors receiver:anObject |
540 |
"create and return a popup menu with labels as entries. |
|
541 |
Each item will send a message with a selector from the corresponding |
|
542 |
selectors-array. |
|
543 |
The menu is created on the default Display." |
|
544 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
545 |
^ self labels:labels selectors:selectors accelerators:nil args:nil receiver:anObject for:nil |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
546 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
547 |
"Modified: 28.2.1996 / 19:02:07 / cg" |
63 | 548 |
! |
549 |
||
202 | 550 |
labels:labels selectors:selectors receiver:anObject for:aView |
551 |
"create and return a popup menu with labels as entries. |
|
552 |
Each item will send a corresponding selector from the selectors-array |
|
553 |
to anObject. The menu is created on the same physical device |
|
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
554 |
as aView (which is only of interest in multi-Display applications; |
202 | 555 |
typical applications can use the sibbling message without the for: argument)." |
63 | 556 |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
557 |
^ self labels:labels selectors:selectors accelerators:nil args:nil receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
558 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
559 |
"Modified: 28.2.1996 / 19:02:10 / cg" |
0 | 560 |
! ! |
561 |
||
562 |
!PopUpMenu class methodsFor:'ST-80 instance creation'! |
|
563 |
||
202 | 564 |
labelArray:labels lines:lines values:values |
565 |
"ST80R4 compatibility" |
|
119 | 566 |
|
202 | 567 |
^ self labels:labels lines:lines values:values |
0 | 568 |
! |
569 |
||
119 | 570 |
labelArray:labels values:values |
571 |
"ST80R4 compatibility" |
|
572 |
||
573 |
^ self labels:labels lines:nil values:values |
|
574 |
! |
|
575 |
||
202 | 576 |
labelList:labels |
577 |
"ST80R4 compatibility: |
|
578 |
given a list consisting of group label entries (to be separated by |
|
579 |
lines), convert into standard form (using '-' for lines. |
|
580 |
" |
|
581 |
||
582 |
^ self labelList:labels values:nil |
|
119 | 583 |
|
202 | 584 |
" |
585 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer |
|
586 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer |
|
587 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer |
|
588 |
" |
|
589 |
! |
|
590 |
||
591 |
labelList:labels lines:lines values:values |
|
592 |
"mhmh what is that ?" |
|
593 |
||
594 |
^ (self new) labels:labels lines:lines values:values |
|
119 | 595 |
! |
596 |
||
0 | 597 |
labelList:labels values:values |
119 | 598 |
"ST80R4 compatibility: |
599 |
given a list consisting of group label entries (to be separated by |
|
600 |
lines), convert into standard form (using '-' for lines. |
|
601 |
" |
|
602 |
||
603 |
|newLabels newValues lS vS first| |
|
604 |
||
605 |
newLabels := OrderedCollection new. |
|
606 |
newValues := OrderedCollection new. |
|
607 |
lS := ReadStream on:labels. |
|
608 |
values notNil ifTrue:[vS := ReadStream on:values]. |
|
609 |
first := true. |
|
610 |
[lS atEnd] whileFalse:[ |
|
611 |
|entry| |
|
612 |
||
613 |
entry := lS next. |
|
614 |
entry isCollection ifTrue:[ |
|
615 |
first ifFalse:[ |
|
616 |
newLabels add:'-'. |
|
617 |
values notNil ifTrue:[newValues add:nil] |
|
618 |
]. |
|
619 |
newLabels addAll:entry. |
|
620 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)] |
|
621 |
] ifFalse:[ |
|
622 |
newLabels add:entry. |
|
623 |
values notNil ifTrue:[newValues add:(vS next)] |
|
624 |
]. |
|
625 |
first := false. |
|
626 |
]. |
|
627 |
values isNil ifTrue:[ |
|
628 |
^ self labels:newLabels |
|
629 |
]. |
|
630 |
^ self labels:newLabels values:newValues |
|
631 |
||
632 |
" |
|
633 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer |
|
634 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer |
|
635 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer |
|
636 |
" |
|
637 |
! |
|
638 |
||
202 | 639 |
labels:labels |
640 |
"ST80R2 compatibility" |
|
59 | 641 |
|
202 | 642 |
^ self labels:labels lines:nil values:nil |
0 | 643 |
! |
644 |
||
202 | 645 |
labels:labels lines:lines |
646 |
"ST80R2 compatibility" |
|
0 | 647 |
|
202 | 648 |
^ self labels:labels lines:lines values:nil |
77 | 649 |
! |
650 |
||
202 | 651 |
labels:labels lines:lines values:values |
652 |
"ST80R2 compatibility" |
|
127 | 653 |
|
202 | 654 |
^ (self new) labels:labels lines:lines values:values |
77 | 655 |
! |
656 |
||
202 | 657 |
labels:labels values:values |
658 |
"ST80R2 compatibility" |
|
59 | 659 |
|
202 | 660 |
^ self labels:labels lines:nil values:values |
127 | 661 |
! ! |
662 |
||
202 | 663 |
!PopUpMenu class methodsFor:'defaults'! |
0 | 664 |
|
202 | 665 |
updateStyleCache |
608 | 666 |
<resource: #style (#popupHideOnRelease)> |
667 |
||
202 | 668 |
DefaultHideOnRelease := StyleSheet at:#popupHideOnRelease default:true. |
608 | 669 |
|
670 |
"Modified: 30.4.1996 / 16:59:25 / cg" |
|
0 | 671 |
! ! |
672 |
||
673 |
!PopUpMenu methodsFor:'ST-80 activation'! |
|
674 |
||
675 |
startUp |
|
38 | 676 |
"start the menu modal - return the selected value, |
677 |
or - if no values where specified - return the index. |
|
0 | 678 |
If nothing was selected, return 0. |
38 | 679 |
Modal - i.e. stay in the menu until finished. |
680 |
This is the ST-80 way of launching a menu." |
|
0 | 681 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
682 |
^ self startUpAt:nil |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
683 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
684 |
" |
655 | 685 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
686 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz') |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
687 |
values:#(foo bar baz)) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
688 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
689 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
690 |
"Modified: 10.1.1996 / 20:16:40 / cg" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
691 |
! |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
692 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
693 |
startUpAt:aPoint |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
694 |
"start the menu modal - return the selected value, |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
695 |
or - if no values where specified - return the index. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
696 |
If nothing was selected, return 0. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
697 |
Modal - i.e. stay in the menu until finished. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
698 |
This is the ST-80 way of launching a menu." |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
699 |
|
96 | 700 |
|return rec sel0 sel1 arg| |
63 | 701 |
|
119 | 702 |
return := 0. |
692 | 703 |
menuView args notNil ifTrue:[ |
704 |
return := nil |
|
705 |
]. |
|
119 | 706 |
|
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
707 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
708 |
"/ arrange for the menu to evaluate this action, |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
709 |
"/ instead of directly sending any messages to the menuReceiver. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
710 |
"/ (which used to be the ST/X way, menus worked). |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
711 |
"/ This works better with menuPerformers - which were not |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
712 |
"/ supported when ST/X menus were originally written. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
713 |
"/ The old ST/X mechanism may vanish. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
714 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
715 |
|
692 | 716 |
menuView action isNil ifTrue:[ |
717 |
menuView action:[:menuView :selected | |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
718 |
|actionIndex value sel retVal selIdx |
692 | 719 |
args selectors checkFlags check| |
119 | 720 |
|
692 | 721 |
retVal := 0. |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
722 |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
723 |
selIdx := menuView selection. |
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
724 |
|
692 | 725 |
args := menuView args. |
726 |
selectors := menuView selectors. |
|
727 |
checkFlags := menuView checkFlags. |
|
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
728 |
|
692 | 729 |
args isNil ifTrue:[ |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
730 |
selectors notNil ifTrue:[ |
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
731 |
sel0 := selectors at:selIdx. |
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
732 |
]. |
692 | 733 |
] ifFalse:[ |
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
734 |
actionIndex := selected. |
692 | 735 |
actionIndex notNil ifTrue:[ |
736 |
actionValues isNil ifTrue:[ |
|
737 |
selectors notNil ifTrue:[ |
|
738 |
"/ mhmh an ST/X menu started the ST-80 way |
|
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
739 |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
740 |
sel1 := selectors at:selIdx. |
692 | 741 |
arg := actionIndex. |
742 |
] ifFalse:[ |
|
743 |
retVal := actionIndex |
|
744 |
] |
|
745 |
] ifFalse:[ |
|
746 |
retVal := actionValues at:actionIndex. |
|
747 |
(retVal isKindOf:PopUpMenu) ifTrue:[ |
|
748 |
retVal := retVal startUp |
|
749 |
] |
|
750 |
] |
|
751 |
] ifFalse:[ |
|
752 |
"/ mhmh an ST/X menu started the ST-80 way |
|
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
753 |
|
692 | 754 |
selectors notNil ifTrue:[ |
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
755 |
sel0 := selectors at:selIdx. |
692 | 756 |
]. |
757 |
] |
|
758 |
]. |
|
759 |
||
760 |
checkFlags notNil ifTrue:[ |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
761 |
check := checkFlags at:selIdx. |
692 | 762 |
check notNil ifTrue:[ |
763 |
arg := check. |
|
764 |
sel1 := sel0. |
|
765 |
sel0 := nil. |
|
766 |
] |
|
767 |
]. |
|
768 |
return := retVal. |
|
769 |
||
770 |
menuView action:nil |
|
771 |
] |
|
0 | 772 |
]. |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
773 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
774 |
aPoint isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
775 |
self showAtPointer |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
776 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
777 |
self showAt:aPoint. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
778 |
]. |
96 | 779 |
|
780 |
"/ |
|
781 |
"/ mhmh an ST/X menu started the ST-80 way |
|
782 |
"/ |
|
783 |
(sel0 notNil or:[sel1 notNil]) ifTrue:[ |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
784 |
rec := menuView receiver. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
785 |
sel0 notNil ifTrue:[ |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
786 |
^ sel0 |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
787 |
]. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
788 |
^ Array with:sel1 with:arg. |
95 | 789 |
]. |
63 | 790 |
^ return |
38 | 791 |
|
792 |
" |
|
655 | 793 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
794 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz') |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
795 |
values:#(foo bar baz)) startUp |
38 | 796 |
" |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
797 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
798 |
"Created: 10.1.1996 / 20:11:42 / cg" |
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
799 |
"Modified: 30.5.1996 / 09:16:57 / cg" |
110 | 800 |
! |
801 |
||
802 |
startUpWithHeading:aString |
|
803 |
"start the menu modal - return the selected value, |
|
804 |
or - if no values where specified - return the index. |
|
805 |
If nothing was selected, return 0. |
|
806 |
Modal - i.e. stay in the menu until finished. |
|
807 |
This is the ST-80 way of launching a menu." |
|
808 |
||
809 |
defaultHideOnRelease := false. |
|
810 |
menuView labels notNil ifTrue:[ |
|
811 |
menuView labels:(Array with:aString with:'=') , menuView labels. |
|
812 |
]. |
|
813 |
menuView selectors notNil ifTrue:[ |
|
814 |
menuView selectors:(Array with:nil with:nil) , menuView selectors. |
|
815 |
]. |
|
816 |
"/ menuView disable:1; disable:2. |
|
817 |
||
818 |
^ self startUp. |
|
819 |
||
820 |
" |
|
821 |
(PopUpMenu |
|
822 |
labels:#('foo' 'bar')) |
|
823 |
startUp |
|
824 |
" |
|
825 |
" |
|
826 |
(PopUpMenu |
|
827 |
labels:#('foo' 'bar')) |
|
828 |
startUpWithHeading:'hello' |
|
829 |
" |
|
0 | 830 |
! ! |
831 |
||
202 | 832 |
!PopUpMenu methodsFor:'accessing-behavior'! |
833 |
||
834 |
hideOnLeave:aBoolean |
|
835 |
"set/clear the hideOnLeave attribute, which controls |
|
836 |
if the menu should be hidden when the pointer leaves |
|
837 |
the view (used with multiple-menus)" |
|
838 |
||
839 |
hideOnLeave := aBoolean |
|
840 |
! |
|
841 |
||
842 |
hideOnRelease:aBoolean |
|
843 |
"set/clear the hideOnRelease attribute, which controls |
|
844 |
if the menu should be hidden when the button is released" |
|
845 |
||
335
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
846 |
defaultHideOnRelease := aBoolean. |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
847 |
menuView hideOnRelease:aBoolean |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
848 |
|
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
849 |
"Modified: 9.2.1996 / 02:06:15 / cg" |
202 | 850 |
! ! |
851 |
||
852 |
!PopUpMenu methodsFor:'accessing-items'! |
|
853 |
||
854 |
indexOf:indexOrName |
|
855 |
"return the index of a submenu - or 0 if there is none" |
|
856 |
||
857 |
^ menuView indexOf:indexOrName |
|
858 |
! |
|
859 |
||
860 |
labels |
|
861 |
"return the list of labels" |
|
862 |
||
863 |
actionLabels notNil ifTrue:[ |
|
864 |
^ actionLabels asStringCollection |
|
865 |
]. |
|
866 |
^ menuView list |
|
867 |
! |
|
868 |
||
869 |
labels:labelString lines:lineArray values:valueArray |
|
870 |
"define the menu the ST-80 way (with labels and lines defined separately)" |
|
871 |
||
872 |
|labelArray argArray convertedLabels |
|
873 |
offs dstOffs linePos| |
|
874 |
||
875 |
actionLabels := labelString. |
|
876 |
actionLines := lineArray. |
|
877 |
actionValues := valueArray. |
|
878 |
||
879 |
labelArray := labelString asStringCollection. |
|
880 |
||
881 |
convertedLabels := Array new:(labelArray size + lineArray size). |
|
882 |
argArray := Array new:(labelArray size + lineArray size). |
|
883 |
||
884 |
offs := 1. |
|
885 |
dstOffs := 1. |
|
886 |
1 to:lineArray size do:[:lineIndex | |
|
887 |
linePos := lineArray at:lineIndex. |
|
888 |
[offs <= linePos] whileTrue:[ |
|
889 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
890 |
argArray at:dstOffs put:offs. |
|
891 |
offs := offs + 1. |
|
892 |
dstOffs := dstOffs + 1 |
|
893 |
]. |
|
894 |
convertedLabels at:dstOffs put:'-'. |
|
895 |
argArray at:dstOffs put:nil. |
|
896 |
dstOffs := dstOffs + 1 |
|
897 |
]. |
|
898 |
[offs <= labelArray size] whileTrue:[ |
|
899 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
900 |
argArray at:dstOffs put:offs. |
|
901 |
offs := offs + 1. |
|
902 |
dstOffs := dstOffs + 1 |
|
903 |
]. |
|
904 |
self menu:(MenuView |
|
905 |
labels:convertedLabels |
|
906 |
selectors:nil |
|
907 |
args:argArray |
|
908 |
receiver:nil |
|
909 |
in:self) |
|
910 |
! |
|
911 |
||
912 |
lines |
|
913 |
"st-80 compatibility" |
|
914 |
||
915 |
^ actionLines |
|
916 |
! |
|
917 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
918 |
menuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
919 |
"return the submenu for entry indexOrName." |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
920 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
921 |
^ self subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
922 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
923 |
"Created: 24.3.1996 / 17:11:05 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
924 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
925 |
|
202 | 926 |
numberOfItems |
927 |
"return the number of items in the menu" |
|
928 |
||
929 |
actionLabels notNil ifTrue:[ |
|
930 |
^ actionLabels asStringCollection size |
|
931 |
]. |
|
932 |
^ menuView list size |
|
933 |
! |
|
934 |
||
935 |
remove:indexOrName |
|
936 |
"remove a menu entry" |
|
937 |
||
938 |
menuView remove:indexOrName |
|
939 |
! |
|
940 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
941 |
subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
942 |
"return the submenu for entry indexOrName" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
943 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
944 |
^ menuView subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
945 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
946 |
"Created: 24.3.1996 / 17:09:15 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
947 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
948 |
|
202 | 949 |
subMenuAt:indexOrName put:aMenu |
950 |
"define a submenu to be shown for entry indexOrName" |
|
951 |
||
952 |
" |
|
953 |
aMenu hideOnLeave:true. |
|
954 |
" |
|
955 |
menuView subMenuAt:indexOrName put:aMenu. |
|
956 |
"tell the submenu to notify me when action is performed" |
|
957 |
aMenu superMenu:self. |
|
958 |
||
959 |
" |
|
960 |
|v m someObject| |
|
961 |
||
962 |
v := View new. |
|
963 |
m := PopUpMenu labels:#('1' '2' '3') |
|
964 |
selectors:#(one two nil) |
|
965 |
receiver:someObject |
|
966 |
for:nil. |
|
967 |
m subMenuAt:3 put:(PopUpMenu |
|
968 |
labels:#('a' 'b' 'c') |
|
969 |
selectors:#(a b c) |
|
970 |
receiver:someObject |
|
971 |
for:nil). |
|
972 |
v middleButtonMenu:m. |
|
973 |
v realize |
|
974 |
" |
|
975 |
! |
|
976 |
||
977 |
values |
|
978 |
"st-80 compatibility" |
|
979 |
||
980 |
^ actionValues |
|
981 |
! |
|
982 |
||
983 |
values:aValueArray |
|
984 |
"st-80 compatibility" |
|
985 |
||
986 |
actionValues := aValueArray |
|
987 |
! ! |
|
988 |
||
989 |
!PopUpMenu methodsFor:'accessing-look'! |
|
990 |
||
991 |
font:aFont |
|
665 | 992 |
"set the menus font. |
993 |
CAVEAT: with the addition of Text objects, |
|
994 |
this method is going to be obsoleted by a textStyle |
|
995 |
method, which allows specific control over |
|
996 |
normalFont/boldFont/italicFont parameters." |
|
997 |
||
202 | 998 |
menuView font:aFont |
665 | 999 |
|
1000 |
"Modified: 22.5.1996 / 12:36:53 / cg" |
|
202 | 1001 |
! |
1002 |
||
1003 |
viewBackground:aColor |
|
1004 |
"this is a kludge and will vanish ..." |
|
1005 |
||
1006 |
super viewBackground:aColor. |
|
1007 |
menuView viewBackground:aColor |
|
1008 |
! ! |
|
1009 |
||
1010 |
!PopUpMenu methodsFor:'accessing-mvc'! |
|
1011 |
||
1012 |
changeMessage |
|
1013 |
"forward from my menu" |
|
1014 |
||
1015 |
^ menuView changeMessage |
|
1016 |
! |
|
1017 |
||
1018 |
changeMessage:aSymbol |
|
1019 |
"forward to my menu" |
|
1020 |
||
1021 |
menuView changeMessage:aSymbol |
|
1022 |
! |
|
1023 |
||
1024 |
model |
|
1025 |
^ menuView model |
|
1026 |
! |
|
1027 |
||
1028 |
model:aModel |
|
1029 |
menuView model:aModel |
|
1030 |
! ! |
|
1031 |
||
1032 |
!PopUpMenu methodsFor:'deactivation'! |
|
1033 |
||
1034 |
hide |
|
1035 |
"hide the menu - if there are any pop-up-submenus, hide them also" |
|
1036 |
||
1037 |
menuView hideSubmenu. |
|
1038 |
windowGroup notNil ifTrue:[ |
|
1039 |
windowGroup removeView:menuView. |
|
1040 |
]. |
|
1041 |
super hide. |
|
1042 |
menuView superMenu notNil ifTrue:[ |
|
1043 |
menuView superMenu regainControl |
|
1044 |
]. |
|
1045 |
! ! |
|
1046 |
||
70 | 1047 |
!PopUpMenu methodsFor:'event handling'! |
0 | 1048 |
|
161 | 1049 |
buttonMotion:state x:x y:y |
70 | 1050 |
|p superMenu| |
7 | 1051 |
|
161 | 1052 |
state == 0 ifTrue:[^ self]. |
1053 |
||
38 | 1054 |
((x >= 0) and:[x < width]) ifTrue:[ |
59 | 1055 |
((y >= 0) and:[y < height]) ifTrue:[ |
105 | 1056 |
hideOnRelease := true. |
161 | 1057 |
menuView buttonMotion:state x:x y:y. |
59 | 1058 |
^ self |
1059 |
] |
|
0 | 1060 |
]. |
7 | 1061 |
|
1062 |
"outside of myself" |
|
70 | 1063 |
superMenu := menuView superMenu. |
1064 |
superMenu notNil ifTrue:[ |
|
59 | 1065 |
p := device translatePoint:(x @ y) |
1066 |
from:drawableId |
|
1067 |
to:(menuView superMenu id). |
|
161 | 1068 |
superMenu buttonMotion:state x:p x y:p y |
7 | 1069 |
]. |
1070 |
||
1071 |
menuView subMenuShown isNil ifTrue:[ |
|
161 | 1072 |
menuView pointerLeave:state. |
7 | 1073 |
]. |
1074 |
||
0 | 1075 |
hideOnLeave ifTrue:[ |
59 | 1076 |
self hide |
38 | 1077 |
]. |
0 | 1078 |
! |
1079 |
||
105 | 1080 |
buttonPress:button x:x y:y |
497 | 1081 |
hideOnRelease := true. |
1082 |
((x >= 0) and:[x < width]) ifTrue:[ |
|
1083 |
((y >= 0) and:[y < height]) ifTrue:[ |
|
1084 |
menuView buttonPress:button x:x y:y. |
|
1085 |
^ self |
|
1086 |
] |
|
105 | 1087 |
]. |
497 | 1088 |
|
1089 |
"Modified: 8.3.1996 / 14:03:34 / cg" |
|
105 | 1090 |
! |
1091 |
||
0 | 1092 |
buttonRelease:button x:x y:y |
497 | 1093 |
|now| |
1094 |
||
1095 |
realized ifFalse:[^ self]. |
|
1096 |
||
1097 |
"/ |
|
1098 |
"/ detect short click - stay open if this is one |
|
1099 |
"/ |
|
1100 |
(OperatingSystem |
|
1101 |
millisecondTimeDeltaBetween:(Time millisecondClockValue) |
|
1102 |
and:mapTime) > 200 ifFalse:[ |
|
1103 |
hideOnRelease := false |
|
1104 |
]. |
|
1105 |
||
105 | 1106 |
hideOnRelease ifFalse:[ |
425 | 1107 |
^ self |
105 | 1108 |
]. |
1109 |
||
497 | 1110 |
(x < 0 |
1111 |
or:[x >= width |
|
1112 |
or:[y < 0 |
|
1113 |
or:[y >= height]]]) ifTrue:[ |
|
1114 |
"/ |
|
1115 |
"/ released outside of mySelf |
|
1116 |
"/ |
|
1117 |
menuView superMenu notNil ifTrue:[ |
|
1118 |
menuView superMenu hideSubmenu |
|
1119 |
] ifFalse:[ |
|
1120 |
self hide |
|
1121 |
]. |
|
1122 |
^ self |
|
1123 |
]. |
|
1124 |
||
1125 |
||
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1126 |
"/ menuView superMenu notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1127 |
"/ menuView superMenu submenuTriggered |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1128 |
"/ ]. |
497 | 1129 |
|
7 | 1130 |
menuView buttonRelease:button x:x y:y. |
425 | 1131 |
|
497 | 1132 |
"Modified: 8.3.1996 / 14:17:18 / cg" |
112 | 1133 |
! |
1134 |
||
1135 |
keyPress:key x:x y:y |
|
491 | 1136 |
<resource: #keyboard (#Tab)> |
1137 |
||
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1138 |
(x isNil or:[x == 0]) ifTrue:[ |
425 | 1139 |
"/ already redelegated |
1140 |
^ self |
|
1141 |
]. |
|
1142 |
||
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1143 |
key == #Tab ifTrue:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1144 |
self hide. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1145 |
super keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1146 |
] ifFalse:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1147 |
menuView keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1148 |
]. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1149 |
|
491 | 1150 |
"Modified: 7.3.1996 / 13:17:54 / cg" |
202 | 1151 |
! |
1152 |
||
342
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1153 |
mapped |
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1154 |
super mapped. |
497 | 1155 |
|
1156 |
"/ |
|
1157 |
"/ check if a button is pressed when mapped; |
|
1158 |
"/ if not, change my hide-strategy |
|
1159 |
"/ |
|
1160 |
||
1161 |
"/ device buttonStates == 0 ifTrue:[ |
|
1162 |
"/ hideOnRelease := false |
|
1163 |
"/ ]. |
|
342
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1164 |
|
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1165 |
"Created: 9.2.1996 / 19:56:20 / cg" |
497 | 1166 |
"Modified: 8.3.1996 / 13:42:15 / cg" |
342
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1167 |
! |
ddbe4e8d6e9f
check if buttons are down at map-time; change release behavior, if no button is pressed then
Claus Gittinger <cg@exept.de>
parents:
335
diff
changeset
|
1168 |
|
202 | 1169 |
pointerEnter:state x:x y:y |
1170 |
"catch quick release of button" |
|
1171 |
||
1172 |
hideOnLeave ifTrue:[ |
|
1173 |
state == 0 ifTrue:[^ self hide]. |
|
1174 |
] |
|
1175 |
! |
|
1176 |
||
1177 |
pointerLeave:state |
|
1178 |
"/ menuView pointerLeave:state. |
|
1179 |
"/ hideOnLeave ifTrue:[ |
|
1180 |
"/ self hide |
|
1181 |
"/ ]. |
|
1182 |
"/ menuView superMenu notNil ifTrue:[ |
|
1183 |
"/ menuView superMenu regainControl |
|
1184 |
"/ ] |
|
0 | 1185 |
! ! |
202 | 1186 |
|
1187 |
!PopUpMenu methodsFor:'initialization'! |
|
1188 |
||
1189 |
initEvents |
|
1190 |
super initEvents. |
|
1191 |
self enableEnterLeaveEvents. |
|
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1192 |
"/ self enableMotionEvents. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1193 |
|
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1194 |
"Modified: 7.3.1996 / 14:17:42 / cg" |
202 | 1195 |
! |
1196 |
||
1197 |
initialize |
|
1198 |
super initialize. |
|
1199 |
||
1200 |
memorize := true. |
|
1201 |
hideOnLeave := false. |
|
1202 |
defaultHideOnRelease := DefaultHideOnRelease. |
|
1203 |
! ! |
|
1204 |
||
1205 |
!PopUpMenu methodsFor:'menuview messages'! |
|
1206 |
||
1207 |
doesNotUnderstand:aMessage |
|
1208 |
"forward all menu-view messages" |
|
1209 |
||
1210 |
(menuView respondsTo:(aMessage selector)) ifTrue:[ |
|
1211 |
^ aMessage sendTo:menuView |
|
1212 |
]. |
|
1213 |
^ super doesNotUnderstand:aMessage |
|
1214 |
! ! |
|
1215 |
||
1216 |
!PopUpMenu methodsFor:'private accessing'! |
|
1217 |
||
1218 |
menu:aMenu |
|
1219 |
"set the actual menu" |
|
1220 |
||
1221 |
menuView := aMenu. |
|
1222 |
menuView origin:(margin @ margin). |
|
1223 |
menuView borderWidth:0. |
|
1224 |
menuView masterView:self |
|
1225 |
! |
|
1226 |
||
1227 |
menuView |
|
1228 |
"return the actual menu" |
|
1229 |
||
1230 |
^ menuView |
|
1231 |
! |
|
1232 |
||
1233 |
superMenu:aMenu |
|
1234 |
"return the superMenu" |
|
1235 |
||
1236 |
menuView superMenu:aMenu |
|
1237 |
! ! |
|
1238 |
||
1239 |
!PopUpMenu methodsFor:'realization'! |
|
1240 |
||
1241 |
fixSize |
|
1242 |
"called right before the view is made visible. |
|
1243 |
adjust my size to the size of the actual menu" |
|
1244 |
||
1245 |
|extra newWidth newHeight| |
|
1246 |
||
1247 |
extra := margin * 2. |
|
1248 |
menuView resizeIfChanged. |
|
1249 |
newWidth := menuView width + extra. |
|
1250 |
newHeight := menuView height + extra. |
|
1251 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[ |
|
1252 |
self extent:(menuView width + extra) @ (menuView height + extra) |
|
1253 |
]. |
|
1254 |
super fixSize |
|
1255 |
! |
|
1256 |
||
1257 |
realize |
|
1258 |
menuView deselectWithoutRedraw. |
|
1259 |
super realize. |
|
1260 |
hideOnRelease := defaultHideOnRelease. |
|
1261 |
! ! |
|
1262 |
||
205 | 1263 |
!PopUpMenu class methodsFor:'documentation'! |
1264 |
||
1265 |
version |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
1266 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.54 1996-05-30 07:17:48 cg Exp $' |
205 | 1267 |
! ! |