author | ca |
Tue, 04 Mar 1997 17:22:38 +0100 | |
changeset 1095 | 5cef29109661 |
parent 1072 | 79c647d81083 |
child 1159 | 856ac1c6046c |
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 |
||
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
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 |
||
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
99 |
|subViews| |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
100 |
|
202 | 101 |
elementsChangeSize := aBoolean. |
102 |
aBoolean ifTrue:[ |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
103 |
(subViews := self subViews) notNil ifTrue:[ |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
104 |
subViews do:[:aView | |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
105 |
aView addDependent:self |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
106 |
] |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
107 |
] |
202 | 108 |
] |
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
109 |
|
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
110 |
"Modified: 28.1.1997 / 17:51:28 / cg" |
202 | 111 |
! |
112 |
||
1036 | 113 |
horizontalLayout |
114 |
"not supported by this view" |
|
115 |
||
116 |
^ nil |
|
117 |
! |
|
118 |
||
119 |
horizontalLayout:aLayoutSymbol |
|
120 |
"not supported by this view" |
|
121 |
||
122 |
! |
|
123 |
||
1072 | 124 |
horizontalSpace |
125 |
"return the horizontal space between elements on pixels (default is 1mm)" |
|
126 |
||
127 |
^ horizontalSpace |
|
128 |
! |
|
129 |
||
202 | 130 |
horizontalSpace:numberOfPixels |
131 |
"set the horizontal space between elements on pixels (default is 1mm)" |
|
132 |
||
133 |
horizontalSpace ~= numberOfPixels ifTrue:[ |
|
134 |
horizontalSpace := numberOfPixels. |
|
135 |
self layoutChanged |
|
136 |
] |
|
137 |
! |
|
138 |
||
139 |
space:numberOfPixels |
|
140 |
"set the space between elements in pixels (default is 1mm) for both directions" |
|
141 |
||
142 |
(verticalSpace ~= numberOfPixels |
|
143 |
or:[horizontalSpace ~= numberOfPixels]) ifTrue:[ |
|
144 |
horizontalSpace := numberOfPixels. |
|
145 |
verticalSpace := numberOfPixels. |
|
146 |
self layoutChanged |
|
147 |
] |
|
148 |
! |
|
149 |
||
1036 | 150 |
verticalLayout |
151 |
"not supported by this view" |
|
152 |
||
153 |
^ nil |
|
154 |
! |
|
155 |
||
156 |
verticalLayout:aLayoutSymbol |
|
157 |
"not supported by this view" |
|
158 |
||
159 |
! |
|
160 |
||
1072 | 161 |
verticalSpace |
162 |
"return the vertical space between elements on pixels (default is 1mm)" |
|
163 |
||
164 |
^ verticalSpace |
|
165 |
! |
|
166 |
||
202 | 167 |
verticalSpace:numberOfPixels |
168 |
"set the vertical space between elements (in pixels). |
|
169 |
The default is computed for 1mm spacing." |
|
170 |
||
171 |
verticalSpace ~= numberOfPixels ifTrue:[ |
|
172 |
verticalSpace := numberOfPixels. |
|
173 |
self layoutChanged |
|
174 |
] |
|
175 |
! ! |
|
176 |
||
177 |
!PanelView methodsFor:'adding & removing subviews'! |
|
178 |
||
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
179 |
addComponent:aComponent |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
180 |
"redefined to recompute layout when a component is added" |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
181 |
|
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
182 |
super addComponent:aComponent. |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
183 |
self addedView:aComponent |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
184 |
|
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
185 |
"Created: 28.1.1997 / 17:44:18 / cg" |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
186 |
! |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
187 |
|
202 | 188 |
addSubView:aView |
189 |
"redefined to recompute layout when a subview is added" |
|
190 |
||
191 |
super addSubView:aView. |
|
192 |
self addedView:aView |
|
193 |
! |
|
194 |
||
195 |
addSubView:newView after:aView |
|
196 |
"redefined to recompute layout when a subview is added" |
|
197 |
||
198 |
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
|
199 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
200 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
201 |
"Modified: 15.7.1996 / 10:15:04 / cg" |
202 | 202 |
! |
203 |
||
204 |
addSubView:newView before:aView |
|
205 |
"redefined to recompute layout when a subview is added" |
|
206 |
||
207 |
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
|
208 |
self addedView:newView |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
209 |
|
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
210 |
"Modified: 15.7.1996 / 10:14:39 / cg" |
202 | 211 |
! |
212 |
||
213 |
removeSubView:aView |
|
214 |
"redefined to recompute layout when a subview is removed" |
|
215 |
||
216 |
super removeSubView:aView. |
|
217 |
aView removeDependent:self. |
|
218 |
self layoutChanged |
|
38 | 219 |
! ! |
0 | 220 |
|
221 |
!PanelView methodsFor:'event processing'! |
|
222 |
||
223 |
sizeChanged:how |
|
119 | 224 |
"my size has changed - must rearrange elements" |
225 |
||
0 | 226 |
super sizeChanged:how. |
60 | 227 |
self layoutChanged |
125 | 228 |
! |
229 |
||
230 |
update:something with:aParameter from:changedObject |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
231 |
"an element changed its size" |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
232 |
|
125 | 233 |
something == #sizeOfView ifTrue:[ |
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
234 |
self layoutChanged. |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
235 |
^ self |
125 | 236 |
]. |
237 |
^ super update:something with:aParameter from:changedObject |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
238 |
|
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
239 |
"Modified: 28.1.1997 / 17:52:44 / cg" |
0 | 240 |
! ! |
241 |
||
202 | 242 |
!PanelView methodsFor:'initialization'! |
243 |
||
244 |
initialize |
|
245 |
super initialize. |
|
246 |
||
247 |
hLayout := vLayout := #center. "/ notice, this is ignored in this class |
|
248 |
"/ used by subclasses only |
|
249 |
verticalSpace := ViewSpacing. |
|
250 |
horizontalSpace := ViewSpacing. |
|
251 |
mustRearrange := elementsChangeSize := false |
|
252 |
! |
|
253 |
||
254 |
realize |
|
255 |
mustRearrange ifTrue:[ |
|
256 |
self setChildPositions |
|
257 |
]. |
|
258 |
super realize |
|
259 |
! |
|
260 |
||
261 |
setChildPositionsIfChanged |
|
262 |
"set all of my child positions - this is usually delayed, |
|
263 |
until the panel is actually shown (since we dont know, if more |
|
264 |
elements are to be added) thus avoiding repositioning the elements |
|
265 |
over and over. However, sometimes it is nescessary, to force positioning |
|
266 |
the elements, for example, before querying the relative position of |
|
267 |
an element (modalBoxes do so, to position the ok-button under the mouse |
|
268 |
pointer)." |
|
269 |
||
270 |
mustRearrange ifTrue:[ |
|
271 |
self setChildPositions |
|
272 |
]. |
|
273 |
||
274 |
! ! |
|
275 |
||
0 | 276 |
!PanelView methodsFor:'private'! |
277 |
||
202 | 278 |
addedView:aView |
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
279 |
"added a new element - rearrange components" |
202 | 280 |
|
281 |
elementsChangeSize ifTrue:[ |
|
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
282 |
aView addDependent:self |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
283 |
]. |
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
284 |
aView resize. |
788
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
285 |
"/ explicitExtent ~~ true ifTrue:[ |
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
286 |
"/ self resize |
653fd742b5b0
extent handling when adding views
Claus Gittinger <cg@exept.de>
parents:
787
diff
changeset
|
287 |
"/ ]. |
202 | 288 |
self layoutChanged |
787
c568dfd06f11
recompute & resize to the preferredExtent when views are added
Claus Gittinger <cg@exept.de>
parents:
593
diff
changeset
|
289 |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
290 |
"Modified: 28.1.1997 / 17:45:10 / cg" |
202 | 291 |
! |
292 |
||
0 | 293 |
layoutChanged |
119 | 294 |
"called whenever repositioning is required. If the panel view is |
295 |
already visible, reposition elements right now. Otherwise, remember |
|
296 |
that a repositioning is needed to do so when the view eventually becomes |
|
297 |
visible." |
|
298 |
||
15 | 299 |
shown ifTrue:[ |
60 | 300 |
self setChildPositions |
0 | 301 |
] ifFalse:[ |
60 | 302 |
mustRearrange := true |
0 | 303 |
] |
304 |
! |
|
305 |
||
306 |
setChildPositions |
|
63 | 307 |
"(re)compute position of every child. |
308 |
This method is redefined for different layout characteristics - you may |
|
309 |
even create subclasses with completely different geometry management." |
|
0 | 310 |
|
1042 | 311 |
|first xpos ypos maxHeightInRow thisRow subViews ext| |
312 |
||
313 |
subViews := self subViews. |
|
314 |
subViews size == 0 ifTrue:[^ self]. |
|
0 | 315 |
|
1042 | 316 |
extentChanged ifTrue:[ |
317 |
ext := self computeExtent. |
|
318 |
width := ext x. |
|
319 |
height := ext y. |
|
320 |
]. |
|
0 | 321 |
|
1042 | 322 |
xpos := horizontalSpace. |
323 |
ypos := verticalSpace. |
|
324 |
||
325 |
maxHeightInRow := 0. |
|
326 |
first := true. |
|
327 |
thisRow := OrderedCollection new. |
|
328 |
subViews do:[:child | |
|
329 |
"go to next row, if this subview won't fit" |
|
330 |
first ifFalse: [ |
|
331 |
(xpos + child widthIncludingBorder + horizontalSpace) > width |
|
332 |
ifTrue: [ |
|
333 |
thisRow notEmpty ifTrue:[ |
|
334 |
thisRow do:[:rowElement | |
|
335 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
336 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
337 |
] |
1042 | 338 |
] |
339 |
]. |
|
340 |
ypos := ypos + verticalSpace + maxHeightInRow. |
|
341 |
xpos := horizontalSpace. |
|
342 |
maxHeightInRow := 0. |
|
343 |
thisRow := OrderedCollection new. |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
344 |
] |
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
345 |
]. |
1042 | 346 |
thisRow add:child. |
347 |
child origin:(xpos@ypos). |
|
348 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace. |
|
349 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[ |
|
350 |
maxHeightInRow := child heightIncludingBorder |
|
351 |
]. |
|
352 |
first := false |
|
353 |
]. |
|
354 |
thisRow notEmpty ifTrue:[ |
|
355 |
thisRow do:[:rowElement | |
|
356 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[ |
|
357 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder)) |
|
358 |
] |
|
359 |
] |
|
0 | 360 |
]. |
361 |
mustRearrange := false |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
362 |
|
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
363 |
"Modified: 28.1.1997 / 17:51:36 / cg" |
0 | 364 |
! ! |
125 | 365 |
|
980
6079922a5519
eliminated references to subViews instance variable (will vanish)
Claus Gittinger <cg@exept.de>
parents:
788
diff
changeset
|
366 |
!PanelView class methodsFor:'documentation'! |
205 | 367 |
|
368 |
version |
|
1072 | 369 |
^ '$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.22 1997-02-27 18:17:41 ca Exp $' |
205 | 370 |
! ! |