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