HorizontalPanelView.st
changeset 379 a0ada7891fe9
parent 340 f820bcd29a51
child 585 8f395aba0173
--- a/HorizontalPanelView.st	Thu Feb 22 19:01:52 1996 +0100
+++ b/HorizontalPanelView.st	Thu Feb 22 21:26:38 1996 +0100
@@ -987,231 +987,245 @@
      my size has changed"
 
     |xpos space sumOfWidths numChilds l wEach wInside hL vL resizeToMaxV 
-     resizeToMaxH maxHeight maxWidth d|
+     resizeToMaxH maxHeight maxWidth d m2|
 
     subViews isNil ifTrue:[^ self].
 
     space := horizontalSpace.
     numChilds := subViews size.
-    wInside := width - (margin * 2) + (borderWidth*2) - subViews last borderWidth.
+    m2 := margin * 2.
+    wInside := width - m2 + (borderWidth*2) - subViews last borderWidth.
 
     hL := hLayout.
     vL := vLayout.
 
     resizeToMaxH := false.
     (hL endsWith:'Max') ifTrue:[
-	wEach := maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder].
-	hL := (hL copyWithoutLast:3) asSymbol.
-	resizeToMaxH := true.
+        wEach := maxWidth := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child widthIncludingBorder].
+        hL := (hL copyWithoutLast:3) asSymbol.
+        resizeToMaxH := true.
     ].
 
     hL == #fitSpace ifTrue:[
-	"
-	 adjust childs extents and set origins.
-	 Be careful to avoid accumulation of rounding errors
-	"
-	wEach := (wInside - (numChilds + 1 * space)) / numChilds.
-	xpos := space + margin - borderWidth.
+        "
+         adjust childs extents and set origins.
+         Be careful to avoid accumulation of rounding errors
+        "
+        wEach := (wInside - (numChilds + 1 * space)) / numChilds.
+        xpos := space + margin - borderWidth.
     ] ifFalse:[
-	hL == #fit ifTrue:[
-	    "
-	     adjust childs extents and set origins.
-	     Be careful to avoid accumulation of rounding errors
-	    "
-	    wEach := (wInside - (numChilds - 1 * space)) / numChilds.
-	    xpos := margin - borderWidth.
-	] ifFalse:[
-	    "
-	     compute net width needed
-	    "
-	    resizeToMaxH ifTrue:[
-		sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + maxWidth + (child borderWidth*2)].
-	    ] ifFalse:[
-		sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
-	    ].
+        hL == #fit ifTrue:[
+            "
+             adjust childs extents and set origins.
+             Be careful to avoid accumulation of rounding errors
+            "
+            wEach := (wInside - (numChilds - 1 * space)) / numChilds.
+            xpos := margin - borderWidth.
+        ] ifFalse:[
+            "
+             compute net width needed
+            "
+            resizeToMaxH ifTrue:[
+                sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + maxWidth + (child borderWidth*2)].
+            ] ifFalse:[
+                sumOfWidths := subViews inject:0 into:[:sumSoFar :child | sumSoFar + child widthIncludingBorder].
+            ].
 
