author | Claus Gittinger <cg@exept.de> |
Thu, 23 Nov 1995 01:50:10 +0100 | |
changeset 193 | 6ccc226ce3a6 |
parent 174 | d80a6cc3f9b2 |
child 202 | 01f3cbb8e20e |
permissions | -rw-r--r-- |
0 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
60 | 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 |
||
125 | 13 |
'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:05:18 pm'! |
14 |
||
119 | 15 |
SimpleView subclass:#PanelView |
125 | 16 |
instanceVariableNames:'hLayout vLayout verticalSpace horizontalSpace mustRearrange |
17 |
elementsChangeSize' |
|
18 |
classVariableNames:'' |
|
19 |
poolDictionaries:'' |
|
20 |
category:'Views-Layout' |
|
0 | 21 |
! |
22 |
||
38 | 23 |
!PanelView class methodsFor:'documentation'! |
0 | 24 |
|
38 | 25 |
copyright |
26 |
" |
|
27 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
60 | 28 |
All Rights Reserved |
0 | 29 |
|
38 | 30 |
This software is furnished under a license and may be used |
31 |
only in accordance with the terms of that license and with the |
|
32 |
inclusion of the above copyright notice. This software may not |
|
33 |
be provided or otherwise made available to, or used by, any |
|
34 |
other person. No title to or ownership of the software is |
|
35 |
hereby transferred. |
|
36 |
" |
|
37 |
! |
|
0 | 38 |
|
38 | 39 |
version |
174
d80a6cc3f9b2
uff - version methods changed to return stings
Claus Gittinger <cg@exept.de>
parents:
146
diff
changeset
|
40 |
^ '$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.12 1995-11-11 16:22:02 cg Exp $' |
38 | 41 |
! |
0 | 42 |
|
38 | 43 |
documentation |
44 |
" |
|
127 | 45 |
this is a view for holding subviews. (layout-widget ?) |
38 | 46 |
|
47 |
Instances of PanelView try to get all their subviews into them, |
|
48 |
arranging subviews left-to-right, top-to-bottom. |
|
49 |
||
50 |
If you dont like its layout, define a new subclass or use one of |
|
51 |
the existing subclasses: HorizontalPanelView and VerticalPanelView. |
|
60 | 52 |
|
127 | 53 |
The panel assumes, that the elements do not resize themselfes, after it |
54 |
became visible. This is not true for all widgets (buttons or labels may |
|
55 |
like to change). If you have changing elements, tell this to the panel |
|
56 |
with 'aPanel elementsChangeSize:true'. In that case, the panel will react |
|
57 |
to size changes, and reorganize things. |
|
58 |
||
63 | 59 |
PanelViews normally delay the actual positioning/sizing of their elements, |
60 | 60 |
until actually displayed. This is useful, if more elements are to |
61 |
be added, to avoid repeated configuration of the elements. |
|
62 |
||
63 |
If you want to query for the relative position of an element BEFORE |
|
64 |
the view is visible, you have to send #setChildPositionsIfChanged before |
|
63 | 65 |
doing so (otherwise, you may get invalid origins from the subviews). As |
66 |
an example, the modalBoxes do so before showing themselfes to ask for the |
|
67 |
position of the ok-button relative to the top-left box-origin, in order to |
|
68 |
position the ok-button under the mouse-pointer. |
|
69 |
||
70 |
Instance variables: |
|
71 |
||
72 |
hLayout <Symbol> controls horizontal layout; ignored in this |
|
73 |
class, but used in Horizontal- and |
|
74 |
VerticalPanelViews. See more info there. |
|
75 |
||
76 |
vLayout <Symbol> controls vertical layout; ignored in this |
|
77 |
class, but used in Horizontal- and |
|
78 |
VerticalPanelViews. See more info there. |
|
79 |
||
80 |
horizontalSpace <Integer> number of pixels to use as space between elements |
|
119 | 81 |
defaults to ViewSpacing, which is 1mm |
63 | 82 |
|
83 |
verticalSpace <Integer> number of pixels to use as space between elements |
|
119 | 84 |
defaults to ViewSpacing, which is 1mm |
63 | 85 |
|
86 |
mustRearrange <Boolean> internal flag, if rearrangement is needed |
|
125 | 87 |
|
88 |
elementsChangeSize |
|
89 |
<Boolean> if true, the panel takes care of this situation. |
|
90 |
By default, this is false. |
|
38 | 91 |
" |
127 | 92 |
! |
93 |
||
94 |
examples |
|
95 |
" |
|
96 |
fill a panel with many buttons (see what happens on resize): |
|
97 |
||
98 |
|top panel| |
|
99 |
||
100 |
top := StandardSystemView new. |
|
101 |
top extent:200@200. |
|
102 |
panel := PanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
103 |
||
104 |
#('one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' |
|
105 |
'nine' 'ten' 'aVeryLongOne') do:[:label | |
|
106 |
|b| |
|
107 |
||
108 |
b := Button label:label. |
|
109 |
panel add:b. |
|
110 |
]. |
|
111 |
top open |
|
112 |
" |
|
38 | 113 |
! ! |
0 | 114 |
|
115 |
!PanelView methodsFor:'event processing'! |
|
116 |
||
117 |
sizeChanged:how |
|
119 | 118 |
"my size has changed - must rearrange elements" |
119 |
||
0 | 120 |
super sizeChanged:how. |
60 | 121 |
self layoutChanged |
125 | 122 |
! |
123 |
||
124 |
update:something with:aParameter from:changedObject |
|
125 |
something == #sizeOfView ifTrue:[ |
|
126 |
" |
|
127 |
an element changed its size |
|
128 |
" |
|
129 |
(subViews includes:changedObject) ifTrue:[ |
|
130 |
self layoutChanged |
|
131 |
]. |
|
132 |
^ self |
|
133 |
]. |
|
134 |
^ super update:something with:aParameter from:changedObject |
|
0 | 135 |
! ! |
136 |
||
137 |
!PanelView methodsFor:'private'! |
|
138 |
||
139 |
layoutChanged |
|
119 | 140 |
"called whenever repositioning is required. If the panel view is |
141 |
already visible, reposition elements right now. Otherwise, remember |
|
142 |
that a repositioning is needed to do so when the view eventually becomes |
|
143 |
visible." |
|
144 |
||
15 | 145 |
shown ifTrue:[ |
60 | 146 |
self setChildPositions |
0 | 147 |
] ifFalse:[ |
60 | 148 |
mustRearrange := true |
0 | 149 |
] |
150 |
! |
|
151 |
||
125 | 152 |
addedView:aView |
153 |
"added a new element" |
|
154 |
||
155 |
elementsChangeSize ifTrue:[ |
|
156 |
aView addDependent:self |
|
157 |
]. |
|
158 |
self layoutChanged |
|
159 |
! |
|
160 |
||
0 | 161 |
setChildPositions |
63 | 162 |
"(re)compute position of every child. |
163 |
This method is redefined for different layout characteristics - you may |
|
164 |
even create subclasses with completely different geometry management." |
|
0 | 165 |
|
60 | 166 |
|first xpos ypos maxHeightInRow thisRow| |
0 | 167 |
|
168 |
subViews notNil ifTrue:[ |
|
60 | 169 |
xpos := horizontalSpace. |
170 |
ypos := verticalSpace. |
|
0 | 171 |
|
60 | 172 |
maxHeightInRow := 0. |
173 |
first := true. |
|
174 |
thisRow := OrderedCollection new. |
|
175 |
subViews do:[:child | |
|
176 |
"go to next row, if this subview won't fit" |
|
177 |
first ifFalse: [ |
|
178 |
(xpos + child widthIncludingBorder + horizontalSpace) > width |
|
179 |
ifTrue: [ |
|
180 |
thisRow notEmpty ifTrue:[ |
|
181 |
thisRow do:[:rowElement | |
|
182 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
183 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
184 |
] |
|
185 |
] |
|
186 |
]. |
|
187 |
ypos := ypos + verticalSpace + maxHeightInRow. |
|
188 |
xpos := horizontalSpace. |
|
189 |
maxHeightInRow := 0. |
|
190 |
thisRow := OrderedCollection new. |
|
191 |
] |
|
192 |
]. |
|
193 |
thisRow add:child. |
|
194 |
child origin:(xpos@ypos). |
|
195 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace. |
|
196 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[ |
|
197 |
maxHeightInRow := child heightIncludingBorder |
|
198 |
]. |
|
199 |
first := false |
|
200 |
]. |
|
201 |
thisRow notEmpty ifTrue:[ |
|
202 |
thisRow do:[:rowElement | |
|
203 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
204 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
205 |
] |
|
206 |
] |
|
207 |
]. |
|
0 | 208 |
]. |
209 |
mustRearrange := false |
|
210 |
! ! |
|
125 | 211 |
|
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 |
||
146 | 246 |
!PanelView methodsFor:'adding & removing subviews'! |
125 | 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 |
||
146 | 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 |
||
125 | 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 |