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