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