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
|
125
|
14 |
instanceVariableNames:'hLayout vLayout verticalSpace horizontalSpace mustRearrange
|
202
|
15 |
elementsChangeSize'
|
125
|
16 |
classVariableNames:''
|
|
17 |
poolDictionaries:''
|
|
18 |
category:'Views-Layout'
|
0
|
19 |
!
|
|
20 |
|
38
|
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 |
|
|
64 |
Instance variables:
|
|
65 |
|
|
66 |
hLayout <Symbol> controls horizontal layout; ignored in this
|
|
67 |
class, but used in Horizontal- and
|
|
68 |
VerticalPanelViews. See more info there.
|
|
69 |
|
|
70 |
vLayout <Symbol> controls vertical layout; ignored in this
|
|
71 |
class, but used in Horizontal- and
|
|
72 |
VerticalPanelViews. See more info there.
|
|
73 |
|
|
74 |
horizontalSpace <Integer> number of pixels to use as space between elements
|
119
|
75 |
defaults to ViewSpacing, which is 1mm
|
63
|
76 |
|
|
77 |
verticalSpace <Integer> number of pixels to use as space between elements
|
119
|
78 |
defaults to ViewSpacing, which is 1mm
|
63
|
79 |
|
|
80 |
mustRearrange <Boolean> internal flag, if rearrangement is needed
|
125
|
81 |
|
|
82 |
elementsChangeSize
|
|
83 |
<Boolean> if true, the panel takes care of this situation.
|
|
84 |
By default, this is false.
|
38
|
85 |
"
|
127
|
86 |
!
|
|
87 |
|
|
88 |
examples
|
|
89 |
"
|
|
90 |
fill a panel with many buttons (see what happens on resize):
|
|
91 |
|
|
92 |
|top panel|
|
|
93 |
|
|
94 |
top := StandardSystemView new.
|
|
95 |
top extent:200@200.
|
|
96 |
panel := PanelView origin:0.0@0.0 corner:1.0@1.0 in:top.
|
|
97 |
|
|
98 |
#('one' 'two' 'three' 'four' 'five' 'six' 'seven' 'eight'
|
|
99 |
'nine' 'ten' 'aVeryLongOne') do:[:label |
|
|
100 |
|b|
|
|
101 |
|
|
102 |
b := Button label:label.
|
|
103 |
panel add:b.
|
|
104 |
].
|
|
105 |
top open
|
|
106 |
"
|
202
|
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
|
38
|
190 |
! !
|
0
|
191 |
|
|
192 |
!PanelView methodsFor:'event processing'!
|
|
193 |
|
|
194 |
sizeChanged:how
|
119
|
195 |
"my size has changed - must rearrange elements"
|
|
196 |
|
0
|
197 |
super sizeChanged:how.
|
60
|
198 |
self layoutChanged
|
125
|
199 |
!
|
|
200 |
|
|
201 |
update:something with:aParameter from:changedObject
|
|
202 |
something == #sizeOfView ifTrue:[
|
|
203 |
"
|
|
204 |
an element changed its size
|
|
205 |
"
|
|
206 |
(subViews includes:changedObject) ifTrue:[
|
|
207 |
self layoutChanged
|
|
208 |
].
|
|
209 |
^ self
|
|
210 |
].
|
|
211 |
^ super update:something with:aParameter from:changedObject
|
0
|
212 |
! !
|
|
213 |
|
202
|
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 |
|
0
|
248 |
!PanelView methodsFor:'private'!
|
|
249 |
|
202
|
250 |
addedView:aView
|
|
251 |
"added a new element"
|
|
252 |
|
|
253 |
elementsChangeSize ifTrue:[
|
|
254 |
aView addDependent:self
|
|
255 |
].
|
|
256 |
self layoutChanged
|
|
257 |
!
|
|
258 |
|
0
|
259 |
layoutChanged
|
119
|
260 |
"called whenever repositioning is required. If the panel view is
|
|
261 |
already visible, reposition elements right now. Otherwise, remember
|
|
262 |
that a repositioning is needed to do so when the view eventually becomes
|
|
263 |
visible."
|
|
264 |
|
15
|
265 |
shown ifTrue:[
|
60
|
266 |
self setChildPositions
|
0
|
267 |
] ifFalse:[
|
60
|
268 |
mustRearrange := true
|
0
|
269 |
]
|
|
270 |
!
|
|
271 |
|
|
272 |
setChildPositions
|
63
|
273 |
"(re)compute position of every child.
|
|
274 |
This method is redefined for different layout characteristics - you may
|
|
275 |
even create subclasses with completely different geometry management."
|
0
|
276 |
|
60
|
277 |
|first xpos ypos maxHeightInRow thisRow|
|
0
|
278 |
|
|
279 |
subViews notNil ifTrue:[
|
60
|
280 |
xpos := horizontalSpace.
|
|
281 |
ypos := verticalSpace.
|
0
|
282 |
|
60
|
283 |
maxHeightInRow := 0.
|
|
284 |
first := true.
|
|
285 |
thisRow := OrderedCollection new.
|
|
286 |
subViews do:[:child |
|
|
287 |
"go to next row, if this subview won't fit"
|
|
288 |
first ifFalse: [
|
|
289 |
(xpos + child widthIncludingBorder + horizontalSpace) > width
|
|
290 |
ifTrue: [
|
|
291 |
thisRow notEmpty ifTrue:[
|
|
292 |
thisRow do:[:rowElement |
|
|
293 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[
|
|
294 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder))
|
|
295 |
]
|
|
296 |
]
|
|
297 |
].
|
|
298 |
ypos := ypos + verticalSpace + maxHeightInRow.
|
|
299 |
xpos := horizontalSpace.
|
|
300 |
maxHeightInRow := 0.
|
|
301 |
thisRow := OrderedCollection new.
|
|
302 |
]
|
|
303 |
].
|
|
304 |
thisRow add:child.
|
|
305 |
child origin:(xpos@ypos).
|
|
306 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace.
|
|
307 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[
|
|
308 |
maxHeightInRow := child heightIncludingBorder
|
|
309 |
].
|
|
310 |
first := false
|
|
311 |
].
|
|
312 |
thisRow notEmpty ifTrue:[
|
|
313 |
thisRow do:[:rowElement |
|
|
314 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[
|
|
315 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder))
|
|
316 |
]
|
|
317 |
]
|
|
318 |
].
|
0
|
319 |
].
|
|
320 |
mustRearrange := false
|
|
321 |
! !
|
125
|
322 |
|