EditField.st
changeset 3 9d7eefb5e69f
parent 0 e6a541c1c0eb
child 5 7b4fb1b170e5
equal deleted inserted replaced
2:880bbcc50207 3:9d7eefb5e69f
    24 
    24 
    25 an editable text-field. Realized by using an EditTextView,
    25 an editable text-field. Realized by using an EditTextView,
    26 and forcing its size to 1 line - disabling cursor movement
    26 and forcing its size to 1 line - disabling cursor movement
    27 in the vertical direction.
    27 in the vertical direction.
    28 
    28 
    29 %W% %E%
    29 $Header: /cvs/stx/stx/libwidg/EditField.st,v 1.2 1993-10-13 01:01:54 claus Exp $
    30 written jan-90 by claus
    30 written jan-90 by claus
    31 '!
    31 '!
    32 
    32 
    33 !EditField class methodsFor:'defaults'!
    33 !EditField class methodsFor:'defaults'!
    34 
    34 
    52 initStyle
    52 initStyle
    53     |myBgColor myFont|
    53     |myBgColor myFont|
    54 
    54 
    55     super initStyle.
    55     super initStyle.
    56 
    56 
    57     myBgColor := Resource name:'EDITFIELD_BACKGROUND'
    57     myBgColor := resources name:'BACKGROUND' default:nil.
    58                     default:nil
       
    59                    fromFile:'Smalltalk.rs'.
       
    60 
       
    61     myBgColor notNil ifTrue:[
    58     myBgColor notNil ifTrue:[
    62         bgColor := myBgColor on:device.
    59         bgColor := myBgColor on:device.
    63         self viewBackground:bgColor.
    60         self viewBackground:bgColor.
    64         selectionFgColor := fgColor on:device.
    61         selectionFgColor := fgColor on:device.
    65         selectionBgColor := White on:device
    62         selectionBgColor := White on:device
    66     ].
    63     ].
    67 
    64 
    68     myFont := Resource name:'EDITFIELD_FONT'
    65     myFont := resources name:'FONT' default:nil.
    69                    default:nil
       
    70                   fromFile:'Smalltalk.rs'.
       
    71 
       
    72     myFont notNil ifTrue:[
    66     myFont notNil ifTrue:[
    73         font := myFont
    67         font := myFont
    74     ]
    68     ]
    75 !
    69 !
    76 
    70 
   222 
   216 
   223 keyPress:key x:x y:y
   217 keyPress:key x:x y:y
   224     "if keyHandler is defined, pass input; otherwise check for leave
   218     "if keyHandler is defined, pass input; otherwise check for leave
   225      keys"
   219      keys"
   226 
   220 
   227     |leave x|
   221     |leave xCol|
   228 
   222 
   229     enabled ifFalse:[
   223     enabled ifFalse:[
   230         (keyboardHandler notNil
   224         (keyboardHandler notNil
   231         and:[keyboardHandler canHandle:key]) ifTrue:[
   225         and:[keyboardHandler canHandle:key]) ifTrue:[
   232             (keyboardHandler == self) ifTrue:[
   226             (keyboardHandler == self) ifTrue:[
   253             leaveAction value:key
   247             leaveAction value:key
   254         ].
   248         ].
   255         ^ self
   249         ^ self
   256     ].
   250     ].
   257     super keyPress:key x:x y:y.
   251     super keyPress:key x:x y:y.
   258     x := (self xOfCol:cursorCol inLine:cursorLine) - leftOffset.
   252     xCol := (self xOfCol:cursorCol inLine:cursorLine) - leftOffset.
   259     (x > (width * (5/6))) ifTrue:[
   253     (xCol > (width * (5/6))) ifTrue:[
   260         leftOffset := leftOffset + (width // 2).
   254         leftOffset := leftOffset + (width // 2).
   261         self clear.
   255         self clear.
   262         self redraw
   256         self redraw
   263     ] ifFalse:[
   257     ] ifFalse:[
   264         (x < (width * (1/6))) ifTrue:[
   258         (xCol < (width * (1/6))) ifTrue:[
   265             leftOffset := 0 max: leftOffset - (width // 2).
   259             leftOffset := 0 max: leftOffset - (width // 2).
   266             self clear.
   260             self clear.
   267             self redraw
   261             self redraw
   268         ]
   262         ]
   269     ]
   263     ]