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