diff -r 7e3c25063173 -r 00927189c882 OptionBox.st --- a/OptionBox.st Thu Nov 23 02:43:52 1995 +0100 +++ b/OptionBox.st Thu Nov 23 03:26:58 1995 +0100 @@ -12,7 +12,7 @@ ModalBox subclass:#OptionBox instanceVariableNames:'formLabel textLabel buttonPanel buttons actions - defaultButtonIndex' + defaultButtonIndex' classVariableNames:'WarnBitmap' poolDictionaries:'' category:'Views-DialogBoxes' @@ -34,10 +34,6 @@ " ! -version - ^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.22 1995-11-22 12:46:57 cg Exp $' -! - documentation " OptionBoxes are like YesNoBoxes but with as many buttons as you like; @@ -89,6 +85,24 @@ CAVEAT: this is a leftover - functionality will be merged into DialogBox " +! + +version + ^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.23 1995-11-23 02:26:38 cg Exp $' +! ! + +!OptionBox class methodsFor:'instance creation'! + +title:titleString numberOfOptions:nOptions + "create a new optionBox with title, aTitleString and nOptions options" + + |box| + + box := (self basicNew) numberOfOptions:nOptions. + box device:Screen current. + box initialize. + box title:titleString. + ^ box ! ! !OptionBox class methodsFor:'easy startup '! @@ -124,21 +138,88 @@ " ! ! -!OptionBox class methodsFor:'instance creation'! +!OptionBox methodsFor:'accessing'! + +action:actionBlock + "define a single the action for all buttons. + The action will be evaluated with the button index as argument." + + buttons keysAndValuesDo:[:index :button | + button action:[ + button turnOffWithoutRedraw. + self hide. + actionBlock value:index + ] + ]. +! + +actions:actionBlocks + "define the actions" -title:titleString numberOfOptions:nOptions - "create a new optionBox with title, aTitleString and nOptions options" + actions := actionBlocks +! + +buttonTitles:titles + "set the button titles" + + titles keysAndValuesDo:[:index :aString | + |b| - |box| + (b := buttons at:index) label:aString. + b resize. + ]. + shown ifTrue:[self resize] +! + +buttonTitles:titles actions:actionBlocks + "define both button titles and actions" + + self buttonTitles:titles. + actions := actionBlocks. +! - box := (self basicNew) numberOfOptions:nOptions. - box device:Screen current. - box initialize. - box title:titleString. - ^ box -! ! +buttons + "return the buttons collection" + + ^ buttons +! + +defaultButtonIndex:index + defaultButtonIndex notNil ifTrue:[ + (buttons at:defaultButtonIndex) isReturnButton:false + ]. + (index notNil and:[index ~~ 0]) ifTrue:[ + defaultButtonIndex := index. + defaultButtonIndex notNil ifTrue:[ + (buttons at:defaultButtonIndex) isReturnButton:true + ]. + ] +! + +form:aFormOrImage + "set the image shown in the label-view" -!OptionBox methodsFor:'accessing'! + formLabel form:aFormOrImage +! + +formLabel + "return the label-view which displays a bitmap" + + ^ formLabel +! + +numberOfOptions + "return the number of options" + + ^ buttons size +! + +numberOfOptions:nOptions + "set the number of options" + + buttons := (OrderedCollection new:nOptions) grow:nOptions. + actions := (OrderedCollection new:nOptions) grow:nOptions +! title:aString "set the boxes title" @@ -156,91 +237,40 @@ self title:aString. buttons grow:nOptions. actions grow:nOptions -! +! ! -formLabel - "return the label-view which displays a bitmap" +!OptionBox methodsFor:'events'! - ^ formLabel -! +keyPress:aKey x:x y:y + "return-key dublicates ok-function if acceptReturnAsOK is true" -form:aFormOrImage - "set the image shown in the label-view" - - formLabel form:aFormOrImage -! + |action| -numberOfOptions:nOptions - "set the number of options" - - buttons := (OrderedCollection new:nOptions) grow:nOptions. - actions := (OrderedCollection new:nOptions) grow:nOptions -! + defaultButtonIndex notNil ifTrue:[ + (aKey == #Return) ifTrue:[ + self hide. + action := actions at:defaultButtonIndex. + action notNil ifTrue:[ + action value + ] + ] + ]. + super keyPress:aKey x:x y:y +! ! -numberOfOptions - "return the number of options" +!OptionBox methodsFor:'initializing'! - ^ buttons size -! - -buttons - "return the buttons collection" - +focusSequence ^ buttons ! -buttonTitles:titles - "set the button titles" - - titles keysAndValuesDo:[:index :aString | - |b| - - (b := buttons at:index) label:aString. - b resize. +initFormBitmap + WarnBitmap isNil ifTrue:[ + WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display ]. - shown ifTrue:[self resize] -! - -actions:actionBlocks - "define the actions" - - actions := actionBlocks + formLabel form:WarnBitmap ! -action:actionBlock - "define a single the action for all buttons. - The action will be evaluated with the button index as argument." - - buttons keysAndValuesDo:[:index :button | - button action:[ - button turnOffWithoutRedraw. - self hide. - actionBlock value:index - ] - ]. -! - -buttonTitles:titles actions:actionBlocks - "define both button titles and actions" - - self buttonTitles:titles. - actions := actionBlocks. -! - -defaultButtonIndex:index - defaultButtonIndex notNil ifTrue:[ - (buttons at:defaultButtonIndex) isReturnButton:false - ]. - (index notNil and:[index ~~ 0]) ifTrue:[ - defaultButtonIndex := index. - defaultButtonIndex notNil ifTrue:[ - (buttons at:defaultButtonIndex) isReturnButton:true - ]. - ] -! ! - -!OptionBox methodsFor:'initializing'! - initialize |nButt| @@ -292,36 +322,6 @@ box := OptionBox title:'hello' numberOfOptions:4. box open " -! - -initFormBitmap - WarnBitmap isNil ifTrue:[ - WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display - ]. - formLabel form:WarnBitmap -! - -focusSequence - ^ buttons -! ! - -!OptionBox methodsFor:'events'! - -keyPress:aKey x:x y:y - "return-key dublicates ok-function if acceptReturnAsOK is true" - - |action| - - defaultButtonIndex notNil ifTrue:[ - (aKey == #Return) ifTrue:[ - self hide. - action := actions at:defaultButtonIndex. - action notNil ifTrue:[ - action value - ] - ] - ]. - super keyPress:aKey x:x y:y ! ! !OptionBox methodsFor:'queries'! @@ -365,3 +365,4 @@ ^ w @ h ! ! +