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