DotNet 4.8.1 build of DotNetBar

This commit is contained in:
2025-02-07 10:35:23 -05:00
parent 33439b63a0
commit 6b0a5d60f4
2609 changed files with 989814 additions and 7 deletions

View File

@@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using DevComponents.DotNetBar.Controls;
using System.Drawing.Imaging;
namespace DevComponents.DotNetBar.Rendering
{
internal class OfficeSideNavItemPainter : SideNavItemPainter
{
/// <summary>
/// Paints ListBoxItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public override void Paint(SideNavItemRendererEventArgs e)
{
Graphics g = e.ItemPaintArgs.Graphics;
SideNavItem item = e.Item;
SideNavStrip navStrip = e.ItemPaintArgs.ContainerControl as SideNavStrip;
SideNavItemColorTable table = ColorTable.SideNav.SideNavItem;
SideNavItemStateColorTable ct = item.IsMouseOver ? table.MouseOver : table.Default;
if (item.Checked)
ct = table.Selected;
else if (item.IsMouseDown)
ct = table.Pressed;
Rectangle r = item.Bounds;
Rectangle textBounds = item.TextRenderBounds;
Rectangle imageBounds = item.ImageRenderBounds;
CompositeImage image = item.GetImage();
if (ct.BackColors != null && ct.BackColors.Length > 0 || item.BackColors != null && item.BackColors.Length > 0)
{
using (Brush brush = DisplayHelp.CreateBrush(r, (item.BackColors != null && item.BackColors.Length > 0) ? item.BackColors : ct.BackColors, ct.BackColorsGradientAngle, ct.BackColorsPositions))
{
DisplayHelp.FillRoundedRectangle(g, brush, r, ct.CornerRadius);
//g.FillRectangle(brush, r);
}
}
Region oldClip = null;
// For top item do not draw the top border
if (r.Y == 0 && item.Checked)
{
oldClip = g.Clip;
g.SetClip(new Rectangle(r.X, r.Y, r.Width, 1), CombineMode.Exclude);
}
if (item.BorderColors != null && item.BorderColors.Length > 0)
DisplayHelp.DrawRoundedRectangle(g, r, item.BorderColors, ct.CornerRadius);
else if (ct.BorderColors != null && ct.BorderColors.Length > 0)
DisplayHelp.DrawRoundedRectangle(g, r, ct.BorderColors, ct.CornerRadius);
if (r.Y == 0 && item.Checked)
{
g.Clip = oldClip;
oldClip.Dispose();
}
Color textColor = ct.TextColor;
bool hasImage = false;
if ((image != null || !string.IsNullOrEmpty(item.SymbolRealized)) && item.ButtonStyle != eButtonStyle.TextOnlyAlways)
{
if (imageBounds.IsEmpty)
imageBounds = GetImageRectangle(item, image);
if (textBounds.IsEmpty)
textBounds = GetTextRectangle(item, image, imageBounds);
hasImage = true;
}
else if (textBounds.IsEmpty)
{
textBounds = r;
r.X += 2;
r.Width -= 2;
}
if (!string.IsNullOrEmpty(item.SymbolRealized))
{
Color symbolColor = item.SymbolColor;
if (symbolColor.IsEmpty) symbolColor = textColor;
TextDrawing.DrawStringLegacy(g, item.SymbolRealized, Symbols.GetFont(item.SymbolSize, item.SymbolSet),
symbolColor, new Rectangle(imageBounds.X, imageBounds.Y + imageBounds.Height / 2, 0, 0), eTextFormat.Default | eTextFormat.VerticalCenter);
}
else if (image != null)
{
if (!item.IsMouseOver && item.HotTrackingStyle == eHotTrackingStyle.Color)
{
// Draw gray-scale image for this hover style...
float[][] array = new float[5][];
array[0] = new float[5] { 0.2125f, 0.2125f, 0.2125f, 0, 0 };
array[1] = new float[5] { 0.5f, 0.5f, 0.5f, 0, 0 };
array[2] = new float[5] { 0.0361f, 0.0361f, 0.0361f, 0, 0 };
array[3] = new float[5] { 0, 0, 0, 1, 0 };
array[4] = new float[5] { 0.2f, 0.2f, 0.2f, 0, 1 };
ColorMatrix grayMatrix = new ColorMatrix(array);
ImageAttributes att = new ImageAttributes();
att.SetColorMatrix(grayMatrix);
image.DrawImage(g, imageBounds, 0, 0, image.ActualWidth, image.ActualHeight, GraphicsUnit.Pixel, att);
}
else
{
image.DrawImage(g, imageBounds);
}
}
item.ImageRenderBounds = imageBounds;
if (!string.IsNullOrEmpty(item.Text) && (item.ButtonStyle!= eButtonStyle.Default || !hasImage))
{
if (!item.ForeColor.IsEmpty) textColor = item.ForeColor;
Font font = e.ItemPaintArgs.Font;
if (item.TextMarkupBody == null)
{
eTextFormat textFormat = eTextFormat.Default | eTextFormat.VerticalCenter;
//if (item.TextAlignment == eButtonTextAlignment.Center)
//{
// textFormat |= eTextFormat.HorizontalCenter;
//}
//else if (item.TextAlignment == eButtonTextAlignment.Right)
//{
// textFormat |= eTextFormat.Right;
//}
TextDrawing.DrawString(g, item.Text, font, textColor, textBounds, textFormat);
}
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, e.ItemPaintArgs.RightToLeft);
d.HotKeyPrefixVisible = false;
d.ContextObject = item;
Rectangle mr = new Rectangle(textBounds.X, textBounds.Y + (textBounds.Height - item.TextMarkupBody.Bounds.Height) / 2, item.TextMarkupBody.Bounds.Width, item.TextMarkupBody.Bounds.Height);
item.TextMarkupBody.Bounds = mr;
item.TextMarkupBody.Render(d);
}
}
item.TextRenderBounds = textBounds;
}
private Rectangle GetImageRectangle(SideNavItem item, CompositeImage image)
{
Rectangle imageRect = Rectangle.Empty;
// Calculate image position
if (image != null || !string.IsNullOrEmpty(item.SymbolRealized))
{
Size imageSize = item.ImageSize;
if (item.ImagePosition == eImagePosition.Top || item.ImagePosition == eImagePosition.Bottom)
imageRect = new Rectangle(item.ImageDrawRect.X, item.ImageDrawRect.Y, item.DisplayRectangle.Width, item.ImageDrawRect.Height);
else if (item.ImagePosition == eImagePosition.Left)
{
if (item.ButtonStyle == eButtonStyle.Default)
return new Rectangle(item.Bounds.X + (item.Bounds.Width - imageSize.Width)/2,
item.Bounds.Y + (item.Bounds.Height - imageSize.Height)/2, imageSize.Width, imageSize.Height);
else
imageRect = new Rectangle(item.ImageDrawRect.X + 4, item.ImageDrawRect.Y,
item.ImageDrawRect.Width,
item.ImageDrawRect.Height);
}
else if (item.ImagePosition == eImagePosition.Right)
imageRect = new Rectangle(item.ImageDrawRect.X + item.ImagePaddingHorizontal + 4,
item.ImageDrawRect.Y, item.ImageDrawRect.Width, item.ImageDrawRect.Height);
imageRect.Offset(item.DisplayRectangle.Left, item.DisplayRectangle.Top);
imageRect.Offset((imageRect.Width - imageSize.Width) / 2, (imageRect.Height - imageSize.Height) / 2);
imageRect.Width = imageSize.Width;
imageRect.Height = imageSize.Height;
}
return imageRect;
}
private Rectangle GetTextRectangle(SideNavItem item, CompositeImage image, Rectangle imageBounds)
{
Rectangle itemRect = item.DisplayRectangle;
Rectangle textRect = item.TextDrawRect;
if (item.ImagePosition == eImagePosition.Top || item.ImagePosition == eImagePosition.Bottom)
{
textRect = new Rectangle(1, textRect.Y, itemRect.Width - 2, textRect.Height);
}
textRect.Offset(itemRect.Left, itemRect.Top);
if (item.ImagePosition == eImagePosition.Left)
textRect.X = imageBounds.Right + item.ImagePaddingHorizontal;
if (textRect.Right > itemRect.Right)
textRect.Width = itemRect.Right - textRect.Left;
return textRect;
}
}
}

