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