author | Claus Gittinger <cg@exept.de> |
Mon, 27 Jan 1997 16:00:15 +0100 | |
changeset 976 | ed2b99f9695a |
parent 972 | 52c5200c35b7 |
child 985 | 6e8a73b27390 |
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 |
789 | 16 |
pressActionBlock releaseActionBlock isToggle isRadio' |
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. |
|
154 |
repeatBlock := [self repeat] |
|
121 | 155 |
|
200 | 156 |
"Modified: 5.9.1995 / 22:06:00 / claus" |
157 |
! |
|
158 |
||
976 | 159 |
beButton |
160 |
"make the receiver act like a button; thats the default, anyway" |
|
161 |
||
162 |
isTriggerOnDown := false. |
|
163 |
isToggle := false. |
|
164 |
isRadio := false. |
|
165 |
||
166 |
"Modified: 15.7.1996 / 13:42:15 / cg" |
|
167 |
"Created: 27.1.1997 / 13:30:11 / cg" |
|
168 |
! |
|
169 |
||
789 | 170 |
beRadioButton |
171 |
"make the receiver act like a radioButton; |
|
172 |
That is like a toggle, but do not allow turning myself off |
|
173 |
by buttonPress (instead, must be turned off by another button or programmatically)" |
|
174 |
||
175 |
isTriggerOnDown := true. |
|
176 |
isToggle := false. |
|
177 |
isRadio := true. |
|
178 |
||
179 |
"Created: 15.7.1996 / 13:42:06 / cg" |
|
180 |
! |
|
181 |
||
200 | 182 |
beToggle |
183 |
"make the receiver act like a toggle" |
|
184 |
||
185 |
isTriggerOnDown := true. |
|
789 | 186 |
isToggle := true. |
187 |
isRadio := false. |
|
188 |
||
189 |
"Modified: 15.7.1996 / 13:42:15 / cg" |
|
121 | 190 |
! |
76 | 191 |
|
200 | 192 |
beTriggerOnDown |
193 |
"make the receiver act on button press" |
|
194 |
||
195 |
isTriggerOnDown := true |
|
196 |
! |
|
197 |
||
198 |
beTriggerOnUp |
|
199 |
"make the receiver act on button release" |
|
121 | 200 |
|
200 | 201 |
isTriggerOnDown := false |
202 |
! |
|
203 |
||
204 |
disable |
|
205 |
"disable the button" |
|
206 |
||
207 |
enableChannel value ifTrue:[ |
|
208 |
enableChannel value:false. |
|
209 |
"/ view redraw - not needed; I listen to enableChannel |
|
210 |
] |
|
121 | 211 |
! |
212 |
||
200 | 213 |
enable |
214 |
"enable the button" |
|
121 | 215 |
|
200 | 216 |
enableChannel value ifFalse:[ |
217 |
enableChannel value:true. |
|
218 |
"/ view redraw - not needed; I listen to enableChannel |
|
219 |
] |
|
76 | 220 |
! |
221 |
||
200 | 222 |
isTriggerOnDown |
223 |
"return true, if I trigger on press |
|
224 |
(in contrast to triggering on up, which is the default)" |
|
225 |
||
226 |
^ isTriggerOnDown |
|
227 |
! |
|
228 |
||
229 |
pressAction |
|
230 |
"return the pressAction; thats the block which gets evaluated |
|
231 |
when the button is pressed (if non-nil)" |
|
232 |
||
233 |
^ pressActionBlock |
|
234 |
! |
|
235 |
||
236 |
pressAction:aBlock |
|
237 |
"define the action to be performed on press" |
|
238 |
||
239 |
pressActionBlock := aBlock |
|
128 | 240 |
! |
241 |
||
200 | 242 |
releaseAction |
243 |
"return the releaseAction; thats the block which gets evaluated |
|
244 |
when the button is relreased (if non-nil)" |
|
245 |
||
246 |
^ releaseActionBlock |
|
247 |
! |
|
248 |
||
249 |
releaseAction:aBlock |
|
250 |
"define the action to be performed on release" |
|
251 |
||
252 |
releaseActionBlock := aBlock |
|
128 | 253 |
! |
254 |
||
200 | 255 |
triggerOnDown:aBoolean |
256 |
"set/clear the flag which controls if the action block is to be evaluated |
|
257 |
on press or on release. |
|
258 |
(see also ST-80 compatibility methods beTriggerOn*)" |
|
259 |
||
260 |
isTriggerOnDown := aBoolean |
|
128 | 261 |
! ! |
262 |
||
145 | 263 |
!ButtonController methodsFor:'accessing-channels'! |
264 |
||
265 |
enableChannel |
|
602 | 266 |
"return the valueHolder holding the enable boolean value" |
145 | 267 |
|
268 |
^ enableChannel |
|
602 | 269 |
|
270 |
"Modified: 30.4.1996 / 15:09:30 / cg" |
|
145 | 271 |
! |
272 |
||
273 |
enableChannel:aValueHolder |
|
274 |
"set the valueHolder, which holds the enable boolean value" |
|
275 |
||
162 | 276 |
|wasEnabled| |
277 |
||
145 | 278 |
enableChannel notNil ifTrue:[ |
162 | 279 |
wasEnabled := enableChannel value. |
258
ae4b8f1a6738
interest is written with one 'r' (shame on me)
Claus Gittinger <cg@exept.de>
parents:
220
diff
changeset
|
280 |
enableChannel retractInterestsFor:self. |
162 | 281 |
] ifFalse:[ |
282 |
wasEnabled := true |
|
145 | 283 |
]. |
284 |
enableChannel := aValueHolder. |
|
285 |
aValueHolder onChangeSend:#enableStateChange to:self. |
|
162 | 286 |
enableChannel value ~~ wasEnabled ifTrue:[ |
287 |
self enableStateChange |
|
145 | 288 |
] |
162 | 289 |
|
290 |
"Modified: 17.9.1995 / 19:41:18 / claus" |
|
145 | 291 |
! |
292 |
||
293 |
pressChannel:aChannel |
|
294 |
pressChannel := aChannel |
|
295 |
! |
|
296 |
||
297 |
releaseChannel:aChannel |
|
298 |
releaseChannel := aChannel |
|
299 |
! ! |
|
300 |
||
200 | 301 |
!ButtonController methodsFor:'accessing-state'! |
76 | 302 |
|
200 | 303 |
active |
304 |
"return true, if I am active; |
|
305 |
that is: currently performing my action. |
|
306 |
This query can be used to avoid multiple redraws." |
|
76 | 307 |
|
200 | 308 |
^ active |
128 | 309 |
! |
310 |
||
200 | 311 |
active:aBoolean |
312 |
active := aBoolean |
|
76 | 313 |
! |
314 |
||
200 | 315 |
enabled |
316 |
"return true, if I am enabled" |
|
128 | 317 |
|
200 | 318 |
^ enableChannel value |
76 | 319 |
! |
320 |
||
200 | 321 |
entered |
322 |
"return true, if the mouse pointer is currently in my view" |
|
155 | 323 |
|
200 | 324 |
^ entered |
325 |
! |
|
155 | 326 |
|
200 | 327 |
entered:aBoolean |
328 |
entered := aBoolean |
|
155 | 329 |
! |
330 |
||
200 | 331 |
pressed |
332 |
"return true, if I am pressed" |
|
76 | 333 |
|
200 | 334 |
^ pressed |
76 | 335 |
! |
336 |
||
200 | 337 |
pressed:aBoolean |
338 |
pressed ~~ aBoolean ifTrue:[ |
|
339 |
pressed := aBoolean. |
|
340 |
self performAction. |
|
118 | 341 |
]. |
342 |
! |
|
343 |
||
200 | 344 |
setPressed:aBoolean |
345 |
pressed := aBoolean. |
|
121 | 346 |
|
200 | 347 |
"Created: 14.11.1995 / 21:37:08 / cg" |
266 | 348 |
! |
349 |
||
350 |
toggle |
|
351 |
"toggle and perform the action" |
|
352 |
||
353 |
enableChannel value ifTrue:[ |
|
354 |
self toggleNoAction. |
|
355 |
self performAction. |
|
356 |
view changed:#toggle with:pressed |
|
357 |
] |
|
358 |
! |
|
359 |
||
360 |
toggleNoAction |
|
361 |
"toggle, but do NOT perform any action" |
|
362 |
||
363 |
pressed ifTrue:[ |
|
364 |
view turnOff. |
|
365 |
pressed := false. |
|
366 |
] ifFalse:[ |
|
367 |
view turnOn. |
|
368 |
pressed := true. |
|
369 |
]. |
|
76 | 370 |
! ! |
371 |
||
372 |
!ButtonController methodsFor:'event handling'! |
|
373 |
||
200 | 374 |
buttonMultiPress:button x:x y:y |
375 |
^ self buttonPress:button x:x y:y |
|
376 |
! |
|
377 |
||
76 | 378 |
buttonPress:button x:x y:y |
379 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 380 |
^ super buttonPress:button x:x y:y |
76 | 381 |
]. |
382 |
||
133 | 383 |
enableChannel value ifTrue:[ |
789 | 384 |
isToggle ifTrue:[ |
385 |
self toggle. |
|
386 |
^ self |
|
387 |
]. |
|
388 |
isRadio ifTrue:[ |
|
389 |
pressed ifFalse:[ |
|
390 |
self toggle |
|
391 |
]. |
|
392 |
^ self |
|
393 |
]. |
|
118 | 394 |
|
789 | 395 |
pressed ifFalse:[ |
396 |
pressed := true. |
|
397 |
view showActive. |
|
76 | 398 |
|
789 | 399 |
(pressActionBlock notNil or:[model notNil]) ifTrue:[ |
400 |
" |
|
401 |
force output - so that button is drawn correctly in case |
|
402 |
of any long-computation (at high priority) |
|
403 |
" |
|
404 |
view flush. |
|
405 |
]. |
|
76 | 406 |
|
789 | 407 |
self performAction. |
76 | 408 |
|
789 | 409 |
autoRepeat ifTrue:[ |
410 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
|
411 |
] |
|
412 |
] |
|
76 | 413 |
] |
262 | 414 |
|
789 | 415 |
"Modified: 15.7.1996 / 14:07:48 / cg" |
76 | 416 |
! |
417 |
||
418 |
buttonRelease:button x:x y:y |
|
419 |
"button was released - if enabled, perform releaseaction" |
|
420 |
||
421 |
(button == 1 or:[button == #select]) ifFalse:[ |
|
789 | 422 |
^ super buttonRelease:button x:x y:y |
76 | 423 |
]. |
118 | 424 |
|
789 | 425 |
(isToggle or:[isRadio]) ifTrue:[ |
426 |
^ self |
|
118 | 427 |
]. |
428 |
||
76 | 429 |
pressed ifTrue:[ |
789 | 430 |
autoRepeat ifTrue:[ |
431 |
Processor removeTimedBlock:repeatBlock |
|
432 |
]. |
|
433 |
pressed := false. |
|
434 |
view showPassive. |
|
76 | 435 |
|
789 | 436 |
enableChannel value ifTrue:[ |
437 |
" |
|
438 |
only perform action if released within myself |
|
439 |
" |
|
440 |
((x >= 0) |
|
441 |
and:[x <= view width |
|
442 |
and:[y >= 0 |
|
443 |
and:[y <= view height]]]) ifTrue:[ |
|
444 |
(releaseActionBlock notNil or:[model notNil]) ifTrue:[ |
|
445 |
" |
|
446 |
force output - so that button is drawn correctly in case |
|
447 |
of any long-computation (at high priority) |
|
448 |
" |
|
449 |
view flush. |
|
450 |
]. |
|
76 | 451 |
|
789 | 452 |
self performAction. |
453 |
] |
|
454 |
] |
|
76 | 455 |
] |
262 | 456 |
|
789 | 457 |
"Modified: 15.7.1996 / 13:42:34 / cg" |
76 | 458 |
! |
459 |
||
200 | 460 |
enableStateChange |
461 |
"this is sent, whenever the enable value has changed" |
|
76 | 462 |
|
200 | 463 |
view notNil ifTrue:[view enableStateChangeRedraw] |
464 |
||
465 |
"Modified: 17.9.1995 / 19:55:52 / claus" |
|
76 | 466 |
! |
467 |
||
200 | 468 |
keyPress:key x:x y:y |
469 |
"trigger on Return and space, if I am the focusView of my group |
|
470 |
(i.e. if I got an explicit focus)" |
|
121 | 471 |
|
349
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
472 |
key == Character space ifTrue:[ |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
473 |
view hasFocus ifTrue:[ |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
474 |
"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
|
475 |
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
|
476 |
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
|
477 |
^ self. |
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
478 |
] |
200 | 479 |
]. |
480 |
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
|
481 |
|
e4382398fc59
ignore Return key - its meant to close a box
Claus Gittinger <cg@exept.de>
parents:
347
diff
changeset
|
482 |
"Modified: 9.2.1996 / 23:11:58 / cg" |
121 | 483 |
! |
484 |
||
485 |
performAction |
|
146 | 486 |
|action value| |
133 | 487 |
|
789 | 488 |
(isToggle or:[isRadio]) ifTrue:[ |
489 |
value := pressed |
|
133 | 490 |
] ifFalse:[ |
789 | 491 |
value := true |
133 | 492 |
]. |
76 | 493 |
|
125 | 494 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
495 |
ST-80 style model notification ... |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
496 |
this updates the model (typically, a ValueHolder) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
497 |
" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
498 |
(isToggle |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
499 |
or:[(isTriggerOnDown and:[pressed]) |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
500 |
or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
501 |
"the ST-80 way of doing things" |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
502 |
view notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
503 |
active := true. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
504 |
view sendChangeMessageWith:value. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
505 |
active := false. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
506 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
507 |
]. |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
508 |
|
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
509 |
" |
145 | 510 |
ST/X style actionBlock evaluation & channel notification ... |
125 | 511 |
" |
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
512 |
pressChannel notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
513 |
pressChannel value:pressed |
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 |
releaseChannel notNil ifTrue:[ |
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
516 |
releaseChannel value:pressed not |
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 |
|
76 | 519 |
pressed ifTrue:[ |
789 | 520 |
action := pressActionBlock. |
121 | 521 |
] ifFalse:[ |
789 | 522 |
action := releaseActionBlock. |
121 | 523 |
]. |
125 | 524 |
action notNil ifTrue:[ |
789 | 525 |
active := true. |
526 |
action numArgs == 0 ifTrue:[ |
|
527 |
action value |
|
528 |
] ifFalse:[ |
|
529 |
action value:value |
|
530 |
]. |
|
531 |
active := false. |
|
125 | 532 |
]. |
76 | 533 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
534 |
"Modified: 24.1.1997 / 11:38:20 / cg" |
76 | 535 |
! |
536 |
||
200 | 537 |
pointerEnter:state x:x y:y |
538 |
"mouse pointer entered my view. |
|
539 |
Redraw with enteredColors if they differ from the normal colors" |
|
540 |
||
541 |
entered := true. |
|
542 |
enableChannel value ifTrue:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
543 |
pressed ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
544 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
545 |
reentered after a leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
546 |
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
|
547 |
triggerOnDown, show active again. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
548 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
549 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
550 |
Processor addTimedBlock:repeatBlock afterSeconds:initialDelay |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
551 |
]. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
552 |
isTriggerOnDown ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
553 |
view showActive. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
554 |
] |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
555 |
] ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
556 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
557 |
] |
200 | 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 |
"Modified: 26.5.1996 / 18:09:06 / cg" |
76 | 561 |
! |
562 |
||
200 | 563 |
pointerLeave:state |
564 |
"mouse pointer left my view. |
|
565 |
Redraw with normal colors if they differ from enteredColors" |
|
76 | 566 |
|
200 | 567 |
entered := false. |
568 |
pressed ifTrue:[ |
|
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
569 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
570 |
leave with mouse-button down; |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
571 |
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
|
572 |
action on release, show passive |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
573 |
" |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
574 |
autoRepeat ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
575 |
Processor removeTimedBlock:repeatBlock |
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 |
isTriggerOnDown ifFalse:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
578 |
view showPassive. |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
579 |
] |
200 | 580 |
] ifFalse:[ |
711
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
581 |
enableChannel value ifTrue:[ |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
582 |
view invalidate |
c830bb66598b
use new #invalidate instead of redraw
Claus Gittinger <cg@exept.de>
parents:
704
diff
changeset
|
583 |
] |
200 | 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 |
"Modified: 26.5.1996 / 18:09:08 / cg" |
76 | 587 |
! |
588 |
||
121 | 589 |
repeat |
590 |
"this is sent from the autorepeat-block, when the button has been pressed long |
|
591 |
enough; it simulates a release-press, by evaluating both release |
|
592 |
and press actions." |
|
76 | 593 |
|
220
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
594 |
|dly| |
635d3f583f61
fast repeat if shift is pressed
Claus Gittinger <cg@exept.de>
parents:
203
diff
changeset
|
595 |
|
76 | 596 |
pressed ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
597 |
enableChannel value ifTrue:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
598 |
active ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
599 |
self performAction. |
155 | 600 |
"/ active := true. |
601 |
"/ releaseActionBlock notNil ifTrue:[releaseActionBlock value]. |
|
602 |
"/ pressActionBlock notNil ifTrue:[pressActionBlock value]. |
|
603 |
"/ active := false. |
|
121 | 604 |
|
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
605 |
autoRepeat ifTrue:[ |
704 | 606 |
view graphicsDevice shiftDown ifTrue:[ |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
607 |
dly := repeatDelay / 4. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
608 |
] ifFalse:[ |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
609 |
dly := repeatDelay |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
610 |
]. |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
611 |
Processor addTimedBlock:repeatBlock afterSeconds:dly |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
612 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
613 |
] |
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
614 |
] |
76 | 615 |
] |
417
3f48ca2beb7d
use device shiftDown - NOT sensor shiftDown
Claus Gittinger <cg@exept.de>
parents:
349
diff
changeset
|
616 |
|
704 | 617 |
"Modified: 28.5.1996 / 20:21:24 / cg" |
76 | 618 |
! ! |
121 | 619 |
|
620 |
!ButtonController methodsFor:'initialization'! |
|
621 |
||
622 |
initialize |
|
623 |
super initialize. |
|
624 |
||
266 | 625 |
enableChannel := true asValue. |
626 |
enableChannel onChangeSend:#enableStateChange to:self. |
|
133 | 627 |
|
121 | 628 |
active := false. |
629 |
pressed := false. |
|
630 |
entered := false. |
|
631 |
autoRepeat := false. |
|
632 |
initialDelay := self class defaultInitialDelay. |
|
633 |
repeatDelay := self class defaultRepeatDelay. |
|
634 |
isTriggerOnDown := false. |
|
789 | 635 |
isToggle := isRadio := false. |
636 |
||
637 |
"Modified: 15.7.1996 / 13:40:14 / cg" |
|
121 | 638 |
! ! |
200 | 639 |
|
971
8caaeb9d63fb
change the model before performing any actionBlock
Claus Gittinger <cg@exept.de>
parents:
789
diff
changeset
|
640 |
!ButtonController class methodsFor:'documentation'! |
203 | 641 |
|
642 |
version |
|
976 | 643 |
^ '$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.38 1997-01-27 15:00:15 cg Exp $' |
203 | 644 |
! ! |