author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 01:50:10 +0100 | |
changeset 193 | 6ccc226ce3a6 |
parent 174 | d80a6cc3f9b2 |
child 202 | 01f3cbb8e20e |
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 |
||
119 | 13 |
SimpleView subclass:#PullDownMenu |
128 | 14 |
instanceVariableNames:'receiver menus titles selectors activeMenuNumber |
59 | 15 |
showSeparatingLines topMargin |
16 |
fgColor bgColor activeFgColor activeBgColor |
|
63 | 17 |
onLevel offLevel edgeStyle |
133 | 18 |
keepMenu toggleKeep raiseTopWhenActivated' |
59 | 19 |
classVariableNames:'DefaultFont |
20 |
DefaultViewBackground |
|
21 |
DefaultForegroundColor |
|
22 |
DefaultBackgroundColor |
|
23 |
DefaultHilightForegroundColor |
|
24 |
DefaultHilightBackgroundColor |
|
25 |
DefaultLevel DefaultHilightLevel |
|
63 | 26 |
DefaultShadowColor DefaultLightColor |
128 | 27 |
DefaultEdgeStyle DefaultKeepMenu DefaultToggleKeep |
28 |
DefaultSeparatingLines' |
|
0 | 29 |
poolDictionaries:'' |
30 |
category:'Views-Menus' |
|
31 |
! |
|
32 |
||
3 | 33 |
!PullDownMenu class methodsFor:'documentation'! |
34 |
||
38 | 35 |
copyright |
36 |
" |
|
37 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 38 |
All Rights Reserved |
38 | 39 |
|
40 |
This software is furnished under a license and may be used |
|
41 |
only in accordance with the terms of that license and with the |
|
42 |
inclusion of the above copyright notice. This software may not |
|
43 |
be provided or otherwise made available to, or used by, any |
|
44 |
other person. No title to or ownership of the software is |
|
45 |
hereby transferred. |
|
46 |
" |
|
47 |
! |
|
48 |
||
49 |
version |
|
174
d80a6cc3f9b2
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
164
diff
changeset
|
50 |
^ '$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.26 1995-11-11 16:22:17 cg Exp $' |
38 | 51 |
! |
52 |
||
3 | 53 |
documentation |
54 |
" |
|
38 | 55 |
PullDown menu provides the top (always visible) part of these menus. |
56 |
It controls display of its menus, which become visible when one of the |
|
57 |
PullDownMenus entries is pressed. |
|
0 | 58 |
|
128 | 59 |
A PullDownMenu itself consists of a single row of labels, which activate |
60 |
a pulled menu when clicked. Entries may be empty (i.e. have no menu) |
|
61 |
and empty entries may (optionally) also perform some action when clicked. |
|
62 |
An entries selector is used as the key to define and access submenus |
|
63 |
and (for empty entries:) the selector sent to the receiver of the menu. |
|
64 |
||
38 | 65 |
Instance variables: |
0 | 66 |
|
128 | 67 |
menus <Collection> the sub menus |
68 |
||
69 |
titles <Collection> the strings in the menu |
|
70 |
||
71 |
selectors <Collection> the selectors to send to the menu- |
|
72 |
receiver (for empty pull-menus) |
|
73 |
if nil (the default), title entries |
|
74 |
do not send anything. |
|
75 |
||
110 | 76 |
activeMenuNumber <Number> the index of the currently active menu |
128 | 77 |
|
110 | 78 |
showSeparatingLines <Boolean> show separating lines between my menu-strings |
128 | 79 |
|
110 | 80 |
topMargin <Number> number of pixels at top |
128 | 81 |
|
82 |
fgColor <Color> fg color to draw passive menu-titles |
|
83 |
bgColor <Color> bg color to draw passive menu-titles |
|
84 |
||
85 |
activeFgColor <Color> fg color to draw activated menu-titles |
|
86 |
activeBgColor <Color> bg color to draw activated menu-titles |
|
87 |
||
88 |
onLevel <Integer> 3D level of entry-buttons when pressed |
|
89 |
offLevel <Integer> 3D level of entry-buttons when released |
|
90 |
||
91 |
edgeStyle <Symbol> how to draw edges |
|
92 |
||
110 | 93 |
keepmenu <Boolean> if on, pulled menu stays on click, |
94 |
till clicked again (motif & windows behavior) |
|
77 | 95 |
|
128 | 96 |
toggleKeep <Boolean> if on and keepMenu is on, |
97 |
clicking again on label closes menu |
|
98 |
||
99 |
except menus, titles and selectors, instvars are usually defined from |
|
100 |
defaults in the styleSheet; you should not care for them. |
|
101 |
||
77 | 102 |
|
103 |
StyleSheet values: |
|
104 |
||
110 | 105 |
pullDownMenuViewBackground view background Color for the menu bar |
106 |
default: menuViewBackground |
|
107 |
||
108 |
pullDownMenuForegroundColor foreground drawing color for the menu bar |
|
109 |
default: menuForegroundColor |
|
110 |
||
111 |
pullDownMenuBackgroundColor background drawing color for the menu bar |
|
112 |
default: menuBackgroundColor |
|
113 |
||
114 |
pullDownMenuHilightForegroundColor active foreground drawing color for the menu bar |
|
115 |
default: menuHilightForegroundColor |
|
116 |
||
117 |
pullDownMenuHilightBackgroundColor active background drawing color for the menu bar |
|
118 |
default: menuHilightBackgroundColor |
|
119 |
||
120 |
pullDownMenuHilightLevel level (3D only) when active |
|
121 |
default: menuHilightLevel |
|
77 | 122 |
|
110 | 123 |
pullDownMenuEdgeStyle edge style (nil or #soft) |
124 |
||
125 |
pullDownMenuKeepMenu if true, pulled menu stays open until button |
|
128 | 126 |
is pressed again outside of the item-area (motif behavior) |
110 | 127 |
if false, menu closes on release (default) |
128 |
||
129 |
pullDownMenuToggleKeep if true, pulled menu closes when an entry is pressed |
|
128 | 130 |
again. Otherwise, only press outside of the items area |
131 |
hides it. default is false |
|
110 | 132 |
|
133 |
pullDownMenuLevel level (3D only) |
|
134 |
||
135 |
pullDownMenuFont font to use for the menu bar |
|
136 |
default: menuFont |
|
128 | 137 |
|
138 |
pullDownMenuShowSeparatingLines if true, lines are drawn between items. |
|
139 |
default: false |
|
133 | 140 |
|
141 |
pullDownMenuRaiseTop if true, topview is raised whenever an entry |
|
142 |
is activated. |
|
143 |
default: true |
|
110 | 144 |
" |
145 |
! |
|
77 | 146 |
|
110 | 147 |
examples |
148 |
" |
|
128 | 149 |
|top menu| |
150 |
||
151 |
top := StandardSystemView new. |
|
152 |
top extent:300@300. |
|
153 |
||
154 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
|
155 |
menu labels:#('foo' 'bar'). |
|
156 |
menu selectors:#(foo bar). |
|
157 |
menu at:#foo |
|
158 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
159 |
selectors:#(foo1 foo2 foo3) |
|
160 |
receiver:nil. |
|
161 |
menu at:#bar |
|
162 |
putLabels:#('bar1' 'bar2' 'bar3') |
|
163 |
selectors:#(bar1 bar2 bar3) |
|
164 |
receiver:nil. |
|
165 |
top open |
|
166 |
||
167 |
||
110 | 168 |
|
128 | 169 |
empty entries are possible as selectable items (with non-nil seletor) ... |
170 |
||
171 |
|top menu| |
|
172 |
||
173 |
top := StandardSystemView new. |
|
174 |
top extent:300@300. |
|
175 |
||
176 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
|
177 |
menu labels:#('foo' 'bar' 'baz'). |
|
178 |
menu selectors:#(foo bar baz). |
|
179 |
menu at:#foo |
|
180 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
181 |
selectors:#(foo1 foo2 foo3) |
|
182 |
receiver:nil. |
|
183 |
menu at:#baz |
|
184 |
putLabels:#('baz1' 'baz2' 'baz3') |
|
185 |
selectors:#(baz1 baz2 baz3) |
|
186 |
receiver:nil. |
|
187 |
top open |
|
110 | 188 |
|
189 |
||
77 | 190 |
|
128 | 191 |
... or as separators (with nil selector) |
110 | 192 |
|
128 | 193 |
|top menu| |
194 |
||
195 |
top := StandardSystemView new. |
|
196 |
top extent:500@200. |
|
110 | 197 |
|
128 | 198 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
199 |
menu labels:#('foo' ' ' 'bar' ' baz' ' ' 'moreFoo' 'moreBar' 'moreBaz'). |
|
200 |
menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz). |
|
201 |
menu at:#foo |
|
202 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
203 |
selectors:#(foo1 foo2 foo3) |
|
204 |
receiver:nil. |
|
205 |
menu at:#bar |
|
206 |
putLabels:#('bar1' 'bar2' 'bar3') |
|
207 |
selectors:#(bar1 bar2 bar3) |
|
208 |
receiver:nil. |
|
209 |
menu at:#baz |
|
210 |
putLabels:#('baz1' 'baz2' 'baz3') |
|
211 |
selectors:#(baz1 baz2 baz3) |
|
212 |
receiver:nil. |
|
213 |
top open |
|
110 | 214 |
|
215 |
||
216 |
||
128 | 217 |
|
218 |
use the menus default height |
|
110 | 219 |
|
128 | 220 |
|top menu| |
221 |
||
222 |
top := StandardSystemView new. |
|
223 |
top extent:300@300. |
|
77 | 224 |
|
128 | 225 |
menu := PullDownMenu in:top. |
226 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
227 |
menu labels:#('foo' 'bar'). |
|
228 |
menu selectors:#(foo bar). |
|
229 |
menu at:#foo |
|
230 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
231 |
selectors:#(foo1 foo2 foo3) |
|
232 |
receiver:nil. |
|
233 |
top open |
|
110 | 234 |
|
77 | 235 |
|
110 | 236 |
|
237 |
||
128 | 238 |
although you can change the font, colors etc (as shown below) |
239 |
you should NOT do it - since if you do so, the styleSheet settings |
|
240 |
are ineffective (which users wont like probably) |
|
241 |
BTW: The styleSheet entries for below are pullDownMenuForegroundColor, |
|
242 |
pullDownMenuBackgroundColor and pullDownMenuFont |
|
110 | 243 |
|
128 | 244 |
|top menu| |
77 | 245 |
|
128 | 246 |
top := StandardSystemView new. |
247 |
menu := PullDownMenu in:top. |
|
248 |
menu font:(Font family:'courier' size:20). |
|
249 |
menu foregroundColor:Color red. |
|
250 |
menu backgroundColor:Color yellow. |
|
251 |
menu viewBackground:Color yellow. |
|
252 |
menu showSeparatingLines:true. |
|
110 | 253 |
|
128 | 254 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
255 |
menu labels:#('foo' 'bar'). |
|
256 |
menu selectors:#(foo bar). |
|
257 |
menu at:#foo |
|
258 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
259 |
selectors:#(foo1 foo2 foo3) |
|
260 |
receiver:nil. |
|
261 |
(menu menuAt:#foo) font:(Font family:'courier' size:36). |
|
262 |
top open |
|
110 | 263 |
|
264 |
||
77 | 265 |
|
128 | 266 |
you can use icons, too ... |
110 | 267 |
|
128 | 268 |
|labels top menu| |
269 |
||
270 |
top := StandardSystemView new. |
|
271 |
top extent:300@300. |
|
110 | 272 |
|
128 | 273 |
menu := PullDownMenu in:top. |
274 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
275 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16) |
|
276 |
with:'foo' |
|
277 |
with:'bar'. |
|
278 |
menu labels:labels. |
|
279 |
menu selectors:#(about foo bar). |
|
280 |
menu at:#about |
|
281 |
putLabels:#('about PullDownMenus') |
|
282 |
selectors:#(aboutMenus) |
|
283 |
receiver:nil. |
|
284 |
menu at:#foo |
|
285 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
286 |
selectors:#(foo1 foo2 foo3) |
|
287 |
receiver:nil. |
|
288 |
top open |
|
110 | 289 |
|
290 |
||
291 |
||
128 | 292 |
a concrete example (combining things described above) |
293 |
(using a Plug, since we have no application class here): |
|
294 |
||
295 |
|labels top menu textView appModel| |
|
110 | 296 |
|
128 | 297 |
appModel := Plug new. |
298 |
appModel respondTo:#quit with:[top destroy]. |
|
299 |
appModel respondTo:#showAbout with:[self information:'some info here ...']. |
|
300 |
appModel respondTo:#help with:[self information:'some help here ...']. |
|
301 |
||
302 |
top := StandardSystemView new. |
|
303 |
top extent:300@300. |
|
304 |
||
305 |
menu := PullDownMenu in:top. |
|
306 |
menu receiver:appModel. |
|
307 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
77 | 308 |
|
128 | 309 |
textView := ScrollableView forView:(EditTextView new). |
310 |
textView origin:0.0@menu height corner:1.0@1.0. |
|
311 |
top addSubView:textView. |
|
312 |
||
313 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16) |
|
314 |
with:'file' |
|
315 |
with:'edit' |
|
316 |
with:'help'. |
|
317 |
menu labels:labels. |
|
318 |
menu selectors:#(about file edit help). |
|
319 |
menu at:#about |
|
320 |
putLabels:#('about PullDownMenus') |
|
321 |
selectors:#(showAbout) |
|
322 |
receiver:appModel. |
|
323 |
menu at:#file |
|
324 |
putLabels:#('quit') |
|
325 |
selectors:#(quit) |
|
326 |
receiver:appModel. |
|
327 |
menu at:#edit |
|
328 |
putLabels:#('copy' 'cut' 'paste') |
|
329 |
selectors:#(copySelection cut paste) |
|
330 |
receiver:textView. |
|
331 |
top open |
|
3 | 332 |
" |
333 |
! ! |
|
0 | 334 |
|
59 | 335 |
!PullDownMenu class methodsFor:'defaults'! |
336 |
||
337 |
updateStyleCache |
|
110 | 338 |
"extract values from the styleSheet and cache them in class variables" |
339 |
||
133 | 340 |
|styleSheet| |
341 |
||
342 |
styleSheet := StyleSheet. |
|
343 |
||
344 |
DefaultViewBackground := styleSheet colorAt:'pullDownMenuViewBackground'. |
|
60 | 345 |
DefaultViewBackground isNil ifTrue:[ |
133 | 346 |
DefaultViewBackground := styleSheet colorAt:'menuViewBackground'. |
59 | 347 |
]. |
133 | 348 |
DefaultForegroundColor := styleSheet colorAt:'pullDownMenuForegroundColor'. |
60 | 349 |
DefaultForegroundColor isNil ifTrue:[ |
133 | 350 |
DefaultForegroundColor := styleSheet colorAt:'menuForegroundColor'. |
60 | 351 |
]. |
133 | 352 |
DefaultBackgroundColor := styleSheet colorAt:'pullDownMenuBackgroundColor'. |
60 | 353 |
DefaultBackgroundColor isNil ifTrue:[ |
77 | 354 |
DefaultViewBackground notNil ifTrue:[ |
355 |
DefaultBackgroundColor := DefaultViewBackground |
|
356 |
] ifFalse:[ |
|
133 | 357 |
DefaultBackgroundColor := styleSheet colorAt:'menuBackgroundColor'. |
77 | 358 |
] |
59 | 359 |
]. |
133 | 360 |
DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenuHilightForegroundColor'. |
60 | 361 |
DefaultHilightForegroundColor isNil ifTrue:[ |
133 | 362 |
DefaultHilightForegroundColor := styleSheet colorAt:'menuHilightForegroundColor'. |
59 | 363 |
]. |
133 | 364 |
DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenuHilightBackgroundColor'. |
60 | 365 |
DefaultHilightBackgroundColor isNil ifTrue:[ |
133 | 366 |
DefaultHilightBackgroundColor := styleSheet colorAt:'menuHilightBackgroundColor'. |
59 | 367 |
]. |
133 | 368 |
DefaultHilightLevel := styleSheet at:'pullDownMenuHilightLevel'. |
60 | 369 |
DefaultHilightLevel isNil ifTrue:[ |
133 | 370 |
DefaultHilightLevel := styleSheet at:'menuHilightLevel' default:0. |
59 | 371 |
]. |
133 | 372 |
DefaultEdgeStyle := styleSheet at:'pullDownMenuEdgeStyle'. |
373 |
DefaultKeepMenu := styleSheet at:'pullDownMenuKeepMenu' default:false. |
|
374 |
DefaultToggleKeep := styleSheet at:'pullDownMenuToggleKeep' default:false. |
|
375 |
DefaultLevel := styleSheet at:'pullDownMenuLevel' default:1. |
|
376 |
DefaultFont := styleSheet fontAt:'pullDownMenuFont'. |
|
60 | 377 |
DefaultFont isNil ifTrue:[ |
133 | 378 |
DefaultFont := styleSheet fontAt:'menuFont'. |
59 | 379 |
]. |
133 | 380 |
DefaultSeparatingLines := styleSheet at:'pullDownMenuSeparatingLines' default:false. |
110 | 381 |
|
382 |
" |
|
383 |
PullDownMenu updateStyleCache |
|
384 |
" |
|
59 | 385 |
! ! |
386 |
||
0 | 387 |
!PullDownMenu class methodsFor:'instance creation'! |
388 |
||
389 |
labels:titleArray |
|
390 |
"create and return a new PullDownMenu" |
|
391 |
||
392 |
^ self new labels:titleArray |
|
393 |
! ! |
|
394 |
||
77 | 395 |
!PullDownMenu methodsFor:'initialize / release'! |
0 | 396 |
|
397 |
initialize |
|
398 |
super initialize. |
|
399 |
||
400 |
font := font on:device. |
|
401 |
self origin:(0.0 @ 0.0) |
|
146 | 402 |
extent:(1.0 @ self preferredExtent y) |
131 | 403 |
"/ extent:(1.0 @ (font height + (font descent * 2) + topMargin)). |
0 | 404 |
! |
405 |
||
406 |
initStyle |
|
130 | 407 |
|style| |
408 |
||
0 | 409 |
super initStyle. |
410 |
||
128 | 411 |
showSeparatingLines := DefaultSeparatingLines. "/ false. |
59 | 412 |
DefaultViewBackground notNil ifTrue:[ |
60 | 413 |
viewBackground := DefaultViewBackground on:device |
59 | 414 |
]. |
415 |
||
60 | 416 |
DefaultFont notNil ifTrue:[ |
417 |
font := DefaultFont on:device |
|
418 |
]. |
|
59 | 419 |
DefaultForegroundColor notNil ifTrue:[ |
420 |
fgColor := DefaultForegroundColor |
|
421 |
] ifFalse:[ |
|
422 |
fgColor := Black. |
|
423 |
]. |
|
424 |
DefaultBackgroundColor notNil ifTrue:[ |
|
425 |
bgColor := DefaultBackgroundColor |
|
426 |
] ifFalse:[ |
|
427 |
bgColor := viewBackground. |
|
428 |
]. |
|
429 |
onLevel := DefaultHilightLevel. |
|
430 |
offLevel := DefaultLevel. |
|
21 | 431 |
|
0 | 432 |
self is3D ifTrue:[ |
59 | 433 |
device hasColors ifTrue:[ |
434 |
activeFgColor := Color name:'yellow' |
|
435 |
] ifFalse:[ |
|
436 |
activeFgColor := White |
|
437 |
]. |
|
438 |
device hasGreyscales ifTrue:[ |
|
439 |
activeBgColor := bgColor. |
|
440 |
] ifFalse:[ |
|
441 |
activeBgColor := fgColor. |
|
442 |
]. |
|
443 |
topMargin := 2. |
|
21 | 444 |
|
130 | 445 |
style := styleSheet name. |
446 |
((style == #iris) or:[style == #motif]) ifTrue:[ |
|
59 | 447 |
self level:2. |
448 |
onLevel := 2. |
|
449 |
offLevel := 0. |
|
450 |
activeFgColor := fgColor |
|
451 |
] |
|
0 | 452 |
] ifFalse:[ |
59 | 453 |
activeFgColor := bgColor. |
454 |
activeBgColor := fgColor. |
|
455 |
topMargin := 0 |
|
456 |
]. |
|
457 |
||
63 | 458 |
edgeStyle := DefaultEdgeStyle. |
459 |
keepMenu := DefaultKeepMenu. |
|
110 | 460 |
toggleKeep := DefaultToggleKeep. |
63 | 461 |
|
59 | 462 |
DefaultHilightForegroundColor notNil ifTrue:[ |
463 |
activeFgColor := DefaultHilightForegroundColor |
|
464 |
]. |
|
465 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
466 |
activeBgColor := DefaultHilightBackgroundColor |
|
0 | 467 |
]. |
59 | 468 |
DefaultShadowColor notNil ifTrue:[ |
469 |
shadowColor := DefaultShadowColor on:device |
|
470 |
]. |
|
471 |
DefaultLightColor notNil ifTrue:[ |
|
472 |
lightColor := DefaultLightColor on:device |
|
473 |
]. |
|
474 |
||
475 |
bgColor := bgColor on:device. |
|
476 |
fgColor := fgColor on:device. |
|
477 |
activeBgColor := activeBgColor on:device. |
|
478 |
activeFgColor := activeFgColor on:device. |
|
133 | 479 |
|
480 |
raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true. |
|
481 |
! |
|
482 |
||
483 |
initCursor |
|
484 |
"set up a hand cursor" |
|
485 |
||
486 |
cursor := Cursor hand |
|
0 | 487 |
! |
488 |
||
489 |
recreate |
|
128 | 490 |
"if the image was saved with an active menu, hide it" |
491 |
||
492 |
|m| |
|
115 | 493 |
|
494 |
activeMenuNumber notNil ifTrue:[ |
|
128 | 495 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
496 |
m unrealize. |
|
497 |
]. |
|
115 | 498 |
activeMenuNumber := nil. |
499 |
]. |
|
500 |
super recreate. |
|
0 | 501 |
self setMenuOrigins |
502 |
! |
|
503 |
||
504 |
create |
|
505 |
super create. |
|
506 |
self setMenuOrigins |
|
77 | 507 |
! |
508 |
||
509 |
destroy |
|
128 | 510 |
"have to destroy the menus manually here, |
511 |
since they are no real subviews of myself" |
|
512 |
||
77 | 513 |
menus notNil ifTrue:[ |
514 |
menus do:[:m | |
|
515 |
m notNil ifTrue:[m destroy] |
|
516 |
]. |
|
517 |
menus := nil |
|
110 | 518 |
]. |
115 | 519 |
activeMenuNumber := nil. |
520 |
super destroy. |
|
133 | 521 |
! |
522 |
||
523 |
superView:aView |
|
524 |
"when my superView changes, all of my menus must change as well" |
|
525 |
||
526 |
super superView:aView. |
|
527 |
menus notNil ifTrue:[ |
|
528 |
menus do:[:aMenu | |
|
529 |
aMenu notNil ifTrue:[ |
|
530 |
aMenu superView:aView |
|
531 |
] |
|
532 |
] |
|
533 |
] |
|
0 | 534 |
! ! |
535 |
||
128 | 536 |
!PullDownMenu methodsFor:'accessing-look'! |
0 | 537 |
|
538 |
showSeparatingLines:aBoolean |
|
128 | 539 |
"turn on/off drawing of separating lines. |
540 |
You should not use this method; instead leave the value as |
|
130 | 541 |
defined in the styleSheet." |
0 | 542 |
|
543 |
showSeparatingLines := aBoolean. |
|
544 |
shown ifTrue:[ |
|
128 | 545 |
self setMenuOrigins. |
59 | 546 |
self redraw |
0 | 547 |
] |
548 |
! |
|
549 |
||
128 | 550 |
font:aFont |
551 |
"set the menus font. |
|
552 |
adjusts menu-origins when font changes. |
|
553 |
You should not use this method; instead leave the value as |
|
130 | 554 |
defined in the styleSheet." |
128 | 555 |
|
556 |
aFont ~~ font ifTrue:[ |
|
557 |
super font:(aFont on:device). |
|
558 |
self height:(font height + (font descent * 2)). |
|
559 |
shown ifTrue:[ |
|
560 |
self setMenuOrigins |
|
561 |
] |
|
562 |
] |
|
563 |
! |
|
564 |
||
565 |
foregroundColor:aColor |
|
566 |
"set the foreground drawing color. |
|
567 |
You should not use this method; instead leave the value as |
|
130 | 568 |
defined in the styleSheet." |
128 | 569 |
|
570 |
fgColor := aColor on:device |
|
571 |
! |
|
572 |
||
573 |
backgroundColor:aColor |
|
574 |
"set the background drawing color. |
|
575 |
You should not use this method; instead leave the value as |
|
130 | 576 |
defined in the styleSheet." |
128 | 577 |
|
578 |
bgColor := aColor on:device |
|
579 |
! ! |
|
580 |
||
581 |
||
582 |
!PullDownMenu methodsFor:'accessing'! |
|
583 |
||
584 |
receiver:anObject |
|
585 |
"set the menu-receiver. Thats the one who gets the |
|
586 |
messages (both from myself and from my submenus). |
|
587 |
This only sets the receiver for menus which are already |
|
588 |
created - menus added later should get their receiver in |
|
589 |
the creation send." |
|
590 |
||
591 |
receiver := anObject. |
|
592 |
menus notNil ifTrue:[ |
|
593 |
menus do:[:aMenu | |
|
131 | 594 |
aMenu notNil ifTrue:[ |
595 |
aMenu receiver:anObject |
|
596 |
] |
|
128 | 597 |
] |
598 |
] |
|
599 |
! |
|
600 |
||
0 | 601 |
numberOfTitles:n |
602 |
"setup blank title-space to be filled in later" |
|
603 |
||
604 |
menus := Array new:n. |
|
605 |
titles := Array new:n |
|
606 |
! |
|
607 |
||
608 |
labels:titleArray |
|
609 |
"define the menu-titles (group-headers)" |
|
610 |
||
611 |
|numberOfLabels| |
|
612 |
||
613 |
numberOfLabels := titleArray size. |
|
614 |
menus := Array new:numberOfLabels. |
|
615 |
titles := Array new:numberOfLabels. |
|
110 | 616 |
|
617 |
titleArray keysAndValuesDo:[:index :entry | |
|
618 |
|e| |
|
619 |
||
620 |
entry isImage ifTrue:[ |
|
621 |
e := entry on:device |
|
622 |
] ifFalse:[ |
|
623 |
e := entry printString |
|
624 |
]. |
|
625 |
titles at:index put:e |
|
0 | 626 |
]. |
627 |
shown ifTrue:[ |
|
59 | 628 |
self clear. |
629 |
self redraw |
|
0 | 630 |
] |
631 |
! |
|
632 |
||
633 |
labels |
|
634 |
"return the menu-titles (group-headers)" |
|
635 |
||
636 |
^ titles |
|
637 |
! |
|
638 |
||
91 | 639 |
selectors:selectorArray |
640 |
"define the menu-selectors. These are used as accesskey only |
|
641 |
in menuAt: accesses. This makes PullDownMenu accesss |
|
642 |
somewhat more compatible to PopUpMenus." |
|
643 |
||
644 |
selectors := selectorArray. |
|
645 |
! |
|
646 |
||
164 | 647 |
labels:titleArray selectors:selectorArray |
648 |
"define the menu-titles (group-headers) and selectors. |
|
649 |
Selectors are mostly used as access keys to get to submenus later." |
|
650 |
||
651 |
self labels:titleArray. |
|
652 |
self selectors:selectorArray |
|
653 |
||
654 |
"Created: 20.10.1995 / 20:15:54 / cg" |
|
655 |
! |
|
656 |
||
657 |
menuAt:stringOrNumber |
|
0 | 658 |
"return the menu with the title; return nil if not found" |
659 |
||
660 |
|index| |
|
661 |
||
164 | 662 |
index := self indexOf:stringOrNumber. |
0 | 663 |
(index == 0) ifTrue:[^ nil]. |
664 |
^ menus at:index |
|
665 |
! |
|
666 |
||
667 |
at:aString putMenu:aMenu |
|
668 |
"set the menu under the title, aString" |
|
669 |
||
670 |
|index| |
|
671 |
||
672 |
index := self indexOf:aString. |
|
164 | 673 |
(index == 0) ifTrue:[ |
674 |
self error:'no such menu entry'. |
|
675 |
^ nil |
|
676 |
]. |
|
112 | 677 |
|
678 |
"/ not needed: |
|
679 |
"/ aMenu origin:((left + (self titleLenUpTo:index)) |
|
680 |
"/ @ |
|
681 |
"/ (height + aMenu borderWidth)). |
|
130 | 682 |
aMenu hiddenOnRealize:true. |
77 | 683 |
menus at:index put:aMenu. |
684 |
aMenu masterView:self. |
|
0 | 685 |
! |
686 |
||
687 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject |
|
688 |
"create and set the menu under the title, aString" |
|
689 |
||
690 |
|menuView| |
|
691 |
||
692 |
menuView := MenuView labels:labels |
|
59 | 693 |
selectors:selectors |
694 |
args:args |
|
695 |
receiver:anObject |
|
696 |
for:self. |
|
0 | 697 |
self at:aString putMenu:menuView |
698 |
! |
|
699 |
||
700 |
at:aString putLabels:labels selector:selector args:args receiver:anObject |
|
701 |
"create and set the menu under the title, aString" |
|
702 |
||
703 |
|menuView| |
|
704 |
||
705 |
menuView := MenuView labels:labels |
|
59 | 706 |
selector:selector |
707 |
args:args |
|
708 |
receiver:anObject |
|
709 |
for:self. |
|
0 | 710 |
self at:aString putMenu:menuView |
711 |
! |
|
712 |
||
713 |
at:aString putLabels:labels selectors:selectors receiver:anObject |
|
714 |
"create and set the menu under the title, aString" |
|
715 |
||
716 |
|menuView| |
|
717 |
||
718 |
menuView := MenuView labels:labels |
|
59 | 719 |
selectors:selectors |
720 |
receiver:anObject |
|
721 |
for:self. |
|
0 | 722 |
self at:aString putMenu:menuView |
723 |
! ! |
|
724 |
||
131 | 725 |
!PullDownMenu methodsFor:'queries'! |
726 |
||
727 |
preferredExtent |
|
146 | 728 |
|w| |
729 |
||
730 |
w := self titleLenUpTo:(titles size + 1). |
|
731 |
^ w @ (font height + (font descent * 2) "+ topMargin" + (margin*2)). |
|
131 | 732 |
! ! |
733 |
||
0 | 734 |
!PullDownMenu methodsFor:'private'! |
735 |
||
736 |
titleLenUpTo:index |
|
110 | 737 |
"answer len (in pixels) of all title-strings up-to |
738 |
(but excluding) title-index. Used to compute x-position when drawing |
|
739 |
individual entries." |
|
0 | 740 |
|
110 | 741 |
|len "{ Class: SmallInteger }" |
742 |
wSpace wSep| |
|
0 | 743 |
|
744 |
(index <= 1) ifTrue:[^ 0]. |
|
110 | 745 |
wSpace := (font widthOf:' '). |
746 |
showSeparatingLines ifTrue:[ |
|
747 |
self is3D ifTrue:[ |
|
748 |
wSep := 2 |
|
749 |
] ifFalse:[ |
|
750 |
wSep := 1 |
|
751 |
] |
|
752 |
] ifFalse:[ |
|
753 |
wSep := 0 |
|
754 |
]. |
|
755 |
||
0 | 756 |
len := 0. |
110 | 757 |
titles from:1 to:(index - 1) do:[:entry | |
758 |
|thisLength| |
|
759 |
||
760 |
entry isString ifTrue:[ |
|
761 |
thisLength := (font widthOf:entry). |
|
762 |
] ifFalse:[ |
|
763 |
thisLength := entry width |
|
764 |
]. |
|
765 |
len := len + thisLength + wSpace + wSep + wSpace. |
|
0 | 766 |
]. |
767 |
^ len |
|
768 |
! |
|
769 |
||
770 |
indexOf:stringOrNumber |
|
91 | 771 |
"return the index of the menu with title; return 0 if not found. |
772 |
stringOrNumber may be a number, a selector from the selectorArray |
|
773 |
or a string from the title array." |
|
774 |
||
775 |
|idx| |
|
0 | 776 |
|
91 | 777 |
stringOrNumber isNumber ifTrue:[ |
59 | 778 |
^ stringOrNumber |
0 | 779 |
]. |
91 | 780 |
selectors notNil ifTrue:[ |
781 |
idx := selectors indexOf:stringOrNumber. |
|
782 |
idx ~~ 0 ifTrue:[^ idx]. |
|
783 |
]. |
|
0 | 784 |
^ titles indexOf:stringOrNumber |
785 |
! |
|
786 |
||
133 | 787 |
someMenuItemLabeled:aLabel |
788 |
"find a menu item. |
|
789 |
Currently, in ST/X, instances of MenuItem are only created as dummy" |
|
790 |
||
791 |
|idx| |
|
792 |
||
793 |
idx := self indexOf:aLabel. |
|
794 |
idx ~~ 0 ifTrue:[ |
|
795 |
^ MenuItem new menu:self index:idx |
|
796 |
]. |
|
797 |
menus notNil ifTrue:[ |
|
798 |
menus do:[:aMenu | |
|
799 |
|item| |
|
800 |
||
801 |
aMenu notNil ifTrue:[ |
|
802 |
(item := aMenu someMenuItemLabeled:aLabel) notNil ifTrue:[ |
|
803 |
^ item |
|
804 |
] |
|
805 |
] |
|
806 |
] |
|
807 |
]. |
|
808 |
^ nil |
|
809 |
! |
|
810 |
||
0 | 811 |
setMenuOrigins |
812 |
"adjust origins of menus when font changes" |
|
813 |
||
814 |
(font device == device) ifTrue:[ |
|
119 | 815 |
menus keysAndValuesDo:[:index :aMenu | |
59 | 816 |
aMenu notNil ifTrue:[ |
817 |
aMenu origin:((left + (self titleLenUpTo:index)) |
|
818 |
@ |
|
819 |
(height + aMenu borderWidth)) |
|
820 |
]. |
|
821 |
] |
|
0 | 822 |
] |
110 | 823 |
! |
824 |
||
825 |
titleIndexForX:x |
|
826 |
"given a click x-position, return index in title or nil" |
|
827 |
||
828 |
|xstart "{ Class: SmallInteger }" |
|
829 |
xend "{ Class: SmallInteger }" |
|
830 |
wSpace wSep| |
|
831 |
||
832 |
wSpace := (font widthOf:' ') * 2. |
|
833 |
showSeparatingLines ifTrue:[ |
|
834 |
self is3D ifTrue:[ |
|
835 |
wSep := 2 |
|
836 |
] ifFalse:[ |
|
837 |
wSep := 1 |
|
838 |
] |
|
839 |
] ifFalse:[ |
|
840 |
wSep := 0 |
|
841 |
]. |
|
842 |
xstart := 0. |
|
843 |
1 to:(titles size) do:[:index | |
|
844 |
|entry thisLength| |
|
845 |
||
846 |
entry := titles at:index. |
|
847 |
entry isString ifTrue:[ |
|
848 |
thisLength := font widthOf:entry. |
|
849 |
] ifFalse:[ |
|
850 |
thisLength := entry width |
|
851 |
]. |
|
852 |
xend := xstart + thisLength + wSpace + wSep. |
|
853 |
(x between:xstart and:xend) ifTrue:[^ index]. |
|
854 |
xstart := xend |
|
855 |
]. |
|
856 |
^ nil |
|
0 | 857 |
! ! |
858 |
||
859 |
!PullDownMenu methodsFor:'hiding/showing menus'! |
|
860 |
||
110 | 861 |
hideActiveMenuRelease:aBoolean |
862 |
"hide currently active menu - release grab if aBoolean is true |
|
863 |
and a grab was set (keepMenu)" |
|
864 |
||
128 | 865 |
|m| |
866 |
||
110 | 867 |
activeMenuNumber notNil ifTrue:[ |
128 | 868 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
131 | 869 |
m hiddenOnRealize:true. |
128 | 870 |
m unrealize. |
871 |
]. |
|
110 | 872 |
self unHighlightActiveTitle. |
873 |
activeMenuNumber := nil |
|
874 |
]. |
|
875 |
aBoolean ifTrue:[ |
|
876 |
device ungrabPointer. |
|
877 |
self cursor:Cursor normal |
|
878 |
]. |
|
879 |
! |
|
880 |
||
881 |
hideActiveMenu |
|
882 |
"hide currently active menu - release grab if there is any grab (keepMenu)" |
|
883 |
||
884 |
^ self hideActiveMenuRelease:true |
|
885 |
! |
|
886 |
||
887 |
pullMenu:aNumber |
|
888 |
"activate a menu, return it or nil" |
|
889 |
||
131 | 890 |
|subMenu r posY| |
110 | 891 |
|
892 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false]. |
|
128 | 893 |
activeMenuNumber := aNumber. |
110 | 894 |
subMenu := menus at:aNumber. |
128 | 895 |
|
133 | 896 |
raiseTopWhenActivated ifTrue:[ |
897 |
self topView raise. |
|
898 |
]. |
|
899 |
||
128 | 900 |
(activeMenuNumber notNil |
901 |
and:[ |
|
902 |
subMenu notNil |
|
131 | 903 |
or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[ |
128 | 904 |
self highlightActiveTitle. |
905 |
]. |
|
906 |
||
110 | 907 |
subMenu notNil ifTrue:[ |
131 | 908 |
subMenu origin:((left + (self titleLenUpTo:aNumber)) |
909 |
@ |
|
910 |
(posY := height + subMenu borderWidth)). |
|
911 |
subMenu hiddenOnRealize:false. |
|
110 | 912 |
subMenu deselect. |
913 |
subMenu create. |
|
914 |
subMenu saveUnder:true. |
|
915 |
subMenu superMenu:self. |
|
131 | 916 |
|
917 |
subMenu right > (r := self right) ifTrue:[ |
|
918 |
subMenu origin:((r - subMenu width) @ posY). |
|
919 |
]. |
|
920 |
subMenu raise show. |
|
110 | 921 |
]. |
922 |
^ subMenu |
|
923 |
! |
|
924 |
||
925 |
regainControl |
|
926 |
keepMenu ifTrue:[ |
|
927 |
device grabPointerInView:self. |
|
928 |
self cursor:Cursor upRightArrow |
|
929 |
] |
|
930 |
! ! |
|
931 |
||
932 |
!PullDownMenu methodsFor:'drawing '! |
|
0 | 933 |
|
110 | 934 |
redraw |
128 | 935 |
|x "{ Class: SmallInteger }" |
110 | 936 |
y "{ Class: SmallInteger }" |
937 |
index "{ Class: SmallInteger }" |
|
133 | 938 |
wSpace clr| |
110 | 939 |
|
940 |
shown ifFalse: [ ^ self ]. |
|
941 |
titles isNil ifTrue:[^ self]. |
|
942 |
||
943 |
wSpace := (font widthOf:' '). |
|
944 |
x := 0. |
|
945 |
y := height "- 1". |
|
946 |
index := 1. |
|
947 |
titles do:[:title | |
|
948 |
self drawTitle:title x:x selected:(index == activeMenuNumber). |
|
949 |
||
950 |
title isString ifTrue:[ |
|
951 |
x := x + (font widthOf:title). |
|
952 |
] ifFalse:[ |
|
953 |
x := x + title width |
|
954 |
]. |
|
955 |
x := x + wSpace + wSpace. |
|
956 |
showSeparatingLines ifTrue:[ |
|
957 |
self is3D ifTrue:[ |
|
958 |
self paint:shadowColor. |
|
959 |
self displayLineFromX:x y:0 toX:x y:y. |
|
960 |
x := x + 1. |
|
133 | 961 |
clr := lightColor. |
110 | 962 |
] ifFalse:[ |
133 | 963 |
clr := fgColor. |
110 | 964 |
]. |
133 | 965 |
self paint:clr. |
110 | 966 |
self displayLineFromX:x y:0 toX:x y:y. |
967 |
x := x + 1 |
|
968 |
]. |
|
969 |
index := index + 1 |
|
970 |
] |
|
971 |
! |
|
972 |
||
973 |
drawTitle:stringOrImage x:x0 selected:selected |
|
164 | 974 |
|y w x wSpace fg bg map| |
133 | 975 |
|
976 |
selected ifTrue:[ |
|
977 |
fg := activeFgColor. |
|
978 |
bg := activeBgColor |
|
979 |
] ifFalse:[ |
|
980 |
fg := fgColor. |
|
981 |
bg := bgColor |
|
982 |
]. |
|
110 | 983 |
|
984 |
wSpace := font widthOf:' '. |
|
985 |
x := x0. |
|
986 |
stringOrImage isString ifTrue:[ |
|
987 |
y := ((height - (font height)) // 2) + (font ascent) "+ topMargin". |
|
988 |
w := font widthOf:stringOrImage. |
|
989 |
] ifFalse:[ |
|
990 |
y := ((height - stringOrImage height) // 2) max:0. |
|
991 |
w := stringOrImage width |
|
992 |
]. |
|
993 |
w := w + (wSpace * 2). |
|
994 |
||
133 | 995 |
self paint:bg. |
0 | 996 |
self fillRectangleX:x y:0 width:w height:height. |
997 |
||
998 |
self is3D ifTrue:[ |
|
59 | 999 |
self drawEdgesForX:x y:0 |
1000 |
width:w |
|
1001 |
height:height |
|
1002 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) |
|
0 | 1003 |
]. |
133 | 1004 |
self paint:fg. |
110 | 1005 |
x := x + wSpace. |
1006 |
stringOrImage isString ifTrue:[ |
|
1007 |
self displayString:stringOrImage x:x y:y |
|
1008 |
] ifFalse:[ |
|
164 | 1009 |
stringOrImage isImageOrForm ifTrue:[ |
1010 |
stringOrImage depth == 1 ifTrue:[ |
|
1011 |
(map := stringOrImage colorMap) notNil ifTrue:[ |
|
1012 |
self paint:(map at:2) on:(map at:1). |
|
1013 |
self displayOpaqueForm:stringOrImage x:x y:y. |
|
1014 |
^ self |
|
1015 |
] |
|
1016 |
]. |
|
1017 |
self displayForm:stringOrImage x:x y:y |
|
1018 |
] ifFalse:[ |
|
1019 |
stringOrImage displayOn:self x:x y:y |
|
1020 |
] |
|
110 | 1021 |
] |
164 | 1022 |
|
1023 |
"Modified: 20.10.1995 / 22:03:27 / cg" |
|
0 | 1024 |
! |
1025 |
||
133 | 1026 |
drawActiveTitleSelected:selected |
110 | 1027 |
|x| |
0 | 1028 |
activeMenuNumber notNil ifTrue:[ |
59 | 1029 |
x := self titleLenUpTo:activeMenuNumber. |
133 | 1030 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:selected |
0 | 1031 |
] |
1032 |
! |
|
1033 |
||
133 | 1034 |
highlightActiveTitle |
1035 |
self drawActiveTitleSelected:true |
|
1036 |
! |
|
1037 |
||
0 | 1038 |
unHighlightActiveTitle |
133 | 1039 |
self drawActiveTitleSelected:false |
110 | 1040 |
! ! |
0 | 1041 |
|
110 | 1042 |
!PullDownMenu methodsFor:'submenu notifications'! |
0 | 1043 |
|
110 | 1044 |
showActive |
128 | 1045 |
"sent by a menu to tell me that it starts to perform |
1046 |
its menu action." |
|
131 | 1047 |
|
1048 |
windowGroup notNil ifTrue:[windowGroup showCursor:Cursor wait] |
|
38 | 1049 |
! |
1050 |
||
110 | 1051 |
showPassive |
128 | 1052 |
"sent by a menu to tell me that it finished its menu-action. |
1053 |
Here, we hide the currently active menu." |
|
0 | 1054 |
|
131 | 1055 |
self hideActiveMenu. |
1056 |
windowGroup notNil ifTrue:[windowGroup restoreCursors] |
|
77 | 1057 |
! |
1058 |
||
110 | 1059 |
submenuTriggered |
1060 |
"sent by a sub-submenu to tell me that it finished its menu-action." |
|
1061 |
||
1062 |
self showPassive |
|
0 | 1063 |
! ! |
1064 |
||
70 | 1065 |
!PullDownMenu methodsFor:'event handling'! |
0 | 1066 |
|
128 | 1067 |
showNoFocus |
1068 |
"when stepping focus, hide any active menu" |
|
1069 |
||
1070 |
self hideActiveMenu. |
|
1071 |
super showNoFocus |
|
1072 |
! |
|
1073 |
||
112 | 1074 |
keyPress:key x:x y:y |
155 | 1075 |
<resource: #keyboard (#CursorLeft #CursorRight #MenuSelect)> |
1076 |
||
128 | 1077 |
|index m sel| |
112 | 1078 |
|
1079 |
" |
|
1080 |
handle CursorLeft/Right for non-mouse operation |
|
133 | 1081 |
(for example, if it has the explicit focus) |
1082 |
These will pull the previous/next menu |
|
112 | 1083 |
" |
1084 |
((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[ |
|
1085 |
activeMenuNumber isNil ifTrue:[ |
|
1086 |
index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size]. |
|
1087 |
] ifFalse:[ |
|
1088 |
(key == #CursorRight) ifTrue:[ |
|
1089 |
index := activeMenuNumber+1 |
|
1090 |
] ifFalse:[ |
|
1091 |
index := activeMenuNumber-1 |
|
1092 |
]. |
|
1093 |
index == 0 ifTrue:[index := menus size] |
|
1094 |
ifFalse:[ |
|
1095 |
index > menus size ifTrue:[index := 1] |
|
1096 |
] |
|
1097 |
]. |
|
128 | 1098 |
self pullMenu:index. |
112 | 1099 |
^ self |
1100 |
]. |
|
1101 |
||
1102 |
activeMenuNumber isNil ifTrue:[^self]. |
|
1103 |
||
1104 |
" |
|
133 | 1105 |
Return, space or the (virtual) MenuSelect key trigger |
1106 |
a menu entry (for non-submenu entries). |
|
1107 |
Otherwise, if we have a submenu open, |
|
1108 |
pass the key on to it ... |
|
112 | 1109 |
" |
1110 |
m := menus at:activeMenuNumber. |
|
128 | 1111 |
m isNil ifTrue:[ |
133 | 1112 |
(key == #Return |
1113 |
or:[key == #MenuSelect |
|
1114 |
or:[key == Character space]]) ifTrue:[ |
|
128 | 1115 |
sel := selectors at:activeMenuNumber. |
1116 |
sel notNil ifTrue:[ |
|
1117 |
receiver perform:sel |
|
1118 |
] |
|
1119 |
]. |
|
1120 |
] ifFalse:[ |
|
1121 |
m keyPress:key x:0 y:0. |
|
1122 |
]. |
|
112 | 1123 |
! |
1124 |
||
110 | 1125 |
buttonPress:button x:x y:y |
1126 |
|titleIndex activeMenu activeLeft activeTop m| |
|
0 | 1127 |
|
110 | 1128 |
device ungrabPointer. |
38 | 1129 |
|
1130 |
(y between:0 and:height) ifTrue:[ |
|
59 | 1131 |
titleIndex := self titleIndexForX:x. |
38 | 1132 |
]. |
0 | 1133 |
|
38 | 1134 |
" |
1135 |
now, titleIndex is non-nil if pressed within myself |
|
1136 |
" |
|
1137 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[ |
|
110 | 1138 |
m := self pullMenu:titleIndex. |
1139 |
(keepMenu and:[m notNil]) ifTrue:[ |
|
77 | 1140 |
device grabPointerInView:self. |
59 | 1141 |
self cursor:Cursor upRightArrow |
1142 |
] |
|
38 | 1143 |
] ifFalse:[ |
110 | 1144 |
(keepMenu and:[toggleKeep not]) ifTrue:[ |
59 | 1145 |
titleIndex == activeMenuNumber ifTrue:[ |
1146 |
"same pressed again ... stay" |
|
110 | 1147 |
device grabPointerInView:self. |
59 | 1148 |
^ self |
1149 |
]. |
|
1150 |
"moving around below" |
|
1151 |
activeMenuNumber isNil ifTrue:[^self]. |
|
1152 |
activeMenu := menus at:activeMenuNumber. |
|
1153 |
activeLeft := activeMenu left. |
|
1154 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
1155 |
activeTop := activeMenu top. |
|
1156 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
1157 |
"moving around in menu" |
|
1158 |
activeMenu buttonPress:button |
|
1159 |
x:(x - activeLeft) |
|
1160 |
y:(y - activeTop). |
|
1161 |
^ self |
|
1162 |
] |
|
1163 |
]. |
|
1164 |
]. |
|
1165 |
self hideActiveMenu |
|
0 | 1166 |
] |
1167 |
! |
|
1168 |
||
161 | 1169 |
buttonMotion:state x:x y:y |
0 | 1170 |
|titleIndex activeMenu activeLeft activeTop| |
1171 |
||
161 | 1172 |
state == 0 ifTrue:[^ self]. |
1173 |
||
116 | 1174 |
activeMenuNumber notNil ifTrue:[ |
1175 |
activeMenu := menus at:activeMenuNumber. |
|
1176 |
]. |
|
1177 |
||
0 | 1178 |
(y < height) ifTrue:[ |
59 | 1179 |
"moving around in title line" |
116 | 1180 |
activeMenu notNil ifTrue:[ |
1181 |
activeMenu selection:nil |
|
59 | 1182 |
]. |
1183 |
titleIndex := self titleIndexForX:x. |
|
1184 |
titleIndex notNil ifTrue:[ |
|
1185 |
(titleIndex ~~ activeMenuNumber) ifTrue:[ |
|
1186 |
self pullMenu:titleIndex |
|
1187 |
] |
|
128 | 1188 |
] ifFalse:[ |
1189 |
self hideActiveMenu |
|
59 | 1190 |
] |
0 | 1191 |
] ifFalse:[ |
59 | 1192 |
"moving around below" |
116 | 1193 |
activeMenu isNil ifTrue:[^self]. |
59 | 1194 |
activeLeft := activeMenu left. |
1195 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
1196 |
activeTop := activeMenu top. |
|
1197 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
1198 |
"moving around in menu" |
|
161 | 1199 |
activeMenu buttonMotion:state |
59 | 1200 |
x:(x - activeLeft) |
1201 |
y:(y - activeTop). |
|
1202 |
^ self |
|
1203 |
] |
|
1204 |
]. |
|
1205 |
"moved outside menu" |
|
1206 |
activeMenu selection:nil |
|
0 | 1207 |
] |
1208 |
! |
|
1209 |
||
1210 |
buttonRelease:button x:x y:y |
|
128 | 1211 |
|activeMenu activeLeft activeTop hideMenu sel| |
1212 |
||
1213 |
activeMenuNumber isNil ifTrue:[^self]. |
|
1214 |
activeMenu := menus at:activeMenuNumber. |
|
0 | 1215 |
|
38 | 1216 |
hideMenu := false. |
0 | 1217 |
(y >= height) ifTrue:[ |
59 | 1218 |
"release below title-line" |
1219 |
activeLeft := activeMenu left. |
|
1220 |
" |
|
1221 |
released in a submenu ? |
|
1222 |
" |
|
1223 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
1224 |
activeTop := activeMenu top. |
|
1225 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
1226 |
"release in menu" |
|
1227 |
self hideActiveMenu. |
|
1228 |
activeMenu buttonRelease:button |
|
1229 |
x:(x - activeLeft) |
|
1230 |
y:(y - activeTop). |
|
1231 |
^ self |
|
1232 |
] |
|
1233 |
]. |
|
1234 |
hideMenu := true. |
|
38 | 1235 |
] ifFalse:[ |
59 | 1236 |
y < 0 ifTrue:[ |
1237 |
hideMenu := true |
|
1238 |
] ifFalse:[ |
|
128 | 1239 |
activeMenu isNil ifTrue:[ |
131 | 1240 |
selectors notNil ifTrue:[ |
1241 |
sel := selectors at:activeMenuNumber. |
|
1242 |
sel notNil ifTrue:[ |
|
1243 |
receiver perform:sel |
|
1244 |
]. |
|
128 | 1245 |
]. |
1246 |
hideMenu := true. |
|
1247 |
] ifFalse:[ |
|
1248 |
keepMenu ifFalse:[ |
|
1249 |
hideMenu := true |
|
1250 |
] |
|
59 | 1251 |
] |
1252 |
] |
|
38 | 1253 |
]. |
1254 |
hideMenu ifTrue:[ |
|
1255 |
self hideActiveMenu. |
|
1256 |
] |
|
0 | 1257 |
! ! |