Xamarin-4959: Fix copy of clipboard data after app exits
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ProgressBar.cs
index b8e9f2adde6d7b6a4c1ad410b4ecd0e9f40df3e5..a7f5cfc993b19288ce9ab3222420971c2a024523 100644 (file)
@@ -34,16 +34,10 @@ using System.Runtime.InteropServices;
 namespace System.Windows.Forms
 {
        [DefaultProperty ("Value")]
-#if NET_2_0
        [DefaultBindingProperty ("Value")]
        [ClassInterface (ClassInterfaceType.AutoDispatch)]
        [ComVisible (true)]
-#endif
-       public
-#if !NET_2_0
-       sealed
-#endif
-       class ProgressBar : Control
+       public class ProgressBar : Control
        {
                #region Local Variables
                private int maximum;
@@ -52,29 +46,14 @@ namespace System.Windows.Forms
                internal int val;
                internal DateTime start = DateTime.Now;
                internal Rectangle client_area = new Rectangle ();
-#if NET_2_0
                internal ProgressBarStyle style;
                Timer marquee_timer;
                bool right_to_left_layout;
-#endif
-
-#if NET_2_0
                private static readonly Color defaultForeColor = SystemColors.Highlight;
-#endif
                #endregion      // Local Variables
 
                #region events
-
                static object RightToLeftLayoutChangedEvent = new object ();
-                       
-#if ONLY_1_1
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public new event EventHandler BackColorChanged {
-                       add { base.BackColorChanged += value; }
-                       remove { base.BackColorChanged -= value; }
-               }
-#endif
                
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
@@ -83,15 +62,13 @@ namespace System.Windows.Forms
                        remove { base.BackgroundImageChanged -= value; }
                }
                
-#if NET_2_0
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
-               public event EventHandler BackgroundImageLayoutChanged {
+               public new event EventHandler BackgroundImageLayoutChanged {
                        add     { base.BackgroundImageLayoutChanged += value; }
                        remove { base.BackgroundImageLayoutChanged -= value; }
                }
-#endif
-                       
+               
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new event EventHandler CausesValidationChanged {
@@ -120,15 +97,6 @@ namespace System.Windows.Forms
                        remove { base.FontChanged -= value; }
                }
                
-#if ONLY_1_1
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public new event EventHandler ForeColorChanged {
-                       add { base.ForeColorChanged += value; }
-                       remove { base.ForeColorChanged -= value; }
-               }
-#endif
-               
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new event EventHandler ImeModeChanged {
@@ -163,23 +131,21 @@ namespace System.Windows.Forms
                        add { base.Leave += value; }
                        remove { base.Leave -= value; }
                }
-
-#if NET_2_0
+               
                [EditorBrowsable(EditorBrowsableState.Never)]
                [Browsable(false)]
-               public event MouseEventHandler MouseDoubleClick {
+               public new event MouseEventHandler MouseDoubleClick {
                        add { base.MouseDoubleClick += value; }
                        remove { base.MouseDoubleClick -= value; }
                }
-                       
+               
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
-               public event EventHandler PaddingChanged {
+               public new event EventHandler PaddingChanged {
                        add { base.PaddingChanged += value; }
                        remove { base.PaddingChanged -= value; }
                }
-#endif
-                       
+               
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new event PaintEventHandler Paint {
@@ -187,20 +153,10 @@ namespace System.Windows.Forms
                        remove { base.Paint -= value; }
                }
                
-#if ONLY_1_1
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public new event EventHandler RightToLeftChanged {
-                       add { base.RightToLeftChanged += value; }
-                       remove { base.RightToLeftChanged -= value; }
-               }
-#endif
-#if NET_2_0
-               public new event EventHandler RightToLeftLayoutChanged {
+               public event EventHandler RightToLeftLayoutChanged {
                        add { Events.AddHandler (RightToLeftLayoutChangedEvent, value); }
                        remove { Events.RemoveHandler (RightToLeftLayoutChangedEvent, value); }
                }
-#endif
                
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
@@ -230,15 +186,13 @@ namespace System.Windows.Forms
                        SetStyle (ControlStyles.UserPaint | 
                                ControlStyles.Selectable | 
                                ControlStyles.ResizeRedraw | 
-                               ControlStyles.Opaque
-#if NET_2_0
-                               | ControlStyles.UseTextForAccessibility
-#endif
+                               ControlStyles.Opaque |
+                               ControlStyles.UseTextForAccessibility
                                , false);
 
-#if NET_2_0
+                       force_double_buffer = true;
+                       
                        ForeColor = defaultForeColor;
-#endif
                }
                #endregion      // Public Constructors
 
@@ -254,18 +208,6 @@ namespace System.Windows.Forms
                        }
                }
 
-#if ONLY_1_1
-               // Setting this property in MS .Net 1.1 does not have any visual effect and it
-               // does not fire a BackColorChanged event
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public override Color BackColor
-               {
-                       get { return base.BackColor; }
-                       set { base.BackColor = value; }
-               }
-#endif
-
                // Setting this property in MS .Net 1.1 does not have any visual effect and it
                // does not fire a BackgroundImageChanged event
                [Browsable (false)]
@@ -276,14 +218,13 @@ 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
+
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new bool CausesValidation
@@ -307,13 +248,12 @@ namespace System.Windows.Forms
                        get { return ThemeEngine.Current.ProgressBarDefaultSize; }
                }
 
-#if NET_2_0
                [EditorBrowsable(EditorBrowsableState.Never)]
                protected override bool DoubleBuffered {
                                get { return base.DoubleBuffered; }
                                set { base.DoubleBuffered = value; }
                }
-#endif
+
                // Setting this property in MS .Net 1.1 does not have any visual effect and it
                // does not fire a FontChanged event
                [Browsable (false)]
@@ -324,18 +264,6 @@ namespace System.Windows.Forms
                        set { base.Font = value; }
                }
 
