Prechádzať zdrojové kódy

2006-08-08 Peter Dennis Bartok <[email protected]>

	* TextBoxBase.cs: Don't try moving the caret if we don't have a window
	  yes (fixes #78806)
	* TextControl.cs: 
	  - PositionCaret: Allow positioning of caret but don't call methods 
	    requiring a handle if the window isn't created yet
	  - CharIndexToLineTag: Fix ending loop early error. Lines is 1 based
	  - owner_HandleCreated: Don't position the caret, just update it's 
	    location. User might have already set a different position


svn path=/trunk/mcs/; revision=63569
Peter Dennis Bartok 19 rokov pred
rodič
commit
bbeea30d2e

+ 11 - 0
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog

@@ -1,3 +1,14 @@
+2006-08-08  Peter Dennis Bartok  <[email protected]> 
+
+	* TextBoxBase.cs: Don't try moving the caret if we don't have a window
+	  yes (fixes #78806)
+	* TextControl.cs: 
+	  - PositionCaret: Allow positioning of caret but don't call methods 
+	    requiring a handle if the window isn't created yet
+	  - CharIndexToLineTag: Fix ending loop early error. Lines is 1 based
+	  - owner_HandleCreated: Don't position the caret, just update it's 
+	    location. User might have already set a different position
+
 2006-08-08  Peter Dennis Bartok  <[email protected]>
 
 	* XplatUIWin32.cs: Don't use the desktop as basis for foster-parented

+ 5 - 1
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs

@@ -663,7 +663,9 @@ namespace System.Windows.Forms {
 		}
 
 		public void ScrollToCaret() {
-			this.CaretMoved(this, EventArgs.Empty);
+			if (IsHandleCreated) {
+				CaretMoved(this, EventArgs.Empty);
+			}
 		}
 
 		public void Select(int start, int length) {
@@ -692,6 +694,8 @@ namespace System.Windows.Forms {
 		#region Protected Instance Methods
 		protected override void CreateHandle() {
 			base.CreateHandle ();
+			document.AlignCaret();
+			ScrollToCaret();
 		}
 
 		protected override bool IsInputKey(Keys keyData) {

+ 11 - 9
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs

@@ -1384,22 +1384,24 @@ namespace System.Windows.Forms {
 		}
 
 		internal void PositionCaret(Line line, int pos) {
-			if (!owner.IsHandleCreated) {
-				return;
+			if (owner.IsHandleCreated) {
+				undo.RecordCursor();
 			}
 
-			undo.RecordCursor();
-
 			caret.tag = line.FindTag(pos);
 			caret.line = line;
 			caret.pos = pos;
 			caret.height = caret.tag.height;
 
-			if (owner.Focused) {
-				XplatUI.SetCaretPos(owner.Handle, (int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+			if (owner.IsHandleCreated) {
+				if (owner.Focused) {
+					XplatUI.SetCaretPos(owner.Handle, (int)caret.tag.line.widths[caret.pos] + caret.line.align_shift - viewport_x, caret.line.Y + caret.tag.shift - viewport_y + caret_shift);
+				}
+
+				if (CaretMoved != null) CaretMoved(this, EventArgs.Empty);
 			}
 
-			if (CaretMoved != null) CaretMoved(this, EventArgs.Empty);
+
 		}
 
 		internal void PositionCaret(int x, int y) {
@@ -3328,7 +3330,7 @@ if (owner.backcolor_set || (owner.Enabled && !owner.read_only)) {
 
 			chars = 0;
 
-			for (i = 1; i < lines; i++) {
+			for (i = 1; i <= lines; i++) {
 				line = GetLine(i);
 
 				start = chars;
@@ -3803,7 +3805,7 @@ if (owner.backcolor_set || (owner.Enabled && !owner.read_only)) {
 
 		private void owner_HandleCreated(object sender, EventArgs e) {
 			RecalculateDocument(owner.CreateGraphicsInternal());
-			PositionCaret(0, 0);
+			AlignCaret();
 		}
 
 		private void owner_VisibleChanged(object sender, EventArgs e) {