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),
1099 col.Rect, col.Format);
1102 // Non-clickable columns
1104 foreach (ColumnHeader col in control.Columns) {
1105 this.CPDrawButton (dc, col.Rect, ButtonState.Flat);
1106 dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
1107 ResPool.GetSolidBrush
1108 (this.ColorButtonText),
1109 col.Rect, col.Format);
1115 // In case of details view draw the items only if
1116 // columns are non-zero
1117 if (!details || control.Columns.Count > 0)
1118 foreach (ListViewItem item in control.Items)
1119 this.DrawListViewItem (dc, control, item);
1121 // draw the gridlines
1122 if (details && control.GridLines) {
1123 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1124 2 : control.Font.Height + 2;
1126 // draw vertical gridlines
1127 foreach (ColumnHeader col in control.Columns)
1128 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1129 col.Rect.Right, top,
1130 col.Rect.Right, control.TotalHeight);
1131 // draw horizontal gridlines
1132 ListViewItem last_item = null;
1133 foreach (ListViewItem item in control.Items) {
1134 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1135 item.EntireRect.Left, item.EntireRect.Top,
1136 control.TotalWidth, item.EntireRect.Top);
1140 // draw a line after at the bottom of the last item
1141 if (last_item != null) {
1142 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1143 last_item.EntireRect.Left,
1144 last_item.EntireRect.Bottom,
1146 last_item.EntireRect.Bottom);
1151 // draws the ListViewItem of the given index
1152 private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1154 if (control.CheckBoxes) {
1155 if (control.StateImageList == null) {
1156 // Make sure we've got at least a line width of 1
1157 int check_wd = Math.Max (3, item.CheckRect.Width / 6);
1158 int scale = Math.Max (1, item.CheckRect.Width / 12);
1160 // set the checkbox background
1161 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
1163 // define a rectangle inside the border area
1164 Rectangle rect = new Rectangle (item.CheckRect.X + 2,
1165 item.CheckRect.Y + 2,
1166 item.CheckRect.Width - 4,
1167 item.CheckRect.Height - 4);
1168 Pen pen = new Pen (this.ColorWindowText, 2);
1169 dc.DrawRectangle (pen, rect);
1171 // Need to draw a check-mark
1174 // adjustments to get the check-mark at the right place
1175 rect.X ++; rect.Y ++;
1176 // following logic is taken from DrawFrameControl method
1177 for (int i = 0; i < check_wd; i++) {
1178 dc.DrawLine (pen, rect.Left + check_wd / 2,
1179 rect.Top + check_wd + i,
1180 rect.Left + check_wd / 2 + 2 * scale,
1181 rect.Top + check_wd + 2 * scale + i);
1183 rect.Left + check_wd / 2 + 2 * scale,
1184 rect.Top + check_wd + 2 * scale + i,
1185 rect.Left + check_wd / 2 + 6 * scale,
1186 rect.Top + check_wd - 2 * scale + i);
1191 if (item.Checked && control.StateImageList.Images.Count > 1)
1192 control.StateImageList.Draw (dc,
1193 item.CheckRect.Location, 1);
1194 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1195 control.StateImageList.Draw (dc,
1196 item.CheckRect.Location, 0);
1200 // Item is drawn as a special case, as it is not just text
1201 if (control.View == View.LargeIcon) {
1202 if (item.ImageIndex > -1 &&
1203 control.LargeImageList != null &&
1204 item.ImageIndex < control.LargeImageList.Images.Count)
1205 control.LargeImageList.Draw (dc, item.IconRect.Location,
1209 if (item.ImageIndex > -1 &&
1210 control.SmallImageList != null &&
1211 item.ImageIndex < control.SmallImageList.Images.Count)
1212 control.SmallImageList.Draw (dc, item.IconRect.Location,
1216 // draw the item text
1217 Rectangle text_rect = item.LabelRect;
1218 // format for the item text
1219 StringFormat format = new StringFormat ();
1220 format.LineAlignment = StringAlignment.Center;
1221 if (control.View == View.LargeIcon)
1222 format.Alignment = StringAlignment.Center;
1224 format.Alignment = StringAlignment.Near;
1226 if (!control.LabelWrap)
1227 format.FormatFlags = StringFormatFlags.NoWrap;
1229 if (item.Selected) {
1230 if (control.View == View.Details) {
1231 if (control.FullRowSelect) {
1232 // fill the entire rect excluding the checkbox
1233 Rectangle full_rect = item.EntireRect;
1234 full_rect.Location = item.LabelRect.Location;
1235 dc.FillRectangle (this.ResPool.GetSolidBrush
1236 (this.ColorHilight), full_rect);
1239 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1241 text_rect.Width = text_size.Width;
1242 dc.FillRectangle (this.ResPool.GetSolidBrush
1243 (this.ColorHilight), text_rect);
1247 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1249 Point loc = text_rect.Location;
1250 loc.X += (text_rect.Width - text_size.Width) / 2;
1251 text_rect.Width = text_size.Width;*/
1252 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHilight),
1257 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1259 if (item.Text != null && item.Text.Length > 0) {
1261 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1262 (this.ColorHilightText), text_rect, format);
1264 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1265 (item.ForeColor), text_rect, format);
1268 if (control.View == View.Details && control.Columns.Count > 0) {
1269 // draw subitems for details view
1270 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1271 int count = (control.Columns.Count < subItems.Count ?
1272 control.Columns.Count : subItems.Count);
1276 ListViewItem.ListViewSubItem subItem;
1277 Rectangle sub_item_rect = item.LabelRect;
1279 // set the format for subitems
1280 format.FormatFlags = StringFormatFlags.NoWrap;
1281 format.Alignment = StringAlignment.Near;
1283 // 0th subitem is the item already drawn
1284 for (int index = 1; index < count; index++) {
1285 subItem = subItems [index];
1286 col = control.Columns [index];
1287 sub_item_rect.X = col.Rect.Left;
1288 sub_item_rect.Width = col.Wd;
1290 SolidBrush sub_item_back_br = null;
1291 SolidBrush sub_item_fore_br = null;
1292 Font sub_item_font = null;
1294 if (item.UseItemStyleForSubItems) {
1295 sub_item_back_br = this.ResPool.GetSolidBrush
1297 sub_item_fore_br = this.ResPool.GetSolidBrush
1299 sub_item_font = item.Font;
1302 sub_item_back_br = this.ResPool.GetSolidBrush
1303 (subItem.BackColor);
1304 sub_item_fore_br = this.ResPool.GetSolidBrush
1305 (subItem.ForeColor);
1306 sub_item_font = subItem.Font;
1309 // In case of fullrowselect, background is filled
1310 // for the entire rect above
1311 if (item.Selected && control.FullRowSelect) {
1312 if (subItem.Text != null && subItem.Text.Length > 0)
1313 dc.DrawString (subItem.Text, sub_item_font,
1314 this.ResPool.GetSolidBrush
1315 (this.ColorHilightText),
1316 sub_item_rect, format);
1319 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1320 if (subItem.Text != null && subItem.Text.Length > 0)
1321 dc.DrawString (subItem.Text, sub_item_font,
1323 sub_item_rect, format);
1325 sub_item_rect.X += col.Wd;
1332 public override Size ListViewCheckBoxSize {
1333 get { return new Size (16, 16); }
1336 public override int ListViewColumnHeaderHeight {
1340 public override int ListViewDefaultColumnWidth {
1344 public override int ListViewVerticalSpacing {
1348 public override int ListViewEmptyColumnWidth {
1352 public override int ListViewHorizontalSpacing {
1356 public override Size ListViewDefaultSize {
1357 get { return new Size (121, 97); }
1359 #endregion // ListView
1362 public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
1367 if (item.item.Visible == false)
1370 if (item.item.Separator == true) {
1371 item.rect.Height = SEPARATOR_HEIGHT / 2;
1372 item.rect.Width = -1;
1376 if (item.item.MeasureEventDefined) {
1377 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.pos);
1378 item.item.PerformMeasureItem (mi);
1379 item.rect.Height = mi.ItemHeight;
1380 item.rect.Width = mi.ItemWidth;
1385 size = dc.MeasureString (item.item.Text, ThemeEngine.Current.MenuFont);
1386 item.rect.Width = (int) size.Width;
1387 item.rect.Height = (int) size.Height;
1391 if (item.item.Shortcut != Shortcut.None && item.item.ShowShortcut) {
1392 item.item.XTab = ThemeEngine.Current.MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1393 size = dc.MeasureString (" " + item.item.GetShortCutText (), ThemeEngine.Current.MenuFont);
1394 item.rect.Width += MENU_TAB_SPACE + (int) size.Width;
1397 item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
1400 item.rect.Width += MENU_BAR_ITEMS_SPACE;
1401 x += item.rect.Width;
1404 if (item.rect.Height < ThemeEngine.Current.MenuHeight)
1405 item.rect.Height = ThemeEngine.Current.MenuHeight;
1409 // Updates the menu rect and returns the height
1410 public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width)
1415 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1417 MenuAPI.MENUITEM item;
1419 while (i < menu.items.Count) {
1421 item = (MenuAPI.MENUITEM) menu.items[i];
1422 CalcItemSize (dc, item, y, x, true);
1425 if (x + item.rect.Width > width) {
1427 y += item.rect.Height;
1432 x += item.rect.Width;
1433 item.item.MenuBar = true;
1435 if (y + item.rect.Height > menu.Height)
1436 menu.Height = item.rect.Height + y;
1444 public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
1450 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1453 while (start < menu.items.Count) {
1456 for (i = start; i < menu.items.Count; i++) {
1457 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
1459 if ((i != start) && (item.item.Break || item.item.BarBreak))
1462 CalcItemSize (dc, item, y, x, false);
1463 y += item.rect.Height;
1465 if (item.rect.Width > max)
1466 max = item.rect.Width;
1469 // Reemplace the -1 by the menu width (separators)
1470 for (n = start; n < i; n++, start++) {
1471 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[n];
1472 item.rect.Width = max;
1475 if (y > menu.Height)
1487 menu.Width += SM_CXBORDER;
1488 menu.Height += SM_CYBORDER;
1491 // Draws a menu bar in a window
1492 public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
1494 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1495 Rectangle item_rect;
1497 if (menu.Height == 0)
1498 ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
1500 rect.Height = menu.Height;
1501 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (menu.Wnd.BackColor), rect);
1503 for (int i = 0; i < menu.items.Count; i++) {
1504 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1505 item_rect = it.rect;
1506 item_rect.X += rect.X;
1507 item_rect.Y += rect.Y;
1508 it.item.MenuHeight = menu.Height;
1509 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1510 item_rect, i, it.item.Status));
1515 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1517 StringFormat string_format;
1518 Rectangle rect_text = e.Bounds;
1520 if (item.Visible == false)
1524 string_format = string_format_menu_menubar_text;
1527 string_format = string_format_menu_text;
1530 if (item.Separator == true) {
1531 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1532 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1534 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1535 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1541 rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
1543 if (item.BarBreak) { /* Draw vertical break bar*/
1544 Rectangle rect = e.Bounds;
1547 rect.Height = item.MenuHeight - 6;
1549 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1550 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1552 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1553 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1559 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1560 color_text = ThemeEngine.Current.ColorHilightText;
1561 color_back = ThemeEngine.Current.ColorHilight;
1564 color_text = ThemeEngine.Current.ColorMenuText;
1565 color_back = ThemeEngine.Current.ColorMenu;
1568 /* Draw background */
1569 Rectangle rect_back = e.Bounds;
1571 rect_back.Width -=2;
1572 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color_back), rect_back);
1575 e.Graphics.DrawString (item.Text, e.Font,
1576 ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1577 rect_text, string_format);
1579 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1580 string str = item.GetShortCutText ();
1581 Rectangle rect = rect_text;
1583 rect.Width -= item.XTab;
1585 e.Graphics.DrawString (str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1586 rect, string_format_menu_shortcut);
1590 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
1591 Color.Black, rect_text, string_format);
1595 if (item.MenuBar == false && item.IsPopup) {
1597 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1598 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1599 Bitmap bmp = new Bitmap (cx, cy);
1600 Graphics gr = Graphics.FromImage (bmp);
1601 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1602 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
1603 bmp.MakeTransparent ();
1606 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1607 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1609 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1610 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1617 /* Draw checked or radio */
1618 if (item.MenuBar == false && item.Checked) {
1620 Rectangle area = e.Bounds;
1621 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1622 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1623 Bitmap bmp = new Bitmap (cx, cy);
1624 Graphics gr = Graphics.FromImage (bmp);
1625 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1627 if (item.RadioCheck)
1628 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
1630 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
1632 bmp.MakeTransparent ();
1633 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1640 public override void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect)
1642 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1644 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1645 (ThemeEngine.Current.ColorMenu), cliparea);
1647 /* Draw menu borders */
1648 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1649 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1651 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1652 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1654 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1655 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1657 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1658 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1660 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1661 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1663 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1664 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1666 for (int i = 0; i < menu.items.Count; i++)
1667 if (cliparea.IntersectsWith (((MenuAPI.MENUITEM) menu.items[i]).rect)) {
1668 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1669 it.item.MenuHeight = menu.Height;
1670 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1671 it.rect, i, it.item.Status));
1677 #region MonthCalendar
1679 // draw the month calendar
1680 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
\r
1682 Rectangle client_rectangle = mc.ClientRectangle;
1683 Size month_size = mc.SingleMonthSize;
1684 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1685 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
1686 Size date_cell_size = (Size)((object)mc.date_cell_size);
1688 // draw the singlecalendars
1691 // adjust for the position of the specific month
1692 for (int i=0; i < mc.CalendarDimensions.Height; i++)
\r
1696 y_offset += month_size.Height + calendar_spacing.Height;
1698 // now adjust for x position
1699 for (int j=0; j < mc.CalendarDimensions.Width; j++)
\r
1703 x_offset += month_size.Width + calendar_spacing.Width;
1710 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
1711 if (month_rect.IntersectsWith (clip_rectangle)) {
1723 Rectangle bottom_rect = new Rectangle (
1725 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
1726 client_rectangle.Width,
1727 date_cell_size.Height + 2);
1728 // draw the today date if it's set
1729 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
\r
1731 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
1733 int today_offset = 5;
1734 if (mc.ShowTodayCircle)
\r
1736 Rectangle today_circle_rect = new Rectangle (
1737 client_rectangle.X + 5,
1738 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
1739 date_cell_size.Width,
1740 date_cell_size.Height);
1741 DrawTodayCircle (dc, today_circle_rect);
1742 today_offset += date_cell_size.Width + 5;
1744 // draw today's date
1745 StringFormat text_format = new StringFormat();
1746 text_format.LineAlignment = StringAlignment.Center;
1747 text_format.Alignment = StringAlignment.Near;
1748 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
1749 Rectangle today_rect = new Rectangle (
1750 today_offset + client_rectangle.X,
1751 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
1752 Math.Max(client_rectangle.Width - today_offset, 0),
1753 date_cell_size.Height);
1754 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
1758 // finally paint the borders of the calendars as required
1759 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
1760 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
1761 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
1762 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
1763 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
1765 Rectangle rect = new Rectangle (
1766 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
1768 calendar_spacing.Width,
1769 client_rectangle.Height);
1770 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1771 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1775 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
1776 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
1777 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
1778 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
1779 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
1781 Rectangle rect = new Rectangle (
1783 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
1784 client_rectangle.Width,
1785 calendar_spacing.Height);
1786 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1787 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1792 // draw the drop down border if need
1793 if (mc.owner != null) {
1794 Rectangle bounds = mc.ClientRectangle;
1795 if (clip_rectangle.Contains (mc.Location)) {
1796 // find out if top or left line to draw
1797 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1799 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
1801 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1802 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
1805 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
1806 // find out if bottom or right line to draw
1807 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1808 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
1810 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1811 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
1817 // darws a single part of the month calendar (with one month)
1818 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
\r
1820 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1821 Size title_size = (Size)((object)mc.title_size);
1822 Size date_cell_size = (Size)((object)mc.date_cell_size);
1823 DateTime current_month = (DateTime)((object)mc.current_month);
1825 // set up some standard string formating variables
1826 StringFormat text_format = new StringFormat();
1827 text_format.LineAlignment = StringAlignment.Center;
1828 text_format.Alignment = StringAlignment.Center;
1831 // draw the title back ground
1832 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
1833 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
1834 if (title_rect.IntersectsWith (clip_rectangle)) {
1835 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
1837 string title_text = this_month.ToString ("MMMM yyyy");
1838 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
1840 // draw previous and next buttons if it's time
1841 if (row == 0 && col == 0)
\r
1843 // draw previous button
1844 DrawMonthCalendarButton (
1850 (System.Drawing.Size)((object)mc.button_size),
1853 if (row == 0 && col == mc.CalendarDimensions.Width-1)
\r
1856 DrawMonthCalendarButton (
1862 (System.Drawing.Size)((object)mc.button_size),
1867 // set the week offset and draw week nums if needed
1868 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
1869 Rectangle day_name_rect = new Rectangle(
1871 rectangle.Y + title_size.Height,
1872 (7 + col_offset) * date_cell_size.Width,
1873 date_cell_size.Height);
1874 if (day_name_rect.IntersectsWith (clip_rectangle)) {
1875 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
1876 // draw the day names
1877 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
1878 for (int i=0; i < 7; i++)
\r
1880 int position = i - (int) first_day_of_week;
1881 if (position < 0)
\r
1883 position = 7 + position;
1886 Rectangle day_rect = new Rectangle(
1887 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
1889 date_cell_size.Width,
1890 date_cell_size.Height);
1891 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
1894 // draw the vertical divider
1895 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
1897 ResPool.GetPen (mc.ForeColor),
1898 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
1899 rectangle.Y + vert_divider_y,
1900 rectangle.Right - mc.divider_line_offset,
1901 rectangle.Y + vert_divider_y);
1905 // draw the actual date items in the grid (including the week numbers)
1906 Rectangle date_rect = new Rectangle (
1908 rectangle.Y + title_size.Height + date_cell_size.Height,
1909 date_cell_size.Width,
1910 date_cell_size.Height);
1911 int month_row_count = 0;
1912 bool draw_week_num_divider = false;
1913 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
1914 for (int i=0; i < 6; i++)
\r
1916 // establish if this row is in our clip_area
1917 Rectangle row_rect = new Rectangle (
1919 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
1920 date_cell_size.Width * 7,
1921 date_cell_size.Height);
1922 if (mc.ShowWeekNumbers) {
1923 row_rect.Width += date_cell_size.Width;
1926 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
1928 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
1930 // establish if this is a valid week to draw
1931 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
1932 month_row_count = i;
1935 // draw the week number if required
1936 if (mc.ShowWeekNumbers && month_row_count == i) {
1937 if (!draw_week_num_divider) {
1938 draw_week_num_divider = draw_row;
1940 // get the week for this row
1941 int week = mc.GetWeekOfYear (current_date);
1947 ResPool.GetSolidBrush (mc.TitleBackColor),
1951 date_rect.Offset(date_cell_size.Width, 0);
1954 // only draw the days if we have to
1955 if(month_row_count == i) {
1956 for (int j=0; j < 7; j++)
\r
1959 DrawMonthCalendarDate (
1970 current_date = current_date.AddDays(1);
1971 date_rect.Offset(date_cell_size.Width, 0);
1974 // shift the rectangle down one row
1975 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
1976 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
1980 // month_row_count is zero based, so add one
1983 // draw week numbers if required
1984 if (draw_week_num_divider) {
1987 ResPool.GetPen (mc.ForeColor),
1988 rectangle.X + date_cell_size.Width - 1,
1989 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
1990 rectangle.X + date_cell_size.Width - 1,
1991 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
1995 // draws the pervious or next button
1996 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
\r
1998 bool is_clicked = false;
1999 Rectangle button_rect;
2000 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2001 Point[] arrow_path = new Point[3];
2002 // prepare the button
2005 is_clicked = mc.is_previous_clicked;
2006 button_rect = new Rectangle (
2007 rectangle.X + 1 + x_offset,
2008 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2009 Math.Max(button_size.Width - 1, 0),
2010 Math.Max(button_size.Height - 1, 0));
2011 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2012 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2014 arrow_rect.Offset(1,1);
2016 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2017 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2018 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2022 is_clicked = mc.is_next_clicked;
2023 button_rect = new Rectangle (
2024 rectangle.Right - 1 - x_offset - button_size.Width,
2025 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2026 Math.Max(button_size.Width - 1, 0),
2027 Math.Max(button_size.Height - 1, 0));
2028 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2029 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2031 arrow_rect.Offset(1,1);
2033 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2034 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2035 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2038 // fill the background
2039 dc.FillRectangle (SystemBrushes.Control, button_rect);
2042 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2045 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
2048 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2052 // draws one day in the calendar grid
2053 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2054 Color date_color = mc.ForeColor;
2055 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2057 // find out if we are the lead of the first calendar or the trail of the last calendar
2058 if (date.Year != month.Year || date.Month != month.Month) {
2059 DateTime check_date = month.AddMonths (-1);
2060 // check if it's the month before
2061 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2062 date_color = mc.TrailingForeColor;
2064 // check if it's the month after
2065 check_date = month.AddMonths (1);
2066 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2067 date_color = mc.TrailingForeColor;
2073 date_color = mc.ForeColor;
2077 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2078 // see if the date is in the start of selection
2079 date_color = mc.BackColor;
2080 // draw the left hand of the back ground
2081 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2082 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2083 } else if (date == mc.SelectionStart) {
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, 90, 180);
2089 // fill the other side as a straight rect
2090 if (date < mc.SelectionEnd)
\r
2092 // use rectangle instead of rectangle to go all the way to edge of rect
2093 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2094 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2095 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2097 } else if (date == mc.SelectionEnd) {
2098 // see if it is the end of selection
2099 date_color = mc.BackColor;
2100 // draw the left hand of the back ground
2101 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2102 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2103 // fill the other side as a straight rect
2104 if (date > mc.SelectionStart) {
2105 selection_rect.X = rectangle.X;
2106 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2107 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2109 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2110 // now see if it's in the middle
2111 date_color = mc.BackColor;
2112 // draw the left hand of the back ground
2113 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2114 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2117 // set up some standard string formating variables
2118 StringFormat text_format = new StringFormat();
2119 text_format.LineAlignment = StringAlignment.Center;
2120 text_format.Alignment = StringAlignment.Center;
2123 // establish if it's a bolded font
2125 if (mc.IsBoldedDate (date)) {
2126 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2131 // just draw the date now
2132 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2134 // today circle if needed
2135 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2136 DrawTodayCircle (dc, interior);
2139 // draw the selection grid
2140 if (mc.is_date_clicked && mc.clicked_date == date) {
2141 using (Pen pen = new Pen (Color.Black, 1) ) {
2142 pen.DashStyle = DashStyle.Dot;
2143 dc.DrawRectangle (pen, interior);
2148 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2149 Color circle_color = Color.FromArgb (248, 0, 0);
2150 // draw the left hand of the circle
2151 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2152 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2153 Point [] curve_points = new Point [3];
2154 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2155 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2156 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2158 using (Pen pen = new Pen (circle_color, 2)) {
2159 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2160 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2161 dc.DrawCurve (pen, curve_points);
2162 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2166 #endregion // MonthCalendar
2169 public override Size PanelDefaultSize {
2171 return new Size (200, 100);
2177 public override void DrawPictureBox (Graphics dc, PictureBox pb) {
2178 Rectangle client = pb.ClientRectangle;
2180 dc.FillRectangle (new SolidBrush (pb.BackColor), client);
2182 if (pb.Image != null) {
2183 switch (pb.SizeMode) {
2184 case PictureBoxSizeMode.StretchImage:
2185 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2188 case PictureBoxSizeMode.CenterImage:
2189 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2193 dc.DrawImage(pb.Image, 0, 0);
2197 CPDrawBorderStyle (dc, client, pb.BorderStyle);
2200 public override Size PictureBoxDefaultSize {
2202 return new Size (100, 50);
2205 #endregion // PictureBox
2208 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2210 Rectangle block_rect;
2211 Rectangle client_area = ctrl.client_area;
2212 int space_betweenblocks = 2;
2217 block_width = ((client_area.Height) * 2 ) / 3;
2218 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2219 increment = block_width + space_betweenblocks;
2222 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
2225 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2226 while ((block_rect.X - client_area.X) < barpos_pixels) {
2228 if (clip_rect.IntersectsWith (block_rect) == true) {
2229 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2232 block_rect.X += increment;
2236 public override Size ProgressBarDefaultSize {
2238 return new Size (100, 23);
2242 #endregion // ProgressBar
2245 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2246 StringFormat text_format;
2247 Rectangle client_rectangle;
2248 Rectangle text_rectangle;
2249 Rectangle radiobutton_rectangle;
2251 int radiobutton_size = 12;
2252 int radiobutton_space = 4;
2254 client_rectangle = radio_button.ClientRectangle;
2255 text_rectangle = client_rectangle;
2256 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2258 text_format = new StringFormat();
2259 text_format.Alignment = StringAlignment.Near;
2260 text_format.LineAlignment = StringAlignment.Center;
2261 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2263 /* Calculate the position of text and checkbox rectangle */
2264 if (radio_button.appearance!=Appearance.Button) {
2265 switch(radio_button.radiobutton_alignment) {
2266 case ContentAlignment.BottomCenter: {
2267 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2268 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2269 text_rectangle.X=client_rectangle.X;
2270 text_rectangle.Width=client_rectangle.Width;
2271 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2275 case ContentAlignment.BottomLeft: {
2276 radiobutton_rectangle.X=client_rectangle.Left;
2277 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2278 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2279 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2283 case ContentAlignment.BottomRight: {
2284 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2285 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2286 text_rectangle.X=client_rectangle.X;
2287 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2291 case ContentAlignment.MiddleCenter: {
2292 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2293 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2294 text_rectangle.X=client_rectangle.X;
2295 text_rectangle.Width=client_rectangle.Width;
2300 case ContentAlignment.MiddleLeft: {
2301 radiobutton_rectangle.X=client_rectangle.Left;
2302 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2303 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2304 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2308 case ContentAlignment.MiddleRight: {
2309 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2310 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2311 text_rectangle.X=client_rectangle.X;
2312 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2316 case ContentAlignment.TopCenter: {
2317 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2318 radiobutton_rectangle.Y=client_rectangle.Top;
2319 text_rectangle.X=client_rectangle.X;
2320 text_rectangle.Y=radiobutton_size+radiobutton_space;
2321 text_rectangle.Width=client_rectangle.Width;
2322 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2326 case ContentAlignment.TopLeft: {
2327 radiobutton_rectangle.X=client_rectangle.Left;
2328 radiobutton_rectangle.Y=client_rectangle.Top;
2329 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2330 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2334 case ContentAlignment.TopRight: {
2335 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2336 radiobutton_rectangle.Y=client_rectangle.Top;
2337 text_rectangle.X=client_rectangle.X;
2338 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2343 text_rectangle.X=client_rectangle.X;
2344 text_rectangle.Width=client_rectangle.Width;
2347 /* Set the horizontal alignment of our text */
2348 switch(radio_button.text_alignment) {
2349 case ContentAlignment.BottomLeft:
2350 case ContentAlignment.MiddleLeft:
2351 case ContentAlignment.TopLeft: {
2352 text_format.Alignment=StringAlignment.Near;
2356 case ContentAlignment.BottomCenter:
2357 case ContentAlignment.MiddleCenter:
2358 case ContentAlignment.TopCenter: {
2359 text_format.Alignment=StringAlignment.Center;
2363 case ContentAlignment.BottomRight:
2364 case ContentAlignment.MiddleRight:
2365 case ContentAlignment.TopRight: {
2366 text_format.Alignment=StringAlignment.Far;
2371 /* Set the vertical alignment of our text */
2372 switch(radio_button.text_alignment) {
2373 case ContentAlignment.TopLeft:
2374 case ContentAlignment.TopCenter:
2375 case ContentAlignment.TopRight: {
2376 text_format.LineAlignment=StringAlignment.Near;
2380 case ContentAlignment.BottomLeft:
2381 case ContentAlignment.BottomCenter:
2382 case ContentAlignment.BottomRight: {
2383 text_format.LineAlignment=StringAlignment.Far;
2387 case ContentAlignment.MiddleLeft:
2388 case ContentAlignment.MiddleCenter:
2389 case ContentAlignment.MiddleRight: {
2390 text_format.LineAlignment=StringAlignment.Center;
2395 ButtonState state = ButtonState.Normal;
2396 if (radio_button.FlatStyle == FlatStyle.Flat) {
2397 state |= ButtonState.Flat;
2400 if (radio_button.Checked) {
2401 state |= ButtonState.Checked;
2406 sb=new SolidBrush(radio_button.BackColor);
2407 dc.FillRectangle(sb, radio_button.ClientRectangle);
2412 if (radio_button.appearance==Appearance.Button) {
2413 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2414 DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
2416 CPDrawButton(dc, radio_button.ClientRectangle, state);
2419 // establish if we are rendering a flat style of some sort
2420 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2421 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2423 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
2427 // offset the text if it's pressed and a button
2428 if (radio_button.Appearance == Appearance.Button) {
2429 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
2430 text_rectangle.X ++;
2431 text_rectangle.Y ++;
2434 text_rectangle.Inflate(-4,-4);
2437 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
2438 sb=new SolidBrush(radio_button.ForeColor);
2439 dc.DrawString (radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2441 if (radio_button.Enabled) {
2442 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
2443 dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2444 } else if (radio_button.FlatStyle == FlatStyle.Flat) {
2445 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
2447 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorButtonText, text_rectangle, text_format);
2450 if (radio_button.Focused) {
2451 if (radio_button.FlatStyle != FlatStyle.Flat) {
2452 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
2454 dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
2459 // renders a radio button with the Flat and Popup FlatStyle
2460 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2464 if (radio_button.Enabled) {
2465 // draw the outer flatstyle arcs
2466 if (radio_button.FlatStyle == FlatStyle.Flat) {
2467 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
2469 // fill in the area depending on whether or not the mouse is hovering
2470 if (radio_button.is_entered && radio_button.Capture) {
2471 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2473 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2476 // must be a popup radio button
2478 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
2480 if (radio_button.is_entered || radio_button.Capture) {
2481 // draw the popup 3d button knob
2482 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2484 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
2485 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
2488 // just draw lighter flatstyle outer circle
2489 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorButtonFace)), rectangle, 0, 359);
2494 // fill control background color regardless of actual backcolor
2495 graphics.FillPie (ResPool.GetSolidBrush (this.ColorButtonFace), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2496 // draw the ark as control dark
2497 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorButtonFace)), rectangle, 0, 359);
2501 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2502 if (radio_button.Checked) {
2503 SolidBrush buttonBrush;
2505 if (!radio_button.Enabled) {
2506 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorButtonFace));
2507 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
2508 buttonBrush = ResPool.GetSolidBrush (this.ColorButtonText);
2510 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
2512 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
2516 public override Size RadioButtonDefaultSize {
2518 return new Size (104,24);
2521 #endregion // RadioButton
2524 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2526 int scrollbutton_width = bar.scrollbutton_width;
2527 int scrollbutton_height = bar.scrollbutton_height;
2528 Rectangle first_arrow_area;
2529 Rectangle second_arrow_area;
2530 Rectangle thumb_pos;
2532 thumb_pos = bar.ThumbPos;
2535 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2536 bar.FirstArrowArea = first_arrow_area;
2538 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2539 bar.SecondArrowArea = second_arrow_area;
2541 thumb_pos.Width = bar.Width;
2542 bar.ThumbPos = thumb_pos;
2545 if (clip.IntersectsWith (first_arrow_area))
2546 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2547 if (clip.IntersectsWith (second_arrow_area))
2548 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2551 switch (bar.thumb_moving) {
2552 case ScrollBar.ThumbMoving.None: {
2553 Rectangle r = new Rectangle (0,
2554 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
2555 Rectangle intersect = Rectangle.Intersect (clip, r);
2557 if (intersect != Rectangle.Empty)
2558 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2561 case ScrollBar.ThumbMoving.Forward: {
2562 Rectangle r = new Rectangle (0, scrollbutton_height,
2563 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2564 Rectangle intersect = Rectangle.Intersect (clip, r);
2566 if (intersect != Rectangle.Empty)
2567 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2570 r.Y = thumb_pos.Y + thumb_pos.Height;
2571 r.Width = bar.ClientRectangle.Width;
2572 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2574 intersect = Rectangle.Intersect (clip, r);
2575 if (intersect != Rectangle.Empty)
2576 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2580 case ScrollBar.ThumbMoving.Backwards: {
2581 Rectangle r = new Rectangle (0, scrollbutton_height,
2582 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2583 Rectangle intersect = Rectangle.Intersect (clip, r);
2585 if (intersect != Rectangle.Empty)
2586 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2589 r.Y = thumb_pos.Y + thumb_pos.Height;
2590 r.Width = bar.ClientRectangle.Width;
2591 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2593 intersect = Rectangle.Intersect (clip, r);
2594 if (intersect != Rectangle.Empty)
2595 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2603 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2604 bar.FirstArrowArea = first_arrow_area;
2606 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2607 bar.SecondArrowArea = second_arrow_area;
2609 thumb_pos.Height = bar.Height;
2610 bar.ThumbPos = thumb_pos;
2613 if (clip.IntersectsWith (first_arrow_area))
2614 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2615 if (clip.IntersectsWith (second_arrow_area))
2616 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2619 switch (bar.thumb_moving) {
2620 case ScrollBar.ThumbMoving.None: {
2621 Rectangle r = new Rectangle (scrollbutton_width,
2622 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
2623 Rectangle intersect = Rectangle.Intersect (clip, r);
2625 if (intersect != Rectangle.Empty)
2626 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2630 case ScrollBar.ThumbMoving.Forward: {
2631 Rectangle r = new Rectangle (scrollbutton_width, 0,
2632 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2633 Rectangle intersect = Rectangle.Intersect (clip, r);
2635 if (intersect != Rectangle.Empty)
2636 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2638 r.X = thumb_pos.X + thumb_pos.Width;
2640 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2641 r.Height = bar.ClientRectangle.Height;
2643 intersect = Rectangle.Intersect (clip, r);
2644 if (intersect != Rectangle.Empty)
2645 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2649 case ScrollBar.ThumbMoving.Backwards: {
2650 Rectangle r = new Rectangle (scrollbutton_width, 0,
2651 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2652 Rectangle intersect = Rectangle.Intersect (clip, r);
2654 if (intersect != Rectangle.Empty)
2655 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2657 r.X = thumb_pos.X + thumb_pos.Width;
2659 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2660 r.Height = bar.ClientRectangle.Height;
2662 intersect = Rectangle.Intersect (clip, r);
2663 if (intersect != Rectangle.Empty)
2664 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2671 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith (thumb_pos))
2672 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
2675 public override int ScrollBarButtonSize {
2678 #endregion // ScrollBar
2681 public override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
2682 Rectangle area = sb.paint_area;
2683 int horz_border = 2;
2684 int vert_border = 2;
2686 dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
2688 if (sb.ShowPanels && sb.Panels.Count == 0) {
2689 // Create a default panel.
2690 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
2692 StatusBarPanel panel = new StatusBarPanel ();
2693 Rectangle new_area = new Rectangle (area.X + horz_border,
2694 area.Y + horz_border,
2695 area.Width - StatusBarSizeGripWidth - horz_border,
2696 area.Height - horz_border);
2697 DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
2698 } else if (sb.ShowPanels) {
2699 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
2700 int prev_x = area.X + horz_border;
2701 int y = area.Y + vert_border;
2702 for (int i = 0; i < sb.Panels.Count; i++) {
2703 Rectangle pr = new Rectangle (prev_x, y,
2704 sb.Panels [i].Width, area.Height);
2705 prev_x += pr.Width + StatusBarHorzGapWidth;
2706 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
2711 CPDrawSizeGrip (dc, ColorButtonFace, area);
2716 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
2717 SolidBrush br_forecolor, StatusBarPanel panel) {
2718 int border_size = 3; // this is actually const, even if the border style is none
2720 area.Height -= border_size;
2721 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
2722 Border3DStyle border_style = Border3DStyle.SunkenInner;
2723 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
2724 border_style = Border3DStyle.RaisedOuter;
2725 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
2728 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
2729 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
2730 dc, panel.Parent.Font, area, index, DrawItemState.Default,
2731 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
2732 panel.Parent.OnDrawItemInternal (e);
2736 int left = area.Left;
2737 if (panel.Icon != null) {
2739 dc.DrawIcon (panel.Icon, left, area.Top);
2740 left += panel.Icon.Width;
2743 if (panel.Text == String.Empty)
2746 string text = panel.Text;
2747 StringFormat string_format = new StringFormat ();
2748 string_format.Trimming = StringTrimming.Character;
2749 string_format.FormatFlags = StringFormatFlags.NoWrap;
2751 if (text [0] == '\t') {
2752 string_format.Alignment = StringAlignment.Center;
2753 text = text.Substring (1);
2754 if (text [0] == '\t') {
2755 string_format.Alignment = StringAlignment.Far;
2756 text = text.Substring (1);
2760 int x = left + border_size;
2761 int y = border_size + 2;
2762 Rectangle r = new Rectangle (x, y,
2763 area.Right - x - border_size,
2764 area.Bottom - y - border_size);
2766 dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
2769 public override int StatusBarSizeGripWidth {
2773 public override int StatusBarHorzGapWidth {
2777 public override Size StatusBarDefaultSize {
2779 return new Size (100, 22);
2782 #endregion // StatusBar
2784 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
2786 // Do we need to fill the back color? It can't be changed...
2787 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
2788 Rectangle panel_rect = GetTabPanelRectExt (tab);
2790 if (tab.Appearance == TabAppearance.Normal) {
2791 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorButtonFace);
2792 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2795 if (tab.Alignment == TabAlignment.Top) {
2796 for (int r = tab.TabPages.Count; r > 0; r--) {
2797 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2798 if (i == tab.SelectedIndex)
2800 if (r != tab.TabPages [i].Row)
2802 Rectangle rect = tab.GetTabRect (i);
2803 if (!rect.IntersectsWith (area))
2805 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2809 for (int r = 0; r < tab.TabPages.Count; r++) {
2810 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2811 if (i == tab.SelectedIndex)
2813 if (r != tab.TabPages [i].Row)
2815 Rectangle rect = tab.GetTabRect (i);
2816 if (!rect.IntersectsWith (area))
2818 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2823 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
2824 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
2825 if (rect.IntersectsWith (area))
2826 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
2829 if (tab.ShowSlider) {
2830 Rectangle right = GetTabControlRightScrollRect (tab);
2831 Rectangle left = GetTabControlLeftScrollRect (tab);
2832 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
2833 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
2837 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
2839 switch (tab.Alignment) {
2840 case TabAlignment.Top:
2841 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
2843 Rectangle panel_rect = GetTabPanelRectExt (tab);
2844 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
2848 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
2850 switch (tab.Alignment) {
2851 case TabAlignment.Top:
2852 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
2854 Rectangle panel_rect = GetTabPanelRectExt (tab);
2855 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
2859 public override Size TabControlDefaultItemSize {
2860 get { return new Size (42, 21); }
2863 public override Point TabControlDefaultPadding {
2864 get { return new Point (6, 3); }
2867 public override int TabControlMinimumTabWidth {
2871 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
2873 Rectangle ext = GetTabPanelRectExt (tab);
2874 // Account for border size
2875 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
2878 public override Size TabControlGetSpacing (TabControl tab) {
2879 switch (tab.Appearance) {
2880 case TabAppearance.Normal:
2881 return new Size (1, -2);
2882 case TabAppearance.Buttons:
2883 return new Size (3, 3);
2884 case TabAppearance.FlatButtons:
2885 return new Size (9, 3);
2887 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
2891 private Rectangle GetTabPanelRectExt (TabControl tab)
2893 // Offset the tab from the top corner
2894 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
2895 tab.ClientRectangle.Y,
2896 tab.ClientRectangle.Width - 2,
2897 tab.ClientRectangle.Height - 1);
2899 if (tab.TabCount == 0)
2902 int spacing = TabControlGetSpacing (tab).Height;
2903 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
2905 switch (tab.Alignment) {
2906 case TabAlignment.Left:
2908 res.Width -= offset;
2910 case TabAlignment.Right:
2911 res.Width -= offset;
2913 case TabAlignment.Top:
2915 res.Height -= offset;
2917 case TabAlignment.Bottom:
2918 res.Height -= offset;
2925 private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
2927 int FlatButtonSpacing = 8;
2929 int res = bounds.Width;
2931 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
2933 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
2935 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2938 if (tab.Appearance == TabAppearance.FlatButtons) {
2939 int width = bounds.Width;
2940 bounds.Width += (FlatButtonSpacing - 2);
2942 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
2943 bounds.Width = width;
2947 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
2948 } else if (tab.Appearance != TabAppearance.FlatButtons) {
2949 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
2952 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
2954 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
2956 switch (tab.Alignment) {
2958 case TabAlignment.Top:
2961 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2963 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
2964 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
2965 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
2967 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
2968 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
2969 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
2971 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2973 if (page.Text != String.Empty) {
2974 StringFormat string_format = new StringFormat ();
2975 string_format.Alignment = StringAlignment.Center;
2976 string_format.LineAlignment = StringAlignment.Center;
2977 string_format.FormatFlags = StringFormatFlags.NoWrap;
2979 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2985 case TabAlignment.Bottom:
2987 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2989 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
2990 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
2992 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
2993 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
2995 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
2996 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
2997 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
2999 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3001 if (page.Text != String.Empty) {
3002 StringFormat string_format = new StringFormat ();
3003 string_format.Alignment = StringAlignment.Center;
3004 string_format.LineAlignment = StringAlignment.Center;
3005 string_format.FormatFlags = StringFormatFlags.NoWrap;
3007 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
3013 case TabAlignment.Left:
3015 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3017 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3018 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3019 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3021 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3023 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3024 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3026 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3028 if (page.Text != String.Empty) {
3029 StringFormat string_format = new StringFormat ();
3030 // Flip the text around
3031 string_format.Alignment = StringAlignment.Center;
3032 string_format.LineAlignment = StringAlignment.Center;
3033 string_format.FormatFlags = StringFormatFlags.NoWrap;
3034 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3035 int wo = interior.Width / 2;
3036 int ho = interior.Height / 2;
3037 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3038 dc.RotateTransform (180);
3039 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), 0, 0, string_format);
3040 dc.ResetTransform ();
3046 // TabAlignment.Right
3048 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3050 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3051 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3053 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3054 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3056 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3057 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3059 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3061 if (page.Text != String.Empty) {
3062 StringFormat string_format = new StringFormat ();
3063 string_format.Alignment = StringAlignment.Center;
3064 string_format.LineAlignment = StringAlignment.Center;
3065 string_format.FormatFlags = StringFormatFlags.NoWrap;
3066 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3068 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
3077 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3084 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
3085 StringFormat format = new StringFormat ();
3086 format.Trimming = StringTrimming.EllipsisWord;
3087 if (control.textAlignment == ToolBarTextAlign.Underneath) {
3088 format.LineAlignment = StringAlignment.Center;
3089 format.Alignment = StringAlignment.Center;
3091 format.LineAlignment = StringAlignment.Center;
3092 format.Alignment = StringAlignment.Near;
3095 // Exclude the area for divider
3096 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
3097 control.Width, control.Height - ToolBarGripWidth / 2);
3098 bool flat = (control.Appearance == ToolBarAppearance.Flat);
3099 dc.FillRectangle (SystemBrushes.Control, paint_area);
3100 CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
3102 if (control.Divider)
3103 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
3105 foreach (ToolBarButton button in control.Buttons) {
3108 Rectangle buttonArea = button.Rectangle;
3109 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
3110 Rectangle txtRect = buttonArea; // rect to draw the text
3111 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
3113 // calculate different rects and draw the frame if its not separator button
3114 if (button.Style != ToolBarButtonStyle.Separator) {
3115 /* Adjustment for drop down arrow */
3116 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
3117 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
3118 ddRect.Y = buttonArea.Y;
3119 ddRect.Width = this.ToolBarDropDownWidth;
3120 ddRect.Height = buttonArea.Height;
3123 // calculate txtRect and imgRect, if imageIndex and imageList are present
3124 if (button.ImageIndex > -1 && control.ImageList != null) {
3125 if (button.ImageIndex < control.ImageList.Images.Count)
3126 image = control.ImageList.Images [button.ImageIndex];
3127 // draw the image at the centre if textalignment is underneath
3128 if (control.TextAlign == ToolBarTextAlign.Underneath) {
3129 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
3130 - control.ImageSize.Width) / 2)
3131 + this.ToolBarImageGripWidth;
3132 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3133 imgRect.Width = control.ImageSize.Width;
3134 imgRect.Height = control.ImageSize.Height;
3136 txtRect.X = buttonArea.X;
3137 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
3138 txtRect.Width = buttonArea.Width - ddRect.Width;
3139 txtRect.Height = buttonArea.Height - imgRect.Height
3140 - 2 * this.ToolBarImageGripWidth;
3143 imgRect.X = buttonArea.X + 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 + imgRect.Width + 2 * this.ToolBarImageGripWidth;
3149 txtRect.Y = buttonArea.Y;
3150 txtRect.Width = buttonArea.Width - imgRect.Width
3151 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
3152 txtRect.Height = buttonArea.Height;
3155 /* Draw the button frame, only if it is not a separator */
3157 if (button.Pushed || button.Pressed) {
3158 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
3159 } else if (button.Hilight) {
3160 dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
3161 if (! ddRect.IsEmpty) {
3162 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
3163 ddRect.Y + ddRect.Height);
3164 buttonArea.Width -= this.ToolBarDropDownWidth;
3168 else { // normal toolbar
3169 if (button.Pushed || button.Pressed) {
3170 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
3171 Border3DSide.All, ColorButtonFace);
3172 if (! ddRect.IsEmpty) {
3173 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
3174 Border3DSide.Left, ColorButtonFace);
3175 buttonArea.Width -= this.ToolBarDropDownWidth;
3179 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
3180 Border3DSide.All, ColorButtonFace);
3181 if (! ddRect.IsEmpty) {
3182 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
3183 Border3DSide.Left, ColorButtonFace);
3184 buttonArea.Width -= this.ToolBarDropDownWidth;
3189 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
3190 imgRect, image, txtRect, ddRect, flat);
3194 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
3195 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
3196 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
3197 if (! button.Visible)
3200 switch (button.Style) {
3202 case ToolBarButtonStyle.Separator:
3203 // separator is drawn only in the case of flat appearance
3205 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
3206 buttonArea.X + 1, buttonArea.Height);
3207 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
3208 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
3209 /* draw a horizontal separator */
3210 if (button.Wrapper) {
3211 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
3212 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
3213 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
3214 y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
3219 case ToolBarButtonStyle.ToggleButton:
3220 Rectangle toggleArea = Rectangle.Empty;
3221 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
3222 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3223 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
3224 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
3225 if (button.PartialPush && button.Pushed) {
3226 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3227 if (! imgRect.IsEmpty) {
3228 if (button.Enabled && image != null)
3229 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3230 imgRect.Height, button.ImageIndex);
3232 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3233 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3234 Border3DSide.Right | Border3DSide.Bottom);
3238 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3240 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
3243 else if (button.PartialPush) {
3244 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
3245 if (! imgRect.IsEmpty) {
3246 if (button.Enabled && image != null)
3247 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3248 imgRect.Height, button.ImageIndex);
3250 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3251 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3252 Border3DSide.Right | Border3DSide.Bottom);
3256 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3258 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3262 else if (button.Pushed) {
3263 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3264 if (! imgRect.IsEmpty) {
3265 if (button.Enabled && image != null)
3266 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3267 imgRect.Height, button.ImageIndex);
3269 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3270 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3271 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3275 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3277 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3282 dc.FillRectangle (SystemBrushes.Control, toggleArea);
3283 if (! imgRect.IsEmpty) {
3284 if (button.Enabled && image != null)
3285 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3286 imgRect.Height, button.ImageIndex);
3288 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3289 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3290 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3294 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3296 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3301 case ToolBarButtonStyle.DropDownButton:
3302 // draw the dropdown arrow
3303 if (! ddRect.IsEmpty) {
3304 PointF [] vertices = new PointF [3];
3305 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
3306 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3307 vertices [0].Y = ddCenter.Y;
3308 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3309 vertices [1].Y = ddCenter.Y;
3310 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3311 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
3312 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3314 goto case ToolBarButtonStyle.PushButton;
3316 case ToolBarButtonStyle.PushButton:
3317 if (! imgRect.IsEmpty){
3318 if (button.Enabled && image != null)
3319 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
3322 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
3323 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3324 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3328 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3330 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3336 // Grip width for the ToolBar
3337 public override int ToolBarGripWidth {
3341 // Grip width for the Image on the ToolBarButton
3342 public override int ToolBarImageGripWidth {
3346 // width of the separator
3347 public override int ToolBarSeparatorWidth {
3351 // width of the dropdown arrow rect
3352 public override int ToolBarDropDownWidth {
3356 // width for the dropdown arrow on the ToolBarButton
3357 public override int ToolBarDropDownArrowWidth {
3361 // height for the dropdown arrow on the ToolBarButton
3362 public override int ToolBarDropDownArrowHeight {
3366 public override Size ToolBarDefaultSize {
3368 return new Size (100, 42);
3371 #endregion // ToolBar
3374 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt) {
3377 control = tt.tooltip_window;
3378 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
3379 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
3380 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, tt.tooltip_window.string_format);
3383 public override Size ToolTipSize(ToolTip tt, string text) {
3386 sizef = tt.tooltip_window.DeviceContext.MeasureString(text, tt.tooltip_window.Font);
3387 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
3389 #endregion // ToolTip
3392 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3393 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3394 float ticks, int value_pos, bool mouse_value) {
3396 Point toptick_startpoint = new Point ();
3397 Point bottomtick_startpoint = new Point ();
3398 Point channel_startpoint = new Point ();
3400 float pixels_betweenticks;
3401 const int space_from_right = 8;
3402 const int space_from_left = 8;
3403 Rectangle area = tb.ClientRectangle;
3405 switch (tb.TickStyle) {
3406 case TickStyle.BottomRight:
3407 case TickStyle.None:
3408 channel_startpoint.Y = 8;
3409 channel_startpoint.X = 9;
3410 bottomtick_startpoint.Y = 13;
3411 bottomtick_startpoint.X = 24;
3413 case TickStyle.TopLeft:
3414 channel_startpoint.Y = 8;
3415 channel_startpoint.X = 19;
3416 toptick_startpoint.Y = 13;
3417 toptick_startpoint.X = 8;
3419 case TickStyle.Both:
3420 channel_startpoint.Y = 8;
3421 channel_startpoint.X = 18;
3422 bottomtick_startpoint.Y = 13;
3423 bottomtick_startpoint.X = 32;
3424 toptick_startpoint.Y = 13;
3425 toptick_startpoint.X = 8;
3431 thumb_area.X = area.X + channel_startpoint.X;
3432 thumb_area.Y = area.Y + channel_startpoint.Y;
3433 thumb_area.Height = area.Height - space_from_right - space_from_left;
3434 thumb_area.Width = 4;
3437 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3438 1, thumb_area.Height);
3440 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
3441 1, thumb_area.Height);
3443 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
3444 1, thumb_area.Height);
3446 pixel_len = thumb_area.Height - 11;
3447 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3449 /* Convert thumb position from mouse position to value*/
3452 if (value_pos >= channel_startpoint.Y)
3453 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
3457 if (value_pos + tb.Minimum > tb.Maximum)
3458 value_pos = tb.Maximum - tb.Minimum;
3460 tb.Value = value_pos + tb.Minimum;
3463 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
3465 /* Draw thumb fixed 10x22 size */
3466 thumb_pos.Width = 10;
3467 thumb_pos.Height = 22;
3469 switch (tb.TickStyle) {
3470 case TickStyle.BottomRight:
3471 case TickStyle.None: {
3472 thumb_pos.X = channel_startpoint.X - 8;
3474 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3475 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3476 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3478 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3479 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3481 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3482 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3484 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3485 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3486 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3487 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3491 case TickStyle.TopLeft: {
3492 thumb_pos.X = channel_startpoint.X - 10;
3494 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3495 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3497 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3498 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3499 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3501 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3502 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3503 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3505 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3506 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3507 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3508 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3513 case TickStyle.Both: {
3514 thumb_pos.X = area.X + 10;
3515 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3516 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3518 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3519 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3521 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3522 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3524 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3533 pixel_len = thumb_area.Height - 11;
3534 pixels_betweenticks = pixel_len / ticks;
3536 thumb_area.X = thumb_pos.X;
3537 thumb_area.Y = channel_startpoint.Y;
3538 thumb_area.Width = thumb_pos.Height;
3541 Region outside = new Region (area);
3542 outside.Exclude (thumb_area);
3544 if (outside.IsVisible (clip_rectangle)) {
3545 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3546 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3548 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3549 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3550 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3551 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3553 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3554 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3558 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3559 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3561 pixel_len = thumb_area.Height - 11;
3562 pixels_betweenticks = pixel_len / ticks;
3564 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3565 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3566 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3567 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3569 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3570 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3580 Does not matter the size of the control, Win32 always draws:
3581 - Ticks starting from pixel 13, 8
3582 - Channel starting at pos 8, 19 and ends at Width - 8
3583 - Autosize makes always the control 40 pixels height
3584 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3587 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3588 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3589 float ticks, int value_pos, bool mouse_value) {
3590 Point toptick_startpoint = new Point ();
3591 Point bottomtick_startpoint = new Point ();
3592 Point channel_startpoint = new Point ();
3594 float pixels_betweenticks;
3595 const int space_from_right = 8;
3596 const int space_from_left = 8;
3597 Rectangle area = tb.ClientRectangle;
3599 switch (tb.TickStyle) {
3600 case TickStyle.BottomRight:
3601 case TickStyle.None:
3602 channel_startpoint.X = 8;
3603 channel_startpoint.Y = 9;
3604 bottomtick_startpoint.X = 13;
3605 bottomtick_startpoint.Y = 24;
3607 case TickStyle.TopLeft:
3608 channel_startpoint.X = 8;
3609 channel_startpoint.Y = 19;
3610 toptick_startpoint.X = 13;
3611 toptick_startpoint.Y = 8;
3613 case TickStyle.Both:
3614 channel_startpoint.X = 8;
3615 channel_startpoint.Y = 18;
3616 bottomtick_startpoint.X = 13;
3617 bottomtick_startpoint.Y = 32;
3618 toptick_startpoint.X = 13;
3619 toptick_startpoint.Y = 8;
3625 thumb_area.X = area.X + channel_startpoint.X;
3626 thumb_area.Y = area.Y + channel_startpoint.Y;
3627 thumb_area.Width = area.Width - space_from_right - space_from_left;
3628 thumb_area.Height = 4;
3631 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3632 thumb_area.Width, 1);
3634 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
3635 thumb_area.Width, 1);
3637 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
3638 thumb_area.Width, 1);
3640 pixel_len = thumb_area.Width - 11;
3641 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3643 /* Convert thumb position from mouse position to value*/
3645 if (value_pos >= channel_startpoint.X)
3646 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
3650 if (value_pos + tb.Minimum > tb.Maximum)
3651 value_pos = tb.Maximum - tb.Minimum;
3653 tb.Value = value_pos + tb.Minimum;
3656 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
3658 /* Draw thumb fixed 10x22 size */
3659 thumb_pos.Width = 10;
3660 thumb_pos.Height = 22;
3662 switch (tb.TickStyle) {
3663 case TickStyle.BottomRight:
3664 case TickStyle.None: {
3665 thumb_pos.Y = channel_startpoint.Y - 8;
3667 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
3668 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
3669 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
3671 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
3672 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
3674 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
3675 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
3677 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
3678 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
3679 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
3680 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
3683 case TickStyle.TopLeft: {
3684 thumb_pos.Y = channel_startpoint.Y - 10;
3686 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
3687 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
3689 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
3690 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
3691 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
3693 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
3694 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
3695 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
3697 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
3698 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
3699 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
3700 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
3704 case TickStyle.Both: {
3705 thumb_pos.Y = area.Y + 10;
3706 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
3707 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
3709 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
3710 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
3712 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
3713 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
3715 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
3724 pixel_len = thumb_area.Width - 11;
3725 pixels_betweenticks = pixel_len / ticks;
3728 thumb_area.Y = thumb_pos.Y;
3729 thumb_area.X = channel_startpoint.X;
3730 thumb_area.Height = thumb_pos.Height;
3731 Region outside = new Region (area);
3732 outside.Exclude (thumb_area);
3734 if (outside.IsVisible (clip_rectangle)) {
3735 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3736 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3738 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3739 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3740 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
3741 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
3743 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
3744 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
3748 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3749 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3751 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3752 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3753 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
3754 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
3756 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
3757 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
3763 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
3768 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
3770 Rectangle thumb_pos = tb.ThumbPos;
3771 Rectangle thumb_area = tb.ThumbArea;
3773 if (tb.thumb_pressed) {
3774 value_pos = tb.thumb_mouseclick;
3777 value_pos = tb.Value - tb.Minimum;
3778 mouse_value = false;
3781 area = tb.ClientRectangle;
3783 if (tb.thumb_pressed == true) {
3784 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
3786 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
3790 /* Control Background */
3791 if (tb.BackColor == DefaultControlBackColor) {
3792 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), clip_rectangle);
3794 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
3799 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
3800 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
3801 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
3802 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
3805 if (tb.Orientation == Orientation.Vertical) {
3806 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3807 br_thumb, ticks, value_pos, mouse_value);
3810 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3811 br_thumb, ticks, value_pos, mouse_value);
3814 tb.ThumbPos = thumb_pos;
3815 tb.ThumbArea = thumb_area;
3818 public override Size TrackBarDefaultSize {
3820 return new Size (104, 42);
3824 #endregion // TrackBar
3827 public override Size VScrollBarDefaultSize {
3829 return new Size (this.ScrollBarButtonSize, 80);
3832 #endregion // VScrollBar
3835 public override Size TreeViewDefaultSize {
\r
3837 return new Size (121, 97);
\r
3843 #region ControlPaint
3844 private enum DrawFrameControlStates {
3845 ButtonCheck = 0x0000,
3846 ButtonRadioImage = 0x0001,
3847 ButtonRadioMask = 0x0002,
3848 ButtonRadio = 0x0004,
3849 Button3State = 0x0008,
3850 ButtonPush = 0x0010,
3852 CaptionClose = 0x0000,
3853 CaptionMin = 0x0001,
3854 CaptionMax = 0x0002,
3855 CaptionRestore = 0x0004,
3856 CaptionHelp = 0x0008,
3860 MenuBullet = 0x0002,
3861 MenuArrowRight = 0x0004,
3864 ScrollDown = 0x0001,
3865 ScrollLeft = 0x0002,
3866 ScrollRight = 0x0003,
3867 ScrollComboBox = 0x0005,
3868 ScrollSizeGrip = 0x0008,
3869 ScrollSizeGripRight = 0x0010,
3874 Transparent = 0x0800,
3876 AdjustRect = 0x2000,
3882 private enum DrawFrameControlTypes {
3889 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
3890 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3891 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3892 int bottomWidth, ButtonBorderStyle bottomStyle) {
3893 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
3894 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
3895 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
3896 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
3899 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
3900 CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
3903 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
3905 Pen penTopLeftInner;
3907 Pen penBottomRightInner;
3908 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
3909 bool doInner = false;
3911 if ((style & Border3DStyle.Adjust)!=0) {
3918 /* default to flat */
3919 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
3920 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3921 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
3922 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3924 if ((style & Border3DStyle.RaisedOuter)!=0) {
3925 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3926 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3927 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3930 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
3931 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3932 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
3933 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3938 if ((style & Border3DStyle.RaisedInner)!=0) {
3940 penTopLeftInner=ResPool.GetPen(control_color);
3941 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3943 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3944 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3946 } else if ((style & Border3DStyle.SunkenInner)!=0) {
3948 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3949 penBottomRightInner=ResPool.GetPen(control_color);
3951 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3952 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
3956 if ((sides & Border3DSide.Middle)!=0) {
3957 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
3960 if ((sides & Border3DSide.Left)!=0) {
3961 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
3963 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
3967 if ((sides & Border3DSide.Top)!=0) {
3968 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
3971 if ((sides & Border3DSide.Left)!=0) {
3972 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
3974 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
3979 if ((sides & Border3DSide.Right)!=0) {
3980 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
3983 if ((sides & Border3DSide.Top)!=0) {
3984 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
3986 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
3991 if ((sides & Border3DSide.Bottom)!=0) {
3994 if ((sides & Border3DSide.Left)!=0) {
3998 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
4001 if ((sides & Border3DSide.Right)!=0) {
4002 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4004 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4012 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4013 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
4015 if ((state & ButtonState.Pushed)!=0) {
4016 dfcs |= DrawFrameControlStates.Pushed;
4019 if ((state & ButtonState.Checked)!=0) {
4020 dfcs |= DrawFrameControlStates.Checked;
4023 if ((state & ButtonState.Flat)!=0) {
4024 dfcs |= DrawFrameControlStates.Flat;
4027 if ((state & ButtonState.Inactive)!=0) {
4028 dfcs |= DrawFrameControlStates.Inactive;
4030 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4034 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4035 Rectangle captionRect;
4038 CPDrawButton(graphics, rectangle, state);
4040 if (rectangle.Width<rectangle.Height) {
4041 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4043 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4046 if ((state & ButtonState.Pushed)!=0) {
4047 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4050 /* Make sure we've got at least a line width of 1 */
4051 lineWidth=Math.Max(1, captionRect.Width/7);
4054 case CaptionButton.Close: {
4057 if ((state & ButtonState.Inactive)!=0) {
4058 pen=new Pen(ColorButtonHilight, lineWidth);
4059 DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
4062 pen=new Pen(ColorButtonShadow, lineWidth);
4063 DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
4067 pen=new Pen(ColorButtonText, lineWidth);
4068 DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
4074 case CaptionButton.Help:
4075 case CaptionButton.Maximize:
4076 case CaptionButton.Minimize:
4077 case CaptionButton.Restore: {
4078 if ((state & ButtonState.Inactive)!=0) {
4079 DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4081 DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4084 DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4092 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
4093 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
4095 if ((state & ButtonState.Pushed)!=0) {
4096 dfcs |= DrawFrameControlStates.Pushed;
4099 if ((state & ButtonState.Checked)!=0) {
4100 dfcs |= DrawFrameControlStates.Checked;
4103 if ((state & ButtonState.Flat)!=0) {
4104 dfcs |= DrawFrameControlStates.Flat;
4107 if ((state & ButtonState.Inactive)!=0) {
4108 dfcs |= DrawFrameControlStates.Inactive;
4111 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4115 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4116 Point[] arrow = new Point[3];
4126 if ((state & ButtonState.Checked)!=0) {
4127 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);
4130 if ((state & ButtonState.Flat)!=0) {
4131 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4133 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4134 // this needs to render like a pushed button - jba
4135 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4136 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4137 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4139 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4143 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4144 centerX=rect.Left+rect.Width/2;
4145 centerY=rect.Top+rect.Height/2;
4146 shiftX=Math.Max(1, rect.Width/8);
4147 shiftY=Math.Max(1, rect.Height/8);
4149 if ((state & ButtonState.Pushed)!=0) {
4156 P1=new Point(rect.Left, centerY);
4157 P2=new Point(rect.Right, centerY);
4158 P3=new Point(centerX, rect.Bottom);
4164 /* Draw the arrow */
4165 if ((state & ButtonState.Inactive)!=0) {
4166 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4168 /* Move away from the shadow */
4178 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4180 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4185 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
4187 Pen pen = new Pen(Color.Black, 1);
4188 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
4192 graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
4193 graphics.DrawRectangle(pen, rect);
4195 X=rect.X+rect.Width/2;
4196 Y=rect.Y+rect.Height/2;
4198 /* Draw the cross */
4199 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
4200 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
4202 /* Draw 'arrows' for vertical lines */
4203 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
4204 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
4206 /* Draw 'arrows' for horizontal lines */
4207 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
4208 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
4212 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4213 // make a rectange to trace around border of the button
4214 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4216 Color outerColor = foreColor;
4217 // adjust focus color according to the flatstyle
4218 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4219 outerColor = (backColor == ColorButtonFace) ? ControlPaint.Dark(ColorButtonFace) : ColorButtonText;
4222 // draw the outer rectangle
4223 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4225 // draw the inner rectangle
4226 if (button.FlatStyle == FlatStyle.Popup) {
4227 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4229 // draw a flat inner rectangle
4230 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4231 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4235 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4237 // make a rectange to trace around border of the button
4238 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4240 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4241 DashStyle oldStyle; // used for caching old penstyle
4242 Pen pen = ResPool.GetPen (colorBackInverted);
4244 oldStyle = pen.DashStyle;
4245 pen.DashStyle = DashStyle.Dot;
4246 graphics.DrawRectangle (pen, trace_rectangle);
4247 pen.DashStyle = oldStyle;
4251 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4253 Rectangle rect = rectangle;
4257 if (backColor.GetBrightness () >= 0.5) {
4258 foreColor = Color.Transparent;
4259 backColor = Color.Black;
4262 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4263 foreColor = Color.Black;
4266 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4267 pen = new Pen (brush, 1);
4272 graphics.DrawRectangle (pen, rect);
4276 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
4280 if (primary==true) {
4281 pen=new Pen(Color.Black, 1);
4282 if (enabled==true) {
4283 sb=ResPool.GetSolidBrush (ColorButtonText);
4285 sb=ResPool.GetSolidBrush (ColorButtonFace);
4288 pen=new Pen(Color.White, 1);
4289 if (enabled==true) {
4290 sb=new SolidBrush(Color.Black);
4292 sb=ResPool.GetSolidBrush (ColorButtonFace);
4295 graphics.FillRectangle(sb, rectangle);
4296 graphics.DrawRectangle(pen, rectangle);
4301 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4307 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4310 foreColor=Color.Black;
4312 foreColor=Color.White;
4316 /* Commented out until I take the time and figure out
4317 which HatchStyle will match requirements. The code below
4318 is only correct for Percent50.
4320 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
4321 HatchBrush brush=null;
4323 switch(pixelsBetweenDots.Width) {
4324 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
4325 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
4326 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
4328 /* Have to do it the slow way */
4333 graphics.FillRectangle(brush, area);
4342 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4344 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4345 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4346 bitmap.SetPixel(x, y, foreColor);
4349 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4353 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4355 Microsoft seems to ignore the background and simply make
4356 the image grayscale. At least when having > 256 colors on
4360 if (imagedisabled_attributes == null) {
4361 imagedisabled_attributes = new ImageAttributes ();
4362 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4363 // This table would create a perfect grayscale image, based on luminance
4364 // new float[]{0.3f,0.3f,0.3f,0,0},
4365 // new float[]{0.59f,0.59f,0.59f,0,0},
4366 // new float[]{0.11f,0.11f,0.11f,0,0},
4367 // new float[]{0,0,0,1,0,0},
4368 // new float[]{0,0,0,0,1,0},
4369 // new float[]{0,0,0,0,0,1}
4371 // This table generates a image that is grayscaled and then
4372 // brightened up. Seems to match MS close enough.
4373 new float[]{0.2f,0.2f,0.2f,0,0},
4374 new float[]{0.41f,0.41f,0.41f,0,0},
4375 new float[]{0.11f,0.11f,0.11f,0,0},
4376 new float[]{0.15f,0.15f,0.15f,1,0,0},
4377 new float[]{0.15f,0.15f,0.15f,0,1,0},
4378 new float[]{0.15f,0.15f,0.15f,0,0,1}
4381 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4384 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4389 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4394 penBorder=new Pen(Color.White, 2);
4395 penInside=new Pen(Color.Black, 1);
4397 penBorder=new Pen(Color.Black, 2);
4398 penInside=new Pen(Color.White, 1);
4400 penBorder.Alignment=PenAlignment.Inset;
4401 penInside.Alignment=PenAlignment.Inset;
4403 graphics.DrawRectangle(penBorder, rectangle);
4404 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4405 penBorder.Dispose();
4406 penInside.Dispose();
4410 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
4414 // MS draws always the background white
4415 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
4418 case MenuGlyph.Arrow: {
4419 Point[] arrow = new Point[3];
4427 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4428 centerX=rect.Left+rect.Width/2;
4429 centerY=rect.Top+rect.Height/2;
4430 shiftX=Math.Max(1, rect.Width/8);
4435 P1=new Point(centerX, rect.Top-1);
4436 P2=new Point(centerX, rect.Bottom);
4437 P3=new Point(rect.Right, centerY);
4443 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4448 case MenuGlyph.Bullet: {
4450 lineWidth=Math.Max(2, rectangle.Width/3);
4451 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4453 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
4458 case MenuGlyph.Checkmark: {
4461 lineWidth=Math.Max(2, rectangle.Width/6);
4462 Scale=Math.Max(1, rectangle.Width/12);
4464 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4466 for (int i=0; i<lineWidth; i++) {
4467 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4468 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);
4476 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4477 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
4479 if ((state & ButtonState.Pushed)!=0) {
4480 dfcs |= DrawFrameControlStates.Pushed;
4483 if ((state & ButtonState.Checked)!=0) {
4484 dfcs |= DrawFrameControlStates.Checked;
4487 if ((state & ButtonState.Flat)!=0) {
4488 dfcs |= DrawFrameControlStates.Flat;
4491 if ((state & ButtonState.Inactive)!=0) {
4492 dfcs |= DrawFrameControlStates.Inactive;
4494 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4499 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4504 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4509 /* Scroll button: regular button + direction arrow */
4510 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4511 bool enabled = (state == ButtonState.Inactive) ? false: true;
4513 DrawScrollButtonPrimitive (dc, area, state);
4515 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
4520 case ScrollButton.Up: {
4521 int x = area.X + (area.Width / 2) - 4;
4524 for (int i = 0; i < 3; i++)
4526 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y - i, x + i + 6 - 2*i, y - i);
4528 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
4531 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4532 x + 3, area.Y + 6, 1, 1);
4536 case ScrollButton.Down: {
4537 int x = area.X + (area.Width / 2) - 5;
4540 for (int i = 4; i != 0; i--)
4542 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i + 8 - 2*i, y + i);
4544 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
4547 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4548 x + 4, y + 4, 1, 1);
4552 case ScrollButton.Left: {
4553 int y = area.Y + (area.Height / 2) - 4;
4556 for (int i = 0; i < 3; i++)
4558 dc.DrawLine (ResPool.GetPen (arrow_color), x - i, y + i, x - i, y + i + 6 - 2*i);
4560 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
4562 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4563 x - 3, y + 3, 1, 1);
4567 case ScrollButton.Right: {
4568 int y = area.Y + (area.Height / 2) - 5;
4571 for (int i = 4; i != 0; i--)
4573 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i, y + i + 8 - 2*i);
4575 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
4577 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4578 x + 4, y + 4, 1, 1);
4589 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
4595 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
4596 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
4598 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
4599 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
4602 for (int i = 0; i < 11; i += 4) {
4603 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
4604 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
4607 for (int i = 3; i < 13; i += 4)
4608 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
4612 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
4613 StringFormat format) {
4615 layoutRectangle.Offset(1.0f, 1.0f);
4616 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 95)), layoutRectangle, format);
4617 layoutRectangle.Offset(-1.0f, -1.0f);
4618 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 50)), layoutRectangle, format);
4622 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
4623 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
4625 Pen pen=new Pen(color, 1);
4628 case ButtonBorderStyle.Solid: {
4629 pen.DashStyle=DashStyle.Solid;
4633 case ButtonBorderStyle.Dashed: {
4634 pen.DashStyle=DashStyle.Dash;
4638 case ButtonBorderStyle.Dotted: {
4639 pen.DashStyle=DashStyle.Dot;
4643 case ButtonBorderStyle.Inset: {
4644 pen.DashStyle=DashStyle.Solid;
4648 case ButtonBorderStyle.Outset: {
4649 pen.DashStyle=DashStyle.Solid;
4654 case ButtonBorderStyle.None: {
4662 case ButtonBorderStyle.Outset: {
4664 int hue, brightness, saturation;
4665 int brightnessSteps;
4666 int brightnessDownSteps;
4668 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4670 brightnessDownSteps=brightness/width;
4671 if (brightness>127) {
4672 brightnessSteps=Math.Max(6, (160-brightness)/width);
4674 brightnessSteps=(127-brightness)/width;
4677 for (int i=0; i<width; i++) {
4679 case Border3DSide.Left: {
4681 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4682 pen=new Pen(colorGrade, 1);
4683 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4687 case Border3DSide.Right: {
4689 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4690 pen=new Pen(colorGrade, 1);
4691 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4695 case Border3DSide.Top: {
4697 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4698 pen=new Pen(colorGrade, 1);
4699 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4703 case Border3DSide.Bottom: {
4705 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4706 pen=new Pen(colorGrade, 1);
4707 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4715 case ButtonBorderStyle.Inset: {
4717 int hue, brightness, saturation;
4718 int brightnessSteps;
4719 int brightnessDownSteps;
4721 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4723 brightnessDownSteps=brightness/width;
4724 if (brightness>127) {
4725 brightnessSteps=Math.Max(6, (160-brightness)/width);
4727 brightnessSteps=(127-brightness)/width;
4730 for (int i=0; i<width; i++) {
4732 case Border3DSide.Left: {
4734 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4735 pen=new Pen(colorGrade, 1);
4736 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4740 case Border3DSide.Right: {
4742 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4743 pen=new Pen(colorGrade, 1);
4744 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4748 case Border3DSide.Top: {
4750 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4751 pen=new Pen(colorGrade, 1);
4752 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4756 case Border3DSide.Bottom: {
4758 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4759 pen=new Pen(colorGrade, 1);
4760 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4769 I decided to have the for-loop duplicated for speed reasons;
4770 that way we only have to switch once (as opposed to have the
4771 for-loop around the switch)
4775 case Border3DSide.Left: {
4776 for (int i=0; i<width; i++) {
4777 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4782 case Border3DSide.Right: {
4783 for (int i=0; i<width; i++) {
4784 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4789 case Border3DSide.Top: {
4790 for (int i=0; i<width; i++) {
4791 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4796 case Border3DSide.Bottom: {
4797 for (int i=0; i<width; i++) {
4798 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4810 This function actually draws the various caption elements.
4811 This way we can scale them nicely, no matter what size, and they
4812 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
4815 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
4817 case CaptionButton.Close: {
4818 pen.StartCap=LineCap.Triangle;
4819 pen.EndCap=LineCap.Triangle;
4821 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);
4822 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);
4825 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4826 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4830 case CaptionButton.Help: {
4831 StringFormat sf = new StringFormat();
4832 SolidBrush sb = new SolidBrush(color);
4833 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
4835 sf.Alignment=StringAlignment.Center;
4836 sf.LineAlignment=StringAlignment.Center;
4839 graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
4848 case CaptionButton.Maximize: {
4849 /* Top 'caption bar' line */
4850 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4851 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);
4854 /* Left side line */
4855 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4856 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4859 /* Right side line */
4860 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4861 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);
4865 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4866 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4871 case CaptionButton.Minimize: {
4873 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4874 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
4879 case CaptionButton.Restore: {
4880 /** First 'window' **/
4881 /* Top 'caption bar' line */
4882 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4883 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);
4886 /* Left side line */
4887 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4888 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);
4891 /* Right side line */
4892 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4893 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);
4897 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4898 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);
4901 /** Second 'window' **/
4902 /* Top 'caption bar' line */
4903 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4904 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);
4907 /* Left side line */
4908 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4909 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4912 /* Right side line */
4913 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4914 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);
4918 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4919 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4928 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
4929 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
4930 // make a rectange to trace around border of the button
4931 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4933 case DrawFrameControlTypes.Button: {
4935 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
4936 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
4937 // /* Goes first, affects the background */
4938 // if ((State & DrawFrameControlStates.Checked)!=0) {
4939 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
4940 // graphics.FillRectangle(hatchBrush,rectangle);
4941 // hatchBrush.Dispose();
4944 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
4945 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4946 } else if ((State & DrawFrameControlStates.Flat)!=0) {
4947 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4948 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
4949 /* Same as normal, it would seem */
4950 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4952 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4954 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
4955 Pen penFatDark = new Pen(ColorButtonShadow, 1);
4956 Pen penFatLight = new Pen(ColorButtonLight, 1);
4959 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
4961 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
4962 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
4964 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
4965 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
4967 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
4969 if ((State & DrawFrameControlStates.Checked)!=0) {
4970 SolidBrush buttonBrush;
4972 if ((State & DrawFrameControlStates.Inactive)!=0) {
4973 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
4975 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
4977 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
4979 penFatDark.Dispose();
4980 penFatLight.Dispose();
4981 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
4982 throw new NotImplementedException () ;
4983 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
4984 throw new NotImplementedException ();
4985 } else { /* Must be Checkbox */
4991 /* Goes first, affects the background */
4992 if ((State & DrawFrameControlStates.Pushed)!=0 ||
4993 (State & DrawFrameControlStates.Inactive)!=0) {
4994 graphics.FillRectangle(SystemBrushes.Control, rectangle);
4996 graphics.FillRectangle(SystemBrushes.Window, rectangle);
4999 /* Draw the sunken frame */
5000 if ((State & DrawFrameControlStates.Flat)!=0) {
5001 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
5003 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
5006 /* Make sure we've got at least a line width of 1 */
5007 lineWidth=Math.Max(3, rectangle.Width/6);
5008 Scale=Math.Max(1, rectangle.Width/12);
5010 // define a rectangle inside the border area
5011 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
5012 if ((State & DrawFrameControlStates.Inactive)!=0) {
5013 pen=SystemPens.ControlDark;
5015 pen=SystemPens.ControlText;
5018 if ((State & DrawFrameControlStates.Checked)!=0) {
5019 /* Need to draw a check-mark */
5020 for (int i=0; i<lineWidth; i++) {
5021 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5022 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);
5030 case DrawFrameControlTypes.Caption: {
5035 case DrawFrameControlTypes.Menu: {
5040 case DrawFrameControlTypes.Scroll: {
5047 /* Generic scroll button */
5048 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5049 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5050 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
5051 area.Y + 1, area.Width - 2 , area.Height - 2);
5053 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
5054 area.Y, area.Width, area.Height);
5059 dc.FillRectangle (new SolidBrush (Color.Blue), area);
5061 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
5062 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
5064 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
5065 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
5068 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
5071 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
5074 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
5075 area.Y + 1, 1, area.Height -3);
5077 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
5078 area.Y, 1, area.Height - 1);
5080 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
5081 area.Y + 2, area.Width - 4, area.Height - 4);
5085 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5086 switch (border_style){
5087 case BorderStyle.Fixed3D:
5088 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
5089 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
5090 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5091 area.Y + area.Height - 1);
5092 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5093 area.Y + area.Height);
5095 // FIXME: These colors are not correct. Microsoft uses different ones but I didn't find them.
5096 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5097 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5098 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5099 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5101 case BorderStyle.FixedSingle:
5102 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5104 case BorderStyle.None:
5110 #endregion // ControlPaint