diff options
| author | MichaelTheShifter <[email protected]> | 2016-07-20 09:40:36 -0400 |
|---|---|---|
| committer | MichaelTheShifter <[email protected]> | 2016-07-20 09:40:36 -0400 |
| commit | d40fed5ce2bc806a91245adb18039634eac13ed0 (patch) | |
| tree | f1d7168aee6db109ac2c738ad18c9db667a6ba69 /source/ShiftUI/ToolStrip/ToolStripControlHost.cs | |
| parent | f1856e8ed30ed882229fd3fa2a4038122a5fb441 (diff) | |
| download | shiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.tar.gz shiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.tar.bz2 shiftos-c--d40fed5ce2bc806a91245adb18039634eac13ed0.zip | |
Move ShiftUI source code to ShiftOS
This'll be a lot easier to work on.
Diffstat (limited to 'source/ShiftUI/ToolStrip/ToolStripControlHost.cs')
| -rw-r--r-- | source/ShiftUI/ToolStrip/ToolStripControlHost.cs | 577 |
1 files changed, 577 insertions, 0 deletions
diff --git a/source/ShiftUI/ToolStrip/ToolStripControlHost.cs b/source/ShiftUI/ToolStrip/ToolStripControlHost.cs new file mode 100644 index 0000000..cf2aeb1 --- /dev/null +++ b/source/ShiftUI/ToolStrip/ToolStripControlHost.cs @@ -0,0 +1,577 @@ +// +// ToolStripWidgetHost.cs +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +// Copyright (c) 2006 Jonathan Pobst +// +// Authors: +// Jonathan Pobst ([email protected]) +// + +using System.Drawing; +using System.ComponentModel; +using System; + +namespace ShiftUI +{ + public class ToolStripWidgetHost : ToolStripItem + { + private Widget _Widget; + private ContentAlignment Widget_align; + private bool double_click_enabled; + + #region Public Constructors + public ToolStripWidgetHost (Widget c) : base () + { + if (c == null) + throw new ArgumentNullException ("c"); + + this.RightToLeft = RightToLeft.No; + this._Widget = c; + this._Widget.Alignment = ContentAlignment.MiddleCenter; + this._Widget.TabStop = false; + this._Widget.Resize += WidgetResizeHandler; + this.Size = DefaultSize; + this.OnSubscribeWidgetEvents (this.Widget); + } + + public ToolStripWidgetHost (Widget c, string name) : this (c) + { + base.Name = name; + } + #endregion + + #region Public Properties + public override Color BackColor { + get { return Widget.BackColor; } + set { Widget.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 Widget.CanSelect; } + } + + [DefaultValue (true)] + public bool CausesValidation { + get { return Widget.CausesValidation; } + set { Widget.CausesValidation = value; } + } + + [Browsable (false)] + //[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + public Widget Widget { + get { return this._Widget; } + } + + [Browsable (false)] + [DefaultValue (ContentAlignment.MiddleCenter)] + public ContentAlignment WidgetAlign { + get { return this.Widget_align; } + set { + if (Widget_align != value) { + if (!Enum.IsDefined (typeof (ContentAlignment), value)) + throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for ContentAlignment", value)); + + this.Widget_align = value; + + if (Widget != null) + Widget.Bounds = AlignInRectangle (this.Bounds, Widget.Size, this.Widget_align); + } + } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Never)] + //[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + public new ToolStripItemDisplayStyle DisplayStyle { + get { return base.DisplayStyle; } + set { base.DisplayStyle = value; } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Never)] + [DefaultValue (false)] + public new bool DoubleClickEnabled { + get { return this.double_click_enabled; } + set { this.double_click_enabled = value; } + } + + public override bool Enabled { + get { return base.Enabled; } + set { + base.Enabled = value; + Widget.Enabled = value; + } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Always)] + public virtual bool Focused { + get { return Widget.Focused; } + } + + public override Font Font { + get { return Widget.Font; } + set { Widget.Font = value; } + } + + public override Color ForeColor { + get { return Widget.ForeColor; } + set { Widget.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)] + //[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + public new ContentAlignment ImageAlign { + get { return base.ImageAlign; } + set { base.ImageAlign = value; } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Never)] + //[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)] + public new ToolStripItemImageScaling ImageScaling { + get { return base.ImageScaling; } + set { base.ImageScaling = value; } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Never)] + //[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 Widget.Site; } + set { Widget.Site = value; + } + } + + public override Size Size { + get { return base.Size; } + set { Widget.Size = value; base.Size = value; if (this.Owner != null) this.Owner.PerformLayout (); } + } + + [DefaultValue ("")] + public override string Text { + get { return Widget.Text; } + set { + base.Text = value; + Widget.Text = value; + } + } + + [Browsable (false)] + //[EditorBrowsable (EditorBrowsableState.Never)] + 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 new TextImageRelation TextImageRelation { + get { return base.TextImageRelation; } + set { base.TextImageRelation = value; } + } + #endregion + + #region Protected Properties + protected override Size DefaultSize { + get { + if (Widget == null) + return new Size (23, 23); + + return Widget.Size; + } + } + #endregion + + #region Public Methods + //[EditorBrowsable (EditorBrowsableState.Advanced)] + public void Focus () + { + Widget.Focus (); + } + + public override Size GetPreferredSize (Size constrainingSize) + { + return Widget.GetPreferredSize (constrainingSize); + } + + //[EditorBrowsable (EditorBrowsableState.Never)] + public override void ResetBackColor () + { + base.ResetBackColor (); + } + + //[EditorBrowsable (EditorBrowsableState.Never)] + public override void ResetForeColor () + { + base.ResetForeColor (); + } + #endregion + + #region Protected Methods + //[EditorBrowsable (EditorBrowsableState.Advanced)] + protected override AccessibleObject CreateAccessibilityInstance () + { + return Widget.AccessibilityObject; + } + + protected override void Dispose (bool disposing) + { + base.Dispose (disposing); + + if (Widget.Created && !Widget.IsDisposed) + Widget.Dispose (); + } + + protected override void OnBoundsChanged () + { + if (Widget != null) + Widget.Bounds = AlignInRectangle (this.Bounds, Widget.Size, this.Widget_align); + + base.OnBoundsChanged (); + } + + protected virtual void OnEnter (EventArgs e) + { + EventHandler eh = (EventHandler)(Events [EnterEvent]); + if (eh != null) + eh (this, e); + } + + protected virtual void OnGotFocus (EventArgs e) + { + EventHandler eh = (EventHandler)(Events [GotFocusEvent]); + if (eh != null) + eh (this, e); + } + + void WidgetResizeHandler (object obj, EventArgs args) + { + OnHostedWidgetResize (args); + } + + protected virtual void OnHostedWidgetResize (EventArgs e) + { + // Since the Widget size has been just adjusted, only update the location + if (Widget != null) + Widget.Location = AlignInRectangle (this.Bounds, Widget.Size, this.Widget_align).Location; + } + + protected virtual void OnKeyDown (KeyEventArgs e) + { + KeyEventHandler eh = (KeyEventHandler)(Events [KeyDownEvent]); + if (eh != null) + eh (this, e); + } + + protected virtual void OnKeyPress (KeyPressEventArgs e) + { + KeyPressEventHandler eh = (KeyPressEventHandler)(Events [KeyPressEvent]); + if (eh != null) + eh (this, e); + } + + protected virtual void OnKeyUp (KeyEventArgs e) + { + KeyEventHandler eh = (KeyEventHandler)(Events [KeyUpEvent]); + if (eh != null) + eh (this, e); + } + + protected override void OnLayout (LayoutEventArgs e) + { + base.OnLayout (e); + + if (Widget != null) + Widget.Bounds = AlignInRectangle (this.Bounds, Widget.Size, this.Widget_align); + } + + protected virtual void OnLeave (EventArgs e) + { + EventHandler eh = (EventHandler)(Events [LeaveEvent]); + if (eh != null) + eh (this, e); + } + + protected virtual void OnLostFocus (EventArgs e) + { + EventHandler eh = (EventHandler)(Events [LostFocusEvent]); + if (eh != null) + eh (this, e); + } + + protected override void OnPaint (PaintEventArgs e) + { + base.OnPaint (e); + } + + protected override void OnParentChanged (ToolStrip oldParent, ToolStrip newParent) + { + base.OnParentChanged (oldParent, newParent); + + if (oldParent != null) + oldParent.Widgets.Remove (Widget); + + if (newParent != null) + newParent.Widgets.Add (Widget); + } + + protected virtual void OnSubscribeWidgetEvents (Widget Widget) + { + this.Widget.Enter += new EventHandler (HandleEnter); + this.Widget.GotFocus += new EventHandler (HandleGotFocus); + this.Widget.KeyDown += new KeyEventHandler (HandleKeyDown); + this.Widget.KeyPress += new KeyPressEventHandler (HandleKeyPress); + this.Widget.KeyUp += new KeyEventHandler (HandleKeyUp); + this.Widget.Leave += new EventHandler (HandleLeave); + this.Widget.LostFocus += new EventHandler (HandleLostFocus); + this.Widget.Validated += new EventHandler (HandleValidated); + this.Widget.Validating += new CancelEventHandler (HandleValidating); + } + + protected virtual void OnUnsubscribeWidgetEvents (Widget Widget) + { + } + + protected virtual void OnValidated (EventArgs e) + { + EventHandler eh = (EventHandler)(Events [ValidatedEvent]); + if (eh != null) + eh (this, e); + } + + protected virtual void OnValidating (CancelEventArgs 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.Widget.Visible = visible; + + if (Widget != null) + Widget.Bounds = AlignInRectangle (this.Bounds, Widget.Size, this.Widget_align); + } + #endregion + + #region Public Events + 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); + } + + private void HandleGotFocus (object sender, EventArgs e) + { + this.OnGotFocus (e); + } + + private void HandleKeyDown (object sender, KeyEventArgs e) + { + this.OnKeyDown (e); + } + + private void HandleKeyPress (object sender, KeyPressEventArgs e) + { + this.OnKeyPress (e); + } + + private void HandleKeyUp (object sender, KeyEventArgs e) + { + this.OnKeyUp (e); + } + + private void HandleLeave (object sender, EventArgs e) + { + this.OnLeave (e); + } + + private void HandleLostFocus (object sender, EventArgs e) + { + this.OnLostFocus (e); + } + + private void HandleValidated (object sender, EventArgs e) + { + this.OnValidated (e); + } + + private void HandleValidating (object sender, CancelEventArgs e) + { + this.OnValidating (e); + } + + internal override bool InternalVisible { + get { return base.InternalVisible; } + set { + Widget.Visible = value; + base.InternalVisible = value; + } + } + #endregion + } +} |
