author | Claus Gittinger <cg@exept.de> |
Sun, 02 Nov 1997 18:44:14 +0100 | |
changeset 601 | b0c2644b5982 |
parent 594 | 72d2c4ced8f5 |
child 608 | 0d8d910768af |
permissions | -rw-r--r-- |
388 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
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 |
||
389 | 14 |
SimpleView subclass:#MenuPanel |
390 | 15 |
instanceVariableNames:'style adornment shadowView mapTime mustRearrange superMenu |
498 | 16 |
shortKeyInset selection items groupSizes receiver enableChannel |
17 |
menuHolder enabled' |
|
390 | 18 |
classVariableNames:'InitialSelectionQuerySignal DefaultStyle DefaultAdornment |
19 |
GroupDividerSize' |
|
388 | 20 |
poolDictionaries:'' |
21 |
category:'Views-Menus' |
|
22 |
! |
|
23 |
||
24 |
Object subclass:#Item |
|
390 | 25 |
instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey |
467 | 26 |
accessCharacterPosition value label activeHelpKey submenuChannel |
571 | 27 |
disabledImage' |
388 | 28 |
classVariableNames:'HorizontalInset VerticalInset LabelRightOffset ShortcutKeyOffset |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
29 |
IndicatorOn IndicatorOff' |
388 | 30 |
poolDictionaries:'' |
31 |
privateIn:MenuPanel |
|
32 |
! |
|
33 |
||
34 |
Object subclass:#Adornment |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
35 |
instanceVariableNames:'indication accessCharacterPosition shortcutKey argument' |
388 | 36 |
classVariableNames:'' |
37 |
poolDictionaries:'' |
|
38 |
privateIn:MenuPanel::Item |
|
39 |
! |
|
40 |
||
41 |
!MenuPanel class methodsFor:'documentation'! |
|
42 |
||
43 |
copyright |
|
44 |
" |
|
45 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
46 |
All Rights Reserved |
|
47 |
||
48 |
This software is furnished under a license and may be used |
|
49 |
only in accordance with the terms of that license and with the |
|
50 |
inclusion of the above copyright notice. This software may not |
|
51 |
be provided or otherwise made available to, or used by, any |
|
52 |
other person. No title to or ownership of the software is |
|
53 |
hereby transferred. |
|
54 |
" |
|
55 |
||
56 |
! |
|
57 |
||
58 |
documentation |
|
59 |
" |
|
60 |
a menu panel used for both pull-down-menus and pop-up-menus. |
|
61 |
||
62 |
not yet finished MenuPanel class - this will eventually replace |
|
63 |
most of the MenuView and PopUpMenu stuff. |
|
64 |
(and hopefully be ST-80 compatible ...) |
|
65 |
||
502 | 66 |
To create a menu, there exists a MenuEditor which will generate |
67 |
a menu specification. |
|
68 |
||
69 |
||
388 | 70 |
[author:] |
71 |
Claus Atzkern |
|
72 |
||
73 |
[see also:] |
|
74 |
Menu |
|
75 |
MenuItem |
|
502 | 76 |
MenuEditor |
388 | 77 |
" |
78 |
||
79 |
! |
|
80 |
||
81 |
examples |
|
82 |
||
83 |
" |
|
84 |
start as PullDownMenu |
|
85 |
[exBegin] |
|
86 |
|top subView mview desc s1 s2 s3 img lbs labels| |
|
87 |
||
88 |
top := StandardSystemView new. |
|
89 |
||
436 | 90 |
mview := MenuPanel in:top. |
388 | 91 |
|
502 | 92 |
labels := #( 'foo' 'bar' 'baz' 'test' 'claus' ). |
388 | 93 |
mview level:2. |
94 |
mview verticalLayout:false. |
|
95 |
img := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
502 | 96 |
lbs := Array with:'foo' with:'bar' with:img with:'baz' with:'test' with:'ludwig'. |
388 | 97 |
mview labels:lbs. |
98 |
mview shortcutKeyAt:2 put:#Cut. |
|
99 |
mview accessCharacterPositionAt:1 put:1. |
|
100 |
mview accessCharacterPositionAt:2 put:2. |
|
101 |
||
102 |
mview enabledAt:5 put:false. |
|
103 |
mview groupSizes:#( 2 2 ). |
|
436 | 104 |
s1 := MenuPanel labels:labels. |
388 | 105 |
s1 accessCharacterPositionAt:1 put:1. |
106 |
s1 accessCharacterPositionAt:2 put:2. |
|
107 |
s1 groupSizes:#( 2 2 ). |
|
436 | 108 |
s2 := MenuPanel labels:#( '1' nil '2' '-' '3' '=' '4' ' ' '5' ). |
109 |
s3 := MenuPanel labels:lbs. |
|
388 | 110 |
|
111 |
s1 subMenuAt:2 put:s2. |
|
436 | 112 |
s1 subMenuAt:3 put:(MenuPanel labels:lbs). |
388 | 113 |
s2 subMenuAt:3 put:s3. |
436 | 114 |
s3 subMenuAt:3 put:(MenuPanel labels:labels). |
388 | 115 |
s3 shortcutKeyAt:3 put:$q. |
116 |
||
117 |
mview subMenuAt:1 put:s1. |
|
436 | 118 |
mview subMenuAt:4 put:(MenuPanel labels:lbs). |
388 | 119 |
(mview subMenuAt:4) shortcutKeyAt:3 put:#Copy. |
120 |
s1 shortcutKeyAt:1 put:#Copy. |
|
121 |
s1 shortcutKeyAt:3 put:#Paste. |
|
122 |
||
436 | 123 |
mview subMenuAt:2 put:(MenuPanel labels:labels). |
388 | 124 |
top extent:(400 @ (mview height)). |
125 |
top open. |
|
126 |
[exEnd] |
|
127 |
||
128 |
||
129 |
start as PopUpMenu |
|
130 |
[exBegin] |
|
131 |
|subView mview desc s1 s2 s3 img lbs labels| |
|
132 |
||
436 | 133 |
mview := MenuPanel new. |
502 | 134 |
labels := #( 'foo' 'bar' 'baz' ). |
388 | 135 |
mview level:2. |
136 |
||
137 |
img := Image fromFile:'bitmaps/SBrowser.xbm'. |
|
502 | 138 |
lbs := Array with:'foo' with:'bar' with:img with:'baz' with:'test'. |
388 | 139 |
mview labels:lbs. |
140 |
||
436 | 141 |
s1 := MenuPanel labels:labels. |
142 |
s2 := MenuPanel labels:#( '1' nil '2' '-' '3' '=' '4' ' ' '5' ). |
|
143 |
s3 := MenuPanel labels:lbs. |
|
388 | 144 |
s1 subMenuAt:2 put:s2. |
436 | 145 |
s1 subMenuAt:3 put:(MenuPanel labels:lbs). |
388 | 146 |
s2 subMenuAt:3 put:s3. |
436 | 147 |
s3 subMenuAt:3 put:(MenuPanel labels:labels). |
388 | 148 |
s3 shortcutKeyAt:3 put:$q. |
149 |
||
150 |
mview subMenuAt:1 put:s1. |
|
436 | 151 |
mview subMenuAt:4 put:(MenuPanel labels:lbs). |
388 | 152 |
(mview subMenuAt:4) shortcutKeyAt:3 put:#Copy. |
153 |
s1 shortcutKeyAt:1 put:#Copy. |
|
154 |
s1 shortcutKeyAt:3 put:#Paste. |
|
155 |
||
436 | 156 |
mview subMenuAt:2 put:(MenuPanel labels:labels). |
388 | 157 |
mview startUp |
158 |
[exEnd] |
|
159 |
||
160 |
||
161 |
start from menu spec |
|
162 |
[exBegin] |
|
163 |
|menu| |
|
164 |
||
436 | 165 |
menu := MenuPanel menu: |
388 | 166 |
#(#Menu #( #(#MenuItem |
167 |
#label: 'File' |
|
168 |
#submenu: |
|
169 |
#(#Menu #(#(#MenuItem #label: 'quit' #value:#quit ) |
|
170 |
(#MenuItem |
|
171 |
#label: 'edit' |
|
172 |
#submenu: |
|
173 |
#(#Menu #( #(#MenuItem #label: 'edit' #value:#edit ) |
|
174 |
#(#MenuItem #label: 'close' #value:#close) |
|
175 |
) |
|
176 |
nil |
|
177 |
nil |
|
178 |
) |
|
179 |
) |
|
180 |
#(#MenuItem #label: 'help' #value:#help ) |
|
181 |
) |
|
182 |
nil |
|
183 |
nil |
|
184 |
) |
|
185 |
) |
|
186 |
#(#MenuItem #label: 'Inspect' #value:#inspectMenu ) |
|
187 |
#(#MenuItem #label: 'Bar' |
|
188 |
#submenu: |
|
389 | 189 |
#(#Menu #( #(#MenuItem #label: 'bar 1' #value:#bar1 ) |
190 |
#(#MenuItem #label: 'bar 2' #value:#bar2 ) |
|
388 | 191 |
) |
192 |
nil |
|
389 | 193 |
nil |
388 | 194 |
) |
195 |
) |
|
196 |
) |
|
197 |
#( 2 ) |
|
198 |
nil |
|
199 |
) decodeAsLiteralArray. |
|
200 |
||
201 |
menu verticalLayout:false. |
|
202 |
Transcript showCR:(menu startUp). |
|
203 |
[exEnd] |
|
204 |
||
205 |
" |
|
206 |
||
207 |
! ! |
|
208 |
||
209 |
!MenuPanel class methodsFor:'instance creation'! |
|
210 |
||
211 |
fromSpec:aSpec |
|
212 |
^ self fromSpec:aSpec receiver:nil |
|
213 |
! |
|
214 |
||
215 |
fromSpec:aSpec receiver:aReceiver |
|
216 |
|menu| |
|
217 |
||
218 |
aSpec notNil ifTrue:[ |
|
219 |
menu := Menu new. |
|
220 |
menu fromLiteralArrayEncoding:aSpec. |
|
221 |
]. |
|
222 |
^ self menu:menu receiver:aReceiver |
|
223 |
! |
|
224 |
||
225 |
labels:labels |
|
226 |
^ self labels:labels nameKeys:nil receiver:nil |
|
227 |
! |
|
228 |
||
229 |
labels:labels nameKeys:nameKeys |
|
230 |
^ self labels:labels nameKeys:nameKeys receiver:nil |
|
231 |
! |
|
232 |
||
233 |
labels:labels nameKeys:nameKeys receiver:aReceiver |
|
234 |
|mview| |
|
235 |
||
236 |
mview := self menu:nil receiver:aReceiver. |
|
237 |
mview labels:labels. |
|
238 |
mview nameKeys:nameKeys. |
|
239 |
^ mview |
|
240 |
||
241 |
! |
|
242 |
||
502 | 243 |
labels:labels receiver:aReceiver |
244 |
^ self labels:labels nameKeys:nil receiver:aReceiver |
|
245 |
! |
|
246 |
||
388 | 247 |
menu:aMenu |
248 |
^ self menu:aMenu receiver:nil |
|
249 |
! |
|
250 |
||
251 |
menu:aMenu receiver:aReceiver |
|
252 |
|mview| |
|
253 |
||
254 |
mview := self new. |
|
255 |
mview menu:aMenu. |
|
256 |
||
257 |
"/ a menu itself may contain a receiver |
|
258 |
"/ thus we do not overwrite the receiver |
|
259 |
||
260 |
aReceiver notNil ifTrue:[ |
|
261 |
mview receiver:aReceiver |
|
262 |
]. |
|
263 |
^ mview |
|
264 |
||
265 |
! ! |
|
266 |
||
267 |
!MenuPanel class methodsFor:'class initialization'! |
|
268 |
||
269 |
initialize |
|
270 |
InitialSelectionQuerySignal isNil ifTrue:[ |
|
271 |
InitialSelectionQuerySignal := QuerySignal new. |
|
272 |
]. |
|
390 | 273 |
|
587 | 274 |
"/ self updateStyleCache. |
388 | 275 |
|
276 |
DefaultAdornment isNil ifTrue:[ |
|
277 |
DefaultAdornment := IdentityDictionary new. |
|
278 |
||
279 |
DefaultAdornment at:#showSeparatingLines put:false. |
|
390 | 280 |
DefaultAdornment at:#showGroupDivider put:true. |
281 |
DefaultAdornment at:#verticalLayout put:true. |
|
282 |
DefaultAdornment at:#item put:nil. |
|
283 |
DefaultAdornment at:#value put:nil. |
|
388 | 284 |
]. |
285 |
||
286 |
" |
|
390 | 287 |
DefaultStyle := nil. |
388 | 288 |
DefaultAdornment := nil. |
289 |
self initialize |
|
290 |
" |
|
450 | 291 |
|
292 |
"Modified: 4.7.1997 / 20:19:10 / cg" |
|
293 |
! |
|
294 |
||
295 |
updateStyleCache |
|
601 | 296 |
|fg bg fn menuStyle| |
580 | 297 |
|
450 | 298 |
DefaultStyle := IdentityDictionary new. |
299 |
||
580 | 300 |
menuStyle := MenuView styleSheet. |
301 |
||
302 |
DefaultStyle at:#foregroundColor put:(fg := menuStyle colorAt:'menu.foregroundColor' default:(Color black)). |
|
303 |
DefaultStyle at:#backgroundColor put:(bg := menuStyle colorAt:'menu.backgroundColor' default:(Color white)). |
|
304 |
DefaultStyle at:#hilightBackgroundColor put:(menuStyle colorAt:'menu.hilightBackgroundColor' default:fg). |
|
305 |
DefaultStyle at:#hilightForegroundColor put:(menuStyle colorAt:'menu.hilightForegroundColor' default:bg). |
|
306 |
DefaultStyle at:#disabledForegroundColor put:(menuStyle colorAt:'menu.disabledForegroundColor' default:(Color darkGray)). |
|
307 |
DefaultStyle at:#groupDividerSize put:(menuStyle at: 'menu.groupDividerSize' default:3). |
|
308 |
DefaultStyle at:#fitFirstPanel put:(menuStyle at: 'menu.fitFirstPanel' default:true). |
|
309 |
DefaultStyle at:#horizontalSpace put:(menuStyle at: 'menu.horizontalSpace' default:0). |
|
310 |
DefaultStyle at:#borderWidth put:(menuStyle at: 'menu.borderWidth' default:1). |
|
601 | 311 |
fn := menuStyle at:'menu.font' default:nil. |
312 |
fn isNil ifTrue:[ |
|
313 |
fn := menuStyle at:'selection.font' default:nil. |
|
314 |
]. |
|
315 |
DefaultStyle at:#font put:fn. |
|
580 | 316 |
|
317 |
" |
|
318 |
self updateStyleCache |
|
319 |
" |
|
320 |
||
321 |
"Created: / 4.7.1997 / 20:18:45 / cg" |
|
601 | 322 |
"Modified: / 1.11.1997 / 03:22:56 / cg" |
388 | 323 |
! ! |
324 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
325 |
!MenuPanel class methodsFor:'private'! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
326 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
327 |
subMenu:aSubMenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
328 |
"create a submenu; can be redifined in derived classes |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
329 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
330 |
^ (MenuPanel new) menu:aSubMenu. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
331 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
332 |
! ! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
333 |
|
389 | 334 |
!MenuPanel methodsFor:'accept'! |
335 |
||
336 |
accept |
|
337 |
"accept current selected item |
|
338 |
" |
|
510 | 339 |
^ self accept:(self selection) |
389 | 340 |
! |
341 |
||
342 |
accept:anItem |
|
343 |
"this is the topMenu: accept item |
|
344 |
" |
|
524 | 345 |
|value item tgState itemIdx recv| |
389 | 346 |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
347 |
self superMenu notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
348 |
^ self topMenu accept:anItem |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
349 |
]. |
436 | 350 |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
351 |
self selection:nil. |
420 | 352 |
self forceUngrabMouseAndKeyboard. |
353 |
||
354 |
(anItem notNil and:[anItem canAccept]) ifTrue:[ |
|
524 | 355 |
tgState := anItem toggleIndication. |
356 |
itemIdx := anItem menuPanel findFirst:[:el| el == anItem ]. |
|
357 |
item := anItem. |
|
358 |
recv := anItem menuPanel receiver. |
|
389 | 359 |
]. |
360 |
||
510 | 361 |
self isPopUpView ifFalse:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
362 |
self do:[:el| el updateIndicators]. |
524 | 363 |
self windowGroup processExposeEvents |
364 |
] ifTrue:[ |
|
365 |
self destroy |
|
366 |
]. |
|
367 |
value := self accept:item index:itemIdx toggle:tgState receiver:recv. |
|
368 |
||
369 |
self isPopUpView ifTrue:[ |
|
370 |
self menuAdornmentAt:#value put:value. |
|
371 |
self menuAdornmentAt:#item put:item |
|
372 |
]. |
|
373 |
^ item. |
|
374 |
||
375 |
! |
|
376 |
||
377 |
accept:anItem index:anIndex toggle:aState receiver:aReceiver |
|
378 |
"accept an item |
|
379 |
" |
|
545 | 380 |
|value argument numArgs isKindOfValueModel| |
524 | 381 |
|
382 |
anItem isNil ifTrue:[ |
|
383 |
self menuAdornmentAt:#hasPerformed put:true. |
|
384 |
^ nil |
|
385 |
]. |
|
386 |
||
387 |
self menuAdornmentAt:#hasPerformed put:(aReceiver isKindOf:ValueModel). |
|
388 |
||
389 |
(value := anItem value) isNil ifTrue:[ |
|
390 |
^ anIndex |
|
391 |
]. |
|
392 |
||
393 |
(argument := anItem argument) isNil ifTrue:[ |
|
394 |
argument := aState |
|
389 | 395 |
]. |
524 | 396 |
|
397 |
value isSymbol ifFalse:[ |
|
398 |
(value respondsTo:#numArgs) ifTrue:[numArgs := value numArgs] |
|
399 |
ifFalse:[numArgs := 0]. |
|
400 |
||
401 |
numArgs == 0 ifTrue:[ |
|
402 |
value value |
|
403 |
] ifFalse:[ |
|
404 |
numArgs == 1 ifTrue:[value value:argument] |
|
405 |
ifFalse:[value value:argument value:self] |
|
406 |
]. |
|
465 | 407 |
self menuAdornmentAt:#hasPerformed put:true. |
524 | 408 |
^ anIndex |
409 |
]. |
|
410 |
||
411 |
aReceiver isNil ifTrue:[ |
|
412 |
^ value |
|
413 |
]. |
|
414 |
isKindOfValueModel := aReceiver isKindOf:ValueModel. |
|
415 |
||
416 |
(numArgs := value numArgs) == 0 ifTrue:[ |
|
417 |
isKindOfValueModel ifFalse:[aReceiver perform:value] |
|
418 |
ifTrue:[aReceiver value:value] |
|
465 | 419 |
] ifFalse:[ |
524 | 420 |
numArgs == 1 ifTrue:[ |
421 |
isKindOfValueModel ifFalse:[aReceiver perform:value with:argument] |
|
422 |
ifTrue:[aReceiver value:value value:argument] |
|
423 |
] ifFalse:[ |
|
424 |
isKindOfValueModel ifFalse:[aReceiver perform:value with:argument with:self] |
|
425 |
ifTrue:[aReceiver value:value value:argument value:self] |
|
426 |
] |
|
420 | 427 |
]. |
524 | 428 |
self menuAdornmentAt:#hasPerformed put:true. |
429 |
^ value |
|
389 | 430 |
! |
431 |
||
432 |
lastItemAccepted |
|
433 |
"returns last item selected or nil |
|
434 |
" |
|
390 | 435 |
^ self topMenu menuAdornmentAt:#item |
389 | 436 |
! |
437 |
||
438 |
lastValueAccepted |
|
439 |
"returns last value accepted or nil |
|
440 |
" |
|
465 | 441 |
|top| |
442 |
||
443 |
top := self topMenu. |
|
444 |
||
445 |
(top menuAdornmentAt:#hasPerformed) ~~ true ifTrue:[ |
|
446 |
^ self topMenu menuAdornmentAt:#value. |
|
447 |
]. |
|
448 |
^ nil |
|
389 | 449 |
! ! |
450 |
||
388 | 451 |
!MenuPanel methodsFor:'accessing'! |
452 |
||
453 |
accessCharacterPositionAt:stringOrNumber |
|
390 | 454 |
"get the access character position for a textLabel |
388 | 455 |
" |
456 |
^ self itemAt:stringOrNumber do:[:el| el accessCharacterPosition ] |
|
457 |
! |
|
458 |
||
459 |
accessCharacterPositionAt:stringOrNumber put:anIndexOrNil |
|
390 | 460 |
"get the access character position for a textLabel |
388 | 461 |
" |
462 |
self itemAt:stringOrNumber do:[:el| el accessCharacterPosition:anIndexOrNil ] |
|
463 |
! |
|
464 |
||
465 |
accessCharacterPositions |
|
466 |
"returns a collection of accessCharacterPosition's or nil |
|
467 |
" |
|
468 |
^ self collect:[:anItem| anItem accessCharacterPosition ] |
|
469 |
||
470 |
! |
|
471 |
||
472 |
accessCharacterPositions:something |
|
473 |
"define accessCharacterPosition's for each item |
|
474 |
" |
|
475 |
self onEachPerform:#accessCharacterPosition: withArgList:something |
|
476 |
! |
|
477 |
||
478 |
args |
|
479 |
"returns a collection of argument's or nil |
|
480 |
" |
|
481 |
^ self collect:[:anItem| anItem argument ] |
|
482 |
! |
|
483 |
||
484 |
args:something |
|
485 |
"define arguments for each item |
|
486 |
" |
|
487 |
self onEachPerform:#argument: withArgList:something |
|
488 |
! |
|
489 |
||
490 |
argsAt:stringOrNumber |
|
491 |
"gets the argument of an item or nil |
|
492 |
" |
|
493 |
^ self itemAt:stringOrNumber do:[:el| el argument ] |
|
494 |
! |
|
495 |
||
496 |
argsAt:stringOrNumber put:anArgument |
|
497 |
"sets the argument of an item |
|
498 |
" |
|
499 |
self itemAt:stringOrNumber do:[:el| el argument:anArgument ] |
|
500 |
! |
|
501 |
||
502 |
groupSizes |
|
503 |
"gets collection of group sizes |
|
504 |
" |
|
505 |
^ groupSizes |
|
506 |
! |
|
507 |
||
508 |
groupSizes:aGroupSizes |
|
509 |
"sets collection of group sizes |
|
510 |
" |
|
511 |
aGroupSizes = groupSizes ifFalse:[ |
|
512 |
groupSizes := aGroupSizes copy. |
|
513 |
self mustRearrange. |
|
514 |
]. |
|
515 |
! |
|
516 |
||
517 |
labelAt:stringOrNumber |
|
518 |
"gets the label of an item or nil |
|
519 |
" |
|
520 |
^ self itemAt:stringOrNumber do:[:el| el label ] |
|
521 |
! |
|
522 |
||
523 |
labelAt:stringOrNumber put:aLabel |
|
524 |
"sets the label of an item |
|
525 |
" |
|
526 |
self itemAt:stringOrNumber do:[:el| el label:aLabel ] |
|
527 |
! |
|
528 |
||
529 |
labels |
|
530 |
"returns a collection of labels's or nil |
|
531 |
" |
|
532 |
^ self collect:[:anItem| anItem label ] |
|
533 |
||
534 |
! |
|
535 |
||
536 |
labels:labels |
|
537 |
"define labels for each item |
|
538 |
" |
|
539 |
self disabledRedrawDo:[ |
|
540 |
self removeAll. |
|
541 |
||
542 |
labels notNil ifTrue:[ |
|
543 |
labels do:[:aLabel|(self createAtIndex:nil) label:aLabel] |
|
544 |
] |
|
545 |
] |
|
546 |
! |
|
547 |
||
548 |
nameKeyAt:stringOrNumber |
|
549 |
"gets the nameKey of an item or nil |
|
550 |
" |
|
551 |
^ self itemAt:stringOrNumber do:[:el| el nameKey ] |
|
552 |
! |
|
553 |
||
554 |
nameKeyAt:stringOrNumber put:aNameKey |
|
555 |
"sets the nameKey of an item |
|
556 |
" |
|
557 |
self itemAt:stringOrNumber do:[:el| el nameKey:aNameKey ] |
|
558 |
! |
|
559 |
||
560 |
nameKeys |
|
561 |
"returns a collection of nameKeys's or nil |
|
562 |
" |
|
563 |
^ self collect:[:anItem| anItem nameKey ] |
|
564 |
! |
|
565 |
||
566 |
nameKeys:something |
|
567 |
"define nameKeys for each item |
|
568 |
" |
|
569 |
self onEachPerform:#nameKey: withArgList:something |
|
570 |
! |
|
571 |
||
572 |
numberOfItems |
|
573 |
"gets number of items |
|
574 |
" |
|
575 |
^ items size |
|
576 |
! |
|
577 |
||
578 |
receiver |
|
579 |
"get the menu-receiver. Thats the one who gets the messages ( both from myself and |
|
580 |
from all submenus no specific receiver is defined ). |
|
581 |
" |
|
389 | 582 |
(receiver isNil and:[superMenu notNil]) ifTrue:[ |
388 | 583 |
^ superMenu receiver |
584 |
]. |
|
389 | 585 |
^ receiver |
388 | 586 |
! |
587 |
||
588 |
receiver:anObject |
|
589 |
"set the menu-receiver. Thats the one who gets the messages ( both from myself and |
|
590 |
from all submenus no specific receiver is defined ). |
|
591 |
" |
|
389 | 592 |
receiver := anObject |
388 | 593 |
! |
594 |
||
595 |
shortcutKeyAt:stringOrNumber |
|
596 |
"gets the shortCutKey of an item or nil |
|
597 |
" |
|
598 |
^ self itemAt:stringOrNumber do:[:el| el shortcutKey ] |
|
599 |
! |
|
600 |
||
601 |
shortcutKeyAt:stringOrNumber put:aKey |
|
602 |
"sets the shortCutKey of an item |
|
603 |
" |
|
604 |
self itemAt:stringOrNumber do:[:el| el shortcutKey:aKey ] |
|
605 |
! |
|
606 |
||
607 |
shortcutKeys |
|
608 |
"returns a collection of shortcutKey's or nil |
|
609 |
" |
|
610 |
^ self collect:[:anItem| anItem shortcutKey ] |
|
611 |
||
612 |
! |
|
613 |
||
614 |
shortcutKeys:something |
|
615 |
"define shortcutKey's for each item |
|
616 |
" |
|
617 |
self onEachPerform:#shortcutKey: withArgList:something |
|
618 |
! |
|
619 |
||
620 |
valueAt:stringOrNumber |
|
621 |
"gets value of an item; a block, valueHolder, ... |
|
622 |
" |
|
623 |
^ self itemAt:stringOrNumber do:[:el| el value ] |
|
624 |
||
625 |
! |
|
626 |
||
627 |
valueAt:stringOrNumber put:someThing |
|
628 |
"sets value of an item; a block, valueHolder, ... |
|
629 |
" |
|
630 |
self itemAt:stringOrNumber do:[:el| el value:someThing ] |
|
631 |
||
632 |
||
633 |
! |
|
634 |
||
635 |
values:something |
|
636 |
"define values for each item |
|
637 |
" |
|
638 |
self onEachPerform:#value: withArgList:something |
|
639 |
! ! |
|
640 |
||
641 |
!MenuPanel methodsFor:'accessing behavior'! |
|
642 |
||
643 |
disable |
|
498 | 644 |
"disable the menu |
388 | 645 |
" |
646 |
self enabled:false |
|
647 |
! |
|
648 |
||
649 |
disableAll |
|
498 | 650 |
"disable all items; not the menu in case of enabled |
388 | 651 |
" |
498 | 652 |
self do:[:anItem| anItem enabled:false] |
388 | 653 |
! |
654 |
||
655 |
disableAll:collectionOfIndicesOrNames |
|
656 |
"disable an collection of items |
|
657 |
" |
|
658 |
collectionOfIndicesOrNames do:[:entry| self enabledAt:entry put:false ]. |
|
659 |
||
660 |
! |
|
661 |
||
662 |
enable |
|
498 | 663 |
"enable the menu |
388 | 664 |
" |
665 |
self enabled:true |
|
666 |
! |
|
667 |
||
668 |
enableAll |
|
498 | 669 |
"enable all items; not the menu in case of disabled |
388 | 670 |
" |
498 | 671 |
self do:[:anItem| anItem enabled:true] |
388 | 672 |
! |
673 |
||
674 |
enableAll:collectionOfIndicesOrNames |
|
675 |
"enable an collection of items |
|
676 |
" |
|
677 |
collectionOfIndicesOrNames do:[:entry| self enabledAt:entry put:true ]. |
|
678 |
||
679 |
! |
|
680 |
||
681 |
enabled |
|
682 |
"returns enabled state |
|
683 |
" |
|
498 | 684 |
^ enabled |
388 | 685 |
! |
686 |
||
687 |
enabled:aState |
|
688 |
"change enabled state of menu |
|
689 |
" |
|
545 | 690 |
|state| |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
691 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
692 |
state := aState ? true. |
388 | 693 |
|
498 | 694 |
self enabled == state ifTrue:[ |
695 |
^ self |
|
696 |
]. |
|
697 |
enabled := state. |
|
698 |
||
699 |
self canDrawItem ifTrue:[ |
|
700 |
self do:[:anItem| anItem enabledStateOfMenuChangedTo:enabled] |
|
701 |
]. |
|
388 | 702 |
! |
703 |
||
704 |
enabledAt:stringOrNumber |
|
705 |
"gets the enabled state of an item or false |
|
706 |
" |
|
707 |
^ self itemAt:stringOrNumber do:[:el| el enabled ] ifAbsent:false |
|
708 |
! |
|
709 |
||
710 |
enabledAt:stringOrNumber put:aState |
|
711 |
"sets the enabled state of an item |
|
712 |
" |
|
713 |
self itemAt:stringOrNumber do:[:el| el enabled:aState ] |
|
714 |
! |
|
715 |
||
716 |
isEnabled:stringOrNumber |
|
717 |
"gets the enabled state of an item or false |
|
718 |
" |
|
719 |
^ self enabledAt:stringOrNumber |
|
720 |
! ! |
|
721 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
722 |
!MenuPanel methodsFor:'accessing channels'! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
723 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
724 |
enableChannel |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
725 |
"gets a enable channel or nil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
726 |
" |
498 | 727 |
^ enableChannel |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
728 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
729 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
730 |
enableChannel:aValueHolder |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
731 |
"set my enableChannel |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
732 |
" |
498 | 733 |
enableChannel notNil ifTrue:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
734 |
enableChannel removeDependent:self |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
735 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
736 |
|
498 | 737 |
(enableChannel := aValueHolder) notNil ifTrue:[ |
738 |
enableChannel addDependent:self. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
739 |
]. |
498 | 740 |
self enabled:(enableChannel value). |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
741 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
742 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
743 |
menuHolder |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
744 |
"gets a menu holder or nil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
745 |
" |
498 | 746 |
^ menuHolder |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
747 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
748 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
749 |
menuHolder:aValueHolder |
498 | 750 |
"set my menuHolder |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
751 |
" |
498 | 752 |
menuHolder notNil ifTrue:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
753 |
menuHolder removeDependent:self |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
754 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
755 |
|
498 | 756 |
(menuHolder := aValueHolder) notNil ifTrue:[ |
757 |
menuHolder addDependent:self. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
758 |
]. |
498 | 759 |
self menu:(menuHolder value) |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
760 |
! ! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
761 |
|
390 | 762 |
!MenuPanel methodsFor:'accessing color & font'! |
763 |
||
764 |
activeBackgroundColor:aColor |
|
765 |
"set the background drawing color used to highlight selection. You should not |
|
766 |
use this method; instead leave the value as defined in the styleSheet. |
|
767 |
" |
|
580 | 768 |
self styleAt:#hilightBackgroundColor put:aColor |
769 |
||
770 |
"Modified: / 27.10.1997 / 01:40:21 / cg" |
|
390 | 771 |
! |
772 |
||
773 |
backgroundColor |
|
774 |
"return the background color |
|
775 |
" |
|
502 | 776 |
^ super viewBackground |
390 | 777 |
! |
778 |
||
779 |
backgroundColor:aColor |
|
780 |
"set the background drawing color. You should not use this method; |
|
781 |
instead leave the value as defined in the styleSheet. |
|
782 |
" |
|
502 | 783 |
super viewBackground:aColor |
390 | 784 |
! |
785 |
||
786 |
disabledForegroundColor |
|
787 |
"return the foreground color used by disabled items |
|
788 |
" |
|
789 |
^ self styleAt:#disabledForegroundColor |
|
790 |
||
791 |
! |
|
792 |
||
793 |
disabledForegroundColor:aColor |
|
794 |
"set the foregroundColor drawing color used by disabled items. You should not |
|
795 |
use this method; instead leave the value as defined in the styleSheet. |
|
796 |
" |
|
797 |
self styleAt:#disabledForegroundColor put:aColor |
|
798 |
! |
|
799 |
||
800 |
font:aFont |
|
801 |
"set the font |
|
802 |
" |
|
803 |
superMenu notNil ifTrue:[ |
|
804 |
self topMenu font:aFont |
|
805 |
] ifFalse:[ |
|
806 |
(aFont notNil and:[aFont ~~ font]) ifTrue:[ |
|
807 |
super font:(aFont on:device). |
|
808 |
self mustRearrange. |
|
809 |
] |
|
810 |
] |
|
811 |
||
812 |
||
813 |
! |
|
814 |
||
815 |
foregroundColor |
|
816 |
"return the passive foreground color |
|
817 |
" |
|
818 |
^ self styleAt:#foregroundColor |
|
819 |
||
820 |
||
821 |
! |
|
822 |
||
823 |
foregroundColor:aColor |
|
824 |
"set the foregroundColor drawing color. You should not use this method; |
|
825 |
instead leave the value as defined in the styleSheet. |
|
826 |
" |
|
827 |
self styleAt:#foregroundColor put:aColor |
|
828 |
! |
|
829 |
||
580 | 830 |
hilightBackgroundColor |
831 |
"return the background color used to highlight selections |
|
832 |
" |
|
833 |
^ self styleAt:#hilightBackgroundColor |
|
834 |
||
835 |
"Created: / 27.10.1997 / 01:39:49 / cg" |
|
836 |
! |
|
837 |
||
838 |
hilightBackgroundColor:aColor |
|
839 |
"set the background drawing color used to highlight selection. You should not |
|
840 |
use this method; instead leave the value as defined in the styleSheet. |
|
841 |
" |
|
842 |
self styleAt:#hilightBackgroundColor put:aColor |
|
843 |
||
844 |
"Created: / 27.10.1997 / 01:40:00 / cg" |
|
845 |
! |
|
846 |
||
847 |
hilightForegroundColor |
|
848 |
"return the foreground color used to highlight selections |
|
849 |
" |
|
850 |
^ self styleAt:#hilightForegroundColor |
|
851 |
||
852 |
"Created: / 27.10.1997 / 01:39:34 / cg" |
|
853 |
! |
|
854 |
||
390 | 855 |
lightColor |
856 |
"get the lightColor |
|
857 |
" |
|
858 |
^ lightColor |
|
859 |
||
860 |
||
861 |
! |
|
862 |
||
863 |
lightColor:aColor |
|
864 |
"set the light drawing color. You should not use this method; |
|
865 |
instead leave the value as defined in the styleSheet. |
|
866 |
" |
|
867 |
lightColor ~~ aColor ifTrue:[ |
|
868 |
super lightColor:aColor. |
|
869 |
||
870 |
shown ifTrue:[ |
|
871 |
self invalidate |
|
872 |
] |
|
873 |
] |
|
874 |
||
875 |
||
876 |
! |
|
877 |
||
878 |
shadowColor |
|
879 |
"get the shadowColor |
|
880 |
" |
|
881 |
^ shadowColor |
|
882 |
||
883 |
||
884 |
! |
|
885 |
||
886 |
shadowColor:aColor |
|
887 |
"set the shadow drawing color. You should not use this method; |
|
888 |
instead leave the value as defined in the styleSheet. |
|
889 |
" |
|
890 |
shadowColor ~~ aColor ifTrue:[ |
|
891 |
super shadowColor:aColor. |
|
892 |
||
893 |
shown ifTrue:[ |
|
894 |
self invalidate |
|
895 |
] |
|
896 |
] |
|
897 |
||
898 |
||
899 |
! ! |
|
900 |
||
388 | 901 |
!MenuPanel methodsFor:'accessing dimensions'! |
902 |
||
903 |
height |
|
904 |
"default height |
|
905 |
" |
|
906 |
|item| |
|
907 |
||
908 |
(explicitExtent ~~ true) ifTrue:[ |
|
909 |
(item := self itemAt:1) notNil ifTrue:[ |
|
910 |
self rearrangeItems. |
|
911 |
^ item height |
|
912 |
]. |
|
913 |
^ 4 + (font height + (font descent * 2)). |
|
914 |
]. |
|
915 |
^ super height |
|
916 |
! |
|
917 |
||
918 |
preferredExtent |
|
919 |
"compute and returns my preferred extent |
|
920 |
" |
|
921 |
|x y hasMenu shCtKey| |
|
922 |
||
923 |
self numberOfItems == 0 ifTrue:[ |
|
924 |
^ 32 @ 32 |
|
925 |
]. |
|
390 | 926 |
self isFitPanel ifTrue:[ |
927 |
x := 0 |
|
928 |
] ifFalse:[ |
|
929 |
x := groupSizes size * self groupDividerSize. |
|
930 |
]. |
|
388 | 931 |
|
932 |
self verticalLayout ifFalse:[ |
|
933 |
y := 0. |
|
934 |
||
935 |
self do:[:el||z| |
|
936 |
x := x + el preferredExtentX. |
|
937 |
y < (z := el preferredExtentY) ifTrue:[y := z] |
|
938 |
]. |
|
390 | 939 |
x := x + ((items size - 1) * self horizontalSpace). |
388 | 940 |
] ifTrue:[ |
941 |
hasMenu := false. |
|
942 |
shCtKey := 0. |
|
943 |
y := x. |
|
944 |
x := 0. |
|
945 |
||
946 |
self do:[:el| |l e| |
|
947 |
(l := el rawLabel) notNil ifTrue:[ |
|
948 |
(e := l widthOn:self) > x ifTrue:[x := e]. |
|
949 |
||
950 |
el hasSubmenu ifTrue:[hasMenu := true]. |
|
951 |
||
952 |
( (l := el shortcutKeyAsString) notNil |
|
953 |
and:[(e := l widthOn:self) > shCtKey] |
|
954 |
) ifTrue:[ |
|
955 |
shCtKey := e |
|
956 |
]. |
|
957 |
]. |
|
958 |
y := y + el preferredExtentY |
|
959 |
]. |
|
960 |
x := x + Item horizontalInset. |
|
961 |
||
962 |
(hasMenu or:[shCtKey ~~ 0]) ifTrue:[ |
|
594 | 963 |
shortKeyInset := x + Item labelRightOffset. |
964 |
x := shortKeyInset + shCtKey + ((items at:1) rightArrow width). |
|
388 | 965 |
|
966 |
(shCtKey ~~ 0 and:[hasMenu]) ifTrue:[ |
|
967 |
x := x + (Item shortcutKeyOffset) |
|
968 |
] |
|
969 |
]. |
|
970 |
x := x + Item horizontalInset. |
|
971 |
]. |
|
972 |
^ x @ y |
|
973 |
||
974 |
||
975 |
! |
|
976 |
||
977 |
shortKeyInset |
|
978 |
"left inset of shortcutKey |
|
979 |
" |
|
980 |
^ shortKeyInset |
|
981 |
! ! |
|
982 |
||
983 |
!MenuPanel methodsFor:'accessing items'! |
|
984 |
||
985 |
itemAt:stringOrNumber |
|
390 | 986 |
"returns item assigned to an index, nameKey, textLabel or value if symbol. |
987 |
If no item match nil is returned. |
|
388 | 988 |
" |
989 |
|idx| |
|
990 |
||
991 |
idx := self indexOf:stringOrNumber. |
|
992 |
(idx > 0 and:[idx <= items size]) ifTrue:[ ^ items at:idx ]. |
|
993 |
^ nil |
|
994 |
||
995 |
! |
|
996 |
||
997 |
itemAt:stringOrNumber do:aOneArgBlock |
|
998 |
"evaluate teh block for an item and return the result from the block. In case that |
|
999 |
the item not exists nil is returned |
|
1000 |
" |
|
1001 |
^ self itemAt:stringOrNumber do:aOneArgBlock ifAbsent:nil |
|
1002 |
! |
|
1003 |
||
1004 |
itemAt:stringOrNumber do:aOneArgBlock ifAbsent:exceptionBlock |
|
1005 |
"evaluate teh block for an item and return the result from the block. In case that |
|
1006 |
the item not exists the result of the exception block is returned (no arguments). |
|
1007 |
" |
|
1008 |
|item| |
|
1009 |
||
1010 |
item := self itemAt:stringOrNumber. |
|
1011 |
item notNil ifTrue:[ ^ aOneArgBlock value:item ]. |
|
1012 |
^ exceptionBlock value |
|
1013 |
! ! |
|
1014 |
||
1015 |
!MenuPanel methodsFor:'accessing look'! |
|
1016 |
||
390 | 1017 |
fitFirstPanel |
1018 |
"gets true if the first panel in the menu hierarchy must be fit |
|
1019 |
to the extent of its superView |
|
388 | 1020 |
" |
390 | 1021 |
^ self styleAt:#fitFirstPanel |
388 | 1022 |
! |
1023 |
||
390 | 1024 |
fitFirstPanel:aState |
1025 |
"sets true if the first panel in the menu hierarchy must be fit |
|
1026 |
to the extent of its superView |
|
388 | 1027 |
" |
390 | 1028 |
self styleAt:#fitFirstPanel put:aState |
388 | 1029 |
! |
1030 |
||
390 | 1031 |
groupDividerSize |
1032 |
"get the size of the group dividers |
|
388 | 1033 |
" |
390 | 1034 |
^ self styleAt:#groupDividerSize |
388 | 1035 |
! |
1036 |
||
390 | 1037 |
groupDividerSize:aSize |
1038 |
"set the size of the group dividers |
|
388 | 1039 |
" |
390 | 1040 |
self styleAt:#groupDividerSize put:aSize |
388 | 1041 |
! |
1042 |
||
390 | 1043 |
horizontalSpace |
1044 |
"get the horizontal space between to items |
|
388 | 1045 |
" |
390 | 1046 |
^ self styleAt:#horizontalSpace |
388 | 1047 |
! |
1048 |
||
390 | 1049 |
horizontalSpace:aSize |
1050 |
"set the horizontal space between to items |
|
388 | 1051 |
" |
390 | 1052 |
self styleAt:#horizontalSpace put:aSize |
388 | 1053 |
! |
1054 |
||
390 | 1055 |
showGroupDivider |
1056 |
"get the enabled flag for showing groupDiveders |
|
388 | 1057 |
" |
390 | 1058 |
^ self menuAdornmentAt:#showGroupDivider |
388 | 1059 |
! |
1060 |
||
390 | 1061 |
showGroupDivider:aState |
1062 |
"set the enabled flag for showing groupDiveders |
|
388 | 1063 |
" |
390 | 1064 |
self menuAdornmentAt:#showGroupDivider put:aState |
388 | 1065 |
! |
1066 |
||
1067 |
showSeparatingLines |
|
1068 |
"gets true if drawing of separating lines is enabled. |
|
1069 |
" |
|
390 | 1070 |
^ self menuAdornmentAt:#showSeparatingLines |
388 | 1071 |
! |
1072 |
||
390 | 1073 |
showSeparatingLines:aState |
388 | 1074 |
"turn on/off drawing of separating lines. |
1075 |
" |
|
390 | 1076 |
self menuAdornmentAt:#showSeparatingLines put:aState |
388 | 1077 |
! |
1078 |
||
1079 |
verticalLayout |
|
1080 |
"get the layout: or vertical( true ) or horizontal( false ) |
|
1081 |
" |
|
390 | 1082 |
^ self menuAdornmentAt:#verticalLayout |
388 | 1083 |
! |
1084 |
||
1085 |
verticalLayout:aState |
|
1086 |
"set the layout: or vertical( true ) or horizontal( false ) |
|
1087 |
" |
|
390 | 1088 |
self menuAdornmentAt:#verticalLayout put:aState. |
388 | 1089 |
! ! |
1090 |
||
1091 |
!MenuPanel methodsFor:'accessing submenu'! |
|
1092 |
||
1093 |
subMenuAt:stringOrNumber |
|
1094 |
"gets the submenu of an item or nil |
|
1095 |
" |
|
1096 |
^ self itemAt:stringOrNumber do:[:el| el submenu ] |
|
1097 |
! |
|
1098 |
||
1099 |
subMenuAt:stringOrNumber put:aSubMenu |
|
1100 |
"sets the submenu of an item |
|
1101 |
" |
|
1102 |
self itemAt:stringOrNumber do:[:el| el submenu:aSubMenu ] |
|
1103 |
||
1104 |
! |
|
1105 |
||
1106 |
subMenuShown |
|
1107 |
"return the currently visible submenu - or nil if there is none |
|
1108 |
" |
|
1109 |
|item| |
|
1110 |
||
1111 |
(item := self selection) notNil ifTrue:[ |
|
1112 |
^ item submenu |
|
1113 |
]. |
|
1114 |
^ nil |
|
1115 |
! ! |
|
1116 |
||
1117 |
!MenuPanel methodsFor:'activation'! |
|
1118 |
||
1119 |
hide |
|
1120 |
"hide the view, leave its modal event loop |
|
1121 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1122 |
|
388 | 1123 |
self selection:nil. |
1124 |
self unmap. |
|
1125 |
||
1126 |
||
1127 |
! |
|
1128 |
||
1129 |
show |
|
1130 |
"realize the view at its last position |
|
1131 |
" |
|
1132 |
^ self showAt:(self origin) resizing:true |
|
1133 |
||
1134 |
! |
|
1135 |
||
1136 |
showAt:aPoint |
|
1137 |
"realize the view at aPoint |
|
1138 |
" |
|
1139 |
^ self showAt:aPoint resizing:true |
|
1140 |
||
1141 |
||
1142 |
! |
|
1143 |
||
1144 |
showAt:aPoint resizing:aBoolean |
|
1145 |
"realize the view at aPoint |
|
1146 |
" |
|
1147 |
self rearrangeItems. |
|
1148 |
||
1149 |
aBoolean ifTrue:[ |
|
1150 |
self fixSize. |
|
1151 |
]. |
|
1152 |
self origin:aPoint. |
|
1153 |
self makeFullyVisible. |
|
1154 |
self openModal:[true]. "realize " |
|
1155 |
||
389 | 1156 |
^ self lastValueAccepted |
388 | 1157 |
|
1158 |
! |
|
1159 |
||
1160 |
showAtPointer |
|
1161 |
"realize the view at the current pointer position |
|
1162 |
" |
|
1163 |
^ self showAt:(device pointerPosition) resizing:true |
|
1164 |
||
1165 |
||
1166 |
! |
|
1167 |
||
1168 |
showCenteredIn:aView |
|
1169 |
"make myself visible at the screen center. |
|
1170 |
" |
|
1171 |
|top| |
|
1172 |
||
1173 |
top := aView topView. |
|
1174 |
top raise. |
|
1175 |
^ self showAt:(top origin + (aView originRelativeTo:top) + (aView extent // 2) - (self extent // 2)) |
|
1176 |
||
1177 |
||
1178 |
! |
|
1179 |
||
1180 |
startUp |
|
1181 |
"realize the menu at the current pointer position |
|
1182 |
" |
|
1183 |
^ self showAtPointer |
|
1184 |
! ! |
|
1185 |
||
434 | 1186 |
!MenuPanel methodsFor:'active help'! |
1187 |
||
1188 |
helpText |
|
1189 |
|appl item key| |
|
1190 |
||
1191 |
(item := self selection) notNil ifTrue:[ |
|
1192 |
(key := item activeHelpKey) notNil ifTrue:[ |
|
1193 |
(appl := self application) notNil ifTrue:[ |
|
1194 |
^ appl helpTextForKey:key |
|
1195 |
]. |
|
1196 |
] |
|
1197 |
]. |
|
1198 |
^ nil. |
|
1199 |
! ! |
|
1200 |
||
388 | 1201 |
!MenuPanel methodsFor:'adding & removing'! |
1202 |
||
1203 |
createAtIndex:anIndexOrNil |
|
1204 |
"create an item and add this item to the index. In case of nil the item |
|
1205 |
is added to the end. If the index is not valid nil is returned otherwise |
|
1206 |
the new created item. |
|
1207 |
" |
|
1208 |
|max item| |
|
1209 |
||
1210 |
max := (items size) + 1. |
|
1211 |
||
1212 |
anIndexOrNil notNil ifTrue:[ |
|
1213 |
(anIndexOrNil < 1 or:[anIndexOrNil > max]) ifTrue:[ |
|
1214 |
^ nil |
|
1215 |
] |
|
1216 |
]. |
|
1217 |
items isNil ifTrue:[ |
|
1218 |
items := OrderedCollection new |
|
1219 |
]. |
|
1220 |
item := Item in:self. |
|
1221 |
||
1222 |
(anIndexOrNil isNil or:[anIndexOrNil == max]) ifTrue:[ |
|
1223 |
items add:item |
|
1224 |
] ifFalse:[ |
|
1225 |
items add:item beforeIndex:anIndexOrNil |
|
1226 |
]. |
|
1227 |
^ item |
|
1228 |
! |
|
1229 |
||
1230 |
remove:stringOrNumber |
|
1231 |
"remove the first item which is assigned to stringOrNumber; |
|
1232 |
if found, remove and return it |
|
1233 |
" |
|
1234 |
|item| |
|
1235 |
||
1236 |
(item := self itemAt:stringOrNumber) notNil ifTrue:[ |
|
1237 |
items remove:item. |
|
1238 |
item destroy. |
|
1239 |
items isEmpty ifTrue:[items := nil]. |
|
1240 |
self mustRearrange. |
|
1241 |
]. |
|
1242 |
^ item |
|
1243 |
! |
|
1244 |
||
1245 |
removeAll |
|
1246 |
"remove all items and submenus |
|
1247 |
" |
|
1248 |
self disabledRedrawDo:[ |
|
1249 |
self selection:nil. |
|
1250 |
groupSizes := nil. |
|
1251 |
self do:[:el| el destroy ]. |
|
1252 |
items := nil |
|
1253 |
]. |
|
1254 |
! ! |
|
1255 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1256 |
!MenuPanel methodsFor:'change & update'! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1257 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1258 |
update:something with:aParameter from:changedObject |
498 | 1259 |
|
1260 |
changedObject == menuHolder ifTrue:[^ self menu:(menuHolder value)]. |
|
1261 |
changedObject == enableChannel ifTrue:[^ self enabled:(enableChannel value)]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1262 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1263 |
super update:something with:aParameter from:changedObject |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1264 |
! ! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1265 |
|
388 | 1266 |
!MenuPanel methodsFor:'converting'! |
1267 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1268 |
asMenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1269 |
"convert contents to menu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1270 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1271 |
|menu| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1272 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1273 |
menu := Menu new. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1274 |
menu groupSizes:groupSizes. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1275 |
self do:[:anItem| menu addItem:(anItem asMenuItem) ]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1276 |
^ menu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1277 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1278 |
|
388 | 1279 |
fromSpec:aMenuSpec |
1280 |
"build from spec |
|
1281 |
" |
|
1282 |
|menu| |
|
1283 |
||
1284 |
menu := Menu new. |
|
1285 |
menu fromLiteralArrayEncoding:aMenuSpec. |
|
1286 |
self menu:menu |
|
1287 |
||
1288 |
! |
|
1289 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1290 |
menu:aMenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1291 |
"convert to Menu |
388 | 1292 |
" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1293 |
|menu| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1294 |
|
388 | 1295 |
self disabledRedrawDo:[ |
1296 |
self removeAll. |
|
1297 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1298 |
(menu := aMenu) notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1299 |
(aMenu isCollection) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1300 |
menu := Menu new. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1301 |
menu fromLiteralArrayEncoding:aMenu. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1302 |
] ifFalse:[ |
524 | 1303 |
menu receiver notNil ifTrue:[receiver := menu receiver] |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1304 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1305 |
menu menuItems notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1306 |
menu menuItems do:[:anItem| |
388 | 1307 |
(self createAtIndex:nil) menuItem:anItem |
1308 |
] |
|
1309 |
]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1310 |
self groupSizes:(menu groupSizes). |
388 | 1311 |
] |
1312 |
] |
|
1313 |
||
1314 |
! ! |
|
1315 |
||
1316 |
!MenuPanel methodsFor:'drawing'! |
|
1317 |
||
1318 |
disabledRedrawDo:aBlock |
|
1319 |
"evaluate a block without redrawing within the block; after processing |
|
1320 |
of the block a redraw might be performed |
|
1321 |
" |
|
1322 |
|state| |
|
1323 |
||
1324 |
state := mustRearrange. |
|
1325 |
mustRearrange := true. |
|
1326 |
aBlock value. |
|
1327 |
mustRearrange := state. |
|
1328 |
self mustRearrange |
|
1329 |
! |
|
1330 |
||
1331 |
mustRearrange |
|
1332 |
"returns true if layout of items must be recomputed |
|
1333 |
" |
|
590 | 1334 |
mustRearrange == true ifFalse:[ |
388 | 1335 |
mustRearrange := true. |
1336 |
self invalidate. |
|
1337 |
] |
|
590 | 1338 |
|
1339 |
"Modified: / 29.10.1997 / 15:48:33 / cg" |
|
388 | 1340 |
! |
1341 |
||
1342 |
rearrangeItems |
|
1343 |
"recompute layout of my items |
|
1344 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1345 |
|expLast x y e grpDivSz hrzSpace layout| |
390 | 1346 |
|
1347 |
mustRearrange ifFalse:[ ^ self ]. |
|
1348 |
||
1349 |
"/ fetch font from superMenu |
|
1350 |
(superMenu notNil and:[superMenu font ~~ font]) ifTrue:[ |
|
388 | 1351 |
super font:(superMenu font on:device) |
1352 |
]. |
|
390 | 1353 |
|
1354 |
items isNil ifTrue:[ |
|
1355 |
mustRearrange := false. |
|
1356 |
^ self |
|
1357 |
]. |
|
1358 |
hrzSpace := self horizontalSpace. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1359 |
expLast := false. |
390 | 1360 |
|
1361 |
self hasGroupDividers ifTrue:[ |
|
1362 |
self isFitPanel ifFalse:[ |
|
1363 |
grpDivSz := self groupDividerSize |
|
1364 |
] ifTrue:[ |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1365 |
expLast := true. |
390 | 1366 |
x := 0. |
1367 |
e := self computeExtent. |
|
388 | 1368 |
|
1369 |
self verticalLayout ifTrue:[ |
|
390 | 1370 |
items do:[:el|x := x + el preferredExtentY]. |
1371 |
y := e y. |
|
388 | 1372 |
] ifFalse:[ |
390 | 1373 |
items do:[:el|x := x + el preferredExtentX]. |
1374 |
x := x + ((items size - 1) * hrzSpace). |
|
1375 |
y := e x. |
|
388 | 1376 |
]. |
390 | 1377 |
(grpDivSz := (y - x) // (groupSizes size)) <= 0 ifTrue:[ |
1378 |
grpDivSz := nil |
|
388 | 1379 |
] |
1380 |
] |
|
1381 |
]. |
|
390 | 1382 |
|
1383 |
(self isPopUpView or:[explicitExtent ~~ true]) ifTrue:[ |
|
1384 |
e := self preferredExtent. |
|
1385 |
||
1386 |
self isPopUpView ifFalse:[ |
|
1387 |
self verticalLayout ifTrue:[e y:1.0] |
|
1388 |
ifFalse:[e x:1.0] |
|
1389 |
]. |
|
1390 |
self extent:e |
|
1391 |
] ifFalse:[ |
|
1392 |
e := self computeExtent |
|
1393 |
]. |
|
1394 |
||
1395 |
x := 0. |
|
1396 |
y := 0. |
|
1397 |
||
1398 |
self keysAndValuesDo:[:anIndex :el||org| |
|
1399 |
org := Point x:x y:y. |
|
1400 |
||
1401 |
self verticalLayout ifTrue:[ |
|
1402 |
y := y + el preferredExtentY. |
|
1403 |
el layout:(Rectangle origin:org corner:(e x @ y)). |
|
1404 |
] ifFalse:[ |
|
1405 |
x := x + el preferredExtentX. |
|
1406 |
el layout:(Rectangle origin:org corner:(x @ e y)). |
|
1407 |
x := x + hrzSpace. |
|
1408 |
]. |
|
1409 |
||
1410 |
(grpDivSz notNil and:[self hasGroupDividerAt:anIndex]) ifTrue:[ |
|
1411 |
self verticalLayout ifTrue:[y := y + grpDivSz] |
|
1412 |
ifFalse:[x := x + grpDivSz] |
|
1413 |
] |
|
1414 |
]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1415 |
expLast ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1416 |
layout := items last layout. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1417 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1418 |
self verticalLayout ifTrue:[layout bottom:((self extent y) + 1)] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1419 |
ifFalse:[layout right:((self extent x) + 1)]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1420 |
]. |
388 | 1421 |
mustRearrange := false. |
1422 |
||
1423 |
||
1424 |
||
1425 |
||
1426 |
||
1427 |
! |
|
1428 |
||
1429 |
redrawX:x y:y width:w height:h |
|
1430 |
"redraw a rectangle |
|
1431 |
" |
|
433 | 1432 |
|start end isVrt x1 x2 y1 y2 item layout lnSz hrzInset| |
388 | 1433 |
|
1434 |
shown ifFalse:[^ self]. |
|
1435 |
||
1436 |
super redrawX:x y:y width:w height:h. |
|
1437 |
self paint:(self backgroundColor). |
|
1438 |
self clearRectangleX:x y:y width:w height:h. |
|
1439 |
||
1440 |
isVrt := self verticalLayout. |
|
1441 |
end := items size. |
|
1442 |
||
1443 |
mustRearrange ifTrue:[ |
|
389 | 1444 |
self isPopUpView not ifTrue:[ |
1445 |
explicitExtent := true |
|
1446 |
]. |
|
388 | 1447 |
self rearrangeItems. |
1448 |
start := 1 |
|
1449 |
] ifFalse:[ |
|
1450 |
end == 0 ifTrue:[ ^ self ]. |
|
1451 |
||
1452 |
isVrt ifTrue:[ |
|
1453 |
start := self findFirst:[:el| (el layout bottom) >= y ]. |
|
1454 |
start == 0 ifTrue:[ ^ self ]. |
|
1455 |
end := y + h. |
|
1456 |
end := self findLast:[:el| (el layout top) < end ]. |
|
1457 |
] ifFalse:[ |
|
1458 |
start := self findFirst:[:el| (el layout right) >= x ]. |
|
1459 |
start == 0 ifTrue:[ ^ self ]. |
|
1460 |
end := x + w. |
|
1461 |
end := self findLast:[:el| (el layout left) < end ]. |
|
1462 |
]. |
|
1463 |
||
390 | 1464 |
(start ~~ 1 and:[self hasGroupDividerAt:(start-1)]) ifTrue:[ |
388 | 1465 |
start := start - 1 |
1466 |
] |
|
1467 |
]. |
|
1468 |
||
390 | 1469 |
( self hasGroupDividers |
1470 |
and:[self showGroupDivider |
|
1471 |
and:[self isFitPanel not]] |
|
1472 |
) ifTrue:[ |
|
1473 |
lnSz := self groupDividerSize // 2 |
|
1474 |
]. |
|
433 | 1475 |
hrzInset := Item horizontalInset. |
388 | 1476 |
|
1477 |
start to:end do:[:i| |
|
1478 |
item := items at:i. |
|
1479 |
item redraw. |
|
1480 |
||
390 | 1481 |
(lnSz notNil and:[self hasGroupDividerAt:i]) ifTrue:[ |
388 | 1482 |
layout := item layout. |
1483 |
||
1484 |
isVrt ifTrue:[ |
|
433 | 1485 |
x1 := layout left + hrzInset. |
1486 |
x2 := layout right - hrzInset. |
|
388 | 1487 |
y1 := (layout bottom) + lnSz. |
1488 |
y2 := y1. |
|
1489 |
] ifFalse:[ |
|
1490 |
x1 := (layout right) + lnSz. |
|
1491 |
x2 := x1. |
|
1492 |
y1 := layout top. |
|
1493 |
y2 := layout bottom. |
|
1494 |
]. |
|
1495 |
self paint:(self shadowColor). |
|
1496 |
self displayLineFromX:x1 y:y1 toX:x2 y:y2. |
|
1497 |
self paint:(self lightColor). |
|
1498 |
||
1499 |
isVrt ifTrue:[y1 := y1 + 1. y2 := y1 ] |
|
1500 |
ifFalse:[x1 := x1 + 1. x2 := x1 ]. |
|
1501 |
||
1502 |
self displayLineFromX:x1 y:y1 toX:x2 y:y2 |
|
1503 |
] |
|
1504 |
] |
|
1505 |
||
1506 |
||
1507 |
! ! |
|
1508 |
||
1509 |
!MenuPanel methodsFor:'enumerting & searching'! |
|
1510 |
||
1511 |
collect:aOneArgBlock |
|
1512 |
"evaluate the argument, aOneArgBlock for every item in the menuPanel |
|
1513 |
and return a collection of the results |
|
1514 |
" |
|
1515 |
items notNil ifTrue:[^ items collect:aOneArgBlock ]. |
|
1516 |
^ nil |
|
1517 |
||
1518 |
! |
|
1519 |
||
1520 |
do:aOneArgBlock |
|
1521 |
"evaluate the argument, aOneArgBlock for every item in the menuPanel. |
|
1522 |
" |
|
1523 |
items notNil ifTrue:[ items do:aOneArgBlock ]. |
|
1524 |
||
1525 |
! |
|
1526 |
||
1527 |
findFirst:aOneArgBlock |
|
1528 |
"find the first item, for which evaluation of the argument, aOneArgBlock |
|
1529 |
returns true; return its index or 0 if none detected. |
|
1530 |
" |
|
1531 |
items notNil ifTrue:[ ^ items findFirst:aOneArgBlock ]. |
|
1532 |
^ 0 |
|
1533 |
||
1534 |
! |
|
1535 |
||
1536 |
findLast:aOneArgBlock |
|
1537 |
"find the last item, for which evaluation of the argument, aOneArgBlock |
|
1538 |
returns true; return its index or 0 if none detected. |
|
1539 |
" |
|
1540 |
items notNil ifTrue:[ ^ items findLast:aOneArgBlock ]. |
|
1541 |
^ 0 |
|
1542 |
||
1543 |
! |
|
1544 |
||
390 | 1545 |
indexOf:something |
1546 |
"returns index of an item assigned to an index, nameKey, textLabel or value if symbol. |
|
1547 |
If no item match 0 is returned. No range checks are performed on a number argument |
|
388 | 1548 |
" |
390 | 1549 |
|i v| |
1550 |
||
1551 |
something isNumber ifTrue:[ ^ something ]. |
|
1552 |
something isNil ifTrue:[ ^ 0 ]. |
|
1553 |
||
1554 |
i := self findFirst:[:el|el nameKey = something]. |
|
1555 |
||
1556 |
i ~~ 0 ifTrue:[ |
|
1557 |
^ i |
|
388 | 1558 |
]. |
390 | 1559 |
|
1560 |
something isSymbol ifTrue:[ |
|
1561 |
i := self findFirst:[:el| |
|
1562 |
v := el value. |
|
1563 |
v isSymbol and:[v == something] |
|
1564 |
]. |
|
1565 |
i ~~ 0 ifTrue:[ |
|
1566 |
^ i |
|
1567 |
] |
|
1568 |
]. |
|
1569 |
||
1570 |
(something respondsTo:#string) ifTrue:[ |
|
1571 |
v := something string. |
|
1572 |
^ self findFirst:[:el|el textLabel = v]. |
|
1573 |
]. |
|
1574 |
^ 0 |
|
388 | 1575 |
! |
1576 |
||
1577 |
keysAndValuesDo:aTwoArgBlock |
|
1578 |
"evaluate the argument, aTwoArgBlock for every item in the menuPanel. |
|
1579 |
" |
|
1580 |
items notNil ifTrue:[ items keysAndValuesDo:aTwoArgBlock ]. |
|
1581 |
||
1582 |
! ! |
|
1583 |
||
1584 |
!MenuPanel methodsFor:'event handling'! |
|
1585 |
||
1586 |
buttonMotion:state x:x y:y |
|
1587 |
"open or close the corresponding submenus |
|
1588 |
" |
|
1589 |
|menu point sensor| |
|
1590 |
||
1591 |
( (sensor := self sensor) notNil |
|
1592 |
and:[sensor hasButtonMotionEventFor:nil] |
|
1593 |
) ifTrue:[ |
|
1594 |
^ self |
|
1595 |
]. |
|
1596 |
||
1597 |
(self containsPointX:x y:y) ifTrue:[ |
|
1598 |
^ self selection:(self itemAtX:x y:y) |
|
1599 |
]. |
|
1600 |
menu := self superMenuAtX:x y:y. |
|
1601 |
||
1602 |
menu isNil ifTrue:[ |
|
1603 |
^ self selection:nil |
|
1604 |
]. |
|
1605 |
point := self translatePoint:(x@y) to:menu. |
|
1606 |
menu selection:(menu itemAtX:(point x) y:(point y)) |
|
1607 |
! |
|
1608 |
||
1609 |
buttonPress:button x:x y:y |
|
1610 |
"any button pressed; open or close the corresponding submenus |
|
1611 |
" |
|
1612 |
|menu point item| |
|
1613 |
||
1614 |
menu := self superMenuAtX:x y:y. |
|
1615 |
||
1616 |
menu isNil ifTrue:[ |
|
1617 |
menu := self topMenu. |
|
1618 |
] ifFalse:[ |
|
1619 |
point := self translatePoint:(x@y) to:menu. |
|
1620 |
item := menu itemAtX:(point x) y:(point y) |
|
1621 |
]. |
|
1622 |
menu selection:item |
|
1623 |
! |
|
1624 |
||
1625 |
buttonRelease:button x:x y:y |
|
1626 |
"button release action; accept selection and close all views |
|
1627 |
" |
|
1628 |
( self hasSelection or:[ |
|
1629 |
(OperatingSystem millisecondTimeDeltaBetween:(Time millisecondClockValue) |
|
1630 |
and:mapTime) > 200] |
|
1631 |
) ifTrue:[ |
|
1632 |
self accept |
|
1633 |
] |
|
1634 |
! |
|
1635 |
||
1636 |
cursorPressed:aKey |
|
1637 |
"handle a cursor key |
|
1638 |
" |
|
1639 |
|idx next first submenu item| |
|
1640 |
||
1641 |
(self hasSelection not and:[superMenu notNil]) ifTrue:[ |
|
1642 |
^ superMenu cursorPressed:aKey |
|
1643 |
]. |
|
1644 |
||
1645 |
self verticalLayout ifTrue:[ |
|
1646 |
aKey == #CursorLeft ifTrue:[^ self selection:nil]. |
|
1647 |
aKey ~~ #CursorRight ifTrue:[next := aKey == #CursorDown]. |
|
1648 |
] ifFalse:[ |
|
1649 |
aKey == #CursorUp ifTrue:[^ self selection:nil]. |
|
1650 |
aKey ~~ #CursorDown ifTrue:[next := aKey == #CursorRight]. |
|
1651 |
]. |
|
1652 |
||
1653 |
next isNil ifTrue:[ |
|
1654 |
(item := self selection) notNil ifTrue:[ |
|
1655 |
(submenu := item submenu) notNil ifTrue:[ |
|
1656 |
idx := submenu findFirst:[:el| el canSelect ]. |
|
1657 |
^ submenu selectionIndex:idx |
|
1658 |
]. |
|
1659 |
^ self selection:nil |
|
1660 |
]. |
|
1661 |
^ self |
|
1662 |
]. |
|
1663 |
||
1664 |
first := self findFirst:[:el| el canSelect ]. |
|
1665 |
first == 0 ifTrue:[^ self]. |
|
1666 |
||
1667 |
idx := self selectionIndex. |
|
1668 |
||
1669 |
next ifTrue:[ |
|
1670 |
[((idx := idx + 1) <= items size and:[(items at:idx) canSelect not]) |
|
1671 |
] whileTrue. |
|
1672 |
||
1673 |
idx > items size ifTrue:[ |
|
1674 |
idx := first |
|
1675 |
]. |
|
1676 |
] ifFalse:[ |
|
1677 |
[((idx := idx - 1) > 0 and:[(items at:idx) canSelect not]) |
|
1678 |
] whileTrue. |
|
1679 |
||
1680 |
idx < 1 ifTrue:[ idx := self findLast:[:el| el canSelect ] ] |
|
1681 |
]. |
|
1682 |
self selectionIndex:idx |
|
1683 |
||
1684 |
! |
|
1685 |
||
1686 |
keyPress:key x:x y:y |
|
1687 |
"any key is pressed |
|
1688 |
" |
|
389 | 1689 |
|listOfItems item menu idx cIdx upperKey lowerKey| |
388 | 1690 |
|
1691 |
menu := self. |
|
1692 |
||
1693 |
[ menu shown ] whileFalse:[ |
|
1694 |
(menu := superMenu) isNil ifTrue:[^ self] |
|
1695 |
]. |
|
1696 |
||
1697 |
key == #Return ifTrue:[ |
|
1698 |
^ menu accept |
|
1699 |
]. |
|
1700 |
||
1701 |
( key == #CursorDown or:[key == #CursorUp |
|
1702 |
or:[key == #CursorLeft or:[key == #CursorRight]]] |
|
1703 |
) ifTrue:[ |
|
1704 |
^ menu cursorPressed:key |
|
1705 |
]. |
|
1706 |
||
1707 |
listOfItems := self selectItemsForShortcutKey:key. |
|
1708 |
listOfItems notNil ifTrue:[ |
|
1709 |
item := listOfItems first. |
|
1710 |
||
1711 |
item hasSubmenu ifFalse:[ |
|
441 | 1712 |
^ menu accept:item |
389 | 1713 |
]. |
1714 |
^ self openMenusFromItems:listOfItems |
|
388 | 1715 |
]. |
1716 |
||
1717 |
(self hasSelection not and:[superMenu notNil]) ifTrue:[ |
|
1718 |
(superMenu containsPoint:(self translatePoint:(x@y) to:superMenu)) ifTrue:[ |
|
1719 |
menu := superMenu |
|
1720 |
] |
|
1721 |
]. |
|
1722 |
||
1723 |
cIdx := menu selectionIndex. |
|
1724 |
cIdx isNil ifTrue:[cIdx := 0]. |
|
1725 |
||
389 | 1726 |
upperKey := key asUppercase. |
1727 |
lowerKey := key asLowercase. |
|
1728 |
||
388 | 1729 |
menu keysAndValuesDo:[:anIndex :el| |c l| |
390 | 1730 |
(el canSelect and:[(l := el textLabel) notNil]) ifTrue:[ |
388 | 1731 |
l size ~~ 0 ifTrue:[ |
1732 |
(c := el accessCharacter) notNil ifTrue:[ |
|
389 | 1733 |
(c == upperKey or:[c == lowerKey]) ifTrue:[ |
388 | 1734 |
^ menu selection:el |
1735 |
] |
|
1736 |
] ifFalse:[ |
|
389 | 1737 |
((c := l first) == upperKey or:[c == lowerKey]) ifTrue:[ |
388 | 1738 |
anIndex > cIdx ifTrue:[ |
1739 |
^ menu selection:el |
|
1740 |
] ifFalse:[ |
|
1741 |
idx isNil ifTrue:[ |
|
1742 |
idx := anIndex |
|
1743 |
] ifFalse:[ |
|
1744 |
anIndex > idx ifTrue:[ |
|
1745 |
anIndex ~~ cIdx ifTrue:[ |
|
1746 |
idx := anIndex |
|
1747 |
] |
|
1748 |
] |
|
1749 |
] |
|
1750 |
] |
|
1751 |
||
1752 |
] |
|
1753 |
] |
|
1754 |
] |
|
1755 |
] |
|
1756 |
]. |
|
417 | 1757 |
(item := menu itemAt:idx) isNil ifTrue:[ |
1758 |
menu hasSelection ifFalse:[ |
|
1759 |
(menu := menu superMenu) isNil ifTrue:[ |
|
1760 |
^ super keyPress:key x:x y:y |
|
1761 |
] |
|
1762 |
] |
|
1763 |
]. |
|
1764 |
menu selection:item. |
|
388 | 1765 |
|
390 | 1766 |
! |
1767 |
||
1768 |
sizeChanged:how |
|
1769 |
self isFitPanel ifTrue:[ |
|
1770 |
self mustRearrange. |
|
1771 |
]. |
|
1772 |
super sizeChanged:how |
|
388 | 1773 |
! ! |
1774 |
||
1775 |
!MenuPanel methodsFor:'grabbing'! |
|
1776 |
||
420 | 1777 |
forceUngrabMouseAndKeyboard |
1778 |
"ungrap resources( mouse and keyboard ) |
|
1779 |
" |
|
1780 |
|sensor| |
|
1781 |
||
1782 |
device ungrabPointer. |
|
1783 |
||
1784 |
(sensor := self sensor) notNil ifTrue:[ |
|
1785 |
"/ make certain all X events have been received |
|
1786 |
device sync. |
|
1787 |
"/ now all events have been received. |
|
1788 |
"/ now, flush all pointer events |
|
1789 |
sensor flushKeyboardFor:nil |
|
1790 |
]. |
|
1791 |
device ungrabKeyboard. |
|
1792 |
||
1793 |
! |
|
1794 |
||
388 | 1795 |
grabMouseAndKeyboard |
1796 |
"get exclusive access to pointer and keyboard |
|
1797 |
" |
|
1798 |
|sensor| |
|
1799 |
||
1800 |
realized ifTrue:[ |
|
1801 |
sensor := self sensor. |
|
1802 |
||
1803 |
device activePointerGrab ~~ self ifTrue:[ |
|
1804 |
sensor notNil ifTrue:[ |
|
1805 |
sensor flushMotionEventsFor:nil. |
|
1806 |
]. |
|
1807 |
||
1808 |
(device grabPointerInView:self) ifFalse:[ |
|
1809 |
Delay waitForSeconds:0.1. |
|
1810 |
(device grabPointerInView:self) ifFalse:[ |
|
1811 |
"give up" |
|
1812 |
'PopUpView [warning]: could not grab pointer' errorPrintCR. |
|
1813 |
self unmap |
|
1814 |
] |
|
1815 |
] |
|
1816 |
]. |
|
1817 |
||
1818 |
device activeKeyboardGrab ~~ self ifTrue:[ |
|
1819 |
sensor notNil ifTrue:[ |
|
1820 |
device sync. |
|
1821 |
sensor flushKeyboardFor:nil |
|
1822 |
]. |
|
1823 |
device grabKeyboardInView:self. |
|
498 | 1824 |
superMenu notNil ifTrue:[ |
1825 |
self getKeyboardFocus |
|
1826 |
] |
|
388 | 1827 |
] |
1828 |
] |
|
1829 |
||
1830 |
||
1831 |
! |
|
1832 |
||
1833 |
ungrabMouseAndKeyboard |
|
1834 |
"ungrap resources( mouse and keyboard ) |
|
1835 |
" |
|
1836 |
|sensor| |
|
1837 |
||
1838 |
device activePointerGrab == self ifTrue:[ |
|
1839 |
device ungrabPointer. |
|
1840 |
]. |
|
1841 |
device activeKeyboardGrab == self ifTrue:[ |
|
1842 |
(sensor := self sensor) notNil ifTrue:[ |
|
1843 |
"/ make certain all X events have been received |
|
1844 |
device sync. |
|
1845 |
"/ now all events have been received. |
|
1846 |
"/ now, flush all pointer events |
|
1847 |
sensor flushKeyboardFor:self |
|
1848 |
]. |
|
1849 |
device ungrabKeyboard. |
|
1850 |
]. |
|
1851 |
(superMenu notNil and:[superMenu shown and:[superMenu isPopUpView]]) ifTrue:[ |
|
1852 |
superMenu grabMouseAndKeyboard |
|
1853 |
] |
|
1854 |
||
1855 |
||
1856 |
||
1857 |
! ! |
|
1858 |
||
1859 |
!MenuPanel methodsFor:'initialize / release'! |
|
1860 |
||
1861 |
create |
|
1862 |
"create the shadow view for a none contained submenu; see initStyle |
|
1863 |
" |
|
436 | 1864 |
|
388 | 1865 |
super create. |
1866 |
||
1867 |
self isPopUpView ifTrue:[ |
|
1868 |
shadowView isNil ifTrue:[ |
|
1869 |
shadowView := (ShadowView onDevice:device) for:self |
|
1870 |
] |
|
1871 |
] ifFalse:[ |
|
1872 |
explicitExtent == true ifTrue:[ |
|
1873 |
(self extent x) == (superView extent x) ifTrue:[ |
|
1874 |
self verticalLayout:false |
|
1875 |
] |
|
1876 |
] |
|
1877 |
] |
|
1878 |
! |
|
1879 |
||
1880 |
destroy |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1881 |
"destroy items and shadowView; remove dependencies |
388 | 1882 |
" |
1883 |
self do:[:el|el destroy]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1884 |
|
498 | 1885 |
menuHolder notNil ifTrue:[menuHolder removeDependent:self]. |
1886 |
enableChannel notNil ifTrue:[enableChannel removeDependent:self]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1887 |
|
388 | 1888 |
super destroy. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1889 |
superMenu := nil. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1890 |
items := nil. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1891 |
shadowView notNil ifTrue:[shadowView destroy]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1892 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1893 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1894 |
|
580 | 1895 |
initStyle |
1896 |
"initialize style specific stuff" |
|
1897 |
||
1898 |
|f| |
|
1899 |
||
1900 |
super initStyle. |
|
1901 |
f := self styleAt:#font. |
|
1902 |
f notNil ifTrue:[ |
|
1903 |
self font:f |
|
1904 |
]. |
|
1905 |
||
1906 |
"Created: / 27.10.1997 / 01:15:17 / cg" |
|
1907 |
! |
|
1908 |
||
388 | 1909 |
initialize |
1910 |
"set default configuration |
|
1911 |
" |
|
1912 |
super initialize. |
|
498 | 1913 |
enabled := true. |
388 | 1914 |
font := font on:device. |
1915 |
self origin:0.0@0.0. |
|
1916 |
originChanged := extentChanged := false. |
|
1917 |
explicitExtent := nil. |
|
1918 |
shortKeyInset := 0. |
|
1919 |
mustRearrange := false. |
|
1920 |
self level:1. |
|
1921 |
! |
|
1922 |
||
1923 |
mapped |
|
1924 |
"grab the pointer here, when visible (but not control is already lost). |
|
1925 |
If the grab fails, try again and unmap myself if that fails too. |
|
1926 |
" |
|
1927 |
|anItemList| |
|
1928 |
||
1929 |
mapTime := Time millisecondClockValue. |
|
1930 |
super mapped. |
|
1931 |
||
1932 |
anItemList := InitialSelectionQuerySignal raise. |
|
1933 |
||
1934 |
self isPopUpView ifTrue:[ |
|
1935 |
self grabMouseAndKeyboard |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1936 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1937 |
super viewBackground:(self backgroundColor) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1938 |
. ]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1939 |
self do:[:el| el updateIndicators ]. |
388 | 1940 |
|
1941 |
anItemList size > 0 ifTrue:[ |
|
1942 |
self redrawX:0 y:0 width:10000 height:10000. |
|
1943 |
self openMenusFromItems:anItemList. |
|
1944 |
]. |
|
1945 |
||
1946 |
! |
|
1947 |
||
1948 |
realize |
|
1949 |
"realize menu and shadowView |
|
1950 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1951 |
|bsz| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
1952 |
|
388 | 1953 |
self isPopUpView ifTrue:[ |
436 | 1954 |
self resize. |
1955 |
shadowView isNil ifTrue:[ |
|
1956 |
shadowView := (ShadowView onDevice:device) for:self |
|
390 | 1957 |
]. |
436 | 1958 |
bsz := self styleAt:#borderWidth. |
1959 |
bsz ~~ self borderWidth ifTrue:[ |
|
1960 |
self borderWidth:bsz |
|
1961 |
]. |
|
1962 |
shadowView realize. |
|
388 | 1963 |
]. |
1964 |
super realize. |
|
436 | 1965 |
self raise. |
388 | 1966 |
|
1967 |
||
1968 |
! |
|
1969 |
||
1970 |
recreate |
|
1971 |
"this is called after a snapin. If the image was saved with an active menu, |
|
1972 |
hide the menu |
|
1973 |
" |
|
1974 |
self selection:nil. |
|
1975 |
super recreate. |
|
1976 |
||
1977 |
! |
|
1978 |
||
1979 |
unmap |
|
1980 |
"unmap view |
|
1981 |
" |
|
1982 |
self ungrabMouseAndKeyboard. |
|
1983 |
super unmap. |
|
1984 |
shadowView notNil ifTrue:[shadowView unmap]. |
|
1985 |
||
1986 |
||
1987 |
! ! |
|
1988 |
||
1989 |
!MenuPanel methodsFor:'misc'! |
|
1990 |
||
427
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1991 |
raiseDeiconified |
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1992 |
^ self raise |
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1993 |
|
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1994 |
"Created: 21.6.1997 / 13:29:12 / cg" |
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1995 |
! |
82cbad72e197
raiseDeiconified is treated like a raise
Claus Gittinger <cg@exept.de>
parents:
420
diff
changeset
|
1996 |
|
388 | 1997 |
superMenu |
1998 |
"returns supermenu or nil |
|
1999 |
" |
|
2000 |
^ superMenu |
|
2001 |
||
2002 |
||
2003 |
! |
|
2004 |
||
2005 |
superMenu:aSuperMenu |
|
2006 |
"set the supermenu starting from |
|
2007 |
" |
|
2008 |
superMenu := aSuperMenu. |
|
2009 |
! |
|
2010 |
||
2011 |
topMenu |
|
2012 |
"returns the topMenu; the one having no superMenu |
|
2013 |
" |
|
2014 |
|top| |
|
2015 |
||
2016 |
top := self. |
|
2017 |
||
2018 |
[ top superMenu notNil ] whileTrue:[ |
|
2019 |
top := top superMenu |
|
2020 |
]. |
|
2021 |
^ top |
|
2022 |
||
2023 |
||
2024 |
! ! |
|
2025 |
||
2026 |
!MenuPanel methodsFor:'private'! |
|
2027 |
||
434 | 2028 |
application |
2029 |
|appl| |
|
2030 |
||
2031 |
superMenu notNil ifTrue:[ |
|
2032 |
^ superMenu application |
|
2033 |
]. |
|
2034 |
(appl := super application) isNil ifTrue:[ |
|
464 | 2035 |
windowGroup notNil ifTrue:[ |
2036 |
appl := windowGroup mainGroup topViews first application |
|
2037 |
] |
|
434 | 2038 |
]. |
2039 |
^ appl |
|
2040 |
! |
|
2041 |
||
390 | 2042 |
menuAdornmentAt:aSymbol |
388 | 2043 |
"returns a value derived from adornment |
2044 |
" |
|
390 | 2045 |
|adm| |
2046 |
||
2047 |
adm := adornment ? DefaultAdornment. |
|
2048 |
^ adm at:aSymbol ifAbsent:nil |
|
388 | 2049 |
! |
2050 |
||
390 | 2051 |
menuAdornmentAt:aSymbol put:something |
2052 |
"sets a value for the specific menu |
|
388 | 2053 |
" |
390 | 2054 |
(self menuAdornmentAt:aSymbol) ~~ something ifTrue:[ |
388 | 2055 |
adornment isNil ifTrue:[ |
2056 |
adornment := DefaultAdornment copy |
|
2057 |
]. |
|
390 | 2058 |
adornment at:aSymbol put:something. |
2059 |
self mustRearrange. |
|
388 | 2060 |
] |
2061 |
! |
|
2062 |
||
2063 |
onEachPerform:aSelector withArgList:aList |
|
2064 |
"on each item perform selector with an argument derived from aList |
|
2065 |
" |
|
2066 |
aList isCollection ifTrue:[ |
|
2067 |
items size >= aList size ifTrue:[ |
|
2068 |
aList keysAndValuesDo:[:anIndex :anArg| |
|
2069 |
(items at:anIndex) perform:aSelector with:anArg |
|
2070 |
] |
|
2071 |
] |
|
2072 |
] ifFalse:[ |
|
2073 |
self do:[:anItem| anItem perform:aSelector with:aList ] |
|
2074 |
] |
|
2075 |
||
2076 |
||
2077 |
! |
|
2078 |
||
2079 |
openMenusFromItems:anItemList |
|
2080 |
"open all menus derived from sequence of items |
|
2081 |
" |
|
2082 |
|item| |
|
2083 |
||
2084 |
(anItemList isNil or:[anItemList isEmpty]) ifTrue:[ |
|
2085 |
^ self |
|
2086 |
]. |
|
2087 |
item := anItemList removeLast. |
|
2088 |
||
2089 |
item enabled ifFalse:[ |
|
2090 |
^ self |
|
2091 |
]. |
|
2092 |
||
2093 |
InitialSelectionQuerySignal answer:anItemList do:[ |
|
2094 |
self selection:item |
|
2095 |
] |
|
2096 |
! |
|
2097 |
||
2098 |
selectItemsForShortcutKey:aKey |
|
2099 |
"get sequence of items up to the item providing the key (inclusive). The |
|
2100 |
first entry into the collection is the item providing the key, the last |
|
2101 |
entry is the item in the topMenu( reverse ) |
|
2102 |
" |
|
2103 |
|seq| |
|
2104 |
||
2105 |
self do:[:anItem| |
|
2106 |
anItem isEnabled ifTrue:[ |
|
2107 |
anItem shortcutKey = aKey ifTrue:[ |
|
2108 |
seq := OrderedCollection new. |
|
2109 |
] ifFalse:[ |
|
2110 |
anItem hasSubmenu ifTrue:[ |
|
2111 |
seq := anItem submenu selectItemsForShortcutKey:aKey |
|
2112 |
] |
|
2113 |
]. |
|
2114 |
seq notNil ifTrue:[ |
|
2115 |
seq add:anItem. |
|
2116 |
^ seq |
|
2117 |
] |
|
2118 |
] |
|
2119 |
]. |
|
2120 |
^ nil |
|
2121 |
||
2122 |
! |
|
2123 |
||
390 | 2124 |
styleAt:aSymbol |
2125 |
"gets a value derived from the style in the topMenu |
|
2126 |
" |
|
2127 |
|aStyle| |
|
2128 |
||
2129 |
superMenu isNil ifTrue:[ |
|
2130 |
aStyle := style ? DefaultStyle. |
|
2131 |
^ aStyle at:aSymbol ifAbsent:nil |
|
2132 |
]. |
|
2133 |
^ superMenu styleAt:aSymbol |
|
2134 |
||
2135 |
! |
|
2136 |
||
2137 |
styleAt:aSymbol put:aValue |
|
2138 |
"sets a value derived from the style in the topMenu |
|
2139 |
" |
|
2140 |
|aStyle| |
|
2141 |
||
2142 |
superMenu isNil ifTrue:[ |
|
2143 |
aStyle := style ? DefaultStyle. |
|
2144 |
||
2145 |
(aStyle at:aSymbol ifAbsent:nil) ~~ aValue ifTrue:[ |
|
2146 |
style isNil ifTrue:[ |
|
2147 |
style := DefaultStyle copy. |
|
2148 |
]. |
|
2149 |
style at:aSymbol put:aValue. |
|
2150 |
] |
|
2151 |
] ifFalse:[ |
|
2152 |
superMenu styleAt:aSymbol put:aValue |
|
2153 |
] |
|
2154 |
! |
|
2155 |
||
388 | 2156 |
translatePoint:aPoint to:aView |
2157 |
"translate a point into a views point; in case of no view nil is returned |
|
2158 |
" |
|
2159 |
aView notNil ifTrue:[ |
|
2160 |
aView == self ifTrue:[^ aPoint]. |
|
2161 |
^ device translatePoint:aPoint from:(self id) to:(aView id) |
|
2162 |
]. |
|
2163 |
^ nil |
|
2164 |
||
2165 |
! ! |
|
2166 |
||
2167 |
!MenuPanel methodsFor:'private searching'! |
|
2168 |
||
2169 |
itemAtX:x y:y |
|
2170 |
"returns item at a point or nil |
|
2171 |
" |
|
2172 |
self do:[:el| (el containsPointX:x y:y) ifTrue:[^el] ]. |
|
2173 |
^ nil |
|
2174 |
||
2175 |
||
2176 |
! |
|
2177 |
||
2178 |
superMenuAtX:x y:y |
|
2179 |
"returns supermenu at a point or nil |
|
2180 |
" |
|
2181 |
|menu| |
|
2182 |
||
2183 |
(self containsPointX:x y:y) ifTrue:[^ self]. |
|
2184 |
menu := self. |
|
2185 |
||
2186 |
[ (menu := menu superMenu) notNil ] whileTrue:[ |
|
2187 |
(menu containsPoint:(self translatePoint:(x@y) to:menu)) ifTrue:[ |
|
2188 |
^ menu |
|
2189 |
] |
|
2190 |
]. |
|
2191 |
^ nil |
|
2192 |
||
2193 |
||
2194 |
! ! |
|
2195 |
||
2196 |
!MenuPanel methodsFor:'queries'! |
|
2197 |
||
2198 |
canDrawItem |
|
2199 |
"returns true if an item could be drawn otherwise false |
|
2200 |
" |
|
2201 |
^ (mustRearrange not and:[self shown]) |
|
2202 |
||
2203 |
||
2204 |
! |
|
2205 |
||
2206 |
containsPoint:aPoint |
|
2207 |
"returns true if point is contained by the view |
|
2208 |
" |
|
2209 |
^ self containsPointX:(aPoint x) y:(aPoint y) |
|
2210 |
! |
|
2211 |
||
2212 |
containsPointX:x y:y |
|
2213 |
"returns true if point is contained by the view |
|
2214 |
" |
|
2215 |
|ext| |
|
2216 |
||
2217 |
(x >= 0 and:[y >= 0]) ifTrue:[ |
|
2218 |
ext := self computeExtent. |
|
2219 |
^ (x < ext x and:[y < ext y]) |
|
2220 |
]. |
|
2221 |
^ false |
|
2222 |
||
2223 |
||
2224 |
! |
|
2225 |
||
390 | 2226 |
hasGroupDividerAt:anIndex |
388 | 2227 |
"returns true if a divider is defined at an index |
2228 |
" |
|
2229 |
|i| |
|
2230 |
||
2231 |
groupSizes size ~~ 0 ifTrue:[ |
|
2232 |
i := 0. |
|
2233 |
||
2234 |
groupSizes do:[:t| |
|
2235 |
(i := i + t) == anIndex ifTrue:[ |
|
2236 |
^ true |
|
2237 |
] |
|
2238 |
] |
|
2239 |
]. |
|
2240 |
^ false |
|
2241 |
||
2242 |
! |
|
2243 |
||
390 | 2244 |
hasGroupDividers |
2245 |
"returns true if any group divider exists |
|
2246 |
" |
|
2247 |
^ (items size ~~ 0 and:[groupSizes size ~~ 0]) |
|
2248 |
! |
|
2249 |
||
388 | 2250 |
isEnabled |
2251 |
"returns enabled state of menu and items |
|
2252 |
" |
|
2253 |
^ self enabled |
|
2254 |
! |
|
2255 |
||
390 | 2256 |
isFitPanel |
2257 |
"returns true if the panel is the first in the menu hierarchy in must |
|
2258 |
be fit to the extent of its superView |
|
2259 |
" |
|
2260 |
superView isNil ifTrue:[ |
|
2261 |
^ false |
|
2262 |
]. |
|
2263 |
^ self styleAt:#fitFirstPanel |
|
2264 |
! |
|
2265 |
||
388 | 2266 |
isPopUpView |
2267 |
"return true if view is a popup view; without decoration |
|
2268 |
and popUp to top immediately |
|
2269 |
" |
|
2270 |
^ superView isNil |
|
2271 |
||
2272 |
||
2273 |
! |
|
2274 |
||
2275 |
isVerticalLayout |
|
2276 |
"returns true if vertical layout otherwise false( horizontal layout ) |
|
2277 |
" |
|
2278 |
^ self verticalLayout |
|
2279 |
||
2280 |
||
416 | 2281 |
! |
2282 |
||
2283 |
type |
|
428 | 2284 |
^ nil. |
416 | 2285 |
|
388 | 2286 |
! ! |
2287 |
||
2288 |
!MenuPanel methodsFor:'selection'! |
|
2289 |
||
2290 |
hasSelection |
|
2291 |
"returns true if a selection exists |
|
2292 |
" |
|
2293 |
^ self selection notNil |
|
2294 |
! |
|
2295 |
||
2296 |
isValidSelection:something |
|
2297 |
"returns true if something could be selected |
|
2298 |
" |
|
2299 |
|item| |
|
2300 |
||
498 | 2301 |
enabled ifTrue:[ |
2302 |
(item := self itemAt:something) notNil ifTrue:[ |
|
2303 |
^ item canSelect |
|
2304 |
] |
|
388 | 2305 |
]. |
2306 |
^ false |
|
2307 |
! |
|
2308 |
||
2309 |
selection |
|
2310 |
"returns current selected item or nil |
|
2311 |
" |
|
2312 |
^ selection |
|
2313 |
||
2314 |
||
2315 |
! |
|
2316 |
||
2317 |
selection:anItemOrNil |
|
2318 |
"change selection to an item |
|
2319 |
" |
|
434 | 2320 |
|item newSel hlp| |
388 | 2321 |
|
2322 |
selection isNumber ifTrue:[ |
|
2323 |
newSel := self itemAt:anItemOrNil |
|
2324 |
] ifFalse:[ |
|
2325 |
(anItemOrNil notNil and:[anItemOrNil canSelect]) ifTrue:[ |
|
2326 |
newSel := anItemOrNil |
|
2327 |
] |
|
2328 |
]. |
|
2329 |
||
2330 |
selection == newSel ifTrue:[^ self]. |
|
2331 |
||
2332 |
(item := selection) notNil ifTrue:[ |
|
2333 |
selection := nil. |
|
2334 |
item selected:false. |
|
2335 |
]. |
|
2336 |
newSel isNil ifTrue:[ |
|
2337 |
self isPopUpView ifFalse:[ |
|
2338 |
self ungrabMouseAndKeyboard |
|
2339 |
]. |
|
2340 |
^ self |
|
2341 |
]. |
|
2342 |
selection := newSel. |
|
434 | 2343 |
|
2344 |
ActiveHelp isActive ifTrue:[ |
|
2345 |
hlp := ActiveHelp currentHelpListener. |
|
2346 |
hlp initiateHelpFor:self atX:1 y:1 now:true. |
|
2347 |
]. |
|
2348 |
||
388 | 2349 |
selection selected:true |
2350 |
! |
|
2351 |
||
2352 |
selectionIndex |
|
2353 |
"returns index of current selection or 0 |
|
2354 |
" |
|
2355 |
|item| |
|
2356 |
||
2357 |
(item := self selection) notNil ifTrue:[ |
|
2358 |
^ self findFirst:[:el| el == item ] |
|
2359 |
]. |
|
2360 |
^ 0 |
|
2361 |
||
2362 |
! |
|
2363 |
||
2364 |
selectionIndex:anIndex |
|
2365 |
"set selection at an index |
|
2366 |
" |
|
2367 |
self selection:(self itemAt:anIndex) |
|
2368 |
! ! |
|
2369 |
||
2370 |
!MenuPanel::Item class methodsFor:'accessing'! |
|
2371 |
||
2372 |
horizontalInset |
|
2373 |
^ HorizontalInset |
|
2374 |
! |
|
2375 |
||
2376 |
labelRightOffset |
|
2377 |
^ LabelRightOffset |
|
2378 |
! |
|
2379 |
||
2380 |
shortcutKeyOffset |
|
2381 |
^ ShortcutKeyOffset |
|
2382 |
! |
|
2383 |
||
2384 |
verticalInset |
|
2385 |
^ VerticalInset |
|
2386 |
! ! |
|
2387 |
||
2388 |
!MenuPanel::Item class methodsFor:'init style'! |
|
2389 |
||
2390 |
initStyle |
|
2391 |
"setup defaults |
|
2392 |
" |
|
2393 |
HorizontalInset := 4. |
|
2394 |
VerticalInset := 4. |
|
2395 |
LabelRightOffset := 15. |
|
2396 |
ShortcutKeyOffset := 5. |
|
2397 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2398 |
IndicatorOn := CheckToggle checkImageForStyle:#borderedFatcross. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2399 |
IndicatorOff := CheckToggle checkImageForStyle:#border. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2400 |
|
388 | 2401 |
" |
2402 |
self initStyle |
|
2403 |
" |
|
2404 |
! ! |
|
2405 |
||
2406 |
!MenuPanel::Item class methodsFor:'instance creation'! |
|
2407 |
||
2408 |
in:aSuperMenu |
|
2409 |
^ self in:aSuperMenu label:nil |
|
2410 |
! |
|
2411 |
||
2412 |
in:aSuperMenu label:aLabel |
|
2413 |
|item| |
|
2414 |
||
2415 |
HorizontalInset isNil ifTrue:[ self initStyle ]. |
|
2416 |
||
2417 |
item := self new in:aSuperMenu. |
|
2418 |
item label:aLabel. |
|
2419 |
^ item |
|
2420 |
! |
|
2421 |
||
2422 |
in:aSuperMenu menuItem:aMenuItem |
|
2423 |
|item| |
|
2424 |
||
2425 |
item := self in:aSuperMenu. |
|
2426 |
item menuItem:aMenuItem. |
|
2427 |
^ item. |
|
2428 |
! ! |
|
2429 |
||
389 | 2430 |
!MenuPanel::Item methodsFor:'accept'! |
2431 |
||
420 | 2432 |
canAccept |
2433 |
"returns true if item is acceptable |
|
2434 |
" |
|
2435 |
^ (self enabled and:[self hasSubmenu not]) |
|
524 | 2436 |
! |
2437 |
||
2438 |
toggleIndication |
|
2439 |
"toggle indication |
|
2440 |
" |
|
2441 |
|arg| |
|
2442 |
||
2443 |
self hasIndication ifTrue:[ |
|
2444 |
arg := self indicationValue not. |
|
2445 |
self indicationValue:arg. |
|
2446 |
]. |
|
2447 |
^ arg |
|
389 | 2448 |
! ! |
2449 |
||
388 | 2450 |
!MenuPanel::Item methodsFor:'accessing'! |
2451 |
||
2452 |
accessCharacter |
|
389 | 2453 |
"returns my accessCharacter or nil |
388 | 2454 |
" |
389 | 2455 |
accessCharacterPosition isNil ifTrue:[ |
2456 |
^ nil |
|
388 | 2457 |
]. |
389 | 2458 |
^ (rawLabel string) at:accessCharacterPosition |
388 | 2459 |
! |
2460 |
||
2461 |
accessCharacterPosition |
|
390 | 2462 |
"get the access character position or nil |
388 | 2463 |
" |
389 | 2464 |
^ accessCharacterPosition |
388 | 2465 |
! |
2466 |
||
2467 |
accessCharacterPosition:anIndex |
|
390 | 2468 |
"set the access character position or nil |
388 | 2469 |
" |
475 | 2470 |
|lbl| |
390 | 2471 |
|
2472 |
( (accessCharacterPosition ~~ anIndex) |
|
2473 |
and:[(lbl := self textLabel) notNil] |
|
389 | 2474 |
) ifTrue:[ |
390 | 2475 |
anIndex notNil ifTrue:[ |
2476 |
(anIndex < 1 or:[anIndex > lbl size]) ifTrue:[ |
|
2477 |
^ self |
|
2478 |
]. |
|
389 | 2479 |
]. |
390 | 2480 |
accessCharacterPosition := anIndex. |
388 | 2481 |
self updateRawLabel. |
2482 |
]. |
|
2483 |
! |
|
2484 |
||
434 | 2485 |
activeHelpKey |
2486 |
^ activeHelpKey |
|
2487 |
! |
|
2488 |
||
2489 |
activeHelpKey:aHelpKey |
|
2490 |
activeHelpKey := aHelpKey |
|
2491 |
! |
|
2492 |
||
388 | 2493 |
argument |
2494 |
"gets the argument |
|
2495 |
" |
|
2496 |
adornment isNil ifTrue:[^ nil ]. |
|
2497 |
^ adornment argument |
|
2498 |
! |
|
2499 |
||
2500 |
argument:anArgument |
|
2501 |
"sets the argument |
|
2502 |
" |
|
2503 |
self argument ~~ anArgument ifTrue:[ |
|
2504 |
self adornment argument:anArgument. |
|
2505 |
] |
|
2506 |
! |
|
2507 |
||
389 | 2508 |
compareAccessCharacterWith:aKey |
2509 |
"returns true if key is my access character |
|
2510 |
" |
|
2511 |
|s| |
|
2512 |
||
2513 |
accessCharacterPosition notNil ifTrue:[ |
|
2514 |
s := (rawLabel string) at:accessCharacterPosition. |
|
2515 |
s == aKey ifTrue:[^ true ]. |
|
2516 |
]. |
|
2517 |
^ false |
|
2518 |
! |
|
2519 |
||
388 | 2520 |
label |
2521 |
"returns the label |
|
2522 |
" |
|
2523 |
^ label |
|
2524 |
! |
|
2525 |
||
2526 |
label:aLabel |
|
399 | 2527 |
"set a new label; if the label changed, a redraw is performed; |
2528 |
handle characters $& (ST-80 compatibility) |
|
388 | 2529 |
" |
475 | 2530 |
|i rest s| |
389 | 2531 |
|
2532 |
accessCharacterPosition := nil. |
|
399 | 2533 |
label := aLabel value. |
2534 |
||
2535 |
(label isString and:[(s := label size) > 1]) ifTrue:[ |
|
2536 |
i := 1. |
|
2537 |
||
2538 |
[((i := label indexOf:$& startingAt:i) ~~ 0 and:[i < s])] whileTrue:[ |
|
2539 |
rest := label copyFrom:(i+1). |
|
2540 |
||
2541 |
i == 1 ifTrue:[label := rest] |
|
2542 |
ifFalse:[label := (label copyFrom:1 to:(i-1)), rest]. |
|
2543 |
||
2544 |
(label at:i) == $& ifTrue:[i := i + 1] |
|
2545 |
ifFalse:[accessCharacterPosition := i]. |
|
2546 |
s := s - 1. |
|
389 | 2547 |
] |
2548 |
]. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2549 |
|
399 | 2550 |
self updateRawLabel |
388 | 2551 |
! |
2552 |
||
2553 |
menuPanel |
|
2554 |
"returns my menuPanel |
|
2555 |
" |
|
399 | 2556 |
^ menuPanel |
388 | 2557 |
! |
2558 |
||
2559 |
nameKey |
|
2560 |
"gets the nameKey |
|
2561 |
" |
|
2562 |
^ nameKey |
|
2563 |
! |
|
2564 |
||
2565 |
nameKey:aNameKey |
|
2566 |
"sets the nameKey |
|
2567 |
" |
|
2568 |
nameKey := aNameKey. |
|
2569 |
! |
|
2570 |
||
2571 |
rawLabel |
|
390 | 2572 |
"returns my printable Label |
388 | 2573 |
" |
2574 |
^ rawLabel |
|
2575 |
! |
|
2576 |
||
2577 |
shortcutKey |
|
2578 |
"get the key to press to select the submenu from the keyboard or if |
|
2579 |
no submenu exists evaluate the action assigned to the item (accept). |
|
2580 |
" |
|
2581 |
adornment isNil ifTrue:[^ nil ]. |
|
2582 |
^ adornment shortcutKey |
|
2583 |
! |
|
2584 |
||
2585 |
shortcutKey:aKey |
|
2586 |
"set the key to press to select the submenu from the keyboard or if |
|
2587 |
no submenu exists evaluate the action assigned to the item (accept). |
|
2588 |
" |
|
2589 |
self shortcutKey ~~ aKey ifTrue:[ |
|
2590 |
self adornment shortcutKey:aKey. |
|
2591 |
self redraw. |
|
2592 |
]. |
|
2593 |
! |
|
2594 |
||
2595 |
submenu |
|
2596 |
"returns my submenu or nil |
|
2597 |
" |
|
464 | 2598 |
subMenu notNil ifTrue:[^ subMenu]. |
2599 |
^ self setupSubmenu |
|
388 | 2600 |
! |
2601 |
||
2602 |
submenu:aSubMenu |
|
2603 |
"set a new submenu; an existing submenu will be destroyed. This might lead |
|
2604 |
to a redraw if 'hasSubmenu' changed |
|
2605 |
" |
|
580 | 2606 |
|
2607 |
(aSubMenu notNil |
|
2608 |
and:[(aSubMenu isView or:[aSubMenu isKindOf:Menu]) not]) ifTrue:[ |
|
2609 |
^ self submenuChannel:aSubMenu |
|
388 | 2610 |
]. |
2611 |
||
2612 |
(subMenu := aSubMenu) notNil ifTrue:[ |
|
2613 |
aSubMenu class == Menu ifTrue:[ |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2614 |
subMenu := menuPanel class subMenu:aSubMenu |
388 | 2615 |
]. |
580 | 2616 |
(subMenu notNil and:[subMenu isView]) ifTrue:[ |
2617 |
subMenu superMenu:menuPanel |
|
2618 |
] |
|
388 | 2619 |
]. |
2620 |
||
580 | 2621 |
"Modified: / 27.10.1997 / 04:43:43 / cg" |
389 | 2622 |
! |
2623 |
||
390 | 2624 |
textLabel |
2625 |
"returns my textLabel or nil if none text |
|
2626 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2627 |
(rawLabel respondsTo:#string) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2628 |
^ rawLabel string |
390 | 2629 |
]. |
2630 |
^ nil |
|
2631 |
! |
|
2632 |
||
389 | 2633 |
value |
2634 |
"gets value |
|
2635 |
" |
|
2636 |
^ value |
|
2637 |
! |
|
2638 |
||
2639 |
value:something |
|
2640 |
"could be a value holder, an action or selector |
|
2641 |
" |
|
2642 |
value := something. |
|
502 | 2643 |
! |
2644 |
||
2645 |
value:aValue argument:anArgument |
|
2646 |
"set the value and an argument |
|
2647 |
" |
|
2648 |
self value:aValue. |
|
2649 |
self argument:anArgument. |
|
388 | 2650 |
! ! |
2651 |
||
2652 |
!MenuPanel::Item methodsFor:'accessing behavior'! |
|
2653 |
||
2654 |
enabled |
|
2655 |
"returns the enabled state |
|
2656 |
" |
|
524 | 2657 |
|state| |
2658 |
||
2659 |
menuPanel enabled ifTrue:[ |
|
2660 |
enableChannel isSymbol ifTrue:[ |
|
2661 |
state := self aspectAt:enableChannel. |
|
2662 |
||
2663 |
(self isKindOfValueHolder:state) ifTrue:[ |
|
2664 |
enableChannel := state. |
|
2665 |
enableChannel addDependent:self. |
|
2666 |
state := enableChannel value. |
|
2667 |
] |
|
465 | 2668 |
] ifFalse:[ |
524 | 2669 |
state := enableChannel value |
465 | 2670 |
]. |
524 | 2671 |
^ state ~~ false |
460 | 2672 |
]. |
524 | 2673 |
^ false |
388 | 2674 |
! |
2675 |
||
389 | 2676 |
enabled:something |
388 | 2677 |
"change the enabled state; if the state changed, a redraw is performed |
2678 |
" |
|
390 | 2679 |
|oldState newState| |
2680 |
||
2681 |
enableChannel isNil ifTrue:[ |
|
2682 |
oldState := true |
|
2683 |
] ifFalse:[ |
|
2684 |
oldState := enableChannel value. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2685 |
(self isKindOfValueHolder:enableChannel) ifTrue:[ |
390 | 2686 |
enableChannel removeDependent:self |
2687 |
] |
|
388 | 2688 |
]. |
390 | 2689 |
enableChannel := something. |
2690 |
||
2691 |
enableChannel isNil ifTrue:[ |
|
580 | 2692 |
menuPanel shown ifFalse:[^ self]. |
390 | 2693 |
newState := true |
2694 |
] ifFalse:[ |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2695 |
(self isKindOfValueHolder:enableChannel) ifTrue:[ |
390 | 2696 |
enableChannel addDependent:self |
460 | 2697 |
] ifFalse:[ |
464 | 2698 |
enableChannel isSymbol ifTrue:[^ self] |
390 | 2699 |
]. |
580 | 2700 |
menuPanel shown ifFalse:[^ self]. |
390 | 2701 |
newState := enableChannel value. |
2702 |
]. |
|
2703 |
||
2704 |
newState ~~ oldState ifTrue:[ |
|
498 | 2705 |
(rawLabel notNil and:[menuPanel canDrawItem]) ifTrue:[ |
2706 |
self drawLabel |
|
2707 |
] |
|
390 | 2708 |
] |
388 | 2709 |
|
580 | 2710 |
"Modified: / 27.10.1997 / 16:13:42 / cg" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2711 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2712 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2713 |
indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2714 |
"get on/off indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2715 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2716 |
adornment isNil ifTrue:[^ nil]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2717 |
^ adornment indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2718 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2719 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2720 |
indication:something |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2721 |
"set on/off indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2722 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2723 |
|old| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2724 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2725 |
old := self indication. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2726 |
old == something ifTrue:[^ self]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2727 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2728 |
(self isKindOfValueHolder:old) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2729 |
old removeDependent:self |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2730 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2731 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2732 |
(self isKindOfValueHolder:something) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2733 |
something addDependent:self |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2734 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2735 |
self adornment indication:something. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2736 |
self updateRawLabel. |
464 | 2737 |
! |
2738 |
||
2739 |
setupSubmenu |
|
2740 |
|appl subm| |
|
2741 |
||
2742 |
submenuChannel notNil ifTrue:[ |
|
2743 |
submenuChannel isSymbol ifFalse:[ |
|
2744 |
subm := submenuChannel |
|
2745 |
] ifTrue:[ |
|
2746 |
appl := menuPanel application. |
|
2747 |
||
2748 |
appl notNil ifTrue:[ |
|
2749 |
Object messageNotUnderstoodSignal handle:[:ex| |
|
2750 |
subm := nil |
|
2751 |
] do:[ |
|
2752 |
subm := appl aspectFor:submenuChannel |
|
2753 |
] |
|
2754 |
] |
|
2755 |
]. |
|
2756 |
(subm := subm value) isArray ifTrue:[ |
|
2757 |
subm := Menu new fromLiteralArrayEncoding:subm. |
|
2758 |
]. |
|
2759 |
self submenu:subm. |
|
2760 |
]. |
|
2761 |
^ subMenu |
|
2762 |
! |
|
2763 |
||
2764 |
submenuChannel |
|
2765 |
"get the submenu channel |
|
2766 |
" |
|
2767 |
^ submenuChannel |
|
2768 |
! |
|
2769 |
||
2770 |
submenuChannel:aSelectorOrNil |
|
2771 |
"returns the submenu channel |
|
2772 |
" |
|
2773 |
submenuChannel := aSelectorOrNil. |
|
388 | 2774 |
! ! |
2775 |
||
2776 |
!MenuPanel::Item methodsFor:'accessing dimension'! |
|
2777 |
||
2778 |
height |
|
2779 |
"gets height |
|
2780 |
" |
|
2781 |
layout isNil ifTrue:[ |
|
2782 |
^ self preferredExtentY |
|
2783 |
]. |
|
2784 |
^ layout height |
|
2785 |
! |
|
2786 |
||
2787 |
layout |
|
2788 |
"returns my layout ( Rectangle ) |
|
2789 |
" |
|
2790 |
^ layout |
|
2791 |
! |
|
2792 |
||
2793 |
layout:aLayout |
|
2794 |
"set a new layout ( Rectangle ) |
|
2795 |
" |
|
2796 |
layout := aLayout. |
|
2797 |
self redraw. |
|
2798 |
! |
|
2799 |
||
2800 |
preferredExtentX |
|
2801 |
"compute my preferred extent x |
|
2802 |
" |
|
2803 |
|x s| |
|
2804 |
||
2805 |
x := HorizontalInset + HorizontalInset. |
|
2806 |
||
2807 |
rawLabel notNil ifTrue:[ |
|
2808 |
x := x + (rawLabel widthOn:menuPanel). |
|
2809 |
||
2810 |
(s := self shortcutKeyAsString) notNil ifTrue:[ |
|
2811 |
x := x + LabelRightOffset + (s widthOn:menuPanel) |
|
2812 |
]. |
|
2813 |
menuPanel verticalLayout ifTrue:[ |
|
2814 |
self hasSubmenu ifTrue:[ |
|
2815 |
x := x + self rightArrow width. |
|
2816 |
||
464 | 2817 |
s notNil ifTrue:[x := x + ShortcutKeyOffset] |
2818 |
ifFalse:[x := x + LabelRightOffset] |
|
388 | 2819 |
] |
464 | 2820 |
]. |
2821 |
] ifFalse:[ |
|
2822 |
menuPanel verticalLayout ifFalse:[ |
|
2823 |
^ x max:(self preferredSeperatorSize) |
|
388 | 2824 |
] |
2825 |
]. |
|
464 | 2826 |
^ x |
388 | 2827 |
! |
2828 |
||
2829 |
preferredExtentY |
|
2830 |
"compute my preferred extent y |
|
2831 |
" |
|
475 | 2832 |
|y| |
464 | 2833 |
|
2834 |
y := VerticalInset + VerticalInset. |
|
2835 |
||
2836 |
rawLabel notNil ifTrue:[ |
|
2837 |
^ y + (rawLabel heightOn:menuPanel) |
|
2838 |
]. |
|
2839 |
||
2840 |
menuPanel verticalLayout ifTrue:[ |
|
2841 |
^ y max:(self preferredSeperatorSize) |
|
2842 |
]. |
|
2843 |
^ y + (menuPanel font height) |
|
2844 |
! |
|
2845 |
||
2846 |
preferredSeperatorSize |
|
2847 |
"returns preferred extent x or y of a separator |
|
2848 |
" |
|
2849 |
|type| |
|
2850 |
||
2851 |
type := self separatorType. |
|
2852 |
type == #doubleLine ifTrue:[^ 10 ]. |
|
2853 |
type == #singleLine ifTrue:[^ 6 ]. |
|
465 | 2854 |
^ 20 |
388 | 2855 |
! |
2856 |
||
2857 |
width |
|
2858 |
"gets width |
|
2859 |
" |
|
2860 |
layout isNil ifTrue:[ |
|
2861 |
^ self preferredExtentX |
|
2862 |
]. |
|
2863 |
^ layout width |
|
2864 |
! ! |
|
2865 |
||
524 | 2866 |
!MenuPanel::Item methodsFor:'building'! |
2867 |
||
2868 |
aspectAt:aKey |
|
2869 |
"retursns value assigned to key or nil |
|
2870 |
" |
|
2871 |
|appl value| |
|
2872 |
||
2873 |
appl := menuPanel receiver. |
|
2874 |
||
2875 |
(appl isKindOf:ValueModel) ifTrue:[ |
|
2876 |
^ appl value:aKey |
|
2877 |
]. |
|
2878 |
||
2879 |
(appl notNil or:[(appl := menuPanel application) notNil]) ifTrue:[ |
|
2880 |
Object messageNotUnderstoodSignal handle:[:ex|] do:[ |
|
2881 |
(appl isKindOf:ApplicationModel) ifTrue:[value := appl aspectFor:aKey] |
|
2882 |
ifFalse:[value := appl perform:aKey] |
|
2883 |
] |
|
2884 |
]. |
|
2885 |
^ value |
|
2886 |
! ! |
|
2887 |
||
390 | 2888 |
!MenuPanel::Item methodsFor:'change & update'! |
2889 |
||
498 | 2890 |
enabledStateOfMenuChangedTo:aState |
2891 |
"enabled state of menu changed to aState |
|
2892 |
" |
|
2893 |
rawLabel notNil ifTrue:[ |
|
2894 |
self drawLabel |
|
2895 |
]. |
|
2896 |
||
2897 |
! |
|
2898 |
||
390 | 2899 |
update:something with:aParameter from:changedObject |
498 | 2900 |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2901 |
changedObject == self indication ifTrue:[ |
498 | 2902 |
rawLabel icon:(self indicator). |
2903 |
^ self redraw |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2904 |
]. |
498 | 2905 |
|
2906 |
changedObject == enableChannel ifTrue:[ |
|
2907 |
(rawLabel notNil and:[menuPanel canDrawItem]) ifTrue:[ |
|
2908 |
self drawLabel |
|
2909 |
]. |
|
2910 |
^ self |
|
2911 |
]. |
|
2912 |
super update:something with:aParameter from:changedObject |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2913 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2914 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2915 |
updateIndicators |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2916 |
"update indicators |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2917 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2918 |
|indicator| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2919 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2920 |
(indicator := self indicator) notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2921 |
indicator = rawLabel icon ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2922 |
rawLabel icon:indicator. |
465 | 2923 |
^ self redraw. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2924 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2925 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2926 |
|
390 | 2927 |
! ! |
2928 |
||
388 | 2929 |
!MenuPanel::Item methodsFor:'constants'! |
2930 |
||
2931 |
rightArrow |
|
2932 |
"arrow used for submenu indication |
|
2933 |
" |
|
2934 |
^ SelectionInListView rightArrowFormOn:(menuPanel device) |
|
2935 |
! |
|
2936 |
||
2937 |
rightArrowShadow |
|
2938 |
"shadow arrow used for submenu indication |
|
2939 |
" |
|
2940 |
^ SelectionInListView rightArrowShadowFormOn:(menuPanel device) |
|
2941 |
! ! |
|
2942 |
||
2943 |
!MenuPanel::Item methodsFor:'converting'! |
|
2944 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2945 |
asMenuItem |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2946 |
"convert to a MenuItem |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2947 |
" |
466 | 2948 |
|item label rcv| |
2949 |
||
2950 |
label := self label. |
|
2951 |
item := MenuItem labeled:(label printString). |
|
2952 |
||
2953 |
label isImage ifTrue:[ |
|
2954 |
rcv := ResourceRetriever new. |
|
2955 |
rcv className:#MenuEditor. |
|
2956 |
rcv selector:#iconUnknown. |
|
2957 |
item labelImage:rcv. |
|
464 | 2958 |
]. |
466 | 2959 |
|
434 | 2960 |
item activeHelpKey:activeHelpKey. |
460 | 2961 |
|
2962 |
enableChannel notNil ifTrue:[ |
|
2963 |
item enabled:(enableChannel value) |
|
2964 |
]. |
|
2965 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2966 |
item accessCharacterPosition:(self accessCharacterPosition). |
502 | 2967 |
item argument:(self argument). |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2968 |
item nameKey:(self nameKey). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2969 |
item shortcutKeyCharacter:(self shortcutKey). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2970 |
item value:(value value). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2971 |
item indication:(self indication value). |
388 | 2972 |
|
464 | 2973 |
submenuChannel isSymbol ifTrue:[ |
2974 |
item submenuChannel:submenuChannel |
|
2975 |
] ifFalse:[ |
|
2976 |
self submenu notNil ifTrue:[ |
|
2977 |
item submenu:(self submenu asMenu) |
|
2978 |
] |
|
388 | 2979 |
]. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2980 |
^ item |
388 | 2981 |
|
2982 |
! |
|
2983 |
||
2984 |
menuItem:aMenuItem |
|
2985 |
"setup attributes from a MenuItem |
|
2986 |
" |
|
502 | 2987 |
|var lbl| |
389 | 2988 |
|
388 | 2989 |
menuPanel disabledRedrawDo:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2990 |
label := nil. |
434 | 2991 |
activeHelpKey := aMenuItem activeHelpKey. |
390 | 2992 |
self enabled:(aMenuItem enabled). |
388 | 2993 |
self nameKey:(aMenuItem nameKey). |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
2994 |
self indication:(aMenuItem indication). |
390 | 2995 |
|
2996 |
(lbl := aMenuItem labelImage value) isNil ifTrue:[ |
|
2997 |
lbl := aMenuItem label. |
|
2998 |
]. |
|
2999 |
self label:lbl. |
|
3000 |
||
388 | 3001 |
self shortcutKey:(aMenuItem shortcutKeyCharacter). |
389 | 3002 |
|
502 | 3003 |
(var := aMenuItem argument) notNil ifTrue:[ |
3004 |
self argument:var. |
|
3005 |
]. |
|
3006 |
||
3007 |
(var := aMenuItem accessCharacterPosition) notNil ifTrue:[ |
|
3008 |
self accessCharacterPosition:var. |
|
389 | 3009 |
]. |
3010 |
||
464 | 3011 |
submenuChannel := aMenuItem submenuChannel. |
388 | 3012 |
self submenu:(aMenuItem submenu). |
389 | 3013 |
self value:(aMenuItem value). |
388 | 3014 |
] |
3015 |
! ! |
|
3016 |
||
3017 |
!MenuPanel::Item methodsFor:'drawing'! |
|
3018 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3019 |
drawLabel |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3020 |
"draw label |
388 | 3021 |
" |
580 | 3022 |
|y img fg| |
464 | 3023 |
|
3024 |
img := rawLabel. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3025 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3026 |
self enabled ifTrue:[ |
580 | 3027 |
self isSelected ifTrue:[ |
3028 |
fg := menuPanel hilightForegroundColor |
|
3029 |
] ifFalse:[ |
|
3030 |
fg := menuPanel foregroundColor |
|
3031 |
]. |
|
3032 |
menuPanel paint:fg |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3033 |
] ifFalse:[ |
464 | 3034 |
menuPanel paint:(menuPanel disabledForegroundColor). |
3035 |
||
571 | 3036 |
rawLabel isText ifFalse:[ |
467 | 3037 |
"/ remember device image to avoid loosing colors |
571 | 3038 |
disabledImage isNil ifTrue:[ |
3039 |
((img respondsTo:#colorMap) and:[img colorMap notNil]) ifTrue:[ |
|
3040 |
disabledImage := img lightened on:menuPanel device. |
|
3041 |
] ifFalse:[ |
|
3042 |
disabledImage := img |
|
3043 |
] |
|
3044 |
]. |
|
3045 |
img := disabledImage. |
|
464 | 3046 |
] |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3047 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3048 |
|
464 | 3049 |
y := (layout top) + (((layout height) - (img heightOn:menuPanel)) // 2). |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3050 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3051 |
(self textLabel) notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3052 |
y := y + menuPanel font ascent. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3053 |
]. |
464 | 3054 |
img displayOn:menuPanel x:((layout left) + HorizontalInset) y:y. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3055 |
self drawShortcutKey. |
571 | 3056 |
|
580 | 3057 |
"Modified: / 27.10.1997 / 01:40:35 / cg" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3058 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3059 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3060 |
drawSeparatingLines |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3061 |
"draw separating lines |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3062 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3063 |
|l r t b| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3064 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3065 |
menuPanel showSeparatingLines ifTrue:[ |
388 | 3066 |
l := layout left. |
3067 |
r := layout right. |
|
3068 |
t := layout top. |
|
3069 |
b := layout bottom. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3070 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3071 |
menuPanel paint:(menuPanel lightColor). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3072 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3073 |
menuPanel verticalLayout ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3074 |
b := b - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3075 |
t := t - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3076 |
menuPanel displayLineFromX:l y:b toX:r y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3077 |
menuPanel displayLineFromX:l y:t toX:r y:t. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3078 |
b := b - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3079 |
t := t - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3080 |
menuPanel paint:(menuPanel shadowColor). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3081 |
menuPanel displayLineFromX:l y:b toX:r y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3082 |
menuPanel displayLineFromX:l y:t toX:r y:t. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3083 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3084 |
r := r - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3085 |
l := l - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3086 |
menuPanel displayLineFromX:r y:t toX:r y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3087 |
menuPanel displayLineFromX:l y:t toX:l y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3088 |
r := r - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3089 |
l := l - 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3090 |
menuPanel paint:(menuPanel shadowColor). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3091 |
menuPanel displayLineFromX:r y:t toX:r y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3092 |
menuPanel displayLineFromX:l y:t toX:l y:b. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3093 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3094 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3095 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3096 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3097 |
drawSeparator |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3098 |
"draw line separator |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3099 |
" |
601 | 3100 |
|type l r t b x y lightColor shadowColor| |
464 | 3101 |
|
3102 |
type := self separatorType. |
|
3103 |
||
3104 |
(type notNil and:[type ~~ #blankLine]) ifFalse:[ |
|
3105 |
^ self |
|
3106 |
]. |
|
3107 |
||
3108 |
l := layout left. |
|
3109 |
t := layout top. |
|
3110 |
||
601 | 3111 |
shadowColor := menuPanel shadowColor. |
3112 |
lightColor := menuPanel lightColor. |
|
3113 |
||
3114 |
menuPanel paint:shadowColor. |
|
464 | 3115 |
|
3116 |
menuPanel verticalLayout ifTrue:[ |
|
3117 |
l := l + HorizontalInset. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3118 |
r := (layout right) - HorizontalInset. |
464 | 3119 |
y := t - 1 + ((layout height) // 2). |
3120 |
||
3121 |
type == #doubleLine ifTrue:[y := y - 2]. |
|
3122 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3123 |
menuPanel displayLineFromX:l y:y toX:r y:y. |
601 | 3124 |
menuPanel paint:lightColor. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3125 |
y := y + 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3126 |
menuPanel displayLineFromX:l y:y toX:r y:y. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3127 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3128 |
type == #doubleLine ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3129 |
y := y + 3. |
601 | 3130 |
menuPanel paint:shadowColor. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3131 |
menuPanel displayLineFromX:l y:y toX:r y:y. |
601 | 3132 |
menuPanel paint:lightColor. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3133 |
y := y + 1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3134 |
menuPanel displayLineFromX:l y:y toX:r y:y. |
464 | 3135 |
]. |
3136 |
] ifFalse:[ |
|
3137 |
b := layout bottom. |
|
3138 |
x := l - 1 + ((layout width) // 2). |
|
3139 |
||
3140 |
type == #doubleLine ifTrue:[x := x - 2]. |
|
3141 |
||
3142 |
menuPanel displayLineFromX:x y:t toX:x y:b. |
|
601 | 3143 |
menuPanel paint:lightColor. |
464 | 3144 |
x := x + 1. |
3145 |
menuPanel displayLineFromX:x y:t toX:x y:b. |
|
3146 |
||
3147 |
type == #doubleLine ifTrue:[ |
|
3148 |
x := x + 3. |
|
601 | 3149 |
menuPanel paint:shadowColor. |
464 | 3150 |
menuPanel displayLineFromX:x y:t toX:x y:b. |
601 | 3151 |
menuPanel paint:lightColor. |
464 | 3152 |
x := x + 1. |
3153 |
menuPanel displayLineFromX:x y:t toX:x y:b. |
|
388 | 3154 |
] |
3155 |
] |
|
3156 |
||
601 | 3157 |
"Modified: / 31.10.1997 / 15:33:51 / cg" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3158 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3159 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3160 |
drawShortcutKey |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3161 |
"draw the shorcutKey |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3162 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3163 |
|string x y| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3164 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3165 |
(string:= self shortcutKeyAsString) notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3166 |
(x := menuPanel shortKeyInset) == 0 ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3167 |
x := LabelRightOffset + (rawLabel widthOn:menuPanel) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3168 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3169 |
x := (layout left) + x. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3170 |
y := (layout top) + (((layout height) - (string heightOn:menuPanel)) // 2). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3171 |
y := y + menuPanel font ascent. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3172 |
string displayOn:menuPanel x:x y:y. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3173 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3174 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3175 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3176 |
drawSubmenuIndication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3177 |
"draw an arrow in case of having a submenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3178 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3179 |
|form x y col| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3180 |
|
464 | 3181 |
(self submenu notNil and:[menuPanel verticalLayout]) ifTrue:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3182 |
form := self rightArrow. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3183 |
x := (layout right) - form width - HorizontalInset. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3184 |
y := layout top + ((layout height - (form heightOn:menuPanel)) // 2). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3185 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3186 |
self isSelected ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3187 |
menuPanel paint:(menuPanel shadowColor). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3188 |
col := menuPanel lightColor. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3189 |
] ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3190 |
menuPanel paint:(menuPanel lightColor). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3191 |
col := menuPanel shadowColor. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3192 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3193 |
menuPanel displayForm:form x:x y:y. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3194 |
menuPanel paint:col. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3195 |
menuPanel displayForm:(self rightArrowShadow) x:x y:y. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3196 |
] |
388 | 3197 |
|
3198 |
! |
|
3199 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3200 |
redraw |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3201 |
"redraw item |
388 | 3202 |
" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3203 |
|ownBgCol x y paint| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3204 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3205 |
menuPanel canDrawItem ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3206 |
^ self |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3207 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3208 |
self isSelected ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3209 |
paint := menuPanel backgroundColor |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3210 |
] ifTrue:[ |
580 | 3211 |
paint := menuPanel hilightBackgroundColor |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3212 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3213 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3214 |
(ownBgCol := self backgroundColorFromLabel) isNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3215 |
menuPanel paint:paint. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3216 |
menuPanel fillRectangle:layout. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3217 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3218 |
self hasIndication ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3219 |
menuPanel paint:ownBgCol. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3220 |
menuPanel fillRectangle:layout. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3221 |
] ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3222 |
menuPanel paint:paint. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3223 |
x := (rawLabel icon width) + HorizontalInset + 4. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3224 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3225 |
menuPanel fillRectangleX:(layout left) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3226 |
y:(layout top) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3227 |
width:x |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3228 |
height:(layout height). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3229 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3230 |
menuPanel paint:ownBgCol. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3231 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3232 |
menuPanel fillRectangleX:(layout left + x) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3233 |
y:(layout top) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3234 |
width:(layout width - x) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3235 |
height:(layout height). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3236 |
ownBgCol := nil. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3237 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3238 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3239 |
self drawSeparatingLines. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3240 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3241 |
rawLabel notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3242 |
self drawLabel. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3243 |
self drawSubmenuIndication. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3244 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3245 |
(ownBgCol notNil and:[self isSelected]) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3246 |
x := Color black. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3247 |
y := Color white. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3248 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3249 |
ownBgCol brightness > 0.5 ifTrue:[menuPanel paint:(Color black)] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3250 |
ifFalse:[menuPanel paint:(Color white)]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3251 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3252 |
menuPanel displayRectangleX:(layout left + 1) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3253 |
y:(layout top + 1) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3254 |
width:(layout width - 2) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3255 |
height:(layout height - 2). |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3256 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3257 |
menuPanel displayRectangleX:(layout left + 2) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3258 |
y:(layout top + 2) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3259 |
width:(layout width - 4) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3260 |
height:(layout height - 4). |
388 | 3261 |
] |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3262 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3263 |
self drawSeparator |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3264 |
] |
580 | 3265 |
|
3266 |
"Modified: / 27.10.1997 / 01:41:31 / cg" |
|
388 | 3267 |
! ! |
3268 |
||
3269 |
!MenuPanel::Item methodsFor:'initialization'! |
|
3270 |
||
3271 |
destroy |
|
3272 |
"destroy submenu |
|
3273 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3274 |
self submenu:nil. "/ destroy submenus |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3275 |
self enabled:nil. "/ remove dependencies |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3276 |
self indication:nil. "/ remove dependencies |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3277 |
menuPanel := nil. |
388 | 3278 |
! |
3279 |
||
3280 |
in:aPanel |
|
3281 |
"create item in a menuPanel |
|
3282 |
" |
|
3283 |
menuPanel := aPanel. |
|
3284 |
! ! |
|
3285 |
||
3286 |
!MenuPanel::Item methodsFor:'private'! |
|
3287 |
||
3288 |
adornment |
|
3289 |
"returns adornment; if not existing yet a new instance |
|
3290 |
is created |
|
3291 |
" |
|
3292 |
adornment isNil ifTrue:[ |
|
3293 |
adornment := Adornment new |
|
3294 |
]. |
|
3295 |
^ adornment |
|
3296 |
! |
|
3297 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3298 |
backgroundColorFromLabel |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3299 |
"returns the background color derived from label or nil |
388 | 3300 |
" |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3301 |
|run| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3302 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3303 |
label isText ifFalse:[^ nil ]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3304 |
run := label emphasis. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3305 |
run size == 0 ifTrue:[^ nil ]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3306 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3307 |
run := run first. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3308 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3309 |
run size == 0 ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3310 |
(run value isColor and:[run key == #backgroundColor]) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3311 |
^ run value |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3312 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3313 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3314 |
run do:[:r| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3315 |
(r value isColor and:[r key == #backgroundColor]) ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3316 |
^ r value |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3317 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3318 |
] |
388 | 3319 |
]. |
3320 |
^ nil |
|
3321 |
! |
|
3322 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3323 |
indicationValue |
524 | 3324 |
"returns indication value or nil in case of no indication |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3325 |
" |
524 | 3326 |
|indication| |
3327 |
||
3328 |
(indication := self indication) isNil ifTrue:[ |
|
3329 |
^ nil "/ has no indication |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3330 |
]. |
524 | 3331 |
|
3332 |
indication isSymbol ifTrue:[ |
|
3333 |
indication last == $: ifTrue:[ |
|
3334 |
indication := (indication copyWithoutLast:1) asSymbol |
|
3335 |
]. |
|
3336 |
indication := self aspectAt:indication. |
|
3337 |
||
3338 |
(self isKindOfValueHolder:indication) ifTrue:[ |
|
3339 |
self adornment indication:indication. |
|
3340 |
indication addDependent:self. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3341 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3342 |
]. |
524 | 3343 |
^ indication value == true |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3344 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3345 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3346 |
indicationValue:aValue |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3347 |
"returns indication value or nil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3348 |
" |
524 | 3349 |
|indication recv| |
3350 |
||
3351 |
(indication := self indication) isNil ifTrue:[ |
|
3352 |
^ self "/ has no indication |
|
3353 |
]. |
|
3354 |
||
3355 |
indication isSymbol ifFalse:[ |
|
3356 |
(self isKindOfValueHolder:indication) ifTrue:[ "/ is value holder |
|
3357 |
indication value:aValue |
|
3358 |
]. |
|
3359 |
^ self |
|
3360 |
]. |
|
3361 |
recv := menuPanel receiver. |
|
3362 |
||
3363 |
(recv isKindOf:ValueModel) ifTrue:[ |
|
3364 |
recv value:indication value:aValue. |
|
3365 |
] ifFalse:[ |
|
3366 |
indication last == $: ifTrue:[ |
|
3367 |
(recv notNil or:[(recv := menuPanel application) notNil]) ifTrue:[ |
|
3368 |
Object messageNotUnderstoodSignal handle:[:ex| ] |
|
3369 |
do:[ recv perform:indication with:aValue ] |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3370 |
] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3371 |
] |
524 | 3372 |
]. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3373 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3374 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3375 |
indicator |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3376 |
"returns indication form or nil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3377 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3378 |
|value| |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3379 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3380 |
(value := self indicationValue) isNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3381 |
^ nil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3382 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3383 |
^ value ifTrue:[IndicatorOn] ifFalse:[IndicatorOff] |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3384 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3385 |
|
464 | 3386 |
separatorType |
3387 |
"returns type of separator line or nil |
|
388 | 3388 |
" |
390 | 3389 |
|c lbl| |
388 | 3390 |
|
3391 |
rawLabel isNil ifFalse:[ |
|
3392 |
^ nil |
|
3393 |
]. |
|
3394 |
||
390 | 3395 |
(lbl := label value) isNil ifTrue:[ |
388 | 3396 |
^ #singleLine |
3397 |
]. |
|
3398 |
||
390 | 3399 |
lbl size == 1 ifTrue:[ |
3400 |
c := lbl first. |
|
388 | 3401 |
c == $- ifTrue:[^ #singleLine]. |
3402 |
c == $= ifTrue:[^ #doubleLine]. |
|
3403 |
]. |
|
3404 |
^ #blankLine |
|
3405 |
! |
|
3406 |
||
3407 |
updateRawLabel |
|
3408 |
"recreate rawLabel |
|
3409 |
" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3410 |
|char size indicator| |
388 | 3411 |
|
390 | 3412 |
(rawLabel := label value) isString ifFalse:[ |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3413 |
^ menuPanel mustRearrange. |
388 | 3414 |
]. |
3415 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3416 |
rawLabel isText ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3417 |
rawLabel := rawLabel withoutSeparators |
388 | 3418 |
]. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3419 |
size := rawLabel size. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3420 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3421 |
(indicator := self indicator) isNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3422 |
size == 0 ifTrue:[ |
464 | 3423 |
rawLabel := nil. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3424 |
^ menuPanel mustRearrange |
388 | 3425 |
]. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3426 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3427 |
size == 1 ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3428 |
char := rawLabel first. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3429 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3430 |
(char == $- or:[char == $=]) ifTrue:[ "/ other line separators |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3431 |
label := String new:1. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3432 |
label at:1 put:char. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3433 |
rawLabel := nil. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3434 |
^ menuPanel mustRearrange |
388 | 3435 |
] |
3436 |
] |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3437 |
] ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3438 |
size == 0 ifTrue:[rawLabel := label value] |
388 | 3439 |
]. |
3440 |
||
3441 |
rawLabel isText ifFalse:[ |
|
3442 |
rawLabel := Text string:rawLabel emphasis:#bold |
|
3443 |
]. |
|
3444 |
size := self accessCharacterPosition. |
|
3445 |
||
3446 |
(size notNil and:[size <= rawLabel size]) ifTrue:[ |
|
3447 |
rawLabel emphasisAt:size add:#underline |
|
3448 |
]. |
|
3449 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3450 |
(indicator := self indicator) notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3451 |
rawLabel := LabelAndIcon icon:indicator string:rawLabel. |
388 | 3452 |
]. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3453 |
menuPanel mustRearrange. |
388 | 3454 |
! ! |
3455 |
||
3456 |
!MenuPanel::Item methodsFor:'queries'! |
|
3457 |
||
3458 |
canSelect |
|
3459 |
"returns true if item is selectable |
|
3460 |
" |
|
3461 |
^ (self enabled and:[rawLabel notNil]) |
|
3462 |
! |
|
3463 |
||
3464 |
containsPointX:x y:y |
|
3465 |
"returns true if point is contained in my layout |
|
3466 |
" |
|
505 | 3467 |
layout isNil ifFalse:[ |
3468 |
^ ( (x >= layout left) |
|
3469 |
and:[x < layout right |
|
3470 |
and:[y > layout top |
|
3471 |
and:[y <= layout bottom]]] |
|
3472 |
) |
|
3473 |
]. |
|
3474 |
^ false |
|
388 | 3475 |
! |
3476 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3477 |
hasIndication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3478 |
"returns true if on/off indication exists |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3479 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3480 |
^ self indication notNil |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3481 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3482 |
|
388 | 3483 |
hasSubmenu |
3484 |
"returns true if a submenu exists |
|
3485 |
" |
|
3486 |
^ self submenu notNil |
|
3487 |
! |
|
3488 |
||
3489 |
isEnabled |
|
3490 |
"returns enabled state |
|
3491 |
" |
|
3492 |
^ self enabled |
|
3493 |
! |
|
3494 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3495 |
isKindOfValueHolder:something |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3496 |
"returns true if something is kind of vlaue holder |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3497 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3498 |
^ ((something respondsTo:#value:) and:[something isBlock not]) |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3499 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3500 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3501 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3502 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3503 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3504 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3505 |
|
388 | 3506 |
shortcutKeyAsString |
3507 |
"converts shortcutKey to a text object |
|
3508 |
" |
|
475 | 3509 |
|nm key| |
388 | 3510 |
|
3511 |
"/ this is somewhat complicated: we have the symbolic key at hand, |
|
3512 |
"/ but want to show the untranslated (inverse keyBoardMapped) key & modifier |
|
3513 |
"/ |
|
3514 |
||
3515 |
(key := self shortcutKey) isNil ifTrue:[ |
|
3516 |
^ nil |
|
3517 |
]. |
|
3518 |
||
3519 |
key isCharacter ifTrue:[ |
|
3520 |
nm := key asString |
|
3521 |
] ifFalse:[ |
|
3522 |
nm := menuPanel device keyboardMap keyAtValue:key ifAbsent:key. |
|
3523 |
"/ |
|
3524 |
"/ some modifier-key combination ? |
|
3525 |
"/ |
|
3526 |
||
3527 |
(nm startsWith:#Cmd) ifTrue:[ |
|
3528 |
nm := (self shortcutKeyPrefixFor:#Cmd) , (nm copyFrom:4) |
|
3529 |
] ifFalse:[(nm startsWith:#Alt) ifTrue:[ |
|
3530 |
nm := (self shortcutKeyPrefixFor:#Alt) , (nm copyFrom:4) |
|
3531 |
] ifFalse:[(nm startsWith:#Meta) ifTrue:[ |
|
3532 |
nm := (self shortcutKeyPrefixFor:#Meta), (nm copyFrom:5) |
|
3533 |
] |
|
3534 |
ifFalse:[(nm startsWith:#Ctrl) ifTrue:[ |
|
3535 |
nm := (self shortcutKeyPrefixFor:#Ctrl), (nm copyFrom:5) |
|
3536 |
] ifFalse:[ |
|
3537 |
nm := nm asString |
|
3538 |
]]]] |
|
3539 |
]. |
|
3540 |
^ Text string:nm emphasis:#bold |
|
3541 |
||
3542 |
||
3543 |
! |
|
3544 |
||
3545 |
shortcutKeyPrefixFor:aModifier |
|
3546 |
"returns prefix assigned to a modifier |
|
3547 |
" |
|
3548 |
|m| |
|
3549 |
||
3550 |
m := menuPanel device modifierKeyTopFor:aModifier. |
|
3551 |
||
3552 |
m notNil ifTrue:[ |
|
3553 |
^ m , '-' |
|
3554 |
]. |
|
3555 |
^ aModifier. |
|
3556 |
! ! |
|
3557 |
||
3558 |
!MenuPanel::Item methodsFor:'selection'! |
|
3559 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3560 |
hideSubmenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3561 |
"hide submenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3562 |
" |
580 | 3563 |
|subMenu id| |
464 | 3564 |
|
3565 |
subMenu := self submenu. |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3566 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3567 |
subMenu realized ifFalse:[ |
580 | 3568 |
(id := subMenu id) notNil ifTrue:[ |
3569 |
menuPanel device unmapWindow:id |
|
3570 |
] |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3571 |
] ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3572 |
subMenu hide |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3573 |
] |
580 | 3574 |
|
3575 |
"Modified: / 27.10.1997 / 04:13:13 / cg" |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3576 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3577 |
|
388 | 3578 |
isSelected |
3579 |
"returns true if item is selected |
|
3580 |
" |
|
3581 |
^ menuPanel selection == self |
|
3582 |
! |
|
3583 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3584 |
openSubmenuAt:aPoint |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3585 |
"open submenu at a point |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3586 |
" |
464 | 3587 |
|windowGrp subMenu| |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3588 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3589 |
windowGrp := menuPanel topMenu windowGroup. |
464 | 3590 |
subMenu := self setupSubmenu. |
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3591 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3592 |
windowGrp notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3593 |
subMenu windowGroup:windowGrp. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3594 |
windowGrp addTopView:subMenu. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3595 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3596 |
subMenu fixSize. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3597 |
subMenu origin:aPoint. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3598 |
subMenu makeFullyVisible. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3599 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3600 |
subMenu realized ifFalse:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3601 |
subMenu realize. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3602 |
] ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3603 |
menuPanel topMenu device mapWindow:subMenu id. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3604 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3605 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3606 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3607 |
|
388 | 3608 |
selected:aState |
3609 |
"change selection to a state. Dependant on the state open or hide an existing |
|
3610 |
submenu and perform a redraw |
|
3611 |
" |
|
3612 |
|p d subMenu| |
|
3613 |
||
3614 |
subMenu := self submenu. |
|
3615 |
||
3616 |
aState ifFalse:[ |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3617 |
self redraw. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3618 |
subMenu notNil ifTrue:[ |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3619 |
self hideSubmenu |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3620 |
]. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3621 |
^ self |
388 | 3622 |
]. |
3623 |
menuPanel shown ifFalse:[^ self]. |
|
3624 |
self redraw. |
|
3625 |
||
3626 |
subMenu isNil ifTrue:[ |
|
3627 |
^ menuPanel grabMouseAndKeyboard |
|
3628 |
]. |
|
3629 |
||
3630 |
menuPanel verticalLayout ifTrue:[p := (layout right) @ (layout top)] |
|
3631 |
ifFalse:[p := (layout left) @ (layout bottom)]. |
|
3632 |
||
3633 |
d := menuPanel device. |
|
3634 |
p := d translatePoint:p from:(menuPanel id) to:(d rootWindowId). |
|
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3635 |
self openSubmenuAt:p. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3636 |
|
388 | 3637 |
|
3638 |
! ! |
|
3639 |
||
3640 |
!MenuPanel::Item::Adornment methodsFor:'accessing'! |
|
3641 |
||
3642 |
accessCharacterPosition |
|
3643 |
"get the index of the access character in the label text or string, or nil if none |
|
3644 |
" |
|
3645 |
^ accessCharacterPosition |
|
3646 |
! |
|
3647 |
||
3648 |
accessCharacterPosition:anIndexOrNil |
|
3649 |
"set the index of the access character in the label text or string, or nil if none |
|
3650 |
" |
|
3651 |
accessCharacterPosition := anIndexOrNil |
|
3652 |
! |
|
3653 |
||
3654 |
argument |
|
3655 |
"ST/X goody; get argunment to a selector or block |
|
3656 |
" |
|
3657 |
^ argument |
|
3658 |
! |
|
3659 |
||
3660 |
argument:anArgumentOrNil |
|
3661 |
"ST/X goody; set argunment to a selector or block |
|
3662 |
" |
|
3663 |
argument := anArgumentOrNil |
|
3664 |
! |
|
3665 |
||
407
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3666 |
indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3667 |
"get has on/off indicator value |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3668 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3669 |
^ indication |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3670 |
! |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3671 |
|
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3672 |
indication:something |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3673 |
"set has on/off indicator value |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3674 |
" |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3675 |
indication := something. |
40554a07d5aa
fix bugs; implement indication; text with backgroundColor
ca
parents:
399
diff
changeset
|
3676 |
! |
388 | 3677 |
|
3678 |
shortcutKey |
|
3679 |
"get the character that is used as a shortcut key for this item |
|
3680 |
" |
|
3681 |
^ shortcutKey |
|
3682 |
! |
|
3683 |
||
3684 |
shortcutKey:aKeyOrNil |
|
3685 |
"set the character that is used as a shortcut key for this item |
|
3686 |
" |
|
3687 |
shortcutKey := aKeyOrNil |
|
3688 |
! ! |
|
3689 |
||
3690 |
!MenuPanel class methodsFor:'documentation'! |
|
3691 |
||
3692 |
version |
|
601 | 3693 |
^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.36 1997-11-02 17:44:14 cg Exp $' |
388 | 3694 |
! ! |
3695 |
MenuPanel initialize! |