1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 // Copyright (c) 2004-2006 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Peter Bartok, pbartok@novell.com
25 // John BouAntoun, jba-mono@optusnet.com.au
26 // Marek Safar, marek.safar@seznam.cz
27 // Alexander Olk, alex.olk@googlemail.com
30 using System.ComponentModel;
32 using System.Drawing.Drawing2D;
33 using System.Drawing.Imaging;
34 using System.Drawing.Text;
36 namespace System.Windows.Forms
39 internal class ThemeWin32Classic : Theme
41 public override Version Version {
43 return new Version(0, 1, 0, 0);
47 /* Hardcoded colour values not exposed in the API constants in all configurations */
48 protected static readonly Color arrow_color = Color.Black;
49 protected static readonly Color pen_ticks_color = Color.Black;
50 protected static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
51 protected static StringFormat string_format_menu_text;
52 protected static StringFormat string_format_menu_shortcut;
53 protected static StringFormat string_format_menu_menubar_text;
54 static ImageAttributes imagedisabled_attributes = null;
55 const int SEPARATOR_HEIGHT = 5;
56 const int SM_CXBORDER = 1;
57 const int SM_CYBORDER = 1;
58 const int MENU_TAB_SPACE = 8; // Pixels added to the width of an item because of a tab
59 const int MENU_BAR_ITEMS_SPACE = 8; // Space between menu bar items
61 #region Principal Theme Methods
62 public ThemeWin32Classic ()
64 defaultWindowBackColor = this.ColorWindow;
65 defaultWindowForeColor = this.ColorControlText;
66 default_font = new Font (FontFamily.GenericSansSerif, 8f);
68 /* Menu string formats */
69 string_format_menu_text = new StringFormat ();
70 string_format_menu_text.LineAlignment = StringAlignment.Center;
71 string_format_menu_text.Alignment = StringAlignment.Near;
72 string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
74 string_format_menu_shortcut = new StringFormat ();
75 string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
76 string_format_menu_shortcut.Alignment = StringAlignment.Far;
78 string_format_menu_menubar_text = new StringFormat ();
79 string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
80 string_format_menu_menubar_text.Alignment = StringAlignment.Center;
81 string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
82 always_draw_hotkeys = false;
85 public override void ResetDefaults() {
86 Console.WriteLine("NOT IMPLEMENTED: ResetDefault()");
87 //throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
90 public override bool DoubleBufferingSupported {
94 public override int HorizontalScrollBarHeight {
96 return XplatUI.HorizontalScrollBarHeight;
100 public override int VerticalScrollBarWidth {
102 return XplatUI.VerticalScrollBarWidth;
106 #endregion // Principal Theme Methods
108 #region Internal Methods
109 protected Brush GetControlBackBrush (Color c) {
110 if (c.ToArgb () == DefaultControlBackColor.ToArgb ())
111 return SystemBrushes.Control;
112 return ResPool.GetSolidBrush (c);
115 protected Brush GetControlForeBrush (Color c) {
116 if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
117 return SystemBrushes.ControlText;
118 return ResPool.GetSolidBrush (c);
120 #endregion // Internal Methods
122 #region OwnerDraw Support
123 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
125 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
126 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
130 e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
133 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
135 if (e.State == DrawItemState.Focus)
136 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
138 #endregion // OwnerDraw Support
141 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
143 // Fill the button with the correct color
144 bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
145 dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
147 // First, draw the image
148 if ((button.image != null) || (button.image_list != null))
149 ButtonBase_DrawImage(button, dc);
151 // Draw the button: Draw border, etc.
152 ButtonBase_DrawButton(button, dc);
154 // Draw the focus rectangle
155 if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled)
156 ButtonBase_DrawFocus(button, dc);
159 if (button.text != null && button.text != String.Empty)
160 ButtonBase_DrawText(button, dc);
163 protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
165 Rectangle borderRectangle;
166 bool check_or_radio = false;
167 bool check_or_radio_checked = false;
169 bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
171 CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
173 if (button is CheckBox) {
174 check_or_radio = true;
175 check_or_radio_checked = ((CheckBox)button).Checked;
176 } else if (button is RadioButton) {
177 check_or_radio = true;
178 check_or_radio_checked = ((RadioButton)button).Checked;
181 if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled && !check_or_radio) {
182 // shrink the rectangle for the normal button drawing inside the focus rectangle
183 borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
185 borderRectangle = button.ClientRectangle;
188 if (button.FlatStyle == FlatStyle.Popup) {
189 if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
190 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
191 else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
192 Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
193 else if (button.is_pressed || check_or_radio_checked)
194 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
195 } else if (button.FlatStyle == FlatStyle.Flat) {
196 if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
197 if ((button.image == null) && (button.image_list == null)) {
198 Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
199 dc.FillRectangle (brush, borderRectangle);
201 } else if (button.is_pressed || check_or_radio_checked) {
202 if ((button.image == null) && (button.image_list == null)) {
203 Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
204 dc.FillRectangle (brush, borderRectangle);
207 Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
208 dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
209 borderRectangle.Width - 9, borderRectangle.Height - 9);
212 Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
214 if ((!button.is_pressed || !button.Enabled) && !check_or_radio_checked)
215 Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
217 Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
221 private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
224 case 0: // normal or normal disabled button
225 Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
226 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
227 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
229 pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
230 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
231 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
233 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
234 dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
235 dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
237 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
238 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
239 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
241 case 1: // popup button normal (or pressed normal or popup button)
242 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
243 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
245 case 2: // popup button poped up
246 pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
247 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
248 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
250 pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
251 dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
252 dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
254 case 3: // flat button not entered
255 pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
256 dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
263 protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
265 // Need to draw a picture
272 int width = button.ClientSize.Width;
273 int height = button.ClientSize.Height;
275 if (button.ImageIndex != -1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
276 i = button.image_list.Images[button.image_index];
281 image_width = i.Width;
282 image_height = i.Height;
284 switch (button.image_alignment) {
285 case ContentAlignment.TopLeft: {
291 case ContentAlignment.TopCenter: {
292 image_x = (width - image_width) / 2;
297 case ContentAlignment.TopRight: {
298 image_x = width - image_width - 5;
303 case ContentAlignment.MiddleLeft: {
305 image_y = (height - image_height) / 2;
309 case ContentAlignment.MiddleCenter: {
310 image_x = (width - image_width) / 2;
311 image_y = (height - image_height) / 2;
315 case ContentAlignment.MiddleRight: {
316 image_x = width - image_width - 4;
317 image_y = (height - image_height) / 2;
321 case ContentAlignment.BottomLeft: {
323 image_y = height - image_height - 4;
327 case ContentAlignment.BottomCenter: {
328 image_x = (width - image_width) / 2;
329 image_y = height - image_height - 4;
333 case ContentAlignment.BottomRight: {
334 image_x = width - image_width - 4;
335 image_y = height - image_height - 4;
346 if (button.Enabled) {
347 dc.DrawImage(i, image_x, image_y);
350 CPDrawImageDisabled(dc, i, image_x, image_y, ColorControl);
354 protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
356 Color focus_color = button.ForeColor;
358 int inflate_value = -3;
360 if (!(button is CheckBox) && !(button is RadioButton)) {
363 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed)
364 focus_color = ControlPaint.Dark(button.BackColor);
366 dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y,
367 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
370 if (button.Focused) {
371 Rectangle rect = Rectangle.Inflate (button.ClientRectangle, inflate_value, inflate_value);
372 ControlPaint.DrawFocusRectangle (dc, rect);
376 protected virtual void ButtonBase_DrawText(ButtonBase button, Graphics dc)
378 Rectangle buttonRectangle = button.ClientRectangle;
379 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
381 if (button.is_pressed) {
386 if (button.Enabled) {
387 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
389 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
390 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
392 CPDrawStringDisabled (dc, button.text, button.Font, button.BackColor, text_rect, button.text_format);
397 public override Size ButtonBaseDefaultSize {
399 return new Size (75, 23);
402 #endregion // ButtonBase
405 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
406 StringFormat text_format;
407 Rectangle client_rectangle;
408 Rectangle text_rectangle;
409 Rectangle checkbox_rectangle;
410 int checkmark_size=13;
411 int checkmark_space = 4;
413 client_rectangle = checkbox.ClientRectangle;
414 text_rectangle = client_rectangle;
415 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
417 text_format = new StringFormat();
418 text_format.Alignment=StringAlignment.Near;
419 text_format.LineAlignment=StringAlignment.Center;
420 text_format.HotkeyPrefix = HotkeyPrefix.Show;
422 /* Calculate the position of text and checkbox rectangle */
423 if (checkbox.appearance!=Appearance.Button) {
424 switch(checkbox.check_alignment) {
425 case ContentAlignment.BottomCenter: {
426 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
427 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
428 text_rectangle.X=client_rectangle.X;
429 text_rectangle.Width=client_rectangle.Width;
430 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
434 case ContentAlignment.BottomLeft: {
435 checkbox_rectangle.X=client_rectangle.Left;
436 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
437 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
438 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
442 case ContentAlignment.BottomRight: {
443 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
444 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
445 text_rectangle.X=client_rectangle.X;
446 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
450 case ContentAlignment.MiddleCenter: {
451 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
452 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
453 text_rectangle.X=client_rectangle.X;
454 text_rectangle.Width=client_rectangle.Width;
459 case ContentAlignment.MiddleLeft: {
460 checkbox_rectangle.X=client_rectangle.Left;
461 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
462 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
463 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
467 case ContentAlignment.MiddleRight: {
468 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
469 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
470 text_rectangle.X=client_rectangle.X;
471 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
475 case ContentAlignment.TopCenter: {
476 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
477 checkbox_rectangle.Y=client_rectangle.Top;
478 text_rectangle.X=client_rectangle.X;
479 text_rectangle.Width=client_rectangle.Width;
480 text_rectangle.Y=checkmark_size+checkmark_space;
481 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
485 case ContentAlignment.TopLeft: {
486 checkbox_rectangle.X=client_rectangle.Left;
487 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
488 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
492 case ContentAlignment.TopRight: {
493 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
494 text_rectangle.X=client_rectangle.X;
495 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
500 text_rectangle.X=client_rectangle.X;
501 text_rectangle.Width=client_rectangle.Width;
504 /* Set the horizontal alignment of our text */
505 switch(checkbox.text_alignment) {
506 case ContentAlignment.BottomLeft:
507 case ContentAlignment.MiddleLeft:
508 case ContentAlignment.TopLeft: {
509 text_format.Alignment=StringAlignment.Near;
513 case ContentAlignment.BottomCenter:
514 case ContentAlignment.MiddleCenter:
515 case ContentAlignment.TopCenter: {
516 text_format.Alignment=StringAlignment.Center;
520 case ContentAlignment.BottomRight:
521 case ContentAlignment.MiddleRight:
522 case ContentAlignment.TopRight: {
523 text_format.Alignment=StringAlignment.Far;
528 /* Set the vertical alignment of our text */
529 switch(checkbox.text_alignment) {
530 case ContentAlignment.TopLeft:
531 case ContentAlignment.TopCenter:
532 case ContentAlignment.TopRight: {
533 text_format.LineAlignment=StringAlignment.Near;
537 case ContentAlignment.BottomLeft:
538 case ContentAlignment.BottomCenter:
539 case ContentAlignment.BottomRight: {
540 text_format.LineAlignment=StringAlignment.Far;
544 case ContentAlignment.MiddleLeft:
545 case ContentAlignment.MiddleCenter:
546 case ContentAlignment.MiddleRight: {
547 text_format.LineAlignment=StringAlignment.Center;
552 ButtonState state = ButtonState.Normal;
553 if (checkbox.FlatStyle == FlatStyle.Flat) {
554 state |= ButtonState.Flat;
557 if (checkbox.Checked) {
558 state |= ButtonState.Checked;
561 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
562 state |= ButtonState.Checked;
563 state |= ButtonState.Pushed;
566 // finally make sure the pushed and inavtive states are rendered
567 if (!checkbox.Enabled) {
568 state |= ButtonState.Inactive;
570 else if (checkbox.is_pressed) {
571 state |= ButtonState.Pushed;
576 CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
578 if ((checkbox.image != null) || (checkbox.image_list != null))
579 ButtonBase_DrawImage(checkbox, dc);
581 CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
583 CheckBox_DrawFocus(checkbox, dc, text_rectangle);
585 text_format.Dispose ();
588 protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
590 Brush brush = checkbox.BackColor.ToArgb () == ColorControl.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
591 dc.FillRectangle (brush, checkbox.ClientRectangle);
592 // render as per normal button
593 if (checkbox.appearance==Appearance.Button) {
594 ButtonBase_DrawButton (checkbox, dc);
596 if ((checkbox.Focused) && checkbox.Enabled)
597 ButtonBase_DrawFocus(checkbox, dc);
599 // establish if we are rendering a flat style of some sort
600 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
601 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
603 CPDrawCheckBox (dc, checkbox_rectangle, state);
608 protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
610 DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc,
611 text_format, checkbox.Appearance, checkbox.Checked);
614 protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
616 if ( checkbox.Focused && checkbox.appearance != Appearance.Button && checkbox.Enabled )
617 DrawInnerFocusRectangle( dc, text_rectangle, checkbox.BackColor );
620 // renders a checkBox with the Flat and Popup FlatStyle
621 protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
625 Rectangle checkbox_rectangle;
626 Rectangle fill_rectangle;
630 // set up our rectangles first
631 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
632 // clip one pixel from bottom right for non popup rendered checkboxes
633 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
634 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));
636 // clip two pixels from bottom right for non popup rendered checkboxes
637 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
638 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));
642 // if disabled render in disabled state
643 if (checkbox.Enabled) {
644 // process the state of the checkbox
645 if (checkbox.is_entered || checkbox.Capture) {
646 // decide on which background color to use
647 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
648 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
649 } else if (checkbox.FlatStyle == FlatStyle.Flat) {
650 if (!checkbox.is_pressed) {
651 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
653 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
655 // use regular window background color
656 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
659 // render the outer border
660 if (checkbox.FlatStyle == FlatStyle.Flat) {
661 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
663 // draw sunken effect
664 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
667 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
669 if (checkbox.FlatStyle == FlatStyle.Flat) {
670 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
672 // draw the outer border
673 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
677 if (checkbox.FlatStyle == FlatStyle.Popup) {
678 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
681 // draw disabled state,
682 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
685 if (checkbox.Checked) {
686 /* Need to draw a check-mark */
688 /* Make sure we've got at least a line width of 1 */
689 lineWidth = Math.Max(3, fill_rectangle.Width/3);
690 Scale=Math.Max(1, fill_rectangle.Width/9);
692 // flat style check box is rendered inside a rectangle shifted down by one
693 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
694 if (checkbox.Enabled) {
695 pen=ResPool.GetPen(checkbox.ForeColor);
697 pen=SystemPens.ControlDark;
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);
707 private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc,
708 StringFormat text_format, Appearance appearance, bool ischecked)
710 // offset the text if it's pressed and a button
711 if (appearance == Appearance.Button) {
712 if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
717 text_rectangle.Inflate (-4, -4);
720 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
722 // Windows seems to not wrap text in certain situations, this matches as close as I could get it
723 if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
724 text_format.FormatFlags |= StringFormatFlags.NoWrap;
726 if (button_base.Enabled) {
727 dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);
728 } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
729 dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
731 CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
734 #endregion // CheckBox
736 #region CheckedListBox
738 public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
740 Color back_color, fore_color;
741 Rectangle item_rect = e.Bounds;
746 if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
747 state = ButtonState.Checked;
748 if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
749 state |= ButtonState.Inactive;
751 state = ButtonState.Normal;
753 if (ctrl.ThreeDCheckBoxes == false)
754 state |= ButtonState.Flat;
756 Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
757 ControlPaint.DrawCheckBox (e.Graphics,
758 item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
759 checkbox_rect.Width, checkbox_rect.Height,
762 item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
763 item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
766 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
767 back_color = ColorHighlight;
768 fore_color = ColorHighlightText;
771 back_color = e.BackColor;
772 fore_color = e.ForeColor;
775 e.Graphics.FillRectangle (ResPool.GetSolidBrush
776 (back_color), item_rect);
778 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
779 ResPool.GetSolidBrush (fore_color),
780 item_rect, ctrl.StringFormat);
782 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
783 CPDrawFocusRectangle (e.Graphics, item_rect,
784 fore_color, back_color);
788 #endregion // CheckedListBox
791 public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
793 Color back_color, fore_color;
794 Rectangle text_draw = e.Bounds;
795 StringFormat string_format = new StringFormat ();
796 string_format.FormatFlags = StringFormatFlags.LineLimit;
798 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
799 back_color = ColorHighlight;
800 fore_color = ColorHighlightText;
803 back_color = e.BackColor;
804 fore_color = e.ForeColor;
808 fore_color = ColorInactiveCaptionText;
810 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
813 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
814 ResPool.GetSolidBrush (fore_color),
815 text_draw, string_format);
818 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
819 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
822 string_format.Dispose ();
827 public override int DataGridPreferredColumnWidth { get { return 75;} }
828 public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
829 public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
830 public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
831 public override Color DataGridBackColor { get { return ColorWindow;} }
832 public override Color DataGridBackgroundColor { get { return ColorAppWorkspace;} }
833 public override Color DataGridCaptionBackColor { get { return ColorActiveCaption;} }
834 public override Color DataGridCaptionForeColor { get { return ColorActiveCaptionText;} }
835 public override Color DataGridGridLineColor { get { return ColorControl;} }
836 public override Color DataGridHeaderBackColor { get { return ColorControl;} }
837 public override Color DataGridHeaderForeColor { get { return ColorControlText;} }
838 public override Color DataGridLinkColor { get { return ColorHotTrack;} }
839 public override Color DataGridLinkHoverColor { get { return ColorHotTrack;} }
840 public override Color DataGridParentRowsBackColor { get { return ColorControl;} }
841 public override Color DataGridParentRowsForeColor { get { return ColorWindowText;} }
842 public override Color DataGridSelectionBackColor { get { return ColorActiveCaption;} }
843 public override Color DataGridSelectionForeColor { get { return ColorActiveCaptionText;} }
845 public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
847 DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
848 DataGridPaintParentRows (pe.Graphics, pe.ClipRectangle, grid);
849 DataGridPaintColumnHeaders (pe.Graphics, pe.ClipRectangle, grid);
850 DataGridPaintRows (pe.Graphics, grid.cells_area, pe.ClipRectangle, grid);
852 // Paint scrollBar corner
853 if (grid.VScrollBar.Visible && grid.HScrollBar.Visible) {
855 Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.HScrollBar.Width,
856 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.VScrollBar.Height,
857 grid.VScrollBar.Width, grid.HScrollBar.Height);
859 if (pe.ClipRectangle.IntersectsWith (corner)) {
860 pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
866 public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
868 Rectangle modified_area = clip;
869 modified_area.Intersect (grid.caption_area);
871 g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
874 g.DrawString (grid.CaptionText, grid.CaptionFont,
875 ResPool.GetSolidBrush (grid.CaptionForeColor),
879 public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
881 Rectangle columns_area = grid.columnhdrs_area;
883 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
884 Rectangle rect_bloc = grid.columnhdrs_area;
885 rect_bloc.Width = grid.RowHeaderWidth;
886 if (clip.IntersectsWith (rect_bloc)) {
887 if (grid.VisibleColumnCount > 0)
888 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
890 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
893 columns_area.X += grid.RowHeaderWidth;
894 columns_area.Width -= grid.RowHeaderWidth;
898 Rectangle columnhdrs_area_complete = columns_area;
899 columnhdrs_area_complete.Width = grid.columnhdrs_maxwidth;
901 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
902 columnhdrs_area_complete.Width -= grid.RowHeaderWidth;
905 // Set column painting
906 Rectangle rect_columnhdr = new Rectangle ();
909 rect_columnhdr.Y = columns_area.Y;
910 rect_columnhdr.Height = columns_area.Height;
912 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
913 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
915 col_pixel = grid.GetColumnStartingPixel (column);
916 rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
917 rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
919 if (clip.IntersectsWith (rect_columnhdr) == false)
922 current_clip = new Region (rect_columnhdr);
923 current_clip.Intersect (columns_area);
924 current_clip.Intersect (clip);
925 g.Clip = current_clip;
927 grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
929 current_clip.Dispose ();
934 Rectangle not_usedarea = columnhdrs_area_complete;
935 not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
936 not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
937 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
941 public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
943 Rectangle rect_row = new Rectangle ();
945 rect_row.X = grid.ParentRowsArea.X;
946 rect_row.Width = grid.ParentRowsArea.Width;
947 rect_row.Height = (grid.CaptionFont.Height + 3);
949 g.SetClip (grid.ParentRowsArea);
951 object[] parentRows = grid.parentRows.ToArray();
954 for (int row = 0; row < parentRows.Length; row++) {
955 rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
957 if (clip.IntersectsWith (rect_row) == false)
960 current_clip = new Region (rect_row);
961 current_clip.Intersect (clip);
962 g.Clip = current_clip;
964 DataGridPaintParentRow (g, rect_row, (DataGridParentRow)parentRows[parentRows.Length - row - 1], grid);
966 current_clip.Dispose ();
972 public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridParentRow row, DataGrid grid)
974 //Console.WriteLine ("drawing parent row {0}", row);
977 g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
980 Font bold_font = new Font (grid.Font.FontFamily, grid.Font.Size, grid.Font.Style | FontStyle.Bold);
981 // set up some standard string formating variables
982 StringFormat text_format = new StringFormat();
983 text_format.LineAlignment = StringAlignment.Center;
984 text_format.Alignment = StringAlignment.Near;
986 string table_name = ((ITypedList)row.view.DataView).GetListName (null) + ": ";
991 text_size = g.MeasureString (table_name, bold_font).ToSize();
992 text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
994 //Console.WriteLine ("drawing text at {0}", text_rect);
996 g.DrawString (table_name,
997 bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
999 foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)row.view).GetProperties()) {
1000 if (typeof(IBindingList).IsAssignableFrom (pd.PropertyType))
1003 text_rect.X += text_rect.Size.Width + 5;
1005 string text = String.Format ("{0}: {1}",
1007 pd.GetValue (row.view));
1009 text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
1010 text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
1012 //Console.WriteLine ("drawing text at {0}", text_rect);
1015 grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
1018 if (grid.FlatMode == false) {
1021 g.DrawLine (ResPool.GetPen (ColorControlLight),
1022 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1024 g.DrawLine (ResPool.GetPen (ColorControlLight),
1025 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1027 g.DrawLine (ResPool.GetPen (ColorControlDark),
1028 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1030 g.DrawLine (ResPool.GetPen (ColorControlDark),
1031 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1035 public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid)
1037 Point[] arrow = new Point[3];
1039 int centerX, centerY, shiftX;
1042 rect = new Rectangle (bounds.X + bounds.Width /4,
1043 bounds.Y + bounds.Height/4, bounds.Width / 2, bounds.Height / 2);
1045 centerX = rect.Left + rect.Width / 2;
1046 centerY = rect.Top + rect.Height / 2;
1047 shiftX = Math.Max (1, rect.Width / 8);
1050 P1 = new Point (centerX, rect.Top - 1);
1051 P2 = new Point (centerX, rect.Bottom);
1052 P3 = new Point (rect.Right, centerY);
1057 g.FillPolygon (ResPool.GetSolidBrush
1058 (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
1061 public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
1063 bool is_add_row = grid.ShowEditRow && row == grid.Rows.Length - 1;
1064 bool is_current_row = row == grid.CurrentCell.RowNumber;
1067 g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
1071 if (is_current_row) {
1072 if (grid.IsChanging) {
1073 g.DrawString ("...", grid.Font,
1074 ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1077 Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
1078 DataGridPaintRowHeaderArrow (g, rect, grid);
1081 else if (is_add_row) {
1082 g.DrawString ("*", grid.Font, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
1086 if (grid.FlatMode == false && !is_add_row) {
1088 g.DrawLine (ResPool.GetPen (ColorControlLight),
1089 bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
1091 g.DrawLine (ResPool.GetPen (ColorControlLight),
1092 bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
1094 g.DrawLine (ResPool.GetPen (ColorControlDark),
1095 bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
1097 g.DrawLine (ResPool.GetPen (ColorControlDark),
1098 bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y + bounds.Height -1);
1102 public override void DataGridPaintRows (Graphics g, Rectangle cells, Rectangle clip, DataGrid grid)
1104 Rectangle rect_row = new Rectangle ();
1105 Rectangle not_usedarea = new Rectangle ();
1107 int rowcnt = grid.VisibleRowCount;
1109 bool showing_add_row = false;
1111 if (grid.ListManager.Count < grid.Rows.Length) {
1112 /* the table has an add row */
1114 if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.Rows.Length) {
1115 showing_add_row = true;
1119 rect_row.Width = cells.Width;
1120 for (int r = 0; r < rowcnt; r++) {
1121 int row = grid.FirstVisibleRow + r;
1122 if (row == grid.Rows.Length - 1)
1123 rect_row.Height = grid.Rows[row].Height;
1125 rect_row.Height = grid.Rows[row + 1].VerticalOffset - grid.Rows[row].VerticalOffset;
1126 rect_row.Y = cells.Y + grid.Rows[row].VerticalOffset - grid.Rows[grid.FirstVisibleRow].VerticalOffset;
1127 if (clip.IntersectsWith (rect_row)) {
1128 if (grid.CurrentTableStyle.HasRelations
1129 && !(showing_add_row && row == grid.Rows.Length - 1))
1130 DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
1132 DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.Rows.Length - 1, clip, grid);
1136 // XXX this should be moved elsewhere and turned into 1 g.FillRectangle call, not grid.Rows.Length separate calls
1137 not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
1138 not_usedarea.Y = rect_row.Y + rect_row.Height;
1139 not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
1142 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
1145 public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1146 Rectangle clip, DataGrid grid)
1148 Rectangle rect_header;
1149 Rectangle icon_bounds = new Rectangle ();
1150 Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor);
1152 /* paint the header if it's visible and intersects the clip */
1153 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1154 rect_header = row_rect;
1155 rect_header.Width = grid.RowHeaderWidth;
1156 row_rect.X += grid.RowHeaderWidth;
1157 if (clip.IntersectsWith (rect_header)) {
1158 DataGridPaintRowHeader (g, rect_header, row, grid);
1161 icon_bounds = rect_header;
1162 icon_bounds.X += icon_bounds.Width / 2;
1164 icon_bounds.Width = 8;
1165 icon_bounds.Height = 8;
1167 g.DrawRectangle (pen, icon_bounds);
1169 /* the - part of the icon */
1171 icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2,
1172 icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2);
1174 if (!grid.IsExpanded (row)) {
1175 /* the | part of the icon */
1177 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2,
1178 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2);
1182 Rectangle nested_rect = row_rect;
1184 if (grid.Rows[row].IsExpanded)
1185 nested_rect.Height -= grid.Rows[row].RelationHeight;
1187 DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
1189 if (grid.Rows[row].IsExpanded) {
1191 //Region prev_clip = g.Clip;
1192 //Region current_clip;
1193 Rectangle rect_cell = row_rect;
1195 rect_cell.X = row_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
1196 rect_cell.Y += nested_rect.Height;
1197 rect_cell.Height = grid.Rows[row].RelationHeight;
1198 rect_cell.Width = 0;
1200 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1201 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++)
1202 rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width;
1204 g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
1207 Rectangle outline = grid.Rows[row].relation_link.Bounds;
1210 icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
1211 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2);
1214 icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
1215 outline.X, outline.Y + outline.Height / 2);
1217 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1218 Rectangle not_usedarea = new Rectangle ();
1219 not_usedarea.X = rect_cell.X + rect_cell.Width;
1220 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1221 not_usedarea.Y = row_rect.Y;
1222 not_usedarea.Height = row_rect.Height;
1223 if (clip.IntersectsWith (not_usedarea))
1224 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1230 public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1231 Rectangle clip, DataGrid grid)
1233 Rectangle rect_cell = new Rectangle ();
1235 Color backcolor, forecolor;
1236 Brush backBrush, foreBrush;
1237 Region prev_clip = g.Clip;
1238 Region current_clip;
1239 Rectangle not_usedarea = new Rectangle ();
1241 rect_cell.Y = row_rect.Y;
1242 rect_cell.Height = row_rect.Height;
1244 if (grid.IsSelected (row)) {
1245 backcolor = grid.SelectionBackColor;
1246 forecolor = grid.SelectionForeColor;
1249 backcolor = grid.BackColor;
1251 backcolor = grid.AlternatingBackColor;
1254 forecolor = grid.ForeColor;
1258 backBrush = ResPool.GetSolidBrush (backcolor);
1259 foreBrush = ResPool.GetSolidBrush (forecolor);
1261 // PaintCells at row, column
1262 int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
1263 for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
1265 col_pixel = grid.GetColumnStartingPixel (column);
1267 rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
1268 rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
1270 if (clip.IntersectsWith (rect_cell)) {
1271 current_clip = new Region (rect_cell);
1272 current_clip.Intersect (row_rect);
1273 current_clip.Intersect (clip);
1274 g.Clip = current_clip;
1277 grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell,
1281 grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
1284 grid.RightToLeft == RightToLeft.Yes);
1287 current_clip.Dispose ();
1293 if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
1294 not_usedarea.X = rect_cell.X + rect_cell.Width;
1295 not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
1296 not_usedarea.Y = row_rect.Y;
1297 not_usedarea.Height = row_rect.Height;
1298 if (clip.IntersectsWith (not_usedarea))
1299 g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
1304 public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
1305 Rectangle clip, DataGrid grid)
1307 /* paint the header if it's visible and intersects the clip */
1308 if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
1309 Rectangle rect_header = row_rect;
1310 rect_header.Width = grid.RowHeaderWidth;
1311 row_rect.X += grid.RowHeaderWidth;
1312 if (clip.IntersectsWith (rect_header)) {
1313 DataGridPaintRowHeader (g, rect_header, row, grid);
1317 DataGridPaintRowContents (g, row, row_rect, is_newrow, clip, grid);
1320 #endregion // Datagrid
1322 #region DateTimePicker
1324 public override void DrawDateTimePicker (Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp) {
1325 // if not showing the numeric updown control then render border
1326 if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
1327 // draw the outer border
1328 Rectangle button_bounds = dtp.ClientRectangle;
1329 this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
1331 // deflate by the border width
1332 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
1333 button_bounds.Inflate (-2,-2);
1334 ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
1335 this.CPDrawComboButton (
1337 dtp.drop_down_arrow_rect,
1342 // render the date part
1343 if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
1344 // fill the background
1345 dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
1347 // fill the currently highlighted area
1348 if (dtp.hilight_date_area != Rectangle.Empty) {
1349 dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
1352 // draw the text part
1353 // TODO: if date format is CUstom then we need to draw the dates as separate parts
1354 StringFormat text_format = new StringFormat();
1355 text_format.LineAlignment = StringAlignment.Center;
1356 text_format.Alignment = StringAlignment.Near;
1357 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
1358 text_format.Dispose ();
1362 #endregion // DateTimePicker
1365 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
1366 StringFormat text_format;
1371 dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
1373 text_format = new StringFormat();
1374 text_format.HotkeyPrefix = HotkeyPrefix.Show;
1376 size = dc.MeasureString (box.Text, box.Font);
1377 width = ((int) size.Width) + 7;
1379 if (width > box.Width - 16)
1380 width = box.Width - 16;
1382 y = box.Font.Height / 2;
1385 CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
1388 if (box.Text.Length != 0) {
1389 Pen pen = ResPool.GetPen (box.BackColor);
1390 dc.DrawLine (pen, 9, y, 8 + width, y);
1391 dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1);
1394 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1396 CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor,
1397 new RectangleF (10, 0, width, box.Font.Height), text_format);
1401 text_format.Dispose ();
1404 public override Size GroupBoxDefaultSize {
1406 return new Size (200,100);
1412 public override Size HScrollBarDefaultSize {
1414 return new Size (80, this.ScrollBarButtonSize);
1418 #endregion // HScrollBar
1421 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label)
1423 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1425 if (label.Enabled) {
1426 dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
1428 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
1433 public override Size LabelDefaultSize {
1435 return new Size (100, 23);
1441 public override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
1443 dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
1445 if (label.pieces == null)
1448 for (int i = 0; i < label.pieces.Length; i ++) {
1449 RectangleF clipf = new RectangleF (clip_rectangle.X, clip_rectangle.Y,
1450 clip_rectangle.Width, clip_rectangle.Height);
1451 RectangleF rectf = label.pieces[i].region.GetBounds (dc);
1453 if (!clipf.IntersectsWith (rectf))
1456 dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.GetPieceColor (label.pieces[i], i)),
1457 rectf, label.string_format);
1459 LinkLabel.Link link = label.pieces[i].link;
1460 if (link != null && link.Focused) {
1461 Rectangle rect = new Rectangle ((int)rectf.X, (int)rectf.Y,
1462 (int)rectf.Width, (int)rectf.Height);
1463 CPDrawFocusRectangle (dc, rect, label.ForeColor, label.BackColor);
1467 #endregion // LinkLabel
1470 public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
1472 Color back_color, fore_color;
1474 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
1475 back_color = ColorHighlight;
1476 fore_color = ColorHighlightText;
1478 back_color = e.BackColor;
1479 fore_color = e.ForeColor;
1482 e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
1484 e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
1485 ResPool.GetSolidBrush (fore_color),
1486 e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
1488 if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
1489 CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
1496 public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
1498 bool details = control.View == View.Details;
1500 dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);
1501 int first = control.FirstVisibleIndex;
1503 for (int i = first; i <= control.LastVisibleIndex; i ++) {
1504 if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
1505 DrawListViewItem (dc, control, control.Items [i]);
1508 // draw the gridlines
1509 if (details && control.GridLines) {
1510 int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
1511 2 : control.Font.Height + 2;
1513 // draw vertical gridlines
1514 foreach (ColumnHeader col in control.Columns)
1515 dc.DrawLine (SystemPens.Control,
1516 col.Rect.Right, top,
1517 col.Rect.Right, control.TotalHeight);
1518 // draw horizontal gridlines
1519 ListViewItem last_item = null;
1520 foreach (ListViewItem item in control.Items) {
1521 dc.DrawLine (SystemPens.Control,
1522 item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
1523 control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
1527 // draw a line after at the bottom of the last item
1528 if (last_item != null) {
1529 dc.DrawLine (SystemPens.Control,
1530 last_item.GetBounds (ItemBoundsPortion.Entire).Left,
1531 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
1533 last_item.GetBounds (ItemBoundsPortion.Entire).Bottom);
1537 // Draw corner between the two scrollbars
1538 if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
1539 Rectangle rect = new Rectangle ();
1540 rect.X = control.h_scroll.Location.X + control.h_scroll.Width;
1541 rect.Width = control.v_scroll.Width;
1542 rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
1543 rect.Height = control.h_scroll.Height;
1544 dc.FillRectangle (SystemBrushes.Control, rect);
1547 Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
1548 if (!box_select_rect.Size.IsEmpty)
1549 dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
1553 public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
1555 bool details = (control.View == View.Details);
1557 // border is drawn directly in the Paint method
1558 if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
1559 dc.FillRectangle (GetControlBackBrush (control.BackColor),
1560 0, 0, control.TotalWidth, control.Font.Height + 5);
1561 if (control.Columns.Count > 0) {
1562 foreach (ColumnHeader col in control.Columns) {
1563 Rectangle rect = col.Rect;
1564 rect.X -= control.h_marker;
1566 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1567 state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
1569 state = ButtonState.Flat;
1570 this.CPDrawButton (dc, rect, state);
1573 if (rect.Width <= 0)
1575 dc.DrawString (col.Text, DefaultFont,
1576 SystemBrushes.ControlText,
1579 int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
1580 if (right < control.Right) {
1581 Rectangle rect = control.Columns [0].Rect;
1583 rect.Width = control.Right - right;
1585 if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
1586 state = ButtonState.Normal;
1588 state = ButtonState.Flat;
1589 CPDrawButton (dc, rect, state);
1595 public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
1597 Rectangle rect = col.Rect;
1598 rect.X -= view.h_marker;
1599 Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
1600 dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
1603 if (rect.Width <= 0)
1605 color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
1606 dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
1607 dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
1610 protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1613 if (control.View == View.Details && control.Columns.Count > 0)
1614 col_offset = control.Columns [0].Rect.X;
1618 Rectangle rect_checkrect = item.CheckRectReal;
1619 rect_checkrect.X += col_offset;
1620 Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
1621 icon_rect.X += col_offset;
1622 Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
1623 full_rect.X += col_offset;
1624 Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);
1625 text_rect.X += col_offset;
1627 if (control.CheckBoxes) {
1628 if (control.StateImageList == null) {
1629 // Make sure we've got at least a line width of 1
1630 int check_wd = Math.Max (3, rect_checkrect.Width / 6);
1631 int scale = Math.Max (1, rect_checkrect.Width / 12);
1633 // set the checkbox background
1634 dc.FillRectangle (SystemBrushes.Window,
1636 // define a rectangle inside the border area
1637 Rectangle rect = new Rectangle (rect_checkrect.X + 2,
1638 rect_checkrect.Y + 2,
1639 rect_checkrect.Width - 4,
1640 rect_checkrect.Height - 4);
1641 Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
1642 dc.DrawRectangle (pen, rect);
1644 // Need to draw a check-mark
1646 Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
1647 // adjustments to get the check-mark at the right place
1648 rect.X ++; rect.Y ++;
1649 // following logic is taken from DrawFrameControl method
1650 for (int i = 0; i < check_wd; i++) {
1651 dc.DrawLine (check_pen, rect.Left + check_wd / 2,
1652 rect.Top + check_wd + i,
1653 rect.Left + check_wd / 2 + 2 * scale,
1654 rect.Top + check_wd + 2 * scale + i);
1655 dc.DrawLine (check_pen,
1656 rect.Left + check_wd / 2 + 2 * scale,
1657 rect.Top + check_wd + 2 * scale + i,
1658 rect.Left + check_wd / 2 + 6 * scale,
1659 rect.Top + check_wd - 2 * scale + i);
1664 if (item.Checked && control.StateImageList.Images.Count > 1)
1665 control.StateImageList.Draw (dc,
1666 rect_checkrect.Location, 1);
1667 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1668 control.StateImageList.Draw (dc,
1669 rect_checkrect.Location, 0);
1673 if (control.View == View.LargeIcon) {
1674 if (item.ImageIndex > -1 && control.LargeImageList != null &&
1675 item.ImageIndex < control.LargeImageList.Images.Count)
1676 control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1678 if (item.ImageIndex > -1 && control.SmallImageList != null &&
1679 item.ImageIndex < control.SmallImageList.Images.Count)
1680 control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
1683 // draw the item text
1684 // format for the item text
1685 StringFormat format = new StringFormat ();
1686 if (control.View == View.SmallIcon)
1687 format.LineAlignment = StringAlignment.Near;
1689 format.LineAlignment = StringAlignment.Center;
1690 if (control.View == View.LargeIcon)
1691 format.Alignment = StringAlignment.Center;
1693 format.Alignment = StringAlignment.Near;
1695 if (!control.LabelWrap)
1696 format.FormatFlags = StringFormatFlags.NoWrap;
1698 Rectangle highlight_rect = text_rect;
1699 if (control.View == View.Details && !control.FullRowSelect) {
1700 Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
1701 highlight_rect.Width = text_size.Width + 4;
1704 if (item.Selected && control.Focused)
1705 dc.FillRectangle (SystemBrushes.Highlight, highlight_rect);
1707 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1710 !control.Enabled ? SystemBrushes.ControlLight :
1711 (item.Selected && control.Focused) ? SystemBrushes.HighlightText :
1712 this.ResPool.GetSolidBrush (item.ForeColor);
1714 if (item.Text != null && item.Text.Length > 0) {
1715 if (item.Selected && control.Focused)
1716 dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format);
1718 dc.DrawString (item.Text, item.Font, textBrush, text_rect, format);
1721 if (control.View == View.Details && control.Columns.Count > 0) {
1722 // draw subitems for details view
1723 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1724 int count = (control.Columns.Count < subItems.Count ?
1725 control.Columns.Count : subItems.Count);
1729 ListViewItem.ListViewSubItem subItem;
1730 Rectangle sub_item_rect = text_rect;
1732 // set the format for subitems
1733 format.FormatFlags = StringFormatFlags.NoWrap;
1735 // 0th subitem is the item already drawn
1736 for (int index = 1; index < count; index++) {
1737 subItem = subItems [index];
1738 col = control.Columns [index];
1739 format.Alignment = col.Format.Alignment;
1740 sub_item_rect.X = col.Rect.X - control.h_marker;
1741 sub_item_rect.Width = col.Wd;
1742 Rectangle sub_item_text_rect = sub_item_rect;
1743 sub_item_text_rect.X += 3;
1744 sub_item_text_rect.Width -= 6;
1746 SolidBrush sub_item_back_br = null;
1747 SolidBrush sub_item_fore_br = null;
1748 Font sub_item_font = null;
1750 if (item.UseItemStyleForSubItems) {
1751 sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
1752 sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
1753 sub_item_font = item.Font;
1755 sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
1756 sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
1757 sub_item_font = subItem.Font;
1760 if (item.Selected && control.FullRowSelect) {
1761 dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
1762 if (subItem.Text != null && subItem.Text.Length > 0)
1763 dc.DrawString (subItem.Text, sub_item_font,
1764 SystemBrushes.HighlightText,
1765 sub_item_text_rect, format);
1767 dc.FillRectangle (sub_item_back_br, sub_item_rect);
1768 if (subItem.Text != null && subItem.Text.Length > 0)
1769 dc.DrawString (subItem.Text, sub_item_font,
1771 sub_item_text_rect, format);
1777 if (item.Focused && control.Focused) {
1778 Rectangle focus_rect = highlight_rect;
1779 if (control.FullRowSelect && control.View == View.Details) {
1781 foreach (ColumnHeader col in control.Columns)
1783 focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
1786 CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
1788 CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
1795 public override Size ListViewCheckBoxSize {
1796 get { return new Size (16, 16); }
1799 public override int ListViewColumnHeaderHeight {
1803 public override int ListViewDefaultColumnWidth {
1807 public override int ListViewVerticalSpacing {
1811 public override int ListViewEmptyColumnWidth {
1815 public override int ListViewHorizontalSpacing {
1819 public override Size ListViewDefaultSize {
1820 get { return new Size (121, 97); }
1822 #endregion // ListView
1825 public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
1830 if (item.Visible == false) {
1836 if (item.Separator == true) {
1837 item.Height = SEPARATOR_HEIGHT / 2;
1842 if (item.MeasureEventDefined) {
1843 MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
1844 item.PerformMeasureItem (mi);
1845 item.Height = mi.ItemHeight;
1846 item.Width = mi.ItemWidth;
1850 size = dc.MeasureString (item.Text, MenuFont);
1851 item.Width = (int) size.Width;
1852 item.Height = (int) size.Height;
1855 if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
1856 item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
1857 size = dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
1858 item.Width += MENU_TAB_SPACE + (int) size.Width;
1861 item.Width += 4 + (MenuCheckSize.Width * 2);
1863 item.Width += MENU_BAR_ITEMS_SPACE;
1867 if (item.Height < MenuHeight)
1868 item.Height = MenuHeight;
1872 // Updates the menu rect and returns the height
1873 public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
1879 foreach (MenuItem item in menu.MenuItems) {
1881 CalcItemSize (dc, item, y, x, true);
1883 if (x + item.Width > width) {
1891 item.MenuBar = true;
1893 if (y + item.Height > menu.Height)
1894 menu.Height = item.Height + y;
1901 public override void CalcPopupMenuSize (Graphics dc, Menu menu)
1909 while (start < menu.MenuItems.Count) {
1912 for (i = start; i < menu.MenuItems.Count; i++) {
1913 MenuItem item = menu.MenuItems [i];
1915 if ((i != start) && (item.Break || item.BarBreak))
1918 CalcItemSize (dc, item, y, x, false);
1921 if (item.Width > max)
1925 // Replace the -1 by the menu width (separators)
1926 for (n = start; n < i; n++, start++)
1927 menu.MenuItems [n].Width = max;
1929 if (y > menu.Height)
1941 menu.Width += SM_CXBORDER;
1942 menu.Height += SM_CYBORDER;
1945 // Draws a menu bar in a window
1946 public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
1948 if (menu.Height == 0)
1949 CalcMenuBarSize (dc, menu, rect.Width);
1951 bool keynav = (menu as MainMenu).tracker.Navigating;
1952 HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
1953 string_format_menu_menubar_text.HotkeyPrefix = hp;
1954 string_format_menu_text.HotkeyPrefix = hp;
1956 rect.Height = menu.Height;
1957 dc.FillRectangle (SystemBrushes.Menu, rect);
1959 for (int i = 0; i < menu.MenuItems.Count; i++) {
1960 MenuItem item = menu.MenuItems [i];
1961 Rectangle item_rect = item.bounds;
1962 item_rect.X += rect.X;
1963 item_rect.Y += rect.Y;
1964 item.MenuHeight = menu.Height;
1965 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status));
1969 protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
1972 if (color.R == 0 && color.G == 0 && color.B == 0)
1973 bg_color = Color.White;
1975 bg_color = Color.Black;
1976 Bitmap bmp = new Bitmap (size.Width, size.Height);
1977 Graphics gr = Graphics.FromImage (bmp);
1978 Rectangle rect = new Rectangle (Point.Empty, size);
1979 gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
1980 CPDrawMenuGlyph (gr, rect, glyph, color);
1981 bmp.MakeTransparent (bg_color);
1986 public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
1988 StringFormat string_format;
1989 Rectangle rect_text = e.Bounds;
1991 if (item.Visible == false)
1995 string_format = string_format_menu_menubar_text;
1997 string_format = string_format_menu_text;
1999 if (item.Separator == true) {
2000 e.Graphics.DrawLine (SystemPens.ControlDark,
2001 e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
2003 e.Graphics.DrawLine (SystemPens.ControlLight,
2004 e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
2010 rect_text.X += MenuCheckSize.Width;
2012 if (item.BarBreak) { /* Draw vertical break bar*/
2013 Rectangle rect = e.Bounds;
2016 rect.Height = item.MenuHeight - 6;
2018 e.Graphics.DrawLine (SystemPens.ControlDark,
2019 rect.X, rect.Y , rect.X, rect.Y + rect.Height);
2021 e.Graphics.DrawLine (SystemPens.ControlLight,
2022 rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
2027 Brush brush_text = null;
2028 Brush brush_back = null;
2030 if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
2031 color_text = ColorHighlightText;
2032 color_back = ColorHighlight;
2033 brush_text = SystemBrushes.HighlightText;
2034 brush_back = SystemBrushes.Highlight;
2036 color_text = ColorMenuText;
2037 color_back = ColorMenu;
2038 brush_text = ResPool.GetSolidBrush (ColorMenuText);
2039 brush_back = SystemBrushes.Menu;
2042 /* Draw background */
2043 Rectangle rect_back = e.Bounds;
2045 rect_back.Width -=2;
2047 e.Graphics.FillRectangle (brush_back, rect_back);
2050 e.Graphics.DrawString (item.Text, e.Font,
2052 rect_text, string_format);
2054 if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
2055 string str = item.GetShortCutText ();
2056 Rectangle rect = rect_text;
2058 rect.Width -= item.XTab;
2060 e.Graphics.DrawString (str, e.Font, brush_text,
2061 rect, string_format_menu_shortcut);
2065 Border3DStyle border_style = Border3DStyle.Adjust;
2066 if ((item.Status & DrawItemState.HotLight) != 0)
2067 border_style = Border3DStyle.RaisedInner;
2068 else if ((item.Status & DrawItemState.Selected) != 0)
2069 border_style = Border3DStyle.SunkenOuter;
2071 if (border_style != Border3DStyle.Adjust)
2072 CPDrawBorder3D(e.Graphics, rect_back, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
2075 if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
2076 e.Graphics.DrawString (item.Text, e.Font, Brushes.White,
2077 new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
2081 e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
2085 if (item.MenuBar == false && item.IsPopup || item.MdiList) {
2087 int cx = MenuCheckSize.Width;
2088 int cy = MenuCheckSize.Height;
2089 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
2092 e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
2093 e.Bounds.Y + ((e.Bounds.Height - cy) /2));
2095 ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
2096 e.Bounds.Y + ((e.Bounds.Height - cy) /2), color_back);
2102 /* Draw checked or radio */
2103 if (item.MenuBar == false && item.Checked) {
2105 Rectangle area = e.Bounds;
2106 int cx = MenuCheckSize.Width;
2107 int cy = MenuCheckSize.Height;
2108 Bitmap bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
2110 e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
2116 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
2119 dc.FillRectangle (SystemBrushes.Menu, cliparea);
2121 Pen pen_cht = SystemPens.HighlightText;
2122 Pen pen_ccd = SystemPens.ControlDark;
2123 Pen pen_ccdd = SystemPens.ControlDarkDark;
2125 /* Draw menu borders */
2126 dc.DrawLine (pen_cht,
2127 rect.X, rect.Y, rect.X + rect.Width, rect.Y);
2129 dc.DrawLine (pen_cht,
2130 rect.X, rect.Y, rect.X, rect.Y + rect.Height);
2132 dc.DrawLine (pen_ccd,
2133 rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
2135 dc.DrawLine (pen_ccdd,
2136 rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
2138 dc.DrawLine (pen_ccd,
2139 rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
2141 dc.DrawLine (pen_ccdd,
2142 rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
2144 for (int i = 0; i < menu.MenuItems.Count; i++)
2145 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
2146 MenuItem item = menu.MenuItems [i];
2147 item.MenuHeight = menu.Height;
2148 item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
2149 item.bounds, i, item.Status));
2155 #region MonthCalendar
2157 // draw the month calendar
2158 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc)
2160 Rectangle client_rectangle = mc.ClientRectangle;
2161 Size month_size = mc.SingleMonthSize;
2162 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2163 Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2164 Size date_cell_size = (Size)((object)mc.date_cell_size);
2166 // draw the singlecalendars
2169 // adjust for the position of the specific month
2170 for (int i=0; i < mc.CalendarDimensions.Height; i++)
2174 y_offset += month_size.Height + calendar_spacing.Height;
2176 // now adjust for x position
2177 for (int j=0; j < mc.CalendarDimensions.Width; j++)
2181 x_offset += month_size.Width + calendar_spacing.Width;
2188 Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2189 if (month_rect.IntersectsWith (clip_rectangle)) {
2201 Rectangle bottom_rect = new Rectangle (
2203 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2204 client_rectangle.Width,
2205 date_cell_size.Height + 2);
2206 // draw the today date if it's set
2207 if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle))
2209 dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
2211 int today_offset = 5;
2212 if (mc.ShowTodayCircle)
2214 Rectangle today_circle_rect = new Rectangle (
2215 client_rectangle.X + 5,
2216 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2217 date_cell_size.Width,
2218 date_cell_size.Height);
2219 DrawTodayCircle (dc, today_circle_rect);
2220 today_offset += date_cell_size.Width + 5;
2222 // draw today's date
2223 StringFormat text_format = new StringFormat();
2224 text_format.LineAlignment = StringAlignment.Center;
2225 text_format.Alignment = StringAlignment.Near;
2226 Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2227 Rectangle today_rect = new Rectangle (
2228 today_offset + client_rectangle.X,
2229 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2230 Math.Max(client_rectangle.Width - today_offset, 0),
2231 date_cell_size.Height);
2232 dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
2233 text_format.Dispose ();
2234 bold_font.Dispose ();
2238 // finally paint the borders of the calendars as required
2239 for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2240 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2241 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
2242 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2243 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
2245 Rectangle rect = new Rectangle (
2246 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2248 calendar_spacing.Width,
2249 client_rectangle.Height);
2250 if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2251 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2255 for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2256 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2257 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
2258 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2259 dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
2261 Rectangle rect = new Rectangle (
2263 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2264 client_rectangle.Width,
2265 calendar_spacing.Height);
2266 if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2267 dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
2272 // draw the drop down border if need
2273 if (mc.owner != null) {
2274 Rectangle bounds = mc.ClientRectangle;
2275 if (clip_rectangle.Contains (mc.Location)) {
2276 // find out if top or left line to draw
2277 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2279 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2281 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2282 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2285 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2286 // find out if bottom or right line to draw
2287 if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2288 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2290 if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2291 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2297 // darws a single part of the month calendar (with one month)
2298 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col)
2300 // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2301 Size title_size = (Size)((object)mc.title_size);
2302 Size date_cell_size = (Size)((object)mc.date_cell_size);
2303 DateTime current_month = (DateTime)((object)mc.current_month);
2305 // set up some standard string formating variables
2306 StringFormat text_format = new StringFormat();
2307 text_format.LineAlignment = StringAlignment.Center;
2308 text_format.Alignment = StringAlignment.Center;
2311 // draw the title back ground
2312 DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2313 Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2314 if (title_rect.IntersectsWith (clip_rectangle)) {
2315 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2317 string title_text = this_month.ToString ("MMMM yyyy");
2318 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2320 // draw previous and next buttons if it's time
2321 if (row == 0 && col == 0)
2323 // draw previous button
2324 DrawMonthCalendarButton (
2330 (System.Drawing.Size)((object)mc.button_size),
2333 if (row == 0 && col == mc.CalendarDimensions.Width-1)
2336 DrawMonthCalendarButton (
2342 (System.Drawing.Size)((object)mc.button_size),
2347 // set the week offset and draw week nums if needed
2348 int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2349 Rectangle day_name_rect = new Rectangle(
2351 rectangle.Y + title_size.Height,
2352 (7 + col_offset) * date_cell_size.Width,
2353 date_cell_size.Height);
2354 if (day_name_rect.IntersectsWith (clip_rectangle)) {
2355 dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
2356 // draw the day names
2357 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2358 for (int i=0; i < 7; i++)
2360 int position = i - (int) first_day_of_week;
2363 position = 7 + position;
2366 Rectangle day_rect = new Rectangle(
2367 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2369 date_cell_size.Width,
2370 date_cell_size.Height);
2371 dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2374 // draw the vertical divider
2375 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2377 ResPool.GetPen (mc.ForeColor),
2378 rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2379 rectangle.Y + vert_divider_y,
2380 rectangle.Right - mc.divider_line_offset,
2381 rectangle.Y + vert_divider_y);
2385 // draw the actual date items in the grid (including the week numbers)
2386 Rectangle date_rect = new Rectangle (
2388 rectangle.Y + title_size.Height + date_cell_size.Height,
2389 date_cell_size.Width,
2390 date_cell_size.Height);
2391 int month_row_count = 0;
2392 bool draw_week_num_divider = false;
2393 DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2394 for (int i=0; i < 6; i++)
2396 // establish if this row is in our clip_area
2397 Rectangle row_rect = new Rectangle (
2399 rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2400 date_cell_size.Width * 7,
2401 date_cell_size.Height);
2402 if (mc.ShowWeekNumbers) {
2403 row_rect.Width += date_cell_size.Width;
2406 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2408 dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
2410 // establish if this is a valid week to draw
2411 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2412 month_row_count = i;
2415 // draw the week number if required
2416 if (mc.ShowWeekNumbers && month_row_count == i) {
2417 if (!draw_week_num_divider) {
2418 draw_week_num_divider = draw_row;
2420 // get the week for this row
2421 int week = mc.GetWeekOfYear (current_date);
2427 ResPool.GetSolidBrush (mc.TitleBackColor),
2431 date_rect.Offset(date_cell_size.Width, 0);
2434 // only draw the days if we have to
2435 if(month_row_count == i) {
2436 for (int j=0; j < 7; j++)
2439 DrawMonthCalendarDate (
2450 current_date = current_date.AddDays(1);
2451 date_rect.Offset(date_cell_size.Width, 0);
2454 // shift the rectangle down one row
2455 int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2456 date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2460 // month_row_count is zero based, so add one
2463 // draw week numbers if required
2464 if (draw_week_num_divider) {
2467 ResPool.GetPen (mc.ForeColor),
2468 rectangle.X + date_cell_size.Width - 1,
2469 rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2470 rectangle.X + date_cell_size.Width - 1,
2471 rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2473 text_format.Dispose ();
2476 // draws the pervious or next button
2477 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous)
2479 bool is_clicked = false;
2480 Rectangle button_rect;
2481 Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2482 Point[] arrow_path = new Point[3];
2483 // prepare the button
2486 is_clicked = mc.is_previous_clicked;
2487 button_rect = new Rectangle (
2488 rectangle.X + 1 + x_offset,
2489 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2490 Math.Max(button_size.Width - 1, 0),
2491 Math.Max(button_size.Height - 1, 0));
2492 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2493 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2495 arrow_rect.Offset(1,1);
2497 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2498 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2499 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2503 is_clicked = mc.is_next_clicked;
2504 button_rect = new Rectangle (
2505 rectangle.Right - 1 - x_offset - button_size.Width,
2506 rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2507 Math.Max(button_size.Width - 1, 0),
2508 Math.Max(button_size.Height - 1, 0));
2509 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2510 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2512 arrow_rect.Offset(1,1);
2514 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2515 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2516 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);
2519 // fill the background
2520 dc.FillRectangle (SystemBrushes.Control, button_rect);
2523 dc.DrawRectangle (SystemPens.ControlDark, button_rect);
2526 CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
2529 dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2533 // draws one day in the calendar grid
2534 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2535 Color date_color = mc.ForeColor;
2536 Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2538 // find out if we are the lead of the first calendar or the trail of the last calendar
2539 if (date.Year != month.Year || date.Month != month.Month) {
2540 DateTime check_date = month.AddMonths (-1);
2541 // check if it's the month before
2542 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2543 date_color = mc.TrailingForeColor;
2545 // check if it's the month after
2546 check_date = month.AddMonths (1);
2547 if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2548 date_color = mc.TrailingForeColor;
2554 date_color = mc.ForeColor;
2558 if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2559 // see if the date is in the start of selection
2560 date_color = mc.BackColor;
2561 // draw the left hand of the back ground
2562 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2563 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2564 } else if (date == mc.SelectionStart) {
2565 // see if the date is in the start of selection
2566 date_color = mc.BackColor;
2567 // draw the left hand of the back ground
2568 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2569 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
2570 // fill the other side as a straight rect
2571 if (date < mc.SelectionEnd)
2573 // use rectangle instead of rectangle to go all the way to edge of rect
2574 selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
2575 selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
2576 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2578 } else if (date == mc.SelectionEnd) {
2579 // see if it is the end of selection
2580 date_color = mc.BackColor;
2581 // draw the left hand of the back ground
2582 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
2583 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
2584 // fill the other side as a straight rect
2585 if (date > mc.SelectionStart) {
2586 selection_rect.X = rectangle.X;
2587 selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
2588 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2590 } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
2591 // now see if it's in the middle
2592 date_color = mc.BackColor;
2593 // draw the left hand of the back ground
2594 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
2595 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
2598 // set up some standard string formating variables
2599 StringFormat text_format = new StringFormat();
2600 text_format.LineAlignment = StringAlignment.Center;
2601 text_format.Alignment = StringAlignment.Center;
2604 // establish if it's a bolded font
2606 if (mc.IsBoldedDate (date)) {
2607 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2612 // just draw the date now
2613 dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
2615 // today circle if needed
2616 if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
2617 DrawTodayCircle (dc, interior);
2620 // draw the selection grid
2621 if (mc.is_date_clicked && mc.clicked_date == date) {
2622 Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
2623 dc.DrawRectangle (pen, interior);
2625 text_format.Dispose ();
2628 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
2629 Color circle_color = Color.FromArgb (248, 0, 0);
2630 // draw the left hand of the circle
2631 Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
2632 Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
2633 Point [] curve_points = new Point [3];
2634 curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
2635 curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
2636 curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
2638 Pen pen = ResPool.GetSizedPen(circle_color, 2);
2639 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
2640 dc.DrawArc (pen, rhs_circle_rect, 270, 180);
2641 dc.DrawCurve (pen, curve_points);
2642 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
2645 #endregion // MonthCalendar
2648 public override Size PanelDefaultSize {
2650 return new Size (200, 100);
2656 public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
2657 Rectangle client = pb.ClientRectangle;
2659 // FIXME - instead of drawing the whole picturebox every time
2660 // intersect the clip rectangle with the drawn picture and only draw what's needed,
2661 // Also, we only need a background fill where no image goes
2662 if (pb.Image != null) {
2663 switch (pb.SizeMode) {
2664 case PictureBoxSizeMode.StretchImage:
2665 dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
2668 case PictureBoxSizeMode.CenterImage:
2669 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2670 dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
2673 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2675 dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
2682 // We only get here if no image is set. At least paint the background
2683 dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
2686 public override Size PictureBoxDefaultSize {
2688 return new Size (100, 50);
2691 #endregion // PictureBox
2694 public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl)
2696 Rectangle block_rect;
2697 Rectangle client_area = ctrl.client_area;
2698 int space_betweenblocks = 2;
2703 block_width = (client_area.Height * 2 ) / 3;
2704 barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
2705 increment = block_width + space_betweenblocks;
2708 CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
2711 block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
2712 while ((block_rect.X - client_area.X) < barpos_pixels) {
2714 if (clip_rect.IntersectsWith (block_rect) == true) {
2715 dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
2718 block_rect.X += increment;
2722 public override Size ProgressBarDefaultSize {
2724 return new Size (100, 23);
2728 #endregion // ProgressBar
2731 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
2732 StringFormat text_format;
2733 Rectangle client_rectangle;
2734 Rectangle text_rectangle;
2735 Rectangle radiobutton_rectangle;
2736 int radiobutton_size = 13;
2737 int radiobutton_space = 4;
2739 client_rectangle = radio_button.ClientRectangle;
2740 text_rectangle = client_rectangle;
2741 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
2743 text_format = new StringFormat();
2744 text_format.Alignment = StringAlignment.Near;
2745 text_format.LineAlignment = StringAlignment.Center;
2746 text_format.HotkeyPrefix = HotkeyPrefix.Show;
2748 /* Calculate the position of text and checkbox rectangle */
2749 if (radio_button.appearance!=Appearance.Button) {
2750 switch(radio_button.radiobutton_alignment) {
2751 case ContentAlignment.BottomCenter: {
2752 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2753 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2754 text_rectangle.X=client_rectangle.X;
2755 text_rectangle.Width=client_rectangle.Width;
2756 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2760 case ContentAlignment.BottomLeft: {
2761 radiobutton_rectangle.X=client_rectangle.Left;
2762 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2763 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2764 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2768 case ContentAlignment.BottomRight: {
2769 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2770 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
2771 text_rectangle.X=client_rectangle.X;
2772 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2776 case ContentAlignment.MiddleCenter: {
2777 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2778 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2779 text_rectangle.X=client_rectangle.X;
2780 text_rectangle.Width=client_rectangle.Width;
2785 case ContentAlignment.MiddleLeft: {
2786 radiobutton_rectangle.X=client_rectangle.Left;
2787 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2788 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2789 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2793 case ContentAlignment.MiddleRight: {
2794 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2795 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
2796 text_rectangle.X=client_rectangle.X;
2797 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2801 case ContentAlignment.TopCenter: {
2802 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
2803 radiobutton_rectangle.Y=client_rectangle.Top;
2804 text_rectangle.X=client_rectangle.X;
2805 text_rectangle.Y=radiobutton_size+radiobutton_space;
2806 text_rectangle.Width=client_rectangle.Width;
2807 text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
2811 case ContentAlignment.TopLeft: {
2812 radiobutton_rectangle.X=client_rectangle.Left;
2813 radiobutton_rectangle.Y=client_rectangle.Top;
2814 text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
2815 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2819 case ContentAlignment.TopRight: {
2820 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
2821 radiobutton_rectangle.Y=client_rectangle.Top;
2822 text_rectangle.X=client_rectangle.X;
2823 text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
2828 text_rectangle.X=client_rectangle.X;
2829 text_rectangle.Width=client_rectangle.Width;
2832 /* Set the horizontal alignment of our text */
2833 switch(radio_button.text_alignment) {
2834 case ContentAlignment.BottomLeft:
2835 case ContentAlignment.MiddleLeft:
2836 case ContentAlignment.TopLeft: {
2837 text_format.Alignment=StringAlignment.Near;
2841 case ContentAlignment.BottomCenter:
2842 case ContentAlignment.MiddleCenter:
2843 case ContentAlignment.TopCenter: {
2844 text_format.Alignment=StringAlignment.Center;
2848 case ContentAlignment.BottomRight:
2849 case ContentAlignment.MiddleRight:
2850 case ContentAlignment.TopRight: {
2851 text_format.Alignment=StringAlignment.Far;
2856 /* Set the vertical alignment of our text */
2857 switch(radio_button.text_alignment) {
2858 case ContentAlignment.TopLeft:
2859 case ContentAlignment.TopCenter:
2860 case ContentAlignment.TopRight: {
2861 text_format.LineAlignment=StringAlignment.Near;
2865 case ContentAlignment.BottomLeft:
2866 case ContentAlignment.BottomCenter:
2867 case ContentAlignment.BottomRight: {
2868 text_format.LineAlignment=StringAlignment.Far;
2872 case ContentAlignment.MiddleLeft:
2873 case ContentAlignment.MiddleCenter:
2874 case ContentAlignment.MiddleRight: {
2875 text_format.LineAlignment=StringAlignment.Center;
2880 ButtonState state = ButtonState.Normal;
2881 if (radio_button.FlatStyle == FlatStyle.Flat) {
2882 state |= ButtonState.Flat;
2885 if (radio_button.Checked) {
2886 state |= ButtonState.Checked;
2889 if (!radio_button.Enabled) {
2890 state |= ButtonState.Inactive;
2894 RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
2896 if ((radio_button.image != null) || (radio_button.image_list != null))
2897 ButtonBase_DrawImage(radio_button, dc);
2899 RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
2901 RadioButton_DrawFocus(radio_button, dc, text_rectangle);
2903 text_format.Dispose ();
2906 protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
2908 dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
2910 if (radio_button.appearance==Appearance.Button) {
2911 ButtonBase_DrawButton (radio_button, dc);
2913 if ((radio_button.Focused) && radio_button.Enabled)
2914 ButtonBase_DrawFocus(radio_button, dc);
2916 // establish if we are rendering a flat style of some sort
2917 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
2918 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
2920 CPDrawRadioButton(dc, radiobutton_rectangle, state);
2925 protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
2927 DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc,
2928 text_format, radio_button.Appearance, radio_button.Checked);
2931 protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
2933 if ( radio_button.Focused && radio_button.appearance != Appearance.Button && radio_button.Enabled )
2934 DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor );
2937 // renders a radio button with the Flat and Popup FlatStyle
2938 protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
2942 if (radio_button.Enabled) {
2944 // draw the outer flatstyle arcs
2945 if (radio_button.FlatStyle == FlatStyle.Flat) {
2946 graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
2948 // fill in the area depending on whether or not the mouse is hovering
2949 if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
2950 graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2952 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2955 // must be a popup radio button
2957 graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
2959 if (radio_button.is_entered || radio_button.Capture) {
2960 // draw the popup 3d button knob
2961 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
2963 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
2964 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
2967 // just draw lighter flatstyle outer circle
2968 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2973 // fill control background color regardless of actual backcolor
2974 graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
2975 // draw the ark as control dark
2976 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
2980 if (radio_button.Checked) {
2981 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
2983 Pen dot_pen = SystemPens.ControlDarkDark;
2984 Brush dot_brush = SystemBrushes.ControlDarkDark;
2986 if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
2987 dot_pen = SystemPens.ControlDark;
2988 dot_brush = SystemBrushes.ControlDark;
2991 if (rectangle.Height > 13) {
2992 graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
2994 int x_half_pos = (rectangle.Width / 2) + rectangle.X;
2995 int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
2997 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
2998 graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
3000 graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
3001 graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
3006 public override Size RadioButtonDefaultSize {
3008 return new Size (104,24);
3011 #endregion // RadioButton
3014 public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
3016 int scrollbutton_width = bar.scrollbutton_width;
3017 int scrollbutton_height = bar.scrollbutton_height;
3018 Rectangle first_arrow_area;
3019 Rectangle second_arrow_area;
3020 Rectangle thumb_pos;
3022 thumb_pos = bar.ThumbPos;
3025 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
3026 bar.FirstArrowArea = first_arrow_area;
3028 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
3029 bar.SecondArrowArea = second_arrow_area;
3031 thumb_pos.Width = bar.Width;
3032 bar.ThumbPos = thumb_pos;
3035 if (clip.IntersectsWith (first_arrow_area))
3036 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
3037 if (clip.IntersectsWith (second_arrow_area))
3038 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
3041 switch (bar.thumb_moving) {
3042 case ScrollBar.ThumbMoving.None: {
3043 ScrollBar_Vertical_Draw_ThumbMoving_None(scrollbutton_height, bar, clip, dc);
3046 case ScrollBar.ThumbMoving.Forward: {
3047 ScrollBar_Vertical_Draw_ThumbMoving_Forward(scrollbutton_height, bar, thumb_pos, clip, dc);
3051 case ScrollBar.ThumbMoving.Backwards: {
3052 ScrollBar_Vertical_Draw_ThumbMoving_Backwards(scrollbutton_height, bar, thumb_pos, clip, dc);
3060 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
3061 bar.FirstArrowArea = first_arrow_area;
3063 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
3064 bar.SecondArrowArea = second_arrow_area;
3066 thumb_pos.Height = bar.Height;
3067 bar.ThumbPos = thumb_pos;
3070 if (clip.IntersectsWith (first_arrow_area))
3071 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
3072 if (clip.IntersectsWith (second_arrow_area))
3073 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
3076 switch (bar.thumb_moving) {
3077 case ScrollBar.ThumbMoving.None: {
3078 ScrollBar_Horizontal_Draw_ThumbMoving_None(scrollbutton_width, bar, clip, dc);
3082 case ScrollBar.ThumbMoving.Forward: {
3083 ScrollBar_Horizontal_Draw_ThumbMoving_Forward(scrollbutton_width, thumb_pos, bar, clip, dc);
3087 case ScrollBar.ThumbMoving.Backwards: {
3088 ScrollBar_Horizontal_Draw_ThumbMoving_Backwards(scrollbutton_width, thumb_pos, bar, clip, dc);
3095 ScrollBar_DrawThumb(bar, thumb_pos, clip, dc);
3098 protected virtual void ScrollBar_DrawThumb(ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc)
3100 if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith(thumb_pos))
3101 DrawScrollButtonPrimitive(dc, thumb_pos, ButtonState.Normal);
3104 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
3106 Rectangle r = new Rectangle( 0,
3107 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
3108 Rectangle intersect = Rectangle.Intersect( clip, r );
3110 if ( intersect != Rectangle.Empty )
3112 Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
3113 dc.FillRectangle( h, intersect );
3117 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3119 Rectangle r = new Rectangle( 0, scrollbutton_height,
3120 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3121 Rectangle intersect = Rectangle.Intersect( clip, r );
3123 if ( intersect != Rectangle.Empty )
3124 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
3127 r.Y = thumb_pos.Y + thumb_pos.Height;
3128 r.Width = bar.ClientRectangle.Width;
3129 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3131 intersect = Rectangle.Intersect( clip, r );
3132 if ( intersect != Rectangle.Empty )
3133 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3136 protected virtual void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
3138 Rectangle r = new Rectangle( 0, scrollbutton_height,
3139 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
3140 Rectangle intersect = Rectangle.Intersect( clip, r );
3142 if ( intersect != Rectangle.Empty )
3143 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3146 r.Y = thumb_pos.Y + thumb_pos.Height;
3147 r.Width = bar.ClientRectangle.Width;
3148 r.Height = bar.ClientRectangle.Height - ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
3150 intersect = Rectangle.Intersect( clip, r );
3151 if ( intersect != Rectangle.Empty )
3152 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3155 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
3157 Rectangle r = new Rectangle( scrollbutton_width,
3158 0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
3159 Rectangle intersect = Rectangle.Intersect( clip, r );
3161 if ( intersect != Rectangle.Empty )
3162 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3165 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3167 Rectangle r = new Rectangle( scrollbutton_width, 0,
3168 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3169 Rectangle intersect = Rectangle.Intersect( clip, r );
3171 if ( intersect != Rectangle.Empty )
3172 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3174 r.X = thumb_pos.X + thumb_pos.Width;
3176 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3177 r.Height = bar.ClientRectangle.Height;
3179 intersect = Rectangle.Intersect( clip, r );
3180 if ( intersect != Rectangle.Empty )
3181 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3184 protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
3186 Rectangle r = new Rectangle( scrollbutton_width, 0,
3187 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
3188 Rectangle intersect = Rectangle.Intersect( clip, r );
3190 if ( intersect != Rectangle.Empty )
3191 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, Color.FromArgb( 255, 63, 63, 63 ), Color.Black ), intersect );
3193 r.X = thumb_pos.X + thumb_pos.Width;
3195 r.Width = bar.ClientRectangle.Width - ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
3196 r.Height = bar.ClientRectangle.Height;
3198 intersect = Rectangle.Intersect( clip, r );
3199 if ( intersect != Rectangle.Empty )
3200 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
3203 public override int ScrollBarButtonSize {
3206 #endregion // ScrollBar
3209 public override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
3210 Rectangle area = sb.ClientRectangle;
3211 int horz_border = 2;
3212 int vert_border = 2;
3214 bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
3216 Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
3217 dc.FillRectangle (brush, clip);
3219 if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
3220 string text = sb.Text;
3221 StringFormat string_format = new StringFormat ();
3222 string_format.Trimming = StringTrimming.Character;
3223 string_format.FormatFlags = StringFormatFlags.NoWrap;
3225 if (text [0] == '\t') {
3226 string_format.Alignment = StringAlignment.Center;
3227 text = text.Substring (1);
3228 if (text [0] == '\t') {
3229 string_format.Alignment = StringAlignment.Far;
3230 text = text.Substring (1);
3234 dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
3235 new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
3236 string_format.Dispose ();
3237 } else if (sb.ShowPanels) {
3238 Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
3239 int prev_x = area.X + horz_border;
3240 int y = area.Y + vert_border;
3241 for (int i = 0; i < sb.Panels.Count; i++) {
3242 Rectangle pr = new Rectangle (prev_x, y,
3243 sb.Panels [i].Width, area.Height);
3244 prev_x += pr.Width + StatusBarHorzGapWidth;
3245 if (pr.IntersectsWith (clip))
3246 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
3250 if (sb.SizingGrip) {
3251 area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
3252 CPDrawSizeGrip (dc, ColorControl, area);
3258 protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
3259 Brush br_forecolor, StatusBarPanel panel) {
3260 int border_size = 3; // this is actually const, even if the border style is none
3261 int icon_width = 16;
3263 area.Height -= border_size;
3265 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
3266 Border3DStyle border_style = Border3DStyle.SunkenOuter;
3267 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
3268 border_style = Border3DStyle.RaisedInner;
3270 CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
3273 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
3274 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
3275 dc, panel.Parent.Font, area, index, DrawItemState.Default,
3276 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
3277 panel.Parent.OnDrawItemInternal (e);
3281 if (panel.Text == String.Empty)
3284 string text = panel.Text;
3285 StringFormat string_format = new StringFormat ();
3286 string_format.Trimming = StringTrimming.Character;
3287 string_format.FormatFlags = StringFormatFlags.NoWrap;
3290 if (text [0] == '\t') {
3291 string_format.Alignment = StringAlignment.Center;
3292 text = text.Substring (1);
3293 if (text [0] == '\t') {
3294 string_format.Alignment = StringAlignment.Far;
3295 text = text.Substring (1);
3299 Rectangle string_rect = Rectangle.Empty;
3303 int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
3305 switch (panel.Alignment) {
3306 case HorizontalAlignment.Right:
3307 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3308 x = area.Right - len - 4;
3309 string_rect = new Rectangle (x, y,
3310 area.Right - x - border_size,
3311 area.Bottom - y - border_size);
3312 if (panel.Icon != null) {
3313 icon_x = x - icon_width - 2;
3316 case HorizontalAlignment.Center:
3317 len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
3318 x = (panel.Width / 2) + (len / 2);
3319 string_rect = new Rectangle (x, y,
3320 area.Right - x - border_size,
3321 area.Bottom - y - border_size);
3323 if (panel.Icon != null) {
3324 icon_x = x - icon_width - 2;
3330 int left = area.Left + border_size;;
3331 if (panel.Icon != null) {
3332 icon_x = area.Left + 2;
3333 left = icon_x + icon_width + 2;
3337 string_rect = new Rectangle (x, y,
3338 area.Right - x - border_size,
3339 area.Bottom - y - border_size);
3343 dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);
3345 if (panel.Icon != null) {
3346 dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
3350 public override int StatusBarSizeGripWidth {
3354 public override int StatusBarHorzGapWidth {
3358 public override Size StatusBarDefaultSize {
3360 return new Size (100, 22);
3363 #endregion // StatusBar
3365 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
3367 Brush brush = SystemBrushes.Control;
3368 dc.FillRectangle (brush, area);
3369 Rectangle panel_rect = GetTabPanelRectExt (tab);
3371 if (tab.Appearance == TabAppearance.Normal) {
3372 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorControl);
3373 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorControl);
3376 if (tab.Alignment == TabAlignment.Top) {
3377 for (int r = tab.TabPages.Count; r > 0; r--) {
3378 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3379 if (i == tab.SelectedIndex)
3381 if (r != tab.TabPages [i].Row)
3383 Rectangle rect = tab.GetTabRect (i);
3384 if (!rect.IntersectsWith (area))
3386 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3390 for (int r = 0; r < tab.TabPages.Count; r++) {
3391 for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
3392 if (i == tab.SelectedIndex)
3394 if (r != tab.TabPages [i].Row)
3396 Rectangle rect = tab.GetTabRect (i);
3397 if (!rect.IntersectsWith (area))
3399 DrawTab (dc, tab.TabPages [i], tab, rect, false);
3404 if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
3405 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
3406 if (rect.IntersectsWith (area))
3407 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
3410 if (tab.ShowSlider) {
3411 Rectangle right = GetTabControlRightScrollRect (tab);
3412 Rectangle left = GetTabControlLeftScrollRect (tab);
3413 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
3414 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
3418 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
3420 switch (tab.Alignment) {
3421 case TabAlignment.Top:
3422 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
3424 Rectangle panel_rect = GetTabPanelRectExt (tab);
3425 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
3429 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
3431 switch (tab.Alignment) {
3432 case TabAlignment.Top:
3433 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
3435 Rectangle panel_rect = GetTabPanelRectExt (tab);
3436 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
3440 public override Size TabControlDefaultItemSize {
3441 get { return new Size (42, 21); }
3444 public override Point TabControlDefaultPadding {
3445 get { return new Point (6, 3); }
3448 public override int TabControlMinimumTabWidth {
3452 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
3454 Rectangle ext = GetTabPanelRectExt (tab);
3455 // Account for border size
3456 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
3459 public override Size TabControlGetSpacing (TabControl tab) {
3460 switch (tab.Appearance) {
3461 case TabAppearance.Normal:
3462 return new Size (1, -2);
3463 case TabAppearance.Buttons:
3464 return new Size (3, 3);
3465 case TabAppearance.FlatButtons:
3466 return new Size (9, 3);
3468 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
3472 protected virtual Rectangle GetTabPanelRectExt (TabControl tab)
3474 // Offset the tab from the top corner
3475 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
3476 tab.ClientRectangle.Y,
3477 tab.ClientRectangle.Width - 2,
3478 tab.ClientRectangle.Height - 1);
3480 if (tab.TabCount == 0)
3483 int spacing = TabControlGetSpacing (tab).Height;
3484 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
3486 switch (tab.Alignment) {
3487 case TabAlignment.Left:
3489 res.Width -= offset;
3491 case TabAlignment.Right:
3492 res.Width -= offset;
3494 case TabAlignment.Top:
3496 res.Height -= offset;
3498 case TabAlignment.Bottom:
3499 res.Height -= offset;
3506 protected virtual int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
3508 int FlatButtonSpacing = 8;
3510 int res = bounds.Width;
3514 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
3516 StringFormat string_format = new StringFormat ();
3517 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
3518 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3521 if (tab.Appearance == TabAppearance.FlatButtons) {
3522 int width = bounds.Width;
3523 bounds.Width += (FlatButtonSpacing - 2);
3525 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
3526 bounds.Width = width;
3530 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3531 } else if (tab.Appearance != TabAppearance.FlatButtons) {
3532 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
3535 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
3538 string_format.Alignment = StringAlignment.Center;
3539 string_format.LineAlignment = StringAlignment.Center;
3540 string_format.FormatFlags = StringFormatFlags.NoWrap;
3542 CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
3544 Pen light = ResPool.GetPen (cpcolor.LightLight);
3546 switch (tab.Alignment) {
3548 case TabAlignment.Top:
3550 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3552 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
3553 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3554 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
3556 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
3557 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
3558 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
3560 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3562 string_format.Alignment = StringAlignment.Center;
3563 string_format.LineAlignment = StringAlignment.Center;
3564 string_format.FormatFlags = StringFormatFlags.NoWrap;
3568 case TabAlignment.Bottom:
3570 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3572 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
3573 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
3575 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
3576 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
3578 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3579 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
3580 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
3582 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3584 string_format.Alignment = StringAlignment.Center;
3585 string_format.LineAlignment = StringAlignment.Center;
3586 string_format.FormatFlags = StringFormatFlags.NoWrap;
3590 case TabAlignment.Left:
3592 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3594 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
3595 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
3596 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
3598 dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
3600 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
3601 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
3603 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3605 string_format.Alignment = StringAlignment.Center;
3606 string_format.LineAlignment = StringAlignment.Center;
3607 string_format.FormatFlags = StringFormatFlags.NoWrap;
3608 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3613 // TabAlignment.Right
3615 dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
3617 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
3618 dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
3620 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
3621 dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
3623 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
3624 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
3626 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
3628 string_format.Alignment = StringAlignment.Center;
3629 string_format.LineAlignment = StringAlignment.Center;
3630 string_format.FormatFlags = StringFormatFlags.NoWrap;
3631 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
3637 if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
3638 if (tab.Alignment == TabAlignment.Left) {
3639 int wo = interior.Width / 2;
3640 int ho = interior.Height / 2;
3641 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
3642 dc.RotateTransform (180);
3643 dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
3644 dc.ResetTransform ();
3646 dc.DrawString (page.Text, page.Font,
3647 SystemBrushes.ControlText,
3648 interior, string_format);
3650 } else if (page.Text != null) {
3651 DrawItemState state = DrawItemState.None;
3652 if (page == tab.SelectedTab)
3653 state |= DrawItemState.Selected;
3654 DrawItemEventArgs e = new DrawItemEventArgs (dc,
3655 tab.Font, bounds, tab.IndexForTabPage (page),
3656 state, page.ForeColor, page.BackColor);
3657 tab.OnDrawItemInternal (e);
3661 if (page.parent.Focused && is_selected) {
3662 CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
3669 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control)
3671 StringFormat format = new StringFormat ();
3672 format.Trimming = StringTrimming.EllipsisCharacter;
3673 format.LineAlignment = StringAlignment.Center;
3674 if (control.TextAlign == ToolBarTextAlign.Underneath)
3675 format.Alignment = StringAlignment.Center;
3677 format.Alignment = StringAlignment.Near;
3679 if (control is PropertyGrid.PropertyToolBar) {
3680 dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
3682 if (clip_rectangle.X == 0) {
3683 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
3686 if (clip_rectangle.Y < 2) {
3687 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3690 if (clip_rectangle.Bottom == control.Bottom) {
3691 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
3694 if (clip_rectangle.Right == control.Right) {
3695 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
3699 if (control.Appearance == ToolBarAppearance.Flat && control.Parent != null) {
3700 if (control.Parent.BackgroundImage != null) {
3701 using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile))
3702 dc.FillRectangle (b, clip_rectangle);
3704 dc.FillRectangle (ResPool.GetSolidBrush (control.Parent.BackColor), clip_rectangle);
3707 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
3710 if (control.Divider && clip_rectangle.Y < 2) {
3711 if (clip_rectangle.Y < 1) {
3712 dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
3714 dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
3718 foreach (ToolBarButton button in control.Buttons)
3719 if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
3720 DrawToolBarButton (dc, control, button, format);
3725 protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3727 bool is_flat = control.Appearance == ToolBarAppearance.Flat;
3729 DrawToolBarButtonBorder (dc, button, is_flat);
3731 switch (button.Style) {
3732 case ToolBarButtonStyle.DropDownButton:
3733 if (control.DropDownArrows)
3734 DrawToolBarDropDownArrow (dc, button, is_flat);
3735 DrawToolBarButtonContents (dc, control, button, format);
3738 case ToolBarButtonStyle.Separator:
3740 DrawToolBarSeparator (dc, button);
3743 case ToolBarButtonStyle.ToggleButton:
3744 DrawToolBarToggleButtonBackground (dc, button);
3745 DrawToolBarButtonContents (dc, control, button, format);
3749 DrawToolBarButtonContents (dc, control, button, format);
3754 const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
3756 protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
3758 if (button.Style == ToolBarButtonStyle.Separator)
3761 Border3DStyle style;
3764 if (button.Pushed || button.Pressed)
3765 style = Border3DStyle.SunkenOuter;
3766 else if (button.Hilight)
3767 style = Border3DStyle.RaisedInner;
3772 if (button.Pushed || button.Pressed)
3773 style = Border3DStyle.Sunken;
3775 style = Border3DStyle.Raised;
3778 CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
3781 protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
3783 Rectangle area = button.Rectangle;
3784 int offset = (int) SystemPens.Control.Width + 1;
3785 dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
3786 dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
3789 protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
3791 Rectangle area = button.Rectangle;
3792 area.X += ToolBarImageGripWidth;
3793 area.Y += ToolBarImageGripWidth;
3794 area.Width -= 2 * ToolBarImageGripWidth;
3795 area.Height -= 2 * ToolBarImageGripWidth;
3798 dc.FillRectangle (SystemBrushes.ControlLightLight, area);
3799 else if (button.PartialPush)
3800 dc.FillRectangle (SystemBrushes.ControlLight, area);
3802 dc.FillRectangle (SystemBrushes.Control, area);
3805 protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
3807 Rectangle rect = button.Rectangle;
3808 rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
3809 rect.Width = ToolBarDropDownWidth;
3811 if (button.dd_pressed) {
3812 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
3813 CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
3814 } else if (button.Pushed || button.Pressed)
3815 CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
3818 CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
3820 CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
3822 PointF [] vertices = new PointF [3];
3823 PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
3824 vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3825 vertices [0].Y = ddCenter.Y;
3826 vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
3827 vertices [1].Y = ddCenter.Y;
3828 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
3829 vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
3830 dc.FillPolygon (SystemBrushes.ControlText, vertices);
3833 protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
3835 if (button.Image != null) {
3836 int x = button.ImageRectangle.X + ToolBarImageGripWidth;
3837 int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
3839 dc.DrawImage (button.Image, x, y);
3841 CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
3844 Rectangle text_rect = button.TextRectangle;
3845 if (text_rect.Width <= 0 || text_rect.Height <= 0)
3849 dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
3851 CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, text_rect, format);
3854 // Grip width for the ToolBar
3855 public override int ToolBarGripWidth {
3859 // Grip width for the Image on the ToolBarButton
3860 public override int ToolBarImageGripWidth {
3864 // width of the separator
3865 public override int ToolBarSeparatorWidth {
3869 // width of the dropdown arrow rect
3870 public override int ToolBarDropDownWidth {
3874 // width for the dropdown arrow on the ToolBarButton
3875 public override int ToolBarDropDownArrowWidth {
3879 // height for the dropdown arrow on the ToolBarButton
3880 public override int ToolBarDropDownArrowHeight {
3884 public override Size ToolBarDefaultSize {
3886 return new Size (100, 42);
3889 #endregion // ToolBar
3892 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
3893 dc.FillRectangle(SystemBrushes.Info, control.client_rect);
3894 dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
3895 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
3898 public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
3901 sizef = tt.DeviceContext.MeasureString(text, tt.Font);
3902 return new Size((int)sizef.Width+8, (int)sizef.Height+3); // Need space for the border
3904 #endregion // ToolTip
3907 private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
3908 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
3909 float ticks, int value_pos, bool mouse_value) {
3911 Point toptick_startpoint = new Point ();
3912 Point bottomtick_startpoint = new Point ();
3913 Point channel_startpoint = new Point ();
3915 float pixels_betweenticks;
3916 const int space_from_right = 8;
3917 const int space_from_left = 8;
3918 const int space_from_bottom = 11;
3919 Rectangle area = tb.ClientRectangle;
3921 switch (tb.TickStyle) {
3922 case TickStyle.BottomRight:
3923 case TickStyle.None:
3924 channel_startpoint.Y = 8;
3925 channel_startpoint.X = 9;
3926 bottomtick_startpoint.Y = 13;
3927 bottomtick_startpoint.X = 24;
3929 case TickStyle.TopLeft:
3930 channel_startpoint.Y = 8;
3931 channel_startpoint.X = 19;
3932 toptick_startpoint.Y = 13;
3933 toptick_startpoint.X = 8;
3935 case TickStyle.Both:
3936 channel_startpoint.Y = 8;
3937 channel_startpoint.X = 18;
3938 bottomtick_startpoint.Y = 13;
3939 bottomtick_startpoint.X = 32;
3940 toptick_startpoint.Y = 13;
3941 toptick_startpoint.X = 8;
3947 thumb_area.X = area.X + channel_startpoint.X;
3948 thumb_area.Y = area.Y + channel_startpoint.Y;
3949 thumb_area.Height = area.Height - space_from_right - space_from_left;
3950 thumb_area.Width = 4;
3953 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
3954 1, thumb_area.Height);
3956 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
3957 1, thumb_area.Height);
3959 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
3960 1, thumb_area.Height);
3962 pixel_len = thumb_area.Height - 11;
3963 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
3965 /* Convert thumb position from mouse position to value*/
3967 if (value_pos < thumb_area.Bottom)
3968 value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
3972 if (value_pos + tb.Minimum > tb.Maximum)
3973 value_pos = tb.Maximum - tb.Minimum;
3975 tb.Value = value_pos + tb.Minimum;
3978 // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
3979 thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
3981 /* Draw thumb fixed 10x22 size */
3982 thumb_pos.Width = 10;
3983 thumb_pos.Height = 22;
3985 switch (tb.TickStyle) {
3986 case TickStyle.BottomRight:
3987 case TickStyle.None: {
3988 thumb_pos.X = channel_startpoint.X - 8;
3990 Pen pen = SystemPens.ControlLight;
3991 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
3992 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
3993 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
3995 pen = SystemPens.ControlDark;
3996 dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
3997 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
3999 pen = SystemPens.ControlDarkDark;
4000 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
4001 dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
4003 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
4004 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
4005 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
4006 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
4010 case TickStyle.TopLeft: {
4011 thumb_pos.X = channel_startpoint.X - 10;
4013 Pen pen = SystemPens.ControlLight;
4014 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
4015 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
4017 pen = SystemPens.ControlDark;
4018 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
4019 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
4020 dc.DrawLine (pen, thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
4022 pen = SystemPens.ControlDarkDark;
4023 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
4024 dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
4025 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
4027 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
4028 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
4029 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
4030 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
4035 case TickStyle.Both: {
4036 thumb_pos.X = area.X + 10;
4038 Pen pen = SystemPens.ControlLight;
4039 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
4040 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
4042 pen = SystemPens.ControlDark;
4043 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
4044 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
4046 pen = SystemPens.ControlDarkDark;
4047 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
4048 dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
4050 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
4059 pixel_len = thumb_area.Height - 11;
4060 pixels_betweenticks = pixel_len / ticks;
4062 thumb_area.X = thumb_pos.X;
4063 thumb_area.Y = channel_startpoint.Y;
4064 thumb_area.Width = thumb_pos.Height;
4067 Region outside = new Region (area);
4068 outside.Exclude (thumb_area);
4070 if (outside.IsVisible (clip_rectangle)) {
4071 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4072 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4074 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4075 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4076 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
4077 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
4079 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
4080 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
4084 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4085 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4087 pixel_len = thumb_area.Height - 11;
4088 pixels_betweenticks = pixel_len / ticks;
4090 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4091 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4092 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
4093 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4095 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
4096 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
4108 Does not matter the size of the control, Win32 always draws:
4109 - Ticks starting from pixel 13, 8
4110 - Channel starting at pos 8, 19 and ends at Width - 8
4111 - Autosize makes always the control 40 pixels height
4112 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
4115 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
4116 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
4117 float ticks, int value_pos, bool mouse_value) {
4118 Point toptick_startpoint = new Point ();
4119 Point bottomtick_startpoint = new Point ();
4120 Point channel_startpoint = new Point ();
4122 float pixels_betweenticks;
4123 const int space_from_right = 8;
4124 const int space_from_left = 8;
4125 Rectangle area = tb.ClientRectangle;
4127 switch (tb.TickStyle) {
4128 case TickStyle.BottomRight:
4129 case TickStyle.None:
4130 channel_startpoint.X = 8;
4131 channel_startpoint.Y = 9;
4132 bottomtick_startpoint.X = 13;
4133 bottomtick_startpoint.Y = 24;
4135 case TickStyle.TopLeft:
4136 channel_startpoint.X = 8;
4137 channel_startpoint.Y = 19;
4138 toptick_startpoint.X = 13;
4139 toptick_startpoint.Y = 8;
4141 case TickStyle.Both:
4142 channel_startpoint.X = 8;
4143 channel_startpoint.Y = 18;
4144 bottomtick_startpoint.X = 13;
4145 bottomtick_startpoint.Y = 32;
4146 toptick_startpoint.X = 13;
4147 toptick_startpoint.Y = 8;
4153 thumb_area.X = area.X + channel_startpoint.X;
4154 thumb_area.Y = area.Y + channel_startpoint.Y;
4155 thumb_area.Width = area.Width - space_from_right - space_from_left;
4156 thumb_area.Height = 4;
4159 dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
4160 thumb_area.Width, 1);
4162 dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
4163 thumb_area.Width, 1);
4165 dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
4166 thumb_area.Width, 1);
4168 pixel_len = thumb_area.Width - 11;
4169 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
4171 /* Convert thumb position from mouse position to value*/
4173 if (value_pos >= channel_startpoint.X)
4174 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
4178 if (value_pos + tb.Minimum > tb.Maximum)
4179 value_pos = tb.Maximum - tb.Minimum;
4181 tb.Value = value_pos + tb.Minimum;
4184 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
4186 /* Draw thumb fixed 10x22 size */
4187 thumb_pos.Width = 10;
4188 thumb_pos.Height = 22;
4190 switch (tb.TickStyle) {
4191 case TickStyle.BottomRight:
4192 case TickStyle.None: {
4193 thumb_pos.Y = channel_startpoint.Y - 8;
4195 Pen pen = SystemPens.ControlLight;
4196 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
4197 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
4198 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
4200 pen = SystemPens.ControlDark;
4201 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
4202 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
4204 pen = SystemPens.ControlDarkDark;
4205 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
4206 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
4208 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
4209 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
4210 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
4211 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
4214 case TickStyle.TopLeft: {
4215 thumb_pos.Y = channel_startpoint.Y - 10;
4217 Pen pen = SystemPens.ControlLight;
4218 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
4219 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
4221 pen = SystemPens.ControlDark;
4222 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
4223 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
4224 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
4226 pen = SystemPens.ControlDarkDark;
4227 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
4228 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
4229 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
4231 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
4232 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
4233 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
4234 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
4238 case TickStyle.Both: {
4239 thumb_pos.Y = area.Y + 10;
4241 Pen pen = SystemPens.ControlLight;
4242 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
4243 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
4245 pen = SystemPens.ControlDark;
4246 dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
4247 dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
4249 pen = SystemPens.ControlDarkDark;
4250 dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
4251 dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
4253 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
4262 pixel_len = thumb_area.Width - 11;
4263 pixels_betweenticks = pixel_len / ticks;
4266 thumb_area.Y = thumb_pos.Y;
4267 thumb_area.X = channel_startpoint.X;
4268 thumb_area.Height = thumb_pos.Height;
4269 Region outside = new Region (area);
4270 outside.Exclude (thumb_area);
4272 if (outside.IsVisible (clip_rectangle)) {
4273 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
4274 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4276 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4277 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4278 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
4279 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
4281 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
4282 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
4286 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
4287 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
4289 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
4290 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
4291 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
4292 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
4294 dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
4295 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
4303 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb)
4308 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
4310 Rectangle thumb_pos = tb.ThumbPos;
4311 Rectangle thumb_area = tb.ThumbArea;
4313 if (tb.thumb_pressed) {
4314 value_pos = tb.thumb_mouseclick;
4317 value_pos = tb.Value - tb.Minimum;
4318 mouse_value = false;
4321 area = tb.ClientRectangle;
4324 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
4325 } else if (tb.thumb_pressed == true) {
4326 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
4328 br_thumb = SystemBrushes.Control;
4332 /* Control Background */
4333 if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
4334 dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
4336 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
4341 Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
4342 dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
4343 dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
4344 dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
4345 dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
4348 if (tb.Orientation == Orientation.Vertical) {
4349 DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4350 br_thumb, ticks, value_pos, mouse_value);
4353 DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
4354 br_thumb, ticks, value_pos, mouse_value);
4357 tb.ThumbPos = thumb_pos;
4358 tb.ThumbArea = thumb_area;
4361 public override Size TrackBarDefaultSize {
4363 return new Size (104, 42);
4367 #endregion // TrackBar
4370 public override Size VScrollBarDefaultSize {
4372 return new Size (this.ScrollBarButtonSize, 80);
4375 #endregion // VScrollBar
4378 public override Size TreeViewDefaultSize {
4380 return new Size (121, 97);
4386 public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
4388 if (wm.IsToolWindow && !wm.IsMinimized)
4389 return SystemInformation.ToolWindowCaptionHeight;
4390 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4392 return SystemInformation.CaptionHeight;
4395 public override int ManagedWindowBorderWidth (InternalWindowManager wm)
4400 public override int ManagedWindowIconWidth (InternalWindowManager wm)
4402 return ManagedWindowTitleBarHeight (wm) - 5;
4405 public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
4407 int bw = ManagedWindowBorderWidth (wm);
4408 Size btsize = ManagedWindowButtonSize (wm);
4409 int btw = btsize.Width;
4410 int bth = btsize.Height;
4412 if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
4413 if (!wm.IsMaximized) {
4414 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2,
4416 wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw,
4418 wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw,
4423 } else if (wm.IsToolWindow) {
4424 wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth);
4428 public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
4430 Form form = wm.Form;
4431 int tbheight = ManagedWindowTitleBarHeight (wm);
4432 int bdwidth = ManagedWindowBorderWidth (wm);
4433 Color titlebar_color = Color.FromArgb (255, 0, 0, 255);
4435 if (wm.HasBorders) {
4436 Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
4437 // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves
4438 dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5);
4439 ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
4442 Color color = ThemeEngine.Current.ColorControlDark;
4444 if (wm.IsActive () && !wm.IsMaximized)
4445 color = titlebar_color;
4447 Rectangle tb = new Rectangle (bdwidth, bdwidth,
4448 form.Width - (bdwidth * 2), tbheight);
4450 // HACK: For now always draw the titlebar until we get updates better
4451 // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle);
4452 //if (vis != Rectangle.Empty)
4453 dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), tb);
4455 dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth,
4456 tbheight + bdwidth, form.Width - (bdwidth * 2),
4457 tbheight + bdwidth);
4459 if (!wm.IsToolWindow) {
4460 tb.X += 18; // Room for the icon and the buttons
4461 tb.Width = (form.Width - 62) - tb.X;
4464 if (form.Text != null) {
4465 StringFormat format = new StringFormat ();
4466 format.FormatFlags = StringFormatFlags.NoWrap;
4467 format.Trimming = StringTrimming.EllipsisCharacter;
4468 format.LineAlignment = StringAlignment.Center;
4470 if (tb.IntersectsWith (clip))
4471 dc.DrawString (form.Text, form.Font,
4472 ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
4476 if (wm.HasBorders) {
4477 if (!wm.IsToolWindow && form.Icon != null) {
4478 Rectangle icon = new Rectangle (bdwidth + 3,
4479 bdwidth + 2, wm.IconWidth, wm.IconWidth);
4480 if (icon.IntersectsWith (clip))
4481 dc.DrawIcon (form.Icon, icon);
4484 if (!wm.IsMaximized) {
4485 if (!wm.IsToolWindow || wm.IsMinimized) {
4486 DrawTitleButton (dc, wm.minimize_button, clip);
4487 DrawTitleButton (dc, wm.maximize_button, clip);
4489 DrawTitleButton (dc, wm.close_button, clip);
4491 // DrawMaximizedButtons (pe, form.ActiveMenu);
4496 public override Size ManagedWindowButtonSize (InternalWindowManager wm)
4498 int height = ManagedWindowTitleBarHeight (wm);
4499 if (!wm.IsMaximized && !wm.IsMinimized) {
4500 if (wm.IsToolWindow)
4501 return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
4503 if (wm.Form.FormBorderStyle == FormBorderStyle.None)
4506 height = SystemInformation.CaptionHeight;
4508 return new Size (SystemInformation.CaptionButtonSize.Width - 2,
4512 private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip)
4514 if (!button.Rectangle.IntersectsWith (clip))
4517 dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
4519 ControlPaint.DrawCaptionButton (dc, button.Rectangle,
4520 button.Caption, ButtonState.Normal);
4523 #region ControlPaint
4524 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
4525 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
4526 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
4527 int bottomWidth, ButtonBorderStyle bottomStyle) {
4528 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
4529 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
4530 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
4531 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
4534 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
4535 CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
4538 protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
4541 Pen penTopLeftInner;
4543 Pen penBottomRightInner;
4544 Rectangle rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4545 bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
4547 if ((style & Border3DStyle.Adjust) != 0) {
4554 penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
4556 CPColor cpcolor = CPColor.Empty;
4558 if (!is_ColorControl)
4559 cpcolor = ResPool.GetCPColor (control_color);
4562 case Border3DStyle.Raised:
4563 penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4564 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4565 penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4567 case Border3DStyle.Sunken:
4568 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4569 penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4570 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4572 case Border3DStyle.Etched:
4573 penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4574 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4576 case Border3DStyle.RaisedOuter:
4577 penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4579 case Border3DStyle.SunkenOuter:
4580 penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4581 penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4583 case Border3DStyle.RaisedInner:
4584 penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
4585 penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4587 case Border3DStyle.SunkenInner:
4588 penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4590 case Border3DStyle.Flat:
4591 penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
4593 case Border3DStyle.Bump:
4594 penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
4600 if ((sides & Border3DSide.Middle) != 0) {
4601 Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
4602 graphics.FillRectangle (brush, rect);
4605 if ((sides & Border3DSide.Left) != 0) {
4606 graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
4607 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
4610 if ((sides & Border3DSide.Top) != 0) {
4611 graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
4612 graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
4615 if ((sides & Border3DSide.Right) != 0) {
4616 graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
4617 graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
4620 if ((sides & Border3DSide.Bottom) != 0) {
4621 graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4622 graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
4626 public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
4628 // sadly enough, the rectangle gets always filled with a hatchbrush
4629 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
4631 if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
4632 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4634 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4636 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4637 dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
4639 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4640 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
4642 Pen pen = SystemPens.ControlDarkDark;
4643 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4644 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4646 pen = SystemPens.ControlDark;
4647 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4648 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4650 pen = SystemPens.ControlLight;
4651 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4652 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4654 if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
4655 Pen pen = SystemPens.ControlDarkDark;
4656 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4657 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4659 pen = SystemPens.ControlDark;
4660 dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
4661 dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
4663 pen = SystemPens.ControlLight;
4664 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
4665 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
4667 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
4668 Pen pen = SystemPens.ControlLight;
4669 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
4670 dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
4672 pen = SystemPens.ControlDark;
4673 dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
4674 dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
4676 pen = SystemPens.ControlDarkDark;
4677 dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
4678 dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
4683 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
4684 Rectangle captionRect;
4687 CPDrawButton(graphics, rectangle, state);
4689 if (rectangle.Width<rectangle.Height) {
4690 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
4692 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
4695 if ((state & ButtonState.Pushed)!=0) {
4696 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
4699 /* Make sure we've got at least a line width of 1 */
4700 lineWidth=Math.Max(1, captionRect.Width/7);
4703 case CaptionButton.Close: {
4706 if ((state & ButtonState.Inactive)!=0) {
4707 pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
4708 DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
4710 pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
4711 DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
4714 pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
4715 DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
4720 case CaptionButton.Help:
4721 case CaptionButton.Maximize:
4722 case CaptionButton.Minimize:
4723 case CaptionButton.Restore: {
4724 if ((state & ButtonState.Inactive)!=0) {
4725 DrawCaptionHelper(graphics, ColorControlLight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
4727 DrawCaptionHelper(graphics, ColorControlDark, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
4730 DrawCaptionHelper(graphics, ColorControlText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
4737 public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
4739 Pen check_pen = SystemPens.ControlDarkDark;
4741 Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
4743 if ((state & ButtonState.All) == ButtonState.All) {
4745 cb_rect.Height -= 2;
4747 dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4748 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4750 check_pen = SystemPens.ControlDark;
4752 if ((state & ButtonState.Flat) == ButtonState.Flat) {
4754 cb_rect.Height -= 2;
4756 dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4757 dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
4760 cb_rect.Height -= 1;
4762 int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
4764 int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
4765 int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
4767 Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
4769 if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
4770 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4772 dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
4774 Pen pen = SystemPens.ControlDark;
4775 dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
4776 dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
4778 pen = SystemPens.ControlDarkDark;
4779 dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
4780 dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
4782 pen = SystemPens.ControlLight;
4783 dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
4784 dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
4786 // oh boy, matching ms is like fighting against windmills
4787 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl))) {
4788 dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
4789 dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
4792 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
4793 check_pen = SystemPens.ControlDark;
4796 if ((state & ButtonState.Checked) == ButtonState.Checked) {
4797 int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
4799 if (check_size < 7) {
4800 int lineWidth = Math.Max (3, check_size / 3);
4801 int Scale = Math.Max (1, check_size / 9);
4803 Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1,
4804 check_size, check_size);
4806 for (int i = 0; i < lineWidth; i++) {
4807 dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
4808 dc.DrawLine (check_pen, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i, rect.Left + lineWidth / 2 + 6 * Scale, rect.Top + lineWidth - 2 * Scale + i);
4811 int lineWidth = Math.Max (3, check_size / 3) + 1;
4813 int x_half = cb_rect.Width / 2;
4814 int y_half = cb_rect.Height / 2;
4816 Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2),
4817 check_size, check_size);
4819 int gradient_left = check_size / 3;
4820 int gradient_right = check_size - gradient_left - 1;
4823 for (int i = 0; i < lineWidth; i++) {
4824 dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
4825 dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i - 1 - gradient_right);
4831 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
4832 Point[] arrow = new Point[3];
4842 if ((state & ButtonState.Checked)!=0) {
4843 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight),rectangle);
4846 if ((state & ButtonState.Flat)!=0) {
4847 ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
4849 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
4850 // this needs to render like a pushed button - jba
4851 // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4852 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4853 graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
4855 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
4859 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
4860 centerX=rect.Left+rect.Width/2;
4861 centerY=rect.Top+rect.Height/2;
4862 shiftX=Math.Max(1, rect.Width/8);
4863 shiftY=Math.Max(1, rect.Height/8);
4865 if ((state & ButtonState.Pushed)!=0) {
4872 P1=new Point(rect.Left, centerY);
4873 P2=new Point(rect.Right, centerY);
4874 P3=new Point(centerX, rect.Bottom);
4880 /* Draw the arrow */
4881 if ((state & ButtonState.Inactive)!=0) {
4882 /* Move away from the shadow */
4883 arrow[0].X += 1; arrow[0].Y += 1;
4884 arrow[1].X += 1; arrow[1].Y += 1;
4885 arrow[2].X += 1; arrow[2].Y += 1;
4887 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
4893 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
4895 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
4900 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
4902 Pen pen = Pens.Black;
4903 Rectangle rect = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1); // Dunno why, but MS does it that way, too
4907 graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
4908 graphics.DrawRectangle (pen, rect);
4910 X = rect.X + rect.Width / 2;
4911 Y = rect.Y + rect.Height / 2;
4913 /* Draw the cross */
4914 graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
4915 graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
4917 /* Draw 'arrows' for vertical lines */
4918 graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
4919 graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
4921 /* Draw 'arrows' for horizontal lines */
4922 graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
4923 graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
4926 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
4927 // make a rectange to trace around border of the button
4928 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4930 Color outerColor = foreColor;
4931 // adjust focus color according to the flatstyle
4932 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
4933 outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;
4936 // draw the outer rectangle
4937 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
4939 // draw the inner rectangle
4940 if (button.FlatStyle == FlatStyle.Popup) {
4941 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
4943 // draw a flat inner rectangle
4944 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
4945 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));
4949 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
4951 // make a rectange to trace around border of the button
4952 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
4954 #if NotUntilCairoIsFixed
4955 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4956 DashStyle oldStyle; // used for caching old penstyle
4957 Pen pen = ResPool.GetPen (colorBackInverted);
4959 oldStyle = pen.DashStyle;
4960 pen.DashStyle = DashStyle.Dot;
4962 graphics.DrawRectangle (pen, trace_rectangle);
4963 pen.DashStyle = oldStyle;
4965 CPDrawFocusRectangle(graphics, trace_rectangle, Color.Wheat, backColor);
4970 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor)
4972 Rectangle rect = rectangle;
4976 if (backColor.GetBrightness () >= 0.5) {
4977 foreColor = Color.Transparent;
4978 backColor = Color.Black;
4981 backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
4982 foreColor = Color.Black;
4985 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
4986 pen = new Pen (brush, 1);
4991 graphics.DrawRectangle (pen, rect);
4995 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
5000 if (primary == true) {
5002 if (enabled == true) {
5005 sb = SystemBrushes.Control;
5009 if (enabled == true) {
5012 sb = SystemBrushes.Control;
5015 graphics.FillRectangle (sb, rectangle);
5016 graphics.DrawRectangle (pen, rectangle);
5020 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
5026 ControlPaint.Color2HBS(backColor, out h, out b, out s);
5029 foreColor=Color.Black;
5031 foreColor=Color.White;
5034 // still not perfect. it seems that ms calculates the position of the first dot or line
5036 using (Pen pen = new Pen (foreColor)) {
5037 pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
5039 for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
5040 graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
5044 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
5046 Microsoft seems to ignore the background and simply make
5047 the image grayscale. At least when having > 256 colors on
5051 if (imagedisabled_attributes == null) {
5052 imagedisabled_attributes = new ImageAttributes ();
5053 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
5054 // This table would create a perfect grayscale image, based on luminance
5055 // new float[]{0.3f,0.3f,0.3f,0,0},
5056 // new float[]{0.59f,0.59f,0.59f,0,0},
5057 // new float[]{0.11f,0.11f,0.11f,0,0},
5058 // new float[]{0,0,0,1,0,0},
5059 // new float[]{0,0,0,0,1,0},
5060 // new float[]{0,0,0,0,0,1}
5062 // This table generates a image that is grayscaled and then
5063 // brightened up. Seems to match MS close enough.
5064 new float[]{0.2f,0.2f,0.2f,0,0},
5065 new float[]{0.41f,0.41f,0.41f,0,0},
5066 new float[]{0.11f,0.11f,0.11f,0,0},
5067 new float[]{0.15f,0.15f,0.15f,1,0,0},
5068 new float[]{0.15f,0.15f,0.15f,0,1,0},
5069 new float[]{0.15f,0.15f,0.15f,0,0,1}
5072 imagedisabled_attributes.SetColorMatrix (colorMatrix);
5075 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
5080 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
5085 penBorder = ResPool.GetSizedPen (Color.White, 2);
5086 penInside = ResPool.GetPen (Color.Black);
5088 penBorder = ResPool.GetSizedPen (Color.Black, 2);
5089 penInside = ResPool.GetPen (Color.White);
5091 penBorder.Alignment=PenAlignment.Inset;
5092 penInside.Alignment=PenAlignment.Inset;
5094 graphics.DrawRectangle(penBorder, rectangle);
5095 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
5099 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
5103 Brush brush = ResPool.GetSolidBrush (color);
5106 case MenuGlyph.Arrow: {
5107 Point[] arrow = new Point[3];
5115 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
5116 centerX=rect.Left+rect.Width/2;
5117 centerY=rect.Top+rect.Height/2;
5118 shiftX=Math.Max(1, rect.Width/8);
5123 P1=new Point(centerX, rect.Top);
5124 P2=new Point(centerX, rect.Bottom);
5125 P3=new Point(rect.Right, centerY);
5131 graphics.FillPolygon(brush, arrow, FillMode.Winding);
5136 case MenuGlyph.Bullet: {
5138 lineWidth=Math.Max(2, rectangle.Width/3);
5139 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
5141 graphics.FillEllipse(brush, rect);
5146 case MenuGlyph.Checkmark: {
5148 Pen pen = ResPool.GetPen (color);
5150 lineWidth=Math.Max(2, rectangle.Width/6);
5151 Scale=Math.Max(1, rectangle.Width/12);
5153 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
5155 for (int i=0; i<lineWidth; i++) {
5156 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
5157 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);
5165 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
5167 CPColor cpcolor = ResPool.GetCPColor (ColorControl);
5169 Color dot_color = Color.Black;
5171 Color top_left_outer = Color.Black;
5172 Color top_left_inner = Color.Black;
5173 Color bottom_right_outer = Color.Black;
5174 Color bottom_right_inner = Color.Black;
5176 int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height * 0.9f) : (int)(rectangle.Width * 0.9f);
5177 int radius = ellipse_diameter / 2;
5179 Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
5183 if ((state & ButtonState.All) == ButtonState.All) {
5184 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5185 dot_color = cpcolor.Dark;
5187 if ((state & ButtonState.Flat) == ButtonState.Flat) {
5188 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5189 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5191 brush = SystemBrushes.ControlLightLight;
5193 if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
5194 brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
5196 brush = SystemBrushes.ControlLightLight;
5198 top_left_outer = cpcolor.Dark;
5199 top_left_inner = cpcolor.DarkDark;
5200 bottom_right_outer = cpcolor.Light;
5201 bottom_right_inner = Color.Transparent;
5203 if ((state & ButtonState.Inactive) == ButtonState.Inactive)
5204 dot_color = cpcolor.Dark;
5207 dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
5209 int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
5211 dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
5212 dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
5213 dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
5215 if (bottom_right_inner != Color.Transparent)
5216 dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5218 using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), line_width)) {
5219 dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
5222 if ((state & ButtonState.Checked) == ButtonState.Checked) {
5223 int inflate = line_width * 4;
5224 Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
5225 if (rectangle.Height > 13) {
5229 dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
5231 Pen pen = ResPool.GetPen (dot_color);
5232 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
5233 dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
5235 dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
5236 dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
5241 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
5246 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
5251 /* Scroll button: regular button + direction arrow */
5252 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
5254 DrawScrollButtonPrimitive (dc, area, state);
5256 bool fill_rect = true;
5259 if ((state & ButtonState.Pushed) != 0)
5263 Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
5265 Point [] arrow = new Point [3];
5266 for (int i = 0; i < 3; i++)
5267 arrow [i] = new Point ();
5269 Pen pen = SystemPens.ControlText;
5271 if ((state & ButtonState.Inactive) != 0) {
5272 pen = SystemPens.ControlDark;
5277 case ScrollButton.Down:
5278 int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5279 int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5283 int triangle_height;
5285 if (rect.Height < 8) {
5286 triangle_height = 2;
5288 } else if (rect.Height == 11) {
5289 triangle_height = 3;
5291 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5294 arrow [0].X = rect.X + x_middle;
5295 arrow [0].Y = rect.Y + y_middle + triangle_height / 2;
5297 arrow [1].X = arrow [0].X + triangle_height - 1;
5298 arrow [1].Y = arrow [0].Y - triangle_height + 1;
5299 arrow [2].X = arrow [0].X - triangle_height + 1;
5300 arrow [2].Y = arrow [1].Y;
5302 dc.DrawPolygon (pen, arrow);
5304 if ((state & ButtonState.Inactive) != 0) {
5305 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
5306 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
5310 for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
5311 dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
5318 case ScrollButton.Up:
5319 x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
5320 y_middle = (int)Math.Round (rect.Height / 2.0f);
5327 if (rect.Height < 8) {
5328 triangle_height = 2;
5330 } else if (rect.Height == 11) {
5331 triangle_height = 3;
5333 triangle_height = (int)Math.Round (rect.Height / 3.0f);
5336 arrow [0].X = rect.X + x_middle;
5337 arrow [0].Y = rect.Y + y_middle - triangle_height / 2;
5339 arrow [1].X = arrow [0].X + triangle_height - 1;
5340 arrow [1].Y = arrow [0].Y + triangle_height - 1;
5341 arrow [2].X = arrow [0].X - triangle_height + 1;
5342 arrow [2].Y = arrow [1].Y;
5344 dc.DrawPolygon (pen, arrow);
5346 if ((state & ButtonState.Inactive) != 0) {
5347 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
5351 for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
5352 dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
5359 case ScrollButton.Left:
5360 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5366 if (rect.Width < 8) {
5369 } else if (rect.Width == 11) {
5372 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5375 arrow [0].X = rect.Left + triangle_width - 1;
5376 arrow [0].Y = rect.Y + y_middle;
5378 if (arrow [0].X - 1 == rect.X)
5381 arrow [1].X = arrow [0].X + triangle_width - 1;
5382 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5383 arrow [2].X = arrow [1].X;
5384 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5386 dc.DrawPolygon (pen, arrow);
5388 if ((state & ButtonState.Inactive) != 0) {
5389 dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5393 for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
5394 dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
5401 case ScrollButton.Right:
5402 y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
5406 if (rect.Width < 8) {
5409 } else if (rect.Width == 11) {
5412 triangle_width = (int)Math.Round (rect.Width / 3.0f);
5415 arrow [0].X = rect.Right - triangle_width - 1;
5416 arrow [0].Y = rect.Y + y_middle;
5418 if (arrow [0].X - 1 == rect.X)
5421 arrow [1].X = arrow [0].X - triangle_width + 1;
5422 arrow [1].Y = arrow [0].Y - triangle_width + 1;
5423 arrow [2].X = arrow [1].X;
5424 arrow [2].Y = arrow [0].Y + triangle_width - 1;
5426 dc.DrawPolygon (pen, arrow);
5428 if ((state & ButtonState.Inactive) != 0) {
5429 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
5430 dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
5434 for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
5435 dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
5444 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
5450 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
5452 Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
5453 Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
5455 for (int i = 2; i < bounds.Width - 2; i += 4) {
5456 dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
5457 dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
5458 dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
5462 public override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
5464 CPColor cpcolor = ResPool.GetCPColor (color);
5466 dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight),
5467 new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
5469 dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
5472 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
5473 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
5478 case ButtonBorderStyle.Solid:
5479 case ButtonBorderStyle.Inset:
5480 case ButtonBorderStyle.Outset:
5481 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
5483 case ButtonBorderStyle.Dashed:
5484 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
5486 case ButtonBorderStyle.Dotted:
5487 pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
5490 case ButtonBorderStyle.None:
5495 case ButtonBorderStyle.Outset: {
5497 int hue, brightness, saturation;
5498 int brightnessSteps;
5499 int brightnessDownSteps;
5501 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5503 brightnessDownSteps=brightness/width;
5504 if (brightness>127) {
5505 brightnessSteps=Math.Max(6, (160-brightness)/width);
5507 brightnessSteps=(127-brightness)/width;
5510 for (int i=0; i<width; i++) {
5512 case Border3DSide.Left: {
5513 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5514 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5515 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5519 case Border3DSide.Right: {
5520 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5521 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5522 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5526 case Border3DSide.Top: {
5527 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5528 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5529 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5533 case Border3DSide.Bottom: {
5534 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5535 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5536 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5544 case ButtonBorderStyle.Inset: {
5546 int hue, brightness, saturation;
5547 int brightnessSteps;
5548 int brightnessDownSteps;
5550 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
5552 brightnessDownSteps=brightness/width;
5553 if (brightness>127) {
5554 brightnessSteps=Math.Max(6, (160-brightness)/width);
5556 brightnessSteps=(127-brightness)/width;
5559 for (int i=0; i<width; i++) {
5561 case Border3DSide.Left: {
5562 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5563 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5564 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5568 case Border3DSide.Right: {
5569 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5570 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5571 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5575 case Border3DSide.Top: {
5576 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
5577 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5578 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5582 case Border3DSide.Bottom: {
5583 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
5584 pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
5585 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5594 I decided to have the for-loop duplicated for speed reasons;
5595 that way we only have to switch once (as opposed to have the
5596 for-loop around the switch)
5600 case Border3DSide.Left: {
5601 for (int i=0; i<width; i++) {
5602 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
5607 case Border3DSide.Right: {
5608 for (int i=0; i<width; i++) {
5609 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
5614 case Border3DSide.Top: {
5615 for (int i=0; i<width; i++) {
5616 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
5621 case Border3DSide.Bottom: {
5622 for (int i=0; i<width; i++) {
5623 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
5634 This function actually draws the various caption elements.
5635 This way we can scale them nicely, no matter what size, and they
5636 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
5639 private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
5641 case CaptionButton.Close: {
5643 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);
5644 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);
5647 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5648 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
5652 case CaptionButton.Help: {
5653 StringFormat sf = new StringFormat();
5654 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
5656 sf.Alignment=StringAlignment.Center;
5657 sf.LineAlignment=StringAlignment.Center;
5660 graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
5668 case CaptionButton.Maximize: {
5669 /* Top 'caption bar' line */
5670 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5671 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);
5674 /* Left side line */
5675 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5676 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5679 /* Right side line */
5680 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5681 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);
5685 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5686 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5691 case CaptionButton.Minimize: {
5693 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5694 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
5699 case CaptionButton.Restore: {
5700 /** First 'window' **/
5701 /* Top 'caption bar' line */
5702 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5703 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);
5706 /* Left side line */
5707 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5708 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);
5711 /* Right side line */
5712 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5713 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);
5717 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5718 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);
5721 /** Second 'window' **/
5722 /* Top 'caption bar' line */
5723 for (int i=0; i<Math.Max(2, lineWidth); i++) {
5724 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);
5727 /* Left side line */
5728 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5729 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
5732 /* Right side line */
5733 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5734 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);
5738 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
5739 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
5748 /* Generic scroll button */
5749 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
5750 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
5751 dc.FillRectangle (SystemBrushes.Control, area.X + 1,
5752 area.Y + 1, area.Width - 2 , area.Height - 2);
5754 dc.DrawRectangle (SystemPens.ControlDark, area.X,
5755 area.Y, area.Width, area.Height);
5760 Brush sb_control = SystemBrushes.Control;
5761 Brush sb_lightlight = SystemBrushes.ControlLightLight;
5762 Brush sb_dark = SystemBrushes.ControlDark;
5763 Brush sb_darkdark = SystemBrushes.ControlDarkDark;
5765 dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
5766 dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
5768 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
5769 dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
5772 dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
5775 dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
5778 dc.FillRectangle (sb_dark, area.X + area.Width - 2,
5779 area.Y + 1, 1, area.Height -3);
5781 dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
5782 area.Y, 1, area.Height - 1);
5784 dc.FillRectangle (sb_control, area.X + 2,
5785 area.Y + 2, area.Width - 4, area.Height - 4);
5789 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
5790 switch (border_style){
5791 case BorderStyle.Fixed3D:
5792 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X +area.Width, area.Y);
5793 dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X, area.Y, area.X, area.Y + area.Height);
5794 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
5795 area.Y + area.Height - 1);
5796 dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
5797 area.Y + area.Height);
5799 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
5800 dc.DrawLine (ResPool.GetPen (ColorActiveBorder), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
5801 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
5802 dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
5804 case BorderStyle.FixedSingle:
5805 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
5807 case BorderStyle.None:
5813 #endregion // ControlPaint