--- a/EditField.st Thu Nov 23 00:08:01 1995 +0100
+++ b/EditField.st Thu Nov 23 01:48:21 1995 +0100
@@ -10,15 +10,14 @@
hereby transferred.
"
-'From Smalltalk/X, Version:2.10.5 on 9-may-1995 at 12:09:38 pm'!
-
EditTextView subclass:#EditField
instanceVariableNames:'leaveAction enabled enableAction crAction tabAction converter
- leaveKeys immediateAccept acceptOnLeave acceptOnReturn
- lengthLimit entryCompletionBlock passwordCharacter cursorMovementWhenUpdating'
+ leaveKeys immediateAccept acceptOnLeave acceptOnReturn
+ lengthLimit entryCompletionBlock passwordCharacter
+ cursorMovementWhenUpdating'
classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
- DefaultSelectionForegroundColor DefaultSelectionBackgroundColor
- DefaultFont'
+ DefaultSelectionForegroundColor DefaultSelectionBackgroundColor
+ DefaultFont'
poolDictionaries:''
category:'Views-Text'
!
@@ -39,10 +38,6 @@
"
!
-version
- ^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.31 1995-11-20 16:11:27 cg Exp $'
-!
-
documentation
"
an editable text-field. Realized by using an EditTextView,
@@ -474,6 +469,10 @@
top openModeless.
"
+!
+
+version
+ ^ '$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.32 1995-11-23 00:48:21 cg Exp $'
! !
!EditField class methodsFor:'defaults'!
@@ -488,6 +487,12 @@
^ #(Return CursorUp CursorDown Next Previous Accept)
!
+defaultNumberOfLines
+ "the number of lines in the field"
+
+ ^ 1
+!
+
updateStyleCache
DefaultForegroundColor := StyleSheet colorAt:'editFieldForegroundColor' default:Black.
DefaultBackgroundColor := StyleSheet colorAt:'editFieldBackgroundColor' default:White.
@@ -498,125 +503,101 @@
"
self updateStyleCache
"
-!
-
-defaultNumberOfLines
- "the number of lines in the field"
-
- ^ 1
! !
-!EditField methodsFor:'private'!
+!EditField methodsFor:'accessing-behavior'!
-textChanged
- "this is sent by mySelf (somewhere in a superclass) whenever
- my contents has changed.
- A good place to add immediateAccept functionality and check for the
- lengthLimit."
-
- |string c|
+acceptOnLeave:aBoolean
+ "set/clear the acceptOnLeave flag. The default is false."
- super textChanged.
- string := self contents.
- lengthLimit notNil ifTrue:[
- string size > lengthLimit ifTrue:[
- c := cursorCol.
- self contents:(string copyTo:lengthLimit).
- self flash.
- self cursorCol:c.
- ]
- ].
- immediateAccept ifTrue:[
- self accept
- ]
+ acceptOnLeave := aBoolean
+!
+
+acceptOnReturn:aBoolean
+ "set/clear the acceptOnReturn flag. The default is false."
+
+ acceptOnReturn := aBoolean
!
-getListFromModel
- "redefined to aquire the text via the aspectMsg - not the listMsg,
- and to ignore updates resulting from my own change."
+crAction:aBlock
+ "define an action to be evaluated when the return key is pressed."
+
+ crAction := aBlock
+!
- "
- ignore updates from my own change
- "
- lockUpdates ifTrue:[
- lockUpdates := false.
- ^ self
- ].
+cursorMovementWhenUpdating:aSymbol
+ "define what should be done with the cursor, when I update
+ my contents from the model. Allowed argumetns are:
+ #keep / nil -> stay where it was
+ #endOfLine -> position cursor after the string
+ #beginOfLine -> position cursor to the beginning
+ The default is #endOfLine"
- (model notNil and:[aspectMsg notNil]) ifTrue:[
- self editValue:(model perform:aspectMsg).
+ cursorMovementWhenUpdating := aSymbol
+!
+
+disable
+ "disable the field; hide cursor and ignore input"
+
+ enabled ifTrue:[
+ enabled := false.
+ self hideCursor
]
!
-argForChangeMessage
- "redefined to send use converted value (if I have one)"
+enable
+ "enable the field; show cursor and allow input"
- ^ self editValue
+ enabled ifFalse:[
+"/ enableAction notNil ifTrue:[
+"/ enableAction value
+"/ ].
+ enabled := true.
+ super showCursor
+ ]
!
-startAutoScrollUp:y
- "no vertical scrolling in editfields"
+enableAction:aBlock
+ "define an action to be evaluated when enabled by clicking upon"
+
+ enableAction := aBlock
+!
- ^ self
+entryCompletionBlock:aOneArgBlock
+ "define an action to be evaluated when Tab (NameCompletion) is pressed.
+ The block gets the current contents as argument."
+
+ entryCompletionBlock := aOneArgBlock
!
-visibleAt:visLineNr
- "return the string at lineNr for display.
- If there is a password character, return a string consisting of those only."
-
- |s|
+immediateAccept:aBoolean
+ "set/clear the immediateAccept flag. The default is false."
- s := super visibleAt:visLineNr.
- passwordCharacter notNil ifTrue:[
- ^ String new:(s size) withAll:passwordCharacter
- ].
- ^ s
+ immediateAccept := aBoolean
+!
- "Modified: 6.9.1995 / 12:25:06 / claus"
+leaveAction:aBlock
+ "define an action to be evaluated when field is left by return key"
+
+ leaveAction := aBlock
!
-startAutoScrollDown:y
- "no vertical scrolling in editfields"
-
- ^ self
-! !
-
-!EditField methodsFor:'scrolling'!
+leaveKeys:aCollectionOfKeySymbols
+ "define the set of keys which are interpreted as leaveKeys.
+ I.e. those that make the field inactive and accept (if acceptOnLeave is true).
+ The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return."
-makeColVisible:col inLine:line
- "dont scroll for the cursor, if its behond the text and a lengthLimit
- is present."
+ leaveKeys := aCollectionOfKeySymbols
+!
- lengthLimit notNil ifTrue:[
- (col == cursorCol and:[col > lengthLimit]) ifTrue:[
- ^ super makeColVisible:lengthLimit inLine:line
- ]
- ].
- ^ super makeColVisible:col inLine:line
+tabAction:aBlock
+ "define an action to be evaluated when the tabulator key is pressed."
- "Modified: 6.9.1995 / 13:57:53 / claus"
+ tabAction := aBlock
! !
!EditField methodsFor:'accessing-contents'!
-list:someText
- "low level access to the underlying contents' list.
- Redefined to force text to 1 line, and notify dependents
- of any changed extent-wishes (for automatic box resizing)."
-
- |l oldWidth|
-
- l := someText.
- l size > 1 ifTrue:[
- l := OrderedCollection with:(l at:1)
- ].
- oldWidth := self widthOfContents.
- super list:l.
- self widthOfContents ~~ oldWidth ifTrue:[
- self changed:#preferredExtent
- ]
-!
-
contents
"return contents as a string
- redefined since EditFields hold only one line of text.
@@ -653,6 +634,22 @@
self cursorCol:newCol.
!
+converter
+ "return the converter (if any)."
+
+ ^ converter
+!
+
+converter:aConverter
+ "set the converter. If non-nil,
+ the converter is applied to the text to convert from the string
+ representation to the actual object value and vice versa.
+ The default converter is nil, meaning no-conversion
+ (i.e. the edited object is the string itself."
+
+ converter := aConverter
+!
+
editValue
"if the field edits a string, this is a name alias for #contents.
Otherwise, if there is a converter, return the edited string
@@ -694,6 +691,12 @@
]
!
+initialText:aString
+ "set the initialText and select it"
+
+ self initialText:aString selected:true
+!
+
initialText:aString selected:aBoolean
"set the initialText and select it if aBoolean is true"
@@ -711,48 +714,32 @@
]
!
-initialText:aString
- "set the initialText and select it"
+list:someText
+ "low level access to the underlying contents' list.
+ Redefined to force text to 1 line, and notify dependents
+ of any changed extent-wishes (for automatic box resizing)."
+
+ |l oldWidth|
- self initialText:aString selected:true
+ l := someText.
+ l size > 1 ifTrue:[
+ l := OrderedCollection with:(l at:1)
+ ].
+ oldWidth := self widthOfContents.
+ super list:l.
+ self widthOfContents ~~ oldWidth ifTrue:[
+ self changed:#preferredExtent
+ ]
!
stringValue
"alias for #contents - for compatibility with ST-80's InputField"
^ self contents
-!
-
-converter:aConverter
- "set the converter. If non-nil,
- the converter is applied to the text to convert from the string
- representation to the actual object value and vice versa.
- The default converter is nil, meaning no-conversion
- (i.e. the edited object is the string itself."
-
- converter := aConverter
-!
-
-converter
- "return the converter (if any)."
-
- ^ converter
! !
!EditField methodsFor:'accessing-look'!
-passwordCharacter:aCharacter
- passwordCharacter := aCharacter
-
- "Modified: 6.9.1995 / 12:25:33 / claus"
-!
-
-passwordCharacter
- ^ passwordCharacter
-
- "Modified: 6.9.1995 / 12:25:39 / claus"
-!
-
maxChars
"return the maximum number of characters that are allowed in
the field.
@@ -771,203 +758,18 @@
compatibility."
lengthLimit := aNumberOrNil
-! !
-
-!EditField methodsFor:'accessing-behavior'!
-
-entryCompletionBlock:aOneArgBlock
- "define an action to be evaluated when Tab (NameCompletion) is pressed.
- The block gets the current contents as argument."
-
- entryCompletionBlock := aOneArgBlock
-!
-
-leaveAction:aBlock
- "define an action to be evaluated when field is left by return key"
-
- leaveAction := aBlock
-!
-
-enable
- "enable the field; show cursor and allow input"
-
- enabled ifFalse:[
-"/ enableAction notNil ifTrue:[
-"/ enableAction value
-"/ ].
- enabled := true.
- super showCursor
- ]
-!
-
-immediateAccept:aBoolean
- "set/clear the immediateAccept flag. The default is false."
-
- immediateAccept := aBoolean
-!
-
-leaveKeys:aCollectionOfKeySymbols
- "define the set of keys which are interpreted as leaveKeys.
- I.e. those that make the field inactive and accept (if acceptOnLeave is true).
- The default is a set of #CursorUp, #CursorDown, #Next, #Prior and #Return."
-
- leaveKeys := aCollectionOfKeySymbols
-!
-
-crAction:aBlock
- "define an action to be evaluated when the return key is pressed."
-
- crAction := aBlock
-!
-
-tabAction:aBlock
- "define an action to be evaluated when the tabulator key is pressed."
-
- tabAction := aBlock
-!
-
-acceptOnReturn:aBoolean
- "set/clear the acceptOnReturn flag. The default is false."
-
- acceptOnReturn := aBoolean
-!
-
-disable
- "disable the field; hide cursor and ignore input"
-
- enabled ifTrue:[
- enabled := false.
- self hideCursor
- ]
-!
-
-acceptOnLeave:aBoolean
- "set/clear the acceptOnLeave flag. The default is false."
-
- acceptOnLeave := aBoolean
-!
-
-enableAction:aBlock
- "define an action to be evaluated when enabled by clicking upon"
-
- enableAction := aBlock
!
-cursorMovementWhenUpdating:aSymbol
- "define what should be done with the cursor, when I update
- my contents from the model. Allowed argumetns are:
- #keep / nil -> stay where it was
- #endOfLine -> position cursor after the string
- #beginOfLine -> position cursor to the beginning
- The default is #endOfLine"
-
- cursorMovementWhenUpdating := aSymbol
-! !
-
-!EditField methodsFor:'initialization'!
-
-initStyle
- super initStyle.
+passwordCharacter
+ ^ passwordCharacter
- DefaultBackgroundColor notNil ifTrue:[
- bgColor := DefaultBackgroundColor on:device.
- self viewBackground:bgColor.
- ].
- fgColor := DefaultForegroundColor.
- selectionFgColor := DefaultSelectionForegroundColor.
- selectionBgColor := DefaultSelectionBackgroundColor.
-
- DefaultFont notNil ifTrue:[
- font := DefaultFont on:device
- ]
-!
-
-initialize
- super initialize.
- self height:(font height + font descent + (topMargin * 2)).
- enabled := true.
- fixedSize := true.
- nFullLinesShown := 1.
- nLinesShown := 1.
- immediateAccept := false.
-"/ acceptOnLeave := false.
-"/ acceptOnReturn := false.
- acceptOnLeave := acceptOnReturn := true.
- cursorShown := true.
- leaveKeys := self class defaultLeaveKeys.
- cursorMovementWhenUpdating := #endOfLine
+ "Modified: 6.9.1995 / 12:25:39 / claus"
!
-editMenu
- |labels selectors m|
-
- labels := #(
- 'copy'
- 'cut'
- 'paste'
-"
- 'replace'
-"
- '-'
- 'accept'
- ).
-
- selectors := #(
- copySelection
- cut
- paste
-"
- replace
-"
- nil
- accept
- ).
-
- m := PopUpMenu
- labels:(resources array:labels)
- selectors:selectors.
-
- self hasSelection ifFalse:[
- m disableAll:#(copySelection cut)
- ].
+passwordCharacter:aCharacter
+ passwordCharacter := aCharacter
- ^ m
-! !
-
-!EditField methodsFor:'realization'!
-
-realize
- "scroll back to beginning when realized"
- leftOffset := 0.
- super realize
-! !
-
-!EditField methodsFor:'queries'!
-
-specClass
- self class == EditField ifTrue:[^ InputFieldSpec].
- ^ nil
-
- "Modified: 5.9.1995 / 17:28:27 / claus"
-!
-
-preferredExtent
- "return the preferred extent of this view.
- That is the width of the string plus some extra,
- but not wider than half of the screen"
-
- |string w f|
-
- string := self contents.
- (string isNil or:[string isBlank]) ifTrue:[
- string := ' ' "/ just any string is ok ^ super preferredExtent
- ].
- f := font on:device.
- w := ((f widthOf:string) * 1.5) rounded.
- w := w min:(device width // 2).
- ^ w @ (f height * 1.5) rounded
-
- "Modified: 6.9.1995 / 19:24:06 / claus"
+ "Modified: 6.9.1995 / 12:25:33 / claus"
! !
!EditField methodsFor:'cursor drawing'!
@@ -1004,22 +806,72 @@
super cursorCol:c
!
-cursorLine:line col:col
- "catch cursor movement"
-
- super cursorLine:1 col:col
-!
-
cursorDown
"catch cursor movement"
(cursorVisibleLine == nLinesShown) ifFalse:[
super cursorDown
]
+!
+
+cursorLine:line col:col
+ "catch cursor movement"
+
+ super cursorLine:1 col:col
+! !
+
+!EditField methodsFor:'editing'!
+
+paste:someText
+ "redefined to force text to 1 line"
+
+ super paste:someText.
+ list size > 1 ifTrue:[
+ self deleteFromLine:2 toLine:(list size)
+ ]
! !
!EditField methodsFor:'event handling'!
+buttonPress:button x:x y:y
+ "enable myself on mouse click"
+
+ enabled ifFalse:[
+ enabled := true.
+ super buttonPress:button x:x y:y.
+ enableAction notNil ifTrue:[
+ enableAction value
+ ]
+ ] ifTrue:[
+ super buttonPress:button x:x y:y
+ ]
+!
+
+canHandle:aKey
+ "return true, if the receiver would like to handle aKey
+ (usually from another view, when the receiver is part of
+ a more complex dialog box).
+ We do return true here, since the editfield will handle
+ all keys.
+ OBSOLETE: dont use this anymore - its a leftover for the tableWidget"
+
+ ^ true
+!
+
+focusIn
+ "got the explicit focus"
+
+ enabled ifFalse:[
+ enabled := true.
+ super focusIn.
+ enableAction notNil ifTrue:[
+ enableAction value
+ ]
+ ] ifTrue:[
+ super focusIn
+ ].
+!
+
keyPress:key x:x y:y
"if keyHandler is defined, pass input; otherwise check for leave
keys"
@@ -1131,54 +983,202 @@
"/ self clear.
"/ self redraw
]
+! !
+
+!EditField methodsFor:'initialization'!
+
+editMenu
+ |labels selectors m|
+
+ labels := #(
+ 'copy'
+ 'cut'
+ 'paste'
+"
+ 'replace'
+"
+ '-'
+ 'accept'
+ ).
+
+ selectors := #(
+ copySelection
+ cut
+ paste
+"
+ replace
+"
+ nil
+ accept
+ ).
+
+ m := PopUpMenu
+ labels:(resources array:labels)
+ selectors:selectors.
+
+ self hasSelection ifFalse:[
+ m disableAll:#(copySelection cut)
+ ].
+
+ ^ m
!
-buttonPress:button x:x y:y
- "enable myself on mouse click"
+initStyle
+ super initStyle.
+
+ DefaultBackgroundColor notNil ifTrue:[
+ bgColor := DefaultBackgroundColor on:device.
+ self viewBackground:bgColor.
+ ].
+ fgColor := DefaultForegroundColor.
+ selectionFgColor := DefaultSelectionForegroundColor.
+ selectionBgColor := DefaultSelectionBackgroundColor.
+
+ DefaultFont notNil ifTrue:[
+ font := DefaultFont on:device
+ ]
+!
- enabled ifFalse:[
- enabled := true.
- super buttonPress:button x:x y:y.
- enableAction notNil ifTrue:[
- enableAction value
- ]
- ] ifTrue:[
- super buttonPress:button x:x y:y
+initialize
+ super initialize.
+ self height:(font height + font descent + (topMargin * 2)).
+ enabled := true.
+ fixedSize := true.
+ nFullLinesShown := 1.
+ nLinesShown := 1.
+ immediateAccept := false.
+"/ acceptOnLeave := false.
+"/ acceptOnReturn := false.
+ acceptOnLeave := acceptOnReturn := true.
+ cursorShown := true.
+ leaveKeys := self class defaultLeaveKeys.
+ cursorMovementWhenUpdating := #endOfLine
+! !
+
+!EditField methodsFor:'private'!
+
+argForChangeMessage
+ "redefined to send use converted value (if I have one)"
+
+ ^ self editValue
+!
+
+getListFromModel
+ "redefined to aquire the text via the aspectMsg - not the listMsg,
+ and to ignore updates resulting from my own change."
+
+ "
+ ignore updates from my own change
+ "
+ lockUpdates ifTrue:[
+ lockUpdates := false.
+ ^ self
+ ].
+
+ (model notNil and:[aspectMsg notNil]) ifTrue:[
+ self editValue:(model perform:aspectMsg).
]
!
-focusIn
- "got the explicit focus"
+startAutoScrollDown:y
+ "no vertical scrolling in editfields"
+
+ ^ self
+!
+
+startAutoScrollUp:y
+ "no vertical scrolling in editfields"
+
+ ^ self
+!
- enabled ifFalse:[
- enabled := true.
- super focusIn.
- enableAction notNil ifTrue:[
- enableAction value
+textChanged
+ "this is sent by mySelf (somewhere in a superclass) whenever
+ my contents has changed.
+ A good place to add immediateAccept functionality and check for the
+ lengthLimit."
+
+ |string c|
+
+ super textChanged.
+ string := self contents.
+ lengthLimit notNil ifTrue:[
+ string size > lengthLimit ifTrue:[
+ c := cursorCol.
+ self contents:(string copyTo:lengthLimit).
+ self flash.
+ self cursorCol:c.
]
- ] ifTrue:[
- super focusIn
].
+ immediateAccept ifTrue:[
+ self accept
+ ]
!
-canHandle:aKey
- "return true, if the receiver would like to handle aKey
- (usually from another view, when the receiver is part of
- a more complex dialog box).
- We do return true here, since the editfield will handle
- all keys.
- OBSOLETE: dont use this anymore - its a leftover for the tableWidget"
+visibleAt:visLineNr
+ "return the string at lineNr for display.
+ If there is a password character, return a string consisting of those only."
+
+ |s|
- ^ true
+ s := super visibleAt:visLineNr.
+ passwordCharacter notNil ifTrue:[
+ ^ String new:(s size) withAll:passwordCharacter
+ ].
+ ^ s
+
+ "Modified: 6.9.1995 / 12:25:06 / claus"
! !
-!EditField methodsFor:'editing'!
+!EditField methodsFor:'queries'!
+
+preferredExtent
+ "return the preferred extent of this view.
+ That is the width of the string plus some extra,
+ but not wider than half of the screen"
+
+ |string w f|
-paste:someText
- "redefined to force text to 1 line"
+ string := self contents.
+ (string isNil or:[string isBlank]) ifTrue:[
+ string := ' ' "/ just any string is ok ^ super preferredExtent
+ ].
+ f := font on:device.
+ w := ((f widthOf:string) * 1.5) rounded.
+ w := w min:(device width // 2).
+ ^ w @ (f height * 1.5) rounded
+
+ "Modified: 6.9.1995 / 19:24:06 / claus"
+!
+
+specClass
+ self class == EditField ifTrue:[^ InputFieldSpec].
+ ^ nil
- super paste:someText.
- list size > 1 ifTrue:[
- self deleteFromLine:2 toLine:(list size)
- ]
+ "Modified: 5.9.1995 / 17:28:27 / claus"
+! !
+
+!EditField methodsFor:'realization'!
+
+realize
+ "scroll back to beginning when realized"
+ leftOffset := 0.
+ super realize
! !
+
+!EditField methodsFor:'scrolling'!
+
+makeColVisible:col inLine:line
+ "dont scroll for the cursor, if its behond the text and a lengthLimit
+ is present."
+
+ lengthLimit notNil ifTrue:[
+ (col == cursorCol and:[col > lengthLimit]) ifTrue:[
+ ^ super makeColVisible:lengthLimit inLine:line
+ ]
+ ].
+ ^ super makeColVisible:col inLine:line
+
+ "Modified: 6.9.1995 / 13:57:53 / claus"
+! !
+