Author: lpage
Date: 2008-02-02 06:37:37 -0500 (Sat, 02 Feb 2008)
New Revision: 94612

Modified:
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Line.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs
   trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs
Log:


Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-02-02 11:12:51 UTC (rev 94611)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog        
2008-02-02 11:37:37 UTC (rev 94612)
@@ -1,3 +1,10 @@
+2008-02-02  Luke Page  <[EMAIL PROTECTED]>
+
+       * 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  <[EMAIL PROTECTED]>
 
        * Hwnd.cs: Ensure that windows moved into -'ve coordinate space

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Line.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Line.cs  
2008-02-02 11:12:51 UTC (rev 94611)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/Line.cs  
2008-02-02 11:37:37 UTC (rev 94612)
@@ -452,11 +452,15 @@
                        bool wrapped;
                        Line line;
                        int wrap_pos;
+                       int prev_height;
+                       int prev_ascent;
 
                        pos = 0;
                        len = this.text.Length;
                        tag = this.tags;
                        prev_offset = this.offset;      // For drawing 
optimization calculations
+                       prev_height = this.height;
+                       prev_ascent = this.ascent;
                        this.height = 0;                // Reset line height
                        this.ascent = 0;                // Reset the ascent for 
the line
                        tag.Shift = 0;
@@ -473,9 +477,10 @@
                        wrap_pos = 0;
 
                        while (pos < len) {
+
                                while (tag.Length == 0) {       // We should 
always have tags after a tag.length==0 unless len==0
                                        //tag.Ascent = 0;
-                                       tag.Shift = 0;
+                                       tag.Shift = tag.Line.ascent - 
tag.Ascent;
                                        tag = tag.Next;
                                }
 
@@ -561,12 +566,18 @@
                                }
                        }
 
+                       while (tag != null) {   
+                               tag.Shift = tag.Line.ascent - tag.Ascent;
+                               tag = tag.Next;
+                       }
+
                        if (this.height == 0) {
                                this.height = tags.Font.Height;
-                               tag.Height = this.height;
+                               tags.Height = this.height;
+                               tags.Shift = 0;
                        }
 
-                       if (prev_offset != offset)
+                       if (prev_offset != offset || prev_height != this.height 
|| prev_ascent != this.ascent)
                                retval = true;
 
                        return retval;

Modified: trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs       
2008-02-02 11:12:51 UTC (rev 94611)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/LineTag.cs       
2008-02-02 11:37:37 UTC (rev 94612)
@@ -396,7 +396,11 @@
                                return tag;     // Not sure if we should get 
the final tag here
 
                        while (tag != null) {
-                               if ((tag.start <= pos) && (pos <= tag.End))
+                               // [H  e][l][l  o  _  W][o  r]  Text
+                               // [1  2][3][4  5  6  7][8  9]  Start
+                               //     3  4           8     10  End
+                               // 0 1  2  3  4  5  6  7  8  9   Pos
+                               if ((tag.start <= pos) && (pos < tag.End))
                                        return GetFinalTag (tag);
 
                                tag = tag.next;
@@ -444,7 +448,7 @@
                                return retval;
                        }
 
-                       start_tag = FindTag (line, formatStart);
+                       start_tag = FindTag (line, formatStart - 1);
 
                        // we are at an empty tag already!
                        // e.g. [Tag 0 - "He"][Tag 1 = 0 length][Tag 2 "llo 
world"]
@@ -487,7 +491,7 @@
                                return retval;
 
                        /// Now do the last tag
-                       end_tag = FindTag (line, end);
+                       end_tag = FindTag (line, end-1);
 
                        if (end_tag != null) {
                                end_tag.Break (end);
@@ -507,13 +511,16 @@
                        int length_no_ending = line.TextLengthWithoutEnding ();
 
                        if (Length == 0)
-                               return start;
+                               return low-1;
 
                        if (length_no_ending == 0)
                                return 0;
-                               
-                       if (x < line.widths[low])
+
+                       if (x < line.widths [low]) {
+                               if (low == 1 && x > (line.widths [1] / 2))
+                                       return low;
                                return low - 1;
+                       }
 
                        if (x > line.widths[length_no_ending])
                                return length_no_ending;
@@ -562,8 +569,9 @@
 
                private static void SetFormat (LineTag tag, Font font, Color 
color, Color back_color, FormatSpecified specified)
                {
-                       if ((FormatSpecified.Font & specified) == 
FormatSpecified.Font)
+                       if ((FormatSpecified.Font & specified) == 
FormatSpecified.Font) {
                                tag.Font = font;
+                       }
                        if ((FormatSpecified.Color & specified) == 
FormatSpecified.Color)
                                tag.color = color;
                        if ((FormatSpecified.BackColor & specified) == 
FormatSpecified.BackColor) {

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs   
2008-02-02 11:12:51 UTC (rev 94611)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs   
2008-02-02 11:37:37 UTC (rev 94612)
@@ -1359,6 +1359,7 @@
                        remove { base.QueryContinueDrag -= value; }
                }
 
+               [MonoTODO("Currently does not ever fire")]
                public event EventHandler SelectionChanged {
                        add { Events.AddHandler (SelectionChangedEvent, value); 
}
                        remove { Events.RemoveHandler (SelectionChangedEvent, 
value); }

Modified: 
trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs
===================================================================
--- trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs   
2008-02-02 11:12:51 UTC (rev 94611)
+++ trunk/mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs   
2008-02-02 11:37:37 UTC (rev 94612)
@@ -1268,11 +1268,20 @@
                                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 @@
                // 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);
 

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to