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.GetItemText (ctrl.Items[e.Index]), 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.GetItemText (ctrl.Items[e.Index]), 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);
860 public override int DataGridPreferredColumnWidth { get { return 75;} }
861 #endregion // Datagrid
863 #region DateTimePicker
865 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
866 // if not showing the numeric updown control then render border
867 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
868 // draw the outer border
869 Rectangle button_bounds = dtp.ClientRectangle;
870 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.All, dtp.BackColor);
872 // deflate by the border width
873 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
874 button_bounds.Inflate (-2,-2);
875 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
876 this.CPDrawComboButton (
878 dtp.drop_down_arrow_rect,
883 // render the date part
884 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
885 // fill the background
886 dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorWindow), dtp.date_area_rect);
888 // fill the currently highlighted area
889 if (dtp.hilight_date_area != Rectangle.Empty) {
890 dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorHilight), dtp.hilight_date_area);
893 // draw the text part
894 // TODO: if date format is CUstom then we need to draw the dates as separate parts
895 StringFormat text_format = new StringFormat();
896 text_format.LineAlignment = StringAlignment.Center;
897 text_format.Alignment = StringAlignment.Near;
898 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
902 #endregion // DateTimePicker
905 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
906 StringFormat text_format;
912 rect = box.ClientRectangle;
914 // Needed once the Dark/Light code below is enabled again
915 //Color disabled = ColorGrayText;
917 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
918 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
920 // TODO: When the Light and Dark methods work this code should be activate it
921 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
922 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
924 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
926 text_format = new StringFormat();
927 text_format.HotkeyPrefix = HotkeyPrefix.Show;
929 size = dc.MeasureString (box.Text, box.Font);
930 width = (int) size.Width;
932 if (width > box.Width - 16)
933 width = box.Width - 16;
935 y = box.Font.Height / 2;
938 dc.DrawLine (pen_dark, 0, y, 8, y); // top
939 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
940 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
941 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
943 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
944 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
946 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
947 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
949 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
950 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
955 dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0, text_format);
957 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
958 new RectangleF (10, 0, width, box.Font.Height), text_format);
963 public override Size GroupBoxDefaultSize {
965 return new Size (200,100);
971 public override Size HScrollBarDefaultSize {
973 return new Size (80, this.ScrollBarButtonSize);
977 #endregion // HScrollBar
980 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
982 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
984 CPDrawBorderStyle (dc, label.ClientRectangle, label.BorderStyle);
987 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
989 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
994 public override Size LabelDefaultSize {
996 return new Size (100, 23);
999 #endregion // Label
\r
1002 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
\r
1006 dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
\r
1007 CPDrawBorderStyle (dc, label.ClientRectangle, label.BorderStyle);
1009 for (int i = 0; i < label.num_pieces; i++) {
1011 if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
1015 color = label.GetLinkColor (label.pieces[i], i);
\r
1017 if (label.pieces[i].link == null)
\r
1018 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),
\r
1019 label.pieces[i].rect.X, label.pieces[i].rect.Y);
\r
1021 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
\r
1022 label.pieces[i].rect.X, label.pieces[i].rect.Y);
1024 if (label.pieces[i].focused) {
1025 CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
1030 #endregion // LinkLabel
\r
1034 public override void DrawListBoxDecorations (Graphics dc, ListBox ctrl)
1036 Rectangle cl = ctrl.LBoxInfo.client_rect;
1039 switch (ctrl.BorderStyle) {
1040 case BorderStyle.Fixed3D: {
1041 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top
1042 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
1043 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
1044 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
1045 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
1046 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2);
1047 dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
1048 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);
1051 case BorderStyle.FixedSingle:
1052 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
1054 case BorderStyle.None:
1060 private int DrawListBoxDecorationSize (BorderStyle border_style)
1062 switch (border_style) {
1063 case BorderStyle.Fixed3D:
1065 case BorderStyle.FixedSingle:
1067 case BorderStyle.None:
1076 public override int DrawListBoxDecorationTop (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1077 public override int DrawListBoxDecorationBottom (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1078 public override int DrawListBoxDecorationRight (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1079 public override int DrawListBoxDecorationLeft (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
1081 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1083 Color back_color, fore_color;
1084 StringFormat string_format = ctrl.GetFormatString ();
1086 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1087 back_color = ThemeEngine.Current.ColorHilight;
1088 fore_color = ThemeEngine.Current.ColorHilightText;
1091 back_color = e.BackColor;
1092 fore_color = e.ForeColor;
1095 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1096 (back_color), e.Bounds);
1098 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1099 ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
1100 e.Bounds, string_format);
1102 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
1103 ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds,
1104 fore_color, back_color);
1112 public override void DrawListView (Graphics dc, Rectangle clip, ListView control)
1114 bool details = (control.View == View.Details);
1116 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);
1118 // border is drawn directly in the Paint method
1119 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1120 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control),
1121 0, 0, control.TotalWidth, control.Font.Height + 5);
1122 if (control.Columns.Count > 0) {
1123 if (control.HeaderStyle == ColumnHeaderStyle.Clickable) {
1124 foreach (ColumnHeader col in control.Columns) {
1125 this.CPDrawButton (dc, col.Rect,
1127 ButtonState.Pushed :
1128 ButtonState.Normal));
1129 dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
1130 ResPool.GetSolidBrush
1131 (this.ColorButtonText),
1134 col.Rect.Y + col.Rect.Height/2 + 1,
1138 // Non-clickable columns
1140 foreach (ColumnHeader col in control.Columns) {
1141 this.CPDrawButton (dc, col.Rect, ButtonState.Flat);
1142 dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
1143 ResPool.GetSolidBrush
1144 (this.ColorButtonText),
1147 col.Rect.Y + col.Rect.Height/2 + 1,
1154 // In case of details view draw the items only if
1155 // columns are non-zero
1156 if (!details || control.Columns.Count > 0)
1157 foreach (ListViewItem item in control.Items) {
1158 if (clip.IntersectsWith (item.EntireRect))
1159 DrawListViewItem (dc, control, item);
1162 // draw the gridlines
1163 if (details && control.GridLines) {
1164 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1165 2 : control.Font.Height + 2;
1167 // draw vertical gridlines
1168 foreach (ColumnHeader col in control.Columns)
1169 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1170 col.Rect.Right, top,
1171 col.Rect.Right, control.TotalHeight);
1172 // draw horizontal gridlines
1173 ListViewItem last_item = null;
1174 foreach (ListViewItem item in control.Items) {
1175 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1176 item.EntireRect.Left, item.EntireRect.Top,
1177 control.TotalWidth, item.EntireRect.Top);
1181 // draw a line after at the bottom of the last item
1182 if (last_item != null) {
1183 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1184 last_item.EntireRect.Left,
1185 last_item.EntireRect.Bottom,
1187 last_item.EntireRect.Bottom);
1192 // draws the ListViewItem of the given index
1193 private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1195 if (control.CheckBoxes) {
1196 if (control.StateImageList == null) {
1197 // Make sure we've got at least a line width of 1
1198 int check_wd = Math.Max (3, item.CheckRect.Width / 6);
1199 int scale = Math.Max (1, item.CheckRect.Width / 12);
1201 // set the checkbox background
1202 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
1204 // define a rectangle inside the border area
1205 Rectangle rect = new Rectangle (item.CheckRect.X + 2,
1206 item.CheckRect.Y + 2,
1207 item.CheckRect.Width - 4,
1208 item.CheckRect.Height - 4);
1209 Pen pen = new Pen (this.ColorWindowText, 2);
1210 dc.DrawRectangle (pen, rect);
1212 // Need to draw a check-mark
1215 // adjustments to get the check-mark at the right place
1216 rect.X ++; rect.Y ++;
1217 // following logic is taken from DrawFrameControl method
1218 for (int i = 0; i < check_wd; i++) {
1219 dc.DrawLine (pen, rect.Left + check_wd / 2,
1220 rect.Top + check_wd + i,
1221 rect.Left + check_wd / 2 + 2 * scale,
1222 rect.Top + check_wd + 2 * scale + i);
1224 rect.Left + check_wd / 2 + 2 * scale,
1225 rect.Top + check_wd + 2 * scale + i,
1226 rect.Left + check_wd / 2 + 6 * scale,
1227 rect.Top + check_wd - 2 * scale + i);
1232 if (item.Checked && control.StateImageList.Images.Count > 1)
1233 control.StateImageList.Draw (dc,
1234 item.CheckRect.Location, 1);
1235 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1236 control.StateImageList.Draw (dc,
1237 item.CheckRect.Location, 0);
1241 // Item is drawn as a special case, as it is not just text
1242 if (control.View == View.LargeIcon) {
1243 if (item.ImageIndex > -1 &&
1244 control.LargeImageList != null &&
1245 item.ImageIndex < control.LargeImageList.Images.Count)
1246 control.LargeImageList.Draw (dc, item.IconRect.Location,
1250 if (item.ImageIndex > -1 &&
1251 control.SmallImageList != null &&
1252 item.ImageIndex < control.SmallImageList.Images.Count)
1253 control.SmallImageList.Draw (dc, item.IconRect.Location,
1257 // draw the item text
1258 Rectangle text_rect = item.LabelRect;
1259 // format for the item text
1260 StringFormat format = new StringFormat ();
1261 format.LineAlignment = StringAlignment.Center;
1262 if (control.View == View.LargeIcon)
1263 format.Alignment = StringAlignment.Center;
1265 format.Alignment = StringAlignment.Near;
1267 if (!control.LabelWrap)
1268 format.FormatFlags = StringFormatFlags.NoWrap;
1270 if (item.Selected) {
1271 if (control.View == View.Details) {
1272 if (control.FullRowSelect) {
1273 // fill the entire rect excluding the checkbox
1274 Rectangle full_rect = item.EntireRect;
1275 full_rect.Location = item.LabelRect.Location;
1276 dc.FillRectangle (this.ResPool.GetSolidBrush
1277 (this.ColorHilight), full_rect);
1280 Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1282 text_rect.Width = text_size.Width;
1283 dc.FillRectangle (this.ResPool.GetSolidBrush
1284 (this.ColorHilight), text_rect);
1288 /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
1290 Point loc = text_rect.Location;
1291 loc.X += (text_rect.Width - text_size.Width) / 2;
1292 text_rect.Width = text_size.Width;*/
1293 dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHilight),
1298 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1300 if (item.Text != null && item.Text.Length > 0) {
1302 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1303 (this.ColorHilightText), text_rect, format);
1305 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1306 (item.ForeColor), text_rect, format);
1309 if (control.View == View.Details && control.Columns.Count > 0) {
1310 // draw subitems for details view
1311 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1312 int count = (control.Columns.Count < subItems.Count ?
1313 control.Columns.Count : subItems.Count);
1317 ListViewItem.ListViewSubItem subItem;
1318 Rectangle sub_item_rect = item.LabelRect;
1320 // set the format for subitems
1321 format.FormatFlags = StringFormatFlags.NoWrap;
1322 format.Alignment = StringAlignment.Near;
1324 // 0th subitem is the item already drawn
1325 for (int index = 1; index < count; index++) {
1326 subItem = subItems [index];
1327 col = control.Columns [index];
1328 sub_item_rect.X = col.Rect.Left;
1329 sub_item_rect.Width = col.Wd;
1331 SolidBrush sub_item_back_br = null;
1332 SolidBrush sub_item_fore_br = null;
1333 Font sub_item_font = null;
1335 if (item.UseItemStyleForSubItems) {
1336 sub_item_back_br = this.ResPool.GetSolidBrush
1338 sub_item_fore_br = this.ResPool.GetSolidBrush
1340 sub_item_font = item.Font;
1343 sub_item_back_br = this.ResPool.GetSolidBrush
1344 (subItem.BackColor);
1345 sub_item_fore_br = this.ResPool.GetSolidBrush
1346 (subItem.ForeColor);
1347 sub_item_font = subItem.Font;
1350 // In case of fullrowselect, background is filled
1351 // for the entire rect above
1352 if (item.Selected && control.FullRowSelect) {
1353 if (subItem.Text != null && subItem.Text.Length > 0)
1354 dc.DrawString (subItem.Text, sub_item_font,
1355 this.ResPool.GetSolidBrush
1356 (this.ColorHilightText),
1357 sub_item_rect, format);
1360 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1361 if (subItem.Text != null && subItem.Text.Length > 0)
1362 dc.DrawString (subItem.Text, sub_item_font,
1364 sub_item_rect, format);
1366 sub_item_rect.X += col.Wd;
1373 public override Size ListViewCheckBoxSize {
1374 get { return new Size (16, 16); }
1377 public override int ListViewColumnHeaderHeight {
1381 public override int ListViewDefaultColumnWidth {
1385 public override int ListViewVerticalSpacing {
1389 public override int ListViewEmptyColumnWidth {
1393 public override int ListViewHorizontalSpacing {
1397 public override Size ListViewDefaultSize {
1398 get { return new Size (121, 97); }
1400 #endregion // ListView
1403 public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
1408 if (item.item.Visible == false)
1411 if (item.item.Separator == true) {
1412 item.rect.Height = SEPARATOR_HEIGHT / 2;
1413 item.rect.Width = -1;
1417 if (item.item.MeasureEventDefined) {
1418 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.pos);
1419 item.item.PerformMeasureItem (mi);
1420 item.rect.Height = mi.ItemHeight;
1421 item.rect.Width = mi.ItemWidth;
1426 size = dc.MeasureString (item.item.Text, ThemeEngine.Current.MenuFont);
1427 item.rect.Width = (int) size.Width;
1428 item.rect.Height = (int) size.Height;
1432 if (item.item.Shortcut != Shortcut.None && item.item.ShowShortcut) {
1433 item.item.XTab = ThemeEngine.Current.MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1434 size = dc.MeasureString (" " + item.item.GetShortCutText (), ThemeEngine.Current.MenuFont);
1435 item.rect.Width += MENU_TAB_SPACE + (int) size.Width;
1438 item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
1441 item.rect.Width += MENU_BAR_ITEMS_SPACE;
1442 x += item.rect.Width;
1445 if (item.rect.Height < ThemeEngine.Current.MenuHeight)
1446 item.rect.Height = ThemeEngine.Current.MenuHeight;
1450 // Updates the menu rect and returns the height
1451 public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width)
1456 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1458 MenuAPI.MENUITEM item;
1460 while (i < menu.items.Count) {
1462 item = (MenuAPI.MENUITEM) menu.items[i];
1463 CalcItemSize (dc, item, y, x, true);
1466 if (x + item.rect.Width > width) {
1468 y += item.rect.Height;
1473 x += item.rect.Width;
1474 item.item.MenuBar = true;
1476 if (y + item.rect.Height > menu.Height)
1477 menu.Height = item.rect.Height + y;
1485 public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
1491 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1494 while (start < menu.items.Count) {
1497 for (i = start; i < menu.items.Count; i++) {
1498 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
1500 if ((i != start) && (item.item.Break || item.item.BarBreak))
1503 CalcItemSize (dc, item, y, x, false);
1504 y += item.rect.Height;
1506 if (item.rect.Width > max)
1507 max = item.rect.Width;
1510 // Reemplace the -1 by the menu width (separators)
1511 for (n = start; n < i; n++, start++) {
1512 MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[n];
1513 item.rect.Width = max;
1516 if (y > menu.Height)
1528 menu.Width += SM_CXBORDER;
1529 menu.Height += SM_CYBORDER;
1532 // Draws a menu bar in a window
1533 public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
1535 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1536 Rectangle item_rect;
1538 if (menu.Height == 0)
1539 ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
1541 rect.Height = menu.Height;
1542 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (menu.Wnd.BackColor), rect);
1544 for (int i = 0; i < menu.items.Count; i++) {
1545 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1546 item_rect = it.rect;
1547 item_rect.X += rect.X;
1548 item_rect.Y += rect.Y;
1549 it.item.MenuHeight = menu.Height;
1550 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1551 item_rect, i, it.item.Status));
1556 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1558 StringFormat string_format;
1559 Rectangle rect_text = e.Bounds;
1561 if (item.Visible == false)
1565 string_format = string_format_menu_menubar_text;
1568 string_format = string_format_menu_text;
1571 if (item.Separator == true) {
1572 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1573 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
1575 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1576 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
1582 rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
1584 if (item.BarBreak) { /* Draw vertical break bar*/
1585 Rectangle rect = e.Bounds;
1588 rect.Height = item.MenuHeight - 6;
1590 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1591 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
1593 e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
1594 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
1600 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1601 color_text = ThemeEngine.Current.ColorHilightText;
1602 color_back = ThemeEngine.Current.ColorHilight;
1605 color_text = ThemeEngine.Current.ColorMenuText;
1606 color_back = ThemeEngine.Current.ColorMenu;
1609 /* Draw background */
1610 Rectangle rect_back = e.Bounds;
1612 rect_back.Width -=2;
1613 e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color_back), rect_back);
1616 e.Graphics.DrawString (item.Text, e.Font,
1617 ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1618 rect_text, string_format);
1620 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
1621 string str = item.GetShortCutText ();
1622 Rectangle rect = rect_text;
1624 rect.Width -= item.XTab;
1626 e.Graphics.DrawString (str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
1627 rect, string_format_menu_shortcut);
1631 ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font,
1632 Color.Black, rect_text, string_format);
1636 if (item.MenuBar == false && item.IsPopup) {
1638 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1639 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1640 Bitmap bmp = new Bitmap (cx, cy);
1641 Graphics gr = Graphics.FromImage (bmp);
1642 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1643 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
1644 bmp.MakeTransparent ();
1647 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
1648 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
1650 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
1651 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
1658 /* Draw checked or radio */
1659 if (item.MenuBar == false && item.Checked) {
1661 Rectangle area = e.Bounds;
1662 int cx = ThemeEngine.Current.MenuCheckSize.Width;
1663 int cy = ThemeEngine.Current.MenuCheckSize.Height;
1664 Bitmap bmp = new Bitmap (cx, cy);
1665 Graphics gr = Graphics.FromImage (bmp);
1666 Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
1668 if (item.RadioCheck)
1669 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
1671 ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
1673 bmp.MakeTransparent ();
1674 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
1681 public override void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect)
1683 MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
1685 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
1686 (ThemeEngine.Current.ColorMenu), cliparea);
1688 /* Draw menu borders */
1689 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1690 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
1692 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
1693 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
1695 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1696 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
1698 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1699 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
1701 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
1702 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
1704 dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
1705 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
1707 for (int i = 0; i < menu.items.Count; i++)
1708 if (cliparea.IntersectsWith (((MenuAPI.MENUITEM) menu.items[i]).rect)) {
1709 MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
1710 it.item.MenuHeight = menu.Height;
1711 it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
1712 it.rect, i, it.item.Status));
1718 #region MonthCalendar
1720 // draw the month calendar
1721 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
\r
1723 Rectangle client_rectangle = mc.ClientRectangle;
1724 Size month_size = mc.SingleMonthSize;
1725 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1726 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
1727 Size date_cell_size = (Size)((object)mc.date_cell_size);
1729 // draw the singlecalendars
1732 // adjust for the position of the specific month
1733 for (int i=0; i < mc.CalendarDimensions.Height; i++)
\r
1737 y_offset += month_size.Height + calendar_spacing.Height;
1739 // now adjust for x position
1740 for (int j=0; j < mc.CalendarDimensions.Width; j++)
\r
1744 x_offset += month_size.Width + calendar_spacing.Width;
1751 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
1752 if (month_rect.IntersectsWith (clip_rectangle)) {
1764 Rectangle bottom_rect = new Rectangle (
1766 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
1767 client_rectangle.Width,
1768 date_cell_size.Height + 2);
1769 // draw the today date if it's set
1770 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
\r
1772 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
1774 int today_offset = 5;
1775 if (mc.ShowTodayCircle)
\r
1777 Rectangle today_circle_rect = new Rectangle (
1778 client_rectangle.X + 5,
1779 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
1780 date_cell_size.Width,
1781 date_cell_size.Height);
1782 DrawTodayCircle (dc, today_circle_rect);
1783 today_offset += date_cell_size.Width + 5;
1785 // draw today's date
1786 StringFormat text_format = new StringFormat();
1787 text_format.LineAlignment = StringAlignment.Center;
1788 text_format.Alignment = StringAlignment.Near;
1789 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
1790 Rectangle today_rect = new Rectangle (
1791 today_offset + client_rectangle.X,
1792 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
1793 Math.Max(client_rectangle.Width - today_offset, 0),
1794 date_cell_size.Height);
1795 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
1799 // finally paint the borders of the calendars as required
1800 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
1801 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
1802 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
1803 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
1804 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
1806 Rectangle rect = new Rectangle (
1807 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
1809 calendar_spacing.Width,
1810 client_rectangle.Height);
1811 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1812 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1816 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
1817 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
1818 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
1819 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
1820 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
1822 Rectangle rect = new Rectangle (
1824 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
1825 client_rectangle.Width,
1826 calendar_spacing.Height);
1827 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
1828 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
1833 // draw the drop down border if need
1834 if (mc.owner != null) {
1835 Rectangle bounds = mc.ClientRectangle;
1836 if (clip_rectangle.Contains (mc.Location)) {
1837 // find out if top or left line to draw
1838 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1840 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
1842 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1843 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
1846 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
1847 // find out if bottom or right line to draw
1848 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
1849 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
1851 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
1852 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
1858 // darws a single part of the month calendar (with one month)
1859 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
\r
1861 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
1862 Size title_size = (Size)((object)mc.title_size);
1863 Size date_cell_size = (Size)((object)mc.date_cell_size);
1864 DateTime current_month = (DateTime)((object)mc.current_month);
1866 // set up some standard string formating variables
1867 StringFormat text_format = new StringFormat();
1868 text_format.LineAlignment = StringAlignment.Center;
1869 text_format.Alignment = StringAlignment.Center;
1872 // draw the title back ground
1873 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
1874 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
1875 if (title_rect.IntersectsWith (clip_rectangle)) {
1876 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
1878 string title_text = this_month.ToString ("MMMM yyyy");
1879 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
1881 // draw previous and next buttons if it's time
1882 if (row == 0 && col == 0)
\r
1884 // draw previous button
1885 DrawMonthCalendarButton (
1891 (System.Drawing.Size)((object)mc.button_size),
1894 if (row == 0 && col == mc.CalendarDimensions.Width-1)
\r
1897 DrawMonthCalendarButton (
1903 (System.Drawing.Size)((object)mc.button_size),
1908 // set the week offset and draw week nums if needed
1909 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
1910 Rectangle day_name_rect = new Rectangle(
1912 rectangle.Y + title_size.Height,
1913 (7 + col_offset) * date_cell_size.Width,
1914 date_cell_size.Height);
1915 if (day_name_rect.IntersectsWith (clip_rectangle)) {
1916 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
1917 // draw the day names
1918 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
1919 for (int i=0; i < 7; i++)
\r
1921 int position = i - (int) first_day_of_week;
1922 if (position < 0)
\r
1924 position = 7 + position;
1927 Rectangle day_rect = new Rectangle(
1928 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
1930 date_cell_size.Width,
1931 date_cell_size.Height);
1932 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
1935 // draw the vertical divider
1936 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
1938 ResPool.GetPen (mc.ForeColor),
1939 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
1940 rectangle.Y + vert_divider_y,
1941 rectangle.Right - mc.divider_line_offset,
1942 rectangle.Y + vert_divider_y);
1946 // draw the actual date items in the grid (including the week numbers)
1947 Rectangle date_rect = new Rectangle (
1949 rectangle.Y + title_size.Height + date_cell_size.Height,
1950 date_cell_size.Width,
1951 date_cell_size.Height);
1952 int month_row_count = 0;
1953 bool draw_week_num_divider = false;
1954 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
1955 for (int i=0; i < 6; i++)
\r
1957 // establish if this row is in our clip_area
1958 Rectangle row_rect = new Rectangle (
1960 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
1961 date_cell_size.Width * 7,
1962 date_cell_size.Height);
1963 if (mc.ShowWeekNumbers) {
1964 row_rect.Width += date_cell_size.Width;
1967 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
1969 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
1971 // establish if this is a valid week to draw
1972 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
1973 month_row_count = i;
1976 // draw the week number if required
1977 if (mc.ShowWeekNumbers && month_row_count == i) {
1978 if (!draw_week_num_divider) {
1979 draw_week_num_divider = draw_row;
1981 // get the week for this row
1982 int week = mc.GetWeekOfYear (current_date);
1988 ResPool.GetSolidBrush (mc.TitleBackColor),
1992 date_rect.Offset(date_cell_size.Width, 0);
1995 // only draw the days if we have to
1996 if(month_row_count == i) {
1997 for (int j=0; j < 7; j++)
\r
2000 DrawMonthCalendarDate (
2011 current_date = current_date.AddDays(1);
2012 date_rect.Offset(date_cell_size.Width, 0);
2015 // shift the rectangle down one row
2016 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2017 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2021 // month_row_count is zero based, so add one
2024 // draw week numbers if required
2025 if (draw_week_num_divider) {
2028 ResPool.GetPen (mc.ForeColor),
2029 rectangle.X + date_cell_size.Width - 1,
2030 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2031 rectangle.X + date_cell_size.Width - 1,
2032 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2036 // draws the pervious or next button
2037 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
\r
2039 bool is_clicked = false;
2040 Rectangle button_rect;
2041 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2042 Point[] arrow_path = new Point[3];
2043 // prepare the button
2046 is_clicked = mc.is_previous_clicked;
2047 button_rect = new Rectangle (
2048 rectangle.X + 1 + x_offset,
2049 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2050 Math.Max(button_size.Width - 1, 0),
2051 Math.Max(button_size.Height - 1, 0));
2052 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2053 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2055 arrow_rect.Offset(1,1);
2057 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2058 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2059 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2063 is_clicked = mc.is_next_clicked;
2064 button_rect = new Rectangle (
2065 rectangle.Right - 1 - x_offset - button_size.Width,
2066 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2067 Math.Max(button_size.Width - 1, 0),
2068 Math.Max(button_size.Height - 1, 0));
2069 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2070 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2072 arrow_rect.Offset(1,1);
2074 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2075 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2076 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2079 // fill the background
2080 dc.FillRectangle (SystemBrushes.Control, button_rect);
2083 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2086 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
2089 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2093 // draws one day in the calendar grid
2094 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2095 Color date_color = mc.ForeColor;
2096 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2098 // find out if we are the lead of the first calendar or the trail of the last calendar
2099 if (date.Year != month.Year || date.Month != month.Month) {
2100 DateTime check_date = month.AddMonths (-1);
2101 // check if it's the month before
2102 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2103 date_color = mc.TrailingForeColor;
2105 // check if it's the month after
2106 check_date = month.AddMonths (1);
2107 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2108 date_color = mc.TrailingForeColor;
2114 date_color = mc.ForeColor;
2118 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2119 // see if the date is in the start of selection
2120 date_color = mc.BackColor;
2121 // draw the left hand of the back ground
2122 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2123 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2124 } else if (date == mc.SelectionStart) {
2125 // see if the date is in the start of selection
2126 date_color = mc.BackColor;
2127 // draw the left hand of the back ground
2128 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2129 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2130 // fill the other side as a straight rect
2131 if (date < mc.SelectionEnd)
\r
2133 // use rectangle instead of rectangle to go all the way to edge of rect
2134 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2135 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2136 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2138 } else if (date == mc.SelectionEnd) {
2139 // see if it is the end of selection
2140 date_color = mc.BackColor;
2141 // draw the left hand of the back ground
2142 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2143 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2144 // fill the other side as a straight rect
2145 if (date > mc.SelectionStart) {
2146 selection_rect.X = rectangle.X;
2147 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2148 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2150 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2151 // now see if it's in the middle
2152 date_color = mc.BackColor;
2153 // draw the left hand of the back ground
2154 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2155 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2158 // set up some standard string formating variables
2159 StringFormat text_format = new StringFormat();
2160 text_format.LineAlignment = StringAlignment.Center;
2161 text_format.Alignment = StringAlignment.Center;
2164 // establish if it's a bolded font
2166 if (mc.IsBoldedDate (date)) {
2167 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2172 // just draw the date now
2173 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2175 // today circle if needed
2176 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2177 DrawTodayCircle (dc, interior);
2180 // draw the selection grid
2181 if (mc.is_date_clicked && mc.clicked_date == date) {
2182 using (Pen pen = new Pen (Color.Black, 1) ) {
2183 pen.DashStyle = DashStyle.Dot;
2184 dc.DrawRectangle (pen, interior);
2189 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2190 Color circle_color = Color.FromArgb (248, 0, 0);
2191 // draw the left hand of the circle
2192 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2193 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2194 Point [] curve_points = new Point [3];
2195 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2196 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2197 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2199 using (Pen pen = new Pen (circle_color, 2)) {
2200 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2201 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2202 dc.DrawCurve (pen, curve_points);
2203 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2207 #endregion // MonthCalendar
2210 public override Size PanelDefaultSize {
2212 return new Size (200, 100);
2218 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2219 Rectangle client = pb.ClientRectangle;
2221 if (pb.Image != null) {
2222 switch (pb.SizeMode) {
2223 case PictureBoxSizeMode.StretchImage:
2224 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2227 case PictureBoxSizeMode.CenterImage:
2228 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2232 dc.DrawImage(pb.Image, 0, 0);
2236 CPDrawBorderStyle (dc, client, pb.BorderStyle);
2239 public override Size PictureBoxDefaultSize {
2241 return new Size (100, 50);
2244 #endregion // PictureBox
2247 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2249 Rectangle block_rect;
2250 Rectangle client_area = ctrl.client_area;
2251 int space_betweenblocks = 2;
2256 block_width = ((client_area.Height) * 2 ) / 3;
2257 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2258 increment = block_width + space_betweenblocks;
2261 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All & ~Border3DSide.Middle, ColorButtonFace);
2264 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2265 while ((block_rect.X - client_area.X) < barpos_pixels) {
2267 if (clip_rect.IntersectsWith (block_rect) == true) {
2268 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2271 block_rect.X += increment;
2275 public override Size ProgressBarDefaultSize {
2277 return new Size (100, 23);
2281 #endregion // ProgressBar
2284 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2285 StringFormat text_format;
2286 Rectangle client_rectangle;
2287 Rectangle text_rectangle;
2288 Rectangle radiobutton_rectangle;
2290 int radiobutton_size = 12;
2291 int radiobutton_space = 4;
2293 client_rectangle = radio_button.ClientRectangle;
2294 text_rectangle = client_rectangle;
2295 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2297 text_format = new StringFormat();
2298 text_format.Alignment = StringAlignment.Near;
2299 text_format.LineAlignment = StringAlignment.Center;
2300 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2302 /* Calculate the position of text and checkbox rectangle */
2303 if (radio_button.appearance!=Appearance.Button) {
2304 switch(radio_button.radiobutton_alignment) {
2305 case ContentAlignment.BottomCenter: {
2306 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2307 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2308 text_rectangle.X=client_rectangle.X;
2309 text_rectangle.Width=client_rectangle.Width;
2310 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2314 case ContentAlignment.BottomLeft: {
2315 radiobutton_rectangle.X=client_rectangle.Left;
2316 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2317 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2318 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2322 case ContentAlignment.BottomRight: {
2323 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2324 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2325 text_rectangle.X=client_rectangle.X;
2326 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2330 case ContentAlignment.MiddleCenter: {
2331 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2332 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2333 text_rectangle.X=client_rectangle.X;
2334 text_rectangle.Width=client_rectangle.Width;
2339 case ContentAlignment.MiddleLeft: {
2340 radiobutton_rectangle.X=client_rectangle.Left;
2341 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2342 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2343 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2347 case ContentAlignment.MiddleRight: {
2348 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2349 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2350 text_rectangle.X=client_rectangle.X;
2351 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2355 case ContentAlignment.TopCenter: {
2356 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2357 radiobutton_rectangle.Y=client_rectangle.Top;
2358 text_rectangle.X=client_rectangle.X;
2359 text_rectangle.Y=radiobutton_size+radiobutton_space;
2360 text_rectangle.Width=client_rectangle.Width;
2361 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2365 case ContentAlignment.TopLeft: {
2366 radiobutton_rectangle.X=client_rectangle.Left;
2367 radiobutton_rectangle.Y=client_rectangle.Top;
2368 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2369 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2373 case ContentAlignment.TopRight: {
2374 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2375 radiobutton_rectangle.Y=client_rectangle.Top;
2376 text_rectangle.X=client_rectangle.X;
2377 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2382 text_rectangle.X=client_rectangle.X;
2383 text_rectangle.Width=client_rectangle.Width;
2386 /* Set the horizontal alignment of our text */
2387 switch(radio_button.text_alignment) {
2388 case ContentAlignment.BottomLeft:
2389 case ContentAlignment.MiddleLeft:
2390 case ContentAlignment.TopLeft: {
2391 text_format.Alignment=StringAlignment.Near;
2395 case ContentAlignment.BottomCenter:
2396 case ContentAlignment.MiddleCenter:
2397 case ContentAlignment.TopCenter: {
2398 text_format.Alignment=StringAlignment.Center;
2402 case ContentAlignment.BottomRight:
2403 case ContentAlignment.MiddleRight:
2404 case ContentAlignment.TopRight: {
2405 text_format.Alignment=StringAlignment.Far;
2410 /* Set the vertical alignment of our text */
2411 switch(radio_button.text_alignment) {
2412 case ContentAlignment.TopLeft:
2413 case ContentAlignment.TopCenter:
2414 case ContentAlignment.TopRight: {
2415 text_format.LineAlignment=StringAlignment.Near;
2419 case ContentAlignment.BottomLeft:
2420 case ContentAlignment.BottomCenter:
2421 case ContentAlignment.BottomRight: {
2422 text_format.LineAlignment=StringAlignment.Far;
2426 case ContentAlignment.MiddleLeft:
2427 case ContentAlignment.MiddleCenter:
2428 case ContentAlignment.MiddleRight: {
2429 text_format.LineAlignment=StringAlignment.Center;
2434 ButtonState state = ButtonState.Normal;
2435 if (radio_button.FlatStyle == FlatStyle.Flat) {
2436 state |= ButtonState.Flat;
2439 if (radio_button.Checked) {
2440 state |= ButtonState.Checked;
2445 sb=new SolidBrush(radio_button.BackColor);
2446 dc.FillRectangle(sb, radio_button.ClientRectangle);
2451 if (radio_button.appearance==Appearance.Button) {
2452 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2453 DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
2455 CPDrawButton(dc, radio_button.ClientRectangle, state);
2458 // establish if we are rendering a flat style of some sort
2459 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2460 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2462 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
2466 // offset the text if it's pressed and a button
2467 if (radio_button.Appearance == Appearance.Button) {
2468 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
2469 text_rectangle.X ++;
2470 text_rectangle.Y ++;
2473 text_rectangle.Inflate(-4,-4);
2476 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
2477 dc.DrawString (radio_button.Text, radio_button.Font, ThemeEngine.Current.ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
2479 if (radio_button.Enabled) {
2480 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
2481 dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
2482 } else if (radio_button.FlatStyle == FlatStyle.Flat) {
2483 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
2485 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorButtonText, text_rectangle, text_format);
2488 if (radio_button.Focused) {
2489 if (radio_button.FlatStyle != FlatStyle.Flat) {
2490 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
2492 dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
2497 // renders a radio button with the Flat and Popup FlatStyle
2498 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2502 if (radio_button.Enabled) {
2503 // draw the outer flatstyle arcs
2504 if (radio_button.FlatStyle == FlatStyle.Flat) {
2505 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
2507 // fill in the area depending on whether or not the mouse is hovering
2508 if (radio_button.is_entered && radio_button.Capture) {
2509 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2511 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2514 // must be a popup radio button
2516 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
2518 if (radio_button.is_entered || radio_button.Capture) {
2519 // draw the popup 3d button knob
2520 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2522 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
2523 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
2526 // just draw lighter flatstyle outer circle
2527 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorButtonFace)), rectangle, 0, 359);
2532 // fill control background color regardless of actual backcolor
2533 graphics.FillPie (ResPool.GetSolidBrush (this.ColorButtonFace), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2534 // draw the ark as control dark
2535 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorButtonFace)), rectangle, 0, 359);
2539 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2540 if (radio_button.Checked) {
2541 SolidBrush buttonBrush;
2543 if (!radio_button.Enabled) {
2544 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorButtonFace));
2545 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
2546 buttonBrush = ResPool.GetSolidBrush (this.ColorButtonText);
2548 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
2550 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
2554 public override Size RadioButtonDefaultSize {
2556 return new Size (104,24);
2559 #endregion // RadioButton
2562 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
2564 int scrollbutton_width = bar.scrollbutton_width;
2565 int scrollbutton_height = bar.scrollbutton_height;
2566 Rectangle first_arrow_area;
2567 Rectangle second_arrow_area;
2568 Rectangle thumb_pos;
2570 thumb_pos = bar.ThumbPos;
2573 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
2574 bar.FirstArrowArea = first_arrow_area;
2576 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
2577 bar.SecondArrowArea = second_arrow_area;
2579 thumb_pos.Width = bar.Width;
2580 bar.ThumbPos = thumb_pos;
2583 if (clip.IntersectsWith (first_arrow_area))
2584 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
2585 if (clip.IntersectsWith (second_arrow_area))
2586 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
2589 switch (bar.thumb_moving) {
2590 case ScrollBar.ThumbMoving.None: {
2591 Rectangle r = new Rectangle (0,
2592 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
2593 Rectangle intersect = Rectangle.Intersect (clip, r);
2595 if (intersect != Rectangle.Empty) {
2596 Brush h = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
2597 dc.FillRectangle (h, intersect);
2601 case ScrollBar.ThumbMoving.Forward: {
2602 Rectangle r = new Rectangle (0, scrollbutton_height,
2603 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2604 Rectangle intersect = Rectangle.Intersect (clip, r);
2606 if (intersect != Rectangle.Empty)
2607 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2610 r.Y = thumb_pos.Y + thumb_pos.Height;
2611 r.Width = bar.ClientRectangle.Width;
2612 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2614 intersect = Rectangle.Intersect (clip, r);
2615 if (intersect != Rectangle.Empty)
2616 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2620 case ScrollBar.ThumbMoving.Backwards: {
2621 Rectangle r = new Rectangle (0, scrollbutton_height,
2622 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
2623 Rectangle intersect = Rectangle.Intersect (clip, r);
2625 if (intersect != Rectangle.Empty)
2626 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2629 r.Y = thumb_pos.Y + thumb_pos.Height;
2630 r.Width = bar.ClientRectangle.Width;
2631 r.Height = bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
2633 intersect = Rectangle.Intersect (clip, r);
2634 if (intersect != Rectangle.Empty)
2635 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2643 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
2644 bar.FirstArrowArea = first_arrow_area;
2646 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
2647 bar.SecondArrowArea = second_arrow_area;
2649 thumb_pos.Height = bar.Height;
2650 bar.ThumbPos = thumb_pos;
2653 if (clip.IntersectsWith (first_arrow_area))
2654 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
2655 if (clip.IntersectsWith (second_arrow_area))
2656 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
2659 switch (bar.thumb_moving) {
2660 case ScrollBar.ThumbMoving.None: {
2661 Rectangle r = new Rectangle (scrollbutton_width,
2662 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
2663 Rectangle intersect = Rectangle.Intersect (clip, r);
2665 if (intersect != Rectangle.Empty)
2666 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2670 case ScrollBar.ThumbMoving.Forward: {
2671 Rectangle r = new Rectangle (scrollbutton_width, 0,
2672 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2673 Rectangle intersect = Rectangle.Intersect (clip, r);
2675 if (intersect != Rectangle.Empty)
2676 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2678 r.X = thumb_pos.X + thumb_pos.Width;
2680 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2681 r.Height = bar.ClientRectangle.Height;
2683 intersect = Rectangle.Intersect (clip, r);
2684 if (intersect != Rectangle.Empty)
2685 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2689 case ScrollBar.ThumbMoving.Backwards: {
2690 Rectangle r = new Rectangle (scrollbutton_width, 0,
2691 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
2692 Rectangle intersect = Rectangle.Intersect (clip, r);
2694 if (intersect != Rectangle.Empty)
2695 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
2697 r.X = thumb_pos.X + thumb_pos.Width;
2699 r.Width = bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
2700 r.Height = bar.ClientRectangle.Height;
2702 intersect = Rectangle.Intersect (clip, r);
2703 if (intersect != Rectangle.Empty)
2704 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
2711 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith (thumb_pos))
2712 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
2715 public override int ScrollBarButtonSize {
2718 #endregion // ScrollBar
2721 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
2722 Rectangle area = sb.ClientRectangle;
2723 int horz_border = 2;
2724 int vert_border = 2;
2726 dc.FillRectangle (GetControlBackBrush (sb.BackColor), clip);
2728 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
2729 string text = sb.Text;
2730 StringFormat string_format = new StringFormat ();
2731 string_format.Trimming = StringTrimming.Character;
2732 string_format.FormatFlags = StringFormatFlags.NoWrap;
2734 if (text [0] == '\t') {
2735 string_format.Alignment = StringAlignment.Center;
2736 text = text.Substring (1);
2737 if (text [0] == '\t') {
2738 string_format.Alignment = StringAlignment.Far;
2739 text = text.Substring (1);
2743 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
2744 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
2745 } else if (sb.ShowPanels) {
2746 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
2747 int prev_x = area.X + horz_border;
2748 int y = area.Y + vert_border;
2749 for (int i = 0; i < sb.Panels.Count; i++) {
2750 Rectangle pr = new Rectangle (prev_x, y,
2751 sb.Panels [i].Width, area.Height);
2752 prev_x += pr.Width + StatusBarHorzGapWidth;
2753 if (pr.IntersectsWith (clip))
2754 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
2759 CPDrawSizeGrip (dc, ColorButtonFace, area);
2764 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
2765 SolidBrush br_forecolor, StatusBarPanel panel) {
2766 int border_size = 3; // this is actually const, even if the border style is none
2768 area.Height -= border_size;
2769 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
2770 Border3DStyle border_style = Border3DStyle.SunkenInner;
2771 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
2772 border_style = Border3DStyle.RaisedOuter;
2773 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
2776 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
2777 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
2778 dc, panel.Parent.Font, area, index, DrawItemState.Default,
2779 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
2780 panel.Parent.OnDrawItemInternal (e);
2784 int left = area.Left;
2785 if (panel.Icon != null) {
2787 dc.DrawIcon (panel.Icon, left, area.Top);
2788 left += panel.Icon.Width;
2791 if (panel.Text == String.Empty)
2794 string text = panel.Text;
2795 StringFormat string_format = new StringFormat ();
2796 string_format.Trimming = StringTrimming.Character;
2797 string_format.FormatFlags = StringFormatFlags.NoWrap;
2799 if (text [0] == '\t') {
2800 string_format.Alignment = StringAlignment.Center;
2801 text = text.Substring (1);
2802 if (text [0] == '\t') {
2803 string_format.Alignment = StringAlignment.Far;
2804 text = text.Substring (1);
2808 int x = left + border_size;
2809 int y = border_size + 2;
2810 Rectangle r = new Rectangle (x, y,
2811 area.Right - x - border_size,
2812 area.Bottom - y - border_size);
2814 dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
2817 public override int StatusBarSizeGripWidth {
2821 public override int StatusBarHorzGapWidth {
2825 public override Size StatusBarDefaultSize {
2827 return new Size (100, 22);
2830 #endregion // StatusBar
2832 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
2834 // Do we need to fill the back color? It can't be changed...
2835 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
2836 Rectangle panel_rect = GetTabPanelRectExt (tab);
2838 if (tab.Appearance == TabAppearance.Normal) {
2839 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorButtonFace);
2840 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2843 if (tab.Alignment == TabAlignment.Top) {
2844 for (int r = tab.TabPages.Count; r > 0; r--) {
2845 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2846 if (i == tab.SelectedIndex)
2848 if (r != tab.TabPages [i].Row)
2850 Rectangle rect = tab.GetTabRect (i);
2851 if (!rect.IntersectsWith (area))
2853 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2857 for (int r = 0; r < tab.TabPages.Count; r++) {
2858 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
2859 if (i == tab.SelectedIndex)
2861 if (r != tab.TabPages [i].Row)
2863 Rectangle rect = tab.GetTabRect (i);
2864 if (!rect.IntersectsWith (area))
2866 DrawTab (dc, tab.TabPages [i], tab, rect, false);
2871 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
2872 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
2873 if (rect.IntersectsWith (area))
2874 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
2877 if (tab.ShowSlider) {
2878 Rectangle right = GetTabControlRightScrollRect (tab);
2879 Rectangle left = GetTabControlLeftScrollRect (tab);
2880 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
2881 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
2885 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
2887 switch (tab.Alignment) {
2888 case TabAlignment.Top:
2889 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
2891 Rectangle panel_rect = GetTabPanelRectExt (tab);
2892 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
2896 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
2898 switch (tab.Alignment) {
2899 case TabAlignment.Top:
2900 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
2902 Rectangle panel_rect = GetTabPanelRectExt (tab);
2903 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
2907 public override Size TabControlDefaultItemSize {
2908 get { return new Size (42, 21); }
2911 public override Point TabControlDefaultPadding {
2912 get { return new Point (6, 3); }
2915 public override int TabControlMinimumTabWidth {
2919 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
2921 Rectangle ext = GetTabPanelRectExt (tab);
2922 // Account for border size
2923 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
2926 public override Size TabControlGetSpacing (TabControl tab) {
2927 switch (tab.Appearance) {
2928 case TabAppearance.Normal:
2929 return new Size (1, -2);
2930 case TabAppearance.Buttons:
2931 return new Size (3, 3);
2932 case TabAppearance.FlatButtons:
2933 return new Size (9, 3);
2935 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
2939 private Rectangle GetTabPanelRectExt (TabControl tab)
2941 // Offset the tab from the top corner
2942 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
2943 tab.ClientRectangle.Y,
2944 tab.ClientRectangle.Width - 2,
2945 tab.ClientRectangle.Height - 1);
2947 if (tab.TabCount == 0)
2950 int spacing = TabControlGetSpacing (tab).Height;
2951 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
2953 switch (tab.Alignment) {
2954 case TabAlignment.Left:
2956 res.Width -= offset;
2958 case TabAlignment.Right:
2959 res.Width -= offset;
2961 case TabAlignment.Top:
2963 res.Height -= offset;
2965 case TabAlignment.Bottom:
2966 res.Height -= offset;
2973 private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
2975 int FlatButtonSpacing = 8;
2977 int res = bounds.Width;
2979 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
2981 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
2983 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2986 if (tab.Appearance == TabAppearance.FlatButtons) {
2987 int width = bounds.Width;
2988 bounds.Width += (FlatButtonSpacing - 2);
2990 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
2991 bounds.Width = width;
2995 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
2996 } else if (tab.Appearance != TabAppearance.FlatButtons) {
2997 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
3000 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3002 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
3004 switch (tab.Alignment) {
3006 case TabAlignment.Top:
3009 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3011 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3012 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3013 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3015 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3016 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3017 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3019 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3021 if (page.Text != String.Empty) {
3022 StringFormat string_format = new StringFormat ();
3023 string_format.Alignment = StringAlignment.Center;
3024 string_format.LineAlignment = StringAlignment.Center;
3025 string_format.FormatFlags = StringFormatFlags.NoWrap;
3027 dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
3033 case TabAlignment.Bottom:
3035 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3037 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3038 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3040 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3041 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3043 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3044 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3045 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3047 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3049 if (page.Text != String.Empty) {
3050 StringFormat string_format = new StringFormat ();
3051 string_format.Alignment = StringAlignment.Center;
3052 string_format.LineAlignment = StringAlignment.Center;
3053 string_format.FormatFlags = StringFormatFlags.NoWrap;
3055 dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
3061 case TabAlignment.Left:
3063 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3065 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3066 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3067 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3069 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3071 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3072 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3074 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3076 if (page.Text != String.Empty) {
3077 StringFormat string_format = new StringFormat ();
3078 // Flip the text around
3079 string_format.Alignment = StringAlignment.Center;
3080 string_format.LineAlignment = StringAlignment.Center;
3081 string_format.FormatFlags = StringFormatFlags.NoWrap;
3082 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3083 int wo = interior.Width / 2;
3084 int ho = interior.Height / 2;
3085 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3086 dc.RotateTransform (180);
3087 dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
3088 dc.ResetTransform ();
3094 // TabAlignment.Right
3096 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
3098 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3099 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3101 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3102 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3104 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3105 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3107 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3109 if (page.Text != String.Empty) {
3110 StringFormat string_format = new StringFormat ();
3111 string_format.Alignment = StringAlignment.Center;
3112 string_format.LineAlignment = StringAlignment.Center;
3113 string_format.FormatFlags = StringFormatFlags.NoWrap;
3114 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3116 dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
3125 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3132 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
3133 StringFormat format = new StringFormat ();
3134 format.Trimming = StringTrimming.EllipsisWord;
3135 if (control.textAlignment == ToolBarTextAlign.Underneath) {
3136 format.LineAlignment = StringAlignment.Center;
3137 format.Alignment = StringAlignment.Center;
3139 format.LineAlignment = StringAlignment.Center;
3140 format.Alignment = StringAlignment.Near;
3143 // Exclude the area for divider
3144 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
3145 control.Width, control.Height - ToolBarGripWidth / 2);
3146 bool flat = (control.Appearance == ToolBarAppearance.Flat);
3147 dc.FillRectangle (SystemBrushes.Control, paint_area);
3148 CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
3150 if (control.Divider)
3151 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
3153 foreach (ToolBarButton button in control.Buttons) {
3156 Rectangle buttonArea = button.Rectangle;
3157 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
3158 Rectangle txtRect = buttonArea; // rect to draw the text
3159 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
3161 // calculate different rects and draw the frame if its not separator button
3162 if (button.Style != ToolBarButtonStyle.Separator) {
3163 /* Adjustment for drop down arrow */
3164 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
3165 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
3166 ddRect.Y = buttonArea.Y;
3167 ddRect.Width = this.ToolBarDropDownWidth;
3168 ddRect.Height = buttonArea.Height;
3171 // calculate txtRect and imgRect, if imageIndex and imageList are present
3172 if (button.ImageIndex > -1 && control.ImageList != null) {
3173 if (button.ImageIndex < control.ImageList.Images.Count)
3174 image = control.ImageList.Images [button.ImageIndex];
3175 // draw the image at the centre if textalignment is underneath
3176 if (control.TextAlign == ToolBarTextAlign.Underneath) {
3177 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
3178 - control.ImageSize.Width) / 2)
3179 + this.ToolBarImageGripWidth;
3180 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3181 imgRect.Width = control.ImageSize.Width;
3182 imgRect.Height = control.ImageSize.Height;
3184 txtRect.X = buttonArea.X;
3185 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
3186 txtRect.Width = buttonArea.Width - ddRect.Width;
3187 txtRect.Height = buttonArea.Height - imgRect.Height
3188 - 2 * this.ToolBarImageGripWidth;
3191 imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
3192 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3193 imgRect.Width = control.ImageSize.Width;
3194 imgRect.Height = control.ImageSize.Height;
3196 txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
3197 txtRect.Y = buttonArea.Y;
3198 txtRect.Width = buttonArea.Width - imgRect.Width
3199 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
3200 txtRect.Height = buttonArea.Height;
3203 /* Draw the button frame, only if it is not a separator */
3205 if (button.Pushed || button.Pressed) {
3206 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
3207 } else if (button.Hilight) {
3208 dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
3209 if (! ddRect.IsEmpty) {
3210 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
3211 ddRect.Y + ddRect.Height);
3212 buttonArea.Width -= this.ToolBarDropDownWidth;
3216 else { // normal toolbar
3217 if (button.Pushed || button.Pressed) {
3218 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
3219 Border3DSide.All, ColorButtonFace);
3220 if (! ddRect.IsEmpty) {
3221 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
3222 Border3DSide.Left, ColorButtonFace);
3223 buttonArea.Width -= this.ToolBarDropDownWidth;
3227 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
3228 Border3DSide.All, ColorButtonFace);
3229 if (! ddRect.IsEmpty) {
3230 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
3231 Border3DSide.Left, ColorButtonFace);
3232 buttonArea.Width -= this.ToolBarDropDownWidth;
3237 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
3238 imgRect, image, txtRect, ddRect, flat);
3242 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
3243 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
3244 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
3245 if (! button.Visible)
3248 switch (button.Style) {
3250 case ToolBarButtonStyle.Separator:
3251 // separator is drawn only in the case of flat appearance
3253 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
3254 buttonArea.X + 1, buttonArea.Height);
3255 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
3256 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
3257 /* draw a horizontal separator */
3258 if (button.Wrapper) {
3259 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
3260 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
3261 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
3262 y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
3267 case ToolBarButtonStyle.ToggleButton:
3268 Rectangle toggleArea = Rectangle.Empty;
3269 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
3270 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
3271 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
3272 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
3273 if (button.PartialPush && button.Pushed) {
3274 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3275 if (! imgRect.IsEmpty) {
3276 if (button.Enabled && image != null)
3277 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3278 imgRect.Height, button.ImageIndex);
3280 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
3281 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3282 Border3DSide.Right | Border3DSide.Bottom);
3286 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3288 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
3291 else if (button.PartialPush) {
3292 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
3293 if (! imgRect.IsEmpty) {
3294 if (button.Enabled && image != null)
3295 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3296 imgRect.Height, button.ImageIndex);
3298 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
3299 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3300 Border3DSide.Right | Border3DSide.Bottom);
3304 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3306 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3310 else if (button.Pushed) {
3311 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
3312 if (! imgRect.IsEmpty) {
3313 if (button.Enabled && image != null)
3314 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3315 imgRect.Height, button.ImageIndex);
3317 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
3318 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3319 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3323 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3325 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3330 dc.FillRectangle (SystemBrushes.Control, toggleArea);
3331 if (! imgRect.IsEmpty) {
3332 if (button.Enabled && image != null)
3333 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
3334 imgRect.Height, button.ImageIndex);
3336 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
3337 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3338 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3342 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3344 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3349 case ToolBarButtonStyle.DropDownButton:
3350 // draw the dropdown arrow
3351 if (! ddRect.IsEmpty) {
3352 PointF [] vertices = new PointF [3];
3353 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
3354 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3355 vertices [0].Y = ddCenter.Y;
3356 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3357 vertices [1].Y = ddCenter.Y;
3358 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3359 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
3360 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3362 goto case ToolBarButtonStyle.PushButton;
3364 case ToolBarButtonStyle.PushButton:
3365 if (! imgRect.IsEmpty){
3366 if (button.Enabled && image != null)
3367 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
3370 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
3371 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
3372 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3376 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
3378 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
3384 // Grip width for the ToolBar
3385 public override int ToolBarGripWidth {
3389 // Grip width for the Image on the ToolBarButton
3390 public override int ToolBarImageGripWidth {
3394 // width of the separator
3395 public override int ToolBarSeparatorWidth {
3399 // width of the dropdown arrow rect
3400 public override int ToolBarDropDownWidth {
3404 // width for the dropdown arrow on the ToolBarButton
3405 public override int ToolBarDropDownArrowWidth {
3409 // height for the dropdown arrow on the ToolBarButton
3410 public override int ToolBarDropDownArrowHeight {
3414 public override Size ToolBarDefaultSize {
3416 return new Size (100, 42);
3419 #endregion // ToolBar
3422 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3423 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
3424 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
3425 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3428 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3431 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3432 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
3434 #endregion // ToolTip
3437 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3438 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3439 float ticks, int value_pos, bool mouse_value) {
3441 Point toptick_startpoint = new Point ();
3442 Point bottomtick_startpoint = new Point ();
3443 Point channel_startpoint = new Point ();
3445 float pixels_betweenticks;
3446 const int space_from_right = 8;
3447 const int space_from_left = 8;
3448 Rectangle area = tb.ClientRectangle;
3450 switch (tb.TickStyle) {
3451 case TickStyle.BottomRight:
3452 case TickStyle.None:
3453 channel_startpoint.Y = 8;
3454 channel_startpoint.X = 9;
3455 bottomtick_startpoint.Y = 13;
3456 bottomtick_startpoint.X = 24;
3458 case TickStyle.TopLeft:
3459 channel_startpoint.Y = 8;
3460 channel_startpoint.X = 19;
3461 toptick_startpoint.Y = 13;
3462 toptick_startpoint.X = 8;
3464 case TickStyle.Both:
3465 channel_startpoint.Y = 8;
3466 channel_startpoint.X = 18;
3467 bottomtick_startpoint.Y = 13;
3468 bottomtick_startpoint.X = 32;
3469 toptick_startpoint.Y = 13;
3470 toptick_startpoint.X = 8;
3476 thumb_area.X = area.X + channel_startpoint.X;
3477 thumb_area.Y = area.Y + channel_startpoint.Y;
3478 thumb_area.Height = area.Height - space_from_right - space_from_left;
3479 thumb_area.Width = 4;
3482 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3483 1, thumb_area.Height);
3485 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
3486 1, thumb_area.Height);
3488 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
3489 1, thumb_area.Height);
3491 pixel_len = thumb_area.Height - 11;
3492 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3494 /* Convert thumb position from mouse position to value*/
3497 if (value_pos >= channel_startpoint.Y)
3498 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
3502 if (value_pos + tb.Minimum > tb.Maximum)
3503 value_pos = tb.Maximum - tb.Minimum;
3505 tb.Value = value_pos + tb.Minimum;
3508 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
3510 /* Draw thumb fixed 10x22 size */
3511 thumb_pos.Width = 10;
3512 thumb_pos.Height = 22;
3514 switch (tb.TickStyle) {
3515 case TickStyle.BottomRight:
3516 case TickStyle.None: {
3517 thumb_pos.X = channel_startpoint.X - 8;
3519 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3520 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3521 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3523 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3524 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3526 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
3527 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
3529 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
3530 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
3531 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
3532 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
3536 case TickStyle.TopLeft: {
3537 thumb_pos.X = channel_startpoint.X - 10;
3539 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
3540 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
3542 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
3543 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
3544 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
3546 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
3547 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
3548 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
3550 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
3551 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
3552 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
3553 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
3558 case TickStyle.Both: {
3559 thumb_pos.X = area.X + 10;
3560 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
3561 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
3563 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
3564 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
3566 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
3567 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
3569 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
3578 pixel_len = thumb_area.Height - 11;
3579 pixels_betweenticks = pixel_len / ticks;
3581 thumb_area.X = thumb_pos.X;
3582 thumb_area.Y = channel_startpoint.Y;
3583 thumb_area.Width = thumb_pos.Height;
3586 Region outside = new Region (area);
3587 outside.Exclude (thumb_area);
3589 if (outside.IsVisible (clip_rectangle)) {
3590 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3591 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3593 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3594 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3595 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
3596 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
3598 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
3599 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
3603 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3604 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3606 pixel_len = thumb_area.Height - 11;
3607 pixels_betweenticks = pixel_len / ticks;
3609 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3610 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3611 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
3612 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3614 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
3615 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
3625 Does not matter the size of the control, Win32 always draws:
3626 - Ticks starting from pixel 13, 8
3627 - Channel starting at pos 8, 19 and ends at Width - 8
3628 - Autosize makes always the control 40 pixels height
3629 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
3632 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3633 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3634 float ticks, int value_pos, bool mouse_value) {
3635 Point toptick_startpoint = new Point ();
3636 Point bottomtick_startpoint = new Point ();
3637 Point channel_startpoint = new Point ();
3639 float pixels_betweenticks;
3640 const int space_from_right = 8;
3641 const int space_from_left = 8;
3642 Rectangle area = tb.ClientRectangle;
3644 switch (tb.TickStyle) {
3645 case TickStyle.BottomRight:
3646 case TickStyle.None:
3647 channel_startpoint.X = 8;
3648 channel_startpoint.Y = 9;
3649 bottomtick_startpoint.X = 13;
3650 bottomtick_startpoint.Y = 24;
3652 case TickStyle.TopLeft:
3653 channel_startpoint.X = 8;
3654 channel_startpoint.Y = 19;
3655 toptick_startpoint.X = 13;
3656 toptick_startpoint.Y = 8;
3658 case TickStyle.Both:
3659 channel_startpoint.X = 8;
3660 channel_startpoint.Y = 18;
3661 bottomtick_startpoint.X = 13;
3662 bottomtick_startpoint.Y = 32;
3663 toptick_startpoint.X = 13;
3664 toptick_startpoint.Y = 8;
3670 thumb_area.X = area.X + channel_startpoint.X;
3671 thumb_area.Y = area.Y + channel_startpoint.Y;
3672 thumb_area.Width = area.Width - space_from_right - space_from_left;
3673 thumb_area.Height = 4;
3676 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
3677 thumb_area.Width, 1);
3679 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
3680 thumb_area.Width, 1);
3682 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
3683 thumb_area.Width, 1);
3685 pixel_len = thumb_area.Width - 11;
3686 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3688 /* Convert thumb position from mouse position to value*/
3690 if (value_pos >= channel_startpoint.X)
3691 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
3695 if (value_pos + tb.Minimum > tb.Maximum)
3696 value_pos = tb.Maximum - tb.Minimum;
3698 tb.Value = value_pos + tb.Minimum;
3701 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
3703 /* Draw thumb fixed 10x22 size */
3704 thumb_pos.Width = 10;
3705 thumb_pos.Height = 22;
3707 switch (tb.TickStyle) {
3708 case TickStyle.BottomRight:
3709 case TickStyle.None: {
3710 thumb_pos.Y = channel_startpoint.Y - 8;
3712 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
3713 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
3714 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
3716 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
3717 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
3719 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
3720 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
3722 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
3723 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
3724 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
3725 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
3728 case TickStyle.TopLeft: {
3729 thumb_pos.Y = channel_startpoint.Y - 10;
3731 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
3732 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
3734 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
3735 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
3736 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
3738 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
3739 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
3740 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
3742 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
3743 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
3744 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
3745 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
3749 case TickStyle.Both: {
3750 thumb_pos.Y = area.Y + 10;
3751 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
3752 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
3754 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
3755 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
3757 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
3758 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
3760 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
3769 pixel_len = thumb_area.Width - 11;
3770 pixels_betweenticks = pixel_len / ticks;
3773 thumb_area.Y = thumb_pos.Y;
3774 thumb_area.X = channel_startpoint.X;
3775 thumb_area.Height = thumb_pos.Height;
3776 Region outside = new Region (area);
3777 outside.Exclude (thumb_area);
3779 if (outside.IsVisible (clip_rectangle)) {
3780 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
3781 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3783 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3784 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3785 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
3786 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
3788 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
3789 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
3793 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
3794 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
3796 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
3797 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
3798 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
3799 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
3801 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
3802 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
3808 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
3813 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
3815 Rectangle thumb_pos = tb.ThumbPos;
3816 Rectangle thumb_area = tb.ThumbArea;
3818 if (tb.thumb_pressed) {
3819 value_pos = tb.thumb_mouseclick;
3822 value_pos = tb.Value - tb.Minimum;
3823 mouse_value = false;
3826 area = tb.ClientRectangle;
3828 if (tb.thumb_pressed == true) {
3829 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
3831 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
3835 /* Control Background */
3836 if (tb.BackColor == DefaultControlBackColor) {
3837 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), clip_rectangle);
3839 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
3844 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
3845 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
3846 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
3847 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
3850 if (tb.Orientation == Orientation.Vertical) {
3851 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3852 br_thumb, ticks, value_pos, mouse_value);
3855 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
3856 br_thumb, ticks, value_pos, mouse_value);
3859 tb.ThumbPos = thumb_pos;
3860 tb.ThumbArea = thumb_area;
3863 public override Size TrackBarDefaultSize {
3865 return new Size (104, 42);
3869 #endregion // TrackBar
3872 public override Size VScrollBarDefaultSize {
3874 return new Size (this.ScrollBarButtonSize, 80);
3877 #endregion // VScrollBar
3880 public override Size TreeViewDefaultSize {
\r
3882 return new Size (121, 97);
\r
3888 #region ControlPaint
3889 private enum DrawFrameControlStates {
3890 ButtonCheck = 0x0000,
3891 ButtonRadioImage = 0x0001,
3892 ButtonRadioMask = 0x0002,
3893 ButtonRadio = 0x0004,
3894 Button3State = 0x0008,
3895 ButtonPush = 0x0010,
3897 CaptionClose = 0x0000,
3898 CaptionMin = 0x0001,
3899 CaptionMax = 0x0002,
3900 CaptionRestore = 0x0004,
3901 CaptionHelp = 0x0008,
3905 MenuBullet = 0x0002,
3906 MenuArrowRight = 0x0004,
3909 ScrollDown = 0x0001,
3910 ScrollLeft = 0x0002,
3911 ScrollRight = 0x0003,
3912 ScrollComboBox = 0x0005,
3913 ScrollSizeGrip = 0x0008,
3914 ScrollSizeGripRight = 0x0010,
3919 Transparent = 0x0800,
3921 AdjustRect = 0x2000,
3927 private enum DrawFrameControlTypes {
3934 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
3935 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3936 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3937 int bottomWidth, ButtonBorderStyle bottomStyle) {
3938 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
3939 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
3940 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
3941 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
3944 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
3945 CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
3948 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
3950 Pen penTopLeftInner;
3952 Pen penBottomRightInner;
3953 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
3954 bool doInner = false;
3956 if ((style & Border3DStyle.Adjust)!=0) {
3963 /* default to flat */
3964 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
3965 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3966 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
3967 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3969 if ((style & Border3DStyle.RaisedOuter)!=0) {
3970 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3971 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3972 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3975 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
3976 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3977 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
3978 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
3983 if ((style & Border3DStyle.RaisedInner)!=0) {
3985 penTopLeftInner=ResPool.GetPen(control_color);
3986 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3988 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
3989 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3991 } else if ((style & Border3DStyle.SunkenInner)!=0) {
3993 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
3994 penBottomRightInner=ResPool.GetPen(control_color);
3996 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
3997 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
4001 if ((sides & Border3DSide.Middle)!=0) {
4002 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
4005 if ((sides & Border3DSide.Left)!=0) {
4006 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
4008 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
4012 if ((sides & Border3DSide.Top)!=0) {
4013 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
4016 if ((sides & Border3DSide.Left)!=0) {
4017 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
4019 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
4024 if ((sides & Border3DSide.Right)!=0) {
4025 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
4028 if ((sides & Border3DSide.Top)!=0) {
4029 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
4031 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
4036 if ((sides & Border3DSide.Bottom)!=0) {
4039 if ((sides & Border3DSide.Left)!=0) {
4043 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
4046 if ((sides & Border3DSide.Right)!=0) {
4047 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4049 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
4057 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4058 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
4060 if ((state & ButtonState.Pushed)!=0) {
4061 dfcs |= DrawFrameControlStates.Pushed;
4064 if ((state & ButtonState.Checked)!=0) {
4065 dfcs |= DrawFrameControlStates.Checked;
4068 if ((state & ButtonState.Flat)!=0) {
4069 dfcs |= DrawFrameControlStates.Flat;
4072 if ((state & ButtonState.Inactive)!=0) {
4073 dfcs |= DrawFrameControlStates.Inactive;
4075 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4079 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4080 Rectangle captionRect;
4083 CPDrawButton(graphics, rectangle, state);
4085 if (rectangle.Width<rectangle.Height) {
4086 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4088 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4091 if ((state & ButtonState.Pushed)!=0) {
4092 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4095 /* Make sure we've got at least a line width of 1 */
4096 lineWidth=Math.Max(1, captionRect.Width/7);
4099 case CaptionButton.Close: {
4102 if ((state & ButtonState.Inactive)!=0) {
4103 pen=new Pen(ColorButtonHilight, lineWidth);
4104 DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
4107 pen=new Pen(ColorButtonShadow, lineWidth);
4108 DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
4112 pen=new Pen(ColorButtonText, lineWidth);
4113 DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
4119 case CaptionButton.Help:
4120 case CaptionButton.Maximize:
4121 case CaptionButton.Minimize:
4122 case CaptionButton.Restore: {
4123 if ((state & ButtonState.Inactive)!=0) {
4124 DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4126 DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4129 DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4137 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
4138 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
4140 if ((state & ButtonState.Pushed)!=0) {
4141 dfcs |= DrawFrameControlStates.Pushed;
4144 if ((state & ButtonState.Checked)!=0) {
4145 dfcs |= DrawFrameControlStates.Checked;
4148 if ((state & ButtonState.Flat)!=0) {
4149 dfcs |= DrawFrameControlStates.Flat;
4152 if ((state & ButtonState.Inactive)!=0) {
4153 dfcs |= DrawFrameControlStates.Inactive;
4156 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4160 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4161 Point[] arrow = new Point[3];
4171 if ((state & ButtonState.Checked)!=0) {
4172 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);
4175 if ((state & ButtonState.Flat)!=0) {
4176 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4178 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4179 // this needs to render like a pushed button - jba
4180 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4181 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4182 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4184 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4188 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4189 centerX=rect.Left+rect.Width/2;
4190 centerY=rect.Top+rect.Height/2;
4191 shiftX=Math.Max(1, rect.Width/8);
4192 shiftY=Math.Max(1, rect.Height/8);
4194 if ((state & ButtonState.Pushed)!=0) {
4201 P1=new Point(rect.Left, centerY);
4202 P2=new Point(rect.Right, centerY);
4203 P3=new Point(centerX, rect.Bottom);
4209 /* Draw the arrow */
4210 if ((state & ButtonState.Inactive)!=0) {
4211 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4213 /* Move away from the shadow */
4223 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4225 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4230 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
4232 Pen pen = new Pen(Color.Black, 1);
4233 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
4237 graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
4238 graphics.DrawRectangle(pen, rect);
4240 X=rect.X+rect.Width/2;
4241 Y=rect.Y+rect.Height/2;
4243 /* Draw the cross */
4244 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
4245 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
4247 /* Draw 'arrows' for vertical lines */
4248 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
4249 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
4251 /* Draw 'arrows' for horizontal lines */
4252 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
4253 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
4257 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4258 // make a rectange to trace around border of the button
4259 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4261 Color outerColor = foreColor;
4262 // adjust focus color according to the flatstyle
4263 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4264 outerColor = (backColor == ColorButtonFace) ? ControlPaint.Dark(ColorButtonFace) : ColorButtonText;
4267 // draw the outer rectangle
4268 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4270 // draw the inner rectangle
4271 if (button.FlatStyle == FlatStyle.Popup) {
4272 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4274 // draw a flat inner rectangle
4275 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4276 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4280 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4282 // make a rectange to trace around border of the button
4283 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4285 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4286 DashStyle oldStyle; // used for caching old penstyle
4287 Pen pen = ResPool.GetPen (colorBackInverted);
4289 oldStyle = pen.DashStyle;
4290 pen.DashStyle = DashStyle.Dot;
4291 graphics.DrawRectangle (pen, trace_rectangle);
4292 pen.DashStyle = oldStyle;
4296 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4298 Rectangle rect = rectangle;
4302 if (backColor.GetBrightness () >= 0.5) {
4303 foreColor = Color.Transparent;
4304 backColor = Color.Black;
4307 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4308 foreColor = Color.Black;
4311 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4312 pen = new Pen (brush, 1);
4317 graphics.DrawRectangle (pen, rect);
4321 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
4325 if (primary==true) {
4326 pen=new Pen(Color.Black, 1);
4327 if (enabled==true) {
4328 sb=ResPool.GetSolidBrush (ColorButtonText);
4330 sb=ResPool.GetSolidBrush (ColorButtonFace);
4333 pen=new Pen(Color.White, 1);
4334 if (enabled==true) {
4335 sb=ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black);
4337 sb=ResPool.GetSolidBrush (ColorButtonFace);
4340 graphics.FillRectangle(sb, rectangle);
4341 graphics.DrawRectangle(pen, rectangle);
4346 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
4352 ControlPaint.Color2HBS(backColor, out h, out b, out s);
4355 foreColor=Color.Black;
4357 foreColor=Color.White;
4361 /* Commented out until I take the time and figure out
4362 which HatchStyle will match requirements. The code below
4363 is only correct for Percent50.
4365 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
4366 HatchBrush brush=null;
4368 switch(pixelsBetweenDots.Width) {
4369 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
4370 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
4371 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
4373 /* Have to do it the slow way */
4378 graphics.FillRectangle(brush, area);
4387 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
4389 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
4390 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
4391 bitmap.SetPixel(x, y, foreColor);
4394 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
4398 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
4400 Microsoft seems to ignore the background and simply make
4401 the image grayscale. At least when having > 256 colors on
4405 if (imagedisabled_attributes == null) {
4406 imagedisabled_attributes = new ImageAttributes ();
4407 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
4408 // This table would create a perfect grayscale image, based on luminance
4409 // new float[]{0.3f,0.3f,0.3f,0,0},
4410 // new float[]{0.59f,0.59f,0.59f,0,0},
4411 // new float[]{0.11f,0.11f,0.11f,0,0},
4412 // new float[]{0,0,0,1,0,0},
4413 // new float[]{0,0,0,0,1,0},
4414 // new float[]{0,0,0,0,0,1}
4416 // This table generates a image that is grayscaled and then
4417 // brightened up. Seems to match MS close enough.
4418 new float[]{0.2f,0.2f,0.2f,0,0},
4419 new float[]{0.41f,0.41f,0.41f,0,0},
4420 new float[]{0.11f,0.11f,0.11f,0,0},
4421 new float[]{0.15f,0.15f,0.15f,1,0,0},
4422 new float[]{0.15f,0.15f,0.15f,0,1,0},
4423 new float[]{0.15f,0.15f,0.15f,0,0,1}
4426 imagedisabled_attributes.SetColorMatrix (colorMatrix);
4429 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
4434 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
4439 penBorder=new Pen(Color.White, 2);
4440 penInside=new Pen(Color.Black, 1);
4442 penBorder=new Pen(Color.Black, 2);
4443 penInside=new Pen(Color.White, 1);
4445 penBorder.Alignment=PenAlignment.Inset;
4446 penInside.Alignment=PenAlignment.Inset;
4448 graphics.DrawRectangle(penBorder, rectangle);
4449 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
4450 penBorder.Dispose();
4451 penInside.Dispose();
4455 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
4459 // MS draws always the background white
4460 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
4463 case MenuGlyph.Arrow: {
4464 Point[] arrow = new Point[3];
4472 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4473 centerX=rect.Left+rect.Width/2;
4474 centerY=rect.Top+rect.Height/2;
4475 shiftX=Math.Max(1, rect.Width/8);
4480 P1=new Point(centerX, rect.Top-1);
4481 P2=new Point(centerX, rect.Bottom);
4482 P3=new Point(rect.Right, centerY);
4488 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4493 case MenuGlyph.Bullet: {
4495 lineWidth=Math.Max(2, rectangle.Width/3);
4496 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4498 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
4503 case MenuGlyph.Checkmark: {
4506 lineWidth=Math.Max(2, rectangle.Width/6);
4507 Scale=Math.Max(1, rectangle.Width/12);
4509 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
4511 for (int i=0; i<lineWidth; i++) {
4512 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4513 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);
4521 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4522 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
4524 if ((state & ButtonState.Pushed)!=0) {
4525 dfcs |= DrawFrameControlStates.Pushed;
4528 if ((state & ButtonState.Checked)!=0) {
4529 dfcs |= DrawFrameControlStates.Checked;
4532 if ((state & ButtonState.Flat)!=0) {
4533 dfcs |= DrawFrameControlStates.Flat;
4536 if ((state & ButtonState.Inactive)!=0) {
4537 dfcs |= DrawFrameControlStates.Inactive;
4539 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
4544 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
4549 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
4554 /* Scroll button: regular button + direction arrow */
4555 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
4556 bool enabled = (state == ButtonState.Inactive) ? false: true;
4558 DrawScrollButtonPrimitive (dc, area, state);
4560 if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
4565 case ScrollButton.Up: {
4566 int x = area.X + (area.Width / 2) - 4;
4569 for (int i = 0; i < 3; i++)
4571 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y - i, x + i + 6 - 2*i, y - i);
4573 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
4576 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4577 x + 3, area.Y + 6, 1, 1);
4581 case ScrollButton.Down: {
4582 int x = area.X + (area.Width / 2) - 5;
4585 for (int i = 4; i != 0; i--)
4587 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i + 8 - 2*i, y + i);
4589 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
4592 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4593 x + 4, y + 4, 1, 1);
4597 case ScrollButton.Left: {
4598 int y = area.Y + (area.Height / 2) - 4;
4601 for (int i = 0; i < 3; i++)
4603 dc.DrawLine (ResPool.GetPen (arrow_color), x - i, y + i, x - i, y + i + 6 - 2*i);
4605 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
4607 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4608 x - 3, y + 3, 1, 1);
4612 case ScrollButton.Right: {
4613 int y = area.Y + (area.Height / 2) - 5;
4616 for (int i = 4; i != 0; i--)
4618 dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i, y + i + 8 - 2*i);
4620 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
4622 dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) : ResPool.GetSolidBrush (ColorGrayText),
4623 x + 4, y + 4, 1, 1);
4634 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
4640 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
4641 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
4643 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
4644 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
4647 for (int i = 0; i < 11; i += 4) {
4648 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
4649 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
4652 for (int i = 3; i < 13; i += 4)
4653 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
4657 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
4658 StringFormat format) {
4660 layoutRectangle.Offset(1.0f, 1.0f);
4661 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 95)), layoutRectangle, format);
4662 layoutRectangle.Offset(-1.0f, -1.0f);
4663 graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 50)), layoutRectangle, format);
4667 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
4668 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
4670 Pen pen=new Pen(color, 1);
4673 case ButtonBorderStyle.Solid: {
4674 pen.DashStyle=DashStyle.Solid;
4678 case ButtonBorderStyle.Dashed: {
4679 pen.DashStyle=DashStyle.Dash;
4683 case ButtonBorderStyle.Dotted: {
4684 pen.DashStyle=DashStyle.Dot;
4688 case ButtonBorderStyle.Inset: {
4689 pen.DashStyle=DashStyle.Solid;
4693 case ButtonBorderStyle.Outset: {
4694 pen.DashStyle=DashStyle.Solid;
4699 case ButtonBorderStyle.None: {
4707 case ButtonBorderStyle.Outset: {
4709 int hue, brightness, saturation;
4710 int brightnessSteps;
4711 int brightnessDownSteps;
4713 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4715 brightnessDownSteps=brightness/width;
4716 if (brightness>127) {
4717 brightnessSteps=Math.Max(6, (160-brightness)/width);
4719 brightnessSteps=(127-brightness)/width;
4722 for (int i=0; i<width; i++) {
4724 case Border3DSide.Left: {
4726 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4727 pen=new Pen(colorGrade, 1);
4728 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4732 case Border3DSide.Right: {
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.Top: {
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.Bottom: {
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);
4760 case ButtonBorderStyle.Inset: {
4762 int hue, brightness, saturation;
4763 int brightnessSteps;
4764 int brightnessDownSteps;
4766 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
4768 brightnessDownSteps=brightness/width;
4769 if (brightness>127) {
4770 brightnessSteps=Math.Max(6, (160-brightness)/width);
4772 brightnessSteps=(127-brightness)/width;
4775 for (int i=0; i<width; i++) {
4777 case Border3DSide.Left: {
4779 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4780 pen=new Pen(colorGrade, 1);
4781 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4785 case Border3DSide.Right: {
4787 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4788 pen=new Pen(colorGrade, 1);
4789 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4793 case Border3DSide.Top: {
4795 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
4796 pen=new Pen(colorGrade, 1);
4797 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4801 case Border3DSide.Bottom: {
4803 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
4804 pen=new Pen(colorGrade, 1);
4805 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4814 I decided to have the for-loop duplicated for speed reasons;
4815 that way we only have to switch once (as opposed to have the
4816 for-loop around the switch)
4820 case Border3DSide.Left: {
4821 for (int i=0; i<width; i++) {
4822 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
4827 case Border3DSide.Right: {
4828 for (int i=0; i<width; i++) {
4829 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
4834 case Border3DSide.Top: {
4835 for (int i=0; i<width; i++) {
4836 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
4841 case Border3DSide.Bottom: {
4842 for (int i=0; i<width; i++) {
4843 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
4855 This function actually draws the various caption elements.
4856 This way we can scale them nicely, no matter what size, and they
4857 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
4860 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
4862 case CaptionButton.Close: {
4863 pen.StartCap=LineCap.Triangle;
4864 pen.EndCap=LineCap.Triangle;
4866 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);
4867 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);
4870 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4871 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
4875 case CaptionButton.Help: {
4876 StringFormat sf = new StringFormat();
4877 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
4879 sf.Alignment=StringAlignment.Center;
4880 sf.LineAlignment=StringAlignment.Center;
4883 graphics.DrawString("?", font, ThemeEngine.Current.ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
4891 case CaptionButton.Maximize: {
4892 /* Top 'caption bar' line */
4893 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4894 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);
4897 /* Left side line */
4898 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4899 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4902 /* Right side line */
4903 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4904 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);
4908 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4909 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4914 case CaptionButton.Minimize: {
4916 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4917 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
4922 case CaptionButton.Restore: {
4923 /** First 'window' **/
4924 /* Top 'caption bar' line */
4925 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4926 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);
4929 /* Left side line */
4930 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4931 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);
4934 /* Right side line */
4935 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4936 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);
4940 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4941 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);
4944 /** Second 'window' **/
4945 /* Top 'caption bar' line */
4946 for (int i=0; i<Math.Max(2, lineWidth); i++) {
4947 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);
4950 /* Left side line */
4951 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4952 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
4955 /* Right side line */
4956 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4957 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);
4961 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
4962 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
4971 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
4972 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
4973 // make a rectange to trace around border of the button
4974 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4976 case DrawFrameControlTypes.Button: {
4978 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
4979 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
4980 // /* Goes first, affects the background */
4981 // if ((State & DrawFrameControlStates.Checked)!=0) {
4982 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
4983 // graphics.FillRectangle(hatchBrush,rectangle);
4984 // hatchBrush.Dispose();
4987 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
4988 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
4989 } else if ((State & DrawFrameControlStates.Flat)!=0) {
4990 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4991 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
4992 /* Same as normal, it would seem */
4993 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4995 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4997 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
4998 Pen penFatDark = new Pen(ColorButtonShadow, 1);
4999 Pen penFatLight = new Pen(ColorButtonLight, 1);
5002 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
5004 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
5005 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
5007 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
5008 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
5010 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
5012 if ((State & DrawFrameControlStates.Checked)!=0) {
5013 SolidBrush buttonBrush;
5015 if ((State & DrawFrameControlStates.Inactive)!=0) {
5016 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
5018 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
5020 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
5022 penFatDark.Dispose();
5023 penFatLight.Dispose();
5024 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
5025 throw new NotImplementedException () ;
5026 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
5027 throw new NotImplementedException ();
5028 } else { /* Must be Checkbox */
5034 /* Goes first, affects the background */
5035 if ((State & DrawFrameControlStates.Pushed)!=0 ||
5036 (State & DrawFrameControlStates.Inactive)!=0) {
5037 graphics.FillRectangle(SystemBrushes.Control, rectangle);
5039 graphics.FillRectangle(SystemBrushes.Window, rectangle);
5042 /* Draw the sunken frame */
5043 if ((State & DrawFrameControlStates.Flat)!=0) {
5044 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
5046 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
5049 /* Make sure we've got at least a line width of 1 */
5050 lineWidth=Math.Max(3, rectangle.Width/6);
5051 Scale=Math.Max(1, rectangle.Width/12);
5053 // define a rectangle inside the border area
5054 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
5055 if ((State & DrawFrameControlStates.Inactive)!=0) {
5056 pen=SystemPens.ControlDark;
5058 pen=SystemPens.ControlText;
5061 if ((State & DrawFrameControlStates.Checked)!=0) {
5062 /* Need to draw a check-mark */
5063 for (int i=0; i<lineWidth; i++) {
5064 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5065 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);
5073 case DrawFrameControlTypes.Caption: {
5078 case DrawFrameControlTypes.Menu: {
5083 case DrawFrameControlTypes.Scroll: {
5090 /* Generic scroll button */
5091 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5092 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5093 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
5094 area.Y + 1, area.Width - 2 , area.Height - 2);
5096 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
5097 area.Y, area.Width, area.Height);
5102 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
5103 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
5105 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
5106 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
5109 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
5112 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
5115 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
5116 area.Y + 1, 1, area.Height -3);
5118 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
5119 area.Y, 1, area.Height - 1);
5121 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
5122 area.Y + 2, area.Width - 4, area.Height - 4);
5126 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5127 switch (border_style){
5128 case BorderStyle.Fixed3D:
5129 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
5130 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
5131 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5132 area.Y + area.Height - 1);
5133 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5134 area.Y + area.Height);
5136 // FIXME: These colors are not correct. Microsoft uses different ones but I didn't find them.
5137 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5138 dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5139 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5140 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5142 case BorderStyle.FixedSingle:
5143 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5145 case BorderStyle.None:
5151 #endregion // ControlPaint