author | Claus Gittinger <cg@exept.de> |
Sat, 06 Jun 1998 19:54:02 +0200 | |
changeset 912 | e4b45ee7df6d |
parent 899 | 68770c9d162d |
child 1264 | dda5fc818ef0 |
permissions | -rw-r--r-- |
338 | 1 |
SimpleView subclass:#UpDownButton |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
2 |
instanceVariableNames:'orientation upButton downButton' |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
3 |
classVariableNames:'' |
338 | 4 |
poolDictionaries:'' |
5 |
category:'Views-Interactors' |
|
6 |
! |
|
7 |
||
8 |
!UpDownButton class methodsFor:'documentation'! |
|
9 |
||
10 |
documentation |
|
11 |
" |
|
12 |
an up/down button - simply two buttons in one view. |
|
13 |
||
14 |
[author:] |
|
15 |
Claus Gittinger |
|
16 |
||
17 |
[see also:] |
|
18 |
ArrowButton |
|
19 |
ComboUpDownView |
|
20 |
" |
|
21 |
! |
|
22 |
||
23 |
examples |
|
24 |
" |
|
25 |
[exBegin] |
|
26 |
|top ud| |
|
27 |
||
28 |
top := StandardSystemView new. |
|
29 |
top extent:(300 @ 200). |
|
30 |
||
31 |
ud := UpDownButton in:top. |
|
32 |
ud origin:(10 @ 10). |
|
33 |
||
34 |
ud upAction:[Transcript showCR:'up']. |
|
35 |
ud downAction:[Transcript showCR:'down']. |
|
36 |
top open. |
|
37 |
[exEnd] |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
38 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
39 |
[exBegin] |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
40 |
|top ud| |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
41 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
42 |
top := StandardSystemView new. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
43 |
top extent:(300 @ 200). |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
44 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
45 |
ud := UpDownButton in:top. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
46 |
ud orientation:#horizontal. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
47 |
ud origin:(10 @ 10). |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
48 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
49 |
ud upAction:[Transcript showCR:'up']. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
50 |
ud downAction:[Transcript showCR:'down']. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
51 |
top open. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
52 |
[exEnd] |
338 | 53 |
" |
54 |
||
55 |
! ! |
|
56 |
||
57 |
!UpDownButton methodsFor:'accessing-behavior'! |
|
58 |
||
818 | 59 |
disable |
899 | 60 |
"disable the upDown button" |
818 | 61 |
|
62 |
upButton disable. |
|
63 |
downButton disable. |
|
64 |
! |
|
65 |
||
338 | 66 |
downAction:aBlock |
899 | 67 |
"set the down-action" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
68 |
|
338 | 69 |
downButton action:aBlock |
70 |
! |
|
71 |
||
818 | 72 |
enable |
73 |
||
74 |
upButton enable. |
|
75 |
downButton enable. |
|
76 |
! |
|
77 |
||
338 | 78 |
upAction:aBlock |
899 | 79 |
"set the up-action" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
80 |
|
338 | 81 |
upButton action:aBlock |
82 |
! ! |
|
83 |
||
818 | 84 |
!UpDownButton methodsFor:'accessing-channels'! |
85 |
||
86 |
backgroundChannel |
|
899 | 87 |
"return a valueHolder for the background color" |
818 | 88 |
|
899 | 89 |
^ upButton backgroundChannel |
818 | 90 |
! |
91 |
||
92 |
backgroundChannel: aValueHolder |
|
899 | 93 |
"set a valueHolder for the background color" |
818 | 94 |
|
95 |
upButton backgroundChannel: aValueHolder. |
|
96 |
downButton backgroundChannel: aValueHolder |
|
97 |
! |
|
98 |
||
99 |
enableChannel |
|
899 | 100 |
"return a valueHolder for the enabled-state" |
818 | 101 |
|
102 |
upButton enableChannel |
|
103 |
! |
|
104 |
||
105 |
enableChannel: aValueHolder |
|
899 | 106 |
"set a valueHolder for the enabled-state" |
818 | 107 |
|
108 |
upButton enableChannel: aValueHolder. |
|
109 |
downButton enableChannel: aValueHolder |
|
110 |
! |
|
111 |
||
112 |
foregroundChannel |
|
899 | 113 |
"return a valueHolder for the foreground color" |
818 | 114 |
|
899 | 115 |
^ upButton foregroundChannel |
818 | 116 |
! |
117 |
||
118 |
foregroundChannel: aValueHolder |
|
899 | 119 |
"set a valueHolder for the foreground color" |
818 | 120 |
|
121 |
upButton foregroundChannel: aValueHolder. |
|
122 |
downButton foregroundChannel: aValueHolder |
|
123 |
! ! |
|
124 |
||
125 |
!UpDownButton methodsFor:'accessing-colors'! |
|
126 |
||
127 |
backgroundColor |
|
899 | 128 |
"return the backgroundColor" |
818 | 129 |
|
852 | 130 |
^upButton backgroundColor |
818 | 131 |
|
132 |
! |
|
133 |
||
134 |
backgroundColor:aColor |
|
899 | 135 |
"set the backgroundColor" |
818 | 136 |
|
137 |
aColor ~~ upButton backgroundColor ifTrue:[ |
|
138 |
upButton backgroundColor:aColor. |
|
139 |
downButton backgroundColor:aColor. |
|
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
140 |
shown ifTrue:[ |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
141 |
self invalidateRepairNow:true |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
142 |
] |
818 | 143 |
] |
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
144 |
|
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
145 |
"Modified: / 6.6.1998 / 19:53:50 / cg" |
818 | 146 |
! |
147 |
||
148 |
foregroundColor |
|
899 | 149 |
"return the foregroundColor" |
818 | 150 |
|
852 | 151 |
^upButton foregroundColor |
818 | 152 |
|
153 |
! |
|
154 |
||
155 |
foregroundColor:aColor |
|
899 | 156 |
"set the foregroundColor" |
818 | 157 |
|
158 |
aColor ~~ upButton foregroundColor ifTrue:[ |
|
159 |
upButton foregroundColor:aColor. |
|
160 |
downButton foregroundColor:aColor. |
|
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
161 |
shown ifTrue:[ |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
162 |
self invalidateRepairNow:true |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
163 |
] |
818 | 164 |
] |
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
165 |
|
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
166 |
"Modified: / 6.6.1998 / 19:53:44 / cg" |
818 | 167 |
! |
168 |
||
169 |
model:aModel |
|
170 |
"ignore models" |
|
171 |
! ! |
|
172 |
||
338 | 173 |
!UpDownButton methodsFor:'accessing-components'! |
174 |
||
175 |
downButton |
|
899 | 176 |
"return the downButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
177 |
|
338 | 178 |
^ downButton |
179 |
! |
|
180 |
||
181 |
upButton |
|
899 | 182 |
"return the upButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
183 |
|
338 | 184 |
^ upButton |
185 |
! ! |
|
186 |
||
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
187 |
!UpDownButton methodsFor:'accessing-look'! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
188 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
189 |
orientation |
899 | 190 |
"return the orientation (a symbol)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
191 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
192 |
^ orientation |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
193 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
194 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
195 |
orientation:aSymbol |
899 | 196 |
"set the orientation (#horizontal or #vertical)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
197 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
198 |
orientation := aSymbol. |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
199 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
200 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
201 |
self initializeButtonForms |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
202 |
! ! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
203 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
204 |
!UpDownButton methodsFor:'change & update'! |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
205 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
206 |
sizeChanged:how |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
207 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
208 |
super sizeChanged:how. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
209 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
210 |
self initializeButtonDimensions |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
211 |
! ! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
212 |
|
899 | 213 |
!UpDownButton methodsFor:'displaying'! |
214 |
||
215 |
showFocus:explicit |
|
216 |
"display myself as having-focus" |
|
217 |
||
218 |
(upButton enabled or:[downButton enabled]) ifTrue: [super showFocus:explicit] |
|
219 |
! ! |
|
220 |
||
868 | 221 |
!UpDownButton methodsFor:'event handling'! |
222 |
||
223 |
keyPress:aKey x:x y:y |
|
224 |
"simulate a buttonPress/release" |
|
225 |
||
226 |
|theButton theController| |
|
227 |
||
228 |
((aKey == #CursorUp) |
|
229 |
or:[aKey == #CursorRight |
|
230 |
or:[aKey == $+]]) ifTrue:[ |
|
231 |
theButton := upButton |
|
232 |
] ifFalse:[ |
|
233 |
((aKey == #CursorDown) |
|
234 |
or:[aKey == #CursorLeft |
|
235 |
or:[aKey == $-]]) ifTrue:[ |
|
236 |
theButton := downButton |
|
237 |
]. |
|
238 |
]. |
|
239 |
theButton notNil ifTrue:[ |
|
240 |
theController := theButton controller. |
|
241 |
theController pressed:true. |
|
242 |
theController pressed:false. |
|
243 |
^ self |
|
244 |
]. |
|
245 |
^ super keyPress:aKey x:x y:y |
|
246 |
||
247 |
"Created: / 21.4.1998 / 19:48:28 / cg" |
|
248 |
"Modified: / 21.4.1998 / 19:56:28 / cg" |
|
249 |
! ! |
|
250 |
||
338 | 251 |
!UpDownButton methodsFor:'initialization'! |
252 |
||
253 |
initialize |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
254 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
255 |
orientation := #vertical. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
256 |
|
338 | 257 |
super initialize. |
258 |
self initializeButtons |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
259 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
260 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
261 |
initializeButtonDimensions |
899 | 262 |
|upOrigin downOrigin upCorner downCorner| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
263 |
|
899 | 264 |
upOrigin := 0@0. |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
265 |
orientation == #vertical ifTrue:[ |
899 | 266 |
upCorner := (width - 1) @ (height // 2). |
267 |
downOrigin := 0 @ (height // 2 + 1). |
|
268 |
downCorner := (width - 1) @ (height - 1) |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
269 |
] ifFalse:[ |
899 | 270 |
upCorner := (width // 2) @ (height - 1). |
271 |
downOrigin := (width // 2 + 1) @ 0. |
|
272 |
downCorner := (width - 1) @ (height - 1) |
|
273 |
]. |
|
274 |
||
275 |
upButton origin:upOrigin. |
|
276 |
upButton corner:upCorner. |
|
277 |
downButton origin:downOrigin. |
|
278 |
downButton corner:downCorner. |
|
279 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
280 |
! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
281 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
282 |
initializeButtonForms |
899 | 283 |
|upLabel downLabel| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
284 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
285 |
orientation == #vertical ifTrue:[ |
899 | 286 |
upLabel := ArrowButton UpArrowForm. |
287 |
downLabel := ArrowButton DownArrowForm. |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
288 |
] ifFalse:[ |
899 | 289 |
upLabel := ArrowButton LeftArrowForm. |
290 |
downLabel := ArrowButton RightArrowForm. |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
291 |
]. |
899 | 292 |
upButton label:upLabel. |
293 |
downButton label:downLabel. |
|
294 |
||
338 | 295 |
! |
296 |
||
297 |
initializeButtons |
|
779
0abab228a8fd
do not define callbacks in action blocks which do not exist
tz
parents:
651
diff
changeset
|
298 |
|
338 | 299 |
upButton := ArrowButton upIn:self. |
300 |
upButton autoRepeat:true. |
|
301 |
||
302 |
downButton := ArrowButton downIn:self. |
|
303 |
downButton autoRepeat:true. |
|
304 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
305 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
306 |
self initializeButtonForms |
338 | 307 |
! ! |
308 |
||
309 |
!UpDownButton class methodsFor:'documentation'! |
|
310 |
||
311 |
version |
|
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
312 |
^ '$Header: /cvs/stx/stx/libwidg2/UpDownButton.st,v 1.11 1998-06-06 17:54:02 cg Exp $' |
338 | 313 |
! ! |