Parcourir la source

2005-06-21 Peter Bartok <[email protected]>

	* TextBoxBase.cs:
	  - Now calling PositionCaret with absolute space coordinates
	  - Enabled vertical scrolling
	  - Better tracking of scrollbar changes, tied into WidthChange
	    event
	  - Improved cursor tracking
	  - Removed debug output
	* TextControl.cs:
	  - PositionCaret coordinates are now works in absolute space, not 
	    the canvas
	  - Improved tracking of document size
	  - Added events for width and height changes


svn path=/trunk/mcs/; revision=46340
Peter Dennis Bartok il y a 20 ans
Parent
commit
a47b4ee260

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

@@ -1,3 +1,18 @@
+2005-06-21  Peter Bartok  <[email protected]> 
+
+	* TextBoxBase.cs:
+	  - Now calling PositionCaret with absolute space coordinates
+	  - Enabled vertical scrolling
+	  - Better tracking of scrollbar changes, tied into WidthChange
+	    event
+	  - Improved cursor tracking
+	  - Removed debug output
+	* TextControl.cs:
+	  - PositionCaret coordinates are now works in absolute space, not 
+	    the canvas
+	  - Improved tracking of document size
+	  - Added events for width and height changes
+
 2005-06-21  Peter Bartok  <[email protected]>
 
 	* Form.cs: Set focus to active control when form is activated

+ 36 - 41
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs

