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 |
"
|
63
|
27 |
$Header: /cvs/stx/stx/libwidg2/CheckBox.st,v 1.8 1995-06-27 02:25:02 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
|
|
212 |
^ self new model:aModel
|
|
213 |
! !
|
|
214 |
|
56
|
215 |
!CheckBox methodsFor:'accessing-mvc'!
|
44
|
216 |
|
56
|
217 |
changeMessage:aChangeSelector
|
|
218 |
"forward to toggle"
|
|
219 |
|
|
220 |
toggleView changeMessage:aChangeSelector
|
55
|
221 |
!
|
|
222 |
|
56
|
223 |
aspect:aspectSymbol
|
|
224 |
"forward to label & toggle"
|
49
|
225 |
|
56
|
226 |
labelView aspect:aspectSymbol.
|
|
227 |
toggleView aspect:aspectSymbol
|
44
|
228 |
!
|
|
229 |
|
55
|
230 |
model:aModel
|
56
|
231 |
"forward to label & toggle"
|
|
232 |
|
55
|
233 |
labelView model:aModel.
|
|
234 |
toggleView model:aModel
|
56
|
235 |
! !
|
|
236 |
|
|
237 |
!CheckBox methodsFor:'accessing-behavior'!
|
|
238 |
|
|
239 |
action:aBlock
|
|
240 |
"forward to toggle"
|
|
241 |
|
|
242 |
toggleView action:aBlock
|
55
|
243 |
!
|
|
244 |
|
56
|
245 |
enable
|
|
246 |
"forward to toggle & change labels color"
|
|
247 |
|
|
248 |
toggleView enable.
|
|
249 |
labelView foregroundColor:(toggleView foregroundColor).
|
|
250 |
!
|
|
251 |
|
|
252 |
disable
|
|
253 |
"forward to toggle & change labels color"
|
|
254 |
|
|
255 |
toggleView disable.
|
|
256 |
labelView foregroundColor:(toggleView disabledForegroundColor).
|
|
257 |
!
|
|
258 |
|
|
259 |
turnOff
|
|
260 |
"forward to toggle"
|
|
261 |
|
|
262 |
toggleView turnOff
|
|
263 |
!
|
|
264 |
|
|
265 |
turnOn
|
|
266 |
"forward to toggle"
|
|
267 |
|
|
268 |
toggleView turnOn
|
|
269 |
! !
|
|
270 |
|
|
271 |
!CheckBox methodsFor:'accessing'!
|
|
272 |
|
44
|
273 |
labelView
|
49
|
274 |
"return the labelView; allows manipulation of the
|
|
275 |
labels attributes (colors etc.)"
|
|
276 |
|
44
|
277 |
^ labelView
|
|
278 |
!
|
|
279 |
|
|
280 |
toggleView
|
49
|
281 |
"return the toggleView; allows manipulation of the
|
|
282 |
toggles attributes (colors etc.)"
|
|
283 |
|
44
|
284 |
^ toggleView
|
56
|
285 |
! !
|
|
286 |
|
|
287 |
!CheckBox methodsFor:'accessing-look'!
|
44
|
288 |
|
56
|
289 |
label:aString
|
|
290 |
"forward to label & resize"
|
|
291 |
|
|
292 |
labelView label:aString.
|
|
293 |
labelView forceResize.
|
|
294 |
mustRearrange := true.
|
49
|
295 |
!
|
44
|
296 |
|
56
|
297 |
font:aFont
|
|
298 |
"forward to label & resize"
|
55
|
299 |
|
56
|
300 |
labelView font:aFont.
|
|
301 |
labelView forceResize.
|
|
302 |
mustRearrange := true.
|
49
|
303 |
!
|
|
304 |
|
56
|
305 |
font
|
|
306 |
"forward from label"
|
|
307 |
|
|
308 |
^ labelView font
|
49
|
309 |
!
|
|
310 |
|
56
|
311 |
label
|
|
312 |
"forward from label"
|
|
313 |
|
|
314 |
^ labelView label
|
|
315 |
! !
|
|
316 |
|
63
|
317 |
!CheckBox methodsFor:'queries'!
|
|
318 |
|
|
319 |
preferredExtent
|
|
320 |
|prefCheck prefLabel|
|
|
321 |
|
|
322 |
prefCheck := toggleView preferredExtent.
|
|
323 |
prefLabel := labelView preferredExtent.
|
|
324 |
^ (prefCheck x + prefLabel x + (3 * ViewSpacing)) @ (prefCheck y max:prefLabel y)
|
|
325 |
! !
|
|
326 |
|
56
|
327 |
!CheckBox methodsFor:'private'!
|
55
|
328 |
|
|
329 |
sendChangeMessageWith:aValue
|
56
|
330 |
"redefined to have mimic changes being sent from the toggle
|
|
331 |
instead of myself"
|
55
|
332 |
|
56
|
333 |
toggleView sendChangeMessageWith:aValue
|
44
|
334 |
! !
|
|
335 |
|
|
336 |
!CheckBox methodsFor:'initialization'!
|
|
337 |
|
|
338 |
initialize
|
56
|
339 |
super initialize.
|
44
|
340 |
|
56
|
341 |
borderWidth := 0.
|
44
|
342 |
|
49
|
343 |
hLayout := #fixLeftSpace.
|
44
|
344 |
vLayout := #center.
|
|
345 |
|
|
346 |
toggleView := CheckToggle in:self.
|
|
347 |
|
|
348 |
labelView := Label in:self.
|
58
|
349 |
labelView label:'check'; borderWidth:0.
|
44
|
350 |
labelView forceResize.
|
|
351 |
labelView adjust:#left.
|
62
|
352 |
self height:labelView preferredExtent y + ViewSpacing.
|
55
|
353 |
|
56
|
354 |
"
|
|
355 |
all of my input goes to the toggle
|
|
356 |
"
|
|
357 |
self delegate:(KeyboardForwarder toView:toggleView).
|
44
|
358 |
|
|
359 |
"
|
|
360 |
|b|
|
|
361 |
|
|
362 |
b := CheckBox new.
|
|
363 |
b label:'foo'.
|
|
364 |
b open
|
|
365 |
"
|
|
366 |
! !
|