0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
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 |
SelectionInListView subclass:#MenuView
|
|
14 |
instanceVariableNames:'selectors args receiver enableFlags
|
|
15 |
disabledFgColor onOffFlags subMenus
|
21
|
16 |
subMenuShown superMenu checkColor'
|
0
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Menus'
|
|
20 |
!
|
|
21 |
|
|
22 |
MenuView comment:'
|
|
23 |
|
5
|
24 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
25 |
All Rights Reserved
|
|
26 |
|
21
|
27 |
$Header: /cvs/stx/stx/libwidg/MenuView.st,v 1.7 1994-01-08 17:27:32 claus Exp $
|
3
|
28 |
'!
|
|
29 |
|
|
30 |
!MenuView class methodsFor:'documentation'!
|
|
31 |
|
|
32 |
documentation
|
|
33 |
"
|
0
|
34 |
a menu view used for both pull-down-menus and pop-up-menus
|
|
35 |
the action to be performed can be defined either as:
|
|
36 |
|
|
37 |
1) action:aBlockWithOneArg
|
|
38 |
which defines a block to be called with the line number (1..n)
|
|
39 |
of the selected line.
|
|
40 |
|
|
41 |
2) selectors:selectorArray [args: argarray] receiver:anObject
|
|
42 |
which defines the messages to be sent to receiver for each
|
|
43 |
line.
|
|
44 |
|
|
45 |
It is also possible to define both actionBlock and selectorArray.
|
|
46 |
|
21
|
47 |
menu entries starting with '\c' are check-entries.
|
|
48 |
menu entries conisting of '-' alone, are separating lines.
|
|
49 |
|
0
|
50 |
written summer 89 by claus
|
3
|
51 |
"
|
|
52 |
! !
|
0
|
53 |
|
|
54 |
!MenuView class methodsFor:'initialization'!
|
|
55 |
|
|
56 |
initialize
|
|
57 |
"setup some defaults - these are usually redefined during startup."
|
|
58 |
|
|
59 |
super initialize.
|
|
60 |
DefaultFont := Font family:'helvetica' face:'bold' style:'roman' size:12
|
|
61 |
! !
|
|
62 |
|
|
63 |
!MenuView class methodsFor:'instance creation'!
|
|
64 |
|
|
65 |
labels:labels selectors:selArray args:argArray receiver:anObject in:aView
|
|
66 |
"create and return a new MenuView in aView
|
|
67 |
- receiverObject gets message from selectorArray with argument
|
|
68 |
from argArray"
|
|
69 |
|
|
70 |
^ (self in:aView) labels:labels
|
|
71 |
selectors:selArray
|
|
72 |
args:argArray
|
|
73 |
receiver:anObject
|
|
74 |
!
|
|
75 |
|
|
76 |
labels:labels selectors:selArray receiver:anObject in:aView
|
|
77 |
"create and return a new MenuView in aView
|
|
78 |
- receiverObject gets message from selectorArray without argument"
|
|
79 |
|
|
80 |
^ (self in:aView) labels:labels
|
|
81 |
selectors:selArray
|
|
82 |
args:nil
|
|
83 |
receiver:anObject
|
|
84 |
!
|
|
85 |
|
|
86 |
labels:labels selector:aSelector args:argArray receiver:anObject in:aTopMenu
|
|
87 |
"create and return a new MenuView
|
|
88 |
- receiverObject gets message aSelector with argument from
|
|
89 |
argArray for all entries"
|
|
90 |
|
|
91 |
^ (self in:aTopMenu) labels:labels
|
|
92 |
selectors:aSelector
|
|
93 |
args:argArray
|
|
94 |
receiver:anObject
|
|
95 |
!
|
|
96 |
|
|
97 |
labels:labels selector:aSelector args:argArray receiver:anObject for:aTopMenu
|
|
98 |
"create and return a new MenuView
|
|
99 |
- receiverObject gets message aSelector with argument from
|
|
100 |
argArray for all entries"
|
|
101 |
|
|
102 |
^ (self in:(aTopMenu superView)) labels:labels
|
|
103 |
selectors:aSelector
|
|
104 |
args:argArray
|
|
105 |
receiver:anObject
|
|
106 |
!
|
|
107 |
|
|
108 |
labels:labels selectors:selArray args:argArray receiver:anObject for:aTopMenu
|
|
109 |
^ (self in:(aTopMenu superView)) labels:labels
|
|
110 |
selectors:selArray
|
|
111 |
args:argArray
|
|
112 |
receiver:anObject
|
|
113 |
!
|
|
114 |
|
|
115 |
labels:labels selectors:selArray receiver:anObject for:aTopMenu
|
|
116 |
^ (self in:(aTopMenu superView)) labels:labels
|
|
117 |
selectors:selArray
|
|
118 |
args:nil
|
|
119 |
receiver:anObject
|
|
120 |
! !
|
|
121 |
|
|
122 |
!MenuView methodsFor:'initialization'!
|
|
123 |
|
|
124 |
initialize
|
|
125 |
super initialize.
|
|
126 |
|
|
127 |
disabledFgColor := Color darkGrey.
|
|
128 |
self is3D ifTrue:[
|
|
129 |
borderWidth := 1.
|
|
130 |
self level:1
|
|
131 |
]
|
|
132 |
!
|
|
133 |
|
|
134 |
reinitialize
|
|
135 |
"this is called right after snapIn;
|
|
136 |
a kind of kludge - reset cursor"
|
|
137 |
|
|
138 |
super reinitialize.
|
|
139 |
selection := nil. "self selection:nil."
|
|
140 |
self cursor:Cursor hand
|
|
141 |
!
|
|
142 |
|
7
|
143 |
initStyle
|
|
144 |
super initStyle.
|
|
145 |
|
21
|
146 |
checkColor := fgColor.
|
7
|
147 |
(style == #iris) ifTrue:[
|
|
148 |
device hasGreyscales ifTrue:[
|
|
149 |
hilightFgColor := fgColor.
|
|
150 |
hilightBgColor := bgColor.
|
|
151 |
hilightLevel := 2.
|
21
|
152 |
].
|
|
153 |
device hasColors ifTrue:[
|
|
154 |
checkColor := Color red.
|
|
155 |
].
|
7
|
156 |
]
|
|
157 |
!
|
|
158 |
|
0
|
159 |
initEvents
|
|
160 |
super initEvents.
|
|
161 |
self enableLeaveEvents.
|
|
162 |
self enableButtonMotionEvents
|
|
163 |
!
|
|
164 |
|
|
165 |
create
|
|
166 |
super create.
|
7
|
167 |
subMenuShown := nil.
|
0
|
168 |
self recomputeSize
|
|
169 |
!
|
|
170 |
|
|
171 |
recreate
|
|
172 |
super recreate.
|
|
173 |
self recomputeSize
|
|
174 |
! !
|
|
175 |
|
|
176 |
!MenuView methodsFor:'accessing'!
|
|
177 |
|
7
|
178 |
superMenu:aMenu
|
|
179 |
"set the menu I am contained in
|
|
180 |
- need this to hide main menus when a submenu performed its action"
|
|
181 |
|
|
182 |
superMenu := aMenu
|
|
183 |
!
|
|
184 |
|
|
185 |
superMenu
|
|
186 |
"ret the menu I am contained in
|
|
187 |
- need this to hide main menus when a submenu performed its action"
|
|
188 |
|
|
189 |
^ superMenu
|
|
190 |
!
|
|
191 |
|
|
192 |
subMenuShown
|
|
193 |
"return the currently visible submenu - or nil if there is none"
|
|
194 |
|
|
195 |
^ subMenuShown
|
|
196 |
!
|
|
197 |
|
0
|
198 |
labels
|
|
199 |
"return the menu-labels"
|
|
200 |
|
|
201 |
^ list
|
|
202 |
!
|
|
203 |
|
|
204 |
labels:text
|
|
205 |
"set the labels to the argument, text"
|
|
206 |
|
|
207 |
(text isKindOf:String) ifTrue:[
|
|
208 |
self list:(text asText)
|
|
209 |
] ifFalse:[
|
|
210 |
self list:text
|
|
211 |
].
|
21
|
212 |
enableFlags := Array new:(list size) withAll:true.
|
0
|
213 |
self recomputeSize
|
|
214 |
!
|
|
215 |
|
|
216 |
labelAt:indexOrName put:aString
|
|
217 |
"change the label at index to be aString"
|
|
218 |
|
|
219 |
|i|
|
|
220 |
|
|
221 |
i := self indexOf:indexOrName.
|
3
|
222 |
i == 0 ifTrue:[^ self].
|
0
|
223 |
list at:i put:aString.
|
3
|
224 |
|
0
|
225 |
"create onOff flags, if this label has a check-mark"
|
|
226 |
(aString startsWith:'\c') ifTrue:[
|
|
227 |
onOffFlags isNil ifTrue:[
|
14
|
228 |
onOffFlags := Array new:(list size) withAll:false
|
0
|
229 |
] ifFalse:[
|
14
|
230 |
[onOffFlags size < list size] whileTrue:[
|
|
231 |
onOffFlags := onOffFlags copyWith:false
|
0
|
232 |
]
|
|
233 |
].
|
|
234 |
onOffFlags at:i put:false
|
|
235 |
].
|
|
236 |
self recomputeSize
|
|
237 |
!
|
|
238 |
|
|
239 |
font:aFont
|
|
240 |
"adjust size for new font"
|
|
241 |
|
|
242 |
super font:(aFont on:device).
|
|
243 |
self recomputeSize
|
|
244 |
!
|
|
245 |
|
|
246 |
addLabel:aLabel selector:aSelector
|
|
247 |
"add another label/selector pair"
|
|
248 |
|
|
249 |
list isNil ifTrue:[
|
|
250 |
list := Array with:aLabel
|
|
251 |
] ifFalse:[
|
|
252 |
list := list copyWith:aLabel
|
|
253 |
].
|
|
254 |
selectors := selectors copyWith:aSelector.
|
|
255 |
enableFlags := enableFlags copyWith:true.
|
|
256 |
self recomputeSize
|
|
257 |
!
|
|
258 |
|
|
259 |
addLabel:aLabel selector:aSelector arg:anArg
|
|
260 |
"add another label/selector/argument trio"
|
|
261 |
|
|
262 |
list isNil ifTrue:[
|
|
263 |
list := Array with:aLabel
|
|
264 |
] ifFalse:[
|
|
265 |
list := list copyWith:aLabel
|
|
266 |
].
|
|
267 |
selectors := selectors copyWith:aSelector.
|
|
268 |
args := args copyWith:anArg.
|
|
269 |
enableFlags := enableFlags copyWith:true.
|
|
270 |
self recomputeSize
|
|
271 |
!
|
|
272 |
|
|
273 |
indexOf:indexOrName
|
|
274 |
"return the index of the label named:aName or , if its a symbol
|
|
275 |
the index in the selector list"
|
|
276 |
|
|
277 |
(indexOrName isMemberOf:String) ifTrue:[
|
|
278 |
^ list indexOf:indexOrName
|
|
279 |
].
|
|
280 |
(indexOrName isMemberOf:Symbol) ifTrue:[
|
|
281 |
^ selectors indexOf:indexOrName
|
|
282 |
].
|
|
283 |
^ indexOrName
|
|
284 |
!
|
|
285 |
|
|
286 |
disable:indexOrName
|
|
287 |
"disable an entry"
|
|
288 |
|
|
289 |
|index|
|
|
290 |
|
|
291 |
index := self indexOf:indexOrName.
|
|
292 |
index ~~ 0 ifTrue:[
|
|
293 |
(enableFlags at:index) ifTrue:[
|
|
294 |
enableFlags at:index put:false.
|
|
295 |
shown ifTrue:[
|
|
296 |
self redrawLine:index
|
|
297 |
]
|
|
298 |
]
|
12
|
299 |
] ifFalse:[
|
|
300 |
"try submenus for convenience"
|
|
301 |
(indexOrName isNumber not and:[subMenus notNil]) ifTrue:[
|
|
302 |
subMenus do:[:m |
|
|
303 |
m notNil ifTrue:[
|
|
304 |
m disable:indexOrName
|
|
305 |
]
|
|
306 |
]
|
|
307 |
]
|
0
|
308 |
]
|
|
309 |
!
|
|
310 |
|
|
311 |
enable:indexOrName
|
|
312 |
"enable an entry"
|
|
313 |
|
|
314 |
|index|
|
|
315 |
|
|
316 |
index := self indexOf:indexOrName.
|
|
317 |
index ~~ 0 ifTrue:[
|
|
318 |
(enableFlags at:index) ifFalse:[
|
|
319 |
enableFlags at:index put:true.
|
|
320 |
shown ifTrue:[
|
|
321 |
self redrawLine:index
|
|
322 |
]
|
|
323 |
]
|
12
|
324 |
] ifFalse:[
|
|
325 |
"try submenus for convenience"
|
|
326 |
(indexOrName isNumber not and:[subMenus notNil]) ifTrue:[
|
|
327 |
subMenus do:[:m |
|
|
328 |
m notNil ifTrue:[
|
|
329 |
m enable:indexOrName
|
|
330 |
]
|
|
331 |
]
|
|
332 |
]
|
0
|
333 |
]
|
|
334 |
!
|
|
335 |
|
|
336 |
receiver
|
|
337 |
"return the receiver of the message"
|
|
338 |
|
|
339 |
^ receiver
|
|
340 |
!
|
|
341 |
|
|
342 |
selectors
|
|
343 |
"return the selector array"
|
|
344 |
|
|
345 |
^ selectors
|
|
346 |
!
|
|
347 |
|
|
348 |
selectors:anArray
|
|
349 |
"set the selector array"
|
|
350 |
|
|
351 |
selectors := anArray
|
|
352 |
!
|
|
353 |
|
|
354 |
selectorAt:indexOrName
|
|
355 |
"return an individual selector"
|
|
356 |
|
|
357 |
|i|
|
|
358 |
|
|
359 |
i := self indexOf:indexOrName.
|
3
|
360 |
i ~~ 0 ifTrue:[^ selectors at:i].
|
|
361 |
^ nil
|
0
|
362 |
!
|
|
363 |
|
|
364 |
selectorAt:indexOrName put:aSelector
|
|
365 |
"set an individual selector"
|
|
366 |
|
|
367 |
|i|
|
|
368 |
|
|
369 |
i := self indexOf:indexOrName.
|
3
|
370 |
i ~~ 0 ifTrue:[selectors at:i put:aSelector]
|
0
|
371 |
!
|
|
372 |
|
|
373 |
args
|
|
374 |
"return the argument array"
|
|
375 |
|
|
376 |
^ args
|
|
377 |
!
|
|
378 |
|
|
379 |
args:anArray
|
|
380 |
"set the argument array"
|
|
381 |
|
|
382 |
args := anArray
|
|
383 |
!
|
|
384 |
|
|
385 |
argsAt:indexOrName put:something
|
|
386 |
"set an individual selector"
|
|
387 |
|
3
|
388 |
|i|
|
|
389 |
|
|
390 |
i := self indexOf:indexOrName.
|
|
391 |
i ~~ 0 ifTrue:[args at:i put:something]
|
0
|
392 |
!
|
|
393 |
|
|
394 |
receiver:anObject
|
|
395 |
"set the receiver of the message"
|
|
396 |
|
|
397 |
receiver := anObject
|
|
398 |
!
|
|
399 |
|
|
400 |
labels:text selectors:selArray args:argArray receiver:anObject
|
|
401 |
"set all relevant stuff"
|
|
402 |
|
|
403 |
self labels:text.
|
|
404 |
selectors := selArray.
|
|
405 |
args := argArray.
|
|
406 |
receiver := anObject
|
|
407 |
!
|
|
408 |
|
|
409 |
checkToggleAt:indexOrName
|
|
410 |
"return a check-toggles boolean state"
|
|
411 |
|
|
412 |
|index|
|
|
413 |
|
|
414 |
index := self indexOf:indexOrName.
|
3
|
415 |
index == 0 ifTrue:[^ false].
|
0
|
416 |
onOffFlags isNil ifTrue:[^ false].
|
|
417 |
^ onOffFlags at:index
|
|
418 |
!
|
|
419 |
|
|
420 |
checkToggleAt:indexOrName put:aBoolean
|
|
421 |
"set/clear a check-toggle"
|
|
422 |
|
|
423 |
|index|
|
|
424 |
|
|
425 |
onOffFlags isNil ifTrue:[
|
14
|
426 |
onOffFlags := Array new:(list size) withAll:false
|
0
|
427 |
].
|
|
428 |
index := self indexOf:indexOrName.
|
3
|
429 |
index == 0 ifTrue:[^ self].
|
0
|
430 |
onOffFlags at:index put:aBoolean.
|
|
431 |
shown ifTrue:[
|
|
432 |
self redrawLine:index
|
|
433 |
]
|
|
434 |
!
|
|
435 |
|
|
436 |
subMenuAt:indexOrName
|
|
437 |
"return a submenu, or nil"
|
|
438 |
|
3
|
439 |
|i|
|
|
440 |
|
0
|
441 |
subMenus isNil ifTrue:[^ nil].
|
3
|
442 |
i := self indexOf:indexOrName.
|
|
443 |
i == 0 ifTrue:[^ nil].
|
|
444 |
^ subMenus at:i
|
0
|
445 |
!
|
|
446 |
|
|
447 |
subMenuAt:indexOrName put:aPopUpMenu
|
|
448 |
"define a submenu"
|
|
449 |
|
3
|
450 |
|i|
|
|
451 |
|
|
452 |
i := self indexOf:indexOrName.
|
|
453 |
i == 0 ifTrue:[^ nil].
|
0
|
454 |
subMenus isNil ifTrue:[
|
21
|
455 |
subMenus := Array new:(list size).
|
|
456 |
self recomputeSize
|
0
|
457 |
].
|
3
|
458 |
subMenus at:i put:aPopUpMenu
|
0
|
459 |
! !
|
|
460 |
|
|
461 |
!MenuView methodsFor:'private'!
|
|
462 |
|
7
|
463 |
hideSubmenu
|
|
464 |
subMenuShown notNil ifTrue:[
|
|
465 |
subMenuShown hide.
|
|
466 |
subMenuShown := nil
|
|
467 |
].
|
|
468 |
!
|
|
469 |
|
0
|
470 |
recomputeSize
|
|
471 |
|margin2 w h|
|
|
472 |
|
|
473 |
margin2 := margin * 2.
|
|
474 |
w := self widthOfContents + leftMargin + leftMargin + margin2.
|
|
475 |
h := (self numberOfLines) * fontHeight + (2 * topMargin) + margin2.
|
21
|
476 |
"if there is a submenu, add some space for the right arrow"
|
|
477 |
subMenus notNil ifTrue:[
|
|
478 |
w := w + 16
|
|
479 |
].
|
0
|
480 |
self extent:(w @ h).
|
|
481 |
(font device == device) ifTrue:[
|
|
482 |
self computeNumberOfLinesShown
|
|
483 |
]
|
|
484 |
!
|
|
485 |
|
|
486 |
setSelectionForX:x y:y
|
7
|
487 |
|newSelection org mx my|
|
0
|
488 |
|
|
489 |
newSelection := self positionToSelectionX:x y:y.
|
7
|
490 |
newSelection ~= selection ifTrue:[
|
|
491 |
self selection:newSelection.
|
|
492 |
subMenuShown notNil ifTrue:[
|
|
493 |
subMenuShown hide.
|
|
494 |
subMenuShown := nil
|
|
495 |
].
|
|
496 |
newSelection notNil ifTrue:[
|
|
497 |
(enableFlags at:newSelection) ifFalse:[
|
|
498 |
newSelection := nil
|
|
499 |
] ifTrue:[
|
|
500 |
subMenus notNil ifTrue:[
|
|
501 |
subMenuShown := subMenus at:newSelection.
|
|
502 |
subMenuShown notNil ifTrue:[
|
|
503 |
"old: show at pointer"
|
|
504 |
"
|
|
505 |
org := device translatePoint:(x @ y)
|
|
506 |
from:(self id)
|
|
507 |
to:(DisplayRootView new id).
|
|
508 |
org := org - 10.
|
|
509 |
"
|
|
510 |
"new: show at right of this menu"
|
21
|
511 |
mx := width - 5.
|
7
|
512 |
my := self yOfLine:newSelection.
|
|
513 |
org := device translatePoint:(mx @ my)
|
|
514 |
from:(self id)
|
|
515 |
to:(DisplayRootView new id).
|
|
516 |
|
|
517 |
ActiveGrab == self ifTrue:[
|
|
518 |
device ungrabPointer.
|
|
519 |
ActiveGrab := nil
|
|
520 |
].
|
|
521 |
subMenuShown superMenu:self.
|
|
522 |
subMenuShown showAt:org.
|
|
523 |
^ self
|
|
524 |
]
|
|
525 |
] ifFalse:[
|
|
526 |
subMenuShown := nil
|
0
|
527 |
]
|
|
528 |
]
|
7
|
529 |
].
|
|
530 |
]
|
0
|
531 |
! !
|
|
532 |
|
|
533 |
!MenuView methodsFor:'showing'!
|
|
534 |
|
|
535 |
show
|
|
536 |
hidden := false.
|
|
537 |
super realize
|
|
538 |
! !
|
|
539 |
|
|
540 |
!MenuView methodsFor:'redrawing'!
|
|
541 |
|
|
542 |
drawMarkInVisibleLine:visLineNr with:fg and:bg
|
|
543 |
"draw an on-mark"
|
|
544 |
|
|
545 |
|w h y x l check|
|
|
546 |
|
|
547 |
l := self visibleLineToListLine:visLineNr.
|
|
548 |
onOffFlags isNil ifTrue:[
|
14
|
549 |
onOffFlags := Array new:(list size) withAll:false.
|
0
|
550 |
check := false
|
|
551 |
] ifFalse:[
|
|
552 |
check := onOffFlags at:l.
|
|
553 |
].
|
|
554 |
|
14
|
555 |
w := font widthOf:'\c'.
|
0
|
556 |
h := font ascent.
|
|
557 |
|
|
558 |
x := (self xOfCol:1 inLine:visLineNr) - leftOffset.
|
|
559 |
y := self yOfLine:visLineNr.
|
|
560 |
|
|
561 |
self paint:bg.
|
7
|
562 |
self fillRectangleX:x y:y width:w height:fontHeight.
|
0
|
563 |
self paint:fg.
|
|
564 |
check ifTrue:[
|
21
|
565 |
self paint:checkColor.
|
0
|
566 |
self displayLineFromX:x
|
|
567 |
y:(y + (h // 2))
|
|
568 |
toX:(x + (w // 3))
|
|
569 |
y:(y + h - 1).
|
|
570 |
|
|
571 |
self displayLineFromX:(x + (w // 3))
|
|
572 |
y:(y + h - 1)
|
|
573 |
toX:(x + w - 1)
|
|
574 |
y:y
|
|
575 |
]
|
|
576 |
!
|
|
577 |
|
|
578 |
drawVisibleLine:visLineNr with:fg and:bg
|
|
579 |
|line isSpecial special|
|
|
580 |
|
|
581 |
line := self visibleAt:visLineNr.
|
|
582 |
|
|
583 |
isSpecial := false.
|
|
584 |
|
|
585 |
((line at:1) == $\) ifTrue:[
|
|
586 |
special := line at:2.
|
|
587 |
(special == $c) ifTrue:[
|
|
588 |
isSpecial := true
|
|
589 |
]
|
|
590 |
].
|
|
591 |
isSpecial ifFalse:[
|
|
592 |
super drawVisibleLine:visLineNr with:fg and:bg
|
|
593 |
] ifTrue:[
|
7
|
594 |
super drawVisibleLine:visLineNr "from:3" with:fg and:bg.
|
0
|
595 |
self drawMarkInVisibleLine:visLineNr with:fg and:bg
|
|
596 |
]
|
|
597 |
!
|
|
598 |
|
|
599 |
redrawVisibleLine:visLine col:col
|
|
600 |
self redrawVisibleLine:visLine
|
|
601 |
!
|
|
602 |
|
|
603 |
redrawVisibleLine:visLine from:startCol
|
|
604 |
self redrawVisibleLine:visLine
|
|
605 |
!
|
|
606 |
|
|
607 |
redrawVisibleLine:visLine from:startCol to:endCol
|
|
608 |
self redrawVisibleLine:visLine
|
|
609 |
!
|
|
610 |
|
|
611 |
redrawVisibleLine:visLineNr
|
|
612 |
|line lineNr y isSpecial isSeparatingLine mm right|
|
|
613 |
|
|
614 |
line := self visibleAt:visLineNr.
|
|
615 |
|
|
616 |
isSpecial := false.
|
|
617 |
(line = '-') ifTrue:[
|
|
618 |
isSeparatingLine := true.
|
|
619 |
isSpecial := true
|
|
620 |
] ifFalse:[
|
|
621 |
(line = '') ifTrue:[
|
|
622 |
isSeparatingLine := false.
|
|
623 |
isSpecial := true
|
|
624 |
]
|
|
625 |
].
|
|
626 |
isSpecial ifFalse:[
|
|
627 |
lineNr := self visibleLineToListLine:visLineNr.
|
|
628 |
(enableFlags at:lineNr) ifFalse:[
|
|
629 |
self drawVisibleLine:visLineNr with:disabledFgColor and:bgColor
|
|
630 |
] ifTrue:[
|
|
631 |
super redrawVisibleLine:visLineNr
|
|
632 |
].
|
21
|
633 |
"is there a submenu ?"
|
|
634 |
(subMenus notNil and:[(subMenus at:lineNr) notNil]) ifTrue:[
|
|
635 |
self drawRightArrowInVisibleLine:visLineNr
|
|
636 |
].
|
0
|
637 |
^ self
|
|
638 |
].
|
|
639 |
|
|
640 |
"handle separating lines"
|
|
641 |
|
|
642 |
y := self yOfLine:visLineNr.
|
|
643 |
self is3D ifFalse:[
|
|
644 |
self paint:bgColor.
|
|
645 |
self fillRectangleX:0 y:y
|
|
646 |
width:width height:fontHeight
|
|
647 |
].
|
|
648 |
isSeparatingLine ifTrue:[
|
|
649 |
y := y + (fontHeight // 2).
|
|
650 |
self is3D ifFalse:[
|
|
651 |
self paint:fgColor.
|
|
652 |
self displayLineFromX:0 y:y toX:width y:y
|
|
653 |
] ifTrue:[
|
|
654 |
"the inset on each side"
|
|
655 |
mm := (device horizontalPixelPerMillimeter * 0.8) rounded.
|
|
656 |
right := width - 1 - mm.
|
|
657 |
self paint:shadowColor.
|
|
658 |
self displayLineFromX:mm y:y toX:right y:y.
|
|
659 |
self paint:lightColor.
|
|
660 |
y := y + 1.
|
|
661 |
self displayLineFromX:mm y:y toX:right y:y
|
|
662 |
]
|
|
663 |
]
|
|
664 |
!
|
|
665 |
|
|
666 |
redrawFromVisibleLine:start to:stop
|
|
667 |
"redraw a line range"
|
|
668 |
|
|
669 |
"the natural way to do it is:
|
|
670 |
|
|
671 |
start to:stop do:[:visLine |
|
|
672 |
self redrawVisibleLine:visLine
|
|
673 |
]
|
|
674 |
|
|
675 |
but I want to draw the stuff in big chunks for slow machines ..."
|
|
676 |
|
|
677 |
|first current line special index|
|
|
678 |
|
|
679 |
first := start.
|
|
680 |
current := start.
|
|
681 |
index := self visibleLineToListLine:start.
|
|
682 |
index notNil ifTrue:[
|
|
683 |
[current <= stop] whileTrue:[
|
|
684 |
line := self visibleAt:current.
|
|
685 |
|
|
686 |
special := (line = '-') or:[(line = '') or:[(line at:1) == $\]].
|
21
|
687 |
(special
|
|
688 |
or:[(enableFlags at:index) not]) ifTrue:[
|
0
|
689 |
"a special case"
|
|
690 |
(first < current) ifTrue:[
|
|
691 |
super redrawFromVisibleLine:first to:(current - 1)
|
|
692 |
].
|
|
693 |
self redrawVisibleLine:current.
|
|
694 |
first := current + 1
|
|
695 |
].
|
|
696 |
current := current + 1.
|
|
697 |
index := index + 1
|
|
698 |
].
|
|
699 |
(first < current) ifTrue:[
|
|
700 |
super redrawFromVisibleLine:first to:(current - 1)
|
21
|
701 |
].
|
|
702 |
|
|
703 |
"draw submenu marks"
|
|
704 |
subMenus notNil ifTrue:[
|
|
705 |
index := self visibleLineToListLine:start.
|
|
706 |
start to:stop do:[:l |
|
|
707 |
index <= subMenus size ifTrue:[
|
|
708 |
(subMenus at:index) notNil ifTrue:[
|
|
709 |
self drawRightArrowInVisibleLine:l
|
|
710 |
].
|
|
711 |
index := index + 1
|
|
712 |
]
|
|
713 |
]
|
0
|
714 |
]
|
|
715 |
]
|
|
716 |
! !
|
|
717 |
|
7
|
718 |
!MenuView methodsFor:'submenu actions'!
|
|
719 |
|
|
720 |
submenuTriggered
|
|
721 |
"submenu has performed some action - have to deselect here"
|
|
722 |
|
|
723 |
self selection:nil.
|
|
724 |
"a bad kludge - 5 minutes before writing the alpha tapes ..."
|
|
725 |
(superView isKindOf:PopUpMenu) ifTrue:[
|
|
726 |
superView hide
|
|
727 |
].
|
|
728 |
superMenu notNil ifTrue:[
|
|
729 |
superMenu submenuTriggered
|
|
730 |
].
|
|
731 |
!
|
|
732 |
|
|
733 |
regainControl
|
|
734 |
"take over pointer control from a submenu"
|
|
735 |
|
|
736 |
^ self
|
|
737 |
!
|
|
738 |
|
|
739 |
showActive
|
|
740 |
"submenu is about to perform an action - show wait cursor here as well"
|
|
741 |
|
|
742 |
self cursor:(Cursor wait)
|
|
743 |
!
|
|
744 |
|
|
745 |
showPassive
|
|
746 |
"submenu has performed its action - show normal cursor again"
|
|
747 |
|
|
748 |
self cursor:(Cursor hand)
|
|
749 |
! !
|
|
750 |
|
0
|
751 |
!MenuView methodsFor:'event handling'!
|
|
752 |
|
|
753 |
buttonPress:button x:x y:y
|
|
754 |
self setSelectionForX:x y:y
|
|
755 |
!
|
|
756 |
|
|
757 |
buttonMotion:state x:x y:y
|
|
758 |
self setSelectionForX:x y:y
|
|
759 |
!
|
|
760 |
|
|
761 |
pointerLeave:state
|
7
|
762 |
subMenuShown notNil ifTrue:[
|
|
763 |
^ self
|
|
764 |
].
|
0
|
765 |
self setSelectionForX:-1 y:-1. "force deselect"
|
7
|
766 |
subMenuShown isNil ifTrue:[
|
0
|
767 |
self selection:nil
|
7
|
768 |
].
|
|
769 |
superMenu notNil ifTrue:[
|
|
770 |
superMenu regainControl.
|
0
|
771 |
]
|
|
772 |
!
|
|
773 |
|
|
774 |
buttonRelease:button x:x y:y
|
|
775 |
|theSelector isCheck|
|
|
776 |
|
7
|
777 |
subMenuShown notNil ifTrue:[
|
|
778 |
^ self
|
|
779 |
].
|
|
780 |
|
0
|
781 |
(x >= 0 and:[x < width]) ifTrue:[
|
|
782 |
(y >= 0 and:[y < height]) ifTrue:[
|
|
783 |
selection notNil ifTrue:[
|
7
|
784 |
(subMenus isNil or:[(subMenus at:selection) isNil]) ifTrue:[
|
|
785 |
self cursor:Cursor wait.
|
|
786 |
superMenu notNil ifTrue:[
|
|
787 |
superMenu showActive
|
|
788 |
].
|
|
789 |
actionBlock notNil ifTrue:[
|
|
790 |
actionBlock value:(self selection)
|
0
|
791 |
].
|
7
|
792 |
selectors notNil ifTrue: [
|
|
793 |
ActiveGrab == self ifTrue:[
|
|
794 |
device ungrabPointer.
|
|
795 |
ActiveGrab := nil.
|
|
796 |
].
|
|
797 |
(selectors isKindOf:Symbol) ifFalse:[
|
|
798 |
selection <= (selectors size) ifTrue:[
|
|
799 |
theSelector := selectors at:selection
|
0
|
800 |
]
|
7
|
801 |
] ifTrue:[
|
|
802 |
theSelector := selectors
|
0
|
803 |
].
|
7
|
804 |
theSelector notNil ifTrue:[
|
|
805 |
isCheck := false.
|
|
806 |
onOffFlags notNil ifTrue:[
|
|
807 |
onOffFlags size >= selection ifTrue:[
|
|
808 |
isCheck := (onOffFlags at:selection) notNil
|
|
809 |
]
|
|
810 |
].
|
|
811 |
isCheck ifTrue:[
|
|
812 |
onOffFlags at:selection
|
|
813 |
put:(onOffFlags at:selection) not.
|
|
814 |
self redrawLine:selection.
|
0
|
815 |
receiver perform:theSelector
|
7
|
816 |
with:(onOffFlags at:selection)
|
0
|
817 |
] ifFalse:[
|
7
|
818 |
args isNil ifTrue:[
|
|
819 |
receiver perform:theSelector
|
|
820 |
] ifFalse:[
|
|
821 |
receiver perform:theSelector
|
|
822 |
with:(args at:selection)
|
|
823 |
]
|
0
|
824 |
]
|
|
825 |
]
|
7
|
826 |
].
|
|
827 |
realized ifTrue:[
|
|
828 |
self cursor:Cursor hand.
|
|
829 |
].
|
|
830 |
superMenu notNil ifTrue:[
|
|
831 |
superMenu showPassive
|
|
832 |
].
|
0
|
833 |
].
|
|
834 |
]
|
|
835 |
]
|
|
836 |
]
|
|
837 |
! !
|