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