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 |
|
|
13 |
View subclass:#FramedBox
|
59
|
14 |
instanceVariableNames:'label layout fgColor showFrame frame3D'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
0
|
18 |
!
|
|
19 |
|
|
20 |
FramedBox comment:'
|
5
|
21 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
22 |
All Rights Reserved
|
0
|
23 |
|
70
|
24 |
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.9 1994-11-28 21:05:00 claus Exp $
|
38
|
25 |
'!
|
|
26 |
|
|
27 |
!FramedBox class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
59
|
32 |
All Rights Reserved
|
0
|
33 |
|
38
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
70
|
45 |
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.9 1994-11-28 21:05:00 claus Exp $
|
38
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a frame around something. The frame may have a label, whose position
|
|
52 |
is controlled by the layout variable, aSymbol which may be one of:
|
|
53 |
[#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight]
|
|
54 |
|
|
55 |
Its also possible, to not show the frame but only the label, by setting
|
|
56 |
showFrame to false.
|
|
57 |
"
|
|
58 |
! !
|
0
|
59 |
|
3
|
60 |
!FramedBox methodsFor:'private'!
|
|
61 |
|
|
62 |
redrawIfShown
|
|
63 |
shown ifTrue:[
|
59
|
64 |
self clear.
|
|
65 |
self redraw
|
3
|
66 |
]
|
|
67 |
! !
|
|
68 |
|
0
|
69 |
!FramedBox methodsFor:'accessing'!
|
|
70 |
|
3
|
71 |
foregroundColor
|
|
72 |
"return the frame labels foreground color"
|
|
73 |
|
|
74 |
^ fgColor
|
|
75 |
!
|
|
76 |
|
|
77 |
foregroundColor:aColor
|
|
78 |
"set the frame labels foreground color"
|
|
79 |
|
|
80 |
aColor ~= fgColor ifTrue:[
|
59
|
81 |
fgColor := aColor.
|
|
82 |
self redrawIfShown
|
3
|
83 |
]
|
|
84 |
!
|
|
85 |
|
38
|
86 |
frameShown
|
|
87 |
"return true, if frame is shown;
|
|
88 |
if false, oly the label is shown"
|
|
89 |
|
|
90 |
^ showFrame
|
|
91 |
!
|
|
92 |
|
|
93 |
showFrame:aBoolean
|
|
94 |
"turn on/off showing of the frame -
|
|
95 |
without a frame, only the label is shown at its position"
|
|
96 |
|
|
97 |
aBoolean ~~ showFrame ifTrue:[
|
59
|
98 |
showFrame := aBoolean.
|
|
99 |
self redrawIfShown
|
38
|
100 |
]
|
|
101 |
!
|
3
|
102 |
|
0
|
103 |
label
|
3
|
104 |
"return the frames labelstring"
|
|
105 |
|
0
|
106 |
^ label
|
|
107 |
!
|
|
108 |
|
|
109 |
label:aString
|
3
|
110 |
"set the frames labelstring"
|
|
111 |
|
0
|
112 |
(label ~= aString) ifTrue:[
|
59
|
113 |
label := aString.
|
|
114 |
self redrawIfShown
|
0
|
115 |
]
|
|
116 |
!
|
|
117 |
|
|
118 |
font:aFont
|
3
|
119 |
"set the frame labelstrings font"
|
|
120 |
|
0
|
121 |
(font ~= aFont) ifTrue:[
|
59
|
122 |
super font:aFont.
|
|
123 |
self redrawIfShown
|
0
|
124 |
]
|
|
125 |
!
|
|
126 |
|
|
127 |
viewRectangle
|
|
128 |
"return the inside area - redefined to save frame from
|
|
129 |
relative computations"
|
|
130 |
|
|
131 |
|m2 sep|
|
|
132 |
|
|
133 |
sep := font height.
|
25
|
134 |
m2 := sep + sep "+ sep".
|
0
|
135 |
|
38
|
136 |
showFrame ifFalse:[
|
59
|
137 |
^ (0 @ sep) extent:(width @ height)
|
38
|
138 |
].
|
|
139 |
^ (sep @ sep) extent:((width - sep) @ (height - sep))
|
0
|
140 |
!
|
|
141 |
|
|
142 |
layout
|
38
|
143 |
"return the current layout, which is a symbol describing
|
|
144 |
the labels position."
|
|
145 |
|
0
|
146 |
^ layout
|
|
147 |
!
|
|
148 |
|
|
149 |
layout:aSymbol
|
|
150 |
"define the position of the label;
|
38
|
151 |
aSymbol may be: #topLeft, #topCenter, #topRight;
|
|
152 |
#bottomLeft, #bottomCenter or #bottomRight"
|
0
|
153 |
|
3
|
154 |
layout ~~ aSymbol ifTrue:[
|
59
|
155 |
layout := aSymbol.
|
|
156 |
self redrawIfShown
|
3
|
157 |
]
|
0
|
158 |
! !
|
|
159 |
|
70
|
160 |
!FramedBox methodsFor:'event handling'!
|
0
|
161 |
|
|
162 |
sizeChanged:how
|
3
|
163 |
self redrawIfShown.
|
0
|
164 |
super sizeChanged:how
|
|
165 |
! !
|
|
166 |
|
|
167 |
!FramedBox methodsFor:'drawing'!
|
|
168 |
|
|
169 |
drawFrame
|
|
170 |
"redraw the frame"
|
|
171 |
|
38
|
172 |
|sep halfSep w h|
|
0
|
173 |
|
38
|
174 |
"
|
|
175 |
if there is no label, give more real estate to the inside
|
|
176 |
"
|
|
177 |
label isNil ifTrue:[
|
59
|
178 |
halfSep := 2
|
38
|
179 |
] ifFalse:[
|
59
|
180 |
halfSep := font height // 2.
|
38
|
181 |
].
|
59
|
182 |
sep := halfSep * 2.
|
38
|
183 |
|
|
184 |
w := width - sep.
|
|
185 |
h := height - sep.
|
|
186 |
|
59
|
187 |
frame3D ifFalse:[
|
|
188 |
self displayRectangleX:halfSep
|
|
189 |
y:halfSep
|
|
190 |
width:w
|
|
191 |
height:h.
|
|
192 |
^ self
|
0
|
193 |
].
|
38
|
194 |
|
|
195 |
w := w + 1.
|
|
196 |
h := h + 1.
|
7
|
197 |
|
0
|
198 |
self paint:shadowColor.
|
38
|
199 |
self displayRectangleX:halfSep-1
|
59
|
200 |
y:halfSep-1
|
|
201 |
width:w
|
|
202 |
height:h.
|
0
|
203 |
|
38
|
204 |
self paint:lightColor.
|
|
205 |
self displayRectangleX:halfSep
|
59
|
206 |
y:halfSep
|
|
207 |
width:w
|
|
208 |
height:h
|
0
|
209 |
!
|
|
210 |
|
|
211 |
redraw
|
|
212 |
"redraw the frame and name if present"
|
|
213 |
|
|
214 |
|labelLen l x y|
|
|
215 |
|
|
216 |
label isNil ifTrue:[
|
59
|
217 |
labelLen := 0
|
0
|
218 |
] ifFalse:[
|
59
|
219 |
l := ' ' , label , ' '.
|
|
220 |
labelLen := font widthOf:l
|
0
|
221 |
].
|
|
222 |
|
38
|
223 |
showFrame ifTrue:[
|
59
|
224 |
self drawFrame.
|
38
|
225 |
].
|
|
226 |
|
0
|
227 |
labelLen > 0 ifTrue:[
|
59
|
228 |
labelLen < width ifTrue:[
|
|
229 |
(#(topLeft topCenter topRight) includes:layout) ifTrue:[
|
|
230 |
y := font ascent.
|
|
231 |
] ifFalse:[
|
|
232 |
y := height - font descent.
|
|
233 |
].
|
|
234 |
(#(topLeft bottomLeft) includes:layout) ifTrue:[
|
|
235 |
x := font height
|
|
236 |
] ifFalse:[
|
|
237 |
(#(topRight bottomRight) includes:layout) ifTrue:[
|
|
238 |
x := width - labelLen - font height
|
|
239 |
] ifFalse:[
|
|
240 |
x := (width - labelLen) // 2
|
|
241 |
]
|
|
242 |
].
|
|
243 |
self paint:fgColor on:viewBackground.
|
|
244 |
self displayOpaqueString:l x:x y:y
|
|
245 |
]
|
0
|
246 |
]
|
|
247 |
! !
|
|
248 |
|
|
249 |
!FramedBox methodsFor:'initialization'!
|
|
250 |
|
38
|
251 |
initialize
|
|
252 |
super initialize.
|
|
253 |
showFrame := true
|
|
254 |
!
|
|
255 |
|
0
|
256 |
initStyle
|
|
257 |
"default position is top-center, except for ms-windows, where
|
|
258 |
the text is positioned at top-left"
|
|
259 |
|
|
260 |
super initStyle.
|
38
|
261 |
|
59
|
262 |
fgColor := StyleSheet at:'framedBoxForegroundColor' default:Black.
|
|
263 |
layout := StyleSheet at:'framedBoxLabelPosition' default:#topCenter.
|
|
264 |
frame3D := StyleSheet at:'framedBox3DFrame' default:true.
|
0
|
265 |
! !
|