EnterFieldGroup.st
changeset 0 e6a541c1c0eb
child 3 9d7eefb5e69f
equal deleted inserted replaced
-1:000000000000 0:e6a541c1c0eb
       
     1 "
       
     2  COPYRIGHT (c) 1992-93 by Claus Gittinger
       
     3               All Rights Reserved
       
     4 
       
     5  This software is furnished under a license and may be used
       
     6  only in accordance with the terms of that license and with the
       
     7  inclusion of the above copyright notice.   This software may not
       
     8  be provided or otherwise made available to, or used by, any
       
     9  other person.  No title to or ownership of the software is
       
    10  hereby transferred.
       
    11 "
       
    12 
       
    13 Controller subclass:#EnterFieldGroup
       
    14          instanceVariableNames:'fields currentField leaveAction'
       
    15          classVariableNames:''
       
    16          poolDictionaries:''
       
    17          category:'Views-Support'
       
    18 !
       
    19 
       
    20 EnterFieldGroup comment:'
       
    21 
       
    22 COPYRIGHT (c) 1992-93 by Claus Gittinger
       
    23               All Rights Reserved
       
    24 
       
    25 EnterFieldGroup controlls the interaction between EnterFields
       
    26 enabling next/prev field when a field is left. Instances of
       
    27 this class keep track of which field of the group is the currentField
       
    28 (i.e. the one getting keyboard input).
       
    29 The block accessable as leaveAction is evaluated when the last
       
    30 field of the group is left (by cursor-down or cr). Usually this block
       
    31 triggers some action on the fields.
       
    32 
       
    33 %W% %E%
       
    34 written nov 91 by claus
       
    35 '!
       
    36 
       
    37 !EnterFieldGroup methodsFor:'adding / removing'!
       
    38 
       
    39 add:aField
       
    40     |thisIndex next|
       
    41 
       
    42     fields isNil ifTrue:[
       
    43         fields := OrderedCollection new
       
    44     ].
       
    45     fields add:aField.
       
    46     thisIndex := fields size.
       
    47     aField controller:self.
       
    48     aField disable.
       
    49 
       
    50     "set the fields enableAction to disable active field"
       
    51 
       
    52     aField enableAction:[
       
    53         currentField notNil ifTrue:[
       
    54             currentField disable
       
    55         ].
       
    56         currentField := aField
       
    57     ].
       
    58 
       
    59     "set the fields leaveAction to enable next field"
       
    60 
       
    61     aField leaveAction:[:key |
       
    62         currentField notNil ifTrue:[
       
    63             currentField disable
       
    64         ].
       
    65         (key == #Up) ifTrue:[
       
    66             (thisIndex == 1) ifTrue:[
       
    67                 next := fields size
       
    68             ] ifFalse:[
       
    69                 next := thisIndex - 1
       
    70             ]
       
    71         ].
       
    72         (key == #Down) ifTrue:[
       
    73             (thisIndex == (fields size)) ifTrue:[
       
    74                 next := 1
       
    75             ] ifFalse:[
       
    76                 next := thisIndex + 1
       
    77             ]
       
    78         ].
       
    79         (key == #Return) ifTrue:[
       
    80             (thisIndex == (fields size)) ifTrue:[
       
    81                 leaveAction notNil ifTrue:[
       
    82                     leaveAction value.
       
    83                     currentField := nil
       
    84                 ] ifFalse:[
       
    85                     next := 1
       
    86                 ]
       
    87             ] ifFalse:[
       
    88                 next := thisIndex + 1
       
    89             ]
       
    90         ].
       
    91         next notNil ifTrue:[
       
    92             (fields at:next) enable.
       
    93             currentField := fields at:next
       
    94         ]
       
    95     ]
       
    96 ! !
       
    97 
       
    98 !EnterFieldGroup methodsFor:'accessing'!
       
    99 
       
   100 leaveAction:aBlock
       
   101     leaveAction := aBlock
       
   102 ! !
       
   103 
       
   104 !EnterFieldGroup methodsFor:'controlling'!
       
   105 
       
   106 canHandle:aKey
       
   107     ^ true
       
   108 !
       
   109 
       
   110 keyPress:key x:x y:y in:aView
       
   111     "key-press in a field"
       
   112 
       
   113     currentField notNil ifTrue:[
       
   114         currentField keyPress:key x:0 y:0
       
   115     ]
       
   116 !
       
   117 
       
   118 keyPress:key x:x y:y
       
   119     "key-press in an outer view when keyHandler has been set"
       
   120 
       
   121     currentField notNil ifTrue:[
       
   122         currentField keyPress:key x:0 y:0
       
   123     ]
       
   124 !
       
   125 
       
   126 buttonMotion:state x:x y:y in:aView
       
   127     aView buttonMotion:state x:x y:y
       
   128 !
       
   129 
       
   130 buttonShiftPress:button x:x y:y in:aView
       
   131     aView buttonShiftPress:button x:x y:y
       
   132 !
       
   133 
       
   134 buttonMultiPress:button x:x y:y in:aView
       
   135     aView buttonMultiPress:button x:x y:y
       
   136 !
       
   137 
       
   138 buttonPress:button x:x y:y in:aView
       
   139     aView buttonPress:button x:x y:y
       
   140 !
       
   141 
       
   142 buttonRelease:button x:x y:y in:aView
       
   143     aView buttonRelease:button x:x y:y
       
   144 ! !