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