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