Imported Upstream version 4.2.0.179

Former-commit-id: 4610231f55806d2a05ed69e5ff3faa7336cc1479
This commit is contained in:
Xamarin Public Jenkins
2015-08-26 07:17:56 -04:00
committed by Jo Shields
parent aa7da660d6
commit c042cd0c52
7507 changed files with 90259 additions and 657307 deletions

View File

@@ -0,0 +1,189 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Andreia Gaita (avidigal@novell.com)
using System;
using System.Drawing;
namespace System.Windows.Forms.Theming.Default
{
/// <summary>
/// Summary description for Button.
/// </summary>
internal class ButtonPainter
{
public ButtonPainter ()
{
}
protected SystemResPool ResPool { get { return ThemeEngine.Current.ResPool; } }
#region Buttons
#region Standard Button
public virtual void Draw (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor) {
bool is_themecolor = backColor.ToArgb () == ThemeEngine.Current.ColorControl.ToArgb () || backColor == Color.Empty ? true : false;
CPColor cpcolor = is_themecolor ? CPColor.Empty : ResPool.GetCPColor (backColor);
Pen pen;
switch (state) {
case ButtonThemeState.Normal:
case ButtonThemeState.Entered:
case ButtonThemeState.Disabled:
pen = is_themecolor ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
g.DrawLine (pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom - 2);
g.DrawLine (pen, bounds.X + 1, bounds.Y, bounds.Right - 2, bounds.Y);
pen = is_themecolor ? SystemPens.Control : ResPool.GetPen (backColor);
g.DrawLine (pen, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Bottom - 3);
g.DrawLine (pen, bounds.X + 2, bounds.Y + 1, bounds.Right - 3, bounds.Y + 1);
pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
g.DrawLine (pen, bounds.X + 1, bounds.Bottom - 2, bounds.Right - 2, bounds.Bottom - 2);
g.DrawLine (pen, bounds.Right - 2, bounds.Y + 1, bounds.Right - 2, bounds.Bottom - 3);
pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
g.DrawLine (pen, bounds.X, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
g.DrawLine (pen, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 2);
break;
case ButtonThemeState.Pressed:
g.DrawRectangle (ResPool.GetPen (foreColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
bounds.Inflate (-1, -1);
pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
g.DrawRectangle (pen, bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
break;
case ButtonThemeState.Default:
g.DrawRectangle (ResPool.GetPen (foreColor), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);
bounds.Inflate (-1, -1);
pen = is_themecolor ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
g.DrawLine (pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom - 2);
g.DrawLine (pen, bounds.X + 1, bounds.Y, bounds.Right - 2, bounds.Y);
pen = is_themecolor ? SystemPens.Control : ResPool.GetPen (backColor);
g.DrawLine (pen, bounds.X + 1, bounds.Y + 1, bounds.X + 1, bounds.Bottom - 3);
g.DrawLine (pen, bounds.X + 2, bounds.Y + 1, bounds.Right - 3, bounds.Y + 1);
pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
g.DrawLine (pen, bounds.X + 1, bounds.Bottom - 2, bounds.Right - 2, bounds.Bottom - 2);
g.DrawLine (pen, bounds.Right - 2, bounds.Y + 1, bounds.Right - 2, bounds.Bottom - 3);
pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
g.DrawLine (pen, bounds.X, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
g.DrawLine (pen, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 2);
break;
}
}
#endregion
#region FlatStyle Button
public virtual void DrawFlat (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor, FlatButtonAppearance appearance) {
bool is_themecolor = backColor.ToArgb () == ThemeEngine.Current.ColorControl.ToArgb () || backColor == Color.Empty ? true : false;
CPColor cpcolor = is_themecolor ? CPColor.Empty : ResPool.GetCPColor (backColor);
Pen pen;
switch (state) {
case ButtonThemeState.Normal:
case ButtonThemeState.Disabled:
// This will just use the BackColor
break;
case ButtonThemeState.Entered:
case ButtonThemeState.Default | ButtonThemeState.Entered:
if (appearance.MouseOverBackColor != Color.Empty)
g.FillRectangle (ResPool.GetSolidBrush (appearance.MouseOverBackColor), bounds);
else
g.FillRectangle (ResPool.GetSolidBrush (ChangeIntensity (backColor, .9F)), bounds);
break;
case ButtonThemeState.Pressed:
if (appearance.MouseDownBackColor != Color.Empty)
g.FillRectangle (ResPool.GetSolidBrush (appearance.MouseDownBackColor), bounds);
else
g.FillRectangle (ResPool.GetSolidBrush (ChangeIntensity (backColor, .95F)), bounds);
break;
case ButtonThemeState.Default:
if (appearance.CheckedBackColor != Color.Empty)
g.FillRectangle (ResPool.GetSolidBrush (appearance.CheckedBackColor), bounds);
break;
}
if (appearance.BorderColor == Color.Empty)
pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetSizedPen (cpcolor.DarkDark, appearance.BorderSize);
else
pen = ResPool.GetSizedPen (appearance.BorderColor, appearance.BorderSize);
bounds.Width -= 1;
bounds.Height -= 1;
if (appearance.BorderSize > 0)
g.DrawRectangle (pen, bounds);
}
#endregion
#region Popup Button
public virtual void DrawPopup (Graphics g, Rectangle bounds, ButtonThemeState state, Color backColor, Color foreColor) {
bool is_themecolor = backColor.ToArgb () == ThemeEngine.Current.ColorControl.ToArgb () || backColor == Color.Empty ? true : false;
CPColor cpcolor = is_themecolor ? CPColor.Empty : ResPool.GetCPColor (backColor);
Pen pen;
switch (state) {
case ButtonThemeState.Normal:
case ButtonThemeState.Disabled:
case ButtonThemeState.Pressed:
case ButtonThemeState.Default:
pen = is_themecolor ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
bounds.Width -= 1;
bounds.Height -= 1;
g.DrawRectangle (pen, bounds);
if (state == ButtonThemeState.Default || state == ButtonThemeState.Pressed) {
bounds.Inflate (-1, -1);
g.DrawRectangle (pen, bounds);
}
break;
case ButtonThemeState.Entered:
pen = is_themecolor ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
g.DrawLine (pen, bounds.X, bounds.Y, bounds.X, bounds.Bottom - 2);
g.DrawLine (pen, bounds.X + 1, bounds.Y, bounds.Right - 2, bounds.Y);
pen = is_themecolor ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
g.DrawLine (pen, bounds.X, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
g.DrawLine (pen, bounds.Right - 1, bounds.Y, bounds.Right - 1, bounds.Bottom - 2);
break;
}
}
#endregion
#endregion
private static Color ChangeIntensity (Color baseColor, float percent)
{
int H, I, S;
ControlPaint.Color2HBS (baseColor, out H, out I, out S);
int NewIntensity = Math.Min (255, (int)(I * percent));
return ControlPaint.HBS2Color (H, NewIntensity, S);
}
}
}

View File

@@ -0,0 +1,200 @@
2010-06-25 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Use TabControl.Font instead of the values of
TabPage.Font.
Fixes bits of #551032.
2010-06-20 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Actually draw the focus rectangle - TabControl
ignores the value of ShowFocusCues. Also, properly compute the bounds
for the focus rectangle, since it should include the padding of the
tab page.
Fixes bits of #515045.
2010-05-17 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Don't use FocusRectSpacing or BorderThickess
to calculate the interior rectangle to draw the tab contents, as
TabControl.Padding is enough - we had been ignoring it. This make
should our tab look more like that one in .net.
2010-05-17 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: When drawing tabs, use TabControl.Padding into
account for the interior rectangle for the text/image contents.
Fixes the remaining bits of #604034.
0201-05-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: The text for our tabs should always be
vertically centered, and it should be horizontally centered if the
size mode is Fixed. Patch from Thomas Goldstein (stifu@free.fr).
Fixes part of #599841.
2010-05-15 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Reduce the height for our default item size,
as we were ignoring the padding before.
2008-10-20 Jonathan Pobst <monkey@jpobst.com>
* ToolStripPainter.cs: Don't paint over a set BackgroundImage.
2008-10-09 Everaldo Canuto <ecanuto@novell.com>
* LinkLabelPainter.cs: Take Padding into account when drawing the linklabel
text.
2008-10-08 Everaldo Canuto <ecanuto@novell.com>
* LabelPainter.cs: Use control.PaddingClientRectangle instead of calculate
rectangle with padding. Also break some lines that theres more than 120
characters.
2008-09-24 Jonathan Pobst <monkey@jpobst.com>
* TabControlPainter.cs: Add 1 pixel to the tab text rectangle
to keep the text from getting cut off on XP.
[Fixes bug #428116]
2008-09-16 Jonathan Pobst <monkey@jpobst.com>
* TabControlPainter.cs: Hook tab painting into ShowFocusCues.
2008-07-31 George Giolfan <georgegiolfan@yahoo.com>
* TabControlPainter.cs: Added DrawScrollButton, GetButtonState.
2008-06-09 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: When calculating the display rectangle for
TabPage elements, don't include TabControlSelectedDelta.Y as part of
the page height, since it is only added ad the end (this is the way
it's done in TabControl). This way having a lot of pages with
Multiline as true doesn't add much extra space between the tab pages
labels and the actual tab pages area.
Fixes #393912.
2008-05-21 George Giolfan <georgegiolfan@yahoo.com>
* TabControlPainter.cs: Added HasHotElementStyles.
2008-05-19 George Giolfan <georgegiolfan@yahoo.com>
* TabControlPainter.cs: Refactored: Extracted DrawBackground.
2008-05-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Use HotPrefix.Show as the value of
StringFormat.HotPrefix when drawing the tab text.
Fixes #355193.
2008-05-16 Carlos Alberto Cortez <calberto.cortez@gmail.com>
* TabControlPainter.cs: Use StringAlignment.Near as the value for
StringFormat.Alignment when drawing the tab text.
Fixes part of #352399.
2008-02-25 Jonathan Pobst <monkey@jpobst.com>
* LabelPainter.cs: Take Padding into account when drawing
the label text.
2008-01-23 Everaldo Canuto <ecanuto@novell.com>
* LabelPainter.cs: Added.
2008-01-22 Everaldo Canuto <ecanuto@novell.com>
* LinkLabelPainter.cs: Change Draw method to virtual.
2008-01-22 Everaldo Canuto <ecanuto@novell.com>
* LinkLabelPainter.cs: Added.
2007-09-04 Everaldo Canuto <everaldo@simios.org>
* CheckBoxPainter.cs: Adjust checkbox light color to ControlLightLight to
mimic win32 look. Fixes #82656 (2.0).
2007-08-28 Jonathan Pobst <monkey@jpobst.com>
* RadioButtonPainter.cs: Added.
2007-08-22 Jonathan Pobst <monkey@jpobst.com>
* CheckBoxPainter.cs: Added.
2007-08-19 Everaldo Canuto <ecanuto@novell.com>
* TabControlPainter.cs: Fix regression in default padding x.
2007-08-19 Everaldo Canuto <ecanuto@novell.com>
* TabControlPainter.cs: Fix border thickness, padding and tab text format to
be horizontal centralized. Fixes #82471.
2007-08-18 Everaldo Canuto <ecanuto@novell.com>
* TabControlPainter.cs: Remove one vertical pixel from tab drawing, the
bottom line was one pixel more than needed.
2007-07-26 Everaldo Canuto <ecanuto@novell.com>
* TabControlPainter.cs: Adjust vertical image position on tab. Fixes #81837.
2007-07-26 Everaldo Canuto <ecanuto@novell.com>
* TabControlPainter.cs: Uses str_rect to draw text since it take in account
the image size. Fixes #81836.
2007-07-20 Jonathan Pobst <monkey@jpobst.com>
* ToolStripPainter.cs: Patch from Rolf. We weren't painting a
Checked button as sunken. [Fixes bug #82151]
2007-07-16 Jonathan Pobst <monkey@jpobst.com>
* ButtonPainter.cs: For flat buttons, draw mouse highlight when
button is focused. Remove random extra rectangle.
2007-07-16 Jonathan Pobst <monkey@jpobst.com>
* ButtonPainter.cs: For Flat button, if no mouse over / press
backcolor is specified, calculate one from the normal backcolor.
2007-07-12 Jonathan Pobst <monkey@jpobst.com>
* ButtonPainter.cs: For Flat button, if BorderSize is 0, don't
draw the rectangle. Setting the pen's width to 1 isn't good
enough, it still draws the border. [Fixes bug #82081]
2007-07-03 Jonathan Pobst <monkey@jpobst.com>
* ToolStripPainter.cs: Added. This is where we paint toolstrips
using the ToolStripSystemRenderer.
2007-05-04 Andreia Gaita <avidigal@novell.com>
* TabControlPainter.cs: Use ControlPaint static methods
instead of ThemeEngine ones (seeing as they're there and
all :p )
2007-04-15 Andreia Gaita <avidigal@novell.com>
* ButtonPainter.cs: refactoring of the button drawing
that was originally located in ThemeElementsDefault
* TabControlPainter.cs: refactoring of the tabcontrol
drawing code originally located in the ThemeWin32Classic.
Also, fixes and changes:
- replaced most hardcoded values with properties to
make it easier to customize implementations.
- fixed left and right alignment drawing problems
- fixed flatbutton border drawing on left and
right alignment
- fixed #79619
- fixed paddings, spacings and positioning.

View File

@@ -0,0 +1,357 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Jonathan Pobst (monkey@jpobst.com)
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace System.Windows.Forms.Theming.Default
{
/// <summary>
/// Summary description for Button.
/// </summary>
internal class CheckBoxPainter
{
public CheckBoxPainter ()
{
}
protected SystemResPool ResPool { get { return ThemeEngine.Current.ResPool; } }
public void PaintCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, ElementState state, FlatStyle style, CheckState checkState)
{
switch (style) {
case FlatStyle.Standard:
case FlatStyle.System:
switch (state) {
case ElementState.Normal:
DrawNormalCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Hot:
DrawHotCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Pressed:
DrawPressedCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Disabled:
DrawDisabledCheckBox (g, bounds, backColor, foreColor, checkState);
break;
}
break;
case FlatStyle.Flat:
switch (state) {
case ElementState.Normal:
DrawFlatNormalCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Hot:
DrawFlatHotCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Pressed:
DrawFlatPressedCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Disabled:
DrawFlatDisabledCheckBox (g, bounds, backColor, foreColor, checkState);
break;
}
break;
case FlatStyle.Popup:
switch (state) {
case ElementState.Normal:
DrawPopupNormalCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Hot:
DrawPopupHotCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Pressed:
DrawPopupPressedCheckBox (g, bounds, backColor, foreColor, checkState);
break;
case ElementState.Disabled:
DrawPopupDisabledCheckBox (g, bounds, backColor, foreColor, checkState);
break;
}
break;
}
}
#region Standard
public virtual void DrawNormalCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
int check_box_visible_size = (bounds.Height > bounds.Width) ? bounds.Width : bounds.Height;
int x_pos = Math.Max (0, bounds.X + (bounds.Width / 2) - check_box_visible_size / 2);
int y_pos = Math.Max (0, bounds.Y + (bounds.Height / 2) - check_box_visible_size / 2);
Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
g.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
Pen pen = SystemPens.ControlDark;
g.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
g.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
pen = SystemPens.ControlDarkDark;
g.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
g.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
pen = SystemPens.ControlLightLight;
g.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1);
g.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
// oh boy, matching ms is like fighting against windmills
using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50,
Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
ColorControl.G, ColorControl.B), ColorControl))) {
g.DrawLine (h_pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
g.DrawLine (h_pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 2);
}
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDark);
}
public virtual void DrawHotCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
DrawNormalCheckBox (g, bounds, backColor, foreColor, state);
}
public virtual void DrawPressedCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
int check_box_visible_size = (bounds.Height > bounds.Width) ? bounds.Width : bounds.Height;
int x_pos = Math.Max (0, bounds.X + (bounds.Width / 2) - check_box_visible_size / 2);
int y_pos = Math.Max (0, bounds.Y + (bounds.Height / 2) - check_box_visible_size / 2);
Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
g.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
ColorControl.G, ColorControl.B),
ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
Pen pen = SystemPens.ControlDark;
g.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
g.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
pen = SystemPens.ControlDarkDark;
g.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
g.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
pen = SystemPens.ControlLightLight;
g.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 1);
g.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
// oh boy, matching ms is like fighting against windmills
using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50,
Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
ColorControl.G, ColorControl.B), ColorControl))) {
g.DrawLine (h_pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
g.DrawLine (h_pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 2);
}
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawDisabledCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
DrawPressedCheckBox (g, bounds, backColor, foreColor, CheckState.Unchecked);
if (state == CheckState.Checked || state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDark);
}
#endregion
#region FlatStyle
public virtual void DrawFlatNormalCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
Rectangle checkbox_rectangle;
Rectangle fill_rectangle;
// set up our rectangles first
// clip two pixels from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle (bounds.X, bounds.Y, Math.Max (bounds.Width - 2, 0), Math.Max (bounds.Height - 2, 0));
fill_rectangle = new Rectangle (checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max (checkbox_rectangle.Width - 2, 0), Math.Max (checkbox_rectangle.Height - 2, 0));
g.FillRectangle (ResPool.GetSolidBrush (ControlPaint.LightLight (backColor)), fill_rectangle);
ControlPaint.DrawBorder (g, checkbox_rectangle, foreColor, ButtonBorderStyle.Solid);
bounds.Offset (-1, 0);
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawFlatHotCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
Rectangle checkbox_rectangle;
Rectangle fill_rectangle;
// set up our rectangles first
// clip two pixels from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle (bounds.X, bounds.Y, Math.Max (bounds.Width - 2, 0), Math.Max (bounds.Height - 2, 0));
fill_rectangle = new Rectangle (checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max (checkbox_rectangle.Width - 2, 0), Math.Max (checkbox_rectangle.Height - 2, 0));
g.FillRectangle (ResPool.GetSolidBrush (backColor), fill_rectangle);
ControlPaint.DrawBorder (g, checkbox_rectangle, foreColor, ButtonBorderStyle.Solid);
bounds.Offset (-1, 0);
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawFlatPressedCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
DrawFlatNormalCheckBox (g, bounds, backColor, foreColor, state);
}
public virtual void DrawFlatDisabledCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
Rectangle checkbox_rectangle;
checkbox_rectangle = new Rectangle (bounds.X, bounds.Y, Math.Max (bounds.Width - 2, 0), Math.Max (bounds.Height - 2, 0));
ControlPaint.DrawBorder (g, checkbox_rectangle, foreColor, ButtonBorderStyle.Solid);
bounds.Offset (-1, 0);
if (state == CheckState.Checked || state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
#endregion
#region Popup
public virtual void DrawPopupNormalCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
DrawFlatNormalCheckBox (g, bounds, backColor, foreColor, state);
}
public virtual void DrawPopupHotCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
Rectangle checkbox_rectangle;
Rectangle fill_rectangle;
// clip one pixel from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle (bounds.X, bounds.Y, Math.Max (bounds.Width - 1, 0), Math.Max (bounds.Height - 1, 0));
fill_rectangle = new Rectangle (checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max (checkbox_rectangle.Width - 3, 0), Math.Max (checkbox_rectangle.Height - 3, 0));
g.FillRectangle (ResPool.GetSolidBrush (ControlPaint.LightLight (backColor)), fill_rectangle);
// draw sunken effect
ThemeEngine.Current.CPDrawBorder3D (g, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, backColor);
bounds.Offset (-1, 0);
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawPopupPressedCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
Rectangle checkbox_rectangle;
Rectangle fill_rectangle;
// clip one pixel from bottom right for non popup rendered checkboxes
checkbox_rectangle = new Rectangle (bounds.X, bounds.Y, Math.Max (bounds.Width - 1, 0), Math.Max (bounds.Height - 1, 0));
fill_rectangle = new Rectangle (checkbox_rectangle.X + 1, checkbox_rectangle.Y + 1, Math.Max (checkbox_rectangle.Width - 3, 0), Math.Max (checkbox_rectangle.Height - 3, 0));
g.FillRectangle (ResPool.GetSolidBrush (backColor), fill_rectangle);
// draw sunken effect
ThemeEngine.Current.CPDrawBorder3D (g, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, backColor);
bounds.Offset (-1, 0);
if (state == CheckState.Checked)
DrawCheck (g, bounds, Color.Black);
else if (state == CheckState.Indeterminate)
DrawCheck (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawPopupDisabledCheckBox (Graphics g, Rectangle bounds, Color backColor, Color foreColor, CheckState state)
{
DrawFlatDisabledCheckBox (g, bounds, backColor, foreColor, state);
}
#endregion
#region Check
public virtual void DrawCheck (Graphics g, Rectangle bounds, Color checkColor)
{
int check_size = (bounds.Height > bounds.Width) ? bounds.Width / 2 : bounds.Height / 2;
Pen check_pen = ResPool.GetPen (checkColor);
if (check_size < 7) {
int lineWidth = Math.Max (3, check_size / 3);
int Scale = Math.Max (1, check_size / 9);
Rectangle rect = new Rectangle (bounds.X + (bounds.Width / 2) - (check_size / 2) - 1, bounds.Y + (bounds.Height / 2) - (check_size / 2) - 1,
check_size, check_size);
for (int i = 0; i < lineWidth; i++) {
g.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
g.DrawLine (check_pen, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i, rect.Left + lineWidth / 2 + 6 * Scale, rect.Top + lineWidth - 2 * Scale + i);
}
} else {
int lineWidth = Math.Max (3, check_size / 3) + 1;
int x_half = bounds.Width / 2;
int y_half = bounds.Height / 2;
Rectangle rect = new Rectangle (bounds.X + x_half - (check_size / 2) - 1, bounds.Y + y_half - (check_size / 2),
check_size, check_size);
int gradient_left = check_size / 3;
int gradient_right = check_size - gradient_left - 1;
for (int i = 0; i < lineWidth; i++) {
g.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
g.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
}
}
}
#endregion
#region Private Methods
private int Clamp (int value, int lower, int upper)
{
if (value < lower) return lower;
else if (value > upper) return upper;
else return value;
}
private Color ColorControl {
get { return SystemColors.Control; }
}
#endregion
}
}

