(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
blobc04ded71a618d6eea4c69895bbd2950679b598d3
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:
8 //
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.
22 // Authors:
23 // Jordi Mas i Hernandez, jordi@ximian.com
24 // Peter Bartok, pbartok@novell.com
25 // John BouAntoun, jba-mono@optusnet.com.au
29 // $Revision: 1.60 $
30 // $Modtime: $
31 // $Log: ThemeWin32Classic.cs,v $
32 // Revision 1.60 2004/11/09 03:12:00 jackson
33 // * ThemeWin32Classic.cs (DrawTabControl): Render tabs from top to
34 // bottom when they are bottom aligned so the bottoms of the tabs get
35 // displayed.
36 // * TabControl.cs (DropRow): Move rows up instead of down when the
37 // tab control is bottom aligned.
39 // Revision 1.59 2004/11/08 20:40:08 jackson
40 // Render the little scrolling jimmi in the correct location with bottom aligned tabs
42 // Revision 1.58 2004/11/08 14:15:00 jordi
43 // fixes vertical scrollbar and removes dead code
45 // Revision 1.57 2004/11/05 05:47:34 jba
46 // - Fix Button rendering for FlatStyle = Flat or Popup
47 // - Fix RadioButton and CheckBox rendering when Appearance = Button (normal and
48 // flatstyle).
49 // - Correct outer rectangle color when drawing focus rectangle
50 // - Adjust button bounds to be 1 px smaller when focused
51 // - Make button not draw sunken 3d border when pushed (windows compat)
52 // - Fix CPDrawBorder3D to not make bottom right hand corner rounded
53 // - Offset the text in RadioButton and Checkbox when being rendered as a button.
54 // - Hover and Click behaviour for Colored FlatStyle.Flat and Popup radiobuttons
55 // - Fixed disabled rendering for colored flatstyle radiobuttons (both)
56 // - Fixed disabled text rendering for normally rendered radiobuttons
58 // Revision 1.56 2004/11/04 11:26:09 ravindra
59 // - Changed default ListView values signatures (prefixed all with ListView).
60 // - Fixed default size values for VScrollBar and HScrollBar.
61 // - Fixed DrawListViewItem method.
63 // Revision 1.55 2004/11/03 18:52:14 jackson
64 // Initial implementation of the scrolly widgerywoo
66 // Revision 1.54 2004/11/02 20:40:54 jackson
67 // Move the row with the selected tab to the bottom
69 // Revision 1.53 2004/11/02 02:47:55 jackson
70 // New rendering and sizing code for tab controls
72 // Revision 1.52 2004/10/30 10:23:02 ravindra
73 // Drawing ListView and some default values.
75 // Revision 1.51 2004/10/26 09:55:48 ravindra
76 // Some formatting for my last checkins.
78 // Revision 1.50 2004/10/26 09:36:32 ravindra
79 // Implemented DetailView drawing for ListView control and default values.
81 // Revision 1.49 2004/10/18 04:49:25 pbartok
82 // - Added ToolTip drawing code
84 // Revision 1.48 2004/10/15 15:08:49 ravindra
85 // Added ColumnHeaderHeight property in Theme for ListView.
87 // Revision 1.47 2004/10/13 15:06:37 pbartok
88 // - Path from John BouAntoun:
89 // * Fix check rendering (centre correctly for normal style, offset
90 // correctly for FlatStyle).
91 // * Fix border color usage (use backcolor) for FlatStyle.Popup
92 // * Use checkbox.Capture instead of checkbox.is_pressed when rendering
93 // flatstyle states.
95 // Revision 1.46 2004/10/13 03:48:15 pbartok
96 // - Removed all occurences of SystemColors and replaced them with the
97 // matching theme color
99 // Revision 1.45 2004/10/13 03:41:45 pbartok
100 // - From John BouAntoun: Added an overload to CPDrawBorder3D to allow him
101 // using the function for flatstyle drawing
102 // - Changed functions to use the new version of CPDrawBorder3D
104 // Revision 1.44 2004/10/13 02:45:21 pbartok
105 // - Fixes from John BouAntoun: now handles forecolors and backcolors for
106 // flatstyle rendered controls much better; It also fixes normal checkbox
107 // rendering when pushed or disabled.
109 // Revision 1.43 2004/10/07 14:56:51 jordi
110 // Removes deletion of cached brushes
112 // Revision 1.42 2004/10/06 09:59:05 jordi
113 // removes warnings from compilation
115 // Revision 1.41 2004/10/05 16:15:30 jackson
116 // Improve rendering of the radio button patch by John BouAntoun
118 // Revision 1.40 2004/10/05 09:04:31 ravindra
119 // - Added DrawListView method and ListViewDefaultSize property.
120 // - Changed ControlPaint method calls to CPDrawXXX wherever possible.
121 // - Changed DOS style CRLF to Unix format (dos2unix).
123 // Revision 1.39 2004/10/04 07:09:37 jordi
124 // fixes right button position causing right button not showing on horizontal scrollbars
126 // Revision 1.38 2004/09/28 18:44:25 pbartok
127 // - Streamlined Theme interfaces:
128 // * Each DrawXXX method for a control now is passed the object for the
129 // control to be drawn in order to allow accessing any state the theme
130 // might require
132 // * ControlPaint methods for the theme now have a CP prefix to avoid
133 // name clashes with the Draw methods for controls
135 // * Every control now retrieves it's DefaultSize from the current theme
137 // Revision 1.37 2004/09/09 08:28:11 pbartok
138 // - Improve disabled string look
140 // Revision 1.36 2004/09/09 03:03:49 ravindra
141 // PictureBox would not draw a null image to avoid crash.
143 // Revision 1.35 2004/09/07 17:12:26 jordi
144 // GroupBox control
146 // Revision 1.34 2004/09/07 09:40:15 jordi
147 // LinkLabel fixes, methods, multiple links
149 // Revision 1.33 2004/09/05 08:03:51 jordi
150 // fixes bugs, adds flashing on certain situations
152 // Revision 1.32 2004/09/02 16:32:54 jordi
153 // implements resource pool for pens, brushes, and hatchbruses
155 // Revision 1.31 2004/08/25 20:04:40 ravindra
156 // Added the missing divider code and grip for ToolBar Control.
158 // Revision 1.30 2004/08/25 18:29:14 jordi
159 // new methods, properties, and fixes for progressbar
161 // Revision 1.29 2004/08/25 00:43:13 ravindra
162 // Fixed wrapping related issues in ToolBar control.
164 // Revision 1.28 2004/08/24 18:37:02 jordi
165 // fixes formmating, methods signature, and adds missing events
167 // Revision 1.27 2004/08/24 16:16:46 jackson
168 // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
170 // Revision 1.26 2004/08/21 01:52:08 ravindra
171 // Improvments in mouse event handling in the ToolBar control.
173 // Revision 1.25 2004/08/20 00:12:51 jordi
174 // fixes methods signature
176 // Revision 1.24 2004/08/19 22:25:31 jordi
177 // theme enhancaments
179 // Revision 1.23 2004/08/18 19:16:53 jordi
180 // Move colors to a table
182 // Revision 1.22 2004/08/17 19:29:11 jackson
183 // Don't use KnownColor to create colours. It has a large startup time.
185 // Revision 1.21 2004/08/15 23:20:54 ravindra
186 // Changes to Theme for ToolBar control and also dos2unix format.
188 // Revision 1.20 2004/08/13 21:22:18 jordi
189 // removes redundant code and fixes issues with tickposition
191 // Revision 1.19 2004/08/12 20:29:01 jordi
192 // Trackbar enhancement, fix mouse problems, highli thumb, etc
194 // Revision 1.18 2004/08/12 18:54:37 jackson
195 // Handle owner draw status bars
197 // Revision 1.17 2004/08/11 01:31:35 jackson
198 // Create Brushes as little as possible
200 // Revision 1.16 2004/08/10 19:21:27 jordi
201 // scrollbar enhancements and standarize on win colors defaults
203 // Revision 1.15 2004/08/10 18:52:30 jackson
204 // Implement DrawItem functionality
206 // Revision 1.14 2004/08/09 21:34:54 jackson
207 // Add support for drawing status bar and get status bar item sizes
209 // Revision 1.13 2004/08/09 21:21:49 jackson
210 // Use known colors for default control colours
212 // Revision 1.12 2004/08/09 21:12:15 jackson
213 // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
215 // Revision 1.11 2004/08/09 17:31:13 jackson
216 // New names for control properties
218 // Revision 1.10 2004/08/09 17:00:00 jackson
219 // Add default window color properties
221 // Revision 1.9 2004/08/09 16:17:19 jackson
222 // Use correct default back color
224 // Revision 1.8 2004/08/09 15:53:12 jackson
225 // Themes now handle default control properties so coloring will be consistent
227 // Revision 1.7 2004/08/08 22:54:21 jordi
228 // Label BorderStyles
230 // Revision 1.6 2004/08/08 18:09:53 jackson
231 // Add pen_buttonface
233 // Revision 1.5 2004/08/08 17:34:28 jordi
234 // Use Windows Standard Colours
236 // Revision 1.4 2004/08/07 23:31:15 jordi
237 // fixes label bug and draw method name
239 // Revision 1.3 2004/08/07 19:05:44 jordi
240 // Theme colour support and GetSysColor defines
242 // Revision 1.2 2004/08/07 00:01:39 pbartok
243 // - Fixed some rounding issues with float/int
245 // Revision 1.1 2004/07/26 17:42:03 jordi
246 // Theme support
250 using System.Drawing;
251 using System.Drawing.Drawing2D;
252 using System.Drawing.Imaging;
254 namespace System.Windows.Forms
257 internal class ThemeWin32Classic : Theme
260 /* Default colors for Win32 classic theme */
261 uint [] theme_colors = { /* AARRGGBB */
262 (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR, 0xffc0c0c0,
263 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND, 0xff008080,
264 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION, 0xff000080,
265 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION, 0xff808080,
266 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU, 0xffc0c0c0,
267 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW, 0xffffffff,
268 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME, 0xff000000,
269 (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT, 0xff000000,
270 (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT, 0xff000000,
271 (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT, 0xffffffff,
272 (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER, 0xffc0c0c0,
273 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER, 0xffc0c0c0,
274 (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE, 0xff808080,
275 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT, 0xff000080,
276 (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT, 0xffffffff,
277 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE, 0xffc0c0c0,
278 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW, 0xff808080,
279 (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT, 0xff808080,
280 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT, 0xff000000,
281 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT, 0xffc0c0c0,
282 (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT, 0xffffffff,
283 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW, 0xff000000,
284 (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT, 0xffe0e0e0,
285 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT, 0xff000000,
286 (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK, 0xffffffff,
290 static protected Pen pen_ticks;
291 static protected SolidBrush br_arrow;
292 static protected SolidBrush br_progressbarblock;
293 static protected Pen pen_arrow;
296 /* Cache */
297 protected SolidBrush label_br_fore_color;
298 protected SolidBrush label_br_back_color;
300 #region Principal Theme Methods
301 public ThemeWin32Classic ()
303 label_br_fore_color = null;
304 label_br_back_color = null;
306 /* Init Default colour array*/
307 syscolors = Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
309 for (int i = 0; i < theme_colors.Length; i +=2)
310 syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
312 pen_ticks = new Pen (Color.Black);
313 br_arrow = new SolidBrush (Color.Black);
314 pen_arrow = new Pen (Color.Black);
315 br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128));
317 defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10);
318 defaultWindowForeColor = ColorButtonText;
319 default_font = new Font (FontFamily.GenericSansSerif, 8.25f);
322 public override bool DoubleBufferingSupported {
323 get {return true; }
325 #endregion // Principal Theme Methods
327 #region Internal Methods
328 protected SolidBrush GetControlBackBrush (Color c) {
329 if (c == DefaultControlBackColor)
330 return ResPool.GetSolidBrush (ColorButtonFace);
331 return new SolidBrush (c);
334 protected SolidBrush GetControlForeBrush (Color c) {
335 if (c == DefaultControlForeColor)
336 return ResPool.GetSolidBrush (ColorButtonText);
337 return new SolidBrush (c);
339 #endregion // Internal Methods
341 #region OwnerDraw Support
342 public override void DrawOwnerDrawBackground (DrawItemEventArgs e)
344 if (e.State == DrawItemState.Selected) {
345 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
346 return;
349 e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
352 public override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
354 if (e.State == DrawItemState.Focus)
355 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
357 #endregion // OwnerDraw Support
359 #region ButtonBase
360 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
361 int width;
362 int height;
363 Rectangle buttonRectangle;
365 width = button.ClientSize.Width;
366 height = button.ClientSize.Height;
368 SolidBrush sb = new SolidBrush(button.BackColor);
369 dc.FillRectangle(sb, button.ClientRectangle);
370 sb.Dispose();
372 // set up the button rectangle
373 buttonRectangle = button.ClientRectangle;
374 if (button.has_focus) {
375 // shrink the rectangle for the normal button drawing inside the focus rectangle
376 buttonRectangle.Inflate(-1,-1);
379 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
380 DrawFlatStyleButton (dc, buttonRectangle, button);
381 } else {
382 CPDrawButton(dc, buttonRectangle, button.ButtonState);
385 // First, draw the image
386 if ((button.image != null) || (button.image_list != null)) {
387 // Need to draw a picture
388 Image i;
389 int image_x;
390 int image_y;
391 int image_width;
392 int image_height;
394 if (button.ImageIndex!=-1) { // We use ImageIndex instead of image_index since it will return -1 if image_list is null
395 i = button.image_list.Images[button.image_index];
396 } else {
397 i = button.image;
400 image_width = button.image.Width;
401 image_height = button.image.Height;
403 switch(button.image_alignment) {
404 case ContentAlignment.TopLeft: {
405 image_x=0;
406 image_y=0;
407 break;
410 case ContentAlignment.TopCenter: {
411 image_x=(width-image_width)/2;
412 image_y=0;
413 break;
416 case ContentAlignment.TopRight: {
417 image_x=width-image_width;
418 image_y=0;
419 break;
422 case ContentAlignment.MiddleLeft: {
423 image_x=0;
424 image_y=(height-image_height)/2;
425 break;
428 case ContentAlignment.MiddleCenter: {
429 image_x=(width-image_width)/2;
430 image_y=(height-image_height)/2;
431 break;
434 case ContentAlignment.MiddleRight: {
435 image_x=width-image_width;
436 image_y=(height-image_height)/2;
437 break;
440 case ContentAlignment.BottomLeft: {
441 image_x=0;
442 image_y=height-image_height;
443 break;
446 case ContentAlignment.BottomCenter: {
447 image_x=(width-image_width)/2;
448 image_y=height-image_height;
449 break;
452 case ContentAlignment.BottomRight: {
453 image_x=width-image_width;
454 image_y=height-image_height;
455 break;
458 default: {
459 image_x=0;
460 image_y=0;
461 break;
465 if (button.is_pressed) {
466 image_x+=2;
467 image_y+=2;
470 if (button.is_enabled) {
471 dc.DrawImage(i, image_x, image_y);
472 } else {
473 CPDrawImageDisabled(dc, i, image_x, image_y, ColorButtonFace);
477 // Draw the focus rectangle
478 if (button.has_focus) {
479 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
480 DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
481 } else {
482 CPDrawFocusRectangle(dc, button.ClientRectangle, button.ForeColor, button.BackColor);
486 // Now the text
487 if (button.text != null && button.text != String.Empty) {
488 Rectangle text_rect = new Rectangle(6, 6, button.ClientSize.Width-12, button.ClientSize.Height-12);
490 if (button.is_pressed) {
491 text_rect.X++;
492 text_rect.Y++;
495 if (button.is_enabled) {
496 SolidBrush b = new SolidBrush(button.ForeColor);
497 dc.DrawString(button.text, button.Font, b, text_rect, button.text_format);
498 b.Dispose();
499 } else {
500 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
501 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rect, button.text_format);
502 } else {
503 CPDrawStringDisabled(dc, button.text, button.Font, ColorButtonText, text_rect, button.text_format);
509 // draw the flat style part of the rectangle
510 public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
511 Color rect_back_color = button.BackColor;
512 Color rect_fore_color = button.ForeColor;
513 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
515 if (button.Enabled) {
516 if (button.Capture || button.is_entered) {
517 if (button.FlatStyle == FlatStyle.Flat) {
518 // fill the rectangle
519 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
521 // now draw the outer border
522 if (button.Capture && button.is_entered) {
523 rect_back_color = ControlPaint.LightLight (rect_back_color);
524 } else {
525 rect_back_color = ControlPaint.Light (rect_back_color);
528 // draw rectangle and fill it
529 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
530 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
531 } else {
532 // else it must be a popup button
534 if (button.Capture && button.is_entered) {
535 graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
536 } else {
537 // draw a 3d border
538 CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor);
539 graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
540 graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
544 // TODO: draw inner focus rectangle
546 } else {
547 // popup has a ButtonColorText forecolor, not a button.ForeCOlor
548 if (button.FlatStyle == FlatStyle.Popup) {
549 rect_fore_color = this.ColorButtonText;
552 // fill then draw outer rect
553 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
554 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
557 // finally some small tweaks to render radiobutton and checkbox
558 CheckBox checkbox = button as CheckBox;
559 RadioButton radiobutton = button as RadioButton;
560 if ((checkbox != null && checkbox.Checked) ||
561 (radiobutton != null && radiobutton.Checked)) {
562 if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
563 // render the hover for flat flatstyle and cheked
564 graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
565 } else if (!button.is_entered && !button.Capture) {
566 // render the checked state for popup when unhovered
567 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
570 } else {
571 // rendering checkbox or radio button style buttons
572 CheckBox checkbox = button as CheckBox;
573 RadioButton radiobutton = button as RadioButton;
574 bool draw_popup_checked = false;
576 if (button.FlatStyle == FlatStyle.Popup) {
577 rect_fore_color = this.ColorButtonText;
579 // see if we should draw a disabled checked popup button
580 draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
581 (radiobutton != null && radiobutton.Checked));
584 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
585 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
587 // finally draw the flatstyle checked effect if need
588 if (draw_popup_checked) {
589 // render the checked state for popup when unhovered
590 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
595 public override Size ButtonBaseDefaultSize {
596 get {
597 return new Size (75, 23);
600 #endregion // ButtonBase
602 #region CheckBox
603 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
604 StringFormat text_format;
605 Rectangle client_rectangle;
606 Rectangle text_rectangle;
607 Rectangle checkbox_rectangle;
608 SolidBrush sb;
609 int checkmark_size=13;
611 client_rectangle = checkbox.ClientRectangle;
612 text_rectangle = client_rectangle;
613 checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
615 text_format = new StringFormat();
616 text_format.Alignment=StringAlignment.Near;
617 text_format.LineAlignment=StringAlignment.Center;
619 /* Calculate the position of text and checkbox rectangle */
620 if (checkbox.appearance!=Appearance.Button) {
621 switch(checkbox.check_alignment) {
622 case ContentAlignment.BottomCenter: {
623 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
624 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
625 text_rectangle.X=client_rectangle.X;
626 text_rectangle.Width=client_rectangle.Width;
627 break;
630 case ContentAlignment.BottomLeft: {
631 checkbox_rectangle.X=client_rectangle.Left;
632 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
633 text_rectangle.X=client_rectangle.X+checkmark_size;
634 text_rectangle.Width=client_rectangle.Width-checkmark_size;
635 break;
638 case ContentAlignment.BottomRight: {
639 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
640 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
641 text_rectangle.X=client_rectangle.X;
642 text_rectangle.Width=client_rectangle.Width-checkmark_size;
643 break;
646 case ContentAlignment.MiddleCenter: {
647 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
648 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
649 text_rectangle.X=client_rectangle.X;
650 text_rectangle.Width=client_rectangle.Width;
651 break;
654 default:
655 case ContentAlignment.MiddleLeft: {
656 checkbox_rectangle.X=client_rectangle.Left;
657 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
658 text_rectangle.X=client_rectangle.X+checkmark_size;
659 text_rectangle.Width=client_rectangle.Width-checkmark_size;
660 break;
663 case ContentAlignment.MiddleRight: {
664 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
665 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
666 text_rectangle.X=client_rectangle.X;
667 text_rectangle.Width=client_rectangle.Width-checkmark_size;
668 break;
671 case ContentAlignment.TopCenter: {
672 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
673 checkbox_rectangle.Y=client_rectangle.Top;
674 text_rectangle.X=client_rectangle.X;
675 text_rectangle.Y=checkmark_size;
676 text_rectangle.Width=client_rectangle.Width;
677 text_rectangle.Height=client_rectangle.Height-checkmark_size;
678 break;
681 case ContentAlignment.TopLeft: {
682 checkbox_rectangle.X=client_rectangle.Left;
683 checkbox_rectangle.Y=client_rectangle.Top;
684 text_rectangle.X=client_rectangle.X+checkmark_size;
685 text_rectangle.Width=client_rectangle.Width-checkmark_size;
686 break;
689 case ContentAlignment.TopRight: {
690 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
691 checkbox_rectangle.Y=client_rectangle.Top;
692 text_rectangle.X=client_rectangle.X;
693 text_rectangle.Width=client_rectangle.Width-checkmark_size;
694 break;
697 } else {
698 text_rectangle.X=client_rectangle.X;
699 text_rectangle.Width=client_rectangle.Width;
702 text_rectangle.Inflate (-4, -4);
704 /* Set the horizontal alignment of our text */
705 switch(checkbox.text_alignment) {
706 case ContentAlignment.BottomLeft:
707 case ContentAlignment.MiddleLeft:
708 case ContentAlignment.TopLeft: {
709 text_format.Alignment=StringAlignment.Near;
710 break;
713 case ContentAlignment.BottomCenter:
714 case ContentAlignment.MiddleCenter:
715 case ContentAlignment.TopCenter: {
716 text_format.Alignment=StringAlignment.Center;
717 break;
720 case ContentAlignment.BottomRight:
721 case ContentAlignment.MiddleRight:
722 case ContentAlignment.TopRight: {
723 text_format.Alignment=StringAlignment.Far;
724 break;
728 /* Set the vertical alignment of our text */
729 switch(checkbox.text_alignment) {
730 case ContentAlignment.TopLeft:
731 case ContentAlignment.TopCenter:
732 case ContentAlignment.TopRight: {
733 text_format.LineAlignment=StringAlignment.Near;
734 break;
737 case ContentAlignment.BottomLeft:
738 case ContentAlignment.BottomCenter:
739 case ContentAlignment.BottomRight: {
740 text_format.LineAlignment=StringAlignment.Far;
741 break;
744 case ContentAlignment.MiddleLeft:
745 case ContentAlignment.MiddleCenter:
746 case ContentAlignment.MiddleRight: {
747 text_format.LineAlignment=StringAlignment.Center;
748 break;
752 ButtonState state = ButtonState.Normal;
753 if (checkbox.FlatStyle == FlatStyle.Flat) {
754 state |= ButtonState.Flat;
757 if (checkbox.Checked) {
758 state |= ButtonState.Checked;
761 if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
762 state |= ButtonState.Checked;
763 state |= ButtonState.Pushed;
766 // finally make sure the pushed and inavtive states are rendered
767 if (!checkbox.Enabled) {
768 state |= ButtonState.Inactive;
770 else if (checkbox.is_pressed) {
771 state |= ButtonState.Pushed;
775 // Start drawing
777 sb=new SolidBrush(checkbox.BackColor);
778 dc.FillRectangle(sb, checkbox.ClientRectangle);
779 sb.Dispose();
781 // render as per normal button
782 if (checkbox.appearance==Appearance.Button) {
783 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
784 DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
785 } else {
786 CPDrawButton(dc, checkbox.ClientRectangle, state);
788 } else {
789 // establish if we are rendering a flat style of some sort
790 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
791 DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
792 } else {
793 ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
797 // win32 compat - win32 seems to give the text a slight (3px) offset when rendering
798 Rectangle inner_text_rectangle = new Rectangle (text_rectangle.X + 2, text_rectangle.Y + 2, Math.Max (text_rectangle.Width - 4, 0), Math.Max (text_rectangle.Height - 4, 0));
799 // offset the text if it's pressed and a button
800 if (checkbox.Appearance == Appearance.Button) {
801 int buttonXOffset = 2;
802 int buttonYOffset = 0;
803 int pressedOffset = 0;
805 if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
806 pressedOffset += 2;
809 inner_text_rectangle = new Rectangle (inner_text_rectangle.X + buttonXOffset + pressedOffset, inner_text_rectangle.Y + buttonYOffset + pressedOffset, inner_text_rectangle.Width - 2*buttonXOffset, inner_text_rectangle.Height - 2*buttonYOffset);
811 /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
812 if (checkbox.Enabled) {
813 sb = ResPool.GetSolidBrush(checkbox.ForeColor);
814 dc.DrawString(checkbox.Text, checkbox.Font, sb, inner_text_rectangle, text_format);
815 } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
816 dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), inner_text_rectangle, text_format);
817 } else {
818 CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorButtonText, inner_text_rectangle, text_format);
821 if (checkbox.Focused) {
822 if (checkbox.FlatStyle != FlatStyle.Flat) {
823 DrawInnerFocusRectangle (dc, text_rectangle, checkbox.BackColor);
824 } else {
825 dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), text_rectangle);
830 // renders a checkBox with the Flat and Popup FlatStyle
831 private void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
833 Pen pen;
834 Rectangle rect;
835 Rectangle checkbox_rectangle;
836 Rectangle fill_rectangle;
837 int lineWidth;
838 int Scale;
840 // set up our rectangles first
841 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
842 // clip one pixel from bottom right for non popup rendered checkboxes
843 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
844 fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-3, 0), Math.Max(checkbox_rectangle.Height-3,0));
845 } else {
846 // clip two pixels from bottom right for non popup rendered checkboxes
847 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
848 fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-2, 0), Math.Max(checkbox_rectangle.Height-2,0));
851 // if disabled render in disabled state
852 if (checkbox.Enabled) {
853 // process the state of the checkbox
854 if (checkbox.is_entered || checkbox.Capture) {
855 // decide on which background color to use
856 if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
857 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
858 } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
859 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
860 } else {
861 // use regular window background color
862 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
865 // render the outer border
866 if (checkbox.FlatStyle == FlatStyle.Flat) {
867 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
868 } else {
869 // draw sunken effect
870 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
871 // draw top left
872 // graphics.DrawLine(ResPool.GetPen (ControlPaint.DarkDark (checkbox.BackColor)), checkbox_rectangle.X, checkbox_rectangle.Y, checkbox_rectangle.X, checkbox_rectangle.Y+checkbox_rectangle.Height);
873 //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);
875 } else {
876 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
878 if (checkbox.FlatStyle == FlatStyle.Flat) {
879 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
880 } else {
881 // draw the outer border
882 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
885 } else {
886 if (checkbox.FlatStyle == FlatStyle.Popup) {
887 graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
890 // draw disabled state,
891 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
894 /* Make sure we've got at least a line width of 1 */
895 lineWidth = Math.Max(3, fill_rectangle.Width/3);
896 Scale=Math.Max(1, fill_rectangle.Width/9);
898 // flat style check box is rendered inside a rectangle shifted down by one
899 rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
900 if (checkbox.Enabled) {
901 pen=ResPool.GetPen(checkbox.ForeColor);
902 } else {
903 pen=SystemPens.ControlDark;
906 if (checkbox.Checked) {
907 /* Need to draw a check-mark */
908 for (int i=0; i<lineWidth; i++) {
909 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
910 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);
916 #endregion // CheckBox
918 #region GroupBox
919 public override void DrawGroupBox (Graphics dc, Rectangle area, GroupBox box) {
920 SizeF size;
921 int width, y;
922 Rectangle rect = box.ClientRectangle;
923 Color disabled = ColorGrayText;
925 Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
926 Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
928 // TODO: When the Light and Dark methods work this code should be activate it
929 //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
930 //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
932 dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
934 size = dc.MeasureString (box.Text, box.Font);
935 width = (int) size.Width;
937 if (width > box.Width - 16)
938 width = box.Width - 16;
940 y = box.Font.Height / 2;
942 /* Draw group box*/
943 dc.DrawLine (pen_dark, 0, y, 8, y); // top
944 dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);
945 dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);
946 dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
948 dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
949 dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);
951 dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width, box.Height - 2); // bottom
952 dc.DrawLine (pen_light, 0, box.Height - 1, box.Width, box.Height - 1);
954 dc.DrawLine (pen_dark, box.Width - 2, y, box.Width - 2, box.Height - 2); // right
955 dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
958 /* Text */
959 if (box.Enabled)
960 dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0);
961 else
962 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor,
963 new RectangleF (10, 0, width, box.Font.Height), new StringFormat ());
967 public override Size GroupBoxDefaultSize {
968 get {
969 return new Size (200,100);
972 #endregion
974 #region HScrollBar
975 public override Size HScrollBarDefaultSize {
976 get {
977 return new Size (80, this.ScrollBarButtonSize);
981 #endregion // HScrollBar
983 #region Label
984 public override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) {
985 if (label_br_fore_color == null || label_br_fore_color.Color != label.ForeColor) {
986 label_br_fore_color = GetControlForeBrush (label.ForeColor);
989 if (label_br_back_color == null || label_br_back_color.Color != label.BackColor) {
990 label_br_back_color = GetControlBackBrush (label.BackColor);
993 dc.FillRectangle (label_br_back_color, clip_rectangle);
995 CPDrawBorderStyle (dc, clip_rectangle, label.BorderStyle);
997 if (label.Enabled) {
998 dc.DrawString (label.Text, label.Font, label_br_fore_color, clip_rectangle, label.string_format);
999 } else {
1000 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
1005 public override Size LabelDefaultSize {
1006 get {
1007 return new Size (100, 23);
1010 #endregion // Label
1012 #region ListView
1013 // Drawing
1014 public override void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control)
1016 Rectangle control_area = control.ClientRectangle;
1017 bool details = (control.View == View.Details);
1019 // Draw the border of the list view with a background
1020 dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), control_area);
1021 this.CPDrawBorderStyle (dc, control_area, control.BorderStyle);
1022 if (details) {
1023 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control),
1024 0, 0, control.TotalWidth, control.Font.Height);
1025 if (control.Columns.Count > 0) {
1026 foreach (ColumnHeader col in control.Columns) {
1027 this.CPDrawButton (dc, col.Rect, ButtonState.Normal);
1028 dc.DrawString (col.Text, control.Font,
1029 ResPool.GetSolidBrush (this.ColorButtonText),
1030 col.Rect, col.Format);
1033 if (control.GridLines) {
1034 // draw vertical gridlines
1035 foreach (ColumnHeader col in control.Columns)
1036 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1037 col.Rect.Right, col.Rect.Bottom,
1038 col.Rect.Right, control.TotalHeight);
1039 // draw horizontal gridlines
1040 foreach (ListViewItem item in control.Items)
1041 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1042 item.EntireRect.Left, item.EntireRect.Bottom,
1043 control.TotalWidth, item.EntireRect.Bottom);
1047 foreach (ListViewItem item in control.Items)
1048 this.DrawListViewItem (dc, control, item);
1051 // draws the ListViewItem of the given index
1052 private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1054 if (control.CheckBoxes) {
1055 if (control.StateImageList == null) {
1056 // Make sure we've got at least a line width of 1
1057 int check_wd = Math.Max (3, item.CheckRect.Width / 6);
1058 int scale = Math.Max (1, item.CheckRect.Width / 12);
1060 // define a rectangle inside the border area
1061 Rectangle rect = new Rectangle (item.CheckRect.X + 2,
1062 item.CheckRect.Y + 2,
1063 item.CheckRect.Width - 4,
1064 item.CheckRect.Height - 4);
1065 Pen pen = new Pen (SystemColors.WindowText, 2);
1066 dc.DrawRectangle (pen, rect);
1068 // Need to draw a check-mark
1069 if (item.Checked) {
1070 pen.Width = 1;
1071 // adjustments to get the check-mark at the right place
1072 rect.X ++; rect.Y ++;
1073 // following logic is taken from DrawFrameControl method
1074 for (int i = 0; i < check_wd; i++) {
1075 dc.DrawLine (pen, rect.Left + check_wd / 2,
1076 rect.Top + check_wd + i,
1077 rect.Left + check_wd / 2 + 2 * scale,
1078 rect.Top + check_wd + 2 * scale + i);
1079 dc.DrawLine (pen,
1080 rect.Left + check_wd / 2 + 2 * scale,
1081 rect.Top + check_wd + 2 * scale + i,
1082 rect.Left + check_wd / 2 + 6 * scale,
1083 rect.Top + check_wd - 2 * scale + i);
1087 else {
1088 if (item.Checked && control.StateImageList.Images.Count > 1)
1089 control.StateImageList.Draw (dc,
1090 item.CheckRect.Location, 1);
1091 else if (! item.Checked && control.StateImageList.Images.Count > 0)
1092 control.StateImageList.Draw (dc,
1093 item.CheckRect.Location, 0);
1097 // Item is drawn as a special case, as it is not just text
1098 if (control.View == View.LargeIcon) {
1099 if (item.ImageIndex > -1 &&
1100 control.LargeImageList != null &&
1101 item.ImageIndex < control.LargeImageList.Images.Count)
1102 control.LargeImageList.Draw (dc, item.IconRect.Location,
1103 item.ImageIndex);
1105 else {
1106 if (item.ImageIndex > -1 &&
1107 control.SmallImageList != null &&
1108 item.ImageIndex < control.SmallImageList.Images.Count)
1109 control.SmallImageList.Draw (dc, item.IconRect.Location,
1110 item.ImageIndex);
1113 // draw the item text
1114 Rectangle text_rect = Rectangle.Empty;
1115 text_rect.X = item.LabelRect.X + 1;
1116 text_rect.Y = item.LabelRect.Y + 1;
1117 text_rect.Width = item.LabelRect.Width - 3;
1118 text_rect.Height = item.LabelRect.Height - 2;
1120 // format for the item text
1121 StringFormat format = new StringFormat ();
1122 format.LineAlignment = StringAlignment.Center;
1123 if (control.View == View.LargeIcon)
1124 format.Alignment = StringAlignment.Center;
1125 else
1126 format.Alignment = StringAlignment.Near;
1128 if (!control.LabelWrap)
1129 format.FormatFlags = StringFormatFlags.NoWrap;
1131 dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1132 if (item.Text != null && item.Text.Length > 0)
1133 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1134 (item.ForeColor), text_rect, format);
1136 if (control.View == View.Details && control.Columns.Count > 0) {
1137 // draw subitems for details view
1138 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1139 int count = (control.Columns.Count < subItems.Count ?
1140 control.Columns.Count : subItems.Count);
1142 if (count > 0) {
1143 Rectangle sub_item_rect = Rectangle.Empty;
1144 sub_item_rect.X = item.LabelRect.Right + 1;
1145 sub_item_rect.Y = item.LabelRect.Y + 1;
1146 sub_item_rect.Height = item.LabelRect.Height - 2;
1148 ListViewItem.ListViewSubItem subItem;
1149 ColumnHeader col;
1151 // set the format for subitems
1152 format.FormatFlags = StringFormatFlags.NoWrap;
1153 format.Alignment = StringAlignment.Near;
1155 // 0th subitem is the item already drawn
1156 for (int index = 1; index < count; index++) {
1157 subItem = subItems [index];
1158 col = control.Columns [index];
1159 sub_item_rect.Width = col.Wd - 3;
1161 if (item.UseItemStyleForSubItems) {
1162 dc.FillRectangle (this.ResPool.GetSolidBrush
1163 (item.BackColor), sub_item_rect);
1164 if (subItem.Text != null && subItem.Text.Length > 0)
1165 dc.DrawString (subItem.Text, item.Font,
1166 this.ResPool.GetSolidBrush
1167 (item.ForeColor),
1168 sub_item_rect, format);
1170 else {
1171 dc.FillRectangle (this.ResPool.GetSolidBrush
1172 (subItem.BackColor),
1173 sub_item_rect);
1174 if (subItem.Text != null && subItem.Text.Length > 0)
1175 dc.DrawString (subItem.Text, subItem.Font,
1176 this.ResPool.GetSolidBrush
1177 (subItem.ForeColor),
1178 sub_item_rect, format);
1180 sub_item_rect.X += col.Wd;
1186 // Sizing
1187 public override Size ListViewCheckBoxSize {
1188 get { return new Size (16, 16); }
1191 public override int ListViewColumnHeaderHeight {
1192 get { return 16; }
1195 public override int ListViewDefaultColumnWidth {
1196 get { return 60; }
1199 public override int ListViewVerticalSpacing {
1200 get { return 22; }
1203 public override int ListViewEmptyColumnWidth {
1204 get { return 10; }
1207 public override int ListViewHorizontalSpacing {
1208 get { return 10; }
1211 public override Size ListViewDefaultSize {
1212 get { return new Size (121, 97); }
1214 #endregion // ListView
1216 #region Panel
1217 public override Size PanelDefaultSize {
1218 get {
1219 return new Size (200, 100);
1222 #endregion // Panel
1224 #region PictureBox
1225 public override void DrawPictureBox (Graphics dc, PictureBox pb) {
1226 Rectangle client = pb.ClientRectangle;
1227 int x, y, width, height;
1229 dc.FillRectangle (new SolidBrush (pb.BackColor), client);
1231 x = y = 0;
1232 if (pb.Image != null) {
1233 switch (pb.SizeMode) {
1234 case PictureBoxSizeMode.StretchImage:
1235 width = client.Width;
1236 height = client.Height;
1237 break;
1238 case PictureBoxSizeMode.CenterImage:
1239 width = client.Width;
1240 height = client.Height;
1241 x = width / 2;
1242 y = (height - pb.Image.Height) / 2;
1243 break;
1244 default:
1245 // Normal, AutoSize
1246 width = client.Width;
1247 height = client.Height;
1248 break;
1250 dc.DrawImage (pb.Image, x, y, width, height);
1252 CPDrawBorderStyle (dc, client, pb.BorderStyle);
1255 public override Size PictureBoxDefaultSize {
1256 get {
1257 return new Size (100, 50);
1260 #endregion // PictureBox
1262 #region ProgressBar
1263 public override void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar) {
1264 Rectangle client_area = progress_bar.client_area;
1265 Rectangle paint_area = progress_bar.paint_area;
1266 int steps = (progress_bar.Maximum - progress_bar.Minimum) / progress_bar.step;
1267 int space_betweenblocks = 2;
1268 int x;
1269 int block_width;
1270 int increment;
1271 int barpos_pixels;
1273 x = client_area.X;
1274 block_width = ((client_area.Height) * 2 ) / 3;
1275 barpos_pixels = ((progress_bar.Value - progress_bar.Minimum) * client_area.Width) / (progress_bar.Maximum - progress_bar.Minimum);
1276 increment = block_width + space_betweenblocks;
1278 /* Draw border */
1279 CPDrawBorder3D (dc, progress_bar.paint_area, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
1281 /* Draw Blocks */
1282 while ((x - client_area.X) < barpos_pixels) {
1283 dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
1284 x = x + increment;
1288 public override Size ProgressBarDefaultSize {
1289 get {
1290 return new Size (100, 23);
1294 #endregion // ProgressBar
1296 #region RadioButton
1297 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
1298 StringFormat text_format;
1299 Rectangle client_rectangle;
1300 Rectangle text_rectangle;
1301 Rectangle radiobutton_rectangle;
1302 SolidBrush sb;
1303 int radiobutton_size = 12;
1305 client_rectangle = radio_button.ClientRectangle;
1306 text_rectangle = client_rectangle;
1307 radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
1309 text_format = new StringFormat();
1310 text_format.Alignment = StringAlignment.Near;
1311 text_format.LineAlignment = StringAlignment.Center;
1313 /* Calculate the position of text and checkbox rectangle */
1314 if (radio_button.appearance!=Appearance.Button) {
1315 switch(radio_button.radiobutton_alignment) {
1316 case ContentAlignment.BottomCenter: {
1317 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1318 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1319 text_rectangle.X=client_rectangle.X;
1320 text_rectangle.Width=client_rectangle.Width;
1321 break;
1324 case ContentAlignment.BottomLeft: {
1325 radiobutton_rectangle.X=client_rectangle.Left;
1326 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1327 text_rectangle.X=client_rectangle.X+radiobutton_size;
1328 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1329 break;
1332 case ContentAlignment.BottomRight: {
1333 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1334 radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1335 text_rectangle.X=client_rectangle.X;
1336 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1337 break;
1340 case ContentAlignment.MiddleCenter: {
1341 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1342 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1343 text_rectangle.X=client_rectangle.X;
1344 text_rectangle.Width=client_rectangle.Width;
1345 break;
1348 default:
1349 case ContentAlignment.MiddleLeft: {
1350 radiobutton_rectangle.X=client_rectangle.Left;
1351 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1352 text_rectangle.X=client_rectangle.X+radiobutton_size;
1353 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1354 break;
1357 case ContentAlignment.MiddleRight: {
1358 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1359 radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1360 text_rectangle.X=client_rectangle.X;
1361 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1362 break;
1365 case ContentAlignment.TopCenter: {
1366 radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1367 radiobutton_rectangle.Y=client_rectangle.Top;
1368 text_rectangle.X=client_rectangle.X;
1369 text_rectangle.Y=radiobutton_size;
1370 text_rectangle.Width=client_rectangle.Width;
1371 text_rectangle.Height=client_rectangle.Height-radiobutton_size;
1372 break;
1375 case ContentAlignment.TopLeft: {
1376 radiobutton_rectangle.X=client_rectangle.Left;
1377 radiobutton_rectangle.Y=client_rectangle.Top;
1378 text_rectangle.X=client_rectangle.X+radiobutton_size;
1379 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1380 break;
1383 case ContentAlignment.TopRight: {
1384 radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1385 radiobutton_rectangle.Y=client_rectangle.Top;
1386 text_rectangle.X=client_rectangle.X;
1387 text_rectangle.Width=client_rectangle.Width-radiobutton_size;
1388 break;
1391 } else {
1392 text_rectangle.X=client_rectangle.X;
1393 text_rectangle.Width=client_rectangle.Width;
1396 text_rectangle.Inflate (-4, -4);
1398 /* Set the horizontal alignment of our text */
1399 switch(radio_button.text_alignment) {
1400 case ContentAlignment.BottomLeft:
1401 case ContentAlignment.MiddleLeft:
1402 case ContentAlignment.TopLeft: {
1403 text_format.Alignment=StringAlignment.Near;
1404 break;
1407 case ContentAlignment.BottomCenter:
1408 case ContentAlignment.MiddleCenter:
1409 case ContentAlignment.TopCenter: {
1410 text_format.Alignment=StringAlignment.Center;
1411 break;
1414 case ContentAlignment.BottomRight:
1415 case ContentAlignment.MiddleRight:
1416 case ContentAlignment.TopRight: {
1417 text_format.Alignment=StringAlignment.Far;
1418 break;
1422 /* Set the vertical alignment of our text */
1423 switch(radio_button.text_alignment) {
1424 case ContentAlignment.TopLeft:
1425 case ContentAlignment.TopCenter:
1426 case ContentAlignment.TopRight: {
1427 text_format.LineAlignment=StringAlignment.Near;
1428 break;
1431 case ContentAlignment.BottomLeft:
1432 case ContentAlignment.BottomCenter:
1433 case ContentAlignment.BottomRight: {
1434 text_format.LineAlignment=StringAlignment.Far;
1435 break;
1438 case ContentAlignment.MiddleLeft:
1439 case ContentAlignment.MiddleCenter:
1440 case ContentAlignment.MiddleRight: {
1441 text_format.LineAlignment=StringAlignment.Center;
1442 break;
1446 ButtonState state = ButtonState.Normal;
1447 if (radio_button.FlatStyle == FlatStyle.Flat) {
1448 state |= ButtonState.Flat;
1451 if (radio_button.Checked) {
1452 state |= ButtonState.Checked;
1455 // Start drawing
1457 sb=new SolidBrush(radio_button.BackColor);
1458 dc.FillRectangle(sb, radio_button.ClientRectangle);
1459 sb.Dispose();
1463 if (radio_button.appearance==Appearance.Button) {
1464 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
1465 DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
1466 } else {
1467 CPDrawButton(dc, radio_button.ClientRectangle, state);
1469 } else {
1470 // establish if we are rendering a flat style of some sort
1471 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
1472 DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
1473 } else {
1474 ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
1478 // wind32 compat - win32 seems to give the text a slight (3px) offset when rendering
1479 Rectangle inner_text_rectangle = new Rectangle (text_rectangle.X + 3, text_rectangle.Y, Math.Max (text_rectangle.Width - 3, 0), text_rectangle.Height);
1480 // offset the text if it's pressed and a button
1481 if (radio_button.Appearance == Appearance.Button) {
1482 int buttonXOffset = 2;
1483 int buttonYOffset = 0;
1484 int pressedOffset = 0;
1486 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
1487 pressedOffset += 2;
1490 inner_text_rectangle = new Rectangle (inner_text_rectangle.X + buttonXOffset + pressedOffset, inner_text_rectangle.Y + buttonYOffset + pressedOffset, inner_text_rectangle.Width - 2*buttonXOffset, inner_text_rectangle.Height - 2*buttonYOffset);
1493 /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
1494 sb=new SolidBrush(radio_button.ForeColor);
1495 dc.DrawString (radio_button.Text, radio_button.Font, sb, inner_text_rectangle, text_format);
1496 sb.Dispose();
1497 if (radio_button.Enabled) {
1498 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
1499 dc.DrawString(radio_button.Text, radio_button.Font, sb, inner_text_rectangle, text_format);
1500 } else if (radio_button.FlatStyle == FlatStyle.Flat) {
1501 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), inner_text_rectangle, text_format);
1502 } else {
1503 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorButtonText, inner_text_rectangle, text_format);
1506 if (radio_button.Focused) {
1507 if (radio_button.FlatStyle != FlatStyle.Flat) {
1508 DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
1509 } else {
1510 dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
1515 // renders a radio button with the Flat and Popup FlatStyle
1516 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
1518 int lineWidth;
1520 if (radio_button.Enabled) {
1521 // draw the outer flatstyle arcs
1522 if (radio_button.FlatStyle == FlatStyle.Flat) {
1523 graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
1525 // fill in the area depending on whether or not the mouse is hovering
1526 if (radio_button.is_entered && radio_button.Capture) {
1527 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1528 } else {
1529 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1531 } else {
1532 // must be a popup radio button
1533 // fill the control
1534 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
1536 if (radio_button.is_entered || radio_button.Capture) {
1537 // draw the popup 3d button knob
1538 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
1540 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
1541 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
1543 } else {
1544 // just draw lighter flatstyle outer circle
1545 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorButtonFace)), rectangle, 0, 359);
1548 } else {
1549 // disabled
1550 // fill control background color regardless of actual backcolor
1551 graphics.FillPie (ResPool.GetSolidBrush (this.ColorButtonFace), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1552 // draw the ark as control dark
1553 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorButtonFace)), rectangle, 0, 359);
1556 // draw the check
1557 lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
1558 if (radio_button.Checked) {
1559 SolidBrush buttonBrush;
1561 if (!radio_button.Enabled) {
1562 buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorButtonFace));
1563 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
1564 buttonBrush = ResPool.GetSolidBrush (this.ColorButtonText);
1565 } else {
1566 buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
1568 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
1572 public override Size RadioButtonDefaultSize {
1573 get {
1574 return new Size (104,24);
1577 #endregion // RadioButton
1579 #region ScrollBar
1580 public override void DrawScrollBar(Graphics dc, Rectangle clip_rectangle, ScrollBar bar) {
1581 int scrollbutton_width = bar.scrollbutton_width;
1582 int scrollbutton_height = bar.scrollbutton_height;
1583 Rectangle first_arrow_area;
1584 Rectangle second_arrow_area;
1585 Rectangle thumb_pos;
1587 thumb_pos = bar.ThumbPos;
1589 if (bar.vert) {
1590 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
1591 bar.FirstArrowArea = first_arrow_area;
1593 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
1594 bar.SecondArrowArea = second_arrow_area;
1596 thumb_pos.Width = bar.Width;
1597 bar.ThumbPos = thumb_pos;
1599 /* Buttons */
1600 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
1601 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
1603 /* Background */
1604 switch (bar.thumb_moving) {
1605 case ScrollBar.ThumbMoving.None: {
1606 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), 0,
1607 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
1609 break;
1611 case ScrollBar.ThumbMoving.Forward: {
1612 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1613 0, scrollbutton_height,
1614 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
1616 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1617 0, thumb_pos.Y + thumb_pos.Height,
1618 bar.ClientRectangle.Width, bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
1620 break;
1623 case ScrollBar.ThumbMoving.Backwards: {
1624 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1625 0, scrollbutton_height,
1626 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
1628 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1629 0, thumb_pos.Y + thumb_pos.Height,
1630 bar.ClientRectangle.Width, bar.ClientRectangle.Height - (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
1632 break;
1635 default:
1636 break;
1640 else {
1641 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
1642 bar.FirstArrowArea = first_arrow_area;
1644 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
1645 bar.SecondArrowArea = second_arrow_area;
1647 thumb_pos.Height = bar.Height;
1648 bar.ThumbPos = thumb_pos;
1650 /* Buttons */
1651 CPDrawScrollButton (dc, bar.FirstArrowArea, ScrollButton.Left, bar.firstbutton_state);
1652 CPDrawScrollButton (dc, bar.SecondArrowArea, ScrollButton.Right, bar.secondbutton_state);
1654 /* Background */
1655 //dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
1656 // 0, area.Width - (scrollbutton_width * 2), area.Height);
1658 switch (bar.thumb_moving) {
1659 case ScrollBar.ThumbMoving.None: {
1660 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
1661 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
1663 break;
1666 case ScrollBar.ThumbMoving.Forward: {
1667 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1668 scrollbutton_width, 0,
1669 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
1671 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1672 thumb_pos.X + thumb_pos.Width, 0,
1673 bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
1675 break;
1678 case ScrollBar.ThumbMoving.Backwards: {
1679 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1680 scrollbutton_width, 0,
1681 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
1683 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1684 thumb_pos.X + thumb_pos.Width, 0,
1685 bar.ClientRectangle.Width - (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
1688 break;
1691 default:
1692 break;
1696 /* Thumb */
1697 if (bar.Enabled)
1698 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
1701 public override int ScrollBarButtonSize {
1702 get { return 16; }
1704 #endregion // ScrollBar
1706 #region StatusBar
1707 public override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
1708 Rectangle area = sb.paint_area;
1709 int horz_border = 2;
1710 int vert_border = 2;
1712 dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
1714 if (sb.ShowPanels && sb.Panels.Count == 0) {
1715 // Create a default panel.
1716 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1718 StatusBarPanel panel = new StatusBarPanel ();
1719 Rectangle new_area = new Rectangle (area.X + horz_border,
1720 area.Y + horz_border,
1721 area.Width - StatusBarSizeGripWidth - horz_border,
1722 area.Height - horz_border);
1723 DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
1724 } else if (sb.ShowPanels) {
1725 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1726 int prev_x = area.X + horz_border;
1727 int y = area.Y + vert_border;
1728 for (int i = 0; i < sb.Panels.Count; i++) {
1729 Rectangle pr = new Rectangle (prev_x, y,
1730 sb.Panels [i].Width, area.Height);
1731 prev_x += pr.Width + StatusBarHorzGapWidth;
1732 DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
1736 if (sb.SizingGrip)
1737 CPDrawSizeGrip (dc, ColorButtonFace, area);
1742 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
1743 SolidBrush br_forecolor, StatusBarPanel panel) {
1744 int border_size = 3; // this is actually const, even if the border style is none
1746 area.Height -= border_size;
1747 if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
1748 Border3DStyle border_style = Border3DStyle.SunkenInner;
1749 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
1750 border_style = Border3DStyle.RaisedOuter;
1751 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
1754 if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
1755 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
1756 dc, panel.Parent.Font, area, index, DrawItemState.Default,
1757 panel, panel.Parent.ForeColor, panel.Parent.BackColor);
1758 panel.Parent.OnDrawItemInternal (e);
1759 return;
1762 int left = area.Left;
1763 if (panel.Icon != null) {
1764 left += 2;
1765 int size = area.Height - border_size;
1766 Rectangle ia = new Rectangle (left, border_size, size, size);
1767 dc.DrawIcon (panel.Icon, left, area.Top);
1768 left += panel.Icon.Width;
1771 if (panel.Text == String.Empty)
1772 return;
1774 string text = panel.Text;
1775 StringFormat string_format = new StringFormat ();
1776 string_format.LineAlignment = StringAlignment.Center;
1777 string_format.Alignment = StringAlignment.Near;
1778 string_format.FormatFlags = StringFormatFlags.NoWrap;
1780 if (text [0] == '\t') {
1781 string_format.Alignment = StringAlignment.Center;
1782 text = text.Substring (1);
1783 if (text [0] == '\t') {
1784 string_format.Alignment = StringAlignment.Far;
1785 text = text.Substring (1);
1789 float x = left + border_size;
1790 float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
1792 dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
1795 public override int StatusBarSizeGripWidth {
1796 get { return 15; }
1799 public override int StatusBarHorzGapWidth {
1800 get { return 3; }
1803 public override Size StatusBarDefaultSize {
1804 get {
1805 return new Size (100, 22);
1808 #endregion // StatusBar
1810 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
1812 // Do we need to fill the back color? It can't be changed...
1813 dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
1814 Rectangle panel_rect = GetTabPanelRectExt (tab);
1816 if (tab.Appearance == TabAppearance.Normal) {
1817 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorButtonFace);
1818 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
1821 if (tab.Alignment == TabAlignment.Top) {
1822 for (int r = tab.TabPages.Count; r > 0; r--) {
1823 for (int i = 0; i < tab.TabPages.Count; i++) {
1824 if (i == tab.SelectedIndex)
1825 continue;
1826 if (r != tab.TabPages [i].Row)
1827 continue;
1828 Rectangle rect = tab.GetTabRect (i);
1829 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1832 } else {
1833 for (int r = 0; r < tab.TabPages.Count; r++) {
1834 for (int i = 0; i < tab.TabPages.Count; i++) {
1835 if (i == tab.SelectedIndex)
1836 continue;
1837 if (r != tab.TabPages [i].Row)
1838 continue;
1839 Rectangle rect = tab.GetTabRect (i);
1840 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1845 if (tab.SelectedIndex != -1) {
1846 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, tab.GetTabRect (tab.SelectedIndex), true);
1849 if (tab.ShowSlider) {
1850 Rectangle right = GetTabControlRightScrollRect (tab);
1851 Rectangle left = GetTabControlLeftScrollRect (tab);
1852 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
1853 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
1857 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
1859 switch (tab.Alignment) {
1860 case TabAlignment.Top:
1861 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
1862 case TabAlignment.Bottom:
1863 Rectangle panel_rect = GetTabPanelRectExt (tab);
1864 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
1865 default:
1866 throw new Exception ("vertical tab rendering");
1870 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
1872 switch (tab.Alignment) {
1873 case TabAlignment.Top:
1874 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
1875 case TabAlignment.Bottom:
1876 Rectangle panel_rect = GetTabPanelRectExt (tab);
1877 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
1878 default:
1879 throw new Exception ("vertical tab rendering");
1883 public override Size TabControlDefaultItemSize {
1884 get { return new Size (42, 21); }
1887 public override Point TabControlDefaultPadding {
1888 get { return new Point (6, 3); }
1891 public override int TabControlMinimumTabWidth {
1892 get { return 42; }
1895 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
1897 Rectangle ext = GetTabPanelRectExt (tab);
1898 // Account for border size
1899 return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
1902 public override Size TabControlGetSpacing (TabControl tab) {
1903 switch (tab.Appearance) {
1904 case TabAppearance.Normal:
1905 return new Size (1, -2);
1906 case TabAppearance.Buttons:
1907 return new Size (3, 3);
1908 case TabAppearance.FlatButtons:
1909 return new Size (9, 3);
1910 default:
1911 throw new Exception ("Invalid Appearance value: " + tab.Appearance);
1915 private Rectangle GetTabPanelRectExt (TabControl tab)
1917 // Offset the tab from the top corner
1918 Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
1919 tab.ClientRectangle.Y,
1920 tab.ClientRectangle.Width - 2,
1921 tab.ClientRectangle.Height - 1);
1923 if (tab.TabCount == 0)
1924 return res;
1926 int spacing = TabControlGetSpacing (tab).Height;
1927 int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
1929 switch (tab.Alignment) {
1930 case TabAlignment.Left:
1931 res.X += offset;
1932 res.Width -= offset;
1933 break;
1934 case TabAlignment.Right:
1935 res.Width -= offset;
1936 break;
1937 case TabAlignment.Top:
1938 res.Y += offset;
1939 res.Height -= offset;
1940 break;
1941 case TabAlignment.Bottom:
1942 res.Height -= offset;
1943 break;
1946 return res;
1949 private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
1951 int FlatButtonSpacing = 8;
1952 int RoundCornerSize = 5;
1953 Rectangle interior;
1954 int res = bounds.Width;
1956 // we can't fill the background right away because the bounds might be adjusted if the tab is selected
1958 if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
1960 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
1962 // Separators
1963 if (tab.Appearance == TabAppearance.FlatButtons) {
1964 int width = bounds.Width;
1965 bounds.Width += (FlatButtonSpacing - 2);
1966 res = bounds.Width;
1967 CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
1968 bounds.Width = width;
1971 if (is_selected) {
1972 CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
1973 } else if (tab.Appearance != TabAppearance.FlatButtons) {
1974 CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
1977 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
1978 } else {
1979 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
1981 switch (tab.Alignment) {
1983 case TabAlignment.Top:
1986 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
1988 dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
1989 dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
1990 dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
1992 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
1993 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
1994 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
1996 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1998 break;
2000 case TabAlignment.Bottom:
2002 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2004 dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
2005 dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
2007 dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
2008 dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
2010 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
2011 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
2012 dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
2014 interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2016 break;
2018 default:
2019 throw new NotImplementedException ("Vertical tab drawing");
2024 if (page.Focused) {
2025 using (Pen pen = new Pen (Color.Black, 1) ) {
2026 pen.DashStyle = DashStyle.Dot;
2027 dc.DrawRectangle (pen, interior);
2031 if (page.Text != String.Empty) {
2032 StringFormat string_format = new StringFormat ();
2033 string_format.Alignment = StringAlignment.Center;
2034 string_format.LineAlignment = StringAlignment.Center;
2035 string_format.FormatFlags = StringFormatFlags.NoWrap;
2036 interior.Y++;
2037 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2040 return res;
2043 #region ToolBar
2044 public override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
2045 StringFormat format = new StringFormat ();
2046 format.Trimming = StringTrimming.EllipsisWord;
2047 if (control.textAlignment == ToolBarTextAlign.Underneath) {
2048 format.LineAlignment = StringAlignment.Center;
2049 format.Alignment = StringAlignment.Center;
2050 } else {
2051 format.LineAlignment = StringAlignment.Center;
2052 format.Alignment = StringAlignment.Near;
2055 // Exclude the area for divider
2056 Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2,
2057 control.Width, control.Height - ToolBarGripWidth / 2);
2058 bool flat = (control.Appearance == ToolBarAppearance.Flat);
2059 dc.FillRectangle (SystemBrushes.Control, paint_area);
2060 CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
2062 if (control.Divider)
2063 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
2065 foreach (ToolBarButton button in control.Buttons) {
2067 Image image = null;
2068 Rectangle buttonArea = button.Rectangle;
2069 Rectangle imgRect = Rectangle.Empty; // rect to draw the image
2070 Rectangle txtRect = buttonArea; // rect to draw the text
2071 Rectangle ddRect = Rectangle.Empty; // rect for the drop down arrow
2073 // calculate different rects and draw the frame if its not separator button
2074 if (button.Style != ToolBarButtonStyle.Separator) {
2075 /* Adjustment for drop down arrow */
2076 if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
2077 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
2078 ddRect.Y = buttonArea.Y;
2079 ddRect.Width = this.ToolBarDropDownWidth;
2080 ddRect.Height = buttonArea.Height;
2083 // calculate txtRect and imgRect, if imageIndex and imageList are present
2084 if (button.ImageIndex > -1 && control.ImageList != null) {
2085 if (button.ImageIndex < control.ImageList.Images.Count)
2086 image = control.ImageList.Images [button.ImageIndex];
2087 // draw the image at the centre if textalignment is underneath
2088 if (control.TextAlign == ToolBarTextAlign.Underneath) {
2089 imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width
2090 - control.ImageSize.Width) / 2)
2091 + this.ToolBarImageGripWidth;
2092 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2093 imgRect.Width = control.ImageSize.Width;
2094 imgRect.Height = control.ImageSize.Height;
2096 txtRect.X = buttonArea.X;
2097 txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
2098 txtRect.Width = buttonArea.Width - ddRect.Width;
2099 txtRect.Height = buttonArea.Height - imgRect.Height
2100 - 2 * this.ToolBarImageGripWidth;
2102 else {
2103 imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
2104 imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2105 imgRect.Width = control.ImageSize.Width;
2106 imgRect.Height = control.ImageSize.Height;
2108 txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
2109 txtRect.Y = buttonArea.Y;
2110 txtRect.Width = buttonArea.Width - imgRect.Width
2111 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
2112 txtRect.Height = buttonArea.Height;
2115 /* Draw the button frame, only if it is not a separator */
2116 if (flat) {
2117 if (button.Pushed || button.Pressed) {
2118 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
2119 } else if (button.Hilight) {
2120 dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
2121 if (! ddRect.IsEmpty) {
2122 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X,
2123 ddRect.Y + ddRect.Height);
2124 buttonArea.Width -= this.ToolBarDropDownWidth;
2128 else { // normal toolbar
2129 if (button.Pushed || button.Pressed) {
2130 CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
2131 Border3DSide.All, ColorButtonFace);
2132 if (! ddRect.IsEmpty) {
2133 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
2134 Border3DSide.Left, ColorButtonFace);
2135 buttonArea.Width -= this.ToolBarDropDownWidth;
2138 else {
2139 CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
2140 Border3DSide.All, ColorButtonFace);
2141 if (! ddRect.IsEmpty) {
2142 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
2143 Border3DSide.Left, ColorButtonFace);
2144 buttonArea.Width -= this.ToolBarDropDownWidth;
2149 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
2150 imgRect, image, txtRect, ddRect, flat);
2154 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
2155 Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect,
2156 Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
2157 if (! button.Visible)
2158 return;
2160 switch (button.Style) {
2162 case ToolBarButtonStyle.Separator:
2163 // separator is drawn only in the case of flat appearance
2164 if (flat) {
2165 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y,
2166 buttonArea.X + 1, buttonArea.Height);
2167 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
2168 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
2169 /* draw a horizontal separator */
2170 if (button.Wrapper) {
2171 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
2172 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
2173 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
2174 y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
2177 break;
2179 case ToolBarButtonStyle.ToggleButton:
2180 Rectangle toggleArea = Rectangle.Empty;
2181 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
2182 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2183 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
2184 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
2185 if (button.PartialPush && button.Pushed) {
2186 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
2187 if (! imgRect.IsEmpty) {
2188 if (button.Enabled && image != null)
2189 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2190 imgRect.Height, button.ImageIndex);
2191 else {
2192 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2193 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2194 Border3DSide.Right | Border3DSide.Bottom);
2197 if (button.Enabled)
2198 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2199 else
2200 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
2203 else if (button.PartialPush) {
2204 dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
2205 if (! imgRect.IsEmpty) {
2206 if (button.Enabled && image != null)
2207 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2208 imgRect.Height, button.ImageIndex);
2209 else {
2210 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2211 ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2212 Border3DSide.Right | Border3DSide.Bottom);
2215 if (button.Enabled)
2216 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2217 else
2218 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2219 txtRect, format);
2222 else if (button.Pushed) {
2223 dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
2224 if (! imgRect.IsEmpty) {
2225 if (button.Enabled && image != null)
2226 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2227 imgRect.Height, button.ImageIndex);
2228 else {
2229 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2230 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2231 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2234 if (button.Enabled)
2235 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2236 else
2237 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2238 txtRect, format);
2241 else {
2242 dc.FillRectangle (SystemBrushes.Control, toggleArea);
2243 if (! imgRect.IsEmpty) {
2244 if (button.Enabled && image != null)
2245 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2246 imgRect.Height, button.ImageIndex);
2247 else {
2248 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2249 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2250 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2253 if (button.Enabled)
2254 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2255 else
2256 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2257 txtRect, format);
2259 break;
2261 case ToolBarButtonStyle.DropDownButton:
2262 // draw the dropdown arrow
2263 if (! ddRect.IsEmpty) {
2264 PointF [] vertices = new PointF [3];
2265 PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
2266 vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
2267 vertices [0].Y = ddCenter.Y;
2268 vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
2269 vertices [1].Y = ddCenter.Y;
2270 vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
2271 vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
2272 dc.FillPolygon (SystemBrushes.ControlText, vertices);
2274 goto case ToolBarButtonStyle.PushButton;
2276 case ToolBarButtonStyle.PushButton:
2277 if (! imgRect.IsEmpty){
2278 if (button.Enabled && image != null)
2279 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
2280 button.ImageIndex);
2281 else {
2282 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2283 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2284 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2287 if (button.Enabled)
2288 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2289 else
2290 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2291 txtRect, format);
2292 break;
2296 // Grip width for the ToolBar
2297 public override int ToolBarGripWidth {
2298 get { return 2;}
2301 // Grip width for the Image on the ToolBarButton
2302 public override int ToolBarImageGripWidth {
2303 get { return 2;}
2306 // width of the separator
2307 public override int ToolBarSeparatorWidth {
2308 get { return 4; }
2311 // width of the dropdown arrow rect
2312 public override int ToolBarDropDownWidth {
2313 get { return 13; }
2316 // width for the dropdown arrow on the ToolBarButton
2317 public override int ToolBarDropDownArrowWidth {
2318 get { return 5;}
2321 // height for the dropdown arrow on the ToolBarButton
2322 public override int ToolBarDropDownArrowHeight {
2323 get { return 3;}
2326 public override Size ToolBarDefaultSize {
2327 get {
2328 return new Size (100, 42);
2331 #endregion // ToolBar
2333 #region ToolTip
2334 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt) {
2335 Control control;
2337 control = tt.tooltip_window;
2338 dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
2339 dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
2340 dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, tt.tooltip_window.string_format);
2343 public override Size ToolTipSize(ToolTip tt, string text) {
2344 SizeF sizef;
2346 sizef = tt.tooltip_window.DeviceContext.MeasureString(text, tt.tooltip_window.Font);
2347 return new Size((int)sizef.Width+2, (int)sizef.Height+3); // Need space for the border
2349 #endregion // ToolTip
2351 #region TrackBar
2352 private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
2353 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
2354 float ticks, int value_pos, bool mouse_value) {
2356 Point toptick_startpoint = new Point ();
2357 Point bottomtick_startpoint = new Point ();
2358 Point channel_startpoint = new Point ();
2359 float pixel_len;
2360 float pixels_betweenticks;
2361 const int space_from_right = 8;
2362 const int space_from_left = 8;
2364 switch (tb.TickStyle) {
2365 case TickStyle.BottomRight:
2366 case TickStyle.None:
2367 channel_startpoint.Y = 8;
2368 channel_startpoint.X = 9;
2369 bottomtick_startpoint.Y = 13;
2370 bottomtick_startpoint.X = 24;
2371 break;
2372 case TickStyle.TopLeft:
2373 channel_startpoint.Y = 8;
2374 channel_startpoint.X = 19;
2375 toptick_startpoint.Y = 13;
2376 toptick_startpoint.X = 8;
2377 break;
2378 case TickStyle.Both:
2379 channel_startpoint.Y = 8;
2380 channel_startpoint.X = 18;
2381 bottomtick_startpoint.Y = 13;
2382 bottomtick_startpoint.X = 32;
2383 toptick_startpoint.Y = 13;
2384 toptick_startpoint.X = 8;
2385 break;
2386 default:
2387 break;
2390 thumb_area.X = area.X + channel_startpoint.X;
2391 thumb_area.Y = area.Y + channel_startpoint.Y;
2392 thumb_area.Height = area.Height - space_from_right - space_from_left;
2393 thumb_area.Width = 4;
2395 /* Draw channel */
2396 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
2397 1, thumb_area.Height);
2399 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
2400 1, thumb_area.Height);
2402 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
2403 1, thumb_area.Height);
2405 pixel_len = thumb_area.Height - 11;
2406 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
2408 /* Convert thumb position from mouse position to value*/
2409 if (mouse_value) {
2411 if (value_pos >= channel_startpoint.Y)
2412 value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
2413 else
2414 value_pos = 0;
2416 if (value_pos + tb.Minimum > tb.Maximum)
2417 value_pos = tb.Maximum - tb.Minimum;
2419 tb.Value = value_pos + tb.Minimum;
2422 thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
2424 /* Draw thumb fixed 10x22 size */
2425 thumb_pos.Width = 10;
2426 thumb_pos.Height = 22;
2428 switch (tb.TickStyle) {
2429 case TickStyle.BottomRight:
2430 case TickStyle.None: {
2431 thumb_pos.X = channel_startpoint.X - 8;
2433 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
2434 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
2435 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
2437 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y +9);
2438 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y +9 - 4);
2440 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X +16, thumb_pos.Y +10);
2441 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y + 10, thumb_pos.X +16 + 5, thumb_pos.Y +10 - 5);
2443 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
2444 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
2445 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
2446 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
2448 break;
2450 case TickStyle.TopLeft: {
2451 thumb_pos.X = channel_startpoint.X - 10;
2453 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
2454 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
2456 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
2457 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y + 9, thumb_pos.X, thumb_pos.Y + 5);
2458 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 19, thumb_pos.Y + 9, thumb_pos.X +19 , thumb_pos.Y+ 1);
2460 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y+ 10, thumb_pos.X + 4 + 16, thumb_pos.Y+ 10);
2461 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 4, thumb_pos.Y + 10, thumb_pos.X -1, thumb_pos.Y+ 5);
2462 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
2464 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
2465 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
2466 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
2467 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
2469 break;
2472 case TickStyle.Both: {
2473 thumb_pos.X = area.X + 10;
2474 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
2475 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
2477 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y + 9);
2478 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y + 8);
2480 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y +10);
2481 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X + 20, thumb_pos.Y+ 9);
2483 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
2485 break;
2488 default:
2489 break;
2492 pixel_len = thumb_area.Height - 11;
2493 pixels_betweenticks = pixel_len / ticks;
2495 /* Draw ticks*/
2496 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
2497 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2499 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2500 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
2501 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y + inc,
2502 area.X + bottomtick_startpoint.X + 3, area.Y + bottomtick_startpoint.Y + inc);
2503 else
2504 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y + inc,
2505 area.X + bottomtick_startpoint.X + 2, area.Y + bottomtick_startpoint.Y + inc);
2509 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
2510 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2512 pixel_len = thumb_area.Height - 11;
2513 pixels_betweenticks = pixel_len / ticks;
2515 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2516 //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
2517 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
2518 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 3 , area.Y + toptick_startpoint.Y + inc,
2519 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
2520 else
2521 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X - 2, area.Y + toptick_startpoint.Y + inc,
2522 area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
2528 Horizontal trackbar
2530 Does not matter the size of the control, Win32 always draws:
2531 - Ticks starting from pixel 13, 8
2532 - Channel starting at pos 8, 19 and ends at Width - 8
2533 - Autosize makes always the control 40 pixels height
2534 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
2537 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
2538 ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
2539 float ticks, int value_pos, bool mouse_value) {
2540 Point toptick_startpoint = new Point ();
2541 Point bottomtick_startpoint = new Point ();
2542 Point channel_startpoint = new Point ();
2543 float pixel_len;
2544 float pixels_betweenticks;
2545 const int space_from_right = 8;
2546 const int space_from_left = 8;
2548 switch (tb.TickStyle) {
2549 case TickStyle.BottomRight:
2550 case TickStyle.None:
2551 channel_startpoint.X = 8;
2552 channel_startpoint.Y = 9;
2553 bottomtick_startpoint.X = 13;
2554 bottomtick_startpoint.Y = 24;
2555 break;
2556 case TickStyle.TopLeft:
2557 channel_startpoint.X = 8;
2558 channel_startpoint.Y = 19;
2559 toptick_startpoint.X = 13;
2560 toptick_startpoint.Y = 8;
2561 break;
2562 case TickStyle.Both:
2563 channel_startpoint.X = 8;
2564 channel_startpoint.Y = 18;
2565 bottomtick_startpoint.X = 13;
2566 bottomtick_startpoint.Y = 32;
2567 toptick_startpoint.X = 13;
2568 toptick_startpoint.Y = 8;
2569 break;
2570 default:
2571 break;
2574 thumb_area.X = area.X + channel_startpoint.X;
2575 thumb_area.Y = area.Y + channel_startpoint.Y;
2576 thumb_area.Width = area.Width - space_from_right - space_from_left;
2577 thumb_area.Height = 4;
2579 /* Draw channel */
2580 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
2581 thumb_area.Width, 1);
2583 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
2584 thumb_area.Width, 1);
2586 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
2587 thumb_area.Width, 1);
2589 pixel_len = thumb_area.Width - 11;
2590 pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
2592 /* Convert thumb position from mouse position to value*/
2593 if (mouse_value) {
2594 if (value_pos >= channel_startpoint.X)
2595 value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
2596 else
2597 value_pos = 0;
2599 if (value_pos + tb.Minimum > tb.Maximum)
2600 value_pos = tb.Maximum - tb.Minimum;
2602 tb.Value = value_pos + tb.Minimum;
2605 thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
2607 /* Draw thumb fixed 10x22 size */
2608 thumb_pos.Width = 10;
2609 thumb_pos.Height = 22;
2611 switch (tb.TickStyle) {
2612 case TickStyle.BottomRight:
2613 case TickStyle.None: {
2614 thumb_pos.Y = channel_startpoint.Y - 8;
2616 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
2617 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
2618 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
2620 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
2621 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
2623 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
2624 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
2626 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
2627 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
2628 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
2629 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
2630 break;
2632 case TickStyle.TopLeft: {
2633 thumb_pos.Y = channel_startpoint.Y - 10;
2635 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
2636 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
2638 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
2639 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
2640 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
2642 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
2643 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
2644 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
2646 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
2647 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
2648 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
2649 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
2650 break;
2653 case TickStyle.Both: {
2654 thumb_pos.Y = area.Y + 10;
2655 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
2656 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
2658 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
2659 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
2661 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
2662 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
2664 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
2666 break;
2669 default:
2670 break;
2673 pixel_len = thumb_area.Width - 11;
2674 pixels_betweenticks = pixel_len / ticks;
2676 /* Draw ticks*/
2677 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
2678 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2680 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2681 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
2682 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y,
2683 area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
2684 else
2685 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y,
2686 area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
2690 if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
2691 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2693 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2694 if (inc == 0 || (inc + pixels_betweenticks) >= pixel_len +1)
2695 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3,
2696 area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
2697 else
2698 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2,
2699 area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2704 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb) {
2705 //public override void DrawTrackBar (Graphics dc,
2706 //Rectangle area,
2707 //TrackBar tb,
2708 //ref Rectangle thumb_pos,
2709 //ref Rectangle thumb_area,
2710 Brush br_thumb;
2711 int value_pos;
2712 bool mouse_value;
2713 float ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
2714 Rectangle area;
2715 Rectangle thumb_pos = tb.ThumbPos;
2716 Rectangle thumb_area = tb.ThumbArea;
2718 if (tb.thumb_pressed) {
2719 value_pos = tb.thumb_mouseclick;
2720 mouse_value = true;
2721 } else {
2722 value_pos = tb.Value - tb.Minimum;
2723 mouse_value = false;
2726 area = tb.paint_area;
2728 if (tb.thumb_pressed == true) {
2729 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
2730 } else {
2731 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
2735 /* Control Background */
2736 if (tb.BackColor == DefaultControlBackColor) {
2737 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
2738 } else {
2739 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
2743 if (tb.Focused) {
2744 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
2745 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
2746 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
2747 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
2750 if (tb.Orientation == Orientation.Vertical) {
2751 DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
2752 br_thumb, ticks, value_pos, mouse_value);
2754 } else {
2755 DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
2756 br_thumb, ticks, value_pos, mouse_value);
2759 tb.ThumbPos = thumb_pos;
2760 tb.ThumbArea = thumb_area;
2763 public override Size TrackBarDefaultSize {
2764 get {
2765 return new Size (104, 42);
2769 #endregion // TrackBar
2771 #region VScrollBar
2772 public override Size VScrollBarDefaultSize {
2773 get {
2774 return new Size (this.ScrollBarButtonSize, 80);
2777 #endregion // VScrollBar
2779 #region ControlPaint
2780 private enum DrawFrameControlStates {
2781 ButtonCheck = 0x0000,
2782 ButtonRadioImage = 0x0001,
2783 ButtonRadioMask = 0x0002,
2784 ButtonRadio = 0x0004,
2785 Button3State = 0x0008,
2786 ButtonPush = 0x0010,
2788 CaptionClose = 0x0000,
2789 CaptionMin = 0x0001,
2790 CaptionMax = 0x0002,
2791 CaptionRestore = 0x0004,
2792 CaptionHelp = 0x0008,
2794 MenuArrow = 0x0000,
2795 MenuCheck = 0x0001,
2796 MenuBullet = 0x0002,
2797 MenuArrowRight = 0x0004,
2799 ScrollUp = 0x0000,
2800 ScrollDown = 0x0001,
2801 ScrollLeft = 0x0002,
2802 ScrollRight = 0x0003,
2803 ScrollComboBox = 0x0005,
2804 ScrollSizeGrip = 0x0008,
2805 ScrollSizeGripRight = 0x0010,
2807 Inactive = 0x0100,
2808 Pushed = 0x0200,
2809 Checked = 0x0400,
2810 Transparent = 0x0800,
2811 Hot = 0x1000,
2812 AdjustRect = 0x2000,
2813 Flat = 0x4000,
2814 Mono = 0x8000
2818 private enum DrawFrameControlTypes {
2819 Caption = 1,
2820 Menu = 2,
2821 Scroll = 3,
2822 Button = 4
2825 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
2826 ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
2827 Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
2828 int bottomWidth, ButtonBorderStyle bottomStyle) {
2829 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
2830 DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
2831 DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
2832 DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
2835 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
2836 CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
2839 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
2840 Pen penTopLeft;
2841 Pen penTopLeftInner;
2842 Pen penBottomRight;
2843 Pen penBottomRightInner;
2844 Rectangle rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
2845 bool doInner = false;
2847 if ((style & Border3DStyle.Adjust)!=0) {
2848 rect.Y-=2;
2849 rect.X-=2;
2850 rect.Width+=4;
2851 rect.Height+=4;
2854 /* default to flat */
2855 penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
2856 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2857 penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
2858 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2860 if ((style & Border3DStyle.RaisedOuter)!=0) {
2861 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2862 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2863 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2864 doInner=true;
2866 } else if ((style & Border3DStyle.SunkenOuter)!=0) {
2867 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2868 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2869 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2870 doInner=true;
2874 if ((style & Border3DStyle.RaisedInner)!=0) {
2875 if (doInner) {
2876 penTopLeftInner=ResPool.GetPen(control_color);
2877 penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2878 } else {
2879 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2880 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2882 } else if ((style & Border3DStyle.SunkenInner)!=0) {
2883 if (doInner) {
2884 penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2885 penBottomRightInner=ResPool.GetPen(control_color);
2886 } else {
2887 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2888 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2892 if ((sides & Border3DSide.Middle)!=0) {
2893 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
2896 if ((sides & Border3DSide.Left)!=0) {
2897 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
2898 if (doInner) {
2899 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
2903 if ((sides & Border3DSide.Top)!=0) {
2904 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
2906 if (doInner) {
2907 if ((sides & Border3DSide.Left)!=0) {
2908 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
2909 } else {
2910 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
2915 if ((sides & Border3DSide.Right)!=0) {
2916 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
2918 if (doInner) {
2919 if ((sides & Border3DSide.Top)!=0) {
2920 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
2921 } else {
2922 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
2927 if ((sides & Border3DSide.Bottom)!=0) {
2928 int left=rect.Left;
2930 if ((sides & Border3DSide.Left)!=0) {
2931 left+=1;
2934 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
2936 if (doInner) {
2937 if ((sides & Border3DSide.Right)!=0) {
2938 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
2939 } else {
2940 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
2948 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
2949 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonPush;
2951 if ((state & ButtonState.Pushed)!=0) {
2952 dfcs |= DrawFrameControlStates.Pushed;
2955 if ((state & ButtonState.Checked)!=0) {
2956 dfcs |= DrawFrameControlStates.Checked;
2959 if ((state & ButtonState.Flat)!=0) {
2960 dfcs |= DrawFrameControlStates.Flat;
2963 if ((state & ButtonState.Inactive)!=0) {
2964 dfcs |= DrawFrameControlStates.Inactive;
2966 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
2970 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
2971 Rectangle captionRect;
2972 int lineWidth;
2974 CPDrawButton(graphics, rectangle, state);
2976 if (rectangle.Width<rectangle.Height) {
2977 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
2978 } else {
2979 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
2982 if ((state & ButtonState.Pushed)!=0) {
2983 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
2986 /* Make sure we've got at least a line width of 1 */
2987 lineWidth=Math.Max(1, captionRect.Width/7);
2989 switch(button) {
2990 case CaptionButton.Close: {
2991 Pen pen;
2993 if ((state & ButtonState.Inactive)!=0) {
2994 pen=new Pen(ColorButtonHilight, lineWidth);
2995 DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
2996 pen.Dispose();
2998 pen=new Pen(ColorButtonShadow, lineWidth);
2999 DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
3000 pen.Dispose();
3001 return;
3002 } else {
3003 pen=new Pen(ColorButtonText, lineWidth);
3004 DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
3005 pen.Dispose();
3006 return;
3010 case CaptionButton.Help:
3011 case CaptionButton.Maximize:
3012 case CaptionButton.Minimize:
3013 case CaptionButton.Restore: {
3014 if ((state & ButtonState.Inactive)!=0) {
3015 DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
3017 DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
3018 return;
3019 } else {
3020 DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
3021 return;
3028 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
3029 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonCheck;
3031 if ((state & ButtonState.Pushed)!=0) {
3032 dfcs |= DrawFrameControlStates.Pushed;
3035 if ((state & ButtonState.Checked)!=0) {
3036 dfcs |= DrawFrameControlStates.Checked;
3039 if ((state & ButtonState.Flat)!=0) {
3040 dfcs |= DrawFrameControlStates.Flat;
3043 if ((state & ButtonState.Inactive)!=0) {
3044 dfcs |= DrawFrameControlStates.Inactive;
3047 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
3051 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
3052 Point[] arrow = new Point[3];
3053 Point P1;
3054 Point P2;
3055 Point P3;
3056 int centerX;
3057 int centerY;
3058 int shiftX;
3059 int shiftY;
3060 Rectangle rect;
3062 if ((state & ButtonState.Checked)!=0) {
3063 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);
3066 if ((state & ButtonState.Flat)!=0) {
3067 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3068 } else {
3069 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
3070 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3071 } else {
3072 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3076 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
3077 centerX=rect.Left+rect.Width/2;
3078 centerY=rect.Top+rect.Height/2;
3079 shiftX=Math.Max(1, rect.Width/8);
3080 shiftY=Math.Max(1, rect.Height/8);
3082 if ((state & ButtonState.Pushed)!=0) {
3083 shiftX++;
3084 shiftY++;
3087 rect.Y-=shiftY;
3088 centerY-=shiftY;
3089 P1=new Point(rect.Left, centerY);
3090 P2=new Point(rect.Right, centerY);
3091 P3=new Point(centerX, rect.Bottom);
3093 arrow[0]=P1;
3094 arrow[1]=P2;
3095 arrow[2]=P3;
3097 /* Draw the arrow */
3098 if ((state & ButtonState.Inactive)!=0) {
3099 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
3101 /* Move away from the shadow */
3102 P1.X-=1; P1.Y-=1;
3103 P2.X-=1; P2.Y-=1;
3104 P3.X-=1; P3.Y-=1;
3106 arrow[0]=P1;
3107 arrow[1]=P2;
3108 arrow[2]=P3;
3111 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
3112 } else {
3113 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
3118 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
3120 Pen pen = new Pen(Color.Black, 1);
3121 Rectangle rect = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1); // Dunno why, but MS does it that way, too
3122 int X;
3123 int Y;
3125 graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
3126 graphics.DrawRectangle(pen, rect);
3128 X=rect.X+rect.Width/2;
3129 Y=rect.Y+rect.Height/2;
3131 /* Draw the cross */
3132 graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
3133 graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
3135 /* Draw 'arrows' for vertical lines */
3136 graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
3137 graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
3139 /* Draw 'arrows' for horizontal lines */
3140 graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
3141 graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
3145 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
3146 // make a rectange to trace around border of the button
3147 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3149 Color outerColor = foreColor;
3150 // adjust focus color according to the flatstyle
3151 if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
3152 outerColor = (backColor == ColorButtonFace) ? ControlPaint.Dark(ColorButtonFace) : ColorButtonText;
3155 // draw the outer rectangle
3156 graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);
3158 // draw the inner rectangle
3159 if (button.FlatStyle == FlatStyle.Popup) {
3160 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -5, -5), backColor);
3161 } else {
3162 // draw a flat inner rectangle
3163 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
3164 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -5, -5));
3168 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
3170 // make a rectange to trace around border of the button
3171 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3173 Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
3174 DashStyle oldStyle; // used for caching old penstyle
3175 Pen pen = ResPool.GetPen (colorBackInverted);
3177 oldStyle = pen.DashStyle;
3178 pen.DashStyle = DashStyle.Dot;
3179 graphics.DrawRectangle (pen, trace_rectangle);
3180 pen.DashStyle = oldStyle;
3184 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
3185 // make a rectange to trace around border of the button
3186 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3188 //Color colorForeInverted;
3189 Pen pen;
3191 //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
3192 //pen=new Pen(colorForeInverted, 1);
3193 // MS seems to always use black
3194 pen = ResPool.GetPen (Color.Black);
3195 graphics.DrawRectangle(pen, trace_rectangle);
3197 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
3200 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
3201 SolidBrush sb;
3202 Pen pen;
3204 if (primary==true) {
3205 pen=new Pen(Color.Black, 1);
3206 if (enabled==true) {
3207 sb=ResPool.GetSolidBrush (ColorButtonText);
3208 } else {
3209 sb=ResPool.GetSolidBrush (ColorButtonFace);
3211 } else {
3212 pen=new Pen(Color.White, 1);
3213 if (enabled==true) {
3214 sb=new SolidBrush(Color.Black);
3215 } else {
3216 sb=ResPool.GetSolidBrush (ColorButtonFace);
3219 graphics.FillRectangle(sb, rectangle);
3220 graphics.DrawRectangle(pen, rectangle);
3221 pen.Dispose();
3225 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
3226 Color foreColor;
3227 int h;
3228 int b;
3229 int s;
3231 ControlPaint.Color2HBS(backColor, out h, out b, out s);
3233 if (b>127) {
3234 foreColor=Color.Black;
3235 } else {
3236 foreColor=Color.White;
3239 #if false
3240 /* Commented out until I take the time and figure out
3241 which HatchStyle will match requirements. The code below
3242 is only correct for Percent50.
3244 if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
3245 HatchBrush brush=null;
3247 switch(pixelsBetweenDots.Width) {
3248 case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
3249 case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
3250 case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
3251 default: {
3252 /* Have to do it the slow way */
3253 break;
3256 if (brush!=null) {
3257 graphics.FillRectangle(brush, area);
3258 pen.Dispose();
3259 brush.Dispose();
3260 return;
3263 #endif
3264 /* Slow method */
3266 Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
3268 for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
3269 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
3270 bitmap.SetPixel(x, y, foreColor);
3273 graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
3274 bitmap.Dispose();
3277 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
3279 Microsoft seems to ignore the background and simply make
3280 the image grayscale. At least when having > 256 colors on
3281 the display.
3284 ImageAttributes imageAttributes=new ImageAttributes();
3285 ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
3286 // This table would create a perfect grayscale image, based on luminance
3287 // new float[]{0.3f,0.3f,0.3f,0,0},
3288 // new float[]{0.59f,0.59f,0.59f,0,0},
3289 // new float[]{0.11f,0.11f,0.11f,0,0},
3290 // new float[]{0,0,0,1,0,0},
3291 // new float[]{0,0,0,0,1,0},
3292 // new float[]{0,0,0,0,0,1}
3294 // This table generates a image that is grayscaled and then
3295 // brightened up. Seems to match MS close enough.
3296 new float[]{0.2f,0.2f,0.2f,0,0},
3297 new float[]{0.41f,0.41f,0.41f,0,0},
3298 new float[]{0.11f,0.11f,0.11f,0,0},
3299 new float[]{0.15f,0.15f,0.15f,1,0,0},
3300 new float[]{0.15f,0.15f,0.15f,0,1,0},
3301 new float[]{0.15f,0.15f,0.15f,0,0,1}
3304 imageAttributes.SetColorMatrix(colorMatrix);
3305 graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
3306 imageAttributes.Dispose();
3310 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
3311 Pen penBorder;
3312 Pen penInside;
3314 if (primary) {
3315 penBorder=new Pen(Color.White, 2);
3316 penInside=new Pen(Color.Black, 1);
3317 } else {
3318 penBorder=new Pen(Color.Black, 2);
3319 penInside=new Pen(Color.White, 1);
3321 penBorder.Alignment=PenAlignment.Inset;
3322 penInside.Alignment=PenAlignment.Inset;
3324 graphics.DrawRectangle(penBorder, rectangle);
3325 graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
3326 penBorder.Dispose();
3327 penInside.Dispose();
3331 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
3332 Rectangle rect;
3333 int lineWidth;
3335 // MS draws always the background white
3336 graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
3338 switch(glyph) {
3339 case MenuGlyph.Arrow: {
3340 Point[] arrow = new Point[3];
3341 Point P1;
3342 Point P2;
3343 Point P3;
3344 int centerX;
3345 int centerY;
3346 int shiftX;
3347 int shiftY;
3349 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
3350 centerX=rect.Left+rect.Width/2;
3351 centerY=rect.Top+rect.Height/2;
3352 shiftX=Math.Max(1, rect.Width/8);
3353 shiftY=Math.Max(1, rect.Height/8);
3355 rect.X-=shiftX;
3356 centerX-=shiftX;
3358 P1=new Point(centerX, rect.Top-1);
3359 P2=new Point(centerX, rect.Bottom);
3360 P3=new Point(rect.Right, centerY);
3362 arrow[0]=P1;
3363 arrow[1]=P2;
3364 arrow[2]=P3;
3366 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
3368 return;
3371 case MenuGlyph.Bullet: {
3373 lineWidth=Math.Max(2, rectangle.Width/3);
3374 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
3376 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
3378 return;
3381 case MenuGlyph.Checkmark: {
3382 int Scale;
3384 lineWidth=Math.Max(2, rectangle.Width/6);
3385 Scale=Math.Max(1, rectangle.Width/12);
3387 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
3389 for (int i=0; i<lineWidth; i++) {
3390 graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
3391 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);
3393 return;
3399 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
3400 DrawFrameControlStates dfcs=DrawFrameControlStates.ButtonRadio;
3402 if ((state & ButtonState.Pushed)!=0) {
3403 dfcs |= DrawFrameControlStates.Pushed;
3406 if ((state & ButtonState.Checked)!=0) {
3407 dfcs |= DrawFrameControlStates.Checked;
3410 if ((state & ButtonState.Flat)!=0) {
3411 dfcs |= DrawFrameControlStates.Flat;
3414 if ((state & ButtonState.Inactive)!=0) {
3415 dfcs |= DrawFrameControlStates.Inactive;
3417 DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
3422 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
3427 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
3432 /* Scroll button: regular button + direction arrow */
3433 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
3434 bool enabled = (state == ButtonState.Inactive) ? false: true;
3436 DrawScrollButtonPrimitive (dc, area, state);
3438 /* Paint arrows */
3439 switch (type) {
3440 case ScrollButton.Up: {
3441 int x = area.X + (area.Width / 2) - 4;
3442 int y = area.Y + 9;
3444 for (int i = 0; i < 3; i++)
3445 if (enabled)
3446 dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
3447 else
3448 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
3451 dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);
3452 break;
3454 case ScrollButton.Down: {
3455 int x = area.X + (area.Width / 2) - 4;
3456 int y = area.Y + 5;
3458 for (int i = 4; i != 0; i--)
3459 if (enabled)
3460 dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
3461 else
3462 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
3465 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
3466 break;
3469 case ScrollButton.Left: {
3470 int y = area.Y + (area.Height / 2) - 4;
3471 int x = area.X + 9;
3473 for (int i = 0; i < 3; i++)
3474 if (enabled)
3475 dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
3476 else
3477 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
3479 dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
3480 break;
3483 case ScrollButton.Right: {
3484 int y = area.Y + (area.Height / 2) - 4;
3485 int x = area.X + 5;
3487 for (int i = 4; i != 0; i--)
3488 if (enabled)
3489 dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
3490 else
3491 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
3493 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
3494 break;
3497 default:
3498 break;
3504 public override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
3505 Color backColor) {
3510 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
3511 Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
3513 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
3514 dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
3516 // diagonals
3517 for (int i = 0; i < 11; i += 4) {
3518 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
3519 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
3522 for (int i = 3; i < 13; i += 4)
3523 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
3527 public override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
3528 StringFormat format) {
3529 SolidBrush brush;
3531 brush=new SolidBrush(ControlPaint.Light(color, 95));
3533 layoutRectangle.Offset(1.0f, 1.0f);
3534 graphics.DrawString(s, font, brush, layoutRectangle, format);
3536 brush.Color=ControlPaint.Light(color, 50);
3537 layoutRectangle.Offset(-1.0f, -1.0f);
3538 graphics.DrawString(s, font, brush, layoutRectangle, format);
3540 brush.Dispose();
3543 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
3544 int width, Color color, ButtonBorderStyle style, Border3DSide side) {
3546 Pen pen=new Pen(color, 1);
3548 switch(style) {
3549 case ButtonBorderStyle.Solid: {
3550 pen.DashStyle=DashStyle.Solid;
3551 break;
3554 case ButtonBorderStyle.Dashed: {
3555 pen.DashStyle=DashStyle.Dash;
3556 break;
3559 case ButtonBorderStyle.Dotted: {
3560 pen.DashStyle=DashStyle.Dot;
3561 break;
3564 case ButtonBorderStyle.Inset: {
3565 pen.DashStyle=DashStyle.Solid;
3566 break;
3569 case ButtonBorderStyle.Outset: {
3570 pen.DashStyle=DashStyle.Solid;
3571 break;
3574 default:
3575 case ButtonBorderStyle.None: {
3576 pen.Dispose();
3577 return;
3582 switch(style) {
3583 case ButtonBorderStyle.Outset: {
3584 Color colorGrade;
3585 int hue, brightness, saturation;
3586 int brightnessSteps;
3587 int brightnessDownSteps;
3589 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
3591 brightnessDownSteps=brightness/width;
3592 if (brightness>127) {
3593 brightnessSteps=Math.Max(6, (160-brightness)/width);
3594 } else {
3595 brightnessSteps=(127-brightness)/width;
3598 for (int i=0; i<width; i++) {
3599 switch(side) {
3600 case Border3DSide.Left: {
3601 pen.Dispose();
3602 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3603 pen=new Pen(colorGrade, 1);
3604 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3605 break;
3608 case Border3DSide.Right: {
3609 pen.Dispose();
3610 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3611 pen=new Pen(colorGrade, 1);
3612 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3613 break;
3616 case Border3DSide.Top: {
3617 pen.Dispose();
3618 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3619 pen=new Pen(colorGrade, 1);
3620 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3621 break;
3624 case Border3DSide.Bottom: {
3625 pen.Dispose();
3626 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3627 pen=new Pen(colorGrade, 1);
3628 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3629 break;
3633 break;
3636 case ButtonBorderStyle.Inset: {
3637 Color colorGrade;
3638 int hue, brightness, saturation;
3639 int brightnessSteps;
3640 int brightnessDownSteps;
3642 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
3644 brightnessDownSteps=brightness/width;
3645 if (brightness>127) {
3646 brightnessSteps=Math.Max(6, (160-brightness)/width);
3647 } else {
3648 brightnessSteps=(127-brightness)/width;
3651 for (int i=0; i<width; i++) {
3652 switch(side) {
3653 case Border3DSide.Left: {
3654 pen.Dispose();
3655 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3656 pen=new Pen(colorGrade, 1);
3657 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3658 break;
3661 case Border3DSide.Right: {
3662 pen.Dispose();
3663 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3664 pen=new Pen(colorGrade, 1);
3665 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3666 break;
3669 case Border3DSide.Top: {
3670 pen.Dispose();
3671 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3672 pen=new Pen(colorGrade, 1);
3673 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3674 break;
3677 case Border3DSide.Bottom: {
3678 pen.Dispose();
3679 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3680 pen=new Pen(colorGrade, 1);
3681 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3682 break;
3686 break;
3690 I decided to have the for-loop duplicated for speed reasons;
3691 that way we only have to switch once (as opposed to have the
3692 for-loop around the switch)
3694 default: {
3695 switch(side) {
3696 case Border3DSide.Left: {
3697 for (int i=0; i<width; i++) {
3698 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3700 break;
3703 case Border3DSide.Right: {
3704 for (int i=0; i<width; i++) {
3705 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3707 break;
3710 case Border3DSide.Top: {
3711 for (int i=0; i<width; i++) {
3712 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3714 break;
3717 case Border3DSide.Bottom: {
3718 for (int i=0; i<width; i++) {
3719 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3721 break;
3724 break;
3727 pen.Dispose();
3731 This function actually draws the various caption elements.
3732 This way we can scale them nicely, no matter what size, and they
3733 still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
3736 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
3737 switch(button) {
3738 case CaptionButton.Close: {
3739 pen.StartCap=LineCap.Triangle;
3740 pen.EndCap=LineCap.Triangle;
3741 if (lineWidth<2) {
3742 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);
3743 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);
3746 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3747 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3748 return;
3751 case CaptionButton.Help: {
3752 StringFormat sf = new StringFormat();
3753 SolidBrush sb = new SolidBrush(color);
3754 Font font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
3756 sf.Alignment=StringAlignment.Center;
3757 sf.LineAlignment=StringAlignment.Center;
3760 graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
3762 sf.Dispose();
3763 sb.Dispose();
3764 font.Dispose();
3766 return;
3769 case CaptionButton.Maximize: {
3770 /* Top 'caption bar' line */
3771 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3772 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);
3775 /* Left side line */
3776 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3777 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3780 /* Right side line */
3781 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3782 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);
3785 /* Bottom line */
3786 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3787 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3789 return;
3792 case CaptionButton.Minimize: {
3793 /* Bottom line */
3794 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3795 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
3797 return;
3800 case CaptionButton.Restore: {
3801 /** First 'window' **/
3802 /* Top 'caption bar' line */
3803 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3804 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);
3807 /* Left side line */
3808 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3809 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);
3812 /* Right side line */
3813 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3814 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);
3817 /* Bottom line */
3818 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3819 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);
3822 /** Second 'window' **/
3823 /* Top 'caption bar' line */
3824 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3825 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);
3828 /* Left side line */
3829 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3830 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3833 /* Right side line */
3834 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3835 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);
3838 /* Bottom line */
3839 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3840 graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3843 return;
3849 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
3850 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
3851 // make a rectange to trace around border of the button
3852 Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3853 switch(Type) {
3854 case DrawFrameControlTypes.Button: {
3856 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
3857 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
3858 // /* Goes first, affects the background */
3859 // if ((State & DrawFrameControlStates.Checked)!=0) {
3860 // HatchBrush hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
3861 // graphics.FillRectangle(hatchBrush,rectangle);
3862 // hatchBrush.Dispose();
3863 // }
3865 if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
3866 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
3867 } else if ((State & DrawFrameControlStates.Flat)!=0) {
3868 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3869 } else if ((State & DrawFrameControlStates.Inactive)!=0) {
3870 /* Same as normal, it would seem */
3871 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3872 } else {
3873 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3875 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
3876 Pen penFatDark = new Pen(ColorButtonShadow, 1);
3877 Pen penFatLight = new Pen(ColorButtonLight, 1);
3878 int lineWidth;
3880 graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3882 graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
3883 graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
3885 graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
3886 graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
3888 lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
3890 if ((State & DrawFrameControlStates.Checked)!=0) {
3891 SolidBrush buttonBrush;
3893 if ((State & DrawFrameControlStates.Inactive)!=0) {
3894 buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
3895 } else {
3896 buttonBrush=(SolidBrush)SystemBrushes.ControlText;
3898 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
3900 penFatDark.Dispose();
3901 penFatLight.Dispose();
3902 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
3903 throw new NotImplementedException () ;
3904 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
3905 throw new NotImplementedException ();
3906 } else { /* Must be Checkbox */
3907 Pen pen;
3908 int lineWidth;
3909 Rectangle rect;
3910 int Scale;
3912 /* Goes first, affects the background */
3913 if ((State & DrawFrameControlStates.Pushed)!=0 ||
3914 (State & DrawFrameControlStates.Inactive)!=0) {
3915 graphics.FillRectangle(SystemBrushes.Control, rectangle);
3916 } else {
3917 graphics.FillRectangle(SystemBrushes.Window, rectangle);
3920 /* Draw the sunken frame */
3921 if ((State & DrawFrameControlStates.Flat)!=0) {
3922 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3923 } else {
3924 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3927 /* Make sure we've got at least a line width of 1 */
3928 lineWidth=Math.Max(3, rectangle.Width/6);
3929 Scale=Math.Max(1, rectangle.Width/12);
3931 // define a rectangle inside the border area
3932 rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
3933 if ((State & DrawFrameControlStates.Inactive)!=0) {
3934 pen=SystemPens.ControlDark;
3935 } else {
3936 pen=SystemPens.ControlText;
3939 if ((State & DrawFrameControlStates.Checked)!=0) {
3940 /* Need to draw a check-mark */
3941 for (int i=0; i<lineWidth; i++) {
3942 graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
3943 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);
3948 return;
3951 case DrawFrameControlTypes.Caption: {
3952 // FIXME:
3953 break;
3956 case DrawFrameControlTypes.Menu: {
3957 // FIXME:
3958 break;
3961 case DrawFrameControlTypes.Scroll: {
3962 // FIXME:
3963 break;
3968 /* Generic scroll button */
3969 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
3970 if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
3971 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
3972 area.Y + 1, area.Width - 2 , area.Height - 2);
3974 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
3975 area.Y, area.Width, area.Height);
3977 return;
3980 dc.FillRectangle (new SolidBrush (Color.Blue), area);
3982 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
3983 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
3985 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
3986 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
3987 area.Height - 4);
3989 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
3990 area.Width - 2, 1);
3992 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
3993 area.Width , 1);
3995 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
3996 area.Y + 1, 1, area.Height -3);
3998 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
3999 area.Y, 1, area.Height - 1);
4001 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
4002 area.Y + 2, area.Width - 4, area.Height - 4);
4006 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
4007 switch (border_style){
4008 case BorderStyle.Fixed3D:
4009 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
4010 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
4011 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width ,
4012 area.Y + area.Height - 1);
4013 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1,
4014 area.Y + area.Height);
4015 break;
4016 case BorderStyle.FixedSingle:
4017 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
4018 break;
4019 case BorderStyle.None:
4020 default:
4021 break;
4025 #endregion // ControlPaint
4028 } //class