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;
58 Font window_border_font;
59 const int SEPARATOR_HEIGHT = 6;
60 const int SEPARATOR_MIN_WIDTH = 20;
61 const int SM_CXBORDER = 1;
62 const int SM_CYBORDER = 1;
63 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tabd
64 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
65 const int CheckSize = 13;
67 #region Principal Theme Methods
68 public ThemeWin32Classic ()
73 public override void ResetDefaults() {
74 defaultWindowBackColor = this.ColorWindow;
75 defaultWindowForeColor = this.ColorControlText;
76 window_border_font = null;
78 /* Menu string formats */
79 string_format_menu_text = new StringFormat ();
80 string_format_menu_text.LineAlignment = StringAlignment.Center;
81 string_format_menu_text.Alignment = StringAlignment.Near;
82 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
83 string_format_menu_text.SetTabStops (0f, new float [] { 50f });
84 string_format_menu_text.FormatFlags |= StringFormatFlags.NoWrap;
86 string_format_menu_shortcut = new StringFormat ();
87 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
88 string_format_menu_shortcut.Alignment = StringAlignment.Far;
90 string_format_menu_menubar_text = new StringFormat ();
91 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
92 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
93 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
96 public override bool DoubleBufferingSupported {
100 public override int HorizontalScrollBarHeight {
102 return XplatUI.HorizontalScrollBarHeight;
106 public override int VerticalScrollBarWidth {
108 return XplatUI.VerticalScrollBarWidth;
112 public override Font WindowBorderFont {
114 return window_border_font ?? (window_border_font = new Font(FontFamily.GenericSansSerif, 8.25f, FontStyle.Bold));
118 #endregion // Principal Theme Methods
120 #region Internal Methods
121 protected Brush GetControlBackBrush (Color c) {
122 if (c.ToArgb () == DefaultControlBackColor.ToArgb ())
123 return SystemBrushes.Control;
124 return ResPool.GetSolidBrush (c);
127 protected Brush GetControlForeBrush (Color c) {
128 if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
129 return SystemBrushes.ControlText;
130 return ResPool.GetSolidBrush (c);
132 #endregion // Internal Methods
135 public override Font GetLinkFont (Control control)
137 return new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Underline, control.Font.Unit);
139 #endregion // Control
141 #region OwnerDraw Support
142 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
144 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
145 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
149 e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
152 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
154 if (e.State == DrawItemState.Focus)
155 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
157 #endregion // OwnerDraw Support
160 #region Standard Button Style
161 public override void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
163 // Draw Button Background
164 DrawButtonBackground (g, b, clipRectangle);
166 // If we have an image, draw it
167 if (imageBounds.Size != Size.Empty)
168 DrawButtonImage (g, b, imageBounds);
170 // If we're focused, draw a focus rectangle
171 if (b.Focused && b.Enabled && b.ShowFocusCues)
172 DrawButtonFocus (g, b);
174 // If we have text, draw it
175 if (textBounds != Rectangle.Empty)
176 DrawButtonText (g, b, textBounds);
179 public virtual void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
182 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
183 else if (button.InternalSelected)
184 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
185 else if (button.Entered)
186 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
187 else if (!button.Enabled)
188 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
190 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
193 public virtual void DrawButtonFocus (Graphics g, Button button)
195 ControlPaint.DrawFocusRectangle (g, Rectangle.Inflate (button.ClientRectangle, -4, -4));
198 public virtual void DrawButtonImage (Graphics g, ButtonBase button, Rectangle imageBounds)
201 g.DrawImage (button.Image, imageBounds);
203 CPDrawImageDisabled (g, button.Image, imageBounds.Left, imageBounds.Top, ColorControl);
206 public virtual void DrawButtonText (Graphics g, ButtonBase button, Rectangle textBounds)
208 // Ensure that at least one line is going to get displayed.
209 // Line limit does not ensure that despite its description.
210 textBounds.Height = Math.Max (textBounds.Height, button.Font.Height);
213 TextRenderer.DrawTextInternal (g, button.Text, button.Font, textBounds, button.ForeColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
215 DrawStringDisabled20 (g, button.Text, button.Font, textBounds, button.BackColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
219 #region FlatStyle Button Style
220 public override void DrawFlatButton (Graphics g, ButtonBase b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
222 // Draw Button Background
223 if (b.BackgroundImage == null)
224 DrawFlatButtonBackground (g, b, clipRectangle);
226 // If we have an image, draw it
227 if (imageBounds.Size != Size.Empty)
228 DrawFlatButtonImage (g, b, imageBounds);
230 // If we're focused, draw a focus rectangle
231 if (b.Focused && b.Enabled && b.ShowFocusCues)
232 DrawFlatButtonFocus (g, b);
234 // If we have text, draw it
235 if (textBounds != Rectangle.Empty)
236 DrawFlatButtonText (g, b, textBounds);
239 public virtual void DrawFlatButtonBackground (Graphics g, ButtonBase button, Rectangle clipArea)
242 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor, button.FlatAppearance);
243 else if (button.InternalSelected) {
245 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default | ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
247 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor, button.FlatAppearance);
249 else if (button.Entered)
250 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
251 else if (!button.Enabled)
252 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor, button.FlatAppearance);
254 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor, button.FlatAppearance);
257 public virtual void DrawFlatButtonFocus (Graphics g, ButtonBase button)
259 if (!button.Pressed) {
260 Color focus_color = ControlPaint.Dark (button.BackColor);
261 g.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.Left + 4, button.ClientRectangle.Top + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9));
265 public virtual void DrawFlatButtonImage (Graphics g, ButtonBase button, Rectangle imageBounds)
267 // No changes from Standard for image for this theme
268 DrawButtonImage (g, button, imageBounds);
271 public virtual void DrawFlatButtonText (Graphics g, ButtonBase button, Rectangle textBounds)
273 // No changes from Standard for text for this theme
274 DrawButtonText (g, button, textBounds);
278 #region Popup Button Style
279 public override void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
281 // Draw Button Background
282 DrawPopupButtonBackground (g, b, clipRectangle);
284 // If we have an image, draw it
285 if (imageBounds.Size != Size.Empty)
286 DrawPopupButtonImage (g, b, imageBounds);
288 // If we're focused, draw a focus rectangle
289 if (b.Focused && b.Enabled && b.ShowFocusCues)
290 DrawPopupButtonFocus (g, b);
292 // If we have text, draw it
293 if (textBounds != Rectangle.Empty)
294 DrawPopupButtonText (g, b, textBounds);
297 public virtual void DrawPopupButtonBackground (Graphics g, Button button, Rectangle clipArea)
300 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
301 else if (button.Entered)
302 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
303 else if (button.InternalSelected)
304 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
305 else if (!button.Enabled)
306 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
308 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
311 public virtual void DrawPopupButtonFocus (Graphics g, Button button)
313 // No changes from Standard for image for this theme
314 DrawButtonFocus (g, button);
317 public virtual void DrawPopupButtonImage (Graphics g, Button button, Rectangle imageBounds)
319 // No changes from Standard for image for this theme
320 DrawButtonImage (g, button, imageBounds);
323 public virtual void DrawPopupButtonText (Graphics g, Button button, Rectangle textBounds)
325 // No changes from Standard for image for this theme
326 DrawButtonText (g, button, textBounds);
330 #region Button Layout Calculations
331 public override Size CalculateButtonAutoSize (Button button)
333 Size ret_size = Size.Empty;
334 Size text_size = TextRenderer.MeasureTextInternal (button.Text, button.Font, button.UseCompatibleTextRendering);
335 Size image_size = button.Image == null ? Size.Empty : button.Image.Size;
338 if (button.Text.Length != 0) {
339 text_size.Height += 4;
340 text_size.Width += 4;
343 switch (button.TextImageRelation) {
344 case TextImageRelation.Overlay:
345 ret_size.Height = Math.Max (button.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
346 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
348 case TextImageRelation.ImageAboveText:
349 case TextImageRelation.TextAboveImage:
350 ret_size.Height = text_size.Height + image_size.Height;
351 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
353 case TextImageRelation.ImageBeforeText:
354 case TextImageRelation.TextBeforeImage:
355 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
356 ret_size.Width = text_size.Width + image_size.Width;
361 ret_size.Height += (button.Padding.Vertical + 6);
362 ret_size.Width += (button.Padding.Horizontal + 6);
367 public override void CalculateButtonTextAndImageLayout (ButtonBase button, out Rectangle textRectangle, out Rectangle imageRectangle)
369 Image image = button.Image;
370 string text = button.Text;
371 Rectangle content_rect = button.PaddingClientRectangle;
372 Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
373 Size image_size = image == null ? Size.Empty : image.Size;
375 textRectangle = Rectangle.Empty;
376 imageRectangle = Rectangle.Empty;
378 switch (button.TextImageRelation) {
379 case TextImageRelation.Overlay:
380 // Overlay is easy, text always goes here
381 textRectangle = Rectangle.Inflate (content_rect, -4, -4);
384 textRectangle.Offset (1, 1);
386 // Image is dependent on ImageAlign
392 int image_height = image.Height;
393 int image_width = image.Width;
395 switch (button.ImageAlign) {
396 case System.Drawing.ContentAlignment.TopLeft:
400 case System.Drawing.ContentAlignment.TopCenter:
401 image_x = (content_rect.Width - image_width) / 2;
404 case System.Drawing.ContentAlignment.TopRight:
405 image_x = content_rect.Width - image_width - 5;
408 case System.Drawing.ContentAlignment.MiddleLeft:
410 image_y = (content_rect.Height - image_height) / 2;
412 case System.Drawing.ContentAlignment.MiddleCenter:
413 image_x = (content_rect.Width - image_width) / 2;
414 image_y = (content_rect.Height - image_height) / 2;
416 case System.Drawing.ContentAlignment.MiddleRight:
417 image_x = content_rect.Width - image_width - 4;
418 image_y = (content_rect.Height - image_height) / 2;
420 case System.Drawing.ContentAlignment.BottomLeft:
422 image_y = content_rect.Height - image_height - 4;
424 case System.Drawing.ContentAlignment.BottomCenter:
425 image_x = (content_rect.Width - image_width) / 2;
426 image_y = content_rect.Height - image_height - 4;
428 case System.Drawing.ContentAlignment.BottomRight:
429 image_x = content_rect.Width - image_width - 4;
430 image_y = content_rect.Height - image_height - 4;
438 imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
440 case TextImageRelation.ImageAboveText:
441 content_rect.Inflate (-4, -4);
442 LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
444 case TextImageRelation.TextAboveImage:
445 content_rect.Inflate (-4, -4);
446 LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
448 case TextImageRelation.ImageBeforeText:
449 content_rect.Inflate (-4, -4);
450 LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
452 case TextImageRelation.TextBeforeImage:
453 content_rect.Inflate (-4, -4);
454 LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
459 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)
461 int element_spacing = 0; // Spacing between the Text and the Image
462 int total_width = textSize.Width + element_spacing + imageSize.Width;
465 element_spacing += 2;
467 // If the text is too big, chop it down to the size we have available to it
468 if (total_width > totalArea.Width) {
469 textSize.Width = totalArea.Width - element_spacing - imageSize.Width;
470 total_width = totalArea.Width;
473 int excess_width = totalArea.Width - total_width;
476 Rectangle final_text_rect;
477 Rectangle final_image_rect;
479 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
480 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
482 if (h_image == HorizontalAlignment.Left)
484 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
485 offset = excess_width;
486 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
487 offset += (int)(excess_width / 3);
489 offset += (int)(2 * (excess_width / 3));
492 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
493 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
496 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
497 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
500 textRect = final_text_rect;
501 imageRect = final_image_rect;
504 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)
506 int element_spacing = 0; // Spacing between the Text and the Image
507 int total_height = textSize.Height + element_spacing + imageSize.Height;
510 element_spacing += 2;
512 if (textSize.Width > totalArea.Width)
513 textSize.Width = totalArea.Width;
515 // If the there isn't enough room and we're text first, cut out the image
516 if (total_height > totalArea.Height && textFirst) {
517 imageSize = Size.Empty;
518 total_height = totalArea.Height;
521 int excess_height = totalArea.Height - total_height;
524 Rectangle final_text_rect;
525 Rectangle final_image_rect;
527 VerticalAlignment v_text = GetVerticalAlignment (textAlign);
528 VerticalAlignment v_image = GetVerticalAlignment (imageAlign);
530 if (v_image == VerticalAlignment.Top)
532 else if (v_image == VerticalAlignment.Bottom && v_text == VerticalAlignment.Bottom)
533 offset = excess_height;
534 else if (v_image == VerticalAlignment.Center && (v_text == VerticalAlignment.Top || v_text == VerticalAlignment.Center))
535 offset += (int)(excess_height / 3);
537 offset += (int)(2 * (excess_height / 3));
540 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textSize.Height);
541 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, final_text_rect.Bottom + element_spacing, imageSize.Width, imageSize.Height);
544 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, totalArea.Top + offset, imageSize.Width, imageSize.Height);
545 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textSize.Height);
547 if (final_text_rect.Bottom > totalArea.Bottom)
548 final_text_rect.Y = totalArea.Top;
551 textRect = final_text_rect;
552 imageRect = final_image_rect;
555 private HorizontalAlignment GetHorizontalAlignment (System.Drawing.ContentAlignment align)
558 case System.Drawing.ContentAlignment.BottomLeft:
559 case System.Drawing.ContentAlignment.MiddleLeft:
560 case System.Drawing.ContentAlignment.TopLeft:
561 return HorizontalAlignment.Left;
562 case System.Drawing.ContentAlignment.BottomCenter:
563 case System.Drawing.ContentAlignment.MiddleCenter:
564 case System.Drawing.ContentAlignment.TopCenter:
565 return HorizontalAlignment.Center;
566 case System.Drawing.ContentAlignment.BottomRight:
567 case System.Drawing.ContentAlignment.MiddleRight:
568 case System.Drawing.ContentAlignment.TopRight:
569 return HorizontalAlignment.Right;
572 return HorizontalAlignment.Left;
575 private enum VerticalAlignment
582 private VerticalAlignment GetVerticalAlignment (System.Drawing.ContentAlignment align)
585 case System.Drawing.ContentAlignment.TopLeft:
586 case System.Drawing.ContentAlignment.TopCenter:
587 case System.Drawing.ContentAlignment.TopRight:
588 return VerticalAlignment.Top;
589 case System.Drawing.ContentAlignment.MiddleLeft:
590 case System.Drawing.ContentAlignment.MiddleCenter:
591 case System.Drawing.ContentAlignment.MiddleRight:
592 return VerticalAlignment.Center;
593 case System.Drawing.ContentAlignment.BottomLeft:
594 case System.Drawing.ContentAlignment.BottomCenter:
595 case System.Drawing.ContentAlignment.BottomRight:
596 return VerticalAlignment.Bottom;
599 return VerticalAlignment.Top;
602 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, System.Drawing.ContentAlignment align)
607 if (align == System.Drawing.ContentAlignment.BottomLeft || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.TopLeft)
609 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.TopCenter)
610 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
611 else if (align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.MiddleRight || align == System.Drawing.ContentAlignment.TopRight)
612 x = outer.Right - inner.Width;
613 if (align == System.Drawing.ContentAlignment.TopCenter || align == System.Drawing.ContentAlignment.TopLeft || align == System.Drawing.ContentAlignment.TopRight)
615 else if (align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.MiddleRight)
616 y = outer.Y + (outer.Height - inner.Height) / 2;
617 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.BottomLeft)
618 y = outer.Bottom - inner.Height;
620 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
626 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button)
628 // Draw the button: Draw border, etc.
629 ButtonBase_DrawButton(button, dc);
632 if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null)))
633 ButtonBase_DrawImage(button, dc);
635 // Draw the focus rectangle
636 if (ShouldPaintFocusRectagle (button))
637 ButtonBase_DrawFocus(button, dc);
640 if (button.Text != null && button.Text != String.Empty)
641 ButtonBase_DrawText(button, dc);
644 protected static bool ShouldPaintFocusRectagle (ButtonBase button)
646 return (button.Focused || button.paint_as_acceptbutton) && button.Enabled && button.ShowFocusCues;
649 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
651 Rectangle borderRectangle;
652 bool check_or_radio = false;
653 bool check_or_radio_checked = false;
655 bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
657 CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
659 if (button is CheckBox) {
660 check_or_radio = true;
661 check_or_radio_checked = ((CheckBox)button).Checked;
662 } else if (button is RadioButton) {
663 check_or_radio = true;
664 check_or_radio_checked = ((RadioButton)button).Checked;
667 if (button.Focused && button.Enabled && !check_or_radio) {
668 // shrink the rectangle for the normal button drawing inside the focus rectangle
669 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
671 borderRectangle = button.ClientRectangle;
674 if (button.FlatStyle == FlatStyle.Popup) {
675 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
676 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
677 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
678 Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
679 else if (button.is_pressed || check_or_radio_checked)
680 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
681 } else if (button.FlatStyle == FlatStyle.Flat) {
682 if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
683 if ((button.image == null) && (button.image_list == null)) {
684 Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
685 dc.FillRectangle (brush, borderRectangle);
687 } else if (button.is_pressed || check_or_radio_checked) {
688 if ((button.image == null) && (button.image_list == null)) {
689 Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
690 dc.FillRectangle (brush, borderRectangle);
693 Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
694 dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
695 borderRectangle.Width - 9, borderRectangle.Height - 9);
698 Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
700 if ((!button.is_pressed || !button.Enabled) && !check_or_radio_checked)
701 Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
703 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
707 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
710 case 0: // normal or normal disabled button
711 Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
712 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
713 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
715 pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
716 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
717 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
719 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
720 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
721 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
723 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
724 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
725 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
727 case 1: // popup button normal (or pressed normal or popup button)
728 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
729 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
731 case 2: // popup button poped up
732 pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
733 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
734 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
736 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
737 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
738 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
740 case 3: // flat button not entered
741 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
742 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
749 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
751 // Need to draw a picture
758 int width = button.ClientSize.Width;
759 int height = button.ClientSize.Height;
761 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
762 i = button.image_list.Images[button.ImageIndex];
767 image_width = i.Width;
768 image_height = i.Height;
770 switch (button.ImageAlign) {
771 case ContentAlignment.TopLeft: {
777 case ContentAlignment.TopCenter: {
778 image_x = (width - image_width) / 2;
783 case ContentAlignment.TopRight: {
784 image_x = width - image_width - 5;
789 case ContentAlignment.MiddleLeft: {
791 image_y = (height - image_height) / 2;
795 case ContentAlignment.MiddleCenter: {
796 image_x = (width - image_width) / 2;
797 image_y = (height - image_height) / 2;
801 case ContentAlignment.MiddleRight: {
802 image_x = width - image_width - 4;
803 image_y = (height - image_height) / 2;
807 case ContentAlignment.BottomLeft: {
809 image_y = height - image_height - 4;
813 case ContentAlignment.BottomCenter: {
814 image_x = (width - image_width) / 2;
815 image_y = height - image_height - 4;
819 case ContentAlignment.BottomRight: {
820 image_x = width - image_width - 4;
821 image_y = height - image_height - 4;
832 dc.SetClip (new Rectangle(3, 3, width - 5, height - 5));
835 dc.DrawImage (i, image_x, image_y, image_width, image_height);
837 CPDrawImageDisabled (dc, i, image_x, image_y, ColorControl);
842 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
844 Color focus_color = button.ForeColor;
846 int inflate_value = -3;
848 if (!(button is CheckBox) && !(button is RadioButton)) {
851 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed)
852 focus_color = ControlPaint.Dark(button.BackColor);
854 dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y,
855 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
858 if (button.Focused) {
859 Rectangle rect = Rectangle.Inflate (button.ClientRectangle, inflate_value, inflate_value);
860 ControlPaint.DrawFocusRectangle (dc, rect);
864 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
866 Rectangle buttonRectangle = button.ClientRectangle;
867 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
869 if (button.is_pressed) {
874 // Ensure that at least one line is going to get displayed.
875 // Line limit does not ensure that despite its description.
876 text_rect.Height = Math.Max (button.Font.Height, text_rect.Height);
878 if (button.Enabled) {
879 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
881 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
882 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
884 CPDrawStringDisabled (dc, button.Text, button.Font, button.BackColor, text_rect, button.text_format);
889 public override Size ButtonBaseDefaultSize {
891 return new Size (75, 23);
894 #endregion // ButtonBase
897 public override void DrawCheckBox (Graphics g, CheckBox cb, Rectangle glyphArea, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
899 // Draw Button Background
900 if (cb.Appearance == Appearance.Button && cb.FlatStyle != FlatStyle.Flat)
901 ButtonBase_DrawButton (cb, g);
902 else if (cb.Appearance != Appearance.Button)
903 DrawCheckBoxGlyph (g, cb, glyphArea);
905 // Draw the borders and such for a Flat CheckBox Button
906 if (cb.Appearance == Appearance.Button && cb.FlatStyle == FlatStyle.Flat)
907 DrawFlatButton (g, cb, textBounds, imageBounds, clipRectangle);
909 // If we have an image, draw it
910 if (imageBounds.Size != Size.Empty)
911 DrawCheckBoxImage (g, cb, imageBounds);
913 if (cb.Focused && cb.Enabled && cb.ShowFocusCues && textBounds != Rectangle.Empty)
914 DrawCheckBoxFocus (g, cb, textBounds);
916 // If we have text, draw it
917 if (textBounds != Rectangle.Empty)
918 DrawCheckBoxText (g, cb, textBounds);
921 public virtual void DrawCheckBoxGlyph (Graphics g, CheckBox cb, Rectangle glyphArea)
924 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Pressed, cb.FlatStyle, cb.CheckState);
925 else if (cb.InternalSelected)
926 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
928 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Hot, cb.FlatStyle, cb.CheckState);
929 else if (!cb.Enabled)
930 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Disabled, cb.FlatStyle, cb.CheckState);
932 ThemeElements.CurrentTheme.CheckBoxPainter.PaintCheckBox (g, glyphArea, cb.BackColor, cb.ForeColor, ElementState.Normal, cb.FlatStyle, cb.CheckState);
935 public virtual void DrawCheckBoxFocus (Graphics g, CheckBox cb, Rectangle focusArea)
937 ControlPaint.DrawFocusRectangle (g, focusArea);
940 public virtual void DrawCheckBoxImage (Graphics g, CheckBox cb, Rectangle imageBounds)
943 g.DrawImage (cb.Image, imageBounds);
945 CPDrawImageDisabled (g, cb.Image, imageBounds.Left, imageBounds.Top, ColorControl);
948 public virtual void DrawCheckBoxText (Graphics g, CheckBox cb, Rectangle textBounds)
951 TextRenderer.DrawTextInternal (g, cb.Text, cb.Font, textBounds, cb.ForeColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
953 DrawStringDisabled20 (g, cb.Text, cb.Font, textBounds, cb.BackColor, cb.TextFormatFlags, cb.UseCompatibleTextRendering);
956 public override void CalculateCheckBoxTextAndImageLayout (ButtonBase button, Point p, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
958 int check_size = CheckSize;
960 if (button is CheckBox)
961 check_size = (button as CheckBox).Appearance == Appearance.Normal ? check_size : 0;
963 glyphArea = new Rectangle (button.Padding.Left, button.Padding.Top, check_size, check_size);
965 Rectangle content_rect = button.PaddingClientRectangle;
966 ContentAlignment align = ContentAlignment.TopLeft;
968 if (button is CheckBox)
969 align = (button as CheckBox).CheckAlign;
970 else if (button is RadioButton)
971 align = (button as RadioButton).CheckAlign;
974 case ContentAlignment.BottomCenter:
975 glyphArea.Y += content_rect.Height - check_size - 2;
976 glyphArea.X += (content_rect.Width - check_size) / 2;
978 case ContentAlignment.BottomLeft:
979 glyphArea.Y += content_rect.Height - check_size - 2;
980 content_rect.Width -= check_size;
981 content_rect.Offset (check_size, 0);
983 case ContentAlignment.BottomRight:
984 glyphArea.Y += content_rect.Height - check_size - 2;
985 glyphArea.X += content_rect.Width - check_size;
986 content_rect.Width -= check_size;
988 case ContentAlignment.MiddleCenter:
989 glyphArea.Y += (content_rect.Height - check_size) / 2;
990 glyphArea.X += (content_rect.Width - check_size) / 2;
992 case ContentAlignment.MiddleLeft:
993 glyphArea.Y += (content_rect.Height - check_size) / 2;
994 content_rect.Width -= check_size;
995 content_rect.Offset (check_size, 0);
997 case ContentAlignment.MiddleRight:
998 glyphArea.Y += (content_rect.Height - check_size) / 2;
999 glyphArea.X += content_rect.Width - check_size;
1000 content_rect.Width -= check_size;
1002 case ContentAlignment.TopCenter:
1003 glyphArea.X += (content_rect.Width - check_size) / 2;
1005 case ContentAlignment.TopLeft:
1006 content_rect.Width -= check_size;
1007 content_rect.Offset (check_size, 0);
1009 case ContentAlignment.TopRight:
1010 glyphArea.X += content_rect.Width - check_size;
1011 content_rect.Width -= check_size;
1015 Image image = button.Image;
1016 string text = button.Text;
1018 Size proposed = Size.Empty;
1020 // Force wrapping if we aren't AutoSize and our text is too long
1021 if (!button.AutoSize)
1022 proposed.Width = button.PaddingClientRectangle.Width - glyphArea.Width - 2;
1024 Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, proposed, button.TextFormatFlags, button.UseCompatibleTextRendering);
1026 // Text can't be bigger than the content rectangle
1027 text_size.Height = Math.Min (text_size.Height, content_rect.Height);
1028 text_size.Width = Math.Min (text_size.Width, content_rect.Width);
1030 Size image_size = image == null ? Size.Empty : image.Size;
1032 textRectangle = Rectangle.Empty;
1033 imageRectangle = Rectangle.Empty;
1035 switch (button.TextImageRelation) {
1036 case TextImageRelation.Overlay:
1037 // Text is centered vertically, and 2 pixels to the right
1038 textRectangle.X = content_rect.Left + 2;
1039 textRectangle.Y = button.PaddingClientRectangle.Top + ((content_rect.Height - text_size.Height) / 2) - 1;
1040 textRectangle.Size = text_size;
1042 // Image is dependent on ImageAlign
1046 int image_x = button.PaddingClientRectangle.Left;
1047 int image_y = button.PaddingClientRectangle.Top;
1048 int image_height = image.Height;
1049 int image_width = image.Width;
1051 switch (button.ImageAlign) {
1052 case System.Drawing.ContentAlignment.TopLeft:
1056 case System.Drawing.ContentAlignment.TopCenter:
1057 image_x += (content_rect.Width - image_width) / 2;
1060 case System.Drawing.ContentAlignment.TopRight:
1061 image_x += content_rect.Width - image_width - 5;
1064 case System.Drawing.ContentAlignment.MiddleLeft:
1066 image_y += (content_rect.Height - image_height) / 2;
1068 case System.Drawing.ContentAlignment.MiddleCenter:
1069 image_x += (content_rect.Width - image_width) / 2;
1070 image_y += (content_rect.Height - image_height) / 2;
1072 case System.Drawing.ContentAlignment.MiddleRight:
1073 image_x += content_rect.Width - image_width - 4;
1074 image_y += (content_rect.Height - image_height) / 2;
1076 case System.Drawing.ContentAlignment.BottomLeft:
1078 image_y += content_rect.Height - image_height - 4;
1080 case System.Drawing.ContentAlignment.BottomCenter:
1081 image_x += (content_rect.Width - image_width) / 2;
1082 image_y += content_rect.Height - image_height - 4;
1084 case System.Drawing.ContentAlignment.BottomRight:
1085 image_x += content_rect.Width - image_width - 4;
1086 image_y += content_rect.Height - image_height - 4;
1094 imageRectangle = new Rectangle (image_x + check_size, image_y, image_width, image_height);
1096 case TextImageRelation.ImageAboveText:
1097 content_rect.Inflate (-4, -4);
1098 LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1100 case TextImageRelation.TextAboveImage:
1101 content_rect.Inflate (-4, -4);
1102 LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1104 case TextImageRelation.ImageBeforeText:
1105 content_rect.Inflate (-4, -4);
1106 LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1108 case TextImageRelation.TextBeforeImage:
1109 content_rect.Inflate (-4, -4);
1110 LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
1115 public override Size CalculateCheckBoxAutoSize (CheckBox checkBox)
1117 Size ret_size = Size.Empty;
1118 Size text_size = TextRenderer.MeasureTextInternal (checkBox.Text, checkBox.Font, checkBox.UseCompatibleTextRendering);
1119 Size image_size = checkBox.Image == null ? Size.Empty : checkBox.Image.Size;
1121 // Pad the text size
1122 if (checkBox.Text.Length != 0) {
1123 text_size.Height += 4;
1124 text_size.Width += 4;
1127 switch (checkBox.TextImageRelation) {
1128 case TextImageRelation.Overlay:
1129 ret_size.Height = Math.Max (checkBox.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
1130 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
1132 case TextImageRelation.ImageAboveText:
1133 case TextImageRelation.TextAboveImage:
1134 ret_size.Height = text_size.Height + image_size.Height;
1135 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
1137 case TextImageRelation.ImageBeforeText:
1138 case TextImageRelation.TextBeforeImage:
1139 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
1140 ret_size.Width = text_size.Width + image_size.Width;
1145 ret_size.Height += (checkBox.Padding.Vertical);
1146 ret_size.Width += (checkBox.Padding.Horizontal) + 15;
1148 // There seems to be a minimum height
1149 if (ret_size.Height == checkBox.Padding.Vertical)
1150 ret_size.Height += 14;
1155 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
1156 StringFormat text_format;
1157 Rectangle client_rectangle;
1158 Rectangle text_rectangle;
1159 Rectangle checkbox_rectangle;
1160 int checkmark_size = CheckSize;
1161 int checkmark_space = 4;
1163 client_rectangle = checkbox.ClientRectangle;
1164 text_rectangle = client_rectangle;
1165 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
1167 text_format = new StringFormat();
1168 text_format.Alignment = StringAlignment.Near;
1169 text_format.LineAlignment = StringAlignment.Center;
1170 if (checkbox.ShowKeyboardCuesInternal)
1171 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1173 text_format.HotkeyPrefix = HotkeyPrefix.Hide;
1175 /* Calculate the position of text and checkbox rectangle */
1176 if (checkbox.appearance!=Appearance.Button) {
1177 switch(checkbox.check_alignment) {
1178 case ContentAlignment.BottomCenter: {
1179 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1180 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1181 text_rectangle.X=client_rectangle.X;
1182 text_rectangle.Width=client_rectangle.Width;
1183 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
1187 case ContentAlignment.BottomLeft: {
1188 checkbox_rectangle.X=client_rectangle.Left;
1189 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1190 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1191 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1195 case ContentAlignment.BottomRight: {
1196 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1197 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
1198 text_rectangle.X=client_rectangle.X;
1199 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1203 case ContentAlignment.MiddleCenter: {
1204 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1205 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1206 text_rectangle.X=client_rectangle.X;
1207 text_rectangle.Width=client_rectangle.Width;
1212 case ContentAlignment.MiddleLeft: {
1213 checkbox_rectangle.X=client_rectangle.Left;
1214 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1215 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1216 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1220 case ContentAlignment.MiddleRight: {
1221 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1222 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
1223 text_rectangle.X=client_rectangle.X;
1224 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1228 case ContentAlignment.TopCenter: {
1229 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
1230 checkbox_rectangle.Y=client_rectangle.Top;
1231 text_rectangle.X=client_rectangle.X;
1232 text_rectangle.Width=client_rectangle.Width;
1233 text_rectangle.Y=checkmark_size+checkmark_space;
1234 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
1238 case ContentAlignment.TopLeft: {
1239 checkbox_rectangle.X=client_rectangle.Left;
1240 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
1241 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1245 case ContentAlignment.TopRight: {
1246 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
1247 text_rectangle.X=client_rectangle.X;
1248 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
1253 text_rectangle.X=client_rectangle.X;
1254 text_rectangle.Width=client_rectangle.Width;
1257 /* Set the horizontal alignment of our text */
1258 switch(checkbox.text_alignment) {
1259 case ContentAlignment.BottomLeft:
1260 case ContentAlignment.MiddleLeft:
1261 case ContentAlignment.TopLeft: {
1262 text_format.Alignment=StringAlignment.Near;
1266 case ContentAlignment.BottomCenter:
1267 case ContentAlignment.MiddleCenter:
1268 case ContentAlignment.TopCenter: {
1269 text_format.Alignment=StringAlignment.Center;
1273 case ContentAlignment.BottomRight:
1274 case ContentAlignment.MiddleRight:
1275 case ContentAlignment.TopRight: {
1276 text_format.Alignment=StringAlignment.Far;
1281 /* Set the vertical alignment of our text */
1282 switch(checkbox.text_alignment) {
1283 case ContentAlignment.TopLeft:
1284 case ContentAlignment.TopCenter:
1285 case ContentAlignment.TopRight: {
1286 text_format.LineAlignment=StringAlignment.Near;
1290 case ContentAlignment.BottomLeft:
1291 case ContentAlignment.BottomCenter:
1292 case ContentAlignment.BottomRight: {
1293 text_format.LineAlignment=StringAlignment.Far;
1297 case ContentAlignment.MiddleLeft:
1298 case ContentAlignment.MiddleCenter:
1299 case ContentAlignment.MiddleRight: {
1300 text_format.LineAlignment=StringAlignment.Center;
1305 ButtonState state = ButtonState.Normal;
1306 if (checkbox.FlatStyle == FlatStyle.Flat) {
1307 state |= ButtonState.Flat;
1310 if (checkbox.Checked) {
1311 state |= ButtonState.Checked;
1314 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
1315 state |= ButtonState.Checked;
1316 state |= ButtonState.Pushed;
1319 // finally make sure the pushed and inavtive states are rendered
1320 if (!checkbox.Enabled) {
1321 state |= ButtonState.Inactive;
1323 else if (checkbox.is_pressed) {
1324 state |= ButtonState.Pushed;
1329 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
1331 if ((checkbox.image != null) || (checkbox.image_list != null))
1332 ButtonBase_DrawImage(checkbox, dc);
1334 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
1336 if (checkbox.Focused && checkbox.Enabled && checkbox.appearance != Appearance.Button && checkbox.Text != String.Empty && checkbox.ShowFocusCues) {
1337 SizeF text_size = dc.MeasureString (checkbox.Text, checkbox.Font);
1339 Rectangle focus_rect = Rectangle.Empty;
1340 focus_rect.X = text_rectangle.X;
1341 focus_rect.Y = (int)((text_rectangle.Height - text_size.Height) / 2);
1342 focus_rect.Size = text_size.ToSize ();
1343 CheckBox_DrawFocus (checkbox, dc, focus_rect);
1346 text_format.Dispose ();
1349 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
1351 Brush brush = checkbox.BackColor.ToArgb () == ColorControl.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
1352 dc.FillRectangle (brush, checkbox.ClientRectangle);
1353 // render as per normal button
1354 if (checkbox.appearance==Appearance.Button) {
1355 ButtonBase_DrawButton (checkbox, dc);
1357 if ((checkbox.Focused) && checkbox.Enabled)
1358 ButtonBase_DrawFocus(checkbox, dc);
1360 // establish if we are rendering a flat style of some sort
1361 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
1362 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
1364 CPDrawCheckBox (dc, checkbox_rectangle, state);
1369 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
1371 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
1372 text_format, checkbox.Appearance, checkbox.Checked);
1375 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
1377 DrawInnerFocusRectangle (dc, text_rectangle, checkbox.BackColor);
1380 // renders a checkBox with the Flat and Popup FlatStyle
1381 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
1385 Rectangle checkbox_rectangle;
1386 Rectangle fill_rectangle;
1390 // set up our rectangles first
1391 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
1392 // clip one pixel from bottom right for non popup rendered checkboxes
1393 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
1394 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));
1396 // clip two pixels from bottom right for non popup rendered checkboxes
1397 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
1398 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));
1402 // if disabled render in disabled state
1403 if (checkbox.Enabled) {
1404 // process the state of the checkbox
1405 if (checkbox.is_entered || checkbox.Capture) {
1406 // decide on which background color to use
1407 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
1408 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1409 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
1410 if (!checkbox.is_pressed) {
1411 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1413 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1415 // use regular window background color
1416 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1419 // render the outer border
1420 if (checkbox.FlatStyle == FlatStyle.Flat) {
1421 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1423 // draw sunken effect
1424 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
1427 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1429 if (checkbox.FlatStyle == FlatStyle.Flat) {
1430 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1432 // draw the outer border
1433 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
1437 if (checkbox.FlatStyle == FlatStyle.Popup) {
1438 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
1441 // draw disabled state,
1442 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
1445 if (checkbox.Checked) {
1446 /* Need to draw a check-mark */
1448 /* Make sure we've got at least a line width of 1 */
1449 lineWidth = Math.Max(3, fill_rectangle.Width/3);
1450 Scale=Math.Max(1, fill_rectangle.Width/9);
1452 // flat style check box is rendered inside a rectangle shifted down by one
1453 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
1454 if (checkbox.Enabled) {
1455 pen=ResPool.GetPen(checkbox.ForeColor);
1457 pen=SystemPens.ControlDark;
1460 for (int i=0; i<lineWidth; i++) {
1461 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
1462 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);
1467 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
1468 StringFormat text_format, Appearance appearance, bool ischecked)
1470 // offset the text if it's pressed and a button
1471 if (appearance == Appearance.Button) {
1472 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
1473 text_rectangle.X ++;
1474 text_rectangle.Y ++;
1477 text_rectangle.Inflate (-4, -4);
1480 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
1482 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
1483 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
1484 text_format.FormatFlags |= StringFormatFlags.NoWrap;
1486 if (button_base.Enabled) {
1487 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
1488 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
1489 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
1491 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
1494 #endregion // CheckBox
1496 #region CheckedListBox
1498 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
1500 Color back_color, fore_color;
1501 Rectangle item_rect = e.Bounds;
1506 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
1507 state = ButtonState.Checked;
1508 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
1509 state |= ButtonState.Inactive;
1511 state = ButtonState.Normal;
1513 if (ctrl.ThreeDCheckBoxes == false)
1514 state |= ButtonState.Flat;
1516 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, CheckSize, CheckSize);
1517 ControlPaint.DrawCheckBox (e.Graphics,
1518 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
1519 checkbox_rect.Width, checkbox_rect.Height,
1522 item_rect.X += checkbox_rect.Right;
1523 item_rect.Width -= checkbox_rect.Right;
1526 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1527 back_color = ColorHighlight;
1528 fore_color = ColorHighlightText;
1531 back_color = e.BackColor;
1532 fore_color = e.ForeColor;
1535 e.Graphics.FillRectangle (ResPool.GetSolidBrush
1536 (back_color), item_rect);
1538 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1539 ResPool.GetSolidBrush (fore_color),
1540 item_rect, ctrl.StringFormat);
1542 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1543 CPDrawFocusRectangle (e.Graphics, item_rect,
1544 fore_color, back_color);
1548 #endregion // CheckedListBox
1551 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
1553 Color back_color, fore_color;
1554 Rectangle text_draw = e.Bounds;
1555 StringFormat string_format = new StringFormat ();
1556 string_format.FormatFlags = StringFormatFlags.LineLimit;
1558 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1559 back_color = ColorHighlight;
1560 fore_color = ColorHighlightText;
1563 back_color = e.BackColor;
1564 fore_color = e.ForeColor;
1568 fore_color = ColorInactiveCaptionText;
1570 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1572 if (e.Index != -1) {
1573 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1574 ResPool.GetSolidBrush (fore_color),
1575 text_draw, string_format);
1578 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1579 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1582 string_format.Dispose ();
1585 public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
1587 Point[] arrow = new Point[3];
1597 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
1598 centerX=rect.Left+rect.Width/2;
1599 centerY=rect.Top+rect.Height/2;
1600 shiftX=Math.Max(1, rect.Width/8);
1601 shiftY=Math.Max(1, rect.Height/8);
1603 if ((state & ButtonState.Pushed)!=0) {
1610 P1=new Point(rect.Left + 1, centerY);
1611 P2=new Point(rect.Right - 1, centerY);
1612 P3=new Point(centerX, rect.Bottom - 1);
1618 /* Draw the arrow */
1619 if ((state & ButtonState.Inactive)!=0) {
1620 /* Move away from the shadow */
1621 arrow[0].X += 1; arrow[0].Y += 1;
1622 arrow[1].X += 1; arrow[1].Y += 1;
1623 arrow[2].X += 1; arrow[2].Y += 1;
1625 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
1631 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
1633 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
1636 public override void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state)
1638 CPDrawComboButton (g, area, state);
1640 public override bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state)
1644 public override bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox)
1648 public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
1650 if (!comboBox.Enabled)
1651 g.FillRectangle (ResPool.GetSolidBrush (ColorControl), comboBox.ClientRectangle);
1653 if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
1654 g.FillRectangle (ResPool.GetSolidBrush (comboBox.Parent.BackColor), comboBox.ClientRectangle);
1656 if (style == FlatStyle.Popup && (comboBox.Entered || comboBox.Focused)) {
1657 Rectangle area = comboBox.TextArea;
1660 g.DrawRectangle (ResPool.GetPen (SystemColors.ControlDark), area);
1661 g.DrawLine (ResPool.GetPen (SystemColors.ControlDark), comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Top, comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Bottom);
1663 bool is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
1664 if (!is_flat && clippingArea.IntersectsWith (comboBox.TextArea))
1665 ControlPaint.DrawBorder3D (g, comboBox.TextArea, Border3DStyle.Sunken);
1667 public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
1674 public override int DataGridPreferredColumnWidth { get { return 75;} }
1675 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
1676 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
1677 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
1678 public override Color DataGridBackColor { get { return ColorWindow;} }
1679 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
1680 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
1681 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
1682 public override Color DataGridGridLineColor { get { return ColorControl;} }
1683 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
1684 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
1685 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
1686 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
1687 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
1688 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
1689 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
1690 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
1692 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
1694 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
1695 DataGridPaintParentRows (pe.Graphics, pe.ClipRectangle, grid);
1696 DataGridPaintColumnHeaders (pe.Graphics, pe.ClipRectangle, grid);
1697 DataGridPaintRows (pe.Graphics, grid.cells_area, pe.ClipRectangle, grid);
1699 // Paint scrollBar corner
1700 if (grid.VScrollBar.Visible && grid.HScrollBar.Visible) {
1702 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.VScrollBar.Width,
1703 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.HScrollBar.Height,
1704 grid.VScrollBar.Width, grid.HScrollBar.Height);
1706 if (pe.ClipRectangle.IntersectsWith (corner)) {
1707 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1713 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
1715 Rectangle bounds = clip;
1716 bounds.Intersect (grid.caption_area);
1719 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor), bounds);
1722 g.DrawLine (ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor),
1723 bounds.X, bounds.Y + bounds.Height -1,
1724 bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1727 if (grid.CaptionText != String.Empty) {
1728 Rectangle text_rect = grid.caption_area;
1729 text_rect.Y += text_rect.Height / 2 - grid.CaptionFont.Height / 2;
1730 text_rect.Height = grid.CaptionFont.Height;
1732 g.DrawString (grid.CaptionText, grid.CaptionFont,
1733 ResPool.GetSolidBrush (grid.CaptionForeColor),
1738 if (bounds.IntersectsWith (grid.back_button_rect)) {
1739 g.DrawImage (grid.back_button_image, grid.back_button_rect);
1740 if (grid.back_button_mouseover) {
1741 CPDrawBorder3D (g, grid.back_button_rect, grid.back_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1746 if (bounds.IntersectsWith (grid.parent_rows_button_rect)) {
1747 g.DrawImage (grid.parent_rows_button_image, grid.parent_rows_button_rect);
1748 if (grid.parent_rows_button_mouseover) {
1749 CPDrawBorder3D (g, grid.parent_rows_button_rect, grid.parent_rows_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1754 public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
1756 if (!grid.CurrentTableStyle.ColumnHeadersVisible)
1759 Rectangle columns_area = grid.column_headers_area;
1761 // Paint corner shared between row and column header
1762 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1763 Rectangle rect_bloc = grid.column_headers_area;
1764 rect_bloc.Width = grid.RowHeaderWidth;
1765 if (clip.IntersectsWith (rect_bloc)) {
1767 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
1769 CPDrawBorder3D (g, rect_bloc, Border3DStyle.RaisedInner,
1770 Border3DSide.Left | Border3DSide.Right |
1771 Border3DSide.Top | Border3DSide.Bottom | Border3DSide.Middle,
1772 grid.CurrentTableStyle.CurrentHeaderBackColor);
1775 columns_area.X += grid.RowHeaderWidth;
1776 columns_area.Width -= grid.RowHeaderWidth;
1779 // Set column painting
1780 Rectangle rect_columnhdr = new Rectangle ();
1782 Region current_clip;
1783 Region prev_clip = g.Clip;
1784 rect_columnhdr.Y = columns_area.Y;
1785 rect_columnhdr.Height = columns_area.Height;
1787 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1788 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1789 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
1792 col_pixel = grid.GetColumnStartingPixel (column);
1793 rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
1794 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1796 if (clip.IntersectsWith (rect_columnhdr) == false)
1799 current_clip = new Region (rect_columnhdr);
1800 current_clip.Intersect (columns_area);
1801 current_clip.Intersect (prev_clip);
1802 g.Clip = current_clip;
1804 DataGridPaintColumnHeader (g, rect_columnhdr, grid, column);
1806 current_clip.Dispose ();
1811 Rectangle not_usedarea = grid.column_headers_area;
1812 not_usedarea.X = (column_cnt == 0) ? grid.RowHeaderWidth : rect_columnhdr.X + rect_columnhdr.Width;
1813 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - not_usedarea.X;
1814 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1817 public override void DataGridPaintColumnHeader (Graphics g, Rectangle bounds, DataGrid grid, int col)
1820 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.HeaderBackColor), bounds);
1823 if (!grid.FlatMode) {
1824 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1825 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1828 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1829 bounds.X, bounds.Y, bounds.X, bounds.Y + bounds.Height);
1831 g.DrawLine (ResPool.GetPen (ColorControlLightLight),
1832 bounds.X, bounds.Y + 2, bounds.X, bounds.Y + bounds.Height - 3);
1835 if (col == (grid.VisibleColumnCount -1)) {
1836 g.DrawLine (ResPool.GetPen (ColorControlDark),
1837 bounds.X + bounds.Width - 1, bounds.Y,
1838 bounds.X + bounds.Width - 1, bounds.Y + bounds.Height);
1840 g.DrawLine (ResPool.GetPen (ColorControlDark),
1841 bounds.X + bounds.Width - 1, bounds.Y + 2,
1842 bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 3);
1845 g.DrawLine (ResPool.GetPen (ColorControlDark),
1846 bounds.X, bounds.Y + bounds.Height - 1,
1847 bounds.X + bounds.Width, bounds.Y + bounds.Height - 1);
1853 DataGridColumnStyle style = grid.CurrentTableStyle.GridColumnStyles[col];
1855 if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No)
1859 StringFormat format = new StringFormat ();
1860 format.FormatFlags |= StringFormatFlags.NoWrap;
1861 format.LineAlignment = StringAlignment.Center;
1862 format.Trimming = StringTrimming.Character;
1864 g.DrawString (style.HeaderText, grid.CurrentTableStyle.HeaderFont,
1865 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1869 if (style.ArrowDrawingMode != DataGridColumnStyle.ArrowDrawing.No) {
1870 Point pnt = new Point (bounds.X + bounds.Width + 4, bounds.Y + ((bounds.Height - 6)/2));
1872 if (style.ArrowDrawingMode == DataGridColumnStyle.ArrowDrawing.Ascending) {
1873 g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y + 6, pnt.X + 3, pnt.Y);
1874 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 6, pnt.Y + 6);
1875 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y + 6, pnt.X + 3, pnt.Y);
1877 g.DrawLine (SystemPens.ControlLightLight, pnt.X + 6, pnt.Y, pnt.X + 3, pnt.Y + 6);
1878 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 6, pnt.Y);
1879 g.DrawLine (SystemPens.ControlDark, pnt.X, pnt.Y, pnt.X + 3, pnt.Y + 6);
1884 public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
1886 Rectangle rect_row = new Rectangle ();
1888 rect_row.X = grid.ParentRowsArea.X;
1889 rect_row.Width = grid.ParentRowsArea.Width;
1890 rect_row.Height = (grid.CaptionFont.Height + 3);
1892 object[] parentRows = grid.data_source_stack.ToArray();
1894 Region current_clip;
1895 Region prev_clip = g.Clip;
1896 for (int row = 0; row < parentRows.Length; row++) {
1897 rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
1899 if (clip.IntersectsWith (rect_row) == false)
1902 current_clip = new Region (rect_row);
1903 current_clip.Intersect (prev_clip);
1904 g.Clip = current_clip;
1906 DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);
1908 current_clip.Dispose ();
1914 public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
1917 g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1920 Font bold_font = new Font (grid.Font.FontFamily, grid.Font.Size, grid.Font.Style | FontStyle.Bold);
1921 // set up some standard string formating variables
1922 StringFormat text_format = new StringFormat();
1923 text_format.LineAlignment = StringAlignment.Center;
1924 text_format.Alignment = StringAlignment.Near;
1926 string table_name = "";
1927 if (row.view is DataRowView)
1928 table_name = ((ITypedList)((DataRowView)row.view).DataView).GetListName (null) + ": ";
1931 Rectangle text_rect;
1934 text_size = g.MeasureString (table_name, bold_font).ToSize();
1935 text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
1937 g.DrawString (table_name,
1938 bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1940 foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)row.view).GetProperties()) {
1941 if (typeof(IBindingList).IsAssignableFrom (pd.PropertyType))
1944 text_rect.X += text_rect.Size.Width + 5;
1946 string text = String.Format ("{0}: {1}",
1948 pd.GetValue (row.view));
1950 text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
1951 text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
1954 grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1958 if (!grid.FlatMode) {
1959 CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
1960 Border3DSide.Left | Border3DSide.Right |
1961 Border3DSide.Top | Border3DSide.Bottom);
1965 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1967 Point[] arrow = new Point[3];
1969 int centerX, centerY, shiftX;
1972 rect = new Rectangle (bounds.X + bounds.Width /4,
1973 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1975 centerX = rect.Left + rect.Width / 2;
1976 centerY = rect.Top + rect.Height / 2;
1977 shiftX = Math.Max (1, rect.Width / 8);
1980 P1 = new Point (centerX, rect.Top - 1);
1981 P2 = new Point (centerX, rect.Bottom);
1982 P3 = new Point (rect.Right, centerY);
1987 g.FillPolygon (ResPool.GetSolidBrush
1988 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1991 public override void DataGridPaintRowHeaderStar (Graphics g, Rectangle bounds, DataGrid grid)
1993 int x = bounds.X + 4;
1994 int y = bounds.Y + 3;
1995 Pen pen = ResPool.GetPen (grid.CurrentTableStyle.CurrentHeaderForeColor);
1997 g.DrawLine (pen, x + 4, y, x + 4, y + 8);
1998 g.DrawLine (pen, x, y + 4, x + 8, y + 4);
1999 g.DrawLine (pen, x + 1, y + 1, x + 7, y + 7);
2000 g.DrawLine (pen, x + 7, y + 1, x + 1, y + 7);
2003 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
2005 bool is_add_row = grid.ShowEditRow && row == grid.DataGridRows.Length - 1;
2006 bool is_current_row = row == grid.CurrentCell.RowNumber;
2009 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), bounds);
2012 if (is_current_row) {
2013 if (grid.IsChanging) {
2014 g.DrawString ("...", grid.Font,
2015 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
2018 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
2019 DataGridPaintRowHeaderArrow (g, rect, grid);
2022 else if (is_add_row) {
2023 DataGridPaintRowHeaderStar (g, bounds, grid);
2026 if (!grid.FlatMode && !is_add_row) {
2027 CPDrawBorder3D (g, bounds, Border3DStyle.RaisedInner,
2028 Border3DSide.Left | Border3DSide.Right |
2029 Border3DSide.Top | Border3DSide.Bottom);
2033 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
2035 Rectangle rect_row = new Rectangle ();
2036 Rectangle not_usedarea = new Rectangle ();
2038 int rowcnt = grid.VisibleRowCount;
2040 bool showing_add_row = false;
2042 if (grid.RowsCount < grid.DataGridRows.Length) {
2043 /* the table has an add row */
2045 if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.DataGridRows.Length) {
2046 showing_add_row = true;
2050 rect_row.Width = cells.Width + grid.RowHeadersArea.Width;
2051 for (int r = 0; r < rowcnt; r++) {
2052 int row = grid.FirstVisibleRow + r;
2053 if (row == grid.DataGridRows.Length - 1)
2054 rect_row.Height = grid.DataGridRows[row].Height;
2056 rect_row.Height = grid.DataGridRows[row + 1].VerticalOffset - grid.DataGridRows[row].VerticalOffset;
2057 rect_row.Y = cells.Y + grid.DataGridRows[row].VerticalOffset - grid.DataGridRows[grid.FirstVisibleRow].VerticalOffset;
2058 if (clip.IntersectsWith (rect_row)) {
2059 if (grid.CurrentTableStyle.HasRelations
2060 && !(showing_add_row && row == grid.DataGridRows.Length - 1))
2061 DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
2063 DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.DataGridRows.Length - 1, clip, grid);
2068 // the rowcnt == 0 check is needed because
2069 // otherwise we'd draw over the caption on
2070 // empty datasources (since rect_row would be
2073 not_usedarea.Y = cells.Y;
2075 not_usedarea.Y = rect_row.Y + rect_row.Height;
2076 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
2077 not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
2079 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
2082 public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2083 Rectangle clip, DataGrid grid)
2085 Rectangle rect_header;
2086 Rectangle icon_bounds = new Rectangle ();
2087 Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor);
2089 /* paint the header if it's visible and intersects the clip */
2090 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
2091 rect_header = row_rect;
2092 rect_header.Width = grid.RowHeaderWidth;
2093 row_rect.X += grid.RowHeaderWidth;
2094 if (clip.IntersectsWith (rect_header)) {
2095 DataGridPaintRowHeader (g, rect_header, row, grid);
2098 icon_bounds = rect_header;
2099 icon_bounds.X += icon_bounds.Width / 2;
2101 icon_bounds.Width = 8;
2102 icon_bounds.Height = 8;
2104 g.DrawRectangle (pen, icon_bounds);
2106 /* the - part of the icon */
2108 icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2,
2109 icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2);
2111 if (!grid.IsExpanded (row)) {
2112 /* the | part of the icon */
2114 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2,
2115 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2);
2119 Rectangle nested_rect = row_rect;
2121 if (grid.DataGridRows[row].IsExpanded)
2122 nested_rect.Height -= grid.DataGridRows[row].RelationHeight;
2124 DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
2126 if (grid.DataGridRows[row].IsExpanded) {
2127 // XXX we should create this in the
2128 // datagrid and cache it for use by
2129 // the theme instead of doing it each
2130 // time through here
2131 string[] relations = grid.CurrentTableStyle.Relations;
2132 StringBuilder relation_builder = new StringBuilder ("");
2134 for (int i = 0; i < relations.Length; i ++) {
2136 relation_builder.Append ("\n");
2138 relation_builder.Append (relations[i]);
2140 string relation_text = relation_builder.ToString ();
2142 StringFormat string_format = new StringFormat ();
2143 string_format.FormatFlags |= StringFormatFlags.NoWrap;
2146 //Region prev_clip = g.Clip;
2147 //Region current_clip;
2148 Rectangle rect_cell = row_rect;
2150 rect_cell.X = nested_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
2151 rect_cell.Y += nested_rect.Height;
2152 rect_cell.Height = grid.DataGridRows[row].RelationHeight;
2154 rect_cell.Width = 0;
2155 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
2156 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
2157 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
2159 rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width;
2161 rect_cell.Width = Math.Max (rect_cell.Width, grid.DataGridRows[row].relation_area.Width);
2163 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
2167 /* draw the line leading from the +/- to the relation area */
2168 Rectangle outline = grid.DataGridRows[row].relation_area;
2169 outline.Y = rect_cell.Y;
2173 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
2174 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2);
2177 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
2178 outline.X, outline.Y + outline.Height / 2);
2180 g.DrawRectangle (pen, outline);
2182 g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor),
2183 outline, string_format);
2185 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
2186 Rectangle not_usedarea = new Rectangle ();
2187 not_usedarea.X = rect_cell.X + rect_cell.Width;
2188 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
2189 not_usedarea.Y = row_rect.Y;
2190 not_usedarea.Height = row_rect.Height;
2191 if (clip.IntersectsWith (not_usedarea))
2192 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
2198 public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2199 Rectangle clip, DataGrid grid)
2201 Rectangle rect_cell = new Rectangle ();
2203 Color backcolor, forecolor;
2204 Brush backBrush, foreBrush;
2205 Rectangle not_usedarea = Rectangle.Empty;
2207 rect_cell.Y = row_rect.Y;
2208 rect_cell.Height = row_rect.Height;
2210 if (grid.IsSelected (row)) {
2211 backcolor = grid.SelectionBackColor;
2212 forecolor = grid.SelectionForeColor;
2215 backcolor = grid.BackColor;
2217 backcolor = grid.AlternatingBackColor;
2220 forecolor = grid.ForeColor;
2224 backBrush = ResPool.GetSolidBrush (backcolor);
2225 foreBrush = ResPool.GetSolidBrush (forecolor);
2227 // PaintCells at row, column
2228 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
2229 DataGridCell current_cell = grid.CurrentCell;
2231 if (column_cnt > 0) {
2232 Region prev_clip = g.Clip;
2233 Region current_clip;
2235 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
2236 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
2239 col_pixel = grid.GetColumnStartingPixel (column);
2241 rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
2242 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
2244 if (clip.IntersectsWith (rect_cell)) {
2245 current_clip = new Region (rect_cell);
2246 current_clip.Intersect (row_rect);
2247 current_clip.Intersect (prev_clip);
2248 g.Clip = current_clip;
2250 Brush colBackBrush = backBrush;
2251 Brush colForeBrush = foreBrush;
2253 // If we are in the precise cell we are editing, then use the normal colors
2254 // even if we are selected.
2255 if (grid.is_editing && column == current_cell.ColumnNumber && row == current_cell.RowNumber) {
2256 colBackBrush = ResPool.GetSolidBrush (grid.BackColor);
2257 colForeBrush = ResPool.GetSolidBrush (grid.ForeColor);
2261 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
2265 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
2268 grid.RightToLeft == RightToLeft.Yes);
2271 current_clip.Dispose ();
2277 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
2278 not_usedarea.X = rect_cell.X + rect_cell.Width;
2279 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
2280 not_usedarea.Y = row_rect.Y;
2281 not_usedarea.Height = row_rect.Height;
2285 not_usedarea = row_rect;
2288 if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea))
2289 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
2293 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
2294 Rectangle clip, DataGrid grid)
2296 /* paint the header if it's visible and intersects the clip */
2297 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
2298 Rectangle rect_header = row_rect;
2299 rect_header.Width = grid.RowHeaderWidth;
2300 row_rect.X += grid.RowHeaderWidth;
2301 if (clip.IntersectsWith (rect_header)) {
2302 DataGridPaintRowHeader (g, rect_header, row, grid);
2306 DataGridPaintRowContents (g, row, row_rect, is_newrow, clip, grid);
2309 #endregion // Datagrid
2311 #region DataGridView
2312 #region DataGridViewHeaderCell
2313 #region DataGridViewRowHeaderCell
2314 public override bool DataGridViewRowHeaderCellDrawBackground (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
2319 public override bool DataGridViewRowHeaderCellDrawSelectionBackground (DataGridViewRowHeaderCell cell)
2324 public override bool DataGridViewRowHeaderCellDrawBorder (DataGridViewRowHeaderCell cell, Graphics g, Rectangle bounds)
2330 #region DataGridViewColumnHeaderCell
2331 public override bool DataGridViewColumnHeaderCellDrawBackground (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
2336 public override bool DataGridViewColumnHeaderCellDrawBorder (DataGridViewColumnHeaderCell cell, Graphics g, Rectangle bounds)
2342 public override bool DataGridViewHeaderCellHasPressedStyle (DataGridView dataGridView)
2347 public override bool DataGridViewHeaderCellHasHotStyle (DataGridView dataGridView)
2354 #region DateTimePicker
2355 protected virtual void DateTimePickerDrawBorder (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
2357 this.CPDrawBorder3D (g, dateTimePicker.ClientRectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dateTimePicker.BackColor);
2360 protected virtual void DateTimePickerDrawDropDownButton (DateTimePicker dateTimePicker, Graphics g, Rectangle clippingArea)
2362 ButtonState state = dateTimePicker.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
2363 g.FillRectangle (ResPool.GetSolidBrush (ColorControl), dateTimePicker.drop_down_arrow_rect);
2364 this.CPDrawComboButton (
2366 dateTimePicker.drop_down_arrow_rect,
2370 public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp)
2373 if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle))
2376 // draw the outer border
2377 Rectangle button_bounds = dtp.ClientRectangle;
2378 DateTimePickerDrawBorder (dtp, dc, clip_rectangle);
2380 // deflate by the border width
2381 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
2382 button_bounds.Inflate (-2,-2);
2383 if (!dtp.ShowUpDown) {
2384 DateTimePickerDrawDropDownButton (dtp, dc, clip_rectangle);
2386 ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal;
2387 ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal;
2388 Rectangle up_bounds = dtp.drop_down_arrow_rect;
2389 Rectangle down_bounds = dtp.drop_down_arrow_rect;
2391 up_bounds.Height = up_bounds.Height / 2;
2392 down_bounds.Y = up_bounds.Height;
2393 down_bounds.Height = dtp.Height - up_bounds.Height;
2394 if (down_bounds.Height > up_bounds.Height)
2397 down_bounds.Height -= 1;
2400 up_bounds.Inflate (-1, -1);
2401 down_bounds.Inflate (-1, -1);
2403 ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state);
2404 ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state);
2408 // render the date part
2409 if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
2412 // fill the background
2413 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
2415 // Update date_area_rect if we are drawing the checkbox
2416 Rectangle date_area_rect = dtp.date_area_rect;
2417 if (dtp.ShowCheckBox) {
2418 Rectangle check_box_rect = dtp.CheckBoxRect;
2419 date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
2420 date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;
2422 ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
2423 CPDrawCheckBox(dc, check_box_rect, bs);
2425 if (dtp.is_checkbox_selected)
2426 CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
2429 // render each text part
2430 using (StringFormat text_format = StringFormat.GenericTypographic)
2432 text_format.LineAlignment = StringAlignment.Near;
2433 text_format.Alignment = StringAlignment.Near;
2434 text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
2435 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
2437 // Calculate the rectangles for each part
2438 if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
2441 for (int i = 0; i < dtp.part_data.Length; i++)
2443 DateTimePicker.PartData fd = dtp.part_data[i];
2444 RectangleF text_rect = new RectangleF();
2445 string text = fd.GetText(dtp.Value);
2446 text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
2448 text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);
2451 text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
2453 text_rect.X = date_area_rect.X;
2456 text_rect.Inflate (1, 0);
2457 fd.drawing_rectangle = text_rect;
2461 // draw the text part
2462 Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ?
2463 SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false
2464 RectangleF clip_rectangleF = clip_rectangle;
2466 for (int i = 0; i < dtp.part_data.Length; i++)
2468 DateTimePicker.PartData fd = dtp.part_data [i];
2471 if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle))
2474 text = dtp.editing_part_index == i ? dtp.editing_text : fd.GetText (dtp.Value);
2476 PointF text_position = new PointF ();
2478 RectangleF text_rect;
2480 text_size = dc.MeasureString (text, dtp.Font, 250, text_format);
2481 text_position.X = (fd.drawing_rectangle.Left + fd.drawing_rectangle.Width / 2) - text_size.Width / 2;
2482 text_position.Y = (fd.drawing_rectangle.Top + fd.drawing_rectangle.Height / 2) - text_size.Height / 2;
2483 text_rect = new RectangleF (text_position, text_size);
2484 text_rect = RectangleF.Intersect (text_rect, date_area_rect);
2486 if (text_rect.IsEmpty)
2489 if (text_rect.Right >= date_area_rect.Right)
2490 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
2492 text_format.FormatFlags |= StringFormatFlags.NoClip;
2495 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
2496 dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format);
2499 dc.DrawString (text, dtp.Font, text_brush, text_rect, text_format);
2502 if (fd.drawing_rectangle.Right > date_area_rect.Right)
2503 break; // the next part would be not be visible, so don't draw anything more.
2508 public override bool DateTimePickerBorderHasHotElementStyle {
2514 public override Rectangle DateTimePickerGetDropDownButtonArea (DateTimePicker dateTimePicker)
2516 Rectangle rect = dateTimePicker.ClientRectangle;
2517 rect.X = rect.Right - SystemInformation.VerticalScrollBarWidth - 2;
2518 if (rect.Width > (SystemInformation.VerticalScrollBarWidth + 2)) {
2519 rect.Width = SystemInformation.VerticalScrollBarWidth;
2521 rect.Width = Math.Max (rect.Width - 2, 0);
2524 rect.Inflate (0, -2);
2528 public override Rectangle DateTimePickerGetDateArea (DateTimePicker dateTimePicker)
2530 Rectangle rect = dateTimePicker.ClientRectangle;
2531 if (dateTimePicker.ShowUpDown) {
2532 // set the space to the left of the up/down button
2533 if (rect.Width > (DateTimePicker.up_down_width + 4)) {
2534 rect.Width -= (DateTimePicker.up_down_width + 4);
2539 // set the space to the left of the up/down button
2540 // TODO make this use up down button
2541 if (rect.Width > (SystemInformation.VerticalScrollBarWidth + 4)) {
2542 rect.Width -= SystemInformation.VerticalScrollBarWidth;
2548 rect.Inflate (-2, -2);
2551 public override bool DateTimePickerDropDownButtonHasHotElementStyle {
2556 #endregion // DateTimePicker
2559 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
2560 StringFormat text_format;
2565 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
2567 text_format = new StringFormat();
2568 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2570 size = dc.MeasureString (box.Text, box.Font);
2573 if (size.Width > 0) {
2574 width = ((int) size.Width) + 7;
2576 if (width > box.Width - 16)
2577 width = box.Width - 16;
2580 y = box.Font.Height / 2;
2582 // Clip the are that the text will be in
2583 Region prev_clip = dc.Clip;
2584 dc.SetClip (new Rectangle (10, 0, width, box.Font.Height), CombineMode.Exclude);
2586 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
2587 dc.Clip = prev_clip;
2590 if (box.Text.Length != 0) {
2592 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
2594 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
2595 new RectangleF (10, 0, width, box.Font.Height), text_format);
2599 text_format.Dispose ();
2602 public override Size GroupBoxDefaultSize {
2604 return new Size (200,100);
2610 public override Size HScrollBarDefaultSize {
2612 return new Size (80, this.ScrollBarButtonSize);
2616 #endregion // HScrollBar
2620 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
2622 Color back_color, fore_color;
2624 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
2625 back_color = ColorHighlight;
2626 fore_color = ColorHighlightText;
2628 back_color = e.BackColor;
2629 fore_color = e.ForeColor;
2632 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
2634 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
2635 ResPool.GetSolidBrush (fore_color),
2636 e.Bounds, ctrl.StringFormat);
2638 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
2639 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
2646 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
2648 bool details = control.View == View.Details;
2649 int first = control.FirstVisibleIndex;
2650 int lastvisibleindex = control.LastVisibleIndex;
2652 if (control.VirtualMode)
2653 control.OnCacheVirtualItems (new CacheVirtualItemsEventArgs (first, lastvisibleindex));
2655 for (int i = first; i <= lastvisibleindex; i++) {
2656 ListViewItem item = control.GetItemAtDisplayIndex (i);
2657 if (clip.IntersectsWith (item.Bounds)) {
2658 bool owner_draw = false;
2659 if (control.OwnerDraw)
2660 owner_draw = DrawListViewItemOwnerDraw (dc, item, i);
2663 DrawListViewItem (dc, control, item);
2664 if (control.View == View.Details)
2665 DrawListViewSubItems (dc, control, item);
2670 if (control.UsingGroups) {
2671 // Use InternalCount instead of Count to take into account Default Group as needed
2672 for (int i = 0; i < control.Groups.InternalCount; i++) {
2673 ListViewGroup group = control.Groups.GetInternalGroup (i);
2674 if (group.ItemCount > 0 && clip.IntersectsWith (group.HeaderBounds))
2675 DrawListViewGroupHeader (dc, control, group);
2679 ListViewInsertionMark insertion_mark = control.InsertionMark;
2680 int insertion_mark_index = insertion_mark.Index;
2681 if (Application.VisualStylesEnabled && insertion_mark.Bounds != Rectangle.Empty &&
2682 (control.View != View.Details && control.View != View.List) &&
2683 insertion_mark_index > -1 && insertion_mark_index < control.Items.Count) {
2685 Brush brush = ResPool.GetSolidBrush (insertion_mark.Color);
2686 dc.FillRectangle (brush, insertion_mark.Line);
2687 dc.FillPolygon (brush, insertion_mark.TopTriangle);
2688 dc.FillPolygon (brush, insertion_mark.BottomTriangle);
2691 // draw the gridlines
2692 if (details && control.GridLines && !control.UsingGroups) {
2693 Size control_size = control.ClientSize;
2694 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
2695 0 : control.header_control.Height;
2697 // draw vertical gridlines
2698 foreach (ColumnHeader col in control.Columns) {
2699 int column_right = col.Rect.Right - control.h_marker;
2700 dc.DrawLine (SystemPens.Control,
2702 column_right, control_size.Height);
2705 // draw horizontal gridlines
2706 int item_height = control.ItemSize.Height;
2707 if (item_height == 0)
2708 item_height = control.Font.Height + 2;
2710 int y = top + item_height - (control.v_marker % item_height); // scroll bar offset
2711 while (y < control_size.Height) {
2712 dc.DrawLine (SystemPens.Control, 0, y, control_size.Width, y);
2717 // Draw corner between the two scrollbars
2718 if (control.h_scroll.Visible == true && control.v_scroll.Visible == true) {
2719 Rectangle rect = new Rectangle ();
2720 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
2721 rect.Width = control.v_scroll.Width;
2722 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
2723 rect.Height = control.h_scroll.Height;
2724 dc.FillRectangle (SystemBrushes.Control, rect);
2727 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
2728 if (!box_select_rect.Size.IsEmpty)
2729 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
2733 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
2735 bool details = (control.View == View.Details);
2737 // border is drawn directly in the Paint method
2738 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
2739 dc.FillRectangle (SystemBrushes.Control,
2740 0, 0, control.TotalWidth, control.Font.Height + 5);
2741 if (control.Columns.Count > 0) {
2742 foreach (ColumnHeader col in control.Columns) {
2743 Rectangle rect = col.Rect;
2744 rect.X -= control.h_marker;
2746 bool owner_draw = false;
2747 if (control.OwnerDraw)
2748 owner_draw = DrawListViewColumnHeaderOwnerDraw (dc, control, col, rect);
2752 ListViewDrawColumnHeaderBackground (control, col, dc, rect, clip);
2755 if (rect.Width <= 0)
2759 if (control.SmallImageList == null)
2762 image_index = col.ImageKey == String.Empty ? col.ImageIndex : control.SmallImageList.Images.IndexOfKey (col.ImageKey);
2764 if (image_index > -1 && image_index < control.SmallImageList.Images.Count) {
2765 int image_width = control.SmallImageList.ImageSize.Width + 5;
2766 int text_width = (int)dc.MeasureString (col.Text, control.Font).Width;
2767 int x_origin = rect.X;
2768 int y_origin = rect.Y + ((rect.Height - control.SmallImageList.ImageSize.Height) / 2);
2770 switch (col.TextAlign) {
2771 case HorizontalAlignment.Left:
2773 case HorizontalAlignment.Right:
2774 x_origin = rect.Right - (text_width + image_width);
2776 case HorizontalAlignment.Center:
2777 x_origin = (rect.Width - (text_width + image_width)) / 2 + rect.X;
2781 if (x_origin < rect.X)
2784 control.SmallImageList.Draw (dc, new Point (x_origin, y_origin), image_index);
2785 rect.X += image_width;
2786 rect.Width -= image_width;
2789 dc.DrawString (col.Text, control.Font, SystemBrushes.ControlText, rect, col.Format);
2791 int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker;
2792 if (right < control.Right) {
2793 Rectangle rect = control.Columns [0].Rect;
2795 rect.Width = control.Right - right;
2796 ListViewDrawUnusedHeaderBackground (control, dc, rect, clip);
2802 protected virtual void ListViewDrawColumnHeaderBackground (ListView listView, ColumnHeader columnHeader, Graphics g, Rectangle area, Rectangle clippingArea)
2805 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
2806 state = columnHeader.Pressed ? ButtonState.Pushed : ButtonState.Normal;
2808 state = ButtonState.Flat;
2809 CPDrawButton (g, area, state);
2812 protected virtual void ListViewDrawUnusedHeaderBackground (ListView listView, Graphics g, Rectangle area, Rectangle clippingArea)
2815 if (listView.HeaderStyle == ColumnHeaderStyle.Clickable)
2816 state = ButtonState.Normal;
2818 state = ButtonState.Flat;
2819 CPDrawButton (g, area, state);
2822 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
2824 Rectangle rect = col.Rect;
2825 rect.X -= view.h_marker;
2826 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
2827 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
2830 if (rect.Width <= 0)
2832 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
2833 dc.DrawString (col.Text, view.Font, ResPool.GetSolidBrush (color), rect, col.Format);
2834 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
2837 protected virtual bool DrawListViewColumnHeaderOwnerDraw (Graphics dc, ListView control, ColumnHeader column, Rectangle bounds)
2839 ListViewItemStates state = ListViewItemStates.ShowKeyboardCues;
2841 state |= ListViewItemStates.Selected;
2843 DrawListViewColumnHeaderEventArgs args = new DrawListViewColumnHeaderEventArgs (dc,
2844 bounds, column.Index, column, state, SystemColors.ControlText, ThemeEngine.Current.ColorControl, DefaultFont);
2845 control.OnDrawColumnHeader (args);
2847 return !args.DrawDefault;
2850 protected virtual bool DrawListViewItemOwnerDraw (Graphics dc, ListViewItem item, int index)
2852 ListViewItemStates item_state = ListViewItemStates.ShowKeyboardCues;
2854 item_state |= ListViewItemStates.Selected;
2856 item_state |= ListViewItemStates.Focused;
2858 DrawListViewItemEventArgs args = new DrawListViewItemEventArgs (dc,
2859 item, item.Bounds, index, item_state);
2860 item.ListView.OnDrawItem (args);
2862 if (args.DrawDefault)
2865 if (item.ListView.View == View.Details) {
2866 int count = Math.Min (item.ListView.Columns.Count, item.SubItems.Count);
2868 // Do system drawing for subitems if no owner draw is done
2869 for (int j = 0; j < count; j++) {
2870 if (!DrawListViewSubItemOwnerDraw (dc, item, item_state, j)) {
2871 if (j == 0) // The first sub item contains the main item semantics
2872 DrawListViewItem (dc, item.ListView, item);
2874 DrawListViewSubItem (dc, item.ListView, item, j);
2882 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
2884 Rectangle rect_checkrect = item.CheckRectReal;
2885 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
2886 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
2887 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
2889 // Tile view doesn't support CheckBoxes
2890 if (control.CheckBoxes && control.View != View.Tile) {
2891 if (control.StateImageList == null) {
2892 // Make sure we've got at least a line width of 1
2893 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
2894 int scale = Math.Max (1, rect_checkrect.Width / 12);
2896 // set the checkbox background
2897 dc.FillRectangle (SystemBrushes.Window,
2899 // define a rectangle inside the border area
2900 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
2901 rect_checkrect.Y + 2,
2902 rect_checkrect.Width - 4,
2903 rect_checkrect.Height - 4);
2904 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
2905 dc.DrawRectangle (pen, rect);
2907 // Need to draw a check-mark
2909 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
2910 // adjustments to get the check-mark at the right place
2911 rect.X ++; rect.Y ++;
2912 // following logic is taken from DrawFrameControl method
2913 int x_offset = rect.Width / 5;
2914 int y_offset = rect.Height / 3;
2915 for (int i = 0; i < check_wd; i++) {
2916 dc.DrawLine (check_pen, rect.Left + x_offset,
2917 rect.Top + y_offset + i,
2918 rect.Left + x_offset + 2 * scale,
2919 rect.Top + y_offset + 2 * scale + i);
2920 dc.DrawLine (check_pen,
2921 rect.Left + x_offset + 2 * scale,
2922 rect.Top + y_offset + 2 * scale + i,
2923 rect.Left + x_offset + 6 * scale,
2924 rect.Top + y_offset - 2 * scale + i);
2931 simage_idx = control.StateImageList.Images.Count > 1 ? 1 : -1;
2933 simage_idx = control.StateImageList.Images.Count > 0 ? 0 : -1;
2935 if (simage_idx > -1)
2936 control.StateImageList.Draw (dc, rect_checkrect.Location, simage_idx);
2940 ImageList image_list = control.View == View.LargeIcon || control.View == View.Tile ? control.LargeImageList : control.SmallImageList;
2941 if (image_list != null) {
2944 if (item.ImageKey != String.Empty)
2945 idx = image_list.Images.IndexOfKey (item.ImageKey);
2947 idx = item.ImageIndex;
2949 if (idx > -1 && idx < image_list.Images.Count)
2950 image_list.Draw (dc, icon_rect.Location, idx);
2953 // draw the item text
2954 // format for the item text
2955 StringFormat format = new StringFormat ();
2956 if (control.View == View.SmallIcon || control.View == View.LargeIcon)
2957 format.LineAlignment = StringAlignment.Near;
2959 format.LineAlignment = StringAlignment.Center;
2960 if (control.View == View.LargeIcon)
2961 format.Alignment = StringAlignment.Center;
2963 format.Alignment = StringAlignment.Near;
2965 if (control.LabelWrap && control.View != View.Details && control.View != View.Tile)
2966 format.FormatFlags = StringFormatFlags.LineLimit;
2968 format.FormatFlags = StringFormatFlags.NoWrap;
2970 if ((control.View == View.LargeIcon && !item.Focused) || control.View == View.Details || control.View == View.Tile)
2971 format.Trimming = StringTrimming.EllipsisCharacter;
2973 Rectangle highlight_rect = text_rect;
2974 if (control.View == View.Details) { // Adjustments for Details view
2975 Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
2977 if (!control.FullRowSelect) // Selection shouldn't be outside the item bounds
2978 highlight_rect.Width = Math.Min (text_size.Width + 4, text_rect.Width);
2981 if (item.Selected && control.Focused)
2982 dc.FillRectangle (SystemBrushes.Highlight, highlight_rect);
2983 else if (item.Selected && !control.HideSelection)
2984 dc.FillRectangle (SystemBrushes.Control, highlight_rect);
2986 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
2989 !control.Enabled ? SystemBrushes.ControlLight :
2990 (item.Selected && control.Focused) ? SystemBrushes.HighlightText :
2991 this.ResPool.GetSolidBrush (item.ForeColor);
2993 // Tile view renders its Text in a different fashion
2994 if (control.View == View.Tile && Application.VisualStylesEnabled) {
2995 // Item.Text is drawn using its first subitem's bounds
2996 dc.DrawString (item.Text, item.Font, textBrush, item.SubItems [0].Bounds, format);
2998 int count = Math.Min (control.Columns.Count, item.SubItems.Count);
2999 for (int i = 1; i < count; i++) {
3000 ListViewItem.ListViewSubItem sub_item = item.SubItems [i];
3001 if (sub_item.Text == null || sub_item.Text.Length == 0)
3004 Brush itemBrush = item.Selected && control.Focused ?
3005 SystemBrushes.HighlightText : GetControlForeBrush (sub_item.ForeColor);
3006 dc.DrawString (sub_item.Text, sub_item.Font, itemBrush, sub_item.Bounds, format);
3010 if (item.Text != null && item.Text.Length > 0) {
3011 Font font = item.Font;
3013 if (control.HotTracking && item.Hot)
3014 font = item.HotFont;
3016 if (item.Selected && control.Focused)
3017 dc.DrawString (item.Text, font, textBrush, highlight_rect, format);
3019 dc.DrawString (item.Text, font, textBrush, text_rect, format);
3022 if (item.Focused && control.Focused) {
3023 Rectangle focus_rect = highlight_rect;
3024 if (control.FullRowSelect && control.View == View.Details) {
3026 foreach (ColumnHeader col in control.Columns)
3028 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
3030 if (control.ShowFocusCues) {
3032 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
3034 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
3041 protected virtual void DrawListViewSubItems (Graphics dc, ListView control, ListViewItem item)
3043 int columns_count = control.Columns.Count;
3044 int count = Math.Min (item.SubItems.Count, columns_count);
3045 // 0th item already done (in this case)
3046 for (int i = 1; i < count; i++)
3047 DrawListViewSubItem (dc, control, item, i);
3049 // Fill in selection for remaining columns if Column.Count > SubItems.Count
3050 Rectangle sub_item_rect = item.GetBounds (ItemBoundsPortion.Label);
3051 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
3052 for (int index = count; index < columns_count; index++) {
3053 ColumnHeader col = control.Columns [index];
3054 sub_item_rect.X = col.Rect.X - control.h_marker;
3055 sub_item_rect.Width = col.Wd;
3056 dc.FillRectangle (control.Focused ? SystemBrushes.Highlight : SystemBrushes.Control,
3062 protected virtual void DrawListViewSubItem (Graphics dc, ListView control, ListViewItem item, int index)
3064 ListViewItem.ListViewSubItem subItem = item.SubItems [index];
3065 ColumnHeader col = control.Columns [index];
3066 StringFormat format = new StringFormat ();
3067 format.Alignment = col.Format.Alignment;
3068 format.LineAlignment = StringAlignment.Center;
3069 format.FormatFlags = StringFormatFlags.NoWrap;
3070 format.Trimming = StringTrimming.EllipsisCharacter;
3072 Rectangle sub_item_rect = subItem.Bounds;
3073 Rectangle sub_item_text_rect = sub_item_rect;
3074 sub_item_text_rect.X += 3;
3075 sub_item_text_rect.Width -= ListViewItemPaddingWidth;
3077 SolidBrush sub_item_back_br = null;
3078 SolidBrush sub_item_fore_br = null;
3079 Font sub_item_font = null;
3081 if (item.UseItemStyleForSubItems) {
3082 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
3083 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
3085 // Hot tracking for subitems only applies when UseStyle is true
3086 if (control.HotTracking && item.Hot)
3087 sub_item_font = item.HotFont;
3089 sub_item_font = item.Font;
3091 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
3092 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
3093 sub_item_font = subItem.Font;
3096 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
3098 if (control.Focused) {
3099 bg = SystemBrushes.Highlight;
3100 text = SystemBrushes.HighlightText;
3102 bg = SystemBrushes.Control;
3103 text = sub_item_fore_br;
3107 dc.FillRectangle (bg, sub_item_rect);
3108 if (subItem.Text != null && subItem.Text.Length > 0)
3109 dc.DrawString (subItem.Text, sub_item_font,
3110 text, sub_item_text_rect, format);
3112 dc.FillRectangle (sub_item_back_br, sub_item_rect);
3113 if (subItem.Text != null && subItem.Text.Length > 0)
3114 dc.DrawString (subItem.Text, sub_item_font,
3116 sub_item_text_rect, format);
3122 protected virtual bool DrawListViewSubItemOwnerDraw (Graphics dc, ListViewItem item, ListViewItemStates state, int index)
3124 ListView control = item.ListView;
3125 ListViewItem.ListViewSubItem subitem = item.SubItems [index];
3127 DrawListViewSubItemEventArgs args = new DrawListViewSubItemEventArgs (dc, subitem.Bounds, item,
3128 subitem, item.Index, index, control.Columns [index], state);
3129 control.OnDrawSubItem (args);
3131 return !args.DrawDefault;
3134 protected virtual void DrawListViewGroupHeader (Graphics dc, ListView control, ListViewGroup group)
3136 Rectangle text_bounds = group.HeaderBounds;
3137 Rectangle header_bounds = group.HeaderBounds;
3138 text_bounds.Offset (8, 0);
3139 text_bounds.Inflate (-8, 0);
3140 int text_height = control.Font.Height + 2; // add a tiny padding between the text and the group line
3142 Font font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
3143 Brush brush = new LinearGradientBrush (new Point (header_bounds.Left, 0), new Point (header_bounds.Left + ListViewGroupLineWidth, 0),
3144 SystemColors.Desktop, Color.White);
3145 Pen pen = new Pen (brush);
3147 StringFormat sformat = new StringFormat ();
3148 switch (group.HeaderAlignment) {
3149 case HorizontalAlignment.Left:
3150 sformat.Alignment = StringAlignment.Near;
3152 case HorizontalAlignment.Center:
3153 sformat.Alignment = StringAlignment.Center;
3155 case HorizontalAlignment.Right:
3156 sformat.Alignment = StringAlignment.Far;
3160 sformat.LineAlignment = StringAlignment.Near;
3161 dc.DrawString (group.Header, font, SystemBrushes.ControlText, text_bounds, sformat);
3162 dc.DrawLine (pen, header_bounds.Left, header_bounds.Top + text_height, header_bounds.Left + ListViewGroupLineWidth,
3163 header_bounds.Top + text_height);
3171 public override bool ListViewHasHotHeaderStyle {
3178 public override int ListViewGetHeaderHeight (ListView listView, Font font)
3180 return ListViewGetHeaderHeight (font);
3183 static int ListViewGetHeaderHeight (Font font)
3185 return font.Height + 5;
3188 public static int ListViewGetHeaderHeight ()
3190 return ListViewGetHeaderHeight (ThemeEngine.Current.DefaultFont);
3193 public override Size ListViewCheckBoxSize {
3194 get { return new Size (16, 16); }
3197 public override int ListViewColumnHeaderHeight {
3201 public override int ListViewDefaultColumnWidth {
3205 public override int ListViewVerticalSpacing {
3209 public override int ListViewEmptyColumnWidth {
3213 public override int ListViewHorizontalSpacing {
3217 public override int ListViewItemPaddingWidth {
3221 public override Size ListViewDefaultSize {
3222 get { return new Size (121, 97); }
3225 public override int ListViewGroupHeight {
3229 public int ListViewGroupLineWidth {
3233 public override int ListViewTileWidthFactor {
3237 public override int ListViewTileHeightFactor {
3240 #endregion // ListView
3244 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
3249 if (item.Visible == false) {
3255 if (item.Separator == true) {
3256 item.Height = SEPARATOR_HEIGHT;
3257 item.Width = SEPARATOR_MIN_WIDTH;
3261 if (item.MeasureEventDefined) {
3262 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
3263 item.PerformMeasureItem (mi);
3264 item.Height = mi.ItemHeight;
3265 item.Width = mi.ItemWidth;
3269 size = dc.MeasureString (item.Text, MenuFont, int.MaxValue, string_format_menu_text);
3270 item.Width = (int) size.Width;
3271 item.Height = (int) size.Height;
3274 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
3275 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
3276 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
3277 item.Width += MENU_TAB_SPACE + (int) size.Width;
3280 item.Width += 4 + (MenuCheckSize.Width * 2);
3282 item.Width += MENU_BAR_ITEMS_SPACE;
3286 if (item.Height < MenuHeight)
3287 item.Height = MenuHeight;
3291 // Updates the menu rect and returns the height
3292 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
3298 foreach (MenuItem item in menu.MenuItems) {
3300 CalcItemSize (dc, item, y, x, true);
3302 if (x + item.Width > width) {
3310 item.MenuBar = true;
3312 if (y + item.Height > menu.Height)
3313 menu.Height = item.Height + y;
3320 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
3328 while (start < menu.MenuItems.Count) {
3331 for (i = start; i < menu.MenuItems.Count; i++) {
3332 MenuItem item = menu.MenuItems [i];
3334 if ((i != start) && (item.Break || item.BarBreak))
3337 CalcItemSize (dc, item, y, x, false);
3340 if (item.Width > max)
3344 // Replace the -1 by the menu width (separators)
3345 for (n = start; n < i; n++, start++)
3346 menu.MenuItems [n].Width = max;
3348 if (y > menu.Height)
3360 menu.Width += SM_CXBORDER;
3361 menu.Height += SM_CYBORDER;
3364 // Draws a menu bar in a window
3365 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
3367 if (menu.Height == 0)
3368 CalcMenuBarSize (dc, menu, rect.Width);
3370 bool keynav = (menu as MainMenu).tracker.hotkey_active;
3371 HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
3372 string_format_menu_menubar_text.HotkeyPrefix = hp;
3373 string_format_menu_text.HotkeyPrefix = hp;
3375 rect.Height = menu.Height;
3376 dc.FillRectangle (SystemBrushes.Menu, rect);
3378 for (int i = 0; i < menu.MenuItems.Count; i++) {
3379 MenuItem item = menu.MenuItems [i];
3380 Rectangle item_rect = item.bounds;
3381 item_rect.X += rect.X;
3382 item_rect.Y += rect.Y;
3383 item.MenuHeight = menu.Height;
3384 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
3388 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
3391 if (color.R == 0 && color.G == 0 && color.B == 0)
3392 bg_color = Color.White;
3394 bg_color = Color.Black;
3396 Bitmap bmp = new Bitmap (size.Width, size.Height);
3397 Graphics gr = Graphics.FromImage (bmp);
3398 Rectangle rect = new Rectangle (Point.Empty, size);
3399 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
3400 CPDrawMenuGlyph (gr, rect, glyph, color, Color.Empty);
3401 bmp.MakeTransparent (bg_color);
3407 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
3409 StringFormat string_format;
3410 Rectangle rect_text = e.Bounds;
3412 if (item.Visible == false)
3416 string_format = string_format_menu_menubar_text;
3418 string_format = string_format_menu_text;
3420 if (item.Separator == true) {
3421 int liney = e.Bounds.Y + (e.Bounds.Height / 2);
3423 e.Graphics.DrawLine (SystemPens.ControlDark,
3424 e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney);
3426 e.Graphics.DrawLine (SystemPens.ControlLight,
3427 e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1);
3433 rect_text.X += MenuCheckSize.Width;
3435 if (item.BarBreak) { /* Draw vertical break bar*/
3436 Rectangle rect = e.Bounds;
3439 rect.Height = item.MenuHeight - 6;
3441 e.Graphics.DrawLine (SystemPens.ControlDark,
3442 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
3444 e.Graphics.DrawLine (SystemPens.ControlLight,
3445 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
3450 Brush brush_text = null;
3451 Brush brush_back = null;
3453 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
3454 color_text = ColorHighlightText;
3455 color_back = ColorHighlight;
3456 brush_text = SystemBrushes.HighlightText;
3457 brush_back = SystemBrushes.Highlight;
3459 color_text = ColorMenuText;
3460 color_back = ColorMenu;
3461 brush_text = ResPool.GetSolidBrush (ColorMenuText);
3462 brush_back = SystemBrushes.Menu;
3465 /* Draw background */
3467 e.Graphics.FillRectangle (brush_back, e.Bounds);
3470 e.Graphics.DrawString (item.Text, e.Font,
3472 rect_text, string_format);
3475 Border3DStyle border_style = Border3DStyle.Adjust;
3476 if ((item.Status & DrawItemState.HotLight) != 0)
3477 border_style = Border3DStyle.RaisedInner;
3478 else if ((item.Status & DrawItemState.Selected) != 0)
3479 border_style = Border3DStyle.SunkenOuter;
3481 if (border_style != Border3DStyle.Adjust)
3482 CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
3485 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
3486 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
3487 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
3492 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
3495 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
3496 string str = item.GetShortCutText ();
3497 Rectangle rect = rect_text;
3499 rect.Width -= item.XTab;
3502 e.Graphics.DrawString (str, e.Font, brush_text, rect, string_format_menu_shortcut);
3504 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
3505 e.Graphics.DrawString (str, e.Font, Brushes.White,
3506 new RectangleF(rect.X + 1, rect.Y + 1, rect.Width, rect_text.Height),
3507 string_format_menu_shortcut);
3510 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect, string_format_menu_shortcut);
3515 if (item.MenuBar == false && (item.IsPopup || item.MdiList)) {
3517 int cx = MenuCheckSize.Width;
3518 int cy = MenuCheckSize.Height;
3519 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
3522 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
3523 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
3525 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
3526 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
3532 /* Draw checked or radio */
3533 if (item.MenuBar == false && item.Checked) {
3535 Rectangle area = e.Bounds;
3536 int cx = MenuCheckSize.Width;
3537 int cy = MenuCheckSize.Height;
3538 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
3540 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
3546 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
3548 // Fill rectangle area
3549 dc.FillRectangle (SystemBrushes.Menu, cliparea);
3551 // Draw menu borders
3552 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3555 for (int i = 0; i < menu.MenuItems.Count; i++) {
3556 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
3557 MenuItem item = menu.MenuItems [i];
3558 item.MenuHeight = menu.Height;
3559 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item.bounds, i, item.Status));
3566 #region MonthCalendar
3568 // draw the month calendar
3569 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
3571 Rectangle client_rectangle = mc.ClientRectangle;
3572 Size month_size = mc.SingleMonthSize;
3573 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
3574 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
3575 Size date_cell_size = (Size)((object)mc.date_cell_size);
3577 // draw the singlecalendars
3580 // adjust for the position of the specific month
3581 for (int i=0; i < mc.CalendarDimensions.Height; i++)
3585 y_offset += month_size.Height + calendar_spacing.Height;
3587 // now adjust for x position
3588 for (int j=0; j < mc.CalendarDimensions.Width; j++)
3592 x_offset += month_size.Width + calendar_spacing.Width;
3599 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
3600 if (month_rect.IntersectsWith (clip_rectangle)) {
3612 Rectangle bottom_rect = new Rectangle (
3614 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
3615 client_rectangle.Width,
3616 date_cell_size.Height + 2);
3617 // draw the today date if it's set
3618 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
3620 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
3622 int today_offset = 5;
3623 if (mc.ShowTodayCircle)
3625 Rectangle today_circle_rect = new Rectangle (
3626 client_rectangle.X + 5,
3627 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
3628 date_cell_size.Width,
3629 date_cell_size.Height);
3630 DrawTodayCircle (dc, today_circle_rect);
3631 today_offset += date_cell_size.Width + 5;
3633 // draw today's date
3634 StringFormat text_format = new StringFormat();
3635 text_format.LineAlignment = StringAlignment.Center;
3636 text_format.Alignment = StringAlignment.Near;
3637 Rectangle today_rect = new Rectangle (
3638 today_offset + client_rectangle.X,
3639 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
3640 Math.Max(client_rectangle.Width - today_offset, 0),
3641 date_cell_size.Height);
3642 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), mc.bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
3643 text_format.Dispose ();
3649 if (mc.owner == null)
3650 border_brush = GetControlBackBrush (mc.BackColor);
3652 border_brush = SystemBrushes.ControlDarkDark;
3654 // finally paint the borders of the calendars as required
3655 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
3656 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
3657 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
3658 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
3659 dc.FillRectangle (border_brush, client_rectangle.Right - 1, client_rectangle.Y, 1, client_rectangle.Height);
3661 Rectangle rect = new Rectangle (
3662 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
3664 calendar_spacing.Width,
3665 client_rectangle.Height);
3666 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
3667 dc.FillRectangle (border_brush, rect);
3671 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
3672 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
3673 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
3674 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
3675 dc.FillRectangle (border_brush, client_rectangle.X, client_rectangle.Bottom - 1, client_rectangle.Width, 1);
3677 Rectangle rect = new Rectangle (
3679 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
3680 client_rectangle.Width,
3681 calendar_spacing.Height);
3682 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
3683 dc.FillRectangle (border_brush, rect);
3688 // draw the drop down border if need
3689 if (mc.owner != null) {
3690 Rectangle bounds = mc.ClientRectangle;
3691 if (clip_rectangle.Contains (mc.Location)) {
3692 // find out if top or left line to draw
3693 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3695 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
3697 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3698 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
3701 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
3702 // find out if bottom or right line to draw
3703 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3704 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
3706 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3707 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
3713 // darws a single part of the month calendar (with one month)
3714 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
3716 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
3717 Size title_size = (Size)((object)mc.title_size);
3718 Size date_cell_size = (Size)((object)mc.date_cell_size);
3719 DateTime current_month = (DateTime)((object)mc.current_month);
3720 DateTime sunday = new DateTime(2006, 10, 1);
3722 // draw the title back ground
3723 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
3724 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
3725 if (title_rect.IntersectsWith (clip_rectangle)) {
3726 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
3728 string title_text = this_month.ToString ("MMMM yyyy");
3729 dc.DrawString (title_text, mc.bold_font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, mc.centered_format);
3731 if (mc.ShowYearUpDown) {
3732 Rectangle year_rect;
3733 Rectangle upRect, downRect;
3734 ButtonState upState, downState;
3736 mc.GetYearNameRectangles (title_rect, row * mc.CalendarDimensions.Width + col, out year_rect, out upRect, out downRect);
3737 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control), year_rect);
3738 dc.DrawString (this_month.ToString ("yyyy"), mc.bold_font, ResPool.GetSolidBrush (Color.Black), year_rect, mc.centered_format);
3740 upState = mc.IsYearGoingUp ? ButtonState.Pushed : ButtonState.Normal;
3741 downState = mc.IsYearGoingDown ? ButtonState.Pushed : ButtonState.Normal;
3743 ControlPaint.DrawScrollButton (dc, upRect, ScrollButton.Up, upState);
3744 ControlPaint.DrawScrollButton (dc, downRect, ScrollButton.Down, downState);
3747 // draw previous and next buttons if it's time
3748 if (row == 0 && col == 0)
3750 // draw previous button
3751 DrawMonthCalendarButton (
3757 (System.Drawing.Size)((object)mc.button_size),
3760 if (row == 0 && col == mc.CalendarDimensions.Width-1)
3763 DrawMonthCalendarButton (
3769 (System.Drawing.Size)((object)mc.button_size),
3774 // set the week offset and draw week nums if needed
3775 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
3776 Rectangle day_name_rect = new Rectangle(
3778 rectangle.Y + title_size.Height,
3779 (7 + col_offset) * date_cell_size.Width,
3780 date_cell_size.Height);
3781 if (day_name_rect.IntersectsWith (clip_rectangle)) {
3782 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
3783 // draw the day names
3784 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
3785 for (int i=0; i < 7; i++)
3787 int position = i - (int) first_day_of_week;
3790 position = 7 + position;
3793 Rectangle day_rect = new Rectangle(
3794 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
3796 date_cell_size.Width,
3797 date_cell_size.Height);
3798 dc.DrawString (sunday.AddDays (i + (int) first_day_of_week).ToString ("ddd"), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, mc.centered_format);
3801 // draw the vertical divider
3802 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
3804 ResPool.GetPen (mc.ForeColor),
3805 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
3806 rectangle.Y + vert_divider_y,
3807 rectangle.Right - mc.divider_line_offset,
3808 rectangle.Y + vert_divider_y);
3812 // draw the actual date items in the grid (including the week numbers)
3813 Rectangle date_rect = new Rectangle (
3815 rectangle.Y + title_size.Height + date_cell_size.Height,
3816 date_cell_size.Width,
3817 date_cell_size.Height);
3818 int month_row_count = 0;
3819 bool draw_week_num_divider = false;
3820 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
3821 for (int i=0; i < 6; i++)
3823 // establish if this row is in our clip_area
3824 Rectangle row_rect = new Rectangle (
3826 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
3827 date_cell_size.Width * 7,
3828 date_cell_size.Height);
3829 if (mc.ShowWeekNumbers) {
3830 row_rect.Width += date_cell_size.Width;
3833 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
3835 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
3837 // establish if this is a valid week to draw
3838 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
3839 month_row_count = i;
3842 // draw the week number if required
3843 if (mc.ShowWeekNumbers && month_row_count == i) {
3844 if (!draw_week_num_divider) {
3845 draw_week_num_divider = draw_row;
3847 // get the week for this row
3848 int week = mc.GetWeekOfYear (current_date);
3854 ResPool.GetSolidBrush (mc.TitleBackColor),
3856 mc.centered_format);
3858 date_rect.Offset(date_cell_size.Width, 0);
3861 // only draw the days if we have to
3862 if(month_row_count == i) {
3863 for (int j=0; j < 7; j++)
3866 DrawMonthCalendarDate (
3877 current_date = current_date.AddDays(1);
3878 date_rect.Offset(date_cell_size.Width, 0);
3881 // shift the rectangle down one row
3882 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
3883 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
3887 // month_row_count is zero based, so add one
3890 // draw week numbers if required
3891 if (draw_week_num_divider) {
3894 ResPool.GetPen (mc.ForeColor),
3895 rectangle.X + date_cell_size.Width - 1,
3896 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
3897 rectangle.X + date_cell_size.Width - 1,
3898 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
3902 // draws the pervious or next button
3903 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
3905 const int arrow_width = 4;
3906 const int arrow_height = 7;
3908 bool is_clicked = false;
3909 Rectangle button_rect;
3910 PointF arrow_center;
3911 PointF [] arrow_path = new PointF [3];
3913 // prepare the button
3916 is_clicked = mc.is_previous_clicked;
3918 button_rect = new Rectangle (
3919 rectangle.X + 1 + x_offset,
3920 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3921 Math.Max(button_size.Width - 1, 0),
3922 Math.Max(button_size.Height - 1, 0));
3924 arrow_center = new PointF (button_rect.X + ((button_rect.Width + arrow_width) / 2.0f),
3925 rectangle.Y + ((button_rect.Height + arrow_height) / 2) + 1);
3927 arrow_center.X += 1;
3928 arrow_center.Y += 1;
3931 arrow_path [0].X = arrow_center.X;
3932 arrow_path [0].Y = arrow_center.Y - arrow_height / 2.0f + 0.5f;
3933 arrow_path [1].X = arrow_center.X;
3934 arrow_path [1].Y = arrow_center.Y + arrow_height / 2.0f + 0.5f;
3935 arrow_path [2].X = arrow_center.X - arrow_width;
3936 arrow_path [2].Y = arrow_center.Y + 0.5f;
3940 is_clicked = mc.is_next_clicked;
3942 button_rect = new Rectangle (
3943 rectangle.Right - 1 - x_offset - button_size.Width,
3944 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3945 Math.Max(button_size.Width - 1, 0),
3946 Math.Max(button_size.Height - 1, 0));
3948 arrow_center = new PointF (button_rect.X + ((button_rect.Width + arrow_width) / 2.0f),
3949 rectangle.Y + ((button_rect.Height + arrow_height) / 2) + 1);
3951 arrow_center.X += 1;
3952 arrow_center.Y += 1;
3955 arrow_path [0].X = arrow_center.X - arrow_width;
3956 arrow_path [0].Y = arrow_center.Y - arrow_height / 2.0f + 0.5f;
3957 arrow_path [1].X = arrow_center.X - arrow_width;
3958 arrow_path [1].Y = arrow_center.Y + arrow_height / 2.0f + 0.5f;
3959 arrow_path [2].X = arrow_center.X;
3960 arrow_path [2].Y = arrow_center.Y + 0.5f;
3963 // fill the background
3964 dc.FillRectangle (SystemBrushes.Control, button_rect);
3967 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
3970 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3973 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
3974 //dc.FillPolygon (SystemBrushes.ControlText, arrow_path, FillMode.Winding);
3978 // draws one day in the calendar grid
3979 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
3980 Color date_color = mc.ForeColor;
3981 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
3983 // find out if we are the lead of the first calendar or the trail of the last calendar
3984 if (date.Year != month.Year || date.Month != month.Month) {
3985 DateTime check_date = month.AddMonths (-1);
3986 // check if it's the month before
3987 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
3988 date_color = mc.TrailingForeColor;
3990 // check if it's the month after
3991 check_date = month.AddMonths (1);
3992 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
3993 date_color = mc.TrailingForeColor;
3999 date_color = mc.ForeColor;
4002 const int inflate = -1;
4004 if (date == mc.SelectionStart.Date && date == mc.SelectionEnd.Date) {
4005 // see if the date is in the start of selection
4006 date_color = mc.BackColor;
4007 // draw the left hand of the back ground
4008 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4009 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360);
4010 } else if (date == mc.SelectionStart.Date) {
4011 // see if the date is in the start of selection
4012 date_color = mc.BackColor;
4013 // draw the left hand of the back ground
4014 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4015 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
4016 // fill the other side as a straight rect
4017 if (date < mc.SelectionEnd.Date)
4019 // use rectangle instead of rectangle to go all the way to edge of rect
4020 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
4021 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
4022 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4024 } else if (date == mc.SelectionEnd.Date) {
4025 // see if it is the end of selection
4026 date_color = mc.BackColor;
4027 // draw the left hand of the back ground
4028 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
4029 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
4030 // fill the other side as a straight rect
4031 if (date > mc.SelectionStart.Date) {
4032 selection_rect.X = rectangle.X;
4033 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
4034 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4036 } else if (date > mc.SelectionStart.Date && date < mc.SelectionEnd.Date) {
4037 // now see if it's in the middle
4038 date_color = mc.BackColor;
4039 // draw the left hand of the back ground
4040 Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate);
4041 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
4044 // establish if it's a bolded font
4045 Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font;
4047 // just draw the date now
4048 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format);
4050 // today circle if needed
4051 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
4052 DrawTodayCircle (dc, interior);
4055 // draw the selection grid
4056 if (mc.is_date_clicked && mc.clicked_date == date) {
4057 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
4058 dc.DrawRectangle (pen, interior);
4062 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
4063 Color circle_color = Color.FromArgb (248, 0, 0);
4064 // draw the left hand of the circle
4065 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
4066 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
4067 Point [] curve_points = new Point [3];
4068 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
4069 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
4070 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
4072 Pen pen = ResPool.GetSizedPen(circle_color, 2);
4073 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
4074 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
4075 dc.DrawCurve (pen, curve_points);
4076 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
4079 #endregion // MonthCalendar
4082 public override Size PanelDefaultSize {
4084 return new Size (200, 100);
4090 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
4091 Rectangle client = pb.ClientRectangle;
4093 client = new Rectangle (client.Left + pb.Padding.Left, client.Top + pb.Padding.Top, client.Width - pb.Padding.Horizontal, client.Height - pb.Padding.Vertical);
4095 // FIXME - instead of drawing the whole picturebox every time
4096 // intersect the clip rectangle with the drawn picture and only draw what's needed,
4097 // Also, we only need a background fill where no image goes
4098 if (pb.Image != null) {
4099 switch (pb.SizeMode) {
4100 case PictureBoxSizeMode.StretchImage:
4101 dc.DrawImage (pb.Image, client.Left, client.Top, client.Width, client.Height);
4104 case PictureBoxSizeMode.CenterImage:
4105 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
4108 case PictureBoxSizeMode.Zoom:
4111 if (((float)pb.Image.Width / (float)pb.Image.Height) >= ((float)client.Width / (float)client.Height))
4112 image_size = new Size (client.Width, (pb.Image.Height * client.Width) / pb.Image.Width);
4114 image_size = new Size ((pb.Image.Width * client.Height) / pb.Image.Height, client.Height);
4116 dc.DrawImage (pb.Image, (client.Width / 2) - (image_size.Width / 2), (client.Height / 2) - (image_size.Height / 2), image_size.Width, image_size.Height);
4121 dc.DrawImage (pb.Image, client.Left, client.Top, pb.Image.Width, pb.Image.Height);
4129 public override Size PictureBoxDefaultSize {
4131 return new Size (100, 50);
4134 #endregion // PictureBox
4136 #region PrintPreviewControl
4137 public override int PrintPreviewControlPadding {
4141 public override Size PrintPreviewControlGetPageSize (PrintPreviewControl preview)
4143 int page_width, page_height;
4144 int padding = PrintPreviewControlPadding;
4145 PreviewPageInfo[] pis = preview.page_infos;
4147 if (preview.AutoZoom) {
4148 int height_available = preview.ClientRectangle.Height - (preview.Rows) * padding - 2 * padding;
4149 int width_available = preview.ClientRectangle.Width - (preview.Columns - 1) * padding - 2 * padding;
4151 float image_ratio = (float)pis[0].Image.Width / pis[0].Image.Height;
4153 /* try to lay things out using the width to determine the size */
4154 page_width = width_available / preview.Columns;
4155 page_height = (int)(page_width / image_ratio);
4157 /* does the height fit? */
4158 if (page_height * (preview.Rows + 1) > height_available) {
4159 /* no, lay things out via the height */
4160 page_height = height_available / (preview.Rows + 1);
4161 page_width = (int)(page_height * image_ratio);
4165 page_width = (int)(pis[0].Image.Width * preview.Zoom);
4166 page_height = (int)(pis[0].Image.Height * preview.Zoom);
4169 return new Size (page_width, page_height);
4172 public override void PrintPreviewControlPaint (PaintEventArgs pe, PrintPreviewControl preview, Size page_size)
4175 PreviewPageInfo[] pis = preview.page_infos;
4181 int width = page_size.Width * preview.Columns + padding * (preview.Columns - 1) + 2 * padding;
4182 int height = page_size.Height * (preview.Rows + 1) + padding * preview.Rows + 2 * padding;
4184 Rectangle viewport = preview.ViewPort;
4186 pe.Graphics.Clip = new Region (viewport);
4188 /* center things if we can */
4189 int off_x = viewport.Width / 2 - width / 2;
4190 if (off_x < 0) off_x = 0;
4191 int off_y = viewport.Height / 2 - height / 2;
4192 if (off_y < 0) off_y = 0;
4194 page_y = off_y + padding - preview.vbar_value;
4196 if (preview.StartPage > 0) {
4197 int p = preview.StartPage - 1;
4198 for (int py = 0; py < preview.Rows + 1; py ++) {
4199 page_x = off_x + padding - preview.hbar_value;
4200 for (int px = 0; px < preview.Columns; px ++) {
4201 if (p >= pis.Length)
4203 Image image = preview.image_cache[p];
4205 image = pis[p].Image;
4206 Rectangle dest = new Rectangle (new Point (page_x, page_y), page_size);
4208 pe.Graphics.DrawImage (image, dest, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
4210 page_x += padding + page_size.Width;
4213 page_y += padding + page_size.Height;
4217 #endregion // PrintPreviewControl
4220 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
4222 Rectangle client_area = ctrl.client_area;
4225 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
4229 int max_blocks = int.MaxValue;
4230 int start_pixel = client_area.X;
4231 draw_mode = (int) ctrl.Style;
4233 switch (draw_mode) {
4234 case 1: { // Continuous
4236 pixels_to_draw = (int)(client_area.Width * ((double)(ctrl.Value - ctrl.Minimum) / (double)(Math.Max(ctrl.Maximum - ctrl.Minimum, 1))));
4237 dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), new Rectangle (client_area.X, client_area.Y, pixels_to_draw, client_area.Height));
4241 if (XplatUI.ThemesEnabled) {
4242 int ms_diff = (int) (DateTime.Now - ctrl.start).TotalMilliseconds;
4243 double percent_done = (double) ms_diff / ProgressBarMarqueeSpeedScaling
4244 % (double)ctrl.MarqueeAnimationSpeed / (double)ctrl.MarqueeAnimationSpeed;
4246 start_pixel = client_area.X + (int) (client_area.Width * percent_done);
4252 Rectangle block_rect;
4253 int space_betweenblocks = ProgressBarChunkSpacing;
4257 int block_count = 0;
4259 block_width = ProgressBarGetChunkSize (client_area.Height);
4260 block_width = Math.Max (block_width, 0); // block_width is used to break out the loop below, it must be >= 0!
4261 barpos_pixels = (int)(((double)(ctrl.Value - ctrl.Minimum) * client_area.Width) / (Math.Max (ctrl.Maximum - ctrl.Minimum, 1)));
4262 increment = block_width + space_betweenblocks;
4264 block_rect = new Rectangle (start_pixel, client_area.Y, block_width, client_area.Height);
4266 if (max_blocks != int.MaxValue) {
4267 if (block_count >= max_blocks)
4269 if (block_rect.X > client_area.Width)
4270 block_rect.X -= client_area.Width;
4272 if ((block_rect.X - client_area.X) >= barpos_pixels)
4276 if (clip_rect.IntersectsWith (block_rect) == true) {
4277 dc.FillRectangle (ResPool.GetSolidBrush (ctrl.ForeColor), block_rect);
4280 block_rect.X += increment;
4288 public const int ProgressBarChunkSpacing = 2;
4290 public static int ProgressBarGetChunkSize ()
4292 return ProgressBarGetChunkSize (ProgressBarDefaultHeight);
4295 static int ProgressBarGetChunkSize (int progressBarClientAreaHeight)
4297 int size = (progressBarClientAreaHeight * 2) / 3;
4301 const int ProgressBarDefaultHeight = 23;
4303 public override Size ProgressBarDefaultSize {
4305 return new Size (100, ProgressBarDefaultHeight);
4309 public const double ProgressBarMarqueeSpeedScaling = 15;
4311 #endregion // ProgressBar
4314 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
4315 StringFormat text_format;
4316 Rectangle client_rectangle;
4317 Rectangle text_rectangle;
4318 Rectangle radiobutton_rectangle;
4319 int radiobutton_size = 13;
4320 int radiobutton_space = 4;
4322 client_rectangle = radio_button.ClientRectangle;
4323 text_rectangle = client_rectangle;
4324 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
4326 text_format = new StringFormat();
4327 text_format.Alignment = StringAlignment.Near;
4328 text_format.LineAlignment = StringAlignment.Center;
4329 text_format.HotkeyPrefix = HotkeyPrefix.Show;
4331 /* Calculate the position of text and checkbox rectangle */
4332 if (radio_button.appearance!=Appearance.Button) {
4333 switch(radio_button.radiobutton_alignment) {
4334 case ContentAlignment.BottomCenter: {
4335 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4336 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4337 text_rectangle.X=client_rectangle.X;
4338 text_rectangle.Width=client_rectangle.Width;
4339 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
4343 case ContentAlignment.BottomLeft: {
4344 radiobutton_rectangle.X=client_rectangle.Left;
4345 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4346 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4347 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4351 case ContentAlignment.BottomRight: {
4352 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4353 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
4354 text_rectangle.X=client_rectangle.X;
4355 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4359 case ContentAlignment.MiddleCenter: {
4360 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4361 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4362 text_rectangle.X=client_rectangle.X;
4363 text_rectangle.Width=client_rectangle.Width;
4368 case ContentAlignment.MiddleLeft: {
4369 radiobutton_rectangle.X=client_rectangle.Left;
4370 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4371 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4372 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4376 case ContentAlignment.MiddleRight: {
4377 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4378 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
4379 text_rectangle.X=client_rectangle.X;
4380 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4384 case ContentAlignment.TopCenter: {
4385 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
4386 radiobutton_rectangle.Y=client_rectangle.Top;
4387 text_rectangle.X=client_rectangle.X;
4388 text_rectangle.Y=radiobutton_size+radiobutton_space;
4389 text_rectangle.Width=client_rectangle.Width;
4390 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
4394 case ContentAlignment.TopLeft: {
4395 radiobutton_rectangle.X=client_rectangle.Left;
4396 radiobutton_rectangle.Y=client_rectangle.Top;
4397 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
4398 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4402 case ContentAlignment.TopRight: {
4403 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
4404 radiobutton_rectangle.Y=client_rectangle.Top;
4405 text_rectangle.X=client_rectangle.X;
4406 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
4411 text_rectangle.X=client_rectangle.X;
4412 text_rectangle.Width=client_rectangle.Width;
4415 /* Set the horizontal alignment of our text */
4416 switch(radio_button.text_alignment) {
4417 case ContentAlignment.BottomLeft:
4418 case ContentAlignment.MiddleLeft:
4419 case ContentAlignment.TopLeft: {
4420 text_format.Alignment=StringAlignment.Near;
4424 case ContentAlignment.BottomCenter:
4425 case ContentAlignment.MiddleCenter:
4426 case ContentAlignment.TopCenter: {
4427 text_format.Alignment=StringAlignment.Center;
4431 case ContentAlignment.BottomRight:
4432 case ContentAlignment.MiddleRight:
4433 case ContentAlignment.TopRight: {
4434 text_format.Alignment=StringAlignment.Far;
4439 /* Set the vertical alignment of our text */
4440 switch(radio_button.text_alignment) {
4441 case ContentAlignment.TopLeft:
4442 case ContentAlignment.TopCenter:
4443 case ContentAlignment.TopRight: {
4444 text_format.LineAlignment=StringAlignment.Near;
4448 case ContentAlignment.BottomLeft:
4449 case ContentAlignment.BottomCenter:
4450 case ContentAlignment.BottomRight: {
4451 text_format.LineAlignment=StringAlignment.Far;
4455 case ContentAlignment.MiddleLeft:
4456 case ContentAlignment.MiddleCenter:
4457 case ContentAlignment.MiddleRight: {
4458 text_format.LineAlignment=StringAlignment.Center;
4463 ButtonState state = ButtonState.Normal;
4464 if (radio_button.FlatStyle == FlatStyle.Flat) {
4465 state |= ButtonState.Flat;
4468 if (radio_button.Checked) {
4469 state |= ButtonState.Checked;
4472 if (!radio_button.Enabled) {
4473 state |= ButtonState.Inactive;
4477 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
4479 if ((radio_button.image != null) || (radio_button.image_list != null))
4480 ButtonBase_DrawImage(radio_button, dc);
4482 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
4484 if (radio_button.Focused && radio_button.Enabled && radio_button.appearance != Appearance.Button && radio_button.Text != String.Empty && radio_button.ShowFocusCues) {
4485 SizeF text_size = dc.MeasureString (radio_button.Text, radio_button.Font);
4487 Rectangle focus_rect = Rectangle.Empty;
4488 focus_rect.X = text_rectangle.X;
4489 focus_rect.Y = (int)((text_rectangle.Height - text_size.Height) / 2);
4490 focus_rect.Size = text_size.ToSize ();
4492 RadioButton_DrawFocus (radio_button, dc, focus_rect);
4495 text_format.Dispose ();
4498 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
4500 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
4502 if (radio_button.appearance==Appearance.Button) {
4503 ButtonBase_DrawButton (radio_button, dc);
4505 if ((radio_button.Focused) && radio_button.Enabled)
4506 ButtonBase_DrawFocus(radio_button, dc);
4508 // establish if we are rendering a flat style of some sort
4509 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
4510 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
4512 CPDrawRadioButton(dc, radiobutton_rectangle, state);
4517 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
4519 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
4520 text_format, radio_button.Appearance, radio_button.Checked);
4523 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
4525 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
4529 // renders a radio button with the Flat and Popup FlatStyle
4530 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
4534 if (radio_button.Enabled) {
4536 // draw the outer flatstyle arcs
4537 if (radio_button.FlatStyle == FlatStyle.Flat) {
4538 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
4540 // fill in the area depending on whether or not the mouse is hovering
4541 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
4542 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4544 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4547 // must be a popup radio button
4549 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
4551 if (radio_button.is_entered || radio_button.Capture) {
4552 // draw the popup 3d button knob
4553 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
4555 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
4556 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
4559 // just draw lighter flatstyle outer circle
4560 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
4565 // fill control background color regardless of actual backcolor
4566 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4567 // draw the ark as control dark
4568 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
4572 if (radio_button.Checked) {
4573 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
4575 Pen dot_pen = SystemPens.ControlDarkDark;
4576 Brush dot_brush = SystemBrushes.ControlDarkDark;
4578 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
4579 dot_pen = SystemPens.ControlDark;
4580 dot_brush = SystemBrushes.ControlDark;
4583 if (rectangle.Height > 13) {
4584 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
4586 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
4587 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
4589 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
4590 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
4592 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
4593 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
4598 public override Size RadioButtonDefaultSize {
4600 return new Size (104,24);
4604 public override void DrawRadioButton (Graphics g, RadioButton rb, Rectangle glyphArea, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
4606 // Draw Button Background
4607 if (rb.FlatStyle == FlatStyle.Flat || rb.FlatStyle == FlatStyle.Popup) {
4608 glyphArea.Height -= 2;
4609 glyphArea.Width -= 2;
4612 DrawRadioButtonGlyph (g, rb, glyphArea);
4614 // If we have an image, draw it
4615 if (imageBounds.Size != Size.Empty)
4616 DrawRadioButtonImage (g, rb, imageBounds);
4618 if (rb.Focused && rb.Enabled && rb.ShowFocusCues && textBounds.Size != Size.Empty)
4619 DrawRadioButtonFocus (g, rb, textBounds);
4621 // If we have text, draw it
4622 if (textBounds != Rectangle.Empty)
4623 DrawRadioButtonText (g, rb, textBounds);
4626 public virtual void DrawRadioButtonGlyph (Graphics g, RadioButton rb, Rectangle glyphArea)
4629 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Pressed, rb.FlatStyle, rb.Checked);
4630 else if (rb.InternalSelected)
4631 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Normal, rb.FlatStyle, rb.Checked);
4632 else if (rb.Entered)
4633 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Hot, rb.FlatStyle, rb.Checked);
4634 else if (!rb.Enabled)
4635 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Disabled, rb.FlatStyle, rb.Checked);
4637 ThemeElements.CurrentTheme.RadioButtonPainter.PaintRadioButton (g, glyphArea, rb.BackColor, rb.ForeColor, ElementState.Normal, rb.FlatStyle, rb.Checked);
4640 public virtual void DrawRadioButtonFocus (Graphics g, RadioButton rb, Rectangle focusArea)
4642 ControlPaint.DrawFocusRectangle (g, focusArea);
4645 public virtual void DrawRadioButtonImage (Graphics g, RadioButton rb, Rectangle imageBounds)
4648 g.DrawImage (rb.Image, imageBounds);
4650 CPDrawImageDisabled (g, rb.Image, imageBounds.Left, imageBounds.Top, ColorControl);
4653 public virtual void DrawRadioButtonText (Graphics g, RadioButton rb, Rectangle textBounds)
4656 TextRenderer.DrawTextInternal (g, rb.Text, rb.Font, textBounds, rb.ForeColor, rb.TextFormatFlags, rb.UseCompatibleTextRendering);
4658 DrawStringDisabled20 (g, rb.Text, rb.Font, textBounds, rb.BackColor, rb.TextFormatFlags, rb.UseCompatibleTextRendering);
4661 public override Size CalculateRadioButtonAutoSize (RadioButton rb)
4663 Size ret_size = Size.Empty;
4664 Size text_size = TextRenderer.MeasureTextInternal (rb.Text, rb.Font, rb.UseCompatibleTextRendering);
4665 Size image_size = rb.Image == null ? Size.Empty : rb.Image.Size;
4667 // Pad the text size
4668 if (rb.Text.Length != 0) {
4669 text_size.Height += 4;
4670 text_size.Width += 4;
4673 switch (rb.TextImageRelation) {
4674 case TextImageRelation.Overlay:
4675 ret_size.Height = Math.Max (rb.Text.Length == 0 ? 0 : text_size.Height, image_size.Height);
4676 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
4678 case TextImageRelation.ImageAboveText:
4679 case TextImageRelation.TextAboveImage:
4680 ret_size.Height = text_size.Height + image_size.Height;
4681 ret_size.Width = Math.Max (text_size.Width, image_size.Width);
4683 case TextImageRelation.ImageBeforeText:
4684 case TextImageRelation.TextBeforeImage:
4685 ret_size.Height = Math.Max (text_size.Height, image_size.Height);
4686 ret_size.Width = text_size.Width + image_size.Width;
4691 ret_size.Height += (rb.Padding.Vertical);
4692 ret_size.Width += (rb.Padding.Horizontal) + 15;
4694 // There seems to be a minimum height
4695 if (ret_size.Height == rb.Padding.Vertical)
4696 ret_size.Height += 14;
4701 public override void CalculateRadioButtonTextAndImageLayout (ButtonBase b, Point offset, out Rectangle glyphArea, out Rectangle textRectangle, out Rectangle imageRectangle)
4703 CalculateCheckBoxTextAndImageLayout (b, offset, out glyphArea, out textRectangle, out imageRectangle);
4705 #endregion // RadioButton
4708 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
4710 int scrollbutton_width = bar.scrollbutton_width;
4711 int scrollbutton_height = bar.scrollbutton_height;
4712 Rectangle first_arrow_area;
4713 Rectangle second_arrow_area;
4714 Rectangle thumb_pos;
4716 thumb_pos = bar.ThumbPos;
4719 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
4720 bar.FirstArrowArea = first_arrow_area;
4722 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
4723 bar.SecondArrowArea = second_arrow_area;
4725 thumb_pos.Width = bar.Width;
4726 bar.ThumbPos = thumb_pos;
4728 Brush VerticalBrush;
4729 /* Background, upper track */
4730 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
4731 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4733 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4734 Rectangle UpperTrack = new Rectangle (0, 0, bar.ClientRectangle.Width, bar.ThumbPos.Bottom);
4735 if (clip.IntersectsWith (UpperTrack))
4736 dc.FillRectangle (VerticalBrush, UpperTrack);
4738 /* Background, lower track */
4739 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
4740 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4742 VerticalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4743 Rectangle LowerTrack = new Rectangle (0, bar.ThumbPos.Bottom, bar.ClientRectangle.Width, bar.ClientRectangle.Height - bar.ThumbPos.Bottom);
4744 if (clip.IntersectsWith (LowerTrack))
4745 dc.FillRectangle (VerticalBrush, LowerTrack);
4748 if (clip.IntersectsWith (first_arrow_area))
4749 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
4750 if (clip.IntersectsWith (second_arrow_area))
4751 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
4753 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
4754 bar.FirstArrowArea = first_arrow_area;
4756 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
4757 bar.SecondArrowArea = second_arrow_area;
4759 thumb_pos.Height = bar.Height;
4760 bar.ThumbPos = thumb_pos;
4762 Brush HorizontalBrush;
4763 //Background, left track
4764 if (bar.thumb_moving == ScrollBar.ThumbMoving.Backwards)
4765 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4767 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4768 Rectangle LeftTrack = new Rectangle (0, 0, bar.ThumbPos.Right, bar.ClientRectangle.Height);
4769 if (clip.IntersectsWith (LeftTrack))
4770 dc.FillRectangle (HorizontalBrush, LeftTrack);
4772 //Background, right track
4773 if (bar.thumb_moving == ScrollBar.ThumbMoving.Forward)
4774 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63, 63, 63), Color.Black);
4776 HorizontalBrush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, Color.White);
4777 Rectangle RightTrack = new Rectangle (bar.ThumbPos.Right, 0, bar.ClientRectangle.Width - bar.ThumbPos.Right, bar.ClientRectangle.Height);
4778 if (clip.IntersectsWith (RightTrack))
4779 dc.FillRectangle (HorizontalBrush, RightTrack);
4782 if (clip.IntersectsWith (first_arrow_area))
4783 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
4784 if (clip.IntersectsWith (second_arrow_area))
4785 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
4789 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
4792 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
4794 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
4795 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
4798 public override int ScrollBarButtonSize {
4802 public override bool ScrollBarHasHotElementStyles {
4808 public override bool ScrollBarHasPressedThumbStyle {
4814 public override bool ScrollBarHasHoverArrowButtonStyle {
4819 #endregion // ScrollBar
4822 public override void DrawStatusBar (Graphics real_dc, Rectangle clip, StatusBar sb) {
4823 Rectangle area = sb.ClientRectangle;
4824 int horz_border = 2;
4825 int vert_border = 2;
4827 Image backbuffer = new Bitmap (sb.ClientSize.Width, sb.ClientSize.Height, real_dc);
4828 Graphics dc = Graphics.FromImage (backbuffer);
4830 DrawStatusBarBackground (dc, clip, sb);
4832 if (!sb.ShowPanels && sb.Text != String.Empty) {
4833 string text = sb.Text;
4834 StringFormat string_format = new StringFormat ();
4835 string_format.Trimming = StringTrimming.Character;
4836 string_format.FormatFlags = StringFormatFlags.NoWrap;
4838 if (text.Length > 127)
4839 text = text.Substring (0, 127);
4841 if (text [0] == '\t') {
4842 string_format.Alignment = StringAlignment.Center;
4843 text = text.Substring (1);
4844 if (text [0] == '\t') {
4845 string_format.Alignment = StringAlignment.Far;
4846 text = text.Substring (1);
4850 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
4851 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
4852 string_format.Dispose ();
4853 } else if (sb.ShowPanels) {
4854 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
4855 int prev_x = area.X + horz_border;
4856 int y = area.Y + vert_border;
4857 for (int i = 0; i < sb.Panels.Count; i++) {
4858 Rectangle pr = new Rectangle (prev_x, y,
4859 sb.Panels [i].Width, area.Height);
4860 prev_x += pr.Width + StatusBarHorzGapWidth;
4861 if (pr.IntersectsWith (clip))
4862 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
4867 DrawStatusBarSizingGrip (dc, clip, sb, area);
4869 real_dc.DrawImage (backbuffer, 0, 0);
4871 backbuffer.Dispose ();
4875 protected virtual void DrawStatusBarBackground (Graphics dc, Rectangle clip, StatusBar sb)
4877 bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
4879 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
4880 dc.FillRectangle (brush, clip);
4883 protected virtual void DrawStatusBarSizingGrip (Graphics dc, Rectangle clip, StatusBar sb, Rectangle area)
4885 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
4886 CPDrawSizeGrip (dc, ColorControl, area);
4889 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
4890 Brush br_forecolor, StatusBarPanel panel) {
4891 int border_size = 3; // this is actually const, even if the border style is none
4892 int icon_width = 16;
4894 area.Height -= border_size;
4896 DrawStatusBarPanelBackground (dc, area, panel);
4898 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
4899 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
4900 dc, panel.Parent.Font, area, index, DrawItemState.Default,
4901 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
4902 panel.Parent.OnDrawItemInternal (e);
4906 string text = panel.Text;
4907 StringFormat string_format = new StringFormat ();
4908 string_format.Trimming = StringTrimming.Character;
4909 string_format.FormatFlags = StringFormatFlags.NoWrap;
4912 if (text != null && text.Length > 0 && text [0] == '\t') {
4913 string_format.Alignment = StringAlignment.Center;
4914 text = text.Substring (1);
4915 if (text [0] == '\t') {
4916 string_format.Alignment = StringAlignment.Far;
4917 text = text.Substring (1);
4921 Rectangle string_rect = Rectangle.Empty;
4925 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
4927 switch (panel.Alignment) {
4928 case HorizontalAlignment.Right:
4929 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4930 x = area.Right - len - 4;
4931 string_rect = new Rectangle (x, y,
4932 area.Right - x - border_size,
4933 area.Bottom - y - border_size);
4934 if (panel.Icon != null) {
4935 icon_x = x - icon_width - 2;
4938 case HorizontalAlignment.Center:
4939 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4940 x = area.Left + ((panel.Width - len) / 2);
4942 string_rect = new Rectangle (x, y,
4943 area.Right - x - border_size,
4944 area.Bottom - y - border_size);
4946 if (panel.Icon != null) {
4947 icon_x = x - icon_width - 2;
4953 int left = area.Left + border_size;;
4954 if (panel.Icon != null) {
4955 icon_x = area.Left + 2;
4956 left = icon_x + icon_width + 2;
4960 string_rect = new Rectangle (x, y,
4961 area.Right - x - border_size,
4962 area.Bottom - y - border_size);
4966 RectangleF clip_bounds = dc.ClipBounds;
4968 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
4969 dc.SetClip (clip_bounds);
4971 if (panel.Icon != null) {
4972 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
4976 protected virtual void DrawStatusBarPanelBackground (Graphics dc, Rectangle area, StatusBarPanel panel)
4978 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
4979 Border3DStyle border_style = Border3DStyle.SunkenOuter;
4980 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
4981 border_style = Border3DStyle.RaisedInner;
4983 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
4987 public override int StatusBarSizeGripWidth {
4991 public override int StatusBarHorzGapWidth {
4995 public override Size StatusBarDefaultSize {
4997 return new Size (100, 22);
5000 #endregion // StatusBar
5004 #region TabControl settings
5006 public override Size TabControlDefaultItemSize {
5007 get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultItemSize; }
5010 public override Point TabControlDefaultPadding {
5011 get { return ThemeElements.CurrentTheme.TabControlPainter.DefaultPadding; }
5014 public override int TabControlMinimumTabWidth {
5015 get { return ThemeElements.CurrentTheme.TabControlPainter.MinimumTabWidth; }
5018 public override Rectangle TabControlSelectedDelta {
5019 get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedTabDelta; }
5022 public override int TabControlSelectedSpacing {
5023 get { return ThemeElements.CurrentTheme.TabControlPainter.SelectedSpacing; }
5026 public override int TabPanelOffsetX {
5027 get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.X; }
5030 public override int TabPanelOffsetY {
5031 get { return ThemeElements.CurrentTheme.TabControlPainter.TabPanelOffset.Y; }
5034 public override int TabControlColSpacing {
5035 get { return ThemeElements.CurrentTheme.TabControlPainter.ColSpacing; }
5038 public override Point TabControlImagePadding {
5039 get { return ThemeElements.CurrentTheme.TabControlPainter.ImagePadding; }
5042 public override int TabControlScrollerWidth {
5043 get {return ThemeElements.CurrentTheme.TabControlPainter.ScrollerWidth; }
5047 public override Size TabControlGetSpacing (TabControl tab)
5050 return ThemeElements.CurrentTheme.TabControlPainter.RowSpacing (tab);
5052 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
5057 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
5059 ThemeElements.CurrentTheme.TabControlPainter.Draw (dc, area, tab);
5062 public override Rectangle TabControlGetDisplayRectangle (TabControl tab)
5064 return ThemeElements.CurrentTheme.TabControlPainter.GetDisplayRectangle (tab);
5067 public override Rectangle TabControlGetPanelRect (TabControl tab)
5069 return ThemeElements.CurrentTheme.TabControlPainter.GetTabPanelRect (tab);
5075 public override void TextBoxBaseFillBackground (TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea)
5077 if (textBoxBase.backcolor_set || (textBoxBase.Enabled && !textBoxBase.read_only)) {
5078 g.FillRectangle(ResPool.GetSolidBrush(textBoxBase.BackColor), clippingArea);
5080 g.FillRectangle(ResPool.GetSolidBrush(ColorControl), clippingArea);
5084 public override bool TextBoxBaseHandleWmNcPaint (TextBoxBase textBoxBase, ref Message m)
5089 public override bool TextBoxBaseShouldPaintBackground (TextBoxBase textBoxBase)
5096 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
5098 StringFormat format = new StringFormat ();
5099 format.Trimming = StringTrimming.EllipsisCharacter;
5100 format.LineAlignment = StringAlignment.Center;
5101 if (control.ShowKeyboardCuesInternal)
5102 format.HotkeyPrefix = HotkeyPrefix.Show;
5104 format.HotkeyPrefix = HotkeyPrefix.Hide;
5106 if (control.TextAlign == ToolBarTextAlign.Underneath)
5107 format.Alignment = StringAlignment.Center;
5109 format.Alignment = StringAlignment.Near;
5111 if (control.Appearance != ToolBarAppearance.Flat || control.Parent == null) {
5112 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
5115 if (control.Divider && clip_rectangle.Y < 2) {
5116 if (clip_rectangle.Y < 1) {
5117 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
5119 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
5122 foreach (ToolBarItem item in control.items)
5123 if (item.Button.Visible && clip_rectangle.IntersectsWith (item.Rectangle))
5124 DrawToolBarButton (dc, control, item, format);
5129 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
5131 bool is_flat = (control.Appearance == ToolBarAppearance.Flat);
5133 DrawToolBarButtonBorder (dc, item, is_flat);
5135 switch (item.Button.Style) {
5136 case ToolBarButtonStyle.DropDownButton:
5137 if (control.DropDownArrows)
5138 DrawToolBarDropDownArrow (dc, item, is_flat);
5139 DrawToolBarButtonContents (dc, control, item, format);
5142 case ToolBarButtonStyle.Separator:
5144 DrawToolBarSeparator (dc, item);
5147 case ToolBarButtonStyle.ToggleButton:
5148 DrawToolBarToggleButtonBackground (dc, item);
5149 DrawToolBarButtonContents (dc, control, item, format);
5153 DrawToolBarButtonContents (dc, control, item, format);
5158 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
5160 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarItem item, bool is_flat)
5162 if (item.Button.Style == ToolBarButtonStyle.Separator)
5165 Border3DStyle style;
5168 if (item.Button.Pushed || item.Pressed)
5169 style = Border3DStyle.SunkenOuter;
5170 else if (item.Hilight)
5171 style = Border3DStyle.RaisedInner;
5176 if (item.Button.Pushed || item.Pressed)
5177 style = Border3DStyle.Sunken;
5179 style = Border3DStyle.Raised;
5182 Rectangle rect = item.Rectangle;
5183 if ((item.Button.Style == ToolBarButtonStyle.DropDownButton) && (item.Button.Parent.DropDownArrows) && is_flat)
5184 rect.Width -= ToolBarDropDownWidth;
5186 CPDrawBorder3D (dc, rect, style, all_sides);
5189 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarItem item)
5191 Rectangle area = item.Rectangle;
5192 int offset = (int) SystemPens.Control.Width + 1;
5193 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
5194 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
5197 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarItem item)
5200 Rectangle area = item.Rectangle;
5201 area.X += ToolBarImageGripWidth;
5202 area.Y += ToolBarImageGripWidth;
5203 area.Width -= 2 * ToolBarImageGripWidth;
5204 area.Height -= 2 * ToolBarImageGripWidth;
5206 if (item.Button.Pushed)
5207 brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight);
5208 else if (item.Button.PartialPush)
5209 brush = SystemBrushes.ControlLight;
5211 brush = SystemBrushes.Control;
5213 dc.FillRectangle (brush, area);
5216 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarItem item, bool is_flat)
5218 Rectangle rect = item.Rectangle;
5219 rect.X = item.Rectangle.Right - ToolBarDropDownWidth;
5220 rect.Width = ToolBarDropDownWidth;
5224 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
5225 else if (item.Button.Pushed || item.Pressed)
5226 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
5227 else if (item.Hilight)
5228 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides);
5231 CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides);
5232 else if (item.Button.Pushed || item.Pressed)
5233 CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides);
5235 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
5238 PointF [] vertices = new PointF [3];
5239 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2));
5241 // Increase vertical and horizontal position by 1 when button is pressed
5242 if (item.Pressed || item.Button.Pushed || item.DDPressed) {
5247 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
5248 vertices [0].Y = ddCenter.Y;
5249 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
5250 vertices [1].Y = ddCenter.Y;
5251 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
5252 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
5253 dc.FillPolygon (SystemBrushes.ControlText, vertices);
5256 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarItem item, StringFormat format)
5258 if (item.Button.Image != null) {
5259 int x = item.ImageRectangle.X + ToolBarImageGripWidth;
5260 int y = item.ImageRectangle.Y + ToolBarImageGripWidth;
5262 // Increase vertical and horizontal position by 1 when button is pressed
5263 if (item.Pressed || item.Button.Pushed) {
5268 if (item.Button.Enabled)
5269 dc.DrawImage (item.Button.Image, x, y);
5271 CPDrawImageDisabled (dc, item.Button.Image, x, y, ColorControl);
5274 Rectangle text_rect = item.TextRectangle;
5275 if (text_rect.Width <= 0 || text_rect.Height <= 0)
5278 if (item.Pressed || item.Button.Pushed) {
5283 if (item.Button.Enabled)
5284 dc.DrawString (item.Button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
5286 CPDrawStringDisabled (dc, item.Button.Text, control.Font, control.BackColor, text_rect, format);
5289 // Grip width for the ToolBar
5290 public override int ToolBarGripWidth {
5294 // Grip width for the Image on the ToolBarButton
5295 public override int ToolBarImageGripWidth {
5299 // width of the separator
5300 public override int ToolBarSeparatorWidth {
5304 // width of the dropdown arrow rect
5305 public override int ToolBarDropDownWidth {
5309 // width for the dropdown arrow on the ToolBarButton
5310 public override int ToolBarDropDownArrowWidth {
5314 // height for the dropdown arrow on the ToolBarButton
5315 public override int ToolBarDropDownArrowHeight {
5319 public override Size ToolBarDefaultSize {
5321 return new Size (100, 42);
5325 public override bool ToolBarHasHotElementStyles (ToolBar toolBar)
5327 return toolBar.Appearance == ToolBarAppearance.Flat;
5330 public override bool ToolBarHasHotCheckedElementStyles {
5335 #endregion // ToolBar
5338 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
5340 ToolTipDrawBackground (dc, clip_rectangle, control);
5342 TextFormatFlags flags = TextFormatFlags.HidePrefix;
5344 Color foreground = control.ForeColor;
5345 if (control.title.Length > 0) {
5346 Font bold_font = new Font (control.Font, control.Font.Style | FontStyle.Bold);
5347 TextRenderer.DrawTextInternal (dc, control.title, bold_font, control.title_rect,
5348 foreground, flags, false);
5349 bold_font.Dispose ();
5352 if (control.icon != null)
5353 dc.DrawIcon (control.icon, control.icon_rect);
5355 TextRenderer.DrawTextInternal (dc, control.Text, control.Font, control.text_rect, foreground, flags, false);
5358 protected virtual void ToolTipDrawBackground (Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control)
5360 Brush back_brush = ResPool.GetSolidBrush (control.BackColor);
5361 dc.FillRectangle (back_brush, control.ClientRectangle);
5362 dc.DrawRectangle (SystemPens.WindowFrame, 0, 0, control.Width - 1, control.Height - 1);
5365 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text)
5367 Size size = TextRenderer.MeasureTextInternal (text, tt.Font, false);
5370 Rectangle text_rect = new Rectangle (Point.Empty, size);
5371 text_rect.Inflate (-2, -1);
5372 tt.text_rect = text_rect;
5373 tt.icon_rect = tt.title_rect = Rectangle.Empty;
5375 Size title_size = Size.Empty;
5376 if (tt.title.Length > 0) {
5377 Font bold_font = new Font (tt.Font, tt.Font.Style | FontStyle.Bold);
5378 title_size = TextRenderer.MeasureTextInternal (tt.title, bold_font, false);
5379 bold_font.Dispose ();
5382 Size icon_size = Size.Empty;
5383 if (tt.icon != null)
5384 icon_size = new Size (size.Height, size.Height);
5386 if (icon_size != Size.Empty || title_size != Size.Empty) {
5388 int top_area_width = 0;
5389 int top_area_height = icon_size.Height > title_size.Height ? icon_size.Height : title_size.Height;
5390 Size text_size = size;
5391 Point location = new Point (padding, padding);
5393 if (icon_size != Size.Empty) {
5394 tt.icon_rect = new Rectangle (location, icon_size);
5395 top_area_width = icon_size.Width + padding;
5398 if (title_size != Size.Empty) {
5399 Rectangle title_rect = new Rectangle (location, new Size (title_size.Width, top_area_height));
5400 if (icon_size != Size.Empty)
5401 title_rect.X += icon_size.Width + padding;
5403 tt.title_rect = title_rect;
5404 top_area_width += title_size.Width;
5407 tt.text_rect = new Rectangle (new Point (location.X, location.Y + top_area_height + padding),
5410 size.Height += padding + top_area_height;
5411 if (top_area_width > size.Width)
5412 size.Width = top_area_width;
5415 size.Width += padding * 2;
5416 size.Height += padding * 2;
5422 public override bool ToolTipTransparentBackground {
5427 #endregion // ToolTip
5429 #region BalloonWindow
5430 NotifyIcon.BalloonWindow balloon_window;
5432 public override void ShowBalloonWindow (IntPtr handle, int timeout, string title, string text, ToolTipIcon icon)
5434 Control control = Control.FromHandle(handle);
5436 if (control == null)
5439 if (balloon_window != null) {
5440 balloon_window.Close ();
5441 balloon_window.Dispose ();
5444 balloon_window = new NotifyIcon.BalloonWindow (handle);
5445 balloon_window.Title = title;
5446 balloon_window.Text = text;
5447 balloon_window.Icon = icon;
5448 balloon_window.Timeout = timeout;
5449 balloon_window.Show ();
5452 public override void HideBalloonWindow (IntPtr handle)
5454 if (balloon_window == null || balloon_window.OwnerHandle != handle)
5457 balloon_window.Close ();
5458 balloon_window.Dispose ();
5459 balloon_window = null;
5462 private const int balloon_iconsize = 16;
5463 private const int balloon_bordersize = 8;
5465 public override void DrawBalloonWindow (Graphics dc, Rectangle clip, NotifyIcon.BalloonWindow control)
5467 Brush solidbrush = ResPool.GetSolidBrush (this.ColorInfoText);
5468 Rectangle rect = control.ClientRectangle;
5469 int iconsize = (control.Icon == ToolTipIcon.None) ? 0 : balloon_iconsize;
5471 // Rectangle borders and background.
5472 dc.FillRectangle (ResPool.GetSolidBrush (ColorInfo), rect);
5473 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), 0, 0, rect.Width - 1, rect.Height - 1);
5477 switch (control.Icon) {
5478 case ToolTipIcon.Info: {
5479 image = ThemeEngine.Current.Images(UIIcon.MessageBoxInfo, balloon_iconsize);
5483 case ToolTipIcon.Warning: {
5484 image = ThemeEngine.Current.Images(UIIcon.MessageBoxError, balloon_iconsize);
5488 case ToolTipIcon.Error: {
5489 image = ThemeEngine.Current.Images(UIIcon.MessageBoxWarning, balloon_iconsize);
5499 if (control.Icon != ToolTipIcon.None)
5500 dc.DrawImage (image, new Rectangle (balloon_bordersize, balloon_bordersize, iconsize, iconsize));
5503 Rectangle titlerect = new Rectangle (rect.X + balloon_bordersize + iconsize + (iconsize > 0 ? balloon_bordersize : 0),
5504 rect.Y + balloon_bordersize,
5505 rect.Width - ((3 * balloon_bordersize) + iconsize),
5506 rect.Height - (2 * balloon_bordersize));
5508 Font titlefont = new Font (control.Font.FontFamily, control.Font.Size, control.Font.Style | FontStyle.Bold, control.Font.Unit);
5509 dc.DrawString (control.Title, titlefont, solidbrush, titlerect, control.Format);
5512 Rectangle textrect = new Rectangle (rect.X + balloon_bordersize,
5513 rect.Y + balloon_bordersize,
5514 rect.Width - (2 * balloon_bordersize),
5515 rect.Height - (2 * balloon_bordersize));
5517 StringFormat textformat = control.Format;
5518 textformat.LineAlignment = StringAlignment.Far;
5519 dc.DrawString (control.Text, control.Font, solidbrush, textrect, textformat);
5522 public override Rectangle BalloonWindowRect (NotifyIcon.BalloonWindow control)
5524 Rectangle deskrect = Screen.GetWorkingArea (control);
5525 SizeF maxsize = new SizeF (250, 200);
5527 SizeF titlesize = TextRenderer.MeasureString (control.Title, control.Font, maxsize, control.Format);
5528 SizeF textsize = TextRenderer.MeasureString (control.Text, control.Font, maxsize, control.Format);
5530 if (titlesize.Height < balloon_iconsize)
5531 titlesize.Height = balloon_iconsize;
5533 Rectangle rect = new Rectangle ();
5534 rect.Height = (int) (titlesize.Height + textsize.Height + (3 * balloon_bordersize));
5535 rect.Width = (int) ((titlesize.Width > textsize.Width) ? titlesize.Width : textsize.Width) + (2 * balloon_bordersize);
5536 rect.X = deskrect.Width - rect.Width - 2;
5537 rect.Y = deskrect.Height - rect.Height - 2;
5541 #endregion // BalloonWindow
5544 public override int TrackBarValueFromMousePosition (int x, int y, TrackBar tb)
5546 int result = tb.Value;
5547 int value_pos = tb.Value;
5548 float pixels_betweenticks;
5549 Rectangle thumb_pos = Rectangle.Empty, thumb_area = Rectangle.Empty;
5550 Point channel_startpoint = Point.Empty, na_point = Point.Empty;
5552 GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out na_point, out na_point);
5554 /* Convert thumb position from mouse position to value*/
5555 if (tb.Orientation == Orientation.Vertical) {
5556 value_pos = (int)Math.Round (((thumb_area.Bottom - y - (float)thumb_pos.Height / 2) / (float)pixels_betweenticks), 0);
5558 if (value_pos + tb.Minimum > tb.Maximum)
5559 value_pos = tb.Maximum - tb.Minimum;
5560 else if (value_pos + tb.Minimum < tb.Minimum)
5563 result = value_pos + tb.Minimum;
5565 value_pos = (int)Math.Round (((x - channel_startpoint.X - (float)thumb_pos.Width / 2) / (float) pixels_betweenticks), 0);
5567 if (value_pos + tb.Minimum > tb.Maximum)
5568 value_pos = tb.Maximum - tb.Minimum;
5569 else if (value_pos + tb.Minimum < tb.Minimum)
5572 result = value_pos + tb.Minimum;
5578 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)
5580 thumb_area = Rectangle.Empty;
5581 thumb_pos = Rectangle.Empty;
5583 if (tb.Orientation == Orientation.Vertical) {
5584 toptick_startpoint = new Point ();
5585 bottomtick_startpoint = new Point ();
5586 channel_startpoint = new Point ();
5588 const int space_from_right = 8;
5589 const int space_from_left = 8;
5590 const int space_from_bottom = 11;
5591 Rectangle area = tb.ClientRectangle;
5593 switch (tb.TickStyle) {
5594 case TickStyle.BottomRight:
5595 case TickStyle.None:
5596 channel_startpoint.Y = 8;
5597 channel_startpoint.X = 9;
5598 bottomtick_startpoint.Y = 13;
5599 bottomtick_startpoint.X = 24;
5601 case TickStyle.TopLeft:
5602 channel_startpoint.Y = 8;
5603 channel_startpoint.X = 19;
5604 toptick_startpoint.Y = 13;
5605 toptick_startpoint.X = 8;
5607 case TickStyle.Both:
5608 channel_startpoint.Y = 8;
5609 channel_startpoint.X = 18;
5610 bottomtick_startpoint.Y = 13;
5611 bottomtick_startpoint.X = 32;
5612 toptick_startpoint.Y = 13;
5613 toptick_startpoint.X = 8;
5619 thumb_area.X = area.X + channel_startpoint.X;
5620 thumb_area.Y = area.Y + channel_startpoint.Y;
5621 thumb_area.Height = area.Height - space_from_right - space_from_left;
5622 thumb_area.Width = TrackBarVerticalTrackWidth;
5624 pixel_len = thumb_area.Height - 11;
5625 if (tb.Maximum == tb.Minimum) {
5626 pixels_betweenticks = 0;
5628 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
5631 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int)(pixels_betweenticks * (float)(tb.Value - tb.Minimum));
5633 toptick_startpoint = new Point ();
5634 bottomtick_startpoint = new Point ();
5635 channel_startpoint = new Point ();
5637 const int space_from_right = 8;
5638 const int space_from_left = 8;
5639 Rectangle area = tb.ClientRectangle;
5641 switch (tb.TickStyle) {
5642 case TickStyle.BottomRight:
5643 case TickStyle.None:
5644 channel_startpoint.X = 8;
5645 channel_startpoint.Y = 9;
5646 bottomtick_startpoint.X = 13;
5647 bottomtick_startpoint.Y = 24;
5649 case TickStyle.TopLeft:
5650 channel_startpoint.X = 8;
5651 channel_startpoint.Y = 19;
5652 toptick_startpoint.X = 13;
5653 toptick_startpoint.Y = 8;
5655 case TickStyle.Both:
5656 channel_startpoint.X = 8;
5657 channel_startpoint.Y = 18;
5658 bottomtick_startpoint.X = 13;
5659 bottomtick_startpoint.Y = 32;
5660 toptick_startpoint.X = 13;
5661 toptick_startpoint.Y = 8;
5667 thumb_area.X = area.X + channel_startpoint.X;
5668 thumb_area.Y = area.Y + channel_startpoint.Y;
5669 thumb_area.Width = area.Width - space_from_right - space_from_left;
5670 thumb_area.Height = TrackBarHorizontalTrackHeight;
5672 pixel_len = thumb_area.Width - 11;
5673 if (tb.Maximum == tb.Minimum) {
5674 pixels_betweenticks = 0;
5676 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
5679 thumb_pos.X = channel_startpoint.X + (int)(pixels_betweenticks * (float) (tb.Value - tb.Minimum));
5682 thumb_pos.Size = TrackBarGetThumbSize (tb);
5685 protected virtual Size TrackBarGetThumbSize (TrackBar trackBar)
5687 return TrackBarGetThumbSize ();
5690 public static Size TrackBarGetThumbSize ()
5692 /* Draw thumb fixed 10x22 size */
5693 return new Size (10, 22);
5696 public const int TrackBarVerticalTrackWidth = 4;
5698 public const int TrackBarHorizontalTrackHeight = 4;
5701 protected interface ITrackBarTickPainter
5703 void Paint (float x1, float y1, float x2, float y2);
5706 class TrackBarTickPainter : ITrackBarTickPainter
5708 readonly Graphics g;
5710 public TrackBarTickPainter (Graphics g, Pen pen)
5715 public void Paint (float x1, float y1, float x2, float y2)
5717 g.DrawLine (pen, x1, y1, x2, y2);
5720 protected virtual ITrackBarTickPainter GetTrackBarTickPainter (Graphics g)
5722 return new TrackBarTickPainter (g, ResPool.GetPen (pen_ticks_color));
5726 #region DrawTrackBar_Vertical
5727 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
5728 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
5729 float ticks, int value_pos, bool mouse_value) {
5731 Point toptick_startpoint = new Point ();
5732 Point bottomtick_startpoint = new Point ();
5733 Point channel_startpoint = new Point ();
5735 float pixels_betweenticks;
5736 Rectangle area = tb.ClientRectangle;
5738 GetTrackBarDrawingInfo (tb, out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
5741 TrackBarDrawVerticalTrack (dc, thumb_area, channel_startpoint, clip_rectangle);
5745 switch (tb.TickStyle) {
5746 case TickStyle.BottomRight:
5747 case TickStyle.None:
5748 thumb_pos.X = channel_startpoint.X - 8;
5749 TrackBarDrawVerticalThumbRight (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5751 case TickStyle.TopLeft:
5752 thumb_pos.X = channel_startpoint.X - 10;
5753 TrackBarDrawVerticalThumbLeft (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5756 thumb_pos.X = area.X + 10;
5757 TrackBarDrawVerticalThumb (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5762 pixel_len = thumb_area.Height - 11;
5763 pixels_betweenticks = pixel_len / ticks;
5765 thumb_area.X = thumb_pos.X;
5766 thumb_area.Y = channel_startpoint.Y;
5767 thumb_area.Width = thumb_pos.Height;
5770 if (pixels_betweenticks <= 0)
5772 if (tb.TickStyle == TickStyle.None)
5774 Region outside = new Region (area);
5775 outside.Exclude (thumb_area);
5777 if (outside.IsVisible (clip_rectangle)) {
5778 ITrackBarTickPainter tick_painter = TrackBarGetVerticalTickPainter (dc);
5780 if ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight) {
5781 float x = area.X + bottomtick_startpoint.X;
5782 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5783 float y = area.Y + bottomtick_startpoint.Y + inc;
5784 tick_painter.Paint (
5786 x + (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2), y);
5790 if ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft) {
5791 float x = area.X + toptick_startpoint.X;
5792 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
5793 float y = area.Y + toptick_startpoint.Y + inc;
5794 tick_painter.Paint (
5795 x - (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2), y,
5806 protected virtual void TrackBarDrawVerticalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
5808 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
5809 1, thumb_area.Height);
5811 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
5812 1, thumb_area.Height);
5814 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
5815 1, thumb_area.Height);
5820 protected virtual void TrackBarDrawVerticalThumbRight (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5822 Pen pen = SystemPens.ControlLightLight;
5823 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 10);
5824 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
5825 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
5827 pen = SystemPens.ControlDark;
5828 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X + 15, thumb_pos.Y + 9);
5829 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X + 16 + 4, thumb_pos.Y + 9 - 4);
5831 pen = SystemPens.ControlDarkDark;
5832 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X + 16, thumb_pos.Y + 10);
5833 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X + 16 + 5, thumb_pos.Y + 10 - 5);
5835 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
5836 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
5837 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
5838 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
5841 protected virtual void TrackBarDrawVerticalThumbLeft (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5843 Pen pen = SystemPens.ControlLightLight;
5844 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
5845 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
5847 pen = SystemPens.ControlDark;
5848 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16, thumb_pos.Y + 9);
5849 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
5850 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X + 19, thumb_pos.Y + 1);
5852 pen = SystemPens.ControlDarkDark;
5853 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X + 4 + 16, thumb_pos.Y + 10);
5854 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X - 1, thumb_pos.Y + 5);
5855 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y + 10);
5857 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
5858 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
5859 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
5860 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
5863 protected virtual void TrackBarDrawVerticalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5865 Pen pen = SystemPens.ControlLightLight;
5866 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
5867 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
5869 pen = SystemPens.ControlDark;
5870 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X + 19, thumb_pos.Y + 9);
5871 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 1, thumb_pos.X + 19, thumb_pos.Y + 8);
5873 pen = SystemPens.ControlDarkDark;
5874 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X + 20, thumb_pos.Y + 10);
5875 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y + 9);
5877 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
5882 protected virtual ITrackBarTickPainter TrackBarGetVerticalTickPainter (Graphics g)
5884 return GetTrackBarTickPainter (g);
5889 #region DrawTrackBar_Horizontal
5893 Does not matter the size of the control, Win32 always draws:
5894 - Ticks starting from pixel 13, 8
5895 - Channel starting at pos 8, 19 and ends at Width - 8
5896 - Autosize makes always the control 45 pixels high
5897 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
5900 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
5901 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
5902 float ticks, int value_pos, bool mouse_value) {
5903 Point toptick_startpoint = new Point ();
5904 Point bottomtick_startpoint = new Point ();
5905 Point channel_startpoint = new Point ();
5907 float pixels_betweenticks;
5908 Rectangle area = tb.ClientRectangle;
5910 GetTrackBarDrawingInfo (tb , out pixels_betweenticks, out thumb_area, out thumb_pos, out channel_startpoint, out bottomtick_startpoint, out toptick_startpoint);
5913 TrackBarDrawHorizontalTrack (dc, thumb_area, channel_startpoint, clip_rectangle);
5917 switch (tb.TickStyle) {
5918 case TickStyle.BottomRight:
5919 case TickStyle.None:
5920 thumb_pos.Y = channel_startpoint.Y - 8;
5921 TrackBarDrawHorizontalThumbBottom (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5923 case TickStyle.TopLeft:
5924 thumb_pos.Y = channel_startpoint.Y - 10;
5925 TrackBarDrawHorizontalThumbTop (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5928 thumb_pos.Y = area.Y + 10;
5929 TrackBarDrawHorizontalThumb (dc, thumb_pos, br_thumb, clip_rectangle, tb);
5934 pixel_len = thumb_area.Width - 11;
5935 pixels_betweenticks = pixel_len / ticks;
5937 thumb_area.Y = thumb_pos.Y;
5938 thumb_area.X = channel_startpoint.X;
5939 thumb_area.Height = thumb_pos.Height;
5941 if (pixels_betweenticks <= 0)
5943 if (tb.TickStyle == TickStyle.None)
5945 Region outside = new Region (area);
5946 outside.Exclude (thumb_area);
5948 if (outside.IsVisible (clip_rectangle)) {
5949 ITrackBarTickPainter tick_painter = TrackBarGetHorizontalTickPainter (dc);
5951 if ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight) {
5952 float y = area.Y + bottomtick_startpoint.Y;
5953 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5954 float x = area.X + bottomtick_startpoint.X + inc;
5955 tick_painter.Paint (
5957 x, y + (inc == 0 || inc + pixels_betweenticks >= pixel_len + 1 ? 3 : 2));
5961 if ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft) {
5962 float y = area.Y + toptick_startpoint.Y;
5963 for (float inc = 0; inc < pixel_len + 1; inc += pixels_betweenticks) {
5964 float x = area.X + toptick_startpoint.X + inc;
5965 tick_painter.Paint (
5966 x, y - (inc == 0 || (inc + pixels_betweenticks) >= pixel_len + 1 ? 3 : 2),
5977 protected virtual void TrackBarDrawHorizontalTrack (Graphics dc, Rectangle thumb_area, Point channel_startpoint, Rectangle clippingArea)
5979 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
5980 thumb_area.Width, 1);
5982 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
5983 thumb_area.Width, 1);
5985 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y + 3,
5986 thumb_area.Width, 1);
5991 protected virtual void TrackBarDrawHorizontalThumbBottom (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
5993 Pen pen = SystemPens.ControlLightLight;
5994 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
5995 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
5996 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
5998 pen = SystemPens.ControlDark;
5999 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 15);
6000 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X + 9 - 4, thumb_pos.Y + 16 + 4);
6002 pen = SystemPens.ControlDarkDark;
6003 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y + 16);
6004 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X + 10 - 5, thumb_pos.Y + 16 + 5);
6006 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
6007 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
6008 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
6009 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
6012 protected virtual void TrackBarDrawHorizontalThumbTop (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
6014 Pen pen = SystemPens.ControlLightLight;
6015 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
6016 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
6018 pen = SystemPens.ControlDark;
6019 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
6020 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
6021 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1, thumb_pos.Y + 19);
6023 pen = SystemPens.ControlDarkDark;
6024 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
6025 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y - 1);
6026 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
6028 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
6029 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
6030 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
6031 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
6034 protected virtual void TrackBarDrawHorizontalThumb (Graphics dc, Rectangle thumb_pos, Brush br_thumb, Rectangle clippingArea, TrackBar trackBar)
6036 Pen pen = SystemPens.ControlLightLight;
6037 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
6038 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
6040 pen = SystemPens.ControlDark;
6041 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
6042 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
6044 pen = SystemPens.ControlDarkDark;
6045 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y + 20);
6046 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
6048 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
6053 protected virtual ITrackBarTickPainter TrackBarGetHorizontalTickPainter (Graphics g)
6055 return GetTrackBarTickPainter (g);
6060 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
6065 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
6067 Rectangle thumb_pos = tb.ThumbPos;
6068 Rectangle thumb_area = tb.ThumbArea;
6070 if (tb.thumb_pressed) {
6071 value_pos = tb.thumb_mouseclick;
6074 value_pos = tb.Value - tb.Minimum;
6075 mouse_value = false;
6078 area = tb.ClientRectangle;
6081 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
6082 } else if (tb.thumb_pressed == true) {
6083 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
6085 br_thumb = SystemBrushes.Control;
6089 /* Control Background */
6090 if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
6091 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
6093 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
6097 CPDrawFocusRectangle(dc, area, tb.ForeColor, tb.BackColor);
6100 if (tb.Orientation == Orientation.Vertical) {
6101 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
6102 br_thumb, ticks, value_pos, mouse_value);
6105 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
6106 br_thumb, ticks, value_pos, mouse_value);
6109 tb.ThumbPos = thumb_pos;
6110 tb.ThumbArea = thumb_area;
6113 public override Size TrackBarDefaultSize {
6115 return new Size (104, 42);
6119 public override bool TrackBarHasHotThumbStyle {
6124 #endregion // TrackBar
6127 public override void UpDownBaseDrawButton (Graphics g, Rectangle bounds, bool top, VisualStyles.PushButtonState state)
6129 ControlPaint.DrawScrollButton (g, bounds, top ? ScrollButton.Up : ScrollButton.Down, state == VisualStyles.PushButtonState.Pressed ? ButtonState.Pushed : ButtonState.Normal);
6132 public override bool UpDownBaseHasHotButtonStyle {
6140 public override Size VScrollBarDefaultSize {
6142 return new Size (this.ScrollBarButtonSize, 80);
6145 #endregion // VScrollBar
6148 public override Size TreeViewDefaultSize {
6150 return new Size (121, 97);
6154 public override void TreeViewDrawNodePlusMinus (TreeView treeView, TreeNode node, Graphics dc, int x, int middle)
6156 int height = treeView.ActualItemHeight - 2;
6157 dc.FillRectangle (ResPool.GetSolidBrush (treeView.BackColor), (x + 4) - (height / 2), node.GetY() + 1, height, height);
6159 dc.DrawRectangle (SystemPens.ControlDarkDark, x, middle - 4, 8, 8);
6161 if (node.IsExpanded) {
6162 dc.DrawLine (SystemPens.ControlDarkDark, x + 2, middle, x + 6, middle);
6164 dc.DrawLine (SystemPens.ControlDarkDark, x + 2, middle, x + 6, middle);
6165 dc.DrawLine (SystemPens.ControlDarkDark, x + 4, middle - 2, x + 4, middle + 2);
6170 #region Managed window
6171 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
6173 if (wm.IsToolWindow && !wm.IsMinimized)
6174 return SystemInformation.ToolWindowCaptionHeight;
6175 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
6177 return SystemInformation.CaptionHeight;
6180 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
6182 if ((wm.IsToolWindow && wm.form.FormBorderStyle == FormBorderStyle.FixedToolWindow) ||
6189 public override int ManagedWindowIconWidth (InternalWindowManager wm)
6191 return ManagedWindowTitleBarHeight (wm) - 5;
6194 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
6196 TitleButtons buttons = wm.TitleButtons;
6197 Form form = wm.form;
6199 buttons.HelpButton.Visible = form.HelpButton;
6201 foreach (TitleButton button in buttons) {
6202 button.Visible = false;
6205 switch (form.FormBorderStyle) {
6206 case FormBorderStyle.None:
6207 if (form.WindowState != FormWindowState.Normal)
6208 goto case FormBorderStyle.Sizable;
6210 case FormBorderStyle.FixedToolWindow:
6211 case FormBorderStyle.SizableToolWindow:
6212 buttons.CloseButton.Visible = true;
6213 if (form.WindowState != FormWindowState.Normal)
6214 goto case FormBorderStyle.Sizable;
6216 case FormBorderStyle.FixedSingle:
6217 case FormBorderStyle.Fixed3D:
6218 case FormBorderStyle.FixedDialog:
6219 case FormBorderStyle.Sizable:
6220 switch (form.WindowState) {
6221 case FormWindowState.Normal:
6222 buttons.MinimizeButton.Visible = true;
6223 buttons.MaximizeButton.Visible = true;
6224 buttons.RestoreButton.Visible = false;
6226 case FormWindowState.Maximized:
6227 buttons.MinimizeButton.Visible = true;
6228 buttons.MaximizeButton.Visible = false;
6229 buttons.RestoreButton.Visible = true;
6231 case FormWindowState.Minimized:
6232 buttons.MinimizeButton.Visible = false;
6233 buttons.MaximizeButton.Visible = true;
6234 buttons.RestoreButton.Visible = true;
6237 buttons.CloseButton.Visible = true;
6241 // Respect MinimizeBox/MaximizeBox
6242 if (form.MinimizeBox == false && form.MaximizeBox == false) {
6243 buttons.MinimizeButton.Visible = false;
6244 buttons.MaximizeButton.Visible = false;
6245 } else if (form.MinimizeBox == false)
6246 buttons.MinimizeButton.State = ButtonState.Inactive;
6247 else if (form.MaximizeBox == false)
6248 buttons.MaximizeButton.State = ButtonState.Inactive;
6250 int bw = ManagedWindowBorderWidth (wm);
6251 Size btsize = ManagedWindowButtonSize (wm);
6252 int btw = btsize.Width;
6253 int bth = btsize.Height;
6255 int left = form.Width - bw - btw - ManagedWindowSpacingAfterLastTitleButton;
6257 if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
6258 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
6261 if (buttons.MaximizeButton.Visible) {
6262 buttons.MaximizeButton.Rectangle = new Rectangle (left, top, btw, bth);
6265 if (buttons.RestoreButton.Visible) {
6266 buttons.RestoreButton.Rectangle = new Rectangle (left, top, btw, bth);
6270 buttons.MinimizeButton.Rectangle = new Rectangle (left, top, btw, bth);
6272 } else if (wm.IsToolWindow) {
6273 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
6278 protected virtual Rectangle ManagedWindowDrawTitleBarAndBorders (Graphics dc, Rectangle clip, InternalWindowManager wm)
6280 Form form = wm.Form;
6281 int tbheight = ManagedWindowTitleBarHeight (wm);
6282 int bdwidth = ManagedWindowBorderWidth (wm);
6283 Color titlebar_color = Color.FromArgb (255, 10, 36, 106);
6284 Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240);
6285 Color color = ThemeEngine.Current.ColorControlDark;
6286 Color color2 = Color.FromArgb (255, 192, 192, 192);
6288 Pen pen = ResPool.GetPen (ColorControl);
6289 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
6290 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
6291 // The 3d border is only 2 pixels wide, so we draw the innermost pixels ourselves
6292 borders = new Rectangle (2, 2, form.Width - 5, form.Height - 5);
6293 for (int i = 2; i < bdwidth; i++) {
6294 dc.DrawRectangle (pen, borders);
6295 borders.Inflate (-1, -1);
6299 bool draw_titlebar_enabled = false;
6300 if (wm.Form.Parent != null && wm.Form.Parent is Form) {
6301 draw_titlebar_enabled = false;
6302 } else if (wm.IsActive && !wm.IsMaximized) {
6303 draw_titlebar_enabled = true;
6305 if (draw_titlebar_enabled) {
6306 color = titlebar_color;
6307 color2 = titlebar_color2;
6310 Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight - 1);
6312 // HACK: For now always draw the titlebar until we get updates better
6313 if (tb.Width > 0 && tb.Height > 0) {
6314 using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal))
6316 dc.FillRectangle (gradient, tb);
6320 if (!wm.IsMinimized)
6321 // Draw the line just beneath the title bar
6322 dc.DrawLine (ResPool.GetPen (SystemColors.Control), bdwidth,
6323 tbheight + bdwidth - 1, form.Width - bdwidth - 1,
6324 tbheight + bdwidth - 1);
6328 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
6331 Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations");
6332 dc.FillRectangle (Brushes.Black, clip);
6334 Rectangle tb = ManagedWindowDrawTitleBarAndBorders (dc, clip, wm);
6336 Form form = wm.Form;
6338 Rectangle icon = ManagedWindowGetTitleBarIconArea (wm);
6339 if (icon.IntersectsWith (clip))
6340 dc.DrawIcon (form.Icon, icon);
6341 const int SpacingBetweenIconAndCaption = 2;
6342 tb.Width -= icon.Right + SpacingBetweenIconAndCaption - tb.X ;
6343 tb.X = icon.Right + SpacingBetweenIconAndCaption;
6346 foreach (TitleButton button in wm.TitleButtons.AllButtons) {
6347 tb.Width -= Math.Max (0, tb.Right - DrawTitleButton (dc, button, clip, form));
6349 const int SpacingBetweenCaptionAndLeftMostButton = 3;
6350 tb.Width -= SpacingBetweenCaptionAndLeftMostButton;
6352 string window_caption = form.Text;
6353 window_caption = window_caption.Replace (Environment.NewLine, string.Empty);
6355 if (window_caption != null && window_caption != string.Empty) {
6356 StringFormat format = new StringFormat ();
6357 format.FormatFlags = StringFormatFlags.NoWrap;
6358 format.Trimming = StringTrimming.EllipsisCharacter;
6359 format.LineAlignment = StringAlignment.Center;
6361 if (tb.IntersectsWith (clip))
6362 dc.DrawString (window_caption, WindowBorderFont,
6363 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
6368 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
6370 int height = ManagedWindowTitleBarHeight (wm);
6371 if (!wm.IsMaximized && !wm.IsMinimized) {
6372 if (wm.IsToolWindow)
6373 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
6375 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
6378 height = SystemInformation.CaptionHeight;
6380 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
6384 private int DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
6386 if (!button.Visible) {
6387 return int.MaxValue;
6390 if (button.Rectangle.IntersectsWith (clip)) {
6391 ManagedWindowDrawTitleButton (dc, button, clip, form);
6393 return button.Rectangle.Left;
6396 protected virtual void ManagedWindowDrawTitleButton (Graphics dc, TitleButton button, Rectangle clip, Form form)
6398 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
6400 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
6401 button.Caption, button.State);
6404 public override Rectangle ManagedWindowGetTitleBarIconArea (InternalWindowManager wm)
6406 int bw = ManagedWindowBorderWidth (wm);
6407 return new Rectangle (bw + 3, bw + 2, wm.IconWidth, wm.IconWidth);
6410 public override Size ManagedWindowGetMenuButtonSize (InternalWindowManager wm)
6412 Size result = SystemInformation.MenuButtonSize;
6418 public override bool ManagedWindowTitleButtonHasHotElementStyle (TitleButton button, Form form)
6423 public override void ManagedWindowDrawMenuButton (Graphics dc, TitleButton button, Rectangle clip, InternalWindowManager wm)
6425 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
6426 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
6427 button.Caption, button.State);
6430 public override void ManagedWindowOnSizeInitializedOrChanged (Form form)
6435 #region ControlPaint
6436 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
6437 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
6438 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
6439 int bottomWidth, ButtonBorderStyle bottomStyle) {
6440 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
6441 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
6442 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
6443 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
6446 public override void CPDrawBorder (Graphics graphics, RectangleF bounds, Color leftColor, int leftWidth,
6447 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
6448 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
6449 int bottomWidth, ButtonBorderStyle bottomStyle) {
6450 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
6451 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
6452 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
6453 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
6456 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
6457 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
6460 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
6463 Pen penTopLeftInner;
6465 Pen penBottomRightInner;
6466 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
6467 bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
6469 if ((style & Border3DStyle.Adjust) != 0) {
6476 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
6478 CPColor cpcolor = CPColor.Empty;
6480 if (!is_ColorControl)
6481 cpcolor = ResPool.GetCPColor (control_color);
6484 case Border3DStyle.Raised:
6485 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6486 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6487 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6489 case Border3DStyle.Sunken:
6490 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6491 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6492 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6494 case Border3DStyle.Etched:
6495 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6496 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6498 case Border3DStyle.RaisedOuter:
6499 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6501 case Border3DStyle.SunkenOuter:
6502 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6503 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6505 case Border3DStyle.RaisedInner:
6506 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
6507 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6509 case Border3DStyle.SunkenInner:
6510 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6512 case Border3DStyle.Flat:
6513 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
6515 case Border3DStyle.Bump:
6516 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
6522 bool inner = ((style != Border3DStyle.RaisedOuter) && (style != Border3DStyle.SunkenOuter));
6524 if ((sides & Border3DSide.Middle) != 0) {
6525 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
6526 graphics.FillRectangle (brush, rect);
6529 if ((sides & Border3DSide.Left) != 0) {
6530 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
6531 if ((rect.Width > 2) && inner)
6532 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
6535 if ((sides & Border3DSide.Top) != 0) {
6536 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
6537 if ((rect.Height > 2) && inner)
6538 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
6541 if ((sides & Border3DSide.Right) != 0) {
6542 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
6543 if ((rect.Width > 3) && inner)
6544 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
6547 if ((sides & Border3DSide.Bottom) != 0) {
6548 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
6549 if ((rect.Height > 3) && inner)
6550 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
6554 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
6556 CPDrawButtonInternal (dc, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLight);
6559 private void CPDrawButtonInternal (Graphics dc, Rectangle rectangle, ButtonState state, Pen DarkPen, Pen NormalPen, Pen LightPen)
6561 // sadly enough, the rectangle gets always filled with a hatchbrush
6562 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
6563 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6564 ColorControl.G, ColorControl.B),
6566 rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
6568 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
6569 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
6571 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
6573 if ((state & ButtonState.Flat) == ButtonState.Flat) {
6574 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
6576 if ((state & ButtonState.Checked) == ButtonState.Checked) {
6577 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
6580 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6581 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6584 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
6585 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
6588 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
6589 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
6591 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
6593 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6594 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6597 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
6598 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
6601 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
6602 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
6604 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
6606 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
6607 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
6610 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
6611 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
6614 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
6615 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
6620 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
6621 Rectangle captionRect;
6624 CPDrawButtonInternal (graphics, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLightLight);
6626 if (rectangle.Width<rectangle.Height) {
6627 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
6629 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
6632 if ((state & ButtonState.Pushed)!=0) {
6633 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
6636 /* Make sure we've got at least a line width of 1 */
6637 lineWidth=Math.Max(1, captionRect.Width/7);
6640 case CaptionButton.Close: {
6643 if ((state & ButtonState.Inactive)!=0) {
6644 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
6645 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
6647 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
6648 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
6651 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
6652 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
6657 case CaptionButton.Help:
6658 case CaptionButton.Maximize:
6659 case CaptionButton.Minimize:
6660 case CaptionButton.Restore: {
6661 if ((state & ButtonState.Inactive)!=0) {
6662 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
6664 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
6667 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
6674 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
6676 CPDrawCheckBoxInternal (dc, rectangle, state, false /* mixed */);
6679 private void CPDrawCheckBoxInternal (Graphics dc, Rectangle rectangle, ButtonState state, bool mixed)
6681 Pen check_pen = (mixed) ? Pens.Gray : Pens.Black;
6683 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
6685 if ((state & ButtonState.All) == ButtonState.All) {
6687 cb_rect.Height -= 2;
6689 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6690 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6692 check_pen = SystemPens.ControlDark;
6694 if ((state & ButtonState.Flat) == ButtonState.Flat) {
6696 cb_rect.Height -= 2;
6698 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
6699 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6701 dc.FillRectangle (Brushes.White, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6702 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
6705 cb_rect.Height -= 1;
6707 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
6709 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
6710 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
6712 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
6714 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
6715 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
6716 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6717 ColorControl.G, ColorControl.B),
6718 ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
6720 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
6722 Pen pen = SystemPens.ControlDark;
6723 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
6724 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
6726 pen = SystemPens.ControlDarkDark;
6727 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
6728 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
6730 pen = SystemPens.ControlLightLight;
6731 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
6732 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
6734 // oh boy, matching ms is like fighting against windmills
6735 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50,
6736 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6737 ColorControl.G, ColorControl.B), ColorControl))) {
6738 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
6739 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
6742 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
6743 check_pen = SystemPens.ControlDark;
6746 if ((state & ButtonState.Checked) == ButtonState.Checked) {
6747 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
6749 if (check_size < 7) {
6750 int lineWidth = Math.Max (3, check_size / 3);
6751 int Scale = Math.Max (1, check_size / 9);
6753 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,
6754 check_size, check_size);
6756 for (int i = 0; i < lineWidth; i++) {
6757 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
6758 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);
6761 int lineWidth = Math.Max (3, check_size / 3) + 1;
6763 int x_half = cb_rect.Width / 2;
6764 int y_half = cb_rect.Height / 2;
6766 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
6767 check_size, check_size);
6769 int gradient_left = check_size / 3;
6770 int gradient_right = check_size - gradient_left - 1;
6773 for (int i = 0; i < lineWidth; i++) {
6774 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
6775 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
6781 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
6782 Point[] arrow = new Point[3];
6792 if ((state & ButtonState.Checked)!=0) {
6793 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
6796 if ((state & ButtonState.Flat)!=0) {
6797 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
6799 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
6800 // this needs to render like a pushed button - jba
6801 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
6802 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6803 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
6805 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
6809 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
6810 centerX=rect.Left+rect.Width/2;
6811 centerY=rect.Top+rect.Height/2;
6812 shiftX=Math.Max(1, rect.Width/8);
6813 shiftY=Math.Max(1, rect.Height/8);
6815 if ((state & ButtonState.Pushed)!=0) {
6822 P1=new Point(rect.Left, centerY);
6823 P2=new Point(rect.Right, centerY);
6824 P3=new Point(centerX, rect.Bottom);
6830 /* Draw the arrow */
6831 if ((state & ButtonState.Inactive)!=0) {
6832 /* Move away from the shadow */
6833 arrow[0].X += 1; arrow[0].Y += 1;
6834 arrow[1].X += 1; arrow[1].Y += 1;
6835 arrow[2].X += 1; arrow[2].Y += 1;
6837 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
6843 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
6845 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
6850 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
6852 Pen pen = Pens.Black;
6853 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
6857 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
6858 graphics.DrawRectangle (pen, rect);
6860 X = rect.X + rect.Width / 2;
6861 Y = rect.Y + rect.Height / 2;
6863 /* Draw the cross */
6864 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
6865 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
6867 /* Draw 'arrows' for vertical lines */
6868 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
6869 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
6871 /* Draw 'arrows' for horizontal lines */
6872 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
6873 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
6876 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
6877 // make a rectange to trace around border of the button
6878 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6880 Color outerColor = foreColor;
6881 // adjust focus color according to the flatstyle
6882 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
6883 outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;
6886 // draw the outer rectangle
6887 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
6889 // draw the inner rectangle
6890 if (button.FlatStyle == FlatStyle.Popup) {
6891 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
6893 // draw a flat inner rectangle
6894 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
6895 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
6899 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
6901 // make a rectange to trace around border of the button
6902 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
6904 #if NotUntilCairoIsFixed
6905 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
6906 DashStyle oldStyle; // used for caching old penstyle
6907 Pen pen = ResPool.GetPen (colorBackInverted);
6909 oldStyle = pen.DashStyle;
6910 pen.DashStyle = DashStyle.Dot;
6912 graphics.DrawRectangle (pen, trace_rectangle);
6913 pen.DashStyle = oldStyle;
6915 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
6920 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
6922 Rectangle rect = rectangle;
6926 if (backColor.GetBrightness () >= 0.5) {
6927 foreColor = Color.Transparent;
6928 backColor = Color.Black;
6931 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
6932 foreColor = Color.Black;
6935 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
6936 pen = new Pen (brush, 1);
6941 graphics.DrawRectangle (pen, rect);
6945 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
6950 if (primary == true) {
6952 if (enabled == true) {
6955 sb = SystemBrushes.Control;
6959 if (enabled == true) {
6962 sb = SystemBrushes.Control;
6965 graphics.FillRectangle (sb, rectangle);
6966 graphics.DrawRectangle (pen, rectangle);
6970 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
6976 ControlPaint.Color2HBS(backColor, out h, out b, out s);
6979 foreColor=Color.Black;
6981 foreColor=Color.White;
6984 // still not perfect. it seems that ms calculates the position of the first dot or line
6986 using (Pen pen = new Pen (foreColor)) {
6987 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
6989 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
6990 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
6994 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
6996 Microsoft seems to ignore the background and simply make
6997 the image grayscale. At least when having > 256 colors on
7001 if (imagedisabled_attributes == null) {
7002 imagedisabled_attributes = new ImageAttributes ();
7003 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
7004 // This table would create a perfect grayscale image, based on luminance
7005 // new float[]{0.3f,0.3f,0.3f,0,0},
7006 // new float[]{0.59f,0.59f,0.59f,0,0},
7007 // new float[]{0.11f,0.11f,0.11f,0,0},
7008 // new float[]{0,0,0,1,0,0},
7009 // new float[]{0,0,0,0,1,0},
7010 // new float[]{0,0,0,0,0,1}
7012 // This table generates a image that is grayscaled and then
7013 // brightened up. Seems to match MS close enough.
7014 new float[]{0.2f,0.2f,0.2f,0,0},
7015 new float[]{0.41f,0.41f,0.41f,0,0},
7016 new float[]{0.11f,0.11f,0.11f,0,0},
7017 new float[]{0.15f,0.15f,0.15f,1,0,0},
7018 new float[]{0.15f,0.15f,0.15f,0,1,0},
7019 new float[]{0.15f,0.15f,0.15f,0,0,1}
7022 imagedisabled_attributes.SetColorMatrix (colorMatrix);
7025 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
7030 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
7035 penBorder = ResPool.GetSizedPen (Color.White, 2);
7036 penInside = ResPool.GetPen (Color.Black);
7038 penBorder = ResPool.GetSizedPen (Color.Black, 2);
7039 penInside = ResPool.GetPen (Color.White);
7041 penBorder.Alignment=PenAlignment.Inset;
7042 penInside.Alignment=PenAlignment.Inset;
7044 graphics.DrawRectangle(penBorder, rectangle);
7045 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
7049 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color, Color backColor) {
7053 if (backColor != Color.Empty)
7054 graphics.FillRectangle (ResPool.GetSolidBrush (backColor), rectangle);
7056 Brush brush = ResPool.GetSolidBrush (color);
7059 case MenuGlyph.Arrow: {
7060 float height = rectangle.Height * 0.7f;
7061 float width = height / 2.0f;
7063 PointF ddCenter = new PointF (rectangle.X + ((rectangle.Width-width) / 2.0f), rectangle.Y + (rectangle.Height / 2.0f));
7065 PointF [] vertices = new PointF [3];
7066 vertices [0].X = ddCenter.X;
7067 vertices [0].Y = ddCenter.Y - (height / 2.0f);
7068 vertices [1].X = ddCenter.X;
7069 vertices [1].Y = ddCenter.Y + (height / 2.0f);
7070 vertices [2].X = ddCenter.X + width + 0.1f;
7071 vertices [2].Y = ddCenter.Y;
7073 graphics.FillPolygon (brush, vertices);
7078 case MenuGlyph.Bullet: {
7080 lineWidth=Math.Max(2, rectangle.Width/3);
7081 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
7083 graphics.FillEllipse(brush, rect);
7088 case MenuGlyph.Checkmark: {
7090 Pen pen = ResPool.GetPen (color);
7091 lineWidth = Math.Max (2, rectangle.Width / 6);
7092 rect = new Rectangle(rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height- lineWidth * 2);
7094 int Scale = Math.Max (1, rectangle.Width / 12);
7095 int top = (rect.Y + lineWidth + ((rect.Height - ((2 * Scale) + lineWidth)) / 2));
7097 for (int i=0; i<lineWidth; i++) {
7098 graphics.DrawLine (pen, rect.Left+lineWidth/2, top+i, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i);
7099 graphics.DrawLine (pen, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i, rect.Left+lineWidth/2+6*Scale, top-2*Scale+i);
7107 public override void CPDrawMixedCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state)
7109 CPDrawCheckBoxInternal (graphics, rectangle, state, true /* mixed */);
7112 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
7114 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
7116 Color dot_color = Color.Black;
7118 Color top_left_outer = Color.Black;
7119 Color top_left_inner = Color.Black;
7120 Color bottom_right_outer = Color.Black;
7121 Color bottom_right_inner = Color.Black;
7123 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
7124 int radius = ellipse_diameter / 2;
7126 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
7130 if ((state & ButtonState.All) == ButtonState.All) {
7131 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
7132 ColorControl.G, ColorControl.B), ColorControl);
7133 dot_color = cpcolor.Dark;
7135 if ((state & ButtonState.Flat) == ButtonState.Flat) {
7136 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
7137 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
7139 brush = SystemBrushes.ControlLightLight;
7141 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
7142 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
7144 brush = SystemBrushes.ControlLightLight;
7146 top_left_outer = cpcolor.Dark;
7147 top_left_inner = cpcolor.DarkDark;
7148 bottom_right_outer = cpcolor.Light;
7149 bottom_right_inner = Color.Transparent;
7151 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
7152 dot_color = cpcolor.Dark;
7155 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
7157 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
7159 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
7160 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
7161 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
7163 if (bottom_right_inner != Color.Transparent)
7164 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
7166 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)) {
7167 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
7170 if ((state & ButtonState.Checked) == ButtonState.Checked) {
7171 int inflate = line_width * 4;
7172 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
7173 if (rectangle.Height > 13) {
7177 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
7179 Pen pen = ResPool.GetPen (dot_color);
7180 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
7181 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
7183 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
7184 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
7189 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
7194 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
7199 /* Scroll button: regular button + direction arrow */
7200 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
7202 DrawScrollButtonPrimitive (dc, area, state);
7204 bool fill_rect = true;
7207 if ((state & ButtonState.Pushed) != 0)
7211 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
7213 Point [] arrow = new Point [3];
7214 for (int i = 0; i < 3; i++)
7215 arrow [i] = new Point ();
7217 Pen pen = SystemPens.ControlText;
7219 if ((state & ButtonState.Inactive) != 0) {
7220 pen = SystemPens.ControlDark;
7225 case ScrollButton.Down:
7226 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
7227 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7231 int triangle_height;
7233 if (rect.Height < 8) {
7234 triangle_height = 2;
7236 } else if (rect.Height == 11) {
7237 triangle_height = 3;
7239 triangle_height = (int)Math.Round (rect.Height / 3.0f);
7242 arrow [0].X = rect.X + x_middle;
7243 arrow [0].Y = rect.Y + y_middle + triangle_height / 2;
7245 arrow [1].X = arrow [0].X + triangle_height - 1;
7246 arrow [1].Y = arrow [0].Y - triangle_height + 1;
7247 arrow [2].X = arrow [0].X - triangle_height + 1;
7248 arrow [2].Y = arrow [1].Y;
7250 dc.DrawPolygon (pen, arrow);
7252 if ((state & ButtonState.Inactive) != 0) {
7253 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
7254 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
7258 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
7259 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
7266 case ScrollButton.Up:
7267 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
7268 y_middle = (int)Math.Round (rect.Height / 2.0f);
7275 if (rect.Height < 8) {
7276 triangle_height = 2;
7278 } else if (rect.Height == 11) {
7279 triangle_height = 3;
7281 triangle_height = (int)Math.Round (rect.Height / 3.0f);
7284 arrow [0].X = rect.X + x_middle;
7285 arrow [0].Y = rect.Y + y_middle - triangle_height / 2;
7287 arrow [1].X = arrow [0].X + triangle_height - 1;
7288 arrow [1].Y = arrow [0].Y + triangle_height - 1;
7289 arrow [2].X = arrow [0].X - triangle_height + 1;
7290 arrow [2].Y = arrow [1].Y;
7292 dc.DrawPolygon (pen, arrow);
7294 if ((state & ButtonState.Inactive) != 0) {
7295 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
7299 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
7300 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
7307 case ScrollButton.Left:
7308 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7314 if (rect.Width < 8) {
7317 } else if (rect.Width == 11) {
7320 triangle_width = (int)Math.Round (rect.Width / 3.0f);
7323 arrow [0].X = rect.Left + triangle_width - 1;
7324 arrow [0].Y = rect.Y + y_middle;
7326 if (arrow [0].X - 1 == rect.X)
7329 arrow [1].X = arrow [0].X + triangle_width - 1;
7330 arrow [1].Y = arrow [0].Y - triangle_width + 1;
7331 arrow [2].X = arrow [1].X;
7332 arrow [2].Y = arrow [0].Y + triangle_width - 1;
7334 dc.DrawPolygon (pen, arrow);
7336 if ((state & ButtonState.Inactive) != 0) {
7337 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
7341 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
7342 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
7349 case ScrollButton.Right:
7350 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
7354 if (rect.Width < 8) {
7357 } else if (rect.Width == 11) {
7360 triangle_width = (int)Math.Round (rect.Width / 3.0f);
7363 arrow [0].X = rect.Right - triangle_width - 1;
7364 arrow [0].Y = rect.Y + y_middle;
7366 if (arrow [0].X - 1 == rect.X)
7369 arrow [1].X = arrow [0].X - triangle_width + 1;
7370 arrow [1].Y = arrow [0].Y - triangle_width + 1;
7371 arrow [2].X = arrow [1].X;
7372 arrow [2].Y = arrow [0].Y + triangle_width - 1;
7374 dc.DrawPolygon (pen, arrow);
7376 if ((state & ButtonState.Inactive) != 0) {
7377 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
7378 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
7382 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
7383 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
7392 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
7398 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
7400 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
7401 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
7403 for (int i = 2; i < bounds.Width - 2; i += 4) {
7404 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
7405 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
7406 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
7410 private void DrawStringDisabled20 (Graphics g, string s, Font font, Rectangle layoutRectangle, Color color, TextFormatFlags flags, bool useDrawString)
7412 CPColor cpcolor = ResPool.GetCPColor (color);
7414 layoutRectangle.Offset (1, 1);
7415 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.LightLight, flags, useDrawString);
7417 layoutRectangle.Offset (-1, -1);
7418 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.Dark, flags, useDrawString);
7421 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
7423 CPColor cpcolor = ResPool.GetCPColor (color);
7425 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
7426 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
7428 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
7431 public override void CPDrawStringDisabled (IDeviceContext dc, string s, Font font, Color color, Rectangle layoutRectangle, TextFormatFlags format)
7433 CPColor cpcolor = ResPool.GetCPColor (color);
7435 layoutRectangle.Offset (1, 1);
7436 TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.LightLight, format);
7438 layoutRectangle.Offset (-1, -1);
7439 TextRenderer.DrawText (dc, s, font, layoutRectangle, cpcolor.Dark, format);
7442 public override void CPDrawVisualStyleBorder (Graphics graphics, Rectangle bounds)
7444 graphics.DrawRectangle (SystemPens.ControlDarkDark, bounds);
7447 private static void DrawBorderInternal (Graphics graphics, int startX, int startY, int endX, int endY,
7448 int width, Color color, ButtonBorderStyle style, Border3DSide side)
7450 DrawBorderInternal (graphics, (float) startX, (float) startY, (float) endX, (float) endY,
7451 width, color, style, side);
7454 private static void DrawBorderInternal (Graphics graphics, float startX, float startY, float endX, float endY,
7455 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
7460 case ButtonBorderStyle.Solid:
7461 case ButtonBorderStyle.Inset:
7462 case ButtonBorderStyle.Outset:
7463 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
7465 case ButtonBorderStyle.Dashed:
7466 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
7468 case ButtonBorderStyle.Dotted:
7469 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
7472 case ButtonBorderStyle.None:
7477 case ButtonBorderStyle.Outset: {
7479 int hue, brightness, saturation;
7480 int brightnessSteps;
7481 int brightnessDownSteps;
7483 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
7485 brightnessDownSteps=brightness/width;
7486 if (brightness>127) {
7487 brightnessSteps=Math.Max(6, (160-brightness)/width);
7489 brightnessSteps=(127-brightness)/width;
7492 for (int i=0; i<width; i++) {
7494 case Border3DSide.Left: {
7495 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7496 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7497 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7501 case Border3DSide.Right: {
7502 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7503 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7504 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7508 case Border3DSide.Top: {
7509 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7510 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7511 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7515 case Border3DSide.Bottom: {
7516 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7517 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7518 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7526 case ButtonBorderStyle.Inset: {
7528 int hue, brightness, saturation;
7529 int brightnessSteps;
7530 int brightnessDownSteps;
7532 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
7534 brightnessDownSteps=brightness/width;
7535 if (brightness>127) {
7536 brightnessSteps=Math.Max(6, (160-brightness)/width);
7538 brightnessSteps=(127-brightness)/width;
7541 for (int i=0; i<width; i++) {
7543 case Border3DSide.Left: {
7544 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7545 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7546 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7550 case Border3DSide.Right: {
7551 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7552 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7553 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7557 case Border3DSide.Top: {
7558 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
7559 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7560 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7564 case Border3DSide.Bottom: {
7565 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
7566 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
7567 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7576 I decided to have the for-loop duplicated for speed reasons;
7577 that way we only have to switch once (as opposed to have the
7578 for-loop around the switch)
7582 case Border3DSide.Left: {
7583 for (int i=0; i<width; i++) {
7584 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
7589 case Border3DSide.Right: {
7590 for (int i=0; i<width; i++) {
7591 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
7596 case Border3DSide.Top: {
7597 for (int i=0; i<width; i++) {
7598 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
7603 case Border3DSide.Bottom: {
7604 for (int i=0; i<width; i++) {
7605 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
7616 This function actually draws the various caption elements.
7617 This way we can scale them nicely, no matter what size, and they
7618 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
7621 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
7623 case CaptionButton.Close: {
7625 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);
7626 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);
7629 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
7630 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
7634 case CaptionButton.Help: {
7635 StringFormat sf = new StringFormat();
7636 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
7638 sf.Alignment=StringAlignment.Center;
7639 sf.LineAlignment=StringAlignment.Center;
7642 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
7650 case CaptionButton.Maximize: {
7651 /* Top 'caption bar' line */
7652 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7653 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);
7656 /* Left side line */
7657 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7658 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
7661 /* Right side line */
7662 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7663 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);
7667 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7668 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
7673 case CaptionButton.Minimize: {
7675 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7676 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
7681 case CaptionButton.Restore: {
7682 /** First 'window' **/
7683 /* Top 'caption bar' line */
7684 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7685 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);
7688 /* Left side line */
7689 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7690 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);
7693 /* Right side line */
7694 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7695 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);
7699 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7700 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);
7703 /** Second 'window' **/
7704 /* Top 'caption bar' line */
7705 for (int i=0; i<Math.Max(2, lineWidth); i++) {
7706 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);
7709 /* Left side line */
7710 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7711 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
7714 /* Right side line */
7715 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7716 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);
7720 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
7721 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
7730 /* Generic scroll button */
7731 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
7732 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
7733 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
7734 area.Y + 1, area.Width - 2 , area.Height - 2);
7736 dc.DrawRectangle (SystemPens.ControlDark, area.X,
7737 area.Y, area.Width, area.Height);
7742 Brush sb_control = SystemBrushes.Control;
7743 Brush sb_lightlight = SystemBrushes.ControlLightLight;
7744 Brush sb_dark = SystemBrushes.ControlDark;
7745 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
7747 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
7748 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
7750 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
7751 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
7754 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
7757 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
7760 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
7761 area.Y + 1, 1, area.Height -3);
7763 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
7764 area.Y, 1, area.Height - 1);
7766 dc.FillRectangle (sb_control, area.X + 2,
7767 area.Y + 2, area.Width - 4, area.Height - 4);
7771 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
7772 switch (border_style){
7773 case BorderStyle.Fixed3D:
7774 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
7775 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
7776 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
7777 area.Y + area.Height - 1);
7778 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
7779 area.Y + area.Height);
7781 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
7782 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
7783 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
7784 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
7786 case BorderStyle.FixedSingle:
7787 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
7789 case BorderStyle.None:
7795 #endregion // ControlPaint