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