author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Mon, 08 Sep 2014 17:03:09 +0100 | |
branch | delegated_gc_hg |
changeset 5128 | 787b617a99e5 |
parent 5049 | 7c2d0217f75a |
child 5252 | 810023c78eb9 |
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 |
" |
|
2173 | 12 |
"{ Package: 'stx:libwidg' }" |
13 |
||
0 | 14 |
PopUpView subclass:#PopUpMenu |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
15 |
instanceVariableNames:'menuView lastSelection memorize hideOnLeave actionLabels |
3365 | 16 |
actionLines actionValues hideOnRelease defaultHideOnRelease |
17 |
hideOnAnyKey hideOnKeyFilter' |
|
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
18 |
classVariableNames:'' |
281
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 |
" |
|
4685 | 41 |
Warning: this is a very old class which was written well before many improved |
42 |
successors and tools were added. A lot of stuff you find here is kept for backward |
|
43 |
compatibility. |
|
44 |
||
692 | 45 |
This class provides PopUpMenu functionality; |
46 |
-> Actually, this class only provides the popup and shadow functionality |
|
47 |
and wraps ANOTHER view, which shows the actual menu-list |
|
4685 | 48 |
(usually an instance of MenuView, but in theory, other views could be wrapped as popup). |
38 | 49 |
|
50 |
PopUpMenus are usually created with a list of labels, selectors and a |
|
4685 | 51 |
receiver. |
52 |
Once activated, the specified receiver will be sent a 'selector'-message. |
|
112 | 53 |
|
54 |
PopupMenus may be either assigned statically to a view (via the #middleButtonMenu: |
|
55 |
message) or created dynamically as required. |
|
56 |
Static definition makes sense, if the menu stays constant and you want to |
|
57 |
assign it once for the lifetime of the view. |
|
58 |
||
59 |
Dynamic menus are easier to use, if the number of or look of the entries has to |
|
60 |
change according the internal state of some model. Also, this is the ST-80 way |
|
3965 | 61 |
of using popupMenus. For dynamic popups, the view's model is asked for a menu |
112 | 62 |
via the #menuSelector each time a button press occurs. |
63 |
||
64 |
See examples section for more. |
|
586 | 65 |
|
66 |
[author:] |
|
67 |
Claus Gittinger |
|
692 | 68 |
|
69 |
[see also:] |
|
70 |
PullDownMenu MenuView |
|
63 | 71 |
" |
72 |
! |
|
38 | 73 |
|
63 | 74 |
examples |
75 |
" |
|
692 | 76 |
The ST-80 way of opening menus is to startUp a menu, |
77 |
and use the returned value: |
|
78 |
[exBegin] |
|
79 |
|p| |
|
284 | 80 |
|
692 | 81 |
p := PopUpMenu |
82 |
labels:#('foo' 'bar' 'baz'). |
|
83 |
Transcript showCR:p startUp |
|
84 |
[exEnd] |
|
85 |
It returns the index of the selected item or 0 if nothing was selected. |
|
86 |
This opening is done by either the controller or the view (if it has |
|
87 |
a middleButtonMenu and/or a menuHolder). |
|
88 |
||
89 |
If the numeric index is inconvenient, alternative values may be specified |
|
90 |
as in (here, nil is returned if nothing was selected): |
|
91 |
[exBegin] |
|
92 |
|p| |
|
93 |
||
94 |
p := PopUpMenu |
|
95 |
labels:#('foo' 'bar' 'baz') |
|
96 |
values:#('hello foo' 'hello bar' 'hello baz'). |
|
97 |
Transcript showCR:p startUp |
|
98 |
[exEnd] |
|
99 |
In ST/X, the above is actually done by a mimicri method (#startUp) |
|
100 |
and menus are typically created in one of the following ways: |
|
101 |
||
102 |
-> With a single actionBlock. |
|
103 |
This is convenient, if all actions shall perform a similar task, |
|
104 |
but require different arguments. |
|
105 |
||
106 |
this is evaluated, passing the selections index or value as argument. |
|
107 |
The action block is NOT evaluated, if nothing was selected. |
|
108 |
With index: |
|
593 | 109 |
[exBegin] |
692 | 110 |
|p| |
111 |
||
112 |
p := PopUpMenu |
|
113 |
labels:#('foo' 'bar' 'baz'). |
|
114 |
p action:[:item | Transcript showCR:item]. |
|
115 |
p showAtPointer |
|
116 |
[exEnd] |
|
117 |
With individual arguments: |
|
118 |
[exBegin] |
|
119 |
|p| |
|
120 |
||
121 |
p := PopUpMenu |
|
122 |
labels:#('foo' 'bar' 'baz') |
|
123 |
args:#('hello foo' 'hello bar' 'hello baz'). |
|
124 |
p action:[:item | Transcript showCR:item]. |
|
125 |
p showAtPointer |
|
126 |
[exEnd] |
|
127 |
||
128 |
-> With an explicit receiver and different selectors. |
|
129 |
This is convenient, if you have to send per-item messages |
|
130 |
to some object (typically, the receiver is the view or a model) |
|
131 |
[exBegin] |
|
132 |
|p m| |
|
133 |
||
134 |
m := Plug new. |
|
135 |
m respondTo:#foo with:[Transcript showCR:'foo received']. |
|
136 |
m respondTo:#bar with:[Transcript showCR:'bar received']. |
|
137 |
m respondTo:#maz with:[Transcript showCR:'maz received']. |
|
138 |
||
139 |
p := PopUpMenu |
|
140 |
labels:#('foo' 'bar' 'baz') |
|
141 |
selectors:#(#foo #bar #baz) |
|
142 |
receiver:m. |
|
143 |
p showAtPointer |
|
593 | 144 |
[exEnd] |
38 | 145 |
|
146 |
||
692 | 147 |
More examples: |
459 | 148 |
dynamic with action instead of selector being sent: |
593 | 149 |
[exBegin] |
459 | 150 |
|p| |
151 |
||
152 |
p := PopUpMenu |
|
153 |
labels:(($a to: $d) collect:[:char | char asString]) |
|
154 |
selectors:nil |
|
155 |
receiver:nil. |
|
655 | 156 |
p action:[:idx | Transcript showCR:'selected index is '; showCR:idx]. |
459 | 157 |
p showAtPointer |
593 | 158 |
[exEnd] |
459 | 159 |
|
160 |
||
545 | 161 |
individual actions: |
593 | 162 |
[exBegin] |
545 | 163 |
|p| |
164 |
p := PopUpMenu |
|
165 |
labels:#('foo' |
|
166 |
'bar' |
|
167 |
'baz') |
|
168 |
selectors:#( |
|
169 |
#foo |
|
170 |
#bar |
|
171 |
#baz). |
|
655 | 172 |
p actionAt:#foo put:[Transcript showCR:'foo']. |
173 |
p actionAt:#bar put:[Transcript showCR:'bar']. |
|
174 |
p actionAt:#baz put:[Transcript showCR:'baz']. |
|
545 | 175 |
p showAtPointer |
593 | 176 |
[exEnd] |
545 | 177 |
|
38 | 178 |
sometimes, you want to specify both selectors and some arguments |
179 |
to be sent; this is done by: |
|
593 | 180 |
[exBegin] |
284 | 181 |
|p| |
182 |
p := PopUpMenu |
|
183 |
labels:#('foo' 'bar' 'baz') |
|
184 |
selectors:#(#foo: #bar: #foo:) |
|
185 |
args:#(1 2 3) |
|
186 |
receiver:nil. |
|
187 |
p showAtPointer |
|
593 | 188 |
[exEnd] |
38 | 189 |
|
190 |
or, the same selector but different arguments: |
|
593 | 191 |
[exBegin] |
284 | 192 |
|p| |
193 |
p := PopUpMenu |
|
194 |
labels:#('foo' 'bar' 'baz') |
|
195 |
selectors:#foo: |
|
196 |
args:#(1 2 3) |
|
197 |
receiver:nil. |
|
198 |
p showAtPointer |
|
593 | 199 |
[exEnd] |
38 | 200 |
|
201 |
Normally, you do not show the menu explicitely, but install |
|
112 | 202 |
it as a either as middleButtonMenu of some view or return it from |
203 |
a model. |
|
204 |
(Views/Controllers button-event handler will show it when the middle |
|
205 |
button is pressed ...) |
|
206 |
Static menu: |
|
593 | 207 |
[exBegin] |
284 | 208 |
|v m| |
38 | 209 |
|
284 | 210 |
v := View new. |
211 |
m := PopUpMenu |
|
212 |
labels:#('lower' |
|
213 |
'raise' |
|
214 |
'-' |
|
215 |
'destroy') |
|
216 |
selectors:#(#lower #raise nil #destroy) |
|
217 |
receiver:v. |
|
218 |
v middleButtonMenu:m. |
|
219 |
v open |
|
593 | 220 |
[exEnd] |
38 | 221 |
|
112 | 222 |
Dynamic menu: |
223 |
(since we need some model which responds to a menu-message, |
|
224 |
we use a plug in the example below; normally, this would be your model) |
|
593 | 225 |
[exBegin] |
284 | 226 |
|v model| |
112 | 227 |
|
284 | 228 |
model := Plug new. |
229 |
model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar') |
|
230 |
selectors:#(foo bar)]. |
|
655 | 231 |
model respondTo:#foo with:[Transcript showCR:'models foo called']. |
232 |
model respondTo:#bar with:[Transcript showCR:'models bar called']. |
|
112 | 233 |
|
284 | 234 |
v := View new. |
235 |
v model:model; menu:#getMenu. |
|
236 |
v open |
|
593 | 237 |
[exEnd] |
112 | 238 |
|
239 |
Dynamic menus are the MVC-way (i.e. ST-80) way of doing things. |
|
240 |
They are usually easier to use, if the menu changes depending on the models |
|
241 |
state. (for example, see the systemBrowsers menus being different when |
|
242 |
things are selected ...) |
|
243 |
||
38 | 244 |
It is also possible, to add check-mark entries, with an entry string |
245 |
starting with the special sequence '\c' (for check-mark). The value |
|
246 |
passed will be the truth-state of the check-mark. |
|
593 | 247 |
[exBegin] |
284 | 248 |
|m v| |
38 | 249 |
|
284 | 250 |
v := View new. |
251 |
m := PopUpMenu |
|
252 |
labels:#('\c foo' |
|
253 |
'\c bar') |
|
254 |
selectors:#(#value: #value:) |
|
655 | 255 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
284 | 256 |
v middleButtonMenu:m. |
257 |
v open |
|
593 | 258 |
[exEnd] |
38 | 259 |
|
404 | 260 |
The style of the checkmark can be: check (\c), box (\b) or thumbs (\t): |
593 | 261 |
[exBegin] |
404 | 262 |
|m v| |
263 |
||
264 |
v := View new. |
|
265 |
m := PopUpMenu |
|
266 |
labels:#('\c foo' |
|
267 |
'\b bar' |
|
268 |
'\t baz') |
|
269 |
selectors:#(#value: #value: #value:) |
|
655 | 270 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
404 | 271 |
v middleButtonMenu:m. |
272 |
v open |
|
593 | 273 |
[exEnd] |
404 | 274 |
|
406 | 275 |
or at the end (looks better with variable fonts): |
593 | 276 |
[exBegin] |
406 | 277 |
|m v| |
278 |
||
279 |
v := View new. |
|
280 |
m := PopUpMenu |
|
281 |
labels:#('foo \c' |
|
282 |
'bar \b' |
|
283 |
'baz \t') |
|
284 |
selectors:#(#value: #value: #value:) |
|
655 | 285 |
receiver:[:v | Transcript show:'arg: '; showCR:v]. |
406 | 286 |
v middleButtonMenu:m. |
287 |
v open |
|
593 | 288 |
[exEnd] |
406 | 289 |
|
38 | 290 |
Finally, you can wrap other views into a popup menu (for example, |
291 |
to implement menus with icons or other components). |
|
292 |
The view should respond to some messages sent from here (for |
|
293 |
example: #hideSubmenus, #deselectWithoutRedraw and others). |
|
294 |
Currently there is only one class in the system, which can be used |
|
295 |
this way (PatternMenu in the DrawTool demo): |
|
593 | 296 |
[exBegin] |
284 | 297 |
|v p| |
38 | 298 |
|
284 | 299 |
v := View new. |
300 |
p := PatternMenu new. |
|
301 |
p patterns:(Array with:Color red |
|
302 |
with:Color green |
|
303 |
with:Color blue). |
|
304 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
305 |
v open |
|
593 | 306 |
[exEnd] |
38 | 307 |
|
308 |
or try: |
|
593 | 309 |
[exBegin] |
284 | 310 |
|v p| |
38 | 311 |
|
284 | 312 |
v := View new. |
313 |
p := PatternMenu new. |
|
314 |
p patterns:(Array with:Color red |
|
315 |
with:Color green |
|
316 |
with:Color blue). |
|
317 |
p selectors:#value:. |
|
318 |
p receiver:[:val | v viewBackground:val. v clear]. |
|
319 |
p args:(Array with:Color red |
|
320 |
with:Color green |
|
321 |
with:Color blue). |
|
322 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
323 |
v open |
|
593 | 324 |
[exEnd] |
38 | 325 |
|
326 |
||
327 |
ST-80 style: |
|
328 |
||
329 |
The above menus all did some message send on selection; it is |
|
330 |
also possible, to use Smalltalk-80 style menus (which return some value |
|
331 |
from their startup method): |
|
593 | 332 |
[exBegin] |
284 | 333 |
|m selection| |
38 | 334 |
|
284 | 335 |
m := PopUpMenu |
336 |
labels:#('one' 'two' 'three'). |
|
337 |
selection := m startUp. |
|
655 | 338 |
Transcript show:'the selection was: '; showCR:selection |
593 | 339 |
[exEnd] |
38 | 340 |
|
341 |
startUp will return the entries index, or 0 if there was no selection. |
|
342 |
You can also specify an array of values to be returned instead of the |
|
343 |
index: |
|
593 | 344 |
[exBegin] |
284 | 345 |
|m selection| |
38 | 346 |
|
284 | 347 |
m := PopUpMenu |
348 |
labels:#('one' 'two' 'three') |
|
349 |
values:#(10 20 30). |
|
350 |
selection := m startUp. |
|
655 | 351 |
Transcript show:'the value was: '; showCR:selection |
593 | 352 |
[exEnd] |
38 | 353 |
|
354 |
In ST/X style menus, separating lines between entries are created |
|
355 |
by a '-'-string as its label text (and corresponding nil-entries in the |
|
356 |
selectors- and args-arrays). |
|
357 |
In ST-80, you have to pass the indices of the lines in an extra array: |
|
593 | 358 |
[exBegin] |
284 | 359 |
|m selection| |
38 | 360 |
|
284 | 361 |
m := PopUpMenu |
362 |
labels:#('one' 'two' 'three' 'four' 'five') |
|
363 |
lines:#(2 4). |
|
364 |
selection := m startUp. |
|
655 | 365 |
Transcript show:'the value was: '; showCR:selection |
593 | 366 |
[exEnd] |
38 | 367 |
|
368 |
or: |
|
593 | 369 |
[exBegin] |
284 | 370 |
|m selection| |
38 | 371 |
|
284 | 372 |
m := PopUpMenu |
373 |
labels:#('one' 'two' 'three') |
|
374 |
lines:#(2) |
|
375 |
values:#(10 20 30). |
|
376 |
selection := m startUp. |
|
655 | 377 |
Transcript show:'the value was: '; showCR:selection |
593 | 378 |
[exEnd] |
38 | 379 |
|
380 |
Use whichever interface you prefer. |
|
381 |
" |
|
119 | 382 |
! ! |
383 |
||
384 |
!PopUpMenu class methodsFor:'instance creation'! |
|
38 | 385 |
|
386 |
forMenu:aMenuView |
|
387 |
"this wraps an already existing menu - allowing to put any |
|
388 |
view (not just MenuViews) into popups (for example, menus |
|
389 |
with icons, or other components). |
|
390 |
Currently, there is only one example of different menus in |
|
391 |
the system (PatternMenu in the DrawTool) which could be used |
|
392 |
this way. |
|
393 |
The view should respond to some of the menuView messages |
|
394 |
(such as hideSubmenu, deselectWithoutRedraw etc.)" |
|
395 |
||
396 |
|newMenu| |
|
397 |
||
2402 | 398 |
aMenuView isView ifFalse:[ |
399 |
self error:'bad argument' |
|
400 |
]. |
|
38 | 401 |
newMenu := self onSameDeviceAs:aMenuView. |
402 |
newMenu addSubView:aMenuView. |
|
1056 | 403 |
newMenu menuView:aMenuView. |
38 | 404 |
^ newMenu |
405 |
! |
|
406 |
||
1505
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
407 |
itemList:itemList resources:resources |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
408 |
"like labels:selectors:... messages, but expects a single collection, |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
409 |
containing items row-wise (i.e. elements are themself arrays, consisting of |
1606 | 410 |
label [selector [accelerator [arg]]] |
1505
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
411 |
if resources are non-nil, labels are translated using the translations found there. |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
412 |
" |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
413 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
414 |
^ self |
1506 | 415 |
itemList:itemList resources:resources receiver:nil for:nil |
1505
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
416 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
417 |
"the sometimes more convenient: |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
418 |
|p| |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
419 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
420 |
p := PopUpMenu |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
421 |
itemList:#(('foo' doFoo CtrlF) |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
422 |
('-') |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
423 |
('bar' doBar CtrlB) |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
424 |
('baz' doBaz CtrlZ)) |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
425 |
resources:nil. |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
426 |
p showAtPointer |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
427 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
428 |
does the same as: |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
429 |
|p| |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
430 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
431 |
p := PopUpMenu |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
432 |
labels:#('foo' '-' 'bar' 'baz') |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
433 |
selectors:#(doFoo nil doBar doBaz) |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
434 |
accelerators:#(CtrlF nil CtrlB CtrlZ). |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
435 |
p showAtPointer |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
436 |
" |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
437 |
|
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
438 |
! |
66e010d679a9
added #itemList: instance creation.
Claus Gittinger <cg@exept.de>
parents:
1442
diff
changeset
|
439 |
|
1543 | 440 |
itemList:itemList resources:resources performer:menuPerformer |
441 |
"like labels:selectors:... messages, but expects a single collection, |
|
442 |
containing items row-wise (i.e. elements are themself arrays, consisting of |
|
1606 | 443 |
label [selector [accelerator [arg]]] |
1543 | 444 |
if resources are non-nil, labels are translated using the translations found there. |
445 |
" |
|
446 |
||
447 |
^ self |
|
448 |
itemList:itemList resources:resources receiver:menuPerformer for:nil |
|
449 |
||
450 |
"Created: / 21.5.1998 / 15:31:42 / cg" |
|
451 |
! |
|
452 |
||
453 |
itemList:itemList resources:resources performer:menuPerformer for:aView |
|
1506 | 454 |
"like labels:selectors:... messages, but expects a single collection, |
455 |
containing items row-wise (i.e. elements are themself arrays, consisting of |
|
456 |
label [selector [accelerator [arg]]] |
|
457 |
if resources are non-nil, labels are translated using the translations found there. |
|
458 |
" |
|
459 |
||
460 |
|n labels selectors accelerators args anyArg| |
|
461 |
||
462 |
n := itemList size. |
|
463 |
labels := Array new:n. |
|
464 |
selectors := Array new:n. |
|
465 |
accelerators := Array new:n. |
|
466 |
anyArg := false. |
|
467 |
||
468 |
itemList keysAndValuesDo:[:idx :item | |
|
469 |
|label selector accelerator arg| |
|
470 |
||
471 |
label := item at:1. |
|
472 |
labels at:idx put:label. |
|
473 |
item size > 1 ifTrue:[ |
|
474 |
selector := item at:2. |
|
475 |
selectors at:idx put:selector. |
|
476 |
item size > 2 ifTrue:[ |
|
477 |
accelerator := item at:3. |
|
478 |
accelerators at:idx put:accelerator. |
|
479 |
item size > 3 ifTrue:[ |
|
480 |
arg := item at:4. |
|
481 |
anyArg ifFalse:[ |
|
482 |
anyArg := true. |
|
483 |
args := Array new:n. |
|
484 |
]. |
|
485 |
args at:idx put:arg. |
|
486 |
] |
|
487 |
] |
|
488 |
]. |
|
489 |
]. |
|
490 |
||
491 |
resources notNil ifTrue:[ |
|
492 |
labels := resources array:labels |
|
493 |
]. |
|
494 |
||
495 |
^ self |
|
496 |
labels:labels |
|
497 |
selectors:selectors |
|
498 |
accelerators:accelerators |
|
499 |
args:args |
|
1543 | 500 |
receiver:menuPerformer |
1506 | 501 |
for:aView |
502 |
||
503 |
"this is sometimes more convenient: |
|
504 |
|p| |
|
505 |
||
506 |
p := PopUpMenu |
|
507 |
itemList:#(('foo' doFoo CtrlF) |
|
508 |
('-') |
|
509 |
('bar' doBar CtrlB) |
|
510 |
('baz' doBaz CtrlZ)) |
|
511 |
resources:nil. |
|
512 |
p showAtPointer |
|
513 |
||
514 |
and does the same as: |
|
515 |
|p| |
|
516 |
||
517 |
p := PopUpMenu |
|
518 |
labels:#('foo' '-' 'bar' 'baz') |
|
519 |
selectors:#(doFoo nil doBar doBaz) |
|
520 |
accelerators:#(CtrlF nil CtrlB CtrlZ). |
|
521 |
p showAtPointer |
|
522 |
" |
|
523 |
||
1543 | 524 |
"Created: / 21.5.1998 / 15:32:39 / cg" |
525 |
! |
|
526 |
||
527 |
itemList:itemList resources:resources receiver:menuPerformer for:aView |
|
528 |
"like labels:selectors:... messages, but expects a single collection, |
|
529 |
containing items row-wise (i.e. elements are themself arrays, consisting of |
|
530 |
label [selector [accelerator [arg]]] |
|
531 |
if resources are non-nil, labels are translated using the translations found there. |
|
532 |
" |
|
533 |
||
534 |
^ self |
|
535 |
itemList:itemList resources:resources performer:menuPerformer for:aView |
|
536 |
||
537 |
"Modified: / 21.5.1998 / 15:33:04 / cg" |
|
1506 | 538 |
! |
539 |
||
692 | 540 |
labels:labels args:args |
541 |
"create and return a menu with label-items and args. |
|
542 |
The actionBlock has to be defined later" |
|
543 |
||
544 |
^ self labels:labels selectors:nil accelerators:nil args:args receiver:nil for:nil |
|
545 |
||
546 |
" |
|
547 |
|m| |
|
548 |
||
549 |
m := PopUpMenu labels:#('foo' 'bar') |
|
550 |
args:#('hello world' 'how about this'). |
|
551 |
m action:[:arg | |
|
552 |
Transcript showCR:arg |
|
553 |
]. |
|
554 |
||
555 |
m showAtPointer |
|
556 |
" |
|
557 |
||
558 |
"Modified: 25.5.1996 / 17:01:43 / cg" |
|
559 |
! |
|
560 |
||
202 | 561 |
labels:labels selector:aSelector args:args receiver:anObject |
562 |
"create and return a popup menu with labels as entries. |
|
563 |
Each item will send aSelector with a corresponding argument from the |
|
564 |
args array to anObject. The menu is created on the default DIsplay" |
|
565 |
||
566 |
" |
|
567 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
568 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
569 |
^ 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
|
570 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
571 |
"Modified: 28.2.1996 / 19:01:12 / cg" |
202 | 572 |
! |
573 |
||
574 |
labels:labels selector:aSelector args:args receiver:anObject for:aView |
|
575 |
"create and return a popup menu with labels as entries. |
|
576 |
Each item will send aSelector with a corresponding argument from the |
|
577 |
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
|
578 |
as aView (which is only of interest in multi-Display applications; |
202 | 579 |
typical applications can use the sibbling message without the for: argument)." |
580 |
||
581 |
" |
|
582 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
583 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
584 |
^ 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
|
585 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
586 |
"Modified: 28.2.1996 / 19:01:29 / cg" |
202 | 587 |
! |
588 |
||
589 |
labels:labels selectors:selectors |
|
590 |
"create and return a menu with label-items and selectors. The receiver |
|
591 |
will either be defined later, or not used at all (if opened via startUp)" |
|
592 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
593 |
^ 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
|
594 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
595 |
"Modified: 28.2.1996 / 19:01:35 / cg" |
202 | 596 |
! |
597 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
598 |
labels:labels selectors:selectors accelerators:shorties |
202 | 599 |
"create and return a menu with label-items and selectors. The receiver |
600 |
will either be defined later, or not used at all (if opened via startUp)" |
|
601 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
602 |
^ 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
|
603 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
604 |
"Created: 28.2.1996 / 18:58:52 / cg" |
202 | 605 |
! |
606 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
607 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject |
202 | 608 |
"create and return a popup menu with labels as entries. |
609 |
Each item will send a corresponding selector:argument from the selectors- |
|
610 |
and args array to anObject. The menu is created on the default Display" |
|
611 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
612 |
^ 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
|
613 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
614 |
"Created: 28.2.1996 / 18:59:03 / cg" |
202 | 615 |
! |
616 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
617 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject for:aView |
63 | 618 |
"create and return a popup menu with labels as entries. |
619 |
Each item will send a corresponding selector:argument from the selectors- |
|
620 |
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
|
621 |
as aView (which is only of interest in multi-Display applications; |
63 | 622 |
typical applications can use the sibbling message without the for: argument)." |
623 |
||
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
624 |
|newMenu m| |
38 | 625 |
|
626 |
newMenu := self onSameDeviceAs:aView. |
|
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
627 |
m := (MenuView |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
628 |
labels:labels |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
629 |
selectors:selectors |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
630 |
accelerators:shorties |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
631 |
args:args |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
632 |
receiver:anObject |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
633 |
in:newMenu). |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
634 |
|
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
635 |
m level:0; borderWidth:0. |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
636 |
newMenu menuView:m. |
38 | 637 |
^ newMenu |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
638 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
639 |
"Created: 28.2.1996 / 18:59:25 / cg" |
1056 | 640 |
"Modified: 25.2.1997 / 20:52:47 / cg" |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
641 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
642 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
643 |
labels:labels selectors:selectors accelerators:shorties receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
644 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
645 |
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
|
646 |
selectors-array. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
647 |
The menu is created on the default Display." |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
648 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
649 |
^ 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
|
650 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
651 |
"Created: 28.2.1996 / 19:00:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
652 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
653 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
654 |
labels:labels selectors:selectors args:argArray |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
655 |
"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
|
656 |
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
|
657 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
658 |
^ 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
|
659 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
660 |
"Modified: 28.2.1996 / 19:01:45 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
661 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
662 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
663 |
labels:labels selectors:selectors args:args receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
664 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
665 |
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
|
666 |
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
|
667 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
668 |
^ 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
|
669 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
670 |
"Modified: 28.2.1996 / 19:01:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
671 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
672 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
673 |
labels:labels selectors:selectors args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
674 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
675 |
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
|
676 |
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
|
677 |
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
|
678 |
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
|
679 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
680 |
^ 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
|
681 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
682 |
"Modified: 28.2.1996 / 19:03:58 / cg" |
38 | 683 |
! |
684 |
||
119 | 685 |
labels:labels selectors:selectors receiver:anObject |
686 |
"create and return a popup menu with labels as entries. |
|
687 |
Each item will send a message with a selector from the corresponding |
|
688 |
selectors-array. |
|
689 |
The menu is created on the default Display." |
|
690 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
691 |
^ 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
|
692 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
693 |
"Modified: 28.2.1996 / 19:02:07 / cg" |
63 | 694 |
! |
695 |
||
202 | 696 |
labels:labels selectors:selectors receiver:anObject for:aView |
697 |
"create and return a popup menu with labels as entries. |
|
698 |
Each item will send a corresponding selector from the selectors-array |
|
699 |
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
|
700 |
as aView (which is only of interest in multi-Display applications; |
202 | 701 |
typical applications can use the sibbling message without the for: argument)." |
63 | 702 |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
703 |
^ 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
|
704 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
705 |
"Modified: 28.2.1996 / 19:02:10 / cg" |
0 | 706 |
! ! |
707 |
||
708 |
!PopUpMenu class methodsFor:'ST-80 instance creation'! |
|
709 |
||
4544 | 710 |
labelArray:labels |
711 |
"ST80R4 compatibility" |
|
712 |
||
713 |
^ self labels:labels lines:nil values:nil |
|
714 |
||
715 |
" |
|
716 |
(PopUpMenu labelArray:#('one' 'two' 'three')) startUp |
|
717 |
" |
|
718 |
! |
|
719 |
||
202 | 720 |
labelArray:labels lines:lines values:values |
721 |
"ST80R4 compatibility" |
|
119 | 722 |
|
202 | 723 |
^ self labels:labels lines:lines values:values |
0 | 724 |
! |
725 |
||
119 | 726 |
labelArray:labels values:values |
727 |
"ST80R4 compatibility" |
|
728 |
||
729 |
^ self labels:labels lines:nil values:values |
|
730 |
! |
|
731 |
||
202 | 732 |
labelList:labels |
733 |
"ST80R4 compatibility: |
|
734 |
given a list consisting of group label entries (to be separated by |
|
735 |
lines), convert into standard form (using '-' for lines. |
|
736 |
" |
|
737 |
||
738 |
^ self labelList:labels values:nil |
|
119 | 739 |
|
202 | 740 |
" |
741 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer |
|
742 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer |
|
743 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer |
|
744 |
" |
|
745 |
! |
|
746 |
||
747 |
labelList:labels lines:lines values:values |
|
748 |
"mhmh what is that ?" |
|
749 |
||
750 |
^ (self new) labels:labels lines:lines values:values |
|
119 | 751 |
! |
752 |
||
0 | 753 |
labelList:labels values:values |
119 | 754 |
"ST80R4 compatibility: |
755 |
given a list consisting of group label entries (to be separated by |
|
756 |
lines), convert into standard form (using '-' for lines. |
|
757 |
" |
|
758 |
||
759 |
|newLabels newValues lS vS first| |
|
760 |
||
761 |
newLabels := OrderedCollection new. |
|
762 |
newValues := OrderedCollection new. |
|
763 |
lS := ReadStream on:labels. |
|
764 |
values notNil ifTrue:[vS := ReadStream on:values]. |
|
765 |
first := true. |
|
766 |
[lS atEnd] whileFalse:[ |
|
767 |
|entry| |
|
768 |
||
769 |
entry := lS next. |
|
770 |
entry isCollection ifTrue:[ |
|
771 |
first ifFalse:[ |
|
772 |
newLabels add:'-'. |
|
773 |
values notNil ifTrue:[newValues add:nil] |
|
774 |
]. |
|
775 |
newLabels addAll:entry. |
|
776 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)] |
|
777 |
] ifFalse:[ |
|
778 |
newLabels add:entry. |
|
779 |
values notNil ifTrue:[newValues add:(vS next)] |
|
780 |
]. |
|
781 |
first := false. |
|
782 |
]. |
|
783 |
values isNil ifTrue:[ |
|
784 |
^ self labels:newLabels |
|
785 |
]. |
|
786 |
^ self labels:newLabels values:newValues |
|
787 |
||
788 |
" |
|
789 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer |
|
790 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer |
|
791 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer |
|
792 |
" |
|
793 |
! |
|
794 |
||
202 | 795 |
labels:labels |
796 |
"ST80R2 compatibility" |
|
59 | 797 |
|
202 | 798 |
^ self labels:labels lines:nil values:nil |
0 | 799 |
! |
800 |
||
202 | 801 |
labels:labels lines:lines |
802 |
"ST80R2 compatibility" |
|
0 | 803 |
|
202 | 804 |
^ self labels:labels lines:lines values:nil |
77 | 805 |
! |
806 |
||
202 | 807 |
labels:labels lines:lines values:values |
808 |
"ST80R2 compatibility" |
|
127 | 809 |
|
202 | 810 |
^ (self new) labels:labels lines:lines values:values |
77 | 811 |
! |
812 |
||
202 | 813 |
labels:labels values:values |
814 |
"ST80R2 compatibility" |
|
59 | 815 |
|
202 | 816 |
^ self labels:labels lines:nil values:values |
127 | 817 |
! ! |
818 |
||
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
819 |
!PopUpMenu class methodsFor:'defaults'! |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
820 |
|
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
821 |
maxClickTimeToStayOpen |
2946 | 822 |
^ 200 "/ if button is pressed shorter, its a click and the menu stays open. |
823 |
"/ otherwise, its a press and the menu hides itself with the release |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
824 |
! ! |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
825 |
|
0 | 826 |
!PopUpMenu methodsFor:'ST-80 activation'! |
827 |
||
828 |
startUp |
|
38 | 829 |
"start the menu modal - return the selected value, |
830 |
or - if no values where specified - return the index. |
|
0 | 831 |
If nothing was selected, return 0. |
38 | 832 |
Modal - i.e. stay in the menu until finished. |
833 |
This is the ST-80 way of launching a menu." |
|
0 | 834 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
835 |
^ self startUpAt:nil |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
836 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
837 |
" |
655 | 838 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
839 |
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
|
840 |
values:#(foo bar baz)) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
841 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
842 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
843 |
"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
|
844 |
! |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
845 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
846 |
startUpAt:aPoint |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
847 |
"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
|
848 |
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
|
849 |
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
|
850 |
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
|
851 |
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
|
852 |
|
2173 | 853 |
^ self startUpAt:aPoint ifNoneSelected:0 |
854 |
||
855 |
" |
|
856 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
|
857 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz') |
|
858 |
values:#(foo bar baz)) startUp |
|
859 |
" |
|
860 |
||
861 |
! |
|
862 |
||
863 |
startUpAt:aPoint ifNoneSelected:defaultReturnValue |
|
864 |
"start the menu modal - return the selected value, |
|
865 |
or - if no values where specified - return the index. |
|
866 |
If nothing was selected, return defaultReturnValue. |
|
867 |
Modal - i.e. stay in the menu until finished. |
|
868 |
This is the ST-80 way of launching a menu." |
|
869 |
||
1354 | 870 |
|return rec sel0 sel1 arg myAction| |
63 | 871 |
|
2173 | 872 |
return := defaultReturnValue. |
2041
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
873 |
actionValues notNil ifTrue:[ |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
874 |
return := nil |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
875 |
]. |
1175
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
876 |
"/ menuView args notNil ifTrue:[ |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
877 |
"/ return := nil |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
878 |
"/ ]. |
119 | 879 |
|
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
880 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
881 |
"/ 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
|
882 |
"/ 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
|
883 |
"/ (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
|
884 |
"/ 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
|
885 |
"/ 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
|
886 |
"/ 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
|
887 |
"/ |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
888 |
|
692 | 889 |
menuView action isNil ifTrue:[ |
1354 | 890 |
myAction := true. |
692 | 891 |
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
|
892 |
|actionIndex value sel retVal selIdx |
692 | 893 |
args selectors checkFlags check| |
119 | 894 |
|
2067
99763d5655ce
must clear the actionBlock when invoked.
Claus Gittinger <cg@exept.de>
parents:
2041
diff
changeset
|
895 |
menuView action:nil. "/ must clear it ... |
2041
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
896 |
retVal := 0. |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
897 |
actionValues notNil ifTrue:[ |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
898 |
retVal := nil |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
899 |
]. |
8107fe7c8cff
if item-values were defined,
Claus Gittinger <cg@exept.de>
parents:
2038
diff
changeset
|
900 |
|
878 | 901 |
selected isNil ifTrue:[ |
902 |
"/ the menu has already sent a message or performed an item-action; do nothing here |
|
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
903 |
retVal |
692 | 904 |
] ifFalse:[ |
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
905 |
selIdx := menuView selection. |
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
906 |
|
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
907 |
args := menuView args. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
908 |
selectors := menuView selectors. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
909 |
checkFlags := menuView checkFlags. |
568
ba7d2bc390ae
oops - checkFlags passed wrong arg
Claus Gittinger <cg@exept.de>
parents:
545
diff
changeset
|
910 |
|
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
911 |
args isNil ifTrue:[ |
692 | 912 |
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
|
913 |
sel0 := selectors at:selIdx. |
692 | 914 |
]. |
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
915 |
] ifFalse:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
916 |
actionIndex := selected. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
917 |
actionIndex notNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
918 |
actionValues isNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
919 |
selectors notNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
920 |
"/ mhmh an ST/X menu started the ST-80 way |
692 | 921 |
|
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
922 |
sel1 := selectors at:selIdx. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
923 |
arg := actionIndex. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
924 |
] ifFalse:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
925 |
retVal := actionIndex |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
926 |
] |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
927 |
] ifFalse:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
928 |
retVal := actionValues at:actionIndex. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
929 |
(retVal isKindOf:PopUpMenu) ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
930 |
retVal := retVal startUp |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
931 |
] |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
932 |
] |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
933 |
] ifFalse:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
934 |
"/ mhmh an ST/X menu started the ST-80 way |
692 | 935 |
|
3594
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
936 |
selectors notNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
937 |
sel0 := selectors at:selIdx. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
938 |
]. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
939 |
] |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
940 |
]. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
941 |
|
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
942 |
checkFlags notNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
943 |
check := checkFlags at:selIdx. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
944 |
check notNil ifTrue:[ |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
945 |
arg := check. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
946 |
sel1 := sel0. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
947 |
sel0 := nil. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
948 |
] |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
949 |
]. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
950 |
return := retVal. |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
951 |
|
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
952 |
menuView action:nil |
e298287e2968
do not return twice from a block
Claus Gittinger <cg@exept.de>
parents:
3493
diff
changeset
|
953 |
] |
692 | 954 |
] |
0 | 955 |
]. |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
956 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
957 |
aPoint isNil ifTrue:[ |
4905 | 958 |
self showAt:(self graphicsDevice pointerPosition) resizing:true |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
959 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
960 |
self showAt:aPoint. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
961 |
]. |
1354 | 962 |
myAction == true ifTrue:[menuView action:nil]. |
96 | 963 |
|
964 |
"/ |
|
965 |
"/ mhmh an ST/X menu started the ST-80 way |
|
966 |
"/ |
|
967 |
(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
|
968 |
rec := menuView receiver. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
969 |
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
|
970 |
^ sel0 |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
971 |
]. |
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
972 |
^ Array with:sel1 with:arg. |
95 | 973 |
]. |
63 | 974 |
^ return |
38 | 975 |
|
976 |
" |
|
655 | 977 |
Transcript showCR:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
978 |
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
|
979 |
values:#(foo bar baz)) startUp |
38 | 980 |
" |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
981 |
|
1539 | 982 |
"Created: / 10.1.1996 / 20:11:42 / cg" |
983 |
"Modified: / 20.5.1998 / 22:39:03 / cg" |
|
110 | 984 |
! |
985 |
||
2645 | 986 |
startUpFor:originatingWidget |
987 |
^ self startUp |
|
988 |
! |
|
989 |
||
2173 | 990 |
startUpOrNil |
991 |
"start the menu modal - return the selected value, |
|
992 |
or - if no values where specified - return the index. |
|
993 |
If nothing was selected, return nil. |
|
994 |
Modal - i.e. stay in the menu until finished. |
|
995 |
This is the ST-80 way of launching a menu." |
|
996 |
||
997 |
^ self startUpAt:nil ifNoneSelected:nil |
|
998 |
||
999 |
! |
|
1000 |
||
110 | 1001 |
startUpWithHeading:aString |
1002 |
"start the menu modal - return the selected value, |
|
1003 |
or - if no values where specified - return the index. |
|
1004 |
If nothing was selected, return 0. |
|
1005 |
Modal - i.e. stay in the menu until finished. |
|
1006 |
This is the ST-80 way of launching a menu." |
|
1007 |
||
3965 | 1008 |
|vector| |
1009 |
||
110 | 1010 |
defaultHideOnRelease := false. |
3965 | 1011 |
(vector := menuView labels) notNil ifTrue:[ |
4686 | 1012 |
menuView labels:(Array with:aString with:'=') , vector. |
3965 | 1013 |
]. |
1014 |
(vector := menuView selectors) notNil ifTrue:[ |
|
1015 |
menuView selectors:#(nil nil) , vector. |
|
110 | 1016 |
]. |
3965 | 1017 |
(vector := menuView args) notNil ifTrue:[ |
1018 |
menuView args:#(nil nil) , vector. |
|
110 | 1019 |
]. |
3965 | 1020 |
(vector := menuView checkFlags) notNil ifTrue:[ |
1021 |
menuView checkFlags:#(nil nil) , vector. |
|
1022 |
]. |
|
1023 |
(vector := menuView actions) notNil ifTrue:[ |
|
1024 |
menuView actions:#(nil nil) , vector. |
|
1025 |
]. |
|
1026 |
menuView disable:1; disable:2. |
|
110 | 1027 |
|
1028 |
^ self startUp. |
|
1029 |
||
1030 |
" |
|
1031 |
(PopUpMenu |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1032 |
labels:#('foo' 'bar')) |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1033 |
startUp |
110 | 1034 |
" |
1035 |
" |
|
1036 |
(PopUpMenu |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1037 |
labels:#('foo' 'bar')) |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1038 |
startUpWithHeading:'hello' |
110 | 1039 |
" |
0 | 1040 |
! ! |
1041 |
||
202 | 1042 |
!PopUpMenu methodsFor:'accessing-behavior'! |
1043 |
||
3365 | 1044 |
hideOnKeyFilter:aBlock |
1045 |
"set a filter, which determines if a key should lead to closing the menu." |
|
1046 |
||
1047 |
hideOnKeyFilter := aBlock |
|
1048 |
! |
|
1049 |
||
202 | 1050 |
hideOnLeave:aBoolean |
1051 |
"set/clear the hideOnLeave attribute, which controls |
|
1052 |
if the menu should be hidden when the pointer leaves |
|
1053 |
the view (used with multiple-menus)" |
|
1054 |
||
1055 |
hideOnLeave := aBoolean |
|
1056 |
! |
|
1057 |
||
1058 |
hideOnRelease:aBoolean |
|
1059 |
"set/clear the hideOnRelease attribute, which controls |
|
1060 |
if the menu should be hidden when the button is released" |
|
1061 |
||
335
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
1062 |
defaultHideOnRelease := aBoolean. |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
1063 |
menuView hideOnRelease:aBoolean |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
1064 |
|
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
1065 |
"Modified: 9.2.1996 / 02:06:15 / cg" |
2433 | 1066 |
! |
1067 |
||
1068 |
isEnabled:indexOrName |
|
1069 |
"return true, if the item at anIndexOrName is enabled" |
|
1070 |
||
1071 |
^ menuView isEnabled:indexOrName |
|
4686 | 1072 |
! |
1073 |
||
1074 |
memorizeLastSelection:index |
|
1075 |
"normally, a popup menu comes up unselected, even if reused. |
|
1076 |
This can be used to arrange for an initial selection to be shown" |
|
1077 |
||
1078 |
lastSelection := index. |
|
1079 |
memorize := true. |
|
202 | 1080 |
! ! |
1081 |
||
1082 |
!PopUpMenu methodsFor:'accessing-items'! |
|
1083 |
||
3235 | 1084 |
addItem:anItem |
1085 |
menuView addItem:anItem |
|
1086 |
! |
|
1087 |
||
4272
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1088 |
atMenuItemLabeled:aString putSubmenu:aMenu visible:visible |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1089 |
|idx| |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1090 |
|
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1091 |
idx := self indexOf:aString. |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1092 |
idx notNil ifTrue:[ |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1093 |
visible ifTrue:[ |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1094 |
self subMenuAt:aString put:(aMenu asOldStylePopUpMenuFor:self application). |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1095 |
]. |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1096 |
]. |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1097 |
|
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1098 |
"Created: / 30-06-2011 / 10:28:57 / cg" |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1099 |
! |
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1100 |
|
4614 | 1101 |
hasItems |
1102 |
"return true, if I have items" |
|
1103 |
||
1104 |
^ menuView notNil and:[ menuView hasItems ] |
|
1105 |
! |
|
1106 |
||
202 | 1107 |
indexOf:indexOrName |
1108 |
"return the index of a submenu - or 0 if there is none" |
|
1109 |
||
1110 |
^ menuView indexOf:indexOrName |
|
1111 |
! |
|
1112 |
||
1113 |
labels |
|
1114 |
"return the list of labels" |
|
1115 |
||
1116 |
actionLabels notNil ifTrue:[ |
|
1117 |
^ actionLabels asStringCollection |
|
1118 |
]. |
|
1119 |
^ menuView list |
|
1120 |
! |
|
1121 |
||
3965 | 1122 |
labels:labelString lines:lineArrayArg values:valueArray |
202 | 1123 |
"define the menu the ST-80 way (with labels and lines defined separately)" |
1124 |
||
3965 | 1125 |
|lineArray labelArray argArray convertedLabels |
1175
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1126 |
offs dstOffs linePos m| |
202 | 1127 |
|
3965 | 1128 |
lineArray := lineArrayArg. |
3973
6989efdd26ff
changed: #labels:lines:values:
Claus Gittinger <cg@exept.de>
parents:
3972
diff
changeset
|
1129 |
(lineArray notNil and:[lineArray first]) == 0 ifTrue:[ |
3965 | 1130 |
lineArray := lineArray copyFrom:2. |
1131 |
]. |
|
1132 |
||
202 | 1133 |
actionLabels := labelString. |
1134 |
actionLines := lineArray. |
|
1135 |
actionValues := valueArray. |
|
1136 |
||
1137 |
labelArray := labelString asStringCollection. |
|
1138 |
||
1139 |
convertedLabels := Array new:(labelArray size + lineArray size). |
|
1140 |
argArray := Array new:(labelArray size + lineArray size). |
|
1141 |
||
1142 |
offs := 1. |
|
1143 |
dstOffs := 1. |
|
1144 |
1 to:lineArray size do:[:lineIndex | |
|
1056 | 1145 |
linePos := lineArray at:lineIndex. |
1146 |
[offs <= linePos] whileTrue:[ |
|
1147 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
1148 |
argArray at:dstOffs put:offs. |
|
1149 |
offs := offs + 1. |
|
1150 |
dstOffs := dstOffs + 1 |
|
1151 |
]. |
|
1152 |
convertedLabels at:dstOffs put:'-'. |
|
1153 |
argArray at:dstOffs put:nil. |
|
1154 |
dstOffs := dstOffs + 1 |
|
202 | 1155 |
]. |
1156 |
[offs <= labelArray size] whileTrue:[ |
|
1056 | 1157 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
1158 |
argArray at:dstOffs put:offs. |
|
1159 |
offs := offs + 1. |
|
1160 |
dstOffs := dstOffs + 1 |
|
202 | 1161 |
]. |
1056 | 1162 |
|
1175
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1163 |
m := MenuView |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1164 |
labels:convertedLabels |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1165 |
selectors:nil |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1166 |
args:argArray |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1167 |
receiver:nil |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1168 |
in:self. |
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1169 |
m level:0; borderWidth:0. |
1175
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1170 |
self menuView:m |
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1171 |
|
9c8aec66cc17
startUp must return 0 if nothing was selected
Claus Gittinger <cg@exept.de>
parents:
1150
diff
changeset
|
1172 |
"Modified: 2.4.1997 / 15:57:52 / cg" |
202 | 1173 |
! |
1174 |
||
1175 |
lines |
|
1176 |
"st-80 compatibility" |
|
1177 |
||
1178 |
^ actionLines |
|
1179 |
! |
|
1180 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1181 |
menuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1182 |
"return the submenu for entry indexOrName." |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1183 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1184 |
^ self subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1185 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1186 |
"Created: 24.3.1996 / 17:11:05 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1187 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1188 |
|
202 | 1189 |
numberOfItems |
1190 |
"return the number of items in the menu" |
|
1191 |
||
1192 |
actionLabels notNil ifTrue:[ |
|
1193 |
^ actionLabels asStringCollection size |
|
1194 |
]. |
|
1195 |
^ menuView list size |
|
1196 |
! |
|
1197 |
||
1198 |
remove:indexOrName |
|
1199 |
"remove a menu entry" |
|
1200 |
||
1201 |
menuView remove:indexOrName |
|
1202 |
! |
|
1203 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1204 |
subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1205 |
"return the submenu for entry indexOrName" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1206 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1207 |
^ menuView subMenuAt:indexOrName |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1208 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1209 |
"Created: 24.3.1996 / 17:09:15 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1210 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
497
diff
changeset
|
1211 |
|
202 | 1212 |
subMenuAt:indexOrName put:aMenu |
1213 |
"define a submenu to be shown for entry indexOrName" |
|
1214 |
||
1215 |
" |
|
1216 |
aMenu hideOnLeave:true. |
|
1217 |
" |
|
1218 |
menuView subMenuAt:indexOrName put:aMenu. |
|
5049 | 1219 |
(aMenu notNil and:[aMenu isBlock not] |
1220 |
) ifTrue:[ |
|
2399
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1221 |
"tell the submenu to notify me when action is performed" |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1222 |
aMenu superMenu:self. |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1223 |
]. |
202 | 1224 |
|
1225 |
" |
|
1226 |
|v m someObject| |
|
1227 |
||
1228 |
v := View new. |
|
1229 |
m := PopUpMenu labels:#('1' '2' '3') |
|
2399
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1230 |
selectors:#(one two nil) |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1231 |
receiver:someObject |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1232 |
for:nil. |
202 | 1233 |
m subMenuAt:3 put:(PopUpMenu |
2399
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1234 |
labels:#('a' 'b' 'c') |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1235 |
selectors:#(a b c) |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1236 |
receiver:someObject |
550e5ab64b82
care for nil arg in #subMenuAt:put:
Claus Gittinger <cg@exept.de>
parents:
2367
diff
changeset
|
1237 |
for:nil). |
202 | 1238 |
v middleButtonMenu:m. |
1239 |
v realize |
|
1240 |
" |
|
1241 |
! |
|
1242 |
||
1243 |
values |
|
1244 |
"st-80 compatibility" |
|
1245 |
||
1246 |
^ actionValues |
|
1247 |
! |
|
1248 |
||
1249 |
values:aValueArray |
|
1250 |
"st-80 compatibility" |
|
1251 |
||
1252 |
actionValues := aValueArray |
|
1253 |
! ! |
|
1254 |
||
1255 |
!PopUpMenu methodsFor:'accessing-look'! |
|
1256 |
||
1257 |
font:aFont |
|
665 | 1258 |
"set the menus font. |
1259 |
CAVEAT: with the addition of Text objects, |
|
1260 |
this method is going to be obsoleted by a textStyle |
|
1261 |
method, which allows specific control over |
|
1262 |
normalFont/boldFont/italicFont parameters." |
|
1263 |
||
1233 | 1264 |
preferredExtent := nil. |
202 | 1265 |
menuView font:aFont |
665 | 1266 |
|
1267 |
"Modified: 22.5.1996 / 12:36:53 / cg" |
|
202 | 1268 |
! |
1269 |
||
1270 |
viewBackground:aColor |
|
1271 |
"this is a kludge and will vanish ..." |
|
1272 |
||
1273 |
super viewBackground:aColor. |
|
1274 |
menuView viewBackground:aColor |
|
1275 |
! ! |
|
1276 |
||
1277 |
!PopUpMenu methodsFor:'accessing-mvc'! |
|
1278 |
||
1279 |
changeMessage |
|
754 | 1280 |
"set the changeMessage from my menu" |
202 | 1281 |
|
1282 |
^ menuView changeMessage |
|
754 | 1283 |
|
1284 |
"Modified: 5.6.1996 / 17:08:52 / cg" |
|
202 | 1285 |
! |
1286 |
||
1287 |
changeMessage:aSymbol |
|
754 | 1288 |
"set the changeMessage - forward to my menu" |
202 | 1289 |
|
1290 |
menuView changeMessage:aSymbol |
|
754 | 1291 |
|
1292 |
"Modified: 5.6.1996 / 17:08:41 / cg" |
|
202 | 1293 |
! |
1294 |
||
962 | 1295 |
menuPerformer |
1296 |
"get the menuPerformer - forwarded to my menuViews" |
|
1297 |
||
1298 |
^ menuView menuPerformer |
|
1299 |
||
1300 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
1301 |
"Created: 21.1.1997 / 15:40:22 / cg" |
|
1302 |
! |
|
1303 |
||
1304 |
menuPerformer:someone |
|
1305 |
"set the menuPerformer - forwarded to my menuViews" |
|
1306 |
||
1307 |
menuView menuPerformer:someone |
|
1308 |
||
1309 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
1310 |
"Created: 21.1.1997 / 15:40:14 / cg" |
|
1311 |
! |
|
1312 |
||
202 | 1313 |
model |
753 | 1314 |
"return my menuViews model" |
1315 |
||
1316 |
^ menuView model |
|
1317 |
||
1318 |
"Modified: 5.6.1996 / 14:16:53 / cg" |
|
202 | 1319 |
! |
1320 |
||
1321 |
model:aModel |
|
754 | 1322 |
"set the model - forwarded to my menuViews" |
1323 |
||
202 | 1324 |
menuView model:aModel |
754 | 1325 |
|
1326 |
"Modified: 5.6.1996 / 17:08:30 / cg" |
|
202 | 1327 |
! ! |
1328 |
||
4272
2023eba96b06
added: #atMenuItemLabeled:putSubmenu:visible:
Claus Gittinger <cg@exept.de>
parents:
4025
diff
changeset
|
1329 |
|
202 | 1330 |
!PopUpMenu methodsFor:'deactivation'! |
1331 |
||
1332 |
hide |
|
1333 |
"hide the menu - if there are any pop-up-submenus, hide them also" |
|
1334 |
||
1335 |
menuView hideSubmenu. |
|
1336 |
super hide. |
|
3972 | 1337 |
(self isOpenedAsSubmenu) ifTrue:[ |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1338 |
menuView superMenu regainControl |
202 | 1339 |
]. |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1340 |
|
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1341 |
"Modified: 25.2.1997 / 22:11:53 / cg" |
2068 | 1342 |
! |
1343 |
||
1344 |
hideForAction |
|
1345 |
"hide the menu - if there are any pop-up-submenus, hide them also. |
|
1346 |
Any superMenu is not asked to regain control, since we are going to |
|
1347 |
hide them also." |
|
1348 |
||
1349 |
menuView hideSubmenu. |
|
1350 |
super hide. |
|
202 | 1351 |
! ! |
1352 |
||
2038 | 1353 |
!PopUpMenu methodsFor:'dummy'! |
1354 |
||
1355 |
findGuiResourcesIn:aResourceContainerOrApplication |
|
1356 |
"dummy - for compatibility with MenuPanel (in case an old-style |
|
1357 |
PopUpMenu us returned from a menu message) |
|
1358 |
" |
|
1359 |
||
1360 |
||
1361 |
! ! |
|
1362 |
||
70 | 1363 |
!PopUpMenu methodsFor:'event handling'! |
0 | 1364 |
|
161 | 1365 |
buttonMotion:state x:x y:y |
3972 | 1366 |
|p sensor| |
7 | 1367 |
|
3913
f15213240dde
preps for right-menu on buttonRelease
Claus Gittinger <cg@exept.de>
parents:
3594
diff
changeset
|
1368 |
"/ state == 0 ifTrue:[^ self]. |
1623
1fde415aabf3
ignore motion event if no button is pressed.
Claus Gittinger <cg@exept.de>
parents:
1606
diff
changeset
|
1369 |
|
1150 | 1370 |
(sensor := self sensor) isNil ifTrue:[^ self]. |
3913
f15213240dde
preps for right-menu on buttonRelease
Claus Gittinger <cg@exept.de>
parents:
3594
diff
changeset
|
1371 |
(sensor hasButtonMotionEventFor:self) ifTrue:[^ self]. |
f15213240dde
preps for right-menu on buttonRelease
Claus Gittinger <cg@exept.de>
parents:
3594
diff
changeset
|
1372 |
|
1623
1fde415aabf3
ignore motion event if no button is pressed.
Claus Gittinger <cg@exept.de>
parents:
1606
diff
changeset
|
1373 |
"any-button ?" |
3913
f15213240dde
preps for right-menu on buttonRelease
Claus Gittinger <cg@exept.de>
parents:
3594
diff
changeset
|
1374 |
"/ sensor anyButtonPressed ifFalse:[^ self]. |
161 | 1375 |
|
1859
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1376 |
((x >= 0) |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1377 |
and:[x < width |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1378 |
and:[y >= 0 |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1379 |
and:[y < height]]]) ifTrue:[ |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1380 |
"/ inside me |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1381 |
|
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1382 |
(x >= margin |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1383 |
and:[x < (width-margin) |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1384 |
and:[y >= margin |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1385 |
and:[y < (height-margin)]]]) ifTrue:[ |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1386 |
"/ inside my menuView |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1387 |
hideOnRelease := true. |
4905 | 1388 |
p := self graphicsDevice |
2434
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1389 |
translatePoint:(x @ y) |
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1390 |
fromView:self |
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1391 |
toView:menuView. |
1859
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1392 |
|
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1393 |
menuView buttonMotion:state x:p x y:p y. |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1394 |
]. |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1395 |
^ self |
0 | 1396 |
]. |
7 | 1397 |
|
1398 |
"outside of myself" |
|
3972 | 1399 |
(self isOpenedAsSubmenu) ifTrue:[ |
4905 | 1400 |
p := self graphicsDevice |
2434
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1401 |
translatePoint:(x @ y) |
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1402 |
fromView:self |
a9b9d8f2ab5b
use new translatePoint:fromView:toView:
Claus Gittinger <cg@exept.de>
parents:
2433
diff
changeset
|
1403 |
toView:(menuView superMenu). |
3493 | 1404 |
p notNil ifTrue:[ |
3972 | 1405 |
menuView superMenu buttonMotion:state x:p x y:p y |
3493 | 1406 |
] |
7 | 1407 |
]. |
1408 |
||
1409 |
menuView subMenuShown isNil ifTrue:[ |
|
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1410 |
menuView pointerLeave:state. |
7 | 1411 |
]. |
1412 |
||
0 | 1413 |
hideOnLeave ifTrue:[ |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1414 |
self hide |
38 | 1415 |
]. |
1057
220f818b0577
ignore motions if more are pending
Claus Gittinger <cg@exept.de>
parents:
1056
diff
changeset
|
1416 |
|
3493 | 1417 |
"Modified: / 28-07-2007 / 13:14:12 / cg" |
0 | 1418 |
! |
1419 |
||
105 | 1420 |
buttonPress:button x:x y:y |
497 | 1421 |
hideOnRelease := true. |
967 | 1422 |
|
497 | 1423 |
((x >= 0) and:[x < width]) ifTrue:[ |
1424 |
((y >= 0) and:[y < height]) ifTrue:[ |
|
1425 |
menuView buttonPress:button x:x y:y. |
|
1426 |
^ self |
|
1427 |
] |
|
105 | 1428 |
]. |
497 | 1429 |
|
967 | 1430 |
"Modified: 22.1.1997 / 17:38:14 / cg" |
105 | 1431 |
! |
1432 |
||
0 | 1433 |
buttonRelease:button x:x y:y |
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1434 |
|h| |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1435 |
|
497 | 1436 |
realized ifFalse:[^ self]. |
1437 |
||
1438 |
"/ |
|
1439 |
"/ detect short click - stay open if this is one |
|
1440 |
"/ |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1441 |
h := hideOnRelease. |
497 | 1442 |
(OperatingSystem |
1443 |
millisecondTimeDeltaBetween:(Time millisecondClockValue) |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1444 |
and:mapTime) > (self class maxClickTimeToStayOpen) ifFalse:[ |
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1445 |
hideOnRelease := false. |
497 | 1446 |
]. |
1447 |
||
105 | 1448 |
hideOnRelease ifFalse:[ |
425 | 1449 |
^ self |
105 | 1450 |
]. |
1451 |
||
497 | 1452 |
(x < 0 |
1453 |
or:[x >= width |
|
1454 |
or:[y < 0 |
|
1455 |
or:[y >= height]]]) ifTrue:[ |
|
1456 |
"/ |
|
1457 |
"/ released outside of mySelf |
|
1458 |
"/ |
|
3972 | 1459 |
(self isOpenedAsSubmenu) ifTrue:[ |
497 | 1460 |
menuView superMenu hideSubmenu |
1461 |
] ifFalse:[ |
|
1462 |
self hide |
|
1463 |
]. |
|
1464 |
^ self |
|
1465 |
]. |
|
1466 |
||
1467 |
||
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1468 |
"/ menuView superMenu notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1469 |
"/ menuView superMenu submenuTriggered |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
459
diff
changeset
|
1470 |
"/ ]. |
497 | 1471 |
|
7 | 1472 |
menuView buttonRelease:button x:x y:y. |
425 | 1473 |
|
497 | 1474 |
"Modified: 8.3.1996 / 14:17:18 / cg" |
112 | 1475 |
! |
1476 |
||
1477 |
keyPress:key x:x y:y |
|
491 | 1478 |
<resource: #keyboard (#Tab)> |
1479 |
||
3365 | 1480 |
hideOnKeyFilter notNil ifTrue:[ |
1481 |
(hideOnKeyFilter value:key) ifTrue:[ |
|
1482 |
self hide. |
|
1483 |
^ self. |
|
1484 |
]. |
|
1485 |
]. |
|
425 | 1486 |
|
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1487 |
key == #Tab ifTrue:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1488 |
self hide. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1489 |
super keyPress:key x:x y:y. |
3365 | 1490 |
^ self. |
1491 |
]. |
|
1492 |
||
1493 |
x == 0 ifTrue:[ |
|
1494 |
menuView keyPress:key x:nil y:nil. |
|
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1495 |
] ifFalse:[ |
3365 | 1496 |
x notNil ifTrue:[ |
1497 |
"/ already redelegated |
|
1498 |
menuView keyPress:key x:x y:y. |
|
1499 |
]. |
|
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1500 |
]. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
1501 |
|
1408
61d42fa7dafd
care for recursive redelegation
Claus Gittinger <cg@exept.de>
parents:
1404
diff
changeset
|
1502 |
"Modified: / 6.12.1997 / 01:53:08 / cg" |
202 | 1503 |
! |
1504 |
||
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
|
1505 |
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
|
1506 |
super mapped. |
497 | 1507 |
|
1508 |
"/ |
|
1509 |
"/ check if a button is pressed when mapped; |
|
1510 |
"/ if not, change my hide-strategy |
|
1511 |
"/ |
|
1512 |
||
1513 |
"/ device buttonStates == 0 ifTrue:[ |
|
1514 |
"/ hideOnRelease := false |
|
1515 |
"/ ]. |
|
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
|
1516 |
|
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
|
1517 |
"Created: 9.2.1996 / 19:56:20 / cg" |
497 | 1518 |
"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
|
1519 |
! |
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
|
1520 |
|
202 | 1521 |
pointerEnter:state x:x y:y |
1522 |
"catch quick release of button" |
|
1523 |
||
1524 |
hideOnLeave ifTrue:[ |
|
1859
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1525 |
state == 0 ifTrue:[ |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1526 |
self hide |
acd3ca6d027b
do not forward motion-events if within my margin.
Claus Gittinger <cg@exept.de>
parents:
1623
diff
changeset
|
1527 |
]. |
202 | 1528 |
] |
1529 |
! |
|
1530 |
||
1531 |
pointerLeave:state |
|
1532 |
"/ menuView pointerLeave:state. |
|
1533 |
"/ hideOnLeave ifTrue:[ |
|
1534 |
"/ self hide |
|
1535 |
"/ ]. |
|
1536 |
"/ menuView superMenu notNil ifTrue:[ |
|
1537 |
"/ menuView superMenu regainControl |
|
1538 |
"/ ] |
|
0 | 1539 |
! ! |
202 | 1540 |
|
1541 |
!PopUpMenu methodsFor:'initialization'! |
|
1542 |
||
1543 |
initEvents |
|
1544 |
super initEvents. |
|
1545 |
self enableEnterLeaveEvents. |
|
3913
f15213240dde
preps for right-menu on buttonRelease
Claus Gittinger <cg@exept.de>
parents:
3594
diff
changeset
|
1546 |
self enableMotionEvents. |
495
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1547 |
|
d993f23ea658
fixed subMenus with a menuPerformer (now also behaves the ST-80 way)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1548 |
"Modified: 7.3.1996 / 14:17:42 / cg" |
202 | 1549 |
! |
1550 |
||
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1551 |
initStyle |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1552 |
<resource: #style (#'popup.hideOnRelease' |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1553 |
#'popup.level' |
4025 | 1554 |
"/ #'popup.borderWidth' |
1555 |
"/ #'popup.borderColor' |
|
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1556 |
)> |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1557 |
|
4025 | 1558 |
|lvl bw bc| |
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1559 |
|
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1560 |
super initStyle. |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1561 |
|
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1562 |
(lvl := styleSheet at:#'popup.level') notNil ifTrue:[ |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1563 |
self level:lvl. |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1564 |
]. |
4025 | 1565 |
"/ (bw := styleSheet at:#'popup.borderWidth') notNil ifTrue:[ |
1566 |
"/ self borderWidth:bw |
|
1567 |
"/ ]. |
|
1568 |
"/ (bc := styleSheet at:#'popup.borderColor') notNil ifTrue:[ |
|
1569 |
"/ self borderColor:bc |
|
1570 |
"/ ]. |
|
2655
3648be6af751
time constant for hideOnRelease shared with MenuPanel
Claus Gittinger <cg@exept.de>
parents:
2645
diff
changeset
|
1571 |
defaultHideOnRelease := styleSheet at:#'popup.hideOnRelease' default:true. |
1861
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1572 |
! |
a582b6c0809d
take level & borderWidth from popup.level and
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
1573 |
|
202 | 1574 |
initialize |
1575 |
super initialize. |
|
1576 |
||
1577 |
memorize := true. |
|
1578 |
hideOnLeave := false. |
|
1579 |
! ! |
|
1580 |
||
1581 |
!PopUpMenu methodsFor:'menuview messages'! |
|
1582 |
||
1583 |
doesNotUnderstand:aMessage |
|
1584 |
"forward all menu-view messages" |
|
1585 |
||
1586 |
(menuView respondsTo:(aMessage selector)) ifTrue:[ |
|
1587 |
^ aMessage sendTo:menuView |
|
1588 |
]. |
|
1589 |
^ super doesNotUnderstand:aMessage |
|
1404 | 1590 |
! |
1591 |
||
1592 |
regainControl |
|
2068 | 1593 |
|g| |
4905 | 1594 |
((g := self graphicsDevice activePointerGrab) ~~ self) ifTrue:[ |
2068 | 1595 |
self forceUngrabPointer. |
1596 |
self forceUngrabKeyboard. |
|
1597 |
shown ifTrue:[ |
|
1598 |
self grabPointer. |
|
1599 |
self grabKeyboard. |
|
1600 |
] |
|
1442
7dfbc21dfdc6
Avoid pointer and keyboard grabbing if not necessary
Stefan Vogel <sv@exept.de>
parents:
1408
diff
changeset
|
1601 |
]. |
1404 | 1602 |
|
1442
7dfbc21dfdc6
Avoid pointer and keyboard grabbing if not necessary
Stefan Vogel <sv@exept.de>
parents:
1408
diff
changeset
|
1603 |
"Modified: / 20.11.1997 / 00:32:32 / cg" |
7dfbc21dfdc6
Avoid pointer and keyboard grabbing if not necessary
Stefan Vogel <sv@exept.de>
parents:
1408
diff
changeset
|
1604 |
"Modified: / 2.2.1998 / 23:52:28 / stefan" |
202 | 1605 |
! ! |
1606 |
||
2742 | 1607 |
!PopUpMenu methodsFor:'private-accessing'! |
202 | 1608 |
|
3972 | 1609 |
isOpenedAsSubmenu |
1610 |
"return true, if I have been opened as a submenu of some other |
|
1611 |
menu." |
|
1612 |
||
1613 |
|superMenu| |
|
1614 |
||
1615 |
superMenu := menuView superMenu. |
|
1616 |
"/ check for realized, because the CTRL/SHIFT menus of a textView |
|
1617 |
"/ are opened as top-menu AND have a non-nil supermenu. |
|
1618 |
"/ thus asking for supermenu being nonNil is NOT a sufficient indicator for |
|
1619 |
"/ being an open submenu !! |
|
1620 |
^ superMenu notNil and:[superMenu realized] |
|
1621 |
! |
|
1622 |
||
1056 | 1623 |
menu:aMenuView |
202 | 1624 |
"set the actual menu" |
1625 |
||
2367 | 1626 |
<resource:#obsolete> |
1627 |
||
1056 | 1628 |
self obsoleteMethodWarning:'use #menuView:'. |
1629 |
self menuView:aMenuView |
|
1630 |
||
1631 |
"Modified: 25.2.1997 / 20:52:08 / cg" |
|
202 | 1632 |
! |
1633 |
||
1634 |
menuView |
|
1635 |
"return the actual menu" |
|
1636 |
||
1637 |
^ menuView |
|
1638 |
! |
|
1639 |
||
1056 | 1640 |
menuView:aMenu |
1641 |
"set the actual menu" |
|
1642 |
||
1643 |
menuView := aMenu. |
|
1644 |
menuView origin:(margin @ margin). |
|
1645 |
menuView borderWidth:0. |
|
1646 |
menuView masterView:self |
|
1647 |
||
1648 |
"Created: 25.2.1997 / 20:51:42 / cg" |
|
1649 |
! |
|
1650 |
||
202 | 1651 |
superMenu:aMenu |
1056 | 1652 |
"set the superMenu" |
202 | 1653 |
|
1654 |
menuView superMenu:aMenu |
|
1056 | 1655 |
|
1656 |
"Modified: 25.2.1997 / 20:52:20 / cg" |
|
202 | 1657 |
! ! |
1658 |
||
1659 |
!PopUpMenu methodsFor:'realization'! |
|
1660 |
||
1661 |
fixSize |
|
1662 |
"called right before the view is made visible. |
|
1663 |
adjust my size to the size of the actual menu" |
|
1664 |
||
1665 |
|extra newWidth newHeight| |
|
1666 |
||
1667 |
extra := margin * 2. |
|
1668 |
menuView resizeIfChanged. |
|
1669 |
newWidth := menuView width + extra. |
|
1670 |
newHeight := menuView height + extra. |
|
1671 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[ |
|
2716 | 1672 |
self extent:(newWidth @ newHeight) |
202 | 1673 |
]. |
1674 |
super fixSize |
|
1675 |
! |
|
1676 |
||
1677 |
realize |
|
4686 | 1678 |
(memorize == true and:[lastSelection notNil]) ifTrue:[ |
1679 |
menuView setSelection:lastSelection. |
|
1680 |
] ifFalse:[ |
|
1681 |
menuView deselectWithoutRedraw. |
|
1682 |
]. |
|
202 | 1683 |
super realize. |
1684 |
hideOnRelease := defaultHideOnRelease. |
|
1685 |
! ! |
|
1686 |
||
205 | 1687 |
!PopUpMenu class methodsFor:'documentation'! |
1688 |
||
4614 | 1689 |
version |
5049 | 1690 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.116 2014-06-04 12:38:42 cg Exp $' |
4614 | 1691 |
! |
1692 |
||
3965 | 1693 |
version_CVS |
5049 | 1694 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.116 2014-06-04 12:38:42 cg Exp $' |
205 | 1695 |
! ! |
4544 | 1696 |