-#if ONLY_1_1
-               // Setting this property in MS .Net 1.1 does not have any visual effect and it
-               // does not fire a FontChanged event
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public override Color ForeColor
-               {
-                       get { return base.ForeColor; }
-                       set { base.ForeColor = value; }
-               }
-#endif
-
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new ImeMode ImeMode
@@ -353,10 +281,12 @@ namespace System.Windows.Forms
                        }
                        set {
                                if (value < 0)
-                                       throw new ArgumentException(
+                                       throw new ArgumentOutOfRangeException ("Maximum", 
                                                string.Format("Value '{0}' must be greater than or equal to 0.", value ));
 
                                maximum = value;
+                               minimum = Math.Min (minimum, maximum);
+                               val = Math.Min (val, maximum);
                                Refresh ();
                        }
                }
@@ -369,26 +299,27 @@ namespace System.Windows.Forms
                        }
                        set {
                                if (value < 0)
-                                       throw new ArgumentException(
+                                       throw new ArgumentOutOfRangeException ("Minimum", 
                                                string.Format("Value '{0}' must be greater than or equal to 0.", value ));
 
                                minimum = value;
+                               maximum = Math.Max (maximum, minimum);
+                               val = Math.Max (val, minimum);
                                Refresh ();
                        }
                }
 
-#if NET_2_0
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                [Browsable(false)]
                [EditorBrowsable(EditorBrowsableState.Never)]
-               public Padding Padding {
+               public new Padding Padding {
                        get { return base.Padding; }
                        set { base.Padding = value; }
                }
                        
                [Localizable(true)]
                [DefaultValue(false)]
-               [MonoTODO ("Layout is currently always from left to right")]
+               [MonoTODO ("RTL is not supported")]
                public virtual bool RightToLeftLayout {
                                get { return right_to_left_layout;}
                                set     { 
@@ -398,17 +329,6 @@ namespace System.Windows.Forms
                                        }
                                }               
                }
-#endif
-                       
-#if ONLY_1_1
-               [Browsable (false)]
-               [EditorBrowsable (EditorBrowsableState.Never)]
-               public override RightToLeft RightToLeft
-               {
-                       get { return base.RightToLeft; }
-                       set { base.RightToLeft = value; }
-               }
-#endif
 
                [DefaultValue (10)]
                public int Step
@@ -420,7 +340,6 @@ namespace System.Windows.Forms
                        }
                }
 
-#if NET_2_0
                [Browsable (true)]
                [DefaultValue (ProgressBarStyle.Blocks)]
                [EditorBrowsable (EditorBrowsableState.Always)]
