[jit] Enable partial generic sharing when not using AOT as an experiment.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / TextBoxBase.cs
index 88134eab3e97b89b7cd9a59afb1320a4e8de2d71..e3c1a70f5cfa98867c03c559fb6c6b8c3afcb28b 100644 (file)
@@ -38,11 +38,9 @@ using System.Collections;
 
 namespace System.Windows.Forms
 {
-#if NET_2_0
        [ComVisible (true)]
        [DefaultBindingProperty ("Text")]
        [ClassInterface (ClassInterfaceType.AutoDispatch)]
-#endif
        [DefaultEvent("TextChanged")]
        [Designer("System.Windows.Forms.Design.TextBoxBaseDesigner, " + Consts.AssemblySystem_Design)]
        public abstract class TextBoxBase : Control
@@ -154,11 +152,9 @@ namespace System.Windows.Forms
                        ResumeLayout ();
                        
                        SetStyle(ControlStyles.UserPaint | ControlStyles.StandardClick, false);
-#if NET_2_0
                        SetStyle(ControlStyles.UseTextForAccessibility, false);
                        
                        base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
-#endif
 
                        canvas_width = ClientSize.Width;
                        canvas_height = ClientSize.Height;
@@ -179,12 +175,10 @@ namespace System.Windows.Forms
                        return s.ToUpper();
                }
 
-#if NET_2_0
                internal override Size GetPreferredSizeCore (Size proposedSize)
                {
                        return new Size (Width, Height);
                }
