OptBox.st
changeset 91 e8db16616e97
parent 85 c229bb31d758
child 95 7535cfca9509
--- a/OptBox.st	Sat Feb 18 21:15:07 1995 +0100
+++ b/OptBox.st	Wed Feb 22 02:21:41 1995 +0100
@@ -11,7 +11,7 @@
 "
 
 ModalBox subclass:#OptionBox
-	 instanceVariableNames:'formLabel textLabel buttons actions'
+	 instanceVariableNames:'formLabel textLabel buttonPanel buttons actions'
 	 classVariableNames:'WarnBitmap'
 	 poolDictionaries:''
 	 category:'Views-DialogBoxes'
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1991 by Claus Gittinger
 	     All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/Attic/OptBox.st,v 1.11 1995-02-15 10:37:50 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Attic/OptBox.st,v 1.12 1995-02-22 01:21:14 claus Exp $
 '!
 
 !OptionBox class methodsFor:'documentation'!
@@ -42,16 +42,31 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/Attic/OptBox.st,v 1.11 1995-02-15 10:37:50 claus Exp $
+$Header: /cvs/stx/stx/libwidg/Attic/OptBox.st,v 1.12 1995-02-22 01:21:14 claus Exp $
 "
 !
 
 documentation
 "
     OptionBoxes are like YesNoBoxes but with as many buttons as you like;
-    will finally be a superclass of WarnBox and YesNoBox - or maybe merged
+    this will finally be a superclass of WarnBox and YesNoBox - or maybe merged
     all into DialogBox..
     Used for multiway questions.
+    For a consistent user interface, the rightmost button is the default return
+    button.
+
+    examples:
+
+	|box|
+
+	box := OptionBox title:'hello' numberOfOptions:4.
+	box showAtPointer
+
+
+	|box|
+	box := OptionBox title:'hello' numberOfOptions:3.
+	box buttonTitles:#('one' 'two' 'three').
+	box showAtPointer
 "
 ! !
 
@@ -134,7 +149,9 @@
 	(buttons at:index) resize.
 	index := index + 1
     ].
-    self resize
+    shown ifTrue:[
+	self resize
+    ]
 !
 
 actions:actionBlocks
@@ -148,13 +165,15 @@
 
     self buttonTitles:titles.
     actions := actionBlocks.
-    self resize
+    shown ifTrue:[
+	self resize
+    ]
 ! !
 
 !OptionBox methodsFor:'initializing'!
 
 initialize
-    |nButt buttonPanel|
+    |nButt|
 
     super initialize.
 
@@ -177,20 +196,30 @@
     1 to:nButt do:[:index |
 	|button|
 
-	button := Button label:'press'
-			action:[
-				   |action|
+	button := Button label:'press'.
+	button action:[
+		       |action|
 
-				   (buttons at:index) turnOffWithoutRedraw.
-				   self hide.
-				   action := actions at:index.
-				   action notNil ifTrue:[
-				       action value
-				   ]
-			       ]
-			    in:buttonPanel "self".
+		       (buttons at:index) turnOffWithoutRedraw.
+		       self hide.
+		       action := actions at:index.
+		       action notNil ifTrue:[
+			   action value
+		       ]
+		      ].
+	index == nButt ifTrue:[
+	    button isReturnButton:true
+	].
+	buttonPanel addSubView:button.
 	buttons at:index put:button.
-    ]
+    ].
+
+    "
+     |box|
+
+     box := OptionBox title:'hello' numberOfOptions:4.
+     box open
+    "
 !
 
 initFormBitmap
@@ -217,15 +246,15 @@
 preferedExtent 
     "return a size to make everything fit into myself"
 
-    |w w1 w2 h maxH|
+    |w w1 w2 h maxH prefPanel|
 
     w1 := ViewSpacing + formLabel width + ViewSpacing + textLabel width + ViewSpacing.
-    w2 := buttons inject:ViewSpacing into:[:sum :butt | sum + butt widthIncludingBorder  + ViewSpacing].
-    w := w1 max:w2.
+    prefPanel := buttonPanel preferedExtent.
+    w := w1 max:prefPanel x.
 
     maxH := 0.
     buttons do:[:button |
-	maxH := maxH max:(button heightIncludingBorder)
+	maxH := maxH max:(button preferedExtent y)
     ].
 
     h := ViewSpacing