author | Claus Gittinger <cg@exept.de> |
Fri, 18 Sep 1998 18:02:39 +0200 | |
changeset 1680 | 4c01dc0d5f1c |
parent 1540 | 8dffe3f0de97 |
child 1710 | 6afc1887a2a3 |
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 |
|
206 |
"disable the button" |
|
207 |
||
208 |
enableChannel value ifTrue:[ |
|
209 |
enableChannel value:false. |
|
210 |
"/ view redraw - not needed; I listen to enableChannel |
|
211 |
] |
|
121 | 212 |
! |
213 |
||
200 | 214 |
enable |
215 |
"enable the button" |
|
121 | 216 |
|
200 | 217 |
enableChannel value ifFalse:[ |
218 |
enableChannel value:true. |
|
219 |
"/ view redraw - not needed; I listen to enableChannel |
|
220 |
] |
|
76 | 221 |
! |
222 |
||
200 | 223 |
isTriggerOnDown |
224 |
"return true, if I trigger on press |
|
225 |
(in contrast to triggering on up, which is the default)" |
|
226 |
||
227 |
^ isTriggerOnDown |
|
228 |
! |
|
229 |
||
230 |
pressAction |
|
231 |
"return the pressAction; thats the block which gets evaluated |
|
232 |
when the button is pressed (if non-nil)" |
|
233 |
||
234 |
^ pressActionBlock |
|
235 |
! |
|
236 |
||
237 |
pressAction:aBlock |
|
238 |
"define the action to be performed on press" |
|
239 |
||
240 |
pressActionBlock := aBlock |
|
128 | 241 |
! |
242 |
||
200 | 243 |
releaseAction |
244 |
"return the releaseAction; thats the block which gets evaluated |
|
245 |
when the button is relreased (if non-nil)" |
|
246 |
||
247 |
^ releaseActionBlock |
|
248 |
! |
|
249 |
||
250 |
releaseAction:aBlock |
|
251 |
"define the action to be performed on release" |
|
252 |
||
253 |
releaseActionBlock := aBlock |
|
128 | 254 |
! |
255 |
||
200 | 256 |
triggerOnDown:aBoolean |
257 |
"set/clear the flag which controls if the action block is to be evaluated |
|
258 |
on press or on release. |
|
259 |
(see also ST-80 compatibility methods beTriggerOn*)" |
|
260 |
||
261 |
isTriggerOnDown := aBoolean |
|
128 | 262 |
! ! |
263 |
||
145 | 264 |
!ButtonController methodsFor:'accessing-channels'! |
265 |
||
266 |
enableChannel |
|
602 | 267 |
"return the valueHolder holding the enable boolean value" |
145 | 268 |
|
269 |
^ enableChannel |
|
602 | 270 |
|
271 |
"Modified: 30.4.1996 / 15:09:30 / cg" |
|
145 | 272 |
! |
273 |
||
274 |
enableChannel:aValueHolder |
|
275 |
"set the valueHolder, which holds the enable boolean value" |
|
276 |
||
162 | 277 |
|wasEnabled| |
278 |
||
145 | 279 |
enableChannel notNil ifTrue:[ |
1447 | 280 |
wasEnabled := enableChannel value. |
281 |
enableChannel retractInterestsFor:self. |
|
162 | 282 |
] ifFalse:[ |
1447 | 283 |
wasEnabled := true |
145 | 284 |
]. |
285 |
enableChannel := aValueHolder. |
|
286 |
aValueHolder onChangeSend:#enableStateChange to:self. |
|
1447 | 287 |
|
162 | 288 |
enableChannel value ~~ wasEnabled ifTrue:[ |
1447 | 289 |
self enableStateChange |
290 |
||
145 | 291 |
] |
162 | 292 |
|
293 |
"Modified: 17.9.1995 / 19:41:18 / claus" |
|
145 | 294 |
! |
295 |
||
296 |
pressChannel:aChannel |
|
297 |
pressChannel := aChannel |
|
298 |
! |
|
299 |
||
300 |
releaseChannel:aChannel |
|
301 |
releaseChannel := aChannel |
|
302 |
! ! |
|
303 |
||
200 | 304 |
!ButtonController methodsFor:'accessing-state'! |
76 | 305 |
|
200 | 306 |
active |
307 |
"return true, if I am active; |
|
308 |
that is: currently performing my action. |
|
309 |
This query can be used to avoid multiple redraws." |
|
76 | 310 |
|
200 | 311 |
^ active |
128 | 312 |
! |
313 |
||
200 | 314 |
active:aBoolean |
315 |
active := aBoolean |
|
76 | 316 |
! |
317 |
||
200 | 318 |
enabled |
319 |
"return true, if I am enabled" |
|
128 | 320 |
|
200 | 321 |
^ enableChannel value |
76 | 322 |
! |
323 |
||
200 | 324 |
entered |
325 |
"return true, if the mouse pointer is currently in my view" |
|
155 | 326 |
|
200 | 327 |
^ entered |
328 |
! |
|
155 | 329 |
|
200 | 330 |
entered:aBoolean |
331 |
entered := aBoolean |
|
155 | 332 |
! |
333 |
||
200 | 334 |
pressed |
335 |
"return true, if I am pressed" |
|
76 | 336 |
|
200 | 337 |
^ pressed |
76 | 338 |
! |
339 |
||
200 | 340 |
pressed:aBoolean |
341 |
pressed ~~ aBoolean ifTrue:[ |
|
342 |
pressed := aBoolean. |
|
343 |
self performAction. |
|
118 | 344 |
]. |
345 |
! |
|
346 |
||
200 | 347 |
setPressed:aBoolean |
348 |
pressed := aBoolean. |
|
121 | 349 |
|
200 | 350 |
"Created: 14.11.1995 / 21:37:08 / cg" |
266 | 351 |
! |
352 |
||
353 |
toggle |
|
354 |
"toggle and perform the action" |
|
355 |
||
356 |
enableChannel value ifTrue:[ |
|
357 |
self toggleNoAction. |
|
358 |
self performAction. |
|
359 |
view changed:#toggle with:pressed |
|
360 |
] |
|
361 |
! |
|
362 |
||
363 |
toggleNoAction |
|
364 |
"toggle, but do NOT perform any action" |
|
365 |
||
366 |
pressed ifTrue:[ |
|
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
367 |
view turnOff. |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
368 |
pressed := false. |
266 | 369 |
] ifFalse:[ |
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
370 |
view turnOn. |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
371 |
pressed := true. |
266 | 372 |
]. |
1463
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
373 |
view repairDamage |
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
374 |
|
5eaeef9cb688
redraw early after a toggle (before telling the model).
Claus Gittinger <cg@exept.de>
parents:
1447
diff
changeset
|
375 |
"Modified: / 4.3.1998 / 13:35:12 / cg" |
76 | 376 |
! ! |
377 |
||
378 |
!ButtonController methodsFor:'event handling'! |
|
379 |
||
1266 | 380 |
buttonMotion:state x:x y:y |
381 |
(x >= 0 and:[x < view width |
|
382 |
and:[y >= 0 and:[y < view height]]]) ifTrue:[ |
|
383 |
entered ifFalse:[ |
|
384 |
self pointerEnter:state x:x y:y |
|
385 |
] |
|
386 |
] ifFalse:[ |
|
387 |
entered ifTrue:[ |
|
388 |
self pointerLeave:state |
|
389 |
] |
|
390 |
] |
|
391 |
! |
|
392 |
||
200 | 393 |
buttonMultiPress:button x:x y:y |
394 |
^ self buttonPress:button x:x y:y |
|
395 |
! |
|
396 |
||
76 | 397 |
buttonPress:button x:x y:y |
398 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 399 |
^ super buttonPress:button x:x y:y |
76 | 400 |
]. |
401 |
||
1680
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
402 |
(view styleSheet at:#'focus.takeOnClick' default:false) ifTrue:[ |
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
403 |
view windowGroup focusToView:view |
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
404 |
]. |
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
405 |
|
1128 | 406 |
buttonDown := true. |
407 |
||
133 | 408 |
enableChannel value ifTrue:[ |
789 | 409 |
isToggle ifTrue:[ |
410 |
self toggle. |
|
411 |
^ self |
|
412 |
]. |
|
413 |
isRadio ifTrue:[ |
|
414 |
pressed ifFalse:[ |
|
415 |
self toggle |
|
416 |
]. |
|
417 |
^ self |
|
418 |
]. |
|
118 | 419 |
|
789 | 420 |
pressed ifFalse:[ |
421 |
pressed := true. |
|
422 |
view showActive. |
|
76 | 423 |
|
789 | 424 |
(pressActionBlock notNil or:[model notNil]) ifTrue:[ |
425 |
" |
|
426 |
force output - so that button is drawn correctly in case |
|
427 |
of any long-computation (at high priority) |
|
428 |
" |
|
429 |
view flush. |
|
430 |
]. |
|
76 | 431 |
|
789 | 432 |
self performAction. |
76 | 433 |
|
789 | 434 |
autoRepeat ifTrue:[ |
435 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
|
436 |
] |
|
437 |
] |
|
76 | 438 |
] |
262 | 439 |
|
1680
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
440 |
"Modified: / 18.9.1998 / 17:18:53 / cg" |
76 | 441 |
! |
442 |
||
443 |
buttonRelease:button x:x y:y |
|
444 |
"button was released - if enabled, perform releaseaction" |
|
445 |
||
446 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 447 |
^ super buttonRelease:button x:x y:y |
76 | 448 |
]. |
118 | 449 |
|
1128 | 450 |
buttonDown := false. |
451 |
||
789 | 452 |
(isToggle or:[isRadio]) ifTrue:[ |
453 |
^ self |
|
118 | 454 |
]. |
455 |
||
76 | 456 |
pressed ifTrue:[ |
789 | 457 |
autoRepeat ifTrue:[ |
458 |
Processor removeTimedBlock:repeatBlock |
|
459 |
]. |
|
460 |
pressed := false. |
|
461 |
view showPassive. |
|
76 | 462 |
|
789 | 463 |
enableChannel value ifTrue:[ |
464 |
" |
|
465 |
only perform action if released within myself |
|
466 |
" |
|
467 |
((x >= 0) |
|
468 |
and:[x <= view width |
|
469 |
and:[y >= 0 |
|
470 |
and:[y <= view height]]]) ifTrue:[ |
|
471 |
(releaseActionBlock notNil or:[model notNil]) ifTrue:[ |
|
472 |
" |
|
473 |
force output - so that button is drawn correctly in case |
|
474 |
of any long-computation (at high priority) |
|
475 |
" |
|
476 |
view flush. |
|
477 |
]. |
|
76 | 478 |
|
789 | 479 |
self performAction. |
480 |
] |
|
481 |
] |
|
76 | 482 |
] |
262 | 483 |
|
1128 | 484 |
"Modified: 8.3.1997 / 00:04:19 / cg" |
76 | 485 |
! |
486 |
||
200 | 487 |
enableStateChange |
488 |
"this is sent, whenever the enable value has changed" |
|
76 | 489 |
|
1191
98386e90229f
use asynchronous #invalidate when enable-state changes.
Claus Gittinger <cg@exept.de>
parents:
1168
diff
changeset
|
490 |
view notNil ifTrue:[view invalidate "redraw"] |
200 | 491 |
|
492 |
"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
|
493 |
"Modified: 17.4.1997 / 01:53:14 / cg" |
76 | 494 |
! |
495 |
||
200 | 496 |
keyPress:key x:x y:y |
497 |
"trigger on Return and space, if I am the focusView of my group |
|
498 |
(i.e. if I got an explicit focus)" |
|
121 | 499 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
500 |
view hasFocus ifTrue:[ |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
501 |
((key == Character space) |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
502 |
or:[key == #Return]) ifTrue:[ |
349
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
503 |
"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
|
504 |
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
|
505 |
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
|
506 |
^ self. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
507 |
] |
200 | 508 |
]. |
509 |
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
|
510 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
511 |
"Modified: 26.2.1997 / 00:50:25 / cg" |
121 | 512 |
! |
513 |
||
514 |
performAction |
|
146 | 515 |
|action value| |
133 | 516 |
|
789 | 517 |
(isToggle or:[isRadio]) ifTrue:[ |
518 |
value := pressed |
|
133 | 519 |
] ifFalse:[ |
789 | 520 |
value := true |
133 | 521 |
]. |
76 | 522 |
|
125 | 523 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
524 |
ST-80 style model notification ... |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
525 |
this updates the model (typically, a ValueHolder) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
526 |
" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
527 |
(isToggle |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
528 |
or:[(isTriggerOnDown and:[pressed]) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
529 |
or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
530 |
"the ST-80 way of doing things" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
531 |
view notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
532 |
active := true. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
533 |
view sendChangeMessageWith:value. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
534 |
active := false. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
535 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
536 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
537 |
|
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
538 |
" |
145 | 539 |
ST/X style actionBlock evaluation & channel notification ... |
125 | 540 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
541 |
pressChannel notNil ifTrue:[ |
1095 | 542 |
pressed ifTrue:[ |
543 |
pressChannel value:true |
|
544 |
] |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
545 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
546 |
releaseChannel notNil ifTrue:[ |
1095 | 547 |
pressed ifFalse:[ |
548 |
releaseChannel value:true |
|
549 |
] |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
550 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
551 |
|
76 | 552 |
pressed ifTrue:[ |
789 | 553 |
action := pressActionBlock. |
121 | 554 |
] ifFalse:[ |
789 | 555 |
action := releaseActionBlock. |
121 | 556 |
]. |
125 | 557 |
action notNil ifTrue:[ |
789 | 558 |
active := true. |
559 |
action numArgs == 0 ifTrue:[ |
|
560 |
action value |
|
561 |
] ifFalse:[ |
|
562 |
action value:value |
|
563 |
]. |
|
564 |
active := false. |
|
125 | 565 |
]. |
76 | 566 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
567 |
"Modified: 24.1.1997 / 11:38:20 / cg" |
76 | 568 |
! |
569 |
||
200 | 570 |
pointerEnter:state x:x y:y |
571 |
"mouse pointer entered my view. |
|
572 |
Redraw with enteredColors if they differ from the normal colors" |
|
573 |
||
574 |
entered := true. |
|
575 |
enableChannel value ifTrue:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
576 |
pressed ifTrue:[ |
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
577 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
578 |
view showActive. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
579 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
580 |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
581 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
582 |
reentered after a leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
583 |
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
|
584 |
triggerOnDown, show active again. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
585 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
586 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
587 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
588 |
]. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
589 |
] ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
590 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
591 |
] |
200 | 592 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
593 |
|
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
594 |
"Modified: 26.5.1996 / 18:09:06 / cg" |
76 | 595 |
! |
596 |
||
200 | 597 |
pointerLeave:state |
598 |
"mouse pointer left my view. |
|
599 |
Redraw with normal colors if they differ from enteredColors" |
|
76 | 600 |
|
200 | 601 |
entered := false. |
602 |
pressed ifTrue:[ |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
603 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
604 |
view showPassive. |
1168
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
605 |
] ifTrue:[ |
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
606 |
view invalidate |
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
607 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
608 |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
609 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
610 |
leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
611 |
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
|
612 |
action on release, show passive |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
613 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
614 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
615 |
Processor removeTimedBlock:repeatBlock |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
616 |
]. |
200 | 617 |
] ifFalse:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
618 |
enableChannel value ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
619 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
620 |
] |
200 | 621 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
622 |
|
1168
231969f02a78
also invalidate in leave if not pressed
Claus Gittinger <cg@exept.de>
parents:
1147
diff
changeset
|
623 |
"Modified: 1.4.1997 / 13:27:32 / cg" |
76 | 624 |
! |
625 |
||
121 | 626 |
repeat |
627 |
"this is sent from the autorepeat-block, when the button has been pressed long |
|
628 |
enough; it simulates a release-press, by evaluating both release |
|
629 |
and press actions." |
|
76 | 630 |
|
220
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
631 |
|dly| |
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
632 |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
633 |
(pressed and:[entered]) ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
634 |
enableChannel value ifTrue:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
635 |
active ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
636 |
self performAction. |
121 | 637 |
|
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
638 |
autoRepeat ifTrue:[ |
704 | 639 |
view graphicsDevice shiftDown ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
640 |
dly := repeatDelay / 4. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
641 |
] ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
642 |
dly := repeatDelay |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
643 |
]. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
644 |
Processor addTimedBlock:repeatBlock afterSeconds:dly |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
645 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
646 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
647 |
] |
76 | 648 |
] |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
649 |
|
704 | 650 |
"Modified: 28.5.1996 / 20:21:24 / cg" |
76 | 651 |
! ! |
121 | 652 |
|
653 |
!ButtonController methodsFor:'initialization'! |
|
654 |
||
1266 | 655 |
controlInitialize |
656 |
active := false. |
|
657 |
entered := false. |
|
658 |
||
659 |
"Created: 24.7.1997 / 14:58:28 / cg" |
|
660 |
"Modified: 24.7.1997 / 14:59:06 / cg" |
|
661 |
! |
|
662 |
||
121 | 663 |
initialize |
664 |
super initialize. |
|
665 |
||
1540 | 666 |
enableChannel := ValueHolder with:true. |
266 | 667 |
enableChannel onChangeSend:#enableStateChange to:self. |
133 | 668 |
|
121 | 669 |
active := false. |
670 |
pressed := false. |
|
671 |
entered := false. |
|
672 |
autoRepeat := false. |
|
673 |
initialDelay := self class defaultInitialDelay. |
|
674 |
repeatDelay := self class defaultRepeatDelay. |
|
675 |
isTriggerOnDown := false. |
|
789 | 676 |
isToggle := isRadio := false. |
677 |
||
1540 | 678 |
"Modified: / 21.5.1998 / 03:07:02 / cg" |
1447 | 679 |
! |
680 |
||
681 |
release |
|
682 |
"release all dependencies" |
|
683 |
||
684 |
enableChannel notNil ifTrue:[ |
|
685 |
enableChannel retractInterestsFor:self. |
|
686 |
enableChannel := nil. |
|
687 |
]. |
|
688 |
super release |
|
121 | 689 |
! ! |
200 | 690 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
691 |
!ButtonController class methodsFor:'documentation'! |
203 | 692 |
|
693 |
version |
|
1680
4c01dc0d5f1c
optional take focus on click
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
694 |
^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.52 1998-09-18 16:02:39 cg Exp $' |
203 | 695 |
! ! |