svn path=/trunk/mcs/; revision=94612
authorLuke Page <lpage@mono-cvs.ximian.com>
Sat, 2 Feb 2008 11:37:37 +0000 (11:37 -0000)
committerLuke Page <lpage@mono-cvs.ximian.com>
Sat, 2 Feb 2008 11:37:37 +0000 (11:37 -0000)
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Line.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs

index a7710a21596e6a6778fb554d0fe16abbecad3876..7fe5e08b565c58ff33858338484d32fa0cf08bbc 100644 (file)
@@ -1,3 +1,10 @@
+2008-02-02  Luke Page  <luke.a.page@gmail.com>
+
+       * Line.cs, LineTag.cs, RichTextBox.cs, TextControl.cs
+       Fixes bug 351938 - caret is positioned correctly when drawn
+       and when calculating textual position of caret, no longer
+       has a NRE in certain situations.
+       
 2008-02-01  Geoff Norton  <gnorton@novell.com>
 
        * Hwnd.cs: Ensure that windows moved into -'ve coordinate space
index 01306ed9e76d9f5d8ed55d7a7fa60896ad68e6b0..8a5c293ab9d4435584e782dfdb806b950159186e 100644 (file)
@@ -452,11 +452,15 @@ namespace System.Windows.Forms
                        bool wrapped;\r
                        Line line;\r
                        int wrap_pos;\r
+                       int prev_height;\r
+                       int prev_ascent;\r
 \r
                        pos = 0;\r
                        len = this.text.Length;\r
                        tag = this.tags;\r
                        prev_offset = this.offset;      // For drawing optimization calculations\r
+                       prev_height = this.height;\r
+                       prev_ascent = this.ascent;\r
                        this.height = 0;                // Reset line height\r
                        this.ascent = 0;                // Reset the ascent for the line\r
                        tag.Shift = 0;\r
@@ -473,9 +477,10 @@ namespace System.Windows.Forms
                        wrap_pos = 0;\r
 \r
                        while (pos < len) {\r
+\r
                                while (tag.Length == 0) {       // We should always have tags after a tag.length==0 unless len==0\r
                                        //tag.Ascent = 0;\r
-                                       tag.Shift = 0;\r
+                                       tag.Shift = tag.Line.ascent - tag.Ascent;\r
                                        tag = tag.Next;\r
                                }\r
 \r
@@ -561,12 +566,18 @@ namespace System.Windows.Forms
                                }\r
                        }\r
 \r
+                       while (tag != null) {   \r
+                               tag.Shift = tag.Line.ascent - tag.Ascent;\r
+                               tag = tag.Next;\r
+                       }\r
+\r
                        if (this.height == 0) {\r
                                this.height = tags.Font.Height;\r
-                               tag.Height = this.height;\r
+                               tags.Height = this.height;\r
+                               tags.Shift = 0;\r
                        }\r
 \r
-                       if (prev_offset != offset)\r
+                       if (prev_offset != offset || prev_height != this.height || prev_ascent != this.ascent)\r
                                retval = true;\r
 \r
                        return retval;\r
index 1cd72bb6bc9177843b030089c7eeb8573cbd14b2..9e0d5c7e2b73556ae03dc28361e8f358f6792f9e 100644 (file)
@@ -396,7 +396,11 @@ namespace System.Windows.Forms
                                return tag;     // Not sure if we should get the final tag here\r
 \r
                        while (tag != null) {\r
-                               if ((tag.start <= pos) && (pos <= tag.End))\r
+                               // [H  e][l][l  o  _  W][o  r]  Text\r
+                               // [1  2][3][4  5  6  7][8  9]  Start\r
+                               //     3  4           8     10  End\r
+                               // 0 1  2  3  4  5  6  7  8  9   Pos\r
+                               if ((tag.start <= pos) && (pos < tag.End))\r
                                        return GetFinalTag (tag);\r
 \r
                                tag = tag.next;\r
@@ -444,7 +448,7 @@ namespace System.Windows.Forms
                                return retval;\r
                        }\r
 \r