@@ -430,18 +349,24 @@ namespace System.Windows.Forms
                        }
 
                        set {
-                               style = value;
-                               
-                               if (style == ProgressBarStyle.Marquee) {
-                                       if (marquee_timer == null) {
-                                               marquee_timer = new Timer ();
-                                               marquee_timer.Interval = 10;
-                                               marquee_timer.Tick += new EventHandler (marquee_timer_Tick);
-                                       }
-                                       marquee_timer.Start ();
-                               } else {
-                                       if (marquee_timer != null) {
-                                               marquee_timer.Stop ();
+                               if (value != ProgressBarStyle.Blocks && value != ProgressBarStyle.Continuous
+                                               && value != ProgressBarStyle.Marquee)
+                                       throw new InvalidEnumArgumentException ("value", unchecked((int)value), typeof (ProgressBarStyle));
+                               if (style != value) {
+                                       style = value;
+
+                                       if (style == ProgressBarStyle.Marquee) {
+                                               if (marquee_timer == null) {
+                                                       marquee_timer = new Timer ();
+                                                       marquee_timer.Interval = 10;
+                                                       marquee_timer.Tick += new EventHandler (marquee_timer_Tick);
+                                               }
+                                               marquee_timer.Start ();
+                                       } else {
+                                               if (marquee_timer != null) {
+                                                       marquee_timer.Stop ();
+                                               }
+                                               Refresh ();
                                        }
                                }
                        }
@@ -463,7 +388,6 @@ namespace System.Windows.Forms
                                marquee_animation_speed = value;
                        }
                }
-#endif
 
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
@@ -491,11 +415,7 @@ namespace System.Windows.Forms
                        }
                        set {
                                if (value < Minimum || value > Maximum)
-#if NET_2_0
                                        throw new ArgumentOutOfRangeException ("Value", string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
-#else
-                                       throw new ArgumentException(string.Format("'{0}' is not a valid value for 'Value'. 'Value' should be between 'Minimum' and 'Maximum'", value));
-#endif
                                val = value;
                                Refresh ();
                        }
@@ -513,6 +433,9 @@ namespace System.Windows.Forms
 
                public void Increment (int value)
                {
+                       if (Style == ProgressBarStyle.Marquee)
+                               throw new InvalidOperationException ("Increment should not be called if the style is Marquee.");
+
                        int newValue = Value + value;
 
                        if (newValue < Minimum)
@@ -532,7 +455,6 @@ namespace System.Windows.Forms
                        UpdateAreas ();
                }
 
-#if NET_2_0
                protected override void OnBackColorChanged (EventArgs e)
                {
                        base.OnBackColorChanged (e);
@@ -551,33 +473,29 @@ namespace System.Windows.Forms
                [EditorBrowsable(EditorBrowsableState.Advanced)]
                protected virtual void OnRightToLeftLayoutChanged(EventArgs e)
                {
-                               EventHandler eh = (EventHandler) Events [RightToLeftLayoutChangedEvent];
-                               if (eh != null)
-                                       eh (this, e);
+                       EventHandler eh = (EventHandler) Events [RightToLeftLayoutChangedEvent];
+                       if (eh != null)
+                               eh (this, e);
                }
-#endif
                        
                public void PerformStep ()
                {
-                       if (Value >= Maximum)
-                               return;
+                       if (Style == ProgressBarStyle.Marquee)
+                               throw new InvalidOperationException ("PerformStep should not be called if the style is Marquee.");
 
-                       Value = Maximum < Value + Step ? Maximum : Value + Step;
-                       Refresh ();     // FIXME - calculate delta and only expose that
+                       Increment (Step);
                }
 
-#if NET_2_0
                [EditorBrowsable (EditorBrowsableState.Never)]
                public override void ResetForeColor ()
                {
                        ForeColor = defaultForeColor;
                }
-#endif
 
                public override string ToString()
                {
                        return string.Format ("{0}, Minimum: {1}, Maximum: {2}, Value: {3}",
-                               GetType().FullName.ToString (),
+                               GetType().FullName,
                                Minimum.ToString (),
                                Maximum.ToString (),
                                Value.ToString () );