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,572 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Drawing;
using DevComponents.DotNetBar.Rendering;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the Office Application Button displayed in the top-left corner of the Ribbon Control.
/// </summary>
[System.ComponentModel.ToolboxItem(false), System.ComponentModel.DesignTimeVisible(false), DefaultEvent("Click"), Designer("DevComponents.DotNetBar.Design.ApplicationButtonDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class ApplicationButton : ButtonItem
{
private const string SysBackstageBackButtonName = "sys_backstage_back_button";
private const string SysBackstagePanelName = "sys_backstage_panel";
#region Private Variables
private bool m_ThumbTucked = false;
#endregion
#region Internal Implementation
protected override void Dispose(bool disposing)
{
if(_BackstageTab!=null)
_BackstageTab.Leave -= BackstageTabLeave;
base.Dispose(disposing);
}
public override void RecalcSize()
{
ButtonItemLayout.LayoutButton(this, true);
m_NeedRecalcSize = false;
}
/// <summary>
/// Gets or sets a value indicating whether the item is expanded or not. For Popup items this would indicate whether the item is popped up or not.
/// </summary>
[System.ComponentModel.Browsable(false), System.ComponentModel.DefaultValue(false), System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public override bool Expanded
{
get { return base.Expanded; }
set
{
if (base.Expanded != value)
{
if (!value)
{
RibbonStrip container = this.ContainerControl as RibbonStrip;
if (container != null && container.MouseDownOnCaption)
return;
}
base.Expanded = value;
}
}
}
protected internal override void OnExpandChange()
{
m_ThumbTucked = false;
if (!this.DesignMode && this.Expanded && this.PopupLocation.IsEmpty && this.PopupSide == ePopupSide.Default &&
(this.Parent is CaptionItemContainer ||
this.Parent is RibbonTabItemContainer))
{
if (this.SubItems.Count > 0 && this.SubItems[0] is ItemContainer &&
((ItemContainer)this.SubItems[0]).BackgroundStyle.Class == ElementStyleClassKeys.RibbonFileMenuContainerKey)
{
RibbonStrip rs = this.ContainerControl as RibbonStrip;
if (rs != null)
{
if (this.Parent is RibbonTabItemContainer)
{
if (this.EffectiveStyle == eDotNetBarStyle.Windows7)
this.PopupLocation = new Point(this.IsRightToLeft ? this.Bounds.Right : this.LeftInternal, this.TopInternal - 1);
else if (StyleManager.IsMetro(this.EffectiveStyle))
{
this.PopupLocation = new Point(this.IsRightToLeft ? this.Bounds.Right : this.LeftInternal - 4, this.TopInternal);
}
else
this.PopupLocation = new Point(this.IsRightToLeft ? this.Bounds.Right : this.LeftInternal, this.TopInternal);
}
else
this.PopupLocation = new Point(this.IsRightToLeft ? this.Bounds.Right : this.LeftInternal, rs.GetItemContainerBounds().Y - 1);
this.VerifyPopupScreenPosition = false;
m_ThumbTucked = true;
}
}
}
_WasMaximized = false;
if (_BackstageTab != null && _BackstageTabEnabled)
{
PopupManager.CloseAllPopups();
if (this.Expanded)
{
PopupOpenEventArgs args = new PopupOpenEventArgs();
OnPopupOpen(args);
if (args.Cancel)
{
this.Expanded = false;
return;
}
if (StyleManager.IsMetro(EffectiveStyle))
{
CreateBackstageBackButton();
if (_BackstageTab.Parent is Form && ((Form)_BackstageTab.Parent).WindowState == FormWindowState.Maximized)
_WasMaximized = true;
}
else
RemoveBackstageBackButton();
UpdateBackstageTabSize();
if (this.ContainerControl is IKeyTipsControl)
{
IKeyTipsControl kc = this.ContainerControl as IKeyTipsControl;
_BackstageTab.TabStrip.ShowKeyTips = kc.ShowKeyTips;
kc.ShowKeyTips = false;
}
OnPopupShowing(EventArgs.Empty);
_BackstageTab.Visible = true;
_BackstageTab.BringToFront();
_BackstageTab.Focus();
if (_BackstageTab.SelectedPanel != null)
_BackstageTab.SelectedPanel.BringToFront();
RibbonStrip strip = this.RibbonStrip;
if (StyleManager.IsMetro(EffectiveStyle) && strip != null)
{
((RibbonStripContainerItem)strip.GetBaseItemContainer()).MetroBackstageOpen = true;
strip.TabGroupPaintSuspended = true;
}
if (strip != null && strip.SelectedRibbonTabItem != null)
{
_LastSelectedRibbonTabItem = strip.SelectedRibbonTabItem;
if (this.DesignMode)
_LastSelectedRibbonTabItem.RenderTabState = false;
else
_LastSelectedRibbonTabItem.Checked = false;
}
}
else
{
OnPopupClose(EventArgs.Empty);
if (_LastSelectedRibbonTabItem != null)
{
if (this.DesignMode)
_LastSelectedRibbonTabItem.RenderTabState = true;
else
_LastSelectedRibbonTabItem.Checked = true;
_LastSelectedRibbonTabItem = null;
}
if (this.ContainerControl is IKeyTipsControl)
{
IKeyTipsControl kc = this.ContainerControl as IKeyTipsControl;
kc.ShowKeyTips = _BackstageTab.TabStrip.ShowKeyTips;
_BackstageTab.TabStrip.ShowKeyTips = false;
}
_BackstageTab.Visible = false;
RibbonStrip strip = this.ContainerControl as RibbonStrip;
if (StyleManager.IsMetro(EffectiveStyle))
{
_BackstageTab.Resize -= BackstageTabResized;
_BackstageTab.TabStrip.Resize -= BackstageTabResized;
if (strip != null)
{
((RibbonStripContainerItem)strip.GetBaseItemContainer()).MetroBackstageOpen = false;
strip.TabGroupPaintSuspended = false;
}
}
if (strip != null)
{
strip.BackstageTabClosed(_BackstageTab);
strip.Invalidate();
}
OnPopupFinalized(EventArgs.Empty);
}
RaiseExpandChange(EventArgs.Empty);
return;
}
base.OnExpandChange();
}
private void CreateBackstageBackButton()
{
if (_BackstageTab.Tabs.Contains(SysBackstageBackButtonName))
return;
ButtonItem back = new ButtonItem(SysBackstageBackButtonName);
back.ColorTable = eButtonColor.BlueOrb;
back.Symbol = "\uf060";
back.Shape = new EllipticalShapeDescriptor();
back.Click += new EventHandler(BackButtonClick);
back.FixedSize = new Size(35, 35);
back.Margin = new Padding(10, 0, 15, 15);
back.SetSystemItem(true);
_BackstageTab.Tabs.Insert(0, back);
back.SetDesignMode(false);
// Insert top dock panel which is excluded by region but will move the tab content down
Panel panel = new Panel();
panel.Dock = DockStyle.Top;
panel.Name = SysBackstagePanelName;
_BackstageTab.Controls.Add(panel);
panel.BringToFront();
}
private void RemoveBackstageBackButton()
{
if (!_BackstageTab.Tabs.Contains(SysBackstageBackButtonName))
return;
_BackstageTab.Tabs.Remove(SysBackstageBackButtonName);
Panel panel = (Panel)_BackstageTab.Controls[SysBackstagePanelName];
_BackstageTab.Controls.Remove(panel);
panel.Dispose();
}
void BackButtonClick(object sender, EventArgs e)
{
this.Expanded = false;
}
public override void ContainerLostFocus(bool appLostFocus)
{
if (_BackstageTabEnabled && _BackstageTab != null && this.DesignMode && this.Expanded && appLostFocus) return;
base.ContainerLostFocus(appLostFocus);
}
internal override bool PopupPositionAdjusted
{
get { return base.PopupPositionAdjusted; }
set
{
base.PopupPositionAdjusted = value;
if (base.PopupPositionAdjusted && m_ThumbTucked)
m_ThumbTucked = false;
}
}
internal void OnMenuPaint(ItemPaintArgs pa)
{
if (!m_ThumbTucked) return;
Graphics g = pa.Graphics;
RibbonStrip rs = this.ContainerControl as RibbonStrip;
if (rs != null)
{
if (this.Parent is RibbonTabItemContainer)
{
if (pa.RightToLeft)
g.TranslateTransform(-(this.LeftInternal - pa.ContainerControl.Width + this.WidthInternal), -(this.TopInternal));
else
{
if (this.EffectiveStyle == eDotNetBarStyle.Windows7)
g.TranslateTransform(-this.LeftInternal, -(this.TopInternal - 1));
else
g.TranslateTransform(-this.LeftInternal, -(this.TopInternal));
}
}
else
{
if (pa.RightToLeft)
g.TranslateTransform(-(this.LeftInternal - pa.ContainerControl.Width + this.WidthInternal), -(rs.GetItemContainerBounds().Y - 1));
else
g.TranslateTransform(-this.LeftInternal, -(rs.GetItemContainerBounds().Y - 1));
}
g.ResetClip();
Control c = pa.ContainerControl;
pa.ContainerControl = rs;
pa.IsOnMenu = false;
this.IgnoreAlpha = true;
bool oldGlassEnabled = pa.GlassEnabled;
pa.GlassEnabled = rs.IsGlassEnabled;
_MenuOverlayPaint = true;
this.Paint(pa);
_MenuOverlayPaint = false;
pa.GlassEnabled = oldGlassEnabled;
this.IgnoreAlpha = false;
pa.ContainerControl = c;
pa.IsOnMenu = true;
g.ResetTransform();
}
}
protected override void OnCommandChanged()
{
}
protected override bool IsRightHanded
{
get
{
return false;
}
}
private bool _MenuOverlayPaint = false;
internal bool IsMenuOverlayPaint
{
get
{
return _MenuOverlayPaint;
}
}
protected override void OnStyleChanged()
{
if (this.EffectiveStyle == eDotNetBarStyle.Office2010)
{
this.ImagePaddingHorizontal = 0;
this.ImagePaddingVertical = 0;
}
else if (this.EffectiveStyle == eDotNetBarStyle.Windows7)
{
this.ImagePaddingHorizontal = 0;
this.ImagePaddingVertical = 0;
}
else if (StyleManager.IsMetro(this.EffectiveStyle))
{
this.ImagePaddingHorizontal = 0;
this.ImagePaddingVertical = 1;
}
else
{
if (ImagePaddingVertical == 0) ImagePaddingVertical = 2;
if (ImagePaddingHorizontal == 0) ImagePaddingHorizontal = 2;
}
base.OnStyleChanged();
}
protected override bool IsPulseEnabed
{
get
{
if ((this.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(this.EffectiveStyle)) && WinApi.IsGlassEnabled) return false;
return base.IsPulseEnabed;
}
}
private void UpdateBackstageTabSize()
{
if (_BackstageTab == null) return;
Control parentForm = _BackstageTab.Parent;
if (parentForm == null) throw new InvalidOperationException("BackstageTab control does not have a parent");
Rectangle tabBounds = parentForm.ClientRectangle;
RibbonStrip strip = this.RibbonStrip;
if (strip != null)
{
if (StyleManager.IsMetro(this.EffectiveStyle))
{
tabBounds = new Rectangle(1, 1, parentForm.Width - 2, parentForm.Height - 2);
Form form = parentForm as Form;
if (form != null && form.WindowState == FormWindowState.Maximized)
{
if (form is RibbonForm)
{
NonClientInfo nci = ((RibbonForm)form).GetNonClientInfo();
tabBounds.Width -= nci.LeftBorder;
tabBounds.Height -= nci.BottomBorder;
}
else
{
tabBounds.Width -= SystemInformation.FrameBorderSize.Width;
tabBounds.Height -= SystemInformation.FrameBorderSize.Height;
}
}
}
else
{
Point p = parentForm.PointToClient(strip.PointToScreen(this.Bounds.Location));
p.Y += this.Bounds.Height;// +1;
tabBounds = new Rectangle(p.X, p.Y, parentForm.ClientRectangle.Width, parentForm.ClientRectangle.Height - p.Y);
RibbonForm ribbonForm = parentForm as RibbonForm;
if (ribbonForm != null)
{
if (!ribbonForm.IsGlassEnabled)
{
tabBounds.Width -= ribbonForm.BorderSize * 2;
tabBounds.Height -= ribbonForm.BorderSize;
}
}
}
}
_BackstageTab.Bounds = tabBounds;
if (StyleManager.IsMetro(this.EffectiveStyle))
{
_BackstageTab.Resize += BackstageTabResized;
_BackstageTab.TabStrip.Resize += BackstageTabResized;
if (_BackstageTab.IsHandleCreated)
UpdateBackstageTabSizeAndRegion();
else
_BackstageTab.HandleCreated += new EventHandler(BackstageTabHandleCreated);
}
else if(_BackstageTab.Region != null)
_BackstageTab.Region = null;
_BackstageTab.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Top;
}
private void UpdateBackstageTabSizeAndRegion()
{
_BackstageTab.RecalcLayout();
UpdateBackstageTabMetroRegion();
}
void BackstageTabHandleCreated(object sender, EventArgs e)
{
_BackstageTab.HandleCreated -= new EventHandler(BackstageTabHandleCreated);
BarUtilities.InvokeDelayed(new MethodInvoker(delegate { UpdateBackstageTabSizeAndRegion(); }), 50);
}
private bool _WasMaximized = false;
private void BackstageTabResized(object sender, EventArgs e)
{
if (StyleManager.IsMetro(this.EffectiveStyle))
{
Form parentForm = _BackstageTab.Parent as Form;
if (parentForm != null && parentForm.WindowState == FormWindowState.Maximized)
_WasMaximized = true;
else if (_WasMaximized)
{
_WasMaximized = false;
UpdateBackstageTabSize();
return;
}
}
UpdateBackstageTabMetroRegion();
}
private void UpdateBackstageTabMetroRegion()
{
int captionHeight = 28;
RibbonStrip strip = RibbonStrip;
if (strip != null) captionHeight = strip.GetTotalCaptionHeight();
_BackstageTab.Controls[SysBackstagePanelName].Height = captionHeight;
Rectangle tabBounds = _BackstageTab.ClientRectangle;
System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
path.AddLine(0, 0, _BackstageTab.TabStrip.Width, 0);
path.AddLine(_BackstageTab.TabStrip.Width, 0, _BackstageTab.TabStrip.Width, captionHeight);
path.AddLine(_BackstageTab.TabStrip.Width, captionHeight, tabBounds.Width, captionHeight);
path.AddLine(tabBounds.Width, tabBounds.Height, 0, tabBounds.Height);
path.CloseAllFigures();
Region reg = new Region(path);
_BackstageTab.Region = reg;
path.Dispose();
}
private RibbonTabItem _LastSelectedRibbonTabItem = null;
private RibbonStrip RibbonStrip
{
get
{
return this.ContainerControl as RibbonStrip;
}
}
private bool _BackstageTabEnabled = true;
/// <summary>
/// Gets or sets whether control set on BackstageTab property is used on application menu popup.
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Indicates whether control set on BackstageTab property is used on application menu popup.")]
public bool BackstageTabEnabled
{
get { return _BackstageTabEnabled; }
set
{
this.Expanded = false;
_BackstageTabEnabled = value;
}
}
private SuperTabControl _BackstageTab = null;
/// <summary>
/// Gets or sets the backstage tab that is displayed instead of popup menu.
/// </summary>
[DefaultValue(null), Category("Behavior"), Description("Indicates backstage tab that is displayed instead of popup menu.")]
public SuperTabControl BackstageTab
{
get
{
return _BackstageTab;
}
set
{
SuperTabControl oldValue = _BackstageTab;
_BackstageTab = value;
OnBackstageTabChanged(oldValue, value);
}
}
private void OnBackstageTabChanged(SuperTabControl oldValue, SuperTabControl newValue)
{
if (oldValue != null)
{
oldValue.Leave -= BackstageTabLeave;
if (oldValue.TabStrip != null) oldValue.TabStrip.ApplicationButton = null;
}
if (this.Expanded) this.Expanded = false;
if (newValue != null)
{
newValue.Visible = false;
newValue.Leave += BackstageTabLeave;
if (newValue.TabStrip != null) newValue.TabStrip.ApplicationButton = this;
}
}
private void BackstageTabLeave(object sender, EventArgs e)
{
if (this.Expanded)
this.Expanded = false;
}
/// <summary>
/// Processes the Escape key when Application Button is hosting the backstage tab and uses it to close the tab if open.
/// This method is called from ProcessDialogKey method of Office2007RibbonForm.
/// </summary>
/// <param name="keyData">Key data</param>
/// <returns>true if key was used to close backstage tab</returns>
[EditorBrowsable(EditorBrowsableState.Never)]
public bool ProcessEscapeKey(Keys keyData)
{
if (keyData == Keys.Escape && this.Expanded)
{
this.Expanded = false;
return true;
}
return false;
}
internal void BackstageMnemonicProcessed(char charCode)
{
}
protected override bool CanShowPopup
{
get
{
return (this.ShowSubItems || ShouldAutoExpandOnClick) && (this.SubItems.Count > 0 || this.PopupType == ePopupType.Container || BackstageTab != null && BackstageTabEnabled);
}
}
public override void Refresh()
{
if (StyleManager.IsMetro(this.EffectiveStyle))
{
Control container = this.ContainerControl as Control;
if (container != null)
{
RibbonForm form = container.FindForm() as RibbonForm;
if (form != null)
{
Rectangle r = this.Bounds;
r.Height++;
r.Width++;
r.Inflate(1, 1);
form.Invalidate(r, true);
}
}
}
base.Refresh();
}
#endregion
}
public class Office2007StartButton : ApplicationButton
{
}
}

View File

@@ -0,0 +1,38 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
internal class BarBackgroundPainter
{
#region Docked Background
/// <summary>
/// Paints background of docked bar.
/// </summary>
/// <param name="e">Context information</param>
public virtual void PaintDockedBackground(ToolbarRendererEventArgs e)
{
}
#endregion
#region Floating Background
/// <summary>
/// Paints background of floating bar.
/// </summary>
/// <param name="e">Context information</param>
public virtual void PaintFloatingBackground(ToolbarRendererEventArgs e)
{
}
#endregion
#region Popup Background
/// <summary>
/// Paints background of popup bar.
/// </summary>
/// <param name="e">Context information</param>
public virtual void PaintPopupBackground(ToolbarRendererEventArgs e)
{
}
#endregion
}
}

View File

@@ -0,0 +1,131 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
#region BaseItemAutoSizeBag
internal class BaseItemAutoSizeBag
{
public BaseItem Item = null;
private bool m_SettingsRecorded;
protected bool SettingsRecorded
{
get
{
return m_SettingsRecorded;
}
set
{
m_SettingsRecorded = value;
}
}
public virtual void RecordSetting(BaseItem item)
{
this.Item = item;
m_SettingsRecorded = true;
}
public virtual void RestoreSettings()
{
m_SettingsRecorded = false;
}
}
#endregion
#region ItemContainerAutoSizeBag
internal class ItemContainerAutoSizeBag : BaseItemAutoSizeBag
{
private bool m_MultiLine = false;
private eOrientation m_LayoutOrientation = eOrientation.Horizontal;
private bool m_TitleVisible = false;
public override void RecordSetting(BaseItem item)
{
if (this.SettingsRecorded)
return;
ItemContainer cont = item as ItemContainer;
m_MultiLine = cont.MultiLine;
m_LayoutOrientation = cont.LayoutOrientation;
m_TitleVisible = cont.TitleVisible;
base.RecordSetting(item);
}
public override void RestoreSettings()
{
if (!this.SettingsRecorded) return;
ItemContainer cont = this.Item as ItemContainer;
cont.MultiLine = m_MultiLine;
cont.LayoutOrientation = m_LayoutOrientation;
cont.TitleVisible = m_TitleVisible;
base.RestoreSettings();
}
}
#endregion
#region ButtonItemAutoSizeBag
internal class ButtonItemAutoSizeBag : BaseItemAutoSizeBag
{
private eButtonStyle m_ButtonStyle = eButtonStyle.Default;
private eImagePosition m_ImagePosition = eImagePosition.Left;
private Size m_ImageFixedSize = Size.Empty;
private string m_Text = null;
public override void RecordSetting(BaseItem item)
{
if (this.SettingsRecorded)
return;
ButtonItem button = item as ButtonItem;
m_ButtonStyle = button.ButtonStyle;
m_ImagePosition = button.ImagePosition;
m_ImageFixedSize = button.ImageFixedSize;
if (button.TextMarkupBody != null && button.TextMarkupBody.HasExpandElement)
m_Text = button.Text;
base.RecordSetting(item);
}
public override void RestoreSettings()
{
if (!this.SettingsRecorded)
return;
ButtonItem button = this.Item as ButtonItem;
bool gi = button.GlobalItem;
button.GlobalItem = false;
button.ButtonStyle = m_ButtonStyle;
button.ImagePosition = m_ImagePosition;
button.ImageFixedSize = m_ImageFixedSize;
if (m_Text != null) button.Text = m_Text;
button.GlobalItem = gi;
base.RestoreSettings();
}
}
#endregion
#region AutoSizeBagFactory
internal class AutoSizeBagFactory
{
public static BaseItemAutoSizeBag CreateAutoSizeBag(ButtonItem item)
{
ButtonItemAutoSizeBag b = new ButtonItemAutoSizeBag();
b.Item = item;
return b;
}
public static ItemContainerAutoSizeBag CreateAutoSizeBag(ItemContainer item)
{
ItemContainerAutoSizeBag c = new ItemContainerAutoSizeBag();
c.Item = item;
return c;
}
}
#endregion
}

View File

@@ -0,0 +1,181 @@
using System;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for ButtonItemPainter.
/// </summary>
internal abstract class ButtonItemPainter
{
public abstract void PaintButton(ButtonItem button, ItemPaintArgs pa);
public abstract void PaintButtonBackground(ButtonItem button, ItemPaintArgs pa, CompositeImage image);
public abstract void PaintButtonCheck(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r);
public abstract void PaintButtonImage(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle imagebounds);
public abstract void PaintButtonMouseOver(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r);
public abstract void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image);
public abstract void PaintCustomizeCheck(ButtonItem button, ItemPaintArgs pa, Rectangle r);
public abstract void PaintExpandButton(ButtonItem button, ItemPaintArgs pa);
public abstract Rectangle GetCheckRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image);
public abstract Rectangle GetCustomizeMenuCheckRectangle(ButtonItem button, ItemPaintArgs pa);
public abstract Rectangle GetImageRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image);
public abstract Rectangle GetMouseOverRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image);
public abstract eTextFormat GetStringFormat(ButtonItem button, ItemPaintArgs pa, CompositeImage image);
public static string GetDrawText(string text)
{
return text; //.Replace(@"\n",Environment.NewLine);
}
public static bool IsItemEnabled(BaseItem item, ItemPaintArgs pa)
{
return item.GetEnabled(pa.ContainerControl);
}
public static Point[] GetExpandPolygon(Rectangle r, ePopupSide direction)
{
Point[] p = new Point[3];
Size defaultSize = new Size(Dpi.Width4, Dpi.Height3);
switch (direction)
{
case ePopupSide.Right:
{
p[0].X = r.Left + 1;
p[0].Y = r.Top + (r.Height - defaultSize.Height) / 2 - 1;
p[1].X = p[0].X;
p[1].Y = p[0].Y + Dpi.Height6;
p[2].X = p[0].X + Dpi.Width3;
p[2].Y = p[0].Y + Dpi.Width3;
break;
}
case ePopupSide.Left:
{
p[0].X = r.Left + Dpi.Width3;
p[0].Y = r.Top + (r.Height - defaultSize.Height) / 2 - 1;
p[1].X = p[0].X;
p[1].Y = p[0].Y + Dpi.Height6;
p[2].X = p[0].X - Dpi.Width3;
p[2].Y = p[0].Y + Dpi.Height3;
break;
}
case ePopupSide.Top:
{
p[0].X = r.Left + (r.Width - defaultSize.Width) / 2;
p[0].Y = r.Top + (r.Height - defaultSize.Height) / 2 + defaultSize.Height;
p[1].X = p[0].X + Dpi.Width5;
p[1].Y = p[0].Y+1;
p[2].X = p[0].X + Dpi.Width2;
p[2].Y = p[0].Y - Dpi.Height3;
//p[0].X = r.Left + (r.Width - defaultSize.Width) / 2 - Dpi.Width1;
//p[0].Y = r.Top + (r.Height - defaultSize.Height) / 2 + defaultSize.Height;
//p[1].X = p[0].X + Dpi.Width6;
//p[1].Y = p[0].Y;
//p[2].X = p[0].X + Dpi.Width3;
//p[2].Y = p[0].Y - Dpi.Height4;
break;
}
case ePopupSide.Bottom:
case ePopupSide.Default:
{
p[0].X = r.Left + (r.Width - defaultSize.Width) / 2;
p[0].Y = r.Top + (r.Height - defaultSize.Height) / 2 + 1;
p[1].X = p[0].X + Dpi.Width5;
p[1].Y = p[0].Y;
p[2].X = p[0].X + Dpi.Width2;
p[2].Y = p[0].Y + Dpi.Height3;
break;
}
}
return p;
}
public static void PaintButtonExpandIndicator(ButtonItem button, ItemPaintArgs pa)
{
Graphics g = pa.Graphics;
Rectangle itemRect = button.DisplayRectangle;
Point[] p = new Point[3];
Rectangle r = button.SubItemsRect;
if (button.PopupSide == ePopupSide.Default)
{
if (button.Orientation == eOrientation.Horizontal)
{
p[0].X = itemRect.Left + r.Left + (r.Width - Dpi.Width5) / 2;
p[0].Y = itemRect.Top + r.Top + (r.Height - Dpi.Height3) / 2 + 1;
p[1].X = p[0].X + Dpi.Width5;
p[1].Y = p[0].Y;
p[2].X = p[0].X + Dpi.Width2;
p[2].Y = p[0].Y + Dpi.Height3;
}
else
{
p[0].X = itemRect.Left + r.Left + r.Width / 2;
p[0].Y = itemRect.Top + r.Top + r.Height / 2 - Dpi.Height3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + Dpi.Height6;
p[2].X = p[0].X + Dpi.Width3;
p[2].Y = p[0].Y + Dpi.Height3;
}
}
else
{
switch (button.PopupSide)
{
case ePopupSide.Right:
{
p[0].X = itemRect.Left + r.Left + r.Width / 2;
p[0].Y = itemRect.Top + r.Top + r.Height / 2 - Dpi.Height3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + Dpi.Height6;
p[2].X = p[0].X + Dpi.Width3;
p[2].Y = p[0].Y + Dpi.Height3;
break;
}
case ePopupSide.Left:
{
p[0].X = itemRect.Left + r.Left + r.Width / 2 + Dpi.Width3;
p[0].Y = itemRect.Top + r.Top + r.Height / 2 - Dpi.Height3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + Dpi.Height6;
p[2].X = p[0].X - Dpi.Width3;
p[2].Y = p[0].Y + Dpi.Height3;
break;
}
case ePopupSide.Top:
{
p[0].X = itemRect.Left + r.Left + (r.Width - Dpi.Width5) / 2;
p[0].Y = itemRect.Top + r.Top + (r.Height - Dpi.Height3) / 2 + Dpi.Height4;
p[1].X = p[0].X + Dpi.Width6;
p[1].Y = p[0].Y;
p[2].X = p[0].X + Dpi.Width3;
p[2].Y = p[0].Y - Dpi.Height4;
break;
}
case ePopupSide.Bottom:
{
p[0].X = itemRect.Left + r.Left + (r.Width - Dpi.Width5) / 2 + 1;
p[0].Y = itemRect.Top + r.Top + (r.Height - Dpi.Height3) / 2 + 1;
p[1].X = p[0].X + Dpi.Width5;
p[1].Y = p[0].Y;
p[2].X = p[0].X + Dpi.Width2;
p[2].Y = p[0].Y + Dpi.Height3;
break;
}
}
}
if (IsItemEnabled(button, pa))
{
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemText))
g.FillPolygon(mybrush, p);
}
else
{
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledText))
g.FillPolygon(mybrush, p);
}
}
}
}

View File

@@ -0,0 +1,56 @@
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for ButtonItemPainterHelper.
/// </summary>
internal class ButtonItemPainterHelper
{
public static Color GetTextColor(ButtonItem button, ItemPaintArgs pa)
{
Color textColor=SystemColors.ControlText;
if(!ButtonItemPainter.IsItemEnabled(button, pa))
{
if(!pa.Colors.ItemDisabledText.IsEmpty)
textColor=pa.Colors.ItemDisabledText;
else
textColor=SystemColors.ControlDark;
}
else if(button.IsMouseDown && !pa.Colors.ItemPressedText.IsEmpty)
{
textColor=pa.Colors.ItemPressedText;
}
else if(button.IsMouseOver)
{
if(!button.HotForeColor.IsEmpty)
textColor=button.HotForeColor;
else
textColor=pa.Colors.ItemHotText;
}
else if(button.Expanded && !pa.Colors.ItemExpandedText.IsEmpty)
{
textColor=pa.Colors.ItemExpandedText;
}
else if(button.Checked && !pa.Colors.ItemCheckedText.IsEmpty)
{
textColor=pa.Colors.ItemCheckedText;
}
else
{
if(!button.ForeColor.IsEmpty)
textColor=button.ForeColor;
else
{
if(button.IsThemed && button.IsOnMenuBar && pa.Colors.ItemText==SystemColors.ControlText)
textColor=SystemColors.MenuText;
else
textColor=pa.Colors.ItemText;
}
}
return textColor;
}
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for ButtonItem rendering.
/// </summary>
public class ButtonItemRendererEventArgs
{
/// <summary>
/// Gets or sets Graphics object group is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets the reference to ButtonItem instance being rendered.
/// </summary>
public ButtonItem ButtonItem = null;
/// <summary>
/// Reference to internal data.
/// </summary>
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Indicates whether to cancel system rendering of the item.
/// </summary>
public bool Cancel = false;
/// <summary>
/// Creates new instance of the object.
/// </summary>
public ButtonItemRendererEventArgs() { }
/// <summary>
/// Creates new instance of the object and initializes it with default values
/// </summary>
/// <param name="g">Reference to Graphics object.</param>
/// <param name="button">Reference to ButtonItem object.</param>
public ButtonItemRendererEventArgs(Graphics g, ButtonItem button)
{
this.Graphics = g;
this.ButtonItem = button;
}
/// <summary>
/// Creates new instance of the object and initializes it with default values
/// </summary>
/// <param name="g">Reference to Graphics object.</param>
/// <param name="button">Reference to ButtonItem object.</param>
internal ButtonItemRendererEventArgs(Graphics g, ButtonItem button, ItemPaintArgs pa)
{
this.Graphics = g;
this.ButtonItem = button;
this.ItemPaintArgs = pa;
}
}
}

View File

@@ -0,0 +1,267 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Defines container for ribbon caption layout and quick access toolbar customization and overflow.
/// </summary>
internal class CaptionItemContainer : GenericItemContainer
{
#region Private Variables
private int m_MinTitleSize = 40;
private int m_MoreItemsLeft = 0;
private CustomizeItem m_CustomizeItem = null;
private int m_MaxItemHeight = 0;
#endregion
#region Constructor
public CaptionItemContainer():base()
{
this.FirstItemSpacing = 3;
this.ToolbarItemsAlign = eContainerVerticalAlignment.Top;
}
#endregion
#region Layout
public override void RecalcSize()
{
if (m_MoreItems != null && m_MoreItems.Expanded)
m_MoreItems.Expanded = false;
m_RecalculatingSize = true;
int width = m_MinTitleSize;
if (this.ContainerControl is Ribbon.QatToolbar)
width = 0;
int count = this.SubItems.Count;
int firstFarIndex = -1;
int maxHeight = 0;
int maxItemHeight = 0;
int moreItemsHeight = Dpi.Height22;
bool hasQatCustomizeItem = false;
for (int i = 0; i < count; i++)
{
BaseItem item = this.SubItems[i];
if (!item.Visible)
continue;
item.RecalcSize();
item.Displayed = true;
width += (item.WidthInternal + (i==0?this.FirstItemSpacing:m_ItemSpacing));
if (item.ItemAlignment == eItemAlignment.Far && firstFarIndex == -1)
firstFarIndex = i;
if (firstFarIndex == -1)
moreItemsHeight = item.HeightInternal;
if (item.HeightInternal > maxHeight)
maxHeight = item.HeightInternal;
if (item.HeightInternal > maxItemHeight && !(item is ApplicationButton || item is SystemCaptionItem))
maxItemHeight = item.HeightInternal;
if (item is QatCustomizeItem || item is QatOverflowItem)
hasQatCustomizeItem = true;
}
if (hasQatCustomizeItem)
width += maxHeight / 2;
m_MaxItemHeight = maxItemHeight;
if (width < this.WidthInternal)
{
m_RecalculatingSize = false;
base.RecalcSize();
return;
}
if (firstFarIndex == -1)
firstFarIndex = this.SubItems.Count;
for (int i = firstFarIndex - 1; i >= 0; i--)
{
BaseItem item = this.SubItems[i];
if (!item.Visible)
continue;
width -= item.WidthInternal;
item.Displayed = false;
if (width + DisplayMoreItem.FixedSize + maxHeight/2 < this.WidthInternal)
break;
}
int x = this.LeftInternal + m_PaddingLeft;
int y = this.TopInternal + m_PaddingTop;
int loopTo = count;
if (firstFarIndex >= 0)
loopTo = firstFarIndex - 1;
bool oneNearVisible = false;
for (int i = 0; i < loopTo; i++)
{
BaseItem item = this.SubItems[i];
if (!item.Visible || !item.Displayed)
continue;
oneNearVisible = true;
Rectangle rb = new Rectangle(x, y, item.WidthInternal, item.HeightInternal);
if (!(item is ApplicationButton || item is SystemCaptionItem))
rb.Y += (maxItemHeight - item.HeightInternal) / 2;
item.Bounds = rb;
x += (item.WidthInternal + (i == 0 ? this.FirstItemSpacing : m_ItemSpacing));
}
m_MoreItemsLeft = x + maxHeight/2;
if (firstFarIndex >= 0)
{
x = this.DisplayRectangle.Right - m_PaddingRight;
for (int i = count - 1; i >= firstFarIndex; i--)
{
BaseItem item = this.SubItems[i];
if (!item.Visible || !item.Displayed)
continue;
x -= item.WidthInternal;
item.Bounds = new Rectangle(x, y, item.WidthInternal, item.HeightInternal);
x -= m_ItemSpacing;
}
}
m_Rect.Height = maxHeight + m_PaddingTop + m_PaddingBottom;
if (oneNearVisible)
{
// Add Display More item...
CreateMoreItemsButton(this.IsRightToLeft);
m_MoreItems.HeightInternal = moreItemsHeight;
m_MoreItems.RecalcSize();
}
else if(m_MoreItems!=null)
{
// Clean up, we don't need this anymore
m_MoreItems.Dispose();
m_MoreItems = null;
}
m_NeedRecalcSize = false;
m_RecalculatingSize = false;
}
protected override int GetItemLayoutWidth(BaseItem objItem)
{
if (objItem is QatCustomizeItem || objItem is QatOverflowItem)
return objItem.WidthInternal + this.HeightInternal / 2;
return base.GetItemLayoutWidth(objItem);
}
protected override int GetItemLayoutX(BaseItem objItem, int iX)
{
if (objItem is QatCustomizeItem || objItem is QatOverflowItem)
return iX + this.HeightInternal / 2;
return base.GetItemLayoutX(objItem, iX);
}
protected override int GetItemLayoutY(BaseItem objItem, int iY)
{
if (!(objItem is ApplicationButton || objItem is SystemCaptionItem || objItem is DevComponents.DotNetBar.Metro.MetroAppButton))
return iY + (m_MaxItemHeight - objItem.HeightInternal) / 2;
return base.GetItemLayoutY(objItem, iY);
}
internal int MaxItemHeight
{
get
{
return m_MaxItemHeight;
}
}
protected override Point GetMoreItemsLocation(bool isRightToLeft)
{
if (m_MoreItems == null)
return Point.Empty;
Point p = Point.Empty;
if (m_Orientation == eOrientation.Vertical)
{
p.X = m_Rect.Left + m_PaddingLeft;
p.Y = m_MoreItemsLeft;
}
else
{
if (isRightToLeft)
p.X = m_Rect.X + m_PaddingLeft;
else
p.X = m_MoreItemsLeft;
p.Y = m_Rect.Top + m_PaddingTop;
}
return p;
}
protected override void CreateMoreItemsButton(bool isRightToLeft)
{
if (m_MoreItems == null)
{
m_MoreItems = new QatOverflowItem();
m_MoreItems.Style = m_Style;
m_MoreItems.SetParent(this);
m_MoreItems.ThemeAware = this.ThemeAware;
}
if (this.MoreItemsOnMenu)
m_MoreItems.PopupType = ePopupType.Menu;
else
m_MoreItems.PopupType = ePopupType.ToolBar;
m_MoreItems.Orientation = m_Orientation;
m_MoreItems.Displayed = true;
if (m_Orientation == eOrientation.Vertical)
{
m_MoreItems.WidthInternal = m_Rect.Width - (m_PaddingLeft + m_PaddingRight);
m_MoreItems.RecalcSize();
}
else
{
m_MoreItems.HeightInternal = m_Rect.Height - (m_PaddingTop + m_PaddingBottom);
m_MoreItems.RecalcSize();
}
Point loc = GetMoreItemsLocation(isRightToLeft);
m_MoreItems.LeftInternal = loc.X;
m_MoreItems.TopInternal = loc.Y;
}
#endregion
#region Internal Implementation
protected internal override void OnItemAdded(BaseItem objItem)
{
base.OnItemAdded(objItem);
BaseItem item = objItem;
if (item is CustomizeItem)
m_CustomizeItem = (CustomizeItem)item;
else if (m_CustomizeItem != null)
{
bool added = false;
if(this.SubItems.Contains(m_CustomizeItem))
this.SubItems._Remove(m_CustomizeItem);
for (int i = this.SubItems.Count - 1; i > 0; i--)
{
if (this.SubItems[i].ItemAlignment == eItemAlignment.Near && !(this.SubItems[i] is SystemCaptionItem))
{
this.SubItems._Add(m_CustomizeItem, i+1);
added = true;
break;
}
}
if (!added)
{
if (this.SubItems.Count > 0 && this.SubItems[this.SubItems.Count - 1] is SystemCaptionItem)
this.SubItems._Add(m_CustomizeItem, this.SubItems.Count - 2);
else
this.SubItems._Add(m_CustomizeItem);
}
}
}
protected internal override void OnAfterItemRemoved(BaseItem objItem, int itemIndex)
{
if (objItem == m_CustomizeItem)
m_CustomizeItem = null;
base.OnAfterItemRemoved(objItem, itemIndex);
}
#endregion
}
}

View File

@@ -0,0 +1,268 @@
using System.Drawing;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for DesignTimeProviderContainer.
/// </summary>
public class DesignTimeProviderContainer
{
/// <summary>
/// Returns information about insertion position for an item given screen coordinates. Used internally for drag&drop support.
/// </summary>
/// <param name="containerItem">Container item</param>
/// <param name="pScreen">Screen coordinates</param>
/// <param name="DragItem">Item that is being dragged</param>
/// <returns>Information about insertion position or null if item cannot be inserted to the container.</returns>
public static InsertPosition GetInsertPosition(BaseItem containerItem, Point pScreen, BaseItem DragItem)
{
InsertPosition objInsertPos=null;
Control objContainer = null;
if (containerItem is PopupItem && containerItem.Expanded)
objContainer = ((PopupItem)containerItem).PopupControl;
else
objContainer = containerItem.ContainerControl as Control;
if (objContainer == null)
return null;
Point pClient=objContainer.PointToClient(pScreen);
Rectangle thisRect=containerItem.DisplayRectangle;
if (containerItem is PopupItem && containerItem.Expanded)
thisRect = objContainer.DisplayRectangle;
if(thisRect.Contains(pClient) || containerItem.SubItems.Count==0 && objContainer.ClientRectangle.Contains(pClient) || containerItem is ItemContainer && ((ItemContainer)containerItem).SystemContainer && objContainer.ClientRectangle.Contains(pClient))
{
Rectangle r;
BaseItem objItem;
// Check first inside any expanded items
objItem=containerItem.ExpandedItem();
if(objItem!=null)
{
IDesignTimeProvider provider=objItem as IDesignTimeProvider;
if(provider!=null)
{
objInsertPos=provider.GetInsertPosition(pScreen, DragItem);
if(objInsertPos!=null)
return objInsertPos;
}
}
bool dragItemPreviousItem = false;
for(int i=0;i<containerItem.SubItems.Count;i++)
{
objItem=containerItem.SubItems[i];
r=objItem.DisplayRectangle;
r.Inflate(2,2);
if(objItem.Visible && r.Contains(pClient))
{
if(objItem.SystemItem && containerItem.SubItems.Count!=1)
{
return null;
}
if(objItem==DragItem)
return new InsertPosition();
if(objItem.IsContainer && objItem is IDesignTimeProvider)
{
Rectangle inner=r;
inner.Inflate(-8,-8);
if (inner.Contains(pClient))
{
return ((IDesignTimeProvider)objItem).GetInsertPosition(pScreen, DragItem);
}
}
if (containerItem.AllowDrop)
{
objInsertPos = new InsertPosition();
objInsertPos.TargetProvider = (IDesignTimeProvider)containerItem;
objInsertPos.Position = i;
if (!dragItemPreviousItem)
{
if (containerItem.Orientation == eOrientation.Horizontal && !objItem.IsOnMenu)
{
if (pClient.X <= objItem.LeftInternal + objItem.WidthInternal / 2 || objItem.SystemItem)
objInsertPos.Before = true;
}
else
{
if (pClient.Y <= objItem.TopInternal + objItem.HeightInternal / 2 || objItem.SystemItem)
objInsertPos.Before = true;
}
}
// We need to collapse any expanded items that are not on this bar
IOwner owner = containerItem.GetOwner() as IOwner;
if (owner != null)
{
BaseItem objExp = owner.GetExpandedItem();
if (objExp != null)
{
while (objExp.Parent != null)
objExp = objExp.Parent;
BaseItem objParent = objItem;
while (objParent.Parent != null)
objParent = objParent.Parent;
if (objExp != objParent)
owner.SetExpandedItem(null);
}
}
if (CanExpand(objItem))
{
if (!objItem.Expanded && objItem.CanCustomize)
objItem.Expanded = true;
}
else if(DragItem == null || objItem!=null && objItem != DragItem.Parent)
{
BaseItem.CollapseSubItems(containerItem);
}
break;
}
}
dragItemPreviousItem = (DragItem == objItem);
}
if(objInsertPos==null && containerItem.AllowDrop)
{
// Container is empty but it can contain the items
if(containerItem.SubItems.Count>1 && containerItem.SubItems[containerItem.SubItems.Count-1].SystemItem)
objInsertPos=new InsertPosition(containerItem.SubItems.Count-2,true,(IDesignTimeProvider)containerItem);
else
objInsertPos=new InsertPosition(containerItem.SubItems.Count-1,false,(IDesignTimeProvider)containerItem);
}
}
else
{
foreach(BaseItem objItem in containerItem.SubItems)
{
if(objItem==DragItem)
continue;
IDesignTimeProvider provider=objItem as IDesignTimeProvider;
if(provider!=null)
{
objInsertPos=provider.GetInsertPosition(pScreen, DragItem);
if(objInsertPos!=null)
break;
}
}
}
return objInsertPos;
}
private static bool CanExpand(BaseItem objItem)
{
return (objItem is PopupItem && (objItem.SubItems.Count > 0 || objItem.IsOnMenuBar)) || objItem is ItemContainer && ((ItemContainer)objItem).CanExpand;
}
/// <summary>
/// Draws reversible marker to indicates item drag&drop position
/// </summary>
/// <param name="containerItem">Container item</param>
/// <param name="iPos">Position to draw marker at</param>
/// <param name="Before">Indicates whether the marker is drawn before the reference position</param>
public static void DrawReversibleMarker(BaseItem containerItem, int iPos, bool Before)
{
Control objCtrl=containerItem.ContainerControl as Control;
if(objCtrl==null)
return;
BaseItem objItem=null;
if(iPos>=0)
objItem=containerItem.SubItems[iPos];
Rectangle r, rl,rr;
if(objItem!=null)
{
if(objItem.DesignInsertMarker!=eDesignInsertPosition.None)
objItem.DesignInsertMarker=eDesignInsertPosition.None;
else if(Before)
objItem.DesignInsertMarker=eDesignInsertPosition.Before;
else
objItem.DesignInsertMarker=eDesignInsertPosition.After;
return;
}
else
{
Rectangle rTmp=containerItem.DisplayRectangle;
rTmp.Inflate(-1,-1);
r=new Rectangle(rTmp.Left+2,rTmp.Top+2,1,rTmp.Height-4);
rl=new Rectangle(rTmp.Left,rTmp.Top+1,5,1);
rr=new Rectangle(rTmp.Left,rTmp.Bottom-2,5,1);
}
//r.Location=objCtrl.PointToScreen(r.Location);
//rl.Location=objCtrl.PointToScreen(rl.Location);
//rr.Location=objCtrl.PointToScreen(rr.Location);
//ControlPaint.DrawReversibleFrame(r,SystemColors.Control,FrameStyle.Thick);
//ControlPaint.DrawReversibleFrame(rl,SystemColors.Control,FrameStyle.Thick);
//ControlPaint.DrawReversibleFrame(rr,SystemColors.Control,FrameStyle.Thick);
}
/// <summary>
/// Inserts drag&drop item at specified position.
/// </summary>
/// <param name="containerItem">Container item.</param>
/// <param name="objItem">Item being inserted</param>
/// <param name="iPos">Insertion position</param>
/// <param name="Before">Indicates whether item is inserted before the specified insertion position</param>
public static void InsertItemAt(BaseItem containerItem, BaseItem objItem, int iPos, bool Before)
{
if(containerItem.ExpandedItem()!=null)
{
containerItem.ExpandedItem().Expanded=false;
}
if(!Before)
{
if(iPos+1>=containerItem.SubItems.Count)
{
containerItem.SubItems.Add(objItem,GetAppendPosition(containerItem));
}
else
{
containerItem.SubItems.Add(objItem,iPos+1);
}
}
else
{
if(iPos>=containerItem.SubItems.Count)
{
containerItem.SubItems.Add(objItem, GetAppendPosition(containerItem));
}
else
{
containerItem.SubItems.Add(objItem,iPos);
}
}
if(containerItem.ContainerControl is Bar)
((Bar)containerItem.ContainerControl).RecalcLayout();
else if(containerItem.ContainerControl is MenuPanel)
((MenuPanel)containerItem.ContainerControl).RecalcSize();
else if(containerItem.ContainerControl is BarBaseControl)
((BarBaseControl)containerItem.ContainerControl).RecalcLayout();
else if(containerItem.ContainerControl is ItemControl)
((ItemControl)containerItem.ContainerControl).RecalcLayout();
else
{
containerItem.RecalcSize();
containerItem.Refresh();
}
}
/// <summary>
/// Returns insertion index for an item taking in account any system items that are at the end of the collection.
/// </summary>
/// <param name="objParent">Parent item</param>
/// <returns>Returns the index at which an item should be inserted</returns>
public static int GetAppendPosition(BaseItem objParent)
{
int iPos=-1;
for(int i=objParent.SubItems.Count-1;i>=0;i--)
{
if(objParent.SubItems[i].SystemItem)
iPos=i;
else
break;
}
return iPos;
}
}
}

View File

@@ -0,0 +1,12 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
internal abstract class DialogLauncherPainter
{
public abstract void PaintDialogLauncher(RibbonBarRendererEventArgs e);
//public virtual void PaintBackground(RibbonBarRendererEventArgs e) { }
//public virtual void PaintTitle(RibbonBarRendererEventArgs e) { }
}
}

View File

@@ -0,0 +1,158 @@
using DevComponents.DotNetBar.Rendering;
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Defines delegate for RenderKeyTips event.
/// </summary>
public delegate void KeyTipsRendererEventHandler(object sender, KeyTipsRendererEventArgs e);
/// <summary>
/// Defines delegate for RenderRibbonTabGroup event.
/// </summary>
public delegate void RibbonTabGroupRendererEventHandler(object sender, RibbonTabGroupRendererEventArgs e);
/// <summary>
/// Defines delegate for RenderItemContainer event.
/// </summary>
public delegate void ItemContainerRendererEventHandler(object sender, ItemContainerRendererEventArgs e);
/// <summary>
/// Defines delegate for RenderItemContainerSeparator event.
/// </summary>
public delegate void ItemContainerSeparatorRendererEventHandler(object sender, ItemContainerSeparatorRendererEventArgs e);
/// <summary>
/// Defines delegate for ButtonItem rendering events.
/// </summary>
public delegate void ButtonItemRendererEventHandler(object sender, ButtonItemRendererEventArgs e);
/// <summary>
/// Defines delegate for RibbonTabItem rendering events.
/// </summary>
public delegate void RibbonTabItemRendererEventHandler(object sender, RibbonTabItemRendererEventArgs e);
/// <summary>
/// Defines delegate for toolbar rendering events.
/// </summary>
public delegate void ToolbarRendererEventHandler(object sender, ToolbarRendererEventArgs e);
/// <summary>
/// Defines delegate for Rendering dialog launcher button rendering events.
/// </summary>
public delegate void RibbonBarRendererEventHandler(object sender, RibbonBarRendererEventArgs e);
/// <summary>
/// Defines delegate for ColorItem rendering events.
/// </summary>
public delegate void ColorItemRendererEventHandler(object sender, ColorItemRendererEventArgs e);
/// <summary>
/// Defines delegate for RibbonControl rendering events.
/// </summary>
public delegate void RibbonControlRendererEventHandler(object sender, RibbonControlRendererEventArgs e);
/// <summary>
/// Defines delegate for SystemCaptionItem rendering events.
/// </summary>
public delegate void SystemCaptionItemRendererEventHandler(object sender, SystemCaptionItemRendererEventArgs e);
/// <summary>
/// Defines delegate for MdiSystemItem rendering events.
/// </summary>
public delegate void MdiSystemItemRendererEventHandler(object sender, MdiSystemItemRendererEventArgs e);
/// <summary>
/// Defines delegate for RenderFormCaptionBackground rendering events.
/// </summary>
public delegate void FormCaptionRendererEventHandler(object sender, FormCaptionRendererEventArgs e);
/// <summary>
/// Defines delegate for CustomizeMenuPopup events.
/// </summary>
public delegate void CustomizeMenuPopupEventHandler(object sender, RibbonCustomizeEventArgs e);
/// <summary>
/// Defines delegate for the Quick Access Overflow item rendering events.
/// </summary>
public delegate void QatOverflowItemRendererEventHandler(object sender, QatOverflowItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the Quick Access Customize item rendering events.
/// </summary>
public delegate void QatCustomizeItemRendererEventHandler(object sender, QatCustomizeItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the Quick Access Customization dialog events.
/// </summary>
public delegate void QatCustomizeDialogEventHandler(object sender, QatCustomizeDialogEventArgs e);
/// <summary>
/// Defines delegate for the CheckBoxItem rendering events.
/// </summary>
public delegate void CheckBoxItemRendererEventHandler(object sender, CheckBoxItemRenderEventArgs e);
/// <summary>
/// Defines delegate for the ProgressBarItem rendering events.
/// </summary>
public delegate void ProgressBarItemRendererEventHandler(object sender, ProgressBarItemRenderEventArgs e);
/// <summary>
/// Defines delegate for the Navigation Pane rendering events.
/// </summary>
public delegate void NavPaneRendererEventHandler(object sender, NavPaneRenderEventArgs e);
/// <summary>
/// Defines delegate for the BeforeRibbonPanelPopupClose event.
/// </summary>
public delegate void RibbonPopupCloseEventHandler(object sender, RibbonPopupCloseEventArgs e);
/// <summary>
/// Defines delegate for the Slider item rendering events.
/// </summary>
public delegate void SliderItemRendererEventHandler(object sender, SliderItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the SideBar control rendering event.
/// </summary>
public delegate void SideBarRendererEventHandler(object sender, SideBarRendererEventArgs e);
/// <summary>
/// Defines delegate for the SideBarPanelItem control rendering event.
/// </summary>
public delegate void SideBarPanelItemRendererEventHandler(object sender, SideBarPanelItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the SwitchButtonItem control rendering event.
/// </summary>
public delegate void SwitchButtonRendererEventHandler(object sender, DevComponents.DotNetBar.Rendering.SwitchButtonRenderEventArgs e);
/// <summary>
/// Defines delegate for the Slider item rendering events.
/// </summary>
public delegate void RangeSliderItemRendererEventHandler(object sender, RangeSliderItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the StepItem rendering events.
/// </summary>
public delegate void StepItemRendererEventHandler(object sender, StepItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the ListBoxItem rendering events.
/// </summary>
public delegate void ListBoxItemRendererEventHandler(object sender, ListBoxItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the SideNavItem rendering events.
/// </summary>
public delegate void SideNavItemRendererEventHandler(object sender, SideNavItemRendererEventArgs e);
/// <summary>
/// Defines delegate for the TabStrip rendering events.
/// </summary>
public delegate void TabFormStripRendererEventHandler(object sender, TabFormStripPainterArgs e);
/// <summary>
/// Defines delegate for the TabParentForm rendering events.
/// </summary>
public delegate void TabFormRendererEventHandler(object sender, TabFormPainterArgs e);
}

View File

@@ -0,0 +1,223 @@
using System;
using System.Text;
using System.Collections;
using System.Threading;
namespace DevComponents.DotNetBar
{
internal class FadeAnimator
{
// Fields
private static Thread fadeThread;
private static ArrayList fadeInfoList;
private static ReaderWriterLock rwImgListLock;
[ThreadStatic]
private static int threadWriterLockWaitCount;
// Methods
static FadeAnimator()
{
FadeAnimator.rwImgListLock = new ReaderWriterLock();
}
private FadeAnimator() {}
public static void Fade(object caller, EventHandler onFadeChangedHandler)
{
if (!BarUtilities.FadeAnimatorEnabled) return;
if (caller != null)
{
FadeAnimator.FadeInfo fadeInfo = null;
lock (caller)
{
fadeInfo = new FadeAnimator.FadeInfo(caller);
}
FadeAnimator.StopFade(caller, onFadeChangedHandler);
bool flag1 = FadeAnimator.rwImgListLock.IsReaderLockHeld;
LockCookie cookie1 = new LockCookie();
FadeAnimator.threadWriterLockWaitCount++;
try
{
if (flag1)
{
cookie1 = FadeAnimator.rwImgListLock.UpgradeToWriterLock(-1);
}
else
{
FadeAnimator.rwImgListLock.AcquireWriterLock(-1);
}
}
finally
{
FadeAnimator.threadWriterLockWaitCount--;
}
try
{
if (FadeAnimator.fadeInfoList == null)
{
FadeAnimator.fadeInfoList = new ArrayList();
}
fadeInfo.FadeChangedHandler = onFadeChangedHandler;
FadeAnimator.fadeInfoList.Add((FadeAnimator.FadeInfo)fadeInfo);
if (FadeAnimator.fadeThread == null)
{
FadeAnimator.fadeThread = new Thread(new ThreadStart(FadeAnimator.AnimateFade50ms));
FadeAnimator.fadeThread.Name = typeof(FadeAnimator).Name;
FadeAnimator.fadeThread.IsBackground = true;
FadeAnimator.fadeThread.Start();
}
}
finally
{
if (flag1)
{
FadeAnimator.rwImgListLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
FadeAnimator.rwImgListLock.ReleaseWriterLock();
}
}
}
}
private static void AnimateFade50ms()
{
while (true)
{
FadeAnimator.rwImgListLock.AcquireReaderLock(-1);
try
{
for (int num1 = 0; num1 < FadeAnimator.fadeInfoList.Count; num1++)
{
FadeAnimator.FadeInfo info1 = FadeAnimator.fadeInfoList[num1] as FadeAnimator.FadeInfo;
info1.Fade();
}
}
finally
{
FadeAnimator.rwImgListLock.ReleaseReaderLock();
}
try
{
using (
System.Threading.ManualResetEvent wait =
new System.Threading.ManualResetEvent(false))
wait.WaitOne(40);
//Thread.Sleep(40);
}
catch
{
}
}
}
public static void StopFade(object caller, EventHandler onFrameChangedHandler)
{
if (!BarUtilities.FadeAnimatorEnabled) return;
if ((caller != null) && (FadeAnimator.fadeInfoList != null))
{
bool readerLockHeld = FadeAnimator.rwImgListLock.IsReaderLockHeld;
LockCookie cookie1 = new LockCookie();
FadeAnimator.threadWriterLockWaitCount++;
try
{
if (readerLockHeld)
{
cookie1 = FadeAnimator.rwImgListLock.UpgradeToWriterLock(-1);
}
else
{
FadeAnimator.rwImgListLock.AcquireWriterLock(-1);
}
}
finally
{
FadeAnimator.threadWriterLockWaitCount--;
}
try
{
for (int num1 = 0; num1 < FadeAnimator.fadeInfoList.Count; num1++)
{
FadeAnimator.FadeInfo info1 = FadeAnimator.fadeInfoList[num1] as FadeAnimator.FadeInfo;
if (caller == info1.Caller)
{
if ((onFrameChangedHandler == info1.FadeChangedHandler) || ((onFrameChangedHandler != null) && onFrameChangedHandler.Equals(info1.FadeChangedHandler)))
{
FadeAnimator.fadeInfoList.Remove((FadeAnimator.FadeInfo)info1);
info1.FadeChangedHandler = null;
info1.Caller = null;
}
return;
}
}
}
finally
{
if (readerLockHeld)
{
FadeAnimator.rwImgListLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
FadeAnimator.rwImgListLock.ReleaseWriterLock();
}
}
}
}
// Nested Types
private class FadeInfo
{
private object m_Caller;
private EventHandler m_OnFadeChangedHandler;
// Methods
public FadeInfo(object caller)
{
this.m_Caller = caller;
}
protected void OnFadeChanged(EventArgs e)
{
if (m_OnFadeChangedHandler != null)
{
m_OnFadeChangedHandler(m_Caller, e);
}
}
public void Fade()
{
this.OnFadeChanged(EventArgs.Empty);
}
public EventHandler FadeChangedHandler
{
get
{
return this.m_OnFadeChangedHandler;
}
set
{
this.m_OnFadeChangedHandler = value;
}
}
internal object Caller
{
get
{
return m_Caller;
}
set
{
m_Caller = value;
}
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,116 @@
using System;
using System.Text;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the popup gallery group that groups set of items inside of gallery into the group.
/// </summary>
[DesignTimeVisible(false), ToolboxItem(false), TypeConverterAttribute("DevComponents.DotNetBar.Design.GalleryGroupConverter, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class GalleryGroup : Component
{
#region Private Variables
private string m_Text = "";
private string m_Name = "";
private GalleryContainer m_ParentGallery = null;
private int m_DisplayOrder = 0;
private SubItemsCollection m_Items = null;
#endregion
#region Internal Implementation
/// <summary>
/// Creates new instance of the object.
/// </summary>
public GalleryGroup()
{
m_Items = new SubItemsCollection(null);
m_Items.IgnoreEvents = true;
m_Items.AllowParentRemove = false;
}
/// <summary>
/// Gets or sets title of the group that will be displayed on the group label when on popup gallery.
/// </summary>
[Browsable(true), DefaultValue(""), Editor("DevComponents.DotNetBar.Design.TextMarkupUIEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), Localizable(true), Description("Indicates title of the group that will be displayed on the group label when on popup gallery.")]
public string Text
{
get { return m_Text; }
set
{
if (value == null) value = "";
m_Text = value;
}
}
/// <summary>
/// Gets or sets name of the group that can be used to identify item from the code.
/// </summary>
[Browsable(false), Category("Design"), Description("Indicates the name used to identify the group.")]
public string Name
{
get
{
if (this.Site != null)
m_Name = this.Site.Name;
return m_Name;
}
set
{
if (this.Site != null)
this.Site.Name = value;
if (value == null)
m_Name = "";
else
m_Name = value;
}
}
/// <summary>
/// Gets the parent gallery for the group.
/// </summary>
[Browsable(false)]
public GalleryContainer ParentGallery
{
get
{
return m_ParentGallery;
}
}
internal void SetParentGallery(GalleryContainer value)
{
m_ParentGallery = value;
}
public override string ToString()
{
if (m_Text.Length > 0)
return m_Text;
return base.ToString();
}
/// <summary>
/// Gets or sets the display order for the group when displayed on the popup. Lower values are displayed closer to the top. Default value is 0.
/// </summary>
[Browsable(true), DefaultValue(0), Description("Indicates display order for the group when displayed on the popup."), Category("Layout")]
public int DisplayOrder
{
get { return m_DisplayOrder; }
set
{
m_DisplayOrder = value;
}
}
/// <summary>
/// Gets the collection of the items assigned to this group.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public SubItemsCollection Items
{
get { return m_Items; }
}
#endregion
}
}

View File

@@ -0,0 +1,152 @@
using System;
using System.Text;
using System.Collections;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the GalleryGroup typed collection.
/// </summary>
public class GalleryGroupCollection : CollectionBase
{
#region Private Variables and Events
public event EventHandler GroupRemoved;
public event EventHandler GroupAdded;
private GalleryContainer m_Owner=null;
#endregion
#region Internal Implementation
/// <summary>
/// Adds new object to the collection.
/// </summary>
/// <param name="tab">Object to add.</param>
/// <returns>Index of newly added object.</returns>
public int Add(GalleryGroup tab)
{
return List.Add(tab);
}
/// <summary>
/// Adds new objects to the collection.
/// </summary>
/// <param name="groups">Array of groups to add.</param>
public void AddRange(GalleryGroup[] groups)
{
foreach(GalleryGroup doc in groups)
List.Add(doc);
}
/// <summary>
/// Returns reference to the object in collection based on it's index.
/// </summary>
public GalleryGroup this[int index]
{
get {return (GalleryGroup)(List[index]);}
set {List[index] = value;}
}
/// <summary>
/// Returns reference to the object in collection based on it's name.
/// </summary>
public GalleryGroup this[string name]
{
get
{
foreach (GalleryGroup g in this.List)
{
if (g.Name == name)
return g;
}
return null;
}
}
/// <summary>
/// Inserts new object into the collection.
/// </summary>
/// <param name="index">Position of the object.</param>
/// <param name="value">Object to insert.</param>
public void Insert(int index, GalleryGroup value)
{
List.Insert(index, value);
}
/// <summary>
/// Returns index of the object inside of the collection.
/// </summary>
/// <param name="value">Reference to the object.</param>
/// <returns>Index of the object.</returns>
public int IndexOf(GalleryGroup value)
{
return List.IndexOf(value);
}
/// <summary>
/// Returns whether collection contains specified object.
/// </summary>
/// <param name="value">Object to look for.</param>
/// <returns>true if object is part of the collection, otherwise false.</returns>
public bool Contains(GalleryGroup value)
{
return List.Contains(value);
}
/// <summary>
/// Removes specified object from the collection.
/// </summary>
/// <param name="value"></param>
public void Remove(GalleryGroup value)
{
List.Remove(value);
}
protected override void OnRemoveComplete(int index,object value)
{
base.OnRemoveComplete(index,value);
GalleryGroup item=value as GalleryGroup;
item.SetParentGallery(null);
if(GroupRemoved!=null)
GroupRemoved(item,new EventArgs());
}
protected override void OnInsertComplete(int index,object value)
{
base.OnInsertComplete(index,value);
GalleryGroup item=value as GalleryGroup;
if(m_Owner!=null)
item.SetParentGallery(m_Owner);
if(GroupAdded!=null)
GroupAdded(item,new EventArgs());
}
/// <summary>
/// Copies collection into the specified array.
/// </summary>
/// <param name="array">Array to copy collection to.</param>
/// <param name="index">Starting index.</param>
public void CopyTo(GalleryGroup[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Copies contained items to the GalleryGroup array.
/// </summary>
/// <param name="array">Array to copy to.</param>
internal void CopyTo(GalleryGroup[] array)
{
List.CopyTo(array,0);
}
internal GalleryContainer Owner
{
get {return m_Owner;}
set {m_Owner=value;}
}
protected override void OnClear()
{
base.OnClear();
}
#endregion
}
}

View File

@@ -0,0 +1,26 @@
using System;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for ISimpleElement.
/// </summary>
public interface ISimpleElement
{
Rectangle Bounds {get;set;}
int FixedWidth {get;set;}
bool ImageVisible {get;}
Size ImageLayoutSize {get;}
eSimplePartAlignment ImageAlignment {get;set;}
Rectangle ImageBounds {get;set;}
int ImageTextSpacing {get;}
bool TextVisible {get;}
string Text {get;set;}
Rectangle TextBounds {get;set;}
System.Drawing.Image Image {get;set;}
Size TextSize { get; set; }
}
}

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections;
using DevComponents.UI.ContentManager;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents IBlock layout manager implementation
/// </summary>
public class ItemBlockLayoutManager:BlockLayoutManager
{
/// <summary>
/// Resizes the content block and sets it's Bounds property to reflect new size.
/// </summary>
/// <param name="block">Content block to resize.</param>
public override void Layout(IBlock block, Size availableSize)
{
if(block is BaseItem)
{
BaseItem item=block as BaseItem;
if (item is ItemContainer || item.IsContainer)
{
item.SuspendLayout = true;
item.WidthInternal = availableSize.Width;
item.HeightInternal = availableSize.Height;
item.SuspendLayout = false;
}
item.RecalcSize();
item.Displayed=item.Visible;
}
}
public override Rectangle FinalizeLayout(Rectangle containerBounds, Rectangle blocksBounds, ArrayList lines)
{
return (blocksBounds);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,12 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
internal abstract class ItemContainerPainter
{
public abstract void PaintBackground(ItemContainerRendererEventArgs e);
public abstract void PaintItemSeparator(ItemContainerSeparatorRendererEventArgs e);
}
}

View File

@@ -0,0 +1,53 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for rendering ItemContainer.
/// </summary>
public class ItemContainerRendererEventArgs:EventArgs
{
/// <summary>
/// Gets or sets Graphics object group is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets the reference to ItemContainer instance being rendered.
/// </summary>
public ItemContainer ItemContainer = null;
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Creates new instance of the object.
/// </summary>
/// <param name="g">Reference to graphics object.</param>
/// <param name="container">Reference to ItemContainer object.</param>
public ItemContainerRendererEventArgs(Graphics g, ItemContainer container)
{
this.Graphics = g;
this.ItemContainer = container;
}
}
/// <summary>
/// Provides data for the item separator rendering inside of the ItemContainer.
/// </summary>
public class ItemContainerSeparatorRendererEventArgs : ItemContainerRendererEventArgs
{
/// <summary>
/// Gets or sets the reference to the item separator is being rendered for.
/// </summary>
public BaseItem Item = null;
/// <summary>
/// Creates new instance of the object.
/// </summary>
public ItemContainerSeparatorRendererEventArgs(Graphics g, ItemContainer container, BaseItem item): base(g, container)
{
this.Item = item;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="utf-8" ?>
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="ResMimeType">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="Version">
<value>1.0.0.0</value>
</resheader>
<resheader name="Reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="Writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,88 @@
using System;
using System.Drawing.Drawing2D;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents class for item display.
/// </summary>
internal class ItemDisplay
{
public ItemDisplay()
{
}
public void Paint(ItemContainer container, ItemPaintArgs p)
{
foreach(BaseItem item in container.SubItems)
{
if(item.Visible && item.Displayed)
{
if (item.BeginGroup)
{
if (p.Renderer != null)
p.Renderer.DrawItemContainerSeparator(new ItemContainerSeparatorRendererEventArgs(p.Graphics, container, item));
}
if (p.ClipRectangle.IsEmpty || p.ClipRectangle.IntersectsWith(item.DisplayRectangle))
{
Region oldClip = p.Graphics.Clip as Region;
p.Graphics.SetClip(item.DisplayRectangle, CombineMode.Intersect);
if (!p.Graphics.IsClipEmpty)
item.Paint(p);
p.Graphics.Clip = oldClip;
if (oldClip != null) oldClip.Dispose();
}
}
}
}
public void Paint(BaseItem container, ItemPaintArgs p)
{
foreach (BaseItem item in container.SubItems)
{
if (item.Visible && item.Displayed)
{
if (p.ClipRectangle.IsEmpty || p.ClipRectangle.IntersectsWith(item.DisplayRectangle))
{
Region oldClip = p.Graphics.Clip; //.Clone() as Region;
p.Graphics.SetClip(item.DisplayRectangle, CombineMode.Intersect);
item.Paint(p);
p.Graphics.Clip = oldClip;
if (oldClip != null)
oldClip.Dispose();
}
}
}
}
public void Paint(StepItemContainer container, ItemPaintArgs p)
{
StepItem mouseOverItem = null;
foreach (BaseItem item in container.SubItems)
{
if (item.Visible && item.Displayed)
{
if (p.ClipRectangle.IsEmpty || p.ClipRectangle.IntersectsWith(item.DisplayRectangle))
{
if (item is StepItem && ((StepItem)item).IsMouseOver)
{
mouseOverItem = (StepItem)item;
continue;
}
Region oldClip = p.Graphics.Clip;
p.Graphics.SetClip(item.DisplayRectangle, CombineMode.Intersect);
item.Paint(p);
p.Graphics.Clip = oldClip;
if (oldClip != null)
oldClip.Dispose();
}
}
}
if (mouseOverItem != null)
{
mouseOverItem.Paint(p);
}
}
}
}

View File

@@ -0,0 +1,283 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Collections;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents generic item panel container control.
/// </summary>
[ToolboxBitmap(typeof(ItemPanel), "Ribbon.ItemPanel.ico"), ToolboxItem(true), Designer("DevComponents.DotNetBar.Design.ItemPanelDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false)]
public class ItemPanel : ItemPanelBase, IScrollableItemControl, IBindingSupport
{
#region Private Variables
#endregion
#region Constructor
public ItemPanel()
{
}
#endregion
#region Internal Implementation
/// <summary>
/// Returns first checked top-level button item.
/// </summary>
/// <returns>An ButtonItem object or null if no button could be found.</returns>
public ButtonItem GetChecked()
{
foreach (BaseItem item in this.Items)
{
if (item.Visible && item is ButtonItem && ((ButtonItem)item).Checked)
return item as ButtonItem;
}
return null;
}
/// <summary>
/// Gets or sets default layout orientation inside the control. You can have multiple layouts inside of the control by adding
/// one or more instances of the ItemContainer object and chaning it's LayoutOrientation property.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Layout"), DefaultValue(eOrientation.Horizontal), DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
public virtual eOrientation LayoutOrientation
{
get { return ItemContainer.LayoutOrientation; }
set
{
ItemContainer.LayoutOrientation = value;
if (this.DesignMode)
this.RecalcLayout();
}
}
/// <summary>
/// Gets or sets whether items contained by container are resized to fit the container bounds. When container is in horizontal
/// layout mode then all items will have the same height. When container is in vertical layout mode then all items
/// will have the same width. Default value is true.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(true), Category("Layout")]
public virtual bool ResizeItemsToFit
{
get { return ItemContainer.ResizeItemsToFit; }
set
{
ItemContainer.ResizeItemsToFit = value;
}
}
/// <summary>
/// Gets or sets whether ButtonItem buttons when in vertical layout are fit into the available width so any text inside of them
/// is wrapped if needed. Default value is false.
/// </summary>
[DefaultValue(false), Category("Layout"), Description("Indicates whether ButtonItem buttons when in vertical layout are fit into the available width so any text inside of them is wrapped if needed.")]
public bool FitButtonsToContainerWidth
{
get { return ItemContainer.FitOversizeItemIntoAvailableWidth; }
set
{
ItemContainer.FitOversizeItemIntoAvailableWidth = value;
if (this.DesignMode)
RecalcLayout();
}
}
/// <summary>
/// Gets or sets the item alignment when container is in horizontal layout. Default value is Left.
/// </summary>
[Browsable(true), DefaultValue(eHorizontalItemsAlignment.Left), Category("Layout"), Description("Indicates item alignment when container is in horizontal layout."), DevCoBrowsable(true)]
public eHorizontalItemsAlignment HorizontalItemAlignment
{
get { return ItemContainer.HorizontalItemAlignment; }
set
{
ItemContainer.HorizontalItemAlignment = value;
}
}
/// <summary>
/// Gets or sets whether items in horizontal layout are wrapped into the new line when they cannot fit allotted container size. Default value is false.
/// </summary>
[Browsable(true), DefaultValue(false), Category("Layout"), Description("Indicates whether items in horizontal layout are wrapped into the new line when they cannot fit allotted container size.")]
public virtual bool MultiLine
{
get { return ItemContainer.MultiLine; }
set
{
ItemContainer.MultiLine = value;
}
}
/// <summary>
/// Returns collection of items on a bar.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false)]
public SubItemsCollection Items
{
get
{
return m_ItemContainer.SubItems;
}
}
/// <summary>
/// Indicates whether block elements inside of container when aligned center or right will reserve the space to the left. Default value is true.
/// </summary>
[DefaultValue(true), Category("Indicates whether block elements inside of container (affects span or div for example) when aligned center or right will reserve the space to the left.")]
public bool ReserveLeftSpace
{
get { return ItemContainer.ReserveLeftSpace; }
set { ItemContainer.ReserveLeftSpace = value; }
}
#endregion
#region Binding and Templating Support
/// <summary>
/// Gets or sets the index specifying the currently selected item.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), Description("Gets or sets the index specifying the currently selected item.")]
public override int SelectedIndex
{
get
{
return _SelectedIndex;
}
set
{
if (value != _SelectedIndex)
{
if (value == -1)
{
_SelectedIndex = -1;
SetItemSelection(this.SelectedItem, false);
}
else
{
BaseItem item = null;
if (_SelectedIndex >= this.Items.Count)
{
_SelectedIndex = -1;
return;
}
if (_SelectedIndex > -1)
item = this.Items[_SelectedIndex];
SetItemSelection(this.SelectedItem, false);
SetItemSelection(item, true);
_SelectedIndex = value;
}
OnSelectedIndexChanged(EventArgs.Empty);
}
}
}
protected override void OnButtonCheckedChanged(ButtonItem item, EventArgs e)
{
if (item.Checked)
{
_SelectedIndex = this.Items.IndexOf(item);
OnSelectedIndexChanged(e);
}
base.OnButtonCheckedChanged(item, e);
}
/// <summary>
/// Adds new item to the ItemPanel based on specified ItemTemplate and sets its Text property.
/// </summary>
/// <param name="text">Text to assign to the item.</param>
/// <returns>reference to newly created item</returns>
public BaseItem AddItem(string text)
{
BaseItem template = GetItemTemplate();
if (template == null)
throw new NullReferenceException("ItemTemplate property not set.");
BaseItem item = template.Copy();
item.Text = text;
this.Items.Add(item);
return item;
}
/// <summary>
/// Gets the list of ButtonItem or CheckBoxItem controls that have their Checked property set to true.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public System.Collections.Generic.List<BaseItem> SelectedItems
{
get
{
System.Collections.Generic.List<BaseItem> items = new System.Collections.Generic.List<BaseItem>();
SubItemsCollection itemsCollection = this.Items;
GetSelectedItems(items, itemsCollection);
return items;
}
}
private static void GetSelectedItems(System.Collections.Generic.List<BaseItem> items, SubItemsCollection itemsCollection)
{
foreach (BaseItem item in itemsCollection)
{
if (item is ItemContainer)
{
GetSelectedItems(items, item.SubItems);
continue;
}
ButtonItem button = item as ButtonItem;
if (button != null && button.Checked)
items.Add(button);
else
{
CheckBoxItem cb = item as CheckBoxItem;
if (cb != null && cb.Checked)
items.Add(cb);
else if (item is DevComponents.DotNetBar.Metro.MetroTileItem && ((DevComponents.DotNetBar.Metro.MetroTileItem)item).Checked)
items.Add(item);
}
}
}
/// <summary>
/// Gets or sets ButtonItem or CheckBoxItem item that have their Checked property set to true.
/// </summary>
[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public BaseItem SelectedItem
{
get
{
int i = this.SelectedIndex;
if (i == -1) return null;
return this.Items[i];
}
set
{
SetItemSelection(this.SelectedItem, false);
SetItemSelection(value, true);
if (value != null)
_SelectedIndex = this.Items.IndexOf(value);
else
_SelectedIndex = -1;
}
}
private bool SetItemSelection(BaseItem item, bool isSelected)
{
if (item == null) return false;
bool isSet = true;
if (item is CheckBoxItem)
((CheckBoxItem)item).Checked = isSelected;
else if (item is ButtonItem)
((ButtonItem)item).Checked = isSelected;
else if (item is DevComponents.DotNetBar.Metro.MetroTileItem)
((DevComponents.DotNetBar.Metro.MetroTileItem)item).Checked = isSelected;
else
isSet = false;
return isSet;
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,111 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents canvas for KeyTips
/// </summary>
internal class KeyTipsCanvasControl : Control
{
#region Private variables
private Control m_ParentControl=null;
private IKeyTipsRenderer m_Renderer=null;
#endregion
#region Internal Implementation
public KeyTipsCanvasControl(IKeyTipsRenderer renderer)
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
this.SetStyle(ControlStyles.ContainerControl, false);
this.SetStyle(ControlStyles.Selectable, false);
this.BackColor = Color.Transparent;
m_Renderer = renderer;
}
protected override void Dispose(bool disposing)
{
if (m_ParentControl != null)
{
m_ParentControl.Resize -= new EventHandler(ParentControlResize);
m_ParentControl = null;
}
base.Dispose(disposing);
}
protected override void OnPaint(PaintEventArgs e)
{
if (m_Renderer != null)
{
m_Renderer.PaintKeyTips(e.Graphics);
}
base.OnPaint(e);
}
protected override void OnParentChanged(EventArgs e)
{
if (m_ParentControl != null)
m_ParentControl.Resize -= new EventHandler(ParentControlResize);
m_ParentControl = this.Parent;
if(m_ParentControl!=null)
m_ParentControl.Resize += new EventHandler(ParentControlResize);
base.OnParentChanged(e);
}
protected override void OnPaintBackground(PaintEventArgs e)
{
}
void ParentControlResize(object sender, EventArgs e)
{
if (m_ParentControl == null)
return;
this.Bounds = new Rectangle(0, 0, m_ParentControl.Width, m_ParentControl.Height);
}
protected override CreateParams CreateParams
{
get
{
const int WS_EX_TRANSPARENT = 0x020;
CreateParams p = base.CreateParams;
p.ExStyle = (p.ExStyle | WS_EX_TRANSPARENT);
return p;
}
}
protected override void WndProc(ref Message m)
{
if (m.Msg == (int)WinApi.WindowsMessages.WM_NCHITTEST)
{
m.Result = new IntPtr(-1);
return;
}
base.WndProc(ref m);
}
#endregion
}
internal interface IKeyTipsRenderer
{
void PaintKeyTips(Graphics g);
}
public interface IKeyTipsControl
{
bool ProcessMnemonicEx(char charCode);
bool ShowKeyTips { get;set;}
string KeyTipsKeysStack { get; set; }
}
}

View File

@@ -0,0 +1,13 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
internal abstract class KeyTipsPainter
{
public abstract void PaintKeyTips(KeyTipsRendererEventArgs e);
public static Size KeyTipsPadding = new Size(6, 4);
}
}

View File

@@ -0,0 +1,46 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents data for key tips rendering.
/// </summary>
public class KeyTipsRendererEventArgs:EventArgs
{
/// <summary>
/// Gets or sets the graphics object used for rendering.
/// </summary>
public Graphics Graphics=null;
/// <summary>
/// Gets or sets key tip bounds.
/// </summary>
public Rectangle Bounds = Rectangle.Empty;
/// <summary>
/// Gets or sets the text of key tip to be rendered.
/// </summary>
public string KeyTip = "";
/// <summary>
/// Gets or sets the font key tip should be rendered with.
/// </summary>
public Font Font = null;
/// <summary>
/// Reference object for which Key Tip is rendered. For example this could be reference to an instance of ButtonItem or BaseItem as well
/// as reference to System.Windows.Forms.Control object. Always test for type before accessing this reference.
/// </summary>
public object ReferenceObject = null;
/// <summary>
/// Creates new instance of the object and initializes it with default values.
/// </summary>
public KeyTipsRendererEventArgs(Graphics g, Rectangle bounds, string keyTip, Font font, object referenceObject)
{
this.Graphics = g;
this.Bounds = bounds;
this.KeyTip = keyTip;
this.Font = font;
this.ReferenceObject = referenceObject;
}
}
}

View File

@@ -0,0 +1,17 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents painter for the MdiSystemItem.
/// </summary>
internal class MdiSystemItemPainter
{
/// <summary>
/// Paints MdiSystemItem.
/// </summary>
/// <param name="e">Provides arguments for the operation.</param>
public virtual void Paint(MdiSystemItemRendererEventArgs e) { }
}
}

View File

@@ -0,0 +1,728 @@
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Globalization;
namespace DevComponents.DotNetBar
{
internal class MessageBoxDialog : OfficeForm
{
private ButtonX Button1;
private ButtonX Button2;
private ButtonX Button3;
private PictureBox PictureBox1;
private PanelEx TextPanel;
private PanelEx ButtonBackgroundPanel;
private eDotNetBarStyle m_Style = eDotNetBarStyle.Office2007;
private bool m_Button1Visible = true;
private bool m_Button2Visible = true;
private bool m_Button3Visible = true;
private MessageBoxButtons m_Buttons = MessageBoxButtons.OK;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
public MessageBoxDialog()
{
InitializeComponent();
TextPanel.DisableSelection();
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing)
{
this.Button1.Click -= new System.EventHandler(this.Button1_Click);
this.Button2.Click -= new System.EventHandler(this.Button2_Click);
this.Button3.Click -= new System.EventHandler(this.Button3_Click);
this.TextPanel.MarkupLinkClick -= new MarkupLinkClickEventHandler(TextPanelMarkupLinkClick);
}
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Button1 = new DevComponents.DotNetBar.ButtonX();
this.Button2 = new DevComponents.DotNetBar.ButtonX();
this.Button3 = new DevComponents.DotNetBar.ButtonX();
this.PictureBox1 = new System.Windows.Forms.PictureBox();
this.TextPanel = new DevComponents.DotNetBar.PanelEx();
this.ButtonBackgroundPanel = new DevComponents.DotNetBar.PanelEx();
this.SuspendLayout();
//
// Button1
//
this.Button1.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.Button1.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.Button1.Location = new System.Drawing.Point(26, 85);
this.Button1.Name = "Button1";
this.Button1.Size = new System.Drawing.Size(77, 24);
this.Button1.TabIndex = 0;
this.Button1.Text = "&OK";
this.Button1.Click += new System.EventHandler(this.Button1_Click);
//
// Button2
//
this.Button2.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.Button2.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.Button2.Location = new System.Drawing.Point(109, 85);
this.Button2.Name = "Button2";
this.Button2.Size = new System.Drawing.Size(77, 24);
this.Button2.TabIndex = 1;
this.Button2.Text = "&Cancel";
this.Button2.Click += new System.EventHandler(this.Button2_Click);
//
// Button3
//
this.Button3.AccessibleRole = System.Windows.Forms.AccessibleRole.PushButton;
this.Button3.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.Button3.Location = new System.Drawing.Point(192, 85);
this.Button3.Name = "Button3";
this.Button3.Size = new System.Drawing.Size(77, 24);
this.Button3.TabIndex = 2;
this.Button3.Text = "&Ignore";
this.Button3.Click += new System.EventHandler(this.Button3_Click);
//
// PictureBox1
//
this.PictureBox1.BackColor = System.Drawing.Color.Transparent;
this.PictureBox1.Location = new System.Drawing.Point(10, 10);
this.PictureBox1.Name = "PictureBox1";
this.PictureBox1.Size = new System.Drawing.Size(34, 34);
this.PictureBox1.TabIndex = 3;
this.PictureBox1.TabStop = false;
//
// TextPanel
//
this.TextPanel.AntiAlias = false;
this.TextPanel.CanvasColor = System.Drawing.SystemColors.Control;
this.TextPanel.Location = new System.Drawing.Point(53, 10);
this.TextPanel.Name = "TextPanel";
this.TextPanel.Size = new System.Drawing.Size(225, 53);
this.TextPanel.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
this.TextPanel.Style.BorderWidth = 0;
this.TextPanel.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText;
this.TextPanel.Style.GradientAngle = 90;
this.TextPanel.Style.LineAlignment = System.Drawing.StringAlignment.Near;
this.TextPanel.TabIndex = 4;
this.TextPanel.TabStop = false;
this.TextPanel.Style.WordWrap = true;
this.TextPanel.MarkupLinkClick += new MarkupLinkClickEventHandler(TextPanelMarkupLinkClick);
//
// ButtonBackgroundPanel
//
this.ButtonBackgroundPanel.AntiAlias = false;
this.ButtonBackgroundPanel.CanvasColor = System.Drawing.SystemColors.Control;
this.ButtonBackgroundPanel.Location = new System.Drawing.Point(53, 10);
this.ButtonBackgroundPanel.Name = "ButtonBackgroundPanel";
this.ButtonBackgroundPanel.Size = new System.Drawing.Size(225, 42);
this.ButtonBackgroundPanel.Dock = DockStyle.Bottom;
this.ButtonBackgroundPanel.ColorSchemeStyle = eDotNetBarStyle.StyleManagerControlled;
this.ButtonBackgroundPanel.Style.Border = DevComponents.DotNetBar.eBorderType.SingleLine;
this.ButtonBackgroundPanel.Style.BorderWidth = 1;
this.ButtonBackgroundPanel.Style.BorderSide = eBorderSide.Top;
this.ButtonBackgroundPanel.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.ItemText;
this.ButtonBackgroundPanel.Style.BackColor1.ColorSchemePart = eColorSchemePart.BarBackground;
this.ButtonBackgroundPanel.Style.BorderColor.ColorSchemePart = eColorSchemePart.BarDockedBorder;
this.ButtonBackgroundPanel.Style.GradientAngle = 90;
this.ButtonBackgroundPanel.Style.LineAlignment = System.Drawing.StringAlignment.Near;
this.ButtonBackgroundPanel.TabIndex = 4;
this.ButtonBackgroundPanel.TabStop = false;
//
// MessageBoxDialog
//
#if FRAMEWORK20
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi;
this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); // for design in 96 DPI
#endif
this.ClientSize = new System.Drawing.Size(290, 121);
this.ShowInTaskbar = false;
this.Controls.Add(this.TextPanel);
this.Controls.Add(this.PictureBox1);
this.Controls.Add(this.Button3);
this.Controls.Add(this.Button2);
this.Controls.Add(this.Button1);
this.Controls.Add(this.ButtonBackgroundPanel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "MessageBoxDialog";
this.ResumeLayout(false);
}
#endregion
private void TextPanelMarkupLinkClick(object sender, MarkupLinkClickEventArgs e)
{
MessageBoxEx.InvokeMarkupLinkClick(sender, e);
}
/// <summary>
/// Gets or sets whether Text supports and renders text markup. Default value is true.
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Gets or sets whether Text supports and renders text markup.")]
public bool TextMarkupEnabled
{
get { return TextPanel.TextMarkupEnabled; }
set
{
TextPanel.TextMarkupEnabled = value;
}
}
public DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool topMost)
{
m_Buttons = buttons;
this.Text = caption;
TextPanel.Style.UseMnemonic = false;
TextPanel.Text = text;
if (icon != MessageBoxIcon.None)
{
Image iconImage= GetSystemImage(icon);
if (iconImage != null && iconImage.Width > PictureBox1.Width) PictureBox1.Width = iconImage.Width;
if (iconImage!=null && iconImage.Height > PictureBox1.Height) PictureBox1.Height = iconImage.Height;
PictureBox1.Image = iconImage;
}
else
{
PictureBox1.Image = null;
PictureBox1.Visible = false;
}
if (!BarFunctions.IsOffice2007Style(m_Style))
this.EnableCustomStyle = false;
if (buttons == MessageBoxButtons.OKCancel || buttons == MessageBoxButtons.RetryCancel || buttons == MessageBoxButtons.YesNo)
{
Button3.Visible = false;
m_Button3Visible = false;
}
else if (buttons == MessageBoxButtons.OK)
{
Button2.Visible = false;
Button3.Visible = false;
m_Button2Visible = false;
m_Button3Visible = false;
}
// Set Cancel and Accept buttons
if (buttons == MessageBoxButtons.OK)
{
this.AcceptButton = Button1;
this.CancelButton = Button1;
}
else if (buttons == MessageBoxButtons.OKCancel || buttons == MessageBoxButtons.RetryCancel || buttons == MessageBoxButtons.YesNo)
{
this.AcceptButton = Button1;
this.CancelButton = Button2;
}
else if (buttons == MessageBoxButtons.YesNoCancel)
{
this.AcceptButton = Button1;
this.CancelButton = Button3;
}
SetButtonText(buttons);
if (defaultButton == MessageBoxDefaultButton.Button1 && m_Button1Visible)
{
// Must invoke delayed or due to WinForms bug, if ShowDialog is called from Validated event for control will never lose focus
BarUtilities.InvokeDelayed(new MethodInvoker(delegate { Button1.Select(); }));
this.AcceptButton = Button1;
}
else if (defaultButton == MessageBoxDefaultButton.Button2 && m_Button2Visible)
{
this.AcceptButton = Button2;
// Must invoke delayed or due to WinForms bug, if ShowDialog is called from Validated event for control will never lose focus
BarUtilities.InvokeDelayed(new MethodInvoker(delegate { Button2.Select(); }));
}
else if (defaultButton == MessageBoxDefaultButton.Button3 && m_Button3Visible)
{
this.AcceptButton = Button3;
// Must invoke delayed or due to WinForms bug, if ShowDialog is called from Validated event for control will never lose focus
BarUtilities.InvokeDelayed(new MethodInvoker(delegate { Button3.Select(); }));
}
ResizeDialog();
SetupColors();
#if FRAMEWORK20
if (icon == MessageBoxIcon.Question)
System.Media.SystemSounds.Question.Play(); // NativeFunctions.sndPlaySound("SystemQuestion", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
else if (icon == MessageBoxIcon.Asterisk)
System.Media.SystemSounds.Asterisk.Play(); // NativeFunctions.sndPlaySound("SystemAsterisk", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
else
System.Media.SystemSounds.Exclamation.Play(); // NativeFunctions.sndPlaySound("SystemExclamation", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
#else
if(icon == MessageBoxIcon.Question)
NativeFunctions.sndPlaySound("SystemQuestion", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
else if(icon == MessageBoxIcon.Asterisk)
NativeFunctions.sndPlaySound("SystemAsterisk", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
else
NativeFunctions.sndPlaySound("SystemExclamation", NativeFunctions.SND_ASYNC | NativeFunctions.SND_NODEFAULT);
#endif
if (buttons == MessageBoxButtons.AbortRetryIgnore || buttons == MessageBoxButtons.YesNo)
{
this.CloseEnabled = false;
}
if(this.TopMost!=topMost)
this.TopMost = topMost;
return this.ShowDialog(owner);
}
public eDotNetBarStyle Style
{
get
{
return m_Style;
}
set
{
m_Style = value;
}
}
private void SetupColors()
{
if (!_MessageTextColor.IsEmpty)
{
this.TextPanel.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.Custom;
this.TextPanel.Style.ForeColor.Color = _MessageTextColor;
}
else if (BarFunctions.IsOffice2007Style(m_Style) && Rendering.GlobalManager.Renderer is Rendering.Office2007Renderer)
{
if (WinApi.IsGlassEnabled)
{
this.TextPanel.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.Custom;
this.TextPanel.Style.ForeColor.Color = SystemColors.ControlText;
}
else
{
Rendering.Office2007ColorTable ct = ((Rendering.Office2007Renderer)Rendering.GlobalManager.Renderer).ColorTable;
this.TextPanel.Style.ForeColor.ColorSchemePart = DevComponents.DotNetBar.eColorSchemePart.Custom;
this.TextPanel.Style.ForeColor.Color = ct.Form.TextColor;
}
}
if (this.EnableGlass && WinApi.IsGlassEnabled)
{
Button1.ThemeAware = true;
Button2.ThemeAware = true;
Button3.ThemeAware = true;
this.ButtonBackgroundPanel.Style.BackColor1.Color = SystemColors.ControlLight;
this.ButtonBackgroundPanel.Style.BorderColor.Color = SystemColors.ControlDark;
}
}
private bool _ButtonsDividerVisible = true;
/// <summary>
/// Gets or sets whether divider panel that divides message box buttons and text content is visible. Default value is true.
/// </summary>
public bool ButtonsDividerVisible
{
get { return _ButtonsDividerVisible; }
set
{
if (_ButtonsDividerVisible != value)
{
_ButtonsDividerVisible = value;
this.ButtonBackgroundPanel.Visible = _ButtonsDividerVisible;
}
}
}
private Color _MessageTextColor = Color.Empty;
public Color MessageTextColor
{
get { return _MessageTextColor; }
set { _MessageTextColor = value; }
}
private void SetButtonText(MessageBoxButtons buttons)
{
if (buttons == MessageBoxButtons.AbortRetryIgnore)
{
Button1.Text = GetString(SystemStrings.Abort);
Button2.Text = GetString(SystemStrings.Retry);
Button3.Text = GetString(SystemStrings.Ignore);
}
else if (buttons == MessageBoxButtons.OK)
{
Button1.Text = GetString(SystemStrings.OK);
}
else if (buttons == MessageBoxButtons.OKCancel)
{
Button1.Text = GetString(SystemStrings.OK);
Button2.Text = GetString(SystemStrings.Cancel);
}
else if (buttons == MessageBoxButtons.RetryCancel)
{
Button1.Text = GetString(SystemStrings.Retry);
Button2.Text = GetString(SystemStrings.Cancel);
}
else if (buttons == MessageBoxButtons.YesNo)
{
Button1.Text = GetString(SystemStrings.Yes);
Button2.Text = GetString(SystemStrings.No);
}
else if (buttons == MessageBoxButtons.YesNoCancel)
{
Button1.Text = GetString(SystemStrings.Yes);
Button2.Text = GetString(SystemStrings.No);
Button3.Text = GetString(SystemStrings.Cancel);
}
}
internal static Image GetSystemImage(MessageBoxIcon icon)
{
Icon ico = null;
if (icon == MessageBoxIcon.Asterisk)
ico = SystemIcons.Asterisk;
else if (icon == MessageBoxIcon.Error || icon == MessageBoxIcon.Stop)
ico = SystemIcons.Error;
else if (icon == MessageBoxIcon.Exclamation)
ico = SystemIcons.Exclamation;
else if (icon == MessageBoxIcon.Hand)
ico = SystemIcons.Hand;
else if (icon == MessageBoxIcon.Information)
ico = SystemIcons.Information;
else if (icon == MessageBoxIcon.Question)
ico = SystemIcons.Question;
else if (icon == MessageBoxIcon.Warning)
ico = SystemIcons.Warning;
Bitmap bmp = new Bitmap(ico.Width, ico.Height);
bmp.MakeTransparent();
using (Graphics g = Graphics.FromImage(bmp))
{
if (System.Environment.Version.Build <= 3705 && System.Environment.Version.Revision == 288 && System.Environment.Version.Major == 1 && System.Environment.Version.Minor == 0)
{
IntPtr hdc = g.GetHdc();
try
{
NativeFunctions.DrawIconEx(hdc, 0, 0, ico.Handle, ico.Width, ico.Height, 0, IntPtr.Zero, 3);
}
finally
{
g.ReleaseHdc(hdc);
}
}
else if (ico.Handle != IntPtr.Zero)
{
try
{
g.DrawIcon(ico, 0,0);
}
catch { }
}
}
return bmp;
}
private void ResizeDialog()
{
Size size = Size.Empty;
int buttonSpacing = Dpi.Width6;
int buttonMargin = Dpi.Width(40);
int textMargin = Dpi.Width10;
int minTextSize = Dpi.Width(110);
if (PictureBox1.Image!=null)
{
TextPanel.Left = PictureBox1.Bounds.Right + Dpi.Width16;
}
else
TextPanel.Left = PictureBox1.Left;
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;
TextPanel.Size = TextPanel.GetAutoSize(workingArea.Width);
if (TextPanel.Size.Width > (double)workingArea.Width * .75d)
TextPanel.Size = TextPanel.GetAutoSize((int)((double)workingArea.Width * .75d));
else if (TextPanel.Size.Width < minTextSize)
TextPanel.Width = minTextSize;
// Measure the caption size
if (this.Text.Length > 0)
{
Size captionSize = Size.Empty;
Font font = this.Font;
using (Graphics g = BarFunctions.CreateGraphics(this))
{
size = TextDrawing.MeasureString(g, this.Text, font, 0, eTextFormat.NoPrefix);
}
size.Width += 2;
size.Height += 2;
if (size.Width > TextPanel.Width)
TextPanel.Width = size.Width;
}
int y = Math.Max(TextPanel.Bounds.Bottom, PictureBox1.Bounds.Bottom);
y += Dpi.Height(19);
Button1.Top = y;
Button2.Top = y;
Button3.Top = y;
int buttonWidth = Button1.Width +
(m_Button2Visible ? Button2.Width + buttonSpacing : 0) +
(m_Button3Visible ? Button3.Width + buttonSpacing : 0);
int buttonArea = buttonWidth + buttonMargin * 2;
if (buttonWidth < TextPanel.Bounds.Right + textMargin)
buttonArea = TextPanel.Bounds.Right + textMargin;
else
{
TextPanel.Width += buttonArea - TextPanel.Bounds.Right - textMargin;
}
// Arrange buttons inside of the available area
int x = (buttonArea - buttonWidth) / 2;
Button1.Left = x;
x += Button1.Width + buttonSpacing;
if (m_Button2Visible)
{
Button2.Left = x;
x += Button2.Width + buttonSpacing;
}
if (m_Button3Visible)
{
Button3.Left = x;
x += Button3.Width + buttonSpacing;
}
NonClientInfo frameSize = GetNonClientInfo();
size = new Size(TextPanel.Bounds.Right + textMargin + frameSize.LeftBorder + frameSize.RightBorder,
Button1.Bounds.Bottom + textMargin + frameSize.CaptionTotalHeight + frameSize.BottomBorder);
this.Size = size;
}
private void Button1_Click(object sender, EventArgs e)
{
DialogResult r = DialogResult.OK;
if (m_Buttons == MessageBoxButtons.OK || m_Buttons == MessageBoxButtons.OKCancel)
r = DialogResult.OK;
else if (m_Buttons == MessageBoxButtons.YesNo || m_Buttons == MessageBoxButtons.YesNoCancel)
r = DialogResult.Yes;
else if (m_Buttons == MessageBoxButtons.AbortRetryIgnore)
r = DialogResult.Abort;
else if (m_Buttons == MessageBoxButtons.RetryCancel)
r = DialogResult.Retry;
this.DialogResult = r;
}
private void Button2_Click(object sender, EventArgs e)
{
DialogResult r = DialogResult.Cancel;
if (m_Buttons == MessageBoxButtons.OKCancel)
r = DialogResult.Cancel;
else if (m_Buttons == MessageBoxButtons.YesNo || m_Buttons == MessageBoxButtons.YesNoCancel)
r = DialogResult.No;
else if (m_Buttons == MessageBoxButtons.AbortRetryIgnore)
r = DialogResult.Retry;
else if (m_Buttons == MessageBoxButtons.RetryCancel)
r = DialogResult.Cancel;
this.DialogResult = r;
}
private void Button3_Click(object sender, EventArgs e)
{
DialogResult r = DialogResult.Cancel;
if (m_Buttons == MessageBoxButtons.AbortRetryIgnore)
r = DialogResult.Ignore;
else if (m_Buttons == MessageBoxButtons.YesNoCancel)
r = DialogResult.Cancel;
this.DialogResult = r;
}
protected override void WndProc(ref Message m)
{
int wParamInt = WinApi.ToInt(m.WParam);
if (m.Msg == NativeFunctions.WM_SYSCOMMAND && (wParamInt == NativeFunctions.SC_MAXIMIZE || wParamInt == NativeFunctions.SC_MINIMIZE))
return;
base.WndProc(ref m);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((keyData & Keys.C) == Keys.C && (keyData & Keys.Control) == Keys.Control)
{
string s = "------------------------------" + "\r\n" + this.Text + "\r\n" + "------------------------------" +
"\r\n" + TextPanel.Text +
"\r\n" + "------------------------------" + "\r\n";
if (Button1.Visible)
s += "[" + Button1.Text.Replace("&", "") + "] ";
if (Button2.Visible)
s += "[" + Button2.Text.Replace("&", "") + "] ";
if (Button3.Visible)
s += "[" + Button3.Text.Replace("&", "") + "]";
s += "\r\n------------------------------";
#if (FRAMEWORK20)
Clipboard.SetText(s);
#else
Clipboard.SetDataObject(s);
#endif
}
return base.ProcessCmdKey(ref msg, keyData);
}
/// <summary>
/// Gets or sets the anti-alias setting for text-pane.
/// </summary>
public bool AntiAlias
{
get { return TextPanel.AntiAlias; }
set
{
TextPanel.AntiAlias = value;
}
}
#region System Strings
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern string MB_GetString(int i);
private static string GetLocalizedText(SystemStrings sysString)
{
string key = "";
string result = null;
if (sysString == SystemStrings.Abort)
{
result = "&Abort";
key = LocalizationKeys.MessageBoxAbortButton;
}
else if (sysString == SystemStrings.Cancel)
{
result = "&Cancel";
key = LocalizationKeys.MessageBoxCancelButton;
}
else if (sysString == SystemStrings.Close)
{
result = "C&lose";
key = LocalizationKeys.MessageBoxCloseButton;
}
else if (sysString == SystemStrings.Continue)
{
result = "Co&ntinue";
key = LocalizationKeys.MessageBoxContinueButton;
}
else if (sysString == SystemStrings.Help)
{
result = "&Help";
key = LocalizationKeys.MessageBoxHelpButton;
}
else if (sysString == SystemStrings.Ignore)
{
result = "&Ignore";
key = LocalizationKeys.MessageBoxIgnoreButton;
}
else if (sysString == SystemStrings.No)
{
result = "&No";
key = LocalizationKeys.MessageBoxNoButton;
}
else if (sysString == SystemStrings.OK)
{
result = "&OK";
key = LocalizationKeys.MessageBoxOkButton;
}
else if (sysString == SystemStrings.Retry)
{
result = "&Retry";
key = LocalizationKeys.MessageBoxRetryButton;
}
else if (sysString == SystemStrings.TryAgain)
{
result = "&Try Again";
key = LocalizationKeys.MessageBoxTryAgainButton;
}
else if (sysString == SystemStrings.Yes)
{
result = "&Yes";
key = LocalizationKeys.MessageBoxYesButton;
}
if (key != null)
{
result = LocalizationManager.GetLocalizedString(key, result);
}
return result;
}
private static string GetString(SystemStrings sysString)
{
string result = "";
if (CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.ToLower() != "en" && MessageBoxEx.UseSystemLocalizedString)
{
try
{
result = MB_GetString((int)sysString);
}
catch
{
result = "";
}
}
if (result == "")
{
result = GetLocalizedText(sysString);
}
return result;
}
/// <summary>
/// Enumeration of available common system strings.
/// </summary>
private enum SystemStrings
{
OK = 0,
Cancel = 1,
Abort = 2,
Retry = 3,
Ignore = 4,
Yes = 5,
No = 6,
Close = 7,
Help = 8,
TryAgain = 9,
Continue = 10
}
#endregion
}
}

View File

@@ -0,0 +1,314 @@
using System;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the class that provides MessageBox like functionality with the styled Office 2007 dialog and text markup support.
/// </summary>
public class MessageBoxEx
{
/// <summary>
/// Occurs when text markup link on Message Box is clicked. Markup links can be created using "a" tag, for example:
/// <a name="MyLink">Markup link</a>
/// </summary>
public static event MarkupLinkClickEventHandler MarkupLinkClick;
internal static void InvokeMarkupLinkClick(object sender, MarkupLinkClickEventArgs e)
{
MarkupLinkClickEventHandler h = MarkupLinkClick;
if (h != null)
h(sender, e);
}
/// <summary>
/// Displays a message box with specified text.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text)
{
return ShowInternal(null, text, "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, false);
}
/// <summary>
/// Displays a message box in front of the specified object and with the specified text.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of. </param>
/// <param name="text">The text to display in the message box. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text)
{
return ShowInternal(owner, text, "", MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, GetTopMost(owner));
}
/// <summary>
/// Displays a message box with specified text and caption.
/// </summary>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption)
{
return ShowInternal(null, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, false);
}
/// <summary>
/// Displays a message box with specified text and caption.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of.</param>
/// <param name="text">The text to display in the message box.</param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption)
{
return ShowInternal(owner, text, caption, MessageBoxButtons.OK, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, GetTopMost(owner));
}
/// <summary>
/// Displays a message box with specified text, caption, and buttons.
/// </summary>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
{
return ShowInternal(null, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, false);
}
/// <summary>
/// Displays a message box with specified text, caption, and buttons.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of.</param>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons)
{
return ShowInternal(owner, text, caption, buttons, MessageBoxIcon.None, MessageBoxDefaultButton.Button1, GetTopMost(owner));
}
/// <summary>
/// Displays a message box with specified text, caption, buttons, and icon.
/// </summary>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
return ShowInternal(null, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, false);
}
/// <summary>
/// Displays a message box with specified text, caption, buttons, and icon.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of.</param>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
{
return ShowInternal(owner, text, caption, buttons, icon, MessageBoxDefaultButton.Button1, GetTopMost(owner));
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, and default button.
/// </summary>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the MessageBoxDefaultButton values that specifies the default button for the message box. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
{
return ShowInternal(null, text, caption, buttons, icon, defaultButton, false);
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, and default button.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of.</param>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the MessageBoxDefaultButton values that specifies the default button for the message box. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
{
return ShowInternal(owner, text, caption, buttons, icon, defaultButton, GetTopMost(owner));
}
/// <summary>
/// Displays a message box with the specified text, caption, buttons, icon, and default button.
/// </summary>
/// <param name="owner">The IWin32Window the message box will display in front of.</param>
/// <param name="text">The text to display in the message box. </param>
/// <param name="caption">The text to display in the title bar of the message box.</param>
/// <param name="buttons">One of the MessageBoxButtons values that specifies which buttons to display in the message box.</param>
/// <param name="icon">One of the MessageBoxIcon values that specifies which icon to display in the message box.</param>
/// <param name="defaultButton">One of the MessageBoxDefaultButton values that specifies the default button for the message box. </param>
/// <param name="topMost">Indicates value for Message Box dialog TopMost property. </param>
/// <returns>One of the DialogResult values.</returns>
public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool topMost)
{
return ShowInternal(owner, text, caption, buttons, icon, defaultButton, topMost);
}
private static DialogResult ShowInternal(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool topMost)
{
PopupManager.CloseAllPopups();
DialogResult r = DialogResult.OK;
if (StyleManager.IsMetro(StyleManager.Style))
{
DevComponents.DotNetBar.Metro.MetroMessageBoxDialog d = new DevComponents.DotNetBar.Metro.MetroMessageBoxDialog();
d.AntiAlias = _AntiAlias;
if (owner != null)
d.StartPosition = _OwnerStartPosition; //FormStartPosition.CenterParent;
else
d.StartPosition = _DefaultStartPosition; // FormStartPosition.CenterScreen;
d.MessageTextColor = _MessageBoxTextColor;
d.ButtonsDividerVisible = _ButtonsDividerVisible;
d.TextMarkupEnabled = _TextMarkupEnabled;
r = d.Show(owner, text, caption, buttons, icon, defaultButton, topMost);
d.Dispose();
}
else
{
MessageBoxDialog d = new MessageBoxDialog();
d.EnableGlass = _EnableGlass;
d.AntiAlias = _AntiAlias;
d.TextMarkupEnabled = _TextMarkupEnabled;
if (owner != null)
d.StartPosition = _OwnerStartPosition; //FormStartPosition.CenterParent;
else
d.StartPosition = _DefaultStartPosition; // FormStartPosition.CenterScreen;
d.MessageTextColor = _MessageBoxTextColor;
d.ButtonsDividerVisible = _ButtonsDividerVisible;
r = d.Show(owner, text, caption, buttons, icon, defaultButton, topMost);
d.Dispose();
}
return r;
}
private static bool GetTopMost(IWin32Window owner)
{
if (owner is Form)
return ((Form)owner).TopMost;
return false;
}
private static bool _UseSystemLocalizedString = false;
/// <summary>
/// Gets or sets whether MessageBoxEx is using Windows System API function to retrieve the localized strings used by MessageBoxEx. Set this to false
/// if you experience issues when using MessageBoxEx under certain conditions.
/// </summary>
public static bool UseSystemLocalizedString
{
get
{
return _UseSystemLocalizedString;
}
set
{
_UseSystemLocalizedString = value;
}
}
private static bool _EnableGlass = true;
/// <summary>
/// Gets or sets whether MessageBoxEx form has Windows Vista Glass enabled if running on
/// Windows Vista with Glass enabled. Default value is true.
/// </summary>
public static bool EnableGlass
{
get { return _EnableGlass; }
set
{
_EnableGlass = value;
}
}
private static bool _AntiAlias = false;
/// <summary>
/// Gets or sets the anti-alias setting for message box text.
/// </summary>
public static bool AntiAlias
{
get { return _AntiAlias; }
set
{
_AntiAlias = value;
}
}
private static Color _MessageBoxTextColor = Color.Empty;
/// <summary>
/// Gets or sets the text color for the message box text. Default value is Color.Empty which indicates that system colors are used.
/// </summary>
public static Color MessageBoxTextColor
{
get { return _MessageBoxTextColor; }
set
{
_MessageBoxTextColor = value;
}
}
private static bool _ButtonsDividerVisible = true;
/// <summary>
/// Gets or sets whether divider panel that divides message box buttons and text content is visible. Default value is true.
/// </summary>
public static bool ButtonsDividerVisible
{
get { return _ButtonsDividerVisible; }
set
{
_ButtonsDividerVisible = value;
}
}
private static FormStartPosition _DefaultStartPosition = FormStartPosition.CenterScreen;
/// <summary>
/// Gets or sets the message box start position when Owner is not specified. Default value is CenterScreen.
/// </summary>
public static FormStartPosition DefaultStartPosition
{
get { return _DefaultStartPosition; }
set { _DefaultStartPosition = value; }
}
private static FormStartPosition _OwnerStartPosition = FormStartPosition.CenterParent;
/// <summary>
/// Gets or sets the message box start position when Owner is specified. Default value is CenterParent.
/// </summary>
public static FormStartPosition OwnerStartPosition
{
get { return _OwnerStartPosition; }
set { _OwnerStartPosition = value; }
}
private static bool _TextMarkupEnabled = true;
/// <summary>
/// Gets or sets whether message box text renders text markup. Default value is true.
/// </summary>
[DefaultValue(true), Category("Behavior"), Description("Gets or sets whether message box text renders text markup.")]
public static bool TextMarkupEnabled
{
get { return _TextMarkupEnabled; }
set { _TextMarkupEnabled = value; }
}
}
}

View File

@@ -0,0 +1,827 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using DevComponents.DotNetBar.Ribbon;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for Office2003ButtonItemPainter.
/// </summary>
internal class Office2003ButtonItemPainter:ButtonItemPainter
{
protected virtual Color GetTextColor(ButtonItem button, ItemPaintArgs pa)
{
return ButtonItemPainterHelper.GetTextColor(button, pa);
}
protected virtual Rectangle GetDisplayRectangle(ButtonItem button)
{
return button.DisplayRectangle;
}
public override void PaintButton(ButtonItem button, ItemPaintArgs pa)
{
bool isOnMenu=IsOnMenu(button, pa);
if(isOnMenu && button.Parent is ItemContainer)
isOnMenu=false;
bool bIsOnMenuBar=pa.IsOnMenuBar;
bool bThemed=button.IsThemed;
Graphics g = pa.Graphics;
Region oldClip = g.Clip as Region;
Rectangle itemRect = GetDisplayRectangle(button);
try
{
g.SetClip(itemRect, CombineMode.Intersect);
if (!pa.IsOnMenu && !bIsOnMenuBar && bThemed)
{
if (pa.ContainerControl is ButtonX)
ThemedButtonXPainter.PaintButton(button, pa);
else
ThemedButtonItemPainter.PaintButton(button, pa);
return;
}
Color textColor = GetTextColor(button, pa);
CompositeImage image = button.GetImage(textColor);
Rectangle imageRect = GetImageRectangle(button, pa, image);
PaintButtonBackground(button, pa, image);
Rectangle customizeCheckRect = GetCustomizeMenuCheckRectangle(button, pa);
Rectangle checkRect = GetCheckRectangle(button, pa, image);
Rectangle mouseOverRect = GetMouseOverRectangle(button, pa, image);
bool mouseOver = button.IsMouseOver;
if (button.Expanded && !isOnMenu)
mouseOver = false;
if (isOnMenu && button.Expanded && pa.ContainerControl != null && pa.ContainerControl.Parent != null)
{
if (!pa.ContainerControl.Parent.Bounds.Contains(System.Windows.Forms.Control.MousePosition))
mouseOver = true;
}
if (button.HotTrackingStyle != eHotTrackingStyle.None)
{
if (mouseOver || button.IsMouseDown && !button.DesignMode)
PaintButtonMouseOver(button, pa, image, mouseOverRect);
}
if (isOnMenu && button.IsOnCustomizeMenu && button.Visible && !button.SystemItem)
PaintCustomizeCheck(button, pa, customizeCheckRect);
if (button.Checked && !button.IsOnCustomizeMenu && (button.GetEnabled(pa.ContainerControl) || isOnMenu))
PaintButtonCheck(button, pa, image, checkRect);
if ((image != null || !string.IsNullOrEmpty(button.SymbolRealized)) && button.ButtonStyle != eButtonStyle.TextOnlyAlways)
PaintButtonImage(button, pa, image, imageRect);
if (!(button is ApplicationButton) || button.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(button.EffectiveStyle))
PaintButtonText(button, pa, textColor, image);
PaintExpandButton(button, pa);
if (button.Focused && button.DesignMode)
{
Rectangle r = itemRect;
r.Inflate(-1, -1);
DesignTime.DrawDesignTimeSelection(g, r, pa.Colors.ItemDesignTimeBorder);
}
if (image != null)
image.Dispose();
}
finally
{
if (oldClip != null)
{
g.Clip = oldClip;
oldClip.Dispose();
}
else
g.ResetClip();
}
}
protected virtual bool IsOnMenu(ButtonItem button, ItemPaintArgs pa)
{
bool isOnMenu = pa.IsOnMenu;
if (isOnMenu && button.Parent is ItemContainer)
isOnMenu = false;
return isOnMenu;
}
public override void PaintButtonImage(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle imagebounds)
{
bool isOnMenu = IsOnMenu(button, pa);
if (imagebounds.Width <= 0 || imagebounds.Height <= 0) return;
if (!string.IsNullOrEmpty(button.SymbolRealized))
{
Font font = Symbols.GetFont(button.SymbolSize, button.SymbolSet);
Color symbolColor = (button.SymbolColor.IsEmpty || !button.Enabled ? GetTextColor(button, pa) : button.SymbolColor);
if (isOnMenu)
TextDrawing.DrawStringLegacy(pa.Graphics, button.SymbolRealized, font, symbolColor, new Rectangle(imagebounds.X + imagebounds.Width / 2, imagebounds.Y, 0, 0), eTextFormat.Default | eTextFormat.HorizontalCenter);
else
TextDrawing.DrawStringLegacy(pa.Graphics, button.SymbolRealized, font, symbolColor, new Rectangle(imagebounds.X, imagebounds.Y - ((button.ImagePosition == eImagePosition.Bottom || Dpi.Factor.Width>1 || !pa.IsBackstageTab) ? 0 : 2), 0, 0), eTextFormat.Default);
return;
}
if (button.EnableImageAnimation && button.CanAnimateImage)
{
if (!button.CurrentlyAnimatingImage)
button.StartImageAnimation(image.Image);
ImageAnimator.UpdateFrames();
}
if (isOnMenu)
{
image.DrawImage(pa.Graphics, imagebounds);
}
else if (!button.IsMouseOver && button.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(pa.Graphics, imagebounds, 0, 0, image.ActualWidth, image.ActualHeight, GraphicsUnit.Pixel, att);
}
else
{
image.DrawImage(pa.Graphics, imagebounds);
}
}
public override Rectangle GetImageRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
Rectangle imageRect = Rectangle.Empty;
bool isOnMenu = IsOnMenu(button, pa);
// Calculate image position
if (image != null || !string.IsNullOrEmpty(button.SymbolRealized))
{
Size imageSize = button.ImageSize;
Rectangle displayRect = GetDisplayRectangle(button);
if (pa.RightToLeft && isOnMenu)
{
imageRect = new Rectangle(displayRect.Right - (button.ImageDrawRect.X + imageSize.Width + 2), button.ImageDrawRect.Y + displayRect.Y, imageSize.Width, imageSize.Height);
}
else
{
if (!isOnMenu && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
imageRect = new Rectangle(button.ImageDrawRect.X, button.ImageDrawRect.Y, displayRect.Width, button.ImageDrawRect.Height);
else
imageRect = new Rectangle(button.ImageDrawRect.X, button.ImageDrawRect.Y, button.ImageDrawRect.Width, button.ImageDrawRect.Height);
imageRect.Offset(displayRect.Left, displayRect.Top);
if ((button.EffectiveStyle == eDotNetBarStyle.Windows7 || button.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(button.EffectiveStyle)) && (button is ApplicationButton || button is DevComponents.DotNetBar.Metro.MetroAppButton))
imageRect.Offset(14, (imageRect.Height - imageSize.Height) / 2);
else
imageRect.Offset((imageRect.Width - imageSize.Width) / 2, (imageRect.Height - imageSize.Height) / 2);
imageRect.Width = imageSize.Width;
imageRect.Height = imageSize.Height;
}
}
return imageRect;
}
public override Rectangle GetCheckRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
Rectangle r = Rectangle.Empty;
bool isOnMenu = IsOnMenu(button, pa);
Rectangle displayRect = GetDisplayRectangle(button);
if (isOnMenu)
{
//r=new Rectangle(button.DisplayRectangle.X+1,button.DisplayRectangle.Y,button.ImageDrawRect.Width-2,button.DisplayRectangle.Height);
//r.Inflate(-1,-1);
// This modification fixes the bug of the checkbox appearing on the wrong side of the button item in RightToLeft mode, thanks Brian!
if (pa.RightToLeft)
{
r = new Rectangle(displayRect.Right - button.ImageDrawRect.Width + 1, displayRect.Y, button.ImageDrawRect.Width - 2, displayRect.Height);
r.Inflate(-1, -1);
}
else
{
// LTR also adjusted by one pixel from original alignment to give more logical position.
// TODO: Find out if MS Office 2007 positions like this or like the original. Original might be right.
r = new Rectangle(displayRect.X, displayRect.Y, button.ImageDrawRect.Width - 2, displayRect.Height);
r.Inflate(-1, -1);
}
}
else if (button.HotTrackingStyle == eHotTrackingStyle.Image && image != null)
{
r = GetImageRectangle(button, pa, image);
r.Inflate(2, 2);
}
else
r = displayRect;
return r;
}
public override Rectangle GetCustomizeMenuCheckRectangle(ButtonItem button, ItemPaintArgs pa)
{
bool isOnMenu = IsOnMenu(button, pa);
Rectangle r = Rectangle.Empty;
if (isOnMenu && button.IsOnCustomizeMenu && button.Visible && !button.SystemItem)
{
Rectangle displayRect = GetDisplayRectangle(button);
r = new Rectangle(displayRect.Left, displayRect.Top, displayRect.Height, displayRect.Height);
r.Inflate(-1, -1);
//System.Diagnostics.Trace.WriteLine("r="+r.ToString()+" "+button.Text+" "+button.ImageDrawRect.ToString()+" "+button.DisplayRectangle.ToString());
}
return r;
}
public override void PaintCustomizeCheck(ButtonItem button, ItemPaintArgs pa, Rectangle r)
{
Color clr=pa.Colors.ItemCheckedBackground;
Graphics g=pa.Graphics;
if(button.IsMouseOver && !pa.Colors.ItemHotBackground2.IsEmpty)
{
using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemHotBackground,pa.Colors.ItemHotBackground2,pa.Colors.ItemHotBackgroundGradientAngle))
{
g.FillRectangle(gradient,r);
}
}
else
{
if(button.IsMouseOver)
clr=pa.Colors.ItemHotBackground;
if(!pa.Colors.ItemCheckedBackground2.IsEmpty && !button.IsMouseOver)
{
using(LinearGradientBrush gradient=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemCheckedBackground,pa.Colors.ItemCheckedBackground2,pa.Colors.ItemCheckedBackgroundGradientAngle))
g.FillRectangle(gradient,r);
}
else
{
using(SolidBrush brush=new SolidBrush(clr))
g.FillRectangle(brush,r);
}
}
Pen objPen=new Pen(pa.Colors.ItemCheckedBorder,Dpi.Width1);
DisplayHelp.DrawRectangle(g,objPen,r);
objPen.Dispose();
objPen=new Pen(pa.Colors.ItemCheckedText);
// Draw checker...
Point[] pt=new Point[3];
pt[0].X = r.Left + (r.Width - Dpi.Width5) / 2 - Dpi.Width1;
pt[0].Y = r.Top + (r.Height - Dpi.Height6) / 2 + Dpi.Height3;
pt[1].X = pt[0].X + Dpi.Width2;
pt[1].Y = pt[0].Y + Dpi.Height2;
pt[2].X = pt[1].X + Dpi.Width4;
pt[2].Y = pt[1].Y - Dpi.Height4;
g.DrawLines(objPen,pt);
pt[0].X++;
pt[1].X++;
pt[2].X++;
g.DrawLines(objPen,pt);
objPen.Dispose();
}
/// <summary>
/// Paints state of the button, either hot, pressed or checked
/// </summary>
/// <param name="button"></param>
/// <param name="pa"></param>
/// <param name="image"></param>
public override void PaintButtonMouseOver(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
bool isMouseDown=button.IsMouseDown;
bool isOnMenu = IsOnMenu(button, pa);
Graphics g=pa.Graphics;
Brush brush=null;
Pen pen=null;
if(isMouseDown && !isOnMenu)
{
if(pa.Colors.ItemPressedBackground2.IsEmpty)
brush=new SolidBrush(pa.Colors.ItemPressedBackground);
else
brush=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemPressedBackground,pa.Colors.ItemPressedBackground2,pa.Colors.ItemPressedBackgroundGradientAngle);
pen=new Pen(pa.Colors.ItemPressedBorder,1);
}
else
{
if(IsItemEnabled(button, pa))
{
if(!pa.Colors.ItemHotBackground2.IsEmpty)
brush=BarFunctions.CreateLinearGradientBrush(r,pa.Colors.ItemHotBackground,pa.Colors.ItemHotBackground2,pa.Colors.ItemHotBackgroundGradientAngle);
else
brush=new SolidBrush(pa.Colors.ItemHotBackground);
pen = new Pen(pa.Colors.ItemHotBorder, 1);
}
else if(isOnMenu)
pen=new Pen(pa.Colors.ItemHotBorder,1);
}
if(brush!=null)
{
//Rectangle rf=r;
//rf.Width--;
//rf.Height--;
g.FillRectangle(brush,r);
}
if(pen!=null)
DisplayHelp.DrawRectangle(g,pen,r);
if(brush!=null)
brush.Dispose();
if(pen!=null)
pen.Dispose();
}
protected virtual void PaintButtonCheckBackground(ButtonItem button, ItemPaintArgs pa, Rectangle r)
{
Graphics g = pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
if (!button.IsMouseOver || isOnMenu)
{
DisplayHelp.FillRectangle(g, r, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
DisplayHelp.DrawRectangle(g, pa.Colors.ItemCheckedBorder, r);
}
}
public override void PaintButtonCheck(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
if(r.IsEmpty)
return;
bool isOnMenu = IsOnMenu(button, pa);
Graphics g=pa.Graphics;
PaintButtonCheckBackground(button, pa, r);
if((image==null && string.IsNullOrEmpty(button.SymbolRealized) || button.ButtonStyle==eButtonStyle.TextOnlyAlways) && isOnMenu)
{
// Draw checker...
using (Pen pen = new Pen((IsItemEnabled(button, pa) ? pa.Colors.ItemCheckedText : pa.Colors.ItemDisabledText), Dpi.Width1))
{
Point[] pt = new Point[3];
pt[0].X = r.Left + (r.Width - Dpi.Width5) / 2 - Dpi.Width1;
pt[0].Y = r.Top + (r.Height - Dpi.Height6) / 2 + Dpi.Height3;
pt[1].X = pt[0].X + Dpi.Width2;
pt[1].Y = pt[0].Y + Dpi.Height2;
pt[2].X = pt[1].X + Dpi.Width4;
pt[2].Y = pt[1].Y - Dpi.Height4;
g.DrawLines(pen, pt);
pt[0].X += Dpi.Width1;
//pt[0].Y
pt[1].X += Dpi.Width1;
//pt[1].Y;
pt[2].X += Dpi.Width1;
//pt[2].Y;
g.DrawLines(pen, pt);
}
}
}
public override Rectangle GetMouseOverRectangle(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
Rectangle r = GetDisplayRectangle(button);
if(button.HotTrackingStyle==eHotTrackingStyle.None || button.HotTrackingStyle==eHotTrackingStyle.Color)
return Rectangle.Empty;
if(button.HotTrackingStyle==eHotTrackingStyle.Image && image!=null)
{
r=GetImageRectangle(button,pa,image);
r.Inflate(2,2);
return r;
}
bool isOnMenu = IsOnMenu(button, pa);
if(isOnMenu)
{
r.X++;
r.Width-=2;
}
return r;
}
public override eTextFormat GetStringFormat(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
eTextFormat stringFormat=pa.ButtonStringFormat;
bool isOnMenu = IsOnMenu(button, pa);
if(!isOnMenu)
{
if(pa.ContainerControl is RibbonStrip && (image==null && string.IsNullOrEmpty(button.SymbolRealized) || button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
|| button._FixedSizeCenterText)
stringFormat |= eTextFormat.HorizontalCenter;
else if (pa.ContainerControl is ButtonX)
{
ButtonX buttonX = pa.ContainerControl as ButtonX;
if(buttonX.TextAlignment== eButtonTextAlignment.Center)
stringFormat |= eTextFormat.HorizontalCenter;
else if(buttonX.TextAlignment== eButtonTextAlignment.Left)
stringFormat |= eTextFormat.Left;
else if (buttonX.TextAlignment == eButtonTextAlignment.Right && (image == null && string.IsNullOrEmpty(button.SymbolRealized) || button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
stringFormat |= eTextFormat.Right;
if (!buttonX.UseMnemonic)
stringFormat |= eTextFormat.NoPrefix;
}
else if (pa.IsOnMenuBar || (pa.ContainerControl is Bar || pa.ContainerControl is ButtonX || button.Orientation == eOrientation.Vertical) && image == null && string.IsNullOrEmpty(button.SymbolRealized) || button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)
stringFormat |= eTextFormat.HorizontalCenter;
//if (pa.ContainerControl is RibbonBar) // VerticalCenter in this configuration was causing the bottom pixels to be cut off so remove it for all cases when images are on top or bottom
{
if (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)
{
if (image != null || !string.IsNullOrEmpty(button.SymbolRealized))
stringFormat |= eTextFormat.WordBreak;
stringFormat = stringFormat & ~(stringFormat & eTextFormat.VerticalCenter) | eTextFormat.Top;
}
}
}
if (pa.RightToLeft) stringFormat |= eTextFormat.RightToLeft;
return stringFormat;
}
protected virtual bool IsTextCentered(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
bool isOnMenu = IsOnMenu(button, pa);
if (!isOnMenu)
{
System.Windows.Forms.Control cc = pa.ContainerControl;
if (cc is RibbonStrip && (image == null && string.IsNullOrEmpty(button.SymbolRealized) || button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom) || button.Name.StartsWith("sysgallery") || button._FixedSizeCenterText)
return true;
else if (cc is ButtonX)
{
ButtonX buttonX = cc as ButtonX;
if (buttonX.TextAlignment == eButtonTextAlignment.Center)
return true;
}
else if (pa.IsOnMenuBar || cc is Bar && image == null && string.IsNullOrEmpty(button.SymbolRealized) || (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
return true;
}
return false;
}
protected virtual Rectangle GetTextRectangle(ButtonItem button, ItemPaintArgs pa, eTextFormat stringFormat, CompositeImage image)
{
Graphics g = pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
bool isOnMenuBar = pa.IsOnMenuBar;
Rectangle itemRect = GetDisplayRectangle(button);
Rectangle textRect = button.TextDrawRect;
Rectangle imageRect = button.ImageDrawRect;
bool rightToLeft = pa.RightToLeft;
// Draw menu item text
if (isOnMenu || button.ButtonStyle != eButtonStyle.Default || image == null && string.IsNullOrEmpty(button.SymbolRealized) || (!isOnMenu && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)))
{
if (isOnMenu)
{
if (rightToLeft)
{
//rect = new Rectangle(26, button.TextDrawRect.Y, itemRect.Width - button.ImageDrawRect.Width - 28, button.TextDrawRect.Height);
// This seems to give a better alignment match with the corresponding LTR alignment
if(button.IsOnCustomizeMenu)
textRect = new Rectangle(itemRect.Height, textRect.Y, itemRect.Width - imageRect.Width - 11 - itemRect.Height, textRect.Height);
else
textRect = new Rectangle(17, textRect.Y, itemRect.Width - imageRect.Width - 28, textRect.Height);
}
else
textRect = new Rectangle(textRect.X, textRect.Y, itemRect.Width - imageRect.Right - 26, textRect.Height);
}
else
{
//rect = button.TextDrawRect;
if (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)
{
if (button.Orientation != eOrientation.Vertical)
{
textRect = new Rectangle(1, textRect.Y + 2, itemRect.Width - 2, textRect.Height);
if (button.SplitButton || pa.ContainerControl is RibbonBar) textRect.Y += 2;
}
}
}
if (image == null && string.IsNullOrEmpty(button.SymbolRealized) && (stringFormat & eTextFormat.HorizontalCenter) != eTextFormat.HorizontalCenter &&
!isOnMenu && !isOnMenuBar && textRect.X == 0 && !pa.RightToLeft)
textRect.X = 3;
textRect.Offset(itemRect.Left, itemRect.Top);
if (button.Orientation == eOrientation.Vertical && !isOnMenu)
{
if (textRect.Bottom > itemRect.Bottom)
textRect.Height = itemRect.Bottom - textRect.Y;
}
else
{
if (textRect.Right > itemRect.Right)
textRect.Width = itemRect.Right - textRect.Left;
}
}
return textRect;
}
public override void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image)
{
if (!button.RenderText) return;
Graphics g=pa.Graphics;
eTextFormat stringFormat=GetStringFormat(button,pa,image);
bool isOnMenu = IsOnMenu(button, pa);
bool isOnMenuBar=pa.IsOnMenuBar;
Rectangle itemRect = GetDisplayRectangle(button);
Rectangle rect=GetTextRectangle(button, pa, stringFormat, image);
Font font=button.GetFont(pa, false);
bool rightToLeft = pa.RightToLeft;
//if (isOnMenu && rightToLeft || (stringFormat & eTextFormat.Left) == eTextFormat.Left)
// stringFormat |=eTextFormat.Right;
// Draw menu item text
if (isOnMenu || button.ButtonStyle != eButtonStyle.Default || image == null && string.IsNullOrEmpty(button.SymbolRealized) || (!isOnMenu && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom)))
{
if(button.Orientation==eOrientation.Vertical && !isOnMenu)
{
g.RotateTransform(90);
if (button.TextMarkupBody == null)
{
TextDrawing.DrawStringLegacy(g, GetDrawText(button.Text), font, textColor, new Rectangle(rect.Top, -rect.Right, rect.Height, rect.Width), stringFormat);
}
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
button.TextMarkupBody.Bounds = new Rectangle(rect.Top, -rect.Right, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
button.TextMarkupBody.Render(d);
}
g.ResetTransform();
}
else
{
if (button.TextMarkupBody == null)
{
#if FRAMEWORK20
if (pa.GlassEnabled && (button.Parent is CaptionItemContainer || button.Parent is RibbonTabItemContainer && (button.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(button.EffectiveStyle))) && !(pa.ContainerControl is QatToolbar))
{
if (!pa.CachedPaint)
Office2007RibbonControlPainter.PaintTextOnGlass(g, button.Text, font, rect, TextDrawing.GetTextFormat(stringFormat), textColor, true, !button.IsMouseOver && !ColorFunctions.IsEqual(textColor, Color.White), 7);
}
else
#endif
TextDrawing.DrawString(g, GetDrawText(button.Text), font, textColor, rect, stringFormat);
}
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, textColor, rightToLeft);
d.HotKeyPrefixVisible = !((stringFormat & eTextFormat.HidePrefix) == eTextFormat.HidePrefix);
d.ContextObject = button;
Rectangle mr = new Rectangle((rightToLeft && isOnMenu?rect.X+rect.Width-button.TextMarkupBody.Bounds.Width:rect.X), rect.Y + (rect.Height - button.TextMarkupBody.Bounds.Height) / 2 /*- (isOnMenu ? -1 : -1)*/+1, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
if (pa.ContainerControl is RibbonBar && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
mr = new Rectangle(rect.X + (rect.Width - button.TextMarkupBody.Bounds.Width) / 2, rect.Y, button.TextMarkupBody.Bounds.Width, button.TextMarkupBody.Bounds.Height);
else if (IsTextCentered(button, pa, image))
mr.Offset((rect.Width - mr.Width) / 2, 0);
if (button._FixedSizeCenterText) mr.Y--;
button.TextMarkupBody.Bounds = mr;
button.TextMarkupBody.Render(d);
}
if(!button.DesignMode && button.Focused && !isOnMenu && !isOnMenuBar && !(pa.ContainerControl is ButtonX && !((ButtonX)pa.ContainerControl).FocusCuesEnabled))
{
Rectangle r=itemRect;
r.Inflate(-2, -2);
ControlPaint.DrawFocusRectangle(g,r);
}
}
}
// Draw Shortcut text if needed
if( button.DrawShortcutText!="" && isOnMenu && !button.IsOnCustomizeDialog)
{
stringFormat |= eTextFormat.HidePrefix;
//if(rightToLeft)
// stringFormat = stringFormat & ~(stringFormat & eTextFormat.Right) | eTextFormat.Left;
//else
stringFormat|=eTextFormat.Right;
TextDrawing.DrawString(g, button.DrawShortcutText, font, textColor, rect, stringFormat);
}
}
protected virtual Rectangle GetTotalSubItemsRect(ButtonItem button)
{
return button.GetTotalSubItemsRect();
}
public override void PaintExpandButton(ButtonItem button, ItemPaintArgs pa)
{
Graphics g=pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
Rectangle itemRect = GetDisplayRectangle(button);
bool mouseOver=button.IsMouseOver;
Color textColor = this.GetTextColor(button, pa);
using (SolidBrush textBrush = new SolidBrush(textColor))
{
// If it has subitems draw the triangle to indicate that
if ((button.SubItems.Count > 0 || button.PopupType == ePopupType.Container) && button.ShowSubItems)
{
if (isOnMenu)
{
Point[] p = new Point[3];
if (pa.RightToLeft)
{
p[0].X = itemRect.Left + 8;
p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 8;
p[2].X = p[0].X - 4;
p[2].Y = p[0].Y + 4;
}
else
{
p[0].X = itemRect.Left + itemRect.Width - 12;
p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 8;
p[2].X = p[0].X + 4;
p[2].Y = p[0].Y + 4;
}
g.FillPolygon(textBrush, p);
}
else if (!button.SubItemsRect.IsEmpty)
{
if (IsItemEnabled(button, pa) && ((mouseOver || button.Checked) && !button.Expanded && button.HotTrackingStyle != eHotTrackingStyle.None && button.HotTrackingStyle != eHotTrackingStyle.Image) && !button.AutoExpandOnClick)
{
Rectangle r = GetTotalSubItemsRect(button); // button.SubItemsRect;
r.Offset(itemRect.Location);
using (Pen mypen = new Pen(mouseOver?pa.Colors.ItemHotBorder:pa.Colors.ItemCheckedBorder))
DisplayHelp.DrawRectangle(g, mypen, r);
}
PaintButtonExpandIndicator(button, pa);
}
}
}
}
protected virtual void PaintMenuItemSide(ButtonItem button, ItemPaintArgs pa, Rectangle sideRect)
{
Graphics g = pa.Graphics;
Region oldClip = g.Clip.Clone() as Region;
g.SetClip(sideRect);
sideRect.Inflate(0, 1);
// Draw side bar
if (button.MenuVisibility == eMenuVisibility.VisibleIfRecentlyUsed && !button.RecentlyUsed)
{
DisplayHelp.FillRectangle(g, sideRect, pa.Colors.MenuUnusedSide, pa.Colors.MenuUnusedSide2, pa.Colors.MenuUnusedSideGradientAngle);
}
else
{
DisplayHelp.FillRectangle(g, sideRect, pa.Colors.MenuSide, pa.Colors.MenuSide2, pa.Colors.MenuSideGradientAngle);
}
if (oldClip != null)
g.Clip = oldClip;
else
g.ResetClip();
}
public override void PaintButtonBackground(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
Graphics g = pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
Rectangle displayRect = GetDisplayRectangle(button);
if (isOnMenu)
{
Rectangle sideRect = new Rectangle(displayRect.Left, displayRect.Top, button.ImageDrawRect.Right, displayRect.Height);
if (pa.RightToLeft)
{
sideRect = new Rectangle(displayRect.Right - button.ImageDrawRect.Right, displayRect.Top, button.ImageDrawRect.Right, displayRect.Height);
}
PaintMenuItemSide(button, pa, sideRect);
}
else
{
// Draw button background
if (!pa.Colors.ItemBackground.IsEmpty)
{
if (pa.Colors.ItemBackground2.IsEmpty)
{
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemBackground))
g.FillRectangle(mybrush, displayRect);
}
else
{
using (LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(displayRect, pa.Colors.ItemBackground, pa.Colors.ItemBackground2, pa.Colors.ItemBackgroundGradientAngle))
g.FillRectangle(gradient, displayRect);
}
}
else if (!IsItemEnabled(button, pa) && !pa.Colors.ItemDisabledBackground.IsEmpty)
{
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledBackground))
g.FillRectangle(mybrush, displayRect);
}
}
Rectangle itemRect = displayRect;
if (IsItemEnabled(button, pa) || button.DesignMode)
{
if (button.Expanded && !isOnMenu)
{
// DotNet Style
if (pa.Colors.ItemExpandedBackground2.IsEmpty)
{
Rectangle rBack = displayRect;
if (!pa.Colors.ItemExpandedShadow.IsEmpty)
rBack.Width -= 2;
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemExpandedBackground))
g.FillRectangle(mybrush, rBack);
}
else
{
LinearGradientBrush gradient = BarFunctions.CreateLinearGradientBrush(new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width - 2, itemRect.Height), pa.Colors.ItemExpandedBackground, pa.Colors.ItemExpandedBackground2, pa.Colors.ItemExpandedBackgroundGradientAngle);
Rectangle rBack = new Rectangle(itemRect.Left, itemRect.Top, itemRect.Width, itemRect.Height);
if (!pa.Colors.ItemExpandedShadow.IsEmpty)
rBack.Width -= 2;
g.FillRectangle(gradient, rBack);
gradient.Dispose();
}
Point[] p;
if (button.Orientation == eOrientation.Horizontal && button.PopupSide == ePopupSide.Default)
p = new Point[4];
else
p = new Point[5];
p[0].X = itemRect.Left;
p[0].Y = itemRect.Top + itemRect.Height - 1;
p[1].X = itemRect.Left;
p[1].Y = itemRect.Top;
if (button.Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/)
{
if (!pa.Colors.ItemExpandedShadow.IsEmpty)
p[2].X = itemRect.Left + itemRect.Width - 3;
else
p[2].X = itemRect.Right - 1;
}
else
p[2].X = itemRect.Left + itemRect.Width - 1;
p[2].Y = itemRect.Top;
if (button.Orientation == eOrientation.Horizontal /*&& !pa.Colors.ItemExpandedShadow.IsEmpty*/)
{
if (!pa.Colors.ItemExpandedShadow.IsEmpty)
p[3].X = itemRect.Left + itemRect.Width - 3;
else
p[3].X = itemRect.Right - 1;
}
else
p[3].X = itemRect.Left + itemRect.Width - 1;
p[3].Y = itemRect.Top + itemRect.Height - 1;
if (button.Orientation == eOrientation.Vertical || button.PopupSide != ePopupSide.Default)
{
p[4].X = itemRect.Left;
p[4].Y = itemRect.Top + itemRect.Height - 1;
}
if (!pa.Colors.ItemExpandedBorder.IsEmpty)
{
using (Pen mypen = new Pen(pa.Colors.ItemExpandedBorder, 1))
g.DrawLines(mypen, p);
}
// Draw the shadow
if (!pa.Colors.ItemExpandedShadow.IsEmpty && button.Orientation == eOrientation.Horizontal)
{
using (SolidBrush shadow = new SolidBrush(pa.Colors.ItemExpandedShadow))
g.FillRectangle(shadow, itemRect.Left + itemRect.Width - 2, itemRect.Top + 2, 2, itemRect.Height - 2); // TODO: ADD GRADIENT SHADOW
}
}
}
}
}
}

View File

@@ -0,0 +1,171 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for Office2003RibbonTabItemPainter.
/// </summary>
internal class Office2003RibbonTabItemPainter:Office2003ButtonItemPainter
{
/// <summary>
/// Paints state of the button, either hot, pressed or checked
/// </summary>
/// <param name="button"></param>
/// <param name="pa"></param>
/// <param name="image"></param>
public override void PaintButtonMouseOver(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
PaintButtonCheck(button,pa,image,r);
}
public override void PaintButtonBackground(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
bool isOnMenu = IsOnMenu(button, pa);
if(isOnMenu)
base.PaintButtonBackground(button,pa, image);
else
PaintButtonCheck(button,pa,image,button.DisplayRectangle);
}
public override void PaintButtonCheck(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
bool isOnMenu = IsOnMenu(button, pa);
if(isOnMenu)
{
base.PaintButtonCheck(button,pa,image,r);
return;
}
// TODO: Cleanup code here, tabs were drawn for every state that code is still left
if(!button.IsMouseOver && !button.Checked)
return;
Color topColor=pa.Colors.BarBackground2;
Color bottomColor=pa.Colors.BarBackground;
Color borderColor=pa.Colors.BarFloatingBorder;
int angle=pa.Colors.BarBackgroundGradientAngle;
if(button.IsMouseOver && !button.Checked)
{
topColor=pa.Colors.ItemHotBackground2;
bottomColor=pa.Colors.ItemHotBackground;
angle=pa.Colors.ItemHotBackgroundGradientAngle;
}
else if(button.Checked)
{
topColor=Color.White;//pa.Colors.BarBackground2;
bottomColor=pa.Colors.BarBackground; //pa.Colors.BarBackground;
//topColor=pa.Colors.ItemPressedBackground;
//bottomColor=pa.Colors.ItemPressedBackground2;
angle=pa.Colors.ItemPressedBackgroundGradientAngle;
}
Color lightColor=ControlPaint.LightLight(bottomColor);
Color darkColor=Color.FromArgb(100,ControlPaint.Dark(topColor));
int cornerDiameter=4;
Graphics g=pa.Graphics;
GraphicsPath path=GetTabPath(r,cornerDiameter);
path.CloseAllFigures();
// Background
using(LinearGradientBrush brush=DisplayHelp.CreateLinearGradientBrush(r,topColor,bottomColor,angle))
{
brush.GammaCorrection=true;
g.FillPath(brush,path);
}
path.Dispose();
// Border light
using(path=GetTabPathLight(r,cornerDiameter-1))
{
using(Pen pen=new Pen(darkColor/*lightColor*/,1))
g.DrawPath(pen,path);
}
// Border dark
using(path=GetTabPathDark(r,cornerDiameter-1))
{
using(Pen pen=new Pen(darkColor,1))
g.DrawPath(pen,path);
}
// Border
using(path=GetTabPath(r,cornerDiameter))
{
using(Pen pen=new Pen(borderColor,1))
g.DrawPath(pen,path);
}
}
private GraphicsPath GetTabPathLight(Rectangle r, int cornerDiameter)
{
r.X++;
r.Y++;
r.Width-=2;
r.Height--;
// Get graphics path for the tab bounds
GraphicsPath path=new GraphicsPath();
path.AddLine(r.X,r.Bottom,r.X,r.Y+cornerDiameter);
ArcData ad=ElementStyleDisplay.GetCornerArc(r,cornerDiameter,eCornerArc.TopLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
//path.AddLine(r.X,r.Y+cornerDiameter,r.X+cornerDiameter,r.Y);
path.AddLine(r.X+cornerDiameter,r.Y,r.Right-cornerDiameter,r.Y);
return path;
}
private GraphicsPath GetTabPathDark(Rectangle r, int cornerDiameter)
{
r.X++;
r.Y++;
r.Width-=3;
r.Height--;
// Get graphics path for the tab bounds
GraphicsPath path=new GraphicsPath();
ArcData ad=ElementStyleDisplay.GetCornerArc(r,cornerDiameter,eCornerArc.TopRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
//path.AddLine(r.Right-cornerDiameter,r.Y,r.Right,r.Y+cornerDiameter);
path.AddLine(r.Right,r.Y+cornerDiameter,r.Right,r.Bottom);
return path;
}
private GraphicsPath GetTabPath(Rectangle r, int cornerDiameter)
{
r.Width--;
//r.Height--;
// Get graphics path for the tab bounds
GraphicsPath path=new GraphicsPath();
path.AddLine(r.X,r.Bottom,r.X,r.Y+cornerDiameter);
//path.AddLine(r.X,r.Y+cornerDiameter,r.X+cornerDiameter,r.Y);
ArcData ad=ElementStyleDisplay.GetCornerArc(r,cornerDiameter,eCornerArc.TopLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(r.X+cornerDiameter,r.Y,r.Right-cornerDiameter,r.Y);
//path.AddLine(r.Right-cornerDiameter,r.Y,r.Right,r.Y+cornerDiameter);
ad=ElementStyleDisplay.GetCornerArc(r,cornerDiameter,eCornerArc.TopRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(r.Right,r.Y+cornerDiameter,r.Right,r.Bottom);
return path;
}
public override void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image)
{
base.PaintButtonText(button,pa,textColor,image);
}
}
}

View File

@@ -0,0 +1,269 @@
using System;
using System.Text;
using System.Drawing;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
internal class Office2007BarBackgroundPainter : BarBackgroundPainter, IOffice2007Painter
{
#region Private Variables
private float m_TopSplit = .4f;
#endregion
#region IOffice2007Painter
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
#region Docked Background
/// <summary>
/// Paints background of docked bar.
/// </summary>
/// <param name="e">Context information</param>
public override void PaintDockedBackground(ToolbarRendererEventArgs e)
{
Graphics g = e.Graphics;
Bar bar = e.Bar;
ItemPaintArgs pa = e.ItemPaintArgs;
Rectangle r = e.Bounds;
Rectangle backgroundBounds = r;
backgroundBounds.Inflate(1, 1);
ColorScheme cs = m_ColorTable.LegacyColors;
if (bar.LayoutType == eLayoutType.DockContainer || bar.LayoutType == eLayoutType.TaskList)
{
if(bar.HasFocus)
DisplayHelp.FillRectangle(g, backgroundBounds, cs.BarBackground, cs.BarBackground2, cs.BarBackgroundGradientAngle);
else
DisplayHelp.FillRectangle(g, backgroundBounds, cs.BarCaptionInactiveBackground, cs.BarCaptionInactiveBackground2, cs.BarCaptionInactiveBackgroundGAngle);
}
else if (bar.MenuBar)
{
DisplayHelp.FillRectangle(g, backgroundBounds, cs.MenuBarBackground, cs.MenuBarBackground2, cs.MenuBarBackgroundGradientAngle);
}
else if (bar.GrabHandleStyle != eGrabHandleStyle.ResizeHandle && bar.BarType != eBarType.StatusBar)
{
// Docked state
if (bar.ItemsContainer.m_BackgroundColor.IsEmpty && bar.BackColor != Color.Transparent)
{
if (bar.IsThemed)
{
Rectangle rb = new Rectangle(-bar.Location.X, -bar.Location.Y, bar.Parent.Width, bar.Parent.Height);
ThemeRebar theme = ((IThemeCache)bar).ThemeRebar;
theme.DrawBackground(g, ThemeRebarParts.Background, ThemeRebarStates.Normal, rb);
}
else
{
if (IsGradientBackground(bar))
DisplayHelp.FillRectangle(g, backgroundBounds, cs.BarBackground, cs.BarBackground2, cs.BarBackgroundGradientAngle, new float[] { 0, .12f, 1f }, new float[] { 0, .50f, 1f });
else
DisplayHelp.FillRectangle(g, backgroundBounds, cs.BarBackground);
}
}
else if (!bar.ItemsContainer.BackColor.IsEmpty)
{
DisplayHelp.FillRectangle(g, backgroundBounds, bar.ItemsContainer.BackColor);
}
if (bar.Parent != null && bar.Parent.BackgroundImage != null && bar.Parent is DockSite)
{
Rectangle rb = new Rectangle(-bar.Location.X, -bar.Location.Y, bar.Parent.Width, bar.Parent.Height);
DockSite site = bar.Parent as DockSite;
BarFunctions.PaintBackgroundImage(g, rb, site.BackgroundImage, site.BackgroundImagePosition, site.BackgroundImageAlpha);
}
else if(bar.BackgroundImage!=null)
BarFunctions.PaintBackgroundImage(g, r, bar.BackgroundImage, bar.BackgroundImagePosition, bar.BackgroundImageAlpha);
if (!bar.IsThemed && bar.LayoutType == eLayoutType.Toolbar && bar.BackColor != Color.Transparent && pa!=null)
{
using (Pen p = new Pen(pa.Colors.BarDockedBorder, 1))
{
g.DrawLine(p, 0, bar.Height - 1, bar.Width, bar.Height - 1);
}
}
else
{
Rectangle border = r; // bar.ClientRectangle;
border.Inflate(-2, -2);
BarFunctions.DrawBorder(g, bar.DockedBorderStyle, border, bar.SingleLineColor);
}
}
else
{
if (!bar.BackColor.IsEmpty && bar.ShouldSerializeBackColor())
{
DisplayHelp.FillRectangle(g, r, bar.BackColor);
}
else
{
Office2007BarColorTable colorTable = m_ColorTable.Bar;
Rectangle back = r;
if(!pa.CachedPaint)
back.Inflate(1, 1);
if (colorTable.ToolbarBottomBackground == null || colorTable.ToolbarBottomBackground.IsEmpty)
{
DisplayHelp.FillRectangle(g, back, colorTable.ToolbarTopBackground);
}
else
{
// Fill top background part
back.Height = (int)(back.Height * m_TopSplit);
back.Height++;
DisplayHelp.FillRectangle(g, back, colorTable.ToolbarTopBackground);
back.Height--;
// Fill bottom background part
back.Y += back.Height;
back.Height = r.Height - back.Height + 1;
DisplayHelp.FillRectangle(g, back, colorTable.ToolbarBottomBackground);
}
if (bar.BarType == eBarType.StatusBar && bar.Items.Count > 0 && bar.Items[bar.Items.Count - 1] is ItemContainer && e.ItemPaintArgs != null && e.ItemPaintArgs.CachedPaint)
{
ItemContainer ic = bar.Items[bar.Items.Count - 1] as ItemContainer;
if (ic.Visible && ic.BackgroundStyle.Class == ElementStyleClassKeys.Office2007StatusBarBackground2Key)
{
Rectangle bounds = new Rectangle(ic.Bounds.X, r.Y, ic.Bounds.Width, e.Bar.Height + 1);
if (e.ItemPaintArgs.RightToLeft)
{
bounds.Width += bounds.X;
bounds.X = 0;
}
else
{
bounds.X += e.ItemPaintArgs.ContainerControl.Left;
bounds.Width += r.Right - bounds.Right;
}
ElementStyleDisplay.Paint(new ElementStyleDisplayInfo(ic.BackgroundStyle, g, bounds));
}
}
if (bar.Parent != null && bar.Parent.BackgroundImage != null && bar.Parent is DockSite)
{
Rectangle backImageRect = new Rectangle(-bar.Location.X, -bar.Location.Y, bar.Parent.Width, bar.Parent.Height);
DockSite site = bar.Parent as DockSite;
BarFunctions.PaintBackgroundImage(g, backImageRect, site.BackgroundImage, site.BackgroundImagePosition, site.BackgroundImageAlpha);
}
else if (bar.BackgroundImage != null)
BarFunctions.PaintBackgroundImage(g, bar.ClientRectangle, bar.BackgroundImage, bar.BackgroundImagePosition, bar.BackgroundImageAlpha);
if (!colorTable.ToolbarBottomBorder.IsEmpty && bar.BarType != eBarType.StatusBar ||
!colorTable.StatusBarTopBorder.IsEmpty && bar.BarType == eBarType.StatusBar)
{
if (bar.BarType == eBarType.StatusBar)
{
using (Pen pen = new Pen(colorTable.StatusBarTopBorder, 1))
g.DrawLine(pen, r.X, r.Y, r.Right, r.Y);
if (!colorTable.StatusBarTopBorderLight.IsEmpty)
{
using (Pen pen = new Pen(colorTable.StatusBarTopBorderLight, 1))
g.DrawLine(pen, r.X, r.Y + 1, r.Right, r.Y + 1);
}
}
else
{
using (Pen pen = new Pen(colorTable.ToolbarBottomBorder, 1))
g.DrawLine(pen, r.X, r.Bottom - 1, r.Right, r.Bottom - 1);
}
}
}
}
if (pa != null && !pa.CachedPaint)
bar.PaintGrabHandle(pa);
}
private bool IsGradientBackground(Bar bar)
{
if (bar.Style == eDotNetBarStyle.VS2005 && bar.LayoutType == eLayoutType.DockContainer)
return false;
return true;
}
#endregion
#region Floating Background
/// <summary>
/// Paints background of floating bar.
/// </summary>
/// <param name="e">Context information</param>
public override void PaintFloatingBackground(ToolbarRendererEventArgs e)
{
Graphics g = e.Graphics;
Bar bar = e.Bar;
ItemPaintArgs pa = e.ItemPaintArgs;
Rectangle r = e.Bounds;
ColorScheme cs = m_ColorTable.LegacyColors;
DisplayHelp.FillRectangle(g, r, cs.BarBackground, cs.BarBackground2, cs.BarBackgroundGradientAngle, new float[] { 0, .12f, 1f }, new float[] { 0, .50f, 1f });
//Office2007BarColorTable colorTable = m_ColorTable.Bar;
//Rectangle back = r;
//// Fill top background part
//back.Height = (int)(back.Height * m_TopSplit);
//DisplayHelp.FillRectangle(g, back, colorTable.ToolbarTopBackground);
//// Fill bottom background part
//back.Y += back.Height;
//back.Height = r.Height - back.Height;
//DisplayHelp.FillRectangle(g, back, colorTable.ToolbarBottomBackground);
if (bar.BackgroundImage != null)
BarFunctions.PaintBackgroundImage(g, bar.ClientRectangle, bar.BackgroundImage, bar.BackgroundImagePosition, bar.BackgroundImageAlpha);
}
#endregion
#region Popup Background
/// <summary>
/// Paints background of popup bar.
/// </summary>
/// <param name="e">Context information</param>
public override void PaintPopupBackground(ToolbarRendererEventArgs e)
{
Graphics g = e.Graphics;
Bar bar = e.Bar;
ItemPaintArgs pa = e.ItemPaintArgs;
Office2007BarColorTable colorTable = m_ColorTable.Bar;
int cornerSize = bar.CornerSize;
Rectangle r = e.Bounds;
DisplayHelp.FillRectangle(g, r, colorTable.PopupToolbarBackground.Start, colorTable.PopupToolbarBackground.End, colorTable.PopupToolbarBackground.GradientAngle);
if (bar.BackgroundImage != null)
BarFunctions.PaintBackgroundImage(g, bar.ClientRectangle, bar.BackgroundImage, bar.BackgroundImagePosition, bar.BackgroundImageAlpha);
bar.PaintSideBar(g);
Rectangle borderRectangle = r;
if (bar.DisplayShadow && !bar.AlphaShadow)
borderRectangle = new Rectangle(0, 0, bar.ClientSize.Width - 2, bar.ClientSize.Height - 2);
using (Pen p = new Pen(colorTable.PopupToolbarBorder, 1))
DisplayHelp.DrawRoundedRectangle(g, p, borderRectangle, cornerSize);
if (bar.DisplayShadow && !bar.AlphaShadow)
{
// Shadow
Point[] pt = new Point[3];
pt[0].X = 2;
pt[0].Y = r.Height - 1;
pt[1].X = r.Width - 1;
pt[1].Y = r.Height - 1;
pt[2].X = r.Width - 1;
pt[2].Y = 2;
using (Pen p = new Pen(SystemColors.ControlDark, 2))
g.DrawLines(p, pt);
}
}
#endregion
}
}

View File

@@ -0,0 +1,968 @@
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using System;
namespace DevComponents.DotNetBar
{
internal class Office2007ButtonItemPainter : Office2003ButtonItemPainter, IOffice2007Painter
{
#region Private Variables
private int m_CornerSize = 2;
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
private static RoundRectangleShapeDescriptor _DefaultOffice2007Shape = new RoundRectangleShapeDescriptor(2);
private static RoundRectangleShapeDescriptor _DefaultOffice2007LeftShape = new RoundRectangleShapeDescriptor(2, 0, 2, 0);
private static RoundRectangleShapeDescriptor _DefaultOffice2007RightShape = new RoundRectangleShapeDescriptor(0, 2, 0, 2);
private static RoundRectangleShapeDescriptor _DefaultOffice2007TopShape = new RoundRectangleShapeDescriptor(2, 2, 0, 0);
private static RoundRectangleShapeDescriptor _DefaultOffice2007BottomShape = new RoundRectangleShapeDescriptor(0, 0, 2, 2);
private static RoundRectangleShapeDescriptor _DefaultMetroShape = new RoundRectangleShapeDescriptor(0);
#endregion
#region Implementation
private bool IsOffice2003Rendering(ButtonItem button, ItemPaintArgs pa)
{
if (button.ColorTable == eButtonColor.Flat || pa.Owner is DotNetBarManager && string.IsNullOrEmpty(button.CustomColorName))
return true;
return false;
}
/// <summary>
/// Paints state of the button, either hot, pressed or checked
/// </summary>
/// <param name="button"></param>
/// <param name="pa"></param>
/// <param name="image"></param>
public override void PaintButtonMouseOver(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintButtonMouseOver(button, pa, image, r);
return;
}
//PaintState(button, pa, image, r, button.IsMouseDown);
}
public override void PaintButtonCheck(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintButtonCheck(button, pa, image, r);
return;
}
bool isOnMenu = IsOnMenu(button, pa);
if (isOnMenu)
base.PaintButtonCheck(button, pa, image, r);
//else
// PaintState(button, pa, image, r, button.IsMouseDown);
}
protected virtual IShapeDescriptor GetButtonShape(ButtonItem button, ItemPaintArgs pa)
{
IShapeDescriptor shape = Office2007ButtonItemPainter.GetButtonShape(button);
if (pa.ContainerControl is ButtonX)
shape = ((ButtonX)pa.ContainerControl).GetButtonShape();
else if (pa.ContainerControl is NavigationBar)
shape = ((NavigationBar)pa.ContainerControl).ButtonShape;
return shape;
}
protected virtual void PaintState(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r, bool isMouseDown)
{
if (r.IsEmpty)
return;
bool isOnMenu = pa.IsOnMenu;
Office2007ColorTable colorTable = this.ColorTable;
Graphics g = pa.Graphics;
IShapeDescriptor shape = GetButtonShape(button, pa);
eButtonContainer buttonCont = GetButtonContainerQualifier(pa, button);
Office2007ButtonItemColorTable buttonColorTable = GetColorTable(button, buttonCont);
Region oldClip = g.Clip;
try
{
g.SetClip(r, CombineMode.Intersect);
Office2007ButtonItemStateColorTable stateColors = buttonColorTable.Default;
if (IsOnMenu(button, pa))
{
Rectangle sideRect = new Rectangle(button.DisplayRectangle.Left, button.DisplayRectangle.Top, button.ImageDrawRect.Right, button.DisplayRectangle.Height);
if (pa.RightToLeft)
sideRect = new Rectangle(button.DisplayRectangle.Right - button.ImageDrawRect.Width, button.DisplayRectangle.Top, button.ImageDrawRect.Width, button.DisplayRectangle.Height);
PaintMenuItemSide(button, pa, sideRect);
}
if (!IsItemEnabled(button, pa))
{
if (!isOnMenu)
PaintStateBackground(button, g, buttonColorTable.Disabled, r, shape, pa.IsDefaultButton, true);
g.Clip = oldClip;
return;
}
bool mouseOver = false;
bool expanded = false;
if (!button.DesignMode)
{
if (button.IsMouseOver && button.HotTrackingStyle != eHotTrackingStyle.Image && button.HotTrackingStyle != eHotTrackingStyle.None)
{
stateColors = buttonColorTable.MouseOver;
mouseOver = true;
}
if (isMouseDown && button.HotTrackingStyle != eHotTrackingStyle.Image && button.HotTrackingStyle != eHotTrackingStyle.None)
{
if (buttonColorTable.Pressed != null)
stateColors = buttonColorTable.Pressed;
}
else if (button.Checked && !button.IsMouseOver && !IsOnMenu(button, pa))
{
stateColors = buttonColorTable.Checked;
}
else if (button.Expanded && button.HotTrackingStyle != eHotTrackingStyle.Image && !(!mouseOver && pa.IsOnMenu))
{
stateColors = buttonColorTable.Expanded;
expanded = true;
}
}
else
{
if (button.Checked && !IsOnMenu(button, pa))
{
stateColors = buttonColorTable.Checked;
}
else if (button.Expanded && button.HotTrackingStyle != eHotTrackingStyle.Image)
{
stateColors = buttonColorTable.Expanded;
expanded = true;
}
}
Rectangle subRect = GetTotalSubItemsRect(button);
bool isSplitButton = (mouseOver || expanded) && !button.AutoExpandOnClick && !subRect.IsEmpty && !IsOnMenu(button, pa);
eDotNetBarStyle effectiveStyle = button.EffectiveStyle;
subRect.Offset(button.DisplayRectangle.Location);
if (isSplitButton && !button.Checked &&
(effectiveStyle == eDotNetBarStyle.Office2010 || effectiveStyle == eDotNetBarStyle.Windows7 || StyleManager.IsMetro(effectiveStyle)))
{
Rectangle[] rects = DisplayHelp.ExcludeRectangle(r, subRect);
if (rects.Length > 0 && (button.IsMouseOverExpand || button.Expanded))
rects = DisplayHelp.ExcludeRectangle(r, rects[0]);
if (rects.Length > 0)
{
PaintStateBackground(button, g, buttonColorTable.MouseOverSplitInactive, r, shape, pa.IsDefaultButton, !pa.IsOnNavigationBar);
if (rects[0].X == r.X && rects[0].Right < r.Right) // Left aligned
shape = (StyleManager.IsMetro(effectiveStyle)) ? _DefaultMetroShape : _DefaultOffice2007LeftShape;
else if (rects[0].X > r.X && rects[0].Right == r.Right) // Right aligned
shape = (StyleManager.IsMetro(effectiveStyle)) ? _DefaultMetroShape : _DefaultOffice2007RightShape;
else if (rects[0].Y == r.Y && rects[0].Bottom < r.Bottom) // Top aligned
shape = (StyleManager.IsMetro(effectiveStyle)) ? _DefaultMetroShape : _DefaultOffice2007TopShape;
else if (rects[0].Y > r.Y && rects[0].Bottom == r.Bottom) // Bottom aligned
shape = (StyleManager.IsMetro(effectiveStyle)) ? _DefaultMetroShape : _DefaultOffice2007BottomShape;
PaintStateBackground(button, g, stateColors, rects[0], shape, pa.IsDefaultButton, !pa.IsOnNavigationBar);
}
else
PaintStateBackground(button, g, stateColors, r, shape, pa.IsDefaultButton, !pa.IsOnNavigationBar);
}
else
PaintStateBackground(button, g, stateColors, r, shape, pa.IsDefaultButton, !pa.IsOnNavigationBar);
if (isSplitButton && !(effectiveStyle == eDotNetBarStyle.Office2010 || effectiveStyle == eDotNetBarStyle.Windows7 || StyleManager.IsMetro(effectiveStyle)))
{
using (Brush brush = GetOverlayInactiveBrush())
{
Rectangle backRect = button.DisplayRectangle;
backRect.Inflate(-1, -1);
if (!button.IsMouseOverExpand && !expanded)
{
subRect.Inflate(-1, -1);
g.SetClip(subRect, CombineMode.Intersect);
GraphicsPath backPath = shape.GetShape(backRect);
if (backPath != null)
{
g.FillPath(brush, backPath);
backPath.Dispose();
}
}
else if (!mouseOver || button.IsMouseOverExpand)
{
g.SetClip(subRect, CombineMode.Exclude);
GraphicsPath backPath = shape.GetShape(backRect);
if (backPath != null)
{
g.FillPath(brush, backPath);
backPath.Dispose();
}
}
}
}
g.Clip = oldClip;
}
finally
{
if (oldClip != null) oldClip.Dispose();
}
}
protected virtual void PaintStateBackground(ButtonItem button, Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
{
PaintBackground(g, stateColors, r, shape, isDefault, paintBorder);
}
public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape)
{
PaintBackground(g, stateColors, r, shape, false);
}
public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault)
{
PaintBackground(g, stateColors, r, shape, isDefault, true);
}
public static void PaintBackground(Graphics g, Office2007ButtonItemStateColorTable stateColors, Rectangle r, IShapeDescriptor shape, bool isDefault, bool paintBorder)
{
float topSplit = .35f;
float bottomSplit = .65f;
if (!shape.CanDrawShape(r)) return;
if (stateColors != null)
{
Rectangle fillRectangle = r;
Rectangle backRect = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, (int)(fillRectangle.Height * topSplit));
if (!stateColors.OuterBorder.IsEmpty && paintBorder)
fillRectangle.Width--;
GraphicsPath backPath = shape.GetShape(fillRectangle);
if (stateColors.Background != null)
{
if (backPath != null)
{
if (stateColors.Background.End.IsEmpty)
{
using (SolidBrush brush = new SolidBrush(stateColors.Background.Start))
g.FillPath(brush, backPath);
}
else
{
using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.Background.Start, stateColors.Background.End, stateColors.Background.GradientAngle))
{
g.FillPath(lb, backPath);
}
}
backPath.Dispose();
}
}
else
{
if (backPath != null && stateColors.TopBackground!= null && stateColors.BottomBackground!=null)
{
if (stateColors.TopBackground.End.IsEmpty && stateColors.BottomBackground.End.IsEmpty)
{
if (stateColors.TopBackground.Start == stateColors.BottomBackground.Start)
using (SolidBrush lb = new SolidBrush(stateColors.TopBackground.Start))
g.FillPath(lb, backPath);
else
{
using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.Start, stateColors.TopBackground.GradientAngle))
{
g.FillPath(lb, backPath);
}
}
}
else
{
using (LinearGradientBrush lb = new LinearGradientBrush(fillRectangle, stateColors.TopBackground.Start, stateColors.BottomBackground.End, stateColors.TopBackground.GradientAngle))
{
ColorBlend cb = new ColorBlend(4);
cb.Colors = new Color[] { stateColors.TopBackground.Start, stateColors.TopBackground.End, stateColors.BottomBackground.Start, stateColors.BottomBackground.End };
cb.Positions = new float[] { 0, topSplit, topSplit, 1f };
lb.InterpolationColors = cb;
g.FillPath(lb, backPath);
}
}
backPath.Dispose();
}
if (stateColors.TopBackgroundHighlight!=null && !stateColors.TopBackgroundHighlight.IsEmpty)
{
Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y, fillRectangle.Width, fillRectangle.Height);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(ellipse);
PathGradientBrush brush = new PathGradientBrush(path);
brush.CenterColor = stateColors.TopBackgroundHighlight.Start;
brush.SurroundColors = new Color[] { stateColors.TopBackgroundHighlight.End };
brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
Blend blend = new Blend();
blend.Factors = new float[] { 0f, .5f, 1f };
blend.Positions = new float[] { .0f, .4f, 1f };
brush.Blend = blend;
g.FillRectangle(brush, backRect);
brush.Dispose();
path.Dispose();
}
// Draw Bottom part
int bottomHeight = (int)(fillRectangle.Height * bottomSplit);
backRect = new Rectangle(fillRectangle.X, fillRectangle.Y + backRect.Height, fillRectangle.Width, fillRectangle.Height - backRect.Height);
if (stateColors.BottomBackgroundHighlight!=null && !stateColors.BottomBackgroundHighlight.IsEmpty)
{
Rectangle ellipse = new Rectangle(fillRectangle.X, fillRectangle.Y + bottomHeight - 2, fillRectangle.Width, fillRectangle.Height + 4);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(ellipse);
PathGradientBrush brush = new PathGradientBrush(path);
brush.CenterColor = stateColors.BottomBackgroundHighlight.Start;
brush.SurroundColors = new Color[] { stateColors.BottomBackgroundHighlight.End };
brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom);
Blend blend = new Blend();
blend.Factors = new float[] { 0f, .5f, .6f };
blend.Positions = new float[] { .0f, .4f, 1f };
brush.Blend = blend;
g.FillRectangle(brush, backRect);
brush.Dispose();
path.Dispose();
}
}
if (paintBorder)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.AntiAlias;
// Draw Border
if (!stateColors.OuterBorder.IsEmpty && stateColors.OuterBorderWidth>0)
{
Rectangle br = r;
br.Width--;
br.Height--;
if (shape is EllipticalShapeDescriptor && stateColors.OuterBorder.End.IsEmpty)
{
br.Width -= (stateColors.OuterBorderWidth / 2);
br.Height -= (stateColors.OuterBorderWidth / 2);
using (Pen pen = new Pen(stateColors.OuterBorder.Start, stateColors.OuterBorderWidth))
g.DrawEllipse(pen, br);
}
else
{
GraphicsPath path = shape.GetShape(br);
if (path != null)
{
DisplayHelp.DrawGradientPath(g, path, r, stateColors.OuterBorder, stateColors.OuterBorderWidth);
path.Dispose();
}
}
//if (cornerSize > 1)
// DisplayHelp.DrawRoundGradientRectangle(g, r, stateColors.OuterBorder, 1, cornerSize);
//else
// DisplayHelp.DrawGradientRectangle(g, r, stateColors.OuterBorder, 1);
if (isDefault)
{
Color clr = Color.FromArgb(128, stateColors.OuterBorder.Start);
r.Inflate(-1, -1);
DisplayHelp.DrawRectangle(g, clr, r);
r.Inflate(-1, -1);
DisplayHelp.DrawRectangle(g, clr, r);
}
}
if (!isDefault && !stateColors.InnerBorder.IsEmpty)
{
Rectangle innerRect = r;
innerRect.Inflate(-1, -1);
innerRect.Width--;
innerRect.Height--;
using (GraphicsPath path = shape.GetInnerShape(innerRect, 1))
DisplayHelp.DrawGradientPath(g, path, innerRect, stateColors.InnerBorder, 1);
//cornerSize--;
//if (cornerSize > 1)
// DisplayHelp.DrawRoundGradientRectangle(g, innerRect, stateColors.InnerBorder, 1, cornerSize);
//else
// DisplayHelp.DrawGradientRectangle(g, innerRect, stateColors.InnerBorder, 1);
}
g.SmoothingMode = sm;
}
}
}
public override void PaintButtonBackground(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintButtonBackground(button, pa, image);
return;
}
if (button is ApplicationButton && m_ColorTable.RibbonControl.StartButtonDefault != null)
{
Image backImage = m_ColorTable.RibbonControl.StartButtonDefault;
if (button.IsMouseDown || button.Expanded)
backImage = m_ColorTable.RibbonControl.StartButtonPressed;
else if (button.IsMouseOver)
backImage = m_ColorTable.RibbonControl.StartButtonMouseOver;
if (backImage != null)
{
if (Office2007ColorTable.CloneImagesOnAccess)
backImage = backImage.Clone() as Image;
pa.Graphics.DrawImageUnscaled(backImage, new Point(button.LeftInternal + (button.WidthInternal - backImage.Width) / 2, button.TopInternal + (button.HeightInternal - backImage.Height) / 2));
if (Office2007ColorTable.CloneImagesOnAccess)
backImage.Dispose();
}
}
PaintState(button, pa, image, button.DisplayRectangle, button.IsMouseDown);
}
private Brush GetOverlayInactiveBrush()
{
return new SolidBrush(Color.FromArgb(76, Color.White));
}
private static IShapeDescriptor GetButtonShape(ButtonItem button)
{
if (button.Shape != null)
return button.Shape;
return _DefaultOffice2007Shape;
}
public override void PaintExpandButton(ButtonItem button, ItemPaintArgs pa)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintExpandButton(button, pa);
return;
}
Graphics g = pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
Rectangle itemRect = button.DisplayRectangle;
bool mouseOver = button.IsMouseOver;
bool enabled = IsItemEnabled(button, pa);
Color textColor = Color.Empty;
eButtonContainer buttonCont = GetButtonContainerQualifier(pa, button);
Office2007ButtonItemColorTable buttonColorTable = GetColorTable(button, buttonCont);
if (buttonCont == eButtonContainer.RibbonStrip)
{
textColor = GetTextColor(button, pa);
}
if (textColor.IsEmpty)
textColor = GetTextColor(button, pa, buttonColorTable, true);
using (SolidBrush textBrush = new SolidBrush(textColor))
{
// If it has subitems draw the triangle to indicate that
if ((button.SubItems.Count > 0 || button.PopupType == ePopupType.Container) && button.ShowSubItems)
{
if (isOnMenu)
{
Point[] p = new Point[3];
if (pa.RightToLeft)
{
p[0].X = itemRect.Left + 8;
p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 8;
p[2].X = p[0].X - 4;
p[2].Y = p[0].Y + 4;
}
else
{
p[0].X = itemRect.Left + itemRect.Width - 12;
p[0].Y = itemRect.Top + (itemRect.Height - 8) / 2;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 8;
p[2].X = p[0].X + 4;
p[2].Y = p[0].Y + 4;
}
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
g.FillPolygon(textBrush, p);
g.SmoothingMode = sm;
}
else if (!button.SubItemsRect.IsEmpty)
{
Point[] p = new Point[3];
Rectangle sr = button.SubItemsRect;
if (pa.IsOnRibbonBar && button.ImagePosition == eImagePosition.Top && !button.SplitButton && button.Text.Length > 0)
sr.Y -= 3;
if (button.PopupSide == ePopupSide.Default)
{
if (pa.IsOnMenu)
{
if (pa.RightToLeft)
{
p[0].X = itemRect.Left + sr.Left + sr.Width / 2 + 3;
p[0].Y = itemRect.Top + sr.Top + sr.Height / 2 - 3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 6;
p[2].X = p[0].X - 3;
p[2].Y = p[0].Y + 3;
}
else
{
p[0].X = itemRect.Left + sr.Left + sr.Width / 2;
p[0].Y = itemRect.Top + sr.Top + sr.Height / 2 - 3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 6;
p[2].X = p[0].X + 3;
p[2].Y = p[0].Y + 3;
}
}
else if (button.Orientation == eOrientation.Horizontal)
{
p[0].X = itemRect.Left + sr.Left + (sr.Width - Dpi.Width5) / 2;
p[0].Y = itemRect.Top + sr.Top + (sr.Height - Dpi.Height3) / 2 + 1;
p[1].X = p[0].X + Dpi.Width5;
p[1].Y = p[0].Y;
p[2].X = p[0].X + Dpi.Width2;
p[2].Y = p[0].Y + Dpi.Height3;
}
else
{
p[0].X = itemRect.Left + sr.Left + (sr.Width - 3) / 2 + 1;
p[0].Y = itemRect.Top + sr.Top + (sr.Height - 5) / 2;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 6;
p[2].X = p[0].X - 3;
p[2].Y = p[0].Y + 3;
}
}
else
{
switch (button.PopupSide)
{
case ePopupSide.Right:
{
p[0].X = itemRect.Left + sr.Left + sr.Width / 2;
p[0].Y = itemRect.Top + sr.Top + sr.Height / 2 - 3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 6;
p[2].X = p[0].X + 3;
p[2].Y = p[0].Y + 3;
break;
}
case ePopupSide.Left:
{
p[0].X = itemRect.Left + sr.Left + sr.Width / 2 + 3;
p[0].Y = itemRect.Top + sr.Top + sr.Height / 2 - 3;
p[1].X = p[0].X;
p[1].Y = p[0].Y + 6;
p[2].X = p[0].X - 3;
p[2].Y = p[0].Y + 3;
break;
}
case ePopupSide.Top:
{
p[0].X = itemRect.Left + sr.Left + (sr.Width - 5) / 2;
p[0].Y = itemRect.Top + sr.Top + (sr.Height - 3) / 2 + 4;
p[1].X = p[0].X + 6;
p[1].Y = p[0].Y;
p[2].X = p[0].X + 3;
p[2].Y = p[0].Y - 4;
break;
}
case ePopupSide.Bottom:
{
p[0].X = itemRect.Left + sr.Left + (sr.Width - 5) / 2 + 1;
p[0].Y = itemRect.Top + sr.Top + (sr.Height - 3) / 2 + 1;
p[1].X = p[0].X + 5;
p[1].Y = p[0].Y;
p[2].X = p[0].X + 2;
p[2].Y = p[0].Y + 3;
break;
}
}
}
if (button.SplitButton && !button.TextDrawRect.IsEmpty && (button.ImagePosition == eImagePosition.Top))
{
p[0].Y -= 3;
p[1].Y -= 3;
p[2].Y -= 3;
}
if (enabled)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
g.FillPolygon(textBrush, p);
g.SmoothingMode = sm;
}
else
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
using (SolidBrush mybrush = new SolidBrush(pa.Colors.ItemDisabledText))
g.FillPolygon(mybrush, p);
g.SmoothingMode = sm;
}
}
Rectangle r = GetTotalSubItemsRect(button);
if (enabled && !r.IsEmpty && (mouseOver || button.Expanded && !pa.IsOnMenu) && !button.AutoExpandOnClick)
{
r.Offset(itemRect.Location);
Point[] pt = new Point[4];
if (pa.ContainerControl is RibbonBar && (button.ImagePosition == eImagePosition.Top || button.ImagePosition == eImagePosition.Bottom))
{
pt[0] = new Point(r.X + 1, r.Y);
pt[1] = new Point(r.Right - 2, r.Y);
pt[2] = new Point(r.X + 1, r.Y + 1);
pt[3] = new Point(r.Right - 2, r.Y + 1);
if (button.SplitButton)
{
pt[0].Y--;
pt[1].Y--;
pt[2].Y--;
pt[3].Y--;
}
}
else
{
r.Y += 1;
r.Height -= 3;
if (pa.RightToLeft)
r.X = r.Right - 1;
pt[0] = new Point(r.X, r.Y);
pt[1] = new Point(r.X, r.Bottom);
pt[2] = new Point(r.X + 1, r.Y);
pt[3] = new Point(r.X + 1, r.Bottom);
}
eDotNetBarStyle effectiveStyle = button.EffectiveStyle;
if (effectiveStyle != eDotNetBarStyle.Office2010 && effectiveStyle != eDotNetBarStyle.Windows7 && !StyleManager.IsMetro(effectiveStyle) || button.Checked)
{
using (Pen pen = new Pen(buttonColorTable.MouseOver.SplitBorder.Start))
g.DrawLine(pen, pt[0], pt[1]); //r.X, r.Y, r.X, r.Bottom);
using (Pen pen = new Pen(buttonColorTable.MouseOver.SplitBorderLight.Start))
g.DrawLine(pen, pt[2], pt[3]); //r.X + 1, r.Y, r.X + 1, r.Bottom);
}
}
}
}
}
protected override void PaintMenuItemSide(ButtonItem button, ItemPaintArgs pa, Rectangle sideRect)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintMenuItemSide(button, pa, sideRect);
return;
}
Graphics g = pa.Graphics;
Office2007MenuColorTable ct = m_ColorTable.Menu;
Region oldClip = g.Clip.Clone() as Region;
g.SetClip(sideRect);
sideRect.Inflate(0, 1);
// Draw side bar
if (button.MenuVisibility == eMenuVisibility.VisibleIfRecentlyUsed && !button.RecentlyUsed)
DisplayHelp.FillRectangle(g, sideRect, ct.SideUnused);
else
DisplayHelp.FillRectangle(g, sideRect, ct.Side);
if (pa.RightToLeft)
{
Point p = new Point(sideRect.X, sideRect.Y);
DisplayHelp.DrawGradientLine(g, p, new Point(p.X, p.Y + sideRect.Height), ct.SideBorder, 1);
p.X++;
DisplayHelp.DrawGradientLine(g, p, new Point(p.X, p.Y + sideRect.Height), ct.SideBorderLight, 1);
}
else
{
Point p = new Point(sideRect.Right - 2, sideRect.Y);
DisplayHelp.DrawGradientLine(g, p, new Point(p.X, p.Y + sideRect.Height), ct.SideBorder, 1);
p.X++;
DisplayHelp.DrawGradientLine(g, p, new Point(p.X, p.Y + sideRect.Height), ct.SideBorderLight, 1);
}
if (oldClip != null)
g.Clip = oldClip;
else
g.ResetClip();
}
protected override void PaintButtonCheckBackground(ButtonItem button, ItemPaintArgs pa, Rectangle r)
{
if (IsOffice2003Rendering(button, pa))
{
base.PaintButtonCheckBackground(button, pa, r);
return;
}
Graphics g = pa.Graphics;
bool isOnMenu = IsOnMenu(button, pa);
int cornerSize = m_CornerSize;
if (pa.ContainerControl is ButtonX)
cornerSize = ((ButtonX)pa.ContainerControl).CornerSize;
if (!button.IsMouseOver || isOnMenu)
{
Rectangle backRect = r;
backRect.Inflate(-1, -1);
DisplayHelp.FillRectangle(g, backRect, pa.Colors.ItemCheckedBackground, pa.Colors.ItemCheckedBackground2, pa.Colors.ItemCheckedBackgroundGradientAngle);
DisplayHelp.DrawRoundedRectangle(g, pa.Colors.ItemCheckedBorder, r, cornerSize);
}
}
protected static readonly Type ButtonColorTableType = typeof(Office2007ButtonItemColorTable);
public virtual Office2007ButtonItemColorTable GetColorTable(ButtonItem button, eButtonContainer buttonCont)
{
Office2007ColorTable colorTable = this.ColorTable;
Office2007ButtonItemColorTable buttonColorTable = null;
if (buttonCont == eButtonContainer.StatusBar)
{
object st = null;
if (colorTable.ContextualTables.TryGetValue(Office2007ColorTable.GetContextualKey(ButtonColorTableType, "StatusBar"), out st))
return (Office2007ButtonItemColorTable)st;
}
if (buttonCont == eButtonContainer.RibbonBar && colorTable.RibbonButtonItemColors.Count > 0)
{
if (button.CustomColorName != "")
buttonColorTable = colorTable.RibbonButtonItemColors[button.CustomColorName];
if (buttonColorTable == null)
buttonColorTable = colorTable.RibbonButtonItemColors[button.GetColorTableName()];
if (buttonColorTable != null)
return buttonColorTable;
}
else if ((buttonCont == eButtonContainer.MenuBar || buttonCont == eButtonContainer.StatusBar) && colorTable.MenuButtonItemColors.Count > 0)
{
if (button.CustomColorName != "")
buttonColorTable = colorTable.MenuButtonItemColors[button.CustomColorName];
if (buttonColorTable == null)
buttonColorTable = colorTable.MenuButtonItemColors[button.GetColorTableName()];
if (buttonColorTable != null)
return buttonColorTable;
}
else if (buttonCont == eButtonContainer.Backstage && colorTable.BackstageButtonItemColors.Count > 0)
{
if (button.CustomColorName != "")
buttonColorTable = colorTable.BackstageButtonItemColors[button.CustomColorName];
if (buttonColorTable == null)
buttonColorTable = colorTable.BackstageButtonItemColors[button.GetColorTableName()];
if (buttonColorTable != null)
return buttonColorTable;
}
else if (buttonCont == eButtonContainer.NavigationPane && colorTable.NavigationPaneButtonItemColors.Count > 0)
{
if (button.CustomColorName != "")
buttonColorTable = colorTable.NavigationPaneButtonItemColors[button.CustomColorName];
if (buttonColorTable == null)
buttonColorTable = colorTable.NavigationPaneButtonItemColors[button.GetColorTableName()];
if (buttonColorTable != null)
return buttonColorTable;
}
if (button.CustomColorName != "")
buttonColorTable = colorTable.ButtonItemColors[button.CustomColorName];
try
{
if (buttonColorTable == null)
buttonColorTable = colorTable.ButtonItemColors[button.GetColorTableName()];
if (buttonColorTable == null)
return colorTable.ButtonItemColors[0];
}
catch
{
buttonColorTable = Office2007ColorTable.GetFallBackButtonItemColorTable();
}
return buttonColorTable;
}
private eButtonContainer GetButtonContainerQualifier(ItemPaintArgs pa, ButtonItem button)
{
eButtonContainer buttonCont = eButtonContainer.None;
if (pa.ContainerControl is RibbonBar)
buttonCont = eButtonContainer.RibbonBar;
else if (pa.ContainerControl is RibbonStrip)
buttonCont = eButtonContainer.RibbonStrip;
else if (pa.ContainerControl is DevComponents.DotNetBar.Metro.MetroTabStrip)
buttonCont = eButtonContainer.MetroTabStrip;
else if (pa.ContainerControl is Bar)
{
Bar bar = pa.ContainerControl as Bar;
if (bar.MenuBar)
buttonCont = eButtonContainer.MenuBar;
else if (bar.LayoutType == eLayoutType.Toolbar)
{
if (bar.BarType == eBarType.StatusBar || bar.GrabHandleStyle == eGrabHandleStyle.ResizeHandle || bar.Dock == DockStyle.Bottom || bar.DockSide == eDockSide.Bottom)
buttonCont = eButtonContainer.StatusBar;
else
buttonCont = eButtonContainer.Toolbar;
}
}
else if (pa.IsOnMenu || pa.IsOnPopupBar)
buttonCont = eButtonContainer.Popup;
else if (pa.ContainerControl is SuperTabStrip && ((SuperTabStrip)pa.ContainerControl).ApplicationButton != null)
buttonCont = eButtonContainer.Backstage;
else if (pa.ContainerControl is NavigationBar)
buttonCont = eButtonContainer.NavigationPane;
return buttonCont;
}
protected virtual Color GetTextColor(ButtonItem button, ItemPaintArgs pa, Office2007ButtonItemColorTable buttonColorTable)
{
return GetTextColor(button, pa, buttonColorTable, false);
}
protected virtual Color GetTextColor(ButtonItem button, ItemPaintArgs pa, Office2007ButtonItemColorTable buttonColorTable, bool isExpandPart)
{
Color textColor = Color.Empty;
bool isMouseOver = button.IsMouseOver;
if (isMouseOver)
{
if (isExpandPart)
{
if (!button.IsMouseOverExpand)
isMouseOver = false;
}
else if (button.IsMouseOverExpand && button.SplitButton && !button.AutoExpandOnClick)
isMouseOver = false;
else if (button.IsMouseOverExpand && !isExpandPart && !button.AutoExpandOnClick)
isMouseOver = false;
}
if (isMouseOver)
{
if (!button.HotForeColor.IsEmpty)
textColor = button.HotForeColor;
}
else if (!button.ForeColor.IsEmpty)
textColor = button.ForeColor;
if (textColor.IsEmpty)
{
if (buttonColorTable != null)
{
if (!button.GetEnabled(pa.ContainerControl))
{
if (buttonColorTable.Disabled != null)
textColor = buttonColorTable.Disabled.Text;
}
else if (button.IsMouseDown)
textColor = buttonColorTable.Pressed.Text;
else if (isMouseOver && !(StyleManager.IsMetro(button.EffectiveStyle) && button.Expanded))
textColor = buttonColorTable.MouseOver.Text;
else if (button.Expanded && (button.AutoExpandOnClick && !button.SplitButton))
textColor = buttonColorTable.Expanded.Text;
else if (button.Checked && !IsOnMenu(button, pa))
textColor = buttonColorTable.Checked.Text;
else
textColor = buttonColorTable.Default.Text;
}
}
if (textColor.IsEmpty)
return base.GetTextColor(button, pa);
return textColor;
}
protected override Color GetTextColor(ButtonItem button, ItemPaintArgs pa)
{
bool enabled = IsItemEnabled(button, pa);
if (enabled && button.IsMouseOver && !button.HotForeColor.IsEmpty)
return button.HotForeColor;
if (enabled && !button.ForeColor.IsEmpty)
return button.ForeColor;
if (enabled && button.ForeColorColorSchemePart != eColorSchemePart.None)
return (Color)pa.Colors.GetType().GetProperty(button.ForeColorColorSchemePart.ToString()).GetValue(pa.Colors, null);
eButtonContainer buttonCont = GetButtonContainerQualifier(pa, button);
if (!enabled || IsOffice2003Rendering(button, pa))
{
if (enabled && buttonCont == eButtonContainer.MenuBar && !button.IsMouseDown && !button.IsMouseOver && !button.Expanded && !button.Checked)
{
Office2007ButtonItemColorTable bt = GetColorTable(button, buttonCont);
return bt.Default.Text;
}
return base.GetTextColor(button, pa);
}
Color textColor = Color.Empty;
if (buttonCont == eButtonContainer.RibbonStrip && !button.IsMouseOver && !button.IsMouseDown && !button.Expanded)
{
Office2007RibbonTabItemColorTable rtc = Office2007RibbonTabItemPainter.GetColorTable(m_ColorTable);
if (pa.GlassEnabled && !rtc.Default.GlassText.IsEmpty)
return rtc.Default.GlassText;
return rtc.Default.Text;
}
Office2007ButtonItemColorTable buttonColorTable = GetColorTable(button, buttonCont);
textColor = GetTextColor(button, pa, buttonColorTable);
return textColor;
}
#endregion
#region IOffice2007Painter Members
public Office2007ColorTable ColorTable
{
get
{
return m_ColorTable;
}
set
{
m_ColorTable = value;
}
}
#endregion
}
internal enum eButtonContainer
{
None,
RibbonBar,
Popup,
RibbonStrip,
MenuBar,
StatusBar,
Toolbar,
Backstage,
NavigationPane,
MetroTabStrip
}
}

View File

@@ -0,0 +1,121 @@
using System;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
internal class Office2007DialogLauncherPainter : DialogLauncherPainter, IOffice2007Painter
{
#region IOffice2007Painter
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
#region Dialog Launcher Painter
public override void PaintDialogLauncher(RibbonBarRendererEventArgs e)
{
Rectangle r = e.Bounds;
Graphics g = e.Graphics;
bool rightToLeft = (e.RibbonBar.RightToLeft == System.Windows.Forms.RightToLeft.Yes);
Office2007DialogLauncherStateColorTable c = GetColorTable(e);
if (!c.TopBackground.IsEmpty && !c.BottomBackground.IsEmpty)
{
Presentation.Rectangle pr = new Presentation.Rectangle(
new Presentation.ShapeBorder(c.OuterBorder), new Presentation.ShapeFill(c.TopBackground));
pr.Padding = new Presentation.PaddingInfo(1, 1, 1, 1);
Presentation.Rectangle prb = new Presentation.Rectangle(new Presentation.ShapeFill(c.BottomBackground));
prb.Size.Height = r.Height / 2;
pr.Children.Add(prb);
prb = new Presentation.Rectangle(new Presentation.ShapeBorder(c.InnerBorder));
pr.Children.Add(prb);
Presentation.ShapePaintInfo pi = new Presentation.ShapePaintInfo(g, r);
pr.Paint(pi);
}
Size size = new Size(Dpi.Width8, Dpi.Height8);
// Get final dialog launcher bounds
if (rightToLeft)
r = new Rectangle(r.X + (r.Width - size.Width) / 2, r.Y + (r.Height - size.Height) / 2, size.Width, size.Height);
else
r = new Rectangle(r.X + (r.Width - size.Width)/2, r.Y + (r.Height - size.Height) / 2, size.Width, size.Height);
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.Default;
// Create the dialog launcher shape
Presentation.ShapeBorder border = new Presentation.ShapeBorder(c.DialogLauncherShade, 1);
Presentation.ShapeFill fill = new Presentation.ShapeFill(c.DialogLauncherShade);
Presentation.Shape shape = new Presentation.Shape();
// Horizontal line
Presentation.Line line = new Presentation.Line(new Presentation.Location(),
new Presentation.Location(Dpi.Width6, 0), border);
shape.Children.Add(line);
// Vertical line
line = new Presentation.Line(new Presentation.Location(),
new Presentation.Location(0, Dpi.Width6), border);
shape.Children.Add(line);
Presentation.Rectangle rect = new Presentation.Rectangle();
rect.Fill = fill;
rect.Location.X = Dpi.Width5;
rect.Location.Y = Dpi.Height5;
rect.Size.Width = Dpi.Width3;
rect.Size.Height = Dpi.Height3;
shape.Children.Add(rect);
// Arrow line vertical
line = new Presentation.Line(new Presentation.Location(Dpi.Width7, Dpi.Height4),
new Presentation.Location(Dpi.Width7, Dpi.Height7), border);
shape.Children.Add(line);
// Arrow line horizontal
line = new Presentation.Line(new Presentation.Location(Dpi.Width4, Dpi.Height7),
new Presentation.Location(Dpi.Width7, Dpi.Height7), border);
shape.Children.Add(line);
// Arrow line cross
line = new Presentation.Line(new Presentation.Location(Dpi.Width4, Dpi.Height4),
new Presentation.Location(Dpi.Width5, Dpi.Height5), border);
shape.Children.Add(line);
r.Offset(Dpi.Width1, Dpi.Height1);
Presentation.ShapePaintInfo p = new Presentation.ShapePaintInfo(g, r);
shape.Paint(p);
border.Color1 = c.DialogLauncher;
fill.Color1 = c.DialogLauncher;
r.Offset(-Dpi.Width1, -Dpi.Height1);
p.Bounds = r;
shape.Paint(p);
g.SmoothingMode = sm;
}
private Office2007DialogLauncherStateColorTable GetColorTable(RibbonBarRendererEventArgs e)
{
if (e.Pressed)
return m_ColorTable.DialogLauncher.Pressed;
else if (e.MouseOver)
return m_ColorTable.DialogLauncher.MouseOver;
else
return m_ColorTable.DialogLauncher.Default;
}
#endregion
}
}

View File

@@ -0,0 +1,186 @@
using System;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
internal class Office2007ItemContainerPainter : ItemContainerPainter, IOffice2007Painter
{
#region IOffice2007Painter
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
#region PaintBackground
public override void PaintBackground(ItemContainerRendererEventArgs e)
{
if (!BarFunctions.IsOffice2007Style(e.ItemContainer.EffectiveStyle))
return;
ItemContainer container = e.ItemContainer;
Office2007ItemGroupColorTable gt = m_ColorTable.ItemGroup;
if (container.SubItems.Count == 0 && (container.WidthInternal <= 0 || container.HeightInternal <= 0) || gt == null)
return;
Rectangle bounds = container.DisplayRectangle;
if (!container.BeginGroup || container.IsOnMenu && !(container.Parent is ItemContainer))
{
if (container.BackgroundStyle.Class == ElementStyleClassKeys.Office2007StatusBarBackground2Key && e.ItemPaintArgs != null &&
e.ItemPaintArgs.ContainerControl is Bar && ((Bar)e.ItemPaintArgs.ContainerControl).BarType == eBarType.StatusBar)
{
bounds.Y = 1;
if (!m_ColorTable.Bar.StatusBarTopBorderLight.IsEmpty) bounds.Y++;
bounds.Height = e.ItemPaintArgs.ContainerControl.Height - 1;
if (container.Parent.SubItems.IndexOf(container) == container.Parent.SubItems.Count - 1)
{
if (e.ItemPaintArgs.RightToLeft)
{
bounds.Width += bounds.X;
bounds.X = 0;
}
else
{
bounds.Width += e.ItemPaintArgs.ContainerControl.Width - bounds.Right;
}
}
}
Region oldClip = e.Graphics.Clip;
e.Graphics.SetClip(bounds);
ElementStyleDisplay.Paint(new ElementStyleDisplayInfo(container.BackgroundStyle, e.Graphics, bounds));
e.Graphics.Clip = oldClip;
if (oldClip != null) oldClip.Dispose();
return;
}
bounds.Width -= container.BackgroundStyle.MarginHorizontal;
bounds.Height -= container.BackgroundStyle.MarginVertical;
bounds.X += container.BackgroundStyle.MarginLeft;
bounds.Y += container.BackgroundStyle.MarginTop;
//bounds.Width--;
//bounds.Height--;
Graphics g = e.Graphics;
int cornerSize = 2;
//GraphicsPath path = DisplayHelp.GetRoundedRectanglePath(bounds, 2);
//using (SolidBrush brush = new SolidBrush(ColorScheme.GetColor("FEFFFF")))
// g.FillPath(brush, path);
// Draw border
if (gt.OuterBorder != null && !gt.OuterBorder.IsEmpty)
DisplayHelp.DrawRoundGradientRectangle(g, bounds, gt.OuterBorder, 1, cornerSize);
if (gt.InnerBorder != null && !gt.InnerBorder.IsEmpty)
{
bounds.Inflate(-1, -1);
DisplayHelp.DrawRoundGradientRectangle(g, bounds, gt.InnerBorder, 1, cornerSize);
}
float topPart = .4f;
Rectangle r = bounds;
r.Inflate(-1, -1);
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.Default;
if(gt.TopBackground!=null && !gt.TopBackground.IsEmpty)
DisplayHelp.FillRectangle(g, r, gt.TopBackground);
int topHeight = (int)(r.Height * topPart);
r.Height -= topHeight;
r.Y += topHeight;
if (gt.BottomBackground != null && !gt.BottomBackground.IsEmpty)
DisplayHelp.FillRectangle(g, r, gt.BottomBackground);
g.SmoothingMode = sm;
bool isVertical = container.LayoutOrientation == eOrientation.Vertical;
using (Pen penLight = new Pen(gt.ItemGroupDividerLight, 1))
{
using (Pen penDark = new Pen(gt.ItemGroupDividerDark))
{
int c = container.SubItems.Count - 1;
for (int i = 0; i <= c; i++)
{
BaseItem item = container.SubItems[i];
if (!item.Visible || item.DisplayRectangle.Right == container.DisplayRectangle.Right || i == c)
continue;
if (isVertical)
{
g.DrawLine(penDark, container.DisplayRectangle.X + 1, item.DisplayRectangle.Bottom - 1, container.DisplayRectangle.Right - 1, item.DisplayRectangle.Bottom - 1);
g.DrawLine(penLight, container.DisplayRectangle.X + 1, item.DisplayRectangle.Bottom, container.DisplayRectangle.Right, item.DisplayRectangle.Bottom);
}
else
{
g.DrawLine(penDark, item.DisplayRectangle.Right - 1, item.DisplayRectangle.Y + 1, item.DisplayRectangle.Right - 1, item.DisplayRectangle.Bottom - 2);
g.DrawLine(penLight, item.DisplayRectangle.Right, item.DisplayRectangle.Y + 1, item.DisplayRectangle.Right, item.DisplayRectangle.Bottom - 2);
}
}
}
}
//path.Dispose();
}
#endregion
#region Paint Separator
public override void PaintItemSeparator(ItemContainerSeparatorRendererEventArgs e)
{
if (e.Item is ItemContainer)
return;
Graphics g = e.Graphics;
BaseItem item = e.Item;
Size imageSize = Size.Empty;
if (item is ImageItem)
imageSize = ((ImageItem)item).ImageSize;
ItemContainer container = e.ItemContainer;
Color color1 = m_ColorTable.LegacyColors.ItemSeparator;
Color color2 = m_ColorTable.LegacyColors.ItemSeparatorShade;
Point start = Point.Empty, end = Point.Empty;
Point start2 = Point.Empty, end2 = Point.Empty;
if (container.LayoutOrientation == eOrientation.Horizontal)
{
start = new Point(item.DisplayRectangle.X - 2, item.DisplayRectangle.Y + 3);
end = new Point(start.X, item.DisplayRectangle.Bottom - 4);
start2 = new Point(start.X + 1, start.Y);
end2 = new Point(end.X + 1, end.Y);
}
else
{
if (item.IsOnMenu)
{
start = new Point(item.DisplayRectangle.X + imageSize.Width, item.DisplayRectangle.Y - 2);
end = new Point(item.DisplayRectangle.Right-1, start.Y);
start2 = new Point(start.X, start.Y + 1);
end2 = new Point(end.X, end.Y + 1);
}
else
{
start = new Point(item.DisplayRectangle.X + 3, item.DisplayRectangle.Y - 2);
end = new Point(item.DisplayRectangle.Right - 4, start.Y);
start2 = new Point(start.X, start.Y + 1);
end2 = new Point(end.X, end.Y + 1);
}
}
DisplayHelp.DrawLine(g, start, end, color1, 1);
DisplayHelp.DrawLine(g, start2, end2, color2, 1);
}
#endregion
}
}

View File

@@ -0,0 +1,51 @@
using System;
using System.Text;
using System.Drawing;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
internal class Office2007KeyTipsPainter : KeyTipsPainter, IOffice2007Painter
{
#region IOffice2007Painter
private Office2007ColorTable m_ColorTable = null; //new OfficeColorTable();
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
#region Paint KeyTips
public override void PaintKeyTips(KeyTipsRendererEventArgs e)
{
Rectangle r = e.Bounds;
Color borderColor = m_ColorTable.KeyTips.KeyTipBorder;
Color textColor = m_ColorTable.KeyTips.KeyTipText;
Color backColor = m_ColorTable.KeyTips.KeyTipBackground;
if (e.ReferenceObject is BaseItem && !((BaseItem)e.ReferenceObject).Enabled)
{
int alpha = 128;
backColor = Color.FromArgb(alpha, backColor);
textColor = Color.FromArgb(alpha, textColor);
borderColor = Color.FromArgb(alpha, borderColor);
}
Graphics g = e.Graphics;
string keyTip = e.KeyTip;
Font font = e.Font;
using (SolidBrush brush = new SolidBrush(backColor))
DisplayHelp.FillRoundedRectangle(g, brush, r, 2);
using (Pen pen = new Pen(textColor, 1))
DisplayHelp.DrawRoundedRectangle(g, pen, r, 2);
TextDrawing.DrawString(g, keyTip, font, textColor, r, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter);
}
#endregion
}
}

View File

@@ -0,0 +1,114 @@
using System;
using System.Drawing;
using System.Text;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents Office 2007 style MdiSystemItem painter
/// </summary>
internal class Office2007MdiSystemItemPainter : MdiSystemItemPainter, IOffice2007Painter
{
#region Private Variables
#endregion
#region IOffice2007Painter
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
/// <summary>
/// Gets or sets color table used by renderer.
/// </summary>
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
public override void Paint(MdiSystemItemRendererEventArgs e)
{
MDISystemItem mdi = e.MdiSystemItem;
Graphics g = e.Graphics;
Rectangle r = mdi.DisplayRectangle;
if (mdi.IsSystemIcon)
{
r.Offset((r.Width - 16) / 2, (r.Height - 16) / 2);
if (mdi.Icon != null)
g.DrawIconUnstretched(mdi.Icon, r);
return;
}
r = new Rectangle(mdi.DisplayRectangle.Location, mdi.GetButtonSize());
if (mdi.Orientation == eOrientation.Horizontal)
r.Offset(0, (mdi.DisplayRectangle.Height - r.Height) / 2);
else
r.Offset((mdi.WidthInternal - r.Width) / 2, 0);
this.PaintButton(g, mdi, SystemButton.Minimize, r, GetColorTable(mdi, SystemButton.Minimize), m_ColorTable.LegacyColors);
if (mdi.Orientation == eOrientation.Horizontal)
r.Offset(r.Width, 0);
else
r.Offset(0, r.Height);
this.PaintButton(g, mdi, SystemButton.Restore, r, GetColorTable(mdi, SystemButton.Restore), m_ColorTable.LegacyColors);
if (mdi.Orientation == eOrientation.Horizontal)
r.Offset(r.Width + 2, 0);
else
r.Offset(0, r.Height + 2);
this.PaintButton(g, mdi, SystemButton.Close, r, GetColorTable(mdi, SystemButton.Close), m_ColorTable.LegacyColors);
}
private Office2007ButtonItemStateColorTable GetColorTable(MDISystemItem mdi, SystemButton button)
{
Office2007ButtonItemColorTable colors = m_ColorTable.ButtonItemColors[eButtonColor.Orange.ToString()];
Office2007ButtonItemStateColorTable ct = colors.Default;
if (mdi.MouseDownButton == button)
ct = colors.Pressed;
else if (mdi.MouseOverButton == button)
ct = colors.MouseOver;
return ct;
}
private void PaintButton(Graphics g, MDISystemItem mdi , SystemButton button, Rectangle r, Office2007ButtonItemStateColorTable ct, ColorScheme colorScheme)
{
Region oldClip = g.Clip;
g.SetClip(r);
Office2007ButtonItemPainter.PaintBackground(g, ct, r, RoundRectangleShapeDescriptor.RoundCorner2);
r.Inflate(-1, -1);
r.Offset(1, 0);
using (Bitmap bmp = mdi.GetButtonBitmap(g, button, r, colorScheme))
{
if (button == SystemButton.Minimize && !mdi.MinimizeEnabled ||
button == SystemButton.Restore && !mdi.RestoreEnabled ||
button == SystemButton.Close && !mdi.CloseEnabled)
{
float[][] array = new float[5][];
array[0] = new float[5] { 0, 0, 0, 0, 0 };
array[1] = new float[5] { 0, 0, 0, 0, 0 };
array[2] = new float[5] { 0, 0, 0, 0, 0 };
array[3] = new float[5] { .5f, .5f, .5f, .5f, 0 };
array[4] = new float[5] { 0, 0, 0, 0, 0 };
System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
System.Drawing.Imaging.ImageAttributes disabledImageAttr = new System.Drawing.Imaging.ImageAttributes();
disabledImageAttr.ClearColorKey();
disabledImageAttr.SetColorMatrix(grayMatrix);
g.DrawImage(bmp, r, 0, 0, bmp.Width, bmp.Height, GraphicsUnit.Pixel, disabledImageAttr);
}
else
{
if (button == mdi.MouseDownButton)
r.Offset(1, 1);
g.DrawImageUnscaled(bmp, r);
}
}
g.Clip = oldClip;
}
}
}

View File

@@ -0,0 +1,994 @@
using System;
using System.Drawing;
using System.Text;
using System.Drawing.Drawing2D;
using System.Collections;
using System.Runtime.InteropServices;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
internal class Office2007RibbonControlPainter : RibbonControlPainter, Rendering.IOffice2007Painter
{
private Rendering.Office2007ColorTable m_ColorTable = null; //new Rendering.Office2007ColorTable();
#region Ribbon Control Background
/// <summary>
/// Paints controls background
/// </summary>
public override void PaintBackground(RibbonControlRendererEventArgs e)
{
Graphics g = e.Graphics;
RibbonControl rc = e.RibbonControl;
Rendering.Office2007RibbonColorTable ct = m_ColorTable.RibbonControl;
Rendering.Office2007RibbonTabItemStateColorTable selectedTabColors = null;
PaintCaptionBackground(e, rc.DisplayRectangle);
if (rc.Expanded && rc.RibbonStrip.HasVisibleTabs)
{
int cornerSize = ct.CornerSize;
// Draw the border which is base for the tabs
Rectangle selectedTabRect = Rectangle.Empty;
if (rc.SelectedRibbonTabItem == null || !rc.Expanded)
selectedTabRect = Rectangle.Empty;
else
{
selectedTabRect = rc.SelectedRibbonTabItem.DisplayRectangle;
selectedTabColors = Office2007RibbonTabItemPainter.GetStateColorTable(Office2007RibbonTabItemPainter.GetColorTable(this.ColorTable, rc.SelectedRibbonTabItem), rc.SelectedRibbonTabItem, rc.Expanded);
}
Rectangle bottomBounds = new Rectangle(rc.ClientRectangle.X, rc.ClientRectangle.Bottom - cornerSize, rc.ClientRectangle.Width - 1, cornerSize);
if (!selectedTabRect.IsEmpty)
bottomBounds = new Rectangle(rc.ClientRectangle.X, selectedTabRect.Bottom,
rc.ClientRectangle.Width - 1, rc.ClientRectangle.Bottom - selectedTabRect.Bottom);
//using (GraphicsPath path = GetBottomLinePath(bottomBounds, cornerSize))
//{
// using (SolidBrush brush = new SolidBrush(m_ColorTable.RibbonBar.Default.TopBackground.Start))
// g.FillPath(brush, path);
//}
// Dark border
using (GraphicsPath path = GetBottomLinePath(bottomBounds, cornerSize))
{
Region oldRegion = null;
if (g.Clip != null) oldRegion = g.Clip as Region;
if (!selectedTabRect.IsEmpty)
{
if (selectedTabColors != null)
{
using (Pen pen = new Pen(selectedTabColors.Background.End.IsEmpty ? selectedTabColors.Background.Start : selectedTabColors.Background.End, 1))
g.DrawLine(pen, selectedTabRect.X + 1, selectedTabRect.Bottom, selectedTabRect.Right - 1, selectedTabRect.Bottom);
}
g.SetClip(new Rectangle(selectedTabRect.X + 1, selectedTabRect.Bottom, selectedTabRect.Width - 1, 1), CombineMode.Exclude);
if (StyleManager.IsMetro(rc.EffectiveStyle))
{
ApplicationButton appButton = rc.GetApplicationButton() as ApplicationButton;
if (appButton != null && appButton.Displayed)
{
Rectangle rApp = appButton.Bounds;
g.TranslateTransform(0, 1);
appButton.Paint(e.ItemPaintArgs);
g.TranslateTransform(0, -1);
rApp.Inflate(0, 2);
rApp.Width-=3;
g.SetClip(rApp, CombineMode.Exclude);
}
}
}
using (Pen pen = new Pen(ct.OuterBorder.Start, 1))
g.DrawPath(pen, path);
if (!selectedTabRect.IsEmpty)
{
if (oldRegion != null)
g.Clip = oldRegion;
else
g.ResetClip();
}
if (oldRegion != null) oldRegion.Dispose();
}
// Light border
bottomBounds.Y++;
if (ct.InnerBorder != null)
{
using (GraphicsPath path = GetBottomLinePath(bottomBounds, cornerSize))
{
using (Pen pen = new Pen(ct.InnerBorder.Start, 1))
g.DrawPath(pen, path);
}
}
}
else
{
int topLineY = rc.ClientRectangle.Bottom - 2;
if (!ct.TabDividerBorder.IsEmpty)
{
using (Pen pen = new Pen(ct.TabDividerBorder, 1))
g.DrawLine(pen, 0, topLineY, rc.ClientRectangle.Right, topLineY);
topLineY++;
}
if (!ct.TabDividerBorderLight.IsEmpty)
{
using (Pen pen = new Pen(ct.TabDividerBorderLight, 1))
g.DrawLine(pen, 0, topLineY, rc.ClientRectangle.Right, topLineY);
}
}
}
/// <summary>
/// Paints form caption background
/// </summary>
public override void PaintCaptionBackground(RibbonControlRendererEventArgs e, Rectangle displayRect)
{
Graphics g = e.Graphics;
RibbonControl rc = e.RibbonControl;
Rendering.Office2007RibbonColorTable ct = m_ColorTable.RibbonControl;
// Draw top divider line that sits between the tabs and any items above
int topLineY = GetTabYPosition(rc.Items);
if (topLineY == -1) topLineY = rc.RibbonStrip.GetAbsoluteCaptionHeight() + 2;
if (topLineY > 2)
{
if (e.GlassEnabled && rc.EffectiveStyle == eDotNetBarStyle.Windows7)
topLineY -= 2;
else
topLineY -= 3;
if (!e.GlassEnabled)
{
if (!ct.TabDividerBorder.IsEmpty)
{
using (Pen pen = new Pen(ct.TabDividerBorder, 1))
g.DrawLine(pen, 0, topLineY, displayRect.Right + 12, topLineY); // 12 extension when painting from Office2007RibbonForm
topLineY++;
}
if (!ct.TabDividerBorderLight.IsEmpty)
{
using (Pen pen = new Pen(ct.TabDividerBorderLight, 1))
g.DrawLine(pen, 0, topLineY, displayRect.Right + 12, topLineY);
}
}
else
{
if (rc.EffectiveStyle != eDotNetBarStyle.Office2010 && !StyleManager.IsMetro(rc.EffectiveStyle))
{
using (Pen pen = new Pen(m_ColorTable.Form.Active.BorderColors[0], 1))
g.DrawLine(pen, 0, topLineY, displayRect.Right + 12, topLineY); // 12 extension when painting from Office2007RibbonForm
}
}
}
// Draw Caption if necessary
if (rc.RibbonStrip.CaptionVisible)
{
Rendering.Office2007FormStateColorTable formct = m_ColorTable.Form.Active;
System.Windows.Forms.Form form = rc.FindForm();
if (!rc.IsDesignMode && form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
{
formct = m_ColorTable.Form.Inactive;
}
Rectangle captionRect = new Rectangle(displayRect.X, displayRect.Y, displayRect.Width, topLineY - 1);
if (captionRect.Height <= 0)
captionRect.Height = rc.RibbonStrip.GetAbsoluteCaptionHeight();
if (!e.GlassEnabled)
{
Rectangle drawRect = captionRect;
if (form is RibbonForm)
drawRect.Width = ((RibbonForm)form).Width;
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.Default;
if (!formct.CaptionTopBackground.End.IsEmpty && !formct.CaptionBottomBackground.End.IsEmpty)
{
using (LinearGradientBrush lb = new LinearGradientBrush(drawRect, formct.CaptionTopBackground.Start, formct.CaptionBottomBackground.End, formct.CaptionTopBackground.GradientAngle))
{
ColorBlend cb = new ColorBlend(4);
cb.Colors = new Color[] { formct.CaptionTopBackground.Start, formct.CaptionTopBackground.End, formct.CaptionBottomBackground.Start, formct.CaptionBottomBackground.End };
cb.Positions = new float[] { 0, .4f, .4f, 1f };
lb.InterpolationColors = cb;
g.FillRectangle(lb, drawRect);
}
}
else
{
using (LinearGradientBrush lb = new LinearGradientBrush(drawRect, formct.CaptionTopBackground.Start, formct.CaptionBottomBackground.Start, formct.CaptionTopBackground.GradientAngle))
{
g.FillRectangle(lb, drawRect);
}
}
//// Top Part
//Rectangle topCaptionPart = new Rectangle(drawRect.X, drawRect.Y, drawRect.Width, (int)(drawRect.Height * .4));
//DisplayHelp.FillRectangle(g, topCaptionPart, formct.CaptionTopBackground);
//Rectangle bottomCaptionPart = new Rectangle(drawRect.X, topCaptionPart.Bottom, drawRect.Width, drawRect.Height - topCaptionPart.Height);
//DisplayHelp.FillRectangle(g, bottomCaptionPart, formct.CaptionBottomBackground);
g.SmoothingMode = sm;
}
rc.RibbonStrip.CaptionBounds = captionRect;
}
}
private GraphicsPath GetBottomLinePath(Rectangle bottomBounds, int cornerSize)
{
GraphicsPath path = new GraphicsPath();
if (cornerSize > 1)
{
if (bottomBounds.Height > cornerSize)
path.AddLine(bottomBounds.X, bottomBounds.Bottom, bottomBounds.X, bottomBounds.Y + cornerSize);
ElementStyleDisplay.AddCornerArc(path, bottomBounds, cornerSize, eCornerArc.TopLeft);
path.AddLine(bottomBounds.X + cornerSize, bottomBounds.Y, bottomBounds.Right - cornerSize, bottomBounds.Y);
ElementStyleDisplay.AddCornerArc(path, bottomBounds, cornerSize, eCornerArc.TopRight);
if (bottomBounds.Height > cornerSize)
path.AddLine(bottomBounds.Right, bottomBounds.Y + cornerSize, bottomBounds.Right, bottomBounds.Bottom);
}
else
{
path.AddLine(bottomBounds.X, bottomBounds.Y, bottomBounds.Right, bottomBounds.Y);
//path.AddRectangle(bottomBounds);
}
return path;
}
private int GetTabYPosition(SubItemsCollection c)
{
foreach (BaseItem item in c)
{
if (item is RibbonTabItem && item.Visible)
{
return item.Bounds.Top;
}
}
return -1;
}
#endregion
#region IOffice2007Painter Members
public DevComponents.DotNetBar.Rendering.Office2007ColorTable ColorTable
{
get
{
return m_ColorTable;
}
set
{
m_ColorTable = value;
}
}
#endregion
#region Form Caption Text Drawing
public override void PaintCaptionText(RibbonControlRendererEventArgs e)
{
RibbonStrip rs = e.RibbonControl.RibbonStrip;
if (!rs.CaptionVisible || rs.CaptionBounds.IsEmpty)
return;
Graphics g = e.Graphics;
bool isMaximized = false;
bool isFormActive = true;
Rendering.Office2007FormStateColorTable formct = m_ColorTable.Form.Active;
System.Windows.Forms.Form form = rs.FindForm();
bool renderText = true;
if (form is RibbonForm && !((RibbonForm)form).RenderFormText) renderText = false;
if (form != null && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
{
formct = m_ColorTable.Form.Inactive;
isFormActive = false;
}
string text = e.RibbonControl.TitleText;
string plainText = text;
bool isTitleTextMarkup = e.RibbonControl.RibbonStrip.TitleTextMarkupBody != null;
if (isTitleTextMarkup)
plainText = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.PlainText;
if (form != null)
{
if (text == "")
{
text = form.Text;
plainText = text;
}
isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;
}
Rectangle captionRect = rs.CaptionBounds;
// Exclude quick access toolbar if any
if (!rs.QuickToolbarBounds.IsEmpty)
DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.QuickToolbarBounds);
else
{
BaseItem sb = e.RibbonControl.GetApplicationButton();
if (sb != null && sb.Visible && sb.Displayed)
DisplayHelp.ExcludeEdgeRect(ref captionRect, sb.Bounds);
else
DisplayHelp.ExcludeEdgeRect(ref captionRect, new Rectangle(0, 0, 22, 22)); // The system button in top-left corner
}
if (!rs.SystemCaptionItemBounds.IsEmpty)
DisplayHelp.ExcludeEdgeRect(ref captionRect, rs.SystemCaptionItemBounds);
// Array of the rectangles after they are split
ArrayList rects = new ArrayList(5);
ArrayList tempRemoveList = new ArrayList(5);
// Exclude Context Tabs Captions if any
if (rs.TabGroupsVisible)
{
foreach (RibbonTabItemGroup group in rs.TabGroups)
{
foreach (Rectangle r in group.DisplayPositions)
{
if (rects.Count > 0)
{
tempRemoveList.Clear();
Rectangle[] arrCopy = new Rectangle[rects.Count];
rects.CopyTo(arrCopy);
for (int irc = 0; irc < arrCopy.Length; irc++)
{
if (arrCopy[irc].IntersectsWith(r))
{
tempRemoveList.Add(irc);
Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(arrCopy[irc], r);
rects.AddRange(splitRects);
}
}
foreach (int idx in tempRemoveList)
rects.RemoveAt(idx);
}
else
{
if (r.IntersectsWith(captionRect))
{
Rectangle[] splitRects = DisplayHelp.ExcludeRectangle(captionRect, r);
if (splitRects.Length > 0)
{
rects.AddRange(splitRects);
break;
}
}
}
}
}
}
Font font = SystemFonts.CaptionFont;
bool disposeFont = true;
if (rs.CaptionFont != null)
{
font.Dispose();
font = rs.CaptionFont;
disposeFont = false;
}
Size textSize = Size.Empty;
if (isTitleTextMarkup)
{
textSize = e.RibbonControl.RibbonStrip.TitleTextMarkupBody.Bounds.Size;
}
else
{
textSize = TextDrawing.MeasureString(g, plainText, font);
}
if (rects.Count > 0)
{
rs.CaptionTextBounds = (Rectangle[])rects.ToArray(typeof(Rectangle));
if (e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.No)
rects.Reverse();
captionRect = Rectangle.Empty;
foreach (Rectangle r in rects)
{
if (r.Width >= textSize.Width)
{
captionRect = r;
break;
}
else if (r.Width > captionRect.Width)
captionRect = r;
}
}
else
rs.CaptionTextBounds = new Rectangle[] { captionRect };
if (captionRect.Width > 6 && captionRect.Height > 6 && renderText)
{
if (e.GlassEnabled && e.ItemPaintArgs != null && e.ItemPaintArgs.ThemeWindow != null && !e.RibbonControl.IsDesignMode)
{
if (!e.ItemPaintArgs.CachedPaint || isMaximized)
PaintGlassText(g, plainText, font, captionRect, isMaximized);
}
else
{
if (!isTitleTextMarkup)
TextDrawing.DrawString(g, plainText, font, formct.CaptionText, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
else
{
TextMarkup.MarkupDrawContext d = new TextMarkup.MarkupDrawContext(g, font, formct.CaptionText, e.RibbonControl.RightToLeft == System.Windows.Forms.RightToLeft.Yes, captionRect, false);
d.AllowMultiLine = false;
d.IgnoreFormattingColors = !isFormActive;
TextMarkup.BodyElement body = e.RibbonControl.RibbonStrip.TitleTextMarkupBody;
if (e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds != captionRect)
{
body.Measure(captionRect.Size, d);
body.Arrange(captionRect, d);
e.RibbonControl.RibbonStrip.TitleTextMarkupLastArrangeBounds = captionRect;
Rectangle mr = body.Bounds;
if (mr.Width < captionRect.Width)
mr.Offset((captionRect.Width - mr.Width) / 2, 0);
if (mr.Height < captionRect.Height)
mr.Offset(0, (captionRect.Height - mr.Height) / 2);
body.Bounds = mr;
}
Region oldClip = g.Clip;
g.SetClip(captionRect, CombineMode.Intersect);
body.Render(d);
g.Clip = oldClip;
if (oldClip != null) oldClip.Dispose();
}
}
}
if (disposeFont) font.Dispose();
}
//private void PaintGlassTextTheme(Graphics g, string text, Font font, Rectangle captionRect, ItemPaintArgs pa)
//{
// //TextDrawing.DrawString(g, text, font, SystemColors.ActiveCaptionText, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
// //Bitmap bmp = new Bitmap(captionRect.Width, captionRect.Height);
// //bmp.MakeTransparent();
// //using (Graphics gb = Graphics.FromImage(bmp))
// {
// //gb.FillRectangle(new SolidBrush(Color.Black), new Rectangle(0, 0, bmp.Width, bmp.Height));
// //gb.FillRectangle(new SolidBrush(Color.FromArgb(186, Color.White)), new Rectangle(0, 0, bmp.Width, bmp.Height));
// //g.ResetTransform();
// //e.ItemPaintArgs.ThemeWindow.DrawText(g, text, font, captionRect,
// // ThemeWindowParts.Caption, ThemeWindowStates.CaptionActive);
// //g.ResetTransform();
// Themes.DTTOPTS options = new Themes.DTTOPTS();
// options.iGlowSize = 12;
// options.crText = new Themes.COLORREF(SystemColors.ActiveCaptionText);
// options.dwFlags = (int)(Themes.DTT_VALIDBITS.DTT_TEXTCOLOR |
// Themes.DTT_VALIDBITS.DTT_APPLYOVERLAY |
// Themes.DTT_VALIDBITS.DTT_COMPOSITED | Themes.DTT_VALIDBITS.DTT_GLOWSIZE
// );
// pa.ThemeWindow.DrawTextEx(g, text, font, captionRect,
// ThemeWindowParts.Caption, ThemeWindowStates.CaptionActive,
// ThemeTextFormat.Center | ThemeTextFormat.VCenter | ThemeTextFormat.EndEllipsis | ThemeTextFormat.NoPrefix |
// ThemeTextFormat.SingleLine,
// options);
// //g.ResetTransform();
// }
// //bmp.MakeTransparent(Color.Black);
// //g.DrawImage(bmp, captionRect.Location);
// //bmp.Save(@"TitleImage.png", System.Drawing.Imaging.ImageFormat.Png);
// //bmp.Dispose();
//}
#if FRAMEWORK20
public static void PaintTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf)
{
PaintTextOnGlass(g, text, font, rect, tf, SystemColors.ControlText, false, true, 16);
}
public static void PaintTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, bool copySourceBackground, bool renderGlow, int glowSize)
{
IntPtr hdc = g.GetHdc();
const int SRCCOPY = 0x00CC0020;
try
{
IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
try
{
WinApi.BITMAPINFO info = new WinApi.BITMAPINFO();
info.biWidth = rect.Width;
info.biHeight = -rect.Height;
info.biPlanes = 1;
info.biBitCount = 32;
info.biSize = Marshal.SizeOf(info);
IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0);
WinApi.SelectObject(memdc, dib);
IntPtr fontHandle = font.ToHfont();
WinApi.SelectObject(memdc, fontHandle);
Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height));
System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
dttOpts.iGlowSize = glowSize;
dttOpts.crText = new Themes.COLORREF(textColor);
dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED |
(renderGlow ? (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE : 0) |
(int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
dttOpts.dwSize = Marshal.SizeOf(dttOpts);
if (copySourceBackground)
WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left, rect.Top, SRCCOPY);
Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);
WinApi.DeleteObject(fontHandle);
WinApi.DeleteObject(dib);
}
finally
{
WinApi.DeleteDC(memdc);
}
}
finally
{
g.ReleaseHdc(hdc);
}
}
public static void PaintShadowTextOnGlass(Graphics g, string text, Font font, Rectangle rect, ThemeTextFormat tf, Color textColor, Color shadowColor, bool copySourceBackground)
{
Point transformPoint = new Point();
using (Matrix trans = g.Transform)
{
Point[] pts = new Point[1];
pts[0] = transformPoint;
trans.TransformPoints(pts);
transformPoint = pts[0];
}
IntPtr hdc = g.GetHdc();
const int SRCCOPY = 0x00CC0020;
try
{
IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
try
{
WinApi.BITMAPINFO info = new WinApi.BITMAPINFO();
info.biWidth = rect.Width;
info.biHeight = -rect.Height;
info.biPlanes = 1;
info.biBitCount = 32;
info.biSize = Marshal.SizeOf(info);
IntPtr dib = WinApi.CreateDIBSection(hdc, info, 0, 0, IntPtr.Zero, 0);
WinApi.SelectObject(memdc, dib);
IntPtr fontHandle = font.ToHfont();
WinApi.SelectObject(memdc, fontHandle);
Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height));
System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
dttOpts.crText = new Themes.COLORREF(shadowColor);
dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED |
(int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
dttOpts.dwSize = Marshal.SizeOf(dttOpts);
if (copySourceBackground)
WinApi.BitBlt(memdc, 0, 0, rect.Width, rect.Height, hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, SRCCOPY);
// Shadow
bounds.Offset(1, 2);
Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
bounds.Offset(-1, -1);
dttOpts.crText = new Themes.COLORREF(textColor);
Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
//Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
WinApi.BitBlt(hdc, rect.Left + transformPoint.X, rect.Top + transformPoint.Y, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);
WinApi.DeleteObject(fontHandle);
WinApi.DeleteObject(dib);
}
finally
{
WinApi.DeleteDC(memdc);
}
}
finally
{
g.ReleaseHdc(hdc);
}
}
private void PaintGlassText(Graphics g, string text, Font font, Rectangle captionRect, bool isMaximized)
{
if (isMaximized && !BarFunctions.IsWindows7)
{
captionRect.Offset(0, 3);
TextDrawing.DrawString(g, text, font, Color.White, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
return;
}
if (isMaximized && BarFunctions.IsWindows7)
{
captionRect.Y += 6;
captionRect.Height -= 6;
}
ThemeTextFormat tf = ThemeTextFormat.Center | ThemeTextFormat.EndEllipsis | ThemeTextFormat.VCenter | ThemeTextFormat.SingleLine;
PaintTextOnGlass(g, text, font, captionRect, tf);
}
#else
private void PaintGlassText(Graphics g, string text, Font font, Rectangle captionRect, bool isMaximized)
{
if (isMaximized)
{
captionRect.Offset(0, 3);
TextDrawing.DrawString(g, text, font, Color.White, captionRect, eTextFormat.VerticalCenter | eTextFormat.HorizontalCenter | eTextFormat.EndEllipsis | eTextFormat.NoPrefix);
return;
}
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.HighQuality;
using (GraphicsPath path = new GraphicsPath())
{
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.Trimming = StringTrimming.EllipsisCharacter;
format.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.None;
format.FormatFlags |= StringFormatFlags.NoWrap;
const float emMulti = 1.3285f;
path.AddString(text, font.FontFamily, (int)font.Style, font.SizeInPoints * emMulti, captionRect, format);
using (Pen glowPen = new Pen(Color.FromArgb(215, Color.White), 4f))
{
//glowPen.PenType = PenType.PathGradient;
GraphicsPath p1 = new GraphicsPath();
Rectangle rc = captionRect;
rc.Inflate(captionRect.Width/2, -3);
p1.AddEllipse(rc);
PathGradientBrush pb = new PathGradientBrush(p1);
pb.CenterColor = Color.FromArgb(164, Color.White);
pb.SurroundColors = new Color[] { Color.Transparent };
glowPen.Brush = pb;
g.DrawPath(glowPen, path);
}
//GraphicsPath glowPath = path.Clone() as GraphicsPath;
//using (Region reg = new Region())
//{
// reg.MakeEmpty();
// reg.Union(glowPath);
// using (Pen pen = new Pen(Color.Black, 5))
// glowPath.Widen(pen);
// reg.Union(glowPath);
// GraphicsPath p1 = new GraphicsPath();
// RectangleF rf = glowPath.GetBounds();
// p1.AddEllipse(rf.X - 12, rf.Y - 4, rf.Width + 24, rf.Height + 8);
// using (PathGradientBrush pb = new PathGradientBrush(p1))
// {
// pb.CenterColor = Color.FromArgb(164, Color.White);
// pb.SurroundColors = new Color[] { Color.Transparent };
// Blend blend = new Blend();
// blend.Factors = new float[] { 0f, .9f, 1f };
// blend.Positions = new float[] { .0f, .9f, 1f };
// pb.Blend = blend;
// g.FillRegion(pb, reg);
// }
// p1.Dispose();
// glowPath.Dispose();
//}
g.FillPath(SystemBrushes.ActiveCaptionText, path);
}
g.SmoothingMode = sm;
}
#endif
private class RectangleWidthComparer : IComparer
{
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
int IComparer.Compare(object x, object y)
{
if (x is Rectangle && y is Rectangle)
{
return ((Rectangle)x).Width - ((Rectangle)y).Width;
}
else
return ((new CaseInsensitiveComparer()).Compare(x, y));
}
}
#endregion
#region Quick Access Toolbar background
/// <summary>
/// Paints the background of quick access toolbar.
/// </summary>
public override void PaintQuickAccessToolbarBackground(RibbonControlRendererEventArgs e)
{
RibbonStrip rs = e.RibbonControl.RibbonStrip;
RibbonControl ribbon = e.RibbonControl;
if (!rs.CaptionVisible)
return;
eDotNetBarStyle effectiveStyle = ribbon.EffectiveStyle;
Graphics g = e.Graphics;
bool rightToLeft = (rs.RightToLeft == System.Windows.Forms.RightToLeft.Yes);
bool drawQatBackground = true;
// Get appropriate color table
Rendering.Office2007QuickAccessToolbarStateColorTable ct = m_ColorTable.QuickAccessToolbar.Active;
System.Windows.Forms.Form form = rs.FindForm();
bool isMaximized = false;
if (form != null) isMaximized = form.WindowState == System.Windows.Forms.FormWindowState.Maximized;
if (form != null && !e.RibbonControl.IsDesignMode && (form != System.Windows.Forms.Form.ActiveForm && form.MdiParent == null ||
form.MdiParent != null && form.MdiParent.ActiveMdiChild != form))
ct = m_ColorTable.QuickAccessToolbar.Inactive;
// Get right most X position of the Quick Access Toolbar
int right = 0, sysLeft = 0;
Size qatSize = Size.Empty;
for (int i = rs.QuickToolbarItems.Count - 1; i >= 0; i--)
{
BaseItem item = rs.QuickToolbarItems[i];
if (!item.Visible || !item.Displayed && !((RibbonStripContainerItem)rs.GetBaseItemContainer()).MetroBackstageOpen)
continue;
if (item is QatCustomizeItem) qatSize = item.DisplayRectangle.Size;
if (item.ItemAlignment == eItemAlignment.Near && item.Visible && i > 0)
{
if (rightToLeft)
right = item.DisplayRectangle.X;
else
right = item.DisplayRectangle.Right;
break;
}
else if (item.ItemAlignment == eItemAlignment.Far && item.Visible)
{
if (rightToLeft)
sysLeft = item.DisplayRectangle.Right;
else
sysLeft = item.DisplayRectangle.X;
}
}
if (right == 0) drawQatBackground = false;
if (rs.CaptionContainerItem is CaptionItemContainer && ((CaptionItemContainer)rs.CaptionContainerItem).MoreItems != null)
{
if (rightToLeft)
right = ((CaptionItemContainer)rs.CaptionContainerItem).MoreItems.DisplayRectangle.X;
else
right = ((CaptionItemContainer)rs.CaptionContainerItem).MoreItems.DisplayRectangle.Right;
qatSize = ((CaptionItemContainer)rs.CaptionContainerItem).MoreItems.DisplayRectangle.Size;
}
Rectangle r = rs.CaptionBounds;
if (sysLeft > 0)
{
if (rightToLeft)
rs.SystemCaptionItemBounds = new Rectangle(r.X, r.Y, sysLeft, r.Height);
else
rs.SystemCaptionItemBounds = new Rectangle(sysLeft, r.Y, r.Right - sysLeft, r.Height);
}
if (right == 0 || r.Height <= 0 || r.Width <= 0)
return;
if (!ribbon.QatPositionedBelowRibbon)
{
BaseItem startButton = ribbon.GetApplicationButton();
if (startButton != null)
{
int startIndex = rs.QuickToolbarItems.IndexOf(startButton);
if (rs.QuickToolbarItems.Count - 1 > startIndex)
{
BaseItem firstItem = rs.QuickToolbarItems[startIndex + 1];
if (rightToLeft)
{
r.Width -= r.Right - firstItem.DisplayRectangle.Right;
}
else
{
r.Width -= firstItem.DisplayRectangle.X - r.X;
r.X = firstItem.DisplayRectangle.X;
}
}
}
r.Height = ((CaptionItemContainer)ribbon.RibbonStrip.CaptionContainerItem).MaxItemHeight + 6;
}
// Create QAT rectangle
int reduction = (r.Right - right);
if (rightToLeft)
{
r.Width = reduction;
if (rightToLeft) r.X += right;
}
else
{
r.Width -= reduction;
}
if (e.GlassEnabled)
{
r.Inflate(0, -3);
r.Offset(0, 2);
}
else
{
r.Inflate(0, -2);
if (isMaximized)
{
r.Y++;
r.Height--;
}
}
// Draw it, fill first
GraphicsPath path = GetQuickToolbarBackPath(r, rightToLeft);
if (path == null) return;
// Get total background bounds and save them
Rectangle clip = Rectangle.Ceiling(path.GetBounds());
rs.QuickToolbarBounds = clip;
// Adjust the bounds of QAT so it is drawn before the QAT Customize Item
r.Width -= (qatSize.Width + qatSize.Height / 2);
if (rightToLeft)
r.X += (qatSize.Width + qatSize.Height / 2) + 3;
path.Dispose();
path = GetQuickToolbarBackPath(r, rightToLeft);
SmoothingMode sm = g.SmoothingMode;
if (!ribbon.QatPositionedBelowRibbon && drawQatBackground && r.Width > 6)
{
bool glassBorderPainted = false;
if (e.GlassEnabled)
{
g.SmoothingMode = SmoothingMode.HighQuality;
if (e.GlassEnabled && isMaximized && effectiveStyle == eDotNetBarStyle.Office2007)
{
DisplayHelp.FillPath(g, path, Color.FromArgb(72, Color.LightGray), Color.Empty);
}
if (!ct.GlassBorder.IsEmpty)
DisplayHelp.DrawGradientPathBorder(g, path, ct.GlassBorder, 1);
g.SmoothingMode = sm;
if (e.GlassEnabled) glassBorderPainted = true;
}
else
{
if (!ct.OutterBorderColor.IsEmpty)
{
g.SmoothingMode = SmoothingMode.HighQuality;
r.X++;
//r.Y++;
r.Y--;
r.Height += 2;
using (GraphicsPath pathOuter = GetQuickToolbarBackPath(r, rightToLeft))
{
using (Pen pen = new Pen(ct.OutterBorderColor))
g.DrawPath(pen, pathOuter);
}
r.X--;
//r.Y--;
r.Y++;
r.Height -= 2;
g.SmoothingMode = sm;
if (e.GlassEnabled) glassBorderPainted = true;
}
}
//if (!e.GlassEnabled) // Fill painted only if Glass is not enabled
//{
Region oldClip = g.Clip;
g.SetClip(path, CombineMode.Intersect);
Rectangle top = new Rectangle(clip.X, clip.Y, clip.Width, (int)(r.Height * .2));
Rectangle bottom = new Rectangle(clip.X, top.Bottom, clip.Width, clip.Height - top.Height);
g.SmoothingMode = SmoothingMode.Default;
if (!e.GlassEnabled)
{
DisplayHelp.FillRectangle(g, top, ct.TopBackground);
DisplayHelp.FillRectangle(g, bottom, ct.BottomBackground);
}
else
{
if (!ct.GlassBorder.IsEmpty)
DisplayHelp.FillRectangle(g, clip, Color.FromArgb(64, Color.White));
}
g.SmoothingMode = sm;
clip.Height -= 2;
clip.Width += 2;
clip.Y++;
clip.X++;
g.SetClip(clip);
//if (!ct.InnerBorderColor.IsEmpty)
//{
// r.X--;
// path = GetQuickToolbarBackPath(r, rightToLeft, true);
// using (Pen pen = new Pen(ct.InnerBorderColor))
// g.DrawPath(pen, path);
// path.Dispose();
// r.X++;
//}
g.Clip = oldClip;
if (oldClip != null) oldClip.Dispose();
//}
if (!ct.MiddleBorderColor.IsEmpty && !(e.GlassEnabled && glassBorderPainted))
{
g.SmoothingMode = SmoothingMode.HighQuality;
path = GetQuickToolbarBackPath(r, rightToLeft);
using (Pen pen = new Pen(ct.MiddleBorderColor))
g.DrawPath(pen, path);
path.Dispose();
path = null;
g.SmoothingMode = sm;
}
}
if (path != null) path.Dispose();
}
private GraphicsPath GetQuickToolbarBackPath(Rectangle r, bool rightToLeft)
{
r.Offset(-1, 0);
r.Height--;
r.Width--;
if (r.Width < 2 || r.Height < 2) return null;
GraphicsPath path = new GraphicsPath();
int outdent = 11;
if (rightToLeft)
{
path.AddCurve(new Point[] { new Point(r.Right + outdent, r.Y), new Point(r.Right + 2, r.Y + 10), new Point(r.Right, r.Bottom) }, .6f);
path.AddLine(r.Right, r.Bottom, r.X, r.Bottom);
path.AddArc(r.X - (outdent + 1), r.Y, 20, r.Height, 90, 180);
path.AddLine(r.X, r.Y, r.Right + outdent, r.Y);
}
else
{
path.AddCurve(new Point[] { new Point(r.X - outdent, r.Y), new Point(r.X - 2, r.Y + 10), new Point(r.X, r.Bottom) }, .6f);
path.AddLine(r.X, r.Bottom, r.Right, r.Bottom);
path.AddArc(r.Right - (outdent + 1), r.Y, 20, r.Height, 90, -180);
path.AddLine(r.Right, r.Y, r.X - outdent, r.Y);
}
path.CloseAllFigures();
return path;
}
//private GraphicsPath GetQuickToolbarBackPath(Rectangle r, bool rightToLeft, bool arcOnly)
//{
// GraphicsPath path = new GraphicsPath();
// if (rightToLeft)
// {
// int arcSize = (int)(r.Height * .8);
// Rectangle arcRect = new Rectangle(r.X - r.Height / 2, r.Y, r.Width + r.Height / 2, r.Height);
// path.AddLine(arcRect.X, r.Bottom, arcRect.X, arcRect.Y + arcSize);
// ElementStyleDisplay.AddCornerArc(path, arcRect, arcSize, eCornerArc.TopLeft);
// if (!arcOnly)
// {
// path.AddLine(r.X, r.Y, r.Right, r.Y);
// path.AddLine(r.Right, r.Y, r.Right, r.Bottom);
// path.CloseAllFigures();
// }
// }
// else
// {
// if (!arcOnly)
// {
// path.AddLine(r.X, r.Bottom, r.X, r.Y);
// path.AddLine(r.X, r.Y, r.Right, r.Y);
// }
// Rectangle arcRect = new Rectangle(r.X, r.Y, r.Width + r.Height / 2, r.Height);
// int arcSize = (int)(r.Height * .8);
// ElementStyleDisplay.AddCornerArc(path, arcRect, arcSize, eCornerArc.TopRight);
// path.AddLine(arcRect.Right, arcRect.Y + arcSize, arcRect.Right, r.Bottom);
// if (!arcOnly) path.CloseAllFigures();
// }
// return path;
//}
#endregion
}
}

View File

@@ -0,0 +1,230 @@
using System;
using System.Text;
using DevComponents.DotNetBar.Rendering;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Runtime.InteropServices;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the Office 2007 Ribbon Tab Group painter.
/// </summary>
internal class Office2007RibbonTabGroupPainter : RibbonTabGroupPainter, IOffice2007Painter
{
#region Private Variables
private Office2007ColorTable m_ColorTable = null; //new Office2007ColorTable();
#endregion
#region Internal Implementation
protected virtual ThemeTextFormat GetThemeFormat()
{
ThemeTextFormat tf = ThemeTextFormat.Center | ThemeTextFormat.EndEllipsis | ThemeTextFormat.VCenter | ThemeTextFormat.SingleLine;
return tf;
}
protected virtual eTextFormat GetTextFormat()
{
return eTextFormat.VerticalCenter;
}
protected virtual Themes.RECT GetThemeTextBounds(Rectangle rect)
{
Themes.RECT bounds = new Themes.RECT(new Rectangle(0, 0, rect.Width, rect.Height));
return bounds;
}
protected virtual Rectangle GetTextBounds(RibbonTabGroupRendererEventArgs e)
{
return e.Bounds;
}
/// <summary>
/// Paints ribbon tab group.
/// </summary>
/// <param name="e">Context information</param>
public override void PaintTabGroup(RibbonTabGroupRendererEventArgs e)
{
Graphics g = e.Graphics;
Office2007RibbonTabGroupColorTable colorTable = GetColors(e.RibbonTabItemGroup);
if (colorTable == null)
return;
#if FRAMEWORK20
if (e.ItemPaintArgs.GlassEnabled)
{
if (e.ItemPaintArgs.CachedPaint) return;
PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, true);
Rectangle rect = e.Bounds;
rect.Height -= 2;
IntPtr hdc = g.GetHdc();
Font font = e.GroupFont;
string text = e.RibbonTabItemGroup.GroupTitle;
ThemeTextFormat tf = GetThemeFormat();
try
{
IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
try
{
WinApi.BITMAPINFO bmpInfo = new WinApi.BITMAPINFO();
bmpInfo.biWidth = rect.Width;
bmpInfo.biHeight = -rect.Height;
bmpInfo.biPlanes = 1;
bmpInfo.biBitCount = 32;
bmpInfo.biSize = Marshal.SizeOf(bmpInfo);
IntPtr dib = WinApi.CreateDIBSection(hdc, bmpInfo, 0, 0, IntPtr.Zero, 0);
WinApi.SelectObject(memdc, dib);
IntPtr fontHandle = font.ToHfont();
WinApi.SelectObject(memdc, fontHandle);
Themes.RECT bounds = GetThemeTextBounds(rect);
System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
dttOpts.iGlowSize = 10;
dttOpts.crText = new Themes.COLORREF(colorTable.Text);
dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
if (colorTable.Background == null || colorTable.Background.IsEmpty || colorTable.Background.Start.A < 255)
dttOpts.dwFlags |= (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE;
dttOpts.dwSize = Marshal.SizeOf(dttOpts);
// Draw Background
using (Graphics gb = Graphics.FromHdc(memdc))
{
PaintTabGroupBackground(gb, colorTable, new Rectangle(0, 0, rect.Width, rect.Height + 2), new Rectangle(0, 0, rect.Width, rect.Height + 2), true);
}
Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
const int SRCCOPY = 0x00CC0020;
WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);
WinApi.DeleteObject(fontHandle);
WinApi.DeleteObject(dib);
}
finally
{
WinApi.DeleteDC(memdc);
}
}
finally
{
g.ReleaseHdc(hdc);
}
return;
}
#endif
PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, false);
ElementStyle style = e.RibbonTabItemGroup.Style; //.Copy();
Color styleTextColor = style.TextColor;
Color styleTextShadowColor = style.TextShadowColor;
Point styleTextShadowOffset = style.TextShadowOffset;
style.FreezeEvents = true;
style.TextColor = colorTable.Text;
style.TextShadowColor = Color.Empty;
style.TextShadowOffset = Point.Empty;
ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, e.Graphics, GetTextBounds(e));
ElementStyleDisplay.PaintText(info, e.RibbonTabItemGroup.GroupTitle, e.GroupFont, false, e.RibbonTabItemGroup.Style.TextFormat | GetTextFormat());
style.TextColor = styleTextColor;
style.TextShadowColor = styleTextShadowColor;
style.TextShadowOffset = styleTextShadowOffset;
style.FreezeEvents = false;
}
protected virtual void PaintTabGroupBackground(Graphics g, Office2007RibbonTabGroupColorTable colorTable, Rectangle bounds, Rectangle groupBounds, bool glassEnabled)
{
if (colorTable == null)
return;
// Draw title rectangle part of the group
Rectangle r = bounds;
r.Height -= 2;
// GDI+ bug
Rectangle rFill = r;
rFill.Width--;
//rFill.Height--;
// First draw background
DisplayHelp.FillRectangle(g, rFill, colorTable.Background.Start, colorTable.Background.End, 90, new float[] { 0f, .10f, .9f }, new float[] { 0f, (glassEnabled?.4f:.70f), 1f });
// Draw highlight
if (!colorTable.BackgroundHighlight.IsEmpty && r.Width > 0 && r.Height > 0)
{
//Rectangle hr = new Rectangle(r.X, r.Bottom - 3, r.Width - 1, 3);
//DisplayHelp.FillRectangle(g, hr, colorTable.BackgroundHighlight.Start, colorTable.BackgroundHighlight.End);
Rectangle ellipse = new Rectangle(r.X - r.Width * 3, r.Y, r.Width * 7, (int)(r.Height * 4.5f));
GraphicsPath path = new GraphicsPath();
path.AddEllipse(ellipse);
PathGradientBrush brush = new PathGradientBrush(path);
brush.CenterColor = colorTable.BackgroundHighlight.Start;
brush.SurroundColors = new Color[] { colorTable.BackgroundHighlight.End };
brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, r.Bottom);
Blend blend = new Blend();
blend.Factors = new float[] { 0f, .05f, 1f };
blend.Positions = new float[] { .0f, .8f, 1f };
brush.Blend = blend;
path.Dispose();
//rFill.Height++;
g.FillRectangle(brush, rFill);
brush.Dispose();
path.Dispose();
}
// Underline highlight
using (Pen pen = new Pen(Color.FromArgb(64, System.Windows.Forms.ControlPaint.Dark(colorTable.BackgroundHighlight.Start))))
g.DrawLine(pen, r.X, r.Bottom, r.Right - 1, r.Bottom);
r = bounds;
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.Default;
Rectangle rAll = groupBounds;
if (!colorTable.Border.IsEmpty)
{
//using(SolidBrush brush=new SolidBrush(colorTable.Border.Start))
//{
// // Draw border top
// g.FillRectangle(brush, bounds.X, bounds.Y, bounds.Width, 4);
//}
// Draw border ... Left first
DisplayHelp.FillRectangle(g, new Rectangle(rAll.X, r.Y, 1, r.Height), colorTable.Border);
// Then right
DisplayHelp.FillRectangle(g, new Rectangle(rAll.Right - 1, r.Y, 1, r.Height), colorTable.Border);
// Draw borders on the bottom...
// Left first
DisplayHelp.FillRectangle(g, new Rectangle(rAll.X, r.Bottom - 1, 1, rAll.Height - r.Height), colorTable.Border.End, Color.Transparent, 90);
// Then right
DisplayHelp.FillRectangle(g, new Rectangle(rAll.Right - 1, r.Bottom - 1, 1, rAll.Height - r.Height), colorTable.Border.End, Color.Transparent, 90);
}
g.SmoothingMode = sm;
}
private Office2007RibbonTabGroupColorTable GetColors(RibbonTabItemGroup group)
{
Office2007RibbonTabGroupColorTable c = null;
if(group.CustomColorName!="")
c = m_ColorTable.RibbonTabGroupColors[group.CustomColorName];
if(c==null)
c = m_ColorTable.RibbonTabGroupColors[Enum.GetName(typeof(eRibbonTabGroupColor), group.Color)];
if (c == null && m_ColorTable.RibbonTabGroupColors.Count > 0)
c = m_ColorTable.RibbonTabGroupColors[0];
return c;
}
#endregion
#region IOffice2007Painter Members
public Office2007ColorTable ColorTable
{
get { return m_ColorTable; }
set { m_ColorTable = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,267 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
namespace DevComponents.DotNetBar
{
/// <summary>
/// RibbonTabItem painter for Office 2007 style
/// </summary>
internal class Office2007RibbonTabItemPainter : Office2007ButtonItemPainter
{
protected override Rectangle GetTextRectangle(ButtonItem button, ItemPaintArgs pa, eTextFormat stringFormat, CompositeImage image)
{
Rectangle r = base.GetTextRectangle(button, pa, stringFormat, image);
if (image == null && string.IsNullOrEmpty(button.SymbolRealized))
r.Inflate(-3, 0);
return r;
}
public override eTextFormat GetStringFormat(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
eTextFormat sf = base.GetStringFormat(button, pa, image);
sf &= ~(sf & eTextFormat.EndEllipsis);
return sf;
}
protected override void PaintState(ButtonItem button, ItemPaintArgs pa, CompositeImage image, Rectangle r, bool isMouseDown)
{
if (r.IsEmpty || !IsItemEnabled(button, pa) || r.Width == 0 || r.Height == 0)
return;
RibbonTabItem tab = button as RibbonTabItem;
if (tab == null || IsOnMenu(button, pa))
{
base.PaintState(button, pa, image, r, isMouseDown);
return;
}
bool isOnMenu = pa.IsOnMenu;
Office2007RibbonTabItemColorTable tabColorTable = GetColorTable(tab);
if (tabColorTable == null)
return;
bool ribbonExpanded = pa.ControlExpanded;
Office2007RibbonTabItemStateColorTable stateColors = GetStateColorTable(tabColorTable, tab, ribbonExpanded);
if (stateColors == null)
return;
Graphics g = pa.Graphics;
int cornerSize = tabColorTable.CornerSize;
Region oldClip = g.Clip;
try
{
Rectangle rClip = r;
rClip.Inflate(1, 0);
g.SetClip(rClip, CombineMode.Replace);
if (stateColors != null)
{
eDotNetBarStyle effectiveStyle = button.EffectiveStyle;
using (GraphicsPath path = GetTabPath(r, cornerSize, true, effectiveStyle))
{
DisplayHelp.FillPath(g, path, stateColors.Background);
DisplayHelp.DrawGradientPathBorder(g, path, stateColors.OuterBorder, 1);
}
if (!StyleManager.IsMetro(effectiveStyle) && tab.Checked && ribbonExpanded && tab.RenderTabState /*|| tab.IsMouseOver*/)
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.Default;
if (this.ColorTable.RibbonControl.TabsBackground.Start.GetBrightness() > .5 && !stateColors.OuterBorder.IsEmpty)
{
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(new Rectangle(r.Right - 1, r.Y + cornerSize + 1, 1, r.Height - cornerSize - 3));
DisplayHelp.FillPath(g, path, Color.FromArgb(96, stateColors.OuterBorder.Start), Color.FromArgb(32, stateColors.OuterBorder.End), 90);
}
using (GraphicsPath path = new GraphicsPath())
{
path.AddRectangle(new Rectangle(r.X + 1, r.Y + cornerSize + 1, 1, r.Height - cornerSize - 3));
DisplayHelp.FillPath(g, path, Color.FromArgb(32, stateColors.OuterBorder.Start), Color.FromArgb(8, stateColors.OuterBorder.End), 90);
}
}
g.SmoothingMode = sm;
}
Rectangle r1 = r;
r1.Inflate(-1, 0);
r1.Height--;
r1.Y++;
using (GraphicsPath path = GetTabPath(r1, cornerSize, true, effectiveStyle))
{
DisplayHelp.DrawGradientPathBorder(g, path, stateColors.InnerBorder, 1);
}
if (tab.Checked && ribbonExpanded && tab.RenderTabState)
{
using (SolidBrush brush = new SolidBrush(stateColors.InnerBorder.Start))
{
SmoothingMode sm = g.SmoothingMode;
g.SmoothingMode = SmoothingMode.None;
g.FillRectangle(brush, new Rectangle(r1.X + cornerSize, r1.Y + 1, r1.Width - cornerSize * 2, 2));
g.SmoothingMode = sm;
}
}
float topSplit = .6f;
float bottomSplit = .4f;
Rectangle fillRectangle = r;
Rectangle backRect = new Rectangle(fillRectangle.X, fillRectangle.Y + (int)(fillRectangle.Height * topSplit), fillRectangle.Width, (int)(fillRectangle.Height * bottomSplit));
if (!stateColors.BackgroundHighlight.IsEmpty)
{
Rectangle ellipse = new Rectangle(backRect.X, backRect.Y, fillRectangle.Width, fillRectangle.Height);
GraphicsPath path = new GraphicsPath();
path.AddEllipse(ellipse);
PathGradientBrush brush = new PathGradientBrush(path);
brush.CenterColor = stateColors.BackgroundHighlight.Start;
brush.SurroundColors = new Color[] { stateColors.BackgroundHighlight.End };
brush.CenterPoint = new PointF(ellipse.X + ellipse.Width / 2, fillRectangle.Bottom + 2);
Blend blend = new Blend();
blend.Factors = new float[] { 0f, .8f, 1f };
blend.Positions = new float[] { .0f, .55f, 1f };
brush.Blend = blend;
g.FillRectangle(brush, backRect);
brush.Dispose();
path.Dispose();
}
}
if (tab.ReducedSize && !tab.Checked && !tab.IsMouseOver && tabColorTable != null && tabColorTable.Selected != null)
{
Color c = this.ColorTable.RibbonControl.OuterBorder.Start;
if (!c.IsEmpty)
DisplayHelp.DrawGradientLine(g, new Point(r.Right - 1, r.Y), new Point(r.Right - 1, r.Bottom - 1),
Color.Transparent, c, 90, 1, new float[] { 0, .8f, 1f }, new float[] { 0, .50f, 1f });
}
g.Clip = oldClip;
}
finally
{
if (oldClip != null) oldClip.Dispose();
}
}
private GraphicsPath GetTabPath(Rectangle r, int cornerSize, bool getBottomPart, eDotNetBarStyle style)
{
GraphicsPath path = new GraphicsPath();
int bottomCorner = (style == eDotNetBarStyle.Windows7 || style == eDotNetBarStyle.Office2010) ? 1 : 2;
if (StyleManager.IsMetro(style)) bottomCorner = 0;
if (getBottomPart)
path.AddLine(r.X, r.Bottom, r.X + bottomCorner, r.Bottom - bottomCorner);
else
path.AddLine(r.X, r.Bottom, r.X, r.Y + cornerSize);
r.Inflate(-bottomCorner, 0);
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.TopLeft);
ElementStyleDisplay.AddCornerArc(path, r, cornerSize, eCornerArc.TopRight);
if (getBottomPart)
path.AddLine(r.Right, r.Bottom - bottomCorner, r.Right + bottomCorner, r.Bottom);
else
path.AddLine(r.Right, r.Y + cornerSize, r.Right, r.Bottom);
return path;
}
protected override Color GetTextColor(ButtonItem button, ItemPaintArgs pa)
{
if (!IsItemEnabled(button, pa) || !(button is RibbonTabItem))
return base.GetTextColor(button, pa);
RibbonTabItem tab = button as RibbonTabItem;
Color textColor = Color.Empty;
Office2007RibbonTabItemStateColorTable ct = GetStateColorTable(GetColorTable(tab), tab, pa.ControlExpanded);
if (ct != null)
{
if (pa.GlassEnabled && !ct.GlassText.IsEmpty)
return ct.GlassText;
textColor = ct.Text;
}
if (textColor.IsEmpty)
return base.GetTextColor(button, pa);
return textColor;
}
private Office2007RibbonTabItemColorTable GetColorTable(RibbonTabItem tab)
{
return GetColorTable(this.ColorTable, tab);
}
internal static Office2007RibbonTabItemColorTable GetColorTable(Office2007ColorTable table, RibbonTabItem tab)
{
if (table == null)
return null;
Office2007RibbonTabItemColorTable rt = table.RibbonTabItemColors[tab.GetColorTableName()];
if (rt == null && table.RibbonTabItemColors.Count > 0)
rt = table.RibbonTabItemColors[0];
return rt;
}
internal static Office2007RibbonTabItemColorTable GetColorTable(Office2007ColorTable table)
{
if (table == null)
return null;
Office2007RibbonTabItemColorTable rt = table.RibbonTabItemColors["Default"];
if (rt == null && table.RibbonTabItemColors.Count > 0)
rt = table.RibbonTabItemColors[0];
return rt;
}
internal static Office2007RibbonTabItemStateColorTable GetStateColorTable(Office2007RibbonTabItemColorTable tabColorTable, RibbonTabItem tab, bool ribbonExpanded)
{
if (tabColorTable == null)
return null;
Office2007RibbonTabItemStateColorTable stateColors = null;
if (!tab.RenderTabState)
stateColors = tabColorTable.Default;
else if (tab.Checked && tab.IsMouseOver && ribbonExpanded)
stateColors = tabColorTable.SelectedMouseOver;
else if (tab.Checked && ribbonExpanded)
stateColors = tabColorTable.Selected;
else if (tab.IsMouseOver)
stateColors = tabColorTable.MouseOver;
else if (tab.GetEnabled())
stateColors = tabColorTable.Default;
return stateColors;
}
#if FRAMEWORK20
public override void PaintButtonText(ButtonItem button, ItemPaintArgs pa, Color textColor, CompositeImage image)
{
eDotNetBarStyle effectiveStyle = button.EffectiveStyle;
if (!((effectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(effectiveStyle)) && pa.GlassEnabled))
{
base.PaintButtonText(button, pa, textColor, image);
return;
}
Rectangle r = GetTextRectangle(button, pa, eTextFormat.HorizontalCenter | eTextFormat.VerticalCenter, image);
//r.Offset(0, 3);
//r.Height -= 2;
ThemeTextFormat textFormat = ThemeTextFormat.Center | ThemeTextFormat.VCenter | ThemeTextFormat.HidePrefix | ThemeTextFormat.SingleLine;
bool renderGlow = true;
//if (effectiveStyle == eDotNetBarStyle.Office2010 && StyleManager.Style == eStyle.Office2010Black)
// renderGlow = false;
Office2007RibbonControlPainter.PaintTextOnGlass(pa.Graphics, button.Text, pa.Font, r, textFormat, textColor, true, renderGlow, 10);
}
#endif
}
}

View File

@@ -0,0 +1,412 @@
using System.Windows.Forms;
using System;
using DevComponents.DotNetBar.Rendering;
using DevComponents.DotNetBar.Metro.Rendering;
using DevComponents.DotNetBar.Controls;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for PainterFactory.
/// </summary>
internal class PainterFactory
{
private static Office2003ButtonItemPainter m_Office2003Painter=new Office2003ButtonItemPainter();
private static Office2007ButtonItemPainter m_Office2007Painter = new Office2007ButtonItemPainter();
private static MetroButtonItemPainter m_MetroButtonPainter = new MetroButtonItemPainter();
private static Office2003RibbonTabItemPainter m_RibbonTabItemOffice2003Painter=new Office2003RibbonTabItemPainter();
private static Office2007ItemContainerPainter m_Office2007ItemContainerPainter = new Office2007ItemContainerPainter();
private static Office2007BarBackgroundPainter m_Office2007BarBackgroundPainter = new Office2007BarBackgroundPainter();
private static Office2007KeyTipsPainter m_Office2007KeyTipsPainter = new Office2007KeyTipsPainter();
private static Office2007DialogLauncherPainter m_Office2007RibbonBarPainter = new Office2007DialogLauncherPainter();
private static Office2007RibbonControlPainter m_Office2007RibbonControlPainter = new Office2007RibbonControlPainter();
private static Office2007RibbonTabItemPainter m_Office2007RibbonTabItemPainter = new Office2007RibbonTabItemPainter();
//private static Office2007RibbonTabGroupPainter m_Office2007RibbonTabGroupPainter = new Office2007RibbonTabGroupPainter();
private static Rendering.Office2007ColorItemPainter m_Office2007ColorItemPainter = new Rendering.Office2007ColorItemPainter();
private static Office2007SystemCaptionItemPainter m_Office2007SystemCaptionItemPainter = null;
private static Office2007MdiSystemItemPainter m_Office2007MdiSystemItemPainter = new Office2007MdiSystemItemPainter();
private static Office2007FormCaptionPainter m_Office2007FormCaptionPainter = new Office2007FormCaptionPainter();
private static Rendering.Office2007RibbonOverflowPainter m_Office2007RibbonOverflowPainter = new DevComponents.DotNetBar.Rendering.Office2007RibbonOverflowPainter();
private static Rendering.Office2007QatOverflowPainter m_Office2007QatOverflowPainter = new DevComponents.DotNetBar.Rendering.Office2007QatOverflowPainter();
private static Rendering.Office2007QatCustomizeItemPainter m_Office2007QatCustomizePainter = new DevComponents.DotNetBar.Rendering.Office2007QatCustomizeItemPainter();
private static Rendering.Office2007CheckBoxItemPainter m_Office2007CheckBoxItemPainter = new Rendering.Office2007CheckBoxItemPainter();
private static Rendering.Office2007ProgressBarItemPainter m_Office2007ProgressBarPainter = new DevComponents.DotNetBar.Rendering.Office2007ProgressBarItemPainter();
private static Rendering.Office2007NavigationPanePainter m_Office2007NavPanePainter = new DevComponents.DotNetBar.Rendering.Office2007NavigationPanePainter();
private static Rendering.SliderPainter m_SliderPainter = new DevComponents.DotNetBar.Rendering.Office2007SliderPainter();
private static Rendering.SideBarPainter m_SideBarPainter = new DevComponents.DotNetBar.Rendering.Office2007SideBarPainter();
private static CrumbBarItemViewPainter m_CrumbBarItemViewPainter = null;
private static SwitchButtonPainter m_SwitchButtonPainter = null;
private static Office2010NavPaneButtonPainter _Office2010NavPaneButtonPainter = new Office2010NavPaneButtonPainter();
private static Rendering.RangeSliderPainter _RangeSliderPainter = new DevComponents.DotNetBar.Rendering.Office2010RangeSliderPainter();
public static ButtonItemPainter CreateButtonPainter(ButtonItem button)
{
if (button is RibbonTabItem)
{
return CreateRibbonTabItemPainter((RibbonTabItem)button);
}
if (button is TabFormItem)
{
return CreateTabFormItemPainter((TabFormItem)button);
}
else if (button is NewTabFormItem)
{
return CreateNewTabFormItemPainter((NewTabFormItem)button);
}
if (button is RibbonOverflowButtonItem)
{
ButtonItemPainter p = CreateRibbonOverflowButtonPainter((RibbonOverflowButtonItem)button);
if (p != null)
return p;
}
eDotNetBarStyle buttonEffectiveStyle = button.EffectiveStyle;
if (buttonEffectiveStyle == eDotNetBarStyle.Office2010 && button.ContainerState == eContainerState.NavigationPane)
{
return _Office2010NavPaneButtonPainter;
}
if (buttonEffectiveStyle == eDotNetBarStyle.Office2010 && button is ApplicationButton)
return Office2010ApplicationButtonPainter;
else if (button is DevComponents.DotNetBar.Metro.MetroAppButton || button is ApplicationButton && StyleManager.IsMetro(buttonEffectiveStyle))
return MetroAppButtonPainter;
if (BarFunctions.IsOffice2007Style(buttonEffectiveStyle))
{
if (StyleManager.IsMetro(buttonEffectiveStyle))
return m_MetroButtonPainter;
if (button.ContainerControl is RibbonBar)
return m_Office2007Painter;
return m_Office2007Painter;
}
return m_Office2003Painter;
}
private static ButtonItemPainter _Office2010ApplicationButtonPainter;
public static ButtonItemPainter Office2010ApplicationButtonPainter
{
get
{
if (_Office2010ApplicationButtonPainter == null) _Office2010ApplicationButtonPainter = new Office2010AppButtonPainter();
return _Office2010ApplicationButtonPainter;
}
}
private static ButtonItemPainter _MetroAppButtonPainter;
public static ButtonItemPainter MetroAppButtonPainter
{
get
{
if (_MetroAppButtonPainter == null) _MetroAppButtonPainter = new DevComponents.DotNetBar.Metro.Rendering.MetroAppButtonPainter();
return _MetroAppButtonPainter;
}
}
public static CrumbBarItemViewPainter GetCrumbBarItemViewPainter(ButtonItem button)
{
if (m_CrumbBarItemViewPainter == null)
m_CrumbBarItemViewPainter = new CrumbBarItemViewPainter();
return m_CrumbBarItemViewPainter;
}
public static ButtonItemPainter CreateRibbonOverflowButtonPainter(RibbonOverflowButtonItem button)
{
if (BarFunctions.IsOffice2007Style(button.EffectiveStyle))
return m_Office2007RibbonOverflowPainter;
return null;
}
public static ButtonItemPainter CreateRibbonTabItemPainter(RibbonTabItem tab)
{
if (BarFunctions.IsOffice2007Style(tab.EffectiveStyle) && !tab.IsOnMenu)
{
return m_Office2007RibbonTabItemPainter;
}
if ((tab.EffectiveStyle == eDotNetBarStyle.Office2003 || tab.EffectiveStyle == eDotNetBarStyle.VS2005) && !tab.IsOnMenu)
{
return m_RibbonTabItemOffice2003Painter;
}
return m_Office2003Painter;
}
private static OfficeTabFormItemPainter _TabFormItemPainter=new OfficeTabFormItemPainter();
public static ButtonItemPainter CreateTabFormItemPainter(TabFormItem tab)
{
return _TabFormItemPainter;
}
private static OfficeNewTabFormItemPainter _NewTabFormItemPainter = new OfficeNewTabFormItemPainter();
public static ButtonItemPainter CreateNewTabFormItemPainter(NewTabFormItem tab)
{
return _NewTabFormItemPainter;
}
public static ItemContainerPainter CreateItemContainerPainter(ItemContainer container)
{
if (BarFunctions.IsOffice2007Style(container.EffectiveStyle))
return m_Office2007ItemContainerPainter;
return null;
}
public static BarBackgroundPainter CreateBarBackgroundPainter(Bar bar)
{
return m_Office2007BarBackgroundPainter;
}
public static KeyTipsPainter CreateKeyTipsPainter()
{
if (StyleManager.IsMetro(StyleManager.Style))
return MetroKeyTipsPainter;
else
return m_Office2007KeyTipsPainter;
}
private static MetroKeyTipsPainter _MetroKeyTipsPainter = null;
private static MetroKeyTipsPainter MetroKeyTipsPainter
{
get
{
if (_MetroKeyTipsPainter == null) _MetroKeyTipsPainter = new MetroKeyTipsPainter();
return _MetroKeyTipsPainter;
}
}
public static DialogLauncherPainter CreateRibbonBarPainter(RibbonBar ribbon)
{
if (BarFunctions.IsOffice2007Style(ribbon.EffectiveStyle))
return m_Office2007RibbonBarPainter;
return null;
}
private static RibbonTabGroupPainter _Office2010RibbonTabGroupPainter = null;
private static RibbonTabGroupPainter Office2010RibbonTabGroupPainter
{
get
{
if (_Office2010RibbonTabGroupPainter == null) _Office2010RibbonTabGroupPainter = new Office2010RibbonTabGroupPainter();
return _Office2010RibbonTabGroupPainter;
}
}
private static RibbonTabGroupPainter _Office2007RibbonTabGroupPainter = null;
private static RibbonTabGroupPainter Office2007RibbonTabGroupPainter
{
get
{
if (_Office2007RibbonTabGroupPainter == null) _Office2007RibbonTabGroupPainter = new Office2007RibbonTabGroupPainter();
return _Office2007RibbonTabGroupPainter;
}
}
private static RibbonTabGroupPainter _MetroRibbonTabGroupPainter = null;
private static RibbonTabGroupPainter MetroRibbonTabGroupPainter
{
get
{
if (_MetroRibbonTabGroupPainter == null) _MetroRibbonTabGroupPainter = new MetroRibbonTabGroupPainter();
return _MetroRibbonTabGroupPainter;
}
}
public static RibbonTabGroupPainter CreateRibbonTabGroupPainter(eDotNetBarStyle style)
{
if (style == eDotNetBarStyle.Office2010)
return Office2010RibbonTabGroupPainter;
else if (StyleManager.IsMetro(style))
return MetroRibbonTabGroupPainter;
else
return Office2007RibbonTabGroupPainter;
}
public static Rendering.ColorItemPainter CreateColorItemPainter(ColorItem item)
{
return m_Office2007ColorItemPainter;
}
public static RibbonControlPainter CreateRibbonControlPainter(RibbonControl r)
{
if (BarFunctions.IsOffice2007Style(r.EffectiveStyle))
return m_Office2007RibbonControlPainter;
return null;
}
private static SystemCaptionItemPainter _MetroCaptionItemPainter = null;
private static SystemCaptionItemPainter MetroCaptionItemPainter
{
get
{
if (_MetroCaptionItemPainter == null) _MetroCaptionItemPainter = new DevComponents.DotNetBar.Metro.Rendering.MetroCaptionItemPainter();
return _MetroCaptionItemPainter;
}
}
private static Office2010SystemCaptionItemPainter _Office2010SystemCaptionItemPainter=null;
private static SystemCaptionItemPainter Office2010SystemCaptionItemPainter
{
get
{
if (_Office2010SystemCaptionItemPainter == null) _Office2010SystemCaptionItemPainter = new Office2010SystemCaptionItemPainter();
return _Office2010SystemCaptionItemPainter;
}
}
private static Office2007SystemCaptionItemPainter _Office2007SystemCaptionItemPainter = null;
private static SystemCaptionItemPainter Office2007SystemCaptionItemPainter
{
get
{
if (_Office2007SystemCaptionItemPainter == null) _Office2007SystemCaptionItemPainter = new Office2007SystemCaptionItemPainter();
return _Office2007SystemCaptionItemPainter;
}
}
public static SystemCaptionItemPainter CreateSystemCaptionItemPainter(SystemCaptionItem item)
{
eDotNetBarStyle effectiveStyle = item.EffectiveStyle;
if (effectiveStyle == eDotNetBarStyle.Office2010)
return Office2010SystemCaptionItemPainter;
if (StyleManager.IsMetro(effectiveStyle))
return MetroCaptionItemPainter;
if (BarFunctions.IsOffice2007Style(effectiveStyle))
return Office2007SystemCaptionItemPainter;
return null;
}
public static MdiSystemItemPainter CreateMdiSystemItemPainter(MDISystemItem mdiSystemItem)
{
if (BarFunctions.IsOffice2007Style(mdiSystemItem.EffectiveStyle))
return m_Office2007MdiSystemItemPainter;
return null;
}
public static FormCaptionPainter CreateFormCaptionPainter(Form form)
{
return m_Office2007FormCaptionPainter;
}
public static DevComponents.DotNetBar.Rendering.QatOverflowPainter CreateQatOverflowItemPainter(QatOverflowItem ribbonQatOverflowItem)
{
return m_Office2007QatOverflowPainter;
}
public static DevComponents.DotNetBar.Rendering.QatCustomizeItemPainter CreateQatCustomizeItemPainter(QatCustomizeItem qatCustomizeItem)
{
return m_Office2007QatCustomizePainter;
}
public static Rendering.Office2007CheckBoxItemPainter CreateCheckBoxItemPainter(CheckBoxItem item)
{
return m_Office2007CheckBoxItemPainter;
}
/// <summary>
/// Forces the creation of the objects inside of factory.
/// </summary>
public static void InitFactory() { }
public static DevComponents.DotNetBar.Rendering.ProgressBarItemPainter CreateProgressBarItemPainter(ProgressBarItem progressBarItem)
{
return m_Office2007ProgressBarPainter;
}
internal static DevComponents.DotNetBar.Rendering.NavigationPanePainter CreateNavigationPanePainter()
{
return m_Office2007NavPanePainter;
}
internal static DevComponents.DotNetBar.Rendering.SliderPainter CreateSliderPainter(SliderItem slider)
{
return m_SliderPainter;
}
internal static DevComponents.DotNetBar.Rendering.RangeSliderPainter CreateRangeSliderPainter(RangeSliderItem slider)
{
return _RangeSliderPainter;
}
internal static DevComponents.DotNetBar.Rendering.SideBarPainter CreateSideBarPainter()
{
return m_SideBarPainter;
}
private static MetroSwitchButtonPainter _MetroSwitchPainter = null;
internal static SwitchButtonPainter CreateSwitchButtonPainter(SwitchButtonItem item)
{
if (StyleManager.IsMetro(item.EffectiveStyle))
{
if (_MetroSwitchPainter == null) _MetroSwitchPainter = new MetroSwitchButtonPainter();
return _MetroSwitchPainter;
}
else
{
if (m_SwitchButtonPainter == null)
m_SwitchButtonPainter = new Office2010SwitchButtonPainter();
}
return m_SwitchButtonPainter;
}
//private static MetroStepItemPainter _MetroStepItemPainter = null;
private static OfficeStepItemPainter _OfficeStepItemPainter = null;
internal static StepItemPainter CreateStepItemPainter(StepItem item)
{
//if (StyleManager.IsMetro(item.EffectiveStyle))
//{
// if (_MetroStepItemPainter == null) _MetroStepItemPainter = new MetroStepItemPainter();
// return _MetroStepItemPainter;
//}
//else
//{
if (_OfficeStepItemPainter == null)
_OfficeStepItemPainter = new OfficeStepItemPainter();
//}
return _OfficeStepItemPainter;
}
private static OfficeListBoxItemPainter _OfficeListBoxPainter = null;
internal static OfficeListBoxItemPainter CreateListBoxItemPainter(ListBoxItem item)
{
//if (StyleManager.IsMetro(item.EffectiveStyle))
//{
// if (_MetroStepItemPainter == null) _MetroStepItemPainter = new MetroStepItemPainter();
// return _MetroStepItemPainter;
//}
//else
//{
if (_OfficeListBoxPainter == null)
{
_OfficeListBoxPainter = new OfficeListBoxItemPainter();
_OfficeListBoxPainter.CheckBoxPainter = m_Office2007CheckBoxItemPainter;
}
//}
return _OfficeListBoxPainter;
}
private static OfficeSideNavItemPainter _OfficeSideNavItemPainter = null;
internal static OfficeSideNavItemPainter CreateSideNavItemPainter(SideNavItem item)
{
//if (StyleManager.IsMetro(item.EffectiveStyle))
//{
// if (_MetroStepItemPainter == null) _MetroStepItemPainter = new MetroStepItemPainter();
// return _MetroStepItemPainter;
//}
//else
//{
if (_OfficeSideNavItemPainter == null)
{
_OfficeSideNavItemPainter = new OfficeSideNavItemPainter();
}
//}
return _OfficeSideNavItemPainter;
}
private static TabFormStripPainter _TabFormStripPainter = null;
internal static TabFormStripPainter CreateTabFormStripPainter(TabFormStripControl c)
{
if(_TabFormStripPainter==null)
_TabFormStripPainter=new OfficeTabFormStripPainter();
return _TabFormStripPainter;
}
private static TabFormPainter _TabFormPainter=new OfficeTabFormPainter();
internal static TabFormPainter CreateTabFormPainter(TabParentForm form)
{
return _TabFormPainter;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,131 @@
using System;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar.Metro;
namespace DevComponents.DotNetBar.Ribbon
{
public class QatCustomizeDialog : DevComponents.DotNetBar.OfficeForm
{
private QatCustomizePanel qatCustomizePanel1;
internal ButtonX buttonOK;
internal ButtonX buttonCancel;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.qatCustomizePanel1 = new DevComponents.DotNetBar.Ribbon.QatCustomizePanel();
this.buttonOK = new DevComponents.DotNetBar.ButtonX();
this.buttonCancel = new DevComponents.DotNetBar.ButtonX();
this.SuspendLayout();
//
// qatCustomizePanel1
//
this.qatCustomizePanel1.BackColor = System.Drawing.Color.Transparent;
this.qatCustomizePanel1.Location = new System.Drawing.Point(0, 0);
this.qatCustomizePanel1.Name = "qatCustomizePanel1";
this.qatCustomizePanel1.Size = new System.Drawing.Size(444, 298);
this.qatCustomizePanel1.TabIndex = 0;
//
// buttonOK
//
this.buttonOK.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.buttonOK.DialogResult = System.Windows.Forms.DialogResult.OK;
this.buttonOK.Location = new System.Drawing.Point(285, 297);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(73, 21);
this.buttonOK.TabIndex = 1;
this.buttonOK.Text = "OK";
//
// buttonCancel
//
this.buttonCancel.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(364, 297);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(73, 21);
this.buttonCancel.TabIndex = 2;
this.buttonCancel.Text = "Cancel";
//
// QatCustomizeDialog
//
this.ClientSize = new System.Drawing.Size(445, 324);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.qatCustomizePanel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowInTaskbar = false;
this.Name = "QatCustomizeDialog";
this.Text = "Customize";
this.ResumeLayout(false);
}
#endregion
public QatCustomizeDialog()
{
InitializeComponent();
this.EnableGlass = false;
//if (System.Environment.OSVersion.Version.Major >= 6)
//{
// this.ClientSize = new Size(this.ClientSize.Width + 10, this.ClientSize.Height + 10);
//}
}
/// <summary>
/// Loads the items for the customization into the ribbon control. All Ribbon Bars on the ribbon are enumerated and items
/// are added if they have CanCustomize=true.
/// </summary>
/// <param name="rc">Ribbon control to enumerate.</param>
public void LoadItems(RibbonControl rc)
{
qatCustomizePanel1.LoadItems(rc);
}
/// <summary>
/// Loads the items for the customization from MetroTab control. Registered MetroToolbar controls are enumerated and items
/// are added if they have CanCustomize=true.
/// </summary>
/// <param name="tab">MetroTab control that holds references to known MetroToolbars.</param>
public void LoadItems(MetroShell tab)
{
qatCustomizePanel1.LoadItems(tab);
}
/// <summary>
/// Gets reference to the internal Quick Access Toolbar Customization panel.
/// </summary>
public QatCustomizePanel QatCustomizePanel
{
get { return qatCustomizePanel1; }
}
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,466 @@
using System;
using System.Text;
using System.ComponentModel;
using DevComponents.DotNetBar.Ribbon;
using DevComponents.DotNetBar.Rendering;
using DevComponents.DotNetBar.Metro;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the item that provides Quick Access Toolbar customization.
/// </summary>
public class QatCustomizeItem : CustomizeItem
{
#region Private Variables
//private bool m_SetupComplete = false;
private const string DefaultTooltipText = "Customize Quick Access Toolbar";
private const int FIXED_SIZE = 14;
#endregion
#region Internal Implementation
/// <summary>
/// Creates new instance of CustomizeItem object.
/// </summary>
public QatCustomizeItem():base()
{
this.Tooltip = DefaultTooltipText;
}
/// <summary>
/// Returns copy of CustomizeItem item
/// </summary>
public override BaseItem Copy()
{
QatCustomizeItem objCopy = new QatCustomizeItem();
this.CopyToItem(objCopy);
return objCopy;
}
public override void Paint(ItemPaintArgs p)
{
Rendering.BaseRenderer renderer = p.Renderer;
if (renderer != null)
{
renderer.DrawQatCustomizeItem(new QatCustomizeItemRendererEventArgs(this, p.Graphics));
return;
}
else
{
Rendering.QatCustomizeItemPainter painter = PainterFactory.CreateQatCustomizeItemPainter(this);
if (painter != null)
{
painter.Paint(new QatCustomizeItemRendererEventArgs(this, p.Graphics));
return;
}
}
base.Paint(p);
}
private bool QatContainsItem(RibbonControl rc, string itemName)
{
if (rc.QuickToolbarItems.Contains(itemName))
return true;
if(this.Parent is QatOverflowItem && this.Parent.SubItems.Contains(itemName))
return true;
return false;
}
private bool QatContainsItem(MetroShell tab, string itemName)
{
if (tab.QuickToolbarItems.Contains(itemName))
return true;
if (this.Parent is QatOverflowItem && this.Parent.SubItems.Contains(itemName))
return true;
return false;
}
protected override void SetupCustomizeItem()
{
if (this.GetRibbonControl() != null)
SetupRibbonCustomizeItem();
else if (this.GetMetroTab() != null)
SetupMetroTabCustomizeItem();
}
private void SetupMetroTabCustomizeItem()
{
this.SubItems.Clear();
// Add customize items...
string qatCustomize = "&Customize Quick Access Toolbar...";
MetroShell tab = GetMetroTab();
if (tab != null)
{
qatCustomize = tab.SystemText.QatCustomizeText;
this.PopupFont = tab.Font;
}
SubItemsCollection qatFrequentCommands = tab.QatFrequentCommands;
string s = "<b>Customize Quick Access Toolbar</b>";
if (tab != null)
s = tab.SystemText.QatCustomizeMenuLabel;
LabelItem label = new LabelItem(RibbonControl.SysQatCustomizeLabelName, s);
label.PaddingBottom = 2;
label.PaddingTop = 2;
label.PaddingLeft = 12;
label.BorderSide = eBorderSide.Bottom;
label.BorderType = eBorderType.SingleLine;
label.CanCustomize = false;
if (GlobalManager.Renderer is Office2007Renderer)
{
label.BackColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelBackground;
label.ForeColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelText;
}
this.SubItems.Add(label);
bool beginGroup = false;
if (qatFrequentCommands.Count > 0)
{
beginGroup = true;
foreach (BaseItem qatFC in qatFrequentCommands)
{
if (qatFC.Text.Length > 0)
{
ButtonItem bf = new ButtonItem(RibbonControl.SysFrequentlyQatNamePart + qatFC.Name, qatFC.Text);
if (QatContainsItem(tab, qatFC.Name))
bf.Checked = true;
bf.CanCustomize = false;
this.SubItems.Add(bf);
bf.Click += new EventHandler(AddFrequentCommandToQat);
bf.Tag = qatFC.Name;
}
}
}
ButtonItem item = new ButtonItem(RibbonControl.SysQatCustomizeItemName, qatCustomize);
item.BeginGroup = beginGroup;
item.CanCustomize = false;
this.SubItems.Add(item);
item.Click += new EventHandler(QatCustomizeItemClick);
//if (tab != null && tab.EnableQatPlacement)
//{
// ButtonItem b = new ButtonItem(RibbonControl.SysQatPlaceItemName);
// b.CanCustomize = false;
// //if (tab.QatPositionedBelowRibbon)
// // b.Text = tab.SystemText.QatPlaceAboveRibbonText;
// //else
// b.Text = tab.SystemText.QatPlaceBelowRibbonText;
// b.Click += new EventHandler(QuickAccessToolbarChangePlacement);
// this.SubItems.Add(b);
//}
//if (tab != null)
//{
// ButtonItem b = null;
// if (tab.Expanded)
// b = new ButtonItem(RibbonControl.SysMinimizeRibbon, tab.SystemText.MinimizeRibbonText);
// else
// b = new ButtonItem(RibbonControl.SysMaximizeRibbon, tab.SystemText.MaximizeRibbonText);
// b.CanCustomize = false;
// b.BeginGroup = true;
// b.Click += new EventHandler(ToggleRibbonExpand);
// this.SubItems.Add(b);
//}
}
private MetroShell GetMetroTab()
{
MetroTabStrip strip = this.ContainerControl as MetroTabStrip;
if (strip == null)
{
BaseItem parent = this;
while (parent != null && strip == null)
{
parent = parent.Parent;
if (parent != null)
{
strip = parent.ContainerControl as MetroTabStrip;
}
}
}
MetroShell tab = null;
if (strip != null) tab = strip.Parent as MetroShell;
return tab;
}
private void SetupRibbonCustomizeItem()
{
this.SubItems.Clear();
// Add customize items...
string qatCustomize = "&Customize Quick Access Toolbar...";
RibbonControl rc = GetRibbonControl();
if (rc != null)
qatCustomize = rc.SystemText.QatCustomizeText;
SubItemsCollection qatFrequentCommands = rc.QatFrequentCommands;
string s = "<b>Customize Quick Access Toolbar</b>";
if (rc != null)
s = rc.SystemText.QatCustomizeMenuLabel;
LabelItem label = new LabelItem(RibbonControl.SysQatCustomizeLabelName, s);
label.PaddingBottom = 2;
label.PaddingTop = 2;
label.PaddingLeft = 12;
label.BorderSide = eBorderSide.Bottom;
label.BorderType = eBorderType.SingleLine;
label.CanCustomize = false;
if (GlobalManager.Renderer is Office2007Renderer)
{
label.BackColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelBackground;
label.ForeColor = ((Office2007Renderer)GlobalManager.Renderer).ColorTable.QuickAccessToolbar.QatCustomizeMenuLabelText;
}
this.SubItems.Add(label);
bool beginGroup = false;
if (qatFrequentCommands.Count > 0)
{
beginGroup = true;
foreach (BaseItem qatFC in qatFrequentCommands)
{
if (qatFC.Text.Length > 0)
{
ButtonItem bf = new ButtonItem(RibbonControl.SysFrequentlyQatNamePart + qatFC.Name, qatFC.Text);
if (QatContainsItem(rc, qatFC.Name))
bf.Checked = true;
bf.CanCustomize = false;
this.SubItems.Add(bf);
bf.Click += new EventHandler(AddFrequentCommandToQat);
bf.Tag = qatFC.Name;
}
}
}
ButtonItem item = new ButtonItem(RibbonControl.SysQatCustomizeItemName, qatCustomize);
item.BeginGroup = beginGroup;
item.CanCustomize = false;
this.SubItems.Add(item);
item.Click += new EventHandler(QatCustomizeItemClick);
if (rc != null && rc.EnableQatPlacement)
{
ButtonItem b = new ButtonItem(RibbonControl.SysQatPlaceItemName);
b.CanCustomize = false;
if (rc.QatPositionedBelowRibbon)
b.Text = rc.SystemText.QatPlaceAboveRibbonText;
else
b.Text = rc.SystemText.QatPlaceBelowRibbonText;
b.Click += new EventHandler(QuickAccessToolbarChangePlacement);
this.SubItems.Add(b);
}
if (rc != null)
{
ButtonItem b = null;
if (rc.Expanded)
b = new ButtonItem(RibbonControl.SysMinimizeRibbon, rc.SystemText.MinimizeRibbonText);
else
b = new ButtonItem(RibbonControl.SysMaximizeRibbon, rc.SystemText.MaximizeRibbonText);
b.CanCustomize = false;
b.BeginGroup = true;
b.Click += new EventHandler(ToggleRibbonExpand);
this.SubItems.Add(b);
}
}
private void AddFrequentCommandToQat(object sender, EventArgs e)
{
RibbonControl rc = GetRibbonControl();
if (rc==null) return;
CollapseAll(this);
rc.RibbonStrip.ClosePopups();
ButtonItem b = sender as ButtonItem;
if (b != null && b.Tag is string && b.Tag.ToString().Length > 0)
{
if (b.Checked)
{
// Remove from QAT
rc.RemoveItemFromQuickAccessToolbar(rc.QuickToolbarItems[b.Tag.ToString()]);
}
else
{
// Add to QAT
rc.AddItemToQuickAccessToolbar(rc.QatFrequentCommands[b.Tag.ToString()]);
}
}
}
private void ToggleRibbonExpand(object sender, EventArgs e)
{
CollapseAll(this);
ButtonItem b = sender as ButtonItem;
if(b==null) return;
RibbonControl rc = GetRibbonControl();
if (rc == null) return;
rc.RibbonStrip.ClosePopups();
if (b.Name == RibbonControl.SysMinimizeRibbon)
rc.Expanded = false;
else if (b.Name == RibbonControl.SysMaximizeRibbon)
rc.Expanded = true;
}
private void QuickAccessToolbarChangePlacement(object sender, EventArgs e)
{
CollapseAll(this);
RibbonControl rc = GetRibbonControl();
if (rc != null)
{
rc.RibbonStrip.ClosePopups();
rc.QuickAccessToolbarChangePlacement();
}
}
private void QatCustomizeItemClick(object sender, EventArgs e)
{
if (GetRibbonControl() != null)
QatCustomizeItemClickRibbon();
else if (GetMetroTab() != null)
QatCustomizeItemClickMetroTab();
}
private void QatCustomizeItemClickMetroTab()
{
MetroShell tab = GetMetroTab();
CollapseAll(this);
if (tab != null)
{
tab.MetroTabStrip.ClosePopups();
tab.ShowQatCustomizeDialog();
}
}
private void QatCustomizeItemClickRibbon()
{
RibbonControl rc = GetRibbonControl();
CollapseAll(this);
if (rc != null)
{
rc.RibbonStrip.ClosePopups();
rc.ShowQatCustomizeDialog();
}
}
private RibbonControl GetRibbonControl()
{
RibbonStrip strip = this.ContainerControl as RibbonStrip;
if (strip == null)
{
BaseItem parent = this;
while (parent != null && strip == null)
{
parent = parent.Parent;
if (parent != null)
{
if (parent.ContainerControl is QatToolbar)
{
QatToolbar qat = parent.ContainerControl as QatToolbar;
if (qat.Parent is RibbonControl)
{
strip = ((RibbonControl)qat.Parent).RibbonStrip;
break;
}
}
else
strip = parent.ContainerControl as RibbonStrip;
}
}
}
RibbonControl rc = null;
if (strip != null) rc = strip.Parent as RibbonControl;
Ribbon.QatToolbar qatToolbar = this.ContainerControl as Ribbon.QatToolbar;
if (qatToolbar != null && qatToolbar.Parent is RibbonControl)
return qatToolbar.Parent as RibbonControl;
return rc;
}
protected override void ClearCustomizeItem()
{
// Nothing to do leave all items as they are
}
protected override void LoadResources() {}
//protected override void SetCustomTooltip(string text) {}
/// <summary>
/// Gets or sets whether Customize menu item is visible.
/// </summary>
[Browsable(false), DevCoBrowsable(false), Category("Behavior"), Description("Indicates whether Customize menu item is visible."), DefaultValue(true), EditorBrowsable(EditorBrowsableState.Never)]
public override bool CustomizeItemVisible
{
get { return base.CustomizeItemVisible; }
set { base.CustomizeItemVisible = value; }
}
/// <summary>
/// Gets/Sets informational text (tooltip) for the item.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(QatCustomizeItem.DefaultTooltipText), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("Indicates the text that is displayed when mouse hovers over the item."), Localizable(true)]
public override string Tooltip
{
get { return base.Tooltip; }
set { base.Tooltip = value; }
}
protected internal override void OnExpandChange()
{
this.PopupSide = ePopupSide.Bottom;
base.OnExpandChange();
}
/// <summary>
/// Overridden. Recalculates the size of the item.
/// </summary>
public override void RecalcSize()
{
if (this.SuspendLayout)
return;
if (m_Orientation == eOrientation.Vertical)
{
// Take suggested width
m_Rect.Height = Dpi.Height(FIXED_SIZE);
m_Rect.Width = Dpi.Width22;
}
else
{
// Take suggested height
m_Rect.Width = Dpi.Width(FIXED_SIZE);
m_Rect.Height = Dpi.Height22;
}
SetCustomTooltip(GetTooltipText());
}
/// <summary>
/// Gets localized tooltip text for this instance of the item.
/// </summary>
/// <returns>Tooltip text.</returns>
protected override string GetTooltipText()
{
string s = "";
using (LocalizationManager lm = new LocalizationManager(this.GetOwner() as IOwnerLocalize))
s = lm.GetLocalizedString(LocalizationKeys.QatCustomizeTooltip);
if (s == "") s = this.Tooltip;
return s;
}
/// <summary>
/// Called when mouse hovers over the customize item.
/// </summary>
protected override void MouseHoverCustomize()
{
}
#endregion
}
}

View File

@@ -0,0 +1,724 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using DevComponents.DotNetBar.Controls;
using DevComponents.DotNetBar.Metro;
using System.Collections.Generic;
namespace DevComponents.DotNetBar.Ribbon
{
/// <summary>
/// Represents the Quick Access Toolbar customization panel which can be used on the custom QAT customization dialogs
/// so customization of Quick Access Toolbar can be reused.
/// </summary>
public class QatCustomizePanel : UserControl
{
#region Private/Public variables
/// <summary>
/// Gets reference to the internal ItemPanel control that displays the commands for selected category.
/// </summary>
public ItemPanel itemPanelCommands;
/// <summary>
/// Gets reference to the ItemPanel control that displays the Quick Access Toolbar Items.
/// </summary>
public ItemPanel itemPanelQat;
/// <summary>
/// Gets reference to the button that perform addition of commands to the Quick Access Toolbar.
/// </summary>
public ButtonX buttonAddToQat;
/// <summary>
/// Gets reference to the button that perform removal of commands from the Quick Access Toolbar.
/// </summary>
public ButtonX buttonRemoveFromQat;
/// <summary>
/// Gets reference to the combo box control that holds all categories.
/// </summary>
public ComboBoxEx comboCategories;
/// <summary>
/// Gets reference to the combo box categories label control.
/// </summary>
public Label labelCategories;
/// <summary>
/// Gets reference to the check box that changes the placement of the Quick Access Toolbar.
/// </summary>
public Controls.CheckBoxX checkQatBelowRibbon;
private Hashtable m_Categories = new Hashtable();
private bool m_DataChanged = false;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
#endregion
#region Constructor
public QatCustomizePanel()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.Opaque, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(DisplayHelp.DoubleBufferFlag, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
InitializeComponent();
}
#endregion
#region Component Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.itemPanelCommands = new DevComponents.DotNetBar.ItemPanel();
this.itemPanelQat = new DevComponents.DotNetBar.ItemPanel();
this.buttonAddToQat = new DevComponents.DotNetBar.ButtonX();
this.buttonRemoveFromQat = new DevComponents.DotNetBar.ButtonX();
this.comboCategories = new Controls.ComboBoxEx();
this.labelCategories = new System.Windows.Forms.Label();
this.checkQatBelowRibbon = new Controls.CheckBoxX();
this.SuspendLayout();
//
// itemPanelCommands
//
this.itemPanelCommands.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
//
//
//
this.itemPanelCommands.AutoScroll = true;
this.itemPanelCommands.BackgroundStyle.Class = DevComponents.DotNetBar.Rendering.ElementStyleClassKeys.ItemPanelKey;
this.itemPanelCommands.Style = eDotNetBarStyle.StyleManagerControlled;
this.itemPanelCommands.FadeEffect = false;
this.itemPanelCommands.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical;
#if!TRIAL
this.itemPanelCommands.LicenseKey = "F962CEC7-CD8F-4911-A9E9-CAB39962FC1F";
#endif
this.itemPanelCommands.Location = new System.Drawing.Point(9, 46);
this.itemPanelCommands.Name = "itemPanelCommands";
this.itemPanelCommands.Size = new System.Drawing.Size(173, 257);
this.itemPanelCommands.TabIndex = 2;
this.itemPanelCommands.Text = "itemPanelCommands";
this.itemPanelCommands.KeyUp += new KeyEventHandler(ItemPanelKeyUp);
this.itemPanelCommands.ItemDoubleClick += new MouseEventHandler(ItemPanelCommandsDoubleClick);
//
// itemPanelQat
//
this.itemPanelQat.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Right)));
//
//
//
this.itemPanelQat.AutoScroll = true;
this.itemPanelQat.BackgroundStyle.Class = DevComponents.DotNetBar.Rendering.ElementStyleClassKeys.ItemPanelKey;
this.itemPanelQat.Style = eDotNetBarStyle.StyleManagerControlled;
this.itemPanelQat.EnableDragDrop = true;
this.itemPanelQat.FadeEffect = false;
this.itemPanelQat.LayoutOrientation = DevComponents.DotNetBar.eOrientation.Vertical;
#if!TRIAL
this.itemPanelQat.LicenseKey = "F962CEC7-CD8F-4911-A9E9-CAB39962FC1F";
#endif
this.itemPanelQat.Location = new System.Drawing.Point(266, 46);
this.itemPanelQat.Name = "itemPanelQat";
this.itemPanelQat.Size = new System.Drawing.Size(173, 257);
this.itemPanelQat.TabIndex = 5;
this.itemPanelQat.Text = "itemPanelCommands";
this.itemPanelQat.DragDrop += new System.Windows.Forms.DragEventHandler(this.itemPanelQat_DragDrop);
this.itemPanelQat.UserCustomize += new EventHandler(this.itemPanelQat_UserCustomize);
this.itemPanelQat.KeyUp += new KeyEventHandler(ItemPanelKeyUp);
this.itemPanelQat.ItemDoubleClick += new MouseEventHandler(ItemPanelQatDoubleClick);
//
// buttonAddToQat
//
this.buttonAddToQat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonAddToQat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.buttonAddToQat.Location = new System.Drawing.Point(188, 126);
this.buttonAddToQat.Name = "buttonAddToQat";
this.buttonAddToQat.Size = new System.Drawing.Size(73, 21);
this.buttonAddToQat.TabIndex = 3;
this.buttonAddToQat.Text = "&Add >>";
this.buttonAddToQat.Click += new System.EventHandler(this.buttonAddToQat_Click);
//
// buttonRemoveFromQat
//
this.buttonRemoveFromQat.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRemoveFromQat.ColorTable = DevComponents.DotNetBar.eButtonColor.OrangeWithBackground;
this.buttonRemoveFromQat.Location = new System.Drawing.Point(188, 153);
this.buttonRemoveFromQat.Name = "buttonRemoveFromQat";
this.buttonRemoveFromQat.Size = new System.Drawing.Size(73, 21);
this.buttonRemoveFromQat.TabIndex = 4;
this.buttonRemoveFromQat.Text = "&Remove";
this.buttonRemoveFromQat.Click += new System.EventHandler(this.buttonRemoveFromQat_Click);
//
// comboCategories
//
this.comboCategories.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.comboCategories.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboCategories.Location = new System.Drawing.Point(9, 19);
this.comboCategories.Name = "comboCategories";
this.comboCategories.Size = new System.Drawing.Size(173, 21);
this.comboCategories.Sorted = true;
this.comboCategories.TabIndex = 1;
this.comboCategories.SelectedIndexChanged += new System.EventHandler(this.comboCategories_SelectedIndexChanged);
this.comboCategories.Style = eDotNetBarStyle.Office2007;
this.comboCategories.DrawMode = DrawMode.OwnerDrawFixed;
this.comboCategories.ThemeAware = false;
//
// labelCategories
//
this.labelCategories.AutoSize = true;
this.labelCategories.BackColor = System.Drawing.Color.Transparent;
this.labelCategories.Location = new System.Drawing.Point(6, 3);
this.labelCategories.Name = "labelCategories";
this.labelCategories.Size = new System.Drawing.Size(123, 13);
this.labelCategories.TabIndex = 0;
this.labelCategories.Text = "&Choose commands from:";
//
// checkQatBelowRibbon
//
this.checkQatBelowRibbon.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.checkQatBelowRibbon.BackColor = System.Drawing.Color.Transparent;
this.checkQatBelowRibbon.Location = new System.Drawing.Point(9, 311);
this.checkQatBelowRibbon.Name = "checkQatBelowRibbon";
this.checkQatBelowRibbon.Size = new System.Drawing.Size(420, 17);
this.checkQatBelowRibbon.TabIndex = 6;
this.checkQatBelowRibbon.Text = "&Place Quick Access Toolbar below the Ribbon";
this.checkQatBelowRibbon.CheckedChangedEx += new Controls.CheckBoxXChangeEventHandler(this.checkQatBelowRibbon_CheckedChanged);
//
// QatCustomizePanel
//
this.BackColor = System.Drawing.Color.Transparent;
this.Controls.Add(this.comboCategories);
this.Controls.Add(this.checkQatBelowRibbon);
this.Controls.Add(this.labelCategories);
this.Controls.Add(this.buttonRemoveFromQat);
this.Controls.Add(this.buttonAddToQat);
this.Controls.Add(this.itemPanelQat);
this.Controls.Add(this.itemPanelCommands);
this.Name = "QatCustomizePanel";
this.Size = new System.Drawing.Size(444, 334);
this.ResumeLayout(false);
this.PerformLayout();
}
private void ItemPanelKeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
{
ItemPanel panel = sender as ItemPanel;
foreach (BaseItem item in panel.Items)
{
ButtonItem button = item as ButtonItem;
if (button != null && button.IsMouseOver && !button.Checked)
{
button.Checked = true;
break;
}
}
}
}
#endregion
#region Internal Implementation
protected override void OnPaint(PaintEventArgs e)
{
if (this.BackColor== Color.Transparent || this.BackColor.A<255)
{
base.OnPaintBackground(e);
}
if (this.BackColor == Color.Transparent)
return;
DisplayHelp.FillRectangle(e.Graphics, this.ClientRectangle, this.BackColor);
}
/// <summary>
/// Loads the items for the customization into the ribbon control. All Ribbon Bars on the ribbon are enumerated and items
/// are added if they have CanCustomize=true.
/// </summary>
/// <param name="rc">Ribbon control to enumerate.</param>
public void LoadItems(RibbonControl rc)
{
m_Categories.Clear();
itemPanelCommands.Items.Clear();
itemPanelQat.Items.Clear();
LoadQatItems(rc);
if (rc.CategorizeMode == eCategorizeMode.Categories)
LoadByCategory(rc);
else
LoadByRibbonBar(rc);
LoadCategories();
checkQatBelowRibbon.Checked = rc.QatPositionedBelowRibbon;
checkQatBelowRibbon.Visible = rc.EnableQatPlacement;
m_DataChanged = false;
}
/// <summary>
/// Loads the items for the customization from MetroTab registered toolbars. All registered Toolbars are enumerated and items
/// are added if they have CanCustomize=true.
/// </summary>
/// <param name="tab">MetroTab control to enumerate.</param>
public void LoadItems(MetroShell tab)
{
m_Categories.Clear();
itemPanelCommands.Items.Clear();
itemPanelQat.Items.Clear();
LoadQatItems(tab);
if (tab.CategorizeMode == eMetroCategorizeMode.Categories)
LoadByCategory(tab);
else
LoadByMetroToolbar(tab);
LoadCategories();
checkQatBelowRibbon.Visible = false;
m_DataChanged = false;
}
#region By Category Loading
private void LoadByCategory(RibbonControl rc)
{
// Loop through all RibbonBars and add the items
foreach (Control panel in rc.Controls)
{
LoadByCategory(panel);
}
BaseItem startButton = rc.GetApplicationButton();
if (startButton!=null)
{
LoadByCategory(startButton);
}
}
private void LoadByCategory(MetroShell tab)
{
// Loop through all RibbonBars and add the items
List<IOwner> toolbars = tab.RegisteredToolbars;
foreach (IOwner toolbar in toolbars)
{
if (toolbar is MetroToolbar)
LoadByCategory((MetroToolbar)toolbar);
}
BaseItem startButton = tab.GetApplicationButton();
if (startButton != null)
{
LoadByCategory(startButton);
}
}
private void LoadByCategory(MetroToolbar toolbar)
{
foreach (BaseItem item in toolbar.Items)
LoadByCategory(item);
foreach (BaseItem item in toolbar.ExtraItems)
LoadByCategory(item);
}
private void LoadByCategory(Control panel)
{
if (panel is RibbonBar)
LoadByCategory(panel as RibbonBar);
foreach (Control c in panel.Controls)
LoadByCategory(c);
}
private void LoadByCategory(RibbonBar bar)
{
foreach (BaseItem item in bar.Items)
LoadByCategory(item);
}
private void LoadByCategory(BaseItem item)
{
if (CanCustomizeItem(item))
{
string cat = GetCategory(item);
ArrayList items = m_Categories[cat] as ArrayList;
if (items == null)
{
items = new ArrayList();
m_Categories.Add(cat, items);
}
items.Add(GetCustomizeRepresentation(item));
}
foreach (BaseItem child in item.SubItems)
LoadByCategory(child);
if (item is GalleryContainer)
{
GalleryContainer gallery = item as GalleryContainer;
foreach (BaseItem child in gallery.PopupGalleryItems)
LoadByCategory(child);
}
}
private string GetCategory(BaseItem item)
{
if (item.Category != "")
return item.Category;
return "Unassigned";
}
#endregion
#region Load by Ribbon or Toolbar
private void LoadByRibbonBar(RibbonControl rc)
{
// Loop through all RibbonBars and add the items
foreach (Control panel in rc.Controls)
{
LoadByRibbonBar(panel);
}
BaseItem startButton = rc.GetApplicationButton();
if (startButton!=null)
{
LoadByRibbonBar(startButton, GetRibbonBarCategory(startButton.Text));
}
}
private void LoadByMetroToolbar(MetroShell rc)
{
// Loop through all RibbonBars and add the items
List<IOwner> toolbars = rc.RegisteredToolbars;
foreach (IOwner owner in toolbars)
{
if (owner is MetroToolbar)
{
LoadByMetroToolbar((MetroToolbar)owner);
}
}
BaseItem startButton = rc.GetApplicationButton();
if (startButton != null)
{
LoadByRibbonBar(startButton, GetMetroToolbarCategory(startButton.Text));
}
}
private void LoadByMetroToolbar(MetroToolbar bar)
{
foreach (BaseItem item in bar.Items)
LoadByRibbonBar(item, GetMetroToolbarCategory(bar.Text));
foreach (BaseItem item in bar.ExtraItems)
LoadByRibbonBar(item, GetMetroToolbarCategory(bar.Text));
}
private void LoadByRibbonBar(Control panel)
{
if (panel is RibbonBar)
LoadByRibbonBar(panel as RibbonBar);
foreach (Control c in panel.Controls)
LoadByRibbonBar(c);
}
private void LoadByRibbonBar(RibbonBar bar)
{
foreach (BaseItem item in bar.Items)
LoadByRibbonBar(item, GetRibbonBarCategory(bar.Text));
}
private string GetRibbonBarCategory(string barText)
{
StringBuilder ret = new StringBuilder(barText.Length);
for (int i = 0; i < barText.Length; i++)
{
if (barText[i] == '&')
{
if (i + 1 < barText.Length && barText[i + 1] == '&')
ret.Append(barText[i]);
else
continue;
}
else
ret.Append(barText[i]);
}
return ret.ToString();
}
private string GetMetroToolbarCategory(string barText)
{
StringBuilder ret = new StringBuilder(barText.Length);
for (int i = 0; i < barText.Length; i++)
{
if (barText[i] == '&')
{
if (i + 1 < barText.Length && barText[i + 1] == '&')
ret.Append(barText[i]);
else
continue;
}
else
ret.Append(barText[i]);
}
return ret.ToString();
}
private void LoadByRibbonBar(BaseItem item, string category)
{
if (CanCustomizeItem(item))
{
ArrayList items = m_Categories[category] as ArrayList;
if (items == null)
{
items = new ArrayList();
m_Categories.Add(category, items);
}
items.Add(GetCustomizeRepresentation(item));
}
foreach (BaseItem child in item.SubItems)
LoadByRibbonBar(child, category);
if (item is GalleryContainer)
{
GalleryContainer gallery = item as GalleryContainer;
foreach (BaseItem child in gallery.PopupGalleryItems)
LoadByRibbonBar(child, category);
}
}
#endregion
private void LoadQatItems(RibbonControl rc)
{
int count = rc.QuickToolbarItems.Count;
int start = 0;
BaseItem startButton = rc.GetApplicationButton();
if (startButton != null)
start = rc.QuickToolbarItems.IndexOf(startButton) + 1;
for (int i = start; i < count; i++)
{
BaseItem item = rc.QuickToolbarItems[i];
if (IsSystemItem(item))
continue;
BaseItem custItem = GetCustomizeRepresentation(item);
custItem.Tag = null;
if (!item.CanCustomize) custItem.Visible = false;
itemPanelQat.Items.Add(custItem);
}
}
private void LoadQatItems(MetroShell tab)
{
int count = tab.QuickToolbarItems.Count;
int start = 0;
BaseItem startButton = tab.GetApplicationButton();
if (startButton != null)
start = tab.QuickToolbarItems.IndexOf(startButton) + 1;
for (int i = start; i < count; i++)
{
BaseItem item = tab.QuickToolbarItems[i];
if (IsSystemItem(item))
continue;
BaseItem custItem = GetCustomizeRepresentation(item);
custItem.Tag = null;
if (!item.CanCustomize) custItem.Visible = false;
itemPanelQat.Items.Add(custItem);
}
}
private bool IsSystemItem(BaseItem item)
{
if (item.SystemItem || item is ItemContainer || item is CustomizeItem || item is SystemCaptionItem)
return true;
return false;
}
private ButtonItem GetCustomizeRepresentation(BaseItem item)
{
ButtonItem ret = new ButtonItem(item.Name);
ret.Text = item.Text;
ret.ButtonStyle = eButtonStyle.ImageAndText;
ret.ImagePaddingVertical = 4;
ret.OptionGroup = "sys";
ret.GlobalItem = false;
if (ret.Text == "")
ret.Text = "Unassigned";
ret.Tag = item;
if (item is ButtonItem)
{
ButtonItem b = item as ButtonItem;
if (b.ImageSmall != null)
{
ret.Image = b.ImageSmall;
if (b.ImageSmall.Width != 16 || b.ImageSmall.Height != 16)
ret.ImageFixedSize = new Size(16, 16);
}
else
{
CompositeImage image = b.GetImage(ImageState.Default, Color.Black);
if (image != null)
{
if (image.IsIcon)
ret.Icon = (Icon)image.Icon.Clone();
else
ret.Image = image.Image;
ret.ImageFixedSize = new Size(16, 16);
}
}
}
else if (item is ComboBoxItem || item is TextBoxItem || item is ControlContainerItem)
{
ret.ImagePosition = eImagePosition.Right;
ret.Image = BarFunctions.LoadBitmap("SystemImages.QatCustomizeItemCombo.png");
}
return ret;
}
private bool CanCustomizeItem(BaseItem item)
{
if (item == null)
return false;
if (!item.CanCustomize || item.SystemItem || item.Name=="tempColorPickerItem")
return false;
if (item is ItemContainer || item is GenericItemContainer)
return false;
return true;
}
private void LoadCategories()
{
comboCategories.Items.Clear();
foreach (string key in m_Categories.Keys)
comboCategories.Items.Add(key);
if (comboCategories.Items.Count > 0)
comboCategories.SelectedIndex = 0;
}
private void comboCategories_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboCategories.SelectedIndex < 0)
{
itemPanelCommands.Items.Clear();
itemPanelCommands.RecalcLayout();
return;
}
string key = comboCategories.Items[comboCategories.SelectedIndex].ToString();
ArrayList items = m_Categories[key] as ArrayList;
itemPanelCommands.Items.Clear();
foreach (BaseItem item in items)
itemPanelCommands.Items.Add(item);
itemPanelCommands.RecalcLayout();
}
private void ItemPanelCommandsDoubleClick(object sender, MouseEventArgs e)
{
AddCheckedButtonToQat();
}
private void AddCheckedButtonToQat()
{
ButtonItem buttonChecked = itemPanelCommands.GetChecked();
if (buttonChecked == null)
return;
if (itemPanelQat.Items.Contains(buttonChecked.Name))
return;
ButtonItem copy = buttonChecked.Copy() as ButtonItem;
copy.Checked = false;
itemPanelQat.Items.Add(copy);
copy.Checked = true;
itemPanelQat.RecalcLayout();
m_DataChanged = true;
int index = itemPanelCommands.Items.IndexOf(buttonChecked) + 1;
if (index == itemPanelCommands.Items.Count)
return;
buttonChecked = itemPanelCommands.Items[index] as ButtonItem;
if (buttonChecked != null)
{
buttonChecked.Checked = true;
itemPanelCommands.EnsureVisible(buttonChecked);
}
}
private void buttonAddToQat_Click(object sender, EventArgs e)
{
AddCheckedButtonToQat();
}
private void RemoveCheckedButtonFromQat()
{
ButtonItem buttonChecked = itemPanelQat.GetChecked();
if (buttonChecked == null)
return;
int index = itemPanelQat.Items.IndexOf(buttonChecked);
itemPanelQat.Items.Remove(buttonChecked);
if (index >= 0 && itemPanelQat.Items.Count > 0)
{
if (index + 1 >= itemPanelQat.Items.Count)
index = itemPanelQat.Items.Count - 1;
buttonChecked = itemPanelQat.Items[index] as ButtonItem;
if (buttonChecked != null)
{
buttonChecked.Checked = true;
itemPanelQat.EnsureVisible(buttonChecked);
}
}
itemPanelQat.RecalcLayout();
m_DataChanged = true;
}
private void buttonRemoveFromQat_Click(object sender, EventArgs e)
{
RemoveCheckedButtonFromQat();
}
void ItemPanelQatDoubleClick(object sender, MouseEventArgs e)
{
RemoveCheckedButtonFromQat();
}
/// <summary>
/// Gets or sets the value of data changed flag.
/// </summary>
[DefaultValue(false), Browsable(false)]
public bool DataChanged
{
get { return m_DataChanged; }
set { m_DataChanged = value; }
}
private void itemPanelQat_DragDrop(object sender, DragEventArgs e)
{
m_DataChanged = true;
}
private void itemPanelQat_UserCustomize(object sender, EventArgs e)
{
m_DataChanged = true;
}
private void checkQatBelowRibbon_CheckedChanged(object sender, Controls.CheckBoxXChangeEventArgs e)
{
m_DataChanged = true;
}
#endregion
}
}

View File

@@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@@ -0,0 +1,74 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Defines the Ribbon Quick Access Overflow system item. Used internally by Ribbon control.
/// </summary>
public class QatOverflowItem : DisplayMoreItem
{
#region Internal Implementation
public QatOverflowItem()
: base()
{
this.KeyTips = "00";
}
/// <summary>
/// Returns copy of DisplayMoreItem item
/// </summary>
public override BaseItem Copy()
{
QatOverflowItem objCopy = new QatOverflowItem();
this.CopyToItem(objCopy);
return objCopy;
}
/// <summary>
/// Overriden. Draws the item.
/// </summary>
/// <param name="g">Target Graphics object.</param>
public override void Paint(ItemPaintArgs p)
{
Rendering.BaseRenderer renderer = p.Renderer;
if (renderer != null)
{
renderer.DrawQatOverflowItem(new QatOverflowItemRendererEventArgs(this, p.Graphics));
return;
}
else
{
Rendering.QatOverflowPainter painter = PainterFactory.CreateQatOverflowItemPainter(this);
if (painter != null)
{
painter.Paint(new QatOverflowItemRendererEventArgs(this, p.Graphics));
return;
}
}
base.Paint(p);
}
/// <summary>
/// Returns the insertion index for the items removed from overflow popup. Assumes that right-most items are removed first by the layout manager.
/// </summary>
/// <returns></returns>
protected override int GetReInsertIndex()
{
int insertPos = m_Parent.SubItems.Count;
for (int i = insertPos - 1; i >= 0; i--)
{
if (m_Parent.SubItems[i] is CustomizeItem || m_Parent.SubItems[i].ItemAlignment == eItemAlignment.Far)
{
insertPos = i;
}
else if (m_Parent.SubItems[i].ItemAlignment == eItemAlignment.Near)
break;
}
return insertPos;
}
#endregion
}
}

View File

@@ -0,0 +1,185 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections;
namespace DevComponents.DotNetBar.Ribbon
{
/// <summary>
/// Represents the stand-alone Quick Access Toolbar control
/// </summary>
internal class QatToolbar : ItemControl
{
#region Private Variables
private CaptionItemContainer m_ItemContainer = null;
private ElementStyle m_DefaultBackgroundStyle = new ElementStyle();
#endregion
#region Constructor
public QatToolbar()
{
m_ItemContainer = new CaptionItemContainer();
m_ItemContainer.GlobalItem = false;
m_ItemContainer.ContainerControl = this;
m_ItemContainer.WrapItems = false;
m_ItemContainer.EventHeight = false;
m_ItemContainer.UseMoreItemsButton = false;
m_ItemContainer.Stretch = true;
m_ItemContainer.Displayed = true;
m_ItemContainer.SystemContainer = true;
m_ItemContainer.PaddingTop = 0;
m_ItemContainer.PaddingBottom = 0;
m_ItemContainer.ItemSpacing = 0;
m_ItemContainer.SetOwner(this);
m_ItemContainer.PaddingBottom = 0;
m_ItemContainer.PaddingTop = 0;
m_ItemContainer.ItemSpacing = 1;
m_ItemContainer.TrackSubItemsImageSize = false;
//m_ItemContainer.ToolbarItemsAlign = eContainerVerticalAlignment.Middle;
this.SetBaseItemContainer(m_ItemContainer);
m_ItemContainer.Style = eDotNetBarStyle.Office2007;
}
#endregion
#region Internal Implementation
protected override ElementStyle GetBackgroundStyle()
{
if(this.BackgroundStyle.Custom)
return base.GetBackgroundStyle();
return m_DefaultBackgroundStyle;
}
protected override void RecalcSize()
{
InitDefaultStyles();
base.RecalcSize();
}
protected override void OnPaint(PaintEventArgs e)
{
InitDefaultStyles();
base.OnPaint(e);
}
private void InitDefaultStyles()
{
// Initialize Default Styles
RibbonPredefinedColorSchemes.ApplyQatElementStyle(m_DefaultBackgroundStyle, this);
}
/// <summary>
/// Gets/Sets the visual style for items and color scheme.
/// </summary>
[Browsable(true), DevCoBrowsable(true), Category("Appearance"), Description("Specifies the visual style of the control."), DefaultValue(eDotNetBarStyle.Office2007)]
public eDotNetBarStyle Style
{
get
{
return m_ItemContainer.Style;
}
set
{
this.ColorScheme.Style = value;
m_ItemContainer.Style = value;
this.Invalidate();
this.RecalcLayout();
}
}
internal eDotNetBarStyle EffectiveStyle
{
get
{
if (Style == eDotNetBarStyle.StyleManagerControlled)
return StyleManager.GetEffectiveStyle();
return Style;
}
}
/// <summary>
/// Returns collection of items on a bar.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content), Browsable(false)]
public SubItemsCollection Items
{
get
{
return m_ItemContainer.SubItems;
}
}
protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
if(this.Parent is RibbonControl)
((RibbonControl)this.Parent).ShowCustomizeContextMenu(this.HitTest(e.X, e.Y), true);
}
base.OnMouseDown(e);
}
protected override bool ProcessMnemonic(char charCode)
{
if (!this.ShowKeyTips) return false;
return base.ProcessMnemonic(charCode);
}
/// <summary>
/// Returns the collection of items with the specified name.
/// </summary>
/// <param name="ItemName">Item name to look for.</param>
/// <returns></returns>
public override ArrayList GetItems(string ItemName)
{
RibbonControl ribbonControl = GetRibbonControl();
if (ribbonControl != null && ribbonControl.RibbonStrip != null)
return ribbonControl.RibbonStrip.GetItems(ItemName);
return base.GetItems(ItemName);
}
/// <summary>
/// Returns the collection of items with the specified name and type.
/// </summary>
/// <param name="ItemName">Item name to look for.</param>
/// <param name="itemType">Item type to look for.</param>
/// <returns></returns>
public override ArrayList GetItems(string ItemName, Type itemType)
{
RibbonControl ribbonControl = GetRibbonControl();
if (ribbonControl != null && ribbonControl.RibbonStrip != null)
return ribbonControl.RibbonStrip.GetItems(ItemName, itemType);
return base.GetItems(ItemName, itemType);
}
/// <summary>
/// Returns the collection of items with the specified name and type.
/// </summary>
/// <param name="ItemName">Item name to look for.</param>
/// <param name="itemType">Item type to look for.</param>
/// <param name="useGlobalName">Indicates whether GlobalName property is used for searching.</param>
/// <returns></returns>
public override ArrayList GetItems(string ItemName, Type itemType, bool useGlobalName)
{
RibbonControl ribbonControl = GetRibbonControl();
if (ribbonControl != null && ribbonControl.RibbonStrip != null)
return ribbonControl.RibbonStrip.GetItems(ItemName, itemType, useGlobalName);
return base.GetItems(ItemName, itemType, useGlobalName);
}
/// <summary>
/// Returns the first item that matches specified name.
/// </summary>
/// <param name="ItemName">Item name to look for.</param>
/// <returns></returns>
public override BaseItem GetItem(string ItemName)
{
RibbonControl ribbonControl = GetRibbonControl();
if (ribbonControl != null && ribbonControl.RibbonStrip != null)
return ribbonControl.RibbonStrip.GetItem(ItemName);
return base.GetItem(ItemName);
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -0,0 +1,320 @@
using System;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the container for RibbonBar objects that will be merged into the MDI parent ribbon control.
/// </summary>
[ToolboxBitmap(typeof(RibbonBarMergeContainer), "Ribbon.RibbonControl.ico"), ToolboxItem(true), Designer("DevComponents.DotNetBar.Design.RibbonBarMergeContainerDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf"), System.Runtime.InteropServices.ComVisible(false)]
public class RibbonBarMergeContainer : RibbonPanel
{
#region Private variables
private bool m_AutoActivateTab = true;
private string m_RibbonTabText = "";
private string m_MergeIntoRibbonTabItemName = "";
private ArrayList m_MergedRibbonBarsList = new ArrayList();
private bool m_RibbonTabItemCreated = false;
private bool m_PreMergedVisibleState = false;
private bool m_AllowMerge = true;
private string m_MergeRibbonGroupName = "";
private int m_MergeRibbonTabItemIndex = -1;
private eRibbonTabColor m_RibbonTabColorTable = eRibbonTabColor.Default;
#endregion
#region Events
/// <summary>
/// Occurs before the RibbonBar objects from container are merged into the Ribbon control.
/// </summary>
public event EventHandler BeforeRibbonMerge;
/// <summary>
/// Occurs after the RibbonBar objects are merged into the Ribbon control.
/// </summary>
public event EventHandler AfterRibbonMerge;
/// <summary>
/// Occurs after the RibbonBar objects are removed from the Ribbon control.
/// </summary>
public event EventHandler BeforeRibbonUnmerge;
/// Occurs before the RibbonBar objects are removed from the Ribbon control.
/// </summary>
public event EventHandler AfterRibbonUnmerge;
#endregion
#region Internal Implementation
/// <summary>
/// Gets whether RibbonBar controls are merged into the RibbonControl.
/// </summary>
public bool IsMerged
{
get
{
return m_MergedRibbonBarsList.Count > 0;
}
}
/// <summary>
/// Removes any RibbonBar objects that were merged into the Ribbon control.
/// </summary>
/// <param name="ribbon">Reference to ribbon control to remove RibbonBar objects from.</param>
public virtual void RemoveMergedRibbonBars(RibbonControl ribbon)
{
OnBeforeRibbonUnmerge(new EventArgs());
Control parent = null;
foreach (RibbonBar c in m_MergedRibbonBarsList)
{
if (c.Parent != null)
{
if (parent == null)
{
parent = c.Parent;
parent.SuspendLayout();
}
c.Parent.Controls.Remove(c);
}
this.Controls.Add(c);
c.Enabled = false; // Disable shortcuts
}
m_MergedRibbonBarsList.Clear();
if (parent != null)
parent.ResumeLayout();
if (m_RibbonTabItemCreated)
{
this.RibbonTabItem.Parent.SubItems.Remove(this.RibbonTabItem);
if (this.RibbonTabItem.Panel != null && this.RibbonTabItem.Panel.Parent!=null)
{
this.RibbonTabItem.Panel.Parent.Controls.Remove(this.RibbonTabItem.Panel);
}
this.RibbonTabItem.Panel.Dispose();
this.RibbonTabItem.Panel = null;
m_RibbonTabItemCreated = false;
}
this.RibbonTabItem = null;
if (this.Visible != m_PreMergedVisibleState)
this.Visible = m_PreMergedVisibleState;
OnAfterRibbonUnmerge(new EventArgs());
}
/// <summary>
/// Merges RibbonBar objects from this container into the Ribbon control.
/// </summary>
/// <param name="ribbon">Reference to ribbon control to remove RibbonBar objects from.</param>
public virtual void MergeRibbonBars(RibbonControl ribbon)
{
OnBeforeRibbonMerge(new EventArgs());
m_PreMergedVisibleState = this.Visible;
if (this.Visible) this.Visible = false;
RibbonTabItem tab = GetCreateRibbonTabItem(ribbon);
Control[] controls = new Control[this.Controls.Count];
this.Controls.CopyTo(controls, 0);
int xpos = tab.Panel.Width + 1;
tab.Panel.SuspendLayout();
foreach (Control c in controls)
{
if (c is RibbonBar)
{
this.Controls.Remove(c);
if (m_MergeIntoRibbonTabItemName.Length > 0 && !tab.Panel.DefaultLayout)
{
c.Left = xpos;
xpos += c.Width;
}
tab.Panel.Controls.Add(c);
c.Enabled = true;
m_MergedRibbonBarsList.Add(c);
}
}
tab.Panel.ResumeLayout();
OnAfterRibbonMerge(new EventArgs());
}
private RibbonTabItem GetCreateRibbonTabItem(RibbonControl ribbon)
{
if (m_MergeIntoRibbonTabItemName != "")
{
if(ribbon.Items.IndexOf(m_MergeIntoRibbonTabItemName)<0)
throw new NullReferenceException("MergeIntoRibbonTabItemName specified (" + m_MergeIntoRibbonTabItemName + ") cannot be found in RibbonControl.Items collection");
this.RibbonTabItem = ribbon.Items[m_MergeIntoRibbonTabItemName] as RibbonTabItem;
return this.RibbonTabItem;
}
string tabText = m_RibbonTabText;
if (tabText.Length == 0)
tabText = this.Name;
string tabName = (this.Parent != null ? this.Parent.Name + "." : "") + this.Name;
this.RibbonTabItem = ribbon.CreateRibbonTab(tabText, tabName, m_MergeRibbonTabItemIndex);
if (!string.IsNullOrEmpty(_RibbonTabKeyTips))
this.RibbonTabItem.KeyTips = _RibbonTabKeyTips;
this.RibbonTabItem.ColorTable = m_RibbonTabColorTable;
m_RibbonTabItemCreated = true;
if (m_MergeRibbonGroupName.Length > 0)
{
RibbonTabItemGroup group = ribbon.TabGroups[m_MergeRibbonGroupName];
if (group != null)
{
int lastTabGroupIndex = -1;
for (int i = 0; i < ribbon.Items.Count; i++)
{
if (ribbon.Items[i] is RibbonTabItem && ((RibbonTabItem)ribbon.Items[i]).Group == group)
lastTabGroupIndex = i;
}
this.RibbonTabItem.Group = group;
if (lastTabGroupIndex >= 0)
{
ribbon.Items.Remove(this.RibbonTabItem);
ribbon.Items.Insert(lastTabGroupIndex + 1, this.RibbonTabItem);
}
}
}
return this.RibbonTabItem;
}
/// <summary>
/// Gets or sets whether RibbonTab item the RibbonBar controls are added to when merged is automatically activated (selected) after
/// controls are merged. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behaviour"), Description("Indicates whether RibbonTab item the RibbonBar controls are added to when merged is automatically activated (selected) after controls are merged.")]
public bool AutoActivateTab
{
get { return m_AutoActivateTab; }
set { m_AutoActivateTab = value; }
}
/// <summary>
/// Gets or sets whether merge functionality is enabled for the container. Default value is true.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Behaviour"), Description("Indicates whether merge functionality is enabled for the container.")]
public bool AllowMerge
{
get { return m_AllowMerge; }
set { m_AllowMerge = value; }
}
/// <summary>
/// Gets or sets the Ribbon Tab text for the tab that will be created when ribbon bar objects from this container are merged into the ribbon.
/// </summary>
[Browsable(true), DefaultValue(""), Localizable(true), Category("Data"), Description("Indicates the Ribbon Tab text for the tab that will be created when ribbon bar objects from this container are merged into the ribbon.")]
public string RibbonTabText
{
get { return m_RibbonTabText; }
set
{
m_RibbonTabText = value;
if (this.IsMerged && this.RibbonTabItem != null)
this.RibbonTabItem.Text = value;
}
}
private string _RibbonTabKeyTips = "";
/// <summary>
/// Gets or sets the Key Tips access key or keys for the Ribbon Tab. Use KeyTips property
/// when you want to assign the one or more letters to be used to access an item. For example assigning the FN to KeyTips property
/// will require the user to press F then N keys to select an item. Pressing the F letter will show only keytips for the items that start with letter F.
/// </summary>
[Browsable(true), Category("Appearance"), DefaultValue(""), Description("Indicates the Key Tips access key or keys for the Ribbon Tab.")]
public virtual string RibbonTabKeyTips
{
get { return _RibbonTabKeyTips; }
set
{
if (value == null) value = "";
_RibbonTabKeyTips = value.ToUpper();
if (this.IsMerged && this.RibbonTabItem != null)
this.RibbonTabItem.KeyTips = _RibbonTabKeyTips;
}
}
/// <summary>
/// Gets or sets the predefined color for the ribbon tab that is created when ribbon bar controls are merged into the ribbon.
/// Default value is eRibbonTabColor.Default
/// </summary>
[Browsable(true), DefaultValue(eRibbonTabColor.Default), Category("Appearance"), Description("Indicates predefined color for the ribbon tab that is created when ribbon bar controls are merged into the ribbon.")]
public eRibbonTabColor RibbonTabColorTable
{
get { return m_RibbonTabColorTable; }
set { m_RibbonTabColorTable = value; }
}
/// <summary>
/// Gets or sets the name of RibbonTabItem object that already exists on Ribbon control into which the RibbonBar controls are merged.
/// If name is not specified new RibbonTabItem is created and RibbonBar controls are added to it.
/// </summary>
[Browsable(true), DefaultValue(""), Category("Data"), Description("Indicates the name of RibbonTabItem object that already exists on Ribbon control into which the RibbonBar controls are merged.")]
public string MergeIntoRibbonTabItemName
{
get { return m_MergeIntoRibbonTabItemName; }
set { m_MergeIntoRibbonTabItemName = value; }
}
/// <summary>
/// Gets or sets the name of the RibbonTabItemGroup the new Ribbon Tab Item that is created will be added to. The RibbonTabItemGroup
/// must be created and added to RibbonControl.TabGroups collection.
/// </summary>
[Browsable(true), DefaultValue(""), Category("Data"), Description("Indicates the name of the RibbonTabItemGroup the new Ribbon Tab Item that is created will be added to.")]
public string MergeRibbonGroupName
{
get { return m_MergeRibbonGroupName; }
set { m_MergeRibbonGroupName = value; }
}
/// <summary>
/// Gets or sets the insertion index for the ribbon tab item that is created when ribbon bars are merged into the ribbon control.
/// Default value is -1 which means that ribbon tab item is appended to the existing ribbon tab items.
/// </summary>
[Browsable(true), DefaultValue(-1), Category("Data"), Description("Indicates the insertion index for the ribbon tab item that is created when ribbon bars are merged into the ribbon control.")]
public int MergeRibbonTabItemIndex
{
get { return m_MergeRibbonTabItemIndex; }
set { m_MergeRibbonTabItemIndex = value; }
}
/// <summary>
/// Raises the BeforeRibbonMerge event.
/// </summary>
protected virtual void OnBeforeRibbonMerge(EventArgs e)
{
if (BeforeRibbonMerge != null)
BeforeRibbonMerge(this, e);
}
/// <summary>
/// Raises the AfterRibbonMerge event.
/// </summary>
protected virtual void OnAfterRibbonMerge(EventArgs e)
{
if (AfterRibbonMerge != null)
AfterRibbonMerge(this, e);
}
/// <summary>
/// Raises the BeforeRibbonUnmerge event.
/// </summary>
protected virtual void OnBeforeRibbonUnmerge(EventArgs e)
{
if (BeforeRibbonUnmerge != null)
BeforeRibbonUnmerge(this, e);
}
/// <summary>
/// Raises the AfterRibbonUnmerge event.
/// </summary>
protected virtual void OnAfterRibbonUnmerge(EventArgs e)
{
if (AfterRibbonUnmerge != null)
AfterRibbonUnmerge(this, e);
}
#endregion
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 246 B

View File

@@ -0,0 +1,59 @@
using System;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using DevComponents.DotNetBar.Controls;
namespace DevComponents.DotNetBar.Ribbon
{
[ToolboxItem(true), Designer("DevComponents.DotNetBar.Design.RibbonClientPanelDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class RibbonClientPanel : PanelControl
{
#region Private Variables
private bool m_IsShadowEnabled = true;
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets whether panel automatically provides shadows for child controls.
/// </summary>
[Browsable(true), DefaultValue(true), Category("Appearance"), Description("Indicates whether panel automatically provides shadows for child controls.")]
public bool IsShadowEnabled
{
get { return m_IsShadowEnabled; }
set
{
if (m_IsShadowEnabled != value)
{
m_IsShadowEnabled = value;
this.Invalidate();
}
}
}
protected override void PaintInnerContent(System.Windows.Forms.PaintEventArgs e, ElementStyle style, bool paintText)
{
base.PaintInnerContent(e, style, paintText);
if (!m_IsShadowEnabled) return;
Graphics g = e.Graphics;
ShadowPaintInfo pi = new ShadowPaintInfo();
pi.Graphics = g;
pi.Size = 6;
foreach (Control c in this.Controls)
{
if (!c.Visible || c.BackColor == Color.Transparent && !(c is GroupPanel)) continue;
if (c is GroupPanel)
{
GroupPanel p = c as GroupPanel;
pi.Rectangle = new Rectangle(c.Bounds.X, c.Bounds.Y + p.GetInternalClientRectangle().Y/2, c.Bounds.Width, c.Bounds.Height - p.GetInternalClientRectangle().Y/2);
}
else
pi.Rectangle = c.Bounds;
ShadowPainter.Paint2(pi);
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 416 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@@ -0,0 +1,36 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents base class for Ribbon Control painting.
/// </summary>
internal class RibbonControlPainter
{
/// <summary>
/// Paints controls background
/// </summary>
public virtual void PaintBackground(RibbonControlRendererEventArgs e)
{
}
/// <summary>
/// Paints form caption background
/// </summary>
public virtual void PaintCaptionBackground(RibbonControlRendererEventArgs e, Rectangle displayRect)
{
}
/// <summary>
/// Paints form caption text when ribbon control is displaying form caption
/// </summary>
public virtual void PaintCaptionText(RibbonControlRendererEventArgs e) { }
/// <summary>
/// Paints the background of quick access toolbar.
/// </summary>
public virtual void PaintQuickAccessToolbarBackground(RibbonControlRendererEventArgs e) { }
}
}

View File

@@ -0,0 +1,56 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for RibbonBar rendering events.
/// </summary>
public class RibbonBarRendererEventArgs : EventArgs
{
/// <summary>
/// Gets or sets the reference to Graphics object.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets or sets the part bounds.
/// </summary>
public Rectangle Bounds = Rectangle.Empty;
/// <summary>
/// Gets or sets the reference to RibbonBar.
/// </summary>
public RibbonBar RibbonBar = null;
/// <summary>
/// Gets or sets whether mouse over state should be painted for the ribbon bar part.
/// </summary>
public bool MouseOver = false;
/// <summary>
/// Gets or sets whether mouse is pressed over the ribbon part.
/// </summary>
public bool Pressed = false;
/// <summary>
/// Gets or sets the region that defines the content bounds. When background is rendered the renderer should set this property
/// to define the content clip.
/// </summary>
public Region ContentClip = null;
/// <summary>
/// Creates new instance of the object and initializes it with default values.
/// </summary>
/// <param name="g">Reference to Graphics object.</param>
/// <param name="bounds">Bounds of the part to be rendered.</param>
/// <param name="ribbon">Reference to ribbon bar.</param>
public RibbonBarRendererEventArgs(Graphics g, Rectangle bounds, RibbonBar ribbon)
{
this.Graphics = g;
this.Bounds = bounds;
this.RibbonBar = ribbon;
}
}
}

View File

@@ -0,0 +1,184 @@
using System;
using System.Text;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents the class that stores text used by ribbon control only for localization purposes.
/// </summary>
[ToolboxItem(false), TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class RibbonLocalization
{
#region Private Variables
private string m_QatRemoveItemText = "&Remove from Quick Access Toolbar";
private string m_QatAddItemText = "&Add to Quick Access Toolbar";
private string m_QatCustomizeText = "&Customize Quick Access Toolbar...";
private string m_QatPlaceBelowRibbonText = "&Place Quick Access Toolbar below the Ribbon";
private string m_QatPlaceAboveRibbonText = "&Place Quick Access Toolbar above the Ribbon";
private string m_QatDialogOkButton = "OK";
private string m_QatDialogCancelButton = "Cancel";
private string m_QatDialogAddButton = "&Add >>";
private string m_QatDialogRemoveButton = "&Remove";
private string m_QatDialogCategoriesLabel = "&Choose commands from:";
private string m_QatDialogPlacementCheckbox = "&Place Quick Access Toolbar below the Ribbon";
private string m_QatDialogCaption = "Customize Quick Access Toolbar";
private string m_MinimizeRibbonText = "Mi&nimize the Ribbon";
private string m_MaximizeRibbonText = "&Maximize the Ribbon";
private string m_QatCustomizeMenuLabel = "<b>Customize Quick Access Toolbar</b>";
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets the title text of the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the the title text of the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogCaption
{
get { return m_QatDialogCaption; }
set { m_QatDialogCaption = value; }
}
/// <summary>
/// Gets or sets the text of the "Place Quick Access Toolbar below the Ribbon" check-box on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the 'Place Quick Access Toolbar below the Ribbon' check-box on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogPlacementCheckbox
{
get { return m_QatDialogPlacementCheckbox; }
set { m_QatDialogPlacementCheckbox = value; }
}
/// <summary>
/// Gets or sets the text of the Choose commands from label on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the Choose commands from label on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogCategoriesLabel
{
get { return m_QatDialogCategoriesLabel; }
set { m_QatDialogCategoriesLabel = value; }
}
/// <summary>
/// Gets or sets the text of the Remove button on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the Remove button on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogRemoveButton
{
get { return m_QatDialogRemoveButton; }
set { m_QatDialogRemoveButton = value; }
}
/// <summary>
/// Gets or sets the text of the Add button on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the Add button on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogAddButton
{
get { return m_QatDialogAddButton; }
set { m_QatDialogAddButton = value; }
}
/// <summary>
/// Gets or sets the text of the OK button on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the OK button on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogOkButton
{
get { return m_QatDialogOkButton; }
set { m_QatDialogOkButton = value; }
}
/// <summary>
/// Gets or sets the text of the Cancel button on the Quick Access Toolbar Customize dialog form.
/// </summary>
[Localizable(true), Description("Indicates the text of the OK button on the Quick Access Toolbar Customize dialog form."), Category("QAT Customize Dialog")]
public string QatDialogCancelButton
{
get { return m_QatDialogCancelButton; }
set { m_QatDialogCancelButton = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu used to customize Quick Access Toolbar.
/// </summary>
[Localizable(true), Description("Indicates the text that is used on context menu used to customize Quick Access Toolbar."), Category("Quick Access Toolbar")]
public string QatRemoveItemText
{
get { return m_QatRemoveItemText; }
set { m_QatRemoveItemText = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu used to customize Quick Access Toolbar.
/// </summary>
[Localizable(true), Description("Indicates the text that is used on context menu used to customize Quick Access Toolbar."), Category("Quick Access Toolbar")]
public string QatAddItemText
{
get { return m_QatAddItemText; }
set { m_QatAddItemText = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu used to customize Quick Access Toolbar.
/// </summary>
[Localizable(true), Description("Indicates the text that is used on context menu used to customize Quick Access Toolbar."), Category("Quick Access Toolbar")]
public string QatCustomizeText
{
get { return m_QatCustomizeText; }
set { m_QatCustomizeText = value; }
}
/// <summary>
/// Gets or sets the text that is used on Quick Access Toolbar customize menu label.
/// </summary>
[Localizable(true), Description("Indicates text that is used on Quick Access Toolbar customize menu label."), Category("Quick Access Toolbar")]
public string QatCustomizeMenuLabel
{
get { return m_QatCustomizeMenuLabel; }
set { m_QatCustomizeMenuLabel = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu used to change placement of the Quick Access Toolbar.
/// </summary>
[Localizable(true), Description("Indicates the text that is used on context menu used to change placement of the Quick Access Toolbar."), Category("Quick Access Toolbar")]
public string QatPlaceBelowRibbonText
{
get { return m_QatPlaceBelowRibbonText; }
set { m_QatPlaceBelowRibbonText = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu used to change placement of the Quick Access Toolbar.
/// </summary>
[Localizable(true), Description("Indicates the text that is used on context menu used to change placement of the Quick Access Toolbar."), Category("Quick Access Toolbar")]
public string QatPlaceAboveRibbonText
{
get { return m_QatPlaceAboveRibbonText; }
set { m_QatPlaceAboveRibbonText = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu item used to minimize the Ribbon.
/// </summary>
[Localizable(true), Description("Indicates text that is used on context menu item used to minimize the Ribbon."), Category("Quick Access Toolbar")]
public string MinimizeRibbonText
{
get { return m_MinimizeRibbonText; }
set { m_MinimizeRibbonText = value; }
}
/// <summary>
/// Gets or sets the text that is used on context menu item used to maximize the Ribbon.
/// </summary>
[Localizable(true), Description("Indicates text that is used on context menu item used to maximize the Ribbon."), Category("Quick Access Toolbar")]
public string MaximizeRibbonText
{
get { return m_MaximizeRibbonText; }
set { m_MaximizeRibbonText = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,43 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents ribbon overflow button.
/// </summary>
internal class RibbonOverflowButtonItem : ButtonItem
{
/// <summary>
/// Gets or sets the ribbon bar control overflow button is displayed on.
/// </summary>
public RibbonBar RibbonBar = null;
protected override void OnCommandChanged()
{
}
protected override void OnExternalSizeChange()
{
base.OnExternalSizeChange();
AdjustSubItemsRect();
}
public override void RecalcSize()
{
base.RecalcSize();
AdjustSubItemsRect();
}
private void AdjustSubItemsRect()
{
Rectangle r = this.SubItemsRect;
if (!r.IsEmpty)
{
r.Y += 8;
r.Height -= 4;
this.SubItemsRect = r;
}
}
}
}

View File

@@ -0,0 +1,849 @@
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using System.Collections;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents panel used by RibbonTabItem as a container panel for the control.
/// </summary>
[ToolboxItem(false), Designer("DevComponents.DotNetBar.Design.RibbonPanelDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class RibbonPanel : PanelControl, IKeyTipsControl
{
#region Private Variables
private const string INFO_TEXT="Drop RibbonBar or other controls here. Drag and Drop tabs and items to re-order.";
private RibbonTabItem m_RibbonTabItem=null;
private bool m_UseCustomStyle=false;
private bool m_DefaultLayout = false;
private bool m_StretchLastRibbonBar = false;
private ElementStyle m_DefaultStyle = new ElementStyle();
private RightToLeft m_RightToLeft = RightToLeft.No;
private bool m_InternalLayoutSuspend = false;
private ButtonX m_ButtonScrollRight = null;
private ButtonX m_ButtonScrollLeft = null;
private Rectangle m_ViewBounds = Rectangle.Empty;
private int m_ScrollOffset = 0;
#endregion
#region Internal Implementation
/// <summary>
/// Creates new instance of the panel.
/// </summary>
public RibbonPanel():base()
{
this.BackColor=SystemColors.Control;
}
protected override ElementStyle GetStyle()
{
if (!this.Style.Custom)
{
return GetDefaultStyle();
}
return base.GetStyle();
}
//protected override bool ScaleChildren
//{
// get { return m_DefaultLayout; }
//}
private bool m_PopupMode = false;
private RibbonControl m_RibbonControl = null;
internal RibbonControl GetRibbonControl()
{
if (m_PopupMode)
return m_RibbonControl;
return this.Parent as RibbonControl;
}
internal bool IsPopupMode
{
get { return m_PopupMode; }
}
internal void SetPopupMode(bool popupMode, RibbonControl rc)
{
m_PopupMode = popupMode;
if (m_PopupMode)
{
m_RibbonControl = rc;
#if FRAMEWORK20
if (this.Padding.Bottom > 0)
{
this.Height += this.Padding.Bottom;
this.Padding = new System.Windows.Forms.Padding(this.Padding.Left, this.Padding.Bottom, this.Padding.Right, this.Padding.Bottom);
}
#else
if (this.DockPadding.Bottom > 0)
{
this.DockPadding.Top = this.DockPadding.Bottom;
this.Height += this.DockPadding.Bottom;
}
#endif
}
else
{
#if FRAMEWORK20
if (this.Padding.Top > 0)
{
this.Height -= this.Padding.Top;
this.Padding = new System.Windows.Forms.Padding(this.Padding.Left, 0, this.Padding.Right, this.Padding.Bottom);
}
#else
if (this.DockPadding.Top > 0)
{
this.Height -= this.DockPadding.Top;
this.DockPadding.Top = 0;
}
#endif
m_RibbonControl = null;
}
}
private ElementStyle GetDefaultStyle()
{
RibbonControl rc = GetRibbonControl();
if (rc!=null && this.ColorSchemeStyle != rc.Style)
this.ColorSchemeStyle = rc.Style;
m_DefaultStyle.SetColorScheme(this.ColorScheme);
if (BarFunctions.IsOffice2007Style(this.EffectiveColorSchemeStyle) || rc != null && BarFunctions.IsOffice2007Style(rc.EffectiveStyle))
{
m_DefaultStyle.Reset();
Rendering.Office2007ColorTable ct = null;
if (rc != null)
ct = rc.GetOffice2007ColorTable();
else if (Rendering.GlobalManager.Renderer is Rendering.Office2007Renderer)
{
ct = ((Rendering.Office2007Renderer)Rendering.GlobalManager.Renderer).ColorTable;
}
else
return this.Style;
if (StyleManager.IsMetro(this.EffectiveColorSchemeStyle) || rc != null && StyleManager.IsMetro(rc.EffectiveStyle))
m_DefaultStyle.Border = eStyleBorderType.Solid;
else
m_DefaultStyle.Border = eStyleBorderType.Double;
if (rc == null || !rc.IsPopupMode)
m_DefaultStyle.BorderTop = eStyleBorderType.None;
m_DefaultStyle.BorderWidth = 1;
m_DefaultStyle.CornerDiameter = ct.RibbonControl.CornerSize;
m_DefaultStyle.CornerType = eCornerType.Rounded;
if (!m_PopupMode)
{
m_DefaultStyle.CornerTypeTopLeft = eCornerType.Square;
m_DefaultStyle.CornerTypeTopRight = eCornerType.Square;
}
else if (ct.InitialColorScheme == DevComponents.DotNetBar.Rendering.eOffice2007ColorScheme.Black)
m_DefaultStyle.BorderTop = eStyleBorderType.None;
if (rc != null && (rc.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(rc.EffectiveStyle)))
{
m_DefaultStyle.CornerTypeBottomRight = eCornerType.Square;
m_DefaultStyle.CornerTypeBottomLeft = eCornerType.Square;
if (rc.RibbonStrip.IsGlassEnabled)
{
m_DefaultStyle.BorderLeftWidth = 0;
m_DefaultStyle.BorderRightWidth = 0;
m_DefaultStyle.BorderLeft = eStyleBorderType.None;
m_DefaultStyle.BorderRight = eStyleBorderType.None;
}
else
{
if (StyleManager.IsMetro(rc.EffectiveStyle))
{
m_DefaultStyle.BorderLeft = eStyleBorderType.None;
m_DefaultStyle.BorderRight = eStyleBorderType.None;
}
else
{
m_DefaultStyle.BorderLeft = eStyleBorderType.Solid;
m_DefaultStyle.BorderRight = eStyleBorderType.Solid;
}
}
}
else if (rc != null && rc.EffectiveStyle == eDotNetBarStyle.Windows7)
{
m_DefaultStyle.CornerType = eCornerType.Square;
m_DefaultStyle.CornerTypeBottomRight = eCornerType.Square;
m_DefaultStyle.CornerTypeBottomLeft = eCornerType.Square;
m_DefaultStyle.CornerTypeTopRight = eCornerType.Square;
m_DefaultStyle.CornerTypeTopLeft = eCornerType.Square;
m_DefaultStyle.CornerDiameter = 0;
if (rc.RibbonStrip.IsGlassEnabled)
{
m_DefaultStyle.BorderLeft = eStyleBorderType.None;
m_DefaultStyle.BorderRight = eStyleBorderType.None;
}
}
// Border Colors
m_DefaultStyle.BorderColor = ct.RibbonControl.OuterBorder.Start;
m_DefaultStyle.BorderColor2 = ct.RibbonControl.OuterBorder.End;
if (ct.RibbonControl.InnerBorder != null)
{
m_DefaultStyle.BorderColorLight = ct.RibbonControl.InnerBorder.Start;
m_DefaultStyle.BorderColorLight2 = ct.RibbonControl.InnerBorder.End;
m_DefaultStyle.BorderBottom = eStyleBorderType.Double;
}
else
{
m_DefaultStyle.BorderBottom = eStyleBorderType.Solid;
}
m_DefaultStyle.BorderWidth = 1;
// Background colors
m_DefaultStyle.BackColorGradientAngle = 90;
m_DefaultStyle.BackColor = ct.RibbonBar.Default.TopBackground.Start;
if (ct.RibbonControl.PanelTopBackgroundHeight== 0 && ct.RibbonControl.PanelBottomBackground==null)
{
m_DefaultStyle.BackColor = ct.RibbonControl.PanelTopBackground.Start;
m_DefaultStyle.BackColor2 = ct.RibbonControl.PanelTopBackground.End;
}
else
{
m_DefaultStyle.BackColorBlend.Add(new BackgroundColorBlend(ct.RibbonControl.PanelTopBackground.Start, 0));
m_DefaultStyle.BackColorBlend.Add(new BackgroundColorBlend(ct.RibbonControl.PanelTopBackground.End, ct.RibbonControl.PanelTopBackgroundHeight));
m_DefaultStyle.BackColorBlend.Add(new BackgroundColorBlend(ct.RibbonControl.PanelBottomBackground.Start, ct.RibbonControl.PanelTopBackgroundHeight));
m_DefaultStyle.BackColorBlend.Add(new BackgroundColorBlend(ct.RibbonControl.PanelBottomBackground.End, 1));
}
}
else
{
ApplyLabelStyle(m_DefaultStyle);
m_DefaultStyle.BorderBottom = eStyleBorderType.Solid;
}
return m_DefaultStyle;
}
protected override void OnControlAdded(ControlEventArgs e)
{
if (!(e.Control is RibbonBar))
{
m_DefaultLayout = false;
}
base.OnControlAdded(e);
}
internal bool InternalLayoutSuspend
{
get { return m_InternalLayoutSuspend; }
set { m_InternalLayoutSuspend = value; }
}
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected override void OnLayout(LayoutEventArgs levent)
{
if (m_DefaultLayout || this.DesignMode)
{
base.OnLayout(levent);
return;
}
if (this.ClientRectangle.Width == 0 || this.ClientRectangle.Height == 0 || !this.IsHandleCreated)
return;
Form f = this.FindForm();
if (f != null && f.WindowState == FormWindowState.Minimized)
return;
// Has RightToLeft changed, if so mirror content
if (m_RightToLeft != this.RightToLeft)
{
m_RightToLeft = this.RightToLeft;
Rectangle r = GetLayoutRectangle();
foreach (Control c in this.Controls)
{
if (!(c is RibbonBar))
continue;
// Mirror the X position of each RibbonBar
c.Left = r.Width - c.Width - c.Left;
}
}
if(!m_InternalLayoutSuspend)
LayoutRibbons();
}
private Rectangle GetLayoutRectangle()
{
Rectangle r = this.ClientRectangle;
r.X += this.DockPadding.Left;
r.Width -= this.DockPadding.Left + this.DockPadding.Right;
r.Y += this.DockPadding.Top;
r.Height -= this.DockPadding.Top + ((this.EffectiveColorSchemeStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(this.EffectiveColorSchemeStyle)) && this.DockPadding.Bottom == 3 ? 2 : this.DockPadding.Bottom);
if (StyleManager.IsMetro(this.EffectiveColorSchemeStyle) && this.DockPadding.All == 0)
{
r.Y += 3;
r.Height -= 6;
}
return r;
}
[EditorBrowsable(EditorBrowsableState.Never)]
public void LayoutRibbons()
{
int spacing = 2;
Rectangle r = GetLayoutRectangle();
int currentWidth = -spacing;
ArrayList resizeOrder = new ArrayList();
ArrayList layoutOrder = new ArrayList();
ArrayList overflowList = new ArrayList();
Control lastVisibleControl = null;
int lastX = 0;
bool resizeOrderSpecified = false;
RibbonBar barGallery = null;
foreach (Control c in this.Controls)
{
RibbonBar bar = c as RibbonBar;
if (bar == null || !bar.Visible) continue;
if(Dpi.Factor.Width>1)
bar.RecalcLayout();
int barContentBasedWidth = bar.GetContentBasedSize().Width;
currentWidth += barContentBasedWidth + spacing;
if (bar.GalleryStretch != null && bar.GalleryStretch.Visible) barGallery = bar;
if (bar.ResizeOrderIndex != 0)
resizeOrderSpecified = true;
resizeOrder.Add(bar);
layoutOrder.Add(bar);
if (bar.OverflowState) overflowList.Add(bar);
if (bar.Left > lastX)
{
lastX = bar.Left;
lastVisibleControl = c;
}
}
layoutOrder.Sort(new XPositionComparer());
if (resizeOrderSpecified)
{
resizeOrder.Sort(new ResizeOrderComparer());
overflowList.Sort(new ResizeOrderComparer());
}
else
{
resizeOrder.Sort(new XPositionComparer());
overflowList.Sort(new XPositionComparer());
}
int lastControlIncrease = 0;
if (currentWidth > r.Width)
{
// One or more ribbons must be reduced in size...
int totalReduction = currentWidth - r.Width;
// Check whether gallery can be reduced first
if (barGallery != null && !barGallery.GalleryStretch.IsAtMinimumSize) // barGallery.GalleryStretch.WidthInternal > barGallery.GalleryStretch.MinimumSize.Width)
{
int oldWidth = barGallery.GetContentBasedSize().Width;
if (barGallery.GalleryStretch.WidthInternal - barGallery.GalleryStretch.MinimumSize.Width >= totalReduction)
barGallery.Size = new Size(oldWidth - totalReduction, r.Height);
else
barGallery.Size = new Size(oldWidth - (barGallery.GalleryStretch.WidthInternal - barGallery.GalleryStretch.MinimumSize.Width), r.Height);
totalReduction -= (oldWidth - barGallery.GetContentBasedSize().Width);
}
if (totalReduction > 0)
{
int c = resizeOrder.Count - 1;
for (int i = c; i >= 0; i--)
{
RibbonBar bar = resizeOrder[i] as RibbonBar;
int oldWidth = bar.GetContentBasedSize().Width;
if (oldWidth > totalReduction && bar.AutoSizeItems)
bar.Size = new Size(oldWidth - totalReduction, r.Height);
else
bar.Size = new Size(1, r.Height);
totalReduction -= (oldWidth - bar.GetContentBasedSize().Width);
if (totalReduction <= 0) break;
}
}
if (totalReduction != 0) lastControlIncrease = Math.Abs(totalReduction);
}
else if (currentWidth < r.Width)
{
// One or more ribbons must be increased in size
int totalIncrease = r.Width - currentWidth;
// Start with overflows first
ArrayList overflowed = new ArrayList();
overflowed.AddRange(overflowList.ToArray());
foreach(RibbonBar bar in overflowed)
{
int oldWidth = bar.GetContentBasedSize().Width;
bar.Size = new Size(oldWidth + totalIncrease, r.Height);
totalIncrease -= (bar.GetContentBasedSize().Width - oldWidth);
if (totalIncrease >= 0 && !bar.OverflowState)
overflowList.Remove(bar);
if (totalIncrease <= 0 || bar.GetContentBasedSize().Width - oldWidth == 0) break;
}
if (totalIncrease > 0 && overflowList.Count == 0)
{
int c = resizeOrder.Count - 1;
for (int i = c; i >= 0; i--)
{
RibbonBar bar = resizeOrder[i] as RibbonBar;
if (bar.OverflowState || overflowed.Contains(bar)) continue;
int oldWidth = bar.GetContentBasedSize().Width;
if (oldWidth == bar.Width && bar.Height == r.Height && bar.LastReducedSize.IsEmpty && bar.BeforeOverflowSize.IsEmpty && bar.GalleryStretch == null)
continue;
if (bar.Width == oldWidth + totalIncrease)
{
if(!(bar == lastVisibleControl && m_StretchLastRibbonBar)) // If not stretching last bar and current bar is last one
totalIncrease = 0;
break;
}
bar.Size = new Size(oldWidth + totalIncrease, r.Height);
totalIncrease -= (bar.GetContentBasedSize().Width - oldWidth);
if (totalIncrease <= 0) break;
}
}
if (totalIncrease > 0) lastControlIncrease = totalIncrease;
}
RepositionRibbons(layoutOrder, r, spacing, lastVisibleControl, lastControlIncrease);
}
private void RepositionRibbons(ArrayList layoutOrder, Rectangle layoutRectangle, int spacing, Control lastVisibleControl, int lastControlIncrease)
{
Point p = layoutRectangle.Location;
// Is there an offset?
int offset = 0;
if (this.RightToLeft == RightToLeft.Yes)
{
int currentWidth = 0;
foreach (RibbonBar bar in layoutOrder)
{
currentWidth += bar.GetContentBasedSize().Width + spacing;
}
if (currentWidth < layoutRectangle.Width)
{
offset = spacing + layoutRectangle.Width - currentWidth;
}
}
Rectangle viewBounds = Rectangle.Empty;
p.X += m_ScrollOffset;
foreach (RibbonBar bar in layoutOrder)
{
Size contentSize = bar.GetContentBasedSize();
if (bar == lastVisibleControl && m_StretchLastRibbonBar && !bar.OverflowState)
contentSize.Width += lastControlIncrease;
//Rectangle bounds = new Rectangle(p.X, p.Y, width, r.Height);
Rectangle bounds = new Rectangle(p.X + offset, p.Y, contentSize.Width, layoutRectangle.Height);
if (this.DesignMode)
TypeDescriptor.GetProperties(bar)["Bounds"].SetValue(bar, bounds);
else
bar.Bounds = bounds;
viewBounds = Rectangle.Union(bounds, viewBounds);
p.X += (bar.Width + spacing);
}
m_ViewBounds = viewBounds;
if (m_ViewBounds.Right > this.Width)
{
if (m_ButtonScrollRight == null)
{
m_ButtonScrollRight = new ButtonX();
m_ButtonScrollRight.Text = "<expand direction=\"right\"/>";
m_ButtonScrollRight.ColorTable = eButtonColor.OrangeWithBackground;
m_ButtonScrollRight.Click += new EventHandler(ScrollPanelRightClick);
}
m_ButtonScrollRight.Bounds = new Rectangle(this.Width - 12, 0, 12, this.Height - 2);
this.Controls.Add(m_ButtonScrollRight);
m_ButtonScrollRight.BringToFront();
}
else
{
if (m_ButtonScrollRight != null)
{
m_ButtonScrollRight.Visible = false;
this.Controls.Remove(m_ButtonScrollRight);
m_ButtonScrollRight.Dispose();
m_ButtonScrollRight = null;
}
}
if (m_ScrollOffset < 0)
{
if (m_ButtonScrollLeft == null)
{
m_ButtonScrollLeft = new ButtonX();
m_ButtonScrollLeft.Text = "<expand direction=\"left\"/>";
m_ButtonScrollLeft.ColorTable = eButtonColor.OrangeWithBackground;
m_ButtonScrollLeft.Click += new EventHandler(ScrollPanelLeftClick);
}
m_ButtonScrollLeft.Bounds = new Rectangle(0, 0, 12, this.Height - 2);
this.Controls.Add(m_ButtonScrollLeft);
m_ButtonScrollLeft.BringToFront();
}
else
{
if (m_ButtonScrollLeft != null)
{
m_ButtonScrollLeft.Visible = false;
this.Controls.Remove(m_ButtonScrollLeft);
m_ButtonScrollLeft.Dispose();
m_ButtonScrollLeft = null;
}
}
}
private void ScrollPanelRightClick(object sender, EventArgs e)
{
ScrollRight();
}
/// <summary>
/// Scrolls the RibbonBar controls to the right one step if there is more of the controls on the panel that can fit into the available space.
/// </summary>
public void ScrollRight()
{
if (m_ScrollOffset + m_ViewBounds.Width <= this.Width)
return;
SetScrollOffset(-Math.Min(this.Width, m_ViewBounds.Right - this.Width + 2));
}
private void ScrollPanelLeftClick(object sender, EventArgs e)
{
ScrollLeft();
}
/// <summary>
/// Scrolls the RibbonBar controls one step to the left.
/// </summary>
public void ScrollLeft()
{
SetScrollOffset(Math.Min(Math.Abs(m_ScrollOffset), this.Width));
}
/// <summary>
/// Resets the panel scroll position.
/// </summary>
public void ResetScrollPosition()
{
SetScrollOffset(-m_ScrollOffset);
}
private void SetScrollOffset(int offset)
{
m_ScrollOffset += offset;
this.PerformLayout();
}
private class XPositionComparer : IComparer
{
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
int IComparer.Compare(object x, object y)
{
if (x is Control && y is Control)
{
return ((Control)x).Left - ((Control)y).Left;
}
else
return( (new CaseInsensitiveComparer()).Compare(x, y));
}
}
private class ResizeOrderComparer : IComparer
{
// Calls CaseInsensitiveComparer.Compare with the parameters reversed.
int IComparer.Compare(object x, object y)
{
if (x is RibbonBar && y is RibbonBar)
{
return ((RibbonBar)x).ResizeOrderIndex - ((RibbonBar)y).ResizeOrderIndex;
}
else
return ((new CaseInsensitiveComparer()).Compare(x, y));
}
}
private Rectangle GetThemedRect(Rectangle r)
{
const int offset=6;
r.Y-=offset;
r.Height+=offset;
return r;
}
protected override void OnPaint(PaintEventArgs e)
{
bool baseCall=true;
if(DrawThemedPane && BarFunctions.ThemedOS)
{
Rectangle r=GetThemedRect(this.ClientRectangle);
eTabStripAlignment tabAlignment=eTabStripAlignment.Top;
Rectangle rTemp=new Rectangle(0,0,r.Width,r.Height);
if(tabAlignment==eTabStripAlignment.Right || tabAlignment==eTabStripAlignment.Left)
rTemp=new Rectangle(0,0,rTemp.Height,rTemp.Width);
if(m_ThemeCachedBitmap==null || m_ThemeCachedBitmap.Size!=rTemp.Size)
{
DisposeThemeCachedBitmap();
Bitmap bmp=new Bitmap(rTemp.Width,rTemp.Height,e.Graphics);
try
{
Graphics gTemp=Graphics.FromImage(bmp);
try
{
using(SolidBrush brush=new SolidBrush(Color.Transparent))
gTemp.FillRectangle(brush,0,0,bmp.Width,bmp.Height);
this.ThemeTab.DrawBackground(gTemp,ThemeTabParts.Pane,ThemeTabStates.Normal,rTemp);
}
finally
{
gTemp.Dispose();
}
}
finally
{
if(tabAlignment==eTabStripAlignment.Left)
bmp.RotateFlip(RotateFlipType.Rotate270FlipNone);
else if(tabAlignment==eTabStripAlignment.Right)
bmp.RotateFlip(RotateFlipType.Rotate90FlipNone);
else if(tabAlignment==eTabStripAlignment.Bottom)
bmp.RotateFlip(RotateFlipType.Rotate180FlipNone);
e.Graphics.DrawImageUnscaled(bmp,r.X,r.Y);
m_ThemeCachedBitmap=bmp;
}
}
else
e.Graphics.DrawImageUnscaled(m_ThemeCachedBitmap,r.X,r.Y);
baseCall=false;
}
if(baseCall)
base.OnPaint(e);
if(this.DesignMode && this.Controls.Count==0 && this.Text=="")
{
Rectangle r=this.ClientRectangle;
r.Inflate(-2,-2);
StringFormat sf=BarFunctions.CreateStringFormat();
sf.Alignment=StringAlignment.Center;
sf.LineAlignment=StringAlignment.Center;
sf.Trimming=StringTrimming.EllipsisCharacter;
Font font=new Font(this.Font,FontStyle.Bold);
e.Graphics.DrawString(INFO_TEXT,font,new SolidBrush(ControlPaint.Dark(this.Style.BackColor)),r,sf);
font.Dispose();
sf.Dispose();
}
if (this.Parent is RibbonControl) ((RibbonControl)this.Parent).RibbonStrip.InvalidateKeyTipsCanvas();
}
//protected override void PaintInnerContent(PaintEventArgs e, ElementStyle style, bool paintText)
//{
// if (m_PopupMode && m_RibbonTabItem != null)
// {
// }
// base.PaintInnerContent(e, style, paintText);
//}
/// <summary>
/// Gets or sets whether default control layout is used instead of Rendering layout for RibbonBar controls positioning. By default
/// internal layout logic is used so proper resizing of Ribbons can be performed. You can disable internal layout by setting this property
/// to true.
/// Default value is false.
/// </summary>
[Browsable(true),DefaultValue(false),Category("Layout"),Description("Indicates whether default control layout is used instead of Rendering layout for RibbonBar controls positioning.")]
public bool DefaultLayout
{
get { return m_DefaultLayout; }
set
{
m_DefaultLayout = value;
this.PerformLayout();
}
}
/// <summary>
/// Indicates whether style of the panel is managed by tab control automatically.
/// Set this to true if you would like to control style of the panel.
/// </summary>
[Browsable(true),DefaultValue(false),Category("Appearance"),Description("Indicates whether style of the panel is managed by tab control automatically. Set this to true if you would like to control style of the panel.")]
public bool UseCustomStyle
{
get {return m_UseCustomStyle;}
set {m_UseCustomStyle=value;}
}
/// <summary>
/// Gets or sets TabItem that this panel is attached to.
/// </summary>
[Browsable(false),DefaultValue(null),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public RibbonTabItem RibbonTabItem
{
get {return m_RibbonTabItem;}
set {m_RibbonTabItem=value;}
}
/// <summary>
/// Gets or sets whether last RibbonBar is stretched to fill available space inside of the panel. Default value is false.
/// </summary>
[Browsable(true),DefaultValue(false), Category("Layout"), Description("Whether last RibbonBar is stretched to fill available space inside of the panel.")]
public bool StretchLastRibbonBar
{
get { return m_StretchLastRibbonBar; }
set
{
m_StretchLastRibbonBar = value;
this.PerformLayout();
}
}
protected override void OnResize(EventArgs e)
{
m_ScrollOffset = 0;
DisposeThemeCachedBitmap();
base.OnResize(e);
}
/// <summary>
/// Gets or sets which edge of the parent container a control is docked to.
/// </summary>
[Browsable(false),DefaultValue(DockStyle.None)]
public override DockStyle Dock
{
get {return base.Dock;}
set {base.Dock=value;}
}
/// <summary>
/// Gets or sets the size of the control.
/// </summary>
[Browsable(false)]
public new Size Size
{
get {return base.Size;}
set {base.Size=value;}
}
/// <summary>
/// Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container.
/// </summary>
[Browsable(false)]
public new Point Location
{
get {return base.Location;}
set {base.Location=value;}
}
/// <summary>
/// Gets or sets a value indicating whether the control is displayed.
/// </summary>
[Browsable(false)]
public new bool Visible
{
get {return base.Visible;}
set {base.Visible=value;}
}
/// <summary>
/// Gets or sets which edges of the control are anchored to the edges of its container.
/// </summary>
[Browsable(false)]
public override AnchorStyles Anchor
{
get {return base.Anchor;}
set {base.Anchor=value;}
}
[Browsable(false), DefaultValue("")]
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
}
}
bool IKeyTipsControl.ProcessMnemonicEx(char charCode)
{
if (this.Controls.Count == 0) return false;
Control[] ca = new Control[this.Controls.Count];
this.Controls.CopyTo(ca, 0);
ArrayList controls = new ArrayList(ca);
controls.Sort(new XPositionComparer());
foreach (Control c in controls)
{
IKeyTipsControl ktc = c as IKeyTipsControl;
if (ktc!=null && c.Visible && c.Enabled)
{
string oldStack = ktc.KeyTipsKeysStack;
bool ret = ktc.ProcessMnemonicEx(charCode);
if (ret)
return true;
if (ktc.KeyTipsKeysStack != oldStack)
{
((IKeyTipsControl)this).KeyTipsKeysStack = ktc.KeyTipsKeysStack;
return false;
}
}
}
return false;
}
private bool m_ShowKeyTips = false;
bool IKeyTipsControl.ShowKeyTips
{
get
{
return m_ShowKeyTips;
}
set
{
m_ShowKeyTips = value;
Control[] controls = new Control[this.Controls.Count];
this.Controls.CopyTo(controls, 0);
foreach (Control c in controls)
{
if (c is IKeyTipsControl && c.Enabled && (c.Visible || !m_ShowKeyTips))
((IKeyTipsControl)c).ShowKeyTips = m_ShowKeyTips;
}
}
}
private string m_KeyTipsKeysStack = "";
string IKeyTipsControl.KeyTipsKeysStack
{
get { return m_KeyTipsKeysStack; }
set
{
m_KeyTipsKeysStack = value;
foreach (Control c in this.Controls)
{
if (c is IKeyTipsControl && c.Visible && c.Enabled)
((IKeyTipsControl)c).KeyTipsKeysStack = m_KeyTipsKeysStack;
}
}
}
#endregion
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,562 @@
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Collections.Generic;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Defines the internal container item for the ribbon strip control.
/// </summary>
[System.ComponentModel.ToolboxItem(false), System.ComponentModel.DesignTimeVisible(false)]
public class RibbonStripContainerItem : ImageItem, IDesignTimeProvider
{
#region Private Variables
private RibbonTabItemContainer m_ItemContainer = null;
private CaptionItemContainer m_CaptionContainer = null;
private SystemCaptionItem m_SystemCaptionItem = null;
private RibbonStrip m_RibbonStrip = null;
private SystemCaptionItem _WindowIcon = null;
private Separator _IconSeparator = null;
#endregion
#region Constructor
/// <summary>
/// Creates new instance of the class and initializes it with the parent RibbonStrip control.
/// </summary>
/// <param name="parent">Reference to parent RibbonStrip control</param>
public RibbonStripContainerItem(RibbonStrip parent)
{
m_RibbonStrip = parent;
// We contain other controls
m_IsContainer = true;
this.AccessibleRole = System.Windows.Forms.AccessibleRole.Grouping;
m_ItemContainer = new RibbonTabItemContainer();
m_ItemContainer.ContainerControl = parent;
m_ItemContainer.GlobalItem = false;
m_ItemContainer.WrapItems = false;
m_ItemContainer.EventHeight = false;
m_ItemContainer.UseMoreItemsButton = false;
m_ItemContainer.Stretch = true;
m_ItemContainer.Displayed = true;
m_ItemContainer.SystemContainer = true;
m_ItemContainer.PaddingTop = 0;
m_ItemContainer.PaddingBottom = 0;
m_ItemContainer.ItemSpacing = 1;
m_CaptionContainer = new CaptionItemContainer();
m_CaptionContainer.ContainerControl = parent;
m_CaptionContainer.GlobalItem = false;
m_CaptionContainer.WrapItems = false;
m_CaptionContainer.EventHeight = false;
m_CaptionContainer.EqualButtonSize = false;
m_CaptionContainer.ToolbarItemsAlign = eContainerVerticalAlignment.Top;
m_CaptionContainer.UseMoreItemsButton = false;
m_CaptionContainer.Stretch = true;
m_CaptionContainer.Displayed = true;
m_CaptionContainer.SystemContainer = true;
m_CaptionContainer.PaddingBottom = 0;
m_CaptionContainer.PaddingTop = 0;
m_CaptionContainer.ItemSpacing = 1;
m_CaptionContainer.TrackSubItemsImageSize = false;
m_CaptionContainer.ItemAdded += this.CaptionContainerNewItemAdded;
this.SubItems.Add(m_CaptionContainer);
this.SubItems.Add(m_ItemContainer);
SystemCaptionItem sc = new SystemCaptionItem();
sc.RestoreEnabled = false;
sc.IsSystemIcon = false;
sc.ItemAlignment = eItemAlignment.Far;
m_CaptionContainer.SubItems.Add(sc);
m_SystemCaptionItem = sc;
}
protected override void Dispose(bool disposing)
{
m_CaptionContainer.ItemAdded -= this.CaptionContainerNewItemAdded;
base.Dispose(disposing);
}
#endregion
#region Internal Implementation
private void CaptionContainerNewItemAdded(object sender, EventArgs e)
{
if (sender is BaseItem)
{
BaseItem item = sender as BaseItem;
if (!(item is SystemCaptionItem))
{
if (m_CaptionContainer.SubItems.Contains(m_SystemCaptionItem))
{
m_CaptionContainer.SubItems._Remove(m_SystemCaptionItem);
m_CaptionContainer.SubItems._Add(m_SystemCaptionItem);
}
}
}
}
internal void ReleaseSystemFocus()
{
m_ItemContainer.ReleaseSystemFocus();
if (m_RibbonStrip.CaptionVisible)
m_CaptionContainer.ReleaseSystemFocus();
}
public override void ContainerLostFocus(bool appLostFocus)
{
base.ContainerLostFocus(appLostFocus);
m_ItemContainer.ContainerLostFocus(appLostFocus);
if (m_RibbonStrip.CaptionVisible)
m_CaptionContainer.ContainerLostFocus(appLostFocus);
}
internal void SetSystemFocus()
{
if (m_RibbonStrip.CaptionVisible && m_ItemContainer.ExpandedItem()==null)
m_CaptionContainer.SetSystemFocus();
else
m_ItemContainer.SetSystemFocus();
}
private List<BaseItem> _HiddenCaptionItems = new List<BaseItem>();
private bool _MetroBackstageOpen = false;
/// <summary>
/// Gets whether Metro Backstage application menu is open.
/// </summary>
public bool MetroBackstageOpen
{
get { return _MetroBackstageOpen; }
internal set
{
if (_MetroBackstageOpen == value) return;
_MetroBackstageOpen = value;
if (value)
{
foreach (BaseItem item in m_CaptionContainer.SubItems)
{
if (item.Visible && item != m_SystemCaptionItem)
{
item.Displayed = false;
item.LockDisplayedChange = true;
_HiddenCaptionItems.Add(item);
}
}
}
else
{
foreach (BaseItem item in _HiddenCaptionItems)
{
item.Displayed = true;
item.LockDisplayedChange = false;
}
_HiddenCaptionItems.Clear();
NeedRecalcSize = true;
}
}
}
/// <summary>
/// Paints this base container
/// </summary>
public override void Paint(ItemPaintArgs pa)
{
if (this.SuspendLayout)
return;
m_ItemContainer.Paint(pa);
if (m_RibbonStrip.CaptionVisible)
m_CaptionContainer.Paint(pa);
}
public override void RecalcSize()
{
if (this.SuspendLayout)
return;
m_ItemContainer.Bounds = GetItemContainerBounds();
m_ItemContainer.RecalcSize();
if (m_ItemContainer.HeightInternal < 0) m_ItemContainer.HeightInternal = 0;
bool isMaximized = false;
bool isGlassEnabled = this.IsGlassEnabled;
if (m_RibbonStrip.CaptionVisible)
{
Size frameBorderSize = SystemInformation.FrameBorderSize;
Control c = this.ContainerControl as Control;
Form form = null;
if (c != null) form = c.FindForm();
if (form != null)
{
isMaximized = form.WindowState == FormWindowState.Maximized;
if (_WindowIcon != null)
_WindowIcon.SetVisibleDirect(form.ShowIcon);
}
if (form is RibbonForm)
{
NonClientInfo nci = ((RibbonForm)form).GetNonClientInfo();
frameBorderSize.Width = nci.LeftBorder; frameBorderSize.Height = nci.BottomBorder;
if (_WindowIcon != null)
_WindowIcon.SetVisibleDirect(form.ShowIcon && ((RibbonForm)form).RenderFormIcon);
}
if (_IconSeparator != null)
_IconSeparator.SetVisibleDirect(_WindowIcon.Visible);
m_CaptionContainer.Bounds = GetCaptionContainerBounds();
m_CaptionContainer.RecalcSize();
if (m_RibbonStrip.CaptionHeight == 0 && m_SystemCaptionItem.TopInternal < (frameBorderSize.Height - 1))
{
if (System.Environment.OSVersion.Version.Major >= 6 && !isGlassEnabled)
{
if (isMaximized)
{
m_SystemCaptionItem.TopInternal = 1;
if (_WindowIcon != null) _WindowIcon.TopInternal = Dpi.Factor.Height > 1 ? Dpi.Height5 : 6;
}
else
{
m_SystemCaptionItem.TopInternal = frameBorderSize.Height - Dpi.Height4;
if (_WindowIcon != null)
{
_WindowIcon.TopInternal = Math.Max(0, frameBorderSize.Height - (Dpi.Factor.Height > 1 ? Dpi.Height3 : 2));
}
}
}
else
{
if (EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(EffectiveStyle))
m_SystemCaptionItem.TopInternal = 1;
else
m_SystemCaptionItem.TopInternal = 0;
if (isGlassEnabled)
{
if (_WindowIcon != null) _WindowIcon.TopInternal = frameBorderSize.Height - Dpi.Width2;
if (_IconSeparator != null) _IconSeparator.TopInternal = frameBorderSize.Height - 4;
}
else
{
if (_WindowIcon != null) _WindowIcon.TopInternal = frameBorderSize.Height + Dpi.Width2;
if (_IconSeparator != null) _IconSeparator.TopInternal = frameBorderSize.Height;
}
}
}
// Adjust the Y position of the items inside of the caption container since they are top aligned and
// quick access toolbar items should be aligned with the bottom of the system caption item.
if (System.Environment.OSVersion.Version.Major >= 6)
{
int topOffset = 2;
if (!isGlassEnabled)
topOffset++;
else if (isMaximized)
topOffset += 1;
int maxBottom = 0;
foreach (BaseItem item in m_CaptionContainer.SubItems)
{
if (!(item is ApplicationButton) && item != m_SystemCaptionItem && item!=_WindowIcon)
item.TopInternal += topOffset;
maxBottom = Math.Max(item.Bounds.Bottom, maxBottom);
}
if (m_CaptionContainer.MoreItems != null)
m_CaptionContainer.MoreItems.TopInternal += topOffset;
if (maxBottom > m_CaptionContainer.HeightInternal) m_CaptionContainer.SetDisplayRectangle(new Rectangle(m_CaptionContainer.Bounds.X, m_CaptionContainer.Bounds.Y, m_CaptionContainer.Bounds.Width, maxBottom));
}
else
{
int maxBottom = 0;
foreach (BaseItem item in m_CaptionContainer.SubItems)
{
if (item.HeightInternal < m_SystemCaptionItem.HeightInternal && (item!= _IconSeparator && item!= _WindowIcon))
{
//item.TopInternal += (m_SystemCaptionItem.HeightInternal - item.HeightInternal);
item.TopInternal = (m_SystemCaptionItem.Bounds.Bottom - (item.HeightInternal + ((item is LabelItem) ? 2 : 0)));
maxBottom = Math.Max(item.Bounds.Bottom, maxBottom);
}
}
if (m_CaptionContainer.MoreItems != null)
m_CaptionContainer.MoreItems.TopInternal += (m_SystemCaptionItem.HeightInternal - m_CaptionContainer.MoreItems.HeightInternal);
if (maxBottom > m_CaptionContainer.HeightInternal) m_CaptionContainer.SetDisplayRectangle(new Rectangle(m_CaptionContainer.Bounds.X, m_CaptionContainer.Bounds.Y, m_CaptionContainer.Bounds.Width, maxBottom));
}
if (m_ItemContainer.HeightInternal == 0)
this.HeightInternal = m_CaptionContainer.HeightInternal;
else
this.HeightInternal = m_ItemContainer.Bounds.Bottom;// -m_CaptionContainer.Bounds.Top;
}
else
{
int h = m_ItemContainer.HeightInternal;
if (m_RibbonStrip.TabGroupsVisible)
h += m_RibbonStrip.TabGroupHeight + 1;
this.HeightInternal = h;
}
base.RecalcSize();
}
private bool IsGlassEnabled
{
get
{
if (this.DesignMode || !m_RibbonStrip.CanSupportGlass) return false;
RibbonForm form = m_RibbonStrip.FindForm() as RibbonForm;
if (form != null) return form.IsGlassEnabled;
return WinApi.IsGlassEnabled;
}
}
private Rectangle GetItemContainerBounds()
{
return m_RibbonStrip.GetItemContainerBounds();
}
private Rectangle GetCaptionContainerBounds()
{
return m_RibbonStrip.GetCaptionContainerBounds();
}
/// <summary>
/// Gets reference to internal ribbon strip container that contains tabs and/or other items.
/// </summary>
public GenericItemContainer RibbonStripContainer
{
get { return m_ItemContainer; }
}
/// <summary>
/// Gets reference to internal caption container item that contains the quick toolbar, start button and system caption item.
/// </summary>
public GenericItemContainer CaptionContainer
{
get { return m_CaptionContainer; }
}
public SystemCaptionItem SystemCaptionItem
{
get { return m_SystemCaptionItem; }
}
/// <summary>
/// Returns copy of GenericItemContainer item
/// </summary>
public override BaseItem Copy()
{
RibbonStripContainerItem objCopy = new RibbonStripContainerItem(m_RibbonStrip);
this.CopyToItem(objCopy);
return objCopy;
}
protected override void CopyToItem(BaseItem copy)
{
RibbonStripContainerItem objCopy = copy as RibbonStripContainerItem;
base.CopyToItem(objCopy);
}
public override void InternalClick(MouseButtons mb, Point mpos)
{
m_ItemContainer.InternalClick(mb, mpos);
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalClick(mb, mpos);
}
public override void InternalDoubleClick(MouseButtons mb, Point mpos)
{
m_ItemContainer.InternalDoubleClick(mb, mpos);
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalDoubleClick(mb, mpos);
}
public override void InternalMouseDown(MouseEventArgs objArg)
{
m_ItemContainer.InternalMouseDown(objArg);
if (m_RibbonStrip.CaptionVisible)
{
if(this.DesignMode && m_CaptionContainer.ItemAtLocation(objArg.X, objArg.Y)!=null || !this.DesignMode)
m_CaptionContainer.InternalMouseDown(objArg);
}
}
public override void InternalMouseHover()
{
m_ItemContainer.InternalMouseHover();
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalMouseHover();
}
public override void InternalMouseLeave()
{
m_ItemContainer.InternalMouseLeave();
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalMouseLeave();
}
public override void InternalMouseMove(MouseEventArgs objArg)
{
m_ItemContainer.InternalMouseMove(objArg);
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalMouseMove(objArg);
}
public override void InternalMouseUp(MouseEventArgs objArg)
{
m_ItemContainer.InternalMouseUp(objArg);
if (m_RibbonStrip.CaptionVisible) m_CaptionContainer.InternalMouseUp(objArg);
}
public override void InternalKeyDown(KeyEventArgs objArg)
{
BaseItem expanded = this.ExpandedItem();
if (expanded == null)
expanded = m_CaptionContainer.ExpandedItem();
if (expanded == null)
expanded = m_ItemContainer.ExpandedItem();
if (expanded == null || !m_RibbonStrip.CaptionVisible)
{
m_ItemContainer.InternalKeyDown(objArg);
if (!objArg.Handled && m_RibbonStrip.CaptionVisible)
m_CaptionContainer.InternalKeyDown(objArg);
}
else
{
if (expanded.Parent == m_ItemContainer)
{
m_ItemContainer.InternalKeyDown(objArg);
}
else
{
m_CaptionContainer.InternalKeyDown(objArg);
}
}
}
/// <summary>
/// Return Sub Item at specified location
/// </summary>
public override BaseItem ItemAtLocation(int x, int y)
{
if (m_ItemContainer.DisplayRectangle.Contains(x, y))
return m_ItemContainer.ItemAtLocation(x, y);
if (m_CaptionContainer.DisplayRectangle.Contains(x, y))
return m_CaptionContainer.ItemAtLocation(x, y);
return null;
}
protected override void OnStyleChanged()
{
if (this.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(this.EffectiveStyle))
{
if (_WindowIcon == null)
{
_IconSeparator = new Separator("sys_caption_separator");
_IconSeparator.SetSystemItem(true);
m_CaptionContainer.SubItems._Add(_IconSeparator, 0);
_WindowIcon = new SystemCaptionItem();
_WindowIcon.Name = "sys_caption_icon";
_WindowIcon.Enabled = false;
_WindowIcon.Style = this.Style;
_WindowIcon.IsSystemIcon = true;
_WindowIcon.QueryIconOnPaint = true;
m_CaptionContainer.SubItems._Add(_WindowIcon, 0);
}
}
else if (this.EffectiveStyle == eDotNetBarStyle.Windows7)
{
if (_WindowIcon == null)
{
_IconSeparator = new Separator("sys_caption_separator");
_IconSeparator.FixedSize = new Size(3, 12);
_IconSeparator.SetSystemItem(true);
m_CaptionContainer.SubItems._Add(_IconSeparator, 0);
_WindowIcon = new SystemCaptionItem();
_WindowIcon.Name = "sys_caption_icon";
_WindowIcon.Enabled = false;
_WindowIcon.Style = this.Style;
_WindowIcon.IsSystemIcon = true;
_WindowIcon.QueryIconOnPaint = true;
m_CaptionContainer.SubItems._Add(_WindowIcon, 0);
}
}
else if(_WindowIcon!=null)
{
if (m_CaptionContainer.SubItems.Contains(_WindowIcon))
m_CaptionContainer.SubItems._Remove(_WindowIcon);
_WindowIcon.Dispose();
_WindowIcon = null;
if (m_CaptionContainer.SubItems.Contains(_IconSeparator))
m_CaptionContainer.SubItems._Remove(_IconSeparator);
_IconSeparator.Dispose();
_IconSeparator = null;
}
base.OnStyleChanged();
}
#endregion
#region IDesignTimeProvider Members
public InsertPosition GetInsertPosition(Point pScreen, BaseItem DragItem)
{
InsertPosition pos = m_ItemContainer.GetInsertPosition(pScreen, DragItem);
if(pos==null && m_RibbonStrip.CaptionVisible)
pos = m_CaptionContainer.GetInsertPosition(pScreen, DragItem);
return pos;
}
public void DrawReversibleMarker(int iPos, bool Before)
{
//DesignTimeProviderContainer.DrawReversibleMarker(this, iPos, Before);
}
public void InsertItemAt(BaseItem objItem, int iPos, bool Before)
{
//DesignTimeProviderContainer.InsertItemAt(this, objItem, iPos, Before);
}
/// <summary>
/// Gets or sets a value indicating whether the item is expanded or not. For Popup items this would indicate whether the item is popped up or not.
/// </summary>
[System.ComponentModel.Browsable(false), System.ComponentModel.DefaultValue(false), System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden)]
public override bool Expanded
{
get
{
return base.Expanded;
}
set
{
base.Expanded = value;
if (!value)
{
foreach (BaseItem item in this.SubItems)
item.Expanded = false;
}
}
}
/// <summary>
/// When parent items does recalc size for its sub-items it should query
/// image size and store biggest image size into this property.
/// </summary>
[System.ComponentModel.Browsable(false), System.ComponentModel.DesignerSerializationVisibility(System.ComponentModel.DesignerSerializationVisibility.Hidden), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public override System.Drawing.Size SubItemsImageSize
{
get
{
return base.SubItemsImageSize;
}
set
{
//m_SubItemsImageSize = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
internal abstract class RibbonTabGroupPainter
{
public abstract void PaintTabGroup(RibbonTabGroupRendererEventArgs e);
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for RenderRibbonTabGroup event.
/// </summary>
public class RibbonTabGroupRendererEventArgs : EventArgs
{
/// <summary>
/// Gets or sets Graphics object group is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets or sets RibbonTabItemGroup being rendered.
/// </summary>
public RibbonTabItemGroup RibbonTabItemGroup = null;
/// <summary>
/// Gets or sets the bounds of the tab group. Bounds specified here are bounds of the tab group title. GroupBounds contains the bounds
/// that include all tabs that belong to the tab group.
/// </summary>
public Rectangle Bounds = Rectangle.Empty;
/// <summary>
/// Gets or sets the font that should be used to render group text.
/// </summary>
public Font GroupFont = null;
/// <summary>
/// Gets or sets group bounds including the tabs that belong to the group.
/// </summary>
public Rectangle GroupBounds = Rectangle.Empty;
/// <summary>
/// Gets or sets the effective style for the group.
/// </summary>
public eDotNetBarStyle EffectiveStyle = eDotNetBarStyle.Office2007;
/// <summary>
/// Gets whether Windows Vista glass is enabled.
/// </summary>
public ItemPaintArgs ItemPaintArgs = null;
public RibbonTabGroupRendererEventArgs(Graphics g, RibbonTabItemGroup group, Rectangle bounds, Rectangle groupBounds, Font font, ItemPaintArgs pa, eDotNetBarStyle effectiveStyle)
{
this.Graphics = g;
this.RibbonTabItemGroup = group;
this.Bounds = bounds;
this.GroupBounds = groupBounds;
this.GroupFont = font;
this.ItemPaintArgs = pa;
this.EffectiveStyle = effectiveStyle;
}
}
}

View File

@@ -0,0 +1,760 @@
using System.ComponentModel;
using System.Drawing;
using System;
using System.Windows.Forms;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents Rendering Tab used on RibbonControl.
/// </summary>
[ToolboxItem(false), DesignTimeVisible(false), Designer("DevComponents.DotNetBar.Design.RibbonTabItemDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class RibbonTabItem:ButtonItem
{
#region Private Variables & Constructor
private RibbonPanel m_Panel=null;
private RibbonTabItemGroup m_Group=null;
private eRibbonTabColor m_ColorTable = eRibbonTabColor.Default; private string m_CashedColorTableName = "Default";
private bool m_ReducedSize = false;
private int m_PaddingHorizontal = 0;
#endregion
#region Internal Implementation
private bool _RenderTabState = true;
/// <summary>
/// Gets or sets whether tab renders its state. Used internally by DotNetBar. Do not set.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
internal bool RenderTabState
{
get { return _RenderTabState; }
set
{
_RenderTabState = value;
if (this.ContainerControl is System.Windows.Forms.Control)
((System.Windows.Forms.Control)this.ContainerControl).Invalidate();
else
this.Refresh();
}
}
protected override bool IsFadeEnabled
{
get
{
if ((this.EffectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(this.EffectiveStyle)) && WinApi.IsGlassEnabled)
return false;
return base.IsFadeEnabled;
}
}
/// <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 m_PaddingHorizontal; }
set
{
m_PaddingHorizontal = value;
UpdateTabAppearance();
}
}
/// <summary>
/// Selects the tab.
/// </summary>
public void Select()
{
this.Checked = true;
}
/// <summary>
/// Gets or sets whether size of the tab has been reduced below the default calculated size.
/// </summary>
internal bool ReducedSize
{
get { return m_ReducedSize; }
set { m_ReducedSize = value; }
}
///// <summary>
///// Gets or sets the custom color name. Name specified here must be represented by the coresponding object with the same name that is part
///// of the Office2007ColorTable.RibbonTabItemColors collection. See documentation for Office2007ColorTable.RibbonTabItemColors for more information.
///// If color table with specified name cannot be found default color will be used. Valid settings for this property override any
///// setting to the Color property.
///// Applies to items with Office 2007 style only.
///// </summary>
//[Browsable(true), DefaultValue(""), Category("Appearance"), Description("Indicates custom color table name for the item when Office 12 style is used.")]
//public string CustomColorName
//{
// get { return m_CustomColorName; }
// set
// {
// m_CustomColorName = value;
// this.Refresh();
// }
//}
/// <summary>
/// Gets or sets the predefined color of item. Color specified here applies to items with Office 2007 style only. It does not have
/// any effect on other styles. Default value is eRibbonTabColor.Default
/// </summary>
[Browsable(true), DefaultValue(eRibbonTabColor.Default), Category("Appearance"), Description("Indicates predefined color of item when Office 2007 style is used.")]
public new eRibbonTabColor ColorTable
{
get { return m_ColorTable; }
set
{
if (m_ColorTable != value)
{
m_ColorTable = value;
m_CashedColorTableName = Enum.GetName(typeof(eRibbonTabColor), m_ColorTable);
this.Refresh();
}
}
}
internal override string GetColorTableName()
{
return this.CustomColorName != "" ? this.CustomColorName : m_CashedColorTableName;
}
/// <summary>
/// Gets or sets the group this tab belongs to. Groups are optional classification that is used to
/// visually group tabs that belong to same functions. These tabs should be positioned next to each other.
/// </summary>
[Editor("DevComponents.DotNetBar.Design.RibbonTabItemGroupTypeEditor, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf", typeof(System.Drawing.Design.UITypeEditor)), Browsable(true), DefaultValue(null), DevCoBrowsable(true), Category("Tab Group"), Description("Indicates the group tab belongs to.")]
public RibbonTabItemGroup Group
{
get {return m_Group;}
set
{
m_Group=value;
if(this.DesignMode)
{
ItemControl c=this.ContainerControl as ItemControl;
if(c!=null)
c.RecalcLayout();
}
}
}
/// <summary>
/// Resets Group property to default value null.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
public void ResetGroup()
{
TypeDescriptor.GetProperties(this)["Group"].SetValue(this,null);
}
/// <summary>
/// Gets or sets the panel assigned to this ribbon tab item.
/// </summary>
[Browsable(false),DefaultValue(null)]
public RibbonPanel Panel
{
get {return m_Panel;}
set
{
if (m_Panel != null)
m_Panel.RibbonTabItem = null;
m_Panel=value;
if (m_Panel != null)
m_Panel.RibbonTabItem = this;
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;
RibbonTabItem b=item as RibbonTabItem;
if (b != null && b.Checked)
{
if (this.DesignMode)
TypeDescriptor.GetProperties(b)["Checked"].SetValue(b, false);
else
b.Checked = false;
}
}
}
m_LastAutoExpandTime = DateTime.MinValue;
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 && m_Panel!=null)
{
if (this.DesignMode)
{
if (!m_Panel.Visible) m_Panel.Visible = true;
TypeDescriptor.GetProperties(m_Panel)["Visible"].SetValue(m_Panel, true);
m_Panel.BringToFront();
}
else
{
if (!m_Panel.IsDisposed)
{
m_Panel.SuspendLayout();
m_Panel.Visible = true;
m_Panel.ResumeLayout(true);
m_Panel.BringToFront();
}
}
}
else if(!this.Checked && m_Panel!=null && !m_Panel.IsPopupMode) // Panels in popup mode will be taken care of by Ribbon
{
if (this.DesignMode)
TypeDescriptor.GetProperties(m_Panel)["Visible"].SetValue(m_Panel, false);
else
m_Panel.Visible = false;
}
}
/// <summary>
/// Occurs just before Click event is fired.
/// </summary>
protected override void OnClick()
{
base.OnClick();
if (!this.Checked)
{
if (this.DesignMode)
TypeDescriptor.GetProperties(this)["Checked"].SetValue(this, true);
else
this.Checked = true;
}
System.Windows.Forms.Control c = this.ContainerControl as System.Windows.Forms.Control;
if (c is RibbonStrip && ((RibbonStrip)c).AutoExpand && c.Parent is RibbonControl)
{
RibbonControl rc = (RibbonControl)c.Parent;
if (!rc.Expanded)
{
TimeSpan span = DateTime.Now.Subtract(m_LastAutoExpandTime);
if (m_LastAutoExpandTime == DateTime.MinValue ||
Math.Abs(span.TotalMilliseconds) > System.Windows.Forms.SystemInformation.DoubleClickTime)
{
rc.RibbonTabItemClick(this);
m_LastAutoExpandTime = DateTime.MinValue;
}
}
}
}
private DateTime m_LastAutoExpandTime = DateTime.MinValue;
/// <summary>
/// Occurs when the item is clicked. This is used by internal implementation only.
/// </summary>
//[System.ComponentModel.Browsable(false), System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
//public override void InternalClick(System.Windows.Forms.MouseButtons mb, System.Drawing.Point mpos)
//{
// base.InternalClick(mb, mpos);
//}
protected override void InvokeDoubleClick()
{
System.Windows.Forms.Control c = this.ContainerControl as System.Windows.Forms.Control;
if (c is RibbonStrip && ((RibbonStrip)c).AutoExpand && c.Parent is RibbonControl)
{
//if (m_LastAutoExpandTime == DateTime.Now || m_LastAutoExpandTime == DateTime.MinValue ||
// m_LastAutoExpandTime != DateTime.Now && Math.Abs(DateTime.Now.Subtract(m_LastAutoExpandTime).Milliseconds) > System.Windows.Forms.SystemInformation.DoubleClickTime)
//{
((RibbonControl)c.Parent).RibbonTabItemDoubleClick(this);
m_LastAutoExpandTime = DateTime.Now; // DateTime.MinValue;
//}
}
base.InvokeDoubleClick();
}
/// <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;
RibbonTabItem b=item as RibbonTabItem;
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>
/// Occurs after item visual style has changed.
/// </summary>
protected override void OnStyleChanged()
{
base.OnStyleChanged();
UpdateTabAppearance();
}
private void UpdateTabAppearance()
{
eDotNetBarStyle effectiveStyle = this.EffectiveStyle;
if (effectiveStyle == eDotNetBarStyle.Office2007)
{
this.VerticalPadding = 0;
this.HorizontalPadding = 12 + m_PaddingHorizontal;
}
else if (effectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(effectiveStyle))
{
this.VerticalPadding = 1;
this.HorizontalPadding = 16 + m_PaddingHorizontal;
}
else if (effectiveStyle == eDotNetBarStyle.Windows7)
{
this.VerticalPadding = 0;
this.HorizontalPadding = 16 + m_PaddingHorizontal;
}
else if (effectiveStyle == eDotNetBarStyle.Office2003)
{
this.VerticalPadding = -1;
this.HorizontalPadding = 2 + m_PaddingHorizontal;
}
else
{
this.VerticalPadding = 0;
this.HorizontalPadding = 0 + m_PaddingHorizontal;
}
this.NeedRecalcSize = true;
this.OnAppearanceChanged();
}
protected override void ScaleItem(SizeF factor)
{
UpdateTabAppearance();
base.ScaleItem(factor);
}
/// <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()
{
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);
}
#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 or sets the text color of the button.
/// </summary>
[System.ComponentModel.Browsable(false), DevCoBrowsable(false), EditorBrowsable(EditorBrowsableState.Never), System.ComponentModel.Category("Appearance"), System.ComponentModel.Description("The foreground color used to display text.")]
public override Color ForeColor
{
get
{
return base.ForeColor;
}
set
{
base.ForeColor = value;
}
}
#endregion
}
}

View File

@@ -0,0 +1,115 @@
using System;
using System.Collections;
using System.Text;
namespace DevComponents.DotNetBar
{
internal class RibbonTabItemContainer : GenericItemContainer
{
protected override void OnStyleChanged()
{
eDotNetBarStyle effectiveStyle = this.EffectiveStyle;
if (effectiveStyle == eDotNetBarStyle.Windows7)
{
this.PaddingLeft = 0;
this.PaddingRight = 0;
this.PaddingTop = 0;
}
else if (effectiveStyle == eDotNetBarStyle.Office2010 || StyleManager.IsMetro(effectiveStyle))
{
this.PaddingLeft = 0;
this.PaddingRight = 1;
this.PaddingTop = 1;
}
else
{
this.PaddingLeft = 1;
this.PaddingRight = 1;
this.PaddingTop = 1;
}
base.OnStyleChanged();
}
protected override bool OnBeforeLayout()
{
if (this.Orientation != eOrientation.Horizontal)
return true;
ArrayList ribbonTabItems = new ArrayList();
int totalWidth = 0;
int totalRibbonTabItemsWidth = 0;
int minimumSize = 24;
int availableWidth = this.WidthInternal - (this.PaddingLeft + this.PaddingRight);
foreach (BaseItem item in this.SubItems)
{
if (!item.Visible)
continue;
item.RecalcSize();
totalWidth += (item.WidthInternal + this.ItemSpacing);
if (item is RibbonTabItem)
{
// Reset reduced size flag
((RibbonTabItem)item).ReducedSize = false;
ribbonTabItems.Add(item);
totalRibbonTabItemsWidth += (item.WidthInternal + this.ItemSpacing);
}
}
int totalReduction = totalWidth - availableWidth;
if (totalWidth > availableWidth && totalRibbonTabItemsWidth > 0)
{
if (totalReduction >= totalRibbonTabItemsWidth - (minimumSize * ribbonTabItems.Count + ribbonTabItems.Count - 1))
{
foreach (RibbonTabItem item in ribbonTabItems)
{
item.WidthInternal = minimumSize;
item.ReducedSize = true;
}
}
else
{
float reduction = 1 - (float)totalReduction / (float)totalRibbonTabItemsWidth;
bool reducedSize = false;
if (reduction <= .75)
reducedSize = true;
for (int i = 0; i < ribbonTabItems.Count; i++)
{
RibbonTabItem item = ribbonTabItems[i] as RibbonTabItem;
item.ReducedSize = reducedSize;
if (i == ribbonTabItems.Count - 1)
{
item.WidthInternal -= totalReduction;
}
else
{
int width = (int)(item.WidthInternal * reduction);
if (width < minimumSize)
width = minimumSize;
totalReduction -= (item.WidthInternal - width);
item.WidthInternal = width;
}
}
}
}
return false;
}
protected override bool ShouldCollapseParentItem()
{
BaseItem expandedItem = ExpandedItem();
if (expandedItem is ApplicationButton)
{
RibbonStrip strip = this.ContainerControl as RibbonStrip;
if (strip != null)
{
BaseItem item = strip.HitTest(MouseDownPt);
if (item is SystemCaptionItem)
return false;
}
}
return true;
}
}
}

View File

@@ -0,0 +1,249 @@
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Represents a group RibbonTabItem objects are assigned to.
/// </summary>
[DesignTimeVisible(false), ToolboxItem(false), TypeConverterAttribute("DevComponents.DotNetBar.Design.RibbonTabItemGroupConverter, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class RibbonTabItemGroup:Component
{
#region Private Variables & Constructor
private ElementStyle m_Style=null;
private string m_GroupTitle="";
private RibbonStrip m_ParentRibbonStrip=null;
[EditorBrowsable(EditorBrowsableState.Never), Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public ArrayList DisplayPositions=new ArrayList();
private eRibbonTabGroupColor m_Color = eRibbonTabGroupColor.Default;
private string m_Name = "";
private string m_CustomColorName = "";
public RibbonTabItemGroup()
{
m_Style=new ElementStyle();
m_Style.StyleChanged+=new EventHandler(StyleChanged);
}
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets the predefined color of the group. Color specified here applies to groups with Office 12 style only. It does not have
/// any effect on other styles. Default value is eRibbonTabGroupColor.Default
/// </summary>
[Browsable(true), DefaultValue(eRibbonTabGroupColor.Default), Category("Appearance"), Description("Indicates predefined color of the group when Office 12 style is used.")]
public eRibbonTabGroupColor Color
{
get { return m_Color; }
set
{
if (m_Color != value)
{
m_Color = value;
if (this.ParentRibbonStrip != null)
this.ParentRibbonStrip.Invalidate();
}
}
}
/// <summary>
/// Gets or sets the custom color name. Name specified here must be represented by the coresponding object with the same name that is part
/// of the Office2007ColorTable.RibbonTabGroupColors collection. See documentation for Office2007ColorTable.RibbonTabGroupColors for more information.
/// If color table with specified name cannot be found default color will be used. Valid settings for this property override any
/// setting to the Color property.
/// </summary>
[Browsable(true), DevCoBrowsable(false), DefaultValue(""), Category("Appearance"), Description("Indicates custom color table name for the button when Office 2007 style is used.")]
public string CustomColorName
{
get { return m_CustomColorName; }
set
{
m_CustomColorName = value;
if (this.ParentRibbonStrip != null)
this.ParentRibbonStrip.Invalidate();
}
}
/// <summary>
/// Gets the style for tab group.
/// </summary>
[Browsable(false),Category("Background"),Description("Gets the style for tab group."),DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public ElementStyle Style
{
get {return m_Style;}
}
/// <summary>
/// Gets or sets title of the group that will be displayed when group is visually represented.
/// </summary>
[Browsable(true), DevCoBrowsable(true), DefaultValue(""), Localizable(true)]
public string GroupTitle
{
get {return m_GroupTitle;}
set
{
m_GroupTitle=value;
if(this.DesignMode && m_ParentRibbonStrip!=null)
{
m_ParentRibbonStrip.RecalcLayout();
}
}
}
private void StyleChanged(object sender, EventArgs e)
{
if(m_ParentRibbonStrip!=null)
m_ParentRibbonStrip.Refresh();
}
/// <summary>
/// Gets or sets parent ribbon strip for this group.
/// </summary>
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden),Browsable(false)]
internal RibbonStrip ParentRibbonStrip
{
get {return m_ParentRibbonStrip;}
set
{
m_ParentRibbonStrip=value;
if(m_ParentRibbonStrip!=null)
m_Style.SetColorScheme(m_ParentRibbonStrip.ColorScheme);
}
}
public override string ToString()
{
if(m_GroupTitle.Length>0)
return m_GroupTitle;
return base.ToString ();
}
/// <summary>
/// Gets or sets whether RibbonTabItem objects that belong to this group are visible. Setting this property will
/// show/hide all RibbonTabItem objects that are assigned to this group through RibbonTabItem.Group property.
/// </summary>
[Browsable(false),DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool Visible
{
get
{
if(m_ParentRibbonStrip==null)
return true;
bool visible=false;
foreach(BaseItem item in m_ParentRibbonStrip.Items)
{
if(item is RibbonTabItem)
{
RibbonTabItem tab=item as RibbonTabItem;
if(tab.Group == this && tab.Visible)
{
visible=true;
break;
}
}
}
return visible;
}
set
{
if(m_ParentRibbonStrip==null)
return;
foreach(BaseItem item in m_ParentRibbonStrip.Items)
{
if(item is RibbonTabItem)
{
RibbonTabItem tab=item as RibbonTabItem;
if(tab.Group==this)
tab.Visible=value;
}
}
m_ParentRibbonStrip.RecalcLayout();
}
}
/// <summary>
/// Gets whether any tab from this tab group is selected.
/// </summary>
[Browsable(false)]
public bool IsTabFromGroupSelected
{
get
{
if(m_ParentRibbonStrip==null)
return false;
foreach(BaseItem item in m_ParentRibbonStrip.Items)
{
if(item is RibbonTabItem)
{
RibbonTabItem tab=item as RibbonTabItem;
if (tab.Group == this && tab.Checked)
return true;
}
}
return false;
}
}
/// <summary>
/// Selected first tab that is part of this group.
/// </summary>
public void SelectFirstTab()
{
if (m_ParentRibbonStrip == null)
return;
foreach (BaseItem item in m_ParentRibbonStrip.Items)
{
if (item is RibbonTabItem)
{
RibbonTabItem tab = item as RibbonTabItem;
if (tab.Group == this && tab.Visible)
{
tab.Checked = true;
break;
}
}
}
}
/// <summary>
/// Gets or sets name of the group that can be used to identify item from the code.
/// </summary>
[Browsable(false), Category("Design"), Description("Indicates the name used to identify the group.")]
public string Name
{
get
{
if (this.Site != null)
m_Name = this.Site.Name;
return m_Name;
}
set
{
if (this.Site != null)
this.Site.Name = value;
if (value == null)
m_Name = "";
else
m_Name = value;
}
}
/// <summary>
/// Gets an array of Rectangle objects that describe the visual position on the ribbon control of the group titles displayed.
/// If tabs that belong to a tab group are not next to each other then there will be multiple rectangle returned as part of the array
/// for each tab group that is apart.
/// </summary>
[Browsable(false)]
public Rectangle[] TitleBounds
{
get
{
return (Rectangle[])DisplayPositions.ToArray(typeof(Rectangle));
}
}
#endregion
}
}

View File

@@ -0,0 +1,151 @@
using System;
using System.Collections;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Collection of RibbonTabItemGroup objects.
/// </summary>
public class RibbonTabItemGroupCollection:CollectionBase
{
#region Private Variables and Events
public event EventHandler GroupRemoved;
public event EventHandler GroupAdded;
private RibbonStrip m_Owner=null;
#endregion
#region Internal Implementation
/// <summary>
/// Adds new object to the collection.
/// </summary>
/// <param name="tab">Object to add.</param>
/// <returns>Index of newly added object.</returns>
public int Add(RibbonTabItemGroup tab)
{
return List.Add(tab);
}
/// <summary>
/// Adds new objects to the collection.
/// </summary>
/// <param name="groups">Array of groups to add.</param>
public void AddRange(RibbonTabItemGroup[] groups)
{
foreach(RibbonTabItemGroup doc in groups)
List.Add(doc);
}
/// <summary>
/// Returns reference to the object in collection based on it's index.
/// </summary>
public RibbonTabItemGroup this[int index]
{
get {return (RibbonTabItemGroup)(List[index]);}
set {List[index] = value;}
}
/// <summary>
/// Returns reference to the object in collection based on it's name.
/// </summary>
public RibbonTabItemGroup this[string name]
{
get
{
foreach (RibbonTabItemGroup g in this.List)
{
if (g.Name == name)
return g;
}
return null;
}
}
/// <summary>
/// Inserts new object into the collection.
/// </summary>
/// <param name="index">Position of the object.</param>
/// <param name="value">Object to insert.</param>
public void Insert(int index, RibbonTabItemGroup value)
{
List.Insert(index, value);
}
/// <summary>
/// Returns index of the object inside of the collection.
/// </summary>
/// <param name="value">Reference to the object.</param>
/// <returns>Index of the object.</returns>
public int IndexOf(RibbonTabItemGroup value)
{
return List.IndexOf(value);
}
/// <summary>
/// Returns whether collection contains specified object.
/// </summary>
/// <param name="value">Object to look for.</param>
/// <returns>true if object is part of the collection, otherwise false.</returns>
public bool Contains(RibbonTabItemGroup value)
{
return List.Contains(value);
}
/// <summary>
/// Removes specified object from the collection.
/// </summary>
/// <param name="value"></param>
public void Remove(RibbonTabItemGroup value)
{
List.Remove(value);
}
protected override void OnRemoveComplete(int index,object value)
{
base.OnRemoveComplete(index,value);
RibbonTabItemGroup item=value as RibbonTabItemGroup;
item.ParentRibbonStrip=null;
if(GroupRemoved!=null)
GroupRemoved(item,new EventArgs());
}
protected override void OnInsertComplete(int index,object value)
{
base.OnInsertComplete(index,value);
RibbonTabItemGroup item=value as RibbonTabItemGroup;
if(m_Owner!=null)
item.ParentRibbonStrip=m_Owner;
if(GroupAdded!=null)
GroupAdded(item,new EventArgs());
}
/// <summary>
/// Copies collection into the specified array.
/// </summary>
/// <param name="array">Array to copy collection to.</param>
/// <param name="index">Starting index.</param>
public void CopyTo(RibbonTabItemGroup[] array, int index)
{
List.CopyTo(array, index);
}
/// <summary>
/// Copies contained items to the RibbonTabItemGroup array.
/// </summary>
/// <param name="array">Array to copy to.</param>
internal void CopyTo(RibbonTabItemGroup[] array)
{
List.CopyTo(array,0);
}
internal RibbonStrip Owner
{
get {return m_Owner;}
set {m_Owner=value;}
}
protected override void OnClear()
{
base.OnClear();
}
#endregion
}
}

View File

@@ -0,0 +1,54 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for ButtonItem rendering.
/// </summary>
public class RibbonTabItemRendererEventArgs
{
/// <summary>
/// Gets or sets Graphics object group is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets the reference to ButtonItem instance being rendered.
/// </summary>
public RibbonTabItem RibbonTabItem = null;
/// <summary>
/// Reference to internal data.
/// </summary>
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Creates new instance of the object.
/// </summary>
public RibbonTabItemRendererEventArgs() { }
/// <summary>
/// Creates new instance of the object and initializes it with default values
/// </summary>
/// <param name="g">Reference to Graphics object.</param>
/// <param name="button">Reference to ButtonItem object.</param>
public RibbonTabItemRendererEventArgs(Graphics g, RibbonTabItem button)
{
this.Graphics = g;
this.RibbonTabItem = button;
}
/// <summary>
/// Creates new instance of the object and initializes it with default values
/// </summary>
/// <param name="g">Reference to Graphics object.</param>
/// <param name="button">Reference to ButtonItem object.</param>
internal RibbonTabItemRendererEventArgs(Graphics g, RibbonTabItem button, ItemPaintArgs pa)
{
this.Graphics = g;
this.RibbonTabItem = button;
this.ItemPaintArgs = pa;
}
}
}

View File

@@ -0,0 +1,125 @@
using System;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for SimpleElement.
/// </summary>
internal class SimpleElement:ISimpleElement
{
#region Private Variables
private Rectangle m_Bounds=Rectangle.Empty;
private Rectangle m_ImageBounds=Rectangle.Empty;
private Rectangle m_TextBounds=Rectangle.Empty;
private Image m_Image=null;
private eSimplePartAlignment m_ImageAlignment=eSimplePartAlignment.NearCenter;
private string m_Text="";
private int m_FixedWidth=0;
#endregion
#region ISimpleElement Members
public int FixedWidth
{
get
{
return m_FixedWidth;
}
set
{
m_FixedWidth=value;
}
}
public bool ImageVisible
{
get
{
return m_Image!=null;
}
}
public System.Drawing.Size ImageLayoutSize
{
get
{
if(m_Image==null)
return Size.Empty;
return m_Image.Size;
}
}
public DevComponents.DotNetBar.eSimplePartAlignment ImageAlignment
{
get
{
return m_ImageAlignment;
}
set
{
m_ImageAlignment=value;
}
}
public int ImageTextSpacing
{
get
{
return 1;
}
}
public bool TextVisible
{
get
{
return true;
}
}
public string Text
{
get
{
return m_Text;
}
set
{
m_Text=value;
}
}
public Rectangle Bounds
{
get { return m_Bounds; }
set { m_Bounds=value; }
}
public Rectangle TextBounds
{
get { return m_TextBounds; }
set { m_TextBounds=value; }
}
public Rectangle ImageBounds
{
get { return m_ImageBounds; }
set { m_ImageBounds=value; }
}
public System.Drawing.Image Image
{
get { return m_Image; }
set { m_Image=value; }
}
private Size _TextSize;
public Size TextSize
{
get { return _TextSize; }
set { _TextSize = value; }
}
#endregion
}
}

View File

@@ -0,0 +1,359 @@
using System;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for SimpleElementLayout.
/// </summary>
internal class SimpleElementLayout
{
internal static void LayoutSimpleElement(SimpleElementLayoutInfo info)
{
Size textsize = Size.Empty;
Font font = info.Font;
int height = 0;
if (info.LayoutStyle.Font != null)
font = info.LayoutStyle.Font;
// Calculate Text Width and Height
string text = info.Element.Text;
if (info.Element.FixedWidth == 0)
{
if (info.Element.TextVisible)
{
if (!string.IsNullOrEmpty(text))
{
textsize = TextDrawing.MeasureString(info.Graphics, text, font);
//textSize=info.Graphics.MeasureString(text,font);
if (info.LayoutStyle != null && !info.LayoutStyle.TextShadowColor.IsEmpty && !info.LayoutStyle.TextShadowOffset.IsEmpty)
textsize.Height += info.LayoutStyle.TextShadowOffset.Y;
info.Element.TextSize = textsize;
}
}
}
else
{
int availTextWidth = info.Element.FixedWidth -
ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
if (info.Element.ImageVisible)
availTextWidth -= info.Element.ImageLayoutSize.Width;
if (info.Element.TextVisible)
{
int elementHeight = font.Height;
if (info.LayoutStyle != null && !info.LayoutStyle.TextShadowColor.IsEmpty && !info.LayoutStyle.TextShadowOffset.IsEmpty)
elementHeight += info.LayoutStyle.TextShadowOffset.Y;
if (info.LayoutStyle.WordWrap)
{
elementHeight = info.LayoutStyle.MaximumHeight - info.LayoutStyle.MarginTop -
info.LayoutStyle.MarginBottom - info.LayoutStyle.PaddingTop - info.LayoutStyle.PaddingBottom;
if (availTextWidth > 0)
{
if (elementHeight > 0)
{
textsize = TextDrawing.MeasureString(info.Graphics, text, font,
new Size(availTextWidth, elementHeight), info.LayoutStyle.TextFormat);
}
else
textsize = TextDrawing.MeasureString(info.Graphics, text, font, availTextWidth, info.LayoutStyle.TextFormat);
info.Element.TextSize = textsize;
}
}
else
{
if (!string.IsNullOrEmpty(text))
info.Element.TextSize = TextDrawing.MeasureString(info.Graphics, text, font);
textsize = new Size(availTextWidth, elementHeight);
}
}
}
if (info.Element.TextVisible && !info.LayoutStyle.TextShadowColor.IsEmpty)
{
textsize.Height += info.LayoutStyle.TextShadowOffset.Y;
}
height = textsize.Height;
if (info.VerticalPartAlignment)
{
if (info.Element.ImageVisible && info.Element.ImageLayoutSize.Height > 0)
height += info.Element.ImageLayoutSize.Height;
}
else
{
if (info.Element.ImageVisible && info.Element.ImageLayoutSize.Height > height)
height = info.Element.ImageLayoutSize.Height;
}
Rectangle r = new Rectangle(info.Left + ElementStyleLayout.LeftWhiteSpace(info.LayoutStyle),
info.Top + ElementStyleLayout.TopWhiteSpace(info.LayoutStyle)
, info.Element.FixedWidth - ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle), height);
if (r.Width == 0)
{
if (info.VerticalPartAlignment)
{
if (info.Element.TextVisible)
r.Width = textsize.Width;
if (info.Element.ImageVisible && info.Element.ImageLayoutSize.Width > r.Width)
r.Width = (info.Element.ImageLayoutSize.Width + info.Element.ImageTextSpacing);
}
else
{
if (info.Element.TextVisible)
r.Width = textsize.Width;
if (info.Element.ImageVisible && info.Element.ImageLayoutSize.Width > 0)
r.Width += (info.Element.ImageLayoutSize.Width + info.Element.ImageTextSpacing);
}
}
// Now that we have element bounds store them
Rectangle rElementBounds = new Rectangle(info.Left, info.Top, info.Element.FixedWidth, r.Height + info.LayoutStyle.MarginTop + info.LayoutStyle.MarginBottom + info.LayoutStyle.PaddingTop + info.LayoutStyle.PaddingBottom);
if (rElementBounds.Width == 0)
rElementBounds.Width = r.Width + ElementStyleLayout.HorizontalStyleWhiteSpace(info.LayoutStyle);
info.Element.Bounds = rElementBounds;
// Set Position of the image
if (info.Element.ImageVisible && !info.Element.ImageLayoutSize.IsEmpty)
{
eVerticalAlign va = GetImageVerticalAlign(info.Element.ImageAlignment);
eHorizontalAlign ha = GetImageHorizontalAlign(info.Element.ImageAlignment, info.LeftToRight);
if (info.VerticalPartAlignment)
info.Element.ImageBounds = AlignContentVertical(info.Element.ImageLayoutSize, ref r, ha, va, info.Element.ImageTextSpacing);
else
info.Element.ImageBounds = AlignContent(info.Element.ImageLayoutSize, ref r, ha, va, info.Element.ImageTextSpacing);
}
else
info.Element.ImageBounds = Rectangle.Empty;
// Set position of the text
if (!textsize.IsEmpty)
info.Element.TextBounds = r;
else
info.Element.TextBounds = Rectangle.Empty;
}
private static Rectangle AlignContent(System.Drawing.Size contentSize, ref Rectangle boundingRectangle, eHorizontalAlign horizAlign, eVerticalAlign vertAlign, int contentSpacing)
{
Rectangle contentRect=new Rectangle(Point.Empty,contentSize);
switch(horizAlign)
{
case eHorizontalAlign.Right:
{
contentRect.X=boundingRectangle.Right-contentRect.Width;
boundingRectangle.Width-=(contentRect.Width+contentSpacing);
break;
}
//case eHorizontalAlign.Left:
default:
{
contentRect.X=boundingRectangle.X;
boundingRectangle.X=contentRect.Right+contentSpacing;
boundingRectangle.Width-=(contentRect.Width+contentSpacing);
break;
}
// case eHorizontalAlign.Center:
// {
// contentRect.X=boundingRectangle.X+(boundingRectangle.Width-contentRect.Width)/2;
// break;
// }
}
switch(vertAlign)
{
case eVerticalAlign.Top:
{
contentRect.Y=boundingRectangle.Y;
break;
}
case eVerticalAlign.Middle:
{
contentRect.Y=boundingRectangle.Y+(boundingRectangle.Height-contentRect.Height)/2;
break;
}
case eVerticalAlign.Bottom:
{
contentRect.Y=boundingRectangle.Bottom-contentRect.Height;
break;
}
}
return contentRect;
}
private static Rectangle AlignContentVertical(System.Drawing.Size contentSize, ref Rectangle boundingRectangle, eHorizontalAlign horizAlign, eVerticalAlign vertAlign, int contentSpacing)
{
Rectangle contentRect=new Rectangle(Point.Empty,contentSize);
switch(horizAlign)
{
case eHorizontalAlign.Left:
{
contentRect.X=boundingRectangle.X;
break;
}
case eHorizontalAlign.Right:
{
contentRect.X=boundingRectangle.Right-contentRect.Width;
break;
}
case eHorizontalAlign.Center:
{
contentRect.X=boundingRectangle.X+(boundingRectangle.Width-contentRect.Width)/2;
break;
}
}
switch(vertAlign)
{
case eVerticalAlign.Bottom:
{
contentRect.Y=boundingRectangle.Bottom-contentRect.Height;
boundingRectangle.Height-=(contentRect.Height+contentSpacing);
break;
}
//case eVerticalAlign.Top:
default:
{
contentRect.Y=boundingRectangle.Y;
boundingRectangle.Y=contentRect.Bottom+contentSpacing;
boundingRectangle.Height-=(contentRect.Height+contentSpacing);
break;
}
// case eVerticalAlign.Middle:
// {
// contentRect.Y=boundingRectangle.Y+(boundingRectangle.Height-contentRect.Height)/2;
// break;
// }
}
return contentRect;
}
private static eHorizontalAlign GetImageHorizontalAlign(eSimplePartAlignment align, bool leftToRight)
{
if(((align==eSimplePartAlignment.NearBottom || align==eSimplePartAlignment.NearCenter ||
align==eSimplePartAlignment.NearTop) && leftToRight) ||
((align==eSimplePartAlignment.FarBottom || align==eSimplePartAlignment.FarCenter ||
align==eSimplePartAlignment.FarTop) && !leftToRight))
return eHorizontalAlign.Left;
else if(align==eSimplePartAlignment.CenterBottom || align==eSimplePartAlignment.CenterTop)
return eHorizontalAlign.Center;
return eHorizontalAlign.Right;
}
private static eVerticalAlign GetImageVerticalAlign(eSimplePartAlignment align)
{
eVerticalAlign va=eVerticalAlign.Middle;
switch(align)
{
case eSimplePartAlignment.FarBottom:
case eSimplePartAlignment.NearBottom:
case eSimplePartAlignment.CenterBottom:
va=eVerticalAlign.Bottom;
break;
case eSimplePartAlignment.FarTop:
case eSimplePartAlignment.NearTop:
case eSimplePartAlignment.CenterTop:
va=eVerticalAlign.Top;
break;
}
return va;
}
/// <summary>
/// Indicates absolute vertical alignment of the content.
/// </summary>
private enum eVerticalAlign
{
/// <summary>
/// Content is aligned to the top
/// </summary>
Top,
/// <summary>
/// Content is aligned in the middle
/// </summary>
Middle,
/// <summary>
/// Content is aligned at the bottom
/// </summary>
Bottom
}
/// <summary>
/// Indicates absolute horizontal alignment
/// </summary>
private enum eHorizontalAlign
{
/// <summary>
/// Content is left aligned
/// </summary>
Left,
/// <summary>
/// Content is centered
/// </summary>
Center,
/// <summary>
/// Content is right aligned
/// </summary>
Right
}
}
/// <summary>Indicates alignment of a part of the cell like image or check box in relation to the text.</summary>
public enum eSimplePartAlignment:int
{
/// <summary>
/// Part is aligned to the left center of the text assuming left-to-right
/// orientation.
/// </summary>
NearCenter=0,
/// <summary>
/// Part is aligned to the right center of the text assuming left-to-right
/// orientation.
/// </summary>
FarCenter=1,
/// <summary>
/// Part is aligned to the top left of the text assuming left-to-right
/// orientation.
/// </summary>
NearTop=2,
/// <summary>Part is aligned above the text and centered.</summary>
CenterTop=3,
/// <summary>
/// Part is aligned to the top right of the text assuming left-to-right
/// orientation.
/// </summary>
FarTop=4,
/// <summary>
/// Part is aligned to the bottom left of the text assuming left-to-right
/// orientation.
/// </summary>
NearBottom=5,
/// <summary>Part is aligned below the text and centered.</summary>
CenterBottom=6,
/// <summary>
/// Part is aligned to the bottom right of the text assuming left-to-right
/// orientation.
/// </summary>
FarBottom=7
}
internal class SimpleElementLayoutInfo
{
public ISimpleElement Element=null;
public System.Drawing.Graphics Graphics=null;
public System.Drawing.Font Font=null;
public int Left=0;
public int Top=0;
public ElementStyle LayoutStyle=null;
public bool LeftToRight=true;
public bool VerticalPartAlignment=false;
}
}

View File

@@ -0,0 +1,96 @@
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for SimpleNodeDisplay.
/// </summary>
internal class SimpleNodeDisplay
{
public static void Paint(SimpleNodeDisplayInfo di)
{
Rectangle r=di.Element.Bounds;
//di.Graphics.SetClip(r);
Region oldClip = di.Graphics.Clip;
if (oldClip != null)
di.Graphics.SetClip(r, CombineMode.Intersect);
else
di.Graphics.SetClip(r, CombineMode.Replace);
//r.Inflate(1,1);
ElementStyleDisplayInfo displayInfo=new ElementStyleDisplayInfo(di.Style,di.Graphics,r);
ElementStyleDisplay.Paint(displayInfo);
di.Graphics.ResetClip();
if(di.Element.ImageVisible)
SimpleNodeDisplay.PaintImage(di);
if(di.Element.TextVisible)
{
displayInfo.Bounds=(di.TextBounds.IsEmpty?di.Element.TextBounds:di.TextBounds);
eTextFormat format = di.Style.TextFormat;
if (di.RightToLeft)
format |= eTextFormat.RightToLeft;
ElementStyleDisplay.PaintText(displayInfo,di.Element.Text,di.Font, false, format);
}
if (oldClip != null)
di.Graphics.Clip = oldClip;
else
di.Graphics.ResetClip();
}
private static void PaintImage(SimpleNodeDisplayInfo di)
{
if(di.Element.ImageLayoutSize.IsEmpty || di.Element.Image==null)
return;
Rectangle r=di.Element.ImageBounds;
di.Graphics.DrawImage(di.Element.Image,r.X+(r.Width-di.Element.Image.Width)/2,
r.Y+(r.Height-di.Element.Image.Height)/2);
}
// private static void PaintText(SimpleNodeDisplayInfo di)
// {
// ISimpleElement e=di.Element;
// if(e.Text=="" || e.TextBounds.IsEmpty || di.Style.TextColor.IsEmpty)
// return;
//
// Rectangle bounds=e.TextBounds;
//
// Font font=di.Style.Font;
// if(font==null)
// font=di.Font;
//
// using(SolidBrush brush=new SolidBrush(di.Style.TextColor))
// {
// di.Graphics.DrawString(e.Text,font,brush,bounds,di.Style.StringFormat);
// }
// }
}
/// <summary>
/// Represents information neccessary to paint the cell on canvas.
/// </summary>
internal class SimpleNodeDisplayInfo
{
public ElementStyle Style=null;
public System.Drawing.Graphics Graphics=null;
public ISimpleElement Element=null;
public System.Drawing.Font Font=null;
public Rectangle TextBounds=Rectangle.Empty;
public bool RightToLeft = false;
public SimpleNodeDisplayInfo(ElementStyle style, System.Drawing.Graphics g, ISimpleElement elem, Font font, bool rightToLeft)
{
this.Style=style;
this.Graphics=g;
this.Element=elem;
this.Font=font;
this.RightToLeft = rightToLeft;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,115 @@
using System;
using System.Text;
using System.ComponentModel;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Indicates spacing for an user interface element either padding or margins.
/// </summary>
[ToolboxItem(false),TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public class Spacing
{
#region Events
public event EventHandler SpacingChanged;
#endregion
#region Private Variables
private int m_Left = 0;
private int m_Right = 0;
private int m_Top = 0;
private int m_Bottom = 0;
#endregion
#region Internal Implementation
/// <summary>
/// Gets or sets the amount of the space on the left side.
/// </summary>
[Browsable(true), DefaultValue(0), Description("Indicates the amount of the space on the left side."), DevCoSerialize()]
public int Left
{
get { return m_Left; }
set
{
m_Left = value;
OnSpacingChanged();
}
}
/// <summary>
/// Gets or sets the amount of the space on the right side.
/// </summary>
[Browsable(true), DefaultValue(0), Description("Indicates the amount of the space on the right side."), DevCoSerialize()]
public int Right
{
get { return m_Right; }
set
{
m_Right = value;
OnSpacingChanged();
}
}
/// <summary>
/// Gets or sets the amount of the space on the top.
/// </summary>
[Browsable(true), DefaultValue(0), Description("Indicates the amount of the space on the top."), DevCoSerialize()]
public int Top
{
get { return m_Top; }
set
{
m_Top = value;
OnSpacingChanged();
}
}
/// <summary>
/// Gets or sets the amount of the space on the bottom.
/// </summary>
[Browsable(true), DefaultValue(0), Description("Indicates the amount of the space on the bottom."), DevCoSerialize()]
public int Bottom
{
get { return m_Bottom; }
set
{
m_Bottom = value;
OnSpacingChanged();
}
}
private void OnSpacingChanged()
{
if (SpacingChanged != null)
SpacingChanged(this, new EventArgs());
}
/// <summary>
/// Gets total horizontal spacing.
/// </summary>
[Browsable(false)]
public int Horizontal
{
get { return Left + Right; }
}
/// <summary>
/// Gets total vertical spacing.
/// </summary>
[Browsable(false)]
public int Vertical
{
get { return Top + Bottom; }
}
/// <summary>
/// Gets whether all memebers of class are set to 0.
/// </summary>
[Browsable(false)]
public bool IsEmpty
{
get { return (m_Left==0 && m_Right==0 && m_Top==0 && m_Bottom==0); }
}
#endregion
}
}

View File

@@ -0,0 +1,41 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar.Ribbon
{
internal class SubItemsQatCollection : SubItemsCollection
{
private Ribbon.QatToolbar m_QatToolbar = null;
public SubItemsQatCollection(Ribbon.QatToolbar qatToolbar):base(null)
{
m_QatToolbar = qatToolbar;
}
protected override void OnInsert(int index, object value) {}
protected override void OnInsertComplete(int index, object value)
{
if (!m_IgnoreEvents)
{
if(m_QatToolbar.Items.Count<=index)
m_QatToolbar.Items.Add(value as BaseItem);
else
m_QatToolbar.Items.Insert(index, value as BaseItem);
}
}
protected override void RemoveInternal(int index, object value)
{
// Raise event before item is actualy removed so the item is able to clean its state
// See override in PopupItem
if (!m_IgnoreEvents)
{
m_QatToolbar.Items.Remove(value as BaseItem);
}
}
protected override void RemoveCompleteInternal(int index, object value)
{
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,235 @@
using System;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Summary description for ThemedButtonItemPainter.
/// </summary>
public class ThemedButtonItemPainter
{
public static void PaintButton(ButtonItem button, ItemPaintArgs pa)
{
System.Drawing.Graphics g=pa.Graphics;
ThemeToolbar theme=pa.ThemeToolbar;
ThemeToolbarParts part=ThemeToolbarParts.Button;
ThemeToolbarStates state=ThemeToolbarStates.Normal;
Color textColor=ButtonItemPainterHelper.GetTextColor(button,pa);
Rectangle rectImage=Rectangle.Empty;
Rectangle itemRect=button.DisplayRectangle;
Font font=null;
CompositeImage image=button.GetImage();
font=button.GetFont(pa, false);
eTextFormat format= GetStringFormat(button, pa, image);
bool bSplitButton=(button.SubItems.Count>0 || button.PopupType==ePopupType.Container) && button.ShowSubItems && !button.SubItemsRect.IsEmpty;
if(bSplitButton)
part=ThemeToolbarParts.SplitButton;
// Calculate image position
if(image!=null)
{
if(button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,itemRect.Width,button.ImageDrawRect.Height);
else
rectImage=new Rectangle(button.ImageDrawRect.X,button.ImageDrawRect.Y,button.ImageDrawRect.Width,button.ImageDrawRect.Height);
rectImage.Offset(itemRect.Left,itemRect.Top);
rectImage.Offset((rectImage.Width-button.ImageSize.Width)/2,(rectImage.Height-button.ImageSize.Height)/2);
rectImage.Width=button.ImageSize.Width;
rectImage.Height=button.ImageSize.Height;
}
// Set the state and text brush
if(!ButtonItemPainter.IsItemEnabled(button, pa))
{
state=ThemeToolbarStates.Disabled;
}
else if(button.IsMouseDown)
{
state=ThemeToolbarStates.Pressed;
}
else if(button.IsMouseOver && button.Checked)
{
state=ThemeToolbarStates.HotChecked;
}
else if(button.IsMouseOver || button.Expanded)
{
state=ThemeToolbarStates.Hot;
}
else if(button.Checked)
{
state=ThemeToolbarStates.Checked;
}
Rectangle backRect=button.DisplayRectangle;
if(button.HotTrackingStyle==eHotTrackingStyle.Image && image!=null)
{
backRect=rectImage;
backRect.Inflate(3,3);
}
else if(bSplitButton)
{
backRect.Width=backRect.Width-button.SubItemsRect.Width;
}
// Draw Button Background
if(button.HotTrackingStyle!=eHotTrackingStyle.None)
{
theme.DrawBackground(g,part,state,backRect);
}
// Draw Image
if(image!=null && button.ButtonStyle!=eButtonStyle.TextOnlyAlways)
{
if(state==ThemeToolbarStates.Normal && button.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};
System.Drawing.Imaging.ColorMatrix grayMatrix = new System.Drawing.Imaging.ColorMatrix(array);
System.Drawing.Imaging.ImageAttributes att = new System.Drawing.Imaging.ImageAttributes();
att.SetColorMatrix(grayMatrix);
//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
image.DrawImage(g,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,att);
}
else if(state==ThemeToolbarStates.Normal && !image.IsIcon)
{
// Draw image little bit lighter, I decied to use gamma it is easy
System.Drawing.Imaging.ImageAttributes lightImageAttr = new System.Drawing.Imaging.ImageAttributes();
lightImageAttr.SetGamma(.7f,System.Drawing.Imaging.ColorAdjustType.Bitmap);
//g.DrawImage(image,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
image.DrawImage(g,rectImage,0,0,image.Width,image.Height,GraphicsUnit.Pixel,lightImageAttr);
}
else
{
image.DrawImage(g,rectImage);
}
}
// Draw Text
if(button.ButtonStyle==eButtonStyle.ImageAndText || button.ButtonStyle==eButtonStyle.TextOnlyAlways || image==null)
{
Rectangle rectText=button.TextDrawRect;
if(button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
{
if(button.Orientation==eOrientation.Vertical)
{
rectText=new Rectangle(button.TextDrawRect.X,button.TextDrawRect.Y,button.TextDrawRect.Width,button.TextDrawRect.Height);
}
else
{
rectText=new Rectangle(button.TextDrawRect.X,button.TextDrawRect.Y,itemRect.Width,button.TextDrawRect.Height);
if((button.SubItems.Count>0 || button.PopupType==ePopupType.Container) && button.ShowSubItems)
rectText.Width-=10;
}
format|=eTextFormat.HorizontalCenter;
}
rectText.Offset(itemRect.Left,itemRect.Top);
if(button.Orientation==eOrientation.Vertical)
{
g.RotateTransform(90);
TextDrawing.DrawStringLegacy(g,ButtonItemPainter.GetDrawText(button.Text),font,textColor,new Rectangle(rectText.Top,-rectText.Right,rectText.Height,rectText.Width),format);
g.ResetTransform();
}
else
{
if(rectText.Right>button.DisplayRectangle.Right)
rectText.Width=button.DisplayRectangle.Right-rectText.Left;
TextDrawing.DrawString(g,ButtonItemPainter.GetDrawText(button.Text),font,textColor,rectText,format);
if(!button.DesignMode && button.Focused && !pa.IsOnMenu && !pa.IsOnMenuBar)
{
//SizeF szf=g.MeasureString(m_Text,font,rectText.Width,format);
Rectangle r=rectText;
//r.Width=(int)Math.Ceiling(szf.Width);
//r.Height=(int)Math.Ceiling(szf.Height);
//r.Inflate(1,1);
System.Windows.Forms.ControlPaint.DrawFocusRectangle(g,r);
}
}
}
// If it has subitems draw the triangle to indicate that
if(bSplitButton)
{
part=ThemeToolbarParts.SplitButtonDropDown;
if(!ButtonItemPainter.IsItemEnabled(button, pa))
state=ThemeToolbarStates.Disabled;
else
state=ThemeToolbarStates.Normal;
if(button.HotTrackingStyle!=eHotTrackingStyle.None && button.HotTrackingStyle!=eHotTrackingStyle.Image && ButtonItemPainter.IsItemEnabled(button, pa))
{
if(button.Expanded || button.IsMouseDown)
state=ThemeToolbarStates.Pressed;
else if(button.IsMouseOver && button.Checked)
state=ThemeToolbarStates.HotChecked;
else if(button.Checked)
state=ThemeToolbarStates.Checked;
else if(button.IsMouseOver)
state=ThemeToolbarStates.Hot;
}
if (!button.AutoExpandOnClick)
{
if (button.Orientation == eOrientation.Horizontal)
{
Rectangle r = button.SubItemsRect;
r.Offset(itemRect.X, itemRect.Y);
theme.DrawBackground(g, part, state, r);
}
else
{
Rectangle r = button.SubItemsRect;
r.Offset(itemRect.X, itemRect.Y);
theme.DrawBackground(g, part, state, r);
}
}
}
if(button.Focused && button.DesignMode)
{
Rectangle r=itemRect;
r.Inflate(-1,-1);
DesignTime.DrawDesignTimeSelection(g,r,pa.Colors.ItemDesignTimeBorder);
}
if(image!=null)
image.Dispose();
}
private static eTextFormat GetStringFormat(ButtonItem button, ItemPaintArgs pa, CompositeImage image)
{
eTextFormat stringFormat=pa.ButtonStringFormat;
bool isOnMenu = IsOnMenu(button, pa);
if(!isOnMenu)
{
if(button.ContainerControl is RibbonStrip && (image==null || button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom))
stringFormat |= eTextFormat.HorizontalCenter;
else if(pa.IsOnMenuBar || pa.ContainerControl is Bar && image==null || button.ImagePosition==eImagePosition.Top || button.ImagePosition==eImagePosition.Bottom)
stringFormat |= eTextFormat.HorizontalCenter;
}
return stringFormat;
}
private static bool IsOnMenu(ButtonItem button, ItemPaintArgs pa)
{
bool isOnMenu = pa.IsOnMenu;
if (isOnMenu && button.Parent is ItemContainer)
isOnMenu = false;
return isOnMenu;
}
}
}

View File

@@ -0,0 +1,134 @@
using System;
using System.Text;
namespace DevComponents.DotNetBar
{
internal class ThreadUIOperation
{
#region Private Variables
private bool m_IsActive = false;
private System.Threading.ReaderWriterLock m_FadeImageLock = new System.Threading.ReaderWriterLock();
private EventHandler m_UpdateUIHandler = null;
private EventHandler m_RecordStartStateHandler = null;
private EventHandler m_CleanupHandler = null;
#endregion
#region Internal Implementation
public ThreadUIOperation(EventHandler recordStartState, EventHandler updateUIHandler, EventHandler cleanup)
{
m_RecordStartStateHandler = recordStartState;
m_UpdateUIHandler = updateUIHandler;
m_CleanupHandler = cleanup;
}
public bool IsActive
{
get { return m_IsActive; }
}
public void Start()
{
m_FadeImageLock.AcquireReaderLock(-1);
try
{
if (m_IsActive)
return;
}
finally
{
m_FadeImageLock.ReleaseReaderLock();
}
bool readerLockHeld = m_FadeImageLock.IsReaderLockHeld;
System.Threading.LockCookie cookie1 = new System.Threading.LockCookie();
if (readerLockHeld)
{
cookie1 = m_FadeImageLock.UpgradeToWriterLock(-1);
}
else
{
m_FadeImageLock.AcquireWriterLock(-1);
}
try
{
m_IsActive = true;
m_RecordStartStateHandler.Invoke(this, new EventArgs());
}
finally
{
if (readerLockHeld)
{
m_FadeImageLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
m_FadeImageLock.ReleaseWriterLock();
}
}
FadeAnimator.Fade(this, new EventHandler(this.OnFadeChanged));
m_IsActive = true;
}
public void Stop()
{
m_FadeImageLock.AcquireReaderLock(-1);
try
{
if (!m_IsActive)
return;
}
finally
{
m_FadeImageLock.ReleaseReaderLock();
}
FadeAnimator.StopFade(this, new EventHandler(OnFadeChanged));
bool readerLockHeld = m_FadeImageLock.IsReaderLockHeld;
System.Threading.LockCookie cookie1 = new System.Threading.LockCookie();
if (readerLockHeld)
{
cookie1 = m_FadeImageLock.UpgradeToWriterLock(-1);
}
else
{
m_FadeImageLock.AcquireWriterLock(-1);
}
try
{
m_IsActive = false;
m_CleanupHandler.Invoke(this, new EventArgs());
}
finally
{
if (readerLockHeld)
{
m_FadeImageLock.DowngradeFromWriterLock(ref cookie1);
}
else
{
m_FadeImageLock.ReleaseWriterLock();
}
}
}
private void OnFadeChanged(object sender, EventArgs e)
{
m_UpdateUIHandler.Invoke(this, new EventArgs());
}
public void StartReadOperation()
{
m_FadeImageLock.AcquireReaderLock(-1);
}
public void EndReadOperation()
{
m_FadeImageLock.ReleaseReaderLock();
}
#endregion
}
}

View File

@@ -0,0 +1,44 @@
using System;
using System.Text;
using System.Drawing;
namespace DevComponents.DotNetBar
{
/// <summary>
/// Provides data for toolbar rendering.
/// </summary>
public class ToolbarRendererEventArgs
{
/// <summary>
/// Gets or sets the reference to Bar object being rendered
/// </summary>
public Bar Bar = null;
/// <summary>
/// Gets or sets Graphics object bar is rendered on.
/// </summary>
public Graphics Graphics = null;
/// <summary>
/// Gets the bounds of the region that should be rendered.
/// </summary>
public Rectangle Bounds = Rectangle.Empty;
/// <summary>
/// Reference to internal data.
/// </summary>
internal ItemPaintArgs ItemPaintArgs = null;
/// <summary>
/// Creates new instance of the object and initializes it with default data.
/// </summary>
/// <param name="bar">Reference to bar object.</param>
/// <param name="g">Reference to Graphics object.</param>
public ToolbarRendererEventArgs(Bar bar, Graphics g, Rectangle bounds)
{
this.Bar = bar;
this.Graphics = g;
this.Bounds = bounds;
}
}
}