8 be provided or otherwise made available to, or used by, any |
8 be provided or otherwise made available to, or used by, any |
9 other person. No title to or ownership of the software is |
9 other person. No title to or ownership of the software is |
10 hereby transferred. |
10 hereby transferred. |
11 " |
11 " |
12 |
12 |
13 'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:05:18 pm'! |
|
14 |
|
15 SimpleView subclass:#PanelView |
13 SimpleView subclass:#PanelView |
16 instanceVariableNames:'hLayout vLayout verticalSpace horizontalSpace mustRearrange |
14 instanceVariableNames:'hLayout vLayout verticalSpace horizontalSpace mustRearrange |
17 elementsChangeSize' |
15 elementsChangeSize' |
18 classVariableNames:'' |
16 classVariableNames:'' |
19 poolDictionaries:'' |
17 poolDictionaries:'' |
20 category:'Views-Layout' |
18 category:'Views-Layout' |
21 ! |
19 ! |
22 |
20 |
108 b := Button label:label. |
102 b := Button label:label. |
109 panel add:b. |
103 panel add:b. |
110 ]. |
104 ]. |
111 top open |
105 top open |
112 " |
106 " |
|
107 ! |
|
108 |
|
109 version |
|
110 ^ '$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.13 1995-11-23 14:36:38 cg Exp $' |
|
111 ! ! |
|
112 |
|
113 !PanelView methodsFor:'accessing'! |
|
114 |
|
115 elementsChangeSize:aBoolean |
|
116 "tell the panel if elements are to change their size by themselfes |
|
117 (for example, Lables or Buttons may do so if their contents changes). |
|
118 Setting this flag will make the panel reorganize the elements whenever |
|
119 any element changes its size." |
|
120 |
|
121 elementsChangeSize := aBoolean. |
|
122 aBoolean ifTrue:[ |
|
123 subViews notNil ifTrue:[ |
|
124 subViews do:[:aView | |
|
125 aView addDependent:self |
|
126 ] |
|
127 ] |
|
128 ] |
|
129 ! |
|
130 |
|
131 horizontalSpace:numberOfPixels |
|
132 "set the horizontal space between elements on pixels (default is 1mm)" |
|
133 |
|
134 horizontalSpace ~= numberOfPixels ifTrue:[ |
|
135 horizontalSpace := numberOfPixels. |
|
136 self layoutChanged |
|
137 ] |
|
138 ! |
|
139 |
|
140 space:numberOfPixels |
|
141 "set the space between elements in pixels (default is 1mm) for both directions" |
|
142 |
|
143 (verticalSpace ~= numberOfPixels |
|
144 or:[horizontalSpace ~= numberOfPixels]) ifTrue:[ |
|
145 horizontalSpace := numberOfPixels. |
|
146 verticalSpace := numberOfPixels. |
|
147 self layoutChanged |
|
148 ] |
|
149 ! |
|
150 |
|
151 verticalSpace:numberOfPixels |
|
152 "set the vertical space between elements (in pixels). |
|
153 The default is computed for 1mm spacing." |
|
154 |
|
155 verticalSpace ~= numberOfPixels ifTrue:[ |
|
156 verticalSpace := numberOfPixels. |
|
157 self layoutChanged |
|
158 ] |
|
159 ! ! |
|
160 |
|
161 !PanelView methodsFor:'adding & removing subviews'! |
|
162 |
|
163 addSubView:aView |
|
164 "redefined to recompute layout when a subview is added" |
|
165 |
|
166 super addSubView:aView. |
|
167 self addedView:aView |
|
168 ! |
|
169 |
|
170 addSubView:newView after:aView |
|
171 "redefined to recompute layout when a subview is added" |
|
172 |
|
173 super addSubView:newView after:aView. |
|
174 self addedView:aView |
|
175 ! |
|
176 |
|
177 addSubView:newView before:aView |
|
178 "redefined to recompute layout when a subview is added" |
|
179 |
|
180 super addSubView:newView before:aView. |
|
181 self addedView:aView |
|
182 ! |
|
183 |
|
184 removeSubView:aView |
|
185 "redefined to recompute layout when a subview is removed" |
|
186 |
|
187 super removeSubView:aView. |
|
188 aView removeDependent:self. |
|
189 self layoutChanged |
113 ! ! |
190 ! ! |
114 |
191 |
115 !PanelView methodsFor:'event processing'! |
192 !PanelView methodsFor:'event processing'! |
116 |
193 |
117 sizeChanged:how |
194 sizeChanged:how |
132 ^ self |
209 ^ self |
133 ]. |
210 ]. |
134 ^ super update:something with:aParameter from:changedObject |
211 ^ super update:something with:aParameter from:changedObject |
135 ! ! |
212 ! ! |
136 |
213 |
|
214 !PanelView methodsFor:'initialization'! |
|
215 |
|
216 initialize |
|
217 super initialize. |
|
218 |
|
219 hLayout := vLayout := #center. "/ notice, this is ignored in this class |
|
220 "/ used by subclasses only |
|
221 verticalSpace := ViewSpacing. |
|
222 horizontalSpace := ViewSpacing. |
|
223 mustRearrange := elementsChangeSize := false |
|
224 ! |
|
225 |
|
226 realize |
|
227 mustRearrange ifTrue:[ |
|
228 self setChildPositions |
|
229 ]. |
|
230 super realize |
|
231 ! |
|
232 |
|
233 setChildPositionsIfChanged |
|
234 "set all of my child positions - this is usually delayed, |
|
235 until the panel is actually shown (since we dont know, if more |
|
236 elements are to be added) thus avoiding repositioning the elements |
|
237 over and over. However, sometimes it is nescessary, to force positioning |
|
238 the elements, for example, before querying the relative position of |
|
239 an element (modalBoxes do so, to position the ok-button under the mouse |
|
240 pointer)." |
|
241 |
|
242 mustRearrange ifTrue:[ |
|
243 self setChildPositions |
|
244 ]. |
|
245 |
|
246 ! ! |
|
247 |
137 !PanelView methodsFor:'private'! |
248 !PanelView methodsFor:'private'! |
|
249 |
|
250 addedView:aView |
|
251 "added a new element" |
|
252 |
|
253 elementsChangeSize ifTrue:[ |
|
254 aView addDependent:self |
|
255 ]. |
|
256 self layoutChanged |
|
257 ! |
138 |
258 |
139 layoutChanged |
259 layoutChanged |
140 "called whenever repositioning is required. If the panel view is |
260 "called whenever repositioning is required. If the panel view is |
141 already visible, reposition elements right now. Otherwise, remember |
261 already visible, reposition elements right now. Otherwise, remember |
142 that a repositioning is needed to do so when the view eventually becomes |
262 that a repositioning is needed to do so when the view eventually becomes |
207 ]. |
318 ]. |
208 ]. |
319 ]. |
209 mustRearrange := false |
320 mustRearrange := false |
210 ! ! |
321 ! ! |
211 |
322 |
212 !PanelView methodsFor:'initialization'! |
|
213 |
|
214 initialize |
|
215 super initialize. |
|
216 |
|
217 hLayout := vLayout := #center. "/ notice, this is ignored in this class |
|
218 "/ used by subclasses only |
|
219 verticalSpace := ViewSpacing. |
|
220 horizontalSpace := ViewSpacing. |
|
221 mustRearrange := elementsChangeSize := false |
|
222 ! |
|
223 |
|
224 realize |
|
225 mustRearrange ifTrue:[ |
|
226 self setChildPositions |
|
227 ]. |
|
228 super realize |
|
229 ! |
|
230 |
|
231 setChildPositionsIfChanged |
|
232 "set all of my child positions - this is usually delayed, |
|
233 until the panel is actually shown (since we dont know, if more |
|
234 elements are to be added) thus avoiding repositioning the elements |
|
235 over and over. However, sometimes it is nescessary, to force positioning |
|
236 the elements, for example, before querying the relative position of |
|
237 an element (modalBoxes do so, to position the ok-button under the mouse |
|
238 pointer)." |
|
239 |
|
240 mustRearrange ifTrue:[ |
|
241 self setChildPositions |
|
242 ]. |
|
243 |
|
244 ! ! |
|
245 |
|
246 !PanelView methodsFor:'adding & removing subviews'! |
|
247 |
|
248 addSubView:aView |
|
249 "redefined to recompute layout when a subview is added" |
|
250 |
|
251 super addSubView:aView. |
|
252 self addedView:aView |
|
253 ! |
|
254 |
|
255 addSubView:newView after:aView |
|
256 "redefined to recompute layout when a subview is added" |
|
257 |
|
258 super addSubView:newView after:aView. |
|
259 self addedView:aView |
|
260 ! |
|
261 |
|
262 addSubView:newView before:aView |
|
263 "redefined to recompute layout when a subview is added" |
|
264 |
|
265 super addSubView:newView before:aView. |
|
266 self addedView:aView |
|
267 ! |
|
268 |
|
269 removeSubView:aView |
|
270 "redefined to recompute layout when a subview is removed" |
|
271 |
|
272 super removeSubView:aView. |
|
273 aView removeDependent:self. |
|
274 self layoutChanged |
|
275 ! ! |
|
276 |
|
277 !PanelView methodsFor:'accessing'! |
|
278 |
|
279 elementsChangeSize:aBoolean |
|
280 "tell the panel if elements are to change their size by themselfes |
|
281 (for example, Lables or Buttons may do so if their contents changes). |
|
282 Setting this flag will make the panel reorganize the elements whenever |
|
283 any element changes its size." |
|
284 |
|
285 elementsChangeSize := aBoolean. |
|
286 aBoolean ifTrue:[ |
|
287 subViews notNil ifTrue:[ |
|
288 subViews do:[:aView | |
|
289 aView addDependent:self |
|
290 ] |
|
291 ] |
|
292 ] |
|
293 ! |
|
294 |
|
295 verticalSpace:numberOfPixels |
|
296 "set the vertical space between elements (in pixels). |
|
297 The default is computed for 1mm spacing." |
|
298 |
|
299 verticalSpace ~= numberOfPixels ifTrue:[ |
|
300 verticalSpace := numberOfPixels. |
|
301 self layoutChanged |
|
302 ] |
|
303 ! |
|
304 |
|
305 horizontalSpace:numberOfPixels |
|
306 "set the horizontal space between elements on pixels (default is 1mm)" |
|
307 |
|
308 horizontalSpace ~= numberOfPixels ifTrue:[ |
|
309 horizontalSpace := numberOfPixels. |
|
310 self layoutChanged |
|
311 ] |
|
312 ! |
|
313 |
|
314 space:numberOfPixels |
|
315 "set the space between elements in pixels (default is 1mm) for both directions" |
|
316 |
|
317 (verticalSpace ~= numberOfPixels |
|
318 or:[horizontalSpace ~= numberOfPixels]) ifTrue:[ |
|
319 horizontalSpace := numberOfPixels. |
|
320 verticalSpace := numberOfPixels. |
|
321 self layoutChanged |
|
322 ] |
|
323 ! ! |
|
324 |
|