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