#if FRAMEWORK20
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using DevComponents.DotNetBar.Rendering;
using System.Drawing.Drawing2D;
namespace DevComponents.DotNetBar.Controls
{
///
/// Represents the PageNavigate item
///
[Browsable(false), Designer("DevComponents.DotNetBar.Design.SimpleItemDesigner, DevComponents.DotNetBar.Design, Version=14.1.0.37, Culture=neutral, PublicKeyToken=90f470f34c89ccaf")]
public class PageNavigatorItem : BaseItem
{
#region Events
///
/// Occurs when NavigateNextPage button is clicked
///
[Description("Occurs when NavigateNextPage button is clicked.")]
public event EventHandler NavigateNextPage;
///
/// Occurs when NavigateToday button is clicked
///
[Description("Occurs when NavigateToday button is clicked.")]
public event EventHandler NavigateToday;
///
/// Occurs when NavigatePreviousPage button is clicked
///
[Description("Occurs when NavigatePreviousPage button is clicked.")]
public event EventHandler NavigatePreviousPage;
#endregion
#region Private Variables
private ePageNavigatorPart _MouseOverPart = ePageNavigatorPart.None;
private ePageNavigatorPart _MouseDownPart = ePageNavigatorPart.None;
private Rectangle _PreviousPageBounds;
private Rectangle _TodayBounds;
private Rectangle _NextPageBounds;
private string _PreviousPageTooltip = "";
private string _TodayTooltip = "";
private string _NextPageTooltip = "";
private Bitmap _PreviousPageBitmap;
private Bitmap _TodayBitmap;
private Bitmap _NextPageBitmap;
private Timer _ClickTimer;
private int _AutoClickCount;
private int _ButtonSize = SystemInformation.VerticalScrollBarWidth;
private int _MinWidth = SystemInformation.VerticalScrollBarWidth * 3;
#endregion
///
/// Creates new instance of PageNavigateItem
///
public PageNavigatorItem() : this("") { }
///
/// Creates new instance of PageNavigateItem and assigns the name to it
///
/// Item name
public PageNavigatorItem(string itemName)
{
this.Name = itemName;
this.ClickRepeatInterval = 200;
this.MouseUpNotification = true;
this.MouseDownCapture = true;
this.Size = new Size(Dpi.Width(_MinWidth), Dpi.Height(_ButtonSize));
}
#region Internal properties
#region MouseOverPart
///
/// Gets or sets the MouseOverPart
///
internal ePageNavigatorPart MouseOverPart
{
get { return _MouseOverPart; }
set
{
if (_MouseOverPart != value)
{
_MouseOverPart = value;
UpdateTooltip();
this.Refresh();
}
}
}
#endregion
#region MouseDownPart
///
/// Gets or sets the MouseDownPart
///
internal ePageNavigatorPart MouseDownPart
{
get { return _MouseDownPart; }
set
{
if (_MouseDownPart != value)
{
_MouseDownPart = value;
this.Refresh();
}
}
}
#endregion
#endregion
#region Public properties
#region Orientation
///
/// Gets or sets the control orientation. Default value is Horizontal
///
[DefaultValue(eOrientation.Horizontal), Category("Appearance")]
[Description("Indicates PageNavigator orientation.")]
public override eOrientation Orientation
{
get { return (base.Orientation); }
set
{
if (base.Orientation != value)
{
base.Orientation = value;
// Release our current cached bitmaps
ReleaseBitmap(ref _NextPageBitmap);
ReleaseBitmap(ref _PreviousPageBitmap);
// Reset our size back to the
// default for the new orientation
this.Size = (value == eOrientation.Horizontal) ?
new Size(Dpi.Width(_MinWidth), Dpi.Height(_ButtonSize)) : new Size(Dpi.Width(_ButtonSize), Dpi.Height(_MinWidth));
NeedRecalcSize = true;
this.Refresh();
}
}
}
protected override void ScaleItem(SizeF factor)
{
ReleaseBitmap(ref _PreviousPageBitmap);
ReleaseBitmap(ref _TodayBitmap);
ReleaseBitmap(ref _NextPageBitmap);
this.Size = (Orientation == eOrientation.Horizontal) ?
new Size(Dpi.Width(_MinWidth), Dpi.Height(_ButtonSize)) : new Size(Dpi.Width(_ButtonSize), Dpi.Height(_MinWidth));
base.ScaleItem(factor);
}
#endregion
#region ClickAutoRepeat
///
/// Gets or sets whether Click event will be auto repeated
/// when mouse button is kept pressed over the item
///
[Browsable(false), DevCoBrowsable(false), DefaultValue(false), Category("Behavior")]
[Description("Gets or sets whether Click event will be auto repeated when the mouse button is kept pressed over the item.")]
public override bool ClickAutoRepeat
{
get { return (base.ClickAutoRepeat); }
set { base.ClickAutoRepeat = value; }
}
#endregion
#region ClickRepeatInterval
///
/// Gets or sets the auto-repeat interval for the click event
/// when mouse button is kept pressed over the item
///
[Browsable(true), DevCoBrowsable(true), DefaultValue(200), Category("Behavior")]
[Description("Gets or sets the auto-repeat interval for the click event when the mouse button is kept pressed over the item.")]
public override int ClickRepeatInterval
{
get { return (base.ClickRepeatInterval); }
set { base.ClickRepeatInterval = value; }
}
#endregion
#region PreviousPageTooltip
///
/// Gets or sets the tooltip for the PreviousPage button of the control
///
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the PreviousPage button of the control.")]
public string PreviousPageTooltip
{
get { return _PreviousPageTooltip; }
set
{
_PreviousPageTooltip = value;
UpdateTooltip();
}
}
#endregion
#region TodayTooltip
///
/// Gets or sets the tooltip for the Today button
///
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the TodayPage button of the control.")]
public string TodayTooltip
{
get { return (_TodayTooltip); }
set
{
_TodayTooltip = value;
UpdateTooltip();
}
}
#endregion
#region NextPageTooltip
///
/// Gets or sets the tooltip for the NextPage button
///
[Browsable(true), DefaultValue(""), Localizable(true), Category("Appearance")]
[Description("Indicates tooltip for the NextPage button of the control.")]
public string NextPageTooltip
{
get { return (_NextPageTooltip); }
set
{
_NextPageTooltip = value;
UpdateTooltip();
}
}
#endregion
#endregion
#region RecalcSize
///
/// Handles size recalc
///
public override void RecalcSize()
{
// Update our layout
UpdateLayout();
base.RecalcSize();
}
#endregion
#region OnExternalSizeChange
///
/// Handles external size changes
///
protected override void OnExternalSizeChange()
{
UpdateLayout();
base.OnExternalSizeChange();
}
#endregion
#region UpdateLayout
///
/// Lays out our control based upon its
/// vertical / horizontal orientation
///
private void UpdateLayout()
{
Rectangle r = Bounds;
if (Orientation == eOrientation.Horizontal)
{
int dx = r.Width / 3;
_PreviousPageBounds = new Rectangle(r.Left, r.Top, dx, r.Height);
_NextPageBounds = new Rectangle(r.Right - dx, r.Top, dx, r.Height);
_TodayBounds = new Rectangle(r.Left + dx, r.Top, r.Width - dx * 2, r.Height);
}
else
{
int dy = r.Height / 3;
_PreviousPageBounds = new Rectangle(r.Left, r.Top, r.Width, dy);
_NextPageBounds = new Rectangle(r.Left, r.Bottom - dy, r.Width, dy);
_TodayBounds = new Rectangle(r.Left, r.Y + dy, r.Width, r.Height - dy * 2);
}
}
#endregion
#region Paint
///
/// Handles control rendering
///
///
public override void Paint(ItemPaintArgs e)
{
Graphics g = e.Graphics;
Office2007ScrollBarColorTable colorTable =
((Office2007Renderer)GlobalManager.Renderer).ColorTable.ScrollBar;
DrawPreviousPage(g, colorTable);
DrawToday(g, colorTable);
DrawNextPage(g, colorTable);
}
#region DrawPreviousPage
///
/// Draws the PreviousPage button
///
/// Graphics
/// Office2007ScrollBarColorTable
private void DrawPreviousPage(Graphics g, Office2007ScrollBarColorTable ct)
{
Office2007ScrollBarStateColorTable cst =
GetPageColorTable(ct, ePageNavigatorPart.PreviousPage);
float angle = (Orientation == eOrientation.Horizontal) ? 90f : 0f;
using (LinearGradientBrush lbr = new LinearGradientBrush(
_PreviousPageBounds, cst.Background.Start, cst.Background.End, angle))
{
if (cst.TrackBackground.Count > 0)
lbr.InterpolationColors =
cst.TrackBackground.GetColorBlend();
g.FillRectangle(lbr, _PreviousPageBounds);
}
g.DrawImageUnscaled(
GetPreviousPageBitmap(g, cst),
CenterRect(_PreviousPageBounds));
}
#region GetPreviousPageBitmap
///
/// Gets the PreviousPage bitmap
///
///
///
///
private Bitmap GetPreviousPageBitmap(
Graphics g, Office2007ScrollBarStateColorTable cst)
{
if (_PreviousPageBitmap == null)
_PreviousPageBitmap = CreatePreviousPageBitmap(g, cst);
return (_PreviousPageBitmap);
}
///
/// Creates the PreviousPage bitmap
///
///
///
///
private Bitmap CreatePreviousPageBitmap(
Graphics g, Office2007ScrollBarStateColorTable cst)
{
Bitmap bmp = new Bitmap(Dpi.Width10, Dpi.Height10, g);
using (Graphics gBmp = Graphics.FromImage(bmp))
{
using (GraphicsPath path = new GraphicsPath())
{
float angle;
if (Orientation == eOrientation.Horizontal)
{
angle = 90;
path.AddLines(new Point[] {
new Point(Dpi.Width8,0),
new Point(Dpi.Width4,Dpi.Height4),
new Point(Dpi.Width8,Dpi.Height8)
});
path.CloseFigure();
path.AddLines(new Point[] {
new Point(Dpi.Width4,0),
new Point(0,Dpi.Height4),
new Point(Dpi.Width4,Dpi.Height8)
});
path.CloseFigure();
}
else
{
angle = 0;
path.AddLines(new Point[] {
new Point(0,Dpi.Height5),
new Point(Dpi.Width4,0),
new Point(Dpi.Width8,Dpi.Height5)
});
path.CloseFigure();
path.AddLines(new Point[] {
new Point(0,Dpi.Height9),
new Point(Dpi.Width4,Dpi.Height4),
new Point(Dpi.Width8,Dpi.Height9)
});
path.CloseFigure();
}
Rectangle r = new Rectangle(0, 0, Dpi.Width10, Dpi.Height10);
using (LinearGradientBrush lbr = new
LinearGradientBrush(r, cst.ThumbSignBackground.Start, cst.ThumbSignBackground.End, angle))
{
gBmp.FillPath(lbr, path);
}
}
}
return (bmp);
}
#endregion
#endregion
#region DrawToday
///
/// Draws the Today button
///
/// Graphics
/// Office2007ScrollBarColorTable
private void DrawToday(Graphics g, Office2007ScrollBarColorTable ct)
{
Office2007ScrollBarStateColorTable cst =
GetPageColorTable(ct, ePageNavigatorPart.Today);
float angle = (Orientation == eOrientation.Horizontal) ? 90f : 0f;
using (LinearGradientBrush lbr = new LinearGradientBrush(
_TodayBounds, cst.Background.Start, cst.Background.End, angle))
{
if (cst.TrackBackground.Count > 0)
lbr.InterpolationColors = cst.TrackBackground.GetColorBlend();
g.FillRectangle(lbr, _TodayBounds);
}
g.DrawImageUnscaled(
GetTodayBitmap(g, cst),
CenterRect(_TodayBounds));
}
#region GetTodayBitmap
///
/// Gets the Today Bitmap
///
///
///
///
private Bitmap GetTodayBitmap(
Graphics g, Office2007ScrollBarStateColorTable cst)
{
if (_TodayBitmap == null)
_TodayBitmap = CreateTodayBitmap(g, cst);
return (_TodayBitmap);
}
///
/// Creates the Today Bitmap
///
///
///
///
private Bitmap CreateTodayBitmap(
Graphics g, Office2007ScrollBarStateColorTable cst)
{
Bitmap bmp = new Bitmap(Dpi.Width10, Dpi.Height10, g);
using (Graphics gBmp = Graphics.FromImage(bmp))
{
Rectangle r = new Rectangle(Dpi.Width1, Dpi.Height1, Dpi.Width6, Dpi.Height6);
gBmp.SmoothingMode = SmoothingMode.HighQuality;
Color color = ControlPaint.LightLight(cst.ThumbSignBackground.Start);
using (SolidBrush br = new SolidBrush(color))
{
gBmp.FillEllipse(br, r);
}
using (Pen pen = new Pen(cst.ThumbSignBackground.End, Dpi.Width1))
{
gBmp.DrawEllipse(pen, r);
}
}
return (bmp);
}
#endregion
#endregion
#region DrawNextPage
///
/// Draws the NextPage button
///
///
///
private void DrawNextPage(Graphics g, Office2007ScrollBarColorTable ct)
{
Office2007ScrollBarStateColorTable cst =
GetPageColorTable(ct, ePageNavigatorPart.NextPage);
float angle = (Orientation == eOrientation.Horizontal) ? 90f : 0f;
using (LinearGradientBrush lbr = new LinearGradientBrush(
_NextPageBounds, cst.Background.Start, cst.Background.End, angle))
{
if (cst.TrackBackground.Count > 0)
lbr.InterpolationColors = cst.TrackBackground.GetColorBlend();
g.FillRectangle(lbr, _NextPageBounds);
}
g.DrawImageUnscaled(
GetNextPageBitmap(g, cst),
CenterRect(_NextPageBounds));
}
#region GetNextPageBitmap
///
/// Gets the NextPage Bitmap
///
///
///
///
private Bitmap GetNextPageBitmap(Graphics g, Office2007ScrollBarStateColorTable cst)
{
if (_NextPageBitmap == null)
_NextPageBitmap = CreateNextPageBitmap(g, cst);
return (_NextPageBitmap);
}
///
/// Creates the NextPage Bitmap
///
///
///
///
private Bitmap CreateNextPageBitmap(Graphics g, Office2007ScrollBarStateColorTable cst)
{
Bitmap bmp = new Bitmap(Dpi.Width10, Dpi.Height10, g);
using (Graphics gBmp = Graphics.FromImage(bmp))
{
using (GraphicsPath path = new GraphicsPath())
{
float angle;
if (Orientation == eOrientation.Horizontal)
{
angle = 90;
path.AddLines(new Point[] {
new Point(Dpi.Width1,0),
new Point(Dpi.Width5,Dpi.Height4),
new Point(Dpi.Width1,Dpi.Height8)
});
path.CloseFigure();
path.AddLines(new Point[] {
new Point(Dpi.Width5,0),
new Point(Dpi.Width9,Dpi.Height4),
new Point(Dpi.Width5,Dpi.Height8)
});
path.CloseFigure();
}
else
{
angle = 0;
path.AddLines(new Point[] {
new Point(Dpi.Width1,0),
new Point(Dpi.Width8,0),
new Point(Dpi.Width4,Dpi.Height4)
});
path.CloseFigure();
path.AddLines(new Point[] {
new Point(Dpi.Width1,Dpi.Height4),
new Point(Dpi.Width8,Dpi.Height4),
new Point(Dpi.Width4,Dpi.Height8)
});
path.CloseFigure();
}
Rectangle r = new Rectangle(0, 0, Dpi.Width10, Dpi.Height10);
DisplayHelp.FillPath(gBmp, path, cst.ThumbSignBackground);
//using (LinearGradientBrush lbr = new
// LinearGradientBrush(r, cst.ThumbSignBackground.Start, cst.ThumbSignBackground.End, angle))
//{
// gBmp.FillPath(lbr, path);
//}
}
}
return (bmp);
}
#endregion
#endregion
#region GetPageColorTable
private Office2007ScrollBarStateColorTable
GetPageColorTable(Office2007ScrollBarColorTable ct, ePageNavigatorPart part)
{
if (GetEnabled() == false)
return (ct.Disabled);
if (MouseDownPart == part)
return (ct.Pressed);
if (MouseOverPart == part)
return (ct.MouseOver);
return (ct.Default);
}
#endregion
#region CenterRect
///
/// Centers the given rect
///
///
///
private Rectangle CenterRect(Rectangle r)
{
r.X += (r.Width - 10) / 2 + 1;
r.Y += (r.Height - 10) / 2 + 1;
if (r.X < 0)
r.X = 0;
if (r.Y < 0)
r.Y = 0;
return (r);
}
#endregion
#endregion
#region Mouse support
#region InternalMouseMove
///
/// Processes InternalMouseMove events
///
///
public override void InternalMouseMove(MouseEventArgs objArg)
{
if (GetEnabled() == true && DesignMode == false)
{
if (MouseDownPart == ePageNavigatorPart.None)
MouseOverPart = HitTest(objArg.Location);
}
base.InternalMouseMove(objArg);
}
#region HitTest
///
/// Returns the HitText area for the given point
///
///
///
public ePageNavigatorPart HitTest(Point pt)
{
if (_PreviousPageBounds.Contains(pt))
return (ePageNavigatorPart.PreviousPage);
if (_NextPageBounds.Contains(pt))
return (ePageNavigatorPart.NextPage);
if (_TodayBounds.Contains(pt))
return (ePageNavigatorPart.Today);
return (ePageNavigatorPart.None);
}
#endregion
#endregion
#region InternalMouseLeave
///
/// Processes Mouse Leave events
///
public override void InternalMouseLeave()
{
DisposeClickTimer();
MouseOverPart = ePageNavigatorPart.None;
MouseDownPart = ePageNavigatorPart.None;
base.InternalMouseLeave();
}
#endregion
#region InternalMouseDown
///
/// Processes Mouse Down events
///
///
public override void InternalMouseDown(MouseEventArgs objArg)
{
if (objArg.Button == MouseButtons.Left)
{
if (GetEnabled() && DesignMode == false)
{
MouseDownPart = HitTest(objArg.Location);
if (MouseDownPart != ePageNavigatorPart.None)
{
switch (MouseDownPart)
{
case ePageNavigatorPart.PreviousPage:
OnNavigatePreviousPage();
break;
case ePageNavigatorPart.NextPage:
OnNavigateNextPage();
break;
default:
OnNavigateToday();
break;
}
}
}
}
base.InternalMouseDown(objArg);
}
#endregion
#region InternalMouseUp
///
/// Processes Mouse Up events
///
///
public override void InternalMouseUp(MouseEventArgs objArg)
{
DisposeClickTimer();
MouseDownPart = ePageNavigatorPart.None;
base.InternalMouseUp(objArg);
}
#endregion
#endregion
#region OnNavigate
///
/// Raises the NavigatePreviousPage event
///
protected virtual void OnNavigatePreviousPage()
{
if (NavigatePreviousPage != null)
NavigatePreviousPage(this, EventArgs.Empty);
EnableClickTimer();
}
///
/// Raises the NavigateToday event
///
protected virtual void OnNavigateToday()
{
if (NavigateToday != null)
NavigateToday(this, EventArgs.Empty);
}
///
/// Raises the NavigateNextPage event
///
protected virtual void OnNavigateNextPage()
{
if (NavigateNextPage != null)
NavigateNextPage(this, EventArgs.Empty);
EnableClickTimer();
}
#endregion
#region Timer support
#region ClickTimerTick
///
/// Handles timer click events
///
///
///
private void ClickTimerTick(object sender, EventArgs e)
{
switch (MouseDownPart)
{
case ePageNavigatorPart.PreviousPage:
OnNavigatePreviousPage();
break;
case ePageNavigatorPart.NextPage:
OnNavigateNextPage();
break;
}
// Auto ramp-up
if (_ClickTimer != null)
{
_AutoClickCount++;
if (_AutoClickCount > 4 && _ClickTimer.Interval > 20)
_ClickTimer.Interval -= 10;
}
}
#endregion
#region UpdateClickTimer
///
/// Enables our click timer
///
private void EnableClickTimer()
{
if (ClickRepeatInterval > 0)
{
if (_ClickTimer == null)
{
_ClickTimer = new Timer();
_ClickTimer.Interval = ClickRepeatInterval;
_ClickTimer.Tick += ClickTimerTick;
_ClickTimer.Start();
_AutoClickCount = 0;
}
}
}
#endregion
#region DisposeClickTimer
///
/// Disposes of the click timer
///
private void DisposeClickTimer()
{
if (_ClickTimer != null)
{
_ClickTimer.Tick -= ClickTimerTick;
_ClickTimer.Stop();
_ClickTimer.Dispose();
_ClickTimer = null;
}
}
#endregion
#endregion
#region OnTooltipChanged
///
/// OnTooltipChanged
///
protected override void OnTooltipChanged()
{
UpdateTooltip();
base.OnTooltipChanged();
}
#endregion
#region UpdateTooltip
///
/// Updates the control tooltip
///
private void UpdateTooltip()
{
if (this.DesignMode == false)
{
string tip = "";
switch (MouseOverPart)
{
case ePageNavigatorPart.PreviousPage:
tip = _PreviousPageTooltip;
break;
case ePageNavigatorPart.Today:
tip = _TodayTooltip;
break;
case ePageNavigatorPart.NextPage:
tip = _NextPageTooltip;
break;
}
if (tip.Equals("") == false)
{
if (m_Tooltip != tip)
{
m_Tooltip = tip;
if (this.ToolTipVisible)
this.ShowToolTip();
}
}
}
}
#endregion
#region Copy
///
/// Returns copy of the item
///
public override BaseItem Copy()
{
PageNavigatorItem objCopy = new PageNavigatorItem(Name);
this.CopyToItem(objCopy);
return (objCopy);
}
///
/// Copies the PageNavigatorItem specific properties to
/// new instance of the item
///
/// New PageNavigatorItem instance
protected override void CopyToItem(BaseItem copy)
{
PageNavigatorItem c = copy as PageNavigatorItem;
if (c != null)
{
base.CopyToItem(c);
c.PreviousPageTooltip = _PreviousPageTooltip;
c.TodayTooltip = _TodayTooltip;
c.NextPageTooltip = _NextPageTooltip;
}
}
#endregion
#region Dispose
///
/// Dispose
///
protected override void Dispose(bool disposing)
{
DisposeClickTimer();
ReleaseBitmap(ref _PreviousPageBitmap);
ReleaseBitmap(ref _TodayBitmap);
ReleaseBitmap(ref _NextPageBitmap);
base.Dispose(disposing);
}
///
/// Releases the given bitmap
///
/// Bitmap to release
private void ReleaseBitmap(ref Bitmap bmp)
{
if (bmp != null)
{
bmp.Dispose();
bmp = null;
}
}
#endregion
}
#region Enums
///
/// Defines the PageNavigator item parts
///
public enum ePageNavigatorPart
{
///
/// Indicates no part
///
None,
///
/// Indicates the PreviousPage button of the control
///
PreviousPage,
///
/// Indicates the TodayPage button of the control
///
Today,
///
/// Indicates the NextPage button of the control
///
NextPage,
}
#endregion
}
#endif