OptionBox.st
changeset 197 00927189c882
parent 188 04f5f20990ac
child 243 5c411425097d
equal deleted inserted replaced
196:7e3c25063173 197:00927189c882
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 ModalBox subclass:#OptionBox
    13 ModalBox subclass:#OptionBox
    14 	 instanceVariableNames:'formLabel textLabel buttonPanel buttons actions
    14 	 instanceVariableNames:'formLabel textLabel buttonPanel buttons actions
    15 				defaultButtonIndex'
    15                 defaultButtonIndex'
    16 	 classVariableNames:'WarnBitmap'
    16 	 classVariableNames:'WarnBitmap'
    17 	 poolDictionaries:''
    17 	 poolDictionaries:''
    18 	 category:'Views-DialogBoxes'
    18 	 category:'Views-DialogBoxes'
    19 !
    19 !
    20 
    20 
    30  inclusion of the above copyright notice.   This software may not
    30  inclusion of the above copyright notice.   This software may not
    31  be provided or otherwise made available to, or used by, any
    31  be provided or otherwise made available to, or used by, any
    32  other person.  No title to or ownership of the software is
    32  other person.  No title to or ownership of the software is
    33  hereby transferred.
    33  hereby transferred.
    34 "
    34 "
    35 !
       
    36 
       
    37 version
       
    38     ^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.22 1995-11-22 12:46:57 cg Exp $'
       
    39 !
    35 !
    40 
    36 
    41 documentation
    37 documentation
    42 "
    38 "
    43     OptionBoxes are like YesNoBoxes but with as many buttons as you like;
    39     OptionBoxes are like YesNoBoxes but with as many buttons as you like;
    87 	someObject perform:what.
    83 	someObject perform:what.
    88 	...
    84 	...
    89 
    85 
    90     CAVEAT: this is a leftover - functionality will be merged into DialogBox
    86     CAVEAT: this is a leftover - functionality will be merged into DialogBox
    91 "
    87 "
       
    88 !
       
    89 
       
    90 version
       
    91     ^ '$Header: /cvs/stx/stx/libwidg/OptionBox.st,v 1.23 1995-11-23 02:26:38 cg Exp $'
       
    92 ! !
       
    93 
       
    94 !OptionBox class methodsFor:'instance creation'!
       
    95 
       
    96 title:titleString numberOfOptions:nOptions
       
    97     "create a new optionBox with title, aTitleString and nOptions options"
       
    98 
       
    99     |box|
       
   100 
       
   101     box := (self basicNew) numberOfOptions:nOptions.
       
   102     box device:Screen current.
       
   103     box initialize.
       
   104     box title:titleString.
       
   105     ^ box
    92 ! !
   106 ! !
    93 
   107 
    94 !OptionBox class methodsFor:'easy startup '!
   108 !OptionBox class methodsFor:'easy startup '!
    95 
   109 
    96 request:title label:label form:aForm buttonLabels:labels values:values 
   110 request:title label:label form:aForm buttonLabels:labels values:values 
   122 	       values:#(1 2 3)
   136 	       values:#(1 2 3)
   123 	       default:3
   137 	       default:3
   124     "
   138     "
   125 ! !
   139 ! !
   126 
   140 
   127 !OptionBox class methodsFor:'instance creation'!
       
   128 
       
   129 title:titleString numberOfOptions:nOptions
       
   130     "create a new optionBox with title, aTitleString and nOptions options"
       
   131 
       
   132     |box|
       
   133 
       
   134     box := (self basicNew) numberOfOptions:nOptions.
       
   135     box device:Screen current.
       
   136     box initialize.
       
   137     box title:titleString.
       
   138     ^ box
       
   139 ! !
       
   140 
       
   141 !OptionBox methodsFor:'accessing'!
   141 !OptionBox methodsFor:'accessing'!
   142 
       
   143 title:aString
       
   144     "set the boxes title"
       
   145 
       
   146     aString ~= textLabel label ifTrue:[
       
   147 	textLabel label:aString withoutSeparators.
       
   148 	textLabel forceResize.
       
   149 	shown ifTrue:[self resize]
       
   150     ]
       
   151 !
       
   152 
       
   153 title:aString numberOfOptions:nOptions
       
   154     "set the boxes title and number of options"
       
   155 
       
   156     self title:aString.
       
   157     buttons grow:nOptions.
       
   158     actions grow:nOptions
       
   159 !
       
   160 
       
   161 formLabel
       
   162     "return the label-view which displays a bitmap"
       
   163 
       
   164     ^ formLabel
       
   165 !
       
   166 
       
   167 form:aFormOrImage
       
   168     "set the image shown in the label-view"
       
   169 
       
   170     formLabel form:aFormOrImage
       
   171 !
       
   172 
       
   173 numberOfOptions:nOptions
       
   174     "set the number of options"
       
   175 
       
   176     buttons := (OrderedCollection new:nOptions) grow:nOptions.
       
   177     actions := (OrderedCollection new:nOptions) grow:nOptions
       
   178 !
       
   179 
       
   180 numberOfOptions
       
   181     "return the number of options"
       
   182 
       
   183     ^ buttons size
       
   184 !
       
   185 
       
   186 buttons
       
   187     "return the buttons collection"
       
   188 
       
   189     ^ buttons
       
   190 !
       
   191 
       
   192 buttonTitles:titles
       
   193     "set the button titles"
       
   194 
       
   195     titles keysAndValuesDo:[:index :aString |
       
   196 	|b|
       
   197 
       
   198 	(b := buttons at:index) label:aString.
       
   199 	b resize.
       
   200     ].
       
   201     shown ifTrue:[self resize]
       
   202 !
       
   203 
       
   204 actions:actionBlocks
       
   205     "define the actions"
       
   206 
       
   207     actions := actionBlocks
       
   208 !
       
   209 
   142 
   210 action:actionBlock
   143 action:actionBlock
   211     "define a single the action for all buttons.
   144     "define a single the action for all buttons.
   212      The action will be evaluated with the button index as argument."
   145      The action will be evaluated with the button index as argument."
   213 
   146 
   218 		       actionBlock value:index
   151 		       actionBlock value:index
   219 		      ]
   152 		      ]
   220     ].
   153     ].
   221 !
   154 !
   222 
   155 
       
   156 actions:actionBlocks
       
   157     "define the actions"
       
   158 
       
   159     actions := actionBlocks
       
   160 !
       
   161 
       
   162 buttonTitles:titles
       
   163     "set the button titles"
       
   164 
       
   165     titles keysAndValuesDo:[:index :aString |
       
   166 	|b|
       
   167 
       
   168 	(b := buttons at:index) label:aString.
       
   169 	b resize.
       
   170     ].
       
   171     shown ifTrue:[self resize]
       
   172 !
       
   173 
   223 buttonTitles:titles actions:actionBlocks
   174 buttonTitles:titles actions:actionBlocks
   224     "define both button titles and actions"
   175     "define both button titles and actions"
   225 
   176 
   226     self buttonTitles:titles.
   177     self buttonTitles:titles.
   227     actions := actionBlocks.
   178     actions := actionBlocks.
       
   179 !
       
   180 
       
   181 buttons
       
   182     "return the buttons collection"
       
   183 
       
   184     ^ buttons
   228 !
   185 !
   229 
   186 
   230 defaultButtonIndex:index
   187 defaultButtonIndex:index
   231     defaultButtonIndex notNil ifTrue:[
   188     defaultButtonIndex notNil ifTrue:[
   232 	(buttons at:defaultButtonIndex) isReturnButton:false
   189 	(buttons at:defaultButtonIndex) isReturnButton:false
   235 	defaultButtonIndex := index.
   192 	defaultButtonIndex := index.
   236 	defaultButtonIndex notNil ifTrue:[
   193 	defaultButtonIndex notNil ifTrue:[
   237 	    (buttons at:defaultButtonIndex) isReturnButton:true 
   194 	    (buttons at:defaultButtonIndex) isReturnButton:true 
   238 	].
   195 	].
   239     ]
   196     ]
       
   197 !
       
   198 
       
   199 form:aFormOrImage
       
   200     "set the image shown in the label-view"
       
   201 
       
   202     formLabel form:aFormOrImage
       
   203 !
       
   204 
       
   205 formLabel
       
   206     "return the label-view which displays a bitmap"
       
   207 
       
   208     ^ formLabel
       
   209 !
       
   210 
       
   211 numberOfOptions
       
   212     "return the number of options"
       
   213 
       
   214     ^ buttons size
       
   215 !
       
   216 
       
   217 numberOfOptions:nOptions
       
   218     "set the number of options"
       
   219 
       
   220     buttons := (OrderedCollection new:nOptions) grow:nOptions.
       
   221     actions := (OrderedCollection new:nOptions) grow:nOptions
       
   222 !
       
   223 
       
   224 title:aString
       
   225     "set the boxes title"
       
   226 
       
   227     aString ~= textLabel label ifTrue:[
       
   228 	textLabel label:aString withoutSeparators.
       
   229 	textLabel forceResize.
       
   230 	shown ifTrue:[self resize]
       
   231     ]
       
   232 !
       
   233 
       
   234 title:aString numberOfOptions:nOptions
       
   235     "set the boxes title and number of options"
       
   236 
       
   237     self title:aString.
       
   238     buttons grow:nOptions.
       
   239     actions grow:nOptions
       
   240 ! !
       
   241 
       
   242 !OptionBox methodsFor:'events'!
       
   243 
       
   244 keyPress:aKey x:x y:y
       
   245     "return-key dublicates ok-function if acceptReturnAsOK is true"
       
   246 
       
   247     |action|
       
   248 
       
   249     defaultButtonIndex notNil ifTrue:[
       
   250 	(aKey == #Return) ifTrue:[
       
   251 	    self hide.
       
   252 	    action := actions at:defaultButtonIndex.
       
   253 	    action notNil ifTrue:[
       
   254 		action value
       
   255 	    ]
       
   256 	]
       
   257     ].
       
   258     super keyPress:aKey x:x y:y
   240 ! !
   259 ! !
   241 
   260 
   242 !OptionBox methodsFor:'initializing'!
   261 !OptionBox methodsFor:'initializing'!
       
   262 
       
   263 focusSequence
       
   264     ^ buttons
       
   265 !
       
   266 
       
   267 initFormBitmap
       
   268     WarnBitmap isNil ifTrue:[
       
   269 	WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display 
       
   270     ].
       
   271     formLabel form:WarnBitmap
       
   272 !
   243 
   273 
   244 initialize
   274 initialize
   245     |nButt|
   275     |nButt|
   246 
   276 
   247     super initialize.
   277     super initialize.
   290      |box|
   320      |box|
   291 
   321 
   292      box := OptionBox title:'hello' numberOfOptions:4.
   322      box := OptionBox title:'hello' numberOfOptions:4.
   293      box open
   323      box open
   294     "
   324     "
   295 !
       
   296 
       
   297 initFormBitmap
       
   298     WarnBitmap isNil ifTrue:[
       
   299 	WarnBitmap := Form fromFile:'Warning.xbm' resolution:100 on:Display 
       
   300     ].
       
   301     formLabel form:WarnBitmap
       
   302 !
       
   303 
       
   304 focusSequence
       
   305     ^ buttons
       
   306 ! !
       
   307 
       
   308 !OptionBox methodsFor:'events'!
       
   309 
       
   310 keyPress:aKey x:x y:y
       
   311     "return-key dublicates ok-function if acceptReturnAsOK is true"
       
   312 
       
   313     |action|
       
   314 
       
   315     defaultButtonIndex notNil ifTrue:[
       
   316 	(aKey == #Return) ifTrue:[
       
   317 	    self hide.
       
   318 	    action := actions at:defaultButtonIndex.
       
   319 	    action notNil ifTrue:[
       
   320 		action value
       
   321 	    ]
       
   322 	]
       
   323     ].
       
   324     super keyPress:aKey x:x y:y
       
   325 ! !
   325 ! !
   326 
   326 
   327 !OptionBox methodsFor:'queries'!
   327 !OptionBox methodsFor:'queries'!
   328 
   328 
   329 positionOffset
   329 positionOffset
   363 	 + maxH
   363 	 + maxH
   364 	 + ViewSpacing.
   364 	 + ViewSpacing.
   365 
   365 
   366     ^ w @ h
   366     ^ w @ h
   367 ! !
   367 ! !
       
   368