author | ca |
Thu, 09 Nov 2000 16:26:41 +0100 | |
changeset 2308 | 49cfd84d2587 |
parent 2283 | 02cd600d410d |
child 2312 | 3fae46685629 |
permissions | -rw-r--r-- |
76 | 1 |
" |
2 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
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 |
||
2283 | 13 |
"{ Package: 'stx:libwidg' }" |
14 |
||
76 | 15 |
Controller subclass:#ButtonController |
262 | 16 |
instanceVariableNames:'enableChannel pressChannel releaseChannel pressed active entered |
220
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
17 |
isTriggerOnDown autoRepeat repeatBlock initialDelay repeatDelay |
1128 | 18 |
pressActionBlock releaseActionBlock isToggle isRadio buttonDown' |
262 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
category:'Interface-Support-Controllers' |
|
76 | 22 |
! |
23 |
||
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
24 |
!ButtonController class methodsFor:'documentation'! |
76 | 25 |
|
26 |
copyright |
|
27 |
" |
|
28 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
29 |
All Rights Reserved |
|
30 |
||
31 |
This software is furnished under a license and may be used |
|
32 |
only in accordance with the terms of that license and with the |
|
33 |
inclusion of the above copyright notice. This software may not |
|
34 |
be provided or otherwise made available to, or used by, any |
|
35 |
other person. No title to or ownership of the software is |
|
36 |
hereby transferred. |
|
37 |
" |
|
38 |
! |
|
39 |
||
40 |
documentation |
|
41 |
" |
|
42 |
ButtonControllers are used with buttons and handle all user interaction. |
|
43 |
These are automatically created when a Button is created, therefore no manual |
|
44 |
action is required for creation. |
|
133 | 45 |
In normal applications, you dont have to care for the controller; |
46 |
access to the controllers behavior is possible via messages to the button. |
|
125 | 47 |
(setting actions, controlling autorepeat etc.) |
76 | 48 |
|
972 | 49 |
A ButtonController supports 3 types of notifications: |
50 |
MVC change notification - as usual |
|
51 |
channel notifications - through the pressChannel/releaseChannels |
|
52 |
action callBack - through pressAction / releaseAction blocks. |
|
53 |
||
54 |
Notifications are made in the above order (i.e. an actionBlock sees the model |
|
55 |
already changed, if there is a model). |
|
56 |
||
57 |
Having multiple mechanisms here is both historic and to make the life |
|
58 |
of simple applications easier - most buttons dont need a model or notification |
|
59 |
channels and simply perform some action. |
|
60 |
In general: actionBlocks are useful, if there is a single subject which |
|
61 |
needs to be told about the press (i.e. actionButtons); |
|
62 |
models should be used when the button represents some value in some other |
|
63 |
object. |
|
64 |
Channels are much like the MVC approach, however, these are useful if |
|
65 |
press/release/label etc. may come from different objects, and a single |
|
66 |
(synthetic) model does not make sense or is not appropriate. |
|
67 |
||
68 |
Actually, the channels are the most general - and the other mechanism could |
|
69 |
(and will, maybe) based upon them; after all, an actionBlock is a channel, |
|
70 |
whcih sends #value to its block .... |
|
71 |
||
72 |
||
73 |
||
133 | 74 |
See examples in the Button class. |
75 |
||
582 | 76 |
[Instance variables:] |
76 | 77 |
|
133 | 78 |
enableChannel <ValueHolder pressing is allowed (default: true) |
582 | 79 |
on Boolean> |
125 | 80 |
|
76 | 81 |
pressed <Boolean> true if currently pressed (read-only) |
125 | 82 |
|
76 | 83 |
entered <Boolean> true if the cursor is currently in this view |
125 | 84 |
|
118 | 85 |
isTriggerOnDown <Boolean> controls if the action should be executed on |
582 | 86 |
press or on release (default: on release). |
125 | 87 |
|
88 |
isToggle <Boolean> controls if the button should show toggle |
|
582 | 89 |
behavior (as opposed to one-shot behavior) |
125 | 90 |
|
76 | 91 |
pressActionBlock <Block> block to evaluate when pressed (default: noop) |
125 | 92 |
|
76 | 93 |
releaseActionBlock <Block> block to evaluate when released (default: noop) |
125 | 94 |
|
76 | 95 |
autoRepeat <Boolean> auto-repeats when pressed long enough (default: false) |
125 | 96 |
|
76 | 97 |
initialDelay <Number> seconds till first auto-repeat (default: 0.2) |
125 | 98 |
|
76 | 99 |
repeatDelay <Number> seconds of repeat intervall (default: 0.025) |
125 | 100 |
|
76 | 101 |
repeatBlock <Block> block evaluated for auto-repeat (internal) |
125 | 102 |
|
76 | 103 |
active <Boolean> true during action evaluation (internal) |
582 | 104 |
|
105 |
[author:] |
|
106 |
Claus Gittinger |
|
76 | 107 |
" |
108 |
! ! |
|
109 |
||
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
110 |
!ButtonController class methodsFor:'defaults'! |
76 | 111 |
|
112 |
defaultInitialDelay |
|
113 |
"when autorepeat is enabled, and button is not released, |
|
114 |
start repeating after initialDelay seconds" |
|
115 |
||
116 |
^ 0.2 |
|
200 | 117 |
! |
118 |
||
119 |
defaultRepeatDelay |
|
120 |
"when autorepeat is enabled, and button is not released, |
|
121 |
repeat every repeatDelay seconds" |
|
122 |
||
123 |
^ 0.025 |
|
76 | 124 |
! ! |
125 |
||
200 | 126 |
!ButtonController methodsFor:'accessing-behavior'! |
127 |
||
128 |
action:aBlock |
|
129 |
"convenient method: depending on the setting the triggerOnDown flag, |
|
347 | 130 |
either set the press-action & clear any release-action or |
200 | 131 |
vice versa, set the release-action and clear the press-action." |
76 | 132 |
|
200 | 133 |
isTriggerOnDown ifTrue:[ |
347 | 134 |
releaseActionBlock := nil. |
135 |
pressActionBlock := aBlock |
|
200 | 136 |
] ifFalse:[ |
347 | 137 |
releaseActionBlock := aBlock. |
138 |
pressActionBlock := nil |
|
200 | 139 |
] |
347 | 140 |
|
141 |
"Modified: 9.2.1996 / 22:41:22 / cg" |
|
200 | 142 |
! |
118 | 143 |
|
200 | 144 |
autoRepeat |
347 | 145 |
"turn on autorepeat. OBSOLETE; use #autoRepeat:" |
200 | 146 |
|
347 | 147 |
self autoRepeat:true. |
148 |
||
149 |
"Modified: 9.2.1996 / 22:42:46 / cg" |
|
118 | 150 |
! |
151 |
||
200 | 152 |
autoRepeat:aBoolean |
153 |
"turn on/off autorepeat" |
|
154 |
||
155 |
autoRepeat := aBoolean. |
|
1147 | 156 |
repeatBlock := MessageSend receiver:self selector:#repeat. "/ [self repeat] |
121 | 157 |
|
200 | 158 |
"Modified: 5.9.1995 / 22:06:00 / claus" |
1147 | 159 |
"Modified: 20.3.1997 / 21:56:13 / cg" |
200 | 160 |
! |
161 |
||
976 | 162 |
beButton |
163 |
"make the receiver act like a button; thats the default, anyway" |
|
164 |
||
165 |
isTriggerOnDown := false. |
|
166 |
isToggle := false. |
|
167 |
isRadio := false. |
|
168 |
||
169 |
"Modified: 15.7.1996 / 13:42:15 / cg" |
|
170 |
"Created: 27.1.1997 / 13:30:11 / cg" |
|
171 |
! |
|
172 |
||
789 | 173 |
beRadioButton |
174 |
"make the receiver act like a radioButton; |
|
175 |
That is like a toggle, but do not allow turning myself off |
|
176 |
by buttonPress (instead, must be turned off by another button or programmatically)" |
|
177 |
||
178 |
isTriggerOnDown := true. |
|
179 |
isToggle := false. |
|
180 |
isRadio := true. |
|
181 |
||
182 |
"Created: 15.7.1996 / 13:42:06 / cg" |
|
183 |
! |
|
184 |
||
200 | 185 |
beToggle |
186 |
"make the receiver act like a toggle" |
|
187 |
||
188 |
isTriggerOnDown := true. |
|
789 | 189 |
isToggle := true. |
190 |
isRadio := false. |
|
191 |
||
192 |
"Modified: 15.7.1996 / 13:42:15 / cg" |
|
121 | 193 |
! |
76 | 194 |
|
200 | 195 |
beTriggerOnDown |
196 |
"make the receiver act on button press" |
|
197 |
||
198 |
isTriggerOnDown := true |
|
199 |
! |
|
200 |
||
201 |
beTriggerOnUp |
|
202 |
"make the receiver act on button release" |
|
121 | 203 |
|
200 | 204 |
isTriggerOnDown := false |
205 |
! |
|
206 |
||
207 |
disable |
|
1832 | 208 |
"alternative invokation; redirected to basic mechanism" |
200 | 209 |
|
1832 | 210 |
self enabled:false |
211 |
||
212 |
"Modified: / 30.3.1999 / 14:50:12 / stefan" |
|
121 | 213 |
! |
214 |
||
200 | 215 |
enable |
1832 | 216 |
"alternative invokation; redirected to basic mechanism" |
217 |
||
218 |
self enabled:true |
|
219 |
||
220 |
"Modified: / 30.3.1999 / 14:50:01 / stefan" |
|
221 |
! |
|
121 | 222 |
|
1832 | 223 |
enabled:aBoolean |
224 |
"disable the button" |
|
225 |
||
226 |
enableChannel value ~~ aBoolean ifTrue:[ |
|
227 |
enableChannel value:aBoolean. |
|
228 |
"/ view redraw - not needed; I listen to enableChannel |
|
200 | 229 |
] |
1832 | 230 |
|
231 |
"Created: / 30.3.1999 / 14:49:05 / stefan" |
|
76 | 232 |
! |
233 |
||
200 | 234 |
isTriggerOnDown |
235 |
"return true, if I trigger on press |
|
236 |
(in contrast to triggering on up, which is the default)" |
|
237 |
||
238 |
^ isTriggerOnDown |
|
239 |
! |
|
240 |
||
241 |
pressAction |
|
242 |
"return the pressAction; thats the block which gets evaluated |
|
243 |
when the button is pressed (if non-nil)" |
|
244 |
||
245 |
^ pressActionBlock |
|
246 |
! |
|
247 |
||
248 |
pressAction:aBlock |
|
249 |
"define the action to be performed on press" |
|
250 |
||
251 |
pressActionBlock := aBlock |
|
128 | 252 |
! |
253 |
||
200 | 254 |
releaseAction |
255 |
"return the releaseAction; thats the block which gets evaluated |
|
256 |
when the button is relreased (if non-nil)" |
|
257 |
||
258 |
^ releaseActionBlock |
|
259 |
! |
|
260 |
||
261 |
releaseAction:aBlock |
|
262 |
"define the action to be performed on release" |
|
263 |
||
264 |
releaseActionBlock := aBlock |
|
128 | 265 |
! |
266 |
||
200 | 267 |
triggerOnDown:aBoolean |
268 |
"set/clear the flag which controls if the action block is to be evaluated |
|
269 |
on press or on release. |
|
270 |
(see also ST-80 compatibility methods beTriggerOn*)" |
|
271 |
||
272 |
isTriggerOnDown := aBoolean |
|
128 | 273 |
! ! |
274 |
||
145 | 275 |
!ButtonController methodsFor:'accessing-channels'! |
276 |
||
277 |
enableChannel |
|
602 | 278 |
"return the valueHolder holding the enable boolean value" |
145 | 279 |
|
280 |
^ enableChannel |
|
602 | 281 |
|
282 |
"Modified: 30.4.1996 / 15:09:30 / cg" |
|
145 | 283 |
! |
284 |
||
285 |
enableChannel:aValueHolder |
|
286 |
"set the valueHolder, which holds the enable boolean value" |
|
287 |
||
162 | 288 |
|wasEnabled| |
289 |
||
145 | 290 |
enableChannel notNil ifTrue:[ |
1447 | 291 |
wasEnabled := enableChannel value. |
292 |
enableChannel retractInterestsFor:self. |
|
162 | 293 |
] ifFalse:[ |
1447 | 294 |
wasEnabled := true |
145 | 295 |
]. |
296 |
enableChannel := aValueHolder. |
|
1837
bc7c89c82edd
renambe #enableStateChange to #enableStateChanged
Claus Gittinger <cg@exept.de>
parents:
1832
diff
changeset
|
297 |
aValueHolder onChangeSend:#enableStateChanged to:self. |
1447 | 298 |
|
162 | 299 |
enableChannel value ~~ wasEnabled ifTrue:[ |
1837
bc7c89c82edd
renambe #enableStateChange to #enableStateChanged
Claus Gittinger <cg@exept.de>
parents:
1832
diff
changeset
|
300 |
self enableStateChanged |
1447 | 301 |
|
145 | 302 |
] |
162 | 303 |
|
304 |
"Modified: 17.9.1995 / 19:41:18 / claus" |
|
145 | 305 |
! |
306 |
||
307 |
pressChannel:aChannel |
|
308 |
pressChannel := aChannel |
|
309 |
! |
|
310 |
||
311 |
releaseChannel:aChannel |
|
312 |
releaseChannel := aChannel |
|
313 |
! ! |
|
314 |
||
200 | 315 |
!ButtonController methodsFor:'accessing-state'! |
76 | 316 |
|
200 | 317 |
active |
318 |
"return true, if I am active; |
|
319 |
that is: currently performing my action. |
|
320 |
This query can be used to avoid multiple redraws." |
|
76 | 321 |
|
200 | 322 |
^ active |
128 | 323 |
! |
324 |
||
200 | 325 |
active:aBoolean |
326 |
active := aBoolean |
|
76 | 327 |
! |
328 |
||
200 | 329 |
enabled |
330 |
"return true, if I am enabled" |
|
128 | 331 |
|
200 | 332 |
^ enableChannel value |
76 | 333 |
! |
334 |
||
200 | 335 |
entered |
336 |
"return true, if the mouse pointer is currently in my view" |
|
155 | 337 |
|
200 | 338 |
^ entered |
339 |
! |
|
155 | 340 |
|
200 | 341 |
entered:aBoolean |
342 |
entered := aBoolean |
|
155 | 343 |
! |
344 |
||
200 | 345 |
pressed |
346 |
"return true, if I am pressed" |
|
76 | 347 |
|
200 | 348 |
^ pressed |
76 | 349 |
! |
350 |
||
200 | 351 |
pressed:aBoolean |
352 |
pressed ~~ aBoolean ifTrue:[ |
|
353 |
pressed := aBoolean. |
|
354 |
self performAction. |
|
118 | 355 |
]. |
356 |
! |
|
357 |
||
200 | 358 |
setPressed:aBoolean |
359 |
pressed := aBoolean. |
|
121 | 360 |
|
200 | 361 |
"Created: 14.11.1995 / 21:37:08 / cg" |
266 | 362 |
! |
363 |
||
364 |
toggle |
|
365 |
"toggle and perform the action" |
|
366 |
||
367 |
enableChannel value ifTrue:[ |
|
368 |
self toggleNoAction. |
|
369 |
self performAction. |
|
370 |
view changed:#toggle with:pressed |
|
371 |
] |
|
372 |
! |
|
373 |
||
374 |
toggleNoAction |
|
375 |
"toggle, but do NOT perform any action" |
|
376 |
||
377 |
pressed ifTrue:[ |
|
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
378 |
view turnOff. |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
379 |
pressed := false. |
266 | 380 |
] ifFalse:[ |
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
381 |
view turnOn. |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
382 |
pressed := true. |
266 | 383 |
]. |
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
384 |
view repairDamage |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
385 |
|
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
386 |
"Modified: / 4.3.1998 / 13:35:12 / cg" |
76 | 387 |
! ! |
388 |
||
389 |
!ButtonController methodsFor:'event handling'! |
|
390 |
||
1266 | 391 |
buttonMotion:state x:x y:y |
392 |
(x >= 0 and:[x < view width |
|
393 |
and:[y >= 0 and:[y < view height]]]) ifTrue:[ |
|
394 |
entered ifFalse:[ |
|
395 |
self pointerEnter:state x:x y:y |
|
396 |
] |
|
397 |
] ifFalse:[ |
|
398 |
entered ifTrue:[ |
|
399 |
self pointerLeave:state |
|
400 |
] |
|
401 |
] |
|
402 |
! |
|
403 |
||
200 | 404 |
buttonMultiPress:button x:x y:y |
405 |
^ self buttonPress:button x:x y:y |
|
406 |
! |
|
407 |
||
76 | 408 |
buttonPress:button x:x y:y |
1710 | 409 |
|wg| |
410 |
||
76 | 411 |
(button == 1 or:[button == #select]) ifFalse:[ |
789 | 412 |
^ super buttonPress:button x:x y:y |
76 | 413 |
]. |
414 |
||
1680
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
415 |
(view styleSheet at:#'focus.takeOnClick' default:false) ifTrue:[ |
1710 | 416 |
"/ mhmh - how can this ever be nil ? |
417 |
(wg := view windowGroup) notNil ifTrue:[ |
|
418 |
wg focusToView:view |
|
419 |
] |
|
1680
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
420 |
]. |
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
421 |
|
1128 | 422 |
buttonDown := true. |
423 |
||
133 | 424 |
enableChannel value ifTrue:[ |
789 | 425 |
isToggle ifTrue:[ |
426 |
self toggle. |
|
427 |
^ self |
|
428 |
]. |
|
429 |
isRadio ifTrue:[ |
|
430 |
pressed ifFalse:[ |
|
431 |
self toggle |
|
432 |
]. |
|
433 |
^ self |
|
434 |
]. |
|
118 | 435 |
|
789 | 436 |
pressed ifFalse:[ |
437 |
pressed := true. |
|
438 |
view showActive. |
|
76 | 439 |
|
789 | 440 |
(pressActionBlock notNil or:[model notNil]) ifTrue:[ |
441 |
" |
|
442 |
force output - so that button is drawn correctly in case |
|
443 |
of any long-computation (at high priority) |
|
444 |
" |
|
445 |
view flush. |
|
446 |
]. |
|
76 | 447 |
|
789 | 448 |
self performAction. |
2004
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
449 |
view flush. |
76 | 450 |
|
789 | 451 |
autoRepeat ifTrue:[ |
452 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
|
453 |
] |
|
454 |
] |
|
76 | 455 |
] |
262 | 456 |
|
1710 | 457 |
"Modified: / 26.10.1998 / 20:23:07 / cg" |
76 | 458 |
! |
459 |
||
460 |
buttonRelease:button x:x y:y |
|
461 |
"button was released - if enabled, perform releaseaction" |
|
462 |
||
463 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 464 |
^ super buttonRelease:button x:x y:y |
76 | 465 |
]. |
118 | 466 |
|
1128 | 467 |
buttonDown := false. |
468 |
||
789 | 469 |
(isToggle or:[isRadio]) ifTrue:[ |
470 |
^ self |
|
118 | 471 |
]. |
472 |
||
76 | 473 |
pressed ifTrue:[ |
789 | 474 |
autoRepeat ifTrue:[ |
475 |
Processor removeTimedBlock:repeatBlock |
|
476 |
]. |
|
477 |
pressed := false. |
|
478 |
view showPassive. |
|
76 | 479 |
|
789 | 480 |
enableChannel value ifTrue:[ |
481 |
" |
|
482 |
only perform action if released within myself |
|
483 |
" |
|
484 |
((x >= 0) |
|
485 |
and:[x <= view width |
|
486 |
and:[y >= 0 |
|
487 |
and:[y <= view height]]]) ifTrue:[ |
|
488 |
(releaseActionBlock notNil or:[model notNil]) ifTrue:[ |
|
489 |
" |
|
490 |
force output - so that button is drawn correctly in case |
|
491 |
of any long-computation (at high priority) |
|
492 |
" |
|
493 |
view flush. |
|
494 |
]. |
|
76 | 495 |
|
789 | 496 |
self performAction. |
497 |
] |
|
498 |
] |
|
76 | 499 |
] |
262 | 500 |
|
1128 | 501 |
"Modified: 8.3.1997 / 00:04:19 / cg" |
76 | 502 |
! |
503 |
||
1837
bc7c89c82edd
renambe #enableStateChange to #enableStateChanged
Claus Gittinger <cg@exept.de>
parents:
1832
diff
changeset
|
504 |
enableStateChanged |
200 | 505 |
"this is sent, whenever the enable value has changed" |
76 | 506 |
|
1779
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
507 |
view notNil ifTrue:[ |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
508 |
view invalidate "redraw". |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
509 |
|
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
510 |
enableChannel value ifTrue:[ |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
511 |
view cursor:Cursor hand |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
512 |
] ifFalse:[ |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
513 |
view cursor:Cursor normal |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
514 |
]. |
cd68cec6ebe8
change the cursor for disabled buttons.
Claus Gittinger <cg@exept.de>
parents:
1739
diff
changeset
|
515 |
] |
200 | 516 |
|
517 |
"Modified: 17.9.1995 / 19:55:52 / claus" |
|
1191
98386e90229f
use asynchronous #invalidate when enable-state changes.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
518 |
"Modified: 17.4.1997 / 01:53:14 / cg" |
76 | 519 |
! |
520 |
||
200 | 521 |
keyPress:key x:x y:y |
522 |
"trigger on Return and space, if I am the focusView of my group |
|
523 |
(i.e. if I got an explicit focus)" |
|
121 | 524 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
525 |
view hasFocus ifTrue:[ |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
526 |
((key == Character space) |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
527 |
or:[key == #Return]) ifTrue:[ |
349
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
528 |
"just simulate a buttonPress/release here." |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
529 |
self buttonPress:1 x:0 y:0. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
530 |
self buttonRelease:1 x:0 y:0. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
531 |
^ self. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
532 |
] |
200 | 533 |
]. |
534 |
view keyPress:key x:x y:y |
|
349
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
535 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
536 |
"Modified: 26.2.1997 / 00:50:25 / cg" |
121 | 537 |
! |
538 |
||
539 |
performAction |
|
146 | 540 |
|action value| |
133 | 541 |
|
789 | 542 |
(isToggle or:[isRadio]) ifTrue:[ |
543 |
value := pressed |
|
133 | 544 |
] ifFalse:[ |
789 | 545 |
value := true |
133 | 546 |
]. |
76 | 547 |
|
125 | 548 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
549 |
ST-80 style model notification ... |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
550 |
this updates the model (typically, a ValueHolder) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
551 |
" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
552 |
(isToggle |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
553 |
or:[(isTriggerOnDown and:[pressed]) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
554 |
or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
555 |
"the ST-80 way of doing things" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
556 |
view notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
557 |
active := true. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
558 |
view sendChangeMessageWith:value. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
559 |
active := false. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
560 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
561 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
562 |
|
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
563 |
" |
145 | 564 |
ST/X style actionBlock evaluation & channel notification ... |
125 | 565 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
566 |
pressChannel notNil ifTrue:[ |
1095 | 567 |
pressed ifTrue:[ |
568 |
pressChannel value:true |
|
569 |
] |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
570 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
571 |
releaseChannel notNil ifTrue:[ |
1095 | 572 |
pressed ifFalse:[ |
573 |
releaseChannel value:true |
|
574 |
] |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
575 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
576 |
|
76 | 577 |
pressed ifTrue:[ |
789 | 578 |
action := pressActionBlock. |
121 | 579 |
] ifFalse:[ |
789 | 580 |
action := releaseActionBlock. |
121 | 581 |
]. |
125 | 582 |
action notNil ifTrue:[ |
789 | 583 |
active := true. |
584 |
action numArgs == 0 ifTrue:[ |
|
585 |
action value |
|
586 |
] ifFalse:[ |
|
587 |
action value:value |
|
588 |
]. |
|
589 |
active := false. |
|
125 | 590 |
]. |
76 | 591 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
592 |
"Modified: 24.1.1997 / 11:38:20 / cg" |
76 | 593 |
! |
594 |
||
2308 | 595 |
performShortcutAction |
596 |
enableChannel value ifTrue:[ |
|
597 |
isToggle ifTrue:[ |
|
598 |
self toggle. |
|
599 |
^ self |
|
600 |
]. |
|
601 |
isRadio ifTrue:[ |
|
602 |
pressed ifFalse:[ |
|
603 |
self toggle |
|
604 |
]. |
|
605 |
^ self |
|
606 |
]. |
|
607 |
||
608 |
self performAction. |
|
609 |
]! |
|
610 |
||
200 | 611 |
pointerEnter:state x:x y:y |
612 |
"mouse pointer entered my view. |
|
613 |
Redraw with enteredColors if they differ from the normal colors" |
|
614 |
||
615 |
entered := true. |
|
616 |
enableChannel value ifTrue:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
617 |
pressed ifTrue:[ |
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
618 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
619 |
view showActive. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
620 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
621 |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
622 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
623 |
reentered after a leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
624 |
restart autorepeating and/or if I am a button with |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
625 |
triggerOnDown, show active again. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
626 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
627 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
628 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
629 |
]. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
630 |
] ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
631 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
632 |
] |
200 | 633 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
634 |
|
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
635 |
"Modified: 26.5.1996 / 18:09:06 / cg" |
76 | 636 |
! |
637 |
||
200 | 638 |
pointerLeave:state |
639 |
"mouse pointer left my view. |
|
640 |
Redraw with normal colors if they differ from enteredColors" |
|
76 | 641 |
|
200 | 642 |
entered := false. |
643 |
pressed ifTrue:[ |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
644 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
645 |
view showPassive. |
1168
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
646 |
] ifTrue:[ |
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
647 |
view invalidate |
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
648 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
649 |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
650 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
651 |
leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
652 |
stop autorepeating and/or if I am a button with |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
653 |
action on release, show passive |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
654 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
655 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
656 |
Processor removeTimedBlock:repeatBlock |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
657 |
]. |
200 | 658 |
] ifFalse:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
659 |
enableChannel value ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
660 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
661 |
] |
200 | 662 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
663 |
|
1168
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
664 |
"Modified: 1.4.1997 / 13:27:32 / cg" |
76 | 665 |
! |
666 |
||
121 | 667 |
repeat |
668 |
"this is sent from the autorepeat-block, when the button has been pressed long |
|
669 |
enough; it simulates a release-press, by evaluating both release |
|
670 |
and press actions." |
|
76 | 671 |
|
220
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
672 |
|dly| |
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
673 |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
674 |
(pressed and:[entered]) ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
675 |
enableChannel value ifTrue:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
676 |
active ifFalse:[ |
2004
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
677 |
"/ dont repeat, if a release is pending ... |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
678 |
"/ (must check this, because the release event could |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
679 |
"/ stick in the queue, since exposes are handled first, |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
680 |
"/ which could lead to event processing to never happen) |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
681 |
(view sensor hasButtonReleaseEventFor:view) ifFalse:[ |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
682 |
self performAction. |
121 | 683 |
|
2004
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
684 |
autoRepeat ifTrue:[ |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
685 |
view graphicsDevice shiftDown ifTrue:[ |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
686 |
dly := repeatDelay / 4. |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
687 |
] ifFalse:[ |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
688 |
dly := repeatDelay |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
689 |
]. |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
690 |
Processor addTimedBlock:repeatBlock afterSeconds:dly |
0f035d5deb50
care for slow scrollers (lots of exposes) when autorepeating
Claus Gittinger <cg@exept.de>
parents:
1837
diff
changeset
|
691 |
] |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
692 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
693 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
694 |
] |
76 | 695 |
] |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
696 |
|
704 | 697 |
"Modified: 28.5.1996 / 20:21:24 / cg" |
1783 | 698 |
! |
699 |
||
700 |
requestAutoAccept |
|
701 |
"request autoAccept from a keyboardProcessor. |
|
702 |
AutoAccept is allowed, if I am enabled and a default buttons controller" |
|
703 |
||
2283 | 704 |
^ true. |
705 |
"/ ^ self enabled and:[view isDefault] |
|
76 | 706 |
! ! |
121 | 707 |
|
708 |
!ButtonController methodsFor:'initialization'! |
|
709 |
||
1266 | 710 |
controlInitialize |
711 |
active := false. |
|
712 |
entered := false. |
|
713 |
||
714 |
"Created: 24.7.1997 / 14:58:28 / cg" |
|
715 |
"Modified: 24.7.1997 / 14:59:06 / cg" |
|
716 |
! |
|
717 |
||
121 | 718 |
initialize |
719 |
super initialize. |
|
720 |
||
1540 | 721 |
enableChannel := ValueHolder with:true. |
1837
bc7c89c82edd
renambe #enableStateChange to #enableStateChanged
Claus Gittinger <cg@exept.de>
parents:
1832
diff
changeset
|
722 |
enableChannel onChangeSend:#enableStateChanged to:self. |
133 | 723 |
|
121 | 724 |
active := false. |
725 |
pressed := false. |
|
726 |
entered := false. |
|
727 |
autoRepeat := false. |
|
728 |
initialDelay := self class defaultInitialDelay. |
|
729 |
repeatDelay := self class defaultRepeatDelay. |
|
730 |
isTriggerOnDown := false. |
|
789 | 731 |
isToggle := isRadio := false. |
732 |
||
1540 | 733 |
"Modified: / 21.5.1998 / 03:07:02 / cg" |
1447 | 734 |
! |
735 |
||
1739 | 736 |
reinitialize |
737 |
active := false. |
|
2166
b6f4fb01cdeb
do not clobber pressed state in reinitialize
Claus Gittinger <cg@exept.de>
parents:
2004
diff
changeset
|
738 |
(isToggle or:[isRadio]) ifFalse:[ |
b6f4fb01cdeb
do not clobber pressed state in reinitialize
Claus Gittinger <cg@exept.de>
parents:
2004
diff
changeset
|
739 |
pressed := false. |
b6f4fb01cdeb
do not clobber pressed state in reinitialize
Claus Gittinger <cg@exept.de>
parents:
2004
diff
changeset
|
740 |
]. |
1739 | 741 |
entered := false. |
2166
b6f4fb01cdeb
do not clobber pressed state in reinitialize
Claus Gittinger <cg@exept.de>
parents:
2004
diff
changeset
|
742 |
|
b6f4fb01cdeb
do not clobber pressed state in reinitialize
Claus Gittinger <cg@exept.de>
parents:
2004
diff
changeset
|
743 |
"Modified: / 1.3.2000 / 15:17:10 / cg" |
1739 | 744 |
! |
745 |
||
1447 | 746 |
release |
747 |
"release all dependencies" |
|
748 |
||
749 |
enableChannel notNil ifTrue:[ |
|
750 |
enableChannel retractInterestsFor:self. |
|
751 |
enableChannel := nil. |
|
752 |
]. |
|
753 |
super release |
|
121 | 754 |
! ! |
200 | 755 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
756 |
!ButtonController class methodsFor:'documentation'! |
203 | 757 |
|
758 |
version |
|
2308 | 759 |
^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.62 2000-11-09 15:26:41 ca Exp $' |
203 | 760 |
! ! |