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