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
31 using System.Drawing.Drawing2D;
32 using System.Drawing.Imaging;
33 using System.Drawing.Text;
35 namespace System.Windows.Forms
38 internal class ThemeWin32Classic : Theme
40 public override Version Version {
42 return new Version(0, 1, 0, 0);
46 /* Hardcoded colour values not exposed in the API constants in all configurations */
47 protected static readonly Color arrow_color = Color.Black;
48 protected static readonly Color pen_ticks_color = Color.Black;
49 protected static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
50 protected static StringFormat string_format_menu_text;
51 protected static StringFormat string_format_menu_shortcut;
52 protected static StringFormat string_format_menu_menubar_text;
53 static readonly Rectangle checkbox_rect = new Rectangle (2, 2, 11,11); // Position of the checkbox relative to the item
54 static ImageAttributes imagedisabled_attributes = null;
55 const int SEPARATOR_HEIGHT = 5;
56 const int SM_CXBORDER = 1;
57 const int SM_CYBORDER = 1;
58 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
59 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
61 #region Principal Theme Methods
62 public ThemeWin32Classic ()
64 defaultWindowBackColor = this.ColorWindow;
65 defaultWindowForeColor = this.ColorControlText;
66 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
68 /* Menu string formats */
69 string_format_menu_text = new StringFormat ();
70 string_format_menu_text.LineAlignment = StringAlignment.Center;
71 string_format_menu_text.Alignment = StringAlignment.Near;
72 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
74 string_format_menu_shortcut = new StringFormat ();
75 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
76 string_format_menu_shortcut.Alignment = StringAlignment.Far;
78 string_format_menu_menubar_text = new StringFormat ();
79 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
80 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
81 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
82 always_draw_hotkeys = false;
85 public override void ResetDefaults() {
86 throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
89 public override bool DoubleBufferingSupported {
92 #endregion // Principal Theme Methods
94 #region Internal Methods
95 protected SolidBrush GetControlBackBrush (Color c) {
96 if (c == DefaultControlBackColor)
97 return ResPool.GetSolidBrush (ColorControl);
98 return ResPool.GetSolidBrush (c);
101 protected SolidBrush GetControlForeBrush (Color c) {
102 if (c == DefaultControlForeColor)
103 return ResPool.GetSolidBrush (ColorControlText);
104 return ResPool.GetSolidBrush (c);
106 #endregion // Internal Methods
108 #region OwnerDraw Support
109 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
111 if (e.State == DrawItemState.Selected) {
112 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
116 e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
119 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
121 if (e.State == DrawItemState.Focus)
122 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
124 #endregion // OwnerDraw Support
127 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
128 // Draw the button: fill rectangle, draw border, etc.
129 ButtonBase_DrawButton(button, dc);
131 // First, draw the image
132 if ((button.image != null) || (button.image_list != null))
133 ButtonBase_DrawImage(button, dc);
135 // Draw the focus rectangle
136 if (button.has_focus)
137 ButtonBase_DrawFocus(button, dc);
140 if (button.text != null && button.text != String.Empty)
141 ButtonBase_DrawText(button, dc);
144 protected virtual void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
146 Rectangle buttonRectangle;
147 Rectangle borderRectangle;
149 dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
151 // set up the button rectangle
152 buttonRectangle = button.ClientRectangle;
153 if (button.has_focus || button.paint_as_acceptbutton) {
154 // shrink the rectangle for the normal button drawing inside the focus rectangle
155 borderRectangle = Rectangle.Inflate(buttonRectangle, -1, -1);
157 borderRectangle = buttonRectangle;
160 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
161 DrawFlatStyleButton (dc, borderRectangle, button);
163 CPDrawButton(dc, borderRectangle, button.ButtonState);
164 if (button.has_focus || button.paint_as_acceptbutton) {
165 dc.DrawRectangle(ResPool.GetPen(button.ForeColor), borderRectangle);
170 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
172 // Need to draw a picture
179 int width = button.ClientSize.Width;
180 int height = button.ClientSize.Height;
182 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
183 i = button.image_list.Images[button.image_index];
188 image_width = button.image.Width;
189 image_height = button.image.Height;
191 switch (button.image_alignment) {
192 case ContentAlignment.TopLeft: {
198 case ContentAlignment.TopCenter: {
199 image_x=(width-image_width)/2;
204 case ContentAlignment.TopRight: {
205 image_x=width-image_width;
210 case ContentAlignment.MiddleLeft: {
212 image_y=(height-image_height)/2;
216 case ContentAlignment.MiddleCenter: {
217 image_x=(width-image_width)/2;
218 image_y=(height-image_height)/2;
222 case ContentAlignment.MiddleRight: {
223 image_x=width-image_width;
224 image_y=(height-image_height)/2;
228 case ContentAlignment.BottomLeft: {
230 image_y=height-image_height;
234 case ContentAlignment.BottomCenter: {
235 image_x=(width-image_width)/2;
236 image_y=height-image_height;
240 case ContentAlignment.BottomRight: {
241 image_x=width-image_width;
242 image_y=height-image_height;
253 if (button.is_pressed) {
258 if (button.is_enabled) {
259 dc.DrawImage(i, image_x, image_y);
262 CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
266 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
268 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
269 DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
271 Rectangle rect = button.ClientRectangle;
272 rect.Inflate (-4, -4);
273 CPDrawFocusRectangle(dc, rect, button.ForeColor, button.BackColor);
277 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
279 Rectangle buttonRectangle = button.ClientRectangle;
280 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
282 if (button.is_pressed) {
287 if (button.is_enabled) {
288 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
290 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
291 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rect, button.text_format);
293 CPDrawStringDisabled(dc, button.text, button.Font, ColorControlText, text_rect, button.text_format);
298 // draw the flat style part of the rectangle
299 public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
300 Color rect_back_color = button.BackColor;
301 Color rect_fore_color = button.ForeColor;
302 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
304 if (button.Enabled) {
305 if (button.Capture || button.is_entered) {
306 if (button.FlatStyle == FlatStyle.Flat) {
307 // fill the rectangle
308 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
310 // now draw the outer border
311 if (button.Capture && button.is_entered) {
312 rect_back_color = ControlPaint.LightLight (rect_back_color);
314 rect_back_color = ControlPaint.Light (rect_back_color);
317 // draw rectangle and fill it
318 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
319 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
321 // else it must be a popup button
323 if (button.Capture && button.is_entered) {
324 graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
327 CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor);
328 graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
329 graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
333 // TODO: draw inner focus rectangle
336 // popup has a ButtonColorText forecolor, not a button.ForeCOlor
337 if (button.FlatStyle == FlatStyle.Popup) {
338 rect_fore_color = this.ColorControlText;
341 // fill then draw outer rect
342 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
343 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
346 // finally some small tweaks to render radiobutton and checkbox
347 CheckBox checkbox = button as CheckBox;
348 RadioButton radiobutton = button as RadioButton;
349 if ((checkbox != null && checkbox.Checked) ||
350 (radiobutton != null && radiobutton.Checked)) {
351 if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
352 // render the hover for flat flatstyle and cheked
353 graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
354 } else if (!button.is_entered && !button.Capture) {
355 // render the checked state for popup when unhovered
356 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
360 // rendering checkbox or radio button style buttons
361 CheckBox checkbox = button as CheckBox;
362 RadioButton radiobutton = button as RadioButton;
363 bool draw_popup_checked = false;
365 if (button.FlatStyle == FlatStyle.Popup) {
366 rect_fore_color = this.ColorControlText;
368 // see if we should draw a disabled checked popup button
369 draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
370 (radiobutton != null && radiobutton.Checked));
373 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
374 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
376 // finally draw the flatstyle checked effect if need
377 if (draw_popup_checked) {
378 // render the checked state for popup when unhovered
379 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
384 public override Size ButtonBaseDefaultSize {
386 return new Size (75, 23);
389 #endregion // ButtonBase
392 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
393 StringFormat text_format;
394 Rectangle client_rectangle;
395 Rectangle text_rectangle;
396 Rectangle checkbox_rectangle;
397 int checkmark_size=13;
398 int checkmark_space = 4;
400 client_rectangle = checkbox.ClientRectangle;
401 text_rectangle = client_rectangle;
402 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
404 text_format = new StringFormat();
405 text_format.Alignment=StringAlignment.Near;
406 text_format.LineAlignment=StringAlignment.Center;
407 text_format.HotkeyPrefix = HotkeyPrefix.Show;
409 /* Calculate the position of text and checkbox rectangle */
410 if (checkbox.appearance!=Appearance.Button) {
411 switch(checkbox.check_alignment) {
412 case ContentAlignment.BottomCenter: {
413 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
414 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
415 text_rectangle.X=client_rectangle.X;
416 text_rectangle.Width=client_rectangle.Width;
417 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
421 case ContentAlignment.BottomLeft: {
422 checkbox_rectangle.X=client_rectangle.Left;
423 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
424 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
425 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
429 case ContentAlignment.BottomRight: {
430 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
431 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
432 text_rectangle.X=client_rectangle.X;
433 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
437 case ContentAlignment.MiddleCenter: {
438 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
439 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
440 text_rectangle.X=client_rectangle.X;
441 text_rectangle.Width=client_rectangle.Width;
446 case ContentAlignment.MiddleLeft: {
447 checkbox_rectangle.X=client_rectangle.Left;
448 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
449 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
450 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
454 case ContentAlignment.MiddleRight: {
455 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
456 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
457 text_rectangle.X=client_rectangle.X;
458 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
462 case ContentAlignment.TopCenter: {
463 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
464 checkbox_rectangle.Y=client_rectangle.Top;
465 text_rectangle.X=client_rectangle.X;
466 text_rectangle.Width=client_rectangle.Width;
467 text_rectangle.Y=checkmark_size+checkmark_space;
468 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
472 case ContentAlignment.TopLeft: {
473 checkbox_rectangle.X=client_rectangle.Left;
474 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
475 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
479 case ContentAlignment.TopRight: {
480 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
481 text_rectangle.X=client_rectangle.X;
482 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
487 text_rectangle.X=client_rectangle.X;
488 text_rectangle.Width=client_rectangle.Width;
491 /* Set the horizontal alignment of our text */
492 switch(checkbox.text_alignment) {
493 case ContentAlignment.BottomLeft:
494 case ContentAlignment.MiddleLeft:
495 case ContentAlignment.TopLeft: {
496 text_format.Alignment=StringAlignment.Near;
500 case ContentAlignment.BottomCenter:
501 case ContentAlignment.MiddleCenter:
502 case ContentAlignment.TopCenter: {
503 text_format.Alignment=StringAlignment.Center;
507 case ContentAlignment.BottomRight:
508 case ContentAlignment.MiddleRight:
509 case ContentAlignment.TopRight: {
510 text_format.Alignment=StringAlignment.Far;
515 /* Set the vertical alignment of our text */
516 switch(checkbox.text_alignment) {
517 case ContentAlignment.TopLeft:
518 case ContentAlignment.TopCenter:
519 case ContentAlignment.TopRight: {
520 text_format.LineAlignment=StringAlignment.Near;
524 case ContentAlignment.BottomLeft:
525 case ContentAlignment.BottomCenter:
526 case ContentAlignment.BottomRight: {
527 text_format.LineAlignment=StringAlignment.Far;
531 case ContentAlignment.MiddleLeft:
532 case ContentAlignment.MiddleCenter:
533 case ContentAlignment.MiddleRight: {
534 text_format.LineAlignment=StringAlignment.Center;
539 ButtonState state = ButtonState.Normal;
540 if (checkbox.FlatStyle == FlatStyle.Flat) {
541 state |= ButtonState.Flat;
544 if (checkbox.Checked) {
545 state |= ButtonState.Checked;
548 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
549 state |= ButtonState.Checked;
550 state |= ButtonState.Pushed;
553 // finally make sure the pushed and inavtive states are rendered
554 if (!checkbox.Enabled) {
555 state |= ButtonState.Inactive;
557 else if (checkbox.is_pressed) {
558 state |= ButtonState.Pushed;
564 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
566 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
568 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
570 text_format.Dispose ();
573 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
575 dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);
576 // render as per normal button
577 if (checkbox.appearance==Appearance.Button) {
578 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
579 DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
581 CPDrawButton(dc, checkbox.ClientRectangle, state);
584 // establish if we are rendering a flat style of some sort
585 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
586 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
588 ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
593 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
597 // offset the text if it's pressed and a button
598 if (checkbox.Appearance == Appearance.Button) {
599 if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
604 text_rectangle.Inflate(-4, -4);
607 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
608 if (checkbox.Enabled) {
609 sb = ResPool.GetSolidBrush(checkbox.ForeColor);
610 dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);
611 } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
612 dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
614 CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorControlText, text_rectangle, text_format);
618 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
620 if (checkbox.Focused) {
621 if (checkbox.FlatStyle != FlatStyle.Flat) {
622 DrawInnerFocusRectangle (dc, Rectangle.Inflate (text_rectangle, -1, -1), checkbox.BackColor);
624 dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (text_rectangle, -1, -1));
629 // renders a checkBox with the Flat and Popup FlatStyle
630 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
634 Rectangle checkbox_rectangle;
635 Rectangle fill_rectangle;
639 // set up our rectangles first
640 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
641 // clip one pixel from bottom right for non popup rendered checkboxes
642 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
643 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));
645 // clip two pixels from bottom right for non popup rendered checkboxes
646 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
647 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));
650 // if disabled render in disabled state
651 if (checkbox.Enabled) {
652 // process the state of the checkbox
653 if (checkbox.is_entered || checkbox.Capture) {
654 // decide on which background color to use
655 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
656 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
657 } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
658 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
660 // use regular window background color
661 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
664 // render the outer border
665 if (checkbox.FlatStyle == FlatStyle.Flat) {
666 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
668 // draw sunken effect
669 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
672 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
674 if (checkbox.FlatStyle == FlatStyle.Flat) {
675 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
677 // draw the outer border
678 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
682 if (checkbox.FlatStyle == FlatStyle.Popup) {
683 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
686 // draw disabled state,
687 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
690 /* Make sure we've got at least a line width of 1 */
691 lineWidth = Math.Max(3, fill_rectangle.Width/3);
692 Scale=Math.Max(1, fill_rectangle.Width/9);
694 // flat style check box is rendered inside a rectangle shifted down by one
695 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
696 if (checkbox.Enabled) {
697 pen=ResPool.GetPen(checkbox.ForeColor);
699 pen=SystemPens.ControlDark;
702 if (checkbox.Checked) {
703 /* Need to draw a check-mark */
704 for (int i=0; i<lineWidth; i++) {
705 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
706 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);
712 #endregion // CheckBox
714 #region CheckedListBox
716 public override Rectangle CheckedListBoxCheckRectangle ()
718 return checkbox_rect;
721 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
723 Color back_color, fore_color;
724 Rectangle item_rect = e.Bounds;
726 StringFormat string_format = ctrl.GetFormatString ();
730 if ((ctrl.Items.GetListBoxItem (e.Index)).State == CheckState.Checked)
731 state = ButtonState.Checked;
733 state = ButtonState.Normal;
735 if (ctrl.ThreeDCheckBoxes == false)
736 state |= ButtonState.Flat;
738 ControlPaint.DrawCheckBox (e.Graphics,
739 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
740 checkbox_rect.Width, checkbox_rect.Height,
743 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
744 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
747 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
748 back_color = ColorHighlight;
749 fore_color = ColorHighlightText;
752 back_color = e.BackColor;
753 fore_color = e.ForeColor;
756 e.Graphics.FillRectangle (ResPool.GetSolidBrush
757 (back_color), item_rect);
759 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
760 ResPool.GetSolidBrush (fore_color),
761 item_rect, string_format);
763 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
764 CPDrawFocusRectangle (e.Graphics, item_rect,
765 fore_color, back_color);
769 #endregion // CheckedListBox
775 public override void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
777 dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
778 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
779 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
780 dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
781 dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
782 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
783 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
784 dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);
788 public override int DrawComboBoxEditDecorationTop () { return 2;}
789 public override int DrawComboBoxEditDecorationBottom () { return 2;}
790 public override int DrawComboBoxEditDecorationRight () { return 2;}
791 public override int DrawComboBoxEditDecorationLeft () { return 2;}
793 private int DrawComboListBoxDecoration (ComboBoxStyle style)
795 if (style == ComboBoxStyle.Simple)
801 public override int DrawComboListBoxDecorationTop (ComboBoxStyle style)
803 return DrawComboListBoxDecoration (style);
806 public override int DrawComboListBoxDecorationBottom (ComboBoxStyle style)
808 return DrawComboListBoxDecoration (style);
811 public override int DrawComboListBoxDecorationRight (ComboBoxStyle style)
813 return DrawComboListBoxDecoration (style);
816 public override int DrawComboListBoxDecorationLeft (ComboBoxStyle style)
818 return DrawComboListBoxDecoration (style);
821 public override void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
823 if (ctrl.DropDownStyle == ComboBoxStyle.Simple) {
824 DrawComboBoxEditDecorations (dc, ctrl, cl);
827 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame),
828 cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
832 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
834 Color back_color, fore_color;
835 Rectangle text_draw = e.Bounds;
836 StringFormat string_format = new StringFormat ();
837 string_format.FormatFlags = StringFormatFlags.LineLimit;
839 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
840 back_color = ColorHighlight;
841 fore_color = ColorHighlightText;
844 back_color = e.BackColor;
845 fore_color = e.ForeColor;
848 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
851 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
852 ResPool.GetSolidBrush (fore_color),
853 text_draw, string_format);
856 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
857 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
860 string_format.Dispose ();
866 public override int DataGridPreferredColumnWidth { get { return 75;} }
867 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
868 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
869 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
870 public override Color DataGridBackColor { get { return ColorWindow;} }
871 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
872 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
873 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
874 public override Color DataGridGridLineColor { get { return ColorControl;} }
875 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
876 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
877 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
878 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
879 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
880 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
881 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
882 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
884 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
887 if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
888 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
891 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
892 DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
893 DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
894 DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
896 // Paint scrollBar corner
897 if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
899 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
900 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
901 grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
903 if (pe.ClipRectangle.IntersectsWith (corner)) {
904 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
910 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
912 Rectangle modified_area = clip;
913 modified_area.Intersect (grid.grid_drawing.caption_area);
915 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
918 g.DrawString (grid.CaptionText, grid.CaptionFont,
919 ResPool.GetSolidBrush (grid.CaptionForeColor),
920 grid.grid_drawing.caption_area);
923 public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
925 Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
927 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
928 Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
929 rect_bloc.Width = grid.RowHeaderWidth;
930 rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
931 if (clip.IntersectsWith (rect_bloc)) {
932 if (grid.visiblecolumn_count > 0) {
933 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
935 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
939 columns_area.X += grid.RowHeaderWidth;
940 columns_area.Width -= grid.RowHeaderWidth;
944 Rectangle columnshdrs_area_complete = columns_area;
945 columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
947 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
948 columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
951 // Set column painting
952 Rectangle rect_columnhdr = new Rectangle ();
955 rect_columnhdr.Y = columns_area.Y;
956 rect_columnhdr.Height = columns_area.Height;
958 current_clip = new Region (columns_area);
959 g.Clip = current_clip;
960 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
961 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
963 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
964 rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
965 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
967 if (clip.IntersectsWith (rect_columnhdr) == false)
970 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
975 current_clip.Dispose ();
978 Rectangle not_usedarea = columnshdrs_area_complete;
979 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
980 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
981 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
985 public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
987 Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
988 rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
989 Rectangle rect_row = new Rectangle ();
990 rect_row.X = grid.grid_drawing.rowshdrs_area.X;
991 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
992 Rectangle not_usedarea = rowshdrs_area_complete;
994 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
998 g.SetClip (grid.grid_drawing.rowshdrs_area);
999 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1001 rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
1002 rect_row.Height = grid.RowHeight;
1003 rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1005 if (clip.IntersectsWith (rect_row)) {
1006 DataGridPaintRowHeader (g, rect_row, row, grid);
1011 not_usedarea.Height = grid.grid_drawing.rowshdrs_maxheight - grid.grid_drawing.rowshdrs_area.Height;
1012 not_usedarea.Y = grid.grid_drawing.rowshdrs_area.Y + grid.grid_drawing.rowshdrs_area.Height;
1013 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1016 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1018 Point[] arrow = new Point[3];
1020 int centerX, centerY, shiftX;
1023 rect = new Rectangle (bounds.X + bounds.Width /4,
1024 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1026 centerX = rect.Left + rect.Width / 2;
1027 centerY = rect.Top + rect.Height / 2;
1028 shiftX = Math.Max (1, rect.Width / 8);
1031 P1 = new Point (centerX, rect.Top - 1);
1032 P2 = new Point (centerX, rect.Bottom);
1033 P3 = new Point (rect.Right, centerY);
1038 g.FillPolygon (ResPool.GetSolidBrush
1039 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1042 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
1045 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
1048 if (grid.FlatMode == false) {
1051 g.DrawLine (ResPool.GetPen (ColorControlLight),
1052 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1054 g.DrawLine (ResPool.GetPen (ColorControlLight),
1055 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1057 g.DrawLine (ResPool.GetPen (ColorControlDark),
1058 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1060 g.DrawLine (ResPool.GetPen (ColorControlDark),
1061 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1064 if (grid.ShowEditRow && grid.RowsCount > 0 && row == grid.RowsCount && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
1066 g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1071 if (row == grid.CurrentCell.RowNumber) {
1073 if (grid.is_changing == true) {
1074 g.DrawString ("...", grid.Font,
1075 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1080 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1081 DataGridPaintRowHeaderArrow (g, rect, grid);
1087 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1089 Rectangle rect_row = new Rectangle ();
1090 Rectangle not_usedarea = new Rectangle ();
1091 rect_row.X = cells.X;
1093 int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
1095 if (grid.ShowEditRow && grid.RowsCount > 0) {
1099 if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
1103 rect_row.Height = grid.RowHeight;
1104 rect_row.Width = cells.Width;
1105 for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
1106 rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
1107 if (clip.IntersectsWith (rect_row)) {
1108 DataGridPaintRow (g, row, rect_row, false, grid);
1112 if (grid.ShowEditRow && grid.RowsCount > 0 && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
1113 rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
1114 if (clip.IntersectsWith (rect_row)) {
1115 DataGridPaintRow (g, rowcnt, rect_row, true, grid);
1119 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1120 not_usedarea.Y = rect_row.Y + rect_row.Height;
1121 not_usedarea.Width = rect_row.Width = cells.Width;
1122 not_usedarea.X = cells.X;
1124 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1127 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid)
1129 Rectangle rect_cell = new Rectangle ();
1131 Color backcolor, forecolor;
1132 Region prev_clip = g.Clip;
1133 Region current_clip;
1134 Rectangle not_usedarea = new Rectangle ();
1136 rect_cell.Y = row_rect.Y;
1137 rect_cell.Height = row_rect.Height;
1139 // PaintCells at row, column
1140 int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
1141 for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
1143 col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
1145 rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
1146 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1148 current_clip = new Region (row_rect);
1149 g.Clip = current_clip;
1151 if (grid.IsSelected (row)) {
1152 backcolor = grid.SelectionBackColor;
1153 forecolor = grid.SelectionForeColor;
1156 backcolor = grid.BackColor;
1158 backcolor = grid.AlternatingBackColor;
1161 forecolor = grid.ForeColor;
1165 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1166 ResPool.GetSolidBrush (backcolor),
1167 ResPool.GetSolidBrush (forecolor));
1170 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1171 ResPool.GetSolidBrush (backcolor),
1172 ResPool.GetSolidBrush (forecolor),
1173 grid.RightToLeft == RightToLeft.Yes);
1177 current_clip.Dispose ();
1180 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1182 not_usedarea.X = rect_cell.X + rect_cell.Width;
1183 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1184 not_usedarea.Y = row_rect.Y;
1185 not_usedarea.Height = row_rect.Height;
1186 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1191 #endregion // Datagrid
1193 #region DateTimePicker
1195 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1196 // if not showing the numeric updown control then render border
1197 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1198 // draw the outer border
1199 Rectangle button_bounds = dtp.ClientRectangle;
1200 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.All, dtp.BackColor);
1202 // deflate by the border width
1203 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1204 button_bounds.Inflate (-2,-2);
1205 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1206 this.CPDrawComboButton (
1208 dtp.drop_down_arrow_rect,
1213 // render the date part
1214 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1215 // fill the background
1216 dc.FillRectangle (ResPool.GetSolidBrush (ColorWindow), dtp.date_area_rect);
1218 // fill the currently highlighted area
1219 if (dtp.hilight_date_area != Rectangle.Empty) {
1220 dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), dtp.hilight_date_area);
1223 // draw the text part
1224 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1225 StringFormat text_format = new StringFormat();
1226 text_format.LineAlignment = StringAlignment.Center;
1227 text_format.Alignment = StringAlignment.Near;
1228 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1229 text_format.Dispose ();
1233 #endregion // DateTimePicker
1236 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1237 StringFormat text_format;
1243 rect = box.ClientRectangle;
1245 // Needed once the Dark/Light code below is enabled again
1246 //Color disabled = ColorGrayText;
1248 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
1249 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
1251 // TODO: When the Light and Dark methods work this code should be activate it
1252 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
1253 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
1255 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
1257 text_format = new StringFormat();
1258 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1260 size = dc.MeasureString (box.Text, box.Font);
1261 width = (int) size.Width;
1263 if (width > box.Width - 16)
1264 width = box.Width - 16;
1266 y = box.Font.Height / 2;
1269 dc.DrawLine (pen_dark, 0, y, 8, y); // top
1270 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
1271 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
1272 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
1274 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
1275 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
1277 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
1278 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
1280 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
1281 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
1286 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1288 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
1289 new RectangleF (10, 0, width, box.Font.Height), text_format);
1291 text_format.Dispose ();
1294 public override Size GroupBoxDefaultSize {
1296 return new Size (200,100);
1302 public override Size HScrollBarDefaultSize {
1304 return new Size (80, this.ScrollBarButtonSize);
1308 #endregion // HScrollBar
1311 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1313 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
1315 if (label.Enabled) {
1316 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1318 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
1323 public override Size LabelDefaultSize {
1325 return new Size (100, 23);
1331 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1335 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
1337 for (int i = 0; i < label.num_pieces; i++) {
1339 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1343 color = label.GetLinkColor (label.pieces[i], i);
1345 if (label.pieces[i].link == null)
1346 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),
1347 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1349 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
1350 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1352 if (label.pieces[i].focused) {
1353 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1358 #endregion // LinkLabel
1363 private int DrawListBoxDecorationSize (BorderStyle border_style)
1365 switch (border_style) {
1366 case BorderStyle.Fixed3D:
1368 case BorderStyle.FixedSingle:
1370 case BorderStyle.None:
1379 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1381 Color back_color, fore_color;
1382 StringFormat string_format = ctrl.GetFormatString ();
1384 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1385 back_color = ColorHighlight;
1386 fore_color = ColorHighlightText;
1389 back_color = e.BackColor;
1390 fore_color = e.ForeColor;
1393 e.Graphics.FillRectangle (ResPool.GetSolidBrush
1394 (back_color), e.Bounds);
1396 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1397 ResPool.GetSolidBrush (fore_color),
1398 e.Bounds.X, e.Bounds.Y, string_format);
1400 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1401 CPDrawFocusRectangle (e.Graphics, e.Bounds,
1402 fore_color, back_color);
1410 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1412 bool details = control.View == View.Details;
1414 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);
1415 int first = control.FirstVisibleIndex;
1417 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1418 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1419 DrawListViewItem (dc, control, control.Items [i]);
1422 // draw the gridlines
1423 if (details && control.GridLines) {
1424 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1425 2 : control.Font.Height + 2;
1427 // draw vertical gridlines
1428 foreach (ColumnHeader col in control.Columns)
1429 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1430 col.Rect.Right, top,
1431 col.Rect.Right, control.TotalHeight);
1432 // draw horizontal gridlines
1433 ListViewItem last_item = null;
1434 foreach (ListViewItem item in control.Items) {
1435 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1436 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1437 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1441 // draw a line after at the bottom of the last item
1442 if (last_item != null) {
1443 dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
1444 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1445 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1447 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1453 // Draw corner between the two scrollbars
1454 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1455 Rectangle rect = new Rectangle ();
1456 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1457 rect.Width = control.v_scroll.Width;
1458 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1459 rect.Height = control.h_scroll.Height;
1460 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), rect);
1465 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1467 bool details = (control.View == View.Details);
1469 // border is drawn directly in the Paint method
1470 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1471 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor),
1472 0, 0, control.TotalWidth, control.Font.Height + 5);
1473 if (control.Columns.Count > 0) {
1474 foreach (ColumnHeader col in control.Columns) {
1475 Rectangle rect = col.Rect;
1476 rect.X -= control.h_marker;
1478 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1479 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1481 state = ButtonState.Flat;
1482 this.CPDrawButton (dc, rect, state);
1485 if (rect.Width <= 0)
1487 dc.DrawString (col.Text, DefaultFont,
1488 ResPool.GetSolidBrush (ColorControlText),
1495 // draws the ListViewItem of the given index
1496 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1498 Rectangle rect_checkrect = item.CheckRectReal;
1499 Rectangle rect_iconrect = item.GetBounds (ItemBoundsPortion.Icon);
1500 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1501 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1503 if (control.CheckBoxes) {
1504 if (control.StateImageList == null) {
1505 // Make sure we've got at least a line width of 1
1506 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1507 int scale = Math.Max (1, rect_checkrect.Width / 12);
1509 // set the checkbox background
1510 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
1512 // define a rectangle inside the border area
1513 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1514 rect_checkrect.Y + 2,
1515 rect_checkrect.Width - 4,
1516 rect_checkrect.Height - 4);
1517 Pen pen = new Pen (this.ColorWindowText, 2);
1518 dc.DrawRectangle (pen, rect);
1520 // Need to draw a check-mark
1523 // adjustments to get the check-mark at the right place
1524 rect.X ++; rect.Y ++;
1525 // following logic is taken from DrawFrameControl method
1526 for (int i = 0; i < check_wd; i++) {
1527 dc.DrawLine (pen, rect.Left + check_wd / 2,
1528 rect.Top + check_wd + i,
1529 rect.Left + check_wd / 2 + 2 * scale,
1530 rect.Top + check_wd + 2 * scale + i);
1532 rect.Left + check_wd / 2 + 2 * scale,
1533 rect.Top + check_wd + 2 * scale + i,
1534 rect.Left + check_wd / 2 + 6 * scale,
1535 rect.Top + check_wd - 2 * scale + i);
1540 if (item.Checked && control.StateImageList.Images.Count > 1)
1541 control.StateImageList.Draw (dc,
1542 rect_checkrect.Location, 1);
1543 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1544 control.StateImageList.Draw (dc,
1545 rect_checkrect.Location, 0);
1549 // Item is drawn as a special case, as it is not just text
1550 if (control.View == View.LargeIcon) {
1551 if (item.ImageIndex > -1 &&
1552 control.LargeImageList != null &&
1553 item.ImageIndex < control.LargeImageList.Images.Count)
1554 control.LargeImageList.Draw (dc, rect_iconrect.Location,
1558 if (item.ImageIndex > -1 &&
1559 control.SmallImageList != null &&
1560 item.ImageIndex < control.SmallImageList.Images.Count)
1561 control.SmallImageList.Draw (dc, rect_iconrect.Location,
1565 // draw the item text
1566 // format for the item text
1567 StringFormat format = new StringFormat ();
1568 if (control.View == View.SmallIcon)
1569 format.LineAlignment = StringAlignment.Near;
1571 format.LineAlignment = StringAlignment.Center;
1572 if (control.View == View.LargeIcon)
1573 format.Alignment = StringAlignment.Center;
1575 format.Alignment = StringAlignment.Near;
1577 if (!control.LabelWrap)
1578 format.FormatFlags = StringFormatFlags.NoWrap;
1580 if (item.Selected) {
1581 if (control.View == View.Details) {
1582 if (control.FullRowSelect) {
1583 // fill the entire rect excluding the checkbox
1584 full_rect.Location = item.GetBounds (ItemBoundsPortion.Label).Location;
1585 dc.FillRectangle (this.ResPool.GetSolidBrush
1586 (this.ColorHighlight), full_rect);
1589 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1591 text_rect.Width = text_size.Width;
1592 dc.FillRectangle (this.ResPool.GetSolidBrush
1593 (this.ColorHighlight), text_rect);
1597 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1599 Point loc = text_rect.Location;
1600 loc.X += (text_rect.Width - text_size.Width) / 2;
1601 text_rect.Width = text_size.Width;*/
1602 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHighlight),
1607 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1609 if (item.Text != null && item.Text.Length > 0) {
1611 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1612 (this.ColorHighlightText), text_rect, format);
1614 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1615 (item.ForeColor), text_rect, format);
1618 if (control.View == View.Details && control.Columns.Count > 0) {
1619 // draw subitems for details view
1620 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1621 int count = (control.Columns.Count < subItems.Count ?
1622 control.Columns.Count : subItems.Count);
1626 ListViewItem.ListViewSubItem subItem;
1627 Rectangle sub_item_rect = text_rect;
1629 // set the format for subitems
1630 format.FormatFlags = StringFormatFlags.NoWrap;
1632 // 0th subitem is the item already drawn
1633 for (int index = 1; index < count; index++) {
1634 subItem = subItems [index];
1635 col = control.Columns [index];
1636 format.Alignment = col.Format.Alignment;
1637 sub_item_rect.X = col.Rect.Left + 3;
1638 sub_item_rect.Width = col.Wd - 6;
1639 sub_item_rect.X -= control.h_marker;
1641 SolidBrush sub_item_back_br = null;
1642 SolidBrush sub_item_fore_br = null;
1643 Font sub_item_font = null;
1645 if (item.UseItemStyleForSubItems) {
1646 sub_item_back_br = this.ResPool.GetSolidBrush
1648 sub_item_fore_br = this.ResPool.GetSolidBrush
1650 sub_item_font = item.Font;
1653 sub_item_back_br = this.ResPool.GetSolidBrush
1654 (subItem.BackColor);
1655 sub_item_fore_br = this.ResPool.GetSolidBrush
1656 (subItem.ForeColor);
1657 sub_item_font = subItem.Font;
1660 // In case of fullrowselect, background is filled
1661 // for the entire rect above
1662 if (item.Selected && control.FullRowSelect) {
1663 if (subItem.Text != null && subItem.Text.Length > 0)
1664 dc.DrawString (subItem.Text, sub_item_font,
1665 this.ResPool.GetSolidBrush
1666 (this.ColorHighlightText),
1667 sub_item_rect, format);
1670 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1671 if (subItem.Text != null && subItem.Text.Length > 0)
1672 dc.DrawString (subItem.Text, sub_item_font,
1674 sub_item_rect, format);
1676 sub_item_rect.X += col.Wd;
1683 CPDrawFocusRectangle (dc, text_rect, ColorHighlightText, ColorHighlight);
1685 CPDrawFocusRectangle (dc, text_rect, control.ForeColor, control.BackColor);
1692 public override Size ListViewCheckBoxSize {
1693 get { return new Size (16, 16); }
1696 public override int ListViewColumnHeaderHeight {
1700 public override int ListViewDefaultColumnWidth {
1704 public override int ListViewVerticalSpacing {
1708 public override int ListViewEmptyColumnWidth {
1712 public override int ListViewHorizontalSpacing {
1716 public override Size ListViewDefaultSize {
1717 get { return new Size (121, 97); }
1719 #endregion // ListView
1722 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1727 if (item.Visible == false) {
1733 if (item.Separator == true) {
1734 item.Height = SEPARATOR_HEIGHT / 2;
1739 if (item.MeasureEventDefined) {
1740 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1741 item.PerformMeasureItem (mi);
1742 item.Height = mi.ItemHeight;
1743 item.Width = mi.ItemWidth;
1747 size = dc.MeasureString (item.Text, MenuFont);
1748 item.Width = (int) size.Width;
1749 item.Height = (int) size.Height;
1752 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1753 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1754 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1755 item.Width += MENU_TAB_SPACE + (int) size.Width;
1758 item.Width += 4 + (MenuCheckSize.Width * 2);
1760 item.Width += MENU_BAR_ITEMS_SPACE;
1764 if (item.Height < MenuHeight)
1765 item.Height = MenuHeight;
1769 // Updates the menu rect and returns the height
1770 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1776 foreach (MenuItem item in menu.MenuItems) {
1778 CalcItemSize (dc, item, y, x, true);
1780 if (x + item.Width > width) {
1788 item.MenuBar = true;
1790 if (y + item.Height > menu.Height)
1791 menu.Height = item.Height + y;
1798 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1806 while (start < menu.MenuItems.Count) {
1809 for (i = start; i < menu.MenuItems.Count; i++) {
1810 MenuItem item = menu.MenuItems [i];
1812 if ((i != start) && (item.Break || item.BarBreak))
1815 CalcItemSize (dc, item, y, x, false);
1818 if (item.Width > max)
1822 // Replace the -1 by the menu width (separators)
1823 for (n = start; n < i; n++, start++)
1824 menu.MenuItems [n].Width = max;
1826 if (y > menu.Height)
1838 menu.Width += SM_CXBORDER;
1839 menu.Height += SM_CYBORDER;
1842 // Draws a menu bar in a window
1843 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1845 if (menu.Height == 0)
1846 CalcMenuBarSize (dc, menu, rect.Width);
1848 bool keynav = (menu as MainMenu).tracker.Navigating;
1849 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1850 string_format_menu_menubar_text.HotkeyPrefix = hp;
1851 string_format_menu_text.HotkeyPrefix = hp;
1853 rect.Height = menu.Height;
1854 dc.FillRectangle (ResPool.GetSolidBrush(ColorMenu), rect);
1856 for (int i = 0; i < menu.MenuItems.Count; i++) {
1857 MenuItem item = menu.MenuItems [i];
1858 Rectangle item_rect = item.bounds;
1859 item_rect.X += rect.X;
1860 item_rect.Y += rect.Y;
1861 item.MenuHeight = menu.Height;
1862 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1866 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1868 StringFormat string_format;
1869 Rectangle rect_text = e.Bounds;
1871 if (item.Visible == false)
1875 string_format = string_format_menu_menubar_text;
1877 string_format = string_format_menu_text;
1879 if (item.Separator == true) {
1880 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
1881 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1883 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
1884 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1890 rect_text.X += MenuCheckSize.Width;
1892 if (item.BarBreak) { /* Draw vertical break bar*/
1893 Rectangle rect = e.Bounds;
1896 rect.Height = item.MenuHeight - 6;
1898 e.Graphics.DrawLine (ResPool.GetPen (ColorControlDark),
1899 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1901 e.Graphics.DrawLine (ResPool.GetPen (ColorControlLight),
1902 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1908 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1909 color_text = ColorHighlightText;
1910 color_back = ColorHighlight;
1912 color_text = ColorMenuText;
1913 color_back = ColorMenu;
1916 /* Draw background */
1917 Rectangle rect_back = e.Bounds;
1919 rect_back.Width -=2;
1920 e.Graphics.FillRectangle (ResPool.GetSolidBrush (color_back), rect_back);
1923 e.Graphics.DrawString (item.Text, e.Font,
1924 ResPool.GetSolidBrush (color_text),
1925 rect_text, string_format);
1927 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1928 string str = item.GetShortCutText ();
1929 Rectangle rect = rect_text;
1931 rect.Width -= item.XTab;
1933 e.Graphics.DrawString (str, e.Font, ResPool.GetSolidBrush (color_text),
1934 rect, string_format_menu_shortcut);
1937 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
1938 Color.Black, rect_text, string_format);
1942 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
1944 int cx = MenuCheckSize.Width;
1945 int cy = MenuCheckSize.Height;
1946 Bitmap bmp = new Bitmap (cx, cy);
1947 Graphics gr = Graphics.FromImage (bmp);
1948 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1949 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
1950 bmp.MakeTransparent ();
1953 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1954 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1956 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1957 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1964 /* Draw checked or radio */
1965 if (item.MenuBar == false && item.Checked) {
1967 Rectangle area = e.Bounds;
1968 int cx = MenuCheckSize.Width;
1969 int cy = MenuCheckSize.Height;
1970 Bitmap bmp = new Bitmap (cx, cy);
1971 Graphics gr = Graphics.FromImage (bmp);
1972 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1974 if (item.RadioCheck)
1975 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
1977 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
1979 bmp.MakeTransparent ();
1980 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1987 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
1990 dc.FillRectangle (ResPool.GetSolidBrush
1991 (ColorMenu), cliparea);
1993 /* Draw menu borders */
1994 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
1995 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1997 dc.DrawLine (ResPool.GetPen (ColorHighlightText),
1998 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
2000 dc.DrawLine (ResPool.GetPen (ColorControlDark),
2001 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
2003 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
2004 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
2006 dc.DrawLine (ResPool.GetPen (ColorControlDark),
2007 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
2009 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark),
2010 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
2012 for (int i = 0; i < menu.MenuItems.Count; i++)
2013 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
2014 MenuItem item = menu.MenuItems [i];
2015 item.MenuHeight = menu.Height;
2016 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
2017 item.bounds, i, item.Status));
2023 #region MonthCalendar
2025 // draw the month calendar
2026 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2028 Rectangle client_rectangle = mc.ClientRectangle;
2029 Size month_size = mc.SingleMonthSize;
2030 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2031 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2032 Size date_cell_size = (Size)((object)mc.date_cell_size);
2034 // draw the singlecalendars
2037 // adjust for the position of the specific month
2038 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2042 y_offset += month_size.Height + calendar_spacing.Height;
2044 // now adjust for x position
2045 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2049 x_offset += month_size.Width + calendar_spacing.Width;
2056 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2057 if (month_rect.IntersectsWith (clip_rectangle)) {
2069 Rectangle bottom_rect = new Rectangle (
2071 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2072 client_rectangle.Width,
2073 date_cell_size.Height + 2);
2074 // draw the today date if it's set
2075 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2077 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
2079 int today_offset = 5;
2080 if (mc.ShowTodayCircle)
2082 Rectangle today_circle_rect = new Rectangle (
2083 client_rectangle.X + 5,
2084 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2085 date_cell_size.Width,
2086 date_cell_size.Height);
2087 DrawTodayCircle (dc, today_circle_rect);
2088 today_offset += date_cell_size.Width + 5;
2090 // draw today's date
2091 StringFormat text_format = new StringFormat();
2092 text_format.LineAlignment = StringAlignment.Center;
2093 text_format.Alignment = StringAlignment.Near;
2094 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2095 Rectangle today_rect = new Rectangle (
2096 today_offset + client_rectangle.X,
2097 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2098 Math.Max(client_rectangle.Width - today_offset, 0),
2099 date_cell_size.Height);
2100 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
2101 text_format.Dispose ();
2102 bold_font.Dispose ();
2106 // finally paint the borders of the calendars as required
2107 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2108 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2109 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
2110 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2111 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
2113 Rectangle rect = new Rectangle (
2114 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2116 calendar_spacing.Width,
2117 client_rectangle.Height);
2118 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2119 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2123 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2124 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2125 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
2126 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2127 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
2129 Rectangle rect = new Rectangle (
2131 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2132 client_rectangle.Width,
2133 calendar_spacing.Height);
2134 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2135 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2140 // draw the drop down border if need
2141 if (mc.owner != null) {
2142 Rectangle bounds = mc.ClientRectangle;
2143 if (clip_rectangle.Contains (mc.Location)) {
2144 // find out if top or left line to draw
2145 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2147 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2149 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2150 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2153 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2154 // find out if bottom or right line to draw
2155 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2156 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2158 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2159 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2165 // darws a single part of the month calendar (with one month)
2166 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2168 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2169 Size title_size = (Size)((object)mc.title_size);
2170 Size date_cell_size = (Size)((object)mc.date_cell_size);
2171 DateTime current_month = (DateTime)((object)mc.current_month);
2173 // set up some standard string formating variables
2174 StringFormat text_format = new StringFormat();
2175 text_format.LineAlignment = StringAlignment.Center;
2176 text_format.Alignment = StringAlignment.Center;
2179 // draw the title back ground
2180 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2181 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2182 if (title_rect.IntersectsWith (clip_rectangle)) {
2183 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2185 string title_text = this_month.ToString ("MMMM yyyy");
2186 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2188 // draw previous and next buttons if it's time
2189 if (row == 0 && col == 0)
2191 // draw previous button
2192 DrawMonthCalendarButton (
2198 (System.Drawing.Size)((object)mc.button_size),
2201 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2204 DrawMonthCalendarButton (
2210 (System.Drawing.Size)((object)mc.button_size),
2215 // set the week offset and draw week nums if needed
2216 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2217 Rectangle day_name_rect = new Rectangle(
2219 rectangle.Y + title_size.Height,
2220 (7 + col_offset) * date_cell_size.Width,
2221 date_cell_size.Height);
2222 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2223 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
2224 // draw the day names
2225 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2226 for (int i=0; i < 7; i++)
2228 int position = i - (int) first_day_of_week;
2231 position = 7 + position;
2234 Rectangle day_rect = new Rectangle(
2235 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2237 date_cell_size.Width,
2238 date_cell_size.Height);
2239 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2242 // draw the vertical divider
2243 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2245 ResPool.GetPen (mc.ForeColor),
2246 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2247 rectangle.Y + vert_divider_y,
2248 rectangle.Right - mc.divider_line_offset,
2249 rectangle.Y + vert_divider_y);
2253 // draw the actual date items in the grid (including the week numbers)
2254 Rectangle date_rect = new Rectangle (
2256 rectangle.Y + title_size.Height + date_cell_size.Height,
2257 date_cell_size.Width,
2258 date_cell_size.Height);
2259 int month_row_count = 0;
2260 bool draw_week_num_divider = false;
2261 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2262 for (int i=0; i < 6; i++)
2264 // establish if this row is in our clip_area
2265 Rectangle row_rect = new Rectangle (
2267 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2268 date_cell_size.Width * 7,
2269 date_cell_size.Height);
2270 if (mc.ShowWeekNumbers) {
2271 row_rect.Width += date_cell_size.Width;
2274 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2276 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
2278 // establish if this is a valid week to draw
2279 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2280 month_row_count = i;
2283 // draw the week number if required
2284 if (mc.ShowWeekNumbers && month_row_count == i) {
2285 if (!draw_week_num_divider) {
2286 draw_week_num_divider = draw_row;
2288 // get the week for this row
2289 int week = mc.GetWeekOfYear (current_date);
2295 ResPool.GetSolidBrush (mc.TitleBackColor),
2299 date_rect.Offset(date_cell_size.Width, 0);
2302 // only draw the days if we have to
2303 if(month_row_count == i) {
2304 for (int j=0; j < 7; j++)
2307 DrawMonthCalendarDate (
2318 current_date = current_date.AddDays(1);
2319 date_rect.Offset(date_cell_size.Width, 0);
2322 // shift the rectangle down one row
2323 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2324 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2328 // month_row_count is zero based, so add one
2331 // draw week numbers if required
2332 if (draw_week_num_divider) {
2335 ResPool.GetPen (mc.ForeColor),
2336 rectangle.X + date_cell_size.Width - 1,
2337 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2338 rectangle.X + date_cell_size.Width - 1,
2339 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2341 text_format.Dispose ();
2344 // draws the pervious or next button
2345 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2347 bool is_clicked = false;
2348 Rectangle button_rect;
2349 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2350 Point[] arrow_path = new Point[3];
2351 // prepare the button
2354 is_clicked = mc.is_previous_clicked;
2355 button_rect = new Rectangle (
2356 rectangle.X + 1 + x_offset,
2357 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2358 Math.Max(button_size.Width - 1, 0),
2359 Math.Max(button_size.Height - 1, 0));
2360 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2361 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2363 arrow_rect.Offset(1,1);
2365 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2366 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2367 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2371 is_clicked = mc.is_next_clicked;
2372 button_rect = new Rectangle (
2373 rectangle.Right - 1 - x_offset - button_size.Width,
2374 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2375 Math.Max(button_size.Width - 1, 0),
2376 Math.Max(button_size.Height - 1, 0));
2377 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2378 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2380 arrow_rect.Offset(1,1);
2382 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2383 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2384 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2387 // fill the background
2388 dc.FillRectangle (SystemBrushes.Control, button_rect);
2391 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2394 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
2397 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2401 // draws one day in the calendar grid
2402 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2403 Color date_color = mc.ForeColor;
2404 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2406 // find out if we are the lead of the first calendar or the trail of the last calendar
2407 if (date.Year != month.Year || date.Month != month.Month) {
2408 DateTime check_date = month.AddMonths (-1);
2409 // check if it's the month before
2410 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2411 date_color = mc.TrailingForeColor;
2413 // check if it's the month after
2414 check_date = month.AddMonths (1);
2415 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2416 date_color = mc.TrailingForeColor;
2422 date_color = mc.ForeColor;
2426 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2427 // see if the date is in the start of selection
2428 date_color = mc.BackColor;
2429 // draw the left hand of the back ground
2430 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2431 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2432 } else if (date == mc.SelectionStart) {
2433 // see if the date is in the start of selection
2434 date_color = mc.BackColor;
2435 // draw the left hand of the back ground
2436 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2437 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2438 // fill the other side as a straight rect
2439 if (date < mc.SelectionEnd)
2441 // use rectangle instead of rectangle to go all the way to edge of rect
2442 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2443 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2444 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2446 } else if (date == mc.SelectionEnd) {
2447 // see if it is the end of selection
2448 date_color = mc.BackColor;
2449 // draw the left hand of the back ground
2450 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2451 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2452 // fill the other side as a straight rect
2453 if (date > mc.SelectionStart) {
2454 selection_rect.X = rectangle.X;
2455 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2456 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2458 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2459 // now see if it's in the middle
2460 date_color = mc.BackColor;
2461 // draw the left hand of the back ground
2462 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2463 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2466 // set up some standard string formating variables
2467 StringFormat text_format = new StringFormat();
2468 text_format.LineAlignment = StringAlignment.Center;
2469 text_format.Alignment = StringAlignment.Center;
2472 // establish if it's a bolded font
2474 if (mc.IsBoldedDate (date)) {
2475 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2480 // just draw the date now
2481 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2483 // today circle if needed
2484 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2485 DrawTodayCircle (dc, interior);
2488 // draw the selection grid
2489 if (mc.is_date_clicked && mc.clicked_date == date) {
2490 using (Pen pen = new Pen (Color.Black, 1) ) {
2491 pen.DashStyle = DashStyle.Dot;
2492 dc.DrawRectangle (pen, interior);
2495 text_format.Dispose ();
2498 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2499 Color circle_color = Color.FromArgb (248, 0, 0);
2500 // draw the left hand of the circle
2501 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2502 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2503 Point [] curve_points = new Point [3];
2504 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2505 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2506 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2508 using (Pen pen = new Pen (circle_color, 2)) {
2509 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2510 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2511 dc.DrawCurve (pen, curve_points);
2512 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2516 #endregion // MonthCalendar
2519 public override Size PanelDefaultSize {
2521 return new Size (200, 100);
2527 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2528 Rectangle client = pb.ClientRectangle;
2530 // FIXME - instead of drawing the whole picturebox every time
2531 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2532 // Also, we only need a background fill where no image goes
2533 if (pb.Image != null) {
2534 switch (pb.SizeMode) {
2535 case PictureBoxSizeMode.StretchImage:
2536 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2539 case PictureBoxSizeMode.CenterImage:
2540 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2541 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2544 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2546 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2553 // We only get here if no image is set. At least paint the background
2554 dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
2557 public override Size PictureBoxDefaultSize {
2559 return new Size (100, 50);
2562 #endregion // PictureBox
2565 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2567 Rectangle block_rect;
2568 Rectangle client_area = ctrl.client_area;
2569 int space_betweenblocks = 2;
2574 block_width = ((client_area.Height) * 2 ) / 3;
2575 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2576 increment = block_width + space_betweenblocks;
2579 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All & ~Border3DSide.Middle, ColorControl);
2582 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2583 while ((block_rect.X - client_area.X) < barpos_pixels) {
2585 if (clip_rect.IntersectsWith (block_rect) == true) {
2586 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2589 block_rect.X += increment;
2593 public override Size ProgressBarDefaultSize {
2595 return new Size (100, 23);
2599 #endregion // ProgressBar
2602 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2603 StringFormat text_format;
2604 Rectangle client_rectangle;
2605 Rectangle text_rectangle;
2606 Rectangle radiobutton_rectangle;
2607 int radiobutton_size = 12;
2608 int radiobutton_space = 4;
2610 client_rectangle = radio_button.ClientRectangle;
2611 text_rectangle = client_rectangle;
2612 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2614 text_format = new StringFormat();
2615 text_format.Alignment = StringAlignment.Near;
2616 text_format.LineAlignment = StringAlignment.Center;
2617 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2619 /* Calculate the position of text and checkbox rectangle */
2620 if (radio_button.appearance!=Appearance.Button) {
2621 switch(radio_button.radiobutton_alignment) {
2622 case ContentAlignment.BottomCenter: {
2623 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2624 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2625 text_rectangle.X=client_rectangle.X;
2626 text_rectangle.Width=client_rectangle.Width;
2627 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2631 case ContentAlignment.BottomLeft: {
2632 radiobutton_rectangle.X=client_rectangle.Left;
2633 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2634 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2635 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2639 case ContentAlignment.BottomRight: {
2640 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2641 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2642 text_rectangle.X=client_rectangle.X;
2643 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2647 case ContentAlignment.MiddleCenter: {
2648 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2649 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2650 text_rectangle.X=client_rectangle.X;
2651 text_rectangle.Width=client_rectangle.Width;
2656 case ContentAlignment.MiddleLeft: {
2657 radiobutton_rectangle.X=client_rectangle.Left;
2658 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2659 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2660 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2664 case ContentAlignment.MiddleRight: {
2665 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2666 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2667 text_rectangle.X=client_rectangle.X;
2668 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2672 case ContentAlignment.TopCenter: {
2673 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2674 radiobutton_rectangle.Y=client_rectangle.Top;
2675 text_rectangle.X=client_rectangle.X;
2676 text_rectangle.Y=radiobutton_size+radiobutton_space;
2677 text_rectangle.Width=client_rectangle.Width;
2678 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2682 case ContentAlignment.TopLeft: {
2683 radiobutton_rectangle.X=client_rectangle.Left;
2684 radiobutton_rectangle.Y=client_rectangle.Top;
2685 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2686 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2690 case ContentAlignment.TopRight: {
2691 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2692 radiobutton_rectangle.Y=client_rectangle.Top;
2693 text_rectangle.X=client_rectangle.X;
2694 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2699 text_rectangle.X=client_rectangle.X;
2700 text_rectangle.Width=client_rectangle.Width;
2703 /* Set the horizontal alignment of our text */
2704 switch(radio_button.text_alignment) {
2705 case ContentAlignment.BottomLeft:
2706 case ContentAlignment.MiddleLeft:
2707 case ContentAlignment.TopLeft: {
2708 text_format.Alignment=StringAlignment.Near;
2712 case ContentAlignment.BottomCenter:
2713 case ContentAlignment.MiddleCenter:
2714 case ContentAlignment.TopCenter: {
2715 text_format.Alignment=StringAlignment.Center;
2719 case ContentAlignment.BottomRight:
2720 case ContentAlignment.MiddleRight:
2721 case ContentAlignment.TopRight: {
2722 text_format.Alignment=StringAlignment.Far;
2727 /* Set the vertical alignment of our text */
2728 switch(radio_button.text_alignment) {
2729 case ContentAlignment.TopLeft:
2730 case ContentAlignment.TopCenter:
2731 case ContentAlignment.TopRight: {
2732 text_format.LineAlignment=StringAlignment.Near;
2736 case ContentAlignment.BottomLeft:
2737 case ContentAlignment.BottomCenter:
2738 case ContentAlignment.BottomRight: {
2739 text_format.LineAlignment=StringAlignment.Far;
2743 case ContentAlignment.MiddleLeft:
2744 case ContentAlignment.MiddleCenter:
2745 case ContentAlignment.MiddleRight: {
2746 text_format.LineAlignment=StringAlignment.Center;
2751 ButtonState state = ButtonState.Normal;
2752 if (radio_button.FlatStyle == FlatStyle.Flat) {
2753 state |= ButtonState.Flat;
2756 if (radio_button.Checked) {
2757 state |= ButtonState.Checked;
2761 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2763 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2765 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2766 text_format.Dispose ();
2769 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2771 SolidBrush sb = new SolidBrush(radio_button.BackColor);
2772 dc.FillRectangle(sb, radio_button.ClientRectangle);
2775 if (radio_button.appearance==Appearance.Button) {
2776 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2777 DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
2779 CPDrawButton(dc, radio_button.ClientRectangle, state);
2782 // establish if we are rendering a flat style of some sort
2783 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2784 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2786 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
2791 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2795 // offset the text if it's pressed and a button
2796 if (radio_button.Appearance == Appearance.Button) {
2797 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
2798 text_rectangle.X ++;
2799 text_rectangle.Y ++;
2802 text_rectangle.Inflate(-4,-4);
2805 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
2806 dc.DrawString (radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
2808 if (radio_button.Enabled) {
2809 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
2810 dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2811 } else if (radio_button.FlatStyle == FlatStyle.Flat) {
2812 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
2814 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorControlText, text_rectangle, text_format);
2818 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2820 if (radio_button.Focused) {
2821 if (radio_button.FlatStyle != FlatStyle.Flat) {
2822 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
2824 dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
2829 // renders a radio button with the Flat and Popup FlatStyle
2830 protected void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2834 if (radio_button.Enabled) {
2835 // draw the outer flatstyle arcs
2836 if (radio_button.FlatStyle == FlatStyle.Flat) {
2837 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
2839 // fill in the area depending on whether or not the mouse is hovering
2840 if (radio_button.is_entered && radio_button.Capture) {
2841 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2843 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2846 // must be a popup radio button
2848 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
2850 if (radio_button.is_entered || radio_button.Capture) {
2851 // draw the popup 3d button knob
2852 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2854 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
2855 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
2858 // just draw lighter flatstyle outer circle
2859 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);
2864 // fill control background color regardless of actual backcolor
2865 graphics.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2866 // draw the ark as control dark
2867 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
2871 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2872 if (radio_button.Checked) {
2873 SolidBrush buttonBrush;
2875 if (!radio_button.Enabled) {
2876 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorControl));
2877 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
2878 buttonBrush = ResPool.GetSolidBrush (this.ColorControlText);
2880 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
2882 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
2886 public override Size RadioButtonDefaultSize {
2888 return new Size (104,24);
2891 #endregion // RadioButton
2894 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2896 int scrollbutton_width = bar.scrollbutton_width;
2897 int scrollbutton_height = bar.scrollbutton_height;
2898 Rectangle first_arrow_area;
2899 Rectangle second_arrow_area;
2900 Rectangle thumb_pos;
2902 thumb_pos = bar.ThumbPos;
2905 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2906 bar.FirstArrowArea = first_arrow_area;
2908 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2909 bar.SecondArrowArea = second_arrow_area;
2911 thumb_pos.Width = bar.Width;
2912 bar.ThumbPos = thumb_pos;
2915 if (clip.IntersectsWith (first_arrow_area))
2916 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2917 if (clip.IntersectsWith (second_arrow_area))
2918 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2921 switch (bar.thumb_moving) {
2922 case ScrollBar.ThumbMoving.None: {
2923 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
2926 case ScrollBar.ThumbMoving.Forward: {
2927 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
2931 case ScrollBar.ThumbMoving.Backwards: {
2932 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
2940 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2941 bar.FirstArrowArea = first_arrow_area;
2943 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2944 bar.SecondArrowArea = second_arrow_area;
2946 thumb_pos.Height = bar.Height;
2947 bar.ThumbPos = thumb_pos;
2950 if (clip.IntersectsWith (first_arrow_area))
2951 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2952 if (clip.IntersectsWith (second_arrow_area))
2953 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2956 switch (bar.thumb_moving) {
2957 case ScrollBar.ThumbMoving.None: {
2958 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
2962 case ScrollBar.ThumbMoving.Forward: {
2963 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
2967 case ScrollBar.ThumbMoving.Backwards: {
2968 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
2975 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
2978 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
2980 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
2981 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
2984 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
2986 Rectangle r = new Rectangle( 0,
2987 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
2988 Rectangle intersect = Rectangle.Intersect( clip, r );
2990 if ( intersect != Rectangle.Empty )
2992 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
2993 dc.FillRectangle( h, intersect );
2997 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
2999 Rectangle r = new Rectangle( 0, scrollbutton_height,
3000 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3001 Rectangle intersect = Rectangle.Intersect( clip, r );
3003 if ( intersect != Rectangle.Empty )
3004 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
3007 r.Y = thumb_pos.Y + thumb_pos.Height;
3008 r.Width = bar.ClientRectangle.Width;
3009 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3011 intersect = Rectangle.Intersect( clip, r );
3012 if ( intersect != Rectangle.Empty )
3013 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3016 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3018 Rectangle r = new Rectangle( 0, scrollbutton_height,
3019 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3020 Rectangle intersect = Rectangle.Intersect( clip, r );
3022 if ( intersect != Rectangle.Empty )
3023 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3026 r.Y = thumb_pos.Y + thumb_pos.Height;
3027 r.Width = bar.ClientRectangle.Width;
3028 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3030 intersect = Rectangle.Intersect( clip, r );
3031 if ( intersect != Rectangle.Empty )
3032 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3035 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
3037 Rectangle r = new Rectangle( scrollbutton_width,
3038 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
3039 Rectangle intersect = Rectangle.Intersect( clip, r );
3041 if ( intersect != Rectangle.Empty )
3042 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3045 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3047 Rectangle r = new Rectangle( scrollbutton_width, 0,
3048 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3049 Rectangle intersect = Rectangle.Intersect( clip, r );
3051 if ( intersect != Rectangle.Empty )
3052 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3054 r.X = thumb_pos.X + thumb_pos.Width;
3056 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3057 r.Height = bar.ClientRectangle.Height;
3059 intersect = Rectangle.Intersect( clip, r );
3060 if ( intersect != Rectangle.Empty )
3061 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3064 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3066 Rectangle r = new Rectangle( scrollbutton_width, 0,
3067 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3068 Rectangle intersect = Rectangle.Intersect( clip, r );
3070 if ( intersect != Rectangle.Empty )
3071 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3073 r.X = thumb_pos.X + thumb_pos.Width;
3075 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3076 r.Height = bar.ClientRectangle.Height;
3078 intersect = Rectangle.Intersect( clip, r );
3079 if ( intersect != Rectangle.Empty )
3080 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3083 public override int ScrollBarButtonSize {
3086 #endregion // ScrollBar
3089 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3090 Rectangle area = sb.ClientRectangle;
3091 int horz_border = 2;
3092 int vert_border = 2;
3094 dc.FillRectangle (GetControlBackBrush (sb.BackColor), clip);
3096 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3097 string text = sb.Text;
3098 StringFormat string_format = new StringFormat ();
3099 string_format.Trimming = StringTrimming.Character;
3100 string_format.FormatFlags = StringFormatFlags.NoWrap;
3102 if (text [0] == '\t') {
3103 string_format.Alignment = StringAlignment.Center;
3104 text = text.Substring (1);
3105 if (text [0] == '\t') {
3106 string_format.Alignment = StringAlignment.Far;
3107 text = text.Substring (1);
3111 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3112 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3113 string_format.Dispose ();
3114 } else if (sb.ShowPanels) {
3115 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
3116 int prev_x = area.X + horz_border;
3117 int y = area.Y + vert_border;
3118 for (int i = 0; i < sb.Panels.Count; i++) {
3119 Rectangle pr = new Rectangle (prev_x, y,
3120 sb.Panels [i].Width, area.Height);
3121 prev_x += pr.Width + StatusBarHorzGapWidth;
3122 if (pr.IntersectsWith (clip))
3123 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3128 CPDrawSizeGrip (dc, ColorControl, area);
3133 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3134 SolidBrush br_forecolor, StatusBarPanel panel) {
3135 int border_size = 3; // this is actually const, even if the border style is none
3137 area.Height -= border_size;
3138 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3139 Border3DStyle border_style = Border3DStyle.SunkenInner;
3140 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3141 border_style = Border3DStyle.RaisedOuter;
3142 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, panel.Parent.BackColor);
3145 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3146 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3147 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3148 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3149 panel.Parent.OnDrawItemInternal (e);
3153 int left = area.Left;
3154 if (panel.Icon != null) {
3156 dc.DrawIcon (panel.Icon, left, area.Top);
3157 left += panel.Icon.Width;
3160 if (panel.Text == String.Empty)
3163 string text = panel.Text;
3164 StringFormat string_format = new StringFormat ();
3165 string_format.Trimming = StringTrimming.Character;
3166 string_format.FormatFlags = StringFormatFlags.NoWrap;
3168 if (text [0] == '\t') {
3169 string_format.Alignment = StringAlignment.Center;
3170 text = text.Substring (1);
3171 if (text [0] == '\t') {
3172 string_format.Alignment = StringAlignment.Far;
3173 text = text.Substring (1);
3177 int x = left + border_size;
3178 int y = border_size + 2;
3179 Rectangle r = new Rectangle (x, y,
3180 area.Right - x - border_size,
3181 area.Bottom - y - border_size);
3183 dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
3184 string_format.Dispose ();
3187 public override int StatusBarSizeGripWidth {
3191 public override int StatusBarHorzGapWidth {
3195 public override Size StatusBarDefaultSize {
3197 return new Size (100, 22);
3200 #endregion // StatusBar
3202 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3204 // Do we need to fill the back color? It can't be changed...
3205 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
3206 Rectangle panel_rect = GetTabPanelRectExt (tab);
3208 if (tab.Appearance == TabAppearance.Normal) {
3209 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3210 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3213 if (tab.Alignment == TabAlignment.Top) {
3214 for (int r = tab.TabPages.Count; r > 0; r--) {
3215 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3216 if (i == tab.SelectedIndex)
3218 if (r != tab.TabPages [i].Row)
3220 Rectangle rect = tab.GetTabRect (i);
3221 if (!rect.IntersectsWith (area))
3223 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3227 for (int r = 0; r < tab.TabPages.Count; r++) {
3228 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3229 if (i == tab.SelectedIndex)
3231 if (r != tab.TabPages [i].Row)
3233 Rectangle rect = tab.GetTabRect (i);
3234 if (!rect.IntersectsWith (area))
3236 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3241 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3242 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3243 if (rect.IntersectsWith (area))
3244 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3247 if (tab.ShowSlider) {
3248 Rectangle right = GetTabControlRightScrollRect (tab);
3249 Rectangle left = GetTabControlLeftScrollRect (tab);
3250 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3251 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3255 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3257 switch (tab.Alignment) {
3258 case TabAlignment.Top:
3259 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3261 Rectangle panel_rect = GetTabPanelRectExt (tab);
3262 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3266 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3268 switch (tab.Alignment) {
3269 case TabAlignment.Top:
3270 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3272 Rectangle panel_rect = GetTabPanelRectExt (tab);
3273 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3277 public override Size TabControlDefaultItemSize {
3278 get { return new Size (42, 21); }
3281 public override Point TabControlDefaultPadding {
3282 get { return new Point (6, 3); }
3285 public override int TabControlMinimumTabWidth {
3289 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3291 Rectangle ext = GetTabPanelRectExt (tab);
3292 // Account for border size
3293 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3296 public override Size TabControlGetSpacing (TabControl tab) {
3297 switch (tab.Appearance) {
3298 case TabAppearance.Normal:
3299 return new Size (1, -2);
3300 case TabAppearance.Buttons:
3301 return new Size (3, 3);
3302 case TabAppearance.FlatButtons:
3303 return new Size (9, 3);
3305 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3309 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3311 // Offset the tab from the top corner
3312 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3313 tab.ClientRectangle.Y,
3314 tab.ClientRectangle.Width - 2,
3315 tab.ClientRectangle.Height - 1);
3317 if (tab.TabCount == 0)
3320 int spacing = TabControlGetSpacing (tab).Height;
3321 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3323 switch (tab.Alignment) {
3324 case TabAlignment.Left:
3326 res.Width -= offset;
3328 case TabAlignment.Right:
3329 res.Width -= offset;
3331 case TabAlignment.Top:
3333 res.Height -= offset;
3335 case TabAlignment.Bottom:
3336 res.Height -= offset;
3343 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3345 int FlatButtonSpacing = 8;
3347 int res = bounds.Width;
3351 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3353 StringFormat string_format = new StringFormat ();
3354 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3355 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3358 if (tab.Appearance == TabAppearance.FlatButtons) {
3359 int width = bounds.Width;
3360 bounds.Width += (FlatButtonSpacing - 2);
3362 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3363 bounds.Width = width;
3367 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
3368 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3369 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
3372 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3375 string_format.Alignment = StringAlignment.Center;
3376 string_format.LineAlignment = StringAlignment.Center;
3377 string_format.FormatFlags = StringFormatFlags.NoWrap;
3379 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
3381 switch (tab.Alignment) {
3383 case TabAlignment.Top:
3386 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3388 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3389 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3390 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3392 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3393 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3394 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3396 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3398 string_format.Alignment = StringAlignment.Center;
3399 string_format.LineAlignment = StringAlignment.Center;
3400 string_format.FormatFlags = StringFormatFlags.NoWrap;
3404 case TabAlignment.Bottom:
3406 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3408 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3409 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3411 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3412 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3414 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3415 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3416 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3418 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3420 string_format.Alignment = StringAlignment.Center;
3421 string_format.LineAlignment = StringAlignment.Center;
3422 string_format.FormatFlags = StringFormatFlags.NoWrap;
3426 case TabAlignment.Left:
3428 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3430 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3431 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3432 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3434 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3436 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3437 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3439 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3441 string_format.Alignment = StringAlignment.Center;
3442 string_format.LineAlignment = StringAlignment.Center;
3443 string_format.FormatFlags = StringFormatFlags.NoWrap;
3444 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3449 // TabAlignment.Right
3451 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3453 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3454 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3456 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3457 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3459 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3460 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3462 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3464 string_format.Alignment = StringAlignment.Center;
3465 string_format.LineAlignment = StringAlignment.Center;
3466 string_format.FormatFlags = StringFormatFlags.NoWrap;
3467 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3473 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3474 if (tab.Alignment == TabAlignment.Left) {
3475 int wo = interior.Width / 2;
3476 int ho = interior.Height / 2;
3477 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3478 dc.RotateTransform (180);
3479 dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
3480 dc.ResetTransform ();
3482 dc.DrawString (page.Text, page.Font,
3483 ResPool.GetSolidBrush (SystemColors.ControlText),
3484 interior, string_format);
3486 } else if (page.Text != null) {
3487 DrawItemState state = DrawItemState.None;
3488 if (page == tab.SelectedTab)
3489 state |= DrawItemState.Selected;
3490 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3491 tab.Font, bounds, tab.IndexForTabPage (page),
3492 state, page.ForeColor, page.BackColor);
3493 tab.OnDrawItemInternal (e);
3498 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3505 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
3506 StringFormat format = new StringFormat ();
3507 format.Trimming = StringTrimming.EllipsisWord;
3508 if (control.textAlignment == ToolBarTextAlign.Underneath) {
3509 format.LineAlignment = StringAlignment.Center;
3510 format.Alignment = StringAlignment.Center;
3512 format.LineAlignment = StringAlignment.Center;
3513 format.Alignment = StringAlignment.Near;
3516 // Exclude the area for divider
3517 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
3518 control.Width, control.Height - ToolBarGripWidth / 2);
3519 bool flat = (control.Appearance == ToolBarAppearance.Flat);
3520 dc.FillRectangle (ResPool.GetSolidBrush( DefaultControlBackColor ), paint_area);
3521 if (control.Divider)
3522 dc.DrawLine (ResPool.GetPen (ColorControlLight), 0, 0, paint_area.Width, 0);
3524 foreach (ToolBarButton button in control.Buttons) {
3527 Rectangle buttonArea = button.Rectangle;
3528 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
3529 Rectangle txtRect = buttonArea; // rect to draw the text
3530 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
3532 // calculate different rects and draw the frame if its not separator button
3533 if (button.Style != ToolBarButtonStyle.Separator) {
3534 /* Adjustment for drop down arrow */
3535 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
3536 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
3537 ddRect.Y = buttonArea.Y;
3538 ddRect.Width = this.ToolBarDropDownWidth;
3539 ddRect.Height = buttonArea.Height;
3542 // calculate txtRect and imgRect, if imageIndex and imageList are present
3543 if (button.ImageIndex > -1 && control.ImageList != null) {
3544 if (button.ImageIndex < control.ImageList.Images.Count)
3545 image = control.ImageList.Images [button.ImageIndex];
3546 // draw the image at the centre if textalignment is underneath
3547 if (control.TextAlign == ToolBarTextAlign.Underneath) {
3548 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
3549 - control.ImageSize.Width) / 2)
3550 + this.ToolBarImageGripWidth;
3551 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3552 imgRect.Width = control.ImageSize.Width;
3553 imgRect.Height = control.ImageSize.Height;
3555 txtRect.X = buttonArea.X;
3556 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
3557 txtRect.Width = buttonArea.Width - ddRect.Width;
3558 txtRect.Height = buttonArea.Height - imgRect.Height
3559 - 2 * this.ToolBarImageGripWidth;
3562 imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
3563 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3564 imgRect.Width = control.ImageSize.Width;
3565 imgRect.Height = control.ImageSize.Height;
3567 txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
3568 txtRect.Y = buttonArea.Y;
3569 txtRect.Width = buttonArea.Width - imgRect.Width
3570 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
3571 txtRect.Height = buttonArea.Height;
3574 /* Draw the button frame, only if it is not a separator */
3576 if (button.Pushed || button.Pressed) {
3577 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorControl);
3578 } else if (button.Hilight) {
3579 dc.DrawRectangle (ResPool.GetPen (ColorControlText), buttonArea);
3580 if (! ddRect.IsEmpty) {
3581 dc.DrawLine (ResPool.GetPen (ColorControlText), ddRect.X, ddRect.Y, ddRect.X,
3582 ddRect.Y + ddRect.Height);
3583 buttonArea.Width -= this.ToolBarDropDownWidth;
3587 else { // normal toolbar
3588 if (button.Pushed || button.Pressed) {
3589 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
3590 Border3DSide.All, ColorControl);
3591 if (! ddRect.IsEmpty) {
3592 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
3593 Border3DSide.Left, ColorControl);
3594 buttonArea.Width -= this.ToolBarDropDownWidth;
3598 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
3599 Border3DSide.All, ColorControl);
3600 if (! ddRect.IsEmpty) {
3601 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
3602 Border3DSide.Left, ColorControl);
3603 buttonArea.Width -= this.ToolBarDropDownWidth;
3608 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
3609 imgRect, image, txtRect, ddRect, flat);
3614 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
3615 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
3616 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
3617 if (! button.Visible)
3620 switch (button.Style) {
3622 case ToolBarButtonStyle.Separator:
3623 // separator is drawn only in the case of flat appearance
3625 dc.DrawLine (ResPool.GetPen (ColorControlDark), buttonArea.X + 1, buttonArea.Y,
3626 buttonArea.X + 1, buttonArea.Height);
3627 dc.DrawLine (ResPool.GetPen (ColorControlLight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorControl).Width,
3628 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorControl).Width, buttonArea.Height);
3629 /* draw a horizontal separator */
3630 if (button.Wrapper) {
3631 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
3632 dc.DrawLine (ResPool.GetPen (ColorControlDark), 0, y, controlArea.Width, y);
3633 dc.DrawLine (ResPool.GetPen (ColorControlLight), 0, y + 1 + (int) ResPool.GetPen (ColorControl).Width, controlArea.Width,
3634 y + 1 + (int) ResPool.GetPen (ColorControl).Width);
3639 case ToolBarButtonStyle.ToggleButton:
3640 Rectangle toggleArea = Rectangle.Empty;
3641 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
3642 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3643 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
3644 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
3645 if (button.PartialPush && button.Pushed) {
3646 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3647 if (! imgRect.IsEmpty) {
3648 if (button.Enabled && image != null)
3649 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3650 imgRect.Height, button.ImageIndex);
3652 dc.FillRectangle (ResPool.GetSolidBrush (ColorGrayText), imgRect);
3653 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3654 Border3DSide.Right | Border3DSide.Bottom);
3658 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3660 CPDrawStringDisabled (dc, button.Text, font, ColorControlLight, txtRect, format);
3663 else if (button.PartialPush) {
3664 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
3665 if (! imgRect.IsEmpty) {
3666 if (button.Enabled && image != null)
3667 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3668 imgRect.Height, button.ImageIndex);
3670 dc.FillRectangle (ResPool.GetSolidBrush (ColorGrayText), imgRect);
3671 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3672 Border3DSide.Right | Border3DSide.Bottom);
3676 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3678 CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
3682 else if (button.Pushed) {
3683 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3684 if (! imgRect.IsEmpty) {
3685 if (button.Enabled && image != null)
3686 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3687 imgRect.Height, button.ImageIndex);
3689 dc.FillRectangle (ResPool.GetSolidBrush (ColorGrayText), imgRect);
3690 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3691 Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3695 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3697 CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
3702 dc.FillRectangle (SystemBrushes.Control, toggleArea);
3703 if (! imgRect.IsEmpty) {
3704 if (button.Enabled && image != null)
3705 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3706 imgRect.Height, button.ImageIndex);
3708 dc.FillRectangle (ResPool.GetSolidBrush (ColorGrayText), imgRect);
3709 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3710 Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3714 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3716 CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
3721 case ToolBarButtonStyle.DropDownButton:
3722 // draw the dropdown arrow
3723 if (! ddRect.IsEmpty) {
3724 PointF [] vertices = new PointF [3];
3725 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
3726 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3727 vertices [0].Y = ddCenter.Y;
3728 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3729 vertices [1].Y = ddCenter.Y;
3730 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3731 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
3732 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3734 goto case ToolBarButtonStyle.PushButton;
3736 case ToolBarButtonStyle.PushButton:
3737 if (! imgRect.IsEmpty){
3738 if (button.Enabled && image != null)
3739 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
3742 dc.FillRectangle (ResPool.GetSolidBrush (ColorGrayText), imgRect);
3743 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3744 Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3748 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3750 CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
3756 // Grip width for the ToolBar
3757 public override int ToolBarGripWidth {
3761 // Grip width for the Image on the ToolBarButton
3762 public override int ToolBarImageGripWidth {
3766 // width of the separator
3767 public override int ToolBarSeparatorWidth {
3771 // width of the dropdown arrow rect
3772 public override int ToolBarDropDownWidth {
3776 // width for the dropdown arrow on the ToolBarButton
3777 public override int ToolBarDropDownArrowWidth {
3781 // height for the dropdown arrow on the ToolBarButton
3782 public override int ToolBarDropDownArrowHeight {
3786 public override Size ToolBarDefaultSize {
3788 return new Size (100, 42);
3791 #endregion // ToolBar
3794 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3795 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfo), control.client_rect);
3796 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
3797 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3800 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3803 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3804 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
3806 #endregion // ToolTip
3809 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3810 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3811 float ticks, int value_pos, bool mouse_value) {
3813 Point toptick_startpoint = new Point ();
3814 Point bottomtick_startpoint = new Point ();
3815 Point channel_startpoint = new Point ();
3817 float pixels_betweenticks;
3818 const int space_from_right = 8;
3819 const int space_from_left = 8;
3820 Rectangle area = tb.ClientRectangle;
3822 switch (tb.TickStyle) {
3823 case TickStyle.BottomRight:
3824 case TickStyle.None:
3825 channel_startpoint.Y = 8;
3826 channel_startpoint.X = 9;
3827 bottomtick_startpoint.Y = 13;
3828 bottomtick_startpoint.X = 24;
3830 case TickStyle.TopLeft:
3831 channel_startpoint.Y = 8;
3832 channel_startpoint.X = 19;
3833 toptick_startpoint.Y = 13;
3834 toptick_startpoint.X = 8;
3836 case TickStyle.Both:
3837 channel_startpoint.Y = 8;
3838 channel_startpoint.X = 18;
3839 bottomtick_startpoint.Y = 13;
3840 bottomtick_startpoint.X = 32;
3841 toptick_startpoint.Y = 13;
3842 toptick_startpoint.X = 8;
3848 thumb_area.X = area.X + channel_startpoint.X;
3849 thumb_area.Y = area.Y + channel_startpoint.Y;
3850 thumb_area.Height = area.Height - space_from_right - space_from_left;
3851 thumb_area.Width = 4;
3854 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
3855 1, thumb_area.Height);
3857 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X + 1, channel_startpoint.Y,
3858 1, thumb_area.Height);
3860 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X + 3, channel_startpoint.Y,
3861 1, thumb_area.Height);
3863 pixel_len = thumb_area.Height - 11;
3864 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3866 /* Convert thumb position from mouse position to value*/
3869 if (value_pos >= channel_startpoint.Y)
3870 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
3874 if (value_pos + tb.Minimum > tb.Maximum)
3875 value_pos = tb.Maximum - tb.Minimum;
3877 tb.Value = value_pos + tb.Minimum;
3880 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
3882 /* Draw thumb fixed 10x22 size */
3883 thumb_pos.Width = 10;
3884 thumb_pos.Height = 22;
3886 switch (tb.TickStyle) {
3887 case TickStyle.BottomRight:
3888 case TickStyle.None: {
3889 thumb_pos.X = channel_startpoint.X - 8;
3891 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3892 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3893 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3895 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3896 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3898 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3899 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3901 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3902 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3903 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3904 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3908 case TickStyle.TopLeft: {
3909 thumb_pos.X = channel_startpoint.X - 10;
3911 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3912 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3914 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3915 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3916 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3918 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3919 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3920 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3922 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3923 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3924 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3925 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3930 case TickStyle.Both: {
3931 thumb_pos.X = area.X + 10;
3932 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3933 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3935 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3936 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3938 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3939 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3941 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3950 pixel_len = thumb_area.Height - 11;
3951 pixels_betweenticks = pixel_len / ticks;
3953 thumb_area.X = thumb_pos.X;
3954 thumb_area.Y = channel_startpoint.Y;
3955 thumb_area.Width = thumb_pos.Height;
3958 Region outside = new Region (area);
3959 outside.Exclude (thumb_area);
3961 if (outside.IsVisible (clip_rectangle)) {
3962 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3963 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3965 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3966 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3967 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3968 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3970 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3971 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3975 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3976 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3978 pixel_len = thumb_area.Height - 11;
3979 pixels_betweenticks = pixel_len / ticks;
3981 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3982 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3983 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3984 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3986 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3987 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3999 Does not matter the size of the control, Win32 always draws:
4000 - Ticks starting from pixel 13, 8
4001 - Channel starting at pos 8, 19 and ends at Width - 8
4002 - Autosize makes always the control 40 pixels height
4003 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4006 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
4007 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
4008 float ticks, int value_pos, bool mouse_value) {
4009 Point toptick_startpoint = new Point ();
4010 Point bottomtick_startpoint = new Point ();
4011 Point channel_startpoint = new Point ();
4013 float pixels_betweenticks;
4014 const int space_from_right = 8;
4015 const int space_from_left = 8;
4016 Rectangle area = tb.ClientRectangle;
4018 switch (tb.TickStyle) {
4019 case TickStyle.BottomRight:
4020 case TickStyle.None:
4021 channel_startpoint.X = 8;
4022 channel_startpoint.Y = 9;
4023 bottomtick_startpoint.X = 13;
4024 bottomtick_startpoint.Y = 24;
4026 case TickStyle.TopLeft:
4027 channel_startpoint.X = 8;
4028 channel_startpoint.Y = 19;
4029 toptick_startpoint.X = 13;
4030 toptick_startpoint.Y = 8;
4032 case TickStyle.Both:
4033 channel_startpoint.X = 8;
4034 channel_startpoint.Y = 18;
4035 bottomtick_startpoint.X = 13;
4036 bottomtick_startpoint.Y = 32;
4037 toptick_startpoint.X = 13;
4038 toptick_startpoint.Y = 8;
4044 thumb_area.X = area.X + channel_startpoint.X;
4045 thumb_area.Y = area.Y + channel_startpoint.Y;
4046 thumb_area.Width = area.Width - space_from_right - space_from_left;
4047 thumb_area.Height = 4;
4050 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
4051 thumb_area.Width, 1);
4053 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X, channel_startpoint.Y + 1,
4054 thumb_area.Width, 1);
4056 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X, channel_startpoint.Y +3,
4057 thumb_area.Width, 1);
4059 pixel_len = thumb_area.Width - 11;
4060 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4062 /* Convert thumb position from mouse position to value*/
4064 if (value_pos >= channel_startpoint.X)
4065 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4069 if (value_pos + tb.Minimum > tb.Maximum)
4070 value_pos = tb.Maximum - tb.Minimum;
4072 tb.Value = value_pos + tb.Minimum;
4075 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4077 /* Draw thumb fixed 10x22 size */
4078 thumb_pos.Width = 10;
4079 thumb_pos.Height = 22;
4081 switch (tb.TickStyle) {
4082 case TickStyle.BottomRight:
4083 case TickStyle.None: {
4084 thumb_pos.Y = channel_startpoint.Y - 8;
4086 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4087 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4088 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4090 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4091 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4093 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4094 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4096 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4097 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4098 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4099 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4102 case TickStyle.TopLeft: {
4103 thumb_pos.Y = channel_startpoint.Y - 10;
4105 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4106 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4108 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4109 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4110 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4112 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4113 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4114 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4116 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4117 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4118 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4119 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4123 case TickStyle.Both: {
4124 thumb_pos.Y = area.Y + 10;
4125 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4126 dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4128 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4129 dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4131 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4132 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4134 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4143 pixel_len = thumb_area.Width - 11;
4144 pixels_betweenticks = pixel_len / ticks;
4147 thumb_area.Y = thumb_pos.Y;
4148 thumb_area.X = channel_startpoint.X;
4149 thumb_area.Height = thumb_pos.Height;
4150 Region outside = new Region (area);
4151 outside.Exclude (thumb_area);
4153 if (outside.IsVisible (clip_rectangle)) {
4154 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4155 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4157 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4158 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4159 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4160 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4162 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4163 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4167 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4168 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4170 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4171 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4172 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4173 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4175 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4176 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4184 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4189 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4191 Rectangle thumb_pos = tb.ThumbPos;
4192 Rectangle thumb_area = tb.ThumbArea;
4194 if (tb.thumb_pressed) {
4195 value_pos = tb.thumb_mouseclick;
4198 value_pos = tb.Value - tb.Minimum;
4199 mouse_value = false;
4202 area = tb.ClientRectangle;
4204 if (tb.thumb_pressed == true) {
4205 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4207 br_thumb = ResPool.GetSolidBrush (ColorControl);
4211 /* Control Background */
4212 if (tb.BackColor == DefaultControlBackColor) {
4213 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
4215 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4220 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, area.Width - 1, 1);
4221 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4222 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, 1, area.Height - 1);
4223 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4226 if (tb.Orientation == Orientation.Vertical) {
4227 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4228 br_thumb, ticks, value_pos, mouse_value);
4231 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4232 br_thumb, ticks, value_pos, mouse_value);
4235 tb.ThumbPos = thumb_pos;
4236 tb.ThumbArea = thumb_area;
4239 public override Size TrackBarDefaultSize {
4241 return new Size (104, 42);
4245 #endregion // TrackBar
4248 public override Size VScrollBarDefaultSize {
4250 return new Size (this.ScrollBarButtonSize, 80);
4253 #endregion // VScrollBar
4256 public override Size TreeViewDefaultSize {
4258 return new Size (121, 97);
4264 #region ControlPaint
4265 private enum DrawFrameControlStates {
4266 ButtonCheck = 0x0000,
4267 ButtonRadioImage = 0x0001,
4268 ButtonRadioMask = 0x0002,
4269 ButtonRadio = 0x0004,
4270 Button3State = 0x0008,
4271 ButtonPush = 0x0010,
4273 CaptionClose = 0x0000,
4274 CaptionMin = 0x0001,
4275 CaptionMax = 0x0002,
4276 CaptionRestore = 0x0004,
4277 CaptionHelp = 0x0008,
4281 MenuBullet = 0x0002,
4282 MenuArrowRight = 0x0004,
4285 ScrollDown = 0x0001,
4286 ScrollLeft = 0x0002,
4287 ScrollRight = 0x0003,
4288 ScrollComboBox = 0x0005,
4289 ScrollSizeGrip = 0x0008,
4290 ScrollSizeGripRight = 0x0010,
4295 Transparent = 0x0800,
4297 AdjustRect = 0x2000,
4303 private enum DrawFrameControlTypes {
4310 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4311 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4312 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4313 int bottomWidth, ButtonBorderStyle bottomStyle) {
4314 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4315 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4316 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4317 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4320 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4321 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4324 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
4326 Pen penTopLeftInner;
4328 Pen penBottomRightInner;
4329 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4330 bool doInner = false;
4332 if ((style & Border3DStyle.Adjust)!=0) {
4339 /* default to flat */
4340 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
4341 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
4342 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
4343 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
4345 if ((style & Border3DStyle.RaisedOuter)!=0) {
4346 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
4347 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
4348 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
4351 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
4352 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
4353 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
4354 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
4359 if ((style & Border3DStyle.RaisedInner)!=0) {
4361 penTopLeftInner=ResPool.GetPen(control_color);
4362 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
4364 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
4365 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
4367 } else if ((style & Border3DStyle.SunkenInner)!=0) {
4369 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
4370 penBottomRightInner=ResPool.GetPen(control_color);
4372 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
4373 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
4377 if ((sides & Border3DSide.Middle)!=0) {
4378 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
4381 if ((sides & Border3DSide.Left)!=0) {
4382 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
4384 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
4388 if ((sides & Border3DSide.Top)!=0) {
4389 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
4392 if ((sides & Border3DSide.Left)!=0) {
4393 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
4395 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
4400 if ((sides & Border3DSide.Right)!=0) {
4401 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
4404 if ((sides & Border3DSide.Top)!=0) {
4405 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
4407 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
4412 if ((sides & Border3DSide.Bottom)!=0) {
4415 if ((sides & Border3DSide.Left)!=0) {
4419 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
4422 if ((sides & Border3DSide.Right)!=0) {
4423 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4425 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4433 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4434 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
4436 if ((state & ButtonState.Pushed)!=0) {
4437 dfcs |= DrawFrameControlStates.Pushed;
4440 if ((state & ButtonState.Checked)!=0) {
4441 dfcs |= DrawFrameControlStates.Checked;
4444 if ((state & ButtonState.Flat)!=0) {
4445 dfcs |= DrawFrameControlStates.Flat;
4448 if ((state & ButtonState.Inactive)!=0) {
4449 dfcs |= DrawFrameControlStates.Inactive;
4451 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4455 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4456 Rectangle captionRect;
4459 CPDrawButton(graphics, rectangle, state);
4461 if (rectangle.Width<rectangle.Height) {
4462 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4464 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4467 if ((state & ButtonState.Pushed)!=0) {
4468 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4471 /* Make sure we've got at least a line width of 1 */
4472 lineWidth=Math.Max(1, captionRect.Width/7);
4475 case CaptionButton.Close: {
4478 if ((state & ButtonState.Inactive)!=0) {
4479 pen=new Pen(ColorControlLight, lineWidth);
4480 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4483 pen=new Pen(ColorControlDark, lineWidth);
4484 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4488 pen=new Pen(ColorControlText, lineWidth);
4489 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4495 case CaptionButton.Help:
4496 case CaptionButton.Maximize:
4497 case CaptionButton.Minimize:
4498 case CaptionButton.Restore: {
4499 if ((state & ButtonState.Inactive)!=0) {
4500 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4502 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4505 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4513 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
4514 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
4516 if ((state & ButtonState.Pushed)!=0) {
4517 dfcs |= DrawFrameControlStates.Pushed;
4520 if ((state & ButtonState.Checked)!=0) {
4521 dfcs |= DrawFrameControlStates.Checked;
4524 if ((state & ButtonState.Flat)!=0) {
4525 dfcs |= DrawFrameControlStates.Flat;
4528 if ((state & ButtonState.Inactive)!=0) {
4529 dfcs |= DrawFrameControlStates.Inactive;
4532 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4536 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4537 Point[] arrow = new Point[3];
4547 if ((state & ButtonState.Checked)!=0) {
4548 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4551 if ((state & ButtonState.Flat)!=0) {
4552 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4554 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4555 // this needs to render like a pushed button - jba
4556 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4557 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4558 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
4560 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4564 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4565 centerX=rect.Left+rect.Width/2;
4566 centerY=rect.Top+rect.Height/2;
4567 shiftX=Math.Max(1, rect.Width/8);
4568 shiftY=Math.Max(1, rect.Height/8);
4570 if ((state & ButtonState.Pushed)!=0) {
4577 P1=new Point(rect.Left, centerY);
4578 P2=new Point(rect.Right, centerY);
4579 P3=new Point(centerX, rect.Bottom);
4585 /* Draw the arrow */
4586 if ((state & ButtonState.Inactive)!=0) {
4587 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4589 /* Move away from the shadow */
4599 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4601 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4606 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
4608 Pen pen = new Pen(Color.Black, 1);
4609 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
4613 graphics.FillRectangle(ResPool.GetSolidBrush (ColorControlText), rect);
4614 graphics.DrawRectangle(pen, rect);
4616 X=rect.X+rect.Width/2;
4617 Y=rect.Y+rect.Height/2;
4619 /* Draw the cross */
4620 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
4621 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
4623 /* Draw 'arrows' for vertical lines */
4624 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
4625 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
4627 /* Draw 'arrows' for horizontal lines */
4628 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
4629 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
4634 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4635 // make a rectange to trace around border of the button
4636 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4638 Color outerColor = foreColor;
4639 // adjust focus color according to the flatstyle
4640 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4641 outerColor = (backColor == ColorControl) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4644 // draw the outer rectangle
4645 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4647 // draw the inner rectangle
4648 if (button.FlatStyle == FlatStyle.Popup) {
4649 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4651 // draw a flat inner rectangle
4652 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4653 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4657 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4659 // make a rectange to trace around border of the button
4660 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4662 #if NotUntilCairoIsFixed
4663 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4664 DashStyle oldStyle; // used for caching old penstyle
4665 Pen pen = ResPool.GetPen (colorBackInverted);
4667 oldStyle = pen.DashStyle;
4668 pen.DashStyle = DashStyle.Dot;
4670 graphics.DrawRectangle (pen, trace_rectangle);
4671 pen.DashStyle = oldStyle;
4673 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4678 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4680 Rectangle rect = rectangle;
4684 if (backColor.GetBrightness () >= 0.5) {
4685 foreColor = Color.Transparent;
4686 backColor = Color.Black;
4689 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4690 foreColor = Color.Black;
4693 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4694 pen = new Pen (brush, 1);
4699 graphics.DrawRectangle (pen, rect);
4703 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
4707 if (primary==true) {
4708 pen=new Pen(Color.Black, 1);
4709 if (enabled==true) {
4710 sb=ResPool.GetSolidBrush (ColorControlText);
4712 sb=ResPool.GetSolidBrush (ColorControl);
4715 pen=new Pen(Color.White, 1);
4716 if (enabled==true) {
4717 sb=ResPool.GetSolidBrush (Color.Black);
4719 sb=ResPool.GetSolidBrush (ColorControl);
4722 graphics.FillRectangle(sb, rectangle);
4723 graphics.DrawRectangle(pen, rectangle);
4728 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4734 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4737 foreColor=Color.Black;
4739 foreColor=Color.White;
4743 /* Commented out until I take the time and figure out
4744 which HatchStyle will match requirements. The code below
4745 is only correct for Percent50.
4747 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
4748 HatchBrush brush=null;
4750 switch(pixelsBetweenDots.Width) {
4751 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
4752 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
4753 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
4755 /* Have to do it the slow way */
4760 graphics.FillRectangle(brush, area);
4769 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4771 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4772 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4773 bitmap.SetPixel(x, y, foreColor);
4776 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4780 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4782 Microsoft seems to ignore the background and simply make
4783 the image grayscale. At least when having > 256 colors on
4787 if (imagedisabled_attributes == null) {
4788 imagedisabled_attributes = new ImageAttributes ();
4789 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4790 // This table would create a perfect grayscale image, based on luminance
4791 // new float[]{0.3f,0.3f,0.3f,0,0},
4792 // new float[]{0.59f,0.59f,0.59f,0,0},
4793 // new float[]{0.11f,0.11f,0.11f,0,0},
4794 // new float[]{0,0,0,1,0,0},
4795 // new float[]{0,0,0,0,1,0},
4796 // new float[]{0,0,0,0,0,1}
4798 // This table generates a image that is grayscaled and then
4799 // brightened up. Seems to match MS close enough.
4800 new float[]{0.2f,0.2f,0.2f,0,0},
4801 new float[]{0.41f,0.41f,0.41f,0,0},
4802 new float[]{0.11f,0.11f,0.11f,0,0},
4803 new float[]{0.15f,0.15f,0.15f,1,0,0},
4804 new float[]{0.15f,0.15f,0.15f,0,1,0},
4805 new float[]{0.15f,0.15f,0.15f,0,0,1}
4808 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4811 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4816 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4821 penBorder=new Pen(Color.White, 2);
4822 penInside=new Pen(Color.Black, 1);
4824 penBorder=new Pen(Color.Black, 2);
4825 penInside=new Pen(Color.White, 1);
4827 penBorder.Alignment=PenAlignment.Inset;
4828 penInside.Alignment=PenAlignment.Inset;
4830 graphics.DrawRectangle(penBorder, rectangle);
4831 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4832 penBorder.Dispose();
4833 penInside.Dispose();
4837 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
4841 // MS draws always the background white
4842 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
4845 case MenuGlyph.Arrow: {
4846 Point[] arrow = new Point[3];
4854 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4855 centerX=rect.Left+rect.Width/2;
4856 centerY=rect.Top+rect.Height/2;
4857 shiftX=Math.Max(1, rect.Width/8);
4862 P1=new Point(centerX, rect.Top-1);
4863 P2=new Point(centerX, rect.Bottom);
4864 P3=new Point(rect.Right, centerY);
4870 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4875 case MenuGlyph.Bullet: {
4877 lineWidth=Math.Max(2, rectangle.Width/3);
4878 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4880 graphics.FillEllipse(ResPool.GetSolidBrush (ColorControlText), rect);
4885 case MenuGlyph.Checkmark: {
4888 lineWidth=Math.Max(2, rectangle.Width/6);
4889 Scale=Math.Max(1, rectangle.Width/12);
4891 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4893 for (int i=0; i<lineWidth; i++) {
4894 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4895 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
4903 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4904 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
4906 if ((state & ButtonState.Pushed)!=0) {
4907 dfcs |= DrawFrameControlStates.Pushed;
4910 if ((state & ButtonState.Checked)!=0) {
4911 dfcs |= DrawFrameControlStates.Checked;
4914 if ((state & ButtonState.Flat)!=0) {
4915 dfcs |= DrawFrameControlStates.Flat;
4918 if ((state & ButtonState.Inactive)!=0) {
4919 dfcs |= DrawFrameControlStates.Inactive;
4921 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4926 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4931 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4936 /* Scroll button: regular button + direction arrow */
4937 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4938 DrawScrollButtonPrimitive (dc, area, state);
4940 // A lot of the following is adapted from the rewind project
4941 Rectangle rect = new Rectangle (area.X - 3, area.Y - 3,
4942 area.Width + 6, area.Height + 6);
4943 int small_diam = rect.Width > rect.Height ? rect.Height : rect.Width;
4944 if (rect.Width < rect.Height) {
4945 rect.Y += (rect.Height - rect.Width) / 2;
4946 rect.Height = small_diam;
4947 } else if (rect.Width > rect.Height) {
4948 rect.X += (rect.Width - rect.Height) / 2;
4949 rect.Width = small_diam;
4954 int tri = 290 * small_diam / 1000 - 1;
4958 Point [] arrow = new Point [3];
4959 for (int i = 0; i < 3; i++)
4960 arrow [i] = new Point ();
4964 case ScrollButton.Down:
4965 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
4966 arrow [2].Y = rect.Top + 687 * small_diam / 1000 + 1;
4967 arrow [0].X = arrow [2].X - tri;
4968 arrow [1].X = arrow [2].X + tri;
4969 arrow [0].Y = arrow [1].Y = arrow [2].Y - tri;
4972 case ScrollButton.Up:
4973 arrow [2].X = rect.Left + 470 * small_diam / 1000 + 2;
4974 arrow [2].Y = rect.Bottom - (687 * small_diam / 1000 + 1);
4975 arrow [0].X = arrow [2].X - tri;
4976 arrow [1].X = arrow [2].X + tri;
4977 arrow [0].Y = arrow [1].Y = arrow [2].Y + tri;
4980 case ScrollButton.Left:
4981 arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
4982 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
4983 arrow [0].Y = arrow [2].Y - tri;
4984 arrow [1].Y = arrow [2].Y + tri;
4985 arrow [0].X = arrow [1].X = arrow [2].X + tri;
4987 case ScrollButton.Right:
4988 arrow [2].X = rect.Left + 687 * small_diam / 1000 + 1;
4989 arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
4990 arrow [0].Y = arrow [2].Y - tri;
4991 arrow [1].Y = arrow [2].Y + tri;
4992 arrow [0].X = arrow [1].X = arrow [2].X - tri;
4996 /* Draw the arrow */
4997 if ((state & ButtonState.Inactive)!=0) {
4998 dc.FillPolygon (SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
5000 for (int i = 0; i < 3; i++) {
5005 dc.FillPolygon (SystemBrushes.ControlDark, arrow, FillMode.Winding);
5007 dc.FillPolygon (SystemBrushes.ControlText, arrow, FillMode.Winding);
5011 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5017 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
5018 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
5020 dc.DrawLine (ResPool.GetPen (ColorControl), pt.X - 12, pt.Y, pt.X, pt.Y);
5021 dc.DrawLine (ResPool.GetPen (ColorControl), pt.X, pt.Y, pt.X, pt.Y - 13);
5024 for (int i = 0; i < 11; i += 4) {
5025 dc.DrawLine (ResPool.GetPen (ColorControlDark), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
5026 dc.DrawLine (ResPool.GetPen (ColorControlDark), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
5029 for (int i = 3; i < 13; i += 4)
5030 dc.DrawLine (ResPool.GetPen (ColorControlLight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
5034 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
5035 StringFormat format) {
5037 graphics.DrawString(s, font, ResPool.GetSolidBrush (ColorGrayText), layoutRectangle, format);
5041 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5042 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5044 Pen pen=new Pen(color, 1);
5047 case ButtonBorderStyle.Solid: {
5048 pen.DashStyle=DashStyle.Solid;
5052 case ButtonBorderStyle.Dashed: {
5053 pen.DashStyle=DashStyle.Dash;
5057 case ButtonBorderStyle.Dotted: {
5058 pen.DashStyle=DashStyle.Dot;
5062 case ButtonBorderStyle.Inset: {
5063 pen.DashStyle=DashStyle.Solid;
5067 case ButtonBorderStyle.Outset: {
5068 pen.DashStyle=DashStyle.Solid;
5073 case ButtonBorderStyle.None: {
5081 case ButtonBorderStyle.Outset: {
5083 int hue, brightness, saturation;
5084 int brightnessSteps;
5085 int brightnessDownSteps;
5087 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5089 brightnessDownSteps=brightness/width;
5090 if (brightness>127) {
5091 brightnessSteps=Math.Max(6, (160-brightness)/width);
5093 brightnessSteps=(127-brightness)/width;
5096 for (int i=0; i<width; i++) {
5098 case Border3DSide.Left: {
5100 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5101 pen=new Pen(colorGrade, 1);
5102 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5106 case Border3DSide.Right: {
5108 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5109 pen=new Pen(colorGrade, 1);
5110 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5114 case Border3DSide.Top: {
5116 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5117 pen=new Pen(colorGrade, 1);
5118 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5122 case Border3DSide.Bottom: {
5124 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5125 pen=new Pen(colorGrade, 1);
5126 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5134 case ButtonBorderStyle.Inset: {
5136 int hue, brightness, saturation;
5137 int brightnessSteps;
5138 int brightnessDownSteps;
5140 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5142 brightnessDownSteps=brightness/width;
5143 if (brightness>127) {
5144 brightnessSteps=Math.Max(6, (160-brightness)/width);
5146 brightnessSteps=(127-brightness)/width;
5149 for (int i=0; i<width; i++) {
5151 case Border3DSide.Left: {
5153 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5154 pen=new Pen(colorGrade, 1);
5155 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5159 case Border3DSide.Right: {
5161 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5162 pen=new Pen(colorGrade, 1);
5163 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5167 case Border3DSide.Top: {
5169 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5170 pen=new Pen(colorGrade, 1);
5171 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5175 case Border3DSide.Bottom: {
5177 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5178 pen=new Pen(colorGrade, 1);
5179 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5188 I decided to have the for-loop duplicated for speed reasons;
5189 that way we only have to switch once (as opposed to have the
5190 for-loop around the switch)
5194 case Border3DSide.Left: {
5195 for (int i=0; i<width; i++) {
5196 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5201 case Border3DSide.Right: {
5202 for (int i=0; i<width; i++) {
5203 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5208 case Border3DSide.Top: {
5209 for (int i=0; i<width; i++) {
5210 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5215 case Border3DSide.Bottom: {
5216 for (int i=0; i<width; i++) {
5217 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5229 This function actually draws the various caption elements.
5230 This way we can scale them nicely, no matter what size, and they
5231 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5234 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5236 case CaptionButton.Close: {
5237 pen.StartCap=LineCap.Triangle;
5238 pen.EndCap=LineCap.Triangle;
5240 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);
5241 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);
5244 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5245 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5249 case CaptionButton.Help: {
5250 StringFormat sf = new StringFormat();
5251 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5253 sf.Alignment=StringAlignment.Center;
5254 sf.LineAlignment=StringAlignment.Center;
5257 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5265 case CaptionButton.Maximize: {
5266 /* Top 'caption bar' line */
5267 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5268 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);
5271 /* Left side line */
5272 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5273 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5276 /* Right side line */
5277 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5278 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);
5282 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5283 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5288 case CaptionButton.Minimize: {
5290 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5291 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5296 case CaptionButton.Restore: {
5297 /** First 'window' **/
5298 /* Top 'caption bar' line */
5299 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5300 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);
5303 /* Left side line */
5304 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5305 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);
5308 /* Right side line */
5309 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5310 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);
5314 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5315 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);
5318 /** Second 'window' **/
5319 /* Top 'caption bar' line */
5320 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5321 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);
5324 /* Left side line */
5325 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5326 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5329 /* Right side line */
5330 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5331 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);
5335 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5336 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5345 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
5346 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
5347 // make a rectange to trace around border of the button
5348 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
5350 case DrawFrameControlTypes.Button: {
5352 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
5353 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
5354 // /* Goes first, affects the background */
5355 // if ((State & DrawFrameControlStates.Checked)!=0) {
5356 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
5357 // graphics.FillRectangle(hatchBrush,rectangle);
5358 // hatchBrush.Dispose();
5361 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
5362 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
5363 } else if ((State & DrawFrameControlStates.Flat)!=0) {
5364 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
5365 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
5366 /* Same as normal, it would seem */
5367 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5369 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5371 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
5372 Pen penFatDark = new Pen(ColorControlDark, 1);
5373 Pen penFatLight = new Pen(ColorControlLightLight, 1);
5376 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
5378 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
5379 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
5381 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
5382 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
5384 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
5386 if ((State & DrawFrameControlStates.Checked)!=0) {
5387 SolidBrush buttonBrush;
5389 if ((State & DrawFrameControlStates.Inactive)!=0) {
5390 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
5392 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
5394 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
5396 penFatDark.Dispose();
5397 penFatLight.Dispose();
5398 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
5399 throw new NotImplementedException () ;
5400 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
5401 throw new NotImplementedException ();
5402 } else { /* Must be Checkbox */
5408 /* Goes first, affects the background */
5409 if ((State & DrawFrameControlStates.Pushed)!=0 ||
5410 (State & DrawFrameControlStates.Inactive)!=0) {
5411 graphics.FillRectangle(SystemBrushes.Control, rectangle);
5413 graphics.FillRectangle(SystemBrushes.Window, rectangle);
5416 /* Draw the sunken frame */
5417 if ((State & DrawFrameControlStates.Flat)!=0) {
5418 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
5420 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
5423 /* Make sure we've got at least a line width of 1 */
5424 lineWidth=Math.Max(3, rectangle.Width/6);
5425 Scale=Math.Max(1, rectangle.Width/12);
5427 // define a rectangle inside the border area
5428 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
5429 if ((State & DrawFrameControlStates.Inactive)!=0) {
5430 pen=SystemPens.ControlDark;
5432 pen=SystemPens.ControlText;
5435 if ((State & DrawFrameControlStates.Checked)!=0) {
5436 /* Need to draw a check-mark */
5437 for (int i=0; i<lineWidth; i++) {
5438 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5439 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);
5447 case DrawFrameControlTypes.Caption: {
5452 case DrawFrameControlTypes.Menu: {
5457 case DrawFrameControlTypes.Scroll: {
5464 /* Generic scroll button */
5465 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5466 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5467 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 1,
5468 area.Y + 1, area.Width - 2 , area.Height - 2);
5470 dc.DrawRectangle (ResPool.GetPen (ColorControlDark), area.X,
5471 area.Y, area.Width, area.Height);
5476 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, area.Width, 1);
5477 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, 1, area.Height);
5479 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 1, area.Width - 1, 1);
5480 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 2, 1,
5483 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + 1, area.Y + area.Height - 2,
5486 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X, area.Y + area.Height -1,
5489 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + area.Width - 2,
5490 area.Y + 1, 1, area.Height -3);
5492 dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X + area.Width -1,
5493 area.Y, 1, area.Height - 1);
5495 dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 2,
5496 area.Y + 2, area.Width - 4, area.Height - 4);
5500 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5501 switch (border_style){
5502 case BorderStyle.Fixed3D:
5503 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5504 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5505 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5506 area.Y + area.Height - 1);
5507 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5508 area.Y + area.Height);
5510 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5511 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5512 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5513 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5515 case BorderStyle.FixedSingle:
5516 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5518 case BorderStyle.None:
5524 #endregion // ControlPaint