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