\r
using System;\r
using System.Drawing;\r
+using System.Drawing.Text;\r
using System.Windows.Forms;\r
+using System.Windows.Forms.VisualStyles;\r
\r
namespace System.Windows.Forms.Theming.Default\r
{\r
\r
public TabControlPainter ()\r
{\r
- defaultItemSize = new Size (42, 21);\r
+ defaultItemSize = new Size (42, 16);\r
defaultPadding = new Point (6, 3);\r
selectedTabDelta = new Rectangle (2, 2, 4, 3);\r
selectedSpacing = 0;\r
imagePadding = new Point (2, 3);\r
\r
defaultFormatting = new StringFormat();\r
+ // Horizontal Alignment is handled in the Draw method\r
defaultFormatting.Alignment = StringAlignment.Near;\r
- defaultFormatting.LineAlignment = StringAlignment.Near;\r
+ defaultFormatting.LineAlignment = StringAlignment.Center;\r
defaultFormatting.FormatFlags = StringFormatFlags.NoWrap | StringFormatFlags.NoClip;\r
+ defaultFormatting.HotkeyPrefix = HotkeyPrefix.Show;\r
\r
- borderThickness = new Rectangle (1, 1, 3, 2);\r
+ borderThickness = new Rectangle (1, 1, 2, 2);\r
}\r
\r
public virtual Rectangle GetLeftScrollRect (System.Windows.Forms.TabControl tab)\r
public Rectangle GetTabPanelRect (System.Windows.Forms.TabControl tab)\r
{ \r
// Offset the tab page (panel) from the top corner\r
- Rectangle res = new Rectangle (tab.ClientRectangle.X,\r
- tab.ClientRectangle.Y,\r
- tab.ClientRectangle.Width,\r
- tab.ClientRectangle.Height);\r
+ Rectangle res = tab.ClientRectangle;\r
\r
if (tab.TabCount == 0)\r
return res;\r
\r
int spacing = RowSpacing (tab).Height;\r
- int tabOffset = (tab.ItemSize.Height + spacing - (selectedTabDelta.Height - selectedTabDelta.Y)) * tab.RowCount;\r
+ int tabOffset = (tab.ItemSize.Height + spacing - selectedTabDelta.Height) * tab.RowCount + selectedTabDelta.Y;\r
switch (tab.Alignment) {\r
case TabAlignment.Top:\r
res.Y += tabOffset;\r
\r
public virtual void Draw (Graphics dc, Rectangle area, TabControl tab)\r
{\r
- Brush brush = SystemBrushes.Control;\r
- dc.FillRectangle (brush, area);\r
- Rectangle panel_rect = GetTabPanelRect (tab);\r
-\r
- if (tab.Appearance == TabAppearance.Normal) {\r
- ControlPaint.DrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top);\r
- ControlPaint.DrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom);\r
- }\r
+ DrawBackground (dc, area, tab);\r
\r
int start = 0;\r
int end = tab.TabPages.Count;\r
end = 0;\r
delta = -1;\r
}\r
+\r
+ if (tab.SizeMode == TabSizeMode.Fixed)\r
+ defaultFormatting.Alignment = StringAlignment.Center;\r
+ else\r
+ defaultFormatting.Alignment = StringAlignment.Near;\r
+\r
int counter = start;\r
for (; counter != end; counter += delta) {\r
for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {\r
if (tab.ShowSlider) {\r
Rectangle right = GetRightScrollRect (tab);\r
Rectangle left = GetLeftScrollRect (tab);\r
- ControlPaint.DrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);\r
- ControlPaint.DrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);\r
+ DrawScrollButton (dc, right, area, ScrollButton.Right, tab.RightSliderState);\r
+ DrawScrollButton (dc, left, area, ScrollButton.Left, tab.LeftSliderState);\r
+ }\r
+ }\r
+\r
+ protected virtual void DrawScrollButton (Graphics dc, Rectangle bounds, Rectangle clippingArea, ScrollButton button, PushButtonState state)\r
+ {\r
+ ControlPaint.DrawScrollButton (dc, bounds, button, GetButtonState (state));\r
+ }\r
+\r
+ static ButtonState GetButtonState (PushButtonState state)\r
+ {\r
+ switch (state) {\r
+ case PushButtonState.Pressed:\r
+ return ButtonState.Pushed;\r
+ default:\r
+ return ButtonState.Normal;\r
+ }\r
+ }\r
+\r
+ protected virtual void DrawBackground (Graphics dc, Rectangle area, TabControl tab)\r
+ {\r
+ Brush brush = SystemBrushes.Control;\r
+ dc.FillRectangle (brush, area);\r
+ Rectangle panel_rect = GetTabPanelRect (tab);\r
+\r
+ if (tab.Appearance == TabAppearance.Normal) {\r
+ ControlPaint.DrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top);\r
+ ControlPaint.DrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom);\r
}\r
}\r
\r
\r
case TabAlignment.Top:\r
\r
- dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);\r
+ dc.DrawLine (light, bounds.Left, bounds.Bottom - 1, bounds.Left, bounds.Top + 3);\r
dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 2, bounds.Top);\r
dc.DrawLine (light, bounds.Left + 2, bounds.Top, bounds.Right - 3, bounds.Top);\r
\r
}\r
}\r
\r
- interior = new Rectangle (bounds.Left + focusRectSpacing.X + borderThickness.Left, \r
- bounds.Top + focusRectSpacing.Y + + borderThickness.Top,\r
- bounds.Width - (focusRectSpacing.X * 2) - borderThickness.Width, \r
- bounds.Height - (focusRectSpacing.Y * 2) - borderThickness.Height);\r
+ Point padding = tab.Padding;\r
+ interior = new Rectangle (bounds.Left + padding.X - 1, // substract a little offset\r
+ bounds.Top + padding.Y,\r
+ bounds.Width - (padding.X * 2), \r
+ bounds.Height - (padding.Y * 2));\r
\r
if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {\r
if (tab.Alignment == TabAlignment.Left) {\r
dc.TranslateTransform (bounds.Left, bounds.Bottom);\r
dc.RotateTransform (-90);\r
- dc.DrawString (page.Text, page.Font,\r
+ dc.DrawString (page.Text, tab.Font,\r
SystemBrushes.ControlText, \r
tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming\r
tab.Padding.Y,\r
} else if (tab.Alignment == TabAlignment.Right) {\r
dc.TranslateTransform (bounds.Right, bounds.Top);\r
dc.RotateTransform (90);\r
- dc.DrawString (page.Text, page.Font,\r
+ dc.DrawString (page.Text, tab.Font,\r
SystemBrushes.ControlText, \r
tab.Padding.X - 2, // drawstring adds some extra unwanted leading spaces, so trimming\r
tab.Padding.Y,\r
Rectangle str_rect = interior;\r
\r
if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) {\r
- tab.ImageList.Draw (dc, new Point (interior.X, interior.Y), page.ImageIndex);\r
+ int image_x;\r
+ if (tab.SizeMode != TabSizeMode.Fixed) {\r
+ image_x = str_rect.X;\r
+ }\r
+ else {\r
+ image_x = str_rect.X + (str_rect.Width - tab.ImageList.ImageSize.Width) / 2;\r
+ if (page.Text != null) {\r
+ SizeF textSize = dc.MeasureString(page.Text, page.Font, str_rect.Size);\r
+ image_x -= (int)(textSize.Width / 2);\r
+ }\r
+ }\r
+ int image_y = str_rect.Y + (str_rect.Height - tab.ImageList.ImageSize.Height) / 2;\r
+ tab.ImageList.Draw (dc, new Point (image_x, image_y), page.ImageIndex);\r
str_rect.X += tab.ImageList.ImageSize.Width + 2;\r
str_rect.Width -= tab.ImageList.ImageSize.Width + 2;\r
}\r
- dc.DrawString (page.Text, page.Font,\r
- SystemBrushes.ControlText,
+ dc.DrawString (page.Text, tab.Font,\r
+ SystemBrushes.ControlText,\r
str_rect, \r
defaultFormatting);\r
\r
return res;\r
}\r
\r
+ // TabControl ignores the value of ShowFocusCues\r
if (page.Parent.Focused && is_selected) {\r
- ThemeEngine.Current.CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);\r
+ Rectangle focus_rect = bounds;\r
+ focus_rect.Inflate (-2, -2);\r
+ ThemeEngine.Current.CPDrawFocusRectangle (dc, focus_rect, tab.BackColor, tab.ForeColor);\r
}\r
\r
return res;\r
}\r
+\r
+ public virtual bool HasHotElementStyles (TabControl tabControl) {\r
+ return false;\r
+ }\r
}\r
}\r