ComboBoxV.st
changeset 130 5cad43b11fb5
parent 127 9d5cc59863e8
child 135 1c113f77460e
equal deleted inserted replaced
129:a680f0b7508f 130:5cad43b11fb5
     1 View subclass:#ComboBoxView
     1 ComboView subclass:#ComboBoxView
     2 	instanceVariableNames:'enterField pullDownButton list'
     2 	instanceVariableNames:''
     3 	classVariableNames:''
     3 	classVariableNames:''
     4 	poolDictionaries:''
     4 	poolDictionaries:''
     5 	category:'Views-Interactors'
     5 	category:'Views-Interactors'
     6 !
     6 !
     7 
     7 
     8 !ComboBoxView class methodsFor:'documentation'!
     8 !ComboBoxView class methodsFor:'documentation'!
     9 
     9 
    10 documentation
    10 documentation
    11 "
    11 "
    12     A comboBoxView combines an inputField with a list of default inputs;
    12     A ComboBoxView combines an inputField with a drop down list of default inputs;
    13     choosing any from the pulled list presets the string in the field.
    13     choosing any from the pulled list presets the string in the field.
    14     In contrast to a popUpList, the string can still be edited -
    14 
       
    15     In contrast to a PopUpList or ComboListView, the string can still be edited -
    15     the list is actually only a set of values for the convenience of the user.
    16     the list is actually only a set of values for the convenience of the user.
    16 
    17 
    17     This is a first attempt in a comboBox implementation.
       
    18     Not yet finished.
    18     Not yet finished.
    19 "
    19 "
    20 !
    20 !
    21 
    21 
    22 examples
    22 examples
    81      Transcript showCr:('1st comboBox''s value: ' , model1 value).
    81      Transcript showCr:('1st comboBox''s value: ' , model1 value).
    82      Transcript showCr:('2nd comboBox''s value: ' , model2 value).
    82      Transcript showCr:('2nd comboBox''s value: ' , model2 value).
    83 "
    83 "
    84 ! !
    84 ! !
    85 
    85 
    86 !ComboBoxView class methodsFor:'defaults'!
       
    87 
       
    88 buttonForm
       
    89     |form|
       
    90 
       
    91     form  := Form fromFile:'ComboDn_win.xbm'.
       
    92     ^ form on:Display
       
    93 ! !
       
    94 
       
    95 !ComboBoxView methodsFor:'accessing-components'!
    86 !ComboBoxView methodsFor:'accessing-components'!
    96 
    87 
    97 editor
    88 editor
    98     "return the inputField component"
    89     "return the inputField component"
    99 
    90 
   100     ^ enterField
    91     ^ field
   101 
    92 
   102     "Created: 9.2.1996 / 20:18:03 / cg"
    93     "Created: 9.2.1996 / 20:18:03 / cg"
   103 !
    94     "Modified: 28.2.1996 / 15:10:50 / cg"
   104 
       
   105 menuButton
       
   106     "return the menuButton component"
       
   107 
       
   108     ^ pullDownButton
       
   109 
       
   110     "Created: 9.2.1996 / 20:18:18 / cg"
       
   111 ! !
       
   112 
       
   113 !ComboBoxView methodsFor:'accessing-contents'!
       
   114 
       
   115 list:aList
       
   116     list := aList.
       
   117     (list notNil and:[list notEmpty]) ifTrue:[
       
   118         pullDownButton controller enable
       
   119     ] ifFalse:[
       
   120         pullDownButton controller disable
       
   121     ].
       
   122 
       
   123     "Created: 9.2.1996 / 00:51:25 / cg"
       
   124     "Modified: 9.2.1996 / 00:51:56 / cg"
       
   125 ! !
    95 ! !
   126 
    96 
   127 !ComboBoxView methodsFor:'accessing-mvc'!
    97 !ComboBoxView methodsFor:'accessing-mvc'!
   128 
    98 
   129 action:aBlock 
    99 action:aBlock 
   130     enterField action:aBlock
   100     field action:aBlock
   131 
   101 
   132     "Created: 9.2.1996 / 01:44:20 / cg"
   102     "Created: 9.2.1996 / 01:44:20 / cg"
       
   103     "Modified: 28.2.1996 / 15:10:55 / cg"
   133 !
   104 !
   134 
   105 
   135 model
   106 model
   136     ^ enterField model
   107     ^ field model
   137 
   108 
   138     "Created: 9.2.1996 / 00:50:18 / cg"
   109     "Created: 9.2.1996 / 00:50:18 / cg"
       
   110     "Modified: 28.2.1996 / 15:10:59 / cg"
   139 !
   111 !
   140 
   112 
   141 model:aModel
   113 model:aModel
   142     enterField model:aModel.
   114     field model:aModel.
   143 
   115 
   144     "Created: 9.2.1996 / 00:50:12 / cg"
   116     "Created: 9.2.1996 / 00:50:12 / cg"
       
   117     "Modified: 28.2.1996 / 15:11:03 / cg"
   145 ! !
   118 ! !
   146 
   119 
   147 !ComboBoxView methodsFor:'initialization'!
   120 !ComboBoxView methodsFor:'initialization'!
   148 
   121 
   149 initialize
   122 initializeField
   150     |ext|
   123     field := EditField in:self.
   151 
   124     field model:('' asValue).
   152     super initialize.
       
   153 
       
   154     enterField := EditField in:self.
       
   155     enterField origin:0.0@0.0 corner:1.0@1.0.
       
   156 
       
   157     enterField model:('' asValue).
       
   158 
       
   159     pullDownButton := Toggle in:self.
       
   160     pullDownButton label:(self class buttonForm).
       
   161     pullDownButton showLamp:false.
       
   162     pullDownButton activeLevel == pullDownButton passiveLevel ifTrue:[
       
   163         pullDownButton activeLevel:0.
       
   164     ].
       
   165     ext := pullDownButton preferredExtent.
       
   166     pullDownButton origin:1.0@0.0 corner:1.0@1.0.
       
   167     pullDownButton leftInset:(ext x "+ (ViewSpacing//2)") negated.
       
   168 "/    pullDownButton rightInset:(ViewSpacing//2).
       
   169 
       
   170     enterField rightInset:(ext x + (ViewSpacing//2)).
       
   171 
       
   172     pullDownButton disable.
       
   173     pullDownButton pressAction:[self pullMenu].
       
   174 
       
   175     self height:enterField preferredExtent y + ViewSpacing.
       
   176 
   125 
   177     "
   126     "
   178      all of my input goes to the enterfield
   127      all of my input goes to the enterfield
   179     "
   128     "
   180     self delegate:(KeyboardForwarder toView:enterField).
   129     self delegate:(KeyboardForwarder toView:field).
   181 
   130 
   182     "
   131     "
   183      |b|
   132      |b|
   184 
   133 
   185      b := ComboBoxView new.
   134      b := ComboBoxView new.
   186      b list:#('hello' 'world' 'this' 'is' 'st/x').
   135      b list:#('hello' 'world' 'this' 'is' 'st/x').
   187      b open
   136      b open
   188     "
   137     "
   189 
   138 
   190     "Created: 9.2.1996 / 00:05:24 / cg"
       
   191     "Modified: 9.2.1996 / 20:06:08 / cg"
   139     "Modified: 9.2.1996 / 20:06:08 / cg"
   192 ! !
   140     "Created: 28.2.1996 / 15:07:51 / cg"
   193 
       
   194 !ComboBoxView methodsFor:'message delegation'!
       
   195 
       
   196 doesNotUnderstand:aMessage
       
   197     (enterField respondsTo:aMessage selector) ifTrue:[
       
   198         ^ aMessage sendTo:enterField
       
   199     ].
       
   200     ^ super doesNotUnderstand:aMessage
       
   201 
       
   202     "Created: 9.2.1996 / 19:22:51 / cg"
       
   203 ! !
       
   204 
       
   205 !ComboBoxView methodsFor:'queries'!
       
   206 
       
   207 preferredExtent
       
   208     |pref1 pref2 m mPrefX|
       
   209 
       
   210     list isNil ifTrue:[
       
   211         mPrefX := 0
       
   212     ] ifFalse:[
       
   213         m := MenuView labels:list.
       
   214         mPrefX := m preferredExtent x.
       
   215     ].
       
   216 
       
   217     pref1 := enterField preferredExtent.
       
   218     pref2 := pullDownButton preferredExtent.
       
   219     ^ ((pref1 x + pref2 x) max:mPrefX) @ (pref1 y max:pref2 y)
       
   220 
       
   221     "Created: 9.2.1996 / 01:08:47 / cg"
       
   222     "Modified: 9.2.1996 / 19:29:58 / cg"
       
   223 ! !
   141 ! !
   224 
   142 
   225 !ComboBoxView methodsFor:'user interaction'!
   143 !ComboBoxView methodsFor:'user interaction'!
   226 
   144 
   227 entryChanged:what
   145 entryChanged:what
   228     enterField contents:what.
   146     field contents:what.
   229     enterField accept.
   147     field accept.
   230     pullDownButton turnOff.
   148     pullDownButton turnOff.
   231 
   149 
   232     "Created: 9.2.1996 / 01:06:01 / cg"
   150     "Created: 9.2.1996 / 01:06:01 / cg"
   233     "Modified: 9.2.1996 / 01:42:38 / cg"
   151     "Modified: 28.2.1996 / 15:08:14 / cg"
   234 !
       
   235 
       
   236 pullMenu
       
   237     |m org|
       
   238 
       
   239     (list notNil and:[list notEmpty]) ifTrue:[
       
   240         m := PopUpMenu
       
   241                     labels:list
       
   242                     selectors:#entryChanged:
       
   243                     args:list
       
   244                     receiver:self.
       
   245 
       
   246         m menuView resize.
       
   247         m menuView width:(self width).
       
   248         m menuView sizeFixed:true.
       
   249         m hideOnRelease:false.
       
   250 
       
   251         org := device translatePoint:(0 @ self height) 
       
   252                                 from:(self id)
       
   253                                   to:(device rootView id).
       
   254 
       
   255         m showAt:org.
       
   256     ].
       
   257 
       
   258     pullDownButton turnOff.
       
   259 
       
   260     "Created: 9.2.1996 / 00:36:49 / cg"
       
   261     "Modified: 9.2.1996 / 19:23:19 / cg"
       
   262 ! !
   152 ! !
   263 
   153 
   264 !ComboBoxView class methodsFor:'documentation'!
   154 !ComboBoxView class methodsFor:'documentation'!
   265 
   155 
   266 version
   156 version
   267     ^ '$Header: /cvs/stx/stx/libwidg2/Attic/ComboBoxV.st,v 1.4 1996-02-09 21:50:11 cg Exp $'
   157     ^ '$Header: /cvs/stx/stx/libwidg2/Attic/ComboBoxV.st,v 1.5 1996-02-28 14:25:23 cg Exp $'
   268 ! !
   158 ! !