-                       start_tag = FindTag (line, formatStart);\r
+                       start_tag = FindTag (line, formatStart - 1);\r
 \r
                        // we are at an empty tag already!\r
                        // e.g. [Tag 0 - "He"][Tag 1 = 0 length][Tag 2 "llo world"]\r
@@ -487,7 +491,7 @@ namespace System.Windows.Forms
                                return retval;\r
 \r
                        /// Now do the last tag\r
-                       end_tag = FindTag (line, end);\r
+                       end_tag = FindTag (line, end-1);\r
 \r
                        if (end_tag != null) {\r
                                end_tag.Break (end);\r
@@ -507,13 +511,16 @@ namespace System.Windows.Forms
                        int length_no_ending = line.TextLengthWithoutEnding ();\r
 \r
                        if (Length == 0)\r
-                               return start;\r
+                               return low-1;\r
 \r
                        if (length_no_ending == 0)\r
                                return 0;\r
-                               \r
-                       if (x < line.widths[low])\r
+\r
+                       if (x < line.widths [low]) {\r
+                               if (low == 1 && x > (line.widths [1] / 2))\r
+                                       return low;\r
                                return low - 1;\r
+                       }\r
 \r
                        if (x > line.widths[length_no_ending])\r
                                return length_no_ending;\r
@@ -562,8 +569,9 @@ namespace System.Windows.Forms
 \r
                private static void SetFormat (LineTag tag, Font font, Color color, Color back_color, FormatSpecified specified)\r
                {\r
-                       if ((FormatSpecified.Font & specified) == FormatSpecified.Font)\r
+                       if ((FormatSpecified.Font & specified) == FormatSpecified.Font) {\r
                                tag.Font = font;\r
+                       }\r
                        if ((FormatSpecified.Color & specified) == FormatSpecified.Color)\r
                                tag.color = color;\r
                        if ((FormatSpecified.BackColor & specified) == FormatSpecified.BackColor) {\r
index 7fb1f67fb4ccd0b319f436187ef10f995ed251ca..5dbb0c7d8371074494c8412fd2e4689a6f23d637 100644 (file)
@@ -1359,6 +1359,7 @@ namespace System.Windows.Forms {
                        remove { base.QueryContinueDrag -= value; }
                }
 
+               [MonoTODO("Currently does not ever fire")]
                public event EventHandler SelectionChanged {
                        add { Events.AddHandler (SelectionChangedEvent, value); }
                        remove { Events.RemoveHandler (SelectionChangedEvent, value); }
index 7df6716c454b7fad596845540449a37413d83f25..d648af62e52312777422dfd520aa2a4a49a79bf6 100644 (file)
@@ -1268,11 +1268,20 @@ namespace System.Windows.Forms {
                                MoveCaretToTextTag ();
                        }
 
-                       caret.height = caret.tag.Height;
+                       // if the caret has had SelectionFont changed to a
+                       // different height, we reflect changes unless the new
+                       // font is larger than the line (line recalculations
+                       // ignore empty tags) in which case we make it equal
+                       // the line height and then when text is entered
+                       if (caret.tag.Height > caret.tag.Line.Height) {
+                               caret.height = caret.line.height;
+                       } else {
+                               caret.height = caret.tag.Height;
+                       }
 
                        if (owner.Focused) {
                                XplatUI.CreateCaret(owner.Handle, caret_width, caret.height);
-                               XplatUI.SetCaretPos(owner.Handle, (int)caret.tag.Line.widths[caret.pos] + caret.line.X - viewport_x, caret.line.Y + caret.tag.Shift - viewport_y + caret_shift);
+                               XplatUI.SetCaretPos (owner.Handle, (int) caret.tag.Line.widths [caret.pos] + caret.line.X - viewport_x, caret.line.Y + viewport_y + caret_shift);
                                DisplayCaret ();
                        }
 
@@ -1955,7 +1964,7 @@ namespace System.Windows.Forms {
                // Inserts a character at the current caret position
                internal void InsertCharAtCaret (char ch, bool move_caret)
                {
-                       caret.line.InsertString (caret.pos, ch.ToString ());
+                       caret.line.InsertString (caret.pos, ch.ToString(), caret.tag);
 
                        undo.RecordTyping (caret.line, caret.pos, ch);