2005-12-07 Mike Kestner <mkestner@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeNice.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, xenomorph2@onlinehome.de
24 //
25 //      based on ThemeWin32Classic
26 //
27 //              - You can activate this Theme with export MONO_THEME=nice
28
29
30 using System.Drawing;
31 using System.Drawing.Drawing2D;
32 using System.Drawing.Imaging;
33 using System.Drawing.Text;
34
35 namespace System.Windows.Forms
36 {
37         internal class ThemeNice : ThemeWin32Classic
38         {
39                 public override Version Version
40                 {
41                         get {
42                                 return new Version( 0, 0, 0, 2 );
43                         }
44                 }
45                 
46                 static readonly Color NormalColor = Color.LightGray;
47                 static readonly Color MouseOverColor = Color.DarkGray;
48                 static readonly Color PressedColor = Color.Gray;
49                 static readonly Color FocusColor = Color.FromArgb( System.Convert.ToInt32( "0xff00c0ff", 16 ) );
50                 static readonly Color LightColor = Color.LightGray;
51                 static readonly Color BorderColor = MouseOverColor;
52                 static readonly Color NiceBackColor  = Color.FromArgb( System.Convert.ToInt32( "0xffefebe7", 16 ) );
53                 
54                 static Bitmap size_grip_bmp = CreateSizegripDot();
55                 
56                 #region Principal Theme Methods
57                 public ThemeNice( )
58                 {
59                         ColorControl = NiceBackColor;
60                         always_draw_hotkeys = true;
61                 }
62                 
63                 public override Color DefaultControlBackColor
64                 {
65                         get { return NiceBackColor; }
66                 }
67                 
68                 public override Color DefaultWindowBackColor
69                 {
70                         get { return NiceBackColor; }                   
71                 }
72                 
73                 public override Color ColorControl {
74                         get { return NiceBackColor;}
75                 }
76                 
77                 static Bitmap CreateSizegripDot()
78                 {
79                         Bitmap bmp = new Bitmap( 4, 4 );
80                         using ( Graphics dc = Graphics.FromImage( bmp ) )
81                         {
82                                 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
83                                 dc.SmoothingMode = SmoothingMode.AntiAlias;
84                                 
85                                 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 4, 4 ), PressedColor, Color.White ) )
86                                                 dc.FillEllipse( lgbr, new Rectangle( 0, 0, 4, 4 ) );
87                                 
88                                 dc.SmoothingMode = old_smoothing_mode;
89                         }
90                         
91                         return bmp;
92                 }
93                 #endregion      // Internal Methods
94                 
95                 #region ButtonBase
96                 protected override void ButtonBase_DrawButton( ButtonBase button, Graphics dc )
97                 {
98                         Rectangle buttonRectangle;
99                         
100                         int width = button.ClientSize.Width;
101                         int height = button.ClientSize.Height;
102                         
103                         dc.FillRectangle( ResPool.GetSolidBrush( button.BackColor ), button.ClientRectangle );
104                         
105                         // set up the button rectangle
106                         buttonRectangle = button.ClientRectangle;
107                         
108                         Color use_color;
109                         Color first_color = button.has_focus ? Color.LightYellow : Color.White;
110                         
111                         if ( ( ( button is CheckBox ) && ( ( (CheckBox)button ).check_state == CheckState.Checked ) ) ||
112                             ( ( button is RadioButton ) && ( ( (RadioButton)button ).check_state == CheckState.Checked ) ) )
113                         {
114                                 use_color = PressedColor;
115                         }
116                         else
117                         if ( !button.is_enabled )
118                         {
119                                 use_color = NormalColor;
120                                 button.is_entered = false;
121                         }
122                         else
123                         if ( !button.is_entered )
124                         {
125                                 use_color = NormalColor;
126                         }
127                         else
128                         {
129                                 if ( !button.is_pressed )
130                                         use_color = MouseOverColor;
131                                 else
132                                         use_color = PressedColor;
133                         }
134                         
135                         // Fill button with a nice linear gradient brush
136                         Rectangle lgbRectangle = Rectangle.Inflate( buttonRectangle, -1, -1 );
137                         
138                         if ( button.flat_style != FlatStyle.Popup || ( ( button.flat_style == FlatStyle.Popup ) && button.is_entered ) )
139                         {
140                                 LinearGradientBrush lgbr;
141                                 if ( button.flat_style == FlatStyle.Flat )
142                                         lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, height - 1 ), use_color, first_color );
143                                 else
144                                         lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, height - 1 ), first_color, use_color );
145                                 dc.FillRectangle( lgbr, lgbRectangle );
146                                 lgbr.Dispose( );
147                                 
148                                 if ( button.has_focus )
149                                         return; 
150                                 
151                                 Point[] points = new Point[] {
152                                         new Point( 2, 0 ),
153                                         new Point( width - 3, 0 ),
154                                         new Point( width - 1, 2 ),
155                                         new Point( width - 1, height - 3 ),
156                                         new Point( width - 3, height - 1 ),
157                                         new Point( 2, height - 1 ),
158                                         new Point( 0, height - 3 ),
159                                         new Point( 0, 2 ),
160                                         new Point( 2, 0 )
161                                 };
162                         
163                                 Pen pen = ResPool.GetPen( BorderColor );
164                                 dc.DrawLines( pen, points );
165                         }
166                 }
167                 
168                 protected override void ButtonBase_DrawFocus( ButtonBase button, Graphics dc )
169                 {
170                         int width = button.ClientSize.Width;
171                         int height = button.ClientSize.Height;
172                         
173                         Point[] points = new Point[] {
174                                 new Point( 2, 0 ),
175                                 new Point( width - 3, 0 ),
176                                 new Point( width - 1, 2 ),
177                                 new Point( width - 1, height - 3 ),
178                                 new Point( width - 3, height - 1 ),
179                                 new Point( 2, height - 1 ),
180                                 new Point( 0, height - 3 ),
181                                 new Point( 0, 2 ),
182                                 new Point( 2, 0 )
183                         };
184                         
185                         Pen pen = ResPool.GetPen( FocusColor );
186                         dc.DrawLines( pen, points );
187                 }
188                 
189                 protected override void ButtonBase_DrawText( ButtonBase button, Graphics dc )
190                 {
191                         if ( !( button is CheckBox ) && !(button is RadioButton ) )
192                         {
193                                 base.ButtonBase_DrawText( button, dc );
194                         }
195                 }
196                 #endregion      // ButtonBase
197                 
198                 #region CheckBox
199                 protected override void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
200                 {
201                         dc.FillRectangle( ResPool.GetSolidBrush( checkbox.BackColor ), checkbox.ClientRectangle );
202                         // render as per normal button
203                         if ( checkbox.appearance == Appearance.Button )
204                         {
205                                 DrawButtonBase( dc, checkbox.ClientRectangle, checkbox );
206                         }
207                         else
208                         {
209                                 // establish if we are rendering a flat style of some sort
210                                 if ( checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup )
211                                 {
212                                         DrawFlatStyleCheckBox( dc, checkbox_rectangle, checkbox );
213                                 }
214                                 else
215                                 {
216                                         ControlPaint.DrawCheckBox( dc, checkbox_rectangle, state );
217                                 }
218                         }
219                 }
220                 #endregion      // CheckBox
221                 
222                 #region ComboBox
223                 
224                 // Drawing
225                 
226                 public override void DrawComboBoxEditDecorations( Graphics dc, ComboBox ctrl, Rectangle cl )
227                 {
228                         if ( !ctrl.Focused )
229                         {
230                                 dc.DrawLine (ResPool.GetPen (BorderColor), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top 
231                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
232                                 dc.DrawLine (ResPool.GetPen (BorderColor), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
233                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2); 
234                                 dc.DrawLine (ResPool.GetPen (BorderColor), cl.X + cl.Width - 1, cl.Y, cl.X + cl.Width - 1, cl.Y + cl.Height); //right
235                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 2, cl.Y + 1 , cl.X + cl.Width - 2, cl.Y + cl.Height - 1);
236                                 dc.DrawLine (ResPool.GetPen (BorderColor), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
237                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
238                         }
239                         else
240                         {
241                                 dc.DrawLine (ResPool.GetPen (FocusColor), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top 
242                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
243                                 dc.DrawLine (ResPool.GetPen (FocusColor), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
244                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2); 
245                                 dc.DrawLine (ResPool.GetPen (FocusColor), cl.X + cl.Width - 1, cl.Y, cl.X + cl.Width - 1, cl.Y + cl.Height); //right
246                                 dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 2, cl.Y + 1 , cl.X + cl.Width - 2, cl.Y + cl.Height - 1);
247                                 dc.DrawLine (ResPool.GetPen (FocusColor), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
248                                 dc.DrawLine (ResPool.GetPen (FocusColor), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
249                         }
250                 }
251                 
252                 public override void DrawComboListBoxDecorations( Graphics dc, ComboBox ctrl, Rectangle cl )
253                 {
254                         if ( ctrl.DropDownStyle == ComboBoxStyle.Simple )
255                         {
256                                 DrawComboBoxEditDecorations( dc, ctrl, cl );
257                         }
258                         else
259                         {
260                                 dc.DrawRectangle( ResPool.GetPen( ThemeEngine.Current.ColorWindowFrame ), cl.X, cl.Y, cl.Width - 1, cl.Height - 1 );
261                         }
262                 }               
263                 #endregion ComboBox
264                 
265                 #region Menus
266                 public override void DrawMenuItem( MenuItem item, DrawItemEventArgs e )
267                 {
268                         StringFormat string_format;
269                         Rectangle rect_text = e.Bounds;
270                         
271                         if ( item.Visible == false )
272                                 return;
273                         
274                         if ( item.MenuBar )
275                         {
276                                 string_format = string_format_menu_menubar_text;
277                         }
278                         else
279                         {
280                                 string_format = string_format_menu_text;
281                         }
282                         
283                         if ( item.Separator )
284                         {
285                                 e.Graphics.DrawLine( ThemeEngine.Current.ResPool.GetPen( BorderColor ),
286                                                     e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y );
287                                 
288                                 e.Graphics.DrawLine( ThemeEngine.Current.ResPool.GetPen( Color.White ),
289                                                     e.Bounds.X + 1, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1 );
290                                 
291                                 return;
292                         }
293                         
294                         if ( !item.MenuBar )
295                                 rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
296                         
297                         if ( item.BarBreak )
298                         { /* Draw vertical break bar*/
299                                 Rectangle rect = e.Bounds;
300                                 rect.Y++;
301                                 rect.Width = 3;
302                                 rect.Height = item.MenuHeight - 6;
303                                 
304                                 e.Graphics.DrawLine( ThemeEngine.Current.ResPool.GetPen( LightColor ),
305                                                     rect.X, rect.Y , rect.X, rect.Y + rect.Height );
306                                 
307                                 e.Graphics.DrawLine( ThemeEngine.Current.ResPool.GetPen( ThemeEngine.Current.ColorControlLight ),
308                                                     rect.X + 1, rect.Y , rect.X + 1, rect.Y + rect.Height );
309                         }
310                         
311                         Color color_text = ThemeEngine.Current.ColorMenuText;
312                         Color color_back;
313                         
314                         /* Draw background */
315                         Rectangle rect_back = e.Bounds;
316                         rect_back.X++;
317                         rect_back.Width -= 2;
318                         
319                         if ( ( e.State & DrawItemState.Selected ) == DrawItemState.Selected )
320                         {
321                                 color_text = ThemeEngine.Current.ColorMenuText;
322                                 color_back = NormalColor;
323                                 
324                                 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rect_back.X, rect_back.Y ), new Point( rect_back.Right, rect_back.Y ), Color.White, NormalColor ) )//NormalColor, Color.White ) )
325                                 {
326                                         e.Graphics.FillRectangle( lgbr, rect_back );
327                                 }
328                                 
329                                 rect_back.Height--;
330                                 e.Graphics.DrawRectangle( ResPool.GetPen( BorderColor ), rect_back );
331                         }
332                         else
333                         {
334                                 color_text = ThemeEngine.Current.ColorMenuText;
335                                 color_back = NiceBackColor;
336                                 
337                                 e.Graphics.FillRectangle( ThemeEngine.Current.ResPool.GetSolidBrush( NiceBackColor ), rect_back );
338                         }
339                         
340                         if ( item.Enabled )
341                         {
342                                 e.Graphics.DrawString( item.Text, e.Font,
343                                                       ThemeEngine.Current.ResPool.GetSolidBrush( color_text ),
344                                                       rect_text, string_format );
345                                 
346                                 if ( !item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut )
347                                 {
348                                         string str = item.GetShortCutText( );
349                                         Rectangle rect = rect_text;
350                                         rect.X = item.XTab;
351                                         rect.Width -= item.XTab;
352                                         
353                                         e.Graphics.DrawString( str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush( color_text ),
354                                                               rect, string_format_menu_shortcut );
355                                 }
356                         }
357                         else
358                         {
359                                 ControlPaint.DrawStringDisabled( e.Graphics, item.Text, e.Font,
360                                                                 Color.Black, rect_text, string_format );
361                         }
362                         
363                         /* Draw arrow */
364                         if ( item.MenuBar == false && item.IsPopup )
365                         {
366                                 int cx = ThemeEngine.Current.MenuCheckSize.Width;
367                                 int cy = ThemeEngine.Current.MenuCheckSize.Height;
368                                 using ( Bitmap  bmp = new Bitmap( cx, cy ) )
369                                 {
370                                         using ( Graphics dc = Graphics.FromImage( bmp ) )
371                                         {
372                                                 SmoothingMode old_smoothing_mode = dc.SmoothingMode;
373                                                 dc.SmoothingMode = SmoothingMode.AntiAlias;
374                                                 
375                                                 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
376                                                 ControlPaint.DrawMenuGlyph( dc, rect_arrow, MenuGlyph.Arrow );
377                                                 bmp.MakeTransparent( );
378                                                 
379                                                 if ( item.Enabled )
380                                                 {
381                                                         e.Graphics.DrawImage( bmp, e.Bounds.X + e.Bounds.Width - cx,
382                                                                              e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
383                                                 }
384                                                 else
385                                                 {
386                                                         ControlPaint.DrawImageDisabled( e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
387                                                                                        e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ),  color_back );
388                                                 }
389                                                 
390                                                 dc.SmoothingMode = old_smoothing_mode;
391                                         }
392                                 }
393                         }
394                         
395                         /* Draw checked or radio */
396                         if ( item.MenuBar == false && item.Checked )
397                         {
398                                 
399                                 Rectangle area = e.Bounds;
400                                 int cx = ThemeEngine.Current.MenuCheckSize.Width;
401                                 int cy = ThemeEngine.Current.MenuCheckSize.Height;
402                                 using ( Bitmap bmp = new Bitmap( cx, cy ) )
403                                 {
404                                         using ( Graphics gr = Graphics.FromImage( bmp ) )
405                                         {
406                                                 Rectangle rect_arrow = new Rectangle( 0, 0, cx, cy );
407                                                 
408                                                 if ( item.RadioCheck )
409                                                         ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Bullet );
410                                                 else
411                                                         ControlPaint.DrawMenuGlyph( gr, rect_arrow, MenuGlyph.Checkmark );
412                                                 
413                                                 bmp.MakeTransparent( );
414                                                 e.Graphics.DrawImage( bmp, area.X, e.Bounds.Y + ( ( e.Bounds.Height - cy ) / 2 ) );
415                                         }
416                                 }
417                         }
418                 }
419                 
420                 public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
421                 {
422                         
423                         dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
424                                           (NiceBackColor), cliparea);
425                         
426                         /* Draw menu borders */
427                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHighlightText),
428                                      rect.X, rect.Y, rect.X + rect.Width, rect.Y);
429                         
430                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHighlightText),
431                                      rect.X, rect.Y, rect.X, rect.Y + rect.Height);
432                         
433                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
434                                      rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
435                         
436                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDarkDark),
437                                      rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
438                         
439                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
440                                      rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
441                         
442                         dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDarkDark),
443                                      rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
444                         
445                         for (int i = 0; i < menu.MenuItems.Count; i++)
446                                 if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
447                                         MenuItem item = menu.MenuItems [i];
448                                         item.MenuHeight = menu.Height;
449                                         item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
450                                                                                      item.bounds, i, item.Status));
451                                 }
452                 }
453                 #endregion // Menus
454                 
455                 #region ProgressBar
456                 public override void DrawProgressBar( Graphics dc, Rectangle clip_rect, ProgressBar ctrl )
457                 {
458                         Rectangle       client_area = ctrl.client_area;
459                         int             barpos_pixels;
460                         Rectangle bar = ctrl.client_area;
461                         
462                         barpos_pixels = ( ( ctrl.Value - ctrl.Minimum ) * client_area.Width ) / ( ctrl.Maximum - ctrl.Minimum );
463                         
464                         bar.Width = barpos_pixels;
465 //                      bar.Height += 1;
466                         
467                         // Draw bar background
468                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( client_area.Left, client_area.Top ), new Point( client_area.Left, client_area.Bottom ), LightColor, Color.White ) )
469                         {
470                                 dc.FillRectangle( lgbr, client_area );
471                         }
472                         
473                         // Draw bar
474                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( bar.Location, new Point( bar.X, bar.Bottom ), Color.White, FocusColor ) )
475                         {
476                                 dc.FillRectangle( lgbr, bar );
477                         }
478                         
479                         /* Draw border */
480                         dc.DrawRectangle( ResPool.GetPen( BorderColor ), ctrl.ClientRectangle.X, ctrl.ClientRectangle.Y, ctrl.ClientRectangle.Width - 1, ctrl.ClientRectangle.Height - 1 );
481                         dc.DrawRectangle( ResPool.GetPen( LightColor ), ctrl.ClientRectangle.X + 1, ctrl.ClientRectangle.Y + 1, ctrl.ClientRectangle.Width - 2, ctrl.ClientRectangle.Height - 2 );
482                 }
483                 #endregion      // ProgressBar
484                 
485                 #region RadioButton
486                 protected override void RadioButton_DrawButton( RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle )
487                 {
488                         SolidBrush sb = new SolidBrush( radio_button.BackColor );
489                         dc.FillRectangle( sb, radio_button.ClientRectangle );
490                         sb.Dispose( );
491                         
492                         if (radio_button.appearance==Appearance.Button) {
493                                 if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
494                                         DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
495                                 } else {
496                                         DrawButtonBase( dc, radio_button.ClientRectangle, radio_button );
497                                 }
498                         } else {
499                                 // establish if we are rendering a flat style of some sort
500                                 if ( radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup ) {
501                                         DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
502                                 } else {
503                                         ControlPaint.DrawRadioButton( dc, radiobutton_rectangle, state );
504                                 }
505                         }
506                 }
507                 
508                 protected override void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
509                 {
510                         if (radio_button.Focused && radio_button.appearance != Appearance.Button) 
511                         {
512                                 if (radio_button.FlatStyle != FlatStyle.Flat && radio_button.FlatStyle != FlatStyle.Popup) 
513                                 {
514                                         DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
515                                 } 
516                         }
517                 }
518                 #endregion      // RadioButton
519                 
520                 #region ScrollBar
521                 protected override void ScrollBar_DrawThumb( ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
522                 {
523                         if ( bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith( thumb_pos ) )
524                                 DrawScrollBarThumb( dc, thumb_pos, bar );
525                 }
526                 
527                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_None( int scrollbutton_height, ScrollBar bar, Rectangle clip, Graphics dc )
528                 {
529                         Rectangle r = new Rectangle( 0,
530                                                     scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
531                         Rectangle intersect = Rectangle.Intersect( clip, r );
532                         
533                         if ( intersect != Rectangle.Empty  )
534                         {
535                                 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
536                                 {
537                                         dc.FillRectangle( lgbr, intersect );
538                                 }
539                         }
540                 }
541                 
542                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Forward( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
543                 {
544                         Rectangle r = new Rectangle( 0,  scrollbutton_height,
545                                                     bar.ClientRectangle.Width, thumb_pos.Y  - scrollbutton_height );
546                         Rectangle intersect = Rectangle.Intersect( clip, r );
547                         
548                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
549                         {
550                                 if ( intersect != Rectangle.Empty )
551                                         dc.FillRectangle( lgbr, intersect );
552                                 
553                                 r.X = 0;
554                                 r.Y = thumb_pos.Y + thumb_pos.Height;
555                                 r.Width = bar.ClientRectangle.Width;
556                                 r.Height = bar.ClientRectangle.Height -  ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
557                                 
558                                 intersect = Rectangle.Intersect( clip, r );
559                                 if ( intersect != Rectangle.Empty )
560                                         dc.FillRectangle( lgbr, intersect );
561                         }
562                 }
563                 
564                 protected override void ScrollBar_Vertical_Draw_ThumbMoving_Backwards( int scrollbutton_height, ScrollBar bar, Rectangle thumb_pos, Rectangle clip, Graphics dc )
565                 {
566                         Rectangle r = new Rectangle( 0,  scrollbutton_height,
567                                                     bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height );
568                         Rectangle intersect = Rectangle.Intersect( clip, r );
569                         
570                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( r. Width - 1, 0 ), LightColor, Color.White ) )
571                         {
572                                 if ( intersect != Rectangle.Empty )
573                                         dc.FillRectangle( lgbr, intersect );
574                                 
575                                 r.X = 0;
576                                 r.Y = thumb_pos.Y + thumb_pos.Height;
577                                 r.Width = bar.ClientRectangle.Width;
578                                 r.Height = bar.ClientRectangle.Height -  ( thumb_pos.Y + thumb_pos.Height ) - scrollbutton_height;
579                                 
580                                 intersect = Rectangle.Intersect( clip, r );
581                                 if ( intersect != Rectangle.Empty )
582                                         dc.FillRectangle( lgbr, intersect );
583                         }
584                 }
585                 
586                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
587                 {
588                         Rectangle r = new Rectangle( scrollbutton_width,
589                                                     0, bar.ClientRectangle.Width - ( scrollbutton_width * 2 ), bar.ClientRectangle.Height );
590                         Rectangle intersect = Rectangle.Intersect( clip, r );
591                         
592                         if ( intersect != Rectangle.Empty )
593                         {
594                                 using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
595                                 {
596                                         dc.FillRectangle( lgbr, intersect );
597                                 }
598                         }
599                 }
600                 
601                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
602                 {
603                         Rectangle r = new Rectangle( scrollbutton_width,  0,
604                                                     thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
605                         Rectangle intersect = Rectangle.Intersect( clip, r );
606                         
607                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
608                         {
609                                 if ( intersect != Rectangle.Empty )
610                                         dc.FillRectangle( lgbr, intersect );
611                                 
612                                 r.X = thumb_pos.X + thumb_pos.Width;
613                                 r.Y = 0;
614                                 r.Width = bar.ClientRectangle.Width -  ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
615                                 r.Height = bar.ClientRectangle.Height;
616                                 
617                                 intersect = Rectangle.Intersect( clip, r );
618                                 if ( intersect != Rectangle.Empty )
619                                         dc.FillRectangle( lgbr, intersect );
620                         }
621                 }
622                 
623                 protected override void ScrollBar_Horizontal_Draw_ThumbMoving_Backwards( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
624                 {
625                         Rectangle r = new Rectangle( scrollbutton_width,  0,
626                                                     thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height );
627                         Rectangle intersect = Rectangle.Intersect( clip, r );
628                         
629                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( 0, 0 ), new Point( 0, r.Height - 1 ), LightColor, Color.White ) )
630                         {
631                                 if ( intersect != Rectangle.Empty )
632                                         dc.FillRectangle( lgbr, intersect );
633                                 
634                                 r.X = thumb_pos.X + thumb_pos.Width;
635                                 r.Y = 0;
636                                 r.Width = bar.ClientRectangle.Width -  ( thumb_pos.X + thumb_pos.Width ) - scrollbutton_width;
637                                 r.Height = bar.ClientRectangle.Height;
638                                 
639                                 intersect = Rectangle.Intersect( clip, r );
640                                 if ( intersect != Rectangle.Empty )
641                                         dc.FillRectangle( lgbr, intersect );
642                         }
643                 }
644                 #endregion      // ScrollBar
645                 
646                 #region StatusBar
647                 protected override void DrawStatusBarPanel( Graphics dc, Rectangle area, int index,
648                                                            SolidBrush br_forecolor, StatusBarPanel panel )
649                 {
650                         int border_size = 3; // this is actually const, even if the border style is none
651                         
652                         area.Height -= border_size;
653                         if ( panel.BorderStyle != StatusBarPanelBorderStyle.None )
654                         {
655                                 DrawNiceRoundedBorder( dc, area, BorderColor );
656                         }
657                         
658                         if ( panel.Style == StatusBarPanelStyle.OwnerDraw )
659                         {
660                                 StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs(
661                                         dc, panel.Parent.Font, area, index, DrawItemState.Default,
662                                         panel, panel.Parent.ForeColor, panel.Parent.BackColor );
663                                 panel.Parent.OnDrawItemInternal( e );
664                                 return;
665                         }
666                         
667                         int left = area.Left;
668                         if ( panel.Icon != null )
669                         {
670                                 left += 2;
671                                 dc.DrawIcon( panel.Icon, left, area.Top );
672                                 left += panel.Icon.Width;
673                         }
674                         
675                         if ( panel.Text == String.Empty )
676                                 return;
677                         
678                         string text = panel.Text;
679                         StringFormat string_format = new StringFormat( );
680                         string_format.Trimming = StringTrimming.Character;
681                         string_format.FormatFlags = StringFormatFlags.NoWrap;
682                         
683                         if ( text[ 0 ] == '\t' )
684                         {
685                                 string_format.Alignment = StringAlignment.Center;
686                                 text = text.Substring( 1 );
687                                 if ( text[ 0 ] == '\t' )
688                                 {
689                                         string_format.Alignment = StringAlignment.Far;
690                                         text = text.Substring( 1 );
691                                 }
692                         }
693                         
694                         int x = left + border_size;
695                         int y = border_size + 2;
696                         Rectangle r = new Rectangle( x, y,
697                                                     area.Right - x - border_size,
698                                                     area.Bottom - y - border_size );
699                         
700                         dc.DrawString( text, panel.Parent.Font, br_forecolor, r, string_format );
701                 }
702                 
703                 private void DrawNiceRoundedBorder( Graphics dc, Rectangle area, Color color )
704                 {
705                         Pen pen = ResPool.GetPen( color ); 
706                         
707                         Point[] points = new Point[] {
708                                 new Point( area.Left + 2, area.Top ),
709                                 new Point( area.Right - 2, area.Top ),
710                                 new Point( area.Right, area.Top + 2 ),
711                                 new Point( area.Right, area.Bottom - 2 ),
712                                 new Point( area.Right - 2, area.Bottom ),
713                                 new Point( area.Left + 2, area.Bottom ),
714                                 new Point( area.Left, area.Bottom - 2 ),
715                                 new Point( area.Left, area.Top + 2 ),
716                                 new Point( area.Left + 2, area.Top )
717                         };
718                         
719                         dc.DrawLines( pen, points );
720                 }
721                 #endregion      // StatusBar
722                 
723                 public override void DrawTabControl( Graphics dc, Rectangle area, TabControl tab )
724                 {
725                         // Do we need to fill the back color? It can't be changed...
726                         dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
727                         Rectangle panel_rect = GetTabPanelRectExt( tab );
728                         
729                         if ( tab.Appearance == TabAppearance.Normal )
730                         {
731                                 CPDrawBorder( dc, panel_rect, BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid,
732                                              BorderColor, 1, ButtonBorderStyle.Solid, BorderColor, 1, ButtonBorderStyle.Solid );
733                         }
734                         
735                         if ( tab.Alignment == TabAlignment.Top )
736                         {
737                                 for ( int r = tab.TabPages.Count; r > 0; r-- )
738                                 {
739                                         for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
740                                         {
741                                                 if ( i == tab.SelectedIndex )
742                                                         continue;
743                                                 if ( r != tab.TabPages[ i ].Row )
744                                                         continue;
745                                                 Rectangle rect = tab.GetTabRect( i );
746                                                 if ( !rect.IntersectsWith( area ) )
747                                                         continue;
748                                                 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
749                                         }
750                                 }
751                         }
752                         else
753                         {
754                                 for ( int r = 0; r < tab.TabPages.Count; r++ )
755                                 {
756                                         for ( int i = tab.SliderPos; i < tab.TabPages.Count; i++ )
757                                         {
758                                                 if ( i == tab.SelectedIndex )
759                                                         continue;
760                                                 if ( r != tab.TabPages[ i ].Row )
761                                                         continue;
762                                                 Rectangle rect = tab.GetTabRect( i );
763                                                 if ( !rect.IntersectsWith( area ) )
764                                                         continue;
765                                                 DrawTab( dc, tab.TabPages[ i ], tab, rect, false );
766                                         }
767                                 }
768                         }
769                         
770                         if ( tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos )
771                         {
772                                 Rectangle rect = tab.GetTabRect( tab.SelectedIndex );
773                                 if ( rect.IntersectsWith( area ) )
774                                         DrawTab( dc, tab.TabPages[ tab.SelectedIndex ], tab, rect, true );
775                         }
776                         
777                         if ( tab.ShowSlider )
778                         {
779                                 Rectangle right = GetTabControlRightScrollRect( tab );
780                                 Rectangle left = GetTabControlLeftScrollRect( tab );
781                                 CPDrawScrollButton( dc, right, ScrollButton.Right, tab.RightSliderState );
782                                 CPDrawScrollButton( dc, left, ScrollButton.Left, tab.LeftSliderState );
783                         }
784                 }
785                 
786                 protected override int DrawTab( Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected )
787                 {
788                         int FlatButtonSpacing = 8;
789                         Rectangle interior;
790                         int res = bounds.Width;
791                         
792                         // we can't fill the background right away because the bounds might be adjusted if the tab is selected
793                         
794                         if ( tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons )
795                         {
796                                 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
797                                 
798                                 // Separators
799                                 if ( tab.Appearance == TabAppearance.FlatButtons )
800                                 {
801                                         int width = bounds.Width;
802                                         bounds.Width += ( FlatButtonSpacing - 2 );
803                                         res = bounds.Width;
804                                         CPDrawBorder3D( dc, bounds, Border3DStyle.Etched, Border3DSide.Right );
805                                         bounds.Width = width;
806                                 }
807                                 
808                                 if ( is_selected )
809                                 {
810                                         CPDrawBorder3D( dc, bounds, Border3DStyle.Sunken, Border3DSide.All );
811                                 }
812                                 else if ( tab.Appearance != TabAppearance.FlatButtons )
813                                 {
814                                         CPDrawBorder3D( dc, bounds, Border3DStyle.Raised, Border3DSide.All );
815                                 }
816                                 
817                                 interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4 );
818                                 
819                                 
820                                 StringFormat string_format = new StringFormat( );
821                                 string_format.Alignment = StringAlignment.Center;
822                                 string_format.LineAlignment = StringAlignment.Center;
823                                 string_format.FormatFlags = StringFormatFlags.NoWrap;
824                                 
825                                 interior.Y++;
826                                 dc.DrawString( page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
827                                 interior.Y--;
828                         }
829                         else
830                         {
831                                 Pen border_pen = ResPool.GetPen( BorderColor );
832                                 
833                                 dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), bounds );
834                                 
835                                 switch ( tab.Alignment )
836                                 {
837                                         case TabAlignment.Top:
838                                                 
839                                                 if ( !is_selected )
840                                                 {
841                                                         interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
842                                                         
843                                                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2  ), new Point( bounds.Left + 2, bounds.Bottom ), Color.White, LightColor ) )
844                                                         {
845                                                                 dc.FillRectangle( lgbr, interior );
846                                                         }
847                                                 }
848                                                 
849                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3 );
850                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top );
851                                                 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Right - 3, bounds.Top );
852                                                 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
853                                                 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom );
854                                                 
855                                                 if ( page.Focused )
856                                                 {
857                                                         dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Top, bounds.Right - 1, bounds.Top );
858                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 1, bounds.Right , bounds.Top + 1 );
859                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Top + 2, bounds.Right , bounds.Top + 2 );
860                                                 }
861                                                 
862                                                 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
863                                                 
864                                                 if ( page.Text != String.Empty )
865                                                 {
866                                                         StringFormat string_format = new StringFormat( );
867                                                         string_format.Alignment = StringAlignment.Center;
868                                                         string_format.LineAlignment = StringAlignment.Center;
869                                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
870                                                         interior.Y++;
871                                                         dc.DrawString( page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
872                                                         interior.Y--;
873                                                 }
874                                                 
875                                                 break;
876                                                 
877                                         case TabAlignment.Bottom:
878                                                 
879                                                 if ( !is_selected )
880                                                 {
881                                                         interior = new Rectangle( bounds.Left + 3, bounds.Top, bounds.Width - 3, bounds.Height );
882                                                         
883                                                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 3, bounds.Top  ), new Point( bounds.Left + 3, bounds.Bottom  ), Color.White, LightColor ) )
884                                                         {
885                                                                 dc.FillRectangle( lgbr, interior );
886                                                         }
887                                                 }
888                                                 
889                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3 );
890                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
891                                                 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right - 3, bounds.Bottom );
892                                                 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Right, bounds.Bottom - 3 );
893                                                 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right, bounds.Top );
894                                                 
895                                                 if ( page.Focused )
896                                                 {
897                                                         dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left - 1 , bounds.Bottom, bounds.Right - 1, bounds.Bottom );
898                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 1, bounds.Right , bounds.Bottom - 1 );
899                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left , bounds.Bottom - 2, bounds.Right , bounds.Bottom - 2 );
900                                                 }
901                                                 
902                                                 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
903                                                 
904                                                 if ( page.Text != String.Empty )
905                                                 {
906                                                         StringFormat string_format = new StringFormat( );
907                                                         string_format.Alignment = StringAlignment.Center;
908                                                         string_format.LineAlignment = StringAlignment.Center;
909                                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
910                                                         interior.Y++;
911                                                         dc.DrawString( page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
912                                                         interior.Y--;
913                                                 }
914                                                 
915                                                 break;
916                                                 
917                                         case TabAlignment.Left:
918                                                 
919                                                 if ( !is_selected )
920                                                 {
921                                                         interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
922                                                         
923                                                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2  ), new Point( bounds.Right, bounds.Top + 2 ), LightColor, Color.White ) )
924                                                         {
925                                                                 dc.FillRectangle( lgbr, interior );
926                                                         }
927                                                 }
928                                                 
929                                                 dc.DrawLine( border_pen, bounds.Right, bounds.Top, bounds.Left + 3, bounds.Top );
930                                                 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Top, bounds.Left, bounds.Top + 3 );
931                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Top + 3, bounds.Left, bounds.Bottom - 3 );
932                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Bottom - 3, bounds.Left + 3, bounds.Bottom );
933                                                 dc.DrawLine( border_pen, bounds.Left + 3, bounds.Bottom, bounds.Right, bounds.Bottom );
934                                                 
935                                                 if ( page.Focused )
936                                                 {
937                                                         dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Left , bounds.Top + 1, bounds.Left , bounds.Bottom - 1 );
938                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 1 , bounds.Top, bounds.Left + 1 , bounds.Bottom );
939                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Left + 2 , bounds.Top, bounds.Left + 2 , bounds.Bottom );
940                                                 }
941                                                 
942                                                 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
943                                                 
944                                                 if ( page.Text != String.Empty )
945                                                 {
946                                                         StringFormat string_format = new StringFormat( );
947                                                         // Flip the text around
948                                                         string_format.Alignment = StringAlignment.Center;
949                                                         string_format.LineAlignment = StringAlignment.Center;
950                                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
951                                                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
952                                                         int wo = interior.Width / 2;
953                                                         int ho = interior.Height / 2;
954                                                         dc.TranslateTransform( interior.X + wo, interior.Y + ho );
955                                                         dc.RotateTransform( 180 );
956                                                         dc.DrawString( page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.ControlText ), 0, 0, string_format );
957                                                         dc.ResetTransform( );
958                                                 }
959                                                 
960                                                 break;
961                                                 
962                                         default:
963                                                 // TabAlignment.Right
964                                                 
965                                                 if ( !is_selected )
966                                                 {
967                                                         interior = new Rectangle( bounds.Left + 2, bounds.Top + 2, bounds.Width - 2, bounds.Height - 2 );
968                                                         
969                                                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( bounds.Left + 2, bounds.Top + 2  ), new Point( bounds.Right, bounds.Top + 2 ), Color.White, LightColor ) )
970                                                         {
971                                                                 dc.FillRectangle( lgbr, interior );
972                                                         }
973                                                 }
974                                                 
975                                                 dc.DrawLine( border_pen, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top );
976                                                 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3 );
977                                                 dc.DrawLine( border_pen, bounds.Right, bounds.Top + 3, bounds.Right, bounds.Bottom - 3 );
978                                                 dc.DrawLine( border_pen, bounds.Right, bounds.Bottom - 3, bounds.Right - 3, bounds.Bottom );
979                                                 dc.DrawLine( border_pen, bounds.Right - 3, bounds.Bottom, bounds.Left, bounds.Bottom );
980                                                 
981                                                 if ( page.Focused )
982                                                 {
983                                                         dc.DrawLine( ResPool.GetPen( Color.DarkOrange ), bounds.Right , bounds.Top + 1, bounds.Right , bounds.Bottom - 1 );
984                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 1 , bounds.Top, bounds.Right - 1 , bounds.Bottom );
985                                                         dc.DrawLine( ResPool.GetPen( Color.Orange ), bounds.Right - 2 , bounds.Top, bounds.Right - 2 , bounds.Bottom );
986                                                 }
987                                                 
988                                                 interior = new Rectangle( bounds.Left + 4, bounds.Top + 4, bounds.Width - 8, bounds.Height - 8 );
989                                                 
990                                                 if ( page.Text != String.Empty )
991                                                 {
992                                                         StringFormat string_format = new StringFormat( );
993                                                         string_format.Alignment = StringAlignment.Center;
994                                                         string_format.LineAlignment = StringAlignment.Center;
995                                                         string_format.FormatFlags = StringFormatFlags.NoWrap;
996                                                         string_format.FormatFlags = StringFormatFlags.DirectionVertical;
997                                                         interior.X++;
998                                                         dc.DrawString( page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush( SystemColors.ControlText ), interior, string_format );
999                                                         interior.X--;
1000                                                 }
1001                                                 
1002                                                 break;
1003                                 }
1004                         }
1005                         
1006                         return res;
1007                 }               
1008                 
1009                 public override void CPDrawComboButton( Graphics dc, Rectangle rectangle, ButtonState state )
1010                 {
1011                         Point[]                 arrow = new Point[ 3 ];
1012                         Point                           P1;
1013                         Point                           P2;
1014                         Point                           P3;
1015                         int                             centerX;
1016                         int                             centerY;
1017                         int                             shiftX;
1018                         int                             shiftY;
1019                         Rectangle               rect;
1020                         
1021                         Color first_color = Color.White;
1022                         Color second_color = NormalColor;
1023                         
1024 //                      rectangle.Width += 1;
1025                         
1026                         if ( ( state & ButtonState.Checked ) != 0 )
1027                         {
1028                                 dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorControlLightLight, ColorControlLight ), rectangle );
1029                         }
1030                         else
1031                                 dc.FillRectangle( ResPool.GetSolidBrush( Color.White ), rectangle );
1032                         
1033                         if ( ( state & ButtonState.Flat ) != 0 )
1034                         {
1035                                 first_color = NormalColor;
1036                                 second_color = Color.White;
1037                         }
1038                         else
1039                         {
1040                                 if ( ( state & ( ButtonState.Pushed | ButtonState.Checked ) ) != 0 )
1041                                 {
1042                                         first_color = Color.White;
1043                                         second_color = PressedColor;
1044                                 }
1045 //                              else
1046 //                              {
1047 //                                      CPDrawBorder3D( graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl );
1048 //                              }
1049                         }
1050                         
1051                         using ( LinearGradientBrush lgbr = new LinearGradientBrush( new Point( rectangle.X + 1, rectangle.Y + 1 ), new Point( rectangle.X + 1, rectangle.Bottom - 2 ), first_color, second_color ) )
1052                         {
1053                                 dc.FillRectangle( lgbr, rectangle.X + 2, rectangle.Y + 1, rectangle.Width - 4, rectangle.Height - 3 );
1054                         }
1055                         
1056                         Point[] points = new Point[] {
1057                                 new Point( rectangle.X + 3, rectangle.Y + 1 ),
1058                                 new Point( rectangle.Right - 4, rectangle.Y + 1 ),
1059                                 new Point( rectangle.Right - 2, rectangle.Y + 3 ),
1060                                 new Point( rectangle.Right - 2, rectangle.Bottom - 4 ),
1061                                 new Point( rectangle.Right - 4, rectangle.Bottom - 2 ),
1062                                 new Point( rectangle.X + 3, rectangle.Bottom - 2 ),
1063                                 new Point( rectangle.X + 1, rectangle.Bottom - 4 ),
1064                                 new Point( rectangle.X + 1, rectangle.Y + 3 ),
1065                                 new Point( rectangle.X + 3, rectangle.Y + 1 )
1066                         };
1067                         
1068                         dc.DrawPolygon( ResPool.GetPen( BorderColor ), points );
1069                         
1070                         rect = new Rectangle( rectangle.X + rectangle.Width / 4, rectangle.Y + rectangle.Height / 4, rectangle.Width / 2, rectangle.Height / 2 );
1071                         centerX = rect.Left + rect.Width / 2;
1072                         centerY = rect.Top + rect.Height / 2;
1073                         shiftX = Math.Max( 1, rect.Width / 8 );
1074                         shiftY = Math.Max( 1, rect.Height / 8 );
1075                         
1076                         if ( ( state & ButtonState.Pushed ) != 0 )
1077                         {
1078                                 shiftX--;
1079                                 shiftY--;
1080                         }
1081                         
1082                         rect.Y -= shiftY;
1083                         centerY -= shiftY;
1084                         
1085                         P1 = new Point( rect.Left, centerY );
1086                         P2 = new Point( centerX, rect.Bottom );
1087                         P3 = new Point( rect.Right, centerY );
1088                         
1089                         arrow[ 0 ] = P1;
1090                         arrow[ 1 ] = P2;
1091                         arrow[ 2 ] = P3;
1092                         
1093                         SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1094                         dc.SmoothingMode = SmoothingMode.AntiAlias;
1095                         
1096                         /* Draw the arrow */
1097                         if ( ( state & ButtonState.Inactive ) != 0 )
1098                         {
1099                                 using ( Pen pen = new Pen( SystemColors.ControlLightLight, 2 ) )
1100                                 {
1101                                         dc.DrawLines( pen, arrow );
1102                                 }
1103                                 
1104                                 /* Move away from the shadow */
1105                                 P1.X -= 1;              P1.Y -= 1;
1106                                 P2.X -= 1;              P2.Y -= 1;
1107                                 P3.X -= 1;              P3.Y -= 1;
1108                                 
1109                                 arrow[ 0 ] = P1;
1110                                 arrow[ 1 ] = P2;
1111                                 arrow[ 2 ] = P3;
1112                                 
1113                                 using ( Pen pen = new Pen( SystemColors.ControlDark, 2 ) )
1114                                 {
1115                                         dc.DrawLines( pen, arrow );
1116                                 }
1117                         }
1118                         else
1119                         {
1120                                 using ( Pen pen = new Pen( SystemColors.ControlText, 2 ) )
1121                                 {
1122                                         dc.DrawLines( pen, arrow );
1123                                 }
1124                         }
1125                         
1126                         dc.SmoothingMode = old_smoothing_mode;
1127                 }
1128                 
1129                 /* Scroll button: regular button + direction arrow */
1130                 public override void CPDrawScrollButton( Graphics dc, Rectangle area, ScrollButton scroll_button_type, ButtonState state )
1131                 {
1132                         bool enabled = ( state == ButtonState.Inactive ) ? false: true;
1133                         
1134                         DrawScrollButtonPrimitive( dc, area, state, scroll_button_type );
1135                         
1136                         if ( area.Width < 12 || area.Height < 12 ) /* Cannot see a thing at smaller sizes */
1137                                 return;
1138                         
1139                         Pen pen = null;
1140                         
1141                         if ( enabled )
1142                                 pen = new Pen( arrow_color, 2 );
1143                         else
1144                                 pen = new Pen( ColorGrayText, 2 );
1145                         
1146                         /* Paint arrows */
1147                         
1148                         int centerX = area.Left + area.Width / 2;
1149                         int centerY = area.Top + area.Height / 2;
1150                         
1151                         int shift = 0;
1152                         
1153                         if ( ( state & ButtonState.Pushed ) != 0 )
1154                                 shift = 1;
1155                         
1156                         Point[] arrow = new Point[ 3 ];
1157                         
1158                         switch ( scroll_button_type )
1159                         {
1160                                 case ScrollButton.Down:
1161                                         centerY += shift;
1162                                         arrow[ 0 ] = new Point( centerX - 3, centerY - 2 );
1163                                         arrow[ 1 ] = new Point( centerX, centerY + 2 );
1164                                         arrow[ 2 ] = new Point( centerX + 3, centerY - 2 );
1165                                         break;
1166                                 case ScrollButton.Up:
1167                                         centerY -= shift;
1168                                         arrow[ 0 ] = new Point( centerX - 3, centerY + 2 );
1169                                         arrow[ 1 ] = new Point( centerX, centerY - 2 );
1170                                         arrow[ 2 ] = new Point( centerX + 3, centerY + 2 );
1171                                         break;
1172                                 case ScrollButton.Left:
1173                                         centerX -= shift;
1174                                         arrow[ 0 ] = new Point( centerX + 2, centerY - 3 );
1175                                         arrow[ 1 ] = new Point( centerX - 2, centerY );
1176                                         arrow[ 2 ] = new Point( centerX + 2, centerY + 3 );
1177                                         break;
1178                                 case ScrollButton.Right:
1179                                         centerX += shift;
1180                                         arrow[ 0 ] = new Point( centerX - 2, centerY - 3 );
1181                                         arrow[ 1 ] = new Point( centerX + 2, centerY );
1182                                         arrow[ 2 ] = new Point( centerX - 2, centerY + 3 );
1183                                         break;
1184                                 default:
1185                                         break;
1186                         }
1187
1188                         SmoothingMode old_smoothing_mode = dc.SmoothingMode;
1189                         dc.SmoothingMode = SmoothingMode.AntiAlias;
1190                         
1191                         dc.DrawLines( pen, arrow );
1192                         
1193                         dc.SmoothingMode = old_smoothing_mode;
1194                         
1195                         pen.Dispose( );
1196                 }
1197                 
1198                 public override void CPDrawSizeGrip( Graphics dc, Color backColor, Rectangle bounds )
1199                 {
1200                         Point pt = new Point( bounds.Right - 4, bounds.Bottom - 4 );
1201                         
1202                         dc.DrawImage( size_grip_bmp, pt );
1203                         dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 5 );
1204                         dc.DrawImage( size_grip_bmp, pt.X, pt.Y - 10 );
1205                         dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y );
1206                         dc.DrawImage( size_grip_bmp, pt.X - 10, pt.Y );
1207                         dc.DrawImage( size_grip_bmp, pt.X - 5, pt.Y - 5 );
1208                 }
1209                 
1210                 private void DrawScrollBarThumb( Graphics dc, Rectangle area, ScrollBar bar )
1211                 {
1212                         LinearGradientBrush lgbr = null;
1213                         
1214                         if ( bar.vert )
1215                                 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right, area.Y ), Color.White, NormalColor );
1216                         else
1217                                 lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom ), Color.White, NormalColor );
1218                         
1219                         Pen pen = ResPool.GetPen( BorderColor );
1220                         
1221                         Point[] points = new Point[] {
1222                                 new Point( area.X + 2, area.Y ),
1223                                 new Point( area.Right - 3, area.Y ),
1224                                 new Point( area.Right - 1, area.Y + 2 ),
1225                                 new Point( area.Right - 1, area.Bottom - 3 ),
1226                                 new Point( area.Right - 3, area.Bottom - 1 ),
1227                                 new Point( area.X + 2, area.Bottom - 1 ),
1228                                 new Point( area.X, area.Bottom - 3 ),
1229                                 new Point( area.X, area.Y + 2 ),
1230                                 new Point( area.X + 2, area.Y )
1231                         };
1232                         
1233                         if ( bar.vert )
1234                         {
1235                                 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1236                                 dc.DrawPolygon( pen, points );
1237                                 
1238                                 // draw grip lines only if stere is enough space
1239                                 if ( area.Height > 20 )
1240                                 {
1241                                         int mid_y = area.Y + ( area.Height / 2 );
1242                                         int mid_x = area.X + ( area.Width / 2 );
1243                                         
1244                                         using ( Pen lpen = new Pen( MouseOverColor, 2 ) )
1245                                         {
1246                                                 dc.DrawLine( lpen, mid_x - 3, mid_y, mid_x + 3, mid_y );
1247                                                 dc.DrawLine( lpen, mid_x - 3, mid_y - 4, mid_x + 3, mid_y - 4 );
1248                                                 dc.DrawLine( lpen, mid_x - 3, mid_y + 4, mid_x + 3, mid_y + 4 );
1249                                         }
1250                                         
1251                                         Pen spen = ResPool.GetPen( Color.White );
1252                                         dc.DrawLine( spen, mid_x - 3, mid_y - 1, mid_x + 3, mid_y - 1 );
1253                                         dc.DrawLine( spen, mid_x - 3, mid_y - 5, mid_x + 3, mid_y - 5 );
1254                                         dc.DrawLine( spen, mid_x - 3, mid_y + 3, mid_x + 3, mid_y + 3 );
1255                                 }
1256                         }
1257                         else
1258                         {
1259                                 dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1260                                 dc.DrawPolygon( pen, points );
1261                                 
1262                                 // draw grip lines only if stere is enough space
1263                                 if ( area.Width > 20 )
1264                                 {
1265                                         int mid_x = area.X +  ( area.Width / 2 );
1266                                         int mid_y = area.Y +  ( area.Height / 2 );
1267                                         
1268                                         using ( Pen lpen = new Pen( MouseOverColor, 2 ) )
1269                                         {
1270                                                 dc.DrawLine( lpen, mid_x, mid_y - 3, mid_x, mid_y + 3 );
1271                                                 dc.DrawLine( lpen, mid_x - 4, mid_y - 3, mid_x - 4, mid_y + 3 );
1272                                                 dc.DrawLine( lpen, mid_x + 4, mid_y - 3, mid_x + 4, mid_y + 3 );
1273                                         }
1274                                         
1275                                         Pen spen = ResPool.GetPen( Color.White );
1276                                         dc.DrawLine( spen, mid_x - 1, mid_y - 3, mid_x - 1, mid_y + 3 );
1277                                         dc.DrawLine( spen, mid_x - 5, mid_y - 3, mid_x - 5, mid_y + 3 );
1278                                         dc.DrawLine( spen, mid_x + 3, mid_y - 3, mid_x + 3, mid_y + 3 );
1279                                 }
1280                         }
1281                         
1282                         lgbr.Dispose( );
1283                 }
1284                 
1285                 /* Nice scroll button */
1286                 public void DrawScrollButtonPrimitive( Graphics dc, Rectangle area, ButtonState state, ScrollButton scroll_button_type )
1287                 {
1288                         Pen pen = ResPool.GetPen( BorderColor );
1289                         
1290                         dc.FillRectangle( ResPool.GetSolidBrush( NiceBackColor ), area );
1291                         
1292                         Color use_color;
1293                         
1294                         if ( ( state & ButtonState.Pushed ) == ButtonState.Pushed )
1295                                 use_color = PressedColor;
1296                         else
1297                                 use_color = NormalColor;
1298                         
1299                         Point[] points = null;
1300                         
1301                         LinearGradientBrush lgbr = null;
1302                         
1303                         switch ( scroll_button_type )
1304                         {
1305                                 case ScrollButton.Left:
1306                                         lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 2, area.Y ), use_color, Color.White );
1307                                         dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 4, area.Height - 2 );
1308                                         
1309                                         points = new Point[] {
1310                                                 new Point( area.X + 2, area.Y ),
1311                                                 new Point( area.Right - 1, area.Y ),
1312                                                 new Point( area.Right - 1, area.Bottom - 1 ),
1313                                                 new Point( area.X + 2, area.Bottom - 1 ),
1314                                                 new Point( area.X, area.Bottom - 3 ),
1315                                                 new Point( area.X, area.Y + 2 ),
1316                                                 new Point( area.X + 2, area.Y )
1317                                         };
1318                                         dc.DrawPolygon( pen, points );
1319                                         break;
1320                                 case ScrollButton.Right:
1321                                         lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.Right - 1, area.Y ), Color.White, use_color );
1322                                         dc.FillRectangle( lgbr, area.X, area.Y + 1, area.Width - 1, area.Height - 2 );
1323                                         
1324                                         points = new Point[] {
1325                                                 new Point( area.X, area.Y ),
1326                                                 new Point( area.Right - 3, area.Y ),
1327                                                 new Point( area.Right - 1, area.Y + 2 ),
1328                                                 new Point( area.Right - 1, area.Bottom - 3 ),
1329                                                 new Point( area.Right - 3, area.Bottom - 1 ),
1330                                                 new Point( area.X, area.Bottom - 1 ),
1331                                                 new Point( area.X, area.Y ),
1332                                         };
1333                                         dc.DrawPolygon( pen, points );
1334                                         break;
1335                                 case ScrollButton.Up:
1336                                         lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), use_color, Color.White );
1337                                         dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1338                                         
1339                                         points = new Point[] {
1340                                                 new Point( area.X + 2, area.Y ),
1341                                                 new Point( area.Right - 3, area.Y ),
1342                                                 new Point( area.Right - 1, area.Y + 2 ),
1343                                                 new Point( area.Right - 1, area.Bottom - 1 ),
1344                                                 new Point( area.X, area.Bottom - 1 ),
1345                                                 new Point( area.X, area.Y + 2 ),
1346                                                 new Point( area.X + 2, area.Y )
1347                                         };
1348                                         dc.DrawPolygon( pen, points );
1349                                         break;
1350                                 case ScrollButton.Down:
1351                                         lgbr = new LinearGradientBrush( new Point( area.X, area.Y ), new Point( area.X, area.Bottom - 1 ), Color.White, use_color );
1352                                         dc.FillRectangle( lgbr, area.X + 1, area.Y + 1, area.Width - 2, area.Height - 2 );
1353                                         
1354                                         points = new Point[] {
1355                                                 new Point( area.X, area.Y ),
1356                                                 new Point( area.Right - 1, area.Y ),
1357                                                 new Point( area.Right - 1, area.Bottom - 3 ),
1358                                                 new Point( area.Right - 3, area.Bottom - 1 ),
1359                                                 new Point( area.X + 2, area.Bottom - 1 ),
1360                                                 new Point( area.X, area.Bottom - 3 ),
1361                                                 new Point( area.X, area.Y )
1362                                         };
1363                                         dc.DrawPolygon( pen, points );
1364                                         break;
1365                         }
1366                         
1367                         lgbr.Dispose( );
1368                 }
1369                 
1370                 #region GroupBox
1371                 public override void DrawGroupBox (Graphics dc,  Rectangle area, GroupBox box) 
1372                 {
1373                         StringFormat    text_format;
1374                         SizeF           size;
1375                         int             width;
1376                         int             y;
1377                         Rectangle       rect;
1378                         
1379                         rect = box.ClientRectangle;
1380                         
1381                         dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
1382                         
1383                         text_format = new StringFormat();
1384                         text_format.HotkeyPrefix = HotkeyPrefix.Show;
1385                         
1386                         size = dc.MeasureString (box.Text, box.Font);
1387                         width = (int) size.Width;
1388                         
1389                         if (width > box.Width - 16)
1390                                 width = box.Width - 16;
1391                         
1392                         y = box.Font.Height / 2;
1393                         
1394                         Pen pen = ResPool.GetPen( BorderColor );
1395                         
1396                         /* Draw group box*/
1397                         Point[] points = new Point[] {
1398                                 new Point( 8 + width, y ),
1399                                 new Point( box.Width - 3, y ),
1400                                 new Point( box.Width - 1, y + 2 ),
1401                                 new Point( box.Width - 1, box.Height - 3 ),
1402                                 new Point( box.Width - 3, box.Height - 1 ),
1403                                 new Point( 2, box.Height - 1 ),
1404                                 new Point( 0, box.Height - 3 ),
1405                                 new Point( 0, y + 2 ),
1406                                 new Point( 2, y ),
1407                                 new Point( 8, y )
1408                         };
1409                         dc.DrawLines( pen, points );
1410                         
1411                         /* Text */
1412                         if (box.Enabled) {
1413                                 dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
1414                         } else {
1415                                 CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor, 
1416                                                       new RectangleF (10, 0, width,  box.Font.Height), text_format);
1417                         }
1418                         text_format.Dispose (); 
1419                 }
1420                 #endregion
1421         } //class
1422 }
1423