@@ -87,6 +87,7 @@ namespace System.Windows.Forms {
 			word_wrap = true;
 			richtext = false;
 			document = new Document(this);
+			document.WidthChanged += new EventHandler(document_WidthChanged);
 			//document.CaretMoved += new EventHandler(CaretMoved);
 			document.Wrap = true;
 			requested_height = -1;
@@ -1092,7 +1093,7 @@ static int current;
 			int	pos;
 
 			if (e.Button == MouseButtons.Left) {
-				document.PositionCaret(e.X, e.Y);
+				document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
 				document.SetSelectionToCaret(true);
 				this.grabbed = true;
 				this.Capture = true;
@@ -1141,7 +1142,7 @@ static int current;
 			this.Capture = false;
 			this.grabbed = false;
 			if (e.Button == MouseButtons.Left) {
-				document.PositionCaret(e.X, e.Y);
+				document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
 				document.SetSelectionToCaret(false);
 				document.DisplayCaret();
 				return;
@@ -1201,8 +1202,8 @@ static int current;
 			}
 
 			if (hscroll.Visible) {
-				vscroll.Maximum += hscroll.Height * 2;
-				canvas_height = this.Height - hscroll.Height * 2;
+				vscroll.Maximum += hscroll.Height;
+				canvas_height = this.Height - hscroll.Height;
 			}
 
 			if (vscroll.Visible) {
@@ -1211,24 +1212,28 @@ static int current;
 			}
 		}
 
+		private void document_WidthChanged(object sender, EventArgs e) {
+			CalculateScrollBars();
+		}
+
 		private void hscroll_ValueChanged(object sender, EventArgs e) {
 			XplatUI.ScrollWindow(this.Handle, document.ViewPortX-this.hscroll.Value, 0, false);
 			document.ViewPortX = this.hscroll.Value;
 			document.UpdateCaret();
-			Console.WriteLine("Dude scrolled horizontal");
+			//Console.WriteLine("Dude scrolled horizontal");
 		}
 
 		private void vscroll_ValueChanged(object sender, EventArgs e) {
 			XplatUI.ScrollWindow(this.Handle, 0, document.ViewPortY-this.vscroll.Value, false);
-			document.ViewPortX = this.vscroll.Value;
+			document.ViewPortY = this.vscroll.Value;
 			document.UpdateCaret();
-			Console.WriteLine("Dude scrolled vertical");
+			//Console.WriteLine("Dude scrolled vertical");
 		}
 
 		private void TextBoxBase_MouseMove(object sender, MouseEventArgs e) {
 			// FIXME - handle auto-scrolling if mouse is to the right/left of the window
 			if (grabbed) {
-				document.PositionCaret(e.X, e.Y);
+				document.PositionCaret(e.X + document.ViewPortX, e.Y + document.ViewPortY);
 				document.SetSelectionToCaret(false);
 				document.DisplayCaret();
 			}
@@ -1252,56 +1257,46 @@ static int current;
 		/// <summary>Ensure the caret is always visible</summary>
 		internal void CaretMoved(object sender, EventArgs e) {
 			Point	pos;
+			int	height;
 			
 			pos = document.Caret;
-			Console.WriteLine("Caret now at {0} (Thumb: {1}x{2}, Canvas: {3}x{4}, Document {5}x{6})", pos, hscroll.Value, vscroll.Value, canvas_width, canvas_height, document.Width, document.Height);
+			//Console.WriteLine("Caret now at {0} (Thumb: {1}x{2}, Canvas: {3}x{4}, Document {5}x{6})", pos, hscroll.Value, vscroll.Value, canvas_width, canvas_height, document.Width, document.Height);
 
 			// Handle horizontal scrolling
 			if (pos.X < (document.ViewPortX + track_width)) {
-				if ((hscroll.Value - track_width) >= hscroll.Minimum) {
-					hscroll.Value -= track_width;
-				} else {
-					hscroll.Value = hscroll.Minimum;
-				}
+				do {
+					if ((hscroll.Value - track_width) >= hscroll.Minimum) {
+						hscroll.Value -= track_width;
+					} else {
+						hscroll.Value = hscroll.Minimum;
+					}
+				} while (hscroll.Value > pos.X);
 			}
 
-			if ((pos.X > (this.Width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {
-				if ((hscroll.Value + track_width) <= hscroll.Maximum) {
-					hscroll.Value += track_width;
-				} else {
-					hscroll.Value = hscroll.Maximum;
-				}
+			if ((pos.X > (this.canvas_width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {
+				do {
+					if ((hscroll.Value + track_width) <= hscroll.Maximum) {
+						hscroll.Value += track_width;
+					} else {
+						hscroll.Value = hscroll.Maximum;
+					}
+				} while (pos.X > (hscroll.Value + this.canvas_width));
 			}
 
 			if (!multiline) {
 				return;
 			}
-#if not
-			// Handle vertical scrolling
-			if (pos.Y < (document.ViewPortY + track_width)) {
-				if ((hscroll.Value - track_width) >= hscroll.Minimum) {
-					hscroll.Value -= track_width;
-				} else {
-					hscroll.Value = hscroll.Minimum;
-				}
 
-				if (pos.X > this.Width + document.ViewPortX) {
-					hscroll.Value = hscroll.Minimum;
-				}
-			}
+			// Handle vertical scrolling
+			height = document.CaretLine.Height;
 
-			if (pos.X > (this.Width + document.ViewPortX - track_width)) {
-				if ((hscroll.Value + track_width) <= hscroll.Maximum) {
-					hscroll.Value += track_width;
-				} else {
-					hscroll.Value = hscroll.Maximum;
-				}
+			if (pos.Y < document.ViewPortY) {
+				vscroll.Value = pos.Y;
 			}
 
-			if (pos.X < document.ViewPortX) {
-				hscroll.Value = hscroll.Minimum;
+			if ((pos.Y + height) > (document.ViewPortY + canvas_height)) {
+				vscroll.Value = pos.Y - canvas_height + height;
 			}
-#endif
 		}
 	}
 }

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

@@ -608,7 +608,7 @@ namespace System.Windows.Forms {
 
 		internal Point Caret {
 			get {
-				return new Point((int)caret.tag.line.widths[caret.pos] + caret.line.align_shift, caret.line.Y + caret.tag.shift);
+				return new Point((int)caret.tag.line.widths[caret.pos] + caret.line.align_shift, caret.line.Y);
 			}
 		}
 
@@ -1008,7 +1008,7 @@ namespace System.Windows.Forms {
 		}
 
 		internal void PositionCaret(int x, int y) {
-			caret.tag = FindCursor(x + viewport_x, y + viewport_y, out caret.pos);
+			caret.tag = FindCursor(x, y, out caret.pos);
 			caret.line = caret.tag.line;
 			caret.height = caret.tag.height;
 
@@ -1244,8 +1244,9 @@ namespace System.Windows.Forms {
 			Brush	hilight_text;
 
 			// First, figure out from what line to what line we need to draw
-			start = GetLineByPixel(clip.Top - viewport_y, false).line_no;
-			end = GetLineByPixel(clip.Bottom - viewport_y, false).line_no;
+			start = GetLineByPixel(clip.Top + viewport_y, false).line_no;
+			end = GetLineByPixel(clip.Bottom + viewport_y, false).line_no;
+Console.WriteLine("Starting drawing at line {0}, ending at line {1} (clip-bottom:{2})", start, end, clip.Bottom);
 
 			// Now draw our elements; try to only draw those that are visible
 			line_no = start;
@@ -2546,9 +2547,12 @@ if (end != null) {
 			Line	line;
 			int	line_no;
 			int	Y;
+			int	new_width;
 
 			Y = GetLine(start).Y;
 			line_no = start;
+			new_width = 0;
+
 			if (optimize) {
 				bool	changed;
 				bool	alignment_recalc;
@@ -2566,9 +2570,8 @@ if (end != null) {
 							end = this.lines;
 						}
 
-						if (line.widths[line.text.Length] > this.document_x) {
-							this.document_x = (int)line.widths[line.text.Length];
-							alignment_recalc = true;
+						if (line.widths[line.text.Length] > new_width) {
+							new_width = (int)line.widths[line.text.Length];
 						}
 
 						// Calculate alignment
@@ -2588,12 +2591,25 @@ if (end != null) {
 					}
 				}
 
+				if (document_x < new_width) {
+					document_x = new_width;
+					alignment_recalc = true;
+					if (WidthChanged != null) {
+						WidthChanged(this, null);
+					}
+				}
+
 				if (alignment_recalc) {
 					RecalculateAlignments();
 				}
 
 				line = GetLine(lines);
-				document_y = line.Y + line.height;
+				if (document_y != line.Y + line.height) {
+					document_y = line.Y + line.height;
+					if (HeightChanged != null) {
+						HeightChanged(this, null);
+					}
+				}
 
 				return changed;
 			} else {
@@ -2613,8 +2629,8 @@ if (end != null) {
 						shift = 0;
 					}
 
-					if (line.widths[line.text.Length] > this.document_x) {
-						this.document_x = (int)line.widths[line.text.Length];
+					if (line.widths[line.text.Length] > new_width) {
+						new_width = (int)line.widths[line.text.Length];
 					}
 
 					// Calculate alignment
@@ -2632,10 +2648,24 @@ if (end != null) {
 						break;
 					}
 				}
+
+				if (document_x != new_width) {
+					document_x = new_width;
+					if (WidthChanged != null) {
+						WidthChanged(this, null);
+					}
+				}
+
 				RecalculateAlignments();
 
 				line = GetLine(lines);
-				document_y = line.Y + line.height;
+
+				if (document_y != line.Y + line.height) {
+					document_y = line.Y + line.height;
+					if (HeightChanged != null) {
+						HeightChanged(this, null);
+					}
+				}
 
 				return true;
 			}
@@ -2652,6 +2682,8 @@ if (end != null) {
 
 		#region Events
 		internal event EventHandler CaretMoved;
+		internal event EventHandler WidthChanged;
+		internal event EventHandler HeightChanged;
 		#endregion	// Events
 
 		#region Administrative