2007-01-07 Jonathan Pobst <monkey@jpobst.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / StatusBarPanel.cs
index 8ac0edce5545f8ae749c42f1384e9919c019f94d..a8610cc856718cee63b7ea549e7c553bec9a89aa 100644 (file)
@@ -37,6 +37,7 @@ namespace System.Windows.Forms {
                #region Local Variables
                private StatusBar parent;
 
+               private bool initializing;
                private string text = String.Empty;
                private string tool_tip_text = String.Empty;
 
@@ -44,9 +45,10 @@ 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 min_width = 10;
+               internal int X;
                #endregion      // Local Variables
 
                #region Constructors
@@ -59,27 +61,39 @@ namespace System.Windows.Forms {
                [Localizable(true)]
                public HorizontalAlignment Alignment {
                        get { return alignment; }
-                       set { alignment = value; }
+                       set { 
+                               alignment = value; 
+                               InvalidateContents ();
+                       }
                }
 
                [DefaultValue(StatusBarPanelAutoSize.None)]
                public StatusBarPanelAutoSize AutoSize {
                        get { return auto_size; }
-                       set { auto_size = value; }
+                       set { 
+                               auto_size = value; 
+                               Invalidate ();
+                       }
                }
 
                [DefaultValue(StatusBarPanelBorderStyle.Sunken)]
                [DispId(-504)]
                public StatusBarPanelBorderStyle BorderStyle {
                        get { return border_style; }
-                       set { border_style = value; }
+                       set { 
+                               border_style = value; 
+                               Invalidate ();
+                       }
                }
 
                [DefaultValue(null)]
                [Localizable(true)]
                public Icon Icon {
                        get { return icon; }
-                       set { icon = value; }
+                       set { 
+                               icon = value; 
+                               InvalidateContents ();
+                       }
                }
 
                [DefaultValue(10)]
@@ -87,14 +101,20 @@ 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 (value < 0)
                                        throw new ArgumentException ("value");
                                min_width = value;
+                               if (min_width > width)
+                                       width = min_width;
+                               
+                               Invalidate ();
                        }
                }
                
@@ -105,21 +125,33 @@ namespace System.Windows.Forms {
                        set {
                                if (value < 0)
                                        throw new ArgumentException ("value");
-                               width = value;
+
+                               if (initializing)
+                                       width = value;
+                               else
+                                       SetWidth(value);
+                               
+                               Invalidate ();
                        }
                }
                
                [DefaultValue(StatusBarPanelStyle.Text)]
                public StatusBarPanelStyle Style {
                        get { return style; }
-                       set { style = value; }
+                       set { 
+                               style = value; 
+                               Invalidate ();
+                       }
                }
 
                [DefaultValue("")]
                [Localizable(true)]
                public string Text {
                        get { return text; }
-                       set { text = value; }
+                       set { 
+                               text = value; 
+                               InvalidateContents ();
+                       }
                }
 
                [DefaultValue("")]
@@ -134,29 +166,55 @@ namespace System.Windows.Forms {
                        get { return parent; }
                }
 
+               private void Invalidate ()
+               {
+                       if (parent == null)
+                               return;
+                       parent.UpdatePanel (this);
+               }
+
+               private void InvalidateContents ()
+               {
+                       if (parent == null)
+                               return;
+                       parent.UpdatePanelContents (this);
+               }
+
                internal void SetParent (StatusBar parent)
                {
                        this.parent = parent;
                }
 
+               internal void SetWidth (int width)
+               {
+                       this.width = width;
+                       if (min_width > this.width)
+                               this.width = min_width;
+               }
+
                public override string ToString ()
                {
                        return "StatusBarPanel: {" + Text +"}";
                }
 
-               [MonoTODO]
                protected override void Dispose (bool disposing)
                {
                }
 
-               [MonoTODO]
-               public virtual void BeginInit()
+               public void BeginInit ()
                {
+                       initializing = true;
                }
 
-               [MonoTODO]
-               public virtual void EndInit()
+               public void EndInit ()
                {
+                       if (!initializing)
+                               return;
+                       
+                       if (min_width > width)
+                               width = min_width;
+                       
+                       initializing = false;
                }
        }
 }