View File

@@ -0,0 +1,776 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.SqlTypes;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;
using DevComponents.DotNetBar.Metro;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents SideNav control to create "hamburger" menus.
/// </summary>
[ToolboxBitmap(typeof(SideNav), "Controls.SideNav.ico"), ToolboxItem(true),Designer("DevComponents.DotNetBar.Design.SideNavDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false)]
public class SideNav : System.Windows.Forms.ContainerControl
{
#region Constructor
private SideNavStrip _Strip = null;
private Bar _TitleBar = null;
private LabelItem _TitleLabel = null;
private ButtonItem _CloseButton = null;
private ButtonItem _MaximizeButton = null;
private ButtonItem _RestoreButton = null;
private Control _Splitter = null;
public SideNav()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.ResizeRedraw
| DisplayHelp.DoubleBufferFlag
| ControlStyles.UserPaint
| ControlStyles.Opaque
, true);
this.Padding = new System.Windows.Forms.Padding(1);
_Splitter = new Control();
_Splitter.Width = 4;
_Splitter.Name = "splitter";
_Splitter.Cursor = Cursors.VSplit;
_Splitter.Dock = DockStyle.Right;
_Splitter.MouseMove += SplitterMouseMove;
_Splitter.MouseDown += SplitterMouseDown;
this.Controls.Add(_Splitter);
// Title bar and fold/extend buttons
Bar titleBar = new Bar();
titleBar.Name = "titleBar";
titleBar.AntiAlias = true;
titleBar.Name = "titleBar";
titleBar.PaddingBottom = 7;
titleBar.PaddingTop = 5;
titleBar.PaddingLeft = 6;
titleBar.RoundCorners = false;
titleBar.Dock = DockStyle.Top;
titleBar.Stretch = true;
titleBar.Style = DevComponents.DotNetBar.eDotNetBarStyle.StyleManagerControlled;
titleBar.TabIndex = 0;
titleBar.TabStop = false;
titleBar.BarType = eBarType.StatusBar;
titleBar.ItemsContainer.OverflowEnabled = false;
LabelItem titleLabel=new LabelItem();
titleLabel.Name = "titleLabel";
titleLabel.Text = "Title";
titleLabel.FontBold = true;
_TitleLabel = titleLabel;
titleBar.Items.Add(titleLabel);
_TitleBar = titleBar;
_CloseButton = new ButtonItem("openCloseButton");
_CloseButton.Symbol = "\uf0d9";
_CloseButton.ImagePaddingHorizontal = 18;
_CloseButton.ItemAlignment= eItemAlignment.Far;
_CloseButton.SymbolSize = 12f;
_CloseButton.Click+=CloseButtonClick;
titleBar.Items.Add(_CloseButton);
_MaximizeButton = new ButtonItem("maximizeButton");
_MaximizeButton.Symbol = "\uf090";
_MaximizeButton.ItemAlignment = eItemAlignment.Far;
_MaximizeButton.SymbolSize = 12f;
_MaximizeButton.Click += MaximizeButtonClick;
titleBar.Items.Add(_MaximizeButton);
_RestoreButton = new ButtonItem("restoreButton");
_RestoreButton.Symbol = "\uf100";
_RestoreButton.ItemAlignment = eItemAlignment.Far;
_RestoreButton.SymbolSize = 12f;
_RestoreButton.Click += RestoreButtonClick;
_RestoreButton.Visible = false;
titleBar.Items.Add(_RestoreButton);
this.Controls.Add(titleBar);
_Strip = new SideNavStrip();
_Strip.Dock = DockStyle.Left;
_Strip.AutoSize = true;
_Strip.AutoSyncSizeOrientation = eOrientation.Horizontal;
_Strip.ButtonCheckedChanged += StripButtonCheckedChanged;
//SideNavItem menuItem=new SideNavItem();
//menuItem.Name = "menuItem";
//menuItem.Text = "Menu";
//menuItem.Symbol = "\uf0c9";
//menuItem.IsSystemMenu = true;
//_Strip.Items.Add(menuItem);
//Separator sep = new Separator();
//sep.SeparatorOrientation = eDesignMarkerOrientation.Vertical;
//sep.FixedSize = new Size(3,1);
//sep.Padding.Left = 6;
//sep.Padding.Right = 6;
//_Strip.Items.Add(sep);
//SideNavItem item = new SideNavItem();
//item.Text = "Home";
//item.Symbol = "\uf015";
//_Strip.Items.Add(item);
//SideNavPanel panel=new SideNavPanel();
//panel.Dock = DockStyle.Fill;
//this.Controls.Add(panel);
//item.Panel = panel;
//item = new SideNavItem();
//item.Text = "Explore";
//item.Symbol = "\uf002";
//_Strip.Items.Add(item);
//ButtonItem button=new ButtonItem();
//button.Text = "Button";
//button.Symbol = "\uf003";
//button.ButtonStyle = eButtonStyle.ImageAndText;
//_Strip.Items.Add(button);
this.Controls.Add(_Strip);
_Strip.Width = 48;
StyleManager.Register(this);
UpdateColors();
}
protected override void Dispose(bool disposing)
{
if (_IsMaximized && disposing && this.Parent!=null)
{
this.Parent.Resize -= ParentResize;
}
base.Dispose(disposing);
}
#endregion
#region Implementation
/// <summary>
/// Called by StyleManager to notify control that style on manager has changed and that control should refresh its appearance if
/// its style is controlled by StyleManager.
/// </summary>
/// <param name="newStyle">New active style.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void StyleManagerStyleChanged(eDotNetBarStyle newStyle)
{
UpdateColors();
}
/// <summary>
/// Updates the control colors from the global color table.
/// </summary>
public void UpdateColors()
{
SideNavColorTable ct = GetColorTable();
_TitleBar.BackColor = ct.TitleBackColor;
_TitleBar.BorderColors = ct.TitleBorderColors;
this.Invalidate(true);
}
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
DisplayHelp.FillRectangle(g,this.ClientRectangle, this.BackColor);
SideNavColorTable table = GetColorTable();
DisplayHelp.DrawRoundedRectangle(g, this.ClientRectangle, table.BorderColors, 0);
}
private SideNavColorTable GetColorTable()
{
return ((Office2007Renderer)GlobalManager.Renderer).ColorTable.SideNav;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void SetDesignMode()
{
_Strip.SetDesignMode(true);
}
private bool _EnableSplitter = true;
/// <summary>
/// Indicates whether splitter that is located on right hand side of open control is visible and enabled.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether splitter that is located on right hand side of open control is visible and enabled.")]
public bool EnableSplitter
{
get { return _EnableSplitter; }
set
{
if (_EnableSplitter != value)
{
bool oldValue = _EnableSplitter;
_EnableSplitter = value;
OnEnableSplitterChanged(value, oldValue);
}
}
}
protected virtual void OnEnableSplitterChanged(bool newValue, bool oldValue)
{
_Splitter.Visible = newValue;
}
private bool _EnableClose = true;
/// <summary>
/// Indicates whether button which folds/closes the control is visible.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether button which folds/closes the control is visible.")]
public bool EnableClose
{
get { return _EnableClose; }
set
{
if (_EnableClose != value)
{
bool oldValue = _EnableClose;
_EnableClose = value;
OnEnableCloseChanged(value, oldValue);
}
}
}
protected virtual void OnEnableCloseChanged(bool newValue, bool oldValue)
{
_CloseButton.Visible = newValue;
_TitleBar.RecalcLayout();
}
private bool _EnableMaximize = true;
// <summary>
/// Indicates whether buttons which maximize and restore the control are visible.
/// </summary>
[DefaultValue(true), Category("Apeparance"), Description("Indicates whether buttons which maximize and restore the control are visible.")]
public bool EnableMaximize
{
get { return _EnableMaximize; }
set
{
if (_EnableMaximize != value)
{
bool oldValue = _EnableMaximize;
_EnableMaximize = value;
OnEnableMaximizeChanged(value, oldValue);
}
}
}
protected virtual void OnEnableMaximizeChanged(bool newValue, bool oldValue)
{
if (!newValue)
{
_MaximizeButton.Visible = false;
_RestoreButton.Visible = false;
}
else
{
if (_IsMaximized)
_RestoreButton.Visible = true;
else
_MaximizeButton.Visible = true;
}
_TitleBar.RecalcLayout();
}
/// <summary>
/// Returns collection of items on a bar.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false)]
public SubItemsCollection Items
{
get
{
return _Strip.Items;
}
}
private void CloseButtonClick(object sender, EventArgs e)
{
Close(eEventSource.Mouse);
}
private void MaximizeButtonClick(object sender, EventArgs e)
{
Maximize(eEventSource.Mouse);
}
private bool _IsMaximized = false;
private int _RestoredWidth = 0;
/// <summary>
/// Maximizes control width so it fills up space to the right of the control.
/// </summary>
/// <param name="source">Source of the event.</param>
public void Maximize(eEventSource source)
{
if(_IsMaximized) return;
if (this.Parent == null)
return;
if (this.Bounds.Right >= this.Parent.ClientRectangle.Right)
return;
CancelSourceEventArgs args=new CancelSourceEventArgs(source);
OnBeforeMaximize(args);
if(args.Cancel) return;
_IsMaximized = true;
int maxWidth = GetMaxWidth();
_RestoredWidth = this.Width;
BarFunctions.AnimateControl(this, true, _AnimationTime, this.Bounds, new Rectangle(this.Location, new Size(maxWidth, this.Height)));
_RestoreButton.Visible = true;
_MaximizeButton.Visible = false;
_TitleBar.RecalcLayout();
_Splitter.Visible = false;
this.Invalidate();
this.Parent.Resize += ParentResize;
}
void ParentResize(object sender, EventArgs e)
{
if (this.Parent.Width > 0)
this.Width = GetMaxWidth();
}
private int GetMaxWidth()
{
int width = this.Width + this.Parent.ClientRectangle.Right - this.Bounds.Right;
if (this.Parent is MetroAppForm)
{
MetroAppForm form = (MetroAppForm) this.Parent;
if (form.BorderThickness.Right > 0)
width -= (int)form.BorderThickness.Right;
else
width -= 3;
}
return width;
}
private void RestoreButtonClick(object sender, EventArgs e)
{
Restore(eEventSource.Mouse);
}
/// <summary>
/// Restores the control to previous size if it was maximized before.
/// </summary>
/// <param name="source">Source of event.</param>
public void Restore(eEventSource source)
{
if (!_IsMaximized || _RestoredWidth == 0) return;
_IsMaximized = false;
CancelSourceEventArgs args = new CancelSourceEventArgs(source);
OnBeforeRestore(args);
if (args.Cancel) return;
BarFunctions.AnimateControl(this, true, _AnimationTime, this.Bounds, new Rectangle(this.Location, new Size(_RestoredWidth, this.Height)));
_RestoredWidth = 0;
_RestoreButton.Visible = false;
_MaximizeButton.Visible = true;
_TitleBar.RecalcLayout();
_Splitter.Visible = _EnableSplitter;
this.Invalidate();
if(this.Parent!=null)
this.Parent.Resize -= ParentResize;
}
private bool _IsOpen = true;
private int _OpenWidth = 0;
/// <summary>
/// Gets or sets whether control is closed, i.e. whether selected item panel is shown or not. When closed
/// any selected item is unselected and selected panel hidden.
/// </summary>
[DefaultValue(false), Browsable(false)]
public bool IsClosed
{
get { return !_IsOpen; }
set
{
if (value)
{
if(_IsOpen)
Close(eEventSource.Code);
}
else
{
if (!_IsOpen)
{
SideNavItem item = FirstVisibleSideNavItem??_LastOpenItem;
if (item != null)
Open(item, eEventSource.Code);
}
}
}
}
private SideNavItem FirstVisibleSideNavItem
{
get
{
for (int i = 0; i < _Strip.Items.Count; i++)
{
if (_Strip.Items[i] is SideNavItem && _Strip.Items[i].Visible)
return (SideNavItem)_Strip.Items[i];
}
return null;
}
}
private void StripButtonCheckedChanged(object sender, EventArgs e)
{
if (sender is SideNavItem && ((SideNavItem)sender).Checked)
{
OnSelectedItemChanged(EventArgs.Empty);
if (!_IsOpen)
Open((SideNavItem)sender, eEventSource.Code);
}
}
/// <summary>
/// Opens the control, i.e. expands it, selects specified item and shows its associated panel.
/// </summary>
/// <param name="item">Item to select.</param>
/// <param name="source">Source of the event.</param>
public void Open(SideNavItem item, eEventSource source)
{
if (item == null)
throw new ArgumentException("item must be set to valid item to select");
if (_IsOpen) return;
CancelSourceEventArgs args=new CancelSourceEventArgs(source, item);
OnBeforeOpen(args);
if(args.Cancel) return;
if (!item.Checked)
item.Checked = true;
BarFunctions.AnimateControl(this, true, _AnimationTime, this.Bounds, new Rectangle(this.Location, new Size(_OpenWidth, this.Height)));
_IsOpen = true;
_Splitter.Visible = _EnableSplitter;
this.Invalidate();
}
private SideNavItem _LastOpenItem = null;
/// <summary>
/// Closes the control, i.e. unselects any selected item, hide its associated panel and folds the control.
/// </summary>
/// <param name="source">Source of the event.</param>
public void Close(eEventSource source)
{
if(!_IsOpen) return;
CancelSourceEventArgs args = new CancelSourceEventArgs(source);
OnBeforeClose(args);
if (args.Cancel) return;
_OpenWidth = this.Width;
int closedWidth = _Strip.Width + this.Padding.Horizontal;
_Splitter.Visible = false;
BarFunctions.AnimateControl(this, true, _AnimationTime, this.Bounds, new Rectangle(this.Location, new Size(closedWidth, this.Height)));
_IsOpen = false;
if (_Strip.SelectedItem != null)
{
_LastOpenItem = _Strip.SelectedItem;
_Strip.SelectedItem.Checked = false;
}
else
_LastOpenItem = null;
this.Invalidate();
}
private bool _IsMenuExpanded = true;
/// <summary>
/// Indicates whether side menu is expanded, i.e. shows both image and text. When menu is collapsed only image is shown.
/// </summary>
[DefaultValue(true), Category("Appearance"), Description("Indicates whether side menu is expanded, i.e. shows both image and text. When menu is collapsed only image is shown.")]
public bool IsMenuExpanded
{
get { return _IsMenuExpanded; }
set
{
if (_IsMenuExpanded != value)
{
bool oldValue = _IsMenuExpanded;
_IsMenuExpanded = value;
OnIsMenuExpandedChanged(value, oldValue);
}
}
}
protected virtual void OnIsMenuExpandedChanged(bool newValue, bool oldValue)
{
ExpandMenu(newValue);
OnIsMenuExpandedChanged(EventArgs.Empty);
}
/// <summary>
/// Occurs when IsMenuExpanded property has changed its value.
/// </summary>
[Description("Occurs when IsMenuExpanded property has changed.")]
public event EventHandler IsMenuExpandedChanged;
/// <summary>
/// Raises IsMenuExpandedChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnIsMenuExpandedChanged(EventArgs e)
{
EventHandler h = IsMenuExpandedChanged;
if (h != null)
h(this, e);
}
private bool _IsMenuExpandedDelayedSet = false;
/// <summary>
/// Expands or collapses the control items menu.
/// </summary>
/// <param name="expand"></param>
private void ExpandMenu(bool expand)
{
if (!this.IsHandleCreated)
{
_IsMenuExpandedDelayedSet = true;
return;
}
for (int i = 0; i < _Strip.Items.Count; i++)
{
ButtonItem button = _Strip.Items[i] as ButtonItem;
if (button != null)
{
button.ButtonStyle = (expand ? eButtonStyle.ImageAndText : eButtonStyle.Default);
}
}
_Strip.RecalcLayout();
if (!_IsOpen)
this.Width = _Strip.Width + this.Padding.Horizontal;
}
private int _AnimationTime = 250;
/// <summary>
/// Indicates the animation time in milliseconds for operations that perform visual animation of transition. Set to zero to disable animation.
/// </summary>
[DefaultValue(250), Category("Behavior"), Description("Indicates the animation time in milliseconds for operations that perform visual animation of transition. Set to zero to disable animation.")]
public int AnimationTime
{
get { return _AnimationTime; }
set
{
if (value != _AnimationTime)
{
int oldValue = _AnimationTime;
_AnimationTime = value;
OnAnimationTimeChanged(oldValue, value);
}
}
}
/// <summary>
/// Called when AnimationTime property has changed.
/// </summary>
/// <param name="oldValue">Old property value</param>
/// <param name="newValue">New property value</param>
protected virtual void OnAnimationTimeChanged(int oldValue, int newValue)
{
//OnPropertyChanged(new PropertyChangedEventArgs("AnimationTime"));
}
/// <summary>
/// Occurs before the control is maximized and allows you to cancel that.
/// </summary>
[Description("Occurs before the control is maximized and allows you to cancel that.")]
public event CancelSourceEventHandler BeforeMaximize;
/// <summary>
/// Raises BeforeMaximize event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeMaximize(CancelSourceEventArgs e)
{
CancelSourceEventHandler h = BeforeMaximize;
if (h != null)
h(this, e);
}
/// <summary>
/// Occurs before the control is restored and allows you to cancel that.
/// </summary>
[Description("Occurs before the control is restored and allows you to cancel that.")]
public event CancelSourceEventHandler BeforeRestore;
/// <summary>
/// Raises BeforeRestore event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeRestore(CancelSourceEventArgs e)
{
CancelSourceEventHandler h = BeforeRestore;
if (h != null)
h(this, e);
}
/// <summary>
/// Occurs before the control is opened and allows you to cancel that.
/// </summary>
[Description("Occurs before the control is opened and allows you to cancel that.")]
public event CancelSourceEventHandler BeforeOpen;
/// <summary>
/// Raises BeforeOpen event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeOpen(CancelSourceEventArgs e)
{
CancelSourceEventHandler h = BeforeOpen;
if (h != null)
h(this, e);
}
/// <summary>
/// Occurs before the control is closed and allows you to cancel that.
/// </summary>
[Description("Occurs before the control is closed and allows you to cancel that.")]
public event CancelSourceEventHandler BeforeClose;
/// <summary>
/// Raises BeforeClose event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnBeforeClose(CancelSourceEventArgs e)
{
CancelSourceEventHandler h = BeforeClose;
if (h != null)
h(this, e);
}
protected override void OnHandleCreated(EventArgs e)
{
UpdateSelectedItemTitle();
UpdateColors();
if (_IsMenuExpandedDelayedSet)
{
ExpandMenu(_IsMenuExpanded);
_IsMenuExpandedDelayedSet = false;
}
base.OnHandleCreated(e);
}
internal void UpdateSelectedItemTitle()
{
SideNavItem item = _Strip.SelectedItem;
if (item == null) return;
if (!string.IsNullOrEmpty(item.Title))
_TitleLabel.Text = item.Title;
else
_TitleLabel.Text = item.Text;
}
private Point _SplitterMouseDownPoint = Point.Empty;
private void SplitterMouseDown(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
_SplitterMouseDownPoint = e.Location;
}
private void SplitterMouseMove(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
int maxWidth = GetMaxWidth();
int minWidth = _Strip.Width + 64;
int newWidth = this.Width + (e.X - _SplitterMouseDownPoint.X);
if (newWidth > maxWidth)
newWidth = maxWidth;
else if (newWidth < minWidth)
newWidth = minWidth;
this.Width = newWidth;
}
}
/// <summary>
/// Gets currently selected item. Only items with Panel assigned can be selected.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SideNavItem SelectedItem
{
get
{
foreach (BaseItem item in this.Items)
{
if (item is SideNavItem && ((SideNavItem)item).Checked)
{
return (SideNavItem)item;
}
}
return null;
}
set
{
if (value != null && value.Panel != null)
value.Checked = true;
}
}
/// <summary>
/// Occurs when SelectedItem changes.
/// </summary>
[Description("Occurs when SelectedItem changes.")]
public event EventHandler SelectedItemChanged;
/// <summary>
/// Raises SelectedItemChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnSelectedItemChanged(EventArgs e)
{
EventHandler h = SelectedItemChanged;
if (h != null)
h(this, e);
}
/// <summary>
/// Gets reference to internal SideNavStrip control.
/// </summary>
[Browsable(false)]
public SideNavStrip SideNavStrip
{
get { return _Strip; }
}
#endregion
}
/// <summary>
/// Defines delegate for the CancelSource events.
/// </summary>
/// <param name="sender"></param>
/// <param name="ea"></param>
public delegate void CancelSourceEventHandler(object sender, CancelSourceEventArgs e);
/// <summary>
/// Event arguments for CancelSourceEventHandler
/// </summary>
public class CancelSourceEventArgs : CancelEventArgs
{
/// <summary>
/// Gets the source of the event.
/// </summary>
public eEventSource Source = eEventSource.Code;
/// <summary>
/// Gets any optional data that is associated with the event.
/// </summary>
public object Data = null;
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="source">Source of event</param>
public CancelSourceEventArgs(eEventSource source)
{
this.Source = source;
}
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="source">Source of event</param>
/// <param name="data">Optional data associated with the event.</param>
public CancelSourceEventArgs(eEventSource source, object data)
{
this.Source = source;
this.Data = data;
}
}
}

