author | Claus Gittinger <cg@exept.de> |
Tue, 14 Jan 1997 00:12:53 +0100 | |
changeset 940 | e53f681448f0 |
parent 788 | 653fd742b5b0 |
child 980 | 6079922a5519 |
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 |
|
202 | 91 |
!PanelView methodsFor:'accessing'! |
92 |
||
93 |
elementsChangeSize:aBoolean |
|
94 |
"tell the panel if elements are to change their size by themselfes |
|
95 |
(for example, Lables or Buttons may do so if their contents changes). |
|
96 |
Setting this flag will make the panel reorganize the elements whenever |
|
97 |
any element changes its size." |
|
98 |
||
99 |
elementsChangeSize := aBoolean. |
|
100 |
aBoolean ifTrue:[ |
|
101 |
subViews notNil ifTrue:[ |
|
102 |
subViews do:[:aView | |
|
103 |
aView addDependent:self |
|
104 |
] |
|
105 |
] |
|
106 |
] |
|
107 |
! |
|
108 |
||
109 |
horizontalSpace:numberOfPixels |
|
110 |
"set the horizontal space between elements on pixels (default is 1mm)" |
|
111 |
||
112 |
horizontalSpace ~= numberOfPixels ifTrue:[ |
|
113 |
horizontalSpace := numberOfPixels. |
|
114 |
self layoutChanged |
|
115 |
] |
|
116 |
! |
|
117 |
||
118 |
space:numberOfPixels |
|
119 |
"set the space between elements in pixels (default is 1mm) for both directions" |
|
120 |
||
121 |
(verticalSpace ~= numberOfPixels |
|
122 |
or:[horizontalSpace ~= numberOfPixels]) ifTrue:[ |
|
123 |
horizontalSpace := numberOfPixels. |
|
124 |
verticalSpace := numberOfPixels. |
|
125 |
self layoutChanged |
|
126 |
] |
|
127 |
! |
|
128 |
||
129 |
verticalSpace:numberOfPixels |
|
130 |
"set the vertical space between elements (in pixels). |
|
131 |
The default is computed for 1mm spacing." |
|
132 |
||
133 |
verticalSpace ~= numberOfPixels ifTrue:[ |
|
134 |
verticalSpace := numberOfPixels. |
|
135 |
self layoutChanged |
|
136 |
] |
|
137 |
! ! |
|
138 |
||
139 |
!PanelView methodsFor:'adding & removing subviews'! |
|
140 |
||
141 |
addSubView:aView |
|
142 |
"redefined to recompute layout when a subview is added" |
|
143 |
||
144 |
super addSubView:aView. |
|
145 |
self addedView:aView |
|
146 |
! |
|
147 |
||
148 |
addSubView:newView after:aView |
|
149 |
"redefined to recompute layout when a subview is added" |
|
150 |
||
151 |
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
|
152 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
153 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
154 |
"Modified: 15.7.1996 / 10:15:04 / cg" |
202 | 155 |
! |
156 |
||
157 |
addSubView:newView before:aView |
|
158 |
"redefined to recompute layout when a subview is added" |
|
159 |
||
160 |
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
|
161 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
162 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
163 |
"Modified: 15.7.1996 / 10:14:39 / cg" |
202 | 164 |
! |
165 |
||
166 |
removeSubView:aView |
|
167 |
"redefined to recompute layout when a subview is removed" |
|
168 |
||
169 |
super removeSubView:aView. |
|
170 |
aView removeDependent:self. |
|
171 |
self layoutChanged |
|
38 | 172 |
! ! |
0 | 173 |
|
174 |
!PanelView methodsFor:'event processing'! |
|
175 |
||
176 |
sizeChanged:how |
|
119 | 177 |
"my size has changed - must rearrange elements" |
178 |
||
0 | 179 |
super sizeChanged:how. |
60 | 180 |
self layoutChanged |
125 | 181 |
! |
182 |
||
183 |
update:something with:aParameter from:changedObject |
|
184 |
something == #sizeOfView ifTrue:[ |
|
185 |
" |
|
186 |
an element changed its size |
|
187 |
" |
|
188 |
(subViews includes:changedObject) ifTrue:[ |
|
189 |
self layoutChanged |
|
190 |
]. |
|
191 |
^ self |
|
192 |
]. |
|
193 |
^ super update:something with:aParameter from:changedObject |
|
0 | 194 |
! ! |
195 |
||
202 | 196 |
!PanelView methodsFor:'initialization'! |
197 |
||
198 |
initialize |
|
199 |
super initialize. |
|
200 |
||
201 |
hLayout := vLayout := #center. "/ notice, this is ignored in this class |
|
202 |
"/ used by subclasses only |
|
203 |
verticalSpace := ViewSpacing. |
|
204 |
horizontalSpace := ViewSpacing. |
|
205 |
mustRearrange := elementsChangeSize := false |
|
206 |
! |
|
207 |
||
208 |
realize |
|
209 |
mustRearrange ifTrue:[ |
|
210 |
self setChildPositions |
|
211 |
]. |
|
212 |
super realize |
|
213 |
! |
|
214 |
||
215 |
setChildPositionsIfChanged |
|
216 |
"set all of my child positions - this is usually delayed, |
|
217 |
until the panel is actually shown (since we dont know, if more |
|
218 |
elements are to be added) thus avoiding repositioning the elements |
|
219 |
over and over. However, sometimes it is nescessary, to force positioning |
|
220 |
the elements, for example, before querying the relative position of |
|
221 |
an element (modalBoxes do so, to position the ok-button under the mouse |
|
222 |
pointer)." |
|
223 |
||
224 |
mustRearrange ifTrue:[ |
|
225 |
self setChildPositions |
|
226 |
]. |
|
227 |
||
228 |
! ! |
|
229 |
||
0 | 230 |
!PanelView methodsFor:'private'! |
231 |
||
202 | 232 |
addedView:aView |
233 |
"added a new element" |
|
234 |
||
235 |
elementsChangeSize ifTrue:[ |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
236 |
aView addDependent:self |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
237 |
]. |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
238 |
aView resize. |
788
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
239 |
"/ explicitExtent ~~ true ifTrue:[ |
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
240 |
"/ self resize |
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
241 |
"/ ]. |
202 | 242 |
self layoutChanged |
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
243 |
|
788
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
244 |
"Modified: 15.7.1996 / 12:52:07 / cg" |
202 | 245 |
! |
246 |
||
0 | 247 |
layoutChanged |
119 | 248 |
"called whenever repositioning is required. If the panel view is |
249 |
already visible, reposition elements right now. Otherwise, remember |
|
250 |
that a repositioning is needed to do so when the view eventually becomes |
|
251 |
visible." |
|
252 |
||
15 | 253 |
shown ifTrue:[ |
60 | 254 |
self setChildPositions |
0 | 255 |
] ifFalse:[ |
60 | 256 |
mustRearrange := true |
0 | 257 |
] |
258 |
! |
|
259 |
||
260 |
setChildPositions |
|
63 | 261 |
"(re)compute position of every child. |
262 |
This method is redefined for different layout characteristics - you may |
|
263 |
even create subclasses with completely different geometry management." |
|
0 | 264 |
|
60 | 265 |
|first xpos ypos maxHeightInRow thisRow| |
0 | 266 |
|
267 |
subViews notNil ifTrue:[ |
|
60 | 268 |
xpos := horizontalSpace. |
269 |
ypos := verticalSpace. |
|
0 | 270 |
|
60 | 271 |
maxHeightInRow := 0. |
272 |
first := true. |
|
273 |
thisRow := OrderedCollection new. |
|
274 |
subViews do:[:child | |
|
275 |
"go to next row, if this subview won't fit" |
|
276 |
first ifFalse: [ |
|
277 |
(xpos + child widthIncludingBorder + horizontalSpace) > width |
|
278 |
ifTrue: [ |
|
279 |
thisRow notEmpty ifTrue:[ |
|
280 |
thisRow do:[:rowElement | |
|
281 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
282 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
283 |
] |
|
284 |
] |
|
285 |
]. |
|
286 |
ypos := ypos + verticalSpace + maxHeightInRow. |
|
287 |
xpos := horizontalSpace. |
|
288 |
maxHeightInRow := 0. |
|
289 |
thisRow := OrderedCollection new. |
|
290 |
] |
|
291 |
]. |
|
292 |
thisRow add:child. |
|
293 |
child origin:(xpos@ypos). |
|
294 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace. |
|
295 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[ |
|
296 |
maxHeightInRow := child heightIncludingBorder |
|
297 |
]. |
|
298 |
first := false |
|
299 |
]. |
|
300 |
thisRow notEmpty ifTrue:[ |
|
301 |
thisRow do:[:rowElement | |
|
302 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
303 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
304 |
] |
|
305 |
] |
|
306 |
]. |
|
0 | 307 |
]. |
308 |
mustRearrange := false |
|
309 |
! ! |
|
125 | 310 |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
311 |
!PanelView class methodsFor:'documentation'! |
205 | 312 |
|
313 |
version |
|
788
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
314 |
^ '$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.18 1996-07-15 14:40:45 cg Exp $' |
205 | 315 |
! ! |