* TextControl.cs: We need to manually break apart tabbed text
authorJackson Harper <jackson@novell.com>
Thu, 24 May 2007 18:57:31 +0000 (18:57 -0000)
committerJackson Harper <jackson@novell.com>
Thu, 24 May 2007 18:57:31 +0000 (18:57 -0000)
        * and
        move the tabs, since the system.drawing tabbing mechanism relies
        on tab stops.
        * TextBoxBase.cs: Move the caret properly when the user enters a
        tab.

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

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 f0a0ee3dc9e8836c31d24b77eabf61bcdd09e2c7..9c89c7deed5fca6b97ae6ec2b7be1d70522eea86 100644 (file)
@@ -1,3 +1,11 @@
+2007-05-24  Jackson Harper  <jackson@ximian.com>
+
+       * TextControl.cs: We need to manually break apart tabbed text and
+       move the tabs, since the system.drawing tabbing mechanism relies
+       on tab stops.
+       * TextBoxBase.cs: Move the caret properly when the user enters a
+       tab.
+
 2007-05-24  Jonathan Pobst  <monkey@jpobst.com>
 
        * ContainerControl.cs: Don't check CanSelect before calling
index 5d2f43c5fb43b9e48602bf395c0b8dc8e536b435..6887debd1b76cd7b69f8378483d62f32421f12d9 100644 (file)
@@ -1254,11 +1254,7 @@ namespace System.Windows.Forms {
 
                                case Keys.Tab: {
                                        if (!read_only && accepts_tab && document.multiline) {
-                                               document.InsertChar(document.CaretLine, document.CaretPosition, '\t');
-                                               if (document.selection_visible) {
-                                                       document.ReplaceSelection("", false);
-                                               }
-                                               document.SetSelectionToCaret(true);
+                                               document.InsertCharAtCaret ('\t', true);
 
                                                OnTextChanged(EventArgs.Empty);
                                                CaretMoved(this, null);
index 665cf63bd465f44f5d946ea4eb09b62d97ddbd5b..89d99cb39f53bb985d859eaa0d75a107b6dc5fd5 100644 (file)
@@ -2131,7 +2131,7 @@ namespace System.Windows.Forms {
                                                }
 
                                                tag.Draw (g, current_brush,
-                                                               line.widths [Math.Max (0, old_tag_pos - 1)] + line.X - viewport_x,
+                                                               line.X - viewport_x,
                                                                line_y + tag.shift,
                                                                old_tag_pos - 1, Math.Min (tag.length, tag_pos - old_tag_pos),
                                                                text.ToString() );
@@ -4506,14 +4506,14 @@ namespace System.Windows.Forms {
                        return (int) (picture.Height + 0.5F);
                }
 
-               internal override void Draw (Graphics dc, Brush brush, float x, float y, int start, int end)
+               internal override void Draw (Graphics dc, Brush brush, float xoff, float y, int start, int end)
                {
-                       picture.DrawImage (dc, x, y, false);
+                       picture.DrawImage (dc, xoff + line.widths [start], y, false);
                }
 
-               internal override void Draw (Graphics dc, Brush brush, float x, float y, int start, int end, string text)
+               internal override void Draw (Graphics dc, Brush brush, float xoff, float y, int start, int end, string text)
                {
-                       picture.DrawImage (dc, x, y, false);
+                       picture.DrawImage (dc, xoff + + line.widths [start], y, false);
                }
 
                public override string Text ()
@@ -4611,12 +4611,15 @@ namespace System.Windows.Forms {
 
                internal virtual SizeF SizeOfPosition (Graphics dc, int pos)
                {
-                       
                        if (pos >= line.TextLengthWithoutEnding () && line.document.multiline)
                                return SizeF.Empty;
 
                        string text = line.text.ToString (pos, 1);
                        switch ((int) text [0]) {
+                       case '\t':
+                               SizeF res = dc.MeasureString (" ", font, 10000, Document.string_format);
+                               res.Width *= 8.0F;
+                               return res;
                        case 10:
                        case 13:
                                return dc.MeasureString ("\u0013", font, 10000, Document.string_format);
@@ -4635,9 +4638,16 @@ namespace System.Windows.Forms {
                        dc.DrawString (line.text.ToString (start, end), font, brush, x, y, StringFormat.GenericTypographic);
                }
 
-               internal virtual void Draw (Graphics dc, Brush brush, float x, float y, int start, int end, string text)
+               internal virtual void Draw (Graphics dc, Brush brush, float xoff, float y, int start, int end, string text)
                {
-                       dc.DrawString (text.Substring (start, end), font, brush, x, y, StringFormat.GenericTypographic);
+                       while (start < end) {
+                               int tab_index = text.IndexOf ("\t", start);
+                               if (tab_index == -1)
+                                       tab_index = end;
+                               dc.DrawString (text.Substring (start, tab_index - start), font, brush, xoff + line.widths [start],
+                                               y, StringFormat.GenericTypographic);
+                               start = tab_index + 1;
+                       }
                }
 
                ///<summary>Break a tag into two with identical attributes; pos is 1-based; returns tag starting at &gt;pos&lt; or null if end-of-line</summary>