0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
3 |
All Rights Reserved
|
0
|
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 |
|
125
|
13 |
'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:04:53 pm'!
|
|
14 |
|
118
|
15 |
SimpleView subclass:#FramedBox
|
130
|
16 |
instanceVariableNames:'label labelPosition fgColor showFrame frame3D'
|
59
|
17 |
classVariableNames:''
|
|
18 |
poolDictionaries:''
|
|
19 |
category:'Views-Layout'
|
0
|
20 |
!
|
|
21 |
|
|
22 |
FramedBox comment:'
|
5
|
23 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
24 |
All Rights Reserved
|
0
|
25 |
|
130
|
26 |
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.12 1995-06-06 04:13:36 claus Exp $
|
38
|
27 |
'!
|
|
28 |
|
|
29 |
!FramedBox class methodsFor:'documentation'!
|
|
30 |
|
|
31 |
copyright
|
|
32 |
"
|
|
33 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
34 |
All Rights Reserved
|
0
|
35 |
|
38
|
36 |
This software is furnished under a license and may be used
|
|
37 |
only in accordance with the terms of that license and with the
|
|
38 |
inclusion of the above copyright notice. This software may not
|
|
39 |
be provided or otherwise made available to, or used by, any
|
|
40 |
other person. No title to or ownership of the software is
|
|
41 |
hereby transferred.
|
|
42 |
"
|
|
43 |
!
|
|
44 |
|
|
45 |
version
|
|
46 |
"
|
130
|
47 |
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.12 1995-06-06 04:13:36 claus Exp $
|
38
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
documentation
|
|
52 |
"
|
|
53 |
a frame around something. The frame may have a label, whose position
|
130
|
54 |
is controlled by the labelPosition variable, aSymbol which may be one of:
|
38
|
55 |
[#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight]
|
|
56 |
|
|
57 |
Its also possible, to not show the frame but only the label, by setting
|
|
58 |
showFrame to false.
|
|
59 |
"
|
0
|
60 |
!
|
|
61 |
|
125
|
62 |
examples
|
|
63 |
"
|
|
64 |
simple:
|
|
65 |
|
|
66 |
|top frame1 frame2 frame3|
|
|
67 |
|
|
68 |
top := StandardSystemView new.
|
|
69 |
top extent:300@200.
|
|
70 |
|
|
71 |
frame1 := FramedBox origin:0.0@0.0 corner:0.5@0.5 in:top.
|
|
72 |
frame1 label:'frame1'.
|
3
|
73 |
|
125
|
74 |
frame2 := FramedBox origin:0.5@0.0 corner:1.0@0.5 in:top.
|
|
75 |
frame2 label:'frame2'.
|
|
76 |
|
|
77 |
frame3 := FramedBox origin:0.0@0.5 corner:1.0@1.0 in:top.
|
|
78 |
frame3 label:'frame3'.
|
0
|
79 |
|
125
|
80 |
top open
|
|
81 |
|
|
82 |
|
|
83 |
placing something inside:
|
|
84 |
|
|
85 |
|top frame1 frame2 frame3 v1 v2 v3|
|
3
|
86 |
|
125
|
87 |
top := StandardSystemView new.
|
|
88 |
top extent:300@200.
|
|
89 |
|
|
90 |
frame1 := FramedBox origin:0.0@0.0 corner:0.5@0.5 in:top.
|
|
91 |
frame1 label:'frame1'.
|
|
92 |
v1 := View origin:0.0@0.0 corner:1.0@1.0 in:frame1.
|
|
93 |
v1 viewBackground:(Color yellow);
|
|
94 |
level:1.
|
|
95 |
|
|
96 |
frame2 := FramedBox origin:0.5@0.0 corner:1.0@0.5 in:top.
|
|
97 |
frame2 label:'frame2'.
|
|
98 |
v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2.
|
|
99 |
v2 viewBackground:(Color red);
|
|
100 |
level:1.
|
0
|
101 |
|
125
|
102 |
frame3 := FramedBox origin:0.0@0.5 corner:1.0@1.0 in:top.
|
|
103 |
frame3 label:'frame3'.
|
|
104 |
v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3.
|
|
105 |
v3 viewBackground:(Color green);
|
|
106 |
level:1.
|
0
|
107 |
|
125
|
108 |
top open
|
|
109 |
|
0
|
110 |
|
125
|
111 |
placing something inside a frame in a dialog:
|
|
112 |
|
|
113 |
|box panel frame1 frame2 frame3 v1 v1b v2 v3|
|
|
114 |
|
|
115 |
box := Dialog new.
|
0
|
116 |
|
125
|
117 |
frame1 := FramedBox label:'frame1'.
|
|
118 |
panel := HorizontalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame1.
|
|
119 |
v1 := View extent:100@100 in:panel.
|
|
120 |
v1 viewBackground:(Color red);
|
|
121 |
level:1.
|
|
122 |
v1b := View extent:100@100 in:panel.
|
|
123 |
v1b viewBackground:(Color yellow);
|
|
124 |
level:1.
|
|
125 |
|
|
126 |
box addComponent:frame1.
|
0
|
127 |
|
125
|
128 |
frame2 := FramedBox label:'frame2'.
|
|
129 |
v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2.
|
|
130 |
v2 viewBackground:(Color green);
|
|
131 |
level:1.
|
|
132 |
box addComponent:frame2.
|
38
|
133 |
|
125
|
134 |
frame3 := FramedBox label:'frame3'.
|
|
135 |
v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3.
|
|
136 |
v3 viewBackground:(Color blue);
|
|
137 |
level:1.
|
|
138 |
box addComponent:frame3.
|
|
139 |
|
|
140 |
box addOkButton.
|
|
141 |
box open
|
|
142 |
|
|
143 |
|
|
144 |
placing something inside a frame in a dialog:
|
0
|
145 |
|
125
|
146 |
|box panel frame1 frame2 frame3 v1 v1b v2 v3|
|
|
147 |
|
|
148 |
box := Dialog new.
|
|
149 |
|
|
150 |
frame1 := FramedBox label:'frame1'.
|
|
151 |
panel := VerticalPanelView origin:0.0@0.0 corner:1.0@1.0 in:frame1.
|
|
152 |
v1 := View extent:100@100 in:panel.
|
|
153 |
v1 viewBackground:(Color red);
|
|
154 |
level:1.
|
|
155 |
v1b := View extent:100@100 in:panel.
|
|
156 |
v1b viewBackground:(Color yellow);
|
|
157 |
level:1.
|
|
158 |
|
|
159 |
box addComponent:frame1.
|
0
|
160 |
|
125
|
161 |
frame2 := FramedBox label:'frame2'.
|
|
162 |
v2 := View origin:0.0@0.0 corner:1.0@1.0 in:frame2.
|
|
163 |
v2 viewBackground:(Color green);
|
|
164 |
level:1.
|
|
165 |
box addComponent:frame2.
|
0
|
166 |
|
125
|
167 |
frame3 := FramedBox label:'frame3'.
|
|
168 |
v3 := View origin:0.0@0.0 corner:1.0@1.0 in:frame3.
|
|
169 |
v3 viewBackground:(Color blue);
|
|
170 |
level:1.
|
|
171 |
box addComponent:frame3.
|
0
|
172 |
|
125
|
173 |
box addOkButton.
|
|
174 |
box open
|
|
175 |
"
|
0
|
176 |
! !
|
|
177 |
|
|
178 |
!FramedBox methodsFor:'drawing'!
|
|
179 |
|
|
180 |
drawFrame
|
|
181 |
"redraw the frame"
|
|
182 |
|
38
|
183 |
|sep halfSep w h|
|
0
|
184 |
|
38
|
185 |
"
|
|
186 |
if there is no label, give more real estate to the inside
|
|
187 |
"
|
|
188 |
label isNil ifTrue:[
|
59
|
189 |
halfSep := 2
|
38
|
190 |
] ifFalse:[
|
59
|
191 |
halfSep := font height // 2.
|
38
|
192 |
].
|
59
|
193 |
sep := halfSep * 2.
|
38
|
194 |
|
|
195 |
w := width - sep.
|
|
196 |
h := height - sep.
|
|
197 |
|
59
|
198 |
frame3D ifFalse:[
|
|
199 |
self displayRectangleX:halfSep
|
|
200 |
y:halfSep
|
|
201 |
width:w
|
|
202 |
height:h.
|
|
203 |
^ self
|
0
|
204 |
].
|
38
|
205 |
|
|
206 |
w := w + 1.
|
|
207 |
h := h + 1.
|
7
|
208 |
|
0
|
209 |
self paint:shadowColor.
|
38
|
210 |
self displayRectangleX:halfSep-1
|
59
|
211 |
y:halfSep-1
|
|
212 |
width:w
|
|
213 |
height:h.
|
0
|
214 |
|
38
|
215 |
self paint:lightColor.
|
|
216 |
self displayRectangleX:halfSep
|
59
|
217 |
y:halfSep
|
|
218 |
width:w
|
|
219 |
height:h
|
0
|
220 |
!
|
|
221 |
|
|
222 |
redraw
|
|
223 |
"redraw the frame and name if present"
|
|
224 |
|
|
225 |
|labelLen l x y|
|
|
226 |
|
|
227 |
label isNil ifTrue:[
|
59
|
228 |
labelLen := 0
|
0
|
229 |
] ifFalse:[
|
59
|
230 |
l := ' ' , label , ' '.
|
|
231 |
labelLen := font widthOf:l
|
0
|
232 |
].
|
|
233 |
|
38
|
234 |
showFrame ifTrue:[
|
59
|
235 |
self drawFrame.
|
38
|
236 |
].
|
|
237 |
|
0
|
238 |
labelLen > 0 ifTrue:[
|
59
|
239 |
labelLen < width ifTrue:[
|
130
|
240 |
(labelPosition == #topLeft
|
|
241 |
or:[labelPosition == #topCenter
|
|
242 |
or:[labelPosition == #topRight]]) ifTrue:[
|
|
243 |
"
|
|
244 |
label at top
|
|
245 |
"
|
59
|
246 |
y := font ascent.
|
|
247 |
] ifFalse:[
|
130
|
248 |
"
|
|
249 |
label at bottom
|
|
250 |
"
|
59
|
251 |
y := height - font descent.
|
|
252 |
].
|
130
|
253 |
(labelPosition == #topLeft
|
|
254 |
or:[labelPosition == #bottomLeft]) ifTrue:[
|
|
255 |
"
|
|
256 |
label at left
|
|
257 |
"
|
59
|
258 |
x := font height
|
|
259 |
] ifFalse:[
|
130
|
260 |
(labelPosition == #topRight
|
|
261 |
or:[labelPosition == #bottomRight]) ifTrue:[
|
|
262 |
"
|
|
263 |
label at right
|
|
264 |
"
|
59
|
265 |
x := width - labelLen - font height
|
|
266 |
] ifFalse:[
|
130
|
267 |
"
|
|
268 |
label at center
|
|
269 |
"
|
59
|
270 |
x := (width - labelLen) // 2
|
|
271 |
]
|
|
272 |
].
|
|
273 |
self paint:fgColor on:viewBackground.
|
|
274 |
self displayOpaqueString:l x:x y:y
|
|
275 |
]
|
0
|
276 |
]
|
|
277 |
! !
|
|
278 |
|
125
|
279 |
!FramedBox methodsFor:'queries'!
|
|
280 |
|
|
281 |
viewRectangle
|
|
282 |
"return the inside area
|
|
283 |
- redefined to save frame from relative computations."
|
|
284 |
|
|
285 |
|m2 sep|
|
|
286 |
|
|
287 |
sep := font height.
|
|
288 |
m2 := sep + sep.
|
|
289 |
|
|
290 |
showFrame ifFalse:[
|
|
291 |
^ (0 @ sep) extent:(width @ (height - m2))
|
|
292 |
].
|
|
293 |
^ (sep @ sep) extent:((width - m2) @ (height - m2))
|
|
294 |
|
|
295 |
"/ |m2 sepH sepV|
|
|
296 |
"/
|
|
297 |
"/ sepV := font height.
|
|
298 |
"/
|
|
299 |
"/ showFrame ifFalse:[
|
|
300 |
"/ ^ (0 @ sepV) extent:(width @ (height - sepV - sepV))
|
|
301 |
"/ ].
|
|
302 |
"/ sepH := sepV // 2.
|
|
303 |
"/ ^ (sepH @ sepH) extent:((width - sepH - sepH) @ (height - sepV - sepV))
|
|
304 |
!
|
|
305 |
|
130
|
306 |
preferredExtent
|
125
|
307 |
"redefined to add space for the frame to the default extent"
|
|
308 |
|
|
309 |
|m2 sep|
|
|
310 |
|
|
311 |
sep := font height.
|
|
312 |
m2 := sep + sep.
|
|
313 |
|
|
314 |
showFrame ifFalse:[
|
130
|
315 |
^ super preferredExtent + (0 @ m2)
|
125
|
316 |
].
|
130
|
317 |
^ super preferredExtent+(m2 @ m2)
|
125
|
318 |
! !
|
|
319 |
|
|
320 |
!FramedBox methodsFor:'private'!
|
|
321 |
|
|
322 |
redrawIfShown
|
|
323 |
shown ifTrue:[
|
|
324 |
self clear.
|
|
325 |
self redraw
|
|
326 |
]
|
|
327 |
! !
|
|
328 |
|
|
329 |
!FramedBox methodsFor:'accessing'!
|
|
330 |
|
|
331 |
label:aString
|
|
332 |
"set the frames labelstring"
|
|
333 |
|
|
334 |
(label ~= aString) ifTrue:[
|
|
335 |
label := aString.
|
|
336 |
self redrawIfShown
|
|
337 |
]
|
|
338 |
!
|
|
339 |
|
|
340 |
foregroundColor
|
|
341 |
"return the frame labels foreground color"
|
|
342 |
|
|
343 |
^ fgColor
|
|
344 |
!
|
|
345 |
|
|
346 |
foregroundColor:aColor
|
|
347 |
"set the frame labels foreground color"
|
|
348 |
|
|
349 |
aColor ~= fgColor ifTrue:[
|
|
350 |
fgColor := aColor.
|
|
351 |
self redrawIfShown
|
|
352 |
]
|
|
353 |
!
|
|
354 |
|
|
355 |
frameShown
|
|
356 |
"return true, if frame is shown;
|
|
357 |
if false, oly the label is shown"
|
|
358 |
|
|
359 |
^ showFrame
|
|
360 |
!
|
|
361 |
|
|
362 |
showFrame:aBoolean
|
|
363 |
"turn on/off showing of the frame -
|
|
364 |
without a frame, only the label is shown at its position"
|
|
365 |
|
|
366 |
aBoolean ~~ showFrame ifTrue:[
|
|
367 |
showFrame := aBoolean.
|
|
368 |
self redrawIfShown
|
|
369 |
]
|
|
370 |
!
|
|
371 |
|
|
372 |
label
|
|
373 |
"return the frames labelstring"
|
|
374 |
|
|
375 |
^ label
|
|
376 |
!
|
|
377 |
|
|
378 |
font:aFont
|
|
379 |
"set the frame labelstrings font"
|
|
380 |
|
|
381 |
(font ~= aFont) ifTrue:[
|
|
382 |
super font:aFont.
|
|
383 |
self redrawIfShown
|
|
384 |
]
|
|
385 |
!
|
|
386 |
|
130
|
387 |
labelPosition
|
|
388 |
"return the labelPosition, which is a symbol describing
|
125
|
389 |
the labels position."
|
|
390 |
|
130
|
391 |
^ labelPosition
|
|
392 |
!
|
|
393 |
|
|
394 |
labelPosition:aSymbol
|
|
395 |
"define the position of the label;
|
|
396 |
aSymbol may be one of:
|
|
397 |
#topLeft, #topCenter, #topRight;
|
|
398 |
#bottomLeft, #bottomCenter or #bottomRight"
|
|
399 |
|
|
400 |
labelPosition ~~ aSymbol ifTrue:[
|
|
401 |
labelPosition := aSymbol.
|
|
402 |
self redrawIfShown
|
|
403 |
]
|
|
404 |
!
|
|
405 |
|
|
406 |
layout
|
|
407 |
"OBSOLETE compatibility interface. Will vanish"
|
|
408 |
|
|
409 |
self obsoleteMethodWarning:'use #labelPosition'.
|
|
410 |
^ labelPosition
|
125
|
411 |
!
|
|
412 |
|
|
413 |
layout:aSymbol
|
130
|
414 |
"OBSOLETE compatibility interface. Will vanish"
|
125
|
415 |
|
130
|
416 |
self obsoleteMethodWarning:'use #labelPosition:'.
|
|
417 |
^ self labelPosition:aSymbol
|
125
|
418 |
! !
|
|
419 |
|
0
|
420 |
!FramedBox methodsFor:'initialization'!
|
|
421 |
|
38
|
422 |
initialize
|
|
423 |
super initialize.
|
|
424 |
showFrame := true
|
|
425 |
!
|
|
426 |
|
0
|
427 |
initStyle
|
|
428 |
"default position is top-center, except for ms-windows, where
|
|
429 |
the text is positioned at top-left"
|
|
430 |
|
|
431 |
super initStyle.
|
38
|
432 |
|
59
|
433 |
fgColor := StyleSheet at:'framedBoxForegroundColor' default:Black.
|
130
|
434 |
labelPosition := StyleSheet at:'framedBoxLabelPosition' default:#topCenter.
|
59
|
435 |
frame3D := StyleSheet at:'framedBox3DFrame' default:true.
|
0
|
436 |
! !
|
125
|
437 |
|
|
438 |
!FramedBox methodsFor:'event handling'!
|
|
439 |
|
|
440 |
sizeChanged:how
|
|
441 |
self redrawIfShown.
|
|
442 |
super sizeChanged:how
|
|
443 |
! !
|
|
444 |
|