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
32 using System.Drawing.Drawing2D;
33 using System.Drawing.Imaging;
34 using System.Drawing.Text;
36 namespace System.Windows.Forms
39 internal class ThemeWin32Classic : Theme
41 public override Version Version {
43 return new Version(0, 1, 0, 0);
47 /* Hardcoded colour values not exposed in the API constants in all configurations */
48 protected static readonly Color arrow_color = Color.Black;
49 protected static readonly Color pen_ticks_color = Color.Black;
50 protected static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
51 protected static StringFormat string_format_menu_text;
52 protected static StringFormat string_format_menu_shortcut;
53 protected static StringFormat string_format_menu_menubar_text;
54 static readonly Rectangle checkbox_rect = new Rectangle (2, 2, 11,11); // Position of the checkbox relative to the item
55 static ImageAttributes imagedisabled_attributes = null;
56 const int SEPARATOR_HEIGHT = 5;
57 const int SM_CXBORDER = 1;
58 const int SM_CYBORDER = 1;
59 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
60 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
62 #region Principal Theme Methods
63 public ThemeWin32Classic ()
65 defaultWindowBackColor = this.ColorWindow;
66 defaultWindowForeColor = this.ColorControlText;
67 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
69 /* Menu string formats */
70 string_format_menu_text = new StringFormat ();
71 string_format_menu_text.LineAlignment = StringAlignment.Center;
72 string_format_menu_text.Alignment = StringAlignment.Near;
73 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
75 string_format_menu_shortcut = new StringFormat ();
76 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
77 string_format_menu_shortcut.Alignment = StringAlignment.Far;
79 string_format_menu_menubar_text = new StringFormat ();
80 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
81 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
82 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
83 always_draw_hotkeys = false;
86 public override void ResetDefaults() {
87 throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
90 public override bool DoubleBufferingSupported {
93 #endregion // Principal Theme Methods
95 #region Internal Methods
96 protected SolidBrush GetControlBackBrush (Color c) {
97 if (c == DefaultControlBackColor)
98 return ResPool.GetSolidBrush (ColorControl);
99 return ResPool.GetSolidBrush (c);
102 protected SolidBrush GetControlForeBrush (Color c) {
103 if (c == DefaultControlForeColor)
104 return ResPool.GetSolidBrush (ColorControlText);
105 return ResPool.GetSolidBrush (c);
107 #endregion // Internal Methods
109 #region OwnerDraw Support
110 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
112 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
113 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
117 e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
120 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
122 if (e.State == DrawItemState.Focus)
123 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
125 #endregion // OwnerDraw Support
128 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
129 // Draw the button: fill rectangle, draw border, etc.
130 ButtonBase_DrawButton(button, dc);
132 // First, draw the image
133 if ((button.image != null) || (button.image_list != null))
134 ButtonBase_DrawImage(button, dc);
136 // Draw the focus rectangle
137 if ((button.has_focus || button.paint_as_acceptbutton) && button.is_enabled)
138 ButtonBase_DrawFocus(button, dc);
141 if (button.text != null && button.text != String.Empty)
142 ButtonBase_DrawText(button, dc);
145 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
147 Rectangle borderRectangle;
148 bool check_or_radio = false;
149 bool check_or_radio_checked = false;
151 CPColor cpcolor = ResPool.GetCPColor (button.BackColor);
153 dc.FillRectangle (ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
155 if (button is CheckBox) {
156 check_or_radio = true;
157 check_or_radio_checked = ((CheckBox)button).Checked;
158 } else if (button is RadioButton) {
159 check_or_radio = true;
160 check_or_radio_checked = ((RadioButton)button).Checked;
163 if ((button.has_focus || button.paint_as_acceptbutton) && button.is_enabled && !check_or_radio) {
164 // shrink the rectangle for the normal button drawing inside the focus rectangle
165 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
167 borderRectangle = button.ClientRectangle;
170 if (button.FlatStyle == FlatStyle.Popup) {
171 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
172 Internal_DrawButton (dc, borderRectangle, 1, cpcolor);
173 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
174 Internal_DrawButton (dc, borderRectangle, 2, cpcolor);
175 else if (button.is_pressed || check_or_radio_checked)
176 Internal_DrawButton (dc, borderRectangle, 1, cpcolor);
177 } else if (button.FlatStyle == FlatStyle.Flat) {
178 if (button.is_entered && !button.is_pressed && !check_or_radio_checked)
179 dc.FillRectangle (ResPool.GetSolidBrush (cpcolor.Dark), borderRectangle);
180 else if (button.is_pressed || check_or_radio_checked) {
181 dc.FillRectangle (ResPool.GetSolidBrush (cpcolor.Light), borderRectangle);
183 dc.DrawRectangle (ResPool.GetPen (cpcolor.Dark), borderRectangle.X + 4, borderRectangle.Y + 4,
184 borderRectangle.Width - 9, borderRectangle.Height - 9);
187 Internal_DrawButton (dc, borderRectangle, 3, cpcolor);
189 if ((!button.is_pressed || !button.is_enabled) && !check_or_radio_checked)
190 Internal_DrawButton (dc, borderRectangle, 0, cpcolor);
192 Internal_DrawButton (dc, borderRectangle, 1, cpcolor);
196 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor)
199 case 0: // normal or normal disabled button
200 Pen pen = ResPool.GetPen (cpcolor.Light);
201 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
202 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
204 pen = ResPool.GetPen (cpcolor.Dark);
205 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
206 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
208 pen = ResPool.GetPen (cpcolor.DarkDark);
209 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
210 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
212 case 1: // popup button normal (or pressed normal or popup button)
213 pen = ResPool.GetPen (cpcolor.Dark);
214 dc.DrawRectangle (pen, new Rectangle (rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
216 case 2: // popup button poped up
217 pen = ResPool.GetPen (cpcolor.Light);
218 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
219 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
221 pen = ResPool.GetPen (cpcolor.Dark);
222 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
223 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
225 case 3: // flat button not entered
226 pen = ResPool.GetPen (cpcolor.DarkDark);
227 dc.DrawRectangle (pen, new Rectangle (rect.X, rect.Y, rect.Width - 1, rect.Height - 1));
234 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
236 // Need to draw a picture
243 int width = button.ClientSize.Width;
244 int height = button.ClientSize.Height;
246 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
247 i = button.image_list.Images[button.image_index];
252 image_width = button.image.Width;
253 image_height = button.image.Height;
255 switch (button.image_alignment) {
256 case ContentAlignment.TopLeft: {
262 case ContentAlignment.TopCenter: {
263 image_x=(width-image_width)/2;
268 case ContentAlignment.TopRight: {
269 image_x=width-image_width;
274 case ContentAlignment.MiddleLeft: {
276 image_y=(height-image_height)/2;
280 case ContentAlignment.MiddleCenter: {
281 image_x=(width-image_width)/2;
282 image_y=(height-image_height)/2;
286 case ContentAlignment.MiddleRight: {
287 image_x=width-image_width;
288 image_y=(height-image_height)/2;
292 case ContentAlignment.BottomLeft: {
294 image_y=height-image_height;
298 case ContentAlignment.BottomCenter: {
299 image_x=(width-image_width)/2;
300 image_y=height-image_height;
304 case ContentAlignment.BottomRight: {
305 image_x=width-image_width;
306 image_y=height-image_height;
317 if (button.is_pressed) {
322 if (button.is_enabled) {
323 dc.DrawImage(i, image_x, image_y);
326 CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
330 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
332 Color focus_color = button.ForeColor;
334 if (button.FlatStyle == FlatStyle.Popup)
335 if (!button.is_pressed)
336 focus_color = ControlPaint.Dark(button.BackColor);
338 dc.DrawRectangle (ResPool.GetPen (focus_color), new Rectangle (button.ClientRectangle.X, button.ClientRectangle.Y,
339 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1));
342 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
344 Rectangle buttonRectangle = button.ClientRectangle;
345 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
347 if (button.is_pressed) {
352 if (button.is_enabled) {
353 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
355 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
356 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
358 Rectangle rect_white = new Rectangle (text_rect.X + 1, text_rect.Y + 1, text_rect.Width, text_rect.Height);
360 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorControlLightLight), rect_white, button.text_format);
361 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
366 // FIXME: Not needed anymore. Will be removed when the other themes are updated
367 // draw the flat style part of the rectangle
368 public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
369 Color rect_back_color = button.BackColor;
370 Color rect_fore_color = button.ForeColor;
371 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
373 if (button.Enabled) {
374 if (button.Capture || button.is_entered) {
375 if (button.FlatStyle == FlatStyle.Flat) {
376 // fill the rectangle
377 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
379 // now draw the outer border
380 if (button.Capture && button.is_entered) {
381 rect_back_color = ControlPaint.LightLight (rect_back_color);
383 rect_back_color = ControlPaint.Light (rect_back_color);
386 // draw rectangle and fill it
387 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
388 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
390 // else it must be a popup button
392 if (button.Capture && button.is_entered) {
393 graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
396 CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor);
397 graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
398 graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
402 // TODO: draw inner focus rectangle
405 // popup has a ButtonColorText forecolor, not a button.ForeCOlor
406 if (button.FlatStyle == FlatStyle.Popup) {
407 rect_fore_color = ColorGrayText;
410 // fill then draw outer rect
411 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
412 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
415 // finally some small tweaks to render radiobutton and checkbox
416 CheckBox checkbox = button as CheckBox;
417 RadioButton radiobutton = button as RadioButton;
418 if ((checkbox != null && checkbox.Checked) ||
419 (radiobutton != null && radiobutton.Checked)) {
420 if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
421 // render the hover for flat flatstyle and cheked
422 graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
423 } else if (!button.is_entered && !button.Capture) {
424 // render the checked state for popup when unhovered
425 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
429 // rendering checkbox or radio button style buttons
430 CheckBox checkbox = button as CheckBox;
431 RadioButton radiobutton = button as RadioButton;
432 bool draw_popup_checked = false;
434 if (button.FlatStyle == FlatStyle.Popup) {
435 rect_fore_color = ColorGrayText;
437 // see if we should draw a disabled checked popup button
438 draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
439 (radiobutton != null && radiobutton.Checked));
442 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
443 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
445 // finally draw the flatstyle checked effect if need
446 if (draw_popup_checked) {
447 // render the checked state for popup when unhovered
448 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
453 public override Size ButtonBaseDefaultSize {
455 return new Size (75, 23);
458 #endregion // ButtonBase
461 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
462 StringFormat text_format;
463 Rectangle client_rectangle;
464 Rectangle text_rectangle;
465 Rectangle checkbox_rectangle;
466 int checkmark_size=13;
467 int checkmark_space = 4;
469 client_rectangle = checkbox.ClientRectangle;
470 text_rectangle = client_rectangle;
471 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
473 text_format = new StringFormat();
474 text_format.Alignment=StringAlignment.Near;
475 text_format.LineAlignment=StringAlignment.Center;
476 text_format.HotkeyPrefix = HotkeyPrefix.Show;
478 /* Calculate the position of text and checkbox rectangle */
479 if (checkbox.appearance!=Appearance.Button) {
480 switch(checkbox.check_alignment) {
481 case ContentAlignment.BottomCenter: {
482 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
483 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
484 text_rectangle.X=client_rectangle.X;
485 text_rectangle.Width=client_rectangle.Width;
486 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
490 case ContentAlignment.BottomLeft: {
491 checkbox_rectangle.X=client_rectangle.Left;
492 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
493 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
494 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
498 case ContentAlignment.BottomRight: {
499 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
500 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
501 text_rectangle.X=client_rectangle.X;
502 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
506 case ContentAlignment.MiddleCenter: {
507 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
508 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
509 text_rectangle.X=client_rectangle.X;
510 text_rectangle.Width=client_rectangle.Width;
515 case ContentAlignment.MiddleLeft: {
516 checkbox_rectangle.X=client_rectangle.Left;
517 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
518 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
519 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
523 case ContentAlignment.MiddleRight: {
524 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
525 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
526 text_rectangle.X=client_rectangle.X;
527 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
531 case ContentAlignment.TopCenter: {
532 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
533 checkbox_rectangle.Y=client_rectangle.Top;
534 text_rectangle.X=client_rectangle.X;
535 text_rectangle.Width=client_rectangle.Width;
536 text_rectangle.Y=checkmark_size+checkmark_space;
537 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
541 case ContentAlignment.TopLeft: {
542 checkbox_rectangle.X=client_rectangle.Left;
543 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
544 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
548 case ContentAlignment.TopRight: {
549 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
550 text_rectangle.X=client_rectangle.X;
551 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
556 text_rectangle.X=client_rectangle.X;
557 text_rectangle.Width=client_rectangle.Width;
560 /* Set the horizontal alignment of our text */
561 switch(checkbox.text_alignment) {
562 case ContentAlignment.BottomLeft:
563 case ContentAlignment.MiddleLeft:
564 case ContentAlignment.TopLeft: {
565 text_format.Alignment=StringAlignment.Near;
569 case ContentAlignment.BottomCenter:
570 case ContentAlignment.MiddleCenter:
571 case ContentAlignment.TopCenter: {
572 text_format.Alignment=StringAlignment.Center;
576 case ContentAlignment.BottomRight:
577 case ContentAlignment.MiddleRight:
578 case ContentAlignment.TopRight: {
579 text_format.Alignment=StringAlignment.Far;
584 /* Set the vertical alignment of our text */
585 switch(checkbox.text_alignment) {
586 case ContentAlignment.TopLeft:
587 case ContentAlignment.TopCenter:
588 case ContentAlignment.TopRight: {
589 text_format.LineAlignment=StringAlignment.Near;
593 case ContentAlignment.BottomLeft:
594 case ContentAlignment.BottomCenter:
595 case ContentAlignment.BottomRight: {
596 text_format.LineAlignment=StringAlignment.Far;
600 case ContentAlignment.MiddleLeft:
601 case ContentAlignment.MiddleCenter:
602 case ContentAlignment.MiddleRight: {
603 text_format.LineAlignment=StringAlignment.Center;
608 ButtonState state = ButtonState.Normal;
609 if (checkbox.FlatStyle == FlatStyle.Flat) {
610 state |= ButtonState.Flat;
613 if (checkbox.Checked) {
614 state |= ButtonState.Checked;
617 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
618 state |= ButtonState.Checked;
619 state |= ButtonState.Pushed;
622 // FIXME: can be removed when other themes are updated ->
623 // finally make sure the pushed and inavtive states are rendered
624 if (!checkbox.Enabled) {
625 state |= ButtonState.Inactive;
627 else if (checkbox.is_pressed) {
628 state |= ButtonState.Pushed;
634 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
636 if ((checkbox.image != null) || (checkbox.image_list != null))
637 ButtonBase_DrawImage(checkbox, dc);
639 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
641 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
643 text_format.Dispose ();
646 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
648 dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);
649 // render as per normal button
650 if (checkbox.appearance==Appearance.Button) {
651 ButtonBase_DrawButton (checkbox, dc);
653 // establish if we are rendering a flat style of some sort
654 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
655 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
657 DrawNormalCheckBox (dc, checkbox_rectangle, checkbox);
662 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
664 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
665 text_format, checkbox.Appearance, checkbox.Checked);
668 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
670 // do nothing here. maybe an other theme needs it
673 protected virtual void DrawNormalCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
680 /* Goes first, affects the background */
681 if (checkbox.is_pressed || !checkbox.is_enabled) {
682 graphics.FillRectangle(SystemBrushes.Control, rectangle);
684 graphics.FillRectangle(SystemBrushes.Window, rectangle);
687 /* Draw the sunken frame */
688 if (checkbox.FlatStyle == FlatStyle.Flat) {
689 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
691 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
694 /* Make sure we've got at least a line width of 1 */
695 lineWidth=Math.Max(3, rectangle.Width/6);
696 Scale=Math.Max(1, rectangle.Width/12);
698 // define a rectangle inside the border area
699 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
700 if (!checkbox.is_enabled) {
701 pen=SystemPens.ControlDark;
703 pen=SystemPens.ControlText;
706 if (checkbox.Checked) {
707 /* Need to draw a check-mark */
708 for (int i=0; i<lineWidth; i++) {
709 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
710 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);
715 // renders a checkBox with the Flat and Popup FlatStyle
716 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
720 Rectangle checkbox_rectangle;
721 Rectangle fill_rectangle;
725 // set up our rectangles first
726 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
727 // clip one pixel from bottom right for non popup rendered checkboxes
728 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
729 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));
731 // clip two pixels from bottom right for non popup rendered checkboxes
732 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
733 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));
736 // if disabled render in disabled state
737 if (checkbox.Enabled) {
738 // process the state of the checkbox
739 if (checkbox.is_entered || checkbox.Capture) {
740 // decide on which background color to use
741 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
742 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
743 } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
744 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
746 // use regular window background color
747 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
750 // render the outer border
751 if (checkbox.FlatStyle == FlatStyle.Flat) {
752 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
754 // draw sunken effect
755 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
758 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
760 if (checkbox.FlatStyle == FlatStyle.Flat) {
761 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
763 // draw the outer border
764 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
768 if (checkbox.FlatStyle == FlatStyle.Popup) {
769 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
772 // draw disabled state,
773 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
776 /* Make sure we've got at least a line width of 1 */
777 lineWidth = Math.Max(3, fill_rectangle.Width/3);
778 Scale=Math.Max(1, fill_rectangle.Width/9);
780 // flat style check box is rendered inside a rectangle shifted down by one
781 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
782 if (checkbox.Enabled) {
783 pen=ResPool.GetPen(checkbox.ForeColor);
785 pen=SystemPens.ControlDark;
788 if (checkbox.Checked) {
789 /* Need to draw a check-mark */
790 for (int i=0; i<lineWidth; i++) {
791 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
792 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);
797 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
798 StringFormat text_format, Appearance appearance, bool ischecked)
800 // offset the text if it's pressed and a button
801 if (appearance == Appearance.Button) {
802 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
807 text_rectangle.Inflate (-4, -4);
810 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
812 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
813 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
814 text_format.FormatFlags |= StringFormatFlags.NoWrap;
816 if (button_base.Enabled) {
817 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
818 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
819 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
821 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, ColorControlText, text_rectangle, text_format);
824 #endregion // CheckBox
826 #region CheckedListBox
828 public override Rectangle CheckedListBoxCheckRectangle ()
830 return checkbox_rect;
833 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
835 Color back_color, fore_color;
836 Rectangle item_rect = e.Bounds;
838 StringFormat string_format = ctrl.GetFormatString ();
842 if ((ctrl.Items.GetListBoxItem (e.Index)).State == CheckState.Checked)
843 state = ButtonState.Checked;
845 state = ButtonState.Normal;
847 if (ctrl.ThreeDCheckBoxes == false)
848 state |= ButtonState.Flat;
850 ControlPaint.DrawCheckBox (e.Graphics,
851 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
852 checkbox_rect.Width, checkbox_rect.Height,
855 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
856 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
859 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
860 back_color = ColorHighlight;
861 fore_color = ColorHighlightText;
864 back_color = e.BackColor;
865 fore_color = e.ForeColor;
868 e.Graphics.FillRectangle (ResPool.GetSolidBrush
869 (back_color), item_rect);
871 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
872 ResPool.GetSolidBrush (fore_color),
873 item_rect, string_format);
875 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
876 CPDrawFocusRectangle (e.Graphics, item_rect,
877 fore_color, back_color);
881 #endregion // CheckedListBox
886 // TODO: get rid of that and use BorderStyle Fixed3D
887 public override void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
889 dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
890 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
891 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
892 dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
893 dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
894 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
895 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 1, cl.Y, cl.X + cl.Width - 1, cl.Y + cl.Height); //right
896 dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X + cl.Width - 2, cl.Y + 1 , cl.X + cl.Width - 2, cl.Y + cl.Height - 1);
900 public override int DrawComboBoxEditDecorationTop () { return 2;}
901 public override int DrawComboBoxEditDecorationBottom () { return 2;}
902 public override int DrawComboBoxEditDecorationRight () { return 2;}
903 public override int DrawComboBoxEditDecorationLeft () { return 2;}
905 private int DrawComboListBoxDecoration (ComboBoxStyle style)
907 if (style == ComboBoxStyle.Simple)
913 public override int DrawComboListBoxDecorationTop (ComboBoxStyle style)
915 return DrawComboListBoxDecoration (style);
918 public override int DrawComboListBoxDecorationBottom (ComboBoxStyle style)
920 return DrawComboListBoxDecoration (style);
923 public override int DrawComboListBoxDecorationRight (ComboBoxStyle style)
925 return DrawComboListBoxDecoration (style);
928 public override int DrawComboListBoxDecorationLeft (ComboBoxStyle style)
930 return DrawComboListBoxDecoration (style);
933 public override void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
935 if (ctrl.DropDownStyle == ComboBoxStyle.Simple) {
936 DrawComboBoxEditDecorations (dc, ctrl, cl);
939 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame),
940 cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
944 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
946 Color back_color, fore_color;
947 Rectangle text_draw = e.Bounds;
948 StringFormat string_format = new StringFormat ();
949 string_format.FormatFlags = StringFormatFlags.LineLimit;
951 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
952 back_color = ColorHighlight;
953 fore_color = ColorHighlightText;
956 back_color = e.BackColor;
957 fore_color = e.ForeColor;
960 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
963 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
964 ResPool.GetSolidBrush (fore_color),
965 text_draw, string_format);
968 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
969 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
972 string_format.Dispose ();
978 public override int DataGridPreferredColumnWidth { get { return 75;} }
979 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
980 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
981 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
982 public override Color DataGridBackColor { get { return ColorWindow;} }
983 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
984 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
985 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
986 public override Color DataGridGridLineColor { get { return ColorControl;} }
987 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
988 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
989 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
990 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
991 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
992 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
993 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
994 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
996 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
999 if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
1000 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
1003 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
1004 DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
1005 DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
1006 DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
1008 // Paint scrollBar corner
1009 if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
1011 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
1012 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
1013 grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
1015 if (pe.ClipRectangle.IntersectsWith (corner)) {
1016 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
1022 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
1024 Rectangle modified_area = clip;
1025 modified_area.Intersect (grid.grid_drawing.caption_area);
1027 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
1030 g.DrawString (grid.CaptionText, grid.CaptionFont,
1031 ResPool.GetSolidBrush (grid.CaptionForeColor),
1032 grid.grid_drawing.caption_area);
1035 public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
1037 Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
1039 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
1040 Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
1041 rect_bloc.Width = grid.RowHeaderWidth;
1042 rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
1043 if (clip.IntersectsWith (rect_bloc)) {
1044 if (grid.visiblecolumn_count > 0) {
1045 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
1047 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
1051 columns_area.X += grid.RowHeaderWidth;
1052 columns_area.Width -= grid.RowHeaderWidth;
1056 Rectangle columnshdrs_area_complete = columns_area;
1057 columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
1059 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1060 columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
1063 // Set column painting
1064 Rectangle rect_columnhdr = new Rectangle ();
1066 Region current_clip;
1067 rect_columnhdr.Y = columns_area.Y;
1068 rect_columnhdr.Height = columns_area.Height;
1070 current_clip = new Region (columns_area);
1071 g.Clip = current_clip;
1072 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1073 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1075 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1076 rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
1077 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1079 if (clip.IntersectsWith (rect_columnhdr) == false)
1082 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
1087 current_clip.Dispose ();
1090 Rectangle not_usedarea = columnshdrs_area_complete;
1091 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
1092 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
1093 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1097 public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
1099 Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
1100 rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
1101 Rectangle rect_row = new Rectangle ();
1102 rect_row.X = grid.grid_drawing.rowshdrs_area.X;
1103 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1104 Rectangle not_usedarea = rowshdrs_area_complete;
1106 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1110 g.SetClip (grid.grid_drawing.rowshdrs_area);
1111 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1113 rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
1114 rect_row.Height = grid.RowHeight;
1115 rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1117 if (clip.IntersectsWith (rect_row)) {
1118 DataGridPaintRowHeader (g, rect_row, row, grid);
1123 not_usedarea.Height = grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
1124 not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + grid.grid_drawing.rowshdrs_area.Height;
1125 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1128 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1130 Point[] arrow = new Point[3];
1132 int centerX, centerY, shiftX;
1135 rect = new Rectangle (bounds.X + bounds.Width /4,
1136 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1138 centerX = rect.Left + rect.Width / 2;
1139 centerY = rect.Top + rect.Height / 2;
1140 shiftX = Math.Max (1, rect.Width / 8);
1143 P1 = new Point (centerX, rect.Top - 1);
1144 P2 = new Point (centerX, rect.Bottom);
1145 P3 = new Point (rect.Right, centerY);
1150 g.FillPolygon (ResPool.GetSolidBrush
1151 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1154 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
1157 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
1160 if (grid.FlatMode == false) {
1163 g.DrawLine (ResPool.GetPen (ColorControlLight),
1164 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1166 g.DrawLine (ResPool.GetPen (ColorControlLight),
1167 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1169 g.DrawLine (ResPool.GetPen (ColorControlDark),
1170 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1172 g.DrawLine (ResPool.GetPen (ColorControlDark),
1173 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1176 if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
1178 g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1183 if (row == grid.CurrentCell.RowNumber) {
1185 if (grid.is_changing == true) {
1186 g.DrawString ("...", grid.Font,
1187 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1192 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1193 DataGridPaintRowHeaderArrow (g, rect, grid);
1199 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1201 Rectangle rect_row = new Rectangle ();
1202 Rectangle not_usedarea = new Rectangle ();
1203 rect_row.X = cells.X;
1205 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1207 if (grid.ShowEditRow && grid.RowsCount > 0) {
1211 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1215 rect_row.Height = grid.RowHeight;
1216 rect_row.Width = cells.Width;
1217 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1218 rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1219 if (clip.IntersectsWith (rect_row)) {
1220 DataGridPaintRow (g, row, rect_row, false, grid);
1224 if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
1225 rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
1226 if (clip.IntersectsWith (rect_row)) {
1227 DataGridPaintRow (g, rowcnt, rect_row, true, grid);
1231 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1232 not_usedarea.Y = rect_row.Y + rect_row.Height;
1233 not_usedarea.Width = rect_row.Width = cells.Width;
1234 not_usedarea.X = cells.X;
1236 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1239 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid)
1241 Rectangle rect_cell = new Rectangle ();
1243 Color backcolor, forecolor;
1244 Region prev_clip = g.Clip;
1245 Region current_clip;
1246 Rectangle not_usedarea = new Rectangle ();
1248 rect_cell.Y = row_rect.Y;
1249 rect_cell.Height = row_rect.Height;
1251 // PaintCells at row, column
1252 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1253 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1255 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1257 rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
1258 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1260 current_clip = new Region (row_rect);
1261 g.Clip = current_clip;
1263 if (grid.IsSelected (row)) {
1264 backcolor = grid.SelectionBackColor;
1265 forecolor = grid.SelectionForeColor;
1268 backcolor = grid.BackColor;
1270 backcolor = grid.AlternatingBackColor;
1273 forecolor = grid.ForeColor;
1277 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1278 ResPool.GetSolidBrush (backcolor),
1279 ResPool.GetSolidBrush (forecolor));
1282 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1283 ResPool.GetSolidBrush (backcolor),
1284 ResPool.GetSolidBrush (forecolor),
1285 grid.RightToLeft == RightToLeft.Yes);
1289 current_clip.Dispose ();
1292 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1294 not_usedarea.X = rect_cell.X + rect_cell.Width;
1295 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1296 not_usedarea.Y = row_rect.Y;
1297 not_usedarea.Height = row_rect.Height;
1298 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1303 #endregion // Datagrid
1305 #region DateTimePicker
1307 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1308 // if not showing the numeric updown control then render border
1309 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1310 // draw the outer border
1311 Rectangle button_bounds = dtp.ClientRectangle;
1312 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1314 // deflate by the border width
1315 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1316 button_bounds.Inflate (-2,-2);
1317 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1318 this.CPDrawComboButton (
1320 dtp.drop_down_arrow_rect,
1325 // render the date part
1326 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1327 // fill the background
1328 dc.FillRectangle (ResPool.GetSolidBrush (ColorWindow), dtp.date_area_rect);
1330 // fill the currently highlighted area
1331 if (dtp.hilight_date_area != Rectangle.Empty) {
1332 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), dtp.hilight_date_area);
1335 // draw the text part
1336 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1337 StringFormat text_format = new StringFormat();
1338 text_format.LineAlignment = StringAlignment.Center;
1339 text_format.Alignment = StringAlignment.Near;
1340 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1341 text_format.Dispose ();
1345 #endregion // DateTimePicker
1348 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1349 StringFormat text_format;
1355 rect = box.ClientRectangle;
1357 // Needed once the Dark/Light code below is enabled again
1358 //Color disabled = ColorGrayText;
1360 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
1361 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
1363 // TODO: When the Light and Dark methods work this code should be activate it
1364 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
1365 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
1367 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
1369 text_format = new StringFormat();
1370 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1372 size = dc.MeasureString (box.Text, box.Font);
1373 width = ((int) size.Width) + 7;
1375 if (width > box.Width - 16)
1376 width = box.Width - 16;
1378 y = box.Font.Height / 2;
1381 dc.DrawLine (pen_dark, 0, y, 8, y); // top
1382 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
1383 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
1384 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
1386 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
1387 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
1389 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
1390 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
1392 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
1393 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
1398 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1400 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
1401 new RectangleF (10, 0, width, box.Font.Height), text_format);
1403 text_format.Dispose ();
1406 public override Size GroupBoxDefaultSize {
1408 return new Size (200,100);
1414 public override Size HScrollBarDefaultSize {
1416 return new Size (80, this.ScrollBarButtonSize);
1420 #endregion // HScrollBar
1423 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1425 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
1427 if (label.Enabled) {
1428 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1430 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
1435 public override Size LabelDefaultSize {
1437 return new Size (100, 23);
1443 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1447 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
1449 for (int i = 0; i < label.num_pieces; i++) {
1451 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1455 color = label.GetLinkColor (label.pieces[i], i);
1457 if (label.pieces[i].link == null)
1458 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),
1459 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1461 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
1462 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1464 if (label.pieces[i].focused) {
1465 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1470 #endregion // LinkLabel
1475 private int DrawListBoxDecorationSize (BorderStyle border_style)
1477 switch (border_style) {
1478 case BorderStyle.Fixed3D:
1480 case BorderStyle.FixedSingle:
1482 case BorderStyle.None:
1491 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1493 Color back_color, fore_color;
1494 StringFormat string_format = ctrl.GetFormatString ();
1496 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1497 back_color = ColorHighlight;
1498 fore_color = ColorHighlightText;
1501 back_color = e.BackColor;
1502 fore_color = e.ForeColor;
1505 e.Graphics.FillRectangle (ResPool.GetSolidBrush
1506 (back_color), e.Bounds);
1508 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1509 ResPool.GetSolidBrush (fore_color),
1510 e.Bounds.X, e.Bounds.Y, string_format);
1512 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1513 CPDrawFocusRectangle (e.Graphics, e.Bounds,
1514 fore_color, back_color);
1522 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1524 bool details = control.View == View.Details;
1526 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);
1527 int first = control.FirstVisibleIndex;
1529 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1530 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1531 DrawListViewItem (dc, control, control.Items [i]);
1534 // draw the gridlines
1535 if (details && control.GridLines) {
1536 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1537 2 : control.Font.Height + 2;
1539 // draw vertical gridlines
1540 foreach (ColumnHeader col in control.Columns)
1541 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1542 col.Rect.Right, top,
1543 col.Rect.Right, control.TotalHeight);
1544 // draw horizontal gridlines
1545 ListViewItem last_item = null;
1546 foreach (ListViewItem item in control.Items) {
1547 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1548 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1549 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1553 // draw a line after at the bottom of the last item
1554 if (last_item != null) {
1555 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1556 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1557 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1559 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1565 // Draw corner between the two scrollbars
1566 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1567 Rectangle rect = new Rectangle ();
1568 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1569 rect.Width = control.v_scroll.Width;
1570 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1571 rect.Height = control.h_scroll.Height;
1572 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), rect);
1577 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1579 bool details = (control.View == View.Details);
1581 // border is drawn directly in the Paint method
1582 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1583 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor),
1584 0, 0, control.TotalWidth, control.Font.Height + 5);
1585 if (control.Columns.Count > 0) {
1586 foreach (ColumnHeader col in control.Columns) {
1587 Rectangle rect = col.Rect;
1588 rect.X -= control.h_marker;
1590 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1591 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1593 state = ButtonState.Flat;
1594 this.CPDrawButton (dc, rect, state);
1597 if (rect.Width <= 0)
1599 dc.DrawString (col.Text, DefaultFont,
1600 ResPool.GetSolidBrush (ColorControlText),
1607 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
1609 Rectangle rect = col.Rect;
1610 rect.X -= view.h_marker;
1611 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
1612 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
1615 if (rect.Width <= 0)
1617 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
1618 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
1619 Pen pen = new Pen (ColorHighlight, 2);
1620 dc.DrawLine (pen, target_x, 0, target_x, col.Rect.Height);
1623 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1626 if (control.View == View.Details && control.Columns.Count > 0)
1627 col_offset = control.Columns [0].Rect.X;
1631 Rectangle rect_checkrect = item.CheckRectReal;
1632 rect_checkrect.X += col_offset;
1633 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
1634 icon_rect.X += col_offset;
1635 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1636 full_rect.X += col_offset;
1637 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1638 text_rect.X += col_offset;
1640 if (control.CheckBoxes) {
1641 if (control.StateImageList == null) {
1642 // Make sure we've got at least a line width of 1
1643 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1644 int scale = Math.Max (1, rect_checkrect.Width / 12);
1646 // set the checkbox background
1647 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
1649 // define a rectangle inside the border area
1650 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1651 rect_checkrect.Y + 2,
1652 rect_checkrect.Width - 4,
1653 rect_checkrect.Height - 4);
1654 Pen pen = new Pen (this.ColorWindowText, 2);
1655 dc.DrawRectangle (pen, rect);
1657 // Need to draw a check-mark
1660 // adjustments to get the check-mark at the right place
1661 rect.X ++; rect.Y ++;
1662 // following logic is taken from DrawFrameControl method
1663 for (int i = 0; i < check_wd; i++) {
1664 dc.DrawLine (pen, rect.Left + check_wd / 2,
1665 rect.Top + check_wd + i,
1666 rect.Left + check_wd / 2 + 2 * scale,
1667 rect.Top + check_wd + 2 * scale + i);
1669 rect.Left + check_wd / 2 + 2 * scale,
1670 rect.Top + check_wd + 2 * scale + i,
1671 rect.Left + check_wd / 2 + 6 * scale,
1672 rect.Top + check_wd - 2 * scale + i);
1677 if (item.Checked && control.StateImageList.Images.Count > 1)
1678 control.StateImageList.Draw (dc,
1679 rect_checkrect.Location, 1);
1680 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1681 control.StateImageList.Draw (dc,
1682 rect_checkrect.Location, 0);
1686 if (control.View == View.LargeIcon) {
1687 if (control.LargeImageList == null) {
1688 Pen pen = new Pen (ColorWindowText, 2);
1689 dc.DrawLine (pen, icon_rect.Left, icon_rect.Y, icon_rect.Left + 11, icon_rect.Y);
1690 } else if (item.ImageIndex > -1 && item.ImageIndex < control.LargeImageList.Images.Count)
1691 control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1693 if (item.ImageIndex > -1 && control.SmallImageList != null &&
1694 item.ImageIndex < control.SmallImageList.Images.Count)
1695 control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1698 // draw the item text
1699 // format for the item text
1700 StringFormat format = new StringFormat ();
1701 if (control.View == View.SmallIcon)
1702 format.LineAlignment = StringAlignment.Near;
1704 format.LineAlignment = StringAlignment.Center;
1705 if (control.View == View.LargeIcon)
1706 format.Alignment = StringAlignment.Center;
1708 format.Alignment = StringAlignment.Near;
1710 if (!control.LabelWrap)
1711 format.FormatFlags = StringFormatFlags.NoWrap;
1713 if (item.Selected) {
1714 if (control.View == View.Details) {
1715 if (control.FullRowSelect) {
1716 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), text_rect);
1719 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1721 text_rect.Width = text_size.Width;
1722 dc.FillRectangle (this.ResPool.GetSolidBrush
1723 (this.ColorHighlight), text_rect);
1727 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1729 Point loc = text_rect.Location;
1730 loc.X += (text_rect.Width - text_size.Width) / 2;
1731 text_rect.Width = text_size.Width;*/
1732 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHighlight),
1737 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1739 if (item.Text != null && item.Text.Length > 0) {
1741 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1742 (this.ColorHighlightText), text_rect, format);
1744 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1745 (item.ForeColor), text_rect, format);
1748 if (control.View == View.Details && control.Columns.Count > 0) {
1749 // draw subitems for details view
1750 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1751 int count = (control.Columns.Count < subItems.Count ?
1752 control.Columns.Count : subItems.Count);
1756 ListViewItem.ListViewSubItem subItem;
1757 Rectangle sub_item_rect = text_rect;
1759 // set the format for subitems
1760 format.FormatFlags = StringFormatFlags.NoWrap;
1762 // 0th subitem is the item already drawn
1763 for (int index = 1; index < count; index++) {
1764 subItem = subItems [index];
1765 col = control.Columns [index];
1766 format.Alignment = col.Format.Alignment;
1767 sub_item_rect.X = col.Rect.X - control.h_marker;
1768 sub_item_rect.Width = col.Wd;
1769 Rectangle sub_item_text_rect = sub_item_rect;
1770 sub_item_text_rect.X += 3;
1771 sub_item_text_rect.Width -= 6;
1773 SolidBrush sub_item_back_br = null;
1774 SolidBrush sub_item_fore_br = null;
1775 Font sub_item_font = null;
1777 if (item.UseItemStyleForSubItems) {
1778 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
1779 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
1780 sub_item_font = item.Font;
1782 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
1783 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
1784 sub_item_font = subItem.Font;
1787 if (item.Selected && control.FullRowSelect) {
1788 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), sub_item_rect);
1789 if (subItem.Text != null && subItem.Text.Length > 0)
1790 dc.DrawString (subItem.Text, sub_item_font,
1791 this.ResPool.GetSolidBrush
1792 (this.ColorHighlightText),
1793 sub_item_text_rect, format);
1795 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1796 if (subItem.Text != null && subItem.Text.Length > 0)
1797 dc.DrawString (subItem.Text, sub_item_font,
1799 sub_item_text_rect, format);
1806 Rectangle focus_rect = text_rect;
1807 if (control.FullRowSelect && control.View == View.Details) {
1809 foreach (ColumnHeader col in control.Columns)
1811 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
1814 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
1816 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
1823 public override Size ListViewCheckBoxSize {
1824 get { return new Size (16, 16); }
1827 public override int ListViewColumnHeaderHeight {
1831 public override int ListViewDefaultColumnWidth {
1835 public override int ListViewVerticalSpacing {
1839 public override int ListViewEmptyColumnWidth {
1843 public override int ListViewHorizontalSpacing {
1847 public override Size ListViewDefaultSize {
1848 get { return new Size (121, 97); }
1850 #endregion // ListView
1853 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1858 if (item.Visible == false) {
1864 if (item.Separator == true) {
1865 item.Height = SEPARATOR_HEIGHT / 2;
1870 if (item.MeasureEventDefined) {
1871 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1872 item.PerformMeasureItem (mi);
1873 item.Height = mi.ItemHeight;
1874 item.Width = mi.ItemWidth;
1878 size = dc.MeasureString (item.Text, MenuFont);
1879 item.Width = (int) size.Width;
1880 item.Height = (int) size.Height;
1883 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1884 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1885 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1886 item.Width += MENU_TAB_SPACE + (int) size.Width;
1889 item.Width += 4 + (MenuCheckSize.Width * 2);
1891 item.Width += MENU_BAR_ITEMS_SPACE;
1895 if (item.Height < MenuHeight)
1896 item.Height = MenuHeight;
1900 // Updates the menu rect and returns the height
1901 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1907 foreach (MenuItem item in menu.MenuItems) {
1909 CalcItemSize (dc, item, y, x, true);
1911 if (x + item.Width > width) {
1919 item.MenuBar = true;
1921 if (y + item.Height > menu.Height)
1922 menu.Height = item.Height + y;
1929 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1937 while (start < menu.MenuItems.Count) {
1940 for (i = start; i < menu.MenuItems.Count; i++) {
1941 MenuItem item = menu.MenuItems [i];
1943 if ((i != start) && (item.Break || item.BarBreak))
1946 CalcItemSize (dc, item, y, x, false);
1949 if (item.Width > max)
1953 // Replace the -1 by the menu width (separators)
1954 for (n = start; n < i; n++, start++)
1955 menu.MenuItems [n].Width = max;
1957 if (y > menu.Height)
1969 menu.Width += SM_CXBORDER;
1970 menu.Height += SM_CYBORDER;
1973 // Draws a menu bar in a window
1974 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1976 if (menu.Height == 0)
1977 CalcMenuBarSize (dc, menu, rect.Width);
1979 bool keynav = (menu as MainMenu).tracker.Navigating;
1980 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1981 string_format_menu_menubar_text.HotkeyPrefix = hp;
1982 string_format_menu_text.HotkeyPrefix = hp;
1984 rect.Height = menu.Height;
1985 dc.FillRectangle (ResPool.GetSolidBrush(ColorMenu), rect);
1987 for (int i = 0; i < menu.MenuItems.Count; i++) {
1988 MenuItem item = menu.MenuItems [i];
1989 Rectangle item_rect = item.bounds;
1990 item_rect.X += rect.X;
1991 item_rect.Y += rect.Y;
1992 item.MenuHeight = menu.Height;
1993 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1997 Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
2000 if (color.R == 0 && color.G == 0 && color.B == 0)
2001 bg_color = Color.White;
2003 bg_color = Color.Black;
2004 Bitmap bmp = new Bitmap (size.Width, size.Height);
2005 Graphics gr = Graphics.FromImage (bmp);
2006 Rectangle rect = new Rectangle (Point.Empty, size);
2007 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
2008 CPDrawMenuGlyph (gr, rect, glyph, color);
2009 bmp.MakeTransparent (bg_color);
2014 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
2016 StringFormat string_format;
2017 Rectangle rect_text = e.Bounds;
2019 if (item.Visible == false)
2023 string_format = string_format_menu_menubar_text;
2025 string_format = string_format_menu_text;
2027 if (item.Separator == true) {
2028 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
2029 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
2031 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
2032 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
2038 rect_text.X += MenuCheckSize.Width;
2040 if (item.BarBreak) { /* Draw vertical break bar*/
2041 Rectangle rect = e.Bounds;
2044 rect.Height = item.MenuHeight - 6;
2046 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
2047 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
2049 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
2050 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
2056 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
2057 color_text = ColorHighlightText;
2058 color_back = ColorHighlight;
2060 color_text = ColorMenuText;
2061 color_back = ColorMenu;
2064 /* Draw background */
2065 Rectangle rect_back = e.Bounds;
2067 rect_back.Width -=2;
2068 e.Graphics.FillRectangle (ResPool.GetSolidBrush (color_back), rect_back);
2071 e.Graphics.DrawString (item.Text, e.Font,
2072 ResPool.GetSolidBrush (color_text),
2073 rect_text, string_format);
2075 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
2076 string str = item.GetShortCutText ();
2077 Rectangle rect = rect_text;
2079 rect.Width -= item.XTab;
2081 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush (color_text),
2082 rect, string_format_menu_shortcut);
2085 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
2086 Color.Black, rect_text, string_format);
2090 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
2092 int cx = MenuCheckSize.Width;
2093 int cy = MenuCheckSize.Height;
2094 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
2097 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
2098 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
2100 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
2101 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
2107 /* Draw checked or radio */
2108 if (item.MenuBar == false && item.Checked) {
2110 Rectangle area = e.Bounds;
2111 int cx = MenuCheckSize.Width;
2112 int cy = MenuCheckSize.Height;
2113 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
2115 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
2121 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
2124 dc.FillRectangle (ResPool.GetSolidBrush
2125 (ColorMenu), cliparea);
2127 /* Draw menu borders */
2128 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
2129 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
2131 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
2132 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
2134 dc.DrawLine (ResPool.GetPen (ColorControlDark),
2135 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
2137 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
2138 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
2140 dc.DrawLine (ResPool.GetPen (ColorControlDark),
2141 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
2143 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
2144 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
2146 for (int i = 0; i < menu.MenuItems.Count; i++)
2147 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
2148 MenuItem item = menu.MenuItems [i];
2149 item.MenuHeight = menu.Height;
2150 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
2151 item.bounds, i, item.Status));
2157 #region MonthCalendar
2159 // draw the month calendar
2160 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2162 Rectangle client_rectangle = mc.ClientRectangle;
2163 Size month_size = mc.SingleMonthSize;
2164 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2165 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2166 Size date_cell_size = (Size)((object)mc.date_cell_size);
2168 // draw the singlecalendars
2171 // adjust for the position of the specific month
2172 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2176 y_offset += month_size.Height + calendar_spacing.Height;
2178 // now adjust for x position
2179 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2183 x_offset += month_size.Width + calendar_spacing.Width;
2190 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2191 if (month_rect.IntersectsWith (clip_rectangle)) {
2203 Rectangle bottom_rect = new Rectangle (
2205 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2206 client_rectangle.Width,
2207 date_cell_size.Height + 2);
2208 // draw the today date if it's set
2209 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2211 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
2213 int today_offset = 5;
2214 if (mc.ShowTodayCircle)
2216 Rectangle today_circle_rect = new Rectangle (
2217 client_rectangle.X + 5,
2218 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2219 date_cell_size.Width,
2220 date_cell_size.Height);
2221 DrawTodayCircle (dc, today_circle_rect);
2222 today_offset += date_cell_size.Width + 5;
2224 // draw today's date
2225 StringFormat text_format = new StringFormat();
2226 text_format.LineAlignment = StringAlignment.Center;
2227 text_format.Alignment = StringAlignment.Near;
2228 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2229 Rectangle today_rect = new Rectangle (
2230 today_offset + client_rectangle.X,
2231 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2232 Math.Max(client_rectangle.Width - today_offset, 0),
2233 date_cell_size.Height);
2234 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
2235 text_format.Dispose ();
2236 bold_font.Dispose ();
2240 // finally paint the borders of the calendars as required
2241 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2242 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2243 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
2244 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2245 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
2247 Rectangle rect = new Rectangle (
2248 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2250 calendar_spacing.Width,
2251 client_rectangle.Height);
2252 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2253 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2257 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2258 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2259 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
2260 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2261 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
2263 Rectangle rect = new Rectangle (
2265 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2266 client_rectangle.Width,
2267 calendar_spacing.Height);
2268 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2269 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2274 // draw the drop down border if need
2275 if (mc.owner != null) {
2276 Rectangle bounds = mc.ClientRectangle;
2277 if (clip_rectangle.Contains (mc.Location)) {
2278 // find out if top or left line to draw
2279 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2281 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2283 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2284 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2287 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2288 // find out if bottom or right line to draw
2289 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2290 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2292 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2293 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2299 // darws a single part of the month calendar (with one month)
2300 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2302 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2303 Size title_size = (Size)((object)mc.title_size);
2304 Size date_cell_size = (Size)((object)mc.date_cell_size);
2305 DateTime current_month = (DateTime)((object)mc.current_month);
2307 // set up some standard string formating variables
2308 StringFormat text_format = new StringFormat();
2309 text_format.LineAlignment = StringAlignment.Center;
2310 text_format.Alignment = StringAlignment.Center;
2313 // draw the title back ground
2314 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2315 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2316 if (title_rect.IntersectsWith (clip_rectangle)) {
2317 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2319 string title_text = this_month.ToString ("MMMM yyyy");
2320 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2322 // draw previous and next buttons if it's time
2323 if (row == 0 && col == 0)
2325 // draw previous button
2326 DrawMonthCalendarButton (
2332 (System.Drawing.Size)((object)mc.button_size),
2335 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2338 DrawMonthCalendarButton (
2344 (System.Drawing.Size)((object)mc.button_size),
2349 // set the week offset and draw week nums if needed
2350 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2351 Rectangle day_name_rect = new Rectangle(
2353 rectangle.Y + title_size.Height,
2354 (7 + col_offset) * date_cell_size.Width,
2355 date_cell_size.Height);
2356 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2357 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
2358 // draw the day names
2359 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2360 for (int i=0; i < 7; i++)
2362 int position = i - (int) first_day_of_week;
2365 position = 7 + position;
2368 Rectangle day_rect = new Rectangle(
2369 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2371 date_cell_size.Width,
2372 date_cell_size.Height);
2373 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2376 // draw the vertical divider
2377 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2379 ResPool.GetPen (mc.ForeColor),
2380 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2381 rectangle.Y + vert_divider_y,
2382 rectangle.Right - mc.divider_line_offset,
2383 rectangle.Y + vert_divider_y);
2387 // draw the actual date items in the grid (including the week numbers)
2388 Rectangle date_rect = new Rectangle (
2390 rectangle.Y + title_size.Height + date_cell_size.Height,
2391 date_cell_size.Width,
2392 date_cell_size.Height);
2393 int month_row_count = 0;
2394 bool draw_week_num_divider = false;
2395 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2396 for (int i=0; i < 6; i++)
2398 // establish if this row is in our clip_area
2399 Rectangle row_rect = new Rectangle (
2401 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2402 date_cell_size.Width * 7,
2403 date_cell_size.Height);
2404 if (mc.ShowWeekNumbers) {
2405 row_rect.Width += date_cell_size.Width;
2408 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2410 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
2412 // establish if this is a valid week to draw
2413 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2414 month_row_count = i;
2417 // draw the week number if required
2418 if (mc.ShowWeekNumbers && month_row_count == i) {
2419 if (!draw_week_num_divider) {
2420 draw_week_num_divider = draw_row;
2422 // get the week for this row
2423 int week = mc.GetWeekOfYear (current_date);
2429 ResPool.GetSolidBrush (mc.TitleBackColor),
2433 date_rect.Offset(date_cell_size.Width, 0);
2436 // only draw the days if we have to
2437 if(month_row_count == i) {
2438 for (int j=0; j < 7; j++)
2441 DrawMonthCalendarDate (
2452 current_date = current_date.AddDays(1);
2453 date_rect.Offset(date_cell_size.Width, 0);
2456 // shift the rectangle down one row
2457 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2458 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2462 // month_row_count is zero based, so add one
2465 // draw week numbers if required
2466 if (draw_week_num_divider) {
2469 ResPool.GetPen (mc.ForeColor),
2470 rectangle.X + date_cell_size.Width - 1,
2471 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2472 rectangle.X + date_cell_size.Width - 1,
2473 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2475 text_format.Dispose ();
2478 // draws the pervious or next button
2479 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2481 bool is_clicked = false;
2482 Rectangle button_rect;
2483 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2484 Point[] arrow_path = new Point[3];
2485 // prepare the button
2488 is_clicked = mc.is_previous_clicked;
2489 button_rect = new Rectangle (
2490 rectangle.X + 1 + x_offset,
2491 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2492 Math.Max(button_size.Width - 1, 0),
2493 Math.Max(button_size.Height - 1, 0));
2494 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2495 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2497 arrow_rect.Offset(1,1);
2499 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2500 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2501 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2505 is_clicked = mc.is_next_clicked;
2506 button_rect = new Rectangle (
2507 rectangle.Right - 1 - x_offset - button_size.Width,
2508 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2509 Math.Max(button_size.Width - 1, 0),
2510 Math.Max(button_size.Height - 1, 0));
2511 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2512 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2514 arrow_rect.Offset(1,1);
2516 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2517 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2518 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2521 // fill the background
2522 dc.FillRectangle (SystemBrushes.Control, button_rect);
2525 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2528 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
2531 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2535 // draws one day in the calendar grid
2536 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2537 Color date_color = mc.ForeColor;
2538 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2540 // find out if we are the lead of the first calendar or the trail of the last calendar
2541 if (date.Year != month.Year || date.Month != month.Month) {
2542 DateTime check_date = month.AddMonths (-1);
2543 // check if it's the month before
2544 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2545 date_color = mc.TrailingForeColor;
2547 // check if it's the month after
2548 check_date = month.AddMonths (1);
2549 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2550 date_color = mc.TrailingForeColor;
2556 date_color = mc.ForeColor;
2560 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2561 // see if the date is in the start of selection
2562 date_color = mc.BackColor;
2563 // draw the left hand of the back ground
2564 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2565 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2566 } else if (date == mc.SelectionStart) {
2567 // see if the date is in the start of selection
2568 date_color = mc.BackColor;
2569 // draw the left hand of the back ground
2570 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2571 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2572 // fill the other side as a straight rect
2573 if (date < mc.SelectionEnd)
2575 // use rectangle instead of rectangle to go all the way to edge of rect
2576 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2577 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2578 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2580 } else if (date == mc.SelectionEnd) {
2581 // see if it is the end of selection
2582 date_color = mc.BackColor;
2583 // draw the left hand of the back ground
2584 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2585 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2586 // fill the other side as a straight rect
2587 if (date > mc.SelectionStart) {
2588 selection_rect.X = rectangle.X;
2589 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2590 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2592 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2593 // now see if it's in the middle
2594 date_color = mc.BackColor;
2595 // draw the left hand of the back ground
2596 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2597 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2600 // set up some standard string formating variables
2601 StringFormat text_format = new StringFormat();
2602 text_format.LineAlignment = StringAlignment.Center;
2603 text_format.Alignment = StringAlignment.Center;
2606 // establish if it's a bolded font
2608 if (mc.IsBoldedDate (date)) {
2609 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2614 // just draw the date now
2615 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2617 // today circle if needed
2618 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2619 DrawTodayCircle (dc, interior);
2622 // draw the selection grid
2623 if (mc.is_date_clicked && mc.clicked_date == date) {
2624 using (Pen pen = new Pen (Color.Black, 1) ) {
2625 pen.DashStyle = DashStyle.Dot;
2626 dc.DrawRectangle (pen, interior);
2629 text_format.Dispose ();
2632 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2633 Color circle_color = Color.FromArgb (248, 0, 0);
2634 // draw the left hand of the circle
2635 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2636 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2637 Point [] curve_points = new Point [3];
2638 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2639 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2640 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2642 using (Pen pen = new Pen (circle_color, 2)) {
2643 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2644 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2645 dc.DrawCurve (pen, curve_points);
2646 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2650 #endregion // MonthCalendar
2653 public override Size PanelDefaultSize {
2655 return new Size (200, 100);
2661 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2662 Rectangle client = pb.ClientRectangle;
2664 // FIXME - instead of drawing the whole picturebox every time
2665 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2666 // Also, we only need a background fill where no image goes
2667 if (pb.Image != null) {
2668 switch (pb.SizeMode) {
2669 case PictureBoxSizeMode.StretchImage:
2670 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2673 case PictureBoxSizeMode.CenterImage:
2674 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2675 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2678 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2680 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2687 // We only get here if no image is set. At least paint the background
2688 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2691 public override Size PictureBoxDefaultSize {
2693 return new Size (100, 50);
2696 #endregion // PictureBox
2699 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2701 Rectangle block_rect;
2702 Rectangle client_area = ctrl.client_area;
2703 int space_betweenblocks = 2;
2708 block_width = (client_area.Height * 2 ) / 3;
2709 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2710 increment = block_width + space_betweenblocks;
2713 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
2716 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2717 while ((block_rect.X - client_area.X) < barpos_pixels) {
2719 if (clip_rect.IntersectsWith (block_rect) == true) {
2720 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2723 block_rect.X += increment;
2727 public override Size ProgressBarDefaultSize {
2729 return new Size (100, 23);
2733 #endregion // ProgressBar
2736 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2737 StringFormat text_format;
2738 Rectangle client_rectangle;
2739 Rectangle text_rectangle;
2740 Rectangle radiobutton_rectangle;
2741 int radiobutton_size = 12;
2742 int radiobutton_space = 4;
2744 client_rectangle = radio_button.ClientRectangle;
2745 text_rectangle = client_rectangle;
2746 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2748 text_format = new StringFormat();
2749 text_format.Alignment = StringAlignment.Near;
2750 text_format.LineAlignment = StringAlignment.Center;
2751 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2753 /* Calculate the position of text and checkbox rectangle */
2754 if (radio_button.appearance!=Appearance.Button) {
2755 switch(radio_button.radiobutton_alignment) {
2756 case ContentAlignment.BottomCenter: {
2757 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2758 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2759 text_rectangle.X=client_rectangle.X;
2760 text_rectangle.Width=client_rectangle.Width;
2761 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2765 case ContentAlignment.BottomLeft: {
2766 radiobutton_rectangle.X=client_rectangle.Left;
2767 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2768 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2769 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2773 case ContentAlignment.BottomRight: {
2774 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2775 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2776 text_rectangle.X=client_rectangle.X;
2777 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2781 case ContentAlignment.MiddleCenter: {
2782 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2783 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2784 text_rectangle.X=client_rectangle.X;
2785 text_rectangle.Width=client_rectangle.Width;
2790 case ContentAlignment.MiddleLeft: {
2791 radiobutton_rectangle.X=client_rectangle.Left;
2792 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2793 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2794 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2798 case ContentAlignment.MiddleRight: {
2799 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2800 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2801 text_rectangle.X=client_rectangle.X;
2802 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2806 case ContentAlignment.TopCenter: {
2807 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2808 radiobutton_rectangle.Y=client_rectangle.Top;
2809 text_rectangle.X=client_rectangle.X;
2810 text_rectangle.Y=radiobutton_size+radiobutton_space;
2811 text_rectangle.Width=client_rectangle.Width;
2812 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2816 case ContentAlignment.TopLeft: {
2817 radiobutton_rectangle.X=client_rectangle.Left;
2818 radiobutton_rectangle.Y=client_rectangle.Top;
2819 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2820 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2824 case ContentAlignment.TopRight: {
2825 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2826 radiobutton_rectangle.Y=client_rectangle.Top;
2827 text_rectangle.X=client_rectangle.X;
2828 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2833 text_rectangle.X=client_rectangle.X;
2834 text_rectangle.Width=client_rectangle.Width;
2837 /* Set the horizontal alignment of our text */
2838 switch(radio_button.text_alignment) {
2839 case ContentAlignment.BottomLeft:
2840 case ContentAlignment.MiddleLeft:
2841 case ContentAlignment.TopLeft: {
2842 text_format.Alignment=StringAlignment.Near;
2846 case ContentAlignment.BottomCenter:
2847 case ContentAlignment.MiddleCenter:
2848 case ContentAlignment.TopCenter: {
2849 text_format.Alignment=StringAlignment.Center;
2853 case ContentAlignment.BottomRight:
2854 case ContentAlignment.MiddleRight:
2855 case ContentAlignment.TopRight: {
2856 text_format.Alignment=StringAlignment.Far;
2861 /* Set the vertical alignment of our text */
2862 switch(radio_button.text_alignment) {
2863 case ContentAlignment.TopLeft:
2864 case ContentAlignment.TopCenter:
2865 case ContentAlignment.TopRight: {
2866 text_format.LineAlignment=StringAlignment.Near;
2870 case ContentAlignment.BottomLeft:
2871 case ContentAlignment.BottomCenter:
2872 case ContentAlignment.BottomRight: {
2873 text_format.LineAlignment=StringAlignment.Far;
2877 case ContentAlignment.MiddleLeft:
2878 case ContentAlignment.MiddleCenter:
2879 case ContentAlignment.MiddleRight: {
2880 text_format.LineAlignment=StringAlignment.Center;
2885 // FIXME: can be removed if themes are updated ->
2886 ButtonState state = ButtonState.Normal;
2887 if (radio_button.FlatStyle == FlatStyle.Flat) {
2888 state |= ButtonState.Flat;
2891 if (radio_button.Checked) {
2892 state |= ButtonState.Checked;
2897 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2899 if ((radio_button.image != null) || (radio_button.image_list != null))
2900 ButtonBase_DrawImage(radio_button, dc);
2902 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2904 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2906 text_format.Dispose ();
2909 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2911 dc.FillRectangle(ResPool.GetSolidBrush(radio_button.BackColor), radio_button.ClientRectangle);
2913 if (radio_button.appearance==Appearance.Button) {
2914 ButtonBase_DrawButton (radio_button, dc);
2916 // establish if we are rendering a flat style of some sort
2917 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2918 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2920 DrawNormalRadioButton (dc, radiobutton_rectangle, radio_button);
2925 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2927 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
2928 text_format, radio_button.Appearance, radio_button.Checked);
2931 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2933 // do nothing here. maybe an other theme needs it
2936 protected virtual void DrawNormalRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2938 Pen penFatDark = new Pen(ColorControlDark, 1);
2939 Pen penFatLight = new Pen(ColorControlLightLight, 1);
2942 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2944 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
2945 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
2947 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
2948 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
2950 if (radio_button.Checked) {
2951 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
2953 SolidBrush buttonBrush;
2955 if (!radio_button.is_enabled) {
2956 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
2958 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
2960 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
2963 penFatDark.Dispose();
2964 penFatLight.Dispose();
2967 // renders a radio button with the Flat and Popup FlatStyle
2968 protected void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2972 if (radio_button.Enabled) {
2973 CPColor cpcolor = ResPool.GetCPColor (radio_button.BackColor);
2975 // draw the outer flatstyle arcs
2976 if (radio_button.FlatStyle == FlatStyle.Flat) {
2977 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
2979 // fill in the area depending on whether or not the mouse is hovering
2980 if (radio_button.is_entered && radio_button.Capture) {
2981 graphics.FillPie (ResPool.GetSolidBrush (cpcolor.Light), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2983 graphics.FillPie (ResPool.GetSolidBrush (cpcolor.LightLight), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2986 // must be a popup radio button
2988 graphics.FillPie (ResPool.GetSolidBrush (cpcolor.LightLight), rectangle, 0, 359);
2990 if (radio_button.is_entered || radio_button.Capture) {
2991 // draw the popup 3d button knob
2992 graphics.DrawArc (ResPool.GetPen (cpcolor.Light), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2994 graphics.DrawArc (ResPool.GetPen (cpcolor.Dark), rectangle, 135, 180);
2995 graphics.DrawArc (ResPool.GetPen (cpcolor.LightLight), rectangle, 315, 180);
2998 // just draw lighter flatstyle outer circle
2999 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);
3004 // fill control background color regardless of actual backcolor
3005 graphics.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3006 // draw the ark as control dark
3007 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
3011 if (radio_button.Checked) {
3012 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
3014 SolidBrush buttonBrush;
3016 if (!radio_button.Enabled) {
3017 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorControl));
3018 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
3019 buttonBrush = ResPool.GetSolidBrush (this.ColorControlText);
3021 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
3024 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
3028 public override Size RadioButtonDefaultSize {
3030 return new Size (104,24);
3033 #endregion // RadioButton
3036 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
3038 int scrollbutton_width = bar.scrollbutton_width;
3039 int scrollbutton_height = bar.scrollbutton_height;
3040 Rectangle first_arrow_area;
3041 Rectangle second_arrow_area;
3042 Rectangle thumb_pos;
3044 thumb_pos = bar.ThumbPos;
3047 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
3048 bar.FirstArrowArea = first_arrow_area;
3050 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
3051 bar.SecondArrowArea = second_arrow_area;
3053 thumb_pos.Width = bar.Width;
3054 bar.ThumbPos = thumb_pos;
3057 if (clip.IntersectsWith (first_arrow_area))
3058 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
3059 if (clip.IntersectsWith (second_arrow_area))
3060 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
3063 switch (bar.thumb_moving) {
3064 case ScrollBar.ThumbMoving.None: {
3065 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
3068 case ScrollBar.ThumbMoving.Forward: {
3069 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
3073 case ScrollBar.ThumbMoving.Backwards: {
3074 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
3082 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
3083 bar.FirstArrowArea = first_arrow_area;
3085 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
3086 bar.SecondArrowArea = second_arrow_area;
3088 thumb_pos.Height = bar.Height;
3089 bar.ThumbPos = thumb_pos;
3092 if (clip.IntersectsWith (first_arrow_area))
3093 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
3094 if (clip.IntersectsWith (second_arrow_area))
3095 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
3098 switch (bar.thumb_moving) {
3099 case ScrollBar.ThumbMoving.None: {
3100 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
3104 case ScrollBar.ThumbMoving.Forward: {
3105 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
3109 case ScrollBar.ThumbMoving.Backwards: {
3110 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
3117 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
3120 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
3122 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
3123 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
3126 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
3128 Rectangle r = new Rectangle( 0,
3129 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
3130 Rectangle intersect = Rectangle.Intersect( clip, r );
3132 if ( intersect != Rectangle.Empty )
3134 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
3135 dc.FillRectangle( h, intersect );
3139 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3141 Rectangle r = new Rectangle( 0, scrollbutton_height,
3142 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3143 Rectangle intersect = Rectangle.Intersect( clip, r );
3145 if ( intersect != Rectangle.Empty )
3146 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
3149 r.Y = thumb_pos.Y + thumb_pos.Height;
3150 r.Width = bar.ClientRectangle.Width;
3151 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3153 intersect = Rectangle.Intersect( clip, r );
3154 if ( intersect != Rectangle.Empty )
3155 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3158 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3160 Rectangle r = new Rectangle( 0, scrollbutton_height,
3161 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3162 Rectangle intersect = Rectangle.Intersect( clip, r );
3164 if ( intersect != Rectangle.Empty )
3165 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3168 r.Y = thumb_pos.Y + thumb_pos.Height;
3169 r.Width = bar.ClientRectangle.Width;
3170 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3172 intersect = Rectangle.Intersect( clip, r );
3173 if ( intersect != Rectangle.Empty )
3174 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3177 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
3179 Rectangle r = new Rectangle( scrollbutton_width,
3180 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
3181 Rectangle intersect = Rectangle.Intersect( clip, r );
3183 if ( intersect != Rectangle.Empty )
3184 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3187 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3189 Rectangle r = new Rectangle( scrollbutton_width, 0,
3190 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3191 Rectangle intersect = Rectangle.Intersect( clip, r );
3193 if ( intersect != Rectangle.Empty )
3194 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3196 r.X = thumb_pos.X + thumb_pos.Width;
3198 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3199 r.Height = bar.ClientRectangle.Height;
3201 intersect = Rectangle.Intersect( clip, r );
3202 if ( intersect != Rectangle.Empty )
3203 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3206 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3208 Rectangle r = new Rectangle( scrollbutton_width, 0,
3209 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3210 Rectangle intersect = Rectangle.Intersect( clip, r );
3212 if ( intersect != Rectangle.Empty )
3213 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3215 r.X = thumb_pos.X + thumb_pos.Width;
3217 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3218 r.Height = bar.ClientRectangle.Height;
3220 intersect = Rectangle.Intersect( clip, r );
3221 if ( intersect != Rectangle.Empty )
3222 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3225 public override int ScrollBarButtonSize {
3228 #endregion // ScrollBar
3231 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3232 Rectangle area = sb.ClientRectangle;
3233 int horz_border = 2;
3234 int vert_border = 2;
3236 dc.FillRectangle (GetControlBackBrush (sb.BackColor), clip);
3238 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3239 string text = sb.Text;
3240 StringFormat string_format = new StringFormat ();
3241 string_format.Trimming = StringTrimming.Character;
3242 string_format.FormatFlags = StringFormatFlags.NoWrap;
3244 if (text [0] == '\t') {
3245 string_format.Alignment = StringAlignment.Center;
3246 text = text.Substring (1);
3247 if (text [0] == '\t') {
3248 string_format.Alignment = StringAlignment.Far;
3249 text = text.Substring (1);
3253 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3254 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3255 string_format.Dispose ();
3256 } else if (sb.ShowPanels) {
3257 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
3258 int prev_x = area.X + horz_border;
3259 int y = area.Y + vert_border;
3260 for (int i = 0; i < sb.Panels.Count; i++) {
3261 Rectangle pr = new Rectangle (prev_x, y,
3262 sb.Panels [i].Width, area.Height);
3263 prev_x += pr.Width + StatusBarHorzGapWidth;
3264 if (pr.IntersectsWith (clip))
3265 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3270 CPDrawSizeGrip (dc, ColorControl, area);
3275 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3276 SolidBrush br_forecolor, StatusBarPanel panel) {
3277 int border_size = 3; // this is actually const, even if the border style is none
3279 area.Height -= border_size;
3281 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3282 Border3DStyle border_style = Border3DStyle.SunkenOuter;
3283 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3284 border_style = Border3DStyle.RaisedInner;
3286 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
3289 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3290 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3291 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3292 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3293 panel.Parent.OnDrawItemInternal (e);
3297 int left = area.Left;
3298 if (panel.Icon != null) {
3300 dc.DrawIcon (panel.Icon, left, area.Top);
3301 left += panel.Icon.Width;
3304 if (panel.Text == String.Empty)
3307 string text = panel.Text;
3308 StringFormat string_format = new StringFormat ();
3309 string_format.Trimming = StringTrimming.Character;
3310 string_format.FormatFlags = StringFormatFlags.NoWrap;
3312 if (text [0] == '\t') {
3313 string_format.Alignment = StringAlignment.Center;
3314 text = text.Substring (1);
3315 if (text [0] == '\t') {
3316 string_format.Alignment = StringAlignment.Far;
3317 text = text.Substring (1);
3321 int x = left + border_size;
3322 int y = border_size + 2;
3323 Rectangle r = new Rectangle (x, y,
3324 area.Right - x - border_size,
3325 area.Bottom - y - border_size);
3327 dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
3328 string_format.Dispose ();
3331 public override int StatusBarSizeGripWidth {
3335 public override int StatusBarHorzGapWidth {
3339 public override Size StatusBarDefaultSize {
3341 return new Size (100, 22);
3344 #endregion // StatusBar
3346 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3348 // Do we need to fill the back color? It can't be changed...
3349 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
3350 Rectangle panel_rect = GetTabPanelRectExt (tab);
3352 if (tab.Appearance == TabAppearance.Normal) {
3353 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3354 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3357 if (tab.Alignment == TabAlignment.Top) {
3358 for (int r = tab.TabPages.Count; r > 0; r--) {
3359 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3360 if (i == tab.SelectedIndex)
3362 if (r != tab.TabPages [i].Row)
3364 Rectangle rect = tab.GetTabRect (i);
3365 if (!rect.IntersectsWith (area))
3367 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3371 for (int r = 0; r < tab.TabPages.Count; r++) {
3372 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3373 if (i == tab.SelectedIndex)
3375 if (r != tab.TabPages [i].Row)
3377 Rectangle rect = tab.GetTabRect (i);
3378 if (!rect.IntersectsWith (area))
3380 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3385 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3386 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3387 if (rect.IntersectsWith (area))
3388 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3391 if (tab.ShowSlider) {
3392 Rectangle right = GetTabControlRightScrollRect (tab);
3393 Rectangle left = GetTabControlLeftScrollRect (tab);
3394 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3395 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3399 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3401 switch (tab.Alignment) {
3402 case TabAlignment.Top:
3403 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3405 Rectangle panel_rect = GetTabPanelRectExt (tab);
3406 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3410 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3412 switch (tab.Alignment) {
3413 case TabAlignment.Top:
3414 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3416 Rectangle panel_rect = GetTabPanelRectExt (tab);
3417 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3421 public override Size TabControlDefaultItemSize {
3422 get { return new Size (42, 21); }
3425 public override Point TabControlDefaultPadding {
3426 get { return new Point (6, 3); }
3429 public override int TabControlMinimumTabWidth {
3433 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3435 Rectangle ext = GetTabPanelRectExt (tab);
3436 // Account for border size
3437 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3440 public override Size TabControlGetSpacing (TabControl tab) {
3441 switch (tab.Appearance) {
3442 case TabAppearance.Normal:
3443 return new Size (1, -2);
3444 case TabAppearance.Buttons:
3445 return new Size (3, 3);
3446 case TabAppearance.FlatButtons:
3447 return new Size (9, 3);
3449 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3453 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3455 // Offset the tab from the top corner
3456 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3457 tab.ClientRectangle.Y,
3458 tab.ClientRectangle.Width - 2,
3459 tab.ClientRectangle.Height - 1);
3461 if (tab.TabCount == 0)
3464 int spacing = TabControlGetSpacing (tab).Height;
3465 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3467 switch (tab.Alignment) {
3468 case TabAlignment.Left:
3470 res.Width -= offset;
3472 case TabAlignment.Right:
3473 res.Width -= offset;
3475 case TabAlignment.Top:
3477 res.Height -= offset;
3479 case TabAlignment.Bottom:
3480 res.Height -= offset;
3487 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3489 int FlatButtonSpacing = 8;
3491 int res = bounds.Width;
3495 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3497 StringFormat string_format = new StringFormat ();
3498 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3499 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3502 if (tab.Appearance == TabAppearance.FlatButtons) {
3503 int width = bounds.Width;
3504 bounds.Width += (FlatButtonSpacing - 2);
3506 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3507 bounds.Width = width;
3511 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3512 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3513 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3516 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3519 string_format.Alignment = StringAlignment.Center;
3520 string_format.LineAlignment = StringAlignment.Center;
3521 string_format.FormatFlags = StringFormatFlags.NoWrap;
3523 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
3525 switch (tab.Alignment) {
3527 case TabAlignment.Top:
3530 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3532 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3533 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3534 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3536 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3537 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3538 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3540 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3542 string_format.Alignment = StringAlignment.Center;
3543 string_format.LineAlignment = StringAlignment.Center;
3544 string_format.FormatFlags = StringFormatFlags.NoWrap;
3548 case TabAlignment.Bottom:
3550 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3552 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3553 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3555 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3556 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3558 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3559 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3560 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3562 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3564 string_format.Alignment = StringAlignment.Center;
3565 string_format.LineAlignment = StringAlignment.Center;
3566 string_format.FormatFlags = StringFormatFlags.NoWrap;
3570 case TabAlignment.Left:
3572 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3574 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3575 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3576 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3578 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3580 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3581 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3583 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3585 string_format.Alignment = StringAlignment.Center;
3586 string_format.LineAlignment = StringAlignment.Center;
3587 string_format.FormatFlags = StringFormatFlags.NoWrap;
3588 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3593 // TabAlignment.Right
3595 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3597 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3598 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3600 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3601 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3603 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3604 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3606 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3608 string_format.Alignment = StringAlignment.Center;
3609 string_format.LineAlignment = StringAlignment.Center;
3610 string_format.FormatFlags = StringFormatFlags.NoWrap;
3611 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3617 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3618 if (tab.Alignment == TabAlignment.Left) {
3619 int wo = interior.Width / 2;
3620 int ho = interior.Height / 2;
3621 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3622 dc.RotateTransform (180);
3623 dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
3624 dc.ResetTransform ();
3626 dc.DrawString (page.Text, page.Font,
3627 ResPool.GetSolidBrush (SystemColors.ControlText),
3628 interior, string_format);
3630 } else if (page.Text != null) {
3631 DrawItemState state = DrawItemState.None;
3632 if (page == tab.SelectedTab)
3633 state |= DrawItemState.Selected;
3634 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3635 tab.Font, bounds, tab.IndexForTabPage (page),
3636 state, page.ForeColor, page.BackColor);
3637 tab.OnDrawItemInternal (e);
3641 if (page.parent.Focused && is_selected) {
3642 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3649 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
3651 StringFormat format = new StringFormat ();
3652 format.Trimming = StringTrimming.EllipsisWord;
3653 format.LineAlignment = StringAlignment.Center;
3654 if (control.TextAlign == ToolBarTextAlign.Underneath)
3655 format.Alignment = StringAlignment.Center;
3657 format.Alignment = StringAlignment.Near;
3659 dc.FillRectangle (ResPool.GetSolidBrush( DefaultControlBackColor ), clip_rectangle);
3661 foreach (ToolBarButton button in control.Buttons)
3662 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
3663 DrawToolBarButton (dc, control, button, format);
3668 void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3670 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
3672 DrawToolBarButtonBorder (dc, button, is_flat);
3674 switch (button.Style) {
3675 case ToolBarButtonStyle.DropDownButton:
3676 if (control.DropDownArrows)
3677 DrawToolBarDropDownArrow (dc, button, is_flat);
3678 DrawToolBarButtonContents (dc, control, button, format);
3681 case ToolBarButtonStyle.Separator:
3683 DrawToolBarSeparator (dc, button);
3686 case ToolBarButtonStyle.ToggleButton:
3687 DrawToolBarToggleButtonBackground (dc, button);
3688 DrawToolBarButtonContents (dc, control, button, format);
3692 DrawToolBarButtonContents (dc, control, button, format);
3697 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
3699 void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
3701 if (button.Style == ToolBarButtonStyle.Separator)
3704 Border3DStyle style;
3707 if (button.Pushed || button.Pressed)
3708 style = Border3DStyle.SunkenOuter;
3709 else if (button.Hilight)
3710 style = Border3DStyle.RaisedInner;
3715 if (button.Pushed || button.Pressed)
3716 style = Border3DStyle.Sunken;
3718 style = Border3DStyle.Raised;
3721 CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
3724 void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
3726 Rectangle area = button.Rectangle;
3727 int offset = (int) ResPool.GetPen (ColorControl).Width + 1;
3728 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X + 1, area.Y, area.X + 1, area.Bottom);
3729 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + offset, area.Y, area.X + offset, area.Bottom);
3732 void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
3734 Rectangle area = button.Rectangle;
3735 area.X += ToolBarImageGripWidth;
3736 area.Y += ToolBarImageGripWidth;
3737 area.Width -= 2 * ToolBarImageGripWidth;
3738 area.Height -= 2 * ToolBarImageGripWidth;
3741 dc.FillRectangle (SystemBrushes.ControlLightLight, area);
3742 else if (button.PartialPush)
3743 dc.FillRectangle (SystemBrushes.ControlLight, area);
3745 dc.FillRectangle (SystemBrushes.Control, area);
3748 void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
3750 Rectangle rect = button.Rectangle;
3751 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
3752 rect.Width = ToolBarDropDownWidth;
3754 if (button.dd_pressed) {
3755 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
3756 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
3757 } else if (button.Pushed || button.Pressed)
3758 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
3761 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
3763 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3765 PointF [] vertices = new PointF [3];
3766 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
3767 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3768 vertices [0].Y = ddCenter.Y;
3769 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3770 vertices [1].Y = ddCenter.Y;
3771 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3772 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
3773 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3776 void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3778 if (button.Image != null) {
3779 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
3780 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
3782 dc.DrawImage (button.Image, x, y);
3784 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
3788 dc.DrawString (button.Text, control.Font, ResPool.GetSolidBrush (ColorControlText), button.TextRectangle, format);
3790 CPDrawStringDisabled (dc, button.Text, control.Font, ColorControlLight, button.TextRectangle, format);
3793 // Grip width for the ToolBar
3794 public override int ToolBarGripWidth {
3798 // Grip width for the Image on the ToolBarButton
3799 public override int ToolBarImageGripWidth {
3803 // width of the separator
3804 public override int ToolBarSeparatorWidth {
3808 // width of the dropdown arrow rect
3809 public override int ToolBarDropDownWidth {
3813 // width for the dropdown arrow on the ToolBarButton
3814 public override int ToolBarDropDownArrowWidth {
3818 // height for the dropdown arrow on the ToolBarButton
3819 public override int ToolBarDropDownArrowHeight {
3823 public override Size ToolBarDefaultSize {
3825 return new Size (100, 42);
3828 #endregion // ToolBar
3831 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3832 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfo), control.client_rect);
3833 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
3834 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3837 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3840 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3841 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
3843 #endregion // ToolTip
3846 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3847 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3848 float ticks, int value_pos, bool mouse_value) {
3850 Point toptick_startpoint = new Point ();
3851 Point bottomtick_startpoint = new Point ();
3852 Point channel_startpoint = new Point ();
3854 float pixels_betweenticks;
3855 const int space_from_right = 8;
3856 const int space_from_left = 8;
3857 const int space_from_bottom = 11;
3858 Rectangle area = tb.ClientRectangle;
3860 switch (tb.TickStyle) {
3861 case TickStyle.BottomRight:
3862 case TickStyle.None:
3863 channel_startpoint.Y = 8;
3864 channel_startpoint.X = 9;
3865 bottomtick_startpoint.Y = 13;
3866 bottomtick_startpoint.X = 24;
3868 case TickStyle.TopLeft:
3869 channel_startpoint.Y = 8;
3870 channel_startpoint.X = 19;
3871 toptick_startpoint.Y = 13;
3872 toptick_startpoint.X = 8;
3874 case TickStyle.Both:
3875 channel_startpoint.Y = 8;
3876 channel_startpoint.X = 18;
3877 bottomtick_startpoint.Y = 13;
3878 bottomtick_startpoint.X = 32;
3879 toptick_startpoint.Y = 13;
3880 toptick_startpoint.X = 8;
3886 thumb_area.X = area.X + channel_startpoint.X;
3887 thumb_area.Y = area.Y + channel_startpoint.Y;
3888 thumb_area.Height = area.Height - space_from_right - space_from_left;
3889 thumb_area.Width = 4;
3892 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
3893 1, thumb_area.Height);
3895 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X + 1, channel_startpoint.Y,
3896 1, thumb_area.Height);
3898 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X + 3, channel_startpoint.Y,
3899 1, thumb_area.Height);
3901 pixel_len = thumb_area.Height - 11;
3902 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3904 /* Convert thumb position from mouse position to value*/
3906 if (value_pos < thumb_area.Bottom)
3907 value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
3911 if (value_pos + tb.Minimum > tb.Maximum)
3912 value_pos = tb.Maximum - tb.Minimum;
3914 tb.Value = value_pos + tb.Minimum;
3917 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
3918 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
3920 /* Draw thumb fixed 10x22 size */
3921 thumb_pos.Width = 10;
3922 thumb_pos.Height = 22;
3924 switch (tb.TickStyle) {
3925 case TickStyle.BottomRight:
3926 case TickStyle.None: {
3927 thumb_pos.X = channel_startpoint.X - 8;
3929 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3930 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3931 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3933 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3934 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3936 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3937 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3939 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3940 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3941 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3942 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3946 case TickStyle.TopLeft: {
3947 thumb_pos.X = channel_startpoint.X - 10;
3949 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3950 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3952 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3953 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3954 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3956 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3957 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3958 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3960 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3961 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3962 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3963 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3968 case TickStyle.Both: {
3969 thumb_pos.X = area.X + 10;
3970 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3971 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3973 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3974 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3976 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3977 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3979 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3988 pixel_len = thumb_area.Height - 11;
3989 pixels_betweenticks = pixel_len / ticks;
3991 thumb_area.X = thumb_pos.X;
3992 thumb_area.Y = channel_startpoint.Y;
3993 thumb_area.Width = thumb_pos.Height;
3996 Region outside = new Region (area);
3997 outside.Exclude (thumb_area);
3999 if (outside.IsVisible (clip_rectangle)) {
4000 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4001 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4003 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4004 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4005 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
4006 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
4008 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
4009 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
4013 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4014 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4016 pixel_len = thumb_area.Height - 11;
4017 pixels_betweenticks = pixel_len / ticks;
4019 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4020 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4021 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
4022 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4024 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
4025 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4037 Does not matter the size of the control, Win32 always draws:
4038 - Ticks starting from pixel 13, 8
4039 - Channel starting at pos 8, 19 and ends at Width - 8
4040 - Autosize makes always the control 40 pixels height
4041 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4044 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
4045 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
4046 float ticks, int value_pos, bool mouse_value) {
4047 Point toptick_startpoint = new Point ();
4048 Point bottomtick_startpoint = new Point ();
4049 Point channel_startpoint = new Point ();
4051 float pixels_betweenticks;
4052 const int space_from_right = 8;
4053 const int space_from_left = 8;
4054 Rectangle area = tb.ClientRectangle;
4056 switch (tb.TickStyle) {
4057 case TickStyle.BottomRight:
4058 case TickStyle.None:
4059 channel_startpoint.X = 8;
4060 channel_startpoint.Y = 9;
4061 bottomtick_startpoint.X = 13;
4062 bottomtick_startpoint.Y = 24;
4064 case TickStyle.TopLeft:
4065 channel_startpoint.X = 8;
4066 channel_startpoint.Y = 19;
4067 toptick_startpoint.X = 13;
4068 toptick_startpoint.Y = 8;
4070 case TickStyle.Both:
4071 channel_startpoint.X = 8;
4072 channel_startpoint.Y = 18;
4073 bottomtick_startpoint.X = 13;
4074 bottomtick_startpoint.Y = 32;
4075 toptick_startpoint.X = 13;
4076 toptick_startpoint.Y = 8;
4082 thumb_area.X = area.X + channel_startpoint.X;
4083 thumb_area.Y = area.Y + channel_startpoint.Y;
4084 thumb_area.Width = area.Width - space_from_right - space_from_left;
4085 thumb_area.Height = 4;
4088 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
4089 thumb_area.Width, 1);
4091 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X, channel_startpoint.Y + 1,
4092 thumb_area.Width, 1);
4094 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X, channel_startpoint.Y +3,
4095 thumb_area.Width, 1);
4097 pixel_len = thumb_area.Width - 11;
4098 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4100 /* Convert thumb position from mouse position to value*/
4102 if (value_pos >= channel_startpoint.X)
4103 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4107 if (value_pos + tb.Minimum > tb.Maximum)
4108 value_pos = tb.Maximum - tb.Minimum;
4110 tb.Value = value_pos + tb.Minimum;
4113 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4115 /* Draw thumb fixed 10x22 size */
4116 thumb_pos.Width = 10;
4117 thumb_pos.Height = 22;
4119 switch (tb.TickStyle) {
4120 case TickStyle.BottomRight:
4121 case TickStyle.None: {
4122 thumb_pos.Y = channel_startpoint.Y - 8;
4124 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4125 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4126 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4128 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4129 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4131 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4132 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4134 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4135 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4136 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4137 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4140 case TickStyle.TopLeft: {
4141 thumb_pos.Y = channel_startpoint.Y - 10;
4143 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4144 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4146 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4147 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4148 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4150 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4151 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4152 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4154 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4155 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4156 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4157 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4161 case TickStyle.Both: {
4162 thumb_pos.Y = area.Y + 10;
4163 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4164 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4166 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4167 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4169 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4170 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4172 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4181 pixel_len = thumb_area.Width - 11;
4182 pixels_betweenticks = pixel_len / ticks;
4185 thumb_area.Y = thumb_pos.Y;
4186 thumb_area.X = channel_startpoint.X;
4187 thumb_area.Height = thumb_pos.Height;
4188 Region outside = new Region (area);
4189 outside.Exclude (thumb_area);
4191 if (outside.IsVisible (clip_rectangle)) {
4192 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4193 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4195 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4196 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4197 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4198 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4200 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4201 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4205 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4206 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4208 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4209 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4210 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4211 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4213 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4214 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4222 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4227 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4229 Rectangle thumb_pos = tb.ThumbPos;
4230 Rectangle thumb_area = tb.ThumbArea;
4232 if (tb.thumb_pressed) {
4233 value_pos = tb.thumb_mouseclick;
4236 value_pos = tb.Value - tb.Minimum;
4237 mouse_value = false;
4240 area = tb.ClientRectangle;
4242 if (tb.thumb_pressed == true) {
4243 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4245 br_thumb = ResPool.GetSolidBrush (ColorControl);
4249 /* Control Background */
4250 if (tb.BackColor == DefaultControlBackColor) {
4251 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
4253 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4258 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, area.Width - 1, 1);
4259 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4260 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, 1, area.Height - 1);
4261 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4264 if (tb.Orientation == Orientation.Vertical) {
4265 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4266 br_thumb, ticks, value_pos, mouse_value);
4269 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4270 br_thumb, ticks, value_pos, mouse_value);
4273 tb.ThumbPos = thumb_pos;
4274 tb.ThumbArea = thumb_area;
4277 public override Size TrackBarDefaultSize {
4279 return new Size (104, 42);
4283 #endregion // TrackBar
4286 public override Size VScrollBarDefaultSize {
4288 return new Size (this.ScrollBarButtonSize, 80);
4291 #endregion // VScrollBar
4294 public override Size TreeViewDefaultSize {
4296 return new Size (121, 97);
4302 #region ControlPaint
4303 private enum DrawFrameControlStates {
4304 ButtonCheck = 0x0000,
4305 ButtonRadioImage = 0x0001,
4306 ButtonRadioMask = 0x0002,
4307 ButtonRadio = 0x0004,
4308 Button3State = 0x0008,
4309 ButtonPush = 0x0010,
4311 CaptionClose = 0x0000,
4312 CaptionMin = 0x0001,
4313 CaptionMax = 0x0002,
4314 CaptionRestore = 0x0004,
4315 CaptionHelp = 0x0008,
4319 MenuBullet = 0x0002,
4320 MenuArrowRight = 0x0004,
4323 ScrollDown = 0x0001,
4324 ScrollLeft = 0x0002,
4325 ScrollRight = 0x0003,
4326 ScrollComboBox = 0x0005,
4327 ScrollSizeGrip = 0x0008,
4328 ScrollSizeGripRight = 0x0010,
4333 Transparent = 0x0800,
4335 AdjustRect = 0x2000,
4341 private enum DrawFrameControlTypes {
4348 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4349 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4350 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4351 int bottomWidth, ButtonBorderStyle bottomStyle) {
4352 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4353 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4354 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4355 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4358 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4359 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4362 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
4365 Pen penTopLeftInner;
4367 Pen penBottomRightInner;
4368 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4370 if ((style & Border3DStyle.Adjust) != 0) {
4377 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = ResPool.GetPen (control_color);
4379 CPColor cpcolor = ResPool.GetCPColor (control_color);
4382 case Border3DStyle.Raised:
4383 penTopLeftInner = ResPool.GetPen (cpcolor.LightLight);
4384 penBottomRight = ResPool.GetPen (cpcolor.DarkDark);
4385 penBottomRightInner = ResPool.GetPen (cpcolor.Dark);
4387 case Border3DStyle.Sunken:
4388 penTopLeft = ResPool.GetPen (cpcolor.Dark);
4389 penTopLeftInner = ResPool.GetPen (cpcolor.DarkDark);
4390 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
4392 case Border3DStyle.Etched:
4393 penTopLeft = penBottomRightInner = ResPool.GetPen (cpcolor.Dark);
4394 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.LightLight);
4396 case Border3DStyle.RaisedOuter:
4397 penBottomRight = ResPool.GetPen (cpcolor.DarkDark);
4399 case Border3DStyle.SunkenOuter:
4400 penTopLeft = ResPool.GetPen (cpcolor.Dark);
4401 penBottomRight = ResPool.GetPen (cpcolor.LightLight);
4403 case Border3DStyle.RaisedInner:
4404 penTopLeft = ResPool.GetPen (cpcolor.LightLight);
4405 penBottomRight = ResPool.GetPen (cpcolor.Dark);
4407 case Border3DStyle.SunkenInner:
4408 penTopLeft = ResPool.GetPen (cpcolor.DarkDark);
4410 case Border3DStyle.Flat:
4411 penTopLeft = penBottomRight = ResPool.GetPen (cpcolor.Dark);
4413 case Border3DStyle.Bump:
4414 penTopLeftInner = penBottomRight = ResPool.GetPen (cpcolor.DarkDark);
4420 if ((sides & Border3DSide.Middle) != 0) {
4421 graphics.FillRectangle (ResPool.GetSolidBrush (control_color), rect);
4424 if ((sides & Border3DSide.Left) != 0) {
4425 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
4426 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
4429 if ((sides & Border3DSide.Top) != 0) {
4430 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
4431 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
4434 if ((sides & Border3DSide.Right) != 0) {
4435 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
4436 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
4439 if ((sides & Border3DSide.Bottom) != 0) {
4440 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4441 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
4445 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4446 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
4448 if ((state & ButtonState.Pushed)!=0) {
4449 dfcs |= DrawFrameControlStates.Pushed;
4452 if ((state & ButtonState.Checked)!=0) {
4453 dfcs |= DrawFrameControlStates.Checked;
4456 if ((state & ButtonState.Flat)!=0) {
4457 dfcs |= DrawFrameControlStates.Flat;
4460 if ((state & ButtonState.Inactive)!=0) {
4461 dfcs |= DrawFrameControlStates.Inactive;
4463 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4467 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4468 Rectangle captionRect;
4471 CPDrawButton(graphics, rectangle, state);
4473 if (rectangle.Width<rectangle.Height) {
4474 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4476 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4479 if ((state & ButtonState.Pushed)!=0) {
4480 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4483 /* Make sure we've got at least a line width of 1 */
4484 lineWidth=Math.Max(1, captionRect.Width/7);
4487 case CaptionButton.Close: {
4490 if ((state & ButtonState.Inactive)!=0) {
4491 pen=new Pen(ColorControlLight, lineWidth);
4492 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4495 pen=new Pen(ColorControlDark, lineWidth);
4496 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4500 pen=new Pen(ColorControlText, lineWidth);
4501 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4507 case CaptionButton.Help:
4508 case CaptionButton.Maximize:
4509 case CaptionButton.Minimize:
4510 case CaptionButton.Restore: {
4511 if ((state & ButtonState.Inactive)!=0) {
4512 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4514 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4517 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4525 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
4526 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
4528 if ((state & ButtonState.Pushed)!=0) {
4529 dfcs |= DrawFrameControlStates.Pushed;
4532 if ((state & ButtonState.Checked)!=0) {
4533 dfcs |= DrawFrameControlStates.Checked;
4536 if ((state & ButtonState.Flat)!=0) {
4537 dfcs |= DrawFrameControlStates.Flat;
4540 if ((state & ButtonState.Inactive)!=0) {
4541 dfcs |= DrawFrameControlStates.Inactive;
4544 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4548 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4549 Point[] arrow = new Point[3];
4559 if ((state & ButtonState.Checked)!=0) {
4560 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4563 if ((state & ButtonState.Flat)!=0) {
4564 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4566 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4567 // this needs to render like a pushed button - jba
4568 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4569 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4570 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
4572 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4576 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4577 centerX=rect.Left+rect.Width/2;
4578 centerY=rect.Top+rect.Height/2;
4579 shiftX=Math.Max(1, rect.Width/8);
4580 shiftY=Math.Max(1, rect.Height/8);
4582 if ((state & ButtonState.Pushed)!=0) {
4589 P1=new Point(rect.Left, centerY);
4590 P2=new Point(rect.Right, centerY);
4591 P3=new Point(centerX, rect.Bottom);
4597 /* Draw the arrow */
4598 if ((state & ButtonState.Inactive)!=0) {
4599 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4601 /* Move away from the shadow */
4611 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4613 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4618 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
4620 Pen pen = new Pen(Color.Black, 1);
4621 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
4625 graphics.FillRectangle(ResPool.GetSolidBrush (ColorControlText), rect);
4626 graphics.DrawRectangle(pen, rect);
4628 X=rect.X+rect.Width/2;
4629 Y=rect.Y+rect.Height/2;
4631 /* Draw the cross */
4632 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
4633 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
4635 /* Draw 'arrows' for vertical lines */
4636 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
4637 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
4639 /* Draw 'arrows' for horizontal lines */
4640 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
4641 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
4646 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4647 // make a rectange to trace around border of the button
4648 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4650 Color outerColor = foreColor;
4651 // adjust focus color according to the flatstyle
4652 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4653 outerColor = (backColor == ColorControl) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4656 // draw the outer rectangle
4657 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4659 // draw the inner rectangle
4660 if (button.FlatStyle == FlatStyle.Popup) {
4661 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4663 // draw a flat inner rectangle
4664 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4665 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4669 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4671 // make a rectange to trace around border of the button
4672 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4674 #if NotUntilCairoIsFixed
4675 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4676 DashStyle oldStyle; // used for caching old penstyle
4677 Pen pen = ResPool.GetPen (colorBackInverted);
4679 oldStyle = pen.DashStyle;
4680 pen.DashStyle = DashStyle.Dot;
4682 graphics.DrawRectangle (pen, trace_rectangle);
4683 pen.DashStyle = oldStyle;
4685 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4690 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4692 Rectangle rect = rectangle;
4696 if (backColor.GetBrightness () >= 0.5) {
4697 foreColor = Color.Transparent;
4698 backColor = Color.Black;
4701 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4702 foreColor = Color.Black;
4705 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4706 pen = new Pen (brush, 1);
4711 graphics.DrawRectangle (pen, rect);
4715 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
4719 if (primary==true) {
4720 pen=new Pen(Color.Black, 1);
4721 if (enabled==true) {
4722 sb=ResPool.GetSolidBrush (ColorControlText);
4724 sb=ResPool.GetSolidBrush (ColorControl);
4727 pen=new Pen(Color.White, 1);
4728 if (enabled==true) {
4729 sb=ResPool.GetSolidBrush (Color.Black);
4731 sb=ResPool.GetSolidBrush (ColorControl);
4734 graphics.FillRectangle(sb, rectangle);
4735 graphics.DrawRectangle(pen, rectangle);
4740 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4746 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4749 foreColor=Color.Black;
4751 foreColor=Color.White;
4755 /* Commented out until I take the time and figure out
4756 which HatchStyle will match requirements. The code below
4757 is only correct for Percent50.
4759 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
4760 HatchBrush brush=null;
4762 switch(pixelsBetweenDots.Width) {
4763 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
4764 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
4765 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
4767 /* Have to do it the slow way */
4772 graphics.FillRectangle(brush, area);
4781 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4783 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4784 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4785 bitmap.SetPixel(x, y, foreColor);
4788 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4792 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4794 Microsoft seems to ignore the background and simply make
4795 the image grayscale. At least when having > 256 colors on
4799 if (imagedisabled_attributes == null) {
4800 imagedisabled_attributes = new ImageAttributes ();
4801 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4802 // This table would create a perfect grayscale image, based on luminance
4803 // new float[]{0.3f,0.3f,0.3f,0,0},
4804 // new float[]{0.59f,0.59f,0.59f,0,0},
4805 // new float[]{0.11f,0.11f,0.11f,0,0},
4806 // new float[]{0,0,0,1,0,0},
4807 // new float[]{0,0,0,0,1,0},
4808 // new float[]{0,0,0,0,0,1}
4810 // This table generates a image that is grayscaled and then
4811 // brightened up. Seems to match MS close enough.
4812 new float[]{0.2f,0.2f,0.2f,0,0},
4813 new float[]{0.41f,0.41f,0.41f,0,0},
4814 new float[]{0.11f,0.11f,0.11f,0,0},
4815 new float[]{0.15f,0.15f,0.15f,1,0,0},
4816 new float[]{0.15f,0.15f,0.15f,0,1,0},
4817 new float[]{0.15f,0.15f,0.15f,0,0,1}
4820 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4823 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4828 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4833 penBorder=new Pen(Color.White, 2);
4834 penInside=new Pen(Color.Black, 1);
4836 penBorder=new Pen(Color.Black, 2);
4837 penInside=new Pen(Color.White, 1);
4839 penBorder.Alignment=PenAlignment.Inset;
4840 penInside.Alignment=PenAlignment.Inset;
4842 graphics.DrawRectangle(penBorder, rectangle);
4843 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4844 penBorder.Dispose();
4845 penInside.Dispose();
4849 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
4853 Brush brush = ResPool.GetSolidBrush (color);
4856 case MenuGlyph.Arrow: {
4857 Point[] arrow = new Point[3];
4865 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4866 centerX=rect.Left+rect.Width/2;
4867 centerY=rect.Top+rect.Height/2;
4868 shiftX=Math.Max(1, rect.Width/8);
4873 P1=new Point(centerX, rect.Top-1);
4874 P2=new Point(centerX, rect.Bottom);
4875 P3=new Point(rect.Right, centerY);
4881 graphics.FillPolygon(brush, arrow, FillMode.Winding);
4886 case MenuGlyph.Bullet: {
4888 lineWidth=Math.Max(2, rectangle.Width/3);
4889 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4891 graphics.FillEllipse(brush, rect);
4896 case MenuGlyph.Checkmark: {
4898 Pen pen = ResPool.GetPen (color);
4900 lineWidth=Math.Max(2, rectangle.Width/6);
4901 Scale=Math.Max(1, rectangle.Width/12);
4903 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4905 for (int i=0; i<lineWidth; i++) {
4906 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4907 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);
4915 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4916 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
4918 if ((state & ButtonState.Pushed)!=0) {
4919 dfcs |= DrawFrameControlStates.Pushed;
4922 if ((state & ButtonState.Checked)!=0) {
4923 dfcs |= DrawFrameControlStates.Checked;
4926 if ((state & ButtonState.Flat)!=0) {
4927 dfcs |= DrawFrameControlStates.Flat;
4930 if ((state & ButtonState.Inactive)!=0) {
4931 dfcs |= DrawFrameControlStates.Inactive;
4934 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4939 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4944 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4949 /* Scroll button: regular button + direction arrow */
4950 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4951 DrawScrollButtonPrimitive (dc, area, state);
4953 int arrow_y_pos_diff = 3;
4956 case ScrollButton.Up:
4957 arrow_y_pos_diff = 2;
4959 case ScrollButton.Down:
4960 arrow_y_pos_diff = 4;
4966 // A lot of the following is adapted from the rewind project
4967 Rectangle rect = new Rectangle (area.X - 3, area.Y - arrow_y_pos_diff,
4968 area.Width + 6, area.Height + 6);
4969 int small_diam = rect.Width > rect.Height ? rect.Height : rect.Width;
4970 if (rect.Width < rect.Height) {
4971 rect.Y += (rect.Height - rect.Width) / 2;
4972 rect.Height = small_diam;
4973 } else if (rect.Width > rect.Height) {
4974 rect.X += (rect.Width - rect.Height) / 2;
4975 rect.Width = small_diam;
4980 int tri = 290 * small_diam / 1000 - 1;
4984 Point [] arrow = new Point [3];
4985 for (int i = 0; i < 3; i++)
4986 arrow [i] = new Point ();
4990 case ScrollButton.Down:
4991 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
4992 arrow [2].Y = rect.Top + 687 * small_diam / 1000 + 1;
4993 arrow [0].X = arrow [2].X - tri;
4994 arrow [1].X = arrow [2].X + tri;
4995 arrow [0].Y = arrow [1].Y = arrow [2].Y - tri;
4998 case ScrollButton.Up:
4999 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
5000 arrow [2].Y = rect.Bottom - (687 * small_diam / 1000 + 1);
5001 arrow [0].X = arrow [2].X - tri;
5002 arrow [1].X = arrow [2].X + tri;
5003 arrow [0].Y = arrow [1].Y = arrow [2].Y + tri;
5006 case ScrollButton.Left:
5007 arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
5008 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
5009 arrow [0].Y = arrow [2].Y - tri;
5010 arrow [1].Y = arrow [2].Y + tri;
5011 arrow [0].X = arrow [1].X = arrow [2].X + tri;
5013 // Left and Right are not drawn correctly because of libgdiplus problems
5014 // once that is solved change it to the code below to match ms
5015 // case ScrollButton.Left:
5016 // arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
5017 // arrow [2].Y = (rect.Top + 470 * small_diam / 1000 + 2) - 1;
5018 // arrow [1].Y = arrow [2].Y + tri;
5019 // arrow [0].Y = arrow [2].Y - tri + 1;
5020 // arrow [0].X = arrow [1].X = arrow [2].X + tri;
5022 case ScrollButton.Right:
5023 arrow [2].X = rect.Left + 687 * small_diam / 1000 + 1;
5024 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
5025 arrow [0].Y = arrow [2].Y - tri;
5026 arrow [1].Y = arrow [2].Y + tri;
5027 arrow [0].X = arrow [1].X = arrow [2].X - tri;
5031 /* Draw the arrow */
5032 if ((state & ButtonState.Inactive)!=0) {
5033 dc.FillPolygon (SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
5035 for (int i = 0; i < 3; i++) {
5040 dc.FillPolygon (SystemBrushes.ControlDark, arrow, FillMode.Winding);
5042 dc.FillPolygon (SystemBrushes.ControlText, arrow, FillMode.Winding);
5046 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5052 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
5054 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
5056 Pen pen = ResPool.GetPen (ColorControlDark);
5058 dc.DrawLine (pen, pt.X - 11, pt.Y, pt.X, pt.Y - 11);
5059 dc.DrawLine (pen, pt.X - 10, pt.Y, pt.X, pt.Y - 10);
5061 dc.DrawLine (pen, pt.X - 7, pt.Y, pt.X, pt.Y - 7);
5062 dc.DrawLine (pen, pt.X - 6, pt.Y, pt.X, pt.Y - 6);
5064 dc.DrawLine (pen, pt.X - 3, pt.Y, pt.X, pt.Y - 3);
5065 dc.DrawLine (pen, pt.X - 2, pt.Y, pt.X, pt.Y - 2);
5067 pen = ResPool.GetPen (ColorControlLight);
5069 dc.DrawLine (pen, pt.X - 12, pt.Y, pt.X, pt.Y - 12);
5070 dc.DrawLine (pen, pt.X - 8, pt.Y, pt.X, pt.Y - 8);
5071 dc.DrawLine (pen, pt.X - 4, pt.Y, pt.X, pt.Y - 4);
5073 dc.DrawLine (ResPool.GetPen (ColorControl), pt.X - 12, pt.Y, pt.X, pt.Y);
5077 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
5078 StringFormat format) {
5080 graphics.DrawString(s, font, ResPool.GetSolidBrush (ColorGrayText), layoutRectangle, format);
5084 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5085 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5087 Pen pen=new Pen(color, 1);
5090 case ButtonBorderStyle.Solid: {
5091 pen.DashStyle=DashStyle.Solid;
5095 case ButtonBorderStyle.Dashed: {
5096 pen.DashStyle=DashStyle.Dash;
5100 case ButtonBorderStyle.Dotted: {
5101 pen.DashStyle=DashStyle.Dot;
5105 case ButtonBorderStyle.Inset: {
5106 pen.DashStyle=DashStyle.Solid;
5110 case ButtonBorderStyle.Outset: {
5111 pen.DashStyle=DashStyle.Solid;
5116 case ButtonBorderStyle.None: {
5124 case ButtonBorderStyle.Outset: {
5126 int hue, brightness, saturation;
5127 int brightnessSteps;
5128 int brightnessDownSteps;
5130 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5132 brightnessDownSteps=brightness/width;
5133 if (brightness>127) {
5134 brightnessSteps=Math.Max(6, (160-brightness)/width);
5136 brightnessSteps=(127-brightness)/width;
5139 for (int i=0; i<width; i++) {
5141 case Border3DSide.Left: {
5143 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5144 pen=new Pen(colorGrade, 1);
5145 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5149 case Border3DSide.Right: {
5151 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5152 pen=new Pen(colorGrade, 1);
5153 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5157 case Border3DSide.Top: {
5159 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5160 pen=new Pen(colorGrade, 1);
5161 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5165 case Border3DSide.Bottom: {
5167 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5168 pen=new Pen(colorGrade, 1);
5169 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5177 case ButtonBorderStyle.Inset: {
5179 int hue, brightness, saturation;
5180 int brightnessSteps;
5181 int brightnessDownSteps;
5183 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5185 brightnessDownSteps=brightness/width;
5186 if (brightness>127) {
5187 brightnessSteps=Math.Max(6, (160-brightness)/width);
5189 brightnessSteps=(127-brightness)/width;
5192 for (int i=0; i<width; i++) {
5194 case Border3DSide.Left: {
5196 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5197 pen=new Pen(colorGrade, 1);
5198 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5202 case Border3DSide.Right: {
5204 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5205 pen=new Pen(colorGrade, 1);
5206 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5210 case Border3DSide.Top: {
5212 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5213 pen=new Pen(colorGrade, 1);
5214 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5218 case Border3DSide.Bottom: {
5220 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5221 pen=new Pen(colorGrade, 1);
5222 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5231 I decided to have the for-loop duplicated for speed reasons;
5232 that way we only have to switch once (as opposed to have the
5233 for-loop around the switch)
5237 case Border3DSide.Left: {
5238 for (int i=0; i<width; i++) {
5239 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5244 case Border3DSide.Right: {
5245 for (int i=0; i<width; i++) {
5246 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5251 case Border3DSide.Top: {
5252 for (int i=0; i<width; i++) {
5253 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5258 case Border3DSide.Bottom: {
5259 for (int i=0; i<width; i++) {
5260 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5272 This function actually draws the various caption elements.
5273 This way we can scale them nicely, no matter what size, and they
5274 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5277 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5279 case CaptionButton.Close: {
5280 pen.StartCap=LineCap.Triangle;
5281 pen.EndCap=LineCap.Triangle;
5283 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);
5284 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);
5287 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5288 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5292 case CaptionButton.Help: {
5293 StringFormat sf = new StringFormat();
5294 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5296 sf.Alignment=StringAlignment.Center;
5297 sf.LineAlignment=StringAlignment.Center;
5300 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5308 case CaptionButton.Maximize: {
5309 /* Top 'caption bar' line */
5310 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5311 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);
5314 /* Left side line */
5315 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5316 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5319 /* Right side line */
5320 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5321 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);
5325 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5326 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5331 case CaptionButton.Minimize: {
5333 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5334 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5339 case CaptionButton.Restore: {
5340 /** First 'window' **/
5341 /* Top 'caption bar' line */
5342 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5343 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);
5346 /* Left side line */
5347 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5348 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);
5351 /* Right side line */
5352 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5353 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);
5357 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5358 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);
5361 /** Second 'window' **/
5362 /* Top 'caption bar' line */
5363 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5364 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);
5367 /* Left side line */
5368 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5369 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5372 /* Right side line */
5373 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5374 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);
5378 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5379 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5388 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
5389 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
5390 // make a rectange to trace around border of the button
5391 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
5393 case DrawFrameControlTypes.Button: {
5395 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
5396 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
5397 // /* Goes first, affects the background */
5398 // if ((State & DrawFrameControlStates.Checked)!=0) {
5399 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
5400 // graphics.FillRectangle(hatchBrush,rectangle);
5401 // hatchBrush.Dispose();
5404 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
5405 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
5406 } else if ((State & DrawFrameControlStates.Flat)!=0) {
5407 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
5409 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5410 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
5411 Pen penFatDark = new Pen(ColorControlDark, 1);
5412 Pen penFatLight = new Pen(ColorControlLightLight, 1);
5415 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
5417 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
5418 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
5420 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
5421 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
5423 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
5425 if ((State & DrawFrameControlStates.Checked)!=0) {
5426 SolidBrush buttonBrush;
5428 if ((State & DrawFrameControlStates.Inactive)!=0) {
5429 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
5431 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
5433 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
5435 penFatDark.Dispose();
5436 penFatLight.Dispose();
5437 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
5438 throw new NotImplementedException () ;
5439 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
5440 throw new NotImplementedException ();
5441 } else { /* Must be Checkbox */
5447 /* Goes first, affects the background */
5448 if ((State & DrawFrameControlStates.Pushed)!=0 ||
5449 (State & DrawFrameControlStates.Inactive)!=0) {
5450 graphics.FillRectangle(SystemBrushes.Control, rectangle);
5452 graphics.FillRectangle(SystemBrushes.Window, rectangle);
5455 /* Draw the sunken frame */
5456 if ((State & DrawFrameControlStates.Flat)!=0) {
5457 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
5459 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5462 /* Make sure we've got at least a line width of 1 */
5463 lineWidth=Math.Max(3, rectangle.Width/6);
5464 Scale=Math.Max(1, rectangle.Width/12);
5466 // define a rectangle inside the border area
5467 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
5468 if ((State & DrawFrameControlStates.Inactive)!=0) {
5469 pen=SystemPens.ControlDark;
5471 pen=SystemPens.ControlText;
5474 if ((State & DrawFrameControlStates.Checked)!=0) {
5475 /* Need to draw a check-mark */
5476 for (int i=0; i<lineWidth; i++) {
5477 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5478 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);
5486 case DrawFrameControlTypes.Caption: {
5491 case DrawFrameControlTypes.Menu: {
5496 case DrawFrameControlTypes.Scroll: {
5503 /* Generic scroll button */
5504 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5505 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5506 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 1,
5507 area.Y + 1, area.Width - 2 , area.Height - 2);
5509 dc.DrawRectangle (ResPool.GetPen (ColorControlDark), area.X,
5510 area.Y, area.Width, area.Height);
5515 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, area.Width, 1);
5516 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, 1, area.Height);
5518 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 1, area.Width - 1, 1);
5519 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 2, 1,
5522 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + 1, area.Y + area.Height - 2,
5525 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X, area.Y + area.Height -1,
5528 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + area.Width - 2,
5529 area.Y + 1, 1, area.Height -3);
5531 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X + area.Width -1,
5532 area.Y, 1, area.Height - 1);
5534 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 2,
5535 area.Y + 2, area.Width - 4, area.Height - 4);
5539 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5540 switch (border_style){
5541 case BorderStyle.Fixed3D:
5542 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5543 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5544 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5545 area.Y + area.Height - 1);
5546 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5547 area.Y + area.Height);
5549 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5550 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5551 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5552 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5554 case BorderStyle.FixedSingle:
5555 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5557 case BorderStyle.None:
5563 #endregion // ControlPaint