92c695cc8a84f0a627b3a9e09964560b9c12f9e9
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
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.
11 //
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.
19 //
20 // Copyright (c) 2004 Novell, Inc.
21 //
22 // Authors:
23 //      Jordi Mas i Hernandez, jordi@ximian.com
24 //      Peter Bartok, pbartok@novell.com
25 //      John BouAntoun, jba-mono@optusnet.com.au
26 //
27 //
28 //
29 // $Revision: 1.64 $
30 // $Modtime: $
31 // $Log: ThemeWin32Classic.cs,v $
32 // Revision 1.64  2004/11/10 19:22:26  jackson
33 //      * ThemeWin32Classic.cs: Don't bother drawing tabs outside of the
34 //      clip area.
35 //
36 // Revision 1.63  2004/11/10 01:04:28  jackson
37 //      * TabControl.cs (CalcXPos): New helper method so we can determine
38 //      the proper place to start drawing vertical tabs.
39 //      * ThemeWin32Classic.cs (DrawTab): Draw right aligned tabs.
40 //
41 // Revision 1.62  2004/11/09 21:44:54  jackson
42 //      * TabControl.cs: Calculate sizing and rects for left aligned tabs.
43 //      * ThemeWin32Classic.cs (GetTabControl*ScrollRect): Only handle Top
44 //      and Bottom, left and right are illegal values for this and
45 //      multiline is enabled when the alignment is set to left or right.
46 //      (DrawTab): Each alignment block should draw the text itself now
47 //      because Left requires special love. Also add rendering for Left
48 //      aligned tabs.
49 //
50 // Revision 1.61  2004/11/09 11:06:21  jba
51 // - (DrawButtonBase): Fix verticle text rect clipping in windows
52 // - (DrawCheckBox): Fix CheckAlign.TopCenter and CheckAlign.BottomCenter
53 //   rendering and incorrect text rect clipping
54 // - (DrawRadioButton): Fix CheckAlign.TopCenter and CheckAlign.BottomCenter
55 //   rendering and incorrect text rect clipping
56 //
57 // Revision 1.60  2004/11/09 03:12:00  jackson
58 //      * ThemeWin32Classic.cs (DrawTabControl): Render tabs from top to
59 //      bottom when they are bottom aligned so the bottoms of the tabs get
60 //      displayed.
61 //      * TabControl.cs (DropRow): Move rows up instead of down when the
62 //      tab control is bottom aligned.
63 //
64 // Revision 1.59  2004/11/08 20:40:08  jackson
65 // Render the little scrolling jimmi in the correct location with bottom aligned tabs
66 //
67 // Revision 1.58  2004/11/08 14:15:00  jordi
68 // fixes vertical scrollbar and removes dead code
69 //
70 // Revision 1.57  2004/11/05 05:47:34  jba
71 // - Fix Button rendering for FlatStyle = Flat or Popup
72 // - Fix RadioButton and CheckBox rendering when Appearance = Button (normal and
73 //   flatstyle).
74 // - Correct outer rectangle color when drawing focus rectangle
75 // - Adjust button bounds to be 1 px smaller when focused
76 // - Make button not draw sunken 3d border when pushed (windows compat)
77 // - Fix CPDrawBorder3D to not make bottom right hand corner rounded
78 // - Offset the text in RadioButton and Checkbox when being rendered as a button.
79 // - Hover and Click behaviour for Colored FlatStyle.Flat and Popup radiobuttons
80 // - Fixed disabled rendering for colored flatstyle radiobuttons (both)
81 // - Fixed disabled text rendering for normally rendered radiobuttons
82 //
83 // Revision 1.56  2004/11/04 11:26:09  ravindra
84 //      - Changed default ListView values signatures (prefixed all with ListView).
85 //      - Fixed default size values for VScrollBar and HScrollBar.
86 //      - Fixed DrawListViewItem method.
87 //
88 // Revision 1.55  2004/11/03 18:52:14  jackson
89 // Initial implementation of the scrolly widgerywoo
90 //
91 // Revision 1.54  2004/11/02 20:40:54  jackson
92 // Move the row with the selected tab to the bottom
93 //
94 // Revision 1.53  2004/11/02 02:47:55  jackson
95 // New rendering and sizing code for tab controls
96 //
97 // Revision 1.52  2004/10/30 10:23:02  ravindra
98 // Drawing ListView and some default values.
99 //
100 // Revision 1.51  2004/10/26 09:55:48  ravindra
101 // Some formatting for my last checkins.
102 //
103 // Revision 1.50  2004/10/26 09:36:32  ravindra
104 // Implemented DetailView drawing for ListView control and default values.
105 //
106 // Revision 1.49  2004/10/18 04:49:25  pbartok
107 // - Added ToolTip drawing code
108 //
109 // Revision 1.48  2004/10/15 15:08:49  ravindra
110 // Added ColumnHeaderHeight property in Theme for ListView.
111 //
112 // Revision 1.47  2004/10/13 15:06:37  pbartok
113 // - Path from John BouAntoun:
114 //   * Fix check rendering (centre correctly for normal style, offset
115 //     correctly for FlatStyle).
116 //   * Fix border color usage (use backcolor) for FlatStyle.Popup
117 //   * Use checkbox.Capture instead of checkbox.is_pressed when rendering
118 //     flatstyle states.
119 //
120 // Revision 1.46  2004/10/13 03:48:15  pbartok
121 // - Removed all occurences of SystemColors and replaced them with the
122 //   matching theme color
123 //
124 // Revision 1.45  2004/10/13 03:41:45  pbartok
125 // - From John BouAntoun: Added an overload to CPDrawBorder3D to allow him
126 //   using the function for flatstyle drawing
127 // - Changed functions to use the new version of CPDrawBorder3D
128 //
129 // Revision 1.44  2004/10/13 02:45:21  pbartok
130 // - Fixes from John BouAntoun: now handles forecolors and backcolors for
131 //   flatstyle rendered controls much better; It also fixes normal checkbox
132 //   rendering when pushed or disabled.
133 //
134 // Revision 1.43  2004/10/07 14:56:51  jordi
135 // Removes deletion of cached brushes
136 //
137 // Revision 1.42  2004/10/06 09:59:05  jordi
138 // removes warnings from compilation
139 //
140 // Revision 1.41  2004/10/05 16:15:30  jackson
141 // Improve rendering of the radio button patch by John BouAntoun
142 //
143 // Revision 1.40  2004/10/05 09:04:31  ravindra
144 //      - Added DrawListView method and ListViewDefaultSize property.
145 //      - Changed ControlPaint method calls to CPDrawXXX wherever possible.
146 //      - Changed DOS style CRLF to Unix format (dos2unix).
147 //
148 // Revision 1.39  2004/10/04 07:09:37  jordi
149 // fixes right button position causing right button not showing on horizontal scrollbars
150 //
151 // Revision 1.38  2004/09/28 18:44:25  pbartok
152 // - Streamlined Theme interfaces:
153 //   * Each DrawXXX method for a control now is passed the object for the
154 //     control to be drawn in order to allow accessing any state the theme
155 //     might require
156 //
157 //   * ControlPaint methods for the theme now have a CP prefix to avoid
158 //     name clashes with the Draw methods for controls
159 //
160 //   * Every control now retrieves it's DefaultSize from the current theme
161 //
162 // Revision 1.37  2004/09/09 08:28:11  pbartok
163 // - Improve disabled string look
164 //
165 // Revision 1.36  2004/09/09 03:03:49  ravindra
166 // PictureBox would not draw a null image to avoid crash.
167 //
168 // Revision 1.35  2004/09/07 17:12:26  jordi
169 // GroupBox control
170 //
171 // Revision 1.34  2004/09/07 09:40:15  jordi
172 // LinkLabel fixes, methods, multiple links
173 //
174 // Revision 1.33  2004/09/05 08:03:51  jordi
175 // fixes bugs, adds flashing on certain situations
176 //
177 // Revision 1.32  2004/09/02 16:32:54  jordi
178 // implements resource pool for pens, brushes, and hatchbruses
179 //
180 // Revision 1.31  2004/08/25 20:04:40  ravindra
181 // Added the missing divider code and grip for ToolBar Control.
182 //
183 // Revision 1.30  2004/08/25 18:29:14  jordi
184 // new methods, properties, and fixes for progressbar
185 //
186 // Revision 1.29  2004/08/25 00:43:13  ravindra
187 // Fixed wrapping related issues in ToolBar control.
188 //
189 // Revision 1.28  2004/08/24 18:37:02  jordi
190 // fixes formmating, methods signature, and adds missing events
191 //
192 // Revision 1.27  2004/08/24 16:16:46  jackson
193 // Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
194 //
195 // Revision 1.26  2004/08/21 01:52:08  ravindra
196 // Improvments in mouse event handling in the ToolBar control.
197 //
198 // Revision 1.25  2004/08/20 00:12:51  jordi
199 // fixes methods signature
200 //
201 // Revision 1.24  2004/08/19 22:25:31  jordi
202 // theme enhancaments
203 //
204 // Revision 1.23  2004/08/18 19:16:53  jordi
205 // Move colors to a table
206 //
207 // Revision 1.22  2004/08/17 19:29:11  jackson
208 // Don't use KnownColor to create colours. It has a large startup time.
209 //
210 // Revision 1.21  2004/08/15 23:20:54  ravindra
211 // Changes to Theme for ToolBar control and also dos2unix format.
212 //
213 // Revision 1.20  2004/08/13 21:22:18  jordi
214 // removes redundant code and fixes issues with tickposition
215 //
216 // Revision 1.19  2004/08/12 20:29:01  jordi
217 // Trackbar enhancement, fix mouse problems, highli thumb, etc
218 //
219 // Revision 1.18  2004/08/12 18:54:37  jackson
220 // Handle owner draw status bars
221 //
222 // Revision 1.17  2004/08/11 01:31:35  jackson
223 // Create Brushes as little as possible
224 //
225 // Revision 1.16  2004/08/10 19:21:27  jordi
226 // scrollbar enhancements and standarize on win colors defaults
227 //
228 // Revision 1.15  2004/08/10 18:52:30  jackson
229 // Implement DrawItem functionality
230 //
231 // Revision 1.14  2004/08/09 21:34:54  jackson
232 // Add support for drawing status bar and get status bar item sizes
233 //
234 // Revision 1.13  2004/08/09 21:21:49  jackson
235 // Use known colors for default control colours
236 //
237 // Revision 1.12  2004/08/09 21:12:15  jackson
238 // Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
239 //
240 // Revision 1.11  2004/08/09 17:31:13  jackson
241 // New names for control properties
242 //
243 // Revision 1.10  2004/08/09 17:00:00  jackson
244 // Add default window color properties
245 //
246 // Revision 1.9  2004/08/09 16:17:19  jackson
247 // Use correct default back color
248 //
249 // Revision 1.8  2004/08/09 15:53:12  jackson
250 // Themes now handle default control properties so coloring will be consistent
251 //
252 // Revision 1.7  2004/08/08 22:54:21  jordi
253 // Label BorderStyles
254 //
255 // Revision 1.6  2004/08/08 18:09:53  jackson
256 // Add pen_buttonface
257 //
258 // Revision 1.5  2004/08/08 17:34:28  jordi
259 // Use Windows Standard Colours
260 //
261 // Revision 1.4  2004/08/07 23:31:15  jordi
262 // fixes label bug and draw method name
263 //
264 // Revision 1.3  2004/08/07 19:05:44  jordi
265 // Theme colour support and GetSysColor defines
266 //
267 // Revision 1.2  2004/08/07 00:01:39  pbartok
268 // - Fixed some rounding issues with float/int
269 //
270 // Revision 1.1  2004/07/26 17:42:03  jordi
271 // Theme support
272 //
273 //
274
275 using System.Drawing;
276 using System.Drawing.Drawing2D;
277 using System.Drawing.Imaging;
278
279 namespace System.Windows.Forms
280 {
281
282         internal class ThemeWin32Classic : Theme
283         {               
284
285                 /* Default colors for Win32 classic theme */
286                 uint [] theme_colors = {                                                        /* AARRGGBB */
287                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_SCROLLBAR,                   0xffc0c0c0,
288                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_BACKGROUND,                  0xff008080,
289                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVECAPTION,               0xff000080,
290                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTION,             0xff808080,
291                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENU,                        0xffc0c0c0,
292                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOW,                      0xffffffff,
293                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWFRAME,                 0xff000000,
294                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_MENUTEXT,                    0xff000000,
295                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_WINDOWTEXT,                  0xff000000,
296                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_CAPTIONTEXT,                 0xffffffff,
297                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_ACTIVEBORDER,                0xffc0c0c0,
298                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVEBORDER,              0xffc0c0c0,
299                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_APPWORKSPACE,                0xff808080,
300                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHT,                   0xff000080,
301                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_HIGHLIGHTTEXT,               0xffffffff,
302                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNFACE,                     0xffc0c0c0,
303                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNSHADOW,                   0xff808080,
304                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_GRAYTEXT,                    0xff808080,
305                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNTEXT,                     0xff000000,
306                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_INACTIVECAPTIONTEXT,         0xffc0c0c0,
307                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_BTNHIGHLIGHT,                0xffffffff,
308                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DDKSHADOW,                  0xff000000,                     
309                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_3DLIGHT,                     0xffe0e0e0,
310                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOTEXT,                    0xff000000,
311                         (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK,                      0xffffffff,
312                   
313                 };              
314                 
315                 static protected Pen pen_ticks;         
316                 static protected SolidBrush br_arrow;
317                 static protected SolidBrush br_progressbarblock;                
318                 static protected Pen pen_arrow;
319                                 
320
321                 /* Cache */
322                 protected SolidBrush label_br_fore_color;
323                 protected SolidBrush label_br_back_color;
324
325                 #region Principal Theme Methods
326                 public ThemeWin32Classic ()
327                 {
328                         label_br_fore_color = null;
329                         label_br_back_color = null;                                             
330
331                         /* Init Default colour array*/
332                         syscolors =  Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
333                         
334                         for (int i = 0; i < theme_colors.Length; i +=2) 
335                                 syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
336  
337                         pen_ticks = new Pen (Color.Black);                      
338                         br_arrow = new SolidBrush (Color.Black);
339                         pen_arrow = new Pen (Color.Black);
340                         br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128));                 
341
342                         defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10);
343                         defaultWindowForeColor = ColorButtonText;
344                         default_font =  new Font (FontFamily.GenericSansSerif, 8.25f);
345                 }       
346
347                 public override bool DoubleBufferingSupported {
348                         get {return true; }
349                 }
350                 #endregion      // Principal Theme Methods
351
352                 #region Internal Methods
353                 protected SolidBrush GetControlBackBrush (Color c) {
354                         if (c == DefaultControlBackColor)
355                                 return ResPool.GetSolidBrush (ColorButtonFace);
356                         return new SolidBrush (c);
357                 }
358
359                 protected SolidBrush GetControlForeBrush (Color c) {
360                         if (c == DefaultControlForeColor)
361                                 return ResPool.GetSolidBrush (ColorButtonText);
362                         return new SolidBrush (c);
363                 }
364                 #endregion      // Internal Methods
365
366                 #region OwnerDraw Support
367                 public  override void DrawOwnerDrawBackground (DrawItemEventArgs e)
368                 {
369                         if (e.State == DrawItemState.Selected) {
370                                 e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
371                                 return;
372                         }
373
374                         e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
375                 }
376
377                 public  override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
378                 {
379                         if (e.State == DrawItemState.Focus)
380                                 CPDrawFocusRectangle (e.Graphics, e.Bounds, e.ForeColor, e.BackColor);
381                 }
382                 #endregion      // OwnerDraw Support
383
384                 #region ButtonBase
385                 public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
386                         int             width;
387                         int             height;
388                         Rectangle buttonRectangle;
389                         Rectangle borderRectangle;
390
391                         width = button.ClientSize.Width;
392                         height = button.ClientSize.Height;
393
394                         SolidBrush      sb = new SolidBrush(button.BackColor);
395                         dc.FillRectangle(sb, button.ClientRectangle);
396                         sb.Dispose();
397                         
398                         // set up the button rectangle
399                         buttonRectangle = button.ClientRectangle;
400                         if (button.has_focus) {
401                                 // shrink the rectangle for the normal button drawing inside the focus rectangle
402                                 borderRectangle = Rectangle.Inflate(buttonRectangle, -1, -1);
403                         } else {
404                                 borderRectangle = buttonRectangle;
405                         }
406
407                         if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
408                                 DrawFlatStyleButton (dc, borderRectangle, button);
409                         } else {
410                                 CPDrawButton(dc, borderRectangle, button.ButtonState);                          
411                         }
412                         
413                         // First, draw the image
414                         if ((button.image != null) || (button.image_list != null)) {
415                                 // Need to draw a picture
416                                 Image   i;
417                                 int     image_x;
418                                 int     image_y;
419                                 int     image_width;
420                                 int     image_height;
421
422                                 if (button.ImageIndex!=-1) {    // We use ImageIndex instead of image_index since it will return -1 if image_list is null
423                                         i = button.image_list.Images[button.image_index];
424                                 } else {
425                                         i = button.image;
426                                 }
427
428                                 image_width = button.image.Width;
429                                 image_height = button.image.Height;
430
431                                 switch(button.image_alignment) {
432                                 case ContentAlignment.TopLeft: {
433                                         image_x=0;
434                                         image_y=0;
435                                         break;
436                                 }
437
438                                 case ContentAlignment.TopCenter: {
439                                         image_x=(width-image_width)/2;
440                                         image_y=0;
441                                         break;
442                                 }
443
444                                 case ContentAlignment.TopRight: {
445                                         image_x=width-image_width;
446                                         image_y=0;
447                                         break;
448                                 }
449
450                                 case ContentAlignment.MiddleLeft: {
451                                         image_x=0;
452                                         image_y=(height-image_height)/2;
453                                         break;
454                                 }
455
456                                 case ContentAlignment.MiddleCenter: {
457                                         image_x=(width-image_width)/2;
458                                         image_y=(height-image_height)/2;
459                                         break;
460                                 }
461
462                                 case ContentAlignment.MiddleRight: {
463                                         image_x=width-image_width;
464                                         image_y=(height-image_height)/2;
465                                         break;
466                                 }
467
468                                 case ContentAlignment.BottomLeft: {
469                                         image_x=0;
470                                         image_y=height-image_height;
471                                         break;
472                                 }
473
474                                 case ContentAlignment.BottomCenter: {
475                                         image_x=(width-image_width)/2;
476                                         image_y=height-image_height;
477                                         break;
478                                 }
479
480                                 case ContentAlignment.BottomRight: {
481                                         image_x=width-image_width;
482                                         image_y=height-image_height;
483                                         break;
484                                 }
485
486                                 default: {
487                                         image_x=0;
488                                         image_y=0;
489                                         break;
490                                 }
491                                 }
492
493                                 if (button.is_pressed) {
494                                         image_x+=1;
495                                         image_y+=1;
496                                 }
497
498                                 if (button.is_enabled) {
499                                         dc.DrawImage(i, image_x, image_y); 
500                                 } else {
501                                         CPDrawImageDisabled(dc, i, image_x, image_y, ColorButtonFace);
502                                 }
503                         }
504                         
505                         // Draw the focus rectangle
506                         if (button.has_focus) {
507                                 if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
508                                         DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
509                                 } else { 
510                                         CPDrawFocusRectangle(dc, button.ClientRectangle, button.ForeColor, button.BackColor);
511                                 }
512                         }
513                         
514                         // Now the text
515                         if (button.text != null && button.text != String.Empty) {
516                                 Rectangle text_rect = Rectangle.Inflate(buttonRectangle, -4, -4);
517
518                                 if (button.is_pressed) {
519                                         text_rect.X++;
520                                         text_rect.Y++;
521                                 }
522
523                                 if (button.is_enabled) {
524                                         SolidBrush      b = new SolidBrush(button.ForeColor);
525                                         dc.DrawString(button.text, button.Font, b, text_rect, button.text_format);
526                                         b.Dispose();
527                                 } else {
528                                         if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
529                                                 dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rect, button.text_format);
530                                         } else {
531                                                 CPDrawStringDisabled(dc, button.text, button.Font, ColorButtonText, text_rect, button.text_format);
532                                         }
533                                 }
534                         }
535                 }
536                 
537                 // draw the flat style part of the rectangle
538                 public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
539                         Color rect_back_color = button.BackColor;
540                         Color rect_fore_color = button.ForeColor;
541                         Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
542                                 
543                         if (button.Enabled) {
544                                 if (button.Capture || button.is_entered) {
545                                         if (button.FlatStyle == FlatStyle.Flat) {
546                                                 // fill the rectangle
547                                                 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
548                                                 
549                                                 // now draw the outer border
550                                                 if (button.Capture && button.is_entered) {
551                                                         rect_back_color = ControlPaint.LightLight (rect_back_color);
552                                                 } else {
553                                                         rect_back_color = ControlPaint.Light (rect_back_color);
554                                                 }
555                                                 
556                                                 // draw rectangle and fill it
557                                                 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
558                                                 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
559                                         } else {
560                                                 // else it must be a popup button
561                                                 
562                                                 if (button.Capture && button.is_entered) {
563                                                         graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
564                                                 } else {
565                                                         // draw a 3d border
566                                                         CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor); 
567                                                         graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
568                                                         graphics.DrawLine ( ResPool.GetPen (this.ColorButtonText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
569                                                 }
570                                         }
571                                         
572                                         // TODO: draw inner focus rectangle
573                                         
574                                 } else {
575                                         // popup has a ButtonColorText forecolor, not a button.ForeCOlor
576                                         if (button.FlatStyle == FlatStyle.Popup) {
577                                                 rect_fore_color = this.ColorButtonText;
578                                         }
579                                         
580                                         // fill then draw outer rect
581                                         graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
582                                         graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
583                                 }
584                                 
585                                 // finally some small tweaks to render radiobutton and checkbox
586                                 CheckBox checkbox = button as CheckBox;
587                                 RadioButton radiobutton = button as RadioButton;
588                                 if ((checkbox != null && checkbox.Checked) ||
589                                         (radiobutton != null && radiobutton.Checked)) {
590                                         if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
591                                                 // render the hover for flat flatstyle and cheked
592                                                 graphics.DrawRectangle(ResPool.GetPen (this.ColorButtonText), trace_rectangle);
593                                         } else if (!button.is_entered && !button.Capture) {
594                                                 // render the checked state for popup when unhovered
595                                                 CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor); 
596                                         }
597                                 }
598                         } else {
599                                 // rendering checkbox or radio button style buttons
600                                 CheckBox checkbox = button as CheckBox;
601                                 RadioButton radiobutton = button as RadioButton;
602                                 bool draw_popup_checked = false;
603                                 
604                                 if (button.FlatStyle == FlatStyle.Popup) {
605                                         rect_fore_color = this.ColorButtonText;
606                                 
607                                         // see if we should draw a disabled checked popup button
608                                         draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
609                                                 (radiobutton != null && radiobutton.Checked));
610                                 }
611                                 
612                                 graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
613                                 graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
614                                 
615                                 // finally draw the flatstyle checked effect if need
616                                 if (draw_popup_checked) {
617                                         // render the checked state for popup when unhovered
618                                         CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
619                                 }
620                         }
621                 }
622
623                 public override Size ButtonBaseDefaultSize {
624                         get {
625                                 return new Size (75, 23);
626                         }
627                 }
628                 #endregion      // ButtonBase
629
630                 #region CheckBox
631                 public override void DrawCheckBox(Graphics dc, Rectangle clip_area, CheckBox checkbox) {
632                         StringFormat            text_format;
633                         Rectangle               client_rectangle;
634                         Rectangle               text_rectangle;
635                         Rectangle               checkbox_rectangle;
636                         SolidBrush              sb;
637                         int                     checkmark_size=13;
638                         int                     checkmark_space = 4;
639
640                         client_rectangle = checkbox.ClientRectangle;
641                         text_rectangle = client_rectangle;
642                         checkbox_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, checkmark_size, checkmark_size);
643
644                         text_format = new StringFormat();
645                         text_format.Alignment=StringAlignment.Near;
646                         text_format.LineAlignment=StringAlignment.Center;
647
648                         /* Calculate the position of text and checkbox rectangle */
649                         if (checkbox.appearance!=Appearance.Button) {
650                                 switch(checkbox.check_alignment) {
651                                         case ContentAlignment.BottomCenter: {
652                                                 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
653                                                 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
654                                                 text_rectangle.X=client_rectangle.X;
655                                                 text_rectangle.Width=client_rectangle.Width;
656                                                 text_rectangle.Height=client_rectangle.Height-checkbox_rectangle.Y-checkmark_space;
657                                                 break;
658                                         }
659
660                                         case ContentAlignment.BottomLeft: {
661                                                 checkbox_rectangle.X=client_rectangle.Left;
662                                                 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
663                                                 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
664                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;                                             
665                                                 break;
666                                         }
667
668                                         case ContentAlignment.BottomRight: {
669                                                 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
670                                                 checkbox_rectangle.Y=client_rectangle.Bottom-checkmark_size;
671                                                 text_rectangle.X=client_rectangle.X;
672                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;                                             
673                                                 break;
674                                         }
675
676                                         case ContentAlignment.MiddleCenter: {
677                                                 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
678                                                 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
679                                                 text_rectangle.X=client_rectangle.X;
680                                                 text_rectangle.Width=client_rectangle.Width;
681                                                 break;
682                                         }
683
684                                         default:
685                                         case ContentAlignment.MiddleLeft: {
686                                                 checkbox_rectangle.X=client_rectangle.Left;
687                                                 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
688                                                 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
689                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;                                                                                             
690                                                 break;
691                                         }
692
693                                         case ContentAlignment.MiddleRight: {
694                                                 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
695                                                 checkbox_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-checkmark_size/2;
696                                                 text_rectangle.X=client_rectangle.X;
697                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
698                                                 break;
699                                         }
700
701                                         case ContentAlignment.TopCenter: {
702                                                 checkbox_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-checkmark_size/2;
703                                                 checkbox_rectangle.Y=client_rectangle.Top;
704                                                 text_rectangle.X=client_rectangle.X;
705                                                 text_rectangle.Width=client_rectangle.Width;
706                                                 text_rectangle.Y=checkmark_size+checkmark_space;
707                                                 text_rectangle.Height=client_rectangle.Height-checkmark_size-checkmark_space;
708                                                 break;
709                                         }
710
711                                         case ContentAlignment.TopLeft: {
712                                                 checkbox_rectangle.X=client_rectangle.Left;
713                                                 text_rectangle.X=client_rectangle.X+checkmark_size+checkmark_space;
714                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
715                                                 break;
716                                         }
717
718                                         case ContentAlignment.TopRight: {
719                                                 checkbox_rectangle.X=client_rectangle.Right-checkmark_size;
720                                                 text_rectangle.X=client_rectangle.X;
721                                                 text_rectangle.Width=client_rectangle.Width-checkmark_size-checkmark_space;
722                                                 break;
723                                         }
724                                 }
725                         } else {
726                                 text_rectangle.X=client_rectangle.X;
727                                 text_rectangle.Width=client_rectangle.Width;
728                         }
729                         
730                         /* Set the horizontal alignment of our text */
731                         switch(checkbox.text_alignment) {
732                                 case ContentAlignment.BottomLeft:
733                                 case ContentAlignment.MiddleLeft:
734                                 case ContentAlignment.TopLeft: {
735                                         text_format.Alignment=StringAlignment.Near;
736                                         break;
737                                 }
738
739                                 case ContentAlignment.BottomCenter:
740                                 case ContentAlignment.MiddleCenter:
741                                 case ContentAlignment.TopCenter: {
742                                         text_format.Alignment=StringAlignment.Center;
743                                         break;
744                                 }
745
746                                 case ContentAlignment.BottomRight:
747                                 case ContentAlignment.MiddleRight:
748                                 case ContentAlignment.TopRight: {
749                                         text_format.Alignment=StringAlignment.Far;
750                                         break;
751                                 }
752                         }
753
754                         /* Set the vertical alignment of our text */
755                         switch(checkbox.text_alignment) {
756                                 case ContentAlignment.TopLeft: 
757                                 case ContentAlignment.TopCenter: 
758                                 case ContentAlignment.TopRight: {
759                                         text_format.LineAlignment=StringAlignment.Near;
760                                         break;
761                                 }
762
763                                 case ContentAlignment.BottomLeft:
764                                 case ContentAlignment.BottomCenter:
765                                 case ContentAlignment.BottomRight: {
766                                         text_format.LineAlignment=StringAlignment.Far;
767                                         break;
768                                 }
769
770                                 case ContentAlignment.MiddleLeft:
771                                 case ContentAlignment.MiddleCenter:
772                                 case ContentAlignment.MiddleRight: {
773                                         text_format.LineAlignment=StringAlignment.Center;
774                                         break;
775                                 }
776                         }
777
778                         ButtonState state = ButtonState.Normal;
779                         if (checkbox.FlatStyle == FlatStyle.Flat) {
780                                 state |= ButtonState.Flat;
781                         }
782                         
783                         if (checkbox.Checked) {
784                                 state |= ButtonState.Checked;
785                         }
786                         
787                         if (checkbox.ThreeState && (checkbox.CheckState == CheckState.Indeterminate)) {
788                                 state |= ButtonState.Checked;
789                                 state |= ButtonState.Pushed;                            
790                         }
791                         
792                         // finally make sure the pushed and inavtive states are rendered
793                         if (!checkbox.Enabled) {
794                                 state |= ButtonState.Inactive;
795                         }
796                         else if (checkbox.is_pressed) {
797                                 state |= ButtonState.Pushed;
798                         }
799                         
800                         
801                         // Start drawing
802
803                         sb=new SolidBrush(checkbox.BackColor);
804                         dc.FillRectangle(sb, checkbox.ClientRectangle);
805                         sb.Dispose();
806                         
807                         // render as per normal button
808                         if (checkbox.appearance==Appearance.Button) {
809                                 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
810                                         DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
811                                 } else {
812                                         CPDrawButton(dc, checkbox.ClientRectangle, state);
813                                 }
814                         } else {
815                                 // establish if we are rendering a flat style of some sort
816                                 if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
817                                         DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
818                                 } else {
819                                         ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
820                                 }
821                         }
822                         
823                         // offset the text if it's pressed and a button
824                         if (checkbox.Appearance == Appearance.Button) {
825                                 if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
826                                         text_rectangle.X ++;
827                                         text_rectangle.Y ++;
828                                 }
829                                 
830                                 text_rectangle.Inflate(-4, -4);
831                         }
832                         
833                         /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
834                         if (checkbox.Enabled) {
835                                 sb = ResPool.GetSolidBrush(checkbox.ForeColor);
836                                 dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);                           
837                         } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
838                                 dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
839                         } else {
840                                 CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorButtonText, text_rectangle, text_format);
841                         }
842
843                         if (checkbox.Focused) {
844                                 if (checkbox.FlatStyle != FlatStyle.Flat) {
845                                         DrawInnerFocusRectangle (dc, Rectangle.Inflate (client_rectangle, -4, -4), checkbox.BackColor);
846                                 } else {
847                                         dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (client_rectangle, -4, -4));
848                                 }
849                         }
850                 }
851
852                 // renders a checkBox with the Flat and Popup FlatStyle
853                 private void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
854                 {
855                         Pen                     pen;                    
856                         Rectangle       rect;
857                         Rectangle       checkbox_rectangle;
858                         Rectangle       fill_rectangle;
859                         int                     lineWidth;
860                         int                     Scale;
861                         
862                         // set up our rectangles first
863                         if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered) {
864                                 // clip one pixel from bottom right for non popup rendered checkboxes
865                                 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-1, 0), Math.Max(rectangle.Height-1,0));
866                                 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));
867                         } else {
868                                 // clip two pixels from bottom right for non popup rendered checkboxes
869                                 checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
870                                 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));
871                         }       
872                                 
873                         // if disabled render in disabled state
874                         if (checkbox.Enabled) {
875                                 // process the state of the checkbox
876                                 if (checkbox.is_entered || checkbox.Capture) {
877                                         // decide on which background color to use
878                                         if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
879                                                 graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
880                                         } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
881                                                 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
882                                         } else {
883                                                 // use regular window background color
884                                                 graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
885                                         }
886                                         
887                                         // render the outer border
888                                         if (checkbox.FlatStyle == FlatStyle.Flat) {
889                                                 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
890                                         } else {
891                                                 // draw sunken effect
892                                                 CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
893                                         }
894                                 } else {
895                                         graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);                           
896                                         
897                                         if (checkbox.FlatStyle == FlatStyle.Flat) {
898                                                 ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
899                                         } else {
900                                                 // draw the outer border
901                                                 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ControlPaint.DarkDark (checkbox.BackColor), ButtonBorderStyle.Solid);
902                                         }                       
903                                 }
904                         } else {
905                                 if (checkbox.FlatStyle == FlatStyle.Popup) {
906                                         graphics.FillRectangle(SystemBrushes.Control, fill_rectangle);
907                                 }       
908                         
909                                 // draw disabled state,
910                                 ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
911                         }               
912                         
913                         /* Make sure we've got at least a line width of 1 */
914                         lineWidth = Math.Max(3, fill_rectangle.Width/3);
915                         Scale=Math.Max(1, fill_rectangle.Width/9);
916                         
917                         // flat style check box is rendered inside a rectangle shifted down by one
918                         rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
919                         if (checkbox.Enabled) {
920                                 pen=ResPool.GetPen(checkbox.ForeColor);
921                         } else {
922                                 pen=SystemPens.ControlDark;
923                         }
924
925                         if (checkbox.Checked) {
926                                 /* Need to draw a check-mark */
927                                 for (int i=0; i<lineWidth; i++) {
928                                         graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
929                                         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);
930                                 }
931                         }                                       
932                 }
933
934
935                 #endregion      // CheckBox
936
937                 #region GroupBox
938                 public override void DrawGroupBox (Graphics dc,  Rectangle area, GroupBox box) {
939                         SizeF size;
940                         int width, y;
941                         Rectangle rect = box.ClientRectangle;
942                         Color disabled = ColorGrayText;
943                         
944                         Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
945                         Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
946                         
947                         // TODO: When the Light and Dark methods work this code should be activate it
948                         //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
949                         //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
950
951                         dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
952
953                         size = dc.MeasureString (box.Text, box.Font);
954                         width = (int) size.Width;
955                         
956                         if (width > box.Width - 16)
957                                 width = box.Width - 16;
958                         
959                         y = box.Font.Height / 2;
960                         
961                         /* Draw group box*/
962                         dc.DrawLine (pen_dark, 0, y, 8, y); // top 
963                         dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);                    
964                         dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);                     
965                         dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
966                         
967                         dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
968                         dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);                       
969                         
970                         dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width,  box.Height - 2); // bottom
971                         dc.DrawLine (pen_light, 0, box.Height - 1, box.Width,  box.Height - 1);
972                         
973                         dc.DrawLine (pen_dark, box.Width - 2, y,  box.Width - 2, box.Height - 2); // right
974                         dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
975                         
976                         
977                         /* Text */
978                         if (box.Enabled)
979                                 dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0);
980                         else
981                                 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor, 
982                                         new RectangleF (10, 0, width,  box.Font.Height), new StringFormat ());                                  
983                                 
984                 }
985
986                 public override Size GroupBoxDefaultSize {
987                         get {
988                                 return new Size (200,100);
989                         }
990                 }
991                 #endregion
992
993                 #region HScrollBar
994                 public override Size HScrollBarDefaultSize {
995                         get {
996                                 return new Size (80, this.ScrollBarButtonSize);
997                         }
998                 }
999
1000                 #endregion      // HScrollBar
1001
1002                 #region Label
1003                 public  override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) {
1004                         if (label_br_fore_color == null || label_br_fore_color.Color != label.ForeColor) {
1005                                 label_br_fore_color = GetControlForeBrush (label.ForeColor);
1006                         }
1007
1008                         if (label_br_back_color == null || label_br_back_color.Color != label.BackColor) {
1009                                 label_br_back_color = GetControlBackBrush (label.BackColor);
1010                         }
1011
1012                         dc.FillRectangle (label_br_back_color, clip_rectangle);
1013                         
1014                         CPDrawBorderStyle (dc, clip_rectangle, label.BorderStyle);              
1015
1016                         if (label.Enabled) {
1017                                 dc.DrawString (label.Text, label.Font, label_br_fore_color, clip_rectangle, label.string_format);
1018                         } else {
1019                                 ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
1020                         }
1021                 
1022                 }
1023
1024                 public override Size LabelDefaultSize {
1025                         get {
1026                                 return new Size (100, 23);
1027                         }
1028                 }
1029                 #endregion      // Label
1030
1031                 #region ListView
1032                 // Drawing
1033                 public override void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control)
1034                 {
1035                         Rectangle control_area = control.ClientRectangle;
1036                         bool details = (control.View == View.Details);
1037
1038                         // Draw the border of the list view with a background
1039                         dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), control_area);
1040                         this.CPDrawBorderStyle (dc, control_area, control.BorderStyle);
1041                         if (details) {
1042                                 dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control),
1043                                                   0, 0, control.TotalWidth, control.Font.Height);
1044                                 if (control.Columns.Count > 0) {
1045                                         foreach (ColumnHeader col in control.Columns) {
1046                                                 this.CPDrawButton (dc, col.Rect, ButtonState.Normal);
1047                                                 dc.DrawString (col.Text, control.Font,
1048                                                                ResPool.GetSolidBrush (this.ColorButtonText),
1049                                                                col.Rect, col.Format);
1050                                         }
1051                                 }
1052                                 if (control.GridLines) {
1053                                         // draw vertical gridlines
1054                                         foreach (ColumnHeader col in control.Columns)
1055                                                 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1056                                                              col.Rect.Right, col.Rect.Bottom,
1057                                                              col.Rect.Right, control.TotalHeight);
1058                                         // draw horizontal gridlines
1059                                         foreach (ListViewItem item in control.Items)
1060                                                 dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
1061                                                              item.EntireRect.Left, item.EntireRect.Bottom,
1062                                                              control.TotalWidth, item.EntireRect.Bottom);
1063                                 }
1064                         }
1065
1066                         foreach (ListViewItem item in control.Items)
1067                                 this.DrawListViewItem (dc, control, item);
1068                 }
1069
1070                 // draws the ListViewItem of the given index
1071                 private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
1072                 {
1073                         if (control.CheckBoxes) {
1074                                 if (control.StateImageList == null) {
1075                                         // Make sure we've got at least a line width of 1
1076                                         int check_wd = Math.Max (3, item.CheckRect.Width / 6);
1077                                         int scale = Math.Max (1, item.CheckRect.Width / 12);
1078
1079                                         // define a rectangle inside the border area
1080                                         Rectangle rect = new Rectangle (item.CheckRect.X + 2,
1081                                                                         item.CheckRect.Y + 2,
1082                                                                         item.CheckRect.Width - 4,
1083                                                                         item.CheckRect.Height - 4);
1084                                         Pen pen = new Pen (SystemColors.WindowText, 2);
1085                                         dc.DrawRectangle (pen, rect);
1086
1087                                         // Need to draw a check-mark
1088                                         if (item.Checked) {
1089                                                 pen.Width = 1;
1090                                                 // adjustments to get the check-mark at the right place
1091                                                 rect.X ++; rect.Y ++;
1092                                                 // following logic is taken from DrawFrameControl method
1093                                                 for (int i = 0; i < check_wd; i++) {
1094                                                         dc.DrawLine (pen, rect.Left + check_wd / 2,
1095                                                                      rect.Top + check_wd + i,
1096                                                                      rect.Left + check_wd / 2 + 2 * scale,
1097                                                                      rect.Top + check_wd + 2 * scale + i);
1098                                                         dc.DrawLine (pen,
1099                                                                      rect.Left + check_wd / 2 + 2 * scale,
1100                                                                      rect.Top + check_wd + 2 * scale + i,
1101                                                                      rect.Left + check_wd / 2 + 6 * scale,
1102                                                                      rect.Top + check_wd - 2 * scale + i);
1103                                                 }
1104                                         }
1105                                 }
1106                                 else {
1107                                         if (item.Checked && control.StateImageList.Images.Count > 1)
1108                                                 control.StateImageList.Draw (dc,
1109                                                                              item.CheckRect.Location, 1);
1110                                         else if (! item.Checked && control.StateImageList.Images.Count > 0)
1111                                                 control.StateImageList.Draw (dc,
1112                                                                              item.CheckRect.Location, 0);
1113                                 }
1114                         }
1115
1116                         // Item is drawn as a special case, as it is not just text
1117                         if (control.View == View.LargeIcon) {
1118                                 if (item.ImageIndex > -1 &&
1119                                     control.LargeImageList != null &&
1120                                     item.ImageIndex < control.LargeImageList.Images.Count)
1121                                         control.LargeImageList.Draw (dc, item.IconRect.Location,
1122                                                                      item.ImageIndex);
1123                         }
1124                         else {
1125                                 if (item.ImageIndex > -1 &&
1126                                     control.SmallImageList != null &&
1127                                     item.ImageIndex < control.SmallImageList.Images.Count)
1128                                         control.SmallImageList.Draw (dc, item.IconRect.Location,
1129                                                                      item.ImageIndex);
1130                         }
1131
1132                         // draw the item text
1133                         Rectangle text_rect = Rectangle.Empty;
1134                         text_rect.X = item.LabelRect.X + 1;
1135                         text_rect.Y = item.LabelRect.Y + 1;
1136                         text_rect.Width = item.LabelRect.Width - 3;
1137                         text_rect.Height = item.LabelRect.Height - 2;
1138
1139                         // format for the item text
1140                         StringFormat format = new StringFormat ();
1141                         format.LineAlignment = StringAlignment.Center;
1142                         if (control.View == View.LargeIcon)
1143                                 format.Alignment = StringAlignment.Center;
1144                         else
1145                                 format.Alignment = StringAlignment.Near;
1146
1147                         if (!control.LabelWrap)
1148                                 format.FormatFlags = StringFormatFlags.NoWrap;
1149
1150                         dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
1151                         if (item.Text != null && item.Text.Length > 0)
1152                                 dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
1153                                                (item.ForeColor), text_rect, format);
1154
1155                         if (control.View == View.Details && control.Columns.Count > 0) {
1156                                 // draw subitems for details view
1157                                 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
1158                                 int count = (control.Columns.Count < subItems.Count ? 
1159                                              control.Columns.Count : subItems.Count);
1160
1161                                 if (count > 0) {
1162                                         Rectangle sub_item_rect = Rectangle.Empty;
1163                                         sub_item_rect.X = item.LabelRect.Right + 1;
1164                                         sub_item_rect.Y = item.LabelRect.Y + 1;
1165                                         sub_item_rect.Height = item.LabelRect.Height - 2;
1166
1167                                         ListViewItem.ListViewSubItem subItem;
1168                                         ColumnHeader col;
1169
1170                                         // set the format for subitems
1171                                         format.FormatFlags = StringFormatFlags.NoWrap;
1172                                         format.Alignment = StringAlignment.Near;
1173
1174                                         // 0th subitem is the item already drawn
1175                                         for (int index = 1; index < count; index++) {
1176                                                 subItem = subItems [index];
1177                                                 col = control.Columns [index];
1178                                                 sub_item_rect.Width = col.Wd - 3;
1179
1180                                                 if (item.UseItemStyleForSubItems) {
1181                                                         dc.FillRectangle (this.ResPool.GetSolidBrush
1182                                                                           (item.BackColor), sub_item_rect);
1183                                                         if (subItem.Text != null && subItem.Text.Length > 0)
1184                                                                 dc.DrawString (subItem.Text, item.Font,
1185                                                                                this.ResPool.GetSolidBrush
1186                                                                                (item.ForeColor),
1187                                                                                sub_item_rect, format);
1188                                                 }
1189                                                 else {
1190                                                         dc.FillRectangle (this.ResPool.GetSolidBrush
1191                                                                           (subItem.BackColor),
1192                                                                           sub_item_rect);
1193                                                         if (subItem.Text != null && subItem.Text.Length > 0)
1194                                                                 dc.DrawString (subItem.Text, subItem.Font,
1195                                                                                this.ResPool.GetSolidBrush
1196                                                                                (subItem.ForeColor),
1197                                                                                sub_item_rect, format);
1198                                                 }
1199                                                 sub_item_rect.X += col.Wd;
1200                                         }
1201                                 }
1202                         }
1203                 }
1204
1205                 // Sizing
1206                 public override Size ListViewCheckBoxSize {
1207                         get { return new Size (16, 16); }
1208                 }
1209
1210                 public override int ListViewColumnHeaderHeight {
1211                         get { return 16; }
1212                 }
1213
1214                 public override int ListViewDefaultColumnWidth {
1215                         get { return 60; }
1216                 }
1217
1218                 public override int ListViewVerticalSpacing {
1219                         get { return 22; }
1220                 }
1221
1222                 public override int ListViewEmptyColumnWidth {
1223                         get { return 10; }
1224                 }
1225
1226                 public override int ListViewHorizontalSpacing {
1227                         get { return 10; }
1228                 }
1229
1230                 public override Size ListViewDefaultSize {
1231                         get { return new Size (121, 97); }
1232                 }
1233                 #endregion      // ListView
1234
1235                 #region Panel
1236                 public override Size PanelDefaultSize {
1237                         get {
1238                                 return new Size (200, 100);
1239                         }
1240                 }
1241                 #endregion      // Panel
1242
1243                 #region PictureBox
1244                 public override void DrawPictureBox (Graphics dc, PictureBox pb) {
1245                         Rectangle client = pb.ClientRectangle;
1246                         int x, y, width, height;
1247
1248                         dc.FillRectangle (new SolidBrush (pb.BackColor), client);
1249
1250                         x = y = 0;
1251                         if (pb.Image != null) {
1252                                 switch (pb.SizeMode) {
1253                                 case PictureBoxSizeMode.StretchImage:
1254                                         width = client.Width;
1255                                         height = client.Height;
1256                                         break;
1257                                 case PictureBoxSizeMode.CenterImage:
1258                                         width = client.Width;
1259                                         height = client.Height;
1260                                         x = width / 2;
1261                                         y = (height - pb.Image.Height) / 2;
1262                                         break;
1263                                 default:
1264                                         // Normal, AutoSize
1265                                         width = client.Width;
1266                                         height = client.Height;
1267                                         break;
1268                                 }
1269                                 dc.DrawImage (pb.Image, x, y, width, height);
1270                         }
1271                         CPDrawBorderStyle (dc, client, pb.BorderStyle);
1272                 }
1273
1274                 public override Size PictureBoxDefaultSize {
1275                         get {
1276                                 return new Size (100, 50);
1277                         }
1278                 }
1279                 #endregion      // PictureBox
1280
1281                 #region ProgressBar
1282                 public override void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar) {
1283                         Rectangle       client_area             = progress_bar.client_area;
1284                         Rectangle       paint_area              = progress_bar.paint_area;
1285                         int             steps                   = (progress_bar.Maximum - progress_bar.Minimum) / progress_bar.step;
1286                         int             space_betweenblocks     = 2;
1287                         int             x;
1288                         int             block_width;
1289                         int             increment;
1290                         int             barpos_pixels;
1291
1292                         x = client_area.X;
1293                         block_width = ((client_area.Height) * 2 ) / 3;
1294                         barpos_pixels = ((progress_bar.Value - progress_bar.Minimum) * client_area.Width) / (progress_bar.Maximum - progress_bar.Minimum);
1295                         increment = block_width + space_betweenblocks;
1296
1297                         /* Draw border */
1298                         CPDrawBorder3D (dc, progress_bar.paint_area, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
1299                         
1300                         /* Draw Blocks */
1301                         while ((x - client_area.X) < barpos_pixels) {
1302                                 dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
1303                                 x  = x + increment;
1304                         }
1305                 }
1306                 
1307                 public override Size ProgressBarDefaultSize {
1308                         get {
1309                                 return new Size (100, 23);
1310                         }
1311                 }
1312
1313                 #endregion      // ProgressBar
1314
1315                 #region RadioButton
1316                 public override void DrawRadioButton (Graphics dc, Rectangle clip_rectangle, RadioButton radio_button) {
1317                         StringFormat    text_format;
1318                         Rectangle       client_rectangle;
1319                         Rectangle       text_rectangle;
1320                         Rectangle       radiobutton_rectangle;
1321                         SolidBrush      sb;
1322                         int             radiobutton_size = 12;
1323                         int     radiobutton_space = 4;
1324
1325                         client_rectangle = radio_button.ClientRectangle;
1326                         text_rectangle = client_rectangle;
1327                         radiobutton_rectangle = new Rectangle(text_rectangle.X, text_rectangle.Y, radiobutton_size, radiobutton_size);
1328
1329                         text_format = new StringFormat();
1330                         text_format.Alignment = StringAlignment.Near;
1331                         text_format.LineAlignment = StringAlignment.Center;
1332
1333                         /* Calculate the position of text and checkbox rectangle */
1334                         if (radio_button.appearance!=Appearance.Button) {
1335                                 switch(radio_button.radiobutton_alignment) {
1336                                 case ContentAlignment.BottomCenter: {
1337                                         radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1338                                         radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1339                                         text_rectangle.X=client_rectangle.X;
1340                                         text_rectangle.Width=client_rectangle.Width;
1341                                         text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
1342                                         break;
1343                                 }
1344
1345                                 case ContentAlignment.BottomLeft: {
1346                                         radiobutton_rectangle.X=client_rectangle.Left;
1347                                         radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1348                                         text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
1349                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;                                 
1350                                         break;
1351                                 }
1352
1353                                 case ContentAlignment.BottomRight: {
1354                                         radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1355                                         radiobutton_rectangle.Y=client_rectangle.Bottom-radiobutton_size;
1356                                         text_rectangle.X=client_rectangle.X;
1357                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
1358                                         break;
1359                                 }
1360
1361                                 case ContentAlignment.MiddleCenter: {
1362                                         radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1363                                         radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1364                                         text_rectangle.X=client_rectangle.X;
1365                                         text_rectangle.Width=client_rectangle.Width;
1366                                         break;
1367                                 }
1368
1369                                 default:
1370                                 case ContentAlignment.MiddleLeft: {
1371                                         radiobutton_rectangle.X=client_rectangle.Left;
1372                                         radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1373                                         text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
1374                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
1375                                         break;
1376                                 }
1377
1378                                 case ContentAlignment.MiddleRight: {
1379                                         radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1380                                         radiobutton_rectangle.Y=(client_rectangle.Bottom-client_rectangle.Top)/2-radiobutton_size/2;
1381                                         text_rectangle.X=client_rectangle.X;
1382                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
1383                                         break;
1384                                 }
1385
1386                                 case ContentAlignment.TopCenter: {
1387                                         radiobutton_rectangle.X=(client_rectangle.Right-client_rectangle.Left)/2-radiobutton_size/2;
1388                                         radiobutton_rectangle.Y=client_rectangle.Top;
1389                                         text_rectangle.X=client_rectangle.X;
1390                                         text_rectangle.Y=radiobutton_size+radiobutton_space;
1391                                         text_rectangle.Width=client_rectangle.Width;
1392                                         text_rectangle.Height=client_rectangle.Height-radiobutton_size-radiobutton_space;
1393                                         break;
1394                                 }
1395
1396                                 case ContentAlignment.TopLeft: {
1397                                         radiobutton_rectangle.X=client_rectangle.Left;
1398                                         radiobutton_rectangle.Y=client_rectangle.Top;
1399                                         text_rectangle.X=client_rectangle.X+radiobutton_size+radiobutton_space;
1400                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
1401                                         break;
1402                                 }
1403
1404                                 case ContentAlignment.TopRight: {
1405                                         radiobutton_rectangle.X=client_rectangle.Right-radiobutton_size;
1406                                         radiobutton_rectangle.Y=client_rectangle.Top;
1407                                         text_rectangle.X=client_rectangle.X;
1408                                         text_rectangle.Width=client_rectangle.Width-radiobutton_size-radiobutton_space;
1409                                         break;
1410                                 }
1411                                 }
1412                         } else {
1413                                 text_rectangle.X=client_rectangle.X;
1414                                 text_rectangle.Width=client_rectangle.Width;
1415                         }
1416                         
1417                         /* Set the horizontal alignment of our text */
1418                         switch(radio_button.text_alignment) {
1419                                 case ContentAlignment.BottomLeft:
1420                                 case ContentAlignment.MiddleLeft:
1421                                 case ContentAlignment.TopLeft: {
1422                                         text_format.Alignment=StringAlignment.Near;
1423                                         break;
1424                                 }
1425
1426                                 case ContentAlignment.BottomCenter:
1427                                 case ContentAlignment.MiddleCenter:
1428                                 case ContentAlignment.TopCenter: {
1429                                         text_format.Alignment=StringAlignment.Center;
1430                                         break;
1431                                 }
1432
1433                                 case ContentAlignment.BottomRight:
1434                                 case ContentAlignment.MiddleRight:
1435                                 case ContentAlignment.TopRight: {
1436                                         text_format.Alignment=StringAlignment.Far;
1437                                         break;
1438                                 }
1439                         }
1440
1441                         /* Set the vertical alignment of our text */
1442                         switch(radio_button.text_alignment) {
1443                                 case ContentAlignment.TopLeft: 
1444                                 case ContentAlignment.TopCenter: 
1445                                 case ContentAlignment.TopRight: {
1446                                         text_format.LineAlignment=StringAlignment.Near;
1447                                         break;
1448                                 }
1449
1450                                 case ContentAlignment.BottomLeft:
1451                                 case ContentAlignment.BottomCenter:
1452                                 case ContentAlignment.BottomRight: {
1453                                         text_format.LineAlignment=StringAlignment.Far;
1454                                         break;
1455                                 }
1456
1457                                 case ContentAlignment.MiddleLeft:
1458                                 case ContentAlignment.MiddleCenter:
1459                                 case ContentAlignment.MiddleRight: {
1460                                         text_format.LineAlignment=StringAlignment.Center;
1461                                         break;
1462                                 }
1463                         }
1464
1465                         ButtonState state = ButtonState.Normal;
1466                         if (radio_button.FlatStyle == FlatStyle.Flat) {
1467                                 state |= ButtonState.Flat;
1468                         }
1469                         
1470                         if (radio_button.Checked) {
1471                                 state |= ButtonState.Checked;
1472                         }
1473
1474                         // Start drawing
1475
1476                         sb=new SolidBrush(radio_button.BackColor);
1477                         dc.FillRectangle(sb, radio_button.ClientRectangle);
1478                         sb.Dispose();
1479                         
1480                 
1481                         
1482                         if (radio_button.appearance==Appearance.Button) {
1483                                 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
1484                                         DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
1485                                 } else {                                
1486                                         CPDrawButton(dc, radio_button.ClientRectangle, state);
1487                                 }               
1488                         } else {
1489                                 // establish if we are rendering a flat style of some sort
1490                                 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
1491                                         DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
1492                                 } else {
1493                                         ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
1494                                 }
1495                         }
1496                         
1497                         // offset the text if it's pressed and a button
1498                         if (radio_button.Appearance == Appearance.Button) {
1499                                 if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
1500                                         text_rectangle.X ++;
1501                                         text_rectangle.Y ++;
1502                                 }
1503                                 
1504                                 text_rectangle.Inflate(-4,-4);
1505                         } 
1506                         
1507                         /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
1508                         sb=new SolidBrush(radio_button.ForeColor);
1509                         dc.DrawString (radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
1510                         sb.Dispose();
1511                         if (radio_button.Enabled) {
1512                                 sb = ResPool.GetSolidBrush(radio_button.ForeColor);
1513                                 dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);                           
1514                         } else if (radio_button.FlatStyle == FlatStyle.Flat) {
1515                                 dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorButtonFace)), text_rectangle, text_format);
1516                         } else {
1517                                 CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorButtonText, text_rectangle, text_format);
1518                         }
1519
1520                         if (radio_button.Focused) {
1521                                 if (radio_button.FlatStyle != FlatStyle.Flat) {
1522                                         DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
1523                                 } else {
1524                                         dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
1525                                 }
1526                         }                       
1527                 }
1528
1529                 // renders a radio button with the Flat and Popup FlatStyle
1530                 private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
1531                 {
1532                         int     lineWidth;
1533                         
1534                         if (radio_button.Enabled) {
1535                                 // draw the outer flatstyle arcs
1536                                 if (radio_button.FlatStyle == FlatStyle.Flat) {
1537                                         graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
1538                                         
1539                                         // fill in the area depending on whether or not the mouse is hovering
1540                                         if (radio_button.is_entered && radio_button.Capture) {
1541                                                 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1542                                         } else {
1543                                                 graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1544                                         }
1545                                 } else {
1546                                         // must be a popup radio button
1547                                         // fill the control
1548                                         graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
1549
1550                                         if (radio_button.is_entered || radio_button.Capture) {
1551                                                 // draw the popup 3d button knob
1552                                                 graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
1553
1554                                                 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
1555                                                 graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
1556                                                 
1557                                         } else {
1558                                                 // just draw lighter flatstyle outer circle
1559                                                 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorButtonFace)), rectangle, 0, 359);                                                
1560                                         }                                                                               
1561                                 }
1562                         } else {
1563                                 // disabled
1564                                 // fill control background color regardless of actual backcolor
1565                                 graphics.FillPie (ResPool.GetSolidBrush (this.ColorButtonFace), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
1566                                 // draw the ark as control dark
1567                                 graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorButtonFace)), rectangle, 0, 359);
1568                         }
1569
1570                         // draw the check
1571                         lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
1572                         if (radio_button.Checked) {
1573                                 SolidBrush buttonBrush;
1574
1575                                 if (!radio_button.Enabled) {
1576                                         buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorButtonFace));
1577                                 } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
1578                                         buttonBrush = ResPool.GetSolidBrush (this.ColorButtonText);
1579                                 } else {
1580                                         buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
1581                                 }
1582                                 graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
1583                         }       
1584                 }
1585
1586                 public override Size RadioButtonDefaultSize {
1587                         get {
1588                                 return new Size (104,24);
1589                         }
1590                 }
1591                 #endregion      // RadioButton
1592
1593                 #region ScrollBar
1594                 public override void DrawScrollBar(Graphics dc, Rectangle clip_rectangle, ScrollBar bar) {
1595                         int             scrollbutton_width = bar.scrollbutton_width;
1596                         int             scrollbutton_height = bar.scrollbutton_height;
1597                         Rectangle       first_arrow_area;
1598                         Rectangle       second_arrow_area;                      
1599                         Rectangle       thumb_pos;
1600                         
1601                         thumb_pos = bar.ThumbPos;
1602
1603                         if (bar.vert) {
1604                                 first_arrow_area = new Rectangle(0, 0, bar.Width, scrollbutton_height);
1605                                 bar.FirstArrowArea = first_arrow_area;
1606
1607                                 second_arrow_area = new Rectangle(0, bar.ClientRectangle.Height - scrollbutton_height, bar.Width, scrollbutton_height);
1608                                 bar.SecondArrowArea = second_arrow_area;
1609
1610                                 thumb_pos.Width = bar.Width;
1611                                 bar.ThumbPos = thumb_pos;
1612
1613                                 /* Buttons */
1614                                 CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
1615                                 CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);                          
1616
1617                                 /* Background */
1618                                 switch (bar.thumb_moving) {
1619                                 case ScrollBar.ThumbMoving.None: {
1620                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), 0,  
1621                                                 scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
1622                                         
1623                                         break;
1624                                 }
1625                                 case ScrollBar.ThumbMoving.Forward: {
1626                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1627                                                 0,  scrollbutton_height,
1628                                                 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
1629                                                                                                 
1630                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1631                                                 0, thumb_pos.Y + thumb_pos.Height,
1632                                                 bar.ClientRectangle.Width, bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
1633                                                 
1634                                         break;
1635                                 }
1636                                 
1637                                 case ScrollBar.ThumbMoving.Backwards: {
1638                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1639                                                 0,  scrollbutton_height,
1640                                                 bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
1641                                                                                                 
1642                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1643                                                 0, thumb_pos.Y + thumb_pos.Height,
1644                                                 bar.ClientRectangle.Width, bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);                                               
1645                                                 
1646                                         break;
1647                                 }
1648                                 
1649                                 default:
1650                                         break;
1651                                 }
1652                                         
1653                         }
1654                         else {
1655                                 first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
1656                                 bar.FirstArrowArea = first_arrow_area;
1657
1658                                 second_arrow_area = new Rectangle (bar.ClientRectangle.Width - scrollbutton_width, 0, scrollbutton_width, bar.Height);
1659                                 bar.SecondArrowArea = second_arrow_area;
1660
1661                                 thumb_pos.Height = bar.Height;
1662                                 bar.ThumbPos = thumb_pos;
1663
1664                                 /* Buttons */
1665                                 CPDrawScrollButton (dc, bar.FirstArrowArea, ScrollButton.Left, bar.firstbutton_state);
1666                                 CPDrawScrollButton (dc, bar.SecondArrowArea, ScrollButton.Right, bar.secondbutton_state);
1667
1668                                 /* Background */
1669                                 //dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width, 
1670                                 //      0, area.Width - (scrollbutton_width * 2), area.Height);
1671                                         
1672                                 switch (bar.thumb_moving) {
1673                                 case ScrollBar.ThumbMoving.None: {
1674                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
1675                                                 0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
1676                                         
1677                                         break;
1678                                 }
1679                                 
1680                                 case ScrollBar.ThumbMoving.Forward: {
1681                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1682                                                 scrollbutton_width,  0,
1683                                                 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
1684                                                                                                 
1685                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1686                                                 thumb_pos.X + thumb_pos.Width, 0,
1687                                                 bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
1688                                                 
1689                                         break;
1690                                 }
1691                                 
1692                                 case ScrollBar.ThumbMoving.Backwards: {
1693                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
1694                                                 scrollbutton_width,  0,
1695                                                 thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
1696                                                                                                 
1697                                         dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
1698                                                 thumb_pos.X + thumb_pos.Width, 0,
1699                                                 bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
1700
1701                                                 
1702                                         break;
1703                                 }
1704                                 
1705                                 default:
1706                                         break;
1707                                 }
1708                         }
1709
1710                         /* Thumb */
1711                         if (bar.Enabled)
1712                                 DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
1713                 }
1714
1715                 public override int ScrollBarButtonSize {
1716                         get { return 16; }
1717                 }
1718                 #endregion      // ScrollBar
1719
1720                 #region StatusBar
1721                 public  override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
1722                         Rectangle       area        = sb.paint_area;
1723                         int             horz_border = 2;
1724                         int             vert_border = 2;
1725
1726                         dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
1727                         
1728                         if (sb.ShowPanels && sb.Panels.Count == 0) {
1729                                 // Create a default panel.
1730                                 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1731                                 
1732                                 StatusBarPanel panel = new StatusBarPanel ();
1733                                 Rectangle new_area = new Rectangle (area.X + horz_border,
1734                                         area.Y + horz_border,
1735                                         area.Width - StatusBarSizeGripWidth - horz_border,
1736                                         area.Height - horz_border);
1737                                 DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
1738                         } else if (sb.ShowPanels) {
1739                                 SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
1740                                 int prev_x = area.X + horz_border;
1741                                 int y = area.Y + vert_border;
1742                                 for (int i = 0; i < sb.Panels.Count; i++) {
1743                                         Rectangle pr = new Rectangle (prev_x, y,
1744                                                 sb.Panels [i].Width, area.Height);
1745                                         prev_x += pr.Width + StatusBarHorzGapWidth;
1746                                         DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
1747                                 }
1748                         }
1749
1750                         if (sb.SizingGrip)
1751                                 CPDrawSizeGrip (dc, ColorButtonFace, area);
1752
1753                 }
1754
1755
1756                 private void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
1757                         SolidBrush br_forecolor, StatusBarPanel panel) {
1758                         int border_size = 3; // this is actually const, even if the border style is none
1759
1760                         area.Height -= border_size;
1761                         if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
1762                                 Border3DStyle border_style = Border3DStyle.SunkenInner;
1763                                 if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
1764                                         border_style = Border3DStyle.RaisedOuter;
1765                                 CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorButtonFace);
1766                         }
1767
1768                         if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
1769                                 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
1770                                         dc, panel.Parent.Font, area, index, DrawItemState.Default,
1771                                         panel, panel.Parent.ForeColor, panel.Parent.BackColor);
1772                                 panel.Parent.OnDrawItemInternal (e);
1773                                 return;
1774                         }
1775
1776                         int left = area.Left;
1777                         if (panel.Icon != null) {
1778                                 left += 2;
1779                                 int size = area.Height - border_size;
1780                                 Rectangle ia = new Rectangle (left, border_size, size, size);
1781                                 dc.DrawIcon (panel.Icon, left, area.Top);
1782                                 left += panel.Icon.Width;
1783                         }
1784
1785                         if (panel.Text == String.Empty)
1786                                 return;
1787
1788                         string text = panel.Text;
1789                         StringFormat string_format = new StringFormat ();
1790                         string_format.LineAlignment = StringAlignment.Center;
1791                         string_format.Alignment = StringAlignment.Near;
1792                         string_format.FormatFlags = StringFormatFlags.NoWrap;
1793
1794                         if (text [0] == '\t') {
1795                                 string_format.Alignment = StringAlignment.Center;
1796                                 text = text.Substring (1);
1797                                 if (text [0] == '\t') {
1798                                         string_format.Alignment = StringAlignment.Far;
1799                                         text = text.Substring (1);
1800                                 }
1801                         }
1802
1803                         float x = left + border_size;
1804                         float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
1805
1806                         dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
1807                 }
1808
1809                 public override int StatusBarSizeGripWidth {
1810                         get { return 15; }
1811                 }
1812
1813                 public override int StatusBarHorzGapWidth {
1814                         get { return 3; }
1815                 }
1816
1817                 public override Size StatusBarDefaultSize {
1818                         get {
1819                                 return new Size (100, 22);
1820                         }
1821                 }
1822                 #endregion      // StatusBar
1823
1824                 public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
1825                 {
1826                         // Do we need to fill the back color? It can't be changed...
1827                         dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
1828                         Rectangle panel_rect = GetTabPanelRectExt (tab);
1829
1830                         if (tab.Appearance == TabAppearance.Normal) {
1831                                 CPDrawBorder3D (dc, panel_rect, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, ColorButtonFace);
1832                                 CPDrawBorder3D (dc, panel_rect, Border3DStyle.Raised, Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
1833                         }
1834
1835                         if (tab.Alignment == TabAlignment.Top) {
1836                                 for (int r = tab.TabPages.Count; r > 0; r--) {
1837                                         for (int i = 0; i < tab.TabPages.Count; i++) {
1838                                                 if (i == tab.SelectedIndex)
1839                                                         continue;
1840                                                 if (r != tab.TabPages [i].Row)
1841                                                         continue;
1842                                                 Rectangle rect = tab.GetTabRect (i);
1843                                                 if (!rect.IntersectsWith (area))
1844                                                         continue;
1845                                                 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1846                                         }
1847                                 }
1848                         } else {
1849                                 for (int r = 0; r < tab.TabPages.Count; r++) {
1850                                         for (int i = 0; i < tab.TabPages.Count; i++) {
1851                                                 if (i == tab.SelectedIndex)
1852                                                         continue;
1853                                                 if (r != tab.TabPages [i].Row)
1854                                                         continue;
1855                                                 Rectangle rect = tab.GetTabRect (i);
1856                                                 if (!rect.IntersectsWith (area))
1857                                                         continue;
1858                                                 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1859                                         }
1860                                 }
1861                         }
1862
1863                         if (tab.SelectedIndex != -1) {
1864                                 DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, tab.GetTabRect (tab.SelectedIndex), true);
1865                         }
1866
1867                         if (tab.ShowSlider) {
1868                                 Rectangle right = GetTabControlRightScrollRect (tab);
1869                                 Rectangle left = GetTabControlLeftScrollRect (tab);
1870                                 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
1871                                 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
1872                         }
1873                 }
1874
1875                 public override Rectangle GetTabControlLeftScrollRect (TabControl tab)
1876                 {
1877                         switch (tab.Alignment) {
1878                         case TabAlignment.Top:
1879                                 return new Rectangle (tab.ClientRectangle.Right - 34, tab.ClientRectangle.Top + 1, 17, 17);
1880                         default:
1881                                 Rectangle panel_rect = GetTabPanelRectExt (tab);
1882                                 return new Rectangle (tab.ClientRectangle.Right - 34, panel_rect.Bottom + 2, 17, 17);
1883                         }
1884                 }
1885
1886                 public override Rectangle GetTabControlRightScrollRect (TabControl tab)
1887                 {
1888                         switch (tab.Alignment) {
1889                         case TabAlignment.Top:
1890                                 return new Rectangle (tab.ClientRectangle.Right - 17, tab.ClientRectangle.Top + 1, 17, 17);
1891                         default:
1892                                 Rectangle panel_rect = GetTabPanelRectExt (tab);
1893                                 return new Rectangle (tab.ClientRectangle.Right - 17, panel_rect.Bottom + 2, 17, 17);
1894                         }
1895                 }
1896
1897                 public override Size TabControlDefaultItemSize {
1898                         get { return new Size (42, 21); }
1899                 }
1900
1901                 public override Point TabControlDefaultPadding {
1902                         get { return new Point (6, 3); }
1903                 }
1904
1905                 public override int TabControlMinimumTabWidth {
1906                         get { return 42; }
1907                 }
1908
1909                 public override Rectangle GetTabControlDisplayRectangle (TabControl tab)
1910                 {
1911                         Rectangle ext = GetTabPanelRectExt (tab);
1912                         // Account for border size
1913                         return new Rectangle (ext.Left + 2, ext.Top + 1, ext.Width - 6, ext.Height - 4);
1914                 }
1915
1916                 public override Size TabControlGetSpacing (TabControl tab) {
1917                         switch (tab.Appearance) {
1918                                 case TabAppearance.Normal:
1919                                         return new Size (1, -2);
1920                                 case TabAppearance.Buttons:
1921                                         return new Size (3, 3);
1922                                 case TabAppearance.FlatButtons:
1923                                         return new Size (9, 3);
1924                                 default:
1925                                         throw new Exception ("Invalid Appearance value: " + tab.Appearance);
1926                                 }
1927                 }
1928
1929                 private Rectangle GetTabPanelRectExt (TabControl tab)
1930                 {
1931                         // Offset the tab from the top corner
1932                         Rectangle res = new Rectangle (tab.ClientRectangle.X + 2,
1933                                         tab.ClientRectangle.Y,
1934                                         tab.ClientRectangle.Width - 2,
1935                                         tab.ClientRectangle.Height - 1);
1936
1937                         if (tab.TabCount == 0)
1938                                 return res;
1939
1940                         int spacing = TabControlGetSpacing (tab).Height;
1941                         int offset = (tab.ItemSize.Height + spacing) * tab.RowCount + 3;
1942
1943                         switch (tab.Alignment) {
1944                         case TabAlignment.Left:
1945                                 res.X += offset;
1946                                 res.Width -= offset;
1947                                 break;
1948                         case TabAlignment.Right:
1949                                 res.Width -= offset;
1950                                 break;
1951                         case TabAlignment.Top:
1952                                 res.Y += offset;
1953                                 res.Height -= offset;
1954                                 break;
1955                         case TabAlignment.Bottom:
1956                                 res.Height -= offset;
1957                                 break;
1958                         }
1959
1960                         return res;
1961                 }
1962
1963                 private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
1964                 {
1965                         int FlatButtonSpacing = 8;
1966                         int RoundCornerSize = 5;
1967                         Rectangle interior;
1968                         int res = bounds.Width;
1969
1970                         // we can't fill the background right away because the bounds might be adjusted if the tab is selected
1971
1972                         if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
1973
1974                                 dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
1975
1976                                 // Separators
1977                                 if (tab.Appearance == TabAppearance.FlatButtons) {
1978                                         int width = bounds.Width;
1979                                         bounds.Width += (FlatButtonSpacing - 2);
1980                                         res = bounds.Width;
1981                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
1982                                         bounds.Width = width;
1983                                 }
1984
1985                                 if (is_selected) {
1986                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
1987                                 } else if (tab.Appearance != TabAppearance.FlatButtons) {
1988                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
1989                                 }
1990
1991                                 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
1992                         } else {
1993                                 Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
1994
1995                                 switch (tab.Alignment) {
1996                                         
1997                                 case TabAlignment.Top:
1998
1999
2000                                         dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2001
2002                                         dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
2003                                         dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
2004                                         dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top);
2005
2006                                         dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom);
2007                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 1, bounds.Top + 2, bounds.Right, bounds.Top + 3);
2008                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom);
2009
2010                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2011
2012                                         if (page.Text != String.Empty) {
2013                                                 StringFormat string_format = new StringFormat ();
2014                                                 string_format.Alignment = StringAlignment.Center;
2015                                                 string_format.LineAlignment = StringAlignment.Center;
2016                                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
2017                                                 interior.Y++;
2018                                                 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2019                                         }
2020
2021                                         break;
2022
2023                                 case TabAlignment.Bottom:
2024
2025                                         dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2026
2027                                         dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
2028                                         dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
2029
2030                                         dc.DrawLine (SystemPens.ControlDark, bounds.Left + 3, bounds.Bottom - 1, bounds.Right - 3, bounds.Bottom - 1);
2031                                         dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Bottom - 3, bounds.Right - 1, bounds.Top);
2032
2033                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
2034                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3);
2035                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top);
2036
2037                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2038
2039                                         if (page.Text != String.Empty) {
2040                                                 StringFormat string_format = new StringFormat ();
2041                                                 string_format.Alignment = StringAlignment.Center;
2042                                                 string_format.LineAlignment = StringAlignment.Center;
2043                                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
2044                                                 interior.Y++;
2045                                                 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2046                                         }
2047
2048                                         break;
2049
2050                                 case TabAlignment.Left:
2051
2052                                         dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2053
2054                                         dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
2055                                         dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
2056                                         dc.DrawLine (light, bounds.Left + 3, bounds.Top, bounds.Right, bounds.Top);
2057
2058                                         dc.DrawLine (SystemPens.ControlDark, bounds.Right, bounds.Bottom - 1, bounds.Left + 2, bounds.Bottom - 1);
2059
2060                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Bottom, bounds.Left + 2, bounds.Bottom);
2061                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left + 2, bounds.Bottom, bounds.Left, bounds.Bottom - 3);
2062
2063                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2064
2065                                         if (page.Text != String.Empty) {
2066                                                 StringFormat string_format = new StringFormat ();
2067                                                 // Flip the text around
2068                                                 string_format.Alignment = StringAlignment.Center;
2069                                                 string_format.LineAlignment = StringAlignment.Center;
2070                                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
2071                                                 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2072                                                 int wo = interior.Width / 2;
2073                                                 int ho = interior.Height / 2;
2074                                                 dc.TranslateTransform (interior.X + wo, interior.Y + ho);
2075                                                 dc.RotateTransform (180);
2076                                                 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), 0, 0, string_format);
2077                                                 dc.ResetTransform ();
2078                                         }
2079
2080                                         break;
2081
2082                                 default:
2083                                         // TabAlignment.Right
2084
2085                                         dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
2086
2087                                         dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
2088                                         dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
2089
2090                                         dc.DrawLine (SystemPens.ControlDark, bounds.Right - 1, bounds.Top + 1, bounds.Right - 1, bounds.Bottom - 1);
2091                                         dc.DrawLine (SystemPens.ControlDark, bounds.Left, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
2092
2093                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3);
2094                                         dc.DrawLine (SystemPens.ControlDarkDark, bounds.Left, bounds.Bottom, bounds.Right - 3, bounds.Bottom);
2095
2096                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
2097
2098                                         if (page.Text != String.Empty) {
2099                                                 StringFormat string_format = new StringFormat ();
2100                                                 string_format.Alignment = StringAlignment.Center;
2101                                                 string_format.LineAlignment = StringAlignment.Center;
2102                                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
2103                                                 string_format.FormatFlags = StringFormatFlags.DirectionVertical;
2104                                                 interior.X++;
2105                                                 dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
2106                                         }
2107
2108                                         break;
2109                                 }
2110                         }
2111
2112                         
2113                         if (page.Focused) {
2114                                 using (Pen pen = new Pen (Color.Black, 1) ) {
2115                                         pen.DashStyle = DashStyle.Dot;
2116                                         dc.DrawRectangle (pen, interior);
2117                                 }
2118                         }
2119
2120                         return res;
2121                 }
2122
2123                 #region ToolBar
2124                 public  override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
2125                         StringFormat    format = new StringFormat ();
2126                         format.Trimming = StringTrimming.EllipsisWord;
2127                         if (control.textAlignment == ToolBarTextAlign.Underneath) {
2128                                 format.LineAlignment = StringAlignment.Center;
2129                                 format.Alignment = StringAlignment.Center;
2130                         } else {
2131                                 format.LineAlignment = StringAlignment.Center;
2132                                 format.Alignment = StringAlignment.Near;
2133                         }
2134                         
2135                         // Exclude the area for divider
2136                         Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2, 
2137                                 control.Width, control.Height - ToolBarGripWidth / 2);
2138                         bool flat = (control.Appearance == ToolBarAppearance.Flat);
2139                         dc.FillRectangle (SystemBrushes.Control, paint_area);
2140                         CPDrawBorderStyle (dc, paint_area, control.BorderStyle);
2141
2142                         if (control.Divider)
2143                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, 0, paint_area.Width, 0);
2144
2145                         foreach (ToolBarButton button in control.Buttons) {
2146
2147                                 Image image = null;
2148                                 Rectangle buttonArea = button.Rectangle;
2149                                 Rectangle imgRect = Rectangle.Empty;  // rect to draw the image
2150                                 Rectangle txtRect = buttonArea;       // rect to draw the text
2151                                 Rectangle ddRect = Rectangle.Empty;   // rect for the drop down arrow
2152
2153                                 // calculate different rects and draw the frame if its not separator button
2154                                 if (button.Style != ToolBarButtonStyle.Separator) {
2155                                         /* Adjustment for drop down arrow */
2156                                         if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
2157                                                 ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
2158                                                 ddRect.Y = buttonArea.Y;
2159                                                 ddRect.Width = this.ToolBarDropDownWidth;
2160                                                 ddRect.Height = buttonArea.Height;
2161                                         }
2162
2163                                         // calculate txtRect and imgRect, if imageIndex and imageList are present
2164                                         if (button.ImageIndex > -1 && control.ImageList != null) {
2165                                                 if (button.ImageIndex < control.ImageList.Images.Count)
2166                                                         image = control.ImageList.Images [button.ImageIndex];
2167                                                 // draw the image at the centre if textalignment is underneath
2168                                                 if (control.TextAlign == ToolBarTextAlign.Underneath) {
2169                                                         imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width 
2170                                                                 - control.ImageSize.Width) / 2) 
2171                                                                 + this.ToolBarImageGripWidth;
2172                                                         imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2173                                                         imgRect.Width = control.ImageSize.Width;
2174                                                         imgRect.Height = control.ImageSize.Height;
2175
2176                                                         txtRect.X = buttonArea.X;
2177                                                         txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
2178                                                         txtRect.Width = buttonArea.Width - ddRect.Width;
2179                                                         txtRect.Height = buttonArea.Height - imgRect.Height 
2180                                                                 - 2 * this.ToolBarImageGripWidth;
2181                                                 }
2182                                                 else {
2183                                                         imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
2184                                                         imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2185                                                         imgRect.Width = control.ImageSize.Width;
2186                                                         imgRect.Height = control.ImageSize.Height;
2187
2188                                                         txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
2189                                                         txtRect.Y = buttonArea.Y;
2190                                                         txtRect.Width = buttonArea.Width - imgRect.Width 
2191                                                                 - 2 * this.ToolBarImageGripWidth - ddRect.Width;
2192                                                         txtRect.Height = buttonArea.Height;
2193                                                 }
2194                                         }
2195                                         /* Draw the button frame, only if it is not a separator */
2196                                         if (flat) { 
2197                                                 if (button.Pushed || button.Pressed) {
2198                                                         CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorButtonFace);
2199                                                 } else if (button.Hilight) {
2200                                                         dc.DrawRectangle (ResPool.GetPen (ColorButtonText), buttonArea);
2201                                                         if (! ddRect.IsEmpty) {
2202                                                                 dc.DrawLine (ResPool.GetPen (ColorButtonText), ddRect.X, ddRect.Y, ddRect.X, 
2203                                                                         ddRect.Y + ddRect.Height);
2204                                                                 buttonArea.Width -= this.ToolBarDropDownWidth;
2205                                                         }
2206                                                 }
2207                                         }
2208                                         else { // normal toolbar
2209                                                 if (button.Pushed || button.Pressed) {
2210                                                         CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
2211                                                                 Border3DSide.All, ColorButtonFace);
2212                                                         if (! ddRect.IsEmpty) {
2213                                                                 CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
2214                                                                         Border3DSide.Left, ColorButtonFace);
2215                                                                 buttonArea.Width -= this.ToolBarDropDownWidth;
2216                                                         }
2217                                                 }
2218                                                 else {
2219                                                         CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
2220                                                                 Border3DSide.All, ColorButtonFace);
2221                                                         if (! ddRect.IsEmpty) {
2222                                                                 CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
2223                                                                         Border3DSide.Left, ColorButtonFace);
2224                                                                 buttonArea.Width -= this.ToolBarDropDownWidth;
2225                                                         }
2226                                                 }
2227                                         }
2228                                 }
2229                                 DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
2230                                         imgRect, image, txtRect, ddRect, flat);
2231                         }
2232                 }
2233
2234                 private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
2235                         Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect, 
2236                         Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
2237                         if (! button.Visible)
2238                                 return;
2239
2240                         switch (button.Style) {
2241
2242                         case ToolBarButtonStyle.Separator:
2243                                 // separator is drawn only in the case of flat appearance
2244                                 if (flat) {
2245                                         dc.DrawLine (ResPool.GetPen (ColorButtonShadow), buttonArea.X + 1, buttonArea.Y, 
2246                                                 buttonArea.X + 1, buttonArea.Height);
2247                                         dc.DrawLine (ResPool.GetPen (ColorButtonHilight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width,
2248                                                 buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, buttonArea.Height);
2249                                         /* draw a horizontal separator */
2250                                         if (button.Wrapper) {
2251                                                 int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
2252                                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), 0, y, controlArea.Width, y);
2253                                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 0, y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width, controlArea.Width,
2254                                                         y + 1 + (int) ResPool.GetPen (ColorButtonFace).Width);
2255                                         }
2256                                 }
2257                                 break;
2258
2259                         case ToolBarButtonStyle.ToggleButton:
2260                                 Rectangle toggleArea = Rectangle.Empty;
2261                                 toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
2262                                 toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
2263                                 toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
2264                                 toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
2265                                 if (button.PartialPush && button.Pushed) {
2266                                         dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
2267                                         if (! imgRect.IsEmpty) {
2268                                                 if (button.Enabled && image != null)
2269                                                         button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, 
2270                                                                 imgRect.Height, button.ImageIndex);
2271                                                 else {
2272                                                         dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2273                                                         ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2274                                                                 Border3DSide.Right | Border3DSide.Bottom);
2275                                                 }
2276                                         }
2277                                         if (button.Enabled)
2278                                                 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2279                                         else
2280                                                 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight, txtRect, format);
2281                                 }
2282
2283                                 else if (button.PartialPush) {
2284                                         dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
2285                                         if (! imgRect.IsEmpty) {
2286                                                 if (button.Enabled && image != null)
2287                                                         button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2288                                                                 imgRect.Height, button.ImageIndex);
2289                                                 else {
2290                                                         dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2291                                                         ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2292                                                                 Border3DSide.Right | Border3DSide.Bottom);
2293                                                 }
2294                                         }
2295                                         if (button.Enabled)
2296                                                 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2297                                         else
2298                                                 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2299                                                         txtRect, format);
2300                                 }
2301
2302                                 else if (button.Pushed) {
2303                                         dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
2304                                         if (! imgRect.IsEmpty) {
2305                                                 if (button.Enabled && image != null)
2306                                                         button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2307                                                                 imgRect.Height, button.ImageIndex);
2308                                                 else {
2309                                                         dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2310                                                         CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2311                                                                 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2312                                                 }
2313                                         }
2314                                         if (button.Enabled)
2315                                                 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2316                                         else
2317                                                 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2318                                                         txtRect, format);
2319                                 }
2320
2321                                 else {
2322                                         dc.FillRectangle (SystemBrushes.Control, toggleArea);
2323                                         if (! imgRect.IsEmpty) {
2324                                                 if (button.Enabled && image != null)
2325                                                         button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
2326                                                                 imgRect.Height, button.ImageIndex);
2327                                                 else {
2328                                                         dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2329                                                         CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2330                                                                 Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2331                                                 }
2332                                         }
2333                                         if (button.Enabled)
2334                                                 dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2335                                         else
2336                                                 CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2337                                                         txtRect, format);
2338                                 }
2339                                 break;
2340
2341                         case ToolBarButtonStyle.DropDownButton:
2342                                 // draw the dropdown arrow
2343                                 if (! ddRect.IsEmpty) {
2344                                         PointF [] vertices = new PointF [3];
2345                                         PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
2346                                         vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
2347                                         vertices [0].Y = ddCenter.Y;
2348                                         vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
2349                                         vertices [1].Y = ddCenter.Y;
2350                                         vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
2351                                         vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
2352                                         dc.FillPolygon (SystemBrushes.ControlText, vertices);
2353                                 }
2354                                 goto case ToolBarButtonStyle.PushButton;
2355
2356                         case ToolBarButtonStyle.PushButton:
2357                                 if (! imgRect.IsEmpty){
2358                                         if (button.Enabled && image != null)
2359                                                 button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
2360                                                         button.ImageIndex);
2361                                         else {
2362                                                 dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
2363                                                 CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
2364                                                         Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
2365                                         }
2366                                 }
2367                                 if (button.Enabled)
2368                                         dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
2369                                 else
2370                                         CPDrawStringDisabled (dc, button.Text, font, ColorButtonHilight,
2371                                                 txtRect, format);
2372                                 break;
2373                         }
2374                 }
2375
2376                 // Grip width for the ToolBar
2377                 public override int ToolBarGripWidth {
2378                         get { return 2;}
2379                 }
2380
2381                 // Grip width for the Image on the ToolBarButton
2382                 public override int ToolBarImageGripWidth {
2383                         get { return 2;}
2384                 }
2385
2386                 // width of the separator
2387                 public override int ToolBarSeparatorWidth {
2388                         get { return 4; }
2389                 }
2390
2391                 // width of the dropdown arrow rect
2392                 public override int ToolBarDropDownWidth {
2393                         get { return 13; }
2394                 }
2395
2396                 // width for the dropdown arrow on the ToolBarButton
2397                 public override int ToolBarDropDownArrowWidth {
2398                         get { return 5;}
2399                 }
2400
2401                 // height for the dropdown arrow on the ToolBarButton
2402                 public override int ToolBarDropDownArrowHeight {
2403                         get { return 3;}
2404                 }
2405
2406                 public override Size ToolBarDefaultSize {
2407                         get {
2408                                 return new Size (100, 42);
2409                         }
2410                 }
2411                 #endregion      // ToolBar
2412
2413                 #region ToolTip
2414                 public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt) {
2415                         Control control;
2416
2417                         control = tt.tooltip_window;
2418                         dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
2419                         dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
2420                         dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, tt.tooltip_window.string_format);
2421                 }
2422
2423                 public override Size ToolTipSize(ToolTip tt, string text) {
2424                         SizeF   sizef;
2425
2426                         sizef = tt.tooltip_window.DeviceContext.MeasureString(text, tt.tooltip_window.Font);\r
2427                         return new Size((int)sizef.Width+2, (int)sizef.Height+3);               // Need space for the border\r
2428                 }
2429                 #endregion      // ToolTip
2430
2431                 #region TrackBar
2432                 private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
2433                         ref Rectangle thumb_pos, ref Rectangle thumb_area,  Brush br_thumb,
2434                         float ticks, int value_pos, bool mouse_value) {                 
2435
2436                         Point toptick_startpoint = new Point ();
2437                         Point bottomtick_startpoint = new Point ();
2438                         Point channel_startpoint = new Point ();
2439                         float pixel_len;
2440                         float pixels_betweenticks;
2441                         const int space_from_right = 8;
2442                         const int space_from_left = 8;                  
2443                         
2444                         switch (tb.TickStyle)   {
2445                         case TickStyle.BottomRight:
2446                         case TickStyle.None:
2447                                 channel_startpoint.Y = 8;
2448                                 channel_startpoint.X = 9;
2449                                 bottomtick_startpoint.Y = 13;
2450                                 bottomtick_startpoint.X = 24;                           
2451                                 break;
2452                         case TickStyle.TopLeft:
2453                                 channel_startpoint.Y = 8;
2454                                 channel_startpoint.X = 19;
2455                                 toptick_startpoint.Y = 13;
2456                                 toptick_startpoint.X = 8;
2457                                 break;
2458                         case TickStyle.Both:
2459                                 channel_startpoint.Y = 8;
2460                                 channel_startpoint.X = 18;      
2461                                 bottomtick_startpoint.Y = 13;
2462                                 bottomtick_startpoint.X = 32;                           
2463                                 toptick_startpoint.Y = 13;
2464                                 toptick_startpoint.X = 8;                               
2465                                 break;
2466                         default:
2467                                 break;
2468                         }
2469                         
2470                         thumb_area.X = area.X + channel_startpoint.X;
2471                         thumb_area.Y = area.Y + channel_startpoint.Y;
2472                         thumb_area.Height = area.Height - space_from_right - space_from_left;
2473                         thumb_area.Width = 4;
2474
2475                         /* Draw channel */
2476                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
2477                                 1, thumb_area.Height);
2478                         
2479                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X + 1, channel_startpoint.Y,
2480                                 1, thumb_area.Height);
2481
2482                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X + 3, channel_startpoint.Y,
2483                                 1, thumb_area.Height);
2484
2485                         pixel_len = thumb_area.Height - 11;
2486                         pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
2487                         
2488                         /* Convert thumb position from mouse position to value*/
2489                         if (mouse_value) {
2490                                 
2491                                 if (value_pos >= channel_startpoint.Y)
2492                                         value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
2493                                 else
2494                                         value_pos = 0;                  
2495
2496                                 if (value_pos + tb.Minimum > tb.Maximum)
2497                                         value_pos = tb.Maximum - tb.Minimum;
2498                                 
2499                                 tb.Value = value_pos + tb.Minimum;
2500                         }                       
2501                         
2502                         thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
2503                         
2504                         /* Draw thumb fixed 10x22 size */
2505                         thumb_pos.Width = 10;
2506                         thumb_pos.Height = 22;
2507
2508                         switch (tb.TickStyle)   {
2509                         case TickStyle.BottomRight:
2510                         case TickStyle.None: {
2511                                 thumb_pos.X = channel_startpoint.X - 8;
2512
2513                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
2514                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
2515                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
2516                                 
2517                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y  +9);
2518                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y  +9 - 4);
2519
2520                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y  + 10, thumb_pos.X +16, thumb_pos.Y +10);
2521                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 16, thumb_pos.Y  + 10, thumb_pos.X  +16 + 5, thumb_pos.Y +10 - 5);
2522
2523                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
2524                                 dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
2525                                 dc.FillRectangle (br_thumb, thumb_pos.X + 18, thumb_pos.Y + 3, 1, 4);
2526                                 dc.FillRectangle (br_thumb, thumb_pos.X + 19, thumb_pos.Y + 4, 1, 2);
2527
2528                                 break;
2529                         }
2530                         case TickStyle.TopLeft: {
2531                                 thumb_pos.X = channel_startpoint.X - 10;
2532
2533                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
2534                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
2535
2536                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X  + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
2537                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 4, thumb_pos.Y  + 9, thumb_pos.X, thumb_pos.Y + 5);
2538                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X  + 19, thumb_pos.Y + 9, thumb_pos.X  +19 , thumb_pos.Y+ 1);
2539
2540                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X  + 4, thumb_pos.Y+ 10, thumb_pos.X  + 4 + 16, thumb_pos.Y+ 10);
2541                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X  + 4, thumb_pos.Y + 10, thumb_pos.X  -1, thumb_pos.Y+ 5);
2542                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
2543
2544                                 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
2545                                 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
2546                                 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 1, 4);
2547                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 1, 2);
2548
2549                                 break;
2550                         }
2551
2552                         case TickStyle.Both: {
2553                                 thumb_pos.X = area.X + 10;
2554                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
2555                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
2556
2557                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y  + 9);
2558                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X  + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y  + 8);
2559
2560                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y  +10);
2561                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X  + 20, thumb_pos.Y, thumb_pos.X  + 20, thumb_pos.Y+ 9);
2562
2563                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
2564
2565                                 break;
2566                         }
2567
2568                         default:
2569                                 break;
2570                         }
2571
2572                         pixel_len = thumb_area.Height - 11;
2573                         pixels_betweenticks = pixel_len / ticks;                                
2574                         
2575                         /* Draw ticks*/
2576                         if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
2577                                 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { 
2578                                 
2579                                 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks)  {                                       
2580                                         if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
2581                                                 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y  + inc, 
2582                                                         area.X + bottomtick_startpoint.X  + 3, area.Y + bottomtick_startpoint.Y + inc);
2583                                         else
2584                                                 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y  + inc, 
2585                                                         area.X + bottomtick_startpoint.X  + 2, area.Y + bottomtick_startpoint.Y + inc);
2586                                 }
2587                         }
2588
2589                         if (pixels_betweenticks > 0 &&  ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
2590                                 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2591
2592                                 pixel_len = thumb_area.Height - 11;
2593                                 pixels_betweenticks = pixel_len / ticks;
2594                                 
2595                                 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
2596                                         //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
2597                                         if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
2598                                                 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X  - 3 , area.Y + toptick_startpoint.Y + inc, 
2599                                                         area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
2600                                         else
2601                                                 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X  - 2, area.Y + toptick_startpoint.Y + inc, 
2602                                                         area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y  + inc);
2603                                 }                       
2604                         }
2605                 }
2606
2607                 /* 
2608                         Horizontal trackbar 
2609                   
2610                         Does not matter the size of the control, Win32 always draws:
2611                                 - Ticks starting from pixel 13, 8
2612                                 - Channel starting at pos 8, 19 and ends at Width - 8
2613                                 - Autosize makes always the control 40 pixels height
2614                                 - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
2615                                 
2616                 */
2617                 private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
2618                         ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
2619                         float ticks, int value_pos, bool mouse_value) {                 
2620                         Point toptick_startpoint = new Point ();
2621                         Point bottomtick_startpoint = new Point ();
2622                         Point channel_startpoint = new Point ();
2623                         float pixel_len;
2624                         float pixels_betweenticks;
2625                         const int space_from_right = 8;
2626                         const int space_from_left = 8;          
2627                                                 
2628                         switch (tb.TickStyle) {
2629                         case TickStyle.BottomRight:
2630                         case TickStyle.None:
2631                                 channel_startpoint.X = 8;
2632                                 channel_startpoint.Y = 9;
2633                                 bottomtick_startpoint.X = 13;
2634                                 bottomtick_startpoint.Y = 24;                           
2635                                 break;
2636                         case TickStyle.TopLeft:
2637                                 channel_startpoint.X = 8;
2638                                 channel_startpoint.Y = 19;
2639                                 toptick_startpoint.X = 13;
2640                                 toptick_startpoint.Y = 8;
2641                                 break;
2642                         case TickStyle.Both:
2643                                 channel_startpoint.X = 8;
2644                                 channel_startpoint.Y = 18;      
2645                                 bottomtick_startpoint.X = 13;
2646                                 bottomtick_startpoint.Y = 32;                           
2647                                 toptick_startpoint.X = 13;
2648                                 toptick_startpoint.Y = 8;                               
2649                                 break;
2650                         default:
2651                                 break;
2652                         }
2653                                                 
2654                         thumb_area.X = area.X + channel_startpoint.X;
2655                         thumb_area.Y = area.Y + channel_startpoint.Y;
2656                         thumb_area.Width = area.Width - space_from_right - space_from_left;
2657                         thumb_area.Height = 4;
2658                         
2659                         /* Draw channel */
2660                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), channel_startpoint.X, channel_startpoint.Y,
2661                                 thumb_area.Width, 1);
2662                         
2663                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), channel_startpoint.X, channel_startpoint.Y + 1,
2664                                 thumb_area.Width, 1);
2665
2666                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), channel_startpoint.X, channel_startpoint.Y +3,
2667                                 thumb_area.Width, 1);
2668
2669                         pixel_len = thumb_area.Width - 11;
2670                         pixels_betweenticks = pixel_len / (tb.Maximum - tb.Minimum);
2671
2672                         /* Convert thumb position from mouse position to value*/
2673                         if (mouse_value) {                      
2674                                 if (value_pos >= channel_startpoint.X)
2675                                         value_pos = (int)(((float) (value_pos - channel_startpoint.X)) / pixels_betweenticks);
2676                                 else
2677                                         value_pos = 0;                          
2678
2679                                 if (value_pos + tb.Minimum > tb.Maximum)
2680                                         value_pos = tb.Maximum - tb.Minimum;
2681                                 
2682                                 tb.Value = value_pos + tb.Minimum;
2683                         }                       
2684                         
2685                         thumb_pos.X = channel_startpoint.X + (int) (pixels_betweenticks * (float) value_pos);
2686                         
2687                         /* Draw thumb fixed 10x22 size */
2688                         thumb_pos.Width = 10;
2689                         thumb_pos.Height = 22;
2690
2691                         switch (tb.TickStyle) {
2692                         case TickStyle.BottomRight:
2693                         case TickStyle.None: {
2694                                 thumb_pos.Y = channel_startpoint.Y - 8;
2695
2696                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
2697                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
2698                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
2699
2700                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
2701                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
2702
2703                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
2704                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
2705
2706                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
2707                                 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
2708                                 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 18, 4, 1);
2709                                 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 19, 2, 1);
2710                                 break;
2711                         }
2712                         case TickStyle.TopLeft: {
2713                                 thumb_pos.Y = channel_startpoint.Y - 10;
2714
2715                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
2716                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
2717
2718                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
2719                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
2720                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
2721
2722                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
2723                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
2724                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
2725
2726                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
2727                                 dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
2728                                 dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 4, 1);
2729                                 dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 2, 1);
2730                                 break;
2731                         }
2732
2733                         case TickStyle.Both: {
2734                                 thumb_pos.Y = area.Y + 10;
2735                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
2736                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
2737
2738                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
2739                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
2740
2741                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
2742                                 dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
2743
2744                                 dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
2745
2746                                 break;
2747                         }
2748
2749                         default:
2750                                 break;
2751                         }
2752
2753                         pixel_len = thumb_area.Width - 11;
2754                         pixels_betweenticks = pixel_len / ticks;
2755
2756                         /* Draw ticks*/
2757                         if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
2758                                 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {                         
2759                                 
2760                                 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
2761                                         if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
2762                                                 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y, 
2763                                                         area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
2764                                         else
2765                                                 dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y, 
2766                                                         area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
2767                                 }
2768                         }
2769
2770                         if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
2771                                 ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
2772                                 
2773                                 for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
2774                                         if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
2775                                                 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3, 
2776                                                         area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
2777                                         else
2778                                                 dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2, 
2779                                                         area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2780                                 }                       
2781                         }
2782                 }
2783
2784                 public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb) {
2785 //public override void DrawTrackBar (Graphics dc, 
2786 //Rectangle area, 
2787 //TrackBar tb,
2788 //ref Rectangle thumb_pos, 
2789 //ref Rectangle thumb_area,  
2790                         Brush           br_thumb;
2791                         int             value_pos;
2792                         bool            mouse_value;
2793                         float           ticks = (tb.Maximum - tb.Minimum) / tb.tickFrequency; /* N of ticks draw*/
2794                         Rectangle       area;
2795                         Rectangle       thumb_pos = tb.ThumbPos;
2796                         Rectangle       thumb_area = tb.ThumbArea;
2797
2798                         if (tb.thumb_pressed) {
2799                                 value_pos = tb.thumb_mouseclick;
2800                                 mouse_value = true;
2801                         } else {
2802                                 value_pos = tb.Value - tb.Minimum;
2803                                 mouse_value = false;
2804                         }
2805
2806                         area = tb.paint_area;
2807
2808                         if (tb.thumb_pressed == true) {
2809                                 br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
2810                         } else {
2811                                 br_thumb = ResPool.GetSolidBrush (ColorButtonFace);
2812                         }
2813
2814                         
2815                         /* Control Background */
2816                         if (tb.BackColor == DefaultControlBackColor) {
2817                                 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
2818                         } else {
2819                                 dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
2820                         }
2821                         
2822
2823                         if (tb.Focused) {
2824                                 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, area.Width - 1, 1);
2825                                 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
2826                                 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X, area.Y, 1, area.Height - 1);
2827                                 dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonFace, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
2828                         }
2829
2830                         if (tb.Orientation == Orientation.Vertical) {
2831                                 DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
2832                                         br_thumb, ticks, value_pos, mouse_value);
2833                         
2834                         } else {
2835                                 DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
2836                                         br_thumb, ticks, value_pos, mouse_value);
2837                         }
2838
2839                         tb.ThumbPos = thumb_pos;
2840                         tb.ThumbArea = thumb_area;
2841                 }
2842
2843                 public override Size TrackBarDefaultSize {
2844                         get {
2845                                 return new Size (104, 42);
2846                         }
2847                 }
2848
2849                 #endregion      // TrackBar
2850
2851                 #region VScrollBar
2852                 public override Size VScrollBarDefaultSize {
2853                         get {
2854                                 return new Size (this.ScrollBarButtonSize, 80);
2855                         }
2856                 }
2857                 #endregion      // VScrollBar
2858
2859                 #region ControlPaint
2860                 private enum DrawFrameControlStates {
2861                         ButtonCheck             = 0x0000,
2862                         ButtonRadioImage        = 0x0001,
2863                         ButtonRadioMask         = 0x0002,
2864                         ButtonRadio             = 0x0004,
2865                         Button3State            = 0x0008,
2866                         ButtonPush              = 0x0010,
2867
2868                         CaptionClose            = 0x0000,
2869                         CaptionMin              = 0x0001,
2870                         CaptionMax              = 0x0002,
2871                         CaptionRestore          = 0x0004,
2872                         CaptionHelp             = 0x0008,
2873
2874                         MenuArrow               = 0x0000,
2875                         MenuCheck               = 0x0001,
2876                         MenuBullet              = 0x0002,
2877                         MenuArrowRight          = 0x0004,
2878
2879                         ScrollUp                = 0x0000,
2880                         ScrollDown              = 0x0001,
2881                         ScrollLeft              = 0x0002,
2882                         ScrollRight             = 0x0003,
2883                         ScrollComboBox          = 0x0005,
2884                         ScrollSizeGrip          = 0x0008,
2885                         ScrollSizeGripRight     = 0x0010,
2886
2887                         Inactive                = 0x0100,
2888                         Pushed                  = 0x0200,
2889                         Checked                 = 0x0400,
2890                         Transparent             = 0x0800,
2891                         Hot                     = 0x1000,
2892                         AdjustRect              = 0x2000,
2893                         Flat                    = 0x4000,
2894                         Mono                    = 0x8000
2895
2896                 }
2897
2898                 private enum DrawFrameControlTypes {
2899                         Caption = 1,
2900                         Menu    = 2,
2901                         Scroll  = 3,
2902                         Button  = 4
2903                 }
2904
2905                 public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
2906                         ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
2907                         Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
2908                         int bottomWidth, ButtonBorderStyle bottomStyle) {
2909                         DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
2910                         DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
2911                         DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
2912                         DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
2913                 }
2914
2915                 public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
2916                         CPDrawBorder3D(graphics, rectangle, style, sides, ColorButtonFace);
2917                 }
2918
2919                 private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
2920                         Pen             penTopLeft;
2921                         Pen             penTopLeftInner;
2922                         Pen             penBottomRight;
2923                         Pen             penBottomRightInner;
2924                         Rectangle       rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
2925                         bool            doInner = false;
2926
2927                         if ((style & Border3DStyle.Adjust)!=0) {
2928                                 rect.Y-=2;
2929                                 rect.X-=2;
2930                                 rect.Width+=4;
2931                                 rect.Height+=4;
2932                         }
2933
2934                         /* default to flat */
2935                         penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
2936                         penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2937                         penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
2938                         penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2939
2940                         if ((style & Border3DStyle.RaisedOuter)!=0) {
2941                                 penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2942                                 penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2943                                 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2944                                         doInner=true;
2945                                 }
2946                         } else if ((style & Border3DStyle.SunkenOuter)!=0) {
2947                                 penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2948                                 penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2949                                 if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
2950                                         doInner=true;
2951                                 }
2952                         }
2953
2954                         if ((style & Border3DStyle.RaisedInner)!=0) {
2955                                 if (doInner) {
2956                                         penTopLeftInner=ResPool.GetPen(control_color);
2957                                         penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2958                                 } else {
2959                                         penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
2960                                         penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2961                                 }
2962                         } else if ((style & Border3DStyle.SunkenInner)!=0) {
2963                                 if (doInner) {
2964                                         penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
2965                                         penBottomRightInner=ResPool.GetPen(control_color);
2966                                 } else {
2967                                         penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
2968                                         penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
2969                                 }
2970                         }
2971
2972                         if ((sides & Border3DSide.Middle)!=0) {
2973                                 graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
2974                         }
2975
2976                         if ((sides & Border3DSide.Left)!=0) {
2977                                 graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
2978                                 if (doInner) {
2979                                         graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
2980                                 }
2981                         }
2982
2983                         if ((sides & Border3DSide.Top)!=0) {
2984                                 graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
2985
2986                                 if (doInner) {
2987                                         if ((sides & Border3DSide.Left)!=0) {
2988                                                 graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
2989                                         } else {
2990                                                 graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
2991                                         }
2992                                 }
2993                         }
2994
2995                         if ((sides & Border3DSide.Right)!=0) {
2996                                 graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
2997
2998                                 if (doInner) {
2999                                         if ((sides & Border3DSide.Top)!=0) {
3000                                                 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
3001                                         } else {
3002                                                 graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
3003                                         }
3004                                 }
3005                         }
3006
3007                         if ((sides & Border3DSide.Bottom)!=0) {
3008                                 int     left=rect.Left;
3009
3010                                 if ((sides & Border3DSide.Left)!=0) {
3011                                         left+=1;
3012                                 }
3013
3014                                 graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
3015
3016                                 if (doInner) {
3017                                         if ((sides & Border3DSide.Right)!=0) {
3018                                                 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
3019                                         } else {
3020                                                 graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
3021                                         }
3022                                 }
3023                         }
3024
3025                 }
3026
3027
3028                 public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
3029                         DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonPush;
3030
3031                         if ((state & ButtonState.Pushed)!=0) {
3032                                 dfcs |= DrawFrameControlStates.Pushed;
3033                         }
3034
3035                         if ((state & ButtonState.Checked)!=0) {
3036                                 dfcs |= DrawFrameControlStates.Checked;
3037                         }
3038
3039                         if ((state & ButtonState.Flat)!=0) {
3040                                 dfcs |= DrawFrameControlStates.Flat;
3041                         }
3042
3043                         if ((state & ButtonState.Inactive)!=0) {
3044                                 dfcs |= DrawFrameControlStates.Inactive;
3045                         }
3046                         DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
3047                 }
3048
3049
3050                 public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
3051                         Rectangle       captionRect;
3052                         int                     lineWidth;
3053
3054                         CPDrawButton(graphics, rectangle, state);
3055
3056                         if (rectangle.Width<rectangle.Height) {
3057                                 captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
3058                         } else {
3059                                 captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
3060                         }
3061
3062                         if ((state & ButtonState.Pushed)!=0) {
3063                                 captionRect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-3, rectangle.Height-3);
3064                         }
3065
3066                         /* Make sure we've got at least a line width of 1 */
3067                         lineWidth=Math.Max(1, captionRect.Width/7);
3068
3069                         switch(button) {
3070                         case CaptionButton.Close: {
3071                                 Pen     pen;
3072
3073                                 if ((state & ButtonState.Inactive)!=0) {
3074                                         pen=new Pen(ColorButtonHilight, lineWidth);
3075                                         DrawCaptionHelper(graphics, ColorButtonHilight, pen, lineWidth, 1, captionRect, button);
3076                                         pen.Dispose();
3077
3078                                         pen=new Pen(ColorButtonShadow, lineWidth);
3079                                         DrawCaptionHelper(graphics, ColorButtonShadow, pen, lineWidth, 0, captionRect, button);
3080                                         pen.Dispose();
3081                                         return;
3082                                 } else {
3083                                         pen=new Pen(ColorButtonText, lineWidth);
3084                                         DrawCaptionHelper(graphics, ColorButtonText, pen, lineWidth, 0, captionRect, button);
3085                                         pen.Dispose();
3086                                         return;
3087                                 }
3088                         }
3089
3090                         case CaptionButton.Help:
3091                         case CaptionButton.Maximize:
3092                         case CaptionButton.Minimize:
3093                         case CaptionButton.Restore: {
3094                                 if ((state & ButtonState.Inactive)!=0) {
3095                                         DrawCaptionHelper(graphics, ColorButtonHilight, SystemPens.ControlLightLight, lineWidth, 1, captionRect, button);
3096
3097                                         DrawCaptionHelper(graphics, ColorButtonShadow, SystemPens.ControlDark, lineWidth, 0, captionRect, button);
3098                                         return;
3099                                 } else {
3100                                         DrawCaptionHelper(graphics, ColorButtonText, SystemPens.ControlText, lineWidth, 0, captionRect, button);
3101                                         return;
3102                                 }
3103                         }
3104                         }
3105                 }
3106
3107
3108                 public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
3109                         DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonCheck;
3110
3111                         if ((state & ButtonState.Pushed)!=0) {
3112                                 dfcs |= DrawFrameControlStates.Pushed;
3113                         }
3114
3115                         if ((state & ButtonState.Checked)!=0) {
3116                                 dfcs |= DrawFrameControlStates.Checked;
3117                         }
3118
3119                         if ((state & ButtonState.Flat)!=0) {
3120                                 dfcs |= DrawFrameControlStates.Flat;
3121                         }
3122
3123                         if ((state & ButtonState.Inactive)!=0) {
3124                                 dfcs |= DrawFrameControlStates.Inactive;
3125                         }
3126
3127                         DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
3128
3129                 }
3130
3131                 public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
3132                         Point[]                 arrow = new Point[3];
3133                         Point                           P1;
3134                         Point                           P2;
3135                         Point                           P3;
3136                         int                             centerX;
3137                         int                             centerY;
3138                         int                             shiftX;
3139                         int                             shiftY;
3140                         Rectangle               rect;
3141
3142                         if ((state & ButtonState.Checked)!=0) {
3143                                 graphics.FillRectangle(ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight),rectangle);                           
3144                         }
3145
3146                         if ((state & ButtonState.Flat)!=0) {
3147                                 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3148                         } else {
3149                                 if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
3150                                         CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3151                                 } else {
3152                                         CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3153                                 }
3154                         }
3155
3156                         rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
3157                         centerX=rect.Left+rect.Width/2;
3158                         centerY=rect.Top+rect.Height/2;
3159                         shiftX=Math.Max(1, rect.Width/8);
3160                         shiftY=Math.Max(1, rect.Height/8);
3161
3162                         if ((state & ButtonState.Pushed)!=0) {
3163                                 shiftX++;
3164                                 shiftY++;
3165                         }
3166
3167                         rect.Y-=shiftY;
3168                         centerY-=shiftY;
3169                         P1=new Point(rect.Left, centerY);
3170                         P2=new Point(rect.Right, centerY);
3171                         P3=new Point(centerX, rect.Bottom);
3172
3173                         arrow[0]=P1;
3174                         arrow[1]=P2;
3175                         arrow[2]=P3;
3176
3177                         /* Draw the arrow */
3178                         if ((state & ButtonState.Inactive)!=0) {
3179                                 graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
3180
3181                                 /* Move away from the shadow */
3182                                 P1.X-=1;                P1.Y-=1;
3183                                 P2.X-=1;                P2.Y-=1;
3184                                 P3.X-=1;                P3.Y-=1;
3185
3186                                 arrow[0]=P1;
3187                                 arrow[1]=P2;
3188                                 arrow[2]=P3;
3189
3190
3191                                 graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
3192                         } else {
3193                                 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
3194                         }
3195                 }
3196
3197
3198                 public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
3199                         
3200                         Pen                     pen     = new Pen(Color.Black, 1);
3201                         Rectangle       rect    = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1);   // Dunno why, but MS does it that way, too
3202                         int                     X;
3203                         int                     Y;
3204
3205                         graphics.FillRectangle(ResPool.GetSolidBrush (ColorButtonText), rect);
3206                         graphics.DrawRectangle(pen, rect);
3207
3208                         X=rect.X+rect.Width/2;
3209                         Y=rect.Y+rect.Height/2;
3210
3211                         /* Draw the cross */
3212                         graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
3213                         graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
3214
3215                         /* Draw 'arrows' for vertical lines */
3216                         graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
3217                         graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
3218
3219                         /* Draw 'arrows' for horizontal lines */
3220                         graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
3221                         graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
3222
3223                 }
3224
3225                 public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
3226                         // make a rectange to trace around border of the button
3227                         Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3228                         
3229                         Color outerColor = foreColor;
3230                         // adjust focus color according to the flatstyle
3231                         if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
3232                                 outerColor = (backColor == ColorButtonFace) ? ControlPaint.Dark(ColorButtonFace) : ColorButtonText;                             
3233                         }
3234                         
3235                         // draw the outer rectangle
3236                         graphics.DrawRectangle (ResPool.GetPen (outerColor), trace_rectangle);                  
3237                         
3238                         // draw the inner rectangle                                             
3239                         if (button.FlatStyle == FlatStyle.Popup) {
3240                                 DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
3241                         } else {
3242                                 // draw a flat inner rectangle
3243                                 Pen pen = ResPool.GetPen (ControlPaint.LightLight (backColor));
3244                                 graphics.DrawRectangle(pen, Rectangle.Inflate (trace_rectangle, -4, -4));                               
3245                         }
3246                 }
3247                 
3248                 public virtual void DrawInnerFocusRectangle(Graphics graphics, Rectangle rectangle, Color backColor)
3249                 {       
3250                         // make a rectange to trace around border of the button
3251                         Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3252                         
3253                         Color colorBackInverted = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
3254                         DashStyle oldStyle; // used for caching old penstyle
3255                         Pen pen = ResPool.GetPen (colorBackInverted);
3256                         
3257                         oldStyle = pen.DashStyle; 
3258                         pen.DashStyle = DashStyle.Dot;
3259                         graphics.DrawRectangle (pen, trace_rectangle);
3260                         pen.DashStyle = oldStyle;
3261                 }
3262                                 
3263
3264                 public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
3265                         // make a rectange to trace around border of the button
3266                         Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3267                         
3268                         //Color                 colorForeInverted;
3269                         Pen                     pen;
3270
3271                         //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
3272                         //pen=new Pen(colorForeInverted, 1);
3273                         // MS seems to always use black
3274                         pen = ResPool.GetPen (Color.Black);
3275                         graphics.DrawRectangle(pen, trace_rectangle);
3276                         
3277                         DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
3278                 }
3279                 
3280                 public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
3281                         SolidBrush      sb;
3282                         Pen                     pen;
3283
3284                         if (primary==true) {
3285                                 pen=new Pen(Color.Black, 1);
3286                                 if (enabled==true) {
3287                                         sb=ResPool.GetSolidBrush (ColorButtonText);
3288                                 } else {
3289                                         sb=ResPool.GetSolidBrush (ColorButtonFace);
3290                                 }
3291                         } else {
3292                                 pen=new Pen(Color.White, 1);
3293                                 if (enabled==true) {
3294                                         sb=new SolidBrush(Color.Black);
3295                                 } else {
3296                                         sb=ResPool.GetSolidBrush (ColorButtonFace);
3297                                 }
3298                         }
3299                         graphics.FillRectangle(sb, rectangle);
3300                         graphics.DrawRectangle(pen, rectangle);                 
3301                         pen.Dispose();
3302                 }
3303
3304
3305                 public override void CPDrawGrid (Graphics graphics, Rectangle area, Size pixelsBetweenDots, Color backColor) {
3306                         Color   foreColor;
3307                         int     h;
3308                         int     b;
3309                         int     s;
3310
3311                         ControlPaint.Color2HBS(backColor, out h, out b, out s);
3312
3313                         if (b>127) {
3314                                 foreColor=Color.Black;
3315                         } else {
3316                                 foreColor=Color.White;
3317                         }
3318
3319 #if false
3320                         /* Commented out until I take the time and figure out
3321                                 which HatchStyle will match requirements. The code below
3322                                 is only correct for Percent50.
3323                         */
3324                         if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
3325                                 HatchBrush      brush=null;
3326
3327                                 switch(pixelsBetweenDots.Width) {
3328                                         case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
3329                                         case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
3330                                         case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
3331                                         default: {
3332                                                 /* Have to do it the slow way */
3333                                                 break;
3334                                         }
3335                                 }
3336                                 if (brush!=null) {
3337                                         graphics.FillRectangle(brush, area);
3338                                         pen.Dispose();
3339                                         brush.Dispose();
3340                                         return;
3341                                 }
3342                         }
3343 #endif
3344                         /* Slow method */
3345
3346                         Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
3347
3348                         for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
3349                                 for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
3350                                         bitmap.SetPixel(x, y, foreColor);
3351                                 }
3352                         }
3353                         graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
3354                         bitmap.Dispose();
3355                 }
3356
3357                 public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
3358                         /*
3359                                 Microsoft seems to ignore the background and simply make
3360                                 the image grayscale. At least when having > 256 colors on
3361                                 the display.
3362                         */
3363
3364                         ImageAttributes imageAttributes=new ImageAttributes();
3365                         ColorMatrix                     colorMatrix=new ColorMatrix(new float[][] {
3366                                                                                                           // This table would create a perfect grayscale image, based on luminance
3367                                                                                                           //                            new float[]{0.3f,0.3f,0.3f,0,0},
3368                                                                                                           //                            new float[]{0.59f,0.59f,0.59f,0,0},
3369                                                                                                           //                            new float[]{0.11f,0.11f,0.11f,0,0},
3370                                                                                                           //                            new float[]{0,0,0,1,0,0},
3371                                                                                                           //                            new float[]{0,0,0,0,1,0},
3372                                                                                                           //                            new float[]{0,0,0,0,0,1}
3373
3374                                                                                                           // This table generates a image that is grayscaled and then
3375                                                                                                           // brightened up. Seems to match MS close enough.
3376                                                                                                           new float[]{0.2f,0.2f,0.2f,0,0},
3377                                                                                                           new float[]{0.41f,0.41f,0.41f,0,0},
3378                                                                                                           new float[]{0.11f,0.11f,0.11f,0,0},
3379                                                                                                           new float[]{0.15f,0.15f,0.15f,1,0,0},
3380                                                                                                           new float[]{0.15f,0.15f,0.15f,0,1,0},
3381                                                                                                           new float[]{0.15f,0.15f,0.15f,0,0,1}
3382                                                                                                   });
3383
3384                         imageAttributes.SetColorMatrix(colorMatrix);
3385                         graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
3386                         imageAttributes.Dispose();
3387                 }
3388
3389
3390                 public override void CPDrawLockedFrame (Graphics graphics, Rectangle rectangle, bool primary) {
3391                         Pen     penBorder;
3392                         Pen     penInside;
3393
3394                         if (primary) {
3395                                 penBorder=new Pen(Color.White, 2);
3396                                 penInside=new Pen(Color.Black, 1);
3397                         } else {
3398                                 penBorder=new Pen(Color.Black, 2);
3399                                 penInside=new Pen(Color.White, 1);
3400                         }
3401                         penBorder.Alignment=PenAlignment.Inset;
3402                         penInside.Alignment=PenAlignment.Inset;
3403
3404                         graphics.DrawRectangle(penBorder, rectangle);
3405                         graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
3406                         penBorder.Dispose();
3407                         penInside.Dispose();
3408                 }
3409
3410
3411                 public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
3412                         Rectangle       rect;
3413                         int                     lineWidth;
3414
3415                         // MS draws always the background white
3416                         graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
3417
3418                         switch(glyph) {
3419                         case MenuGlyph.Arrow: {
3420                                 Point[]                 arrow = new Point[3];
3421                                 Point                           P1;
3422                                 Point                           P2;
3423                                 Point                           P3;
3424                                 int                             centerX;
3425                                 int                             centerY;
3426                                 int                             shiftX;
3427                                 int                             shiftY;
3428
3429                                 rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
3430                                 centerX=rect.Left+rect.Width/2;
3431                                 centerY=rect.Top+rect.Height/2;
3432                                 shiftX=Math.Max(1, rect.Width/8);
3433                                 shiftY=Math.Max(1, rect.Height/8);
3434
3435                                 rect.X-=shiftX;
3436                                 centerX-=shiftX;
3437
3438                                 P1=new Point(centerX, rect.Top-1);
3439                                 P2=new Point(centerX, rect.Bottom);
3440                                 P3=new Point(rect.Right, centerY);
3441
3442                                 arrow[0]=P1;
3443                                 arrow[1]=P2;
3444                                 arrow[2]=P3;
3445
3446                                 graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
3447
3448                                 return;
3449                         }
3450
3451                         case MenuGlyph.Bullet: {
3452                                 
3453                                 lineWidth=Math.Max(2, rectangle.Width/3);
3454                                 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
3455                                 
3456                                 graphics.FillEllipse(ResPool.GetSolidBrush (ColorButtonText), rect);
3457                                 
3458                                 return;
3459                         }
3460
3461                         case MenuGlyph.Checkmark: {
3462                                 int                     Scale;
3463
3464                                 lineWidth=Math.Max(2, rectangle.Width/6);
3465                                 Scale=Math.Max(1, rectangle.Width/12);
3466
3467                                 rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
3468
3469                                 for (int i=0; i<lineWidth; i++) {
3470                                         graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
3471                                         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);
3472                                 }
3473                                 return;
3474                         }
3475                         }
3476
3477                 }
3478
3479                 public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
3480                         DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonRadio;
3481
3482                         if ((state & ButtonState.Pushed)!=0) {
3483                                 dfcs |= DrawFrameControlStates.Pushed;
3484                         }
3485
3486                         if ((state & ButtonState.Checked)!=0) {
3487                                 dfcs |= DrawFrameControlStates.Checked;
3488                         }
3489
3490                         if ((state & ButtonState.Flat)!=0) {
3491                                 dfcs |= DrawFrameControlStates.Flat;
3492                         }
3493
3494                         if ((state & ButtonState.Inactive)!=0) {
3495                                 dfcs |= DrawFrameControlStates.Inactive;
3496                         }
3497                         DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
3498
3499                 }
3500
3501
3502                 public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
3503
3504                 }
3505
3506
3507                 public override void CPDrawReversibleLine (Point start, Point end, Color backColor) {
3508
3509                 }
3510
3511
3512                 /* Scroll button: regular button + direction arrow */
3513                 public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
3514                         bool enabled = (state == ButtonState.Inactive) ? false: true;                   
3515                                         
3516                         DrawScrollButtonPrimitive (dc, area, state);
3517
3518                         /* Paint arrows */
3519                         switch (type) {
3520                         case ScrollButton.Up: {
3521                                 int x = area.X +  (area.Width / 2) - 4;
3522                                 int y = area.Y + 9;
3523
3524                                 for (int i = 0; i < 3; i++)
3525                                         if (enabled)
3526                                                 dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
3527                                         else
3528                                                 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
3529
3530                                 
3531                                 dc.FillRectangle (br_arrow, x + 3, area.Y + 6, 1, 1);                           
3532                                 break;
3533                         }
3534                         case ScrollButton.Down: {
3535                                 int x = area.X +  (area.Width / 2) - 4;
3536                                 int y = area.Y + 5;
3537
3538                                 for (int i = 4; i != 0; i--)
3539                                         if (enabled)
3540                                                 dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
3541                                         else
3542                                                 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
3543
3544                                 
3545                                 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);
3546                                 break;
3547                         }
3548
3549                         case ScrollButton.Left: {
3550                                 int y = area.Y +  (area.Height / 2) - 4;
3551                                 int x = area.X + 9;
3552
3553                                 for (int i = 0; i < 3; i++)
3554                                         if (enabled)
3555                                                 dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
3556                                         else
3557                                                 dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
3558
3559                                 dc.FillRectangle (br_arrow, x - 3, y + 3, 1, 1);
3560                                 break;
3561                         }
3562
3563                         case ScrollButton.Right: {
3564                                 int y = area.Y +  (area.Height / 2) - 4;
3565                                 int x = area.X + 5;
3566
3567                                 for (int i = 4; i != 0; i--)
3568                                         if (enabled)
3569                                                 dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
3570                                         else
3571                                                 dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
3572
3573                                 dc.FillRectangle (br_arrow, x + 4, y + 4, 1, 1);                                
3574                                 break;
3575                         }
3576
3577                         default:
3578                                 break;
3579
3580                         }
3581                 }
3582
3583
3584                 public  override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
3585                         Color backColor) {
3586
3587                 }
3588
3589
3590                 public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
3591                         Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
3592
3593                         dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X - 12, pt.Y, pt.X, pt.Y);
3594                         dc.DrawLine (ResPool.GetPen (ColorButtonFace), pt.X, pt.Y, pt.X, pt.Y - 13);
3595
3596                         // diagonals
3597                         for (int i = 0; i < 11; i += 4) {
3598                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
3599                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
3600                         }
3601
3602                         for (int i = 3; i < 13; i += 4)
3603                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
3604                 }
3605
3606
3607                 public  override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
3608                         StringFormat format) {
3609                         SolidBrush      brush;
3610
3611                         brush=new SolidBrush(ControlPaint.Light(color, 95));
3612
3613                         layoutRectangle.Offset(1.0f, 1.0f);
3614                         graphics.DrawString(s, font, brush, layoutRectangle, format);
3615
3616                         brush.Color=ControlPaint.Light(color, 50);
3617                         layoutRectangle.Offset(-1.0f, -1.0f);
3618                         graphics.DrawString(s, font, brush, layoutRectangle, format);
3619
3620                         brush.Dispose();
3621                 }
3622
3623                 private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
3624                         int width, Color color, ButtonBorderStyle style, Border3DSide side) {
3625
3626                         Pen     pen=new Pen(color, 1);
3627
3628                         switch(style) {
3629                         case ButtonBorderStyle.Solid: {
3630                                 pen.DashStyle=DashStyle.Solid;
3631                                 break;
3632                         }
3633
3634                         case ButtonBorderStyle.Dashed: {
3635                                 pen.DashStyle=DashStyle.Dash;
3636                                 break;
3637                         }
3638
3639                         case ButtonBorderStyle.Dotted: {
3640                                 pen.DashStyle=DashStyle.Dot;
3641                                 break;
3642                         }
3643
3644                         case ButtonBorderStyle.Inset: {
3645                                 pen.DashStyle=DashStyle.Solid;
3646                                 break;
3647                         }
3648
3649                         case ButtonBorderStyle.Outset: {
3650                                 pen.DashStyle=DashStyle.Solid;
3651                                 break;
3652                         }
3653
3654                         default:
3655                         case ButtonBorderStyle.None: {
3656                                 pen.Dispose();
3657                                 return;
3658                         }
3659                         }
3660
3661
3662                         switch(style) {
3663                         case ButtonBorderStyle.Outset: {
3664                                 Color           colorGrade;
3665                                 int             hue, brightness, saturation;
3666                                 int             brightnessSteps;
3667                                 int             brightnessDownSteps;
3668
3669                                 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
3670
3671                                 brightnessDownSteps=brightness/width;
3672                                 if (brightness>127) {
3673                                         brightnessSteps=Math.Max(6, (160-brightness)/width);
3674                                 } else {
3675                                         brightnessSteps=(127-brightness)/width;
3676                                 }
3677
3678                                 for (int i=0; i<width; i++) {
3679                                         switch(side) {
3680                                         case Border3DSide.Left: {
3681                                                 pen.Dispose();
3682                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3683                                                 pen=new Pen(colorGrade, 1);
3684                                                 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3685                                                 break;
3686                                         }
3687
3688                                         case Border3DSide.Right: {
3689                                                 pen.Dispose();
3690                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3691                                                 pen=new Pen(colorGrade, 1);
3692                                                 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3693                                                 break;
3694                                         }
3695
3696                                         case Border3DSide.Top: {
3697                                                 pen.Dispose();
3698                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3699                                                 pen=new Pen(colorGrade, 1);
3700                                                 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3701                                                 break;
3702                                         }
3703
3704                                         case Border3DSide.Bottom: {
3705                                                 pen.Dispose();
3706                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3707                                                 pen=new Pen(colorGrade, 1);
3708                                                 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3709                                                 break;
3710                                         }
3711                                         }
3712                                 }
3713                                 break;
3714                         }
3715
3716                         case ButtonBorderStyle.Inset: {
3717                                 Color           colorGrade;
3718                                 int             hue, brightness, saturation;
3719                                 int             brightnessSteps;
3720                                 int             brightnessDownSteps;
3721
3722                                 ControlPaint.Color2HBS(color, out hue, out brightness, out saturation);
3723
3724                                 brightnessDownSteps=brightness/width;
3725                                 if (brightness>127) {
3726                                         brightnessSteps=Math.Max(6, (160-brightness)/width);
3727                                 } else {
3728                                         brightnessSteps=(127-brightness)/width;
3729                                 }
3730
3731                                 for (int i=0; i<width; i++) {
3732                                         switch(side) {
3733                                         case Border3DSide.Left: {
3734                                                 pen.Dispose();
3735                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3736                                                 pen=new Pen(colorGrade, 1);
3737                                                 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3738                                                 break;
3739                                         }
3740
3741                                         case Border3DSide.Right: {
3742                                                 pen.Dispose();
3743                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3744                                                 pen=new Pen(colorGrade, 1);
3745                                                 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3746                                                 break;
3747                                         }
3748
3749                                         case Border3DSide.Top: {
3750                                                 pen.Dispose();
3751                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
3752                                                 pen=new Pen(colorGrade, 1);
3753                                                 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3754                                                 break;
3755                                         }
3756
3757                                         case Border3DSide.Bottom: {
3758                                                 pen.Dispose();
3759                                                 colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
3760                                                 pen=new Pen(colorGrade, 1);
3761                                                 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3762                                                 break;
3763                                         }
3764                                         }
3765                                 }
3766                                 break;
3767                         }
3768
3769                                 /*
3770                                         I decided to have the for-loop duplicated for speed reasons;
3771                                         that way we only have to switch once (as opposed to have the
3772                                         for-loop around the switch)
3773                                 */
3774                         default: {
3775                                 switch(side) {
3776                                 case Border3DSide.Left: {
3777                                         for (int i=0; i<width; i++) {
3778                                                 graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
3779                                         }
3780                                         break;
3781                                 }
3782
3783                                 case Border3DSide.Right: {
3784                                         for (int i=0; i<width; i++) {
3785                                                 graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
3786                                         }
3787                                         break;
3788                                 }
3789
3790                                 case Border3DSide.Top: {
3791                                         for (int i=0; i<width; i++) {
3792                                                 graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
3793                                         }
3794                                         break;
3795                                 }
3796
3797                                 case Border3DSide.Bottom: {
3798                                         for (int i=0; i<width; i++) {
3799                                                 graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
3800                                         }
3801                                         break;
3802                                 }
3803                                 }
3804                                 break;
3805                         }
3806                         }
3807                         pen.Dispose();
3808                 }
3809
3810                 /*
3811                         This function actually draws the various caption elements.
3812                         This way we can scale them nicely, no matter what size, and they
3813                         still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
3814                 */
3815
3816                 private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
3817                         switch(button) {
3818                         case CaptionButton.Close: {
3819                                 pen.StartCap=LineCap.Triangle;
3820                                 pen.EndCap=LineCap.Triangle;
3821                                 if (lineWidth<2) {
3822                                         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);
3823                                         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);
3824                                 }
3825
3826                                 graphics.DrawLine(pen, captionRect.Left+2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3827                                 graphics.DrawLine(pen, captionRect.Right-2*lineWidth+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+shift, captionRect.Bottom-2*lineWidth+shift);
3828                                 return;
3829                         }
3830
3831                         case CaptionButton.Help: {
3832                                 StringFormat    sf = new StringFormat();
3833                                 SolidBrush              sb = new SolidBrush(color);
3834                                 Font                            font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
3835
3836                                 sf.Alignment=StringAlignment.Center;
3837                                 sf.LineAlignment=StringAlignment.Center;
3838
3839
3840                                 graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
3841
3842                                 sf.Dispose();
3843                                 sb.Dispose();
3844                                 font.Dispose();
3845
3846                                 return;
3847                         }
3848
3849                         case CaptionButton.Maximize: {
3850                                 /* Top 'caption bar' line */
3851                                 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3852                                         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);
3853                                 }
3854
3855                                 /* Left side line */
3856                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3857                                         graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+2*lineWidth+shift, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3858                                 }
3859
3860                                 /* Right side line */
3861                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3862                                         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);
3863                                 }
3864
3865                                 /* Bottom line */
3866                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3867                                         graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3868                                 }
3869                                 return;
3870                         }
3871
3872                         case CaptionButton.Minimize: {
3873                                 /* Bottom line */
3874                                 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3875                                         graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth+shift, captionRect.Bottom-lineWidth+shift-i);
3876                                 }
3877                                 return;
3878                         }
3879
3880                         case CaptionButton.Restore: {
3881                                 /** First 'window' **/
3882                                 /* Top 'caption bar' line */
3883                                 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3884                                         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);
3885                                 }
3886
3887                                 /* Left side line */
3888                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3889                                         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);
3890                                 }
3891
3892                                 /* Right side line */
3893                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3894                                         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);
3895                                 }
3896
3897                                 /* Bottom line */
3898                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3899                                         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);
3900                                 }
3901
3902                                 /** Second 'window' **/
3903                                 /* Top 'caption bar' line */
3904                                 for (int i=0; i<Math.Max(2, lineWidth); i++) {
3905                                         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);
3906                                 }
3907
3908                                 /* Left side line */
3909                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3910                                         graphics.DrawLine(pen, captionRect.Left+lineWidth+shift+i, captionRect.Top+4*lineWidth+shift+1, captionRect.Left+lineWidth+shift+i, captionRect.Bottom-lineWidth+shift);
3911                                 }
3912
3913                                 /* Right side line */
3914                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3915                                         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);
3916                                 }
3917
3918                                 /* Bottom line */
3919                                 for (int i=0; i<Math.Max(1, lineWidth/2); i++) {
3920                                         graphics.DrawLine(pen, captionRect.Left+lineWidth+shift, captionRect.Bottom-lineWidth+shift-i, captionRect.Right-3*lineWidth-lineWidth/2+shift, captionRect.Bottom-lineWidth+shift-i);
3921                                 }
3922
3923                                 return;
3924                         }
3925
3926                         }
3927                 }
3928
3929                 [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
3930                 private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
3931                         // make a rectange to trace around border of the button
3932                         Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
3933                         switch(Type) {
3934                         case DrawFrameControlTypes.Button: {
3935
3936                                 if ((State & DrawFrameControlStates.ButtonPush)!=0) {
3937 // JBA 31 oct 2004 - I don't think that button style should be rendered like this
3938 //                                      /* Goes first, affects the background */
3939 //                                      if ((State & DrawFrameControlStates.Checked)!=0) {
3940 //                                              HatchBrush      hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorButtonLight, ColorButtonHilight);
3941 //                                              graphics.FillRectangle(hatchBrush,rectangle);
3942 //                                              hatchBrush.Dispose();
3943 //                                      }
3944
3945                                         if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
3946                                                 graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
3947                                         } else if ((State & DrawFrameControlStates.Flat)!=0) {
3948                                                 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
3949                                         } else if ((State & DrawFrameControlStates.Inactive)!=0) {
3950                                                 /* Same as normal, it would seem */
3951                                                 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3952                                         } else {
3953                                                 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
3954                                         }
3955                                 } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
3956                                         Pen                     penFatDark      = new Pen(ColorButtonShadow, 1);
3957                                         Pen                     penFatLight     = new Pen(ColorButtonLight, 1);
3958                                         int                     lineWidth;
3959
3960                                         graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3961
3962                                         graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
3963                                         graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
3964
3965                                         graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
3966                                         graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
3967
3968                                         lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
3969
3970                                         if ((State & DrawFrameControlStates.Checked)!=0) {
3971                                                 SolidBrush      buttonBrush;
3972
3973                                                 if ((State & DrawFrameControlStates.Inactive)!=0) {
3974                                                         buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
3975                                                 } else {
3976                                                         buttonBrush=(SolidBrush)SystemBrushes.ControlText;
3977                                                 }
3978                                                 graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
3979                                         }
3980                                         penFatDark.Dispose();
3981                                         penFatLight.Dispose();
3982                                 } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
3983                                         throw new NotImplementedException () ;
3984                                 } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
3985                                         throw new NotImplementedException ();
3986                                 } else {        /* Must be Checkbox */
3987                                         Pen                     pen;
3988                                         int                     lineWidth;
3989                                         Rectangle       rect;
3990                                         int                     Scale;
3991
3992                                         /* Goes first, affects the background */
3993                                         if ((State & DrawFrameControlStates.Pushed)!=0 ||
3994                                                 (State & DrawFrameControlStates.Inactive)!=0) {
3995                                                 graphics.FillRectangle(SystemBrushes.Control, rectangle);
3996                                         } else {
3997                                                 graphics.FillRectangle(SystemBrushes.Window, rectangle);
3998                                         }
3999
4000                                         /* Draw the sunken frame */
4001                                         if ((State & DrawFrameControlStates.Flat)!=0) {
4002                                                 ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
4003                                         } else {
4004                                                 CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
4005                                         }
4006
4007                                         /* Make sure we've got at least a line width of 1 */
4008                                         lineWidth=Math.Max(3, rectangle.Width/6);
4009                                         Scale=Math.Max(1, rectangle.Width/12);
4010
4011                                         // define a rectangle inside the border area
4012                                         rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
4013                                         if ((State & DrawFrameControlStates.Inactive)!=0) {
4014                                                 pen=SystemPens.ControlDark;
4015                                         } else {
4016                                                 pen=SystemPens.ControlText;
4017                                         }
4018
4019                                         if ((State & DrawFrameControlStates.Checked)!=0) {
4020                                                 /* Need to draw a check-mark */
4021                                                 for (int i=0; i<lineWidth; i++) {
4022                                                         graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
4023                                                         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);
4024                                                 }
4025
4026                                         }
4027                                 }
4028                                 return;
4029                         }
4030
4031                         case DrawFrameControlTypes.Caption: {
4032                                 // FIXME:
4033                                 break;
4034                         }
4035
4036                         case DrawFrameControlTypes.Menu: {
4037                                 // FIXME:
4038                                 break;
4039                         }
4040
4041                         case DrawFrameControlTypes.Scroll: {
4042                                 // FIXME:
4043                                 break;
4044                         }
4045                         }
4046                 }
4047
4048                 /* Generic scroll button */
4049                 public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
4050                         if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
4051                                 dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 1,
4052                                         area.Y + 1, area.Width - 2 , area.Height - 2);
4053
4054                                 dc.DrawRectangle (ResPool.GetPen (ColorButtonShadow), area.X,
4055                                         area.Y, area.Width, area.Height);
4056
4057                                 return;
4058                         }                       
4059
4060                         dc.FillRectangle (new SolidBrush (Color.Blue), area);
4061                         
4062                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
4063                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
4064
4065                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 1, area.Width - 1, 1);
4066                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonHilight), area.X + 1, area.Y + 2, 1,
4067                                 area.Height - 4);
4068
4069                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + 1, area.Y + area.Height - 2,
4070                                 area.Width - 2, 1);
4071
4072                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X, area.Y + area.Height -1,
4073                                 area.Width , 1);
4074
4075                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonShadow), area.X + area.Width - 2,
4076                                 area.Y + 1, 1, area.Height -3);
4077
4078                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonDkShadow), area.X + area.Width -1,
4079                                 area.Y, 1, area.Height - 1);
4080
4081                         dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X + 2,
4082                                 area.Y + 2, area.Width - 4, area.Height - 4);
4083                         
4084                 }
4085                 
4086                 public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
4087                         switch (border_style){
4088                         case BorderStyle.Fixed3D:                               
4089                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
4090                                 dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
4091                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width , 
4092                                         area.Y + area.Height - 1);
4093                                 dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1, 
4094                                         area.Y + area.Height);
4095                                 break;
4096                         case BorderStyle.FixedSingle:
4097                                 dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);
4098                                 break;
4099                         case BorderStyle.None:
4100                         default:
4101                                 break;
4102                         }
4103                         
4104                 }
4105                 #endregion      // ControlPaint
4106
4107
4108         } //class
4109 }