0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
3 |
All Rights Reserved
|
|
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 |
|
|
13 |
View subclass:#PanelView
|
|
14 |
instanceVariableNames:'layout verticalSpace horizontalSpace mustRearrange'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
PanelView comment:'
|
5
|
21 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
38
|
24 |
$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.5 1994-08-07 13:23:05 claus Exp $
|
|
25 |
'!
|
|
26 |
|
|
27 |
!PanelView class methodsFor:'documentation'!
|
0
|
28 |
|
38
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1989 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
0
|
33 |
|
38
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
0
|
42 |
|
38
|
43 |
version
|
|
44 |
"
|
|
45 |
$Header: /cvs/stx/stx/libwidg/PanelView.st,v 1.5 1994-08-07 13:23:05 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
0
|
48 |
|
38
|
49 |
documentation
|
|
50 |
"
|
|
51 |
this is a view for holding subviews. (layout-widget ?!!)
|
|
52 |
|
|
53 |
Instances of PanelView try to get all their subviews into them,
|
|
54 |
arranging subviews left-to-right, top-to-bottom.
|
|
55 |
|
|
56 |
If you dont like its layout, define a new subclass or use one of
|
|
57 |
the existing subclasses: HorizontalPanelView and VerticalPanelView.
|
|
58 |
"
|
|
59 |
! !
|
0
|
60 |
|
|
61 |
!PanelView methodsFor:'initialization'!
|
|
62 |
|
|
63 |
initialize
|
|
64 |
super initialize.
|
|
65 |
|
|
66 |
layout := #center.
|
|
67 |
verticalSpace := ViewSpacing.
|
|
68 |
horizontalSpace := ViewSpacing.
|
|
69 |
mustRearrange := false
|
|
70 |
!
|
|
71 |
|
|
72 |
realize
|
|
73 |
mustRearrange ifTrue:[
|
|
74 |
self setChildPositions
|
|
75 |
].
|
|
76 |
super realize
|
|
77 |
! !
|
|
78 |
|
|
79 |
!PanelView methodsFor:'accessing'!
|
|
80 |
|
|
81 |
verticalSpace:numberOfPixels
|
|
82 |
"set the space between elements (default is 1mm)"
|
|
83 |
|
|
84 |
verticalSpace := numberOfPixels
|
|
85 |
!
|
|
86 |
|
|
87 |
horizontalSpace:numberOfPixels
|
|
88 |
"set the space between elements (default is 1mm)"
|
|
89 |
|
|
90 |
horizontalSpace := numberOfPixels
|
|
91 |
!
|
|
92 |
|
|
93 |
space:numberOfPixels
|
|
94 |
"set the space between elements (default is 1mm)"
|
|
95 |
|
|
96 |
horizontalSpace := numberOfPixels.
|
|
97 |
verticalSpace := numberOfPixels
|
|
98 |
!
|
|
99 |
|
38
|
100 |
layout
|
|
101 |
"return the layout as symbol.
|
|
102 |
the returned value is #left / #top; #spread; #center or #right / #bottom"
|
|
103 |
|
|
104 |
^ layout
|
|
105 |
!
|
|
106 |
|
0
|
107 |
layout:aSymbol
|
|
108 |
"change the layout - the argument, aSymbol is interpreted in subclasses
|
|
109 |
HorizontalPanelView and VerticalPanelView;
|
|
110 |
it may be: #left / #top; #spread; #center or #right / #bottom"
|
|
111 |
|
|
112 |
(layout ~~ aSymbol) ifTrue:[
|
|
113 |
layout := aSymbol.
|
|
114 |
self layoutChanged
|
|
115 |
]
|
|
116 |
!
|
|
117 |
|
|
118 |
addSubView:aView
|
38
|
119 |
"redefined to recompute layout when a subview is added"
|
|
120 |
|
0
|
121 |
super addSubView:aView.
|
|
122 |
self layoutChanged
|
38
|
123 |
!
|
|
124 |
|
|
125 |
addSubView:newView after:aView
|
|
126 |
"redefined to recompute layout when a subview is added"
|
|
127 |
|
|
128 |
super addSubView:newView after:aView.
|
|
129 |
self layoutChanged
|
|
130 |
!
|
|
131 |
|
|
132 |
addSubView:newView before:aView
|
|
133 |
"redefined to recompute layout when a subview is added"
|
|
134 |
|
|
135 |
super addSubView:newView before:aView.
|
|
136 |
self layoutChanged
|
0
|
137 |
! !
|
|
138 |
|
|
139 |
!PanelView methodsFor:'event processing'!
|
|
140 |
|
|
141 |
sizeChanged:how
|
|
142 |
super sizeChanged:how.
|
|
143 |
self setChildPositions
|
|
144 |
! !
|
|
145 |
|
|
146 |
!PanelView methodsFor:'private'!
|
|
147 |
|
|
148 |
layoutChanged
|
15
|
149 |
shown ifTrue:[
|
0
|
150 |
self setChildPositions
|
|
151 |
] ifFalse:[
|
|
152 |
mustRearrange := true
|
|
153 |
]
|
|
154 |
!
|
|
155 |
|
|
156 |
setChildPositions
|
|
157 |
"(re)compute position of every child"
|
|
158 |
|
38
|
159 |
|first xpos ypos maxHeightInRow thisRow fixRow|
|
0
|
160 |
|
|
161 |
subViews notNil ifTrue:[
|
|
162 |
xpos := horizontalSpace.
|
|
163 |
ypos := verticalSpace.
|
|
164 |
|
|
165 |
maxHeightInRow := 0.
|
|
166 |
first := true.
|
38
|
167 |
thisRow := OrderedCollection new.
|
0
|
168 |
subViews do:[:child |
|
|
169 |
"go to next row, if this subview won't fit"
|
|
170 |
first ifFalse: [
|
|
171 |
(xpos + child widthIncludingBorder + horizontalSpace) > width
|
|
172 |
ifTrue: [
|
38
|
173 |
thisRow notEmpty ifTrue:[
|
|
174 |
thisRow do:[:rowElement |
|
|
175 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[
|
|
176 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder))
|
|
177 |
]
|
|
178 |
]
|
|
179 |
].
|
0
|
180 |
ypos := ypos + verticalSpace + maxHeightInRow.
|
|
181 |
xpos := horizontalSpace.
|
38
|
182 |
maxHeightInRow := 0.
|
|
183 |
thisRow := OrderedCollection new.
|
0
|
184 |
]
|
|
185 |
].
|
38
|
186 |
thisRow add:child.
|
0
|
187 |
child origin:(xpos@ypos).
|
|
188 |
xpos := xpos + (child widthIncludingBorder) + horizontalSpace.
|
|
189 |
(maxHeightInRow < (child heightIncludingBorder)) ifTrue:[
|
|
190 |
maxHeightInRow := child heightIncludingBorder
|
|
191 |
].
|
|
192 |
first := false
|
38
|
193 |
].
|
|
194 |
thisRow notEmpty ifTrue:[
|
|
195 |
thisRow do:[:rowElement |
|
|
196 |
rowElement heightIncludingBorder < maxHeightInRow ifTrue:[
|
|
197 |
rowElement top:(rowElement top + (maxHeightInRow - rowElement heightIncludingBorder))
|
|
198 |
]
|
|
199 |
]
|
|
200 |
].
|
0
|
201 |
].
|
|
202 |
mustRearrange := false
|
|
203 |
! !
|