|
1 " |
|
2 COPYRIGHT (c) 1991-93 by Claus Gittinger |
|
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 |
|
14 instanceVariableNames:'label layout' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'Views-Layout' |
|
18 ! |
|
19 |
|
20 FramedBox comment:' |
|
21 |
|
22 COPYRIGHT (c) 1991-93 by Claus Gittinger |
|
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 |
|
29 %W% %E% |
|
30 written spring 91 by claus |
|
31 '! |
|
32 |
|
33 !FramedBox methodsFor:'accessing'! |
|
34 |
|
35 label |
|
36 ^ label |
|
37 ! |
|
38 |
|
39 label:aString |
|
40 (label ~= aString) ifTrue:[ |
|
41 label := aString. |
|
42 shown ifTrue:[ |
|
43 self clear. |
|
44 self redraw |
|
45 ] |
|
46 ] |
|
47 ! |
|
48 |
|
49 font:aFont |
|
50 (font ~= aFont) ifTrue:[ |
|
51 super font:aFont. |
|
52 shown ifTrue:[ |
|
53 self clear. |
|
54 self redraw |
|
55 ] |
|
56 ] |
|
57 ! |
|
58 |
|
59 viewRectangle |
|
60 "return the inside area - redefined to save frame from |
|
61 relative computations" |
|
62 |
|
63 |m2 sep| |
|
64 |
|
65 sep := font height. |
|
66 m2 := sep + sep + sep. |
|
67 |
|
68 ^ (sep @ sep) extent:((width - m2) @ (height - m2)) |
|
69 ! |
|
70 |
|
71 layout |
|
72 ^ layout |
|
73 ! |
|
74 |
|
75 layout:aSymbol |
|
76 "define the position of the label; |
|
77 aSymbol may be: topLeft, topCenter, topRight; |
|
78 bottomLeft, bottomCenter or bottomRight" |
|
79 |
|
80 layout := aSymbol. |
|
81 self clear. |
|
82 self redraw |
|
83 ! ! |
|
84 |
|
85 !FramedBox methodsFor:'events'! |
|
86 |
|
87 sizeChanged:how |
|
88 shown ifTrue:[ |
|
89 self clear. |
|
90 self redraw |
|
91 ]. |
|
92 super sizeChanged:how |
|
93 ! ! |
|
94 |
|
95 !FramedBox methodsFor:'drawing'! |
|
96 |
|
97 drawFrame |
|
98 "redraw the frame" |
|
99 |
|
100 |sep halfSep right bot left top bm1 rm3| |
|
101 |
|
102 sep := font height. |
|
103 halfSep := sep // 2. |
|
104 self is3D ifFalse:[ |
|
105 self drawRectangleX:halfSep y:halfSep |
|
106 width:(width - sep) height:(height - sep). |
|
107 ^ self |
|
108 ]. |
|
109 self paint:lightColor. |
|
110 right := width - halfSep. |
|
111 bot := height - halfSep. |
|
112 self drawRectangleX:halfSep y:halfSep |
|
113 width:(width - sep) height:(height - sep + 1). |
|
114 self paint:shadowColor. |
|
115 |
|
116 left := halfSep - 1. |
|
117 top := halfSep - 1. |
|
118 bm1 := bot - 1. |
|
119 self displayLineFromX:left y:top |
|
120 toX:(right - 1) y:top. |
|
121 self displayLineFromX:left y:top |
|
122 toX:left y:bm1. |
|
123 |
|
124 rm3 := right - 3. |
|
125 self displayLineFromX:rm3 y:(halfSep + 1) |
|
126 toX:rm3 y:bm1. |
|
127 self displayLineFromX:(halfSep + 2) y:(bot - 2) |
|
128 toX:(right - 2) y:(bot - 2) |
|
129 ! |
|
130 |
|
131 redraw |
|
132 "redraw the frame and name if present" |
|
133 |
|
134 |labelLen l x y| |
|
135 |
|
136 label isNil ifTrue:[ |
|
137 l := ' '. |
|
138 labelLen := 0 |
|
139 ] ifFalse:[ |
|
140 l := ' ' , label , ' '. |
|
141 labelLen := font widthOf:l |
|
142 ]. |
|
143 |
|
144 self drawFrame. |
|
145 labelLen > 0 ifTrue:[ |
|
146 labelLen < width ifTrue:[ |
|
147 (#(topLeft topCenter topRight) includes:layout) ifTrue:[ |
|
148 y := font ascent. |
|
149 ] ifFalse:[ |
|
150 y := height - font descent. |
|
151 ]. |
|
152 (#(topLeft bottomLeft) includes:layout) ifTrue:[ |
|
153 x := font height |
|
154 ] ifFalse:[ |
|
155 (#(topRight bottomRight) includes:layout) ifTrue:[ |
|
156 x := width - labelLen - font height |
|
157 ] ifFalse:[ |
|
158 x := (width - labelLen) // 2 |
|
159 ] |
|
160 ]. |
|
161 self background:viewBackground. |
|
162 self displayOpaqueString:l x:x y:y |
|
163 ] |
|
164 ] |
|
165 ! ! |
|
166 |
|
167 !FramedBox methodsFor:'initialization'! |
|
168 |
|
169 initStyle |
|
170 "default position is top-center, except for ms-windows, where |
|
171 the text is positioned at top-left" |
|
172 |
|
173 super initStyle. |
|
174 style == #mswindows ifTrue:[ |
|
175 layout := #topLeft |
|
176 ] ifFalse:[ |
|
177 layout := #topCenter |
|
178 ] |
|
179 ! ! |