author | Claus Gittinger <cg@exept.de> |
Fri, 21 Mar 1997 13:12:28 +0100 | |
changeset 1150 | ce8842029d20 |
parent 1057 | 220f818b0577 |
child 1175 | 9c8aec66cc17 |
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. |
|
1056 | 394 |
newMenu menuView:aMenuView. |
38 | 395 |
^ newMenu |
1056 | 396 |
|
397 |
"Modified: 25.2.1997 / 20:52:42 / cg" |
|
38 | 398 |
! |
399 |
||
692 | 400 |
labels:labels args:args |
401 |
"create and return a menu with label-items and args. |
|
402 |
The actionBlock has to be defined later" |
|
403 |
||
404 |
^ self labels:labels selectors:nil accelerators:nil args:args receiver:nil for:nil |
|
405 |
||
406 |
" |
|
407 |
|m| |
|
408 |
||
409 |
m := PopUpMenu labels:#('foo' 'bar') |
|
410 |
args:#('hello world' 'how about this'). |
|
411 |
m action:[:arg | |
|
412 |
Transcript showCR:arg |
|
413 |
]. |
|
414 |
||
415 |
m showAtPointer |
|
416 |
" |
|
417 |
||
418 |
"Modified: 25.5.1996 / 17:01:43 / cg" |
|
419 |
! |
|
420 |
||
202 | 421 |
labels:labels selector:aSelector args:args receiver:anObject |
422 |
"create and return a popup menu with labels as entries. |
|
423 |
Each item will send aSelector with a corresponding argument from the |
|
424 |
args array to anObject. The menu is created on the default DIsplay" |
|
425 |
||
426 |
" |
|
427 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
428 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
429 |
^ 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
|
430 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
431 |
"Modified: 28.2.1996 / 19:01:12 / cg" |
202 | 432 |
! |
433 |
||
434 |
labels:labels selector:aSelector args:args receiver:anObject for:aView |
|
435 |
"create and return a popup menu with labels as entries. |
|
436 |
Each item will send aSelector with a corresponding argument from the |
|
437 |
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
|
438 |
as aView (which is only of interest in multi-Display applications; |
202 | 439 |
typical applications can use the sibbling message without the for: argument)." |
440 |
||
441 |
" |
|
442 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
443 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
444 |
^ 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
|
445 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
446 |
"Modified: 28.2.1996 / 19:01:29 / cg" |
202 | 447 |
! |
448 |
||
449 |
labels:labels selectors:selectors |
|
450 |
"create and return a menu with label-items and selectors. The receiver |
|
451 |
will either be defined later, or not used at all (if opened via startUp)" |
|
452 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
453 |
^ 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
|
454 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
455 |
"Modified: 28.2.1996 / 19:01:35 / cg" |
202 | 456 |
! |
457 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
458 |
labels:labels selectors:selectors accelerators:shorties |
202 | 459 |
"create and return a menu with label-items and selectors. The receiver |
460 |
will either be defined later, or not used at all (if opened via startUp)" |
|
461 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
462 |
^ 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
|
463 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
464 |
"Created: 28.2.1996 / 18:58:52 / cg" |
202 | 465 |
! |
466 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
467 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject |
202 | 468 |
"create and return a popup menu with labels as entries. |
469 |
Each item will send a corresponding selector:argument from the selectors- |
|
470 |
and args array to anObject. The menu is created on the default Display" |
|
471 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
472 |
^ 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
|
473 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
474 |
"Created: 28.2.1996 / 18:59:03 / cg" |
202 | 475 |
! |
476 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
477 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject for:aView |
63 | 478 |
"create and return a popup menu with labels as entries. |
479 |
Each item will send a corresponding selector:argument from the selectors- |
|
480 |
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
|
481 |
as aView (which is only of interest in multi-Display applications; |
63 | 482 |
typical applications can use the sibbling message without the for: argument)." |
483 |
||
38 | 484 |
|newMenu| |
485 |
||
486 |
newMenu := self onSameDeviceAs:aView. |
|
1056 | 487 |
newMenu menuView:(MenuView |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
488 |
labels:labels |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
489 |
selectors:selectors |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
490 |
accelerators:shorties |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
491 |
args:args |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
492 |
receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
493 |
in:newMenu). |
38 | 494 |
^ newMenu |
426
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 |
"Created: 28.2.1996 / 18:59:25 / cg" |
1056 | 497 |
"Modified: 25.2.1997 / 20:52:47 / cg" |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
498 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
499 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
500 |
labels:labels selectors:selectors accelerators:shorties receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
501 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
502 |
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
|
503 |
selectors-array. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
504 |
The menu is created on the default Display." |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
505 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
506 |
^ 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
|
507 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
508 |
"Created: 28.2.1996 / 19:00:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
509 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
510 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
511 |
labels:labels selectors:selectors args:argArray |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
512 |
"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
|
513 |
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
|
514 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
515 |
^ 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
|
516 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
517 |
"Modified: 28.2.1996 / 19:01:45 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
518 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
519 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
520 |
labels:labels selectors:selectors args:args receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
521 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
522 |
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
|
523 |
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
|
524 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
525 |
^ 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
|
526 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
527 |
"Modified: 28.2.1996 / 19:01:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
528 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
529 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
530 |
labels:labels selectors:selectors args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
531 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
532 |
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
|
533 |
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
|
534 |
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
|
535 |
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
|
536 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
537 |
^ 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
|
538 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
539 |
"Modified: 28.2.1996 / 19:03:58 / cg" |
38 | 540 |
! |
541 |
||
119 | 542 |
labels:labels selectors:selectors receiver:anObject |
543 |
"create and return a popup menu with labels as entries. |
|
544 |
Each item will send a message with a selector from the corresponding |
|
545 |
selectors-array. |
|
546 |
The menu is created on the default Display." |
|
547 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
548 |
^ 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
|
549 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
550 |
"Modified: 28.2.1996 / 19:02:07 / cg" |
63 | 551 |
! |
552 |
||
202 | 553 |
labels:labels selectors:selectors receiver:anObject for:aView |
554 |
"create and return a popup menu with labels as entries. |
|
555 |
Each item will send a corresponding selector from the selectors-array |
|
556 |
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
|
557 |
as aView (which is only of interest in multi-Display applications; |
202 | 558 |
typical applications can use the sibbling message without the for: argument)." |
63 | 559 |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
560 |
^ 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
|
561 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
562 |
"Modified: 28.2.1996 / 19:02:10 / cg" |
0 | 563 |
! ! |
564 |
||
565 |
!PopUpMenu class methodsFor:'ST-80 instance creation'! |
|
566 |
||
202 | 567 |
labelArray:labels lines:lines values:values |
568 |
"ST80R4 compatibility" |
|
119 | 569 |
|
202 | 570 |
^ self labels:labels lines:lines values:values |
0 | 571 |
! |
572 |
||
119 | 573 |
labelArray:labels values:values |
574 |
"ST80R4 compatibility" |
|
575 |
||
576 |
^ self labels:labels lines:nil values:values |
|
577 |
! |
|
578 |
||
202 | 579 |
labelList:labels |
580 |
"ST80R4 compatibility: |
|
581 |
given a list consisting of group label entries (to be separated by |
|
582 |
lines), convert into standard form (using '-' for lines. |
|
583 |
" |
|
584 |
||
585 |
^ self labelList:labels values:nil |
|
119 | 586 |
|
202 | 587 |
" |
588 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer |
|
589 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer |
|
590 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer |
|
591 |
" |
|
592 |
! |
|
593 |
||
594 |
labelList:labels lines:lines values:values |
|
595 |
"mhmh what is that ?" |
|
596 |
||
597 |
^ (self new) labels:labels lines:lines values:values |
|
119 | 598 |
! |
599 |
||
0 | 600 |
labelList:labels values:values |
119 | 601 |
"ST80R4 compatibility: |
602 |
given a list consisting of group label entries (to be separated by |
|
603 |
lines), convert into standard form (using '-' for lines. |
|
604 |
" |
|
605 |
||
606 |
|newLabels newValues lS vS first| |
|
607 |
||
608 |
newLabels := OrderedCollection new. |
|
609 |
newValues := OrderedCollection new. |
|
610 |
lS := ReadStream on:labels. |
|
611 |
values notNil ifTrue:[vS := ReadStream on:values]. |
|
612 |
first := true. |
|
613 |
[lS atEnd] whileFalse:[ |
|
614 |
|entry| |
|
615 |
||
616 |
entry := lS next. |
|
617 |
entry isCollection ifTrue:[ |
|
618 |
first ifFalse:[ |
|
619 |
newLabels add:'-'. |
|
620 |
values notNil ifTrue:[newValues add:nil] |
|
621 |
]. |
|
622 |
newLabels addAll:entry. |
|
623 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)] |
|
624 |
] ifFalse:[ |
|
625 |
newLabels add:entry. |
|
626 |
values notNil ifTrue:[newValues add:(vS next)] |
|
627 |
]. |
|
628 |
first := false. |
|
629 |
]. |
|
630 |
values isNil ifTrue:[ |
|
631 |
^ self labels:newLabels |
|
632 |
]. |
|
633 |
^ self labels:newLabels values:newValues |
|
634 |
||
635 |
" |
|
636 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer |
|
637 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer |
|
638 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer |
|
639 |
" |
|
640 |
! |
|
641 |
||
202 | 642 |
labels:labels |
643 |
"ST80R2 compatibility" |
|
59 | 644 |
|
202 | 645 |
^ self labels:labels lines:nil values:nil |
0 | 646 |
! |
647 |
||
202 | 648 |
labels:labels lines:lines |
649 |
"ST80R2 compatibility" |
|
0 | 650 |
|
202 | 651 |
^ self labels:labels lines:lines values:nil |
77 | 652 |
! |
653 |
||
202 | 654 |
labels:labels lines:lines values:values |
655 |
"ST80R2 compatibility" |
|
127 | 656 |
|
202 | 657 |
^ (self new) labels:labels lines:lines values:values |
77 | 658 |
! |
659 |
||
202 | 660 |
labels:labels values:values |
661 |
"ST80R2 compatibility" |
|
59 | 662 |
|
202 | 663 |
^ self labels:labels lines:nil values:values |
127 | 664 |
! ! |
665 |
||
202 | 666 |
!PopUpMenu class methodsFor:'defaults'! |
0 | 667 |
|
202 | 668 |
updateStyleCache |
959 | 669 |
"extract values from the styleSheet and cache them in class variables" |
670 |
||
608 | 671 |
<resource: #style (#popupHideOnRelease)> |
672 |
||
202 | 673 |
DefaultHideOnRelease := StyleSheet at:#popupHideOnRelease default:true. |
608 | 674 |
|
959 | 675 |
"Modified: 17.1.1997 / 23:19:29 / cg" |
0 | 676 |
! ! |
677 |
||
678 |
!PopUpMenu methodsFor:'ST-80 activation'! |
|
679 |
||
680 |
startUp |
|
38 | 681 |
"start the menu modal - return the selected value, |
682 |
or - if no values where specified - return the index. |
|
0 | 683 |
If nothing was selected, return 0. |
38 | 684 |
Modal - i.e. stay in the menu until finished. |
685 |
This is the ST-80 way of launching a menu." |
|
0 | 686 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
687 |
^ self startUpAt:nil |
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 |
" |
655 | 690 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
691 |
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
|
692 |
values:#(foo bar baz)) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
693 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
694 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
695 |
"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
|
696 |
! |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
697 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
698 |
startUpAt:aPoint |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
699 |
"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
|
700 |
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
|
701 |
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
|
702 |
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
|
703 |
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
|
704 |
|
96 | 705 |
|return rec sel0 sel1 arg| |
63 | 706 |
|
119 | 707 |
return := 0. |
692 | 708 |
menuView args notNil ifTrue:[ |
709 |
return := nil |
|
710 |
]. |
|
119 | 711 |
|
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
712 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
713 |
"/ 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
|
714 |
"/ 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
|
715 |
"/ (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
|
716 |
"/ 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
|
717 |
"/ 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
|
718 |
"/ 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
|
719 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
720 |
|
692 | 721 |
menuView action isNil ifTrue:[ |
722 |
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
|
723 |
|actionIndex value sel retVal selIdx |
692 | 724 |
args selectors checkFlags check| |
119 | 725 |
|
878 | 726 |
selected isNil ifTrue:[ |
727 |
"/ the menu has already sent a message or performed an item-action; do nothing here |
|
728 |
^ nil |
|
729 |
]. |
|
730 |
||
692 | 731 |
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
|
732 |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
733 |
selIdx := menuView selection. |
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
734 |
|
692 | 735 |
args := menuView args. |
736 |
selectors := menuView selectors. |
|
737 |
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
|
738 |
|
692 | 739 |
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
|
740 |
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
|
741 |
sel0 := selectors at:selIdx. |
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
742 |
]. |
692 | 743 |
] ifFalse:[ |
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
744 |
actionIndex := selected. |
692 | 745 |
actionIndex notNil ifTrue:[ |
746 |
actionValues isNil ifTrue:[ |
|
747 |
selectors notNil ifTrue:[ |
|
748 |
"/ 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
|
749 |
|
726
bef52bf8f6c3
oops - menuAction is now called with arg if there is one
Claus Gittinger <cg@exept.de>
parents:
692
diff
changeset
|
750 |
sel1 := selectors at:selIdx. |
692 | 751 |
arg := actionIndex. |
752 |
] ifFalse:[ |
|
753 |
retVal := actionIndex |
|
754 |
] |
|
755 |
] ifFalse:[ |
|
756 |
retVal := actionValues at:actionIndex. |
|
757 |
(retVal isKindOf:PopUpMenu) ifTrue:[ |
|
758 |
retVal := retVal startUp |
|
759 |
] |
|
760 |
] |
|
761 |
] ifFalse:[ |
|
762 |
"/ 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
|
763 |
|
692 | 764 |
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
|
765 |
sel0 := selectors at:selIdx. |
692 | 766 |
]. |
767 |
] |
|
768 |
]. |
|
769 |
||
770 |
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
|
771 |
check := checkFlags at:selIdx. |
692 | 772 |
check notNil ifTrue:[ |
773 |
arg := check. |
|
774 |
sel1 := sel0. |
|
775 |
sel0 := nil. |
|
776 |
] |
|
777 |
]. |
|
778 |
return := retVal. |
|
779 |
||
780 |
menuView action:nil |
|
781 |
] |
|
0 | 782 |
]. |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
783 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
784 |
aPoint isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
785 |
self showAtPointer |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
786 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
787 |
self showAt:aPoint. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
788 |
]. |
96 | 789 |
|
790 |
"/ |
|
791 |
"/ mhmh an ST/X menu started the ST-80 way |
|
792 |
"/ |
|
793 |
(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
|
794 |
rec := menuView receiver. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
795 |
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
|
796 |
^ sel0 |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
797 |
]. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
798 |
^ Array with:sel1 with:arg. |
95 | 799 |
]. |
63 | 800 |
^ return |
38 | 801 |
|
802 |
" |
|
655 | 803 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
804 |
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
|
805 |
values:#(foo bar baz)) startUp |
38 | 806 |
" |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
807 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
808 |
"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
|
809 |
"Modified: 30.5.1996 / 09:16:57 / cg" |
110 | 810 |
! |
811 |
||
812 |
startUpWithHeading:aString |
|
813 |
"start the menu modal - return the selected value, |
|
814 |
or - if no values where specified - return the index. |
|
815 |
If nothing was selected, return 0. |
|
816 |
Modal - i.e. stay in the menu until finished. |
|
817 |
This is the ST-80 way of launching a menu." |
|
818 |
||
819 |
defaultHideOnRelease := false. |
|
820 |
menuView labels notNil ifTrue:[ |
|
821 |
menuView labels:(Array with:aString with:'=') , menuView labels. |
|
822 |
]. |
|
823 |
menuView selectors notNil ifTrue:[ |
|
824 |
menuView selectors:(Array with:nil with:nil) , menuView selectors. |
|
825 |
]. |
|
826 |
"/ menuView disable:1; disable:2. |
|
827 |
||
828 |
^ self startUp. |
|
829 |
||
830 |
" |
|
831 |
(PopUpMenu |
|
832 |
labels:#('foo' 'bar')) |
|
833 |
startUp |
|
834 |
" |
|
835 |
" |
|
836 |
(PopUpMenu |
|
837 |
labels:#('foo' 'bar')) |
|
838 |
startUpWithHeading:'hello' |
|
839 |
" |
|
0 | 840 |
! ! |
841 |
||
202 | 842 |
!PopUpMenu methodsFor:'accessing-behavior'! |
843 |
||
844 |
hideOnLeave:aBoolean |
|
845 |
"set/clear the hideOnLeave attribute, which controls |
|
846 |
if the menu should be hidden when the pointer leaves |
|
847 |
the view (used with multiple-menus)" |
|
848 |
||
849 |
hideOnLeave := aBoolean |
|
850 |
! |
|
851 |
||
852 |
hideOnRelease:aBoolean |
|
853 |
"set/clear the hideOnRelease attribute, which controls |
|
854 |
if the menu should be hidden when the button is released" |
|
855 |
||
335
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
856 |
defaultHideOnRelease := aBoolean. |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
857 |
menuView hideOnRelease:aBoolean |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
858 |
|
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
859 |
"Modified: 9.2.1996 / 02:06:15 / cg" |
202 | 860 |
! ! |
861 |
||
862 |
!PopUpMenu methodsFor:'accessing-items'! |
|
863 |
||
864 |
indexOf:indexOrName |
|
865 |
"return the index of a submenu - or 0 if there is none" |
|
866 |
||
867 |
^ menuView indexOf:indexOrName |
|
868 |
! |
|
869 |
||
870 |
labels |
|
871 |
"return the list of labels" |
|
872 |
||
873 |
actionLabels notNil ifTrue:[ |
|
874 |
^ actionLabels asStringCollection |
|
875 |
]. |
|
876 |
^ menuView list |
|
877 |
! |
|
878 |
||
879 |
labels:labelString lines:lineArray values:valueArray |
|
880 |
"define the menu the ST-80 way (with labels and lines defined separately)" |
|
881 |
||
882 |
|labelArray argArray convertedLabels |
|
883 |
offs dstOffs linePos| |
|
884 |
||
885 |
actionLabels := labelString. |
|
886 |
actionLines := lineArray. |
|
887 |
actionValues := valueArray. |
|
888 |
||
889 |
labelArray := labelString asStringCollection. |
|
890 |
||
891 |
convertedLabels := Array new:(labelArray size + lineArray size). |
|
892 |
argArray := Array new:(labelArray size + lineArray size). |
|
893 |
||
894 |
offs := 1. |
|
895 |
dstOffs := 1. |
|
896 |
1 to:lineArray size do:[:lineIndex | |
|
1056 | 897 |
linePos := lineArray at:lineIndex. |
898 |
[offs <= linePos] 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 |
convertedLabels at:dstOffs put:'-'. |
|
905 |
argArray at:dstOffs put:nil. |
|
906 |
dstOffs := dstOffs + 1 |
|
202 | 907 |
]. |
908 |
[offs <= labelArray size] whileTrue:[ |
|
1056 | 909 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
910 |
argArray at:dstOffs put:offs. |
|
911 |
offs := offs + 1. |
|
912 |
dstOffs := dstOffs + 1 |
|
202 | 913 |
]. |
1056 | 914 |
self menuView:(MenuView |
915 |
labels:convertedLabels |
|
916 |
selectors:nil |
|
917 |
args:argArray |
|
918 |
receiver:nil |
|
919 |
in:self) |
|
920 |
||
921 |
"Modified: 25.2.1997 / 20:52:49 / cg" |
|
202 | 922 |
! |
923 |
||
924 |
lines |
|
925 |
"st-80 compatibility" |
|
926 |
||
927 |
^ actionLines |
|
928 |
! |
|
929 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
930 |
menuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
931 |
"return the submenu for entry indexOrName." |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
932 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
933 |
^ self subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
934 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
935 |
"Created: 24.3.1996 / 17:11:05 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
936 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
937 |
|
202 | 938 |
numberOfItems |
939 |
"return the number of items in the menu" |
|
940 |
||
941 |
actionLabels notNil ifTrue:[ |
|
942 |
^ actionLabels asStringCollection size |
|
943 |
]. |
|
944 |
^ menuView list size |
|
945 |
! |
|
946 |
||
947 |
remove:indexOrName |
|
948 |
"remove a menu entry" |
|
949 |
||
950 |
menuView remove:indexOrName |
|
951 |
! |
|
952 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
953 |
subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
954 |
"return the submenu for entry indexOrName" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
955 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
956 |
^ menuView subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
957 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
958 |
"Created: 24.3.1996 / 17:09:15 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
959 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
960 |
|
202 | 961 |
subMenuAt:indexOrName put:aMenu |
962 |
"define a submenu to be shown for entry indexOrName" |
|
963 |
||
964 |
" |
|
965 |
aMenu hideOnLeave:true. |
|
966 |
" |
|
967 |
menuView subMenuAt:indexOrName put:aMenu. |
|
968 |
"tell the submenu to notify me when action is performed" |
|
969 |
aMenu superMenu:self. |
|
970 |
||
971 |
" |
|
972 |
|v m someObject| |
|
973 |
||
974 |
v := View new. |
|
975 |
m := PopUpMenu labels:#('1' '2' '3') |
|
976 |
selectors:#(one two nil) |
|
977 |
receiver:someObject |
|
978 |
for:nil. |
|
979 |
m subMenuAt:3 put:(PopUpMenu |
|
980 |
labels:#('a' 'b' 'c') |
|
981 |
selectors:#(a b c) |
|
982 |
receiver:someObject |
|
983 |
for:nil). |
|
984 |
v middleButtonMenu:m. |
|
985 |
v realize |
|
986 |
" |
|
987 |
! |
|
988 |
||
989 |
values |
|
990 |
"st-80 compatibility" |
|
991 |
||
992 |
^ actionValues |
|
993 |
! |
|
994 |
||
995 |
values:aValueArray |
|
996 |
"st-80 compatibility" |
|
997 |
||
998 |
actionValues := aValueArray |
|
999 |
! ! |
|
1000 |
||
1001 |
!PopUpMenu methodsFor:'accessing-look'! |
|
1002 |
||
1003 |
font:aFont |
|
665 | 1004 |
"set the menus font. |
1005 |
CAVEAT: with the addition of Text objects, |
|
1006 |
this method is going to be obsoleted by a textStyle |
|
1007 |
method, which allows specific control over |
|
1008 |
normalFont/boldFont/italicFont parameters." |
|
1009 |
||
202 | 1010 |
menuView font:aFont |
665 | 1011 |
|
1012 |
"Modified: 22.5.1996 / 12:36:53 / cg" |
|
202 | 1013 |
! |
1014 |
||
1015 |
viewBackground:aColor |
|
1016 |
"this is a kludge and will vanish ..." |
|
1017 |
||
1018 |
super viewBackground:aColor. |
|
1019 |
menuView viewBackground:aColor |
|
1020 |
! ! |
|
1021 |
||
1022 |
!PopUpMenu methodsFor:'accessing-mvc'! |
|
1023 |
||
1024 |
changeMessage |
|
754 | 1025 |
"set the changeMessage from my menu" |
202 | 1026 |
|
1027 |
^ menuView changeMessage |
|
754 | 1028 |
|
1029 |
"Modified: 5.6.1996 / 17:08:52 / cg" |
|
202 | 1030 |
! |
1031 |
||
1032 |
changeMessage:aSymbol |
|
754 | 1033 |
"set the changeMessage - forward to my menu" |
202 | 1034 |
|
1035 |
menuView changeMessage:aSymbol |
|
754 | 1036 |
|
1037 |
"Modified: 5.6.1996 / 17:08:41 / cg" |
|
202 | 1038 |
! |
1039 |
||
962 | 1040 |
menuPerformer |
1041 |
"get the menuPerformer - forwarded to my menuViews" |
|
1042 |
||
1043 |
^ menuView menuPerformer |
|
1044 |
||
1045 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
1046 |
"Created: 21.1.1997 / 15:40:22 / cg" |
|
1047 |
! |
|
1048 |
||
1049 |
menuPerformer:someone |
|
1050 |
"set the menuPerformer - forwarded to my menuViews" |
|
1051 |
||
1052 |
menuView menuPerformer:someone |
|
1053 |
||
1054 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
1055 |
"Created: 21.1.1997 / 15:40:14 / cg" |
|
1056 |
! |
|
1057 |
||
202 | 1058 |
model |
753 | 1059 |
"return my menuViews model" |
1060 |
||
1061 |
^ menuView model |
|
1062 |
||
1063 |
"Modified: 5.6.1996 / 14:16:53 / cg" |
|
202 | 1064 |
! |
1065 |
||
1066 |
model:aModel |
|
754 | 1067 |
"set the model - forwarded to my menuViews" |
1068 |
||
202 | 1069 |
menuView model:aModel |
754 | 1070 |
|
1071 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
202 | 1072 |
! ! |
1073 |
||
1074 |
!PopUpMenu methodsFor:'deactivation'! |
|
1075 |
||
1076 |
hide |
|
1077 |
"hide the menu - if there are any pop-up-submenus, hide them also" |
|
1078 |
||
1079 |
menuView hideSubmenu. |
|
1080 |
super hide. |
|
1081 |
menuView superMenu notNil ifTrue:[ |
|
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1082 |
menuView superMenu regainControl |
202 | 1083 |
]. |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1084 |
|
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1085 |
"Modified: 25.2.1997 / 22:11:53 / cg" |
202 | 1086 |
! ! |
1087 |
||
70 | 1088 |
!PopUpMenu methodsFor:'event handling'! |
0 | 1089 |
|
161 | 1090 |
buttonMotion:state x:x y:y |
1150 | 1091 |
|p superMenu sensor| |
7 | 1092 |
|
161 | 1093 |
state == 0 ifTrue:[^ self]. |
1150 | 1094 |
(sensor := self sensor) isNil ifTrue:[^ self]. |
1095 |
(sensor hasButtonMotionEventFor:self) ifTrue:[^ self]. |
|
161 | 1096 |
|
38 | 1097 |
((x >= 0) and:[x < width]) ifTrue:[ |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1098 |
((y >= 0) and:[y < height]) ifTrue:[ |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1099 |
hideOnRelease := true. |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1100 |
menuView buttonMotion:state x:x y:y. |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1101 |
^ self |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1102 |
] |
0 | 1103 |
]. |
7 | 1104 |
|
1105 |
"outside of myself" |
|
70 | 1106 |
superMenu := menuView superMenu. |
1107 |
superMenu notNil ifTrue:[ |
|
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1108 |
p := device translatePoint:(x @ y) |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1109 |
from:drawableId |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1110 |
to:(menuView superMenu id). |
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1111 |
superMenu buttonMotion:state x:p x y:p y |
7 | 1112 |
]. |
1113 |
||
1114 |
menuView subMenuShown isNil ifTrue:[ |
|
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1115 |
menuView pointerLeave:state. |
7 | 1116 |
]. |
1117 |
||
0 | 1118 |
hideOnLeave ifTrue:[ |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1119 |
self hide |
38 | 1120 |
]. |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1121 |
|
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1122 |
"Modified: 25.2.1997 / 22:36:42 / cg" |
0 | 1123 |
! |
1124 |
||
105 | 1125 |
buttonPress:button x:x y:y |
497 | 1126 |
hideOnRelease := true. |
967 | 1127 |
|
497 | 1128 |
((x >= 0) and:[x < width]) ifTrue:[ |
1129 |
((y >= 0) and:[y < height]) ifTrue:[ |
|
1130 |
menuView buttonPress:button x:x y:y. |
|
1131 |
^ self |
|
1132 |
] |
|
105 | 1133 |
]. |
497 | 1134 |
|
967 | 1135 |
"Modified: 22.1.1997 / 17:38:14 / cg" |
105 | 1136 |
! |
1137 |
||
0 | 1138 |
buttonRelease:button x:x y:y |
497 | 1139 |
|now| |
1140 |
||
1141 |
realized ifFalse:[^ self]. |
|
1142 |
||
1143 |
"/ |
|
1144 |
"/ detect short click - stay open if this is one |
|
1145 |
"/ |
|
1146 |
(OperatingSystem |
|
1147 |
millisecondTimeDeltaBetween:(Time millisecondClockValue) |
|
1148 |
and:mapTime) > 200 ifFalse:[ |
|
1149 |
hideOnRelease := false |
|
1150 |
]. |
|
1151 |
||
105 | 1152 |
hideOnRelease ifFalse:[ |
425 | 1153 |
^ self |
105 | 1154 |
]. |
1155 |
||
497 | 1156 |
(x < 0 |
1157 |
or:[x >= width |
|
1158 |
or:[y < 0 |
|
1159 |
or:[y >= height]]]) ifTrue:[ |
|
1160 |
"/ |
|
1161 |
"/ released outside of mySelf |
|
1162 |
"/ |
|
1163 |
menuView superMenu notNil ifTrue:[ |
|
1164 |
menuView superMenu hideSubmenu |
|
1165 |
] ifFalse:[ |
|
1166 |
self hide |
|
1167 |
]. |
|
1168 |
^ self |
|
1169 |
]. |
|
1170 |
||
1171 |
||
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1172 |
"/ menuView superMenu notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1173 |
"/ menuView superMenu submenuTriggered |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1174 |
"/ ]. |
497 | 1175 |
|
7 | 1176 |
menuView buttonRelease:button x:x y:y. |
425 | 1177 |
|
497 | 1178 |
"Modified: 8.3.1996 / 14:17:18 / cg" |
112 | 1179 |
! |
1180 |
||
1181 |
keyPress:key x:x y:y |
|
491 | 1182 |
<resource: #keyboard (#Tab)> |
1183 |
||
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1184 |
(x isNil or:[x == 0]) ifTrue:[ |
425 | 1185 |
"/ already redelegated |
1186 |
^ self |
|
1187 |
]. |
|
1188 |
||
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1189 |
key == #Tab ifTrue:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1190 |
self hide. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1191 |
super keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1192 |
] ifFalse:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1193 |
menuView keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1194 |
]. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1195 |
|
491 | 1196 |
"Modified: 7.3.1996 / 13:17:54 / cg" |
202 | 1197 |
! |
1198 |
||
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
|
1199 |
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
|
1200 |
super mapped. |
497 | 1201 |
|
1202 |
"/ |
|
1203 |
"/ check if a button is pressed when mapped; |
|
1204 |
"/ if not, change my hide-strategy |
|
1205 |
"/ |
|
1206 |
||
1207 |
"/ device buttonStates == 0 ifTrue:[ |
|
1208 |
"/ hideOnRelease := false |
|
1209 |
"/ ]. |
|
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
|
1210 |
|
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
|
1211 |
"Created: 9.2.1996 / 19:56:20 / cg" |
497 | 1212 |
"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
|
1213 |
! |
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
|
1214 |
|
202 | 1215 |
pointerEnter:state x:x y:y |
1216 |
"catch quick release of button" |
|
1217 |
||
1218 |
hideOnLeave ifTrue:[ |
|
1219 |
state == 0 ifTrue:[^ self hide]. |
|
1220 |
] |
|
1221 |
! |
|
1222 |
||
1223 |
pointerLeave:state |
|
1224 |
"/ menuView pointerLeave:state. |
|
1225 |
"/ hideOnLeave ifTrue:[ |
|
1226 |
"/ self hide |
|
1227 |
"/ ]. |
|
1228 |
"/ menuView superMenu notNil ifTrue:[ |
|
1229 |
"/ menuView superMenu regainControl |
|
1230 |
"/ ] |
|
0 | 1231 |
! ! |
202 | 1232 |
|
1233 |
!PopUpMenu methodsFor:'initialization'! |
|
1234 |
||
1235 |
initEvents |
|
1236 |
super initEvents. |
|
1237 |
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
|
1238 |
"/ self enableMotionEvents. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1239 |
|
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1240 |
"Modified: 7.3.1996 / 14:17:42 / cg" |
202 | 1241 |
! |
1242 |
||
1243 |
initialize |
|
1244 |
super initialize. |
|
1245 |
||
1246 |
memorize := true. |
|
1247 |
hideOnLeave := false. |
|
1248 |
defaultHideOnRelease := DefaultHideOnRelease. |
|
1249 |
! ! |
|
1250 |
||
1251 |
!PopUpMenu methodsFor:'menuview messages'! |
|
1252 |
||
1253 |
doesNotUnderstand:aMessage |
|
1254 |
"forward all menu-view messages" |
|
1255 |
||
1256 |
(menuView respondsTo:(aMessage selector)) ifTrue:[ |
|
1257 |
^ aMessage sendTo:menuView |
|
1258 |
]. |
|
1259 |
^ super doesNotUnderstand:aMessage |
|
1260 |
! ! |
|
1261 |
||
1262 |
!PopUpMenu methodsFor:'private accessing'! |
|
1263 |
||
1056 | 1264 |
menu:aMenuView |
202 | 1265 |
"set the actual menu" |
1266 |
||
1056 | 1267 |
self obsoleteMethodWarning:'use #menuView:'. |
1268 |
self menuView:aMenuView |
|
1269 |
||
1270 |
"Modified: 25.2.1997 / 20:52:08 / cg" |
|
202 | 1271 |
! |
1272 |
||
1273 |
menuView |
|
1274 |
"return the actual menu" |
|
1275 |
||
1276 |
^ menuView |
|
1277 |
! |
|
1278 |
||
1056 | 1279 |
menuView:aMenu |
1280 |
"set the actual menu" |
|
1281 |
||
1282 |
menuView := aMenu. |
|
1283 |
menuView origin:(margin @ margin). |
|
1284 |
menuView borderWidth:0. |
|
1285 |
menuView masterView:self |
|
1286 |
||
1287 |
"Created: 25.2.1997 / 20:51:42 / cg" |
|
1288 |
! |
|
1289 |
||
202 | 1290 |
superMenu:aMenu |
1056 | 1291 |
"set the superMenu" |
202 | 1292 |
|
1293 |
menuView superMenu:aMenu |
|
1056 | 1294 |
|
1295 |
"Modified: 25.2.1997 / 20:52:20 / cg" |
|
202 | 1296 |
! ! |
1297 |
||
1298 |
!PopUpMenu methodsFor:'realization'! |
|
1299 |
||
1300 |
fixSize |
|
1301 |
"called right before the view is made visible. |
|
1302 |
adjust my size to the size of the actual menu" |
|
1303 |
||
1304 |
|extra newWidth newHeight| |
|
1305 |
||
1306 |
extra := margin * 2. |
|
1307 |
menuView resizeIfChanged. |
|
1308 |
newWidth := menuView width + extra. |
|
1309 |
newHeight := menuView height + extra. |
|
1310 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[ |
|
1311 |
self extent:(menuView width + extra) @ (menuView height + extra) |
|
1312 |
]. |
|
1313 |
super fixSize |
|
1314 |
! |
|
1315 |
||
1316 |
realize |
|
1317 |
menuView deselectWithoutRedraw. |
|
1318 |
super realize. |
|
1319 |
hideOnRelease := defaultHideOnRelease. |
|
1320 |
! ! |
|
1321 |
||
205 | 1322 |
!PopUpMenu class methodsFor:'documentation'! |
1323 |
||
1324 |
version |
|
1150 | 1325 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.63 1997-03-21 12:12:28 cg Exp $' |
205 | 1326 |
! ! |