2008-10-03 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Line.cs
index 80fe2c1cf1ace08e57c7a1760ba355aad9a66292..a94ef12fbb818503e036843a5769cface8c5b8d5 100644 (file)
@@ -58,7 +58,7 @@ namespace System.Windows.Forms
                internal Line                   left;                   // Line with smaller line number\r
                internal Line                   right;                  // Line with higher line number\r
                internal LineColor              color;                  // We're doing a black/red tree. this is the node color\r
-               internal int                    DEFAULT_TEXT_LEN;       // \r
+               static int                      DEFAULT_TEXT_LEN = 0;   // \r
                internal bool                   recalc;                 // Line changed\r
                #endregion      // Local Variables\r
 \r
@@ -90,7 +90,7 @@ namespace System.Windows.Forms
                        \r
                        tags = new LineTag(this, 1);\r
                        tags.Font = font;\r
-                       tags.Color = color;                             \r
+                       tags.Color = color;\r
                }\r
 \r
                internal Line (Document document, int LineNo, string Text, HorizontalAlignment align, Font font, Color color, LineEnding ending) : this(document, ending)\r
@@ -201,7 +201,40 @@ namespace System.Windows.Forms
                #endregion      // Internal Properties\r
 \r
                #region Internal Methods\r
-               public void DeleteCharacters (int pos, int count)\r
+\r
+               /// <summary>\r
+               ///  Builds a simple code to record which tags are links and how many tags\r
+               ///  used to compare lines before and after to see if the scan for links\r
+               ///  process has changed anything.\r
+               /// </summary>\r
+               internal void LinkRecord (StringBuilder linkRecord)\r
+               {\r
+                       LineTag tag = tags;\r
+\r
+                       while (tag != null) {\r
+                               if (tag.IsLink)\r
+                                       linkRecord.Append ("L");\r
+                               else\r
+                                       linkRecord.Append ("N");\r
+\r
+                               tag = tag.Next;\r
+                       }\r
+               }\r
+\r
+               /// <summary>\r
+               ///  Clears all link properties from tags\r
+               /// </summary>\r
+               internal void ClearLinks ()\r
+               {\r
+                       LineTag tag = tags;\r
+\r
+                       while (tag != null) {\r
+                               tag.IsLink = false;\r
+                               tag = tag.Next;\r
+                       }\r
+               }\r
+\r
+               public void DeleteCharacters(int pos, int count)\r
                {\r
                        LineTag tag;\r
                        bool streamline = false;\r
@@ -211,7 +244,7 @@ namespace System.Windows.Forms
                                return;\r
 \r
                        // Find the first tag that we are deleting from\r
-                       tag = FindTag (pos);\r
+                       tag = FindTag (pos + 1);\r
 \r
                        // Remove the characters from the line\r
                        text.Remove (pos, count);\r
@@ -298,7 +331,7 @@ namespace System.Windows.Forms
                                break;\r
                        }\r
 \r
-                       TextBoxTextRenderer.DrawText (dc, end_str, last.Font, last.Color, X + widths [TextLengthWithoutEnding ()] - document.viewport_x, y, true);\r
+                       TextBoxTextRenderer.DrawText (dc, end_str, last.Font, last.Color, X + widths [TextLengthWithoutEnding ()] - document.viewport_x + document.OffsetX, y, true);\r
                }\r
 \r
                /// <summary> Find the tag on a line based on the character position, pos is 0-based</summary>\r
@@ -315,7 +348,7 @@ namespace System.Windows.Forms
                                pos = text.Length - 1;\r
 \r
                        while (tag != null) {\r
-                               if (((tag.Start - 1) <= pos) && (pos < (tag.Start + tag.Length - 1)))\r
+                               if (((tag.Start - 1) <= pos) && (pos <= (tag.Start + tag.Length - 1)))\r
                                        return LineTag.GetFinalTag (tag);\r
 \r
                                tag = tag.Next;\r
@@ -375,11 +408,14 @@ namespace System.Windows.Forms
                                widths = new_widths;\r
                        }\r
                }\r
+               public void InsertString (int pos, string s)\r
+               {\r
+                       InsertString (pos, s, FindTag (pos));\r
+               }\r
 \r
                // Inserts a string at the given position\r
-               public void InsertString (int pos, string s)\r
+               public void InsertString (int pos, string s, LineTag tag)\r
                {\r
-                       LineTag tag = FindTag (pos);\r
                        int len = s.Length;\r
 \r
                        // Insert the text into the StringBuilder\r
@@ -416,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
@@ -437,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
@@ -525,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