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 readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
55 protected static StringFormat string_format_menu_text;
56 protected static StringFormat string_format_menu_shortcut;
57 protected static StringFormat string_format_menu_menubar_text;
58 static ImageAttributes imagedisabled_attributes = null;
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 tab
64 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
66 #region Principal Theme Methods
67 public ThemeWin32Classic ()
69 defaultWindowBackColor = this.ColorWindow;
70 defaultWindowForeColor = this.ColorControlText;
71 window_border_font = new Font(FontFamily.GenericSansSerif, 8.25f, FontStyle.Bold);
73 /* Menu string formats */
74 string_format_menu_text = new StringFormat ();
75 string_format_menu_text.LineAlignment = StringAlignment.Center;
76 string_format_menu_text.Alignment = StringAlignment.Near;
77 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
79 string_format_menu_shortcut = new StringFormat ();
80 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
81 string_format_menu_shortcut.Alignment = StringAlignment.Far;
83 string_format_menu_menubar_text = new StringFormat ();
84 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
85 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
86 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
89 public override void ResetDefaults() {
90 Console.WriteLine("NOT IMPLEMENTED: ResetDefault()");
91 //throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
94 public override bool DoubleBufferingSupported {
98 public override int HorizontalScrollBarHeight {
100 return XplatUI.HorizontalScrollBarHeight;
104 public override int VerticalScrollBarWidth {
106 return XplatUI.VerticalScrollBarWidth;
110 #endregion // Principal Theme Methods
112 #region Internal Methods
113 protected Brush GetControlBackBrush (Color c) {
114 if (c.ToArgb () == DefaultControlBackColor.ToArgb ())
115 return SystemBrushes.Control;
116 return ResPool.GetSolidBrush (c);
119 protected Brush GetControlForeBrush (Color c) {
120 if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
121 return SystemBrushes.ControlText;
122 return ResPool.GetSolidBrush (c);
124 #endregion // Internal Methods
126 #region OwnerDraw Support
127 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
129 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
130 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
134 e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
137 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
139 if (e.State == DrawItemState.Focus)
140 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
142 #endregion // OwnerDraw Support
145 #region Standard Button Style
146 public override void DrawButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
148 // Draw Button Background
149 DrawButtonBackground (g, b, clipRectangle);
151 // If we have an image, draw it
152 if (imageBounds.Size != Size.Empty)
153 DrawButtonImage (g, b, imageBounds);
155 // If we're focused, draw a focus rectangle
156 if (b.Focused && b.Enabled)
157 DrawButtonFocus (g, b);
159 // If we have text, draw it
160 if (textBounds != Rectangle.Empty)
161 DrawButtonText (g, b, textBounds);
164 public virtual void DrawButtonBackground (Graphics g, Button button, Rectangle clipArea)
167 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
168 else if (button.InternalSelected)
169 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
170 else if (button.Entered)
171 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
172 else if (!button.Enabled)
173 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
175 ThemeElements.DrawButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
178 public virtual void DrawButtonFocus (Graphics g, Button button)
180 ControlPaint.DrawFocusRectangle (g, Rectangle.Inflate (button.ClientRectangle, -4, -4));
183 public virtual void DrawButtonImage (Graphics g, Button button, Rectangle imageBounds)
186 g.DrawImage (button.Image, imageBounds);
188 CPDrawImageDisabled (g, button.Image, imageBounds.Left, imageBounds.Top, ColorControl);
191 public virtual void DrawButtonText (Graphics g, Button button, Rectangle textBounds)
194 textBounds.Offset (1, 1);
197 TextRenderer.DrawTextInternal (g, button.Text, button.Font, textBounds, button.ForeColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
199 DrawStringDisabled20 (g, button.Text, button.Font, textBounds, button.BackColor, button.TextFormatFlags, button.UseCompatibleTextRendering);
203 #region FlatStyle Button Style
204 public override void DrawFlatButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
206 // Draw Button Background
207 DrawFlatButtonBackground (g, b, clipRectangle);
209 // If we have an image, draw it
210 if (imageBounds.Size != Size.Empty)
211 DrawFlatButtonImage (g, b, imageBounds);
213 // If we're focused, draw a focus rectangle
214 if (b.Focused && b.Enabled)
215 DrawFlatButtonFocus (g, b);
217 // If we have text, draw it
218 if (textBounds != Rectangle.Empty)
219 DrawFlatButtonText (g, b, textBounds);
222 public virtual void DrawFlatButtonBackground (Graphics g, Button button, Rectangle clipArea)
225 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor, button.FlatAppearance);
226 else if (button.InternalSelected)
227 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor, button.FlatAppearance);
228 else if (button.Entered)
229 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor, button.FlatAppearance);
230 else if (!button.Enabled)
231 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor, button.FlatAppearance);
233 ThemeElements.DrawFlatButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor, button.FlatAppearance);
236 public virtual void DrawFlatButtonFocus (Graphics g, Button button)
238 if (!button.Pressed) {
239 Color focus_color = ControlPaint.Light(button.BackColor);
240 g.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.Left + 4, button.ClientRectangle.Top + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9));
244 public virtual void DrawFlatButtonImage (Graphics g, Button button, Rectangle imageBounds)
246 // No changes from Standard for image for this theme
247 DrawButtonImage (g, button, imageBounds);
250 public virtual void DrawFlatButtonText (Graphics g, Button button, Rectangle textBounds)
252 // No changes from Standard for image for this theme
253 DrawButtonText (g, button, textBounds);
257 #region Popup Button Style
258 public override void DrawPopupButton (Graphics g, Button b, Rectangle textBounds, Rectangle imageBounds, Rectangle clipRectangle)
260 // Draw Button Background
261 DrawPopupButtonBackground (g, b, clipRectangle);
263 // If we have an image, draw it
264 if (imageBounds.Size != Size.Empty)
265 DrawPopupButtonImage (g, b, imageBounds);
267 // If we're focused, draw a focus rectangle
268 if (b.Focused && b.Enabled)
269 DrawPopupButtonFocus (g, b);
271 // If we have text, draw it
272 if (textBounds != Rectangle.Empty)
273 DrawPopupButtonText (g, b, textBounds);
276 public virtual void DrawPopupButtonBackground (Graphics g, Button button, Rectangle clipArea)
279 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Pressed, button.BackColor, button.ForeColor);
280 else if (button.Entered)
281 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Entered, button.BackColor, button.ForeColor);
282 else if (button.InternalSelected)
283 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Default, button.BackColor, button.ForeColor);
284 else if (!button.Enabled)
285 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Disabled, button.BackColor, button.ForeColor);
287 ThemeElements.DrawPopupButton (g, button.ClientRectangle, ButtonThemeState.Normal, button.BackColor, button.ForeColor);
290 public virtual void DrawPopupButtonFocus (Graphics g, Button button)
292 // No changes from Standard for image for this theme
293 DrawButtonFocus (g, button);
296 public virtual void DrawPopupButtonImage (Graphics g, Button button, Rectangle imageBounds)
298 // No changes from Standard for image for this theme
299 DrawButtonImage (g, button, imageBounds);
302 public virtual void DrawPopupButtonText (Graphics g, Button button, Rectangle textBounds)
304 // No changes from Standard for image for this theme
305 DrawButtonText (g, button, textBounds);
309 #region Button Layout Calculations
310 public override void CalculateButtonTextAndImageLayout (Button button, out Rectangle textRectangle, out Rectangle imageRectangle)
312 Image image = button.Image;
313 string text = button.Text;
314 Rectangle content_rect = button.ClientRectangle;
315 Size text_size = TextRenderer.MeasureTextInternal (text, button.Font, content_rect.Size, button.TextFormatFlags, button.UseCompatibleTextRendering);
316 Size image_size = image == null ? Size.Empty : image.Size;
318 textRectangle = Rectangle.Empty;
319 imageRectangle = Rectangle.Empty;
321 switch (button.TextImageRelation) {
322 case TextImageRelation.Overlay:
323 // Overlay is easy, text always goes here
324 textRectangle = Rectangle.Inflate (content_rect, -4, -4);
327 textRectangle.Offset (1, 1);
329 // Image is dependent on ImageAlign
335 int image_height = image.Height;
336 int image_width = image.Width;
338 switch (button.ImageAlign) {
339 case System.Drawing.ContentAlignment.TopLeft:
343 case System.Drawing.ContentAlignment.TopCenter:
344 image_x = (content_rect.Width - image_width) / 2;
347 case System.Drawing.ContentAlignment.TopRight:
348 image_x = content_rect.Width - image_width - 5;
351 case System.Drawing.ContentAlignment.MiddleLeft:
353 image_y = (content_rect.Height - image_height) / 2;
355 case System.Drawing.ContentAlignment.MiddleCenter:
356 image_x = (content_rect.Width - image_width) / 2;
357 image_y = (content_rect.Height - image_height) / 2;
359 case System.Drawing.ContentAlignment.MiddleRight:
360 image_x = content_rect.Width - image_width - 4;
361 image_y = (content_rect.Height - image_height) / 2;
363 case System.Drawing.ContentAlignment.BottomLeft:
365 image_y = content_rect.Height - image_height - 4;
367 case System.Drawing.ContentAlignment.BottomCenter:
368 image_x = (content_rect.Width - image_width) / 2;
369 image_y = content_rect.Height - image_height - 4;
371 case System.Drawing.ContentAlignment.BottomRight:
372 image_x = content_rect.Width - image_width - 4;
373 image_y = content_rect.Height - image_height - 4;
381 imageRectangle = new Rectangle (image_x, image_y, image_width, image_height);
383 case TextImageRelation.ImageAboveText:
384 content_rect.Inflate (-4, -4);
385 LayoutTextAboveOrBelowImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
387 case TextImageRelation.TextAboveImage:
388 content_rect.Inflate (-4, -4);
389 LayoutTextAboveOrBelowImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
391 case TextImageRelation.ImageBeforeText:
392 content_rect.Inflate (-4, -4);
393 LayoutTextBeforeOrAfterImage (content_rect, false, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
395 case TextImageRelation.TextBeforeImage:
396 content_rect.Inflate (-4, -4);
397 LayoutTextBeforeOrAfterImage (content_rect, true, text_size, image_size, button.TextAlign, button.ImageAlign, out textRectangle, out imageRectangle);
402 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)
404 int element_spacing = 0; // Spacing between the Text and the Image
405 int total_width = textSize.Width + element_spacing + imageSize.Width;
408 element_spacing += 2;
410 // If the text is too big, chop it down to the size we have available to it
411 if (total_width > totalArea.Width) {
412 textSize.Width = totalArea.Width - element_spacing - imageSize.Width;
413 total_width = totalArea.Width;
416 int excess_width = totalArea.Width - total_width;
419 Rectangle final_text_rect;
420 Rectangle final_image_rect;
422 HorizontalAlignment h_text = GetHorizontalAlignment (textAlign);
423 HorizontalAlignment h_image = GetHorizontalAlignment (imageAlign);
425 if (h_image == HorizontalAlignment.Left)
427 else if (h_image == HorizontalAlignment.Right && h_text == HorizontalAlignment.Right)
428 offset = excess_width;
429 else if (h_image == HorizontalAlignment.Center && (h_text == HorizontalAlignment.Left || h_text == HorizontalAlignment.Center))
430 offset += (int)(excess_width / 3);
432 offset += (int)(2 * (excess_width / 3));
435 final_text_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
436 final_image_rect = new Rectangle (final_text_rect.Right + element_spacing, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
439 final_image_rect = new Rectangle (totalArea.Left + offset, AlignInRectangle (totalArea, imageSize, imageAlign).Top, imageSize.Width, imageSize.Height);
440 final_text_rect = new Rectangle (final_image_rect.Right + element_spacing, AlignInRectangle (totalArea, textSize, textAlign).Top, textSize.Width, textSize.Height);
443 textRect = final_text_rect;
444 imageRect = final_image_rect;
447 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)
449 int element_spacing = 0; // Spacing between the Text and the Image
450 int total_height = textSize.Height + element_spacing + imageSize.Height;
453 element_spacing += 2;
455 if (textSize.Width > totalArea.Width)
456 textSize.Width = totalArea.Width;
458 // If the there isn't enough room and we're text first, cut out the image
459 if (total_height > totalArea.Height && textFirst) {
460 imageSize = Size.Empty;
461 total_height = totalArea.Height;
464 int excess_height = totalArea.Height - total_height;
467 Rectangle final_text_rect;
468 Rectangle final_image_rect;
470 VerticalAlignment v_text = GetVerticalAlignment (textAlign);
471 VerticalAlignment v_image = GetVerticalAlignment (imageAlign);
473 if (v_image == VerticalAlignment.Top)
475 else if (v_image == VerticalAlignment.Bottom && v_text == VerticalAlignment.Bottom)
476 offset = excess_height;
477 else if (v_image == VerticalAlignment.Center && (v_text == VerticalAlignment.Top || v_text == VerticalAlignment.Center))
478 offset += (int)(excess_height / 3);
480 offset += (int)(2 * (excess_height / 3));
483 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, totalArea.Top + offset, textSize.Width, textSize.Height);
484 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, final_text_rect.Bottom + element_spacing, imageSize.Width, imageSize.Height);
487 final_image_rect = new Rectangle (AlignInRectangle (totalArea, imageSize, imageAlign).Left, totalArea.Top + offset, imageSize.Width, imageSize.Height);
488 final_text_rect = new Rectangle (AlignInRectangle (totalArea, textSize, textAlign).Left, final_image_rect.Bottom + element_spacing, textSize.Width, textSize.Height);
490 if (final_text_rect.Bottom > totalArea.Bottom)
491 final_text_rect.Y = totalArea.Top;
494 textRect = final_text_rect;
495 imageRect = final_image_rect;
498 private HorizontalAlignment GetHorizontalAlignment (System.Drawing.ContentAlignment align)
501 case System.Drawing.ContentAlignment.BottomLeft:
502 case System.Drawing.ContentAlignment.MiddleLeft:
503 case System.Drawing.ContentAlignment.TopLeft:
504 return HorizontalAlignment.Left;
505 case System.Drawing.ContentAlignment.BottomCenter:
506 case System.Drawing.ContentAlignment.MiddleCenter:
507 case System.Drawing.ContentAlignment.TopCenter:
508 return HorizontalAlignment.Center;
509 case System.Drawing.ContentAlignment.BottomRight:
510 case System.Drawing.ContentAlignment.MiddleRight:
511 case System.Drawing.ContentAlignment.TopRight:
512 return HorizontalAlignment.Right;
515 return HorizontalAlignment.Left;
518 private enum VerticalAlignment
525 private VerticalAlignment GetVerticalAlignment (System.Drawing.ContentAlignment align)
528 case System.Drawing.ContentAlignment.TopLeft:
529 case System.Drawing.ContentAlignment.TopCenter:
530 case System.Drawing.ContentAlignment.TopRight:
531 return VerticalAlignment.Top;
532 case System.Drawing.ContentAlignment.MiddleLeft:
533 case System.Drawing.ContentAlignment.MiddleCenter:
534 case System.Drawing.ContentAlignment.MiddleRight:
535 return VerticalAlignment.Center;
536 case System.Drawing.ContentAlignment.BottomLeft:
537 case System.Drawing.ContentAlignment.BottomCenter:
538 case System.Drawing.ContentAlignment.BottomRight:
539 return VerticalAlignment.Bottom;
542 return VerticalAlignment.Top;
545 internal Rectangle AlignInRectangle (Rectangle outer, Size inner, System.Drawing.ContentAlignment align)
550 if (align == System.Drawing.ContentAlignment.BottomLeft || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.TopLeft)
552 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.TopCenter)
553 x = Math.Max (outer.X + ((outer.Width - inner.Width) / 2), outer.Left);
554 else if (align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.MiddleRight || align == System.Drawing.ContentAlignment.TopRight)
555 x = outer.Right - inner.Width;
556 if (align == System.Drawing.ContentAlignment.TopCenter || align == System.Drawing.ContentAlignment.TopLeft || align == System.Drawing.ContentAlignment.TopRight)
558 else if (align == System.Drawing.ContentAlignment.MiddleCenter || align == System.Drawing.ContentAlignment.MiddleLeft || align == System.Drawing.ContentAlignment.MiddleRight)
559 y = outer.Y + (outer.Height - inner.Height) / 2;
560 else if (align == System.Drawing.ContentAlignment.BottomCenter || align == System.Drawing.ContentAlignment.BottomRight || align == System.Drawing.ContentAlignment.BottomLeft)
561 y = outer.Bottom - inner.Height;
563 return new Rectangle (x, y, Math.Min (inner.Width, outer.Width), Math.Min (inner.Height, outer.Height));
569 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button)
571 // Draw the button: Draw border, etc.
572 ButtonBase_DrawButton(button, dc);
575 if (button.FlatStyle != FlatStyle.System && ((button.image != null) || (button.image_list != null)))
576 ButtonBase_DrawImage(button, dc);
578 // Draw the focus rectangle
579 if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled)
580 ButtonBase_DrawFocus(button, dc);
583 if (button.Text != null && button.Text != String.Empty)
584 ButtonBase_DrawText(button, dc);
587 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
589 Rectangle borderRectangle;
590 bool check_or_radio = false;
591 bool check_or_radio_checked = false;
593 bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
595 CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
597 if (button is CheckBox) {
598 check_or_radio = true;
599 check_or_radio_checked = ((CheckBox)button).Checked;
600 } else if (button is RadioButton) {
601 check_or_radio = true;
602 check_or_radio_checked = ((RadioButton)button).Checked;
605 if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled && !check_or_radio) {
606 // shrink the rectangle for the normal button drawing inside the focus rectangle
607 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
609 borderRectangle = button.ClientRectangle;
612 if (button.FlatStyle == FlatStyle.Popup) {
613 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
614 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
615 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
616 Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
617 else if (button.is_pressed || check_or_radio_checked)
618 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
619 } else if (button.FlatStyle == FlatStyle.Flat) {
620 if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
621 if ((button.image == null) && (button.image_list == null)) {
622 Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
623 dc.FillRectangle (brush, borderRectangle);
625 } else if (button.is_pressed || check_or_radio_checked) {
626 if ((button.image == null) && (button.image_list == null)) {
627 Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
628 dc.FillRectangle (brush, borderRectangle);
631 Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
632 dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
633 borderRectangle.Width - 9, borderRectangle.Height - 9);
636 Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
638 if ((!button.is_pressed || !button.Enabled) && !check_or_radio_checked)
639 Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
641 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
645 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
648 case 0: // normal or normal disabled button
649 Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
650 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
651 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
653 pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
654 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
655 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
657 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
658 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
659 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
661 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
662 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
663 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
665 case 1: // popup button normal (or pressed normal or popup button)
666 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
667 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
669 case 2: // popup button poped up
670 pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
671 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
672 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
674 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
675 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
676 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
678 case 3: // flat button not entered
679 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
680 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
687 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
689 // Need to draw a picture
696 int width = button.ClientSize.Width;
697 int height = button.ClientSize.Height;
699 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
700 i = button.image_list.Images[button.ImageIndex];
705 image_width = i.Width;
706 image_height = i.Height;
708 switch (button.ImageAlign) {
709 case ContentAlignment.TopLeft: {
715 case ContentAlignment.TopCenter: {
716 image_x = (width - image_width) / 2;
721 case ContentAlignment.TopRight: {
722 image_x = width - image_width - 5;
727 case ContentAlignment.MiddleLeft: {
729 image_y = (height - image_height) / 2;
733 case ContentAlignment.MiddleCenter: {
734 image_x = (width - image_width) / 2;
735 image_y = (height - image_height) / 2;
739 case ContentAlignment.MiddleRight: {
740 image_x = width - image_width - 4;
741 image_y = (height - image_height) / 2;
745 case ContentAlignment.BottomLeft: {
747 image_y = height - image_height - 4;
751 case ContentAlignment.BottomCenter: {
752 image_x = (width - image_width) / 2;
753 image_y = height - image_height - 4;
757 case ContentAlignment.BottomRight: {
758 image_x = width - image_width - 4;
759 image_y = height - image_height - 4;
770 dc.SetClip (new Rectangle(3, 3, width - 5, height - 5));
773 dc.DrawImage (i, image_x, image_y, image_width, image_height);
775 CPDrawImageDisabled (dc, i, image_x, image_y, ColorControl);
780 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
782 Color focus_color = button.ForeColor;
784 int inflate_value = -3;
786 if (!(button is CheckBox) && !(button is RadioButton)) {
789 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed)
790 focus_color = ControlPaint.Dark(button.BackColor);
792 dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y,
793 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
796 if (button.Focused) {
797 Rectangle rect = Rectangle.Inflate (button.ClientRectangle, inflate_value, inflate_value);
798 ControlPaint.DrawFocusRectangle (dc, rect);
802 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
804 Rectangle buttonRectangle = button.ClientRectangle;
805 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
807 if (button.is_pressed) {
812 if (button.Enabled) {
813 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
815 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
816 dc.DrawString(button.Text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
818 CPDrawStringDisabled (dc, button.Text, button.Font, button.BackColor, text_rect, button.text_format);
823 public override Size ButtonBaseDefaultSize {
825 return new Size (75, 23);
828 #endregion // ButtonBase
831 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
832 StringFormat text_format;
833 Rectangle client_rectangle;
834 Rectangle text_rectangle;
835 Rectangle checkbox_rectangle;
836 int checkmark_size=13;
837 int checkmark_space = 4;
839 client_rectangle = checkbox.ClientRectangle;
840 text_rectangle = client_rectangle;
841 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
843 text_format = new StringFormat();
844 text_format.Alignment=StringAlignment.Near;
845 text_format.LineAlignment=StringAlignment.Center;
846 text_format.HotkeyPrefix = HotkeyPrefix.Show;
848 /* Calculate the position of text and checkbox rectangle */
849 if (checkbox.appearance!=Appearance.Button) {
850 switch(checkbox.check_alignment) {
851 case ContentAlignment.BottomCenter: {
852 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
853 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
854 text_rectangle.X=client_rectangle.X;
855 text_rectangle.Width=client_rectangle.Width;
856 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
860 case ContentAlignment.BottomLeft: {
861 checkbox_rectangle.X=client_rectangle.Left;
862 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
863 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
864 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
868 case ContentAlignment.BottomRight: {
869 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
870 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
871 text_rectangle.X=client_rectangle.X;
872 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
876 case ContentAlignment.MiddleCenter: {
877 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
878 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
879 text_rectangle.X=client_rectangle.X;
880 text_rectangle.Width=client_rectangle.Width;
885 case ContentAlignment.MiddleLeft: {
886 checkbox_rectangle.X=client_rectangle.Left;
887 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
888 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
889 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
893 case ContentAlignment.MiddleRight: {
894 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
895 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
896 text_rectangle.X=client_rectangle.X;
897 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
901 case ContentAlignment.TopCenter: {
902 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
903 checkbox_rectangle.Y=client_rectangle.Top;
904 text_rectangle.X=client_rectangle.X;
905 text_rectangle.Width=client_rectangle.Width;
906 text_rectangle.Y=checkmark_size+checkmark_space;
907 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
911 case ContentAlignment.TopLeft: {
912 checkbox_rectangle.X=client_rectangle.Left;
913 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
914 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
918 case ContentAlignment.TopRight: {
919 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
920 text_rectangle.X=client_rectangle.X;
921 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
926 text_rectangle.X=client_rectangle.X;
927 text_rectangle.Width=client_rectangle.Width;
930 /* Set the horizontal alignment of our text */
931 switch(checkbox.text_alignment) {
932 case ContentAlignment.BottomLeft:
933 case ContentAlignment.MiddleLeft:
934 case ContentAlignment.TopLeft: {
935 text_format.Alignment=StringAlignment.Near;
939 case ContentAlignment.BottomCenter:
940 case ContentAlignment.MiddleCenter:
941 case ContentAlignment.TopCenter: {
942 text_format.Alignment=StringAlignment.Center;
946 case ContentAlignment.BottomRight:
947 case ContentAlignment.MiddleRight:
948 case ContentAlignment.TopRight: {
949 text_format.Alignment=StringAlignment.Far;
954 /* Set the vertical alignment of our text */
955 switch(checkbox.text_alignment) {
956 case ContentAlignment.TopLeft:
957 case ContentAlignment.TopCenter:
958 case ContentAlignment.TopRight: {
959 text_format.LineAlignment=StringAlignment.Near;
963 case ContentAlignment.BottomLeft:
964 case ContentAlignment.BottomCenter:
965 case ContentAlignment.BottomRight: {
966 text_format.LineAlignment=StringAlignment.Far;
970 case ContentAlignment.MiddleLeft:
971 case ContentAlignment.MiddleCenter:
972 case ContentAlignment.MiddleRight: {
973 text_format.LineAlignment=StringAlignment.Center;
978 ButtonState state = ButtonState.Normal;
979 if (checkbox.FlatStyle == FlatStyle.Flat) {
980 state |= ButtonState.Flat;
983 if (checkbox.Checked) {
984 state |= ButtonState.Checked;
987 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
988 state |= ButtonState.Checked;
989 state |= ButtonState.Pushed;
992 // finally make sure the pushed and inavtive states are rendered
993 if (!checkbox.Enabled) {
994 state |= ButtonState.Inactive;
996 else if (checkbox.is_pressed) {
997 state |= ButtonState.Pushed;
1002 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
1004 if ((checkbox.image != null) || (checkbox.image_list != null))
1005 ButtonBase_DrawImage(checkbox, dc);
1007 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
1009 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
1011 text_format.Dispose ();
1014 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
1016 Brush brush = checkbox.BackColor.ToArgb () == ColorControl.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
1017 dc.FillRectangle (brush, checkbox.ClientRectangle);
1018 // render as per normal button
1019 if (checkbox.appearance==Appearance.Button) {
1020 ButtonBase_DrawButton (checkbox, dc);
1022 if ((checkbox.Focused) && checkbox.Enabled)
1023 ButtonBase_DrawFocus(checkbox, dc);
1025 // establish if we are rendering a flat style of some sort
1026 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
1027 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
1029 CPDrawCheckBox (dc, checkbox_rectangle, state);
1034 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
1036 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
1037 text_format, checkbox.Appearance, checkbox.Checked);
1040 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
1042 if ( checkbox.Focused && checkbox.appearance != Appearance.Button && checkbox.Enabled )
1043 DrawInnerFocusRectangle( dc, text_rectangle, checkbox.BackColor );
1046 // renders a checkBox with the Flat and Popup FlatStyle
1047 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
1051 Rectangle checkbox_rectangle;
1052 Rectangle fill_rectangle;
1056 // set up our rectangles first
1057 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
1058 // clip one pixel from bottom right for non popup rendered checkboxes
1059 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
1060 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));
1062 // clip two pixels from bottom right for non popup rendered checkboxes
1063 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
1064 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));
1068 // if disabled render in disabled state
1069 if (checkbox.Enabled) {
1070 // process the state of the checkbox
1071 if (checkbox.is_entered || checkbox.Capture) {
1072 // decide on which background color to use
1073 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
1074 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1075 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
1076 if (!checkbox.is_pressed) {
1077 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
1079 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1081 // use regular window background color
1082 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1085 // render the outer border
1086 if (checkbox.FlatStyle == FlatStyle.Flat) {
1087 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1089 // draw sunken effect
1090 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
1093 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
1095 if (checkbox.FlatStyle == FlatStyle.Flat) {
1096 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
1098 // draw the outer border
1099 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
1103 if (checkbox.FlatStyle == FlatStyle.Popup) {
1104 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
1107 // draw disabled state,
1108 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
1111 if (checkbox.Checked) {
1112 /* Need to draw a check-mark */
1114 /* Make sure we've got at least a line width of 1 */
1115 lineWidth = Math.Max(3, fill_rectangle.Width/3);
1116 Scale=Math.Max(1, fill_rectangle.Width/9);
1118 // flat style check box is rendered inside a rectangle shifted down by one
1119 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
1120 if (checkbox.Enabled) {
1121 pen=ResPool.GetPen(checkbox.ForeColor);
1123 pen=SystemPens.ControlDark;
1126 for (int i=0; i<lineWidth; i++) {
1127 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
1128 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);
1133 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
1134 StringFormat text_format, Appearance appearance, bool ischecked)
1136 // offset the text if it's pressed and a button
1137 if (appearance == Appearance.Button) {
1138 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
1139 text_rectangle.X ++;
1140 text_rectangle.Y ++;
1143 text_rectangle.Inflate (-4, -4);
1146 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
1148 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
1149 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
1150 text_format.FormatFlags |= StringFormatFlags.NoWrap;
1152 if (button_base.Enabled) {
1153 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
1154 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
1155 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
1157 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
1160 #endregion // CheckBox
1162 #region CheckedListBox
1164 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
1166 Color back_color, fore_color;
1167 Rectangle item_rect = e.Bounds;
1172 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
1173 state = ButtonState.Checked;
1174 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
1175 state |= ButtonState.Inactive;
1177 state = ButtonState.Normal;
1179 if (ctrl.ThreeDCheckBoxes == false)
1180 state |= ButtonState.Flat;
1182 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
1183 ControlPaint.DrawCheckBox (e.Graphics,
1184 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
1185 checkbox_rect.Width, checkbox_rect.Height,
1188 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
1189 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
1192 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1193 back_color = ColorHighlight;
1194 fore_color = ColorHighlightText;
1197 back_color = e.BackColor;
1198 fore_color = e.ForeColor;
1201 e.Graphics.FillRectangle (ResPool.GetSolidBrush
1202 (back_color), item_rect);
1204 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1205 ResPool.GetSolidBrush (fore_color),
1206 item_rect, ctrl.StringFormat);
1208 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1209 CPDrawFocusRectangle (e.Graphics, item_rect,
1210 fore_color, back_color);
1214 #endregion // CheckedListBox
1217 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
1219 Color back_color, fore_color;
1220 Rectangle text_draw = e.Bounds;
1221 StringFormat string_format = new StringFormat ();
1222 string_format.FormatFlags = StringFormatFlags.LineLimit;
1224 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1225 back_color = ColorHighlight;
1226 fore_color = ColorHighlightText;
1229 back_color = e.BackColor;
1230 fore_color = e.ForeColor;
1234 fore_color = ColorInactiveCaptionText;
1236 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1238 if (e.Index != -1) {
1239 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1240 ResPool.GetSolidBrush (fore_color),
1241 text_draw, string_format);
1244 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1245 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1248 string_format.Dispose ();
1251 public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
1253 Point[] arrow = new Point[3];
1263 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
1264 centerX=rect.Left+rect.Width/2;
1265 centerY=rect.Top+rect.Height/2;
1266 shiftX=Math.Max(1, rect.Width/8);
1267 shiftY=Math.Max(1, rect.Height/8);
1269 if ((state & ButtonState.Pushed)!=0) {
1276 P1=new Point(rect.Left + 1, centerY);
1277 P2=new Point(rect.Right - 1, centerY);
1278 P3=new Point(centerX, rect.Bottom - 1);
1284 /* Draw the arrow */
1285 if ((state & ButtonState.Inactive)!=0) {
1286 /* Move away from the shadow */
1287 arrow[0].X += 1; arrow[0].Y += 1;
1288 arrow[1].X += 1; arrow[1].Y += 1;
1289 arrow[2].X += 1; arrow[2].Y += 1;
1291 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
1297 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
1299 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
1305 public override int DataGridPreferredColumnWidth { get { return 75;} }
1306 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
1307 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
1308 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
1309 public override Color DataGridBackColor { get { return ColorWindow;} }
1310 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
1311 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
1312 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
1313 public override Color DataGridGridLineColor { get { return ColorControl;} }
1314 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
1315 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
1316 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
1317 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
1318 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
1319 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
1320 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
1321 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
1323 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
1325 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
1326 DataGridPaintParentRows (pe.Graphics, pe.ClipRectangle, grid);
1327 DataGridPaintColumnHeaders (pe.Graphics, pe.ClipRectangle, grid);
1328 DataGridPaintRows (pe.Graphics, grid.cells_area, pe.ClipRectangle, grid);
1330 // Paint scrollBar corner
1331 if (grid.VScrollBar.Visible && grid.HScrollBar.Visible) {
1333 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.VScrollBar.Width,
1334 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.HScrollBar.Height,
1335 grid.VScrollBar.Width, grid.HScrollBar.Height);
1337 if (pe.ClipRectangle.IntersectsWith (corner)) {
1338 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1344 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
1346 Rectangle modified_area = clip;
1347 modified_area.Intersect (grid.caption_area);
1349 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
1352 Rectangle text_rect = grid.caption_area;
1353 text_rect.Y += text_rect.Height / 2 - grid.CaptionFont.Height / 2;
1354 text_rect.Height = grid.CaptionFont.Height;
1356 g.DrawString (grid.CaptionText, grid.CaptionFont,
1357 ResPool.GetSolidBrush (grid.CaptionForeColor),
1360 if (modified_area.IntersectsWith (grid.back_button_rect)) {
1361 g.DrawImage (grid.back_button_image, grid.back_button_rect);
1362 if (grid.back_button_mouseover) {
1363 CPDrawBorder3D (g, grid.back_button_rect, grid.back_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1366 if (modified_area.IntersectsWith (grid.parent_rows_button_rect)) {
1367 g.DrawImage (grid.parent_rows_button_image, grid.parent_rows_button_rect);
1368 if (grid.parent_rows_button_mouseover) {
1369 CPDrawBorder3D (g, grid.parent_rows_button_rect, grid.parent_rows_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
1374 public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
1376 Rectangle columns_area = grid.columnhdrs_area;
1378 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
1379 Rectangle rect_bloc = grid.columnhdrs_area;
1380 rect_bloc.Width = grid.RowHeaderWidth;
1381 if (clip.IntersectsWith (rect_bloc)) {
1382 if (grid.VisibleColumnCount > 0)
1383 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
1385 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
1388 columns_area.X += grid.RowHeaderWidth;
1389 columns_area.Width -= grid.RowHeaderWidth;
1393 Rectangle columnhdrs_area_complete = columns_area;
1394 columnhdrs_area_complete.Width = grid.columnhdrs_maxwidth;
1396 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1397 columnhdrs_area_complete.Width -= grid.RowHeaderWidth;
1400 // Set column painting
1401 Rectangle rect_columnhdr = new Rectangle ();
1403 Region current_clip;
1404 Region prev_clip = g.Clip;
1405 rect_columnhdr.Y = columns_area.Y;
1406 rect_columnhdr.Height = columns_area.Height;
1408 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1409 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1410 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
1413 col_pixel = grid.GetColumnStartingPixel (column);
1414 rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
1415 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1417 if (clip.IntersectsWith (rect_columnhdr) == false)
1420 current_clip = new Region (rect_columnhdr);
1421 current_clip.Intersect (columns_area);
1422 current_clip.Intersect (prev_clip);
1423 g.Clip = current_clip;
1425 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
1427 current_clip.Dispose ();
1432 Rectangle not_usedarea = columnhdrs_area_complete;
1433 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
1434 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
1435 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1439 public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
1441 Rectangle rect_row = new Rectangle ();
1443 rect_row.X = grid.ParentRowsArea.X;
1444 rect_row.Width = grid.ParentRowsArea.Width;
1445 rect_row.Height = (grid.CaptionFont.Height + 3);
1447 object[] parentRows = grid.dataSourceStack.ToArray();
1449 Region current_clip;
1450 Region prev_clip = g.Clip;
1451 for (int row = 0; row < parentRows.Length; row++) {
1452 rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
1454 if (clip.IntersectsWith (rect_row) == false)
1457 current_clip = new Region (rect_row);
1458 current_clip.Intersect (prev_clip);
1459 g.Clip = current_clip;
1461 DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);
1463 current_clip.Dispose ();
1469 public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
1471 //Console.WriteLine ("drawing parent row {0}", row);
1474 g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1477 Font bold_font = new Font (grid.Font.FontFamily, grid.Font.Size, grid.Font.Style | FontStyle.Bold);
1478 // set up some standard string formating variables
1479 StringFormat text_format = new StringFormat();
1480 text_format.LineAlignment = StringAlignment.Center;
1481 text_format.Alignment = StringAlignment.Near;
1483 string table_name = "";
1484 if (row.view is DataRowView)
1485 table_name = ((ITypedList)((DataRowView)row.view).DataView).GetListName (null) + ": ";
1488 Rectangle text_rect;
1491 text_size = g.MeasureString (table_name, bold_font).ToSize();
1492 text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
1494 //Console.WriteLine ("drawing text at {0}", text_rect);
1496 g.DrawString (table_name,
1497 bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1499 foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)row.view).GetProperties()) {
1500 if (typeof(IBindingList).IsAssignableFrom (pd.PropertyType))
1503 text_rect.X += text_rect.Size.Width + 5;
1505 string text = String.Format ("{0}: {1}",
1507 pd.GetValue (row.view));
1509 text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
1510 text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
1512 //Console.WriteLine ("drawing text at {0}", text_rect);
1515 grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1518 if (grid.FlatMode == false) {
1521 g.DrawLine (ResPool.GetPen (ColorControlLight),
1522 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1524 g.DrawLine (ResPool.GetPen (ColorControlLight),
1525 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1527 g.DrawLine (ResPool.GetPen (ColorControlDark),
1528 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1530 g.DrawLine (ResPool.GetPen (ColorControlDark),
1531 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1535 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1537 Point[] arrow = new Point[3];
1539 int centerX, centerY, shiftX;
1542 rect = new Rectangle (bounds.X + bounds.Width /4,
1543 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1545 centerX = rect.Left + rect.Width / 2;
1546 centerY = rect.Top + rect.Height / 2;
1547 shiftX = Math.Max (1, rect.Width / 8);
1550 P1 = new Point (centerX, rect.Top - 1);
1551 P2 = new Point (centerX, rect.Bottom);
1552 P3 = new Point (rect.Right, centerY);
1557 g.FillPolygon (ResPool.GetSolidBrush
1558 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1561 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
1563 bool is_add_row = grid.ShowEditRow && row == grid.DataGridRows.Length - 1;
1564 bool is_current_row = row == grid.CurrentCell.RowNumber;
1567 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
1571 if (is_current_row) {
1572 if (grid.IsChanging) {
1573 g.DrawString ("...", grid.Font,
1574 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1577 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1578 DataGridPaintRowHeaderArrow (g, rect, grid);
1581 else if (is_add_row) {
1582 g.DrawString ("*", grid.Font, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1586 if (grid.FlatMode == false && !is_add_row) {
1588 g.DrawLine (ResPool.GetPen (ColorControlLight),
1589 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1591 g.DrawLine (ResPool.GetPen (ColorControlLight),
1592 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1594 g.DrawLine (ResPool.GetPen (ColorControlDark),
1595 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1597 g.DrawLine (ResPool.GetPen (ColorControlDark),
1598 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1602 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1604 Rectangle rect_row = new Rectangle ();
1605 Rectangle not_usedarea = new Rectangle ();
1607 int rowcnt = grid.VisibleRowCount;
1609 bool showing_add_row = false;
1611 if (grid.RowsCount < grid.DataGridRows.Length) {
1612 /* the table has an add row */
1614 if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.DataGridRows.Length) {
1615 showing_add_row = true;
1619 rect_row.Width = cells.Width + grid.RowHeadersArea.Width;
1620 for (int r = 0; r < rowcnt; r++) {
1621 int row = grid.FirstVisibleRow + r;
1622 if (row == grid.DataGridRows.Length - 1)
1623 rect_row.Height = grid.DataGridRows[row].Height;
1625 rect_row.Height = grid.DataGridRows[row + 1].VerticalOffset - grid.DataGridRows[row].VerticalOffset;
1626 rect_row.Y = cells.Y + grid.DataGridRows[row].VerticalOffset - grid.DataGridRows[grid.FirstVisibleRow].VerticalOffset;
1627 if (clip.IntersectsWith (rect_row)) {
1628 if (grid.CurrentTableStyle.HasRelations
1629 && !(showing_add_row && row == grid.DataGridRows.Length - 1))
1630 DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
1632 DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.DataGridRows.Length - 1, clip, grid);
1637 // the rowcnt == 0 check is needed because
1638 // otherwise we'd draw over the caption on
1639 // empty datasources (since rect_row would be
1642 not_usedarea.Y = cells.Y;
1644 not_usedarea.Y = rect_row.Y + rect_row.Height;
1645 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1646 not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
1648 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1651 public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1652 Rectangle clip, DataGrid grid)
1654 Rectangle rect_header;
1655 Rectangle icon_bounds = new Rectangle ();
1656 Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor);
1658 /* paint the header if it's visible and intersects the clip */
1659 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1660 rect_header = row_rect;
1661 rect_header.Width = grid.RowHeaderWidth;
1662 row_rect.X += grid.RowHeaderWidth;
1663 if (clip.IntersectsWith (rect_header)) {
1664 DataGridPaintRowHeader (g, rect_header, row, grid);
1667 icon_bounds = rect_header;
1668 icon_bounds.X += icon_bounds.Width / 2;
1670 icon_bounds.Width = 8;
1671 icon_bounds.Height = 8;
1673 g.DrawRectangle (pen, icon_bounds);
1675 /* the - part of the icon */
1677 icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2,
1678 icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2);
1680 if (!grid.IsExpanded (row)) {
1681 /* the | part of the icon */
1683 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2,
1684 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2);
1688 Rectangle nested_rect = row_rect;
1690 if (grid.DataGridRows[row].IsExpanded)
1691 nested_rect.Height -= grid.DataGridRows[row].RelationHeight;
1693 DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
1695 if (grid.DataGridRows[row].IsExpanded) {
1696 // XXX we should create this in the
1697 // datagrid and cache it for use by
1698 // the theme instead of doing it each
1699 // time through here
1700 string[] relations = grid.CurrentTableStyle.Relations;
1701 StringBuilder relation_builder = new StringBuilder ("");
1703 for (int i = 0; i < relations.Length; i ++) {
1705 relation_builder.Append ("\n");
1707 relation_builder.Append (relations[i]);
1709 string relation_text = relation_builder.ToString ();
1711 StringFormat string_format = new StringFormat ();
1712 string_format.FormatFlags |= StringFormatFlags.NoWrap;
1715 //Region prev_clip = g.Clip;
1716 //Region current_clip;
1717 Rectangle rect_cell = row_rect;
1719 rect_cell.X = nested_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
1720 rect_cell.Y += nested_rect.Height;
1721 rect_cell.Height = grid.DataGridRows[row].RelationHeight;
1723 rect_cell.Width = 0;
1724 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1725 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1726 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
1728 rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width;
1730 rect_cell.Width = Math.Max (rect_cell.Width, grid.DataGridRows[row].relation_area.Width);
1732 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
1736 /* draw the line leading from the +/- to the relation area */
1737 Rectangle outline = grid.DataGridRows[row].relation_area;
1738 outline.Y = rect_cell.Y;
1742 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
1743 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2);
1746 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
1747 outline.X, outline.Y + outline.Height / 2);
1749 g.DrawRectangle (pen, outline);
1751 g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor),
1752 outline, string_format);
1754 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1755 Rectangle not_usedarea = new Rectangle ();
1756 not_usedarea.X = rect_cell.X + rect_cell.Width;
1757 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1758 not_usedarea.Y = row_rect.Y;
1759 not_usedarea.Height = row_rect.Height;
1760 if (clip.IntersectsWith (not_usedarea))
1761 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1767 public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1768 Rectangle clip, DataGrid grid)
1770 Rectangle rect_cell = new Rectangle ();
1772 Color backcolor, forecolor;
1773 Brush backBrush, foreBrush;
1774 Rectangle not_usedarea = Rectangle.Empty;
1776 rect_cell.Y = row_rect.Y;
1777 rect_cell.Height = row_rect.Height;
1779 if (grid.IsSelected (row)) {
1780 backcolor = grid.SelectionBackColor;
1781 forecolor = grid.SelectionForeColor;
1784 backcolor = grid.BackColor;
1786 backcolor = grid.AlternatingBackColor;
1789 forecolor = grid.ForeColor;
1793 backBrush = ResPool.GetSolidBrush (backcolor);
1794 foreBrush = ResPool.GetSolidBrush (forecolor);
1796 // PaintCells at row, column
1797 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1799 if (column_cnt > 0) {
1800 Region prev_clip = g.Clip;
1801 Region current_clip;
1803 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1804 if (grid.CurrentTableStyle.GridColumnStyles[column].bound == false)
1807 col_pixel = grid.GetColumnStartingPixel (column);
1809 rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
1810 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1812 if (clip.IntersectsWith (rect_cell)) {
1813 current_clip = new Region (rect_cell);
1814 current_clip.Intersect (row_rect);
1815 current_clip.Intersect (prev_clip);
1816 g.Clip = current_clip;
1819 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1823 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1826 grid.RightToLeft == RightToLeft.Yes);
1829 current_clip.Dispose ();
1835 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1836 not_usedarea.X = rect_cell.X + rect_cell.Width;
1837 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1838 not_usedarea.Y = row_rect.Y;
1839 not_usedarea.Height = row_rect.Height;
1843 not_usedarea = row_rect;
1846 if (!not_usedarea.IsEmpty && clip.IntersectsWith (not_usedarea))
1847 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1851 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1852 Rectangle clip, DataGrid grid)
1854 /* paint the header if it's visible and intersects the clip */
1855 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1856 Rectangle rect_header = row_rect;
1857 rect_header.Width = grid.RowHeaderWidth;
1858 row_rect.X += grid.RowHeaderWidth;
1859 if (clip.IntersectsWith (rect_header)) {
1860 DataGridPaintRowHeader (g, rect_header, row, grid);
1864 DataGridPaintRowContents (g, row, row_rect, is_newrow, clip, grid);
1867 #endregion // Datagrid
1869 #region DateTimePicker
1871 public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp)
1874 if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle))
1877 // draw the outer border
1878 Rectangle button_bounds = dtp.ClientRectangle;
1879 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1881 // deflate by the border width
1882 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1883 button_bounds.Inflate (-2,-2);
1884 if (!dtp.ShowUpDown) {
1885 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1886 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), dtp.drop_down_arrow_rect);
1887 this.CPDrawComboButton (
1889 dtp.drop_down_arrow_rect,
1892 ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal;
1893 ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal;
1894 Rectangle up_bounds = dtp.drop_down_arrow_rect;
1895 Rectangle down_bounds = dtp.drop_down_arrow_rect;
1897 up_bounds.Height = up_bounds.Height / 2;
1898 down_bounds.Y = up_bounds.Height;
1899 down_bounds.Height = dtp.Height - up_bounds.Height;
1900 if (down_bounds.Height > up_bounds.Height)
1903 down_bounds.Height -= 1;
1906 up_bounds.Inflate (-1, -1);
1907 down_bounds.Inflate (-1, -1);
1909 ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state);
1910 ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state);
1914 // render the date part
1915 if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
1918 // fill the background
1919 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
1921 // Update date_area_rect if we are drawing the checkbox
1922 Rectangle date_area_rect = dtp.date_area_rect;
1923 if (dtp.ShowCheckBox) {
1924 Rectangle check_box_rect = dtp.CheckBoxRect;
1925 date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
1926 date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;
1928 ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
1929 CPDrawCheckBox(dc, check_box_rect, bs);
1931 if (dtp.is_checkbox_selected)
1932 CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
1935 // render each text part
1936 using (StringFormat text_format = StringFormat.GenericTypographic)
1938 text_format.LineAlignment = StringAlignment.Near;
1939 text_format.Alignment = StringAlignment.Near;
1940 text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
1941 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
1943 // Calculate the rectangles for each part
1944 if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
1947 for (int i = 0; i < dtp.part_data.Length; i++)
1949 DateTimePicker.PartData fd = dtp.part_data[i];
1950 RectangleF text_rect = new RectangleF();
1951 string text = fd.GetText(dtp.Value);
1952 text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
1954 text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);
1957 text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
1959 text_rect.X = date_area_rect.X;
1962 text_rect.Inflate (1, 0);
1963 fd.drawing_rectangle = text_rect;
1967 // draw the text part
1968 Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ?
1969 SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false
1970 RectangleF clip_rectangleF = clip_rectangle;
1972 for (int i = 0; i < dtp.part_data.Length; i++)
1974 DateTimePicker.PartData fd = dtp.part_data [i];
1977 if (!clip_rectangleF.IntersectsWith (fd.drawing_rectangle))
1980 text = fd.GetText (dtp.Value);
1982 PointF text_position = new PointF ();
1984 RectangleF text_rect;
1986 text_size = dc.MeasureString (text, dtp.Font, 250, text_format);
1987 text_position.X = (fd.drawing_rectangle.Left + fd.drawing_rectangle.Width / 2) - text_size.Width / 2;
1988 text_position.Y = (fd.drawing_rectangle.Top + fd.drawing_rectangle.Height / 2) - text_size.Height / 2;
1989 text_rect = new RectangleF (text_position, text_size);
1990 text_rect = RectangleF.Intersect (text_rect, date_area_rect);
1992 if (text_rect.IsEmpty)
1995 if (text_rect.Right >= date_area_rect.Right)
1996 text_format.FormatFlags &= ~StringFormatFlags.NoClip;
1998 text_format.FormatFlags |= StringFormatFlags.NoClip;
2000 if (fd.is_selected) {
2001 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
2002 dc.DrawString (text, dtp.Font, SystemBrushes.HighlightText, text_rect, text_format);
2005 dc.DrawString (text, dtp.Font, text_brush, text_rect, text_format);
2008 if (fd.drawing_rectangle.Right > date_area_rect.Right)
2009 break; // the next part would be not be visible, so don't draw anything more.
2014 #endregion // DateTimePicker
2017 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
2018 StringFormat text_format;
2023 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
2025 text_format = new StringFormat();
2026 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2028 size = dc.MeasureString (box.Text, box.Font);
2031 if (size.Width > 0) {
2032 width = ((int) size.Width) + 7;
2034 if (width > box.Width - 16)
2035 width = box.Width - 16;
2038 y = box.Font.Height / 2;
2040 // Clip the are that the text will be in
2041 Region prev_clip = dc.Clip;
2042 dc.SetClip (new Rectangle (10, 0, width, box.Font.Height), CombineMode.Exclude);
2044 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
2045 dc.Clip = prev_clip;
2048 if (box.Text.Length != 0) {
2050 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
2052 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
2053 new RectangleF (10, 0, width, box.Font.Height), text_format);
2057 text_format.Dispose ();
2060 public override Size GroupBoxDefaultSize {
2062 return new Size (200,100);
2068 public override Size HScrollBarDefaultSize {
2070 return new Size (80, this.ScrollBarButtonSize);
2074 #endregion // HScrollBar
2077 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
2079 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
2081 if (label.Enabled) {
2082 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
2084 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
2089 public override Size LabelDefaultSize {
2091 return new Size (100, 23);
2097 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
2099 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
2101 if (label.pieces == null)
2104 for (int i = 0; i < label.pieces.Length; i ++) {
2106 Rectangle rect = Rectangle.Round (label.pieces[i].region.GetBounds (dc));
2108 if (!clip_rectangle.IntersectsWith (rect))
2111 LinkLabel.Link link = label.pieces[i].link;
2112 if (link != null && link.Focused)
2113 CPDrawFocusRectangle (dc, rect, label.ForeColor, label.BackColor);
2115 // To adjust diference between measurement and draw string.
2116 Rectangle rectf = label.factor;
2119 rect.Width += rectf.Width;
2120 rect.Height += rectf.Height;
2122 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.GetPieceColor (label.pieces[i], i)),
2123 rect, label.string_format);
2127 #endregion // LinkLabel
2130 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
2132 Color back_color, fore_color;
2134 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
2135 back_color = ColorHighlight;
2136 fore_color = ColorHighlightText;
2138 back_color = e.BackColor;
2139 fore_color = e.ForeColor;
2142 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
2144 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
2145 ResPool.GetSolidBrush (fore_color),
2146 e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
2148 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
2149 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
2156 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
2158 bool details = control.View == View.Details;
2160 if (control.Enabled)
2161 dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);
2163 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip);
2165 int first = control.FirstVisibleIndex;
2167 for (int i = first; i <= control.LastVisibleIndex; i ++) {
2168 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
2169 DrawListViewItem (dc, control, control.Items [i]);
2172 // draw the gridlines
2173 if (details && control.GridLines) {
2174 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
2175 2 : control.Font.Height + 2;
2177 // draw vertical gridlines
2178 foreach (ColumnHeader col in control.Columns)
2179 dc.DrawLine (SystemPens.Control,
2180 col.Rect.Right, top,
2181 col.Rect.Right, control.TotalHeight);
2182 // draw horizontal gridlines
2183 ListViewItem last_item = null;
2184 foreach (ListViewItem item in control.Items) {
2185 dc.DrawLine (SystemPens.Control,
2186 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
2187 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
2191 // draw a line after at the bottom of the last item
2192 if (last_item != null) {
2193 dc.DrawLine (SystemPens.Control,
2194 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
2195 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
2197 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
2201 // Draw corner between the two scrollbars
2202 if (control.h_scroll.Visible == true && control.v_scroll.Visible == true) {
2203 Rectangle rect = new Rectangle ();
2204 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
2205 rect.Width = control.v_scroll.Width;
2206 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
2207 rect.Height = control.h_scroll.Height;
2208 dc.FillRectangle (SystemBrushes.Control, rect);
2211 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
2212 if (!box_select_rect.Size.IsEmpty)
2213 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
2217 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
2219 bool details = (control.View == View.Details);
2221 // border is drawn directly in the Paint method
2222 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
2223 dc.FillRectangle (GetControlBackBrush (control.BackColor),
2224 0, 0, control.TotalWidth, control.Font.Height + 5);
2225 if (control.Columns.Count > 0) {
2226 foreach (ColumnHeader col in control.Columns) {
2227 Rectangle rect = col.Rect;
2228 rect.X -= control.h_marker;
2230 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
2231 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
2233 state = ButtonState.Flat;
2234 this.CPDrawButton (dc, rect, state);
2237 if (rect.Width <= 0)
2240 dc.DrawString (col.Text, DefaultFont,
2241 SystemBrushes.ControlText,
2244 int right = control.GetReorderedColumn (control.Columns.Count - 1).Rect.Right - control.h_marker;
2245 if (right < control.Right) {
2246 Rectangle rect = control.Columns [0].Rect;
2248 rect.Width = control.Right - right;
2250 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
2251 state = ButtonState.Normal;
2253 state = ButtonState.Flat;
2254 CPDrawButton (dc, rect, state);
2260 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
2262 Rectangle rect = col.Rect;
2263 rect.X -= view.h_marker;
2264 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
2265 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
2268 if (rect.Width <= 0)
2270 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
2271 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
2272 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
2275 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
2278 if (control.View == View.Details && control.Columns.Count > 0)
2279 col_offset = control.Columns [0].Rect.X;
2283 Rectangle rect_checkrect = item.CheckRectReal;
2284 rect_checkrect.X += col_offset;
2285 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
2286 icon_rect.X += col_offset;
2287 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
2288 full_rect.X += col_offset;
2289 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
2290 text_rect.X += col_offset;
2293 // Tile view doesn't support CheckBoxes
2294 if (control.CheckBoxes && control.View != View.Tile) {
2296 if (control.CheckBoxes) {
2298 if (control.StateImageList == null) {
2299 // Make sure we've got at least a line width of 1
2300 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
2301 int scale = Math.Max (1, rect_checkrect.Width / 12);
2303 // set the checkbox background
2304 dc.FillRectangle (SystemBrushes.Window,
2306 // define a rectangle inside the border area
2307 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
2308 rect_checkrect.Y + 2,
2309 rect_checkrect.Width - 4,
2310 rect_checkrect.Height - 4);
2311 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
2312 dc.DrawRectangle (pen, rect);
2314 // Need to draw a check-mark
2316 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
2317 // adjustments to get the check-mark at the right place
2318 rect.X ++; rect.Y ++;
2319 // following logic is taken from DrawFrameControl method
2320 for (int i = 0; i < check_wd; i++) {
2321 dc.DrawLine (check_pen, rect.Left + check_wd / 2,
2322 rect.Top + check_wd + i,
2323 rect.Left + check_wd / 2 + 2 * scale,
2324 rect.Top + check_wd + 2 * scale + i);
2325 dc.DrawLine (check_pen,
2326 rect.Left + check_wd / 2 + 2 * scale,
2327 rect.Top + check_wd + 2 * scale + i,
2328 rect.Left + check_wd / 2 + 6 * scale,
2329 rect.Top + check_wd - 2 * scale + i);
2334 if (item.Checked && control.StateImageList.Images.Count > 1)
2335 control.StateImageList.Draw (dc,
2336 rect_checkrect.Location, 1);
2337 else if (! item.Checked && control.StateImageList.Images.Count > 0)
2338 control.StateImageList.Draw (dc,
2339 rect_checkrect.Location, 0);
2343 ImageList image_list = control.View == View.LargeIcon
2345 || control.View == View.Tile
2347 ? control.LargeImageList : control.SmallImageList;
2348 if (image_list != null) {
2352 if (item.ImageKey != String.Empty)
2353 idx = image_list.Images.IndexOfKey (item.ImageKey);
2356 idx = item.ImageIndex;
2358 if (idx > -1 && idx < image_list.Images.Count)
2359 image_list.Draw (dc, icon_rect.Location, idx);
2362 // draw the item text
2363 // format for the item text
2364 StringFormat format = new StringFormat ();
2365 if (control.View == View.SmallIcon)
2366 format.LineAlignment = StringAlignment.Near;
2368 format.LineAlignment = StringAlignment.Center;
2369 if (control.View == View.LargeIcon)
2370 format.Alignment = StringAlignment.Center;
2372 format.Alignment = StringAlignment.Near;
2374 if (control.LabelWrap)
2375 format.FormatFlags = StringFormatFlags.LineLimit;
2377 format.FormatFlags = StringFormatFlags.NoWrap;
2379 Rectangle highlight_rect = text_rect;
2380 if (control.View == View.Details) { // Adjustments for Details view
2381 Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
2383 if (!control.FullRowSelect) // Selection shouldn't be outside the item bounds
2384 highlight_rect.Width = Math.Min (text_size.Width + 4, text_rect.Width);
2386 if (text_size.Width > text_rect.Width)
2387 format.Trimming = StringTrimming.EllipsisCharacter;
2390 if (item.Selected && control.Focused)
2391 dc.FillRectangle (SystemBrushes.Highlight, highlight_rect);
2392 else if (item.Selected && !control.HideSelection)
2393 dc.FillRectangle (SystemBrushes.Control, highlight_rect);
2395 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
2398 !control.Enabled ? SystemBrushes.ControlLight :
2399 (item.Selected && control.Focused) ? SystemBrushes.HighlightText :
2400 this.ResPool.GetSolidBrush (item.ForeColor);
2403 // Tile view renders its Text in a different fashion
2404 if (control.View == View.Tile) {
2405 // Item.Text is drawn using its first subitem's bounds
2406 dc.DrawString (item.Text, item.Font, textBrush, item.SubItems [0].Bounds, format);
2408 int count = Math.Min (control.Columns.Count, item.SubItems.Count);
2409 for (int i = 1; i < count; i++) {
2410 ListViewItem.ListViewSubItem sub_item = item.SubItems [i];
2411 if (sub_item.Text == null || sub_item.Text.Length == 0)
2414 Brush itemBrush = item.Selected && control.Focused ?
2415 SystemBrushes.HighlightText : GetControlForeBrush (sub_item.ForeColor);
2416 dc.DrawString (sub_item.Text, sub_item.Font, itemBrush, sub_item.Bounds, format);
2421 if (item.Text != null && item.Text.Length > 0) {
2422 if (item.Selected && control.Focused)
2423 dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format);
2425 dc.DrawString (item.Text, item.Font, textBrush, text_rect, format);
2428 if (control.View == View.Details && control.Columns.Count > 0) {
2429 // draw subitems for details view
2430 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
2431 int count = (control.Columns.Count < subItems.Count ?
2432 control.Columns.Count : subItems.Count);
2436 ListViewItem.ListViewSubItem subItem;
2437 Rectangle sub_item_rect = text_rect;
2439 // set the format for subitems
2440 format.FormatFlags = StringFormatFlags.NoWrap;
2442 // 0th subitem is the item already drawn
2443 for (int index = 1; index < count; index++) {
2444 subItem = subItems [index];
2445 col = control.Columns [index];
2446 format.Alignment = col.Format.Alignment;
2447 sub_item_rect.X = col.Rect.X - control.h_marker;
2448 sub_item_rect.Width = col.Wd;
2449 Rectangle sub_item_text_rect = sub_item_rect;
2450 sub_item_text_rect.X += 3;
2451 sub_item_text_rect.Width -= 6;
2453 SolidBrush sub_item_back_br = null;
2454 SolidBrush sub_item_fore_br = null;
2455 Font sub_item_font = null;
2457 if (item.UseItemStyleForSubItems) {
2458 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
2459 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
2460 sub_item_font = item.Font;
2462 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
2463 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
2464 sub_item_font = subItem.Font;
2467 int sub_item_text_width = (int) Math.Ceiling (control.DeviceContext.MeasureString (subItem.Text,
2468 sub_item_font).Width);
2470 format.Trimming = sub_item_text_width > sub_item_text_rect.Width ? StringTrimming.EllipsisCharacter :
2471 StringTrimming.None;
2473 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
2475 if (control.Focused) {
2476 bg = SystemBrushes.Highlight;
2477 text = SystemBrushes.HighlightText;
2479 bg = SystemBrushes.Control;
2480 text = sub_item_fore_br;
2483 dc.FillRectangle (bg, sub_item_rect);
2484 if (subItem.Text != null && subItem.Text.Length > 0)
2485 dc.DrawString (subItem.Text, sub_item_font,
2486 text, sub_item_text_rect, format);
2488 dc.FillRectangle (sub_item_back_br, sub_item_rect);
2489 if (subItem.Text != null && subItem.Text.Length > 0)
2490 dc.DrawString (subItem.Text, sub_item_font,
2492 sub_item_text_rect, format);
2496 // Fill in selection for remaining columns if Column.Count > SubItems.Count
2497 if (item.Selected && (control.Focused || !control.HideSelection) && control.FullRowSelect) {
2498 for (int index = count; index < control.Columns.Count; index++)
2500 col = control.Columns [index];
2501 sub_item_rect.X = col.Rect.X - control.h_marker;
2502 sub_item_rect.Width = col.Wd;
2503 if (control.Focused)
2504 dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
2506 dc.FillRectangle (SystemBrushes.Control, sub_item_rect);
2512 if (item.Focused && control.Focused) {
2513 Rectangle focus_rect = highlight_rect;
2514 if (control.FullRowSelect && control.View == View.Details) {
2516 foreach (ColumnHeader col in control.Columns)
2518 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
2521 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
2523 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
2530 public override Size ListViewCheckBoxSize {
2531 get { return new Size (16, 16); }
2534 public override int ListViewColumnHeaderHeight {
2538 public override int ListViewDefaultColumnWidth {
2542 public override int ListViewVerticalSpacing {
2546 public override int ListViewEmptyColumnWidth {
2550 public override int ListViewHorizontalSpacing {
2554 public override Size ListViewDefaultSize {
2555 get { return new Size (121, 97); }
2558 public override int ListViewGroupHeight {
2562 public override int ListViewTileWidthFactor {
2566 public override int ListViewTileHeightFactor {
2569 #endregion // ListView
2573 public override bool MenuAccessKeysUnderlined {
2574 get { return false; }
2577 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
2582 if (item.Visible == false) {
2588 if (item.Separator == true) {
2589 item.Height = SEPARATOR_HEIGHT;
2590 item.Width = SEPARATOR_MIN_WIDTH;
2594 if (item.MeasureEventDefined) {
2595 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
2596 item.PerformMeasureItem (mi);
2597 item.Height = mi.ItemHeight;
2598 item.Width = mi.ItemWidth;
2602 size = dc.MeasureString (item.Text, MenuFont);
2603 item.Width = (int) size.Width;
2604 item.Height = (int) size.Height;
2607 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
2608 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
2609 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
2610 item.Width += MENU_TAB_SPACE + (int) size.Width;
2613 item.Width += 4 + (MenuCheckSize.Width * 2);
2615 item.Width += MENU_BAR_ITEMS_SPACE;
2619 if (item.Height < MenuHeight)
2620 item.Height = MenuHeight;
2624 // Updates the menu rect and returns the height
2625 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
2631 foreach (MenuItem item in menu.MenuItems) {
2633 CalcItemSize (dc, item, y, x, true);
2635 if (x + item.Width > width) {
2643 item.MenuBar = true;
2645 if (y + item.Height > menu.Height)
2646 menu.Height = item.Height + y;
2653 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
2661 while (start < menu.MenuItems.Count) {
2664 for (i = start; i < menu.MenuItems.Count; i++) {
2665 MenuItem item = menu.MenuItems [i];
2667 if ((i != start) && (item.Break || item.BarBreak))
2670 CalcItemSize (dc, item, y, x, false);
2673 if (item.Width > max)
2677 // Replace the -1 by the menu width (separators)
2678 for (n = start; n < i; n++, start++)
2679 menu.MenuItems [n].Width = max;
2681 if (y > menu.Height)
2693 menu.Width += SM_CXBORDER;
2694 menu.Height += SM_CYBORDER;
2697 // Draws a menu bar in a window
2698 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
2700 if (menu.Height == 0)
2701 CalcMenuBarSize (dc, menu, rect.Width);
2703 bool keynav = (menu as MainMenu).tracker.hotkey_active;
2704 HotkeyPrefix hp = MenuAccessKeysUnderlined || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
2705 string_format_menu_menubar_text.HotkeyPrefix = hp;
2706 string_format_menu_text.HotkeyPrefix = hp;
2708 rect.Height = menu.Height;
2709 dc.FillRectangle (SystemBrushes.Menu, rect);
2711 for (int i = 0; i < menu.MenuItems.Count; i++) {
2712 MenuItem item = menu.MenuItems [i];
2713 Rectangle item_rect = item.bounds;
2714 item_rect.X += rect.X;
2715 item_rect.Y += rect.Y;
2716 item.MenuHeight = menu.Height;
2717 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
2721 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
2724 if (color.R == 0 && color.G == 0 && color.B == 0)
2725 bg_color = Color.White;
2727 bg_color = Color.Black;
2729 Bitmap bmp = new Bitmap (size.Width, size.Height);
2730 Graphics gr = Graphics.FromImage (bmp);
2731 Rectangle rect = new Rectangle (Point.Empty, size);
2732 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
2733 CPDrawMenuGlyph (gr, rect, glyph, color);
2734 bmp.MakeTransparent (bg_color);
2740 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
2742 StringFormat string_format;
2743 Rectangle rect_text = e.Bounds;
2745 if (item.Visible == false)
2749 string_format = string_format_menu_menubar_text;
2751 string_format = string_format_menu_text;
2753 if (item.Separator == true) {
2754 int liney = e.Bounds.Y + (e.Bounds.Height / 2);
2756 e.Graphics.DrawLine (SystemPens.ControlDark,
2757 e.Bounds.X, liney, e.Bounds.X + e.Bounds.Width, liney);
2759 e.Graphics.DrawLine (SystemPens.ControlLight,
2760 e.Bounds.X, liney + 1, e.Bounds.X + e.Bounds.Width, liney + 1);
2766 rect_text.X += MenuCheckSize.Width;
2768 if (item.BarBreak) { /* Draw vertical break bar*/
2769 Rectangle rect = e.Bounds;
2772 rect.Height = item.MenuHeight - 6;
2774 e.Graphics.DrawLine (SystemPens.ControlDark,
2775 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
2777 e.Graphics.DrawLine (SystemPens.ControlLight,
2778 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
2783 Brush brush_text = null;
2784 Brush brush_back = null;
2786 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
2787 color_text = ColorHighlightText;
2788 color_back = ColorHighlight;
2789 brush_text = SystemBrushes.HighlightText;
2790 brush_back = SystemBrushes.Highlight;
2792 color_text = ColorMenuText;
2793 color_back = ColorMenu;
2794 brush_text = ResPool.GetSolidBrush (ColorMenuText);
2795 brush_back = SystemBrushes.Menu;
2798 /* Draw background */
2800 e.Graphics.FillRectangle (brush_back, e.Bounds);
2803 e.Graphics.DrawString (item.Text, e.Font,
2805 rect_text, string_format);
2807 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
2808 string str = item.GetShortCutText ();
2809 Rectangle rect = rect_text;
2811 rect.Width -= item.XTab;
2813 e.Graphics.DrawString (str, e.Font, brush_text,
2814 rect, string_format_menu_shortcut);
2818 Border3DStyle border_style = Border3DStyle.Adjust;
2819 if ((item.Status & DrawItemState.HotLight) != 0)
2820 border_style = Border3DStyle.RaisedInner;
2821 else if ((item.Status & DrawItemState.Selected) != 0)
2822 border_style = Border3DStyle.SunkenOuter;
2824 if (border_style != Border3DStyle.Adjust)
2825 CPDrawBorder3D(e.Graphics, e.Bounds, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
2828 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
2829 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
2830 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
2834 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
2838 if (item.MenuBar == false && (item.IsPopup || item.MdiList)) {
2840 int cx = MenuCheckSize.Width;
2841 int cy = MenuCheckSize.Height;
2842 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
2845 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
2846 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
2848 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
2849 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
2855 /* Draw checked or radio */
2856 if (item.MenuBar == false && item.Checked) {
2858 Rectangle area = e.Bounds;
2859 int cx = MenuCheckSize.Width;
2860 int cy = MenuCheckSize.Height;
2861 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
2863 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
2869 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
2871 // Fill rectangle area
2872 dc.FillRectangle (SystemBrushes.Menu, cliparea);
2874 // Draw menu borders
2875 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
2878 for (int i = 0; i < menu.MenuItems.Count; i++) {
2879 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
2880 MenuItem item = menu.MenuItems [i];
2881 item.MenuHeight = menu.Height;
2882 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item.bounds, i, item.Status));
2889 #region MonthCalendar
2891 // draw the month calendar
2892 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2894 Rectangle client_rectangle = mc.ClientRectangle;
2895 Size month_size = mc.SingleMonthSize;
2896 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2897 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2898 Size date_cell_size = (Size)((object)mc.date_cell_size);
2900 // draw the singlecalendars
2903 // adjust for the position of the specific month
2904 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2908 y_offset += month_size.Height + calendar_spacing.Height;
2910 // now adjust for x position
2911 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2915 x_offset += month_size.Width + calendar_spacing.Width;
2922 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2923 if (month_rect.IntersectsWith (clip_rectangle)) {
2935 Rectangle bottom_rect = new Rectangle (
2937 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2938 client_rectangle.Width,
2939 date_cell_size.Height + 2);
2940 // draw the today date if it's set
2941 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2943 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
2945 int today_offset = 5;
2946 if (mc.ShowTodayCircle)
2948 Rectangle today_circle_rect = new Rectangle (
2949 client_rectangle.X + 5,
2950 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2951 date_cell_size.Width,
2952 date_cell_size.Height);
2953 DrawTodayCircle (dc, today_circle_rect);
2954 today_offset += date_cell_size.Width + 5;
2956 // draw today's date
2957 StringFormat text_format = new StringFormat();
2958 text_format.LineAlignment = StringAlignment.Center;
2959 text_format.Alignment = StringAlignment.Near;
2960 Rectangle today_rect = new Rectangle (
2961 today_offset + client_rectangle.X,
2962 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2963 Math.Max(client_rectangle.Width - today_offset, 0),
2964 date_cell_size.Height);
2965 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), mc.bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
2966 text_format.Dispose ();
2970 // finally paint the borders of the calendars as required
2971 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2972 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2973 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
2974 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2975 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
2977 Rectangle rect = new Rectangle (
2978 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2980 calendar_spacing.Width,
2981 client_rectangle.Height);
2982 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2983 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2987 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2988 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2989 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
2990 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2991 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
2993 Rectangle rect = new Rectangle (
2995 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2996 client_rectangle.Width,
2997 calendar_spacing.Height);
2998 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2999 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
3004 // draw the drop down border if need
3005 if (mc.owner != null) {
3006 Rectangle bounds = mc.ClientRectangle;
3007 if (clip_rectangle.Contains (mc.Location)) {
3008 // find out if top or left line to draw
3009 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3011 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
3013 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3014 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
3017 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
3018 // find out if bottom or right line to draw
3019 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
3020 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
3022 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
3023 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
3029 // darws a single part of the month calendar (with one month)
3030 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
3032 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
3033 Size title_size = (Size)((object)mc.title_size);
3034 Size date_cell_size = (Size)((object)mc.date_cell_size);
3035 DateTime current_month = (DateTime)((object)mc.current_month);
3036 DateTime sunday = new DateTime(2006, 10, 1);
3038 // draw the title back ground
3039 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
3040 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
3041 if (title_rect.IntersectsWith (clip_rectangle)) {
3042 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
3044 string title_text = this_month.ToString ("MMMM yyyy");
3045 dc.DrawString (title_text, mc.bold_font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, mc.centered_format);
3047 if (mc.ShowYearUpDown) {
3048 Rectangle year_rect;
3049 Rectangle upRect, downRect;
3050 ButtonState upState, downState;
3052 mc.GetYearNameRectangles (title_rect, row * mc.CalendarDimensions.Width + col, out year_rect, out upRect, out downRect);
3053 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control), year_rect);
3054 dc.DrawString (this_month.ToString ("yyyy"), mc.bold_font, ResPool.GetSolidBrush (Color.Black), year_rect, mc.centered_format);
3056 upState = mc.IsYearGoingUp ? ButtonState.Pushed : ButtonState.Normal;
3057 downState = mc.IsYearGoingDown ? ButtonState.Pushed : ButtonState.Normal;
3059 ControlPaint.DrawScrollButton (dc, upRect, ScrollButton.Up, upState);
3060 ControlPaint.DrawScrollButton (dc, downRect, ScrollButton.Down, downState);
3063 // draw previous and next buttons if it's time
3064 if (row == 0 && col == 0)
3066 // draw previous button
3067 DrawMonthCalendarButton (
3073 (System.Drawing.Size)((object)mc.button_size),
3076 if (row == 0 && col == mc.CalendarDimensions.Width-1)
3079 DrawMonthCalendarButton (
3085 (System.Drawing.Size)((object)mc.button_size),
3090 // set the week offset and draw week nums if needed
3091 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
3092 Rectangle day_name_rect = new Rectangle(
3094 rectangle.Y + title_size.Height,
3095 (7 + col_offset) * date_cell_size.Width,
3096 date_cell_size.Height);
3097 if (day_name_rect.IntersectsWith (clip_rectangle)) {
3098 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
3099 // draw the day names
3100 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
3101 for (int i=0; i < 7; i++)
3103 int position = i - (int) first_day_of_week;
3106 position = 7 + position;
3109 Rectangle day_rect = new Rectangle(
3110 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
3112 date_cell_size.Width,
3113 date_cell_size.Height);
3114 dc.DrawString (sunday.AddDays (i + (int) first_day_of_week).ToString ("ddd"), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, mc.centered_format);
3117 // draw the vertical divider
3118 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
3120 ResPool.GetPen (mc.ForeColor),
3121 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
3122 rectangle.Y + vert_divider_y,
3123 rectangle.Right - mc.divider_line_offset,
3124 rectangle.Y + vert_divider_y);
3128 // draw the actual date items in the grid (including the week numbers)
3129 Rectangle date_rect = new Rectangle (
3131 rectangle.Y + title_size.Height + date_cell_size.Height,
3132 date_cell_size.Width,
3133 date_cell_size.Height);
3134 int month_row_count = 0;
3135 bool draw_week_num_divider = false;
3136 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
3137 for (int i=0; i < 6; i++)
3139 // establish if this row is in our clip_area
3140 Rectangle row_rect = new Rectangle (
3142 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
3143 date_cell_size.Width * 7,
3144 date_cell_size.Height);
3145 if (mc.ShowWeekNumbers) {
3146 row_rect.Width += date_cell_size.Width;
3149 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
3151 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
3153 // establish if this is a valid week to draw
3154 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
3155 month_row_count = i;
3158 // draw the week number if required
3159 if (mc.ShowWeekNumbers && month_row_count == i) {
3160 if (!draw_week_num_divider) {
3161 draw_week_num_divider = draw_row;
3163 // get the week for this row
3164 int week = mc.GetWeekOfYear (current_date);
3170 ResPool.GetSolidBrush (mc.TitleBackColor),
3172 mc.centered_format);
3174 date_rect.Offset(date_cell_size.Width, 0);
3177 // only draw the days if we have to
3178 if(month_row_count == i) {
3179 for (int j=0; j < 7; j++)
3182 DrawMonthCalendarDate (
3193 current_date = current_date.AddDays(1);
3194 date_rect.Offset(date_cell_size.Width, 0);
3197 // shift the rectangle down one row
3198 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
3199 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
3203 // month_row_count is zero based, so add one
3206 // draw week numbers if required
3207 if (draw_week_num_divider) {
3210 ResPool.GetPen (mc.ForeColor),
3211 rectangle.X + date_cell_size.Width - 1,
3212 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
3213 rectangle.X + date_cell_size.Width - 1,
3214 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
3218 // draws the pervious or next button
3219 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
3221 bool is_clicked = false;
3222 Rectangle button_rect;
3223 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
3224 Point[] arrow_path = new Point[3];
3225 // prepare the button
3228 is_clicked = mc.is_previous_clicked;
3229 button_rect = new Rectangle (
3230 rectangle.X + 1 + x_offset,
3231 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3232 Math.Max(button_size.Width - 1, 0),
3233 Math.Max(button_size.Height - 1, 0));
3234 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
3235 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
3237 arrow_rect.Offset(1,1);
3239 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
3240 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
3241 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
3245 is_clicked = mc.is_next_clicked;
3246 button_rect = new Rectangle (
3247 rectangle.Right - 1 - x_offset - button_size.Width,
3248 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
3249 Math.Max(button_size.Width - 1, 0),
3250 Math.Max(button_size.Height - 1, 0));
3251 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
3252 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
3254 arrow_rect.Offset(1,1);
3256 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
3257 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
3258 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
3261 // fill the background
3262 dc.FillRectangle (SystemBrushes.Control, button_rect);
3265 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
3268 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3271 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
3275 // draws one day in the calendar grid
3276 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
3277 Color date_color = mc.ForeColor;
3278 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
3280 // find out if we are the lead of the first calendar or the trail of the last calendar
3281 if (date.Year != month.Year || date.Month != month.Month) {
3282 DateTime check_date = month.AddMonths (-1);
3283 // check if it's the month before
3284 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
3285 date_color = mc.TrailingForeColor;
3287 // check if it's the month after
3288 check_date = month.AddMonths (1);
3289 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
3290 date_color = mc.TrailingForeColor;
3296 date_color = mc.ForeColor;
3299 const int inflate = -1;
3300 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
3301 // see if the date is in the start of selection
3302 date_color = mc.BackColor;
3303 // draw the left hand of the back ground
3304 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
3305 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 360);
3306 } else if (date == mc.SelectionStart) {
3307 // see if the date is in the start of selection
3308 date_color = mc.BackColor;
3309 // draw the left hand of the back ground
3310 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
3311 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
3312 // fill the other side as a straight rect
3313 if (date < mc.SelectionEnd)
3315 // use rectangle instead of rectangle to go all the way to edge of rect
3316 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
3317 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
3318 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3320 } else if (date == mc.SelectionEnd) {
3321 // see if it is the end of selection
3322 date_color = mc.BackColor;
3323 // draw the left hand of the back ground
3324 Rectangle selection_rect = Rectangle.Inflate (rectangle, inflate, inflate);
3325 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
3326 // fill the other side as a straight rect
3327 if (date > mc.SelectionStart) {
3328 selection_rect.X = rectangle.X;
3329 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
3330 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3332 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
3333 // now see if it's in the middle
3334 date_color = mc.BackColor;
3335 // draw the left hand of the back ground
3336 Rectangle selection_rect = Rectangle.Inflate (rectangle, 0, inflate);
3337 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3340 // establish if it's a bolded font
3341 Font font = mc.IsBoldedDate (date) ? mc.bold_font : mc.Font;
3343 // just draw the date now
3344 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, mc.centered_format);
3346 // today circle if needed
3347 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
3348 DrawTodayCircle (dc, interior);
3351 // draw the selection grid
3352 if (mc.is_date_clicked && mc.clicked_date == date) {
3353 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
3354 dc.DrawRectangle (pen, interior);
3358 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
3359 Color circle_color = Color.FromArgb (248, 0, 0);
3360 // draw the left hand of the circle
3361 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
3362 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
3363 Point [] curve_points = new Point [3];
3364 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
3365 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
3366 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
3368 Pen pen = ResPool.GetSizedPen(circle_color, 2);
3369 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
3370 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
3371 dc.DrawCurve (pen, curve_points);
3372 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
3375 #endregion // MonthCalendar
3378 public override Size PanelDefaultSize {
3380 return new Size (200, 100);
3386 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
3387 Rectangle client = pb.ClientRectangle;
3389 // FIXME - instead of drawing the whole picturebox every time
3390 // intersect the clip rectangle with the drawn picture and only draw what's needed,
3391 // Also, we only need a background fill where no image goes
3392 if (pb.Image != null) {
3393 switch (pb.SizeMode) {
3394 case PictureBoxSizeMode.StretchImage:
3395 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
3398 case PictureBoxSizeMode.CenterImage:
3399 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
3400 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
3403 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
3405 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
3412 // We only get here if no image is set. At least paint the background
3413 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
3416 public override Size PictureBoxDefaultSize {
3418 return new Size (100, 50);
3421 #endregion // PictureBox
3423 #region PrintPreviewControl
3424 public override int PrintPreviewControlPadding {
3428 public override Size PrintPreviewControlGetPageSize (PrintPreviewControl preview)
3430 int page_width, page_height;
3431 int padding = PrintPreviewControlPadding;
3432 PreviewPageInfo[] pis = preview.page_infos;
3434 if (preview.AutoZoom) {
3435 int height_available = preview.ClientRectangle.Height - (preview.Rows) * padding - 2 * padding;
3436 int width_available = preview.ClientRectangle.Width - (preview.Columns - 1) * padding - 2 * padding;
3438 float image_ratio = (float)pis[0].Image.Width / pis[0].Image.Height;
3440 /* try to lay things out using the width to determine the size */
3441 page_width = width_available / preview.Columns;
3442 page_height = (int)(page_width / image_ratio);
3444 /* does the height fit? */
3445 if (page_height * (preview.Rows + 1) > height_available) {
3446 /* no, lay things out via the height */
3447 page_height = height_available / (preview.Rows + 1);
3448 page_width = (int)(page_height * image_ratio);
3452 page_width = (int)(pis[0].Image.Width * preview.Zoom);
3453 page_height = (int)(pis[0].Image.Height * preview.Zoom);
3456 return new Size (page_width, page_height);
3459 public override void PrintPreviewControlPaint (PaintEventArgs pe, PrintPreviewControl preview, Size page_size)
3462 PreviewPageInfo[] pis = preview.page_infos;
3468 int width = page_size.Width * preview.Columns + padding * (preview.Columns - 1) + 2 * padding;
3469 int height = page_size.Height * (preview.Rows + 1) + padding * preview.Rows + 2 * padding;
3471 Rectangle viewport = preview.ViewPort;
3473 pe.Graphics.Clip = new Region (viewport);
3475 /* center things if we can */
3476 int off_x = viewport.Width / 2 - width / 2;
3477 if (off_x < 0) off_x = 0;
3478 int off_y = viewport.Height / 2 - height / 2;
3479 if (off_y < 0) off_y = 0;
3481 page_y = off_y + padding - preview.vbar_value;
3483 if (preview.StartPage > 0) {
3484 int p = preview.StartPage - 1;
3485 for (int py = 0; py < preview.Rows + 1; py ++) {
3486 page_x = off_x + padding - preview.hbar_value;
3487 for (int px = 0; px < preview.Columns; px ++) {
3488 if (p >= pis.Length)
3490 Image image = preview.image_cache[p];
3492 image = pis[p].Image;
3493 Rectangle dest = new Rectangle (new Point (page_x, page_y), page_size);
3495 pe.Graphics.DrawImage (image, dest, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
3497 page_x += padding + page_size.Width;
3500 page_y += padding + page_size.Height;
3504 #endregion // PrintPreviewControl
3507 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
3509 Rectangle block_rect;
3510 Rectangle client_area = ctrl.client_area;
3511 int space_betweenblocks = 2;
3516 block_width = (client_area.Height * 2 ) / 3;
3517 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
3518 increment = block_width + space_betweenblocks;
3521 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
3524 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
3525 while ((block_rect.X - client_area.X) < barpos_pixels) {
3527 if (clip_rect.IntersectsWith (block_rect) == true) {
3528 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
3531 block_rect.X += increment;
3535 public override Size ProgressBarDefaultSize {
3537 return new Size (100, 23);
3541 #endregion // ProgressBar
3544 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
3545 StringFormat text_format;
3546 Rectangle client_rectangle;
3547 Rectangle text_rectangle;
3548 Rectangle radiobutton_rectangle;
3549 int radiobutton_size = 13;
3550 int radiobutton_space = 4;
3552 client_rectangle = radio_button.ClientRectangle;
3553 text_rectangle = client_rectangle;
3554 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
3556 text_format = new StringFormat();
3557 text_format.Alignment = StringAlignment.Near;
3558 text_format.LineAlignment = StringAlignment.Center;
3559 text_format.HotkeyPrefix = HotkeyPrefix.Show;
3561 /* Calculate the position of text and checkbox rectangle */
3562 if (radio_button.appearance!=Appearance.Button) {
3563 switch(radio_button.radiobutton_alignment) {
3564 case ContentAlignment.BottomCenter: {
3565 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
3566 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
3567 text_rectangle.X=client_rectangle.X;
3568 text_rectangle.Width=client_rectangle.Width;
3569 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
3573 case ContentAlignment.BottomLeft: {
3574 radiobutton_rectangle.X=client_rectangle.Left;
3575 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
3576 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
3577 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3581 case ContentAlignment.BottomRight: {
3582 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
3583 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
3584 text_rectangle.X=client_rectangle.X;
3585 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3589 case ContentAlignment.MiddleCenter: {
3590 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
3591 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
3592 text_rectangle.X=client_rectangle.X;
3593 text_rectangle.Width=client_rectangle.Width;
3598 case ContentAlignment.MiddleLeft: {
3599 radiobutton_rectangle.X=client_rectangle.Left;
3600 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
3601 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
3602 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3606 case ContentAlignment.MiddleRight: {
3607 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
3608 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
3609 text_rectangle.X=client_rectangle.X;
3610 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3614 case ContentAlignment.TopCenter: {
3615 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
3616 radiobutton_rectangle.Y=client_rectangle.Top;
3617 text_rectangle.X=client_rectangle.X;
3618 text_rectangle.Y=radiobutton_size+radiobutton_space;
3619 text_rectangle.Width=client_rectangle.Width;
3620 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
3624 case ContentAlignment.TopLeft: {
3625 radiobutton_rectangle.X=client_rectangle.Left;
3626 radiobutton_rectangle.Y=client_rectangle.Top;
3627 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
3628 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3632 case ContentAlignment.TopRight: {
3633 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
3634 radiobutton_rectangle.Y=client_rectangle.Top;
3635 text_rectangle.X=client_rectangle.X;
3636 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
3641 text_rectangle.X=client_rectangle.X;
3642 text_rectangle.Width=client_rectangle.Width;
3645 /* Set the horizontal alignment of our text */
3646 switch(radio_button.text_alignment) {
3647 case ContentAlignment.BottomLeft:
3648 case ContentAlignment.MiddleLeft:
3649 case ContentAlignment.TopLeft: {
3650 text_format.Alignment=StringAlignment.Near;
3654 case ContentAlignment.BottomCenter:
3655 case ContentAlignment.MiddleCenter:
3656 case ContentAlignment.TopCenter: {
3657 text_format.Alignment=StringAlignment.Center;
3661 case ContentAlignment.BottomRight:
3662 case ContentAlignment.MiddleRight:
3663 case ContentAlignment.TopRight: {
3664 text_format.Alignment=StringAlignment.Far;
3669 /* Set the vertical alignment of our text */
3670 switch(radio_button.text_alignment) {
3671 case ContentAlignment.TopLeft:
3672 case ContentAlignment.TopCenter:
3673 case ContentAlignment.TopRight: {
3674 text_format.LineAlignment=StringAlignment.Near;
3678 case ContentAlignment.BottomLeft:
3679 case ContentAlignment.BottomCenter:
3680 case ContentAlignment.BottomRight: {
3681 text_format.LineAlignment=StringAlignment.Far;
3685 case ContentAlignment.MiddleLeft:
3686 case ContentAlignment.MiddleCenter:
3687 case ContentAlignment.MiddleRight: {
3688 text_format.LineAlignment=StringAlignment.Center;
3693 ButtonState state = ButtonState.Normal;
3694 if (radio_button.FlatStyle == FlatStyle.Flat) {
3695 state |= ButtonState.Flat;
3698 if (radio_button.Checked) {
3699 state |= ButtonState.Checked;
3702 if (!radio_button.Enabled) {
3703 state |= ButtonState.Inactive;
3707 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
3709 if ((radio_button.image != null) || (radio_button.image_list != null))
3710 ButtonBase_DrawImage(radio_button, dc);
3712 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
3714 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
3716 text_format.Dispose ();
3719 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
3721 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
3723 if (radio_button.appearance==Appearance.Button) {
3724 ButtonBase_DrawButton (radio_button, dc);
3726 if ((radio_button.Focused) && radio_button.Enabled)
3727 ButtonBase_DrawFocus(radio_button, dc);
3729 // establish if we are rendering a flat style of some sort
3730 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
3731 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
3733 CPDrawRadioButton(dc, radiobutton_rectangle, state);
3738 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
3740 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
3741 text_format, radio_button.Appearance, radio_button.Checked);
3744 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
3746 if ( radio_button.Focused && radio_button.appearance != Appearance.Button && radio_button.Enabled )
3747 DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor );
3751 // renders a radio button with the Flat and Popup FlatStyle
3752 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
3756 if (radio_button.Enabled) {
3758 // draw the outer flatstyle arcs
3759 if (radio_button.FlatStyle == FlatStyle.Flat) {
3760 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
3762 // fill in the area depending on whether or not the mouse is hovering
3763 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
3764 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3766 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3769 // must be a popup radio button
3771 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
3773 if (radio_button.is_entered || radio_button.Capture) {
3774 // draw the popup 3d button knob
3775 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
3777 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
3778 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
3781 // just draw lighter flatstyle outer circle
3782 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
3787 // fill control background color regardless of actual backcolor
3788 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3789 // draw the ark as control dark
3790 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
3794 if (radio_button.Checked) {
3795 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
3797 Pen dot_pen = SystemPens.ControlDarkDark;
3798 Brush dot_brush = SystemBrushes.ControlDarkDark;
3800 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
3801 dot_pen = SystemPens.ControlDark;
3802 dot_brush = SystemBrushes.ControlDark;
3805 if (rectangle.Height > 13) {
3806 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
3808 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
3809 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
3811 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
3812 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
3814 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
3815 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
3820 public override Size RadioButtonDefaultSize {
3822 return new Size (104,24);
3825 #endregion // RadioButton
3828 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
3830 int scrollbutton_width = bar.scrollbutton_width;
3831 int scrollbutton_height = bar.scrollbutton_height;
3832 Rectangle first_arrow_area;
3833 Rectangle second_arrow_area;
3834 Rectangle thumb_pos;
3836 thumb_pos = bar.ThumbPos;
3839 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
3840 bar.FirstArrowArea = first_arrow_area;
3842 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
3843 bar.SecondArrowArea = second_arrow_area;
3845 thumb_pos.Width = bar.Width;
3846 bar.ThumbPos = thumb_pos;
3849 if (clip.IntersectsWith (first_arrow_area))
3850 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
3851 if (clip.IntersectsWith (second_arrow_area))
3852 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
3855 switch (bar.thumb_moving) {
3856 case ScrollBar.ThumbMoving.None: {
3857 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
3860 case ScrollBar.ThumbMoving.Forward: {
3861 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
3865 case ScrollBar.ThumbMoving.Backwards: {
3866 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
3874 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
3875 bar.FirstArrowArea = first_arrow_area;
3877 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
3878 bar.SecondArrowArea = second_arrow_area;
3880 thumb_pos.Height = bar.Height;
3881 bar.ThumbPos = thumb_pos;
3884 if (clip.IntersectsWith (first_arrow_area))
3885 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
3886 if (clip.IntersectsWith (second_arrow_area))
3887 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
3890 switch (bar.thumb_moving) {
3891 case ScrollBar.ThumbMoving.None: {
3892 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
3896 case ScrollBar.ThumbMoving.Forward: {
3897 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
3901 case ScrollBar.ThumbMoving.Backwards: {
3902 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
3909 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
3912 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
3914 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
3915 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
3918 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
3920 Rectangle r = new Rectangle( 0,
3921 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
3922 Rectangle intersect = Rectangle.Intersect( clip, r );
3924 if ( intersect != Rectangle.Empty )
3926 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
3927 dc.FillRectangle( h, intersect );
3931 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3933 Rectangle r = new Rectangle( 0, scrollbutton_height,
3934 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3935 Rectangle intersect = Rectangle.Intersect( clip, r );
3937 if ( intersect != Rectangle.Empty )
3938 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
3941 r.Y = thumb_pos.Y + thumb_pos.Height;
3942 r.Width = bar.ClientRectangle.Width;
3943 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3945 intersect = Rectangle.Intersect( clip, r );
3946 if ( intersect != Rectangle.Empty )
3947 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3950 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3952 Rectangle r = new Rectangle( 0, scrollbutton_height,
3953 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3954 Rectangle intersect = Rectangle.Intersect( clip, r );
3956 if ( intersect != Rectangle.Empty )
3957 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3960 r.Y = thumb_pos.Y + thumb_pos.Height;
3961 r.Width = bar.ClientRectangle.Width;
3962 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3964 intersect = Rectangle.Intersect( clip, r );
3965 if ( intersect != Rectangle.Empty )
3966 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3969 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
3971 Rectangle r = new Rectangle( scrollbutton_width,
3972 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
3973 Rectangle intersect = Rectangle.Intersect( clip, r );
3975 if ( intersect != Rectangle.Empty )
3976 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3979 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3981 Rectangle r = new Rectangle( scrollbutton_width, 0,
3982 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3983 Rectangle intersect = Rectangle.Intersect( clip, r );
3985 if ( intersect != Rectangle.Empty )
3986 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3988 r.X = thumb_pos.X + thumb_pos.Width;
3990 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3991 r.Height = bar.ClientRectangle.Height;
3993 intersect = Rectangle.Intersect( clip, r );
3994 if ( intersect != Rectangle.Empty )
3995 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3998 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
4000 Rectangle r = new Rectangle( scrollbutton_width, 0,
4001 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
4002 Rectangle intersect = Rectangle.Intersect( clip, r );
4004 if ( intersect != Rectangle.Empty )
4005 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
4007 r.X = thumb_pos.X + thumb_pos.Width;
4009 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
4010 r.Height = bar.ClientRectangle.Height;
4012 intersect = Rectangle.Intersect( clip, r );
4013 if ( intersect != Rectangle.Empty )
4014 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
4017 public override int ScrollBarButtonSize {
4020 #endregion // ScrollBar
4023 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
4024 Rectangle area = sb.ClientRectangle;
4025 int horz_border = 2;
4026 int vert_border = 2;
4028 bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
4030 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
4031 dc.FillRectangle (brush, clip);
4033 if (!sb.ShowPanels && sb.Text != String.Empty) {
4034 string text = sb.Text;
4035 StringFormat string_format = new StringFormat ();
4036 string_format.Trimming = StringTrimming.Character;
4037 string_format.FormatFlags = StringFormatFlags.NoWrap;
4039 if (text.Length > 127)
4040 text = text.Substring (0, 127);
4042 if (text [0] == '\t') {
4043 string_format.Alignment = StringAlignment.Center;
4044 text = text.Substring (1);
4045 if (text [0] == '\t') {
4046 string_format.Alignment = StringAlignment.Far;
4047 text = text.Substring (1);
4051 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
4052 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
4053 string_format.Dispose ();
4054 } else if (sb.ShowPanels) {
4055 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
4056 int prev_x = area.X + horz_border;
4057 int y = area.Y + vert_border;
4058 for (int i = 0; i < sb.Panels.Count; i++) {
4059 Rectangle pr = new Rectangle (prev_x, y,
4060 sb.Panels [i].Width, area.Height);
4061 prev_x += pr.Width + StatusBarHorzGapWidth;
4062 if (pr.IntersectsWith (clip))
4063 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
4067 if (sb.SizingGrip) {
4068 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
4069 CPDrawSizeGrip (dc, ColorControl, area);
4075 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
4076 Brush br_forecolor, StatusBarPanel panel) {
4077 int border_size = 3; // this is actually const, even if the border style is none
4078 int icon_width = 16;
4080 area.Height -= border_size;
4082 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
4083 Border3DStyle border_style = Border3DStyle.SunkenOuter;
4084 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
4085 border_style = Border3DStyle.RaisedInner;
4087 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
4090 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
4091 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
4092 dc, panel.Parent.Font, area, index, DrawItemState.Default,
4093 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
4094 panel.Parent.OnDrawItemInternal (e);
4098 if (panel.Text == String.Empty)
4101 string text = panel.Text;
4102 StringFormat string_format = new StringFormat ();
4103 string_format.Trimming = StringTrimming.Character;
4104 string_format.FormatFlags = StringFormatFlags.NoWrap;
4107 if (text [0] == '\t') {
4108 string_format.Alignment = StringAlignment.Center;
4109 text = text.Substring (1);
4110 if (text [0] == '\t') {
4111 string_format.Alignment = StringAlignment.Far;
4112 text = text.Substring (1);
4116 Rectangle string_rect = Rectangle.Empty;
4120 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
4122 switch (panel.Alignment) {
4123 case HorizontalAlignment.Right:
4124 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4125 x = area.Right - len - 4;
4126 string_rect = new Rectangle (x, y,
4127 area.Right - x - border_size,
4128 area.Bottom - y - border_size);
4129 if (panel.Icon != null) {
4130 icon_x = x - icon_width - 2;
4133 case HorizontalAlignment.Center:
4134 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
4135 x = (panel.Width / 2) + (len / 2);
4136 string_rect = new Rectangle (x, y,
4137 area.Right - x - border_size,
4138 area.Bottom - y - border_size);
4140 if (panel.Icon != null) {
4141 icon_x = x - icon_width - 2;
4147 int left = area.Left + border_size;;
4148 if (panel.Icon != null) {
4149 icon_x = area.Left + 2;
4150 left = icon_x + icon_width + 2;
4154 string_rect = new Rectangle (x, y,
4155 area.Right - x - border_size,
4156 area.Bottom - y - border_size);
4160 RectangleF clip_bounds = dc.ClipBounds;
4162 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
4163 dc.SetClip (clip_bounds);
4165 if (panel.Icon != null) {
4166 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
4170 public override int StatusBarSizeGripWidth {
4174 public override int StatusBarHorzGapWidth {
4178 public override Size StatusBarDefaultSize {
4180 return new Size (100, 22);
4183 #endregion // StatusBar
4185 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
4187 Brush brush = SystemBrushes.Control;
4188 dc.FillRectangle (brush, area);
4189 Rectangle panel_rect = GetTabPanelRectExt (tab);
4191 if (tab.Appearance == TabAppearance.Normal) {
4192 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
4193 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4196 if (tab.Alignment == TabAlignment.Top) {
4197 for (int r = tab.TabPages.Count; r > 0; r--) {
4198 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
4199 if (i == tab.SelectedIndex)
4201 if (r != tab.TabPages [i].Row)
4203 Rectangle rect = tab.GetTabRect (i);
4204 if (!rect.IntersectsWith (area))
4206 DrawTab (dc, tab.TabPages [i], tab, rect, false);
4210 for (int r = 0; r < tab.TabPages.Count; r++) {
4211 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
4212 if (i == tab.SelectedIndex)
4214 if (r != tab.TabPages [i].Row)
4216 Rectangle rect = tab.GetTabRect (i);
4217 if (!rect.IntersectsWith (area))
4219 DrawTab (dc, tab.TabPages [i], tab, rect, false);
4224 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
4225 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
4226 if (rect.IntersectsWith (area))
4227 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
4230 if (tab.ShowSlider) {
4231 Rectangle right = GetTabControlRightScrollRect (tab);
4232 Rectangle left = GetTabControlLeftScrollRect (tab);
4233 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
4234 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
4238 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
4240 switch (tab.Alignment) {
4241 case TabAlignment.Top:
4242 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
4244 Rectangle panel_rect = GetTabPanelRectExt (tab);
4245 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
4249 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
4251 switch (tab.Alignment) {
4252 case TabAlignment.Top:
4253 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
4255 Rectangle panel_rect = GetTabPanelRectExt (tab);
4256 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
4260 public override Size TabControlDefaultItemSize {
4261 get { return new Size (42, 21); }
4264 public override Point TabControlDefaultPadding {
4265 get { return new Point (6, 3); }
4268 public override int TabControlMinimumTabWidth {
4272 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
4274 Rectangle ext = GetTabPanelRectExt (tab);
4275 // Account for border size
4276 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
4279 public override Size TabControlGetSpacing (TabControl tab) {
4280 switch (tab.Appearance) {
4281 case TabAppearance.Normal:
4282 return new Size (1, -2);
4283 case TabAppearance.Buttons:
4284 return new Size (3, 3);
4285 case TabAppearance.FlatButtons:
4286 return new Size (9, 3);
4288 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
4292 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
4294 // Offset the tab from the top corner
4295 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
4296 tab.ClientRectangle.Y,
4297 tab.ClientRectangle.Width - 2,
4298 tab.ClientRectangle.Height - 1);
4300 if (tab.TabCount == 0)
4303 int spacing = TabControlGetSpacing (tab).Height;
4304 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
4306 switch (tab.Alignment) {
4307 case TabAlignment.Left:
4309 res.Width -= offset;
4311 case TabAlignment.Right:
4312 res.Width -= offset;
4314 case TabAlignment.Top:
4316 res.Height -= offset;
4318 case TabAlignment.Bottom:
4319 res.Height -= offset;
4326 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
4328 int FlatButtonSpacing = 8;
4330 int res = bounds.Width;
4334 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
4336 StringFormat string_format = new StringFormat ();
4337 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
4338 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
4341 if (tab.Appearance == TabAppearance.FlatButtons) {
4342 int width = bounds.Width;
4343 bounds.Width += (FlatButtonSpacing - 2);
4345 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
4346 bounds.Width = width;
4350 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
4351 } else if (tab.Appearance != TabAppearance.FlatButtons) {
4352 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
4355 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
4358 string_format.Alignment = StringAlignment.Center;
4359 string_format.LineAlignment = StringAlignment.Center;
4360 string_format.FormatFlags = StringFormatFlags.NoWrap;
4362 CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
4364 Pen light = ResPool.GetPen (cpcolor.LightLight);
4366 switch (tab.Alignment) {
4368 case TabAlignment.Top:
4370 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
4372 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
4373 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
4374 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
4376 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
4377 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
4378 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
4380 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
4382 string_format.Alignment = StringAlignment.Center;
4383 string_format.LineAlignment = StringAlignment.Center;
4384 string_format.FormatFlags = StringFormatFlags.NoWrap;
4388 case TabAlignment.Bottom:
4390 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
4392 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
4393 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
4395 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
4396 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
4398 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
4399 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
4400 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
4402 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
4404 string_format.Alignment = StringAlignment.Center;
4405 string_format.LineAlignment = StringAlignment.Center;
4406 string_format.FormatFlags = StringFormatFlags.NoWrap;
4410 case TabAlignment.Left:
4412 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
4414 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
4415 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
4416 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
4418 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
4420 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
4421 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
4423 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
4425 string_format.Alignment = StringAlignment.Center;
4426 string_format.LineAlignment = StringAlignment.Center;
4427 string_format.FormatFlags = StringFormatFlags.NoWrap;
4428 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
4433 // TabAlignment.Right
4435 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
4437 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
4438 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
4440 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
4441 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
4443 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
4444 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
4446 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
4448 string_format.Alignment = StringAlignment.Center;
4449 string_format.LineAlignment = StringAlignment.Center;
4450 string_format.FormatFlags = StringFormatFlags.NoWrap;
4451 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
4457 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
4458 if (tab.Alignment == TabAlignment.Left) {
4459 int wo = interior.Width / 2;
4460 int ho = interior.Height / 2;
4461 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
4462 dc.RotateTransform (180);
4463 dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
4464 dc.ResetTransform ();
4466 Rectangle str_rect = interior;
4468 if (tab.ImageList != null && page.ImageIndex >= 0 && page.ImageIndex < tab.ImageList.Images.Count) {
4469 tab.ImageList.Draw (dc, new Point (interior.X, interior.Y), page.ImageIndex);
4470 str_rect.X += tab.ImageList.ImageSize.Width + 2;
4471 str_rect.Width -= tab.ImageList.ImageSize.Width + 2;
4473 dc.DrawString (page.Text, page.Font,
4474 SystemBrushes.ControlText,
4475 str_rect, string_format);
4477 } else if (page.Text != null) {
4478 DrawItemState state = DrawItemState.None;
4479 if (page == tab.SelectedTab)
4480 state |= DrawItemState.Selected;
4481 DrawItemEventArgs e = new DrawItemEventArgs (dc,
4482 tab.Font, bounds, tab.IndexForTabPage (page),
4483 state, page.ForeColor, page.BackColor);
4484 tab.OnDrawItemInternal (e);
4488 if (page.Parent.Focused && is_selected) {
4489 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
4496 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
4498 StringFormat format = new StringFormat ();
4499 format.Trimming = StringTrimming.EllipsisCharacter;
4500 format.LineAlignment = StringAlignment.Center;
4501 format.HotkeyPrefix = MenuAccessKeysUnderlined ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
4502 if (control.TextAlign == ToolBarTextAlign.Underneath)
4503 format.Alignment = StringAlignment.Center;
4505 format.Alignment = StringAlignment.Near;
4507 if (control is PropertyGrid.PropertyToolBar) {
4508 dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
4510 if (clip_rectangle.X == 0) {
4511 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
4514 if (clip_rectangle.Y < 2) {
4515 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
4518 if (clip_rectangle.Bottom == control.Bottom) {
4519 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
4522 if (clip_rectangle.Right == control.Right) {
4523 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
4527 if (control.Appearance == ToolBarAppearance.Flat && control.Parent != null) {
4528 if (control.Parent.BackgroundImage != null) {
4529 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile))
4530 dc.FillRectangle (b, clip_rectangle);
4532 dc.FillRectangle (ResPool.GetSolidBrush (control.Parent.BackColor), clip_rectangle);
4535 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
4538 if (control.Divider && clip_rectangle.Y < 2) {
4539 if (clip_rectangle.Y < 1) {
4540 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
4542 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
4546 foreach (ToolBarButton button in control.Buttons)
4547 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
4548 DrawToolBarButton (dc, control, button, format);
4553 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
4555 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
4557 DrawToolBarButtonBorder (dc, button, is_flat);
4559 switch (button.Style) {
4560 case ToolBarButtonStyle.DropDownButton:
4561 if (control.DropDownArrows)
4562 DrawToolBarDropDownArrow (dc, button, is_flat);
4563 DrawToolBarButtonContents (dc, control, button, format);
4566 case ToolBarButtonStyle.Separator:
4568 DrawToolBarSeparator (dc, button);
4571 case ToolBarButtonStyle.ToggleButton:
4572 DrawToolBarToggleButtonBackground (dc, button);
4573 DrawToolBarButtonContents (dc, control, button, format);
4577 DrawToolBarButtonContents (dc, control, button, format);
4582 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
4584 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
4586 if (button.Style == ToolBarButtonStyle.Separator)
4589 Border3DStyle style;
4592 if (button.Pushed || button.Pressed)
4593 style = Border3DStyle.SunkenOuter;
4594 else if (button.Hilight)
4595 style = Border3DStyle.RaisedInner;
4600 if (button.Pushed || button.Pressed)
4601 style = Border3DStyle.Sunken;
4603 style = Border3DStyle.Raised;
4606 Rectangle rect = button.Rectangle;
4607 if ((button.Style == ToolBarButtonStyle.DropDownButton) && (button.Parent.DropDownArrows) && is_flat)
4608 rect.Width -= ToolBarDropDownWidth;
4610 CPDrawBorder3D (dc, rect, style, all_sides);
4613 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
4615 Rectangle area = button.Rectangle;
4616 int offset = (int) SystemPens.Control.Width + 1;
4617 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
4618 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
4621 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
4624 Rectangle area = button.Rectangle;
4625 area.X += ToolBarImageGripWidth;
4626 area.Y += ToolBarImageGripWidth;
4627 area.Width -= 2 * ToolBarImageGripWidth;
4628 area.Height -= 2 * ToolBarImageGripWidth;
4631 brush = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorScrollBar, ColorControlLightLight);
4632 else if (button.PartialPush)
4633 brush = SystemBrushes.ControlLight;
4635 brush = SystemBrushes.Control;
4637 dc.FillRectangle (brush, area);
4640 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
4642 Rectangle rect = button.Rectangle;
4643 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
4644 rect.Width = ToolBarDropDownWidth;
4647 if (button.dd_pressed)
4648 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
4649 else if (button.Pushed || button.Pressed)
4650 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
4651 else if (button.Hilight)
4652 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedInner, all_sides);
4654 if (button.dd_pressed)
4655 CPDrawBorder3D (dc, rect, Border3DStyle.Flat, all_sides);
4656 else if (button.Pushed || button.Pressed)
4657 CPDrawBorder3D (dc, Rectangle.Inflate(rect, -1, -1), Border3DStyle.SunkenOuter, all_sides);
4659 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
4662 PointF [] vertices = new PointF [3];
4663 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height / 2));
4665 // Increase vertical and horizontal position by 1 when button is pressed
4666 if (button.Pressed || button.Pushed || button.dd_pressed) {
4671 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
4672 vertices [0].Y = ddCenter.Y;
4673 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
4674 vertices [1].Y = ddCenter.Y;
4675 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
4676 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
4677 dc.FillPolygon (SystemBrushes.ControlText, vertices);
4680 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
4682 if (button.Image != null) {
4683 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
4684 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
4686 // Increase vertical and horizontal position by 1 when button is pressed
4687 if (button.Pressed || button.Pushed) {
4693 dc.DrawImage (button.Image, x, y);
4695 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
4698 Rectangle text_rect = button.TextRectangle;
4699 if (text_rect.Width <= 0 || text_rect.Height <= 0)
4702 if (button.Pressed || button.Pushed) {
4708 dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
4710 CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, text_rect, format);
4713 // Grip width for the ToolBar
4714 public override int ToolBarGripWidth {
4718 // Grip width for the Image on the ToolBarButton
4719 public override int ToolBarImageGripWidth {
4723 // width of the separator
4724 public override int ToolBarSeparatorWidth {
4728 // width of the dropdown arrow rect
4729 public override int ToolBarDropDownWidth {
4733 // width for the dropdown arrow on the ToolBarButton
4734 public override int ToolBarDropDownArrowWidth {
4738 // height for the dropdown arrow on the ToolBarButton
4739 public override int ToolBarDropDownArrowHeight {
4743 public override Size ToolBarDefaultSize {
4745 return new Size (100, 42);
4749 #endregion // ToolBar
4752 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
4753 dc.FillRectangle(SystemBrushes.Info, control.ClientRectangle);
4754 dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
4755 dc.DrawString(control.Text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.ClientRectangle, control.string_format);
4758 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
4761 sizef = tt.DeviceContext.MeasureString(text, tt.Font, SizeF.Empty, tt.string_format);
4762 return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
4764 #endregion // ToolTip
4767 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
4768 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
4769 float ticks, int value_pos, bool mouse_value) {
4771 Point toptick_startpoint = new Point ();
4772 Point bottomtick_startpoint = new Point ();
4773 Point channel_startpoint = new Point ();
4775 float pixels_betweenticks;
4776 const int space_from_right = 8;
4777 const int space_from_left = 8;
4778 const int space_from_bottom = 11;
4779 Rectangle area = tb.ClientRectangle;
4781 switch (tb.TickStyle) {
4782 case TickStyle.BottomRight:
4783 case TickStyle.None:
4784 channel_startpoint.Y = 8;
4785 channel_startpoint.X = 9;
4786 bottomtick_startpoint.Y = 13;
4787 bottomtick_startpoint.X = 24;
4789 case TickStyle.TopLeft:
4790 channel_startpoint.Y = 8;
4791 channel_startpoint.X = 19;
4792 toptick_startpoint.Y = 13;
4793 toptick_startpoint.X = 8;
4795 case TickStyle.Both:
4796 channel_startpoint.Y = 8;
4797 channel_startpoint.X = 18;
4798 bottomtick_startpoint.Y = 13;
4799 bottomtick_startpoint.X = 32;
4800 toptick_startpoint.Y = 13;
4801 toptick_startpoint.X = 8;
4807 thumb_area.X = area.X + channel_startpoint.X;
4808 thumb_area.Y = area.Y + channel_startpoint.Y;
4809 thumb_area.Height = area.Height - space_from_right - space_from_left;
4810 thumb_area.Width = 4;
4813 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
4814 1, thumb_area.Height);
4816 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
4817 1, thumb_area.Height);
4819 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
4820 1, thumb_area.Height);
4822 pixel_len = thumb_area.Height - 11;
4823 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4825 /* Convert thumb position from mouse position to value*/
4827 if (tb.mouse_moved) {
4828 value_pos += (int) pixels_betweenticks / 2;
4829 if (value_pos < thumb_area.Bottom) {
4830 value_pos = (int) ((thumb_area.Bottom - value_pos - (int)(thumb_pos.Width / 2)) / pixels_betweenticks);
4835 if (value_pos + tb.Minimum > tb.Maximum)
4836 value_pos = tb.Maximum - tb.Minimum;
4837 else if (value_pos + tb.Minimum < tb.Minimum)
4840 tb.Value = value_pos + tb.Minimum;
4842 value_pos = tb.Value - tb.Minimum;
4846 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
4847 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
4849 /* Draw thumb fixed 10x22 size */
4850 thumb_pos.Width = 10;
4851 thumb_pos.Height = 22;
4853 switch (tb.TickStyle) {
4854 case TickStyle.BottomRight:
4855 case TickStyle.None: {
4856 thumb_pos.X = channel_startpoint.X - 8;
4858 Pen pen = SystemPens.ControlLight;
4859 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
4860 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
4861 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
4863 pen = SystemPens.ControlDark;
4864 dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
4865 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
4867 pen = SystemPens.ControlDarkDark;
4868 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
4869 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
4871 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
4872 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
4873 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
4874 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
4878 case TickStyle.TopLeft: {
4879 thumb_pos.X = channel_startpoint.X - 10;
4881 Pen pen = SystemPens.ControlLight;
4882 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
4883 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
4885 pen = SystemPens.ControlDark;
4886 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
4887 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
4888 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
4890 pen = SystemPens.ControlDarkDark;
4891 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
4892 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
4893 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
4895 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
4896 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
4897 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
4898 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
4903 case TickStyle.Both: {
4904 thumb_pos.X = area.X + 10;
4906 Pen pen = SystemPens.ControlLight;
4907 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
4908 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
4910 pen = SystemPens.ControlDark;
4911 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
4912 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
4914 pen = SystemPens.ControlDarkDark;
4915 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
4916 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
4918 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
4927 pixel_len = thumb_area.Height - 11;
4928 pixels_betweenticks = pixel_len / ticks;
4930 thumb_area.X = thumb_pos.X;
4931 thumb_area.Y = channel_startpoint.Y;
4932 thumb_area.Width = thumb_pos.Height;
4935 Region outside = new Region (area);
4936 outside.Exclude (thumb_area);
4938 if (outside.IsVisible (clip_rectangle)) {
4939 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4940 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4942 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4943 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4944 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
4945 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
4947 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
4948 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
4952 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4953 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4955 pixel_len = thumb_area.Height - 11;
4956 pixels_betweenticks = pixel_len / ticks;
4958 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4959 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4960 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
4961 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4963 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
4964 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4976 Does not matter the size of the control, Win32 always draws:
4977 - Ticks starting from pixel 13, 8
4978 - Channel starting at pos 8, 19 and ends at Width - 8
4979 - Autosize makes always the control 45 pixels high
4980 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4983 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
4984 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
4985 float ticks, int value_pos, bool mouse_value) {
4986 Point toptick_startpoint = new Point ();
4987 Point bottomtick_startpoint = new Point ();
4988 Point channel_startpoint = new Point ();
4990 float pixels_betweenticks;
4991 const int space_from_right = 8;
4992 const int space_from_left = 8;
4993 Rectangle area = tb.ClientRectangle;
4995 switch (tb.TickStyle) {
4996 case TickStyle.BottomRight:
4997 case TickStyle.None:
4998 channel_startpoint.X = 8;
4999 channel_startpoint.Y = 9;
5000 bottomtick_startpoint.X = 13;
5001 bottomtick_startpoint.Y = 24;
5003 case TickStyle.TopLeft:
5004 channel_startpoint.X = 8;
5005 channel_startpoint.Y = 19;
5006 toptick_startpoint.X = 13;
5007 toptick_startpoint.Y = 8;
5009 case TickStyle.Both:
5010 channel_startpoint.X = 8;
5011 channel_startpoint.Y = 18;
5012 bottomtick_startpoint.X = 13;
5013 bottomtick_startpoint.Y = 32;
5014 toptick_startpoint.X = 13;
5015 toptick_startpoint.Y = 8;
5021 thumb_area.X = area.X + channel_startpoint.X;
5022 thumb_area.Y = area.Y + channel_startpoint.Y;
5023 thumb_area.Width = area.Width - space_from_right - space_from_left;
5024 thumb_area.Height = 4;
5027 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
5028 thumb_area.Width, 1);
5030 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
5031 thumb_area.Width, 1);
5033 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
5034 thumb_area.Width, 1);
5036 pixel_len = thumb_area.Width - 11;
5037 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
5039 /* Convert thumb position from mouse position to value*/
5041 if (tb.mouse_moved) {
5042 value_pos += (int) pixels_betweenticks / 2;
5043 if (value_pos >= channel_startpoint.X) {
5044 value_pos = (int)(((float) (value_pos - channel_startpoint.X - (int)(thumb_pos.Width / 2))) / pixels_betweenticks);
5048 if (value_pos + tb.Minimum > tb.Maximum)
5049 value_pos = tb.Maximum - tb.Minimum;
5050 else if(value_pos + tb.Minimum < tb.Minimum)
5053 tb.Value = value_pos + tb.Minimum;
5055 value_pos = tb.Value - tb.Minimum;
5059 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
5061 /* Draw thumb fixed 10x22 size */
5062 thumb_pos.Width = 10;
5063 thumb_pos.Height = 22;
5065 switch (tb.TickStyle) {
5066 case TickStyle.BottomRight:
5067 case TickStyle.None: {
5068 thumb_pos.Y = channel_startpoint.Y - 8;
5070 Pen pen = SystemPens.ControlLight;
5071 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
5072 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
5073 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
5075 pen = SystemPens.ControlDark;
5076 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
5077 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
5079 pen = SystemPens.ControlDarkDark;
5080 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
5081 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
5083 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
5084 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
5085 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
5086 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
5089 case TickStyle.TopLeft: {
5090 thumb_pos.Y = channel_startpoint.Y - 10;
5092 Pen pen = SystemPens.ControlLight;
5093 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
5094 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
5096 pen = SystemPens.ControlDark;
5097 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
5098 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
5099 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
5101 pen = SystemPens.ControlDarkDark;
5102 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
5103 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
5104 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
5106 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
5107 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
5108 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
5109 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
5113 case TickStyle.Both: {
5114 thumb_pos.Y = area.Y + 10;
5116 Pen pen = SystemPens.ControlLight;
5117 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
5118 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
5120 pen = SystemPens.ControlDark;
5121 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
5122 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
5124 pen = SystemPens.ControlDarkDark;
5125 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
5126 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
5128 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
5137 pixel_len = thumb_area.Width - 11;
5138 pixels_betweenticks = pixel_len / ticks;
5141 thumb_area.Y = thumb_pos.Y;
5142 thumb_area.X = channel_startpoint.X;
5143 thumb_area.Height = thumb_pos.Height;
5144 Region outside = new Region (area);
5145 outside.Exclude (thumb_area);
5147 if (outside.IsVisible (clip_rectangle)) {
5148 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
5149 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
5151 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
5152 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
5153 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
5154 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
5156 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
5157 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
5161 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
5162 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
5164 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
5165 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
5166 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
5167 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
5169 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
5170 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
5178 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
5183 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
5185 Rectangle thumb_pos = tb.ThumbPos;
5186 Rectangle thumb_area = tb.ThumbArea;
5188 if (tb.thumb_pressed) {
5189 value_pos = tb.thumb_mouseclick;
5192 value_pos = tb.Value - tb.Minimum;
5193 mouse_value = false;
5196 area = tb.ClientRectangle;
5199 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
5200 } else if (tb.thumb_pressed == true) {
5201 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
5203 br_thumb = SystemBrushes.Control;
5207 /* Control Background */
5208 if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
5209 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
5211 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
5215 CPDrawFocusRectangle(dc, area, tb.ForeColor, tb.BackColor);
5218 if (tb.Orientation == Orientation.Vertical) {
5219 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
5220 br_thumb, ticks, value_pos, mouse_value);
5223 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
5224 br_thumb, ticks, value_pos, mouse_value);
5227 tb.ThumbPos = thumb_pos;
5228 tb.ThumbArea = thumb_area;
5231 public override Size TrackBarDefaultSize {
5233 return new Size (104, 42);
5237 #endregion // TrackBar
5240 public override Size VScrollBarDefaultSize {
5242 return new Size (this.ScrollBarButtonSize, 80);
5245 #endregion // VScrollBar
5248 public override Size TreeViewDefaultSize {
5250 return new Size (121, 97);
5256 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
5258 if (wm.IsToolWindow && !wm.IsMinimized)
5259 return SystemInformation.ToolWindowCaptionHeight;
5260 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
5262 return SystemInformation.CaptionHeight;
5265 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
5270 public override int ManagedWindowIconWidth (InternalWindowManager wm)
5272 return ManagedWindowTitleBarHeight (wm) - 5;
5275 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
5277 TitleButtons buttons = wm.TitleButtons;
5278 Form form = wm.form;
5280 buttons.HelpButton.Visible = form.HelpButton;
5282 foreach (TitleButton button in buttons) {
5283 button.Visible = false;
5286 switch (form.FormBorderStyle) {
5287 case FormBorderStyle.None:
5288 if (form.WindowState != FormWindowState.Normal)
5289 goto case FormBorderStyle.Sizable;
5291 case FormBorderStyle.FixedToolWindow:
5292 case FormBorderStyle.SizableToolWindow:
5293 buttons.CloseButton.Visible = true;
5294 if (form.WindowState != FormWindowState.Normal)
5295 goto case FormBorderStyle.Sizable;
5297 case FormBorderStyle.FixedSingle:
5298 case FormBorderStyle.Fixed3D:
5299 case FormBorderStyle.FixedDialog:
5300 case FormBorderStyle.Sizable:
5301 switch (form.WindowState) {
5302 case FormWindowState.Normal:
5303 buttons.MinimizeButton.Visible = true;
5304 buttons.MaximizeButton.Visible = true;
5305 buttons.RestoreButton.Visible = false;
5307 case FormWindowState.Maximized:
5308 buttons.MinimizeButton.Visible = true;
5309 buttons.MaximizeButton.Visible = false;
5310 buttons.RestoreButton.Visible = true;
5312 case FormWindowState.Minimized:
5313 buttons.MinimizeButton.Visible = false;
5314 buttons.MaximizeButton.Visible = true;
5315 buttons.RestoreButton.Visible = true;
5318 buttons.CloseButton.Visible = true;
5322 int bw = ManagedWindowBorderWidth (wm);
5323 Size btsize = ManagedWindowButtonSize (wm);
5324 int btw = btsize.Width;
5325 int bth = btsize.Height;
5327 int left = form.Width - bw - btw - 2;
5329 if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
5330 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
5333 if (buttons.MaximizeButton.Visible) {
5334 buttons.MaximizeButton.Rectangle = new Rectangle (left, top, btw, bth);
5337 if (buttons.RestoreButton.Visible) {
5338 buttons.RestoreButton.Rectangle = new Rectangle (left, top, btw, bth);
5342 buttons.MinimizeButton.Rectangle = new Rectangle (left, top, btw, bth);
5344 } else if (wm.IsToolWindow) {
5345 buttons.CloseButton.Rectangle = new Rectangle (left, top, btw, bth);
5350 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
5352 Form form = wm.Form;
5353 int tbheight = ManagedWindowTitleBarHeight (wm);
5354 int bdwidth = ManagedWindowBorderWidth (wm);
5355 Color titlebar_color = Color.FromArgb (255, 10, 36, 106);
5356 Color titlebar_color2 = Color.FromArgb (255, 166, 202, 240);
5357 Color color = ThemeEngine.Current.ColorControlDark;
5358 Color color2 = Color.FromArgb (255, 192, 192, 192);
5361 Console.WriteLine (DateTime.Now.ToLongTimeString () + " DrawManagedWindowDecorations");
5362 dc.FillRectangle (Brushes.Black, clip);
5365 if (wm.HasBorders) {
5366 Pen pen = ResPool.GetPen (ColorControl);
5367 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
5368 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
5369 // The 3d border is only 2 pixels wide, so we draw the innermost pixels ourselves
5370 borders = new Rectangle (2, 2, form.Width - 5, form.Height - 5);
5371 for (int i = 2; i < bdwidth; i++) {
5372 dc.DrawRectangle (pen, borders);
5373 borders.Inflate (-1, -1);
5378 bool draw_titlebar_enabled = false;
5379 if (wm.Form.Parent != null && wm.Form.Parent is Form) {
5380 draw_titlebar_enabled = false;
5381 } else if (wm.IsActive && !wm.IsMaximized) {
5382 draw_titlebar_enabled = true;
5384 if (draw_titlebar_enabled) {
5385 color = titlebar_color;
5386 color2 = titlebar_color2;
5389 Rectangle tb = new Rectangle (bdwidth, bdwidth, form.Width - (bdwidth * 2), tbheight - 1);
5391 // HACK: For now always draw the titlebar until we get updates better
5392 if (tb.Width > 0 && tb.Height > 0) {
5393 using (System.Drawing.Drawing2D.LinearGradientBrush gradient = new LinearGradientBrush (tb, color, color2, LinearGradientMode.Horizontal))
5395 dc.FillRectangle (gradient, tb);
5399 // Draw the line just beneath the title bar
5400 dc.DrawLine (ResPool.GetPen (SystemColors.Control), bdwidth,
5401 tbheight + bdwidth - 1, form.Width - bdwidth - 1,
5402 tbheight + bdwidth - 1);
5404 if (!wm.IsToolWindow) {
5405 tb.X += 18; // Room for the icon and the buttons
5406 tb.Width = (form.Width - 62) - tb.X;
5409 if (form.Text != null && form.Text != string.Empty) {
5410 StringFormat format = new StringFormat ();
5411 format.FormatFlags = StringFormatFlags.NoWrap;
5412 format.Trimming = StringTrimming.EllipsisCharacter;
5413 format.LineAlignment = StringAlignment.Center;
5415 if (tb.IntersectsWith (clip))
5416 dc.DrawString (form.Text, WindowBorderFont,
5417 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
5421 if (wm.HasBorders) {
5422 bool draw_icon = false;
5424 draw_icon = !wm.IsToolWindow && form.Icon != null && form.ShowIcon;
5426 draw_icon = !wm.IsToolWindow && form.Icon != null;
5429 Rectangle icon = new Rectangle (bdwidth + 3,
5430 bdwidth + 2, wm.IconWidth, wm.IconWidth);
5431 if (icon.IntersectsWith (clip))
5432 dc.DrawIcon (form.Icon, icon);
5435 foreach (TitleButton button in wm.TitleButtons.AllButtons) {
5436 DrawTitleButton (dc, button, clip);
5441 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
5443 int height = ManagedWindowTitleBarHeight (wm);
5444 if (!wm.IsMaximized && !wm.IsMinimized) {
5445 if (wm.IsToolWindow)
5446 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
5448 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
5451 height = SystemInformation.CaptionHeight;
5453 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
5457 private void DrawTitleButton (Graphics dc, TitleButton button, Rectangle clip)
5459 if (!button.Visible) {
5463 if (!button.Rectangle.IntersectsWith (clip))
5466 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
5468 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
5469 button.Caption, button.State);
5472 #region ControlPaint
5473 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
5474 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
5475 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
5476 int bottomWidth, ButtonBorderStyle bottomStyle) {
5477 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
5478 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
5479 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
5480 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
5483 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
5484 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
5487 protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
5490 Pen penTopLeftInner;
5492 Pen penBottomRightInner;
5493 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
5494 bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
5496 if ((style & Border3DStyle.Adjust) != 0) {
5503 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
5505 CPColor cpcolor = CPColor.Empty;
5507 if (!is_ColorControl)
5508 cpcolor = ResPool.GetCPColor (control_color);
5511 case Border3DStyle.Raised:
5512 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
5513 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
5514 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5516 case Border3DStyle.Sunken:
5517 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5518 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
5519 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
5521 case Border3DStyle.Etched:
5522 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5523 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
5525 case Border3DStyle.RaisedOuter:
5526 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
5528 case Border3DStyle.SunkenOuter:
5529 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5530 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
5532 case Border3DStyle.RaisedInner:
5533 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
5534 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5536 case Border3DStyle.SunkenInner:
5537 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
5539 case Border3DStyle.Flat:
5540 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
5542 case Border3DStyle.Bump:
5543 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
5549 bool inner = ((style != Border3DStyle.RaisedOuter) && (style != Border3DStyle.SunkenOuter));
5551 if ((sides & Border3DSide.Middle) != 0) {
5552 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
5553 graphics.FillRectangle (brush, rect);
5556 if ((sides & Border3DSide.Left) != 0) {
5557 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
5558 if ((rect.Width > 2) && inner)
5559 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
5562 if ((sides & Border3DSide.Top) != 0) {
5563 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
5564 if ((rect.Height > 2) && inner)
5565 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
5568 if ((sides & Border3DSide.Right) != 0) {
5569 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
5570 if ((rect.Width > 3) && inner)
5571 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
5574 if ((sides & Border3DSide.Bottom) != 0) {
5575 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
5576 if ((rect.Height > 3) && inner)
5577 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
5581 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
5583 CPDrawButtonInternal (dc, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLight);
5586 private void CPDrawButtonInternal (Graphics dc, Rectangle rectangle, ButtonState state, Pen DarkPen, Pen NormalPen, Pen LightPen)
5588 // sadly enough, the rectangle gets always filled with a hatchbrush
5589 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
5590 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
5591 ColorControl.G, ColorControl.B),
5593 rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
5595 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
5596 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
5598 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
5600 if ((state & ButtonState.Flat) == ButtonState.Flat) {
5601 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
5603 if ((state & ButtonState.Checked) == ButtonState.Checked) {
5604 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
5607 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
5608 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
5611 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
5612 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
5615 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
5616 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
5618 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
5620 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
5621 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
5624 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
5625 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
5628 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
5629 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
5631 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
5633 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
5634 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
5637 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
5638 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
5641 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
5642 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
5647 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
5648 Rectangle captionRect;
5651 CPDrawButtonInternal (graphics, rectangle, state, SystemPens.ControlDarkDark, SystemPens.ControlDark, SystemPens.ControlLightLight);
5653 if (rectangle.Width<rectangle.Height) {
5654 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
5656 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
5659 if ((state & ButtonState.Pushed)!=0) {
5660 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
5663 /* Make sure we've got at least a line width of 1 */
5664 lineWidth=Math.Max(1, captionRect.Width/7);
5667 case CaptionButton.Close: {
5670 if ((state & ButtonState.Inactive)!=0) {
5671 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
5672 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
5674 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
5675 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
5678 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
5679 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
5684 case CaptionButton.Help:
5685 case CaptionButton.Maximize:
5686 case CaptionButton.Minimize:
5687 case CaptionButton.Restore: {
5688 if ((state & ButtonState.Inactive)!=0) {
5689 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
5691 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
5694 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
5701 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
5703 Pen check_pen = SystemPens.ControlDarkDark;
5705 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
5707 if ((state & ButtonState.All) == ButtonState.All) {
5709 cb_rect.Height -= 2;
5711 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
5712 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
5714 check_pen = SystemPens.ControlDark;
5716 if ((state & ButtonState.Flat) == ButtonState.Flat) {
5718 cb_rect.Height -= 2;
5720 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
5721 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
5724 cb_rect.Height -= 1;
5726 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
5728 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
5729 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
5731 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
5733 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
5734 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50,
5735 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
5736 ColorControl.G, ColorControl.B),
5737 ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
5739 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
5741 Pen pen = SystemPens.ControlDark;
5742 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
5743 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
5745 pen = SystemPens.ControlDarkDark;
5746 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
5747 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
5749 pen = SystemPens.ControlLight;
5750 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
5751 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
5753 // oh boy, matching ms is like fighting against windmills
5754 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50,
5755 Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
5756 ColorControl.G, ColorControl.B), ColorControl))) {
5757 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
5758 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
5761 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
5762 check_pen = SystemPens.ControlDark;
5765 if ((state & ButtonState.Checked) == ButtonState.Checked) {
5766 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
5768 if (check_size < 7) {
5769 int lineWidth = Math.Max (3, check_size / 3);
5770 int Scale = Math.Max (1, check_size / 9);
5772 Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1,
5773 check_size, check_size);
5775 for (int i = 0; i < lineWidth; i++) {
5776 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
5777 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);
5780 int lineWidth = Math.Max (3, check_size / 3) + 1;
5782 int x_half = cb_rect.Width / 2;
5783 int y_half = cb_rect.Height / 2;
5785 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
5786 check_size, check_size);
5788 int gradient_left = check_size / 3;
5789 int gradient_right = check_size - gradient_left - 1;
5792 for (int i = 0; i < lineWidth; i++) {
5793 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
5794 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
5800 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
5801 Point[] arrow = new Point[3];
5811 if ((state & ButtonState.Checked)!=0) {
5812 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
5815 if ((state & ButtonState.Flat)!=0) {
5816 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
5818 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
5819 // this needs to render like a pushed button - jba
5820 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5821 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
5822 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
5824 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5828 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
5829 centerX=rect.Left+rect.Width/2;
5830 centerY=rect.Top+rect.Height/2;
5831 shiftX=Math.Max(1, rect.Width/8);
5832 shiftY=Math.Max(1, rect.Height/8);
5834 if ((state & ButtonState.Pushed)!=0) {
5841 P1=new Point(rect.Left, centerY);
5842 P2=new Point(rect.Right, centerY);
5843 P3=new Point(centerX, rect.Bottom);
5849 /* Draw the arrow */
5850 if ((state & ButtonState.Inactive)!=0) {
5851 /* Move away from the shadow */
5852 arrow[0].X += 1; arrow[0].Y += 1;
5853 arrow[1].X += 1; arrow[1].Y += 1;
5854 arrow[2].X += 1; arrow[2].Y += 1;
5856 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
5862 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
5864 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
5869 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
5871 Pen pen = Pens.Black;
5872 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
5876 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
5877 graphics.DrawRectangle (pen, rect);
5879 X = rect.X + rect.Width / 2;
5880 Y = rect.Y + rect.Height / 2;
5882 /* Draw the cross */
5883 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
5884 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
5886 /* Draw 'arrows' for vertical lines */
5887 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
5888 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
5890 /* Draw 'arrows' for horizontal lines */
5891 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
5892 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
5895 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
5896 // make a rectange to trace around border of the button
5897 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
5899 Color outerColor = foreColor;
5900 // adjust focus color according to the flatstyle
5901 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
5902 outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;
5905 // draw the outer rectangle
5906 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
5908 // draw the inner rectangle
5909 if (button.FlatStyle == FlatStyle.Popup) {
5910 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
5912 // draw a flat inner rectangle
5913 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
5914 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
5918 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
5920 // make a rectange to trace around border of the button
5921 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
5923 #if NotUntilCairoIsFixed
5924 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
5925 DashStyle oldStyle; // used for caching old penstyle
5926 Pen pen = ResPool.GetPen (colorBackInverted);
5928 oldStyle = pen.DashStyle;
5929 pen.DashStyle = DashStyle.Dot;
5931 graphics.DrawRectangle (pen, trace_rectangle);
5932 pen.DashStyle = oldStyle;
5934 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
5939 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
5941 Rectangle rect = rectangle;
5945 if (backColor.GetBrightness () >= 0.5) {
5946 foreColor = Color.Transparent;
5947 backColor = Color.Black;
5950 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
5951 foreColor = Color.Black;
5954 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
5955 pen = new Pen (brush, 1);
5960 graphics.DrawRectangle (pen, rect);
5964 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
5969 if (primary == true) {
5971 if (enabled == true) {
5974 sb = SystemBrushes.Control;
5978 if (enabled == true) {
5981 sb = SystemBrushes.Control;
5984 graphics.FillRectangle (sb, rectangle);
5985 graphics.DrawRectangle (pen, rectangle);
5989 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
5995 ControlPaint.Color2HBS(backColor, out h, out b, out s);
5998 foreColor=Color.Black;
6000 foreColor=Color.White;
6003 // still not perfect. it seems that ms calculates the position of the first dot or line
6005 using (Pen pen = new Pen (foreColor)) {
6006 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
6008 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
6009 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
6013 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
6015 Microsoft seems to ignore the background and simply make
6016 the image grayscale. At least when having > 256 colors on
6020 if (imagedisabled_attributes == null) {
6021 imagedisabled_attributes = new ImageAttributes ();
6022 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
6023 // This table would create a perfect grayscale image, based on luminance
6024 // new float[]{0.3f,0.3f,0.3f,0,0},
6025 // new float[]{0.59f,0.59f,0.59f,0,0},
6026 // new float[]{0.11f,0.11f,0.11f,0,0},
6027 // new float[]{0,0,0,1,0,0},
6028 // new float[]{0,0,0,0,1,0},
6029 // new float[]{0,0,0,0,0,1}
6031 // This table generates a image that is grayscaled and then
6032 // brightened up. Seems to match MS close enough.
6033 new float[]{0.2f,0.2f,0.2f,0,0},
6034 new float[]{0.41f,0.41f,0.41f,0,0},
6035 new float[]{0.11f,0.11f,0.11f,0,0},
6036 new float[]{0.15f,0.15f,0.15f,1,0,0},
6037 new float[]{0.15f,0.15f,0.15f,0,1,0},
6038 new float[]{0.15f,0.15f,0.15f,0,0,1}
6041 imagedisabled_attributes.SetColorMatrix (colorMatrix);
6044 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
6049 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
6054 penBorder = ResPool.GetSizedPen (Color.White, 2);
6055 penInside = ResPool.GetPen (Color.Black);
6057 penBorder = ResPool.GetSizedPen (Color.Black, 2);
6058 penInside = ResPool.GetPen (Color.White);
6060 penBorder.Alignment=PenAlignment.Inset;
6061 penInside.Alignment=PenAlignment.Inset;
6063 graphics.DrawRectangle(penBorder, rectangle);
6064 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
6068 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
6072 Brush brush = ResPool.GetSolidBrush (color);
6075 case MenuGlyph.Arrow: {
6076 float height = rectangle.Height * 0.7f;
6077 float width = height / 2.0f;
6079 PointF ddCenter = new PointF (rectangle.X + ((rectangle.Width-width) / 2.0f), rectangle.Y + (rectangle.Height / 2.0f));
6081 PointF [] vertices = new PointF [3];
6082 vertices [0].X = ddCenter.X;
6083 vertices [0].Y = ddCenter.Y - (height / 2.0f);
6084 vertices [1].X = ddCenter.X;
6085 vertices [1].Y = ddCenter.Y + (height / 2.0f);
6086 vertices [2].X = ddCenter.X + width + 0.1f;
6087 vertices [2].Y = ddCenter.Y;
6089 graphics.FillPolygon (brush, vertices);
6094 case MenuGlyph.Bullet: {
6096 lineWidth=Math.Max(2, rectangle.Width/3);
6097 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
6099 graphics.FillEllipse(brush, rect);
6104 case MenuGlyph.Checkmark: {
6106 Pen pen = ResPool.GetPen (color);
6107 lineWidth = Math.Max (2, rectangle.Width / 6);
6108 rect = new Rectangle(rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height- lineWidth * 2);
6110 int Scale = Math.Max (1, rectangle.Width / 12);
6111 int top = (rect.Y + lineWidth + ((rect.Height - ((2 * Scale) + lineWidth)) / 2));
6113 for (int i=0; i<lineWidth; i++) {
6114 graphics.DrawLine (pen, rect.Left+lineWidth/2, top+i, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i);
6115 graphics.DrawLine (pen, rect.Left+lineWidth/2+2*Scale, top+2*Scale+i, rect.Left+lineWidth/2+6*Scale, top-2*Scale+i);
6123 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
6125 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
6127 Color dot_color = Color.Black;
6129 Color top_left_outer = Color.Black;
6130 Color top_left_inner = Color.Black;
6131 Color bottom_right_outer = Color.Black;
6132 Color bottom_right_inner = Color.Black;
6134 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
6135 int radius = ellipse_diameter / 2;
6137 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
6141 if ((state & ButtonState.All) == ButtonState.All) {
6142 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255),
6143 ColorControl.G, ColorControl.B), ColorControl);
6144 dot_color = cpcolor.Dark;
6146 if ((state & ButtonState.Flat) == ButtonState.Flat) {
6147 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
6148 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
6150 brush = SystemBrushes.ControlLightLight;
6152 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
6153 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (Clamp (ColorControl.R + 3, 0, 255), ColorControl.G, ColorControl.B), ColorControl);
6155 brush = SystemBrushes.ControlLightLight;
6157 top_left_outer = cpcolor.Dark;
6158 top_left_inner = cpcolor.DarkDark;
6159 bottom_right_outer = cpcolor.Light;
6160 bottom_right_inner = Color.Transparent;
6162 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
6163 dot_color = cpcolor.Dark;
6166 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
6168 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
6170 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
6171 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
6172 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
6174 if (bottom_right_inner != Color.Transparent)
6175 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
6177 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)) {
6178 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
6181 if ((state & ButtonState.Checked) == ButtonState.Checked) {
6182 int inflate = line_width * 4;
6183 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
6184 if (rectangle.Height > 13) {
6188 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
6190 Pen pen = ResPool.GetPen (dot_color);
6191 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
6192 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
6194 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
6195 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
6200 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
6205 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
6210 /* Scroll button: regular button + direction arrow */
6211 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
6213 DrawScrollButtonPrimitive (dc, area, state);
6215 bool fill_rect = true;
6218 if ((state & ButtonState.Pushed) != 0)
6222 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
6224 Point [] arrow = new Point [3];
6225 for (int i = 0; i < 3; i++)
6226 arrow [i] = new Point ();
6228 Pen pen = SystemPens.ControlText;
6230 if ((state & ButtonState.Inactive) != 0) {
6231 pen = SystemPens.ControlDark;
6236 case ScrollButton.Down:
6237 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
6238 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
6242 int triangle_height;
6244 if (rect.Height < 8) {
6245 triangle_height = 2;
6247 } else if (rect.Height == 11) {
6248 triangle_height = 3;
6250 triangle_height = (int)Math.Round (rect.Height / 3.0f);
6253 arrow [0].X = rect.X + x_middle;
6254 arrow [0].Y = rect.Y + y_middle + triangle_height / 2;
6256 arrow [1].X = arrow [0].X + triangle_height - 1;
6257 arrow [1].Y = arrow [0].Y - triangle_height + 1;
6258 arrow [2].X = arrow [0].X - triangle_height + 1;
6259 arrow [2].Y = arrow [1].Y;
6261 dc.DrawPolygon (pen, arrow);
6263 if ((state & ButtonState.Inactive) != 0) {
6264 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
6265 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
6269 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
6270 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
6277 case ScrollButton.Up:
6278 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
6279 y_middle = (int)Math.Round (rect.Height / 2.0f);
6286 if (rect.Height < 8) {
6287 triangle_height = 2;
6289 } else if (rect.Height == 11) {
6290 triangle_height = 3;
6292 triangle_height = (int)Math.Round (rect.Height / 3.0f);
6295 arrow [0].X = rect.X + x_middle;
6296 arrow [0].Y = rect.Y + y_middle - triangle_height / 2;
6298 arrow [1].X = arrow [0].X + triangle_height - 1;
6299 arrow [1].Y = arrow [0].Y + triangle_height - 1;
6300 arrow [2].X = arrow [0].X - triangle_height + 1;
6301 arrow [2].Y = arrow [1].Y;
6303 dc.DrawPolygon (pen, arrow);
6305 if ((state & ButtonState.Inactive) != 0) {
6306 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
6310 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
6311 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
6318 case ScrollButton.Left:
6319 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
6325 if (rect.Width < 8) {
6328 } else if (rect.Width == 11) {
6331 triangle_width = (int)Math.Round (rect.Width / 3.0f);
6334 arrow [0].X = rect.Left + triangle_width - 1;
6335 arrow [0].Y = rect.Y + y_middle;
6337 if (arrow [0].X - 1 == rect.X)
6340 arrow [1].X = arrow [0].X + triangle_width - 1;
6341 arrow [1].Y = arrow [0].Y - triangle_width + 1;
6342 arrow [2].X = arrow [1].X;
6343 arrow [2].Y = arrow [0].Y + triangle_width - 1;
6345 dc.DrawPolygon (pen, arrow);
6347 if ((state & ButtonState.Inactive) != 0) {
6348 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
6352 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
6353 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
6360 case ScrollButton.Right:
6361 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
6365 if (rect.Width < 8) {
6368 } else if (rect.Width == 11) {
6371 triangle_width = (int)Math.Round (rect.Width / 3.0f);
6374 arrow [0].X = rect.Right - triangle_width - 1;
6375 arrow [0].Y = rect.Y + y_middle;
6377 if (arrow [0].X - 1 == rect.X)
6380 arrow [1].X = arrow [0].X - triangle_width + 1;
6381 arrow [1].Y = arrow [0].Y - triangle_width + 1;
6382 arrow [2].X = arrow [1].X;
6383 arrow [2].Y = arrow [0].Y + triangle_width - 1;
6385 dc.DrawPolygon (pen, arrow);
6387 if ((state & ButtonState.Inactive) != 0) {
6388 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
6389 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
6393 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
6394 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
6403 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
6409 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
6411 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
6412 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
6414 for (int i = 2; i < bounds.Width - 2; i += 4) {
6415 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
6416 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
6417 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
6421 private void DrawStringDisabled20 (Graphics g, string s, Font font, Rectangle layoutRectangle, Color color, TextFormatFlags flags, bool useDrawString)
6423 CPColor cpcolor = ResPool.GetCPColor (color);
6425 layoutRectangle.Offset (1, 1);
6426 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.LightLight, flags, useDrawString);
6428 layoutRectangle.Offset (-1, -1);
6429 TextRenderer.DrawTextInternal (g, s, font, layoutRectangle, cpcolor.Dark, flags, useDrawString);
6432 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
6434 CPColor cpcolor = ResPool.GetCPColor (color);
6436 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
6437 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
6439 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
6442 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
6443 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
6448 case ButtonBorderStyle.Solid:
6449 case ButtonBorderStyle.Inset:
6450 case ButtonBorderStyle.Outset:
6451 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
6453 case ButtonBorderStyle.Dashed:
6454 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
6456 case ButtonBorderStyle.Dotted:
6457 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
6460 case ButtonBorderStyle.None:
6465 case ButtonBorderStyle.Outset: {
6467 int hue, brightness, saturation;
6468 int brightnessSteps;
6469 int brightnessDownSteps;
6471 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
6473 brightnessDownSteps=brightness/width;
6474 if (brightness>127) {
6475 brightnessSteps=Math.Max(6, (160-brightness)/width);
6477 brightnessSteps=(127-brightness)/width;
6480 for (int i=0; i<width; i++) {
6482 case Border3DSide.Left: {
6483 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
6484 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6485 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
6489 case Border3DSide.Right: {
6490 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
6491 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6492 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
6496 case Border3DSide.Top: {
6497 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
6498 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6499 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
6503 case Border3DSide.Bottom: {
6504 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
6505 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6506 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
6514 case ButtonBorderStyle.Inset: {
6516 int hue, brightness, saturation;
6517 int brightnessSteps;
6518 int brightnessDownSteps;
6520 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
6522 brightnessDownSteps=brightness/width;
6523 if (brightness>127) {
6524 brightnessSteps=Math.Max(6, (160-brightness)/width);
6526 brightnessSteps=(127-brightness)/width;
6529 for (int i=0; i<width; i++) {
6531 case Border3DSide.Left: {
6532 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
6533 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6534 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
6538 case Border3DSide.Right: {
6539 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
6540 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6541 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
6545 case Border3DSide.Top: {
6546 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
6547 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6548 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
6552 case Border3DSide.Bottom: {
6553 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
6554 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
6555 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
6564 I decided to have the for-loop duplicated for speed reasons;
6565 that way we only have to switch once (as opposed to have the
6566 for-loop around the switch)
6570 case Border3DSide.Left: {
6571 for (int i=0; i<width; i++) {
6572 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
6577 case Border3DSide.Right: {
6578 for (int i=0; i<width; i++) {
6579 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
6584 case Border3DSide.Top: {
6585 for (int i=0; i<width; i++) {
6586 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
6591 case Border3DSide.Bottom: {
6592 for (int i=0; i<width; i++) {
6593 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
6604 This function actually draws the various caption elements.
6605 This way we can scale them nicely, no matter what size, and they
6606 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
6609 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
6611 case CaptionButton.Close: {
6613 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);
6614 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);
6617 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
6618 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
6622 case CaptionButton.Help: {
6623 StringFormat sf = new StringFormat();
6624 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
6626 sf.Alignment=StringAlignment.Center;
6627 sf.LineAlignment=StringAlignment.Center;
6630 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
6638 case CaptionButton.Maximize: {
6639 /* Top 'caption bar' line */
6640 for (int i=0; i<Math.Max(2, lineWidth); i++) {
6641 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);
6644 /* Left side line */
6645 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6646 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
6649 /* Right side line */
6650 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6651 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);
6655 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6656 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
6661 case CaptionButton.Minimize: {
6663 for (int i=0; i<Math.Max(2, lineWidth); i++) {
6664 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
6669 case CaptionButton.Restore: {
6670 /** First 'window' **/
6671 /* Top 'caption bar' line */
6672 for (int i=0; i<Math.Max(2, lineWidth); i++) {
6673 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);
6676 /* Left side line */
6677 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6678 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);
6681 /* Right side line */
6682 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6683 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);
6687 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6688 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);
6691 /** Second 'window' **/
6692 /* Top 'caption bar' line */
6693 for (int i=0; i<Math.Max(2, lineWidth); i++) {
6694 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);
6697 /* Left side line */
6698 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6699 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
6702 /* Right side line */
6703 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6704 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);
6708 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
6709 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
6718 /* Generic scroll button */
6719 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
6720 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
6721 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
6722 area.Y + 1, area.Width - 2 , area.Height - 2);
6724 dc.DrawRectangle (SystemPens.ControlDark, area.X,
6725 area.Y, area.Width, area.Height);
6730 Brush sb_control = SystemBrushes.Control;
6731 Brush sb_lightlight = SystemBrushes.ControlLightLight;
6732 Brush sb_dark = SystemBrushes.ControlDark;
6733 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
6735 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
6736 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
6738 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
6739 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
6742 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
6745 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
6748 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
6749 area.Y + 1, 1, area.Height -3);
6751 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
6752 area.Y, 1, area.Height - 1);
6754 dc.FillRectangle (sb_control, area.X + 2,
6755 area.Y + 2, area.Width - 4, area.Height - 4);
6759 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
6760 switch (border_style){
6761 case BorderStyle.Fixed3D:
6762 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
6763 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
6764 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
6765 area.Y + area.Height - 1);
6766 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
6767 area.Y + area.Height);
6769 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
6770 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
6771 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
6772 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
6774 case BorderStyle.FixedSingle:
6775 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
6777 case BorderStyle.None:
6783 #endregion // ControlPaint