2023-01-24 15:29:31 +01:00
|
|
|
|
/* Copyright (c) Cloud Software Group, Inc.
|
2013-08-26 12:42:32 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms,
|
|
|
|
|
* with or without modification, are permitted provided
|
|
|
|
|
* that the following conditions are met:
|
|
|
|
|
*
|
|
|
|
|
* * Redistributions of source code must retain the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer.
|
|
|
|
|
* * Redistributions in binary form must reproduce the above
|
|
|
|
|
* copyright notice, this list of conditions and the
|
|
|
|
|
* following disclaimer in the documentation and/or other
|
|
|
|
|
* materials provided with the distribution.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
|
|
|
|
|
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
|
|
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
|
|
|
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Drawing.Drawing2D;
|
|
|
|
|
using System.Windows.Forms;
|
2013-11-26 12:36:45 +01:00
|
|
|
|
using XenAdmin.Core;
|
2013-08-26 12:42:32 +02:00
|
|
|
|
|
|
|
|
|
namespace XenAdmin.Controls.MainWindowControls
|
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
class NavigationToolStripRenderer : ToolStripProfessionalRenderer
|
2013-08-26 12:42:32 +02:00
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
public NavigationToolStripRenderer()
|
|
|
|
|
: base(new NavigationColourTable())
|
2013-08-26 12:42:32 +02:00
|
|
|
|
{
|
|
|
|
|
RoundedEdges = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 12:36:45 +01:00
|
|
|
|
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
|
2013-08-26 12:42:32 +02:00
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
var bounds = new Rectangle(Point.Empty, e.ToolStrip.Size);
|
|
|
|
|
|
|
|
|
|
using (Pen pen = new Pen(NavigationColourTable.BACK_COLOR))
|
|
|
|
|
e.Graphics.DrawRectangle(pen, bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnRenderButtonBackground(e);
|
|
|
|
|
|
|
|
|
|
var button = (NavigationButton)e.Item;
|
|
|
|
|
if (button == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var gradTop = ColorTable.ToolStripPanelGradientBegin;
|
|
|
|
|
var gradBottom = ColorTable.ToolStripPanelGradientBegin;
|
|
|
|
|
|
|
|
|
|
if (button.Pressed || button.Checked)
|
|
|
|
|
{
|
|
|
|
|
gradTop = NavigationColourTable.CHECKED_GRADIENT_BEGIN;
|
|
|
|
|
gradBottom = NavigationColourTable.CHECKED_GRADIENT_END;
|
|
|
|
|
}
|
|
|
|
|
else if (button.Selected)//hover
|
|
|
|
|
{
|
|
|
|
|
gradTop = NavigationColourTable.HOVER_GRADIENT_BEGIN;
|
|
|
|
|
gradBottom = NavigationColourTable.HOVER_GRADIENT_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bounds = new Rectangle(Point.Empty, e.Item.Size);
|
|
|
|
|
var g = e.Graphics;
|
|
|
|
|
|
|
|
|
|
DrawItemBackGround(g, bounds, gradTop, gradBottom);
|
|
|
|
|
|
|
|
|
|
if (button.Pressed || button.Checked || button.Selected)
|
|
|
|
|
DrawItemBorder(g, bounds);
|
2013-08-26 12:42:32 +02:00
|
|
|
|
}
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
|
|
|
|
protected override void OnRenderDropDownButtonBackground(ToolStripItemRenderEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnRenderDropDownButtonBackground(e);
|
|
|
|
|
|
|
|
|
|
var dropdown = e.Item as NavigationDropDownButton;
|
|
|
|
|
if (dropdown == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
var gradTop = ColorTable.ToolStripPanelGradientBegin;
|
|
|
|
|
var gradBottom = ColorTable.ToolStripPanelGradientBegin;
|
|
|
|
|
|
|
|
|
|
var dropDownItems = dropdown.DropDownItems;
|
|
|
|
|
if (dropDownItems.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
var pairedItem = dropdown.PairedItem as NavigationDropDownButton;
|
|
|
|
|
if (pairedItem != null)
|
|
|
|
|
dropDownItems = pairedItem.DropDownItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool itemChecked = false;
|
|
|
|
|
foreach (ToolStripMenuItem menuItem in dropDownItems)
|
|
|
|
|
{
|
|
|
|
|
if (menuItem.Checked)
|
|
|
|
|
{
|
|
|
|
|
itemChecked = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (itemChecked)
|
|
|
|
|
{
|
|
|
|
|
gradTop = NavigationColourTable.CHECKED_GRADIENT_BEGIN;
|
|
|
|
|
gradBottom = NavigationColourTable.CHECKED_GRADIENT_END;
|
|
|
|
|
}
|
|
|
|
|
else if (dropdown.Pressed || dropdown.Selected)//mouse down or hover
|
|
|
|
|
{
|
|
|
|
|
gradTop = NavigationColourTable.HOVER_GRADIENT_BEGIN;
|
|
|
|
|
gradBottom = NavigationColourTable.HOVER_GRADIENT_END;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bounds = new Rectangle(Point.Empty, e.Item.Size);
|
|
|
|
|
var g = e.Graphics;
|
|
|
|
|
|
|
|
|
|
DrawItemBackGround(g, bounds, gradTop, gradBottom);
|
|
|
|
|
|
|
|
|
|
if (itemChecked || dropdown.Pressed || dropdown.Selected)
|
|
|
|
|
DrawItemBorder(g, bounds);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnRenderItemText(ToolStripItemTextRenderEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnRenderItemText(e);
|
|
|
|
|
|
|
|
|
|
var notifyButton = e.Item as NotificationButtonBig;
|
|
|
|
|
if (notifyButton == null || notifyButton.UnreadEntries == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
using (Font blobFont = new Font(e.TextFont, FontStyle.Bold))
|
|
|
|
|
{
|
|
|
|
|
var g = e.Graphics;
|
2013-11-27 09:42:51 +01:00
|
|
|
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
|
|
|
|
|
2013-11-26 12:36:45 +01:00
|
|
|
|
var blobText = notifyButton.UnreadEntries.ToString();
|
2013-11-27 09:42:51 +01:00
|
|
|
|
var textFlags = TextFormatFlags.HorizontalCenter | TextFormatFlags.VerticalCenter | TextFormatFlags.NoPadding;
|
|
|
|
|
|
2013-11-26 12:36:45 +01:00
|
|
|
|
var contRect = e.Item.ContentRectangle;
|
2013-11-27 09:42:51 +01:00
|
|
|
|
var blobSize = Drawing.MeasureText(g, blobText, blobFont, contRect.Size, textFlags);
|
|
|
|
|
|
|
|
|
|
int horizPadding = 5;
|
|
|
|
|
int vertPadding = 1;
|
|
|
|
|
int rightMargin = 2;
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
2013-11-27 09:42:51 +01:00
|
|
|
|
var blobRect = new Rectangle(e.TextRectangle.Right + rightMargin + horizPadding + 1,
|
|
|
|
|
contRect.Top + ((contRect.Height - blobSize.Height) / 2),
|
|
|
|
|
blobSize.Width,
|
|
|
|
|
blobSize.Height);
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
2013-11-27 09:42:51 +01:00
|
|
|
|
var redRect = new Rectangle(blobRect.Location, blobRect.Size);
|
|
|
|
|
var whiteRect = new Rectangle(blobRect.Location, blobRect.Size);
|
|
|
|
|
redRect.Inflate(horizPadding, vertPadding);
|
|
|
|
|
whiteRect.Inflate(horizPadding + 1, vertPadding + 1);
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
|
|
|
|
using (GraphicsPath path = new GraphicsPath())
|
|
|
|
|
{
|
2013-11-27 09:42:51 +01:00
|
|
|
|
int diameter = redRect.Height;
|
|
|
|
|
var arc = new Rectangle(redRect.Location, new Size(diameter, diameter));
|
|
|
|
|
|
|
|
|
|
//top left corner
|
|
|
|
|
path.AddArc(arc, 180, 90);
|
|
|
|
|
|
|
|
|
|
// top right corner
|
|
|
|
|
arc.X = redRect.Right - diameter;
|
|
|
|
|
path.AddArc(arc, 270, 90);
|
|
|
|
|
|
|
|
|
|
// bottom right corner
|
|
|
|
|
arc.Y = redRect.Bottom - diameter;
|
|
|
|
|
path.AddArc(arc, 0, 90);
|
|
|
|
|
|
|
|
|
|
// bottom left corner
|
|
|
|
|
arc.X = redRect.Left;
|
|
|
|
|
path.AddArc(arc, 90, 90);
|
|
|
|
|
|
|
|
|
|
path.CloseFigure();
|
|
|
|
|
|
|
|
|
|
using (var brush = new SolidBrush(NavigationColourTable.NOTIFICATION_BACKCOLOR))
|
|
|
|
|
g.FillPath(brush, path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
using (GraphicsPath path = new GraphicsPath())
|
|
|
|
|
{
|
|
|
|
|
int diameter = whiteRect.Height;
|
|
|
|
|
var arc = new Rectangle(whiteRect.Location, new Size(diameter, diameter));
|
|
|
|
|
|
|
|
|
|
//top left corner
|
|
|
|
|
path.AddArc(arc, 180, 90);
|
|
|
|
|
|
|
|
|
|
// top right corner
|
|
|
|
|
arc.X = whiteRect.Right - diameter;
|
|
|
|
|
path.AddArc(arc, 270, 90);
|
|
|
|
|
|
|
|
|
|
// bottom right corner
|
|
|
|
|
arc.Y = whiteRect.Bottom - diameter;
|
|
|
|
|
path.AddArc(arc, 0, 90);
|
|
|
|
|
|
|
|
|
|
// bottom left corner
|
|
|
|
|
arc.X = whiteRect.Left;
|
|
|
|
|
path.AddArc(arc, 90, 90);
|
|
|
|
|
|
|
|
|
|
path.CloseFigure();
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
2013-11-27 09:42:51 +01:00
|
|
|
|
using (var pen = new Pen(NavigationColourTable.NOTIFICATION_FORECOLOR, 1))
|
|
|
|
|
g.DrawPath(pen, path);
|
2013-11-26 12:36:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
2013-11-27 09:42:51 +01:00
|
|
|
|
Drawing.DrawText(g, blobText, blobFont, blobRect, NavigationColourTable.NOTIFICATION_FORECOLOR, textFlags);
|
2013-11-26 12:36:45 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawItemBackGround(Graphics g, Rectangle bounds, Color gradTop, Color gradBottom)
|
|
|
|
|
{
|
|
|
|
|
using (var brush = new LinearGradientBrush(bounds, Color.Black, Color.Black, LinearGradientMode.Vertical))
|
|
|
|
|
{
|
|
|
|
|
ColorBlend blend = new ColorBlend
|
|
|
|
|
{
|
|
|
|
|
Positions = new[] { 0, 1 / 2f, 1 },
|
|
|
|
|
Colors = new[] { gradTop, gradBottom, gradTop }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
brush.InterpolationColors = blend;
|
|
|
|
|
g.FillRectangle(brush, bounds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawItemBorder(Graphics g, Rectangle bounds)
|
|
|
|
|
{
|
|
|
|
|
using (Pen pen = new Pen(NavigationColourTable.ITEM_BORDER_COLOR))
|
|
|
|
|
g.DrawRectangle(pen, bounds.X + 1, bounds.Y, bounds.Width - 2, bounds.Height - 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class SmallNavigationToolStripRenderer : NavigationToolStripRenderer
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class BigNavigationToolStripRenderer : NavigationToolStripRenderer
|
|
|
|
|
{
|
|
|
|
|
|
2013-08-26 12:42:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class NavigationColourTable : ProfessionalColorTable
|
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
internal static readonly Color CHECKED_GRADIENT_BEGIN = Color.Silver;
|
|
|
|
|
internal static readonly Color CHECKED_GRADIENT_END = Color.WhiteSmoke;
|
|
|
|
|
internal static readonly Color HOVER_GRADIENT_BEGIN = Color.WhiteSmoke;
|
|
|
|
|
internal static readonly Color HOVER_GRADIENT_END = Color.White;
|
|
|
|
|
internal static readonly Color BACK_COLOR = SystemColors.Control;
|
|
|
|
|
internal static readonly Color ITEM_BORDER_COLOR = Color.SlateGray;
|
2013-11-27 09:42:51 +01:00
|
|
|
|
internal static readonly Color NOTIFICATION_BACKCOLOR = Color.FromArgb(204, 0, 0);
|
|
|
|
|
internal static readonly Color NOTIFICATION_FORECOLOR = Color.White;
|
2013-11-26 12:36:45 +01:00
|
|
|
|
|
|
|
|
|
public override Color ToolStripGradientBegin
|
|
|
|
|
{
|
|
|
|
|
get { return BACK_COLOR; }
|
|
|
|
|
}
|
2013-08-26 12:42:32 +02:00
|
|
|
|
public override Color ToolStripGradientMiddle
|
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
get { return BACK_COLOR; }
|
2013-08-26 12:42:32 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override Color ToolStripGradientEnd
|
|
|
|
|
{
|
2013-11-26 12:36:45 +01:00
|
|
|
|
get { return BACK_COLOR; }
|
2013-08-26 12:42:32 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|