View File

@@ -0,0 +1,791 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false), DesignTimeVisible(false)]
public class SideNavItem : ButtonItem
{
#region Private Variables & Constructor
private SideNavPanel _Panel = null;
/// <summary>
/// Initializes a new instance of the MetroTabItem class.
/// </summary>
public SideNavItem()
{
this.ButtonStyle = eButtonStyle.ImageAndText;
}
#endregion
#region Internal Implementation
public override void Paint(ItemPaintArgs p)
{
Rendering.BaseRenderer renderer = p.Renderer;
if (renderer != null)
{
SideNavItemRendererEventArgs args = new SideNavItemRendererEventArgs(this, p.Graphics);
args.ItemPaintArgs = p;
renderer.DrawSideNavItem(args);
}
if (!string.IsNullOrEmpty(NotificationMarkText))
DevComponents.DotNetBar.Rendering.NotificationMarkPainter.Paint(p.Graphics, this.Bounds, NotificationMarkPosition,
NotificationMarkText, new Size(NotificationMarkSize, NotificationMarkSize), NotificationMarkOffset, NotificationMarkColor);
if (this.DesignMode && this.Focused)
{
Rectangle r = this.Bounds;
r.Inflate(-1, -1);
DesignTime.DrawDesignTimeSelection(p.Graphics, r, p.Colors.ItemDesignTimeBorder);
}
this.DrawInsertMarker(p.Graphics);
}
public override void RecalcSize()
{
_ImageRenderBounds = Rectangle.Empty;
_TextRenderBounds = Rectangle.Empty;
base.RecalcSize();
}
private Rectangle _ImageRenderBounds = Rectangle.Empty;
/// <summary>
/// Gets or sets cached image rendering bounds.
/// </summary>
internal Rectangle ImageRenderBounds
{
get { return _ImageRenderBounds; }
set { _ImageRenderBounds = value; }
}
private Rectangle _TextRenderBounds = Rectangle.Empty;
/// <summary>
/// Gets or sets cached text rendering bounds.
/// </summary>
internal Rectangle TextRenderBounds
{
get { return _TextRenderBounds; }
set { _TextRenderBounds = value; }
}
protected override bool IsFadeEnabled
{
get
{
return false;
}
}
/// <summary>
/// Selects the tab.
/// </summary>
public void Select()
{
if (AllowSelection)
this.Checked = true;
}
/// <summary>
/// Gets or sets the panel assigned to this tab item.
/// </summary>
[Browsable(false), DefaultValue(null)]
public SideNavPanel Panel
{
get { return _Panel; }
set
{
_Panel = value;
OnPanelChanged();
}
}
private void OnPanelChanged()
{
ChangePanelVisibility();
}
/// <summary>
/// Called after Checked property has changed.
/// </summary>
protected override void OnCheckedChanged()
{
if (this.Checked && this.Parent != null)
{
ChangePanelVisibility();
foreach (BaseItem item in this.Parent.SubItems)
{
if (item == this)
continue;
SideNavItem b = item as SideNavItem;
if (b != null && b.Checked)
{
if (this.DesignMode)
TypeDescriptor.GetProperties(b)["Checked"].SetValue(b, false);
else
b.Checked = false;
}
}
}
if (BarFunctions.IsOffice2007Style(this.EffectiveStyle) && this.ContainerControl is System.Windows.Forms.Control)
((System.Windows.Forms.Control)this.ContainerControl).Invalidate();
if (!this.Checked)
ChangePanelVisibility();
InvokeCheckedChanged();
}
private void ChangePanelVisibility()
{
if (this.Checked && _Panel != null)
{
if (this.DesignMode)
{
if (!_Panel.Visible) _Panel.Visible = true;
TypeDescriptor.GetProperties(_Panel)["Visible"].SetValue(_Panel, true);
_Panel.BringToFront();
}
else
{
if (!_Panel.IsDisposed)
{
// Had to remove this optimization since in certain use-cases it caused
// .NET WinForms layout framework to move child controls inside of the panel
// Following 3 lines reduce flashing of panel's child controls when Dock panel is shown
//System.Windows.Forms.DockStyle oldDock = _Panel.Dock;
//_Panel.Dock = System.Windows.Forms.DockStyle.None;
//_Panel.Location = new Point(-32000, 32000);
_Panel.Enabled = true;
_Panel.Visible = true;
_Panel.BringToFront();
//if (_Panel.Dock != oldDock)
// _Panel.Dock = oldDock;
}
}
}
else if (!this.Checked && _Panel != null)
{
if (this.DesignMode)
TypeDescriptor.GetProperties(_Panel)["Visible"].SetValue(_Panel, false);
else
{
_Panel.Visible = false;
_Panel.Enabled = false;
}
}
}
private bool AllowSelection
{
get { return _Panel != null; }
}
/// <summary>
/// Occurs just before Click event is fired.
/// </summary>
protected override void OnClick()
{
base.OnClick();
if (_IsSystemMenu)
{
SideNavStrip strip = this.ContainerControl as SideNavStrip;
if(strip!=null && strip.Parent is SideNav)
((SideNav)strip.Parent).IsMenuExpanded = !((SideNav)strip.Parent).IsMenuExpanded;
}
else if (!this.Checked && AllowSelection)
{
if (this.DesignMode)
TypeDescriptor.GetProperties(this)["Checked"].SetValue(this, true);
else
{
SideNav nav = GetSideNav();
if (nav != null && !nav.ValidateChildren())
return;
this.Checked = true;
}
}
}
private SideNav GetSideNav()
{
SideNavStrip strip = this.ContainerControl as SideNavStrip;
if (strip == null) return null;
return strip.Parent as SideNav;
}
/// <summary>
/// Called when Visibility of the items has changed.
/// </summary>
/// <param name="bVisible">New Visible state.</param>
protected internal override void OnVisibleChanged(bool bVisible)
{
base.OnVisibleChanged(bVisible);
if (!bVisible && this.Checked)
{
TypeDescriptor.GetProperties(this)["Checked"].SetValue(this, false);
// Try to check first item in the group
if (this.Parent != null)
{
foreach (BaseItem item in this.Parent.SubItems)
{
if (item == this || !item.GetEnabled() || !item.Visible)
continue;
SideNavItem b = item as SideNavItem;
if (b != null)
{
TypeDescriptor.GetProperties(b)["Checked"].SetValue(this, true);
break;
}
}
}
}
}
/// <summary>
/// Gets or set the Group item belongs to. The groups allows a user to choose from mutually exclusive options within the group. The choice is reflected by Checked property.
/// </summary>
[Browsable(false), DevCoBrowsable(false), DefaultValue(""), EditorBrowsable(EditorBrowsableState.Never)]
public override string OptionGroup
{
get { return base.OptionGroup; }
set { base.OptionGroup = value; }
}
/// <summary>
/// Returns the collection of sub items.
/// </summary>
[Browsable(false), DevCoBrowsable(false), DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Content)]
public override SubItemsCollection SubItems
{
get { return base.SubItems; }
}
internal override void DoAccesibleDefaultAction()
{
if (AllowSelection)
this.Checked = true;
}
protected override void Invalidate(System.Windows.Forms.Control containerControl)
{
Rectangle r = m_Rect;
r.Width++;
r.Height++;
if (containerControl.InvokeRequired)
containerControl.BeginInvoke(new MethodInvoker(delegate { containerControl.Invalidate(r, true); }));
else
containerControl.Invalidate(r, true);
}
public override bool UseParentSubItemsImageSize
{
get
{
return false;
}
}
private Color[] _BackColors = null;
/// <summary>
/// Indicates the array of colors that when set are used to draw the background of the item.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the array of colors that when set are used to draw the background of the item."), TypeConverter(typeof(ArrayConverter))]
public Color[] BackColors
{
get
{
return _BackColors;
}
set
{
if (_BackColors != value)
{
_BackColors = value;
//OnPropertyChanged(new PropertyChangedEventArgs("Colors"));
this.Refresh();
}
}
}
private Color[] _BorderColors = null;
/// <summary>
/// Indicates the array of colors that when set are used to draw the border of the item.
/// </summary>
[DefaultValue(null), Category("Appearance"), Description("Indicates the array of colors that when set are used to draw the border of the item."), TypeConverter(typeof(ArrayConverter))]
public Color[] BorderColors
{
get
{
return _BorderColors;
}
set
{
if (_BorderColors != value)
{
_BorderColors = value;
//OnPropertyChanged(new PropertyChangedEventArgs("Colors"));
this.Refresh();
}
}
}
/// <summary>
/// Occurs after item visual style has changed.
/// </summary>
protected override void OnStyleChanged()
{
base.OnStyleChanged();
UpdateItemAppearance();
}
private int _PaddingHorizontal = 0;
/// <summary>
/// Gets or sets the additional padding added around the tab item in pixels. Default value is 0.
/// </summary>
[Browsable(true), DefaultValue(0), Category("Layout"), Description("Indicates additional padding added around the tab item in pixels.")]
public int PaddingHorizontal
{
get { return _PaddingHorizontal; }
set
{
_PaddingHorizontal = value;
UpdateItemAppearance();
}
}
private void UpdateItemAppearance()
{
this.VerticalPadding = 6;
this.HorizontalPadding = 14 + _PaddingHorizontal;
this.NeedRecalcSize = true;
this.OnAppearanceChanged();
}
private string _Title = "";
/// <summary>
/// Indicates an optional title for the associated panel. If not set item text is used.
/// </summary>
[DefaultValue(""), Category("Appearance"), Description("Indicates an optional title for the associated panel. If not set item text is used.")]
public string Title
{
get { return _Title; }
set
{
if (value == null) value = "";
if (_Title != value)
{
string oldValue = _Title;
_Title = value;
OnTitleChanged(value, oldValue);
}
}
}
protected virtual void OnTitleChanged(string newValue, string oldValue)
{
if (this.Checked)
{
SideNavStrip strip = this.ContainerControl as SideNavStrip;
if (strip != null && strip.Parent is SideNav)
((SideNav)strip.Parent).UpdateSelectedItemTitle();
}
}
private bool _IsSystemMenu = false;
/// <summary>
/// Gets or sets whether this item acts as the SideNav control system menu which collapses and expands the SideNav items.
/// </summary>
[DefaultValue(false), Category("Behavior"), Description("Indicates whether this item acts as the SideNav control system menu which collapses and expands the SideNav items.")]
public bool IsSystemMenu
{
get { return _IsSystemMenu; }
set
{
if (_IsSystemMenu != value)
{
bool oldValue = _IsSystemMenu;
_IsSystemMenu = value;
OnIsSystemMenuChanged(value, oldValue);
}
}
}
protected virtual void OnIsSystemMenuChanged(bool newValue, bool oldValue)
{
if (newValue && this.DesignMode)
{
if (string.IsNullOrEmpty(this.Symbol))
this.Symbol = "\uf0c9";
if (string.IsNullOrEmpty(this.Text))
this.Text = "Menu";
}
//throw new NotImplementedException();
}
#endregion
#region Hidden Properties
/// <summary>
/// Indicates whether the item will auto-collapse (fold) when clicked.
/// When item is on popup menu and this property is set to false, menu will not
/// close when item is clicked.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Behavior"), DefaultValue(true), Description("Indicates whether the item will auto-collapse (fold) when clicked.")]
public override bool AutoCollapseOnClick
{
get
{
return base.AutoCollapseOnClick;
}
set
{
base.AutoCollapseOnClick = value;
}
}
/// <summary>
/// Indicates whether the item will auto-expand when clicked.
/// When item is on top level bar and not on menu and contains sub-items, sub-items will be shown only if user
/// click the expand part of the button. Setting this propert to true will expand the button and show sub-items when user
/// clicks anywhere inside of the button. Default value is false which indicates that button is expanded only
/// if its expand part is clicked.
/// </summary>
[DefaultValue(false), Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DevCoBrowsable(false), Category("Behavior"), Description("Indicates whether the item will auto-collapse (fold) when clicked.")]
public override bool AutoExpandOnClick
{
get
{
return base.AutoExpandOnClick;
}
set
{
base.AutoExpandOnClick = value;
}
}
/// <summary>
/// Gets or sets whether item can be customized by end user.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(true), System.ComponentModel.Category("Behavior"), System.ComponentModel.Description("Indicates whether item can be customized by user.")]
public override bool CanCustomize
{
get
{
return base.CanCustomize;
}
set
{
base.CanCustomize = value;
}
}
/// <summary>
/// Gets or set a value indicating whether the button is in the checked state.
/// </summary>
[Browsable(false), DevCoBrowsable(false), Category("Appearance"), Description("Indicates whether item is checked or not."), DefaultValue(false)]
public override bool Checked
{
get
{
return base.Checked;
}
set
{
base.Checked = value;
}
}
/// <summary>
/// Gets or sets whether Click event will be auto repeated when mouse button is kept pressed over the item.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(false), Category("Behavior"), Description("Gets or sets whether Click event will be auto repeated when mouse button is kept pressed over the item.")]
public override bool ClickAutoRepeat
{
get
{
return base.ClickAutoRepeat;
}
set
{
base.ClickAutoRepeat = value;
}
}
/// <summary>
/// Gets or sets the auto-repeat interval for the click event when mouse button is kept pressed over the item.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(600), Category("Behavior"), Description("Gets or sets the auto-repeat interval for the click event when mouse button is kept pressed over the item.")]
public override int ClickRepeatInterval
{
get
{
return base.ClickRepeatInterval;
}
set
{
base.ClickRepeatInterval = value;
}
}
/// <summary>
/// Gets or sets a value indicating whether the item is enabled.
/// </summary>
[Browsable(false), DevCoBrowsable(false), DefaultValue(true), Category("Behavior"), Description("Indicates whether is item enabled.")]
public override bool Enabled
{
get
{
return base.Enabled;
}
set
{
base.Enabled = value;
}
}
/// <summary>
/// Indicates item's visiblity when on pop-up menu.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Appearance"), Description("Indicates item's visiblity when on pop-up menu."), DefaultValue(eMenuVisibility.VisibleAlways)]
public override eMenuVisibility MenuVisibility
{
get
{
return base.MenuVisibility;
}
set
{
base.MenuVisibility = value;
}
}
/// <summary>
/// Indicates when menu items are displayed when MenuVisiblity is set to VisibleIfRecentlyUsed and RecentlyUsed is true.
/// </summary>
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DevCoBrowsable(false), Category("Appearance"), Description("Indicates when menu items are displayed when MenuVisiblity is set to VisibleIfRecentlyUsed and RecentlyUsed is true."), DefaultValue(ePersonalizedMenus.Disabled)]
public override ePersonalizedMenus PersonalizedMenus
{
get
{
return base.PersonalizedMenus;
}
set
{
base.PersonalizedMenus = value;
}
}
/// <summary>
/// Indicates Animation type for Popups.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Behavior"), Description("Indicates Animation type for Popups."), DefaultValue(ePopupAnimation.ManagerControlled)]
public override ePopupAnimation PopupAnimation
{
get
{
return base.PopupAnimation;
}
set
{
base.PopupAnimation = value;
}
}
/// <summary>
/// Indicates the font that will be used on the popup window.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Appearance"), Description("Indicates the font that will be used on the popup window."), DefaultValue(null)]
public override System.Drawing.Font PopupFont
{
get
{
return base.PopupFont;
}
set
{
base.PopupFont = value;
}
}
/// <summary>
/// Indicates whether sub-items are shown on popup Bar or popup menu.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Appearance"), Description("Indicates whether sub-items are shown on popup Bar or popup menu."), DefaultValue(ePopupType.Menu)]
public override ePopupType PopupType
{
get
{
return base.PopupType;
}
set
{
base.PopupType = value;
}
}
/// <summary>
/// Specifies the inital width for the Bar that hosts pop-up items. Applies to PopupType.Toolbar only.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Layout"), Description("Specifies the inital width for the Bar that hosts pop-up items. Applies to PopupType.Toolbar only."), DefaultValue(200)]
public override int PopupWidth
{
get
{
return base.PopupWidth;
}
set
{
base.PopupWidth = value;
}
}
/// <summary>
/// Gets or sets whether item will display sub items.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(true), Category("Behavior"), Description("Determines whether sub-items are displayed.")]
public override bool ShowSubItems
{
get
{
return base.ShowSubItems;
}
set
{
base.ShowSubItems = value;
}
}
/// <summary>
/// Gets or sets whether the item expands automatically to fill out the remaining space inside the container. Applies to Items on stretchable, no-wrap Bars only.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), DefaultValue(false), Category("Appearance"), Description("Indicates whether item will stretch to consume empty space. Items on stretchable, no-wrap Bars only.")]
public override bool Stretch
{
get
{
return base.Stretch;
}
set
{
base.Stretch = value;
}
}
/// <summary>
/// Gets or sets the width of the expand part of the button item.
/// </summary>
[Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), Category("Behavior"), Description("Indicates the width of the expand part of the button item."), DefaultValue(12)]
public override int SubItemsExpandWidth
{
get { return base.SubItemsExpandWidth; }
set
{
base.SubItemsExpandWidth = value;
}
}
/// <summary>
/// Gets or set the alternative shortcut text.
/// </summary>
[System.ComponentModel.Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DevCoBrowsable(false), System.ComponentModel.Category("Design"), System.ComponentModel.Description("Gets or set the alternative Shortcut Text. This text appears next to the Text instead of any shortcuts"), System.ComponentModel.DefaultValue("")]
public override string AlternateShortCutText
{
get
{
return base.AlternateShortCutText;
}
set
{
base.AlternateShortCutText = value;
}
}
/// <summary>
/// Gets or sets whether item separator is shown before this item.
/// </summary>
[System.ComponentModel.Browsable(false), DevCoBrowsable(false), System.ComponentModel.DefaultValue(false), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("Indicates whether this item is beginning of the group.")]
public override bool BeginGroup
{
get
{
return base.BeginGroup;
}
set
{
base.BeginGroup = value;
}
}
/// <summary>
/// Returns category for this item. If item cannot be customzied using the
/// customize dialog category is empty string.
/// </summary>
[System.ComponentModel.Browsable(false), DevCoBrowsable(false), System.ComponentModel.DefaultValue(""), System.ComponentModel.Category("Design"), System.ComponentModel.Description("Indicates item category used to group similar items at design-time."), EditorBrowsable(EditorBrowsableState.Never)]
public override string Category
{
get
{
return base.Category;
}
set
{
base.Category = value;
}
}
/// <summary>
/// Gets or sets the text color of the button when mouse is over the item.
/// </summary>
[System.ComponentModel.Browsable(false), DevCoBrowsable(false), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("The foreground color used to display text when mouse is over the item."), EditorBrowsable(EditorBrowsableState.Never)]
public override Color HotForeColor
{
get
{
return base.HotForeColor;
}
set
{
base.HotForeColor = value;
}
}
/// <summary>
/// Indicates the way item is painting the picture when mouse is over it. Setting the value to Color will render the image in gray-scale when mouse is not over the item.
/// </summary>
[System.ComponentModel.Browsable(false), DevCoBrowsable(false), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("Indicates the way item is painting the picture when mouse is over it. Setting the value to Color will render the image in gray-scale when mouse is not over the item."), System.ComponentModel.DefaultValue(eHotTrackingStyle.Default), EditorBrowsable(EditorBrowsableState.Never)]
public override eHotTrackingStyle HotTrackingStyle
{
get { return base.HotTrackingStyle; }
set
{
base.HotTrackingStyle = value;
}
}
/// <summary>
/// Gets/Sets the button style which controls the appearance of the button elements. Changing the property can display image only, text only or image and text on the button at all times.
/// </summary>
[Browsable(false), Category("Appearance"), Description("Determines the style of the button."), DefaultValue(eButtonStyle.ImageAndText), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public override eButtonStyle ButtonStyle
{
get
{
return base.ButtonStyle;
}
set
{
base.ButtonStyle = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,33 @@
using DevComponents.DotNetBar.Controls;
using System;
using System.Collections.Generic;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
internal class SideNavItemPainter : IOffice2007Painter
{
/// <summary>
/// Paints ListBoxItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public virtual void Paint(SideNavItemRendererEventArgs e) { }
#region IOffice2007Painter Members
private Office2007ColorTable _ColorTable = null; //new Office2007ColorTable();
public Office2007ColorTable ColorTable
{
get
{
return _ColorTable;
}
set
{
_ColorTable = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,42 @@
using DevComponents.DotNetBar.Controls;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Provides data for the SideNavItem rendering events.
/// </summary>
public class SideNavItemRendererEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the reference to the item being rendered.
/// </summary>
public SideNavItem Item = null;
/// <summary>
/// Gets or sets the reference to graphics object.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Indicates whether to cancel system rendering of the item.
/// </summary>
public bool Cancel = false;
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Creates new instance of the object and initializes it with default values.
/// </summary>
/// <param name="item">Reference to the ListBoxItem being rendered.</param>
/// <param name="g">Reference to the graphics object.</param>
public SideNavItemRendererEventArgs(SideNavItem item, Graphics g)
{
this.Item = item;
this.Graphics = g;
}
}
}

View File

@@ -0,0 +1,115 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace DevComponents.DotNetBar.Rendering
{
/// <summary>
/// Defines color table for SideNav control.
/// </summary>
public class SideNavColorTable
{
/// <summary>
/// Gets or sets the color table for SideNavItem
/// </summary>
public SideNavItemColorTable SideNavItem = new SideNavItemColorTable();
/// <summary>
/// Gets or sets the background color of SideNav title bar.
/// </summary>
public Color TitleBackColor = Color.Empty;
/// <summary>
/// Gets or sets the border color of the title of SideNav control.
/// </summary>
public Color[] TitleBorderColors = new Color[0];
/// <summary>
/// Gets or sets the color of the strip which hosts the items.
/// </summary>
public Color ItemsBackColor = Color.Empty;
/// <summary>
/// Gets or sets the border color of the SideNav control.
/// </summary>
public Color[] BorderColors = new Color[0];
/// <summary>
/// Gets or sets the back color of panels that are attached to SideNavItem and displayed when SideNavItem is selected.
/// </summary>
public Color PanelBackColor = Color.Empty;
}
/// <summary>
/// Defines color table for SideNavItem
/// </summary>
public class SideNavItemColorTable
{
/// <summary>
/// Gets or sets the color table for Default state.
/// </summary>
public SideNavItemStateColorTable Default = new SideNavItemStateColorTable();
/// <summary>
/// Gets or sets the color table for MouseOver state.
/// </summary>
public SideNavItemStateColorTable MouseOver = new SideNavItemStateColorTable();
/// <summary>
/// Gets or sets the color table for Pressed state.
/// </summary>
public SideNavItemStateColorTable Pressed = new SideNavItemStateColorTable();
/// <summary>
/// Gets or sets the color table for Selected state.
/// </summary>
public SideNavItemStateColorTable Selected = new SideNavItemStateColorTable();
}
/// <summary>
/// Defines state color table for SideNavItem
/// </summary>
public class SideNavItemStateColorTable
{
public SideNavItemStateColorTable()
{
}
public SideNavItemStateColorTable(Color textColor)
{
this.TextColor = textColor;
}
public SideNavItemStateColorTable(Color textColor, Color[] backColors, Color[] borderColors)
{
this.TextColor = textColor;
this.BackColors = backColors;
this.BorderColors = borderColors;
}
public SideNavItemStateColorTable(Color textColor, Color[] backColors, Color[] borderColors, int cornerRadius)
{
this.TextColor = textColor;
this.BackColors = backColors;
this.BorderColors = borderColors;
this.CornerRadius = cornerRadius;
}
/// <summary>
/// Indicates item text color.
/// </summary>
public Color TextColor = Color.Black;
/// <summary>
/// Gets or sets the background colors for the item.
/// </summary>
public Color[] BackColors = new Color[0];
/// <summary>
/// Gets or sets the back colors gradient angle if there is more than one color in BackColors array.
/// </summary>
public int BackColorsGradientAngle = 90;
/// <summary>
/// Gets or sets the gradient colors positions if there is more than one color in BackColors array.
/// </summary>
public float[] BackColorsPositions = new float[0];
/// <summary>
/// Gets or sets the border colors for the item.
/// </summary>
public Color[] BorderColors = new Color[0];
/// <summary>
/// Indicates the corner radius.
/// </summary>
public int CornerRadius = 0;
}
}

View File

@@ -0,0 +1,148 @@
using DevComponents.DotNetBar.Rendering;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Reflection;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
namespace DevComponents.DotNetBar.Controls
{
/// <summary>
/// Represents a panel which hosts controls for the SideNavItem.
/// </summary>
[ToolboxItem(false)]
public class SideNavPanel : Panel, IScrollBarOverrideSupport
{
private ScrollbarSkinner _ScrollSkinner = null;
public SideNavPanel()
{
this.SetStyle(ControlStyles.AllPaintingInWmPaint
| ControlStyles.ResizeRedraw
| DisplayHelp.DoubleBufferFlag
| ControlStyles.UserPaint
| ControlStyles.Opaque
, true);
_ScrollSkinner = new ScrollbarSkinner(this);
}
protected override void Dispose(bool disposing)
{
_ScrollSkinner.Dispose();
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
Color backColor = GetBackColor();
if (!backColor.IsEmpty)
{
using (SolidBrush brush = new SolidBrush(backColor))
e.Graphics.FillRectangle(brush, this.ClientRectangle);
}
base.OnPaint(e);
}
private Color _BackColor = Color.Empty;
protected override void OnBackColorChanged(EventArgs e)
{
PropertyInfo prop = typeof (Control).GetProperty("RawBackColor",
BindingFlags.GetProperty | BindingFlags.NonPublic | BindingFlags.Instance);
if (prop != null)
{
_BackColor = (Color)prop.GetValue(this, null);
}
base.OnBackColorChanged(e);
}
private Color GetBackColor()
{
if(!_BackColor.IsEmpty)
return _BackColor;
return GetColorTable().PanelBackColor;
}
private SideNavColorTable GetColorTable()
{
return ((Office2007Renderer)GlobalManager.Renderer).ColorTable.SideNav;
}
protected override void WndProc(ref Message m)
{
//Console.WriteLine("{0} Message {1}", DateTime.Now, MapMessage(m.Msg));
if (m.Msg == (int)WinApi.WindowsMessages.WM_VSCROLL || m.Msg == (int)WinApi.WindowsMessages.WM_HSCROLL || m.Msg == (int)WinApi.WindowsMessages.WM_MOUSEWHEEL)
{
base.WndProc(ref m);
OnScrollBarValueChanged(new ScrollValueChangedEventArgs(ScrollbarControl.MapMessageToScrollChange(m.Msg)));
return;
}
else if (m.Msg == (int)WinApi.WindowsMessages.WM_NCCALCSIZE)
{
base.WndProc(ref m);
OnNonClientSizeChanged(EventArgs.Empty);
return;
}
else if (m.Msg == 206 || m.Msg == 8270) // Internal RichTextBox message we use to trigger scroll-bar update
{
base.WndProc(ref m);
OnScrollBarValueChanged(new ScrollValueChangedEventArgs(eScrollBarScrollChange.Horizontal | eScrollBarScrollChange.Vertical));
return;
}
else if (m.Msg == (int)WinApi.WindowsMessages.WM_MOVE) // Internal RichTextBox message we use to trigger scroll-bar update
{
base.WndProc(ref m);
OnControlMoved(EventArgs.Empty);
return;
}
base.WndProc(ref m);
}
#region IScrollBarOverrideSupport Members
[Browsable(false)]
public event EventHandler NonClientSizeChanged;
/// <summary>
/// Raises NonClientSizeChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnNonClientSizeChanged(EventArgs e)
{
EventHandler handler = NonClientSizeChanged;
if (handler != null)
handler(this, e);
}
public event ScrollValueChangedHandler ScrollBarValueChanged;
/// <summary>
/// Raises ScrollBarValueChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnScrollBarValueChanged(ScrollValueChangedEventArgs e)
{
ScrollValueChangedHandler handler = ScrollBarValueChanged;
if (handler != null)
handler(this, e);
}
[Browsable(false)]
public event EventHandler ControlMoved;
/// <summary>
/// Raises NonClientSizeChanged event.
/// </summary>
/// <param name="e">Provides event arguments.</param>
protected virtual void OnControlMoved(EventArgs e)
{
EventHandler handler = ControlMoved;
if (handler != null)
handler(this, e);
}
bool IScrollBarOverrideSupport.DesignMode
{
get
{
return this.DesignMode;
}
}
#endregion
}
}

View File

@@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using DevComponents.DotNetBar.Rendering;
using System.Drawing;
using DevComponents.AdvTree.Layout;
namespace DevComponents.DotNetBar.Controls
{
[ToolboxItem(false)]
public class SideNavStrip : ItemControl
{
#region Constructor
private SimpleItemContainer _ItemContainer = null;
public SideNavStrip()
{
_ItemContainer = new SimpleItemContainer();
_ItemContainer.GlobalItem = false;
_ItemContainer.ContainerControl = this;
_ItemContainer.Stretch = true;
_ItemContainer.Displayed = true;
_ItemContainer.Style = eDotNetBarStyle.StyleManagerControlled;
_ItemContainer.LayoutOrientation = eOrientation.Vertical;
//base.AutoSize = true;
this.ColorScheme.Style = eDotNetBarStyle.StyleManagerControlled;
_ItemContainer.SetOwner(this);
this.SetBaseItemContainer(_ItemContainer);
this.BackgroundStyle.Class = ElementStyleClassKeys.SideNavStripKey;
StyleManager.Register(this);
}
#endregion
#region Implementation
/// <summary>
/// Called by StyleManager to notify control that style on manager has changed and that control should refresh its appearance if
/// its style is controlled by StyleManager.
/// </summary>
/// <param name="newStyle">New active style.</param>
[EditorBrowsable(EditorBrowsableState.Never)]
public void StyleManagerStyleChanged(eDotNetBarStyle newStyle)
{
_ItemContainer.NeedRecalcSize = true;
}
/// <summary>
/// Returns collection of items on a bar.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false)]
public SubItemsCollection Items
{
get
{
return _ItemContainer.SubItems;
}
}
/// <summary>
/// Gets currently selected item.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SideNavItem SelectedItem
{
get
{
foreach (BaseItem item in this.Items)
{
if (item is SideNavItem && ((SideNavItem)item).Checked)
{
return (SideNavItem)item;
}
}
return null;
}
set
{
if (value != null && value.Panel != null)
value.Checked = true;
}
}
protected override void PaintControl(ItemPaintArgs pa)
{
base.PaintControl(pa);
SideNavItem selectedItem = this.SelectedItem;
if (selectedItem != null)
{
Color color = GetBorderColor();
if (!color.IsEmpty)
{
Graphics g = pa.Graphics;
using (Pen pen = new Pen(color))
{
if (selectedItem.TopInternal > 0)
g.DrawLine(pen, this.Width - 1, 0, this.Width - 1, selectedItem.TopInternal - 1);
if (selectedItem.Bounds.Bottom < this.Height)
g.DrawLine(pen, this.Width - 1, selectedItem.Bounds.Bottom, this.Width - 1, this.Height);
}
}
}
}
private Color GetBorderColor()
{
SideNavColorTable ct = GetColorTable();
if (ct.BorderColors != null && ct.BorderColors.Length > 0)
return ct.BorderColors[0];
return Color.Empty;
}
private SideNavColorTable GetColorTable()
{
return ((Office2007Renderer)GlobalManager.Renderer).ColorTable.SideNav;
}
internal void SelectFirstItem()
{
foreach (BaseItem item in this.Items)
{
if (item.Visible && item.Enabled && item is SideNavItem)
{
((SideNavItem)item).Checked = true;
break;
}
}
}
protected override void OnButtonCheckedChanged(ButtonItem item, EventArgs e)
{
if (this.Parent is SideNav)
((SideNav)this.Parent).UpdateSelectedItemTitle();
base.OnButtonCheckedChanged(item, e);
}
#endregion
}
}