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