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