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