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