View File

@@ -0,0 +1,57 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Everaldo Canuto (ecanuto@novell.com)
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace System.Windows.Forms.Theming.Default
{
internal class LabelPainter
{
public LabelPainter ()
{
}
public virtual void Draw (Graphics dc, Rectangle client_rectangle, Label label)
{
Rectangle rect = label.PaddingClientRectangle;
label.DrawImage (dc, label.Image, rect, label.ImageAlign);
if (label.Enabled) {
dc.DrawString (label.Text, label.Font,
ThemeEngine.Current.ResPool.GetSolidBrush (label.ForeColor),
rect, label.string_format);
} else {
ControlPaint.DrawStringDisabled (
dc, label.Text, label.Font, label.BackColor, rect, label.string_format);
}
}
public virtual Size DefaultSize {
get { return new Size (100, 23); }
}
}
}

View File

@@ -0,0 +1,120 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Everaldo Canuto (ecanuto@novell.com)
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace System.Windows.Forms.Theming.Default
{
internal class LinkLabelPainter
{
public LinkLabelPainter ()
{
}
private Color GetPieceColor (LinkLabel label, LinkLabel.Piece piece, int i)
{
if (!label.Enabled)
return label.DisabledLinkColor;
if (piece.link == null)
return label.ForeColor;
if (!piece.link.Enabled)
return label.DisabledLinkColor;
if (piece.link.Active)
return label.ActiveLinkColor;
if ((label.LinkVisited && i == 0) || piece.link.Visited)
return label.VisitedLinkColor;
return label.LinkColor;
}
public virtual void Draw (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
{
Rectangle client_rect = label.PaddingClientRectangle;
label.DrawImage (dc, label.Image, client_rect, label.ImageAlign);
if (label.pieces == null)
return;
// Paint all text as disabled.
if (!label.Enabled) {
dc.SetClip (clip_rectangle);
ThemeEngine.Current.CPDrawStringDisabled (
dc, label.Text, label.Font, label.BackColor, client_rect, label.string_format);
return;
}
Font font, link_font = ThemeEngine.Current.GetLinkFont (label);
Region text_region = new Region (new Rectangle());
// Draw links.
for (int i = 0; i < label.pieces.Length; i ++) {
LinkLabel.Piece piece = label.pieces[i];
if (piece.link == null) {
text_region.Union (piece.region);
continue;
}
Color color = GetPieceColor (label, piece, i);
if ( (label.LinkBehavior == LinkBehavior.AlwaysUnderline) ||
(label.LinkBehavior == LinkBehavior.SystemDefault) ||
((label.LinkBehavior == LinkBehavior.HoverUnderline) && piece.link.Hovered) )
font = link_font;
else
font = label.Font;
dc.Clip = piece.region;
dc.Clip.Intersect (clip_rectangle);
dc.DrawString (label.Text, font,
ThemeEngine.Current.ResPool.GetSolidBrush (color),
client_rect, label.string_format);
// Draw focus rectangle
if ((piece.link != null) && piece.link.Focused) {
foreach (RectangleF rect in piece.region.GetRegionScans (dc.Transform))
ControlPaint.DrawFocusRectangle (dc, Rectangle.Round (rect), label.ForeColor, label.BackColor);
}
}
// Draw normal text (without links).
if (!text_region.IsEmpty (dc)) {
dc.Clip = text_region;
dc.Clip.Intersect (clip_rectangle);
if (!dc.Clip.IsEmpty (dc))
dc.DrawString(label.Text, label.Font,
ThemeEngine.Current.ResPool.GetSolidBrush(label.ForeColor),
client_rect, label.string_format);
}
}
}
}

View File

@@ -0,0 +1,239 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Jonathan Pobst (monkey@jpobst.com)
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace System.Windows.Forms.Theming.Default
{
/// <summary>
/// Summary description for Button.
/// </summary>
internal class RadioButtonPainter
{
public RadioButtonPainter ()
{
}
protected SystemResPool ResPool { get { return ThemeEngine.Current.ResPool; } }
public void PaintRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, ElementState state, FlatStyle style, bool isChecked)
{
switch (style) {
case FlatStyle.Standard:
case FlatStyle.System:
switch (state) {
case ElementState.Normal:
DrawNormalRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Hot:
DrawHotRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Pressed:
DrawPressedRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Disabled:
DrawDisabledRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
}
break;
case FlatStyle.Flat:
switch (state) {
case ElementState.Normal:
DrawFlatNormalRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Hot:
DrawFlatHotRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Pressed:
DrawFlatPressedRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Disabled:
DrawFlatDisabledRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
}
break;
case FlatStyle.Popup:
switch (state) {
case ElementState.Normal:
DrawPopupNormalRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Hot:
DrawPopupHotRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Pressed:
DrawPopupPressedRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
case ElementState.Disabled:
DrawPopupDisabledRadioButton (g, bounds, backColor, foreColor, isChecked);
break;
}
break;
}
}
#region Standard
public virtual void DrawNormalRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
ButtonState bs = ButtonState.Normal;
if (isChecked)
bs |= ButtonState.Checked;
ControlPaint.DrawRadioButton (g, bounds, bs);
}
public virtual void DrawHotRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
DrawNormalRadioButton (g, bounds, backColor, foreColor, isChecked);
}
public virtual void DrawPressedRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
ButtonState bs = ButtonState.Pushed;
if (isChecked)
bs |= ButtonState.Checked;
ControlPaint.DrawRadioButton (g, bounds, bs);
}
public virtual void DrawDisabledRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
ButtonState bs = ButtonState.Inactive;
if (isChecked)
bs |= ButtonState.Checked;
ControlPaint.DrawRadioButton (g, bounds, bs);
}
#endregion
#region FlatStyle
public virtual void DrawFlatNormalRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.DrawArc (SystemPens.ControlDarkDark, bounds, 0, 359);
g.FillPie (SystemBrushes.ControlLightLight, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawFlatHotRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.DrawArc (SystemPens.ControlDarkDark, bounds, 0, 359);
g.FillPie (SystemBrushes.ControlLight, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawFlatPressedRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.DrawArc (SystemPens.ControlDarkDark, bounds, 0, 359);
g.FillPie (SystemBrushes.ControlLightLight, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawFlatDisabledRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.FillPie (SystemBrushes.Control, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
g.DrawArc (SystemPens.ControlDark, bounds, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDark);
}
#endregion
#region Popup
public virtual void DrawPopupNormalRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.FillPie (SystemBrushes.ControlLightLight, bounds, 0, 359);
g.DrawArc (SystemPens.ControlDark, bounds, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawPopupHotRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.FillPie (SystemBrushes.ControlLightLight, bounds, 0, 359);
g.DrawArc (SystemPens.ControlLight, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
g.DrawArc (SystemPens.ControlDark, bounds, 135, 180);
g.DrawArc (SystemPens.ControlLightLight, bounds, 315, 180);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawPopupPressedRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.FillPie (SystemBrushes.ControlLightLight, bounds, 0, 359);
g.DrawArc (SystemPens.ControlLight, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
g.DrawArc (SystemPens.ControlDark, bounds, 135, 180);
g.DrawArc (SystemPens.ControlLightLight, bounds, 315, 180);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
public virtual void DrawPopupDisabledRadioButton (Graphics g, Rectangle bounds, Color backColor, Color foreColor, bool isChecked)
{
g.FillPie (SystemBrushes.Control, bounds.X + 1, bounds.Y + 1, bounds.Width - 2, bounds.Height - 2, 0, 359);
g.DrawArc (SystemPens.ControlDark, bounds, 0, 359);
if (isChecked)
DrawFlatRadioGlyphDot (g, bounds, SystemColors.ControlDarkDark);
}
#endregion
#region Glyph
protected void DrawFlatRadioGlyphDot (Graphics g, Rectangle bounds, Color dotColor)
{
int lineWidth = Math.Max (1, Math.Min (bounds.Width, bounds.Height) / 3);
Pen dot_pen = ResPool.GetPen (dotColor);
Brush dot_brush = ResPool.GetSolidBrush (dotColor);
if (bounds.Height > 13) {
g.FillPie (dot_brush, bounds.X + lineWidth, bounds.Y + lineWidth, bounds.Width - lineWidth * 2, bounds.Height - lineWidth * 2, 0, 359);
} else {
int x_half_pos = (bounds.Width / 2) + bounds.X;
int y_half_pos = (bounds.Height / 2) + bounds.Y;
g.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
g.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
g.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
g.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
}
}
#endregion
}
}

View File

@@ -0,0 +1,189 @@
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Copyright (c) 2007 Novell, Inc.
//
// Authors:
// Jonathan Pobst (monkey@jpobst.com)
using System;
using System.Drawing;
namespace System.Windows.Forms.Theming.Default
{
internal class ToolStripPainter
{
public ToolStripPainter ()
{
}
protected SystemResPool ResPool { get { return ThemeEngine.Current.ResPool; } }
#region Painting
public virtual void OnRenderButtonBackground (ToolStripItemRenderEventArgs e)
{
if (e.Item.Enabled == false)
return;
Rectangle paint_here = new Rectangle (0, 0, e.Item.Width, e.Item.Height);
ToolStripButton tsb = e.Item as ToolStripButton;
if (e.Item.Pressed || (tsb != null && tsb.Checked))
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.SunkenOuter);
else if (e.Item.Selected)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), paint_here);
}
public virtual void OnRenderDropDownButtonBackground (ToolStripItemRenderEventArgs e)
{
if (e.Item.Enabled == false)
return;
Rectangle paint_here = new Rectangle (0, 0, e.Item.Width, e.Item.Height);
if (e.Item.Pressed)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.SunkenOuter);
else if (e.Item.Selected)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), paint_here);
}
public virtual void OnRenderGrip (ToolStripGripRenderEventArgs e)
{
if (e.GripStyle == ToolStripGripStyle.Hidden)
return;
if (e.GripDisplayStyle == ToolStripGripDisplayStyle.Vertical) {
e.Graphics.DrawLine (Pens.White, 0, 2, 1, 2);
e.Graphics.DrawLine (Pens.White, 0, 2, 0, e.GripBounds.Height - 3);
e.Graphics.DrawLine (SystemPens.ControlDark, 2, 2, 2, e.GripBounds.Height - 3);
e.Graphics.DrawLine (SystemPens.ControlDark, 2, e.GripBounds.Height - 3, 0, e.GripBounds.Height - 3);
}
else {
e.Graphics.DrawLine (Pens.White, 2, 0, e.GripBounds.Width - 3, 0);
e.Graphics.DrawLine (Pens.White, 2, 0, 2, 1);
e.Graphics.DrawLine (SystemPens.ControlDark, e.GripBounds.Width - 3, 0, e.GripBounds.Width - 3, 2);
e.Graphics.DrawLine (SystemPens.ControlDark, 2, 2, e.GripBounds.Width - 3, 2);
}
}
public virtual void OnRenderMenuItemBackground (ToolStripItemRenderEventArgs e)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)e.Item;
Rectangle paint_here = new Rectangle (Point.Empty, tsmi.Size);
if (tsmi.IsOnDropDown) {
// Drop down menu item
if (e.Item.Selected || e.Item.Pressed)
e.Graphics.FillRectangle (SystemBrushes.Highlight, paint_here);
} else {
// Top level menu item
if (e.Item.Pressed)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.SunkenOuter);
else if (e.Item.Selected)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), paint_here);
}
}
public virtual void OnRenderOverflowButtonBackground (ToolStripItemRenderEventArgs e)
{
Rectangle paint_here = new Rectangle (Point.Empty, e.Item.Size);
if (e.Item.Pressed)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.SunkenOuter);
else if (e.Item.Selected)
ControlPaint.DrawBorder3D (e.Graphics, paint_here, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), paint_here);
// Paint the arrow
ToolStripRenderer.DrawDownArrow (e.Graphics, SystemPens.ControlText, e.Item.Width / 2 - 3, e.Item.Height / 2 - 1);
}
public virtual void OnRenderSeparator (ToolStripSeparatorRenderEventArgs e)
{
if (e.Vertical) {
e.Graphics.DrawLine (Pens.White, 4, 3, 4, e.Item.Height - 1);
e.Graphics.DrawLine (SystemPens.ControlDark, 3, 3, 3, e.Item.Height - 1);
} else {
if (!e.Item.IsOnDropDown) {
e.Graphics.DrawLine (Pens.White, 2, 4, e.Item.Right - 1, 4);
e.Graphics.DrawLine (SystemPens.ControlDark, 2, 3, e.Item.Right - 1, 3);
} else {
e.Graphics.DrawLine (Pens.White, 3, 4, e.Item.Right - 4, 4);
e.Graphics.DrawLine (SystemPens.ControlDark, 3, 3, e.Item.Right - 4, 3);
}
}
}
public virtual void OnRenderSplitButtonBackground (ToolStripItemRenderEventArgs e)
{
ToolStripSplitButton tssb = (ToolStripSplitButton)e.Item;
Rectangle button_part = new Rectangle (Point.Empty, tssb.ButtonBounds.Size);
Point drop_start = new Point (tssb.Width - tssb.DropDownButtonBounds.Width, 0);
Rectangle drop_part = new Rectangle (drop_start, tssb.DropDownButtonBounds.Size);
// Regular button part
if (tssb.ButtonPressed)
ControlPaint.DrawBorder3D (e.Graphics, button_part, Border3DStyle.SunkenOuter);
else if (tssb.ButtonSelected)
ControlPaint.DrawBorder3D (e.Graphics, button_part, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), button_part);
// Drop down button part
if (tssb.DropDownButtonPressed || tssb.ButtonPressed)
ControlPaint.DrawBorder3D (e.Graphics, drop_part, Border3DStyle.SunkenOuter);
else if (tssb.DropDownButtonSelected || tssb.ButtonSelected)
ControlPaint.DrawBorder3D (e.Graphics, drop_part, Border3DStyle.RaisedInner);
else if (e.Item.BackColor != Control.DefaultBackColor && e.Item.BackColor != Color.Empty)
e.Graphics.FillRectangle (ResPool.GetSolidBrush (e.Item.BackColor), drop_part);
}
public virtual void OnRenderToolStripBackground (ToolStripRenderEventArgs e)
{
if (e.ToolStrip.BackgroundImage == null)
e.Graphics.Clear (e.BackColor);
if (e.ToolStrip is StatusStrip)
e.Graphics.DrawLine (Pens.White, e.AffectedBounds.Left, e.AffectedBounds.Top, e.AffectedBounds.Right, e.AffectedBounds.Top);
}
public virtual void OnRenderToolStripBorder (ToolStripRenderEventArgs e)
{
if (e.ToolStrip is StatusStrip)
return;
if (e.ToolStrip is ToolStripDropDown)
ControlPaint.DrawBorder3D (e.Graphics, e.AffectedBounds, Border3DStyle.Raised);
else {
e.Graphics.DrawLine (SystemPens.ControlDark, new Point (e.ToolStrip.Left, e.ToolStrip.Height - 2), new Point (e.ToolStrip.Right, e.ToolStrip.Height - 2));
e.Graphics.DrawLine (Pens.White, new Point (e.ToolStrip.Left, e.ToolStrip.Height - 1), new Point (e.ToolStrip.Right, e.ToolStrip.Height - 1));
}
}
#endregion
}
}