author | Claus Gittinger <cg@exept.de> |
Wed, 28 Feb 1996 19:46:01 +0100 | |
changeset 426 | bf35bf40ab11 |
parent 425 | 9d44d3ff44a0 |
child 459 | 5c35e2f02d27 |
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' |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
16 |
classVariableNames:'DefaultHideOnRelease' |
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 |
" |
|
39 |
This class provides PopUpMenu functionality; Actually, this class |
|
40 |
only provides the popup and shadow functionality and wraps another |
|
41 |
view, which is the actual menu-list (usually an instance of MenuView). |
|
42 |
||
43 |
PopUpMenus are usually created with a list of labels, selectors and a |
|
44 |
receivier. Once activated, the specified receiver will be sent a |
|
45 |
'selector'-message. |
|
112 | 46 |
|
47 |
PopupMenus may be either assigned statically to a view (via the #middleButtonMenu: |
|
48 |
message) or created dynamically as required. |
|
49 |
Static definition makes sense, if the menu stays constant and you want to |
|
50 |
assign it once for the lifetime of the view. |
|
51 |
||
52 |
Dynamic menus are easier to use, if the number of or look of the entries has to |
|
53 |
change according the internal state of some model. Also, this is the ST-80 way |
|
54 |
of using popupMenus. For dynamic popups, the views model is asked for a menu |
|
55 |
via the #menuSelector each time a button press occurs. |
|
56 |
||
57 |
See examples section for more. |
|
63 | 58 |
" |
59 |
! |
|
38 | 60 |
|
63 | 61 |
examples |
62 |
" |
|
284 | 63 |
|
38 | 64 |
Examples: |
65 |
||
284 | 66 |
|p| |
67 |
p := PopUpMenu |
|
68 |
labels:#('foo' |
|
69 |
'bar' |
|
70 |
'baz') |
|
71 |
selectors:#( |
|
72 |
#foo |
|
73 |
#bar |
|
74 |
#baz) |
|
75 |
receiver:nil. |
|
76 |
p showAtPointer |
|
38 | 77 |
|
78 |
||
79 |
sometimes, you want to specify both selectors and some arguments |
|
80 |
to be sent; this is done by: |
|
81 |
||
284 | 82 |
|p| |
83 |
p := PopUpMenu |
|
84 |
labels:#('foo' 'bar' 'baz') |
|
85 |
selectors:#(#foo: #bar: #foo:) |
|
86 |
args:#(1 2 3) |
|
87 |
receiver:nil. |
|
88 |
p showAtPointer |
|
38 | 89 |
|
90 |
or, the same selector but different arguments: |
|
91 |
||
284 | 92 |
|p| |
93 |
p := PopUpMenu |
|
94 |
labels:#('foo' 'bar' 'baz') |
|
95 |
selectors:#foo: |
|
96 |
args:#(1 2 3) |
|
97 |
receiver:nil. |
|
98 |
p showAtPointer |
|
38 | 99 |
|
100 |
Normally, you do not show the menu explicitely, but install |
|
112 | 101 |
it as a either as middleButtonMenu of some view or return it from |
102 |
a model. |
|
103 |
(Views/Controllers button-event handler will show it when the middle |
|
104 |
button is pressed ...) |
|
105 |
Static menu: |
|
38 | 106 |
|
284 | 107 |
|v m| |
38 | 108 |
|
284 | 109 |
v := View new. |
110 |
m := PopUpMenu |
|
111 |
labels:#('lower' |
|
112 |
'raise' |
|
113 |
'-' |
|
114 |
'destroy') |
|
115 |
selectors:#(#lower #raise nil #destroy) |
|
116 |
receiver:v. |
|
117 |
v middleButtonMenu:m. |
|
118 |
v open |
|
38 | 119 |
|
112 | 120 |
Dynamic menu: |
121 |
(since we need some model which responds to a menu-message, |
|
122 |
we use a plug in the example below; normally, this would be your model) |
|
123 |
||
284 | 124 |
|v model| |
112 | 125 |
|
284 | 126 |
model := Plug new. |
127 |
model respondTo:#getMenu with:[PopUpMenu labels:#('foo' 'bar') |
|
128 |
selectors:#(foo bar)]. |
|
129 |
model respondTo:#foo with:[Transcript showCr:'models foo called']. |
|
130 |
model respondTo:#bar with:[Transcript showCr:'models bar called']. |
|
112 | 131 |
|
284 | 132 |
v := View new. |
133 |
v model:model; menu:#getMenu. |
|
134 |
v open |
|
112 | 135 |
|
136 |
Dynamic menus are the MVC-way (i.e. ST-80) way of doing things. |
|
137 |
They are usually easier to use, if the menu changes depending on the models |
|
138 |
state. (for example, see the systemBrowsers menus being different when |
|
139 |
things are selected ...) |
|
140 |
||
38 | 141 |
It is also possible, to add check-mark entries, with an entry string |
142 |
starting with the special sequence '\c' (for check-mark). The value |
|
143 |
passed will be the truth-state of the check-mark. |
|
144 |
||
284 | 145 |
|m v| |
38 | 146 |
|
284 | 147 |
v := View new. |
148 |
m := PopUpMenu |
|
149 |
labels:#('\c foo' |
|
150 |
'\c bar') |
|
151 |
selectors:#(#value: #value:) |
|
152 |
receiver:[:v | Transcript show:'arg: '; showCr:v]. |
|
153 |
v middleButtonMenu:m. |
|
154 |
v open |
|
38 | 155 |
|
404 | 156 |
The style of the checkmark can be: check (\c), box (\b) or thumbs (\t): |
157 |
||
158 |
|m v| |
|
159 |
||
160 |
v := View new. |
|
161 |
m := PopUpMenu |
|
162 |
labels:#('\c foo' |
|
163 |
'\b bar' |
|
164 |
'\t baz') |
|
165 |
selectors:#(#value: #value: #value:) |
|
166 |
receiver:[:v | Transcript show:'arg: '; showCr:v]. |
|
167 |
v middleButtonMenu:m. |
|
168 |
v open |
|
169 |
||
406 | 170 |
or at the end (looks better with variable fonts): |
171 |
||
172 |
|m v| |
|
173 |
||
174 |
v := View new. |
|
175 |
m := PopUpMenu |
|
176 |
labels:#('foo \c' |
|
177 |
'bar \b' |
|
178 |
'baz \t') |
|
179 |
selectors:#(#value: #value: #value:) |
|
180 |
receiver:[:v | Transcript show:'arg: '; showCr:v]. |
|
181 |
v middleButtonMenu:m. |
|
182 |
v open |
|
183 |
||
38 | 184 |
Finally, you can wrap other views into a popup menu (for example, |
185 |
to implement menus with icons or other components). |
|
186 |
The view should respond to some messages sent from here (for |
|
187 |
example: #hideSubmenus, #deselectWithoutRedraw and others). |
|
188 |
Currently there is only one class in the system, which can be used |
|
189 |
this way (PatternMenu in the DrawTool demo): |
|
190 |
||
284 | 191 |
|v p| |
38 | 192 |
|
284 | 193 |
v := View new. |
194 |
p := PatternMenu new. |
|
195 |
p patterns:(Array with:Color red |
|
196 |
with:Color green |
|
197 |
with:Color blue). |
|
198 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
199 |
v open |
|
38 | 200 |
|
201 |
or try: |
|
202 |
||
284 | 203 |
|v p| |
38 | 204 |
|
284 | 205 |
v := View new. |
206 |
p := PatternMenu new. |
|
207 |
p patterns:(Array with:Color red |
|
208 |
with:Color green |
|
209 |
with:Color blue). |
|
210 |
p selectors:#value:. |
|
211 |
p receiver:[:val | v viewBackground:val. v clear]. |
|
212 |
p args:(Array with:Color red |
|
213 |
with:Color green |
|
214 |
with:Color blue). |
|
215 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
216 |
v open |
|
38 | 217 |
|
218 |
||
219 |
ST-80 style: |
|
220 |
||
221 |
The above menus all did some message send on selection; it is |
|
222 |
also possible, to use Smalltalk-80 style menus (which return some value |
|
223 |
from their startup method): |
|
224 |
||
284 | 225 |
|m selection| |
38 | 226 |
|
284 | 227 |
m := PopUpMenu |
228 |
labels:#('one' 'two' 'three'). |
|
229 |
selection := m startUp. |
|
230 |
Transcript show:'the selection was: '; showCr:selection |
|
38 | 231 |
|
232 |
startUp will return the entries index, or 0 if there was no selection. |
|
233 |
You can also specify an array of values to be returned instead of the |
|
234 |
index: |
|
235 |
||
284 | 236 |
|m selection| |
38 | 237 |
|
284 | 238 |
m := PopUpMenu |
239 |
labels:#('one' 'two' 'three') |
|
240 |
values:#(10 20 30). |
|
241 |
selection := m startUp. |
|
242 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 243 |
|
244 |
In ST/X style menus, separating lines between entries are created |
|
245 |
by a '-'-string as its label text (and corresponding nil-entries in the |
|
246 |
selectors- and args-arrays). |
|
247 |
In ST-80, you have to pass the indices of the lines in an extra array: |
|
248 |
||
284 | 249 |
|m selection| |
38 | 250 |
|
284 | 251 |
m := PopUpMenu |
252 |
labels:#('one' 'two' 'three' 'four' 'five') |
|
253 |
lines:#(2 4). |
|
254 |
selection := m startUp. |
|
255 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 256 |
|
257 |
or: |
|
284 | 258 |
|m selection| |
38 | 259 |
|
284 | 260 |
m := PopUpMenu |
261 |
labels:#('one' 'two' 'three') |
|
262 |
lines:#(2) |
|
263 |
values:#(10 20 30). |
|
264 |
selection := m startUp. |
|
265 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 266 |
|
267 |
Use whichever interface you prefer. |
|
268 |
" |
|
119 | 269 |
! ! |
270 |
||
271 |
!PopUpMenu class methodsFor:'instance creation'! |
|
38 | 272 |
|
273 |
forMenu:aMenuView |
|
274 |
"this wraps an already existing menu - allowing to put any |
|
275 |
view (not just MenuViews) into popups (for example, menus |
|
276 |
with icons, or other components). |
|
277 |
Currently, there is only one example of different menus in |
|
278 |
the system (PatternMenu in the DrawTool) which could be used |
|
279 |
this way. |
|
280 |
The view should respond to some of the menuView messages |
|
281 |
(such as hideSubmenu, deselectWithoutRedraw etc.)" |
|
282 |
||
283 |
|newMenu| |
|
284 |
||
285 |
newMenu := self onSameDeviceAs:aMenuView. |
|
286 |
newMenu addSubView:aMenuView. |
|
287 |
newMenu menu:aMenuView. |
|
288 |
^ newMenu |
|
289 |
! |
|
290 |
||
202 | 291 |
labels:labels selector:aSelector args:args receiver:anObject |
292 |
"create and return a popup menu with labels as entries. |
|
293 |
Each item will send aSelector with a corresponding argument from the |
|
294 |
args array to anObject. The menu is created on the default DIsplay" |
|
295 |
||
296 |
" |
|
297 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
298 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
299 |
^ 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
|
300 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
301 |
"Modified: 28.2.1996 / 19:01:12 / cg" |
202 | 302 |
! |
303 |
||
304 |
labels:labels selector:aSelector args:args receiver:anObject for:aView |
|
305 |
"create and return a popup menu with labels as entries. |
|
306 |
Each item will send aSelector with a corresponding argument from the |
|
307 |
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
|
308 |
as aView (which is only of interest in multi-Display applications; |
202 | 309 |
typical applications can use the sibbling message without the for: argument)." |
310 |
||
311 |
" |
|
312 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
313 |
" |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
314 |
^ 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
|
315 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
316 |
"Modified: 28.2.1996 / 19:01:29 / cg" |
202 | 317 |
! |
318 |
||
319 |
labels:labels selectors:selectors |
|
320 |
"create and return a menu with label-items and selectors. The receiver |
|
321 |
will either be defined later, or not used at all (if opened via startUp)" |
|
322 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
323 |
^ 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
|
324 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
325 |
"Modified: 28.2.1996 / 19:01:35 / cg" |
202 | 326 |
! |
327 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
328 |
labels:labels selectors:selectors accelerators:shorties |
202 | 329 |
"create and return a menu with label-items and selectors. The receiver |
330 |
will either be defined later, or not used at all (if opened via startUp)" |
|
331 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
332 |
^ 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
|
333 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
334 |
"Created: 28.2.1996 / 18:58:52 / cg" |
202 | 335 |
! |
336 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
337 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject |
202 | 338 |
"create and return a popup menu with labels as entries. |
339 |
Each item will send a corresponding selector:argument from the selectors- |
|
340 |
and args array to anObject. The menu is created on the default Display" |
|
341 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
342 |
^ 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
|
343 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
344 |
"Created: 28.2.1996 / 18:59:03 / cg" |
202 | 345 |
! |
346 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
347 |
labels:labels selectors:selectors accelerators:shorties args:args receiver:anObject for:aView |
63 | 348 |
"create and return a popup menu with labels as entries. |
349 |
Each item will send a corresponding selector:argument from the selectors- |
|
350 |
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
|
351 |
as aView (which is only of interest in multi-Display applications; |
63 | 352 |
typical applications can use the sibbling message without the for: argument)." |
353 |
||
38 | 354 |
|newMenu| |
355 |
||
356 |
newMenu := self onSameDeviceAs:aView. |
|
357 |
newMenu menu:(MenuView |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
358 |
labels:labels |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
359 |
selectors:selectors |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
360 |
accelerators:shorties |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
361 |
args:args |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
362 |
receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
363 |
in:newMenu). |
38 | 364 |
^ newMenu |
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
365 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
366 |
"Created: 28.2.1996 / 18:59:25 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
367 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
368 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
369 |
labels:labels selectors:selectors accelerators:shorties receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
370 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
371 |
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
|
372 |
selectors-array. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
373 |
The menu is created on the default Display." |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
374 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
375 |
^ 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
|
376 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
377 |
"Created: 28.2.1996 / 19:00:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
378 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
379 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
380 |
labels:labels selectors:selectors args:argArray |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
381 |
"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
|
382 |
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
|
383 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
384 |
^ 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
|
385 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
386 |
"Modified: 28.2.1996 / 19:01:45 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
387 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
388 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
389 |
labels:labels selectors:selectors args:args receiver:anObject |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
390 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
391 |
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
|
392 |
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
|
393 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
394 |
^ 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
|
395 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
396 |
"Modified: 28.2.1996 / 19:01:49 / cg" |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
397 |
! |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
398 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
399 |
labels:labels selectors:selectors args:args receiver:anObject for:aView |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
400 |
"create and return a popup menu with labels as entries. |
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
401 |
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
|
402 |
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
|
403 |
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
|
404 |
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
|
405 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
406 |
^ 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
|
407 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
408 |
"Modified: 28.2.1996 / 19:03:58 / cg" |
38 | 409 |
! |
410 |
||
119 | 411 |
labels:labels selectors:selectors receiver:anObject |
412 |
"create and return a popup menu with labels as entries. |
|
413 |
Each item will send a message with a selector from the corresponding |
|
414 |
selectors-array. |
|
415 |
The menu is created on the default Display." |
|
416 |
||
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
417 |
^ 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
|
418 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
419 |
"Modified: 28.2.1996 / 19:02:07 / cg" |
63 | 420 |
! |
421 |
||
202 | 422 |
labels:labels selectors:selectors receiver:anObject for:aView |
423 |
"create and return a popup menu with labels as entries. |
|
424 |
Each item will send a corresponding selector from the selectors-array |
|
425 |
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
|
426 |
as aView (which is only of interest in multi-Display applications; |
202 | 427 |
typical applications can use the sibbling message without the for: argument)." |
63 | 428 |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
429 |
^ 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
|
430 |
|
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
431 |
"Modified: 28.2.1996 / 19:02:10 / cg" |
0 | 432 |
! ! |
433 |
||
434 |
!PopUpMenu class methodsFor:'ST-80 instance creation'! |
|
435 |
||
202 | 436 |
labelArray:labels lines:lines values:values |
437 |
"ST80R4 compatibility" |
|
119 | 438 |
|
202 | 439 |
^ self labels:labels lines:lines values:values |
0 | 440 |
! |
441 |
||
119 | 442 |
labelArray:labels values:values |
443 |
"ST80R4 compatibility" |
|
444 |
||
445 |
^ self labels:labels lines:nil values:values |
|
446 |
! |
|
447 |
||
202 | 448 |
labelList:labels |
449 |
"ST80R4 compatibility: |
|
450 |
given a list consisting of group label entries (to be separated by |
|
451 |
lines), convert into standard form (using '-' for lines. |
|
452 |
" |
|
453 |
||
454 |
^ self labelList:labels values:nil |
|
119 | 455 |
|
202 | 456 |
" |
457 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer |
|
458 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer |
|
459 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer |
|
460 |
" |
|
461 |
! |
|
462 |
||
463 |
labelList:labels lines:lines values:values |
|
464 |
"mhmh what is that ?" |
|
465 |
||
466 |
^ (self new) labels:labels lines:lines values:values |
|
119 | 467 |
! |
468 |
||
0 | 469 |
labelList:labels values:values |
119 | 470 |
"ST80R4 compatibility: |
471 |
given a list consisting of group label entries (to be separated by |
|
472 |
lines), convert into standard form (using '-' for lines. |
|
473 |
" |
|
474 |
||
475 |
|newLabels newValues lS vS first| |
|
476 |
||
477 |
newLabels := OrderedCollection new. |
|
478 |
newValues := OrderedCollection new. |
|
479 |
lS := ReadStream on:labels. |
|
480 |
values notNil ifTrue:[vS := ReadStream on:values]. |
|
481 |
first := true. |
|
482 |
[lS atEnd] whileFalse:[ |
|
483 |
|entry| |
|
484 |
||
485 |
entry := lS next. |
|
486 |
entry isCollection ifTrue:[ |
|
487 |
first ifFalse:[ |
|
488 |
newLabels add:'-'. |
|
489 |
values notNil ifTrue:[newValues add:nil] |
|
490 |
]. |
|
491 |
newLabels addAll:entry. |
|
492 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)] |
|
493 |
] ifFalse:[ |
|
494 |
newLabels add:entry. |
|
495 |
values notNil ifTrue:[newValues add:(vS next)] |
|
496 |
]. |
|
497 |
first := false. |
|
498 |
]. |
|
499 |
values isNil ifTrue:[ |
|
500 |
^ self labels:newLabels |
|
501 |
]. |
|
502 |
^ self labels:newLabels values:newValues |
|
503 |
||
504 |
" |
|
505 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer |
|
506 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer |
|
507 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer |
|
508 |
" |
|
509 |
! |
|
510 |
||
202 | 511 |
labels:labels |
512 |
"ST80R2 compatibility" |
|
59 | 513 |
|
202 | 514 |
^ self labels:labels lines:nil values:nil |
0 | 515 |
! |
516 |
||
202 | 517 |
labels:labels lines:lines |
518 |
"ST80R2 compatibility" |
|
0 | 519 |
|
202 | 520 |
^ self labels:labels lines:lines values:nil |
77 | 521 |
! |
522 |
||
202 | 523 |
labels:labels lines:lines values:values |
524 |
"ST80R2 compatibility" |
|
127 | 525 |
|
202 | 526 |
^ (self new) labels:labels lines:lines values:values |
77 | 527 |
! |
528 |
||
202 | 529 |
labels:labels values:values |
530 |
"ST80R2 compatibility" |
|
59 | 531 |
|
202 | 532 |
^ self labels:labels lines:nil values:values |
127 | 533 |
! ! |
534 |
||
202 | 535 |
!PopUpMenu class methodsFor:'defaults'! |
0 | 536 |
|
202 | 537 |
updateStyleCache |
538 |
DefaultHideOnRelease := StyleSheet at:#popupHideOnRelease default:true. |
|
0 | 539 |
! ! |
540 |
||
541 |
!PopUpMenu methodsFor:'ST-80 activation'! |
|
542 |
||
543 |
startUp |
|
38 | 544 |
"start the menu modal - return the selected value, |
545 |
or - if no values where specified - return the index. |
|
0 | 546 |
If nothing was selected, return 0. |
38 | 547 |
Modal - i.e. stay in the menu until finished. |
548 |
This is the ST-80 way of launching a menu." |
|
0 | 549 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
550 |
^ self startUpAt:nil |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
551 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
552 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
553 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
554 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz') |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
555 |
values:#(foo bar baz)) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
556 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
557 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
558 |
"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
|
559 |
! |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
560 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
561 |
startUpAt:aPoint |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
562 |
"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
|
563 |
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
|
564 |
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
|
565 |
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
|
566 |
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
|
567 |
|
96 | 568 |
|return rec sel0 sel1 arg| |
63 | 569 |
|
119 | 570 |
return := 0. |
571 |
||
0 | 572 |
menuView action:[:selected | |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
573 |
|actionIndex value sel retVal| |
38 | 574 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
575 |
retVal := 0. |
95 | 576 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
577 |
menuView args isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
578 |
menuView selectors notNil ifTrue:[ |
119 | 579 |
"/ sel := menuView selectors at:selected. |
580 |
"/ sel notNil ifTrue:[sel0 := sel]. |
|
581 |
||
582 |
"/ (arg := menuView checkFlags at:selected) isNil ifTrue:[ |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
583 |
sel0 := menuView selectors at:selected. |
119 | 584 |
"/ ] ifFalse:[ |
585 |
"/ sel1 := menuView selectors at:selected. |
|
586 |
"/ ]. |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
587 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
588 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
589 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
590 |
actionIndex := menuView args at:selected. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
591 |
actionIndex notNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
592 |
actionValues isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
593 |
menuView selectors notNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
594 |
"/ mhmh an ST/X menu started the ST-80 way |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
595 |
sel1 := menuView selectors at:selected. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
596 |
arg := actionIndex. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
597 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
598 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
599 |
retVal := actionIndex |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
600 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
601 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
602 |
retVal := actionValues at:actionIndex. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
603 |
(retVal isKindOf:PopUpMenu) ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
604 |
retVal := retVal startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
605 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
606 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
607 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
608 |
"/ mhmh an ST/X menu started the ST-80 way |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
609 |
menuView selectors notNil ifTrue:[ |
119 | 610 |
"/ (arg := menuView checkFlags at:selected) isNil ifTrue:[ |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
611 |
sel0 := menuView selectors at:selected. |
119 | 612 |
"/ ] ifFalse:[ |
613 |
"/ sel1 := menuView selectors at:selected. |
|
614 |
"/ ]. |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
615 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
616 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
617 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
618 |
]. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
619 |
return := retVal |
0 | 620 |
]. |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
621 |
aPoint isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
622 |
self showAtPointer |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
623 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
624 |
self showAt:aPoint. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
625 |
]. |
96 | 626 |
|
627 |
"/ |
|
628 |
"/ mhmh an ST/X menu started the ST-80 way |
|
629 |
"/ |
|
630 |
(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
|
631 |
rec := menuView receiver. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
632 |
sel0 notNil ifTrue:[ |
131 | 633 |
^ sel0 |
634 |
"/ rec perform:sel0 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
635 |
] ifFalse:[ |
131 | 636 |
^ Array with:sel1 with:arg. |
637 |
"/ rec perform:sel1 with:arg. |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
638 |
] |
95 | 639 |
]. |
63 | 640 |
^ return |
38 | 641 |
|
642 |
" |
|
63 | 643 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
38 | 644 |
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
|
645 |
values:#(foo bar baz)) startUp |
38 | 646 |
" |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
647 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
648 |
"Created: 10.1.1996 / 20:11:42 / cg" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
649 |
"Modified: 10.1.1996 / 20:12:26 / cg" |
110 | 650 |
! |
651 |
||
652 |
startUpWithHeading:aString |
|
653 |
"start the menu modal - return the selected value, |
|
654 |
or - if no values where specified - return the index. |
|
655 |
If nothing was selected, return 0. |
|
656 |
Modal - i.e. stay in the menu until finished. |
|
657 |
This is the ST-80 way of launching a menu." |
|
658 |
||
659 |
defaultHideOnRelease := false. |
|
660 |
menuView labels notNil ifTrue:[ |
|
661 |
menuView labels:(Array with:aString with:'=') , menuView labels. |
|
662 |
]. |
|
663 |
menuView selectors notNil ifTrue:[ |
|
664 |
menuView selectors:(Array with:nil with:nil) , menuView selectors. |
|
665 |
]. |
|
666 |
"/ menuView disable:1; disable:2. |
|
667 |
||
668 |
^ self startUp. |
|
669 |
||
670 |
" |
|
671 |
(PopUpMenu |
|
672 |
labels:#('foo' 'bar')) |
|
673 |
startUp |
|
674 |
" |
|
675 |
" |
|
676 |
(PopUpMenu |
|
677 |
labels:#('foo' 'bar')) |
|
678 |
startUpWithHeading:'hello' |
|
679 |
" |
|
0 | 680 |
! ! |
681 |
||
202 | 682 |
!PopUpMenu methodsFor:'accessing-behavior'! |
683 |
||
684 |
hideOnLeave:aBoolean |
|
685 |
"set/clear the hideOnLeave attribute, which controls |
|
686 |
if the menu should be hidden when the pointer leaves |
|
687 |
the view (used with multiple-menus)" |
|
688 |
||
689 |
hideOnLeave := aBoolean |
|
690 |
! |
|
691 |
||
692 |
hideOnRelease:aBoolean |
|
693 |
"set/clear the hideOnRelease attribute, which controls |
|
694 |
if the menu should be hidden when the button is released" |
|
695 |
||
335
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
696 |
defaultHideOnRelease := aBoolean. |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
697 |
menuView hideOnRelease:aBoolean |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
698 |
|
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
699 |
"Modified: 9.2.1996 / 02:06:15 / cg" |
202 | 700 |
! ! |
701 |
||
702 |
!PopUpMenu methodsFor:'accessing-items'! |
|
703 |
||
704 |
indexOf:indexOrName |
|
705 |
"return the index of a submenu - or 0 if there is none" |
|
706 |
||
707 |
^ menuView indexOf:indexOrName |
|
708 |
! |
|
709 |
||
710 |
labels |
|
711 |
"return the list of labels" |
|
712 |
||
713 |
actionLabels notNil ifTrue:[ |
|
714 |
^ actionLabels asStringCollection |
|
715 |
]. |
|
716 |
^ menuView list |
|
717 |
! |
|
718 |
||
719 |
labels:labelString lines:lineArray values:valueArray |
|
720 |
"define the menu the ST-80 way (with labels and lines defined separately)" |
|
721 |
||
722 |
|labelArray argArray convertedLabels |
|
723 |
offs dstOffs linePos| |
|
724 |
||
725 |
actionLabels := labelString. |
|
726 |
actionLines := lineArray. |
|
727 |
actionValues := valueArray. |
|
728 |
||
729 |
labelArray := labelString asStringCollection. |
|
730 |
||
731 |
convertedLabels := Array new:(labelArray size + lineArray size). |
|
732 |
argArray := Array new:(labelArray size + lineArray size). |
|
733 |
||
734 |
offs := 1. |
|
735 |
dstOffs := 1. |
|
736 |
1 to:lineArray size do:[:lineIndex | |
|
737 |
linePos := lineArray at:lineIndex. |
|
738 |
[offs <= linePos] whileTrue:[ |
|
739 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
740 |
argArray at:dstOffs put:offs. |
|
741 |
offs := offs + 1. |
|
742 |
dstOffs := dstOffs + 1 |
|
743 |
]. |
|
744 |
convertedLabels at:dstOffs put:'-'. |
|
745 |
argArray at:dstOffs put:nil. |
|
746 |
dstOffs := dstOffs + 1 |
|
747 |
]. |
|
748 |
[offs <= labelArray size] whileTrue:[ |
|
749 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
750 |
argArray at:dstOffs put:offs. |
|
751 |
offs := offs + 1. |
|
752 |
dstOffs := dstOffs + 1 |
|
753 |
]. |
|
754 |
self menu:(MenuView |
|
755 |
labels:convertedLabels |
|
756 |
selectors:nil |
|
757 |
args:argArray |
|
758 |
receiver:nil |
|
759 |
in:self) |
|
760 |
! |
|
761 |
||
762 |
lines |
|
763 |
"st-80 compatibility" |
|
764 |
||
765 |
^ actionLines |
|
766 |
! |
|
767 |
||
768 |
numberOfItems |
|
769 |
"return the number of items in the menu" |
|
770 |
||
771 |
actionLabels notNil ifTrue:[ |
|
772 |
^ actionLabels asStringCollection size |
|
773 |
]. |
|
774 |
^ menuView list size |
|
775 |
! |
|
776 |
||
777 |
remove:indexOrName |
|
778 |
"remove a menu entry" |
|
779 |
||
780 |
menuView remove:indexOrName |
|
781 |
! |
|
782 |
||
783 |
subMenuAt:indexOrName put:aMenu |
|
784 |
"define a submenu to be shown for entry indexOrName" |
|
785 |
||
786 |
" |
|
787 |
aMenu hideOnLeave:true. |
|
788 |
" |
|
789 |
menuView subMenuAt:indexOrName put:aMenu. |
|
790 |
"tell the submenu to notify me when action is performed" |
|
791 |
aMenu superMenu:self. |
|
792 |
||
793 |
" |
|
794 |
|v m someObject| |
|
795 |
||
796 |
v := View new. |
|
797 |
m := PopUpMenu labels:#('1' '2' '3') |
|
798 |
selectors:#(one two nil) |
|
799 |
receiver:someObject |
|
800 |
for:nil. |
|
801 |
m subMenuAt:3 put:(PopUpMenu |
|
802 |
labels:#('a' 'b' 'c') |
|
803 |
selectors:#(a b c) |
|
804 |
receiver:someObject |
|
805 |
for:nil). |
|
806 |
v middleButtonMenu:m. |
|
807 |
v realize |
|
808 |
" |
|
809 |
! |
|
810 |
||
811 |
values |
|
812 |
"st-80 compatibility" |
|
813 |
||
814 |
^ actionValues |
|
815 |
! |
|
816 |
||
817 |
values:aValueArray |
|
818 |
"st-80 compatibility" |
|
819 |
||
820 |
actionValues := aValueArray |
|
821 |
! ! |
|
822 |
||
823 |
!PopUpMenu methodsFor:'accessing-look'! |
|
824 |
||
825 |
font:aFont |
|
826 |
menuView font:aFont |
|
827 |
! |
|
828 |
||
829 |
viewBackground:aColor |
|
830 |
"this is a kludge and will vanish ..." |
|
831 |
||
832 |
super viewBackground:aColor. |
|
833 |
menuView viewBackground:aColor |
|
834 |
! ! |
|
835 |
||
836 |
!PopUpMenu methodsFor:'accessing-mvc'! |
|
837 |
||
838 |
changeMessage |
|
839 |
"forward from my menu" |
|
840 |
||
841 |
^ menuView changeMessage |
|
842 |
! |
|
843 |
||
844 |
changeMessage:aSymbol |
|
845 |
"forward to my menu" |
|
846 |
||
847 |
menuView changeMessage:aSymbol |
|
848 |
! |
|
849 |
||
850 |
model |
|
851 |
^ menuView model |
|
852 |
! |
|
853 |
||
854 |
model:aModel |
|
855 |
menuView model:aModel |
|
856 |
! ! |
|
857 |
||
858 |
!PopUpMenu methodsFor:'deactivation'! |
|
859 |
||
860 |
hide |
|
861 |
"hide the menu - if there are any pop-up-submenus, hide them also" |
|
862 |
||
863 |
menuView hideSubmenu. |
|
864 |
windowGroup notNil ifTrue:[ |
|
865 |
windowGroup removeView:menuView. |
|
866 |
]. |
|
867 |
super hide. |
|
868 |
menuView superMenu notNil ifTrue:[ |
|
869 |
menuView superMenu regainControl |
|
870 |
]. |
|
871 |
! ! |
|
872 |
||
70 | 873 |
!PopUpMenu methodsFor:'event handling'! |
0 | 874 |
|
161 | 875 |
buttonMotion:state x:x y:y |
70 | 876 |
|p superMenu| |
7 | 877 |
|
161 | 878 |
state == 0 ifTrue:[^ self]. |
879 |
||
38 | 880 |
((x >= 0) and:[x < width]) ifTrue:[ |
59 | 881 |
((y >= 0) and:[y < height]) ifTrue:[ |
105 | 882 |
hideOnRelease := true. |
161 | 883 |
menuView buttonMotion:state x:x y:y. |
59 | 884 |
^ self |
885 |
] |
|
0 | 886 |
]. |
7 | 887 |
|
888 |
"outside of myself" |
|
70 | 889 |
superMenu := menuView superMenu. |
890 |
superMenu notNil ifTrue:[ |
|
59 | 891 |
p := device translatePoint:(x @ y) |
892 |
from:drawableId |
|
893 |
to:(menuView superMenu id). |
|
161 | 894 |
superMenu buttonMotion:state x:p x y:p y |
7 | 895 |
]. |
896 |
||
897 |
menuView subMenuShown isNil ifTrue:[ |
|
161 | 898 |
menuView pointerLeave:state. |
7 | 899 |
]. |
900 |
||
0 | 901 |
hideOnLeave ifTrue:[ |
59 | 902 |
self hide |
38 | 903 |
]. |
0 | 904 |
! |
905 |
||
105 | 906 |
buttonPress:button x:x y:y |
907 |
hideOnRelease ifTrue:[ |
|
908 |
self hide. |
|
909 |
" |
|
910 |
menuView buttonRelease:button x:x y:y. |
|
911 |
" |
|
912 |
menuView superMenu notNil ifTrue:[ |
|
913 |
menuView superMenu submenuTriggered |
|
914 |
]. |
|
915 |
menuView buttonRelease:button x:x y:y. |
|
916 |
] ifFalse:[ |
|
917 |
hideOnRelease := true. |
|
918 |
((x >= 0) and:[x < width]) ifTrue:[ |
|
919 |
((y >= 0) and:[y < height]) ifTrue:[ |
|
920 |
menuView buttonPress:button x:x y:y. |
|
921 |
^ self |
|
922 |
] |
|
923 |
]. |
|
924 |
]. |
|
925 |
! |
|
926 |
||
0 | 927 |
buttonRelease:button x:x y:y |
425 | 928 |
realized ifFalse:[^ self]. |
105 | 929 |
hideOnRelease ifFalse:[ |
425 | 930 |
^ self |
105 | 931 |
]. |
932 |
||
0 | 933 |
self hide. |
7 | 934 |
" |
935 |
menuView buttonRelease:button x:x y:y. |
|
936 |
" |
|
937 |
menuView superMenu notNil ifTrue:[ |
|
425 | 938 |
menuView superMenu submenuTriggered |
7 | 939 |
]. |
940 |
menuView buttonRelease:button x:x y:y. |
|
425 | 941 |
|
942 |
"Modified: 28.2.1996 / 13:10:10 / cg" |
|
112 | 943 |
! |
944 |
||
945 |
keyPress:key x:x y:y |
|
946 |
"/ hideOnRelease := true. |
|
425 | 947 |
x <= 0 ifTrue:[ |
948 |
"/ already redelegated |
|
949 |
^ self |
|
950 |
]. |
|
951 |
||
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
952 |
key == #Tab ifTrue:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
953 |
self hide. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
954 |
super keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
955 |
] ifFalse:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
956 |
menuView keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
957 |
]. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
958 |
|
425 | 959 |
"Modified: 28.2.1996 / 15:22:32 / cg" |
202 | 960 |
! |
961 |
||
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
|
962 |
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
|
963 |
super 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
|
964 |
device buttonStates == 0 ifTrue:[ |
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
|
965 |
hideOnRelease := false |
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
|
966 |
]. |
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
|
967 |
|
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
|
968 |
"Created: 9.2.1996 / 19:56:20 / cg" |
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
|
969 |
! |
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
|
970 |
|
202 | 971 |
pointerEnter:state x:x y:y |
972 |
"catch quick release of button" |
|
973 |
||
974 |
hideOnLeave ifTrue:[ |
|
975 |
state == 0 ifTrue:[^ self hide]. |
|
976 |
] |
|
977 |
! |
|
978 |
||
979 |
pointerLeave:state |
|
980 |
"/ menuView pointerLeave:state. |
|
981 |
"/ hideOnLeave ifTrue:[ |
|
982 |
"/ self hide |
|
983 |
"/ ]. |
|
984 |
"/ menuView superMenu notNil ifTrue:[ |
|
985 |
"/ menuView superMenu regainControl |
|
986 |
"/ ] |
|
0 | 987 |
! ! |
202 | 988 |
|
989 |
!PopUpMenu methodsFor:'initialization'! |
|
990 |
||
991 |
initEvents |
|
992 |
super initEvents. |
|
993 |
self enableEnterLeaveEvents. |
|
994 |
self enableMotionEvents. |
|
995 |
! |
|
996 |
||
997 |
initialize |
|
998 |
super initialize. |
|
999 |
||
1000 |
memorize := true. |
|
1001 |
hideOnLeave := false. |
|
1002 |
defaultHideOnRelease := DefaultHideOnRelease. |
|
1003 |
! ! |
|
1004 |
||
1005 |
!PopUpMenu methodsFor:'menuview messages'! |
|
1006 |
||
1007 |
doesNotUnderstand:aMessage |
|
1008 |
"forward all menu-view messages" |
|
1009 |
||
1010 |
(menuView respondsTo:(aMessage selector)) ifTrue:[ |
|
1011 |
^ aMessage sendTo:menuView |
|
1012 |
]. |
|
1013 |
^ super doesNotUnderstand:aMessage |
|
1014 |
! ! |
|
1015 |
||
1016 |
!PopUpMenu methodsFor:'private accessing'! |
|
1017 |
||
1018 |
menu:aMenu |
|
1019 |
"set the actual menu" |
|
1020 |
||
1021 |
menuView := aMenu. |
|
1022 |
menuView origin:(margin @ margin). |
|
1023 |
menuView borderWidth:0. |
|
1024 |
menuView masterView:self |
|
1025 |
! |
|
1026 |
||
1027 |
menuView |
|
1028 |
"return the actual menu" |
|
1029 |
||
1030 |
^ menuView |
|
1031 |
! |
|
1032 |
||
1033 |
superMenu:aMenu |
|
1034 |
"return the superMenu" |
|
1035 |
||
1036 |
menuView superMenu:aMenu |
|
1037 |
! ! |
|
1038 |
||
1039 |
!PopUpMenu methodsFor:'realization'! |
|
1040 |
||
1041 |
fixSize |
|
1042 |
"called right before the view is made visible. |
|
1043 |
adjust my size to the size of the actual menu" |
|
1044 |
||
1045 |
|extra newWidth newHeight| |
|
1046 |
||
1047 |
extra := margin * 2. |
|
1048 |
menuView resizeIfChanged. |
|
1049 |
newWidth := menuView width + extra. |
|
1050 |
newHeight := menuView height + extra. |
|
1051 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[ |
|
1052 |
self extent:(menuView width + extra) @ (menuView height + extra) |
|
1053 |
]. |
|
1054 |
super fixSize |
|
1055 |
! |
|
1056 |
||
1057 |
realize |
|
1058 |
menuView deselectWithoutRedraw. |
|
1059 |
super realize. |
|
1060 |
hideOnRelease := defaultHideOnRelease. |
|
1061 |
! ! |
|
1062 |
||
205 | 1063 |
!PopUpMenu class methodsFor:'documentation'! |
1064 |
||
1065 |
version |
|
426
bf35bf40ab11
changes for accelerator-display
Claus Gittinger <cg@exept.de>
parents:
425
diff
changeset
|
1066 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.38 1996-02-28 18:46:01 cg Exp $' |
205 | 1067 |
! ! |