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