2006-02-27 Peter Dennis Bartok <pbartok@novell.com>
authorPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Tue, 28 Feb 2006 01:40:04 +0000 (01:40 -0000)
committerPeter Dennis Bartok <pbartok@mono-cvs.ximian.com>
Tue, 28 Feb 2006 01:40:04 +0000 (01:40 -0000)
* TextControl.cs: Added property and implemented means to allow
  disabling recalculation of a document (can be used to speed up
  multiple inserts and is needed to make RTF inserts predictable, see
  bug #77659)
* RichTextBox.cs: Using the new NoRecalc property of Document to
  keep x/y insert locations predictable. Also makes it faster inserting
  large chunks of RTF

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

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/RichTextBox.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/TextControl.cs

index 835bb1f15cdbe2b7f96eaef30b18a758ce423f51..9e7f3a5d6ba807f5a60325126139bd4b1f5a85fb 100644 (file)
@@ -1,3 +1,13 @@
+2006-02-27  Peter Dennis Bartok  <pbartok@novell.com>
+
+       * TextControl.cs: Added property and implemented means to allow 
+         disabling recalculation of a document (can be used to speed up
+         multiple inserts and is needed to make RTF inserts predictable, see
+         bug #77659)
+       * RichTextBox.cs: Using the new NoRecalc property of Document to
+         keep x/y insert locations predictable. Also makes it faster inserting
+         large chunks of RTF
+
 2006-02-27  Peter Dennis Bartok  <pbartok@novell.com> 
 
        * Control.cs: Separated special WM_SYSKEYUP keyboard handling. That way
index 6662c87d5dd6d6021fffa6685d577377c17d965d..1fc221f6bc44e18256aae9457aeeea04574754fa 100644 (file)
@@ -1352,6 +1352,8 @@ namespace System.Windows.Forms {
                        rtf_text_map = new RTF.TextMap();
                        RTF.TextMap.SetupStandardTable(rtf_text_map.Table);
 
+                       document.NoRecalc = true;
+
                        try {
                                rtf.Read();     // That's it
                                FlushText(rtf, false);
@@ -1366,6 +1368,8 @@ namespace System.Windows.Forms {
                        to_y = rtf_cursor_y;
 
                        document.RecalculateDocument(CreateGraphics(), cursor_y, document.Lines, false);
+                       document.NoRecalc = false;
+
                        document.Invalidate(document.GetLine(cursor_y), 0, document.GetLine(document.Lines), -1);
                }
 
index 69a447c614425f11180d12835645248f0bc43cc3..98960cb1c0ac5fa1d4aacf05492492bf66b59928 100644 (file)
@@ -726,6 +726,12 @@ namespace System.Windows.Forms {
                private bool            calc_pass;
                private int             char_count;
 
+               private bool            no_recalc;
+               private bool            recalc_pending;
+               private int             recalc_start;
+               private int             recalc_end;
+               private bool            recalc_optimize;
+
                internal bool           multiline;
                internal bool           wrap;
 
@@ -763,6 +769,8 @@ namespace System.Windows.Forms {
                        multiline = true;
                        password_char = "";
                        calc_pass = false;
+                       no_recalc = false;
+                       recalc_pending = false;
 
                        // Tree related stuff
                        sentinel = new Line();
@@ -908,6 +916,22 @@ namespace System.Windows.Forms {
                        }
                }
 
+               ///<summary>Setting NoRecalc to true will prevent the document from being recalculated.
+               ///This ensures that coordinates of added text are predictable after adding the text even with wrapped view</summary>
+               internal bool NoRecalc {
+                       get {
+                               return no_recalc;
+                       }
+
+                       set {
+                               no_recalc = value;
+                               if (!no_recalc && recalc_pending) {
+                                       RecalculateDocument(owner.CreateGraphics(), recalc_start, recalc_end, recalc_optimize);
+                                       recalc_pending = false;
+                               }
+                       }
+               }
+
                internal int ViewPortY {
                        get {
                                return viewport_y;
@@ -1247,6 +1271,14 @@ namespace System.Windows.Forms {
                                return;
                        }
 
+                       if (no_recalc) {
+                               recalc_start = line.line_no;
+                               recalc_end = line.line_no;
+                               recalc_optimize = true;
+                               recalc_pending = true;
+                               return;
+                       }
+
                        if (RecalculateDocument(owner.CreateGraphics(), line.line_no, line.line_no, true)) {
                                // Lineheight changed, invalidate the rest of the document
                                if ((line.Y - viewport_y) >=0 ) {
@@ -1264,6 +1296,18 @@ namespace System.Windows.Forms {
 
                // Update display from line, down line_count lines; pos is unused, but required for the signature
                internal void UpdateView(Line line, int line_count, int pos) {
+                       if (!owner.IsHandleCreated) {
+                               return;
+                       }
+
+                       if (no_recalc) {
+                               recalc_start = line.line_no;
+                               recalc_end = line.line_no + line_count - 1;
+                               recalc_optimize = true;
+                               recalc_pending = true;
+                               return;
+                       }
+
                        if (RecalculateDocument(owner.CreateGraphics(), line.line_no, line.line_no + line_count - 1, true)) {
                                // Lineheight changed, invalidate the rest of the document
                                if ((line.Y - viewport_y) >=0 ) {
@@ -3442,6 +3486,14 @@ namespace System.Windows.Forms {
                        bool    changed;
                        int     shift;
 
+                       if (no_recalc) {
+                               recalc_pending = true;
+                               recalc_start = start;
+                               recalc_end = end;
+                               recalc_optimize = optimize;
+                               return false;
+                       }
+
                        Y = GetLine(start).Y;
                        line_no = start;
                        new_width = 0;