allow specification of the resizing behavior (better list-choosers)
authorClaus Gittinger <cg@exept.de>
Sat, 27 Jan 1996 18:30:14 +0100
changeset 310 4bbc8deffc8c
parent 309 b5c9d68e95e1
child 311 cddf10b2207e
allow specification of the resizing behavior (better list-choosers)
DialogBox.st
--- a/DialogBox.st	Sat Jan 27 16:37:22 1996 +0100
+++ b/DialogBox.st	Sat Jan 27 18:30:14 1996 +0100
@@ -14,7 +14,7 @@
 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
 		addedComponents inputFieldGroup acceptOnLeave acceptValue
-		tabableElements hideOnAccept acceptCheck'
+		tabableElements hideOnAccept acceptCheck needResize'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Views-DialogBoxes'
@@ -1336,8 +1336,7 @@
         listView := ScrollableView for:SelectionInListView.
         listView list:list.
         listView doubleClickAction:[:line | box hide. ^ listValues at:line].
-"/        list height:(list font height * maxLines).
-        box addComponent:listView.
+        box addComponent:listView withHeight:(listView heightForLines:maxLines).
     ].
 
     buttonLabels notNil ifTrue:[
@@ -1354,6 +1353,10 @@
     ].
     box addAbortButton.
     list notNil ifTrue:[box addOkButton].
+
+    listView notNil ifTrue:[box stickAtBottomWithVariableHeight:listView].
+    panel notNil ifTrue:[box stickAtBottomWithFixHeight:panel].
+
     box showAtPointer.
     box accepted ifTrue:[
         (answer := listView selection) notNil ifTrue:[
@@ -1372,7 +1375,7 @@
                 values:#(1 2 3 4) 
                 buttons:#('five' 'six' 'seven')
                 values:#(5 6 7)
-                lines:4
+                lines:10 
                 cancel:nil
          )
 
@@ -1435,7 +1438,7 @@
 
     "
 
-    "Modified: 27.1.1996 / 14:17:27 / cg"
+    "Modified: 27.1.1996 / 17:20:16 / cg"
 !
 
 choose:aString fromList:list values:listValues lines:maxLines cancel:cancelBlock
@@ -1741,12 +1744,15 @@
 
     buttonPanel addSubView:aButton after:someOtherButtonOrNil.
     buttonPanel subViews size > 1 ifTrue:[
-	buttonPanel horizontalLayout:#fitSpace.
+        buttonPanel horizontalLayout:#fitSpace.
     ].
     (h := (aButton heightIncludingBorder + (ViewSpacing * 2))) > buttonPanel topInset ifTrue:[
-	 buttonPanel topInset:h negated
+         buttonPanel topInset:h negated
     ].
+    needResize := true.
     ^ aButton
+
+    "Modified: 27.1.1996 / 18:20:18 / cg"
 !
 
 addCheckBox:label on:aModel
@@ -1874,11 +1880,14 @@
     fullSize := ext + (leftIndent + rightIndent @ 0).
     aComponent extent:fullSize.
     aComponent origin:0.0@yPosition; 
-	       leftInset:leftIndent; 
-	       rightInset:rightIndent.
+               leftInset:leftIndent; 
+               rightInset:rightIndent.
     yPosition := yPosition + aComponent height + ViewSpacing.
     width := fullSize x max:width.
+    needResize := true.
     ^ aComponent
+
+    "Modified: 27.1.1996 / 18:20:36 / cg"
 !
 
 addComponent:aComponent withHeight:height 
@@ -1888,11 +1897,14 @@
     self basicAddComponent:aComponent.
     aComponent height:height.
     aComponent origin:0.0@yPosition; 
-	       width:1.0; 
-	       leftInset:leftIndent;
-	       rightInset:rightIndent.
+               width:1.0; 
+               leftInset:leftIndent;
+               rightInset:rightIndent.
     yPosition := yPosition + "aComponent" height + ViewSpacing.
+    needResize := true.
     ^ aComponent
+
+    "Modified: 27.1.1996 / 18:20:39 / cg"
 !
 
 addFilenameInputFieldOn:aModel in:aDirectory tabable:tabable
@@ -2193,6 +2205,9 @@
     "add some pixels of space to the next component"
 
     yPosition := yPosition + nPixel.
+    needResize := true.
+
+    "Modified: 27.1.1996 / 18:21:27 / cg"
 !
 
 leftIndent:aNumber 
@@ -2200,6 +2215,9 @@
      will be located)."
 
     leftIndent := aNumber.
+    needResize := true.
+
+    "Modified: 27.1.1996 / 18:21:31 / cg"
 !
 
 makeTabable:aComponentOrSubcomponent
@@ -2228,6 +2246,9 @@
     "set the right indent"
 
     rightIndent := aNumber.
+    needResize := true.
+
+    "Modified: 27.1.1996 / 18:21:36 / cg"
 !
 
 yPosition 
@@ -2242,6 +2263,9 @@
      will be located)."
 
     yPosition := aNumber.
+    needResize := true.
+
+    "Modified: 27.1.1996 / 18:21:40 / cg"
 ! !
 
 !DialogBox methodsFor:'initialization'!
