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