// Authors:
// Jonathan Pobst (monkey@jpobst.com)
//
-#if NET_2_0
+
using System.Drawing;
using System.ComponentModel;
private Control control;
private ContentAlignment control_align;
private bool double_click_enabled;
- private ContentAlignment image_align;
- private ToolStripItemImageScaling image_scaling;
- private Color image_transparent_color;
- private ContentAlignment text_align;
- private TextImageRelation text_image_relation;
#region Public Constructors
public ToolStripControlHost (Control c) : base ()
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);
}
public ToolStripControlHost (Control c, string name) : this (c)
{
- this.control.name = name;
+ base.Name = name;
}
#endregion
#region Public Properties
public override Color BackColor {
- get { return base.BackColor; }
- set {
- base.BackColor = value;
- control.BackColor = value;
+ get { return control.BackColor; }
+ set { control.BackColor = value;
}
}
+ [Localizable (true)]
+ [DefaultValue (null)]
+ public override Image BackgroundImage {
+ get { return base.BackgroundImage; }
+ set { base.BackgroundImage = value; }
+ }
+
+ [Localizable (true)]
+ [DefaultValue (ImageLayout.Tile)]
+ public override ImageLayout BackgroundImageLayout {
+ get { return base.BackgroundImageLayout; }
+ set { base.BackgroundImageLayout = value; }
+ }
+
public override bool CanSelect {
get { return control.CanSelect; }
}
+ [DefaultValue (true)]
+ public bool CausesValidation {
+ get { return control.CausesValidation; }
+ set { control.CausesValidation = value; }
+ }
+
+ [Browsable (false)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public Control Control {
get { return this.control; }
}
+ [Browsable (false)]
+ [DefaultValue (ContentAlignment.MiddleCenter)]
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);
+ }
}
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public override ToolStripItemDisplayStyle DisplayStyle {
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public new ToolStripItemDisplayStyle DisplayStyle {
get { return base.DisplayStyle; }
set { base.DisplayStyle = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public bool DoubleClickEnabled {
+ [DefaultValue (false)]
+ public new bool DoubleClickEnabled {
get { return this.double_click_enabled; }
set { this.double_click_enabled = value; }
}
}
}
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Always)]
public virtual bool Focused {
get { return control.Focused; }
}
public override Font Font {
- get { return base.Font; }
- set {
- base.Font = value;
- control.Font = value;
- }
+ get { return control.Font; }
+ set { control.Font = value; }
}
public override Color ForeColor {
- get { return base.ForeColor; }
- set {
- base.ForeColor = value;
- control.ForeColor = value;
- }
+ get { return control.ForeColor; }
+ set { control.ForeColor = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
public override Image Image {
get { return base.Image; }
set { base.Image = value; }
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public ContentAlignment ImageAlign {
- get { return this.image_align; }
- set { this.image_align = value; }
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public new ContentAlignment ImageAlign {
+ get { return base.ImageAlign; }
+ set { base.ImageAlign = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public ToolStripItemImageScaling ImageScaling {
- get { return this.image_scaling; }
- set { this.image_scaling = value; }
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public new ToolStripItemImageScaling ImageScaling {
+ get { return base.ImageScaling; }
+ set { base.ImageScaling = value; }
}
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public Color ImageTransparentColor {
- get { return this.image_transparent_color; }
- set { this.image_transparent_color = value; }
+ [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+ public new Color ImageTransparentColor {
+ get { return base.ImageTransparentColor; }
+ 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; }
}
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
public override ISite Site {
- get { return base.Site; }
- set {
- base.Site = value;
- control.Site = value;
+ get { return control.Site; }
+ set { control.Site = value;
}
}
+ 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;
[Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
- public ContentAlignment TextAlign {
- get { return this.text_align; }
- set { this.text_align = value; }
+ public new ContentAlignment TextAlign {
+ get { return base.TextAlign; }
+ 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 TextImageRelation TextImageRelation {
- get { return this.text_image_relation; }
- set { this.text_image_relation = value; }
+ public new TextImageRelation TextImageRelation {
+ get { return base.TextImageRelation; }
+ set { base.TextImageRelation = value; }
}
#endregion
if (control == null)
return new Size (23, 23);
- return control.GetPreferredSize (Size.Empty);
+ return control.Size;
}
}
#endregion
#region Public Methods
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
public void Focus ()
{
control.Focus ();
public override Size GetPreferredSize (Size constrainingSize)
{
- return this.Size;
+ return control.GetPreferredSize (constrainingSize);
}
- [Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override void ResetBackColor ()
{
base.ResetBackColor ();
}
- [Browsable (false)]
[EditorBrowsable (EditorBrowsableState.Never)]
public override void ResetForeColor ()
{
#endregion
#region Protected Methods
- protected override void OnBoundsChanged (EventArgs e)
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ protected override AccessibleObject CreateAccessibilityInstance ()
{
- base.OnBoundsChanged (e);
+ return control.AccessibilityObject;
+ }
- if (this.Parent != null) {
- control.Size = this.Size;
- OnLayout (new LayoutEventArgs (null, string.Empty));
- }
+ protected override void Dispose (bool disposing)
+ {
+ base.Dispose (disposing);
+
+ 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 ();
}
protected virtual void OnEnter (EventArgs e)
{
- if (Enter != null) Enter (this, e);
+ EventHandler eh = (EventHandler)(Events [EnterEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnGotFocus (EventArgs e)
{
- if (GotFocus != null) GotFocus (this, e);
+ EventHandler eh = (EventHandler)(Events [GotFocusEvent]);
+ 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)
{
- if (KeyDown != null) KeyDown (this, e);
+ KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnKeyPress (KeyPressEventArgs e)
{
- if (KeyPress != null) KeyPress (this, e);
+ KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnKeyUp (KeyEventArgs e)
{
- if (KeyUp != null) KeyUp (this, e);
+ KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected override void OnLayout (LayoutEventArgs e)
protected virtual void OnLeave (EventArgs e)
{
- if (Leave != null) Leave (this, e);
+ EventHandler eh = (EventHandler)(Events [LeaveEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnLostFocus (EventArgs e)
{
- if (LostFocus != null) LostFocus (this, e);
+ EventHandler eh = (EventHandler)(Events [LostFocusEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected override void OnPaint (PaintEventArgs e)
protected virtual void OnValidated (EventArgs e)
{
- if (Validated != null) Validated (this, e);
+ EventHandler eh = (EventHandler)(Events [ValidatedEvent]);
+ if (eh != null)
+ eh (this, e);
}
protected virtual void OnValidating (CancelEventArgs e)
{
- if (Validating != null) Validating (this, e);
+ CancelEventHandler eh = (CancelEventHandler)(Events [ValidatingEvent]);
+ if (eh != null)
+ 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
#region Public Events
- public event EventHandler DisplayStyleChanged;
- public event EventHandler Enter;
- public event EventHandler GotFocus;
- public event KeyEventHandler KeyDown;
- public event KeyPressEventHandler KeyPress;
- public event KeyEventHandler KeyUp;
- public event EventHandler Leave;
- public event EventHandler LostFocus;
- public event EventHandler Validated;
- public event CancelEventHandler Validating;
+ static object EnterEvent = new object ();
+ static object GotFocusEvent = new object ();
+ static object KeyDownEvent = new object ();
+ static object KeyPressEvent = new object ();
+ static object KeyUpEvent = new object ();
+ static object LeaveEvent = new object ();
+ static object LostFocusEvent = new object ();
+ static object ValidatedEvent = new object ();
+ static object ValidatingEvent = new object ();
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Never)]
+ public new event EventHandler DisplayStyleChanged {
+ add { base.DisplayStyleChanged += value; }
+ remove { base.DisplayStyleChanged -= value; }
+ }
+
+ public event EventHandler Enter {
+ add { Events.AddHandler (EnterEvent, value); }
+ remove { Events.RemoveHandler (EnterEvent, value); }
+ }
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ public event EventHandler GotFocus {
+ add { Events.AddHandler (GotFocusEvent, value); }
+ remove { Events.RemoveHandler (GotFocusEvent, value); }
+ }
+
+ public event KeyEventHandler KeyDown {
+ add { Events.AddHandler (KeyDownEvent, value); }
+ remove { Events.RemoveHandler (KeyDownEvent, value); }
+ }
+
+ public event KeyPressEventHandler KeyPress {
+ add { Events.AddHandler (KeyPressEvent, value); }
+ remove { Events.RemoveHandler (KeyPressEvent, value); }
+ }
+
+ public event KeyEventHandler KeyUp {
+ add { Events.AddHandler (KeyUpEvent, value); }
+ remove { Events.RemoveHandler (KeyUpEvent, value); }
+ }
+
+ public event EventHandler Leave {
+ add { Events.AddHandler (LeaveEvent, value); }
+ remove { Events.RemoveHandler (LeaveEvent, value); }
+ }
+
+ [Browsable (false)]
+ [EditorBrowsable (EditorBrowsableState.Advanced)]
+ public event EventHandler LostFocus {
+ add { Events.AddHandler (LostFocusEvent, value); }
+ remove { Events.RemoveHandler (LostFocusEvent, value); }
+ }
+
+ public event EventHandler Validated {
+ add { Events.AddHandler (ValidatedEvent, value); }
+ remove { Events.RemoveHandler (ValidatedEvent, value); }
+ }
+
+ public event CancelEventHandler Validating {
+ add { Events.AddHandler (ValidatingEvent, value); }
+ remove { Events.RemoveHandler (ValidatingEvent, value); }
+ }
#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);
{
this.OnValidating (e);
}
+
+ internal override bool InternalVisible {
+ get { return base.InternalVisible; }
+ set {
+ Control.Visible = value;
+ base.InternalVisible = value;
+ }
+ }
#endregion
}
}
-#endif
\ No newline at end of file