author | Claus Gittinger <cg@exept.de> |
Mon, 26 Feb 1996 23:12:42 +0100 | |
changeset 404 | 6a32f6111fce |
parent 348 | 2925bbd4f346 |
child 406 | 00b4fb72a566 |
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 |
||
38 | 170 |
Finally, you can wrap other views into a popup menu (for example, |
171 |
to implement menus with icons or other components). |
|
172 |
The view should respond to some messages sent from here (for |
|
173 |
example: #hideSubmenus, #deselectWithoutRedraw and others). |
|
174 |
Currently there is only one class in the system, which can be used |
|
175 |
this way (PatternMenu in the DrawTool demo): |
|
176 |
||
284 | 177 |
|v p| |
38 | 178 |
|
284 | 179 |
v := View new. |
180 |
p := PatternMenu new. |
|
181 |
p patterns:(Array with:Color red |
|
182 |
with:Color green |
|
183 |
with:Color blue). |
|
184 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
185 |
v open |
|
38 | 186 |
|
187 |
or try: |
|
188 |
||
284 | 189 |
|v p| |
38 | 190 |
|
284 | 191 |
v := View new. |
192 |
p := PatternMenu new. |
|
193 |
p patterns:(Array with:Color red |
|
194 |
with:Color green |
|
195 |
with:Color blue). |
|
196 |
p selectors:#value:. |
|
197 |
p receiver:[:val | v viewBackground:val. v clear]. |
|
198 |
p args:(Array with:Color red |
|
199 |
with:Color green |
|
200 |
with:Color blue). |
|
201 |
v middleButtonMenu:(PopUpMenu forMenu:p). |
|
202 |
v open |
|
38 | 203 |
|
204 |
||
205 |
ST-80 style: |
|
206 |
||
207 |
The above menus all did some message send on selection; it is |
|
208 |
also possible, to use Smalltalk-80 style menus (which return some value |
|
209 |
from their startup method): |
|
210 |
||
284 | 211 |
|m selection| |
38 | 212 |
|
284 | 213 |
m := PopUpMenu |
214 |
labels:#('one' 'two' 'three'). |
|
215 |
selection := m startUp. |
|
216 |
Transcript show:'the selection was: '; showCr:selection |
|
38 | 217 |
|
218 |
startUp will return the entries index, or 0 if there was no selection. |
|
219 |
You can also specify an array of values to be returned instead of the |
|
220 |
index: |
|
221 |
||
284 | 222 |
|m selection| |
38 | 223 |
|
284 | 224 |
m := PopUpMenu |
225 |
labels:#('one' 'two' 'three') |
|
226 |
values:#(10 20 30). |
|
227 |
selection := m startUp. |
|
228 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 229 |
|
230 |
In ST/X style menus, separating lines between entries are created |
|
231 |
by a '-'-string as its label text (and corresponding nil-entries in the |
|
232 |
selectors- and args-arrays). |
|
233 |
In ST-80, you have to pass the indices of the lines in an extra array: |
|
234 |
||
284 | 235 |
|m selection| |
38 | 236 |
|
284 | 237 |
m := PopUpMenu |
238 |
labels:#('one' 'two' 'three' 'four' 'five') |
|
239 |
lines:#(2 4). |
|
240 |
selection := m startUp. |
|
241 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 242 |
|
243 |
or: |
|
284 | 244 |
|m selection| |
38 | 245 |
|
284 | 246 |
m := PopUpMenu |
247 |
labels:#('one' 'two' 'three') |
|
248 |
lines:#(2) |
|
249 |
values:#(10 20 30). |
|
250 |
selection := m startUp. |
|
251 |
Transcript show:'the value was: '; showCr:selection |
|
38 | 252 |
|
253 |
Use whichever interface you prefer. |
|
254 |
" |
|
119 | 255 |
! ! |
256 |
||
257 |
!PopUpMenu class methodsFor:'instance creation'! |
|
38 | 258 |
|
259 |
forMenu:aMenuView |
|
260 |
"this wraps an already existing menu - allowing to put any |
|
261 |
view (not just MenuViews) into popups (for example, menus |
|
262 |
with icons, or other components). |
|
263 |
Currently, there is only one example of different menus in |
|
264 |
the system (PatternMenu in the DrawTool) which could be used |
|
265 |
this way. |
|
266 |
The view should respond to some of the menuView messages |
|
267 |
(such as hideSubmenu, deselectWithoutRedraw etc.)" |
|
268 |
||
269 |
|newMenu| |
|
270 |
||
271 |
newMenu := self onSameDeviceAs:aMenuView. |
|
272 |
newMenu addSubView:aMenuView. |
|
273 |
newMenu menu:aMenuView. |
|
274 |
^ newMenu |
|
275 |
! |
|
276 |
||
202 | 277 |
labels:labels selector:aSelector args:args receiver:anObject |
278 |
"create and return a popup menu with labels as entries. |
|
279 |
Each item will send aSelector with a corresponding argument from the |
|
280 |
args array to anObject. The menu is created on the default DIsplay" |
|
281 |
||
282 |
" |
|
283 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
284 |
" |
|
285 |
^ self labels:labels selectors:aSelector args:args receiver:anObject |
|
286 |
! |
|
287 |
||
288 |
labels:labels selector:aSelector args:args receiver:anObject for:aView |
|
289 |
"create and return a popup menu with labels as entries. |
|
290 |
Each item will send aSelector with a corresponding argument from the |
|
291 |
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
|
292 |
as aView (which is only of interest in multi-Display applications; |
202 | 293 |
typical applications can use the sibbling message without the for: argument)." |
294 |
||
295 |
" |
|
296 |
OBSOLETE protocol: #labels:selectors:... knows how to handle single-symbol selectors-arg |
|
297 |
" |
|
298 |
^ self labels:labels selectors:aSelector args:args receiver:anObject for:aView |
|
299 |
! |
|
300 |
||
301 |
labels:labels selectors:selectors |
|
302 |
"create and return a menu with label-items and selectors. The receiver |
|
303 |
will either be defined later, or not used at all (if opened via startUp)" |
|
304 |
||
305 |
^ self labels:labels selectors:selectors args:nil receiver:nil for:nil |
|
306 |
! |
|
307 |
||
308 |
labels:labels selectors:selectors args:argArray |
|
309 |
"create and return a menu with label-items and selectors. The receiver |
|
310 |
will either be defined later, or not used at all (if opened via startUp)" |
|
311 |
||
312 |
^ self labels:labels selectors:selectors args:argArray receiver:nil for:nil |
|
313 |
! |
|
314 |
||
315 |
labels:labels selectors:selectors args:args receiver:anObject |
|
316 |
"create and return a popup menu with labels as entries. |
|
317 |
Each item will send a corresponding selector:argument from the selectors- |
|
318 |
and args array to anObject. The menu is created on the default Display" |
|
319 |
||
320 |
^ self labels:labels selectors:selectors args:args receiver:anObject for:nil |
|
321 |
! |
|
322 |
||
38 | 323 |
labels:labels selectors:selectors args:args receiver:anObject for:aView |
63 | 324 |
"create and return a popup menu with labels as entries. |
325 |
Each item will send a corresponding selector:argument from the selectors- |
|
326 |
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
|
327 |
as aView (which is only of interest in multi-Display applications; |
63 | 328 |
typical applications can use the sibbling message without the for: argument)." |
329 |
||
38 | 330 |
|newMenu| |
331 |
||
332 |
newMenu := self onSameDeviceAs:aView. |
|
333 |
newMenu menu:(MenuView |
|
59 | 334 |
labels:labels |
335 |
selectors:selectors |
|
336 |
args:args |
|
337 |
receiver:anObject |
|
338 |
in:newMenu). |
|
38 | 339 |
^ newMenu |
340 |
! |
|
341 |
||
119 | 342 |
labels:labels selectors:selectors receiver:anObject |
343 |
"create and return a popup menu with labels as entries. |
|
344 |
Each item will send a message with a selector from the corresponding |
|
345 |
selectors-array. |
|
346 |
The menu is created on the default Display." |
|
347 |
||
348 |
^ self labels:labels selectors:selectors args:nil receiver:anObject for:nil |
|
63 | 349 |
! |
350 |
||
202 | 351 |
labels:labels selectors:selectors receiver:anObject for:aView |
352 |
"create and return a popup menu with labels as entries. |
|
353 |
Each item will send a corresponding selector from the selectors-array |
|
354 |
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
|
355 |
as aView (which is only of interest in multi-Display applications; |
202 | 356 |
typical applications can use the sibbling message without the for: argument)." |
63 | 357 |
|
202 | 358 |
^ self labels:labels selectors:selectors args:nil receiver:anObject for:aView |
0 | 359 |
! ! |
360 |
||
361 |
!PopUpMenu class methodsFor:'ST-80 instance creation'! |
|
362 |
||
202 | 363 |
labelArray:labels lines:lines values:values |
364 |
"ST80R4 compatibility" |
|
119 | 365 |
|
202 | 366 |
^ self labels:labels lines:lines values:values |
0 | 367 |
! |
368 |
||
119 | 369 |
labelArray:labels values:values |
370 |
"ST80R4 compatibility" |
|
371 |
||
372 |
^ self labels:labels lines:nil values:values |
|
373 |
! |
|
374 |
||
202 | 375 |
labelList:labels |
376 |
"ST80R4 compatibility: |
|
377 |
given a list consisting of group label entries (to be separated by |
|
378 |
lines), convert into standard form (using '-' for lines. |
|
379 |
" |
|
380 |
||
381 |
^ self labelList:labels values:nil |
|
119 | 382 |
|
202 | 383 |
" |
384 |
(PopUpMenu labels:#('1' '2' '3')) showAtPointer |
|
385 |
(PopUpMenu labelList:#(('1') ('2' '3'))) showAtPointer |
|
386 |
(PopUpMenu labelList:#(('1') ('2') ('3'))) showAtPointer |
|
387 |
" |
|
388 |
! |
|
389 |
||
390 |
labelList:labels lines:lines values:values |
|
391 |
"mhmh what is that ?" |
|
392 |
||
393 |
^ (self new) labels:labels lines:lines values:values |
|
119 | 394 |
! |
395 |
||
0 | 396 |
labelList:labels values:values |
119 | 397 |
"ST80R4 compatibility: |
398 |
given a list consisting of group label entries (to be separated by |
|
399 |
lines), convert into standard form (using '-' for lines. |
|
400 |
" |
|
401 |
||
402 |
|newLabels newValues lS vS first| |
|
403 |
||
404 |
newLabels := OrderedCollection new. |
|
405 |
newValues := OrderedCollection new. |
|
406 |
lS := ReadStream on:labels. |
|
407 |
values notNil ifTrue:[vS := ReadStream on:values]. |
|
408 |
first := true. |
|
409 |
[lS atEnd] whileFalse:[ |
|
410 |
|entry| |
|
411 |
||
412 |
entry := lS next. |
|
413 |
entry isCollection ifTrue:[ |
|
414 |
first ifFalse:[ |
|
415 |
newLabels add:'-'. |
|
416 |
values notNil ifTrue:[newValues add:nil] |
|
417 |
]. |
|
418 |
newLabels addAll:entry. |
|
419 |
values notNil ifTrue:[newValues addAll:(vS next:entry size)] |
|
420 |
] ifFalse:[ |
|
421 |
newLabels add:entry. |
|
422 |
values notNil ifTrue:[newValues add:(vS next)] |
|
423 |
]. |
|
424 |
first := false. |
|
425 |
]. |
|
426 |
values isNil ifTrue:[ |
|
427 |
^ self labels:newLabels |
|
428 |
]. |
|
429 |
^ self labels:newLabels values:newValues |
|
430 |
||
431 |
" |
|
432 |
(PopUpMenu labels:#('1' '2' '3') values:#(1 2 3)) showAtPointer |
|
433 |
(PopUpMenu labelList:#(('1') ('2' '3')) values:#(1 2 3)) showAtPointer |
|
434 |
(PopUpMenu labelList:#(('1') ('2') ('3')) values:#(1 2 3)) showAtPointer |
|
435 |
" |
|
436 |
! |
|
437 |
||
202 | 438 |
labels:labels |
439 |
"ST80R2 compatibility" |
|
59 | 440 |
|
202 | 441 |
^ self labels:labels lines:nil values:nil |
0 | 442 |
! |
443 |
||
202 | 444 |
labels:labels lines:lines |
445 |
"ST80R2 compatibility" |
|
0 | 446 |
|
202 | 447 |
^ self labels:labels lines:lines values:nil |
77 | 448 |
! |
449 |
||
202 | 450 |
labels:labels lines:lines values:values |
451 |
"ST80R2 compatibility" |
|
127 | 452 |
|
202 | 453 |
^ (self new) labels:labels lines:lines values:values |
77 | 454 |
! |
455 |
||
202 | 456 |
labels:labels values:values |
457 |
"ST80R2 compatibility" |
|
59 | 458 |
|
202 | 459 |
^ self labels:labels lines:nil values:values |
127 | 460 |
! ! |
461 |
||
202 | 462 |
!PopUpMenu class methodsFor:'defaults'! |
0 | 463 |
|
202 | 464 |
updateStyleCache |
465 |
DefaultHideOnRelease := StyleSheet at:#popupHideOnRelease default:true. |
|
0 | 466 |
! ! |
467 |
||
468 |
!PopUpMenu methodsFor:'ST-80 activation'! |
|
469 |
||
470 |
startUp |
|
38 | 471 |
"start the menu modal - return the selected value, |
472 |
or - if no values where specified - return the index. |
|
0 | 473 |
If nothing was selected, return 0. |
38 | 474 |
Modal - i.e. stay in the menu until finished. |
475 |
This is the ST-80 way of launching a menu." |
|
0 | 476 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
477 |
^ self startUpAt:nil |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
478 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
479 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
480 |
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
|
481 |
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
|
482 |
values:#(foo bar baz)) startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
483 |
" |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
484 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
485 |
"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
|
486 |
! |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
487 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
488 |
startUpAt:aPoint |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
489 |
"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
|
490 |
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
|
491 |
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
|
492 |
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
|
493 |
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
|
494 |
|
96 | 495 |
|return rec sel0 sel1 arg| |
63 | 496 |
|
119 | 497 |
return := 0. |
498 |
||
0 | 499 |
menuView action:[:selected | |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
500 |
|actionIndex value sel retVal| |
38 | 501 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
502 |
retVal := 0. |
95 | 503 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
504 |
menuView args isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
505 |
menuView selectors notNil ifTrue:[ |
119 | 506 |
"/ sel := menuView selectors at:selected. |
507 |
"/ sel notNil ifTrue:[sel0 := sel]. |
|
508 |
||
509 |
"/ (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
|
510 |
sel0 := menuView selectors at:selected. |
119 | 511 |
"/ ] ifFalse:[ |
512 |
"/ sel1 := menuView selectors at:selected. |
|
513 |
"/ ]. |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
514 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
515 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
516 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
517 |
actionIndex := menuView args at:selected. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
518 |
actionIndex notNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
519 |
actionValues isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
520 |
menuView selectors notNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
521 |
"/ 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
|
522 |
sel1 := menuView selectors at:selected. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
523 |
arg := actionIndex. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
524 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
525 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
526 |
retVal := actionIndex |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
527 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
528 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
529 |
retVal := actionValues at:actionIndex. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
530 |
(retVal isKindOf:PopUpMenu) ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
531 |
retVal := retVal startUp |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
532 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
533 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
534 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
535 |
"/ 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
|
536 |
menuView selectors notNil ifTrue:[ |
119 | 537 |
"/ (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
|
538 |
sel0 := menuView selectors at:selected. |
119 | 539 |
"/ ] ifFalse:[ |
540 |
"/ sel1 := menuView selectors at:selected. |
|
541 |
"/ ]. |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
542 |
"/ retVal := nil. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
543 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
544 |
] |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
545 |
]. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
546 |
return := retVal |
0 | 547 |
]. |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
548 |
aPoint isNil ifTrue:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
549 |
self showAtPointer |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
550 |
] ifFalse:[ |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
551 |
self showAt:aPoint. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
552 |
]. |
96 | 553 |
|
554 |
"/ |
|
555 |
"/ mhmh an ST/X menu started the ST-80 way |
|
556 |
"/ |
|
557 |
(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
|
558 |
rec := menuView receiver. |
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
559 |
sel0 notNil ifTrue:[ |
131 | 560 |
^ sel0 |
561 |
"/ rec perform:sel0 |
|
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
562 |
] ifFalse:[ |
131 | 563 |
^ Array with:sel1 with:arg. |
564 |
"/ 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
|
565 |
] |
95 | 566 |
]. |
63 | 567 |
^ return |
38 | 568 |
|
569 |
" |
|
63 | 570 |
Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp |
38 | 571 |
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
|
572 |
values:#(foo bar baz)) startUp |
38 | 573 |
" |
281
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
574 |
|
0f41c95fa722
added method to open menu at a particular position
Claus Gittinger <cg@exept.de>
parents:
258
diff
changeset
|
575 |
"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
|
576 |
"Modified: 10.1.1996 / 20:12:26 / cg" |
110 | 577 |
! |
578 |
||
579 |
startUpWithHeading:aString |
|
580 |
"start the menu modal - return the selected value, |
|
581 |
or - if no values where specified - return the index. |
|
582 |
If nothing was selected, return 0. |
|
583 |
Modal - i.e. stay in the menu until finished. |
|
584 |
This is the ST-80 way of launching a menu." |
|
585 |
||
586 |
defaultHideOnRelease := false. |
|
587 |
menuView labels notNil ifTrue:[ |
|
588 |
menuView labels:(Array with:aString with:'=') , menuView labels. |
|
589 |
]. |
|
590 |
menuView selectors notNil ifTrue:[ |
|
591 |
menuView selectors:(Array with:nil with:nil) , menuView selectors. |
|
592 |
]. |
|
593 |
"/ menuView disable:1; disable:2. |
|
594 |
||
595 |
^ self startUp. |
|
596 |
||
597 |
" |
|
598 |
(PopUpMenu |
|
599 |
labels:#('foo' 'bar')) |
|
600 |
startUp |
|
601 |
" |
|
602 |
" |
|
603 |
(PopUpMenu |
|
604 |
labels:#('foo' 'bar')) |
|
605 |
startUpWithHeading:'hello' |
|
606 |
" |
|
0 | 607 |
! ! |
608 |
||
202 | 609 |
!PopUpMenu methodsFor:'accessing-behavior'! |
610 |
||
611 |
hideOnLeave:aBoolean |
|
612 |
"set/clear the hideOnLeave attribute, which controls |
|
613 |
if the menu should be hidden when the pointer leaves |
|
614 |
the view (used with multiple-menus)" |
|
615 |
||
616 |
hideOnLeave := aBoolean |
|
617 |
! |
|
618 |
||
619 |
hideOnRelease:aBoolean |
|
620 |
"set/clear the hideOnRelease attribute, which controls |
|
621 |
if the menu should be hidden when the button is released" |
|
622 |
||
335
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
623 |
defaultHideOnRelease := aBoolean. |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
624 |
menuView hideOnRelease:aBoolean |
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
625 |
|
81c8965c4437
hideOnRelease fixes for COmboBox
Claus Gittinger <cg@exept.de>
parents:
284
diff
changeset
|
626 |
"Modified: 9.2.1996 / 02:06:15 / cg" |
202 | 627 |
! ! |
628 |
||
629 |
!PopUpMenu methodsFor:'accessing-items'! |
|
630 |
||
631 |
indexOf:indexOrName |
|
632 |
"return the index of a submenu - or 0 if there is none" |
|
633 |
||
634 |
^ menuView indexOf:indexOrName |
|
635 |
! |
|
636 |
||
637 |
labels |
|
638 |
"return the list of labels" |
|
639 |
||
640 |
actionLabels notNil ifTrue:[ |
|
641 |
^ actionLabels asStringCollection |
|
642 |
]. |
|
643 |
^ menuView list |
|
644 |
! |
|
645 |
||
646 |
labels:labelString lines:lineArray values:valueArray |
|
647 |
"define the menu the ST-80 way (with labels and lines defined separately)" |
|
648 |
||
649 |
|labelArray argArray convertedLabels |
|
650 |
offs dstOffs linePos| |
|
651 |
||
652 |
actionLabels := labelString. |
|
653 |
actionLines := lineArray. |
|
654 |
actionValues := valueArray. |
|
655 |
||
656 |
labelArray := labelString asStringCollection. |
|
657 |
||
658 |
convertedLabels := Array new:(labelArray size + lineArray size). |
|
659 |
argArray := Array new:(labelArray size + lineArray size). |
|
660 |
||
661 |
offs := 1. |
|
662 |
dstOffs := 1. |
|
663 |
1 to:lineArray size do:[:lineIndex | |
|
664 |
linePos := lineArray at:lineIndex. |
|
665 |
[offs <= linePos] whileTrue:[ |
|
666 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
667 |
argArray at:dstOffs put:offs. |
|
668 |
offs := offs + 1. |
|
669 |
dstOffs := dstOffs + 1 |
|
670 |
]. |
|
671 |
convertedLabels at:dstOffs put:'-'. |
|
672 |
argArray at:dstOffs put:nil. |
|
673 |
dstOffs := dstOffs + 1 |
|
674 |
]. |
|
675 |
[offs <= labelArray size] whileTrue:[ |
|
676 |
convertedLabels at:dstOffs put:(labelArray at:offs). |
|
677 |
argArray at:dstOffs put:offs. |
|
678 |
offs := offs + 1. |
|
679 |
dstOffs := dstOffs + 1 |
|
680 |
]. |
|
681 |
self menu:(MenuView |
|
682 |
labels:convertedLabels |
|
683 |
selectors:nil |
|
684 |
args:argArray |
|
685 |
receiver:nil |
|
686 |
in:self) |
|
687 |
! |
|
688 |
||
689 |
lines |
|
690 |
"st-80 compatibility" |
|
691 |
||
692 |
^ actionLines |
|
693 |
! |
|
694 |
||
695 |
numberOfItems |
|
696 |
"return the number of items in the menu" |
|
697 |
||
698 |
actionLabels notNil ifTrue:[ |
|
699 |
^ actionLabels asStringCollection size |
|
700 |
]. |
|
701 |
^ menuView list size |
|
702 |
! |
|
703 |
||
704 |
remove:indexOrName |
|
705 |
"remove a menu entry" |
|
706 |
||
707 |
menuView remove:indexOrName |
|
708 |
! |
|
709 |
||
710 |
subMenuAt:indexOrName put:aMenu |
|
711 |
"define a submenu to be shown for entry indexOrName" |
|
712 |
||
713 |
" |
|
714 |
aMenu hideOnLeave:true. |
|
715 |
" |
|
716 |
menuView subMenuAt:indexOrName put:aMenu. |
|
717 |
"tell the submenu to notify me when action is performed" |
|
718 |
aMenu superMenu:self. |
|
719 |
||
720 |
" |
|
721 |
|v m someObject| |
|
722 |
||
723 |
v := View new. |
|
724 |
m := PopUpMenu labels:#('1' '2' '3') |
|
725 |
selectors:#(one two nil) |
|
726 |
receiver:someObject |
|
727 |
for:nil. |
|
728 |
m subMenuAt:3 put:(PopUpMenu |
|
729 |
labels:#('a' 'b' 'c') |
|
730 |
selectors:#(a b c) |
|
731 |
receiver:someObject |
|
732 |
for:nil). |
|
733 |
v middleButtonMenu:m. |
|
734 |
v realize |
|
735 |
" |
|
736 |
! |
|
737 |
||
738 |
values |
|
739 |
"st-80 compatibility" |
|
740 |
||
741 |
^ actionValues |
|
742 |
! |
|
743 |
||
744 |
values:aValueArray |
|
745 |
"st-80 compatibility" |
|
746 |
||
747 |
actionValues := aValueArray |
|
748 |
! ! |
|
749 |
||
750 |
!PopUpMenu methodsFor:'accessing-look'! |
|
751 |
||
752 |
font:aFont |
|
753 |
menuView font:aFont |
|
754 |
! |
|
755 |
||
756 |
viewBackground:aColor |
|
757 |
"this is a kludge and will vanish ..." |
|
758 |
||
759 |
super viewBackground:aColor. |
|
760 |
menuView viewBackground:aColor |
|
761 |
! ! |
|
762 |
||
763 |
!PopUpMenu methodsFor:'accessing-mvc'! |
|
764 |
||
765 |
changeMessage |
|
766 |
"forward from my menu" |
|
767 |
||
768 |
^ menuView changeMessage |
|
769 |
! |
|
770 |
||
771 |
changeMessage:aSymbol |
|
772 |
"forward to my menu" |
|
773 |
||
774 |
menuView changeMessage:aSymbol |
|
775 |
! |
|
776 |
||
777 |
model |
|
778 |
^ menuView model |
|
779 |
! |
|
780 |
||
781 |
model:aModel |
|
782 |
menuView model:aModel |
|
783 |
! ! |
|
784 |
||
785 |
!PopUpMenu methodsFor:'deactivation'! |
|
786 |
||
787 |
hide |
|
788 |
"hide the menu - if there are any pop-up-submenus, hide them also" |
|
789 |
||
790 |
menuView hideSubmenu. |
|
791 |
windowGroup notNil ifTrue:[ |
|
792 |
windowGroup removeView:menuView. |
|
793 |
]. |
|
794 |
super hide. |
|
795 |
menuView superMenu notNil ifTrue:[ |
|
796 |
menuView superMenu regainControl |
|
797 |
]. |
|
798 |
! ! |
|
799 |
||
70 | 800 |
!PopUpMenu methodsFor:'event handling'! |
0 | 801 |
|
161 | 802 |
buttonMotion:state x:x y:y |
70 | 803 |
|p superMenu| |
7 | 804 |
|
161 | 805 |
state == 0 ifTrue:[^ self]. |
806 |
||
38 | 807 |
((x >= 0) and:[x < width]) ifTrue:[ |
59 | 808 |
((y >= 0) and:[y < height]) ifTrue:[ |
105 | 809 |
hideOnRelease := true. |
161 | 810 |
menuView buttonMotion:state x:x y:y. |
59 | 811 |
^ self |
812 |
] |
|
0 | 813 |
]. |
7 | 814 |
|
815 |
"outside of myself" |
|
70 | 816 |
superMenu := menuView superMenu. |
817 |
superMenu notNil ifTrue:[ |
|
59 | 818 |
p := device translatePoint:(x @ y) |
819 |
from:drawableId |
|
820 |
to:(menuView superMenu id). |
|
161 | 821 |
superMenu buttonMotion:state x:p x y:p y |
7 | 822 |
]. |
823 |
||
824 |
menuView subMenuShown isNil ifTrue:[ |
|
161 | 825 |
menuView pointerLeave:state. |
7 | 826 |
]. |
827 |
||
0 | 828 |
hideOnLeave ifTrue:[ |
59 | 829 |
self hide |
38 | 830 |
]. |
0 | 831 |
! |
832 |
||
105 | 833 |
buttonPress:button x:x y:y |
834 |
hideOnRelease ifTrue:[ |
|
835 |
self hide. |
|
836 |
" |
|
837 |
menuView buttonRelease:button x:x y:y. |
|
838 |
" |
|
839 |
menuView superMenu notNil ifTrue:[ |
|
840 |
menuView superMenu submenuTriggered |
|
841 |
]. |
|
842 |
menuView buttonRelease:button x:x y:y. |
|
843 |
] ifFalse:[ |
|
844 |
hideOnRelease := true. |
|
845 |
((x >= 0) and:[x < width]) ifTrue:[ |
|
846 |
((y >= 0) and:[y < height]) ifTrue:[ |
|
847 |
menuView buttonPress:button x:x y:y. |
|
848 |
^ self |
|
849 |
] |
|
850 |
]. |
|
851 |
]. |
|
852 |
! |
|
853 |
||
0 | 854 |
buttonRelease:button x:x y:y |
105 | 855 |
hideOnRelease ifFalse:[ |
856 |
^ self |
|
857 |
]. |
|
858 |
||
0 | 859 |
self hide. |
7 | 860 |
" |
861 |
menuView buttonRelease:button x:x y:y. |
|
862 |
" |
|
863 |
menuView superMenu notNil ifTrue:[ |
|
59 | 864 |
menuView superMenu submenuTriggered |
7 | 865 |
]. |
866 |
menuView buttonRelease:button x:x y:y. |
|
112 | 867 |
! |
868 |
||
869 |
keyPress:key x:x y:y |
|
870 |
"/ hideOnRelease := true. |
|
348
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
871 |
key == #Tab ifTrue:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
872 |
self hide. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
873 |
super keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
874 |
] ifFalse:[ |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
875 |
menuView keyPress:key x:x y:y. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
876 |
]. |
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
877 |
|
2925bbd4f346
dont forward Tab to pulled views
Claus Gittinger <cg@exept.de>
parents:
342
diff
changeset
|
878 |
"Modified: 9.2.1996 / 22:07:06 / cg" |
202 | 879 |
! |
880 |
||
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
|
881 |
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
|
882 |
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
|
883 |
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
|
884 |
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
|
885 |
]. |
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
|
886 |
|
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
|
887 |
"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
|
888 |
! |
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
|
889 |
|
202 | 890 |
pointerEnter:state x:x y:y |
891 |
"catch quick release of button" |
|
892 |
||
893 |
hideOnLeave ifTrue:[ |
|
894 |
state == 0 ifTrue:[^ self hide]. |
|
895 |
] |
|
896 |
! |
|
897 |
||
898 |
pointerLeave:state |
|
899 |
"/ menuView pointerLeave:state. |
|
900 |
"/ hideOnLeave ifTrue:[ |
|
901 |
"/ self hide |
|
902 |
"/ ]. |
|
903 |
"/ menuView superMenu notNil ifTrue:[ |
|
904 |
"/ menuView superMenu regainControl |
|
905 |
"/ ] |
|
0 | 906 |
! ! |
202 | 907 |
|
908 |
!PopUpMenu methodsFor:'initialization'! |
|
909 |
||
910 |
initEvents |
|
911 |
super initEvents. |
|
912 |
self enableEnterLeaveEvents. |
|
913 |
self enableMotionEvents. |
|
914 |
! |
|
915 |
||
916 |
initialize |
|
917 |
super initialize. |
|
918 |
||
919 |
memorize := true. |
|
920 |
hideOnLeave := false. |
|
921 |
defaultHideOnRelease := DefaultHideOnRelease. |
|
922 |
! ! |
|
923 |
||
924 |
!PopUpMenu methodsFor:'menuview messages'! |
|
925 |
||
926 |
doesNotUnderstand:aMessage |
|
927 |
"forward all menu-view messages" |
|
928 |
||
929 |
(menuView respondsTo:(aMessage selector)) ifTrue:[ |
|
930 |
^ aMessage sendTo:menuView |
|
931 |
]. |
|
932 |
^ super doesNotUnderstand:aMessage |
|
933 |
! ! |
|
934 |
||
935 |
!PopUpMenu methodsFor:'private accessing'! |
|
936 |
||
937 |
menu:aMenu |
|
938 |
"set the actual menu" |
|
939 |
||
940 |
menuView := aMenu. |
|
941 |
menuView origin:(margin @ margin). |
|
942 |
menuView borderWidth:0. |
|
943 |
menuView masterView:self |
|
944 |
! |
|
945 |
||
946 |
menuView |
|
947 |
"return the actual menu" |
|
948 |
||
949 |
^ menuView |
|
950 |
! |
|
951 |
||
952 |
superMenu:aMenu |
|
953 |
"return the superMenu" |
|
954 |
||
955 |
menuView superMenu:aMenu |
|
956 |
! ! |
|
957 |
||
958 |
!PopUpMenu methodsFor:'realization'! |
|
959 |
||
960 |
fixSize |
|
961 |
"called right before the view is made visible. |
|
962 |
adjust my size to the size of the actual menu" |
|
963 |
||
964 |
|extra newWidth newHeight| |
|
965 |
||
966 |
extra := margin * 2. |
|
967 |
menuView resizeIfChanged. |
|
968 |
newWidth := menuView width + extra. |
|
969 |
newHeight := menuView height + extra. |
|
970 |
((newWidth ~~ width) or:[newHeight ~~ height]) ifTrue:[ |
|
971 |
self extent:(menuView width + extra) @ (menuView height + extra) |
|
972 |
]. |
|
973 |
super fixSize |
|
974 |
! |
|
975 |
||
976 |
realize |
|
977 |
menuView deselectWithoutRedraw. |
|
978 |
super realize. |
|
979 |
hideOnRelease := defaultHideOnRelease. |
|
980 |
! ! |
|
981 |
||
205 | 982 |
!PopUpMenu class methodsFor:'documentation'! |
983 |
||
984 |
version |
|
404 | 985 |
^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.35 1996-02-26 22:12:42 cg Exp $' |
205 | 986 |
! ! |