44
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
49
|
3 |
All Rights Reserved
|
44
|
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 |
"
|
|
12 |
|
|
13 |
|
55
|
14 |
'From Smalltalk/X, Version:2.10.5 on 8-may-1995 at 3:48:28 am'!
|
44
|
15 |
|
|
16 |
HorizontalPanelView subclass:#CheckBox
|
|
17 |
instanceVariableNames:'toggleView labelView'
|
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Views-Interactors'
|
|
21 |
!
|
|
22 |
|
|
23 |
!CheckBox class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
version
|
|
26 |
"
|
78
|
27 |
$Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.11 1995-09-21 12:24:27 claus Exp $
|
44
|
28 |
"
|
|
29 |
!
|
|
30 |
|
|
31 |
documentation
|
|
32 |
"
|
|
33 |
CheckBox has been added somwehat in a hurry
|
|
34 |
- obviously, much more protocol is needed.
|
|
35 |
|
|
36 |
For now, set actions etc. via sends to the components,
|
|
37 |
labelView and toggleView.
|
|
38 |
"
|
|
39 |
!
|
|
40 |
|
|
41 |
examples
|
|
42 |
"
|
|
43 |
no-op checkBox:
|
|
44 |
|
|
45 |
|b|
|
|
46 |
|
|
47 |
b := CheckBox new.
|
|
48 |
b label:'foo'.
|
|
49 |
b open
|
|
50 |
|
|
51 |
|
56
|
52 |
no-op checkBox, disabled:
|
|
53 |
|
|
54 |
|b|
|
|
55 |
|
|
56 |
b := CheckBox new.
|
|
57 |
b label:'foo'.
|
|
58 |
b disable.
|
|
59 |
b open
|
|
60 |
|
|
61 |
|
|
62 |
changing colors
|
|
63 |
(a demo only: it is no good style to fight the styleSheet):
|
44
|
64 |
|
|
65 |
|panel b|
|
|
66 |
|
|
67 |
panel := VerticalPanelView new.
|
|
68 |
|
|
69 |
b := CheckBox in:panel.
|
|
70 |
b label:'foo'.
|
|
71 |
|
|
72 |
b := CheckBox in:panel.
|
|
73 |
b label:'bar'.
|
|
74 |
b labelView foregroundColor:Color red.
|
|
75 |
|
|
76 |
b := CheckBox in:panel.
|
|
77 |
b label:'baz'.
|
|
78 |
b toggleView activeForegroundColor:Color blue.
|
|
79 |
|
|
80 |
panel open
|
|
81 |
|
|
82 |
|
|
83 |
using action-blocks:
|
|
84 |
|
49
|
85 |
|b|
|
44
|
86 |
|
|
87 |
b := CheckBox new.
|
|
88 |
b label:'check'.
|
49
|
89 |
b action:[:value | Transcript show:'set to: '; showCr:value].
|
44
|
90 |
b open.
|
|
91 |
|
|
92 |
|
49
|
93 |
with a model (default ST-80 behavior, sending #value: to the model):
|
|
94 |
(see changing value in the inspector)
|
|
95 |
|
|
96 |
|b model|
|
|
97 |
|
|
98 |
model := ValueHolder newBoolean.
|
|
99 |
|
|
100 |
b := CheckBox new.
|
|
101 |
b label:'check'.
|
|
102 |
b model:model.
|
|
103 |
b open.
|
|
104 |
model inspect.
|
|
105 |
|
56
|
106 |
|
49
|
107 |
with a model and different changeSelector
|
|
108 |
(using a plug here, for demonstration only):
|
44
|
109 |
|
|
110 |
|b model|
|
|
111 |
|
|
112 |
model := Plug new.
|
|
113 |
model respondTo:#changeCheck: with:[:arg | Transcript showCr:'change to ' , arg printString].
|
|
114 |
|
|
115 |
b := CheckBox new.
|
|
116 |
b label:'check'.
|
59
|
117 |
b model:model; changeMessage:#changeCheck:.
|
44
|
118 |
b open.
|
|
119 |
|
56
|
120 |
|
|
121 |
with models, one checkBox disabling the others:
|
|
122 |
|
|
123 |
|dialog translator enableChannel val1 val2 val3 eBox box1 box2 box3|
|
|
124 |
|
|
125 |
translator := Plug new.
|
|
126 |
translator respondTo:#enableDisable
|
|
127 |
with:[enableChannel value
|
|
128 |
ifTrue:[box1 enable.
|
|
129 |
box2 enable.
|
|
130 |
box3 enable.]
|
|
131 |
ifFalse:[box1 disable.
|
|
132 |
box2 disable.
|
|
133 |
box3 disable.]].
|
|
134 |
|
|
135 |
enableChannel := true asValue.
|
|
136 |
enableChannel onChangeSend:#enableDisable to:translator.
|
|
137 |
val1 := true asValue.
|
|
138 |
val2 := false asValue.
|
|
139 |
val3 := true asValue.
|
|
140 |
|
|
141 |
dialog := Dialog new.
|
|
142 |
dialog addCheckBox:'enable' on:enableChannel.
|
|
143 |
dialog addVerticalSpace.
|
|
144 |
dialog leftIndent:30.
|
|
145 |
box1 := dialog addCheckBox:'value1' on:val1.
|
|
146 |
dialog addVerticalSpace.
|
|
147 |
box2 := dialog addCheckBox:'value2' on:val2.
|
|
148 |
dialog addVerticalSpace.
|
|
149 |
box3 := dialog addCheckBox:'value3' on:val3.
|
|
150 |
dialog addVerticalSpace.
|
|
151 |
dialog addOkButton.
|
|
152 |
|
|
153 |
dialog open.
|
|
154 |
|
|
155 |
|
49
|
156 |
multiple checkBoxes on a single model (using different aspects)
|
|
157 |
|
|
158 |
|top panel b model value1 value2 ok|
|
|
159 |
|
|
160 |
value1 := true.
|
|
161 |
value2 := false.
|
|
162 |
model := Plug new.
|
|
163 |
model respondTo:#value1 with:[value1].
|
|
164 |
model respondTo:#value1: with:[:val | value1 := val].
|
|
165 |
model respondTo:#value2 with:[value2].
|
|
166 |
model respondTo:#value2: with:[:val | value2 := val].
|
|
167 |
|
|
168 |
top := DialogBox new.
|
|
169 |
top extent:200@300.
|
|
170 |
|
|
171 |
panel := VerticalPanelView new.
|
|
172 |
|
|
173 |
b := CheckBox in:panel.
|
|
174 |
b label:'check1'.
|
59
|
175 |
b model:model; aspect:#value1; changeMessage:#value1:.
|
49
|
176 |
|
|
177 |
b := CheckBox in:panel.
|
|
178 |
b label:'check2'.
|
59
|
179 |
b model:model; aspect:#value2; changeMessage:#value2:.
|
49
|
180 |
|
|
181 |
top addComponent:panel.
|
|
182 |
top addAbortButton; addOkButton.
|
|
183 |
top okAction:[ok := true].
|
|
184 |
ok := false.
|
|
185 |
top openModal.
|
|
186 |
|
|
187 |
ok ifTrue:[
|
|
188 |
Transcript show:'value1: '; showCr:model value1.
|
|
189 |
Transcript show:'value2: '; showCr:model value2.
|
|
190 |
]
|
44
|
191 |
"
|
|
192 |
!
|
|
193 |
|
|
194 |
copyright
|
|
195 |
"
|
|
196 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
49
|
197 |
All Rights Reserved
|
44
|
198 |
|
|
199 |
This software is furnished under a license and may be used
|
|
200 |
only in accordance with the terms of that license and with the
|
|
201 |
inclusion of the above copyright notice. This software may not
|
|
202 |
be provided or otherwise made available to, or used by, any
|
|
203 |
other person. No title to or ownership of the software is
|
|
204 |
hereby transferred.
|
|
205 |
"
|
|
206 |
|
|
207 |
! !
|
|
208 |
|
62
|
209 |
!CheckBox class methodsFor:'instance creation'!
|
|
210 |
|
|
211 |
model:aModel
|
76
|
212 |
"create & return a new checkBox, on aModel (typically a ValueHolder)"
|
|
213 |
|
62
|
214 |
^ self new model:aModel
|
76
|
215 |
!
|
|
216 |
|
|
217 |
label:aStringOrImage model:aModel
|
|
218 |
"create & return a new checkBox, on aModel (typically a ValueHolder),
|
|
219 |
with aStringOrImage as label."
|
|
220 |
|
|
221 |
^ (self new model:aModel) label:aStringOrImage
|
|
222 |
|
|
223 |
"Created: 17.9.1995 / 14:20:58 / claus"
|
62
|
224 |
! !
|
|
225 |
|
56
|
226 |
!CheckBox methodsFor:'accessing-mvc'!
|
44
|
227 |
|
56
|
228 |
changeMessage:aChangeSelector
|
|
229 |
"forward to toggle"
|
|
230 |
|
|
231 |
toggleView changeMessage:aChangeSelector
|
55
|
232 |
!
|
|
233 |
|
78
|
234 |
aspectMessage:aspectSymbol
|
56
|
235 |
"forward to label & toggle"
|
49
|
236 |
|
78
|
237 |
labelView aspectMessage:aspectSymbol.
|
|
238 |
toggleView aspectMessage:aspectSymbol
|
44
|
239 |
!
|
|
240 |
|
55
|
241 |
model:aModel
|
56
|
242 |
"forward to label & toggle"
|
|
243 |
|
55
|
244 |
labelView model:aModel.
|
|
245 |
toggleView model:aModel
|
56
|
246 |
! !
|
|
247 |
|
|
248 |
!CheckBox methodsFor:'accessing-behavior'!
|
|
249 |
|
|
250 |
action:aBlock
|
|
251 |
"forward to toggle"
|
|
252 |
|
|
253 |
toggleView action:aBlock
|
55
|
254 |
!
|
|
255 |
|
56
|
256 |
enable
|
|
257 |
"forward to toggle & change labels color"
|
|
258 |
|
|
259 |
toggleView enable.
|
|
260 |
labelView foregroundColor:(toggleView foregroundColor).
|
|
261 |
!
|
|
262 |
|
|
263 |
disable
|
|
264 |
"forward to toggle & change labels color"
|
|
265 |
|
|
266 |
toggleView disable.
|
|
267 |
labelView foregroundColor:(toggleView disabledForegroundColor).
|
|
268 |
!
|
|
269 |
|
|
270 |
turnOff
|
|
271 |
"forward to toggle"
|
|
272 |
|
|
273 |
toggleView turnOff
|
|
274 |
!
|
|
275 |
|
|
276 |
turnOn
|
|
277 |
"forward to toggle"
|
|
278 |
|
|
279 |
toggleView turnOn
|
|
280 |
! !
|
|
281 |
|
|
282 |
!CheckBox methodsFor:'accessing'!
|
|
283 |
|
44
|
284 |
labelView
|
49
|
285 |
"return the labelView; allows manipulation of the
|
|
286 |
labels attributes (colors etc.)"
|
|
287 |
|
44
|
288 |
^ labelView
|
|
289 |
!
|
|
290 |
|
|
291 |
toggleView
|
49
|
292 |
"return the toggleView; allows manipulation of the
|
|
293 |
toggles attributes (colors etc.)"
|
|
294 |
|
44
|
295 |
^ toggleView
|
56
|
296 |
! !
|
|
297 |
|
78
|
298 |
!CheckBox methodsFor:'accessing-state'!
|
|
299 |
|
|
300 |
isOn
|
|
301 |
^ toggleView isOn
|
|
302 |
! !
|
|
303 |
|
56
|
304 |
!CheckBox methodsFor:'accessing-look'!
|
44
|
305 |
|
56
|
306 |
label:aString
|
|
307 |
"forward to label & resize"
|
|
308 |
|
|
309 |
labelView label:aString.
|
|
310 |
labelView forceResize.
|
|
311 |
mustRearrange := true.
|
49
|
312 |
!
|
44
|
313 |
|
56
|
314 |
font:aFont
|
|
315 |
"forward to label & resize"
|
55
|
316 |
|
56
|
317 |
labelView font:aFont.
|
|
318 |
labelView forceResize.
|
|
319 |
mustRearrange := true.
|
49
|
320 |
!
|
|
321 |
|
56
|
322 |
font
|
|
323 |
"forward from label"
|
|
324 |
|
|
325 |
^ labelView font
|
49
|
326 |
!
|
|
327 |
|
56
|
328 |
label
|
|
329 |
"forward from label"
|
|
330 |
|
|
331 |
^ labelView label
|
|
332 |
! !
|
|
333 |
|
63
|
334 |
!CheckBox methodsFor:'queries'!
|
|
335 |
|
|
336 |
preferredExtent
|
66
|
337 |
|prefCheck prefLabel bw2|
|
63
|
338 |
|
|
339 |
prefCheck := toggleView preferredExtent.
|
|
340 |
prefLabel := labelView preferredExtent.
|
66
|
341 |
bw2 := borderWidth * 2.
|
|
342 |
^ (prefCheck x + prefLabel x + (3 * ViewSpacing)) @ ((prefCheck y max:prefLabel y) + bw2 + 2)
|
63
|
343 |
! !
|
|
344 |
|
56
|
345 |
!CheckBox methodsFor:'private'!
|
55
|
346 |
|
|
347 |
sendChangeMessageWith:aValue
|
56
|
348 |
"redefined to have mimic changes being sent from the toggle
|
|
349 |
instead of myself"
|
55
|
350 |
|
56
|
351 |
toggleView sendChangeMessageWith:aValue
|
44
|
352 |
! !
|
|
353 |
|
|
354 |
!CheckBox methodsFor:'initialization'!
|
|
355 |
|
|
356 |
initialize
|
56
|
357 |
super initialize.
|
44
|
358 |
|
56
|
359 |
borderWidth := 0.
|
44
|
360 |
|
49
|
361 |
hLayout := #fixLeftSpace.
|
44
|
362 |
vLayout := #center.
|
|
363 |
|
|
364 |
toggleView := CheckToggle in:self.
|
|
365 |
|
|
366 |
labelView := Label in:self.
|
58
|
367 |
labelView label:'check'; borderWidth:0.
|
44
|
368 |
labelView forceResize.
|
|
369 |
labelView adjust:#left.
|
62
|
370 |
self height:labelView preferredExtent y + ViewSpacing.
|
55
|
371 |
|
56
|
372 |
"
|
|
373 |
all of my input goes to the toggle
|
|
374 |
"
|
|
375 |
self delegate:(KeyboardForwarder toView:toggleView).
|
44
|
376 |
|
|
377 |
"
|
|
378 |
|b|
|
|
379 |
|
|
380 |
b := CheckBox new.
|
|
381 |
b label:'foo'.
|
|
382 |
b open
|
|
383 |
"
|
|
384 |
! !
|