0
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1992-93 by Claus Gittinger
|
|
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 |
VariableVerticalPanel subclass:#VariableHorizontalPanel
|
|
14 |
instanceVariableNames:''
|
|
15 |
classVariableNames:'hArrow'
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
VariableHorizontalPanel comment:'
|
|
21 |
|
|
22 |
COPYRIGHT (c) 1992-93 by Claus Gittinger
|
|
23 |
All Rights Reserved
|
|
24 |
|
|
25 |
a View to separate its subviews horizontally by a movable bar
|
|
26 |
to adjust the size-ratios.
|
|
27 |
The bar-handle is either an exposed knob (knobStyle == #motif)
|
|
28 |
or the forms defined in Scroller (knobStyle ~~ #motif)
|
|
29 |
|
|
30 |
%W% %E%
|
|
31 |
|
|
32 |
written summer 92 by claus
|
|
33 |
'!
|
|
34 |
|
|
35 |
!VariableHorizontalPanel methodsFor:'initializing'!
|
|
36 |
|
|
37 |
initCursor
|
|
38 |
"set the cursor - a horizontal double arrow"
|
|
39 |
|
|
40 |
"which one looks better ?"
|
|
41 |
cursor := Cursor leftRightArrow
|
|
42 |
"cursor := Cursor leftLimitArrow"
|
|
43 |
! !
|
|
44 |
|
|
45 |
!VariableHorizontalPanel methodsFor:'private'!
|
|
46 |
|
|
47 |
handleOriginsFrom:start to:stop do:aBlock
|
|
48 |
"evaluate the argument block for some handle-origins"
|
|
49 |
|
|
50 |
|y hh|
|
|
51 |
|
|
52 |
subViews notNil ifTrue:[
|
|
53 |
shadowForm notNil ifTrue:[
|
|
54 |
hh := shadowForm height
|
|
55 |
] ifFalse:[
|
|
56 |
hh := barHeight
|
|
57 |
].
|
|
58 |
(handlePosition == #left) ifTrue:[
|
|
59 |
y := hh * 2
|
|
60 |
] ifFalse:[
|
|
61 |
(handlePosition == #right) ifTrue:[
|
|
62 |
y := height - (2 * hh) - margin
|
|
63 |
] ifFalse:[
|
|
64 |
y := height // 2
|
|
65 |
]
|
|
66 |
].
|
|
67 |
(start + 1) to:stop do:[:index |
|
|
68 |
|x view|
|
|
69 |
|
|
70 |
view := subViews at:index.
|
|
71 |
x := view origin x - barHeight + 1.
|
|
72 |
aBlock value:(x @ y)
|
|
73 |
]
|
|
74 |
]
|
|
75 |
!
|
|
76 |
|
|
77 |
setupSubviewSizes
|
|
78 |
"setup subviews sizes (in case of non-relative sizes)"
|
|
79 |
|
|
80 |
|x w |
|
|
81 |
|
|
82 |
self anyNonRelativeSubviews ifTrue:[
|
|
83 |
"there is at least one subview without
|
|
84 |
relative origin/extent - setup all subviews
|
|
85 |
to spread evenly ..."
|
|
86 |
|
|
87 |
x := 0.0.
|
|
88 |
w := 1.0 / (subViews size).
|
|
89 |
|
|
90 |
1 to:(subViews size) do:[:index |
|
|
91 |
|view|
|
|
92 |
|
|
93 |
view := subViews at:index.
|
|
94 |
index == subViews size ifTrue:[
|
|
95 |
view origin:(x @ 0.0) corner:(1.0 @ 1.0)
|
|
96 |
] ifFalse:[
|
|
97 |
view origin:(x @ 0.0) corner:((x + w) @ 1.0)
|
|
98 |
].
|
|
99 |
x := x + w
|
|
100 |
]
|
|
101 |
]
|
|
102 |
!
|
|
103 |
|
|
104 |
resizeSubviewsFrom:start to:stop
|
|
105 |
"readjust size of some subviews"
|
|
106 |
|
|
107 |
|step nSubviews|
|
|
108 |
|
|
109 |
subViews notNil ifTrue:[
|
|
110 |
(start <= stop) ifTrue:[
|
|
111 |
step := 1
|
|
112 |
] ifFalse:[
|
|
113 |
step := -1
|
|
114 |
].
|
|
115 |
nSubviews := subViews size.
|
|
116 |
start to:stop by:step do:[:index |
|
|
117 |
|bw view o1 o2 relCorner relOrg newCorner newOrg|
|
|
118 |
|
|
119 |
view := subViews at:index.
|
|
120 |
bw := view borderWidth.
|
|
121 |
|
|
122 |
index == 1 ifTrue:[
|
|
123 |
o1 := 0.
|
|
124 |
] ifFalse:[
|
|
125 |
o1 := barHeight // 2 - bw
|
|
126 |
].
|
|
127 |
index == nSubviews ifTrue:[
|
|
128 |
o2 := 0.
|
|
129 |
] ifFalse:[
|
|
130 |
o2 := barHeight // 2 - bw
|
|
131 |
].
|
|
132 |
|
|
133 |
relCorner := view relativeCorner.
|
|
134 |
relCorner isNil ifTrue:[
|
|
135 |
self error:'subview must have relative corner'
|
|
136 |
].
|
|
137 |
newCorner := view cornerFromRelativeCorner.
|
|
138 |
newCorner notNil ifTrue:[
|
|
139 |
newCorner x:(newCorner x - o2)
|
|
140 |
].
|
|
141 |
|
|
142 |
relOrg := view relativeOrigin.
|
|
143 |
relOrg isNil ifTrue:[
|
|
144 |
self error:'subview must have relative origin'
|
|
145 |
].
|
|
146 |
newOrg := view originFromRelativeOrigin.
|
|
147 |
newOrg notNil ifTrue:[
|
|
148 |
(index ~~ 1) ifTrue:[
|
|
149 |
newOrg x:(newOrg x + o1)
|
|
150 |
].
|
|
151 |
].
|
|
152 |
view pixelOrigin:newOrg corner:newCorner
|
|
153 |
]
|
|
154 |
]
|
|
155 |
! !
|
|
156 |
|
|
157 |
!VariableHorizontalPanel methodsFor:'events'!
|
|
158 |
|
|
159 |
buttonPress:button x:bx y:by
|
|
160 |
"button was pressed - if it hits a handle, start move"
|
|
161 |
|
|
162 |
|handle|
|
|
163 |
|
|
164 |
(button == 1) ifTrue:[
|
|
165 |
handle := 1.
|
|
166 |
self handleOriginsDo:[:hPoint |
|
|
167 |
|hx|
|
|
168 |
|
|
169 |
hx := hPoint x.
|
|
170 |
(bx between:hx and:(hx + barHeight)) ifTrue:[
|
|
171 |
movedHandle := handle.
|
|
172 |
prev := hx.
|
|
173 |
start := bx - hx.
|
|
174 |
self noClipByChildren.
|
|
175 |
self xoring:[
|
|
176 |
self fillRectangleX:hx y:0 width:barHeight height:height
|
|
177 |
].
|
|
178 |
self clipByChildren.
|
|
179 |
^ self
|
|
180 |
].
|
|
181 |
handle := handle + 1
|
|
182 |
].
|
|
183 |
movedHandle := nil
|
|
184 |
] ifFalse:[
|
|
185 |
super buttonPress:button x:bx y:by
|
|
186 |
]
|
|
187 |
!
|
|
188 |
|
|
189 |
buttonMotion:button x:bx y:by
|
|
190 |
"mouse-button was moved while pressed;
|
|
191 |
clear prev handleBar and draw handle bar at new position"
|
|
192 |
|
|
193 |
|xpos limitTop limitBot|
|
|
194 |
|
|
195 |
movedHandle isNil ifTrue: [^ self]. "should not happen"
|
|
196 |
|
|
197 |
"speedup - if there is already another movement,
|
|
198 |
ignore thisone ... "
|
|
199 |
|
|
200 |
device synchronizeOutput.
|
|
201 |
self buttonMotionEventPending ifTrue:[^ self].
|
|
202 |
|
|
203 |
xpos := bx - start.
|
|
204 |
limitTop := barHeight // 2.
|
|
205 |
limitBot := self width - barHeight.
|
|
206 |
movedHandle > 1 ifTrue:[
|
|
207 |
limitTop := (subViews at:movedHandle) origin x + (barHeight // 2)
|
|
208 |
].
|
|
209 |
movedHandle < (subViews size - 1) ifTrue:[
|
|
210 |
limitBot := (subViews at:(movedHandle + 2)) origin x - barHeight
|
|
211 |
].
|
|
212 |
limitBot := limitBot - barHeight.
|
|
213 |
(xpos < limitTop) ifTrue:[ "check against view limits"
|
|
214 |
xpos := limitTop
|
|
215 |
] ifFalse:[
|
|
216 |
(xpos > limitBot) ifTrue:[
|
|
217 |
xpos := limitBot
|
|
218 |
]
|
|
219 |
].
|
|
220 |
|
|
221 |
self noClipByChildren.
|
|
222 |
self xoring:[
|
|
223 |
self fillRectangleX:prev y:0 width:barHeight height:height.
|
|
224 |
self fillRectangleX:xpos y:0 width:barHeight height:height
|
|
225 |
].
|
|
226 |
self clipByChildren.
|
|
227 |
prev := xpos
|
|
228 |
!
|
|
229 |
|
|
230 |
buttonRelease:button x:x y:y
|
|
231 |
"end bar-move"
|
|
232 |
|
|
233 |
|aboveView belowView aboveIndex belowIndex newX|
|
|
234 |
|
|
235 |
(button == 1) ifTrue:[
|
|
236 |
movedHandle isNil ifTrue:[^ self].
|
|
237 |
|
|
238 |
"undo the last xor"
|
|
239 |
|
|
240 |
self noClipByChildren.
|
|
241 |
self xoring:[
|
|
242 |
self fillRectangleX:prev y:0 width:barHeight height:height
|
|
243 |
].
|
|
244 |
self clipByChildren.
|
|
245 |
|
|
246 |
"compute the new relative heights"
|
|
247 |
|
|
248 |
aboveIndex := movedHandle.
|
|
249 |
belowIndex := movedHandle + 1.
|
|
250 |
aboveView := subViews at:aboveIndex.
|
|
251 |
belowView := subViews at:belowIndex.
|
|
252 |
|
|
253 |
newX := (prev + start / width) asFloat .
|
|
254 |
aboveView relativeCorner:newX @ aboveView relativeCorner y.
|
|
255 |
belowView relativeOrigin:newX @ belowView relativeOrigin y.
|
|
256 |
self resizeSubviewsFrom:aboveIndex to:belowIndex.
|
|
257 |
|
|
258 |
movedHandle := nil.
|
|
259 |
|
|
260 |
"and redraw handles"
|
|
261 |
|
|
262 |
self redrawHandlesFrom:aboveIndex to:belowIndex
|
|
263 |
] ifFalse:[
|
|
264 |
super buttonRelease:button x:x y:y
|
|
265 |
]
|
|
266 |
! !
|
|
267 |
|
|
268 |
!VariableHorizontalPanel methodsFor:'drawing'!
|
|
269 |
|
|
270 |
drawHandleAtX:hx y:hy
|
|
271 |
|w x m|
|
|
272 |
|
|
273 |
(self is3D and:[shadowForm notNil]) ifTrue:[
|
|
274 |
w := shadowForm height
|
|
275 |
] ifFalse:[
|
|
276 |
w := barHeight - 4
|
|
277 |
].
|
|
278 |
|
|
279 |
self paint:viewBackground.
|
|
280 |
self fillRectangleX:hx y:margin
|
|
281 |
width:barHeight
|
|
282 |
height:(height - margin - margin).
|
|
283 |
|
|
284 |
self is3D ifTrue:[
|
|
285 |
m := (barHeight - w) // 2.
|
|
286 |
shadowForm isNil ifTrue:[
|
|
287 |
x := hx + (barHeight // 2).
|
|
288 |
style == #motif ifTrue:[
|
|
289 |
self paint:shadowColor.
|
|
290 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
291 |
x := x + 1.
|
|
292 |
self paint:lightColor.
|
|
293 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
294 |
].
|
|
295 |
self paint:viewBackground.
|
|
296 |
self fillRectangleX:hx y:(hy - barWidth)
|
|
297 |
width:w height:(barWidth + barWidth).
|
|
298 |
|
|
299 |
self drawEdgesForX:(hx + m)
|
|
300 |
y:(hy - barWidth)
|
|
301 |
width:w height:(barWidth + barWidth)
|
|
302 |
level:2
|
|
303 |
] ifFalse:[
|
|
304 |
self drawHandleFormAtX:(hx + m) y:hy
|
|
305 |
]
|
|
306 |
] ifFalse:[
|
|
307 |
x := hx + barHeight - 2.
|
|
308 |
self paint:handleColor.
|
|
309 |
self displayLineFromX:hx y:0 toX:hx y:height.
|
|
310 |
self displayLineFromX:x y:0 toX:x y:height.
|
|
311 |
self fillRectangleX:hx y:hy width:barHeight height:barHeight
|
|
312 |
]
|
|
313 |
!
|
|
314 |
|
|
315 |
redrawHandlesFrom:start to:stop
|
|
316 |
"redraw some handles"
|
|
317 |
|
|
318 |
subViews notNil ifTrue:[
|
|
319 |
self handleOriginsFrom:start to:stop do:[:hPoint |
|
|
320 |
self drawHandleAtX:(hPoint x) y:(hPoint y)
|
|
321 |
].
|
|
322 |
movedHandle notNil ifTrue:[
|
|
323 |
self noClipByChildren.
|
|
324 |
self xoring:[
|
|
325 |
self fillRectangleX:prev y:0 width:barHeight height:height
|
|
326 |
].
|
|
327 |
self clipByChildren
|
|
328 |
]
|
|
329 |
]
|
|
330 |
|
|
331 |
! !
|