@@ -2284,14 +2308,15 @@
 
     buttonPanel := HorizontalPanelView in:self.
     buttonPanel 
-	origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
-	bottomInset:mm; 
-	topInset:(font height + mm * 2) negated;
-	borderWidth:0;
-	horizontalLayout:#spread.
+        origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
+        bottomInset:mm; 
+        topInset:(font height + mm * 2) negated;
+        borderWidth:0;
+        horizontalLayout:#spread.
 
     yPosition := ViewSpacing.
     leftIndent := rightIndent := ViewSpacing.
+    needResize := true.
 
     "
      |b|
@@ -2321,6 +2346,8 @@
        addOkButton; 
        showAtPointer
     "
+
+    "Modified: 27.1.1996 / 17:21:22 / cg"
 !
 
 reAdjustGeometry
@@ -2364,6 +2391,16 @@
 	inputFieldGroup activateFirst
     ].
     super realize
+!
+
+resize
+    needResize ifTrue:[
+        needResize := false.
+        super resize
+    ]
+
+    "Created: 27.1.1996 / 17:22:33 / cg"
+    "Modified: 27.1.1996 / 18:25:40 / cg"
 ! !
 
 !DialogBox methodsFor:'queries'!
@@ -2395,26 +2432,25 @@
     |w h p|
 
     addedComponents notNil ifTrue:[
-	w := addedComponents 
-		inject:0 
-		into:[:max :element |
-			|eExt|
-
-			eExt := (element preferredExtent x) + (element borderWidth * 2). "/ max:element extent x.
-			max max:(eExt + element leftInset + element rightInset)].
+        w := addedComponents 
+                inject:0 
+                into:[:max :element |
+                        |eExt|
+
+                        eExt := (element preferredExtent x) + (element borderWidth * 2). "/ max:element extent x.
+                        max max:(eExt + element leftInset + element rightInset)].
     ] ifFalse:[
-	w := super preferredExtent x.
+        w := super preferredExtent x.
     ].
     w := w max:width.
-    h := yPosition
-	 + ViewSpacing.
+    h := yPosition + ViewSpacing.
 
     buttonPanel subViews size ~~ 0 ifTrue:[
-	p := buttonPanel preferredExtent.
-	w := w max:p x.
-	h := h
-	     + p y
-	     + ViewSpacing.
+        p := buttonPanel preferredExtent.
+        w := w max:p x.
+        h := h
+             + p y
+             + ViewSpacing.
     ].
 
 "/    okButton isNil ifTrue:[
@@ -2427,6 +2463,89 @@
 "/         + ViewSpacing.
 "/
     ^ w @ h
+
+    "Modified: 27.1.1996 / 18:19:50 / cg"
+! !
+
+!DialogBox methodsFor:'special geometry settings'!
+
+stickAtBottomWithFixHeight:aComponent
+    "arrange for a component to be positioned at a constant offset
+     from the bottom of the box and its height to remain the same.
+     This will keep the component at a constant distance from the bottom
+     (without this setup, it would stay at a constant offset from the top)"
+
+    self resize.
+
+    aComponent
+        topInset:(self height - aComponent top) negated;
+        bottomInset:(self height - aComponent bottom); 
+        origin:0.0 @ 1.0; corner:1.0 @ 1.0.
+
+    "
+     compare the resizing behavior of:
+
+        |box|
+
+        box := Dialog new.
+        box addTextLabel:'hello'.
+        box addTextLabel:'hello2'.
+        box addOkButton.
+        box show
+
+     with:
+
+        |box l2|
+
+        box := Dialog new.
+        box addTextLabel:'hello'.
+        l2 := box addTextLabel:'hello2'.
+        box addOkButton.
+        box stickAtBottomWithFixHeight:l2.
+        box show
+   "
+
+    "Created: 27.1.1996 / 17:17:41 / cg"
+    "Modified: 27.1.1996 / 18:29:03 / cg"
+!
+
+stickAtBottomWithVariableHeight:aComponent
+    "arrange for a component to be positioned at a constant offset
+     from the bottom of the box and its height to be adjusted.
+     This will resize the component for a constant distance from the top,
+     and the bottom.
+     (without this setup, its height would remain constant)"
+
+    self resize.
+
+    aComponent
+        bottomInset:(self height - aComponent bottom); 
+        corner:1.0@1.0.
+
+    "
+     compare the resizing behavior of:
+
+        |box|
+
+        box := Dialog new.
+        box addTextLabel:'hello'.
+        (box addComponent:(SelectionInListView new)) level:-1.
+        box addOkButton.
+        box show
+
+     with:
+
+        |box list|
+
+        box := Dialog new.
+        box addTextLabel:'hello'.
+        list := (box addComponent:(SelectionInListView new)) level:-1.
+        box addOkButton.
+        box stickAtBottomWithVariableHeight:list.
+        box show
+   "
+
+    "Modified: 27.1.1996 / 18:27:36 / cg"
 ! !
 
 !DialogBox methodsFor:'user actions'!
@@ -2509,5 +2628,5 @@
 !DialogBox class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.36 1996-01-27 14:16:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.37 1996-01-27 17:30:14 cg Exp $'
 ! !