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