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 ImageAttributes imagedisabled_attributes = null;
55 const int SEPARATOR_HEIGHT = 5;
56 const int SM_CXBORDER = 1;
57 const int SM_CYBORDER = 1;
58 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
59 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
61 #region Principal Theme Methods
62 public ThemeWin32Classic ()
64 defaultWindowBackColor = this.ColorWindow;
65 defaultWindowForeColor = this.ColorControlText;
66 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
68 /* Menu string formats */
69 string_format_menu_text = new StringFormat ();
70 string_format_menu_text.LineAlignment = StringAlignment.Center;
71 string_format_menu_text.Alignment = StringAlignment.Near;
72 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
74 string_format_menu_shortcut = new StringFormat ();
75 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
76 string_format_menu_shortcut.Alignment = StringAlignment.Far;
78 string_format_menu_menubar_text = new StringFormat ();
79 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
80 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
81 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
82 always_draw_hotkeys = false;
85 public override void ResetDefaults() {
86 throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
89 public override bool DoubleBufferingSupported {
93 public override int HorizontalScrollBarHeight {
95 return XplatUI.HorizontalScrollBarHeight;
99 public override int VerticalScrollBarWidth {
101 return XplatUI.VerticalScrollBarWidth;
105 #endregion // Principal Theme Methods
107 #region Internal Methods
108 protected Brush GetControlBackBrush (Color c) {
109 if (c == DefaultControlBackColor)
110 return SystemBrushes.Control;
111 return ResPool.GetSolidBrush (c);
114 protected Brush GetControlForeBrush (Color c) {
115 if (c == DefaultControlForeColor)
116 return SystemBrushes.ControlText;
117 return ResPool.GetSolidBrush (c);
119 #endregion // Internal Methods
121 #region OwnerDraw Support
122 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
124 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
125 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
129 e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
132 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
134 if (e.State == DrawItemState.Focus)
135 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
137 #endregion // OwnerDraw Support
140 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
142 // Fill the button with the correct color
143 bool is_ColorControl = button.BackColor == ColorControl ? true : false;
144 dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
146 // First, draw the image
147 if ((button.image != null) || (button.image_list != null))
148 ButtonBase_DrawImage(button, dc);
150 // Draw the button: Draw border, etc.
151 ButtonBase_DrawButton(button, dc);
153 // Draw the focus rectangle
154 if ((button.has_focus || button.paint_as_acceptbutton) && button.is_enabled)
155 ButtonBase_DrawFocus(button, dc);
158 if (button.text != null && button.text != String.Empty)
159 ButtonBase_DrawText(button, dc);
162 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
164 Rectangle borderRectangle;
165 bool check_or_radio = false;
166 bool check_or_radio_checked = false;
168 bool is_ColorControl = button.BackColor == ColorControl ? true : false;
170 CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
172 if (button is CheckBox) {
173 check_or_radio = true;
174 check_or_radio_checked = ((CheckBox)button).Checked;
175 } else if (button is RadioButton) {
176 check_or_radio = true;
177 check_or_radio_checked = ((RadioButton)button).Checked;
180 if ((button.has_focus || button.paint_as_acceptbutton) && button.is_enabled && !check_or_radio) {
181 // shrink the rectangle for the normal button drawing inside the focus rectangle
182 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
184 borderRectangle = button.ClientRectangle;
187 if (button.FlatStyle == FlatStyle.Popup) {
188 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
189 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
190 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
191 Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
192 else if (button.is_pressed || check_or_radio_checked)
193 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
194 } else if (button.FlatStyle == FlatStyle.Flat) {
195 if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
196 if ((button.image == null) && (button.image_list == null)) {
197 Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
198 dc.FillRectangle (brush, borderRectangle);
200 } else if (button.is_pressed || check_or_radio_checked) {
201 if ((button.image == null) && (button.image_list == null)) {
202 Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
203 dc.FillRectangle (brush, borderRectangle);
206 Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
207 dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
208 borderRectangle.Width - 9, borderRectangle.Height - 9);
211 Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
213 if ((!button.is_pressed || !button.is_enabled) && !check_or_radio_checked)
214 Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
216 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
220 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
223 case 0: // normal or normal disabled button
224 Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
225 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
226 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
228 pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
229 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
230 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
232 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
233 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
234 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
236 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
237 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
238 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
240 case 1: // popup button normal (or pressed normal or popup button)
241 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
242 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
244 case 2: // popup button poped up
245 pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
246 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
247 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
249 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
250 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
251 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
253 case 3: // flat button not entered
254 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
255 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
262 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
264 // Need to draw a picture
271 int width = button.ClientSize.Width;
272 int height = button.ClientSize.Height;
274 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
275 i = button.image_list.Images[button.image_index];
280 image_width = i.Width;
281 image_height = i.Height;
283 switch (button.image_alignment) {
284 case ContentAlignment.TopLeft: {
290 case ContentAlignment.TopCenter: {
291 image_x = (width - image_width) / 2;
296 case ContentAlignment.TopRight: {
297 image_x = width - image_width - 5;
302 case ContentAlignment.MiddleLeft: {
304 image_y = (height - image_height) / 2;
308 case ContentAlignment.MiddleCenter: {
309 image_x = (width - image_width) / 2;
310 image_y = (height - image_height) / 2;
314 case ContentAlignment.MiddleRight: {
315 image_x = width - image_width - 4;
316 image_y = (height - image_height) / 2;
320 case ContentAlignment.BottomLeft: {
322 image_y = height - image_height - 4;
326 case ContentAlignment.BottomCenter: {
327 image_x = (width - image_width) / 2;
328 image_y = height - image_height - 4;
332 case ContentAlignment.BottomRight: {
333 image_x = width - image_width - 4;
334 image_y = height - image_height - 4;
345 if (button.is_enabled) {
346 dc.DrawImage(i, image_x, image_y);
349 CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
353 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
355 Color focus_color = button.ForeColor;
357 if (button.FlatStyle == FlatStyle.Popup)
358 if (!button.is_pressed)
359 focus_color = ControlPaint.Dark(button.BackColor);
361 dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y,
362 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
365 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
367 Rectangle buttonRectangle = button.ClientRectangle;
368 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
370 if (button.is_pressed) {
375 if (button.is_enabled) {
376 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
378 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
379 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
381 CPDrawStringDisabled (dc, button.text, button.Font, button.BackColor, text_rect, button.text_format);
386 public override Size ButtonBaseDefaultSize {
388 return new Size (75, 23);
391 #endregion // ButtonBase
394 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
395 StringFormat text_format;
396 Rectangle client_rectangle;
397 Rectangle text_rectangle;
398 Rectangle checkbox_rectangle;
399 int checkmark_size=13;
400 int checkmark_space = 4;
402 client_rectangle = checkbox.ClientRectangle;
403 text_rectangle = client_rectangle;
404 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
406 text_format = new StringFormat();
407 text_format.Alignment=StringAlignment.Near;
408 text_format.LineAlignment=StringAlignment.Center;
409 text_format.HotkeyPrefix = HotkeyPrefix.Show;
411 /* Calculate the position of text and checkbox rectangle */
412 if (checkbox.appearance!=Appearance.Button) {
413 switch(checkbox.check_alignment) {
414 case ContentAlignment.BottomCenter: {
415 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
416 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
417 text_rectangle.X=client_rectangle.X;
418 text_rectangle.Width=client_rectangle.Width;
419 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
423 case ContentAlignment.BottomLeft: {
424 checkbox_rectangle.X=client_rectangle.Left;
425 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
426 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
427 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
431 case ContentAlignment.BottomRight: {
432 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
433 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
434 text_rectangle.X=client_rectangle.X;
435 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
439 case ContentAlignment.MiddleCenter: {
440 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
441 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
442 text_rectangle.X=client_rectangle.X;
443 text_rectangle.Width=client_rectangle.Width;
448 case ContentAlignment.MiddleLeft: {
449 checkbox_rectangle.X=client_rectangle.Left;
450 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
451 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
452 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
456 case ContentAlignment.MiddleRight: {
457 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
458 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
459 text_rectangle.X=client_rectangle.X;
460 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
464 case ContentAlignment.TopCenter: {
465 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
466 checkbox_rectangle.Y=client_rectangle.Top;
467 text_rectangle.X=client_rectangle.X;
468 text_rectangle.Width=client_rectangle.Width;
469 text_rectangle.Y=checkmark_size+checkmark_space;
470 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
474 case ContentAlignment.TopLeft: {
475 checkbox_rectangle.X=client_rectangle.Left;
476 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
477 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
481 case ContentAlignment.TopRight: {
482 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
483 text_rectangle.X=client_rectangle.X;
484 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
489 text_rectangle.X=client_rectangle.X;
490 text_rectangle.Width=client_rectangle.Width;
493 /* Set the horizontal alignment of our text */
494 switch(checkbox.text_alignment) {
495 case ContentAlignment.BottomLeft:
496 case ContentAlignment.MiddleLeft:
497 case ContentAlignment.TopLeft: {
498 text_format.Alignment=StringAlignment.Near;
502 case ContentAlignment.BottomCenter:
503 case ContentAlignment.MiddleCenter:
504 case ContentAlignment.TopCenter: {
505 text_format.Alignment=StringAlignment.Center;
509 case ContentAlignment.BottomRight:
510 case ContentAlignment.MiddleRight:
511 case ContentAlignment.TopRight: {
512 text_format.Alignment=StringAlignment.Far;
517 /* Set the vertical alignment of our text */
518 switch(checkbox.text_alignment) {
519 case ContentAlignment.TopLeft:
520 case ContentAlignment.TopCenter:
521 case ContentAlignment.TopRight: {
522 text_format.LineAlignment=StringAlignment.Near;
526 case ContentAlignment.BottomLeft:
527 case ContentAlignment.BottomCenter:
528 case ContentAlignment.BottomRight: {
529 text_format.LineAlignment=StringAlignment.Far;
533 case ContentAlignment.MiddleLeft:
534 case ContentAlignment.MiddleCenter:
535 case ContentAlignment.MiddleRight: {
536 text_format.LineAlignment=StringAlignment.Center;
541 ButtonState state = ButtonState.Normal;
542 if (checkbox.FlatStyle == FlatStyle.Flat) {
543 state |= ButtonState.Flat;
546 if (checkbox.Checked) {
547 state |= ButtonState.Checked;
550 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
551 state |= ButtonState.Checked;
552 state |= ButtonState.Pushed;
555 // finally make sure the pushed and inavtive states are rendered
556 if (!checkbox.Enabled) {
557 state |= ButtonState.Inactive;
559 else if (checkbox.is_pressed) {
560 state |= ButtonState.Pushed;
565 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
567 if ((checkbox.image != null) || (checkbox.image_list != null))
568 ButtonBase_DrawImage(checkbox, dc);
570 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
572 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
574 text_format.Dispose ();
577 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
579 Brush brush = checkbox.BackColor == ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
580 dc.FillRectangle (brush, checkbox.ClientRectangle);
581 // render as per normal button
582 if (checkbox.appearance==Appearance.Button) {
583 ButtonBase_DrawButton (checkbox, dc);
585 // establish if we are rendering a flat style of some sort
586 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
587 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
589 CPDrawCheckBox (dc, checkbox_rectangle, state);
594 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
596 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
597 text_format, checkbox.Appearance, checkbox.Checked);
600 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
602 // do nothing here. maybe an other theme needs it
605 // renders a checkBox with the Flat and Popup FlatStyle
606 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
610 Rectangle checkbox_rectangle;
611 Rectangle fill_rectangle;
615 // set up our rectangles first
616 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
617 // clip one pixel from bottom right for non popup rendered checkboxes
618 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
619 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));
621 // clip two pixels from bottom right for non popup rendered checkboxes
622 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
623 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));
627 // if disabled render in disabled state
628 if (checkbox.Enabled) {
629 // process the state of the checkbox
630 if (checkbox.is_entered || checkbox.Capture) {
631 // decide on which background color to use
632 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
633 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
634 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
635 if (!checkbox.is_pressed) {
636 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
638 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
640 // use regular window background color
641 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
644 // render the outer border
645 if (checkbox.FlatStyle == FlatStyle.Flat) {
646 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
648 // draw sunken effect
649 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
652 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
654 if (checkbox.FlatStyle == FlatStyle.Flat) {
655 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
657 // draw the outer border
658 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
662 if (checkbox.FlatStyle == FlatStyle.Popup) {
663 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
666 // draw disabled state,
667 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
670 if (checkbox.Checked) {
671 /* Need to draw a check-mark */
673 /* Make sure we've got at least a line width of 1 */
674 lineWidth = Math.Max(3, fill_rectangle.Width/3);
675 Scale=Math.Max(1, fill_rectangle.Width/9);
677 // flat style check box is rendered inside a rectangle shifted down by one
678 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
679 if (checkbox.Enabled) {
680 pen=ResPool.GetPen(checkbox.ForeColor);
682 pen=SystemPens.ControlDark;
685 for (int i=0; i<lineWidth; i++) {
686 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
687 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);
692 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
693 StringFormat text_format, Appearance appearance, bool ischecked)
695 // offset the text if it's pressed and a button
696 if (appearance == Appearance.Button) {
697 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
702 text_rectangle.Inflate (-4, -4);
705 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
707 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
708 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
709 text_format.FormatFlags |= StringFormatFlags.NoWrap;
711 if (button_base.Enabled) {
712 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
713 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
714 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
716 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
719 #endregion // CheckBox
721 #region CheckedListBox
723 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
725 Color back_color, fore_color;
726 Rectangle item_rect = e.Bounds;
731 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
732 state = ButtonState.Checked;
733 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
734 state |= ButtonState.Inactive;
736 state = ButtonState.Normal;
738 if (ctrl.ThreeDCheckBoxes == false)
739 state |= ButtonState.Flat;
741 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
742 ControlPaint.DrawCheckBox (e.Graphics,
743 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
744 checkbox_rect.Width, checkbox_rect.Height,
747 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
748 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
751 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
752 back_color = ColorHighlight;
753 fore_color = ColorHighlightText;
756 back_color = e.BackColor;
757 fore_color = e.ForeColor;
760 e.Graphics.FillRectangle (ResPool.GetSolidBrush
761 (back_color), item_rect);
763 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
764 ResPool.GetSolidBrush (fore_color),
765 item_rect, ctrl.StringFormat);
767 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
768 CPDrawFocusRectangle (e.Graphics, item_rect,
769 fore_color, back_color);
773 #endregion // CheckedListBox
776 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
778 Color back_color, fore_color;
779 Rectangle text_draw = e.Bounds;
780 StringFormat string_format = new StringFormat ();
781 string_format.FormatFlags = StringFormatFlags.LineLimit;
783 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
784 back_color = ColorHighlight;
785 fore_color = ColorHighlightText;
788 back_color = e.BackColor;
789 fore_color = e.ForeColor;
792 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
795 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
796 ResPool.GetSolidBrush (fore_color),
797 text_draw, string_format);
800 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
801 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
804 string_format.Dispose ();
809 public override int DataGridPreferredColumnWidth { get { return 75;} }
810 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
811 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
812 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
813 public override Color DataGridBackColor { get { return ColorWindow;} }
814 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
815 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
816 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
817 public override Color DataGridGridLineColor { get { return ColorControl;} }
818 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
819 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
820 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
821 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
822 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
823 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
824 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
825 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
827 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
830 if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
831 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
834 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
835 DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
836 DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
837 DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
839 // Paint scrollBar corner
840 if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
842 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
843 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
844 grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
846 if (pe.ClipRectangle.IntersectsWith (corner)) {
847 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
853 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
855 Rectangle modified_area = clip;
856 modified_area.Intersect (grid.grid_drawing.caption_area);
858 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
861 g.DrawString (grid.CaptionText, grid.CaptionFont,
862 ResPool.GetSolidBrush (grid.CaptionForeColor),
863 grid.grid_drawing.caption_area);
866 public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
868 Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
870 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
871 Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
872 rect_bloc.Width = grid.RowHeaderWidth;
873 rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
874 if (clip.IntersectsWith (rect_bloc)) {
875 if (grid.visiblecolumn_count > 0) {
876 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
878 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
882 columns_area.X += grid.RowHeaderWidth;
883 columns_area.Width -= grid.RowHeaderWidth;
887 Rectangle columnshdrs_area_complete = columns_area;
888 columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
890 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
891 columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
894 // Set column painting
895 Rectangle rect_columnhdr = new Rectangle ();
898 rect_columnhdr.Y = columns_area.Y;
899 rect_columnhdr.Height = columns_area.Height;
901 current_clip = new Region (columns_area);
902 g.Clip = current_clip;
903 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
904 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
906 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
907 rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
908 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
910 if (clip.IntersectsWith (rect_columnhdr) == false)
913 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
918 current_clip.Dispose ();
921 Rectangle not_usedarea = columnshdrs_area_complete;
922 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
923 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
924 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
928 public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
930 Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
931 rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
932 Rectangle rect_row = new Rectangle ();
933 rect_row.X = grid.grid_drawing.rowshdrs_area.X;
934 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
935 Rectangle not_usedarea = rowshdrs_area_complete;
937 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
941 g.SetClip (grid.grid_drawing.rowshdrs_area);
942 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
944 rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
945 rect_row.Height = grid.RowHeight;
946 rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
948 if (clip.IntersectsWith (rect_row)) {
949 DataGridPaintRowHeader (g, rect_row, row, grid);
954 not_usedarea.Height = grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
955 not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + grid.grid_drawing.rowshdrs_area.Height;
956 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
959 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
961 Point[] arrow = new Point[3];
963 int centerX, centerY, shiftX;
966 rect = new Rectangle (bounds.X + bounds.Width /4,
967 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
969 centerX = rect.Left + rect.Width / 2;
970 centerY = rect.Top + rect.Height / 2;
971 shiftX = Math.Max (1, rect.Width / 8);
974 P1 = new Point (centerX, rect.Top - 1);
975 P2 = new Point (centerX, rect.Bottom);
976 P3 = new Point (rect.Right, centerY);
981 g.FillPolygon (ResPool.GetSolidBrush
982 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
985 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
988 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
991 if (grid.FlatMode == false) {
994 g.DrawLine (ResPool.GetPen (ColorControlLight),
995 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
997 g.DrawLine (ResPool.GetPen (ColorControlLight),
998 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1000 g.DrawLine (ResPool.GetPen (ColorControlDark),
1001 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1003 g.DrawLine (ResPool.GetPen (ColorControlDark),
1004 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1007 if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
1009 g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1014 if (row == grid.CurrentCell.RowNumber) {
1016 if (grid.is_changing == true) {
1017 g.DrawString ("...", grid.Font,
1018 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1023 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1024 DataGridPaintRowHeaderArrow (g, rect, grid);
1030 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1032 Rectangle rect_row = new Rectangle ();
1033 Rectangle not_usedarea = new Rectangle ();
1034 rect_row.X = cells.X;
1036 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1038 if (grid.ShowEditRow && grid.RowsCount > 0) {
1042 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1046 rect_row.Height = grid.RowHeight;
1047 rect_row.Width = cells.Width;
1048 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1049 rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1050 if (clip.IntersectsWith (rect_row)) {
1051 DataGridPaintRow (g, row, rect_row, false, grid);
1055 if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
1056 rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
1057 if (clip.IntersectsWith (rect_row)) {
1058 DataGridPaintRow (g, rowcnt, rect_row, true, grid);
1062 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1063 not_usedarea.Y = rect_row.Y + rect_row.Height;
1064 not_usedarea.Width = rect_row.Width = cells.Width;
1065 not_usedarea.X = cells.X;
1067 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1070 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid)
1072 Rectangle rect_cell = new Rectangle ();
1074 Color backcolor, forecolor;
1075 Region prev_clip = g.Clip;
1076 Region current_clip;
1077 Rectangle not_usedarea = new Rectangle ();
1079 rect_cell.Y = row_rect.Y;
1080 rect_cell.Height = row_rect.Height;
1082 // PaintCells at row, column
1083 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1084 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1086 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1088 rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
1089 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1091 current_clip = new Region (row_rect);
1092 g.Clip = current_clip;
1094 if (grid.IsSelected (row)) {
1095 backcolor = grid.SelectionBackColor;
1096 forecolor = grid.SelectionForeColor;
1099 backcolor = grid.BackColor;
1101 backcolor = grid.AlternatingBackColor;
1104 forecolor = grid.ForeColor;
1108 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1109 ResPool.GetSolidBrush (backcolor),
1110 ResPool.GetSolidBrush (forecolor));
1113 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1114 ResPool.GetSolidBrush (backcolor),
1115 ResPool.GetSolidBrush (forecolor),
1116 grid.RightToLeft == RightToLeft.Yes);
1120 current_clip.Dispose ();
1123 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1125 not_usedarea.X = rect_cell.X + rect_cell.Width;
1126 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1127 not_usedarea.Y = row_rect.Y;
1128 not_usedarea.Height = row_rect.Height;
1129 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1134 #endregion // Datagrid
1136 #region DateTimePicker
1138 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1139 // if not showing the numeric updown control then render border
1140 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1141 // draw the outer border
1142 Rectangle button_bounds = dtp.ClientRectangle;
1143 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1145 // deflate by the border width
1146 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1147 button_bounds.Inflate (-2,-2);
1148 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1149 this.CPDrawComboButton (
1151 dtp.drop_down_arrow_rect,
1156 // render the date part
1157 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1158 // fill the background
1159 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
1161 // fill the currently highlighted area
1162 if (dtp.hilight_date_area != Rectangle.Empty) {
1163 dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
1166 // draw the text part
1167 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1168 StringFormat text_format = new StringFormat();
1169 text_format.LineAlignment = StringAlignment.Center;
1170 text_format.Alignment = StringAlignment.Near;
1171 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1172 text_format.Dispose ();
1176 #endregion // DateTimePicker
1179 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1180 StringFormat text_format;
1185 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
1187 text_format = new StringFormat();
1188 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1190 size = dc.MeasureString (box.Text, box.Font);
1191 width = ((int) size.Width) + 7;
1193 if (width > box.Width - 16)
1194 width = box.Width - 16;
1196 y = box.Font.Height / 2;
1199 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
1202 if (box.Text.Length != 0) {
1203 Pen pen = ResPool.GetPen (box.BackColor);
1204 dc.DrawLine (pen, 9, y, 8 + width, y);
1205 dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1);
1208 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1210 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
1211 new RectangleF (10, 0, width, box.Font.Height), text_format);
1215 text_format.Dispose ();
1218 public override Size GroupBoxDefaultSize {
1220 return new Size (200,100);
1226 public override Size HScrollBarDefaultSize {
1228 return new Size (80, this.ScrollBarButtonSize);
1232 #endregion // HScrollBar
1235 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1237 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1239 if (label.Enabled) {
1240 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1242 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
1247 public override Size LabelDefaultSize {
1249 return new Size (100, 23);
1255 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1259 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1261 for (int i = 0; i < label.num_pieces; i++) {
1263 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1267 color = label.GetLinkColor (label.pieces[i], i);
1269 if (label.pieces[i].link == null)
1270 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),
1271 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1273 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
1274 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1276 if (label.pieces[i].focused) {
1277 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1282 #endregion // LinkLabel
1285 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1287 Color back_color, fore_color;
1289 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1290 back_color = ColorHighlight;
1291 fore_color = ColorHighlightText;
1293 back_color = e.BackColor;
1294 fore_color = e.ForeColor;
1297 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1299 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1300 ResPool.GetSolidBrush (fore_color),
1301 e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
1303 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
1304 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1311 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1313 bool details = control.View == View.Details;
1315 dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);
1316 int first = control.FirstVisibleIndex;
1318 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1319 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1320 DrawListViewItem (dc, control, control.Items [i]);
1323 // draw the gridlines
1324 if (details && control.GridLines) {
1325 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1326 2 : control.Font.Height + 2;
1328 // draw vertical gridlines
1329 foreach (ColumnHeader col in control.Columns)
1330 dc.DrawLine (SystemPens.Control,
1331 col.Rect.Right, top,
1332 col.Rect.Right, control.TotalHeight);
1333 // draw horizontal gridlines
1334 ListViewItem last_item = null;
1335 foreach (ListViewItem item in control.Items) {
1336 dc.DrawLine (SystemPens.Control,
1337 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1338 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1342 // draw a line after at the bottom of the last item
1343 if (last_item != null) {
1344 dc.DrawLine (SystemPens.Control,
1345 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1346 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1348 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1352 // Draw corner between the two scrollbars
1353 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1354 Rectangle rect = new Rectangle ();
1355 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1356 rect.Width = control.v_scroll.Width;
1357 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1358 rect.Height = control.h_scroll.Height;
1359 dc.FillRectangle (SystemBrushes.Control, rect);
1362 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
1363 if (!box_select_rect.Size.IsEmpty)
1364 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
1368 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1370 bool details = (control.View == View.Details);
1372 // border is drawn directly in the Paint method
1373 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1374 dc.FillRectangle (GetControlBackBrush (control.BackColor),
1375 0, 0, control.TotalWidth, control.Font.Height + 5);
1376 if (control.Columns.Count > 0) {
1377 foreach (ColumnHeader col in control.Columns) {
1378 Rectangle rect = col.Rect;
1379 rect.X -= control.h_marker;
1381 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1382 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1384 state = ButtonState.Flat;
1385 this.CPDrawButton (dc, rect, state);
1388 if (rect.Width <= 0)
1390 dc.DrawString (col.Text, DefaultFont,
1391 SystemBrushes.ControlText,
1394 int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
1395 if (right < control.Right) {
1396 Rectangle rect = control.Columns [0].Rect;
1398 rect.Width = control.Right - right;
1400 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1401 state = ButtonState.Normal;
1403 state = ButtonState.Flat;
1404 CPDrawButton (dc, rect, state);
1410 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
1412 Rectangle rect = col.Rect;
1413 rect.X -= view.h_marker;
1414 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
1415 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
1418 if (rect.Width <= 0)
1420 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
1421 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
1422 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
1425 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1428 if (control.View == View.Details && control.Columns.Count > 0)
1429 col_offset = control.Columns [0].Rect.X;
1433 Rectangle rect_checkrect = item.CheckRectReal;
1434 rect_checkrect.X += col_offset;
1435 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
1436 icon_rect.X += col_offset;
1437 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1438 full_rect.X += col_offset;
1439 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1440 text_rect.X += col_offset;
1442 if (control.CheckBoxes) {
1443 if (control.StateImageList == null) {
1444 // Make sure we've got at least a line width of 1
1445 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1446 int scale = Math.Max (1, rect_checkrect.Width / 12);
1448 // set the checkbox background
1449 dc.FillRectangle (SystemBrushes.Window,
1451 // define a rectangle inside the border area
1452 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1453 rect_checkrect.Y + 2,
1454 rect_checkrect.Width - 4,
1455 rect_checkrect.Height - 4);
1456 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
1457 dc.DrawRectangle (pen, rect);
1459 // Need to draw a check-mark
1462 // adjustments to get the check-mark at the right place
1463 rect.X ++; rect.Y ++;
1464 // following logic is taken from DrawFrameControl method
1465 for (int i = 0; i < check_wd; i++) {
1466 dc.DrawLine (pen, rect.Left + check_wd / 2,
1467 rect.Top + check_wd + i,
1468 rect.Left + check_wd / 2 + 2 * scale,
1469 rect.Top + check_wd + 2 * scale + i);
1471 rect.Left + check_wd / 2 + 2 * scale,
1472 rect.Top + check_wd + 2 * scale + i,
1473 rect.Left + check_wd / 2 + 6 * scale,
1474 rect.Top + check_wd - 2 * scale + i);
1479 if (item.Checked && control.StateImageList.Images.Count > 1)
1480 control.StateImageList.Draw (dc,
1481 rect_checkrect.Location, 1);
1482 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1483 control.StateImageList.Draw (dc,
1484 rect_checkrect.Location, 0);
1488 if (control.View == View.LargeIcon) {
1489 if (control.LargeImageList == null) {
1490 dc.DrawLine (ResPool.GetSizedPen (this.ColorWindowText, 2), icon_rect.Left, icon_rect.Y, icon_rect.Left + 11, icon_rect.Y);
1491 } else if (item.ImageIndex > -1 && item.ImageIndex < control.LargeImageList.Images.Count)
1492 control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1494 if (item.ImageIndex > -1 && control.SmallImageList != null &&
1495 item.ImageIndex < control.SmallImageList.Images.Count)
1496 control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1499 // draw the item text
1500 // format for the item text
1501 StringFormat format = new StringFormat ();
1502 if (control.View == View.SmallIcon)
1503 format.LineAlignment = StringAlignment.Near;
1505 format.LineAlignment = StringAlignment.Center;
1506 if (control.View == View.LargeIcon)
1507 format.Alignment = StringAlignment.Center;
1509 format.Alignment = StringAlignment.Near;
1511 if (!control.LabelWrap)
1512 format.FormatFlags = StringFormatFlags.NoWrap;
1514 if (item.Selected) {
1515 if (control.View == View.Details) {
1516 if (control.FullRowSelect) {
1517 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1520 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1522 text_rect.Width = text_size.Width;
1523 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1527 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1529 Point loc = text_rect.Location;
1530 loc.X += (text_rect.Width - text_size.Width) / 2;
1531 text_rect.Width = text_size.Width;*/
1532 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1536 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1538 if (item.Text != null && item.Text.Length > 0) {
1540 dc.DrawString (item.Text, item.Font, SystemBrushes.HighlightText, text_rect, format);
1542 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1543 (item.ForeColor), text_rect, format);
1546 if (control.View == View.Details && control.Columns.Count > 0) {
1547 // draw subitems for details view
1548 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1549 int count = (control.Columns.Count < subItems.Count ?
1550 control.Columns.Count : subItems.Count);
1554 ListViewItem.ListViewSubItem subItem;
1555 Rectangle sub_item_rect = text_rect;
1557 // set the format for subitems
1558 format.FormatFlags = StringFormatFlags.NoWrap;
1560 // 0th subitem is the item already drawn
1561 for (int index = 1; index < count; index++) {
1562 subItem = subItems [index];
1563 col = control.Columns [index];
1564 format.Alignment = col.Format.Alignment;
1565 sub_item_rect.X = col.Rect.X - control.h_marker;
1566 sub_item_rect.Width = col.Wd;
1567 Rectangle sub_item_text_rect = sub_item_rect;
1568 sub_item_text_rect.X += 3;
1569 sub_item_text_rect.Width -= 6;
1571 SolidBrush sub_item_back_br = null;
1572 SolidBrush sub_item_fore_br = null;
1573 Font sub_item_font = null;
1575 if (item.UseItemStyleForSubItems) {
1576 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
1577 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
1578 sub_item_font = item.Font;
1580 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
1581 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
1582 sub_item_font = subItem.Font;
1585 if (item.Selected && control.FullRowSelect) {
1586 dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
1587 if (subItem.Text != null && subItem.Text.Length > 0)
1588 dc.DrawString (subItem.Text, sub_item_font,
1589 SystemBrushes.HighlightText,
1590 sub_item_text_rect, format);
1592 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1593 if (subItem.Text != null && subItem.Text.Length > 0)
1594 dc.DrawString (subItem.Text, sub_item_font,
1596 sub_item_text_rect, format);
1603 Rectangle focus_rect = text_rect;
1604 if (control.FullRowSelect && control.View == View.Details) {
1606 foreach (ColumnHeader col in control.Columns)
1608 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
1611 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
1613 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
1620 public override Size ListViewCheckBoxSize {
1621 get { return new Size (16, 16); }
1624 public override int ListViewColumnHeaderHeight {
1628 public override int ListViewDefaultColumnWidth {
1632 public override int ListViewVerticalSpacing {
1636 public override int ListViewEmptyColumnWidth {
1640 public override int ListViewHorizontalSpacing {
1644 public override Size ListViewDefaultSize {
1645 get { return new Size (121, 97); }
1647 #endregion // ListView
1650 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1655 if (item.Visible == false) {
1661 if (item.Separator == true) {
1662 item.Height = SEPARATOR_HEIGHT / 2;
1667 if (item.MeasureEventDefined) {
1668 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1669 item.PerformMeasureItem (mi);
1670 item.Height = mi.ItemHeight;
1671 item.Width = mi.ItemWidth;
1675 size = dc.MeasureString (item.Text, MenuFont);
1676 item.Width = (int) size.Width;
1677 item.Height = (int) size.Height;
1680 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1681 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1682 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1683 item.Width += MENU_TAB_SPACE + (int) size.Width;
1686 item.Width += 4 + (MenuCheckSize.Width * 2);
1688 item.Width += MENU_BAR_ITEMS_SPACE;
1692 if (item.Height < MenuHeight)
1693 item.Height = MenuHeight;
1697 // Updates the menu rect and returns the height
1698 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1704 foreach (MenuItem item in menu.MenuItems) {
1706 CalcItemSize (dc, item, y, x, true);
1708 if (x + item.Width > width) {
1716 item.MenuBar = true;
1718 if (y + item.Height > menu.Height)
1719 menu.Height = item.Height + y;
1726 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1734 while (start < menu.MenuItems.Count) {
1737 for (i = start; i < menu.MenuItems.Count; i++) {
1738 MenuItem item = menu.MenuItems [i];
1740 if ((i != start) && (item.Break || item.BarBreak))
1743 CalcItemSize (dc, item, y, x, false);
1746 if (item.Width > max)
1750 // Replace the -1 by the menu width (separators)
1751 for (n = start; n < i; n++, start++)
1752 menu.MenuItems [n].Width = max;
1754 if (y > menu.Height)
1766 menu.Width += SM_CXBORDER;
1767 menu.Height += SM_CYBORDER;
1770 // Draws a menu bar in a window
1771 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1773 if (menu.Height == 0)
1774 CalcMenuBarSize (dc, menu, rect.Width);
1776 bool keynav = (menu as MainMenu).tracker.Navigating;
1777 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1778 string_format_menu_menubar_text.HotkeyPrefix = hp;
1779 string_format_menu_text.HotkeyPrefix = hp;
1781 rect.Height = menu.Height;
1782 dc.FillRectangle (SystemBrushes.Menu, rect);
1784 for (int i = 0; i < menu.MenuItems.Count; i++) {
1785 MenuItem item = menu.MenuItems [i];
1786 Rectangle item_rect = item.bounds;
1787 item_rect.X += rect.X;
1788 item_rect.Y += rect.Y;
1789 item.MenuHeight = menu.Height;
1790 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1794 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
1797 if (color.R == 0 && color.G == 0 && color.B == 0)
1798 bg_color = Color.White;
1800 bg_color = Color.Black;
1801 Bitmap bmp = new Bitmap (size.Width, size.Height);
1802 Graphics gr = Graphics.FromImage (bmp);
1803 Rectangle rect = new Rectangle (Point.Empty, size);
1804 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
1805 CPDrawMenuGlyph (gr, rect, glyph, color);
1806 bmp.MakeTransparent (bg_color);
1811 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1813 StringFormat string_format;
1814 Rectangle rect_text = e.Bounds;
1816 if (item.Visible == false)
1820 string_format = string_format_menu_menubar_text;
1822 string_format = string_format_menu_text;
1824 if (item.Separator == true) {
1825 e.Graphics.DrawLine (SystemPens.ControlDark,
1826 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1828 e.Graphics.DrawLine (SystemPens.ControlLight,
1829 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1835 rect_text.X += MenuCheckSize.Width;
1837 if (item.BarBreak) { /* Draw vertical break bar*/
1838 Rectangle rect = e.Bounds;
1841 rect.Height = item.MenuHeight - 6;
1843 e.Graphics.DrawLine (SystemPens.ControlDark,
1844 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1846 e.Graphics.DrawLine (SystemPens.ControlLight,
1847 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1852 Brush brush_text = null;
1853 Brush brush_back = null;
1855 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
1856 color_text = ColorHighlightText;
1857 color_back = ColorHighlight;
1858 brush_text = SystemBrushes.HighlightText;
1859 brush_back = SystemBrushes.Highlight;
1861 color_text = ColorMenuText;
1862 color_back = ColorMenu;
1863 brush_text = ResPool.GetSolidBrush (ColorMenuText);
1864 brush_back = SystemBrushes.Menu;
1867 /* Draw background */
1868 Rectangle rect_back = e.Bounds;
1870 rect_back.Width -=2;
1872 e.Graphics.FillRectangle (brush_back, rect_back);
1875 e.Graphics.DrawString (item.Text, e.Font,
1877 rect_text, string_format);
1879 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1880 string str = item.GetShortCutText ();
1881 Rectangle rect = rect_text;
1883 rect.Width -= item.XTab;
1885 e.Graphics.DrawString (str, e.Font, brush_text,
1886 rect, string_format_menu_shortcut);
1890 Border3DStyle border_style = Border3DStyle.Adjust;
1891 if ((item.Status & DrawItemState.HotLight) != 0)
1892 border_style = Border3DStyle.RaisedInner;
1893 else if ((item.Status & DrawItemState.Selected) != 0)
1894 border_style = Border3DStyle.SunkenOuter;
1896 if (border_style != Border3DStyle.Adjust)
1897 CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
1900 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
1901 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
1902 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
1906 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
1910 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
1912 int cx = MenuCheckSize.Width;
1913 int cy = MenuCheckSize.Height;
1914 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
1917 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1918 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1920 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1921 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1927 /* Draw checked or radio */
1928 if (item.MenuBar == false && item.Checked) {
1930 Rectangle area = e.Bounds;
1931 int cx = MenuCheckSize.Width;
1932 int cy = MenuCheckSize.Height;
1933 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
1935 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1941 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
1944 dc.FillRectangle (SystemBrushes.Menu, cliparea);
1946 Pen pen_cht = SystemPens.HighlightText;
1947 Pen pen_ccd = SystemPens.ControlDark;
1948 Pen pen_ccdd = SystemPens.ControlDarkDark;
1950 /* Draw menu borders */
1951 dc.DrawLine (pen_cht,
1952 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1954 dc.DrawLine (pen_cht,
1955 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1957 dc.DrawLine (pen_ccd,
1958 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1960 dc.DrawLine (pen_ccdd,
1961 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1963 dc.DrawLine (pen_ccd,
1964 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1966 dc.DrawLine (pen_ccdd,
1967 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1969 for (int i = 0; i < menu.MenuItems.Count; i++)
1970 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
1971 MenuItem item = menu.MenuItems [i];
1972 item.MenuHeight = menu.Height;
1973 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
1974 item.bounds, i, item.Status));
1980 #region MonthCalendar
1982 // draw the month calendar
1983 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
1985 Rectangle client_rectangle = mc.ClientRectangle;
1986 Size month_size = mc.SingleMonthSize;
1987 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1988 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
1989 Size date_cell_size = (Size)((object)mc.date_cell_size);
1991 // draw the singlecalendars
1994 // adjust for the position of the specific month
1995 for (int i=0; i < mc.CalendarDimensions.Height; i++)
1999 y_offset += month_size.Height + calendar_spacing.Height;
2001 // now adjust for x position
2002 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2006 x_offset += month_size.Width + calendar_spacing.Width;
2013 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2014 if (month_rect.IntersectsWith (clip_rectangle)) {
2026 Rectangle bottom_rect = new Rectangle (
2028 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2029 client_rectangle.Width,
2030 date_cell_size.Height + 2);
2031 // draw the today date if it's set
2032 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2034 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
2036 int today_offset = 5;
2037 if (mc.ShowTodayCircle)
2039 Rectangle today_circle_rect = new Rectangle (
2040 client_rectangle.X + 5,
2041 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2042 date_cell_size.Width,
2043 date_cell_size.Height);
2044 DrawTodayCircle (dc, today_circle_rect);
2045 today_offset += date_cell_size.Width + 5;
2047 // draw today's date
2048 StringFormat text_format = new StringFormat();
2049 text_format.LineAlignment = StringAlignment.Center;
2050 text_format.Alignment = StringAlignment.Near;
2051 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2052 Rectangle today_rect = new Rectangle (
2053 today_offset + client_rectangle.X,
2054 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2055 Math.Max(client_rectangle.Width - today_offset, 0),
2056 date_cell_size.Height);
2057 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
2058 text_format.Dispose ();
2059 bold_font.Dispose ();
2063 // finally paint the borders of the calendars as required
2064 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2065 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2066 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
2067 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2068 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
2070 Rectangle rect = new Rectangle (
2071 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2073 calendar_spacing.Width,
2074 client_rectangle.Height);
2075 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2076 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2080 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2081 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2082 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
2083 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2084 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
2086 Rectangle rect = new Rectangle (
2088 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2089 client_rectangle.Width,
2090 calendar_spacing.Height);
2091 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2092 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2097 // draw the drop down border if need
2098 if (mc.owner != null) {
2099 Rectangle bounds = mc.ClientRectangle;
2100 if (clip_rectangle.Contains (mc.Location)) {
2101 // find out if top or left line to draw
2102 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2104 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2106 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2107 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2110 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2111 // find out if bottom or right line to draw
2112 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2113 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2115 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2116 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2122 // darws a single part of the month calendar (with one month)
2123 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2125 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2126 Size title_size = (Size)((object)mc.title_size);
2127 Size date_cell_size = (Size)((object)mc.date_cell_size);
2128 DateTime current_month = (DateTime)((object)mc.current_month);
2130 // set up some standard string formating variables
2131 StringFormat text_format = new StringFormat();
2132 text_format.LineAlignment = StringAlignment.Center;
2133 text_format.Alignment = StringAlignment.Center;
2136 // draw the title back ground
2137 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2138 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2139 if (title_rect.IntersectsWith (clip_rectangle)) {
2140 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2142 string title_text = this_month.ToString ("MMMM yyyy");
2143 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2145 // draw previous and next buttons if it's time
2146 if (row == 0 && col == 0)
2148 // draw previous button
2149 DrawMonthCalendarButton (
2155 (System.Drawing.Size)((object)mc.button_size),
2158 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2161 DrawMonthCalendarButton (
2167 (System.Drawing.Size)((object)mc.button_size),
2172 // set the week offset and draw week nums if needed
2173 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2174 Rectangle day_name_rect = new Rectangle(
2176 rectangle.Y + title_size.Height,
2177 (7 + col_offset) * date_cell_size.Width,
2178 date_cell_size.Height);
2179 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2180 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
2181 // draw the day names
2182 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2183 for (int i=0; i < 7; i++)
2185 int position = i - (int) first_day_of_week;
2188 position = 7 + position;
2191 Rectangle day_rect = new Rectangle(
2192 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2194 date_cell_size.Width,
2195 date_cell_size.Height);
2196 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2199 // draw the vertical divider
2200 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2202 ResPool.GetPen (mc.ForeColor),
2203 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2204 rectangle.Y + vert_divider_y,
2205 rectangle.Right - mc.divider_line_offset,
2206 rectangle.Y + vert_divider_y);
2210 // draw the actual date items in the grid (including the week numbers)
2211 Rectangle date_rect = new Rectangle (
2213 rectangle.Y + title_size.Height + date_cell_size.Height,
2214 date_cell_size.Width,
2215 date_cell_size.Height);
2216 int month_row_count = 0;
2217 bool draw_week_num_divider = false;
2218 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2219 for (int i=0; i < 6; i++)
2221 // establish if this row is in our clip_area
2222 Rectangle row_rect = new Rectangle (
2224 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2225 date_cell_size.Width * 7,
2226 date_cell_size.Height);
2227 if (mc.ShowWeekNumbers) {
2228 row_rect.Width += date_cell_size.Width;
2231 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2233 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
2235 // establish if this is a valid week to draw
2236 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2237 month_row_count = i;
2240 // draw the week number if required
2241 if (mc.ShowWeekNumbers && month_row_count == i) {
2242 if (!draw_week_num_divider) {
2243 draw_week_num_divider = draw_row;
2245 // get the week for this row
2246 int week = mc.GetWeekOfYear (current_date);
2252 ResPool.GetSolidBrush (mc.TitleBackColor),
2256 date_rect.Offset(date_cell_size.Width, 0);
2259 // only draw the days if we have to
2260 if(month_row_count == i) {
2261 for (int j=0; j < 7; j++)
2264 DrawMonthCalendarDate (
2275 current_date = current_date.AddDays(1);
2276 date_rect.Offset(date_cell_size.Width, 0);
2279 // shift the rectangle down one row
2280 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2281 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2285 // month_row_count is zero based, so add one
2288 // draw week numbers if required
2289 if (draw_week_num_divider) {
2292 ResPool.GetPen (mc.ForeColor),
2293 rectangle.X + date_cell_size.Width - 1,
2294 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2295 rectangle.X + date_cell_size.Width - 1,
2296 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2298 text_format.Dispose ();
2301 // draws the pervious or next button
2302 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2304 bool is_clicked = false;
2305 Rectangle button_rect;
2306 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2307 Point[] arrow_path = new Point[3];
2308 // prepare the button
2311 is_clicked = mc.is_previous_clicked;
2312 button_rect = new Rectangle (
2313 rectangle.X + 1 + x_offset,
2314 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2315 Math.Max(button_size.Width - 1, 0),
2316 Math.Max(button_size.Height - 1, 0));
2317 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2318 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2320 arrow_rect.Offset(1,1);
2322 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2323 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2324 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2328 is_clicked = mc.is_next_clicked;
2329 button_rect = new Rectangle (
2330 rectangle.Right - 1 - x_offset - button_size.Width,
2331 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2332 Math.Max(button_size.Width - 1, 0),
2333 Math.Max(button_size.Height - 1, 0));
2334 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2335 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2337 arrow_rect.Offset(1,1);
2339 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2340 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2341 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2344 // fill the background
2345 dc.FillRectangle (SystemBrushes.Control, button_rect);
2348 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2351 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
2354 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2358 // draws one day in the calendar grid
2359 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2360 Color date_color = mc.ForeColor;
2361 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2363 // find out if we are the lead of the first calendar or the trail of the last calendar
2364 if (date.Year != month.Year || date.Month != month.Month) {
2365 DateTime check_date = month.AddMonths (-1);
2366 // check if it's the month before
2367 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2368 date_color = mc.TrailingForeColor;
2370 // check if it's the month after
2371 check_date = month.AddMonths (1);
2372 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2373 date_color = mc.TrailingForeColor;
2379 date_color = mc.ForeColor;
2383 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2384 // see if the date is in the start of selection
2385 date_color = mc.BackColor;
2386 // draw the left hand of the back ground
2387 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2388 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2389 } else if (date == mc.SelectionStart) {
2390 // see if the date is in the start of selection
2391 date_color = mc.BackColor;
2392 // draw the left hand of the back ground
2393 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2394 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2395 // fill the other side as a straight rect
2396 if (date < mc.SelectionEnd)
2398 // use rectangle instead of rectangle to go all the way to edge of rect
2399 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2400 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2401 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2403 } else if (date == mc.SelectionEnd) {
2404 // see if it is the end of selection
2405 date_color = mc.BackColor;
2406 // draw the left hand of the back ground
2407 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2408 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2409 // fill the other side as a straight rect
2410 if (date > mc.SelectionStart) {
2411 selection_rect.X = rectangle.X;
2412 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2413 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2415 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2416 // now see if it's in the middle
2417 date_color = mc.BackColor;
2418 // draw the left hand of the back ground
2419 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2420 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2423 // set up some standard string formating variables
2424 StringFormat text_format = new StringFormat();
2425 text_format.LineAlignment = StringAlignment.Center;
2426 text_format.Alignment = StringAlignment.Center;
2429 // establish if it's a bolded font
2431 if (mc.IsBoldedDate (date)) {
2432 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2437 // just draw the date now
2438 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2440 // today circle if needed
2441 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2442 DrawTodayCircle (dc, interior);
2445 // draw the selection grid
2446 if (mc.is_date_clicked && mc.clicked_date == date) {
2447 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
2448 dc.DrawRectangle (pen, interior);
2450 text_format.Dispose ();
2453 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2454 Color circle_color = Color.FromArgb (248, 0, 0);
2455 // draw the left hand of the circle
2456 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2457 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2458 Point [] curve_points = new Point [3];
2459 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2460 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2461 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2463 Pen pen = ResPool.GetSizedPen(circle_color, 2);
2464 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2465 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2466 dc.DrawCurve (pen, curve_points);
2467 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2470 #endregion // MonthCalendar
2473 public override Size PanelDefaultSize {
2475 return new Size (200, 100);
2481 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2482 Rectangle client = pb.ClientRectangle;
2484 // FIXME - instead of drawing the whole picturebox every time
2485 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2486 // Also, we only need a background fill where no image goes
2487 if (pb.Image != null) {
2488 switch (pb.SizeMode) {
2489 case PictureBoxSizeMode.StretchImage:
2490 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2493 case PictureBoxSizeMode.CenterImage:
2494 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2495 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2498 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2500 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2507 // We only get here if no image is set. At least paint the background
2508 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2511 public override Size PictureBoxDefaultSize {
2513 return new Size (100, 50);
2516 #endregion // PictureBox
2519 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2521 Rectangle block_rect;
2522 Rectangle client_area = ctrl.client_area;
2523 int space_betweenblocks = 2;
2528 block_width = (client_area.Height * 2 ) / 3;
2529 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2530 increment = block_width + space_betweenblocks;
2533 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
2536 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2537 while ((block_rect.X - client_area.X) < barpos_pixels) {
2539 if (clip_rect.IntersectsWith (block_rect) == true) {
2540 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2543 block_rect.X += increment;
2547 public override Size ProgressBarDefaultSize {
2549 return new Size (100, 23);
2553 #endregion // ProgressBar
2556 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2557 StringFormat text_format;
2558 Rectangle client_rectangle;
2559 Rectangle text_rectangle;
2560 Rectangle radiobutton_rectangle;
2561 int radiobutton_size = 13;
2562 int radiobutton_space = 4;
2564 client_rectangle = radio_button.ClientRectangle;
2565 text_rectangle = client_rectangle;
2566 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2568 text_format = new StringFormat();
2569 text_format.Alignment = StringAlignment.Near;
2570 text_format.LineAlignment = StringAlignment.Center;
2571 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2573 /* Calculate the position of text and checkbox rectangle */
2574 if (radio_button.appearance!=Appearance.Button) {
2575 switch(radio_button.radiobutton_alignment) {
2576 case ContentAlignment.BottomCenter: {
2577 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2578 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2579 text_rectangle.X=client_rectangle.X;
2580 text_rectangle.Width=client_rectangle.Width;
2581 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2585 case ContentAlignment.BottomLeft: {
2586 radiobutton_rectangle.X=client_rectangle.Left;
2587 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2588 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2589 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2593 case ContentAlignment.BottomRight: {
2594 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2595 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2596 text_rectangle.X=client_rectangle.X;
2597 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2601 case ContentAlignment.MiddleCenter: {
2602 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2603 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2604 text_rectangle.X=client_rectangle.X;
2605 text_rectangle.Width=client_rectangle.Width;
2610 case ContentAlignment.MiddleLeft: {
2611 radiobutton_rectangle.X=client_rectangle.Left;
2612 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2613 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2614 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2618 case ContentAlignment.MiddleRight: {
2619 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2620 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2621 text_rectangle.X=client_rectangle.X;
2622 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2626 case ContentAlignment.TopCenter: {
2627 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2628 radiobutton_rectangle.Y=client_rectangle.Top;
2629 text_rectangle.X=client_rectangle.X;
2630 text_rectangle.Y=radiobutton_size+radiobutton_space;
2631 text_rectangle.Width=client_rectangle.Width;
2632 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2636 case ContentAlignment.TopLeft: {
2637 radiobutton_rectangle.X=client_rectangle.Left;
2638 radiobutton_rectangle.Y=client_rectangle.Top;
2639 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2640 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2644 case ContentAlignment.TopRight: {
2645 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2646 radiobutton_rectangle.Y=client_rectangle.Top;
2647 text_rectangle.X=client_rectangle.X;
2648 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2653 text_rectangle.X=client_rectangle.X;
2654 text_rectangle.Width=client_rectangle.Width;
2657 /* Set the horizontal alignment of our text */
2658 switch(radio_button.text_alignment) {
2659 case ContentAlignment.BottomLeft:
2660 case ContentAlignment.MiddleLeft:
2661 case ContentAlignment.TopLeft: {
2662 text_format.Alignment=StringAlignment.Near;
2666 case ContentAlignment.BottomCenter:
2667 case ContentAlignment.MiddleCenter:
2668 case ContentAlignment.TopCenter: {
2669 text_format.Alignment=StringAlignment.Center;
2673 case ContentAlignment.BottomRight:
2674 case ContentAlignment.MiddleRight:
2675 case ContentAlignment.TopRight: {
2676 text_format.Alignment=StringAlignment.Far;
2681 /* Set the vertical alignment of our text */
2682 switch(radio_button.text_alignment) {
2683 case ContentAlignment.TopLeft:
2684 case ContentAlignment.TopCenter:
2685 case ContentAlignment.TopRight: {
2686 text_format.LineAlignment=StringAlignment.Near;
2690 case ContentAlignment.BottomLeft:
2691 case ContentAlignment.BottomCenter:
2692 case ContentAlignment.BottomRight: {
2693 text_format.LineAlignment=StringAlignment.Far;
2697 case ContentAlignment.MiddleLeft:
2698 case ContentAlignment.MiddleCenter:
2699 case ContentAlignment.MiddleRight: {
2700 text_format.LineAlignment=StringAlignment.Center;
2705 ButtonState state = ButtonState.Normal;
2706 if (radio_button.FlatStyle == FlatStyle.Flat) {
2707 state |= ButtonState.Flat;
2710 if (radio_button.Checked) {
2711 state |= ButtonState.Checked;
2714 if (!radio_button.Enabled) {
2715 state |= ButtonState.Inactive;
2719 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2721 if ((radio_button.image != null) || (radio_button.image_list != null))
2722 ButtonBase_DrawImage(radio_button, dc);
2724 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2726 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2728 text_format.Dispose ();
2731 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2733 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
2735 if (radio_button.appearance==Appearance.Button) {
2736 ButtonBase_DrawButton (radio_button, dc);
2738 // establish if we are rendering a flat style of some sort
2739 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2740 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2742 CPDrawRadioButton(dc, radiobutton_rectangle, state);
2747 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2749 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
2750 text_format, radio_button.Appearance, radio_button.Checked);
2753 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2755 // do nothing here. maybe an other theme needs it
2758 // renders a radio button with the Flat and Popup FlatStyle
2759 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2763 if (radio_button.Enabled) {
2765 // draw the outer flatstyle arcs
2766 if (radio_button.FlatStyle == FlatStyle.Flat) {
2767 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
2769 // fill in the area depending on whether or not the mouse is hovering
2770 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
2771 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2773 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2776 // must be a popup radio button
2778 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
2780 if (radio_button.is_entered || radio_button.Capture) {
2781 // draw the popup 3d button knob
2782 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2784 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
2785 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
2788 // just draw lighter flatstyle outer circle
2789 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2794 // fill control background color regardless of actual backcolor
2795 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2796 // draw the ark as control dark
2797 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2801 if (radio_button.Checked) {
2802 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2804 Pen dot_pen = SystemPens.ControlDarkDark;
2805 Brush dot_brush = SystemBrushes.ControlDarkDark;
2807 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
2808 dot_pen = SystemPens.ControlDark;
2809 dot_brush = SystemBrushes.ControlDark;
2812 if (rectangle.Height > 13) {
2813 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
2815 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
2816 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
2818 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
2819 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
2821 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
2822 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
2827 public override Size RadioButtonDefaultSize {
2829 return new Size (104,24);
2832 #endregion // RadioButton
2835 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2837 int scrollbutton_width = bar.scrollbutton_width;
2838 int scrollbutton_height = bar.scrollbutton_height;
2839 Rectangle first_arrow_area;
2840 Rectangle second_arrow_area;
2841 Rectangle thumb_pos;
2843 thumb_pos = bar.ThumbPos;
2846 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2847 bar.FirstArrowArea = first_arrow_area;
2849 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2850 bar.SecondArrowArea = second_arrow_area;
2852 thumb_pos.Width = bar.Width;
2853 bar.ThumbPos = thumb_pos;
2856 if (clip.IntersectsWith (first_arrow_area))
2857 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2858 if (clip.IntersectsWith (second_arrow_area))
2859 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2862 switch (bar.thumb_moving) {
2863 case ScrollBar.ThumbMoving.None: {
2864 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
2867 case ScrollBar.ThumbMoving.Forward: {
2868 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
2872 case ScrollBar.ThumbMoving.Backwards: {
2873 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
2881 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2882 bar.FirstArrowArea = first_arrow_area;
2884 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2885 bar.SecondArrowArea = second_arrow_area;
2887 thumb_pos.Height = bar.Height;
2888 bar.ThumbPos = thumb_pos;
2891 if (clip.IntersectsWith (first_arrow_area))
2892 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2893 if (clip.IntersectsWith (second_arrow_area))
2894 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2897 switch (bar.thumb_moving) {
2898 case ScrollBar.ThumbMoving.None: {
2899 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
2903 case ScrollBar.ThumbMoving.Forward: {
2904 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
2908 case ScrollBar.ThumbMoving.Backwards: {
2909 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
2916 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
2919 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
2921 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
2922 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
2925 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
2927 Rectangle r = new Rectangle( 0,
2928 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
2929 Rectangle intersect = Rectangle.Intersect( clip, r );
2931 if ( intersect != Rectangle.Empty )
2933 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
2934 dc.FillRectangle( h, intersect );
2938 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2940 Rectangle r = new Rectangle( 0, scrollbutton_height,
2941 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2942 Rectangle intersect = Rectangle.Intersect( clip, r );
2944 if ( intersect != Rectangle.Empty )
2945 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
2948 r.Y = thumb_pos.Y + thumb_pos.Height;
2949 r.Width = bar.ClientRectangle.Width;
2950 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2952 intersect = Rectangle.Intersect( clip, r );
2953 if ( intersect != Rectangle.Empty )
2954 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2957 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2959 Rectangle r = new Rectangle( 0, scrollbutton_height,
2960 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2961 Rectangle intersect = Rectangle.Intersect( clip, r );
2963 if ( intersect != Rectangle.Empty )
2964 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2967 r.Y = thumb_pos.Y + thumb_pos.Height;
2968 r.Width = bar.ClientRectangle.Width;
2969 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2971 intersect = Rectangle.Intersect( clip, r );
2972 if ( intersect != Rectangle.Empty )
2973 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
2976 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
2978 Rectangle r = new Rectangle( scrollbutton_width,
2979 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
2980 Rectangle intersect = Rectangle.Intersect( clip, r );
2982 if ( intersect != Rectangle.Empty )
2983 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
2986 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
2988 Rectangle r = new Rectangle( scrollbutton_width, 0,
2989 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
2990 Rectangle intersect = Rectangle.Intersect( clip, r );
2992 if ( intersect != Rectangle.Empty )
2993 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
2995 r.X = thumb_pos.X + thumb_pos.Width;
2997 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
2998 r.Height = bar.ClientRectangle.Height;
3000 intersect = Rectangle.Intersect( clip, r );
3001 if ( intersect != Rectangle.Empty )
3002 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3005 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3007 Rectangle r = new Rectangle( scrollbutton_width, 0,
3008 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3009 Rectangle intersect = Rectangle.Intersect( clip, r );
3011 if ( intersect != Rectangle.Empty )
3012 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3014 r.X = thumb_pos.X + thumb_pos.Width;
3016 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3017 r.Height = bar.ClientRectangle.Height;
3019 intersect = Rectangle.Intersect( clip, r );
3020 if ( intersect != Rectangle.Empty )
3021 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3024 public override int ScrollBarButtonSize {
3027 #endregion // ScrollBar
3030 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3031 Rectangle area = sb.ClientRectangle;
3032 int horz_border = 2;
3033 int vert_border = 2;
3035 bool is_color_control = sb.BackColor == ColorControl;
3037 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
3038 dc.FillRectangle (brush, clip);
3040 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3041 string text = sb.Text;
3042 StringFormat string_format = new StringFormat ();
3043 string_format.Trimming = StringTrimming.Character;
3044 string_format.FormatFlags = StringFormatFlags.NoWrap;
3046 if (text [0] == '\t') {
3047 string_format.Alignment = StringAlignment.Center;
3048 text = text.Substring (1);
3049 if (text [0] == '\t') {
3050 string_format.Alignment = StringAlignment.Far;
3051 text = text.Substring (1);
3055 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3056 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3057 string_format.Dispose ();
3058 } else if (sb.ShowPanels) {
3059 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
3060 int prev_x = area.X + horz_border;
3061 int y = area.Y + vert_border;
3062 for (int i = 0; i < sb.Panels.Count; i++) {
3063 Rectangle pr = new Rectangle (prev_x, y,
3064 sb.Panels [i].Width, area.Height);
3065 prev_x += pr.Width + StatusBarHorzGapWidth;
3066 if (pr.IntersectsWith (clip))
3067 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3071 if (sb.SizingGrip) {
3072 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
3073 CPDrawSizeGrip (dc, ColorControl, area);
3079 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3080 Brush br_forecolor, StatusBarPanel panel) {
3081 int border_size = 3; // this is actually const, even if the border style is none
3082 int icon_width = 16;
3084 area.Height -= border_size;
3086 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3087 Border3DStyle border_style = Border3DStyle.SunkenOuter;
3088 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3089 border_style = Border3DStyle.RaisedInner;
3091 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
3094 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3095 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3096 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3097 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3098 panel.Parent.OnDrawItemInternal (e);
3102 if (panel.Text == String.Empty)
3105 string text = panel.Text;
3106 StringFormat string_format = new StringFormat ();
3107 string_format.Trimming = StringTrimming.Character;
3108 string_format.FormatFlags = StringFormatFlags.NoWrap;
3111 if (text [0] == '\t') {
3112 string_format.Alignment = StringAlignment.Center;
3113 text = text.Substring (1);
3114 if (text [0] == '\t') {
3115 string_format.Alignment = StringAlignment.Far;
3116 text = text.Substring (1);
3120 Rectangle string_rect = Rectangle.Empty;
3124 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
3126 switch (panel.Alignment) {
3127 case HorizontalAlignment.Right:
3128 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3129 x = area.Right - len - 4;
3130 string_rect = new Rectangle (x, y,
3131 area.Right - x - border_size,
3132 area.Bottom - y - border_size);
3133 if (panel.Icon != null) {
3134 icon_x = x - icon_width - 2;
3137 case HorizontalAlignment.Center:
3138 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3139 x = (panel.Width / 2) + (len / 2);
3140 string_rect = new Rectangle (x, y,
3141 area.Right - x - border_size,
3142 area.Bottom - y - border_size);
3144 if (panel.Icon != null) {
3145 icon_x = x - icon_width - 2;
3151 int left = area.Left + border_size;;
3152 if (panel.Icon != null) {
3153 icon_x = area.Left + 2;
3154 left = icon_x + icon_width + 2;
3158 string_rect = new Rectangle (x, y,
3159 area.Right - x - border_size,
3160 area.Bottom - y - border_size);
3164 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
3166 if (panel.Icon != null) {
3167 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
3171 public override int StatusBarSizeGripWidth {
3175 public override int StatusBarHorzGapWidth {
3179 public override Size StatusBarDefaultSize {
3181 return new Size (100, 22);
3184 #endregion // StatusBar
3186 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3188 // Do we need to fill the back color? It can't be changed...
3189 Brush brush = tab.BackColor == DefaultControlBackColor ? SystemBrushes.Control : ResPool.GetSolidBrush (tab.BackColor);
3190 dc.FillRectangle (brush, area);
3191 Rectangle panel_rect = GetTabPanelRectExt (tab);
3193 if (tab.Appearance == TabAppearance.Normal) {
3194 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3195 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3198 if (tab.Alignment == TabAlignment.Top) {
3199 for (int r = tab.TabPages.Count; r > 0; r--) {
3200 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3201 if (i == tab.SelectedIndex)
3203 if (r != tab.TabPages [i].Row)
3205 Rectangle rect = tab.GetTabRect (i);
3206 if (!rect.IntersectsWith (area))
3208 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3212 for (int r = 0; r < tab.TabPages.Count; r++) {
3213 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3214 if (i == tab.SelectedIndex)
3216 if (r != tab.TabPages [i].Row)
3218 Rectangle rect = tab.GetTabRect (i);
3219 if (!rect.IntersectsWith (area))
3221 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3226 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3227 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3228 if (rect.IntersectsWith (area))
3229 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3232 if (tab.ShowSlider) {
3233 Rectangle right = GetTabControlRightScrollRect (tab);
3234 Rectangle left = GetTabControlLeftScrollRect (tab);
3235 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3236 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3240 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3242 switch (tab.Alignment) {
3243 case TabAlignment.Top:
3244 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3246 Rectangle panel_rect = GetTabPanelRectExt (tab);
3247 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3251 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3253 switch (tab.Alignment) {
3254 case TabAlignment.Top:
3255 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3257 Rectangle panel_rect = GetTabPanelRectExt (tab);
3258 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3262 public override Size TabControlDefaultItemSize {
3263 get { return new Size (42, 21); }
3266 public override Point TabControlDefaultPadding {
3267 get { return new Point (6, 3); }
3270 public override int TabControlMinimumTabWidth {
3274 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3276 Rectangle ext = GetTabPanelRectExt (tab);
3277 // Account for border size
3278 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3281 public override Size TabControlGetSpacing (TabControl tab) {
3282 switch (tab.Appearance) {
3283 case TabAppearance.Normal:
3284 return new Size (1, -2);
3285 case TabAppearance.Buttons:
3286 return new Size (3, 3);
3287 case TabAppearance.FlatButtons:
3288 return new Size (9, 3);
3290 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3294 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3296 // Offset the tab from the top corner
3297 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3298 tab.ClientRectangle.Y,
3299 tab.ClientRectangle.Width - 2,
3300 tab.ClientRectangle.Height - 1);
3302 if (tab.TabCount == 0)
3305 int spacing = TabControlGetSpacing (tab).Height;
3306 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3308 switch (tab.Alignment) {
3309 case TabAlignment.Left:
3311 res.Width -= offset;
3313 case TabAlignment.Right:
3314 res.Width -= offset;
3316 case TabAlignment.Top:
3318 res.Height -= offset;
3320 case TabAlignment.Bottom:
3321 res.Height -= offset;
3328 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3330 int FlatButtonSpacing = 8;
3332 int res = bounds.Width;
3336 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3338 StringFormat string_format = new StringFormat ();
3339 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3340 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3343 if (tab.Appearance == TabAppearance.FlatButtons) {
3344 int width = bounds.Width;
3345 bounds.Width += (FlatButtonSpacing - 2);
3347 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3348 bounds.Width = width;
3352 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3353 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3354 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3357 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3360 string_format.Alignment = StringAlignment.Center;
3361 string_format.LineAlignment = StringAlignment.Center;
3362 string_format.FormatFlags = StringFormatFlags.NoWrap;
3364 CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
3366 Pen light = ResPool.GetPen (cpcolor.LightLight);
3368 switch (tab.Alignment) {
3370 case TabAlignment.Top:
3372 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3374 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3375 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3376 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3378 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3379 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3380 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3382 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3384 string_format.Alignment = StringAlignment.Center;
3385 string_format.LineAlignment = StringAlignment.Center;
3386 string_format.FormatFlags = StringFormatFlags.NoWrap;
3390 case TabAlignment.Bottom:
3392 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3394 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3395 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3397 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3398 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3400 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3401 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3402 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3404 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3406 string_format.Alignment = StringAlignment.Center;
3407 string_format.LineAlignment = StringAlignment.Center;
3408 string_format.FormatFlags = StringFormatFlags.NoWrap;
3412 case TabAlignment.Left:
3414 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3416 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3417 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3418 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3420 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3422 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3423 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3425 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3427 string_format.Alignment = StringAlignment.Center;
3428 string_format.LineAlignment = StringAlignment.Center;
3429 string_format.FormatFlags = StringFormatFlags.NoWrap;
3430 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3435 // TabAlignment.Right
3437 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3439 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3440 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3442 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3443 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3445 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3446 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3448 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3450 string_format.Alignment = StringAlignment.Center;
3451 string_format.LineAlignment = StringAlignment.Center;
3452 string_format.FormatFlags = StringFormatFlags.NoWrap;
3453 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3459 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3460 if (tab.Alignment == TabAlignment.Left) {
3461 int wo = interior.Width / 2;
3462 int ho = interior.Height / 2;
3463 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3464 dc.RotateTransform (180);
3465 dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
3466 dc.ResetTransform ();
3468 dc.DrawString (page.Text, page.Font,
3469 SystemBrushes.ControlText,
3470 interior, string_format);
3472 } else if (page.Text != null) {
3473 DrawItemState state = DrawItemState.None;
3474 if (page == tab.SelectedTab)
3475 state |= DrawItemState.Selected;
3476 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3477 tab.Font, bounds, tab.IndexForTabPage (page),
3478 state, page.ForeColor, page.BackColor);
3479 tab.OnDrawItemInternal (e);
3483 if (page.parent.Focused && is_selected) {
3484 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3491 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
3493 StringFormat format = new StringFormat ();
3494 format.Trimming = StringTrimming.EllipsisWord;
3495 format.LineAlignment = StringAlignment.Center;
3496 if (control.TextAlign == ToolBarTextAlign.Underneath)
3497 format.Alignment = StringAlignment.Center;
3499 format.Alignment = StringAlignment.Near;
3501 if (control is PropertyGrid.PropertyToolBar) {
3502 dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
3504 if (clip_rectangle.X == 0) {
3505 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
3508 if (clip_rectangle.Y < 2) {
3509 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3512 if (clip_rectangle.Bottom == control.Bottom) {
3513 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
3516 if (clip_rectangle.Right == control.Right) {
3517 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
3519 } else if (control.Divider) {
3521 if (control.Appearance == ToolBarAppearance.Flat &&
3522 control.Parent != null && control.Parent.BackgroundImage != null) {
3523 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3524 dc.FillRectangle (b, clip_rectangle);
3527 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
3530 if (clip_rectangle.Y < 2) {
3531 if (clip_rectangle.Y < 1) {
3532 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
3534 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3537 if (control.Appearance == ToolBarAppearance.Flat &&
3538 control.Parent != null && control.Parent.BackgroundImage != null) {
3539 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3540 dc.FillRectangle (b, clip_rectangle);
3545 foreach (ToolBarButton button in control.Buttons)
3546 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
3547 DrawToolBarButton (dc, control, button, format);
3552 void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3554 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
3556 DrawToolBarButtonBorder (dc, button, is_flat);
3558 switch (button.Style) {
3559 case ToolBarButtonStyle.DropDownButton:
3560 if (control.DropDownArrows)
3561 DrawToolBarDropDownArrow (dc, button, is_flat);
3562 DrawToolBarButtonContents (dc, control, button, format);
3565 case ToolBarButtonStyle.Separator:
3567 DrawToolBarSeparator (dc, button);
3570 case ToolBarButtonStyle.ToggleButton:
3571 DrawToolBarToggleButtonBackground (dc, button);
3572 DrawToolBarButtonContents (dc, control, button, format);
3576 DrawToolBarButtonContents (dc, control, button, format);
3581 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
3583 void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
3585 if (button.Style == ToolBarButtonStyle.Separator)
3588 Border3DStyle style;
3591 if (button.Pushed || button.Pressed)
3592 style = Border3DStyle.SunkenOuter;
3593 else if (button.Hilight)
3594 style = Border3DStyle.RaisedInner;
3599 if (button.Pushed || button.Pressed)
3600 style = Border3DStyle.Sunken;
3602 style = Border3DStyle.Raised;
3605 CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
3608 void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
3610 Rectangle area = button.Rectangle;
3611 int offset = (int) SystemPens.Control.Width + 1;
3612 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
3613 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
3616 void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
3618 Rectangle area = button.Rectangle;
3619 area.X += ToolBarImageGripWidth;
3620 area.Y += ToolBarImageGripWidth;
3621 area.Width -= 2 * ToolBarImageGripWidth;
3622 area.Height -= 2 * ToolBarImageGripWidth;
3625 dc.FillRectangle (SystemBrushes.ControlLightLight, area);
3626 else if (button.PartialPush)
3627 dc.FillRectangle (SystemBrushes.ControlLight, area);
3629 dc.FillRectangle (SystemBrushes.Control, area);
3632 void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
3634 Rectangle rect = button.Rectangle;
3635 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
3636 rect.Width = ToolBarDropDownWidth;
3638 if (button.dd_pressed) {
3639 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
3640 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
3641 } else if (button.Pushed || button.Pressed)
3642 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
3645 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
3647 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3649 PointF [] vertices = new PointF [3];
3650 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
3651 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3652 vertices [0].Y = ddCenter.Y;
3653 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3654 vertices [1].Y = ddCenter.Y;
3655 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3656 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
3657 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3660 void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3662 if (button.Image != null) {
3663 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
3664 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
3666 dc.DrawImage (button.Image, x, y);
3668 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
3672 dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, button.TextRectangle, format);
3674 CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, button.TextRectangle, format);
3677 // Grip width for the ToolBar
3678 public override int ToolBarGripWidth {
3682 // Grip width for the Image on the ToolBarButton
3683 public override int ToolBarImageGripWidth {
3687 // width of the separator
3688 public override int ToolBarSeparatorWidth {
3692 // width of the dropdown arrow rect
3693 public override int ToolBarDropDownWidth {
3697 // width for the dropdown arrow on the ToolBarButton
3698 public override int ToolBarDropDownArrowWidth {
3702 // height for the dropdown arrow on the ToolBarButton
3703 public override int ToolBarDropDownArrowHeight {
3707 public override Size ToolBarDefaultSize {
3709 return new Size (100, 42);
3712 #endregion // ToolBar
3715 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3716 dc.FillRectangle(SystemBrushes.Info, control.client_rect);
3717 dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
3718 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3721 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3724 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3725 return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
3727 #endregion // ToolTip
3730 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3731 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3732 float ticks, int value_pos, bool mouse_value) {
3734 Point toptick_startpoint = new Point ();
3735 Point bottomtick_startpoint = new Point ();
3736 Point channel_startpoint = new Point ();
3738 float pixels_betweenticks;
3739 const int space_from_right = 8;
3740 const int space_from_left = 8;
3741 const int space_from_bottom = 11;
3742 Rectangle area = tb.ClientRectangle;
3744 switch (tb.TickStyle) {
3745 case TickStyle.BottomRight:
3746 case TickStyle.None:
3747 channel_startpoint.Y = 8;
3748 channel_startpoint.X = 9;
3749 bottomtick_startpoint.Y = 13;
3750 bottomtick_startpoint.X = 24;
3752 case TickStyle.TopLeft:
3753 channel_startpoint.Y = 8;
3754 channel_startpoint.X = 19;
3755 toptick_startpoint.Y = 13;
3756 toptick_startpoint.X = 8;
3758 case TickStyle.Both:
3759 channel_startpoint.Y = 8;
3760 channel_startpoint.X = 18;
3761 bottomtick_startpoint.Y = 13;
3762 bottomtick_startpoint.X = 32;
3763 toptick_startpoint.Y = 13;
3764 toptick_startpoint.X = 8;
3770 thumb_area.X = area.X + channel_startpoint.X;
3771 thumb_area.Y = area.Y + channel_startpoint.Y;
3772 thumb_area.Height = area.Height - space_from_right - space_from_left;
3773 thumb_area.Width = 4;
3776 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3777 1, thumb_area.Height);
3779 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
3780 1, thumb_area.Height);
3782 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
3783 1, thumb_area.Height);
3785 pixel_len = thumb_area.Height - 11;
3786 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3788 /* Convert thumb position from mouse position to value*/
3790 if (value_pos < thumb_area.Bottom)
3791 value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
3795 if (value_pos + tb.Minimum > tb.Maximum)
3796 value_pos = tb.Maximum - tb.Minimum;
3798 tb.Value = value_pos + tb.Minimum;
3801 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
3802 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
3804 /* Draw thumb fixed 10x22 size */
3805 thumb_pos.Width = 10;
3806 thumb_pos.Height = 22;
3808 switch (tb.TickStyle) {
3809 case TickStyle.BottomRight:
3810 case TickStyle.None: {
3811 thumb_pos.X = channel_startpoint.X - 8;
3813 Pen pen = SystemPens.ControlLight;
3814 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3815 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3816 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3818 pen = SystemPens.ControlDark;
3819 dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3820 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3822 pen = SystemPens.ControlDarkDark;
3823 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3824 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3826 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3827 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3828 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3829 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3833 case TickStyle.TopLeft: {
3834 thumb_pos.X = channel_startpoint.X - 10;
3836 Pen pen = SystemPens.ControlLight;
3837 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3838 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3840 pen = SystemPens.ControlDark;
3841 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3842 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3843 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3845 pen = SystemPens.ControlDarkDark;
3846 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3847 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3848 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3850 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3851 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3852 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3853 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3858 case TickStyle.Both: {
3859 thumb_pos.X = area.X + 10;
3861 Pen pen = SystemPens.ControlLight;
3862 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3863 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3865 pen = SystemPens.ControlDark;
3866 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3867 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3869 pen = SystemPens.ControlDarkDark;
3870 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3871 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3873 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3882 pixel_len = thumb_area.Height - 11;
3883 pixels_betweenticks = pixel_len / ticks;
3885 thumb_area.X = thumb_pos.X;
3886 thumb_area.Y = channel_startpoint.Y;
3887 thumb_area.Width = thumb_pos.Height;
3890 Region outside = new Region (area);
3891 outside.Exclude (thumb_area);
3893 if (outside.IsVisible (clip_rectangle)) {
3894 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3895 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3897 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3898 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3899 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3900 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3902 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3903 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3907 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3908 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3910 pixel_len = thumb_area.Height - 11;
3911 pixels_betweenticks = pixel_len / ticks;
3913 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3914 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3915 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3916 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3918 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3919 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3931 Does not matter the size of the control, Win32 always draws:
3932 - Ticks starting from pixel 13, 8
3933 - Channel starting at pos 8, 19 and ends at Width - 8
3934 - Autosize makes always the control 40 pixels height
3935 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3938 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3939 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3940 float ticks, int value_pos, bool mouse_value) {
3941 Point toptick_startpoint = new Point ();
3942 Point bottomtick_startpoint = new Point ();
3943 Point channel_startpoint = new Point ();
3945 float pixels_betweenticks;
3946 const int space_from_right = 8;
3947 const int space_from_left = 8;
3948 Rectangle area = tb.ClientRectangle;
3950 switch (tb.TickStyle) {
3951 case TickStyle.BottomRight:
3952 case TickStyle.None:
3953 channel_startpoint.X = 8;
3954 channel_startpoint.Y = 9;
3955 bottomtick_startpoint.X = 13;
3956 bottomtick_startpoint.Y = 24;
3958 case TickStyle.TopLeft:
3959 channel_startpoint.X = 8;
3960 channel_startpoint.Y = 19;
3961 toptick_startpoint.X = 13;
3962 toptick_startpoint.Y = 8;
3964 case TickStyle.Both:
3965 channel_startpoint.X = 8;
3966 channel_startpoint.Y = 18;
3967 bottomtick_startpoint.X = 13;
3968 bottomtick_startpoint.Y = 32;
3969 toptick_startpoint.X = 13;
3970 toptick_startpoint.Y = 8;
3976 thumb_area.X = area.X + channel_startpoint.X;
3977 thumb_area.Y = area.Y + channel_startpoint.Y;
3978 thumb_area.Width = area.Width - space_from_right - space_from_left;
3979 thumb_area.Height = 4;
3982 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3983 thumb_area.Width, 1);
3985 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
3986 thumb_area.Width, 1);
3988 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
3989 thumb_area.Width, 1);
3991 pixel_len = thumb_area.Width - 11;
3992 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3994 /* Convert thumb position from mouse position to value*/
3996 if (value_pos >= channel_startpoint.X)
3997 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4001 if (value_pos + tb.Minimum > tb.Maximum)
4002 value_pos = tb.Maximum - tb.Minimum;
4004 tb.Value = value_pos + tb.Minimum;
4007 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4009 /* Draw thumb fixed 10x22 size */
4010 thumb_pos.Width = 10;
4011 thumb_pos.Height = 22;
4013 switch (tb.TickStyle) {
4014 case TickStyle.BottomRight:
4015 case TickStyle.None: {
4016 thumb_pos.Y = channel_startpoint.Y - 8;
4018 Pen pen = SystemPens.ControlLight;
4019 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4020 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4021 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4023 pen = SystemPens.ControlDark;
4024 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4025 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4027 pen = SystemPens.ControlDarkDark;
4028 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4029 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4031 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4032 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4033 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4034 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4037 case TickStyle.TopLeft: {
4038 thumb_pos.Y = channel_startpoint.Y - 10;
4040 Pen pen = SystemPens.ControlLight;
4041 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4042 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4044 pen = SystemPens.ControlDark;
4045 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4046 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4047 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4049 pen = SystemPens.ControlDarkDark;
4050 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4051 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4052 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4054 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4055 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4056 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4057 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4061 case TickStyle.Both: {
4062 thumb_pos.Y = area.Y + 10;
4064 Pen pen = SystemPens.ControlLight;
4065 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4066 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4068 pen = SystemPens.ControlDark;
4069 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4070 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4072 pen = SystemPens.ControlDarkDark;
4073 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4074 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4076 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4085 pixel_len = thumb_area.Width - 11;
4086 pixels_betweenticks = pixel_len / ticks;
4089 thumb_area.Y = thumb_pos.Y;
4090 thumb_area.X = channel_startpoint.X;
4091 thumb_area.Height = thumb_pos.Height;
4092 Region outside = new Region (area);
4093 outside.Exclude (thumb_area);
4095 if (outside.IsVisible (clip_rectangle)) {
4096 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4097 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4099 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4100 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4101 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4102 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4104 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4105 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4109 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4110 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4112 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4113 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4114 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4115 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4117 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4118 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4126 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4131 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4133 Rectangle thumb_pos = tb.ThumbPos;
4134 Rectangle thumb_area = tb.ThumbArea;
4136 if (tb.thumb_pressed) {
4137 value_pos = tb.thumb_mouseclick;
4140 value_pos = tb.Value - tb.Minimum;
4141 mouse_value = false;
4144 area = tb.ClientRectangle;
4146 if (tb.thumb_pressed == true) {
4147 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4149 br_thumb = SystemBrushes.Control;
4153 /* Control Background */
4154 if (tb.BackColor == DefaultControlBackColor) {
4155 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
4157 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4162 Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
4163 dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
4164 dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4165 dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
4166 dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4169 if (tb.Orientation == Orientation.Vertical) {
4170 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4171 br_thumb, ticks, value_pos, mouse_value);
4174 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4175 br_thumb, ticks, value_pos, mouse_value);
4178 tb.ThumbPos = thumb_pos;
4179 tb.ThumbArea = thumb_area;
4182 public override Size TrackBarDefaultSize {
4184 return new Size (104, 42);
4188 #endregion // TrackBar
4191 public override Size VScrollBarDefaultSize {
4193 return new Size (this.ScrollBarButtonSize, 80);
4196 #endregion // VScrollBar
4199 public override Size TreeViewDefaultSize {
4201 return new Size (121, 97);
4207 #region ControlPaint
4208 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4209 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4210 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4211 int bottomWidth, ButtonBorderStyle bottomStyle) {
4212 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4213 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4214 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4215 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4218 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4219 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4222 protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
4225 Pen penTopLeftInner;
4227 Pen penBottomRightInner;
4228 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4229 bool is_ColorControl = control_color == ColorControl ? true : false;
4231 if ((style & Border3DStyle.Adjust) != 0) {
4238 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
4240 CPColor cpcolor = CPColor.Empty;
4242 if (!is_ColorControl)
4243 cpcolor = ResPool.GetCPColor (control_color);
4246 case Border3DStyle.Raised:
4247 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4248 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4249 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4251 case Border3DStyle.Sunken:
4252 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4253 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4254 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4256 case Border3DStyle.Etched:
4257 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4258 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4260 case Border3DStyle.RaisedOuter:
4261 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4263 case Border3DStyle.SunkenOuter:
4264 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4265 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4267 case Border3DStyle.RaisedInner:
4268 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4269 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4271 case Border3DStyle.SunkenInner:
4272 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4274 case Border3DStyle.Flat:
4275 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4277 case Border3DStyle.Bump:
4278 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4284 if ((sides & Border3DSide.Middle) != 0) {
4285 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
4286 graphics.FillRectangle (brush, rect);
4289 if ((sides & Border3DSide.Left) != 0) {
4290 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
4291 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
4294 if ((sides & Border3DSide.Top) != 0) {
4295 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
4296 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
4299 if ((sides & Border3DSide.Right) != 0) {
4300 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
4301 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
4304 if ((sides & Border3DSide.Bottom) != 0) {
4305 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4306 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
4310 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
4312 // sadly enough, the rectangle gets always filled with a hatchbrush
4313 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
4315 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
4316 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4318 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4320 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4321 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4323 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4324 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4326 Pen pen = SystemPens.ControlDarkDark;
4327 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4328 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4330 pen = SystemPens.ControlDark;
4331 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4332 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4334 pen = SystemPens.ControlLight;
4335 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4336 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4338 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
4339 Pen pen = SystemPens.ControlDarkDark;
4340 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4341 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4343 pen = SystemPens.ControlDark;
4344 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4345 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4347 pen = SystemPens.ControlLight;
4348 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4349 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4351 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
4352 Pen pen = SystemPens.ControlLight;
4353 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4354 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4356 pen = SystemPens.ControlDark;
4357 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
4358 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
4360 pen = SystemPens.ControlDarkDark;
4361 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
4362 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
4367 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4368 Rectangle captionRect;
4371 CPDrawButton(graphics, rectangle, state);
4373 if (rectangle.Width<rectangle.Height) {
4374 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4376 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4379 if ((state & ButtonState.Pushed)!=0) {
4380 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4383 /* Make sure we've got at least a line width of 1 */
4384 lineWidth=Math.Max(1, captionRect.Width/7);
4387 case CaptionButton.Close: {
4390 if ((state & ButtonState.Inactive)!=0) {
4391 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
4392 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4394 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
4395 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4398 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
4399 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4404 case CaptionButton.Help:
4405 case CaptionButton.Maximize:
4406 case CaptionButton.Minimize:
4407 case CaptionButton.Restore: {
4408 if ((state & ButtonState.Inactive)!=0) {
4409 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4411 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4414 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4421 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
4423 Pen check_pen = SystemPens.ControlDarkDark;
4425 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4427 if ((state & ButtonState.All) == ButtonState.All) {
4429 cb_rect.Height -= 2;
4431 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4432 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4434 check_pen = SystemPens.ControlDark;
4436 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4438 cb_rect.Height -= 2;
4440 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4441 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4444 cb_rect.Height -= 1;
4446 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
4448 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
4449 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
4451 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
4453 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
4454 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4456 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4458 Pen pen = SystemPens.ControlDark;
4459 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
4460 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
4462 pen = SystemPens.ControlDarkDark;
4463 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
4464 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
4466 pen = SystemPens.ControlLight;
4467 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
4468 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
4470 // oh boy, matching ms is like fighting against windmills
4471 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl))) {
4472 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4473 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
4476 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
4477 check_pen = SystemPens.ControlDark;
4480 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4481 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
4483 if (check_size < 7) {
4484 int lineWidth = Math.Max (3, check_size / 3);
4485 int Scale = Math.Max (1, check_size / 9);
4487 Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1,
4488 check_size, check_size);
4490 for (int i = 0; i < lineWidth; i++) {
4491 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
4492 dc.DrawLine (check_pen, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i, rect.Left + lineWidth / 2 + 6 * Scale, rect.Top + lineWidth - 2 * Scale + i);
4495 int lineWidth = Math.Max (3, check_size / 3) + 1;
4497 int x_half = cb_rect.Width / 2;
4498 int y_half = cb_rect.Height / 2;
4500 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
4501 check_size, check_size);
4503 int gradient_left = check_size / 3;
4504 int gradient_right = check_size - gradient_left - 1;
4507 for (int i = 0; i < lineWidth; i++) {
4508 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
4509 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
4515 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4516 Point[] arrow = new Point[3];
4526 if ((state & ButtonState.Checked)!=0) {
4527 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4530 if ((state & ButtonState.Flat)!=0) {
4531 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4533 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4534 // this needs to render like a pushed button - jba
4535 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4536 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4537 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
4539 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4543 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4544 centerX=rect.Left+rect.Width/2;
4545 centerY=rect.Top+rect.Height/2;
4546 shiftX=Math.Max(1, rect.Width/8);
4547 shiftY=Math.Max(1, rect.Height/8);
4549 if ((state & ButtonState.Pushed)!=0) {
4556 P1=new Point(rect.Left, centerY);
4557 P2=new Point(rect.Right, centerY);
4558 P3=new Point(centerX, rect.Bottom);
4564 /* Draw the arrow */
4565 if ((state & ButtonState.Inactive)!=0) {
4566 /* Move away from the shadow */
4567 arrow[0].X += 1; arrow[0].Y += 1;
4568 arrow[1].X += 1; arrow[1].Y += 1;
4569 arrow[2].X += 1; arrow[2].Y += 1;
4571 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4577 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4579 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4584 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
4586 Pen pen = Pens.Black;
4587 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
4591 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
4592 graphics.DrawRectangle (pen, rect);
4594 X = rect.X + rect.Width / 2;
4595 Y = rect.Y + rect.Height / 2;
4597 /* Draw the cross */
4598 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
4599 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
4601 /* Draw 'arrows' for vertical lines */
4602 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
4603 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
4605 /* Draw 'arrows' for horizontal lines */
4606 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
4607 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
4610 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4611 // make a rectange to trace around border of the button
4612 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4614 Color outerColor = foreColor;
4615 // adjust focus color according to the flatstyle
4616 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4617 outerColor = (backColor == ColorControl) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4620 // draw the outer rectangle
4621 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4623 // draw the inner rectangle
4624 if (button.FlatStyle == FlatStyle.Popup) {
4625 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4627 // draw a flat inner rectangle
4628 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4629 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4633 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4635 // make a rectange to trace around border of the button
4636 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4638 #if NotUntilCairoIsFixed
4639 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4640 DashStyle oldStyle; // used for caching old penstyle
4641 Pen pen = ResPool.GetPen (colorBackInverted);
4643 oldStyle = pen.DashStyle;
4644 pen.DashStyle = DashStyle.Dot;
4646 graphics.DrawRectangle (pen, trace_rectangle);
4647 pen.DashStyle = oldStyle;
4649 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4654 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4656 Rectangle rect = rectangle;
4660 if (backColor.GetBrightness () >= 0.5) {
4661 foreColor = Color.Transparent;
4662 backColor = Color.Black;
4665 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4666 foreColor = Color.Black;
4669 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4670 pen = new Pen (brush, 1);
4675 graphics.DrawRectangle (pen, rect);
4679 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
4684 if (primary == true) {
4686 if (enabled == true) {
4689 sb = SystemBrushes.Control;
4693 if (enabled == true) {
4696 sb = SystemBrushes.Control;
4699 graphics.FillRectangle (sb, rectangle);
4700 graphics.DrawRectangle (pen, rectangle);
4704 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4710 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4713 foreColor=Color.Black;
4715 foreColor=Color.White;
4720 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4722 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4723 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4724 bitmap.SetPixel(x, y, foreColor);
4727 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4730 #if correct_but_needs_libgdiplus_fix_bug_nr_78059
4731 using (Pen pen = new Pen (foreColor)) {
4732 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
4734 for (int y = area.Y; y < area.Bottom; y += pixelsBetweenDots.Height - 1)
4735 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
4740 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4742 Microsoft seems to ignore the background and simply make
4743 the image grayscale. At least when having > 256 colors on
4747 if (imagedisabled_attributes == null) {
4748 imagedisabled_attributes = new ImageAttributes ();
4749 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4750 // This table would create a perfect grayscale image, based on luminance
4751 // new float[]{0.3f,0.3f,0.3f,0,0},
4752 // new float[]{0.59f,0.59f,0.59f,0,0},
4753 // new float[]{0.11f,0.11f,0.11f,0,0},
4754 // new float[]{0,0,0,1,0,0},
4755 // new float[]{0,0,0,0,1,0},
4756 // new float[]{0,0,0,0,0,1}
4758 // This table generates a image that is grayscaled and then
4759 // brightened up. Seems to match MS close enough.
4760 new float[]{0.2f,0.2f,0.2f,0,0},
4761 new float[]{0.41f,0.41f,0.41f,0,0},
4762 new float[]{0.11f,0.11f,0.11f,0,0},
4763 new float[]{0.15f,0.15f,0.15f,1,0,0},
4764 new float[]{0.15f,0.15f,0.15f,0,1,0},
4765 new float[]{0.15f,0.15f,0.15f,0,0,1}
4768 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4771 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4776 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4781 penBorder = ResPool.GetSizedPen (Color.White, 2);
4782 penInside = ResPool.GetPen (Color.Black);
4784 penBorder = ResPool.GetSizedPen (Color.Black, 2);
4785 penInside = ResPool.GetPen (Color.White);
4787 penBorder.Alignment=PenAlignment.Inset;
4788 penInside.Alignment=PenAlignment.Inset;
4790 graphics.DrawRectangle(penBorder, rectangle);
4791 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4795 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
4799 Brush brush = ResPool.GetSolidBrush (color);
4802 case MenuGlyph.Arrow: {
4803 Point[] arrow = new Point[3];
4811 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4812 centerX=rect.Left+rect.Width/2;
4813 centerY=rect.Top+rect.Height/2;
4814 shiftX=Math.Max(1, rect.Width/8);
4819 P1=new Point(centerX, rect.Top-1);
4820 P2=new Point(centerX, rect.Bottom);
4821 P3=new Point(rect.Right, centerY);
4827 graphics.FillPolygon(brush, arrow, FillMode.Winding);
4832 case MenuGlyph.Bullet: {
4834 lineWidth=Math.Max(2, rectangle.Width/3);
4835 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4837 graphics.FillEllipse(brush, rect);
4842 case MenuGlyph.Checkmark: {
4844 Pen pen = ResPool.GetPen (color);
4846 lineWidth=Math.Max(2, rectangle.Width/6);
4847 Scale=Math.Max(1, rectangle.Width/12);
4849 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4851 for (int i=0; i<lineWidth; i++) {
4852 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4853 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);
4861 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
4863 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
4865 Color dot_color = Color.Black;
4867 Color top_left_outer = Color.Black;
4868 Color top_left_inner = Color.Black;
4869 Color bottom_right_outer = Color.Black;
4870 Color bottom_right_inner = Color.Black;
4872 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
4873 int radius = ellipse_diameter / 2;
4875 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
4879 if ((state & ButtonState.All) == ButtonState.All) {
4880 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
4881 dot_color = cpcolor.Dark;
4883 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4884 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
4885 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
4887 brush = SystemBrushes.ControlLightLight;
4889 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
4890 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
4892 brush = SystemBrushes.ControlLightLight;
4894 top_left_outer = cpcolor.Dark;
4895 top_left_inner = cpcolor.DarkDark;
4896 bottom_right_outer = cpcolor.Light;
4897 bottom_right_inner = Color.Transparent;
4899 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
4900 dot_color = cpcolor.Dark;
4903 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
4905 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
4907 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
4908 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
4909 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
4911 if (bottom_right_inner != Color.Transparent)
4912 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
4914 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), line_width)) {
4915 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
4918 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4919 int inflate = line_width * 4;
4920 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
4921 if (rectangle.Height > 13) {
4925 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
4927 Pen pen = ResPool.GetPen (dot_color);
4928 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
4929 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
4931 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
4932 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
4937 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4942 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4947 /* Scroll button: regular button + direction arrow */
4948 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4949 DrawScrollButtonPrimitive (dc, area, state);
4951 int arrow_y_pos_diff = 3;
4954 case ScrollButton.Up:
4955 arrow_y_pos_diff = 2;
4957 case ScrollButton.Down:
4958 arrow_y_pos_diff = 4;
4964 // A lot of the following is adapted from the rewind project
4965 Rectangle rect = new Rectangle (area.X - 3, area.Y - arrow_y_pos_diff,
4966 area.Width + 6, area.Height + 6);
4967 int small_diam = rect.Width > rect.Height ? rect.Height : rect.Width;
4968 if (rect.Width < rect.Height) {
4969 rect.Y += (rect.Height - rect.Width) / 2;
4970 rect.Height = small_diam;
4971 } else if (rect.Width > rect.Height) {
4972 rect.X += (rect.Width - rect.Height) / 2;
4973 rect.Width = small_diam;
4978 int tri = 290 * small_diam / 1000 - 1;
4982 Point [] arrow = new Point [3];
4983 for (int i = 0; i < 3; i++)
4984 arrow [i] = new Point ();
4988 case ScrollButton.Down:
4989 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
4990 arrow [2].Y = rect.Top + 687 * small_diam / 1000 + 1;
4991 arrow [0].X = arrow [2].X - tri;
4992 arrow [1].X = arrow [2].X + tri;
4993 arrow [0].Y = arrow [1].Y = arrow [2].Y - tri;
4996 case ScrollButton.Up:
4997 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
4998 arrow [2].Y = rect.Bottom - (687 * small_diam / 1000 + 1);
4999 arrow [0].X = arrow [2].X - tri;
5000 arrow [1].X = arrow [2].X + tri;
5001 arrow [0].Y = arrow [1].Y = arrow [2].Y + tri;
5004 case ScrollButton.Left:
5005 arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
5006 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
5007 arrow [0].Y = arrow [2].Y - tri;
5008 arrow [1].Y = arrow [2].Y + tri;
5009 arrow [0].X = arrow [1].X = arrow [2].X + tri;
5011 // Left and Right are not drawn correctly because of libgdiplus problems
5012 // once that is solved change it to the code below to match ms
5013 // case ScrollButton.Left:
5014 // arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
5015 // arrow [2].Y = (rect.Top + 470 * small_diam / 1000 + 2) - 1;
5016 // arrow [1].Y = arrow [2].Y + tri;
5017 // arrow [0].Y = arrow [2].Y - tri + 1;
5018 // arrow [0].X = arrow [1].X = arrow [2].X + tri;
5020 case ScrollButton.Right:
5021 arrow [2].X = rect.Left + 687 * small_diam / 1000 + 1;
5022 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
5023 arrow [0].Y = arrow [2].Y - tri;
5024 arrow [1].Y = arrow [2].Y + tri;
5025 arrow [0].X = arrow [1].X = arrow [2].X - tri;
5029 /* Draw the arrow */
5030 if ((state & ButtonState.Inactive)!=0) {
5031 dc.FillPolygon (SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
5033 for (int i = 0; i < 3; i++) {
5038 dc.FillPolygon (SystemBrushes.ControlDark, arrow, FillMode.Winding);
5040 dc.FillPolygon (SystemBrushes.ControlText, arrow, FillMode.Winding);
5044 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5050 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
5052 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
5053 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
5055 for (int i = 2; i < bounds.Width - 2; i += 4) {
5056 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
5057 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
5058 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
5062 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
5064 CPColor cpcolor = ResPool.GetCPColor (color);
5066 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
5067 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
5069 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
5072 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5073 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5078 case ButtonBorderStyle.Solid:
5079 case ButtonBorderStyle.Inset:
5080 case ButtonBorderStyle.Outset:
5081 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
5083 case ButtonBorderStyle.Dashed:
5084 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
5086 case ButtonBorderStyle.Dotted:
5087 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
5090 case ButtonBorderStyle.None:
5095 case ButtonBorderStyle.Outset: {
5097 int hue, brightness, saturation;
5098 int brightnessSteps;
5099 int brightnessDownSteps;
5101 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5103 brightnessDownSteps=brightness/width;
5104 if (brightness>127) {
5105 brightnessSteps=Math.Max(6, (160-brightness)/width);
5107 brightnessSteps=(127-brightness)/width;
5110 for (int i=0; i<width; i++) {
5112 case Border3DSide.Left: {
5113 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5114 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5115 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5119 case Border3DSide.Right: {
5120 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5121 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5122 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5126 case Border3DSide.Top: {
5127 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5128 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5129 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5133 case Border3DSide.Bottom: {
5134 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5135 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5136 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5144 case ButtonBorderStyle.Inset: {
5146 int hue, brightness, saturation;
5147 int brightnessSteps;
5148 int brightnessDownSteps;
5150 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5152 brightnessDownSteps=brightness/width;
5153 if (brightness>127) {
5154 brightnessSteps=Math.Max(6, (160-brightness)/width);
5156 brightnessSteps=(127-brightness)/width;
5159 for (int i=0; i<width; i++) {
5161 case Border3DSide.Left: {
5162 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5163 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5164 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5168 case Border3DSide.Right: {
5169 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5170 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5171 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5175 case Border3DSide.Top: {
5176 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5177 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5178 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5182 case Border3DSide.Bottom: {
5183 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5184 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5185 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5194 I decided to have the for-loop duplicated for speed reasons;
5195 that way we only have to switch once (as opposed to have the
5196 for-loop around the switch)
5200 case Border3DSide.Left: {
5201 for (int i=0; i<width; i++) {
5202 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5207 case Border3DSide.Right: {
5208 for (int i=0; i<width; i++) {
5209 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5214 case Border3DSide.Top: {
5215 for (int i=0; i<width; i++) {
5216 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5221 case Border3DSide.Bottom: {
5222 for (int i=0; i<width; i++) {
5223 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5234 This function actually draws the various caption elements.
5235 This way we can scale them nicely, no matter what size, and they
5236 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5239 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5241 case CaptionButton.Close: {
5242 LineCap oldStartCap = pen.StartCap;
5243 LineCap oldEndCap = pen.EndCap;
5244 pen.StartCap=LineCap.Triangle;
5245 pen.EndCap=LineCap.Triangle;
5247 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);
5248 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);
5251 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5252 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5253 pen.StartCap = oldStartCap;
5254 pen.EndCap = oldEndCap;
5258 case CaptionButton.Help: {
5259 StringFormat sf = new StringFormat();
5260 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5262 sf.Alignment=StringAlignment.Center;
5263 sf.LineAlignment=StringAlignment.Center;
5266 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5274 case CaptionButton.Maximize: {
5275 /* Top 'caption bar' line */
5276 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5277 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);
5280 /* Left side line */
5281 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5282 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5285 /* Right side line */
5286 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5287 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);
5291 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5292 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5297 case CaptionButton.Minimize: {
5299 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5300 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5305 case CaptionButton.Restore: {
5306 /** First 'window' **/
5307 /* Top 'caption bar' line */
5308 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5309 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);
5312 /* Left side line */
5313 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5314 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);
5317 /* Right side line */
5318 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5319 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);
5323 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5324 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);
5327 /** Second 'window' **/
5328 /* Top 'caption bar' line */
5329 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5330 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);
5333 /* Left side line */
5334 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5335 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5338 /* Right side line */
5339 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5340 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);
5344 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5345 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5354 /* Generic scroll button */
5355 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5356 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5357 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
5358 area.Y + 1, area.Width - 2 , area.Height - 2);
5360 dc.DrawRectangle (SystemPens.ControlDark, area.X,
5361 area.Y, area.Width, area.Height);
5366 Brush sb_control = SystemBrushes.Control;
5367 Brush sb_lightlight = SystemBrushes.ControlLightLight;
5368 Brush sb_dark = SystemBrushes.ControlDark;
5369 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
5371 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
5372 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
5374 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
5375 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
5378 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
5381 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
5384 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
5385 area.Y + 1, 1, area.Height -3);
5387 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
5388 area.Y, 1, area.Height - 1);
5390 dc.FillRectangle (sb_control, area.X + 2,
5391 area.Y + 2, area.Width - 4, area.Height - 4);
5395 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5396 switch (border_style){
5397 case BorderStyle.Fixed3D:
5398 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5399 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5400 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5401 area.Y + area.Height - 1);
5402 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5403 area.Y + area.Height);
5405 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5406 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5407 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5408 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5410 case BorderStyle.FixedSingle:
5411 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5413 case BorderStyle.None:
5419 #endregion // ControlPaint