Refactored, cleaned up
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TextControl.cs
index 5d3c25cb73be69681200f7c8602055916e958ef7..71e5f4207c888601bb5fc7ed4eb7d8a1cd37104b 100644 (file)
@@ -659,11 +659,14 @@ namespace System.Windows.Forms {
 
                private void SetSelectionVisible (bool value)
                {
+                       bool old_selection_visible = selection_visible;
                        selection_visible = value;
 
                        // cursor and selection are enemies, we can't have both in the same room at the same time
                        if (owner.IsHandleCreated && !owner.show_caret_w_selection)
                                XplatUI.CaretVisible (owner.Handle, !selection_visible);
+                       if (UIASelectionChanged != null && (selection_visible || old_selection_visible))
+                               UIASelectionChanged (this, EventArgs.Empty);
                }
 
                private void DecrementLines(int line_no) {
@@ -926,15 +929,14 @@ namespace System.Windows.Forms {
 
                        int start_line_top = line.Y;                    
 
-                       int end_line_bottom;
-                       Line end_line;
-
-                       end_line = GetLine (line.line_no + line_count);
+                       Line end_line = GetLine (line.line_no + line_count);
                        if (end_line == null)
                                end_line = GetLine (lines);
 
-
-                       end_line_bottom = end_line.Y + end_line.height;
+                       if (end_line == null)
+                               return;
+                       
+                       int end_line_bottom = end_line.Y + end_line.height;
                        
                        if (RecalculateDocument(owner.CreateGraphicsInternal(), line.line_no, line.line_no + line_count, true)) {
                                // Lineheight changed, invalidate the rest of the document
@@ -1143,11 +1145,7 @@ namespace System.Windows.Forms {
                        int best_index = -1;
 
                        for (int i = 0; i < needles.Length; i++) {
-#if  NET_2_0
                                int index = haystack.IndexOf (needles [i], start_index, StringComparison.InvariantCultureIgnoreCase);
-#else
-                               int index = haystack.ToLower().IndexOf(needles[i], start_index);
-#endif
 
                                if (index > -1) {
                                        if (term_found > -1) {
@@ -1684,8 +1682,12 @@ namespace System.Windows.Forms {
                internal void GetVisibleLineIndexes (Rectangle clip, out int start, out int end)
                {
                        if (multiline) {
-                               start = GetLineByPixel(clip.Top + viewport_y - offset_y, false).line_no;
-                               end = GetLineByPixel(clip.Bottom + viewport_y - offset_y, false).line_no;
+                               /* Expand the region slightly to be sure to
+                                * paint the full extent of the line of text.
+                                * See bug 464464.
+                                */
+                               start = GetLineByPixel(clip.Top + viewport_y - offset_y - 1, false).line_no;
+                               end = GetLineByPixel(clip.Bottom + viewport_y - offset_y + 1, false).line_no;
                        } else {
                                start = GetLineByPixel(clip.Left + viewport_x - offset_x, false).line_no;
                                end = GetLineByPixel(clip.Right + viewport_x - offset_x, false).line_no;
@@ -1982,6 +1984,11 @@ namespace System.Windows.Forms {
                        base_line = line.line_no;
                        old_line_count = lines;
 
+                       // Discard chars after any possible -unlikely- end of file
+                       int eof_index = s.IndexOf ('\0');
+                       if (eof_index != -1)
+                               s = s.Substring (0, eof_index);
+
                        break_index = GetLineEnding (s, 0, out ending, LineEnding.Hard | LineEnding.Rich);
 
                        // There are no line feeds in our text to be pasted
@@ -2184,10 +2191,17 @@ namespace System.Windows.Forms {
                        if ((pos == 0 && forward == false) || (pos == line.text.Length && forward == true))
                                return;
                        
-                       if (forward)
+                       undo.BeginUserAction ("Delete");
+
+                       if (forward) {
+                               undo.RecordDeleteString (line, pos, line, pos + 1);
                                DeleteChars (line, pos, 1);
-                       else
+                       } else {
+                               undo.RecordDeleteString (line, pos - 1, line, pos);
                                DeleteChars (line, pos - 1, 1);
+                       }
+
+                       undo.EndUserAction ();
                }
 
                // Combine two lines
@@ -4007,6 +4021,7 @@ namespace System.Windows.Forms {
                internal event EventHandler WidthChanged;
                internal event EventHandler HeightChanged;
                internal event EventHandler LengthChanged;
+               internal event EventHandler UIASelectionChanged;
                #endregion      // Events
 
                #region Administrative