2005-06-21 Peter Bartok <pbartok@novell.com>
authorPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Wed, 22 Jun 2005 02:03:47 +0000 (02:03 -0000)
committerPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Wed, 22 Jun 2005 02:03:47 +0000 (02:03 -0000)
* 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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextBoxBase.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs

index 9bc8ce08d7d617c01775e2491e1e0d503ec0d7a3..02a24db860ab7be0831b6f7b808e92df6c6252c1 100644 (file)
@@ -1,3 +1,18 @@
+2005-06-21  Peter Bartok  <pbartok@novell.com> 
+
+       * 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  <pbartok@novell.com>
 
        * Form.cs: Set focus to active control when form is activated
index 974a2fcfa21fc90d08ac5028960a8776e225ca2c..5ef36e35535b67fd4ae11691de445cde5f493a08 100644 (file)
@@ -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) {\r
+                       CalculateScrollBars();\r
+               }\r
+
                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) {\r
                        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");
                }\r
 
                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>\r
                internal void CaretMoved(object sender, EventArgs e) {\r
                        Point   pos;\r
+                       int     height;\r
                        \r
                        pos = document.Caret;\r
-                       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);\r
+                       //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);\r
 \r
                        // Handle horizontal scrolling\r
                        if (pos.X < (document.ViewPortX + track_width)) {\r
-                               if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
-                                       hscroll.Value -= track_width;\r
-                               } else {\r
-                                       hscroll.Value = hscroll.Minimum;\r
-                               }\r
+                               do {\r
+                                       if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
+                                               hscroll.Value -= track_width;\r
+                                       } else {\r
+                                               hscroll.Value = hscroll.Minimum;\r
+                                       }\r
+                               } while (hscroll.Value > pos.X);\r
                        }\r
 \r
-                       if ((pos.X > (this.Width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {\r
-                               if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
-                                       hscroll.Value += track_width;\r
-                               } else {\r
-                                       hscroll.Value = hscroll.Maximum;\r
-                               }\r
+                       if ((pos.X > (this.canvas_width + document.ViewPortX - track_width)) && (hscroll.Value != hscroll.Maximum)) {\r
+                               do {\r
+                                       if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
+                                               hscroll.Value += track_width;\r
+                                       } else {\r
+                                               hscroll.Value = hscroll.Maximum;\r
+                                       }\r
+                               } while (pos.X > (hscroll.Value + this.canvas_width));\r
                        }\r
 \r
                        if (!multiline) {\r
                                return;\r
                        }\r
-#if not\r
-                       // Handle vertical scrolling\r
-                       if (pos.Y < (document.ViewPortY + track_width)) {\r
-                               if ((hscroll.Value - track_width) >= hscroll.Minimum) {\r
-                                       hscroll.Value -= track_width;\r
-                               } else {\r
-                                       hscroll.Value = hscroll.Minimum;\r
-                               }\r
 \r
-                               if (pos.X > this.Width + document.ViewPortX) {\r
-                                       hscroll.Value = hscroll.Minimum;\r
-                               }\r
-                       }\r
+                       // Handle vertical scrolling\r
+                       height = document.CaretLine.Height;\r
 \r
-                       if (pos.X > (this.Width + document.ViewPortX - track_width)) {\r
-                               if ((hscroll.Value + track_width) <= hscroll.Maximum) {\r
-                                       hscroll.Value += track_width;\r
-                               } else {\r
-                                       hscroll.Value = hscroll.Maximum;\r
-                               }\r
+                       if (pos.Y < document.ViewPortY) {\r
+                               vscroll.Value = pos.Y;\r
                        }\r
 \r
-                       if (pos.X < document.ViewPortX) {\r
-                               hscroll.Value = hscroll.Minimum;\r
+                       if ((pos.Y + height) > (document.ViewPortY + canvas_height)) {\r
+                               vscroll.Value = pos.Y - canvas_height + height;\r
                        }\r
-#endif\r
                }\r
        }
 }
index d4638edfd86387b4a12563ee0c76ef87ebd655ca..be08e86376ca52c932a51e7b57ec85440cbfa7c8 100644 (file)
@@ -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(xy, 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