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