-	    l := hL.
-	    ((l == #center) and:[numChilds == 1]) ifTrue:[
-		l := #spread
-	    ].
-	    (l == #spread and:[numChilds == 1]) ifTrue:[
-		l := #spreadSpace
-	    ].
+            l := hL.
+            ((l == #center) and:[numChilds == 1]) ifTrue:[
+                l := #spread
+            ].
+            (l == #spread and:[numChilds == 1]) ifTrue:[
+                l := #spreadSpace
+            ].
 
-	    "
-	     compute position of leftmost subview and space between them;
-	     if they do hardly fit, leave no space between them 
-	    "
-	    ((sumOfWidths >= (width - (margin * 2))) 
-	    and:[l ~~ #fixLeftSpace and:[l ~~ #fixLeft]]) ifTrue:[
-		xpos := 0.
-		space := 0
-	    ] ifFalse: [
-		l == #fixLeftSpace ifTrue:[
-		    l := #leftSpace
-		] ifFalse:[
-		    l == #fixLeft ifTrue:[
-			l := #left
-		    ]
-		].
-		((l == #right) or:[l == #rightSpace]) ifTrue:[
-		    xpos := width - (space * (numChilds - 1)) - sumOfWidths.
-	"
-		    borderWidth == 0 ifTrue:[
-			xpos := xpos + space 
-		    ].
-	"
-		    l == #rightSpace ifTrue:[
-			xpos >= space ifTrue:[
-			    xpos := xpos - space
-			]
-		    ].
+            "
+             compute position of leftmost subview and space between them;
+             if they do hardly fit, leave no space between them 
+            "
+            ((sumOfWidths >= (width - m2)) 
+            and:[l ~~ #fixLeftSpace and:[l ~~ #fixLeft]]) ifTrue:[
+                xpos := margin.
+                space := 0
+            ] ifFalse: [
+                l == #fixLeftSpace ifTrue:[
+                    l := #leftSpace
+                ] ifFalse:[
+                    l == #fixLeft ifTrue:[
+                        l := #left
+                    ]
+                ].
+                ((l == #right) or:[l == #rightSpace]) ifTrue:[
+                    xpos := width - (space * (numChilds - 1)) - sumOfWidths.
+        "
+                    borderWidth == 0 ifTrue:[
+                        xpos := xpos + space 
+                    ].
+        "
+                    l == #rightSpace ifTrue:[
+                        xpos >= space ifTrue:[
+                            xpos := xpos - space
+                        ]
+                    ].
 
-		    xpos < 0 ifTrue:[
-			space := space min:(width - sumOfWidths) // (numChilds + 1).
-			xpos := width - (space * numChilds) - sumOfWidths.
-		    ]
-		] ifFalse:[
-		    (l == #spread) ifTrue:[
-			space := (width - sumOfWidths) // (numChilds - 1).
-			xpos := 0.
-			(space == 0) ifTrue:[
-			    xpos := (width - sumOfWidths) // 2
-			]
-		    ] ifFalse:[
-		      (l == #spreadSpace) ifTrue:[
-			space := (width - sumOfWidths) // (numChilds + 1).
-			xpos := space.
-			(space == 0) ifTrue:[
-			    xpos := (width - sumOfWidths) // 2
-			]
-		      ] ifFalse:[
-			((l == #left) 
-			or:[l == #leftSpace
-			or:[l == #leftFit
-			or:[l == #leftSpaceFit]]]) ifTrue:[
-			    space := space min:(width - sumOfWidths) // (numChilds + 1).
-			    (hL == #fixLeft or:[hL == #fixLeftSpace]) ifTrue:[
-				space := space max:horizontalSpace.
-			    ] ifFalse:[
-				space := space max:0.
-			    ].
-			    (l == #leftSpace 
-			    or:[l == #leftSpaceFit]) ifTrue:[
-				xpos := space.
-			    ] ifFalse:[
-				xpos := 0
-			    ]
-	"
-			    borderWidth == 0 ifTrue:[
-				xpos := 0 
-			    ].
-	"
-			] ifFalse:[
-			    "center"
-			    xpos := (width - (sumOfWidths
-					      + ((numChilds - 1) * space))) // 2.
-			    xpos < 0 ifTrue:[
-				space := (width - sumOfWidths) // (numChilds + 1).
-				xpos := (width - (sumOfWidths
-					       + ((numChilds - 1) * space))) // 2.
-			    ]
-			]
-		      ]
-		    ]
-		]
-	    ].
-	].
+                    xpos < 0 ifTrue:[
+                        space := space min:(width - sumOfWidths) // (numChilds + 1).
+                        xpos := width - (space * numChilds) - sumOfWidths.
+                    ]
+                ] ifFalse:[
+                    (l == #spread) ifTrue:[
+                        space := (width - m2 - sumOfWidths) // (numChilds - 1).
+                        xpos := margin.
+                        (space == 0) ifTrue:[
+                            xpos := (width - sumOfWidths) // 2
+                        ]
+                    ] ifFalse:[
+                      (l == #spreadSpace) ifTrue:[
+                        space := (width - sumOfWidths) // (numChilds + 1).
+                        xpos := space.
+                        (space == 0) ifTrue:[
+                            xpos := (width - sumOfWidths) // 2
+                        ]
+                      ] ifFalse:[
+                        ((l == #left) 
+                        or:[l == #leftSpace
+                        or:[l == #leftFit
+                        or:[l == #leftSpaceFit]]]) ifTrue:[
+                            space := space min:(width - sumOfWidths - m2) // (numChilds + 1).
+                            (hL == #fixLeft or:[hL == #fixLeftSpace]) ifTrue:[
+                                space := space max:horizontalSpace.
+                            ] ifFalse:[
+                                space := space max:0.
+                            ].
+                            (l == #leftSpace 
+                            or:[l == #leftSpaceFit]) ifTrue:[
+                                xpos := space.
+                            ] ifFalse:[
+                                "/
+                                "/ if the very first view has a 0-level AND
+                                "/ my level is non-zero, begin with margin
+                                "/
+                                (margin ~~ 0 and:[subViews first level == 0]) ifTrue:[
+                                    xpos := margin
+                                ] ifFalse:[
+                                    xpos := 0
+                                ]
+                            ]
+                        ] ifFalse:[
+                            "center"
+                            xpos := (width - (sumOfWidths
+                                              + ((numChilds - 1) * space))) // 2.
+                            xpos < 0 ifTrue:[
+                                space := (width - sumOfWidths) // (numChilds + 1).
+                                xpos := (width - (sumOfWidths
+                                               + ((numChilds - 1) * space))) // 2.
+                            ]
+                        ]
+                      ]
+                    ]
+                ]
+            ].
+        ].
     ].
 
     vL := vLayout.
     resizeToMaxV := false.
     (vLayout endsWith:'Max') ifTrue:[
-	resizeToMaxV := true.
-	maxHeight := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child heightIncludingBorder].
-	vL == #centerMax ifTrue:[vL := #center].
-	vL == #bottomMax ifTrue:[vL := #bottom].
-	vL == #bottomSpaceMax ifTrue:[vL := #bottomSpace].
-	vL == #topMax ifTrue:[vL := #top].
-	vL == #topSpaceMax ifTrue:[vL := #topSpace].
+        resizeToMaxV := true.
+        maxHeight := subViews inject:0 into:[:maxSoFar :child | maxSoFar max:child heightIncludingBorder].
+        vL == #centerMax ifTrue:[vL := #center].
+        vL == #bottomMax ifTrue:[vL := #bottom].
+        vL == #bottomSpaceMax ifTrue:[vL := #bottomSpace].
+        vL == #topMax ifTrue:[vL := #top].
+        vL == #topSpaceMax ifTrue:[vL := #topSpace].
     ].
 
     "now set positions"
 
     subViews keysAndValuesDo:[:index :child |
-	|ypos advance bwChild hChild|
+        |ypos advance bwChild hChild newHChild|
 
-	hChild := child heightIncludingBorder.
-	bwChild := child borderWidth.
+        hChild := child heightIncludingBorder.
+        bwChild := child borderWidth.
 
-	resizeToMaxV ifTrue:[
-	    child height:(hChild := maxHeight - (bwChild  * 2)).
-	].
+        resizeToMaxV ifTrue:[
+            child height:(hChild := maxHeight - (bwChild  * 2)).
+        ].
 
-	vL == #top ifTrue:[
-	    ypos := 0
-	] ifFalse:[
-	    vL == #topSpace ifTrue:[
-		ypos := verticalSpace
-	    ] ifFalse:[
-		vL == #bottom ifTrue:[
-		    ypos := height - child heightIncludingBorder
-		] ifFalse:[
-		    vL == #bottomSpace ifTrue:[
-			ypos := height - verticalSpace - child heightIncludingBorder.
-		    ] ifFalse:[
-			vL == #fitSpace ifTrue:[
-			    ypos := verticalSpace.
-			    child height:(height - (verticalSpace + bwChild * 2))
-			] ifFalse:[
-			    vL == #fit ifTrue:[
-				ypos := 0.
-				child height:(height - (bwChild * 2))
-			    ] ifFalse:[
-				"centered"
-				ypos := (height - child heightIncludingBorder) // 2.
-			    ]
-			]
-		    ]
-		]
-	    ]
-	].
-	(ypos < 0) ifTrue:[ypos := 0].
+        vL == #top ifTrue:[
+            ypos := margin
+        ] ifFalse:[
+            vL == #topSpace ifTrue:[
+                ypos := verticalSpace
+            ] ifFalse:[
+                vL == #bottom ifTrue:[
+                    ypos := height - margin - child heightIncludingBorder
+                ] ifFalse:[
+                    vL == #bottomSpace ifTrue:[
+                        ypos := height - verticalSpace - child heightIncludingBorder.
+                    ] ifFalse:[
+                        vL == #fitSpace ifTrue:[
+                            ypos := verticalSpace.
+                            newHChild := height - (verticalSpace + bwChild * 2)
+                        ] ifFalse:[
+                            vL == #fit ifTrue:[
+                                newHChild := height - (bwChild * 2).
+                                child level == 0 ifTrue:[
+                                    ypos := margin.
+                                    newHChild := newHChild - m2
+                                ] ifFalse:[
+                                    ypos := 0. 
+                                ].
+                            ] ifFalse:[
+                                "centered"
+                                ypos := (height - m2 - hChild) // 2.
+                            ]
+                        ]
+                    ]
+                ]
+            ]
+        ].
+        newHChild notNil ifTrue:[
+            child height:newHChild
+        ].
 
