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