author | ca |
Thu, 07 Mar 1996 10:33:53 +0100 | |
changeset 487 | 4ee60598df58 |
parent 484 | 80c251cc9eff |
child 491 | 7b376aaa06d5 |
permissions | -rw-r--r-- |
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 |
||
119 | 13 |
SimpleView subclass:#PullDownMenu |
283 | 14 |
instanceVariableNames:'receiver menus titles selectors activeMenuNumber |
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
15 |
showSeparatingLines topMargin fgColor bgColor activeFgColor |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
16 |
activeBgColor onLevel offLevel edgeStyle keepMenu toggleKeep |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
17 |
raiseTopWhenActivated' |
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
18 |
classVariableNames:'DefaultViewBackground DefaultForegroundColor |
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
19 |
DefaultBackgroundColor DefaultHilightForegroundColor |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
20 |
DefaultHilightBackgroundColor DefaultLevel DefaultHilightLevel |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
21 |
DefaultShadowColor DefaultLightColor DefaultEdgeStyle |
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
22 |
DefaultKeepMenu DefaultToggleKeep DefaultSeparatingLines' |
283 | 23 |
poolDictionaries:'' |
24 |
category:'Views-Menus' |
|
0 | 25 |
! |
26 |
||
3 | 27 |
!PullDownMenu class methodsFor:'documentation'! |
28 |
||
38 | 29 |
copyright |
30 |
" |
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
59 | 32 |
All Rights Reserved |
38 | 33 |
|
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
3 | 43 |
documentation |
44 |
" |
|
38 | 45 |
PullDown menu provides the top (always visible) part of these menus. |
46 |
It controls display of its menus, which become visible when one of the |
|
47 |
PullDownMenus entries is pressed. |
|
0 | 48 |
|
128 | 49 |
A PullDownMenu itself consists of a single row of labels, which activate |
50 |
a pulled menu when clicked. Entries may be empty (i.e. have no menu) |
|
51 |
and empty entries may (optionally) also perform some action when clicked. |
|
52 |
An entries selector is used as the key to define and access submenus |
|
53 |
and (for empty entries:) the selector sent to the receiver of the menu. |
|
54 |
||
38 | 55 |
Instance variables: |
0 | 56 |
|
128 | 57 |
menus <Collection> the sub menus |
58 |
||
59 |
titles <Collection> the strings in the menu |
|
60 |
||
61 |
selectors <Collection> the selectors to send to the menu- |
|
62 |
receiver (for empty pull-menus) |
|
63 |
if nil (the default), title entries |
|
64 |
do not send anything. |
|
65 |
||
110 | 66 |
activeMenuNumber <Number> the index of the currently active menu |
128 | 67 |
|
110 | 68 |
showSeparatingLines <Boolean> show separating lines between my menu-strings |
128 | 69 |
|
110 | 70 |
topMargin <Number> number of pixels at top |
128 | 71 |
|
72 |
fgColor <Color> fg color to draw passive menu-titles |
|
73 |
bgColor <Color> bg color to draw passive menu-titles |
|
74 |
||
75 |
activeFgColor <Color> fg color to draw activated menu-titles |
|
76 |
activeBgColor <Color> bg color to draw activated menu-titles |
|
77 |
||
78 |
onLevel <Integer> 3D level of entry-buttons when pressed |
|
79 |
offLevel <Integer> 3D level of entry-buttons when released |
|
80 |
||
81 |
edgeStyle <Symbol> how to draw edges |
|
82 |
||
110 | 83 |
keepmenu <Boolean> if on, pulled menu stays on click, |
84 |
till clicked again (motif & windows behavior) |
|
77 | 85 |
|
128 | 86 |
toggleKeep <Boolean> if on and keepMenu is on, |
87 |
clicking again on label closes menu |
|
88 |
||
89 |
except menus, titles and selectors, instvars are usually defined from |
|
90 |
defaults in the styleSheet; you should not care for them. |
|
91 |
||
77 | 92 |
|
93 |
StyleSheet values: |
|
94 |
||
110 | 95 |
pullDownMenuViewBackground view background Color for the menu bar |
96 |
default: menuViewBackground |
|
97 |
||
98 |
pullDownMenuForegroundColor foreground drawing color for the menu bar |
|
99 |
default: menuForegroundColor |
|
100 |
||
101 |
pullDownMenuBackgroundColor background drawing color for the menu bar |
|
102 |
default: menuBackgroundColor |
|
103 |
||
104 |
pullDownMenuHilightForegroundColor active foreground drawing color for the menu bar |
|
105 |
default: menuHilightForegroundColor |
|
106 |
||
107 |
pullDownMenuHilightBackgroundColor active background drawing color for the menu bar |
|
108 |
default: menuHilightBackgroundColor |
|
109 |
||
110 |
pullDownMenuHilightLevel level (3D only) when active |
|
111 |
default: menuHilightLevel |
|
77 | 112 |
|
110 | 113 |
pullDownMenuEdgeStyle edge style (nil or #soft) |
114 |
||
115 |
pullDownMenuKeepMenu if true, pulled menu stays open until button |
|
128 | 116 |
is pressed again outside of the item-area (motif behavior) |
110 | 117 |
if false, menu closes on release (default) |
118 |
||
119 |
pullDownMenuToggleKeep if true, pulled menu closes when an entry is pressed |
|
128 | 120 |
again. Otherwise, only press outside of the items area |
121 |
hides it. default is false |
|
110 | 122 |
|
123 |
pullDownMenuLevel level (3D only) |
|
124 |
||
125 |
pullDownMenuFont font to use for the menu bar |
|
126 |
default: menuFont |
|
128 | 127 |
|
128 |
pullDownMenuShowSeparatingLines if true, lines are drawn between items. |
|
129 |
default: false |
|
133 | 130 |
|
131 |
pullDownMenuRaiseTop if true, topview is raised whenever an entry |
|
132 |
is activated. |
|
133 |
default: true |
|
110 | 134 |
" |
135 |
! |
|
77 | 136 |
|
110 | 137 |
examples |
138 |
" |
|
128 | 139 |
|top menu| |
140 |
||
141 |
top := StandardSystemView new. |
|
142 |
top extent:300@300. |
|
143 |
||
144 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
|
145 |
menu labels:#('foo' 'bar'). |
|
146 |
menu selectors:#(foo bar). |
|
147 |
menu at:#foo |
|
148 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
149 |
selectors:#(foo1 foo2 foo3) |
|
150 |
receiver:nil. |
|
151 |
menu at:#bar |
|
152 |
putLabels:#('bar1' 'bar2' 'bar3') |
|
153 |
selectors:#(bar1 bar2 bar3) |
|
154 |
receiver:nil. |
|
155 |
top open |
|
156 |
||
157 |
||
110 | 158 |
|
128 | 159 |
empty entries are possible as selectable items (with non-nil seletor) ... |
160 |
||
161 |
|top menu| |
|
162 |
||
163 |
top := StandardSystemView new. |
|
164 |
top extent:300@300. |
|
165 |
||
166 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
|
167 |
menu labels:#('foo' 'bar' 'baz'). |
|
168 |
menu selectors:#(foo bar baz). |
|
169 |
menu at:#foo |
|
170 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
171 |
selectors:#(foo1 foo2 foo3) |
|
172 |
receiver:nil. |
|
173 |
menu at:#baz |
|
174 |
putLabels:#('baz1' 'baz2' 'baz3') |
|
175 |
selectors:#(baz1 baz2 baz3) |
|
176 |
receiver:nil. |
|
177 |
top open |
|
110 | 178 |
|
179 |
||
77 | 180 |
|
128 | 181 |
... or as separators (with nil selector) |
110 | 182 |
|
128 | 183 |
|top menu| |
184 |
||
185 |
top := StandardSystemView new. |
|
186 |
top extent:500@200. |
|
110 | 187 |
|
128 | 188 |
menu := PullDownMenu origin:0.0@0.0 corner:1.0@30 in:top. |
189 |
menu labels:#('foo' ' ' 'bar' ' baz' ' ' 'moreFoo' 'moreBar' 'moreBaz'). |
|
190 |
menu selectors:#(foo nil bar baz nil moreFoo moreBar moreBaz). |
|
191 |
menu at:#foo |
|
192 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
193 |
selectors:#(foo1 foo2 foo3) |
|
194 |
receiver:nil. |
|
195 |
menu at:#bar |
|
196 |
putLabels:#('bar1' 'bar2' 'bar3') |
|
197 |
selectors:#(bar1 bar2 bar3) |
|
198 |
receiver:nil. |
|
199 |
menu at:#baz |
|
200 |
putLabels:#('baz1' 'baz2' 'baz3') |
|
201 |
selectors:#(baz1 baz2 baz3) |
|
202 |
receiver:nil. |
|
203 |
top open |
|
110 | 204 |
|
205 |
||
206 |
||
128 | 207 |
|
208 |
use the menus default height |
|
110 | 209 |
|
128 | 210 |
|top menu| |
211 |
||
212 |
top := StandardSystemView new. |
|
213 |
top extent:300@300. |
|
77 | 214 |
|
128 | 215 |
menu := PullDownMenu in:top. |
216 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
217 |
menu labels:#('foo' 'bar'). |
|
218 |
menu selectors:#(foo bar). |
|
219 |
menu at:#foo |
|
220 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
221 |
selectors:#(foo1 foo2 foo3) |
|
222 |
receiver:nil. |
|
223 |
top open |
|
110 | 224 |
|
77 | 225 |
|
110 | 226 |
|
227 |
||
128 | 228 |
although you can change the font, colors etc (as shown below) |
229 |
you should NOT do it - since if you do so, the styleSheet settings |
|
230 |
are ineffective (which users wont like probably) |
|
231 |
BTW: The styleSheet entries for below are pullDownMenuForegroundColor, |
|
232 |
pullDownMenuBackgroundColor and pullDownMenuFont |
|
110 | 233 |
|
128 | 234 |
|top menu| |
77 | 235 |
|
128 | 236 |
top := StandardSystemView new. |
237 |
menu := PullDownMenu in:top. |
|
238 |
menu font:(Font family:'courier' size:20). |
|
239 |
menu foregroundColor:Color red. |
|
240 |
menu backgroundColor:Color yellow. |
|
241 |
menu viewBackground:Color yellow. |
|
242 |
menu showSeparatingLines:true. |
|
110 | 243 |
|
128 | 244 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
245 |
menu labels:#('foo' 'bar'). |
|
246 |
menu selectors:#(foo bar). |
|
247 |
menu at:#foo |
|
248 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
249 |
selectors:#(foo1 foo2 foo3) |
|
250 |
receiver:nil. |
|
251 |
(menu menuAt:#foo) font:(Font family:'courier' size:36). |
|
252 |
top open |
|
110 | 253 |
|
254 |
||
77 | 255 |
|
128 | 256 |
you can use icons, too ... |
110 | 257 |
|
128 | 258 |
|labels top menu| |
259 |
||
260 |
top := StandardSystemView new. |
|
261 |
top extent:300@300. |
|
110 | 262 |
|
128 | 263 |
menu := PullDownMenu in:top. |
264 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
265 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16) |
|
266 |
with:'foo' |
|
267 |
with:'bar'. |
|
268 |
menu labels:labels. |
|
269 |
menu selectors:#(about foo bar). |
|
270 |
menu at:#about |
|
271 |
putLabels:#('about PullDownMenus') |
|
272 |
selectors:#(aboutMenus) |
|
273 |
receiver:nil. |
|
274 |
menu at:#foo |
|
275 |
putLabels:#('foo1' 'foo2' 'foo3') |
|
276 |
selectors:#(foo1 foo2 foo3) |
|
277 |
receiver:nil. |
|
278 |
top open |
|
110 | 279 |
|
280 |
||
281 |
||
128 | 282 |
a concrete example (combining things described above) |
283 |
(using a Plug, since we have no application class here): |
|
284 |
||
285 |
|labels top menu textView appModel| |
|
110 | 286 |
|
128 | 287 |
appModel := Plug new. |
288 |
appModel respondTo:#quit with:[top destroy]. |
|
289 |
appModel respondTo:#showAbout with:[self information:'some info here ...']. |
|
290 |
appModel respondTo:#help with:[self information:'some help here ...']. |
|
291 |
||
292 |
top := StandardSystemView new. |
|
293 |
top extent:300@300. |
|
294 |
||
295 |
menu := PullDownMenu in:top. |
|
296 |
menu receiver:appModel. |
|
297 |
menu origin:0.0@0.0 corner:1.0@(menu height). |
|
77 | 298 |
|
128 | 299 |
textView := ScrollableView forView:(EditTextView new). |
300 |
textView origin:0.0@menu height corner:1.0@1.0. |
|
301 |
top addSubView:textView. |
|
302 |
||
303 |
labels := Array with:((Image fromFile:'SmalltalkX.xbm') magnifiedTo:16@16) |
|
304 |
with:'file' |
|
305 |
with:'edit' |
|
306 |
with:'help'. |
|
307 |
menu labels:labels. |
|
308 |
menu selectors:#(about file edit help). |
|
309 |
menu at:#about |
|
310 |
putLabels:#('about PullDownMenus') |
|
311 |
selectors:#(showAbout) |
|
312 |
receiver:appModel. |
|
313 |
menu at:#file |
|
314 |
putLabels:#('quit') |
|
315 |
selectors:#(quit) |
|
316 |
receiver:appModel. |
|
317 |
menu at:#edit |
|
318 |
putLabels:#('copy' 'cut' 'paste') |
|
319 |
selectors:#(copySelection cut paste) |
|
320 |
receiver:textView. |
|
321 |
top open |
|
3 | 322 |
" |
202 | 323 |
! ! |
324 |
||
325 |
!PullDownMenu class methodsFor:'instance creation'! |
|
326 |
||
327 |
labels:titleArray |
|
328 |
"create and return a new PullDownMenu" |
|
329 |
||
330 |
^ self new labels:titleArray |
|
3 | 331 |
! ! |
0 | 332 |
|
59 | 333 |
!PullDownMenu class methodsFor:'defaults'! |
334 |
||
335 |
updateStyleCache |
|
110 | 336 |
"extract values from the styleSheet and cache them in class variables" |
337 |
||
456 | 338 |
<resource: #style (#pullDownMenuViewBackground #menuViewBackground |
339 |
#pullDownMenuForegroundColor #menuForegroundColor |
|
340 |
#pullDownMenuBackgroundColor #menuBackgroundColor |
|
341 |
#pullDownMenuHilightForegroundColor #menuHilightForegroundColor |
|
342 |
#pullDownMenuHilightBackgroundColor #menuHilightBackgroundColor |
|
343 |
#pullDownMenuHilightLevel #menuHilightLevel |
|
344 |
#pullDownMenuEdgeStyle #pullDownMenuKeepMenu |
|
345 |
#pullDownMenuToggleKeep #pullDownMenuLevel |
|
346 |
#pullDownMenuFont #menuFont |
|
347 |
#pullDownMenuSeparatingLines)> |
|
348 |
||
133 | 349 |
|styleSheet| |
350 |
||
351 |
styleSheet := StyleSheet. |
|
352 |
||
353 |
DefaultViewBackground := styleSheet colorAt:'pullDownMenuViewBackground'. |
|
60 | 354 |
DefaultViewBackground isNil ifTrue:[ |
456 | 355 |
DefaultViewBackground := styleSheet colorAt:'menuViewBackground'. |
59 | 356 |
]. |
133 | 357 |
DefaultForegroundColor := styleSheet colorAt:'pullDownMenuForegroundColor'. |
60 | 358 |
DefaultForegroundColor isNil ifTrue:[ |
456 | 359 |
DefaultForegroundColor := styleSheet colorAt:'menuForegroundColor'. |
60 | 360 |
]. |
133 | 361 |
DefaultBackgroundColor := styleSheet colorAt:'pullDownMenuBackgroundColor'. |
60 | 362 |
DefaultBackgroundColor isNil ifTrue:[ |
456 | 363 |
DefaultViewBackground notNil ifTrue:[ |
364 |
DefaultBackgroundColor := DefaultViewBackground |
|
365 |
] ifFalse:[ |
|
366 |
DefaultBackgroundColor := styleSheet colorAt:'menuBackgroundColor'. |
|
367 |
] |
|
59 | 368 |
]. |
133 | 369 |
DefaultHilightForegroundColor := styleSheet colorAt:'pullDownMenuHilightForegroundColor'. |
60 | 370 |
DefaultHilightForegroundColor isNil ifTrue:[ |
456 | 371 |
DefaultHilightForegroundColor := styleSheet colorAt:'menuHilightForegroundColor'. |
59 | 372 |
]. |
133 | 373 |
DefaultHilightBackgroundColor := styleSheet colorAt:'pullDownMenuHilightBackgroundColor'. |
60 | 374 |
DefaultHilightBackgroundColor isNil ifTrue:[ |
456 | 375 |
DefaultHilightBackgroundColor := styleSheet colorAt:'menuHilightBackgroundColor'. |
59 | 376 |
]. |
133 | 377 |
DefaultHilightLevel := styleSheet at:'pullDownMenuHilightLevel'. |
60 | 378 |
DefaultHilightLevel isNil ifTrue:[ |
456 | 379 |
DefaultHilightLevel := styleSheet at:'menuHilightLevel' default:0. |
59 | 380 |
]. |
133 | 381 |
DefaultEdgeStyle := styleSheet at:'pullDownMenuEdgeStyle'. |
382 |
DefaultKeepMenu := styleSheet at:'pullDownMenuKeepMenu' default:false. |
|
383 |
DefaultToggleKeep := styleSheet at:'pullDownMenuToggleKeep' default:false. |
|
384 |
DefaultLevel := styleSheet at:'pullDownMenuLevel' default:1. |
|
385 |
DefaultFont := styleSheet fontAt:'pullDownMenuFont'. |
|
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
386 |
DefaultFont isNil ifTrue:[DefaultFont := styleSheet fontAt:'menuFont']. |
133 | 387 |
DefaultSeparatingLines := styleSheet at:'pullDownMenuSeparatingLines' default:false. |
110 | 388 |
|
389 |
" |
|
390 |
PullDownMenu updateStyleCache |
|
391 |
" |
|
456 | 392 |
|
393 |
"Modified: 1.3.1996 / 13:45:19 / cg" |
|
59 | 394 |
! ! |
395 |
||
202 | 396 |
!PullDownMenu methodsFor:'accessing'! |
397 |
||
283 | 398 |
add:label selector:selector |
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
399 |
"add a new title-item at the end. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
400 |
The corresponding label can later be set with #at:putMenu: |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
401 |
or #at:putLabels:selectors:..." |
283 | 402 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
403 |
self add:label selector:selector after:nil |
283 | 404 |
! |
405 |
||
406 |
add:label selector:selector after:indexOrString |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
407 |
"add a new title-item after an existing item, indexOrString, |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
408 |
or at the end if the after-arg is nil. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
409 |
The corresponding label can later be set with #at:putMenu: |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
410 |
or #at:putLabels:selectors:..." |
283 | 411 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
412 |
|idx| |
283 | 413 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
414 |
indexOrString isNil ifTrue:[ |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
415 |
idx := titles size |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
416 |
] ifFalse:[ |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
417 |
idx := self indexOf:indexOrString. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
418 |
]. |
283 | 419 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
420 |
titles isNil ifTrue:[ |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
421 |
menus := Array with:nil. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
422 |
titles := Array with:label. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
423 |
selectors := Array with:nil. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
424 |
] ifFalse:[ |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
425 |
menus := (menus copyTo:idx) , #(nil) , (menus copyFrom:idx+1). |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
426 |
titles := ((titles copyTo:idx) copyWith:label) , (titles copyFrom:idx+1). |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
427 |
selectors := ((selectors copyTo:idx) copyWith:selector) , (selectors copyFrom:idx+1). |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
428 |
]. |
283 | 429 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
430 |
" |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
431 |
|top m| |
283 | 432 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
433 |
top := StandardSystemView new. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
434 |
m := PullDownMenu in:top. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
435 |
m labels:#('file' 'edit'). |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
436 |
m selectors:#(file #edit). |
283 | 437 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
438 |
m add:'help' selector:#help after:#file. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
439 |
m at:#help putMenu:(MenuView labels:#('foo' 'bar') |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
440 |
selectors:#(foo bar) |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
441 |
receiver:nil). |
283 | 442 |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
443 |
top open |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
444 |
" |
283 | 445 |
! |
446 |
||
202 | 447 |
at:aString putLabels:labels selector:selector args:args receiver:anObject |
448 |
"create and set the menu under the title, aString" |
|
449 |
||
450 |
|menuView| |
|
451 |
||
452 |
menuView := MenuView labels:labels |
|
453 |
selector:selector |
|
454 |
args:args |
|
455 |
receiver:anObject |
|
456 |
for:self. |
|
457 |
self at:aString putMenu:menuView |
|
458 |
! |
|
459 |
||
460 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject |
|
461 |
"create and set the menu under the title, aString" |
|
462 |
||
463 |
|menuView| |
|
464 |
||
465 |
menuView := MenuView labels:labels |
|
466 |
selectors:selectors |
|
467 |
args:args |
|
468 |
receiver:anObject |
|
469 |
for:self. |
|
470 |
self at:aString putMenu:menuView |
|
471 |
! |
|
472 |
||
473 |
at:aString putLabels:labels selectors:selectors receiver:anObject |
|
474 |
"create and set the menu under the title, aString" |
|
475 |
||
476 |
|menuView| |
|
477 |
||
478 |
menuView := MenuView labels:labels |
|
479 |
selectors:selectors |
|
480 |
receiver:anObject |
|
481 |
for:self. |
|
482 |
self at:aString putMenu:menuView |
|
483 |
! |
|
484 |
||
485 |
at:aString putMenu:aMenu |
|
486 |
"set the menu under the title, aString" |
|
487 |
||
488 |
|index| |
|
489 |
||
490 |
index := self indexOf:aString. |
|
491 |
(index == 0) ifTrue:[ |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
492 |
self error:'no such menu entry'. |
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
493 |
^ nil |
202 | 494 |
]. |
495 |
||
496 |
"/ not needed: |
|
497 |
"/ aMenu origin:((left + (self titleLenUpTo:index)) |
|
498 |
"/ @ |
|
499 |
"/ (height + aMenu borderWidth)). |
|
283 | 500 |
aMenu superView:(self superView). |
291 | 501 |
aMenu beInvisible. |
202 | 502 |
menus at:index put:aMenu. |
503 |
aMenu masterView:self. |
|
504 |
! |
|
505 |
||
506 |
labels |
|
507 |
"return the menu-titles (group-headers)" |
|
508 |
||
509 |
^ titles |
|
510 |
! |
|
0 | 511 |
|
512 |
labels:titleArray |
|
202 | 513 |
"define the menu-titles (group-headers)" |
514 |
||
515 |
|numberOfLabels| |
|
516 |
||
517 |
numberOfLabels := titleArray size. |
|
518 |
menus := Array new:numberOfLabels. |
|
519 |
titles := Array new:numberOfLabels. |
|
520 |
||
521 |
titleArray keysAndValuesDo:[:index :entry | |
|
522 |
|e| |
|
523 |
||
524 |
entry isImage ifTrue:[ |
|
525 |
e := entry on:device |
|
526 |
] ifFalse:[ |
|
527 |
e := entry printString |
|
528 |
]. |
|
529 |
titles at:index put:e |
|
530 |
]. |
|
531 |
shown ifTrue:[ |
|
532 |
self clear. |
|
533 |
self redraw |
|
534 |
] |
|
535 |
! |
|
536 |
||
537 |
labels:titleArray selectors:selectorArray |
|
538 |
"define the menu-titles (group-headers) and selectors. |
|
539 |
Selectors are mostly used as access keys to get to submenus later." |
|
540 |
||
541 |
self labels:titleArray. |
|
542 |
self selectors:selectorArray |
|
543 |
||
544 |
"Created: 20.10.1995 / 20:15:54 / cg" |
|
545 |
! |
|
546 |
||
547 |
menuAt:stringOrNumber |
|
548 |
"return the menu with the title; return nil if not found" |
|
549 |
||
550 |
|index| |
|
551 |
||
552 |
index := self indexOf:stringOrNumber. |
|
553 |
(index == 0) ifTrue:[^ nil]. |
|
554 |
^ menus at:index |
|
555 |
! |
|
556 |
||
557 |
numberOfTitles:n |
|
558 |
"setup blank title-space to be filled in later" |
|
559 |
||
560 |
menus := Array new:n. |
|
561 |
titles := Array new:n |
|
562 |
! |
|
563 |
||
564 |
receiver:anObject |
|
565 |
"set the menu-receiver. Thats the one who gets the |
|
566 |
messages (both from myself and from my submenus). |
|
567 |
This only sets the receiver for menus which are already |
|
568 |
created - menus added later should get their receiver in |
|
569 |
the creation send." |
|
570 |
||
571 |
receiver := anObject. |
|
572 |
menus notNil ifTrue:[ |
|
573 |
menus do:[:aMenu | |
|
574 |
aMenu notNil ifTrue:[ |
|
575 |
aMenu receiver:anObject |
|
576 |
] |
|
577 |
] |
|
578 |
] |
|
579 |
! |
|
580 |
||
283 | 581 |
selectors |
582 |
"return the menu-selectors" |
|
583 |
||
584 |
^ selectors |
|
585 |
! |
|
586 |
||
202 | 587 |
selectors:selectorArray |
588 |
"define the menu-selectors. These are used as accesskey only |
|
589 |
in menuAt: accesses. This makes PullDownMenu accesss |
|
590 |
somewhat more compatible to PopUpMenus." |
|
591 |
||
592 |
selectors := selectorArray. |
|
283 | 593 |
|
202 | 594 |
! ! |
595 |
||
596 |
!PullDownMenu methodsFor:'accessing-look'! |
|
597 |
||
598 |
backgroundColor:aColor |
|
599 |
"set the background drawing color. |
|
600 |
You should not use this method; instead leave the value as |
|
601 |
defined in the styleSheet." |
|
602 |
||
603 |
bgColor := aColor on:device |
|
604 |
! |
|
605 |
||
606 |
font:aFont |
|
607 |
"set the menus font. |
|
608 |
adjusts menu-origins when font changes. |
|
609 |
You should not use this method; instead leave the value as |
|
610 |
defined in the styleSheet." |
|
611 |
||
612 |
aFont ~~ font ifTrue:[ |
|
613 |
super font:(aFont on:device). |
|
614 |
self height:(font height + (font descent * 2)). |
|
615 |
shown ifTrue:[ |
|
616 |
self setMenuOrigins |
|
617 |
] |
|
618 |
] |
|
619 |
! |
|
620 |
||
621 |
foregroundColor:aColor |
|
622 |
"set the foreground drawing color. |
|
623 |
You should not use this method; instead leave the value as |
|
624 |
defined in the styleSheet." |
|
625 |
||
626 |
fgColor := aColor on:device |
|
627 |
! |
|
628 |
||
629 |
showSeparatingLines:aBoolean |
|
630 |
"turn on/off drawing of separating lines. |
|
631 |
You should not use this method; instead leave the value as |
|
632 |
defined in the styleSheet." |
|
633 |
||
634 |
showSeparatingLines := aBoolean. |
|
635 |
shown ifTrue:[ |
|
636 |
self setMenuOrigins. |
|
637 |
self redraw |
|
638 |
] |
|
639 |
! ! |
|
640 |
||
641 |
!PullDownMenu methodsFor:'drawing '! |
|
642 |
||
643 |
drawActiveTitleSelected:selected |
|
644 |
|x| |
|
645 |
activeMenuNumber notNil ifTrue:[ |
|
646 |
x := self titleLenUpTo:activeMenuNumber. |
|
647 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:selected |
|
648 |
] |
|
649 |
! |
|
650 |
||
651 |
drawTitle:stringOrImage x:x0 selected:selected |
|
652 |
|y w x wSpace fg bg map| |
|
653 |
||
654 |
selected ifTrue:[ |
|
655 |
fg := activeFgColor. |
|
656 |
bg := activeBgColor |
|
657 |
] ifFalse:[ |
|
658 |
fg := fgColor. |
|
659 |
bg := bgColor |
|
660 |
]. |
|
661 |
||
662 |
wSpace := font widthOf:' '. |
|
663 |
x := x0. |
|
664 |
stringOrImage isString ifTrue:[ |
|
665 |
y := ((height - (font height)) // 2) + (font ascent) "+ topMargin". |
|
666 |
w := font widthOf:stringOrImage. |
|
667 |
] ifFalse:[ |
|
668 |
y := ((height - stringOrImage height) // 2) max:0. |
|
669 |
w := stringOrImage width |
|
670 |
]. |
|
671 |
w := w + (wSpace * 2). |
|
672 |
||
673 |
self paint:bg. |
|
674 |
self fillRectangleX:x y:0 width:w height:height. |
|
675 |
||
676 |
self is3D ifTrue:[ |
|
677 |
self drawEdgesForX:x y:0 |
|
678 |
width:w |
|
679 |
height:height |
|
680 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) |
|
681 |
]. |
|
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
682 |
self paint:fg on:bg. |
202 | 683 |
x := x + wSpace. |
684 |
stringOrImage isString ifTrue:[ |
|
250
77012e65ac84
draw strings as opaque strings - OS/2 server has a bug with non-image strings
Claus Gittinger <cg@exept.de>
parents:
205
diff
changeset
|
685 |
self displayOpaqueString:stringOrImage x:x y:y |
202 | 686 |
] ifFalse:[ |
687 |
stringOrImage isImageOrForm ifTrue:[ |
|
688 |
stringOrImage depth == 1 ifTrue:[ |
|
689 |
(map := stringOrImage colorMap) notNil ifTrue:[ |
|
690 |
self paint:(map at:2) on:(map at:1). |
|
691 |
self displayOpaqueForm:stringOrImage x:x y:y. |
|
692 |
^ self |
|
693 |
] |
|
694 |
]. |
|
695 |
self displayForm:stringOrImage x:x y:y |
|
696 |
] ifFalse:[ |
|
697 |
stringOrImage displayOn:self x:x y:y |
|
698 |
] |
|
699 |
] |
|
700 |
||
701 |
"Modified: 20.10.1995 / 22:03:27 / cg" |
|
702 |
! |
|
703 |
||
704 |
highlightActiveTitle |
|
705 |
self drawActiveTitleSelected:true |
|
706 |
! |
|
707 |
||
708 |
redraw |
|
709 |
|x "{ Class: SmallInteger }" |
|
710 |
y "{ Class: SmallInteger }" |
|
711 |
index "{ Class: SmallInteger }" |
|
712 |
wSpace clr| |
|
713 |
||
714 |
shown ifFalse: [ ^ self ]. |
|
715 |
titles isNil ifTrue:[^ self]. |
|
716 |
||
717 |
wSpace := (font widthOf:' '). |
|
718 |
x := 0. |
|
719 |
y := height "- 1". |
|
720 |
index := 1. |
|
721 |
titles do:[:title | |
|
722 |
self drawTitle:title x:x selected:(index == activeMenuNumber). |
|
723 |
||
724 |
title isString ifTrue:[ |
|
725 |
x := x + (font widthOf:title). |
|
726 |
] ifFalse:[ |
|
727 |
x := x + title width |
|
728 |
]. |
|
729 |
x := x + wSpace + wSpace. |
|
730 |
showSeparatingLines ifTrue:[ |
|
731 |
self is3D ifTrue:[ |
|
732 |
self paint:shadowColor. |
|
733 |
self displayLineFromX:x y:0 toX:x y:y. |
|
734 |
x := x + 1. |
|
735 |
clr := lightColor. |
|
736 |
] ifFalse:[ |
|
737 |
clr := fgColor. |
|
738 |
]. |
|
739 |
self paint:clr. |
|
740 |
self displayLineFromX:x y:0 toX:x y:y. |
|
741 |
x := x + 1 |
|
742 |
]. |
|
743 |
index := index + 1 |
|
744 |
] |
|
745 |
! |
|
746 |
||
747 |
unHighlightActiveTitle |
|
748 |
self drawActiveTitleSelected:false |
|
749 |
! ! |
|
750 |
||
751 |
!PullDownMenu methodsFor:'event handling'! |
|
752 |
||
753 |
buttonMotion:state x:x y:y |
|
754 |
|titleIndex activeMenu activeLeft activeTop| |
|
755 |
||
756 |
state == 0 ifTrue:[^ self]. |
|
757 |
||
758 |
activeMenuNumber notNil ifTrue:[ |
|
759 |
activeMenu := menus at:activeMenuNumber. |
|
760 |
]. |
|
0 | 761 |
|
202 | 762 |
(y < height) ifTrue:[ |
763 |
"moving around in title line" |
|
764 |
activeMenu notNil ifTrue:[ |
|
765 |
activeMenu selection:nil |
|
766 |
]. |
|
767 |
titleIndex := self titleIndexForX:x. |
|
768 |
titleIndex notNil ifTrue:[ |
|
769 |
(titleIndex ~~ activeMenuNumber) ifTrue:[ |
|
770 |
self pullMenu:titleIndex |
|
771 |
] |
|
772 |
] ifFalse:[ |
|
773 |
self hideActiveMenu |
|
774 |
] |
|
775 |
] ifFalse:[ |
|
776 |
"moving around below" |
|
777 |
activeMenu isNil ifTrue:[^self]. |
|
778 |
activeLeft := activeMenu left. |
|
779 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
780 |
activeTop := activeMenu top. |
|
781 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
782 |
"moving around in menu" |
|
783 |
activeMenu buttonMotion:state |
|
784 |
x:(x - activeLeft) |
|
785 |
y:(y - activeTop). |
|
786 |
^ self |
|
787 |
] |
|
788 |
]. |
|
789 |
"moved outside menu" |
|
790 |
activeMenu selection:nil |
|
791 |
] |
|
792 |
! |
|
793 |
||
794 |
buttonPress:button x:x y:y |
|
795 |
|titleIndex activeMenu activeLeft activeTop m| |
|
796 |
||
797 |
device ungrabPointer. |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
798 |
device ungrabKeyboard. |
202 | 799 |
|
800 |
(y between:0 and:height) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
801 |
titleIndex := self titleIndexForX:x. |
202 | 802 |
]. |
803 |
||
804 |
" |
|
805 |
now, titleIndex is non-nil if pressed within myself |
|
806 |
" |
|
807 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
808 |
m := self pullMenu:titleIndex. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
809 |
(keepMenu and:[m notNil]) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
810 |
device grabPointerInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
811 |
device grabKeyboardInView:self. |
484 | 812 |
"/ self cursor:Cursor upRightArrow |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
813 |
] |
202 | 814 |
] ifFalse:[ |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
815 |
(keepMenu and:[toggleKeep not]) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
816 |
titleIndex == activeMenuNumber ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
817 |
"same pressed again ... stay" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
818 |
titleIndex notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
819 |
device grabPointerInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
820 |
device grabKeyboardInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
821 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
822 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
823 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
824 |
"moving around below" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
825 |
activeMenuNumber isNil ifTrue:[^self]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
826 |
activeMenu := menus at:activeMenuNumber. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
827 |
activeLeft := activeMenu left. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
828 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
829 |
activeTop := activeMenu top. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
830 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
831 |
"moving around in menu" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
832 |
activeMenu buttonPress:button |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
833 |
x:(x - activeLeft) |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
834 |
y:(y - activeTop). |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
835 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
836 |
] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
837 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
838 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
839 |
self hideActiveMenu |
202 | 840 |
] |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
841 |
|
484 | 842 |
"Modified: 6.3.1996 / 17:14:16 / cg" |
202 | 843 |
! |
844 |
||
845 |
buttonRelease:button x:x y:y |
|
846 |
|activeMenu activeLeft activeTop hideMenu sel| |
|
847 |
||
848 |
activeMenuNumber isNil ifTrue:[^self]. |
|
849 |
activeMenu := menus at:activeMenuNumber. |
|
850 |
||
851 |
hideMenu := false. |
|
852 |
(y >= height) ifTrue:[ |
|
853 |
"release below title-line" |
|
854 |
activeLeft := activeMenu left. |
|
855 |
" |
|
856 |
released in a submenu ? |
|
857 |
" |
|
858 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
859 |
activeTop := activeMenu top. |
|
860 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
861 |
"release in menu" |
|
862 |
self hideActiveMenu. |
|
863 |
activeMenu buttonRelease:button |
|
864 |
x:(x - activeLeft) |
|
865 |
y:(y - activeTop). |
|
866 |
^ self |
|
867 |
] |
|
868 |
]. |
|
869 |
hideMenu := true. |
|
870 |
] ifFalse:[ |
|
871 |
y < 0 ifTrue:[ |
|
872 |
hideMenu := true |
|
873 |
] ifFalse:[ |
|
874 |
activeMenu isNil ifTrue:[ |
|
875 |
selectors notNil ifTrue:[ |
|
876 |
sel := selectors at:activeMenuNumber. |
|
877 |
sel notNil ifTrue:[ |
|
878 |
receiver perform:sel |
|
879 |
]. |
|
880 |
]. |
|
881 |
hideMenu := true. |
|
882 |
] ifFalse:[ |
|
883 |
keepMenu ifFalse:[ |
|
884 |
hideMenu := true |
|
885 |
] |
|
886 |
] |
|
887 |
] |
|
888 |
]. |
|
889 |
hideMenu ifTrue:[ |
|
890 |
self hideActiveMenu. |
|
891 |
] |
|
892 |
! |
|
893 |
||
894 |
keyPress:key x:x y:y |
|
895 |
<resource: #keyboard (#CursorLeft #CursorRight #MenuSelect)> |
|
896 |
||
897 |
|index m sel| |
|
898 |
||
899 |
" |
|
900 |
handle CursorLeft/Right for non-mouse operation |
|
901 |
(for example, if it has the explicit focus) |
|
902 |
These will pull the previous/next menu |
|
903 |
" |
|
904 |
((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
905 |
activeMenuNumber isNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
906 |
index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
907 |
] ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
908 |
(key == #CursorRight) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
909 |
index := activeMenuNumber+1 |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
910 |
] ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
911 |
index := activeMenuNumber-1 |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
912 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
913 |
index == 0 ifTrue:[index := menus size] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
914 |
ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
915 |
index > menus size ifTrue:[index := 1] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
916 |
] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
917 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
918 |
self pullMenu:index. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
919 |
^ self |
202 | 920 |
]. |
921 |
||
487 | 922 |
activeMenuNumber isNil ifTrue:[^ super keyPress:key x:x y:y]. |
202 | 923 |
|
924 |
" |
|
925 |
Return, space or the (virtual) MenuSelect key trigger |
|
926 |
a menu entry (for non-submenu entries). |
|
927 |
Otherwise, if we have a submenu open, |
|
928 |
pass the key on to it ... |
|
929 |
" |
|
930 |
m := menus at:activeMenuNumber. |
|
931 |
m isNil ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
932 |
(key == #Return |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
933 |
or:[key == #MenuSelect |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
934 |
or:[key == Character space]]) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
935 |
sel := selectors at:activeMenuNumber. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
936 |
sel notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
937 |
receiver perform:sel |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
938 |
] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
939 |
]. |
202 | 940 |
] ifFalse:[ |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
941 |
m keyPress:key x:0 y:0. |
202 | 942 |
]. |
943 |
! |
|
944 |
||
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
945 |
showNoFocus:explicit |
202 | 946 |
"when stepping focus, hide any active menu" |
947 |
||
948 |
self hideActiveMenu. |
|
309
b5c9d68e95e1
new tabbing scheme (asking via #canTab); new focus change (passing explicit to showFocus/noFocus);
Claus Gittinger <cg@exept.de>
parents:
291
diff
changeset
|
949 |
super showNoFocus:explicit |
202 | 950 |
! ! |
951 |
||
952 |
!PullDownMenu methodsFor:'hiding/showing menus'! |
|
953 |
||
317
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
954 |
hide |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
955 |
"sent by an aborted menu" |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
956 |
|
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
957 |
self hideActiveMenu. |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
958 |
! |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
959 |
|
202 | 960 |
hideActiveMenu |
961 |
"hide currently active menu - release grab if there is any grab (keepMenu)" |
|
962 |
||
963 |
^ self hideActiveMenuRelease:true |
|
964 |
! |
|
965 |
||
966 |
hideActiveMenuRelease:aBoolean |
|
967 |
"hide currently active menu - release grab if aBoolean is true |
|
968 |
and a grab was set (keepMenu)" |
|
969 |
||
970 |
|m| |
|
971 |
||
972 |
activeMenuNumber notNil ifTrue:[ |
|
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
973 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
974 |
m beInvisible. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
975 |
]. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
976 |
self unHighlightActiveTitle. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
977 |
activeMenuNumber := nil |
202 | 978 |
]. |
979 |
aBoolean ifTrue:[ |
|
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
980 |
device ungrabKeyboard. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
981 |
device ungrabPointer. |
484 | 982 |
"/ self cursor:Cursor normal |
202 | 983 |
]. |
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
984 |
|
484 | 985 |
"Modified: 6.3.1996 / 17:14:21 / cg" |
202 | 986 |
! |
987 |
||
988 |
pullMenu:aNumber |
|
989 |
"activate a menu, return it or nil" |
|
990 |
||
991 |
|subMenu r posY| |
|
992 |
||
993 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false]. |
|
994 |
activeMenuNumber := aNumber. |
|
995 |
subMenu := menus at:aNumber. |
|
996 |
||
997 |
raiseTopWhenActivated ifTrue:[ |
|
998 |
self topView raise. |
|
999 |
]. |
|
1000 |
||
1001 |
(activeMenuNumber notNil |
|
1002 |
and:[ |
|
1003 |
subMenu notNil |
|
1004 |
or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[ |
|
1005 |
self highlightActiveTitle. |
|
1006 |
]. |
|
1007 |
||
1008 |
subMenu notNil ifTrue:[ |
|
1009 |
subMenu origin:((left + (self titleLenUpTo:aNumber)) |
|
1010 |
@ |
|
1011 |
(posY := height + subMenu borderWidth)). |
|
1012 |
subMenu hiddenOnRealize:false. |
|
1013 |
subMenu deselect. |
|
1014 |
subMenu create. |
|
1015 |
subMenu saveUnder:true. |
|
1016 |
subMenu superMenu:self. |
|
1017 |
||
1018 |
subMenu right > (r := self right) ifTrue:[ |
|
1019 |
subMenu origin:((r - subMenu width) @ posY). |
|
1020 |
]. |
|
1021 |
subMenu raise show. |
|
1022 |
]. |
|
1023 |
^ subMenu |
|
1024 |
! |
|
1025 |
||
1026 |
regainControl |
|
1027 |
keepMenu ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1028 |
device grabPointerInView:self. |
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1029 |
device grabKeyboardInView:self. |
484 | 1030 |
"/ self cursor:Cursor upRightArrow |
202 | 1031 |
] |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1032 |
|
484 | 1033 |
"Modified: 6.3.1996 / 17:14:27 / cg" |
0 | 1034 |
! ! |
1035 |
||
77 | 1036 |
!PullDownMenu methodsFor:'initialize / release'! |
0 | 1037 |
|
202 | 1038 |
create |
1039 |
super create. |
|
1040 |
self setMenuOrigins |
|
1041 |
! |
|
1042 |
||
1043 |
destroy |
|
1044 |
"have to destroy the menus manually here, |
|
1045 |
since they are no real subviews of myself" |
|
0 | 1046 |
|
202 | 1047 |
menus notNil ifTrue:[ |
1048 |
menus do:[:m | |
|
1049 |
m notNil ifTrue:[m destroy] |
|
1050 |
]. |
|
1051 |
menus := nil |
|
1052 |
]. |
|
1053 |
activeMenuNumber := nil. |
|
1054 |
super destroy. |
|
1055 |
! |
|
1056 |
||
1057 |
initCursor |
|
1058 |
"set up a hand cursor" |
|
1059 |
||
1060 |
cursor := Cursor hand |
|
0 | 1061 |
! |
1062 |
||
1063 |
initStyle |
|
130 | 1064 |
|style| |
1065 |
||
0 | 1066 |
super initStyle. |
1067 |
||
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1068 |
"/ DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1069 |
|
128 | 1070 |
showSeparatingLines := DefaultSeparatingLines. "/ false. |
59 | 1071 |
DefaultViewBackground notNil ifTrue:[ |
60 | 1072 |
viewBackground := DefaultViewBackground on:device |
59 | 1073 |
]. |
1074 |
||
1075 |
DefaultForegroundColor notNil ifTrue:[ |
|
1076 |
fgColor := DefaultForegroundColor |
|
1077 |
] ifFalse:[ |
|
1078 |
fgColor := Black. |
|
1079 |
]. |
|
1080 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1081 |
bgColor := DefaultBackgroundColor |
|
1082 |
] ifFalse:[ |
|
1083 |
bgColor := viewBackground. |
|
1084 |
]. |
|
1085 |
onLevel := DefaultHilightLevel. |
|
1086 |
offLevel := DefaultLevel. |
|
21 | 1087 |
|
0 | 1088 |
self is3D ifTrue:[ |
59 | 1089 |
device hasColors ifTrue:[ |
1090 |
activeFgColor := Color name:'yellow' |
|
1091 |
] ifFalse:[ |
|
1092 |
activeFgColor := White |
|
1093 |
]. |
|
1094 |
device hasGreyscales ifTrue:[ |
|
1095 |
activeBgColor := bgColor. |
|
1096 |
] ifFalse:[ |
|
1097 |
activeBgColor := fgColor. |
|
1098 |
]. |
|
1099 |
topMargin := 2. |
|
21 | 1100 |
|
130 | 1101 |
style := styleSheet name. |
1102 |
((style == #iris) or:[style == #motif]) ifTrue:[ |
|
59 | 1103 |
self level:2. |
1104 |
onLevel := 2. |
|
1105 |
offLevel := 0. |
|
1106 |
activeFgColor := fgColor |
|
1107 |
] |
|
0 | 1108 |
] ifFalse:[ |
59 | 1109 |
activeFgColor := bgColor. |
1110 |
activeBgColor := fgColor. |
|
1111 |
topMargin := 0 |
|
1112 |
]. |
|
1113 |
||
63 | 1114 |
edgeStyle := DefaultEdgeStyle. |
1115 |
keepMenu := DefaultKeepMenu. |
|
110 | 1116 |
toggleKeep := DefaultToggleKeep. |
63 | 1117 |
|
59 | 1118 |
DefaultHilightForegroundColor notNil ifTrue:[ |
1119 |
activeFgColor := DefaultHilightForegroundColor |
|
1120 |
]. |
|
1121 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
1122 |
activeBgColor := DefaultHilightBackgroundColor |
|
0 | 1123 |
]. |
59 | 1124 |
DefaultShadowColor notNil ifTrue:[ |
1125 |
shadowColor := DefaultShadowColor on:device |
|
1126 |
]. |
|
1127 |
DefaultLightColor notNil ifTrue:[ |
|
1128 |
lightColor := DefaultLightColor on:device |
|
1129 |
]. |
|
1130 |
||
1131 |
bgColor := bgColor on:device. |
|
1132 |
fgColor := fgColor on:device. |
|
1133 |
activeBgColor := activeBgColor on:device. |
|
1134 |
activeFgColor := activeFgColor on:device. |
|
133 | 1135 |
|
1136 |
raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true. |
|
1137 |
! |
|
1138 |
||
202 | 1139 |
initialize |
1140 |
super initialize. |
|
133 | 1141 |
|
202 | 1142 |
font := font on:device. |
1143 |
self origin:(0.0 @ 0.0) |
|
1144 |
extent:(1.0 @ self preferredExtent y) |
|
1145 |
"/ extent:(1.0 @ (font height + (font descent * 2) + topMargin)). |
|
0 | 1146 |
! |
1147 |
||
1148 |
recreate |
|
128 | 1149 |
"if the image was saved with an active menu, hide it" |
1150 |
||
1151 |
|m| |
|
115 | 1152 |
|
1153 |
activeMenuNumber notNil ifTrue:[ |
|
128 | 1154 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
1155 |
m unrealize. |
|
1156 |
]. |
|
115 | 1157 |
activeMenuNumber := nil. |
1158 |
]. |
|
1159 |
super recreate. |
|
0 | 1160 |
self setMenuOrigins |
1161 |
! |
|
1162 |
||
133 | 1163 |
superView:aView |
1164 |
"when my superView changes, all of my menus must change as well" |
|
1165 |
||
1166 |
super superView:aView. |
|
1167 |
menus notNil ifTrue:[ |
|
1168 |
menus do:[:aMenu | |
|
1169 |
aMenu notNil ifTrue:[ |
|
1170 |
aMenu superView:aView |
|
1171 |
] |
|
1172 |
] |
|
1173 |
] |
|
0 | 1174 |
! ! |
1175 |
||
1176 |
!PullDownMenu methodsFor:'private'! |
|
1177 |
||
1178 |
indexOf:stringOrNumber |
|
91 | 1179 |
"return the index of the menu with title; return 0 if not found. |
1180 |
stringOrNumber may be a number, a selector from the selectorArray |
|
1181 |
or a string from the title array." |
|
1182 |
||
1183 |
|idx| |
|
0 | 1184 |
|
91 | 1185 |
stringOrNumber isNumber ifTrue:[ |
59 | 1186 |
^ stringOrNumber |
0 | 1187 |
]. |
91 | 1188 |
selectors notNil ifTrue:[ |
1189 |
idx := selectors indexOf:stringOrNumber. |
|
1190 |
idx ~~ 0 ifTrue:[^ idx]. |
|
1191 |
]. |
|
0 | 1192 |
^ titles indexOf:stringOrNumber |
1193 |
! |
|
1194 |
||
202 | 1195 |
setMenuOrigins |
1196 |
"adjust origins of menus when font changes" |
|
1197 |
||
1198 |
(font device == device) ifTrue:[ |
|
1199 |
menus keysAndValuesDo:[:index :aMenu | |
|
1200 |
aMenu notNil ifTrue:[ |
|
1201 |
aMenu origin:((left + (self titleLenUpTo:index)) |
|
1202 |
@ |
|
1203 |
(height + aMenu borderWidth)) |
|
1204 |
]. |
|
1205 |
] |
|
1206 |
] |
|
1207 |
! |
|
1208 |
||
133 | 1209 |
someMenuItemLabeled:aLabel |
1210 |
"find a menu item. |
|
1211 |
Currently, in ST/X, instances of MenuItem are only created as dummy" |
|
1212 |
||
1213 |
|idx| |
|
1214 |
||
1215 |
idx := self indexOf:aLabel. |
|
1216 |
idx ~~ 0 ifTrue:[ |
|
1217 |
^ MenuItem new menu:self index:idx |
|
1218 |
]. |
|
1219 |
menus notNil ifTrue:[ |
|
1220 |
menus do:[:aMenu | |
|
1221 |
|item| |
|
1222 |
||
1223 |
aMenu notNil ifTrue:[ |
|
1224 |
(item := aMenu someMenuItemLabeled:aLabel) notNil ifTrue:[ |
|
1225 |
^ item |
|
1226 |
] |
|
1227 |
] |
|
1228 |
] |
|
1229 |
]. |
|
1230 |
^ nil |
|
1231 |
! |
|
1232 |
||
110 | 1233 |
titleIndexForX:x |
1234 |
"given a click x-position, return index in title or nil" |
|
1235 |
||
1236 |
|xstart "{ Class: SmallInteger }" |
|
1237 |
xend "{ Class: SmallInteger }" |
|
1238 |
wSpace wSep| |
|
1239 |
||
1240 |
wSpace := (font widthOf:' ') * 2. |
|
1241 |
showSeparatingLines ifTrue:[ |
|
1242 |
self is3D ifTrue:[ |
|
1243 |
wSep := 2 |
|
1244 |
] ifFalse:[ |
|
1245 |
wSep := 1 |
|
1246 |
] |
|
1247 |
] ifFalse:[ |
|
1248 |
wSep := 0 |
|
1249 |
]. |
|
1250 |
xstart := 0. |
|
1251 |
1 to:(titles size) do:[:index | |
|
1252 |
|entry thisLength| |
|
1253 |
||
1254 |
entry := titles at:index. |
|
1255 |
entry isString ifTrue:[ |
|
1256 |
thisLength := font widthOf:entry. |
|
1257 |
] ifFalse:[ |
|
1258 |
thisLength := entry width |
|
1259 |
]. |
|
1260 |
xend := xstart + thisLength + wSpace + wSep. |
|
1261 |
(x between:xstart and:xend) ifTrue:[^ index]. |
|
1262 |
xstart := xend |
|
1263 |
]. |
|
1264 |
^ nil |
|
1265 |
! |
|
1266 |
||
202 | 1267 |
titleLenUpTo:index |
1268 |
"answer len (in pixels) of all title-strings up-to |
|
1269 |
(but excluding) title-index. Used to compute x-position when drawing |
|
1270 |
individual entries." |
|
110 | 1271 |
|
202 | 1272 |
|len "{ Class: SmallInteger }" |
1273 |
wSpace wSep| |
|
110 | 1274 |
|
202 | 1275 |
(index <= 1) ifTrue:[^ 0]. |
1276 |
wSpace := (font widthOf:' '). |
|
1277 |
showSeparatingLines ifTrue:[ |
|
1278 |
self is3D ifTrue:[ |
|
1279 |
wSep := 2 |
|
1280 |
] ifFalse:[ |
|
1281 |
wSep := 1 |
|
1282 |
] |
|
1283 |
] ifFalse:[ |
|
1284 |
wSep := 0 |
|
133 | 1285 |
]. |
1286 |
||
202 | 1287 |
len := 0. |
1288 |
titles from:1 to:(index - 1) do:[:entry | |
|
1289 |
|thisLength| |
|
128 | 1290 |
|
202 | 1291 |
entry isString ifTrue:[ |
1292 |
thisLength := (font widthOf:entry). |
|
1293 |
] ifFalse:[ |
|
1294 |
thisLength := entry width |
|
131 | 1295 |
]. |
202 | 1296 |
len := len + thisLength + wSpace + wSep + wSpace. |
110 | 1297 |
]. |
202 | 1298 |
^ len |
110 | 1299 |
! ! |
1300 |
||
202 | 1301 |
!PullDownMenu methodsFor:'queries'! |
110 | 1302 |
|
202 | 1303 |
preferredExtent |
1304 |
|w| |
|
0 | 1305 |
|
202 | 1306 |
w := self titleLenUpTo:(titles size + 1). |
1307 |
^ w @ (font height + (font descent * 2) "+ topMargin" + (margin*2)). |
|
110 | 1308 |
! ! |
0 | 1309 |
|
110 | 1310 |
!PullDownMenu methodsFor:'submenu notifications'! |
0 | 1311 |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1312 |
hideSubmenu |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1313 |
"sent by en escaped menu - ignored here" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1314 |
|
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1315 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1316 |
|
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1317 |
"Modified: 4.3.1996 / 22:58:22 / cg" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1318 |
! |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1319 |
|
110 | 1320 |
showActive |
128 | 1321 |
"sent by a menu to tell me that it starts to perform |
1322 |
its menu action." |
|
131 | 1323 |
|
1324 |
windowGroup notNil ifTrue:[windowGroup showCursor:Cursor wait] |
|
38 | 1325 |
! |
1326 |
||
110 | 1327 |
showPassive |
128 | 1328 |
"sent by a menu to tell me that it finished its menu-action. |
1329 |
Here, we hide the currently active menu." |
|
0 | 1330 |
|
131 | 1331 |
self hideActiveMenu. |
1332 |
windowGroup notNil ifTrue:[windowGroup restoreCursors] |
|
77 | 1333 |
! |
1334 |
||
110 | 1335 |
submenuTriggered |
1336 |
"sent by a sub-submenu to tell me that it finished its menu-action." |
|
1337 |
||
1338 |
self showPassive |
|
0 | 1339 |
! ! |
1340 |
||
205 | 1341 |
!PullDownMenu class methodsFor:'documentation'! |
1342 |
||
1343 |
version |
|
487 | 1344 |
^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.40 1996-03-07 09:33:53 ca Exp $' |
205 | 1345 |
! ! |