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