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, 8f);
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);
364 if (button.has_focus) {
365 Rectangle rect = Rectangle.Inflate (button.ClientRectangle, -4, -4);
366 ControlPaint.DrawFocusRectangle (dc, rect);
370 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
372 Rectangle buttonRectangle = button.ClientRectangle;
373 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
375 if (button.is_pressed) {
380 if (button.is_enabled) {
381 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
383 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
384 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
386 CPDrawStringDisabled (dc, button.text, button.Font, button.BackColor, text_rect, button.text_format);
391 public override Size ButtonBaseDefaultSize {
393 return new Size (75, 23);
396 #endregion // ButtonBase
399 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
400 StringFormat text_format;
401 Rectangle client_rectangle;
402 Rectangle text_rectangle;
403 Rectangle checkbox_rectangle;
404 int checkmark_size=13;
405 int checkmark_space = 4;
407 client_rectangle = checkbox.ClientRectangle;
408 text_rectangle = client_rectangle;
409 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
411 text_format = new StringFormat();
412 text_format.Alignment=StringAlignment.Near;
413 text_format.LineAlignment=StringAlignment.Center;
414 text_format.HotkeyPrefix = HotkeyPrefix.Show;
416 /* Calculate the position of text and checkbox rectangle */
417 if (checkbox.appearance!=Appearance.Button) {
418 switch(checkbox.check_alignment) {
419 case ContentAlignment.BottomCenter: {
420 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
421 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
422 text_rectangle.X=client_rectangle.X;
423 text_rectangle.Width=client_rectangle.Width;
424 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
428 case ContentAlignment.BottomLeft: {
429 checkbox_rectangle.X=client_rectangle.Left;
430 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
431 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
432 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
436 case ContentAlignment.BottomRight: {
437 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
438 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
439 text_rectangle.X=client_rectangle.X;
440 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
444 case ContentAlignment.MiddleCenter: {
445 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
446 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
447 text_rectangle.X=client_rectangle.X;
448 text_rectangle.Width=client_rectangle.Width;
453 case ContentAlignment.MiddleLeft: {
454 checkbox_rectangle.X=client_rectangle.Left;
455 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
456 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
457 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
461 case ContentAlignment.MiddleRight: {
462 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
463 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
464 text_rectangle.X=client_rectangle.X;
465 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
469 case ContentAlignment.TopCenter: {
470 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
471 checkbox_rectangle.Y=client_rectangle.Top;
472 text_rectangle.X=client_rectangle.X;
473 text_rectangle.Width=client_rectangle.Width;
474 text_rectangle.Y=checkmark_size+checkmark_space;
475 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
479 case ContentAlignment.TopLeft: {
480 checkbox_rectangle.X=client_rectangle.Left;
481 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
482 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
486 case ContentAlignment.TopRight: {
487 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
488 text_rectangle.X=client_rectangle.X;
489 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
494 text_rectangle.X=client_rectangle.X;
495 text_rectangle.Width=client_rectangle.Width;
498 /* Set the horizontal alignment of our text */
499 switch(checkbox.text_alignment) {
500 case ContentAlignment.BottomLeft:
501 case ContentAlignment.MiddleLeft:
502 case ContentAlignment.TopLeft: {
503 text_format.Alignment=StringAlignment.Near;
507 case ContentAlignment.BottomCenter:
508 case ContentAlignment.MiddleCenter:
509 case ContentAlignment.TopCenter: {
510 text_format.Alignment=StringAlignment.Center;
514 case ContentAlignment.BottomRight:
515 case ContentAlignment.MiddleRight:
516 case ContentAlignment.TopRight: {
517 text_format.Alignment=StringAlignment.Far;
522 /* Set the vertical alignment of our text */
523 switch(checkbox.text_alignment) {
524 case ContentAlignment.TopLeft:
525 case ContentAlignment.TopCenter:
526 case ContentAlignment.TopRight: {
527 text_format.LineAlignment=StringAlignment.Near;
531 case ContentAlignment.BottomLeft:
532 case ContentAlignment.BottomCenter:
533 case ContentAlignment.BottomRight: {
534 text_format.LineAlignment=StringAlignment.Far;
538 case ContentAlignment.MiddleLeft:
539 case ContentAlignment.MiddleCenter:
540 case ContentAlignment.MiddleRight: {
541 text_format.LineAlignment=StringAlignment.Center;
546 ButtonState state = ButtonState.Normal;
547 if (checkbox.FlatStyle == FlatStyle.Flat) {
548 state |= ButtonState.Flat;
551 if (checkbox.Checked) {
552 state |= ButtonState.Checked;
555 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
556 state |= ButtonState.Checked;
557 state |= ButtonState.Pushed;
560 // finally make sure the pushed and inavtive states are rendered
561 if (!checkbox.Enabled) {
562 state |= ButtonState.Inactive;
564 else if (checkbox.is_pressed) {
565 state |= ButtonState.Pushed;
570 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
572 if ((checkbox.image != null) || (checkbox.image_list != null))
573 ButtonBase_DrawImage(checkbox, dc);
575 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
577 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
579 text_format.Dispose ();
582 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
584 Brush brush = checkbox.BackColor == ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
585 dc.FillRectangle (brush, checkbox.ClientRectangle);
586 // render as per normal button
587 if (checkbox.appearance==Appearance.Button) {
588 ButtonBase_DrawButton (checkbox, dc);
590 // establish if we are rendering a flat style of some sort
591 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
592 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
594 CPDrawCheckBox (dc, checkbox_rectangle, state);
599 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
601 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
602 text_format, checkbox.Appearance, checkbox.Checked);
605 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
607 // do nothing here. maybe an other theme needs it
610 // renders a checkBox with the Flat and Popup FlatStyle
611 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
615 Rectangle checkbox_rectangle;
616 Rectangle fill_rectangle;
620 // set up our rectangles first
621 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
622 // clip one pixel from bottom right for non popup rendered checkboxes
623 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
624 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));
626 // clip two pixels from bottom right for non popup rendered checkboxes
627 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
628 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));
632 // if disabled render in disabled state
633 if (checkbox.Enabled) {
634 // process the state of the checkbox
635 if (checkbox.is_entered || checkbox.Capture) {
636 // decide on which background color to use
637 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
638 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
639 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
640 if (!checkbox.is_pressed) {
641 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
643 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
645 // use regular window background color
646 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
649 // render the outer border
650 if (checkbox.FlatStyle == FlatStyle.Flat) {
651 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
653 // draw sunken effect
654 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
657 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
659 if (checkbox.FlatStyle == FlatStyle.Flat) {
660 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
662 // draw the outer border
663 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
667 if (checkbox.FlatStyle == FlatStyle.Popup) {
668 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
671 // draw disabled state,
672 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
675 if (checkbox.Checked) {
676 /* Need to draw a check-mark */
678 /* Make sure we've got at least a line width of 1 */
679 lineWidth = Math.Max(3, fill_rectangle.Width/3);
680 Scale=Math.Max(1, fill_rectangle.Width/9);
682 // flat style check box is rendered inside a rectangle shifted down by one
683 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
684 if (checkbox.Enabled) {
685 pen=ResPool.GetPen(checkbox.ForeColor);
687 pen=SystemPens.ControlDark;
690 for (int i=0; i<lineWidth; i++) {
691 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
692 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);
697 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
698 StringFormat text_format, Appearance appearance, bool ischecked)
700 // offset the text if it's pressed and a button
701 if (appearance == Appearance.Button) {
702 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
707 text_rectangle.Inflate (-4, -4);
710 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
712 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
713 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
714 text_format.FormatFlags |= StringFormatFlags.NoWrap;
716 if (button_base.Enabled) {
717 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
718 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
719 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
721 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
724 #endregion // CheckBox
726 #region CheckedListBox
728 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
730 Color back_color, fore_color;
731 Rectangle item_rect = e.Bounds;
736 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
737 state = ButtonState.Checked;
738 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
739 state |= ButtonState.Inactive;
741 state = ButtonState.Normal;
743 if (ctrl.ThreeDCheckBoxes == false)
744 state |= ButtonState.Flat;
746 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
747 ControlPaint.DrawCheckBox (e.Graphics,
748 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
749 checkbox_rect.Width, checkbox_rect.Height,
752 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
753 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
756 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
757 back_color = ColorHighlight;
758 fore_color = ColorHighlightText;
761 back_color = e.BackColor;
762 fore_color = e.ForeColor;
765 e.Graphics.FillRectangle (ResPool.GetSolidBrush
766 (back_color), item_rect);
768 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
769 ResPool.GetSolidBrush (fore_color),
770 item_rect, ctrl.StringFormat);
772 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
773 CPDrawFocusRectangle (e.Graphics, item_rect,
774 fore_color, back_color);
778 #endregion // CheckedListBox
781 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
783 Color back_color, fore_color;
784 Rectangle text_draw = e.Bounds;
785 StringFormat string_format = new StringFormat ();
786 string_format.FormatFlags = StringFormatFlags.LineLimit;
788 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
789 back_color = ColorHighlight;
790 fore_color = ColorHighlightText;
793 back_color = e.BackColor;
794 fore_color = e.ForeColor;
797 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
800 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
801 ResPool.GetSolidBrush (fore_color),
802 text_draw, string_format);
805 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
806 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
809 string_format.Dispose ();
814 public override int DataGridPreferredColumnWidth { get { return 75;} }
815 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
816 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
817 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
818 public override Color DataGridBackColor { get { return ColorWindow;} }
819 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
820 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
821 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
822 public override Color DataGridGridLineColor { get { return ColorControl;} }
823 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
824 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
825 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
826 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
827 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
828 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
829 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
830 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
832 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
835 if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
836 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
839 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
840 DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
841 DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
842 DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
844 // Paint scrollBar corner
845 if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
847 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
848 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
849 grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
851 if (pe.ClipRectangle.IntersectsWith (corner)) {
852 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
858 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
860 Rectangle modified_area = clip;
861 modified_area.Intersect (grid.grid_drawing.caption_area);
863 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
866 g.DrawString (grid.CaptionText, grid.CaptionFont,
867 ResPool.GetSolidBrush (grid.CaptionForeColor),
868 grid.grid_drawing.caption_area);
871 public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
873 Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
875 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
876 Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
877 rect_bloc.Width = grid.RowHeaderWidth;
878 rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
879 if (clip.IntersectsWith (rect_bloc)) {
880 if (grid.visiblecolumn_count > 0) {
881 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
883 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
887 columns_area.X += grid.RowHeaderWidth;
888 columns_area.Width -= grid.RowHeaderWidth;
892 Rectangle columnshdrs_area_complete = columns_area;
893 columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
895 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
896 columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
899 // Set column painting
900 Rectangle rect_columnhdr = new Rectangle ();
903 rect_columnhdr.Y = columns_area.Y;
904 rect_columnhdr.Height = columns_area.Height;
906 current_clip = new Region (columns_area);
907 g.Clip = current_clip;
908 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
909 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
911 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
912 rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
913 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
915 if (clip.IntersectsWith (rect_columnhdr) == false)
918 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
923 current_clip.Dispose ();
926 Rectangle not_usedarea = columnshdrs_area_complete;
927 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
928 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
929 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
933 public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
935 Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
936 rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
937 Rectangle rect_row = new Rectangle ();
938 rect_row.X = grid.grid_drawing.rowshdrs_area.X;
939 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
940 Rectangle not_usedarea = rowshdrs_area_complete;
942 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
946 g.SetClip (grid.grid_drawing.rowshdrs_area);
947 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
949 rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
950 rect_row.Height = grid.RowHeight;
951 rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
953 if (clip.IntersectsWith (rect_row)) {
954 DataGridPaintRowHeader (g, rect_row, row, grid);
959 not_usedarea.Height = grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
960 not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + grid.grid_drawing.rowshdrs_area.Height;
961 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
964 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
966 Point[] arrow = new Point[3];
968 int centerX, centerY, shiftX;
971 rect = new Rectangle (bounds.X + bounds.Width /4,
972 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
974 centerX = rect.Left + rect.Width / 2;
975 centerY = rect.Top + rect.Height / 2;
976 shiftX = Math.Max (1, rect.Width / 8);
979 P1 = new Point (centerX, rect.Top - 1);
980 P2 = new Point (centerX, rect.Bottom);
981 P3 = new Point (rect.Right, centerY);
986 g.FillPolygon (ResPool.GetSolidBrush
987 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
990 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
993 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
996 if (grid.FlatMode == false) {
999 g.DrawLine (ResPool.GetPen (ColorControlLight),
1000 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1002 g.DrawLine (ResPool.GetPen (ColorControlLight),
1003 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1005 g.DrawLine (ResPool.GetPen (ColorControlDark),
1006 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1008 g.DrawLine (ResPool.GetPen (ColorControlDark),
1009 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1012 if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
1014 g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1019 if (row == grid.CurrentCell.RowNumber) {
1021 if (grid.is_changing == true) {
1022 g.DrawString ("...", grid.Font,
1023 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1028 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1029 DataGridPaintRowHeaderArrow (g, rect, grid);
1035 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1037 Rectangle rect_row = new Rectangle ();
1038 Rectangle not_usedarea = new Rectangle ();
1039 rect_row.X = cells.X;
1041 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1043 if (grid.ShowEditRow && grid.RowsCount > 0) {
1047 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1051 rect_row.Height = grid.RowHeight;
1052 rect_row.Width = cells.Width;
1053 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1054 rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1055 if (clip.IntersectsWith (rect_row)) {
1056 DataGridPaintRow (g, row, rect_row, false, clip, grid);
1060 if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
1061 rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
1062 if (clip.IntersectsWith (rect_row)) {
1063 DataGridPaintRow (g, rowcnt, rect_row, true, clip, grid);
1068 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1069 not_usedarea.Y = rect_row.Y + rect_row.Height;
1070 not_usedarea.Width = rect_row.Width = cells.Width;
1071 not_usedarea.X = cells.X;
1073 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1076 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1077 Rectangle clip, DataGrid grid)
1079 Rectangle rect_cell = new Rectangle ();
1081 Color backcolor, forecolor;
1082 Brush backBrush, foreBrush;
1083 Region prev_clip = g.Clip;
1084 Region current_clip;
1085 Rectangle not_usedarea = new Rectangle ();
1087 rect_cell.Y = row_rect.Y;
1088 rect_cell.Height = row_rect.Height;
1090 if (grid.IsSelected (row)) {
1091 backcolor = grid.SelectionBackColor;
1092 forecolor = grid.SelectionForeColor;
1095 backcolor = grid.BackColor;
1097 backcolor = grid.AlternatingBackColor;
1100 forecolor = grid.ForeColor;
1104 backBrush = ResPool.GetSolidBrush (backcolor);
1105 foreBrush = ResPool.GetSolidBrush (forecolor);
1107 // PaintCells at row, column
1108 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1109 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1111 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1113 rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
1114 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1116 if (clip.IntersectsWith (rect_cell)) {
1117 current_clip = new Region (row_rect);
1118 current_clip.Intersect (rect_cell);
1119 g.Clip = current_clip;
1122 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1126 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1129 grid.RightToLeft == RightToLeft.Yes);
1132 current_clip.Dispose ();
1138 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1139 not_usedarea.X = rect_cell.X + rect_cell.Width;
1140 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1141 not_usedarea.Y = row_rect.Y;
1142 not_usedarea.Height = row_rect.Height;
1143 if (clip.IntersectsWith (not_usedarea))
1144 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1149 #endregion // Datagrid
1151 #region DateTimePicker
1153 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1154 // if not showing the numeric updown control then render border
1155 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1156 // draw the outer border
1157 Rectangle button_bounds = dtp.ClientRectangle;
1158 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1160 // deflate by the border width
1161 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1162 button_bounds.Inflate (-2,-2);
1163 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1164 this.CPDrawComboButton (
1166 dtp.drop_down_arrow_rect,
1171 // render the date part
1172 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1173 // fill the background
1174 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
1176 // fill the currently highlighted area
1177 if (dtp.hilight_date_area != Rectangle.Empty) {
1178 dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
1181 // draw the text part
1182 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1183 StringFormat text_format = new StringFormat();
1184 text_format.LineAlignment = StringAlignment.Center;
1185 text_format.Alignment = StringAlignment.Near;
1186 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1187 text_format.Dispose ();
1191 #endregion // DateTimePicker
1194 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1195 StringFormat text_format;
1200 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
1202 text_format = new StringFormat();
1203 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1205 size = dc.MeasureString (box.Text, box.Font);
1206 width = ((int) size.Width) + 7;
1208 if (width > box.Width - 16)
1209 width = box.Width - 16;
1211 y = box.Font.Height / 2;
1214 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
1217 if (box.Text.Length != 0) {
1218 Pen pen = ResPool.GetPen (box.BackColor);
1219 dc.DrawLine (pen, 9, y, 8 + width, y);
1220 dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1);
1223 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1225 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
1226 new RectangleF (10, 0, width, box.Font.Height), text_format);
1230 text_format.Dispose ();
1233 public override Size GroupBoxDefaultSize {
1235 return new Size (200,100);
1241 public override Size HScrollBarDefaultSize {
1243 return new Size (80, this.ScrollBarButtonSize);
1247 #endregion // HScrollBar
1250 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1252 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1254 if (label.Enabled) {
1255 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1257 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
1262 public override Size LabelDefaultSize {
1264 return new Size (100, 23);
1270 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1274 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1276 for (int i = 0; i < label.num_pieces; i++) {
1278 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1282 color = label.GetLinkColor (label.pieces[i], i);
1284 if (label.pieces[i].link == null)
1285 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.ForeColor),
1286 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1288 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
1289 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1291 if (label.pieces[i].focused) {
1292 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1297 #endregion // LinkLabel
1300 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1302 Color back_color, fore_color;
1304 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1305 back_color = ColorHighlight;
1306 fore_color = ColorHighlightText;
1308 back_color = e.BackColor;
1309 fore_color = e.ForeColor;
1312 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1314 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1315 ResPool.GetSolidBrush (fore_color),
1316 e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
1318 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
1319 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1326 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1328 bool details = control.View == View.Details;
1330 dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);
1331 int first = control.FirstVisibleIndex;
1333 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1334 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1335 DrawListViewItem (dc, control, control.Items [i]);
1338 // draw the gridlines
1339 if (details && control.GridLines) {
1340 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1341 2 : control.Font.Height + 2;
1343 // draw vertical gridlines
1344 foreach (ColumnHeader col in control.Columns)
1345 dc.DrawLine (SystemPens.Control,
1346 col.Rect.Right, top,
1347 col.Rect.Right, control.TotalHeight);
1348 // draw horizontal gridlines
1349 ListViewItem last_item = null;
1350 foreach (ListViewItem item in control.Items) {
1351 dc.DrawLine (SystemPens.Control,
1352 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1353 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1357 // draw a line after at the bottom of the last item
1358 if (last_item != null) {
1359 dc.DrawLine (SystemPens.Control,
1360 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1361 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1363 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1367 // Draw corner between the two scrollbars
1368 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1369 Rectangle rect = new Rectangle ();
1370 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1371 rect.Width = control.v_scroll.Width;
1372 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1373 rect.Height = control.h_scroll.Height;
1374 dc.FillRectangle (SystemBrushes.Control, rect);
1377 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
1378 if (!box_select_rect.Size.IsEmpty)
1379 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
1383 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1385 bool details = (control.View == View.Details);
1387 // border is drawn directly in the Paint method
1388 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1389 dc.FillRectangle (GetControlBackBrush (control.BackColor),
1390 0, 0, control.TotalWidth, control.Font.Height + 5);
1391 if (control.Columns.Count > 0) {
1392 foreach (ColumnHeader col in control.Columns) {
1393 Rectangle rect = col.Rect;
1394 rect.X -= control.h_marker;
1396 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1397 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1399 state = ButtonState.Flat;
1400 this.CPDrawButton (dc, rect, state);
1403 if (rect.Width <= 0)
1405 dc.DrawString (col.Text, DefaultFont,
1406 SystemBrushes.ControlText,
1409 int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
1410 if (right < control.Right) {
1411 Rectangle rect = control.Columns [0].Rect;
1413 rect.Width = control.Right - right;
1415 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1416 state = ButtonState.Normal;
1418 state = ButtonState.Flat;
1419 CPDrawButton (dc, rect, state);
1425 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
1427 Rectangle rect = col.Rect;
1428 rect.X -= view.h_marker;
1429 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
1430 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
1433 if (rect.Width <= 0)
1435 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
1436 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
1437 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
1440 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1443 if (control.View == View.Details && control.Columns.Count > 0)
1444 col_offset = control.Columns [0].Rect.X;
1448 Rectangle rect_checkrect = item.CheckRectReal;
1449 rect_checkrect.X += col_offset;
1450 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
1451 icon_rect.X += col_offset;
1452 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1453 full_rect.X += col_offset;
1454 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1455 text_rect.X += col_offset;
1457 if (control.CheckBoxes) {
1458 if (control.StateImageList == null) {
1459 // Make sure we've got at least a line width of 1
1460 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1461 int scale = Math.Max (1, rect_checkrect.Width / 12);
1463 // set the checkbox background
1464 dc.FillRectangle (SystemBrushes.Window,
1466 // define a rectangle inside the border area
1467 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1468 rect_checkrect.Y + 2,
1469 rect_checkrect.Width - 4,
1470 rect_checkrect.Height - 4);
1471 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
1472 dc.DrawRectangle (pen, rect);
1474 // Need to draw a check-mark
1476 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
1477 // adjustments to get the check-mark at the right place
1478 rect.X ++; rect.Y ++;
1479 // following logic is taken from DrawFrameControl method
1480 for (int i = 0; i < check_wd; i++) {
1481 dc.DrawLine (check_pen, rect.Left + check_wd / 2,
1482 rect.Top + check_wd + i,
1483 rect.Left + check_wd / 2 + 2 * scale,
1484 rect.Top + check_wd + 2 * scale + i);
1485 dc.DrawLine (check_pen,
1486 rect.Left + check_wd / 2 + 2 * scale,
1487 rect.Top + check_wd + 2 * scale + i,
1488 rect.Left + check_wd / 2 + 6 * scale,
1489 rect.Top + check_wd - 2 * scale + i);
1494 if (item.Checked && control.StateImageList.Images.Count > 1)
1495 control.StateImageList.Draw (dc,
1496 rect_checkrect.Location, 1);
1497 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1498 control.StateImageList.Draw (dc,
1499 rect_checkrect.Location, 0);
1503 if (control.View == View.LargeIcon) {
1504 if (control.LargeImageList == null) {
1505 dc.DrawLine (ResPool.GetSizedPen (this.ColorWindowText, 2), icon_rect.Left, icon_rect.Y, icon_rect.Left + 11, icon_rect.Y);
1506 } else if (item.ImageIndex > -1 && item.ImageIndex < control.LargeImageList.Images.Count)
1507 control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1509 if (item.ImageIndex > -1 && control.SmallImageList != null &&
1510 item.ImageIndex < control.SmallImageList.Images.Count)
1511 control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1514 // draw the item text
1515 // format for the item text
1516 StringFormat format = new StringFormat ();
1517 if (control.View == View.SmallIcon)
1518 format.LineAlignment = StringAlignment.Near;
1520 format.LineAlignment = StringAlignment.Center;
1521 if (control.View == View.LargeIcon)
1522 format.Alignment = StringAlignment.Center;
1524 format.Alignment = StringAlignment.Near;
1526 if (!control.LabelWrap)
1527 format.FormatFlags = StringFormatFlags.NoWrap;
1529 if (item.Selected && control.item_control.Focused) {
1530 if (control.View == View.Details) {
1531 if (control.FullRowSelect) {
1532 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1535 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1537 text_rect.Width = text_size.Width;
1538 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1542 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1544 Point loc = text_rect.Location;
1545 loc.X += (text_rect.Width - text_size.Width) / 2;
1546 text_rect.Width = text_size.Width;*/
1547 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1551 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1553 if (item.Text != null && item.Text.Length > 0) {
1554 if (item.Selected && control.item_control.Focused)
1555 dc.DrawString (item.Text, item.Font, SystemBrushes.HighlightText, text_rect, format);
1557 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1558 (item.ForeColor), text_rect, format);
1561 if (control.View == View.Details && control.Columns.Count > 0) {
1562 // draw subitems for details view
1563 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1564 int count = (control.Columns.Count < subItems.Count ?
1565 control.Columns.Count : subItems.Count);
1569 ListViewItem.ListViewSubItem subItem;
1570 Rectangle sub_item_rect = text_rect;
1572 // set the format for subitems
1573 format.FormatFlags = StringFormatFlags.NoWrap;
1575 // 0th subitem is the item already drawn
1576 for (int index = 1; index < count; index++) {
1577 subItem = subItems [index];
1578 col = control.Columns [index];
1579 format.Alignment = col.Format.Alignment;
1580 sub_item_rect.X = col.Rect.X - control.h_marker;
1581 sub_item_rect.Width = col.Wd;
1582 Rectangle sub_item_text_rect = sub_item_rect;
1583 sub_item_text_rect.X += 3;
1584 sub_item_text_rect.Width -= 6;
1586 SolidBrush sub_item_back_br = null;
1587 SolidBrush sub_item_fore_br = null;
1588 Font sub_item_font = null;
1590 if (item.UseItemStyleForSubItems) {
1591 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
1592 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
1593 sub_item_font = item.Font;
1595 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
1596 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
1597 sub_item_font = subItem.Font;
1600 if (item.Selected && control.FullRowSelect) {
1601 dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
1602 if (subItem.Text != null && subItem.Text.Length > 0)
1603 dc.DrawString (subItem.Text, sub_item_font,
1604 SystemBrushes.HighlightText,
1605 sub_item_text_rect, format);
1607 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1608 if (subItem.Text != null && subItem.Text.Length > 0)
1609 dc.DrawString (subItem.Text, sub_item_font,
1611 sub_item_text_rect, format);
1617 if (item.Focused && control.item_control.Focused) {
1618 Rectangle focus_rect = text_rect;
1619 if (control.FullRowSelect && control.View == View.Details) {
1621 foreach (ColumnHeader col in control.Columns)
1623 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
1626 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
1628 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
1635 public override Size ListViewCheckBoxSize {
1636 get { return new Size (16, 16); }
1639 public override int ListViewColumnHeaderHeight {
1643 public override int ListViewDefaultColumnWidth {
1647 public override int ListViewVerticalSpacing {
1651 public override int ListViewEmptyColumnWidth {
1655 public override int ListViewHorizontalSpacing {
1659 public override Size ListViewDefaultSize {
1660 get { return new Size (121, 97); }
1662 #endregion // ListView
1665 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1670 if (item.Visible == false) {
1676 if (item.Separator == true) {
1677 item.Height = SEPARATOR_HEIGHT / 2;
1682 if (item.MeasureEventDefined) {
1683 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1684 item.PerformMeasureItem (mi);
1685 item.Height = mi.ItemHeight;
1686 item.Width = mi.ItemWidth;
1690 size = dc.MeasureString (item.Text, MenuFont);
1691 item.Width = (int) size.Width;
1692 item.Height = (int) size.Height;
1695 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1696 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1697 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1698 item.Width += MENU_TAB_SPACE + (int) size.Width;
1701 item.Width += 4 + (MenuCheckSize.Width * 2);
1703 item.Width += MENU_BAR_ITEMS_SPACE;
1707 if (item.Height < MenuHeight)
1708 item.Height = MenuHeight;
1712 // Updates the menu rect and returns the height
1713 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1719 foreach (MenuItem item in menu.MenuItems) {
1721 CalcItemSize (dc, item, y, x, true);
1723 if (x + item.Width > width) {
1731 item.MenuBar = true;
1733 if (y + item.Height > menu.Height)
1734 menu.Height = item.Height + y;
1741 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1749 while (start < menu.MenuItems.Count) {
1752 for (i = start; i < menu.MenuItems.Count; i++) {
1753 MenuItem item = menu.MenuItems [i];
1755 if ((i != start) && (item.Break || item.BarBreak))
1758 CalcItemSize (dc, item, y, x, false);
1761 if (item.Width > max)
1765 // Replace the -1 by the menu width (separators)
1766 for (n = start; n < i; n++, start++)
1767 menu.MenuItems [n].Width = max;
1769 if (y > menu.Height)
1781 menu.Width += SM_CXBORDER;
1782 menu.Height += SM_CYBORDER;
1785 // Draws a menu bar in a window
1786 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1788 if (menu.Height == 0)
1789 CalcMenuBarSize (dc, menu, rect.Width);
1791 bool keynav = (menu as MainMenu).tracker.Navigating;
1792 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1793 string_format_menu_menubar_text.HotkeyPrefix = hp;
1794 string_format_menu_text.HotkeyPrefix = hp;
1796 rect.Height = menu.Height;
1797 dc.FillRectangle (SystemBrushes.Menu, rect);
1799 for (int i = 0; i < menu.MenuItems.Count; i++) {
1800 MenuItem item = menu.MenuItems [i];
1801 Rectangle item_rect = item.bounds;
1802 item_rect.X += rect.X;
1803 item_rect.Y += rect.Y;
1804 item.MenuHeight = menu.Height;
1805 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1809 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
1812 if (color.R == 0 && color.G == 0 && color.B == 0)
1813 bg_color = Color.White;
1815 bg_color = Color.Black;
1816 Bitmap bmp = new Bitmap (size.Width, size.Height);
1817 Graphics gr = Graphics.FromImage (bmp);
1818 Rectangle rect = new Rectangle (Point.Empty, size);
1819 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
1820 CPDrawMenuGlyph (gr, rect, glyph, color);
1821 bmp.MakeTransparent (bg_color);
1826 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1828 StringFormat string_format;
1829 Rectangle rect_text = e.Bounds;
1831 if (item.Visible == false)
1835 string_format = string_format_menu_menubar_text;
1837 string_format = string_format_menu_text;
1839 if (item.Separator == true) {
1840 e.Graphics.DrawLine (SystemPens.ControlDark,
1841 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1843 e.Graphics.DrawLine (SystemPens.ControlLight,
1844 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1850 rect_text.X += MenuCheckSize.Width;
1852 if (item.BarBreak) { /* Draw vertical break bar*/
1853 Rectangle rect = e.Bounds;
1856 rect.Height = item.MenuHeight - 6;
1858 e.Graphics.DrawLine (SystemPens.ControlDark,
1859 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1861 e.Graphics.DrawLine (SystemPens.ControlLight,
1862 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1867 Brush brush_text = null;
1868 Brush brush_back = null;
1870 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
1871 color_text = ColorHighlightText;
1872 color_back = ColorHighlight;
1873 brush_text = SystemBrushes.HighlightText;
1874 brush_back = SystemBrushes.Highlight;
1876 color_text = ColorMenuText;
1877 color_back = ColorMenu;
1878 brush_text = ResPool.GetSolidBrush (ColorMenuText);
1879 brush_back = SystemBrushes.Menu;
1882 /* Draw background */
1883 Rectangle rect_back = e.Bounds;
1885 rect_back.Width -=2;
1887 e.Graphics.FillRectangle (brush_back, rect_back);
1890 e.Graphics.DrawString (item.Text, e.Font,
1892 rect_text, string_format);
1894 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1895 string str = item.GetShortCutText ();
1896 Rectangle rect = rect_text;
1898 rect.Width -= item.XTab;
1900 e.Graphics.DrawString (str, e.Font, brush_text,
1901 rect, string_format_menu_shortcut);
1905 Border3DStyle border_style = Border3DStyle.Adjust;
1906 if ((item.Status & DrawItemState.HotLight) != 0)
1907 border_style = Border3DStyle.RaisedInner;
1908 else if ((item.Status & DrawItemState.Selected) != 0)
1909 border_style = Border3DStyle.SunkenOuter;
1911 if (border_style != Border3DStyle.Adjust)
1912 CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
1915 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
1916 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
1917 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
1921 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
1925 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
1927 int cx = MenuCheckSize.Width;
1928 int cy = MenuCheckSize.Height;
1929 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
1932 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1933 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1935 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1936 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1942 /* Draw checked or radio */
1943 if (item.MenuBar == false && item.Checked) {
1945 Rectangle area = e.Bounds;
1946 int cx = MenuCheckSize.Width;
1947 int cy = MenuCheckSize.Height;
1948 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
1950 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1956 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
1959 dc.FillRectangle (SystemBrushes.Menu, cliparea);
1961 Pen pen_cht = SystemPens.HighlightText;
1962 Pen pen_ccd = SystemPens.ControlDark;
1963 Pen pen_ccdd = SystemPens.ControlDarkDark;
1965 /* Draw menu borders */
1966 dc.DrawLine (pen_cht,
1967 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1969 dc.DrawLine (pen_cht,
1970 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1972 dc.DrawLine (pen_ccd,
1973 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1975 dc.DrawLine (pen_ccdd,
1976 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1978 dc.DrawLine (pen_ccd,
1979 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1981 dc.DrawLine (pen_ccdd,
1982 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1984 for (int i = 0; i < menu.MenuItems.Count; i++)
1985 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
1986 MenuItem item = menu.MenuItems [i];
1987 item.MenuHeight = menu.Height;
1988 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
1989 item.bounds, i, item.Status));
1995 #region MonthCalendar
1997 // draw the month calendar
1998 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2000 Rectangle client_rectangle = mc.ClientRectangle;
2001 Size month_size = mc.SingleMonthSize;
2002 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2003 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2004 Size date_cell_size = (Size)((object)mc.date_cell_size);
2006 // draw the singlecalendars
2009 // adjust for the position of the specific month
2010 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2014 y_offset += month_size.Height + calendar_spacing.Height;
2016 // now adjust for x position
2017 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2021 x_offset += month_size.Width + calendar_spacing.Width;
2028 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2029 if (month_rect.IntersectsWith (clip_rectangle)) {
2041 Rectangle bottom_rect = new Rectangle (
2043 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2044 client_rectangle.Width,
2045 date_cell_size.Height + 2);
2046 // draw the today date if it's set
2047 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2049 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
2051 int today_offset = 5;
2052 if (mc.ShowTodayCircle)
2054 Rectangle today_circle_rect = new Rectangle (
2055 client_rectangle.X + 5,
2056 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2057 date_cell_size.Width,
2058 date_cell_size.Height);
2059 DrawTodayCircle (dc, today_circle_rect);
2060 today_offset += date_cell_size.Width + 5;
2062 // draw today's date
2063 StringFormat text_format = new StringFormat();
2064 text_format.LineAlignment = StringAlignment.Center;
2065 text_format.Alignment = StringAlignment.Near;
2066 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2067 Rectangle today_rect = new Rectangle (
2068 today_offset + client_rectangle.X,
2069 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2070 Math.Max(client_rectangle.Width - today_offset, 0),
2071 date_cell_size.Height);
2072 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
2073 text_format.Dispose ();
2074 bold_font.Dispose ();
2078 // finally paint the borders of the calendars as required
2079 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2080 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2081 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
2082 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2083 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
2085 Rectangle rect = new Rectangle (
2086 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2088 calendar_spacing.Width,
2089 client_rectangle.Height);
2090 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2091 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2095 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2096 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2097 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
2098 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2099 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
2101 Rectangle rect = new Rectangle (
2103 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2104 client_rectangle.Width,
2105 calendar_spacing.Height);
2106 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2107 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2112 // draw the drop down border if need
2113 if (mc.owner != null) {
2114 Rectangle bounds = mc.ClientRectangle;
2115 if (clip_rectangle.Contains (mc.Location)) {
2116 // find out if top or left line to draw
2117 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2119 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2121 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2122 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2125 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2126 // find out if bottom or right line to draw
2127 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2128 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2130 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2131 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2137 // darws a single part of the month calendar (with one month)
2138 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2140 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2141 Size title_size = (Size)((object)mc.title_size);
2142 Size date_cell_size = (Size)((object)mc.date_cell_size);
2143 DateTime current_month = (DateTime)((object)mc.current_month);
2145 // set up some standard string formating variables
2146 StringFormat text_format = new StringFormat();
2147 text_format.LineAlignment = StringAlignment.Center;
2148 text_format.Alignment = StringAlignment.Center;
2151 // draw the title back ground
2152 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2153 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2154 if (title_rect.IntersectsWith (clip_rectangle)) {
2155 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2157 string title_text = this_month.ToString ("MMMM yyyy");
2158 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2160 // draw previous and next buttons if it's time
2161 if (row == 0 && col == 0)
2163 // draw previous button
2164 DrawMonthCalendarButton (
2170 (System.Drawing.Size)((object)mc.button_size),
2173 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2176 DrawMonthCalendarButton (
2182 (System.Drawing.Size)((object)mc.button_size),
2187 // set the week offset and draw week nums if needed
2188 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2189 Rectangle day_name_rect = new Rectangle(
2191 rectangle.Y + title_size.Height,
2192 (7 + col_offset) * date_cell_size.Width,
2193 date_cell_size.Height);
2194 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2195 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
2196 // draw the day names
2197 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2198 for (int i=0; i < 7; i++)
2200 int position = i - (int) first_day_of_week;
2203 position = 7 + position;
2206 Rectangle day_rect = new Rectangle(
2207 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2209 date_cell_size.Width,
2210 date_cell_size.Height);
2211 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2214 // draw the vertical divider
2215 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2217 ResPool.GetPen (mc.ForeColor),
2218 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2219 rectangle.Y + vert_divider_y,
2220 rectangle.Right - mc.divider_line_offset,
2221 rectangle.Y + vert_divider_y);
2225 // draw the actual date items in the grid (including the week numbers)
2226 Rectangle date_rect = new Rectangle (
2228 rectangle.Y + title_size.Height + date_cell_size.Height,
2229 date_cell_size.Width,
2230 date_cell_size.Height);
2231 int month_row_count = 0;
2232 bool draw_week_num_divider = false;
2233 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2234 for (int i=0; i < 6; i++)
2236 // establish if this row is in our clip_area
2237 Rectangle row_rect = new Rectangle (
2239 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2240 date_cell_size.Width * 7,
2241 date_cell_size.Height);
2242 if (mc.ShowWeekNumbers) {
2243 row_rect.Width += date_cell_size.Width;
2246 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2248 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
2250 // establish if this is a valid week to draw
2251 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2252 month_row_count = i;
2255 // draw the week number if required
2256 if (mc.ShowWeekNumbers && month_row_count == i) {
2257 if (!draw_week_num_divider) {
2258 draw_week_num_divider = draw_row;
2260 // get the week for this row
2261 int week = mc.GetWeekOfYear (current_date);
2267 ResPool.GetSolidBrush (mc.TitleBackColor),
2271 date_rect.Offset(date_cell_size.Width, 0);
2274 // only draw the days if we have to
2275 if(month_row_count == i) {
2276 for (int j=0; j < 7; j++)
2279 DrawMonthCalendarDate (
2290 current_date = current_date.AddDays(1);
2291 date_rect.Offset(date_cell_size.Width, 0);
2294 // shift the rectangle down one row
2295 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2296 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2300 // month_row_count is zero based, so add one
2303 // draw week numbers if required
2304 if (draw_week_num_divider) {
2307 ResPool.GetPen (mc.ForeColor),
2308 rectangle.X + date_cell_size.Width - 1,
2309 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2310 rectangle.X + date_cell_size.Width - 1,
2311 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2313 text_format.Dispose ();
2316 // draws the pervious or next button
2317 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2319 bool is_clicked = false;
2320 Rectangle button_rect;
2321 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2322 Point[] arrow_path = new Point[3];
2323 // prepare the button
2326 is_clicked = mc.is_previous_clicked;
2327 button_rect = new Rectangle (
2328 rectangle.X + 1 + x_offset,
2329 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2330 Math.Max(button_size.Width - 1, 0),
2331 Math.Max(button_size.Height - 1, 0));
2332 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2333 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2335 arrow_rect.Offset(1,1);
2337 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2338 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2339 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2343 is_clicked = mc.is_next_clicked;
2344 button_rect = new Rectangle (
2345 rectangle.Right - 1 - x_offset - button_size.Width,
2346 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2347 Math.Max(button_size.Width - 1, 0),
2348 Math.Max(button_size.Height - 1, 0));
2349 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2350 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2352 arrow_rect.Offset(1,1);
2354 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2355 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2356 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2359 // fill the background
2360 dc.FillRectangle (SystemBrushes.Control, button_rect);
2363 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2366 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
2369 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2373 // draws one day in the calendar grid
2374 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2375 Color date_color = mc.ForeColor;
2376 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2378 // find out if we are the lead of the first calendar or the trail of the last calendar
2379 if (date.Year != month.Year || date.Month != month.Month) {
2380 DateTime check_date = month.AddMonths (-1);
2381 // check if it's the month before
2382 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2383 date_color = mc.TrailingForeColor;
2385 // check if it's the month after
2386 check_date = month.AddMonths (1);
2387 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2388 date_color = mc.TrailingForeColor;
2394 date_color = mc.ForeColor;
2398 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2399 // see if the date is in the start of selection
2400 date_color = mc.BackColor;
2401 // draw the left hand of the back ground
2402 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2403 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2404 } else if (date == mc.SelectionStart) {
2405 // see if the date is in the start of selection
2406 date_color = mc.BackColor;
2407 // draw the left hand of the back ground
2408 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2409 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2410 // fill the other side as a straight rect
2411 if (date < mc.SelectionEnd)
2413 // use rectangle instead of rectangle to go all the way to edge of rect
2414 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2415 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2416 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2418 } else if (date == mc.SelectionEnd) {
2419 // see if it is the end of selection
2420 date_color = mc.BackColor;
2421 // draw the left hand of the back ground
2422 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2423 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2424 // fill the other side as a straight rect
2425 if (date > mc.SelectionStart) {
2426 selection_rect.X = rectangle.X;
2427 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2428 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2430 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2431 // now see if it's in the middle
2432 date_color = mc.BackColor;
2433 // draw the left hand of the back ground
2434 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2435 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2438 // set up some standard string formating variables
2439 StringFormat text_format = new StringFormat();
2440 text_format.LineAlignment = StringAlignment.Center;
2441 text_format.Alignment = StringAlignment.Center;
2444 // establish if it's a bolded font
2446 if (mc.IsBoldedDate (date)) {
2447 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2452 // just draw the date now
2453 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2455 // today circle if needed
2456 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2457 DrawTodayCircle (dc, interior);
2460 // draw the selection grid
2461 if (mc.is_date_clicked && mc.clicked_date == date) {
2462 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
2463 dc.DrawRectangle (pen, interior);
2465 text_format.Dispose ();
2468 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2469 Color circle_color = Color.FromArgb (248, 0, 0);
2470 // draw the left hand of the circle
2471 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2472 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2473 Point [] curve_points = new Point [3];
2474 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2475 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2476 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2478 Pen pen = ResPool.GetSizedPen(circle_color, 2);
2479 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2480 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2481 dc.DrawCurve (pen, curve_points);
2482 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2485 #endregion // MonthCalendar
2488 public override Size PanelDefaultSize {
2490 return new Size (200, 100);
2496 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2497 Rectangle client = pb.ClientRectangle;
2499 // FIXME - instead of drawing the whole picturebox every time
2500 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2501 // Also, we only need a background fill where no image goes
2502 if (pb.Image != null) {
2503 switch (pb.SizeMode) {
2504 case PictureBoxSizeMode.StretchImage:
2505 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2508 case PictureBoxSizeMode.CenterImage:
2509 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2510 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2513 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2515 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2522 // We only get here if no image is set. At least paint the background
2523 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2526 public override Size PictureBoxDefaultSize {
2528 return new Size (100, 50);
2531 #endregion // PictureBox
2534 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2536 Rectangle block_rect;
2537 Rectangle client_area = ctrl.client_area;
2538 int space_betweenblocks = 2;
2543 block_width = (client_area.Height * 2 ) / 3;
2544 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2545 increment = block_width + space_betweenblocks;
2548 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
2551 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2552 while ((block_rect.X - client_area.X) < barpos_pixels) {
2554 if (clip_rect.IntersectsWith (block_rect) == true) {
2555 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2558 block_rect.X += increment;
2562 public override Size ProgressBarDefaultSize {
2564 return new Size (100, 23);
2568 #endregion // ProgressBar
2571 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2572 StringFormat text_format;
2573 Rectangle client_rectangle;
2574 Rectangle text_rectangle;
2575 Rectangle radiobutton_rectangle;
2576 int radiobutton_size = 13;
2577 int radiobutton_space = 4;
2579 client_rectangle = radio_button.ClientRectangle;
2580 text_rectangle = client_rectangle;
2581 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2583 text_format = new StringFormat();
2584 text_format.Alignment = StringAlignment.Near;
2585 text_format.LineAlignment = StringAlignment.Center;
2586 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2588 /* Calculate the position of text and checkbox rectangle */
2589 if (radio_button.appearance!=Appearance.Button) {
2590 switch(radio_button.radiobutton_alignment) {
2591 case ContentAlignment.BottomCenter: {
2592 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2593 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2594 text_rectangle.X=client_rectangle.X;
2595 text_rectangle.Width=client_rectangle.Width;
2596 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2600 case ContentAlignment.BottomLeft: {
2601 radiobutton_rectangle.X=client_rectangle.Left;
2602 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2603 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2604 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2608 case ContentAlignment.BottomRight: {
2609 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2610 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2611 text_rectangle.X=client_rectangle.X;
2612 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2616 case ContentAlignment.MiddleCenter: {
2617 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2618 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2619 text_rectangle.X=client_rectangle.X;
2620 text_rectangle.Width=client_rectangle.Width;
2625 case ContentAlignment.MiddleLeft: {
2626 radiobutton_rectangle.X=client_rectangle.Left;
2627 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2628 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2629 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2633 case ContentAlignment.MiddleRight: {
2634 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2635 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2636 text_rectangle.X=client_rectangle.X;
2637 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2641 case ContentAlignment.TopCenter: {
2642 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2643 radiobutton_rectangle.Y=client_rectangle.Top;
2644 text_rectangle.X=client_rectangle.X;
2645 text_rectangle.Y=radiobutton_size+radiobutton_space;
2646 text_rectangle.Width=client_rectangle.Width;
2647 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2651 case ContentAlignment.TopLeft: {
2652 radiobutton_rectangle.X=client_rectangle.Left;
2653 radiobutton_rectangle.Y=client_rectangle.Top;
2654 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2655 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2659 case ContentAlignment.TopRight: {
2660 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2661 radiobutton_rectangle.Y=client_rectangle.Top;
2662 text_rectangle.X=client_rectangle.X;
2663 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2668 text_rectangle.X=client_rectangle.X;
2669 text_rectangle.Width=client_rectangle.Width;
2672 /* Set the horizontal alignment of our text */
2673 switch(radio_button.text_alignment) {
2674 case ContentAlignment.BottomLeft:
2675 case ContentAlignment.MiddleLeft:
2676 case ContentAlignment.TopLeft: {
2677 text_format.Alignment=StringAlignment.Near;
2681 case ContentAlignment.BottomCenter:
2682 case ContentAlignment.MiddleCenter:
2683 case ContentAlignment.TopCenter: {
2684 text_format.Alignment=StringAlignment.Center;
2688 case ContentAlignment.BottomRight:
2689 case ContentAlignment.MiddleRight:
2690 case ContentAlignment.TopRight: {
2691 text_format.Alignment=StringAlignment.Far;
2696 /* Set the vertical alignment of our text */
2697 switch(radio_button.text_alignment) {
2698 case ContentAlignment.TopLeft:
2699 case ContentAlignment.TopCenter:
2700 case ContentAlignment.TopRight: {
2701 text_format.LineAlignment=StringAlignment.Near;
2705 case ContentAlignment.BottomLeft:
2706 case ContentAlignment.BottomCenter:
2707 case ContentAlignment.BottomRight: {
2708 text_format.LineAlignment=StringAlignment.Far;
2712 case ContentAlignment.MiddleLeft:
2713 case ContentAlignment.MiddleCenter:
2714 case ContentAlignment.MiddleRight: {
2715 text_format.LineAlignment=StringAlignment.Center;
2720 ButtonState state = ButtonState.Normal;
2721 if (radio_button.FlatStyle == FlatStyle.Flat) {
2722 state |= ButtonState.Flat;
2725 if (radio_button.Checked) {
2726 state |= ButtonState.Checked;
2729 if (!radio_button.Enabled) {
2730 state |= ButtonState.Inactive;
2734 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2736 if ((radio_button.image != null) || (radio_button.image_list != null))
2737 ButtonBase_DrawImage(radio_button, dc);
2739 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2741 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2743 text_format.Dispose ();
2746 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2748 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
2750 if (radio_button.appearance==Appearance.Button) {
2751 ButtonBase_DrawButton (radio_button, dc);
2753 // establish if we are rendering a flat style of some sort
2754 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2755 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2757 CPDrawRadioButton(dc, radiobutton_rectangle, state);
2762 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2764 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
2765 text_format, radio_button.Appearance, radio_button.Checked);
2768 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2770 // do nothing here. maybe an other theme needs it
2773 // renders a radio button with the Flat and Popup FlatStyle
2774 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2778 if (radio_button.Enabled) {
2780 // draw the outer flatstyle arcs
2781 if (radio_button.FlatStyle == FlatStyle.Flat) {
2782 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
2784 // fill in the area depending on whether or not the mouse is hovering
2785 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
2786 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2788 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2791 // must be a popup radio button
2793 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
2795 if (radio_button.is_entered || radio_button.Capture) {
2796 // draw the popup 3d button knob
2797 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2799 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
2800 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
2803 // just draw lighter flatstyle outer circle
2804 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2809 // fill control background color regardless of actual backcolor
2810 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2811 // draw the ark as control dark
2812 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2816 if (radio_button.Checked) {
2817 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2819 Pen dot_pen = SystemPens.ControlDarkDark;
2820 Brush dot_brush = SystemBrushes.ControlDarkDark;
2822 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
2823 dot_pen = SystemPens.ControlDark;
2824 dot_brush = SystemBrushes.ControlDark;
2827 if (rectangle.Height > 13) {
2828 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
2830 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
2831 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
2833 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
2834 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
2836 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
2837 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
2842 public override Size RadioButtonDefaultSize {
2844 return new Size (104,24);
2847 #endregion // RadioButton
2850 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2852 int scrollbutton_width = bar.scrollbutton_width;
2853 int scrollbutton_height = bar.scrollbutton_height;
2854 Rectangle first_arrow_area;
2855 Rectangle second_arrow_area;
2856 Rectangle thumb_pos;
2858 thumb_pos = bar.ThumbPos;
2861 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2862 bar.FirstArrowArea = first_arrow_area;
2864 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2865 bar.SecondArrowArea = second_arrow_area;
2867 thumb_pos.Width = bar.Width;
2868 bar.ThumbPos = thumb_pos;
2871 if (clip.IntersectsWith (first_arrow_area))
2872 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2873 if (clip.IntersectsWith (second_arrow_area))
2874 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2877 switch (bar.thumb_moving) {
2878 case ScrollBar.ThumbMoving.None: {
2879 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
2882 case ScrollBar.ThumbMoving.Forward: {
2883 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
2887 case ScrollBar.ThumbMoving.Backwards: {
2888 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
2896 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2897 bar.FirstArrowArea = first_arrow_area;
2899 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2900 bar.SecondArrowArea = second_arrow_area;
2902 thumb_pos.Height = bar.Height;
2903 bar.ThumbPos = thumb_pos;
2906 if (clip.IntersectsWith (first_arrow_area))
2907 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2908 if (clip.IntersectsWith (second_arrow_area))
2909 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2912 switch (bar.thumb_moving) {
2913 case ScrollBar.ThumbMoving.None: {
2914 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
2918 case ScrollBar.ThumbMoving.Forward: {
2919 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
2923 case ScrollBar.ThumbMoving.Backwards: {
2924 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
2931 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
2934 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
2936 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
2937 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
2940 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
2942 Rectangle r = new Rectangle( 0,
2943 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
2944 Rectangle intersect = Rectangle.Intersect( clip, r );
2946 if ( intersect != Rectangle.Empty )
2948 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
2949 dc.FillRectangle( h, intersect );
2953 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2955 Rectangle r = new Rectangle( 0, scrollbutton_height,
2956 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2957 Rectangle intersect = Rectangle.Intersect( clip, r );
2959 if ( intersect != Rectangle.Empty )
2960 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
2963 r.Y = thumb_pos.Y + thumb_pos.Height;
2964 r.Width = bar.ClientRectangle.Width;
2965 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2967 intersect = Rectangle.Intersect( clip, r );
2968 if ( intersect != Rectangle.Empty )
2969 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2972 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2974 Rectangle r = new Rectangle( 0, scrollbutton_height,
2975 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2976 Rectangle intersect = Rectangle.Intersect( clip, r );
2978 if ( intersect != Rectangle.Empty )
2979 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2982 r.Y = thumb_pos.Y + thumb_pos.Height;
2983 r.Width = bar.ClientRectangle.Width;
2984 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2986 intersect = Rectangle.Intersect( clip, r );
2987 if ( intersect != Rectangle.Empty )
2988 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
2991 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
2993 Rectangle r = new Rectangle( scrollbutton_width,
2994 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
2995 Rectangle intersect = Rectangle.Intersect( clip, r );
2997 if ( intersect != Rectangle.Empty )
2998 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3001 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3003 Rectangle r = new Rectangle( scrollbutton_width, 0,
3004 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3005 Rectangle intersect = Rectangle.Intersect( clip, r );
3007 if ( intersect != Rectangle.Empty )
3008 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3010 r.X = thumb_pos.X + thumb_pos.Width;
3012 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3013 r.Height = bar.ClientRectangle.Height;
3015 intersect = Rectangle.Intersect( clip, r );
3016 if ( intersect != Rectangle.Empty )
3017 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3020 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3022 Rectangle r = new Rectangle( scrollbutton_width, 0,
3023 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3024 Rectangle intersect = Rectangle.Intersect( clip, r );
3026 if ( intersect != Rectangle.Empty )
3027 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3029 r.X = thumb_pos.X + thumb_pos.Width;
3031 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3032 r.Height = bar.ClientRectangle.Height;
3034 intersect = Rectangle.Intersect( clip, r );
3035 if ( intersect != Rectangle.Empty )
3036 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3039 public override int ScrollBarButtonSize {
3042 #endregion // ScrollBar
3045 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3046 Rectangle area = sb.ClientRectangle;
3047 int horz_border = 2;
3048 int vert_border = 2;
3050 bool is_color_control = sb.BackColor == ColorControl;
3052 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
3053 dc.FillRectangle (brush, clip);
3055 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3056 string text = sb.Text;
3057 StringFormat string_format = new StringFormat ();
3058 string_format.Trimming = StringTrimming.Character;
3059 string_format.FormatFlags = StringFormatFlags.NoWrap;
3061 if (text [0] == '\t') {
3062 string_format.Alignment = StringAlignment.Center;
3063 text = text.Substring (1);
3064 if (text [0] == '\t') {
3065 string_format.Alignment = StringAlignment.Far;
3066 text = text.Substring (1);
3070 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3071 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3072 string_format.Dispose ();
3073 } else if (sb.ShowPanels) {
3074 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
3075 int prev_x = area.X + horz_border;
3076 int y = area.Y + vert_border;
3077 for (int i = 0; i < sb.Panels.Count; i++) {
3078 Rectangle pr = new Rectangle (prev_x, y,
3079 sb.Panels [i].Width, area.Height);
3080 prev_x += pr.Width + StatusBarHorzGapWidth;
3081 if (pr.IntersectsWith (clip))
3082 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3086 if (sb.SizingGrip) {
3087 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
3088 CPDrawSizeGrip (dc, ColorControl, area);
3094 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3095 Brush br_forecolor, StatusBarPanel panel) {
3096 int border_size = 3; // this is actually const, even if the border style is none
3097 int icon_width = 16;
3099 area.Height -= border_size;
3101 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3102 Border3DStyle border_style = Border3DStyle.SunkenOuter;
3103 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3104 border_style = Border3DStyle.RaisedInner;
3106 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
3109 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3110 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3111 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3112 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3113 panel.Parent.OnDrawItemInternal (e);
3117 if (panel.Text == String.Empty)
3120 string text = panel.Text;
3121 StringFormat string_format = new StringFormat ();
3122 string_format.Trimming = StringTrimming.Character;
3123 string_format.FormatFlags = StringFormatFlags.NoWrap;
3126 if (text [0] == '\t') {
3127 string_format.Alignment = StringAlignment.Center;
3128 text = text.Substring (1);
3129 if (text [0] == '\t') {
3130 string_format.Alignment = StringAlignment.Far;
3131 text = text.Substring (1);
3135 Rectangle string_rect = Rectangle.Empty;
3139 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
3141 switch (panel.Alignment) {
3142 case HorizontalAlignment.Right:
3143 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3144 x = area.Right - len - 4;
3145 string_rect = new Rectangle (x, y,
3146 area.Right - x - border_size,
3147 area.Bottom - y - border_size);
3148 if (panel.Icon != null) {
3149 icon_x = x - icon_width - 2;
3152 case HorizontalAlignment.Center:
3153 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3154 x = (panel.Width / 2) + (len / 2);
3155 string_rect = new Rectangle (x, y,
3156 area.Right - x - border_size,
3157 area.Bottom - y - border_size);
3159 if (panel.Icon != null) {
3160 icon_x = x - icon_width - 2;
3166 int left = area.Left + border_size;;
3167 if (panel.Icon != null) {
3168 icon_x = area.Left + 2;
3169 left = icon_x + icon_width + 2;
3173 string_rect = new Rectangle (x, y,
3174 area.Right - x - border_size,
3175 area.Bottom - y - border_size);
3179 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
3181 if (panel.Icon != null) {
3182 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
3186 public override int StatusBarSizeGripWidth {
3190 public override int StatusBarHorzGapWidth {
3194 public override Size StatusBarDefaultSize {
3196 return new Size (100, 22);
3199 #endregion // StatusBar
3201 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3203 // Do we need to fill the back color? It can't be changed...
3204 Brush brush = tab.BackColor == DefaultControlBackColor ? SystemBrushes.Control : ResPool.GetSolidBrush (tab.BackColor);
3205 dc.FillRectangle (brush, area);
3206 Rectangle panel_rect = GetTabPanelRectExt (tab);
3208 if (tab.Appearance == TabAppearance.Normal) {
3209 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3210 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3213 if (tab.Alignment == TabAlignment.Top) {
3214 for (int r = tab.TabPages.Count; r > 0; r--) {
3215 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3216 if (i == tab.SelectedIndex)
3218 if (r != tab.TabPages [i].Row)
3220 Rectangle rect = tab.GetTabRect (i);
3221 if (!rect.IntersectsWith (area))
3223 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3227 for (int r = 0; r < tab.TabPages.Count; r++) {
3228 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3229 if (i == tab.SelectedIndex)
3231 if (r != tab.TabPages [i].Row)
3233 Rectangle rect = tab.GetTabRect (i);
3234 if (!rect.IntersectsWith (area))
3236 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3241 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3242 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3243 if (rect.IntersectsWith (area))
3244 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3247 if (tab.ShowSlider) {
3248 Rectangle right = GetTabControlRightScrollRect (tab);
3249 Rectangle left = GetTabControlLeftScrollRect (tab);
3250 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3251 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3255 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3257 switch (tab.Alignment) {
3258 case TabAlignment.Top:
3259 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3261 Rectangle panel_rect = GetTabPanelRectExt (tab);
3262 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3266 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3268 switch (tab.Alignment) {
3269 case TabAlignment.Top:
3270 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3272 Rectangle panel_rect = GetTabPanelRectExt (tab);
3273 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3277 public override Size TabControlDefaultItemSize {
3278 get { return new Size (42, 21); }
3281 public override Point TabControlDefaultPadding {
3282 get { return new Point (6, 3); }
3285 public override int TabControlMinimumTabWidth {
3289 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3291 Rectangle ext = GetTabPanelRectExt (tab);
3292 // Account for border size
3293 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3296 public override Size TabControlGetSpacing (TabControl tab) {
3297 switch (tab.Appearance) {
3298 case TabAppearance.Normal:
3299 return new Size (1, -2);
3300 case TabAppearance.Buttons:
3301 return new Size (3, 3);
3302 case TabAppearance.FlatButtons:
3303 return new Size (9, 3);
3305 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3309 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3311 // Offset the tab from the top corner
3312 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3313 tab.ClientRectangle.Y,
3314 tab.ClientRectangle.Width - 2,
3315 tab.ClientRectangle.Height - 1);
3317 if (tab.TabCount == 0)
3320 int spacing = TabControlGetSpacing (tab).Height;
3321 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3323 switch (tab.Alignment) {
3324 case TabAlignment.Left:
3326 res.Width -= offset;
3328 case TabAlignment.Right:
3329 res.Width -= offset;
3331 case TabAlignment.Top:
3333 res.Height -= offset;
3335 case TabAlignment.Bottom:
3336 res.Height -= offset;
3343 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3345 int FlatButtonSpacing = 8;
3347 int res = bounds.Width;
3351 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3353 StringFormat string_format = new StringFormat ();
3354 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3355 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3358 if (tab.Appearance == TabAppearance.FlatButtons) {
3359 int width = bounds.Width;
3360 bounds.Width += (FlatButtonSpacing - 2);
3362 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3363 bounds.Width = width;
3367 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3368 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3369 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3372 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3375 string_format.Alignment = StringAlignment.Center;
3376 string_format.LineAlignment = StringAlignment.Center;
3377 string_format.FormatFlags = StringFormatFlags.NoWrap;
3379 CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
3381 Pen light = ResPool.GetPen (cpcolor.LightLight);
3383 switch (tab.Alignment) {
3385 case TabAlignment.Top:
3387 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3389 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3390 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3391 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3393 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3394 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3395 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3397 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3399 string_format.Alignment = StringAlignment.Center;
3400 string_format.LineAlignment = StringAlignment.Center;
3401 string_format.FormatFlags = StringFormatFlags.NoWrap;
3405 case TabAlignment.Bottom:
3407 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3409 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3410 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3412 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3413 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3415 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3416 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3417 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3419 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3421 string_format.Alignment = StringAlignment.Center;
3422 string_format.LineAlignment = StringAlignment.Center;
3423 string_format.FormatFlags = StringFormatFlags.NoWrap;
3427 case TabAlignment.Left:
3429 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3431 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3432 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3433 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3435 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3437 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3438 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3440 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3442 string_format.Alignment = StringAlignment.Center;
3443 string_format.LineAlignment = StringAlignment.Center;
3444 string_format.FormatFlags = StringFormatFlags.NoWrap;
3445 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3450 // TabAlignment.Right
3452 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3454 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3455 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3457 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3458 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3460 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3461 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3463 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3465 string_format.Alignment = StringAlignment.Center;
3466 string_format.LineAlignment = StringAlignment.Center;
3467 string_format.FormatFlags = StringFormatFlags.NoWrap;
3468 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3474 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3475 if (tab.Alignment == TabAlignment.Left) {
3476 int wo = interior.Width / 2;
3477 int ho = interior.Height / 2;
3478 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3479 dc.RotateTransform (180);
3480 dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
3481 dc.ResetTransform ();
3483 dc.DrawString (page.Text, page.Font,
3484 SystemBrushes.ControlText,
3485 interior, string_format);
3487 } else if (page.Text != null) {
3488 DrawItemState state = DrawItemState.None;
3489 if (page == tab.SelectedTab)
3490 state |= DrawItemState.Selected;
3491 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3492 tab.Font, bounds, tab.IndexForTabPage (page),
3493 state, page.ForeColor, page.BackColor);
3494 tab.OnDrawItemInternal (e);
3498 if (page.parent.Focused && is_selected) {
3499 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3506 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
3508 StringFormat format = new StringFormat ();
3509 format.Trimming = StringTrimming.EllipsisWord;
3510 format.LineAlignment = StringAlignment.Center;
3511 if (control.TextAlign == ToolBarTextAlign.Underneath)
3512 format.Alignment = StringAlignment.Center;
3514 format.Alignment = StringAlignment.Near;
3516 if (control is PropertyGrid.PropertyToolBar) {
3517 dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
3519 if (clip_rectangle.X == 0) {
3520 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
3523 if (clip_rectangle.Y < 2) {
3524 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3527 if (clip_rectangle.Bottom == control.Bottom) {
3528 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
3531 if (clip_rectangle.Right == control.Right) {
3532 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
3534 } else if (control.Divider) {
3536 if (control.Appearance == ToolBarAppearance.Flat &&
3537 control.Parent != null && control.Parent.BackgroundImage != null) {
3538 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3539 dc.FillRectangle (b, clip_rectangle);
3542 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
3545 if (clip_rectangle.Y < 2) {
3546 if (clip_rectangle.Y < 1) {
3547 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
3549 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3552 if (control.Appearance == ToolBarAppearance.Flat &&
3553 control.Parent != null && control.Parent.BackgroundImage != null) {
3554 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3555 dc.FillRectangle (b, clip_rectangle);
3560 foreach (ToolBarButton button in control.Buttons)
3561 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
3562 DrawToolBarButton (dc, control, button, format);
3567 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3569 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
3571 DrawToolBarButtonBorder (dc, button, is_flat);
3573 switch (button.Style) {
3574 case ToolBarButtonStyle.DropDownButton:
3575 if (control.DropDownArrows)
3576 DrawToolBarDropDownArrow (dc, button, is_flat);
3577 DrawToolBarButtonContents (dc, control, button, format);
3580 case ToolBarButtonStyle.Separator:
3582 DrawToolBarSeparator (dc, button);
3585 case ToolBarButtonStyle.ToggleButton:
3586 DrawToolBarToggleButtonBackground (dc, button);
3587 DrawToolBarButtonContents (dc, control, button, format);
3591 DrawToolBarButtonContents (dc, control, button, format);
3596 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
3598 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
3600 if (button.Style == ToolBarButtonStyle.Separator)
3603 Border3DStyle style;
3606 if (button.Pushed || button.Pressed)
3607 style = Border3DStyle.SunkenOuter;
3608 else if (button.Hilight)
3609 style = Border3DStyle.RaisedInner;
3614 if (button.Pushed || button.Pressed)
3615 style = Border3DStyle.Sunken;
3617 style = Border3DStyle.Raised;
3620 CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
3623 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
3625 Rectangle area = button.Rectangle;
3626 int offset = (int) SystemPens.Control.Width + 1;
3627 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
3628 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
3631 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
3633 Rectangle area = button.Rectangle;
3634 area.X += ToolBarImageGripWidth;
3635 area.Y += ToolBarImageGripWidth;
3636 area.Width -= 2 * ToolBarImageGripWidth;
3637 area.Height -= 2 * ToolBarImageGripWidth;
3640 dc.FillRectangle (SystemBrushes.ControlLightLight, area);
3641 else if (button.PartialPush)
3642 dc.FillRectangle (SystemBrushes.ControlLight, area);
3644 dc.FillRectangle (SystemBrushes.Control, area);
3647 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
3649 Rectangle rect = button.Rectangle;
3650 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
3651 rect.Width = ToolBarDropDownWidth;
3653 if (button.dd_pressed) {
3654 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
3655 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
3656 } else if (button.Pushed || button.Pressed)
3657 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
3660 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
3662 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3664 PointF [] vertices = new PointF [3];
3665 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
3666 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3667 vertices [0].Y = ddCenter.Y;
3668 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3669 vertices [1].Y = ddCenter.Y;
3670 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3671 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
3672 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3675 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3677 if (button.Image != null) {
3678 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
3679 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
3681 dc.DrawImage (button.Image, x, y);
3683 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
3687 dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, button.TextRectangle, format);
3689 CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, button.TextRectangle, format);
3692 // Grip width for the ToolBar
3693 public override int ToolBarGripWidth {
3697 // Grip width for the Image on the ToolBarButton
3698 public override int ToolBarImageGripWidth {
3702 // width of the separator
3703 public override int ToolBarSeparatorWidth {
3707 // width of the dropdown arrow rect
3708 public override int ToolBarDropDownWidth {
3712 // width for the dropdown arrow on the ToolBarButton
3713 public override int ToolBarDropDownArrowWidth {
3717 // height for the dropdown arrow on the ToolBarButton
3718 public override int ToolBarDropDownArrowHeight {
3722 public override Size ToolBarDefaultSize {
3724 return new Size (100, 42);
3727 #endregion // ToolBar
3730 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3731 dc.FillRectangle(SystemBrushes.Info, control.client_rect);
3732 dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
3733 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3736 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3739 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3740 return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
3742 #endregion // ToolTip
3745 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3746 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3747 float ticks, int value_pos, bool mouse_value) {
3749 Point toptick_startpoint = new Point ();
3750 Point bottomtick_startpoint = new Point ();
3751 Point channel_startpoint = new Point ();
3753 float pixels_betweenticks;
3754 const int space_from_right = 8;
3755 const int space_from_left = 8;
3756 const int space_from_bottom = 11;
3757 Rectangle area = tb.ClientRectangle;
3759 switch (tb.TickStyle) {
3760 case TickStyle.BottomRight:
3761 case TickStyle.None:
3762 channel_startpoint.Y = 8;
3763 channel_startpoint.X = 9;
3764 bottomtick_startpoint.Y = 13;
3765 bottomtick_startpoint.X = 24;
3767 case TickStyle.TopLeft:
3768 channel_startpoint.Y = 8;
3769 channel_startpoint.X = 19;
3770 toptick_startpoint.Y = 13;
3771 toptick_startpoint.X = 8;
3773 case TickStyle.Both:
3774 channel_startpoint.Y = 8;
3775 channel_startpoint.X = 18;
3776 bottomtick_startpoint.Y = 13;
3777 bottomtick_startpoint.X = 32;
3778 toptick_startpoint.Y = 13;
3779 toptick_startpoint.X = 8;
3785 thumb_area.X = area.X + channel_startpoint.X;
3786 thumb_area.Y = area.Y + channel_startpoint.Y;
3787 thumb_area.Height = area.Height - space_from_right - space_from_left;
3788 thumb_area.Width = 4;
3791 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3792 1, thumb_area.Height);
3794 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
3795 1, thumb_area.Height);
3797 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
3798 1, thumb_area.Height);
3800 pixel_len = thumb_area.Height - 11;
3801 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3803 /* Convert thumb position from mouse position to value*/
3805 if (value_pos < thumb_area.Bottom)
3806 value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
3810 if (value_pos + tb.Minimum > tb.Maximum)
3811 value_pos = tb.Maximum - tb.Minimum;
3813 tb.Value = value_pos + tb.Minimum;
3816 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
3817 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
3819 /* Draw thumb fixed 10x22 size */
3820 thumb_pos.Width = 10;
3821 thumb_pos.Height = 22;
3823 switch (tb.TickStyle) {
3824 case TickStyle.BottomRight:
3825 case TickStyle.None: {
3826 thumb_pos.X = channel_startpoint.X - 8;
3828 Pen pen = SystemPens.ControlLight;
3829 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3830 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3831 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3833 pen = SystemPens.ControlDark;
3834 dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3835 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3837 pen = SystemPens.ControlDarkDark;
3838 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3839 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3841 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3842 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3843 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3844 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3848 case TickStyle.TopLeft: {
3849 thumb_pos.X = channel_startpoint.X - 10;
3851 Pen pen = SystemPens.ControlLight;
3852 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3853 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3855 pen = SystemPens.ControlDark;
3856 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3857 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3858 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3860 pen = SystemPens.ControlDarkDark;
3861 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3862 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3863 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3865 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3866 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3867 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3868 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3873 case TickStyle.Both: {
3874 thumb_pos.X = area.X + 10;
3876 Pen pen = SystemPens.ControlLight;
3877 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3878 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3880 pen = SystemPens.ControlDark;
3881 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3882 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3884 pen = SystemPens.ControlDarkDark;
3885 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3886 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3888 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3897 pixel_len = thumb_area.Height - 11;
3898 pixels_betweenticks = pixel_len / ticks;
3900 thumb_area.X = thumb_pos.X;
3901 thumb_area.Y = channel_startpoint.Y;
3902 thumb_area.Width = thumb_pos.Height;
3905 Region outside = new Region (area);
3906 outside.Exclude (thumb_area);
3908 if (outside.IsVisible (clip_rectangle)) {
3909 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3910 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3912 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3913 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3914 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3915 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3917 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3918 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3922 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3923 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3925 pixel_len = thumb_area.Height - 11;
3926 pixels_betweenticks = pixel_len / ticks;
3928 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3929 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3930 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3931 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3933 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3934 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3946 Does not matter the size of the control, Win32 always draws:
3947 - Ticks starting from pixel 13, 8
3948 - Channel starting at pos 8, 19 and ends at Width - 8
3949 - Autosize makes always the control 40 pixels height
3950 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3953 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3954 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3955 float ticks, int value_pos, bool mouse_value) {
3956 Point toptick_startpoint = new Point ();
3957 Point bottomtick_startpoint = new Point ();
3958 Point channel_startpoint = new Point ();
3960 float pixels_betweenticks;
3961 const int space_from_right = 8;
3962 const int space_from_left = 8;
3963 Rectangle area = tb.ClientRectangle;
3965 switch (tb.TickStyle) {
3966 case TickStyle.BottomRight:
3967 case TickStyle.None:
3968 channel_startpoint.X = 8;
3969 channel_startpoint.Y = 9;
3970 bottomtick_startpoint.X = 13;
3971 bottomtick_startpoint.Y = 24;
3973 case TickStyle.TopLeft:
3974 channel_startpoint.X = 8;
3975 channel_startpoint.Y = 19;
3976 toptick_startpoint.X = 13;
3977 toptick_startpoint.Y = 8;
3979 case TickStyle.Both:
3980 channel_startpoint.X = 8;
3981 channel_startpoint.Y = 18;
3982 bottomtick_startpoint.X = 13;
3983 bottomtick_startpoint.Y = 32;
3984 toptick_startpoint.X = 13;
3985 toptick_startpoint.Y = 8;
3991 thumb_area.X = area.X + channel_startpoint.X;
3992 thumb_area.Y = area.Y + channel_startpoint.Y;
3993 thumb_area.Width = area.Width - space_from_right - space_from_left;
3994 thumb_area.Height = 4;
3997 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3998 thumb_area.Width, 1);
4000 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
4001 thumb_area.Width, 1);
4003 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
4004 thumb_area.Width, 1);
4006 pixel_len = thumb_area.Width - 11;
4007 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4009 /* Convert thumb position from mouse position to value*/
4011 if (value_pos >= channel_startpoint.X)
4012 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4016 if (value_pos + tb.Minimum > tb.Maximum)
4017 value_pos = tb.Maximum - tb.Minimum;
4019 tb.Value = value_pos + tb.Minimum;
4022 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4024 /* Draw thumb fixed 10x22 size */
4025 thumb_pos.Width = 10;
4026 thumb_pos.Height = 22;
4028 switch (tb.TickStyle) {
4029 case TickStyle.BottomRight:
4030 case TickStyle.None: {
4031 thumb_pos.Y = channel_startpoint.Y - 8;
4033 Pen pen = SystemPens.ControlLight;
4034 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4035 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4036 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4038 pen = SystemPens.ControlDark;
4039 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4040 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4042 pen = SystemPens.ControlDarkDark;
4043 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4044 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4046 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4047 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4048 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4049 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4052 case TickStyle.TopLeft: {
4053 thumb_pos.Y = channel_startpoint.Y - 10;
4055 Pen pen = SystemPens.ControlLight;
4056 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4057 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4059 pen = SystemPens.ControlDark;
4060 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4061 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4062 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4064 pen = SystemPens.ControlDarkDark;
4065 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4066 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4067 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4069 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4070 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4071 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4072 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4076 case TickStyle.Both: {
4077 thumb_pos.Y = area.Y + 10;
4079 Pen pen = SystemPens.ControlLight;
4080 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4081 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4083 pen = SystemPens.ControlDark;
4084 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4085 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4087 pen = SystemPens.ControlDarkDark;
4088 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4089 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4091 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4100 pixel_len = thumb_area.Width - 11;
4101 pixels_betweenticks = pixel_len / ticks;
4104 thumb_area.Y = thumb_pos.Y;
4105 thumb_area.X = channel_startpoint.X;
4106 thumb_area.Height = thumb_pos.Height;
4107 Region outside = new Region (area);
4108 outside.Exclude (thumb_area);
4110 if (outside.IsVisible (clip_rectangle)) {
4111 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4112 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4114 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4115 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4116 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4117 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4119 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4120 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4124 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4125 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4127 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4128 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4129 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4130 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4132 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4133 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4141 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4146 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4148 Rectangle thumb_pos = tb.ThumbPos;
4149 Rectangle thumb_area = tb.ThumbArea;
4151 if (tb.thumb_pressed) {
4152 value_pos = tb.thumb_mouseclick;
4155 value_pos = tb.Value - tb.Minimum;
4156 mouse_value = false;
4159 area = tb.ClientRectangle;
4161 if (tb.thumb_pressed == true) {
4162 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4164 br_thumb = SystemBrushes.Control;
4168 /* Control Background */
4169 if (tb.BackColor == DefaultControlBackColor) {
4170 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
4172 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4177 Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
4178 dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
4179 dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4180 dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
4181 dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4184 if (tb.Orientation == Orientation.Vertical) {
4185 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4186 br_thumb, ticks, value_pos, mouse_value);
4189 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4190 br_thumb, ticks, value_pos, mouse_value);
4193 tb.ThumbPos = thumb_pos;
4194 tb.ThumbArea = thumb_area;
4197 public override Size TrackBarDefaultSize {
4199 return new Size (104, 42);
4203 #endregion // TrackBar
4206 public override Size VScrollBarDefaultSize {
4208 return new Size (this.ScrollBarButtonSize, 80);
4211 #endregion // VScrollBar
4214 public override Size TreeViewDefaultSize {
4216 return new Size (121, 97);
4222 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
4224 if (wm.IsToolWindow)
4225 return SystemInformation.ToolWindowCaptionHeight;
4226 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4228 return SystemInformation.CaptionHeight;
4231 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
4236 public override int ManagedWindowIconWidth (InternalWindowManager wm)
4238 return ManagedWindowTitleBarHeight (wm) - 5;
4241 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
4243 int bw = ManagedWindowBorderWidth (wm);
4244 Size btsize = ManagedWindowButtonSize (wm);
4245 int btw = btsize.Width;
4246 int bth = btsize.Height;
4248 if (!wm.IsToolWindow && wm.HasBorders) {
4249 if (!wm.IsMaximized) {
4250 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2,
4252 wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw,
4254 wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw,
4259 } else if (wm.IsToolWindow) {
4260 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth);
4264 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
4266 Form form = wm.Form;
4267 int tbheight = ManagedWindowTitleBarHeight (wm);
4268 int bdwidth = ManagedWindowBorderWidth (wm);
4269 Color titlebar_color = Color.FromArgb (255, 0, 0, 255);
4271 if (wm.HasBorders) {
4272 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
4273 // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves
4274 dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5);
4275 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
4278 Color color = ThemeEngine.Current.ColorControlDark;
4280 if (wm.IsActive () && !wm.IsMaximized)
4281 color = titlebar_color;
4283 Rectangle tb = new Rectangle (bdwidth, bdwidth,
4284 form.Width - (bdwidth * 2), tbheight);
4286 // HACK: For now always draw the titlebar until we get updates better
4287 // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle);
4288 //if (vis != Rectangle.Empty)
4289 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), tb);
4291 dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth,
4292 tbheight + bdwidth, form.Width - (bdwidth * 2),
4293 tbheight + bdwidth);
4295 if (!wm.IsToolWindow) {
4296 tb.X += 18; // Room for the icon and the buttons
4297 tb.Width = (form.Width - 62) - tb.X;
4300 if (form.Text != null) {
4301 StringFormat format = new StringFormat ();
4302 format.FormatFlags = StringFormatFlags.NoWrap;
4303 format.Trimming = StringTrimming.EllipsisCharacter;
4304 format.LineAlignment = StringAlignment.Center;
4306 if (tb.IntersectsWith (clip))
4307 dc.DrawString (form.Text, form.Font,
4308 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
4312 if (wm.HasBorders) {
4313 if (!wm.IsToolWindow && form.Icon != null) {
4314 Rectangle icon = new Rectangle (bdwidth + 3,
4315 bdwidth + 2, wm.IconWidth, wm.IconWidth);
4316 if (icon.IntersectsWith (clip))
4317 dc.DrawIcon (form.Icon, icon);
4320 if (!wm.IsMaximized) {
4321 if (!wm.IsToolWindow) {
4322 DrawTitleButton (dc, wm.minimize_button, clip);
4323 DrawTitleButton (dc, wm.maximize_button, clip);
4325 DrawTitleButton (dc, wm.close_button, clip);
4327 // DrawMaximizedButtons (pe, form.ActiveMenu);
4332 private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip)
4334 if (!button.Rectangle.IntersectsWith (clip))
4337 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
4339 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
4340 button.Caption, ButtonState.Normal);
4343 private Size ManagedWindowButtonSize (InternalWindowManager wm)
4345 int height = wm.TitleBarHeight;
4346 if (wm.IsToolWindow)
4347 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
4349 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4351 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
4355 #region ControlPaint
4356 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4357 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4358 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4359 int bottomWidth, ButtonBorderStyle bottomStyle) {
4360 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4361 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4362 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4363 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4366 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4367 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4370 protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
4373 Pen penTopLeftInner;
4375 Pen penBottomRightInner;
4376 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4377 bool is_ColorControl = control_color == ColorControl ? true : false;
4379 if ((style & Border3DStyle.Adjust) != 0) {
4386 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
4388 CPColor cpcolor = CPColor.Empty;
4390 if (!is_ColorControl)
4391 cpcolor = ResPool.GetCPColor (control_color);
4394 case Border3DStyle.Raised:
4395 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4396 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4397 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4399 case Border3DStyle.Sunken:
4400 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4401 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4402 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4404 case Border3DStyle.Etched:
4405 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4406 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4408 case Border3DStyle.RaisedOuter:
4409 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4411 case Border3DStyle.SunkenOuter:
4412 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4413 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4415 case Border3DStyle.RaisedInner:
4416 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4417 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4419 case Border3DStyle.SunkenInner:
4420 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4422 case Border3DStyle.Flat:
4423 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4425 case Border3DStyle.Bump:
4426 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4432 if ((sides & Border3DSide.Middle) != 0) {
4433 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
4434 graphics.FillRectangle (brush, rect);
4437 if ((sides & Border3DSide.Left) != 0) {
4438 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
4439 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
4442 if ((sides & Border3DSide.Top) != 0) {
4443 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
4444 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
4447 if ((sides & Border3DSide.Right) != 0) {
4448 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
4449 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
4452 if ((sides & Border3DSide.Bottom) != 0) {
4453 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4454 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
4458 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
4460 // sadly enough, the rectangle gets always filled with a hatchbrush
4461 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);
4463 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
4464 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4466 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4468 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4469 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4471 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4472 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4474 Pen pen = SystemPens.ControlDarkDark;
4475 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4476 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4478 pen = SystemPens.ControlDark;
4479 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4480 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4482 pen = SystemPens.ControlLight;
4483 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4484 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4486 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
4487 Pen pen = SystemPens.ControlDarkDark;
4488 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4489 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4491 pen = SystemPens.ControlDark;
4492 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4493 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4495 pen = SystemPens.ControlLight;
4496 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4497 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4499 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
4500 Pen pen = SystemPens.ControlLight;
4501 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4502 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4504 pen = SystemPens.ControlDark;
4505 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
4506 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
4508 pen = SystemPens.ControlDarkDark;
4509 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
4510 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
4515 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4516 Rectangle captionRect;
4519 CPDrawButton(graphics, rectangle, state);
4521 if (rectangle.Width<rectangle.Height) {
4522 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4524 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4527 if ((state & ButtonState.Pushed)!=0) {
4528 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4531 /* Make sure we've got at least a line width of 1 */
4532 lineWidth=Math.Max(1, captionRect.Width/7);
4535 case CaptionButton.Close: {
4538 if ((state & ButtonState.Inactive)!=0) {
4539 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
4540 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4542 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
4543 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4546 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
4547 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4552 case CaptionButton.Help:
4553 case CaptionButton.Maximize:
4554 case CaptionButton.Minimize:
4555 case CaptionButton.Restore: {
4556 if ((state & ButtonState.Inactive)!=0) {
4557 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4559 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4562 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4569 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
4571 Pen check_pen = SystemPens.ControlDarkDark;
4573 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4575 if ((state & ButtonState.All) == ButtonState.All) {
4577 cb_rect.Height -= 2;
4579 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4580 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4582 check_pen = SystemPens.ControlDark;
4584 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4586 cb_rect.Height -= 2;
4588 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4589 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4592 cb_rect.Height -= 1;
4594 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
4596 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
4597 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
4599 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
4601 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
4602 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);
4604 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4606 Pen pen = SystemPens.ControlDark;
4607 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
4608 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
4610 pen = SystemPens.ControlDarkDark;
4611 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
4612 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
4614 pen = SystemPens.ControlLight;
4615 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
4616 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
4618 // oh boy, matching ms is like fighting against windmills
4619 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl))) {
4620 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4621 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
4624 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
4625 check_pen = SystemPens.ControlDark;
4628 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4629 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
4631 if (check_size < 7) {
4632 int lineWidth = Math.Max (3, check_size / 3);
4633 int Scale = Math.Max (1, check_size / 9);
4635 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,
4636 check_size, check_size);
4638 for (int i = 0; i < lineWidth; i++) {
4639 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
4640 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);
4643 int lineWidth = Math.Max (3, check_size / 3) + 1;
4645 int x_half = cb_rect.Width / 2;
4646 int y_half = cb_rect.Height / 2;
4648 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
4649 check_size, check_size);
4651 int gradient_left = check_size / 3;
4652 int gradient_right = check_size - gradient_left - 1;
4655 for (int i = 0; i < lineWidth; i++) {
4656 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
4657 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
4663 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4664 Point[] arrow = new Point[3];
4674 if ((state & ButtonState.Checked)!=0) {
4675 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4678 if ((state & ButtonState.Flat)!=0) {
4679 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4681 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4682 // this needs to render like a pushed button - jba
4683 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4684 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4685 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
4687 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4691 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4692 centerX=rect.Left+rect.Width/2;
4693 centerY=rect.Top+rect.Height/2;
4694 shiftX=Math.Max(1, rect.Width/8);
4695 shiftY=Math.Max(1, rect.Height/8);
4697 if ((state & ButtonState.Pushed)!=0) {
4704 P1=new Point(rect.Left, centerY);
4705 P2=new Point(rect.Right, centerY);
4706 P3=new Point(centerX, rect.Bottom);
4712 /* Draw the arrow */
4713 if ((state & ButtonState.Inactive)!=0) {
4714 /* Move away from the shadow */
4715 arrow[0].X += 1; arrow[0].Y += 1;
4716 arrow[1].X += 1; arrow[1].Y += 1;
4717 arrow[2].X += 1; arrow[2].Y += 1;
4719 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4725 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4727 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4732 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
4734 Pen pen = Pens.Black;
4735 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
4739 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
4740 graphics.DrawRectangle (pen, rect);
4742 X = rect.X + rect.Width / 2;
4743 Y = rect.Y + rect.Height / 2;
4745 /* Draw the cross */
4746 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
4747 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
4749 /* Draw 'arrows' for vertical lines */
4750 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
4751 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
4753 /* Draw 'arrows' for horizontal lines */
4754 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
4755 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
4758 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4759 // make a rectange to trace around border of the button
4760 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4762 Color outerColor = foreColor;
4763 // adjust focus color according to the flatstyle
4764 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4765 outerColor = (backColor == ColorControl) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4768 // draw the outer rectangle
4769 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4771 // draw the inner rectangle
4772 if (button.FlatStyle == FlatStyle.Popup) {
4773 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4775 // draw a flat inner rectangle
4776 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4777 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4781 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4783 // make a rectange to trace around border of the button
4784 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4786 #if NotUntilCairoIsFixed
4787 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4788 DashStyle oldStyle; // used for caching old penstyle
4789 Pen pen = ResPool.GetPen (colorBackInverted);
4791 oldStyle = pen.DashStyle;
4792 pen.DashStyle = DashStyle.Dot;
4794 graphics.DrawRectangle (pen, trace_rectangle);
4795 pen.DashStyle = oldStyle;
4797 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4802 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4804 Rectangle rect = rectangle;
4808 if (backColor.GetBrightness () >= 0.5) {
4809 foreColor = Color.Transparent;
4810 backColor = Color.Black;
4813 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4814 foreColor = Color.Black;
4817 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4818 pen = new Pen (brush, 1);
4823 graphics.DrawRectangle (pen, rect);
4827 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
4832 if (primary == true) {
4834 if (enabled == true) {
4837 sb = SystemBrushes.Control;
4841 if (enabled == true) {
4844 sb = SystemBrushes.Control;
4847 graphics.FillRectangle (sb, rectangle);
4848 graphics.DrawRectangle (pen, rectangle);
4852 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4858 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4861 foreColor=Color.Black;
4863 foreColor=Color.White;
4866 // still not perfect. it seems that ms calculates the position of the first dot or line
4868 using (Pen pen = new Pen (foreColor)) {
4869 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
4871 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
4872 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
4876 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4878 Microsoft seems to ignore the background and simply make
4879 the image grayscale. At least when having > 256 colors on
4883 if (imagedisabled_attributes == null) {
4884 imagedisabled_attributes = new ImageAttributes ();
4885 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4886 // This table would create a perfect grayscale image, based on luminance
4887 // new float[]{0.3f,0.3f,0.3f,0,0},
4888 // new float[]{0.59f,0.59f,0.59f,0,0},
4889 // new float[]{0.11f,0.11f,0.11f,0,0},
4890 // new float[]{0,0,0,1,0,0},
4891 // new float[]{0,0,0,0,1,0},
4892 // new float[]{0,0,0,0,0,1}
4894 // This table generates a image that is grayscaled and then
4895 // brightened up. Seems to match MS close enough.
4896 new float[]{0.2f,0.2f,0.2f,0,0},
4897 new float[]{0.41f,0.41f,0.41f,0,0},
4898 new float[]{0.11f,0.11f,0.11f,0,0},
4899 new float[]{0.15f,0.15f,0.15f,1,0,0},
4900 new float[]{0.15f,0.15f,0.15f,0,1,0},
4901 new float[]{0.15f,0.15f,0.15f,0,0,1}
4904 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4907 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4912 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4917 penBorder = ResPool.GetSizedPen (Color.White, 2);
4918 penInside = ResPool.GetPen (Color.Black);
4920 penBorder = ResPool.GetSizedPen (Color.Black, 2);
4921 penInside = ResPool.GetPen (Color.White);
4923 penBorder.Alignment=PenAlignment.Inset;
4924 penInside.Alignment=PenAlignment.Inset;
4926 graphics.DrawRectangle(penBorder, rectangle);
4927 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4931 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
4935 Brush brush = ResPool.GetSolidBrush (color);
4938 case MenuGlyph.Arrow: {
4939 Point[] arrow = new Point[3];
4947 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4948 centerX=rect.Left+rect.Width/2;
4949 centerY=rect.Top+rect.Height/2;
4950 shiftX=Math.Max(1, rect.Width/8);
4955 P1=new Point(centerX, rect.Top);
4956 P2=new Point(centerX, rect.Bottom);
4957 P3=new Point(rect.Right, centerY);
4963 graphics.FillPolygon(brush, arrow, FillMode.Winding);
4968 case MenuGlyph.Bullet: {
4970 lineWidth=Math.Max(2, rectangle.Width/3);
4971 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4973 graphics.FillEllipse(brush, rect);
4978 case MenuGlyph.Checkmark: {
4980 Pen pen = ResPool.GetPen (color);
4982 lineWidth=Math.Max(2, rectangle.Width/6);
4983 Scale=Math.Max(1, rectangle.Width/12);
4985 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4987 for (int i=0; i<lineWidth; i++) {
4988 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4989 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);
4997 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
4999 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
5001 Color dot_color = Color.Black;
5003 Color top_left_outer = Color.Black;
5004 Color top_left_inner = Color.Black;
5005 Color bottom_right_outer = Color.Black;
5006 Color bottom_right_inner = Color.Black;
5008 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
5009 int radius = ellipse_diameter / 2;
5011 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
5015 if ((state & ButtonState.All) == ButtonState.All) {
5016 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5017 dot_color = cpcolor.Dark;
5019 if ((state & ButtonState.Flat) == ButtonState.Flat) {
5020 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5021 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5023 brush = SystemBrushes.ControlLightLight;
5025 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5026 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5028 brush = SystemBrushes.ControlLightLight;
5030 top_left_outer = cpcolor.Dark;
5031 top_left_inner = cpcolor.DarkDark;
5032 bottom_right_outer = cpcolor.Light;
5033 bottom_right_inner = Color.Transparent;
5035 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
5036 dot_color = cpcolor.Dark;
5039 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
5041 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
5043 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
5044 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
5045 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
5047 if (bottom_right_inner != Color.Transparent)
5048 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5050 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), line_width)) {
5051 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5054 if ((state & ButtonState.Checked) == ButtonState.Checked) {
5055 int inflate = line_width * 4;
5056 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
5057 if (rectangle.Height > 13) {
5061 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
5063 Pen pen = ResPool.GetPen (dot_color);
5064 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
5065 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
5067 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
5068 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
5073 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
5078 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
5083 /* Scroll button: regular button + direction arrow */
5084 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
5086 DrawScrollButtonPrimitive (dc, area, state);
5088 bool fill_rect = true;
5091 if ((state & ButtonState.Pushed) != 0)
5095 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
5097 Point [] arrow = new Point [3];
5098 for (int i = 0; i < 3; i++)
5099 arrow [i] = new Point ();
5101 Pen pen = SystemPens.ControlText;
5103 if ((state & ButtonState.Inactive) != 0) {
5104 pen = SystemPens.ControlDark;
5109 case ScrollButton.Down:
5110 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5114 int triangle_height;
5116 if (rect.Height < 8) {
5117 triangle_height = 2;
5119 } else if (rect.Height == 11) {
5120 triangle_height = 3;
5122 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5125 arrow [0].X = rect.X + x_middle;
5126 arrow [0].Y = rect.Bottom - triangle_height - 1;
5128 if (arrow [0].Y - 1 == rect.Y)
5131 arrow [1].X = arrow [0].X + triangle_height - 1;
5132 arrow [1].Y = arrow [0].Y - triangle_height + 1;
5133 arrow [2].X = arrow [0].X - triangle_height + 1;
5134 arrow [2].Y = arrow [1].Y;
5136 dc.DrawPolygon (pen, arrow);
5138 if ((state & ButtonState.Inactive) != 0) {
5139 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
5140 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
5144 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
5145 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
5154 case ScrollButton.Up:
5155 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5159 if (rect.Height < 8) {
5160 triangle_height = 2;
5162 } else if (rect.Height == 11) {
5163 triangle_height = 3;
5165 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5168 arrow [0].X = rect.X + x_middle;
5169 arrow [0].Y = rect.Y + triangle_height;
5171 if (arrow [0].Y + 1 == rect.Bottom - 1)
5174 arrow [1].X = arrow [0].X + triangle_height - 1;
5175 arrow [1].Y = arrow [0].Y + triangle_height - 1;
5176 arrow [2].X = arrow [0].X - triangle_height + 1;
5177 arrow [2].Y = arrow [1].Y;
5179 dc.DrawPolygon (pen, arrow);
5181 if ((state & ButtonState.Inactive) != 0) {
5182 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
5186 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
5187 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
5195 case ScrollButton.Left:
5196 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5202 if (rect.Width < 8) {
5205 } else if (rect.Width == 11) {
5208 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5211 arrow [0].X = rect.Left + triangle_width - 1;
5212 arrow [0].Y = rect.Y + y_middle;
5214 if (arrow [0].X - 1 == rect.X)
5217 arrow [1].X = arrow [0].X + triangle_width - 1;
5218 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5219 arrow [2].X = arrow [1].X;
5220 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5222 dc.DrawPolygon (pen, arrow);
5224 if ((state & ButtonState.Inactive) != 0) {
5225 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5229 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
5230 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
5237 case ScrollButton.Right:
5238 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5242 if (rect.Width < 8) {
5245 } else if (rect.Width == 11) {
5248 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5251 arrow [0].X = rect.Right - triangle_width - 1;
5252 arrow [0].Y = rect.Y + y_middle;
5254 if (arrow [0].X - 1 == rect.X)
5257 arrow [1].X = arrow [0].X - triangle_width + 1;
5258 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5259 arrow [2].X = arrow [1].X;
5260 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5262 dc.DrawPolygon (pen, arrow);
5264 if ((state & ButtonState.Inactive) != 0) {
5265 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5266 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
5270 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
5271 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
5280 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5286 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
5288 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
5289 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
5291 for (int i = 2; i < bounds.Width - 2; i += 4) {
5292 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
5293 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
5294 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
5298 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
5300 CPColor cpcolor = ResPool.GetCPColor (color);
5302 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
5303 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
5305 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
5308 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5309 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5314 case ButtonBorderStyle.Solid:
5315 case ButtonBorderStyle.Inset:
5316 case ButtonBorderStyle.Outset:
5317 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
5319 case ButtonBorderStyle.Dashed:
5320 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
5322 case ButtonBorderStyle.Dotted:
5323 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
5326 case ButtonBorderStyle.None:
5331 case ButtonBorderStyle.Outset: {
5333 int hue, brightness, saturation;
5334 int brightnessSteps;
5335 int brightnessDownSteps;
5337 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5339 brightnessDownSteps=brightness/width;
5340 if (brightness>127) {
5341 brightnessSteps=Math.Max(6, (160-brightness)/width);
5343 brightnessSteps=(127-brightness)/width;
5346 for (int i=0; i<width; i++) {
5348 case Border3DSide.Left: {
5349 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5350 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5351 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5355 case Border3DSide.Right: {
5356 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5357 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5358 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5362 case Border3DSide.Top: {
5363 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5364 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5365 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5369 case Border3DSide.Bottom: {
5370 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5371 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5372 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5380 case ButtonBorderStyle.Inset: {
5382 int hue, brightness, saturation;
5383 int brightnessSteps;
5384 int brightnessDownSteps;
5386 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5388 brightnessDownSteps=brightness/width;
5389 if (brightness>127) {
5390 brightnessSteps=Math.Max(6, (160-brightness)/width);
5392 brightnessSteps=(127-brightness)/width;
5395 for (int i=0; i<width; i++) {
5397 case Border3DSide.Left: {
5398 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5399 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5400 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5404 case Border3DSide.Right: {
5405 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5406 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5407 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5411 case Border3DSide.Top: {
5412 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5413 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5414 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5418 case Border3DSide.Bottom: {
5419 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5420 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5421 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5430 I decided to have the for-loop duplicated for speed reasons;
5431 that way we only have to switch once (as opposed to have the
5432 for-loop around the switch)
5436 case Border3DSide.Left: {
5437 for (int i=0; i<width; i++) {
5438 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5443 case Border3DSide.Right: {
5444 for (int i=0; i<width; i++) {
5445 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5450 case Border3DSide.Top: {
5451 for (int i=0; i<width; i++) {
5452 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5457 case Border3DSide.Bottom: {
5458 for (int i=0; i<width; i++) {
5459 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5470 This function actually draws the various caption elements.
5471 This way we can scale them nicely, no matter what size, and they
5472 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5475 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5477 case CaptionButton.Close: {
5479 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);
5480 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);
5483 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5484 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5488 case CaptionButton.Help: {
5489 StringFormat sf = new StringFormat();
5490 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5492 sf.Alignment=StringAlignment.Center;
5493 sf.LineAlignment=StringAlignment.Center;
5496 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5504 case CaptionButton.Maximize: {
5505 /* Top 'caption bar' line */
5506 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5507 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);
5510 /* Left side line */
5511 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5512 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5515 /* Right side line */
5516 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5517 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);
5521 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5522 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5527 case CaptionButton.Minimize: {
5529 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5530 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5535 case CaptionButton.Restore: {
5536 /** First 'window' **/
5537 /* Top 'caption bar' line */
5538 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5539 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);
5542 /* Left side line */
5543 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5544 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);
5547 /* Right side line */
5548 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5549 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);
5553 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5554 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);
5557 /** Second 'window' **/
5558 /* Top 'caption bar' line */
5559 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5560 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);
5563 /* Left side line */
5564 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5565 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5568 /* Right side line */
5569 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5570 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);
5574 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5575 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5584 /* Generic scroll button */
5585 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5586 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5587 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
5588 area.Y + 1, area.Width - 2 , area.Height - 2);
5590 dc.DrawRectangle (SystemPens.ControlDark, area.X,
5591 area.Y, area.Width, area.Height);
5596 Brush sb_control = SystemBrushes.Control;
5597 Brush sb_lightlight = SystemBrushes.ControlLightLight;
5598 Brush sb_dark = SystemBrushes.ControlDark;
5599 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
5601 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
5602 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
5604 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
5605 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
5608 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
5611 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
5614 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
5615 area.Y + 1, 1, area.Height -3);
5617 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
5618 area.Y, 1, area.Height - 1);
5620 dc.FillRectangle (sb_control, area.X + 2,
5621 area.Y + 2, area.Width - 4, area.Height - 4);
5625 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5626 switch (border_style){
5627 case BorderStyle.Fixed3D:
5628 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5629 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5630 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5631 area.Y + area.Height - 1);
5632 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5633 area.Y + area.Height);
5635 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5636 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5637 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5638 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5640 case BorderStyle.FixedSingle:
5641 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5643 case BorderStyle.None:
5649 #endregion // ControlPaint