using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace DevComponents.DotNetBar
{
///
/// Provides display support for SimualtedTheme tab style.
///
internal class TabStripSimulatedThemeDisplay:TabStripBaseDisplay
{
public TabStripSimulatedThemeDisplay()
{
this.HorizontalText=true;
}
#region Methods
public override void Paint(Graphics g, TabStrip tabStrip)
{
base.Paint(g,tabStrip);
TabColorScheme colorScheme=tabStrip.ColorScheme;
Rectangle clientRect=tabStrip.ClientRectangle;
if (tabStrip.BackColor != Color.Transparent || colorScheme.TabBackground != Color.Transparent)
{
if (colorScheme.TabPanelBackground2.IsEmpty)
{
if (!colorScheme.TabPanelBackground.IsEmpty)
{
using (SolidBrush brush = new SolidBrush(colorScheme.TabPanelBackground))
g.FillRectangle(brush, clientRect);
}
}
else
{
using (SolidBrush brush = new SolidBrush(Color.White))
g.FillRectangle(brush, clientRect);
using (LinearGradientBrush brush = CreateTabGradientBrush(clientRect, colorScheme.TabPanelBackground, colorScheme.TabPanelBackground2, colorScheme.TabPanelBackgroundGradientAngle))
g.FillRectangle(brush, clientRect);
}
}
tabStrip.ClipExcludeSystemBox(g);
DrawBackgroundInternal(clientRect,g,colorScheme,new Region(tabStrip.DisplayRectangle),tabStrip.TabAlignment, tabStrip.TabItemsBounds);
for(int i=tabStrip.Tabs.Count-1;i>=0;i--)
{
TabItem tab=tabStrip.Tabs[i];
if(!tab.Visible || tab.IsSelected || !tab.DisplayRectangle.IntersectsWith(clientRect))
continue;
PaintTab(g,tab,false,false);
}
if(tabStrip.SelectedTab!=null && tabStrip.Tabs.Contains(tabStrip.SelectedTab))
PaintTab(g,tabStrip.SelectedTab,false,false);
g.ResetClip();
tabStrip.PaintTabSystemBox(g);
}
protected override GraphicsPath GetTabItemPath(TabItem tab, bool bFirst, bool bLast)
{
Rectangle r=tab.DisplayRectangle;
GraphicsPath path=new GraphicsPath();
if(!tab.IsSelected && !tab.IsMouseOver)
{
if(tab.TabAlignment==eTabStripAlignment.Bottom)
{
r.Height--;
}
else if(tab.TabAlignment==eTabStripAlignment.Top)
{
r.Height--;
r.Y++;
}
else if(tab.TabAlignment==eTabStripAlignment.Left)
{
r.Width--;
r.X++;
}
else if(tab.TabAlignment==eTabStripAlignment.Right)
{
r.Width--;
}
path.AddRectangle(r);
}
else
{
if(tab.TabAlignment==eTabStripAlignment.Bottom)
{
//r.Height++;
path.AddLine(r.X+2,r.Bottom,r.X,r.Bottom-2);
path.AddLine(r.X,r.Y,r.Right,r.Y);
path.AddLine(r.Right,r.Bottom-2,r.Right-2,r.Bottom);
path.AddLine(r.Right-2,r.Bottom,r.X+2,r.Bottom);
}
else if(tab.TabAlignment==eTabStripAlignment.Top)
{
//r.Height++;
//r.Y--;
path.AddLine(r.X,r.Y+2,r.X+2,r.Y);
path.AddLine(r.Right-2,r.Y,r.Right,r.Y+2);
path.AddLine(r.Right,r.Bottom,r.X,r.Bottom);
}
else if(tab.TabAlignment==eTabStripAlignment.Left)
{
//r.Width++;
//r.X--;
path.AddLine(r.Right,r.Bottom,r.X+2,r.Bottom);
path.AddLine(r.X+2,r.Bottom,r.X,r.Bottom-2);
path.AddLine(r.X,r.Bottom-2,r.X,r.Y+2);
path.AddLine(r.X,r.Y+2,r.X+2,r.Y);
path.AddLine(r.Right-1,r.Y,r.Right-1,r.Bottom);
}
else if(tab.TabAlignment==eTabStripAlignment.Right)
{
//r.Width++;
path.AddLine(r.X,r.Y,r.Right-2,r.Y);
path.AddLine(r.Right-2,r.Y,r.Right,r.Y+2);
path.AddLine(r.Right,r.Y+2,r.Right,r.Bottom-2);
path.AddLine(r.Right,r.Bottom-2,r.Right-2,r.Bottom);
path.AddLine(r.X,r.Bottom,r.X,r.Y);
}
path.CloseAllFigures();
}
return path;
}
private GraphicsPath GetTabEdge(TabItem tab)
{
GraphicsPath path=new GraphicsPath();
Rectangle r=tab.DisplayRectangle;
if(tab.TabAlignment==eTabStripAlignment.Bottom)
{
r.Height++;
path.AddLine(r.Right,r.Bottom-2,r.Right-2,r.Bottom);
path.AddLine(r.Right-2,r.Bottom,r.X+2,r.Bottom);
path.AddLine(r.X+2,r.Bottom,r.X,r.Bottom-2);
}
else if(tab.TabAlignment==eTabStripAlignment.Top)
{
r.Height++;
r.Y--;
path.AddLine(r.X,r.Y+2,r.X+2,r.Y);
path.AddLine(r.X+2,r.Y,r.Right-2,r.Y);
path.AddLine(r.Right-2,r.Y,r.Right,r.Y+2);
}
else if(tab.TabAlignment==eTabStripAlignment.Left)
{
r.Width++;
r.X--;
//path.AddLine(r.Right,r.Bottom,r.X+2,r.Bottom);
path.AddLine(r.X+2,r.Bottom,r.X,r.Bottom-2);
path.AddLine(r.X,r.Bottom-2,r.X,r.Y+2);
path.AddLine(r.X,r.Y+2,r.X+2,r.Y);
//path.AddLine(r.Right,r.Y,r.Right,r.Bottom);
}
else if(tab.TabAlignment==eTabStripAlignment.Right)
{
r.Width++;
//path.AddLine(r.X,r.Y,r.Right-2,r.Y);
path.AddLine(r.Right-2,r.Y,r.Right,r.Y+2);
path.AddLine(r.Right,r.Y+2,r.Right,r.Bottom-2);
path.AddLine(r.Right,r.Bottom-2,r.Right-2,r.Bottom);
//path.AddLine(r.X,r.Bottom,r.X,r.Y);
}
//path.CloseAllFigures();
return path;
}
private void DrawBackgroundInternal(Rectangle tabStripRect, Graphics g, TabColorScheme colors, Region tabsRegion, eTabStripAlignment tabAlignment, Rectangle tabItemsBounds)
{
int cornerDiameter=3;
Rectangle br;
GraphicsPath path=new GraphicsPath();
GraphicsPath backPath=null;
if(!tabItemsBounds.IsEmpty)
{
if(tabAlignment==eTabStripAlignment.Top)
{
tabItemsBounds.Width+=3;
br=new Rectangle(tabStripRect.X,tabItemsBounds.Y+1,(tabItemsBounds.Right>tabStripRect.Right?tabStripRect.Width:tabItemsBounds.Right),tabItemsBounds.Height-1);
path.AddLine(br.X,br.Bottom,br.X,br.Top+cornerDiameter);
ArcData ad=GetCornerArc(br,cornerDiameter,eCornerArc.TopLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.X+cornerDiameter,br.Y,br.Right-cornerDiameter,br.Y);
ad=GetCornerArc(br,cornerDiameter,eCornerArc.TopRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.Right,br.Y+cornerDiameter,br.Right,br.Bottom);
backPath=path.Clone() as GraphicsPath;
backPath.CloseAllFigures();
if(tabItemsBounds.RighttabStripRect.Right?tabStripRect.Width:tabItemsBounds.Right),tabItemsBounds.Height-1);
path.AddLine(br.Right,br.Y,br.Right,br.Bottom-cornerDiameter);
ArcData ad=GetCornerArc(br,cornerDiameter,eCornerArc.BottomRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.Right-cornerDiameter,br.Bottom,br.X+cornerDiameter,br.Bottom);
ad=GetCornerArc(br,cornerDiameter,eCornerArc.BottomLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.X,br.Bottom-cornerDiameter,br.X,br.Y);
backPath=path.Clone() as GraphicsPath;
backPath.CloseAllFigures();
if(tabItemsBounds.RighttabStripRect.Bottom?tabStripRect.Height:tabItemsBounds.Bottom));
path.AddLine(br.Right-1,br.Bottom,br.X+cornerDiameter,br.Bottom);
ArcData ad=GetCornerArc(br,cornerDiameter,eCornerArc.BottomLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.X,br.Bottom-cornerDiameter,br.X,br.Y+cornerDiameter);
ad=GetCornerArc(br,cornerDiameter,eCornerArc.TopLeft);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.X+cornerDiameter,br.Y,br.Right-1,br.Y);
backPath=path.Clone() as GraphicsPath;
backPath.CloseAllFigures();
if(tabItemsBounds.BottomtabStripRect.Bottom?tabStripRect.Height:tabItemsBounds.Bottom));
path.AddLine(br.X,br.Y,br.Right-cornerDiameter,br.Y);
ArcData ad=GetCornerArc(br,cornerDiameter,eCornerArc.TopRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.Right,br.Y+cornerDiameter,br.Right,br.Bottom-cornerDiameter);
ad=GetCornerArc(br,cornerDiameter,eCornerArc.BottomRight);
path.AddArc(ad.X,ad.Y,ad.Width,ad.Height,ad.StartAngle,ad.SweepAngle);
path.AddLine(br.Right-cornerDiameter,br.Bottom,br.X,br.Bottom);
backPath=path.Clone() as GraphicsPath;
backPath.CloseAllFigures();
if(tabItemsBounds.Bottom