0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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
|
3
|
14 |
instanceVariableNames:'label layout fgColor'
|
0
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
FramedBox comment:'
|
|
21 |
|
5
|
22 |
COPYRIGHT (c) 1991 by Claus Gittinger
|
0
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
a frame around something. The frame may have a label, whose position
|
|
26 |
is controlled by the layout variable, aSymbol which may be one of:
|
|
27 |
[#topCenter #topLeft #topRight #bottomLeft #bottomCenter #bottomRight]
|
|
28 |
|
25
|
29 |
$Header: /cvs/stx/stx/libwidg/FramedBox.st,v 1.6 1994-01-16 04:01:45 claus Exp $
|
0
|
30 |
written spring 91 by claus
|
|
31 |
'!
|
|
32 |
|
3
|
33 |
!FramedBox methodsFor:'private'!
|
|
34 |
|
|
35 |
redrawIfShown
|
|
36 |
shown ifTrue:[
|
|
37 |
self clear.
|
|
38 |
self redraw
|
|
39 |
]
|
|
40 |
! !
|
|
41 |
|
0
|
42 |
!FramedBox methodsFor:'accessing'!
|
|
43 |
|
3
|
44 |
foregroundColor
|
|
45 |
"return the frame labels foreground color"
|
|
46 |
|
|
47 |
^ fgColor
|
|
48 |
!
|
|
49 |
|
|
50 |
foregroundColor:aColor
|
|
51 |
"set the frame labels foreground color"
|
|
52 |
|
|
53 |
aColor ~= fgColor ifTrue:[
|
|
54 |
fgColor := aColor.
|
|
55 |
self redrawIfShown
|
|
56 |
]
|
|
57 |
!
|
|
58 |
|
|
59 |
|
0
|
60 |
label
|
3
|
61 |
"return the frames labelstring"
|
|
62 |
|
0
|
63 |
^ label
|
|
64 |
!
|
|
65 |
|
|
66 |
label:aString
|
3
|
67 |
"set the frames labelstring"
|
|
68 |
|
0
|
69 |
(label ~= aString) ifTrue:[
|
|
70 |
label := aString.
|
3
|
71 |
self redrawIfShown
|
0
|
72 |
]
|
|
73 |
!
|
|
74 |
|
|
75 |
font:aFont
|
3
|
76 |
"set the frame labelstrings font"
|
|
77 |
|
0
|
78 |
(font ~= aFont) ifTrue:[
|
|
79 |
super font:aFont.
|
3
|
80 |
self redrawIfShown
|
0
|
81 |
]
|
|
82 |
!
|
|
83 |
|
|
84 |
viewRectangle
|
|
85 |
"return the inside area - redefined to save frame from
|
|
86 |
relative computations"
|
|
87 |
|
|
88 |
|m2 sep|
|
|
89 |
|
|
90 |
sep := font height.
|
25
|
91 |
m2 := sep + sep "+ sep".
|
0
|
92 |
|
|
93 |
^ (sep @ sep) extent:((width - m2) @ (height - m2))
|
|
94 |
!
|
|
95 |
|
|
96 |
layout
|
|
97 |
^ layout
|
|
98 |
!
|
|
99 |
|
|
100 |
layout:aSymbol
|
|
101 |
"define the position of the label;
|
|
102 |
aSymbol may be: topLeft, topCenter, topRight;
|
|
103 |
bottomLeft, bottomCenter or bottomRight"
|
|
104 |
|
3
|
105 |
layout ~~ aSymbol ifTrue:[
|
|
106 |
layout := aSymbol.
|
|
107 |
self redrawIfShown
|
|
108 |
]
|
0
|
109 |
! !
|
|
110 |
|
|
111 |
!FramedBox methodsFor:'events'!
|
|
112 |
|
|
113 |
sizeChanged:how
|
3
|
114 |
self redrawIfShown.
|
0
|
115 |
super sizeChanged:how
|
|
116 |
! !
|
|
117 |
|
|
118 |
!FramedBox methodsFor:'drawing'!
|
|
119 |
|
|
120 |
drawFrame
|
|
121 |
"redraw the frame"
|
|
122 |
|
|
123 |
|sep halfSep right bot left top bm1 rm3|
|
|
124 |
|
|
125 |
sep := font height.
|
|
126 |
halfSep := sep // 2.
|
|
127 |
self is3D ifFalse:[
|
24
|
128 |
self displayRectangleX:halfSep y:halfSep
|
|
129 |
width:(width - sep) height:(height - sep).
|
0
|
130 |
^ self
|
|
131 |
].
|
|
132 |
self paint:lightColor.
|
|
133 |
right := width - halfSep.
|
|
134 |
bot := height - halfSep.
|
24
|
135 |
self displayRectangleX:halfSep y:halfSep
|
|
136 |
width:(width - sep) height:(height - sep + 1).
|
7
|
137 |
|
0
|
138 |
self paint:shadowColor.
|
|
139 |
left := halfSep - 1.
|
|
140 |
top := halfSep - 1.
|
|
141 |
bm1 := bot - 1.
|
7
|
142 |
self displayLineFromX:left y:top toX:(right - 1) y:top.
|
|
143 |
self displayLineFromX:left y:top toX:left y:bm1.
|
0
|
144 |
|
|
145 |
rm3 := right - 3.
|
7
|
146 |
"
|
|
147 |
self displayLineFromX:rm3 y:(halfSep + 1) toX:rm3 y:bm1.
|
|
148 |
self displayLineFromX:(halfSep + 2) y:(bot - 2) toX:(right - 2) y:(bot - 2)
|
|
149 |
"
|
|
150 |
self displayLineFromX:rm3 y:(halfSep + 1) toX:rm3 y:bm1-1.
|
|
151 |
self displayLineFromX:(halfSep + 2) y:(bot - 2) toX:(right - 2 - 1) y:(bot - 2)
|
0
|
152 |
!
|
|
153 |
|
|
154 |
redraw
|
|
155 |
"redraw the frame and name if present"
|
|
156 |
|
|
157 |
|labelLen l x y|
|
|
158 |
|
|
159 |
label isNil ifTrue:[
|
|
160 |
l := ' '.
|
|
161 |
labelLen := 0
|
|
162 |
] ifFalse:[
|
|
163 |
l := ' ' , label , ' '.
|
|
164 |
labelLen := font widthOf:l
|
|
165 |
].
|
|
166 |
|
|
167 |
self drawFrame.
|
|
168 |
labelLen > 0 ifTrue:[
|
|
169 |
labelLen < width ifTrue:[
|
|
170 |
(#(topLeft topCenter topRight) includes:layout) ifTrue:[
|
|
171 |
y := font ascent.
|
|
172 |
] ifFalse:[
|
|
173 |
y := height - font descent.
|
|
174 |
].
|
|
175 |
(#(topLeft bottomLeft) includes:layout) ifTrue:[
|
|
176 |
x := font height
|
|
177 |
] ifFalse:[
|
|
178 |
(#(topRight bottomRight) includes:layout) ifTrue:[
|
|
179 |
x := width - labelLen - font height
|
|
180 |
] ifFalse:[
|
|
181 |
x := (width - labelLen) // 2
|
|
182 |
]
|
|
183 |
].
|
3
|
184 |
self paint:fgColor on:viewBackground.
|
0
|
185 |
self displayOpaqueString:l x:x y:y
|
|
186 |
]
|
|
187 |
]
|
|
188 |
! !
|
|
189 |
|
|
190 |
!FramedBox methodsFor:'initialization'!
|
|
191 |
|
|
192 |
initStyle
|
|
193 |
"default position is top-center, except for ms-windows, where
|
|
194 |
the text is positioned at top-left"
|
|
195 |
|
|
196 |
super initStyle.
|
3
|
197 |
fgColor := Black.
|
0
|
198 |
style == #mswindows ifTrue:[
|
|
199 |
layout := #topLeft
|
|
200 |
] ifFalse:[
|
|
201 |
layout := #topCenter
|
|
202 |
]
|
|
203 |
! !
|