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