author | Claus Gittinger <cg@exept.de> |
Mon, 17 Nov 2014 23:50:13 +0100 | |
changeset 5149 | cc14f4e4157d |
parent 4525 | 27c8f14cfd04 |
child 6083 | 3843436837d2 |
permissions | -rw-r--r-- |
88 | 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 |
" |
|
2504
f12dab112227
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
973
diff
changeset
|
12 |
"{ Package: 'stx:libwidg' }" |
f12dab112227
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
973
diff
changeset
|
13 |
|
78 | 14 |
ButtonController subclass:#ToggleController |
582 | 15 |
instanceVariableNames:'action' |
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Interface-Support-Controllers' |
|
78 | 19 |
! |
20 |
||
88 | 21 |
!ToggleController class methodsFor:'documentation'! |
22 |
||
23 |
copyright |
|
24 |
" |
|
25 |
COPYRIGHT (c) 1995 by Claus Gittinger |
|
26 |
All Rights Reserved |
|
27 |
||
28 |
This software is furnished under a license and may be used |
|
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
36 |
||
37 |
documentation |
|
38 |
" |
|
39 |
ToggleControllers redefine some of ButtonControllers behavior; |
|
40 |
user interaction: they always triggerOnDown, and ignore buttonrelease. |
|
41 |
Finally, every buttonPress leads to a toggle action. |
|
125 | 42 |
|
128 | 43 |
ToggleController adds another actionBlock, since it inherits press- |
125 | 44 |
and releaseActions, while we want one actionBlock to be used for both |
45 |
on- and off. The actionBlock (if any) is evaluated with the current |
|
46 |
toggles state if it expects an argument, or without argument if its a no-arg |
|
47 |
block. |
|
128 | 48 |
|
49 |
Other than that, all model relations are inherited - i.e. if the view has a model, |
|
50 |
that one gets change-messages and the toggle updates on aspect changes. |
|
582 | 51 |
|
52 |
[author:] |
|
53 |
Claus Gittinger |
|
88 | 54 |
" |
55 |
! ! |
|
56 |
||
200 | 57 |
!ToggleController methodsFor:'accessing'! |
78 | 58 |
|
200 | 59 |
action:aBlock |
60 |
"set the action to be performed. This is called |
|
61 |
with the toggles state as argument." |
|
62 |
||
63 |
action := aBlock |
|
119 | 64 |
! ! |
65 |
||
66 |
!ToggleController methodsFor:'events'! |
|
67 |
||
4524 | 68 |
keyPress:key x:x y:y |
69 |
"toggle on space" |
|
70 |
||
71 |
<resource: #keyboard (#Space)> |
|
72 |
||
73 |
(key == Character space) ifTrue:[ |
|
4525 | 74 |
enableChannel value ifTrue:[ |
75 |
self toggle. |
|
76 |
^ self |
|
77 |
]. |
|
4524 | 78 |
]. |
79 |
super keyPress:key x:x y:y |
|
80 |
! |
|
81 |
||
119 | 82 |
performAction |
973
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
83 |
"the toggle changed its state; first tell the model and |
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
84 |
channels, then evaluate any (optional) press/release actions, |
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
85 |
finally evaluate my real action, the toggle action. |
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
86 |
Individual press/release actions are usually nil for toggles." |
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
87 |
|
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
88 |
super performAction. |
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
89 |
|
120 | 90 |
action notNil ifTrue:[ |
973
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
91 |
active := true. |
2504
f12dab112227
use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents:
973
diff
changeset
|
92 |
action valueWithOptionalArgument:pressed. |
973
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
93 |
active := false. |
120 | 94 |
]. |
973
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
95 |
|
bcc8b920dccc
model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents:
582
diff
changeset
|
96 |
"Modified: 24.1.1997 / 15:42:14 / cg" |
78 | 97 |
! ! |
98 |
||
200 | 99 |
!ToggleController methodsFor:'initialization'! |
78 | 100 |
|
200 | 101 |
initialize |
102 |
super initialize. |
|
103 |
self beToggle |
|
104 |
! ! |
|
78 | 105 |
|
203 | 106 |
!ToggleController class methodsFor:'documentation'! |
107 |
||
108 |
version |
|
4525 | 109 |
^ '$Header: /cvs/stx/stx/libwidg/ToggleController.st,v 1.15 2013-02-27 11:23:05 stefan Exp $' |
110 |
! |
|
111 |
||
112 |
version_CVS |
|
113 |
^ '$Header: /cvs/stx/stx/libwidg/ToggleController.st,v 1.15 2013-02-27 11:23:05 stefan Exp $' |
|
203 | 114 |
! ! |
4524 | 115 |