author | Claus Gittinger <cg@exept.de> |
Mon, 15 Jul 1996 12:10:05 +0200 | |
changeset 787 | c568dfd06f11 |
parent 593 | 86dd024ed773 |
child 788 | 653fd742b5b0 |
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 |
||
119 | 13 |
SimpleView subclass:#PanelView |
585 | 14 |
instanceVariableNames:'hLayout vLayout verticalSpace horizontalSpace mustRearrange |
15 |
elementsChangeSize' |
|
16 |
classVariableNames:'' |
|
17 |
poolDictionaries:'' |
|
18 |
category:'Views-Layout' |
|
0 | 19 |
! |
20 |
||
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
21 |
!PanelView class methodsFor:'documentation'! |
0 | 22 |
|
38 | 23 |
copyright |
24 |
" |
|
25 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
60 | 26 |
All Rights Reserved |
0 | 27 |
|
38 | 28 |
This software is furnished under a license and may be used |
29 |
only in accordance with the terms of that license and with the |
|
30 |
inclusion of the above copyright notice. This software may not |
|
31 |
be provided or otherwise made available to, or used by, any |
|
32 |
other person. No title to or ownership of the software is |
|
33 |
hereby transferred. |
|
34 |
" |
|
35 |
! |
|
0 | 36 |
|
38 | 37 |
documentation |
38 |
" |
|
127 | 39 |
this is a view for holding subviews. (layout-widget ?) |
38 | 40 |
|
41 |
Instances of PanelView try to get all their subviews into them, |
|
42 |
arranging subviews left-to-right, top-to-bottom. |
|
43 |
||
44 |
If you dont like its layout, define a new subclass or use one of |
|
45 |
the existing subclasses: HorizontalPanelView and VerticalPanelView. |
|
60 | 46 |
|
127 | 47 |
The panel assumes, that the elements do not resize themselfes, after it |
48 |
became visible. This is not true for all widgets (buttons or labels may |
|
49 |
like to change). If you have changing elements, tell this to the panel |
|
50 |
with 'aPanel elementsChangeSize:true'. In that case, the panel will react |
|
51 |
to size changes, and reorganize things. |
|
52 |
||
63 | 53 |
PanelViews normally delay the actual positioning/sizing of their elements, |
60 | 54 |
until actually displayed. This is useful, if more elements are to |
55 |
be added, to avoid repeated configuration of the elements. |
|
56 |
||
57 |
If you want to query for the relative position of an element BEFORE |
|
58 |
the view is visible, you have to send #setChildPositionsIfChanged before |
|
63 | 59 |
doing so (otherwise, you may get invalid origins from the subviews). As |
60 |
an example, the modalBoxes do so before showing themselfes to ask for the |
|
61 |
position of the ok-button relative to the top-left box-origin, in order to |
|
62 |
position the ok-button under the mouse-pointer. |
|
63 |
||
585 | 64 |
[Instance variables:] |
63 | 65 |
|
585 | 66 |
hLayout <Symbol> controls horizontal layout; ignored in this |
67 |
class, but used in Horizontal- and |
|
68 |
VerticalPanelViews. See more info there. |
|
63 | 69 |
|
585 | 70 |
vLayout <Symbol> controls vertical layout; ignored in this |
71 |
class, but used in Horizontal- and |
|
72 |
VerticalPanelViews. See more info there. |
|
63 | 73 |
|
585 | 74 |
horizontalSpace <Integer> number of pixels to use as space between elements |
75 |
defaults to ViewSpacing, which is 1mm |
|
63 | 76 |
|
585 | 77 |
verticalSpace <Integer> number of pixels to use as space between elements |
78 |
defaults to ViewSpacing, which is 1mm |
|
63 | 79 |
|
585 | 80 |
mustRearrange <Boolean> internal flag, if rearrangement is needed |
125 | 81 |
|
585 | 82 |
elementsChangeSize |
83 |
<Boolean> if true, the panel takes care of this situation. |
|
84 |
By default, this is false. |
|
85 |
||
86 |
[author:] |
|
87 |
Claus Gittinger |
|
38 | 88 |
" |
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
89 |
! ! |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
90 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
91 |
!PanelView class ignoredMethodsFor:'documentation'! |
127 | 92 |
|
93 |
examples |
|
94 |
" |
|
95 |
fill a panel with many buttons (see what happens on resize): |
|
593 | 96 |
[exBegin] |
97 |
|top panel| |
|
127 | 98 |
|
593 | 99 |
top := StandardSystemView new. |
100 |
top extent:200@200. |
|
101 |
panel := PanelView origin:0.0@0.0 corner:1.0@1.0 in:top. |
|
127 | 102 |
|
593 | 103 |
#('one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight' |
104 |
'nine' 'ten' 'aVeryLongOne') do:[:label | |
|
105 |
|b| |
|
127 | 106 |
|
593 | 107 |
b := Button label:label. |
108 |
panel add:b. |
|
109 |
]. |
|
110 |
top open |
|
111 |
[exEnd] |
|
127 | 112 |
" |
202 | 113 |
! ! |
114 |
||
115 |
!PanelView methodsFor:'accessing'! |
|
116 |
||
117 |
elementsChangeSize:aBoolean |
|
118 |
"tell the panel if elements are to change their size by themselfes |
|
119 |
(for example, Lables or Buttons may do so if their contents changes). |
|
120 |
Setting this flag will make the panel reorganize the elements whenever |
|
121 |
any element changes its size." |
|
122 |
||
123 |
elementsChangeSize := aBoolean. |
|
124 |
aBoolean ifTrue:[ |
|
125 |
subViews notNil ifTrue:[ |
|
126 |
subViews do:[:aView | |
|
127 |
aView addDependent:self |
|
128 |
] |
|
129 |
] |
|
130 |
] |
|
131 |
! |
|
132 |
||
133 |
horizontalSpace:numberOfPixels |
|
134 |
"set the horizontal space between elements on pixels (default is 1mm)" |
|
135 |
||
136 |
horizontalSpace ~= numberOfPixels ifTrue:[ |
|
137 |
horizontalSpace := numberOfPixels. |
|
138 |
self layoutChanged |
|
139 |
] |
|
140 |
! |
|
141 |
||
142 |
space:numberOfPixels |
|
143 |
"set the space between elements in pixels (default is 1mm) for both directions" |
|
144 |
||
145 |
(verticalSpace ~= numberOfPixels |
|
146 |
or:[horizontalSpace ~= numberOfPixels]) ifTrue:[ |
|
147 |
horizontalSpace := numberOfPixels. |
|
148 |
verticalSpace := numberOfPixels. |
|
149 |
self layoutChanged |
|
150 |
] |
|
151 |
! |
|
152 |
||
153 |
verticalSpace:numberOfPixels |
|
154 |
"set the vertical space between elements (in pixels). |
|
155 |
The default is computed for 1mm spacing." |
|
156 |
||
157 |
verticalSpace ~= numberOfPixels ifTrue:[ |
|
158 |
verticalSpace := numberOfPixels. |
|
159 |
self layoutChanged |
|
160 |
] |
|
161 |
! ! |
|
162 |
||
163 |
!PanelView methodsFor:'adding & removing subviews'! |
|
164 |
||
165 |
addSubView:aView |
|
166 |
"redefined to recompute layout when a subview is added" |
|
167 |
||
168 |
super addSubView:aView. |
|
169 |
self addedView:aView |
|
170 |
! |
|
171 |
||
172 |
addSubView:newView after:aView |
|
173 |
"redefined to recompute layout when a subview is added" |
|
174 |
||
175 |
super addSubView:newView after:aView. |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
176 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
177 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
178 |
"Modified: 15.7.1996 / 10:15:04 / cg" |
202 | 179 |
! |
180 |
||
181 |
addSubView:newView before:aView |
|
182 |
"redefined to recompute layout when a subview is added" |
|
183 |
||
184 |
super addSubView:newView before:aView. |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
185 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
186 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
187 |
"Modified: 15.7.1996 / 10:14:39 / cg" |
202 | 188 |
! |
189 |
||
190 |
removeSubView:aView |
|
191 |
"redefined to recompute layout when a subview is removed" |
|
192 |
||
193 |
super removeSubView:aView. |
|
194 |
aView removeDependent:self. |
|
195 |
self layoutChanged |
|
38 | 196 |
! ! |
0 | 197 |
|
198 |
!PanelView methodsFor:'event processing'! |
|
199 |
||
200 |
sizeChanged:how |
|
119 | 201 |
"my size has changed - must rearrange elements" |
202 |
||
0 | 203 |
super sizeChanged:how. |
60 | 204 |
self layoutChanged |
125 | 205 |
! |
206 |
||
207 |
update:something with:aParameter from:changedObject |
|
208 |
something == #sizeOfView ifTrue:[ |
|
209 |
" |
|
210 |
an element changed its size |
|
211 |
" |
|
212 |
(subViews includes:changedObject) ifTrue:[ |
|
213 |
self layoutChanged |
|
214 |
]. |
|
215 |
^ self |
|
216 |
]. |
|
217 |
^ super update:something with:aParameter from:changedObject |
|
0 | 218 |
! ! |
219 |
||
202 | 220 |
!PanelView methodsFor:'initialization'! |
221 |
||
222 |
initialize |
|
223 |
super initialize. |
|
224 |
||
225 |
hLayout := vLayout := #center. "/ notice, this is ignored in this class |
|
226 |
"/ used by subclasses only |
|
227 |
verticalSpace := ViewSpacing. |
|
228 |
horizontalSpace := ViewSpacing. |
|
229 |
mustRearrange := elementsChangeSize := false |
|
230 |
! |
|
231 |
||
232 |
realize |
|
233 |
mustRearrange ifTrue:[ |
|
234 |
self setChildPositions |
|
235 |
]. |
|
236 |
super realize |
|
237 |
! |
|
238 |
||
239 |
setChildPositionsIfChanged |
|
240 |
"set all of my child positions - this is usually delayed, |
|
241 |
until the panel is actually shown (since we dont know, if more |
|
242 |
elements are to be added) thus avoiding repositioning the elements |
|
243 |
over and over. However, sometimes it is nescessary, to force positioning |
|
244 |
the elements, for example, before querying the relative position of |
|
245 |
an element (modalBoxes do so, to position the ok-button under the mouse |
|
246 |
pointer)." |
|
247 |
||
248 |
mustRearrange ifTrue:[ |
|
249 |
self setChildPositions |
|
250 |
]. |
|
251 |
||
252 |
! ! |
|
253 |
||
0 | 254 |
!PanelView methodsFor:'private'! |
255 |
||
202 | 256 |
addedView:aView |
257 |
"added a new element" |
|
258 |
||
259 |
elementsChangeSize ifTrue:[ |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
260 |
aView addDependent:self |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
261 |
]. |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
262 |
aView resize. |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
263 |
explicitExtent ~~ true ifTrue:[ |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
264 |
self resize |
202 | 265 |
]. |
266 |
self layoutChanged |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
267 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
268 |
"Modified: 15.7.1996 / 11:16:53 / cg" |
202 | 269 |
! |
270 |
||
0 | 271 |
layoutChanged |
119 | 272 |
"called whenever repositioning is required. If the panel view is |
273 |
already visible, reposition elements right now. Otherwise, remember |
|
274 |
that a repositioning is needed to do so when the view eventually becomes |
|
275 |
visible." |
|
276 |
||
15 | 277 |
shown ifTrue:[ |
60 | 278 |
self setChildPositions |
0 | 279 |
] ifFalse:[ |
60 | 280 |
mustRearrange := true |
0 | 281 |
] |
282 |
! |
|
283 |
||
284 |
setChildPositions |
|
63 | 285 |
"(re)compute position of every child. |
286 |
This method is redefined for different layout characteristics - you may |
|
287 |
even create subclasses with completely different geometry management." |
|
0 | 288 |
|
60 | 289 |
|first xpos ypos maxHeightInRow thisRow| |
0 | 290 |
|
291 |
subViews notNil ifTrue:[ |
|
60 | 292 |
xpos := horizontalSpace. |
293 |
ypos := verticalSpace. |
|
0 | 294 |
|
60 | 295 |
maxHeightInRow := 0. |
296 |
first := true. |
|
297 |
thisRow := OrderedCollection new. |
|
298 |
subViews do:[:child | |
|
299 |
"go to next row, if this subview won't fit" |
|
300 |
first ifFalse: [ |
|
301 |
(xpos + child widthIncludingBorder + horizontalSpace) > width |
|
302 |
ifTrue: [ |
|
303 |
thisRow notEmpty ifTrue:[ |
|
304 |
thisRow do:[:rowElement | |
|
305 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
306 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
307 |
] |
|
308 |
] |
|
309 |
]. |
|
310 |
ypos := ypos + verticalSpace + maxHeightInRow. |
|
311 |
xpos := horizontalSpace. |
|
312 |
maxHeightInRow := 0. |
|
313 |
thisRow := OrderedCollection new. |
|
314 |
] |
|
315 |
]. |
|
316 |
thisRow add:child. |
|
317 |
child origin:(xpos@ypos). |
|
318 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace. |
|
319 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[ |
|
320 |
maxHeightInRow := child heightIncludingBorder |
|
321 |
]. |
|
322 |
first := false |
|
323 |
]. |
|
324 |
thisRow notEmpty ifTrue:[ |
|
325 |
thisRow do:[:rowElement | |
|
326 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
327 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
328 |
] |
|
329 |
] |
|
330 |
]. |
|
0 | 331 |
]. |
332 |
mustRearrange := false |
|
333 |
! ! |
|
125 | 334 |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
335 |
!PanelView class methodsFor:'documentation'! |
205 | 336 |
|
337 |
version |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
338 |
^ '$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.17 1996-07-15 10:10:05 cg Exp $' |
205 | 339 |
! ! |