InfoBox.st
changeset 8 82e87dc3540e
parent 7 15a9291b9bd0
child 38 4b9b70b2cc87
--- a/InfoBox.st	Sat Dec 11 02:51:34 1993 +0100
+++ b/InfoBox.st	Mon Dec 13 18:06:07 1993 +0100
@@ -11,7 +11,8 @@
 "
 
 ModalBox subclass:#InfoBox
-       instanceVariableNames:'formLabel textLabel okButton okAction'
+       instanceVariableNames:'formLabel textLabel okButton okAction
+                              acceptReturnAsOK'
        classVariableNames:'InfoBitmap'
        poolDictionaries:''
        category:'Views-Interactors'
@@ -22,12 +23,21 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
               All Rights Reserved
 
-this class implements a pop-up box to show an information message
-
-$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.4 1993-12-11 01:45:27 claus Exp $
+$Header: /cvs/stx/stx/libwidg/InfoBox.st,v 1.5 1993-12-13 17:06:07 claus Exp $
 written Spring/Summer 89 by claus
 '!
 
+!InfoBox class methodsFor:'documentation'!
+
+documentation
+"
+this class implements a pop-up box to show an information message.
+It has a single ok-Button, which closes the box.
+Also entering return has (by default) the same effect as pressing
+the ok-button.
+"
+! !
+
 !InfoBox class methodsFor:'instance creation'!
 
 title:titleString
@@ -45,6 +55,8 @@
         InfoBitmap := Form fromFile:'Information.xbm' resolution:100 on:device
     ].
 
+    acceptReturnAsOK := true.
+
     formLabel := Label in:self.
     self initFormBitmap.
     formLabel borderWidth:0.
@@ -61,12 +73,16 @@
                               ]
                        in:self.
 
-    "okButton isReturnButton:true."
+    okButton isReturnButton:true.
     okButton origin:[(width // 4) @ (height - ViewSpacing - okButton height)]
              extent:[(width // 2) @ okButton height]
 !
 
 initFormBitmap
+    "setup the bitmap shown in the upper left -
+     extracted into a separate method for easier redefinition
+     in subclasses"
+
     formLabel form:InfoBitmap
 ! !
 
@@ -74,7 +90,7 @@
 
 positionOffset
     "return the delta, by which the box should be displayed
-     from the mouse pointer. Value returned here makes
+     from the mouse pointer. Value returned here makes center of
      okButton appear under the cursor"
 
     ^ (okButton originRelativeTo:self) + (okButton extent // 2)
@@ -82,6 +98,14 @@
 
 !InfoBox methodsFor:'accessing'!
 
+acceptReturnAsOK:aBoolean
+    "turn on/off interpretation of return-key as ok.
+     Default is on"
+
+    acceptReturnAsOK := aBoolean.
+    okButton isReturnButton:aBoolean.
+!
+
 form:aForm
     "define a form to be displayed left of the title
      - usually an exclamation-mark"
@@ -92,15 +116,17 @@
 !
 
 title:aString
-    "set the title"
+    "set the boxes title string"
 
-    textLabel label:aString.
-    textLabel resize.
-    self resize
+    aString ~= textLabel label ifTrue:[
+        textLabel label:aString.
+        textLabel resize.
+        self resize
+    ]
 !
 
 title
-    "return the title"
+    "return the boxes title string"
 
     ^ textLabel label
 !
@@ -114,14 +140,18 @@
 okText:aString
     "define the text in the ok-button"
 
-    okButton label:aString.
-    self resize
+    aString ~= okButton label ifTrue:[
+        okButton label:aString.
+        self resize
+    ]
 ! !
 
 !InfoBox methodsFor:'private'!
 
 resize
-    "resize myself to make everything fit into myself"
+    "resize myself to make everything fit into myself.
+     This method should be called after every change in
+     the title, form-field or button(s)."
 
     |w h extra|
 
@@ -132,7 +162,7 @@
          + okButton height
          + ViewSpacing.
 
-    extra := margin * 2.
+    extra := 0 "margin * 2".
     super extent:(w + extra) @ (h + extra)
 ! !
 
@@ -155,5 +185,7 @@
 keyPress:aKey x:x y:y
     "return-key dublicates ok-function"
 
-    (aKey == #Return) ifTrue:[self okPressed]
+    acceptReturnAsOK ifTrue:[
+        (aKey == #Return) ifTrue:[self okPressed]
+    ]
 ! !