author | Claus Gittinger <cg@exept.de> |
Fri, 22 May 1998 14:09:01 +0200 | |
changeset 899 | 68770c9d162d |
parent 868 | 0fa479aee842 |
child 912 | e4b45ee7df6d |
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. |
|
140 |
shown ifTrue:[self invalidate] |
|
141 |
] |
|
142 |
! |
|
143 |
||
144 |
foregroundColor |
|
899 | 145 |
"return the foregroundColor" |
818 | 146 |
|
852 | 147 |
^upButton foregroundColor |
818 | 148 |
|
149 |
! |
|
150 |
||
151 |
foregroundColor:aColor |
|
899 | 152 |
"set the foregroundColor" |
818 | 153 |
|
154 |
aColor ~~ upButton foregroundColor ifTrue:[ |
|
155 |
upButton foregroundColor:aColor. |
|
156 |
downButton foregroundColor:aColor. |
|
157 |
shown ifTrue:[self invalidate] |
|
158 |
] |
|
159 |
! |
|
160 |
||
161 |
model:aModel |
|
162 |
"ignore models" |
|
163 |
! ! |
|
164 |
||
338 | 165 |
!UpDownButton methodsFor:'accessing-components'! |
166 |
||
167 |
downButton |
|
899 | 168 |
"return the downButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
169 |
|
338 | 170 |
^ downButton |
171 |
! |
|
172 |
||
173 |
upButton |
|
899 | 174 |
"return the upButton" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
175 |
|
338 | 176 |
^ upButton |
177 |
! ! |
|
178 |
||
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
179 |
!UpDownButton methodsFor:'accessing-look'! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
180 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
181 |
orientation |
899 | 182 |
"return the orientation (a symbol)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
183 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
184 |
^ orientation |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
185 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
186 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
187 |
orientation:aSymbol |
899 | 188 |
"set the orientation (#horizontal or #vertical)" |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
189 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
190 |
orientation := aSymbol. |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
191 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
192 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
193 |
self initializeButtonForms |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
194 |
! ! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
195 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
196 |
!UpDownButton methodsFor:'change & update'! |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
197 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
198 |
sizeChanged:how |
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 |
super sizeChanged:how. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
201 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
202 |
self initializeButtonDimensions |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
203 |
! ! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
204 |
|
899 | 205 |
!UpDownButton methodsFor:'displaying'! |
206 |
||
207 |
showFocus:explicit |
|
208 |
"display myself as having-focus" |
|
209 |
||
210 |
(upButton enabled or:[downButton enabled]) ifTrue: [super showFocus:explicit] |
|
211 |
! ! |
|
212 |
||
868 | 213 |
!UpDownButton methodsFor:'event handling'! |
214 |
||
215 |
keyPress:aKey x:x y:y |
|
216 |
"simulate a buttonPress/release" |
|
217 |
||
218 |
|theButton theController| |
|
219 |
||
220 |
((aKey == #CursorUp) |
|
221 |
or:[aKey == #CursorRight |
|
222 |
or:[aKey == $+]]) ifTrue:[ |
|
223 |
theButton := upButton |
|
224 |
] ifFalse:[ |
|
225 |
((aKey == #CursorDown) |
|
226 |
or:[aKey == #CursorLeft |
|
227 |
or:[aKey == $-]]) ifTrue:[ |
|
228 |
theButton := downButton |
|
229 |
]. |
|
230 |
]. |
|
231 |
theButton notNil ifTrue:[ |
|
232 |
theController := theButton controller. |
|
233 |
theController pressed:true. |
|
234 |
theController pressed:false. |
|
235 |
^ self |
|
236 |
]. |
|
237 |
^ super keyPress:aKey x:x y:y |
|
238 |
||
239 |
"Created: / 21.4.1998 / 19:48:28 / cg" |
|
240 |
"Modified: / 21.4.1998 / 19:56:28 / cg" |
|
241 |
! ! |
|
242 |
||
338 | 243 |
!UpDownButton methodsFor:'initialization'! |
244 |
||
245 |
initialize |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
246 |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
247 |
orientation := #vertical. |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
248 |
|
338 | 249 |
super initialize. |
250 |
self initializeButtons |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
251 |
! |
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
252 |
|
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
253 |
initializeButtonDimensions |
899 | 254 |
|upOrigin downOrigin upCorner downCorner| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
255 |
|
899 | 256 |
upOrigin := 0@0. |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
257 |
orientation == #vertical ifTrue:[ |
899 | 258 |
upCorner := (width - 1) @ (height // 2). |
259 |
downOrigin := 0 @ (height // 2 + 1). |
|
260 |
downCorner := (width - 1) @ (height - 1) |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
261 |
] ifFalse:[ |
899 | 262 |
upCorner := (width // 2) @ (height - 1). |
263 |
downOrigin := (width // 2 + 1) @ 0. |
|
264 |
downCorner := (width - 1) @ (height - 1) |
|
265 |
]. |
|
266 |
||
267 |
upButton origin:upOrigin. |
|
268 |
upButton corner:upCorner. |
|
269 |
downButton origin:downOrigin. |
|
270 |
downButton corner:downCorner. |
|
271 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
272 |
! |
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
273 |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
274 |
initializeButtonForms |
899 | 275 |
|upLabel downLabel| |
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
276 |
|
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
277 |
orientation == #vertical ifTrue:[ |
899 | 278 |
upLabel := ArrowButton UpArrowForm. |
279 |
downLabel := ArrowButton DownArrowForm. |
|
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
280 |
] ifFalse:[ |
899 | 281 |
upLabel := ArrowButton LeftArrowForm. |
282 |
downLabel := ArrowButton RightArrowForm. |
|
340
c02e5db9b6f5
added left-right orientation.
Claus Gittinger <cg@exept.de>
parents:
338
diff
changeset
|
283 |
]. |
899 | 284 |
upButton label:upLabel. |
285 |
downButton label:downLabel. |
|
286 |
||
338 | 287 |
! |
288 |
||
289 |
initializeButtons |
|
779
0abab228a8fd
do not define callbacks in action blocks which do not exist
tz
parents:
651
diff
changeset
|
290 |
|
338 | 291 |
upButton := ArrowButton upIn:self. |
292 |
upButton autoRepeat:true. |
|
293 |
||
294 |
downButton := ArrowButton downIn:self. |
|
295 |
downButton autoRepeat:true. |
|
296 |
||
788
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
297 |
self initializeButtonDimensions. |
826f9374823b
take forms from the ArrowButton + resizing behavior added
tz
parents:
779
diff
changeset
|
298 |
self initializeButtonForms |
338 | 299 |
! ! |
300 |
||
301 |
!UpDownButton class methodsFor:'documentation'! |
|
302 |
||
303 |
version |
|
899 | 304 |
^ '$Header: /cvs/stx/stx/libwidg2/UpDownButton.st,v 1.10 1998-05-22 12:09:01 cg Exp $' |
338 | 305 |
! ! |