author | Claus Gittinger <cg@exept.de> |
Thu, 20 Mar 1997 21:58:30 +0100 | |
changeset 1147 | 9bb71c3e69c3 |
parent 1128 | 809b943f4711 |
child 1168 | 231969f02a78 |
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 |
||
200 | 375 |
buttonMultiPress:button x:x y:y |
376 |
^ self buttonPress:button x:x y:y |
|
377 |
! |
|
378 |
||
76 | 379 |
buttonPress:button x:x y:y |
380 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 381 |
^ super buttonPress:button x:x y:y |
76 | 382 |
]. |
383 |
||
1128 | 384 |
buttonDown := true. |
385 |
||
133 | 386 |
enableChannel value ifTrue:[ |
789 | 387 |
isToggle ifTrue:[ |
388 |
self toggle. |
|
389 |
^ self |
|
390 |
]. |
|
391 |
isRadio ifTrue:[ |
|
392 |
pressed ifFalse:[ |
|
393 |
self toggle |
|
394 |
]. |
|
395 |
^ self |
|
396 |
]. |
|
118 | 397 |
|
789 | 398 |
pressed ifFalse:[ |
399 |
pressed := true. |
|
400 |
view showActive. |
|
76 | 401 |
|
789 | 402 |
(pressActionBlock notNil or:[model notNil]) ifTrue:[ |
403 |
" |
|
404 |
force output - so that button is drawn correctly in case |
|
405 |
of any long-computation (at high priority) |
|
406 |
" |
|
407 |
view flush. |
|
408 |
]. |
|
76 | 409 |
|
789 | 410 |
self performAction. |
76 | 411 |
|
789 | 412 |
autoRepeat ifTrue:[ |
413 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
|
414 |
] |
|
415 |
] |
|
76 | 416 |
] |
262 | 417 |
|
1128 | 418 |
"Modified: 8.3.1997 / 00:04:11 / cg" |
76 | 419 |
! |
420 |
||
421 |
buttonRelease:button x:x y:y |
|
422 |
"button was released - if enabled, perform releaseaction" |
|
423 |
||
424 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 425 |
^ super buttonRelease:button x:x y:y |
76 | 426 |
]. |
118 | 427 |
|
1128 | 428 |
buttonDown := false. |
429 |
||
789 | 430 |
(isToggle or:[isRadio]) ifTrue:[ |
431 |
^ self |
|
118 | 432 |
]. |
433 |
||
76 | 434 |
pressed ifTrue:[ |
789 | 435 |
autoRepeat ifTrue:[ |
436 |
Processor removeTimedBlock:repeatBlock |
|
437 |
]. |
|
438 |
pressed := false. |
|
439 |
view showPassive. |
|
76 | 440 |
|
789 | 441 |
enableChannel value ifTrue:[ |
442 |
" |
|
443 |
only perform action if released within myself |
|
444 |
" |
|
445 |
((x >= 0) |
|
446 |
and:[x <= view width |
|
447 |
and:[y >= 0 |
|
448 |
and:[y <= view height]]]) ifTrue:[ |
|
449 |
(releaseActionBlock notNil or:[model notNil]) ifTrue:[ |
|
450 |
" |
|
451 |
force output - so that button is drawn correctly in case |
|
452 |
of any long-computation (at high priority) |
|
453 |
" |
|
454 |
view flush. |
|
455 |
]. |
|
76 | 456 |
|
789 | 457 |
self performAction. |
458 |
] |
|
459 |
] |
|
76 | 460 |
] |
262 | 461 |
|
1128 | 462 |
"Modified: 8.3.1997 / 00:04:19 / cg" |
76 | 463 |
! |
464 |
||
200 | 465 |
enableStateChange |
466 |
"this is sent, whenever the enable value has changed" |
|
76 | 467 |
|
1091 | 468 |
view notNil ifTrue:[view redraw] |
200 | 469 |
|
470 |
"Modified: 17.9.1995 / 19:55:52 / claus" |
|
1091 | 471 |
"Modified: 3.3.1997 / 10:52:22 / cg" |
76 | 472 |
! |
473 |
||
200 | 474 |
keyPress:key x:x y:y |
475 |
"trigger on Return and space, if I am the focusView of my group |
|
476 |
(i.e. if I got an explicit focus)" |
|
121 | 477 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
478 |
view hasFocus ifTrue:[ |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
479 |
((key == Character space) |
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
480 |
or:[key == #Return]) ifTrue:[ |
349
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
481 |
"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
|
482 |
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
|
483 |
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
|
484 |
^ self. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
485 |
] |
200 | 486 |
]. |
487 |
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
|
488 |
|
1062
5fbcf4ce6a51
handle return as trigger - iff my view has explicit focus
Claus Gittinger <cg@exept.de>
parents:
985
diff
changeset
|
489 |
"Modified: 26.2.1997 / 00:50:25 / cg" |
121 | 490 |
! |
491 |
||
492 |
performAction |
|
146 | 493 |
|action value| |
133 | 494 |
|
789 | 495 |
(isToggle or:[isRadio]) ifTrue:[ |
496 |
value := pressed |
|
133 | 497 |
] ifFalse:[ |
789 | 498 |
value := true |
133 | 499 |
]. |
76 | 500 |
|
125 | 501 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
502 |
ST-80 style model notification ... |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
503 |
this updates the model (typically, a ValueHolder) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
504 |
" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
505 |
(isToggle |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
506 |
or:[(isTriggerOnDown and:[pressed]) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
507 |
or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
508 |
"the ST-80 way of doing things" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
509 |
view notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
510 |
active := true. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
511 |
view sendChangeMessageWith:value. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
512 |
active := false. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
513 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
514 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
515 |
|
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
516 |
" |
145 | 517 |
ST/X style actionBlock evaluation & channel notification ... |
125 | 518 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
519 |
pressChannel notNil ifTrue:[ |
1095 | 520 |
pressed ifTrue:[ |
521 |
pressChannel value:true |
|
522 |
] |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
523 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
524 |
releaseChannel notNil ifTrue:[ |
1095 | 525 |
pressed ifFalse:[ |
526 |
releaseChannel value:true |
|
527 |
] |
|
971
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 |
|
76 | 530 |
pressed ifTrue:[ |
789 | 531 |
action := pressActionBlock. |
121 | 532 |
] ifFalse:[ |
789 | 533 |
action := releaseActionBlock. |
121 | 534 |
]. |
125 | 535 |
action notNil ifTrue:[ |
789 | 536 |
active := true. |
537 |
action numArgs == 0 ifTrue:[ |
|
538 |
action value |
|
539 |
] ifFalse:[ |
|
540 |
action value:value |
|
541 |
]. |
|
542 |
active := false. |
|
125 | 543 |
]. |
76 | 544 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
545 |
"Modified: 24.1.1997 / 11:38:20 / cg" |
76 | 546 |
! |
547 |
||
200 | 548 |
pointerEnter:state x:x y:y |
549 |
"mouse pointer entered my view. |
|
550 |
Redraw with enteredColors if they differ from the normal colors" |
|
551 |
||
552 |
entered := true. |
|
553 |
enableChannel value ifTrue:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
554 |
pressed ifTrue:[ |
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
555 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
556 |
view showActive. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
557 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
558 |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
559 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
560 |
reentered after a leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
561 |
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
|
562 |
triggerOnDown, show active again. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
563 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
564 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
565 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
566 |
]. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
567 |
] ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
568 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
569 |
] |
200 | 570 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
571 |
|
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
572 |
"Modified: 26.5.1996 / 18:09:06 / cg" |
76 | 573 |
! |
574 |
||
200 | 575 |
pointerLeave:state |
576 |
"mouse pointer left my view. |
|
577 |
Redraw with normal colors if they differ from enteredColors" |
|
76 | 578 |
|
200 | 579 |
entered := false. |
580 |
pressed ifTrue:[ |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
581 |
isTriggerOnDown ifFalse:[ |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
582 |
view showPassive. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
583 |
]. |
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
584 |
|
711
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 |
leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
587 |
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
|
588 |
action on release, show passive |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
589 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
590 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
591 |
Processor removeTimedBlock:repeatBlock |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
592 |
]. |
200 | 593 |
] ifFalse:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
594 |
enableChannel value ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
595 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
596 |
] |
200 | 597 |
] |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
598 |
|
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
599 |
"Modified: 26.5.1996 / 18:09:08 / cg" |
76 | 600 |
! |
601 |
||
121 | 602 |
repeat |
603 |
"this is sent from the autorepeat-block, when the button has been pressed long |
|
604 |
enough; it simulates a release-press, by evaluating both release |
|
605 |
and press actions." |
|
76 | 606 |
|
220
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
607 |
|dly| |
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
608 |
|
985
6e8a73b27390
perform action first, then reinstall autorepeat
Claus Gittinger <cg@exept.de>
parents:
976
diff
changeset
|
609 |
(pressed and:[entered]) ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
610 |
enableChannel value ifTrue:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
611 |
active ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
612 |
self performAction. |
121 | 613 |
|
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
614 |
autoRepeat ifTrue:[ |
704 | 615 |
view graphicsDevice shiftDown ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
616 |
dly := repeatDelay / 4. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
617 |
] ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
618 |
dly := repeatDelay |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
619 |
]. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
620 |
Processor addTimedBlock:repeatBlock afterSeconds:dly |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
621 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
622 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
623 |
] |
76 | 624 |
] |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
625 |
|
704 | 626 |
"Modified: 28.5.1996 / 20:21:24 / cg" |
76 | 627 |
! ! |
121 | 628 |
|
629 |
!ButtonController methodsFor:'initialization'! |
|
630 |
||
631 |
initialize |
|
632 |
super initialize. |
|
633 |
||
266 | 634 |
enableChannel := true asValue. |
635 |
enableChannel onChangeSend:#enableStateChange to:self. |
|
133 | 636 |
|
121 | 637 |
active := false. |
638 |
pressed := false. |
|
639 |
entered := false. |
|
640 |
autoRepeat := false. |
|
641 |
initialDelay := self class defaultInitialDelay. |
|
642 |
repeatDelay := self class defaultRepeatDelay. |
|
643 |
isTriggerOnDown := false. |
|
789 | 644 |
isToggle := isRadio := false. |
645 |
||
646 |
"Modified: 15.7.1996 / 13:40:14 / cg" |
|
121 | 647 |
! ! |
200 | 648 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
649 |
!ButtonController class methodsFor:'documentation'! |
203 | 650 |
|
651 |
version |
|
1147 | 652 |
^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.44 1997-03-20 20:58:30 cg Exp $' |
203 | 653 |
! ! |