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