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-2005 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Peter Bartok, pbartok@novell.com
25 // John BouAntoun, jba-mono@optusnet.com.au
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 {
\r
42 return new Version(0, 1, 0, 0);
\r
47 /* Default colors for Win32 classic theme */
48 uint [] theme_colors = { /* AARRGGBB */
49 (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR, 0xffc0c0c0,
50 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND, 0xff008080,
51 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION, 0xff000080,
52 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION, 0xff808080,
53 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU, 0xffc0c0c0,
54 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW, 0xffffffff,
55 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME, 0xff000000,
56 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT, 0xff000000,
57 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT, 0xff000000,
58 (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT, 0xffffffff,
59 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER, 0xffc0c0c0,
60 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER, 0xffc0c0c0,
61 (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE, 0xff808080,
62 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT, 0xff000080,
63 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT, 0xffffffff,
64 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE, 0xffc0c0c0,
65 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW, 0xff808080,
66 (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT, 0xff808080,
67 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT, 0xff000000,
68 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, 0xffc0c0c0,
69 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT, 0xffffffff,
70 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW, 0xff000000,
71 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT, 0xffe0e0e0,
72 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT, 0xff000000,
73 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK, 0xffffffff,
77 /* Hardcoded colour values not exposed in the API constants in all configurations */
78 static readonly Color arrow_color = Color.Black;
79 static readonly Color pen_ticks_color = Color.Black;
80 static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
81 static StringFormat string_format_menu_text;
82 static StringFormat string_format_menu_shortcut;
83 static StringFormat string_format_menu_menubar_text;
84 static readonly Rectangle checkbox_rect = new Rectangle (2, 2, 11,11); // Position of the checkbox relative to the item
85 static ImageAttributes imagedisabled_attributes = null;
86 const int SEPARATOR_HEIGHT = 5;
87 const int SM_CXBORDER = 1;
88 const int SM_CYBORDER = 1;
89 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
90 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
92 #region Principal Theme Methods
93 public ThemeWin32Classic ()
95 /* Init Default colour array*/
96 syscolors = Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
98 for (int i = 0; i < theme_colors.Length; i +=2)
99 syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
101 defaultWindowBackColor = SystemColors.Window;
102 defaultWindowForeColor = ColorButtonText;
103 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
105 /* Menu string formats */
106 string_format_menu_text = new StringFormat ();
107 string_format_menu_text.LineAlignment = StringAlignment.Center;
108 string_format_menu_text.Alignment = StringAlignment.Near;
109 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
111 string_format_menu_shortcut = new StringFormat ();
112 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
113 string_format_menu_shortcut.Alignment = StringAlignment.Far;
115 string_format_menu_menubar_text = new StringFormat ();
116 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
117 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
118 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
121 public override void ResetDefaults() {
122 throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
125 public override bool DoubleBufferingSupported {
128 #endregion // Principal Theme Methods
130 #region Internal Methods
131 protected SolidBrush GetControlBackBrush (Color c) {
132 if (c == DefaultControlBackColor)
133 return ResPool.GetSolidBrush (ColorButtonFace);
134 return new SolidBrush (c);
137 protected SolidBrush GetControlForeBrush (Color c) {
138 if (c == DefaultControlForeColor)
139 return ResPool.GetSolidBrush (ColorButtonText);
140 return new SolidBrush (c);
142 #endregion // Internal Methods
144 #region OwnerDraw Support
145 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
147 if (e.State == DrawItemState.Selected) {
148 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
152 e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
155 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
157 if (e.State == DrawItemState.Focus)
158 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
160 #endregion // OwnerDraw Support
163 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
166 Rectangle buttonRectangle;
167 Rectangle borderRectangle;
169 width = button.ClientSize.Width;
170 height = button.ClientSize.Height;
172 dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
174 // set up the button rectangle
175 buttonRectangle = button.ClientRectangle;
176 if (button.has_focus) {
177 // shrink the rectangle for the normal button drawing inside the focus rectangle
178 borderRectangle = Rectangle.Inflate(buttonRectangle, -1, -1);
180 borderRectangle = buttonRectangle;
183 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
184 DrawFlatStyleButton (dc, borderRectangle, button);
186 CPDrawButton(dc, borderRectangle, button.ButtonState);
189 // First, draw the image
190 if ((button.image != null) || (button.image_list != null)) {
191 // Need to draw a picture
198 if (button.ImageIndex!=-1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
199 i = button.image_list.Images[button.image_index];
204 image_width = button.image.Width;
205 image_height = button.image.Height;
207 switch(button.image_alignment) {
208 case ContentAlignment.TopLeft: {
214 case ContentAlignment.TopCenter: {
215 image_x=(width-image_width)/2;
220 case ContentAlignment.TopRight: {
221 image_x=width-image_width;
226 case ContentAlignment.MiddleLeft: {
228 image_y=(height-image_height)/2;
232 case ContentAlignment.MiddleCenter: {
233 image_x=(width-image_width)/2;
234 image_y=(height-image_height)/2;
238 case ContentAlignment.MiddleRight: {
239 image_x=width-image_width;
240 image_y=(height-image_height)/2;
244 case ContentAlignment.BottomLeft: {
246 image_y=height-image_height;
250 case ContentAlignment.BottomCenter: {
251 image_x=(width-image_width)/2;
252 image_y=height-image_height;
256 case ContentAlignment.BottomRight: {
257 image_x=width-image_width;
258 image_y=height-image_height;
269 if (button.is_pressed) {
274 if (button.is_enabled) {
275 dc.DrawImage(i, image_x, image_y);
277 CPDrawImageDisabled(dc, i, image_x, image_y, ColorButtonFace);
281 // Draw the focus rectangle
282 if (button.has_focus) {
283 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
284 DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
286 CPDrawFocusRectangle(dc, button.ClientRectangle, button.ForeColor, button.BackColor);
291 if (button.text != null && button.text != String.Empty) {
292 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
294 if (button.is_pressed) {
299 if (button.is_enabled) {
300 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
303 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
304 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rect, button.text_format);
306 CPDrawStringDisabled(dc, button.text, button.Font, ColorButtonText, text_rect, button.text_format);
312 // draw the flat style part of the rectangle
313 public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
314 Color rect_back_color = button.BackColor;
315 Color rect_fore_color = button.ForeColor;
316 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
318 if (button.Enabled) {
319 if (button.Capture || button.is_entered) {
320 if (button.FlatStyle == FlatStyle.Flat) {
321 // fill the rectangle
322 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
324 // now draw the outer border
325 if (button.Capture && button.is_entered) {
326 rect_back_color = ControlPaint.LightLight (rect_back_color);
328 rect_back_color = ControlPaint.Light (rect_back_color);
331 // draw rectangle and fill it
332 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
333 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
335 // else it must be a popup button
337 if (button.Capture && button.is_entered) {
338 graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
341 CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor);
342 graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
343 graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
347 // TODO: draw inner focus rectangle
350 // popup has a ButtonColorText forecolor, not a button.ForeCOlor
351 if (button.FlatStyle == FlatStyle.Popup) {
352 rect_fore_color = this.ColorButtonText;
355 // fill then draw outer rect
356 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
357 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
360 // finally some small tweaks to render radiobutton and checkbox
361 CheckBox checkbox = button as CheckBox;
362 RadioButton radiobutton = button as RadioButton;
363 if ((checkbox != null && checkbox.Checked) ||
364 (radiobutton != null && radiobutton.Checked)) {
365 if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
366 // render the hover for flat flatstyle and cheked
367 graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
368 } else if (!button.is_entered && !button.Capture) {
369 // render the checked state for popup when unhovered
370 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
374 // rendering checkbox or radio button style buttons
375 CheckBox checkbox = button as CheckBox;
376 RadioButton radiobutton = button as RadioButton;
377 bool draw_popup_checked = false;
379 if (button.FlatStyle == FlatStyle.Popup) {
380 rect_fore_color = this.ColorButtonText;
382 // see if we should draw a disabled checked popup button
383 draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
384 (radiobutton != null && radiobutton.Checked));
387 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
388 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
390 // finally draw the flatstyle checked effect if need
391 if (draw_popup_checked) {
392 // render the checked state for popup when unhovered
393 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
398 public override Size ButtonBaseDefaultSize {
400 return new Size (75, 23);
403 #endregion // ButtonBase
406 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
407 StringFormat text_format;
408 Rectangle client_rectangle;
409 Rectangle text_rectangle;
410 Rectangle checkbox_rectangle;
412 int checkmark_size=13;
413 int checkmark_space = 4;
415 client_rectangle = checkbox.ClientRectangle;
416 text_rectangle = client_rectangle;
417 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
419 text_format = new StringFormat();
420 text_format.Alignment=StringAlignment.Near;
421 text_format.LineAlignment=StringAlignment.Center;
422 text_format.HotkeyPrefix = HotkeyPrefix.Show;
424 /* Calculate the position of text and checkbox rectangle */
425 if (checkbox.appearance!=Appearance.Button) {
426 switch(checkbox.check_alignment) {
427 case ContentAlignment.BottomCenter: {
428 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
429 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
430 text_rectangle.X=client_rectangle.X;
431 text_rectangle.Width=client_rectangle.Width;
432 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
436 case ContentAlignment.BottomLeft: {
437 checkbox_rectangle.X=client_rectangle.Left;
438 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
439 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
440 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
444 case ContentAlignment.BottomRight: {
445 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
446 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
447 text_rectangle.X=client_rectangle.X;
448 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
452 case ContentAlignment.MiddleCenter: {
453 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
454 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
455 text_rectangle.X=client_rectangle.X;
456 text_rectangle.Width=client_rectangle.Width;
461 case ContentAlignment.MiddleLeft: {
462 checkbox_rectangle.X=client_rectangle.Left;
463 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
464 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
465 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
469 case ContentAlignment.MiddleRight: {
470 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
471 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
472 text_rectangle.X=client_rectangle.X;
473 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
477 case ContentAlignment.TopCenter: {
478 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
479 checkbox_rectangle.Y=client_rectangle.Top;
480 text_rectangle.X=client_rectangle.X;
481 text_rectangle.Width=client_rectangle.Width;
482 text_rectangle.Y=checkmark_size+checkmark_space;
483 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
487 case ContentAlignment.TopLeft: {
488 checkbox_rectangle.X=client_rectangle.Left;
489 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
490 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
494 case ContentAlignment.TopRight: {
495 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
496 text_rectangle.X=client_rectangle.X;
497 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
502 text_rectangle.X=client_rectangle.X;
503 text_rectangle.Width=client_rectangle.Width;
506 /* Set the horizontal alignment of our text */
507 switch(checkbox.text_alignment) {
508 case ContentAlignment.BottomLeft:
509 case ContentAlignment.MiddleLeft:
510 case ContentAlignment.TopLeft: {
511 text_format.Alignment=StringAlignment.Near;
515 case ContentAlignment.BottomCenter:
516 case ContentAlignment.MiddleCenter:
517 case ContentAlignment.TopCenter: {
518 text_format.Alignment=StringAlignment.Center;
522 case ContentAlignment.BottomRight:
523 case ContentAlignment.MiddleRight:
524 case ContentAlignment.TopRight: {
525 text_format.Alignment=StringAlignment.Far;
530 /* Set the vertical alignment of our text */
531 switch(checkbox.text_alignment) {
532 case ContentAlignment.TopLeft:
533 case ContentAlignment.TopCenter:
534 case ContentAlignment.TopRight: {
535 text_format.LineAlignment=StringAlignment.Near;
539 case ContentAlignment.BottomLeft:
540 case ContentAlignment.BottomCenter:
541 case ContentAlignment.BottomRight: {
542 text_format.LineAlignment=StringAlignment.Far;
546 case ContentAlignment.MiddleLeft:
547 case ContentAlignment.MiddleCenter:
548 case ContentAlignment.MiddleRight: {
549 text_format.LineAlignment=StringAlignment.Center;
554 ButtonState state = ButtonState.Normal;
555 if (checkbox.FlatStyle == FlatStyle.Flat) {
556 state |= ButtonState.Flat;
559 if (checkbox.Checked) {
560 state |= ButtonState.Checked;
563 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
564 state |= ButtonState.Checked;
565 state |= ButtonState.Pushed;
568 // finally make sure the pushed and inavtive states are rendered
569 if (!checkbox.Enabled) {
570 state |= ButtonState.Inactive;
572 else if (checkbox.is_pressed) {
573 state |= ButtonState.Pushed;
579 dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);
580 // render as per normal button
581 if (checkbox.appearance==Appearance.Button) {
582 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
583 DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
585 CPDrawButton(dc, checkbox.ClientRectangle, state);
588 // establish if we are rendering a flat style of some sort
589 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
590 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
592 ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
596 // offset the text if it's pressed and a button
597 if (checkbox.Appearance == Appearance.Button) {
598 if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
603 text_rectangle.Inflate(-4, -4);
606 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
607 if (checkbox.Enabled) {
608 sb = ResPool.GetSolidBrush(checkbox.ForeColor);
609 dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);
610 } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
611 dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
613 CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorButtonText, text_rectangle, text_format);
616 if (checkbox.Focused) {
617 if (checkbox.FlatStyle != FlatStyle.Flat) {
618 DrawInnerFocusRectangle (dc, Rectangle.Inflate (text_rectangle, -1, -1), checkbox.BackColor);
620 dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (text_rectangle, -1, -1));
625 // renders a checkBox with the Flat and Popup FlatStyle
626 private void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
630 Rectangle checkbox_rectangle;
631 Rectangle fill_rectangle;
635 // set up our rectangles first
636 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
637 // clip one pixel from bottom right for non popup rendered checkboxes
638 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
639 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));
641 // clip two pixels from bottom right for non popup rendered checkboxes
642 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
643 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));
646 // if disabled render in disabled state
647 if (checkbox.Enabled) {
648 // process the state of the checkbox
649 if (checkbox.is_entered || checkbox.Capture) {
650 // decide on which background color to use
651 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
652 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
653 } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
654 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
656 // use regular window background color
657 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
660 // render the outer border
661 if (checkbox.FlatStyle == FlatStyle.Flat) {
662 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
664 // draw sunken effect
665 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
668 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
670 if (checkbox.FlatStyle == FlatStyle.Flat) {
671 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
673 // draw the outer border
674 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
678 if (checkbox.FlatStyle == FlatStyle.Popup) {
679 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
682 // draw disabled state,
683 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
686 /* Make sure we've got at least a line width of 1 */
687 lineWidth = Math.Max(3, fill_rectangle.Width/3);
688 Scale=Math.Max(1, fill_rectangle.Width/9);
690 // flat style check box is rendered inside a rectangle shifted down by one
691 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
692 if (checkbox.Enabled) {
693 pen=ResPool.GetPen(checkbox.ForeColor);
695 pen=SystemPens.ControlDark;
698 if (checkbox.Checked) {
699 /* Need to draw a check-mark */
700 for (int i=0; i<lineWidth; i++) {
701 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
702 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);
708 #endregion // CheckBox
710 #region CheckedListBox
712 public override Rectangle CheckedListBoxCheckRectangle ()
714 return checkbox_rect;
717 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
719 Color back_color, fore_color;
720 Rectangle item_rect = e.Bounds;
722 StringFormat string_format = ctrl.GetFormatString ();
726 if ((ctrl.Items.GetListBoxItem (e.Index)).State == CheckState.Checked)
727 state = ButtonState.Checked;
729 state = ButtonState.Normal;
731 if (ctrl.ThreeDCheckBoxes == false)
732 state |= ButtonState.Flat;
734 ControlPaint.DrawCheckBox (e.Graphics,
735 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
736 checkbox_rect.Width, checkbox_rect.Height,
739 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
740 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
743 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
744 back_color = ThemeEngine.Current.ColorHilight;
745 fore_color = ThemeEngine.Current.ColorHilightText;
748 back_color = e.BackColor;
749 fore_color = e.ForeColor;
752 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
753 (back_color), item_rect);
755 e.Graphics.DrawString (ctrl.Items[e.Index].ToString (), e.Font,
756 ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
757 item_rect, string_format);
759 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
760 ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, item_rect,
761 fore_color, back_color);
765 #endregion // CheckedListBox
771 public override void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
773 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
774 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
775 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
776 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
777 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
778 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
779 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
780 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);
784 public override int DrawComboBoxEditDecorationTop () { return 2;}
785 public override int DrawComboBoxEditDecorationBottom () { return 2;}
786 public override int DrawComboBoxEditDecorationRight () { return 2;}
787 public override int DrawComboBoxEditDecorationLeft () { return 2;}
789 private int DrawComboListBoxDecoration (ComboBoxStyle style)
791 if (style == ComboBoxStyle.Simple)
797 public override int DrawComboListBoxDecorationTop (ComboBoxStyle style)
799 return DrawComboListBoxDecoration (style);
802 public override int DrawComboListBoxDecorationBottom (ComboBoxStyle style)
804 return DrawComboListBoxDecoration (style);
807 public override int DrawComboListBoxDecorationRight (ComboBoxStyle style)
809 return DrawComboListBoxDecoration (style);
812 public override int DrawComboListBoxDecorationLeft (ComboBoxStyle style)
814 return DrawComboListBoxDecoration (style);
817 public override void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
819 if (ctrl.DropDownStyle == ComboBoxStyle.Simple) {
820 DrawComboBoxEditDecorations (dc, ctrl, cl);
823 dc.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorWindowFrame),
824 cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
828 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
830 Color back_color, fore_color;
831 Rectangle text_draw = e.Bounds;
832 StringFormat string_format = new StringFormat ();
833 string_format.FormatFlags = StringFormatFlags.LineLimit;
835 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
836 back_color = ThemeEngine.Current.ColorHilight;
837 fore_color = ThemeEngine.Current.ColorHilightText;
840 back_color = e.BackColor;
841 fore_color = e.ForeColor;
844 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (back_color), e.Bounds);
847 e.Graphics.DrawString (ctrl.Items[e.Index].ToString (), e.Font,
848 ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
849 text_draw, string_format);
852 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
853 ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
859 #region DateTimePicker
861 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
862 // if not showing the numeric updown control then render border
863 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
864 // draw the outer border
865 Rectangle button_bounds = dtp.ClientRectangle;
866 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.All, dtp.BackColor);
868 // deflate by the border width
869 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
870 button_bounds.Inflate (-2,-2);
871 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
872 this.CPDrawComboButton (
874 dtp.drop_down_arrow_rect,
879 // render the date part
880 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
881 // fill the background
882 dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorWindow), dtp.date_area_rect);
884 // fill the currently highlighted area
885 if (dtp.hilight_date_area != Rectangle.Empty) {
886 dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorHilight), dtp.hilight_date_area);
889 // draw the text part
890 // TODO: if date format is CUstom then we need to draw the dates as separate parts
891 StringFormat text_format = new StringFormat();
892 text_format.LineAlignment = StringAlignment.Center;
893 text_format.Alignment = StringAlignment.Near;
894 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
898 #endregion // DateTimePicker
901 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
902 StringFormat text_format;
908 rect = box.ClientRectangle;
910 // Needed once the Dark/Light code below is enabled again
911 //Color disabled = ColorGrayText;
913 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
914 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
916 // TODO: When the Light and Dark methods work this code should be activate it
917 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
918 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
920 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
922 text_format = new StringFormat();
923 text_format.HotkeyPrefix = HotkeyPrefix.Show;
925 size = dc.MeasureString (box.Text, box.Font);
926 width = (int) size.Width;
928 if (width > box.Width - 16)
929 width = box.Width - 16;
931 y = box.Font.Height / 2;
934 dc.DrawLine (pen_dark, 0, y, 8, y); // top
935 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
936 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
937 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
939 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
940 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
942 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
943 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
945 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
946 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
951 dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0, text_format);
953 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
954 new RectangleF (10, 0, width, box.Font.Height), text_format);
959 public override Size GroupBoxDefaultSize {
961 return new Size (200,100);
967 public override Size HScrollBarDefaultSize {
969 return new Size (80, this.ScrollBarButtonSize);
973 #endregion // HScrollBar
976 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
978 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
980 CPDrawBorderStyle (dc, clip_rectangle, label.BorderStyle);
983 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
985 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
990 public override Size LabelDefaultSize {
992 return new Size (100, 23);
1000 public override void DrawListBoxDecorations (Graphics dc, ListBox ctrl)
1002 Rectangle cl = ctrl.LBoxInfo.client_rect;
1005 switch (ctrl.BorderStyle) {
1006 case BorderStyle.Fixed3D: {
1007 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
1008 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
1009 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
1010 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
1011 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
1012 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
1013 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
1014 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);
1017 case BorderStyle.FixedSingle:
1018 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
1020 case BorderStyle.None:
1026 private int DrawListBoxDecorationSize (BorderStyle border_style)
1028 switch (border_style) {
1029 case BorderStyle.Fixed3D:
1031 case BorderStyle.FixedSingle:
1033 case BorderStyle.None:
1042 public override int DrawListBoxDecorationTop (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1043 public override int DrawListBoxDecorationBottom (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1044 public override int DrawListBoxDecorationRight (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1045 public override int DrawListBoxDecorationLeft (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1047 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1049 Color back_color, fore_color;
1050 StringFormat string_format = ctrl.GetFormatString ();
1052 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1053 back_color = ThemeEngine.Current.ColorHilight;
1054 fore_color = ThemeEngine.Current.ColorHilightText;
1057 back_color = e.BackColor;
1058 fore_color = e.ForeColor;
1061 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1062 (back_color), e.Bounds);
1064 e.Graphics.DrawString (ctrl.Items[e.Index].ToString (), e.Font,
1065 ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
1066 e.Bounds, string_format);
1068 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1069 ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds,
1070 fore_color, back_color);
1078 public override void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control)
1080 bool details = (control.View == View.Details);
1082 // Clear the graphics context
1083 dc.Clear (control.BackColor);
1085 // border is drawn directly in the Paint method
1086 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1087 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control),
1088 0, 0, control.TotalWidth, control.Font.Height + 5);
1089 if (control.Columns.Count > 0) {
1090 if (control.HeaderStyle == ColumnHeaderStyle.Clickable) {
1091 foreach (ColumnHeader col in control.Columns) {
1092 this.CPDrawButton (dc, col.Rect,
1094 ButtonState.Pushed :
1095 ButtonState.Normal));
1096 dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
1097 ResPool.GetSolidBrush
1098 (this.ColorButtonText),
1101 col.Rect.Y + col.Rect.Height/2 + 1,
1105 // Non-clickable columns
1107 foreach (ColumnHeader col in control.Columns) {
1108 this.CPDrawButton (dc, col.Rect, ButtonState.Flat);
1109 dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
1110 ResPool.GetSolidBrush
1111 (this.ColorButtonText),
1114 col.Rect.Y + col.Rect.Height/2 + 1,
1121 // In case of details view draw the items only if
1122 // columns are non-zero
1123 if (!details || control.Columns.Count > 0)
1124 foreach (ListViewItem item in control.Items)
1125 this.DrawListViewItem (dc, control, item);
1127 // draw the gridlines
1128 if (details && control.GridLines) {
1129 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1130 2 : control.Font.Height + 2;
1132 // draw vertical gridlines
1133 foreach (ColumnHeader col in control.Columns)
1134 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1135 col.Rect.Right, top,
1136 col.Rect.Right, control.TotalHeight);
1137 // draw horizontal gridlines
1138 ListViewItem last_item = null;
1139 foreach (ListViewItem item in control.Items) {
1140 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1141 item.EntireRect.Left, item.EntireRect.Top,
1142 control.TotalWidth, item.EntireRect.Top);
1146 // draw a line after at the bottom of the last item
1147 if (last_item != null) {
1148 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1149 last_item.EntireRect.Left,
1150 last_item.EntireRect.Bottom,
1152 last_item.EntireRect.Bottom);
1157 // draws the ListViewItem of the given index
1158 private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1160 if (control.CheckBoxes) {
1161 if (control.StateImageList == null) {
1162 // Make sure we've got at least a line width of 1
1163 int check_wd = Math.Max (3, item.CheckRect.Width / 6);
1164 int scale = Math.Max (1, item.CheckRect.Width / 12);
1166 // set the checkbox background
1167 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
1169 // define a rectangle inside the border area
1170 Rectangle rect = new Rectangle (item.CheckRect.X + 2,
1171 item.CheckRect.Y + 2,
1172 item.CheckRect.Width - 4,
1173 item.CheckRect.Height - 4);
1174 Pen pen = new Pen (this.ColorWindowText, 2);
1175 dc.DrawRectangle (pen, rect);
1177 // Need to draw a check-mark
1180 // adjustments to get the check-mark at the right place
1181 rect.X ++; rect.Y ++;
1182 // following logic is taken from DrawFrameControl method
1183 for (int i = 0; i < check_wd; i++) {
1184 dc.DrawLine (pen, rect.Left + check_wd / 2,
1185 rect.Top + check_wd + i,
1186 rect.Left + check_wd / 2 + 2 * scale,
1187 rect.Top + check_wd + 2 * scale + i);
1189 rect.Left + check_wd / 2 + 2 * scale,
1190 rect.Top + check_wd + 2 * scale + i,
1191 rect.Left + check_wd / 2 + 6 * scale,
1192 rect.Top + check_wd - 2 * scale + i);
1197 if (item.Checked && control.StateImageList.Images.Count > 1)
1198 control.StateImageList.Draw (dc,
1199 item.CheckRect.Location, 1);
1200 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1201 control.StateImageList.Draw (dc,
1202 item.CheckRect.Location, 0);
1206 // Item is drawn as a special case, as it is not just text
1207 if (control.View == View.LargeIcon) {
1208 if (item.ImageIndex > -1 &&
1209 control.LargeImageList != null &&
1210 item.ImageIndex < control.LargeImageList.Images.Count)
1211 control.LargeImageList.Draw (dc, item.IconRect.Location,
1215 if (item.ImageIndex > -1 &&
1216 control.SmallImageList != null &&
1217 item.ImageIndex < control.SmallImageList.Images.Count)
1218 control.SmallImageList.Draw (dc, item.IconRect.Location,
1222 // draw the item text
1223 Rectangle text_rect = item.LabelRect;
1224 // format for the item text
1225 StringFormat format = new StringFormat ();
1226 format.LineAlignment = StringAlignment.Center;
1227 if (control.View == View.LargeIcon)
1228 format.Alignment = StringAlignment.Center;
1230 format.Alignment = StringAlignment.Near;
1232 if (!control.LabelWrap)
1233 format.FormatFlags = StringFormatFlags.NoWrap;
1235 if (item.Selected) {
1236 if (control.View == View.Details) {
1237 if (control.FullRowSelect) {
1238 // fill the entire rect excluding the checkbox
1239 Rectangle full_rect = item.EntireRect;
1240 full_rect.Location = item.LabelRect.Location;
1241 dc.FillRectangle (this.ResPool.GetSolidBrush
1242 (this.ColorHilight), full_rect);
1245 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1247 text_rect.Width = text_size.Width;
1248 dc.FillRectangle (this.ResPool.GetSolidBrush
1249 (this.ColorHilight), text_rect);
1253 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1255 Point loc = text_rect.Location;
1256 loc.X += (text_rect.Width - text_size.Width) / 2;
1257 text_rect.Width = text_size.Width;*/
1258 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHilight),
1263 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1265 if (item.Text != null && item.Text.Length > 0) {
1267 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1268 (this.ColorHilightText), text_rect, format);
1270 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1271 (item.ForeColor), text_rect, format);
1274 if (control.View == View.Details && control.Columns.Count > 0) {
1275 // draw subitems for details view
1276 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1277 int count = (control.Columns.Count < subItems.Count ?
1278 control.Columns.Count : subItems.Count);
1282 ListViewItem.ListViewSubItem subItem;
1283 Rectangle sub_item_rect = item.LabelRect;
1285 // set the format for subitems
1286 format.FormatFlags = StringFormatFlags.NoWrap;
1287 format.Alignment = StringAlignment.Near;
1289 // 0th subitem is the item already drawn
1290 for (int index = 1; index < count; index++) {
1291 subItem = subItems [index];
1292 col = control.Columns [index];
1293 sub_item_rect.X = col.Rect.Left;
1294 sub_item_rect.Width = col.Wd;
1296 SolidBrush sub_item_back_br = null;
1297 SolidBrush sub_item_fore_br = null;
1298 Font sub_item_font = null;
1300 if (item.UseItemStyleForSubItems) {
1301 sub_item_back_br = this.ResPool.GetSolidBrush
1303 sub_item_fore_br = this.ResPool.GetSolidBrush
1305 sub_item_font = item.Font;
1308 sub_item_back_br = this.ResPool.GetSolidBrush
1309 (subItem.BackColor);
1310 sub_item_fore_br = this.ResPool.GetSolidBrush
1311 (subItem.ForeColor);
1312 sub_item_font = subItem.Font;
1315 // In case of fullrowselect, background is filled
1316 // for the entire rect above
1317 if (item.Selected && control.FullRowSelect) {
1318 if (subItem.Text != null && subItem.Text.Length > 0)
1319 dc.DrawString (subItem.Text, sub_item_font,
1320 this.ResPool.GetSolidBrush
1321 (this.ColorHilightText),
1322 sub_item_rect, format);
1325 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1326 if (subItem.Text != null && subItem.Text.Length > 0)
1327 dc.DrawString (subItem.Text, sub_item_font,
1329 sub_item_rect, format);
1331 sub_item_rect.X += col.Wd;
1338 public override Size ListViewCheckBoxSize {
1339 get { return new Size (16, 16); }
1342 public override int ListViewColumnHeaderHeight {
1346 public override int ListViewDefaultColumnWidth {
1350 public override int ListViewVerticalSpacing {
1354 public override int ListViewEmptyColumnWidth {
1358 public override int ListViewHorizontalSpacing {
1362 public override Size ListViewDefaultSize {
1363 get { return new Size (121, 97); }
1365 #endregion // ListView
1368 public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
1373 if (item.item.Visible == false)
1376 if (item.item.Separator == true) {
1377 item.rect.Height = SEPARATOR_HEIGHT / 2;
1378 item.rect.Width = -1;
1382 if (item.item.MeasureEventDefined) {
1383 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.pos);
1384 item.item.PerformMeasureItem (mi);
1385 item.rect.Height = mi.ItemHeight;
1386 item.rect.Width = mi.ItemWidth;
1391 size = dc.MeasureString (item.item.Text, ThemeEngine.Current.MenuFont);
1392 item.rect.Width = (int) size.Width;
1393 item.rect.Height = (int) size.Height;
1397 if (item.item.Shortcut != Shortcut.None && item.item.ShowShortcut) {
1398 item.item.XTab = ThemeEngine.Current.MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1399 size = dc.MeasureString (" " + item.item.GetShortCutText (), ThemeEngine.Current.MenuFont);
1400 item.rect.Width += MENU_TAB_SPACE + (int) size.Width;
1403 item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
1406 item.rect.Width += MENU_BAR_ITEMS_SPACE;
1407 x += item.rect.Width;
1410 if (item.rect.Height < ThemeEngine.Current.MenuHeight)
1411 item.rect.Height = ThemeEngine.Current.MenuHeight;
1415 // Updates the menu rect and returns the height
1416 public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width)
1421 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1423 MenuAPI.MENUITEM item;
1425 while (i < menu.items.Count) {
1427 item = (MenuAPI.MENUITEM) menu.items[i];
1428 CalcItemSize (dc, item, y, x, true);
1431 if (x + item.rect.Width > width) {
1433 y += item.rect.Height;
1438 x += item.rect.Width;
1439 item.item.MenuBar = true;
1441 if (y + item.rect.Height > menu.Height)
1442 menu.Height = item.rect.Height + y;
1450 public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
1456 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1459 while (start < menu.items.Count) {
1462 for (i = start; i < menu.items.Count; i++) {
1463 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
1465 if ((i != start) && (item.item.Break || item.item.BarBreak))
1468 CalcItemSize (dc, item, y, x, false);
1469 y += item.rect.Height;
1471 if (item.rect.Width > max)
1472 max = item.rect.Width;
1475 // Reemplace the -1 by the menu width (separators)
1476 for (n = start; n < i; n++, start++) {
1477 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[n];
1478 item.rect.Width = max;
1481 if (y > menu.Height)
1493 menu.Width += SM_CXBORDER;
1494 menu.Height += SM_CYBORDER;
1497 // Draws a menu bar in a window
1498 public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
1500 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1501 Rectangle item_rect;
1503 if (menu.Height == 0)
1504 ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
1506 rect.Height = menu.Height;
1507 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (menu.Wnd.BackColor), rect);
1509 for (int i = 0; i < menu.items.Count; i++) {
1510 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1511 item_rect = it.rect;
1512 item_rect.X += rect.X;
1513 item_rect.Y += rect.Y;
1514 it.item.MenuHeight = menu.Height;
1515 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1516 item_rect, i, it.item.Status));
1521 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1523 StringFormat string_format;
1524 Rectangle rect_text = e.Bounds;
1526 if (item.Visible == false)
1530 string_format = string_format_menu_menubar_text;
1533 string_format = string_format_menu_text;
1536 if (item.Separator == true) {
1537 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1538 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1540 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1541 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1547 rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
1549 if (item.BarBreak) { /* Draw vertical break bar*/
1550 Rectangle rect = e.Bounds;
1553 rect.Height = item.MenuHeight - 6;
1555 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1556 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1558 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1559 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1565 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1566 color_text = ThemeEngine.Current.ColorHilightText;
1567 color_back = ThemeEngine.Current.ColorHilight;
1570 color_text = ThemeEngine.Current.ColorMenuText;
1571 color_back = ThemeEngine.Current.ColorMenu;
1574 /* Draw background */
1575 Rectangle rect_back = e.Bounds;
1577 rect_back.Width -=2;
1578 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color_back), rect_back);
1581 e.Graphics.DrawString (item.Text, e.Font,
1582 ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1583 rect_text, string_format);
1585 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1586 string str = item.GetShortCutText ();
1587 Rectangle rect = rect_text;
1589 rect.Width -= item.XTab;
1591 e.Graphics.DrawString (str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1592 rect, string_format_menu_shortcut);
1596 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
1597 Color.Black, rect_text, string_format);
1601 if (item.MenuBar == false && item.IsPopup) {
1603 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1604 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1605 Bitmap bmp = new Bitmap (cx, cy);
1606 Graphics gr = Graphics.FromImage (bmp);
1607 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1608 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
1609 bmp.MakeTransparent ();
1612 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1613 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1615 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1616 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1623 /* Draw checked or radio */
1624 if (item.MenuBar == false && item.Checked) {
1626 Rectangle area = e.Bounds;
1627 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1628 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1629 Bitmap bmp = new Bitmap (cx, cy);
1630 Graphics gr = Graphics.FromImage (bmp);
1631 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1633 if (item.RadioCheck)
1634 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
1636 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
1638 bmp.MakeTransparent ();
1639 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1646 public override void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect)
1648 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1650 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1651 (ThemeEngine.Current.ColorMenu), cliparea);
1653 /* Draw menu borders */
1654 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1655 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1657 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1658 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1660 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1661 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1663 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1664 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1666 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1667 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1669 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1670 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1672 for (int i = 0; i < menu.items.Count; i++)
1673 if (cliparea.IntersectsWith (((MenuAPI.MENUITEM) menu.items[i]).rect)) {
1674 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1675 it.item.MenuHeight = menu.Height;
1676 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1677 it.rect, i, it.item.Status));
1683 #region MonthCalendar
1685 // draw the month calendar
1686 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
\r
1688 Rectangle client_rectangle = mc.ClientRectangle;
1689 Size month_size = mc.SingleMonthSize;
1690 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1691 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
1692 Size date_cell_size = (Size)((object)mc.date_cell_size);
1694 // draw the singlecalendars
1697 // adjust for the position of the specific month
1698 for (int i=0; i < mc.CalendarDimensions.Height; i++)
\r
1702 y_offset += month_size.Height + calendar_spacing.Height;
1704 // now adjust for x position
1705 for (int j=0; j < mc.CalendarDimensions.Width; j++)
\r
1709 x_offset += month_size.Width + calendar_spacing.Width;
1716 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
1717 if (month_rect.IntersectsWith (clip_rectangle)) {
1729 Rectangle bottom_rect = new Rectangle (
1731 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
1732 client_rectangle.Width,
1733 date_cell_size.Height + 2);
1734 // draw the today date if it's set
1735 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
\r
1737 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
1739 int today_offset = 5;
1740 if (mc.ShowTodayCircle)
\r
1742 Rectangle today_circle_rect = new Rectangle (
1743 client_rectangle.X + 5,
1744 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
1745 date_cell_size.Width,
1746 date_cell_size.Height);
1747 DrawTodayCircle (dc, today_circle_rect);
1748 today_offset += date_cell_size.Width + 5;
1750 // draw today's date
1751 StringFormat text_format = new StringFormat();
1752 text_format.LineAlignment = StringAlignment.Center;
1753 text_format.Alignment = StringAlignment.Near;
1754 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
1755 Rectangle today_rect = new Rectangle (
1756 today_offset + client_rectangle.X,
1757 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
1758 Math.Max(client_rectangle.Width - today_offset, 0),
1759 date_cell_size.Height);
1760 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
1764 // finally paint the borders of the calendars as required
1765 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
1766 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
1767 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
1768 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
1769 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
1771 Rectangle rect = new Rectangle (
1772 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
1774 calendar_spacing.Width,
1775 client_rectangle.Height);
1776 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1777 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1781 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
1782 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
1783 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
1784 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
1785 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
1787 Rectangle rect = new Rectangle (
1789 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
1790 client_rectangle.Width,
1791 calendar_spacing.Height);
1792 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1793 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1798 // draw the drop down border if need
1799 if (mc.owner != null) {
1800 Rectangle bounds = mc.ClientRectangle;
1801 if (clip_rectangle.Contains (mc.Location)) {
1802 // find out if top or left line to draw
1803 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1805 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
1807 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1808 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
1811 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
1812 // find out if bottom or right line to draw
1813 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1814 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
1816 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1817 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
1823 // darws a single part of the month calendar (with one month)
1824 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
\r
1826 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1827 Size title_size = (Size)((object)mc.title_size);
1828 Size date_cell_size = (Size)((object)mc.date_cell_size);
1829 DateTime current_month = (DateTime)((object)mc.current_month);
1831 // set up some standard string formating variables
1832 StringFormat text_format = new StringFormat();
1833 text_format.LineAlignment = StringAlignment.Center;
1834 text_format.Alignment = StringAlignment.Center;
1837 // draw the title back ground
1838 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
1839 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
1840 if (title_rect.IntersectsWith (clip_rectangle)) {
1841 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
1843 string title_text = this_month.ToString ("MMMM yyyy");
1844 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
1846 // draw previous and next buttons if it's time
1847 if (row == 0 && col == 0)
\r
1849 // draw previous button
1850 DrawMonthCalendarButton (
1856 (System.Drawing.Size)((object)mc.button_size),
1859 if (row == 0 && col == mc.CalendarDimensions.Width-1)
\r
1862 DrawMonthCalendarButton (
1868 (System.Drawing.Size)((object)mc.button_size),
1873 // set the week offset and draw week nums if needed
1874 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
1875 Rectangle day_name_rect = new Rectangle(
1877 rectangle.Y + title_size.Height,
1878 (7 + col_offset) * date_cell_size.Width,
1879 date_cell_size.Height);
1880 if (day_name_rect.IntersectsWith (clip_rectangle)) {
1881 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
1882 // draw the day names
1883 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
1884 for (int i=0; i < 7; i++)
\r
1886 int position = i - (int) first_day_of_week;
1887 if (position < 0)
\r
1889 position = 7 + position;
1892 Rectangle day_rect = new Rectangle(
1893 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
1895 date_cell_size.Width,
1896 date_cell_size.Height);
1897 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
1900 // draw the vertical divider
1901 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
1903 ResPool.GetPen (mc.ForeColor),
1904 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
1905 rectangle.Y + vert_divider_y,
1906 rectangle.Right - mc.divider_line_offset,
1907 rectangle.Y + vert_divider_y);
1911 // draw the actual date items in the grid (including the week numbers)
1912 Rectangle date_rect = new Rectangle (
1914 rectangle.Y + title_size.Height + date_cell_size.Height,
1915 date_cell_size.Width,
1916 date_cell_size.Height);
1917 int month_row_count = 0;
1918 bool draw_week_num_divider = false;
1919 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
1920 for (int i=0; i < 6; i++)
\r
1922 // establish if this row is in our clip_area
1923 Rectangle row_rect = new Rectangle (
1925 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
1926 date_cell_size.Width * 7,
1927 date_cell_size.Height);
1928 if (mc.ShowWeekNumbers) {
1929 row_rect.Width += date_cell_size.Width;
1932 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
1934 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
1936 // establish if this is a valid week to draw
1937 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
1938 month_row_count = i;
1941 // draw the week number if required
1942 if (mc.ShowWeekNumbers && month_row_count == i) {
1943 if (!draw_week_num_divider) {
1944 draw_week_num_divider = draw_row;
1946 // get the week for this row
1947 int week = mc.GetWeekOfYear (current_date);
1953 ResPool.GetSolidBrush (mc.TitleBackColor),
1957 date_rect.Offset(date_cell_size.Width, 0);
1960 // only draw the days if we have to
1961 if(month_row_count == i) {
1962 for (int j=0; j < 7; j++)
\r
1965 DrawMonthCalendarDate (
1976 current_date = current_date.AddDays(1);
1977 date_rect.Offset(date_cell_size.Width, 0);
1980 // shift the rectangle down one row
1981 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
1982 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
1986 // month_row_count is zero based, so add one
1989 // draw week numbers if required
1990 if (draw_week_num_divider) {
1993 ResPool.GetPen (mc.ForeColor),
1994 rectangle.X + date_cell_size.Width - 1,
1995 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
1996 rectangle.X + date_cell_size.Width - 1,
1997 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2001 // draws the pervious or next button
2002 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
\r
2004 bool is_clicked = false;
2005 Rectangle button_rect;
2006 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2007 Point[] arrow_path = new Point[3];
2008 // prepare the button
2011 is_clicked = mc.is_previous_clicked;
2012 button_rect = new Rectangle (
2013 rectangle.X + 1 + x_offset,
2014 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2015 Math.Max(button_size.Width - 1, 0),
2016 Math.Max(button_size.Height - 1, 0));
2017 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2018 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2020 arrow_rect.Offset(1,1);
2022 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2023 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2024 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2028 is_clicked = mc.is_next_clicked;
2029 button_rect = new Rectangle (
2030 rectangle.Right - 1 - x_offset - button_size.Width,
2031 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2032 Math.Max(button_size.Width - 1, 0),
2033 Math.Max(button_size.Height - 1, 0));
2034 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2035 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2037 arrow_rect.Offset(1,1);
2039 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2040 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2041 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2044 // fill the background
2045 dc.FillRectangle (SystemBrushes.Control, button_rect);
2048 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2051 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
2054 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2058 // draws one day in the calendar grid
2059 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2060 Color date_color = mc.ForeColor;
2061 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2063 // find out if we are the lead of the first calendar or the trail of the last calendar
2064 if (date.Year != month.Year || date.Month != month.Month) {
2065 DateTime check_date = month.AddMonths (-1);
2066 // check if it's the month before
2067 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2068 date_color = mc.TrailingForeColor;
2070 // check if it's the month after
2071 check_date = month.AddMonths (1);
2072 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2073 date_color = mc.TrailingForeColor;
2079 date_color = mc.ForeColor;
2083 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2084 // see if the date is in the start of selection
2085 date_color = mc.BackColor;
2086 // draw the left hand of the back ground
2087 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2088 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2089 } else if (date == mc.SelectionStart) {
2090 // see if the date is in the start of selection
2091 date_color = mc.BackColor;
2092 // draw the left hand of the back ground
2093 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2094 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2095 // fill the other side as a straight rect
2096 if (date < mc.SelectionEnd)
\r
2098 // use rectangle instead of rectangle to go all the way to edge of rect
2099 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2100 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2101 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2103 } else if (date == mc.SelectionEnd) {
2104 // see if it is the end of selection
2105 date_color = mc.BackColor;
2106 // draw the left hand of the back ground
2107 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2108 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2109 // fill the other side as a straight rect
2110 if (date > mc.SelectionStart) {
2111 selection_rect.X = rectangle.X;
2112 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2113 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2115 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2116 // now see if it's in the middle
2117 date_color = mc.BackColor;
2118 // draw the left hand of the back ground
2119 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2120 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2123 // set up some standard string formating variables
2124 StringFormat text_format = new StringFormat();
2125 text_format.LineAlignment = StringAlignment.Center;
2126 text_format.Alignment = StringAlignment.Center;
2129 // establish if it's a bolded font
2131 if (mc.IsBoldedDate (date)) {
2132 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2137 // just draw the date now
2138 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2140 // today circle if needed
2141 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2142 DrawTodayCircle (dc, interior);
2145 // draw the selection grid
2146 if (mc.is_date_clicked && mc.clicked_date == date) {
2147 using (Pen pen = new Pen (Color.Black, 1) ) {
2148 pen.DashStyle = DashStyle.Dot;
2149 dc.DrawRectangle (pen, interior);
2154 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2155 Color circle_color = Color.FromArgb (248, 0, 0);
2156 // draw the left hand of the circle
2157 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2158 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2159 Point [] curve_points = new Point [3];
2160 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2161 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2162 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2164 using (Pen pen = new Pen (circle_color, 2)) {
2165 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2166 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2167 dc.DrawCurve (pen, curve_points);
2168 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2172 #endregion // MonthCalendar
2175 public override Size PanelDefaultSize {
2177 return new Size (200, 100);
2183 public override void DrawPictureBox (Graphics dc, PictureBox pb) {
2184 Rectangle client = pb.ClientRectangle;
2186 dc.FillRectangle (new SolidBrush (pb.BackColor), client);
2188 if (pb.Image != null) {
2189 switch (pb.SizeMode) {
2190 case PictureBoxSizeMode.StretchImage:
2191 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2194 case PictureBoxSizeMode.CenterImage:
2195 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2199 dc.DrawImage(pb.Image, 0, 0);
2203 CPDrawBorderStyle (dc, client, pb.BorderStyle);
2206 public override Size PictureBoxDefaultSize {
2208 return new Size (100, 50);
2211 #endregion // PictureBox
2214 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2216 Rectangle block_rect;
2217 Rectangle client_area = ctrl.client_area;
2218 int space_betweenblocks = 2;
2223 block_width = ((client_area.Height) * 2 ) / 3;
2224 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2225 increment = block_width + space_betweenblocks;
2228 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
2231 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2232 while ((block_rect.X - client_area.X) < barpos_pixels) {
2234 if (clip_rect.IntersectsWith (block_rect) == true) {
2235 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2238 block_rect.X += increment;
2242 public override Size ProgressBarDefaultSize {
2244 return new Size (100, 23);
2248 #endregion // ProgressBar
2251 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2252 StringFormat text_format;
2253 Rectangle client_rectangle;
2254 Rectangle text_rectangle;
2255 Rectangle radiobutton_rectangle;
2257 int radiobutton_size = 12;
2258 int radiobutton_space = 4;
2260 client_rectangle = radio_button.ClientRectangle;
2261 text_rectangle = client_rectangle;
2262 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2264 text_format = new StringFormat();
2265 text_format.Alignment = StringAlignment.Near;
2266 text_format.LineAlignment = StringAlignment.Center;
2267 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2269 /* Calculate the position of text and checkbox rectangle */
2270 if (radio_button.appearance!=Appearance.Button) {
2271 switch(radio_button.radiobutton_alignment) {
2272 case ContentAlignment.BottomCenter: {
2273 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2274 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2275 text_rectangle.X=client_rectangle.X;
2276 text_rectangle.Width=client_rectangle.Width;
2277 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2281 case ContentAlignment.BottomLeft: {
2282 radiobutton_rectangle.X=client_rectangle.Left;
2283 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2284 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2285 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2289 case ContentAlignment.BottomRight: {
2290 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2291 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2292 text_rectangle.X=client_rectangle.X;
2293 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2297 case ContentAlignment.MiddleCenter: {
2298 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2299 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2300 text_rectangle.X=client_rectangle.X;
2301 text_rectangle.Width=client_rectangle.Width;
2306 case ContentAlignment.MiddleLeft: {
2307 radiobutton_rectangle.X=client_rectangle.Left;
2308 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2309 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2310 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2314 case ContentAlignment.MiddleRight: {
2315 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2316 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2317 text_rectangle.X=client_rectangle.X;
2318 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2322 case ContentAlignment.TopCenter: {
2323 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2324 radiobutton_rectangle.Y=client_rectangle.Top;
2325 text_rectangle.X=client_rectangle.X;
2326 text_rectangle.Y=radiobutton_size+radiobutton_space;
2327 text_rectangle.Width=client_rectangle.Width;
2328 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2332 case ContentAlignment.TopLeft: {
2333 radiobutton_rectangle.X=client_rectangle.Left;
2334 radiobutton_rectangle.Y=client_rectangle.Top;
2335 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2336 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2340 case ContentAlignment.TopRight: {
2341 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2342 radiobutton_rectangle.Y=client_rectangle.Top;
2343 text_rectangle.X=client_rectangle.X;
2344 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2349 text_rectangle.X=client_rectangle.X;
2350 text_rectangle.Width=client_rectangle.Width;
2353 /* Set the horizontal alignment of our text */
2354 switch(radio_button.text_alignment) {
2355 case ContentAlignment.BottomLeft:
2356 case ContentAlignment.MiddleLeft:
2357 case ContentAlignment.TopLeft: {
2358 text_format.Alignment=StringAlignment.Near;
2362 case ContentAlignment.BottomCenter:
2363 case ContentAlignment.MiddleCenter:
2364 case ContentAlignment.TopCenter: {
2365 text_format.Alignment=StringAlignment.Center;
2369 case ContentAlignment.BottomRight:
2370 case ContentAlignment.MiddleRight:
2371 case ContentAlignment.TopRight: {
2372 text_format.Alignment=StringAlignment.Far;
2377 /* Set the vertical alignment of our text */
2378 switch(radio_button.text_alignment) {
2379 case ContentAlignment.TopLeft:
2380 case ContentAlignment.TopCenter:
2381 case ContentAlignment.TopRight: {
2382 text_format.LineAlignment=StringAlignment.Near;
2386 case ContentAlignment.BottomLeft:
2387 case ContentAlignment.BottomCenter:
2388 case ContentAlignment.BottomRight: {
2389 text_format.LineAlignment=StringAlignment.Far;
2393 case ContentAlignment.MiddleLeft:
2394 case ContentAlignment.MiddleCenter:
2395 case ContentAlignment.MiddleRight: {
2396 text_format.LineAlignment=StringAlignment.Center;
2401 ButtonState state = ButtonState.Normal;
2402 if (radio_button.FlatStyle == FlatStyle.Flat) {
2403 state |= ButtonState.Flat;
2406 if (radio_button.Checked) {
2407 state |= ButtonState.Checked;
2412 sb=new SolidBrush(radio_button.BackColor);
2413 dc.FillRectangle(sb, radio_button.ClientRectangle);
2418 if (radio_button.appearance==Appearance.Button) {
2419 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2420 DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
2422 CPDrawButton(dc, radio_button.ClientRectangle, state);
2425 // establish if we are rendering a flat style of some sort
2426 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2427 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2429 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
2433 // offset the text if it's pressed and a button
2434 if (radio_button.Appearance == Appearance.Button) {
2435 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
2436 text_rectangle.X ++;
2437 text_rectangle.Y ++;
2440 text_rectangle.Inflate(-4,-4);
2443 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
2444 sb=new SolidBrush(radio_button.ForeColor);
2445 dc.DrawString (radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2447 if (radio_button.Enabled) {
2448 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
2449 dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2450 } else if (radio_button.FlatStyle == FlatStyle.Flat) {
2451 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
2453 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorButtonText, text_rectangle, text_format);
2456 if (radio_button.Focused) {
2457 if (radio_button.FlatStyle != FlatStyle.Flat) {
2458 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
2460 dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
2465 // renders a radio button with the Flat and Popup FlatStyle
2466 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2470 if (radio_button.Enabled) {
2471 // draw the outer flatstyle arcs
2472 if (radio_button.FlatStyle == FlatStyle.Flat) {
2473 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
2475 // fill in the area depending on whether or not the mouse is hovering
2476 if (radio_button.is_entered && radio_button.Capture) {
2477 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2479 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2482 // must be a popup radio button
2484 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
2486 if (radio_button.is_entered || radio_button.Capture) {
2487 // draw the popup 3d button knob
2488 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2490 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
2491 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
2494 // just draw lighter flatstyle outer circle
2495 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorButtonFace)), rectangle, 0, 359);
2500 // fill control background color regardless of actual backcolor
2501 graphics.FillPie (ResPool.GetSolidBrush (this.ColorButtonFace), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2502 // draw the ark as control dark
2503 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorButtonFace)), rectangle, 0, 359);
2507 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2508 if (radio_button.Checked) {
2509 SolidBrush buttonBrush;
2511 if (!radio_button.Enabled) {
2512 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorButtonFace));
2513 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
2514 buttonBrush = ResPool.GetSolidBrush (this.ColorButtonText);
2516 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
2518 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
2522 public override Size RadioButtonDefaultSize {
2524 return new Size (104,24);
2527 #endregion // RadioButton
2530 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2532 int scrollbutton_width = bar.scrollbutton_width;
2533 int scrollbutton_height = bar.scrollbutton_height;
2534 Rectangle first_arrow_area;
2535 Rectangle second_arrow_area;
2536 Rectangle thumb_pos;
2538 thumb_pos = bar.ThumbPos;
2541 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2542 bar.FirstArrowArea = first_arrow_area;
2544 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2545 bar.SecondArrowArea = second_arrow_area;
2547 thumb_pos.Width = bar.Width;
2548 bar.ThumbPos = thumb_pos;
2551 if (clip.IntersectsWith (first_arrow_area))
2552 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2553 if (clip.IntersectsWith (second_arrow_area))
2554 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2557 switch (bar.thumb_moving) {
2558 case ScrollBar.ThumbMoving.None: {
2559 Rectangle r = new Rectangle (0,
2560 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
2561 Rectangle intersect = Rectangle.Intersect (clip, r);
2563 if (intersect != Rectangle.Empty)
2564 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2567 case ScrollBar.ThumbMoving.Forward: {
2568 Rectangle r = new Rectangle (0, scrollbutton_height,
2569 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2570 Rectangle intersect = Rectangle.Intersect (clip, r);
2572 if (intersect != Rectangle.Empty)
2573 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2576 r.Y = thumb_pos.Y + thumb_pos.Height;
2577 r.Width = bar.ClientRectangle.Width;
2578 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2580 intersect = Rectangle.Intersect (clip, r);
2581 if (intersect != Rectangle.Empty)
2582 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2586 case ScrollBar.ThumbMoving.Backwards: {
2587 Rectangle r = new Rectangle (0, scrollbutton_height,
2588 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2589 Rectangle intersect = Rectangle.Intersect (clip, r);
2591 if (intersect != Rectangle.Empty)
2592 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2595 r.Y = thumb_pos.Y + thumb_pos.Height;
2596 r.Width = bar.ClientRectangle.Width;
2597 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2599 intersect = Rectangle.Intersect (clip, r);
2600 if (intersect != Rectangle.Empty)
2601 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2609 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2610 bar.FirstArrowArea = first_arrow_area;
2612 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2613 bar.SecondArrowArea = second_arrow_area;
2615 thumb_pos.Height = bar.Height;
2616 bar.ThumbPos = thumb_pos;
2619 if (clip.IntersectsWith (first_arrow_area))
2620 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2621 if (clip.IntersectsWith (second_arrow_area))
2622 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2625 switch (bar.thumb_moving) {
2626 case ScrollBar.ThumbMoving.None: {
2627 Rectangle r = new Rectangle (scrollbutton_width,
2628 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
2629 Rectangle intersect = Rectangle.Intersect (clip, r);
2631 if (intersect != Rectangle.Empty)
2632 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2636 case ScrollBar.ThumbMoving.Forward: {
2637 Rectangle r = new Rectangle (scrollbutton_width, 0,
2638 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2639 Rectangle intersect = Rectangle.Intersect (clip, r);
2641 if (intersect != Rectangle.Empty)
2642 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2644 r.X = thumb_pos.X + thumb_pos.Width;
2646 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2647 r.Height = bar.ClientRectangle.Height;
2649 intersect = Rectangle.Intersect (clip, r);
2650 if (intersect != Rectangle.Empty)
2651 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2655 case ScrollBar.ThumbMoving.Backwards: {
2656 Rectangle r = new Rectangle (scrollbutton_width, 0,
2657 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2658 Rectangle intersect = Rectangle.Intersect (clip, r);
2660 if (intersect != Rectangle.Empty)
2661 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2663 r.X = thumb_pos.X + thumb_pos.Width;
2665 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2666 r.Height = bar.ClientRectangle.Height;
2668 intersect = Rectangle.Intersect (clip, r);
2669 if (intersect != Rectangle.Empty)
2670 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2677 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith (thumb_pos))
2678 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
2681 public override int ScrollBarButtonSize {
2684 #endregion // ScrollBar
2687 public override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
2688 Rectangle area = sb.paint_area;
2689 int horz_border = 2;
2690 int vert_border = 2;
2692 dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
2694 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
2695 string text = sb.Text;
2696 StringFormat string_format = new StringFormat ();
2697 string_format.Trimming = StringTrimming.Character;
2698 string_format.FormatFlags = StringFormatFlags.NoWrap;
2700 if (text [0] == '\t') {
2701 string_format.Alignment = StringAlignment.Center;
2702 text = text.Substring (1);
2703 if (text [0] == '\t') {
2704 string_format.Alignment = StringAlignment.Far;
2705 text = text.Substring (1);
2709 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor), new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
2710 } else if (sb.ShowPanels) {
2711 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
2712 int prev_x = area.X + horz_border;
2713 int y = area.Y + vert_border;
2714 for (int i = 0; i < sb.Panels.Count; i++) {
2715 Rectangle pr = new Rectangle (prev_x, y,
2716 sb.Panels [i].Width, area.Height);
2717 prev_x += pr.Width + StatusBarHorzGapWidth;
2718 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
2723 CPDrawSizeGrip (dc, ColorButtonFace, area);
2728 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
2729 SolidBrush br_forecolor, StatusBarPanel panel) {
2730 int border_size = 3; // this is actually const, even if the border style is none
2732 area.Height -= border_size;
2733 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
2734 Border3DStyle border_style = Border3DStyle.SunkenInner;
2735 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
2736 border_style = Border3DStyle.RaisedOuter;
2737 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
2740 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
2741 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
2742 dc, panel.Parent.Font, area, index, DrawItemState.Default,
2743 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
2744 panel.Parent.OnDrawItemInternal (e);
2748 int left = area.Left;
2749 if (panel.Icon != null) {
2751 dc.DrawIcon (panel.Icon, left, area.Top);
2752 left += panel.Icon.Width;
2755 if (panel.Text == String.Empty)
2758 string text = panel.Text;
2759 StringFormat string_format = new StringFormat ();
2760 string_format.Trimming = StringTrimming.Character;
2761 string_format.FormatFlags = StringFormatFlags.NoWrap;
2763 if (text [0] == '\t') {
2764 string_format.Alignment = StringAlignment.Center;
2765 text = text.Substring (1);
2766 if (text [0] == '\t') {
2767 string_format.Alignment = StringAlignment.Far;
2768 text = text.Substring (1);
2772 int x = left + border_size;
2773 int y = border_size + 2;
2774 Rectangle r = new Rectangle (x, y,
2775 area.Right - x - border_size,
2776 area.Bottom - y - border_size);
2778 dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
2781 public override int StatusBarSizeGripWidth {
2785 public override int StatusBarHorzGapWidth {
2789 public override Size StatusBarDefaultSize {
2791 return new Size (100, 22);
2794 #endregion // StatusBar
2796 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
2798 // Do we need to fill the back color? It can't be changed...
2799 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
2800 Rectangle panel_rect = GetTabPanelRectExt (tab);
2802 if (tab.Appearance == TabAppearance.Normal) {
2803 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorButtonFace);
2804 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2807 if (tab.Alignment == TabAlignment.Top) {
2808 for (int r = tab.TabPages.Count; r > 0; r--) {
2809 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2810 if (i == tab.SelectedIndex)
2812 if (r != tab.TabPages [i].Row)
2814 Rectangle rect = tab.GetTabRect (i);
2815 if (!rect.IntersectsWith (area))
2817 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2821 for (int r = 0; r < tab.TabPages.Count; r++) {
2822 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2823 if (i == tab.SelectedIndex)
2825 if (r != tab.TabPages [i].Row)
2827 Rectangle rect = tab.GetTabRect (i);
2828 if (!rect.IntersectsWith (area))
2830 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2835 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
2836 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
2837 if (rect.IntersectsWith (area))
2838 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
2841 if (tab.ShowSlider) {
2842 Rectangle right = GetTabControlRightScrollRect (tab);
2843 Rectangle left = GetTabControlLeftScrollRect (tab);
2844 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
2845 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
2849 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
2851 switch (tab.Alignment) {
2852 case TabAlignment.Top:
2853 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
2855 Rectangle panel_rect = GetTabPanelRectExt (tab);
2856 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
2860 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
2862 switch (tab.Alignment) {
2863 case TabAlignment.Top:
2864 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
2866 Rectangle panel_rect = GetTabPanelRectExt (tab);
2867 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
2871 public override Size TabControlDefaultItemSize {
2872 get { return new Size (42, 21); }
2875 public override Point TabControlDefaultPadding {
2876 get { return new Point (6, 3); }
2879 public override int TabControlMinimumTabWidth {
2883 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
2885 Rectangle ext = GetTabPanelRectExt (tab);
2886 // Account for border size
2887 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
2890 public override Size TabControlGetSpacing (TabControl tab) {
2891 switch (tab.Appearance) {
2892 case TabAppearance.Normal:
2893 return new Size (1, -2);
2894 case TabAppearance.Buttons:
2895 return new Size (3, 3);
2896 case TabAppearance.FlatButtons:
2897 return new Size (9, 3);
2899 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
2903 private Rectangle GetTabPanelRectExt (TabControl tab)
2905 // Offset the tab from the top corner
2906 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
2907 tab.ClientRectangle.Y,
2908 tab.ClientRectangle.Width - 2,
2909 tab.ClientRectangle.Height - 1);
2911 if (tab.TabCount == 0)
2914 int spacing = TabControlGetSpacing (tab).Height;
2915 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
2917 switch (tab.Alignment) {
2918 case TabAlignment.Left:
2920 res.Width -= offset;
2922 case TabAlignment.Right:
2923 res.Width -= offset;
2925 case TabAlignment.Top:
2927 res.Height -= offset;
2929 case TabAlignment.Bottom:
2930 res.Height -= offset;
2937 private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
2939 int FlatButtonSpacing = 8;
2941 int res = bounds.Width;
2943 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
2945 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
2947 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2950 if (tab.Appearance == TabAppearance.FlatButtons) {
2951 int width = bounds.Width;
2952 bounds.Width += (FlatButtonSpacing - 2);
2954 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
2955 bounds.Width = width;
2959 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
2960 } else if (tab.Appearance != TabAppearance.FlatButtons) {
2961 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
2964 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
2966 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
2968 switch (tab.Alignment) {
2970 case TabAlignment.Top:
2973 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2975 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
2976 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
2977 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
2979 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
2980 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
2981 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
2983 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2985 if (page.Text != String.Empty) {
2986 StringFormat string_format = new StringFormat ();
2987 string_format.Alignment = StringAlignment.Center;
2988 string_format.LineAlignment = StringAlignment.Center;
2989 string_format.FormatFlags = StringFormatFlags.NoWrap;
2991 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2997 case TabAlignment.Bottom:
2999 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3001 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3002 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3004 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3005 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3007 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3008 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3009 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3011 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3013 if (page.Text != String.Empty) {
3014 StringFormat string_format = new StringFormat ();
3015 string_format.Alignment = StringAlignment.Center;
3016 string_format.LineAlignment = StringAlignment.Center;
3017 string_format.FormatFlags = StringFormatFlags.NoWrap;
3019 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
3025 case TabAlignment.Left:
3027 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3029 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3030 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3031 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3033 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3035 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3036 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3038 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3040 if (page.Text != String.Empty) {
3041 StringFormat string_format = new StringFormat ();
3042 // Flip the text around
3043 string_format.Alignment = StringAlignment.Center;
3044 string_format.LineAlignment = StringAlignment.Center;
3045 string_format.FormatFlags = StringFormatFlags.NoWrap;
3046 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3047 int wo = interior.Width / 2;
3048 int ho = interior.Height / 2;
3049 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3050 dc.RotateTransform (180);
3051 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), 0, 0, string_format);
3052 dc.ResetTransform ();
3058 // TabAlignment.Right
3060 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3062 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3063 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3065 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3066 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3068 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3069 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3071 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3073 if (page.Text != String.Empty) {
3074 StringFormat string_format = new StringFormat ();
3075 string_format.Alignment = StringAlignment.Center;
3076 string_format.LineAlignment = StringAlignment.Center;
3077 string_format.FormatFlags = StringFormatFlags.NoWrap;
3078 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3080 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
3089 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3096 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
3097 StringFormat format = new StringFormat ();
3098 format.Trimming = StringTrimming.EllipsisWord;
3099 if (control.textAlignment == ToolBarTextAlign.Underneath) {
3100 format.LineAlignment = StringAlignment.Center;
3101 format.Alignment = StringAlignment.Center;
3103 format.LineAlignment = StringAlignment.Center;
3104 format.Alignment = StringAlignment.Near;
3107 // Exclude the area for divider
3108 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
3109 control.Width, control.Height - ToolBarGripWidth / 2);
3110 bool flat = (control.Appearance == ToolBarAppearance.Flat);
3111 dc.FillRectangle (SystemBrushes.Control, paint_area);
3112 CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
3114 if (control.Divider)
3115 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
3117 foreach (ToolBarButton button in control.Buttons) {
3120 Rectangle buttonArea = button.Rectangle;
3121 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
3122 Rectangle txtRect = buttonArea; // rect to draw the text
3123 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
3125 // calculate different rects and draw the frame if its not separator button
3126 if (button.Style != ToolBarButtonStyle.Separator) {
3127 /* Adjustment for drop down arrow */
3128 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
3129 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
3130 ddRect.Y = buttonArea.Y;
3131 ddRect.Width = this.ToolBarDropDownWidth;
3132 ddRect.Height = buttonArea.Height;
3135 // calculate txtRect and imgRect, if imageIndex and imageList are present
3136 if (button.ImageIndex > -1 && control.ImageList != null) {
3137 if (button.ImageIndex < control.ImageList.Images.Count)
3138 image = control.ImageList.Images [button.ImageIndex];
3139 // draw the image at the centre if textalignment is underneath
3140 if (control.TextAlign == ToolBarTextAlign.Underneath) {
3141 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
3142 - control.ImageSize.Width) / 2)
3143 + this.ToolBarImageGripWidth;
3144 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3145 imgRect.Width = control.ImageSize.Width;
3146 imgRect.Height = control.ImageSize.Height;
3148 txtRect.X = buttonArea.X;
3149 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
3150 txtRect.Width = buttonArea.Width - ddRect.Width;
3151 txtRect.Height = buttonArea.Height - imgRect.Height
3152 - 2 * this.ToolBarImageGripWidth;
3155 imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
3156 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3157 imgRect.Width = control.ImageSize.Width;
3158 imgRect.Height = control.ImageSize.Height;
3160 txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
3161 txtRect.Y = buttonArea.Y;
3162 txtRect.Width = buttonArea.Width - imgRect.Width
3163 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
3164 txtRect.Height = buttonArea.Height;
3167 /* Draw the button frame, only if it is not a separator */
3169 if (button.Pushed || button.Pressed) {
3170 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
3171 } else if (button.Hilight) {
3172 dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
3173 if (! ddRect.IsEmpty) {
3174 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
3175 ddRect.Y + ddRect.Height);
3176 buttonArea.Width -= this.ToolBarDropDownWidth;
3180 else { // normal toolbar
3181 if (button.Pushed || button.Pressed) {
3182 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
3183 Border3DSide.All, ColorButtonFace);
3184 if (! ddRect.IsEmpty) {
3185 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
3186 Border3DSide.Left, ColorButtonFace);
3187 buttonArea.Width -= this.ToolBarDropDownWidth;
3191 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
3192 Border3DSide.All, ColorButtonFace);
3193 if (! ddRect.IsEmpty) {
3194 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
3195 Border3DSide.Left, ColorButtonFace);
3196 buttonArea.Width -= this.ToolBarDropDownWidth;
3201 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
3202 imgRect, image, txtRect, ddRect, flat);
3206 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
3207 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
3208 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
3209 if (! button.Visible)
3212 switch (button.Style) {
3214 case ToolBarButtonStyle.Separator:
3215 // separator is drawn only in the case of flat appearance
3217 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
3218 buttonArea.X + 1, buttonArea.Height);
3219 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
3220 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
3221 /* draw a horizontal separator */
3222 if (button.Wrapper) {
3223 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
3224 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
3225 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
3226 y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
3231 case ToolBarButtonStyle.ToggleButton:
3232 Rectangle toggleArea = Rectangle.Empty;
3233 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
3234 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3235 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
3236 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
3237 if (button.PartialPush && button.Pushed) {
3238 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3239 if (! imgRect.IsEmpty) {
3240 if (button.Enabled && image != null)
3241 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3242 imgRect.Height, button.ImageIndex);
3244 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3245 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3246 Border3DSide.Right | Border3DSide.Bottom);
3250 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3252 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
3255 else if (button.PartialPush) {
3256 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
3257 if (! imgRect.IsEmpty) {
3258 if (button.Enabled && image != null)
3259 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3260 imgRect.Height, button.ImageIndex);
3262 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3263 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3264 Border3DSide.Right | Border3DSide.Bottom);
3268 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3270 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3274 else if (button.Pushed) {
3275 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3276 if (! imgRect.IsEmpty) {
3277 if (button.Enabled && image != null)
3278 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3279 imgRect.Height, button.ImageIndex);
3281 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3282 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3283 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3287 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3289 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3294 dc.FillRectangle (SystemBrushes.Control, toggleArea);
3295 if (! imgRect.IsEmpty) {
3296 if (button.Enabled && image != null)
3297 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3298 imgRect.Height, button.ImageIndex);
3300 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3301 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3302 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3306 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3308 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3313 case ToolBarButtonStyle.DropDownButton:
3314 // draw the dropdown arrow
3315 if (! ddRect.IsEmpty) {
3316 PointF [] vertices = new PointF [3];
3317 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
3318 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3319 vertices [0].Y = ddCenter.Y;
3320 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3321 vertices [1].Y = ddCenter.Y;
3322 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3323 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
3324 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3326 goto case ToolBarButtonStyle.PushButton;
3328 case ToolBarButtonStyle.PushButton:
3329 if (! imgRect.IsEmpty){
3330 if (button.Enabled && image != null)
3331 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
3334 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3335 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3336 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3340 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3342 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3348 // Grip width for the ToolBar
3349 public override int ToolBarGripWidth {
3353 // Grip width for the Image on the ToolBarButton
3354 public override int ToolBarImageGripWidth {
3358 // width of the separator
3359 public override int ToolBarSeparatorWidth {
3363 // width of the dropdown arrow rect
3364 public override int ToolBarDropDownWidth {
3368 // width for the dropdown arrow on the ToolBarButton
3369 public override int ToolBarDropDownArrowWidth {
3373 // height for the dropdown arrow on the ToolBarButton
3374 public override int ToolBarDropDownArrowHeight {
3378 public override Size ToolBarDefaultSize {
3380 return new Size (100, 42);
3383 #endregion // ToolBar
3386 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt) {
3389 control = tt.tooltip_window;
3390 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
3391 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
3392 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, tt.tooltip_window.string_format);
3395 public override Size ToolTipSize(ToolTip tt, string text) {
3398 sizef = tt.tooltip_window.DeviceContext.MeasureString(text, tt.tooltip_window.Font);
3399 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
3401 #endregion // ToolTip
3404 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3405 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3406 float ticks, int value_pos, bool mouse_value) {
3408 Point toptick_startpoint = new Point ();
3409 Point bottomtick_startpoint = new Point ();
3410 Point channel_startpoint = new Point ();
3412 float pixels_betweenticks;
3413 const int space_from_right = 8;
3414 const int space_from_left = 8;
3415 Rectangle area = tb.ClientRectangle;
3417 switch (tb.TickStyle) {
3418 case TickStyle.BottomRight:
3419 case TickStyle.None:
3420 channel_startpoint.Y = 8;
3421 channel_startpoint.X = 9;
3422 bottomtick_startpoint.Y = 13;
3423 bottomtick_startpoint.X = 24;
3425 case TickStyle.TopLeft:
3426 channel_startpoint.Y = 8;
3427 channel_startpoint.X = 19;
3428 toptick_startpoint.Y = 13;
3429 toptick_startpoint.X = 8;
3431 case TickStyle.Both:
3432 channel_startpoint.Y = 8;
3433 channel_startpoint.X = 18;
3434 bottomtick_startpoint.Y = 13;
3435 bottomtick_startpoint.X = 32;
3436 toptick_startpoint.Y = 13;
3437 toptick_startpoint.X = 8;
3443 thumb_area.X = area.X + channel_startpoint.X;
3444 thumb_area.Y = area.Y + channel_startpoint.Y;
3445 thumb_area.Height = area.Height - space_from_right - space_from_left;
3446 thumb_area.Width = 4;
3449 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3450 1, thumb_area.Height);
3452 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
3453 1, thumb_area.Height);
3455 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
3456 1, thumb_area.Height);
3458 pixel_len = thumb_area.Height - 11;
3459 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3461 /* Convert thumb position from mouse position to value*/
3464 if (value_pos >= channel_startpoint.Y)
3465 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
3469 if (value_pos + tb.Minimum > tb.Maximum)
3470 value_pos = tb.Maximum - tb.Minimum;
3472 tb.Value = value_pos + tb.Minimum;
3475 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
3477 /* Draw thumb fixed 10x22 size */
3478 thumb_pos.Width = 10;
3479 thumb_pos.Height = 22;
3481 switch (tb.TickStyle) {
3482 case TickStyle.BottomRight:
3483 case TickStyle.None: {
3484 thumb_pos.X = channel_startpoint.X - 8;
3486 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3487 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3488 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3490 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3491 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3493 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3494 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3496 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3497 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3498 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3499 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3503 case TickStyle.TopLeft: {
3504 thumb_pos.X = channel_startpoint.X - 10;
3506 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3507 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3509 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3510 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3511 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3513 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3514 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3515 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3517 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3518 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3519 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3520 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3525 case TickStyle.Both: {
3526 thumb_pos.X = area.X + 10;
3527 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3528 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3530 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3531 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3533 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3534 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3536 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3545 pixel_len = thumb_area.Height - 11;
3546 pixels_betweenticks = pixel_len / ticks;
3548 thumb_area.X = thumb_pos.X;
3549 thumb_area.Y = channel_startpoint.Y;
3550 thumb_area.Width = thumb_pos.Height;
3553 Region outside = new Region (area);
3554 outside.Exclude (thumb_area);
3556 if (outside.IsVisible (clip_rectangle)) {
3557 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3558 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3560 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3561 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3562 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3563 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3565 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3566 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3570 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3571 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3573 pixel_len = thumb_area.Height - 11;
3574 pixels_betweenticks = pixel_len / ticks;
3576 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3577 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3578 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3579 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3581 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3582 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3592 Does not matter the size of the control, Win32 always draws:
3593 - Ticks starting from pixel 13, 8
3594 - Channel starting at pos 8, 19 and ends at Width - 8
3595 - Autosize makes always the control 40 pixels height
3596 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3599 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3600 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3601 float ticks, int value_pos, bool mouse_value) {
3602 Point toptick_startpoint = new Point ();
3603 Point bottomtick_startpoint = new Point ();
3604 Point channel_startpoint = new Point ();
3606 float pixels_betweenticks;
3607 const int space_from_right = 8;
3608 const int space_from_left = 8;
3609 Rectangle area = tb.ClientRectangle;
3611 switch (tb.TickStyle) {
3612 case TickStyle.BottomRight:
3613 case TickStyle.None:
3614 channel_startpoint.X = 8;
3615 channel_startpoint.Y = 9;
3616 bottomtick_startpoint.X = 13;
3617 bottomtick_startpoint.Y = 24;
3619 case TickStyle.TopLeft:
3620 channel_startpoint.X = 8;
3621 channel_startpoint.Y = 19;
3622 toptick_startpoint.X = 13;
3623 toptick_startpoint.Y = 8;
3625 case TickStyle.Both:
3626 channel_startpoint.X = 8;
3627 channel_startpoint.Y = 18;
3628 bottomtick_startpoint.X = 13;
3629 bottomtick_startpoint.Y = 32;
3630 toptick_startpoint.X = 13;
3631 toptick_startpoint.Y = 8;
3637 thumb_area.X = area.X + channel_startpoint.X;
3638 thumb_area.Y = area.Y + channel_startpoint.Y;
3639 thumb_area.Width = area.Width - space_from_right - space_from_left;
3640 thumb_area.Height = 4;
3643 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3644 thumb_area.Width, 1);
3646 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
3647 thumb_area.Width, 1);
3649 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
3650 thumb_area.Width, 1);
3652 pixel_len = thumb_area.Width - 11;
3653 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3655 /* Convert thumb position from mouse position to value*/
3657 if (value_pos >= channel_startpoint.X)
3658 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
3662 if (value_pos + tb.Minimum > tb.Maximum)
3663 value_pos = tb.Maximum - tb.Minimum;
3665 tb.Value = value_pos + tb.Minimum;
3668 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
3670 /* Draw thumb fixed 10x22 size */
3671 thumb_pos.Width = 10;
3672 thumb_pos.Height = 22;
3674 switch (tb.TickStyle) {
3675 case TickStyle.BottomRight:
3676 case TickStyle.None: {
3677 thumb_pos.Y = channel_startpoint.Y - 8;
3679 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
3680 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
3681 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
3683 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
3684 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
3686 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
3687 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
3689 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
3690 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
3691 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
3692 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
3695 case TickStyle.TopLeft: {
3696 thumb_pos.Y = channel_startpoint.Y - 10;
3698 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
3699 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
3701 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
3702 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
3703 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
3705 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
3706 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
3707 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
3709 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
3710 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
3711 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
3712 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
3716 case TickStyle.Both: {
3717 thumb_pos.Y = area.Y + 10;
3718 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
3719 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
3721 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
3722 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
3724 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
3725 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
3727 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
3736 pixel_len = thumb_area.Width - 11;
3737 pixels_betweenticks = pixel_len / ticks;
3740 thumb_area.Y = thumb_pos.Y;
3741 thumb_area.X = channel_startpoint.X;
3742 thumb_area.Height = thumb_pos.Height;
3743 Region outside = new Region (area);
3744 outside.Exclude (thumb_area);
3746 if (outside.IsVisible (clip_rectangle)) {
3747 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3748 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3750 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3751 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3752 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
3753 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
3755 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
3756 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
3760 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3761 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3763 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3764 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3765 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
3766 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
3768 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
3769 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
3775 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
3780 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
3782 Rectangle thumb_pos = tb.ThumbPos;
3783 Rectangle thumb_area = tb.ThumbArea;
3785 if (tb.thumb_pressed) {
3786 value_pos = tb.thumb_mouseclick;
3789 value_pos = tb.Value - tb.Minimum;
3790 mouse_value = false;
3793 area = tb.ClientRectangle;
3795 if (tb.thumb_pressed == true) {
3796 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
3798 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
3802 /* Control Background */
3803 if (tb.BackColor == DefaultControlBackColor) {
3804 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), clip_rectangle);
3806 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
3811 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
3812 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
3813 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
3814 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
3817 if (tb.Orientation == Orientation.Vertical) {
3818 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3819 br_thumb, ticks, value_pos, mouse_value);
3822 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3823 br_thumb, ticks, value_pos, mouse_value);
3826 tb.ThumbPos = thumb_pos;
3827 tb.ThumbArea = thumb_area;
3830 public override Size TrackBarDefaultSize {
3832 return new Size (104, 42);
3836 #endregion // TrackBar
3839 public override Size VScrollBarDefaultSize {
3841 return new Size (this.ScrollBarButtonSize, 80);
3844 #endregion // VScrollBar
3847 public override Size TreeViewDefaultSize {
\r
3849 return new Size (121, 97);
\r
3855 #region ControlPaint
3856 private enum DrawFrameControlStates {
3857 ButtonCheck = 0x0000,
3858 ButtonRadioImage = 0x0001,
3859 ButtonRadioMask = 0x0002,
3860 ButtonRadio = 0x0004,
3861 Button3State = 0x0008,
3862 ButtonPush = 0x0010,
3864 CaptionClose = 0x0000,
3865 CaptionMin = 0x0001,
3866 CaptionMax = 0x0002,
3867 CaptionRestore = 0x0004,
3868 CaptionHelp = 0x0008,
3872 MenuBullet = 0x0002,
3873 MenuArrowRight = 0x0004,
3876 ScrollDown = 0x0001,
3877 ScrollLeft = 0x0002,
3878 ScrollRight = 0x0003,
3879 ScrollComboBox = 0x0005,
3880 ScrollSizeGrip = 0x0008,
3881 ScrollSizeGripRight = 0x0010,
3886 Transparent = 0x0800,
3888 AdjustRect = 0x2000,
3894 private enum DrawFrameControlTypes {
3901 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
3902 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3903 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3904 int bottomWidth, ButtonBorderStyle bottomStyle) {
3905 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
3906 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
3907 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
3908 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
3911 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
3912 CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
3915 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
3917 Pen penTopLeftInner;
3919 Pen penBottomRightInner;
3920 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
3921 bool doInner = false;
3923 if ((style & Border3DStyle.Adjust)!=0) {
3930 /* default to flat */
3931 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
3932 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3933 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
3934 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3936 if ((style & Border3DStyle.RaisedOuter)!=0) {
3937 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3938 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3939 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3942 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
3943 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3944 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
3945 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3950 if ((style & Border3DStyle.RaisedInner)!=0) {
3952 penTopLeftInner=ResPool.GetPen(control_color);
3953 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3955 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3956 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3958 } else if ((style & Border3DStyle.SunkenInner)!=0) {
3960 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3961 penBottomRightInner=ResPool.GetPen(control_color);
3963 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3964 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
3968 if ((sides & Border3DSide.Middle)!=0) {
3969 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
3972 if ((sides & Border3DSide.Left)!=0) {
3973 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
3975 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
3979 if ((sides & Border3DSide.Top)!=0) {
3980 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
3983 if ((sides & Border3DSide.Left)!=0) {
3984 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
3986 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
3991 if ((sides & Border3DSide.Right)!=0) {
3992 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
3995 if ((sides & Border3DSide.Top)!=0) {
3996 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
3998 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
4003 if ((sides & Border3DSide.Bottom)!=0) {
4006 if ((sides & Border3DSide.Left)!=0) {
4010 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
4013 if ((sides & Border3DSide.Right)!=0) {
4014 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4016 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4024 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4025 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
4027 if ((state & ButtonState.Pushed)!=0) {
4028 dfcs |= DrawFrameControlStates.Pushed;
4031 if ((state & ButtonState.Checked)!=0) {
4032 dfcs |= DrawFrameControlStates.Checked;
4035 if ((state & ButtonState.Flat)!=0) {
4036 dfcs |= DrawFrameControlStates.Flat;
4039 if ((state & ButtonState.Inactive)!=0) {
4040 dfcs |= DrawFrameControlStates.Inactive;
4042 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4046 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4047 Rectangle captionRect;
4050 CPDrawButton(graphics, rectangle, state);
4052 if (rectangle.Width<rectangle.Height) {
4053 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4055 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4058 if ((state & ButtonState.Pushed)!=0) {
4059 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4062 /* Make sure we've got at least a line width of 1 */
4063 lineWidth=Math.Max(1, captionRect.Width/7);
4066 case CaptionButton.Close: {
4069 if ((state & ButtonState.Inactive)!=0) {
4070 pen=new Pen(ColorButtonHilight, lineWidth);
4071 DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
4074 pen=new Pen(ColorButtonShadow, lineWidth);
4075 DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
4079 pen=new Pen(ColorButtonText, lineWidth);
4080 DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
4086 case CaptionButton.Help:
4087 case CaptionButton.Maximize:
4088 case CaptionButton.Minimize:
4089 case CaptionButton.Restore: {
4090 if ((state & ButtonState.Inactive)!=0) {
4091 DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4093 DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4096 DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4104 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
4105 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
4107 if ((state & ButtonState.Pushed)!=0) {
4108 dfcs |= DrawFrameControlStates.Pushed;
4111 if ((state & ButtonState.Checked)!=0) {
4112 dfcs |= DrawFrameControlStates.Checked;
4115 if ((state & ButtonState.Flat)!=0) {
4116 dfcs |= DrawFrameControlStates.Flat;
4119 if ((state & ButtonState.Inactive)!=0) {
4120 dfcs |= DrawFrameControlStates.Inactive;
4123 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4127 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4128 Point[] arrow = new Point[3];
4138 if ((state & ButtonState.Checked)!=0) {
4139 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);
4142 if ((state & ButtonState.Flat)!=0) {
4143 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4145 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4146 // this needs to render like a pushed button - jba
4147 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4148 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4149 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4151 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4155 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4156 centerX=rect.Left+rect.Width/2;
4157 centerY=rect.Top+rect.Height/2;
4158 shiftX=Math.Max(1, rect.Width/8);
4159 shiftY=Math.Max(1, rect.Height/8);
4161 if ((state & ButtonState.Pushed)!=0) {
4168 P1=new Point(rect.Left, centerY);
4169 P2=new Point(rect.Right, centerY);
4170 P3=new Point(centerX, rect.Bottom);
4176 /* Draw the arrow */
4177 if ((state & ButtonState.Inactive)!=0) {
4178 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4180 /* Move away from the shadow */
4190 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4192 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4197 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
4199 Pen pen = new Pen(Color.Black, 1);
4200 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
4204 graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
4205 graphics.DrawRectangle(pen, rect);
4207 X=rect.X+rect.Width/2;
4208 Y=rect.Y+rect.Height/2;
4210 /* Draw the cross */
4211 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
4212 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
4214 /* Draw 'arrows' for vertical lines */
4215 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
4216 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
4218 /* Draw 'arrows' for horizontal lines */
4219 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
4220 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
4224 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4225 // make a rectange to trace around border of the button
4226 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4228 Color outerColor = foreColor;
4229 // adjust focus color according to the flatstyle
4230 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4231 outerColor = (backColor == ColorButtonFace) ? ControlPaint.Dark(ColorButtonFace) : ColorButtonText;
4234 // draw the outer rectangle
4235 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4237 // draw the inner rectangle
4238 if (button.FlatStyle == FlatStyle.Popup) {
4239 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4241 // draw a flat inner rectangle
4242 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4243 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4247 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4249 // make a rectange to trace around border of the button
4250 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4252 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4253 DashStyle oldStyle; // used for caching old penstyle
4254 Pen pen = ResPool.GetPen (colorBackInverted);
4256 oldStyle = pen.DashStyle;
4257 pen.DashStyle = DashStyle.Dot;
4258 graphics.DrawRectangle (pen, trace_rectangle);
4259 pen.DashStyle = oldStyle;
4263 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4265 Rectangle rect = rectangle;
4269 if (backColor.GetBrightness () >= 0.5) {
4270 foreColor = Color.Transparent;
4271 backColor = Color.Black;
4274 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4275 foreColor = Color.Black;
4278 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4279 pen = new Pen (brush, 1);
4284 graphics.DrawRectangle (pen, rect);
4288 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
4292 if (primary==true) {
4293 pen=new Pen(Color.Black, 1);
4294 if (enabled==true) {
4295 sb=ResPool.GetSolidBrush (ColorButtonText);
4297 sb=ResPool.GetSolidBrush (ColorButtonFace);
4300 pen=new Pen(Color.White, 1);
4301 if (enabled==true) {
4302 sb=new SolidBrush(Color.Black);
4304 sb=ResPool.GetSolidBrush (ColorButtonFace);
4307 graphics.FillRectangle(sb, rectangle);
4308 graphics.DrawRectangle(pen, rectangle);
4313 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4319 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4322 foreColor=Color.Black;
4324 foreColor=Color.White;
4328 /* Commented out until I take the time and figure out
4329 which HatchStyle will match requirements. The code below
4330 is only correct for Percent50.
4332 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
4333 HatchBrush brush=null;
4335 switch(pixelsBetweenDots.Width) {
4336 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
4337 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
4338 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
4340 /* Have to do it the slow way */
4345 graphics.FillRectangle(brush, area);
4354 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4356 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4357 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4358 bitmap.SetPixel(x, y, foreColor);
4361 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4365 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4367 Microsoft seems to ignore the background and simply make
4368 the image grayscale. At least when having > 256 colors on
4372 if (imagedisabled_attributes == null) {
4373 imagedisabled_attributes = new ImageAttributes ();
4374 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4375 // This table would create a perfect grayscale image, based on luminance
4376 // new float[]{0.3f,0.3f,0.3f,0,0},
4377 // new float[]{0.59f,0.59f,0.59f,0,0},
4378 // new float[]{0.11f,0.11f,0.11f,0,0},
4379 // new float[]{0,0,0,1,0,0},
4380 // new float[]{0,0,0,0,1,0},
4381 // new float[]{0,0,0,0,0,1}
4383 // This table generates a image that is grayscaled and then
4384 // brightened up. Seems to match MS close enough.
4385 new float[]{0.2f,0.2f,0.2f,0,0},
4386 new float[]{0.41f,0.41f,0.41f,0,0},
4387 new float[]{0.11f,0.11f,0.11f,0,0},
4388 new float[]{0.15f,0.15f,0.15f,1,0,0},
4389 new float[]{0.15f,0.15f,0.15f,0,1,0},
4390 new float[]{0.15f,0.15f,0.15f,0,0,1}
4393 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4396 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4401 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4406 penBorder=new Pen(Color.White, 2);
4407 penInside=new Pen(Color.Black, 1);
4409 penBorder=new Pen(Color.Black, 2);
4410 penInside=new Pen(Color.White, 1);
4412 penBorder.Alignment=PenAlignment.Inset;
4413 penInside.Alignment=PenAlignment.Inset;
4415 graphics.DrawRectangle(penBorder, rectangle);
4416 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4417 penBorder.Dispose();
4418 penInside.Dispose();
4422 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
4426 // MS draws always the background white
4427 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
4430 case MenuGlyph.Arrow: {
4431 Point[] arrow = new Point[3];
4439 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4440 centerX=rect.Left+rect.Width/2;
4441 centerY=rect.Top+rect.Height/2;
4442 shiftX=Math.Max(1, rect.Width/8);
4447 P1=new Point(centerX, rect.Top-1);
4448 P2=new Point(centerX, rect.Bottom);
4449 P3=new Point(rect.Right, centerY);
4455 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4460 case MenuGlyph.Bullet: {
4462 lineWidth=Math.Max(2, rectangle.Width/3);
4463 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4465 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
4470 case MenuGlyph.Checkmark: {
4473 lineWidth=Math.Max(2, rectangle.Width/6);
4474 Scale=Math.Max(1, rectangle.Width/12);
4476 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4478 for (int i=0; i<lineWidth; i++) {
4479 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4480 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);
4488 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4489 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
4491 if ((state & ButtonState.Pushed)!=0) {
4492 dfcs |= DrawFrameControlStates.Pushed;
4495 if ((state & ButtonState.Checked)!=0) {
4496 dfcs |= DrawFrameControlStates.Checked;
4499 if ((state & ButtonState.Flat)!=0) {
4500 dfcs |= DrawFrameControlStates.Flat;
4503 if ((state & ButtonState.Inactive)!=0) {
4504 dfcs |= DrawFrameControlStates.Inactive;
4506 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4511 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4516 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4521 /* Scroll button: regular button + direction arrow */
4522 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4523 bool enabled = (state == ButtonState.Inactive) ? false: true;
4525 DrawScrollButtonPrimitive (dc, area, state);
4527 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
4532 case ScrollButton.Up: {
4533 int x = area.X + (area.Width / 2) - 4;
4536 for (int i = 0; i < 3; i++)
4538 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y - i, x + i + 6 - 2*i, y - i);
4540 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
4543 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4544 x + 3, area.Y + 6, 1, 1);
4548 case ScrollButton.Down: {
4549 int x = area.X + (area.Width / 2) - 5;
4552 for (int i = 4; i != 0; i--)
4554 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i + 8 - 2*i, y + i);
4556 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
4559 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4560 x + 4, y + 4, 1, 1);
4564 case ScrollButton.Left: {
4565 int y = area.Y + (area.Height / 2) - 4;
4568 for (int i = 0; i < 3; i++)
4570 dc.DrawLine (ResPool.GetPen (arrow_color), x - i, y + i, x - i, y + i + 6 - 2*i);
4572 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
4574 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4575 x - 3, y + 3, 1, 1);
4579 case ScrollButton.Right: {
4580 int y = area.Y + (area.Height / 2) - 5;
4583 for (int i = 4; i != 0; i--)
4585 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i, y + i + 8 - 2*i);
4587 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
4589 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4590 x + 4, y + 4, 1, 1);
4601 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
4607 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
4608 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
4610 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
4611 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
4614 for (int i = 0; i < 11; i += 4) {
4615 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
4616 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
4619 for (int i = 3; i < 13; i += 4)
4620 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
4624 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
4625 StringFormat format) {
4627 layoutRectangle.Offset(1.0f, 1.0f);
4628 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 95)), layoutRectangle, format);
4629 layoutRectangle.Offset(-1.0f, -1.0f);
4630 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 50)), layoutRectangle, format);
4634 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
4635 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
4637 Pen pen=new Pen(color, 1);
4640 case ButtonBorderStyle.Solid: {
4641 pen.DashStyle=DashStyle.Solid;
4645 case ButtonBorderStyle.Dashed: {
4646 pen.DashStyle=DashStyle.Dash;
4650 case ButtonBorderStyle.Dotted: {
4651 pen.DashStyle=DashStyle.Dot;
4655 case ButtonBorderStyle.Inset: {
4656 pen.DashStyle=DashStyle.Solid;
4660 case ButtonBorderStyle.Outset: {
4661 pen.DashStyle=DashStyle.Solid;
4666 case ButtonBorderStyle.None: {
4674 case ButtonBorderStyle.Outset: {
4676 int hue, brightness, saturation;
4677 int brightnessSteps;
4678 int brightnessDownSteps;
4680 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4682 brightnessDownSteps=brightness/width;
4683 if (brightness>127) {
4684 brightnessSteps=Math.Max(6, (160-brightness)/width);
4686 brightnessSteps=(127-brightness)/width;
4689 for (int i=0; i<width; i++) {
4691 case Border3DSide.Left: {
4693 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4694 pen=new Pen(colorGrade, 1);
4695 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4699 case Border3DSide.Right: {
4701 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4702 pen=new Pen(colorGrade, 1);
4703 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4707 case Border3DSide.Top: {
4709 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4710 pen=new Pen(colorGrade, 1);
4711 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4715 case Border3DSide.Bottom: {
4717 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4718 pen=new Pen(colorGrade, 1);
4719 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4727 case ButtonBorderStyle.Inset: {
4729 int hue, brightness, saturation;
4730 int brightnessSteps;
4731 int brightnessDownSteps;
4733 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4735 brightnessDownSteps=brightness/width;
4736 if (brightness>127) {
4737 brightnessSteps=Math.Max(6, (160-brightness)/width);
4739 brightnessSteps=(127-brightness)/width;
4742 for (int i=0; i<width; i++) {
4744 case Border3DSide.Left: {
4746 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4747 pen=new Pen(colorGrade, 1);
4748 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4752 case Border3DSide.Right: {
4754 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4755 pen=new Pen(colorGrade, 1);
4756 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4760 case Border3DSide.Top: {
4762 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4763 pen=new Pen(colorGrade, 1);
4764 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4768 case Border3DSide.Bottom: {
4770 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4771 pen=new Pen(colorGrade, 1);
4772 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4781 I decided to have the for-loop duplicated for speed reasons;
4782 that way we only have to switch once (as opposed to have the
4783 for-loop around the switch)
4787 case Border3DSide.Left: {
4788 for (int i=0; i<width; i++) {
4789 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4794 case Border3DSide.Right: {
4795 for (int i=0; i<width; i++) {
4796 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4801 case Border3DSide.Top: {
4802 for (int i=0; i<width; i++) {
4803 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4808 case Border3DSide.Bottom: {
4809 for (int i=0; i<width; i++) {
4810 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4822 This function actually draws the various caption elements.
4823 This way we can scale them nicely, no matter what size, and they
4824 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
4827 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
4829 case CaptionButton.Close: {
4830 pen.StartCap=LineCap.Triangle;
4831 pen.EndCap=LineCap.Triangle;
4833 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);
4834 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);
4837 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4838 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4842 case CaptionButton.Help: {
4843 StringFormat sf = new StringFormat();
4844 SolidBrush sb = new SolidBrush(color);
4845 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
4847 sf.Alignment=StringAlignment.Center;
4848 sf.LineAlignment=StringAlignment.Center;
4851 graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
4860 case CaptionButton.Maximize: {
4861 /* Top 'caption bar' line */
4862 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4863 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);
4866 /* Left side line */
4867 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4868 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4871 /* Right side line */
4872 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4873 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);
4877 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4878 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4883 case CaptionButton.Minimize: {
4885 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4886 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
4891 case CaptionButton.Restore: {
4892 /** First 'window' **/
4893 /* Top 'caption bar' line */
4894 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4895 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);
4898 /* Left side line */
4899 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4900 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);
4903 /* Right side line */
4904 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4905 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);
4909 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4910 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);
4913 /** Second 'window' **/
4914 /* Top 'caption bar' line */
4915 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4916 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);
4919 /* Left side line */
4920 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4921 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4924 /* Right side line */
4925 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4926 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);
4930 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4931 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4940 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
4941 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
4942 // make a rectange to trace around border of the button
4943 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4945 case DrawFrameControlTypes.Button: {
4947 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
4948 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
4949 // /* Goes first, affects the background */
4950 // if ((State & DrawFrameControlStates.Checked)!=0) {
4951 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
4952 // graphics.FillRectangle(hatchBrush,rectangle);
4953 // hatchBrush.Dispose();
4956 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
4957 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4958 } else if ((State & DrawFrameControlStates.Flat)!=0) {
4959 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4960 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
4961 /* Same as normal, it would seem */
4962 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4964 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4966 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
4967 Pen penFatDark = new Pen(ColorButtonShadow, 1);
4968 Pen penFatLight = new Pen(ColorButtonLight, 1);
4971 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4973 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
4974 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
4976 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
4977 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
4979 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
4981 if ((State & DrawFrameControlStates.Checked)!=0) {
4982 SolidBrush buttonBrush;
4984 if ((State & DrawFrameControlStates.Inactive)!=0) {
4985 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
4987 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
4989 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
4991 penFatDark.Dispose();
4992 penFatLight.Dispose();
4993 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
4994 throw new NotImplementedException () ;
4995 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
4996 throw new NotImplementedException ();
4997 } else { /* Must be Checkbox */
5003 /* Goes first, affects the background */
5004 if ((State & DrawFrameControlStates.Pushed)!=0 ||
5005 (State & DrawFrameControlStates.Inactive)!=0) {
5006 graphics.FillRectangle(SystemBrushes.Control, rectangle);
5008 graphics.FillRectangle(SystemBrushes.Window, rectangle);
5011 /* Draw the sunken frame */
5012 if ((State & DrawFrameControlStates.Flat)!=0) {
5013 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
5015 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
5018 /* Make sure we've got at least a line width of 1 */
5019 lineWidth=Math.Max(3, rectangle.Width/6);
5020 Scale=Math.Max(1, rectangle.Width/12);
5022 // define a rectangle inside the border area
5023 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
5024 if ((State & DrawFrameControlStates.Inactive)!=0) {
5025 pen=SystemPens.ControlDark;
5027 pen=SystemPens.ControlText;
5030 if ((State & DrawFrameControlStates.Checked)!=0) {
5031 /* Need to draw a check-mark */
5032 for (int i=0; i<lineWidth; i++) {
5033 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5034 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);
5042 case DrawFrameControlTypes.Caption: {
5047 case DrawFrameControlTypes.Menu: {
5052 case DrawFrameControlTypes.Scroll: {
5059 /* Generic scroll button */
5060 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5061 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5062 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
5063 area.Y + 1, area.Width - 2 , area.Height - 2);
5065 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
5066 area.Y, area.Width, area.Height);
5071 dc.FillRectangle (new SolidBrush (Color.Blue), area);
5073 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
5074 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
5076 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
5077 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
5080 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
5083 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
5086 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
5087 area.Y + 1, 1, area.Height -3);
5089 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
5090 area.Y, 1, area.Height - 1);
5092 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
5093 area.Y + 2, area.Width - 4, area.Height - 4);
5097 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5098 switch (border_style){
5099 case BorderStyle.Fixed3D:
5100 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
5101 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
5102 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5103 area.Y + area.Height - 1);
5104 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5105 area.Y + area.Height);
5107 // FIXME: These colors are not correct. Microsoft uses different ones but I didn't find them.
5108 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5109 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5110 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5111 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5113 case BorderStyle.FixedSingle:
5114 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5116 case BorderStyle.None:
5122 #endregion // ControlPaint