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