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