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