EditField.st
changeset 155 d6f3836d2b51
parent 144 a86f474be012
child 163 18d87bf16389
--- a/EditField.st	Thu Aug 31 07:01:01 1995 +0200
+++ b/EditField.st	Thu Sep 07 14:46:28 1995 +0200
@@ -15,7 +15,7 @@
 EditTextView subclass:#EditField
 	 instanceVariableNames:'leaveAction enabled enableAction crAction tabAction converter
 		leaveKeys immediateAccept acceptOnLeave acceptOnReturn
-		lengthLimit entryCompletionBlock'
+		lengthLimit entryCompletionBlock passwordCharacter'
 	 classVariableNames:'DefaultForegroundColor DefaultBackgroundColor
 		DefaultSelectionForegroundColor DefaultSelectionBackgroundColor
 		DefaultFont'
@@ -27,7 +27,7 @@
 COPYRIGHT (c) 1990 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.27 1995-08-23 18:05:07 claus Exp $
+$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.28 1995-09-07 12:44:43 claus Exp $
 '!
 
 !EditField class methodsFor:'documentation'!
@@ -48,7 +48,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.27 1995-08-23 18:05:07 claus Exp $
+$Header: /cvs/stx/stx/libwidg/EditField.st,v 1.28 1995-09-07 12:44:43 claus Exp $
 "
 !
 
@@ -523,14 +523,16 @@
      A good place to add immediateAccept functionality and check for the
      lengthLimit."
 
-    |string|
+    |string c|
 
     super textChanged.
     string := self contents.
     lengthLimit notNil ifTrue:[
 	string size > lengthLimit ifTrue:[
-	    self contents:(string := string copyTo:lengthLimit).
+	    c := cursorCol.
+	    self contents:(string copyTo:lengthLimit).
 	    self flash.
+	    self cursorCol:c.
 	]
     ].
     immediateAccept ifTrue:[
@@ -567,12 +569,44 @@
     ^ self
 !
 
+visibleAt:visLineNr
+    "return the string at lineNr for display.
+     If there is a password character, return a string consisting of those only."
+
+    |s|
+
+    s := super visibleAt:visLineNr.
+    passwordCharacter notNil ifTrue:[
+	^ String new:(s size) withAll:passwordCharacter
+    ].
+    ^ s
+
+    "Modified: 6.9.1995 / 12:25:06 / claus"
+!
+
 startAutoScrollDown:y
     "no vertical scrolling in editfields"
 
     ^ self
 ! !
 
+!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"
+!
+
+
 !EditField methodsFor:'accessing'!
 
 contents
@@ -772,6 +806,28 @@
     ^ converter
 !
 
+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. 
+     A limit of nil means: unlimited. This is the default."
+
+    ^ lengthLimit
+
+    "Modified: 6.9.1995 / 13:43:33 / claus"
+!
+
 maxChars:aNumberOrNil
     "set the maximum number of characters that are allowed in
      the field. Additional input will be ignored by the field.
@@ -867,24 +923,42 @@
 
 !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|
+    |string w f|
 
     string := self contents.
     (string isNil or:[string isBlank]) ifTrue:[
 	string := '          ' "/ just any string is ok ^ super preferredExtent
     ].
-    w := (((font on:device) widthOf:string) * 1.5) rounded.
+    f := font on:device.
+    w := ((f widthOf:string) * 1.5) rounded.
     w := w min:(device width // 2).
-    ^ w @ self height
+    ^ w @ (f height * 1.5) rounded
+
+    "Modified: 6.9.1995 / 19:24:06 / claus"
 ! !
 
 !EditField methodsFor:'cursor drawing'!
 
+drawFromVisibleLine:startVisLineNr to:endVisLineNr with:fg and:bg
+    startVisLineNr to:endVisLineNr do:[:visLine |
+	self drawVisibleLine:visLine with:fg and:bg
+    ]
+
+    "Modified: 6.9.1995 / 12:24:29 / claus"
+!
+
 showCursor
     "make cursor visible if currently invisible - but only if this
      EditField is enabled"
@@ -1011,7 +1085,7 @@
     ].
 
     "
-     did someone react ?
+     did someone react (i.e. has my extent changed) ?
      (if not, we scroll horizontally)
     "
     xCol := (self xOfCol:cursorCol inVisibleLine:cursorLine) - leftOffset.
@@ -1025,9 +1099,10 @@
 	]
     ].
     newOffset ~~ leftOffset ifTrue:[
-	leftOffset := newOffset.
-	self clear.
-	self redraw
+	self scrollHorizontalTo:newOffset.
+"/        leftOffset := newOffset.
+"/        self clear.
+"/        self redraw
     ]
 !