author | Claus Gittinger <cg@exept.de> |
Tue, 23 Apr 1996 00:20:42 +0200 | |
changeset 572 | 121735c2aff6 |
parent 542 | 25e48c7527f8 |
child 586 | 032b3245e53a |
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 |
||
542 | 13 |
View 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 |
542 | 17 |
raiseTopWhenActivated actions' |
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 |
||
542 | 398 |
actionAt:stringOrNumber |
399 |
"return the actionBlock associated with stringOrNumber; |
|
400 |
nil if there is none (but there may be still a selector there)." |
|
401 |
||
402 |
|index| |
|
403 |
||
404 |
actions isNil ifTrue:[^ nil]. |
|
405 |
index := self indexOf:stringOrNumber. |
|
406 |
(index == 0) ifTrue:[^ nil]. |
|
407 |
^ actions at:index ifAbsent:nil |
|
408 |
||
409 |
"Modified: 24.3.1996 / 17:09:56 / cg" |
|
410 |
"Created: 17.4.1996 / 20:50:45 / cg" |
|
411 |
! |
|
412 |
||
413 |
actionAt:stringOrNumber put:aBlock |
|
414 |
"return the actionBlock associated with stringOrNumber; |
|
415 |
nil if there is none (but there may be still a selector there)." |
|
416 |
||
417 |
|index newActions| |
|
418 |
||
419 |
index := self indexOf:stringOrNumber. |
|
420 |
(index == 0) ifTrue:[^ nil]. |
|
421 |
actions size < index ifTrue:[ |
|
422 |
newActions := Array new:index. |
|
423 |
newActions replaceFrom:1 to:actions size with:actions. |
|
424 |
actions := newActions |
|
425 |
]. |
|
426 |
actions at:index put:aBlock |
|
427 |
||
428 |
"Modified: 24.3.1996 / 17:09:56 / cg" |
|
429 |
"Created: 17.4.1996 / 20:52:13 / cg" |
|
430 |
! |
|
431 |
||
283 | 432 |
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
|
433 |
"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
|
434 |
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
|
435 |
or #at:putLabels:selectors:..." |
283 | 436 |
|
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
|
437 |
self add:label selector:selector after:nil |
283 | 438 |
! |
439 |
||
440 |
add:label selector:selector after:indexOrString |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
441 |
"add a new title-item after an existing item, indexOrString, |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
442 |
or at the end if the after-arg is nil. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
443 |
The corresponding label can later be set with #at:putMenu: |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
444 |
or #at:putLabels:selectors:..." |
283 | 445 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
446 |
|idx| |
283 | 447 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
448 |
indexOrString isNil ifTrue:[ |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
449 |
idx := titles size |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
450 |
] ifFalse:[ |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
451 |
idx := self indexOf:indexOrString. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
452 |
]. |
283 | 453 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
454 |
titles isNil ifTrue:[ |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
455 |
menus := Array with:nil. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
456 |
titles := Array with:label. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
457 |
selectors := Array with:selector. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
458 |
] ifFalse:[ |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
459 |
menus := (menus copyTo:idx) , #(nil) , (menus copyFrom:idx+1). |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
460 |
titles := ((titles copyTo:idx) copyWith:label) , (titles copyFrom:idx+1). |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
461 |
selectors := ((selectors copyTo:idx) copyWith:selector) , (selectors copyFrom:idx+1). |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
462 |
]. |
283 | 463 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
464 |
" |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
465 |
|top m| |
283 | 466 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
467 |
top := StandardSystemView new. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
468 |
m := PullDownMenu in:top. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
469 |
m labels:#('file' 'edit'). |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
470 |
m selectors:#(file #edit). |
283 | 471 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
472 |
m add:'help' selector:#help after:#file. |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
473 |
m at:#help putMenu:(MenuView labels:#('foo' 'bar') |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
474 |
selectors:#(foo bar) |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
475 |
receiver:nil). |
283 | 476 |
|
532
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
477 |
top open |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
478 |
" |
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
479 |
|
689d1c622a14
oops - adding to an empty menu forgor selector
Claus Gittinger <cg@exept.de>
parents:
518
diff
changeset
|
480 |
"Modified: 12.4.1996 / 19:02:47 / cg" |
283 | 481 |
! |
482 |
||
202 | 483 |
at:aString putLabels:labels selector:selector args:args receiver:anObject |
484 |
"create and set the menu under the title, aString" |
|
485 |
||
486 |
|menuView| |
|
487 |
||
488 |
menuView := MenuView labels:labels |
|
489 |
selector:selector |
|
490 |
args:args |
|
491 |
receiver:anObject |
|
492 |
for:self. |
|
493 |
self at:aString putMenu:menuView |
|
494 |
! |
|
495 |
||
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
496 |
at:aString putLabels:labels selectors:selectors |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
497 |
"create and set the menu under the title, aString" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
498 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
499 |
^ self at:aString putLabels:labels selectors:selectors receiver:nil |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
500 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
501 |
"Created: 24.3.1996 / 17:06:45 / cg" |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
502 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
503 |
|
202 | 504 |
at:aString putLabels:labels selectors:selectors args:args receiver:anObject |
505 |
"create and set the menu under the title, aString" |
|
506 |
||
507 |
|menuView| |
|
508 |
||
509 |
menuView := MenuView labels:labels |
|
510 |
selectors:selectors |
|
511 |
args:args |
|
512 |
receiver:anObject |
|
513 |
for:self. |
|
514 |
self at:aString putMenu:menuView |
|
515 |
! |
|
516 |
||
517 |
at:aString putLabels:labels selectors:selectors receiver:anObject |
|
518 |
"create and set the menu under the title, aString" |
|
519 |
||
520 |
|menuView| |
|
521 |
||
522 |
menuView := MenuView labels:labels |
|
523 |
selectors:selectors |
|
524 |
receiver:anObject |
|
525 |
for:self. |
|
526 |
self at:aString putMenu:menuView |
|
527 |
! |
|
528 |
||
529 |
at:aString putMenu:aMenu |
|
530 |
"set the menu under the title, aString" |
|
531 |
||
532 |
|index| |
|
533 |
||
534 |
index := self indexOf:aString. |
|
535 |
(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
|
536 |
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
|
537 |
^ nil |
202 | 538 |
]. |
539 |
||
540 |
"/ not needed: |
|
541 |
"/ aMenu origin:((left + (self titleLenUpTo:index)) |
|
542 |
"/ @ |
|
543 |
"/ (height + aMenu borderWidth)). |
|
283 | 544 |
aMenu superView:(self superView). |
291 | 545 |
aMenu beInvisible. |
202 | 546 |
menus at:index put:aMenu. |
547 |
aMenu masterView:self. |
|
548 |
! |
|
549 |
||
550 |
labels |
|
551 |
"return the menu-titles (group-headers)" |
|
552 |
||
553 |
^ titles |
|
554 |
! |
|
0 | 555 |
|
556 |
labels:titleArray |
|
202 | 557 |
"define the menu-titles (group-headers)" |
558 |
||
559 |
|numberOfLabels| |
|
560 |
||
561 |
numberOfLabels := titleArray size. |
|
562 |
menus := Array new:numberOfLabels. |
|
563 |
titles := Array new:numberOfLabels. |
|
564 |
||
565 |
titleArray keysAndValuesDo:[:index :entry | |
|
566 |
|e| |
|
567 |
||
568 |
entry isImage ifTrue:[ |
|
569 |
e := entry on:device |
|
570 |
] ifFalse:[ |
|
571 |
e := entry printString |
|
572 |
]. |
|
573 |
titles at:index put:e |
|
574 |
]. |
|
575 |
shown ifTrue:[ |
|
576 |
self clear. |
|
577 |
self redraw |
|
578 |
] |
|
579 |
! |
|
580 |
||
581 |
labels:titleArray selectors:selectorArray |
|
582 |
"define the menu-titles (group-headers) and selectors. |
|
583 |
Selectors are mostly used as access keys to get to submenus later." |
|
584 |
||
585 |
self labels:titleArray. |
|
586 |
self selectors:selectorArray |
|
587 |
||
588 |
"Created: 20.10.1995 / 20:15:54 / cg" |
|
589 |
! |
|
590 |
||
591 |
menuAt:stringOrNumber |
|
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
592 |
"return the menu with the title; nil if not found" |
202 | 593 |
|
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
594 |
^ self subMenuAt:stringOrNumber |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
595 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
596 |
"Modified: 24.3.1996 / 17:10:11 / cg" |
202 | 597 |
! |
598 |
||
599 |
numberOfTitles:n |
|
600 |
"setup blank title-space to be filled in later" |
|
601 |
||
602 |
menus := Array new:n. |
|
603 |
titles := Array new:n |
|
604 |
! |
|
605 |
||
606 |
receiver:anObject |
|
607 |
"set the menu-receiver. Thats the one who gets the |
|
608 |
messages (both from myself and from my submenus). |
|
609 |
This only sets the receiver for menus which are already |
|
610 |
created - menus added later should get their receiver in |
|
611 |
the creation send." |
|
612 |
||
613 |
receiver := anObject. |
|
614 |
menus notNil ifTrue:[ |
|
615 |
menus do:[:aMenu | |
|
616 |
aMenu notNil ifTrue:[ |
|
617 |
aMenu receiver:anObject |
|
618 |
] |
|
619 |
] |
|
620 |
] |
|
621 |
! |
|
622 |
||
283 | 623 |
selectors |
624 |
"return the menu-selectors" |
|
625 |
||
626 |
^ selectors |
|
627 |
! |
|
628 |
||
202 | 629 |
selectors:selectorArray |
630 |
"define the menu-selectors. These are used as accesskey only |
|
631 |
in menuAt: accesses. This makes PullDownMenu accesss |
|
632 |
somewhat more compatible to PopUpMenus." |
|
633 |
||
634 |
selectors := selectorArray. |
|
283 | 635 |
|
518
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
636 |
! |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
637 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
638 |
subMenuAt:stringOrNumber |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
639 |
"return the menu with the title; nil if not found." |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
640 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
641 |
|index| |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
642 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
643 |
index := self indexOf:stringOrNumber. |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
644 |
(index == 0) ifTrue:[^ nil]. |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
645 |
^ menus at:index |
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
646 |
|
731c905a6d89
unified #menuAt/#subMenuAt method names
Claus Gittinger <cg@exept.de>
parents:
516
diff
changeset
|
647 |
"Modified: 24.3.1996 / 17:09:56 / cg" |
202 | 648 |
! ! |
649 |
||
650 |
!PullDownMenu methodsFor:'accessing-look'! |
|
651 |
||
652 |
backgroundColor:aColor |
|
653 |
"set the background drawing color. |
|
654 |
You should not use this method; instead leave the value as |
|
655 |
defined in the styleSheet." |
|
656 |
||
657 |
bgColor := aColor on:device |
|
658 |
! |
|
659 |
||
660 |
font:aFont |
|
661 |
"set the menus font. |
|
662 |
adjusts menu-origins when font changes. |
|
663 |
You should not use this method; instead leave the value as |
|
664 |
defined in the styleSheet." |
|
665 |
||
666 |
aFont ~~ font ifTrue:[ |
|
667 |
super font:(aFont on:device). |
|
668 |
self height:(font height + (font descent * 2)). |
|
669 |
shown ifTrue:[ |
|
670 |
self setMenuOrigins |
|
671 |
] |
|
672 |
] |
|
673 |
! |
|
674 |
||
675 |
foregroundColor:aColor |
|
676 |
"set the foreground drawing color. |
|
677 |
You should not use this method; instead leave the value as |
|
678 |
defined in the styleSheet." |
|
679 |
||
680 |
fgColor := aColor on:device |
|
681 |
! |
|
682 |
||
683 |
showSeparatingLines:aBoolean |
|
684 |
"turn on/off drawing of separating lines. |
|
685 |
You should not use this method; instead leave the value as |
|
686 |
defined in the styleSheet." |
|
687 |
||
688 |
showSeparatingLines := aBoolean. |
|
689 |
shown ifTrue:[ |
|
690 |
self setMenuOrigins. |
|
691 |
self redraw |
|
692 |
] |
|
693 |
! ! |
|
694 |
||
695 |
!PullDownMenu methodsFor:'drawing '! |
|
696 |
||
697 |
drawActiveTitleSelected:selected |
|
698 |
|x| |
|
699 |
activeMenuNumber notNil ifTrue:[ |
|
700 |
x := self titleLenUpTo:activeMenuNumber. |
|
701 |
self drawTitle:(titles at:activeMenuNumber) x:x selected:selected |
|
702 |
] |
|
703 |
! |
|
704 |
||
705 |
drawTitle:stringOrImage x:x0 selected:selected |
|
706 |
|y w x wSpace fg bg map| |
|
707 |
||
708 |
selected ifTrue:[ |
|
709 |
fg := activeFgColor. |
|
710 |
bg := activeBgColor |
|
711 |
] ifFalse:[ |
|
712 |
fg := fgColor. |
|
713 |
bg := bgColor |
|
714 |
]. |
|
715 |
||
716 |
wSpace := font widthOf:' '. |
|
717 |
x := x0. |
|
718 |
stringOrImage isString ifTrue:[ |
|
719 |
y := ((height - (font height)) // 2) + (font ascent) "+ topMargin". |
|
720 |
w := font widthOf:stringOrImage. |
|
721 |
] ifFalse:[ |
|
722 |
y := ((height - stringOrImage height) // 2) max:0. |
|
723 |
w := stringOrImage width |
|
724 |
]. |
|
725 |
w := w + (wSpace * 2). |
|
726 |
||
727 |
self paint:bg. |
|
728 |
self fillRectangleX:x y:0 width:w height:height. |
|
729 |
||
730 |
self is3D ifTrue:[ |
|
731 |
self drawEdgesForX:x y:0 |
|
732 |
width:w |
|
733 |
height:height |
|
734 |
level:(selected ifTrue:[onLevel] ifFalse:[offLevel]) |
|
735 |
]. |
|
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
|
736 |
self paint:fg on:bg. |
202 | 737 |
x := x + wSpace. |
738 |
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
|
739 |
self displayOpaqueString:stringOrImage x:x y:y |
202 | 740 |
] ifFalse:[ |
741 |
stringOrImage isImageOrForm ifTrue:[ |
|
742 |
stringOrImage depth == 1 ifTrue:[ |
|
743 |
(map := stringOrImage colorMap) notNil ifTrue:[ |
|
744 |
self paint:(map at:2) on:(map at:1). |
|
745 |
self displayOpaqueForm:stringOrImage x:x y:y. |
|
746 |
^ self |
|
747 |
] |
|
748 |
]. |
|
749 |
self displayForm:stringOrImage x:x y:y |
|
750 |
] ifFalse:[ |
|
751 |
stringOrImage displayOn:self x:x y:y |
|
752 |
] |
|
753 |
] |
|
754 |
||
755 |
"Modified: 20.10.1995 / 22:03:27 / cg" |
|
756 |
! |
|
757 |
||
758 |
highlightActiveTitle |
|
759 |
self drawActiveTitleSelected:true |
|
760 |
! |
|
761 |
||
762 |
redraw |
|
763 |
|x "{ Class: SmallInteger }" |
|
764 |
y "{ Class: SmallInteger }" |
|
765 |
index "{ Class: SmallInteger }" |
|
766 |
wSpace clr| |
|
767 |
||
768 |
shown ifFalse: [ ^ self ]. |
|
769 |
titles isNil ifTrue:[^ self]. |
|
770 |
||
771 |
wSpace := (font widthOf:' '). |
|
772 |
x := 0. |
|
773 |
y := height "- 1". |
|
774 |
index := 1. |
|
775 |
titles do:[:title | |
|
776 |
self drawTitle:title x:x selected:(index == activeMenuNumber). |
|
777 |
||
778 |
title isString ifTrue:[ |
|
779 |
x := x + (font widthOf:title). |
|
780 |
] ifFalse:[ |
|
781 |
x := x + title width |
|
782 |
]. |
|
783 |
x := x + wSpace + wSpace. |
|
784 |
showSeparatingLines ifTrue:[ |
|
785 |
self is3D ifTrue:[ |
|
786 |
self paint:shadowColor. |
|
787 |
self displayLineFromX:x y:0 toX:x y:y. |
|
788 |
x := x + 1. |
|
789 |
clr := lightColor. |
|
790 |
] ifFalse:[ |
|
791 |
clr := fgColor. |
|
792 |
]. |
|
793 |
self paint:clr. |
|
794 |
self displayLineFromX:x y:0 toX:x y:y. |
|
795 |
x := x + 1 |
|
796 |
]. |
|
797 |
index := index + 1 |
|
798 |
] |
|
799 |
! |
|
800 |
||
801 |
unHighlightActiveTitle |
|
802 |
self drawActiveTitleSelected:false |
|
803 |
! ! |
|
804 |
||
805 |
!PullDownMenu methodsFor:'event handling'! |
|
806 |
||
807 |
buttonMotion:state x:x y:y |
|
808 |
|titleIndex activeMenu activeLeft activeTop| |
|
809 |
||
810 |
state == 0 ifTrue:[^ self]. |
|
811 |
||
812 |
activeMenuNumber notNil ifTrue:[ |
|
813 |
activeMenu := menus at:activeMenuNumber. |
|
814 |
]. |
|
0 | 815 |
|
202 | 816 |
(y < height) ifTrue:[ |
817 |
"moving around in title line" |
|
818 |
activeMenu notNil ifTrue:[ |
|
819 |
activeMenu selection:nil |
|
820 |
]. |
|
821 |
titleIndex := self titleIndexForX:x. |
|
822 |
titleIndex notNil ifTrue:[ |
|
823 |
(titleIndex ~~ activeMenuNumber) ifTrue:[ |
|
824 |
self pullMenu:titleIndex |
|
825 |
] |
|
826 |
] ifFalse:[ |
|
827 |
self hideActiveMenu |
|
828 |
] |
|
829 |
] ifFalse:[ |
|
830 |
"moving around below" |
|
831 |
activeMenu isNil ifTrue:[^self]. |
|
832 |
activeLeft := activeMenu left. |
|
833 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
834 |
activeTop := activeMenu top. |
|
835 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
836 |
"moving around in menu" |
|
837 |
activeMenu buttonMotion:state |
|
838 |
x:(x - activeLeft) |
|
839 |
y:(y - activeTop). |
|
840 |
^ self |
|
841 |
] |
|
842 |
]. |
|
843 |
"moved outside menu" |
|
844 |
activeMenu selection:nil |
|
845 |
] |
|
846 |
! |
|
847 |
||
848 |
buttonPress:button x:x y:y |
|
849 |
|titleIndex activeMenu activeLeft activeTop m| |
|
850 |
||
851 |
device ungrabPointer. |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
852 |
device ungrabKeyboard. |
202 | 853 |
|
854 |
(y between:0 and:height) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
855 |
titleIndex := self titleIndexForX:x. |
202 | 856 |
]. |
857 |
||
858 |
" |
|
859 |
now, titleIndex is non-nil if pressed within myself |
|
860 |
" |
|
861 |
(titleIndex notNil and:[titleIndex ~~ activeMenuNumber]) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
862 |
m := self pullMenu:titleIndex. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
863 |
(keepMenu and:[m notNil]) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
864 |
device grabPointerInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
865 |
device grabKeyboardInView:self. |
484 | 866 |
"/ self cursor:Cursor upRightArrow |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
867 |
] |
202 | 868 |
] ifFalse:[ |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
869 |
(keepMenu and:[toggleKeep not]) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
870 |
titleIndex == activeMenuNumber ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
871 |
"same pressed again ... stay" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
872 |
titleIndex notNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
873 |
device grabPointerInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
874 |
device grabKeyboardInView:self. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
875 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
876 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
877 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
878 |
"moving around below" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
879 |
activeMenuNumber isNil ifTrue:[^self]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
880 |
activeMenu := menus at:activeMenuNumber. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
881 |
activeLeft := activeMenu left. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
882 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
883 |
activeTop := activeMenu top. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
884 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
885 |
"moving around in menu" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
886 |
activeMenu buttonPress:button |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
887 |
x:(x - activeLeft) |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
888 |
y:(y - activeTop). |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
889 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
890 |
] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
891 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
892 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
893 |
self hideActiveMenu |
202 | 894 |
] |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
895 |
|
484 | 896 |
"Modified: 6.3.1996 / 17:14:16 / cg" |
202 | 897 |
! |
898 |
||
899 |
buttonRelease:button x:x y:y |
|
900 |
|activeMenu activeLeft activeTop hideMenu sel| |
|
901 |
||
902 |
activeMenuNumber isNil ifTrue:[^self]. |
|
903 |
activeMenu := menus at:activeMenuNumber. |
|
904 |
||
905 |
hideMenu := false. |
|
906 |
(y >= height) ifTrue:[ |
|
542 | 907 |
"release below title-line" |
908 |
activeLeft := activeMenu left. |
|
909 |
" |
|
910 |
released in a submenu ? |
|
911 |
" |
|
912 |
(x between:activeLeft and:(activeMenu right)) ifTrue:[ |
|
913 |
activeTop := activeMenu top. |
|
914 |
(y between:activeTop and:(activeMenu bottom)) ifTrue:[ |
|
915 |
"release in menu" |
|
916 |
self hideActiveMenu. |
|
917 |
activeMenu buttonRelease:button |
|
918 |
x:(x - activeLeft) |
|
919 |
y:(y - activeTop). |
|
920 |
^ self |
|
921 |
] |
|
922 |
]. |
|
923 |
hideMenu := true. |
|
202 | 924 |
] ifFalse:[ |
542 | 925 |
y < 0 ifTrue:[ |
926 |
hideMenu := true |
|
927 |
] ifFalse:[ |
|
928 |
activeMenu isNil ifTrue:[ |
|
929 |
self performSelectedAction. |
|
930 |
hideMenu := true. |
|
931 |
] ifFalse:[ |
|
932 |
keepMenu ifFalse:[ |
|
933 |
hideMenu := true |
|
934 |
] |
|
935 |
] |
|
936 |
] |
|
202 | 937 |
]. |
938 |
hideMenu ifTrue:[ |
|
939 |
self hideActiveMenu. |
|
940 |
] |
|
542 | 941 |
|
942 |
"Modified: 17.4.1996 / 20:56:08 / cg" |
|
202 | 943 |
! |
944 |
||
945 |
keyPress:key x:x y:y |
|
491 | 946 |
|
202 | 947 |
<resource: #keyboard (#CursorLeft #CursorRight #MenuSelect)> |
948 |
||
513
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
949 |
|index startIndex m sel| |
202 | 950 |
|
951 |
" |
|
952 |
handle CursorLeft/Right for non-mouse operation |
|
953 |
(for example, if it has the explicit focus) |
|
954 |
These will pull the previous/next menu |
|
955 |
" |
|
956 |
((key == #CursorRight) or:[key == #CursorLeft]) ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
957 |
activeMenuNumber isNil ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
958 |
index := (key == #CursorRight) ifTrue:[1] ifFalse:[menus size]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
959 |
] ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
960 |
(key == #CursorRight) ifTrue:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
961 |
index := activeMenuNumber+1 |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
962 |
] ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
963 |
index := activeMenuNumber-1 |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
964 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
965 |
index == 0 ifTrue:[index := menus size] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
966 |
ifFalse:[ |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
967 |
index > menus size ifTrue:[index := 1] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
968 |
] |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
969 |
]. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
970 |
self pullMenu:index. |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
971 |
^ self |
202 | 972 |
]. |
973 |
||
513
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
974 |
"/ activeMenuNumber isNil ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
975 |
"/ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
976 |
"/ find an item starting with that alpha-key |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
977 |
"/ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
978 |
key isCharacter ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
979 |
(key isLetter) ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
980 |
activeMenuNumber isNil ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
981 |
startIndex := 1. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
982 |
] ifFalse:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
983 |
startIndex := activeMenuNumber + 1 |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
984 |
]. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
985 |
index := titles |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
986 |
findFirst:[:item | |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
987 |
item isString |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
988 |
and:[(item startsWith:key asUppercase) |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
989 |
or:[item startsWith:key asLowercase]]] |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
990 |
startingAt:startIndex. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
991 |
|
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
992 |
(index == 0 and:[startIndex ~~ 1]) ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
993 |
index := titles |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
994 |
findFirst:[:item | |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
995 |
item isString |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
996 |
and:[(item startsWith:key asUppercase) |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
997 |
or:[item startsWith:key asLowercase]]] |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
998 |
startingAt:1. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
999 |
]. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1000 |
|
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1001 |
index ~~ 0 ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1002 |
self pullMenu:index. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1003 |
]. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1004 |
^ self |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1005 |
] |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1006 |
]. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1007 |
"/ ]. |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1008 |
|
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1009 |
activeMenuNumber isNil ifTrue:[ |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1010 |
^ super keyPress:key x:x y:y |
97fe3c60042b
quick item select (press alpha key for item)
Claus Gittinger <cg@exept.de>
parents:
491
diff
changeset
|
1011 |
]. |
202 | 1012 |
|
1013 |
" |
|
1014 |
Return, space or the (virtual) MenuSelect key trigger |
|
1015 |
a menu entry (for non-submenu entries). |
|
1016 |
Otherwise, if we have a submenu open, |
|
1017 |
pass the key on to it ... |
|
1018 |
" |
|
1019 |
m := menus at:activeMenuNumber. |
|
1020 |
m isNil ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1021 |
(key == #Return |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1022 |
or:[key == #MenuSelect |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1023 |
or:[key == Character space]]) ifTrue:[ |
542 | 1024 |
self performSelectedAction. |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1025 |
]. |
202 | 1026 |
] ifFalse:[ |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1027 |
m keyPress:key x:0 y:0. |
202 | 1028 |
]. |
491 | 1029 |
|
542 | 1030 |
"Modified: 17.4.1996 / 20:56:20 / cg" |
202 | 1031 |
! |
1032 |
||
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
|
1033 |
showNoFocus:explicit |
202 | 1034 |
"when stepping focus, hide any active menu" |
1035 |
||
1036 |
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
|
1037 |
super showNoFocus:explicit |
202 | 1038 |
! ! |
1039 |
||
1040 |
!PullDownMenu methodsFor:'hiding/showing menus'! |
|
1041 |
||
317
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1042 |
hide |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1043 |
"sent by an aborted menu" |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1044 |
|
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1045 |
self hideActiveMenu. |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1046 |
! |
f23de8b78f5e
Escape closes pullDownMenus & PopUpLists
Claus Gittinger <cg@exept.de>
parents:
309
diff
changeset
|
1047 |
|
202 | 1048 |
hideActiveMenu |
1049 |
"hide currently active menu - release grab if there is any grab (keepMenu)" |
|
1050 |
||
1051 |
^ self hideActiveMenuRelease:true |
|
1052 |
! |
|
1053 |
||
1054 |
hideActiveMenuRelease:aBoolean |
|
1055 |
"hide currently active menu - release grab if aBoolean is true |
|
1056 |
and a grab was set (keepMenu)" |
|
1057 |
||
1058 |
|m| |
|
1059 |
||
1060 |
activeMenuNumber notNil ifTrue:[ |
|
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1061 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1062 |
m beInvisible. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1063 |
]. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1064 |
self unHighlightActiveTitle. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1065 |
activeMenuNumber := nil |
202 | 1066 |
]. |
1067 |
aBoolean ifTrue:[ |
|
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1068 |
device ungrabKeyboard. |
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1069 |
device ungrabPointer. |
484 | 1070 |
"/ self cursor:Cursor normal |
202 | 1071 |
]. |
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1072 |
|
484 | 1073 |
"Modified: 6.3.1996 / 17:14:21 / cg" |
202 | 1074 |
! |
1075 |
||
1076 |
pullMenu:aNumber |
|
1077 |
"activate a menu, return it or nil" |
|
1078 |
||
1079 |
|subMenu r posY| |
|
1080 |
||
1081 |
activeMenuNumber notNil ifTrue:[self hideActiveMenuRelease:false]. |
|
1082 |
activeMenuNumber := aNumber. |
|
1083 |
subMenu := menus at:aNumber. |
|
1084 |
||
1085 |
raiseTopWhenActivated ifTrue:[ |
|
1086 |
self topView raise. |
|
1087 |
]. |
|
1088 |
||
1089 |
(activeMenuNumber notNil |
|
1090 |
and:[ |
|
1091 |
subMenu notNil |
|
1092 |
or:[selectors notNil and:[(selectors at:activeMenuNumber) notNil]]]) ifTrue:[ |
|
1093 |
self highlightActiveTitle. |
|
1094 |
]. |
|
1095 |
||
1096 |
subMenu notNil ifTrue:[ |
|
1097 |
subMenu origin:((left + (self titleLenUpTo:aNumber)) |
|
1098 |
@ |
|
1099 |
(posY := height + subMenu borderWidth)). |
|
1100 |
subMenu hiddenOnRealize:false. |
|
1101 |
subMenu deselect. |
|
1102 |
subMenu create. |
|
1103 |
subMenu saveUnder:true. |
|
1104 |
subMenu superMenu:self. |
|
1105 |
||
1106 |
subMenu right > (r := self right) ifTrue:[ |
|
1107 |
subMenu origin:((r - subMenu width) @ posY). |
|
1108 |
]. |
|
1109 |
subMenu raise show. |
|
1110 |
]. |
|
1111 |
^ subMenu |
|
1112 |
! |
|
1113 |
||
1114 |
regainControl |
|
1115 |
keepMenu ifTrue:[ |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1116 |
device grabPointerInView:self. |
476
c101043c91f7
oops - must release the keyboard as well
Claus Gittinger <cg@exept.de>
parents:
465
diff
changeset
|
1117 |
device grabKeyboardInView:self. |
484 | 1118 |
"/ self cursor:Cursor upRightArrow |
202 | 1119 |
] |
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1120 |
|
484 | 1121 |
"Modified: 6.3.1996 / 17:14:27 / cg" |
0 | 1122 |
! ! |
1123 |
||
77 | 1124 |
!PullDownMenu methodsFor:'initialize / release'! |
0 | 1125 |
|
202 | 1126 |
create |
1127 |
super create. |
|
1128 |
self setMenuOrigins |
|
1129 |
! |
|
1130 |
||
1131 |
destroy |
|
1132 |
"have to destroy the menus manually here, |
|
1133 |
since they are no real subviews of myself" |
|
0 | 1134 |
|
202 | 1135 |
menus notNil ifTrue:[ |
1136 |
menus do:[:m | |
|
1137 |
m notNil ifTrue:[m destroy] |
|
1138 |
]. |
|
1139 |
menus := nil |
|
1140 |
]. |
|
1141 |
activeMenuNumber := nil. |
|
1142 |
super destroy. |
|
1143 |
! |
|
1144 |
||
1145 |
initCursor |
|
1146 |
"set up a hand cursor" |
|
1147 |
||
1148 |
cursor := Cursor hand |
|
0 | 1149 |
! |
1150 |
||
1151 |
initStyle |
|
130 | 1152 |
|style| |
1153 |
||
0 | 1154 |
super initStyle. |
1155 |
||
392
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1156 |
"/ DefaultFont notNil ifTrue:[font := DefaultFont on:device]. |
81343306d796
eliminated all DefaultFont classVars (are now classINSTvars)
Claus Gittinger <cg@exept.de>
parents:
317
diff
changeset
|
1157 |
|
128 | 1158 |
showSeparatingLines := DefaultSeparatingLines. "/ false. |
59 | 1159 |
DefaultViewBackground notNil ifTrue:[ |
60 | 1160 |
viewBackground := DefaultViewBackground on:device |
59 | 1161 |
]. |
1162 |
||
1163 |
DefaultForegroundColor notNil ifTrue:[ |
|
1164 |
fgColor := DefaultForegroundColor |
|
1165 |
] ifFalse:[ |
|
1166 |
fgColor := Black. |
|
1167 |
]. |
|
1168 |
DefaultBackgroundColor notNil ifTrue:[ |
|
1169 |
bgColor := DefaultBackgroundColor |
|
1170 |
] ifFalse:[ |
|
1171 |
bgColor := viewBackground. |
|
1172 |
]. |
|
1173 |
onLevel := DefaultHilightLevel. |
|
1174 |
offLevel := DefaultLevel. |
|
21 | 1175 |
|
0 | 1176 |
self is3D ifTrue:[ |
59 | 1177 |
device hasColors ifTrue:[ |
1178 |
activeFgColor := Color name:'yellow' |
|
1179 |
] ifFalse:[ |
|
1180 |
activeFgColor := White |
|
1181 |
]. |
|
1182 |
device hasGreyscales ifTrue:[ |
|
1183 |
activeBgColor := bgColor. |
|
1184 |
] ifFalse:[ |
|
1185 |
activeBgColor := fgColor. |
|
1186 |
]. |
|
1187 |
topMargin := 2. |
|
21 | 1188 |
|
130 | 1189 |
style := styleSheet name. |
1190 |
((style == #iris) or:[style == #motif]) ifTrue:[ |
|
59 | 1191 |
self level:2. |
1192 |
onLevel := 2. |
|
1193 |
offLevel := 0. |
|
1194 |
activeFgColor := fgColor |
|
1195 |
] |
|
0 | 1196 |
] ifFalse:[ |
59 | 1197 |
activeFgColor := bgColor. |
1198 |
activeBgColor := fgColor. |
|
1199 |
topMargin := 0 |
|
1200 |
]. |
|
1201 |
||
63 | 1202 |
edgeStyle := DefaultEdgeStyle. |
1203 |
keepMenu := DefaultKeepMenu. |
|
110 | 1204 |
toggleKeep := DefaultToggleKeep. |
63 | 1205 |
|
59 | 1206 |
DefaultHilightForegroundColor notNil ifTrue:[ |
1207 |
activeFgColor := DefaultHilightForegroundColor |
|
1208 |
]. |
|
1209 |
DefaultHilightBackgroundColor notNil ifTrue:[ |
|
1210 |
activeBgColor := DefaultHilightBackgroundColor |
|
0 | 1211 |
]. |
59 | 1212 |
DefaultShadowColor notNil ifTrue:[ |
1213 |
shadowColor := DefaultShadowColor on:device |
|
1214 |
]. |
|
1215 |
DefaultLightColor notNil ifTrue:[ |
|
1216 |
lightColor := DefaultLightColor on:device |
|
1217 |
]. |
|
1218 |
||
1219 |
bgColor := bgColor on:device. |
|
1220 |
fgColor := fgColor on:device. |
|
1221 |
activeBgColor := activeBgColor on:device. |
|
1222 |
activeFgColor := activeFgColor on:device. |
|
133 | 1223 |
|
1224 |
raiseTopWhenActivated := styleSheet at:'pullDownMenuRaiseTop' default:true. |
|
1225 |
! |
|
1226 |
||
202 | 1227 |
initialize |
1228 |
super initialize. |
|
133 | 1229 |
|
202 | 1230 |
font := font on:device. |
1231 |
self origin:(0.0 @ 0.0) |
|
1232 |
extent:(1.0 @ self preferredExtent y) |
|
1233 |
"/ extent:(1.0 @ (font height + (font descent * 2) + topMargin)). |
|
0 | 1234 |
! |
1235 |
||
1236 |
recreate |
|
128 | 1237 |
"if the image was saved with an active menu, hide it" |
1238 |
||
1239 |
|m| |
|
115 | 1240 |
|
1241 |
activeMenuNumber notNil ifTrue:[ |
|
128 | 1242 |
(m := menus at:activeMenuNumber) notNil ifTrue:[ |
1243 |
m unrealize. |
|
1244 |
]. |
|
115 | 1245 |
activeMenuNumber := nil. |
1246 |
]. |
|
1247 |
super recreate. |
|
0 | 1248 |
self setMenuOrigins |
1249 |
! |
|
1250 |
||
133 | 1251 |
superView:aView |
1252 |
"when my superView changes, all of my menus must change as well" |
|
1253 |
||
1254 |
super superView:aView. |
|
1255 |
menus notNil ifTrue:[ |
|
1256 |
menus do:[:aMenu | |
|
1257 |
aMenu notNil ifTrue:[ |
|
1258 |
aMenu superView:aView |
|
1259 |
] |
|
1260 |
] |
|
1261 |
] |
|
0 | 1262 |
! ! |
1263 |
||
1264 |
!PullDownMenu methodsFor:'private'! |
|
1265 |
||
1266 |
indexOf:stringOrNumber |
|
91 | 1267 |
"return the index of the menu with title; return 0 if not found. |
1268 |
stringOrNumber may be a number, a selector from the selectorArray |
|
1269 |
or a string from the title array." |
|
1270 |
||
1271 |
|idx| |
|
0 | 1272 |
|
91 | 1273 |
stringOrNumber isNumber ifTrue:[ |
59 | 1274 |
^ stringOrNumber |
0 | 1275 |
]. |
91 | 1276 |
selectors notNil ifTrue:[ |
1277 |
idx := selectors indexOf:stringOrNumber. |
|
1278 |
idx ~~ 0 ifTrue:[^ idx]. |
|
1279 |
]. |
|
0 | 1280 |
^ titles indexOf:stringOrNumber |
1281 |
! |
|
1282 |
||
542 | 1283 |
performEntry:itemIndex |
1284 |
|block sel model| |
|
1285 |
||
1286 |
actions notNil ifTrue:[ |
|
1287 |
block := actions at:itemIndex. |
|
1288 |
block notNil ifTrue:[ |
|
1289 |
block value. |
|
1290 |
^ self |
|
1291 |
]. |
|
1292 |
]. |
|
1293 |
selectors notNil ifTrue:[ |
|
1294 |
sel := selectors at:itemIndex. |
|
1295 |
sel notNil ifTrue:[ |
|
1296 |
model notNil ifTrue:[ |
|
1297 |
model perform:sel |
|
1298 |
] ifFalse:[ |
|
1299 |
receiver perform:sel |
|
1300 |
] |
|
1301 |
]. |
|
1302 |
]. |
|
1303 |
||
1304 |
"Modified: 17.4.1996 / 20:55:11 / cg" |
|
1305 |
! |
|
1306 |
||
1307 |
performSelectedAction |
|
1308 |
|block sel| |
|
1309 |
||
1310 |
actions notNil ifTrue:[ |
|
1311 |
block := actions at:activeMenuNumber. |
|
1312 |
block notNil ifTrue:[ |
|
1313 |
block value. |
|
1314 |
^ self |
|
1315 |
]. |
|
1316 |
]. |
|
1317 |
selectors notNil ifTrue:[ |
|
1318 |
sel := selectors at:activeMenuNumber. |
|
1319 |
sel notNil ifTrue:[ |
|
1320 |
model notNil ifTrue:[ |
|
1321 |
model perform:sel |
|
1322 |
] ifFalse:[ |
|
1323 |
receiver perform:sel |
|
1324 |
] |
|
1325 |
]. |
|
1326 |
]. |
|
1327 |
||
1328 |
"Modified: 17.4.1996 / 20:55:11 / cg" |
|
1329 |
"Created: 17.4.1996 / 20:55:53 / cg" |
|
1330 |
! |
|
1331 |
||
202 | 1332 |
setMenuOrigins |
1333 |
"adjust origins of menus when font changes" |
|
1334 |
||
1335 |
(font device == device) ifTrue:[ |
|
516 | 1336 |
menus notNil ifTrue:[ |
1337 |
menus keysAndValuesDo:[:index :aMenu | |
|
1338 |
aMenu notNil ifTrue:[ |
|
1339 |
aMenu origin:((left + (self titleLenUpTo:index)) |
|
1340 |
@ |
|
1341 |
(height + aMenu borderWidth)) |
|
1342 |
]. |
|
1343 |
] |
|
1344 |
] |
|
202 | 1345 |
] |
516 | 1346 |
|
1347 |
"Modified: 23.3.1996 / 17:18:36 / cg" |
|
202 | 1348 |
! |
1349 |
||
133 | 1350 |
someMenuItemLabeled:aLabel |
1351 |
"find a menu item. |
|
1352 |
Currently, in ST/X, instances of MenuItem are only created as dummy" |
|
1353 |
||
1354 |
|idx| |
|
1355 |
||
1356 |
idx := self indexOf:aLabel. |
|
1357 |
idx ~~ 0 ifTrue:[ |
|
1358 |
^ MenuItem new menu:self index:idx |
|
1359 |
]. |
|
1360 |
menus notNil ifTrue:[ |
|
1361 |
menus do:[:aMenu | |
|
1362 |
|item| |
|
1363 |
||
1364 |
aMenu notNil ifTrue:[ |
|
1365 |
(item := aMenu someMenuItemLabeled:aLabel) notNil ifTrue:[ |
|
1366 |
^ item |
|
1367 |
] |
|
1368 |
] |
|
1369 |
] |
|
1370 |
]. |
|
1371 |
^ nil |
|
1372 |
! |
|
1373 |
||
110 | 1374 |
titleIndexForX:x |
1375 |
"given a click x-position, return index in title or nil" |
|
1376 |
||
1377 |
|xstart "{ Class: SmallInteger }" |
|
1378 |
xend "{ Class: SmallInteger }" |
|
1379 |
wSpace wSep| |
|
1380 |
||
1381 |
wSpace := (font widthOf:' ') * 2. |
|
1382 |
showSeparatingLines ifTrue:[ |
|
1383 |
self is3D ifTrue:[ |
|
1384 |
wSep := 2 |
|
1385 |
] ifFalse:[ |
|
1386 |
wSep := 1 |
|
1387 |
] |
|
1388 |
] ifFalse:[ |
|
1389 |
wSep := 0 |
|
1390 |
]. |
|
1391 |
xstart := 0. |
|
1392 |
1 to:(titles size) do:[:index | |
|
1393 |
|entry thisLength| |
|
1394 |
||
1395 |
entry := titles at:index. |
|
1396 |
entry isString ifTrue:[ |
|
1397 |
thisLength := font widthOf:entry. |
|
1398 |
] ifFalse:[ |
|
1399 |
thisLength := entry width |
|
1400 |
]. |
|
1401 |
xend := xstart + thisLength + wSpace + wSep. |
|
1402 |
(x between:xstart and:xend) ifTrue:[^ index]. |
|
1403 |
xstart := xend |
|
1404 |
]. |
|
1405 |
^ nil |
|
1406 |
! |
|
1407 |
||
202 | 1408 |
titleLenUpTo:index |
1409 |
"answer len (in pixels) of all title-strings up-to |
|
1410 |
(but excluding) title-index. Used to compute x-position when drawing |
|
1411 |
individual entries." |
|
110 | 1412 |
|
202 | 1413 |
|len "{ Class: SmallInteger }" |
1414 |
wSpace wSep| |
|
110 | 1415 |
|
202 | 1416 |
(index <= 1) ifTrue:[^ 0]. |
1417 |
wSpace := (font widthOf:' '). |
|
1418 |
showSeparatingLines ifTrue:[ |
|
1419 |
self is3D ifTrue:[ |
|
1420 |
wSep := 2 |
|
1421 |
] ifFalse:[ |
|
1422 |
wSep := 1 |
|
1423 |
] |
|
1424 |
] ifFalse:[ |
|
1425 |
wSep := 0 |
|
133 | 1426 |
]. |
1427 |
||
202 | 1428 |
len := 0. |
1429 |
titles from:1 to:(index - 1) do:[:entry | |
|
1430 |
|thisLength| |
|
128 | 1431 |
|
202 | 1432 |
entry isString ifTrue:[ |
1433 |
thisLength := (font widthOf:entry). |
|
1434 |
] ifFalse:[ |
|
1435 |
thisLength := entry width |
|
131 | 1436 |
]. |
202 | 1437 |
len := len + thisLength + wSpace + wSep + wSpace. |
110 | 1438 |
]. |
202 | 1439 |
^ len |
110 | 1440 |
! ! |
1441 |
||
202 | 1442 |
!PullDownMenu methodsFor:'queries'! |
110 | 1443 |
|
202 | 1444 |
preferredExtent |
572 | 1445 |
"return my preferredExtent from the title-item widths & font height" |
1446 |
||
202 | 1447 |
|w| |
0 | 1448 |
|
202 | 1449 |
w := self titleLenUpTo:(titles size + 1). |
1450 |
^ w @ (font height + (font descent * 2) "+ topMargin" + (margin*2)). |
|
572 | 1451 |
|
1452 |
"Modified: 23.4.1996 / 00:17:24 / cg" |
|
110 | 1453 |
! ! |
0 | 1454 |
|
110 | 1455 |
!PullDownMenu methodsFor:'submenu notifications'! |
0 | 1456 |
|
465
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1457 |
hideSubmenu |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1458 |
"sent by en escaped menu - ignored here" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1459 |
|
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1460 |
^ self |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1461 |
|
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1462 |
"Modified: 4.3.1996 / 22:58:22 / cg" |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1463 |
! |
b473edeab54e
can now be controlled by keyboard
Claus Gittinger <cg@exept.de>
parents:
456
diff
changeset
|
1464 |
|
110 | 1465 |
showActive |
128 | 1466 |
"sent by a menu to tell me that it starts to perform |
1467 |
its menu action." |
|
131 | 1468 |
|
1469 |
windowGroup notNil ifTrue:[windowGroup showCursor:Cursor wait] |
|
38 | 1470 |
! |
1471 |
||
110 | 1472 |
showPassive |
128 | 1473 |
"sent by a menu to tell me that it finished its menu-action. |
1474 |
Here, we hide the currently active menu." |
|
0 | 1475 |
|
131 | 1476 |
self hideActiveMenu. |
1477 |
windowGroup notNil ifTrue:[windowGroup restoreCursors] |
|
77 | 1478 |
! |
1479 |
||
110 | 1480 |
submenuTriggered |
1481 |
"sent by a sub-submenu to tell me that it finished its menu-action." |
|
1482 |
||
1483 |
self showPassive |
|
0 | 1484 |
! ! |
1485 |
||
205 | 1486 |
!PullDownMenu class methodsFor:'documentation'! |
1487 |
||
1488 |
version |
|
572 | 1489 |
^ '$Header: /cvs/stx/stx/libwidg/PullDownMenu.st,v 1.47 1996-04-22 22:19:32 cg Exp $' |
205 | 1490 |
! ! |