0
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 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 |
VariableVerticalPanel subclass:#VariableHorizontalPanel
|
|
14 |
instanceVariableNames:''
|
23
|
15 |
classVariableNames:''
|
0
|
16 |
poolDictionaries:''
|
|
17 |
category:'Views-Layout'
|
|
18 |
!
|
|
19 |
|
|
20 |
VariableHorizontalPanel comment:'
|
5
|
21 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
0
|
22 |
All Rights Reserved
|
|
23 |
|
38
|
24 |
$Header: /cvs/stx/stx/libwidg/VariableHorizontalPanel.st,v 1.6 1994-08-07 13:23:35 claus Exp $
|
|
25 |
'!
|
|
26 |
|
|
27 |
!VariableHorizontalPanel class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
32 |
All Rights Reserved
|
|
33 |
|
|
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 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
|
45 |
$Header: /cvs/stx/stx/libwidg/VariableHorizontalPanel.st,v 1.6 1994-08-07 13:23:35 claus Exp $
|
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
a View to separate its subviews horizontally by a movable bar
|
|
52 |
to adjust the size-ratios.
|
|
53 |
The bar-handle is either an exposed knob (knobStyle == #motif)
|
|
54 |
or the forms defined in Scroller (knobStyle ~~ #motif)
|
|
55 |
or nothing.
|
|
56 |
|
|
57 |
The subvies dimensions MUST be given as relative sizes;
|
|
58 |
typically creation is done as:
|
0
|
59 |
|
38
|
60 |
p := VariableHorizontalPanel in:superView.
|
|
61 |
v1 := <someViewClass> origin:0.0 @ 0.0
|
|
62 |
corner:0.5 @ 1.0
|
|
63 |
in:p.
|
|
64 |
v2 := <someViewClass> origin:0.5 @ 0.0
|
|
65 |
corner:0.8 @ 1.0
|
|
66 |
in:p.
|
|
67 |
v3 := <someViewClass> origin:0.8 @ 0.0
|
|
68 |
corner:1.0 @ 1.0
|
|
69 |
in:p.
|
|
70 |
|
|
71 |
example:
|
|
72 |
|top p v1 v2 v3|
|
|
73 |
|
|
74 |
top := StandardSystemView new.
|
|
75 |
top extent:300@200.
|
0
|
76 |
|
38
|
77 |
p := VariableHorizontalPanel
|
|
78 |
origin:0.0 @ 0.0
|
|
79 |
corner:1.0 @ 1.0
|
|
80 |
in:top.
|
|
81 |
v1 := SelectionInListView
|
|
82 |
origin:0.0 @ 0.0
|
|
83 |
corner:0.5 @ 1.0
|
|
84 |
in:p.
|
|
85 |
v2 := EditTextView
|
|
86 |
origin:0.5 @ 0.0
|
|
87 |
corner:0.8 @ 1.0
|
|
88 |
in:p.
|
|
89 |
v3 := ScrollableView
|
|
90 |
for:TextView
|
|
91 |
in:p.
|
|
92 |
v3 origin:0.8 @ 0.0
|
|
93 |
corner:1.0 @ 1.0.
|
|
94 |
top open
|
|
95 |
"
|
|
96 |
! !
|
0
|
97 |
|
|
98 |
!VariableHorizontalPanel methodsFor:'initializing'!
|
|
99 |
|
|
100 |
initCursor
|
|
101 |
"set the cursor - a horizontal double arrow"
|
|
102 |
|
38
|
103 |
cursor := Cursor sourceForm:(Form fromFile:'VHPanel.xbm')
|
|
104 |
maskForm:(Form fromFile:'VHPanel_m.xbm')
|
|
105 |
hotX:8
|
|
106 |
hotY:8.
|
|
107 |
"
|
|
108 |
if bitmaps are not available, use a standard cursor
|
|
109 |
"
|
|
110 |
cursor isNil ifTrue:[
|
|
111 |
"which one looks better ?"
|
|
112 |
cursor := Cursor leftRightArrow
|
|
113 |
"cursor := Cursor leftLimitArrow"
|
|
114 |
]
|
0
|
115 |
! !
|
|
116 |
|
|
117 |
!VariableHorizontalPanel methodsFor:'private'!
|
|
118 |
|
|
119 |
handleOriginsFrom:start to:stop do:aBlock
|
|
120 |
"evaluate the argument block for some handle-origins"
|
|
121 |
|
|
122 |
|y hh|
|
|
123 |
|
|
124 |
subViews notNil ifTrue:[
|
|
125 |
shadowForm notNil ifTrue:[
|
|
126 |
hh := shadowForm height
|
|
127 |
] ifFalse:[
|
|
128 |
hh := barHeight
|
|
129 |
].
|
|
130 |
(handlePosition == #left) ifTrue:[
|
|
131 |
y := hh * 2
|
|
132 |
] ifFalse:[
|
|
133 |
(handlePosition == #right) ifTrue:[
|
|
134 |
y := height - (2 * hh) - margin
|
|
135 |
] ifFalse:[
|
|
136 |
y := height // 2
|
|
137 |
]
|
|
138 |
].
|
|
139 |
(start + 1) to:stop do:[:index |
|
|
140 |
|x view|
|
|
141 |
|
|
142 |
view := subViews at:index.
|
|
143 |
x := view origin x - barHeight + 1.
|
|
144 |
aBlock value:(x @ y)
|
|
145 |
]
|
|
146 |
]
|
|
147 |
!
|
|
148 |
|
|
149 |
setupSubviewSizes
|
|
150 |
"setup subviews sizes (in case of non-relative sizes)"
|
|
151 |
|
|
152 |
|x w |
|
|
153 |
|
|
154 |
self anyNonRelativeSubviews ifTrue:[
|
|
155 |
"there is at least one subview without
|
|
156 |
relative origin/extent - setup all subviews
|
|
157 |
to spread evenly ..."
|
|
158 |
|
|
159 |
x := 0.0.
|
|
160 |
w := 1.0 / (subViews size).
|
|
161 |
|
|
162 |
1 to:(subViews size) do:[:index |
|
|
163 |
|view|
|
|
164 |
|
|
165 |
view := subViews at:index.
|
|
166 |
index == subViews size ifTrue:[
|
|
167 |
view origin:(x @ 0.0) corner:(1.0 @ 1.0)
|
|
168 |
] ifFalse:[
|
|
169 |
view origin:(x @ 0.0) corner:((x + w) @ 1.0)
|
|
170 |
].
|
|
171 |
x := x + w
|
|
172 |
]
|
|
173 |
]
|
|
174 |
!
|
|
175 |
|
|
176 |
resizeSubviewsFrom:start to:stop
|
|
177 |
"readjust size of some subviews"
|
|
178 |
|
|
179 |
|step nSubviews|
|
|
180 |
|
|
181 |
subViews notNil ifTrue:[
|
|
182 |
(start <= stop) ifTrue:[
|
|
183 |
step := 1
|
|
184 |
] ifFalse:[
|
|
185 |
step := -1
|
|
186 |
].
|
|
187 |
nSubviews := subViews size.
|
|
188 |
start to:stop by:step do:[:index |
|
|
189 |
|bw view o1 o2 relCorner relOrg newCorner newOrg|
|
|
190 |
|
|
191 |
view := subViews at:index.
|
|
192 |
bw := view borderWidth.
|
|
193 |
|
|
194 |
index == 1 ifTrue:[
|
|
195 |
o1 := 0.
|
|
196 |
] ifFalse:[
|
|
197 |
o1 := barHeight // 2 - bw
|
|
198 |
].
|
|
199 |
index == nSubviews ifTrue:[
|
|
200 |
o2 := 0.
|
|
201 |
] ifFalse:[
|
|
202 |
o2 := barHeight // 2 - bw
|
|
203 |
].
|
|
204 |
|
|
205 |
relCorner := view relativeCorner.
|
|
206 |
relCorner isNil ifTrue:[
|
|
207 |
self error:'subview must have relative corner'
|
|
208 |
].
|
|
209 |
newCorner := view cornerFromRelativeCorner.
|
|
210 |
newCorner notNil ifTrue:[
|
|
211 |
newCorner x:(newCorner x - o2)
|
|
212 |
].
|
|
213 |
|
|
214 |
relOrg := view relativeOrigin.
|
|
215 |
relOrg isNil ifTrue:[
|
|
216 |
self error:'subview must have relative origin'
|
|
217 |
].
|
|
218 |
newOrg := view originFromRelativeOrigin.
|
|
219 |
newOrg notNil ifTrue:[
|
|
220 |
(index ~~ 1) ifTrue:[
|
|
221 |
newOrg x:(newOrg x + o1)
|
|
222 |
].
|
|
223 |
].
|
|
224 |
view pixelOrigin:newOrg corner:newCorner
|
|
225 |
]
|
|
226 |
]
|
|
227 |
! !
|
|
228 |
|
|
229 |
!VariableHorizontalPanel methodsFor:'events'!
|
|
230 |
|
|
231 |
buttonPress:button x:bx y:by
|
|
232 |
"button was pressed - if it hits a handle, start move"
|
|
233 |
|
|
234 |
|handle|
|
|
235 |
|
38
|
236 |
((button == 1) or:[button == #select]) ifTrue:[
|
0
|
237 |
handle := 1.
|
|
238 |
self handleOriginsDo:[:hPoint |
|
|
239 |
|hx|
|
|
240 |
|
|
241 |
hx := hPoint x.
|
|
242 |
(bx between:hx and:(hx + barHeight)) ifTrue:[
|
|
243 |
movedHandle := handle.
|
|
244 |
prev := hx.
|
|
245 |
start := bx - hx.
|
|
246 |
self noClipByChildren.
|
|
247 |
self xoring:[
|
|
248 |
self fillRectangleX:hx y:0 width:barHeight height:height
|
|
249 |
].
|
|
250 |
self clipByChildren.
|
|
251 |
^ self
|
|
252 |
].
|
|
253 |
handle := handle + 1
|
|
254 |
].
|
|
255 |
movedHandle := nil
|
|
256 |
] ifFalse:[
|
|
257 |
super buttonPress:button x:bx y:by
|
|
258 |
]
|
|
259 |
!
|
|
260 |
|
|
261 |
buttonMotion:button x:bx y:by
|
|
262 |
"mouse-button was moved while pressed;
|
|
263 |
clear prev handleBar and draw handle bar at new position"
|
|
264 |
|
|
265 |
|xpos limitTop limitBot|
|
|
266 |
|
|
267 |
movedHandle isNil ifTrue: [^ self]. "should not happen"
|
|
268 |
|
|
269 |
"speedup - if there is already another movement,
|
|
270 |
ignore thisone ... "
|
|
271 |
|
|
272 |
device synchronizeOutput.
|
|
273 |
self buttonMotionEventPending ifTrue:[^ self].
|
|
274 |
|
|
275 |
xpos := bx - start.
|
|
276 |
limitTop := barHeight // 2.
|
|
277 |
limitBot := self width - barHeight.
|
|
278 |
movedHandle > 1 ifTrue:[
|
|
279 |
limitTop := (subViews at:movedHandle) origin x + (barHeight // 2)
|
|
280 |
].
|
|
281 |
movedHandle < (subViews size - 1) ifTrue:[
|
|
282 |
limitBot := (subViews at:(movedHandle + 2)) origin x - barHeight
|
|
283 |
].
|
|
284 |
limitBot := limitBot - barHeight.
|
|
285 |
(xpos < limitTop) ifTrue:[ "check against view limits"
|
|
286 |
xpos := limitTop
|
|
287 |
] ifFalse:[
|
|
288 |
(xpos > limitBot) ifTrue:[
|
|
289 |
xpos := limitBot
|
|
290 |
]
|
|
291 |
].
|
|
292 |
|
|
293 |
self noClipByChildren.
|
|
294 |
self xoring:[
|
|
295 |
self fillRectangleX:prev y:0 width:barHeight height:height.
|
|
296 |
self fillRectangleX:xpos y:0 width:barHeight height:height
|
|
297 |
].
|
|
298 |
self clipByChildren.
|
|
299 |
prev := xpos
|
|
300 |
!
|
|
301 |
|
|
302 |
buttonRelease:button x:x y:y
|
|
303 |
"end bar-move"
|
|
304 |
|
|
305 |
|aboveView belowView aboveIndex belowIndex newX|
|
|
306 |
|
38
|
307 |
((button == 1) or:[button == #select]) ifTrue:[
|
0
|
308 |
movedHandle isNil ifTrue:[^ self].
|
|
309 |
|
|
310 |
"undo the last xor"
|
|
311 |
|
|
312 |
self noClipByChildren.
|
|
313 |
self xoring:[
|
|
314 |
self fillRectangleX:prev y:0 width:barHeight height:height
|
|
315 |
].
|
|
316 |
self clipByChildren.
|
|
317 |
|
|
318 |
"compute the new relative heights"
|
|
319 |
|
|
320 |
aboveIndex := movedHandle.
|
|
321 |
belowIndex := movedHandle + 1.
|
|
322 |
aboveView := subViews at:aboveIndex.
|
|
323 |
belowView := subViews at:belowIndex.
|
|
324 |
|
|
325 |
newX := (prev + start / width) asFloat .
|
|
326 |
aboveView relativeCorner:newX @ aboveView relativeCorner y.
|
|
327 |
belowView relativeOrigin:newX @ belowView relativeOrigin y.
|
|
328 |
self resizeSubviewsFrom:aboveIndex to:belowIndex.
|
|
329 |
|
|
330 |
movedHandle := nil.
|
|
331 |
|
|
332 |
"and redraw handles"
|
|
333 |
|
|
334 |
self redrawHandlesFrom:aboveIndex to:belowIndex
|
|
335 |
] ifFalse:[
|
|
336 |
super buttonRelease:button x:x y:y
|
|
337 |
]
|
|
338 |
! !
|
|
339 |
|
|
340 |
!VariableHorizontalPanel methodsFor:'drawing'!
|
|
341 |
|
|
342 |
drawHandleAtX:hx y:hy
|
|
343 |
|w x m|
|
|
344 |
|
|
345 |
(self is3D and:[shadowForm notNil]) ifTrue:[
|
|
346 |
w := shadowForm height
|
|
347 |
] ifFalse:[
|
|
348 |
w := barHeight - 4
|
|
349 |
].
|
|
350 |
|
|
351 |
self paint:viewBackground.
|
|
352 |
self fillRectangleX:hx y:margin
|
|
353 |
width:barHeight
|
|
354 |
height:(height - margin - margin).
|
|
355 |
|
|
356 |
self is3D ifTrue:[
|
|
357 |
m := (barHeight - w) // 2.
|
|
358 |
shadowForm isNil ifTrue:[
|
|
359 |
x := hx + (barHeight // 2).
|
7
|
360 |
separatingLine ifTrue:[
|
0
|
361 |
self paint:shadowColor.
|
|
362 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
363 |
x := x + 1.
|
|
364 |
self paint:lightColor.
|
|
365 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
366 |
].
|
|
367 |
self paint:viewBackground.
|
|
368 |
self fillRectangleX:hx y:(hy - barWidth)
|
|
369 |
width:w height:(barWidth + barWidth).
|
|
370 |
|
38
|
371 |
"/ x := hx. "old"
|
|
372 |
x := hx - 1. "2.10.3"
|
|
373 |
self drawEdgesForX:(x + m)
|
0
|
374 |
y:(hy - barWidth)
|
|
375 |
width:w height:(barWidth + barWidth)
|
|
376 |
level:2
|
|
377 |
] ifFalse:[
|
38
|
378 |
"/ x := hx. "old"
|
|
379 |
x := hx - 1. "2.10.3"
|
|
380 |
self drawHandleFormAtX:(x + m) y:hy
|
|
381 |
].
|
|
382 |
style == #st80 ifTrue:[
|
|
383 |
x := hx - 1.
|
|
384 |
self paint:lightColor.
|
|
385 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
386 |
x := hx + barHeight - 2.
|
|
387 |
self paint:shadowColor.
|
|
388 |
self displayLineFromX:x y:margin toX:x y:(height - margin).
|
|
389 |
].
|
0
|
390 |
] ifFalse:[
|
|
391 |
x := hx + barHeight - 2.
|
|
392 |
self paint:handleColor.
|
7
|
393 |
separatingLine ifTrue:[
|
|
394 |
self displayLineFromX:hx y:0 toX:hx y:height.
|
|
395 |
self displayLineFromX:x y:0 toX:x y:height.
|
|
396 |
].
|
0
|
397 |
self fillRectangleX:hx y:hy width:barHeight height:barHeight
|
|
398 |
]
|
|
399 |
!
|
|
400 |
|
|
401 |
redrawHandlesFrom:start to:stop
|
|
402 |
"redraw some handles"
|
|
403 |
|
|
404 |
subViews notNil ifTrue:[
|
|
405 |
self handleOriginsFrom:start to:stop do:[:hPoint |
|
|
406 |
self drawHandleAtX:(hPoint x) y:(hPoint y)
|
|
407 |
].
|
|
408 |
movedHandle notNil ifTrue:[
|
|
409 |
self noClipByChildren.
|
|
410 |
self xoring:[
|
|
411 |
self fillRectangleX:prev y:0 width:barHeight height:height
|
|
412 |
].
|
|
413 |
self clipByChildren
|
|
414 |
]
|
|
415 |
]
|
|
416 |
|
|
417 |
! !
|