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