* XplatUIX11.cs: Removed unused hwnd var in SetBorderStyle.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeClearlooks.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) 2006 Alexander Olk
21 //
22 // Authors:
23 //      Alexander Olk, alex.olk@googlemail.com
24 //
25 //      based on ThemeWin32Classic
26 //
27 //              - You can activate this Theme with export MONO_THEME=clearlooks
28 //
29 // This theme tries to match clearlooks theme
30 //
31 // TODO:        
32 //      - if an other control draws over a ScrollBar button you can see artefacts on the rounded edges 
33 //        (maybe use theme backcolor, but that looks ugly on a white background, need to find a way to get the backcolor of the parent control)
34 //      - more correct drawing of disabled controls
35
36 using System.Drawing;
37 using System.Drawing.Drawing2D;
38 using System.Drawing.Imaging;
39 using System.Drawing.Text;
40
41 namespace System.Windows.Forms {
42         internal class ThemeClearlooks : ThemeWin32Classic {
43                 public override Version Version {
44                         get {
45                                 return new Version( 0, 0, 0, 2 );
46                         }
47                 }
48                 
49                 static readonly Color theme_back_color = Color.FromArgb( 239, 235, 231 );
50                 
51                 static readonly Color gradient_first_color = Color.FromArgb( 250, 248, 247 );
52                 static readonly Color gradient_second_color = Color.FromArgb( 226, 219, 212 );
53                 static readonly Color gradient_second_color_nr2 = Color.FromArgb( 234, 229, 224 );
54                 static readonly Color pressed_gradient_first_color = Color.FromArgb( 217, 207, 202 );
55                 static readonly Color pressed_gradient_second_color = Color.FromArgb( 199, 193, 187 );
56                 static readonly Color border_normal_dark_color = Color.FromArgb( 129, 117, 106 );
57                 static readonly Color border_normal_light_color = Color.FromArgb( 158, 145, 131 );
58                 static readonly Color border_pressed_dark_color = Color.FromArgb( 109, 103, 98 );
59                 static readonly Color border_pressed_light_color = Color.FromArgb( 120, 114, 107 );
60                 static readonly Color button_outer_border_dark_color = Color.FromArgb( 232, 226, 220 );
61                 static readonly Color button_outer_border_light_color = Color.FromArgb( 250, 248, 247 ); 
62                 static readonly Color inner_border_dark_color = Color.FromArgb( 226, 219, 212 );
63                 static readonly Color pressed_inner_border_dark_color = Color.FromArgb( 192, 181, 169 );
64                 static readonly Color edge_top_inner_color = Color.FromArgb( 206, 200, 194 );
65                 static readonly Color edge_bottom_inner_color = Color.FromArgb( 215, 209, 202 );
66                 static readonly Color button_edge_top_outer_color = Color.FromArgb( 237, 233, 228 );
67                 static readonly Color button_edge_bottom_outer_color = Color.FromArgb( 243, 239, 236 );
68                 static readonly Color button_focus_color = Color.FromArgb( 101, 94, 86 );
69                 static readonly Color button_mouse_entered_second_gradient_color = Color.FromArgb( 230, 226, 219 );
70                 
71                 static readonly Color scrollbar_background_color = Color.FromArgb( 209, 200, 191 );
72                 static readonly Color scrollbar_border_color = Color.FromArgb( 170, 156, 143 );
73                 static readonly Color scrollbar_gradient_first_color = Color.FromArgb( 248, 247, 245 );
74                 static readonly Color scrollbar_gradient_second_color = Color.FromArgb( 234, 229, 224 );
75                 
76                 new static readonly Color arrow_color = Color.FromArgb( 16, 16, 16 );
77                 
78                 static readonly Color tab_border_color = Color.FromArgb( 166, 151, 138 );
79                 static readonly Color tab_not_selected_gradient_first_color = Color.FromArgb( 227, 223, 220 );
80                 static readonly Color tab_not_selected_gradient_second_color = Color.FromArgb( 214, 209, 204 );
81                 static readonly Color tab_selected_gradient_first_color = Color.FromArgb( 243, 239, 236 );
82                 static readonly Color tab_selected_gradient_second_color = Color.FromArgb( 234, 228, 223 );
83                 static readonly Color tab_edge_color = Color.FromArgb( 200, 196, 191 );
84                 static readonly Color tab_inner_border_color = Color.FromArgb( 221, 212, 205 );
85                 static readonly Color tab_top_border_focus_color = Color.FromArgb( 70, 91, 110 );
86                 static readonly Color tab_focus_color = Color.FromArgb( 105, 147, 185 );
87                 
88                 static readonly Color menuitem_gradient_first_color = Color.FromArgb( 98, 140, 178 );
89                 static readonly Color menuitem_gradient_second_color = Color.FromArgb( 81, 113, 142 );
90                 static readonly Color menuitem_border_color = Color.FromArgb( 80, 112, 141 );
91                 static readonly Color menu_separator_color = Color.FromArgb( 219, 211, 203 );
92                 static readonly Color menu_background_color = Color.FromArgb( 248, 245, 242 );
93                 static readonly Color menu_border_color = Color.FromArgb( 141, 122, 104 );
94                 static readonly Color menu_inner_border_color = Color.FromArgb( 236, 228, 221 );
95                 
96                 static readonly Color combobox_border_color = Color.FromArgb( 159, 146, 132 );
97                 static readonly Color combobox_focus_border_color = Color.FromArgb( 70, 91, 110 );
98                 //static readonly Color combobox_focus_inner_border_color = Color.FromArgb( 167, 198, 225 );
99                 static readonly Color combobox_button_second_gradient_color = Color.FromArgb( 226, 220, 213 );
100                 
101                 static readonly Color progressbar_edge_dot_color = Color.FromArgb( 219, 212, 205 );
102                 static readonly Color progressbar_inner_border_color = Color.FromArgb( 139, 176, 209 );
103                 static readonly Color progressbar_first_gradient_color = Color.FromArgb( 104, 146, 184 );
104                 static readonly Color progressbar_second_gradient_color = Color.FromArgb( 91, 133, 172 );
105                 
106                 static readonly Color checkbox_inner_boder_color = Color.FromArgb( 237, 234, 231 );
107                 static readonly Color checkbox_pressed_inner_boder_color = Color.FromArgb( 203, 196, 189 );
108                 static readonly Color checkbox_pressed_backcolor = Color.FromArgb( 212, 207, 202 );
109                 
110                 static readonly Color trackbar_second_gradient_color = Color.FromArgb( 114, 154, 190 );
111                 static readonly Color trackbar_third_gradient_color = Color.FromArgb( 130, 168, 202 );
112                 static readonly Color trackbar_inner_first_gradient_color = Color.FromArgb( 238, 233, 229 );
113                 static readonly Color trackbar_inner_second_gradient_color = Color.FromArgb( 223, 215, 208 );
114                 static readonly Color trackbar_inner_pressed_second_gradient_color = Color.FromArgb( 224, 217, 210 );
115                 
116                 //static readonly Color disabled_color_foreground = Color.FromArgb( 182, 180, 173 );
117                 
118                 static readonly Color active_caption = Color.FromArgb( 85, 152, 215 );
119                 
120                 static readonly Color radio_button_border_circle_color = Color.FromArgb( 126, 118, 105 );
121                 static readonly Color radio_button_dot_color = Color.FromArgb( 94, 160, 221 );
122                 
123                 const int SEPARATOR_HEIGHT = 7;
124                 const int MENU_TAB_SPACE = 8;           // Pixels added to the width of an item because of a tab
125                 const int MENU_BAR_ITEMS_SPACE = 8;     // Space between menu bar items
126                 
127                 int platform = (int) Environment.OSVersion.Platform;
128                 
129                 static Color control_parent_backcolor;
130                 
131                 #region Principal Theme Methods
132                 public ThemeClearlooks( ) {
133                         ColorControl = theme_back_color;
134                         always_draw_hotkeys = true;
135                 }
136                 
137                 public override Color DefaultControlBackColor {
138                         get { return theme_back_color; }
139                 }
140                 
141                 public override Color DefaultWindowBackColor {
142                         get { return theme_back_color; }                        
143                 }
144                 
145                 public override Color ColorControl {
146                         get { return theme_back_color;}
147                 }
148                 
149                 public override Color ColorHighlight {
150                         get { return menuitem_gradient_first_color; }
151                 }
152                 
153                 public override Color ColorActiveCaption {
154                         get { return active_caption; }
155                 }
156                 
157                 public override Size Border3DSize {
158                         get {
159                                 return new Size( 3, 3 );
160                         }
161                 }
162                 
163                 public override Image Images(UIIcon index, int size) {
164                         switch (index) {
165                         case UIIcon.PlacesRecentDocuments:
166                                 if ((platform == 4) || (platform == 128))
167                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "recently/recently", new Size(size, size) );
168                                 else
169                                         return base.Images (UIIcon.PlacesRecentDocuments, size);
170                         case UIIcon.PlacesDesktop:
171                                 if ((platform == 4) || (platform == 128))
172                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "desktop/desktop", new Size(size, size) );
173                                 else
174                                         return base.Images (UIIcon.PlacesDesktop, size);
175                         case UIIcon.PlacesPersonal:
176                                 if ((platform == 4) || (platform == 128))
177                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "directory/home", new Size(size, size) );
178                                 else
179                                         return base.Images (UIIcon.PlacesPersonal, size);
180                         case UIIcon.PlacesMyComputer:
181                                 if ((platform == 4) || (platform == 128))
182                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "workplace/workplace", new Size(size, size) );
183                                 else
184                                         return base.Images (UIIcon.PlacesMyComputer, size);
185                         case UIIcon.PlacesMyNetwork:
186                                 if ((platform == 4) || (platform == 128))
187                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "network/network", new Size(size, size) );
188                                 else
189                                         return base.Images (UIIcon.PlacesMyNetwork, size);
190                                 
191                                 // Icons for message boxes
192                         case UIIcon.MessageBoxError:            return base.Images (UIIcon.MessageBoxError, size);
193                         case UIIcon.MessageBoxInfo:             return base.Images (UIIcon.MessageBoxInfo, size);
194                         case UIIcon.MessageBoxQuestion:         return base.Images (UIIcon.MessageBoxQuestion, size);
195                         case UIIcon.MessageBoxWarning:          return base.Images (UIIcon.MessageBoxWarning, size);
196                                 
197                                 // misc Icons
198                         case UIIcon.NormalFolder:
199                                 if ((platform == 4) || (platform == 128))
200                                         return MimeIconEngine.GetIconForMimeTypeAndSize( "inode/directory", new Size(size, size) );
201                                 else
202                                         return base.Images (UIIcon.NormalFolder, size);
203                                 
204                         default: {
205                                         throw new ArgumentException("Invalid Icon type requested", "index");
206                                 }
207                         }
208                 }
209                 #endregion      // Internal Methods
210                 
211                 #region ButtonBase
212                 protected override void ButtonBase_DrawButton( ButtonBase button, Graphics dc ) {
213                         dc.FillRectangle( ResPool.GetSolidBrush( button.BackColor ), button.ClientRectangle );
214                         
215                         Color first_gradient_color = gradient_first_color;
216                         Color second_gradient_color = gradient_second_color;
217                         
218                         if (((button is CheckBox) && (((CheckBox)button).check_state == CheckState.Checked)) ||
219                             ((button is RadioButton) && (((RadioButton)button).check_state == CheckState.Checked))) {
220                                 first_gradient_color = button.is_entered ? gradient_second_color : pressed_gradient_first_color;
221                                 second_gradient_color = button.is_entered  ? gradient_second_color : pressed_gradient_second_color;
222                         } else
223                         if (!button.is_enabled) {
224                                 button.is_entered = false;
225                         } else
226                         if (button.is_entered) {
227                                 if (!button.is_pressed) {
228                                         first_gradient_color = Color.White;
229                                         second_gradient_color = button_mouse_entered_second_gradient_color;
230                                 } else {
231                                         first_gradient_color = pressed_gradient_first_color;
232                                         second_gradient_color = pressed_gradient_second_color;
233                                 }
234                         }
235                         
236                         bool paint_acceptbutton_black_border = false;
237                         Form form = button.TopLevelControl as Form;
238                         
239                         if (form != null && (form.AcceptButton == button as IButtonControl))
240                                 paint_acceptbutton_black_border = true;
241                         
242                         CL_Draw_Button(dc, button.ClientRectangle, button.FlatStyle,
243                                           button.is_entered, button.is_enabled, button.is_pressed,
244                                           first_gradient_color, second_gradient_color,
245                                           paint_acceptbutton_black_border);
246                 }
247
248                 private void CL_Draw_Button(Graphics dc, Rectangle buttonRectangle, FlatStyle flat_style,
249                                                bool is_entered, bool is_enabled, bool is_pressed,
250                                                Color first_gradient_color, Color second_gradient_color,
251                                                bool paint_acceptbutton_black_border)
252                 {
253                         Rectangle lgbRectangle = new Rectangle (buttonRectangle.X + 3, buttonRectangle.Y + 3,
254                                                                 is_pressed ? buttonRectangle.Width - 5 : buttonRectangle.Width - 6,
255                                                                 buttonRectangle.Height - 6);
256                         
257                         if (flat_style != FlatStyle.Popup || ((flat_style == FlatStyle.Popup) && is_entered)) {
258                                 LinearGradientBrush lgbr;
259                                 if (flat_style == FlatStyle.Flat) {
260                                         lgbr = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
261                                                                        new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
262                                                                        second_gradient_color, first_gradient_color);
263                                 } else {
264                                         lgbr = new LinearGradientBrush  (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
265                                                                         new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
266                                                                         first_gradient_color, second_gradient_color);
267                                 }
268                                 dc.FillRectangle (lgbr, lgbRectangle);
269                                 lgbr.Dispose ();
270                                 
271                                 Point[] points_top = {
272                                         new Point (buttonRectangle.X + 2, buttonRectangle.Y + 2),
273                                         new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
274                                         new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
275                                         new Point (buttonRectangle.Right - 3 , buttonRectangle.Y + 2)
276                                 };
277                                 
278                                 Point[] points_bottom = {
279                                         new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 3),
280                                         new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
281                                         new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
282                                         new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 3)
283                                 };
284                                 
285                                 Point[] points_top_outer = {
286                                         new Point (buttonRectangle.X + 1, buttonRectangle.Y + 1),
287                                         new Point (buttonRectangle.X + 2, buttonRectangle.Y),
288                                         new Point (buttonRectangle.Right - 3, buttonRectangle.Y),
289                                         new Point (buttonRectangle.Right - 2 , buttonRectangle.Y + 1)
290                                 };
291                                 
292                                 Point[] points_bottom_outer = {
293                                         new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 2),
294                                         new Point (buttonRectangle.X + 2, buttonRectangle.Bottom - 1),
295                                         new Point (buttonRectangle.Right - 3, buttonRectangle.Bottom - 1),
296                                         new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 2)
297                                 };
298                                 
299                                 Pen pen = null; 
300                                 
301                                 // normal border
302                                 if (is_enabled) { 
303                                         Color top_color = Color.Black;
304                                         Color bottom_color = Color.Black;
305                                         
306                                         if (!paint_acceptbutton_black_border) {
307                                                 top_color = is_pressed ? border_pressed_dark_color : border_normal_dark_color;
308                                                 bottom_color = is_pressed ? border_pressed_light_color : border_normal_light_color;
309                                         }
310                                         
311                                         pen = ResPool.GetPen (top_color);
312                                         dc.DrawLines (pen, points_top);
313                                         pen = ResPool.GetPen (bottom_color);
314                                         dc.DrawLines (pen, points_bottom);
315                                         
316                                         using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 3),
317                                                                                                     new Point (buttonRectangle.X, buttonRectangle.Bottom - 3),
318                                                                                                     top_color, bottom_color)) {
319                                                 using (Pen lgbrpen = new Pen (lgbr2)) {
320                                                         dc.DrawLine (lgbrpen, buttonRectangle.X + 1, buttonRectangle.Y + 3, buttonRectangle.X + 1, buttonRectangle.Bottom - 3);
321                                                         dc.DrawLine (lgbrpen, buttonRectangle.Right - 2, buttonRectangle.Y + 3, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3);
322                                                 }
323                                         }
324                                 } else {
325                                         Point[] points_button_complete = {
326                                                 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3),
327                                                 new Point (buttonRectangle.X + 3, buttonRectangle.Y + 1),
328                                                 new Point (buttonRectangle.Right - 4, buttonRectangle.Y + 1),
329                                                 new Point (buttonRectangle.Right - 2, buttonRectangle.Y + 3),
330                                                 new Point (buttonRectangle.Right - 2, buttonRectangle.Bottom - 4),
331                                                 new Point (buttonRectangle.Right - 4, buttonRectangle.Bottom - 2),
332                                                 new Point (buttonRectangle.X + 3, buttonRectangle.Bottom - 2),
333                                                 new Point (buttonRectangle.X + 1, buttonRectangle.Bottom - 4),
334                                                 new Point (buttonRectangle.X + 1, buttonRectangle.Y + 3)
335                                         };
336                                         
337                                         pen = ResPool.GetPen (pressed_inner_border_dark_color);
338                                         dc.DrawLines (pen, points_button_complete);
339                                 }
340                                 
341                                 // outer border
342                                 pen = ResPool.GetPen (button_outer_border_dark_color);
343                                 dc.DrawLines (pen, points_top_outer);
344                                 pen = ResPool.GetPen (button_outer_border_light_color);
345                                 dc.DrawLines (pen, points_bottom_outer);
346                                 
347                                 using (LinearGradientBrush lgbr2 = new LinearGradientBrush (new Point (buttonRectangle.X, buttonRectangle.Y + 2),
348                                                                                             new Point (buttonRectangle.X, buttonRectangle.Bottom - 1),
349                                                                                             button_outer_border_dark_color, button_outer_border_light_color)) {
350                                         using (Pen lgbrpen = new Pen(lgbr2)) {
351                                                 dc.DrawLine (lgbrpen, buttonRectangle.X, buttonRectangle.Y + 2, buttonRectangle.X, buttonRectangle.Bottom - 3);
352                                                 dc.DrawLine (lgbrpen, buttonRectangle.Right - 1, buttonRectangle.Y + 2, buttonRectangle.Right - 1, buttonRectangle.Bottom - 3);
353                                         }
354                                 }
355                                 
356                                 // inner border
357                                 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : inner_border_dark_color);
358                                 if (!is_pressed) {
359                                         dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 4);
360                                 }
361                                 dc.DrawLine (pen, buttonRectangle.X + 3, buttonRectangle.Bottom - 3, buttonRectangle.Right - 4, buttonRectangle.Bottom - 3);
362                                 pen = ResPool.GetPen (is_pressed ? pressed_inner_border_dark_color : Color.White);
363                                 dc.DrawLine (pen, buttonRectangle.X + 2, buttonRectangle.Y + 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 4);
364                                 dc.DrawLine (pen, buttonRectangle.X + 3 , buttonRectangle.Y + 2, buttonRectangle.Right - 4, buttonRectangle.Y + 2);
365                                 
366                                 // edges
367                                 pen = ResPool.GetPen (edge_top_inner_color);
368                                 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Y + 2, buttonRectangle.X + 2, buttonRectangle.Y + 1);
369                                 dc.DrawLine (pen, buttonRectangle.Right - 3, buttonRectangle.Y + 1, buttonRectangle.Right - 2, buttonRectangle.Y + 2);
370                                 
371                                 pen = ResPool.GetPen (button_edge_top_outer_color);
372                                 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Y + 1, buttonRectangle.X + 1, buttonRectangle.Y);
373                                 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Y, buttonRectangle.Right - 1, buttonRectangle.Y + 1);
374                                 
375                                 pen = ResPool.GetPen (edge_bottom_inner_color);
376                                 dc.DrawLine (pen, buttonRectangle.X + 1, buttonRectangle.Bottom - 3, buttonRectangle.X + 2, buttonRectangle.Bottom - 2);
377                                 dc.DrawLine (pen, buttonRectangle.Right - 2, buttonRectangle.Bottom - 3, buttonRectangle.Right - 3, buttonRectangle.Bottom - 2);
378                                 
379                                 pen = ResPool.GetPen (button_edge_bottom_outer_color);
380                                 dc.DrawLine (pen, buttonRectangle.X, buttonRectangle.Bottom - 2, buttonRectangle.X + 1, buttonRectangle.Bottom - 1);
381                                 dc.DrawLine (pen, buttonRectangle.Right - 1, buttonRectangle.Bottom - 2, buttonRectangle.Right - 2, buttonRectangle.Bottom - 1);
382                         }
383                 }
384                 
385                 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc ) {
386                         
387                         if ( !button.is_enabled || button.FlatStyle == FlatStyle.Popup )
388                                 return;
389                         
390                         Pen pen = ResPool.GetPen( button_focus_color );
391                         DashStyle old_dash_style = pen.DashStyle;
392                         pen.DashStyle = DashStyle.Dot;
393                         
394                         Rectangle focus_rect = new Rectangle( button.ClientRectangle.X + 4, button.ClientRectangle.Y + 4, button.ClientRectangle.Width - 9, button.ClientRectangle.Height - 9 );
395                         
396                         dc.DrawRectangle( pen, focus_rect );
397                         
398                         pen.DashStyle = old_dash_style;
399                 }
400                 
401                 // FIXME: remove if libgdiplus DrawOrMeasureString is fixed
402                 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc ) {
403                         if ( !( button is CheckBox ) && !( button is RadioButton ) ) {
404                                 Rectangle buttonRectangle = button.ClientRectangle;
405                                 Rectangle text_rect = Rectangle.Inflate( buttonRectangle, -4, -4 );
406                                 
407                                 string text = button.Text;
408                                 
409                                 if ( text.Length > 1 ) {
410                                         SizeF sizef = dc.MeasureString( text, button.Font, text_rect.Width, button.text_format );
411                                         
412                                         if ( (int)sizef.Width > text_rect.Width - 3 ) {
413                                                 for ( int i = 1; i < text.Length + 1; i++ ) {
414                                                         sizef = dc.MeasureString( text.Substring( 0, i ), button.Font, text_rect.Width, button.text_format );
415                                                         
416                                                         if ( (int)sizef.Width > text_rect.Width - 3 ) {
417                                                                 text = text.Substring( 0, i - 1 );
418                                                                 break;
419                                                         }
420                                                 }
421                                         }
422                                 }
423                                 
424                                 if ( button.is_pressed ) {
425                                         text_rect.X++;
426                                         text_rect.Y++;
427                                 }
428                                 
429                                 if ( button.is_enabled ) {                                      
430                                         dc.DrawString( text, button.Font, ResPool.GetSolidBrush( button.ForeColor ), text_rect, button.text_format );
431                                 } else {
432                                         if ( button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup ) {
433                                                 dc.DrawString( text, button.Font, ResPool.GetSolidBrush( ControlPaint.DarkDark( this.ColorControl ) ), text_rect, button.text_format );
434                                         } else {
435                                                 CPDrawStringDisabled( dc, text, button.Font, ColorControlText, text_rect, button.text_format );
436                                         }
437                                 }
438                         }
439                 }
440                 #endregion      // ButtonBase
441                 
442                 #region Menus
443                 public override void DrawMenuItem( MenuItem item, DrawItemEventArgs e ) {
444                         StringFormat string_format;
445                         Rectangle rect_text = e.Bounds;
446                         
447                         if ( item.Visible == false )
448                                 return; 
449                         
450                         if ( item.MenuBar ) {
451                                 string_format = string_format_menu_menubar_text;
452                         } else {
453                                 string_format = string_format_menu_text;
454                         }
455                         
456                         if ( item.Separator ) {
457                                 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
458                                                     e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 1 );
459                                 
460                                 e.Graphics.DrawLine( ResPool.GetPen( Color.White ),
461                                                     e.Bounds.X, e.Bounds.Y + 2, e.Bounds.X + e.Bounds.Right - 4, e.Bounds.Y + 2 );
462                                 
463                                 return;
464                         }
465                         
466                         if ( !item.MenuBar )
467                                 rect_text.X += MenuCheckSize.Width;
468                         
469                         if ( item.BarBreak ) { /* Draw vertical break bar*/
470                                 Rectangle rect = e.Bounds;
471                                 rect.Y++;
472                                 rect.Width = 3;
473                                 rect.Height = item.MenuHeight - 6;
474                                 
475                                 e.Graphics.DrawLine( ResPool.GetPen( menu_separator_color ),
476                                                     rect.X, rect.Y , rect.X, rect.Y + rect.Height );
477                                 
478                                 e.Graphics.DrawLine( ResPool.GetPen( ColorControlLight ),
479                                                     rect.X + 1, rect.Y , rect.X + 1, rect.Y + rect.Height );
480                         }
481                         
482                         Color color_text = ColorMenuText;
483                         Color color_back;
484                         
485                         /* Draw background */
486                         Rectangle rect_back = e.Bounds;
487                         rect_back.X++;
488                         rect_back.Width -= 2;
489                         
490                         if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected ) {
491                                 color_text = ColorHighlightText;
492                                 color_back = item.MenuBar ? theme_back_color : menu_background_color;
493                                 
494                                 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rect_back.X, rect_back.Y + 1 ), new Point( rect_back.X, rect_back.Bottom - 1 ), menuitem_gradient_first_color, menuitem_gradient_second_color ) ) {
495                                         e.Graphics.FillRectangle( lgbr, rect_back.X + 1, rect_back.Y + 1, rect_back.Width - 1, rect_back.Height - 1 );
496                                 }
497                                 
498                                 rect_back.Height--;
499                                 Pen tmp_pen = ResPool.GetPen( menuitem_border_color );
500                                 e.Graphics.DrawLine( tmp_pen, rect_back.X + 1, rect_back.Y, rect_back.Right - 1, rect_back.Y );
501                                 e.Graphics.DrawLine( tmp_pen, rect_back.Right, rect_back.Y + 1, rect_back.Right, rect_back.Bottom - 1 );
502                                 e.Graphics.DrawLine( tmp_pen, rect_back.Right - 1, rect_back.Bottom, rect_back.X + 1, rect_back.Bottom );
503                                 e.Graphics.DrawLine( tmp_pen, rect_back.X, rect_back.Bottom - 1, rect_back.X, rect_back.Y + 1 );
504                         } else {
505                                 color_text = ColorMenuText;
506                                 color_back = item.MenuBar ? theme_back_color : menu_background_color;
507                                 
508                                 e.Graphics.FillRectangle( ResPool.GetSolidBrush( color_back ), rect_back );
509                         }
510                         
511                         if ( item.Enabled ) {
512                                 e.Graphics.DrawString( item.Text, e.Font,
513                                                       ResPool.GetSolidBrush( color_text ),
514                                                       rect_text, string_format );
515                                 
516                                 if ( !item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut ) {
517                                         string str = item.GetShortCutText( );
518                                         Rectangle rect = rect_text;
519                                         rect.X = item.XTab;
520                                         rect.Width -= item.XTab;
521                                         
522                                         e.Graphics.DrawString( str, e.Font, ResPool.GetSolidBrush( color_text ),
523                                                               rect, string_format_menu_shortcut );
524                                 }
525                         } else {
526                                 ControlPaint.DrawStringDisabled( e.Graphics, item.Text, e.Font,
527                                                                 Color.Black, rect_text, string_format );
528                         }
529                         
530                         /* Draw arrow */
531                         if ( item.MenuBar == false && item.IsPopup ) {
532                                 int cx = MenuCheckSize.Width;
533                                 int cy = MenuCheckSize.Height;
534                                 using ( Bitmap  bmp = new Bitmap( cx, cy ) ) {
535                                         using ( Graphics dc = Graphics.FromImage( bmp ) ) {
536                                                 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
537                                                 dc.SmoothingMode = SmoothingMode.AntiAlias;
538                                                 
539                                                 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
540                                                 ControlPaint.DrawMenuGlyph( dc, rect_arrow, MenuGlyph.Arrow );
541                                                 bmp.MakeTransparent( );
542                                                 
543                                                 if ( item.Enabled ) {
544                                                         e.Graphics.DrawImage( bmp, e.Bounds.X + e.Bounds.Width - cx,
545                                                                              e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
546                                                 } else {
547                                                         ControlPaint.DrawImageDisabled( e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
548                                                                                        e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ),  color_back );
549                                                 }
550                                                 
551                                                 dc.SmoothingMode = old_smoothing_mode;
552                                         }
553                                 }
554                         }
555                         
556                         /* Draw checked or radio */
557                         if ( item.MenuBar == false && item.Checked ) {
558                                 
559                                 Rectangle area = e.Bounds;
560                                 int cx = MenuCheckSize.Width;
561                                 int cy = MenuCheckSize.Height;
562                                 using ( Bitmap bmp = new Bitmap( cx, cy ) ) {
563                                         using ( Graphics gr = Graphics.FromImage( bmp ) ) {
564                                                 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
565                                                 
566                                                 if ( item.RadioCheck )
567                                                         ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Bullet );
568                                                 else
569                                                         ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Checkmark );
570                                                 
571                                                 bmp.MakeTransparent( );
572                                                 e.Graphics.DrawImage( bmp, area.X, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
573                                         }
574                                 }
575                         }
576                 }
577                 
578                 public override void DrawPopupMenu( Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect ) {
579                         
580                         dc.FillRectangle( ResPool.GetSolidBrush
581                                          ( menu_background_color ), cliparea );
582                         
583                         /* Draw menu borders */
584                         dc.DrawRectangle( ResPool.GetPen( menu_border_color ), rect.X, rect.Y, rect.Width - 1, rect.Height - 1 );
585                         
586                         // inner border
587                         Pen tmp_pen = ResPool.GetPen( Color.White );
588                         dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 1, rect.Right - 2, rect.Y + 1 );
589                         dc.DrawLine( tmp_pen, rect.X + 1, rect.Y + 2, rect.X + 1, rect.Bottom - 2 );
590                         
591                         tmp_pen = ResPool.GetPen( menu_inner_border_color );
592                         dc.DrawLine( tmp_pen, rect.Right - 2, rect.Y + 2, rect.Right - 2, rect.Bottom - 2 );
593                         dc.DrawLine( tmp_pen, rect.Right - 3, rect.Bottom - 2, rect.X + 2, rect.Bottom - 2 );
594                         
595                         for ( int i = 0; i < menu.MenuItems.Count; i++ )
596                                 if ( cliparea.IntersectsWith( menu.MenuItems[ i ].bounds ) ) {
597                                         MenuItem item = menu.MenuItems[ i ];
598                                         item.MenuHeight = menu.Height;
599                                         item.PerformDrawItem( new DrawItemEventArgs( dc, MenuFont,
600                                                                                     item.bounds, i, item.Status ) );
601                                 }
602                 }
603                 #endregion // Menus
604                 
605                 #region ProgressBar
606                 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl ) {
607                         Rectangle       client_area = ctrl.client_area;
608                         int             barpos_pixels;
609                         Rectangle bar = ctrl.client_area;
610                         
611                         barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
612                         
613                         bar.Width = barpos_pixels + 1;
614                         
615                         // Draw bar background
616                         dc.FillRectangle( ResPool.GetSolidBrush( menu_separator_color ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
617                         
618                         /* Draw border */
619                         Pen tmp_pen = ResPool.GetPen( progressbar_edge_dot_color );
620                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1 );
621                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
622                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1 );
623                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
624                         
625                         tmp_pen = ResPool.GetPen( scrollbar_border_color );
626                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Y );
627                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Right - 1, ctrl.ClientRectangle.Bottom - 2 );
628                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Bottom - 1, ctrl.ClientRectangle.Right - 2, ctrl.ClientRectangle.Bottom - 1 );
629                         dc.DrawLine( tmp_pen, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.X, ctrl.ClientRectangle.Bottom - 2 );
630                         
631                         if ( barpos_pixels <= 0 )
632                                 return;
633                         
634                         if ((bar.Width - 2) <= 0 || (bar.Height - 1) <= 0)
635                                 return;
636                         
637                         // Draw bar
638                         dc.DrawRectangle( ResPool.GetPen( combobox_focus_border_color ), bar.X - 1, bar.Y - 1, bar.Width, bar.Height + 1 );
639                         tmp_pen = ResPool.GetPen( progressbar_inner_border_color );
640                         dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.Right - 2, bar.Y );
641                         dc.DrawLine( tmp_pen, bar.X, bar.Y, bar.X, bar.Bottom - 1 );
642                         
643                         using ( Bitmap bmp = new Bitmap( bar.Width - 2, bar.Height - 1 ) ) {
644                                 using ( Graphics gr = Graphics.FromImage( bmp ) ) {
645                                         gr.FillRectangle( ResPool.GetSolidBrush( tab_focus_color ), 0, 0, bmp.Width, bmp.Height );
646                                         
647                                         LinearGradientBrush lgbr = new LinearGradientBrush( new Rectangle( 0, 0, bmp.Height, bmp.Height ), progressbar_first_gradient_color, progressbar_second_gradient_color, 0.0f, true );
648                                         
649                                         lgbr.RotateTransform( 45.0f, MatrixOrder.Append );
650                                         
651                                         float pen_width = bmp.Height / 2;
652                                         
653                                         Pen pen = new Pen( lgbr, pen_width );
654                                         
655                                         int add = bmp.Height + (int)pen.Width / 2;
656                                         
657                                         int x_top = 0;
658                                         int x_bottom = - bmp.Height;
659                                         
660                                         while ( x_bottom < bmp.Width ) {
661                                                 gr.DrawLine( pen, x_top, 0, x_bottom, bmp.Height );
662                                                 x_top += add;
663                                                 x_bottom += add;
664                                         }
665                                         pen.Dispose( );
666                                         lgbr.Dispose( );
667                                 }
668                                 
669                                 dc.DrawImage( bmp, bar.X + 1, bar.Y + 1 );
670                         }
671                 }
672                 #endregion      // ProgressBar
673                 
674                 #region RadioButton
675                 
676                 // renders a radio button with the Flat and Popup FlatStyle
677                 protected override void DrawFlatStyleRadioButton (Graphics dc, Rectangle rectangle, RadioButton radio_button)
678                 {
679                         if (radio_button.Enabled) {
680                                 // draw the outer flatstyle arcs
681                                 if (radio_button.FlatStyle == FlatStyle.Flat) {
682                                         dc.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
683                                         
684                                         // fill in the area depending on whether or not the mouse is hovering
685                                         if (radio_button.is_entered && radio_button.Capture) {
686                                                 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
687                                         } else {
688                                                 dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
689                                         }
690                                 } else {
691                                         // must be a popup radio button
692                                         // fill the control
693                                         dc.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
694                                         
695                                         if (radio_button.is_entered || radio_button.Capture) {
696                                                 // draw the popup 3d button knob
697                                                 dc.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
698                                                 
699                                                 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
700                                                 dc.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
701                                                 
702                                         } else {
703                                                 // just draw lighter flatstyle outer circle
704                                                 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);                                         
705                                         }                                                                               
706                                 }
707                         } else {
708                                 // disabled
709                                 // fill control background color regardless of actual backcolor
710                                 dc.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
711                                 // draw the ark as control dark
712                                 dc.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
713                         }
714                         
715                         // draw the check
716                         if (radio_button.Checked) {
717                                 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
718                                 dc.SmoothingMode = SmoothingMode.AntiAlias;
719                                 
720                                 CL_Draw_RadioButton_Dot (dc, rectangle, true, false);
721                                 
722                                 dc.SmoothingMode = old_smoothing_mode;
723                         }
724                 }
725                 #endregion      // RadioButton
726                 
727                 #region ScrollBar
728                 public override void DrawScrollBar( Graphics dc, Rectangle clip, ScrollBar bar ) {
729                         int             scrollbutton_width = bar.scrollbutton_width;
730                         int             scrollbutton_height = bar.scrollbutton_height;
731                         Rectangle       first_arrow_area;
732                         Rectangle       second_arrow_area;                      
733                         Rectangle       thumb_pos;
734                         
735                         thumb_pos = bar.ThumbPos;
736                         
737                         if ( bar.vert ) {
738                                 first_arrow_area = new Rectangle( 0, 0, bar.Width, scrollbutton_height + 1 );
739                                 bar.FirstArrowArea = first_arrow_area;
740                                 
741                                 second_arrow_area = new Rectangle( 0, bar.ClientRectangle.Height - scrollbutton_height - 1, bar.Width, scrollbutton_height + 1 );
742                                 bar.SecondArrowArea = second_arrow_area;
743                                 
744                                 thumb_pos.Width = bar.Width;
745                                 bar.ThumbPos = thumb_pos;
746                                 
747                                 /* Background */
748                                 switch ( bar.thumb_moving ) {
749                                         case ScrollBar.ThumbMoving.None: {
750                                                         ScrollBar_Vertical_Draw_ThumbMoving_None( scrollbutton_height, bar, clip, dc );
751                                                         break;
752                                                 }
753                                         case ScrollBar.ThumbMoving.Forward: {
754                                                         ScrollBar_Vertical_Draw_ThumbMoving_Forward( scrollbutton_height, bar, thumb_pos, clip, dc );
755                                                         break;
756                                                 }
757                                                 
758                                         case ScrollBar.ThumbMoving.Backwards: {
759                                                         ScrollBar_Vertical_Draw_ThumbMoving_Backwards( scrollbutton_height, bar, thumb_pos, clip, dc );
760                                                         break;
761                                                 }
762                                                 
763                                         default:
764                                                 break;
765                                 }
766                                 
767                                 /* Buttons */
768                                 if ( clip.IntersectsWith( first_arrow_area ) )
769                                         CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state );
770                                 if ( clip.IntersectsWith( second_arrow_area ) )
771                                         CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state );
772                         } else {
773                                 first_arrow_area = new Rectangle( 0, 0, scrollbutton_width + 1, bar.Height );
774                                 bar.FirstArrowArea = first_arrow_area;
775                                 
776                                 second_arrow_area = new Rectangle( bar.ClientRectangle.Width - scrollbutton_width - 1, 0, scrollbutton_width + 1, bar.Height );
777                                 bar.SecondArrowArea = second_arrow_area;
778                                 
779                                 thumb_pos.Height = bar.Height;
780                                 bar.ThumbPos = thumb_pos;
781                                 
782                                 /* Background */                                        
783                                 switch ( bar.thumb_moving ) {
784                                         case ScrollBar.ThumbMoving.None: {
785                                                         ScrollBar_Horizontal_Draw_ThumbMoving_None( scrollbutton_width, bar, clip, dc );
786                                                         break;
787                                                 }
788                                                 
789                                         case ScrollBar.ThumbMoving.Forward: {
790                                                         ScrollBar_Horizontal_Draw_ThumbMoving_Forward( scrollbutton_width, thumb_pos, bar, clip, dc );
791                                                         break;
792                                                 }
793                                                 
794                                         case ScrollBar.ThumbMoving.Backwards: {
795                                                         ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( scrollbutton_width, thumb_pos, bar, clip, dc );
796                                                         break;
797                                                 }
798                                 }
799                                 
800                                 /* Buttons */
801                                 if ( clip.IntersectsWith( first_arrow_area ) )
802                                         CPDrawScrollButton( dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state );
803                                 if ( clip.IntersectsWith( second_arrow_area ) )
804                                         CPDrawScrollButton( dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state );
805                         }
806                         
807                         /* Thumb */
808                         ScrollBar_DrawThumb( bar, thumb_pos, clip, dc );                                
809                 }
810                 
811                 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
812                         if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
813                                 DrawScrollBarThumb( dc, thumb_pos, bar );
814                 }
815                 
816                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc ) {
817                         Rectangle r = new Rectangle( 0,
818                                                     scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
819                         Rectangle intersect = Rectangle.Intersect( clip, r );
820                         
821                         if ( intersect != Rectangle.Empty ) {
822                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
823                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
824                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
825                                 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
826                         }
827                 }
828                 
829                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
830                         Rectangle r = new Rectangle( 0,  scrollbutton_height,
831                                                     bar.ClientRectangle.Width, thumb_pos.Y  - scrollbutton_height );
832                         Rectangle intersect = Rectangle.Intersect( clip, r );
833                         
834                         if ( intersect != Rectangle.Empty ) {
835                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
836                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
837                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
838                                 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
839                         }
840                         
841                         r.X = 0;
842                         r.Y = thumb_pos.Y + thumb_pos.Height;
843                         r.Width = bar.ClientRectangle.Width;
844                         r.Height = bar.ClientRectangle.Height -  ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
845                         
846                         intersect = Rectangle.Intersect( clip, r );
847                         if ( intersect != Rectangle.Empty ) {
848                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
849                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
850                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
851                                 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
852                         }
853                 }
854                 
855                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc ) {
856                         Rectangle r = new Rectangle( 0,  scrollbutton_height,
857                                                     bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
858                         Rectangle intersect = Rectangle.Intersect( clip, r );
859                         
860                         if ( intersect != Rectangle.Empty ) {
861                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
862                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
863                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
864                                 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
865                         }
866                         
867                         r.X = 0;
868                         r.Y = thumb_pos.Y + thumb_pos.Height;
869                         r.Width = bar.ClientRectangle.Width;
870                         r.Height = bar.ClientRectangle.Height -  ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
871                         
872                         intersect = Rectangle.Intersect( clip, r );
873                         if ( intersect != Rectangle.Empty ) {
874                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
875                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
876                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.X, intersect.Bottom - 1 );
877                                 dc.DrawLine( pen, intersect.Right - 1, intersect.Y, intersect.Right - 1, intersect.Bottom - 1 );
878                         }
879                 }
880                 
881                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc ) {
882                         Rectangle r = new Rectangle( scrollbutton_width,
883                                                     0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
884                         Rectangle intersect = Rectangle.Intersect( clip, r );
885                         
886                         if ( intersect != Rectangle.Empty ) {
887                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
888                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
889                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
890                                 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
891                         }
892                 }
893                 
894                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
895                         Rectangle r = new Rectangle( scrollbutton_width,  0,
896                                                     thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
897                         Rectangle intersect = Rectangle.Intersect( clip, r );
898                         
899                         if ( intersect != Rectangle.Empty ) {
900                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
901                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
902                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
903                                 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
904                         }
905                         
906                         r.X = thumb_pos.X + thumb_pos.Width;
907                         r.Y = 0;
908                         r.Width = bar.ClientRectangle.Width -  ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
909                         r.Height = bar.ClientRectangle.Height;
910                         
911                         intersect = Rectangle.Intersect( clip, r );
912                         if ( intersect != Rectangle.Empty ) {
913                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
914                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
915                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
916                                 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
917                         }
918                 }
919                 
920                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc ) {
921                         Rectangle r = new Rectangle( scrollbutton_width,  0,
922                                                     thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
923                         Rectangle intersect = Rectangle.Intersect( clip, r );
924                         
925                         if ( intersect != Rectangle.Empty ) {
926                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
927                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
928                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
929                                 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
930                         }
931                         
932                         r.X = thumb_pos.X + thumb_pos.Width;
933                         r.Y = 0;
934                         r.Width = bar.ClientRectangle.Width -  ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
935                         r.Height = bar.ClientRectangle.Height;
936                         
937                         intersect = Rectangle.Intersect( clip, r );
938                         if ( intersect != Rectangle.Empty ) {
939                                 dc.FillRectangle( ResPool.GetSolidBrush( scrollbar_background_color ), intersect );
940                                 Pen pen = ResPool.GetPen( scrollbar_border_color );
941                                 dc.DrawLine( pen, intersect.X, intersect.Y, intersect.Right - 1, intersect.Y );
942                                 dc.DrawLine( pen, intersect.X, intersect.Bottom - 1, intersect.Right - 1, intersect.Bottom - 1 );
943                         }
944                 }
945                 #endregion      // ScrollBar
946                 
947                 #region StatusBar
948                 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
949                                                            Brush br_forecolor, StatusBarPanel panel ) {
950                         int border_size = 3; // this is actually const, even if the border style is none
951                         
952                         area.Height -= border_size;
953                         if ( panel.BorderStyle != StatusBarPanelBorderStyle.None ) {
954                                 dc.DrawRectangle( ResPool.GetPen( pressed_inner_border_dark_color ), area );
955                         }
956                         
957                         if ( panel.Style == StatusBarPanelStyle.OwnerDraw ) {
958                                 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
959                                         dc, panel.Parent.Font, area, index, DrawItemState.Default,
960                                         panel, panel.Parent.ForeColor, panel.Parent.BackColor );
961                                 panel.Parent.OnDrawItemInternal( e );
962                                 return;
963                         }
964                         
965                         int left = area.Left;
966                         if ( panel.Icon != null ) {
967                                 left += 2;
968                                 dc.DrawIcon( panel.Icon, left, area.Top );
969                                 left += panel.Icon.Width;
970                         }
971                         
972                         if ( panel.Text == String.Empty )
973                                 return;
974                         
975                         string text = panel.Text;
976                         StringFormat string_format = new StringFormat( );
977                         string_format.Trimming = StringTrimming.Character;
978                         string_format.FormatFlags = StringFormatFlags.NoWrap;
979                         
980                         if ( text[ 0 ] == '\t' ) {
981                                 string_format.Alignment = StringAlignment.Center;
982                                 text = text.Substring( 1 );
983                                 if ( text[ 0 ] == '\t' ) {
984                                         string_format.Alignment = StringAlignment.Far;
985                                         text = text.Substring( 1 );
986                                 }
987                         }
988                         
989                         int x = left + border_size;
990                         int y = border_size + 2;
991                         Rectangle r = new Rectangle( x, y,
992                                                     area.Right - x - border_size,
993                                                     area.Bottom - y - border_size );
994                         
995                         dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
996                 }
997                 #endregion      // StatusBar
998                 
999                 // FIXME: regions near the borders don't get filled with the correct backcolor
1000                 // TODO: TabAlignment.Left and TabAlignment.Bottom
1001                 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab ) {
1002                         if (tab.Parent != null)
1003                                 dc.FillRectangle( ResPool.GetSolidBrush( tab.Parent.BackColor ), area );
1004                         else
1005                                 dc.FillRectangle( ResPool.GetSolidBrush( tab.BackColor ), area );
1006                         Rectangle panel_rect = GetTabPanelRectExt( tab );
1007                         
1008                         if ( tab.Appearance == TabAppearance.Normal ) {
1009                                 
1010                                 switch ( tab.Alignment ) {
1011                                         case TabAlignment.Top:
1012                                                 // inner border...
1013                                                 Pen pen = ResPool.GetPen( Color.White );
1014                                                 
1015                                                 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1016                                                 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top , panel_rect.Right - 2, panel_rect.Top );
1017                                                 
1018                                                 pen = ResPool.GetPen( tab_inner_border_color );
1019                                                 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1020                                                 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1021                                                 
1022                                                 // border
1023                                                 pen = ResPool.GetPen( tab_border_color );
1024                                                 
1025                                                 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Top - 1 );
1026                                                 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top - 1, panel_rect.Right - 1, panel_rect.Bottom - 2 );
1027                                                 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom - 2, panel_rect.Right - 3, panel_rect.Bottom );
1028                                                 dc.DrawLine( pen, panel_rect.Right - 3, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1029                                                 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1030                                                 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top - 1 );
1031                                                 break;
1032                                                 
1033                                                 // FIXME: the size of the tab page is to big to draw the upper inner white border
1034                                         case TabAlignment.Right:
1035                                                 // inner border...
1036                                                 pen = ResPool.GetPen( Color.White );
1037                                                 
1038                                                 dc.DrawLine( pen, panel_rect.Left + 1, panel_rect.Top + 1, panel_rect.Left + 1, panel_rect.Bottom - 1 );
1039                                                 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top + 1 , panel_rect.Right - 2, panel_rect.Top + 1 );
1040                                                 
1041                                                 pen = ResPool.GetPen( tab_inner_border_color );
1042                                                 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Top + 1, panel_rect.Right - 2, panel_rect.Bottom - 2 );
1043                                                 dc.DrawLine( pen, panel_rect.Right - 2, panel_rect.Bottom - 1, panel_rect.Left + 2, panel_rect.Bottom - 1 );
1044                                                 
1045                                                 // border
1046                                                 pen = ResPool.GetPen( tab_border_color );
1047                                                 
1048                                                 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Top, panel_rect.Right - 1, panel_rect.Top );
1049                                                 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Top, panel_rect.Right - 1, panel_rect.Bottom );
1050                                                 dc.DrawLine( pen, panel_rect.Right - 1, panel_rect.Bottom, panel_rect.Left + 2, panel_rect.Bottom );
1051                                                 dc.DrawLine( pen, panel_rect.Left + 2, panel_rect.Bottom, panel_rect.Left, panel_rect.Bottom - 2 );
1052                                                 dc.DrawLine( pen, panel_rect.Left, panel_rect.Bottom - 2, panel_rect.Left, panel_rect.Top + 2 );
1053                                                 dc.DrawLine( pen, panel_rect.Left, panel_rect.Top + 2, panel_rect.Left + 2, panel_rect.Top );
1054                                                 break;
1055                                 }
1056                         }
1057                         
1058                         if (tab.Alignment == TabAlignment.Top) {
1059                                 for (int r = tab.TabPages.Count; r > 0; r--) {
1060                                         for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1061                                                 if (i == tab.SelectedIndex)
1062                                                         continue;
1063                                                 if (r != tab.TabPages [i].Row)
1064                                                         continue;
1065                                                 Rectangle rect = tab.GetTabRect (i);
1066                                                 if (!rect.IntersectsWith (area))
1067                                                         continue;
1068                                                 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1069                                         }
1070                                 }
1071                         } else {
1072                                 for (int r = 0; r < tab.TabPages.Count; r++) {
1073                                         for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
1074                                                 if (i == tab.SelectedIndex)
1075                                                         continue;
1076                                                 if (r != tab.TabPages [i].Row)
1077                                                         continue;
1078                                                 Rectangle rect = tab.GetTabRect (i);
1079                                                 if (!rect.IntersectsWith (area))
1080                                                         continue;
1081                                                 DrawTab (dc, tab.TabPages [i], tab, rect, false);
1082                                         }
1083                                 }
1084                         }
1085                         
1086                         if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
1087                                 Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
1088                                 if (rect.IntersectsWith (area))
1089                                         DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
1090                         }
1091                         
1092                         if (tab.ShowSlider) {
1093                                 Rectangle right = GetTabControlRightScrollRect (tab);
1094                                 Rectangle left = GetTabControlLeftScrollRect (tab);
1095                                 CPDrawScrollButton (dc, right, ScrollButton.Right, tab.RightSliderState);
1096                                 CPDrawScrollButton (dc, left, ScrollButton.Left, tab.LeftSliderState);
1097                         }
1098                 }
1099                 
1100                 protected override int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
1101                 {
1102                         int FlatButtonSpacing = 8;
1103                         Rectangle interior;
1104                         int res = bounds.Width;
1105                         
1106                         if (page.BackColor != tab_selected_gradient_second_color)
1107                                 page.BackColor = tab_selected_gradient_second_color;
1108                         
1109                         // we can't fill the background right away because the bounds might be adjusted if the tab is selected
1110                         
1111                         StringFormat string_format = new StringFormat ();
1112                         
1113                         if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
1114                                 dc.FillRectangle (ResPool.GetSolidBrush (tab_selected_gradient_second_color), bounds);
1115                                 
1116                                 // Separators
1117                                 if (tab.Appearance == TabAppearance.FlatButtons) {
1118                                         int width = bounds.Width;
1119                                         bounds.Width += (FlatButtonSpacing - 2);
1120                                         res = bounds.Width;
1121                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Etched, Border3DSide.Right);
1122                                         bounds.Width = width;
1123                                 }
1124                                 
1125                                 if (is_selected) {
1126                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1127                                 } else if (tab.Appearance != TabAppearance.FlatButtons) {
1128                                         CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
1129                                 }
1130                                 
1131                                 interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
1132                                 
1133                                 string_format.Alignment = StringAlignment.Center;
1134                                 string_format.LineAlignment = StringAlignment.Center;
1135                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
1136                         } else {
1137                                 Color tab_first_color = is_selected ? tab_selected_gradient_first_color : tab_not_selected_gradient_first_color;
1138                                 Color tab_second_color = is_selected ? tab_selected_gradient_second_color : tab_not_selected_gradient_second_color;
1139                                 
1140                                 switch (tab.Alignment) {
1141                                 case TabAlignment.Top:
1142                                         
1143                                         Rectangle tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1144                                         
1145                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom), tab_first_color, tab_second_color)) {
1146                                                 dc.FillRectangle (lgbr, tab_interior);
1147                                         }
1148                                         
1149                                         // edges
1150                                         Pen tmp_pen = ResPool.GetPen (tab_edge_color);
1151                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 1, bounds.Left + 1, bounds.Top);
1152                                         dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top, bounds.Right, bounds.Top + 1);
1153                                         
1154                                         // inner border
1155                                         tmp_pen = ResPool.GetPen (Color.White);
1156                                         dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 1);
1157                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 1, bounds.Top + 1);
1158                                         
1159                                         // border
1160                                         tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1161                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1162                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1163                                         dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1164                                         
1165                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_dark_color, border_pressed_light_color)) {
1166                                                 int diff = is_selected ? 3 : 2;
1167                                                 using (Pen lgbrpen = new Pen (lgbr)) {
1168                                                         dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - diff);
1169                                                         dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Right, bounds.Bottom - diff);
1170                                                 }
1171                                         }
1172                                         
1173                                         if (page.Focused) {
1174                                                 tmp_pen = ResPool.GetPen (tab_focus_color);
1175                                                 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top  + 2, bounds.Right - 1, bounds.Top + 2);
1176                                                 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1177                                                 
1178                                                 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1179                                                 dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left + 2, bounds.Top);
1180                                                 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Right - 2, bounds.Top);
1181                                                 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right, bounds.Top + 2);
1182                                         }
1183                                         
1184                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1185                                         
1186                                         string_format.Alignment = StringAlignment.Center;
1187                                         string_format.LineAlignment = StringAlignment.Center;
1188                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
1189                                         
1190                                         break;
1191                                         
1192                                 case TabAlignment.Bottom:
1193                                         
1194                                         tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 3);
1195                                         
1196                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Left + 2, bounds.Bottom - 1), tab_first_color, tab_second_color)) {
1197                                                 dc.FillRectangle (lgbr, tab_interior);
1198                                         }
1199                                         
1200                                         // edges
1201                                         tmp_pen = ResPool.GetPen (tab_edge_color);
1202                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1203                                         dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom, bounds.Right, bounds.Bottom - 1);
1204                                         
1205                                         // inner border
1206                                         tmp_pen = ResPool.GetPen (Color.White);
1207                                         dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 1, bounds.Top + 2);
1208                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 1, bounds.Bottom - 1);
1209                                         
1210                                         // border
1211                                         tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1212                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1213                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1214                                         dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1215                                         
1216                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Left, bounds.Bottom - 1), border_pressed_light_color, border_pressed_dark_color)) {
1217                                                 int diff = is_selected ? 3 : 2;
1218                                                 using (Pen lgbrpen = new Pen (lgbr)) {
1219                                                         dc.DrawLine (lgbrpen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1220                                                         dc.DrawLine (lgbrpen, bounds.Right, bounds.Top + 2, bounds.Left, bounds.Bottom - 1 - diff);
1221                                                 }
1222                                         }
1223                                         
1224                                         if (page.Focused) {
1225                                                 tmp_pen = ResPool.GetPen (tab_focus_color);
1226                                                 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Bottom - 2);
1227                                                 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom - 1);
1228                                                 
1229                                                 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1230                                                 dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1231                                                 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Bottom, bounds.Right - 2, bounds.Bottom);
1232                                                 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Bottom, bounds.Right, bounds.Bottom - 2);
1233                                         }
1234                                         
1235                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1236                                         
1237                                         string_format.Alignment = StringAlignment.Center;
1238                                         string_format.LineAlignment = StringAlignment.Center;
1239                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
1240                                         
1241                                         break;
1242                                         
1243                                 case TabAlignment.Left:
1244                                         
1245                                         int w_diff = is_selected ? 2 : 0;
1246                                         
1247                                         tab_interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 2 - w_diff, bounds.Height - 2);
1248                                         
1249                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left + 2, bounds.Top + 2), new Point (bounds.Right - w_diff, bounds.Top + 2), tab_first_color, tab_second_color)) {
1250                                                 dc.FillRectangle (lgbr, tab_interior);
1251                                         }
1252                                         
1253                                         // edges
1254                                         tmp_pen = ResPool.GetPen (tab_edge_color);
1255                                         dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top, bounds.Left, bounds.Top + 1);
1256                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 1, bounds.Left + 1, bounds.Bottom);
1257                                         
1258                                         // inner border
1259                                         tmp_pen = ResPool.GetPen (Color.White);
1260                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 1, bounds.Right - 3, bounds.Top + 1);
1261                                         dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1262                                         
1263                                         // border
1264                                         tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1265                                         dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top, bounds.Left, bounds.Top + 2);
1266                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Top + 2, bounds.Left, bounds.Bottom - 2);
1267                                         dc.DrawLine (tmp_pen, bounds.Left, bounds.Bottom - 2, bounds.Left + 2, bounds.Bottom);
1268                                         
1269                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_dark_color, border_pressed_light_color)) {
1270                                                 int diff = is_selected ? 3 : 1;
1271                                                 
1272                                                 using (Pen lgbrpen = new Pen (lgbr)) {
1273                                                         dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Top, bounds.Right - diff, bounds.Left + 2);
1274                                                         dc.DrawLine (lgbrpen, bounds.Left + 2, bounds.Bottom, bounds.Right - diff, bounds.Left + 2);
1275                                                 }
1276                                         }
1277                                         
1278                                         if (page.Focused) {
1279                                                 tmp_pen = ResPool.GetPen (tab_focus_color);
1280                                                 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top + 1, bounds.Left + 3, bounds.Bottom - 1);
1281                                                 dc.DrawLine (tmp_pen, bounds.Left + 2, bounds.Top + 2, bounds.Left + 2, bounds.Bottom - 2);
1282                                                 
1283                                                 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1284                                                 dc.DrawLine (tmp_pen, bounds.Left + 3, bounds.Top, bounds.Left + 1, bounds.Top + 2);
1285                                                 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Top + 2, bounds.Left + 1, bounds.Bottom - 2);
1286                                                 dc.DrawLine (tmp_pen, bounds.Left + 1, bounds.Bottom - 2, bounds.Left + 3, bounds.Bottom);
1287                                         }
1288                                         
1289                                         interior = new Rectangle (bounds.Left + 2, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1290                                         
1291                                         string_format.Alignment = StringAlignment.Center;
1292                                         string_format.LineAlignment = StringAlignment.Center;
1293                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
1294                                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1295                                         
1296                                         break;
1297                                         
1298                                 default:
1299                                         // TabAlignment.Right
1300                                         
1301                                         tab_interior = new Rectangle (bounds.Left, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2);
1302                                         
1303                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right, bounds.Top + 2), tab_second_color, tab_first_color)) {
1304                                                 dc.FillRectangle (lgbr, tab_interior);
1305                                         }
1306                                         
1307                                         int l_diff = is_selected ? 2 : 0;
1308                                         
1309                                         // edges
1310                                         tmp_pen = ResPool.GetPen (tab_edge_color);
1311                                         dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top, bounds.Right - 1, bounds.Top + 1);
1312                                         dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 1, bounds.Right - 2, bounds.Bottom);
1313                                         
1314                                         // inner border
1315                                         tmp_pen = ResPool.GetPen (Color.White);
1316                                         dc.DrawLine (tmp_pen, bounds.Left + l_diff, bounds.Top + 1, bounds.Right - 2, bounds.Top + 1);
1317                                         dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1318                                         
1319                                         // border
1320                                         tmp_pen = ResPool.GetPen (border_pressed_dark_color);
1321                                         dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1322                                         dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1323                                         dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1324                                         
1325                                         using (LinearGradientBrush lgbr = new LinearGradientBrush (new Point (bounds.Left, bounds.Top + 2), new Point (bounds.Right - 2, bounds.Top + 2), border_pressed_light_color, border_pressed_dark_color)) {
1326                                                 int diff = is_selected ? 3 : 1;
1327                                                 
1328                                                 using (Pen lgbrpen = new Pen (lgbr)) {
1329                                                         dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Top, bounds.Right - diff, bounds.Top);
1330                                                         dc.DrawLine (lgbrpen, bounds.Left + l_diff, bounds.Bottom, bounds.Right - diff, bounds.Bottom);
1331                                                 }
1332                                         }
1333                                         
1334                                         if (page.Focused) {
1335                                                 tmp_pen = ResPool.GetPen (tab_focus_color);
1336                                                 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top + 1, bounds.Right - 3, bounds.Bottom - 1);
1337                                                 dc.DrawLine (tmp_pen, bounds.Right - 2, bounds.Top + 2, bounds.Right - 2, bounds.Bottom - 2);
1338                                                 
1339                                                 tmp_pen = ResPool.GetPen (tab_top_border_focus_color);
1340                                                 dc.DrawLine (tmp_pen, bounds.Right - 3, bounds.Top, bounds.Right - 1, bounds.Top + 2);
1341                                                 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Top + 2, bounds.Right - 1, bounds.Bottom - 2);
1342                                                 dc.DrawLine (tmp_pen, bounds.Right - 1, bounds.Bottom - 2, bounds.Right - 3, bounds.Bottom);
1343                                         }
1344                                         
1345                                         interior = new Rectangle (bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8);
1346                                         
1347                                         string_format.Alignment = StringAlignment.Center;
1348                                         string_format.LineAlignment = StringAlignment.Center;
1349                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
1350                                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
1351                                         
1352                                         break;
1353                                 }
1354                         }
1355                         
1356                         if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
1357                                 if (tab.Alignment == TabAlignment.Left) {
1358                                         int wo = interior.Width / 2;
1359                                         int ho = interior.Height / 2;
1360                                         dc.TranslateTransform (interior.X + wo, interior.Y + ho);
1361                                         dc.RotateTransform (180);
1362                                         dc.DrawString (page.Text, page.Font, ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
1363                                         dc.ResetTransform ();
1364                                 } else {
1365                                         dc.DrawString (page.Text, page.Font,
1366                                                        ResPool.GetSolidBrush (SystemColors.ControlText),
1367                                                        interior, string_format);
1368                                 }
1369                         } else if (page.Text != null) {
1370                                 DrawItemState state = DrawItemState.None;
1371                                 if (page == tab.SelectedTab)
1372                                         state |= DrawItemState.Selected;
1373                                 DrawItemEventArgs e = new DrawItemEventArgs (dc,
1374                                                                              tab.Font, bounds, tab.IndexForTabPage (page),
1375                                                                              state, page.ForeColor, page.BackColor);
1376                                 tab.OnDrawItemInternal (e);
1377                                 return res;
1378                         }
1379                         
1380                         return res;
1381                 }               
1382                 
1383                 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state ) {
1384                         Point[]                 arrow = new Point[ 3 ];
1385                         Point                           P1;
1386                         Point                           P2;
1387                         Point                           P3;
1388                         int                             centerX;
1389                         int                             centerY;
1390                         int                             shiftX;
1391                         int                             shiftY;
1392                         Rectangle               rect;
1393                         
1394                         bool pushed = false;
1395                         
1396                         Color first_color = Color.White;
1397                         Color second_color = combobox_button_second_gradient_color;
1398                         
1399                         dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1400                         
1401                         if ( state == ButtonState.Pushed ) {
1402                                 first_color = pressed_gradient_first_color;
1403                                 second_color = pressed_gradient_second_color;
1404                                 pushed = true;
1405                         }
1406                         
1407                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 2 ), first_color, second_color ) ) {
1408                                 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
1409                         }
1410                         
1411                         // inner borders
1412                         Pen tmp_pen = ResPool.GetPen( !pushed ? Color.White : pressed_inner_border_dark_color );
1413                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 1 );
1414                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 2 );
1415                         
1416                         tmp_pen = ResPool.GetPen( !pushed ? inner_border_dark_color : pressed_inner_border_dark_color  );
1417                         dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y + 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1418                         dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2 );
1419                         
1420                         // border
1421                         Point[] points = new Point[] {
1422                                 new Point( rectangle.X, rectangle.Y ),
1423                                 new Point( rectangle.Right - 3, rectangle.Y ),
1424                                 new Point( rectangle.Right - 1, rectangle.Y + 2 ),
1425                                 new Point( rectangle.Right - 1, rectangle.Bottom - 3 ),
1426                                 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
1427                                 new Point( rectangle.X, rectangle.Bottom - 1 ),
1428                                 new Point( rectangle.X, rectangle.Y )
1429                         };
1430                         
1431                         dc.DrawPolygon( ResPool.GetPen( pushed ? border_pressed_dark_color : border_normal_dark_color ), points );
1432                         
1433                         // edges on right side
1434                         tmp_pen = ResPool.GetPen( control_parent_backcolor );
1435                         dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1436                         dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1437                         
1438                         tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
1439                         dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
1440                         dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 2 );
1441                         
1442                         rect = new Rectangle( rectangle.X + 1 + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2 - 1, rectangle.Height / 2 );
1443                         centerX = rect.Left + rect.Width / 2;
1444                         centerY = rect.Top + rect.Height / 2;
1445                         shiftX = Math.Max( 1, rect.Width / 8 );
1446                         shiftY = Math.Max( 1, rect.Height / 8 );
1447                         
1448                         if ( ( state & ButtonState.Pushed ) != 0 ) {
1449                                 shiftX--;
1450                                 shiftY--;
1451                         }
1452                         
1453                         rect.Y -= shiftY;
1454                         centerY -= shiftY;
1455                         
1456                         P1 = new Point( rect.Left, centerY );
1457                         P2 = new Point( centerX, rect.Bottom );
1458                         P3 = new Point( rect.Right - 1, centerY );
1459                         
1460                         arrow[ 0 ] = P1;
1461                         arrow[ 1 ] = P2;
1462                         arrow[ 2 ] = P3;
1463                         
1464                         SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1465                         dc.SmoothingMode = SmoothingMode.AntiAlias;
1466                         
1467                         /* Draw the arrow */
1468                         if ( state == ButtonState.Inactive ) {
1469                                 /* Move away from the shadow */
1470                                 P1.X += 1;              P1.Y += 1;
1471                                 P2.X += 1;              P2.Y += 1;
1472                                 P3.X += 1;              P3.Y += 1;
1473                                 
1474                                 arrow[ 0 ] = P1;
1475                                 arrow[ 1 ] = P2;
1476                                 arrow[ 2 ] = P3;
1477                                 
1478                                 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) ) {
1479                                         dc.DrawLines( pen, arrow );
1480                                 }
1481                                 
1482                                 P1 = new Point( rect.Left, centerY );
1483                                 P2 = new Point( centerX, rect.Bottom );
1484                                 P3 = new Point( rect.Right - 1, centerY );
1485                                 
1486                                 arrow[ 0 ] = P1;
1487                                 arrow[ 1 ] = P2;
1488                                 arrow[ 2 ] = P3;
1489                                 
1490                                 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) ) {
1491                                         dc.DrawLines( pen, arrow );
1492                                 }
1493                         } else {
1494                                 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) ) {
1495                                         dc.DrawLines( pen, arrow );
1496                                 }
1497                         }
1498                         
1499                         dc.SmoothingMode = old_smoothing_mode;
1500                 }
1501                 
1502                 /* Scroll button: regular button + direction arrow */
1503                 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state ) {
1504                         bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1505                         
1506                         DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1507                         
1508                         Color color_arrow;
1509                         
1510                         if ( enabled )
1511                                 color_arrow = arrow_color;
1512                         else
1513                                 color_arrow = ColorGrayText;
1514                         
1515                         /* Paint arrows */
1516                         
1517                         int centerX = area.Left + area.Width / 2;
1518                         int centerY = area.Top + area.Height / 2;
1519                         
1520                         int shift = 0;
1521                         
1522                         if ( ( state & ButtonState.Pushed ) != 0 )
1523                                 shift = 1;
1524                         
1525                         int min_4 = 4;
1526                         int min_2 = 2;
1527                         if ( area.Width < 12 || area.Height < 12 ) {
1528                                 min_4 = 3;
1529                                 min_2 = 1;
1530                         }
1531                         
1532                         Point[] arrow = new Point[ 4 ];
1533                         
1534                         switch (scroll_button_type) {
1535                         case ScrollButton.Down:
1536                                 centerY += shift + 1;
1537                                 arrow [0] = new Point (centerX - min_4, centerY - min_2);
1538                                 arrow [1] = new Point (centerX, centerY + min_2);
1539                                 arrow [2] = new Point (centerX + min_4, centerY - min_2);
1540                                 arrow [3] = new Point (centerX - min_4, centerY - min_2);
1541                                 break;
1542                         case ScrollButton.Up:
1543                                 centerY -= shift;
1544                                 arrow [0] = new Point (centerX - min_4, centerY + min_2);
1545                                 arrow [1] = new Point (centerX, centerY - min_2);
1546                                 arrow [2] = new Point (centerX + min_4, centerY + min_2);
1547                                 arrow [3] = new Point (centerX - min_4, centerY + min_2);
1548                                 break;
1549                         case ScrollButton.Left:
1550                                 centerX -= shift;
1551                                 arrow [0] = new Point (centerX + min_2, centerY - min_4);
1552                                 arrow [1] = new Point (centerX + min_2, centerY + min_4);
1553                                 arrow [2] = new Point (centerX - min_2, centerY);
1554                                 arrow [3] = new Point (centerX + min_2, centerY - min_4);
1555                                 break;
1556                         case ScrollButton.Right:
1557                                 centerX += shift + 1;
1558                                 arrow [0] = new Point (centerX - min_2, centerY - min_4);
1559                                 arrow [1] = new Point (centerX + min_2, centerY);
1560                                 arrow [2] = new Point (centerX - min_2, centerY + min_4);
1561                                 arrow [3] = new Point (centerX - min_2, centerY - min_4);
1562                                 break;
1563                         default:
1564                                 break;
1565                         }
1566                         
1567                         SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1568                         dc.SmoothingMode = SmoothingMode.AntiAlias;
1569                         dc.FillPolygon( ResPool.GetSolidBrush( color_arrow ), arrow );
1570                         dc.SmoothingMode = old_smoothing_mode;
1571                 }
1572                 
1573                 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds ) {
1574                         Point pt1 = new Point( bounds.Right - 3, bounds.Bottom );
1575                         Point pt2 = new Point( bounds.Right, bounds.Bottom - 3 );
1576                         
1577                         // diagonals
1578                         Pen tmp_pen = ResPool.GetPen( Color.White );
1579                         for ( int i = 0; i < 4; i++ ) {
1580                                 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1581                         }
1582                         
1583                         pt1.X += 1;
1584                         pt2.Y += 1;
1585                         
1586                         tmp_pen = ResPool.GetPen( pressed_inner_border_dark_color );
1587                         for ( int i = 0; i < 4; i++ ) {
1588                                 dc.DrawLine( tmp_pen, pt1.X - i * 4, pt1.Y, pt2.X, pt2.Y - i * 4 );
1589                         }
1590                 }
1591                 
1592                 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar ) {
1593                         LinearGradientBrush lgbr = null;
1594                         
1595                         if ( bar.vert )
1596                                 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.Right - 2, area.Y + 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1597                         else
1598                                 lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), scrollbar_gradient_first_color, scrollbar_gradient_second_color );
1599                         
1600                         dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1601                         
1602                         lgbr.Dispose( );
1603                         
1604                         // outer border
1605                         Pen pen = ResPool.GetPen( border_normal_dark_color );
1606                         
1607                         dc.DrawRectangle( pen, area.X, area.Y, area.Width - 1, area.Height - 1 );
1608                         
1609                         // inner border
1610                         pen = ResPool.GetPen( Color.White );
1611                         dc.DrawLine( pen, area.X + 1, area.Bottom - 2, area.X + 1, area.Y + 1 );
1612                         dc.DrawLine( pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1613                         
1614                         pen = ResPool.GetPen( inner_border_dark_color );
1615                         dc.DrawLine( pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1616                         dc.DrawLine( pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1617                         
1618                         if ( bar.vert ) {
1619                                 if ( area.Height > 12 ) {
1620                                         int mid_y = area.Y + ( area.Height / 2 );
1621                                         int mid_x = area.X + ( area.Width / 2 );
1622                                         
1623                                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
1624                                         dc.DrawLine( pen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1625                                         dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x + 3, mid_y - 3 );
1626                                         dc.DrawLine( pen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1627                                         
1628                                         Pen spen = ResPool.GetPen( Color.White );
1629                                         dc.DrawLine( spen, mid_x - 3, mid_y + 1, mid_x + 3, mid_y + 1 );
1630                                         dc.DrawLine( spen, mid_x - 3, mid_y - 2, mid_x + 3, mid_y - 2 );
1631                                         dc.DrawLine( spen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1632                                 }
1633                         } else {
1634                                 // draw grip lines only if there is enough space
1635                                 if ( area.Width > 12 ) {
1636                                         int mid_x = area.X +  ( area.Width / 2 );
1637                                         int mid_y = area.Y +  ( area.Height / 2 );
1638                                         
1639                                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
1640                                         dc.DrawLine( pen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1641                                         dc.DrawLine( pen, mid_x - 3, mid_y - 3, mid_x - 3, mid_y + 3 );
1642                                         dc.DrawLine( pen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1643                                         
1644                                         Pen spen = ResPool.GetPen( Color.White );
1645                                         dc.DrawLine( spen, mid_x + 1, mid_y - 3, mid_x + 1, mid_y + 3 );
1646                                         dc.DrawLine( spen, mid_x - 2, mid_y - 3, mid_x - 2, mid_y + 3 );
1647                                         dc.DrawLine( spen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1648                                 }
1649                         }
1650                 }
1651                 
1652                 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type ) {
1653                         Pen pen = ResPool.GetPen( border_normal_dark_color );
1654                         
1655                         Color first_gradient_color = gradient_first_color; 
1656                         Color second_gradient_color = gradient_second_color_nr2;
1657                         
1658                         bool pushed = false;
1659                         
1660                         if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed ) {
1661                                 first_gradient_color = pressed_gradient_first_color;
1662                                 second_gradient_color = pressed_gradient_second_color;
1663                                 pushed = true;
1664                         }
1665                         
1666                         Point[] points = null;
1667                         
1668                         LinearGradientBrush lgbr = null;
1669                         
1670                         switch ( scroll_button_type ) {
1671                                 case ScrollButton.Left:
1672                                         // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1673                                         dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.X, area.Bottom - 1 );
1674                                         
1675                                         lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1676                                         dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1677                                         
1678                                         Pen tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1679                                         dc.DrawLine( tmp_pen, area.X + 1, area.Y + 2, area.X + 1, area.Bottom - 2 );
1680                                         dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1681                                         
1682                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1683                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1684                                         dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1685                                         
1686                                         tmp_pen = ResPool.GetPen( edge_top_inner_color );
1687                                         dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1688                                         dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1689                                         
1690                                         points = new Point[] {
1691                                                 new Point( area.X + 2, area.Y ),
1692                                                 new Point( area.Right - 1, area.Y ),
1693                                                 new Point( area.Right - 1, area.Bottom - 1 ),
1694                                                 new Point( area.X + 2, area.Bottom - 1 ),
1695                                                 new Point( area.X, area.Bottom - 3 ),
1696                                                 new Point( area.X, area.Y + 2 ),
1697                                                 new Point( area.X + 2, area.Y )
1698                                         };
1699                                         dc.DrawPolygon( pen, points );
1700                                         break;
1701                                 case ScrollButton.Right:
1702                                         // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1703                                         dc.DrawLine( ResPool.GetPen( ColorControl ), area.Right - 1, area.Y, area.Right - 1, area.Bottom - 1 );
1704                                         
1705                                         lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y + 2 ), new Point( area.X + 2, area.Bottom - 2 ), first_gradient_color, second_gradient_color );
1706                                         dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 2 );
1707                                         
1708                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1709                                         dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1710                                         dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1711                                         
1712                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1713                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1714                                         dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1715                                         
1716                                         tmp_pen = ResPool.GetPen( edge_top_inner_color );
1717                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1718                                         dc.DrawLine( tmp_pen, area.Right - 1, area.Bottom - 2, area.Right - 2, area.Bottom - 1 );
1719                                         
1720                                         points = new Point[] {
1721                                                 new Point( area.X, area.Y ),
1722                                                 new Point( area.Right - 3, area.Y ),
1723                                                 new Point( area.Right - 1, area.Y + 2 ),
1724                                                 new Point( area.Right - 1, area.Bottom - 3 ),
1725                                                 new Point( area.Right - 3, area.Bottom - 1 ),
1726                                                 new Point( area.X, area.Bottom - 1 ),
1727                                                 new Point( area.X, area.Y ),
1728                                         };
1729                                         dc.DrawPolygon( pen, points );
1730                                         break;
1731                                 case ScrollButton.Up:
1732                                         // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1733                                         dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Y, area.Right - 1, area.Y );
1734                                         
1735                                         lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1736                                         dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1737                                         
1738                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1739                                         dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1740                                         dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1741                                         
1742                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1743                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1744                                         dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1745                                         
1746                                         tmp_pen = ResPool.GetPen( edge_top_inner_color );
1747                                         dc.DrawLine( tmp_pen, area.X, area.Y + 1, area.X + 1, area.Y );
1748                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y, area.Right - 1, area.Y + 1 );
1749                                         
1750                                         points = new Point[] {
1751                                                 new Point( area.X + 2, area.Y ),
1752                                                 new Point( area.Right - 3, area.Y ),
1753                                                 new Point( area.Right - 1, area.Y + 2 ),
1754                                                 new Point( area.Right - 1, area.Bottom - 1 ),
1755                                                 new Point( area.X, area.Bottom - 1 ),
1756                                                 new Point( area.X, area.Y + 2 ),
1757                                                 new Point( area.X + 2, area.Y )
1758                                         };
1759                                         dc.DrawPolygon( pen, points );
1760                                         break;
1761                                 case ScrollButton.Down:
1762                                         // FIXME: temporary fix for artefacts, it should use the backcolor of the parent control
1763                                         dc.DrawLine( ResPool.GetPen( ColorControl ), area.X, area.Bottom - 1, area.Right - 1, area.Bottom - 1 );
1764                                         
1765                                         lgbr = new LinearGradientBrush( new Point( area.X + 2, area.Y ), new Point( area.Right - 2, area.Y ), first_gradient_color, second_gradient_color );
1766                                         dc.FillRectangle( lgbr, area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4 );
1767                                         
1768                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : Color.White );
1769                                         dc.DrawLine( tmp_pen, area.X + 1, area.Y + 1, area.X + 1, area.Bottom - 2 );
1770                                         dc.DrawLine( tmp_pen, area.X + 2, area.Y + 1, area.Right - 2, area.Y + 1 );
1771                                         
1772                                         tmp_pen = ResPool.GetPen( pushed ? pressed_inner_border_dark_color : inner_border_dark_color );
1773                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Y + 2, area.Right - 2, area.Bottom - 2 );
1774                                         dc.DrawLine( tmp_pen, area.X + 2, area.Bottom - 2, area.Right - 3, area.Bottom - 2 );
1775                                         
1776                                         tmp_pen = ResPool.GetPen( edge_top_inner_color );
1777                                         dc.DrawLine( tmp_pen, area.X, area.Bottom - 2, area.X + 1, area.Bottom - 1 );
1778                                         dc.DrawLine( tmp_pen, area.Right - 2, area.Bottom - 1, area.Right - 1, area.Bottom - 2 );
1779                                         
1780                                         points = new Point[] {
1781                                                 new Point( area.X, area.Y ),
1782                                                 new Point( area.Right - 1, area.Y ),
1783                                                 new Point( area.Right - 1, area.Bottom - 3 ),
1784                                                 new Point( area.Right - 3, area.Bottom - 1 ),
1785                                                 new Point( area.X + 2, area.Bottom - 1 ),
1786                                                 new Point( area.X, area.Bottom - 3 ),
1787                                                 new Point( area.X, area.Y )
1788                                         };
1789                                         dc.DrawPolygon( pen, points );
1790                                         break;
1791                         }
1792                         
1793                         lgbr.Dispose( );
1794                 }
1795                 
1796                 #region ToolBar
1797                 public override bool ToolBarInvalidateEntireButton {
1798                         get { return true; }
1799                 }
1800                 #endregion // ToolBar
1801
1802                 #region GroupBox
1803                 public override void DrawGroupBox( Graphics dc,  Rectangle area, GroupBox box ) {
1804                         StringFormat    text_format;
1805                         SizeF           size;
1806                         int             width;
1807                         int             y;
1808                         Rectangle       rect;
1809                         
1810                         rect = box.ClientRectangle;
1811                         
1812                         dc.FillRectangle( ResPool.GetSolidBrush( box.BackColor ), rect );
1813                         
1814                         text_format = new StringFormat( );
1815                         text_format.HotkeyPrefix = HotkeyPrefix.Show;
1816                         
1817                         size = dc.MeasureString( box.Text, box.Font );
1818                         width = (int) size.Width;
1819                         
1820                         if ( width > box.Width - 16 )
1821                                 width = box.Width - 16;
1822                         
1823                         y = box.Font.Height / 2;
1824                         
1825                         Pen pen = ResPool.GetPen( pressed_inner_border_dark_color );
1826                         
1827                         /* Draw group box*/
1828                         Point[] points = {
1829                                 new Point( 8 + width, y ),
1830                                 new Point( box.Width - 3, y ),
1831                                 new Point( box.Width - 1, y + 2 ),
1832                                 new Point( box.Width - 1, box.Height - 3 ),
1833                                 new Point( box.Width - 3, box.Height - 1 ),
1834                                 new Point( 2, box.Height - 1 ),
1835                                 new Point( 0, box.Height - 3 ),
1836                                 new Point( 0, y + 2 ),
1837                                 new Point( 2, y ),
1838                                 new Point( 8, y )
1839                         };
1840                         dc.DrawLines( pen, points );
1841                         
1842                         /* Text */
1843                         if ( box.Enabled ) {
1844                                 dc.DrawString( box.Text, box.Font, ResPool.GetSolidBrush( box.ForeColor ), 10, 0, text_format );
1845                         } else {
1846                                 CPDrawStringDisabled( dc, box.Text, box.Font, box.ForeColor, 
1847                                                      new RectangleF( 10, 0, width,  box.Font.Height ), text_format );
1848                         }
1849                         text_format.Dispose( ); 
1850                 }
1851                 #endregion
1852                 
1853                 #region TrackBar
1854                 private void DrawTrackBar_Vertical( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
1855                                                    ref Rectangle thumb_pos, ref Rectangle thumb_area,
1856                                                    float ticks, int value_pos, bool mouse_value ) {                     
1857                         
1858                         Point toptick_startpoint = new Point( );
1859                         Point bottomtick_startpoint = new Point( );
1860                         Point channel_startpoint = new Point( );
1861                         float pixel_len;
1862                         float pixels_betweenticks;
1863                         const int space_from_right = 8;
1864                         const int space_from_left = 8;
1865                         Rectangle area = tb.ClientRectangle;
1866                         
1867                         switch ( tb.TickStyle )         {
1868                                 case TickStyle.BottomRight:
1869                                 case TickStyle.None:
1870                                         channel_startpoint.Y = 8;
1871                                         channel_startpoint.X = 9;
1872                                         bottomtick_startpoint.Y = 13;
1873                                         bottomtick_startpoint.X = 24;                           
1874                                         break;
1875                                 case TickStyle.TopLeft:
1876                                         channel_startpoint.Y = 8;
1877                                         channel_startpoint.X = 19;
1878                                         toptick_startpoint.Y = 13;
1879                                         toptick_startpoint.X = 8;
1880                                         break;
1881                                 case TickStyle.Both:
1882                                         channel_startpoint.Y = 8;
1883                                         channel_startpoint.X = 18;      
1884                                         bottomtick_startpoint.Y = 13;
1885                                         bottomtick_startpoint.X = 32;                           
1886                                         toptick_startpoint.Y = 13;
1887                                         toptick_startpoint.X = 8;                               
1888                                         break;
1889                                 default:
1890                                         break;
1891                         }
1892                         
1893                         thumb_area.X = area.X + channel_startpoint.X;
1894                         thumb_area.Y = area.Y + channel_startpoint.Y;
1895                         thumb_area.Height = area.Height - space_from_right - space_from_left;
1896                         thumb_area.Width = 4;
1897                         
1898                         pixel_len = thumb_area.Height - 11;
1899                         pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
1900                         
1901                         /* Convert thumb position from mouse position to value*/
1902                         if ( mouse_value ) {
1903                                 
1904                                 if ( value_pos >= channel_startpoint.Y )
1905                                         value_pos = (int)( ( (float) ( value_pos - channel_startpoint.Y ) ) / pixels_betweenticks );
1906                                 else
1907                                         value_pos = 0;                  
1908                                 
1909                                 if ( value_pos + tb.Minimum > tb.Maximum )
1910                                         value_pos = tb.Maximum - tb.Minimum;
1911                                 
1912                                 tb.Value = value_pos + tb.Minimum;
1913                         }               
1914                         
1915                         thumb_pos.Width = 13;
1916                         thumb_pos.Height = 29;
1917                         
1918                         thumb_pos.Y = channel_startpoint.Y + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Height / 3 );
1919                         
1920                         if ( thumb_pos.Y < channel_startpoint.Y )
1921                                 thumb_pos.Y = channel_startpoint.Y;
1922                         
1923                         if ( thumb_pos.Y > thumb_area.Bottom - 29 )
1924                                 thumb_pos.Y = thumb_area.Bottom - 29;
1925                         
1926                         /* Draw channel */
1927                         // bottom
1928                         Pen pen = ResPool.GetPen( tab_top_border_focus_color );
1929                         dc.DrawLine( pen, channel_startpoint.X, thumb_pos.Y + 29, channel_startpoint.X, thumb_area.Bottom );
1930                         dc.DrawLine( pen, channel_startpoint.X, thumb_area.Bottom, channel_startpoint.X + 4, thumb_area.Bottom );
1931                         dc.DrawLine( pen, channel_startpoint.X + 4, thumb_pos.Y + 29, channel_startpoint.X + 4, thumb_area.Bottom );
1932                         
1933                         pen = ResPool.GetPen( menuitem_gradient_first_color );
1934                         dc.DrawLine( pen, channel_startpoint.X + 1, thumb_pos.Y + 28, channel_startpoint.X + 1, thumb_area.Bottom - 1 );
1935                         pen = ResPool.GetPen( trackbar_second_gradient_color );
1936                         dc.DrawLine( pen, channel_startpoint.X + 2, thumb_pos.Y + 28, channel_startpoint.X + 2, thumb_area.Bottom - 1 );
1937                         pen = ResPool.GetPen( trackbar_third_gradient_color );
1938                         dc.DrawLine( pen, channel_startpoint.X + 3, thumb_pos.Y + 28, channel_startpoint.X + 3, thumb_area.Bottom - 1 );
1939                         
1940                         // top
1941                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
1942                         dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, channel_startpoint.X + 1, thumb_pos.Y );
1943                         dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), channel_startpoint.X + 2, channel_startpoint.Y + 1, 1, thumb_pos.Y );
1944                         
1945                         pen = ResPool.GetPen( scrollbar_border_color );
1946                         dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, thumb_pos.Y );
1947                         dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X + 4, channel_startpoint.Y );
1948                         dc.DrawLine( pen, channel_startpoint.X + 4, channel_startpoint.Y, channel_startpoint.X + 4, thumb_pos.Y );
1949                         
1950                         /* Draw thumb */
1951                         thumb_pos.X = channel_startpoint.X - 4;
1952                         
1953                         // inner border
1954                         pen = ResPool.GetPen( Color.White );
1955                         dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
1956                         dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
1957                         
1958                         pen = ResPool.GetPen( menu_separator_color );
1959                         dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1960                         dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
1961                         
1962                         // outer border
1963                         Point[] points = {
1964                                 new Point( thumb_pos.X + 2, thumb_pos.Y ),
1965                                 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
1966                                 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
1967                                 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
1968                                 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
1969                                 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
1970                                 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
1971                                 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
1972                                 new Point( thumb_pos.X + 2, thumb_pos.Y )
1973                         };
1974                         
1975                         dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
1976                         
1977                         Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
1978                         Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
1979                         
1980                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
1981                                 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
1982                         }
1983                         
1984                         // outer egdes
1985                         pen = ResPool.GetPen( edge_top_inner_color );
1986                         dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
1987                         dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
1988                         
1989                         pen = ResPool.GetPen( edge_bottom_inner_color );
1990                         dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
1991                         dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
1992                         
1993                         // draw grip lines
1994                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
1995                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 11, thumb_pos.X + 8, thumb_pos.Y + 11 );
1996                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 14, thumb_pos.X + 8, thumb_pos.Y + 14 );
1997                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 17, thumb_pos.X + 8, thumb_pos.Y + 17 );
1998                         
1999                         pen = ResPool.GetPen( Color.White );
2000                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 12, thumb_pos.X + 8, thumb_pos.Y + 12 );
2001                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 15, thumb_pos.X + 8, thumb_pos.Y + 15 );
2002                         dc.DrawLine( pen, thumb_pos.X + 4, thumb_pos.Y + 18, thumb_pos.X + 8, thumb_pos.Y + 18 );
2003                         
2004                         pixel_len = thumb_area.Height - 11;
2005                         pixels_betweenticks = pixel_len / ticks;
2006                         
2007                         /* Draw ticks*/
2008                         thumb_area.X = thumb_pos.X;
2009                         thumb_area.Y = channel_startpoint.Y;
2010                         thumb_area.Width = thumb_pos.Width;
2011                         
2012                         Region outside = new Region( area );
2013                         outside.Exclude( thumb_area );                  
2014                         
2015                         if ( outside.IsVisible( clip_rectangle ) ) {                            
2016                                 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2017                                     ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {       
2018                                         
2019                                         for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks )      {                                       
2020                                                 if ( inc == 0 || ( inc +  pixels_betweenticks ) >= pixel_len + 1 )
2021                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y  + inc, 
2022                                                                     area.X + bottomtick_startpoint.X  + 3, area.Y + bottomtick_startpoint.Y + inc );
2023                                                 else
2024                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y  + inc, 
2025                                                                     area.X + bottomtick_startpoint.X  + 2, area.Y + bottomtick_startpoint.Y + inc );
2026                                         }
2027                                 }
2028                                 
2029                                 if ( pixels_betweenticks > 0 &&  ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2030                                     ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2031                                         
2032                                         pixel_len = thumb_area.Height - 11;
2033                                         pixels_betweenticks = pixel_len / ticks;
2034                                         
2035                                         for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {                                    
2036                                                 if ( inc == 0 || ( inc +  pixels_betweenticks ) >= pixel_len + 1 )
2037                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X  - 3 , area.Y + toptick_startpoint.Y + inc, 
2038                                                                     area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc );
2039                                                 else
2040                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X  - 2, area.Y + toptick_startpoint.Y + inc, 
2041                                                                     area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y  + inc );
2042                                         }                       
2043                                 }
2044                         }
2045                         
2046                         outside.Dispose( );
2047                         
2048                 }
2049                 
2050                 private void DrawTrackBar_Horizontal( Graphics dc, Rectangle clip_rectangle, TrackBar tb,
2051                                                      ref Rectangle thumb_pos, ref Rectangle thumb_area,
2052                                                      float ticks, int value_pos, bool mouse_value ) {                   
2053                         Point toptick_startpoint = new Point( );
2054                         Point bottomtick_startpoint = new Point( );
2055                         Point channel_startpoint = new Point( );
2056                         float pixel_len;
2057                         float pixels_betweenticks;
2058                         const int space_from_right = 8;
2059                         const int space_from_left = 8;
2060                         Rectangle area = tb.ClientRectangle;
2061                         
2062                         switch ( tb.TickStyle ) {
2063                                 case TickStyle.BottomRight:
2064                                 case TickStyle.None:
2065                                         channel_startpoint.X = 8;
2066                                         channel_startpoint.Y = 9;
2067                                         bottomtick_startpoint.X = 13;
2068                                         bottomtick_startpoint.Y = 24;                           
2069                                         break;
2070                                 case TickStyle.TopLeft:
2071                                         channel_startpoint.X = 8;
2072                                         channel_startpoint.Y = 19;
2073                                         toptick_startpoint.X = 13;
2074                                         toptick_startpoint.Y = 8;
2075                                         break;
2076                                 case TickStyle.Both:
2077                                         channel_startpoint.X = 8;
2078                                         channel_startpoint.Y = 18;      
2079                                         bottomtick_startpoint.X = 13;
2080                                         bottomtick_startpoint.Y = 32;                           
2081                                         toptick_startpoint.X = 13;
2082                                         toptick_startpoint.Y = 8;                               
2083                                         break;
2084                                 default:
2085                                         break;
2086                         }
2087                         
2088                         thumb_area.X = area.X + channel_startpoint.X;
2089                         thumb_area.Y = area.Y + channel_startpoint.Y;
2090                         thumb_area.Width = area.Width - space_from_right - space_from_left;
2091                         thumb_area.Height = 4;
2092                         
2093                         pixel_len = thumb_area.Width - 11;
2094                         pixels_betweenticks = pixel_len / ( tb.Maximum - tb.Minimum );
2095                         
2096                         /* Convert thumb position from mouse position to value*/
2097                         if ( mouse_value ) {                    
2098                                 if ( value_pos >= channel_startpoint.X )
2099                                         value_pos = (int)( ( (float) ( value_pos - channel_startpoint.X ) ) / pixels_betweenticks );
2100                                 else
2101                                         value_pos = 0;                          
2102                                 
2103                                 if ( value_pos + tb.Minimum > tb.Maximum )
2104                                         value_pos = tb.Maximum - tb.Minimum;
2105                                 
2106                                 tb.Value = value_pos + tb.Minimum;
2107                         }                       
2108                         
2109                         thumb_pos.Width = 29;
2110                         thumb_pos.Height = 13;
2111                         
2112                         thumb_pos.X = channel_startpoint.X + (int) ( pixels_betweenticks * (float) value_pos ) - ( thumb_pos.Width / 3 );
2113                         
2114                         if ( thumb_pos.X < channel_startpoint.X )
2115                                 thumb_pos.X = channel_startpoint.X;
2116                         
2117                         if ( thumb_pos.X > thumb_area.Right - 29 )
2118                                 thumb_pos.X = thumb_area.Right - 29;
2119                         
2120                         /* Draw channel */
2121                         // left side
2122                         Pen pen = ResPool.GetPen( tab_top_border_focus_color );
2123                         dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, thumb_pos.X, channel_startpoint.Y );
2124                         dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y, channel_startpoint.X, channel_startpoint.Y + 4 );
2125                         dc.DrawLine( pen, channel_startpoint.X, channel_startpoint.Y + 4, thumb_pos.X, channel_startpoint.Y + 4 );
2126                         
2127                         pen = ResPool.GetPen( menuitem_gradient_first_color );
2128                         dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 1, thumb_pos.X, channel_startpoint.Y + 1 );
2129                         pen = ResPool.GetPen( trackbar_second_gradient_color );
2130                         dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 2, thumb_pos.X, channel_startpoint.Y + 2 );
2131                         pen = ResPool.GetPen( trackbar_third_gradient_color );
2132                         dc.DrawLine( pen, channel_startpoint.X + 1, channel_startpoint.Y + 3, thumb_pos.X, channel_startpoint.Y + 3 );
2133                         
2134                         // right side
2135                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
2136                         dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 1, thumb_area.Right - 1, channel_startpoint.Y + 1 );
2137                         dc.DrawRectangle( ResPool.GetPen( scrollbar_background_color ), thumb_pos.X + 29, channel_startpoint.Y + 2, thumb_area.Right - thumb_pos.X - 30, 1 );
2138                         
2139                         pen = ResPool.GetPen( scrollbar_border_color );
2140                         dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y );
2141                         dc.DrawLine( pen, thumb_area.Right, channel_startpoint.Y, thumb_area.Right, channel_startpoint.Y + 4 );
2142                         dc.DrawLine( pen, thumb_pos.X + 29, channel_startpoint.Y + 4, thumb_area.Right, channel_startpoint.Y + 4 );
2143                         
2144                         /* Draw thumb */
2145                         
2146                         thumb_pos.Y = channel_startpoint.Y - 4;
2147                         
2148                         // inner border
2149                         pen = ResPool.GetPen( Color.White );
2150                         dc.DrawLine( pen, thumb_pos.X + 1, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Bottom - 2 );
2151                         dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Y + 1, thumb_pos.Right - 2, thumb_pos.Y + 1 );
2152                         
2153                         pen = ResPool.GetPen( menu_separator_color );
2154                         dc.DrawLine( pen, thumb_pos.X + 2, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2155                         dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y + 2, thumb_pos.Right - 2, thumb_pos.Bottom - 2 );
2156                         
2157                         // outer border
2158                         Point[] points = {
2159                                 new Point( thumb_pos.X + 2, thumb_pos.Y ),
2160                                 new Point( thumb_pos.Right - 3 , thumb_pos.Y ),
2161                                 new Point( thumb_pos.Right - 1, thumb_pos.Y + 2 ),
2162                                 new Point( thumb_pos.Right - 1, thumb_pos.Bottom - 3 ),
2163                                 new Point( thumb_pos.Right - 3, thumb_pos.Bottom - 1 ),
2164                                 new Point( thumb_pos.X + 2, thumb_pos.Bottom - 1 ),
2165                                 new Point( thumb_pos.X, thumb_pos.Bottom - 3 ),
2166                                 new Point( thumb_pos.X, thumb_pos.Y + 2 ),
2167                                 new Point( thumb_pos.X + 2, thumb_pos.Y )
2168                         };
2169                         
2170                         dc.DrawLines( ResPool.GetPen( border_normal_dark_color ), points );
2171                         
2172                         Color first_gradient_color = mouse_value ? button_edge_bottom_outer_color : trackbar_inner_first_gradient_color;
2173                         Color second_gradient_color = mouse_value ? trackbar_inner_pressed_second_gradient_color : trackbar_inner_second_gradient_color;
2174                         
2175                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( thumb_pos.X, thumb_pos.Y + 2 ), new Point( thumb_pos.X, thumb_pos.Bottom - 2 ), first_gradient_color, second_gradient_color ) ) {
2176                                 dc.FillRectangle( lgbr, thumb_pos.X + 2, thumb_pos.Y + 2, thumb_pos.Width - 4, thumb_pos.Height - 4 );
2177                         }
2178                         
2179                         // outer egdes
2180                         pen = ResPool.GetPen( edge_top_inner_color );
2181                         dc.DrawLine( pen, thumb_pos.X, thumb_pos.Y + 1, thumb_pos.X + 1, thumb_pos.Y );
2182                         dc.DrawLine( pen, thumb_pos.Right - 2, thumb_pos.Y, thumb_pos.Right - 1, thumb_pos.Y + 1 );
2183                         
2184                         pen = ResPool.GetPen( edge_bottom_inner_color );
2185                         dc.DrawLine( pen, thumb_pos.X, thumb_pos.Bottom - 2, thumb_pos.X + 1, thumb_pos.Bottom - 1 );
2186                         dc.DrawLine( pen, thumb_pos.Right - 1, thumb_pos.Bottom - 2, thumb_pos.Right - 2, thumb_pos.Bottom - 1 );
2187                         
2188                         // draw grip lines
2189                         pen = ResPool.GetPen( pressed_inner_border_dark_color );
2190                         dc.DrawLine( pen, thumb_pos.X + 11, thumb_pos.Y + 4, thumb_pos.X + 11, thumb_pos.Y + 8 );
2191                         dc.DrawLine( pen, thumb_pos.X + 14, thumb_pos.Y + 4, thumb_pos.X + 14, thumb_pos.Y + 8 );
2192                         dc.DrawLine( pen, thumb_pos.X + 17, thumb_pos.Y + 4, thumb_pos.X + 17, thumb_pos.Y + 8 );
2193                         
2194                         pen = ResPool.GetPen( Color.White );
2195                         dc.DrawLine( pen, thumb_pos.X + 12, thumb_pos.Y + 4, thumb_pos.X  + 12, thumb_pos.Y + 8 );
2196                         dc.DrawLine( pen, thumb_pos.X + 15, thumb_pos.Y + 4, thumb_pos.X + 15, thumb_pos.Y + 8 );
2197                         dc.DrawLine( pen, thumb_pos.X + 18, thumb_pos.Y + 4, thumb_pos.X + 18, thumb_pos.Y + 8 );
2198                         
2199                         pixel_len = thumb_area.Width - 11;
2200                         pixels_betweenticks = pixel_len / ticks;
2201                         
2202                         /* Draw ticks*/
2203                         thumb_area.Y = thumb_pos.Y;
2204                         thumb_area.X = channel_startpoint.X;
2205                         thumb_area.Height = thumb_pos.Height;
2206                         Region outside = new Region( area );
2207                         outside.Exclude( thumb_area );                  
2208                         
2209                         if ( outside.IsVisible( clip_rectangle ) ) {                            
2210                                 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.BottomRight ) == TickStyle.BottomRight ||
2211                                     ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {                               
2212                                         
2213                                         for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {                                    
2214                                                 if ( inc == 0 || ( inc +  pixels_betweenticks ) >= pixel_len + 1 )
2215                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y, 
2216                                                                     area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3 );
2217                                                 else
2218                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y, 
2219                                                                     area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2 );
2220                                         }
2221                                 }
2222                                 
2223                                 if ( pixels_betweenticks > 0 && ( ( tb.TickStyle & TickStyle.TopLeft ) == TickStyle.TopLeft ||
2224                                     ( ( tb.TickStyle & TickStyle.Both ) == TickStyle.Both ) ) ) {
2225                                         
2226                                         for ( float inc = 0; inc < ( pixel_len + 1 ); inc += pixels_betweenticks ) {                                    
2227                                                 if ( inc == 0 || ( inc +  pixels_betweenticks ) >= pixel_len + 1 )
2228                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3, 
2229                                                                     area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y );
2230                                                 else
2231                                                         dc.DrawLine( ResPool.GetPen( pen_ticks_color ), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2, 
2232                                                                     area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
2233                                         }                       
2234                                 }
2235                         }
2236                         
2237                         outside.Dispose( );                     
2238                 }
2239                 
2240                 public override void DrawTrackBar( Graphics dc, Rectangle clip_rectangle, TrackBar tb ) {
2241                         int             value_pos;
2242                         bool            mouse_value;
2243                         float           ticks = ( tb.Maximum - tb.Minimum ) / tb.tickFrequency; /* N of ticks draw*/
2244                         Rectangle       area;
2245                         Rectangle       thumb_pos = tb.ThumbPos;
2246                         Rectangle       thumb_area = tb.ThumbArea;
2247                         
2248                         if ( tb.thumb_pressed ) {
2249                                 value_pos = tb.thumb_mouseclick;
2250                                 mouse_value = true;
2251                         } else {
2252                                 value_pos = tb.Value - tb.Minimum;
2253                                 mouse_value = false;
2254                         }
2255                         
2256                         area = tb.ClientRectangle;
2257                         
2258                         /* Control Background */
2259                         if ( tb.BackColor == DefaultControlBackColor ) {
2260                                 dc.FillRectangle( ResPool.GetSolidBrush( ColorControl ), clip_rectangle );
2261                         } else {
2262                                 dc.FillRectangle( ResPool.GetSolidBrush( tb.BackColor ), clip_rectangle );
2263                         }
2264                         
2265                         if ( tb.Orientation == Orientation.Vertical ) {
2266                                 DrawTrackBar_Vertical( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2267                                                       ticks, value_pos, mouse_value );
2268                                 
2269                         } else {
2270                                 DrawTrackBar_Horizontal( dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
2271                                                         ticks, value_pos, mouse_value );
2272                         }
2273                         
2274                         // TODO: draw better focus rectangle
2275                         if ( tb.Focused ) {
2276                                 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, area.Width - 1, 1 );
2277                                 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y + area.Height - 1, area.Width - 1, 1 );
2278                                 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X, area.Y, 1, area.Height - 1 );
2279                                 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControl, Color.Black ), area.X + area.Width - 1, area.Y, 1, area.Height - 1 );
2280                         }
2281                         
2282                         tb.ThumbPos = thumb_pos;
2283                         tb.ThumbArea = thumb_area;
2284                 }
2285                 #endregion      // TrackBar
2286                 
2287                 #region ListView
2288                 // draws the ListViewItem of the given index
2289                 protected override void DrawListViewItem( Graphics dc, ListView control, ListViewItem item ) {                          
2290                         Rectangle rect_checkrect = item.CheckRectReal;
2291                         Rectangle rect_iconrect = item.GetBounds( ItemBoundsPortion.Icon );
2292                         Rectangle full_rect = item.GetBounds( ItemBoundsPortion.Entire );
2293                         Rectangle text_rect = item.GetBounds( ItemBoundsPortion.Label );                        
2294                         
2295                         if ( control.CheckBoxes ) {
2296                                 if ( control.StateImageList == null ) {
2297                                         // Make sure we've got at least a line width of 1
2298                                         int check_wd = Math.Max( 3, rect_checkrect.Width / 6 );
2299                                         int scale = Math.Max( 1, rect_checkrect.Width / 12 );
2300                                         
2301                                         // set the checkbox background
2302                                         dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorWindow ),
2303                                                          rect_checkrect );
2304                                         // define a rectangle inside the border area
2305                                         Rectangle rect = new Rectangle( rect_checkrect.X + 2,
2306                                                                        rect_checkrect.Y + 2,
2307                                                                        rect_checkrect.Width - 4,
2308                                                                        rect_checkrect.Height - 4 );
2309                                         Pen pen = new Pen( this.ColorWindowText, 2 );
2310                                         dc.DrawRectangle( pen, rect );
2311                                         
2312                                         // Need to draw a check-mark
2313                                         if ( item.Checked ) {
2314                                                 pen.Width = 1;
2315                                                 // adjustments to get the check-mark at the right place
2316                                                 rect.X ++; rect.Y ++;
2317                                                 // following logic is taken from DrawFrameControl method
2318                                                 for ( int i = 0; i < check_wd; i++ ) {
2319                                                         dc.DrawLine( pen, rect.Left + check_wd / 2,
2320                                                                     rect.Top + check_wd + i,
2321                                                                     rect.Left + check_wd / 2 + 2 * scale,
2322                                                                     rect.Top + check_wd + 2 * scale + i );
2323                                                         dc.DrawLine( pen,
2324                                                                     rect.Left + check_wd / 2 + 2 * scale,
2325                                                                     rect.Top + check_wd + 2 * scale + i,
2326                                                                     rect.Left + check_wd / 2 + 6 * scale,
2327                                                                     rect.Top + check_wd - 2 * scale + i );
2328                                                 }
2329                                         }
2330                                 } else {
2331                                         if ( item.Checked && control.StateImageList.Images.Count > 1 )
2332                                                 control.StateImageList.Draw( dc,
2333                                                                             rect_checkrect.Location, 1 );
2334                                         else if ( ! item.Checked && control.StateImageList.Images.Count > 0 )
2335                                                 control.StateImageList.Draw( dc,
2336                                                                             rect_checkrect.Location, 0 );
2337                                 }
2338                         }
2339                         
2340                         // Item is drawn as a special case, as it is not just text
2341                         if ( control.View == View.LargeIcon ) {
2342                                 if ( item.ImageIndex > -1 &&
2343                                     control.LargeImageList != null &&
2344                                     item.ImageIndex < control.LargeImageList.Images.Count ) {
2345                                         // center image
2346                                         Point image_location = rect_iconrect.Location;
2347                                         Image image = control.LargeImageList.Images[ item.ImageIndex ];
2348                                         if ( image.Width < rect_iconrect.Width ) {
2349                                                 int icon_rect_middle = rect_iconrect.Width / 2;
2350                                                 int image_middle = image.Width / 2;
2351                                                 image_location.X = image_location.X + icon_rect_middle - image_middle;
2352                                         }
2353                                         control.LargeImageList.Draw( dc, image_location,
2354                                                                     item.ImageIndex );
2355                                 }
2356                         } else {
2357                                 if ( item.ImageIndex > -1 &&
2358                                     control.SmallImageList != null &&
2359                                     item.ImageIndex < control.SmallImageList.Images.Count )
2360                                         control.SmallImageList.Draw( dc, rect_iconrect.Location,
2361                                                                     item.ImageIndex );
2362                         }
2363                         
2364                         // draw the item text                   
2365                         // format for the item text
2366                         StringFormat format = new StringFormat( );
2367                         format.LineAlignment = StringAlignment.Center;
2368                         if ( control.View == View.LargeIcon )
2369                                 format.Alignment = StringAlignment.Center; 
2370                         else
2371                                 format.Alignment = StringAlignment.Near;
2372                         
2373                         if ( !control.LabelWrap )
2374                                 format.FormatFlags = StringFormatFlags.NoWrap;
2375                         
2376                         if ( item.Selected ) {
2377                                 if ( control.View == View.Details ) {
2378                                         if ( control.FullRowSelect ) {
2379                                                 // fill the entire rect excluding the checkbox                                          
2380                                                 full_rect.Location = item.GetBounds (ItemBoundsPortion.Label).Location;
2381                                                 dc.FillRectangle( this.ResPool.GetSolidBrush
2382                                                                  ( this.ColorHighlight ), full_rect );
2383                                         } else {
2384                                                 Size text_size = Size.Ceiling( dc.MeasureString( item.Text,
2385                                                                                                 item.Font ) );
2386                                                 text_rect.Width = text_size.Width;
2387                                                 dc.FillRectangle( this.ResPool.GetSolidBrush
2388                                                                  ( this.ColorHighlight ), text_rect );
2389                                         }
2390                                 } else {
2391                                         /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
2392                                          item.Font));
2393                                          Point loc = text_rect.Location;
2394                                          loc.X += (text_rect.Width - text_size.Width) / 2;
2395                                          text_rect.Width = text_size.Width;*/
2396                                         dc.FillRectangle( this.ResPool.GetSolidBrush( this.ColorHighlight ),
2397                                                          text_rect );
2398                                 }
2399                         } else
2400                                 dc.FillRectangle( ResPool.GetSolidBrush( item.BackColor ), text_rect );
2401                         
2402                         if ( item.Text != null && item.Text.Length > 0 ) {
2403                                 
2404                                 if ( control.View != View.LargeIcon ) {
2405                                         if ( item.Selected )
2406                                                 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2407                                                               ( this.ColorHighlightText ), text_rect, format );
2408                                         else
2409                                                 dc.DrawString( item.Text, item.Font, this.ResPool.GetSolidBrush
2410                                                               ( item.ForeColor ), text_rect, format );
2411                                 } else {
2412                                         // ListView CalcTextSize says wrapping is done for two lines only !?!
2413                                         // text is centered for the complete text_rect but it should be centered per available row/line
2414                                         
2415                                         // calculate how much lines we get out of text_rect and current item.Font
2416                                         int nr_lines = text_rect.Height / item.Font.Height;
2417                                         int rest = text_rect.Height % item.Font.Height;
2418                                         int line_height = item.Font.Height + ( rest > 1 ? 2 : 0 );
2419                                         
2420                                         Rectangle[] text_rects = new Rectangle[ nr_lines ];
2421                                         
2422                                         for ( int i = 0; i < nr_lines; i++ ) {
2423                                                 text_rects[ i ].X = text_rect.X;
2424                                                 text_rects[ i ].Y = text_rect.Y + i * line_height;
2425                                                 text_rects[ i ].Width = text_rect.Width;
2426                                                 text_rects[ i ].Height = line_height;
2427                                         }
2428                                         
2429                                         string[] lines = new string[ nr_lines ];
2430                                         
2431                                         string text = item.Text;
2432                                         
2433                                         int line_nr = 0;
2434                                         int current_pos = 0;
2435                                         for ( int k = 1; k <= text.Length; k++ ) {
2436                                                 lines[ line_nr ] = text.Substring( current_pos, k - current_pos );
2437                                                 
2438                                                 // FIXME: Graphics.MeasureString returns wrong results if there is a 
2439                                                 //        space char in the string
2440                                                 SizeF sizef = dc.MeasureString( lines[ line_nr ], item.Font, text_rect.Width, format );
2441                                                 
2442                                                 if ( (int)sizef.Width > text_rect.Width - 3 ) {
2443                                                         lines[ line_nr ] = lines[ line_nr ].Remove( lines[ line_nr ].Length - 1, 1 );
2444                                                         k--;
2445                                                         current_pos = k;
2446                                                         line_nr++;
2447                                                         if ( line_nr == nr_lines )
2448                                                                 break;
2449                                                 }
2450                                         }
2451                                         
2452                                         int j = 0;
2453                                         foreach ( Rectangle t_rect in text_rects ) {
2454                                                 if ( item.Selected )
2455                                                         dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2456                                                                       ( this.ColorHighlightText ), t_rect, format );
2457                                                 else
2458                                                         dc.DrawString( lines[ j ], item.Font, this.ResPool.GetSolidBrush
2459                                                                       ( item.ForeColor ), t_rect, format );
2460                                                 j++;
2461                                         }
2462                                 } 
2463                         }
2464                         
2465                         if ( control.View == View.Details && control.Columns.Count > 0 ) {
2466                                 // draw subitems for details view
2467                                 ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
2468                                 int count = ( control.Columns.Count < subItems.Count ? 
2469                                         control.Columns.Count : subItems.Count );
2470                                 
2471                                 if ( count > 0 ) {
2472                                         ColumnHeader col;
2473                                         ListViewItem.ListViewSubItem subItem;
2474                                         Rectangle sub_item_rect = text_rect; 
2475                                         
2476                                         // set the format for subitems
2477                                         format.FormatFlags = StringFormatFlags.NoWrap;
2478                                         format.Alignment = StringAlignment.Near;
2479                                         
2480                                         // 0th subitem is the item already drawn
2481                                         for ( int index = 1; index < count; index++ ) {
2482                                                 subItem = subItems[ index ];
2483                                                 col = control.Columns[ index ];
2484                                                 sub_item_rect.X = col.Rect.Left;
2485                                                 sub_item_rect.Width = col.Wd;
2486                                                 sub_item_rect.X -= control.h_marker;
2487                                                 
2488                                                 SolidBrush sub_item_back_br = null;
2489                                                 SolidBrush sub_item_fore_br = null;
2490                                                 Font sub_item_font = null;
2491                                                 
2492                                                 if ( item.UseItemStyleForSubItems ) {
2493                                                         sub_item_back_br = this.ResPool.GetSolidBrush
2494                                                         ( item.BackColor );
2495                                                         sub_item_fore_br = this.ResPool.GetSolidBrush
2496                                                         ( item.ForeColor );
2497                                                         sub_item_font = item.Font;
2498                                                 } else {
2499                                                         sub_item_back_br = this.ResPool.GetSolidBrush
2500                                                         ( subItem.BackColor );
2501                                                         sub_item_fore_br = this.ResPool.GetSolidBrush
2502                                                         ( subItem.ForeColor );
2503                                                         sub_item_font = subItem.Font;
2504                                                 }
2505                                                 
2506                                                 // In case of fullrowselect, background is filled
2507                                                 // for the entire rect above
2508                                                 if ( item.Selected && control.FullRowSelect ) {
2509                                                         if ( subItem.Text != null && subItem.Text.Length > 0 )
2510                                                                 dc.DrawString( subItem.Text, sub_item_font,
2511                                                                               this.ResPool.GetSolidBrush
2512                                                                               ( this.ColorHighlightText ),
2513                                                                               sub_item_rect, format );
2514                                                 } else {
2515                                                         dc.FillRectangle( sub_item_back_br, sub_item_rect );
2516                                                         if ( subItem.Text != null && subItem.Text.Length > 0 )
2517                                                                 dc.DrawString( subItem.Text, sub_item_font,
2518                                                                               sub_item_fore_br,
2519                                                                               sub_item_rect, format );
2520                                                 }
2521                                                 sub_item_rect.X += col.Wd;
2522                                         }
2523                                 }
2524                         }
2525                         
2526                         if ( item.Focused ) {                           
2527                                 if ( item.Selected )
2528                                         CPDrawFocusRectangle( dc, text_rect, ColorHighlightText, ColorHighlight );
2529                                 else
2530                                         CPDrawFocusRectangle( dc, text_rect, control.ForeColor, control.BackColor );
2531                         }
2532                         
2533                         format.Dispose( );
2534                 }
2535                 #endregion ListView
2536                 
2537                 #region DateTimePicker
2538                 public override void DrawDateTimePicker (Graphics dc,  Rectangle clip_rectangle, DateTimePicker dtp) {
2539                         // if not showing the numeric updown control then render border
2540                         if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
2541                                 // draw the outer border
2542                                 Rectangle button_bounds = dtp.ClientRectangle;
2543                                 CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
2544                                 
2545                                 // deflate by the border width
2546                                 if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
2547                                         button_bounds.Inflate (-2,-2);
2548                                         ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
2549                                         Rectangle button_rect = new Rectangle(dtp.drop_down_arrow_rect.X, dtp.drop_down_arrow_rect.Y + 1,
2550                                                                               dtp.drop_down_arrow_rect.Width - 1, dtp.drop_down_arrow_rect.Height - 2);
2551                                         this.CPDrawComboButton ( 
2552                                                 dc, 
2553                                                 button_rect, 
2554                                                 state);
2555                                 }
2556                         }
2557                         
2558                         // render the date part
2559                         if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
2560                                 // fill the background
2561                                 Rectangle date_area_rect = new Rectangle( dtp.date_area_rect.X + 1, dtp.date_area_rect.Y + 1,
2562                                                                          dtp.date_area_rect.Width - 2,  dtp.date_area_rect.Height - 2);
2563                                 dc.FillRectangle (ResPool.GetSolidBrush (ColorWindow), date_area_rect);
2564                                 
2565                                 // fill the currently highlighted area
2566                                 if (dtp.hilight_date_area != Rectangle.Empty) {
2567                                         dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), dtp.hilight_date_area);
2568                                 }
2569                                 
2570                                 // draw the text part
2571                                 // TODO: if date format is CUstom then we need to draw the dates as separate parts
2572                                 StringFormat text_format = new StringFormat();
2573                                 text_format.LineAlignment = StringAlignment.Center;
2574                                 text_format.Alignment = StringAlignment.Near;                                   
2575                                 dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
2576                                 text_format.Dispose ();
2577                         }
2578                 }
2579                 #endregion // DateTimePicker
2580                 
2581                 #region MonthCalendar
2582                 // draw the month calendar
2583                 public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc) 
2584                 {
2585                         Rectangle client_rectangle = mc.ClientRectangle;
2586                         Size month_size = mc.SingleMonthSize;
2587                         // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2588                         Size calendar_spacing = (Size)((object)mc.calendar_spacing);
2589                         Size date_cell_size = (Size)((object)mc.date_cell_size);
2590                         
2591                         // draw the singlecalendars
2592                         int x_offset = 1;
2593                         int y_offset = 1;
2594                         // adjust for the position of the specific month
2595                         for (int i=0; i < mc.CalendarDimensions.Height; i++) 
2596                         {
2597                                 if (i > 0) 
2598                                 {
2599                                         y_offset += month_size.Height + calendar_spacing.Height;
2600                                 }
2601                                 // now adjust for x position    
2602                                 for (int j=0; j < mc.CalendarDimensions.Width; j++) 
2603                                 {
2604                                         if (j > 0) 
2605                                         {
2606                                                 x_offset += month_size.Width + calendar_spacing.Width;
2607                                         } 
2608                                         else 
2609                                         {
2610                                                 x_offset = 1;
2611                                         }
2612                                         
2613                                         Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
2614                                         if (month_rect.IntersectsWith (clip_rectangle)) {
2615                                                 DrawSingleMonth (
2616                                                         dc,
2617                                                         clip_rectangle,
2618                                                         month_rect,
2619                                                         mc,
2620                                                         i,
2621                                                         j);
2622                                         }
2623                                 }
2624                         }
2625                         
2626                         Rectangle bottom_rect = new Rectangle (
2627                                 client_rectangle.X,
2628                                 Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
2629                                 client_rectangle.Width,
2630                                 date_cell_size.Height + 2);
2631                         // draw the today date if it's set
2632                         if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle)) 
2633                         {
2634                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
2635                                 if (mc.ShowToday) {
2636                                         int today_offset = 5;
2637                                         if (mc.ShowTodayCircle) 
2638                                         {
2639                                                 Rectangle today_circle_rect = new Rectangle (
2640                                                         client_rectangle.X + 5,
2641                                                         Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
2642                                                         date_cell_size.Width,
2643                                                         date_cell_size.Height);
2644                                                 DrawTodayCircle (dc, today_circle_rect);
2645                                                 today_offset += date_cell_size.Width + 5;
2646                                         }
2647                                         // draw today's date
2648                                         StringFormat text_format = new StringFormat();
2649                                         text_format.LineAlignment = StringAlignment.Center;
2650                                         text_format.Alignment = StringAlignment.Near;
2651                                         Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
2652                                         Rectangle today_rect = new Rectangle (
2653                                                 today_offset + client_rectangle.X,
2654                                                 Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
2655                                                 Math.Max(client_rectangle.Width - today_offset, 0),
2656                                                 date_cell_size.Height);
2657                                         dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
2658                                         text_format.Dispose ();
2659                                         bold_font.Dispose ();
2660                                 }                               
2661                         }
2662                         
2663                         // finally paint the borders of the calendars as required
2664                         for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
2665                                 if (i == 0 && clip_rectangle.X == client_rectangle.X) {
2666                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
2667                                 } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
2668                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
2669                                 } else { 
2670                                         Rectangle rect = new Rectangle (
2671                                                 client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
2672                                                 client_rectangle.Y,
2673                                                 calendar_spacing.Width,
2674                                                 client_rectangle.Height);
2675                                         if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2676                                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2677                                         }
2678                                 }
2679                         }
2680                         for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
2681                                 if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
2682                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
2683                                 } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
2684                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
2685                                 } else { 
2686                                         Rectangle rect = new Rectangle (
2687                                                 client_rectangle.X,
2688                                                 client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
2689                                                 client_rectangle.Width,
2690                                                 calendar_spacing.Height);
2691                                         if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
2692                                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
2693                                         }
2694                                 }
2695                         }
2696                         
2697                         // draw the drop down border if need
2698                         if (mc.owner != null) {
2699                                 Rectangle bounds = mc.ClientRectangle;
2700                                 if (clip_rectangle.Contains (mc.Location)) {
2701                                         // find out if top or left line to draw
2702                                         if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2703                                                 
2704                                                 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
2705                                         }
2706                                         if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2707                                                 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
2708                                         }
2709                                 }
2710                                 if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
2711                                         // find out if bottom or right line to draw
2712                                         if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
2713                                                 dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
2714                                         }
2715                                         if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
2716                                                 dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
2717                                         }
2718                                 }
2719                         }
2720                 }
2721                 
2722                 // darws a single part of the month calendar (with one month)
2723                 private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col) 
2724                 {
2725                         // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
2726                         Size title_size = (Size)((object)mc.title_size);
2727                         Size date_cell_size = (Size)((object)mc.date_cell_size);
2728                         DateTime current_month = (DateTime)((object)mc.current_month);
2729                         
2730                         // set up some standard string formating variables
2731                         StringFormat text_format = new StringFormat();
2732                         text_format.LineAlignment = StringAlignment.Center;
2733                         text_format.Alignment = StringAlignment.Center;
2734                         
2735                         
2736                         // draw the title back ground
2737                         DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
2738                         Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
2739                         if (title_rect.IntersectsWith (clip_rectangle)) {
2740                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
2741                                 // draw the title                               
2742                                 string title_text = this_month.ToString ("MMMM yyyy");
2743                                 dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
2744                                 
2745                                 // draw previous and next buttons if it's time
2746                                 if (row == 0 && col == 0) 
2747                                 {
2748                                         // draw previous button
2749                                         DrawMonthCalendarButton (
2750                                                 dc,
2751                                                 rectangle,
2752                                                 mc,
2753                                                 title_size,
2754                                                 mc.button_x_offset,
2755                                                 (System.Drawing.Size)((object)mc.button_size),
2756                                                 true);
2757                                 }
2758                                 if (row == 0 && col == mc.CalendarDimensions.Width-1) 
2759                                 {
2760                                         // draw next button
2761                                         DrawMonthCalendarButton (
2762                                                 dc,
2763                                                 rectangle,
2764                                                 mc,
2765                                                 title_size,
2766                                                 mc.button_x_offset,
2767                                                 (System.Drawing.Size)((object)mc.button_size),
2768                                                 false);
2769                                 }
2770                         }
2771                         
2772                         // set the week offset and draw week nums if needed
2773                         int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
2774                         Rectangle day_name_rect = new Rectangle(
2775                                 rectangle.X,
2776                                 rectangle.Y + title_size.Height,
2777                                 (7 + col_offset) * date_cell_size.Width,
2778                                 date_cell_size.Height);
2779                         if (day_name_rect.IntersectsWith (clip_rectangle)) {
2780                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
2781                                 // draw the day names 
2782                                 DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
2783                                 for (int i=0; i < 7; i++) 
2784                                 {
2785                                         int position = i - (int) first_day_of_week;
2786                                         if (position < 0) 
2787                                         {
2788                                                 position = 7 + position;
2789                                         }
2790                                         // draw it
2791                                         Rectangle day_rect = new Rectangle(
2792                                                 day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
2793                                                 day_name_rect.Y,
2794                                                 date_cell_size.Width,
2795                                                 date_cell_size.Height);
2796                                         dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
2797                                 }
2798                                 
2799                                 // draw the vertical divider
2800                                 int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
2801                                 dc.DrawLine (
2802                                         ResPool.GetPen (mc.ForeColor),
2803                                         rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
2804                                         rectangle.Y + vert_divider_y,
2805                                         rectangle.Right - mc.divider_line_offset,
2806                                         rectangle.Y + vert_divider_y);
2807                         }
2808                         
2809                         
2810                         // draw the actual date items in the grid (including the week numbers)
2811                         Rectangle date_rect = new Rectangle (
2812                                 rectangle.X,
2813                                 rectangle.Y + title_size.Height + date_cell_size.Height,
2814                                 date_cell_size.Width,
2815                                 date_cell_size.Height);
2816                         int month_row_count = 0;
2817                         bool draw_week_num_divider = false;
2818                         DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
2819                         for (int i=0; i < 6; i++) 
2820                         {
2821                                 // establish if this row is in our clip_area
2822                                 Rectangle row_rect = new Rectangle (
2823                                         rectangle.X,
2824                                         rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
2825                                         date_cell_size.Width * 7,
2826                                         date_cell_size.Height);
2827                                 if (mc.ShowWeekNumbers) {
2828                                         row_rect.Width += date_cell_size.Width;
2829                                 }
2830                                 
2831                                 bool draw_row = row_rect.IntersectsWith (clip_rectangle);
2832                                 if (draw_row) {
2833                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
2834                                 }
2835                                 // establish if this is a valid week to draw
2836                                 if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
2837                                         month_row_count = i;
2838                                 }
2839                                 
2840                                 // draw the week number if required
2841                                 if (mc.ShowWeekNumbers && month_row_count == i) {
2842                                         if (!draw_week_num_divider) {
2843                                                 draw_week_num_divider = draw_row;
2844                                         }
2845                                         // get the week for this row
2846                                         int week = mc.GetWeekOfYear (current_date);     
2847                                         
2848                                         if (draw_row) {
2849                                                 dc.DrawString (
2850                                                         week.ToString(),
2851                                                         mc.Font,
2852                                                         ResPool.GetSolidBrush (mc.TitleBackColor),
2853                                                         date_rect,
2854                                                         text_format);
2855                                         }
2856                                         date_rect.Offset(date_cell_size.Width, 0);
2857                                 }
2858                                 
2859                                 // only draw the days if we have to
2860                                 if(month_row_count == i) {
2861                                         for (int j=0; j < 7; j++) 
2862                                         {
2863                                                 if (draw_row) {
2864                                                         DrawMonthCalendarDate (
2865                                                                 dc,
2866                                                                 date_rect,
2867                                                                 mc,
2868                                                                 current_date,
2869                                                                 this_month,
2870                                                                 row,
2871                                                                 col);
2872                                                 }
2873                                                 
2874                                                 // move the day on
2875                                                 current_date = current_date.AddDays(1);
2876                                                 date_rect.Offset(date_cell_size.Width, 0);
2877                                         }
2878                                         
2879                                         // shift the rectangle down one row
2880                                         int offset = (mc.ShowWeekNumbers) ? -8 : -7;
2881                                         date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
2882                                 }
2883                         }
2884                         
2885                         // month_row_count is zero based, so add one
2886                         month_row_count++;
2887                         
2888                         // draw week numbers if required
2889                         if (draw_week_num_divider) {
2890                                 col_offset = 1;
2891                                 dc.DrawLine (
2892                                         ResPool.GetPen (mc.ForeColor),
2893                                         rectangle.X + date_cell_size.Width - 1,
2894                                         rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
2895                                         rectangle.X + date_cell_size.Width - 1,
2896                                         rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
2897                         }
2898                         text_format.Dispose ();
2899                 }
2900                 
2901                 // draws the pervious or next button
2902                 private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous) 
2903                 {
2904                         bool is_clicked = false;
2905                         Rectangle button_rect;
2906                         Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
2907                         Point[] arrow_path = new Point[3];
2908                         // prepare the button
2909                         if (is_previous) 
2910                         {
2911                                 is_clicked = mc.is_previous_clicked;
2912                                 button_rect = new Rectangle (
2913                                         rectangle.X + 1 + x_offset,
2914                                         rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2915                                         Math.Max(button_size.Width - 1, 0),
2916                                         Math.Max(button_size.Height - 1, 0));
2917                                 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2918                                 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2919                                 if (is_clicked) {
2920                                         arrow_rect.Offset(1,1);
2921                                 }
2922                                 arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
2923                                 arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
2924                                 arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
2925                         }
2926                         else
2927                         {
2928                                 is_clicked = mc.is_next_clicked;
2929                                 button_rect = new Rectangle (
2930                                         rectangle.Right - 1 - x_offset - button_size.Width,
2931                                         rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
2932                                         Math.Max(button_size.Width - 1, 0),
2933                                         Math.Max(button_size.Height - 1, 0));
2934                                 arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
2935                                 arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
2936                                 if (is_clicked) {
2937                                         arrow_rect.Offset(1,1);
2938                                 }
2939                                 arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
2940                                 arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
2941                                 arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);                            
2942                         }
2943                         
2944                         // fill the background
2945                         dc.FillRectangle (ResPool.GetSolidBrush(mc.TitleBackColor), button_rect);
2946                         
2947                         // draw the button
2948                         Color first_gradient_color = is_clicked ? pressed_gradient_first_color : gradient_first_color;
2949                         Color second_gradient_color = is_clicked ? pressed_gradient_second_color : gradient_second_color;
2950                         
2951                         CL_Draw_Button (dc, button_rect, FlatStyle.Standard,
2952                                            false, true, is_clicked, 
2953                                            first_gradient_color, second_gradient_color,
2954                                            false);
2955                                 
2956                         // draw the arrow
2957                         SmoothingMode old_smooting_mode = dc.SmoothingMode;
2958                         dc.SmoothingMode = SmoothingMode.AntiAlias;
2959                         dc.FillPolygon (SystemBrushes.ControlText, arrow_path);
2960                         dc.SmoothingMode = old_smooting_mode;
2961                 }
2962                 
2963                 
2964                 // draws one day in the calendar grid
2965                 private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
2966                         Color date_color = mc.ForeColor;
2967                         Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
2968                         
2969                         // find out if we are the lead of the first calendar or the trail of the last calendar                                          
2970                         if (date.Year != month.Year || date.Month != month.Month) {
2971                                 DateTime check_date = month.AddMonths (-1);
2972                                 // check if it's the month before 
2973                                 if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
2974                                         date_color = mc.TrailingForeColor;
2975                                 } else {
2976                                         // check if it's the month after
2977                                         check_date = month.AddMonths (1);
2978                                         if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
2979                                                 date_color = mc.TrailingForeColor;
2980                                         } else {
2981                                                 return;
2982                                         }
2983                                 }
2984                         } else {
2985                                 date_color = mc.ForeColor;
2986                         }
2987                         
2988                         
2989                         if (date == mc.SelectionStart && date == mc.SelectionEnd) {
2990                                 // see if the date is in the start of selection
2991                                 date_color = mc.BackColor;
2992                                 // draw the left hand of the back ground
2993                                 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);                                
2994                                 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
2995                         } else if (date == mc.SelectionStart) {
2996                                 // see if the date is in the start of selection
2997                                 date_color = mc.BackColor;
2998                                 // draw the left hand of the back ground
2999                                 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);                                
3000                                 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
3001                                 // fill the other side as a straight rect
3002                                 if (date < mc.SelectionEnd) 
3003                                 {
3004                                         // use rectangle instead of rectangle to go all the way to edge of rect
3005                                         selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
3006                                         selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
3007                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3008                                 }
3009                         } else if (date == mc.SelectionEnd) {
3010                                 // see if it is the end of selection
3011                                 date_color = mc.BackColor;
3012                                 // draw the left hand of the back ground
3013                                 Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
3014                                 dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
3015                                 // fill the other side as a straight rect
3016                                 if (date > mc.SelectionStart) {
3017                                         selection_rect.X = rectangle.X;
3018                                         selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
3019                                         dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3020                                 }
3021                         } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
3022                                 // now see if it's in the middle
3023                                 date_color = mc.BackColor;
3024                                 // draw the left hand of the back ground
3025                                 Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
3026                                 dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
3027                         }
3028                         
3029                         // set up some standard string formating variables
3030                         StringFormat text_format = new StringFormat();
3031                         text_format.LineAlignment = StringAlignment.Center;
3032                         text_format.Alignment = StringAlignment.Center;
3033                         
3034                         
3035                         // establish if it's a bolded font
3036                         Font font;
3037                         if (mc.IsBoldedDate (date)) {
3038                                 font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
3039                         } else {
3040                                 font = mc.Font;
3041                         }
3042                         
3043                         // just draw the date now
3044                         dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
3045                         
3046                         // today circle if needed
3047                         if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
3048                                 DrawTodayCircle (dc, interior);
3049                         }
3050                         
3051                         // draw the selection grid
3052                         if (mc.is_date_clicked && mc.clicked_date == date) {                            
3053                                 using (Pen pen = new Pen (Color.Black, 1) ) {
3054                                         pen.DashStyle = DashStyle.Dot;
3055                                         dc.DrawRectangle (pen, interior);
3056                                 }
3057                         }
3058                         text_format.Dispose ();
3059                 }
3060                 
3061                 private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
3062                         Color circle_color = Color.FromArgb (248, 0, 0);
3063                         // draw the left hand of the circle 
3064                         Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
3065                         Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
3066                         Point [] curve_points = new Point [3];
3067                         curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
3068                         curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
3069                         curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
3070                         
3071                         SmoothingMode old_smoothing_mode = dc.SmoothingMode;
3072                         dc.SmoothingMode = SmoothingMode.AntiAlias;
3073                         
3074                         using (Pen pen = new Pen (circle_color, 2)) {
3075                                 dc.DrawArc (pen, lhs_circle_rect, 90, 180);
3076                                 dc.DrawArc (pen, rhs_circle_rect, 270, 180);                                    
3077                                 dc.DrawCurve (pen, curve_points);
3078                                 dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
3079                         }
3080                         
3081                         dc.SmoothingMode = old_smoothing_mode;
3082                 }
3083                 #endregion      // MonthCalendar
3084                 
3085                 public override void CPDrawBorder3D( Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides ) {
3086                         CPDrawBorder3D( graphics, rectangle, style, sides, ColorControl );
3087                 }
3088                 
3089                 protected override void CPDrawBorder3D( Graphics dc, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color ) {
3090                         // currently we don't take care of Border3DStyle or Border3DSide
3091                         
3092                         Pen tmp_pen = ResPool.GetPen( edge_bottom_inner_color );
3093                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 2, rectangle.Y + 1 );
3094                         dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 1, rectangle.Right - 2, rectangle.Y + 2 );
3095                         dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 3 );
3096                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Bottom - 3, rectangle.X + 2, rectangle.Bottom - 2 );
3097                         
3098                         tmp_pen = ResPool.GetPen( theme_back_color );
3099                         dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 2, rectangle.Right - 3, rectangle.Y + 2 );
3100                         dc.DrawLine( tmp_pen, rectangle.X + 2, rectangle.Y + 3, rectangle.X + 2, rectangle.Bottom - 3 );
3101                         
3102                         tmp_pen = ResPool.GetPen( Color.White );
3103                         dc.DrawLine( tmp_pen, rectangle.X + 3, rectangle.Bottom - 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3104                         dc.DrawLine( tmp_pen, rectangle.Right - 3, rectangle.Y + 3, rectangle.Right - 3, rectangle.Bottom - 3 );
3105                         
3106                         Point[] points = {
3107                                 new Point( rectangle.X + 3, rectangle.Y + 1 ),
3108                                 new Point( rectangle.Right - 4, rectangle.Y + 1 ),
3109                                 new Point( rectangle.Right - 2, rectangle.Y + 3 ),
3110                                 new Point( rectangle.Right - 2, rectangle.Bottom - 4 ),
3111                                 new Point( rectangle.Right - 4, rectangle.Bottom - 2 ),
3112                                 new Point( rectangle.X + 3, rectangle.Bottom - 2 ),
3113                                 new Point( rectangle.X + 1, rectangle.Bottom - 4 ),
3114                                 new Point( rectangle.X + 1, rectangle.Y + 3 ),
3115                                 new Point( rectangle.X + 3, rectangle.Y + 1 )
3116                         };
3117                         
3118                         dc.DrawLines( ResPool.GetPen( combobox_border_color ), points );
3119                         
3120                         Point[] points_top_outer = {
3121                                 new Point( rectangle.X + 1, rectangle.Y + 1 ),
3122                                 new Point( rectangle.X + 2, rectangle.Y ),
3123                                 new Point( rectangle.Right - 3, rectangle.Y ),
3124                                 new Point( rectangle.Right - 2 , rectangle.Y + 1 )
3125                         };
3126                         
3127                         Point[] points_bottom_outer = {
3128                                 new Point( rectangle.X + 1, rectangle.Bottom - 2 ),
3129                                 new Point( rectangle.X + 2, rectangle.Bottom - 1 ),
3130                                 new Point( rectangle.Right - 3, rectangle.Bottom - 1 ),
3131                                 new Point( rectangle.Right - 2, rectangle.Bottom - 2 )
3132                         };
3133                         
3134                         // outer border
3135                         tmp_pen = ResPool.GetPen( button_outer_border_dark_color );
3136                         dc.DrawLines( tmp_pen, points_top_outer );
3137                         tmp_pen = ResPool.GetPen( button_outer_border_light_color );
3138                         dc.DrawLines( tmp_pen, points_bottom_outer );
3139                         
3140                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X, rectangle.Y + 2 ), new Point( rectangle.X, rectangle.Bottom - 3 ), button_outer_border_dark_color, button_outer_border_light_color ) ) {
3141                                 using (Pen lgbrpen = new Pen (lgbr)) {
3142                                         dc.DrawLine (lgbrpen, rectangle.X, rectangle.Y + 2, rectangle.X, rectangle.Bottom - 3 );
3143                                         dc.DrawLine (lgbrpen, rectangle.Right - 1, rectangle.Y + 2, rectangle.Right - 1, rectangle.Bottom - 3 );
3144                                 }
3145                         }
3146                         
3147                         tmp_pen = ResPool.GetPen( button_edge_top_outer_color );
3148                         dc.DrawLine( tmp_pen, rectangle.X, rectangle.Y + 1, rectangle.X + 1, rectangle.Y );
3149                         dc.DrawLine( tmp_pen, rectangle.Right - 2, rectangle.Y, rectangle.Right - 1, rectangle.Y + 1 );
3150                         
3151                         tmp_pen = ResPool.GetPen( button_edge_bottom_outer_color );
3152                         dc.DrawLine( tmp_pen, rectangle.X, rectangle.Bottom - 2, rectangle.X + 1, rectangle.Bottom - 1 );
3153                         dc.DrawLine( tmp_pen, rectangle.Right - 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 1 );
3154                 }
3155                 
3156                 public override void CPDrawBorder( Graphics dc, Rectangle bounds, Color leftColor, int leftWidth,
3157                                                   ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
3158                                                   Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
3159                                                   int bottomWidth, ButtonBorderStyle bottomStyle ) {
3160                         dc.DrawRectangle( ResPool.GetPen( combobox_border_color ), bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1 );
3161                 }
3162                 
3163                 // TODO: inactive...
3164                 public override void CPDrawCheckBox( Graphics dc, Rectangle rectangle, ButtonState state ) {
3165                         
3166                         bool pushed = ( state & ButtonState.Pushed ) != 0;
3167                         
3168                         int lineWidth;
3169                         Rectangle rect;
3170                         int scale;
3171                         
3172                         // background
3173                         dc.FillRectangle( ResPool.GetSolidBrush( pushed ? checkbox_pressed_backcolor : Color.White ), rectangle );
3174                         
3175                         // border
3176                         dc.DrawRectangle( ResPool.GetPen( scrollbar_border_color ), rectangle );
3177                         
3178                         Color inner_border_color = pushed ? checkbox_pressed_inner_boder_color : checkbox_inner_boder_color;
3179                         
3180                         Pen tmp_pen = ResPool.GetPen( inner_border_color );
3181                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 1, rectangle.Right - 1, rectangle.Y + 1 );
3182                         dc.DrawLine( tmp_pen, rectangle.X + 1, rectangle.Y + 2, rectangle.X + 1, rectangle.Bottom - 1 );
3183                         
3184                         /* Make sure we've got at least a line width of 1 */
3185                         lineWidth = Math.Max( 3, rectangle.Width / 6 );
3186                         scale = Math.Max( 1, rectangle.Width / 12 );
3187                         
3188                         // define a rectangle inside the border area
3189                         rect = new Rectangle( rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4 );
3190                         if ( ( state & ButtonState.Inactive ) != 0 ) {
3191                                 tmp_pen = SystemPens.ControlDark;
3192                         } else {
3193                                 tmp_pen = SystemPens.ControlText;
3194                         }
3195                         
3196                         if ( ( state & ButtonState.Checked ) != 0 ) { 
3197                                 /* Need to draw a check-mark */
3198                                 for ( int i=0; i < lineWidth; i++ ) {
3199                                         dc.DrawLine( tmp_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * scale, rect.Top + lineWidth + 2 * scale + i );
3200                                         dc.DrawLine( tmp_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 );
3201                                 }
3202                         }
3203                 }
3204                 
3205                 public  override void CPDrawStringDisabled( Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
3206                                                            StringFormat format ) {                      
3207                         
3208                         graphics.DrawString( s, font, ResPool.GetSolidBrush( ColorGrayText), layoutRectangle, format );                 
3209                         
3210                 }
3211                 
3212                 public override void CPDrawButton (Graphics dc, Rectangle buttonRectangle, ButtonState state)
3213                 {
3214                         bool is_enabled = true;
3215                         FlatStyle flat_style = FlatStyle.Standard;
3216                         bool is_pressed = false;
3217                         
3218                         if ((state & ButtonState.Pushed) != 0) {
3219                                 is_pressed = true;
3220                         }
3221                         
3222 //                      if ((state & ButtonState.Checked)!=0) {
3223 //                              dfcs |= DrawFrameControlStates.Checked;
3224 //                      }
3225                         
3226                         if ((state & ButtonState.Flat) != 0) {
3227                                 flat_style = FlatStyle.Flat;
3228                         }
3229                         
3230                         if ((state & ButtonState.Inactive) != 0) {
3231                                 is_enabled = false;
3232                         }
3233                         
3234                         Color first_gradient_color = gradient_first_color;
3235                         Color second_gradient_color = gradient_second_color;
3236                         
3237                         if (is_pressed) {
3238                                 first_gradient_color = pressed_gradient_first_color;
3239                                 second_gradient_color = pressed_gradient_second_color;
3240                         }
3241                         
3242                         CL_Draw_Button (dc, buttonRectangle, flat_style,
3243                                         false, is_enabled, is_pressed,
3244                                         first_gradient_color, second_gradient_color,
3245                                         false);
3246                 }
3247                 
3248                 public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
3249                 {
3250                         bool is_checked = false;
3251                         bool is_inactive = false;
3252                         
3253                         if ((state & ButtonState.Checked) != 0) {
3254                                 is_checked = true;
3255                         }
3256                         
3257                         if ((state & ButtonState.Inactive) != 0) {
3258                                 is_inactive = true;
3259                         }
3260                         
3261                         SmoothingMode old_smooting_mode = dc.SmoothingMode;
3262                         dc.SmoothingMode = SmoothingMode.AntiAlias;
3263                         
3264                         dc.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3265                         
3266                         dc.DrawArc (ResPool.GetPen (radio_button_border_circle_color), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
3267                         
3268                         CL_Draw_RadioButton_Dot (dc, rectangle, is_checked, is_inactive);
3269                         
3270                         dc.SmoothingMode = old_smooting_mode;
3271                 }
3272
3273                 private void CL_Draw_RadioButton_Dot (Graphics dc,  Rectangle rectangle, bool is_checked, bool is_inactive)
3274                 {
3275                         if (is_checked) {
3276                                 int lineWidth = Math.Max (1, Math.Min (rectangle.Width, rectangle.Height) / 4);
3277                                 
3278                                 SolidBrush buttonBrush;
3279                                 
3280                                 if (is_inactive) {
3281                                         buttonBrush = SystemBrushes.ControlDark as SolidBrush;
3282                                 } else {
3283                                         buttonBrush = ResPool.GetSolidBrush (radio_button_dot_color);
3284                                 }
3285                                 dc.FillPie (buttonBrush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
3286                                 
3287                                 // the white shiny dott
3288                                 buttonBrush = ResPool.GetSolidBrush (ColorWindow);
3289                                 dc.FillPie (buttonBrush, rectangle.X + lineWidth + lineWidth / 2, rectangle.Y + lineWidth + lineWidth / 2, (rectangle.Width - lineWidth * 2) / 3, (rectangle.Height - lineWidth * 2) / 3, 0, 359);
3290                         }
3291                 }
3292         } //class
3293 }
3294