-	(hL == #fit 
-	 or:[hL == #fitSpace
-	 or:[resizeToMaxH]]) ifTrue:[
-	    child sizeFixed ifTrue:[
-		d := wEach - (child widthIncludingBorder) // 2.
-		child origin:(xpos truncated + d @ ypos)
-	    ] ifFalse:[
-		child origin:(xpos truncated @ ypos)
-		      corner:(xpos + wEach - (child borderWidth) - 1) truncated
-			     @ (ypos + child height - 1).
-	    ].
-	    advance := wEach.
-	] ifFalse:[
-	    child origin:(xpos @ ypos).
-	    advance := child widthIncludingBorder
-	].
-	xpos := xpos + advance + space.
+        (ypos < 0) ifTrue:[ypos := 0].
 
-	index == numChilds ifTrue:[
-	    |x|
+        (hL == #fit 
+         or:[hL == #fitSpace
+         or:[resizeToMaxH]]) ifTrue:[
+            child sizeFixed ifTrue:[
+                d := wEach - (child widthIncludingBorder) // 2.
+                child origin:(xpos truncated + d @ ypos)
+            ] ifFalse:[
+                child origin:(xpos truncated @ ypos)
+                      corner:(xpos + wEach - (child borderWidth) - 1) truncated
+                             @ (ypos + child height - 1).
+            ].
+            advance := wEach.
+        ] ifFalse:[
+            child origin:(xpos @ ypos).
+            advance := child widthIncludingBorder
+        ].
+        xpos := xpos + advance + space.
 
-	    hL == #leftFit ifTrue:[
-		x := width - margin - 1.
-	    ].
-	    hL == #leftSpaceFit ifTrue:[
-		x := width - margin - 1 - space
-	    ].
-	    x notNil ifTrue:[
-		subViews last corner:(x @ (ypos + child height - 1))
-	    ]
-	]
+        index == numChilds ifTrue:[
+            |x|
+
+            (hL == #leftFit or:[hL == #leftSpaceFit]) ifTrue:[
+                x := width - margin - 1.
+                hL == #leftSpaceFit ifTrue:[
+                    x := x - space
+                ]
+            ].
+            x notNil ifTrue:[
+                subViews last corner:(x @ (ypos + child height - 1))
+            ]
+        ]
     ].
 
     "Modified: 4.9.1995 / 18:43:10 / claus"
+    "Modified: 22.2.1996 / 21:25:54 / cg"
 ! !
 
 !HorizontalPanelView methodsFor:'queries'!
@@ -1219,7 +1233,7 @@
 preferredExtent
     "return a good extent, one that makes subviews fit"
 
-    |sumOfWidths maxHeight maxWidth|
+    |sumOfWidths maxHeight maxWidth m2|
 
     subViews isNil ifTrue:[^ horizontalSpace @ verticalSpace].
 
@@ -1274,13 +1288,14 @@
         ]        
     ].
 
-    ^ sumOfWidths @ maxHeight
+    m2 := margin * 2.
+    ^ (sumOfWidths + m2) @ (maxHeight + m2)
 
-    "Modified: 9.2.1996 / 18:55:32 / cg"
+    "Modified: 22.2.1996 / 20:46:28 / cg"
 ! !
 
 !HorizontalPanelView class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.20 1996-02-09 17:56:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/HorizontalPanelView.st,v 1.21 1996-02-22 20:26:38 cg Exp $'
 ! !