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 |
View subclass:#PullDownMenu
|
91
|
14 |
instanceVariableNames:'menus titles selectors activeMenuNumber
|
59
|
15 |
showSeparatingLines topMargin
|
|
16 |
fgColor bgColor activeFgColor activeBgColor
|
63
|
17 |
onLevel offLevel edgeStyle
|
59
|
18 |
keepMenu'
|
|
19 |
classVariableNames:'DefaultFont
|
|
20 |
DefaultViewBackground
|
|
21 |
DefaultForegroundColor
|
|
22 |
DefaultBackgroundColor
|
|
23 |
DefaultHilightForegroundColor
|
|
24 |
DefaultHilightBackgroundColor
|
|
25 |
DefaultLevel DefaultHilightLevel
|
63
|
26 |
DefaultShadowColor DefaultLightColor
|
77
|
27 |
DefaultEdgeStyle DefaultKeepMenu'
|
0
|
28 |
poolDictionaries:''
|
|
29 |
category:'Views-Menus'
|
|
30 |
!
|
|
31 |
|
|
32 |
PullDownMenu comment:'
|
5
|
33 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
34 |
All Rights Reserved
|
0
|
35 |
|
95
|
36 |
$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.12 1995-02-27 10:40:40 claus Exp $
|
3
|
37 |
'!
|
0
|
38 |
|
3
|
39 |
!PullDownMenu class methodsFor:'documentation'!
|
|
40 |
|
38
|
41 |
copyright
|
|
42 |
"
|
|
43 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
59
|
44 |
All Rights Reserved
|
38
|
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 |
version
|
|
56 |
"
|
95
|
57 |
$Header: /cvs/stx/stx/libwidg/Attic/PullDMenu.st,v 1.12 1995-02-27 10:40:40 claus Exp $
|
38
|
58 |
"
|
|
59 |
!
|
|
60 |
|
3
|
61 |
documentation
|
|
62 |
"
|
38
|
63 |
PullDown menu provides the top (always visible) part of these menus.
|
|
64 |
It controls display of its menus, which become visible when one of the
|
|
65 |
PullDownMenus entries is pressed.
|
0
|
66 |
|
38
|
67 |
Instance variables:
|
0
|
68 |
|
38
|
69 |
menus <aCollection> the sub menus
|
|
70 |
titles <aCollection> the strings in the menu
|
|
71 |
activeMenuNumber <Number> the index of the currently active menu
|
|
72 |
showSeparatingLines <Boolean> show separating lines between my menu-strings
|
|
73 |
topMargin <Number> number of pixels at top
|
|
74 |
fgColor <Color> color to draw passive menu-titles
|
|
75 |
bgColor <Color> color to draw passive menu-titles
|
|
76 |
activeFgColor <Color> color to draw activated menu-titles
|
|
77 |
activeBgColor <Color> color to draw activated menu-titles
|
|
78 |
onLevel <Integer> level of entry-buttons when pressed
|
|
79 |
offLevel <Integer> level of entry-buttons when released
|
|
80 |
keepmenu <Boolean> if on, pulled menu stays on click,
|
59
|
81 |
till clicked again (motif & windows behavior)
|
77
|
82 |
|
|
83 |
|
|
84 |
StyleSheet values:
|
|
85 |
|
|
86 |
pullDownMenuViewBackground view background Color
|
|
87 |
default: menuViewBackground
|
|
88 |
|
|
89 |
pullDownMenuForegroundColor foreground drawing color
|
|
90 |
default: menuForegroundColor
|
|
91 |
|
|
92 |
pullDownMenuBackgroundColor background drawing color
|
|
93 |
default: menuBackgroundColor
|
|
94 |
|
|
95 |
pullDownMenuHilightForegroundColor active foreground drawing color
|
|
96 |
default: menuHilightForegroundColor
|
|
97 |
|
|
98 |
pullDownMenuHilightBackgroundColor active background drawing color
|
|
99 |
default: menuHilightBackgroundColor
|
|
100 |
|
|
101 |
pullDownMenuHilightLevel level (3D only) when active
|
|
102 |
default: menuHilightLevel
|
|
103 |
|
|
104 |
pullDownMenuEdgeStyle edge style (nil or #soft)
|
|
105 |
|
|
106 |
pullDownMenuKeepMenu if true, menu stays open until button
|
|
107 |
is pressed again (motif behavior)
|
|
108 |
if false, menu closes on release (default)
|
|
109 |
|
|
110 |
pullDownMenuLevel level (3D only)
|
|
111 |
|
|
112 |
pullDownMenuFont font
|
|
113 |
default: menuFont
|
3
|
114 |
"
|
|
115 |
! !
|
0
|
116 |
|
59
|
117 |
!PullDownMenu class methodsFor:'defaults'!
|
|
118 |
|
|
119 |
updateStyleCache
|
60
|
120 |
DefaultViewBackground := StyleSheet colorAt:'pullDownMenuViewBackground'.
|
|
121 |
DefaultViewBackground isNil ifTrue:[
|
|
122 |
DefaultViewBackground := StyleSheet colorAt:'menuViewBackground'.
|
59
|
123 |
].
|
60
|
124 |
DefaultForegroundColor := StyleSheet colorAt:'pullDownMenuForegroundColor'.
|
|
125 |
DefaultForegroundColor isNil ifTrue:[
|
|
126 |
DefaultForegroundColor := StyleSheet colorAt:'menuForegroundColor'.
|
|
127 |
].
|
|
128 |
DefaultBackgroundColor := StyleSheet colorAt:'pullDownMenuBackgroundColor'.
|
|
129 |
DefaultBackgroundColor isNil ifTrue:[
|
77
|
130 |
DefaultViewBackground notNil ifTrue:[
|
|
131 |
DefaultBackgroundColor := DefaultViewBackground
|
|
132 |
] ifFalse:[
|
|
133 |
DefaultBackgroundColor := StyleSheet colorAt:'menuBackgroundColor'.
|
|
134 |
]
|
59
|
135 |
].
|
60
|
136 |
DefaultHilightForegroundColor := StyleSheet colorAt:'pullDownMenuHilightForegroundColor'.
|
|
137 |
DefaultHilightForegroundColor isNil ifTrue:[
|
|
138 |
DefaultHilightForegroundColor := StyleSheet colorAt:'menuHilightForegroundColor'.
|
59
|
139 |
].
|
60
|
140 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'pullDownMenuHilightBackgroundColor'.
|
|
141 |
DefaultHilightBackgroundColor isNil ifTrue:[
|
|
142 |
DefaultHilightBackgroundColor := StyleSheet colorAt:'menuHilightBackgroundColor'.
|
59
|
143 |
].
|
60
|
144 |
DefaultHilightLevel := StyleSheet at:'pullDownMenuHilightLevel'.
|
|
145 |
DefaultHilightLevel isNil ifTrue:[
|
|
146 |
DefaultHilightLevel := StyleSheet at:'menuHilightLevel' default:0.
|
59
|
147 |
].
|
63
|
148 |
DefaultEdgeStyle := StyleSheet at:'pullDownMenuEdgeStyle'.
|
77
|
149 |
DefaultKeepMenu := StyleSheet at:'pullDownMenuKeepMenu' default:false.
|
60
|
150 |
DefaultLevel := StyleSheet at:'pullDownMenuLevel' default:1.
|
|
151 |
DefaultFont := StyleSheet fontAt:'pullDownMenuFont'.
|
|
152 |
DefaultFont isNil ifTrue:[
|
|
153 |
DefaultFont := StyleSheet fontAt:'menuFont'.
|
59
|
154 |
].
|
|
155 |
! !
|
|
156 |
|
0
|
157 |
!PullDownMenu class methodsFor:'instance creation'!
|
|
158 |
|
|
159 |
labels:titleArray
|
|
160 |
"create and return a new PullDownMenu"
|
|
161 |
|
|
162 |
^ self new labels:titleArray
|
|
163 |
! !
|
|
164 |
|
77
|
165 |
!PullDownMenu methodsFor:'initialize / release'!
|
0
|
166 |
|
|
167 |
initialize
|
|
168 |
super initialize.
|
|
169 |
|
|
170 |
font := font on:device.
|
|
171 |
self origin:(0.0 @ 0.0)
|
59
|
172 |
extent:(1.0 @ (font height + (font descent * 2) + topMargin)).
|
0
|
173 |
!
|
|
174 |
|
|
175 |
initStyle
|
|
176 |
super initStyle.
|
|
177 |
|
|
178 |
showSeparatingLines := false.
|
59
|
179 |
DefaultViewBackground notNil ifTrue:[
|
60
|
180 |
viewBackground := DefaultViewBackground on:device
|
59
|
181 |
].
|
|
182 |
|
60
|
183 |
DefaultFont notNil ifTrue:[
|
|
184 |
font := DefaultFont on:device
|
|
185 |
].
|
59
|
186 |
DefaultForegroundColor notNil ifTrue:[
|
|
187 |
fgColor := DefaultForegroundColor
|
|
188 |
] ifFalse:[
|
|
189 |
fgColor := Black.
|
|
190 |
].
|
|
191 |
DefaultBackgroundColor notNil ifTrue:[
|
|
192 |
bgColor := DefaultBackgroundColor
|
|
193 |
] ifFalse:[
|
|
194 |
bgColor := viewBackground.
|
|
195 |
].
|
|
196 |
onLevel := DefaultHilightLevel.
|
|
197 |
offLevel := DefaultLevel.
|
21
|
198 |
|
0
|
199 |
self is3D ifTrue:[
|
59
|
200 |
device hasColors ifTrue:[
|
|
201 |
activeFgColor := Color name:'yellow'
|
|
202 |
] ifFalse:[
|
|
203 |
activeFgColor := White
|
|
204 |
].
|
|
205 |
device hasGreyscales ifTrue:[
|
|
206 |
activeBgColor := bgColor.
|
|
207 |
] ifFalse:[
|
|
208 |
activeBgColor := fgColor.
|
|
209 |
].
|
|
210 |
topMargin := 2.
|
21
|
211 |
|
77
|
212 |
((StyleSheet name == #iris) or:[StyleSheet name == #motif]) ifTrue:[
|
59
|
213 |
self level:2.
|
|
214 |
onLevel := 2.
|
|
215 |
offLevel := 0.
|
|
216 |
activeFgColor := fgColor
|
|
217 |
]
|
0
|
218 |
] ifFalse:[
|
59
|
219 |
activeFgColor := bgColor.
|
|
220 |
activeBgColor := fgColor.
|
|
221 |
topMargin := 0
|
|
222 |
].
|
|
223 |
|
63
|
224 |
edgeStyle := DefaultEdgeStyle.
|
|
225 |
keepMenu := DefaultKeepMenu.
|
|
226 |
|
59
|
227 |
DefaultHilightForegroundColor notNil ifTrue:[
|
|
228 |
activeFgColor := DefaultHilightForegroundColor
|
|
229 |
].
|
|
230 |
DefaultHilightBackgroundColor notNil ifTrue:[
|
|
231 |
activeBgColor := DefaultHilightBackgroundColor
|
0
|
232 |
].
|
59
|
233 |
DefaultShadowColor notNil ifTrue:[
|
|
234 |
shadowColor := DefaultShadowColor on:device
|
|
235 |
].
|
|
236 |
DefaultLightColor notNil ifTrue:[
|
|
237 |
lightColor := DefaultLightColor on:device
|
|
238 |
].
|
|
239 |
|
|
240 |
bgColor := bgColor on:device.
|
|
241 |
fgColor := fgColor on:device.
|
|
242 |
activeBgColor := activeBgColor on:device.
|
|
243 |
activeFgColor := activeFgColor on:device.
|
0
|
244 |
!
|
|
245 |
|
|
246 |
recreate
|
|
247 |
super create.
|
|
248 |
self setMenuOrigins
|
|
249 |
!
|
|
250 |
|
|
251 |
create
|
|
252 |
super create.
|
|
253 |
self setMenuOrigins
|
77
|
254 |
!
|
|
255 |
|
|
256 |
destroy
|
|
257 |
super destroy.
|
|
258 |
"
|
|
259 |
have to destroy the menus manually here,
|
|
260 |
since they are no real subviews of myself
|
|
261 |
"
|
|
262 |
menus notNil ifTrue:[
|
|
263 |
menus do:[:m |
|
|
264 |
m notNil ifTrue:[m destroy]
|
|
265 |
].
|
|
266 |
menus := nil
|
|
267 |
]
|
0
|
268 |
! !
|
|
269 |
|
|
270 |
!PullDownMenu methodsFor:'accessing'!
|
|
271 |
|
|
272 |
showSeparatingLines:aBoolean
|
|
273 |
"turn on/off drawing of separating lines"
|
|
274 |
|
|
275 |
showSeparatingLines := aBoolean.
|
|
276 |
shown ifTrue:[
|
59
|
277 |
self redraw
|
0
|
278 |
]
|
|
279 |
!
|
|
280 |
|
|
281 |
numberOfTitles:n
|
|
282 |
"setup blank title-space to be filled in later"
|
|
283 |
|
|
284 |
menus := Array new:n.
|
|
285 |
titles := Array new:n
|
|
286 |
!
|
|
287 |
|
|
288 |
labels:titleArray
|
|
289 |
"define the menu-titles (group-headers)"
|
|
290 |
|
|
291 |
|numberOfLabels|
|
|
292 |
|
|
293 |
numberOfLabels := titleArray size.
|
|
294 |
menus := Array new:numberOfLabels.
|
|
295 |
titles := Array new:numberOfLabels.
|
|
296 |
1 to:numberOfLabels do:[:index |
|
59
|
297 |
titles at:index put:(titleArray at:index) printString
|
0
|
298 |
].
|
|
299 |
shown ifTrue:[
|
59
|
300 |
self clear.
|
|
301 |
self redraw
|
0
|
302 |
]
|
|
303 |
!
|
|
304 |
|
|
305 |
labels
|
|
306 |
"return the menu-titles (group-headers)"
|
|
307 |
|
|
308 |
^ titles
|
|
309 |
!
|
|
310 |
|
91
|
311 |
selectors:selectorArray
|
|
312 |
"define the menu-selectors. These are used as accesskey only
|
|
313 |
in menuAt: accesses. This makes PullDownMenu accesss
|
|
314 |
somewhat more compatible to PopUpMenus."
|
|
315 |
|
|
316 |
selectors := selectorArray.
|
|
317 |
!
|
|
318 |
|
0
|
319 |
font:aFont
|
|
320 |
"adjust menu-origins when font changes"
|
|
321 |
|
3
|
322 |
super font:(aFont on:device).
|
|
323 |
self height:(font height + (font descent * 2)).
|
0
|
324 |
self setMenuOrigins
|
|
325 |
!
|
|
326 |
|
|
327 |
menuAt:string
|
|
328 |
"return the menu with the title; return nil if not found"
|
|
329 |
|
|
330 |
|index|
|
|
331 |
|
|
332 |
index := self indexOf:string.
|
|
333 |
(index == 0) ifTrue:[^ nil].
|
|
334 |
^ menus at:index
|
|
335 |
!
|
|
336 |
|
|
337 |
at:aString putMenu:aMenu
|
|
338 |
"set the menu under the title, aString"
|
|
339 |
|
|
340 |
|index|
|
|
341 |
|
|
342 |
index := self indexOf:aString.
|
|
343 |
(index == 0) ifTrue:[^ nil].
|
|
344 |
aMenu origin:((left + (self titleLenUpTo:index))
|
59
|
345 |
@
|
|
346 |
(height + aMenu borderWidth)).
|
0
|
347 |
aMenu hidden:true.
|
77
|
348 |
menus at:index put:aMenu.
|
|
349 |
aMenu masterView:self.
|
0
|
350 |
!
|
|
351 |
|
|
352 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject
|
|
353 |
"create and set the menu under the title, aString"
|
|
354 |
|
|
355 |
|menuView|
|
|
356 |
|
|
357 |
menuView := MenuView labels:labels
|
59
|
358 |
selectors:selectors
|
|
359 |
args:args
|
|
360 |
receiver:anObject
|
|
361 |
for:self.
|
0
|
362 |
self at:aString putMenu:menuView
|
|
363 |
!
|
|
364 |
|
|
365 |
at:aString putLabels:labels selector:selector args:args receiver:anObject
|
|
366 |
"create and set the menu under the title, aString"
|
|
367 |
|
|
368 |
|menuView|
|
|
369 |
|
|
370 |
menuView := MenuView labels:labels
|
59
|
371 |
selector:selector
|
|
372 |
args:args
|
|
373 |
receiver:anObject
|
|
374 |
for:self.
|
0
|
375 |
self at:aString putMenu:menuView
|
|
376 |
!
|
|
377 |
|
|
378 |
at:aString putLabels:labels selectors:selectors receiver:anObject
|
|
379 |
"create and set the menu under the title, aString"
|
|
380 |
|
|
381 |
|menuView|
|
|
382 |
|
|
383 |
menuView := MenuView labels:labels
|
59
|
384 |
selectors:selectors
|
|
385 |
receiver:anObject
|
|
386 |
for:self.
|
0
|
387 |
self at:aString putMenu:menuView
|
|
388 |
! !
|
|
389 |
|
|
390 |
!PullDownMenu methodsFor:'private'!
|
|
391 |
|
|
392 |
titleLenUpTo:index
|
|
393 |
"answer len of all title-strings up-to (but excluding) title-index"
|
|
394 |
|
|
395 |
|len "{ Class: SmallInteger }" |
|
|
396 |
|
|
397 |
(index <= 1) ifTrue:[^ 0].
|
|
398 |
len := 0.
|
|
399 |
titles from:1 to:(index - 1) do:[:string |
|
59
|
400 |
len := len + (font widthOf:(' ' , string , ' ')).
|
|
401 |
showSeparatingLines ifTrue:[
|
|
402 |
self is3D ifTrue:[
|
|
403 |
len := len + 2
|
|
404 |
] ifFalse:[
|
|
405 |
len := len + 1
|
|
406 |
]
|
|
407 |
]
|
0
|
408 |
].
|
|
409 |
^ len
|
|
410 |
!
|
|
411 |
|
|
412 |
indexOf:stringOrNumber
|
91
|
413 |
"return the index of the menu with title; return 0 if not found.
|
|
414 |
stringOrNumber may be a number, a selector from the selectorArray
|
|
415 |
or a string from the title array."
|
|
416 |
|
|
417 |
|idx|
|
0
|
418 |
|
91
|
419 |
stringOrNumber isNumber ifTrue:[
|
59
|
420 |
^ stringOrNumber
|
0
|
421 |
].
|
91
|
422 |
selectors notNil ifTrue:[
|
|
423 |
idx := selectors indexOf:stringOrNumber.
|
|
424 |
idx ~~ 0 ifTrue:[^ idx].
|
|
425 |
].
|
0
|
426 |
^ titles indexOf:stringOrNumber
|
|
427 |
!
|
|
428 |
|
|
429 |
setMenuOrigins
|
|
430 |
"adjust origins of menus when font changes"
|
|
431 |
|
|
432 |
|index|
|
|
433 |
|
|
434 |
(font device == device) ifTrue:[
|
59
|
435 |
index := 1.
|
|
436 |
menus do:[:aMenu |
|
|
437 |
aMenu notNil ifTrue:[
|
|
438 |
aMenu origin:((left + (self titleLenUpTo:index))
|
|
439 |
@
|
|
440 |
(height + aMenu borderWidth))
|
|
441 |
].
|
|
442 |
index := index + 1
|
|
443 |
]
|
0
|
444 |
]
|
|
445 |
! !
|
|
446 |
|
|
447 |
!PullDownMenu methodsFor:'hiding/showing menus'!
|
|
448 |
|
|
449 |
drawTitle:string x:x selected:selected
|
|
450 |
|yText w|
|
|
451 |
|
3
|
452 |
yText := ((height - (font height)) // 2) + (font ascent) "+ topMargin".
|
0
|
453 |
w := font widthOf:string.
|
|
454 |
selected ifTrue:[
|
59
|
455 |
self paint:activeBgColor
|
0
|
456 |
] ifFalse:[
|
59
|
457 |
self paint:bgColor
|
0
|
458 |
].
|
|
459 |
self fillRectangleX:x y:0 width:w height:height.
|
|
460 |
|
|
461 |
self is3D ifTrue:[
|
59
|
462 |
self drawEdgesForX:x y:0
|
|
463 |
width:w
|
|
464 |
height:height
|
|
465 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel])
|
0
|
466 |
].
|
|
467 |
selected ifTrue:[
|
59
|
468 |
self paint:activeFgColor
|
0
|
469 |
] ifFalse:[
|
59
|
470 |
self paint:fgColor
|
0
|
471 |
].
|
|
472 |
self displayString:string x:x y:yText
|
|
473 |
!
|
|
474 |
|
|
475 |
highlightActiveTitle
|
|
476 |
|x string|
|
|
477 |
activeMenuNumber notNil ifTrue:[
|
59
|
478 |
x := self titleLenUpTo:activeMenuNumber.
|
|
479 |
string := ' ' , (titles at:activeMenuNumber) , ' '.
|
|
480 |
self drawTitle:string x:x selected:true
|
0
|
481 |
]
|
|
482 |
!
|
|
483 |
|
|
484 |
unHighlightActiveTitle
|
|
485 |
|x string|
|
|
486 |
activeMenuNumber notNil ifTrue:[
|
59
|
487 |
x := self titleLenUpTo:activeMenuNumber.
|
|
488 |
string := ' ' , (titles at:activeMenuNumber) , ' '.
|
|
489 |
self drawTitle:string x:x selected:false
|
0
|
490 |
]
|
|
491 |
!
|
|
492 |
|
38
|
493 |
hideActiveMenuRelease:aBoolean
|
0
|
494 |
activeMenuNumber notNil ifTrue:[
|
59
|
495 |
(menus at:activeMenuNumber) unrealize.
|
|
496 |
self unHighlightActiveTitle.
|
|
497 |
aBoolean ifTrue:[device ungrabPointer. self cursor:Cursor normal].
|
|
498 |
activeMenuNumber := nil
|
0
|
499 |
]
|
|
500 |
!
|
|
501 |
|
38
|
502 |
hideActiveMenu
|
|
503 |
^ self hideActiveMenuRelease:true
|
|
504 |
!
|
|
505 |
|
0
|
506 |
pullMenu:aNumber
|
|
507 |
"activate a menu"
|
|
508 |
|
|
509 |
|subMenu|
|
|
510 |
|
38
|
511 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false].
|
0
|
512 |
subMenu := menus at:aNumber.
|
|
513 |
subMenu notNil ifTrue:[
|
59
|
514 |
activeMenuNumber := aNumber.
|
|
515 |
self highlightActiveTitle.
|
|
516 |
subMenu deselect.
|
|
517 |
subMenu create.
|
|
518 |
subMenu saveUnder:true.
|
|
519 |
subMenu raise show
|
0
|
520 |
]
|
77
|
521 |
!
|
|
522 |
|
|
523 |
regainControl
|
|
524 |
keepMenu ifTrue:[
|
|
525 |
device grabPointerInView:self.
|
|
526 |
self cursor:Cursor upRightArrow
|
|
527 |
]
|
0
|
528 |
! !
|
|
529 |
|
70
|
530 |
!PullDownMenu methodsFor:'event handling'!
|
0
|
531 |
|
|
532 |
redraw
|
|
533 |
|string
|
|
534 |
x "{ Class: SmallInteger }"
|
|
535 |
y "{ Class: SmallInteger }"
|
|
536 |
index "{ Class: SmallInteger }" |
|
|
537 |
|
|
538 |
shown ifFalse: [ ^ self ].
|
|
539 |
titles isNil ifTrue:[^ self].
|
|
540 |
x := 0.
|
|
541 |
y := height "- 1".
|
|
542 |
index := 0.
|
|
543 |
titles do:[:title |
|
59
|
544 |
string := ' ' , title , ' '.
|
|
545 |
self drawTitle:string x:x selected:(index == activeMenuNumber).
|
|
546 |
x := x + (font widthOf:string).
|
|
547 |
showSeparatingLines ifTrue:[
|
|
548 |
self is3D ifTrue:[
|
|
549 |
self paint:shadowColor.
|
|
550 |
self displayLineFromX:x y:0 toX:x y:y.
|
|
551 |
x := x + 1.
|
|
552 |
self paint:lightColor.
|
|
553 |
self displayLineFromX:x y:0 toX:x y:y
|
|
554 |
] ifFalse:[
|
|
555 |
self paint:fgColor.
|
|
556 |
self displayLineFromX:x y:0 toX:x y:y
|
|
557 |
].
|
|
558 |
x := x + 1
|
|
559 |
].
|
|
560 |
index := index + 1
|
0
|
561 |
]
|
|
562 |
!
|
|
563 |
|
|
564 |
titleIndexForX:x
|
|
565 |
"given a click x-position, return index in title or nil"
|
|
566 |
|
|
567 |
|string
|
|
568 |
xstart "{ Class: SmallInteger }"
|
|
569 |
xend "{ Class: SmallInteger }" |
|
|
570 |
|
|
571 |
xstart := 0.
|
|
572 |
1 to:(titles size) do:[:index |
|
59
|
573 |
string := ' ' , (titles at:index) , ' '.
|
|
574 |
xend := xstart + (font widthOf:string).
|
|
575 |
showSeparatingLines ifTrue:[
|
|
576 |
self is3D ifTrue:[
|
|
577 |
xend := xend + 2
|
|
578 |
] ifFalse:[
|
|
579 |
xend := xend + 1
|
|
580 |
]
|
|
581 |
].
|
|
582 |
(x between:xstart and:xend) ifTrue:[^ index].
|
|
583 |
xstart := xend
|
0
|
584 |
].
|
|
585 |
^ nil
|
|
586 |
!
|
|
587 |
|
|
588 |
buttonPress:button x:x y:y
|
38
|
589 |
|titleIndex activeMenu activeLeft activeTop|
|
|
590 |
|
|
591 |
(y between:0 and:height) ifTrue:[
|
59
|
592 |
titleIndex := self titleIndexForX:x.
|
38
|
593 |
].
|
0
|
594 |
|
38
|
595 |
"
|
|
596 |
now, titleIndex is non-nil if pressed within myself
|
|
597 |
"
|
|
598 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[
|
59
|
599 |
self pullMenu:titleIndex.
|
|
600 |
keepMenu ifTrue:[
|
77
|
601 |
device grabPointerInView:self.
|
59
|
602 |
self cursor:Cursor upRightArrow
|
|
603 |
]
|
38
|
604 |
] ifFalse:[
|
59
|
605 |
keepMenu ifTrue:[
|
|
606 |
titleIndex == activeMenuNumber ifTrue:[
|
|
607 |
"same pressed again ... stay"
|
|
608 |
^ self
|
|
609 |
].
|
|
610 |
"moving around below"
|
|
611 |
activeMenuNumber isNil ifTrue:[^self].
|
|
612 |
activeMenu := menus at:activeMenuNumber.
|
|
613 |
activeLeft := activeMenu left.
|
|
614 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
615 |
activeTop := activeMenu top.
|
|
616 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
617 |
"moving around in menu"
|
|
618 |
activeMenu buttonPress:button
|
|
619 |
x:(x - activeLeft)
|
|
620 |
y:(y - activeTop).
|
|
621 |
^ self
|
|
622 |
]
|
|
623 |
].
|
|
624 |
].
|
|
625 |
self hideActiveMenu
|
0
|
626 |
]
|
|
627 |
!
|
|
628 |
|
|
629 |
buttonMotion:button x:x y:y
|
|
630 |
|titleIndex activeMenu activeLeft activeTop|
|
|
631 |
|
|
632 |
(y < height) ifTrue:[
|
59
|
633 |
"moving around in title line"
|
|
634 |
activeMenuNumber notNil ifTrue:[
|
|
635 |
(menus at:activeMenuNumber) selection:nil
|
|
636 |
].
|
|
637 |
titleIndex := self titleIndexForX:x.
|
|
638 |
titleIndex notNil ifTrue:[
|
|
639 |
(titleIndex ~~ activeMenuNumber) ifTrue:[
|
|
640 |
self pullMenu:titleIndex
|
|
641 |
]
|
|
642 |
]
|
0
|
643 |
] ifFalse:[
|
59
|
644 |
"moving around below"
|
|
645 |
activeMenuNumber isNil ifTrue:[^self].
|
|
646 |
activeMenu := menus at:activeMenuNumber.
|
|
647 |
activeLeft := activeMenu left.
|
|
648 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
649 |
activeTop := activeMenu top.
|
|
650 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
651 |
"moving around in menu"
|
|
652 |
activeMenu buttonMotion:button
|
|
653 |
x:(x - activeLeft)
|
|
654 |
y:(y - activeTop).
|
|
655 |
^ self
|
|
656 |
]
|
|
657 |
].
|
|
658 |
"moved outside menu"
|
|
659 |
activeMenu selection:nil
|
0
|
660 |
]
|
|
661 |
!
|
|
662 |
|
|
663 |
buttonRelease:button x:x y:y
|
38
|
664 |
|activeMenu activeLeft activeTop hideMenu|
|
0
|
665 |
|
38
|
666 |
hideMenu := false.
|
0
|
667 |
(y >= height) ifTrue:[
|
59
|
668 |
"release below title-line"
|
|
669 |
activeMenuNumber isNil ifTrue:[^self].
|
|
670 |
activeMenu := menus at:activeMenuNumber.
|
|
671 |
activeLeft := activeMenu left.
|
|
672 |
"
|
|
673 |
released in a submenu ?
|
|
674 |
"
|
|
675 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[
|
|
676 |
activeTop := activeMenu top.
|
|
677 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[
|
|
678 |
"release in menu"
|
|
679 |
self hideActiveMenu.
|
|
680 |
activeMenu buttonRelease:button
|
|
681 |
x:(x - activeLeft)
|
|
682 |
y:(y - activeTop).
|
|
683 |
^ self
|
|
684 |
]
|
|
685 |
].
|
|
686 |
hideMenu := true.
|
38
|
687 |
] ifFalse:[
|
59
|
688 |
y < 0 ifTrue:[
|
|
689 |
hideMenu := true
|
|
690 |
] ifFalse:[
|
|
691 |
keepMenu ifFalse:[
|
|
692 |
hideMenu := true
|
|
693 |
]
|
|
694 |
]
|
38
|
695 |
].
|
|
696 |
hideMenu ifTrue:[
|
|
697 |
self hideActiveMenu.
|
|
698 |
]
|
0
|
699 |
! !
|