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.ToArgb () == DefaultControlBackColor.ToArgb ())
110 return SystemBrushes.Control;
111 return ResPool.GetSolidBrush (c);
114 protected Brush GetControlForeBrush (Color c) {
115 if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
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.ToArgb () == ColorControl.ToArgb () ? 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.ToArgb () == ColorControl.ToArgb () ? 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.ToArgb () == ColorControl.ToArgb () ? 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 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
907 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
909 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
910 rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
911 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
913 if (clip.IntersectsWith (rect_columnhdr) == false)
916 current_clip = new Region (rect_columnhdr);
917 current_clip.Intersect (columns_area);
918 current_clip.Intersect (clip);
919 g.Clip = current_clip;
921 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
923 current_clip.Dispose ();
928 Rectangle not_usedarea = columnshdrs_area_complete;
929 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
930 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
931 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
935 public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
937 Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
938 rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
939 Rectangle rect_row = new Rectangle ();
940 rect_row.X = grid.grid_drawing.rowshdrs_area.X;
941 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
942 Rectangle not_usedarea = rowshdrs_area_complete;
944 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
948 g.SetClip (grid.grid_drawing.rowshdrs_area);
949 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
951 rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
952 rect_row.Height = grid.RowHeight;
953 rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
955 if (clip.IntersectsWith (rect_row)) {
956 DataGridPaintRowHeader (g, rect_row, row, grid);
961 not_usedarea.Height = grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
962 not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + grid.grid_drawing.rowshdrs_area.Height;
963 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
966 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
968 Point[] arrow = new Point[3];
970 int centerX, centerY, shiftX;
973 rect = new Rectangle (bounds.X + bounds.Width /4,
974 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
976 centerX = rect.Left + rect.Width / 2;
977 centerY = rect.Top + rect.Height / 2;
978 shiftX = Math.Max (1, rect.Width / 8);
981 P1 = new Point (centerX, rect.Top - 1);
982 P2 = new Point (centerX, rect.Bottom);
983 P3 = new Point (rect.Right, centerY);
988 g.FillPolygon (ResPool.GetSolidBrush
989 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
992 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
995 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
998 if (grid.FlatMode == false) {
1001 g.DrawLine (ResPool.GetPen (ColorControlLight),
1002 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1004 g.DrawLine (ResPool.GetPen (ColorControlLight),
1005 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1007 g.DrawLine (ResPool.GetPen (ColorControlDark),
1008 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1010 g.DrawLine (ResPool.GetPen (ColorControlDark),
1011 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1014 if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
1016 g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1021 if (row == grid.CurrentCell.RowNumber) {
1023 if (grid.is_changing == true) {
1024 g.DrawString ("...", grid.Font,
1025 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1030 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1031 DataGridPaintRowHeaderArrow (g, rect, grid);
1037 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1039 Rectangle rect_row = new Rectangle ();
1040 Rectangle not_usedarea = new Rectangle ();
1041 rect_row.X = cells.X;
1043 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1045 if (grid.ShowEditRow && grid.RowsCount > 0) {
1049 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1053 rect_row.Height = grid.RowHeight;
1054 rect_row.Width = cells.Width;
1055 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1056 rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1057 if (clip.IntersectsWith (rect_row)) {
1058 DataGridPaintRow (g, row, rect_row, false, clip, grid);
1062 if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
1063 rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
1064 if (clip.IntersectsWith (rect_row)) {
1065 DataGridPaintRow (g, rowcnt, rect_row, true, clip, grid);
1070 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1071 not_usedarea.Y = rect_row.Y + rect_row.Height;
1072 not_usedarea.Width = rect_row.Width = cells.Width;
1073 not_usedarea.X = cells.X;
1075 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1078 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1079 Rectangle clip, DataGrid grid)
1081 Rectangle rect_cell = new Rectangle ();
1083 Color backcolor, forecolor;
1084 Brush backBrush, foreBrush;
1085 Region prev_clip = g.Clip;
1086 Region current_clip;
1087 Rectangle not_usedarea = new Rectangle ();
1089 rect_cell.Y = row_rect.Y;
1090 rect_cell.Height = row_rect.Height;
1092 if (grid.IsSelected (row)) {
1093 backcolor = grid.SelectionBackColor;
1094 forecolor = grid.SelectionForeColor;
1097 backcolor = grid.BackColor;
1099 backcolor = grid.AlternatingBackColor;
1102 forecolor = grid.ForeColor;
1106 backBrush = ResPool.GetSolidBrush (backcolor);
1107 foreBrush = ResPool.GetSolidBrush (forecolor);
1109 // PaintCells at row, column
1110 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1111 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1113 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1115 rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
1116 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1118 if (clip.IntersectsWith (rect_cell)) {
1119 current_clip = new Region (rect_cell);
1120 current_clip.Intersect (row_rect);
1121 current_clip.Intersect (clip);
1122 g.Clip = current_clip;
1125 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1129 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1132 grid.RightToLeft == RightToLeft.Yes);
1135 current_clip.Dispose ();
1141 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1142 not_usedarea.X = rect_cell.X + rect_cell.Width;
1143 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1144 not_usedarea.Y = row_rect.Y;
1145 not_usedarea.Height = row_rect.Height;
1146 if (clip.IntersectsWith (not_usedarea))
1147 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1152 #endregion // Datagrid
1154 #region DateTimePicker
1156 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1157 // if not showing the numeric updown control then render border
1158 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1159 // draw the outer border
1160 Rectangle button_bounds = dtp.ClientRectangle;
1161 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1163 // deflate by the border width
1164 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1165 button_bounds.Inflate (-2,-2);
1166 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1167 this.CPDrawComboButton (
1169 dtp.drop_down_arrow_rect,
1174 // render the date part
1175 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1176 // fill the background
1177 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
1179 // fill the currently highlighted area
1180 if (dtp.hilight_date_area != Rectangle.Empty) {
1181 dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
1184 // draw the text part
1185 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1186 StringFormat text_format = new StringFormat();
1187 text_format.LineAlignment = StringAlignment.Center;
1188 text_format.Alignment = StringAlignment.Near;
1189 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1190 text_format.Dispose ();
1194 #endregion // DateTimePicker
1197 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1198 StringFormat text_format;
1203 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
1205 text_format = new StringFormat();
1206 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1208 size = dc.MeasureString (box.Text, box.Font);
1209 width = ((int) size.Width) + 7;
1211 if (width > box.Width - 16)
1212 width = box.Width - 16;
1214 y = box.Font.Height / 2;
1217 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
1220 if (box.Text.Length != 0) {
1221 Pen pen = ResPool.GetPen (box.BackColor);
1222 dc.DrawLine (pen, 9, y, 8 + width, y);
1223 dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1);
1226 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1228 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
1229 new RectangleF (10, 0, width, box.Font.Height), text_format);
1233 text_format.Dispose ();
1236 public override Size GroupBoxDefaultSize {
1238 return new Size (200,100);
1244 public override Size HScrollBarDefaultSize {
1246 return new Size (80, this.ScrollBarButtonSize);
1250 #endregion // HScrollBar
1253 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1255 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1257 if (label.Enabled) {
1258 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1260 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
1265 public override Size LabelDefaultSize {
1267 return new Size (100, 23);
1273 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1277 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1279 for (int i = 0; i < label.num_pieces; i++) {
1281 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1285 color = label.GetLinkColor (label.pieces[i], i);
1287 if (label.pieces[i].link == null)
1288 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.ForeColor),
1289 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1291 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
1292 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1294 if (label.pieces[i].focused) {
1295 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1300 #endregion // LinkLabel
1303 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1305 Color back_color, fore_color;
1307 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1308 back_color = ColorHighlight;
1309 fore_color = ColorHighlightText;
1311 back_color = e.BackColor;
1312 fore_color = e.ForeColor;
1315 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1317 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1318 ResPool.GetSolidBrush (fore_color),
1319 e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
1321 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
1322 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1329 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1331 bool details = control.View == View.Details;
1333 dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);
1334 int first = control.FirstVisibleIndex;
1336 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1337 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1338 DrawListViewItem (dc, control, control.Items [i]);
1341 // draw the gridlines
1342 if (details && control.GridLines) {
1343 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1344 2 : control.Font.Height + 2;
1346 // draw vertical gridlines
1347 foreach (ColumnHeader col in control.Columns)
1348 dc.DrawLine (SystemPens.Control,
1349 col.Rect.Right, top,
1350 col.Rect.Right, control.TotalHeight);
1351 // draw horizontal gridlines
1352 ListViewItem last_item = null;
1353 foreach (ListViewItem item in control.Items) {
1354 dc.DrawLine (SystemPens.Control,
1355 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1356 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1360 // draw a line after at the bottom of the last item
1361 if (last_item != null) {
1362 dc.DrawLine (SystemPens.Control,
1363 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1364 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1366 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1370 // Draw corner between the two scrollbars
1371 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1372 Rectangle rect = new Rectangle ();
1373 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1374 rect.Width = control.v_scroll.Width;
1375 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1376 rect.Height = control.h_scroll.Height;
1377 dc.FillRectangle (SystemBrushes.Control, rect);
1380 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
1381 if (!box_select_rect.Size.IsEmpty)
1382 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
1386 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1388 bool details = (control.View == View.Details);
1390 // border is drawn directly in the Paint method
1391 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1392 dc.FillRectangle (GetControlBackBrush (control.BackColor),
1393 0, 0, control.TotalWidth, control.Font.Height + 5);
1394 if (control.Columns.Count > 0) {
1395 foreach (ColumnHeader col in control.Columns) {
1396 Rectangle rect = col.Rect;
1397 rect.X -= control.h_marker;
1399 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1400 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1402 state = ButtonState.Flat;
1403 this.CPDrawButton (dc, rect, state);
1406 if (rect.Width <= 0)
1408 dc.DrawString (col.Text, DefaultFont,
1409 SystemBrushes.ControlText,
1412 int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
1413 if (right < control.Right) {
1414 Rectangle rect = control.Columns [0].Rect;
1416 rect.Width = control.Right - right;
1418 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1419 state = ButtonState.Normal;
1421 state = ButtonState.Flat;
1422 CPDrawButton (dc, rect, state);
1428 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
1430 Rectangle rect = col.Rect;
1431 rect.X -= view.h_marker;
1432 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
1433 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
1436 if (rect.Width <= 0)
1438 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
1439 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
1440 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
1443 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1446 if (control.View == View.Details && control.Columns.Count > 0)
1447 col_offset = control.Columns [0].Rect.X;
1451 Rectangle rect_checkrect = item.CheckRectReal;
1452 rect_checkrect.X += col_offset;
1453 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
1454 icon_rect.X += col_offset;
1455 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1456 full_rect.X += col_offset;
1457 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1458 text_rect.X += col_offset;
1460 if (control.CheckBoxes) {
1461 if (control.StateImageList == null) {
1462 // Make sure we've got at least a line width of 1
1463 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1464 int scale = Math.Max (1, rect_checkrect.Width / 12);
1466 // set the checkbox background
1467 dc.FillRectangle (SystemBrushes.Window,
1469 // define a rectangle inside the border area
1470 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1471 rect_checkrect.Y + 2,
1472 rect_checkrect.Width - 4,
1473 rect_checkrect.Height - 4);
1474 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
1475 dc.DrawRectangle (pen, rect);
1477 // Need to draw a check-mark
1479 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
1480 // adjustments to get the check-mark at the right place
1481 rect.X ++; rect.Y ++;
1482 // following logic is taken from DrawFrameControl method
1483 for (int i = 0; i < check_wd; i++) {
1484 dc.DrawLine (check_pen, rect.Left + check_wd / 2,
1485 rect.Top + check_wd + i,
1486 rect.Left + check_wd / 2 + 2 * scale,
1487 rect.Top + check_wd + 2 * scale + i);
1488 dc.DrawLine (check_pen,
1489 rect.Left + check_wd / 2 + 2 * scale,
1490 rect.Top + check_wd + 2 * scale + i,
1491 rect.Left + check_wd / 2 + 6 * scale,
1492 rect.Top + check_wd - 2 * scale + i);
1497 if (item.Checked && control.StateImageList.Images.Count > 1)
1498 control.StateImageList.Draw (dc,
1499 rect_checkrect.Location, 1);
1500 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1501 control.StateImageList.Draw (dc,
1502 rect_checkrect.Location, 0);
1506 if (control.View == View.LargeIcon) {
1507 if (item.ImageIndex > -1 && control.LargeImageList != null &&
1508 item.ImageIndex < control.LargeImageList.Images.Count)
1509 control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1511 if (item.ImageIndex > -1 && control.SmallImageList != null &&
1512 item.ImageIndex < control.SmallImageList.Images.Count)
1513 control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1516 // draw the item text
1517 // format for the item text
1518 StringFormat format = new StringFormat ();
1519 if (control.View == View.SmallIcon)
1520 format.LineAlignment = StringAlignment.Near;
1522 format.LineAlignment = StringAlignment.Center;
1523 if (control.View == View.LargeIcon)
1524 format.Alignment = StringAlignment.Center;
1526 format.Alignment = StringAlignment.Near;
1528 if (!control.LabelWrap)
1529 format.FormatFlags = StringFormatFlags.NoWrap;
1531 if (item.Selected && control.item_control.Focused) {
1532 if (control.View == View.Details) {
1533 if (control.FullRowSelect) {
1534 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1537 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1539 text_rect.Width = text_size.Width;
1540 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1544 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1546 Point loc = text_rect.Location;
1547 loc.X += (text_rect.Width - text_size.Width) / 2;
1548 text_rect.Width = text_size.Width;*/
1549 dc.FillRectangle (SystemBrushes.Highlight, text_rect);
1553 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1555 if (item.Text != null && item.Text.Length > 0) {
1556 if (item.Selected && control.item_control.Focused)
1557 dc.DrawString (item.Text, item.Font, SystemBrushes.HighlightText, text_rect, format);
1559 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1560 (item.ForeColor), text_rect, format);
1563 if (control.View == View.Details && control.Columns.Count > 0) {
1564 // draw subitems for details view
1565 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1566 int count = (control.Columns.Count < subItems.Count ?
1567 control.Columns.Count : subItems.Count);
1571 ListViewItem.ListViewSubItem subItem;
1572 Rectangle sub_item_rect = text_rect;
1574 // set the format for subitems
1575 format.FormatFlags = StringFormatFlags.NoWrap;
1577 // 0th subitem is the item already drawn
1578 for (int index = 1; index < count; index++) {
1579 subItem = subItems [index];
1580 col = control.Columns [index];
1581 format.Alignment = col.Format.Alignment;
1582 sub_item_rect.X = col.Rect.X - control.h_marker;
1583 sub_item_rect.Width = col.Wd;
1584 Rectangle sub_item_text_rect = sub_item_rect;
1585 sub_item_text_rect.X += 3;
1586 sub_item_text_rect.Width -= 6;
1588 SolidBrush sub_item_back_br = null;
1589 SolidBrush sub_item_fore_br = null;
1590 Font sub_item_font = null;
1592 if (item.UseItemStyleForSubItems) {
1593 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
1594 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
1595 sub_item_font = item.Font;
1597 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
1598 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
1599 sub_item_font = subItem.Font;
1602 if (item.Selected && control.FullRowSelect) {
1603 dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
1604 if (subItem.Text != null && subItem.Text.Length > 0)
1605 dc.DrawString (subItem.Text, sub_item_font,
1606 SystemBrushes.HighlightText,
1607 sub_item_text_rect, format);
1609 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1610 if (subItem.Text != null && subItem.Text.Length > 0)
1611 dc.DrawString (subItem.Text, sub_item_font,
1613 sub_item_text_rect, format);
1619 if (item.Focused && control.item_control.Focused) {
1620 Rectangle focus_rect = text_rect;
1621 if (control.FullRowSelect && control.View == View.Details) {
1623 foreach (ColumnHeader col in control.Columns)
1625 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
1628 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
1630 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
1637 public override Size ListViewCheckBoxSize {
1638 get { return new Size (16, 16); }
1641 public override int ListViewColumnHeaderHeight {
1645 public override int ListViewDefaultColumnWidth {
1649 public override int ListViewVerticalSpacing {
1653 public override int ListViewEmptyColumnWidth {
1657 public override int ListViewHorizontalSpacing {
1661 public override Size ListViewDefaultSize {
1662 get { return new Size (121, 97); }
1664 #endregion // ListView
1667 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1672 if (item.Visible == false) {
1678 if (item.Separator == true) {
1679 item.Height = SEPARATOR_HEIGHT / 2;
1684 if (item.MeasureEventDefined) {
1685 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1686 item.PerformMeasureItem (mi);
1687 item.Height = mi.ItemHeight;
1688 item.Width = mi.ItemWidth;
1692 size = dc.MeasureString (item.Text, MenuFont);
1693 item.Width = (int) size.Width;
1694 item.Height = (int) size.Height;
1697 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1698 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1699 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1700 item.Width += MENU_TAB_SPACE + (int) size.Width;
1703 item.Width += 4 + (MenuCheckSize.Width * 2);
1705 item.Width += MENU_BAR_ITEMS_SPACE;
1709 if (item.Height < MenuHeight)
1710 item.Height = MenuHeight;
1714 // Updates the menu rect and returns the height
1715 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1721 foreach (MenuItem item in menu.MenuItems) {
1723 CalcItemSize (dc, item, y, x, true);
1725 if (x + item.Width > width) {
1733 item.MenuBar = true;
1735 if (y + item.Height > menu.Height)
1736 menu.Height = item.Height + y;
1743 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1751 while (start < menu.MenuItems.Count) {
1754 for (i = start; i < menu.MenuItems.Count; i++) {
1755 MenuItem item = menu.MenuItems [i];
1757 if ((i != start) && (item.Break || item.BarBreak))
1760 CalcItemSize (dc, item, y, x, false);
1763 if (item.Width > max)
1767 // Replace the -1 by the menu width (separators)
1768 for (n = start; n < i; n++, start++)
1769 menu.MenuItems [n].Width = max;
1771 if (y > menu.Height)
1783 menu.Width += SM_CXBORDER;
1784 menu.Height += SM_CYBORDER;
1787 // Draws a menu bar in a window
1788 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1790 if (menu.Height == 0)
1791 CalcMenuBarSize (dc, menu, rect.Width);
1793 bool keynav = (menu as MainMenu).tracker.Navigating;
1794 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1795 string_format_menu_menubar_text.HotkeyPrefix = hp;
1796 string_format_menu_text.HotkeyPrefix = hp;
1798 rect.Height = menu.Height;
1799 dc.FillRectangle (SystemBrushes.Menu, rect);
1801 for (int i = 0; i < menu.MenuItems.Count; i++) {
1802 MenuItem item = menu.MenuItems [i];
1803 Rectangle item_rect = item.bounds;
1804 item_rect.X += rect.X;
1805 item_rect.Y += rect.Y;
1806 item.MenuHeight = menu.Height;
1807 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1811 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
1814 if (color.R == 0 && color.G == 0 && color.B == 0)
1815 bg_color = Color.White;
1817 bg_color = Color.Black;
1818 Bitmap bmp = new Bitmap (size.Width, size.Height);
1819 Graphics gr = Graphics.FromImage (bmp);
1820 Rectangle rect = new Rectangle (Point.Empty, size);
1821 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
1822 CPDrawMenuGlyph (gr, rect, glyph, color);
1823 bmp.MakeTransparent (bg_color);
1828 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1830 StringFormat string_format;
1831 Rectangle rect_text = e.Bounds;
1833 if (item.Visible == false)
1837 string_format = string_format_menu_menubar_text;
1839 string_format = string_format_menu_text;
1841 if (item.Separator == true) {
1842 e.Graphics.DrawLine (SystemPens.ControlDark,
1843 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1845 e.Graphics.DrawLine (SystemPens.ControlLight,
1846 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1852 rect_text.X += MenuCheckSize.Width;
1854 if (item.BarBreak) { /* Draw vertical break bar*/
1855 Rectangle rect = e.Bounds;
1858 rect.Height = item.MenuHeight - 6;
1860 e.Graphics.DrawLine (SystemPens.ControlDark,
1861 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1863 e.Graphics.DrawLine (SystemPens.ControlLight,
1864 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1869 Brush brush_text = null;
1870 Brush brush_back = null;
1872 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
1873 color_text = ColorHighlightText;
1874 color_back = ColorHighlight;
1875 brush_text = SystemBrushes.HighlightText;
1876 brush_back = SystemBrushes.Highlight;
1878 color_text = ColorMenuText;
1879 color_back = ColorMenu;
1880 brush_text = ResPool.GetSolidBrush (ColorMenuText);
1881 brush_back = SystemBrushes.Menu;
1884 /* Draw background */
1885 Rectangle rect_back = e.Bounds;
1887 rect_back.Width -=2;
1889 e.Graphics.FillRectangle (brush_back, rect_back);
1892 e.Graphics.DrawString (item.Text, e.Font,
1894 rect_text, string_format);
1896 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1897 string str = item.GetShortCutText ();
1898 Rectangle rect = rect_text;
1900 rect.Width -= item.XTab;
1902 e.Graphics.DrawString (str, e.Font, brush_text,
1903 rect, string_format_menu_shortcut);
1907 Border3DStyle border_style = Border3DStyle.Adjust;
1908 if ((item.Status & DrawItemState.HotLight) != 0)
1909 border_style = Border3DStyle.RaisedInner;
1910 else if ((item.Status & DrawItemState.Selected) != 0)
1911 border_style = Border3DStyle.SunkenOuter;
1913 if (border_style != Border3DStyle.Adjust)
1914 CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
1917 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
1918 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
1919 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
1923 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
1927 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
1929 int cx = MenuCheckSize.Width;
1930 int cy = MenuCheckSize.Height;
1931 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
1934 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1935 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1937 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1938 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1944 /* Draw checked or radio */
1945 if (item.MenuBar == false && item.Checked) {
1947 Rectangle area = e.Bounds;
1948 int cx = MenuCheckSize.Width;
1949 int cy = MenuCheckSize.Height;
1950 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
1952 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1958 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
1961 dc.FillRectangle (SystemBrushes.Menu, cliparea);
1963 Pen pen_cht = SystemPens.HighlightText;
1964 Pen pen_ccd = SystemPens.ControlDark;
1965 Pen pen_ccdd = SystemPens.ControlDarkDark;
1967 /* Draw menu borders */
1968 dc.DrawLine (pen_cht,
1969 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1971 dc.DrawLine (pen_cht,
1972 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1974 dc.DrawLine (pen_ccd,
1975 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1977 dc.DrawLine (pen_ccdd,
1978 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1980 dc.DrawLine (pen_ccd,
1981 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1983 dc.DrawLine (pen_ccdd,
1984 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1986 for (int i = 0; i < menu.MenuItems.Count; i++)
1987 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
1988 MenuItem item = menu.MenuItems [i];
1989 item.MenuHeight = menu.Height;
1990 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
1991 item.bounds, i, item.Status));
1997 #region MonthCalendar
1999 // draw the month calendar
2000 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2002 Rectangle client_rectangle = mc.ClientRectangle;
2003 Size month_size = mc.SingleMonthSize;
2004 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2005 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2006 Size date_cell_size = (Size)((object)mc.date_cell_size);
2008 // draw the singlecalendars
2011 // adjust for the position of the specific month
2012 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2016 y_offset += month_size.Height + calendar_spacing.Height;
2018 // now adjust for x position
2019 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2023 x_offset += month_size.Width + calendar_spacing.Width;
2030 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2031 if (month_rect.IntersectsWith (clip_rectangle)) {
2043 Rectangle bottom_rect = new Rectangle (
2045 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2046 client_rectangle.Width,
2047 date_cell_size.Height + 2);
2048 // draw the today date if it's set
2049 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2051 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
2053 int today_offset = 5;
2054 if (mc.ShowTodayCircle)
2056 Rectangle today_circle_rect = new Rectangle (
2057 client_rectangle.X + 5,
2058 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2059 date_cell_size.Width,
2060 date_cell_size.Height);
2061 DrawTodayCircle (dc, today_circle_rect);
2062 today_offset += date_cell_size.Width + 5;
2064 // draw today's date
2065 StringFormat text_format = new StringFormat();
2066 text_format.LineAlignment = StringAlignment.Center;
2067 text_format.Alignment = StringAlignment.Near;
2068 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2069 Rectangle today_rect = new Rectangle (
2070 today_offset + client_rectangle.X,
2071 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2072 Math.Max(client_rectangle.Width - today_offset, 0),
2073 date_cell_size.Height);
2074 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
2075 text_format.Dispose ();
2076 bold_font.Dispose ();
2080 // finally paint the borders of the calendars as required
2081 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2082 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2083 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
2084 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2085 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
2087 Rectangle rect = new Rectangle (
2088 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2090 calendar_spacing.Width,
2091 client_rectangle.Height);
2092 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2093 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2097 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2098 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2099 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
2100 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2101 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
2103 Rectangle rect = new Rectangle (
2105 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2106 client_rectangle.Width,
2107 calendar_spacing.Height);
2108 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2109 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2114 // draw the drop down border if need
2115 if (mc.owner != null) {
2116 Rectangle bounds = mc.ClientRectangle;
2117 if (clip_rectangle.Contains (mc.Location)) {
2118 // find out if top or left line to draw
2119 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2121 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2123 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2124 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2127 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2128 // find out if bottom or right line to draw
2129 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2130 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2132 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2133 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2139 // darws a single part of the month calendar (with one month)
2140 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2142 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2143 Size title_size = (Size)((object)mc.title_size);
2144 Size date_cell_size = (Size)((object)mc.date_cell_size);
2145 DateTime current_month = (DateTime)((object)mc.current_month);
2147 // set up some standard string formating variables
2148 StringFormat text_format = new StringFormat();
2149 text_format.LineAlignment = StringAlignment.Center;
2150 text_format.Alignment = StringAlignment.Center;
2153 // draw the title back ground
2154 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2155 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2156 if (title_rect.IntersectsWith (clip_rectangle)) {
2157 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2159 string title_text = this_month.ToString ("MMMM yyyy");
2160 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2162 // draw previous and next buttons if it's time
2163 if (row == 0 && col == 0)
2165 // draw previous button
2166 DrawMonthCalendarButton (
2172 (System.Drawing.Size)((object)mc.button_size),
2175 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2178 DrawMonthCalendarButton (
2184 (System.Drawing.Size)((object)mc.button_size),
2189 // set the week offset and draw week nums if needed
2190 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2191 Rectangle day_name_rect = new Rectangle(
2193 rectangle.Y + title_size.Height,
2194 (7 + col_offset) * date_cell_size.Width,
2195 date_cell_size.Height);
2196 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2197 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
2198 // draw the day names
2199 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2200 for (int i=0; i < 7; i++)
2202 int position = i - (int) first_day_of_week;
2205 position = 7 + position;
2208 Rectangle day_rect = new Rectangle(
2209 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2211 date_cell_size.Width,
2212 date_cell_size.Height);
2213 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2216 // draw the vertical divider
2217 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2219 ResPool.GetPen (mc.ForeColor),
2220 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2221 rectangle.Y + vert_divider_y,
2222 rectangle.Right - mc.divider_line_offset,
2223 rectangle.Y + vert_divider_y);
2227 // draw the actual date items in the grid (including the week numbers)
2228 Rectangle date_rect = new Rectangle (
2230 rectangle.Y + title_size.Height + date_cell_size.Height,
2231 date_cell_size.Width,
2232 date_cell_size.Height);
2233 int month_row_count = 0;
2234 bool draw_week_num_divider = false;
2235 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2236 for (int i=0; i < 6; i++)
2238 // establish if this row is in our clip_area
2239 Rectangle row_rect = new Rectangle (
2241 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2242 date_cell_size.Width * 7,
2243 date_cell_size.Height);
2244 if (mc.ShowWeekNumbers) {
2245 row_rect.Width += date_cell_size.Width;
2248 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2250 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
2252 // establish if this is a valid week to draw
2253 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2254 month_row_count = i;
2257 // draw the week number if required
2258 if (mc.ShowWeekNumbers && month_row_count == i) {
2259 if (!draw_week_num_divider) {
2260 draw_week_num_divider = draw_row;
2262 // get the week for this row
2263 int week = mc.GetWeekOfYear (current_date);
2269 ResPool.GetSolidBrush (mc.TitleBackColor),
2273 date_rect.Offset(date_cell_size.Width, 0);
2276 // only draw the days if we have to
2277 if(month_row_count == i) {
2278 for (int j=0; j < 7; j++)
2281 DrawMonthCalendarDate (
2292 current_date = current_date.AddDays(1);
2293 date_rect.Offset(date_cell_size.Width, 0);
2296 // shift the rectangle down one row
2297 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2298 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2302 // month_row_count is zero based, so add one
2305 // draw week numbers if required
2306 if (draw_week_num_divider) {
2309 ResPool.GetPen (mc.ForeColor),
2310 rectangle.X + date_cell_size.Width - 1,
2311 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2312 rectangle.X + date_cell_size.Width - 1,
2313 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2315 text_format.Dispose ();
2318 // draws the pervious or next button
2319 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2321 bool is_clicked = false;
2322 Rectangle button_rect;
2323 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2324 Point[] arrow_path = new Point[3];
2325 // prepare the button
2328 is_clicked = mc.is_previous_clicked;
2329 button_rect = new Rectangle (
2330 rectangle.X + 1 + x_offset,
2331 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2332 Math.Max(button_size.Width - 1, 0),
2333 Math.Max(button_size.Height - 1, 0));
2334 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2335 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2337 arrow_rect.Offset(1,1);
2339 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2340 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2341 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2345 is_clicked = mc.is_next_clicked;
2346 button_rect = new Rectangle (
2347 rectangle.Right - 1 - x_offset - button_size.Width,
2348 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2349 Math.Max(button_size.Width - 1, 0),
2350 Math.Max(button_size.Height - 1, 0));
2351 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2352 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2354 arrow_rect.Offset(1,1);
2356 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2357 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2358 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2361 // fill the background
2362 dc.FillRectangle (SystemBrushes.Control, button_rect);
2365 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2368 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
2371 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2375 // draws one day in the calendar grid
2376 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2377 Color date_color = mc.ForeColor;
2378 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2380 // find out if we are the lead of the first calendar or the trail of the last calendar
2381 if (date.Year != month.Year || date.Month != month.Month) {
2382 DateTime check_date = month.AddMonths (-1);
2383 // check if it's the month before
2384 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2385 date_color = mc.TrailingForeColor;
2387 // check if it's the month after
2388 check_date = month.AddMonths (1);
2389 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2390 date_color = mc.TrailingForeColor;
2396 date_color = mc.ForeColor;
2400 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2401 // see if the date is in the start of selection
2402 date_color = mc.BackColor;
2403 // draw the left hand of the back ground
2404 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2405 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2406 } else if (date == mc.SelectionStart) {
2407 // see if the date is in the start of selection
2408 date_color = mc.BackColor;
2409 // draw the left hand of the back ground
2410 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2411 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2412 // fill the other side as a straight rect
2413 if (date < mc.SelectionEnd)
2415 // use rectangle instead of rectangle to go all the way to edge of rect
2416 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2417 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2418 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2420 } else if (date == mc.SelectionEnd) {
2421 // see if it is the end of selection
2422 date_color = mc.BackColor;
2423 // draw the left hand of the back ground
2424 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2425 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2426 // fill the other side as a straight rect
2427 if (date > mc.SelectionStart) {
2428 selection_rect.X = rectangle.X;
2429 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2430 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2432 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2433 // now see if it's in the middle
2434 date_color = mc.BackColor;
2435 // draw the left hand of the back ground
2436 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2437 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2440 // set up some standard string formating variables
2441 StringFormat text_format = new StringFormat();
2442 text_format.LineAlignment = StringAlignment.Center;
2443 text_format.Alignment = StringAlignment.Center;
2446 // establish if it's a bolded font
2448 if (mc.IsBoldedDate (date)) {
2449 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2454 // just draw the date now
2455 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2457 // today circle if needed
2458 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2459 DrawTodayCircle (dc, interior);
2462 // draw the selection grid
2463 if (mc.is_date_clicked && mc.clicked_date == date) {
2464 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
2465 dc.DrawRectangle (pen, interior);
2467 text_format.Dispose ();
2470 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2471 Color circle_color = Color.FromArgb (248, 0, 0);
2472 // draw the left hand of the circle
2473 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2474 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2475 Point [] curve_points = new Point [3];
2476 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2477 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2478 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2480 Pen pen = ResPool.GetSizedPen(circle_color, 2);
2481 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2482 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2483 dc.DrawCurve (pen, curve_points);
2484 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2487 #endregion // MonthCalendar
2490 public override Size PanelDefaultSize {
2492 return new Size (200, 100);
2498 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2499 Rectangle client = pb.ClientRectangle;
2501 // FIXME - instead of drawing the whole picturebox every time
2502 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2503 // Also, we only need a background fill where no image goes
2504 if (pb.Image != null) {
2505 switch (pb.SizeMode) {
2506 case PictureBoxSizeMode.StretchImage:
2507 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2510 case PictureBoxSizeMode.CenterImage:
2511 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2512 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2515 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2517 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2524 // We only get here if no image is set. At least paint the background
2525 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2528 public override Size PictureBoxDefaultSize {
2530 return new Size (100, 50);
2533 #endregion // PictureBox
2536 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2538 Rectangle block_rect;
2539 Rectangle client_area = ctrl.client_area;
2540 int space_betweenblocks = 2;
2545 block_width = (client_area.Height * 2 ) / 3;
2546 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2547 increment = block_width + space_betweenblocks;
2550 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
2553 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2554 while ((block_rect.X - client_area.X) < barpos_pixels) {
2556 if (clip_rect.IntersectsWith (block_rect) == true) {
2557 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2560 block_rect.X += increment;
2564 public override Size ProgressBarDefaultSize {
2566 return new Size (100, 23);
2570 #endregion // ProgressBar
2573 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2574 StringFormat text_format;
2575 Rectangle client_rectangle;
2576 Rectangle text_rectangle;
2577 Rectangle radiobutton_rectangle;
2578 int radiobutton_size = 13;
2579 int radiobutton_space = 4;
2581 client_rectangle = radio_button.ClientRectangle;
2582 text_rectangle = client_rectangle;
2583 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2585 text_format = new StringFormat();
2586 text_format.Alignment = StringAlignment.Near;
2587 text_format.LineAlignment = StringAlignment.Center;
2588 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2590 /* Calculate the position of text and checkbox rectangle */
2591 if (radio_button.appearance!=Appearance.Button) {
2592 switch(radio_button.radiobutton_alignment) {
2593 case ContentAlignment.BottomCenter: {
2594 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2595 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2596 text_rectangle.X=client_rectangle.X;
2597 text_rectangle.Width=client_rectangle.Width;
2598 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2602 case ContentAlignment.BottomLeft: {
2603 radiobutton_rectangle.X=client_rectangle.Left;
2604 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2605 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2606 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2610 case ContentAlignment.BottomRight: {
2611 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2612 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2613 text_rectangle.X=client_rectangle.X;
2614 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2618 case ContentAlignment.MiddleCenter: {
2619 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2620 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2621 text_rectangle.X=client_rectangle.X;
2622 text_rectangle.Width=client_rectangle.Width;
2627 case ContentAlignment.MiddleLeft: {
2628 radiobutton_rectangle.X=client_rectangle.Left;
2629 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2630 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2631 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2635 case ContentAlignment.MiddleRight: {
2636 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2637 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2638 text_rectangle.X=client_rectangle.X;
2639 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2643 case ContentAlignment.TopCenter: {
2644 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2645 radiobutton_rectangle.Y=client_rectangle.Top;
2646 text_rectangle.X=client_rectangle.X;
2647 text_rectangle.Y=radiobutton_size+radiobutton_space;
2648 text_rectangle.Width=client_rectangle.Width;
2649 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2653 case ContentAlignment.TopLeft: {
2654 radiobutton_rectangle.X=client_rectangle.Left;
2655 radiobutton_rectangle.Y=client_rectangle.Top;
2656 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2657 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2661 case ContentAlignment.TopRight: {
2662 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2663 radiobutton_rectangle.Y=client_rectangle.Top;
2664 text_rectangle.X=client_rectangle.X;
2665 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2670 text_rectangle.X=client_rectangle.X;
2671 text_rectangle.Width=client_rectangle.Width;
2674 /* Set the horizontal alignment of our text */
2675 switch(radio_button.text_alignment) {
2676 case ContentAlignment.BottomLeft:
2677 case ContentAlignment.MiddleLeft:
2678 case ContentAlignment.TopLeft: {
2679 text_format.Alignment=StringAlignment.Near;
2683 case ContentAlignment.BottomCenter:
2684 case ContentAlignment.MiddleCenter:
2685 case ContentAlignment.TopCenter: {
2686 text_format.Alignment=StringAlignment.Center;
2690 case ContentAlignment.BottomRight:
2691 case ContentAlignment.MiddleRight:
2692 case ContentAlignment.TopRight: {
2693 text_format.Alignment=StringAlignment.Far;
2698 /* Set the vertical alignment of our text */
2699 switch(radio_button.text_alignment) {
2700 case ContentAlignment.TopLeft:
2701 case ContentAlignment.TopCenter:
2702 case ContentAlignment.TopRight: {
2703 text_format.LineAlignment=StringAlignment.Near;
2707 case ContentAlignment.BottomLeft:
2708 case ContentAlignment.BottomCenter:
2709 case ContentAlignment.BottomRight: {
2710 text_format.LineAlignment=StringAlignment.Far;
2714 case ContentAlignment.MiddleLeft:
2715 case ContentAlignment.MiddleCenter:
2716 case ContentAlignment.MiddleRight: {
2717 text_format.LineAlignment=StringAlignment.Center;
2722 ButtonState state = ButtonState.Normal;
2723 if (radio_button.FlatStyle == FlatStyle.Flat) {
2724 state |= ButtonState.Flat;
2727 if (radio_button.Checked) {
2728 state |= ButtonState.Checked;
2731 if (!radio_button.Enabled) {
2732 state |= ButtonState.Inactive;
2736 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2738 if ((radio_button.image != null) || (radio_button.image_list != null))
2739 ButtonBase_DrawImage(radio_button, dc);
2741 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2743 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2745 text_format.Dispose ();
2748 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2750 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
2752 if (radio_button.appearance==Appearance.Button) {
2753 ButtonBase_DrawButton (radio_button, dc);
2755 // establish if we are rendering a flat style of some sort
2756 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2757 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2759 CPDrawRadioButton(dc, radiobutton_rectangle, state);
2764 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2766 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
2767 text_format, radio_button.Appearance, radio_button.Checked);
2770 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2772 // do nothing here. maybe an other theme needs it
2775 // renders a radio button with the Flat and Popup FlatStyle
2776 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2780 if (radio_button.Enabled) {
2782 // draw the outer flatstyle arcs
2783 if (radio_button.FlatStyle == FlatStyle.Flat) {
2784 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
2786 // fill in the area depending on whether or not the mouse is hovering
2787 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
2788 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2790 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2793 // must be a popup radio button
2795 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
2797 if (radio_button.is_entered || radio_button.Capture) {
2798 // draw the popup 3d button knob
2799 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2801 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
2802 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
2805 // just draw lighter flatstyle outer circle
2806 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2811 // fill control background color regardless of actual backcolor
2812 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2813 // draw the ark as control dark
2814 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2818 if (radio_button.Checked) {
2819 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2821 Pen dot_pen = SystemPens.ControlDarkDark;
2822 Brush dot_brush = SystemBrushes.ControlDarkDark;
2824 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
2825 dot_pen = SystemPens.ControlDark;
2826 dot_brush = SystemBrushes.ControlDark;
2829 if (rectangle.Height > 13) {
2830 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
2832 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
2833 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
2835 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
2836 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
2838 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
2839 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
2844 public override Size RadioButtonDefaultSize {
2846 return new Size (104,24);
2849 #endregion // RadioButton
2852 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2854 int scrollbutton_width = bar.scrollbutton_width;
2855 int scrollbutton_height = bar.scrollbutton_height;
2856 Rectangle first_arrow_area;
2857 Rectangle second_arrow_area;
2858 Rectangle thumb_pos;
2860 thumb_pos = bar.ThumbPos;
2863 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2864 bar.FirstArrowArea = first_arrow_area;
2866 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2867 bar.SecondArrowArea = second_arrow_area;
2869 thumb_pos.Width = bar.Width;
2870 bar.ThumbPos = thumb_pos;
2873 if (clip.IntersectsWith (first_arrow_area))
2874 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2875 if (clip.IntersectsWith (second_arrow_area))
2876 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2879 switch (bar.thumb_moving) {
2880 case ScrollBar.ThumbMoving.None: {
2881 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
2884 case ScrollBar.ThumbMoving.Forward: {
2885 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
2889 case ScrollBar.ThumbMoving.Backwards: {
2890 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
2898 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2899 bar.FirstArrowArea = first_arrow_area;
2901 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2902 bar.SecondArrowArea = second_arrow_area;
2904 thumb_pos.Height = bar.Height;
2905 bar.ThumbPos = thumb_pos;
2908 if (clip.IntersectsWith (first_arrow_area))
2909 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2910 if (clip.IntersectsWith (second_arrow_area))
2911 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2914 switch (bar.thumb_moving) {
2915 case ScrollBar.ThumbMoving.None: {
2916 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
2920 case ScrollBar.ThumbMoving.Forward: {
2921 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
2925 case ScrollBar.ThumbMoving.Backwards: {
2926 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
2933 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
2936 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
2938 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
2939 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
2942 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
2944 Rectangle r = new Rectangle( 0,
2945 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
2946 Rectangle intersect = Rectangle.Intersect( clip, r );
2948 if ( intersect != Rectangle.Empty )
2950 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
2951 dc.FillRectangle( h, intersect );
2955 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2957 Rectangle r = new Rectangle( 0, scrollbutton_height,
2958 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2959 Rectangle intersect = Rectangle.Intersect( clip, r );
2961 if ( intersect != Rectangle.Empty )
2962 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
2965 r.Y = thumb_pos.Y + thumb_pos.Height;
2966 r.Width = bar.ClientRectangle.Width;
2967 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2969 intersect = Rectangle.Intersect( clip, r );
2970 if ( intersect != Rectangle.Empty )
2971 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2974 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2976 Rectangle r = new Rectangle( 0, scrollbutton_height,
2977 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
2978 Rectangle intersect = Rectangle.Intersect( clip, r );
2980 if ( intersect != Rectangle.Empty )
2981 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
2984 r.Y = thumb_pos.Y + thumb_pos.Height;
2985 r.Width = bar.ClientRectangle.Width;
2986 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
2988 intersect = Rectangle.Intersect( clip, r );
2989 if ( intersect != Rectangle.Empty )
2990 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
2993 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
2995 Rectangle r = new Rectangle( scrollbutton_width,
2996 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
2997 Rectangle intersect = Rectangle.Intersect( clip, r );
2999 if ( intersect != Rectangle.Empty )
3000 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3003 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3005 Rectangle r = new Rectangle( scrollbutton_width, 0,
3006 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3007 Rectangle intersect = Rectangle.Intersect( clip, r );
3009 if ( intersect != Rectangle.Empty )
3010 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3012 r.X = thumb_pos.X + thumb_pos.Width;
3014 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3015 r.Height = bar.ClientRectangle.Height;
3017 intersect = Rectangle.Intersect( clip, r );
3018 if ( intersect != Rectangle.Empty )
3019 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3022 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3024 Rectangle r = new Rectangle( scrollbutton_width, 0,
3025 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3026 Rectangle intersect = Rectangle.Intersect( clip, r );
3028 if ( intersect != Rectangle.Empty )
3029 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3031 r.X = thumb_pos.X + thumb_pos.Width;
3033 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3034 r.Height = bar.ClientRectangle.Height;
3036 intersect = Rectangle.Intersect( clip, r );
3037 if ( intersect != Rectangle.Empty )
3038 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3041 public override int ScrollBarButtonSize {
3044 #endregion // ScrollBar
3047 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3048 Rectangle area = sb.ClientRectangle;
3049 int horz_border = 2;
3050 int vert_border = 2;
3052 bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
3054 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
3055 dc.FillRectangle (brush, clip);
3057 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3058 string text = sb.Text;
3059 StringFormat string_format = new StringFormat ();
3060 string_format.Trimming = StringTrimming.Character;
3061 string_format.FormatFlags = StringFormatFlags.NoWrap;
3063 if (text [0] == '\t') {
3064 string_format.Alignment = StringAlignment.Center;
3065 text = text.Substring (1);
3066 if (text [0] == '\t') {
3067 string_format.Alignment = StringAlignment.Far;
3068 text = text.Substring (1);
3072 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3073 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3074 string_format.Dispose ();
3075 } else if (sb.ShowPanels) {
3076 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
3077 int prev_x = area.X + horz_border;
3078 int y = area.Y + vert_border;
3079 for (int i = 0; i < sb.Panels.Count; i++) {
3080 Rectangle pr = new Rectangle (prev_x, y,
3081 sb.Panels [i].Width, area.Height);
3082 prev_x += pr.Width + StatusBarHorzGapWidth;
3083 if (pr.IntersectsWith (clip))
3084 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3088 if (sb.SizingGrip) {
3089 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
3090 CPDrawSizeGrip (dc, ColorControl, area);
3096 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3097 Brush br_forecolor, StatusBarPanel panel) {
3098 int border_size = 3; // this is actually const, even if the border style is none
3099 int icon_width = 16;
3101 area.Height -= border_size;
3103 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3104 Border3DStyle border_style = Border3DStyle.SunkenOuter;
3105 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3106 border_style = Border3DStyle.RaisedInner;
3108 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
3111 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3112 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3113 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3114 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3115 panel.Parent.OnDrawItemInternal (e);
3119 if (panel.Text == String.Empty)
3122 string text = panel.Text;
3123 StringFormat string_format = new StringFormat ();
3124 string_format.Trimming = StringTrimming.Character;
3125 string_format.FormatFlags = StringFormatFlags.NoWrap;
3128 if (text [0] == '\t') {
3129 string_format.Alignment = StringAlignment.Center;
3130 text = text.Substring (1);
3131 if (text [0] == '\t') {
3132 string_format.Alignment = StringAlignment.Far;
3133 text = text.Substring (1);
3137 Rectangle string_rect = Rectangle.Empty;
3141 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
3143 switch (panel.Alignment) {
3144 case HorizontalAlignment.Right:
3145 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3146 x = area.Right - len - 4;
3147 string_rect = new Rectangle (x, y,
3148 area.Right - x - border_size,
3149 area.Bottom - y - border_size);
3150 if (panel.Icon != null) {
3151 icon_x = x - icon_width - 2;
3154 case HorizontalAlignment.Center:
3155 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3156 x = (panel.Width / 2) + (len / 2);
3157 string_rect = new Rectangle (x, y,
3158 area.Right - x - border_size,
3159 area.Bottom - y - border_size);
3161 if (panel.Icon != null) {
3162 icon_x = x - icon_width - 2;
3168 int left = area.Left + border_size;;
3169 if (panel.Icon != null) {
3170 icon_x = area.Left + 2;
3171 left = icon_x + icon_width + 2;
3175 string_rect = new Rectangle (x, y,
3176 area.Right - x - border_size,
3177 area.Bottom - y - border_size);
3181 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
3183 if (panel.Icon != null) {
3184 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
3188 public override int StatusBarSizeGripWidth {
3192 public override int StatusBarHorzGapWidth {
3196 public override Size StatusBarDefaultSize {
3198 return new Size (100, 22);
3201 #endregion // StatusBar
3203 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3205 // Do we need to fill the back color? It can't be changed...
3206 Brush brush = tab.BackColor.ToArgb () == DefaultControlBackColor.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (tab.BackColor);
3207 dc.FillRectangle (brush, area);
3208 Rectangle panel_rect = GetTabPanelRectExt (tab);
3210 if (tab.Appearance == TabAppearance.Normal) {
3211 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3212 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3215 if (tab.Alignment == TabAlignment.Top) {
3216 for (int r = tab.TabPages.Count; r > 0; r--) {
3217 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3218 if (i == tab.SelectedIndex)
3220 if (r != tab.TabPages [i].Row)
3222 Rectangle rect = tab.GetTabRect (i);
3223 if (!rect.IntersectsWith (area))
3225 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3229 for (int r = 0; r < tab.TabPages.Count; r++) {
3230 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3231 if (i == tab.SelectedIndex)
3233 if (r != tab.TabPages [i].Row)
3235 Rectangle rect = tab.GetTabRect (i);
3236 if (!rect.IntersectsWith (area))
3238 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3243 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3244 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3245 if (rect.IntersectsWith (area))
3246 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3249 if (tab.ShowSlider) {
3250 Rectangle right = GetTabControlRightScrollRect (tab);
3251 Rectangle left = GetTabControlLeftScrollRect (tab);
3252 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3253 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3257 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3259 switch (tab.Alignment) {
3260 case TabAlignment.Top:
3261 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3263 Rectangle panel_rect = GetTabPanelRectExt (tab);
3264 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3268 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3270 switch (tab.Alignment) {
3271 case TabAlignment.Top:
3272 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3274 Rectangle panel_rect = GetTabPanelRectExt (tab);
3275 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3279 public override Size TabControlDefaultItemSize {
3280 get { return new Size (42, 21); }
3283 public override Point TabControlDefaultPadding {
3284 get { return new Point (6, 3); }
3287 public override int TabControlMinimumTabWidth {
3291 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3293 Rectangle ext = GetTabPanelRectExt (tab);
3294 // Account for border size
3295 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3298 public override Size TabControlGetSpacing (TabControl tab) {
3299 switch (tab.Appearance) {
3300 case TabAppearance.Normal:
3301 return new Size (1, -2);
3302 case TabAppearance.Buttons:
3303 return new Size (3, 3);
3304 case TabAppearance.FlatButtons:
3305 return new Size (9, 3);
3307 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3311 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3313 // Offset the tab from the top corner
3314 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3315 tab.ClientRectangle.Y,
3316 tab.ClientRectangle.Width - 2,
3317 tab.ClientRectangle.Height - 1);
3319 if (tab.TabCount == 0)
3322 int spacing = TabControlGetSpacing (tab).Height;
3323 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3325 switch (tab.Alignment) {
3326 case TabAlignment.Left:
3328 res.Width -= offset;
3330 case TabAlignment.Right:
3331 res.Width -= offset;
3333 case TabAlignment.Top:
3335 res.Height -= offset;
3337 case TabAlignment.Bottom:
3338 res.Height -= offset;
3345 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3347 int FlatButtonSpacing = 8;
3349 int res = bounds.Width;
3353 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3355 StringFormat string_format = new StringFormat ();
3356 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3357 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3360 if (tab.Appearance == TabAppearance.FlatButtons) {
3361 int width = bounds.Width;
3362 bounds.Width += (FlatButtonSpacing - 2);
3364 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3365 bounds.Width = width;
3369 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3370 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3371 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3374 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3377 string_format.Alignment = StringAlignment.Center;
3378 string_format.LineAlignment = StringAlignment.Center;
3379 string_format.FormatFlags = StringFormatFlags.NoWrap;
3381 CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
3383 Pen light = ResPool.GetPen (cpcolor.LightLight);
3385 switch (tab.Alignment) {
3387 case TabAlignment.Top:
3389 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3391 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3392 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3393 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3395 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3396 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3397 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3399 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3401 string_format.Alignment = StringAlignment.Center;
3402 string_format.LineAlignment = StringAlignment.Center;
3403 string_format.FormatFlags = StringFormatFlags.NoWrap;
3407 case TabAlignment.Bottom:
3409 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3411 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3412 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3414 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3415 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3417 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3418 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3419 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3421 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3423 string_format.Alignment = StringAlignment.Center;
3424 string_format.LineAlignment = StringAlignment.Center;
3425 string_format.FormatFlags = StringFormatFlags.NoWrap;
3429 case TabAlignment.Left:
3431 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3433 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3434 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3435 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3437 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3439 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3440 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3442 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3444 string_format.Alignment = StringAlignment.Center;
3445 string_format.LineAlignment = StringAlignment.Center;
3446 string_format.FormatFlags = StringFormatFlags.NoWrap;
3447 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3452 // TabAlignment.Right
3454 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3456 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3457 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3459 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3460 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3462 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3463 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3465 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3467 string_format.Alignment = StringAlignment.Center;
3468 string_format.LineAlignment = StringAlignment.Center;
3469 string_format.FormatFlags = StringFormatFlags.NoWrap;
3470 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3476 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3477 if (tab.Alignment == TabAlignment.Left) {
3478 int wo = interior.Width / 2;
3479 int ho = interior.Height / 2;
3480 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3481 dc.RotateTransform (180);
3482 dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
3483 dc.ResetTransform ();
3485 dc.DrawString (page.Text, page.Font,
3486 SystemBrushes.ControlText,
3487 interior, string_format);
3489 } else if (page.Text != null) {
3490 DrawItemState state = DrawItemState.None;
3491 if (page == tab.SelectedTab)
3492 state |= DrawItemState.Selected;
3493 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3494 tab.Font, bounds, tab.IndexForTabPage (page),
3495 state, page.ForeColor, page.BackColor);
3496 tab.OnDrawItemInternal (e);
3500 if (page.parent.Focused && is_selected) {
3501 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3508 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
3510 StringFormat format = new StringFormat ();
3511 format.Trimming = StringTrimming.EllipsisWord;
3512 format.LineAlignment = StringAlignment.Center;
3513 if (control.TextAlign == ToolBarTextAlign.Underneath)
3514 format.Alignment = StringAlignment.Center;
3516 format.Alignment = StringAlignment.Near;
3518 if (control is PropertyGrid.PropertyToolBar) {
3519 dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
3521 if (clip_rectangle.X == 0) {
3522 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
3525 if (clip_rectangle.Y < 2) {
3526 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3529 if (clip_rectangle.Bottom == control.Bottom) {
3530 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
3533 if (clip_rectangle.Right == control.Right) {
3534 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
3536 } else if (control.Divider) {
3538 if (control.Appearance == ToolBarAppearance.Flat &&
3539 control.Parent != null && control.Parent.BackgroundImage != null) {
3540 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3541 dc.FillRectangle (b, clip_rectangle);
3544 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
3547 if (clip_rectangle.Y < 2) {
3548 if (clip_rectangle.Y < 1) {
3549 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
3551 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3554 if (control.Appearance == ToolBarAppearance.Flat &&
3555 control.Parent != null && control.Parent.BackgroundImage != null) {
3556 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile)) {
3557 dc.FillRectangle (b, clip_rectangle);
3562 foreach (ToolBarButton button in control.Buttons)
3563 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
3564 DrawToolBarButton (dc, control, button, format);
3569 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3571 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
3573 DrawToolBarButtonBorder (dc, button, is_flat);
3575 switch (button.Style) {
3576 case ToolBarButtonStyle.DropDownButton:
3577 if (control.DropDownArrows)
3578 DrawToolBarDropDownArrow (dc, button, is_flat);
3579 DrawToolBarButtonContents (dc, control, button, format);
3582 case ToolBarButtonStyle.Separator:
3584 DrawToolBarSeparator (dc, button);
3587 case ToolBarButtonStyle.ToggleButton:
3588 DrawToolBarToggleButtonBackground (dc, button);
3589 DrawToolBarButtonContents (dc, control, button, format);
3593 DrawToolBarButtonContents (dc, control, button, format);
3598 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
3600 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
3602 if (button.Style == ToolBarButtonStyle.Separator)
3605 Border3DStyle style;
3608 if (button.Pushed || button.Pressed)
3609 style = Border3DStyle.SunkenOuter;
3610 else if (button.Hilight)
3611 style = Border3DStyle.RaisedInner;
3616 if (button.Pushed || button.Pressed)
3617 style = Border3DStyle.Sunken;
3619 style = Border3DStyle.Raised;
3622 CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
3625 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
3627 Rectangle area = button.Rectangle;
3628 int offset = (int) SystemPens.Control.Width + 1;
3629 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
3630 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
3633 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
3635 Rectangle area = button.Rectangle;
3636 area.X += ToolBarImageGripWidth;
3637 area.Y += ToolBarImageGripWidth;
3638 area.Width -= 2 * ToolBarImageGripWidth;
3639 area.Height -= 2 * ToolBarImageGripWidth;
3642 dc.FillRectangle (SystemBrushes.ControlLightLight, area);
3643 else if (button.PartialPush)
3644 dc.FillRectangle (SystemBrushes.ControlLight, area);
3646 dc.FillRectangle (SystemBrushes.Control, area);
3649 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
3651 Rectangle rect = button.Rectangle;
3652 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
3653 rect.Width = ToolBarDropDownWidth;
3655 if (button.dd_pressed) {
3656 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
3657 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
3658 } else if (button.Pushed || button.Pressed)
3659 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
3662 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
3664 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3666 PointF [] vertices = new PointF [3];
3667 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
3668 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3669 vertices [0].Y = ddCenter.Y;
3670 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3671 vertices [1].Y = ddCenter.Y;
3672 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3673 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
3674 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3677 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3679 if (button.Image != null) {
3680 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
3681 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
3683 dc.DrawImage (button.Image, x, y);
3685 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
3689 dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, button.TextRectangle, format);
3691 CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, button.TextRectangle, format);
3694 // Grip width for the ToolBar
3695 public override int ToolBarGripWidth {
3699 // Grip width for the Image on the ToolBarButton
3700 public override int ToolBarImageGripWidth {
3704 // width of the separator
3705 public override int ToolBarSeparatorWidth {
3709 // width of the dropdown arrow rect
3710 public override int ToolBarDropDownWidth {
3714 // width for the dropdown arrow on the ToolBarButton
3715 public override int ToolBarDropDownArrowWidth {
3719 // height for the dropdown arrow on the ToolBarButton
3720 public override int ToolBarDropDownArrowHeight {
3724 public override Size ToolBarDefaultSize {
3726 return new Size (100, 42);
3729 #endregion // ToolBar
3732 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3733 dc.FillRectangle(SystemBrushes.Info, control.client_rect);
3734 dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
3735 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3738 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3741 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3742 return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
3744 #endregion // ToolTip
3747 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3748 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3749 float ticks, int value_pos, bool mouse_value) {
3751 Point toptick_startpoint = new Point ();
3752 Point bottomtick_startpoint = new Point ();
3753 Point channel_startpoint = new Point ();
3755 float pixels_betweenticks;
3756 const int space_from_right = 8;
3757 const int space_from_left = 8;
3758 const int space_from_bottom = 11;
3759 Rectangle area = tb.ClientRectangle;
3761 switch (tb.TickStyle) {
3762 case TickStyle.BottomRight:
3763 case TickStyle.None:
3764 channel_startpoint.Y = 8;
3765 channel_startpoint.X = 9;
3766 bottomtick_startpoint.Y = 13;
3767 bottomtick_startpoint.X = 24;
3769 case TickStyle.TopLeft:
3770 channel_startpoint.Y = 8;
3771 channel_startpoint.X = 19;
3772 toptick_startpoint.Y = 13;
3773 toptick_startpoint.X = 8;
3775 case TickStyle.Both:
3776 channel_startpoint.Y = 8;
3777 channel_startpoint.X = 18;
3778 bottomtick_startpoint.Y = 13;
3779 bottomtick_startpoint.X = 32;
3780 toptick_startpoint.Y = 13;
3781 toptick_startpoint.X = 8;
3787 thumb_area.X = area.X + channel_startpoint.X;
3788 thumb_area.Y = area.Y + channel_startpoint.Y;
3789 thumb_area.Height = area.Height - space_from_right - space_from_left;
3790 thumb_area.Width = 4;
3793 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3794 1, thumb_area.Height);
3796 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
3797 1, thumb_area.Height);
3799 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
3800 1, thumb_area.Height);
3802 pixel_len = thumb_area.Height - 11;
3803 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3805 /* Convert thumb position from mouse position to value*/
3807 if (value_pos < thumb_area.Bottom)
3808 value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
3812 if (value_pos + tb.Minimum > tb.Maximum)
3813 value_pos = tb.Maximum - tb.Minimum;
3815 tb.Value = value_pos + tb.Minimum;
3818 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
3819 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
3821 /* Draw thumb fixed 10x22 size */
3822 thumb_pos.Width = 10;
3823 thumb_pos.Height = 22;
3825 switch (tb.TickStyle) {
3826 case TickStyle.BottomRight:
3827 case TickStyle.None: {
3828 thumb_pos.X = channel_startpoint.X - 8;
3830 Pen pen = SystemPens.ControlLight;
3831 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3832 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3833 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3835 pen = SystemPens.ControlDark;
3836 dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3837 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3839 pen = SystemPens.ControlDarkDark;
3840 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3841 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3843 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3844 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3845 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3846 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3850 case TickStyle.TopLeft: {
3851 thumb_pos.X = channel_startpoint.X - 10;
3853 Pen pen = SystemPens.ControlLight;
3854 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3855 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3857 pen = SystemPens.ControlDark;
3858 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3859 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3860 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3862 pen = SystemPens.ControlDarkDark;
3863 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3864 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3865 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3867 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3868 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3869 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3870 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3875 case TickStyle.Both: {
3876 thumb_pos.X = area.X + 10;
3878 Pen pen = SystemPens.ControlLight;
3879 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3880 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3882 pen = SystemPens.ControlDark;
3883 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3884 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3886 pen = SystemPens.ControlDarkDark;
3887 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3888 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3890 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3899 pixel_len = thumb_area.Height - 11;
3900 pixels_betweenticks = pixel_len / ticks;
3902 thumb_area.X = thumb_pos.X;
3903 thumb_area.Y = channel_startpoint.Y;
3904 thumb_area.Width = thumb_pos.Height;
3907 Region outside = new Region (area);
3908 outside.Exclude (thumb_area);
3910 if (outside.IsVisible (clip_rectangle)) {
3911 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3912 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3914 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3915 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3916 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3917 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3919 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3920 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3924 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3925 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3927 pixel_len = thumb_area.Height - 11;
3928 pixels_betweenticks = pixel_len / ticks;
3930 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3931 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3932 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3933 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3935 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3936 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3948 Does not matter the size of the control, Win32 always draws:
3949 - Ticks starting from pixel 13, 8
3950 - Channel starting at pos 8, 19 and ends at Width - 8
3951 - Autosize makes always the control 40 pixels height
3952 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3955 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3956 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3957 float ticks, int value_pos, bool mouse_value) {
3958 Point toptick_startpoint = new Point ();
3959 Point bottomtick_startpoint = new Point ();
3960 Point channel_startpoint = new Point ();
3962 float pixels_betweenticks;
3963 const int space_from_right = 8;
3964 const int space_from_left = 8;
3965 Rectangle area = tb.ClientRectangle;
3967 switch (tb.TickStyle) {
3968 case TickStyle.BottomRight:
3969 case TickStyle.None:
3970 channel_startpoint.X = 8;
3971 channel_startpoint.Y = 9;
3972 bottomtick_startpoint.X = 13;
3973 bottomtick_startpoint.Y = 24;
3975 case TickStyle.TopLeft:
3976 channel_startpoint.X = 8;
3977 channel_startpoint.Y = 19;
3978 toptick_startpoint.X = 13;
3979 toptick_startpoint.Y = 8;
3981 case TickStyle.Both:
3982 channel_startpoint.X = 8;
3983 channel_startpoint.Y = 18;
3984 bottomtick_startpoint.X = 13;
3985 bottomtick_startpoint.Y = 32;
3986 toptick_startpoint.X = 13;
3987 toptick_startpoint.Y = 8;
3993 thumb_area.X = area.X + channel_startpoint.X;
3994 thumb_area.Y = area.Y + channel_startpoint.Y;
3995 thumb_area.Width = area.Width - space_from_right - space_from_left;
3996 thumb_area.Height = 4;
3999 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
4000 thumb_area.Width, 1);
4002 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
4003 thumb_area.Width, 1);
4005 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
4006 thumb_area.Width, 1);
4008 pixel_len = thumb_area.Width - 11;
4009 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4011 /* Convert thumb position from mouse position to value*/
4013 if (value_pos >= channel_startpoint.X)
4014 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4018 if (value_pos + tb.Minimum > tb.Maximum)
4019 value_pos = tb.Maximum - tb.Minimum;
4021 tb.Value = value_pos + tb.Minimum;
4024 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4026 /* Draw thumb fixed 10x22 size */
4027 thumb_pos.Width = 10;
4028 thumb_pos.Height = 22;
4030 switch (tb.TickStyle) {
4031 case TickStyle.BottomRight:
4032 case TickStyle.None: {
4033 thumb_pos.Y = channel_startpoint.Y - 8;
4035 Pen pen = SystemPens.ControlLight;
4036 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4037 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4038 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4040 pen = SystemPens.ControlDark;
4041 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4042 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4044 pen = SystemPens.ControlDarkDark;
4045 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4046 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4048 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4049 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4050 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4051 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4054 case TickStyle.TopLeft: {
4055 thumb_pos.Y = channel_startpoint.Y - 10;
4057 Pen pen = SystemPens.ControlLight;
4058 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4059 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4061 pen = SystemPens.ControlDark;
4062 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4063 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4064 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4066 pen = SystemPens.ControlDarkDark;
4067 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4068 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4069 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4071 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4072 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4073 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4074 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4078 case TickStyle.Both: {
4079 thumb_pos.Y = area.Y + 10;
4081 Pen pen = SystemPens.ControlLight;
4082 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4083 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4085 pen = SystemPens.ControlDark;
4086 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4087 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4089 pen = SystemPens.ControlDarkDark;
4090 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4091 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4093 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4102 pixel_len = thumb_area.Width - 11;
4103 pixels_betweenticks = pixel_len / ticks;
4106 thumb_area.Y = thumb_pos.Y;
4107 thumb_area.X = channel_startpoint.X;
4108 thumb_area.Height = thumb_pos.Height;
4109 Region outside = new Region (area);
4110 outside.Exclude (thumb_area);
4112 if (outside.IsVisible (clip_rectangle)) {
4113 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4114 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4116 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4117 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4118 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4119 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4121 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4122 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4126 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4127 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4129 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4130 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4131 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4132 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4134 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4135 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4143 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4148 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4150 Rectangle thumb_pos = tb.ThumbPos;
4151 Rectangle thumb_area = tb.ThumbArea;
4153 if (tb.thumb_pressed) {
4154 value_pos = tb.thumb_mouseclick;
4157 value_pos = tb.Value - tb.Minimum;
4158 mouse_value = false;
4161 area = tb.ClientRectangle;
4163 if (tb.thumb_pressed == true) {
4164 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4166 br_thumb = SystemBrushes.Control;
4170 /* Control Background */
4171 if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
4172 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
4174 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4179 Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
4180 dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
4181 dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4182 dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
4183 dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4186 if (tb.Orientation == Orientation.Vertical) {
4187 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4188 br_thumb, ticks, value_pos, mouse_value);
4191 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4192 br_thumb, ticks, value_pos, mouse_value);
4195 tb.ThumbPos = thumb_pos;
4196 tb.ThumbArea = thumb_area;
4199 public override Size TrackBarDefaultSize {
4201 return new Size (104, 42);
4205 #endregion // TrackBar
4208 public override Size VScrollBarDefaultSize {
4210 return new Size (this.ScrollBarButtonSize, 80);
4213 #endregion // VScrollBar
4216 public override Size TreeViewDefaultSize {
4218 return new Size (121, 97);
4224 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
4226 if (wm.IsToolWindow)
4227 return SystemInformation.ToolWindowCaptionHeight;
4228 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4230 return SystemInformation.CaptionHeight;
4233 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
4238 public override int ManagedWindowIconWidth (InternalWindowManager wm)
4240 return ManagedWindowTitleBarHeight (wm) - 5;
4243 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
4245 int bw = ManagedWindowBorderWidth (wm);
4246 Size btsize = ManagedWindowButtonSize (wm);
4247 int btw = btsize.Width;
4248 int bth = btsize.Height;
4250 if (!wm.IsToolWindow && wm.HasBorders) {
4251 if (!wm.IsMaximized) {
4252 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2,
4254 wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw,
4256 wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw,
4261 } else if (wm.IsToolWindow) {
4262 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth);
4266 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
4268 Form form = wm.Form;
4269 int tbheight = ManagedWindowTitleBarHeight (wm);
4270 int bdwidth = ManagedWindowBorderWidth (wm);
4271 Color titlebar_color = Color.FromArgb (255, 0, 0, 255);
4273 if (wm.HasBorders) {
4274 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
4275 // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves
4276 dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5);
4277 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
4280 Color color = ThemeEngine.Current.ColorControlDark;
4282 if (wm.IsActive () && !wm.IsMaximized)
4283 color = titlebar_color;
4285 Rectangle tb = new Rectangle (bdwidth, bdwidth,
4286 form.Width - (bdwidth * 2), tbheight);
4288 // HACK: For now always draw the titlebar until we get updates better
4289 // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle);
4290 //if (vis != Rectangle.Empty)
4291 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), tb);
4293 dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth,
4294 tbheight + bdwidth, form.Width - (bdwidth * 2),
4295 tbheight + bdwidth);
4297 if (!wm.IsToolWindow) {
4298 tb.X += 18; // Room for the icon and the buttons
4299 tb.Width = (form.Width - 62) - tb.X;
4302 if (form.Text != null) {
4303 StringFormat format = new StringFormat ();
4304 format.FormatFlags = StringFormatFlags.NoWrap;
4305 format.Trimming = StringTrimming.EllipsisCharacter;
4306 format.LineAlignment = StringAlignment.Center;
4308 if (tb.IntersectsWith (clip))
4309 dc.DrawString (form.Text, form.Font,
4310 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
4314 if (wm.HasBorders) {
4315 if (!wm.IsToolWindow && form.Icon != null) {
4316 Rectangle icon = new Rectangle (bdwidth + 3,
4317 bdwidth + 2, wm.IconWidth, wm.IconWidth);
4318 if (icon.IntersectsWith (clip))
4319 dc.DrawIcon (form.Icon, icon);
4322 if (!wm.IsMaximized) {
4323 if (!wm.IsToolWindow) {
4324 DrawTitleButton (dc, wm.minimize_button, clip);
4325 DrawTitleButton (dc, wm.maximize_button, clip);
4327 DrawTitleButton (dc, wm.close_button, clip);
4329 // DrawMaximizedButtons (pe, form.ActiveMenu);
4334 private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip)
4336 if (!button.Rectangle.IntersectsWith (clip))
4339 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
4341 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
4342 button.Caption, ButtonState.Normal);
4345 private Size ManagedWindowButtonSize (InternalWindowManager wm)
4347 int height = wm.TitleBarHeight;
4348 if (wm.IsToolWindow)
4349 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
4351 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4353 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
4357 #region ControlPaint
4358 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4359 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4360 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4361 int bottomWidth, ButtonBorderStyle bottomStyle) {
4362 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4363 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4364 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4365 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4368 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4369 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4372 protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
4375 Pen penTopLeftInner;
4377 Pen penBottomRightInner;
4378 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4379 bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
4381 if ((style & Border3DStyle.Adjust) != 0) {
4388 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
4390 CPColor cpcolor = CPColor.Empty;
4392 if (!is_ColorControl)
4393 cpcolor = ResPool.GetCPColor (control_color);
4396 case Border3DStyle.Raised:
4397 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4398 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4399 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4401 case Border3DStyle.Sunken:
4402 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4403 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4404 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4406 case Border3DStyle.Etched:
4407 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4408 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4410 case Border3DStyle.RaisedOuter:
4411 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4413 case Border3DStyle.SunkenOuter:
4414 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4415 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4417 case Border3DStyle.RaisedInner:
4418 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4419 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4421 case Border3DStyle.SunkenInner:
4422 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4424 case Border3DStyle.Flat:
4425 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4427 case Border3DStyle.Bump:
4428 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4434 if ((sides & Border3DSide.Middle) != 0) {
4435 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
4436 graphics.FillRectangle (brush, rect);
4439 if ((sides & Border3DSide.Left) != 0) {
4440 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
4441 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
4444 if ((sides & Border3DSide.Top) != 0) {
4445 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
4446 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
4449 if ((sides & Border3DSide.Right) != 0) {
4450 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
4451 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
4454 if ((sides & Border3DSide.Bottom) != 0) {
4455 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4456 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
4460 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
4462 // sadly enough, the rectangle gets always filled with a hatchbrush
4463 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);
4465 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
4466 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4468 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4470 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4471 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4473 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4474 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4476 Pen pen = SystemPens.ControlDarkDark;
4477 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4478 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4480 pen = SystemPens.ControlDark;
4481 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4482 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4484 pen = SystemPens.ControlLight;
4485 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4486 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4488 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
4489 Pen pen = SystemPens.ControlDarkDark;
4490 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4491 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4493 pen = SystemPens.ControlDark;
4494 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4495 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4497 pen = SystemPens.ControlLight;
4498 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4499 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4501 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
4502 Pen pen = SystemPens.ControlLight;
4503 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4504 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4506 pen = SystemPens.ControlDark;
4507 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
4508 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
4510 pen = SystemPens.ControlDarkDark;
4511 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
4512 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
4517 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4518 Rectangle captionRect;
4521 CPDrawButton(graphics, rectangle, state);
4523 if (rectangle.Width<rectangle.Height) {
4524 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4526 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4529 if ((state & ButtonState.Pushed)!=0) {
4530 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4533 /* Make sure we've got at least a line width of 1 */
4534 lineWidth=Math.Max(1, captionRect.Width/7);
4537 case CaptionButton.Close: {
4540 if ((state & ButtonState.Inactive)!=0) {
4541 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
4542 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4544 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
4545 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4548 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
4549 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4554 case CaptionButton.Help:
4555 case CaptionButton.Maximize:
4556 case CaptionButton.Minimize:
4557 case CaptionButton.Restore: {
4558 if ((state & ButtonState.Inactive)!=0) {
4559 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4561 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4564 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4571 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
4573 Pen check_pen = SystemPens.ControlDarkDark;
4575 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4577 if ((state & ButtonState.All) == ButtonState.All) {
4579 cb_rect.Height -= 2;
4581 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4582 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4584 check_pen = SystemPens.ControlDark;
4586 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4588 cb_rect.Height -= 2;
4590 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4591 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4594 cb_rect.Height -= 1;
4596 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
4598 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
4599 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
4601 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
4603 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
4604 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);
4606 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4608 Pen pen = SystemPens.ControlDark;
4609 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
4610 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
4612 pen = SystemPens.ControlDarkDark;
4613 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
4614 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
4616 pen = SystemPens.ControlLight;
4617 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
4618 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
4620 // oh boy, matching ms is like fighting against windmills
4621 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl))) {
4622 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4623 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
4626 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
4627 check_pen = SystemPens.ControlDark;
4630 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4631 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
4633 if (check_size < 7) {
4634 int lineWidth = Math.Max (3, check_size / 3);
4635 int Scale = Math.Max (1, check_size / 9);
4637 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,
4638 check_size, check_size);
4640 for (int i = 0; i < lineWidth; i++) {
4641 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
4642 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);
4645 int lineWidth = Math.Max (3, check_size / 3) + 1;
4647 int x_half = cb_rect.Width / 2;
4648 int y_half = cb_rect.Height / 2;
4650 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
4651 check_size, check_size);
4653 int gradient_left = check_size / 3;
4654 int gradient_right = check_size - gradient_left - 1;
4657 for (int i = 0; i < lineWidth; i++) {
4658 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
4659 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
4665 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4666 Point[] arrow = new Point[3];
4676 if ((state & ButtonState.Checked)!=0) {
4677 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4680 if ((state & ButtonState.Flat)!=0) {
4681 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4683 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4684 // this needs to render like a pushed button - jba
4685 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4686 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4687 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
4689 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4693 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4694 centerX=rect.Left+rect.Width/2;
4695 centerY=rect.Top+rect.Height/2;
4696 shiftX=Math.Max(1, rect.Width/8);
4697 shiftY=Math.Max(1, rect.Height/8);
4699 if ((state & ButtonState.Pushed)!=0) {
4706 P1=new Point(rect.Left, centerY);
4707 P2=new Point(rect.Right, centerY);
4708 P3=new Point(centerX, rect.Bottom);
4714 /* Draw the arrow */
4715 if ((state & ButtonState.Inactive)!=0) {
4716 /* Move away from the shadow */
4717 arrow[0].X += 1; arrow[0].Y += 1;
4718 arrow[1].X += 1; arrow[1].Y += 1;
4719 arrow[2].X += 1; arrow[2].Y += 1;
4721 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4727 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4729 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4734 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
4736 Pen pen = Pens.Black;
4737 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
4741 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
4742 graphics.DrawRectangle (pen, rect);
4744 X = rect.X + rect.Width / 2;
4745 Y = rect.Y + rect.Height / 2;
4747 /* Draw the cross */
4748 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
4749 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
4751 /* Draw 'arrows' for vertical lines */
4752 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
4753 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
4755 /* Draw 'arrows' for horizontal lines */
4756 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
4757 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
4760 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4761 // make a rectange to trace around border of the button
4762 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4764 Color outerColor = foreColor;
4765 // adjust focus color according to the flatstyle
4766 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4767 outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4770 // draw the outer rectangle
4771 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4773 // draw the inner rectangle
4774 if (button.FlatStyle == FlatStyle.Popup) {
4775 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4777 // draw a flat inner rectangle
4778 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4779 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4783 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4785 // make a rectange to trace around border of the button
4786 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4788 #if NotUntilCairoIsFixed
4789 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4790 DashStyle oldStyle; // used for caching old penstyle
4791 Pen pen = ResPool.GetPen (colorBackInverted);
4793 oldStyle = pen.DashStyle;
4794 pen.DashStyle = DashStyle.Dot;
4796 graphics.DrawRectangle (pen, trace_rectangle);
4797 pen.DashStyle = oldStyle;
4799 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4804 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4806 Rectangle rect = rectangle;
4810 if (backColor.GetBrightness () >= 0.5) {
4811 foreColor = Color.Transparent;
4812 backColor = Color.Black;
4815 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4816 foreColor = Color.Black;
4819 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4820 pen = new Pen (brush, 1);
4825 graphics.DrawRectangle (pen, rect);
4829 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
4834 if (primary == true) {
4836 if (enabled == true) {
4839 sb = SystemBrushes.Control;
4843 if (enabled == true) {
4846 sb = SystemBrushes.Control;
4849 graphics.FillRectangle (sb, rectangle);
4850 graphics.DrawRectangle (pen, rectangle);
4854 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4860 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4863 foreColor=Color.Black;
4865 foreColor=Color.White;
4868 // still not perfect. it seems that ms calculates the position of the first dot or line
4870 using (Pen pen = new Pen (foreColor)) {
4871 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
4873 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
4874 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
4878 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4880 Microsoft seems to ignore the background and simply make
4881 the image grayscale. At least when having > 256 colors on
4885 if (imagedisabled_attributes == null) {
4886 imagedisabled_attributes = new ImageAttributes ();
4887 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4888 // This table would create a perfect grayscale image, based on luminance
4889 // new float[]{0.3f,0.3f,0.3f,0,0},
4890 // new float[]{0.59f,0.59f,0.59f,0,0},
4891 // new float[]{0.11f,0.11f,0.11f,0,0},
4892 // new float[]{0,0,0,1,0,0},
4893 // new float[]{0,0,0,0,1,0},
4894 // new float[]{0,0,0,0,0,1}
4896 // This table generates a image that is grayscaled and then
4897 // brightened up. Seems to match MS close enough.
4898 new float[]{0.2f,0.2f,0.2f,0,0},
4899 new float[]{0.41f,0.41f,0.41f,0,0},
4900 new float[]{0.11f,0.11f,0.11f,0,0},
4901 new float[]{0.15f,0.15f,0.15f,1,0,0},
4902 new float[]{0.15f,0.15f,0.15f,0,1,0},
4903 new float[]{0.15f,0.15f,0.15f,0,0,1}
4906 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4909 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4914 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4919 penBorder = ResPool.GetSizedPen (Color.White, 2);
4920 penInside = ResPool.GetPen (Color.Black);
4922 penBorder = ResPool.GetSizedPen (Color.Black, 2);
4923 penInside = ResPool.GetPen (Color.White);
4925 penBorder.Alignment=PenAlignment.Inset;
4926 penInside.Alignment=PenAlignment.Inset;
4928 graphics.DrawRectangle(penBorder, rectangle);
4929 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4933 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
4937 Brush brush = ResPool.GetSolidBrush (color);
4940 case MenuGlyph.Arrow: {
4941 Point[] arrow = new Point[3];
4949 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4950 centerX=rect.Left+rect.Width/2;
4951 centerY=rect.Top+rect.Height/2;
4952 shiftX=Math.Max(1, rect.Width/8);
4957 P1=new Point(centerX, rect.Top);
4958 P2=new Point(centerX, rect.Bottom);
4959 P3=new Point(rect.Right, centerY);
4965 graphics.FillPolygon(brush, arrow, FillMode.Winding);
4970 case MenuGlyph.Bullet: {
4972 lineWidth=Math.Max(2, rectangle.Width/3);
4973 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4975 graphics.FillEllipse(brush, rect);
4980 case MenuGlyph.Checkmark: {
4982 Pen pen = ResPool.GetPen (color);
4984 lineWidth=Math.Max(2, rectangle.Width/6);
4985 Scale=Math.Max(1, rectangle.Width/12);
4987 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4989 for (int i=0; i<lineWidth; i++) {
4990 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4991 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);
4999 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
5001 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
5003 Color dot_color = Color.Black;
5005 Color top_left_outer = Color.Black;
5006 Color top_left_inner = Color.Black;
5007 Color bottom_right_outer = Color.Black;
5008 Color bottom_right_inner = Color.Black;
5010 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
5011 int radius = ellipse_diameter / 2;
5013 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
5017 if ((state & ButtonState.All) == ButtonState.All) {
5018 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5019 dot_color = cpcolor.Dark;
5021 if ((state & ButtonState.Flat) == ButtonState.Flat) {
5022 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5023 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5025 brush = SystemBrushes.ControlLightLight;
5027 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5028 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5030 brush = SystemBrushes.ControlLightLight;
5032 top_left_outer = cpcolor.Dark;
5033 top_left_inner = cpcolor.DarkDark;
5034 bottom_right_outer = cpcolor.Light;
5035 bottom_right_inner = Color.Transparent;
5037 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
5038 dot_color = cpcolor.Dark;
5041 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
5043 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
5045 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
5046 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
5047 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
5049 if (bottom_right_inner != Color.Transparent)
5050 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5052 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), line_width)) {
5053 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5056 if ((state & ButtonState.Checked) == ButtonState.Checked) {
5057 int inflate = line_width * 4;
5058 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
5059 if (rectangle.Height > 13) {
5063 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
5065 Pen pen = ResPool.GetPen (dot_color);
5066 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
5067 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
5069 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
5070 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
5075 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
5080 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
5085 /* Scroll button: regular button + direction arrow */
5086 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
5088 DrawScrollButtonPrimitive (dc, area, state);
5090 bool fill_rect = true;
5093 if ((state & ButtonState.Pushed) != 0)
5097 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
5099 Point [] arrow = new Point [3];
5100 for (int i = 0; i < 3; i++)
5101 arrow [i] = new Point ();
5103 Pen pen = SystemPens.ControlText;
5105 if ((state & ButtonState.Inactive) != 0) {
5106 pen = SystemPens.ControlDark;
5111 case ScrollButton.Down:
5112 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5116 int triangle_height;
5118 if (rect.Height < 8) {
5119 triangle_height = 2;
5121 } else if (rect.Height == 11) {
5122 triangle_height = 3;
5124 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5127 arrow [0].X = rect.X + x_middle;
5128 arrow [0].Y = rect.Bottom - triangle_height - 1;
5130 if (arrow [0].Y - 1 == rect.Y)
5133 arrow [1].X = arrow [0].X + triangle_height - 1;
5134 arrow [1].Y = arrow [0].Y - triangle_height + 1;
5135 arrow [2].X = arrow [0].X - triangle_height + 1;
5136 arrow [2].Y = arrow [1].Y;
5138 dc.DrawPolygon (pen, arrow);
5140 if ((state & ButtonState.Inactive) != 0) {
5141 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
5142 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
5146 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
5147 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
5156 case ScrollButton.Up:
5157 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5161 if (rect.Height < 8) {
5162 triangle_height = 2;
5164 } else if (rect.Height == 11) {
5165 triangle_height = 3;
5167 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5170 arrow [0].X = rect.X + x_middle;
5171 arrow [0].Y = rect.Y + triangle_height;
5173 if (arrow [0].Y + 1 == rect.Bottom - 1)
5176 arrow [1].X = arrow [0].X + triangle_height - 1;
5177 arrow [1].Y = arrow [0].Y + triangle_height - 1;
5178 arrow [2].X = arrow [0].X - triangle_height + 1;
5179 arrow [2].Y = arrow [1].Y;
5181 dc.DrawPolygon (pen, arrow);
5183 if ((state & ButtonState.Inactive) != 0) {
5184 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
5188 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
5189 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
5197 case ScrollButton.Left:
5198 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5204 if (rect.Width < 8) {
5207 } else if (rect.Width == 11) {
5210 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5213 arrow [0].X = rect.Left + triangle_width - 1;
5214 arrow [0].Y = rect.Y + y_middle;
5216 if (arrow [0].X - 1 == rect.X)
5219 arrow [1].X = arrow [0].X + triangle_width - 1;
5220 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5221 arrow [2].X = arrow [1].X;
5222 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5224 dc.DrawPolygon (pen, arrow);
5226 if ((state & ButtonState.Inactive) != 0) {
5227 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5231 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
5232 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
5239 case ScrollButton.Right:
5240 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5244 if (rect.Width < 8) {
5247 } else if (rect.Width == 11) {
5250 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5253 arrow [0].X = rect.Right - triangle_width - 1;
5254 arrow [0].Y = rect.Y + y_middle;
5256 if (arrow [0].X - 1 == rect.X)
5259 arrow [1].X = arrow [0].X - triangle_width + 1;
5260 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5261 arrow [2].X = arrow [1].X;
5262 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5264 dc.DrawPolygon (pen, arrow);
5266 if ((state & ButtonState.Inactive) != 0) {
5267 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5268 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
5272 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
5273 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
5282 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5288 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
5290 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
5291 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
5293 for (int i = 2; i < bounds.Width - 2; i += 4) {
5294 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
5295 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
5296 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
5300 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
5302 CPColor cpcolor = ResPool.GetCPColor (color);
5304 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
5305 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
5307 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
5310 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5311 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5316 case ButtonBorderStyle.Solid:
5317 case ButtonBorderStyle.Inset:
5318 case ButtonBorderStyle.Outset:
5319 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
5321 case ButtonBorderStyle.Dashed:
5322 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
5324 case ButtonBorderStyle.Dotted:
5325 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
5328 case ButtonBorderStyle.None:
5333 case ButtonBorderStyle.Outset: {
5335 int hue, brightness, saturation;
5336 int brightnessSteps;
5337 int brightnessDownSteps;
5339 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5341 brightnessDownSteps=brightness/width;
5342 if (brightness>127) {
5343 brightnessSteps=Math.Max(6, (160-brightness)/width);
5345 brightnessSteps=(127-brightness)/width;
5348 for (int i=0; i<width; i++) {
5350 case Border3DSide.Left: {
5351 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5352 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5353 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5357 case Border3DSide.Right: {
5358 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5359 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5360 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5364 case Border3DSide.Top: {
5365 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5366 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5367 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5371 case Border3DSide.Bottom: {
5372 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5373 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5374 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5382 case ButtonBorderStyle.Inset: {
5384 int hue, brightness, saturation;
5385 int brightnessSteps;
5386 int brightnessDownSteps;
5388 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5390 brightnessDownSteps=brightness/width;
5391 if (brightness>127) {
5392 brightnessSteps=Math.Max(6, (160-brightness)/width);
5394 brightnessSteps=(127-brightness)/width;
5397 for (int i=0; i<width; i++) {
5399 case Border3DSide.Left: {
5400 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5401 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5402 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5406 case Border3DSide.Right: {
5407 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5408 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5409 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5413 case Border3DSide.Top: {
5414 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5415 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5416 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5420 case Border3DSide.Bottom: {
5421 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5422 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5423 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5432 I decided to have the for-loop duplicated for speed reasons;
5433 that way we only have to switch once (as opposed to have the
5434 for-loop around the switch)
5438 case Border3DSide.Left: {
5439 for (int i=0; i<width; i++) {
5440 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5445 case Border3DSide.Right: {
5446 for (int i=0; i<width; i++) {
5447 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5452 case Border3DSide.Top: {
5453 for (int i=0; i<width; i++) {
5454 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5459 case Border3DSide.Bottom: {
5460 for (int i=0; i<width; i++) {
5461 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5472 This function actually draws the various caption elements.
5473 This way we can scale them nicely, no matter what size, and they
5474 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5477 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5479 case CaptionButton.Close: {
5481 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);
5482 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);
5485 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5486 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5490 case CaptionButton.Help: {
5491 StringFormat sf = new StringFormat();
5492 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5494 sf.Alignment=StringAlignment.Center;
5495 sf.LineAlignment=StringAlignment.Center;
5498 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5506 case CaptionButton.Maximize: {
5507 /* Top 'caption bar' line */
5508 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5509 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);
5512 /* Left side line */
5513 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5514 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5517 /* Right side line */
5518 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5519 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);
5523 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5524 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5529 case CaptionButton.Minimize: {
5531 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5532 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5537 case CaptionButton.Restore: {
5538 /** First 'window' **/
5539 /* Top 'caption bar' line */
5540 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5541 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);
5544 /* Left side line */
5545 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5546 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);
5549 /* Right side line */
5550 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5551 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);
5555 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5556 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);
5559 /** Second 'window' **/
5560 /* Top 'caption bar' line */
5561 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5562 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);
5565 /* Left side line */
5566 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5567 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5570 /* Right side line */
5571 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5572 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);
5576 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5577 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5586 /* Generic scroll button */
5587 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5588 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5589 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
5590 area.Y + 1, area.Width - 2 , area.Height - 2);
5592 dc.DrawRectangle (SystemPens.ControlDark, area.X,
5593 area.Y, area.Width, area.Height);
5598 Brush sb_control = SystemBrushes.Control;
5599 Brush sb_lightlight = SystemBrushes.ControlLightLight;
5600 Brush sb_dark = SystemBrushes.ControlDark;
5601 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
5603 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
5604 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
5606 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
5607 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
5610 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
5613 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
5616 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
5617 area.Y + 1, 1, area.Height -3);
5619 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
5620 area.Y, 1, area.Height - 1);
5622 dc.FillRectangle (sb_control, area.X + 2,
5623 area.Y + 2, area.Width - 4, area.Height - 4);
5627 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5628 switch (border_style){
5629 case BorderStyle.Fixed3D:
5630 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5631 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5632 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5633 area.Y + area.Height - 1);
5634 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5635 area.Y + area.Height);
5637 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5638 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5639 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5640 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5642 case BorderStyle.FixedSingle:
5643 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5645 case BorderStyle.None:
5651 #endregion // ControlPaint