0
|
1 |
"
|
4
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
Label subclass:#Button
|
|
14 |
instanceVariableNames:'pressActionBlock releaseActionBlock
|
|
15 |
enabled pressed active
|
|
16 |
autoRepeat repeatBlock
|
|
17 |
onLevel offLevel
|
|
18 |
initialDelay repeatDelay
|
|
19 |
disabledFgColor
|
|
20 |
activeFgColor activeBgColor
|
|
21 |
enteredFgColor enteredBgColor
|
|
22 |
isReturnButton
|
|
23 |
shadowForm lightForm
|
|
24 |
formColor formShadowColor formLightColor'
|
18
|
25 |
classVariableNames:'ReturnForm ReturnLightForm ReturnShadowForm'
|
0
|
26 |
poolDictionaries:''
|
|
27 |
category:'Views-Interactors'
|
|
28 |
!
|
|
29 |
|
|
30 |
Button comment:'
|
|
31 |
|
4
|
32 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
33 |
All Rights Reserved
|
|
34 |
|
18
|
35 |
$Header: /cvs/stx/stx/libwidg/Button.st,v 1.5 1994-01-08 17:22:47 claus Exp $
|
0
|
36 |
|
|
37 |
written spring/summer 89 by claus
|
|
38 |
'!
|
|
39 |
|
|
40 |
!Button class methodsFor:'documentation'!
|
|
41 |
|
|
42 |
documentation
|
|
43 |
"
|
|
44 |
Buttons are Labels which do something when pressed/released.
|
|
45 |
|
|
46 |
Instance variables:
|
|
47 |
|
|
48 |
pressActionBlock <Block> block to evaluate when pressed
|
|
49 |
releaseActionBlock <Block> block to evaluate when released
|
|
50 |
enabled <Boolean> pressing is allowed
|
|
51 |
active <Boolean> true during action evaluation (internal)
|
|
52 |
pressed <Boolean> true if currently pressed
|
|
53 |
autoRepeat <Boolean> allows auto-repeat when pressed long enough
|
|
54 |
repeatBlock <Block> block evaluated for auto-repeat
|
|
55 |
onLevel <Number> level when pressed (3D only)
|
|
56 |
offLevel <Number> level when released (3D only)
|
|
57 |
initialDelay <Number> seconds till first auto-repeat
|
|
58 |
repeatDelay <Number> seconds of repeat intervall
|
|
59 |
disabledFgColor <Color> color used to draw logo when disabled
|
|
60 |
activeFgColor <Color> color to draw logo when pressed
|
|
61 |
activeBgColor <Color> bg color when pressed
|
|
62 |
enteredFgColor <Color> color to draw logo when cursor entered
|
|
63 |
enteredBgColor <Color> bg color when cursor entered
|
|
64 |
|
|
65 |
isReturnButton <Boolean> true if this button is also activated by the
|
|
66 |
return key
|
|
67 |
shadowForm <Form> form to display in addition to buttons label
|
|
68 |
lightForm <Form> light part of shadowForm
|
|
69 |
formColor <Color> color to draw form with
|
|
70 |
formShadowColor <Color> color for shadowing the form (3D only)
|
|
71 |
formLightColor <Color> color for lighting the form (3D only)
|
|
72 |
"
|
|
73 |
! !
|
|
74 |
|
|
75 |
!Button class methodsFor:'defaults'!
|
|
76 |
|
|
77 |
defaultInitialDelay
|
|
78 |
"when autorepeat is enabled, and button is not released,
|
|
79 |
start repeating after initialDelay seconds"
|
|
80 |
|
|
81 |
^ 0.2
|
|
82 |
!
|
|
83 |
|
|
84 |
defaultRepeatDelay
|
|
85 |
"when autorepeat is enabled, and button is not released,
|
|
86 |
repeat every repeatDelay seconds"
|
|
87 |
|
|
88 |
^ 0.025
|
|
89 |
!
|
|
90 |
|
|
91 |
returnFormOn:aDevice
|
|
92 |
"return the form used for the return arrow in non-3D;
|
|
93 |
cache the one for Display for the next round."
|
|
94 |
|
|
95 |
|f|
|
|
96 |
|
18
|
97 |
((aDevice == Display) and:[ReturnForm notNil]) ifTrue:[
|
|
98 |
^ ReturnForm
|
0
|
99 |
].
|
|
100 |
f := Form fromFile:'Return.xbm' resolution:100 on:aDevice.
|
|
101 |
f isNil ifTrue:[
|
|
102 |
f := Form width:24 height:16 fromArray:#(2r00000000 2r00000000 2r00000000
|
|
103 |
2r00000000 2r00000000 2r00000000
|
|
104 |
2r00000000 2r00000000 2r00000000
|
|
105 |
2r00000000 2r00000011 2r11100000
|
|
106 |
2r00000001 2r10000011 2r11100000
|
|
107 |
2r00000011 2r10000011 2r11100000
|
|
108 |
2r00000111 2r11111111 2r11100000
|
|
109 |
2r00001111 2r11111111 2r11100000
|
|
110 |
2r00011111 2r11111111 2r11100000
|
|
111 |
2r00001111 2r11111111 2r11100000
|
|
112 |
2r00000111 2r11111111 2r11100000
|
|
113 |
2r00000011 2r10000000 2r00000000
|
|
114 |
2r00000001 2r10000000 2r00000000
|
|
115 |
2r00000000 2r00000000 2r00000000
|
|
116 |
2r00000000 2r00000000 2r00000000
|
|
117 |
2r00000000 2r00000000 2r00000000)
|
|
118 |
on:aDevice
|
|
119 |
].
|
|
120 |
(aDevice == Display) ifTrue:[
|
18
|
121 |
ReturnForm := f
|
0
|
122 |
].
|
|
123 |
^ f
|
|
124 |
!
|
|
125 |
|
|
126 |
returnShadowFormOn:aDevice
|
|
127 |
"return the form used for the return arrow shadow pixels (3D only);
|
|
128 |
cache the one for Display for the next round."
|
|
129 |
|
|
130 |
|f|
|
|
131 |
|
18
|
132 |
((aDevice == Display) and:[ReturnShadowForm notNil]) ifTrue:[
|
|
133 |
^ ReturnShadowForm
|
0
|
134 |
].
|
|
135 |
f := Form fromFile:'ReturnShadow.xbm' resolution:100 on:aDevice.
|
|
136 |
f isNil ifTrue:[
|
|
137 |
f := Form width:24 height:16 fromArray:#(2r00000000 2r00000000 2r00000000
|
|
138 |
2r00000000 2r00000000 2r00000000
|
|
139 |
2r00000000 2r00000000 2r00000000
|
|
140 |
2r00000000 2r00000011 2r11100000
|
|
141 |
2r00000001 2r10000010 2r00000000
|
|
142 |
2r00000010 2r10000010 2r00000000
|
|
143 |
2r00000100 2r11111110 2r00000000
|
|
144 |
2r00001000 2r00000000 2r00000000
|
|
145 |
2r00010000 2r00000000 2r00000000
|
|
146 |
2r00001000 2r00000000 2r00000000
|
|
147 |
2r00000100 2r00000000 2r00000000
|
|
148 |
2r00000010 2r00000000 2r00000000
|
|
149 |
2r00000001 2r00000000 2r00000000
|
|
150 |
2r00000000 2r00000000 2r00000000
|
|
151 |
2r00000000 2r00000000 2r00000000
|
|
152 |
2r00000000 2r00000000 2r00000000)
|
|
153 |
on:aDevice
|
|
154 |
].
|
|
155 |
(aDevice == Display) ifTrue:[
|
18
|
156 |
ReturnShadowForm := f
|
0
|
157 |
].
|
|
158 |
^ f
|
|
159 |
!
|
|
160 |
|
|
161 |
returnLightFormOn:aDevice
|
|
162 |
"return the form used for the return arrow light pixels (3D only);
|
|
163 |
cache the one for Display for the next round"
|
|
164 |
|
|
165 |
|f|
|
|
166 |
|
18
|
167 |
((aDevice == Display) and:[ReturnLightForm notNil]) ifTrue:[
|
|
168 |
^ ReturnLightForm
|
0
|
169 |
].
|
|
170 |
f := Form fromFile:'ReturnLight.xbm' resolution:100 on:aDevice.
|
|
171 |
f isNil ifTrue:[
|
|
172 |
f := Form width:24 height:16 fromArray:#(2r00000000 2r00000000 2r00000000
|
|
173 |
2r00000000 2r00000000 2r00000000
|
|
174 |
2r00000000 2r00000000 2r00000000
|
|
175 |
2r00000000 2r00000000 2r00000000
|
|
176 |
2r00000000 2r00000000 2r00100000
|
|
177 |
2r00000000 2r00000000 2r00100000
|
|
178 |
2r00000000 2r00000000 2r00100000
|
|
179 |
2r00000000 2r00000000 2r00100000
|
|
180 |
2r00000000 2r00000000 2r00100000
|
|
181 |
2r00000000 2r00000000 2r00100000
|
|
182 |
2r00000000 2r11111111 2r11100000
|
|
183 |
2r00000000 2r10000000 2r00000000
|
|
184 |
2r00000000 2r10000000 2r00000000
|
|
185 |
2r00000000 2r00000000 2r00000000
|
|
186 |
2r00000000 2r00000000 2r00000000
|
|
187 |
2r00000000 2r00000000 2r00000000)
|
|
188 |
on:aDevice
|
|
189 |
].
|
|
190 |
(aDevice == Display) ifTrue:[
|
18
|
191 |
ReturnLightForm := f
|
0
|
192 |
].
|
|
193 |
^ f
|
|
194 |
! !
|
|
195 |
|
|
196 |
!Button class methodsFor:'instance creation'!
|
|
197 |
|
|
198 |
label:aLabel action:aBlock in:aView
|
|
199 |
"create and return a new Button with text-label, aString
|
|
200 |
and pressAction, aBlock. Button is placed into aView."
|
|
201 |
|
|
202 |
^ ((self in:aView) label:aLabel) action:aBlock
|
|
203 |
!
|
|
204 |
|
|
205 |
form:aForm action:aBlock in:aView
|
|
206 |
"create and return a new Button with icon-label, aForm
|
|
207 |
and pressAction, aBlock. Button is placed into aView."
|
|
208 |
|
|
209 |
^ ((self in:aView) form:aForm) action:aBlock
|
|
210 |
! !
|
|
211 |
|
|
212 |
!Button methodsFor:'initialization'!
|
|
213 |
|
|
214 |
initialize
|
|
215 |
super initialize.
|
|
216 |
|
|
217 |
enabled := true.
|
|
218 |
active := false.
|
|
219 |
autoRepeat := false.
|
|
220 |
initialDelay := self class defaultInitialDelay.
|
|
221 |
repeatDelay := self class defaultRepeatDelay.
|
|
222 |
pressed := false.
|
|
223 |
isReturnButton := false.
|
|
224 |
|
|
225 |
self initStyle
|
|
226 |
!
|
|
227 |
|
|
228 |
initStyle
|
|
229 |
super initStyle.
|
|
230 |
|
|
231 |
onLevel := -1.
|
|
232 |
offLevel := 1.
|
18
|
233 |
softEdge := false.
|
0
|
234 |
|
|
235 |
disabledFgColor := Color grey.
|
|
236 |
enteredFgColor := fgColor.
|
|
237 |
enteredBgColor := bgColor.
|
18
|
238 |
activeFgColor := activeBgColor := nil.
|
|
239 |
enteredFgColor := enteredBgColor := nil.
|
|
240 |
halfShadowColor := shadowColor := nil.
|
0
|
241 |
|
|
242 |
(style == #next) ifTrue:[
|
|
243 |
softEdge := true.
|
|
244 |
onLevel := 1.
|
|
245 |
offLevel := 2.
|
|
246 |
device hasGreyscales ifTrue:[
|
|
247 |
activeFgColor := Black.
|
|
248 |
activeBgColor := White.
|
|
249 |
enteredFgColor := fgColor.
|
|
250 |
enteredBgColor := Color lightGrey.
|
|
251 |
halfShadowColor := Color darkGrey.
|
|
252 |
shadowColor := Black.
|
|
253 |
]
|
|
254 |
] ifFalse:[
|
|
255 |
(style == #openwin) ifTrue:[
|
|
256 |
device hasGreyscales ifTrue:[
|
|
257 |
activeFgColor := Black.
|
|
258 |
activeBgColor := Color grey
|
|
259 |
]
|
|
260 |
] ifFalse:[
|
|
261 |
(style == #mswindows) ifTrue:[
|
|
262 |
disabledFgColor := Color darkGrey.
|
|
263 |
device hasGreyscales ifTrue:[
|
|
264 |
offLevel := 3.
|
|
265 |
onLevel := -1.
|
|
266 |
softEdge := true.
|
|
267 |
fgColor := Black.
|
|
268 |
bgColor := Grey.
|
|
269 |
halfShadowColor := Color darkGrey.
|
|
270 |
shadowColor := Black.
|
|
271 |
activeFgColor := fgColor.
|
|
272 |
activeBgColor := bgColor
|
|
273 |
]
|
|
274 |
] ifFalse:[
|
|
275 |
(style == #iris) ifTrue:[
|
|
276 |
offLevel := 3.
|
|
277 |
onLevel := -1.
|
|
278 |
softEdge := true.
|
|
279 |
halfShadowColor := Color darkGrey.
|
|
280 |
shadowColor := Black.
|
|
281 |
disabledFgColor := Color darkGrey.
|
|
282 |
enteredFgColor := fgColor.
|
|
283 |
device hasGreyscales ifTrue:[
|
6
|
284 |
enteredBgColor := bgColor lightened "Color lightGrey".
|
0
|
285 |
activeBgColor := enteredBgColor.
|
|
286 |
activeFgColor := enteredFgColor.
|
|
287 |
] ifFalse:[
|
|
288 |
enteredBgColor := Color veryLightGrey.
|
|
289 |
activeBgColor := Black.
|
|
290 |
activeFgColor := White.
|
|
291 |
].
|
|
292 |
] ifFalse:[
|
|
293 |
device hasColors ifTrue:[
|
|
294 |
activeFgColor := Color red:100 green:100 blue:0 "yellow"
|
|
295 |
] ifFalse:[
|
|
296 |
activeFgColor := White
|
|
297 |
].
|
|
298 |
device hasGreyscales ifTrue:[
|
|
299 |
activeBgColor := bgColor
|
|
300 |
] ifFalse:[
|
|
301 |
activeBgColor := Black
|
|
302 |
]
|
|
303 |
]
|
|
304 |
]
|
|
305 |
]
|
|
306 |
].
|
|
307 |
|
|
308 |
"default for mono-displays and non-3D"
|
|
309 |
activeFgColor isNil ifTrue:[
|
|
310 |
activeFgColor := White.
|
|
311 |
activeBgColor := Black
|
|
312 |
].
|
|
313 |
self level:offLevel.
|
|
314 |
margin := (onLevel abs) max:(offLevel abs).
|
|
315 |
|
|
316 |
self is3D ifTrue:[
|
|
317 |
shadowForm := self class returnShadowFormOn:device.
|
|
318 |
lightForm := self class returnLightFormOn:device.
|
|
319 |
formColor := viewBackground.
|
|
320 |
formShadowColor := shadowColor.
|
|
321 |
formLightColor := lightColor
|
|
322 |
] ifFalse:[
|
|
323 |
shadowForm := self class returnFormOn:device.
|
|
324 |
formColor := Black
|
|
325 |
].
|
|
326 |
!
|
|
327 |
|
|
328 |
initCursor
|
|
329 |
"set up a hand cursor"
|
|
330 |
|
|
331 |
cursor := Cursor hand
|
|
332 |
!
|
|
333 |
|
|
334 |
initEvents
|
|
335 |
super initEvents.
|
|
336 |
self enableButtonEvents.
|
|
337 |
self enableEnterLeaveEvents
|
|
338 |
!
|
|
339 |
|
|
340 |
realize
|
|
341 |
super realize.
|
|
342 |
active := false.
|
|
343 |
|
|
344 |
fgColor := fgColor on:device.
|
|
345 |
bgColor := bgColor on:device.
|
18
|
346 |
activeFgColor notNil ifTrue:[
|
|
347 |
activeFgColor := activeFgColor on:device.
|
|
348 |
].
|
|
349 |
activeBgColor notNil ifTrue:[
|
|
350 |
activeBgColor := activeBgColor on:device.
|
|
351 |
].
|
|
352 |
enteredFgColor notNil ifTrue:[
|
|
353 |
enteredFgColor := enteredFgColor on:device.
|
|
354 |
].
|
|
355 |
enteredBgColor notNil ifTrue:[
|
|
356 |
enteredBgColor := enteredBgColor on:device.
|
|
357 |
].
|
|
358 |
formColor notNil ifTrue:[
|
|
359 |
formColor := formColor on:device.
|
|
360 |
].
|
0
|
361 |
!
|
|
362 |
|
|
363 |
reinitialize
|
|
364 |
super reinitialize.
|
|
365 |
active := false
|
|
366 |
! !
|
|
367 |
|
|
368 |
!Button methodsFor:'accessing'!
|
|
369 |
|
|
370 |
is3D
|
|
371 |
"return true, if the receiver is a 3D style view"
|
|
372 |
|
|
373 |
style == #mswindows ifTrue:[^ true].
|
|
374 |
^ super is3D
|
|
375 |
!
|
|
376 |
|
|
377 |
isReturnButton:aBoolean
|
|
378 |
"show/dont show a return-key image after the label"
|
|
379 |
|
|
380 |
isReturnButton ~~ aBoolean ifTrue:[
|
|
381 |
isReturnButton := aBoolean.
|
|
382 |
self newLayout
|
|
383 |
]
|
|
384 |
!
|
|
385 |
|
|
386 |
disable
|
|
387 |
"disable the button"
|
|
388 |
|
|
389 |
enabled ifTrue:[
|
|
390 |
enabled := false.
|
|
391 |
self redraw
|
|
392 |
]
|
|
393 |
!
|
|
394 |
|
|
395 |
enable
|
|
396 |
"enable the button"
|
|
397 |
|
|
398 |
enabled ifFalse:[
|
|
399 |
enabled := true.
|
|
400 |
self redraw
|
|
401 |
]
|
|
402 |
!
|
|
403 |
|
|
404 |
turnOffWithoutRedraw
|
|
405 |
"turn the button off - no redraw"
|
|
406 |
|
|
407 |
pressed := false.
|
|
408 |
active := false.
|
|
409 |
self is3D ifTrue:[
|
|
410 |
"do not use super level:offLevel
|
|
411 |
- that one redraws the edges.
|
|
412 |
Shure, this is no good coding style"
|
|
413 |
level := offLevel.
|
|
414 |
margin := level abs
|
|
415 |
]
|
|
416 |
!
|
|
417 |
|
|
418 |
turnOff
|
|
419 |
"turn the button off (if not already off)"
|
|
420 |
|
|
421 |
pressed ifTrue:[
|
|
422 |
active := false.
|
|
423 |
pressed := false.
|
|
424 |
self level:offLevel.
|
|
425 |
self redraw
|
|
426 |
]
|
|
427 |
!
|
|
428 |
|
|
429 |
turnOn
|
|
430 |
"turn the button on (if not already on)"
|
|
431 |
|
|
432 |
pressed ifFalse:[
|
|
433 |
pressed := true.
|
|
434 |
self level:onLevel.
|
|
435 |
self redraw
|
|
436 |
]
|
|
437 |
!
|
|
438 |
|
|
439 |
pressAction:aBlock
|
|
440 |
"define the action to be performed on press"
|
|
441 |
|
|
442 |
pressActionBlock := aBlock
|
|
443 |
!
|
|
444 |
|
|
445 |
releaseAction:aBlock
|
|
446 |
"define the action to be performed on release"
|
|
447 |
|
|
448 |
releaseActionBlock := aBlock
|
|
449 |
!
|
|
450 |
|
|
451 |
action:aBlock
|
|
452 |
"convenient method: define the press-action clear any release-action"
|
|
453 |
|
|
454 |
releaseActionBlock := nil.
|
|
455 |
pressActionBlock := aBlock
|
|
456 |
!
|
|
457 |
|
|
458 |
autoRepeat
|
|
459 |
"turn on autorepeat"
|
|
460 |
|
|
461 |
autoRepeat := true.
|
|
462 |
repeatBlock := [self repeat]
|
|
463 |
!
|
|
464 |
|
|
465 |
isOn
|
|
466 |
"return true, if this button is currently pressed"
|
|
467 |
|
|
468 |
^ pressed
|
|
469 |
!
|
|
470 |
|
|
471 |
onLevel:aNumber
|
|
472 |
"set the level of the button when pressed (i.e. how deep)"
|
|
473 |
|
|
474 |
onLevel := aNumber.
|
|
475 |
pressed ifTrue:[
|
|
476 |
self level:onLevel.
|
|
477 |
margin := onLevel abs max:offLevel abs.
|
|
478 |
self redraw
|
|
479 |
]
|
|
480 |
!
|
|
481 |
|
|
482 |
onLevel
|
|
483 |
"return the level of the button when pressed"
|
|
484 |
|
|
485 |
^ onLevel
|
|
486 |
!
|
|
487 |
|
|
488 |
offLevel:aNumber
|
|
489 |
"set the level of the button when not pressed (i.e. how high)"
|
|
490 |
|
|
491 |
offLevel := aNumber.
|
|
492 |
pressed ifFalse:[
|
|
493 |
self level:offLevel.
|
|
494 |
margin := onLevel abs max:offLevel abs.
|
|
495 |
self redraw
|
|
496 |
]
|
|
497 |
!
|
|
498 |
|
|
499 |
offLevel
|
|
500 |
"return the level of the button when released"
|
|
501 |
|
|
502 |
^ offLevel
|
|
503 |
!
|
|
504 |
|
|
505 |
activeForegroundColor
|
|
506 |
"return the foreground color to be used when pressed"
|
|
507 |
|
|
508 |
^ activeFgColor
|
|
509 |
!
|
|
510 |
|
|
511 |
activeForegroundColor:aColor
|
|
512 |
"set the foreground color to be used when pressed"
|
|
513 |
|
|
514 |
activeFgColor := aColor.
|
|
515 |
pressed ifTrue:[
|
|
516 |
self redraw
|
|
517 |
]
|
|
518 |
!
|
|
519 |
|
|
520 |
activeBackgroundColor
|
|
521 |
"return the background color to be used when pressed"
|
|
522 |
|
|
523 |
^ activeBgColor
|
|
524 |
!
|
|
525 |
|
|
526 |
activeBackgroundColor:aColor
|
|
527 |
"set the background color to be used when pressed"
|
|
528 |
|
|
529 |
activeBgColor := aColor.
|
|
530 |
pressed ifTrue:[
|
|
531 |
self redraw
|
|
532 |
]
|
|
533 |
!
|
|
534 |
|
|
535 |
activeForegroundColor:fgColor backgroundColor:bgColor
|
|
536 |
"set the colors to be used when pressed"
|
|
537 |
|
|
538 |
activeFgColor := fgColor.
|
|
539 |
activeBgColor := bgColor.
|
|
540 |
pressed ifTrue:[
|
|
541 |
self redraw
|
|
542 |
]
|
|
543 |
!
|
|
544 |
|
|
545 |
enteredForegroundColor
|
|
546 |
"return the foreground color to be used when the mouse
|
|
547 |
pointer enters the button area"
|
|
548 |
|
|
549 |
^ enteredFgColor
|
|
550 |
!
|
|
551 |
|
|
552 |
enteredForegroundColor:aColor
|
|
553 |
"set the foreground color to be used when the mouse
|
|
554 |
pointer enters the button area"
|
|
555 |
|
|
556 |
enteredFgColor := aColor
|
|
557 |
!
|
|
558 |
|
|
559 |
enteredBackgroundColor
|
|
560 |
"return the background color to be used when the mouse
|
|
561 |
pointer enters the button area"
|
|
562 |
|
|
563 |
^ enteredBgColor
|
|
564 |
!
|
|
565 |
|
|
566 |
enteredBackgroundColor:aColor
|
|
567 |
"set the background color to be used when the mouse
|
|
568 |
pointer enters the button area"
|
|
569 |
|
|
570 |
enteredBgColor := aColor
|
|
571 |
! !
|
|
572 |
|
|
573 |
!Button methodsFor:'private'!
|
|
574 |
|
|
575 |
computeLabelSize
|
|
576 |
"compute the extent needed to hold the label plus the return form"
|
|
577 |
|
|
578 |
super computeLabelSize.
|
|
579 |
isReturnButton ifTrue:[
|
|
580 |
labelWidth := labelWidth + hSpace + shadowForm width.
|
|
581 |
labelHeight := labelHeight max: (shadowForm height + vSpace)
|
|
582 |
]
|
|
583 |
!
|
|
584 |
|
|
585 |
resize
|
|
586 |
"resize myself to make logo fit into myself.
|
|
587 |
Redefined, since we add space for a frame around text when non-3D"
|
|
588 |
|
|
589 |
|extra|
|
|
590 |
|
|
591 |
logo isNil ifFalse:[
|
|
592 |
self computeLabelOrigin.
|
|
593 |
(relativeExtent isNil and:[extentRule isNil]) ifTrue:[
|
|
594 |
extra := (onLevel abs max:offLevel abs) * 2.
|
|
595 |
self is3D ifFalse:[
|
|
596 |
(logo isKindOf:Form) ifFalse:[
|
|
597 |
"add space for a frame around"
|
|
598 |
extra := extra + 2
|
|
599 |
]
|
|
600 |
].
|
|
601 |
self extent:(labelWidth + extra) @ (labelHeight + extra)
|
|
602 |
]
|
|
603 |
]
|
|
604 |
! !
|
|
605 |
|
|
606 |
!Button methodsFor:'redrawing'!
|
|
607 |
|
|
608 |
drawWith:fg and:bg
|
|
609 |
"redraw myself with fg/bg. Use super to draw the label, add
|
|
610 |
the return-arrow here."
|
|
611 |
|
18
|
612 |
|x y sColor lColor|
|
0
|
613 |
|
|
614 |
super drawWith:fg and:bg. "this draws the text"
|
|
615 |
|
|
616 |
isReturnButton ifTrue:[
|
|
617 |
y := (height - shadowForm height) // 2.
|
|
618 |
x := width - shadowForm width - (hSpace // 2).
|
|
619 |
|
|
620 |
self is3D ifFalse:[
|
|
621 |
self paint:fg on:bg.
|
|
622 |
self background:bg.
|
|
623 |
self drawOpaqueForm:shadowForm x:x y:y
|
|
624 |
] ifTrue:[
|
|
625 |
((formShadowColor colorId notNil)
|
|
626 |
and:[(formLightColor colorId notNil)
|
18
|
627 |
and:[formColor colorId notNil]])
|
0
|
628 |
ifTrue:[
|
18
|
629 |
sColor := formShadowColor.
|
|
630 |
lColor := formLightColor.
|
|
631 |
] ifFalse:[
|
|
632 |
sColor := Black.
|
|
633 |
lColor := White.
|
|
634 |
].
|
|
635 |
shadowForm notNil ifTrue:[
|
|
636 |
self foreground:sColor.
|
|
637 |
self drawForm:shadowForm x:x y:y.
|
|
638 |
].
|
|
639 |
lightForm notNil ifTrue:[
|
|
640 |
self foreground:lColor.
|
|
641 |
self drawForm:lightForm x:x y:y.
|
|
642 |
].
|
|
643 |
self foreground:fg background:bg function:#copy
|
0
|
644 |
]
|
|
645 |
]
|
|
646 |
!
|
|
647 |
|
|
648 |
redraw
|
|
649 |
"like redrawing a label, but hilight when pressed
|
|
650 |
(lolight when disabled)"
|
|
651 |
|
|
652 |
|fg bg|
|
|
653 |
|
|
654 |
shown ifTrue:[
|
|
655 |
fg := fgColor.
|
|
656 |
bg := bgColor.
|
|
657 |
active ifFalse:[
|
|
658 |
self is3D ifTrue:[
|
|
659 |
enabled ifFalse:[
|
|
660 |
fg := disabledFgColor
|
|
661 |
] ifTrue:[
|
|
662 |
pressed ifTrue:[
|
|
663 |
fg := activeFgColor.
|
|
664 |
bg := activeBgColor
|
|
665 |
]
|
|
666 |
].
|
|
667 |
self drawWith:fg and:bg
|
|
668 |
] ifFalse:[
|
|
669 |
enabled ifFalse:[
|
|
670 |
fg := disabledFgColor.
|
|
671 |
self drawWith:fg and:bg
|
|
672 |
] ifTrue:[
|
|
673 |
pressed ifTrue:[
|
|
674 |
self drawWith:bgColor and:fgColor.
|
|
675 |
(logo isKindOf:Form) ifFalse:[
|
|
676 |
self paint:bg.
|
|
677 |
self drawRectangleX:0 y:0 width:width height:height
|
|
678 |
]
|
|
679 |
] ifFalse:[
|
|
680 |
super redraw
|
|
681 |
]
|
|
682 |
]
|
|
683 |
]
|
|
684 |
]
|
|
685 |
]
|
|
686 |
! !
|
|
687 |
|
|
688 |
!Button methodsFor:'event handling'!
|
|
689 |
|
|
690 |
buttonPress:button x:x y:y
|
|
691 |
"button was pressed - if enabled, perform pressaction"
|
|
692 |
|
|
693 |
button == 1 ifFalse:[
|
|
694 |
^ super buttonPress:button x:x y:y
|
|
695 |
].
|
|
696 |
pressed ifFalse:[
|
|
697 |
enabled ifTrue:[
|
|
698 |
pressed := true.
|
|
699 |
self level:onLevel.
|
|
700 |
self redraw.
|
|
701 |
active := true.
|
|
702 |
pressActionBlock notNil ifTrue:[device synchronizeOutput.
|
|
703 |
pressActionBlock value].
|
|
704 |
active := false.
|
|
705 |
device synchronizeOutput.
|
|
706 |
|
|
707 |
autoRepeat ifTrue:[
|
6
|
708 |
Processor addTimedBlock:repeatBlock after:initialDelay
|
0
|
709 |
]
|
|
710 |
]
|
|
711 |
]
|
|
712 |
!
|
|
713 |
|
|
714 |
buttonMultiPress:button x:x y:y
|
|
715 |
^ self buttonPress:button x:x y:y
|
|
716 |
!
|
|
717 |
|
|
718 |
buttonRelease:button x:x y:y
|
|
719 |
"button was released - if enabled, perform releaseaction"
|
|
720 |
|
|
721 |
button == 1 ifFalse:[
|
|
722 |
^ super buttonRelease:button x:x y:y
|
|
723 |
].
|
|
724 |
pressed ifTrue:[
|
|
725 |
autoRepeat ifTrue:[
|
6
|
726 |
Processor removeTimedBlock:repeatBlock
|
0
|
727 |
].
|
|
728 |
pressed := false.
|
|
729 |
self level:offLevel.
|
|
730 |
self redraw.
|
|
731 |
enabled ifTrue:[
|
|
732 |
active := true.
|
|
733 |
releaseActionBlock notNil ifTrue:[device synchronizeOutput.
|
|
734 |
releaseActionBlock value].
|
|
735 |
active := false.
|
|
736 |
enteredFgColor notNil ifTrue:[
|
|
737 |
self drawWith:enteredFgColor and:enteredBgColor
|
|
738 |
]
|
|
739 |
]
|
|
740 |
]
|
|
741 |
!
|
|
742 |
|
|
743 |
pointerLeave:state
|
|
744 |
"redraw with normal colors if they differ from enteredColors"
|
|
745 |
|
|
746 |
pressed ifTrue:[
|
|
747 |
autoRepeat ifTrue:[
|
6
|
748 |
Processor removeTimedBlock:repeatBlock
|
0
|
749 |
]
|
|
750 |
] ifFalse:[
|
|
751 |
enabled ifTrue:[
|
|
752 |
enteredFgColor notNil ifTrue:[
|
|
753 |
(enteredFgColor ~~ fgColor
|
|
754 |
or:[enteredBgColor ~~ bgColor]) ifTrue:[
|
|
755 |
self drawWith:fgColor and:bgColor
|
|
756 |
]
|
|
757 |
]
|
|
758 |
]
|
|
759 |
]
|
|
760 |
!
|
|
761 |
|
|
762 |
pointerEnter:state x:x y:y
|
|
763 |
"redraw with enteredColors if they differ from the normal colors"
|
|
764 |
|
|
765 |
pressed ifTrue:[
|
|
766 |
enabled ifTrue:[
|
|
767 |
autoRepeat ifTrue:[
|
6
|
768 |
Processor addTimedBlock:repeatBlock after:initialDelay
|
0
|
769 |
]
|
|
770 |
]
|
|
771 |
] ifFalse:[
|
|
772 |
enabled ifTrue:[
|
|
773 |
enteredFgColor notNil ifTrue:[
|
|
774 |
(enteredFgColor ~~ fgColor
|
|
775 |
or:[enteredBgColor ~~ bgColor]) ifTrue:[
|
|
776 |
self drawWith:enteredFgColor and:enteredBgColor
|
|
777 |
]
|
|
778 |
]
|
|
779 |
]
|
|
780 |
]
|
|
781 |
!
|
|
782 |
|
|
783 |
repeat
|
|
784 |
"this is sent from the autorepeat-block, when the button has been pressed long
|
|
785 |
enough; it simulates a release-press, thereby retriggering action."
|
|
786 |
|
|
787 |
pressed ifTrue:[
|
|
788 |
enabled ifTrue:[
|
|
789 |
active ifFalse:[
|
|
790 |
active := true.
|
|
791 |
releaseActionBlock notNil ifTrue:[releaseActionBlock value].
|
|
792 |
pressActionBlock notNil ifTrue:[pressActionBlock value].
|
|
793 |
active := false.
|
|
794 |
device synchronizeOutput.
|
|
795 |
|
|
796 |
autoRepeat ifTrue:[
|
6
|
797 |
Processor addTimedBlock:repeatBlock after:repeatDelay
|
0
|
798 |
]
|
|
799 |
]
|
|
800 |
]
|
|
801 |
]
|
|
802 |
! !
|