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