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