0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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 |
SelectionInListView subclass:#MenuView
|
|
14 |
instanceVariableNames:'selectors args receiver enableFlags
|
59
|
15 |
disabledFgColor onOffFlags subMenus
|
|
16 |
subMenuShown superMenu checkColor
|
77
|
17 |
lineLevel lineInset masterView hilightStyle'
|
60
|
18 |
classVariableNames:'DefaultFont DefaultCheckColor DefaultViewBackground
|
59
|
19 |
DefaultForegroundColor
|
|
20 |
DefaultBackgroundColor
|
|
21 |
DefaultDisabledForegroundColor
|
|
22 |
DefaultHilightForegroundColor
|
|
23 |
DefaultHilightBackgroundColor
|
77
|
24 |
DefaultHilightLevel DefaultHilightStyle
|
59
|
25 |
DefaultLineLevel
|
|
26 |
DefaultShadowColor DefaultLightColor'
|
0
|
27 |
poolDictionaries:''
|
|
28 |
category:'Views-Menus'
|
|
29 |
!
|
|
30 |
|
|
31 |
MenuView comment:'
|
5
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
33 |
All Rights Reserved
|
0
|
34 |
|
97
|
35 |
$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.19 1995-03-06 19:29:00 claus Exp $
|
3
|
36 |
'!
|
|
37 |
|
|
38 |
!MenuView class methodsFor:'documentation'!
|
|
39 |
|
38
|
40 |
copyright
|
|
41 |
"
|
|
42 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
43 |
All Rights Reserved
|
38
|
44 |
|
|
45 |
This software is furnished under a license and may be used
|
|
46 |
only in accordance with the terms of that license and with the
|
|
47 |
inclusion of the above copyright notice. This software may not
|
|
48 |
be provided or otherwise made available to, or used by, any
|
|
49 |
other person. No title to or ownership of the software is
|
|
50 |
hereby transferred.
|
|
51 |
"
|
|
52 |
!
|
|
53 |
|
|
54 |
version
|
|
55 |
"
|
97
|
56 |
$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.19 1995-03-06 19:29:00 claus Exp $
|
38
|
57 |
"
|
|
58 |
!
|
|
59 |
|
3
|
60 |
documentation
|
|
61 |
"
|
63
|
62 |
a menu view used for both pull-down-menus and pop-up-menus (and also,
|
|
63 |
for nonModal menus, such as the Launchers click-menu).
|
38
|
64 |
the action to be performed can be defined either as:
|
0
|
65 |
|
38
|
66 |
1) action:aBlockWithOneArg
|
|
67 |
which defines a block to be called with the line number (1..n)
|
|
68 |
of the selected line.
|
0
|
69 |
|
38
|
70 |
2) selectors:selectorArray [args: argarray] receiver:anObject
|
|
71 |
which defines the messages to be sent to receiver for each
|
|
72 |
line.
|
0
|
73 |
|
38
|
74 |
It is also possible to define both actionBlock and selectorArray.
|
0
|
75 |
|
63
|
76 |
The wellknown popups are created by wrapping a MenuView into an instance of
|
|
77 |
PopUpMenu (read the description of popupmenu).
|
|
78 |
|
38
|
79 |
menu entries starting with '\c' are check-entries.
|
|
80 |
menu entries conisting of '-' alone, are separating lines.
|
63
|
81 |
menu entries conisting of '=' alone, are double separating lines.
|
|
82 |
"
|
|
83 |
!
|
21
|
84 |
|
63
|
85 |
examples
|
|
86 |
"
|
45
|
87 |
Examples:
|
59
|
88 |
Notice: normally, menuviews are wrapped into either a popup-
|
|
89 |
menu or pulldown-menu. But they can also be used stand-alone
|
|
90 |
as in:
|
45
|
91 |
|
59
|
92 |
|m|
|
|
93 |
m := MenuView
|
|
94 |
labels:#('foo'
|
|
95 |
'bar'
|
|
96 |
'baz')
|
|
97 |
selectors:#(
|
|
98 |
#foo
|
|
99 |
#bar
|
|
100 |
#baz)
|
|
101 |
receiver:nil.
|
|
102 |
m open
|
3
|
103 |
"
|
|
104 |
! !
|
0
|
105 |
|
59
|
106 |
!MenuView class methodsFor:'defaults'!
|
|
107 |
|
|
108 |
updateStyleCache
|
60
|
109 |
DefaultViewBackground := StyleSheet colorAt:'menuViewBackground'.
|
|
110 |
DefaultForegroundColor := StyleSheet colorAt:'menuForegroundColor'.
|
|
111 |
DefaultBackgroundColor := StyleSheet colorAt:'menuBackgroundColor'.
|
|
112 |
DefaultShadowColor := StyleSheet colorAt:'menuShadowColor'.
|
|
113 |
DefaultLightColor := StyleSheet colorAt:'menuLightColor'.
|
|
114 |
DefaultHilightForegroundColor := StyleSheet colorAt:'menuHilightForegroundColor'.
|
|
115 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'menuHilightBackgroundColor'.
|
59
|
116 |
DefaultHilightLevel := StyleSheet at:'menuHilightLevel'.
|
77
|
117 |
DefaultHilightStyle := StyleSheet at:'menuHilightStyle'.
|
59
|
118 |
DefaultLineLevel := StyleSheet at:'menuSeparatingLineLevel'.
|
60
|
119 |
DefaultDisabledForegroundColor := StyleSheet colorAt:'menuDisabledForegroundColor' default:Color darkGrey.
|
|
120 |
DefaultCheckColor := StyleSheet colorAt:'menuCheckColor'.
|
|
121 |
DefaultFont := StyleSheet fontAt:'menuFont'.
|
0
|
122 |
! !
|
|
123 |
|
|
124 |
!MenuView class methodsFor:'instance creation'!
|
|
125 |
|
|
126 |
labels:labels selectors:selArray args:argArray receiver:anObject in:aView
|
|
127 |
"create and return a new MenuView in aView
|
|
128 |
- receiverObject gets message from selectorArray with argument
|
|
129 |
from argArray"
|
|
130 |
|
|
131 |
^ (self in:aView) labels:labels
|
59
|
132 |
selectors:selArray
|
|
133 |
args:argArray
|
|
134 |
receiver:anObject
|
0
|
135 |
!
|
|
136 |
|
|
137 |
labels:labels selectors:selArray receiver:anObject in:aView
|
|
138 |
"create and return a new MenuView in aView
|
|
139 |
- receiverObject gets message from selectorArray without argument"
|
|
140 |
|
|
141 |
^ (self in:aView) labels:labels
|
59
|
142 |
selectors:selArray
|
|
143 |
args:nil
|
|
144 |
receiver:anObject
|
0
|
145 |
!
|
|
146 |
|
|
147 |
labels:labels selector:aSelector args:argArray receiver:anObject in:aTopMenu
|
|
148 |
"create and return a new MenuView
|
|
149 |
- receiverObject gets message aSelector with argument from
|
|
150 |
argArray for all entries"
|
|
151 |
|
|
152 |
^ (self in:aTopMenu) labels:labels
|
59
|
153 |
selectors:aSelector
|
|
154 |
args:argArray
|
|
155 |
receiver:anObject
|
0
|
156 |
!
|
|
157 |
|
|
158 |
labels:labels selector:aSelector args:argArray receiver:anObject for:aTopMenu
|
|
159 |
"create and return a new MenuView
|
|
160 |
- receiverObject gets message aSelector with argument from
|
|
161 |
argArray for all entries"
|
|
162 |
|
|
163 |
^ (self in:(aTopMenu superView)) labels:labels
|
59
|
164 |
selectors:aSelector
|
|
165 |
args:argArray
|
|
166 |
receiver:anObject
|
0
|
167 |
!
|
|
168 |
|
|
169 |
labels:labels selectors:selArray args:argArray receiver:anObject for:aTopMenu
|
|
170 |
^ (self in:(aTopMenu superView)) labels:labels
|
59
|
171 |
selectors:selArray
|
|
172 |
args:argArray
|
|
173 |
receiver:anObject
|
0
|
174 |
!
|
|
175 |
|
|
176 |
labels:labels selectors:selArray receiver:anObject for:aTopMenu
|
|
177 |
^ (self in:(aTopMenu superView)) labels:labels
|
59
|
178 |
selectors:selArray
|
|
179 |
args:nil
|
|
180 |
receiver:anObject
|
38
|
181 |
!
|
|
182 |
|
|
183 |
labels:labels selectors:selArray receiver:anObject
|
|
184 |
"create and return a new MenuView. The parent view
|
|
185 |
should be set later."
|
|
186 |
|
|
187 |
^ (self new) labels:labels
|
59
|
188 |
selectors:selArray
|
|
189 |
args:nil
|
|
190 |
receiver:anObject
|
38
|
191 |
!
|
|
192 |
|
|
193 |
labels:labels selectors:selArray
|
|
194 |
"create and return a new MenuView. The parent veiw
|
|
195 |
and receiver should be set later."
|
|
196 |
|
|
197 |
^ (self new) labels:labels
|
59
|
198 |
selectors:selArray
|
|
199 |
args:nil
|
|
200 |
receiver:nil
|
38
|
201 |
!
|
|
202 |
|
|
203 |
labels:labels
|
|
204 |
"create and return a new MenuView. The parent view,
|
|
205 |
selectors and receiver should be set later."
|
|
206 |
|
|
207 |
^ (self new) labels:labels
|
59
|
208 |
selectors:nil
|
|
209 |
args:nil
|
|
210 |
receiver:nil
|
0
|
211 |
! !
|
|
212 |
|
77
|
213 |
!MenuView methodsFor:'initialize / release'!
|
0
|
214 |
|
|
215 |
initialize
|
|
216 |
super initialize.
|
|
217 |
|
38
|
218 |
((style ~~ #normal) and:[style ~~ #mswindows]) ifTrue:[
|
59
|
219 |
borderWidth := 1.
|
|
220 |
self level:1
|
0
|
221 |
]
|
|
222 |
!
|
|
223 |
|
|
224 |
reinitialize
|
|
225 |
"this is called right after snapIn;
|
|
226 |
a kind of kludge - reset cursor"
|
|
227 |
|
|
228 |
super reinitialize.
|
|
229 |
selection := nil. "self selection:nil."
|
|
230 |
self cursor:Cursor hand
|
|
231 |
!
|
|
232 |
|
7
|
233 |
initStyle
|
|
234 |
super initStyle.
|
|
235 |
|
59
|
236 |
DefaultFont notNil ifTrue:[
|
|
237 |
font := DefaultFont on:device
|
|
238 |
].
|
|
239 |
|
|
240 |
DefaultCheckColor notNil ifTrue:[
|
|
241 |
checkColor := DefaultCheckColor
|
|
242 |
] ifFalse:[
|
|
243 |
checkColor := fgColor.
|
|
244 |
].
|
|
245 |
DefaultDisabledForegroundColor notNil ifTrue:[
|
|
246 |
disabledFgColor := DefaultDisabledForegroundColor
|
|
247 |
] ifFalse:[
|
|
248 |
disabledFgColor := Color darkGrey
|
|
249 |
].
|
|
250 |
disabledFgColor := disabledFgColor on:device.
|
|
251 |
|
|
252 |
DefaultForegroundColor notNil ifTrue:[
|
|
253 |
fgColor := DefaultForegroundColor on:device
|
|
254 |
].
|
|
255 |
DefaultBackgroundColor notNil ifTrue:[
|
|
256 |
bgColor := DefaultBackgroundColor on:device
|
|
257 |
].
|
|
258 |
|
|
259 |
DefaultShadowColor notNil ifTrue:[
|
|
260 |
shadowColor := DefaultShadowColor on:device
|
|
261 |
].
|
|
262 |
DefaultLightColor notNil ifTrue:[
|
|
263 |
lightColor := DefaultLightColor on:device
|
|
264 |
].
|
|
265 |
|
|
266 |
DefaultHilightLevel notNil ifTrue:[
|
|
267 |
hilightLevel := DefaultHilightLevel
|
38
|
268 |
] ifFalse:[
|
59
|
269 |
hilightLevel := 0.
|
|
270 |
].
|
77
|
271 |
hilightStyle := DefaultHilightStyle.
|
60
|
272 |
|
59
|
273 |
StyleSheet is3D ifTrue:[
|
60
|
274 |
"some 3D style menu - set hilight defaults to same"
|
59
|
275 |
|
|
276 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
277 |
hilightFgColor := DefaultHilightForegroundColor on:device
|
|
278 |
] ifFalse:[
|
|
279 |
hilightFgColor := fgColor.
|
|
280 |
].
|
|
281 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
282 |
hilightBgColor := DefaultHilightBackgroundColor on:device
|
|
283 |
] ifFalse:[
|
|
284 |
hilightBgColor := bgColor.
|
|
285 |
].
|
|
286 |
DefaultLineLevel notNil ifTrue:[
|
|
287 |
lineLevel := DefaultLineLevel
|
|
288 |
] ifFalse:[
|
|
289 |
lineLevel := -1.
|
|
290 |
]
|
|
291 |
] ifFalse:[
|
60
|
292 |
"some 2D style menu - set hilight defaults to inverse"
|
59
|
293 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
294 |
hilightFgColor := DefaultHilightForegroundColor on:device
|
|
295 |
] ifFalse:[
|
|
296 |
hilightFgColor := bgColor.
|
|
297 |
].
|
|
298 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
299 |
hilightBgColor := DefaultHilightBackgroundColor on:device
|
|
300 |
] ifFalse:[
|
|
301 |
hilightBgColor := fgColor.
|
|
302 |
].
|
|
303 |
DefaultLineLevel notNil ifTrue:[
|
|
304 |
lineLevel := DefaultLineLevel
|
|
305 |
] ifFalse:[
|
|
306 |
lineLevel := 0.
|
|
307 |
]
|
|
308 |
].
|
|
309 |
|
|
310 |
"
|
|
311 |
the following has to be changed to
|
|
312 |
use the styleSheet too
|
|
313 |
"
|
60
|
314 |
(style ~~ #normal) ifTrue:[
|
59
|
315 |
"the inset on each side"
|
|
316 |
style == #motif ifTrue:[
|
|
317 |
lineInset := 0
|
|
318 |
] ifFalse:[
|
|
319 |
lineInset := (device horizontalPixelPerMillimeter * 0.8) rounded.
|
|
320 |
]
|
38
|
321 |
].
|
7
|
322 |
(style == #iris) ifTrue:[
|
59
|
323 |
device hasGreyscales ifTrue:[
|
|
324 |
lineSpacing := 3
|
|
325 |
].
|
38
|
326 |
].
|
|
327 |
(style == #motif) ifTrue:[
|
59
|
328 |
lineSpacing := (2 * hilightLevel)
|
38
|
329 |
].
|
77
|
330 |
hilightStyle == #openwin ifTrue:[
|
59
|
331 |
"add some space for rounded-hilight area"
|
|
332 |
self leftMargin:10.
|
38
|
333 |
].
|
|
334 |
(style == #st80) ifTrue:[
|
59
|
335 |
level := 0.
|
|
336 |
lineInset := 0
|
38
|
337 |
].
|
60
|
338 |
DefaultViewBackground notNil ifTrue:[
|
|
339 |
viewBackground := DefaultViewBackground on:device
|
|
340 |
].
|
7
|
341 |
!
|
|
342 |
|
0
|
343 |
initEvents
|
|
344 |
super initEvents.
|
|
345 |
self enableLeaveEvents.
|
77
|
346 |
windowGroup notNil ifTrue:[
|
|
347 |
windowGroup sensor compressMotionEvents:true
|
|
348 |
]
|
0
|
349 |
!
|
|
350 |
|
|
351 |
create
|
|
352 |
super create.
|
7
|
353 |
subMenuShown := nil.
|
0
|
354 |
self recomputeSize
|
|
355 |
!
|
|
356 |
|
|
357 |
recreate
|
|
358 |
super recreate.
|
77
|
359 |
hilightStyle == #openwin ifTrue:[
|
59
|
360 |
self leftMargin:10.
|
38
|
361 |
].
|
0
|
362 |
self recomputeSize
|
77
|
363 |
!
|
|
364 |
|
|
365 |
destroy
|
|
366 |
super destroy.
|
|
367 |
|
|
368 |
"
|
|
369 |
have to destroy the submenus manually here,
|
|
370 |
since they are no real subviews of myself
|
|
371 |
"
|
|
372 |
subMenus notNil ifTrue:[
|
|
373 |
subMenus do:[:m |
|
|
374 |
m notNil ifTrue:[
|
|
375 |
m destroy
|
|
376 |
]
|
|
377 |
].
|
|
378 |
subMenus := nil
|
|
379 |
]
|
0
|
380 |
! !
|
|
381 |
|
|
382 |
!MenuView methodsFor:'accessing'!
|
|
383 |
|
7
|
384 |
superMenu:aMenu
|
|
385 |
"set the menu I am contained in
|
|
386 |
- need this to hide main menus when a submenu performed its action"
|
|
387 |
|
|
388 |
superMenu := aMenu
|
|
389 |
!
|
|
390 |
|
|
391 |
superMenu
|
|
392 |
"ret the menu I am contained in
|
|
393 |
- need this to hide main menus when a submenu performed its action"
|
|
394 |
|
|
395 |
^ superMenu
|
|
396 |
!
|
|
397 |
|
70
|
398 |
masterView
|
|
399 |
"return the popup-masterview I am contained in."
|
|
400 |
|
|
401 |
^ masterView
|
|
402 |
!
|
|
403 |
|
|
404 |
masterView:aPopUpView
|
|
405 |
"set the popup-masterview I am contained in."
|
|
406 |
|
|
407 |
masterView := aPopUpView
|
|
408 |
!
|
|
409 |
|
7
|
410 |
subMenuShown
|
|
411 |
"return the currently visible submenu - or nil if there is none"
|
|
412 |
|
|
413 |
^ subMenuShown
|
|
414 |
!
|
|
415 |
|
0
|
416 |
labels
|
|
417 |
"return the menu-labels"
|
|
418 |
|
|
419 |
^ list
|
|
420 |
!
|
|
421 |
|
|
422 |
labels:text
|
|
423 |
"set the labels to the argument, text"
|
|
424 |
|
38
|
425 |
(text isString) ifTrue:[
|
81
|
426 |
self list:(text asStringCollection)
|
0
|
427 |
] ifFalse:[
|
59
|
428 |
self list:text
|
0
|
429 |
].
|
21
|
430 |
enableFlags := Array new:(list size) withAll:true.
|
77
|
431 |
onOffFlags := Array new:(list size).
|
|
432 |
text keysAndValuesDo:[:index :line |
|
97
|
433 |
(line notNil and:[line includes:$\ ]) ifTrue:[
|
77
|
434 |
onOffFlags at:index put:false
|
|
435 |
].
|
|
436 |
].
|
0
|
437 |
self recomputeSize
|
|
438 |
!
|
|
439 |
|
|
440 |
labelAt:indexOrName put:aString
|
|
441 |
"change the label at index to be aString"
|
|
442 |
|
|
443 |
|i|
|
|
444 |
|
|
445 |
i := self indexOf:indexOrName.
|
3
|
446 |
i == 0 ifTrue:[^ self].
|
0
|
447 |
list at:i put:aString.
|
3
|
448 |
|
0
|
449 |
"create onOff flags, if this label has a check-mark"
|
|
450 |
(aString startsWith:'\c') ifTrue:[
|
59
|
451 |
onOffFlags isNil ifTrue:[
|
65
|
452 |
onOffFlags := Array new:(list size)
|
59
|
453 |
] ifFalse:[
|
|
454 |
[onOffFlags size < list size] whileTrue:[
|
65
|
455 |
onOffFlags := onOffFlags copyWith:nil
|
59
|
456 |
]
|
|
457 |
].
|
|
458 |
onOffFlags at:i put:false
|
0
|
459 |
].
|
|
460 |
self recomputeSize
|
|
461 |
!
|
|
462 |
|
|
463 |
font:aFont
|
|
464 |
"adjust size for new font"
|
|
465 |
|
|
466 |
super font:(aFont on:device).
|
|
467 |
self recomputeSize
|
|
468 |
!
|
|
469 |
|
59
|
470 |
addSeparatingLine
|
|
471 |
"add a separating line"
|
|
472 |
|
|
473 |
self addLabel:'-' selector:nil
|
|
474 |
!
|
|
475 |
|
|
476 |
addSeparatingLineAfter:aLabelOrSelectorOrNumber
|
|
477 |
"add a separating line"
|
|
478 |
|
|
479 |
self addLabel:'-' selector:nil after:aLabelOrSelectorOrNumber
|
|
480 |
!
|
|
481 |
|
0
|
482 |
addLabel:aLabel selector:aSelector
|
|
483 |
"add another label/selector pair"
|
|
484 |
|
|
485 |
list isNil ifTrue:[
|
59
|
486 |
list := Array with:aLabel
|
0
|
487 |
] ifFalse:[
|
59
|
488 |
list := list copyWith:aLabel
|
0
|
489 |
].
|
|
490 |
selectors := selectors copyWith:aSelector.
|
|
491 |
enableFlags := enableFlags copyWith:true.
|
|
492 |
self recomputeSize
|
|
493 |
!
|
|
494 |
|
|
495 |
addLabel:aLabel selector:aSelector arg:anArg
|
|
496 |
"add another label/selector/argument trio"
|
|
497 |
|
|
498 |
list isNil ifTrue:[
|
59
|
499 |
list := Array with:aLabel
|
0
|
500 |
] ifFalse:[
|
59
|
501 |
list := list copyWith:aLabel
|
0
|
502 |
].
|
|
503 |
selectors := selectors copyWith:aSelector.
|
|
504 |
args := args copyWith:anArg.
|
|
505 |
enableFlags := enableFlags copyWith:true.
|
|
506 |
self recomputeSize
|
|
507 |
!
|
|
508 |
|
38
|
509 |
addLabel:aLabel selector:aSelector after:aLabelOrSelectorOrNumber
|
|
510 |
"insert another label/selector pair at some place.
|
|
511 |
Being very friendly here, allowing label-string, selector or numeric
|
95
|
512 |
index for the argument aLabelOrSelectorOrNumber.
|
|
513 |
|
|
514 |
To be independent of the entries label, we recommend you use the selector
|
|
515 |
as index; in systems which translate strings for national variants,
|
|
516 |
this makes your code easier to maintain."
|
|
517 |
|
|
518 |
^ self addLabel:aLabel
|
|
519 |
selector:aSelector
|
|
520 |
before:(self indexOf:aLabelOrSelectorOrNumber) + 1
|
|
521 |
"
|
|
522 |
|v1 v2 v3 v4|
|
|
523 |
|
|
524 |
v1 := CodeView new realize.
|
|
525 |
|
|
526 |
v2 := CodeView new realize.
|
|
527 |
v2 middleButtonMenu menuView addLabel:'new entry' selector:#foo after:'paste'.
|
|
528 |
|
|
529 |
v3 := CodeView new realize.
|
|
530 |
v3 middleButtonMenu menuView addLabel:'new entry' selector:#foo after:#others.
|
|
531 |
|
|
532 |
v4 := CodeView new realize.
|
|
533 |
v4 middleButtonMenu menuView addLabel:'new entry' selector:#foo after:1.
|
|
534 |
"
|
|
535 |
!
|
|
536 |
|
|
537 |
addLabel:aLabel selector:aSelector before:aLabelOrSelectorOrNumber
|
|
538 |
"insert another label/selector pair at some place.
|
|
539 |
Being very friendly here, allowing label-string, selector or numeric
|
|
540 |
index for the argument aLabelOrSelectorOrNumber.
|
|
541 |
|
|
542 |
To be independent of the entries label, we recommend you use the selector
|
|
543 |
as index; in systems which translate strings for national variants,
|
|
544 |
this makes your code easier to maintain."
|
38
|
545 |
|
|
546 |
|idx|
|
|
547 |
|
|
548 |
list isNil ifTrue:[
|
59
|
549 |
^ self addLabel:aLabel selector:aSelector
|
38
|
550 |
].
|
|
551 |
"
|
|
552 |
be user friendly - allow both label or selector
|
|
553 |
to be passed
|
|
554 |
"
|
95
|
555 |
idx := self indexOf:aLabelOrSelectorOrNumber.
|
60
|
556 |
(idx between:1 and:list size) ifFalse:[
|
|
557 |
"add to end"
|
|
558 |
^ self addLabel:aLabel selector:aSelector
|
|
559 |
].
|
|
560 |
|
95
|
561 |
list := list asOrderedCollection.
|
|
562 |
list add:aLabel beforeIndex:idx.
|
|
563 |
selectors := selectors asOrderedCollection.
|
|
564 |
selectors add:aSelector beforeIndex:idx.
|
|
565 |
enableFlags := enableFlags asOrderedCollection.
|
|
566 |
enableFlags add:true beforeIndex:idx.
|
60
|
567 |
subMenus notNil ifTrue:[
|
95
|
568 |
subMenus := subMenus asOrderedCollection.
|
|
569 |
subMenus add:nil beforeIndex:idx.
|
60
|
570 |
].
|
|
571 |
args notNil ifTrue:[
|
95
|
572 |
args := args asOrderedCollection.
|
|
573 |
args add:nil beforeIndex:idx.
|
60
|
574 |
].
|
|
575 |
self recomputeSize
|
|
576 |
|
|
577 |
"
|
95
|
578 |
|v1 v2 v3 v4|
|
|
579 |
|
|
580 |
v1 := CodeView new realize.
|
|
581 |
|
|
582 |
v2 := CodeView new realize.
|
|
583 |
v2 middleButtonMenu menuView addLabel:'new entry' selector:#foo before:'paste'.
|
|
584 |
|
|
585 |
v3 := CodeView new realize.
|
|
586 |
v3 middleButtonMenu menuView addLabel:'new entry' selector:#foo before:#again.
|
|
587 |
|
|
588 |
v4 := CodeView new realize.
|
|
589 |
v4 middleButtonMenu menuView addLabel:'new entry' selector:#foo before:1.
|
60
|
590 |
"
|
|
591 |
!
|
|
592 |
|
38
|
593 |
remove:indexOrName
|
|
594 |
"remove the label at index"
|
|
595 |
|
|
596 |
|i|
|
|
597 |
|
|
598 |
i := self indexOf:indexOrName.
|
|
599 |
i == 0 ifTrue:[^ self].
|
|
600 |
list := list asOrderedCollection removeIndex:i.
|
|
601 |
selectors := selectors asOrderedCollection removeIndex:i.
|
|
602 |
enableFlags := enableFlags asOrderedCollection removeIndex:i.
|
|
603 |
subMenus notNil ifTrue:[
|
59
|
604 |
subMenus := subMenus asOrderedCollection removeIndex:i.
|
38
|
605 |
].
|
|
606 |
self recomputeSize
|
|
607 |
!
|
|
608 |
|
0
|
609 |
indexOf:indexOrName
|
|
610 |
"return the index of the label named:aName or , if its a symbol
|
|
611 |
the index in the selector list"
|
|
612 |
|
95
|
613 |
indexOrName isSymbol ifTrue:[
|
59
|
614 |
^ selectors indexOf:indexOrName
|
0
|
615 |
].
|
95
|
616 |
indexOrName isString ifTrue:[
|
59
|
617 |
^ list indexOf:indexOrName
|
38
|
618 |
].
|
0
|
619 |
^ indexOrName
|
|
620 |
!
|
|
621 |
|
|
622 |
disable:indexOrName
|
|
623 |
"disable an entry"
|
|
624 |
|
|
625 |
|index|
|
|
626 |
|
|
627 |
index := self indexOf:indexOrName.
|
|
628 |
index ~~ 0 ifTrue:[
|
59
|
629 |
(enableFlags at:index) ifTrue:[
|
|
630 |
enableFlags at:index put:false.
|
|
631 |
shown ifTrue:[
|
|
632 |
self redrawLine:index
|
|
633 |
]
|
|
634 |
]
|
12
|
635 |
] ifFalse:[
|
59
|
636 |
"try submenus for convenience"
|
|
637 |
(indexOrName isNumber not and:[subMenus notNil]) ifTrue:[
|
|
638 |
subMenus do:[:m |
|
|
639 |
m notNil ifTrue:[
|
|
640 |
m disable:indexOrName
|
|
641 |
]
|
|
642 |
]
|
|
643 |
]
|
0
|
644 |
]
|
|
645 |
!
|
|
646 |
|
|
647 |
enable:indexOrName
|
|
648 |
"enable an entry"
|
|
649 |
|
|
650 |
|index|
|
|
651 |
|
|
652 |
index := self indexOf:indexOrName.
|
|
653 |
index ~~ 0 ifTrue:[
|
59
|
654 |
(enableFlags at:index) ifFalse:[
|
|
655 |
enableFlags at:index put:true.
|
|
656 |
shown ifTrue:[
|
|
657 |
self redrawLine:index
|
|
658 |
]
|
|
659 |
]
|
12
|
660 |
] ifFalse:[
|
59
|
661 |
"try submenus for convenience"
|
|
662 |
(indexOrName isNumber not and:[subMenus notNil]) ifTrue:[
|
|
663 |
subMenus do:[:m |
|
|
664 |
m notNil ifTrue:[
|
|
665 |
m enable:indexOrName
|
|
666 |
]
|
|
667 |
]
|
|
668 |
]
|
0
|
669 |
]
|
|
670 |
!
|
|
671 |
|
70
|
672 |
isEnabled:indexOrName
|
|
673 |
|index|
|
|
674 |
|
|
675 |
index := self indexOf:indexOrName.
|
|
676 |
index ~~ 0 ifTrue:[
|
|
677 |
enableFlags isNil ifTrue:[^ true].
|
|
678 |
^ enableFlags at:index
|
|
679 |
].
|
|
680 |
"ask submenus for convenience"
|
|
681 |
(indexOrName isNumber not and:[subMenus notNil]) ifTrue:[
|
|
682 |
subMenus do:[:m |
|
|
683 |
m notNil ifTrue:[
|
|
684 |
m enable:indexOrName
|
|
685 |
]
|
|
686 |
]
|
|
687 |
]
|
|
688 |
!
|
|
689 |
|
0
|
690 |
receiver
|
|
691 |
"return the receiver of the message"
|
|
692 |
|
|
693 |
^ receiver
|
|
694 |
!
|
|
695 |
|
|
696 |
selectors
|
|
697 |
"return the selector array"
|
|
698 |
|
|
699 |
^ selectors
|
|
700 |
!
|
|
701 |
|
|
702 |
selectors:anArray
|
|
703 |
"set the selector array"
|
|
704 |
|
|
705 |
selectors := anArray
|
|
706 |
!
|
|
707 |
|
|
708 |
selectorAt:indexOrName
|
|
709 |
"return an individual selector"
|
|
710 |
|
|
711 |
|i|
|
|
712 |
|
|
713 |
i := self indexOf:indexOrName.
|
3
|
714 |
i ~~ 0 ifTrue:[^ selectors at:i].
|
|
715 |
^ nil
|
0
|
716 |
!
|
|
717 |
|
|
718 |
selectorAt:indexOrName put:aSelector
|
|
719 |
"set an individual selector"
|
|
720 |
|
|
721 |
|i|
|
|
722 |
|
|
723 |
i := self indexOf:indexOrName.
|
3
|
724 |
i ~~ 0 ifTrue:[selectors at:i put:aSelector]
|
0
|
725 |
!
|
|
726 |
|
|
727 |
args
|
|
728 |
"return the argument array"
|
|
729 |
|
|
730 |
^ args
|
|
731 |
!
|
|
732 |
|
|
733 |
args:anArray
|
|
734 |
"set the argument array"
|
|
735 |
|
|
736 |
args := anArray
|
|
737 |
!
|
|
738 |
|
|
739 |
argsAt:indexOrName put:something
|
|
740 |
"set an individual selector"
|
|
741 |
|
3
|
742 |
|i|
|
|
743 |
|
|
744 |
i := self indexOf:indexOrName.
|
|
745 |
i ~~ 0 ifTrue:[args at:i put:something]
|
0
|
746 |
!
|
|
747 |
|
|
748 |
receiver:anObject
|
|
749 |
"set the receiver of the message"
|
|
750 |
|
|
751 |
receiver := anObject
|
|
752 |
!
|
|
753 |
|
|
754 |
labels:text selectors:selArray args:argArray receiver:anObject
|
|
755 |
"set all relevant stuff"
|
|
756 |
|
|
757 |
self labels:text.
|
|
758 |
selectors := selArray.
|
|
759 |
args := argArray.
|
|
760 |
receiver := anObject
|
|
761 |
!
|
|
762 |
|
|
763 |
checkToggleAt:indexOrName
|
|
764 |
"return a check-toggles boolean state"
|
|
765 |
|
|
766 |
|index|
|
|
767 |
|
|
768 |
index := self indexOf:indexOrName.
|
3
|
769 |
index == 0 ifTrue:[^ false].
|
0
|
770 |
onOffFlags isNil ifTrue:[^ false].
|
|
771 |
^ onOffFlags at:index
|
|
772 |
!
|
|
773 |
|
|
774 |
checkToggleAt:indexOrName put:aBoolean
|
|
775 |
"set/clear a check-toggle"
|
|
776 |
|
|
777 |
|index|
|
|
778 |
|
|
779 |
index := self indexOf:indexOrName.
|
3
|
780 |
index == 0 ifTrue:[^ self].
|
65
|
781 |
|
|
782 |
onOffFlags isNil ifTrue:[
|
|
783 |
onOffFlags := Array new:(list size)
|
|
784 |
].
|
0
|
785 |
onOffFlags at:index put:aBoolean.
|
|
786 |
shown ifTrue:[
|
59
|
787 |
self redrawLine:index
|
0
|
788 |
]
|
|
789 |
!
|
|
790 |
|
|
791 |
subMenuAt:indexOrName
|
|
792 |
"return a submenu, or nil"
|
|
793 |
|
3
|
794 |
|i|
|
|
795 |
|
0
|
796 |
subMenus isNil ifTrue:[^ nil].
|
3
|
797 |
i := self indexOf:indexOrName.
|
|
798 |
i == 0 ifTrue:[^ nil].
|
|
799 |
^ subMenus at:i
|
0
|
800 |
!
|
|
801 |
|
|
802 |
subMenuAt:indexOrName put:aPopUpMenu
|
|
803 |
"define a submenu"
|
|
804 |
|
59
|
805 |
|i newSubMenus|
|
3
|
806 |
|
|
807 |
i := self indexOf:indexOrName.
|
|
808 |
i == 0 ifTrue:[^ nil].
|
59
|
809 |
subMenus size < i ifTrue:[
|
|
810 |
newSubMenus := Array new:(list size max:i).
|
|
811 |
subMenus notNil ifTrue:[
|
|
812 |
newSubMenus replaceFrom:1 with:subMenus.
|
|
813 |
].
|
|
814 |
subMenus := newSubMenus.
|
|
815 |
self recomputeSize
|
0
|
816 |
].
|
3
|
817 |
subMenus at:i put:aPopUpMenu
|
77
|
818 |
!
|
|
819 |
|
|
820 |
selection:index
|
|
821 |
|sel line|
|
|
822 |
|
|
823 |
sel := index.
|
|
824 |
sel notNil ifTrue:[
|
|
825 |
line := self listAt:index.
|
|
826 |
((line = '-')
|
|
827 |
or:[(line = '=')
|
|
828 |
or:[line = '']]) ifTrue:[
|
|
829 |
"
|
|
830 |
not really selectable, but a separating line
|
|
831 |
"
|
|
832 |
sel := nil
|
|
833 |
]
|
|
834 |
].
|
|
835 |
super selection:sel
|
0
|
836 |
! !
|
|
837 |
|
|
838 |
!MenuView methodsFor:'private'!
|
|
839 |
|
7
|
840 |
hideSubmenu
|
|
841 |
subMenuShown notNil ifTrue:[
|
59
|
842 |
subMenuShown hide.
|
|
843 |
subMenuShown := nil
|
7
|
844 |
].
|
|
845 |
!
|
|
846 |
|
0
|
847 |
recomputeSize
|
|
848 |
|margin2 w h|
|
|
849 |
|
|
850 |
margin2 := margin * 2.
|
|
851 |
w := self widthOfContents + leftMargin + leftMargin + margin2.
|
|
852 |
h := (self numberOfLines) * fontHeight + (2 * topMargin) + margin2.
|
21
|
853 |
"if there is a submenu, add some space for the right arrow"
|
|
854 |
subMenus notNil ifTrue:[
|
59
|
855 |
w := w + 16
|
21
|
856 |
].
|
0
|
857 |
self extent:(w @ h).
|
|
858 |
(font device == device) ifTrue:[
|
59
|
859 |
self computeNumberOfLinesShown
|
0
|
860 |
]
|
|
861 |
!
|
|
862 |
|
77
|
863 |
showSubmenu:index
|
|
864 |
"show subMenu at index"
|
|
865 |
|
|
866 |
|org mx my m|
|
|
867 |
|
|
868 |
m := subMenus at:index.
|
|
869 |
m isNil ifTrue:[^ self].
|
|
870 |
|
|
871 |
mx := width - 5.
|
|
872 |
my := self yOfVisibleLine:index.
|
|
873 |
org := device translatePoint:(mx @ my)
|
|
874 |
from:(self id)
|
|
875 |
to:(DisplayRootView new id).
|
|
876 |
|
|
877 |
|
|
878 |
windowGroup notNil ifTrue:[
|
|
879 |
windowGroup processExposeEvents
|
|
880 |
].
|
|
881 |
|
|
882 |
m superMenu:self.
|
|
883 |
|
|
884 |
"
|
|
885 |
realize the submenu in MY windowgroup
|
|
886 |
"
|
|
887 |
windowGroup notNil ifTrue:[
|
|
888 |
m windowGroup:windowGroup.
|
|
889 |
windowGroup addTopView:m.
|
|
890 |
].
|
|
891 |
m fixSize.
|
|
892 |
m origin:org.
|
|
893 |
m makeFullyVisible.
|
|
894 |
m realize.
|
|
895 |
device synchronizeOutput.
|
|
896 |
|
|
897 |
subMenuShown := m
|
|
898 |
!
|
|
899 |
|
0
|
900 |
setSelectionForX:x y:y
|
77
|
901 |
"select whatever is under x/y coordinate - if there is
|
|
902 |
a subMenu, show it"
|
|
903 |
|
87
|
904 |
|newSelection|
|
0
|
905 |
|
38
|
906 |
(x < 0
|
|
907 |
or:[x >= width
|
|
908 |
or:[y < 0
|
|
909 |
or:[y >= height]]]) ifTrue:[
|
59
|
910 |
"
|
|
911 |
moved outside submenu, but not within self
|
|
912 |
"
|
|
913 |
subMenuShown notNil ifTrue:[
|
|
914 |
^ self
|
|
915 |
].
|
70
|
916 |
superMenu notNil ifTrue:[
|
|
917 |
superMenu regainControl
|
|
918 |
].
|
38
|
919 |
].
|
|
920 |
|
0
|
921 |
newSelection := self positionToSelectionX:x y:y.
|
7
|
922 |
newSelection ~= selection ifTrue:[
|
59
|
923 |
newSelection notNil ifTrue:[
|
|
924 |
(enableFlags at:newSelection) ifFalse:[
|
|
925 |
newSelection := nil
|
70
|
926 |
]
|
|
927 |
].
|
|
928 |
|
|
929 |
self selection:newSelection.
|
|
930 |
|
|
931 |
subMenuShown notNil ifTrue:[
|
|
932 |
self hideSubmenu.
|
|
933 |
].
|
7
|
934 |
|
77
|
935 |
selection notNil ifTrue:[
|
70
|
936 |
subMenus notNil ifTrue:[
|
77
|
937 |
self showSubmenu:selection.
|
70
|
938 |
] ifFalse:[
|
|
939 |
subMenuShown := nil
|
59
|
940 |
]
|
|
941 |
].
|
7
|
942 |
]
|
0
|
943 |
! !
|
|
944 |
|
|
945 |
!MenuView methodsFor:'showing'!
|
|
946 |
|
|
947 |
show
|
|
948 |
hidden := false.
|
|
949 |
super realize
|
|
950 |
! !
|
|
951 |
|
77
|
952 |
!MenuView methodsFor:'selections'!
|
|
953 |
|
|
954 |
isValidSelection:aNumber
|
|
955 |
"return true, if aNumber is ok for a selection lineNo"
|
|
956 |
|
|
957 |
|line|
|
|
958 |
|
|
959 |
(super isValidSelection:aNumber) ifFalse:[^ false].
|
|
960 |
|
|
961 |
line := self listAt:aNumber.
|
|
962 |
|
|
963 |
(line = '-') ifTrue:[^ false].
|
|
964 |
(line = '=') ifTrue:[^ false].
|
|
965 |
(line = '') ifTrue:[^ false].
|
|
966 |
^ true.
|
|
967 |
! !
|
|
968 |
|
0
|
969 |
!MenuView methodsFor:'redrawing'!
|
|
970 |
|
|
971 |
drawMarkInVisibleLine:visLineNr with:fg and:bg
|
63
|
972 |
"draw an on-mark (or the space for it)"
|
0
|
973 |
|
87
|
974 |
|w h y x l check xR yB|
|
0
|
975 |
|
|
976 |
l := self visibleLineToListLine:visLineNr.
|
|
977 |
onOffFlags isNil ifTrue:[
|
59
|
978 |
check := false
|
0
|
979 |
] ifFalse:[
|
65
|
980 |
check := (onOffFlags at:l) == true.
|
0
|
981 |
].
|
|
982 |
|
14
|
983 |
w := font widthOf:'\c'.
|
0
|
984 |
|
59
|
985 |
x := (self xOfCol:1 inVisibleLine:visLineNr) - leftOffset.
|
|
986 |
y := self yOfVisibleLine:visLineNr.
|
0
|
987 |
|
|
988 |
self paint:bg.
|
7
|
989 |
self fillRectangleX:x y:y width:w height:fontHeight.
|
0
|
990 |
self paint:fg.
|
63
|
991 |
|
0
|
992 |
check ifTrue:[
|
65
|
993 |
h := font ascent.
|
59
|
994 |
self paint:checkColor.
|
87
|
995 |
xR := x + (w // 3).
|
|
996 |
yB := y + h - 1.
|
|
997 |
self displayLineFromX:x y:(y + (h // 2)) toX:xR y:yB.
|
|
998 |
self displayLineFromX:xR y:yB toX:(x + w - 1) y:y
|
0
|
999 |
]
|
|
1000 |
!
|
|
1001 |
|
|
1002 |
drawVisibleLine:visLineNr with:fg and:bg
|
63
|
1003 |
|line isSpecial|
|
0
|
1004 |
|
|
1005 |
line := self visibleAt:visLineNr.
|
|
1006 |
|
97
|
1007 |
isSpecial := line notNil and:[line includes:$\].
|
0
|
1008 |
isSpecial ifFalse:[
|
63
|
1009 |
"
|
|
1010 |
a normal entry
|
|
1011 |
"
|
59
|
1012 |
super drawVisibleLine:visLineNr with:fg and:bg
|
0
|
1013 |
] ifTrue:[
|
63
|
1014 |
"
|
|
1015 |
some speciality in this line (check-mark)
|
|
1016 |
"
|
59
|
1017 |
super drawVisibleLine:visLineNr "from:3" with:fg and:bg.
|
|
1018 |
self drawMarkInVisibleLine:visLineNr with:fg and:bg
|
0
|
1019 |
]
|
|
1020 |
!
|
|
1021 |
|
38
|
1022 |
drawVisibleLineSelected:visLineNr
|
|
1023 |
"redraw a single line as selected."
|
|
1024 |
|
|
1025 |
|listLine fg bg
|
87
|
1026 |
y "{ Class: SmallInteger }"
|
38
|
1027 |
y2 "{ Class: SmallInteger }"
|
|
1028 |
r2 radius topLeftColor botRightColor |
|
|
1029 |
|
77
|
1030 |
hilightStyle ~~ #openwin ifTrue:[
|
59
|
1031 |
^ super drawVisibleLineSelected:visLineNr.
|
38
|
1032 |
].
|
77
|
1033 |
|
38
|
1034 |
"
|
|
1035 |
openwin draws selections in a menu as (edged) rounded rectangles
|
|
1036 |
"
|
|
1037 |
bg := hilightBgColor.
|
|
1038 |
fg := hilightFgColor.
|
|
1039 |
listLine := self visibleLineToListLine:visLineNr.
|
|
1040 |
listLine notNil ifTrue:[
|
|
1041 |
|
59
|
1042 |
self drawVisibleLine:visLineNr with:fg and:bg.
|
|
1043 |
y := self yOfVisibleLine:visLineNr.
|
|
1044 |
y2 := y + fontHeight - 1.
|
|
1045 |
r2 := font height.
|
|
1046 |
radius := r2 // 2.
|
|
1047 |
"
|
|
1048 |
refill with normal bg, where arcs will be drawn below
|
|
1049 |
"
|
|
1050 |
self paint:bgColor.
|
|
1051 |
self fillRectangleX:margin y:y width:radius height:fontHeight.
|
|
1052 |
self fillRectangleX:width-radius-margin y:y width:radius height:fontHeight.
|
|
1053 |
"
|
|
1054 |
fill the arcs
|
|
1055 |
"
|
|
1056 |
self paint:hilightBgColor.
|
|
1057 |
self fillArcX:1+margin+1 y:y w:r2 h:r2+1+1 from:90 angle:180.
|
|
1058 |
self fillArcX:width-r2-1-1-margin-1 y:y w:r2 h:r2+1+1 from:270 angle:180.
|
38
|
1059 |
|
59
|
1060 |
"
|
|
1061 |
a highlight-border around
|
|
1062 |
"
|
|
1063 |
hilightFrameColor notNil ifTrue:[
|
|
1064 |
self paint:hilightFrameColor.
|
|
1065 |
self displayLineFromX:radius+2 y:y toX:width-radius-3 y:y.
|
|
1066 |
self displayLineFromX:radius+2 y:y2 toX:width-radius-3 y:y2.
|
38
|
1067 |
|
59
|
1068 |
self displayArcX:1+margin+1 y:y w:r2 h:r2+1+1 from:90 angle:180.
|
|
1069 |
self displayArcX:width-r2-1-1-margin-1 y:y w:r2 h:r2+1+1 from:270 angle:180.
|
|
1070 |
^ self
|
|
1071 |
].
|
38
|
1072 |
|
59
|
1073 |
"
|
|
1074 |
an edge around
|
|
1075 |
"
|
|
1076 |
(hilightLevel ~~ 0) ifTrue:[
|
|
1077 |
(hilightLevel < 0) ifTrue:[
|
|
1078 |
topLeftColor := shadowColor.
|
|
1079 |
botRightColor := lightColor.
|
|
1080 |
] ifFalse:[
|
|
1081 |
topLeftColor := lightColor.
|
|
1082 |
botRightColor := shadowColor.
|
|
1083 |
].
|
38
|
1084 |
|
59
|
1085 |
self paint:topLeftColor.
|
|
1086 |
self displayLineFromX:radius+2 y:y toX:width-radius-3 y:y.
|
38
|
1087 |
|
59
|
1088 |
self displayArcX:1+margin+1 y:y w:r2 h:r2+1+1 from:90 angle:125.
|
|
1089 |
self displayArcX:width-r2-1-1-margin-1 y:y w:r2 h:r2+1+1 from:270+125 angle:55.
|
38
|
1090 |
|
59
|
1091 |
self paint:botRightColor.
|
38
|
1092 |
|
59
|
1093 |
self displayLineFromX:radius+2 y:y2 toX:width-radius-3 y:y2.
|
|
1094 |
self displayArcX:1+margin+1 y:y w:r2 h:r2+1+1 from:90+125 angle:55.
|
|
1095 |
self displayArcX:width-r2-1-1-margin-1 y:y w:r2 h:r2+1+1 from:270 angle:125.
|
77
|
1096 |
].
|
|
1097 |
^ self
|
38
|
1098 |
].
|
|
1099 |
^ super drawVisibleLine:visLineNr with:fg and:bg
|
|
1100 |
!
|
|
1101 |
|
0
|
1102 |
redrawVisibleLine:visLine col:col
|
|
1103 |
self redrawVisibleLine:visLine
|
|
1104 |
!
|
|
1105 |
|
|
1106 |
redrawVisibleLine:visLine from:startCol
|
|
1107 |
self redrawVisibleLine:visLine
|
|
1108 |
!
|
|
1109 |
|
|
1110 |
redrawVisibleLine:visLine from:startCol to:endCol
|
|
1111 |
self redrawVisibleLine:visLine
|
|
1112 |
!
|
|
1113 |
|
|
1114 |
redrawVisibleLine:visLineNr
|
63
|
1115 |
"redefined from normal list-line drawing, to handle special
|
|
1116 |
lines. These are:
|
|
1117 |
lines consisting of '-' only: draw a horizontal separating line
|
|
1118 |
lines consisting of '=' only: draw double separating line
|
|
1119 |
empty line : leave blank
|
|
1120 |
there may be more in the future.
|
|
1121 |
"
|
|
1122 |
|
|
1123 |
|line lineNr y isSpecial isSeparatingLine
|
|
1124 |
isDoubleLine right clr1 clr2|
|
0
|
1125 |
|
|
1126 |
line := self visibleAt:visLineNr.
|
|
1127 |
|
63
|
1128 |
isSpecial := isDoubleLine := isSeparatingLine := false.
|
0
|
1129 |
(line = '-') ifTrue:[
|
63
|
1130 |
isSeparatingLine := isSpecial := true.
|
0
|
1131 |
] ifFalse:[
|
63
|
1132 |
(line = '=') ifTrue:[
|
|
1133 |
isSeparatingLine := isSpecial := isDoubleLine := true.
|
|
1134 |
] ifFalse:[
|
|
1135 |
(line = '') ifTrue:[
|
|
1136 |
isSpecial := true
|
|
1137 |
]
|
59
|
1138 |
]
|
0
|
1139 |
].
|
63
|
1140 |
|
0
|
1141 |
isSpecial ifFalse:[
|
59
|
1142 |
lineNr := self visibleLineToListLine:visLineNr.
|
|
1143 |
(enableFlags at:lineNr) ifFalse:[
|
|
1144 |
self drawVisibleLine:visLineNr with:disabledFgColor and:bgColor
|
|
1145 |
] ifTrue:[
|
|
1146 |
super redrawVisibleLine:visLineNr
|
|
1147 |
].
|
|
1148 |
"is there a submenu ?"
|
|
1149 |
(subMenus notNil and:[(subMenus at:lineNr) notNil]) ifTrue:[
|
|
1150 |
self drawRightArrowInVisibleLine:visLineNr
|
|
1151 |
].
|
|
1152 |
^ self
|
0
|
1153 |
].
|
|
1154 |
|
|
1155 |
"handle separating lines"
|
|
1156 |
|
59
|
1157 |
y := self yOfVisibleLine:visLineNr.
|
38
|
1158 |
|
|
1159 |
self paint:bgColor.
|
|
1160 |
self fillRectangleX:0 y:y width:width height:fontHeight.
|
|
1161 |
|
0
|
1162 |
isSeparatingLine ifTrue:[
|
59
|
1163 |
y := y + (fontHeight // 2).
|
63
|
1164 |
isDoubleLine ifTrue:[
|
|
1165 |
y := y - (fontHeight // 8).
|
|
1166 |
].
|
59
|
1167 |
lineLevel == 0 ifTrue:[
|
|
1168 |
self paint:fgColor.
|
63
|
1169 |
self displayLineFromX:0 y:y toX:width y:y.
|
|
1170 |
isDoubleLine ifTrue:[
|
|
1171 |
y := y + (fontHeight // 4).
|
|
1172 |
self displayLineFromX:0 y:y toX:width y:y
|
|
1173 |
]
|
59
|
1174 |
] ifFalse:[
|
|
1175 |
"the inset on each side"
|
38
|
1176 |
|
59
|
1177 |
lineLevel < 0 ifTrue:[
|
|
1178 |
clr1 := shadowColor.
|
|
1179 |
clr2 := lightColor.
|
|
1180 |
] ifFalse:[
|
|
1181 |
clr1 := lightColor.
|
|
1182 |
clr2 := shadowColor.
|
|
1183 |
].
|
63
|
1184 |
right := width - 1 - lineInset.
|
|
1185 |
|
59
|
1186 |
self paint:clr1.
|
|
1187 |
self displayLineFromX:lineInset y:y toX:right y:y.
|
|
1188 |
self paint:clr2.
|
|
1189 |
y := y + 1.
|
63
|
1190 |
self displayLineFromX:lineInset y:y toX:right y:y.
|
|
1191 |
isDoubleLine ifTrue:[
|
|
1192 |
y := y + (fontHeight // 4).
|
|
1193 |
self displayLineFromX:lineInset y:y toX:right y:y.
|
|
1194 |
y := y - 1.
|
|
1195 |
self paint:clr1.
|
|
1196 |
self displayLineFromX:lineInset y:y toX:right y:y.
|
|
1197 |
]
|
59
|
1198 |
]
|
0
|
1199 |
]
|
|
1200 |
!
|
|
1201 |
|
|
1202 |
redrawFromVisibleLine:start to:stop
|
63
|
1203 |
"redraw a line range - redefined to care for special entries."
|
0
|
1204 |
|
|
1205 |
"the natural way to do it is:
|
|
1206 |
|
|
1207 |
start to:stop do:[:visLine |
|
59
|
1208 |
self redrawVisibleLine:visLine
|
0
|
1209 |
]
|
|
1210 |
|
|
1211 |
but I want to draw the stuff in big chunks for slow machines ..."
|
|
1212 |
|
|
1213 |
|first current line special index|
|
|
1214 |
|
|
1215 |
first := start.
|
|
1216 |
current := start.
|
|
1217 |
index := self visibleLineToListLine:start.
|
|
1218 |
index notNil ifTrue:[
|
59
|
1219 |
[current <= stop] whileTrue:[
|
|
1220 |
line := self visibleAt:current.
|
0
|
1221 |
|
97
|
1222 |
special := line notNil and:[
|
|
1223 |
(line = '-')
|
|
1224 |
or:[(line = '')
|
|
1225 |
or:[(line at:1) == $\
|
|
1226 |
or:[(line = '=')]]]].
|
|
1227 |
|
59
|
1228 |
(special
|
|
1229 |
or:[(enableFlags at:index) not]) ifTrue:[
|
|
1230 |
"a special case"
|
|
1231 |
(first < current) ifTrue:[
|
|
1232 |
super redrawFromVisibleLine:first to:(current - 1)
|
|
1233 |
].
|
|
1234 |
self redrawVisibleLine:current.
|
|
1235 |
first := current + 1
|
|
1236 |
].
|
|
1237 |
current := current + 1.
|
|
1238 |
index := index + 1
|
|
1239 |
].
|
|
1240 |
(first < current) ifTrue:[
|
|
1241 |
super redrawFromVisibleLine:first to:(current - 1)
|
|
1242 |
].
|
21
|
1243 |
|
59
|
1244 |
"draw submenu marks"
|
|
1245 |
subMenus notNil ifTrue:[
|
|
1246 |
index := self visibleLineToListLine:start.
|
|
1247 |
start to:stop do:[:l |
|
|
1248 |
index <= subMenus size ifTrue:[
|
|
1249 |
(subMenus at:index) notNil ifTrue:[
|
|
1250 |
self drawRightArrowInVisibleLine:l
|
|
1251 |
].
|
|
1252 |
index := index + 1
|
|
1253 |
]
|
|
1254 |
]
|
|
1255 |
]
|
0
|
1256 |
]
|
|
1257 |
! !
|
|
1258 |
|
7
|
1259 |
!MenuView methodsFor:'submenu actions'!
|
|
1260 |
|
|
1261 |
submenuTriggered
|
|
1262 |
"submenu has performed some action - have to deselect here"
|
|
1263 |
|
|
1264 |
self selection:nil.
|
|
1265 |
"a bad kludge - 5 minutes before writing the alpha tapes ..."
|
|
1266 |
(superView isKindOf:PopUpMenu) ifTrue:[
|
59
|
1267 |
superView hide
|
7
|
1268 |
].
|
|
1269 |
superMenu notNil ifTrue:[
|
59
|
1270 |
superMenu submenuTriggered
|
7
|
1271 |
].
|
|
1272 |
!
|
|
1273 |
|
70
|
1274 |
regainControl
|
7
|
1275 |
"take over pointer control from a submenu"
|
|
1276 |
|
70
|
1277 |
masterView notNil ifTrue:[
|
|
1278 |
masterView regainControl
|
|
1279 |
].
|
7
|
1280 |
^ self
|
|
1281 |
!
|
|
1282 |
|
|
1283 |
showActive
|
|
1284 |
"submenu is about to perform an action - show wait cursor here as well"
|
|
1285 |
|
|
1286 |
self cursor:(Cursor wait)
|
|
1287 |
!
|
|
1288 |
|
|
1289 |
showPassive
|
|
1290 |
"submenu has performed its action - show normal cursor again"
|
|
1291 |
|
|
1292 |
self cursor:(Cursor hand)
|
|
1293 |
! !
|
|
1294 |
|
0
|
1295 |
!MenuView methodsFor:'event handling'!
|
|
1296 |
|
|
1297 |
buttonPress:button x:x y:y
|
|
1298 |
self setSelectionForX:x y:y
|
|
1299 |
!
|
|
1300 |
|
|
1301 |
buttonMotion:state x:x y:y
|
65
|
1302 |
state ~~ 0 ifTrue:[
|
70
|
1303 |
self setSelectionForX:x y:y
|
65
|
1304 |
]
|
0
|
1305 |
!
|
|
1306 |
|
77
|
1307 |
keyPress:aKey x:x y:y
|
|
1308 |
aKey == #Return ifTrue:[
|
|
1309 |
selection notNil ifTrue:[
|
|
1310 |
(subMenus notNil and:[(subMenus at:selection) notNil]) ifTrue:[
|
|
1311 |
self showSubmenu:selection.
|
|
1312 |
] ifFalse:[
|
|
1313 |
subMenuShown := nil.
|
|
1314 |
self buttonRelease:1 x:x y:y.
|
|
1315 |
]
|
|
1316 |
].
|
|
1317 |
^ self
|
|
1318 |
].
|
|
1319 |
super keyPress:aKey x:x y:y
|
|
1320 |
!
|
|
1321 |
|
0
|
1322 |
pointerLeave:state
|
7
|
1323 |
subMenuShown notNil ifTrue:[
|
59
|
1324 |
^ self
|
7
|
1325 |
].
|
38
|
1326 |
"/ self setSelectionForX:-1 y:-1. "force deselect"
|
7
|
1327 |
subMenuShown isNil ifTrue:[
|
59
|
1328 |
self selection:nil
|
7
|
1329 |
].
|
38
|
1330 |
"/ superMenu notNil ifTrue:[
|
|
1331 |
"/ superMenu regainControl.
|
|
1332 |
"/ ]
|
0
|
1333 |
!
|
|
1334 |
|
|
1335 |
buttonRelease:button x:x y:y
|
77
|
1336 |
|theSelector isCheck val|
|
0
|
1337 |
|
7
|
1338 |
subMenuShown notNil ifTrue:[
|
59
|
1339 |
^ self
|
7
|
1340 |
].
|
|
1341 |
|
0
|
1342 |
(x >= 0 and:[x < width]) ifTrue:[
|
59
|
1343 |
(y >= 0 and:[y < height]) ifTrue:[
|
|
1344 |
selection notNil ifTrue:[
|
|
1345 |
(subMenus isNil or:[(subMenus at:selection) isNil]) ifTrue:[
|
|
1346 |
self cursor:Cursor wait.
|
77
|
1347 |
[
|
|
1348 |
superMenu notNil ifTrue:[
|
|
1349 |
superMenu showActive
|
|
1350 |
].
|
|
1351 |
|
|
1352 |
val := selection.
|
|
1353 |
args notNil ifTrue:[
|
|
1354 |
val := args at:selection
|
|
1355 |
].
|
|
1356 |
|
|
1357 |
"
|
|
1358 |
ST-80 style model notification
|
|
1359 |
"
|
95
|
1360 |
self sendChangeMessageWith:val.
|
77
|
1361 |
|
|
1362 |
"
|
|
1363 |
either action-block or selectors-array-style
|
|
1364 |
"
|
|
1365 |
actionBlock notNil ifTrue:[
|
|
1366 |
Object abortSignal handle:[:ex |
|
|
1367 |
ex return
|
|
1368 |
] do:[
|
|
1369 |
actionBlock value:(self selection)
|
|
1370 |
]
|
|
1371 |
] ifFalse:[
|
|
1372 |
selectors notNil ifTrue: [
|
|
1373 |
device activePointerGrab == self ifTrue:[
|
|
1374 |
device ungrabPointer.
|
|
1375 |
].
|
87
|
1376 |
selectors isSymbol ifFalse:[
|
77
|
1377 |
(selection notNil
|
|
1378 |
and:[selection <= selectors size]) ifTrue:[
|
|
1379 |
theSelector := selectors at:selection
|
59
|
1380 |
]
|
77
|
1381 |
] ifTrue:[
|
|
1382 |
theSelector := selectors
|
59
|
1383 |
].
|
77
|
1384 |
theSelector notNil ifTrue:[
|
|
1385 |
isCheck := false.
|
|
1386 |
onOffFlags notNil ifTrue:[
|
|
1387 |
onOffFlags size >= selection ifTrue:[
|
|
1388 |
isCheck := (onOffFlags at:selection) notNil
|
|
1389 |
]
|
|
1390 |
].
|
|
1391 |
Object abortSignal handle:[:ex |
|
|
1392 |
ex return
|
|
1393 |
] do:[
|
|
1394 |
isCheck ifTrue:[
|
|
1395 |
onOffFlags at:selection
|
|
1396 |
put:(onOffFlags at:selection) not.
|
|
1397 |
self redrawLine:selection.
|
59
|
1398 |
receiver perform:theSelector
|
77
|
1399 |
with:(onOffFlags at:selection)
|
59
|
1400 |
] ifFalse:[
|
77
|
1401 |
args isNil ifTrue:[
|
|
1402 |
receiver perform:theSelector
|
|
1403 |
] ifFalse:[
|
|
1404 |
receiver perform:theSelector with:val
|
|
1405 |
]
|
59
|
1406 |
]
|
|
1407 |
]
|
|
1408 |
]
|
|
1409 |
]
|
77
|
1410 |
].
|
|
1411 |
] valueNowOrOnUnwindDo:[
|
|
1412 |
realized ifTrue:[
|
|
1413 |
self cursor:Cursor hand.
|
|
1414 |
].
|
|
1415 |
superMenu notNil ifTrue:[
|
|
1416 |
superMenu showPassive
|
59
|
1417 |
]
|
|
1418 |
].
|
|
1419 |
].
|
|
1420 |
]
|
|
1421 |
]
|
0
|
1422 |
]
|
|
1423 |
! !
|