1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Peter Bartok, pbartok@novell.com
25 // John BouAntoun, jba-mono@optusnet.com.au
26 // Marek Safar, marek.safar@seznam.cz
27 // Alexander Olk, alex.olk@googlemail.com
30 using System.ComponentModel;
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Printing;
36 using System.Drawing.Text;
38 using System.Windows.Forms.Theming;
40 namespace System.Windows.Forms
43 internal class ThemeWin32Classic : Theme
45 public override Version Version {
47 return new Version(0, 1, 0, 0);
51 /* Hardcoded colour values not exposed in the API constants in all configurations */
52 protected static readonly Color arrow_color = Color.Black;
53 protected static readonly Color pen_ticks_color = Color.Black;
54 protected static StringFormat string_format_menu_text;
55 protected static StringFormat string_format_menu_shortcut;
56 protected static StringFormat string_format_menu_menubar_text;
57 static ImageAttributes imagedisabled_attributes = null;
58 const int SEPARATOR_HEIGHT = 6;
59 const int SEPARATOR_MIN_WIDTH = 20;
60 const int SM_CXBORDER = 1;
61 const int SM_CYBORDER = 1;
62 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tabd
63 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
65 #region Principal Theme Methods
66 public ThemeWin32Classic ()
71 public override void ResetDefaults() {
72 defaultWindowBackColor = this.ColorWindow;
73 defaultWindowForeColor = this.ColorControlText;
74 window_border_font = new Font(FontFamily.GenericSansSerif, 8.25f, FontStyle.Bold);
76 /* Menu string formats */
77 string_format_menu_text = new StringFormat ();
78 string_format_menu_text.LineAlignment = StringAlignment.Center;
79 string_format_menu_text.Alignment = StringAlignment.Near;
80 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
81 string_format_menu_text.SetTabStops (0f, new float [] { 50f });
82 string_format_menu_text.FormatFlags |= StringFormatFlags.NoWrap;
84 string_format_menu_shortcut = new StringFormat ();
85 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
86 string_format_menu_shortcut.Alignment = StringAlignment.Far;
88 string_format_menu_menubar_text = new StringFormat ();
89 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
90 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
91 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
94 public override bool DoubleBufferingSupported {
98 public override int HorizontalScrollBarHeight {
100 return XplatUI.HorizontalScrollBarHeight;
104 public override int VerticalScrollBarWidth {
106 return XplatUI.VerticalScrollBarWidth;
110 #endregion // Principal Theme Methods
112 #region Internal Methods
113 protected Brush GetControlBackBrush (Color c) {
114 if (c.ToArgb () == DefaultControlBackColor.ToArgb ())
115 return SystemBrushes.Control;
116 return ResPool.GetSolidBrush (c);
119 protected Brush GetControlForeBrush (Color c) {
120 if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
121 return SystemBrushes.ControlText;
122 return ResPool.GetSolidBrush (c);
124 #endregion // Internal Methods
127 public override Font GetLinkFont (Control control)
129 return new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Underline, control.Font.Unit);
131 #endregion // Control
133 #region OwnerDraw Support
134 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
136 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
137 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
141 e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
144 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
146 if (e.State == DrawItemState.Focus)
147 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
149 #endregion // OwnerDraw Support
152 #region Standard Button Style
153 public override void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
155 // Draw Button Background
156 DrawButtonBackground (g, b, clipRectangle);
158 // If we have an image, draw it
159 if (imageBounds.Size != Size.Empty)
160 DrawButtonImage (g, b, imageBounds);
162 // If we're focused, draw a focus rectangle
163 if (b.Focused && b.Enabled && b.ShowFocusCues)
164 DrawButtonFocus (g, b);
166 // If we have text, draw it
167 if (textBounds != Rectangle.Empty)
168 DrawButtonText (g, b, textBounds);
171 public virtual void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
174 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
175 else if (button.InternalSelected)
176 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
177 else if (button.Entered)
178 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
179 else if (!button.Enabled)
180 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
182 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
185 public virtual void DrawButtonFocus (Graphics g, Button button)
187 ControlPaint.DrawFocusRectangle (g, Rectangle.Inflate (button.ClientRectangle, -4, -4));
190 public virtual void DrawButtonImage (Graphics g, ButtonBase button, Rectangle imageBounds)
193 g.DrawImage (button.Image, imageBounds);
195 CPDrawImageDisabled (g, button.Image, imageBounds.Left, imageBounds.Top, ColorControl);
198 public virtual void DrawButtonText (Graphics g, ButtonBase button, Rectangle textBounds)
200 // Ensure that at least one line is going to get displayed.
201 // Line limit does not ensure that despite its description.
202 textBounds.Height = Math.Max (textBounds.Height, button.Font.Height);
205 TextRenderer.DrawTextInternal (g, button.Text, button.Font, textBounds, button.ForeColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
207 DrawStringDisabled20 (g, button.Text, button.Font, textBounds, button.BackColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
211 #region FlatStyle Button Style
212 public override void DrawFlatButton (Graphics g, ButtonBase b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
214 // Draw Button Background
215 if (b.BackgroundImage == null)
216 DrawFlatButtonBackground (g, b, clipRectangle);
218 // If we have an image, draw it
219 if (imageBounds.Size != Size.Empty)
220 DrawFlatButtonImage (g, b, imageBounds);
222 // If we're focused, draw a focus rectangle
223 if (b.Focused && b.Enabled && b.ShowFocusCues)
224 DrawFlatButtonFocus (g, b);
226 // If we have text, draw it
227 if (textBounds != Rectangle.Empty)
228 DrawFlatButtonText (g, b, textBounds);
231 public virtual void DrawFlatButtonBackground (Graphics g, ButtonBase button, Rectangle clipArea)
234 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor, button.FlatAppearance);
235 else if (button.InternalSelected) {
237 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default | ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
239 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor, button.FlatAppearance);
241 else if (button.Entered)
242 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
243 else if (!button.Enabled)
244 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor, button.FlatAppearance);
246 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor, button.FlatAppearance);
249 public virtual void DrawFlatButtonFocus (Graphics g, ButtonBase button)
251 if (!button.Pressed) {
252 Color focus_color = ControlPaint.Dark (button.BackColor);
253 g.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.Left + 4, button.ClientRectangle.Top + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9));
257 public virtual void DrawFlatButtonImage (Graphics g, ButtonBase button, Rectangle imageBounds)
259 // No changes from Standard for image for this theme
260 DrawButtonImage (g, button, imageBounds);
263 public virtual void DrawFlatButtonText (Graphics g, ButtonBase button, Rectangle textBounds)
265 // No changes from Standard for text for this theme
266 DrawButtonText (g, button, textBounds);
270 #region Popup Button Style
271 public override void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
273 // Draw Button Background
274 DrawPopupButtonBackground (g, b, clipRectangle);
276 // If we have an image, draw it
277 if (imageBounds.Size != Size.Empty)
278 DrawPopupButtonImage (g, b, imageBounds);
280 // If we're focused, draw a focus rectangle
281 if (b.Focused && b.Enabled && b.ShowFocusCues)
282 DrawPopupButtonFocus (g, b);
284 // If we have text, draw it
285 if (textBounds != Rectangle.Empty)
286 DrawPopupButtonText (g, b, textBounds);
289 public virtual void DrawPopupButtonBackground (Graphics g, Button button, Rectangle clipArea)
292 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
293 else if (button.Entered)
294 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
295 else if (button.InternalSelected)
296 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
297 else if (!button.Enabled)
298 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
300 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
303 public virtual void DrawPopupButtonFocus (Graphics g, Button button)
305 // No changes from Standard for image for this theme
306 DrawButtonFocus (g, button);
309 public virtual void DrawPopupButtonImage (Graphics g, Button button, Rectangle imageBounds)
311 // No changes from Standard for image for this theme
312 DrawButtonImage (g, button, imageBounds);
315 public virtual void DrawPopupButtonText (Graphics g, Button button, Rectangle textBounds)
317 // No changes from Standard for image for this theme
318 DrawButtonText (g, button, textBounds);
322 #region Button Layout Calculations
323 public override Size CalculateButtonAutoSize (Button button)
325 Size ret_size = Size.Empty;
326 Size text_size = TextRenderer.MeasureTextInternal (button.Text, button.Font, button.UseCompatibleTextRendering);
327 Size image_size = button.Image == null ? Size.Empty : button.Image.Size;
330 if (button.Text.Length != 0) {
331 text_size.Height += 4;
332 text_size.Width += 4;
335 switch (button.TextImageRelation) {
336 case TextImageRelation.Overlay:
337 ret_size.Height = Math.Max (button.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
338 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
340 case TextImageRelation.ImageAboveText:
341 case TextImageRelation.TextAboveImage:
342 ret_size.Height = text_size.Height + image_size.Height;
343 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
345 case TextImageRelation.ImageBeforeText:
346 case TextImageRelation.TextBeforeImage:
347 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
348 ret_size.Width = text_size.Width + image_size.Width;
353 ret_size.Height += (button.Padding.Vertical + 6);
354 ret_size.Width += (button.Padding.Horizontal + 6);
359 public override void CalculateButtonTextAndImageLayout (ButtonBase button, out Rectangle textRectangle, out Rectangle imageRectangle)
361 Image image = button.Image;
362 string text = button.Text;
363 Rectangle content_rect = button.ClientRectangle;
364 Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
365 Size image_size = image == null ? Size.Empty : image.Size;
367 textRectangle = Rectangle.Empty;
368 imageRectangle = Rectangle.Empty;
370 switch (button.TextImageRelation) {
371 case TextImageRelation.Overlay:
372 // Overlay is easy, text always goes here
373 textRectangle = Rectangle.Inflate (content_rect, -4, -4);
376 textRectangle.Offset (1, 1);
378 // Image is dependent on ImageAlign
384 int image_height = image.Height;
385 int image_width = image.Width;
387 switch (button.ImageAlign) {
388 case System.Drawing.ContentAlignment.TopLeft:
392 case System.Drawing.ContentAlignment.TopCenter:
393 image_x = (content_rect.Width - image_width) / 2;
396 case System.Drawing.ContentAlignment.TopRight:
397 image_x = content_rect.Width - image_width - 5;
400 case System.Drawing.ContentAlignment.MiddleLeft:
402 image_y = (content_rect.Height - image_height) / 2;
404 case System.Drawing.ContentAlignment.MiddleCenter:
405 image_x = (content_rect.Width - image_width) / 2;
406 image_y = (content_rect.Height - image_height) / 2;
408 case System.Drawing.ContentAlignment.MiddleRight:
409 image_x = content_rect.Width - image_width - 4;
410 image_y = (content_rect.Height - image_height) / 2;
412 case System.Drawing.ContentAlignment.BottomLeft:
414 image_y = content_rect.Height - image_height - 4;
416 case System.Drawing.ContentAlignment.BottomCenter:
417 image_x = (content_rect.Width - image_width) / 2;
418 image_y = content_rect.Height - image_height - 4;
420 case System.Drawing.ContentAlignment.BottomRight:
421 image_x = content_rect.Width - image_width - 4;
422 image_y = content_rect.Height - image_height - 4;
430 imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
432 case TextImageRelation.ImageAboveText:
433 content_rect.Inflate (-4, -4);
434 LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
436 case TextImageRelation.TextAboveImage:
437 content_rect.Inflate (-4, -4);
438 LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
440 case TextImageRelation.ImageBeforeText:
441 content_rect.Inflate (-4, -4);
442 LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
444 case TextImageRelation.TextBeforeImage:
445 content_rect.Inflate (-4, -4);
446 LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
451 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)
453 int element_spacing = 0; // Spacing between the Text and the Image
454 int total_width = textSize.Width + element_spacing + imageSize.Width;
457 element_spacing += 2;
459 // If the text is too big, chop it down to the size we have available to it
460 if (total_width > totalArea.Width) {
461 textSize.Width = totalArea.Width - element_spacing - imageSize.Width;
462 total_width = totalArea.Width;
465 int excess_width = totalArea.Width - total_width;
468 Rectangle final_text_rect;
469 Rectangle final_image_rect;
471 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
472 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
474 if (h_image == HorizontalAlignment.Left)
476 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
477 offset = excess_width;
478 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
479 offset += (int)(excess_width / 3);
481 offset += (int)(2 * (excess_width / 3));
484 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
485 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
488 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
489 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
492 textRect = final_text_rect;
493 imageRect = final_image_rect;
496 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)
498 int element_spacing = 0; // Spacing between the Text and the Image
499 int total_height = textSize.Height + element_spacing + imageSize.Height;
502 element_spacing += 2;
504 if (textSize.Width > totalArea.Width)
505 textSize.Width = totalArea.Width;
507 // If the there isn't enough room and we're text first, cut out the image
508 if (total_height > totalArea.Height && textFirst) {
509 imageSize = Size.Empty;
510 total_height = totalArea.Height;
513 int excess_height = totalArea.Height - total_height;
516 Rectangle final_text_rect;
517 Rectangle final_image_rect;
519 VerticalAlignment v_text = GetVerticalAlignment (textAlign);
520 VerticalAlignment v_image = GetVerticalAlignment (imageAlign);
522 if (v_image == VerticalAlignment.Top)
524 else if (v_image == VerticalAlignment.Bottom && v_text == VerticalAlignment.Bottom)
525 offset = excess_height;
526 else if (v_image == VerticalAlignment.Center && (v_text == VerticalAlignment.Top || v_text == VerticalAlignment.Center))
527 offset += (int)(excess_height / 3);
529 offset += (int)(2 * (excess_height / 3));
532 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textSize.Height);
533 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, final_text_rect.Bottom + element_spacing, imageSize.Width, imageSize.Height);
536 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, totalArea.Top + offset, imageSize.Width, imageSize.Height);
537 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textSize.Height);
539 if (final_text_rect.Bottom > totalArea.Bottom)
540 final_text_rect.Y = totalArea.Top;
543 textRect = final_text_rect;
544 imageRect = final_image_rect;
547 private HorizontalAlignment GetHorizontalAlignment (System.Drawing.ContentAlignment align)
550 case System.Drawing.ContentAlignment.BottomLeft:
551 case System.Drawing.ContentAlignment.MiddleLeft:
552 case System.Drawing.ContentAlignment.TopLeft:
553 return HorizontalAlignment.Left;
554 case System.Drawing.ContentAlignment.BottomCenter:
555 case System.Drawing.ContentAlignment.MiddleCenter:
556 case System.Drawing.ContentAlignment.TopCenter:
557 return HorizontalAlignment.Center;
558 case System.Drawing.ContentAlignment.BottomRight:
559 case System.Drawing.ContentAlignment.MiddleRight:
560 case System.Drawing.ContentAlignment.TopRight:
561 return HorizontalAlignment.Right;
564 return HorizontalAlignment.Left;
567 private enum VerticalAlignment
574 private VerticalAlignment GetVerticalAlignment (System.Drawing.ContentAlignment align)
577 case System.Drawing.ContentAlignment.TopLeft:
578 case System.Drawing.ContentAlignment.TopCenter:
579 case System.Drawing.ContentAlignment.TopRight:
580 return VerticalAlignment.Top;
581 case System.Drawing.ContentAlignment.MiddleLeft:
582 case System.Drawing.ContentAlignment.MiddleCenter:
583 case System.Drawing.ContentAlignment.MiddleRight:
584 return VerticalAlignment.Center;
585 case System.Drawing.ContentAlignment.BottomLeft:
586 case System.Drawing.ContentAlignment.BottomCenter:
587 case System.Drawing.ContentAlignment.BottomRight:
588 return VerticalAlignment.Bottom;
591 return VerticalAlignment.Top;
594 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, System.Drawing.ContentAlignment align)
599 if (align == System.Drawing.ContentAlignment.BottomLeft || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.TopLeft)
601 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.TopCenter)
602 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
603 else if (align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.MiddleRight || align == System.Drawing.ContentAlignment.TopRight)
604 x = outer.Right - inner.Width;
605 if (align == System.Drawing.ContentAlignment.TopCenter || align == System.Drawing.ContentAlignment.TopLeft || align == System.Drawing.ContentAlignment.TopRight)
607 else if (align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.MiddleRight)
608 y = outer.Y + (outer.Height - inner.Height) / 2;
609 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.BottomLeft)
610 y = outer.Bottom - inner.Height;
612 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
618 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button)
620 // Draw the button: Draw border, etc.
621 ButtonBase_DrawButton(button, dc);
624 if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null)))
625 ButtonBase_DrawImage(button, dc);
627 // Draw the focus rectangle
628 if (ShouldPaintFocusRectagle (button))
629 ButtonBase_DrawFocus(button, dc);
632 if (button.Text != null && button.Text != String.Empty)
633 ButtonBase_DrawText(button, dc);
636 protected static bool ShouldPaintFocusRectagle (ButtonBase button)
638 return (button.Focused || button.paint_as_acceptbutton) && button.Enabled && button.ShowFocusCues;
641 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
643 Rectangle borderRectangle;
644 bool check_or_radio = false;
645 bool check_or_radio_checked = false;
647 bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
649 CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
651 if (button is CheckBox) {
652 check_or_radio = true;
653 check_or_radio_checked = ((CheckBox)button).Checked;
654 } else if (button is RadioButton) {
655 check_or_radio = true;
656 check_or_radio_checked = ((RadioButton)button).Checked;
659 if (button.Focused && button.Enabled && !check_or_radio) {
660 // shrink the rectangle for the normal button drawing inside the focus rectangle
661 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
663 borderRectangle = button.ClientRectangle;
666 if (button.FlatStyle == FlatStyle.Popup) {
667 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
668 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
669 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
670 Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
671 else if (button.is_pressed || check_or_radio_checked)
672 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
673 } else if (button.FlatStyle == FlatStyle.Flat) {
674 if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
675 if ((button.image == null) && (button.image_list == null)) {
676 Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
677 dc.FillRectangle (brush, borderRectangle);
679 } else if (button.is_pressed || check_or_radio_checked) {
680 if ((button.image == null) && (button.image_list == null)) {
681 Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
682 dc.FillRectangle (brush, borderRectangle);
685 Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
686 dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
687 borderRectangle.Width - 9, borderRectangle.Height - 9);
690 Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
692 if ((!button.is_pressed || !button.Enabled) && !check_or_radio_checked)
693 Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
695 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
699 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
702 case 0: // normal or normal disabled button
703 Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
704 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
705 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
707 pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
708 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
709 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
711 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
712 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
713 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
715 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
716 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
717 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
719 case 1: // popup button normal (or pressed normal or popup button)
720 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
721 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
723 case 2: // popup button poped up
724 pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
725 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
726 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
728 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
729 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
730 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
732 case 3: // flat button not entered
733 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
734 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
741 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
743 // Need to draw a picture
750 int width = button.ClientSize.Width;
751 int height = button.ClientSize.Height;
753 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
754 i = button.image_list.Images[button.ImageIndex];
759 image_width = i.Width;
760 image_height = i.Height;
762 switch (button.ImageAlign) {
763 case ContentAlignment.TopLeft: {
769 case ContentAlignment.TopCenter: {
770 image_x = (width - image_width) / 2;
775 case ContentAlignment.TopRight: {
776 image_x = width - image_width - 5;
781 case ContentAlignment.MiddleLeft: {
783 image_y = (height - image_height) / 2;
787 case ContentAlignment.MiddleCenter: {
788 image_x = (width - image_width) / 2;
789 image_y = (height - image_height) / 2;
793 case ContentAlignment.MiddleRight: {
794 image_x = width - image_width - 4;
795 image_y = (height - image_height) / 2;
799 case ContentAlignment.BottomLeft: {
801 image_y = height - image_height - 4;
805 case ContentAlignment.BottomCenter: {
806 image_x = (width - image_width) / 2;
807 image_y = height - image_height - 4;
811 case ContentAlignment.BottomRight: {
812 image_x = width - image_width - 4;
813 image_y = height - image_height - 4;
824 dc.SetClip (new Rectangle(3, 3, width - 5, height - 5));
827 dc.DrawImage (i, image_x, image_y, image_width, image_height);
829 CPDrawImageDisabled (dc, i, image_x, image_y, ColorControl);
834 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
836 Color focus_color = button.ForeColor;
838 int inflate_value = -3;
840 if (!(button is CheckBox) && !(button is RadioButton)) {
843 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed)
844 focus_color = ControlPaint.Dark(button.BackColor);
846 dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y,
847 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
850 if (button.Focused) {
851 Rectangle rect = Rectangle.Inflate (button.ClientRectangle, inflate_value, inflate_value);
852 ControlPaint.DrawFocusRectangle (dc, rect);
856 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
858 Rectangle buttonRectangle = button.ClientRectangle;
859 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
861 if (button.is_pressed) {
866 // Ensure that at least one line is going to get displayed.
867 // Line limit does not ensure that despite its description.
868 text_rect.Height = Math.Max (button.Font.Height, text_rect.Height);
870 if (button.Enabled) {
871 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
873 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
874 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
876 CPDrawStringDisabled (dc, button.Text, button.Font, button.BackColor, text_rect, button.text_format);
881 public override Size ButtonBaseDefaultSize {
883 return new Size (75, 23);
886 #endregion // ButtonBase
889 public override void DrawCheckBox (Graphics g, CheckBox cb, Rectangle glyphArea, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
891 // Draw Button Background
892 if (cb.Appearance == Appearance.Button && cb.FlatStyle != FlatStyle.Flat)
893 ButtonBase_DrawButton (cb, g);
894 else if (cb.Appearance != Appearance.Button)
895 DrawCheckBoxGlyph (g, cb, glyphArea);
897 // Draw the borders and such for a Flat CheckBox Button
898 if (cb.Appearance == Appearance.Button && cb.FlatStyle == FlatStyle.Flat)
899 DrawFlatButton (g, cb, textBounds, imageBounds, clipRectangle);
901 // If we have an image, draw it
902 if (imageBounds.Size != Size.Empty)
903 DrawCheckBoxImage (g, cb, imageBounds);
905 if (cb.Focused && cb.Enabled && cb.ShowFocusCues && textBounds != Rectangle.Empty)
906 DrawCheckBoxFocus (g, cb, textBounds);
908 // If we have text, draw it
909 if (textBounds != Rectangle.Empty)
910 DrawCheckBoxText (g, cb, textBounds);
913 public virtual void DrawCheckBoxGlyph (Graphics g, CheckBox cb, Rectangle glyphArea)
916 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Pressed, cb.FlatStyle, cb.CheckState);
917 else if (cb.InternalSelected)
918 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
920 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Hot, cb.FlatStyle, cb.CheckState);
921 else if (!cb.Enabled)
922 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Disabled, cb.FlatStyle, cb.CheckState);
924 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
927 public virtual void DrawCheckBoxFocus (Graphics g, CheckBox cb, Rectangle focusArea)
929 ControlPaint.DrawFocusRectangle (g, focusArea);
932 public virtual void DrawCheckBoxImage (Graphics g, CheckBox cb, Rectangle imageBounds)
935 g.DrawImage (cb.Image, imageBounds);
937 CPDrawImageDisabled (g, cb.Image, imageBounds.Left, imageBounds.Top, ColorControl);
940 public virtual void DrawCheckBoxText (Graphics g, CheckBox cb, Rectangle textBounds)
943 TextRenderer.DrawTextInternal (g, cb.Text, cb.Font, textBounds, cb.ForeColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
945 DrawStringDisabled20 (g, cb.Text, cb.Font, textBounds, cb.BackColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
948 public override void CalculateCheckBoxTextAndImageLayout (ButtonBase button, Point p, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
952 if (button is CheckBox)
953 check_size = (button as CheckBox).Appearance == Appearance.Normal ? 13 : 0;
955 glyphArea = new Rectangle (0, 2, check_size, check_size);
957 Rectangle content_rect = button.ClientRectangle;
958 ContentAlignment align = ContentAlignment.TopLeft;;
960 if (button is CheckBox)
961 align = (button as CheckBox).CheckAlign;
962 else if (button is RadioButton)
963 align = (button as RadioButton).CheckAlign;
966 case ContentAlignment.BottomCenter:
967 glyphArea.Y = button.Height - check_size;
968 glyphArea.X = (button.Width - check_size) / 2 - 2;
970 case ContentAlignment.BottomLeft:
971 glyphArea.Y = button.Height - check_size - 2;
972 content_rect.Width -= check_size;
973 content_rect.Offset (check_size, 0);
975 case ContentAlignment.BottomRight:
976 glyphArea.Y = button.Height - check_size - 2;
977 glyphArea.X = button.Width - check_size;
978 content_rect.Width -= check_size;
980 case ContentAlignment.MiddleCenter:
981 glyphArea.Y = (button.Height - check_size) / 2;
982 glyphArea.X = (button.Width - check_size) / 2;
984 case ContentAlignment.MiddleLeft:
985 glyphArea.Y = (button.Height - check_size) / 2;
986 content_rect.Width -= check_size;
987 content_rect.Offset (check_size, 0);
989 case ContentAlignment.MiddleRight:
990 glyphArea.Y = (button.Height - check_size) / 2;
991 glyphArea.X = button.Width - check_size;
992 content_rect.Width -= check_size;
994 case ContentAlignment.TopCenter:
995 glyphArea.X = (button.Width - check_size) / 2;
997 case ContentAlignment.TopLeft:
998 content_rect.Width -= check_size;
999 content_rect.Offset (check_size, 0);
1001 case ContentAlignment.TopRight:
1002 glyphArea.X = button.Width - check_size;
1003 content_rect.Width -= check_size;
1007 Image image = button.Image;
1008 string text = button.Text;
1010 Size proposed = Size.Empty;
1012 // Force wrapping if we aren't AutoSize and our text is too long
1013 if (!button.AutoSize)
1014 proposed.Width = button.Width - glyphArea.Width - 2;
1016 Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, proposed, button.TextFormatFlags, button.UseCompatibleTextRendering);
1018 // Text can't be bigger than the content rectangle
1019 text_size.Height = Math.Min (text_size.Height, content_rect.Height);
1020 text_size.Width = Math.Min (text_size.Width, content_rect.Width);
1022 Size image_size = image == null ? Size.Empty : image.Size;
1024 textRectangle = Rectangle.Empty;
1025 imageRectangle = Rectangle.Empty;
1027 switch (button.TextImageRelation) {
1028 case TextImageRelation.Overlay:
1029 // Text is centered vertically, and 2 pixels to the right
1030 textRectangle.X = content_rect.Left + 2;
1031 textRectangle.Y = ((content_rect.Height - text_size.Height) / 2) - 1;
1032 textRectangle.Size = text_size;
1034 // Image is dependent on ImageAlign
1040 int image_height = image.Height;
1041 int image_width = image.Width;
1043 switch (button.ImageAlign) {
1044 case System.Drawing.ContentAlignment.TopLeft:
1048 case System.Drawing.ContentAlignment.TopCenter:
1049 image_x = (content_rect.Width - image_width) / 2;
1052 case System.Drawing.ContentAlignment.TopRight:
1053 image_x = content_rect.Width - image_width - 5;
1056 case System.Drawing.ContentAlignment.MiddleLeft:
1058 image_y = (content_rect.Height - image_height) / 2;
1060 case System.Drawing.ContentAlignment.MiddleCenter:
1061 image_x = (content_rect.Width - image_width) / 2;
1062 image_y = (content_rect.Height - image_height) / 2;
1064 case System.Drawing.ContentAlignment.MiddleRight:
1065 image_x = content_rect.Width - image_width - 4;
1066 image_y = (content_rect.Height - image_height) / 2;
1068 case System.Drawing.ContentAlignment.BottomLeft:
1070 image_y = content_rect.Height - image_height - 4;
1072 case System.Drawing.ContentAlignment.BottomCenter:
1073 image_x = (content_rect.Width - image_width) / 2;
1074 image_y = content_rect.Height - image_height - 4;
1076 case System.Drawing.ContentAlignment.BottomRight:
1077 image_x = content_rect.Width - image_width - 4;
1078 image_y = content_rect.Height - image_height - 4;
1086 imageRectangle = new Rectangle (image_x + check_size, image_y, image_width, image_height);
1088 case TextImageRelation.ImageAboveText:
1089 content_rect.Inflate (-4, -4);
1090 LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1092 case TextImageRelation.TextAboveImage:
1093 content_rect.Inflate (-4, -4);
1094 LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1096 case TextImageRelation.ImageBeforeText:
1097 content_rect.Inflate (-4, -4);
1098 LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1100 case TextImageRelation.TextBeforeImage:
1101 content_rect.Inflate (-4, -4);
1102 LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1107 public override Size CalculateCheckBoxAutoSize (CheckBox checkBox)
1109 Size ret_size = Size.Empty;
1110 Size text_size = TextRenderer.MeasureTextInternal (checkBox.Text, checkBox.Font, checkBox.UseCompatibleTextRendering);
1111 Size image_size = checkBox.Image == null ? Size.Empty : checkBox.Image.Size;
1113 // Pad the text size
1114 if (checkBox.Text.Length != 0) {
1115 text_size.Height += 4;
1116 text_size.Width += 4;
1119 switch (checkBox.TextImageRelation) {
1120 case TextImageRelation.Overlay:
1121 ret_size.Height = Math.Max (checkBox.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
1122 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
1124 case TextImageRelation.ImageAboveText:
1125 case TextImageRelation.TextAboveImage:
1126 ret_size.Height = text_size.Height + image_size.Height;
1127 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
1129 case TextImageRelation.ImageBeforeText:
1130 case TextImageRelation.TextBeforeImage:
1131 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
1132 ret_size.Width = text_size.Width + image_size.Width;
1137 ret_size.Height += (checkBox.Padding.Vertical);
1138 ret_size.Width += (checkBox.Padding.Horizontal) + 15;
1140 // There seems to be a minimum height
1141 if (ret_size.Height == checkBox.Padding.Vertical)
1142 ret_size.Height += 14;
1147 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
1148 StringFormat text_format;
1149 Rectangle client_rectangle;
1150 Rectangle text_rectangle;
1151 Rectangle checkbox_rectangle;
1152 int checkmark_size=13;
1153 int checkmark_space = 4;
1155 client_rectangle = checkbox.ClientRectangle;
1156 text_rectangle = client_rectangle;
1157 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
1159 text_format = new StringFormat();
1160 text_format.Alignment = StringAlignment.Near;
1161 text_format.LineAlignment = StringAlignment.Center;
1162 if (checkbox.ShowKeyboardCuesInternal)
1163 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1165 text_format.HotkeyPrefix = HotkeyPrefix.Hide;
1167 /* Calculate the position of text and checkbox rectangle */
1168 if (checkbox.appearance!=Appearance.Button) {
1169 switch(checkbox.check_alignment) {
1170 case ContentAlignment.BottomCenter: {
1171 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1172 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1173 text_rectangle.X=client_rectangle.X;
1174 text_rectangle.Width=client_rectangle.Width;
1175 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
1179 case ContentAlignment.BottomLeft: {
1180 checkbox_rectangle.X=client_rectangle.Left;
1181 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1182 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1183 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1187 case ContentAlignment.BottomRight: {
1188 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1189 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1190 text_rectangle.X=client_rectangle.X;
1191 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1195 case ContentAlignment.MiddleCenter: {
1196 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1197 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1198 text_rectangle.X=client_rectangle.X;
1199 text_rectangle.Width=client_rectangle.Width;
1204 case ContentAlignment.MiddleLeft: {
1205 checkbox_rectangle.X=client_rectangle.Left;
1206 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1207 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1208 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1212 case ContentAlignment.MiddleRight: {
1213 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1214 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1215 text_rectangle.X=client_rectangle.X;
1216 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1220 case ContentAlignment.TopCenter: {
1221 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1222 checkbox_rectangle.Y=client_rectangle.Top;
1223 text_rectangle.X=client_rectangle.X;
1224 text_rectangle.Width=client_rectangle.Width;
1225 text_rectangle.Y=checkmark_size+checkmark_space;
1226 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
1230 case ContentAlignment.TopLeft: {
1231 checkbox_rectangle.X=client_rectangle.Left;
1232 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1233 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1237 case ContentAlignment.TopRight: {
1238 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1239 text_rectangle.X=client_rectangle.X;
1240 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1245 text_rectangle.X=client_rectangle.X;
1246 text_rectangle.Width=client_rectangle.Width;
1249 /* Set the horizontal alignment of our text */
1250 switch(checkbox.text_alignment) {
1251 case ContentAlignment.BottomLeft:
1252 case ContentAlignment.MiddleLeft:
1253 case ContentAlignment.TopLeft: {
1254 text_format.Alignment=StringAlignment.Near;
1258 case ContentAlignment.BottomCenter:
1259 case ContentAlignment.MiddleCenter:
1260 case ContentAlignment.TopCenter: {
1261 text_format.Alignment=StringAlignment.Center;
1265 case ContentAlignment.BottomRight:
1266 case ContentAlignment.MiddleRight:
1267 case ContentAlignment.TopRight: {
1268 text_format.Alignment=StringAlignment.Far;
1273 /* Set the vertical alignment of our text */
1274 switch(checkbox.text_alignment) {
1275 case ContentAlignment.TopLeft:
1276 case ContentAlignment.TopCenter:
1277 case ContentAlignment.TopRight: {
1278 text_format.LineAlignment=StringAlignment.Near;
1282 case ContentAlignment.BottomLeft:
1283 case ContentAlignment.BottomCenter:
1284 case ContentAlignment.BottomRight: {
1285 text_format.LineAlignment=StringAlignment.Far;
1289 case ContentAlignment.MiddleLeft:
1290 case ContentAlignment.MiddleCenter:
1291 case ContentAlignment.MiddleRight: {
1292 text_format.LineAlignment=StringAlignment.Center;
1297 ButtonState state = ButtonState.Normal;
1298 if (checkbox.FlatStyle == FlatStyle.Flat) {
1299 state |= ButtonState.Flat;
1302 if (checkbox.Checked) {
1303 state |= ButtonState.Checked;
1306 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
1307 state |= ButtonState.Checked;
1308 state |= ButtonState.Pushed;
1311 // finally make sure the pushed and inavtive states are rendered
1312 if (!checkbox.Enabled) {
1313 state |= ButtonState.Inactive;
1315 else if (checkbox.is_pressed) {
1316 state |= ButtonState.Pushed;
1321 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
1323 if ((checkbox.image != null) || (checkbox.image_list != null))
1324 ButtonBase_DrawImage(checkbox, dc);
1326 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
1328 if (checkbox.Focused && checkbox.Enabled && checkbox.appearance != Appearance.Button && checkbox.Text != String.Empty && checkbox.ShowFocusCues) {
1329 SizeF text_size = dc.MeasureString (checkbox.Text, checkbox.Font);
1331 Rectangle focus_rect = Rectangle.Empty;
1332 focus_rect.X = text_rectangle.X;
1333 focus_rect.Y = (int)((text_rectangle.Height - text_size.Height) / 2);
1334 focus_rect.Size = text_size.ToSize ();
1335 CheckBox_DrawFocus (checkbox, dc, focus_rect);
1338 text_format.Dispose ();
1341 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
1343 Brush brush = checkbox.BackColor.ToArgb () == ColorControl.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
1344 dc.FillRectangle (brush, checkbox.ClientRectangle);
1345 // render as per normal button
1346 if (checkbox.appearance==Appearance.Button) {
1347 ButtonBase_DrawButton (checkbox, dc);
1349 if ((checkbox.Focused) && checkbox.Enabled)
1350 ButtonBase_DrawFocus(checkbox, dc);
1352 // establish if we are rendering a flat style of some sort
1353 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
1354 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
1356 CPDrawCheckBox (dc, checkbox_rectangle, state);
1361 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
1363 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
1364 text_format, checkbox.Appearance, checkbox.Checked);
1367 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
1369 DrawInnerFocusRectangle (dc, text_rectangle, checkbox.BackColor);
1372 // renders a checkBox with the Flat and Popup FlatStyle
1373 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
1377 Rectangle checkbox_rectangle;
1378 Rectangle fill_rectangle;
1382 // set up our rectangles first
1383 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
1384 // clip one pixel from bottom right for non popup rendered checkboxes
1385 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
1386 fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-3, 0), Math.Max(checkbox_rectangle.Height-3,0));
1388 // clip two pixels from bottom right for non popup rendered checkboxes
1389 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
1390 fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-2, 0), Math.Max(checkbox_rectangle.Height-2,0));
1394 // if disabled render in disabled state
1395 if (checkbox.Enabled) {
1396 // process the state of the checkbox
1397 if (checkbox.is_entered || checkbox.Capture) {
1398 // decide on which background color to use
1399 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
1400 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1401 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
1402 if (!checkbox.is_pressed) {
1403 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1405 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1407 // use regular window background color
1408 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1411 // render the outer border
1412 if (checkbox.FlatStyle == FlatStyle.Flat) {
1413 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1415 // draw sunken effect
1416 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
1419 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1421 if (checkbox.FlatStyle == FlatStyle.Flat) {
1422 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1424 // draw the outer border
1425 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
1429 if (checkbox.FlatStyle == FlatStyle.Popup) {
1430 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
1433 // draw disabled state,
1434 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
1437 if (checkbox.Checked) {
1438 /* Need to draw a check-mark */
1440 /* Make sure we've got at least a line width of 1 */
1441 lineWidth = Math.Max(3, fill_rectangle.Width/3);
1442 Scale=Math.Max(1, fill_rectangle.Width/9);
1444 // flat style check box is rendered inside a rectangle shifted down by one
1445 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
1446 if (checkbox.Enabled) {
1447 pen=ResPool.GetPen(checkbox.ForeColor);
1449 pen=SystemPens.ControlDark;
1452 for (int i=0; i<lineWidth; i++) {
1453 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
1454 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);
1459 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
1460 StringFormat text_format, Appearance appearance, bool ischecked)
1462 // offset the text if it's pressed and a button
1463 if (appearance == Appearance.Button) {
1464 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
1465 text_rectangle.X ++;
1466 text_rectangle.Y ++;
1469 text_rectangle.Inflate (-4, -4);
1472 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
1474 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
1475 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
1476 text_format.FormatFlags |= StringFormatFlags.NoWrap;
1478 if (button_base.Enabled) {
1479 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
1480 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
1481 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
1483 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
1486 #endregion // CheckBox
1488 #region CheckedListBox
1490 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
1492 Color back_color, fore_color;
1493 Rectangle item_rect = e.Bounds;
1498 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
1499 state = ButtonState.Checked;
1500 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
1501 state |= ButtonState.Inactive;
1503 state = ButtonState.Normal;
1505 if (ctrl.ThreeDCheckBoxes == false)
1506 state |= ButtonState.Flat;
1508 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 13, 13);
1509 ControlPaint.DrawCheckBox (e.Graphics,
1510 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
1511 checkbox_rect.Width, checkbox_rect.Height,
1514 item_rect.X += checkbox_rect.Right;
1515 item_rect.Width -= checkbox_rect.Right;
1518 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1519 back_color = ColorHighlight;
1520 fore_color = ColorHighlightText;
1523 back_color = e.BackColor;
1524 fore_color = e.ForeColor;
1527 e.Graphics.FillRectangle (ResPool.GetSolidBrush
1528 (back_color), item_rect);
1530 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1531 ResPool.GetSolidBrush (fore_color),
1532 item_rect, ctrl.StringFormat);
1534 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1535 CPDrawFocusRectangle (e.Graphics, item_rect,
1536 fore_color, back_color);
1540 #endregion // CheckedListBox
1543 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
1545 Color back_color, fore_color;
1546 Rectangle text_draw = e.Bounds;
1547 StringFormat string_format = new StringFormat ();
1548 string_format.FormatFlags = StringFormatFlags.LineLimit;
1550 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1551 back_color = ColorHighlight;
1552 fore_color = ColorHighlightText;
1555 back_color = e.BackColor;
1556 fore_color = e.ForeColor;
1560 fore_color = ColorInactiveCaptionText;
1562 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1564 if (e.Index != -1) {
1565 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1566 ResPool.GetSolidBrush (fore_color),
1567 text_draw, string_format);
1570 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1571 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1574 string_format.Dispose ();
1577 public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
1579 Point[] arrow = new Point[3];
1589 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
1590 centerX=rect.Left+rect.Width/2;
1591 centerY=rect.Top+rect.Height/2;
1592 shiftX=Math.Max(1, rect.Width/8);
1593 shiftY=Math.Max(1, rect.Height/8);
1595 if ((state & ButtonState.Pushed)!=0) {
1602 P1=new Point(rect.Left + 1, centerY);
1603 P2=new Point(rect.Right - 1, centerY);
1604 P3=new Point(centerX, rect.Bottom - 1);
1610 /* Draw the arrow */
1611 if ((state & ButtonState.Inactive)!=0) {
1612 /* Move away from the shadow */
1613 arrow[0].X += 1; arrow[0].Y += 1;
1614 arrow[1].X += 1; arrow[1].Y += 1;
1615 arrow[2].X += 1; arrow[2].Y += 1;
1617 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
1623 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
1625 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
1628 public override void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state)
1630 CPDrawComboButton (g, area, state);
1632 public override bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state)
1636 public override bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox)
1640 public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
1642 if (!comboBox.Enabled)
1643 g.FillRectangle (ResPool.GetSolidBrush (ColorControl), comboBox.ClientRectangle);
1645 if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
1646 g.FillRectangle (ResPool.GetSolidBrush (comboBox.Parent.BackColor), comboBox.ClientRectangle);
1648 if (style == FlatStyle.Popup && (comboBox.Entered || comboBox.Focused)) {
1649 Rectangle area = comboBox.TextArea;
1652 g.DrawRectangle (ResPool.GetPen (SystemColors.ControlDark), area);
1653 g.DrawLine (ResPool.GetPen (SystemColors.ControlDark), comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Top, comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Bottom);
1655 bool is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
1656 if (!is_flat && clippingArea.IntersectsWith (comboBox.TextArea))
1657 ControlPaint.DrawBorder3D (g, comboBox.TextArea, Border3DStyle.Sunken);
1659 public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
1666 public override int DataGridPreferredColumnWidth { get { return 75;} }
1667 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
1668 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
1669 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
1670 public override Color DataGridBackColor { get { return ColorWindow;} }
1671 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
1672 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
1673 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
1674 public override Color DataGridGridLineColor { get { return ColorControl;} }
1675 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
1676 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
1677 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
1678 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
1679 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
1680 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
1681 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
1682 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
1684 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
1686 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
1687 DataGridPaintParentRows (pe.Graphics, pe.ClipRectangle, grid);
1688 DataGridPaintColumnHeaders (pe.Graphics, pe.ClipRectangle, grid);
1689 DataGridPaintRows (pe.Graphics, grid.cells_area, pe.ClipRectangle, grid);
1691 // Paint scrollBar corner
1692 if (grid.VScrollBar.Visible && grid.HScrollBar.Visible) {
1694 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.VScrollBar.Width,
1695 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.HScrollBar.Height,
1696 grid.VScrollBar.Width, grid.HScrollBar.Height);
1698 if (pe.ClipRectangle.IntersectsWith (corner)) {
1699 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1705 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
1707 Rectangle bounds = clip;
1708 bounds.Intersect (grid.caption_area);
1711 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor), bounds);
1714 g.DrawLine (ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor),
1715 bounds.X, bounds.Y + bounds.Height -1,
1716 bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1719 if (grid.CaptionText != String.Empty) {
1720 Rectangle text_rect = grid.caption_area;
1721 text_rect.Y += text_rect.Height / 2 - grid.CaptionFont.Height / 2;
1722 text_rect.Height = grid.CaptionFont.Height;
1724 g.DrawString (grid.CaptionText, grid.CaptionFont,
1725 ResPool.GetSolidBrush (grid.CaptionForeColor),
1730 if (bounds.IntersectsWith (grid.back_button_rect)) {
1731 g.DrawImage (grid.back_button_image, grid.back_button_rect);
1732 if (grid.back_button_mouseover) {
1733 CPDrawBorder3D (g, grid.back_button_rect, grid.back_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1738 if (bounds.IntersectsWith (grid.parent_rows_button_rect)) {
1739 g.DrawImage (grid.parent_rows_button_image, grid.parent_rows_button_rect);
1740 if (grid.parent_rows_button_mouseover) {
1741 CPDrawBorder3D (g, grid.parent_rows_button_rect, grid.parent_rows_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1746 public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
1748 if (!grid.CurrentTableStyle.ColumnHeadersVisible)
1751 Rectangle columns_area = grid.column_headers_area;
1753 // Paint corner shared between row and column header
1754 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1755 Rectangle rect_bloc = grid.column_headers_area;
1756 rect_bloc.Width = grid.RowHeaderWidth;
1757 if (clip.IntersectsWith (rect_bloc)) {
1759 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
1761 CPDrawBorder3D (g, rect_bloc, Border3DStyle.RaisedInner,
1762 Border3DSide.Left | Border3DSide.Right |
1763 Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Middle,
1764 grid.CurrentTableStyle.CurrentHeaderBackColor);
1767 columns_area.X += grid.RowHeaderWidth;
1768 columns_area.Width -= grid.RowHeaderWidth;
1771 // Set column painting
1772 Rectangle rect_columnhdr = new Rectangle ();
1774 Region current_clip;
1775 Region prev_clip = g.Clip;
1776 rect_columnhdr.Y = columns_area.Y;
1777 rect_columnhdr.Height = columns_area.Height;
1779 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1780 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1781 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
1784 col_pixel = grid.GetColumnStartingPixel (column);
1785 rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
1786 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1788 if (clip.IntersectsWith (rect_columnhdr) == false)
1791 current_clip = new Region (rect_columnhdr);
1792 current_clip.Intersect (columns_area);
1793 current_clip.Intersect (prev_clip);
1794 g.Clip = current_clip;
1796 DataGridPaintColumnHeader (g, rect_columnhdr, grid, column);
1798 current_clip.Dispose ();
1803 Rectangle not_usedarea = grid.column_headers_area;
1804 not_usedarea.X = (column_cnt == 0) ? grid.RowHeaderWidth : rect_columnhdr.X + rect_columnhdr.Width;
1805 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - not_usedarea.X;
1806 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1809 public override void DataGridPaintColumnHeader (Graphics g, Rectangle bounds, DataGrid grid, int col)
1812 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.HeaderBackColor), bounds);
1815 if (!grid.FlatMode) {
1816 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1817 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1820 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1821 bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height);
1823 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1824 bounds.X, bounds.Y + 2, bounds.X, bounds.Y + bounds.Height - 3);
1827 if (col == (grid.VisibleColumnCount -1)) {
1828 g.DrawLine (ResPool.GetPen (ColorControlDark),
1829 bounds.X + bounds.Width - 1, bounds.Y,
1830 bounds.X + bounds.Width - 1, bounds.Y + bounds.Height);
1832 g.DrawLine (ResPool.GetPen (ColorControlDark),
1833 bounds.X + bounds.Width - 1, bounds.Y + 2,
1834 bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 3);
1837 g.DrawLine (ResPool.GetPen (ColorControlDark),
1838 bounds.X, bounds.Y + bounds.Height - 1,
1839 bounds.X + bounds.Width, bounds.Y + bounds.Height - 1);
1845 DataGridColumnStyle style = grid.CurrentTableStyle.GridColumnStyles[col];
1847 if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No)
1851 StringFormat format = new StringFormat ();
1852 format.FormatFlags |= StringFormatFlags.NoWrap;
1853 format.LineAlignment = StringAlignment.Center;
1854 format.Trimming = StringTrimming.Character;
1856 g.DrawString (style.HeaderText, grid.CurrentTableStyle.HeaderFont,
1857 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1861 if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No) {
1862 Point pnt = new Point (bounds.X + bounds.Width + 4, bounds.Y + ((bounds.Height - 6)/2));
1864 if (style.ArrowDrawingMode == DataGridColumnStyle.ArrowDrawing.Ascending) {
1865 g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y + 6, pnt.X + 3, pnt.Y);
1866 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 6, pnt.Y + 6);
1867 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 3, pnt.Y);
1869 g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y, pnt.X + 3, pnt.Y + 6);
1870 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 6, pnt.Y);
1871 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 3, pnt.Y + 6);
1876 public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
1878 Rectangle rect_row = new Rectangle ();
1880 rect_row.X = grid.ParentRowsArea.X;
1881 rect_row.Width = grid.ParentRowsArea.Width;
1882 rect_row.Height = (grid.CaptionFont.Height + 3);
1884 object[] parentRows = grid.data_source_stack.ToArray();
1886 Region current_clip;
1887 Region prev_clip = g.Clip;
1888 for (int row = 0; row < parentRows.Length; row++) {
1889 rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
1891 if (clip.IntersectsWith (rect_row) == false)
1894 current_clip = new Region (rect_row);
1895 current_clip.Intersect (prev_clip);
1896 g.Clip = current_clip;
1898 DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);
1900 current_clip.Dispose ();
1906 public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
1909 g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1912 Font bold_font = new Font (grid.Font.FontFamily, grid.Font.Size, grid.Font.Style | FontStyle.Bold);
1913 // set up some standard string formating variables
1914 StringFormat text_format = new StringFormat();
1915 text_format.LineAlignment = StringAlignment.Center;
1916 text_format.Alignment = StringAlignment.Near;
1918 string table_name = "";
1919 if (row.view is DataRowView)
1920 table_name = ((ITypedList)((DataRowView)row.view).DataView).GetListName (null) + ": ";
1923 Rectangle text_rect;
1926 text_size = g.MeasureString (table_name, bold_font).ToSize();
1927 text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
1929 g.DrawString (table_name,
1930 bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1932 foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)row.view).GetProperties()) {
1933 if (typeof(IBindingList).IsAssignableFrom (pd.PropertyType))
1936 text_rect.X += text_rect.Size.Width + 5;
1938 string text = String.Format ("{0}: {1}",
1940 pd.GetValue (row.view));
1942 text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
1943 text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
1946 grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1950 if (!grid.FlatMode) {
1951 CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
1952 Border3DSide.Left | Border3DSide.Right |
1953 Border3DSide.Top | Border3DSide.Bottom);
1957 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1959 Point[] arrow = new Point[3];
1961 int centerX, centerY, shiftX;
1964 rect = new Rectangle (bounds.X + bounds.Width /4,
1965 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1967 centerX = rect.Left + rect.Width / 2;
1968 centerY = rect.Top + rect.Height / 2;
1969 shiftX = Math.Max (1, rect.Width / 8);
1972 P1 = new Point (centerX, rect.Top - 1);
1973 P2 = new Point (centerX, rect.Bottom);
1974 P3 = new Point (rect.Right, centerY);
1979 g.FillPolygon (ResPool.GetSolidBrush
1980 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1983 public override void DataGridPaintRowHeaderStar (Graphics g, Rectangle bounds, DataGrid grid)
1985 int x = bounds.X + 4;
1986 int y = bounds.Y + 3;
1987 Pen pen = ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor);
1989 g.DrawLine (pen, x + 4, y, x + 4, y + 8);
1990 g.DrawLine (pen, x, y + 4, x + 8, y + 4);
1991 g.DrawLine (pen, x + 1, y + 1, x + 7, y + 7);
1992 g.DrawLine (pen, x + 7, y + 1, x + 1, y + 7);
1995 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
1997 bool is_add_row = grid.ShowEditRow && row == grid.DataGridRows.Length - 1;
1998 bool is_current_row = row == grid.CurrentCell.RowNumber;
2001 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), bounds);
2004 if (is_current_row) {
2005 if (grid.IsChanging) {
2006 g.DrawString ("...", grid.Font,
2007 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
2010 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
2011 DataGridPaintRowHeaderArrow (g, rect, grid);
2014 else if (is_add_row) {
2015 DataGridPaintRowHeaderStar (g, bounds, grid);
2018 if (!grid.FlatMode && !is_add_row) {
2019 CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
2020 Border3DSide.Left | Border3DSide.Right |
2021 Border3DSide.Top | Border3DSide.Bottom);
2025 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
2027 Rectangle rect_row = new Rectangle ();
2028 Rectangle not_usedarea = new Rectangle ();
2030 int rowcnt = grid.VisibleRowCount;
2032 bool showing_add_row = false;
2034 if (grid.RowsCount < grid.DataGridRows.Length) {
2035 /* the table has an add row */
2037 if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.DataGridRows.Length) {
2038 showing_add_row = true;
2042 rect_row.Width = cells.Width + grid.RowHeadersArea.Width;
2043 for (int r = 0; r < rowcnt; r++) {
2044 int row = grid.FirstVisibleRow + r;
2045 if (row == grid.DataGridRows.Length - 1)
2046 rect_row.Height = grid.DataGridRows[row].Height;
2048 rect_row.Height = grid.DataGridRows[row + 1].VerticalOffset - grid.DataGridRows[row].VerticalOffset;
2049 rect_row.Y = cells.Y + grid.DataGridRows[row].VerticalOffset - grid.DataGridRows[grid.FirstVisibleRow].VerticalOffset;
2050 if (clip.IntersectsWith (rect_row)) {
2051 if (grid.CurrentTableStyle.HasRelations
2052 && !(showing_add_row && row == grid.DataGridRows.Length - 1))
2053 DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
2055 DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.DataGridRows.Length - 1, clip, grid);
2060 // the rowcnt == 0 check is needed because
2061 // otherwise we'd draw over the caption on
2062 // empty datasources (since rect_row would be
2065 not_usedarea.Y = cells.Y;
2067 not_usedarea.Y = rect_row.Y + rect_row.Height;
2068 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
2069 not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
2071 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
2074 public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2075 Rectangle clip, DataGrid grid)
2077 Rectangle rect_header;
2078 Rectangle icon_bounds = new Rectangle ();
2079 Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor);
2081 /* paint the header if it's visible and intersects the clip */
2082 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
2083 rect_header = row_rect;
2084 rect_header.Width = grid.RowHeaderWidth;
2085 row_rect.X += grid.RowHeaderWidth;
2086 if (clip.IntersectsWith (rect_header)) {
2087 DataGridPaintRowHeader (g, rect_header, row, grid);
2090 icon_bounds = rect_header;
2091 icon_bounds.X += icon_bounds.Width / 2;
2093 icon_bounds.Width = 8;
2094 icon_bounds.Height = 8;
2096 g.DrawRectangle (pen, icon_bounds);
2098 /* the - part of the icon */
2100 icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2,
2101 icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2);
2103 if (!grid.IsExpanded (row)) {
2104 /* the | part of the icon */
2106 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2,
2107 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2);
2111 Rectangle nested_rect = row_rect;
2113 if (grid.DataGridRows[row].IsExpanded)
2114 nested_rect.Height -= grid.DataGridRows[row].RelationHeight;
2116 DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
2118 if (grid.DataGridRows[row].IsExpanded) {
2119 // XXX we should create this in the
2120 // datagrid and cache it for use by
2121 // the theme instead of doing it each
2122 // time through here
2123 string[] relations = grid.CurrentTableStyle.Relations;
2124 StringBuilder relation_builder = new StringBuilder ("");
2126 for (int i = 0; i < relations.Length; i ++) {
2128 relation_builder.Append ("\n");
2130 relation_builder.Append (relations[i]);
2132 string relation_text = relation_builder.ToString ();
2134 StringFormat string_format = new StringFormat ();
2135 string_format.FormatFlags |= StringFormatFlags.NoWrap;
2138 //Region prev_clip = g.Clip;
2139 //Region current_clip;
2140 Rectangle rect_cell = row_rect;
2142 rect_cell.X = nested_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
2143 rect_cell.Y += nested_rect.Height;
2144 rect_cell.Height = grid.DataGridRows[row].RelationHeight;
2146 rect_cell.Width = 0;
2147 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
2148 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
2149 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
2151 rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width;
2153 rect_cell.Width = Math.Max (rect_cell.Width, grid.DataGridRows[row].relation_area.Width);
2155 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
2159 /* draw the line leading from the +/- to the relation area */
2160 Rectangle outline = grid.DataGridRows[row].relation_area;
2161 outline.Y = rect_cell.Y;
2165 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
2166 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2);
2169 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
2170 outline.X, outline.Y + outline.Height / 2);
2172 g.DrawRectangle (pen, outline);
2174 g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor),
2175 outline, string_format);
2177 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
2178 Rectangle not_usedarea = new Rectangle ();
2179 not_usedarea.X = rect_cell.X + rect_cell.Width;
2180 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
2181 not_usedarea.Y = row_rect.Y;
2182 not_usedarea.Height = row_rect.Height;
2183 if (clip.IntersectsWith (not_usedarea))
2184 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
2190 public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2191 Rectangle clip, DataGrid grid)
2193 Rectangle rect_cell = new Rectangle ();
2195 Color backcolor, forecolor;
2196 Brush backBrush, foreBrush;
2197 Rectangle not_usedarea = Rectangle.Empty;
2199 rect_cell.Y = row_rect.Y;
2200 rect_cell.Height = row_rect.Height;
2202 if (grid.IsSelected (row)) {
2203 backcolor = grid.SelectionBackColor;
2204 forecolor = grid.SelectionForeColor;
2207 backcolor = grid.BackColor;
2209 backcolor = grid.AlternatingBackColor;
2212 forecolor = grid.ForeColor;
2216 backBrush = ResPool.GetSolidBrush (backcolor);
2217 foreBrush = ResPool.GetSolidBrush (forecolor);
2219 // PaintCells at row, column
2220 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
2221 DataGridCell current_cell = grid.CurrentCell;
2223 if (column_cnt > 0) {
2224 Region prev_clip = g.Clip;
2225 Region current_clip;
2227 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
2228 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
2231 col_pixel = grid.GetColumnStartingPixel (column);
2233 rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
2234 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
2236 if (clip.IntersectsWith (rect_cell)) {
2237 current_clip = new Region (rect_cell);
2238 current_clip.Intersect (row_rect);
2239 current_clip.Intersect (prev_clip);
2240 g.Clip = current_clip;
2242 Brush colBackBrush = backBrush;
2243 Brush colForeBrush = foreBrush;
2245 // If we are in the precise cell we are editing, then use the normal colors
2246 // even if we are selected.
2247 if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) {
2248 colBackBrush = ResPool.GetSolidBrush (grid.BackColor);
2249 colForeBrush = ResPool.GetSolidBrush (grid.ForeColor);
2253 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
2257 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
2260 grid.RightToLeft == RightToLeft.Yes);
2263 current_clip.Dispose ();
2269 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
2270 not_usedarea.X = rect_cell.X + rect_cell.Width;
2271 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
2272 not_usedarea.Y = row_rect.Y;
2273 not_usedarea.Height = row_rect.Height;
2277 not_usedarea = row_rect;
2280 if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea))
2281 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
2285 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2286 Rectangle clip, DataGrid grid)
2288 /* paint the header if it's visible and intersects the clip */
2289 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
2290 Rectangle rect_header = row_rect;
2291 rect_header.Width = grid.RowHeaderWidth;
2292 row_rect.X += grid.RowHeaderWidth;
2293 if (clip.IntersectsWith (rect_header)) {
2294 DataGridPaintRowHeader (g, rect_header, row, grid);
2298 DataGridPaintRowContents (g, row, row_rect, is_newrow, clip, grid);
2301 #endregion // Datagrid
2303 #region DataGridView
2304 #region DataGridViewHeaderCell
2305 #region DataGridViewRowHeaderCell
2306 public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
2311 public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
2316 public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
2322 #region DataGridViewColumnHeaderCell
2323 public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
2328 public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
2334 public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
2339 public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
2346 #region DateTimePicker
2347 protected virtual void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
2349 this.CPDrawBorder3D (g, dateTimePicker.ClientRectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dateTimePicker.BackColor);
2352 protected virtual void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
2354 ButtonState state = dateTimePicker.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
2355 g.FillRectangle (ResPool.GetSolidBrush (ColorControl), dateTimePicker.drop_down_arrow_rect);
2356 this.CPDrawComboButton (
2358 dateTimePicker.drop_down_arrow_rect,
2362 public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp)
2365 if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle))
2368 // draw the outer border
2369 Rectangle button_bounds = dtp.ClientRectangle;
2370 DateTimePickerDrawBorder (dtp, dc, clip_rectangle);
2372 // deflate by the border width
2373 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
2374 button_bounds.Inflate (-2,-2);
2375 if (!dtp.ShowUpDown) {
2376 DateTimePickerDrawDropDownButton (dtp, dc, clip_rectangle);
2378 ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal;
2379 ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal;
2380 Rectangle up_bounds = dtp.drop_down_arrow_rect;
2381 Rectangle down_bounds = dtp.drop_down_arrow_rect;
2383 up_bounds.Height = up_bounds.Height / 2;
2384 down_bounds.Y = up_bounds.Height;
2385 down_bounds.Height = dtp.Height - up_bounds.Height;
2386 if (down_bounds.Height > up_bounds.Height)
2389 down_bounds.Height -= 1;
2392 up_bounds.Inflate (-1, -1);
2393 down_bounds.Inflate (-1, -1);
2395 ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state);
2396 ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state);
2400 // render the date part
2401 if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
2404 // fill the background
2405 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
2407 // Update date_area_rect if we are drawing the checkbox
2408 Rectangle date_area_rect = dtp.date_area_rect;
2409 if (dtp.ShowCheckBox) {
2410 Rectangle check_box_rect = dtp.CheckBoxRect;
2411 date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
2412 date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;
2414 ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
2415 CPDrawCheckBox(dc, check_box_rect, bs);
2417 if (dtp.is_checkbox_selected)
2418 CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
2421 // render each text part
2422 using (StringFormat text_format = StringFormat.GenericTypographic)
2424 text_format.LineAlignment = StringAlignment.Near;
2425 text_format.Alignment = StringAlignment.Near;
2426 text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
2427 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
2429 // Calculate the rectangles for each part
2430 if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
2433 for (int i = 0; i < dtp.part_data.Length; i++)
2435 DateTimePicker.PartData fd = dtp.part_data[i];
2436 RectangleF text_rect = new RectangleF();
2437 string text = fd.GetText(dtp.Value);
2438 text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
2440 text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);
2443 text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
2445 text_rect.X = date_area_rect.X;
2448 text_rect.Inflate (1, 0);
2449 fd.drawing_rectangle = text_rect;
2453 // draw the text part
2454 Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ?
2455 SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false
2456 RectangleF clip_rectangleF = clip_rectangle;
2458 for (int i = 0; i < dtp.part_data.Length; i++)
2460 DateTimePicker.PartData fd = dtp.part_data [i];
2463 if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle))
2466 text = dtp.editing_part_index == i ? dtp.editing_text : fd.GetText (dtp.Value);
2468 PointF text_position = new PointF ();
2470 RectangleF text_rect;
2472 text_size = dc.MeasureString (text, dtp.Font, 250, text_format);
2473 text_position.X = (fd.drawing_rectangle.Left + fd.drawing_rectangle.Width / 2) - text_size.Width / 2;
2474 text_position.Y = (fd.drawing_rectangle.Top + fd.drawing_rectangle.Height / 2) - text_size.Height / 2;
2475 text_rect = new RectangleF (text_position, text_size);
2476 text_rect = RectangleF.Intersect (text_rect, date_area_rect);
2478 if (text_rect.IsEmpty)
2481 if (text_rect.Right >= date_area_rect.Right)
2482 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
2484 text_format.FormatFlags |= StringFormatFlags.NoClip;
2487 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
2488 dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format);
2491 dc.DrawString (text, dtp.Font, text_brush, text_rect, text_format);
2494 if (fd.drawing_rectangle.Right > date_area_rect.Right)
2495 break; // the next part would be not be visible, so don't draw anything more.
2500 public override bool DateTimePickerBorderHasHotElementStyle {
2506 public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
2508 Rectangle rect = dateTimePicker.ClientRectangle;
2509 rect.X = rect.Right - SystemInformation.VerticalScrollBarWidth - 2;
2510 if (rect.Width > (SystemInformation.VerticalScrollBarWidth + 2)) {
2511 rect.Width = SystemInformation.VerticalScrollBarWidth;
2513 rect.Width = Math.Max (rect.Width - 2, 0);
2516 rect.Inflate (0, -2);
2520 public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
2522 Rectangle rect = dateTimePicker.ClientRectangle;
2523 if (dateTimePicker.ShowUpDown) {
2524 // set the space to the left of the up/down button
2525 if (rect.Width > (DateTimePicker.up_down_width + 4)) {
2526 rect.Width -= (DateTimePicker.up_down_width + 4);
2531 // set the space to the left of the up/down button
2532 // TODO make this use up down button
2533 if (rect.Width > (SystemInformation.VerticalScrollBarWidth + 4)) {
2534 rect.Width -= SystemInformation.VerticalScrollBarWidth;
2540 rect.Inflate (-2, -2);
2543 public override bool DateTimePickerDropDownButtonHasHotElementStyle {
2548 #endregion // DateTimePicker
2551 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
2552 StringFormat text_format;
2557 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
2559 text_format = new StringFormat();
2560 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2562 size = dc.MeasureString (box.Text, box.Font);
2565 if (size.Width > 0) {
2566 width = ((int) size.Width) + 7;
2568 if (width > box.Width - 16)
2569 width = box.Width - 16;
2572 y = box.Font.Height / 2;
2574 // Clip the are that the text will be in
2575 Region prev_clip = dc.Clip;
2576 dc.SetClip (new Rectangle (10, 0, width, box.Font.Height), CombineMode.Exclude);
2578 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
2579 dc.Clip = prev_clip;
2582 if (box.Text.Length != 0) {
2584 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
2586 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
2587 new RectangleF (10, 0, width, box.Font.Height), text_format);
2591 text_format.Dispose ();
2594 public override Size GroupBoxDefaultSize {
2596 return new Size (200,100);
2602 public override Size HScrollBarDefaultSize {
2604 return new Size (80, this.ScrollBarButtonSize);
2608 #endregion // HScrollBar
2612 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
2614 Color back_color, fore_color;
2616 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
2617 back_color = ColorHighlight;
2618 fore_color = ColorHighlightText;
2620 back_color = e.BackColor;
2621 fore_color = e.ForeColor;
2624 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
2626 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
2627 ResPool.GetSolidBrush (fore_color),
2628 e.Bounds, ctrl.StringFormat);
2630 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
2631 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
2638 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
2640 bool details = control.View == View.Details;
2641 int first = control.FirstVisibleIndex;
2642 int lastvisibleindex = control.LastVisibleIndex;
2644 if (control.VirtualMode)
2645 control.OnCacheVirtualItems (new CacheVirtualItemsEventArgs (first, lastvisibleindex));
2647 for (int i = first; i <= lastvisibleindex; i++) {
2648 ListViewItem item = control.GetItemAtDisplayIndex (i);
2649 if (clip.IntersectsWith (item.Bounds)) {
2650 bool owner_draw = false;
2651 if (control.OwnerDraw)
2652 owner_draw = DrawListViewItemOwnerDraw (dc, item, i);
2655 DrawListViewItem (dc, control, item);
2656 if (control.View == View.Details)
2657 DrawListViewSubItems (dc, control, item);
2662 if (control.UsingGroups) {
2663 // Use InternalCount instead of Count to take into account Default Group as needed
2664 for (int i = 0; i < control.Groups.InternalCount; i++) {
2665 ListViewGroup group = control.Groups.GetInternalGroup (i);
2666 if (group.ItemCount > 0 && clip.IntersectsWith (group.HeaderBounds))
2667 DrawListViewGroupHeader (dc, control, group);
2671 ListViewInsertionMark insertion_mark = control.InsertionMark;
2672 int insertion_mark_index = insertion_mark.Index;
2673 if (Application.VisualStylesEnabled && insertion_mark.Bounds != Rectangle.Empty &&
2674 (control.View != View.Details && control.View != View.List) &&
2675 insertion_mark_index > -1 && insertion_mark_index < control.Items.Count) {
2677 Brush brush = ResPool.GetSolidBrush (insertion_mark.Color);
2678 dc.FillRectangle (brush, insertion_mark.Line);
2679 dc.FillPolygon (brush, insertion_mark.TopTriangle);
2680 dc.FillPolygon (brush, insertion_mark.BottomTriangle);
2683 // draw the gridlines
2684 if (details && control.GridLines && !control.UsingGroups) {
2685 Size control_size = control.ClientSize;
2686 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
2687 0 : control.header_control.Height;
2689 // draw vertical gridlines
2690 foreach (ColumnHeader col in control.Columns) {
2691 int column_right = col.Rect.Right - control.h_marker;
2692 dc.DrawLine (SystemPens.Control,
2694 column_right, control_size.Height);
2697 // draw horizontal gridlines
2698 int item_height = control.ItemSize.Height;
2699 if (item_height == 0)
2700 item_height = control.Font.Height + 2;
2702 int y = top + item_height - (control.v_marker % item_height); // scroll bar offset
2703 while (y < control_size.Height) {
2704 dc.DrawLine (SystemPens.Control, 0, y, control_size.Width, y);
2709 // Draw corner between the two scrollbars
2710 if (control.h_scroll.Visible == true && control.v_scroll.Visible == true) {
2711 Rectangle rect = new Rectangle ();
2712 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
2713 rect.Width = control.v_scroll.Width;
2714 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
2715 rect.Height = control.h_scroll.Height;
2716 dc.FillRectangle (SystemBrushes.Control, rect);
2719 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
2720 if (!box_select_rect.Size.IsEmpty)
2721 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
2725 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
2727 bool details = (control.View == View.Details);
2729 // border is drawn directly in the Paint method
2730 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
2731 dc.FillRectangle (SystemBrushes.Control,
2732 0, 0, control.TotalWidth, control.Font.Height + 5);
2733 if (control.Columns.Count > 0) {
2734 foreach (ColumnHeader col in control.Columns) {
2735 Rectangle rect = col.Rect;
2736 rect.X -= control.h_marker;
2738 bool owner_draw = false;
2739 if (control.OwnerDraw)
2740 owner_draw = DrawListViewColumnHeaderOwnerDraw (dc, control, col, rect);
2744 ListViewDrawColumnHeaderBackground (control, col, dc, rect, clip);
2747 if (rect.Width <= 0)
2751 if (control.SmallImageList == null)
2754 image_index = col.ImageKey == String.Empty ? col.ImageIndex : control.SmallImageList.Images.IndexOfKey (col.ImageKey);
2756 if (image_index > -1 && image_index < control.SmallImageList.Images.Count) {
2757 int image_width = control.SmallImageList.ImageSize.Width + 5;
2758 int text_width = (int)dc.MeasureString (col.Text, control.Font).Width;
2759 int x_origin = rect.X;
2760 int y_origin = rect.Y + ((rect.Height - control.SmallImageList.ImageSize.Height) / 2);
2762 switch (col.TextAlign) {
2763 case HorizontalAlignment.Left:
2765 case HorizontalAlignment.Right:
2766 x_origin = rect.Right - (text_width + image_width);
2768 case HorizontalAlignment.Center:
2769 x_origin = (rect.Width - (text_width + image_width)) / 2 + rect.X;
2773 if (x_origin < rect.X)
2776 control.SmallImageList.Draw (dc, new Point (x_origin, y_origin), image_index);
2777 rect.X += image_width;
2778 rect.Width -= image_width;
2781 dc.DrawString (col.Text, control.Font, SystemBrushes.ControlText, rect, col.Format);
2783 int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker;
2784 if (right < control.Right) {
2785 Rectangle rect = control.Columns [0].Rect;
2787 rect.Width = control.Right - right;
2788 ListViewDrawUnusedHeaderBackground (control, dc, rect, clip);
2794 protected virtual void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
2797 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
2798 state = columnHeader.Pressed ? ButtonState.Pushed : ButtonState.Normal;
2800 state = ButtonState.Flat;
2801 CPDrawButton (g, area, state);
2804 protected virtual void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
2807 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
2808 state = ButtonState.Normal;
2810 state = ButtonState.Flat;
2811 CPDrawButton (g, area, state);
2814 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
2816 Rectangle rect = col.Rect;
2817 rect.X -= view.h_marker;
2818 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
2819 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
2822 if (rect.Width <= 0)
2824 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
2825 dc.DrawString (col.Text, view.Font, ResPool.GetSolidBrush (color), rect, col.Format);
2826 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
2829 protected virtual bool DrawListViewColumnHeaderOwnerDraw (Graphics dc, ListView control, ColumnHeader column, Rectangle bounds)
2831 ListViewItemStates state = ListViewItemStates.ShowKeyboardCues;
2833 state |= ListViewItemStates.Selected;
2835 DrawListViewColumnHeaderEventArgs args = new DrawListViewColumnHeaderEventArgs (dc,
2836 bounds, column.Index, column, state, SystemColors.ControlText, ThemeEngine.Current.ColorControl, DefaultFont);
2837 control.OnDrawColumnHeader (args);
2839 return !args.DrawDefault;
2842 protected virtual bool DrawListViewItemOwnerDraw (Graphics dc, ListViewItem item, int index)
2844 ListViewItemStates item_state = ListViewItemStates.ShowKeyboardCues;
2846 item_state |= ListViewItemStates.Selected;
2848 item_state |= ListViewItemStates.Focused;
2850 DrawListViewItemEventArgs args = new DrawListViewItemEventArgs (dc,
2851 item, item.Bounds, index, item_state);
2852 item.ListView.OnDrawItem (args);
2854 if (args.DrawDefault)
2857 if (item.ListView.View == View.Details) {
2858 int count = Math.Min (item.ListView.Columns.Count, item.SubItems.Count);
2860 // Do system drawing for subitems if no owner draw is done
2861 for (int j = 0; j < count; j++) {
2862 if (!DrawListViewSubItemOwnerDraw (dc, item, item_state, j)) {
2863 if (j == 0) // The first sub item contains the main item semantics
2864 DrawListViewItem (dc, item.ListView, item);
2866 DrawListViewSubItem (dc, item.ListView, item, j);
2874 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
2876 Rectangle rect_checkrect = item.CheckRectReal;
2877 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
2878 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
2879 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
2881 // Tile view doesn't support CheckBoxes
2882 if (control.CheckBoxes && control.View != View.Tile) {
2883 if (control.StateImageList == null) {
2884 // Make sure we've got at least a line width of 1
2885 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
2886 int scale = Math.Max (1, rect_checkrect.Width / 12);
2888 // set the checkbox background
2889 dc.FillRectangle (SystemBrushes.Window,
2891 // define a rectangle inside the border area
2892 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
2893 rect_checkrect.Y + 2,
2894 rect_checkrect.Width - 4,
2895 rect_checkrect.Height - 4);
2896 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
2897 dc.DrawRectangle (pen, rect);
2899 // Need to draw a check-mark
2901 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
2902 // adjustments to get the check-mark at the right place
2903 rect.X ++; rect.Y ++;
2904 // following logic is taken from DrawFrameControl method
2905 int x_offset = rect.Width / 5;
2906 int y_offset = rect.Height / 3;
2907 for (int i = 0; i < check_wd; i++) {
2908 dc.DrawLine (check_pen, rect.Left + x_offset,
2909 rect.Top + y_offset + i,
2910 rect.Left + x_offset + 2 * scale,
2911 rect.Top + y_offset + 2 * scale + i);
2912 dc.DrawLine (check_pen,
2913 rect.Left + x_offset + 2 * scale,
2914 rect.Top + y_offset + 2 * scale + i,
2915 rect.Left + x_offset + 6 * scale,
2916 rect.Top + y_offset - 2 * scale + i);
2923 simage_idx = control.StateImageList.Images.Count > 1 ? 1 : -1;
2925 simage_idx = control.StateImageList.Images.Count > 0 ? 0 : -1;
2927 if (simage_idx > -1)
2928 control.StateImageList.Draw (dc, rect_checkrect.Location, simage_idx);
2932 ImageList image_list = control.View == View.LargeIcon || control.View == View.Tile ? control.LargeImageList : control.SmallImageList;
2933 if (image_list != null) {
2936 if (item.ImageKey != String.Empty)
2937 idx = image_list.Images.IndexOfKey (item.ImageKey);
2939 idx = item.ImageIndex;
2941 if (idx > -1 && idx < image_list.Images.Count)
2942 image_list.Draw (dc, icon_rect.Location, idx);
2945 // draw the item text
2946 // format for the item text
2947 StringFormat format = new StringFormat ();
2948 if (control.View == View.SmallIcon || control.View == View.LargeIcon)
2949 format.LineAlignment = StringAlignment.Near;
2951 format.LineAlignment = StringAlignment.Center;
2952 if (control.View == View.LargeIcon)
2953 format.Alignment = StringAlignment.Center;
2955 format.Alignment = StringAlignment.Near;
2957 if (control.LabelWrap && control.View != View.Details && control.View != View.Tile)
2958 format.FormatFlags = StringFormatFlags.LineLimit;
2960 format.FormatFlags = StringFormatFlags.NoWrap;
2962 if ((control.View == View.LargeIcon && !item.Focused) || control.View == View.Details || control.View == View.Tile)
2963 format.Trimming = StringTrimming.EllipsisCharacter;
2965 Rectangle highlight_rect = text_rect;
2966 if (control.View == View.Details) { // Adjustments for Details view
2967 Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
2969 if (!control.FullRowSelect) // Selection shouldn't be outside the item bounds
2970 highlight_rect.Width = Math.Min (text_size.Width + 4, text_rect.Width);
2973 if (item.Selected && control.Focused)
2974 dc.FillRectangle (SystemBrushes.Highlight, highlight_rect);
2975 else if (item.Selected && !control.HideSelection)
2976 dc.FillRectangle (SystemBrushes.Control, highlight_rect);
2978 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
2981 !control.Enabled ? SystemBrushes.ControlLight :
2982 (item.Selected && control.Focused) ? SystemBrushes.HighlightText :
2983 this.ResPool.GetSolidBrush (item.ForeColor);
2985 // Tile view renders its Text in a different fashion
2986 if (control.View == View.Tile && Application.VisualStylesEnabled) {
2987 // Item.Text is drawn using its first subitem's bounds
2988 dc.DrawString (item.Text, item.Font, textBrush, item.SubItems [0].Bounds, format);
2990 int count = Math.Min (control.Columns.Count, item.SubItems.Count);
2991 for (int i = 1; i < count; i++) {
2992 ListViewItem.ListViewSubItem sub_item = item.SubItems [i];
2993 if (sub_item.Text == null || sub_item.Text.Length == 0)
2996 Brush itemBrush = item.Selected && control.Focused ?
2997 SystemBrushes.HighlightText : GetControlForeBrush (sub_item.ForeColor);
2998 dc.DrawString (sub_item.Text, sub_item.Font, itemBrush, sub_item.Bounds, format);
3002 if (item.Text != null && item.Text.Length > 0) {
3003 Font font = item.Font;
3005 if (control.HotTracking && item.Hot)
3006 font = item.HotFont;
3008 if (item.Selected && control.Focused)
3009 dc.DrawString (item.Text, font, textBrush, highlight_rect, format);
3011 dc.DrawString (item.Text, font, textBrush, text_rect, format);
3014 if (item.Focused && control.Focused) {
3015 Rectangle focus_rect = highlight_rect;
3016 if (control.FullRowSelect && control.View == View.Details) {
3018 foreach (ColumnHeader col in control.Columns)
3020 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
3022 if (control.ShowFocusCues) {
3024 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
3026 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
3033 protected virtual void DrawListViewSubItems (Graphics dc, ListView control, ListViewItem item)
3035 int columns_count = control.Columns.Count;
3036 int count = Math.Min (item.SubItems.Count, columns_count);
3037 // 0th item already done (in this case)
3038 for (int i = 1; i < count; i++)
3039 DrawListViewSubItem (dc, control, item, i);
3041 // Fill in selection for remaining columns if Column.Count > SubItems.Count
3042 Rectangle sub_item_rect = item.GetBounds (ItemBoundsPortion.Label);
3043 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
3044 for (int index = count; index < columns_count; index++) {
3045 ColumnHeader col = control.Columns [index];
3046 sub_item_rect.X = col.Rect.X - control.h_marker;
3047 sub_item_rect.Width = col.Wd;
3048 dc.FillRectangle (control.Focused ? SystemBrushes.Highlight : SystemBrushes.Control,
3054 protected virtual void DrawListViewSubItem (Graphics dc, ListView control, ListViewItem item, int index)
3056 ListViewItem.ListViewSubItem subItem = item.SubItems [index];
3057 ColumnHeader col = control.Columns [index];
3058 StringFormat format = new StringFormat ();
3059 format.Alignment = col.Format.Alignment;
3060 format.LineAlignment = StringAlignment.Center;
3061 format.FormatFlags = StringFormatFlags.NoWrap;
3062 format.Trimming = StringTrimming.EllipsisCharacter;
3064 Rectangle sub_item_rect = subItem.Bounds;
3065 Rectangle sub_item_text_rect = sub_item_rect;
3066 sub_item_text_rect.X += 3;
3067 sub_item_text_rect.Width -= ListViewItemPaddingWidth;
3069 SolidBrush sub_item_back_br = null;
3070 SolidBrush sub_item_fore_br = null;
3071 Font sub_item_font = null;
3073 if (item.UseItemStyleForSubItems) {
3074 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
3075 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
3077 // Hot tracking for subitems only applies when UseStyle is true
3078 if (control.HotTracking && item.Hot)
3079 sub_item_font = item.HotFont;
3081 sub_item_font = item.Font;
3083 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
3084 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
3085 sub_item_font = subItem.Font;
3088 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
3090 if (control.Focused) {
3091 bg = SystemBrushes.Highlight;
3092 text = SystemBrushes.HighlightText;
3094 bg = SystemBrushes.Control;
3095 text = sub_item_fore_br;
3099 dc.FillRectangle (bg, sub_item_rect);
3100 if (subItem.Text != null && subItem.Text.Length > 0)
3101 dc.DrawString (subItem.Text, sub_item_font,
3102 text, sub_item_text_rect, format);
3104 dc.FillRectangle (sub_item_back_br, sub_item_rect);
3105 if (subItem.Text != null && subItem.Text.Length > 0)
3106 dc.DrawString (subItem.Text, sub_item_font,
3108 sub_item_text_rect, format);
3114 protected virtual bool DrawListViewSubItemOwnerDraw (Graphics dc, ListViewItem item, ListViewItemStates state, int index)
3116 ListView control = item.ListView;
3117 ListViewItem.ListViewSubItem subitem = item.SubItems [index];
3119 DrawListViewSubItemEventArgs args = new DrawListViewSubItemEventArgs (dc, subitem.Bounds, item,
3120 subitem, item.Index, index, control.Columns [index], state);
3121 control.OnDrawSubItem (args);
3123 return !args.DrawDefault;
3126 protected virtual void DrawListViewGroupHeader (Graphics dc, ListView control, ListViewGroup group)
3128 Rectangle text_bounds = group.HeaderBounds;
3129 Rectangle header_bounds = group.HeaderBounds;
3130 text_bounds.Offset (8, 0);
3131 text_bounds.Inflate (-8, 0);
3132 int text_height = control.Font.Height + 2; // add a tiny padding between the text and the group line
3134 Font font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
3135 Brush brush = new LinearGradientBrush (new Point (header_bounds.Left, 0), new Point (header_bounds.Left + ListViewGroupLineWidth, 0),
3136 SystemColors.Desktop, Color.White);
3137 Pen pen = new Pen (brush);
3139 StringFormat sformat = new StringFormat ();
3140 switch (group.HeaderAlignment) {
3141 case HorizontalAlignment.Left:
3142 sformat.Alignment = StringAlignment.Near;
3144 case HorizontalAlignment.Center:
3145 sformat.Alignment = StringAlignment.Center;
3147 case HorizontalAlignment.Right:
3148 sformat.Alignment = StringAlignment.Far;
3152 sformat.LineAlignment = StringAlignment.Near;
3153 dc.DrawString (group.Header, font, SystemBrushes.ControlText, text_bounds, sformat);
3154 dc.DrawLine (pen, header_bounds.Left, header_bounds.Top + text_height, header_bounds.Left + ListViewGroupLineWidth,
3155 header_bounds.Top + text_height);
3163 public override bool ListViewHasHotHeaderStyle {
3170 public override int ListViewGetHeaderHeight (ListView listView, Font font)
3172 return ListViewGetHeaderHeight (font);
3175 static int ListViewGetHeaderHeight (Font font)
3177 return font.Height + 5;
3180 public static int ListViewGetHeaderHeight ()
3182 return ListViewGetHeaderHeight (ThemeEngine.Current.DefaultFont);
3185 public override Size ListViewCheckBoxSize {
3186 get { return new Size (16, 16); }
3189 public override int ListViewColumnHeaderHeight {
3193 public override int ListViewDefaultColumnWidth {
3197 public override int ListViewVerticalSpacing {
3201 public override int ListViewEmptyColumnWidth {
3205 public override int ListViewHorizontalSpacing {
3209 public override int ListViewItemPaddingWidth {
3213 public override Size ListViewDefaultSize {
3214 get { return new Size (121, 97); }
3217 public override int ListViewGroupHeight {
3221 public int ListViewGroupLineWidth {
3225 public override int ListViewTileWidthFactor {
3229 public override int ListViewTileHeightFactor {
3232 #endregion // ListView
3236 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
3241 if (item.Visible == false) {
3247 if (item.Separator == true) {
3248 item.Height = SEPARATOR_HEIGHT;
3249 item.Width = SEPARATOR_MIN_WIDTH;
3253 if (item.MeasureEventDefined) {
3254 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
3255 item.PerformMeasureItem (mi);
3256 item.Height = mi.ItemHeight;
3257 item.Width = mi.ItemWidth;
3261 size = dc.MeasureString (item.Text, MenuFont, int.MaxValue, string_format_menu_text);
3262 item.Width = (int) size.Width;
3263 item.Height = (int) size.Height;
3266 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
3267 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
3268 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
3269 item.Width += MENU_TAB_SPACE + (int) size.Width;
3272 item.Width += 4 + (MenuCheckSize.Width * 2);
3274 item.Width += MENU_BAR_ITEMS_SPACE;
3278 if (item.Height < MenuHeight)
3279 item.Height = MenuHeight;
3283 // Updates the menu rect and returns the height
3284 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
3290 foreach (MenuItem item in menu.MenuItems) {
3292 CalcItemSize (dc, item, y, x, true);
3294 if (x + item.Width > width) {
3302 item.MenuBar = true;
3304 if (y + item.Height > menu.Height)
3305 menu.Height = item.Height + y;
3312 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
3320 while (start < menu.MenuItems.Count) {
3323 for (i = start; i < menu.MenuItems.Count; i++) {
3324 MenuItem item = menu.MenuItems [i];
3326 if ((i != start) && (item.Break || item.BarBreak))
3329 CalcItemSize (dc, item, y, x, false);
3332 if (item.Width > max)
3336 // Replace the -1 by the menu width (separators)
3337 for (n = start; n < i; n++, start++)
3338 menu.MenuItems [n].Width = max;
3340 if (y > menu.Height)
3352 menu.Width += SM_CXBORDER;
3353 menu.Height += SM_CYBORDER;
3356 // Draws a menu bar in a window
3357 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
3359 if (menu.Height == 0)
3360 CalcMenuBarSize (dc, menu, rect.Width);
3362 bool keynav = (menu as MainMenu).tracker.hotkey_active;
3363 HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
3364 string_format_menu_menubar_text.HotkeyPrefix = hp;
3365 string_format_menu_text.HotkeyPrefix = hp;
3367 rect.Height = menu.Height;
3368 dc.FillRectangle (SystemBrushes.Menu, rect);
3370 for (int i = 0; i < menu.MenuItems.Count; i++) {
3371 MenuItem item = menu.MenuItems [i];
3372 Rectangle item_rect = item.bounds;
3373 item_rect.X += rect.X;
3374 item_rect.Y += rect.Y;
3375 item.MenuHeight = menu.Height;
3376 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
3380 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
3383 if (color.R == 0 && color.G == 0 && color.B == 0)
3384 bg_color = Color.White;
3386 bg_color = Color.Black;
3388 Bitmap bmp = new Bitmap (size.Width, size.Height);
3389 Graphics gr = Graphics.FromImage (bmp);
3390 Rectangle rect = new Rectangle (Point.Empty, size);
3391 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
3392 CPDrawMenuGlyph (gr, rect, glyph, color, Color.Empty);
3393 bmp.MakeTransparent (bg_color);
3399 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
3401 StringFormat string_format;
3402 Rectangle rect_text = e.Bounds;
3404 if (item.Visible == false)
3408 string_format = string_format_menu_menubar_text;
3410 string_format = string_format_menu_text;
3412 if (item.Separator == true) {
3413 int liney = e.Bounds.Y + (e.Bounds.Height / 2);
3415 e.Graphics.DrawLine (SystemPens.ControlDark,
3416 e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney);
3418 e.Graphics.DrawLine (SystemPens.ControlLight,
3419 e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1);
3425 rect_text.X += MenuCheckSize.Width;
3427 if (item.BarBreak) { /* Draw vertical break bar*/
3428 Rectangle rect = e.Bounds;
3431 rect.Height = item.MenuHeight - 6;
3433 e.Graphics.DrawLine (SystemPens.ControlDark,
3434 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
3436 e.Graphics.DrawLine (SystemPens.ControlLight,
3437 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
3442 Brush brush_text = null;
3443 Brush brush_back = null;
3445 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
3446 color_text = ColorHighlightText;
3447 color_back = ColorHighlight;
3448 brush_text = SystemBrushes.HighlightText;
3449 brush_back = SystemBrushes.Highlight;
3451 color_text = ColorMenuText;
3452 color_back = ColorMenu;
3453 brush_text = ResPool.GetSolidBrush (ColorMenuText);
3454 brush_back = SystemBrushes.Menu;
3457 /* Draw background */
3459 e.Graphics.FillRectangle (brush_back, e.Bounds);
3462 e.Graphics.DrawString (item.Text, e.Font,
3464 rect_text, string_format);
3467 Border3DStyle border_style = Border3DStyle.Adjust;
3468 if ((item.Status & DrawItemState.HotLight) != 0)
3469 border_style = Border3DStyle.RaisedInner;
3470 else if ((item.Status & DrawItemState.Selected) != 0)
3471 border_style = Border3DStyle.SunkenOuter;
3473 if (border_style != Border3DStyle.Adjust)
3474 CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
3477 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
3478 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
3479 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
3484 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
3487 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
3488 string str = item.GetShortCutText ();
3489 Rectangle rect = rect_text;
3491 rect.Width -= item.XTab;
3494 e.Graphics.DrawString (str, e.Font, brush_text, rect, string_format_menu_shortcut);
3496 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
3497 e.Graphics.DrawString (str, e.Font, Brushes.White,
3498 new RectangleF(rect.X + 1, rect.Y + 1, rect.Width, rect_text.Height),
3499 string_format_menu_shortcut);
3502 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect, string_format_menu_shortcut);
3507 if (item.MenuBar == false && (item.IsPopup || item.MdiList)) {
3509 int cx = MenuCheckSize.Width;
3510 int cy = MenuCheckSize.Height;
3511 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
3514 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
3515 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
3517 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
3518 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
3524 /* Draw checked or radio */
3525 if (item.MenuBar == false && item.Checked) {
3527 Rectangle area = e.Bounds;
3528 int cx = MenuCheckSize.Width;
3529 int cy = MenuCheckSize.Height;
3530 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
3532 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
3538 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
3540 // Fill rectangle area
3541 dc.FillRectangle (SystemBrushes.Menu, cliparea);
3543 // Draw menu borders
3544 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3547 for (int i = 0; i < menu.MenuItems.Count; i++) {
3548 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
3549 MenuItem item = menu.MenuItems [i];
3550 item.MenuHeight = menu.Height;
3551 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item.bounds, i, item.Status));
3558 #region MonthCalendar
3560 // draw the month calendar
3561 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
3563 Rectangle client_rectangle = mc.ClientRectangle;
3564 Size month_size = mc.SingleMonthSize;
3565 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
3566 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
3567 Size date_cell_size = (Size)((object)mc.date_cell_size);
3569 // draw the singlecalendars
3572 // adjust for the position of the specific month
3573 for (int i=0; i < mc.CalendarDimensions.Height; i++)
3577 y_offset += month_size.Height + calendar_spacing.Height;
3579 // now adjust for x position
3580 for (int j=0; j < mc.CalendarDimensions.Width; j++)
3584 x_offset += month_size.Width + calendar_spacing.Width;
3591 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
3592 if (month_rect.IntersectsWith (clip_rectangle)) {
3604 Rectangle bottom_rect = new Rectangle (
3606 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
3607 client_rectangle.Width,
3608 date_cell_size.Height + 2);
3609 // draw the today date if it's set
3610 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
3612 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
3614 int today_offset = 5;
3615 if (mc.ShowTodayCircle)
3617 Rectangle today_circle_rect = new Rectangle (
3618 client_rectangle.X + 5,
3619 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
3620 date_cell_size.Width,
3621 date_cell_size.Height);
3622 DrawTodayCircle (dc, today_circle_rect);
3623 today_offset += date_cell_size.Width + 5;
3625 // draw today's date
3626 StringFormat text_format = new StringFormat();
3627 text_format.LineAlignment = StringAlignment.Center;
3628 text_format.Alignment = StringAlignment.Near;
3629 Rectangle today_rect = new Rectangle (
3630 today_offset + client_rectangle.X,
3631 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
3632 Math.Max(client_rectangle.Width - today_offset, 0),
3633 date_cell_size.Height);
3634 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), mc.bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
3635 text_format.Dispose ();
3641 if (mc.owner == null)
3642 border_brush = GetControlBackBrush (mc.BackColor);
3644 border_brush = SystemBrushes.ControlDarkDark;
3646 // finally paint the borders of the calendars as required
3647 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
3648 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
3649 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
3650 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
3651 dc.FillRectangle (border_brush, client_rectangle.Right - 1, client_rectangle.Y, 1, client_rectangle.Height);
3653 Rectangle rect = new Rectangle (
3654 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
3656 calendar_spacing.Width,
3657 client_rectangle.Height);
3658 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
3659 dc.FillRectangle (border_brush, rect);
3663 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
3664 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
3665 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
3666 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
3667 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Bottom - 1, client_rectangle.Width, 1);
3669 Rectangle rect = new Rectangle (
3671 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
3672 client_rectangle.Width,
3673 calendar_spacing.Height);
3674 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
3675 dc.FillRectangle (border_brush, rect);
3680 // draw the drop down border if need
3681 if (mc.owner != null) {
3682 Rectangle bounds = mc.ClientRectangle;
3683 if (clip_rectangle.Contains (mc.Location)) {
3684 // find out if top or left line to draw
3685 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3687 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
3689 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3690 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
3693 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
3694 // find out if bottom or right line to draw
3695 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3696 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
3698 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3699 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
3705 // darws a single part of the month calendar (with one month)
3706 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
3708 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
3709 Size title_size = (Size)((object)mc.title_size);
3710 Size date_cell_size = (Size)((object)mc.date_cell_size);
3711 DateTime current_month = (DateTime)((object)mc.current_month);
3712 DateTime sunday = new DateTime(2006, 10, 1);
3714 // draw the title back ground
3715 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
3716 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
3717 if (title_rect.IntersectsWith (clip_rectangle)) {
3718 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
3720 string title_text = this_month.ToString ("MMMM yyyy");
3721 dc.DrawString (title_text, mc.bold_font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, mc.centered_format);
3723 if (mc.ShowYearUpDown) {
3724 Rectangle year_rect;
3725 Rectangle upRect, downRect;
3726 ButtonState upState, downState;
3728 mc.GetYearNameRectangles (title_rect, row * mc.CalendarDimensions.Width + col, out year_rect, out upRect, out downRect);
3729 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control), year_rect);
3730 dc.DrawString (this_month.ToString ("yyyy"), mc.bold_font, ResPool.GetSolidBrush (Color.Black), year_rect, mc.centered_format);
3732 upState = mc.IsYearGoingUp ? ButtonState.Pushed : ButtonState.Normal;
3733 downState = mc.IsYearGoingDown ? ButtonState.Pushed : ButtonState.Normal;
3735 ControlPaint.DrawScrollButton (dc, upRect, ScrollButton.Up, upState);
3736 ControlPaint.DrawScrollButton (dc, downRect, ScrollButton.Down, downState);
3739 // draw previous and next buttons if it's time
3740 if (row == 0 && col == 0)
3742 // draw previous button
3743 DrawMonthCalendarButton (
3749 (System.Drawing.Size)((object)mc.button_size),
3752 if (row == 0 && col == mc.CalendarDimensions.Width-1)
3755 DrawMonthCalendarButton (
3761 (System.Drawing.Size)((object)mc.button_size),
3766 // set the week offset and draw week nums if needed
3767 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
3768 Rectangle day_name_rect = new Rectangle(
3770 rectangle.Y + title_size.Height,
3771 (7 + col_offset) * date_cell_size.Width,
3772 date_cell_size.Height);
3773 if (day_name_rect.IntersectsWith (clip_rectangle)) {
3774 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
3775 // draw the day names
3776 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
3777 for (int i=0; i < 7; i++)
3779 int position = i - (int) first_day_of_week;
3782 position = 7 + position;
3785 Rectangle day_rect = new Rectangle(
3786 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
3788 date_cell_size.Width,
3789 date_cell_size.Height);
3790 dc.DrawString (sunday.AddDays (i + (int) first_day_of_week).ToString ("ddd"), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, mc.centered_format);
3793 // draw the vertical divider
3794 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
3796 ResPool.GetPen (mc.ForeColor),
3797 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
3798 rectangle.Y + vert_divider_y,
3799 rectangle.Right - mc.divider_line_offset,
3800 rectangle.Y + vert_divider_y);
3804 // draw the actual date items in the grid (including the week numbers)
3805 Rectangle date_rect = new Rectangle (
3807 rectangle.Y + title_size.Height + date_cell_size.Height,
3808 date_cell_size.Width,
3809 date_cell_size.Height);
3810 int month_row_count = 0;
3811 bool draw_week_num_divider = false;
3812 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
3813 for (int i=0; i < 6; i++)
3815 // establish if this row is in our clip_area
3816 Rectangle row_rect = new Rectangle (
3818 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
3819 date_cell_size.Width * 7,
3820 date_cell_size.Height);
3821 if (mc.ShowWeekNumbers) {
3822 row_rect.Width += date_cell_size.Width;
3825 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
3827 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
3829 // establish if this is a valid week to draw
3830 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
3831 month_row_count = i;
3834 // draw the week number if required
3835 if (mc.ShowWeekNumbers && month_row_count == i) {
3836 if (!draw_week_num_divider) {
3837 draw_week_num_divider = draw_row;
3839 // get the week for this row
3840 int week = mc.GetWeekOfYear (current_date);
3846 ResPool.GetSolidBrush (mc.TitleBackColor),
3848 mc.centered_format);
3850 date_rect.Offset(date_cell_size.Width, 0);
3853 // only draw the days if we have to
3854 if(month_row_count == i) {
3855 for (int j=0; j < 7; j++)
3858 DrawMonthCalendarDate (
3869 current_date = current_date.AddDays(1);
3870 date_rect.Offset(date_cell_size.Width, 0);
3873 // shift the rectangle down one row
3874 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
3875 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
3879 // month_row_count is zero based, so add one
3882 // draw week numbers if required
3883 if (draw_week_num_divider) {
3886 ResPool.GetPen (mc.ForeColor),
3887 rectangle.X + date_cell_size.Width - 1,
3888 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
3889 rectangle.X + date_cell_size.Width - 1,
3890 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
3894 // draws the pervious or next button
3895 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
3897 const int arrow_width = 4;
3898 const int arrow_height = 7;
3900 bool is_clicked = false;
3901 Rectangle button_rect;
3902 PointF arrow_center;
3903 PointF [] arrow_path = new PointF [3];
3905 // prepare the button
3908 is_clicked = mc.is_previous_clicked;
3910 button_rect = new Rectangle (
3911 rectangle.X + 1 + x_offset,
3912 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3913 Math.Max(button_size.Width - 1, 0),
3914 Math.Max(button_size.Height - 1, 0));
3916 arrow_center = new PointF (button_rect.X + ((button_rect.Width + arrow_width) / 2.0f),
3917 rectangle.Y + ((button_rect.Height + arrow_height) / 2) + 1);
3919 arrow_center.X += 1;
3920 arrow_center.Y += 1;
3923 arrow_path [0].X = arrow_center.X;
3924 arrow_path [0].Y = arrow_center.Y - arrow_height / 2.0f + 0.5f;
3925 arrow_path [1].X = arrow_center.X;
3926 arrow_path [1].Y = arrow_center.Y + arrow_height / 2.0f + 0.5f;
3927 arrow_path [2].X = arrow_center.X - arrow_width;
3928 arrow_path [2].Y = arrow_center.Y + 0.5f;
3932 is_clicked = mc.is_next_clicked;
3934 button_rect = new Rectangle (
3935 rectangle.Right - 1 - x_offset - button_size.Width,
3936 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3937 Math.Max(button_size.Width - 1, 0),
3938 Math.Max(button_size.Height - 1, 0));
3940 arrow_center = new PointF (button_rect.X + ((button_rect.Width + arrow_width) / 2.0f),
3941 rectangle.Y + ((button_rect.Height + arrow_height) / 2) + 1);
3943 arrow_center.X += 1;
3944 arrow_center.Y += 1;
3947 arrow_path [0].X = arrow_center.X - arrow_width;
3948 arrow_path [0].Y = arrow_center.Y - arrow_height / 2.0f + 0.5f;
3949 arrow_path [1].X = arrow_center.X - arrow_width;
3950 arrow_path [1].Y = arrow_center.Y + arrow_height / 2.0f + 0.5f;
3951 arrow_path [2].X = arrow_center.X;
3952 arrow_path [2].Y = arrow_center.Y + 0.5f;
3955 // fill the background
3956 dc.FillRectangle (SystemBrushes.Control, button_rect);
3959 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
3962 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3965 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
3966 //dc.FillPolygon (SystemBrushes.ControlText, arrow_path, FillMode.Winding);
3970 // draws one day in the calendar grid
3971 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
3972 Color date_color = mc.ForeColor;
3973 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
3975 // find out if we are the lead of the first calendar or the trail of the last calendar
3976 if (date.Year != month.Year || date.Month != month.Month) {
3977 DateTime check_date = month.AddMonths (-1);
3978 // check if it's the month before
3979 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
3980 date_color = mc.TrailingForeColor;
3982 // check if it's the month after
3983 check_date = month.AddMonths (1);
3984 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
3985 date_color = mc.TrailingForeColor;
3991 date_color = mc.ForeColor;
3994 const int inflate = -1;
3996 if (date == mc.SelectionStart.Date && date == mc.SelectionEnd.Date) {
3997 // see if the date is in the start of selection
3998 date_color = mc.BackColor;
3999 // draw the left hand of the back ground
4000 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4001 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360);
4002 } else if (date == mc.SelectionStart.Date) {
4003 // see if the date is in the start of selection
4004 date_color = mc.BackColor;
4005 // draw the left hand of the back ground
4006 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4007 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
4008 // fill the other side as a straight rect
4009 if (date < mc.SelectionEnd.Date)
4011 // use rectangle instead of rectangle to go all the way to edge of rect
4012 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
4013 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
4014 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4016 } else if (date == mc.SelectionEnd.Date) {
4017 // see if it is the end of selection
4018 date_color = mc.BackColor;
4019 // draw the left hand of the back ground
4020 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4021 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
4022 // fill the other side as a straight rect
4023 if (date > mc.SelectionStart.Date) {
4024 selection_rect.X = rectangle.X;
4025 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
4026 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4028 } else if (date > mc.SelectionStart.Date && date < mc.SelectionEnd.Date) {
4029 // now see if it's in the middle
4030 date_color = mc.BackColor;
4031 // draw the left hand of the back ground
4032 Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate);
4033 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4036 // establish if it's a bolded font
4037 Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font;
4039 // just draw the date now
4040 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format);
4042 // today circle if needed
4043 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
4044 DrawTodayCircle (dc, interior);
4047 // draw the selection grid
4048 if (mc.is_date_clicked && mc.clicked_date == date) {
4049 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
4050 dc.DrawRectangle (pen, interior);
4054 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
4055 Color circle_color = Color.FromArgb (248, 0, 0);
4056 // draw the left hand of the circle
4057 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
4058 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
4059 Point [] curve_points = new Point [3];
4060 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
4061 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
4062 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
4064 Pen pen = ResPool.GetSizedPen(circle_color, 2);
4065 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
4066 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
4067 dc.DrawCurve (pen, curve_points);
4068 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
4071 #endregion // MonthCalendar
4074 public override Size PanelDefaultSize {
4076 return new Size (200, 100);
4082 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
4083 Rectangle client = pb.ClientRectangle;
4085 client = new Rectangle (client.Left + pb.Padding.Left, client.Top + pb.Padding.Top, client.Width - pb.Padding.Horizontal, client.Height - pb.Padding.Vertical);
4087 // FIXME - instead of drawing the whole picturebox every time
4088 // intersect the clip rectangle with the drawn picture and only draw what's needed,
4089 // Also, we only need a background fill where no image goes
4090 if (pb.Image != null) {
4091 switch (pb.SizeMode) {
4092 case PictureBoxSizeMode.StretchImage:
4093 dc.DrawImage (pb.Image, client.Left, client.Top, client.Width, client.Height);
4096 case PictureBoxSizeMode.CenterImage:
4097 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
4100 case PictureBoxSizeMode.Zoom:
4103 if (((float)pb.Image.Width / (float)pb.Image.Height) >= ((float)client.Width / (float)client.Height))
4104 image_size = new Size (client.Width, (pb.Image.Height * client.Width) / pb.Image.Width);
4106 image_size = new Size ((pb.Image.Width * client.Height) / pb.Image.Height, client.Height);
4108 dc.DrawImage (pb.Image, (client.Width / 2) - (image_size.Width / 2), (client.Height / 2) - (image_size.Height / 2), image_size.Width, image_size.Height);
4113 dc.DrawImage (pb.Image, client.Left, client.Top, pb.Image.Width, pb.Image.Height);
4121 public override Size PictureBoxDefaultSize {
4123 return new Size (100, 50);
4126 #endregion // PictureBox
4128 #region PrintPreviewControl
4129 public override int PrintPreviewControlPadding {
4133 public override Size PrintPreviewControlGetPageSize (PrintPreviewControl preview)
4135 int page_width, page_height;
4136 int padding = PrintPreviewControlPadding;
4137 PreviewPageInfo[] pis = preview.page_infos;
4139 if (preview.AutoZoom) {
4140 int height_available = preview.ClientRectangle.Height - (preview.Rows) * padding - 2 * padding;
4141 int width_available = preview.ClientRectangle.Width - (preview.Columns - 1) * padding - 2 * padding;
4143 float image_ratio = (float)pis[0].Image.Width / pis[0].Image.Height;
4145 /* try to lay things out using the width to determine the size */
4146 page_width = width_available / preview.Columns;
4147 page_height = (int)(page_width / image_ratio);
4149 /* does the height fit? */
4150 if (page_height * (preview.Rows + 1) > height_available) {
4151 /* no, lay things out via the height */
4152 page_height = height_available / (preview.Rows + 1);
4153 page_width = (int)(page_height * image_ratio);
4157 page_width = (int)(pis[0].Image.Width * preview.Zoom);
4158 page_height = (int)(pis[0].Image.Height * preview.Zoom);
4161 return new Size (page_width, page_height);
4164 public override void PrintPreviewControlPaint (PaintEventArgs pe, PrintPreviewControl preview, Size page_size)
4167 PreviewPageInfo[] pis = preview.page_infos;
4173 int width = page_size.Width * preview.Columns + padding * (preview.Columns - 1) + 2 * padding;
4174 int height = page_size.Height * (preview.Rows + 1) + padding * preview.Rows + 2 * padding;
4176 Rectangle viewport = preview.ViewPort;
4178 pe.Graphics.Clip = new Region (viewport);
4180 /* center things if we can */
4181 int off_x = viewport.Width / 2 - width / 2;
4182 if (off_x < 0) off_x = 0;
4183 int off_y = viewport.Height / 2 - height / 2;
4184 if (off_y < 0) off_y = 0;
4186 page_y = off_y + padding - preview.vbar_value;
4188 if (preview.StartPage > 0) {
4189 int p = preview.StartPage - 1;
4190 for (int py = 0; py < preview.Rows + 1; py ++) {
4191 page_x = off_x + padding - preview.hbar_value;
4192 for (int px = 0; px < preview.Columns; px ++) {
4193 if (p >= pis.Length)
4195 Image image = preview.image_cache[p];
4197 image = pis[p].Image;
4198 Rectangle dest = new Rectangle (new Point (page_x, page_y), page_size);
4200 pe.Graphics.DrawImage (image, dest, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
4202 page_x += padding + page_size.Width;
4205 page_y += padding + page_size.Height;
4209 #endregion // PrintPreviewControl
4212 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
4214 Rectangle client_area = ctrl.client_area;
4217 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
4221 int max_blocks = int.MaxValue;
4222 int start_pixel = client_area.X;
4223 draw_mode = (int) ctrl.Style;
4225 switch (draw_mode) {
4226 case 1: { // Continuous
4228 pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max(ctrl.Maximum - ctrl.Minimum, 1))));
4229 dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
4233 if (XplatUI.ThemesEnabled) {
4234 int ms_diff = (int) (DateTime.Now - ctrl.start).TotalMilliseconds;
4235 double percent_done = (double) ms_diff / ProgressBarMarqueeSpeedScaling
4236 % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
4238 start_pixel = client_area.X + (int) (client_area.Width * percent_done);
4244 Rectangle block_rect;
4245 int space_betweenblocks = ProgressBarChunkSpacing;
4249 int block_count = 0;
4251 block_width = ProgressBarGetChunkSize (client_area.Height);
4252 block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
4253 barpos_pixels = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1)));
4254 increment = block_width + space_betweenblocks;
4256 block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
4258 if (max_blocks != int.MaxValue) {
4259 if (block_count >= max_blocks)
4261 if (block_rect.X > client_area.Width)
4262 block_rect.X -= client_area.Width;
4264 if ((block_rect.X - client_area.X) >= barpos_pixels)
4268 if (clip_rect.IntersectsWith (block_rect) == true) {
4269 dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), block_rect);
4272 block_rect.X += increment;
4280 public const int ProgressBarChunkSpacing = 2;
4282 public static int ProgressBarGetChunkSize ()
4284 return ProgressBarGetChunkSize (ProgressBarDefaultHeight);
4287 static int ProgressBarGetChunkSize (int progressBarClientAreaHeight)
4289 int size = (progressBarClientAreaHeight * 2) / 3;
4293 const int ProgressBarDefaultHeight = 23;
4295 public override Size ProgressBarDefaultSize {
4297 return new Size (100, ProgressBarDefaultHeight);
4301 public const double ProgressBarMarqueeSpeedScaling = 15;
4303 #endregion // ProgressBar
4306 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
4307 StringFormat text_format;
4308 Rectangle client_rectangle;
4309 Rectangle text_rectangle;
4310 Rectangle radiobutton_rectangle;
4311 int radiobutton_size = 13;
4312 int radiobutton_space = 4;
4314 client_rectangle = radio_button.ClientRectangle;
4315 text_rectangle = client_rectangle;
4316 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
4318 text_format = new StringFormat();
4319 text_format.Alignment = StringAlignment.Near;
4320 text_format.LineAlignment = StringAlignment.Center;
4321 text_format.HotkeyPrefix = HotkeyPrefix.Show;
4323 /* Calculate the position of text and checkbox rectangle */
4324 if (radio_button.appearance!=Appearance.Button) {
4325 switch(radio_button.radiobutton_alignment) {
4326 case ContentAlignment.BottomCenter: {
4327 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4328 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4329 text_rectangle.X=client_rectangle.X;
4330 text_rectangle.Width=client_rectangle.Width;
4331 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
4335 case ContentAlignment.BottomLeft: {
4336 radiobutton_rectangle.X=client_rectangle.Left;
4337 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4338 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4339 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4343 case ContentAlignment.BottomRight: {
4344 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4345 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4346 text_rectangle.X=client_rectangle.X;
4347 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4351 case ContentAlignment.MiddleCenter: {
4352 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4353 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4354 text_rectangle.X=client_rectangle.X;
4355 text_rectangle.Width=client_rectangle.Width;
4360 case ContentAlignment.MiddleLeft: {
4361 radiobutton_rectangle.X=client_rectangle.Left;
4362 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4363 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4364 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4368 case ContentAlignment.MiddleRight: {
4369 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4370 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4371 text_rectangle.X=client_rectangle.X;
4372 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4376 case ContentAlignment.TopCenter: {
4377 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4378 radiobutton_rectangle.Y=client_rectangle.Top;
4379 text_rectangle.X=client_rectangle.X;
4380 text_rectangle.Y=radiobutton_size+radiobutton_space;
4381 text_rectangle.Width=client_rectangle.Width;
4382 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
4386 case ContentAlignment.TopLeft: {
4387 radiobutton_rectangle.X=client_rectangle.Left;
4388 radiobutton_rectangle.Y=client_rectangle.Top;
4389 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4390 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4394 case ContentAlignment.TopRight: {
4395 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4396 radiobutton_rectangle.Y=client_rectangle.Top;
4397 text_rectangle.X=client_rectangle.X;
4398 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4403 text_rectangle.X=client_rectangle.X;
4404 text_rectangle.Width=client_rectangle.Width;
4407 /* Set the horizontal alignment of our text */
4408 switch(radio_button.text_alignment) {
4409 case ContentAlignment.BottomLeft:
4410 case ContentAlignment.MiddleLeft:
4411 case ContentAlignment.TopLeft: {
4412 text_format.Alignment=StringAlignment.Near;
4416 case ContentAlignment.BottomCenter:
4417 case ContentAlignment.MiddleCenter:
4418 case ContentAlignment.TopCenter: {
4419 text_format.Alignment=StringAlignment.Center;
4423 case ContentAlignment.BottomRight:
4424 case ContentAlignment.MiddleRight:
4425 case ContentAlignment.TopRight: {
4426 text_format.Alignment=StringAlignment.Far;
4431 /* Set the vertical alignment of our text */
4432 switch(radio_button.text_alignment) {
4433 case ContentAlignment.TopLeft:
4434 case ContentAlignment.TopCenter:
4435 case ContentAlignment.TopRight: {
4436 text_format.LineAlignment=StringAlignment.Near;
4440 case ContentAlignment.BottomLeft:
4441 case ContentAlignment.BottomCenter:
4442 case ContentAlignment.BottomRight: {
4443 text_format.LineAlignment=StringAlignment.Far;
4447 case ContentAlignment.MiddleLeft:
4448 case ContentAlignment.MiddleCenter:
4449 case ContentAlignment.MiddleRight: {
4450 text_format.LineAlignment=StringAlignment.Center;
4455 ButtonState state = ButtonState.Normal;
4456 if (radio_button.FlatStyle == FlatStyle.Flat) {
4457 state |= ButtonState.Flat;
4460 if (radio_button.Checked) {
4461 state |= ButtonState.Checked;
4464 if (!radio_button.Enabled) {
4465 state |= ButtonState.Inactive;
4469 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
4471 if ((radio_button.image != null) || (radio_button.image_list != null))
4472 ButtonBase_DrawImage(radio_button, dc);
4474 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
4476 if (radio_button.Focused && radio_button.Enabled && radio_button.appearance != Appearance.Button && radio_button.Text != String.Empty && radio_button.ShowFocusCues) {
4477 SizeF text_size = dc.MeasureString (radio_button.Text, radio_button.Font);
4479 Rectangle focus_rect = Rectangle.Empty;
4480 focus_rect.X = text_rectangle.X;
4481 focus_rect.Y = (int)((text_rectangle.Height - text_size.Height) / 2);
4482 focus_rect.Size = text_size.ToSize ();
4484 RadioButton_DrawFocus (radio_button, dc, focus_rect);
4487 text_format.Dispose ();
4490 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
4492 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
4494 if (radio_button.appearance==Appearance.Button) {
4495 ButtonBase_DrawButton (radio_button, dc);
4497 if ((radio_button.Focused) && radio_button.Enabled)
4498 ButtonBase_DrawFocus(radio_button, dc);
4500 // establish if we are rendering a flat style of some sort
4501 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
4502 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
4504 CPDrawRadioButton(dc, radiobutton_rectangle, state);
4509 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
4511 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
4512 text_format, radio_button.Appearance, radio_button.Checked);
4515 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
4517 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
4521 // renders a radio button with the Flat and Popup FlatStyle
4522 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
4526 if (radio_button.Enabled) {
4528 // draw the outer flatstyle arcs
4529 if (radio_button.FlatStyle == FlatStyle.Flat) {
4530 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
4532 // fill in the area depending on whether or not the mouse is hovering
4533 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
4534 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4536 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4539 // must be a popup radio button
4541 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
4543 if (radio_button.is_entered || radio_button.Capture) {
4544 // draw the popup 3d button knob
4545 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
4547 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
4548 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
4551 // just draw lighter flatstyle outer circle
4552 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
4557 // fill control background color regardless of actual backcolor
4558 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4559 // draw the ark as control dark
4560 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
4564 if (radio_button.Checked) {
4565 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
4567 Pen dot_pen = SystemPens.ControlDarkDark;
4568 Brush dot_brush = SystemBrushes.ControlDarkDark;
4570 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
4571 dot_pen = SystemPens.ControlDark;
4572 dot_brush = SystemBrushes.ControlDark;
4575 if (rectangle.Height > 13) {
4576 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
4578 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
4579 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
4581 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
4582 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
4584 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
4585 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
4590 public override Size RadioButtonDefaultSize {
4592 return new Size (104,24);
4596 public override void DrawRadioButton (Graphics g, RadioButton rb, Rectangle glyphArea, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
4598 // Draw Button Background
4599 if (rb.FlatStyle == FlatStyle.Flat || rb.FlatStyle == FlatStyle.Popup) {
4600 glyphArea.Height -= 2;
4601 glyphArea.Width -= 2;
4604 DrawRadioButtonGlyph (g, rb, glyphArea);
4606 // If we have an image, draw it
4607 if (imageBounds.Size != Size.Empty)
4608 DrawRadioButtonImage (g, rb, imageBounds);
4610 if (rb.Focused && rb.Enabled && rb.ShowFocusCues && textBounds.Size != Size.Empty)
4611 DrawRadioButtonFocus (g, rb, textBounds);
4613 // If we have text, draw it
4614 if (textBounds != Rectangle.Empty)
4615 DrawRadioButtonText (g, rb, textBounds);
4618 public virtual void DrawRadioButtonGlyph (Graphics g, RadioButton rb, Rectangle glyphArea)
4621 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Pressed, rb.FlatStyle, rb.Checked);
4622 else if (rb.InternalSelected)
4623 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Normal, rb.FlatStyle, rb.Checked);
4624 else if (rb.Entered)
4625 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Hot, rb.FlatStyle, rb.Checked);
4626 else if (!rb.Enabled)
4627 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Disabled, rb.FlatStyle, rb.Checked);
4629 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Normal, rb.FlatStyle, rb.Checked);
4632 public virtual void DrawRadioButtonFocus (Graphics g, RadioButton rb, Rectangle focusArea)
4634 ControlPaint.DrawFocusRectangle (g, focusArea);
4637 public virtual void DrawRadioButtonImage (Graphics g, RadioButton rb, Rectangle imageBounds)
4640 g.DrawImage (rb.Image, imageBounds);
4642 CPDrawImageDisabled (g, rb.Image, imageBounds.Left, imageBounds.Top, ColorControl);
4645 public virtual void DrawRadioButtonText (Graphics g, RadioButton rb, Rectangle textBounds)
4648 TextRenderer.DrawTextInternal (g, rb.Text, rb.Font, textBounds, rb.ForeColor, rb.TextFormatFlags, rb.UseCompatibleTextRendering);
4650 DrawStringDisabled20 (g, rb.Text, rb.Font, textBounds, rb.BackColor, rb.TextFormatFlags, rb.UseCompatibleTextRendering);
4653 public override Size CalculateRadioButtonAutoSize (RadioButton rb)
4655 Size ret_size = Size.Empty;
4656 Size text_size = TextRenderer.MeasureTextInternal (rb.Text, rb.Font, rb.UseCompatibleTextRendering);
4657 Size image_size = rb.Image == null ? Size.Empty : rb.Image.Size;
4659 // Pad the text size
4660 if (rb.Text.Length != 0) {
4661 text_size.Height += 4;
4662 text_size.Width += 4;
4665 switch (rb.TextImageRelation) {
4666 case TextImageRelation.Overlay:
4667 ret_size.Height = Math.Max (rb.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
4668 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
4670 case TextImageRelation.ImageAboveText:
4671 case TextImageRelation.TextAboveImage:
4672 ret_size.Height = text_size.Height + image_size.Height;
4673 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
4675 case TextImageRelation.ImageBeforeText:
4676 case TextImageRelation.TextBeforeImage:
4677 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
4678 ret_size.Width = text_size.Width + image_size.Width;
4683 ret_size.Height += (rb.Padding.Vertical);
4684 ret_size.Width += (rb.Padding.Horizontal) + 15;
4686 // There seems to be a minimum height
4687 if (ret_size.Height == rb.Padding.Vertical)
4688 ret_size.Height += 14;
4693 public override void CalculateRadioButtonTextAndImageLayout (ButtonBase b, Point offset, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
4695 CalculateCheckBoxTextAndImageLayout (b, offset, out glyphArea, out textRectangle, out imageRectangle);
4697 #endregion // RadioButton
4700 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
4702 int scrollbutton_width = bar.scrollbutton_width;
4703 int scrollbutton_height = bar.scrollbutton_height;
4704 Rectangle first_arrow_area;
4705 Rectangle second_arrow_area;
4706 Rectangle thumb_pos;
4708 thumb_pos = bar.ThumbPos;
4711 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
4712 bar.FirstArrowArea = first_arrow_area;
4714 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
4715 bar.SecondArrowArea = second_arrow_area;
4717 thumb_pos.Width = bar.Width;
4718 bar.ThumbPos = thumb_pos;
4720 Brush VerticalBrush;
4721 /* Background, upper track */
4722 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
4723 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4725 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4726 Rectangle UpperTrack = new Rectangle (0, 0, bar.ClientRectangle.Width, bar.ThumbPos.Bottom);
4727 if (clip.IntersectsWith (UpperTrack))
4728 dc.FillRectangle (VerticalBrush, UpperTrack);
4730 /* Background, lower track */
4731 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
4732 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4734 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4735 Rectangle LowerTrack = new Rectangle (0, bar.ThumbPos.Bottom, bar.ClientRectangle.Width, bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
4736 if (clip.IntersectsWith (LowerTrack))
4737 dc.FillRectangle (VerticalBrush, LowerTrack);
4740 if (clip.IntersectsWith (first_arrow_area))
4741 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
4742 if (clip.IntersectsWith (second_arrow_area))
4743 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
4745 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
4746 bar.FirstArrowArea = first_arrow_area;
4748 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
4749 bar.SecondArrowArea = second_arrow_area;
4751 thumb_pos.Height = bar.Height;
4752 bar.ThumbPos = thumb_pos;
4754 Brush HorizontalBrush;
4755 //Background, left track
4756 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
4757 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4759 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4760 Rectangle LeftTrack = new Rectangle (0, 0, bar.ThumbPos.Right, bar.ClientRectangle.Height);
4761 if (clip.IntersectsWith (LeftTrack))
4762 dc.FillRectangle (HorizontalBrush, LeftTrack);
4764 //Background, right track
4765 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
4766 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4768 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4769 Rectangle RightTrack = new Rectangle (bar.ThumbPos.Right, 0, bar.ClientRectangle.Width - bar.ThumbPos.Right, bar.ClientRectangle.Height);
4770 if (clip.IntersectsWith (RightTrack))
4771 dc.FillRectangle (HorizontalBrush, RightTrack);
4774 if (clip.IntersectsWith (first_arrow_area))
4775 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
4776 if (clip.IntersectsWith (second_arrow_area))
4777 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
4781 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
4784 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
4786 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
4787 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
4790 public override int ScrollBarButtonSize {
4794 public override bool ScrollBarHasHotElementStyles {
4800 public override bool ScrollBarHasPressedThumbStyle {
4806 public override bool ScrollBarHasHoverArrowButtonStyle {
4811 #endregion // ScrollBar
4814 public override void DrawStatusBar (Graphics real_dc, Rectangle clip, StatusBar sb) {
4815 Rectangle area = sb.ClientRectangle;
4816 int horz_border = 2;
4817 int vert_border = 2;
4819 Image backbuffer = new Bitmap (sb.ClientSize.Width, sb.ClientSize.Height, real_dc);
4820 Graphics dc = Graphics.FromImage (backbuffer);
4822 DrawStatusBarBackground (dc, clip, sb);
4824 if (!sb.ShowPanels && sb.Text != String.Empty) {
4825 string text = sb.Text;
4826 StringFormat string_format = new StringFormat ();
4827 string_format.Trimming = StringTrimming.Character;
4828 string_format.FormatFlags = StringFormatFlags.NoWrap;
4830 if (text.Length > 127)
4831 text = text.Substring (0, 127);
4833 if (text [0] == '\t') {
4834 string_format.Alignment = StringAlignment.Center;
4835 text = text.Substring (1);
4836 if (text [0] == '\t') {
4837 string_format.Alignment = StringAlignment.Far;
4838 text = text.Substring (1);
4842 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
4843 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
4844 string_format.Dispose ();
4845 } else if (sb.ShowPanels) {
4846 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
4847 int prev_x = area.X + horz_border;
4848 int y = area.Y + vert_border;
4849 for (int i = 0; i < sb.Panels.Count; i++) {
4850 Rectangle pr = new Rectangle (prev_x, y,
4851 sb.Panels [i].Width, area.Height);
4852 prev_x += pr.Width + StatusBarHorzGapWidth;
4853 if (pr.IntersectsWith (clip))
4854 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
4859 DrawStatusBarSizingGrip (dc, clip, sb, area);
4861 real_dc.DrawImage (backbuffer, 0, 0);
4863 backbuffer.Dispose ();
4867 protected virtual void DrawStatusBarBackground (Graphics dc, Rectangle clip, StatusBar sb)
4869 bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
4871 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
4872 dc.FillRectangle (brush, clip);
4875 protected virtual void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
4877 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
4878 CPDrawSizeGrip (dc, ColorControl, area);
4881 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
4882 Brush br_forecolor, StatusBarPanel panel) {
4883 int border_size = 3; // this is actually const, even if the border style is none
4884 int icon_width = 16;
4886 area.Height -= border_size;
4888 DrawStatusBarPanelBackground (dc, area, panel);
4890 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
4891 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
4892 dc, panel.Parent.Font, area, index, DrawItemState.Default,
4893 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
4894 panel.Parent.OnDrawItemInternal (e);
4898 string text = panel.Text;
4899 StringFormat string_format = new StringFormat ();
4900 string_format.Trimming = StringTrimming.Character;
4901 string_format.FormatFlags = StringFormatFlags.NoWrap;
4904 if (text != null && text.Length > 0 && text [0] == '\t') {
4905 string_format.Alignment = StringAlignment.Center;
4906 text = text.Substring (1);
4907 if (text [0] == '\t') {
4908 string_format.Alignment = StringAlignment.Far;
4909 text = text.Substring (1);
4913 Rectangle string_rect = Rectangle.Empty;
4917 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
4919 switch (panel.Alignment) {
4920 case HorizontalAlignment.Right:
4921 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4922 x = area.Right - len - 4;
4923 string_rect = new Rectangle (x, y,
4924 area.Right - x - border_size,
4925 area.Bottom - y - border_size);
4926 if (panel.Icon != null) {
4927 icon_x = x - icon_width - 2;
4930 case HorizontalAlignment.Center:
4931 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4932 x = area.Left + ((panel.Width - len) / 2);
4934 string_rect = new Rectangle (x, y,
4935 area.Right - x - border_size,
4936 area.Bottom - y - border_size);
4938 if (panel.Icon != null) {
4939 icon_x = x - icon_width - 2;
4945 int left = area.Left + border_size;;
4946 if (panel.Icon != null) {
4947 icon_x = area.Left + 2;
4948 left = icon_x + icon_width + 2;
4952 string_rect = new Rectangle (x, y,
4953 area.Right - x - border_size,
4954 area.Bottom - y - border_size);
4958 RectangleF clip_bounds = dc.ClipBounds;
4960 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
4961 dc.SetClip (clip_bounds);
4963 if (panel.Icon != null) {
4964 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
4968 protected virtual void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
4970 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
4971 Border3DStyle border_style = Border3DStyle.SunkenOuter;
4972 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
4973 border_style = Border3DStyle.RaisedInner;
4975 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
4979 public override int StatusBarSizeGripWidth {
4983 public override int StatusBarHorzGapWidth {
4987 public override Size StatusBarDefaultSize {
4989 return new Size (100, 22);
4992 #endregion // StatusBar
4996 #region TabControl settings
4998 public override Size TabControlDefaultItemSize {
4999 get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultItemSize; }
5002 public override Point TabControlDefaultPadding {
5003 get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultPadding; }
5006 public override int TabControlMinimumTabWidth {
5007 get { return ThemeElements.CurrentTheme.TabControlPainter.MinimumTabWidth; }
5010 public override Rectangle TabControlSelectedDelta {
5011 get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedTabDelta; }
5014 public override int TabControlSelectedSpacing {
5015 get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedSpacing; }
5018 public override int TabPanelOffsetX {
5019 get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.X; }
5022 public override int TabPanelOffsetY {
5023 get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.Y; }
5026 public override int TabControlColSpacing {
5027 get { return ThemeElements.CurrentTheme.TabControlPainter.ColSpacing; }
5030 public override Point TabControlImagePadding {
5031 get { return ThemeElements.CurrentTheme.TabControlPainter.ImagePadding; }
5034 public override int TabControlScrollerWidth {
5035 get {return ThemeElements.CurrentTheme.TabControlPainter.ScrollerWidth; }
5039 public override Size TabControlGetSpacing (TabControl tab)
5042 return ThemeElements.CurrentTheme.TabControlPainter.RowSpacing (tab);
5044 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
5049 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
5051 ThemeElements.CurrentTheme.TabControlPainter.Draw (dc, area, tab);
5054 public override Rectangle TabControlGetDisplayRectangle (TabControl tab)
5056 return ThemeElements.CurrentTheme.TabControlPainter.GetDisplayRectangle (tab);
5059 public override Rectangle TabControlGetPanelRect (TabControl tab)
5061 return ThemeElements.CurrentTheme.TabControlPainter.GetTabPanelRect (tab);
5067 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
5069 if (textBoxBase.backcolor_set || (textBoxBase.Enabled && !textBoxBase.read_only)) {
5070 g.FillRectangle(ResPool.GetSolidBrush(textBoxBase.BackColor), clippingArea);
5072 g.FillRectangle(ResPool.GetSolidBrush(ColorControl), clippingArea);
5076 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
5081 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
5088 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
5090 StringFormat format = new StringFormat ();
5091 format.Trimming = StringTrimming.EllipsisCharacter;
5092 format.LineAlignment = StringAlignment.Center;
5093 if (control.ShowKeyboardCuesInternal)
5094 format.HotkeyPrefix = HotkeyPrefix.Show;
5096 format.HotkeyPrefix = HotkeyPrefix.Hide;
5098 if (control.TextAlign == ToolBarTextAlign.Underneath)
5099 format.Alignment = StringAlignment.Center;
5101 format.Alignment = StringAlignment.Near;
5103 if (control.Appearance != ToolBarAppearance.Flat || control.Parent == null) {
5104 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
5107 if (control.Divider && clip_rectangle.Y < 2) {
5108 if (clip_rectangle.Y < 1) {
5109 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
5111 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
5114 foreach (ToolBarItem item in control.items)
5115 if (item.Button.Visible && clip_rectangle.IntersectsWith (item.Rectangle))
5116 DrawToolBarButton (dc, control, item, format);
5121 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
5123 bool is_flat = (control.Appearance == ToolBarAppearance.Flat);
5125 DrawToolBarButtonBorder (dc, item, is_flat);
5127 switch (item.Button.Style) {
5128 case ToolBarButtonStyle.DropDownButton:
5129 if (control.DropDownArrows)
5130 DrawToolBarDropDownArrow (dc, item, is_flat);
5131 DrawToolBarButtonContents (dc, control, item, format);
5134 case ToolBarButtonStyle.Separator:
5136 DrawToolBarSeparator (dc, item);
5139 case ToolBarButtonStyle.ToggleButton:
5140 DrawToolBarToggleButtonBackground (dc, item);
5141 DrawToolBarButtonContents (dc, control, item, format);
5145 DrawToolBarButtonContents (dc, control, item, format);
5150 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
5152 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
5154 if (item.Button.Style == ToolBarButtonStyle.Separator)
5157 Border3DStyle style;
5160 if (item.Button.Pushed || item.Pressed)
5161 style = Border3DStyle.SunkenOuter;
5162 else if (item.Hilight)
5163 style = Border3DStyle.RaisedInner;
5168 if (item.Button.Pushed || item.Pressed)
5169 style = Border3DStyle.Sunken;
5171 style = Border3DStyle.Raised;
5174 Rectangle rect = item.Rectangle;
5175 if ((item.Button.Style == ToolBarButtonStyle.DropDownButton) && (item.Button.Parent.DropDownArrows) && is_flat)
5176 rect.Width -= ToolBarDropDownWidth;
5178 CPDrawBorder3D (dc, rect, style, all_sides);
5181 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
5183 Rectangle area = item.Rectangle;
5184 int offset = (int) SystemPens.Control.Width + 1;
5185 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
5186 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
5189 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
5192 Rectangle area = item.Rectangle;
5193 area.X += ToolBarImageGripWidth;
5194 area.Y += ToolBarImageGripWidth;
5195 area.Width -= 2 * ToolBarImageGripWidth;
5196 area.Height -= 2 * ToolBarImageGripWidth;
5198 if (item.Button.Pushed)
5199 brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight);
5200 else if (item.Button.PartialPush)
5201 brush = SystemBrushes.ControlLight;
5203 brush = SystemBrushes.Control;
5205 dc.FillRectangle (brush, area);
5208 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
5210 Rectangle rect = item.Rectangle;
5211 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
5212 rect.Width = ToolBarDropDownWidth;
5216 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
5217 else if (item.Button.Pushed || item.Pressed)
5218 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
5219 else if (item.Hilight)
5220 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides);
5223 CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides);
5224 else if (item.Button.Pushed || item.Pressed)
5225 CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides);
5227 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
5230 PointF [] vertices = new PointF [3];
5231 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2));
5233 // Increase vertical and horizontal position by 1 when button is pressed
5234 if (item.Pressed || item.Button.Pushed || item.DDPressed) {
5239 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
5240 vertices [0].Y = ddCenter.Y;
5241 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
5242 vertices [1].Y = ddCenter.Y;
5243 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
5244 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
5245 dc.FillPolygon (SystemBrushes.ControlText, vertices);
5248 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
5250 if (item.Button.Image != null) {
5251 int x = item.ImageRectangle.X + ToolBarImageGripWidth;
5252 int y = item.ImageRectangle.Y + ToolBarImageGripWidth;
5254 // Increase vertical and horizontal position by 1 when button is pressed
5255 if (item.Pressed || item.Button.Pushed) {
5260 if (item.Button.Enabled)
5261 dc.DrawImage (item.Button.Image, x, y);
5263 CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl);
5266 Rectangle text_rect = item.TextRectangle;
5267 if (text_rect.Width <= 0 || text_rect.Height <= 0)
5270 if (item.Pressed || item.Button.Pushed) {
5275 if (item.Button.Enabled)
5276 dc.DrawString (item.Button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
5278 CPDrawStringDisabled (dc, item.Button.Text, control.Font, control.BackColor, text_rect, format);
5281 // Grip width for the ToolBar
5282 public override int ToolBarGripWidth {
5286 // Grip width for the Image on the ToolBarButton
5287 public override int ToolBarImageGripWidth {
5291 // width of the separator
5292 public override int ToolBarSeparatorWidth {
5296 // width of the dropdown arrow rect
5297 public override int ToolBarDropDownWidth {
5301 // width for the dropdown arrow on the ToolBarButton
5302 public override int ToolBarDropDownArrowWidth {
5306 // height for the dropdown arrow on the ToolBarButton
5307 public override int ToolBarDropDownArrowHeight {
5311 public override Size ToolBarDefaultSize {
5313 return new Size (100, 42);
5317 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
5319 return toolBar.Appearance == ToolBarAppearance.Flat;
5322 public override bool ToolBarHasHotCheckedElementStyles {
5327 #endregion // ToolBar
5330 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
5332 ToolTipDrawBackground (dc, clip_rectangle, control);
5334 TextFormatFlags flags = TextFormatFlags.HidePrefix;
5336 Color foreground = control.ForeColor;
5337 if (control.title.Length > 0) {
5338 Font bold_font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
5339 TextRenderer.DrawTextInternal (dc, control.title, bold_font, control.title_rect,
5340 foreground, flags, false);
5341 bold_font.Dispose ();
5344 if (control.icon != null)
5345 dc.DrawIcon (control.icon, control.icon_rect);
5347 TextRenderer.DrawTextInternal (dc, control.Text, control.Font, control.text_rect, foreground, flags, false);
5350 protected virtual void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
5352 Brush back_brush = ResPool.GetSolidBrush (control.BackColor);
5353 dc.FillRectangle (back_brush, control.ClientRectangle);
5354 dc.DrawRectangle (SystemPens.WindowFrame, 0, 0, control.Width - 1, control.Height - 1);
5357 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text)
5359 Size size = TextRenderer.MeasureTextInternal (text, tt.Font, false);
5362 Rectangle text_rect = new Rectangle (Point.Empty, size);
5363 text_rect.Inflate (-2, -1);
5364 tt.text_rect = text_rect;
5365 tt.icon_rect = tt.title_rect = Rectangle.Empty;
5367 Size title_size = Size.Empty;
5368 if (tt.title.Length > 0) {
5369 Font bold_font = new Font (tt.Font, tt.Font.Style | FontStyle.Bold);
5370 title_size = TextRenderer.MeasureTextInternal (tt.title, bold_font, false);
5371 bold_font.Dispose ();
5374 Size icon_size = Size.Empty;
5375 if (tt.icon != null)
5376 icon_size = new Size (size.Height, size.Height);
5378 if (icon_size != Size.Empty || title_size != Size.Empty) {
5380 int top_area_width = 0;
5381 int top_area_height = icon_size.Height > title_size.Height ? icon_size.Height : title_size.Height;
5382 Size text_size = size;
5383 Point location = new Point (padding, padding);
5385 if (icon_size != Size.Empty) {
5386 tt.icon_rect = new Rectangle (location, icon_size);
5387 top_area_width = icon_size.Width + padding;
5390 if (title_size != Size.Empty) {
5391 Rectangle title_rect = new Rectangle (location, new Size (title_size.Width, top_area_height));
5392 if (icon_size != Size.Empty)
5393 title_rect.X += icon_size.Width + padding;
5395 tt.title_rect = title_rect;
5396 top_area_width += title_size.Width;
5399 tt.text_rect = new Rectangle (new Point (location.X, location.Y + top_area_height + padding),
5402 size.Height += padding + top_area_height;
5403 if (top_area_width > size.Width)
5404 size.Width = top_area_width;
5407 size.Width += padding * 2;
5408 size.Height += padding * 2;
5414 public override bool ToolTipTransparentBackground {
5419 #endregion // ToolTip
5421 #region BalloonWindow
5422 NotifyIcon.BalloonWindow balloon_window;
5424 public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
5426 Control control = Control.FromHandle(handle);
5428 if (control == null)
5431 if (balloon_window != null) {
5432 balloon_window.Close ();
5433 balloon_window.Dispose ();
5436 balloon_window = new NotifyIcon.BalloonWindow (handle);
5437 balloon_window.Title = title;
5438 balloon_window.Text = text;
5439 balloon_window.Icon = icon;
5440 balloon_window.Timeout = timeout;
5441 balloon_window.Show ();
5444 public override void HideBalloonWindow (IntPtr handle)
5446 if (balloon_window == null || balloon_window.OwnerHandle != handle)
5449 balloon_window.Close ();
5450 balloon_window.Dispose ();
5451 balloon_window = null;
5454 private const int balloon_iconsize = 16;
5455 private const int balloon_bordersize = 8;
5457 public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control)
5459 Brush solidbrush = ResPool.GetSolidBrush (this.ColorInfoText);
5460 Rectangle rect = control.ClientRectangle;
5461 int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
5463 // Rectangle borders and background.
5464 dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
5465 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), 0, 0, rect.Width - 1, rect.Height - 1);
5469 switch (control.Icon) {
5470 case ToolTipIcon.Info: {
5471 image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
5475 case ToolTipIcon.Warning: {
5476 image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
5480 case ToolTipIcon.Error: {
5481 image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
5491 if (control.Icon != ToolTipIcon.None)
5492 dc.DrawImage (image, new Rectangle (balloon_bordersize, balloon_bordersize, iconsize, iconsize));
5495 Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + iconsize + (iconsize > 0 ? balloon_bordersize : 0),
5496 rect.Y + balloon_bordersize,
5497 rect.Width - ((3 * balloon_bordersize) + iconsize),
5498 rect.Height - (2 * balloon_bordersize));
5500 Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
5501 dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
5504 Rectangle textrect = new Rectangle (rect.X + balloon_bordersize,
5505 rect.Y + balloon_bordersize,
5506 rect.Width - (2 * balloon_bordersize),
5507 rect.Height - (2 * balloon_bordersize));
5509 StringFormat textformat = control.Format;
5510 textformat.LineAlignment = StringAlignment.Far;
5511 dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
5514 public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
5516 Rectangle deskrect = Screen.GetWorkingArea (control);
5517 SizeF maxsize = new SizeF (250, 200);
5519 SizeF titlesize = TextRenderer.MeasureString (control.Title, control.Font, maxsize, control.Format);
5520 SizeF textsize = TextRenderer.MeasureString (control.Text, control.Font, maxsize, control.Format);
5522 if (titlesize.Height < balloon_iconsize)
5523 titlesize.Height = balloon_iconsize;
5525 Rectangle rect = new Rectangle ();
5526 rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
5527 rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (2 * balloon_bordersize);
5528 rect.X = deskrect.Width - rect.Width - 2;
5529 rect.Y = deskrect.Height - rect.Height - 2;
5533 #endregion // BalloonWindow
5536 public override int TrackBarValueFromMousePosition (int x, int y, TrackBar tb)
5538 int result = tb.Value;
5539 int value_pos = tb.Value;
5540 float pixels_betweenticks;
5541 Rectangle thumb_pos = Rectangle.Empty, thumb_area = Rectangle.Empty;
5542 Point channel_startpoint = Point.Empty, na_point = Point.Empty;
5544 GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out na_point, out na_point);
5546 /* Convert thumb position from mouse position to value*/
5547 if (tb.Orientation == Orientation.Vertical) {
5548 value_pos = (int)Math.Round (((thumb_area.Bottom - y - (float)thumb_pos.Height / 2) / (float)pixels_betweenticks), 0);
5550 if (value_pos + tb.Minimum > tb.Maximum)
5551 value_pos = tb.Maximum - tb.Minimum;
5552 else if (value_pos + tb.Minimum < tb.Minimum)
5555 result = value_pos + tb.Minimum;
5557 value_pos = (int)Math.Round (((x - channel_startpoint.X - (float)thumb_pos.Width / 2) / (float) pixels_betweenticks), 0);
5559 if (value_pos + tb.Minimum > tb.Maximum)
5560 value_pos = tb.Maximum - tb.Minimum;
5561 else if (value_pos + tb.Minimum < tb.Minimum)
5564 result = value_pos + tb.Minimum;
5570 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)
5572 thumb_area = Rectangle.Empty;
5573 thumb_pos = Rectangle.Empty;
5575 if (tb.Orientation == Orientation.Vertical) {
5576 toptick_startpoint = new Point ();
5577 bottomtick_startpoint = new Point ();
5578 channel_startpoint = new Point ();
5580 const int space_from_right = 8;
5581 const int space_from_left = 8;
5582 const int space_from_bottom = 11;
5583 Rectangle area = tb.ClientRectangle;
5585 switch (tb.TickStyle) {
5586 case TickStyle.BottomRight:
5587 case TickStyle.None:
5588 channel_startpoint.Y = 8;
5589 channel_startpoint.X = 9;
5590 bottomtick_startpoint.Y = 13;
5591 bottomtick_startpoint.X = 24;
5593 case TickStyle.TopLeft:
5594 channel_startpoint.Y = 8;
5595 channel_startpoint.X = 19;
5596 toptick_startpoint.Y = 13;
5597 toptick_startpoint.X = 8;
5599 case TickStyle.Both:
5600 channel_startpoint.Y = 8;
5601 channel_startpoint.X = 18;
5602 bottomtick_startpoint.Y = 13;
5603 bottomtick_startpoint.X = 32;
5604 toptick_startpoint.Y = 13;
5605 toptick_startpoint.X = 8;
5611 thumb_area.X = area.X + channel_startpoint.X;
5612 thumb_area.Y = area.Y + channel_startpoint.Y;
5613 thumb_area.Height = area.Height - space_from_right - space_from_left;
5614 thumb_area.Width = TrackBarVerticalTrackWidth;
5616 pixel_len = thumb_area.Height - 11;
5617 if (tb.Maximum == tb.Minimum) {
5618 pixels_betweenticks = 0;
5620 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
5623 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int)(pixels_betweenticks * (float)(tb.Value - tb.Minimum));
5625 toptick_startpoint = new Point ();
5626 bottomtick_startpoint = new Point ();
5627 channel_startpoint = new Point ();
5629 const int space_from_right = 8;
5630 const int space_from_left = 8;
5631 Rectangle area = tb.ClientRectangle;
5633 switch (tb.TickStyle) {
5634 case TickStyle.BottomRight:
5635 case TickStyle.None:
5636 channel_startpoint.X = 8;
5637 channel_startpoint.Y = 9;
5638 bottomtick_startpoint.X = 13;
5639 bottomtick_startpoint.Y = 24;
5641 case TickStyle.TopLeft:
5642 channel_startpoint.X = 8;
5643 channel_startpoint.Y = 19;
5644 toptick_startpoint.X = 13;
5645 toptick_startpoint.Y = 8;
5647 case TickStyle.Both:
5648 channel_startpoint.X = 8;
5649 channel_startpoint.Y = 18;
5650 bottomtick_startpoint.X = 13;
5651 bottomtick_startpoint.Y = 32;
5652 toptick_startpoint.X = 13;
5653 toptick_startpoint.Y = 8;
5659 thumb_area.X = area.X + channel_startpoint.X;
5660 thumb_area.Y = area.Y + channel_startpoint.Y;
5661 thumb_area.Width = area.Width - space_from_right - space_from_left;
5662 thumb_area.Height = TrackBarHorizontalTrackHeight;
5664 pixel_len = thumb_area.Width - 11;
5665 if (tb.Maximum == tb.Minimum) {
5666 pixels_betweenticks = 0;
5668 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
5671 thumb_pos.X = channel_startpoint.X + (int)(pixels_betweenticks * (float) (tb.Value - tb.Minimum));
5674 thumb_pos.Size = TrackBarGetThumbSize (tb);
5677 protected virtual Size TrackBarGetThumbSize (TrackBar trackBar)
5679 return TrackBarGetThumbSize ();
5682 public static Size TrackBarGetThumbSize ()
5684 /* Draw thumb fixed 10x22 size */
5685 return new Size (10, 22);
5688 public const int TrackBarVerticalTrackWidth = 4;
5690 public const int TrackBarHorizontalTrackHeight = 4;
5693 protected interface ITrackBarTickPainter
5695 void Paint (float x1, float y1, float x2, float y2);
5698 class TrackBarTickPainter : ITrackBarTickPainter
5700 readonly Graphics g;
5702 public TrackBarTickPainter (Graphics g, Pen pen)
5707 public void Paint (float x1, float y1, float x2, float y2)
5709 g.DrawLine (pen, x1, y1, x2, y2);
5712 protected virtual ITrackBarTickPainter GetTrackBarTickPainter (Graphics g)
5714 return new TrackBarTickPainter (g, ResPool.GetPen (pen_ticks_color));
5718 #region DrawTrackBar_Vertical
5719 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
5720 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
5721 float ticks, int value_pos, bool mouse_value) {
5723 Point toptick_startpoint = new Point ();
5724 Point bottomtick_startpoint = new Point ();
5725 Point channel_startpoint = new Point ();
5727 float pixels_betweenticks;
5728 Rectangle area = tb.ClientRectangle;
5730 GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
5733 TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clip_rectangle);
5737 switch (tb.TickStyle) {
5738 case TickStyle.BottomRight:
5739 case TickStyle.None:
5740 thumb_pos.X = channel_startpoint.X - 8;
5741 TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5743 case TickStyle.TopLeft:
5744 thumb_pos.X = channel_startpoint.X - 10;
5745 TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5748 thumb_pos.X = area.X + 10;
5749 TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5754 pixel_len = thumb_area.Height - 11;
5755 pixels_betweenticks = pixel_len / ticks;
5757 thumb_area.X = thumb_pos.X;
5758 thumb_area.Y = channel_startpoint.Y;
5759 thumb_area.Width = thumb_pos.Height;
5762 if (pixels_betweenticks <= 0)
5764 if (tb.TickStyle == TickStyle.None)
5766 Region outside = new Region (area);
5767 outside.Exclude (thumb_area);
5769 if (outside.IsVisible (clip_rectangle)) {
5770 ITrackBarTickPainter tick_painter = TrackBarGetVerticalTickPainter (dc);
5772 if ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight) {
5773 float x = area.X + bottomtick_startpoint.X;
5774 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5775 float y = area.Y + bottomtick_startpoint.Y + inc;
5776 tick_painter.Paint (
5778 x + (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2), y);
5782 if ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft) {
5783 float x = area.X + toptick_startpoint.X;
5784 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
5785 float y = area.Y + toptick_startpoint.Y + inc;
5786 tick_painter.Paint (
5787 x - (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2), y,
5798 protected virtual void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
5800 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
5801 1, thumb_area.Height);
5803 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
5804 1, thumb_area.Height);
5806 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
5807 1, thumb_area.Height);
5812 protected virtual void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5814 Pen pen = SystemPens.ControlLightLight;
5815 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 10);
5816 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
5817 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
5819 pen = SystemPens.ControlDark;
5820 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X + 15, thumb_pos.Y + 9);
5821 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X + 16 + 4, thumb_pos.Y + 9 - 4);
5823 pen = SystemPens.ControlDarkDark;
5824 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X + 16, thumb_pos.Y + 10);
5825 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X + 16 + 5, thumb_pos.Y + 10 - 5);
5827 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
5828 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
5829 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
5830 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
5833 protected virtual void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5835 Pen pen = SystemPens.ControlLightLight;
5836 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
5837 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
5839 pen = SystemPens.ControlDark;
5840 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16, thumb_pos.Y + 9);
5841 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
5842 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X + 19, thumb_pos.Y + 1);
5844 pen = SystemPens.ControlDarkDark;
5845 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X + 4 + 16, thumb_pos.Y + 10);
5846 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X - 1, thumb_pos.Y + 5);
5847 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y + 10);
5849 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
5850 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
5851 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
5852 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
5855 protected virtual void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5857 Pen pen = SystemPens.ControlLightLight;
5858 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
5859 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
5861 pen = SystemPens.ControlDark;
5862 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X + 19, thumb_pos.Y + 9);
5863 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 1, thumb_pos.X + 19, thumb_pos.Y + 8);
5865 pen = SystemPens.ControlDarkDark;
5866 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X + 20, thumb_pos.Y + 10);
5867 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y + 9);
5869 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
5874 protected virtual ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
5876 return GetTrackBarTickPainter (g);
5881 #region DrawTrackBar_Horizontal
5885 Does not matter the size of the control, Win32 always draws:
5886 - Ticks starting from pixel 13, 8
5887 - Channel starting at pos 8, 19 and ends at Width - 8
5888 - Autosize makes always the control 45 pixels high
5889 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
5892 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
5893 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
5894 float ticks, int value_pos, bool mouse_value) {
5895 Point toptick_startpoint = new Point ();
5896 Point bottomtick_startpoint = new Point ();
5897 Point channel_startpoint = new Point ();
5899 float pixels_betweenticks;
5900 Rectangle area = tb.ClientRectangle;
5902 GetTrackBarDrawingInfo (tb , out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
5905 TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clip_rectangle);
5909 switch (tb.TickStyle) {
5910 case TickStyle.BottomRight:
5911 case TickStyle.None:
5912 thumb_pos.Y = channel_startpoint.Y - 8;
5913 TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5915 case TickStyle.TopLeft:
5916 thumb_pos.Y = channel_startpoint.Y - 10;
5917 TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5920 thumb_pos.Y = area.Y + 10;
5921 TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5926 pixel_len = thumb_area.Width - 11;
5927 pixels_betweenticks = pixel_len / ticks;
5929 thumb_area.Y = thumb_pos.Y;
5930 thumb_area.X = channel_startpoint.X;
5931 thumb_area.Height = thumb_pos.Height;
5933 if (pixels_betweenticks <= 0)
5935 if (tb.TickStyle == TickStyle.None)
5937 Region outside = new Region (area);
5938 outside.Exclude (thumb_area);
5940 if (outside.IsVisible (clip_rectangle)) {
5941 ITrackBarTickPainter tick_painter = TrackBarGetHorizontalTickPainter (dc);
5943 if ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight) {
5944 float y = area.Y + bottomtick_startpoint.Y;
5945 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5946 float x = area.X + bottomtick_startpoint.X + inc;
5947 tick_painter.Paint (
5949 x, y + (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2));
5953 if ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft) {
5954 float y = area.Y + toptick_startpoint.Y;
5955 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5956 float x = area.X + toptick_startpoint.X + inc;
5957 tick_painter.Paint (
5958 x, y - (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1 ? 3 : 2),
5969 protected virtual void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
5971 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
5972 thumb_area.Width, 1);
5974 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
5975 thumb_area.Width, 1);
5977 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y + 3,
5978 thumb_area.Width, 1);
5983 protected virtual void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5985 Pen pen = SystemPens.ControlLightLight;
5986 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
5987 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
5988 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
5990 pen = SystemPens.ControlDark;
5991 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 15);
5992 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X + 9 - 4, thumb_pos.Y + 16 + 4);
5994 pen = SystemPens.ControlDarkDark;
5995 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y + 16);
5996 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X + 10 - 5, thumb_pos.Y + 16 + 5);
5998 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
5999 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
6000 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
6001 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
6004 protected virtual void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
6006 Pen pen = SystemPens.ControlLightLight;
6007 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
6008 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
6010 pen = SystemPens.ControlDark;
6011 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
6012 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
6013 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1, thumb_pos.Y + 19);
6015 pen = SystemPens.ControlDarkDark;
6016 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
6017 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y - 1);
6018 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
6020 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
6021 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
6022 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
6023 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
6026 protected virtual void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
6028 Pen pen = SystemPens.ControlLightLight;
6029 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
6030 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
6032 pen = SystemPens.ControlDark;
6033 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
6034 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
6036 pen = SystemPens.ControlDarkDark;
6037 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y + 20);
6038 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
6040 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
6045 protected virtual ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
6047 return GetTrackBarTickPainter (g);
6052 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
6057 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
6059 Rectangle thumb_pos = tb.ThumbPos;
6060 Rectangle thumb_area = tb.ThumbArea;
6062 if (tb.thumb_pressed) {
6063 value_pos = tb.thumb_mouseclick;
6066 value_pos = tb.Value - tb.Minimum;
6067 mouse_value = false;
6070 area = tb.ClientRectangle;
6073 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
6074 } else if (tb.thumb_pressed == true) {
6075 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
6077 br_thumb = SystemBrushes.Control;
6081 /* Control Background */
6082 if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
6083 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
6085 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
6089 CPDrawFocusRectangle(dc, area, tb.ForeColor, tb.BackColor);
6092 if (tb.Orientation == Orientation.Vertical) {
6093 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
6094 br_thumb, ticks, value_pos, mouse_value);
6097 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
6098 br_thumb, ticks, value_pos, mouse_value);
6101 tb.ThumbPos = thumb_pos;
6102 tb.ThumbArea = thumb_area;
6105 public override Size TrackBarDefaultSize {
6107 return new Size (104, 42);
6111 public override bool TrackBarHasHotThumbStyle {
6116 #endregion // TrackBar
6119 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, VisualStyles.PushButtonState state)
6121 ControlPaint.DrawScrollButton (g, bounds, top ? ScrollButton.Up : ScrollButton.Down, state == VisualStyles.PushButtonState.Pressed ? ButtonState.Pushed : ButtonState.Normal);
6124 public override bool UpDownBaseHasHotButtonStyle {
6132 public override Size VScrollBarDefaultSize {
6134 return new Size (this.ScrollBarButtonSize, 80);
6137 #endregion // VScrollBar
6140 public override Size TreeViewDefaultSize {
6142 return new Size (121, 97);
6146 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
6148 int height = treeView.ActualItemHeight - 2;
6149 dc.FillRectangle (ResPool.GetSolidBrush (treeView.BackColor), (x + 4) - (height / 2), node.GetY() + 1, height, height);
6151 dc.DrawRectangle (SystemPens.ControlDarkDark, x, middle - 4, 8, 8);
6153 if (node.IsExpanded) {
6154 dc.DrawLine (SystemPens.ControlDarkDark, x + 2, middle, x + 6, middle);
6156 dc.DrawLine (SystemPens.ControlDarkDark, x + 2, middle, x + 6, middle);
6157 dc.DrawLine (SystemPens.ControlDarkDark, x + 4, middle - 2, x + 4, middle + 2);
6162 #region Managed window
6163 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
6165 if (wm.IsToolWindow && !wm.IsMinimized)
6166 return SystemInformation.ToolWindowCaptionHeight;
6167 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
6169 return SystemInformation.CaptionHeight;
6172 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
6174 if ((wm.IsToolWindow && wm.form.FormBorderStyle == FormBorderStyle.FixedToolWindow) ||
6181 public override int ManagedWindowIconWidth (InternalWindowManager wm)
6183 return ManagedWindowTitleBarHeight (wm) - 5;
6186 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
6188 TitleButtons buttons = wm.TitleButtons;
6189 Form form = wm.form;
6191 buttons.HelpButton.Visible = form.HelpButton;
6193 foreach (TitleButton button in buttons) {
6194 button.Visible = false;
6197 switch (form.FormBorderStyle) {
6198 case FormBorderStyle.None:
6199 if (form.WindowState != FormWindowState.Normal)
6200 goto case FormBorderStyle.Sizable;
6202 case FormBorderStyle.FixedToolWindow:
6203 case FormBorderStyle.SizableToolWindow:
6204 buttons.CloseButton.Visible = true;
6205 if (form.WindowState != FormWindowState.Normal)
6206 goto case FormBorderStyle.Sizable;
6208 case FormBorderStyle.FixedSingle:
6209 case FormBorderStyle.Fixed3D:
6210 case FormBorderStyle.FixedDialog:
6211 case FormBorderStyle.Sizable:
6212 switch (form.WindowState) {
6213 case FormWindowState.Normal:
6214 buttons.MinimizeButton.Visible = true;
6215 buttons.MaximizeButton.Visible = true;
6216 buttons.RestoreButton.Visible = false;
6218 case FormWindowState.Maximized:
6219 buttons.MinimizeButton.Visible = true;
6220 buttons.MaximizeButton.Visible = false;
6221 buttons.RestoreButton.Visible = true;
6223 case FormWindowState.Minimized:
6224 buttons.MinimizeButton.Visible = false;
6225 buttons.MaximizeButton.Visible = true;
6226 buttons.RestoreButton.Visible = true;
6229 buttons.CloseButton.Visible = true;
6233 // Respect MinimizeBox/MaximizeBox
6234 if (form.MinimizeBox == false && form.MaximizeBox == false) {
6235 buttons.MinimizeButton.Visible = false;
6236 buttons.MaximizeButton.Visible = false;
6237 } else if (form.MinimizeBox == false)
6238 buttons.MinimizeButton.State = ButtonState.Inactive;
6239 else if (form.MaximizeBox == false)
6240 buttons.MaximizeButton.State = ButtonState.Inactive;
6242 int bw = ManagedWindowBorderWidth (wm);
6243 Size btsize = ManagedWindowButtonSize (wm);
6244 int btw = btsize.Width;
6245 int bth = btsize.Height;
6247 int left = form.Width - bw - btw - ManagedWindowSpacingAfterLastTitleButton;
6249 if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
6250 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
6253 if (buttons.MaximizeButton.Visible) {
6254 buttons.MaximizeButton.Rectangle = new Rectangle (left, top, btw, bth);
6257 if (buttons.RestoreButton.Visible) {
6258 buttons.RestoreButton.Rectangle = new Rectangle (left, top, btw, bth);
6262 buttons.MinimizeButton.Rectangle = new Rectangle (left, top, btw, bth);
6264 } else if (wm.IsToolWindow) {
6265 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
6270 protected virtual Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
6272 Form form = wm.Form;
6273 int tbheight = ManagedWindowTitleBarHeight (wm);
6274 int bdwidth = ManagedWindowBorderWidth (wm);
6275 Color titlebar_color = Color.FromArgb (255, 10, 36, 106);
6276 Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240);
6277 Color color = ThemeEngine.Current.ColorControlDark;
6278 Color color2 = Color.FromArgb (255, 192, 192, 192);
6280 Pen pen = ResPool.GetPen (ColorControl);
6281 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
6282 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
6283 // The 3d border is only 2 pixels wide, so we draw the innermost pixels ourselves
6284 borders = new Rectangle (2, 2, form.Width - 5, form.Height - 5);
6285 for (int i = 2; i < bdwidth; i++) {
6286 dc.DrawRectangle (pen, borders);
6287 borders.Inflate (-1, -1);
6291 bool draw_titlebar_enabled = false;
6292 if (wm.Form.Parent != null && wm.Form.Parent is Form) {
6293 draw_titlebar_enabled = false;
6294 } else if (wm.IsActive && !wm.IsMaximized) {
6295 draw_titlebar_enabled = true;
6297 if (draw_titlebar_enabled) {
6298 color = titlebar_color;
6299 color2 = titlebar_color2;
6302 Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight - 1);
6304 // HACK: For now always draw the titlebar until we get updates better
6305 if (tb.Width > 0 && tb.Height > 0) {
6306 using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal))
6308 dc.FillRectangle (gradient, tb);
6312 if (!wm.IsMinimized)
6313 // Draw the line just beneath the title bar
6314 dc.DrawLine (ResPool.GetPen (SystemColors.Control), bdwidth,
6315 tbheight + bdwidth - 1, form.Width - bdwidth - 1,
6316 tbheight + bdwidth - 1);
6320 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
6323 Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations");
6324 dc.FillRectangle (Brushes.Black, clip);
6326 Rectangle tb = ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
6328 Form form = wm.Form;
6330 Rectangle icon = ManagedWindowGetTitleBarIconArea (wm);
6331 if (icon.IntersectsWith (clip))
6332 dc.DrawIcon (form.Icon, icon);
6333 const int SpacingBetweenIconAndCaption = 2;
6334 tb.Width -= icon.Right + SpacingBetweenIconAndCaption - tb.X ;
6335 tb.X = icon.Right + SpacingBetweenIconAndCaption;
6338 foreach (TitleButton button in wm.TitleButtons.AllButtons) {
6339 tb.Width -= Math.Max (0, tb.Right - DrawTitleButton (dc, button, clip, form));
6341 const int SpacingBetweenCaptionAndLeftMostButton = 3;
6342 tb.Width -= SpacingBetweenCaptionAndLeftMostButton;
6344 string window_caption = form.Text;
6345 window_caption = window_caption.Replace (Environment.NewLine, string.Empty);
6347 if (window_caption != null && window_caption != string.Empty) {
6348 StringFormat format = new StringFormat ();
6349 format.FormatFlags = StringFormatFlags.NoWrap;
6350 format.Trimming = StringTrimming.EllipsisCharacter;
6351 format.LineAlignment = StringAlignment.Center;
6353 if (tb.IntersectsWith (clip))
6354 dc.DrawString (window_caption, WindowBorderFont,
6355 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
6360 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
6362 int height = ManagedWindowTitleBarHeight (wm);
6363 if (!wm.IsMaximized && !wm.IsMinimized) {
6364 if (wm.IsToolWindow)
6365 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
6367 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
6370 height = SystemInformation.CaptionHeight;
6372 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
6376 private int DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
6378 if (!button.Visible) {
6379 return int.MaxValue;
6382 if (button.Rectangle.IntersectsWith (clip)) {
6383 ManagedWindowDrawTitleButton (dc, button, clip, form);
6385 return button.Rectangle.Left;
6388 protected virtual void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
6390 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
6392 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
6393 button.Caption, button.State);
6396 public override Rectangle ManagedWindowGetTitleBarIconArea (InternalWindowManager wm)
6398 int bw = ManagedWindowBorderWidth (wm);
6399 return new Rectangle (bw + 3, bw + 2, wm.IconWidth, wm.IconWidth);
6402 public override Size ManagedWindowGetMenuButtonSize (InternalWindowManager wm)
6404 Size result = SystemInformation.MenuButtonSize;
6410 public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
6415 public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
6417 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
6418 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
6419 button.Caption, button.State);
6422 public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
6427 #region ControlPaint
6428 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
6429 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
6430 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
6431 int bottomWidth, ButtonBorderStyle bottomStyle) {
6432 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
6433 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
6434 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
6435 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
6438 public override void CPDrawBorder (Graphics graphics, RectangleF bounds, Color leftColor, int leftWidth,
6439 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
6440 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
6441 int bottomWidth, ButtonBorderStyle bottomStyle) {
6442 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
6443 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
6444 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
6445 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
6448 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
6449 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
6452 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
6455 Pen penTopLeftInner;
6457 Pen penBottomRightInner;
6458 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
6459 bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
6461 if ((style & Border3DStyle.Adjust) != 0) {
6468 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
6470 CPColor cpcolor = CPColor.Empty;
6472 if (!is_ColorControl)
6473 cpcolor = ResPool.GetCPColor (control_color);
6476 case Border3DStyle.Raised:
6477 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6478 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6479 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6481 case Border3DStyle.Sunken:
6482 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6483 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6484 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6486 case Border3DStyle.Etched:
6487 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6488 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6490 case Border3DStyle.RaisedOuter:
6491 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6493 case Border3DStyle.SunkenOuter:
6494 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6495 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6497 case Border3DStyle.RaisedInner:
6498 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6499 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6501 case Border3DStyle.SunkenInner:
6502 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6504 case Border3DStyle.Flat:
6505 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6507 case Border3DStyle.Bump:
6508 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6514 bool inner = ((style != Border3DStyle.RaisedOuter) && (style != Border3DStyle.SunkenOuter));
6516 if ((sides & Border3DSide.Middle) != 0) {
6517 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
6518 graphics.FillRectangle (brush, rect);
6521 if ((sides & Border3DSide.Left) != 0) {
6522 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
6523 if ((rect.Width > 2) && inner)
6524 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
6527 if ((sides & Border3DSide.Top) != 0) {
6528 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
6529 if ((rect.Height > 2) && inner)
6530 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
6533 if ((sides & Border3DSide.Right) != 0) {
6534 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
6535 if ((rect.Width > 3) && inner)
6536 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
6539 if ((sides & Border3DSide.Bottom) != 0) {
6540 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
6541 if ((rect.Height > 3) && inner)
6542 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
6546 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
6548 CPDrawButtonInternal (dc, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLight);
6551 private void CPDrawButtonInternal (Graphics dc, Rectangle rectangle, ButtonState state, Pen DarkPen, Pen NormalPen, Pen LightPen)
6553 // sadly enough, the rectangle gets always filled with a hatchbrush
6554 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
6555 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6556 ColorControl.G, ColorControl.B),
6558 rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
6560 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
6561 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
6563 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
6565 if ((state & ButtonState.Flat) == ButtonState.Flat) {
6566 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
6568 if ((state & ButtonState.Checked) == ButtonState.Checked) {
6569 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
6572 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6573 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6576 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
6577 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
6580 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
6581 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
6583 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
6585 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6586 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6589 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
6590 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
6593 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
6594 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
6596 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
6598 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6599 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6602 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
6603 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
6606 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
6607 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
6612 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
6613 Rectangle captionRect;
6616 CPDrawButtonInternal (graphics, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLightLight);
6618 if (rectangle.Width<rectangle.Height) {
6619 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
6621 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
6624 if ((state & ButtonState.Pushed)!=0) {
6625 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
6628 /* Make sure we've got at least a line width of 1 */
6629 lineWidth=Math.Max(1, captionRect.Width/7);
6632 case CaptionButton.Close: {
6635 if ((state & ButtonState.Inactive)!=0) {
6636 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
6637 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
6639 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
6640 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
6643 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
6644 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
6649 case CaptionButton.Help:
6650 case CaptionButton.Maximize:
6651 case CaptionButton.Minimize:
6652 case CaptionButton.Restore: {
6653 if ((state & ButtonState.Inactive)!=0) {
6654 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
6656 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
6659 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
6666 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
6668 Pen check_pen = Pens.Black;
6670 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
6672 if ((state & ButtonState.All) == ButtonState.All) {
6674 cb_rect.Height -= 2;
6676 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6677 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6679 check_pen = SystemPens.ControlDark;
6681 if ((state & ButtonState.Flat) == ButtonState.Flat) {
6683 cb_rect.Height -= 2;
6685 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
6686 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6688 dc.FillRectangle (Brushes.White, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6689 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6692 cb_rect.Height -= 1;
6694 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
6696 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
6697 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
6699 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
6701 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
6702 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
6703 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6704 ColorControl.G, ColorControl.B),
6705 ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
6707 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
6709 Pen pen = SystemPens.ControlDark;
6710 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
6711 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
6713 pen = SystemPens.ControlDarkDark;
6714 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
6715 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
6717 pen = SystemPens.ControlLightLight;
6718 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
6719 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
6721 // oh boy, matching ms is like fighting against windmills
6722 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50,
6723 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6724 ColorControl.G, ColorControl.B), ColorControl))) {
6725 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
6726 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
6729 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
6730 check_pen = SystemPens.ControlDark;
6733 if ((state & ButtonState.Checked) == ButtonState.Checked) {
6734 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
6736 if (check_size < 7) {
6737 int lineWidth = Math.Max (3, check_size / 3);
6738 int Scale = Math.Max (1, check_size / 9);
6740 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,
6741 check_size, check_size);
6743 for (int i = 0; i < lineWidth; i++) {
6744 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
6745 dc.DrawLine (check_pen, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i, rect.Left + lineWidth / 2 + 6 * Scale, rect.Top + lineWidth - 2 * Scale + i);
6748 int lineWidth = Math.Max (3, check_size / 3) + 1;
6750 int x_half = cb_rect.Width / 2;
6751 int y_half = cb_rect.Height / 2;
6753 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
6754 check_size, check_size);
6756 int gradient_left = check_size / 3;
6757 int gradient_right = check_size - gradient_left - 1;
6760 for (int i = 0; i < lineWidth; i++) {
6761 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
6762 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
6768 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
6769 Point[] arrow = new Point[3];
6779 if ((state & ButtonState.Checked)!=0) {
6780 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
6783 if ((state & ButtonState.Flat)!=0) {
6784 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
6786 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
6787 // this needs to render like a pushed button - jba
6788 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
6789 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6790 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
6792 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
6796 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
6797 centerX=rect.Left+rect.Width/2;
6798 centerY=rect.Top+rect.Height/2;
6799 shiftX=Math.Max(1, rect.Width/8);
6800 shiftY=Math.Max(1, rect.Height/8);
6802 if ((state & ButtonState.Pushed)!=0) {
6809 P1=new Point(rect.Left, centerY);
6810 P2=new Point(rect.Right, centerY);
6811 P3=new Point(centerX, rect.Bottom);
6817 /* Draw the arrow */
6818 if ((state & ButtonState.Inactive)!=0) {
6819 /* Move away from the shadow */
6820 arrow[0].X += 1; arrow[0].Y += 1;
6821 arrow[1].X += 1; arrow[1].Y += 1;
6822 arrow[2].X += 1; arrow[2].Y += 1;
6824 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
6830 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
6832 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
6837 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
6839 Pen pen = Pens.Black;
6840 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
6844 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
6845 graphics.DrawRectangle (pen, rect);
6847 X = rect.X + rect.Width / 2;
6848 Y = rect.Y + rect.Height / 2;
6850 /* Draw the cross */
6851 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
6852 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
6854 /* Draw 'arrows' for vertical lines */
6855 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
6856 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
6858 /* Draw 'arrows' for horizontal lines */
6859 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
6860 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
6863 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
6864 // make a rectange to trace around border of the button
6865 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6867 Color outerColor = foreColor;
6868 // adjust focus color according to the flatstyle
6869 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
6870 outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;
6873 // draw the outer rectangle
6874 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
6876 // draw the inner rectangle
6877 if (button.FlatStyle == FlatStyle.Popup) {
6878 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
6880 // draw a flat inner rectangle
6881 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
6882 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
6886 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
6888 // make a rectange to trace around border of the button
6889 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6891 #if NotUntilCairoIsFixed
6892 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
6893 DashStyle oldStyle; // used for caching old penstyle
6894 Pen pen = ResPool.GetPen (colorBackInverted);
6896 oldStyle = pen.DashStyle;
6897 pen.DashStyle = DashStyle.Dot;
6899 graphics.DrawRectangle (pen, trace_rectangle);
6900 pen.DashStyle = oldStyle;
6902 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
6907 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
6909 Rectangle rect = rectangle;
6913 if (backColor.GetBrightness () >= 0.5) {
6914 foreColor = Color.Transparent;
6915 backColor = Color.Black;
6918 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
6919 foreColor = Color.Black;
6922 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
6923 pen = new Pen (brush, 1);
6928 graphics.DrawRectangle (pen, rect);
6932 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
6937 if (primary == true) {
6939 if (enabled == true) {
6942 sb = SystemBrushes.Control;
6946 if (enabled == true) {
6949 sb = SystemBrushes.Control;
6952 graphics.FillRectangle (sb, rectangle);
6953 graphics.DrawRectangle (pen, rectangle);
6957 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
6963 ControlPaint.Color2HBS(backColor, out h, out b, out s);
6966 foreColor=Color.Black;
6968 foreColor=Color.White;
6971 // still not perfect. it seems that ms calculates the position of the first dot or line
6973 using (Pen pen = new Pen (foreColor)) {
6974 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
6976 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
6977 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
6981 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
6983 Microsoft seems to ignore the background and simply make
6984 the image grayscale. At least when having > 256 colors on
6988 if (imagedisabled_attributes == null) {
6989 imagedisabled_attributes = new ImageAttributes ();
6990 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
6991 // This table would create a perfect grayscale image, based on luminance
6992 // new float[]{0.3f,0.3f,0.3f,0,0},
6993 // new float[]{0.59f,0.59f,0.59f,0,0},
6994 // new float[]{0.11f,0.11f,0.11f,0,0},
6995 // new float[]{0,0,0,1,0,0},
6996 // new float[]{0,0,0,0,1,0},
6997 // new float[]{0,0,0,0,0,1}
6999 // This table generates a image that is grayscaled and then
7000 // brightened up. Seems to match MS close enough.
7001 new float[]{0.2f,0.2f,0.2f,0,0},
7002 new float[]{0.41f,0.41f,0.41f,0,0},
7003 new float[]{0.11f,0.11f,0.11f,0,0},
7004 new float[]{0.15f,0.15f,0.15f,1,0,0},
7005 new float[]{0.15f,0.15f,0.15f,0,1,0},
7006 new float[]{0.15f,0.15f,0.15f,0,0,1}
7009 imagedisabled_attributes.SetColorMatrix (colorMatrix);
7012 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
7017 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
7022 penBorder = ResPool.GetSizedPen (Color.White, 2);
7023 penInside = ResPool.GetPen (Color.Black);
7025 penBorder = ResPool.GetSizedPen (Color.Black, 2);
7026 penInside = ResPool.GetPen (Color.White);
7028 penBorder.Alignment=PenAlignment.Inset;
7029 penInside.Alignment=PenAlignment.Inset;
7031 graphics.DrawRectangle(penBorder, rectangle);
7032 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
7036 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color, Color backColor) {
7040 if (backColor != Color.Empty)
7041 graphics.FillRectangle (ResPool.GetSolidBrush (backColor), rectangle);
7043 Brush brush = ResPool.GetSolidBrush (color);
7046 case MenuGlyph.Arrow: {
7047 float height = rectangle.Height * 0.7f;
7048 float width = height / 2.0f;
7050 PointF ddCenter = new PointF (rectangle.X + ((rectangle.Width-width) / 2.0f), rectangle.Y + (rectangle.Height / 2.0f));
7052 PointF [] vertices = new PointF [3];
7053 vertices [0].X = ddCenter.X;
7054 vertices [0].Y = ddCenter.Y - (height / 2.0f);
7055 vertices [1].X = ddCenter.X;
7056 vertices [1].Y = ddCenter.Y + (height / 2.0f);
7057 vertices [2].X = ddCenter.X + width + 0.1f;
7058 vertices [2].Y = ddCenter.Y;
7060 graphics.FillPolygon (brush, vertices);
7065 case MenuGlyph.Bullet: {
7067 lineWidth=Math.Max(2, rectangle.Width/3);
7068 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
7070 graphics.FillEllipse(brush, rect);
7075 case MenuGlyph.Checkmark: {
7077 Pen pen = ResPool.GetPen (color);
7078 lineWidth = Math.Max (2, rectangle.Width / 6);
7079 rect = new Rectangle(rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height- lineWidth * 2);
7081 int Scale = Math.Max (1, rectangle.Width / 12);
7082 int top = (rect.Y + lineWidth + ((rect.Height - ((2 * Scale) + lineWidth)) / 2));
7084 for (int i=0; i<lineWidth; i++) {
7085 graphics.DrawLine (pen, rect.Left+lineWidth/2, top+i, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i);
7086 graphics.DrawLine (pen, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i, rect.Left+lineWidth/2+6*Scale, top-2*Scale+i);
7094 [MonoInternalNote ("Does not respect Mixed")]
7095 public override void CPDrawMixedCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
7097 CPDrawCheckBox (graphics, rectangle, state);
7100 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
7102 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
7104 Color dot_color = Color.Black;
7106 Color top_left_outer = Color.Black;
7107 Color top_left_inner = Color.Black;
7108 Color bottom_right_outer = Color.Black;
7109 Color bottom_right_inner = Color.Black;
7111 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
7112 int radius = ellipse_diameter / 2;
7114 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
7118 if ((state & ButtonState.All) == ButtonState.All) {
7119 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
7120 ColorControl.G, ColorControl.B), ColorControl);
7121 dot_color = cpcolor.Dark;
7123 if ((state & ButtonState.Flat) == ButtonState.Flat) {
7124 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
7125 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
7127 brush = SystemBrushes.ControlLightLight;
7129 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
7130 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
7132 brush = SystemBrushes.ControlLightLight;
7134 top_left_outer = cpcolor.Dark;
7135 top_left_inner = cpcolor.DarkDark;
7136 bottom_right_outer = cpcolor.Light;
7137 bottom_right_inner = Color.Transparent;
7139 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
7140 dot_color = cpcolor.Dark;
7143 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
7145 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
7147 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
7148 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
7149 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
7151 if (bottom_right_inner != Color.Transparent)
7152 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
7154 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl), line_width)) {
7155 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
7158 if ((state & ButtonState.Checked) == ButtonState.Checked) {
7159 int inflate = line_width * 4;
7160 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
7161 if (rectangle.Height > 13) {
7165 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
7167 Pen pen = ResPool.GetPen (dot_color);
7168 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
7169 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
7171 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
7172 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
7177 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
7182 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
7187 /* Scroll button: regular button + direction arrow */
7188 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
7190 DrawScrollButtonPrimitive (dc, area, state);
7192 bool fill_rect = true;
7195 if ((state & ButtonState.Pushed) != 0)
7199 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
7201 Point [] arrow = new Point [3];
7202 for (int i = 0; i < 3; i++)
7203 arrow [i] = new Point ();
7205 Pen pen = SystemPens.ControlText;
7207 if ((state & ButtonState.Inactive) != 0) {
7208 pen = SystemPens.ControlDark;
7213 case ScrollButton.Down:
7214 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
7215 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7219 int triangle_height;
7221 if (rect.Height < 8) {
7222 triangle_height = 2;
7224 } else if (rect.Height == 11) {
7225 triangle_height = 3;
7227 triangle_height = (int)Math.Round (rect.Height / 3.0f);
7230 arrow [0].X = rect.X + x_middle;
7231 arrow [0].Y = rect.Y + y_middle + triangle_height / 2;
7233 arrow [1].X = arrow [0].X + triangle_height - 1;
7234 arrow [1].Y = arrow [0].Y - triangle_height + 1;
7235 arrow [2].X = arrow [0].X - triangle_height + 1;
7236 arrow [2].Y = arrow [1].Y;
7238 dc.DrawPolygon (pen, arrow);
7240 if ((state & ButtonState.Inactive) != 0) {
7241 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
7242 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
7246 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
7247 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
7254 case ScrollButton.Up:
7255 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
7256 y_middle = (int)Math.Round (rect.Height / 2.0f);
7263 if (rect.Height < 8) {
7264 triangle_height = 2;
7266 } else if (rect.Height == 11) {
7267 triangle_height = 3;
7269 triangle_height = (int)Math.Round (rect.Height / 3.0f);
7272 arrow [0].X = rect.X + x_middle;
7273 arrow [0].Y = rect.Y + y_middle - triangle_height / 2;
7275 arrow [1].X = arrow [0].X + triangle_height - 1;
7276 arrow [1].Y = arrow [0].Y + triangle_height - 1;
7277 arrow [2].X = arrow [0].X - triangle_height + 1;
7278 arrow [2].Y = arrow [1].Y;
7280 dc.DrawPolygon (pen, arrow);
7282 if ((state & ButtonState.Inactive) != 0) {
7283 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
7287 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
7288 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
7295 case ScrollButton.Left:
7296 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7302 if (rect.Width < 8) {
7305 } else if (rect.Width == 11) {
7308 triangle_width = (int)Math.Round (rect.Width / 3.0f);
7311 arrow [0].X = rect.Left + triangle_width - 1;
7312 arrow [0].Y = rect.Y + y_middle;
7314 if (arrow [0].X - 1 == rect.X)
7317 arrow [1].X = arrow [0].X + triangle_width - 1;
7318 arrow [1].Y = arrow [0].Y - triangle_width + 1;
7319 arrow [2].X = arrow [1].X;
7320 arrow [2].Y = arrow [0].Y + triangle_width - 1;
7322 dc.DrawPolygon (pen, arrow);
7324 if ((state & ButtonState.Inactive) != 0) {
7325 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
7329 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
7330 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
7337 case ScrollButton.Right:
7338 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7342 if (rect.Width < 8) {
7345 } else if (rect.Width == 11) {
7348 triangle_width = (int)Math.Round (rect.Width / 3.0f);
7351 arrow [0].X = rect.Right - triangle_width - 1;
7352 arrow [0].Y = rect.Y + y_middle;
7354 if (arrow [0].X - 1 == rect.X)
7357 arrow [1].X = arrow [0].X - triangle_width + 1;
7358 arrow [1].Y = arrow [0].Y - triangle_width + 1;
7359 arrow [2].X = arrow [1].X;
7360 arrow [2].Y = arrow [0].Y + triangle_width - 1;
7362 dc.DrawPolygon (pen, arrow);
7364 if ((state & ButtonState.Inactive) != 0) {
7365 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
7366 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
7370 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
7371 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
7380 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
7386 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
7388 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
7389 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
7391 for (int i = 2; i < bounds.Width - 2; i += 4) {
7392 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
7393 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
7394 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
7398 private void DrawStringDisabled20 (Graphics g, string s, Font font, Rectangle layoutRectangle, Color color, TextFormatFlags flags, bool useDrawString)
7400 CPColor cpcolor = ResPool.GetCPColor (color);
7402 layoutRectangle.Offset (1, 1);
7403 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.LightLight, flags, useDrawString);
7405 layoutRectangle.Offset (-1, -1);
7406 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.Dark, flags, useDrawString);
7409 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
7411 CPColor cpcolor = ResPool.GetCPColor (color);
7413 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
7414 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
7416 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
7419 public override void CPDrawStringDisabled (IDeviceContext dc, string s, Font font, Color color, Rectangle layoutRectangle, TextFormatFlags format)
7421 CPColor cpcolor = ResPool.GetCPColor (color);
7423 layoutRectangle.Offset (1, 1);
7424 TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.LightLight, format);
7426 layoutRectangle.Offset (-1, -1);
7427 TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.Dark, format);
7430 public override void CPDrawVisualStyleBorder (Graphics graphics, Rectangle bounds)
7432 graphics.DrawRectangle (SystemPens.ControlDarkDark, bounds);
7435 private static void DrawBorderInternal (Graphics graphics, int startX, int startY, int endX, int endY,
7436 int width, Color color, ButtonBorderStyle style, Border3DSide side)
7438 DrawBorderInternal (graphics, (float) startX, (float) startY, (float) endX, (float) endY,
7439 width, color, style, side);
7442 private static void DrawBorderInternal (Graphics graphics, float startX, float startY, float endX, float endY,
7443 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
7448 case ButtonBorderStyle.Solid:
7449 case ButtonBorderStyle.Inset:
7450 case ButtonBorderStyle.Outset:
7451 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
7453 case ButtonBorderStyle.Dashed:
7454 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
7456 case ButtonBorderStyle.Dotted:
7457 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
7460 case ButtonBorderStyle.None:
7465 case ButtonBorderStyle.Outset: {
7467 int hue, brightness, saturation;
7468 int brightnessSteps;
7469 int brightnessDownSteps;
7471 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
7473 brightnessDownSteps=brightness/width;
7474 if (brightness>127) {
7475 brightnessSteps=Math.Max(6, (160-brightness)/width);
7477 brightnessSteps=(127-brightness)/width;
7480 for (int i=0; i<width; i++) {
7482 case Border3DSide.Left: {
7483 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7484 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7485 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7489 case Border3DSide.Right: {
7490 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7491 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7492 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7496 case Border3DSide.Top: {
7497 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7498 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7499 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7503 case Border3DSide.Bottom: {
7504 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7505 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7506 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7514 case ButtonBorderStyle.Inset: {
7516 int hue, brightness, saturation;
7517 int brightnessSteps;
7518 int brightnessDownSteps;
7520 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
7522 brightnessDownSteps=brightness/width;
7523 if (brightness>127) {
7524 brightnessSteps=Math.Max(6, (160-brightness)/width);
7526 brightnessSteps=(127-brightness)/width;
7529 for (int i=0; i<width; i++) {
7531 case Border3DSide.Left: {
7532 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7533 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7534 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7538 case Border3DSide.Right: {
7539 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7540 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7541 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7545 case Border3DSide.Top: {
7546 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7547 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7548 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7552 case Border3DSide.Bottom: {
7553 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7554 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7555 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7564 I decided to have the for-loop duplicated for speed reasons;
7565 that way we only have to switch once (as opposed to have the
7566 for-loop around the switch)
7570 case Border3DSide.Left: {
7571 for (int i=0; i<width; i++) {
7572 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7577 case Border3DSide.Right: {
7578 for (int i=0; i<width; i++) {
7579 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7584 case Border3DSide.Top: {
7585 for (int i=0; i<width; i++) {
7586 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7591 case Border3DSide.Bottom: {
7592 for (int i=0; i<width; i++) {
7593 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7604 This function actually draws the various caption elements.
7605 This way we can scale them nicely, no matter what size, and they
7606 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
7609 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
7611 case CaptionButton.Close: {
7613 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
7614 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
7617 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
7618 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
7622 case CaptionButton.Help: {
7623 StringFormat sf = new StringFormat();
7624 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
7626 sf.Alignment=StringAlignment.Center;
7627 sf.LineAlignment=StringAlignment.Center;
7630 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
7638 case CaptionButton.Maximize: {
7639 /* Top 'caption bar' line */
7640 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7641 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Top+2*lineWidth+shift+i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+2*lineWidth+shift+i);
7644 /* Left side line */
7645 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7646 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
7649 /* Right side line */
7650 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7651 graphics.DrawLine(pen, captionRect.Right-lineWidth-lineWidth/2+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Right-lineWidth-lineWidth/2+shift+i, captionRect.Bottom-lineWidth+shift);
7655 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7656 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
7661 case CaptionButton.Minimize: {
7663 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7664 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
7669 case CaptionButton.Restore: {
7670 /** First 'window' **/
7671 /* Top 'caption bar' line */
7672 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7673 graphics.DrawLine(pen, captionRect.Left+3*lineWidth+shift, captionRect.Top+2*lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+2*lineWidth+shift-i);
7676 /* Left side line */
7677 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7678 graphics.DrawLine(pen, captionRect.Left+3*lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+3*lineWidth+shift+i, captionRect.Top+4*lineWidth+shift);
7681 /* Right side line */
7682 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7683 graphics.DrawLine(pen, captionRect.Right-lineWidth-lineWidth/2+shift-i, captionRect.Top+2*lineWidth+shift, captionRect.Right-lineWidth-lineWidth/2+shift-i, captionRect.Top+5*lineWidth-lineWidth/2+shift);
7687 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7688 graphics.DrawLine(pen, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Top+5*lineWidth-lineWidth/2+shift+1+i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Top+5*lineWidth-lineWidth/2+shift+1+i);
7691 /** Second 'window' **/
7692 /* Top 'caption bar' line */
7693 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7694 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Top+4*lineWidth+shift+1-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Top+4*lineWidth+shift+1-i);
7697 /* Left side line */
7698 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7699 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
7702 /* Right side line */
7703 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7704 graphics.DrawLine(pen, captionRect.Right-3*lineWidth-lineWidth/2+shift-i, captionRect.Top+4*lineWidth+shift+1, captionRect.Right-3*lineWidth-lineWidth/2+shift-i, captionRect.Bottom-lineWidth+shift);
7708 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7709 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
7718 /* Generic scroll button */
7719 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
7720 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
7721 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
7722 area.Y + 1, area.Width - 2 , area.Height - 2);
7724 dc.DrawRectangle (SystemPens.ControlDark, area.X,
7725 area.Y, area.Width, area.Height);
7730 Brush sb_control = SystemBrushes.Control;
7731 Brush sb_lightlight = SystemBrushes.ControlLightLight;
7732 Brush sb_dark = SystemBrushes.ControlDark;
7733 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
7735 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
7736 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
7738 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
7739 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
7742 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
7745 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
7748 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
7749 area.Y + 1, 1, area.Height -3);
7751 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
7752 area.Y, 1, area.Height - 1);
7754 dc.FillRectangle (sb_control, area.X + 2,
7755 area.Y + 2, area.Width - 4, area.Height - 4);
7759 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
7760 switch (border_style){
7761 case BorderStyle.Fixed3D:
7762 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
7763 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
7764 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
7765 area.Y + area.Height - 1);
7766 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
7767 area.Y + area.Height);
7769 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
7770 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
7771 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
7772 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
7774 case BorderStyle.FixedSingle:
7775 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
7777 case BorderStyle.None:
7783 #endregion // ControlPaint