2007-10-04 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / RichTextBox.cs
index 3d15dc68dd74cf4f7b5419086e5283f91b8e233e..7901a63d754d4ba0cf065a43ed363dcef76ad681 100644 (file)
@@ -41,6 +41,7 @@ namespace System.Windows.Forms {
        [ClassInterface (ClassInterfaceType.AutoDispatch)]
        [Docking (DockingBehavior.Ask)]
        [ComVisible (true)]
+       [Designer ("System.Windows.Forms.Design.RichTextBoxDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
 #endif
        public class RichTextBox : TextBoxBase {
                #region Local Variables
@@ -63,6 +64,13 @@ namespace System.Windows.Forms {
                private int             rtf_cursor_y;
                private int             rtf_chars;
                private int rtf_par_line_left_indent;
+
+#if NET_2_0
+               private bool            enable_auto_drag_drop;
+               private RichTextBoxLanguageOptions language_option;
+               private bool            rich_text_shortcuts_enabled;
+               private Color           selection_back_color;
+#endif
                #endregion      // Local Variables
 
                #region Public Constructors
@@ -85,6 +93,9 @@ namespace System.Windows.Forms {
                        BackColor = ThemeEngine.Current.ColorWindow;
 #if NET_2_0
                        backcolor_set = false;
+                       language_option = RichTextBoxLanguageOptions.AutoFontSizeAdjust;
+                       rich_text_shortcuts_enabled = true;
+                       selection_back_color = DefaultBackColor;
 #endif
                        ForeColor = ThemeEngine.Current.ColorWindowText;
 
@@ -173,6 +184,15 @@ namespace System.Windows.Forms {
                        set { base.BackgroundImage = value; }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public override ImageLayout BackgroundImageLayout {
+                       get { return base.BackgroundImageLayout; }
+                       set { base.BackgroundImageLayout = value; }
+               }
+#endif
+
                [DefaultValue(0)]
                [Localizable(true)]
                public int BulletIndent {
@@ -204,6 +224,15 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [MonoTODO ("Stub")]
+               [DefaultValue (false)]
+               public bool EnableAutoDragDrop {
+                       get { return enable_auto_drag_drop; }
+                       set { enable_auto_drag_drop = value; }
+               }
+#endif
+
                public override Font Font {
                        get {
                                return base.Font;
@@ -240,6 +269,16 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [MonoTODO ("Stub")]
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public RichTextBoxLanguageOptions LanguageOption {
+                       get { return language_option; }
+                       set { language_option = value; }
+               }
+#endif
+
                [DefaultValue(Int32.MaxValue)]
                public override int MaxLength {
                        get {
@@ -271,6 +310,17 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [MonoTODO ("Stub")]
+               [Browsable (false)]
+               [DefaultValue (true)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public bool RichTextShortcutsEnabled {
+                       get { return rich_text_shortcuts_enabled; }
+                       set { rich_text_shortcuts_enabled = value; }
+               }
+#endif
+
                [DefaultValue(0)]
                [Localizable(true)]
                [MonoTODO("Teach TextControl.RecalculateLine to consider the right margin as well")]
@@ -327,7 +377,10 @@ namespace System.Windows.Forms {
                                        throw new InvalidEnumArgumentException ("value", (int) value,
                                                typeof (RichTextBoxScrollBars));
 
-                               scrollbars = value;
+                               if (value != scrollbars) {
+                                       scrollbars = value;
+                                       CalculateDocument ();
+                               }
                        }
                }
 
@@ -434,6 +487,16 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [MonoTODO ("Stub")]
+               [Browsable (false)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public Color SelectionBackColor {
+                       get { return selection_back_color; }
+                       set { selection_back_color = value; }
+               }
+#endif
+
                [Browsable(false)]
                [DefaultValue(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
@@ -827,11 +890,9 @@ namespace System.Windows.Forms {
                        return Find(str, -1, -1, options);
                }
 
-               public
-#if NET_2_0
-               override
-#endif
-               char GetCharFromPosition(Point pt) {
+               
+#if !NET_2_0
+               public char GetCharFromPosition(Point pt) {
                        LineTag tag;
                        int     pos;
 
@@ -842,8 +903,21 @@ namespace System.Windows.Forms {
                        }
 
                        return tag.line.text[pos];
-                       
                }
+#else
+               internal override char GetCharFromPositionInternal (Point p)
+               {
+                       LineTag tag;
+                       int pos;
+
+                       PointToTagPos (p, out tag, out pos);
+
+                       if (pos >= tag.line.text.Length)
+                               return '\n';
+
+                       return tag.line.text[pos];
+               }
+#endif
 
                public
 #if NET_2_0
@@ -1046,6 +1120,23 @@ namespace System.Windows.Forms {
 //                     }
                }
 
+#if NET_2_0
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public new void DrawToBitmap (Bitmap bitmap, Rectangle clip)
+               {
+                       Graphics dc = Graphics.FromImage (bitmap);
+
+                       if (backcolor_set || (Enabled && !read_only)) {
+                               dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), clip);
+                       } else {
+                               dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ThemeEngine.Current.ColorControl), clip);
+                       }
+                       
+                       // Draw the viewable document
+                       document.Draw (dc, clip);
+               }
+#endif
+
                #endregion      // Public Instance Methods
 
                #region Protected Instance Methods
@@ -1110,6 +1201,7 @@ namespace System.Windows.Forms {
                                eh (this, e);
                }
 
+#if !NET_2_0
                protected override void OnSystemColorsChanged(EventArgs e) {
                        base.OnSystemColorsChanged (e);
                }
@@ -1117,6 +1209,7 @@ namespace System.Windows.Forms {
                protected override void OnTextChanged(EventArgs e) {
                        base.OnTextChanged (e);
                }
+#endif
 
                protected virtual void OnVScroll(EventArgs e) {
                        EventHandler eh = (EventHandler)(Events [VScrollEvent]);
@@ -1127,6 +1220,13 @@ namespace System.Windows.Forms {
                protected override void WndProc(ref Message m) {
                        base.WndProc (ref m);
                }
+
+#if NET_2_0
+               protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
+               {
+                       return base.ProcessCmdKey (ref msg, keyData);
+               }
+#endif
                #endregion      // Protected Instance Methods
 
                #region Events
@@ -1145,17 +1245,28 @@ namespace System.Windows.Forms {
                        remove { base.BackgroundImageChanged -= value; }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public new event EventHandler BackgroundImageLayoutChanged {
+                       add { base.BackgroundImageLayoutChanged += value; }
+                       remove { base.BackgroundImageLayoutChanged -= value; }
+               }
+#endif
+
                public event ContentsResizedEventHandler ContentsResized {
                        add { Events.AddHandler (ContentsResizedEvent, value); }
                        remove { Events.RemoveHandler (ContentsResizedEvent, value); }
                }
 
+#if !NET_2_0
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
                public new event EventHandler DoubleClick {
                        add { base.DoubleClick += value; }
                        remove { base.DoubleClick -= value; }
                }
+#endif
 
                [Browsable(false)]
 #if !NET_2_0
@@ -1519,8 +1630,11 @@ namespace System.Windows.Forms {
 
                        rtf_chars += rtf_line.Length;
 
+                       
+
                        if (rtf_cursor_x == 0) {
-                               document.Add(rtf_cursor_y, rtf_line.ToString(), rtf_rtfalign, font, rtf_color, LineEnding.Wrap);
+                               document.Add(rtf_cursor_y, rtf_line.ToString(), rtf_rtfalign, font, rtf_color,
+                                               newline ? LineEnding.Rich : LineEnding.Wrap);
                                if (rtf_par_line_left_indent != 0) {
                                        Line line = document.GetLine (rtf_cursor_y);
                                        line.indent = rtf_par_line_left_indent;
@@ -1532,10 +1646,14 @@ namespace System.Windows.Forms {
                                line.indent = rtf_par_line_left_indent;
                                if (rtf_line.Length > 0) {
                                        document.InsertString(line, rtf_cursor_x, rtf_line.ToString());
-                                       document.FormatText(line, rtf_cursor_x + 1, line, rtf_cursor_x + 1 + length, font, rtf_color, null, FormatSpecified.Font | FormatSpecified.Color); // FormatText is 1-based
+                                       document.FormatText (line, rtf_cursor_x + 1, line, rtf_cursor_x + 1 + length,
+                                                       font, rtf_color, null,
+                                                       FormatSpecified.Font | FormatSpecified.Color);
                                }
                                if (newline) {
                                        document.Split(line, rtf_cursor_x + length);
+                                       line = document.GetLine (rtf_cursor_y);
+                                       line.ending = LineEnding.Rich;
                                }
                        }
 
@@ -1750,7 +1868,7 @@ namespace System.Windows.Forms {
                                                }
                                        }
 
-                                       pos = tag.start + tag.length - 1;
+                                       pos = tag.start + tag.Length - 1;
                                        tag = tag.next;
                                }
                                pos = 0;
@@ -1831,17 +1949,17 @@ namespace System.Windows.Forms {
 
                                        // Emit the string itself
                                        if (line_no != end_line.line_no) {
-                                               EmitRTFText(sb, tag.line.text.ToString(pos, tag.start + tag.length - pos - 1));
+                                               EmitRTFText(sb, tag.line.text.ToString(pos, tag.start + tag.Length - pos - 1));
                                        } else {
-                                               if (end_pos < (tag.start + tag.length - 1)) {
+                                               if (end_pos < (tag.start + tag.Length - 1)) {
                                                        // Emit partial tag only, end_pos is inside this tag
                                                        EmitRTFText(sb, tag.line.text.ToString(pos, end_pos - pos));
                                                } else {
-                                                       EmitRTFText(sb, tag.line.text.ToString(pos, tag.start + tag.length - pos - 1));
+                                                       EmitRTFText(sb, tag.line.text.ToString(pos, tag.start + tag.Length - pos - 1));
                                                }
                                        }
 
-                                       pos = tag.start + tag.length - 1;
+                                       pos = tag.start + tag.Length - 1;
                                        tag = tag.next;
                                }
                                if (pos >= line.text.Length) {