-#endif
 
                internal override void HandleClick (int clicks, MouseEventArgs me)
                {
@@ -228,21 +222,13 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
-#endif
                [DefaultValue(true)]
                [Localizable(true)]
                [RefreshProperties(RefreshProperties.Repaint)]
                [MWFCategory("Behavior")]
-               public
-#if NET_2_0
-               override
-#else
-               virtual
-#endif
-               bool AutoSize {
+               public override bool AutoSize {
                        get {
                                return auto_size;
                        }
@@ -251,13 +237,10 @@ namespace System.Windows.Forms
                                if (value != auto_size) {
                                        auto_size = value;
                                        if (auto_size) {
-                                               if (PreferredHeight != ClientSize.Height) {
-                                                       ClientSize = new Size(ClientSize.Width, PreferredHeight);
+                                               if (PreferredHeight != Height) {
+                                                       Height = PreferredHeight;
                                                }
                                        }
-#if NET_1_1
-                                       OnAutoSizeChanged(EventArgs.Empty);
-#endif
                                }
                        }
                }
@@ -342,9 +325,7 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                [MergableProperty (false)]
-#endif
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [Editor("System.Windows.Forms.Design.StringArrayEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
                [Localizable(true)]
@@ -485,20 +466,20 @@ namespace System.Windows.Forms
                [Browsable(false)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [EditorBrowsable(EditorBrowsableState.Advanced)]
+               // This returns the preferred outer height, not the client height.
                public int PreferredHeight {
                        get {
+                               int clientDelta = Height - ClientSize.Height;
                                if (BorderStyle != BorderStyle.None)
-                                       return Font.Height + 7;
+                                       return Font.Height + 7 + clientDelta;
 
                                // usually in borderless mode the top margin is 0, but
                                // try to access it, in case it was set manually, as ToolStrip* controls do
-                               return Font.Height + TopMargin;
+                               return Font.Height + TopMargin + clientDelta;
                        }
                }
 
-#if NET_2_0
                [RefreshProperties (RefreshProperties.Repaint)] 
-#endif
                [DefaultValue(false)]
                [MWFCategory("Behavior")]
                public bool ReadOnly {
@@ -509,14 +490,12 @@ namespace System.Windows.Forms
                        set {
                                if (value != read_only) {
                                        read_only = value;
-#if NET_2_0
                                        if (!backcolor_set) {
                                                if (read_only)
                                                        background_color = SystemColors.Control;
                                                else
                                                        background_color = SystemColors.Window;
                                        }
-#endif
                                        OnReadOnlyChanged(EventArgs.Empty);
                                        Invalidate ();
                                }
@@ -529,14 +508,13 @@ namespace System.Windows.Forms
                        get {
                                string retval = document.GetSelection ();
 
-#if ONLY_1_1
-                               if (!IsHandleCreated && retval == string.Empty)
-                                       return null;
-#endif
                                return retval;
                        }
 
                        set {
+                               if (value == null)
+                                       value = String.Empty;
+
                                document.ReplaceSelection(CaseAdjust(value), false);
 
                                ScrollToCaret();
@@ -550,22 +528,13 @@ namespace System.Windows.Forms
                        get {
                                int res = document.SelectionLength ();
 
-#if !NET_2_0
-                               if (res == 0 && !IsHandleCreated)
-                                       res = -1;
-#endif
-
                                return res;
                        }
 
                        set {
                                if (value < 0) {
                                        string msg = String.Format ("'{0}' is not a valid value for 'SelectionLength'", value);
-#if NET_2_0
                                        throw new ArgumentOutOfRangeException ("SelectionLength", msg);
-#else
-                                       throw new ArgumentException (msg);
-#endif
                                }
 
                                document.InvalidateSelectionArea ();
@@ -599,11 +568,7 @@ namespace System.Windows.Forms
                        set {
                                if (value < 0) {
                                        string msg = String.Format ("'{0}' is not a valid value for 'SelectionStart'", value);
-#if NET_2_0
                                        throw new ArgumentOutOfRangeException ("SelectionStart", msg);
-#else
-                                       throw new ArgumentException (msg);
-#endif
                                }
 
                                // If SelectionStart has been used, we don't highlight on focus
@@ -620,7 +585,6 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                [DefaultValue (true)]
                public virtual bool ShortcutsEnabled {
                        get { return shortcuts_enabled; }
@@ -629,7 +593,6 @@ namespace System.Windows.Forms
 
                [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
                         "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
-#endif
                [Localizable(true)]
                public override string Text {
                        get {
@@ -701,7 +664,6 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public override ImageLayout BackgroundImageLayout {
@@ -720,11 +682,9 @@ namespace System.Windows.Forms
                protected override Cursor DefaultCursor {
                        get { return Cursors.IBeam; }
                }
-#endif
                #endregion      // Public Instance Properties
 
                #region Protected Instance Properties
-#if NET_2_0
                protected override bool CanEnableIme {
                        get {
                                if (ReadOnly || password_char != '\0')
@@ -733,7 +693,6 @@ namespace System.Windows.Forms
                                return true;
                        }
                }
-#endif
 
                protected override CreateParams CreateParams {
                        get {
@@ -747,14 +706,12 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                // Currently our double buffering breaks our scrolling, so don't let people enable this
                [EditorBrowsable (EditorBrowsableState.Never)]
                protected override bool DoubleBuffered {
                        get { return false; }
                        set { }
                }
-#endif
 
                #endregion      // Protected Instance Properties
 
@@ -882,7 +839,6 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                public void DeselectAll ()
                {
                        SelectionLength = 0;
@@ -974,7 +930,6 @@ namespace System.Windows.Forms
                {
                        return document.LineTagToCharIndex (document.caret.line, 0);
                }
-#endif
                #endregion      // Public Instance Methods
 
                #region Protected Instance Methods
@@ -1028,15 +983,6 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
-#if ONLY_1_1
-               protected virtual void OnAutoSizeChanged (EventArgs e)
-               {
-                       EventHandler eh = (EventHandler)(Events [AutoSizeChangedEvent]);
-                       if (eh != null)
-                               eh (this, e);
-               }
-#endif
-
                protected virtual void OnBorderStyleChanged (EventArgs e)
                {
                        EventHandler eh = (EventHandler)(Events [BorderStyleChangedEvent]);
@@ -1049,7 +995,7 @@ namespace System.Windows.Forms
                        base.OnFontChanged (e);
 
                        if (auto_size && !document.multiline) {
-                               if (PreferredHeight != ClientSize.Height) {
+                               if (PreferredHeight != Height) {
                                        Height = PreferredHeight;
                                }
                        }
@@ -1087,12 +1033,10 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
-#if NET_2_0
                protected override void OnPaddingChanged (EventArgs e)
                {
                        base.OnPaddingChanged (e);
                }
-#endif
 
                protected virtual void OnReadOnlyChanged (EventArgs e)
                {
@@ -1101,12 +1045,10 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
-#if NET_2_0
                protected override bool ProcessCmdKey (ref Message msg, Keys keyData)
                {
                        return base.ProcessCmdKey (ref msg, keyData);
                }
-#endif
                protected override bool ProcessDialogKey (Keys keyData)
                {
                        // The user can use Ctrl-Tab or Ctrl-Shift-Tab to move control focus
@@ -1588,9 +1530,7 @@ namespace System.Windows.Forms
 
                                        if (document.Length < max_length) {
                                                document.InsertCharAtCaret(c, true);
-#if NET_2_0
                                                OnTextUpdate ();
-#endif
                                                CaretMoved (this, null);
                                                Modified = true;
                                                OnTextChanged(EventArgs.Empty);
@@ -1646,15 +1586,9 @@ namespace System.Windows.Forms
                        remove { Events.RemoveHandler (AcceptsTabChangedEvent, value); }
                }
 
-#if NET_2_0
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
-#endif
-               public
-#if NET_2_0
-               new
-#endif
-               event EventHandler AutoSizeChanged {
+               public new event EventHandler AutoSizeChanged {
                        add { Events.AddHandler (AutoSizeChangedEvent, value); }
                        remove { Events.RemoveHandler (AutoSizeChangedEvent, value); }
                }
@@ -1701,7 +1635,6 @@ namespace System.Windows.Forms
                        remove { base.BackgroundImageChanged -= value; }
                }
 
-#if NET_2_0
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new event EventHandler BackgroundImageLayoutChanged {
@@ -1726,19 +1659,19 @@ namespace System.Windows.Forms
 
                [Browsable (true)]
                [EditorBrowsable (EditorBrowsableState.Always)]
-#else
-               [Browsable(false)]
-               [EditorBrowsable(EditorBrowsableState.Advanced)]
-#endif
                public new event EventHandler Click {
                        add { base.Click += value; }
                        remove { base.Click -= value; }
                }
 
                // XXX should this not manipulate base.Paint?
+#pragma warning disable 0067
+               [MonoTODO]
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
                public new event PaintEventHandler Paint;
+#pragma warning restore 0067
+
                #endregion      // Events
 
                #region Private Methods
@@ -1835,8 +1768,8 @@ namespace System.Windows.Forms
                {
                        if (!richtext) {
                                if (!document.multiline) {
-                                       if (PreferredHeight != ClientSize.Height) {
-                                               ClientSize = new Size (ClientSize.Width, PreferredHeight);
+                                       if (PreferredHeight != Height) {
+                                               Height = PreferredHeight;
                                        }
                                }
                        }
@@ -2297,11 +2230,7 @@ namespace System.Windows.Forms
                        }
 
                        if (found_link == false) {
-#if NET_2_0
                                XplatUI.SetCursor (window.Handle, DefaultCursor.handle);
-#else
-                               XplatUI.SetCursor(window.Handle, Cursors.IBeam.handle);
-#endif
                                current_link = null;
                        }
                }
@@ -2532,7 +2461,6 @@ namespace System.Windows.Forms
                }
                #endregion
 
-#if NET_2_0
                // This is called just before OnTextChanged is called.
                internal virtual void OnTextUpdate ()
                {
@@ -2558,6 +2486,5 @@ namespace System.Windows.Forms
                {
                        base.OnMouseUp (mevent);
                }
-#endif
        }
 }