author | Stefan Vogel <sv@exept.de> |
Wed, 31 Mar 1999 08:09:00 +0200 | |
changeset 1299 | f088a69429be |
parent 1264 | dda5fc818ef0 |
child 1435 | 6343d644bf32 |
permissions | -rw-r--r-- |
1299 | 1 |
View 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. |
1299 | 46 |
ud origin:(10 @ 10). |
47 |
ud model:[:arg| Transcript showCR:arg]. |
|
48 |
top open. |
|
49 |
[exEnd] |
|
50 |
||
51 |
[exBegin] |
|
52 |
|top ud| |
|
53 |
||
54 |
top := StandardSystemView new. |
|
55 |
top extent:(300 @ 200). |
|
56 |
||
57 |
ud := UpDownButton in:top. |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
58 |
ud orientation:#horizontal. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
59 |
ud origin:(10 @ 10). |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
60 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
61 |
ud upAction:[Transcript showCR:'up']. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
62 |
ud downAction:[Transcript showCR:'down']. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
63 |
top open. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
64 |
[exEnd] |
338 | 65 |
" |
66 |
||
67 |
! ! |
|
68 |
||
69 |
!UpDownButton methodsFor:'accessing-behavior'! |
|
70 |
||
71 |
downAction:aBlock |
|
899 | 72 |
"set the down-action" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
73 |
|
338 | 74 |
downButton action:aBlock |
75 |
! |
|
76 |
||
1299 | 77 |
enabled |
78 |
||
79 |
^ upButton enabled. |
|
80 |
||
81 |
"Created: / 30.3.1999 / 17:01:43 / stefan" |
|
82 |
! |
|
818 | 83 |
|
1299 | 84 |
enabled:aBoolean |
85 |
||
86 |
upButton enabled:aBoolean. |
|
87 |
downButton enabled:aBoolean. |
|
88 |
||
89 |
"Created: / 30.3.1999 / 15:47:11 / stefan" |
|
818 | 90 |
! |
91 |
||
338 | 92 |
upAction:aBlock |
899 | 93 |
"set the up-action" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
94 |
|
338 | 95 |
upButton action:aBlock |
96 |
! ! |
|
97 |
||
818 | 98 |
!UpDownButton methodsFor:'accessing-channels'! |
99 |
||
100 |
backgroundChannel |
|
899 | 101 |
"return a valueHolder for the background color" |
818 | 102 |
|
899 | 103 |
^ upButton backgroundChannel |
818 | 104 |
! |
105 |
||
106 |
backgroundChannel: aValueHolder |
|
899 | 107 |
"set a valueHolder for the background color" |
818 | 108 |
|
109 |
upButton backgroundChannel: aValueHolder. |
|
110 |
downButton backgroundChannel: aValueHolder |
|
111 |
! |
|
112 |
||
113 |
enableChannel |
|
899 | 114 |
"return a valueHolder for the enabled-state" |
818 | 115 |
|
1299 | 116 |
^ upButton enableChannel |
117 |
||
118 |
"Modified: / 30.3.1999 / 16:56:32 / stefan" |
|
818 | 119 |
! |
120 |
||
121 |
enableChannel: aValueHolder |
|
899 | 122 |
"set a valueHolder for the enabled-state" |
818 | 123 |
|
124 |
upButton enableChannel: aValueHolder. |
|
125 |
downButton enableChannel: aValueHolder |
|
126 |
! |
|
127 |
||
128 |
foregroundChannel |
|
899 | 129 |
"return a valueHolder for the foreground color" |
818 | 130 |
|
899 | 131 |
^ upButton foregroundChannel |
818 | 132 |
! |
133 |
||
134 |
foregroundChannel: aValueHolder |
|
899 | 135 |
"set a valueHolder for the foreground color" |
818 | 136 |
|
137 |
upButton foregroundChannel: aValueHolder. |
|
138 |
downButton foregroundChannel: aValueHolder |
|
1299 | 139 |
! |
140 |
||
141 |
model:aModel |
|
142 |
||
143 |
|m| |
|
144 |
||
145 |
aModel notNil ifTrue:[ |
|
146 |
m := self. |
|
147 |
upButton changeMessage:#changeUp:. |
|
148 |
downButton changeMessage:#changeDown:. |
|
149 |
]. |
|
150 |
upButton model:m. |
|
151 |
downButton model:m. |
|
152 |
^ super model:aModel |
|
153 |
||
154 |
"Modified: / 30.3.1999 / 17:45:59 / stefan" |
|
818 | 155 |
! ! |
156 |
||
157 |
!UpDownButton methodsFor:'accessing-colors'! |
|
158 |
||
159 |
backgroundColor |
|
899 | 160 |
"return the backgroundColor" |
818 | 161 |
|
852 | 162 |
^upButton backgroundColor |
818 | 163 |
|
164 |
! |
|
165 |
||
166 |
backgroundColor:aColor |
|
899 | 167 |
"set the backgroundColor" |
818 | 168 |
|
169 |
aColor ~~ upButton backgroundColor ifTrue:[ |
|
170 |
upButton backgroundColor:aColor. |
|
171 |
downButton backgroundColor:aColor. |
|
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
172 |
shown ifTrue:[ |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
173 |
self invalidateRepairNow:true |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
174 |
] |
818 | 175 |
] |
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
176 |
|
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
177 |
"Modified: / 6.6.1998 / 19:53:50 / cg" |
818 | 178 |
! |
179 |
||
180 |
foregroundColor |
|
899 | 181 |
"return the foregroundColor" |
818 | 182 |
|
852 | 183 |
^upButton foregroundColor |
818 | 184 |
|
185 |
! |
|
186 |
||
187 |
foregroundColor:aColor |
|
899 | 188 |
"set the foregroundColor" |
818 | 189 |
|
190 |
aColor ~~ upButton foregroundColor ifTrue:[ |
|
191 |
upButton foregroundColor:aColor. |
|
192 |
downButton foregroundColor:aColor. |
|
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
193 |
shown ifTrue:[ |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
194 |
self invalidateRepairNow:true |
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
195 |
] |
818 | 196 |
] |
912
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
197 |
|
e4b45ee7df6d
redrawNow, when colors change.
Claus Gittinger <cg@exept.de>
parents:
899
diff
changeset
|
198 |
"Modified: / 6.6.1998 / 19:53:44 / cg" |
818 | 199 |
! ! |
200 |
||
338 | 201 |
!UpDownButton methodsFor:'accessing-components'! |
202 |
||
203 |
downButton |
|
899 | 204 |
"return the downButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
205 |
|
338 | 206 |
^ downButton |
207 |
! |
|
208 |
||
209 |
upButton |
|
899 | 210 |
"return the upButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
211 |
|
338 | 212 |
^ upButton |
213 |
! ! |
|
214 |
||
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
215 |
!UpDownButton methodsFor:'accessing-look'! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
216 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
217 |
orientation |
899 | 218 |
"return the orientation (a symbol)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
219 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
220 |
^ orientation |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
221 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
222 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
223 |
orientation:aSymbol |
899 | 224 |
"set the orientation (#horizontal or #vertical)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
225 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
226 |
orientation := aSymbol. |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
227 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
228 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
229 |
self initializeButtonForms |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
230 |
! ! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
231 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
232 |
!UpDownButton methodsFor:'change & update'! |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
233 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
234 |
sizeChanged:how |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
235 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
236 |
super sizeChanged:how. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
237 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
238 |
self initializeButtonDimensions |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
239 |
! ! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
240 |
|
868 | 241 |
!UpDownButton methodsFor:'event handling'! |
242 |
||
1299 | 243 |
changeDown:aValue |
244 |
"down button was pressed, send to my model" |
|
245 |
||
246 |
self sendChangeMessageWith:#down |
|
247 |
||
248 |
"Modified: / 30.3.1999 / 17:28:50 / stefan" |
|
249 |
! |
|
250 |
||
251 |
changeUp:aValue |
|
252 |
"up button was pressed, send to my model" |
|
253 |
||
254 |
self sendChangeMessageWith:#up |
|
255 |
||
256 |
"Created: / 30.3.1999 / 17:28:26 / stefan" |
|
257 |
! |
|
258 |
||
868 | 259 |
keyPress:aKey x:x y:y |
260 |
"simulate a buttonPress/release" |
|
261 |
||
262 |
|theButton theController| |
|
263 |
||
264 |
((aKey == #CursorUp) |
|
265 |
or:[aKey == #CursorRight |
|
266 |
or:[aKey == $+]]) ifTrue:[ |
|
267 |
theButton := upButton |
|
268 |
] ifFalse:[ |
|
269 |
((aKey == #CursorDown) |
|
270 |
or:[aKey == #CursorLeft |
|
271 |
or:[aKey == $-]]) ifTrue:[ |
|
272 |
theButton := downButton |
|
273 |
]. |
|
274 |
]. |
|
275 |
theButton notNil ifTrue:[ |
|
276 |
theController := theButton controller. |
|
277 |
theController pressed:true. |
|
278 |
theController pressed:false. |
|
279 |
^ self |
|
280 |
]. |
|
281 |
^ super keyPress:aKey x:x y:y |
|
282 |
||
283 |
"Created: / 21.4.1998 / 19:48:28 / cg" |
|
284 |
"Modified: / 21.4.1998 / 19:56:28 / cg" |
|
285 |
! ! |
|
286 |
||
1264 | 287 |
!UpDownButton methodsFor:'focus handling'! |
288 |
||
289 |
showFocus:explicit |
|
290 |
"display myself as having-focus" |
|
291 |
||
292 |
(upButton enabled or:[downButton enabled]) ifTrue: [ |
|
293 |
super showFocus:explicit |
|
294 |
] |
|
295 |
! ! |
|
296 |
||
338 | 297 |
!UpDownButton methodsFor:'initialization'! |
298 |
||
299 |
initialize |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
300 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
301 |
orientation := #vertical. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
302 |
|
338 | 303 |
super initialize. |
304 |
self initializeButtons |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
305 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
306 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
307 |
initializeButtonDimensions |
899 | 308 |
|upOrigin downOrigin upCorner downCorner| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
309 |
|
899 | 310 |
upOrigin := 0@0. |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
311 |
orientation == #vertical ifTrue:[ |
899 | 312 |
upCorner := (width - 1) @ (height // 2). |
313 |
downOrigin := 0 @ (height // 2 + 1). |
|
314 |
downCorner := (width - 1) @ (height - 1) |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
315 |
] ifFalse:[ |
899 | 316 |
upCorner := (width // 2) @ (height - 1). |
317 |
downOrigin := (width // 2 + 1) @ 0. |
|
318 |
downCorner := (width - 1) @ (height - 1) |
|
319 |
]. |
|
320 |
||
321 |
upButton origin:upOrigin. |
|
322 |
upButton corner:upCorner. |
|
323 |
downButton origin:downOrigin. |
|
324 |
downButton corner:downCorner. |
|
325 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
326 |
! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
327 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
328 |
initializeButtonForms |
899 | 329 |
|upLabel downLabel| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
330 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
331 |
orientation == #vertical ifTrue:[ |
899 | 332 |
upLabel := ArrowButton UpArrowForm. |
333 |
downLabel := ArrowButton DownArrowForm. |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
334 |
] ifFalse:[ |
899 | 335 |
upLabel := ArrowButton LeftArrowForm. |
336 |
downLabel := ArrowButton RightArrowForm. |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
337 |
]. |
899 | 338 |
upButton label:upLabel. |
339 |
downButton label:downLabel. |
|
340 |
||
338 | 341 |
! |
342 |
||
343 |
initializeButtons |
|
779
0abab228a8fd
do not define callbacks in action blocks which do not exist
tz
parents:
651
diff
changeset
|
344 |
|
338 | 345 |
upButton := ArrowButton upIn:self. |
346 |
upButton autoRepeat:true. |
|
347 |
||
348 |
downButton := ArrowButton downIn:self. |
|
349 |
downButton autoRepeat:true. |
|
350 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
351 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
352 |
self initializeButtonForms |
338 | 353 |
! ! |
354 |
||
355 |
!UpDownButton class methodsFor:'documentation'! |
|
356 |
||
357 |
version |
|
1299 | 358 |
^ '$Header: /cvs/stx/stx/libwidg2/UpDownButton.st,v 1.13 1999-03-31 06:09:00 stefan Exp $' |
338 | 359 |
! ! |