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