using System; using System.Text; using System.Drawing; using System.ComponentModel; using DevComponents.DotNetBar.Controls; namespace DevComponents.DotNetBar { /// /// Represents the visual separator line that is displayed between items. /// [ToolboxItem(false)] public class Separator : BaseItem { #region Private Variables #endregion #region Constructors /// /// Creates new instance of Separator. /// public Separator():this("") {} /// /// Creates new instance of Separator and assigns the name to it. /// /// Item name. public Separator(string sItemName):base(sItemName) { } #endregion #region Internal Implementation public override void Paint(ItemPaintArgs p) { Rectangle bounds = this.Bounds; if (bounds.Width < 1 || bounds.Height < 1) return; Color colorLine = p.Colors.ItemSeparator; if (p.ContainerControl is SideNavStrip) colorLine = p.Colors.BarDockedBorder; if (!_SeparatorColor.IsEmpty) colorLine = _SeparatorColor; Color colorShade = p.Colors.ItemSeparatorShade; if (!_ShadeColor.IsEmpty) colorShade = _ShadeColor; Graphics g=p.Graphics; Rectangle r; Padding padding = Dpi.Size(_Padding); if (this.Orientation == eOrientation.Vertical && _SeparatorOrientation == eDesignMarkerOrientation.NotSet || _SeparatorOrientation== eDesignMarkerOrientation.Vertical) { r = new Rectangle(bounds.X + padding.Left, bounds.Y + padding.Top + (bounds.Height - padding.Vertical) / 2, bounds.Width - padding.Horizontal, 1); if (!colorLine.IsEmpty) DisplayHelp.DrawLine(g, r.X, r.Y, r.Right -1, r.Y, colorLine, 1); } else { r = new Rectangle(bounds.X + padding.Left + (bounds.Width - padding.Horizontal) / 2, bounds.Y + padding.Top, 1, bounds.Height - padding.Vertical); if (!colorLine.IsEmpty) DisplayHelp.DrawLine(g, r.X, r.Y, r.X, r.Bottom - 1, colorLine, 1); } if (!colorShade.IsEmpty && (_FixedSize.Height>1 && (_SeparatorOrientation == eDesignMarkerOrientation.Vertical || this.Orientation == eOrientation.Vertical && _SeparatorOrientation == eDesignMarkerOrientation.NotSet) || _FixedSize.Width>1 && (_SeparatorOrientation == eDesignMarkerOrientation.Horizontal || this.Orientation == eOrientation.Horizontal && _SeparatorOrientation == eDesignMarkerOrientation.NotSet))) { r.Inflate(1, 1); DisplayHelp.DrawRectangle(g, colorShade, r); } if (this.DesignMode && this.Focused) { r = this.Bounds; r.Inflate(-1, -1); DesignTime.DrawDesignTimeSelection(p.Graphics, r, p.Colors.ItemDesignTimeBorder); } this.DrawInsertMarker(p.Graphics); } private Padding _Padding = new Padding(2, 2, 2, 2); /// /// Gets or sets separator padding. /// [Browsable(true), Category("Appearance"), Description("Gets or sets separator padding."), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] public Padding Padding { get { return _Padding; } } [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializePadding() { return _Padding.Bottom != 2 || _Padding.Top != 2 || _Padding.Left != 2 || _Padding.Right != 2; } [EditorBrowsable(EditorBrowsableState.Never)] private void ResetPadding() { _Padding = new Padding(2, 2, 2, 2); } private Size _FixedSize = new Size(3, 16); /// /// Gets or sets the size of separator. Size specified is for separator in Vertical orientation. If orientation changes then the size will be internally switched to respect proper orientation. /// public Size FixedSize { get { return _FixedSize; } set { _FixedSize = value; NeedRecalcSize = true; OnAppearanceChanged(); } } public override void RecalcSize() { if (this.Orientation == eOrientation.Horizontal) m_Rect.Size = new Size(Dpi.Width(_FixedSize.Width + _Padding.Horizontal), Dpi.Height(_FixedSize.Height + _Padding.Vertical)); else m_Rect.Size = new Size(Dpi.Width(_FixedSize.Height + Padding.Horizontal), Dpi.Height(_FixedSize.Width + _Padding.Vertical)); base.RecalcSize(); } /// /// Returns copy of the item. /// public override BaseItem Copy() { Separator objCopy = new Separator(m_Name); this.CopyToItem(objCopy); return objCopy; } /// /// Copies the ButtonItem specific properties to new instance of the item. /// /// New ButtonItem instance. protected override void CopyToItem(BaseItem copy) { Separator objCopy = copy as Separator; base.CopyToItem(objCopy); objCopy.FixedSize = _FixedSize; objCopy.Padding.Left = _Padding.Left; objCopy.Padding.Right = _Padding.Right; objCopy.Padding.Top = _Padding.Top; objCopy.Padding.Bottom = _Padding.Bottom; } private eDesignMarkerOrientation _SeparatorOrientation = eDesignMarkerOrientation.NotSet; /// /// Indicates splitter orientation. /// [DefaultValue(eDesignMarkerOrientation.NotSet), Category("Appearance"), Description("Indicates splitter orientation.")] public eDesignMarkerOrientation SeparatorOrientation { get { return _SeparatorOrientation; } set { if (_SeparatorOrientation != value) { eDesignMarkerOrientation oldValue = _SeparatorOrientation; _SeparatorOrientation = value; OnSeparatorOrientationChanged(value, oldValue); } } } protected virtual void OnSeparatorOrientationChanged(eDesignMarkerOrientation newValue, eDesignMarkerOrientation oldValue) { this.OnAppearanceChanged(); } private Color _SeparatorColor = Color.Empty; /// /// Gets or sets the separator color. /// [Category("Appearance"), Description("Indicates separator color.")] public Color SeparatorColor { get { return _SeparatorColor; } set { _SeparatorColor = value; this.Refresh(); } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeSeparatorColor() { return !_SeparatorColor.IsEmpty; } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetSeparatorColor() { this.SeparatorColor = Color.Empty; } private Color _ShadeColor = Color.Empty; /// /// Gets or sets the separator shade color. /// [Category("Appearance"), Description("Indicates separator shade color.")] public Color ShadeColor { get { return _ShadeColor; } set { _ShadeColor = value; this.Refresh(); } } /// /// Gets whether property should be serialized. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool ShouldSerializeShadeColor() { return !_ShadeColor.IsEmpty; } /// /// Resets property to its default value. /// [EditorBrowsable(EditorBrowsableState.Never)] public void ResetShadeColor() { this.ShadeColor = Color.Empty; } #endregion } }