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