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