using System; using Gwen.Input; namespace Gwen.Control { /// /// Tab header. /// public class TabButton : Button { private Base m_Page; private TabControl m_Control; /// /// Indicates whether the tab is active. /// public bool IsActive { get { return m_Page != null && m_Page.IsVisible; } } // todo: remove public access public TabControl TabControl { get { return m_Control; } set { if (value == m_Control) return; if (m_Control != null) m_Control.OnLoseTab(this); m_Control = value; } } /// /// Interior of the tab. /// public Base Page { get { return m_Page; } set { m_Page = value; } } /// /// Determines whether the control should be clipped to its bounds while rendering. /// protected override bool ShouldClip { get { return false; } } /// /// Initializes a new instance of the class. /// /// Parent control. public TabButton(Base parent) : base(parent) { DragAndDrop_SetPackage(true, "TabButtonMove"); Alignment = Pos.Top | Pos.Left; TextPadding = new Padding(5, 3, 3, 3); Padding = Padding.Two; KeyboardInputEnabled = true; } public override void DragAndDrop_StartDragging(DragDrop.Package package, int x, int y) { IsHidden = true; } public override void DragAndDrop_EndDragging(bool success, int x, int y) { IsHidden = false; IsDepressed = false; } public override bool DragAndDrop_ShouldStartDrag() { return m_Control.AllowReorder; } /// /// Renders the control using specified skin. /// /// Skin to use. protected override void Render(Skin.Base skin) { skin.DrawTabButton(this, IsActive, m_Control.TabStrip.Dock); } /// /// Handler for Down Arrow keyboard event. /// /// Indicates whether the key was pressed or released. /// /// True if handled. /// protected override bool OnKeyDown(bool down) { OnKeyRight(down); return true; } /// /// Handler for Up Arrow keyboard event. /// /// Indicates whether the key was pressed or released. /// /// True if handled. /// protected override bool OnKeyUp(bool down) { OnKeyLeft(down); return true; } /// /// Handler for Right Arrow keyboard event. /// /// Indicates whether the key was pressed or released. /// /// True if handled. /// protected override bool OnKeyRight(bool down) { if (down) { var count = Parent.Children.Count; int me = Parent.Children.IndexOf(this); if (me + 1 < count) { var nextTab = Parent.Children[me + 1]; TabControl.OnTabPressed(nextTab); InputHandler.KeyboardFocus = nextTab; } } return true; } /// /// Handler for Left Arrow keyboard event. /// /// Indicates whether the key was pressed or released. /// /// True if handled. /// protected override bool OnKeyLeft(bool down) { if (down) { var count = Parent.Children.Count; int me = Parent.Children.IndexOf(this); if (me - 1 >= 0) { var prevTab = Parent.Children[me - 1]; TabControl.OnTabPressed(prevTab); InputHandler.KeyboardFocus = prevTab; } } return true; } /// /// Updates control colors. /// public override void UpdateColors() { if (IsActive) { if (IsDisabled) { TextColor = Skin.Colors.Tab.Active.Disabled; return; } if (IsDepressed) { TextColor = Skin.Colors.Tab.Active.Down; return; } if (IsHovered) { TextColor = Skin.Colors.Tab.Active.Hover; return; } TextColor = Skin.Colors.Tab.Active.Normal; } if (IsDisabled) { TextColor = Skin.Colors.Tab.Inactive.Disabled; return; } if (IsDepressed) { TextColor = Skin.Colors.Tab.Inactive.Down; return; } if (IsHovered) { TextColor = Skin.Colors.Tab.Inactive.Hover; return; } TextColor = Skin.Colors.Tab.Inactive.Normal; } } }