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 Novell, Inc.
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Peter Bartok, pbartok@novell.com
25 // John BouAntoun, jba-mono@optusnet.com.au
31 // $Log: ThemeWin32Classic.cs,v $
32 // Revision 1.46 2004/10/13 03:48:15 pbartok
33 // - Removed all occurences of SystemColors and replaced them with the
34 // matching theme color
36 // Revision 1.45 2004/10/13 03:41:45 pbartok
37 // - From John BouAntoun: Added an overload to CPDrawBorder3D to allow him
38 // using the function for flatstyle drawing
39 // - Changed functions to use the new version of CPDrawBorder3D
41 // Revision 1.44 2004/10/13 02:45:21 pbartok
42 // - Fixes from John BouAntoun: now handles forecolors and backcolors for
43 // flatstyle rendered controls much better; It also fixes normal checkbox
44 // rendering when pushed or disabled.
46 // Revision 1.43 2004/10/07 14:56:51 jordi
47 // Removes deletion of cached brushes
49 // Revision 1.42 2004/10/06 09:59:05 jordi
50 // removes warnings from compilation
52 // Revision 1.41 2004/10/05 16:15:30 jackson
53 // Improve rendering of the radio button patch by John BouAntoun
55 // Revision 1.40 2004/10/05 09:04:31 ravindra
56 // - Added DrawListView method and ListViewDefaultSize property.
57 // - Changed ControlPaint method calls to CPDrawXXX wherever possible.
58 // - Changed DOS style CRLF to Unix format (dos2unix).
60 // Revision 1.39 2004/10/04 07:09:37 jordi
61 // fixes right button position causing right button not showing on horizontal scrollbars
63 // Revision 1.38 2004/09/28 18:44:25 pbartok
64 // - Streamlined Theme interfaces:
65 // * Each DrawXXX method for a control now is passed the object for the
66 // control to be drawn in order to allow accessing any state the theme
69 // * ControlPaint methods for the theme now have a CP prefix to avoid
70 // name clashes with the Draw methods for controls
72 // * Every control now retrieves it's DefaultSize from the current theme
74 // Revision 1.37 2004/09/09 08:28:11 pbartok
75 // - Improve disabled string look
77 // Revision 1.36 2004/09/09 03:03:49 ravindra
78 // PictureBox would not draw a null image to avoid crash.
80 // Revision 1.35 2004/09/07 17:12:26 jordi
83 // Revision 1.34 2004/09/07 09:40:15 jordi
84 // LinkLabel fixes, methods, multiple links
86 // Revision 1.33 2004/09/05 08:03:51 jordi
87 // fixes bugs, adds flashing on certain situations
89 // Revision 1.32 2004/09/02 16:32:54 jordi
90 // implements resource pool for pens, brushes, and hatchbruses
92 // Revision 1.31 2004/08/25 20:04:40 ravindra
93 // Added the missing divider code and grip for ToolBar Control.
95 // Revision 1.30 2004/08/25 18:29:14 jordi
96 // new methods, properties, and fixes for progressbar
98 // Revision 1.29 2004/08/25 00:43:13 ravindra
99 // Fixed wrapping related issues in ToolBar control.
101 // Revision 1.28 2004/08/24 18:37:02 jordi
102 // fixes formmating, methods signature, and adds missing events
104 // Revision 1.27 2004/08/24 16:16:46 jackson
105 // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
107 // Revision 1.26 2004/08/21 01:52:08 ravindra
108 // Improvments in mouse event handling in the ToolBar control.
110 // Revision 1.25 2004/08/20 00:12:51 jordi
111 // fixes methods signature
113 // Revision 1.24 2004/08/19 22:25:31 jordi
114 // theme enhancaments
116 // Revision 1.23 2004/08/18 19:16:53 jordi
117 // Move colors to a table
119 // Revision 1.22 2004/08/17 19:29:11 jackson
120 // Don't use KnownColor to create colours. It has a large startup time.
122 // Revision 1.21 2004/08/15 23:20:54 ravindra
123 // Changes to Theme for ToolBar control and also dos2unix format.
125 // Revision 1.20 2004/08/13 21:22:18 jordi
126 // removes redundant code and fixes issues with tickposition
128 // Revision 1.19 2004/08/12 20:29:01 jordi
129 // Trackbar enhancement, fix mouse problems, highli thumb, etc
131 // Revision 1.18 2004/08/12 18:54:37 jackson
132 // Handle owner draw status bars
134 // Revision 1.17 2004/08/11 01:31:35 jackson
135 // Create Brushes as little as possible
137 // Revision 1.16 2004/08/10 19:21:27 jordi
138 // scrollbar enhancements and standarize on win colors defaults
140 // Revision 1.15 2004/08/10 18:52:30 jackson
141 // Implement DrawItem functionality
143 // Revision 1.14 2004/08/09 21:34:54 jackson
144 // Add support for drawing status bar and get status bar item sizes
146 // Revision 1.13 2004/08/09 21:21:49 jackson
147 // Use known colors for default control colours
149 // Revision 1.12 2004/08/09 21:12:15 jackson
150 // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
152 // Revision 1.11 2004/08/09 17:31:13 jackson
153 // New names for control properties
155 // Revision 1.10 2004/08/09 17:00:00 jackson
156 // Add default window color properties
158 // Revision 1.9 2004/08/09 16:17:19 jackson
159 // Use correct default back color
161 // Revision 1.8 2004/08/09 15:53:12 jackson
162 // Themes now handle default control properties so coloring will be consistent
164 // Revision 1.7 2004/08/08 22:54:21 jordi
165 // Label BorderStyles
167 // Revision 1.6 2004/08/08 18:09:53 jackson
168 // Add pen_buttonface
170 // Revision 1.5 2004/08/08 17:34:28 jordi
171 // Use Windows Standard Colours
173 // Revision 1.4 2004/08/07 23:31:15 jordi
174 // fixes label bug and draw method name
176 // Revision 1.3 2004/08/07 19:05:44 jordi
177 // Theme colour support and GetSysColor defines
179 // Revision 1.2 2004/08/07 00:01:39 pbartok
180 // - Fixed some rounding issues with float/int
182 // Revision 1.1 2004/07/26 17:42:03 jordi
187 using System.Drawing;
188 using System.Drawing.Drawing2D;
189 using System.Drawing.Imaging;
191 namespace System.Windows.Forms
194 internal class ThemeWin32Classic : Theme
197 /* Default colors for Win32 classic theme */
198 uint [] theme_colors = { /* AARRGGBB */
199 (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR, 0xffc0c0c0,
200 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND, 0xff008080,
201 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION, 0xff000080,
202 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION, 0xff808080,
203 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU, 0xffc0c0c0,
204 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW, 0xffffffff,
205 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME, 0xff000000,
206 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT, 0xff000000,
207 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT, 0xff000000,
208 (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT, 0xffffffff,
209 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER, 0xffc0c0c0,
210 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER, 0xffc0c0c0,
211 (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE, 0xff808080,
212 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT, 0xff000080,
213 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT, 0xffffffff,
214 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE, 0xffc0c0c0,
215 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW, 0xff808080,
216 (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT, 0xff808080,
217 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT, 0xff000000,
218 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, 0xffc0c0c0,
219 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT, 0xffffffff,
220 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW, 0xff000000,
221 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT, 0xffe0e0e0,
222 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT, 0xff000000,
223 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK, 0xffffffff,
227 static protected Pen pen_ticks;
228 static protected SolidBrush br_arrow;
229 static protected SolidBrush br_progressbarblock;
230 static protected Pen pen_arrow;
234 protected SolidBrush label_br_fore_color;
235 protected SolidBrush label_br_back_color;
237 #region Principal Theme Methods
238 public ThemeWin32Classic ()
240 label_br_fore_color = null;
241 label_br_back_color = null;
243 /* Init Default colour array*/
244 syscolors = Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
246 for (int i = 0; i < theme_colors.Length; i +=2)
247 syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
249 pen_ticks = new Pen (Color.Black);
250 br_arrow = new SolidBrush (Color.Black);
251 pen_arrow = new Pen (Color.Black);
252 br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128));
254 defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10);
255 defaultWindowForeColor = ColorButtonText;
256 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
259 public override bool DoubleBufferingSupported {
262 #endregion // Principal Theme Methods
264 #region Internal Methods
265 protected SolidBrush GetControlBackBrush (Color c) {
266 if (c == DefaultControlBackColor)
267 return ResPool.GetSolidBrush (ColorButtonFace);
268 return new SolidBrush (c);
271 protected SolidBrush GetControlForeBrush (Color c) {
272 if (c == DefaultControlForeColor)
273 return ResPool.GetSolidBrush (ColorButtonText);
274 return new SolidBrush (c);
276 #endregion // Internal Methods
278 #region OwnerDraw Support
279 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
281 if (e.State == DrawItemState.Selected) {
282 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
286 e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
289 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
291 if (e.State == DrawItemState.Focus)
292 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
294 #endregion // OwnerDraw Support
297 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
301 width = button.ClientSize.Width;
302 height = button.ClientSize.Height;
304 SolidBrush sb = new SolidBrush(button.BackColor);
305 dc.FillRectangle(sb, button.ClientRectangle);
308 CPDrawButton(dc, button.ClientRectangle, button.ButtonState);
310 if (button.has_focus) {
311 CPDrawFocusRectangle(dc, button.ClientRectangle, ColorButtonText, ColorButtonFace);
314 // First, draw the image
315 if ((button.image != null) || (button.image_list != null)) {
316 // Need to draw a picture
323 if (button.ImageIndex!=-1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
324 i = button.image_list.Images[button.image_index];
329 image_width = button.image.Width;
330 image_height = button.image.Height;
332 switch(button.image_alignment) {
333 case ContentAlignment.TopLeft: {
339 case ContentAlignment.TopCenter: {
340 image_x=(width-image_width)/2;
345 case ContentAlignment.TopRight: {
346 image_x=width-image_width;
351 case ContentAlignment.MiddleLeft: {
353 image_y=(height-image_height)/2;
357 case ContentAlignment.MiddleCenter: {
358 image_x=(width-image_width)/2;
359 image_y=(height-image_height)/2;
363 case ContentAlignment.MiddleRight: {
364 image_x=width-image_width;
365 image_y=(height-image_height)/2;
369 case ContentAlignment.BottomLeft: {
371 image_y=height-image_height;
375 case ContentAlignment.BottomCenter: {
376 image_x=(width-image_width)/2;
377 image_y=height-image_height;
381 case ContentAlignment.BottomRight: {
382 image_x=width-image_width;
383 image_y=height-image_height;
394 if (button.is_pressed) {
399 if (button.is_enabled) {
400 dc.DrawImage(i, image_x, image_y);
402 CPDrawImageDisabled(dc, i, image_x, image_y, ColorButtonFace);
407 if (button.text != null && button.text != String.Empty) {
408 Rectangle text_rect = new Rectangle(3, 3, button.ClientSize.Width-6, button.ClientSize.Height-6); // FIXME; calculate rect properly
410 if (button.is_pressed) {
415 if (button.is_enabled) {
416 SolidBrush b = new SolidBrush(button.ForeColor);
417 dc.DrawString(button.text, button.Font, b, text_rect, button.text_format);
420 CPDrawStringDisabled(dc, button.text, button.Font, ColorButtonText, text_rect, button.text_format);
425 public override Size ButtonBaseDefaultSize {
427 return new Size (75, 23);
430 #endregion // ButtonBase
433 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
434 StringFormat text_format;
435 Rectangle client_rectangle;
436 Rectangle text_rectangle;
437 Rectangle checkbox_rectangle;
439 int checkmark_size=13;
441 client_rectangle = checkbox.ClientRectangle;
442 text_rectangle = client_rectangle;
443 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
445 text_format = new StringFormat();
446 text_format.Alignment=StringAlignment.Near;
447 text_format.LineAlignment=StringAlignment.Center;
449 /* Calculate the position of text and checkbox rectangle */
450 if (checkbox.appearance!=Appearance.Button) {
451 switch(checkbox.check_alignment) {
452 case ContentAlignment.BottomCenter: {
453 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
454 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
455 text_rectangle.X=client_rectangle.X;
456 text_rectangle.Width=client_rectangle.Width;
460 case ContentAlignment.BottomLeft: {
461 checkbox_rectangle.X=client_rectangle.Left;
462 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
463 text_rectangle.X=client_rectangle.X+checkmark_size;
464 text_rectangle.Width=client_rectangle.Width-checkmark_size;
468 case ContentAlignment.BottomRight: {
469 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
470 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
471 text_rectangle.X=client_rectangle.X;
472 text_rectangle.Width=client_rectangle.Width-checkmark_size;
476 case ContentAlignment.MiddleCenter: {
477 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
478 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
479 text_rectangle.X=client_rectangle.X;
480 text_rectangle.Width=client_rectangle.Width;
485 case ContentAlignment.MiddleLeft: {
486 checkbox_rectangle.X=client_rectangle.Left;
487 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
488 text_rectangle.X=client_rectangle.X+checkmark_size;
489 text_rectangle.Width=client_rectangle.Width-checkmark_size;
493 case ContentAlignment.MiddleRight: {
494 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
495 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
496 text_rectangle.X=client_rectangle.X;
497 text_rectangle.Width=client_rectangle.Width-checkmark_size;
501 case ContentAlignment.TopCenter: {
502 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
503 checkbox_rectangle.Y=client_rectangle.Top;
504 text_rectangle.X=client_rectangle.X;
505 text_rectangle.Y=checkmark_size;
506 text_rectangle.Width=client_rectangle.Width;
507 text_rectangle.Height=client_rectangle.Height-checkmark_size;
511 case ContentAlignment.TopLeft: {
512 checkbox_rectangle.X=client_rectangle.Left;
513 checkbox_rectangle.Y=client_rectangle.Top;
514 text_rectangle.X=client_rectangle.X+checkmark_size;
515 text_rectangle.Width=client_rectangle.Width-checkmark_size;
519 case ContentAlignment.TopRight: {
520 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
521 checkbox_rectangle.Y=client_rectangle.Top;
522 text_rectangle.X=client_rectangle.X;
523 text_rectangle.Width=client_rectangle.Width-checkmark_size;
528 text_rectangle.X=client_rectangle.X;
529 text_rectangle.Width=client_rectangle.Width;
532 /* Set the horizontal alignment of our text */
533 switch(checkbox.text_alignment) {
534 case ContentAlignment.BottomLeft:
535 case ContentAlignment.MiddleLeft:
536 case ContentAlignment.TopLeft: {
537 text_format.Alignment=StringAlignment.Near;
541 case ContentAlignment.BottomCenter:
542 case ContentAlignment.MiddleCenter:
543 case ContentAlignment.TopCenter: {
544 text_format.Alignment=StringAlignment.Center;
548 case ContentAlignment.BottomRight:
549 case ContentAlignment.MiddleRight:
550 case ContentAlignment.TopRight: {
551 text_format.Alignment=StringAlignment.Far;
556 /* Set the vertical alignment of our text */
557 switch(checkbox.text_alignment) {
558 case ContentAlignment.TopLeft:
559 case ContentAlignment.TopCenter:
560 case ContentAlignment.TopRight: {
561 text_format.LineAlignment=StringAlignment.Near;
565 case ContentAlignment.BottomLeft:
566 case ContentAlignment.BottomCenter:
567 case ContentAlignment.BottomRight: {
568 text_format.LineAlignment=StringAlignment.Far;
572 case ContentAlignment.MiddleLeft:
573 case ContentAlignment.MiddleCenter:
574 case ContentAlignment.MiddleRight: {
575 text_format.LineAlignment=StringAlignment.Center;
580 ButtonState state = ButtonState.Normal;
581 if (checkbox.FlatStyle == FlatStyle.Flat) {
582 state |= ButtonState.Flat;
585 if (checkbox.Checked) {
586 state |= ButtonState.Checked;
589 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
590 state |= ButtonState.Checked;
591 state |= ButtonState.Pushed;
594 // finally make sure the pushed and inavtive states are rendered
595 if (!checkbox.Enabled) {
596 state |= ButtonState.Inactive;
598 else if (checkbox.is_pressed) {
599 state |= ButtonState.Pushed;
605 sb=new SolidBrush(checkbox.BackColor);
606 dc.FillRectangle(sb, checkbox.ClientRectangle);
609 // establish if we are rendering a flat style of some sort
610 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
611 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
613 // render as per normal
614 if (checkbox.appearance!=Appearance.Button) {
615 ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
617 ControlPaint.DrawButton(dc, text_rectangle, state);
621 // win32 compat - win32 seems to give the text a slight (3px) offset when rendering
622 Rectangle inner_text_rectangle = new Rectangle (text_rectangle.X + 3, text_rectangle.Y, Math.Max (text_rectangle.Width - 3, 0), text_rectangle.Height);
624 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
625 if (checkbox.Enabled) {
626 sb = ResPool.GetSolidBrush(checkbox.ForeColor);
627 dc.DrawString(checkbox.Text, checkbox.Font, sb, inner_text_rectangle, text_format);
628 } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
629 dc.DrawString(checkbox.Text, checkbox.Font, SystemBrushes.ControlDark, inner_text_rectangle, text_format);
631 CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorButtonText, inner_text_rectangle, text_format);
634 if (checkbox.Focused) {
635 ControlPaint.DrawFocusRectangle(dc, text_rectangle);
639 // renders a checkBox with the Flat and Popup FlatStyle
640 private void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
645 Rectangle checkbox_rectangle;
646 Rectangle fill_rectangle;
649 // first clip the last pixel of the height and width (windows compat)
650 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
651 // clip the fill rectangle
652 fill_rectangle = new Rectangle(rectangle.X+1, rectangle.Y+1, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
654 // if disabled render in disabled state
655 if (checkbox.Enabled) {
656 // process the state of the checkbox
657 if (checkbox.is_entered || checkbox.is_pressed) {
658 // decide on which background color to use
659 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.is_pressed) {
660 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
661 } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.is_pressed)) {
662 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
664 // use regular window background color
665 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
668 // render the outer border
669 if (checkbox.FlatStyle == FlatStyle.Flat) {
670 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
672 // draw sunken effect
673 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right, ColorButtonFace);
675 graphics.DrawLine(ResPool.GetPen (ControlPaint.DarkDark (checkbox.BackColor)), checkbox_rectangle.X, checkbox_rectangle.Y, checkbox_rectangle.X, checkbox_rectangle.Y+checkbox_rectangle.Height);
676 graphics.DrawLine(ResPool.GetPen (ControlPaint.DarkDark (checkbox.BackColor)), checkbox_rectangle.X, checkbox_rectangle.Y, Math.Max(checkbox_rectangle.X + checkbox_rectangle.Width - 1, 0), checkbox_rectangle.Y);
679 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
681 if (checkbox.FlatStyle == FlatStyle.Flat) {
682 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
684 // draw the outer border
685 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
689 if (checkbox.FlatStyle == FlatStyle.Popup) {
690 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
693 // draw disabled state,
694 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
697 /* Make sure we've got at least a line width of 1 */
698 lineWidth=Math.Max(3, rectangle.Width/6);
699 Scale=Math.Max(1, rectangle.Width/12);
701 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
702 if (checkbox.Enabled) {
703 pen=ResPool.GetPen(checkbox.ForeColor);
705 pen=SystemPens.ControlDark;
708 if (checkbox.Checked) {
709 /* Need to draw a check-mark */
710 for (int i=0; i<lineWidth; i++) {
711 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
712 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);
719 #endregion // CheckBox
722 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
725 Rectangle rect = box.ClientRectangle;
726 Color disabled = ColorGrayText;
728 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
729 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
731 // TODO: When the Light and Dark methods work this code should be activate it
732 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
733 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
735 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
737 size = dc.MeasureString (box.Text, box.Font);
738 width = (int) size.Width;
740 if (width > box.Width - 16)
741 width = box.Width - 16;
743 y = box.Font.Height / 2;
746 dc.DrawLine (pen_dark, 0, y, 8, y); // top
747 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
748 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
749 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
751 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
752 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
754 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
755 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
757 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
758 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
763 dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0);
765 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
766 new RectangleF (10, 0, width, box.Font.Height), new StringFormat ());
770 public override Size GroupBoxDefaultSize {
772 return new Size (200,100);
778 public override Size HScrollBarDefaultSize {
780 return new Size (80,13);
784 #endregion // HScrollBar
787 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) {
788 if (label_br_fore_color == null || label_br_fore_color.Color != label.ForeColor) {
789 label_br_fore_color = GetControlForeBrush (label.ForeColor);
792 if (label_br_back_color == null || label_br_back_color.Color != label.BackColor) {
793 label_br_back_color = GetControlBackBrush (label.BackColor);
796 dc.FillRectangle (label_br_back_color, clip_rectangle);
798 CPDrawBorderStyle (dc, clip_rectangle, label.BorderStyle);
801 dc.DrawString (label.Text, label.Font, label_br_fore_color, clip_rectangle, label.string_format);
803 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
808 public override Size LabelDefaultSize {
810 return new Size (100,23);
817 public override void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control)
823 public override Size ListViewDefaultSize {
825 return new Size (121, 97);
828 #endregion // ListView
831 public override Size PanelDefaultSize {
833 return new Size (200, 100);
840 public override void DrawPictureBox (Graphics dc, PictureBox pb) {
841 Rectangle client = pb.ClientRectangle;
842 int x, y, width, height;
844 dc.FillRectangle (new SolidBrush (pb.BackColor), client);
847 if (pb.Image != null) {
848 switch (pb.SizeMode) {
849 case PictureBoxSizeMode.StretchImage:
850 width = client.Width;
851 height = client.Height;
853 case PictureBoxSizeMode.CenterImage:
854 width = client.Width;
855 height = client.Height;
857 y = (height - pb.Image.Height) / 2;
861 width = client.Width;
862 height = client.Height;
865 dc.DrawImage (pb.Image, x, y, width, height);
867 CPDrawBorderStyle (dc, client, pb.BorderStyle);
870 public override Size PictureBoxDefaultSize {
872 return new Size (100, 50);
875 #endregion // PictureBox
878 public override void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar) {
879 Rectangle client_area = progress_bar.client_area;
880 Rectangle paint_area = progress_bar.paint_area;
881 int steps = (progress_bar.Maximum - progress_bar.Minimum) / progress_bar.step;
882 int space_betweenblocks = 2;
889 block_width = ((client_area.Height) * 2 ) / 3;
890 barpos_pixels = ((progress_bar.Value - progress_bar.Minimum) * client_area.Width) / (progress_bar.Maximum - progress_bar.Minimum);
891 increment = block_width + space_betweenblocks;
894 CPDrawBorder3D (dc, progress_bar.paint_area, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
897 while ((x - client_area.X) < barpos_pixels) {
898 dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
903 public override Size ProgressBarDefaultSize {
905 return new Size (100, 23);
909 #endregion // ProgressBar
912 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
913 StringFormat text_format;
914 Rectangle client_rectangle;
915 Rectangle text_rectangle;
916 Rectangle radiobutton_rectangle;
918 int radiobutton_size = 12;
920 client_rectangle = radio_button.ClientRectangle;
921 text_rectangle = client_rectangle;
922 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
924 text_format = new StringFormat();
925 text_format.Alignment = StringAlignment.Near;
926 text_format.LineAlignment = StringAlignment.Center;
928 /* Calculate the position of text and checkbox rectangle */
929 if (radio_button.appearance!=Appearance.Button) {
930 switch(radio_button.radiobutton_alignment) {
931 case ContentAlignment.BottomCenter: {
932 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
933 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
934 text_rectangle.X=client_rectangle.X;
935 text_rectangle.Width=client_rectangle.Width;
939 case ContentAlignment.BottomLeft: {
940 radiobutton_rectangle.X=client_rectangle.Left;
941 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
942 text_rectangle.X=client_rectangle.X+radiobutton_size;
943 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
947 case ContentAlignment.BottomRight: {
948 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
949 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
950 text_rectangle.X=client_rectangle.X;
951 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
955 case ContentAlignment.MiddleCenter: {
956 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
957 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
958 text_rectangle.X=client_rectangle.X;
959 text_rectangle.Width=client_rectangle.Width;
964 case ContentAlignment.MiddleLeft: {
965 radiobutton_rectangle.X=client_rectangle.Left;
966 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
967 text_rectangle.X=client_rectangle.X+radiobutton_size;
968 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
972 case ContentAlignment.MiddleRight: {
973 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
974 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
975 text_rectangle.X=client_rectangle.X;
976 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
980 case ContentAlignment.TopCenter: {
981 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
982 radiobutton_rectangle.Y=client_rectangle.Top;
983 text_rectangle.X=client_rectangle.X;
984 text_rectangle.Y=radiobutton_size;
985 text_rectangle.Width=client_rectangle.Width;
986 text_rectangle.Height=client_rectangle.Height-radiobutton_size;
990 case ContentAlignment.TopLeft: {
991 radiobutton_rectangle.X=client_rectangle.Left;
992 radiobutton_rectangle.Y=client_rectangle.Top;
993 text_rectangle.X=client_rectangle.X+radiobutton_size;
994 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
998 case ContentAlignment.TopRight: {
999 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1000 radiobutton_rectangle.Y=client_rectangle.Top;
1001 text_rectangle.X=client_rectangle.X;
1002 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1007 text_rectangle.X=client_rectangle.X;
1008 text_rectangle.Width=client_rectangle.Width;
1011 /* Set the horizontal alignment of our text */
1012 switch(radio_button.text_alignment) {
1013 case ContentAlignment.BottomLeft:
1014 case ContentAlignment.MiddleLeft:
1015 case ContentAlignment.TopLeft: {
1016 text_format.Alignment=StringAlignment.Near;
1020 case ContentAlignment.BottomCenter:
1021 case ContentAlignment.MiddleCenter:
1022 case ContentAlignment.TopCenter: {
1023 text_format.Alignment=StringAlignment.Center;
1027 case ContentAlignment.BottomRight:
1028 case ContentAlignment.MiddleRight:
1029 case ContentAlignment.TopRight: {
1030 text_format.Alignment=StringAlignment.Far;
1035 /* Set the vertical alignment of our text */
1036 switch(radio_button.text_alignment) {
1037 case ContentAlignment.TopLeft:
1038 case ContentAlignment.TopCenter:
1039 case ContentAlignment.TopRight: {
1040 text_format.LineAlignment=StringAlignment.Near;
1044 case ContentAlignment.BottomLeft:
1045 case ContentAlignment.BottomCenter:
1046 case ContentAlignment.BottomRight: {
1047 text_format.LineAlignment=StringAlignment.Far;
1051 case ContentAlignment.MiddleLeft:
1052 case ContentAlignment.MiddleCenter:
1053 case ContentAlignment.MiddleRight: {
1054 text_format.LineAlignment=StringAlignment.Center;
1059 ButtonState state = ButtonState.Normal;
1060 if (radio_button.FlatStyle == FlatStyle.Flat) {
1061 state |= ButtonState.Flat;
1064 if (radio_button.Checked) {
1065 state |= ButtonState.Checked;
1070 sb=new SolidBrush(radio_button.BackColor);
1071 dc.FillRectangle(sb, radio_button.ClientRectangle);
1074 // establish if we are rendering a flat style of some sort
1075 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
1076 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
1078 // render as per normal
1079 if (radio_button.appearance!=Appearance.Button) {
1080 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
1082 ControlPaint.DrawButton (dc, text_rectangle, state);
1086 // wind32 compat - win32 seems to give the text a slight (3px) offset when rendering
1087 Rectangle inner_text_rectangle = new Rectangle (text_rectangle.X + 3, text_rectangle.Y, Math.Max (text_rectangle.Width - 3, 0), text_rectangle.Height);
1089 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
1090 sb=new SolidBrush(radio_button.ForeColor);
1091 dc.DrawString (radio_button.Text, radio_button.Font, sb, inner_text_rectangle, text_format);
1094 if (radio_button.Focused) {
1095 ControlPaint.DrawFocusRectangle(dc, text_rectangle);
1099 // renders a radio button with the Flat and Popup FlatStyle
1100 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
1104 // win32 compat fill in the background of the knob
1105 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1107 // draw the outer flatstyle arcs
1108 if (radio_button.FlatStyle == FlatStyle.Flat) {
1109 graphics.DrawArc (ResPool.GetPen (ColorButtonText), rectangle, 0, 359);
1111 // must be a popup radio button
1112 if (radio_button.is_entered) {
1113 // draw the popup 3d button knob
1114 graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
1116 graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
1117 graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
1119 // just draw lighter flatstyle outer circle
1120 graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
1125 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
1126 if (radio_button.Checked) {
1127 SolidBrush buttonBrush;
1129 if (!radio_button.Enabled) {
1130 buttonBrush = (SolidBrush) SystemBrushes.ControlDark;
1132 buttonBrush = (SolidBrush) SystemBrushes.ControlText;
1134 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
1138 public override Size RadioButtonDefaultSize {
1140 return new Size (104,24);
1143 #endregion // RadioButton
1146 public override void DrawScrollBar(Graphics dc, Rectangle clip_rectangle, ScrollBar bar) {
1147 int scrollbutton_width = bar.scrollbutton_width;
1148 int scrollbutton_height = bar.scrollbutton_height;
1149 Rectangle first_arrow_area;
1150 Rectangle second_arrow_area;
1152 Rectangle thumb_pos;
1154 area = bar.paint_area;
1155 thumb_pos = bar.ThumbPos;
1158 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
1159 bar.FirstArrowArea = first_arrow_area;
1161 second_arrow_area = new Rectangle(0, area.Height - scrollbutton_height, bar.Width, scrollbutton_height);
1162 bar.SecondArrowArea = second_arrow_area;
1164 thumb_pos.Width = bar.Width;
1165 bar.ThumbPos = thumb_pos;
1168 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
1169 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
1172 switch (bar.thumb_moving) {
1173 case ScrollBar.ThumbMoving.None: {
1174 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), 0,
1175 scrollbutton_height, area.Width, area.Height - (scrollbutton_height * 2));
1179 case ScrollBar.ThumbMoving.Forward: {
1180 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1181 0, scrollbutton_height,
1182 area.Width, thumb_pos.Y - scrollbutton_height);
1184 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1185 0, thumb_pos.Y + thumb_pos.Height,
1186 area.Width, area.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
1191 case ScrollBar.ThumbMoving.Backwards: {
1192 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1193 0, scrollbutton_height,
1194 area.Width, thumb_pos.Y - scrollbutton_height);
1196 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1197 0, thumb_pos.Y + thumb_pos.Height,
1198 area.Width, area.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
1209 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
1210 bar.FirstArrowArea = first_arrow_area;
1212 second_arrow_area = new Rectangle(area.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
1213 bar.SecondArrowArea = second_arrow_area;
1215 thumb_pos.Height = bar.Height;
1216 bar.ThumbPos = thumb_pos;
1219 CPDrawScrollButton (dc, bar.FirstArrowArea, ScrollButton.Left, bar.firstbutton_state);
1220 CPDrawScrollButton (dc, bar.SecondArrowArea, ScrollButton.Right, bar.secondbutton_state);
1223 //dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
1224 // 0, area.Width - (scrollbutton_width * 2), area.Height);
1226 switch (bar.thumb_moving) {
1227 case ScrollBar.ThumbMoving.None: {
1228 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
1229 0, area.Width - (scrollbutton_width * 2), area.Height);
1234 case ScrollBar.ThumbMoving.Forward: {
1235 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1236 scrollbutton_width, 0,
1237 thumb_pos.X - scrollbutton_width, area.Height);
1239 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1240 thumb_pos.X + thumb_pos.Width, 0,
1241 area.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, area.Height);
1246 case ScrollBar.ThumbMoving.Backwards: {
1247 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1248 scrollbutton_width, 0,
1249 thumb_pos.X - scrollbutton_width, area.Height);
1251 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1252 thumb_pos.X + thumb_pos.Width, 0,
1253 area.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, area.Height);
1266 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
1269 public override int ScrollBarButtonSize {
1272 #endregion // ScrollBar
1275 public override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
1276 Rectangle area = sb.paint_area;
1277 int horz_border = 2;
1278 int vert_border = 2;
1280 dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
1282 if (sb.ShowPanels && sb.Panels.Count == 0) {
1283 // Create a default panel.
1284 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1286 StatusBarPanel panel = new StatusBarPanel ();
1287 Rectangle new_area = new Rectangle (area.X + horz_border,
1288 area.Y + horz_border,
1289 area.Width - StatusBarSizeGripWidth - horz_border,
1290 area.Height - horz_border);
1291 DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
1292 } else if (sb.ShowPanels) {
1293 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1294 int prev_x = area.X + horz_border;
1295 int y = area.Y + vert_border;
1296 for (int i = 0; i < sb.Panels.Count; i++) {
1297 Rectangle pr = new Rectangle (prev_x, y,
1298 sb.Panels [i].Width, area.Height);
1299 prev_x += pr.Width + StatusBarHorzGapWidth;
1300 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
1305 CPDrawSizeGrip (dc, ColorButtonFace, area);
1310 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
1311 SolidBrush br_forecolor, StatusBarPanel panel) {
1312 int border_size = 3; // this is actually const, even if the border style is none
1314 area.Height -= border_size;
1315 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
1316 Border3DStyle border_style = Border3DStyle.SunkenInner;
1317 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
1318 border_style = Border3DStyle.RaisedOuter;
1319 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
1322 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
1323 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
1324 dc, panel.Parent.Font, area, index, DrawItemState.Default,
1325 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
1326 panel.Parent.OnDrawItemInternal (e);
1330 int left = area.Left;
1331 if (panel.Icon != null) {
1333 int size = area.Height - border_size;
1334 Rectangle ia = new Rectangle (left, border_size, size, size);
1335 dc.DrawIcon (panel.Icon, left, area.Top);
1336 left += panel.Icon.Width;
1339 if (panel.Text == String.Empty)
1342 string text = panel.Text;
1343 StringFormat string_format = new StringFormat ();
1344 string_format.LineAlignment = StringAlignment.Center;
1345 string_format.Alignment = StringAlignment.Near;
1346 string_format.FormatFlags = StringFormatFlags.NoWrap;
1348 if (text [0] == '\t') {
1349 string_format.Alignment = StringAlignment.Center;
1350 text = text.Substring (1);
1351 if (text [0] == '\t') {
1352 string_format.Alignment = StringAlignment.Far;
1353 text = text.Substring (1);
1357 float x = left + border_size;
1358 float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
1360 dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
1363 public override int StatusBarSizeGripWidth {
1367 public override int StatusBarHorzGapWidth {
1371 public override Size StatusBarDefaultSize {
1373 return new Size (100, 22);
1376 #endregion // StatusBar
1379 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
1380 StringFormat format = new StringFormat ();
1382 if (control.textAlignment == ToolBarTextAlign.Underneath) {
1383 format.LineAlignment = StringAlignment.Center;
1384 format.Alignment = StringAlignment.Center;
1386 format.LineAlignment = StringAlignment.Center;
1387 format.Alignment = StringAlignment.Near;
1390 // Exclude the area for divider
1391 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
1392 control.Width, control.Height - ToolBarGripWidth / 2);
1393 bool flat = (control.Appearance == ToolBarAppearance.Flat);
1394 dc.FillRectangle (SystemBrushes.Control, paint_area);
1395 CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
1397 if (control.Divider)
1398 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
1400 foreach (ToolBarButton button in control.Buttons) {
1403 Rectangle buttonArea = button.Rectangle;
1404 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
1405 Rectangle txtRect = buttonArea; // rect to draw the text
1406 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
1408 // calculate different rects and draw the frame if its not separator button
1409 if (button.Style != ToolBarButtonStyle.Separator) {
1410 /* Adjustment for drop down arrow */
1411 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
1412 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
1413 ddRect.Y = buttonArea.Y;
1414 ddRect.Width = this.ToolBarDropDownWidth;
1415 ddRect.Height = buttonArea.Height;
1418 // calculate txtRect and imgRect, if imageIndex and imageList are present
1419 if (button.ImageIndex > -1 && control.ImageList != null) {
1420 if (button.ImageIndex < control.ImageList.Images.Count)
1421 image = control.ImageList.Images [button.ImageIndex];
1422 // draw the image at the centre if textalignment is underneath
1423 if (control.TextAlign == ToolBarTextAlign.Underneath) {
1424 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
1425 - control.ImageSize.Width) / 2)
1426 + this.ToolBarImageGripWidth;
1427 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
1428 imgRect.Width = control.ImageSize.Width;
1429 imgRect.Height = control.ImageSize.Height;
1431 txtRect.X = buttonArea.X;
1432 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
1433 txtRect.Width = buttonArea.Width - ddRect.Width;
1434 txtRect.Height = buttonArea.Height - imgRect.Height
1435 - 2 * this.ToolBarImageGripWidth;
1438 imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
1439 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
1440 imgRect.Width = control.ImageSize.Width;
1441 imgRect.Height = control.ImageSize.Height;
1443 txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
1444 txtRect.Y = buttonArea.Y;
1445 txtRect.Width = buttonArea.Width - imgRect.Width
1446 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
1447 txtRect.Height = buttonArea.Height;
1450 /* Draw the button frame, only if it is not a separator */
1452 if (button.Pushed || button.Pressed) {
1453 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
1454 } else if (button.Hilight) {
1455 dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
1456 if (! ddRect.IsEmpty) {
1457 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
1458 ddRect.Y + ddRect.Height);
1459 buttonArea.Width -= this.ToolBarDropDownWidth;
1463 else { // normal toolbar
1464 if (button.Pushed || button.Pressed) {
1465 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
1466 Border3DSide.All, ColorButtonFace);
1467 if (! ddRect.IsEmpty) {
1468 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
1469 Border3DSide.Left, ColorButtonFace);
1470 buttonArea.Width -= this.ToolBarDropDownWidth;
1474 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
1475 Border3DSide.All, ColorButtonFace);
1476 if (! ddRect.IsEmpty) {
1477 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
1478 Border3DSide.Left, ColorButtonFace);
1479 buttonArea.Width -= this.ToolBarDropDownWidth;
1484 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
1485 imgRect, image, txtRect, ddRect, flat);
1489 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
1490 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
1491 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
1492 if (! button.Visible)
1495 switch (button.Style) {
1497 case ToolBarButtonStyle.Separator:
1498 // separator is drawn only in the case of flat appearance
1500 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
1501 buttonArea.X + 1, buttonArea.Height);
1502 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
1503 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
1504 /* draw a horizontal separator */
1505 if (button.Wrapper) {
1506 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
1507 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
1508 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
1509 y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
1514 case ToolBarButtonStyle.ToggleButton:
1515 Rectangle toggleArea = Rectangle.Empty;
1516 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
1517 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
1518 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
1519 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
1520 if (button.PartialPush && button.Pushed) {
1521 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
1522 if (! imgRect.IsEmpty) {
1523 if (button.Enabled && image != null)
1524 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
1525 imgRect.Height, button.ImageIndex);
1527 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
1528 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
1529 Border3DSide.Right | Border3DSide.Bottom);
1533 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
1535 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
1538 else if (button.PartialPush) {
1539 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
1540 if (! imgRect.IsEmpty) {
1541 if (button.Enabled && image != null)
1542 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
1543 imgRect.Height, button.ImageIndex);
1545 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
1546 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
1547 Border3DSide.Right | Border3DSide.Bottom);
1551 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
1553 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
1557 else if (button.Pushed) {
1558 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
1559 if (! imgRect.IsEmpty) {
1560 if (button.Enabled && image != null)
1561 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
1562 imgRect.Height, button.ImageIndex);
1564 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
1565 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
1566 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
1570 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
1572 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
1577 dc.FillRectangle (SystemBrushes.Control, toggleArea);
1578 if (! imgRect.IsEmpty) {
1579 if (button.Enabled && image != null)
1580 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
1581 imgRect.Height, button.ImageIndex);
1583 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
1584 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
1585 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
1589 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
1591 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
1596 case ToolBarButtonStyle.DropDownButton:
1597 // draw the dropdown arrow
1598 if (! ddRect.IsEmpty) {
1599 PointF [] vertices = new PointF [3];
1600 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
1601 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1602 vertices [0].Y = ddCenter.Y;
1603 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
1604 vertices [1].Y = ddCenter.Y;
1605 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
1606 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
1607 dc.FillPolygon (SystemBrushes.ControlText, vertices);
1609 goto case ToolBarButtonStyle.PushButton;
1611 case ToolBarButtonStyle.PushButton:
1612 if (! imgRect.IsEmpty){
1613 if (button.Enabled && image != null)
1614 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
1617 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
1618 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
1619 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
1623 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
1625 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
1631 // Grip width for the ToolBar
1632 public override int ToolBarGripWidth {
1636 // Grip width for the Image on the ToolBarButton
1637 public override int ToolBarImageGripWidth {
1641 // width of the separator
1642 public override int ToolBarSeparatorWidth {
1646 // width of the dropdown arrow rect
1647 public override int ToolBarDropDownWidth {
1651 // width for the dropdown arrow on the ToolBarButton
1652 public override int ToolBarDropDownArrowWidth {
1656 // height for the dropdown arrow on the ToolBarButton
1657 public override int ToolBarDropDownArrowHeight {
1661 public override Size ToolBarDefaultSize {
1663 return new Size (100, 42);
1666 #endregion // ToolBar
1669 private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
1670 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
1671 float ticks, int value_pos, bool mouse_value) {
1673 Point toptick_startpoint = new Point ();
1674 Point bottomtick_startpoint = new Point ();
1675 Point channel_startpoint = new Point ();
1677 float pixels_betweenticks;
1678 const int space_from_right = 8;
1679 const int space_from_left = 8;
1681 switch (tb.TickStyle) {
1682 case TickStyle.BottomRight:
1683 case TickStyle.None:
1684 channel_startpoint.Y = 8;
1685 channel_startpoint.X = 9;
1686 bottomtick_startpoint.Y = 13;
1687 bottomtick_startpoint.X = 24;
1689 case TickStyle.TopLeft:
1690 channel_startpoint.Y = 8;
1691 channel_startpoint.X = 19;
1692 toptick_startpoint.Y = 13;
1693 toptick_startpoint.X = 8;
1695 case TickStyle.Both:
1696 channel_startpoint.Y = 8;
1697 channel_startpoint.X = 18;
1698 bottomtick_startpoint.Y = 13;
1699 bottomtick_startpoint.X = 32;
1700 toptick_startpoint.Y = 13;
1701 toptick_startpoint.X = 8;
1707 thumb_area.X = area.X + channel_startpoint.X;
1708 thumb_area.Y = area.Y + channel_startpoint.Y;
1709 thumb_area.Height = area.Height - space_from_right - space_from_left;
1710 thumb_area.Width = 4;
1713 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
1714 1, thumb_area.Height);
1716 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
1717 1, thumb_area.Height);
1719 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
1720 1, thumb_area.Height);
1722 pixel_len = thumb_area.Height - 11;
1723 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1725 /* Convert thumb position from mouse position to value*/
1728 if (value_pos >= channel_startpoint.Y)
1729 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
1733 if (value_pos + tb.Minimum > tb.Maximum)
1734 value_pos = tb.Maximum - tb.Minimum;
1736 tb.Value = value_pos + tb.Minimum;
1739 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
1741 /* Draw thumb fixed 10x22 size */
1742 thumb_pos.Width = 10;
1743 thumb_pos.Height = 22;
1745 switch (tb.TickStyle) {
1746 case TickStyle.BottomRight:
1747 case TickStyle.None: {
1748 thumb_pos.X = channel_startpoint.X - 8;
1750 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
1751 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
1752 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
1754 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
1755 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
1757 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
1758 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
1760 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
1761 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
1762 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
1763 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
1767 case TickStyle.TopLeft: {
1768 thumb_pos.X = channel_startpoint.X - 10;
1770 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
1771 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
1773 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
1774 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
1775 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
1777 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
1778 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
1779 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
1781 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
1782 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
1783 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
1784 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
1789 case TickStyle.Both: {
1790 thumb_pos.X = area.X + 10;
1791 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
1792 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
1794 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
1795 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
1797 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
1798 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
1800 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
1809 pixel_len = thumb_area.Height - 11;
1810 pixels_betweenticks = pixel_len / ticks;
1813 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1814 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1816 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1817 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
1818 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
1819 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
1821 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
1822 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
1826 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
1827 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1829 pixel_len = thumb_area.Height - 11;
1830 pixels_betweenticks = pixel_len / ticks;
1832 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1833 //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
1834 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
1835 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
1836 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1838 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
1839 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
1847 Does not matter the size of the control, Win32 always draws:
1848 - Ticks starting from pixel 13, 8
1849 - Channel starting at pos 8, 19 and ends at Width - 8
1850 - Autosize makes always the control 40 pixels height
1851 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
1854 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
1855 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
1856 float ticks, int value_pos, bool mouse_value) {
1857 Point toptick_startpoint = new Point ();
1858 Point bottomtick_startpoint = new Point ();
1859 Point channel_startpoint = new Point ();
1861 float pixels_betweenticks;
1862 const int space_from_right = 8;
1863 const int space_from_left = 8;
1865 switch (tb.TickStyle) {
1866 case TickStyle.BottomRight:
1867 case TickStyle.None:
1868 channel_startpoint.X = 8;
1869 channel_startpoint.Y = 9;
1870 bottomtick_startpoint.X = 13;
1871 bottomtick_startpoint.Y = 24;
1873 case TickStyle.TopLeft:
1874 channel_startpoint.X = 8;
1875 channel_startpoint.Y = 19;
1876 toptick_startpoint.X = 13;
1877 toptick_startpoint.Y = 8;
1879 case TickStyle.Both:
1880 channel_startpoint.X = 8;
1881 channel_startpoint.Y = 18;
1882 bottomtick_startpoint.X = 13;
1883 bottomtick_startpoint.Y = 32;
1884 toptick_startpoint.X = 13;
1885 toptick_startpoint.Y = 8;
1891 thumb_area.X = area.X + channel_startpoint.X;
1892 thumb_area.Y = area.Y + channel_startpoint.Y;
1893 thumb_area.Width = area.Width - space_from_right - space_from_left;
1894 thumb_area.Height = 4;
1897 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
1898 thumb_area.Width, 1);
1900 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
1901 thumb_area.Width, 1);
1903 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
1904 thumb_area.Width, 1);
1906 pixel_len = thumb_area.Width - 11;
1907 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
1909 /* Convert thumb position from mouse position to value*/
1911 if (value_pos >= channel_startpoint.X)
1912 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
1916 if (value_pos + tb.Minimum > tb.Maximum)
1917 value_pos = tb.Maximum - tb.Minimum;
1919 tb.Value = value_pos + tb.Minimum;
1922 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
1924 /* Draw thumb fixed 10x22 size */
1925 thumb_pos.Width = 10;
1926 thumb_pos.Height = 22;
1928 switch (tb.TickStyle) {
1929 case TickStyle.BottomRight:
1930 case TickStyle.None: {
1931 thumb_pos.Y = channel_startpoint.Y - 8;
1933 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
1934 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
1935 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
1937 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
1938 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
1940 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
1941 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
1943 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
1944 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
1945 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
1946 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
1949 case TickStyle.TopLeft: {
1950 thumb_pos.Y = channel_startpoint.Y - 10;
1952 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
1953 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
1955 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
1956 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
1957 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
1959 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
1960 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
1961 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
1963 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
1964 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
1965 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
1966 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
1970 case TickStyle.Both: {
1971 thumb_pos.Y = area.Y + 10;
1972 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
1973 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
1975 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
1976 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
1978 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
1979 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
1981 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
1990 pixel_len = thumb_area.Width - 11;
1991 pixels_betweenticks = pixel_len / ticks;
1994 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
1995 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
1997 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
1998 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
1999 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
2000 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
2002 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
2003 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
2007 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
2008 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2010 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2011 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
2012 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
2013 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
2015 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
2016 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2021 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb) {
2022 //public override void DrawTrackBar (Graphics dc,
2025 //ref Rectangle thumb_pos,
2026 //ref Rectangle thumb_area,
2030 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
2032 Rectangle thumb_pos = tb.ThumbPos;
2033 Rectangle thumb_area = tb.ThumbArea;
2035 if (tb.thumb_pressed) {
2036 value_pos = tb.thumb_mouseclick;
2039 value_pos = tb.Value - tb.Minimum;
2040 mouse_value = false;
2043 area = tb.paint_area;
2045 if (tb.thumb_pressed == true) {
2046 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
2048 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
2052 /* Control Background */
2053 if (tb.BackColor == DefaultControlBackColor) {
2054 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
2056 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
2061 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
2062 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
2063 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
2064 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
2067 if (tb.Orientation == Orientation.Vertical) {
2068 DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
2069 br_thumb, ticks, value_pos, mouse_value);
2072 DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
2073 br_thumb, ticks, value_pos, mouse_value);
2076 tb.ThumbPos = thumb_pos;
2077 tb.ThumbArea = thumb_area;
2080 public override Size TrackBarDefaultSize {
2082 return new Size (104, 42);
2086 #endregion // TrackBar
2089 public override Size VScrollBarDefaultSize {
2091 return new Size (13,80);
2094 #endregion // VScrollBar
2096 #region ControlPaint
2097 private enum DrawFrameControlStates {
2098 ButtonCheck = 0x0000,
2099 ButtonRadioImage = 0x0001,
2100 ButtonRadioMask = 0x0002,
2101 ButtonRadio = 0x0004,
2102 Button3State = 0x0008,
2103 ButtonPush = 0x0010,
2105 CaptionClose = 0x0000,
2106 CaptionMin = 0x0001,
2107 CaptionMax = 0x0002,
2108 CaptionRestore = 0x0004,
2109 CaptionHelp = 0x0008,
2113 MenuBullet = 0x0002,
2114 MenuArrowRight = 0x0004,
2117 ScrollDown = 0x0001,
2118 ScrollLeft = 0x0002,
2119 ScrollRight = 0x0003,
2120 ScrollComboBox = 0x0005,
2121 ScrollSizeGrip = 0x0008,
2122 ScrollSizeGripRight = 0x0010,
2127 Transparent = 0x0800,
2129 AdjustRect = 0x2000,
2135 private enum DrawFrameControlTypes {
2142 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
2143 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
2144 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
2145 int bottomWidth, ButtonBorderStyle bottomStyle) {
2146 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
2147 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
2148 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
2149 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
2152 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
2153 CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
2156 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
2158 Pen penTopLeftInner;
2160 Pen penBottomRightInner;
2161 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
2162 bool doInner = false;
2164 if ((style & Border3DStyle.Adjust)!=0) {
2171 /* default to flat */
2172 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
2173 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2174 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
2175 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2177 if ((style & Border3DStyle.RaisedOuter)!=0) {
2178 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2179 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2180 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2183 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
2184 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2185 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2186 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2191 if ((style & Border3DStyle.RaisedInner)!=0) {
2193 penTopLeftInner=ResPool.GetPen(ControlPaint.Light(control_color));
2194 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2196 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2197 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2199 } else if ((style & Border3DStyle.SunkenInner)!=0) {
2201 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2202 penBottomRightInner=ResPool.GetPen(ControlPaint.Light(control_color));
2204 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2205 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2209 if ((sides & Border3DSide.Middle)!=0) {
2210 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
2213 if ((sides & Border3DSide.Left)!=0) {
2214 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-1, rect.Left, rect.Top);
2216 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-1, rect.Left+1, rect.Top);
2220 if ((sides & Border3DSide.Top)!=0) {
2221 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-1, rect.Top);
2224 if ((sides & Border3DSide.Left)!=0) {
2225 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-1, rect.Top+1);
2227 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-1, rect.Top+1);
2232 if ((sides & Border3DSide.Right)!=0) {
2233 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
2236 if ((sides & Border3DSide.Top)!=0) {
2237 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-1);
2239 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-1);
2244 if ((sides & Border3DSide.Bottom)!=0) {
2247 if ((sides & Border3DSide.Left)!=0) {
2251 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
2254 if ((sides & Border3DSide.Right)!=0) {
2255 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
2257 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-1, rect.Bottom-2);
2265 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
2266 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
2268 if ((state & ButtonState.Pushed)!=0) {
2269 dfcs |= DrawFrameControlStates.Pushed;
2272 if ((state & ButtonState.Checked)!=0) {
2273 dfcs |= DrawFrameControlStates.Checked;
2276 if ((state & ButtonState.Flat)!=0) {
2277 dfcs |= DrawFrameControlStates.Flat;
2280 if ((state & ButtonState.Inactive)!=0) {
2281 dfcs |= DrawFrameControlStates.Inactive;
2283 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
2287 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
2288 Rectangle captionRect;
2291 CPDrawButton(graphics, rectangle, state);
2293 if (rectangle.Width<rectangle.Height) {
2294 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
2296 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
2299 if ((state & ButtonState.Pushed)!=0) {
2300 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
2303 /* Make sure we've got at least a line width of 1 */
2304 lineWidth=Math.Max(1, captionRect.Width/7);
2307 case CaptionButton.Close: {
2310 if ((state & ButtonState.Inactive)!=0) {
2311 pen=new Pen(ColorButtonHilight, lineWidth);
2312 DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
2315 pen=new Pen(ColorButtonShadow, lineWidth);
2316 DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
2320 pen=new Pen(ColorButtonText, lineWidth);
2321 DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
2327 case CaptionButton.Help:
2328 case CaptionButton.Maximize:
2329 case CaptionButton.Minimize:
2330 case CaptionButton.Restore: {
2331 if ((state & ButtonState.Inactive)!=0) {
2332 DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
2334 DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
2337 DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
2345 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
2346 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
2348 if ((state & ButtonState.Pushed)!=0) {
2349 dfcs |= DrawFrameControlStates.Pushed;
2352 if ((state & ButtonState.Checked)!=0) {
2353 dfcs |= DrawFrameControlStates.Checked;
2356 if ((state & ButtonState.Flat)!=0) {
2357 dfcs |= DrawFrameControlStates.Flat;
2360 if ((state & ButtonState.Inactive)!=0) {
2361 dfcs |= DrawFrameControlStates.Inactive;
2364 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
2368 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
2369 Point[] arrow = new Point[3];
2379 if ((state & ButtonState.Checked)!=0) {
2380 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);
2383 if ((state & ButtonState.Flat)!=0) {
2384 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
2386 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
2387 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2389 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2393 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
2394 centerX=rect.Left+rect.Width/2;
2395 centerY=rect.Top+rect.Height/2;
2396 shiftX=Math.Max(1, rect.Width/8);
2397 shiftY=Math.Max(1, rect.Height/8);
2399 if ((state & ButtonState.Pushed)!=0) {
2406 P1=new Point(rect.Left, centerY);
2407 P2=new Point(rect.Right, centerY);
2408 P3=new Point(centerX, rect.Bottom);
2414 /* Draw the arrow */
2415 if ((state & ButtonState.Inactive)!=0) {
2416 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
2418 /* Move away from the shadow */
2428 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
2430 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
2435 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
2437 Pen pen = new Pen(Color.Black, 1);
2438 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
2442 graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
2443 graphics.DrawRectangle(pen, rect);
2445 X=rect.X+rect.Width/2;
2446 Y=rect.Y+rect.Height/2;
2448 /* Draw the cross */
2449 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
2450 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
2452 /* Draw 'arrows' for vertical lines */
2453 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
2454 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
2456 /* Draw 'arrows' for horizontal lines */
2457 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
2458 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
2463 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
2464 //Color colorForeInverted;
2465 Color colorBackInverted;
2468 //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
2469 //pen=new Pen(colorForeInverted, 1);
2470 // MS seems to always use black
2471 pen=new Pen(Color.Black, 1);
2472 graphics.DrawRectangle(pen, rectangle);
2475 colorBackInverted=Color.FromArgb(Math.Abs(backColor.R-255), Math.Abs(backColor.G-255), Math.Abs(backColor.B-255));
2476 pen=new Pen(colorBackInverted, 1);
2477 pen.DashStyle=DashStyle.Dot;
2478 graphics.DrawRectangle(pen, rectangle);
2483 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
2487 if (primary==true) {
2488 pen=new Pen(Color.Black, 1);
2489 if (enabled==true) {
2490 sb=ResPool.GetSolidBrush (ColorButtonText);
2492 sb=ResPool.GetSolidBrush (ColorButtonFace);
2495 pen=new Pen(Color.White, 1);
2496 if (enabled==true) {
2497 sb=new SolidBrush(Color.Black);
2499 sb=ResPool.GetSolidBrush (ColorButtonFace);
2502 graphics.FillRectangle(sb, rectangle);
2503 graphics.DrawRectangle(pen, rectangle);
2508 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
2514 ControlPaint.Color2HBS(backColor, out h, out b, out s);
2517 foreColor=Color.Black;
2519 foreColor=Color.White;
2523 /* Commented out until I take the time and figure out
2524 which HatchStyle will match requirements. The code below
2525 is only correct for Percent50.
2527 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
2528 HatchBrush brush=null;
2530 switch(pixelsBetweenDots.Width) {
2531 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
2532 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
2533 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
2535 /* Have to do it the slow way */
2540 graphics.FillRectangle(brush, area);
2549 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
2551 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
2552 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
2553 bitmap.SetPixel(x, y, foreColor);
2556 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
2560 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
2562 Microsoft seems to ignore the background and simply make
2563 the image grayscale. At least when having > 256 colors on
2567 ImageAttributes imageAttributes=new ImageAttributes();
2568 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
2569 // This table would create a perfect grayscale image, based on luminance
2570 // new float[]{0.3f,0.3f,0.3f,0,0},
2571 // new float[]{0.59f,0.59f,0.59f,0,0},
2572 // new float[]{0.11f,0.11f,0.11f,0,0},
2573 // new float[]{0,0,0,1,0,0},
2574 // new float[]{0,0,0,0,1,0},
2575 // new float[]{0,0,0,0,0,1}
2577 // This table generates a image that is grayscaled and then
2578 // brightened up. Seems to match MS close enough.
2579 new float[]{0.2f,0.2f,0.2f,0,0},
2580 new float[]{0.41f,0.41f,0.41f,0,0},
2581 new float[]{0.11f,0.11f,0.11f,0,0},
2582 new float[]{0.15f,0.15f,0.15f,1,0,0},
2583 new float[]{0.15f,0.15f,0.15f,0,1,0},
2584 new float[]{0.15f,0.15f,0.15f,0,0,1}
2587 imageAttributes.SetColorMatrix(colorMatrix);
2588 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
2589 imageAttributes.Dispose();
2593 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
2598 penBorder=new Pen(Color.White, 2);
2599 penInside=new Pen(Color.Black, 1);
2601 penBorder=new Pen(Color.Black, 2);
2602 penInside=new Pen(Color.White, 1);
2604 penBorder.Alignment=PenAlignment.Inset;
2605 penInside.Alignment=PenAlignment.Inset;
2607 graphics.DrawRectangle(penBorder, rectangle);
2608 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
2609 penBorder.Dispose();
2610 penInside.Dispose();
2614 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
2618 // MS draws always the background white
2619 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
2622 case MenuGlyph.Arrow: {
2623 Point[] arrow = new Point[3];
2632 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
2633 centerX=rect.Left+rect.Width/2;
2634 centerY=rect.Top+rect.Height/2;
2635 shiftX=Math.Max(1, rect.Width/8);
2636 shiftY=Math.Max(1, rect.Height/8);
2641 P1=new Point(centerX, rect.Top-1);
2642 P2=new Point(centerX, rect.Bottom);
2643 P3=new Point(rect.Right, centerY);
2649 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
2654 case MenuGlyph.Bullet: {
2656 lineWidth=Math.Max(2, rectangle.Width/3);
2657 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
2659 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
2664 case MenuGlyph.Checkmark: {
2667 lineWidth=Math.Max(2, rectangle.Width/6);
2668 Scale=Math.Max(1, rectangle.Width/12);
2670 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
2672 for (int i=0; i<lineWidth; i++) {
2673 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
2674 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
2682 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
2683 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
2685 if ((state & ButtonState.Pushed)!=0) {
2686 dfcs |= DrawFrameControlStates.Pushed;
2689 if ((state & ButtonState.Checked)!=0) {
2690 dfcs |= DrawFrameControlStates.Checked;
2693 if ((state & ButtonState.Flat)!=0) {
2694 dfcs |= DrawFrameControlStates.Flat;
2697 if ((state & ButtonState.Inactive)!=0) {
2698 dfcs |= DrawFrameControlStates.Inactive;
2700 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
2705 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
2710 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
2715 /* Scroll button: regular button + direction arrow */
2716 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
2717 bool enabled = (state == ButtonState.Inactive) ? false: true;
2719 DrawScrollButtonPrimitive (dc, area, state);
2723 case ScrollButton.Up: {
2724 int x = area.X + (area.Width / 2) - 4;
2727 for (int i = 0; i < 3; i++)
2729 dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
2731 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
2734 dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);
2737 case ScrollButton.Down: {
2738 int x = area.X + (area.Width / 2) - 4;
2741 for (int i = 4; i != 0; i--)
2743 dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
2745 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
2748 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
2752 case ScrollButton.Left: {
2753 int y = area.Y + (area.Height / 2) - 4;
2756 for (int i = 0; i < 3; i++)
2758 dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
2760 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
2762 dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
2766 case ScrollButton.Right: {
2767 int y = area.Y + (area.Height / 2) - 4;
2770 for (int i = 4; i != 0; i--)
2772 dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
2774 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
2776 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
2787 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
2793 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
2794 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
2796 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
2797 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
2800 for (int i = 0; i < 11; i += 4) {
2801 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
2802 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
2805 for (int i = 3; i < 13; i += 4)
2806 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
2810 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
2811 StringFormat format) {
2814 brush=new SolidBrush(ControlPaint.Light(color, 95));
2816 layoutRectangle.Offset(1.0f, 1.0f);
2817 graphics.DrawString(s, font, brush, layoutRectangle, format);
2819 brush.Color=ControlPaint.Light(color, 50);
2820 layoutRectangle.Offset(-1.0f, -1.0f);
2821 graphics.DrawString(s, font, brush, layoutRectangle, format);
2826 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
2827 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
2829 Pen pen=new Pen(color, 1);
2832 case ButtonBorderStyle.Solid: {
2833 pen.DashStyle=DashStyle.Solid;
2837 case ButtonBorderStyle.Dashed: {
2838 pen.DashStyle=DashStyle.Dash;
2842 case ButtonBorderStyle.Dotted: {
2843 pen.DashStyle=DashStyle.Dot;
2847 case ButtonBorderStyle.Inset: {
2848 pen.DashStyle=DashStyle.Solid;
2852 case ButtonBorderStyle.Outset: {
2853 pen.DashStyle=DashStyle.Solid;
2858 case ButtonBorderStyle.None: {
2866 case ButtonBorderStyle.Outset: {
2868 int hue, brightness, saturation;
2869 int brightnessSteps;
2870 int brightnessDownSteps;
2872 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
2874 brightnessDownSteps=brightness/width;
2875 if (brightness>127) {
2876 brightnessSteps=Math.Max(6, (160-brightness)/width);
2878 brightnessSteps=(127-brightness)/width;
2881 for (int i=0; i<width; i++) {
2883 case Border3DSide.Left: {
2885 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
2886 pen=new Pen(colorGrade, 1);
2887 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
2891 case Border3DSide.Right: {
2893 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
2894 pen=new Pen(colorGrade, 1);
2895 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
2899 case Border3DSide.Top: {
2901 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
2902 pen=new Pen(colorGrade, 1);
2903 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
2907 case Border3DSide.Bottom: {
2909 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
2910 pen=new Pen(colorGrade, 1);
2911 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
2919 case ButtonBorderStyle.Inset: {
2921 int hue, brightness, saturation;
2922 int brightnessSteps;
2923 int brightnessDownSteps;
2925 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
2927 brightnessDownSteps=brightness/width;
2928 if (brightness>127) {
2929 brightnessSteps=Math.Max(6, (160-brightness)/width);
2931 brightnessSteps=(127-brightness)/width;
2934 for (int i=0; i<width; i++) {
2936 case Border3DSide.Left: {
2938 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
2939 pen=new Pen(colorGrade, 1);
2940 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
2944 case Border3DSide.Right: {
2946 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
2947 pen=new Pen(colorGrade, 1);
2948 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
2952 case Border3DSide.Top: {
2954 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
2955 pen=new Pen(colorGrade, 1);
2956 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
2960 case Border3DSide.Bottom: {
2962 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
2963 pen=new Pen(colorGrade, 1);
2964 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
2973 I decided to have the for-loop duplicated for speed reasons;
2974 that way we only have to switch once (as opposed to have the
2975 for-loop around the switch)
2979 case Border3DSide.Left: {
2980 for (int i=0; i<width; i++) {
2981 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
2986 case Border3DSide.Right: {
2987 for (int i=0; i<width; i++) {
2988 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
2993 case Border3DSide.Top: {
2994 for (int i=0; i<width; i++) {
2995 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3000 case Border3DSide.Bottom: {
3001 for (int i=0; i<width; i++) {
3002 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3014 This function actually draws the various caption elements.
3015 This way we can scale them nicely, no matter what size, and they
3016 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
3019 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
3021 case CaptionButton.Close: {
3022 pen.StartCap=LineCap.Triangle;
3023 pen.EndCap=LineCap.Triangle;
3025 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);
3026 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);
3029 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3030 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3034 case CaptionButton.Help: {
3035 StringFormat sf = new StringFormat();
3036 SolidBrush sb = new SolidBrush(color);
3037 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
3039 sf.Alignment=StringAlignment.Center;
3040 sf.LineAlignment=StringAlignment.Center;
3043 graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
3052 case CaptionButton.Maximize: {
3053 /* Top 'caption bar' line */
3054 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3055 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);
3058 /* Left side line */
3059 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3060 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3063 /* Right side line */
3064 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3065 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);
3069 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3070 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3075 case CaptionButton.Minimize: {
3077 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3078 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
3083 case CaptionButton.Restore: {
3084 /** First 'window' **/
3085 /* Top 'caption bar' line */
3086 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3087 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);
3090 /* Left side line */
3091 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3092 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);
3095 /* Right side line */
3096 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3097 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);
3101 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3102 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);
3105 /** Second 'window' **/
3106 /* Top 'caption bar' line */
3107 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3108 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);
3111 /* Left side line */
3112 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3113 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3116 /* Right side line */
3117 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3118 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);
3122 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3123 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3132 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
3133 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
3135 case DrawFrameControlTypes.Button: {
3136 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
3137 /* Goes first, affects the background */
3138 if ((State & DrawFrameControlStates.Checked)!=0) {
3139 HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
3140 graphics.FillRectangle(hatchBrush,rectangle);
3141 hatchBrush.Dispose();
3144 if ((State & DrawFrameControlStates.Pushed)!=0) {
3145 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3146 } else if ((State & DrawFrameControlStates.Flat)!=0) {
3147 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3148 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
3149 /* Same as normal, it would seem */
3150 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3152 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3154 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
3155 Pen penFatDark = new Pen(ColorButtonShadow, 1);
3156 Pen penFatLight = new Pen(ColorButtonLight, 1);
3159 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3161 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
3162 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
3164 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
3165 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
3167 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
3169 if ((State & DrawFrameControlStates.Checked)!=0) {
3170 SolidBrush buttonBrush;
3172 if ((State & DrawFrameControlStates.Inactive)!=0) {
3173 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
3175 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
3177 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
3179 penFatDark.Dispose();
3180 penFatLight.Dispose();
3181 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
3182 throw new NotImplementedException () ;
3183 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
3184 throw new NotImplementedException ();
3185 } else { /* Must be Checkbox */
3191 /* Goes first, affects the background */
3192 if ((State & DrawFrameControlStates.Pushed)!=0 ||
3193 (State & DrawFrameControlStates.Inactive)!=0) {
3194 graphics.FillRectangle(SystemBrushes.Control, rectangle);
3196 graphics.FillRectangle(SystemBrushes.Window, rectangle);
3199 /* Draw the sunken frame */
3200 if ((State & DrawFrameControlStates.Flat)!=0) {
3201 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3203 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3206 /* Make sure we've got at least a line width of 1 */
3207 lineWidth=Math.Max(3, rectangle.Width/6);
3208 Scale=Math.Max(1, rectangle.Width/12);
3210 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
3211 if ((State & DrawFrameControlStates.Inactive)!=0) {
3212 pen=SystemPens.ControlDark;
3214 pen=SystemPens.ControlText;
3217 if ((State & DrawFrameControlStates.Checked)!=0) {
3218 /* Need to draw a check-mark */
3219 for (int i=0; i<lineWidth; i++) {
3220 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
3221 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);
3229 case DrawFrameControlTypes.Caption: {
3234 case DrawFrameControlTypes.Menu: {
3239 case DrawFrameControlTypes.Scroll: {
3246 /* Generic scroll button */
3247 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
3248 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
3249 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
3250 area.Y + 1, area.Width - 2 , area.Height - 2);
3252 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
3253 area.Y, area.Width, area.Height);
3258 dc.FillRectangle (new SolidBrush (Color.Blue), area);
3260 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
3261 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
3263 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
3264 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
3267 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
3270 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
3273 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
3274 area.Y + 1, 1, area.Height -3);
3276 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
3277 area.Y, 1, area.Height - 1);
3279 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
3280 area.Y + 2, area.Width - 4, area.Height - 4);
3284 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
3285 switch (border_style){
3286 case BorderStyle.Fixed3D:
3287 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
3288 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
3289 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
3290 area.Y + area.Height - 1);
3291 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
3292 area.Y + area.Height);
3294 case BorderStyle.FixedSingle:
3295 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
3297 case BorderStyle.None:
3303 #endregion // ControlPaint