2007-03-12 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / StatusBarPanel.cs
index 8aa7f7ccd52e96fe6927479be872c86fcbcfe216..e1c5a10e7aa3aa5279e41821383ffe924b050a7b 100644 (file)
@@ -31,6 +31,9 @@ using System.ComponentModel.Design;
 using System.Runtime.InteropServices;
 
 namespace System.Windows.Forms {
+#if NET_2_0
+       [ToolboxItem (false)]
+#endif
        [DefaultProperty("Text")]
        [DesignTimeVisible(false)]
        public class StatusBarPanel : Component, ISupportInitialize {
@@ -45,11 +48,15 @@ namespace System.Windows.Forms {
                private HorizontalAlignment alignment = HorizontalAlignment.Left;
                private StatusBarPanelAutoSize auto_size = StatusBarPanelAutoSize.None;
                private StatusBarPanelBorderStyle border_style = StatusBarPanelBorderStyle.Sunken;
-               private StatusBarPanelStyle style;
+               private StatusBarPanelStyle style = StatusBarPanelStyle.Text;
                private int width = 100;
-               private int twidth = -1;
                private int min_width = 10;
                internal int X;
+               
+#if NET_2_0
+               private string name;
+               private object tag;
+#endif
                #endregion      // Local Variables
 
                #region Constructors
@@ -68,6 +75,9 @@ namespace System.Windows.Forms {
                        }
                }
 
+#if NET_2_0
+               [RefreshProperties (RefreshProperties.All)]
+#endif
                [DefaultValue(StatusBarPanelAutoSize.None)]
                public StatusBarPanelAutoSize AutoSize {
                        get { return auto_size; }
@@ -102,17 +112,40 @@ namespace System.Windows.Forms {
                [RefreshProperties(RefreshProperties.All)]
                public int MinWidth {
                        get {
-                               if (AutoSize == StatusBarPanelAutoSize.None)
-                                       return Width;
+                       /*
+                               MSDN says that when AutoSize = None then MinWidth is automatically
+                               set to Width, but neither v1.1 nor v2.0 behave that way.
+                       */
                                return min_width;
                        }
                        set {
+#if NET_2_0
+                               if (value < 0)
+                                       throw new ArgumentOutOfRangeException ("value");
+#else
                                if (value < 0)
                                        throw new ArgumentException ("value");
+#endif
                                min_width = value;
+                               if (min_width > width)
+                                       width = min_width;
+                               
                                Invalidate ();
                        }
                }
+#if NET_2_0
+               [Localizable (true)]
+               public string Name {
+                       get {
+                               if (name == null)
+                                       return string.Empty;
+                               return name;
+                       }
+                       set {
+                               name = value;
+                       }
+               }
+#endif
                
                [DefaultValue(100)]
                [Localizable(true)]
@@ -123,10 +156,10 @@ namespace System.Windows.Forms {
                                        throw new ArgumentException ("value");
 
                                if (initializing)
-                                       twidth = value;
-                               else
                                        width = value;
-                       
+                               else
+                                       SetWidth(value);
+                               
                                Invalidate ();
                        }
                }
@@ -139,6 +172,20 @@ namespace System.Windows.Forms {
                                Invalidate ();
                        }
                }
+#if NET_2_0
+               [TypeConverter (typeof (StringConverter))]
+               [Localizable (false)]
+               [Bindable (true)]
+               [DefaultValue (null)]
+               public object Tag {
+                       get {
+                               return tag;
+                       }
+                       set {
+                               tag = value;
+                       }
+               }
+#endif
 
                [DefaultValue("")]
                [Localizable(true)]
@@ -184,6 +231,8 @@ namespace System.Windows.Forms {
                internal void SetWidth (int width)
                {
                        this.width = width;
+                       if (min_width > this.width)
+                               this.width = min_width;
                }
 
                public override string ToString ()
@@ -202,11 +251,12 @@ namespace System.Windows.Forms {
 
                public void EndInit ()
                {
-                       if (!initializing || twidth == -1)
+                       if (!initializing)
                                return;
-
-                       width = twidth;
-                       twidth = -1;
+                       
+                       if (min_width > width)
+                               width = min_width;
+                       
                        initializing = false;
                }
        }