#if FRAMEWORK20 using System; using System.ComponentModel; using System.Drawing.Design; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; using DevComponents.DotNetBar.Rendering; namespace DevComponents.DotNetBar { [Designer("DevComponents.DotNetBar.Design.SuperTabItemDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")] public class SuperTabItem : BaseItem { #region Events /// /// Occurs when text markup link is clicked /// [Description("Occurs when text markup link is clicked.")] public event MarkupLinkClickEventHandler MarkupLinkClick; /// /// Occurs when the tab colors have changed /// [Description("Occurs when the tab colors have changed.")] public event EventHandler TabColorChanged; #endregion #region Private variables private Icon _Icon; private Image _Image; private int _ImageIndex = -1; private Rectangle _ImageBounds; private eTabItemColor _PredefinedColor = eTabItemColor.Default; private SuperTabItemColorTable _TabColor = new SuperTabItemColorTable(); private bool _EnableMarkup = true; private eItemAlignment? _TextAlignment; private Rectangle _TextBounds; private Font _TabFont; private Font _SelectedTabFont; private Font _SizingFont; private bool _CloseButtonVisible = true; private bool _CloseButtonMouseOver; private bool _CloseButtonPressed; private Rectangle _CloseButtonBounds; private SuperTabStripItem _TabStripItem; private Control _AttachedControl; private SuperTabItemBaseDisplay _TabItemDisplay; private Font _DefaultSelectedTabFont; private bool _EnableImageAnimation; private bool _CanAnimateImage; private ImageAlignment _ImageAlignment = ImageAlignment.NotSet; private Padding _ImagePadding; private Size _FixedTabSize = Size.Empty; private Color _SymbolColor = Color.Empty; private string _Symbol = ""; private float _SymbolSize = 0f; private bool _StartsNewTabLine; #endregion /// /// Constructor /// public SuperTabItem() { Visible = true; GlobalItem = false; Stretch = false; Displayed = true; HookEvents(true); } #region Protected properties #region IsMarkupSupported /// /// IsMarkupSupported /// protected override bool IsMarkupSupported { get { return _EnableMarkup; } } #endregion #region DefaultSelectedTabFont /// /// Gets or sets the default SelectedTabFont /// protected Font DefaultSelectedTabFont { get { if (_DefaultSelectedTabFont == null) _DefaultSelectedTabFont = new Font(SystemFonts.CaptionFont, FontStyle.Bold); return (_DefaultSelectedTabFont); } set { if (_DefaultSelectedTabFont != null) _DefaultSelectedTabFont.Dispose(); _DefaultSelectedTabFont = value; _SizingFont = null; } } #endregion #endregion #region Internal properties #region CanAnimateImage internal bool CanAnimateImage { get { return (_EnableImageAnimation == true && _CanAnimateImage == true); } } #endregion #region CloseButtonBounds /// /// Gets the tab CloseButton Bounds /// internal Rectangle CloseButtonBounds { get { if (_CloseButtonBounds.IsEmpty) _CloseButtonBounds = GetCloseButtonBounds(); return (_CloseButtonBounds); } } #endregion #region CloseButtonMouseOver /// /// Gets or sets the CloseButtonMouseOver state /// internal bool CloseButtonMouseOver { get { return (_CloseButtonMouseOver); } set { if (_CloseButtonMouseOver != value) { _CloseButtonMouseOver = value; Refresh(); } } } #endregion #region CloseButtonPressed /// /// Gets or sets the CloseButtonPressed state /// internal bool CloseButtonPressed { get { return (_CloseButtonPressed); } set { if (_CloseButtonPressed != value) { _CloseButtonPressed = value; Refresh(); } } } #endregion #region EffectiveImageAlignment /// /// Gets the effective image alignment /// internal ImageAlignment EffectiveImageAlignment { get { if (ImageAlignment != ImageAlignment.NotSet) return (ImageAlignment); if (TabStripItem.ImageAlignment != ImageAlignment.NotSet) return (TabStripItem.ImageAlignment); return (ImageAlignment.MiddleLeft); } } #endregion #region ImageBounds /// /// Gets the tab Image Bounds /// internal Rectangle ImageBounds { get { if (_ImageBounds.IsEmpty) _ImageBounds = GetImageBounds(); return (_ImageBounds); } } #endregion #region IsVertical /// /// Gets the tabs vertical orientation /// internal bool IsVertical { get { return (_TabStripItem.HorizontalText == false && (_TabStripItem.TabAlignment == eTabStripAlignment.Left || _TabStripItem.TabAlignment == eTabStripAlignment.Right)); } } #endregion #region SelectedFont internal Font SelectedFont { get { return (_SelectedTabFont ?? _TabStripItem.SelectedTabFont) ?? DefaultSelectedTabFont; } } #endregion #region SizingFont internal Font SizingFont { get { return (_SizingFont); } set { _SizingFont = value; } } #endregion #region TabDisplay /// /// Gets the TabItemDisplay /// internal SuperTabItemBaseDisplay TabItemDisplay { get { return (_TabItemDisplay); } } #endregion #region TabStrip /// /// Gets the tabs TabStrip /// internal SuperTabStrip TabStrip { get { return (TabStripItem != null ? TabStripItem.TabStrip : null); } } #endregion #region TextBounds /// /// Gets the tabs Text Bounds /// internal Rectangle TextBounds { get { if (_TextBounds.IsEmpty) _TextBounds = GetTextBounds(); return (_TextBounds); } } #endregion #region UnselectedFont internal Font UnselectedFont { get { return (_TabFont ?? _TabStripItem.TabFont) ?? SystemFonts.CaptionFont; } } #endregion #endregion #region Public properties #region Browsable properties #region EnableImageAnimation /// /// Gets or sets whether image animation is enabled /// [Browsable(true), DevCoBrowsable(true)] [DefaultValue(false), Category("Appearance")] [Description("Indicates whether image animation is enabled.")] public bool EnableImageAnimation { get { return (_EnableImageAnimation); } set { if (_EnableImageAnimation != value) { _EnableImageAnimation = value; RefreshOwner(); } } } #endregion #region TabColor /// /// Gets or sets user specified tab display colors /// [Browsable(true), Category("Style")] [Description("Contains user specified tab display colors.")] public SuperTabItemColorTable TabColor { get { return (_TabColor); } set { if (_TabColor.Equals(value) == false) { if (_TabColor != null) _TabColor.ColorTableChanged -= ColorTableColorTableChanged; _TabColor = value; if (value != null) _TabColor.ColorTableChanged += ColorTableColorTableChanged; OnTabColorChanged(); Refresh(); } } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeTabColor() { return (_TabColor.IsEmpty == false); } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public void ResetTabColor() { TabColor = new SuperTabItemColorTable(); } #endregion #region CloseButtonVisible /// /// Gets or sets whether Close button on the tab is visible when SuperTabStrip.CloseButtonOnTabsVisible property is set to true /// [Browsable(true), DefaultValue(true), Category("Appearance")] [Description("Indicates whether Close button on the tab is visible when SuperTabStrip.CloseButtonOnTabsVisible property is set to true.")] public bool CloseButtonVisible { get { return (_CloseButtonVisible); } set { if (_CloseButtonVisible != value) { _CloseButtonVisible = value; RefreshOwner(); } } } #endregion #region Enabled /// /// Enabled /// [Browsable(true), DefaultValue(true), Category("Behavior")] [Description("Indicates whether the tab is enabled.")] public override bool Enabled { get { return base.Enabled; } set { if (base.Enabled != value) { base.Enabled = value; if (_TabStripItem != null) { if (value == false && IsSelected == true && DesignMode == false) _TabStripItem.SelectNewTab(this); } RefreshOwner(); } } } #endregion #region EnableMarkup /// /// Gets or sets whether text-markup support is enabled for the control's Text property /// [DefaultValue(true), Category("Appearance")] [Description("Indicates whether text-markup support is enabled for the control's Text property.")] public bool EnableMarkup { get { return (_EnableMarkup); } set { if (_EnableMarkup != value) { _EnableMarkup = value; NeedRecalcSize = true; OnTextChanged(); } } } #endregion #region FixedTabSize /// /// Gets or sets the FixedTabSize /// public Size FixedTabSize { get { return _FixedTabSize; } set { value.Width = Math.Max(0, value.Width); value.Height = Math.Max(0, value.Height); if (_FixedTabSize != value) { _FixedTabSize = value; RefreshOwner(); } } } [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeFixedTabSize() { return (_FixedTabSize.IsEmpty == false); } #endregion #region Icon /// /// Gets or sets the tab icon. Icon has same functionality as Image except that it supports Alpha blending /// [Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")] [Description("Indicates the tab icon. Icon has same functionality as Image except that it supports Alpha blending.")] public Icon Icon { get { return _Icon; } set { if (_Icon != value) { _Icon = value; RefreshOwner(); } } } [Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never)] public void ResetIcon() { Icon = null; } #endregion #region Image /// /// Gets or sets the tab image /// [Browsable(true), DevCoBrowsable(true), DefaultValue(null), Category("Appearance")] [Description("Indicates the tab image.")] public Image Image { get { return (_Image); } set { if (_Image != value) { _Image = value; OnImageChanged(); } } } private void OnImageChanged() { if (_EnableImageAnimation == true) { if (_TabItemDisplay != null) _TabItemDisplay.StopImageAnimation(); } Image image = GetImage(); _CanAnimateImage = ImageAnimator.CanAnimate(image); RefreshOwner(); } #endregion #region ImageIndex /// /// Gets or sets the tab image index /// [Browsable(true), DevCoBrowsable(true), DefaultValue(-1)] [Category("Appearance"), Description("Indicates the tab image index")] [Editor("DevComponents.DotNetBar.Design.ImageIndexEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))] [TypeConverter(typeof(ImageIndexConverter))] public int ImageIndex { get { return (_ImageIndex); } set { if (_ImageIndex != value) { _ImageIndex = value; OnImageChanged(); } } } [Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never)] public void ResetImageIndex() { ImageIndex = -1; } #endregion #region ImageList [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public ImageList ImageList { get { if (_TabStripItem != null && _TabStripItem.TabStrip != null) return (_TabStripItem.TabStrip.ImageList); return (null); } } #endregion #region ImageAlignment /// /// Gets or sets the alignment of the Image within the tab /// [DefaultValue(ImageAlignment.NotSet), Category("Appearance")] [Description("Indicates the alignment of the Image within the tab.")] public ImageAlignment ImageAlignment { get { return (_ImageAlignment); } set { if (_ImageAlignment != value) { _ImageAlignment = value; RefreshOwner(); } } } #endregion #region ImagePadding /// /// Gets or sets the spacing between content and edges of the Image /// [Description("Indicates the spacing between content and edges of the Image")] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Padding ImagePadding { get { if (_ImagePadding == null) { _ImagePadding = new Padding(0); UpdateChangeHandler(null, _ImagePadding); } return (_ImagePadding); } set { if (_ImagePadding != value) { UpdateChangeHandler(_ImagePadding, value); _ImagePadding = value; RefreshOwner(); } } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] private bool ShouldSerializeImagePadding() { return (_ImagePadding != null && _ImagePadding.IsEmpty == false); } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] private void ResetImagePadding() { ImagePadding = null; } #endregion #region PredefinedColor /// /// Gets or sets the predefined color for the tab /// [Browsable(true), DefaultValue(eTabItemColor.Default), Category("Style")] [Description("Indicates the predefined color for the tab.")] public eTabItemColor PredefinedColor { get { return (_PredefinedColor); } set { _PredefinedColor = value; OnTabColorChanged(); } } #endregion #region SelectedTabFont /// /// Gets or sets the selected tab Font /// [Browsable(true), DevCoBrowsable(true), Category("Style"), DefaultValue(null)] [Description("Indicates the selected tab Font")] public Font SelectedTabFont { get { return (_SelectedTabFont); } set { if (_SelectedTabFont != value) { if (value != null) DefaultSelectedTabFont = null; _SelectedTabFont = value; _SizingFont = null; RefreshOwner(); } } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeSelectedTabFont() { return (_SelectedTabFont != null); } [EditorBrowsable(EditorBrowsableState.Never)] public void ResetSelectedTabFont() { SelectedTabFont = null; } #endregion #region StartsNewTabLine /// /// StartsNewTabLine /// [Browsable(true), DefaultValue(false), Category("Behavior")] [Description("Indicates whether the tab starts a new tab line.")] public bool StartsNewTabLine { get { return (_StartsNewTabLine); } set { if (value != _StartsNewTabLine) { _StartsNewTabLine = value; RefreshOwner(); } } } #endregion #region Symbol /// /// Gets the realized symbol string. /// [Browsable(false)] public string SymbolRealized { get { return _SymbolRealized; } } private string _SymbolRealized = ""; /// /// Indicates the symbol displayed on face of the button instead of /// the image. Setting the symbol overrides the image setting. /// [DefaultValue(""), Category("Appearance"), Description("Indicates the symbol displayed on face of the button instead of the image. Setting the symbol overrides the image setting.")] [Editor("DevComponents.DotNetBar.Design.SymbolTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor))] public string Symbol { get { return (_Symbol); } set { if (value != _Symbol) { string oldValue = _Symbol; _Symbol = value; OnSymbolChanged(oldValue, value); } } } #region OnSymbolChanged /// /// Called when Symbol property has changed. /// /// Old property value /// New property value protected virtual void OnSymbolChanged(string oldValue, string newValue) { if (string.IsNullOrEmpty(newValue)) _SymbolRealized = ""; else _SymbolRealized = Symbols.GetSymbol(newValue); NeedRecalcSize = true; OnAppearanceChanged(); Refresh(); } #endregion private eSymbolSet _SymbolSet = eSymbolSet.Awesome; /// /// Gets or sets the symbol set used to represent the Symbol. /// [Browsable(false), DefaultValue(eSymbolSet.Awesome)] public eSymbolSet SymbolSet { get { return _SymbolSet; } set { if (_SymbolSet != value) { eSymbolSet oldValue = _SymbolSet; _SymbolSet = value; OnSymbolSetChanged(oldValue, value); } } } /// /// Called when SymbolSet property value changes. /// /// Indciates old value /// Indicates new value protected virtual void OnSymbolSetChanged(eSymbolSet oldValue, eSymbolSet newValue) { NeedRecalcSize = true; OnAppearanceChanged(); this.Refresh(); } #endregion #region SymbolColor /// /// Gets or sets the color of the Symbol. /// [Category("Appearance"), Description("Indicates color of the Symbol.")] public Color SymbolColor { get { return (_SymbolColor); } set { _SymbolColor = value; Refresh(); } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeSymbolColor() { return (_SymbolColor.IsEmpty == false); } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetSymbolColor() { SymbolColor = Color.Empty; } #endregion #region SymbolSize /// /// Indicates the size of the symbol in points. /// [DefaultValue(0f), Category("Appearance"), Description("Indicates the size of the symbol in points.")] public float SymbolSize { get { return (_SymbolSize); } set { if (value != _SymbolSize) { float oldValue = _SymbolSize; _SymbolSize = value; OnSymbolSizeChanged(oldValue, value); } } } #region OnSymbolSizeChanged /// /// Called when SymbolSize property has changed. /// /// Old property value /// New property value protected virtual void OnSymbolSizeChanged(float oldValue, float newValue) { NeedRecalcSize = true; OnAppearanceChanged(); Refresh(); } #endregion #endregion #region TextAlignment /// /// Gets or sets the text alignment /// [Browsable(true), DefaultValue(null)] [DevCoBrowsable(true), Category("Layout"), Description("Indicates text alignment.")] public eItemAlignment? TextAlignment { get { return (_TextAlignment); } set { if (_TextAlignment != value) { _TextAlignment = value; Refresh(); } } } #endregion #region TabFont /// /// Gets or sets the tab Font /// [Browsable(true), DevCoBrowsable(true), Category("Style"), DefaultValue(null)] [Description("Indicates the tab Font")] public Font TabFont { get { return (_TabFont); } set { if (_TabFont != value) { _TabFont = value; _SizingFont = null; RefreshOwner(); } } } [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeTabFont() { return (_TabFont != null); } [EditorBrowsable(EditorBrowsableState.Never)] public void ResetTabFont() { TabFont = null; } #endregion #region Text /// /// Gets or sets the tab text /// [Browsable(true)] [Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(UITypeEditor))] [Category("Appearance"), Description("Indicates the tab text.")] public override string Text { get { return (base.Text); } set { base.Text = value; } } #endregion #endregion #region Non-Browsable properties #region AttachedControl /// /// Gets or sets the control that is attached to this tab /// [Browsable(false), DevCoBrowsable(true), DefaultValue(null), Category("Behavior")] public Control AttachedControl { get { return (_AttachedControl); } set { SuperTabControlPanel panel = _AttachedControl as SuperTabControlPanel; if (panel != null) panel.PanelColorChanged -= ColorTableColorTableChanged; _AttachedControl = value; panel = _AttachedControl as SuperTabControlPanel; if (panel != null) { panel.TabItem = this; panel.Dock = DockStyle.Fill; panel.PanelColorChanged += ColorTableColorTableChanged; if (_TabStripItem != null && _TabStripItem.TabStrip != null) { if (DesignMode == true) _TabStripItem.TabStrip.Controls.Add(panel); panel.BringToFront(); panel.Visible = (_TabStripItem.SelectedTab == this); } } } } #endregion #region Bounds /// /// Gets or sets the tab Bounds /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public override Rectangle Bounds { get { return (base.Bounds); } set { base.Bounds = value; _TextBounds = Rectangle.Empty; _CloseButtonBounds = Rectangle.Empty; _ImageBounds = Rectangle.Empty; } } #endregion #region IsMouseOver /// /// Gets the MouseOver state /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool IsMouseOver { get { return (_TabStripItem != null && _TabStripItem.MouseOverTab == this); } } #endregion #region IsSelected /// /// Gets the tab selected state /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public bool IsSelected { get { return (_TabStripItem != null && _TabStripItem.SelectedTab == this); } } #endregion #region TabAlignment /// /// Gets the tab alignment /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public eTabStripAlignment TabAlignment { get { if (_TabStripItem != null) return (_TabStripItem.TabAlignment); return (eTabStripAlignment.Top); } } #endregion #region ContentRectangle /// /// Gets the tab Content Rectangle /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public Rectangle ContentRectangle { get { if (_TabItemDisplay != null) return (_TabItemDisplay.GetContentRectangle()); return (Rectangle.Empty); } } #endregion #region TabStripItem /// /// Gets or sets the tab TabStripItem /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public SuperTabStripItem TabStripItem { get { return (_TabStripItem); } set { _TabStripItem = value; if(_TabStripItem!=null) SetOwner(_TabStripItem.GetOwner()); if (_TabStripItem != null) { TabStyle = _TabStripItem.TabStyle; ContainerControl = _TabStripItem.ContainerControl; } } } #endregion #region TabStyle /// /// Gets or sets the tabs TabStyle /// [Browsable(false)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public eSuperTabStyle TabStyle { get { if (_TabStripItem != null) return (_TabStripItem.TabStyle); return (eSuperTabStyle.Office2007); } internal set { if (_TabItemDisplay != null) _TabItemDisplay.Dispose(); switch (value) { case eSuperTabStyle.Office2007: _TabItemDisplay = new Office2007SuperTabItem(this); break; case eSuperTabStyle.Office2010BackstageBlue: _TabItemDisplay = new Office2010BackstageSuperTabItem(this); break; case eSuperTabStyle.OneNote2007: _TabItemDisplay = new OneNote2007SuperTabItem(this); break; case eSuperTabStyle.OfficeMobile2014: _TabItemDisplay = new OfficeMobile2014SuperTabItem(this); break; case eSuperTabStyle.VisualStudio2008Dock: _TabItemDisplay = new VS2008DockSuperTabItem(this); break; case eSuperTabStyle.VisualStudio2008Document: _TabItemDisplay = new VS2008DocumentSuperTabItem(this); break; case eSuperTabStyle.WinMediaPlayer12: _TabItemDisplay = new WinMediaPlayer12SuperTabItem(this); break; } } } #endregion #region Visible /// /// Visible /// public override bool Visible { get { return (base.Visible); } set { base.Visible = value; if (_TabStripItem != null) { if (value == false && IsSelected == true && DesignMode == false) _TabStripItem.SelectNewTab(this); RefreshOwner(); } } } #endregion #endregion #endregion #region HookEvents /// /// Hooks or unhooks control events /// /// true to hook private void HookEvents(bool hook) { if (hook == true) { TextChanged += SuperTabItemTextChanged; MarkupLinkClick += TextMarkupLinkClick; _TabColor.ColorTableChanged += ColorTableColorTableChanged; } else { TextChanged -= SuperTabItemTextChanged; MarkupLinkClick -= TextMarkupLinkClick; if (_TabColor != null) _TabColor.ColorTableChanged -= ColorTableColorTableChanged; } } #endregion #region Event processing #region SuperTabItem_TextChanged /// /// SuperTabItem_TextChanged processing /// /// /// void SuperTabItemTextChanged(object sender, EventArgs e) { NeedRecalcSize = true; Refresh(); if (_TabStripItem != null) { _TabStripItem.NeedRecalcSize = true; _TabStripItem.Refresh(); } } #endregion #region Markup Support /// /// TextMarkupLinkClick /// /// /// protected override void TextMarkupLinkClick(object sender, EventArgs e) { TextMarkup.HyperLink link = sender as TextMarkup.HyperLink; if (link != null) OnMarkupLinkClick(new MarkupLinkClickEventArgs(link.Name, link.HRef)); base.TextMarkupLinkClick(sender, e); } /// /// OnMarkupLinkClick /// /// protected virtual void OnMarkupLinkClick(MarkupLinkClickEventArgs e) { if (MarkupLinkClick != null) MarkupLinkClick(this, e); } #endregion #region ColorTable_ColorTableChanged /// /// ColorTable_ColorTableChanged /// /// /// void ColorTableColorTableChanged(object sender, EventArgs e) { OnTabColorChanged(); } #endregion #endregion #region OnColorTableChanged /// /// Processes ColorTable changes /// protected void OnTabColorChanged() { if (TabColorChanged != null) TabColorChanged(this, EventArgs.Empty); Refresh(); } #endregion #region Close /// /// Closes the tab /// public void Close() { _TabStripItem.CloseTab(this); } #endregion #region GetTabFont /// /// Gets the operational tab font /// /// public Font GetTabFont() { return ((IsSelected == true) ? SelectedFont : UnselectedFont); } #endregion #region GetTabColorTable /// /// Gets the tab ColorTable /// /// SuperTabItemStateColorTable internal SuperTabItemStateColorTable GetTabColorTable() { return (_TabItemDisplay.GetTabColorTable()); } /// /// Gets the tab ColorStateTable for the given state /// /// eTabState /// SuperTabItemStateColorTable internal SuperTabItemStateColorTable GetTabColorTable(eTabState tabState) { return (_TabItemDisplay.GetTabColorTable(tabState)); } internal SuperTabItemStateColorTable GetTabColorTableEx(eTabState tabState) { return (_TabItemDisplay.GetTabColorTableEx(tabState)); } #endregion #region GetPanelColorTable /// /// Gets the tab Panel ColorTable /// /// internal SuperTabPanelItemColorTable GetPanelColorTable() { return (_TabItemDisplay.GetPanelColorTable()); } #endregion #region GetTabAreaFromPoint /// /// Gets the area of the tab that contains the given Point /// /// /// public eSuperTabArea GetTabAreaFromPoint(Point pt) { if (Bounds.Contains(pt) == true) { if (CloseButtonBounds.Contains(pt) == true) return (eSuperTabArea.InCloseBox); if (ImageBounds.Contains(pt) == true) return (eSuperTabArea.InImage); return (eSuperTabArea.InContent); } return (eSuperTabArea.InNone); } #endregion #region PointInTab /// /// Determines if the given Point is in the tab /// /// Point to test /// true if Point is in tab public bool PointInTab(Point pt) { using (GraphicsPath path = GetTabItemPath()) { if (path.IsVisible(pt)) return (true); } return (false); } #endregion #region GetTabItemPath /// /// Gets the tab bordering GraphicsPath /// /// GraphicsPath public GraphicsPath GetTabItemPath() { return (_TabItemDisplay != null ? _TabItemDisplay.TabItemPath() : null); } #endregion #region GetCloseButtonBounds /// /// Gets the Close Button bounding Rectangle /// /// Bounding Rectangle private Rectangle GetCloseButtonBounds() { if (CloseButtonVisible == false || _TabStripItem == null || _TabStripItem.CloseButtonOnTabsVisible == false) { return (Rectangle.Empty); } Rectangle r = TabItemDisplay.GetContentRectangle(); Rectangle t = r; Size closeSize = _TabStripItem.TabCloseButtonSize; int spacing = _TabStripItem.TabHorizontalSpacing; if (IsVertical == true) { if (TabStripItem.CloseButtonPosition == eTabCloseButtonPosition.Left) { r = new Rectangle(r.X + (r.Width - closeSize.Width) / 2 + 1, r.Bottom - spacing - closeSize.Height - 1, closeSize.Width, closeSize.Height); } else { r = new Rectangle(r.X + (r.Width - closeSize.Width)/2 + 1, r.Y + spacing, closeSize.Width, closeSize.Height); } if (TabStripItem.RotateVerticalText ^ TabStripItem.TabAlignment == eTabStripAlignment.Right) { r.X = t.X + (t.Right - r.Right); r.Y = t.Y + (t.Bottom - r.Bottom); } } else { if (_TabStripItem.CloseButtonPosition == eTabCloseButtonPosition.Left) { r = new Rectangle(r.X + spacing, r.Y + (r.Height - closeSize.Height) / 2, closeSize.Width, closeSize.Height); if (_TabStripItem.TabAlignment == eTabStripAlignment.Right) { if (IsSelected == true) r.X += _TabStripItem.TabDisplay.SelectedPaddingWidth; } } else { r = new Rectangle(r.Right - spacing - closeSize.Width, r.Y + (r.Height - closeSize.Height) / 2 + 1, closeSize.Width, closeSize.Height); if (_TabStripItem.TabAlignment == eTabStripAlignment.Left) { if (IsSelected == true) r.X -= _TabStripItem.TabDisplay.SelectedPaddingWidth; } } } r = _TabStripItem.OnGetCloseBounds(this, r); return (r); } #endregion #region GetImageBounds /// /// Gets the Image bounding Rectangle /// /// Bounding Rectangle private Rectangle GetImageBounds() { CompositeImage image = GetTabImage(); if (string.IsNullOrEmpty(SymbolRealized) && image == null) return (Rectangle.Empty); Rectangle r = TabItemDisplay.GetContentRectangle(); r = ProcessCloseBounds(r); r = (IsVertical == true) ? CalcVerticalImageBounds(image, r) : CalcHorizontalImageBounds(image, r); r = _TabStripItem.OnGetImageBounds(this, r); return (r); } #region CalcVerticalImageBounds private Rectangle CalcVerticalImageBounds(CompositeImage image, Rectangle r) { int h = 0; int w = 0; if (string.IsNullOrEmpty(SymbolRealized) == false) { Size size = GetSymbolSize(); w = size.Width; h = size.Height; } else { w = Dpi.ImageWidth(image.Width); h = Dpi.ImageHeight(image.Height); } Padding padding = Dpi.Size(ImagePadding); Rectangle t = r; switch (EffectiveImageAlignment) { case ImageAlignment.TopLeft: r.X += padding.Top + TabStripItem.TabVerticalSpacing; r.Y = r.Bottom - (w + padding.Left); break; case ImageAlignment.TopCenter: r.X += padding.Top + TabStripItem.TabVerticalSpacing; r.Y += (r.Height - (w + padding.Horizontal - TabStripItem.TabHorizontalSpacing))/2; break; case ImageAlignment.TopRight: r.X += padding.Top + TabStripItem.TabVerticalSpacing; r.Y += padding.Right + TabStripItem.TabHorizontalSpacing; break; case ImageAlignment.MiddleLeft: r.X += (r.Width - (h + padding.Vertical))/2 + padding.Top; r.Y = r.Bottom - (w + padding.Left); break; case ImageAlignment.MiddleCenter: r.X += (r.Width - (h + padding.Vertical))/2 + padding.Top; r.Y += (r.Height - (w + padding.Horizontal - TabStripItem.TabHorizontalSpacing)) / 2; break; case ImageAlignment.MiddleRight: r.X += (r.Width - (h + padding.Vertical))/2 + padding.Top; r.Y += padding.Right + TabStripItem.TabHorizontalSpacing; break; case ImageAlignment.BottomLeft: r.X = r.Right - (w + padding.Right + TabStripItem.TabHorizontalSpacing); r.Y = r.Bottom - (w + padding.Left); break; case ImageAlignment.BottomCenter: r.X = r.Right - (w + padding.Right + TabStripItem.TabHorizontalSpacing); r.Y += (r.Height - (w + padding.Horizontal - TabStripItem.TabHorizontalSpacing)) / 2; break; case ImageAlignment.BottomRight: r.X = r.Right - (w + padding.Right + TabStripItem.TabHorizontalSpacing); r.Y += padding.Right + TabStripItem.TabHorizontalSpacing; break; } if (TabStripItem.RotateVerticalText ^ TabStripItem.TabAlignment == eTabStripAlignment.Right == true) { r.X = t.X + (t.Right - (r.X + h)); r.Y = t.Y + (t.Bottom - (r.Y + w)); } r.Width = w; r.Height = h; return (r); } #endregion #region CalcHorizontalImageBounds private Rectangle CalcHorizontalImageBounds(CompositeImage image, Rectangle r) { int h = 0; int w = 0; if (string.IsNullOrEmpty(SymbolRealized) == false) { Size size = GetSymbolSize(); w = size.Width; h = size.Height; } else { w = image.Width; h = image.Height; } Padding padding = ImagePadding; switch (EffectiveImageAlignment) { case ImageAlignment.TopLeft: r.X += padding.Left; r.Y += padding.Top + TabStripItem.TabVerticalSpacing; break; case ImageAlignment.TopCenter: r.X += (r.Width - (w + padding.Horizontal + TabStripItem.TabHorizontalSpacing)) / 2; r.Y += padding.Top + TabStripItem.TabVerticalSpacing; break; case ImageAlignment.TopRight: r.X = r.Right - w - padding.Right - TabStripItem.TabHorizontalSpacing; r.Y += padding.Top + TabStripItem.TabVerticalSpacing; break; case ImageAlignment.MiddleLeft: r.X += padding.Left; r.Y += (r.Height - (h + padding.Vertical)) / 2 + padding.Top; break; case ImageAlignment.MiddleCenter: r.X += (r.Width - (w + padding.Horizontal + TabStripItem.TabHorizontalSpacing)) / 2; r.Y += (r.Height - (h + padding.Vertical)) / 2 + padding.Top; break; case ImageAlignment.MiddleRight: r.X = r.Right - w - padding.Right - TabStripItem.TabHorizontalSpacing; r.Y += (r.Height - (h + padding.Vertical)) / 2 + padding.Top; break; case ImageAlignment.BottomLeft: r.X += padding.Left; r.Y = r.Bottom - (h + padding.Bottom + TabStripItem.TabVerticalSpacing); break; case ImageAlignment.BottomCenter: r.X += (r.Width - (w + padding.Horizontal + TabStripItem.TabHorizontalSpacing)) / 2; r.Y = r.Bottom - (h + padding.Bottom + TabStripItem.TabVerticalSpacing); break; case ImageAlignment.BottomRight: r.X = r.Right - w - padding.Right - TabStripItem.TabHorizontalSpacing; r.Y = r.Bottom - (h + padding.Bottom + TabStripItem.TabVerticalSpacing); break; } r.Width = w; r.Height = h; return (r); } #endregion #region GetTabImage internal CompositeImage GetTabImage() { Image image = GetImage(); if (image != null) return (new CompositeImage(image, false)); return (Icon != null) ? (new CompositeImage(Icon, false, Icon.Size)) : null; } #endregion #region GetImage private Image GetImage() { if (_Image != null) return (_Image); if (_ImageIndex >= 0 && TabStrip != null) { ImageList imageList = TabStrip.ImageList; if (imageList != null && _ImageIndex < imageList.Images.Count) return (imageList.Images[_ImageIndex]); } return (null); } #endregion #region GetSymbolSize internal Size GetSymbolSize() { using (Graphics g = BarFunctions.CreateGraphics(TabStrip)) { Font symFont = Symbols.GetFont(SymbolSize, SymbolSet); Size size = TextDrawing.MeasureStringLegacy(g, SymbolRealized, symFont, Size.Empty, eTextFormat.Default); int descent = (int)Math.Ceiling((symFont.FontFamily.GetCellDescent(symFont.Style) * symFont.Size / symFont.FontFamily.GetEmHeight(symFont.Style))); size.Height -= descent; return (size); } } #endregion #endregion #region GetTextBounds /// /// Gets the Text bounding Rectangle /// /// Bounding Rectangle private Rectangle GetTextBounds() { Rectangle r = TabItemDisplay.GetContentRectangle(); r = ProcessImageBounds( ProcessCloseBounds(r)); if (IsVertical == false) { if (IsSelected == true) { if (_TabStripItem.TabAlignment == eTabStripAlignment.Left || _TabStripItem.TabAlignment == eTabStripAlignment.Right) { r.Width -= Dpi.Width(_TabStripItem.TabDisplay.SelectedPaddingWidth); } } } else { if ((_TabStripItem.TabAlignment == eTabStripAlignment.Left && _TabStripItem.RotateVerticalText == true) || (_TabStripItem.TabAlignment == eTabStripAlignment.Right && _TabStripItem.RotateVerticalText == false)) { if (_TabStripItem.TabAlignment == eTabStripAlignment.Left) { r.X += Dpi.Width(_TabStripItem.TabVerticalSpacing); r.Width -= Dpi.Width(_TabStripItem.TabVerticalSpacing); } else { r.Width -= Dpi.Width(_TabStripItem.TabVerticalSpacing); } } } r = _TabStripItem.OnGetTextBounds(this, r); return (r); } #endregion #region ProcessCloseBounds /// /// Calculates Close button bounds /// /// Running rectangle /// Running rectangle private Rectangle ProcessCloseBounds(Rectangle r) { int spacing = _TabStripItem.TabHorizontalSpacing; Size size = new Size(); if (_TabStripItem.CloseButtonOnTabsVisible && CloseButtonVisible) { size += CloseButtonBounds.Size; size.Width += spacing; size.Height += spacing; } if (IsVertical == true) { Rectangle t = r; if (TabStripItem.CloseButtonPosition == eTabCloseButtonPosition.Right) r.Y += size.Width; r.Height -= (size.Width + spacing); if (TabStripItem.RotateVerticalText ^ TabStripItem.TabAlignment == eTabStripAlignment.Right) { r.X = t.X + (t.Right - r.Right); r.Y = t.Y + (t.Bottom - r.Bottom); } } else { if (size.Width > 0) { if (_TabStripItem.CloseButtonPosition == eTabCloseButtonPosition.Left) r.X += (size.Width + spacing); r.Width -= (size.Width + spacing); } r.X += spacing; r.Width -= (spacing * 2); if (IsSelected == true) { if (_TabStripItem.TabAlignment == eTabStripAlignment.Right) r.X += _TabStripItem.TabDisplay.SelectedPaddingWidth; } } return (r); } #endregion #region ProcessImageBounds /// /// Calculates Image bounds /// /// Running rectangle /// Running rectangle private Rectangle ProcessImageBounds(Rectangle r) { CompositeImage image = GetTabImage(); if (String.IsNullOrEmpty(SymbolRealized) == false || image != null) { r = (IsVertical == true) ? SubVerticalImageBounds(image, r) : SubHorizontalImageBounds(image, r); } return (r); } #region SubHorizontalImageBounds private Rectangle SubHorizontalImageBounds(CompositeImage image, Rectangle r) { int h = 0; int w = 0; if (string.IsNullOrEmpty(SymbolRealized) == false) { Size size = GetSymbolSize(); w = size.Width; h = size.Height; } else { w = image.Width; h = image.Height; } w += (_TabStripItem.TabHorizontalSpacing + ImagePadding.Horizontal); h += (_TabStripItem.TabVerticalSpacing + ImagePadding.Vertical); switch (EffectiveImageAlignment) { case ImageAlignment.TopLeft: case ImageAlignment.TopCenter: case ImageAlignment.TopRight: r.Y += h; r.Height -= h; break; case ImageAlignment.MiddleLeft: r.X += w; r.Width -= w; break; case ImageAlignment.MiddleRight: r.Width -= w; break; case ImageAlignment.BottomLeft: case ImageAlignment.BottomCenter: case ImageAlignment.BottomRight: r.Height -= h; break; } return (r); } #endregion #region SubVerticalImageBounds private Rectangle SubVerticalImageBounds(CompositeImage image, Rectangle r) { int h = 0; int w = 0; if (string.IsNullOrEmpty(SymbolRealized) == false) { Size size = GetSymbolSize(); w = size.Width; h = size.Height; } else { w = image.Width; h = image.Height; } w += (_TabStripItem.TabHorizontalSpacing + ImagePadding.Horizontal); h += (_TabStripItem.TabVerticalSpacing + ImagePadding.Vertical); Rectangle t = r; switch (EffectiveImageAlignment) { case ImageAlignment.TopLeft: case ImageAlignment.TopCenter: case ImageAlignment.TopRight: r.X += h; r.Width -= h; break; case ImageAlignment.MiddleLeft: r.Height -= w; break; case ImageAlignment.MiddleRight: r.Y += w; r.Height -= w; break; case ImageAlignment.BottomLeft: case ImageAlignment.BottomCenter: case ImageAlignment.BottomRight: r.Width -= h; break; } if (TabStripItem.RotateVerticalText ^ TabStripItem.TabAlignment == eTabStripAlignment.Right) { r.X = t.X + (t.Right - r.Right); r.Y = t.Y + (t.Bottom - r.Bottom); } return (r); } #endregion #endregion #region RefreshOwner /// /// Refreshes the tab owner /// private void RefreshOwner() { if (_TabStripItem != null) { _TabStripItem.NeedRecalcSize = true; _TabStripItem.Refresh(); } Refresh(); } #endregion #region Refresh /// /// Refreshes the tab display /// public override void Refresh() { if (SuspendLayout == false) { if (Visible == true && Displayed == true && TabStripItem != null) { Control objCtrl = TabStripItem.ContainerControl as Control; if (objCtrl != null && IsHandleValid(objCtrl)) { if (NeedRecalcSize == true) { if (Parent is ItemContainer) { Parent.RecalcSize(); } else { RecalcSize(); if (Parent != null) Parent.SubItemSizeChanged(this); } } Invalidate(objCtrl); } } } } #endregion #region Paint /// /// Paint processing /// /// public override void Paint(ItemPaintArgs p) { if (_TabItemDisplay != null) _TabItemDisplay.Paint(p); } #endregion #region Mouse support #region InternalMouseMove /// /// InternalMouseMove /// /// public override void InternalMouseMove(MouseEventArgs objArg) { base.InternalMouseMove(objArg); CloseButtonMouseOver = CloseButtonBounds.Contains(objArg.Location); } #endregion #region InternalMouseEnter /// /// InternalMouseEnter /// public override void InternalMouseEnter() { base.InternalMouseEnter(); Refresh(); } #endregion #region InternalMouseLeave /// /// InternalMouseLeave /// public override void InternalMouseLeave() { base.InternalMouseLeave(); CloseButtonMouseOver = false; CloseButtonPressed = false; Refresh(); } #endregion #region InternalMouseDown /// /// InternalMouseDown /// /// public override void InternalMouseDown(MouseEventArgs objArg) { base.InternalMouseDown(objArg); if (CloseButtonMouseOver == true) { CloseButtonPressed = ((objArg.Button & MouseButtons.Left) == MouseButtons.Left); } } #endregion #region InternalMouseUp /// /// InternalMouseUp /// /// public override void InternalMouseUp(MouseEventArgs objArg) { base.InternalMouseUp(objArg); CloseButtonPressed = false; } #endregion #endregion #region UpdateChangeHandler protected void UpdateChangeHandler( INotifyPropertyChanged oldValue, INotifyPropertyChanged newValue) { if (oldValue != null) oldValue.PropertyChanged -= ValuePropertyChanged; if (newValue != null) newValue.PropertyChanged += ValuePropertyChanged; } void ValuePropertyChanged(object sender, PropertyChangedEventArgs e) { RefreshOwner(); } #endregion #region ToString /// /// ToString /// /// public override string ToString() { return (Text); } #endregion #region Dispose /// /// Dispose /// protected override void Dispose(bool disposing) { if (disposing == true && IsDisposed == false) HookEvents(false); base.Dispose(disposing); } #endregion #region Copy /// /// Returns copy of the item. /// public override BaseItem Copy() { SuperTabItem objCopy = new SuperTabItem(); CopyToItem(objCopy); return (objCopy); } /// /// Copies specific properties to new instance of the item. /// /// New SuperTabItem instance protected override void CopyToItem(BaseItem copy) { SuperTabItem objCopy = copy as SuperTabItem; if (objCopy != null) { base.CopyToItem(objCopy); objCopy.TabColor = _TabColor; objCopy.CloseButtonVisible = _CloseButtonVisible; objCopy.EnableImageAnimation = _EnableImageAnimation; objCopy.EnableMarkup = _EnableMarkup; objCopy.Icon = _Icon; objCopy.Image = _Image; objCopy.ImageIndex = _ImageIndex; objCopy.PredefinedColor = _PredefinedColor; objCopy.SelectedTabFont = _SelectedTabFont; objCopy.TextAlignment = _TextAlignment; objCopy.TabFont = _TabFont; objCopy.Symbol = _Symbol; objCopy.SymbolSet = _SymbolSet; objCopy.SymbolColor = _SymbolColor; objCopy.SymbolSize = _SymbolSize; objCopy.AttachedControl = _AttachedControl; } } #endregion } #region enums #region ImageAlignment /// /// Alignment /// public enum ImageAlignment { /// /// NotSet = -1, /// /// TopLeft /// TopLeft, /// /// TopCenter /// TopCenter, /// /// TopRight /// TopRight, /// /// MiddleLeft /// MiddleLeft, /// /// MiddleCenter /// MiddleCenter, /// /// MiddleRight /// MiddleRight, /// /// BottomLeft /// BottomLeft, /// /// BottomCenter /// BottomCenter, /// /// BottomRight /// BottomRight, } #endregion #region eSuperTabArea /// /// Tab area parts /// public enum eSuperTabArea { InNone, InContent, InImage, InCloseBox } #endregion #region eTabState /// /// Tab states /// public enum eTabState { Default, Selected, MouseOver, SelectedMouseOver, Disabled, } #endregion #endregion } #endif