using System.Drawing.Printing;
using System.Drawing.Text;
using System.Text;
+using System.Windows.Forms.Theming;
namespace System.Windows.Forms
{
const int SEPARATOR_MIN_WIDTH = 20;
const int SM_CXBORDER = 1;
const int SM_CYBORDER = 1;
- const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
- const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
+ const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tabd
+ const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
#region Principal Theme Methods
public ThemeWin32Classic ()
string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
string_format_menu_menubar_text.Alignment = StringAlignment.Center;
string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
- always_draw_hotkeys = false;
}
public override void ResetDefaults() {
}
#endregion // Internal Methods
+ #region Control
+ public override Font GetLinkFont (Control control)
+ {
+ return new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Underline, control.Font.Unit);
+ }
+ #endregion // Control
+
#region OwnerDraw Support
public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
{
}
#endregion // OwnerDraw Support
- #region ButtonBase
- public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
+ #region Button
+ #region Standard Button Style
+ public override void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
+ {
+ // Draw Button Background
+ DrawButtonBackground (g, b, clipRectangle);
+
+ // If we have an image, draw it
+ if (imageBounds.Size != Size.Empty)
+ DrawButtonImage (g, b, imageBounds);
+
+ // If we're focused, draw a focus rectangle
+ if (b.Focused && b.Enabled)
+ DrawButtonFocus (g, b);
+
+ // If we have text, draw it
+ if (textBounds != Rectangle.Empty)
+ DrawButtonText (g, b, textBounds);
+ }
+
+ public virtual void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
+ {
+ if (button.Pressed)
+ ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
+ else if (button.InternalSelected)
+ ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
+ else if (button.Entered)
+ ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
+ else if (!button.Enabled)
+ ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
+ else
+ ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
+ }
+
+ public virtual void DrawButtonFocus (Graphics g, Button button)
+ {
+ ControlPaint.DrawFocusRectangle (g, Rectangle.Inflate (button.ClientRectangle, -4, -4));
+ }
+
+ public virtual void DrawButtonImage (Graphics g, Button button, Rectangle imageBounds)
+ {
+ if (button.Enabled)
+ g.DrawImage (button.Image, imageBounds);
+ else
+ CPDrawImageDisabled (g, button.Image, imageBounds.Left, imageBounds.Top, ColorControl);
+ }
+
+ public virtual void DrawButtonText (Graphics g, Button button, Rectangle textBounds)
+ {
+ if (button.Enabled)
+ TextRenderer.DrawTextInternal (g, button.Text, button.Font, textBounds, button.ForeColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
+ else
+ DrawStringDisabled20 (g, button.Text, button.Font, textBounds, button.BackColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
+ }
+ #endregion
+
+ #region FlatStyle Button Style
+ public override void DrawFlatButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
+ {
+ // Draw Button Background
+ DrawFlatButtonBackground (g, b, clipRectangle);
+
+ // If we have an image, draw it
+ if (imageBounds.Size != Size.Empty)
+ DrawFlatButtonImage (g, b, imageBounds);
+
+ // If we're focused, draw a focus rectangle
+ if (b.Focused && b.Enabled)
+ DrawFlatButtonFocus (g, b);
+
+ // If we have text, draw it
+ if (textBounds != Rectangle.Empty)
+ DrawFlatButtonText (g, b, textBounds);
+ }
+
+ public virtual void DrawFlatButtonBackground (Graphics g, Button button, Rectangle clipArea)
+ {
+ if (button.Pressed)
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor, button.FlatAppearance);
+ else if (button.InternalSelected) {
+ if (button.Entered)
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default | ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
+ else
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor, button.FlatAppearance);
+ }
+ else if (button.Entered)
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
+ else if (!button.Enabled)
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor, button.FlatAppearance);
+ else
+ ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor, button.FlatAppearance);
+ }
+
+ public virtual void DrawFlatButtonFocus (Graphics g, Button button)
+ {
+ if (!button.Pressed) {
+ Color focus_color = ControlPaint.Dark (button.BackColor);
+ g.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.Left + 4, button.ClientRectangle.Top + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9));
+ }
+ }
+
+ public virtual void DrawFlatButtonImage (Graphics g, Button button, Rectangle imageBounds)
+ {
+ // No changes from Standard for image for this theme
+ DrawButtonImage (g, button, imageBounds);
+ }
+
+ public virtual void DrawFlatButtonText (Graphics g, Button button, Rectangle textBounds)
+ {
+ // No changes from Standard for text for this theme
+ DrawButtonText (g, button, textBounds);
+ }
+ #endregion
+
+ #region Popup Button Style
+ public override void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
+ {
+ // Draw Button Background
+ DrawPopupButtonBackground (g, b, clipRectangle);
+
+ // If we have an image, draw it
+ if (imageBounds.Size != Size.Empty)
+ DrawPopupButtonImage (g, b, imageBounds);
+
+ // If we're focused, draw a focus rectangle
+ if (b.Focused && b.Enabled)
+ DrawPopupButtonFocus (g, b);
+
+ // If we have text, draw it
+ if (textBounds != Rectangle.Empty)
+ DrawPopupButtonText (g, b, textBounds);
+ }
+
+ public virtual void DrawPopupButtonBackground (Graphics g, Button button, Rectangle clipArea)
+ {
+ if (button.Pressed)
+ ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
+ else if (button.Entered)
+ ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
+ else if (button.InternalSelected)
+ ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
+ else if (!button.Enabled)
+ ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
+ else
+ ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
+ }
+
+ public virtual void DrawPopupButtonFocus (Graphics g, Button button)
+ {
+ // No changes from Standard for image for this theme
+ DrawButtonFocus (g, button);
+ }
+
+ public virtual void DrawPopupButtonImage (Graphics g, Button button, Rectangle imageBounds)
+ {
+ // No changes from Standard for image for this theme
+ DrawButtonImage (g, button, imageBounds);
+ }
+
+ public virtual void DrawPopupButtonText (Graphics g, Button button, Rectangle textBounds)
+ {
+ // No changes from Standard for image for this theme
+ DrawButtonText (g, button, textBounds);
+ }
+ #endregion
+
+ #region Button Layout Calculations
+#if NET_2_0
+ public override Size CalculateButtonAutoSize (Button button)
+ {
+ Size ret_size = Size.Empty;
+ Size text_size = TextRenderer.MeasureTextInternal (button.Text, button.Font, button.UseCompatibleTextRendering);
+ Size image_size = button.Image == null ? Size.Empty : button.Image.Size;
- // Fill the button with the correct color
- bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
- dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
+ // Pad the text size
+ if (button.Text.Length != 0) {
+ text_size.Height += 4;
+ text_size.Width += 4;
+ }
- // First, draw the image
- if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null)))
- ButtonBase_DrawImage(button, dc);
+ switch (button.TextImageRelation) {
+ case TextImageRelation.Overlay:
+ ret_size.Height = Math.Max (button.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
+ ret_size.Width = Math.Max (text_size.Width, image_size.Width);
+ break;
+ case TextImageRelation.ImageAboveText:
+ case TextImageRelation.TextAboveImage:
+ ret_size.Height = text_size.Height + image_size.Height;
+ ret_size.Width = Math.Max (text_size.Width, image_size.Width);
+ break;
+ case TextImageRelation.ImageBeforeText:
+ case TextImageRelation.TextBeforeImage:
+ ret_size.Height = Math.Max (text_size.Height, image_size.Height);
+ ret_size.Width = text_size.Width + image_size.Width;
+ break;
+ }
+
+ // Pad the result
+ ret_size.Height += (button.Padding.Vertical + 6);
+ ret_size.Width += (button.Padding.Horizontal + 6);
+ return ret_size;
+ }
+#endif
+
+ public override void CalculateButtonTextAndImageLayout (ButtonBase button, out Rectangle textRectangle, out Rectangle imageRectangle)
+ {
+ Image image = button.Image;
+ string text = button.Text;
+ Rectangle content_rect = button.ClientRectangle;
+ Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
+ Size image_size = image == null ? Size.Empty : image.Size;
+
+ textRectangle = Rectangle.Empty;
+ imageRectangle = Rectangle.Empty;
+
+ switch (button.TextImageRelation) {
+ case TextImageRelation.Overlay:
+ // Overlay is easy, text always goes here
+ textRectangle = Rectangle.Inflate (content_rect, -4, -4);
+
+ if (button.Pressed)
+ textRectangle.Offset (1, 1);
+
+ // Image is dependent on ImageAlign
+ if (image == null)
+ return;
+
+ int image_x = 0;
+ int image_y = 0;
+ int image_height = image.Height;
+ int image_width = image.Width;
+
+ switch (button.ImageAlign) {
+ case System.Drawing.ContentAlignment.TopLeft:
+ image_x = 5;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.TopCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.TopRight:
+ image_x = content_rect.Width - image_width - 5;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.MiddleLeft:
+ image_x = 5;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.MiddleCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.MiddleRight:
+ image_x = content_rect.Width - image_width - 4;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.BottomLeft:
+ image_x = 5;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ case System.Drawing.ContentAlignment.BottomCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ case System.Drawing.ContentAlignment.BottomRight:
+ image_x = content_rect.Width - image_width - 4;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ default:
+ image_x = 5;
+ image_y = 5;
+ break;
+ }
+
+ imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
+ break;
+ case TextImageRelation.ImageAboveText:
+ content_rect.Inflate (-4, -4);
+ LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.TextAboveImage:
+ content_rect.Inflate (-4, -4);
+ LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.ImageBeforeText:
+ content_rect.Inflate (-4, -4);
+ LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.TextBeforeImage:
+ content_rect.Inflate (-4, -4);
+ LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ }
+ }
+
+ private void LayoutTextBeforeOrAfterImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
+ {
+ int element_spacing = 0; // Spacing between the Text and the Image
+ int total_width = textSize.Width + element_spacing + imageSize.Width;
+
+ if (!textFirst)
+ element_spacing += 2;
+
+ // If the text is too big, chop it down to the size we have available to it
+ if (total_width > totalArea.Width) {
+ textSize.Width = totalArea.Width - element_spacing - imageSize.Width;
+ total_width = totalArea.Width;
+ }
+
+ int excess_width = totalArea.Width - total_width;
+ int offset = 0;
+
+ Rectangle final_text_rect;
+ Rectangle final_image_rect;
+
+ HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
+ HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
+
+ if (h_image == HorizontalAlignment.Left)
+ offset = 0;
+ else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
+ offset = excess_width;
+ else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
+ offset += (int)(excess_width / 3);
+ else
+ offset += (int)(2 * (excess_width / 3));
+
+ if (textFirst) {
+ final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
+ final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
+ }
+ else {
+ final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
+ final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
+ }
+
+ textRect = final_text_rect;
+ imageRect = final_image_rect;
+ }
+
+ private void LayoutTextAboveOrBelowImage (Rectangle totalArea, bool textFirst, Size textSize, Size imageSize, System.Drawing.ContentAlignment textAlign, System.Drawing.ContentAlignment imageAlign, out Rectangle textRect, out Rectangle imageRect)
+ {
+ int element_spacing = 0; // Spacing between the Text and the Image
+ int total_height = textSize.Height + element_spacing + imageSize.Height;
+
+ if (textFirst)
+ element_spacing += 2;
+
+ if (textSize.Width > totalArea.Width)
+ textSize.Width = totalArea.Width;
+
+ // If the there isn't enough room and we're text first, cut out the image
+ if (total_height > totalArea.Height && textFirst) {
+ imageSize = Size.Empty;
+ total_height = totalArea.Height;
+ }
+
+ int excess_height = totalArea.Height - total_height;
+ int offset = 0;
+
+ Rectangle final_text_rect;
+ Rectangle final_image_rect;
+
+ VerticalAlignment v_text = GetVerticalAlignment (textAlign);
+ VerticalAlignment v_image = GetVerticalAlignment (imageAlign);
+
+ if (v_image == VerticalAlignment.Top)
+ offset = 0;
+ else if (v_image == VerticalAlignment.Bottom && v_text == VerticalAlignment.Bottom)
+ offset = excess_height;
+ else if (v_image == VerticalAlignment.Center && (v_text == VerticalAlignment.Top || v_text == VerticalAlignment.Center))
+ offset += (int)(excess_height / 3);
+ else
+ offset += (int)(2 * (excess_height / 3));
+
+ if (textFirst) {
+ final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textSize.Height);
+ final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, final_text_rect.Bottom + element_spacing, imageSize.Width, imageSize.Height);
+ }
+ else {
+ final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, totalArea.Top + offset, imageSize.Width, imageSize.Height);
+ final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textSize.Height);
+
+ if (final_text_rect.Bottom > totalArea.Bottom)
+ final_text_rect.Y = totalArea.Top;
+ }
+
+ textRect = final_text_rect;
+ imageRect = final_image_rect;
+ }
+
+ private HorizontalAlignment GetHorizontalAlignment (System.Drawing.ContentAlignment align)
+ {
+ switch (align) {
+ case System.Drawing.ContentAlignment.BottomLeft:
+ case System.Drawing.ContentAlignment.MiddleLeft:
+ case System.Drawing.ContentAlignment.TopLeft:
+ return HorizontalAlignment.Left;
+ case System.Drawing.ContentAlignment.BottomCenter:
+ case System.Drawing.ContentAlignment.MiddleCenter:
+ case System.Drawing.ContentAlignment.TopCenter:
+ return HorizontalAlignment.Center;
+ case System.Drawing.ContentAlignment.BottomRight:
+ case System.Drawing.ContentAlignment.MiddleRight:
+ case System.Drawing.ContentAlignment.TopRight:
+ return HorizontalAlignment.Right;
+ }
+
+ return HorizontalAlignment.Left;
+ }
+
+ private enum VerticalAlignment
+ {
+ Top = 0,
+ Center = 1,
+ Bottom = 2
+ }
+
+ private VerticalAlignment GetVerticalAlignment (System.Drawing.ContentAlignment align)
+ {
+ switch (align) {
+ case System.Drawing.ContentAlignment.TopLeft:
+ case System.Drawing.ContentAlignment.TopCenter:
+ case System.Drawing.ContentAlignment.TopRight:
+ return VerticalAlignment.Top;
+ case System.Drawing.ContentAlignment.MiddleLeft:
+ case System.Drawing.ContentAlignment.MiddleCenter:
+ case System.Drawing.ContentAlignment.MiddleRight:
+ return VerticalAlignment.Center;
+ case System.Drawing.ContentAlignment.BottomLeft:
+ case System.Drawing.ContentAlignment.BottomCenter:
+ case System.Drawing.ContentAlignment.BottomRight:
+ return VerticalAlignment.Bottom;
+ }
+
+ return VerticalAlignment.Top;
+ }
+
+ internal Rectangle AlignInRectangle (Rectangle outer, Size inner, System.Drawing.ContentAlignment align)
+ {
+ int x = 0;
+ int y = 0;
+
+ if (align == System.Drawing.ContentAlignment.BottomLeft || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.TopLeft)
+ x = outer.X;
+ else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.TopCenter)
+ x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
+ else if (align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.MiddleRight || align == System.Drawing.ContentAlignment.TopRight)
+ x = outer.Right - inner.Width;
+ if (align == System.Drawing.ContentAlignment.TopCenter || align == System.Drawing.ContentAlignment.TopLeft || align == System.Drawing.ContentAlignment.TopRight)
+ y = outer.Y;
+ else if (align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.MiddleRight)
+ y = outer.Y + (outer.Height - inner.Height) / 2;
+ else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.BottomLeft)
+ y = outer.Bottom - inner.Height;
+
+ return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
+ }
+ #endregion
+ #endregion
+
+ #region ButtonBase
+ public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button)
+ {
// Draw the button: Draw border, etc.
ButtonBase_DrawButton(button, dc);
+
+ // Draw the image
+ if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null)))
+ ButtonBase_DrawImage(button, dc);
// Draw the focus rectangle
if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled)
int height = button.ClientSize.Height;
if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
- i = button.image_list.Images[button.image_index];
+ i = button.image_list.Images[button.ImageIndex];
} else {
i = button.image;
}
image_width = i.Width;
image_height = i.Height;
- switch (button.image_alignment) {
+ switch (button.ImageAlign) {
case ContentAlignment.TopLeft: {
image_x = 5;
image_y = 5;
}
}
- if (button.Enabled) {
- dc.DrawImage(i, image_x, image_y, image_width, image_height);
- }
- else {
- CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
- }
+ dc.SetClip (new Rectangle(3, 3, width - 5, height - 5));
+
+ if (button.Enabled)
+ dc.DrawImage (i, image_x, image_y, image_width, image_height);
+ else
+ CPDrawImageDisabled (dc, i, image_x, image_y, ColorControl);
+
+ dc.ResetClip ();
}
protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
#endregion // ButtonBase
#region CheckBox
+#if NET_2_0
+ public override void DrawCheckBox (Graphics g, CheckBox cb, Rectangle glyphArea, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
+ {
+ // Draw Button Background
+ DrawCheckBoxGlyph (g, cb, glyphArea);
+
+ // If we have an image, draw it
+ if (imageBounds.Size != Size.Empty)
+ DrawCheckBoxImage (g, cb, imageBounds);
+
+ if (cb.Focused && cb.Enabled && cb.ShowKeyboardCuesInternal && textBounds != Rectangle.Empty)
+ DrawCheckBoxFocus (g, cb, textBounds);
+
+ // If we have text, draw it
+ if (textBounds != Rectangle.Empty)
+ DrawCheckBoxText (g, cb, textBounds);
+ }
+
+ public virtual void DrawCheckBoxGlyph (Graphics g, CheckBox cb, Rectangle glyphArea)
+ {
+ if (cb.Pressed)
+ ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Pressed, cb.FlatStyle, cb.CheckState);
+ else if (cb.InternalSelected)
+ ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
+ else if (cb.Entered)
+ ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Hot, cb.FlatStyle, cb.CheckState);
+ else if (!cb.Enabled)
+ ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Disabled, cb.FlatStyle, cb.CheckState);
+ else
+ ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
+ }
+
+ public virtual void DrawCheckBoxFocus (Graphics g, CheckBox cb, Rectangle focusArea)
+ {
+ ControlPaint.DrawFocusRectangle (g, focusArea);
+ }
+
+ public virtual void DrawCheckBoxImage (Graphics g, CheckBox cb, Rectangle imageBounds)
+ {
+ if (cb.Enabled)
+ g.DrawImage (cb.Image, imageBounds);
+ else
+ CPDrawImageDisabled (g, cb.Image, imageBounds.Left, imageBounds.Top, ColorControl);
+ }
+
+ public virtual void DrawCheckBoxText (Graphics g, CheckBox cb, Rectangle textBounds)
+ {
+ if (cb.Enabled)
+ TextRenderer.DrawTextInternal (g, cb.Text, cb.Font, textBounds, cb.ForeColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
+ else
+ DrawStringDisabled20 (g, cb.Text, cb.Font, textBounds, cb.BackColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
+ }
+
+ public override void CalculateCheckBoxTextAndImageLayout (ButtonBase button, Point p, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
+ {
+ int check_size = 13;
+ glyphArea = new Rectangle (0, (button.Height - check_size) / 2, check_size, check_size);
+
+ Image image = button.Image;
+ string text = button.Text;
+ Rectangle content_rect = button.ClientRectangle;
+ content_rect.Width -= check_size;
+ content_rect.Offset (check_size, 0);
+
+ Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
+ Size image_size = image == null ? Size.Empty : image.Size;
+
+ textRectangle = Rectangle.Empty;
+ imageRectangle = Rectangle.Empty;
+
+ switch (button.TextImageRelation) {
+ case TextImageRelation.Overlay:
+ // Overlay is easy, text always goes here
+ textRectangle = Rectangle.Inflate (content_rect, -4, -4);
+ textRectangle.Offset (0, -2);
+
+ // Image is dependent on ImageAlign
+ if (image == null)
+ return;
+
+ int image_x = 0;
+ int image_y = 0;
+ int image_height = image.Height;
+ int image_width = image.Width;
+
+ switch (button.ImageAlign) {
+ case System.Drawing.ContentAlignment.TopLeft:
+ image_x = 5;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.TopCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.TopRight:
+ image_x = content_rect.Width - image_width - 5;
+ image_y = 5;
+ break;
+ case System.Drawing.ContentAlignment.MiddleLeft:
+ image_x = 5;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.MiddleCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.MiddleRight:
+ image_x = content_rect.Width - image_width - 4;
+ image_y = (content_rect.Height - image_height) / 2;
+ break;
+ case System.Drawing.ContentAlignment.BottomLeft:
+ image_x = 5;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ case System.Drawing.ContentAlignment.BottomCenter:
+ image_x = (content_rect.Width - image_width) / 2;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ case System.Drawing.ContentAlignment.BottomRight:
+ image_x = content_rect.Width - image_width - 4;
+ image_y = content_rect.Height - image_height - 4;
+ break;
+ default:
+ image_x = 5;
+ image_y = 5;
+ break;
+ }
+
+ imageRectangle = new Rectangle (image_x + check_size, image_y, image_width, image_height);
+ break;
+ case TextImageRelation.ImageAboveText:
+ content_rect.Inflate (-4, -4);
+ LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.TextAboveImage:
+ content_rect.Inflate (-4, -4);
+ LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.ImageBeforeText:
+ content_rect.Inflate (-4, -4);
+ LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ case TextImageRelation.TextBeforeImage:
+ content_rect.Inflate (-4, -4);
+ LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
+ break;
+ }
+ }
+
+ public override Size CalculateCheckBoxAutoSize (CheckBox checkBox)
+ {
+ Size ret_size = Size.Empty;
+ Size text_size = TextRenderer.MeasureTextInternal (checkBox.Text, checkBox.Font, checkBox.UseCompatibleTextRendering);
+ Size image_size = checkBox.Image == null ? Size.Empty : checkBox.Image.Size;
+
+ // Pad the text size
+ if (checkBox.Text.Length != 0) {
+ text_size.Height += 4;
+ text_size.Width += 4;
+ }
+
+ switch (checkBox.TextImageRelation) {
+ case TextImageRelation.Overlay:
+ ret_size.Height = Math.Max (checkBox.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
+ ret_size.Width = Math.Max (text_size.Width, image_size.Width);
+ break;
+ case TextImageRelation.ImageAboveText:
+ case TextImageRelation.TextAboveImage:
+ ret_size.Height = text_size.Height + image_size.Height;
+ ret_size.Width = Math.Max (text_size.Width, image_size.Width);
+ break;
+ case TextImageRelation.ImageBeforeText:
+ case TextImageRelation.TextBeforeImage:
+ ret_size.Height = Math.Max (text_size.Height, image_size.Height);
+ ret_size.Width = text_size.Width + image_size.Width;
+ break;
+ }
+
+ // Pad the result
+ ret_size.Height += (checkBox.Padding.Vertical);
+ ret_size.Width += (checkBox.Padding.Horizontal) + 15;
+
+ // There seems to be a minimum height
+ if (ret_size.Height == checkBox.Padding.Vertical)
+ ret_size.Height += 14;
+
+ return ret_size;
+ }
+#endif
+
public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
StringFormat text_format;
Rectangle client_rectangle;
checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
text_format = new StringFormat();
- text_format.Alignment=StringAlignment.Near;
- text_format.LineAlignment=StringAlignment.Center;
- text_format.HotkeyPrefix = HotkeyPrefix.Show;
+ text_format.Alignment = StringAlignment.Near;
+ text_format.LineAlignment = StringAlignment.Center;
+ if (checkbox.ShowKeyboardCuesInternal)
+ text_format.HotkeyPrefix = HotkeyPrefix.Show;
+ else
+ text_format.HotkeyPrefix = HotkeyPrefix.Hide;
/* Calculate the position of text and checkbox rectangle */
if (checkbox.appearance!=Appearance.Button) {
if (ctrl.ThreeDCheckBoxes == false)
state |= ButtonState.Flat;
- Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
+ Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 13, 13);
ControlPaint.DrawCheckBox (e.Graphics,
item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
checkbox_rect.Width, checkbox_rect.Height,
state);
- item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
- item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
+ item_rect.X += checkbox_rect.Right;
+ item_rect.Width -= checkbox_rect.Right;
/* Draw text*/
if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
ResPool.GetSolidBrush (fore_color),
- item_rect, ctrl.StringFormat);
+ item_rect.X, item_rect.Y, ctrl.StringFormat);
if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
CPDrawFocusRectangle (e.Graphics, item_rect,
string_format.Dispose ();
}
+
+ public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
+ {
+ Point[] arrow = new Point[3];
+ Point P1;
+ Point P2;
+ Point P3;
+ int centerX;
+ int centerY;
+ int shiftX;
+ int shiftY;
+ Rectangle rect;
+
+ rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
+ centerX=rect.Left+rect.Width/2;
+ centerY=rect.Top+rect.Height/2;
+ shiftX=Math.Max(1, rect.Width/8);
+ shiftY=Math.Max(1, rect.Height/8);
+
+ if ((state & ButtonState.Pushed)!=0) {
+ shiftX++;
+ shiftY++;
+ }
+
+ rect.Y-=shiftY;
+ centerY-=shiftY;
+ P1=new Point(rect.Left + 1, centerY);
+ P2=new Point(rect.Right - 1, centerY);
+ P3=new Point(centerX, rect.Bottom - 1);
+
+ arrow[0]=P1;
+ arrow[1]=P2;
+ arrow[2]=P3;
+
+ /* Draw the arrow */
+ if ((state & ButtonState.Inactive)!=0) {
+ /* Move away from the shadow */
+ arrow[0].X += 1; arrow[0].Y += 1;
+ arrow[1].X += 1; arrow[1].Y += 1;
+ arrow[2].X += 1; arrow[2].Y += 1;
+
+ graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
+
+ arrow[0]=P1;
+ arrow[1]=P2;
+ arrow[2]=P3;
+
+ graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
+ } else {
+ graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
+ }
+ }
#endregion ComboBox
#region Datagrid
public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
{
- Rectangle columns_area = grid.columnhdrs_area;
+ Rectangle columns_area = grid.column_headers_area;
if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
- Rectangle rect_bloc = grid.columnhdrs_area;
+ Rectangle rect_bloc = grid.column_headers_area;
rect_bloc.Width = grid.RowHeaderWidth;
if (clip.IntersectsWith (rect_bloc)) {
if (grid.VisibleColumnCount > 0)
}
// Set unused area
- Rectangle columnhdrs_area_complete = columns_area;
- columnhdrs_area_complete.Width = grid.columnhdrs_maxwidth;
+ Rectangle column_headers_area_complete = columns_area;
+ column_headers_area_complete.Width = grid.column_headers_max_width;
if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
- columnhdrs_area_complete.Width -= grid.RowHeaderWidth;
+ column_headers_area_complete.Width -= grid.RowHeaderWidth;
}
// Set column painting
g.Clip = prev_clip;
- Rectangle not_usedarea = columnhdrs_area_complete;
+ Rectangle not_usedarea = column_headers_area_complete;
not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
rect_row.Width = grid.ParentRowsArea.Width;
rect_row.Height = (grid.CaptionFont.Height + 3);
- object[] parentRows = grid.dataSourceStack.ToArray();
+ object[] parentRows = grid.data_source_stack.ToArray();
Region current_clip;
Region prev_clip = g.Clip;
#endregion // Label
#region LinkLabel
- public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
+
+ private Color LinkLabelGetPieceColor (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 override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
{
dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
if (label.pieces == null)
return;
- for (int i = 0; i < label.pieces.Length; i ++) {
- RectangleF clipf = new RectangleF (clip_rectangle.X, clip_rectangle.Y,
- clip_rectangle.Width, clip_rectangle.Height);
- RectangleF rectf = label.pieces[i].region.GetBounds (dc);
+ // Paint all text as disabled.
+ if (!label.Enabled) {
+ dc.SetClip (clip_rectangle);
+ CPDrawStringDisabled (dc, label.Text, label.Font, label.BackColor, label.ClientRectangle, label.string_format);
+ return;
+ }
+
+ Font font, link_font = GetLinkFont (label);
+
+ Region text_region = new Region (new Rectangle());
- if (!clipf.IntersectsWith (rectf))
+ // 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;
+ }
- dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.GetPieceColor (label.pieces[i], i)),
- rectf, label.string_format);
+ Color color = LinkLabelGetPieceColor (label, piece, i);
- LinkLabel.Link link = label.pieces[i].link;
- if (link != null && link.Focused) {
- Rectangle rect = new Rectangle ((int)rectf.X, (int)rectf.Y,
- (int)rectf.Width, (int)rectf.Height);
- CPDrawFocusRectangle (dc, rect, label.ForeColor, label.BackColor);
+ 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, ResPool.GetSolidBrush (color), label.ClientRectangle, 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, ResPool.GetSolidBrush(label.ForeColor), label.ClientRectangle, label.string_format);
+ }
}
+
#endregion // LinkLabel
+
#region ListBox
public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
int first = control.FirstVisibleIndex;
for (int i = first; i <= control.LastVisibleIndex; i ++) {
- if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
- DrawListViewItem (dc, control, control.Items [i]);
+ if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire))) {
+#if NET_2_0
+ bool owner_draw = false;
+ if (control.OwnerDraw)
+ owner_draw = DrawListViewItemOwnerDraw (dc, control.Items [i], i);
+ if (!owner_draw)
+#endif
+ DrawListViewItem (dc, control, control.Items [i]);
+ }
}
+
+#if NET_2_0
+ // draw group headers
+ if (control.ShowGroups && control.View != View.List) {
+ for (int i = 0; i < control.Groups.Count; i++) {
+ ListViewGroup group = control.Groups [i];
+ if (group.Items.Count > 0 && clip.IntersectsWith (group.HeaderBounds))
+ DrawListViewGroupHeader (dc, control, group);
+ }
+ }
+#endif
// draw the gridlines
if (details && control.GridLines) {
dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
}
-
+
public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
{
bool details = (control.View == View.Details);
// border is drawn directly in the Paint method
if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
- dc.FillRectangle (GetControlBackBrush (control.BackColor),
+ dc.FillRectangle (SystemBrushes.Control,
0, 0, control.TotalWidth, control.Font.Height + 5);
if (control.Columns.Count > 0) {
foreach (ColumnHeader col in control.Columns) {
Rectangle rect = col.Rect;
rect.X -= control.h_marker;
+
+#if NET_2_0
+ bool owner_draw = false;
+ if (control.OwnerDraw)
+ owner_draw = DrawListViewColumnHeaderOwnerDraw (dc, control, col, rect);
+ if (owner_draw)
+ continue;
+#endif
+
ButtonState state;
if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
else
state = ButtonState.Flat;
- this.CPDrawButton (dc, rect, state);
- rect.X += 3;
- rect.Width -= 8;
+ CPDrawButton (dc, rect, state);
+ rect.X += 8;
+ rect.Width -= 13;
if (rect.Width <= 0)
continue;
+
dc.DrawString (col.Text, DefaultFont,
SystemBrushes.ControlText,
rect, col.Format);
}
- int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
+ int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker;
if (right < control.Right) {
Rectangle rect = control.Columns [0].Rect;
rect.X = right;
dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
}
+#if NET_2_0
+ protected virtual bool DrawListViewColumnHeaderOwnerDraw (Graphics dc, ListView control, ColumnHeader column, Rectangle bounds)
+ {
+ ListViewItemStates state = ListViewItemStates.ShowKeyboardCues;
+ if (column.Pressed)
+ state |= ListViewItemStates.Selected;
+
+ DrawListViewColumnHeaderEventArgs args = new DrawListViewColumnHeaderEventArgs (dc,
+ bounds, column.Index, column, state, SystemColors.ControlText, ThemeEngine.Current.ColorControl, DefaultFont);
+ control.OnDrawColumnHeader (args);
+
+ return !args.DrawDefault;
+ }
+
+ protected virtual bool DrawListViewItemOwnerDraw (Graphics dc, ListViewItem item, int index)
+ {
+ ListViewItemStates item_state = ListViewItemStates.ShowKeyboardCues;
+ if (item.Selected)
+ item_state |= ListViewItemStates.Selected;
+ if (item.Focused)
+ item_state |= ListViewItemStates.Focused;
+
+ DrawListViewItemEventArgs args = new DrawListViewItemEventArgs (dc,
+ item, item.Bounds, index, item_state);
+ item.ListView.OnDrawItem (args);
+
+ if (args.DrawDefault)
+ return false;
+
+ if (item.ListView.View == View.Details)
+ for (int i = 0; i < item.SubItems.Count; i++) {
+ int count = Math.Min (item.ListView.Columns.Count, item.SubItems.Count);
+
+ // Do system drawing for subitems if no owner draw is done
+ for (int j = 0; j < count; j++)
+ if (!DrawListViewSubItemOwnerDraw (dc, item, item_state, j))
+ DrawListViewSubItem (dc, item.ListView, item, j);
+ }
+
+ return true;
+ }
+#endif
+
protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
{
- int col_offset;
- if (control.View == View.Details && control.Columns.Count > 0)
- col_offset = control.Columns [0].Rect.X;
- else
- col_offset = 0;
-
Rectangle rect_checkrect = item.CheckRectReal;
- rect_checkrect.X += col_offset;
Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
- icon_rect.X += col_offset;
Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
- full_rect.X += col_offset;
Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
- text_rect.X += col_offset;
#if NET_2_0
// Tile view doesn't support CheckBoxes
// adjustments to get the check-mark at the right place
rect.X ++; rect.Y ++;
// following logic is taken from DrawFrameControl method
+ int x_offset = rect.Width / 5;
+ int y_offset = rect.Height / 3;
for (int i = 0; i < check_wd; i++) {
- dc.DrawLine (check_pen, rect.Left + check_wd / 2,
- rect.Top + check_wd + i,
- rect.Left + check_wd / 2 + 2 * scale,
- rect.Top + check_wd + 2 * scale + i);
+ dc.DrawLine (check_pen, rect.Left + x_offset,
+ rect.Top + y_offset + i,
+ rect.Left + x_offset + 2 * scale,
+ rect.Top + y_offset + 2 * scale + i);
dc.DrawLine (check_pen,
- rect.Left + check_wd / 2 + 2 * scale,
- rect.Top + check_wd + 2 * scale + i,
- rect.Left + check_wd / 2 + 6 * scale,
- rect.Top + check_wd - 2 * scale + i);
+ rect.Left + x_offset + 2 * scale,
+ rect.Top + y_offset + 2 * scale + i,
+ rect.Left + x_offset + 6 * scale,
+ rect.Top + y_offset - 2 * scale + i);
}
}
}
else {
- if (item.Checked && control.StateImageList.Images.Count > 1)
- control.StateImageList.Draw (dc,
- rect_checkrect.Location, 1);
- else if (! item.Checked && control.StateImageList.Images.Count > 0)
- control.StateImageList.Draw (dc,
- rect_checkrect.Location, 0);
+ int simage_idx;
+ if (item.Checked)
+#if NET_2_0
+ simage_idx = control.StateImageList.Images.Count > 1 ? 1 : -1;
+#else
+ simage_idx = control.StateImageList.Images.Count > 1 ? 1 : 0;
+#endif
+ else
+ simage_idx = control.StateImageList.Images.Count > 0 ? 0 : -1;
+
+ if (simage_idx > -1)
+ control.StateImageList.Draw (dc, rect_checkrect.Location, simage_idx);
}
}
// draw the item text
// format for the item text
StringFormat format = new StringFormat ();
- if (control.View == View.SmallIcon)
+ if (control.View == View.SmallIcon || control.View == View.LargeIcon)
format.LineAlignment = StringAlignment.Near;
else
format.LineAlignment = StringAlignment.Center;
format.FormatFlags = StringFormatFlags.LineLimit;
else
format.FormatFlags = StringFormatFlags.NoWrap;
-
+
+ if ((control.View == View.LargeIcon && !item.Focused)
+ || control.View == View.Details
+#if NET_2_0
+ || control.View == View.Tile
+#endif
+ )
+ format.Trimming = StringTrimming.EllipsisCharacter;
+
Rectangle highlight_rect = text_rect;
- if (control.View == View.Details && !control.FullRowSelect) {
+ if (control.View == View.Details) { // Adjustments for Details view
Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
- highlight_rect.Width = text_size.Width + 4;
+
+ if (!control.FullRowSelect) // Selection shouldn't be outside the item bounds
+ highlight_rect.Width = Math.Min (text_size.Width + 4, text_rect.Width);
}
if (item.Selected && control.Focused)
#endif
if (item.Text != null && item.Text.Length > 0) {
+ Font font = item.Font;
+#if NET_2_0
+ if (control.HotTracking && item.Hot)
+ font = item.HotFont;
+#endif
+
if (item.Selected && control.Focused)
- dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format);
+ dc.DrawString (item.Text, font, textBrush, highlight_rect, format);
else
- dc.DrawString (item.Text, item.Font, textBrush, text_rect, format);
+ dc.DrawString (item.Text, font, textBrush, text_rect, format);
}
if (control.View == View.Details && control.Columns.Count > 0) {
control.Columns.Count : subItems.Count);
if (count > 0) {
- ColumnHeader col;
- ListViewItem.ListViewSubItem subItem;
- Rectangle sub_item_rect = text_rect;
-
- // set the format for subitems
- format.FormatFlags = StringFormatFlags.NoWrap;
-
// 0th subitem is the item already drawn
- for (int index = 1; index < count; index++) {
- subItem = subItems [index];
- col = control.Columns [index];
- format.Alignment = col.Format.Alignment;
- sub_item_rect.X = col.Rect.X - control.h_marker;
- sub_item_rect.Width = col.Wd;
- Rectangle sub_item_text_rect = sub_item_rect;
- sub_item_text_rect.X += 3;
- sub_item_text_rect.Width -= 6;
-
- SolidBrush sub_item_back_br = null;
- SolidBrush sub_item_fore_br = null;
- Font sub_item_font = null;
-
- if (item.UseItemStyleForSubItems) {
- sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
- sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
- sub_item_font = item.Font;
- } else {
- sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
- sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
- sub_item_font = subItem.Font;
- }
-
- if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
- Brush bg, text;
- if (control.Focused) {
- bg = SystemBrushes.Highlight;
- text = SystemBrushes.HighlightText;
- } else {
- bg = SystemBrushes.Control;
- text = sub_item_fore_br;
- }
-
- dc.FillRectangle (bg, sub_item_rect);
- if (subItem.Text != null && subItem.Text.Length > 0)
- dc.DrawString (subItem.Text, sub_item_font,
- text, sub_item_text_rect, format);
- } else {
- dc.FillRectangle (sub_item_back_br, sub_item_rect);
- if (subItem.Text != null && subItem.Text.Length > 0)
- dc.DrawString (subItem.Text, sub_item_font,
- sub_item_fore_br,
- sub_item_text_rect, format);
- }
- }
+ for (int index = 1; index < count; index++)
+ DrawListViewSubItem (dc, control, item, index);
// Fill in selection for remaining columns if Column.Count > SubItems.Count
+ ColumnHeader col;
+ Rectangle sub_item_rect = text_rect;
if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
- for (int index = count; index < control.Columns.Count; index++)
- {
+ for (int index = count; index < control.Columns.Count; index++) {
col = control.Columns [index];
sub_item_rect.X = col.Rect.X - control.h_marker;
sub_item_rect.Width = col.Wd;
format.Dispose ();
}
+ protected virtual void DrawListViewSubItem (Graphics dc, ListView control, ListViewItem item, int index)
+ {
+ ListViewItem.ListViewSubItem subItem = item.SubItems [index];
+ ColumnHeader col = control.Columns [index];
+ StringFormat format = new StringFormat ();
+ format.Alignment = col.Format.Alignment;
+ format.FormatFlags = StringFormatFlags.NoWrap;
+ format.Trimming = StringTrimming.EllipsisCharacter;
+
+ Rectangle sub_item_rect = subItem.Bounds;
+ Rectangle sub_item_text_rect = sub_item_rect;
+ sub_item_text_rect.X += 3;
+ sub_item_text_rect.Width -= 6;
+
+ SolidBrush sub_item_back_br = null;
+ SolidBrush sub_item_fore_br = null;
+ Font sub_item_font = null;
+
+ if (item.UseItemStyleForSubItems) {
+ sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
+ sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
+#if NET_2_0
+ // Hot tracking for subitems only applies when UseStyle is true
+ if (control.HotTracking && item.Hot)
+ sub_item_font = item.HotFont;
+ else
+#endif
+ sub_item_font = item.Font;
+ } else {
+ sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
+ sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
+ sub_item_font = subItem.Font;
+ }
+
+ if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
+ Brush bg, text;
+ if (control.Focused) {
+ bg = SystemBrushes.Highlight;
+ text = SystemBrushes.HighlightText;
+ } else {
+ bg = SystemBrushes.Control;
+ text = sub_item_fore_br;
+
+ }
+
+ dc.FillRectangle (bg, sub_item_rect);
+ if (subItem.Text != null && subItem.Text.Length > 0)
+ dc.DrawString (subItem.Text, sub_item_font,
+ text, sub_item_text_rect, format);
+ } else {
+ dc.FillRectangle (sub_item_back_br, sub_item_rect);
+ if (subItem.Text != null && subItem.Text.Length > 0)
+ dc.DrawString (subItem.Text, sub_item_font,
+ sub_item_fore_br,
+ sub_item_text_rect, format);
+ }
+
+ format.Dispose ();
+ }
+
+#if NET_2_0
+ protected virtual bool DrawListViewSubItemOwnerDraw (Graphics dc, ListViewItem item, ListViewItemStates state, int index)
+ {
+ ListView control = item.ListView;
+ ListViewItem.ListViewSubItem subitem = item.SubItems [index];
+
+ DrawListViewSubItemEventArgs args = new DrawListViewSubItemEventArgs (dc, subitem.Bounds, item,
+ subitem, item.Index, index, control.Columns [index], state);
+ control.OnDrawSubItem (args);
+
+ return !args.DrawDefault;
+ }
+
+ protected virtual void DrawListViewGroupHeader (Graphics dc, ListView control, ListViewGroup group)
+ {
+ Rectangle text_bounds = group.HeaderBounds;
+ Rectangle header_bounds = group.HeaderBounds;
+ text_bounds.Offset (8, 0);
+ text_bounds.Inflate (-8, 0);
+ Size text_size = control.text_size;
+
+ Font font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
+ Brush brush = new LinearGradientBrush (new Point (header_bounds.Left, 0), new Point (header_bounds.Left + ListViewGroupLineWidth, 0),
+ SystemColors.Desktop, Color.White);
+ Pen pen = new Pen (brush);
+
+ StringFormat sformat = new StringFormat ();
+ switch (group.HeaderAlignment) {
+ case HorizontalAlignment.Left:
+ sformat.Alignment = StringAlignment.Near;
+ break;
+ case HorizontalAlignment.Center:
+ sformat.Alignment = StringAlignment.Center;
+ break;
+ case HorizontalAlignment.Right:
+ sformat.Alignment = StringAlignment.Far;
+ break;
+ }
+
+ sformat.LineAlignment = StringAlignment.Near;
+ dc.DrawString (group.Header, font, SystemBrushes.ControlText, text_bounds, sformat);
+ dc.DrawLine (pen, header_bounds.Left, header_bounds.Top + text_size.Height, header_bounds.Left + ListViewGroupLineWidth,
+ header_bounds.Top + text_size.Height);
+
+ sformat.Dispose ();
+ font.Dispose ();
+ pen.Dispose ();
+ brush.Dispose ();
+ }
+#endif
+
// Sizing
public override Size ListViewCheckBoxSize {
get { return new Size (16, 16); }
}
public override int ListViewHorizontalSpacing {
- get { return 10; }
+ get { return 4; }
}
public override Size ListViewDefaultSize {
get { return 20; }
}
+ public int ListViewGroupLineWidth {
+ get { return 200; }
+ }
+
public override int ListViewTileWidthFactor {
get { return 22; }
}
#endregion // ListView
#region Menus
+
public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
{
item.X = x;
menu.Height = 0;
while (start < menu.MenuItems.Count) {
- y = 2;
+ y = 3;
max = 0;
for (i = start; i < menu.MenuItems.Count; i++) {
MenuItem item = menu.MenuItems [i];
menu.Height += 2;
menu.Width += SM_CXBORDER;
- menu.Height += SM_CYBORDER;
+ menu.Height += SM_CYBORDER;
}
// Draws a menu bar in a window
if (menu.Height == 0)
CalcMenuBarSize (dc, menu, rect.Width);
- bool keynav = (menu as MainMenu).tracker.Navigating;
- HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
+ bool keynav = (menu as MainMenu).tracker.hotkey_active;
+ HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
string_format_menu_menubar_text.HotkeyPrefix = hp;
string_format_menu_text.HotkeyPrefix = hp;
bg_color = Color.White;
else
bg_color = Color.Black;
+
Bitmap bmp = new Bitmap (size.Width, size.Height);
Graphics gr = Graphics.FromImage (bmp);
Rectangle rect = new Rectangle (Point.Empty, size);
gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
- CPDrawMenuGlyph (gr, rect, glyph, color);
+ CPDrawMenuGlyph (gr, rect, glyph, color, Color.Empty);
bmp.MakeTransparent (bg_color);
gr.Dispose ();
+
return bmp;
}
if (item.BarBreak) { /* Draw vertical break bar*/
Rectangle rect = e.Bounds;
rect.Y++;
- rect.Width = 3;
- rect.Height = item.MenuHeight - 6;
+ rect.Width = 3;
+ rect.Height = item.MenuHeight - 6;
e.Graphics.DrawLine (SystemPens.ControlDark,
rect.X, rect.Y , rect.X, rect.Y + rect.Height);
}
/* Draw background */
- Rectangle rect_back = e.Bounds;
- rect_back.X++;
- rect_back.Width -=2;
if (!item.MenuBar)
- e.Graphics.FillRectangle (brush_back, rect_back);
+ e.Graphics.FillRectangle (brush_back, e.Bounds);
if (item.Enabled) {
e.Graphics.DrawString (item.Text, e.Font,
border_style = Border3DStyle.SunkenOuter;
if (border_style != Border3DStyle.Adjust)
- CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
+ CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
}
} else {
if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
{
-
+ // Fill rectangle area
dc.FillRectangle (SystemBrushes.Menu, cliparea);
- Pen pen_cht = SystemPens.HighlightText;
- Pen pen_ccd = SystemPens.ControlDark;
- Pen pen_ccdd = SystemPens.ControlDarkDark;
-
- /* Draw menu borders */
- dc.DrawLine (pen_cht,
- rect.X, rect.Y, rect.X + rect.Width, rect.Y);
-
- dc.DrawLine (pen_cht,
- rect.X, rect.Y, rect.X, rect.Y + rect.Height);
-
- dc.DrawLine (pen_ccd,
- rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
-
- dc.DrawLine (pen_ccdd,
- rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
-
- dc.DrawLine (pen_ccd,
- rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
-
- dc.DrawLine (pen_ccdd,
- rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
-
- for (int i = 0; i < menu.MenuItems.Count; i++)
+ // Draw menu borders
+ CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
+
+ // Draw menu items
+ for (int i = 0; i < menu.MenuItems.Count; i++) {
if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
MenuItem item = menu.MenuItems [i];
item.MenuHeight = menu.Height;
- item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
- item.bounds, i, item.Status));
+ item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item.bounds, i, item.Status));
+ }
}
}
dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
break;
+#if NET_2_0
+ case PictureBoxSizeMode.Zoom:
+ dc.FillRectangle (GetControlBackBrush (pb.BackColor), clip);
+
+ Size image_size;
+
+ if (((float)pb.Image.Width / (float)pb.Image.Height) >= ((float)client.Width / (float)client.Height))
+ image_size = new Size (client.Width, (pb.Image.Height * client.Width) / pb.Image.Width);
+ else
+ image_size = new Size ((pb.Image.Width * client.Height) / pb.Image.Height, client.Height);
+
+ dc.DrawImage (pb.Image, (client.Width / 2) - (image_size.Width / 2), (client.Height / 2) - (image_size.Height / 2), image_size.Width, image_size.Height);
+ break;
+#endif
default:
dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
// Normal, AutoSize
#region ProgressBar
public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
{
- Rectangle block_rect;
- Rectangle client_area = ctrl.client_area;
- int space_betweenblocks = 2;
- int block_width;
- int increment;
- int barpos_pixels;
+ Rectangle client_area = ctrl.client_area;
- block_width = (client_area.Height * 2 ) / 3;
- barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
- increment = block_width + space_betweenblocks;
-
/* Draw border */
CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
/* Draw Blocks */
- block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
- while ((block_rect.X - client_area.X) < barpos_pixels) {
+ int draw_mode = 0;
+ int max_blocks = int.MaxValue;
+ int start_pixel = client_area.X;
+#if NET_2_0
+ draw_mode = (int) ctrl.Style;
+#endif
+ switch (draw_mode) {
+#if NET_2_0
+ case 1: { // Continuous
+ int pixels_to_draw;
+ pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max(ctrl.Maximum - ctrl.Minimum, 1))));
+ dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
+ break;
+ }
+ case 2: // Marquee
+ if (XplatUI.ThemesEnabled) {
+ int ms_diff = (int) (DateTime.Now - ctrl.start).TotalMilliseconds;
+ double percent_done = (double) ms_diff % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
+ max_blocks = 5;
+ start_pixel = client_area.X + (int) (client_area.Width * percent_done);
+ }
- if (clip_rect.IntersectsWith (block_rect) == true) {
- dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
- }
+ goto case 0;
+#endif
+ case 0:
+ default: // Blocks
+ Rectangle block_rect;
+ int space_betweenblocks = 2;
+ int block_width;
+ int increment;
+ int barpos_pixels;
+ int block_count = 0;
- block_rect.X += increment;
+ block_width = (client_area.Height * 2) / 3;
+ barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max(ctrl.Maximum - ctrl.Minimum, 1));
+ increment = block_width + space_betweenblocks;
+
+ block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
+ while (true) {
+ if (max_blocks != int.MaxValue) {
+ if (block_count >= max_blocks)
+ break;
+ if (block_rect.X > client_area.Width)
+ block_rect.X -= client_area.Width;
+ } else {
+ if ((block_rect.X - client_area.X) >= barpos_pixels)
+ break;
+ }
+
+ if (clip_rect.IntersectsWith (block_rect) == true) {
+ dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
+ }
+
+ block_rect.X += increment;
+ block_count++;
+ }
+ break;
+
}
}
DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor );
}
+
// renders a radio button with the Flat and Popup FlatStyle
protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
{
#endregion // ScrollBar
#region StatusBar
- public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
+ public override void DrawStatusBar (Graphics real_dc, Rectangle clip, StatusBar sb) {
Rectangle area = sb.ClientRectangle;
int horz_border = 2;
int vert_border = 2;
+
+ Image backbuffer = new Bitmap (sb.ClientSize.Width, sb.ClientSize.Height, real_dc);
+ Graphics dc = Graphics.FromImage (backbuffer);
bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
dc.FillRectangle (brush, clip);
- if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
+ if (!sb.ShowPanels && sb.Text != String.Empty) {
string text = sb.Text;
StringFormat string_format = new StringFormat ();
string_format.Trimming = StringTrimming.Character;
string_format.FormatFlags = StringFormatFlags.NoWrap;
+
+ if (text.Length > 127)
+ text = text.Substring (0, 127);
if (text [0] == '\t') {
string_format.Alignment = StringAlignment.Center;
area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
CPDrawSizeGrip (dc, ColorControl, area);
}
+
+ real_dc.DrawImage (backbuffer, 0, 0);
+ dc.Dispose ();
+ backbuffer.Dispose ();
}
break;
}
+ RectangleF clip_bounds = dc.ClipBounds;
+ dc.SetClip (area);
dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
+ dc.SetClip (clip_bounds);
if (panel.Icon != null) {
dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
}
#endregion // StatusBar
- public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
- {
- Brush brush = SystemBrushes.Control;
- dc.FillRectangle (brush, area);
- Rectangle panel_rect = GetTabPanelRectExt (tab);
-
- if (tab.Appearance == TabAppearance.Normal) {
- CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
- CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
- }
-
- if (tab.Alignment == TabAlignment.Top) {
- for (int r = tab.TabPages.Count; r > 0; r--) {
- for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
- if (i == tab.SelectedIndex)
- continue;
- if (r != tab.TabPages [i].Row)
- continue;
- Rectangle rect = tab.GetTabRect (i);
- if (!rect.IntersectsWith (area))
- continue;
- DrawTab (dc, tab.TabPages [i], tab, rect, false);
- }
- }
- } else {
- for (int r = 0; r < tab.TabPages.Count; r++) {
- for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
- if (i == tab.SelectedIndex)
- continue;
- if (r != tab.TabPages [i].Row)
- continue;
- Rectangle rect = tab.GetTabRect (i);
- if (!rect.IntersectsWith (area))
- continue;
- DrawTab (dc, tab.TabPages [i], tab, rect, false);
- }
- }
- }
-
- if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
- Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
- if (rect.IntersectsWith (area))
- DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
- }
-
- if (tab.ShowSlider) {
- Rectangle right = GetTabControlRightScrollRect (tab);
- Rectangle left = GetTabControlLeftScrollRect (tab);
- CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
- CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
- }
- }
-
- public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
- {
- switch (tab.Alignment) {
- case TabAlignment.Top:
- return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
- default:
- Rectangle panel_rect = GetTabPanelRectExt (tab);
- return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
- }
- }
+ #region TabControl
- public override Rectangle GetTabControlRightScrollRect (TabControl tab)
- {
- switch (tab.Alignment) {
- case TabAlignment.Top:
- return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
- default:
- Rectangle panel_rect = GetTabPanelRectExt (tab);
- return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
- }
- }
+ #region TabControl settings
public override Size TabControlDefaultItemSize {
- get { return new Size (42, 21); }
+ get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultItemSize; }
}
public override Point TabControlDefaultPadding {
- get { return new Point (6, 3); }
+ get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultPadding; }
}
public override int TabControlMinimumTabWidth {
- get { return 42; }
+ get { return ThemeElements.CurrentTheme.TabControlPainter.MinimumTabWidth; }
}
- public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
- {
- Rectangle ext = GetTabPanelRectExt (tab);
- // Account for border size
- return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
+ public override Rectangle TabControlSelectedDelta {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedTabDelta; }
}
- public override Size TabControlGetSpacing (TabControl tab) {
- switch (tab.Appearance) {
- case TabAppearance.Normal:
- return new Size (1, -2);
- case TabAppearance.Buttons:
- return new Size (3, 3);
- case TabAppearance.FlatButtons:
- return new Size (9, 3);
- default:
- throw new Exception ("Invalid Appearance value: " + tab.Appearance);
- }
+ public override int TabControlSelectedSpacing {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedSpacing; }
}
-
- protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
- {
- // Offset the tab from the top corner
- Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
- tab.ClientRectangle.Y,
- tab.ClientRectangle.Width - 2,
- tab.ClientRectangle.Height - 1);
-
- if (tab.TabCount == 0)
- return res;
-
- int spacing = TabControlGetSpacing (tab).Height;
- int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
-
- switch (tab.Alignment) {
- case TabAlignment.Left:
- res.X += offset;
- res.Width -= offset;
- break;
- case TabAlignment.Right:
- res.Width -= offset;
- break;
- case TabAlignment.Top:
- res.Y += offset;
- res.Height -= offset;
- break;
- case TabAlignment.Bottom:
- res.Height -= offset;
- break;
- }
-
- return res;
+
+ public override int TabPanelOffsetX {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.X; }
+ }
+
+ public override int TabPanelOffsetY {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.Y; }
}
- protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
- {
- int FlatButtonSpacing = 8;
- Rectangle interior;
- int res = bounds.Width;
-
-
-
- // we can't fill the background right away because the bounds might be adjusted if the tab is selected
-
- StringFormat string_format = new StringFormat ();
- if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
- dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
-
- // Separators
- if (tab.Appearance == TabAppearance.FlatButtons) {
- int width = bounds.Width;
- bounds.Width += (FlatButtonSpacing - 2);
- res = bounds.Width;
- CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
- bounds.Width = width;
- }
-
- if (is_selected) {
- CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
- } else if (tab.Appearance != TabAppearance.FlatButtons) {
- CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
- }
-
- interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
-
-
- string_format.Alignment = StringAlignment.Center;
- string_format.LineAlignment = StringAlignment.Center;
- string_format.FormatFlags = StringFormatFlags.NoWrap;
- } else {
- CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
-
- Pen light = ResPool.GetPen (cpcolor.LightLight);
-
- switch (tab.Alignment) {
-
- case TabAlignment.Top:
-
- dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
-
- dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
- dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
- dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
-
- dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
-
- interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
-
- string_format.Alignment = StringAlignment.Center;
- string_format.LineAlignment = StringAlignment.Center;
- string_format.FormatFlags = StringFormatFlags.NoWrap;
-
- break;
-
- case TabAlignment.Bottom:
-
- dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
-
- dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
- dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
-
- dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
- dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
-
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
-
- interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
-
- string_format.Alignment = StringAlignment.Center;
- string_format.LineAlignment = StringAlignment.Center;
- string_format.FormatFlags = StringFormatFlags.NoWrap;
-
- break;
-
- case TabAlignment.Left:
-
- dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
-
- dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
- dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
- dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
-
- dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
-
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
-
- interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
-
- string_format.Alignment = StringAlignment.Center;
- string_format.LineAlignment = StringAlignment.Center;
- string_format.FormatFlags = StringFormatFlags.NoWrap;
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
-
- break;
-
- default:
- // TabAlignment.Right
-
- dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
-
- dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
- dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
-
- dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
- dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
+ public override int TabControlColSpacing {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.ColSpacing; }
+ }
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
- dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
+ public override Point TabControlImagePadding {
+ get { return ThemeElements.CurrentTheme.TabControlPainter.ImagePadding; }
+ }
- interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
+ public override int TabControlScrollerWidth {
+ get {return ThemeElements.CurrentTheme.TabControlPainter.ScrollerWidth; }
+ }
- string_format.Alignment = StringAlignment.Center;
- string_format.LineAlignment = StringAlignment.Center;
- string_format.FormatFlags = StringFormatFlags.NoWrap;
- string_format.FormatFlags = StringFormatFlags.DirectionVertical;
- break;
- }
+ public override Size TabControlGetSpacing (TabControl tab)
+ {
+ try {
+ return ThemeElements.CurrentTheme.TabControlPainter.RowSpacing (tab);
+ } catch {
+ throw new Exception ("Invalid Appearance value: " + tab.Appearance);
}
+ }
+ #endregion
- if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
- if (tab.Alignment == TabAlignment.Left) {
- int wo = interior.Width / 2;
- int ho = interior.Height / 2;
- dc.TranslateTransform (interior.X + wo, interior.Y + ho);
- dc.RotateTransform (180);
- dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
- dc.ResetTransform ();
- } else {
- Rectangle str_rect = interior;
+ public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
+ {
+ ThemeElements.CurrentTheme.TabControlPainter.Draw (dc, area, tab);
+ }
- if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) {
- tab.ImageList.Draw (dc, new Point (interior.X, interior.Y), page.ImageIndex);
- str_rect.X += tab.ImageList.ImageSize.Width + 2;
- str_rect.Width -= tab.ImageList.ImageSize.Width + 2;
- }
- dc.DrawString (page.Text, page.Font,
- SystemBrushes.ControlText,
- str_rect, string_format);
- }
- } else if (page.Text != null) {
- DrawItemState state = DrawItemState.None;
- if (page == tab.SelectedTab)
- state |= DrawItemState.Selected;
- DrawItemEventArgs e = new DrawItemEventArgs (dc,
- tab.Font, bounds, tab.IndexForTabPage (page),
- state, page.ForeColor, page.BackColor);
- tab.OnDrawItemInternal (e);
- return res;
- }
+ public override Rectangle TabControlGetLeftScrollRect (TabControl tab)
+ {
+ return ThemeElements.CurrentTheme.TabControlPainter.GetLeftScrollRect (tab);
+ }
- if (page.Parent.Focused && is_selected) {
- CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
- }
+ public override Rectangle TabControlGetRightScrollRect (TabControl tab)
+ {
+ return ThemeElements.CurrentTheme.TabControlPainter.GetRightScrollRect (tab);
+ }
+
+ public override Rectangle TabControlGetDisplayRectangle (TabControl tab)
+ {
+ return ThemeElements.CurrentTheme.TabControlPainter.GetDisplayRectangle (tab);
+ }
- return res;
+ public override Rectangle TabControlGetPanelRect (TabControl tab)
+ {
+ return ThemeElements.CurrentTheme.TabControlPainter.GetTabPanelRect (tab);
}
+ #endregion
+
#region ToolBar
public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
{
StringFormat format = new StringFormat ();
format.Trimming = StringTrimming.EllipsisCharacter;
format.LineAlignment = StringAlignment.Center;
+ if (control.ShowKeyboardCuesInternal)
+ format.HotkeyPrefix = HotkeyPrefix.Show;
+ else
+ format.HotkeyPrefix = HotkeyPrefix.Hide;
+
if (control.TextAlign == ToolBarTextAlign.Underneath)
format.Alignment = StringAlignment.Center;
else
format.Alignment = StringAlignment.Near;
-
+#if !NET_2_0
if (control is PropertyGrid.PropertyToolBar) {
dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
}
} else {
-
+#endif
if (control.Appearance == ToolBarAppearance.Flat && control.Parent != null) {
if (control.Parent.BackgroundImage != null) {
using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile))
}
dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
}
+#if !NET_2_0
}
+#endif
- foreach (ToolBarButton button in control.Buttons)
- if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
- DrawToolBarButton (dc, control, button, format);
+ foreach (ToolBarItem item in control.items)
+ if (item.Button.Visible && clip_rectangle.IntersectsWith (item.Rectangle))
+ DrawToolBarButton (dc, control, item, format);
format.Dispose ();
}
- protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
+ protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
{
- bool is_flat = control.Appearance == ToolBarAppearance.Flat;
-
- DrawToolBarButtonBorder (dc, button, is_flat);
+ bool is_flat = (control.Appearance == ToolBarAppearance.Flat);
+
+ DrawToolBarButtonBorder (dc, item, is_flat);
- switch (button.Style) {
+ switch (item.Button.Style) {
case ToolBarButtonStyle.DropDownButton:
if (control.DropDownArrows)
- DrawToolBarDropDownArrow (dc, button, is_flat);
- DrawToolBarButtonContents (dc, control, button, format);
+ DrawToolBarDropDownArrow (dc, item, is_flat);
+ DrawToolBarButtonContents (dc, control, item, format);
break;
case ToolBarButtonStyle.Separator:
if (is_flat)
- DrawToolBarSeparator (dc, button);
+ DrawToolBarSeparator (dc, item);
break;
case ToolBarButtonStyle.ToggleButton:
- DrawToolBarToggleButtonBackground (dc, button);
- DrawToolBarButtonContents (dc, control, button, format);
+ DrawToolBarToggleButtonBackground (dc, item);
+ DrawToolBarButtonContents (dc, control, item, format);
break;
default:
- DrawToolBarButtonContents (dc, control, button, format);
+ DrawToolBarButtonContents (dc, control, item, format);
break;
}
}
const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
- protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
+ protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
{
- if (button.Style == ToolBarButtonStyle.Separator)
+ if (item.Button.Style == ToolBarButtonStyle.Separator)
return;
Border3DStyle style;
if (is_flat) {
- if (button.Pushed || button.Pressed)
+ if (item.Button.Pushed || item.Pressed)
style = Border3DStyle.SunkenOuter;
- else if (button.Hilight)
+ else if (item.Hilight)
style = Border3DStyle.RaisedInner;
else
return;
} else {
- if (button.Pushed || button.Pressed)
+ if (item.Button.Pushed || item.Pressed)
style = Border3DStyle.Sunken;
else
style = Border3DStyle.Raised;
}
- Rectangle rect = button.Rectangle;
- if ((button.Style == ToolBarButtonStyle.DropDownButton) && (button.Parent.DropDownArrows) && is_flat)
+ Rectangle rect = item.Rectangle;
+ if ((item.Button.Style == ToolBarButtonStyle.DropDownButton) && (item.Button.Parent.DropDownArrows) && is_flat)
rect.Width -= ToolBarDropDownWidth;
CPDrawBorder3D (dc, rect, style, all_sides);
}
- protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
+ protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
{
- Rectangle area = button.Rectangle;
+ Rectangle area = item.Rectangle;
int offset = (int) SystemPens.Control.Width + 1;
dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
}
- protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
+ protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
{
Brush brush;
- Rectangle area = button.Rectangle;
+ Rectangle area = item.Rectangle;
area.X += ToolBarImageGripWidth;
area.Y += ToolBarImageGripWidth;
area.Width -= 2 * ToolBarImageGripWidth;
area.Height -= 2 * ToolBarImageGripWidth;
- if (button.Pushed)
+ if (item.Button.Pushed)
brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight);
- else if (button.PartialPush)
+ else if (item.Button.PartialPush)
brush = SystemBrushes.ControlLight;
else
brush = SystemBrushes.Control;
dc.FillRectangle (brush, area);
}
- protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
+ protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
{
- Rectangle rect = button.Rectangle;
- rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
+ Rectangle rect = item.Rectangle;
+ rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
rect.Width = ToolBarDropDownWidth;
if (is_flat) {
- if (button.dd_pressed)
+ if (item.DDPressed)
CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
- else if (button.Pushed || button.Pressed)
+ else if (item.Button.Pushed || item.Pressed)
CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
- else if (button.Hilight)
+ else if (item.Hilight)
CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides);
} else {
- if (button.dd_pressed)
+ if (item.DDPressed)
CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides);
- else if (button.Pushed || button.Pressed)
+ else if (item.Button.Pushed || item.Pressed)
CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides);
else
CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2));
// Increase vertical and horizontal position by 1 when button is pressed
- if (button.Pressed || button.Pushed || button.dd_pressed) {
+ if (item.Pressed || item.Button.Pushed || item.DDPressed) {
ddCenter.X += 1;
ddCenter.Y += 1;
}
dc.FillPolygon (SystemBrushes.ControlText, vertices);
}
- protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
+ protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
{
- if (button.Image != null) {
- int x = button.ImageRectangle.X + ToolBarImageGripWidth;
- int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
+ if (item.Button.Image != null) {
+ int x = item.ImageRectangle.X + ToolBarImageGripWidth;
+ int y = item.ImageRectangle.Y + ToolBarImageGripWidth;
// Increase vertical and horizontal position by 1 when button is pressed
- if (button.Pressed || button.Pushed) {
+ if (item.Pressed || item.Button.Pushed) {
x += 1;
y += 1;
}
- if (button.Enabled)
- dc.DrawImage (button.Image, x, y);
+ if (item.Button.Enabled)
+ dc.DrawImage (item.Button.Image, x, y);
else
- CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
+ CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl);
}
- Rectangle text_rect = button.TextRectangle;
+ Rectangle text_rect = item.TextRectangle;
if (text_rect.Width <= 0 || text_rect.Height <= 0)
return;
- if (button.Pressed || button.Pushed) {
+ if (item.Pressed || item.Button.Pushed) {
text_rect.X += 1;
text_rect.Y += 1;
}
- if (button.Enabled)
- dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
+ if (item.Button.Enabled)
+ dc.DrawString (item.Button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
else
- CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, text_rect, format);
+ CPDrawStringDisabled (dc, item.Button.Text, control.Font, control.BackColor, text_rect, format);
}
// Grip width for the ToolBar
}
}
- public override bool ToolBarInvalidateEntireButton {
- get { return false; }
- }
-
#endregion // ToolBar
#region ToolTip
- public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
- dc.FillRectangle(SystemBrushes.Info, control.ClientRectangle);
- dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
- dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.ClientRectangle, control.string_format);
+ public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
+ {
+ Rectangle text_rect = Rectangle.Inflate (control.ClientRectangle, -2, -1);
+
+#if NET_2_0
+ Brush back_brush = ResPool.GetSolidBrush (control.BackColor);;
+ Color foreground = control.ForeColor;
+#else
+ Brush back_brush = SystemBrushes.Info;
+ Color foreground = this.ColorInfoText;
+#endif
+
+ dc.FillRectangle (back_brush, control.ClientRectangle);
+ dc.DrawRectangle (SystemPens.WindowFrame, 0, 0, control.Width - 1, control.Height - 1);
+
+ TextFormatFlags flags = TextFormatFlags.HidePrefix | TextFormatFlags.SingleLine | TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
+ TextRenderer.DrawTextInternal (dc, control.Text, control.Font, text_rect, foreground, flags, false);
}
- public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
- SizeF sizef;
+ public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text)
+ {
+ Size size = TextRenderer.MeasureTextInternal (text, tt.Font, false);
- sizef = tt.DeviceContext.MeasureString(text, tt.Font);
- return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
+ size.Width += 8;
+ size.Height += 3;
+
+ return size;
}
#endregion // ToolTip
+ #region BalloonWindow
+#if NET_2_0
+ NotifyIcon.BalloonWindow balloon_window;
+
+ public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
+ {
+ Control control = Control.FromHandle(handle);
+
+ if (control == null)
+ return;
+
+ if (balloon_window != null) {
+ balloon_window.Close ();
+ balloon_window.Dispose ();
+ }
+
+ balloon_window = new NotifyIcon.BalloonWindow (handle);
+ balloon_window.Title = title;
+ balloon_window.Text = text;
+ balloon_window.Icon = icon;
+ balloon_window.Timeout = timeout;
+ balloon_window.Show ();
+ }
+
+ private const int balloon_iconsize = 16;
+ private const int balloon_bordersize = 8;
+
+ public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control)
+ {
+ Brush solidbrush = ResPool.GetSolidBrush (this.ColorInfoText);
+ Rectangle rect = control.ClientRectangle;
+ int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
+
+ // Rectangle borders and background.
+ dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
+ dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), 0, 0, rect.Width - 1, rect.Height - 1);
+
+ // Icon
+ Image image;
+ switch (control.Icon) {
+ case ToolTipIcon.Info: {
+ image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
+ break;
+ }
+
+ case ToolTipIcon.Warning: {
+ image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
+ break;
+ }
+
+ case ToolTipIcon.Error: {
+ image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
+ break;
+ }
+
+ default: {
+ image = null;
+ break;
+ }
+ }
+
+ if (control.Icon != ToolTipIcon.None)
+ dc.DrawImage (image, new Rectangle (balloon_bordersize, balloon_bordersize, iconsize, iconsize));
+
+ // Title
+ Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + iconsize + (iconsize > 0 ? balloon_bordersize : 0),
+ rect.Y + balloon_bordersize,
+ rect.Width - ((3 * balloon_bordersize) + iconsize),
+ rect.Height - (2 * balloon_bordersize));
+
+ Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
+ dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
+
+ // Text
+ Rectangle textrect = new Rectangle (rect.X + balloon_bordersize,
+ rect.Y + balloon_bordersize,
+ rect.Width - (2 * balloon_bordersize),
+ rect.Height - (2 * balloon_bordersize));
+
+ StringFormat textformat = control.Format;
+ textformat.LineAlignment = StringAlignment.Far;
+ dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
+ }
+
+ public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
+ {
+ Rectangle deskrect = Screen.GetWorkingArea (control);
+ SizeF maxsize = new SizeF (250, 200);
+
+ SizeF titlesize = TextRenderer.MeasureString (control.Title, control.Font, maxsize, control.Format);
+ SizeF textsize = TextRenderer.MeasureString (control.Text, control.Font, maxsize, control.Format);
+
+ if (titlesize.Height < balloon_iconsize)
+ titlesize.Height = balloon_iconsize;
+
+ Rectangle rect = new Rectangle ();
+ rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
+ rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (2 * balloon_bordersize);
+ rect.X = deskrect.Width - rect.Width - 2;
+ rect.Y = deskrect.Height - rect.Height - 2;
+
+ return rect;
+ }
+#endif
+ #endregion // BalloonWindow
+
#region TrackBar
+ public override int TrackBarValueFromMousePosition (int x, int y, TrackBar tb)
+ {
+ int result = tb.Value;
+ int value_pos = tb.Value;
+ float pixels_betweenticks;
+ Rectangle thumb_pos = Rectangle.Empty, thumb_area = Rectangle.Empty;
+ Point channel_startpoint = Point.Empty, na_point = Point.Empty;
+
+ GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out na_point, out na_point);
+
+ /* Convert thumb position from mouse position to value*/
+ if (tb.Orientation == Orientation.Vertical) {
+ value_pos = (int)((thumb_area.Bottom - y -(float)pixels_betweenticks / 2) / (float)pixels_betweenticks);
+
+ if (value_pos + tb.Minimum > tb.Maximum)
+ value_pos = tb.Maximum - tb.Minimum;
+ else if (value_pos + tb.Minimum < tb.Minimum)
+ value_pos = 0;
+
+ result = value_pos + tb.Minimum;
+ } else {
+ value_pos = (int) ((x - channel_startpoint.X - (float) pixels_betweenticks / 2) / (float) pixels_betweenticks);
+
+ if (value_pos + tb.Minimum > tb.Maximum)
+ value_pos = tb.Maximum - tb.Minimum;
+ else if (value_pos + tb.Minimum < tb.Minimum)
+ value_pos = 0;
+
+ result = value_pos + tb.Minimum;
+ }
+
+ return result;
+ }
+
+ private void GetTrackBarDrawingInfo (TrackBar tb, out float pixels_betweenticks, out Rectangle thumb_area, out Rectangle thumb_pos, out Point channel_startpoint, out Point bottomtick_startpoint, out Point toptick_startpoint)
+ {
+ thumb_area = Rectangle.Empty;
+ thumb_pos = Rectangle.Empty;
+
+ if (tb.Orientation == Orientation.Vertical) {
+ toptick_startpoint = new Point ();
+ bottomtick_startpoint = new Point ();
+ channel_startpoint = new Point ();
+ float pixel_len;
+ const int space_from_right = 8;
+ const int space_from_left = 8;
+ const int space_from_bottom = 11;
+ Rectangle area = tb.ClientRectangle;
+
+ switch (tb.TickStyle) {
+ case TickStyle.BottomRight:
+ case TickStyle.None:
+ channel_startpoint.Y = 8;
+ channel_startpoint.X = 9;
+ bottomtick_startpoint.Y = 13;
+ bottomtick_startpoint.X = 24;
+ break;
+ case TickStyle.TopLeft:
+ channel_startpoint.Y = 8;
+ channel_startpoint.X = 19;
+ toptick_startpoint.Y = 13;
+ toptick_startpoint.X = 8;
+ break;
+ case TickStyle.Both:
+ channel_startpoint.Y = 8;
+ channel_startpoint.X = 18;
+ bottomtick_startpoint.Y = 13;
+ bottomtick_startpoint.X = 32;
+ toptick_startpoint.Y = 13;
+ toptick_startpoint.X = 8;
+ break;
+ default:
+ break;
+ }
+
+ thumb_area.X = area.X + channel_startpoint.X;
+ thumb_area.Y = area.Y + channel_startpoint.Y;
+ thumb_area.Height = area.Height - space_from_right - space_from_left;
+ thumb_area.Width = 4;
+
+ pixel_len = thumb_area.Height - 11;
+ if (tb.Maximum == tb.Minimum) {
+ pixels_betweenticks = 0;
+ } else {
+ pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
+ }
+
+ thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int)(pixels_betweenticks * (float)(tb.Value - tb.Minimum));
+
+ /* Draw thumb fixed 10x22 size */
+ thumb_pos.Width = 10;
+ thumb_pos.Height = 22;
+ } else {
+ toptick_startpoint = new Point ();
+ bottomtick_startpoint = new Point ();
+ channel_startpoint = new Point ();
+ float pixel_len;
+ const int space_from_right = 8;
+ const int space_from_left = 8;
+ Rectangle area = tb.ClientRectangle;
+
+ switch (tb.TickStyle) {
+ case TickStyle.BottomRight:
+ case TickStyle.None:
+ channel_startpoint.X = 8;
+ channel_startpoint.Y = 9;
+ bottomtick_startpoint.X = 13;
+ bottomtick_startpoint.Y = 24;
+ break;
+ case TickStyle.TopLeft:
+ channel_startpoint.X = 8;
+ channel_startpoint.Y = 19;
+ toptick_startpoint.X = 13;
+ toptick_startpoint.Y = 8;
+ break;
+ case TickStyle.Both:
+ channel_startpoint.X = 8;
+ channel_startpoint.Y = 18;
+ bottomtick_startpoint.X = 13;
+ bottomtick_startpoint.Y = 32;
+ toptick_startpoint.X = 13;
+ toptick_startpoint.Y = 8;
+ break;
+ default:
+ break;
+ }
+
+ thumb_area.X = area.X + channel_startpoint.X;
+ thumb_area.Y = area.Y + channel_startpoint.Y;
+ thumb_area.Width = area.Width - space_from_right - space_from_left;
+ thumb_area.Height = 4;
+
+ pixel_len = thumb_area.Width - 11;
+ if (tb.Maximum == tb.Minimum) {
+ pixels_betweenticks = 0;
+ } else {
+ pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
+ }
+
+ thumb_pos.X = channel_startpoint.X + (int)(pixels_betweenticks * (float) (tb.Value - tb.Minimum));
+
+ /* Draw thumb fixed 10x22 size */
+ thumb_pos.Width = 10;
+ thumb_pos.Height = 22;
+ }
+ }
+
private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
float ticks, int value_pos, bool mouse_value) {
Point channel_startpoint = new Point ();
float pixel_len;
float pixels_betweenticks;
- const int space_from_right = 8;
- const int space_from_left = 8;
- const int space_from_bottom = 11;
Rectangle area = tb.ClientRectangle;
- switch (tb.TickStyle) {
- case TickStyle.BottomRight:
- case TickStyle.None:
- channel_startpoint.Y = 8;
- channel_startpoint.X = 9;
- bottomtick_startpoint.Y = 13;
- bottomtick_startpoint.X = 24;
- break;
- case TickStyle.TopLeft:
- channel_startpoint.Y = 8;
- channel_startpoint.X = 19;
- toptick_startpoint.Y = 13;
- toptick_startpoint.X = 8;
- break;
- case TickStyle.Both:
- channel_startpoint.Y = 8;
- channel_startpoint.X = 18;
- bottomtick_startpoint.Y = 13;
- bottomtick_startpoint.X = 32;
- toptick_startpoint.Y = 13;
- toptick_startpoint.X = 8;
- break;
- default:
- break;
- }
-
- thumb_area.X = area.X + channel_startpoint.X;
- thumb_area.Y = area.Y + channel_startpoint.Y;
- thumb_area.Height = area.Height - space_from_right - space_from_left;
- thumb_area.Width = 4;
+ GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
/* Draw channel */
dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
1, thumb_area.Height);
- pixel_len = thumb_area.Height - 11;
- pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
-
- /* Convert thumb position from mouse position to value*/
- if (mouse_value) {
- if (tb.mouse_moved) {
- value_pos += (int) pixels_betweenticks / 2;
- if (value_pos < thumb_area.Bottom) {
- value_pos = (int) ((thumb_area.Bottom - value_pos - (int)(thumb_pos.Width / 2)) / pixels_betweenticks);
- } else {
- value_pos = 0;
- }
-
- if (value_pos + tb.Minimum > tb.Maximum)
- value_pos = tb.Maximum - tb.Minimum;
- else if (value_pos + tb.Minimum < tb.Minimum)
- value_pos = 0;
-
- tb.Value = value_pos + tb.Minimum;
- } else {
- value_pos = tb.Value - tb.Minimum;
- }
- }
-
- // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
- thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
-
- /* Draw thumb fixed 10x22 size */
- thumb_pos.Width = 10;
- thumb_pos.Height = 22;
-
switch (tb.TickStyle) {
case TickStyle.BottomRight:
case TickStyle.None: {
thumb_pos.X = channel_startpoint.X - 8;
- Pen pen = SystemPens.ControlLight;
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
case TickStyle.TopLeft: {
thumb_pos.X = channel_startpoint.X - 10;
- Pen pen = SystemPens.ControlLight;
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
case TickStyle.Both: {
thumb_pos.X = area.X + 10;
-
- Pen pen = SystemPens.ControlLight;
+
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
Point channel_startpoint = new Point ();
float pixel_len;
float pixels_betweenticks;
- const int space_from_right = 8;
- const int space_from_left = 8;
Rectangle area = tb.ClientRectangle;
-
- switch (tb.TickStyle) {
- case TickStyle.BottomRight:
- case TickStyle.None:
- channel_startpoint.X = 8;
- channel_startpoint.Y = 9;
- bottomtick_startpoint.X = 13;
- bottomtick_startpoint.Y = 24;
- break;
- case TickStyle.TopLeft:
- channel_startpoint.X = 8;
- channel_startpoint.Y = 19;
- toptick_startpoint.X = 13;
- toptick_startpoint.Y = 8;
- break;
- case TickStyle.Both:
- channel_startpoint.X = 8;
- channel_startpoint.Y = 18;
- bottomtick_startpoint.X = 13;
- bottomtick_startpoint.Y = 32;
- toptick_startpoint.X = 13;
- toptick_startpoint.Y = 8;
- break;
- default:
- break;
- }
-
- thumb_area.X = area.X + channel_startpoint.X;
- thumb_area.Y = area.Y + channel_startpoint.Y;
- thumb_area.Width = area.Width - space_from_right - space_from_left;
- thumb_area.Height = 4;
+
+ GetTrackBarDrawingInfo (tb , out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
/* Draw channel */
dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
thumb_area.Width, 1);
- pixel_len = thumb_area.Width - 11;
- pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
-
- /* Convert thumb position from mouse position to value*/
- if (mouse_value) {
- if (tb.mouse_moved) {
- value_pos += (int) pixels_betweenticks / 2;
- if (value_pos >= channel_startpoint.X) {
- value_pos = (int)(((float) (value_pos - channel_startpoint.X - (int)(thumb_pos.Width / 2))) / pixels_betweenticks);
- } else
- value_pos = 0;
-
- if (value_pos + tb.Minimum > tb.Maximum)
- value_pos = tb.Maximum - tb.Minimum;
- else if(value_pos + tb.Minimum < tb.Minimum)
- value_pos = 0;
-
- tb.Value = value_pos + tb.Minimum;
- } else {
- value_pos = tb.Value - tb.Minimum;
- }
- }
-
- thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
-
- /* Draw thumb fixed 10x22 size */
- thumb_pos.Width = 10;
- thumb_pos.Height = 22;
-
switch (tb.TickStyle) {
case TickStyle.BottomRight:
case TickStyle.None: {
thumb_pos.Y = channel_startpoint.Y - 8;
- Pen pen = SystemPens.ControlLight;
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
case TickStyle.TopLeft: {
thumb_pos.Y = channel_startpoint.Y - 10;
- Pen pen = SystemPens.ControlLight;
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
case TickStyle.Both: {
thumb_pos.Y = area.Y + 10;
- Pen pen = SystemPens.ControlLight;
+ Pen pen = SystemPens.ControlLightLight;
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
public override int ManagedWindowBorderWidth (InternalWindowManager wm)
{
- return 3;
+ if (wm is ToolWindowManager && wm.form.FormBorderStyle == FormBorderStyle.FixedToolWindow)
+ return 3;
+ else
+ return 4;
}
public override int ManagedWindowIconWidth (InternalWindowManager wm)
public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
{
+ TitleButtons buttons = wm.TitleButtons;
+ Form form = wm.form;
+
+ buttons.HelpButton.Visible = form.HelpButton;
+
+ foreach (TitleButton button in buttons) {
+ button.Visible = false;
+ }
+
+ switch (form.FormBorderStyle) {
+ case FormBorderStyle.None:
+ if (form.WindowState != FormWindowState.Normal)
+ goto case FormBorderStyle.Sizable;
+ break;
+ case FormBorderStyle.FixedToolWindow:
+ case FormBorderStyle.SizableToolWindow:
+ buttons.CloseButton.Visible = true;
+ if (form.WindowState != FormWindowState.Normal)
+ goto case FormBorderStyle.Sizable;
+ break;
+ case FormBorderStyle.FixedSingle:
+ case FormBorderStyle.Fixed3D:
+ case FormBorderStyle.FixedDialog:
+ case FormBorderStyle.Sizable:
+ switch (form.WindowState) {
+ case FormWindowState.Normal:
+ buttons.MinimizeButton.Visible = true;
+ buttons.MaximizeButton.Visible = true;
+ buttons.RestoreButton.Visible = false;
+ break;
+ case FormWindowState.Maximized:
+ buttons.MinimizeButton.Visible = true;
+ buttons.MaximizeButton.Visible = false;
+ buttons.RestoreButton.Visible = true;
+ break;
+ case FormWindowState.Minimized:
+ buttons.MinimizeButton.Visible = false;
+ buttons.MaximizeButton.Visible = true;
+ buttons.RestoreButton.Visible = true;
+ break;
+ }
+ buttons.CloseButton.Visible = true;
+ break;
+ }
+
int bw = ManagedWindowBorderWidth (wm);
Size btsize = ManagedWindowButtonSize (wm);
int btw = btsize.Width;
int bth = btsize.Height;
-
+ int top = bw + 2;
+ int left = form.Width - bw - btw - 2;
+
if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
- if (!wm.IsMaximized) {
- wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2,
- bw + 2, btw, bth);
- wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw,
- bw + 2, btw, bth);
- wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw,
- bw + 2, btw, bth);
- } else {
- // Maximized
+ buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
+ left -= 2 + btw;
+
+ if (buttons.MaximizeButton.Visible) {
+ buttons.MaximizeButton.Rectangle = new Rectangle (left, top, btw, bth);
+ left -= 2 + btw;
+ }
+ if (buttons.RestoreButton.Visible) {
+ buttons.RestoreButton.Rectangle = new Rectangle (left, top, btw, bth);
+ left -= 2 + btw;
}
+
+ buttons.MinimizeButton.Rectangle = new Rectangle (left, top, btw, bth);
+ left -= 2 + btw;
} else if (wm.IsToolWindow) {
- wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth);
+ buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
+ left -= 2 + btw;
}
}
int bdwidth = ManagedWindowBorderWidth (wm);
Color titlebar_color = Color.FromArgb (255, 10, 36, 106);
Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240);
+ Color color = ThemeEngine.Current.ColorControlDark;
+ Color color2 = Color.FromArgb (255, 192, 192, 192);
+#if debug
+ Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations");
+ dc.FillRectangle (Brushes.Black, clip);
+#endif
+
if (wm.HasBorders) {
- Pen pen = new Pen(ColorControl, 1);
+ Pen pen = ResPool.GetPen (ColorControl);
Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
- // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves
- dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5);
- ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
-
- if (!wm.IsMaximized) {
- borders.Y += tbheight + bdwidth;
- borders.X += bdwidth;
- borders.Height -= tbheight + bdwidth * 2 + 1;
- borders.Width -= bdwidth * 2 + 1;
-
+ ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
+ // The 3d border is only 2 pixels wide, so we draw the innermost pixels ourselves
+ borders = new Rectangle (2, 2, form.Width - 5, form.Height - 5);
+ for (int i = 2; i < bdwidth; i++) {
dc.DrawRectangle (pen, borders);
- }
+ borders.Inflate (-1, -1);
+ }
}
- Color color = ThemeEngine.Current.ColorControlDark;
- Color color2 = Color.FromArgb (255, 192, 192, 192);
- if (wm.IsActive () && !wm.IsMaximized) {
+
+ bool draw_titlebar_enabled = false;
+ if (wm.Form.Parent != null && wm.Form.Parent is Form) {
+ draw_titlebar_enabled = false;
+ } else if (wm.IsActive && !wm.IsMaximized) {
+ draw_titlebar_enabled = true;
+ }
+ if (draw_titlebar_enabled) {
color = titlebar_color;
color2 = titlebar_color2;
}
- Rectangle tb = new Rectangle (bdwidth, bdwidth,
- form.Width - (bdwidth * 2), tbheight);
+ Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight - 1);
// HACK: For now always draw the titlebar until we get updates better
- // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle);
- //if (vis != Rectangle.Empty)
if (tb.Width > 0 && tb.Height > 0) {
using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal))
{
}
}
- dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth,
- tbheight + bdwidth, form.Width - (bdwidth * 2),
- tbheight + bdwidth);
+ // Draw the line just beneath the title bar
+ dc.DrawLine (ResPool.GetPen (SystemColors.Control), bdwidth,
+ tbheight + bdwidth - 1, form.Width - bdwidth - 1,
+ tbheight + bdwidth - 1);
if (!wm.IsToolWindow) {
tb.X += 18; // Room for the icon and the buttons
tb.Width = (form.Width - 62) - tb.X;
}
- if (form.Text != null) {
+ if (form.Text != null && form.Text != string.Empty) {
StringFormat format = new StringFormat ();
format.FormatFlags = StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.EllipsisCharacter;
}
if (wm.HasBorders) {
- if (!wm.IsToolWindow && form.Icon != null) {
+ bool draw_icon = false;
+#if NET_2_0
+ draw_icon = !wm.IsToolWindow && form.Icon != null && form.ShowIcon;
+#else
+ draw_icon = !wm.IsToolWindow && form.Icon != null;
+#endif
+ if (draw_icon) {
Rectangle icon = new Rectangle (bdwidth + 3,
bdwidth + 2, wm.IconWidth, wm.IconWidth);
if (icon.IntersectsWith (clip))
dc.DrawIcon (form.Icon, icon);
}
-
- if (!wm.IsMaximized) {
- if (!wm.IsToolWindow || wm.IsMinimized) {
- DrawTitleButton (dc, wm.minimize_button, clip);
- DrawTitleButton (dc, wm.maximize_button, clip);
- }
- DrawTitleButton (dc, wm.close_button, clip);
- } else {
- // DrawMaximizedButtons (pe, form.ActiveMenu);
+
+ foreach (TitleButton button in wm.TitleButtons.AllButtons) {
+ DrawTitleButton (dc, button, clip);
}
}
}
height - 5);
}
- private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip)
+ private void DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip)
{
+ if (!button.Visible) {
+ return;
+ }
+
if (!button.Rectangle.IntersectsWith (clip))
return;
DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
}
+ public override void CPDrawBorder (Graphics graphics, RectangleF bounds, Color leftColor, int leftWidth,
+ ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
+ Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
+ int bottomWidth, ButtonBorderStyle bottomStyle) {
+ DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
+ DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
+ DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
+ DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
+ }
+
public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
}
- protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
+ public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
{
Pen penTopLeft;
Pen penTopLeftInner;
break;
}
+ bool inner = ((style != Border3DStyle.RaisedOuter) && (style != Border3DStyle.SunkenOuter));
+
if ((sides & Border3DSide.Middle) != 0) {
Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
graphics.FillRectangle (brush, rect);
if ((sides & Border3DSide.Left) != 0) {
graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
- if (rect.Width > 2)
+ if ((rect.Width > 2) && inner)
graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
}
if ((sides & Border3DSide.Top) != 0) {
graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
- if (rect.Height > 2)
+ if ((rect.Height > 2) && inner)
graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
}
if ((sides & Border3DSide.Right) != 0) {
graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
- if (rect.Width > 3)
+ if ((rect.Width > 3) && inner)
graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
}
if ((sides & Border3DSide.Bottom) != 0) {
graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
- if (rect.Height > 3)
+ if ((rect.Height > 3) && inner)
graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
}
}
public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
{
- Pen check_pen = SystemPens.ControlDarkDark;
+ Pen check_pen = Pens.Black;
Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
cb_rect.Width -= 2;
cb_rect.Height -= 2;
- dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+ if ((state & ButtonState.Inactive) == ButtonState.Inactive)
+ dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+ else
+ dc.FillRectangle (Brushes.White, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
} else {
cb_rect.Width -= 1;
int lineWidth = Math.Max (3, check_size / 3);
int Scale = Math.Max (1, check_size / 9);
- Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1,
+ Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (int)Math.Ceiling ((float)check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1,
check_size, check_size);
for (int i = 0; i < lineWidth; i++) {
}
- public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
+ public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color, Color backColor) {
Rectangle rect;
int lineWidth;
+ if (backColor != Color.Empty)
+ graphics.FillRectangle (ResPool.GetSolidBrush (backColor), rectangle);
+
Brush brush = ResPool.GetSolidBrush (color);
switch(glyph) {
case MenuGlyph.Arrow: {
- Point[] arrow = new Point[3];
- Point P1;
- Point P2;
- Point P3;
- int centerX;
- int centerY;
- int shiftX;
-
- rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
- centerX=rect.Left+rect.Width/2;
- centerY=rect.Top+rect.Height/2;
- shiftX=Math.Max(1, rect.Width/8);
-
- rect.X-=shiftX;
- centerX-=shiftX;
-
- P1=new Point(centerX, rect.Top);
- P2=new Point(centerX, rect.Bottom);
- P3=new Point(rect.Right, centerY);
-
- arrow[0]=P1;
- arrow[1]=P2;
- arrow[2]=P3;
-
- graphics.FillPolygon(brush, arrow, FillMode.Winding);
+ float height = rectangle.Height * 0.7f;
+ float width = height / 2.0f;
+
+ PointF ddCenter = new PointF (rectangle.X + ((rectangle.Width-width) / 2.0f), rectangle.Y + (rectangle.Height / 2.0f));
+
+ PointF [] vertices = new PointF [3];
+ vertices [0].X = ddCenter.X;
+ vertices [0].Y = ddCenter.Y - (height / 2.0f);
+ vertices [1].X = ddCenter.X;
+ vertices [1].Y = ddCenter.Y + (height / 2.0f);
+ vertices [2].X = ddCenter.X + width + 0.1f;
+ vertices [2].Y = ddCenter.Y;
+
+ graphics.FillPolygon (brush, vertices);
return;
}
}
case MenuGlyph.Checkmark: {
- int Scale;
+
Pen pen = ResPool.GetPen (color);
+ lineWidth = Math.Max (2, rectangle.Width / 6);
+ rect = new Rectangle(rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height- lineWidth * 2);
- lineWidth=Math.Max(2, rectangle.Width/6);
- Scale=Math.Max(1, rectangle.Width/12);
-
- rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
+ int Scale = Math.Max (1, rectangle.Width / 12);
+ int top = (rect.Y + lineWidth + ((rect.Height - ((2 * Scale) + lineWidth)) / 2));
for (int i=0; i<lineWidth; i++) {
- graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
- graphics.DrawLine(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);
+ graphics.DrawLine (pen, rect.Left+lineWidth/2, top+i, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i);
+ graphics.DrawLine (pen, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i, rect.Left+lineWidth/2+6*Scale, top-2*Scale+i);
}
return;
}
}
}
+ private void DrawStringDisabled20 (Graphics g, string s, Font font, Rectangle layoutRectangle, Color color, TextFormatFlags flags, bool useDrawString)
+ {
+ CPColor cpcolor = ResPool.GetCPColor (color);
+
+ layoutRectangle.Offset (1, 1);
+ TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.LightLight, flags, useDrawString);
+
+ layoutRectangle.Offset (-1, -1);
+ TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.Dark, flags, useDrawString);
+ }
+
public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
{
CPColor cpcolor = ResPool.GetCPColor (color);
dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
}
- private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
+#if NET_2_0
+ public override void CPDrawStringDisabled (IDeviceContext dc, string s, Font font, Color color, Rectangle layoutRectangle, TextFormatFlags format)
+ {
+ CPColor cpcolor = ResPool.GetCPColor (color);
+
+ layoutRectangle.Offset (1, 1);
+ TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.LightLight, format);
+
+ layoutRectangle.Offset (-1, -1);
+ TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.Dark, format);
+ }
+
+ public override void CPDrawVisualStyleBorder (Graphics graphics, Rectangle bounds)
+ {
+ graphics.DrawRectangle (SystemPens.ControlDarkDark, bounds);
+ }
+#endif
+
+ private static void DrawBorderInternal (Graphics graphics, int startX, int startY, int endX, int endY,
+ int width, Color color, ButtonBorderStyle style, Border3DSide side)
+ {
+ DrawBorderInternal (graphics, (float) startX, (float) startY, (float) endX, (float) endY,
+ width, color, style, side);
+ }
+
+ private static void DrawBorderInternal (Graphics graphics, float startX, float startY, float endX, float endY,
int width, Color color, ButtonBorderStyle style, Border3DSide side) {
Pen pen = null;