Browse Source

* TextBox.cs: Move the has_been_focused into the base control,
* so
some of the text adding methods can manipulate it (probably time
for a better name for this flag too).
- Call a new version of selectall that doesn't scroll
* TextBoxBase.cs: When we append text, if the document is empty,
don't scroll. If the document has text already, we scroll to
the
end of the appended text.
- When the text is changed, we reset the has_been_focused, so
the
next time the control gets focused, all the text is selected.


svn path=/trunk/mcs/; revision=75971

Jackson Harper 18 years ago
parent
commit
112fdecfbf

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

@@ -1,3 +1,15 @@
+2007-04-19  Jackson Harper  <[email protected]>
+
+	* TextBox.cs: Move the has_been_focused into the base control, so
+	some of the text adding methods can manipulate it (probably time
+	for a better name for this flag too).
+	- Call a new version of selectall that doesn't scroll
+	* TextBoxBase.cs: When we append text, if the document is empty,
+	don't scroll.  If the document has text already, we scroll to the
+	end of the appended text.
+	- When the text is changed, we reset the has_been_focused, so the
+	next time the control gets focused, all the text is selected.
+
 2007-04-19  Jackson Harper  <[email protected]>
 
 	* TextControl.cs: Move the margins to the document, add a method

+ 1 - 2
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBox.cs

@@ -49,7 +49,6 @@ namespace System.Windows.Forms {
 		private MenuItem	delete;
 		private MenuItem	select_all;
 
-		private bool has_been_focused;
 #if NET_2_0
 		private bool use_system_password_char = false;
 		private AutoCompleteStringCollection auto_complete_custom_source = null;
@@ -356,7 +355,7 @@ namespace System.Windows.Forms {
 		protected override void OnGotFocus(EventArgs e) {
 			base.OnGotFocus (e);
 			if (selection_length == -1 && !has_been_focused)
-				SelectAll ();
+				SelectAllNoScroll ();
 			has_been_focused = true;
 		}
 

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

@@ -62,6 +62,9 @@ namespace System.Windows.Forms {
 		internal Timer			scroll_timer;
 		internal bool			richtext;
 		internal bool			show_selection;		// set to true to always show selection, even if no focus is set
+		
+		internal bool has_been_focused;
+
 		internal int			selection_length = -1;	// set to the user-specified selection length, or -1 if none
 		internal bool show_caret_w_selection;  // TextBox shows the caret when the selection is visible
 		internal int			requested_height;
@@ -591,6 +594,9 @@ namespace System.Windows.Forms {
 			}
 
 			set {
+				// reset to force a select all next time the box gets focus
+				has_been_focused = false;
+
 				if (value == Text)
 					return;
 
@@ -660,12 +666,24 @@ namespace System.Windows.Forms {
 		#endregion	// Protected Instance Properties
 
 		#region Public Instance Methods
-		public void AppendText(string text) {
-			document.MoveCaret (CaretDirection.CtrlEnd);				
+		public void AppendText(string text)
+		{
+			// Save some cycles and only check the Text if we are one line
+			bool is_empty = document.Lines == 1 && Text == String.Empty; 
+
+			document.MoveCaret (CaretDirection.CtrlEnd);
 			document.Insert (document.caret.line, document.caret.pos, false, text);
 			document.MoveCaret (CaretDirection.CtrlEnd);
 			document.SetSelectionToCaret (true);
 
+			if (!is_empty)
+				ScrollToCaret ();
+
+			//
+			// Avoid the initial focus selecting all when append text is used
+			//
+			has_been_focused = true;
+
 			OnTextChanged(EventArgs.Empty);
 		}
 
@@ -731,8 +749,7 @@ namespace System.Windows.Forms {
 			document.DisplayCaret ();
 		}
 
-		/// Sync with above (except the invalidation of course)
-		internal void SelectAllNoInvalidate ()
+		internal void SelectAllNoScroll ()
 		{
 			Line last;
 
@@ -741,6 +758,8 @@ namespace System.Windows.Forms {
 			document.SetSelectionEnd(last, last.text.Length, false);
 			document.PositionCaret (document.selection_end.line, document.selection_end.pos);
 			selection_length = -1;
+
+			document.DisplayCaret ();
 		}
 
 		public override string ToString() {
@@ -1839,7 +1858,7 @@ namespace System.Windows.Forms {
 			Point	pos;
 			int	height;
 
-			if (canvas_width < 1 || canvas_height < 1)
+			if (!IsHandleCreated || canvas_width < 1 || canvas_height < 1)
 				return;
 
   			document.MoveCaretToTextTag ();