Assign values to base class.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ToolStripControlHost.cs
index 94cd394d1603716de788335ea2a3fc83a196d7c7..1e34d8d2007289758c3e5bba989e7e199db08d9d 100644 (file)
@@ -25,7 +25,7 @@
 // Authors:
 //     Jonathan Pobst (monkey@jpobst.com)
 //
-#if NET_2_0
+
 using System.Drawing;
 using System.ComponentModel;
 
@@ -43,8 +43,12 @@ namespace System.Windows.Forms
                        if (c == null)
                                throw new ArgumentNullException ("c");
 
+                       this.RightToLeft = RightToLeft.No;
                        this.control = c;
                        this.control_align = ContentAlignment.MiddleCenter;
+                       this.control.TabStop = false;
+                       this.control.Resize += ControlResizeHandler;
+                       this.Size = DefaultSize;
                        this.OnSubscribeControlEvents (this.control);
                }
 
@@ -96,10 +100,15 @@ namespace System.Windows.Forms
                public ContentAlignment ControlAlign {
                        get { return this.control_align; }
                        set {
-                               if (!Enum.IsDefined (typeof (ContentAlignment), value))
-                                       throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
-
-                               this.control_align = value;
+                               if (control_align != value) {
+                                       if (!Enum.IsDefined (typeof (ContentAlignment), value))
+                                               throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value));
+
+                                       this.control_align = value;
+                                       
+                                       if (control != null)
+                                               control.Bounds = AlignInRectangle (this.Bounds, control.Size, this.control_align);
+                               }
                        }
                }
 
@@ -175,6 +184,19 @@ namespace System.Windows.Forms
                        set { base.ImageTransparentColor = value; }
                }
 
+               public override RightToLeft RightToLeft {
+                       get { return base.RightToLeft; }
+                       set { base.RightToLeft = value; }
+               }
+
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               public new bool RightToLeftAutoMirrorImage {
+                       get { return base.RightToLeftAutoMirrorImage; }
+                       set { base.RightToLeftAutoMirrorImage = value; }
+               }
+               
                public override bool Selected {
                        get { return base.Selected; }
                }
@@ -186,15 +208,14 @@ namespace System.Windows.Forms
                        }
                }
 
-               public override Size Size
-               {
-                       get { return control.Size; }
+               public override Size Size {
+                       get { return base.Size; }
                        set { control.Size = value; base.Size = value;  if (this.Owner != null) this.Owner.PerformLayout (); }
                }
                
                [DefaultValue ("")]
                public override string Text {
-                       get { return base.Text; }
+                       get { return control.Text; }
                        set {
                                base.Text = value;
                                control.Text = value;
@@ -208,6 +229,14 @@ namespace System.Windows.Forms
                        set { base.TextAlign = value; }
                }
 
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [DefaultValue (ToolStripTextDirection.Horizontal)]
+               public override ToolStripTextDirection TextDirection {
+                       get { return base.TextDirection; }
+                       set { base.TextDirection = value; }
+               }
+
                [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Never)]
                public new TextImageRelation TextImageRelation {
@@ -222,7 +251,7 @@ namespace System.Windows.Forms
                                if (control == null)
                                        return new Size (23, 23);
 
-                               return control.GetPreferredSize (Size.Empty);
+                               return control.Size;
                        }
                }
                #endregion
@@ -236,7 +265,7 @@ namespace System.Windows.Forms
 
                public override Size GetPreferredSize (Size constrainingSize)
                {
-                       return control.Size;
+                       return control.GetPreferredSize (constrainingSize);
                }
 
                [EditorBrowsable (EditorBrowsableState.Never)]
@@ -262,13 +291,16 @@ namespace System.Windows.Forms
                protected override void Dispose (bool disposing)
                {
                        base.Dispose (disposing);
-                       
-                       if (!control.IsDisposed)
+
+                       if (control.Created && !control.IsDisposed)
                                control.Dispose ();
                }
                
                protected override void OnBoundsChanged ()
                {
+                       if (control != null)
+                               control.Bounds = AlignInRectangle (this.Bounds, control.Size, this.control_align);
+
                        base.OnBoundsChanged ();
                }
                
@@ -285,9 +317,17 @@ namespace System.Windows.Forms
                        if (eh != null)
                                eh (this, e);
                }
+
+               void ControlResizeHandler (object obj, EventArgs args)
+               {
+                       OnHostedControlResize (args);
+               }
                
                protected virtual void OnHostedControlResize (EventArgs e)
                {
+                       // Since the control size has been just adjusted, only update the location
+                       if (control != null)
+                               control.Location = AlignInRectangle (this.Bounds, control.Size, this.control_align).Location;
                }
                
                protected virtual void OnKeyDown (KeyEventArgs e)
@@ -380,10 +420,23 @@ namespace System.Windows.Forms
                                eh (this, e);
                }
 
+               protected internal override bool ProcessCmdKey (ref Message m, Keys keyData)
+               {
+                       return base.ProcessCmdKey (ref m, keyData);
+               }
+               
+               protected internal override bool ProcessDialogKey (Keys keyData)
+               {
+                       return base.ProcessDialogKey (keyData);
+               }
+               
                protected override void SetVisibleCore (bool visible)
                {
                        base.SetVisibleCore (visible);
                        this.control.Visible = visible;
+
+                       if (control != null)
+                               control.Bounds = AlignInRectangle (this.Bounds, control.Size, this.control_align);
                }
                #endregion
 
@@ -456,6 +509,16 @@ namespace System.Windows.Forms
                #endregion
 
                #region Private Methods
+               internal override ToolStripTextDirection DefaultTextDirection { get { return ToolStripTextDirection.Horizontal; } }
+
+               internal override void Dismiss (ToolStripDropDownCloseReason reason)
+               {
+                       if (this.Selected)
+                               this.Parent.Focus ();
+                               
+                       base.Dismiss (reason);
+               }
+               
                private void HandleEnter (object sender, EventArgs e)
                {
                        this.OnEnter (e);
@@ -500,7 +563,14 @@ namespace System.Windows.Forms
                {
                        this.OnValidating (e);
                }
+
+               internal override bool InternalVisible {
+                       get { return base.InternalVisible; }
+                       set { 
+                               Control.Visible = value;
+                               base.InternalVisible = value;
+                       }
+               }
                #endregion
        }
 }
-#endif