* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
index 19f3b82bcdc72a847789ec2632d2d77690372df2..b2d26b3100b4a55b0fb50c5017abb231f03136ee 100644 (file)
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-// Copyright (c) 2004-2005 Novell, Inc.
+// Copyright (c) 2004-2006 Novell, Inc.
 //
 // Authors:
 //     Jordi Mas i Hernandez, jordi@ximian.com
 //     Peter Bartok, pbartok@novell.com
 //     John BouAntoun, jba-mono@optusnet.com.au
-//  Marek Safar, marek.safar@seznam.cz
+//     Marek Safar, marek.safar@seznam.cz
+//     Alexander Olk, alex.olk@googlemail.com
 //
 
-
+using System.ComponentModel;
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
+using System.Text;
 
 namespace System.Windows.Forms
 {
@@ -50,7 +52,6 @@ namespace System.Windows.Forms
                protected static StringFormat string_format_menu_text;
                protected static StringFormat string_format_menu_shortcut;
                protected static StringFormat string_format_menu_menubar_text;
-               static readonly Rectangle checkbox_rect = new Rectangle (2, 2, 11,11); // Position of the checkbox relative to the item
                static ImageAttributes imagedisabled_attributes = null;
                const int SEPARATOR_HEIGHT = 5;
                const int SM_CXBORDER = 1;
@@ -63,7 +64,7 @@ namespace System.Windows.Forms
                {                       
                        defaultWindowBackColor = this.ColorWindow;
                        defaultWindowForeColor = this.ColorControlText;
-                       default_font =  new Font (FontFamily.GenericSansSerif, 8.25f);
+                       default_font =  new Font (FontFamily.GenericSansSerif, 8f);
                        
                        /* Menu string formats */
                        string_format_menu_text = new StringFormat ();
@@ -79,40 +80,55 @@ namespace System.Windows.Forms
                        string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
                        string_format_menu_menubar_text.Alignment = StringAlignment.Center;
                        string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
-               }       
+                       always_draw_hotkeys = false;
+               }
 
                public override void ResetDefaults() {
-                       throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
+                       Console.WriteLine("NOT IMPLEMENTED: ResetDefault()");
+                       //throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
                }
 
                public override bool DoubleBufferingSupported {
                        get {return true; }
                }
+
+               public override int HorizontalScrollBarHeight {
+                       get {
+                               return XplatUI.HorizontalScrollBarHeight;
+                       }
+               }
+
+               public override int VerticalScrollBarWidth {
+                       get {
+                               return XplatUI.VerticalScrollBarWidth;
+                       }
+               }
+
                #endregion      // Principal Theme Methods
 
                #region Internal Methods
-               protected SolidBrush GetControlBackBrush (Color c) {
-                       if (c == DefaultControlBackColor)
-                               return ResPool.GetSolidBrush (ColorControl);
-                       return new SolidBrush (c);
+               protected Brush GetControlBackBrush (Color c) {
+                       if (c.ToArgb () == DefaultControlBackColor.ToArgb ())
+                               return SystemBrushes.Control;
+                       return ResPool.GetSolidBrush (c);
                }
 
-               protected SolidBrush GetControlForeBrush (Color c) {
-                       if (c == DefaultControlForeColor)
-                               return ResPool.GetSolidBrush (ColorControlText);
-                       return new SolidBrush (c);
+               protected Brush GetControlForeBrush (Color c) {
+                       if (c.ToArgb () == DefaultControlForeColor.ToArgb ())
+                               return SystemBrushes.ControlText;
+                       return ResPool.GetSolidBrush (c);
                }
                #endregion      // Internal Methods
 
                #region OwnerDraw Support
                public  override void DrawOwnerDrawBackground (DrawItemEventArgs e)
                {
-                       if (e.State == DrawItemState.Selected) {
+                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
                                e.Graphics.FillRectangle (SystemBrushes.Highlight, e.Bounds);
                                return;
                        }
 
-                       e.Graphics.FillRectangle (GetControlBackBrush (e.BackColor), e.Bounds);
+                       e.Graphics.FillRectangle (ResPool.GetSolidBrush(e.BackColor), e.Bounds);
                }
 
                public  override void DrawOwnerDrawFocusRectangle (DrawItemEventArgs e)
@@ -124,15 +140,20 @@ namespace System.Windows.Forms
 
                #region ButtonBase
                public override void DrawButtonBase(Graphics dc, Rectangle clip_area, ButtonBase button) {
-                       // Draw the button: fill rectangle, draw border, etc.
-                       ButtonBase_DrawButton(button, dc);
+                       
+                       // Fill the button with the correct color
+                       bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
+                       dc.FillRectangle (is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
                        
                        // First, draw the image
                        if ((button.image != null) || (button.image_list != null))
                                ButtonBase_DrawImage(button, dc);
                        
+                       // Draw the button: Draw border, etc.
+                       ButtonBase_DrawButton(button, dc);
+                       
                        // Draw the focus rectangle
-                       if (button.has_focus)
+                       if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled)
                                ButtonBase_DrawFocus(button, dc);
                        
                        // Now the text
@@ -140,32 +161,106 @@ namespace System.Windows.Forms
                                ButtonBase_DrawText(button, dc);
                }
 
-               protected virtual void ButtonBase_DrawButton(ButtonBase button, Graphics dc)
+               protected virtual void ButtonBase_DrawButton (ButtonBase button, Graphics dc)
                {
-                       Rectangle buttonRectangle;
                        Rectangle borderRectangle;
+                       bool check_or_radio = false;
+                       bool check_or_radio_checked = false;
                        
-                       dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);
+                       bool is_ColorControl = button.BackColor.ToArgb () == ColorControl.ToArgb () ? true : false;
                        
-                       // set up the button rectangle
-                       buttonRectangle = button.ClientRectangle;
-                       if (button.has_focus) {
+                       CPColor cpcolor = is_ColorControl ? CPColor.Empty : ResPool.GetCPColor (button.BackColor);
+                       
+                       if (button is CheckBox) {
+                               check_or_radio = true;
+                               check_or_radio_checked = ((CheckBox)button).Checked;
+                       } else if (button is RadioButton) {
+                               check_or_radio = true;
+                               check_or_radio_checked = ((RadioButton)button).Checked;
+                       }
+                       
+                       if ((button.Focused || button.paint_as_acceptbutton) && button.Enabled && !check_or_radio) {
                                // shrink the rectangle for the normal button drawing inside the focus rectangle
-                               borderRectangle = Rectangle.Inflate(buttonRectangle, -1, -1);
+                               borderRectangle = Rectangle.Inflate (button.ClientRectangle, -1, -1);
                        } else {
-                               borderRectangle = buttonRectangle;
+                               borderRectangle = button.ClientRectangle;
                        }
-
-                       if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
-                               DrawFlatStyleButton (dc, borderRectangle, button);
-                       } else {
-                               CPDrawButton(dc, borderRectangle, button.ButtonState);
-                               if (button.has_focus) {
-                                       dc.DrawRectangle(ResPool.GetPen(button.ForeColor), borderRectangle);
+                       
+                       if (button.FlatStyle == FlatStyle.Popup) {
+                               if (!button.is_pressed && !button.is_entered && !check_or_radio_checked)
+                                       Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
+                               else if (!button.is_pressed && button.is_entered &&!check_or_radio_checked)
+                                       Internal_DrawButton (dc, borderRectangle, 2, cpcolor, is_ColorControl, button.BackColor);
+                               else if (button.is_pressed || check_or_radio_checked)
+                                       Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
+                       } else if (button.FlatStyle == FlatStyle.Flat) {
+                               if (button.is_entered && !button.is_pressed && !check_or_radio_checked) {
+                                       if ((button.image == null) && (button.image_list == null)) {
+                                               Brush brush = is_ColorControl ? SystemBrushes.ControlDark : ResPool.GetSolidBrush (cpcolor.Dark);
+                                               dc.FillRectangle (brush, borderRectangle);
+                                       }
+                               } else if (button.is_pressed || check_or_radio_checked) {
+                                       if ((button.image == null) && (button.image_list == null)) {
+                                               Brush brush = is_ColorControl ? SystemBrushes.ControlLightLight : ResPool.GetSolidBrush (cpcolor.LightLight);
+                                               dc.FillRectangle (brush, borderRectangle);
+                                       }
+                                       
+                                       Pen pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                                       dc.DrawRectangle (pen, borderRectangle.X + 4, borderRectangle.Y + 4,
+                                                         borderRectangle.Width - 9, borderRectangle.Height - 9);
                                }
+                               
+                               Internal_DrawButton (dc, borderRectangle, 3, cpcolor, is_ColorControl, button.BackColor);
+                       } else {
+                               if ((!button.is_pressed || !button.Enabled) && !check_or_radio_checked)
+                                       Internal_DrawButton (dc, borderRectangle, 0, cpcolor, is_ColorControl, button.BackColor);
+                               else
+                                       Internal_DrawButton (dc, borderRectangle, 1, cpcolor, is_ColorControl, button.BackColor);
                        }
                }
-
+               
+               private void Internal_DrawButton (Graphics dc, Rectangle rect, int state, CPColor cpcolor, bool is_ColorControl, Color backcolor)
+               {
+                       switch (state) {
+                       case 0: // normal or normal disabled button
+                               Pen pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
+                               dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
+                               
+                               pen = is_ColorControl ? SystemPens.Control : ResPool.GetPen (backcolor);
+                               dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 3);
+                               dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 3, rect.Y + 1);
+                               
+                               pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               dc.DrawLine (pen, rect.X + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
+                               dc.DrawLine (pen, rect.Right - 2, rect.Y + 1, rect.Right - 2, rect.Bottom - 3);
+                               
+                               pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
+                               dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
+                               break;
+                       case 1: // popup button normal (or pressed normal or popup button)
+                               pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
+                               break;
+                       case 2: // popup button poped up
+                               pen = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 2);
+                               dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 2, rect.Y);
+                               
+                               pen = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               dc.DrawLine (pen, rect.X, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
+                               dc.DrawLine (pen, rect.Right - 1, rect.Y, rect.Right - 1, rect.Bottom - 2);
+                               break;
+                       case 3: // flat button not entered
+                               pen = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               dc.DrawRectangle (pen, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
+                               break;
+                       default:
+                               break;
+                       }
+               }
+               
                protected virtual void ButtonBase_DrawImage(ButtonBase button, Graphics dc)
                {
                        // Need to draw a picture
@@ -177,84 +272,79 @@ namespace System.Windows.Forms
                        
                        int width = button.ClientSize.Width;
                        int height = button.ClientSize.Height;
-                       
+
                        if (button.ImageIndex != -1) {   // We use ImageIndex instead of image_index since it will return -1 if image_list is null
                                i = button.image_list.Images[button.image_index];
                        } else {
                                i = button.image;
                        }
-                       
-                       image_width = button.image.Width;
-                       image_height = button.image.Height;
+
+                       image_width = i.Width;
+                       image_height = i.Height;
                        
                        switch (button.image_alignment) {
                                case ContentAlignment.TopLeft: {
-                                       image_x=0;
-                                       image_y=0;
+                                       image_x = 5;
+                                       image_y = 5;
                                        break;
                                }
                                        
                                case ContentAlignment.TopCenter: {
-                                       image_x=(width-image_width)/2;
-                                       image_y=0;
+                                       image_x = (width - image_width) / 2;
+                                       image_y = 5;
                                        break;
                                }
                                        
                                case ContentAlignment.TopRight: {
-                                       image_x=width-image_width;
-                                       image_y=0;
+                                       image_x = width - image_width - 5;
+                                       image_y = 5;
                                        break;
                                }
                                        
                                case ContentAlignment.MiddleLeft: {
-                                       image_x=0;
-                                       image_y=(height-image_height)/2;
+                                       image_x = 5;
+                                       image_y = (height - image_height) / 2;
                                        break;
                                }
                                        
                                case ContentAlignment.MiddleCenter: {
-                                       image_x=(width-image_width)/2;
-                                       image_y=(height-image_height)/2;
+                                       image_x = (width - image_width) / 2;
+                                       image_y = (height - image_height) / 2;
                                        break;
                                }
                                        
                                case ContentAlignment.MiddleRight: {
-                                       image_x=width-image_width;
-                                       image_y=(height-image_height)/2;
+                                       image_x = width - image_width - 4;
+                                       image_y = (height - image_height) / 2;
                                        break;
                                }
                                        
                                case ContentAlignment.BottomLeft: {
-                                       image_x=0;
-                                       image_y=height-image_height;
+                                       image_x = 5;
+                                       image_y = height - image_height - 4;
                                        break;
                                }
                                        
                                case ContentAlignment.BottomCenter: {
-                                       image_x=(width-image_width)/2;
-                                       image_y=height-image_height;
+                                       image_x = (width - image_width) / 2;
+                                       image_y = height - image_height - 4;
                                        break;
                                }
                                        
                                case ContentAlignment.BottomRight: {
-                                       image_x=width-image_width;
-                                       image_y=height-image_height;
+                                       image_x = width - image_width - 4;
+                                       image_y = height - image_height - 4;
                                        break;
                                }
                                        
                                default: {
-                                       image_x=0;
-                                       image_y=0;
+                                       image_x = 5;
+                                       image_y = 5;
                                        break;
                                }
                        }
                        
-                       if (button.is_pressed) {
-                               image_x+=1;
-                               image_y+=1;
-                       }
-                       
-                       if (button.is_enabled) {
+                       if (button.Enabled) {
                                dc.DrawImage(i, image_x, image_y); 
                        }
                        else {
@@ -264,12 +354,23 @@ namespace System.Windows.Forms
                
                protected virtual void ButtonBase_DrawFocus(ButtonBase button, Graphics dc)
                {
-                       if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
-                               DrawFlatStyleFocusRectangle (dc, button.ClientRectangle, button, button.ForeColor, button.BackColor);
-                       } else { 
-                               Rectangle rect = button.ClientRectangle;
-                               rect.Inflate (-4, -4);
-                               CPDrawFocusRectangle(dc, rect, button.ForeColor, button.BackColor);
+                       Color focus_color = button.ForeColor;
+                       
+                       int inflate_value = -3;
+                       
+                       if (!(button is CheckBox) && !(button is RadioButton)) {
+                               inflate_value = -4;
+                               
+                               if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed)
+                                       focus_color = ControlPaint.Dark(button.BackColor);
+                               
+                               dc.DrawRectangle (ResPool.GetPen (focus_color), button.ClientRectangle.X, button.ClientRectangle.Y, 
+                                                 button.ClientRectangle.Width - 1, button.ClientRectangle.Height - 1);
+                       }
+                       
+                       if (button.Focused) {
+                               Rectangle rect = Rectangle.Inflate (button.ClientRectangle, inflate_value, inflate_value);
+                               ControlPaint.DrawFocusRectangle (dc, rect);
                        }
                }
                
@@ -283,103 +384,17 @@ namespace System.Windows.Forms
                                text_rect.Y++;
                        }
                        
-                       if (button.is_enabled) {                                        
+                       if (button.Enabled) {                                   
                                dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (button.ForeColor), text_rect, button.text_format);
                        } else {
                                if (button.FlatStyle == FlatStyle.Flat || button.FlatStyle == FlatStyle.Popup) {
-                                       dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rect, button.text_format);
+                                       dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
                                } else {
-                                       CPDrawStringDisabled(dc, button.text, button.Font, ColorControlText, text_rect, button.text_format);
+                                       CPDrawStringDisabled (dc, button.text, button.Font, button.BackColor, text_rect, button.text_format);
                                }
                        }
                }
                
-               // draw the flat style part of the rectangle
-               public void DrawFlatStyleButton (Graphics graphics, Rectangle rectangle, ButtonBase button) {
-                       Color rect_back_color = button.BackColor;
-                       Color rect_fore_color = button.ForeColor;
-                       Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
-                               
-                       if (button.Enabled) {
-                               if (button.Capture || button.is_entered) {
-                                       if (button.FlatStyle == FlatStyle.Flat) {
-                                               // fill the rectangle
-                                               graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
-                                               
-                                               // now draw the outer border
-                                               if (button.Capture && button.is_entered) {
-                                                       rect_back_color = ControlPaint.LightLight (rect_back_color);
-                                               } else {
-                                                       rect_back_color = ControlPaint.Light (rect_back_color);
-                                               }
-                                               
-                                               // draw rectangle and fill it
-                                               graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
-                                               graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
-                                       } else {
-                                               // else it must be a popup button
-                                               
-                                               if (button.Capture && button.is_entered) {
-                                                       graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
-                                               } else {
-                                                       // draw a 3d border
-                                                       CPDrawBorder3D (graphics, rectangle, Border3DStyle.RaisedInner, Border3DSide.Left | Border3DSide.Top, button.BackColor); 
-                                                       graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.X, trace_rectangle.Bottom, trace_rectangle.Right, trace_rectangle.Bottom);
-                                                       graphics.DrawLine ( ResPool.GetPen (this.ColorControlText), trace_rectangle.Right, trace_rectangle.Y, trace_rectangle.Right, trace_rectangle.Bottom);
-                                               }
-                                       }
-                                       
-                                       // TODO: draw inner focus rectangle
-                                       
-                               } else {
-                                       // popup has a ButtonColorText forecolor, not a button.ForeCOlor
-                                       if (button.FlatStyle == FlatStyle.Popup) {
-                                               rect_fore_color = this.ColorControlText;
-                                       }
-                                       
-                                       // fill then draw outer rect
-                                       graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
-                                       graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
-                               }
-                               
-                               // finally some small tweaks to render radiobutton and checkbox
-                               CheckBox checkbox = button as CheckBox;
-                               RadioButton radiobutton = button as RadioButton;
-                               if ((checkbox != null && checkbox.Checked) ||
-                                       (radiobutton != null && radiobutton.Checked)) {
-                                       if (button.FlatStyle == FlatStyle.Flat && button.is_entered && !button.Capture) {
-                                               // render the hover for flat flatstyle and cheked
-                                               graphics.DrawRectangle(ResPool.GetPen (this.ColorControlText), trace_rectangle);
-                                       } else if (!button.is_entered && !button.Capture) {
-                                               // render the checked state for popup when unhovered
-                                               CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor); 
-                                       }
-                               }
-                       } else {
-                               // rendering checkbox or radio button style buttons
-                               CheckBox checkbox = button as CheckBox;
-                               RadioButton radiobutton = button as RadioButton;
-                               bool draw_popup_checked = false;
-                               
-                               if (button.FlatStyle == FlatStyle.Popup) {
-                                       rect_fore_color = this.ColorControlText;
-                               
-                                       // see if we should draw a disabled checked popup button
-                                       draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
-                                               (radiobutton != null && radiobutton.Checked));
-                               }
-                               
-                               graphics.FillRectangle (ResPool.GetSolidBrush (rect_back_color), rectangle);
-                               graphics.DrawRectangle(ResPool.GetPen (rect_fore_color), trace_rectangle);
-                               
-                               // finally draw the flatstyle checked effect if need
-                               if (draw_popup_checked) {
-                                       // render the checked state for popup when unhovered
-                                       CPDrawBorder3D (graphics, rectangle, Border3DStyle.SunkenInner, Border3DSide.Right | Border3DSide.Bottom, button.BackColor);
-                               }
-                       }
-               }
-
                public override Size ButtonBaseDefaultSize {
                        get {
                                return new Size (75, 23);
@@ -557,11 +572,13 @@ namespace System.Windows.Forms
                                state |= ButtonState.Pushed;
                        }
                        
-                       
                        // Start drawing
                        
                        CheckBox_DrawCheckBox(dc, checkbox, state, checkbox_rectangle);
                        
+                       if ((checkbox.image != null) || (checkbox.image_list != null))
+                               ButtonBase_DrawImage(checkbox, dc);
+                       
                        CheckBox_DrawText(checkbox, text_rectangle, dc, text_format);
 
                        CheckBox_DrawFocus(checkbox, dc, text_rectangle);
@@ -571,60 +588,36 @@ namespace System.Windows.Forms
 
                protected virtual void CheckBox_DrawCheckBox( Graphics dc, CheckBox checkbox, ButtonState state, Rectangle checkbox_rectangle )
                {
-                       dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);                        
+                       Brush brush = checkbox.BackColor.ToArgb () == ColorControl.ToArgb () ? SystemBrushes.Control : ResPool.GetSolidBrush (checkbox.BackColor);
+                       dc.FillRectangle (brush, checkbox.ClientRectangle);                     
                        // render as per normal button
                        if (checkbox.appearance==Appearance.Button) {
-                               if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
-                                       DrawFlatStyleButton(dc, checkbox.ClientRectangle, checkbox);
-                               } else {
-                                       CPDrawButton(dc, checkbox.ClientRectangle, state);
-                               }
+                               ButtonBase_DrawButton (checkbox, dc);
+                               
+                               if ((checkbox.Focused) && checkbox.Enabled)
+                                       ButtonBase_DrawFocus(checkbox, dc);
                        } else {
                                // establish if we are rendering a flat style of some sort
                                if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
                                        DrawFlatStyleCheckBox (dc, checkbox_rectangle, checkbox);
                                } else {
-                                       ControlPaint.DrawCheckBox(dc, checkbox_rectangle, state);
+                                       CPDrawCheckBox (dc, checkbox_rectangle, state);
                                }
                        }
                }
                
                protected virtual void CheckBox_DrawText( CheckBox checkbox, Rectangle text_rectangle, Graphics dc, StringFormat text_format )
                {
-                       SolidBrush sb;
-                       
-                       // offset the text if it's pressed and a button
-                       if (checkbox.Appearance == Appearance.Button) {
-                               if (checkbox.Checked || (checkbox.Capture && checkbox.FlatStyle != FlatStyle.Flat)) {
-                                       text_rectangle.X ++;
-                                       text_rectangle.Y ++;
-                               }
-                               
-                               text_rectangle.Inflate(-4, -4);
-                       }
-                       
-                       /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
-                       if (checkbox.Enabled) {
-                               sb = ResPool.GetSolidBrush(checkbox.ForeColor);
-                               dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);                   
-                       } else if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
-                               dc.DrawString(checkbox.Text, checkbox.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
-                       } else {
-                               CPDrawStringDisabled(dc, checkbox.Text, checkbox.Font, ColorControlText, text_rectangle, text_format);
-                       }
+                       DrawCheckBox_and_RadioButtonText (checkbox, text_rectangle, dc, 
+                                                         text_format, checkbox.Appearance, checkbox.Checked);
                }
                
                protected virtual void CheckBox_DrawFocus( CheckBox checkbox, Graphics dc, Rectangle text_rectangle )
                {
-                       if (checkbox.Focused) {
-                               if (checkbox.FlatStyle != FlatStyle.Flat) {
-                                       DrawInnerFocusRectangle (dc, Rectangle.Inflate (text_rectangle, -1, -1), checkbox.BackColor);
-                               } else {
-                                       dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (text_rectangle, -1, -1));
-                               }
-                       }
+                       if ( checkbox.Focused && checkbox.appearance != Appearance.Button && checkbox.Enabled )
+                               DrawInnerFocusRectangle( dc, text_rectangle, checkbox.BackColor );
                }
-
+               
                // renders a checkBox with the Flat and Popup FlatStyle
                protected virtual void DrawFlatStyleCheckBox (Graphics graphics, Rectangle rectangle, CheckBox checkbox)
                {
@@ -645,7 +638,8 @@ namespace System.Windows.Forms
                                checkbox_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max(rectangle.Width-2, 0), Math.Max(rectangle.Height-2,0));
                                fill_rectangle = new Rectangle(checkbox_rectangle.X+1, checkbox_rectangle.Y+1, Math.Max(checkbox_rectangle.Width-2, 0), Math.Max(checkbox_rectangle.Height-2,0));
                        }       
-                               
+                       
+                       
                        // if disabled render in disabled state
                        if (checkbox.Enabled) {
                                // process the state of the checkbox
@@ -653,8 +647,11 @@ namespace System.Windows.Forms
                                        // decide on which background color to use
                                        if (checkbox.FlatStyle == FlatStyle.Popup && checkbox.is_entered && checkbox.Capture) {
                                                graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
-                                       } else if (checkbox.FlatStyle == FlatStyle.Flat && !(checkbox.is_entered && checkbox.Capture)) {
-                                               graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.Light(checkbox.BackColor)), fill_rectangle);
+                                       } else if (checkbox.FlatStyle == FlatStyle.Flat) { 
+                                               if (!checkbox.is_pressed) {
+                                                       graphics.FillRectangle(ResPool.GetSolidBrush (checkbox.BackColor), fill_rectangle);
+                                               } else
+                                                       graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
                                        } else {
                                                // use regular window background color
                                                graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);
@@ -665,7 +662,7 @@ namespace System.Windows.Forms
                                                ControlPaint.DrawBorder(graphics, checkbox_rectangle, checkbox.ForeColor, ButtonBorderStyle.Solid);
                                        } else {
                                                // draw sunken effect
-                                               CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.All, checkbox.BackColor);
+                                               CPDrawBorder3D (graphics, checkbox_rectangle, Border3DStyle.SunkenInner, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, checkbox.BackColor);
                                        }
                                } else {
                                        graphics.FillRectangle(ResPool.GetSolidBrush (ControlPaint.LightLight (checkbox.BackColor)), fill_rectangle);                           
@@ -686,20 +683,21 @@ namespace System.Windows.Forms
                                ControlPaint.DrawBorder(graphics, checkbox_rectangle, ColorControlDark, ButtonBorderStyle.Solid);
                        }               
                        
-                       /* Make sure we've got at least a line width of 1 */
-                       lineWidth = Math.Max(3, fill_rectangle.Width/3);
-                       Scale=Math.Max(1, fill_rectangle.Width/9);
-                       
-                       // flat style check box is rendered inside a rectangle shifted down by one
-                       rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
-                       if (checkbox.Enabled) {
-                               pen=ResPool.GetPen(checkbox.ForeColor);
-                       } else {
-                               pen=SystemPens.ControlDark;
-                       }
-
                        if (checkbox.Checked) {
                                /* Need to draw a check-mark */
+                               
+                               /* Make sure we've got at least a line width of 1 */
+                               lineWidth = Math.Max(3, fill_rectangle.Width/3);
+                               Scale=Math.Max(1, fill_rectangle.Width/9);
+                               
+                               // flat style check box is rendered inside a rectangle shifted down by one
+                               rect=new Rectangle(fill_rectangle.X, fill_rectangle.Y+1, fill_rectangle.Width, fill_rectangle.Height);
+                               if (checkbox.Enabled) {
+                                       pen=ResPool.GetPen(checkbox.ForeColor);
+                               } else {
+                                       pen=SystemPens.ControlDark;
+                               }
+                               
                                for (int i=0; i<lineWidth; i++) {
                                        graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
                                        graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
@@ -707,33 +705,56 @@ namespace System.Windows.Forms
                        }                                       
                }
 
-
+               private void DrawCheckBox_and_RadioButtonText (ButtonBase button_base, Rectangle text_rectangle, Graphics dc, 
+                                                              StringFormat text_format, Appearance appearance, bool ischecked)
+               {
+                       // offset the text if it's pressed and a button
+                       if (appearance == Appearance.Button) {
+                               if (ischecked || (button_base.Capture && button_base.FlatStyle != FlatStyle.Flat)) {
+                                       text_rectangle.X ++;
+                                       text_rectangle.Y ++;
+                               }
+                               
+                               text_rectangle.Inflate (-4, -4);
+                       }
+                       
+                       /* Place the text; to be compatible with Windows place it after the checkbox has been drawn */
+                       
+                       // Windows seems to not wrap text in certain situations, this matches as close as I could get it
+                       if ((float)(button_base.Font.Height * 1.5f) > text_rectangle.Height) {
+                               text_format.FormatFlags |= StringFormatFlags.NoWrap;
+                       }
+                       if (button_base.Enabled) {
+                               dc.DrawString (button_base.Text, button_base.Font, ResPool.GetSolidBrush (button_base.ForeColor), text_rectangle, text_format);                 
+                       } else if (button_base.FlatStyle == FlatStyle.Flat || button_base.FlatStyle == FlatStyle.Popup) {
+                               dc.DrawString (button_base.Text, button_base.Font, SystemBrushes.ControlDarkDark, text_rectangle, text_format);
+                       } else {
+                               CPDrawStringDisabled (dc, button_base.Text, button_base.Font, button_base.BackColor, text_rectangle, text_format);
+                       }
+               }
                #endregion      // CheckBox
                
                #region CheckedListBox
                
-               public override Rectangle CheckedListBoxCheckRectangle ()
-               {
-                       return checkbox_rect;
-               }
-               
                public override void DrawCheckedListBoxItem (CheckedListBox ctrl, DrawItemEventArgs e)
                {                       
                        Color back_color, fore_color;
                        Rectangle item_rect = e.Bounds;
                        ButtonState state;
-                       StringFormat string_format = ctrl.GetFormatString ();
 
                        /* Draw checkbox */             
 
-                       if ((ctrl.Items.GetListBoxItem (e.Index)).State == CheckState.Checked)
+                       if ((e.State & DrawItemState.Checked) == DrawItemState.Checked) {
                                state = ButtonState.Checked;
-                       else
+                               if ((e.State & DrawItemState.Inactive) == DrawItemState.Inactive)
+                                       state |= ButtonState.Inactive;
+                       } else
                                state = ButtonState.Normal;
 
                        if (ctrl.ThreeDCheckBoxes == false)
                                state |= ButtonState.Flat;
 
+                       Rectangle checkbox_rect = new Rectangle (2, (item_rect.Height - 11) / 2, 11, 11);
                        ControlPaint.DrawCheckBox (e.Graphics,
                                item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
                                checkbox_rect.Width, checkbox_rect.Height,
@@ -744,90 +765,30 @@ namespace System.Windows.Forms
                        
                        /* Draw text*/
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
-                               back_color = ThemeEngine.Current.ColorHighlight;
-                               fore_color = ThemeEngine.Current.ColorHighlightText;
+                               back_color = ColorHighlight;
+                               fore_color = ColorHighlightText;
                        }
                        else {
                                back_color = e.BackColor;
                                fore_color = e.ForeColor;
                        }
                        
-                       e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
+                       e.Graphics.FillRectangle (ResPool.GetSolidBrush
                                (back_color), item_rect);
 
                        e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
-                               ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
-                               item_rect, string_format);
+                               ResPool.GetSolidBrush (fore_color),
+                               item_rect, ctrl.StringFormat);
                                        
                        if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
-                               ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, item_rect,
+                               CPDrawFocusRectangle (e.Graphics, item_rect,
                                        fore_color, back_color);
                        }
                }
                
                #endregion // CheckedListBox
                
-               #region ComboBox
-               
-               // Drawing
-               
-               public override void DrawComboBoxEditDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
-               {                               
-                       dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top 
-                       dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
-                       dc.DrawLine (ResPool.GetPen (ColorControl), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
-                       dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
-                       dc.DrawLine (ResPool.GetPen (ColorControlDark), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
-                       dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2); 
-                       dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
-                       dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);                            
-               }               
-               
-               // Sizing                               
-               public override int DrawComboBoxEditDecorationTop () { return 2;}
-               public override int DrawComboBoxEditDecorationBottom () { return 2;}
-               public override int DrawComboBoxEditDecorationRight () { return 2;}
-               public override int DrawComboBoxEditDecorationLeft () { return 2;}
-               
-               private int DrawComboListBoxDecoration (ComboBoxStyle style)
-               {
-                       if (style == ComboBoxStyle.Simple)
-                               return 2;
-                       else
-                               return 1;
-               }
-                               
-               public override int DrawComboListBoxDecorationTop (ComboBoxStyle style) 
-               {
-                       return DrawComboListBoxDecoration (style);
-               }
-               
-               public override int DrawComboListBoxDecorationBottom (ComboBoxStyle style)
-               {
-                       return DrawComboListBoxDecoration (style);
-               }
-               
-               public override int DrawComboListBoxDecorationRight (ComboBoxStyle style)
-               {
-                       return DrawComboListBoxDecoration (style);
-               }
-               
-               public override int DrawComboListBoxDecorationLeft (ComboBoxStyle style)
-               {
-                       return DrawComboListBoxDecoration (style);
-               }
-               
-               public override void DrawComboListBoxDecorations (Graphics dc, ComboBox ctrl, Rectangle cl)
-               {
-                       if (ctrl.DropDownStyle == ComboBoxStyle.Simple) {
-                               DrawComboBoxEditDecorations (dc, ctrl, cl);
-                       }
-                       else {                  
-                               dc.DrawRectangle (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorWindowFrame),
-                                       cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
-                       }                       
-               }
-               
+               #region ComboBox                
                public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
                {
                        Color back_color, fore_color;
@@ -836,29 +797,31 @@ namespace System.Windows.Forms
                        string_format.FormatFlags = StringFormatFlags.LineLimit;
                        
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
-                               back_color = ThemeEngine.Current.ColorHighlight;
-                               fore_color = ThemeEngine.Current.ColorHighlightText;
+                               back_color = ColorHighlight;
+                               fore_color = ColorHighlightText;
                        }
                        else {
                                back_color = e.BackColor;
                                fore_color = e.ForeColor;
-                       }                       
+                       }
+                       
+                       if (!ctrl.Enabled)
+                               fore_color = ColorInactiveCaptionText;
                                                        
-                       e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (back_color), e.Bounds);
+                       e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
 
                        if (e.Index != -1) {
                                e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
-                                       ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
+                                       ResPool.GetSolidBrush (fore_color),
                                        text_draw, string_format);
                        }
                        
                        if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
-                               ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
+                               CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
                        }
 
                        string_format.Dispose ();
                }
-               
                #endregion ComboBox
                
                #region Datagrid
@@ -882,57 +845,63 @@ namespace System.Windows.Forms
                
                public override void DataGridPaint (PaintEventArgs pe, DataGrid grid)
                {
-                       // Draw parent rows
-                       if (pe.ClipRectangle.IntersectsWith (grid.grid_drawing.parent_rows)) {
-                               pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor), grid.grid_drawing.parent_rows);
-                       }
-
                        DataGridPaintCaption (pe.Graphics, pe.ClipRectangle, grid);
-                       DataGridPaintColumnsHdrs (pe.Graphics, pe.ClipRectangle, grid);
-                       DataGridPaintRowsHeaders (pe.Graphics, pe.ClipRectangle, grid);
-                       DataGridPaintRows (pe.Graphics, grid.grid_drawing.cells_area, pe.ClipRectangle, grid);
+                       DataGridPaintParentRows (pe.Graphics, pe.ClipRectangle, grid);
+                       DataGridPaintColumnHeaders (pe.Graphics, pe.ClipRectangle, grid);
+                       DataGridPaintRows (pe.Graphics, grid.cells_area, pe.ClipRectangle, grid);
 
                        // Paint scrollBar corner
-                       if (grid.vert_scrollbar.Visible && grid.horiz_scrollbar.Visible) {
+                       if (grid.VScrollBar.Visible && grid.HScrollBar.Visible) {
 
-                               Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.horiz_scrollbar.Height,
-                                        grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.horiz_scrollbar.Height,
-                                        grid.horiz_scrollbar.Height, grid.horiz_scrollbar.Height);
+                               Rectangle corner = new Rectangle (grid.ClientRectangle.X + grid.ClientRectangle.Width - grid.HScrollBar.Width,
+                                                                 grid.ClientRectangle.Y + grid.ClientRectangle.Height - grid.VScrollBar.Height,
+                                                                 grid.VScrollBar.Width, grid.HScrollBar.Height);
 
                                if (pe.ClipRectangle.IntersectsWith (corner)) {
                                        pe.Graphics.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
-                                               corner);
+                                                                  corner);
                                }
                        }
                }
-               
+
                public override void DataGridPaintCaption (Graphics g, Rectangle clip, DataGrid grid)
                {
                        Rectangle modified_area = clip;
-                       modified_area.Intersect (grid.grid_drawing.caption_area);
+                       modified_area.Intersect (grid.caption_area);
 
                        g.FillRectangle (ResPool.GetSolidBrush (grid.CaptionBackColor),
-                               modified_area);
+                                        modified_area);
 
                        g.DrawString (grid.CaptionText, grid.CaptionFont,
-                               ThemeEngine.Current.ResPool.GetSolidBrush (grid.CaptionForeColor),
-                               grid.grid_drawing.caption_area);                
+                                     ResPool.GetSolidBrush (grid.CaptionForeColor),
+                                     grid.caption_area);
+
+                       if (modified_area.IntersectsWith (grid.back_button_rect)) {
+                               g.DrawImage (grid.back_button_image, grid.back_button_rect);
+                               if (grid.back_button_mouseover) {
+                                       CPDrawBorder3D (g, grid.back_button_rect, grid.back_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
+                               }
+                       }
+                       if (modified_area.IntersectsWith (grid.parent_rows_button_rect)) {
+                               g.DrawImage (grid.parent_rows_button_image, grid.parent_rows_button_rect);
+                               if (grid.parent_rows_button_mouseover) {
+                                       CPDrawBorder3D (g, grid.parent_rows_button_rect, grid.parent_rows_button_active ? Border3DStyle.Sunken : Border3DStyle.Raised, all_sides);
+                               }
+                       }
                }
 
-               public override void DataGridPaintColumnsHdrs (Graphics g, Rectangle clip, DataGrid grid)
+               public override void DataGridPaintColumnHeaders (Graphics g, Rectangle clip, DataGrid grid)
                {
-                       Rectangle columns_area = grid.grid_drawing.columnshdrs_area;
+                       Rectangle columns_area = grid.columnhdrs_area;
 
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) { // Paint corner shared between row and column header
-                               Rectangle rect_bloc = grid.grid_drawing.columnshdrs_area;
+                               Rectangle rect_bloc = grid.columnhdrs_area;
                                rect_bloc.Width = grid.RowHeaderWidth;
-                               rect_bloc.Height = grid.grid_drawing.columnshdrs_area.Height;
                                if (clip.IntersectsWith (rect_bloc)) {
-                                       if (grid.visiblecolumn_count > 0) {
+                                       if (grid.VisibleColumnCount > 0)
                                                g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor), rect_bloc);
-                                       }else {
+                                       else
                                                g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), rect_bloc);
-                                       }
                                }
 
                                columns_area.X += grid.RowHeaderWidth;
@@ -940,11 +909,11 @@ namespace System.Windows.Forms
                        }
 
                        // Set unused area
-                       Rectangle columnshdrs_area_complete = columns_area;
-                       columnshdrs_area_complete.Width = grid.grid_drawing.columnshdrs_maxwidth;
+                       Rectangle columnhdrs_area_complete = columns_area;
+                       columnhdrs_area_complete.Width = grid.columnhdrs_maxwidth;
                        
                        if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
-                               columnshdrs_area_complete.Width -= grid.RowHeaderWidth;
+                               columnhdrs_area_complete.Width -= grid.RowHeaderWidth;
                        }               
 
                        // Set column painting
@@ -954,80 +923,129 @@ namespace System.Windows.Forms
                        rect_columnhdr.Y = columns_area.Y;
                        rect_columnhdr.Height = columns_area.Height;
                        
-                       current_clip = new Region (columns_area);
-                       g.Clip = current_clip;
-                       int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
-                       for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
+                       int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
+                       for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
                                
-                               col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
-                               rect_columnhdr.X = columns_area.X + col_pixel - grid.horz_pixeloffset;
+                               col_pixel = grid.GetColumnStartingPixel (column);
+                               rect_columnhdr.X = columns_area.X + col_pixel - grid.HorizPixelOffset;
                                rect_columnhdr.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
 
                                if (clip.IntersectsWith (rect_columnhdr) == false)
                                        continue;
 
+                               current_clip = new Region (rect_columnhdr);
+                               current_clip.Intersect (columns_area);
+                               current_clip.Intersect (clip);
+                               g.Clip = current_clip;
+
                                grid.CurrentTableStyle.GridColumnStyles[column].PaintHeader (g, rect_columnhdr, column);
 
-                               
+                               current_clip.Dispose ();
                        }
 
-                       current_clip.Dispose ();
                        g.ResetClip ();
-                       
-                       // This fills with background colour the unused part in the row headers
-                       if (rect_columnhdr.X + rect_columnhdr.Height < grid.ClientRectangle.X + grid.ClientRectangle.Width) {
                                
-                               Rectangle not_usedarea = columnshdrs_area_complete;                             
-                               not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
-                               not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;
+                       Rectangle not_usedarea = columnhdrs_area_complete;                              
+                       not_usedarea.X = rect_columnhdr.X + rect_columnhdr.Width;
+                       not_usedarea.Width = grid.ClientRectangle.X + grid.ClientRectangle.Width - rect_columnhdr.X - rect_columnhdr.Height;            
+                       g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
                        
-                               g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
-                                       not_usedarea);
-                       }
                }
 
-               public override void DataGridPaintRowsHeaders (Graphics g, Rectangle clip, DataGrid grid)
+               public override void DataGridPaintParentRows (Graphics g, Rectangle clip, DataGrid grid)
                {
-                       Rectangle rowshdrs_area_complete = grid.grid_drawing.rowshdrs_area;
-                       rowshdrs_area_complete.Height = grid.grid_drawing.rowshdrs_maxheight;
                        Rectangle rect_row = new Rectangle ();
-                       rect_row.X = grid.grid_drawing.rowshdrs_area.X;
-                       int last_y = 0;
-                       int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
 
-                       if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
-                               rowcnt++;
-                       }
+                       rect_row.X = grid.ParentRowsArea.X;
+                       rect_row.Width = grid.ParentRowsArea.Width;
+                       rect_row.Height = (grid.CaptionFont.Height + 3);
 
-                       g.SetClip (grid.grid_drawing.rowshdrs_area);
-                       for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {
+                       g.SetClip (grid.ParentRowsArea);
 
-                               rect_row.Width = grid.grid_drawing.rowshdrs_area.Width;
-                               rect_row.Height = grid.RowHeight;
-                               rect_row.Y = grid.grid_drawing.rowshdrs_area.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
+                       object[] parentRows = grid.dataSourceStack.ToArray();
+                       
+                       Region current_clip;
+                       for (int row = 0; row < parentRows.Length; row++) {
+                               rect_row.Y = grid.ParentRowsArea.Y + row * rect_row.Height;
 
-                               if (clip.IntersectsWith (rect_row)) {
-                                       DataGridPaintRowHeader (g, rect_row, row, grid);
-                                       last_y = rect_row.Y;
-                               }
+                               if (clip.IntersectsWith (rect_row) == false)
+                                       continue;
+
+                               current_clip = new Region (rect_row);
+                               current_clip.Intersect (clip);
+                               g.Clip = current_clip;
+
+                               DataGridPaintParentRow (g, rect_row, (DataGridDataSource)parentRows[parentRows.Length - row - 1], grid);
+
+                               current_clip.Dispose ();
                        }
                        
                        g.ResetClip ();
+               }
 
-                       // This fills with background colour the unused part in the row headers
-                       if (last_y > 0 && rect_row.Y + rect_row.Height < grid.grid_drawing.cells_area.Y + grid.grid_drawing.cells_area.Height) {
-                               Rectangle not_usedarea = clip;
-                               not_usedarea.Intersect (rowshdrs_area_complete);
-                               
-                               not_usedarea.Y = rect_row.Y + rect_row.Height;
-                               not_usedarea.Height = rowshdrs_area_complete.Y + rowshdrs_area_complete.Height - rect_row.Height - rect_row.Y;
-                               g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
-                                       not_usedarea);
-                       }                       
+               public override void DataGridPaintParentRow (Graphics g, Rectangle bounds, DataGridDataSource row, DataGrid grid)
+               {
+                       //Console.WriteLine ("drawing parent row {0}", row);
 
-                       
+                       // Background
+                       g.FillRectangle (ResPool.GetSolidBrush (grid.ParentRowsBackColor),
+                                        bounds);
+
+                       Font bold_font = new Font (grid.Font.FontFamily, grid.Font.Size, grid.Font.Style | FontStyle.Bold);
+                       // set up some standard string formating variables
+                       StringFormat text_format = new StringFormat();
+                       text_format.LineAlignment = StringAlignment.Center;
+                       text_format.Alignment = StringAlignment.Near;
+
+                       string table_name = ((ITypedList)row.view.DataView).GetListName (null) + ": ";
+
+                       Rectangle       text_rect;
+                       Size            text_size;
+
+                       text_size = g.MeasureString (table_name, bold_font).ToSize();
+                       text_rect = new Rectangle(new Point(bounds.X + 3, bounds.Y + bounds.Height - text_size.Height), text_size);
+
+                       //Console.WriteLine ("drawing text at {0}", text_rect);
+
+                       g.DrawString (table_name,
+                                     bold_font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
+
+                       foreach (PropertyDescriptor pd in ((ICustomTypeDescriptor)row.view).GetProperties()) {
+                               if (typeof(IBindingList).IsAssignableFrom (pd.PropertyType))
+                                       continue;
+
+                               text_rect.X += text_rect.Size.Width + 5;
+
+                               string text = String.Format ("{0}: {1}",
+                                                            pd.Name,
+                                                            pd.GetValue (row.view));
+
+                               text_rect.Size = g.MeasureString (text, grid.Font).ToSize();
+                               text_rect.Y = bounds.Y + bounds.Height - text_rect.Height; // XXX
+
+                               //Console.WriteLine ("drawing text at {0}", text_rect);
+
+                               g.DrawString (text,
+                                             grid.Font, ResPool.GetSolidBrush (grid.ParentRowsForeColor), text_rect, text_format);
+                       }
+
+                       if (grid.FlatMode == false) {
+                               
+                               // Paint Borders
+                               g.DrawLine (ResPool.GetPen (ColorControlLight),
+                                       bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
+       
+                               g.DrawLine (ResPool.GetPen (ColorControlLight),
+                                       bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
+       
+                               g.DrawLine (ResPool.GetPen (ColorControlDark),
+                                       bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
+       
+                               g.DrawLine (ResPool.GetPen (ColorControlDark),
+                                       bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y  + bounds.Height -1);
+                       }
                }
-               
+
                public override void DataGridPaintRowHeaderArrow (Graphics g, Rectangle bounds, DataGrid grid) 
                {               
                        Point[] arrow = new Point[3];
@@ -1050,52 +1068,48 @@ namespace System.Windows.Forms
                        arrow[1] = P2;
                        arrow[2] = P3;
                        
-                       g.FillPolygon (ThemeEngine.Current.ResPool.GetSolidBrush 
+                       g.FillPolygon (ResPool.GetSolidBrush 
                                (grid.CurrentTableStyle.CurrentHeaderForeColor), arrow, FillMode.Winding);
                }
 
                public override void DataGridPaintRowHeader (Graphics g, Rectangle bounds, int row, DataGrid grid)
                {
+                       bool is_add_row = grid.ShowEditRow && row == grid.Rows.Length - 1;
+                       bool is_current_row = row == grid.CurrentCell.RowNumber;
+
                        // Background
-                       g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
+                       g.FillRectangle (ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderBackColor),
                                bounds);
-                               
-                       if (grid.FlatMode == false) {
-                               
+
+                       // Draw arrow
+                       if (is_current_row) {
+                               if (grid.IsChanging) {
+                                       g.DrawString ("...", grid.Font,
+                                                     ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
+                                                     bounds);
+                               } else {
+                                       Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);
+                                       DataGridPaintRowHeaderArrow (g, rect, grid);
+                               }
+                       }
+                       else if (is_add_row) {
+                               g.DrawString ("*", grid.Font, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
+                                             bounds);
+                       }
+
+                       if (grid.FlatMode == false && !is_add_row) {
                                // Paint Borders
-                               g.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlLight),
-                                       bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
-       
-                               g.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlLight),
-                                       bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
-       
-                               g.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
-                                       bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
-       
-                               g.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
-                                       bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y  + bounds.Height -1);
-                       }
+                               g.DrawLine (ResPool.GetPen (ColorControlLight),
+                                           bounds.X, bounds.Y, bounds.X + bounds.Width, bounds.Y);
 
-                       if (grid.ShowEditRow && row == grid.RowsCount  && !(row == grid.CurrentCell.RowNumber && grid.is_changing == true)) {
-                               
-                               g.DrawString ("*", grid.grid_drawing.font_newrow, ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
-                                       bounds);
-                               
-                       } else {
-                               // Draw arrow
-                               if (row == grid.CurrentCell.RowNumber) {
-       
-                                       if (grid.is_changing == true) {
-                                               g.DrawString ("...", grid.Font,
-                                                       ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.CurrentHeaderForeColor),
-                                                       bounds);
-       
-                                       } else {
-                                               
-                                               Rectangle rect = new Rectangle (bounds.X - 2, bounds.Y, 18, 18);                                                                                        
-                                               DataGridPaintRowHeaderArrow (g, rect, grid);
-                                       }
-                               }
+                               g.DrawLine (ResPool.GetPen (ColorControlLight),
+                                           bounds.X, bounds.Y + 1, bounds.X, bounds.Y + bounds.Height - 1);
+
+                               g.DrawLine (ResPool.GetPen (ColorControlDark),
+                                           bounds.X + bounds.Width - 1, bounds.Y + 1 , bounds.X + bounds.Width - 1, bounds.Y + bounds.Height - 1);
+
+                               g.DrawLine (ResPool.GetPen (ColorControlDark),
+                                           bounds.X, bounds.Y + bounds.Height -1, bounds.X + bounds.Width, bounds.Y  + bounds.Height -1);
                        }
                }
                
@@ -1103,48 +1117,164 @@ namespace System.Windows.Forms
                {
                        Rectangle rect_row = new Rectangle ();
                        Rectangle not_usedarea = new Rectangle ();
-                       rect_row.X = cells.X;
 
-                       int rowcnt = grid.FirstVisibleRow + grid.VisibleRowCount;
+                       int rowcnt = grid.VisibleRowCount;
                        
-                       if (grid.ShowEditRow) {
-                               rowcnt--;
-                       }                       
+                       bool showing_add_row = false;
 
-                       if (rowcnt < grid.RowsCount) { // Paint one row more for partial rows
-                               rowcnt++;
-                       }                       
-                       
-                       rect_row.Height = grid.RowHeight;
-                       rect_row.Width = cells.Width;
-                       for (int row = grid.FirstVisibleRow; row < rowcnt; row++) {                                                             
-                               rect_row.Y = cells.Y + ((row - grid.FirstVisibleRow) * grid.RowHeight);
-                               if (clip.IntersectsWith (rect_row)) {
-                                       DataGridPaintRow (g, row, rect_row, false, grid);
+                       if (grid.ListManager.Count < grid.Rows.Length) {
+                               /* the table has an add row */
+
+                               if (grid.FirstVisibleRow + grid.VisibleRowCount >= grid.Rows.Length) {
+                                       showing_add_row = true;
                                }
                        }
-                       
-                       if (grid.ShowEditRow && grid.FirstVisibleRow + grid.VisibleRowCount == grid.RowsCount + 1) {
-                               rect_row.Y = cells.Y + ((rowcnt - grid.FirstVisibleRow) * grid.RowHeight);
+
+                       rect_row.Width = cells.Width;
+                       for (int r = 0; r < rowcnt; r++) {
+                               int row = grid.FirstVisibleRow + r;
+                               if (row == grid.Rows.Length - 1)
+                                       rect_row.Height = grid.Rows[row].Height;
+                               else
+                                       rect_row.Height = grid.Rows[row + 1].VerticalOffset - grid.Rows[row].VerticalOffset;
+                               rect_row.Y = cells.Y + grid.Rows[row].VerticalOffset - grid.Rows[grid.FirstVisibleRow].VerticalOffset;
                                if (clip.IntersectsWith (rect_row)) {
-                                       DataGridPaintRow (g, rowcnt, rect_row, true, grid);
+                                       if (grid.CurrentTableStyle.HasRelations
+                                           && !(showing_add_row && row == grid.Rows.Length - 1))
+                                               DataGridPaintRelationRow (g, row, rect_row, false, clip, grid);
+                                       else
+                                               DataGridPaintRow (g, row, rect_row, showing_add_row && row == grid.Rows.Length - 1, clip, grid);
                                }
                        }
-                       
+
+                       // XXX this should be moved elsewhere and turned into 1 g.FillRectangle call, not grid.Rows.Length separate calls
                        not_usedarea.Height = cells.Y + cells.Height - rect_row.Y - rect_row.Height;
                        not_usedarea.Y = rect_row.Y + rect_row.Height;
-                       not_usedarea.Width = rect_row.Width = cells.Width;
-                       not_usedarea.X = cells.X;                       
+                       not_usedarea.Width = cells.Width + grid.RowHeadersArea.Width;
+                       not_usedarea.X = 0;
 
-                       g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.BackgroundColor),
-                               not_usedarea);                  
+                       g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor), not_usedarea);
                }
-               
-               public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow, DataGrid grid)
-               {                       
+
+               public override void DataGridPaintRelationRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
+                                                              Rectangle clip, DataGrid grid)
+               {
+                       Rectangle rect_header;
+                       Rectangle icon_bounds = new Rectangle ();
+                       Pen pen = ThemeEngine.Current.ResPool.GetPen (grid.CurrentTableStyle.ForeColor);
+
+                       /* paint the header if it's visible and intersects the clip */
+                       if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
+                               rect_header = row_rect;
+                               rect_header.Width = grid.RowHeaderWidth;
+                               row_rect.X += grid.RowHeaderWidth;
+                               if (clip.IntersectsWith (rect_header)) {
+                                       DataGridPaintRowHeader (g, rect_header, row, grid);
+                               }
+
+                               icon_bounds = rect_header;
+                               icon_bounds.X += icon_bounds.Width / 2;
+                               icon_bounds.Y += 3;
+                               icon_bounds.Width = 8;
+                               icon_bounds.Height = 8;
+
+                               g.DrawRectangle (pen, icon_bounds);
+
+                               /* the - part of the icon */
+                               g.DrawLine (pen,
+                                           icon_bounds.X + 2, icon_bounds.Y + icon_bounds.Height / 2,
+                                           icon_bounds.X + icon_bounds.Width - 2, icon_bounds.Y + icon_bounds.Height / 2);
+                                           
+                               if (!grid.IsExpanded (row)) {
+                                       /* the | part of the icon */
+                                       g.DrawLine (pen,
+                                                   icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + 2,
+                                                   icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height - 2);
+                               }
+                       }
+
+                       Rectangle nested_rect = row_rect;
+
+                       if (grid.Rows[row].IsExpanded)
+                               nested_rect.Height -= grid.Rows[row].RelationHeight;
+
+                       DataGridPaintRowContents (g, row, nested_rect, is_newrow, clip, grid);
+
+                       if (grid.Rows[row].IsExpanded) {
+                               // XXX we should create this in the
+                               // datagrid and cache it for use by
+                               // the theme instead of doing it each
+                               // time through here
+                               string[] relations = grid.CurrentTableStyle.Relations;
+                               StringBuilder relation_builder = new StringBuilder ("");
+
+                               for (int i = 0; i < relations.Length; i ++) {
+                                       if (i > 0)
+                                               relation_builder.Append ("\n");
+
+                                       relation_builder.Append (relations[i]);
+                               }
+                               string relation_text = relation_builder.ToString ();
+
+                               StringFormat string_format = new StringFormat ();
+                               string_format.FormatFlags |= StringFormatFlags.NoWrap;
+
+
+                               //Region prev_clip = g.Clip;
+                               //Region current_clip;
+                               Rectangle rect_cell = row_rect;
+
+                               rect_cell.X = row_rect.X + grid.GetColumnStartingPixel (grid.FirstVisibleColumn) - grid.HorizPixelOffset;
+                               rect_cell.Y += nested_rect.Height;
+                               rect_cell.Height = grid.Rows[row].RelationHeight;
+                               rect_cell.Width = 0;
+
+                               int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
+                               for (int column = grid.FirstVisibleColumn; column < column_cnt; column++)
+                                       rect_cell.Width += grid.CurrentTableStyle.GridColumnStyles[column].Width;
+
+                               g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.CurrentTableStyle.BackColor),
+                                                rect_cell);
+
+
+                               /* draw the line leading from the +/- to the relation area */
+                               Rectangle outline = grid.Rows[row].relation_area;
+                               outline.Y = rect_cell.Y;
+                               outline.Height --;
+
+                               g.DrawLine (pen,
+                                           icon_bounds.X + icon_bounds.Width / 2, icon_bounds.Y + icon_bounds.Height,
+                                           icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2);
+
+                               g.DrawLine (pen,
+                                           icon_bounds.X + icon_bounds.Width / 2, outline.Y + outline.Height / 2,
+                                           outline.X, outline.Y + outline.Height / 2);
+
+                               g.DrawRectangle (pen, outline);
+
+                               g.DrawString (relation_text, grid.LinkFont, ResPool.GetSolidBrush (grid.LinkColor),
+                                             outline, string_format);
+
+                               if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
+                                       Rectangle not_usedarea = new Rectangle ();
+                                       not_usedarea.X = rect_cell.X + rect_cell.Width;
+                                       not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
+                                       not_usedarea.Y = row_rect.Y;
+                                       not_usedarea.Height = row_rect.Height;
+                                       if (clip.IntersectsWith (not_usedarea))
+                                               g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
+                                                                not_usedarea);
+                               }
+                       }
+               }
+
+               public override void DataGridPaintRowContents (Graphics g, int row, Rectangle row_rect, bool is_newrow,
+                                                              Rectangle clip, DataGrid grid)
+               {
                        Rectangle rect_cell = new Rectangle ();
                        int col_pixel;
                        Color backcolor, forecolor;
+                       Brush backBrush, foreBrush;
                        Region prev_clip = g.Clip;
                        Region current_clip;
                        Rectangle not_usedarea = new Rectangle ();
@@ -1152,56 +1282,80 @@ namespace System.Windows.Forms
                        rect_cell.Y = row_rect.Y;
                        rect_cell.Height = row_rect.Height;
 
+                       if (grid.IsSelected (row)) {
+                               backcolor =  grid.SelectionBackColor;
+                               forecolor =  grid.SelectionForeColor;
+                       } else {
+                               if (row % 2 == 0) {
+                                       backcolor =  grid.BackColor;
+                               } else {
+                                       backcolor =  grid.AlternatingBackColor;
+                               }
+
+                               forecolor =  grid.ForeColor;
+                       }                       
+
+
+                       backBrush = ResPool.GetSolidBrush (backcolor);
+                       foreBrush = ResPool.GetSolidBrush (forecolor);
+
                        // PaintCells at row, column
-                       int column_cnt = grid.first_visiblecolumn + grid.visiblecolumn_count;
-                       for (int column = grid.first_visiblecolumn; column < column_cnt; column++) {
+                       int column_cnt = grid.FirstVisibleColumn + grid.VisibleColumnCount;
+                       for (int column = grid.FirstVisibleColumn; column < column_cnt; column++) {
 
-                               col_pixel = grid.grid_drawing.GetColumnStartingPixel (column);
+                               col_pixel = grid.GetColumnStartingPixel (column);
 
-                               rect_cell.X = row_rect.X + col_pixel - grid.horz_pixeloffset;
+                               rect_cell.X = row_rect.X + col_pixel - grid.HorizPixelOffset;
                                rect_cell.Width = grid.CurrentTableStyle.GridColumnStyles[column].Width;
 
-                               current_clip = new Region (row_rect);
-                               g.Clip = current_clip;
+                               if (clip.IntersectsWith (rect_cell)) {
+                                       current_clip = new Region (rect_cell);
+                                       current_clip.Intersect (row_rect);
+                                       current_clip.Intersect (clip);
+                                       g.Clip = current_clip;
 
-                               if (grid.IsSelected (row)) {
-                                       backcolor =  grid.SelectionBackColor;
-                                       forecolor =  grid.SelectionForeColor;
-                               } else {
-                                       if (row % 2 == 0) {
-                                               backcolor =  grid.BackColor;
+                                       if (is_newrow) {
+                                               grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, 
+                                                                                                            backBrush,
+                                                                                                            foreBrush);
                                        } else {
-                                               backcolor =  grid.AlternatingBackColor;
+                                               grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
+                                                                                                      backBrush,
+                                                                                                      foreBrush,
+                                                                                                      grid.RightToLeft == RightToLeft.Yes);
                                        }
-                                       
-                                       forecolor =  grid.ForeColor;
-                               }                       
 
-                               if (is_newrow) {
-                                       grid.CurrentTableStyle.GridColumnStyles[column].PaintNewRow (g, rect_cell, 
-                                               ThemeEngine.Current.ResPool.GetSolidBrush (backcolor),
-                                               ThemeEngine.Current.ResPool.GetSolidBrush (forecolor));                                         
-                                       
-                               } else {
-                                       grid.CurrentTableStyle.GridColumnStyles[column].Paint (g, rect_cell, grid.ListManager, row,
-                                               ThemeEngine.Current.ResPool.GetSolidBrush (backcolor),
-                                               ThemeEngine.Current.ResPool.GetSolidBrush (forecolor),
-                                               grid.RightToLeft == RightToLeft.Yes);
+                                       current_clip.Dispose ();
                                }
-
-                               g.Clip = prev_clip;
-                               current_clip.Dispose ();
                        }
+
+                       g.Clip = prev_clip;
                        
                        if (row_rect.X + row_rect.Width > rect_cell.X + rect_cell.Width) {
-
                                not_usedarea.X = rect_cell.X + rect_cell.Width;
                                not_usedarea.Width = row_rect.X + row_rect.Width - rect_cell.X - rect_cell.Width;
                                not_usedarea.Y = row_rect.Y;
                                not_usedarea.Height = row_rect.Height;
-                               g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (grid.BackgroundColor),
-                                       not_usedarea);
+                               if (clip.IntersectsWith (not_usedarea))
+                                       g.FillRectangle (ResPool.GetSolidBrush (grid.BackgroundColor),
+                                                        not_usedarea);
+                       }
+               }
+
+               public override void DataGridPaintRow (Graphics g, int row, Rectangle row_rect, bool is_newrow,
+                                                      Rectangle clip, DataGrid grid)
+               {                       
+                       /* paint the header if it's visible and intersects the clip */
+                       if (grid.CurrentTableStyle.CurrentRowHeadersVisible) {
+                               Rectangle rect_header = row_rect;
+                               rect_header.Width = grid.RowHeaderWidth;
+                               row_rect.X += grid.RowHeaderWidth;
+                               if (clip.IntersectsWith (rect_header)) {
+                                       DataGridPaintRowHeader (g, rect_header, row, grid);
+                               }
                        }
+
+                       DataGridPaintRowContents (g, row, row_rect, is_newrow, clip, grid);
                }
                
                #endregion // Datagrid
@@ -1213,7 +1367,7 @@ namespace System.Windows.Forms
                        if (!dtp.ShowUpDown && clip_rectangle.IntersectsWith (dtp.ClientRectangle)) {
                                // draw the outer border
                                Rectangle button_bounds = dtp.ClientRectangle;
-                               this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.All, dtp.BackColor);
+                               this.CPDrawBorder3D (dc, button_bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, dtp.BackColor);
                                
                                // deflate by the border width
                                if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
@@ -1229,11 +1383,11 @@ namespace System.Windows.Forms
                        // render the date part
                        if (clip_rectangle.IntersectsWith (dtp.date_area_rect)) {
                                // fill the background
-                               dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorWindow), dtp.date_area_rect);
+                               dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);
                                
                                // fill the currently highlighted area
                                if (dtp.hilight_date_area != Rectangle.Empty) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorHighlight), dtp.hilight_date_area);
+                                       dc.FillRectangle (SystemBrushes.Highlight, dtp.hilight_date_area);
                                }
                                
                                // draw the text part
@@ -1254,27 +1408,14 @@ namespace System.Windows.Forms
                        SizeF           size;
                        int             width;
                        int             y;
-                       Rectangle       rect;
 
-                       rect = box.ClientRectangle;
-
-                       // Needed once the Dark/Light code below is enabled again
-                       //Color disabled = ColorGrayText;
-                       
-                       Pen pen_light = ResPool.GetPen (Color.FromArgb (255,255,255,255));
-                       Pen pen_dark = ResPool.GetPen (Color.FromArgb (255, 128, 128,128));
+                       dc.FillRectangle (GetControlBackBrush (box.BackColor), box.ClientRectangle);
                        
-                       // TODO: When the Light and Dark methods work this code should be activate it
-                       //Pen pen_light = new Pen (ControlPaint.Light (disabled, 1));
-                       //Pen pen_dark = new Pen (ControlPaint.Dark (disabled, 0));
-
-                       dc.FillRectangle (ResPool.GetSolidBrush (box.BackColor), rect);
-
                        text_format = new StringFormat();
                        text_format.HotkeyPrefix = HotkeyPrefix.Show;
 
                        size = dc.MeasureString (box.Text, box.Font);
-                       width = (int) size.Width;
+                       width = ((int) size.Width) + 7;
                        
                        if (width > box.Width - 16)
                                width = box.Width - 16;
@@ -1282,28 +1423,22 @@ namespace System.Windows.Forms
                        y = box.Font.Height / 2;
                        
                        /* Draw group box*/
-                       dc.DrawLine (pen_dark, 0, y, 8, y); // top 
-                       dc.DrawLine (pen_light, 0, y + 1, 8, y + 1);                    
-                       dc.DrawLine (pen_dark, 8 + width, y, box.Width, y);                     
-                       dc.DrawLine (pen_light, 8 + width, y + 1, box.Width, y + 1);
-                       
-                       dc.DrawLine (pen_dark, 0, y + 1, 0, box.Height); // left
-                       dc.DrawLine (pen_light, 1, y + 1, 1, box.Height);                       
-                       
-                       dc.DrawLine (pen_dark, 0, box.Height - 2, box.Width,  box.Height - 2); // bottom
-                       dc.DrawLine (pen_light, 0, box.Height - 1, box.Width,  box.Height - 1);
-                       
-                       dc.DrawLine (pen_dark, box.Width - 2, y,  box.Width - 2, box.Height - 2); // right
-                       dc.DrawLine (pen_light, box.Width - 1, y, box.Width - 1, box.Height - 2);
-                       
+                       CPDrawBorder3D (dc, new Rectangle (0, y, box.Width, box.Height - y), Border3DStyle.Etched, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, box.BackColor);
                        
                        /* Text */
-                       if (box.Enabled) {
-                               dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
-                       } else {
-                               CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor, 
-                                       new RectangleF (10, 0, width,  box.Font.Height), text_format);
+                       if (box.Text.Length != 0) {
+                               Pen pen = ResPool.GetPen (box.BackColor);
+                               dc.DrawLine (pen, 9, y, 8 + width, y);
+                               dc.DrawLine (pen, 9, y + 1, 8 + width, y + 1);
+                               
+                               if (box.Enabled) {
+                                       dc.DrawString (box.Text, box.Font, ResPool.GetSolidBrush (box.ForeColor), 10, 0, text_format);
+                               } else {
+                                       CPDrawStringDisabled (dc, box.Text, box.Font, box.BackColor, 
+                                                             new RectangleF (10, 0, width,  box.Font.Height), text_format);
+                               }
                        }
+                       
                        text_format.Dispose (); 
                }
 
@@ -1326,12 +1461,12 @@ namespace System.Windows.Forms
                #region Label
                public  override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) 
                {               
-                       dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
+                       dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
 
                        if (label.Enabled) {
                                dc.DrawString (label.Text, label.Font, ResPool.GetSolidBrush (label.ForeColor), clip_rectangle, label.string_format);
                        } else {
-                               ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.ForeColor, clip_rectangle, label.string_format);
+                               ControlPaint.DrawStringDisabled (dc, label.Text, label.Font, label.BackColor, clip_rectangle, label.string_format);
                        }
                
                }
@@ -1346,108 +1481,69 @@ namespace System.Windows.Forms
                #region LinkLabel
                public  override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)
                {
-                       Color color;
+                       dc.FillRectangle (GetControlBackBrush (label.BackColor), clip_rectangle);
+
+                       if (label.pieces == null)
+                               return;
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
+                       for (int i = 0; i < label.pieces.Length; i ++) {
+                               RectangleF clipf = new RectangleF (clip_rectangle.X, clip_rectangle.Y,
+                                                                  clip_rectangle.Width, clip_rectangle.Height);
+                               RectangleF rectf = label.pieces[i].region.GetBounds (dc);
 
-                       for (int i = 0; i < label.num_pieces; i++) {
-                               
-                               if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
+                               if (!clipf.IntersectsWith (rectf))
                                        continue;
-                               }                               
-                               
-                               color = label.GetLinkColor (label.pieces[i], i);
 
-                               if (label.pieces[i].link == null)
-                                       dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),
-                                               label.pieces[i].rect.X, label.pieces[i].rect.Y);
-                               else
-                                       dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),
-                                               label.pieces[i].rect.X, label.pieces[i].rect.Y);
-                                               
-                               if (label.pieces[i].focused) {                                  
-                                       CPDrawFocusRectangle (dc, label.pieces[i].rect, label.ForeColor, label.BackColor);
+                               dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (label.GetPieceColor (label.pieces[i], i)),
+                                              rectf, label.string_format);
+
+                               LinkLabel.Link link = label.pieces[i].link;
+                               if (link != null && link.Focused) {
+                                       Rectangle rect = new Rectangle ((int)rectf.X, (int)rectf.Y,
+                                                                       (int)rectf.Width, (int)rectf.Height);
+                                       CPDrawFocusRectangle (dc, rect, label.ForeColor, label.BackColor);
                                }
-                       }                       
-                       
+                       }
                }
                #endregion      // LinkLabel
                #region ListBox
-               
-               // Drawing              
-               
-               private int DrawListBoxDecorationSize (BorderStyle border_style)
-               {
-                       switch (border_style) {
-                               case BorderStyle.Fixed3D:
-                                       return 2;
-                               case BorderStyle.FixedSingle:                                   
-                                       return 1;
-                               case BorderStyle.None:
-                               default:
-                                       break;
-                               }
-                               
-                       return 0;
-               }                       
-               
-               // Sizing                               
+
                public override void DrawListBoxItem (ListBox ctrl, DrawItemEventArgs e)
                {
                        Color back_color, fore_color;
-                       StringFormat string_format = ctrl.GetFormatString ();
                        
                        if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
-                               back_color = ThemeEngine.Current.ColorHighlight;
-                               fore_color = ThemeEngine.Current.ColorHighlightText;
-                       }
-                       else {
+                               back_color = ColorHighlight;
+                               fore_color = ColorHighlightText;
+                       } else {
                                back_color = e.BackColor;
                                fore_color = e.ForeColor;
                        }
-                       
-                       e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
-                               (back_color), e.Bounds);
+
+                       e.Graphics.FillRectangle (ResPool.GetSolidBrush (back_color), e.Bounds);
 
                        e.Graphics.DrawString (ctrl.GetItemText (ctrl.Items[e.Index]), e.Font,
-                               ThemeEngine.Current.ResPool.GetSolidBrush (fore_color),
-                               e.Bounds.X, e.Bounds.Y, string_format);
+                                              ResPool.GetSolidBrush (fore_color),
+                                              e.Bounds.X, e.Bounds.Y, ctrl.StringFormat);
                                        
-                       if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
-                               ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds,
-                                       fore_color, back_color);
-                       }
+                       if ((e.State & DrawItemState.Focus) == DrawItemState.Focus)
+                               CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
                }
                
                #endregion ListBox
 
                #region ListView
                // Drawing
-               public override void DrawListView (Graphics dc, Rectangle clip, ListView control)
+               public override void DrawListViewItems (Graphics dc, Rectangle clip, ListView control)
                {
-                       bool details = (control.View == View.Details);
-                       Rectangle client_area_nohdrs;                   
-                       DrawListViewHeader (dc, clip, control);
-                       
-                       if (details && control.Columns.Count > 0) {
-                               client_area_nohdrs = control.client_area;
-                               client_area_nohdrs.Y += control.Columns[0].Ht;
-                               client_area_nohdrs.Height -= control.Columns[0].Ht;
-                               dc.SetClip (client_area_nohdrs);                                
-                       } else
-                               dc.SetClip (control.client_area);
-                       
-                       dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);                                             
-                                               
-                       // In case of details view draw the items only if
-                       // columns are non-zero                 
-                       if (!details || control.Columns.Count > 0) {
-                               int first = control.FirstVisibleIndex;  
-                               
-                               for (int i = first; i <= control.LastItemIndex; i ++) {                                 
-                                       if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
-                                               DrawListViewItem (dc, control, control.Items[i]);
-                               }                               
+                       bool details = control.View == View.Details;
+
+                       dc.FillRectangle (GetControlBackBrush (control.BackColor), clip);                                               
+                       int first = control.FirstVisibleIndex;  
+
+                       for (int i = first; i <= control.LastVisibleIndex; i ++) {                                      
+                               if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
+                                       DrawListViewItem (dc, control, control.Items [i]);
                        }       
                        
                        // draw the gridlines
@@ -1457,13 +1553,13 @@ namespace System.Windows.Forms
 
                                // draw vertical gridlines
                                foreach (ColumnHeader col in control.Columns)
-                                       dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
+                                       dc.DrawLine (SystemPens.Control,
                                                     col.Rect.Right, top,
                                                     col.Rect.Right, control.TotalHeight);
                                // draw horizontal gridlines
                                ListViewItem last_item = null;
                                foreach (ListViewItem item in control.Items) {
-                                       dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
+                                       dc.DrawLine (SystemPens.Control,
                                                     item.GetBounds (ItemBoundsPortion.Entire).Left, item.GetBounds (ItemBoundsPortion.Entire).Top,
                                                     control.TotalWidth, item.GetBounds (ItemBoundsPortion.Entire).Top);
                                        last_item = item;
@@ -1471,7 +1567,7 @@ namespace System.Windows.Forms
 
                                // draw a line after at the bottom of the last item
                                if (last_item != null) {
-                                       dc.DrawLine (this.ResPool.GetPen (this.ColorControl),
+                                       dc.DrawLine (SystemPens.Control,
                                                     last_item.GetBounds (ItemBoundsPortion.Entire).Left,
                                                     last_item.GetBounds (ItemBoundsPortion.Entire).Bottom,
                                                     control.TotalWidth,
@@ -1479,8 +1575,6 @@ namespace System.Windows.Forms
                                }
                        }                       
                        
-                       dc.ResetClip ();
-                       
                        // Draw corner between the two scrollbars
                        if (control.h_scroll.Visible == true && control.h_scroll.Visible == true) {
                                Rectangle rect = new Rectangle ();
@@ -1488,62 +1582,89 @@ namespace System.Windows.Forms
                                rect.Width = control.v_scroll.Width;
                                rect.Y = control.v_scroll.Location.Y + control.v_scroll.Height;
                                rect.Height = control.h_scroll.Height;
-                               dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), rect);
+                               dc.FillRectangle (SystemBrushes.Control, rect);
                        }
 
+                       Rectangle box_select_rect = control.item_control.BoxSelectRectangle;
+                       if (!box_select_rect.Size.IsEmpty)
+                               dc.DrawRectangle (ResPool.GetDashPen (ColorControlText, DashStyle.Dot), box_select_rect);
+
                }
                
-               private void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
+               public override void DrawListViewHeader (Graphics dc, Rectangle clip, ListView control)
                {       
                        bool details = (control.View == View.Details);
                                
                        // border is drawn directly in the Paint method
                        if (details && control.HeaderStyle != ColumnHeaderStyle.None) {                         
-                               dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor),
+                               dc.FillRectangle (GetControlBackBrush (control.BackColor),
                                                  0, 0, control.TotalWidth, control.Font.Height + 5);
                                if (control.Columns.Count > 0) {
-                                       if (control.HeaderStyle == ColumnHeaderStyle.Clickable) {
-                                               foreach (ColumnHeader col in control.Columns) {
-                                                       Rectangle rect = col.Rect;
-                                                       rect.X -= control.h_marker;
-                                                       this.CPDrawButton (dc, rect,
-                                                                          (col.Pressed ?
-                                                                           ButtonState.Pushed :
-                                                                           ButtonState.Normal));
-                                                       dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
-                                                                      ResPool.GetSolidBrush
-                                                                      (this.ColorControlText),
-                                                                       rect.X + 3,
-                                                                       rect.Y + rect.Height/2 + 1,
-                                                                       col.Format);
-                                               }
+                                       foreach (ColumnHeader col in control.Columns) {
+                                               Rectangle rect = col.Rect;
+                                               rect.X -= control.h_marker;
+                                               ButtonState state;
+                                               if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
+                                                       state = col.Pressed ? ButtonState.Pushed : ButtonState.Normal;
+                                               else
+                                                       state = ButtonState.Flat;
+                                               this.CPDrawButton (dc, rect, state);
+                                               rect.X += 3;
+                                               rect.Width -= 8;
+                                               if (rect.Width <= 0)
+                                                       continue;
+                                               dc.DrawString (col.Text, DefaultFont,
+                                                              SystemBrushes.ControlText,
+                                                              rect, col.Format);
                                        }
-                                       // Non-clickable columns
-                                       else {
-                                               foreach (ColumnHeader col in control.Columns) {
-                                                       Rectangle rect = col.Rect;
-                                                       rect.X -= control.h_marker;
-                                                       this.CPDrawButton (dc, rect, ButtonState.Flat);
-                                                       dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
-                                                                      ResPool.GetSolidBrush
-                                                                      (this.ColorControlText),
-                                                                       rect.X + 3,
-                                                                       rect.Y + rect.Height/2 + 1,
-                                                                       col.Format);
-                                               }
+                                       int right = control.Columns [control.Columns.Count - 1].Rect.Right - control.h_marker;
+                                       if (right < control.Right) {
+                                               Rectangle rect = control.Columns [0].Rect;
+                                               rect.X = right;
+                                               rect.Width = control.Right - right;
+                                               ButtonState state;
+                                               if (control.HeaderStyle == ColumnHeaderStyle.Clickable)
+                                                       state = ButtonState.Normal;
+                                               else
+                                                       state = ButtonState.Flat;
+                                               CPDrawButton (dc, rect, state);
                                        }
                                }
                        }
                }
 
-               // draws the ListViewItem of the given index
-               private void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
+               public override void DrawListViewHeaderDragDetails (Graphics dc, ListView view, ColumnHeader col, int target_x)
+               {
+                       Rectangle rect = col.Rect;
+                       rect.X -= view.h_marker;
+                       Color color = Color.FromArgb (0x7f, ColorControlDark.R, ColorControlDark.G, ColorControlDark.B);
+                       dc.FillRectangle (ResPool.GetSolidBrush (color), rect);
+                       rect.X += 3;
+                       rect.Width -= 8;
+                       if (rect.Width <= 0)
+                               return;
+                       color = Color.FromArgb (0x7f, ColorControlText.R, ColorControlText.G, ColorControlText.B);
+                       dc.DrawString (col.Text, DefaultFont, ResPool.GetSolidBrush (color), rect, col.Format);
+                       dc.DrawLine (ResPool.GetSizedPen (ColorHighlight, 2), target_x, 0, target_x, col.Rect.Height);
+               }
+
+               protected virtual void DrawListViewItem (Graphics dc, ListView control, ListViewItem item)
                {                               
+                       int col_offset;
+                       if (control.View == View.Details && control.Columns.Count > 0)
+                               col_offset = control.Columns [0].Rect.X;
+                       else
+                               col_offset = 0;
+                       
                        Rectangle rect_checkrect = item.CheckRectReal;
-                       Rectangle rect_iconrect = item.GetBounds (ItemBoundsPortion.Icon);
+                       rect_checkrect.X += col_offset;
+                       Rectangle icon_rect = item.GetBounds (ItemBoundsPortion.Icon);
+                       icon_rect.X += col_offset;
                        Rectangle full_rect = item.GetBounds (ItemBoundsPortion.Entire);
+                       full_rect.X += col_offset;
                        Rectangle text_rect = item.GetBounds (ItemBoundsPortion.Label);                 
-                       
+                       text_rect.X += col_offset;
+
                        if (control.CheckBoxes) {
                                if (control.StateImageList == null) {
                                        // Make sure we've got at least a line width of 1
@@ -1551,28 +1672,28 @@ namespace System.Windows.Forms
                                        int scale = Math.Max (1, rect_checkrect.Width / 12);
 
                                        // set the checkbox background
-                                       dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
+                                       dc.FillRectangle (SystemBrushes.Window,
                                                          rect_checkrect);
                                        // define a rectangle inside the border area
                                        Rectangle rect = new Rectangle (rect_checkrect.X + 2,
                                                                        rect_checkrect.Y + 2,
                                                                        rect_checkrect.Width - 4,
                                                                        rect_checkrect.Height - 4);
-                                       Pen pen = new Pen (this.ColorWindowText, 2);
+                                       Pen pen = ResPool.GetSizedPen (this.ColorWindowText, 2);
                                        dc.DrawRectangle (pen, rect);
 
                                        // Need to draw a check-mark
                                        if (item.Checked) {
-                                               pen.Width = 1;
+                                               Pen check_pen = ResPool.GetSizedPen (this.ColorWindowText, 1);
                                                // adjustments to get the check-mark at the right place
                                                rect.X ++; rect.Y ++;
                                                // following logic is taken from DrawFrameControl method
                                                for (int i = 0; i < check_wd; i++) {
-                                                       dc.DrawLine (pen, rect.Left + check_wd / 2,
+                                                       dc.DrawLine (check_pen, rect.Left + check_wd / 2,
                                                                     rect.Top + check_wd + i,
                                                                     rect.Left + check_wd / 2 + 2 * scale,
                                                                     rect.Top + check_wd + 2 * scale + i);
-                                                       dc.DrawLine (pen,
+                                                       dc.DrawLine (check_pen,
                                                                     rect.Left + check_wd / 2 + 2 * scale,
                                                                     rect.Top + check_wd + 2 * scale + i,
                                                                     rect.Left + check_wd / 2 + 6 * scale,
@@ -1590,26 +1711,23 @@ namespace System.Windows.Forms
                                }
                        }
 
-                       // Item is drawn as a special case, as it is not just text
                        if (control.View == View.LargeIcon) {
-                               if (item.ImageIndex > -1 &&
-                                   control.LargeImageList != null &&
+                               if (item.ImageIndex > -1 && control.LargeImageList != null &&
                                    item.ImageIndex < control.LargeImageList.Images.Count)
-                                       control.LargeImageList.Draw (dc, rect_iconrect.Location,
-                                                                    item.ImageIndex);
-                       }
-                       else {
-                               if (item.ImageIndex > -1 &&
-                                   control.SmallImageList != null &&
+                                       control.LargeImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
+                       } else {
+                               if (item.ImageIndex > -1 && control.SmallImageList != null &&
                                    item.ImageIndex < control.SmallImageList.Images.Count)
-                                       control.SmallImageList.Draw (dc, rect_iconrect.Location,
-                                                                    item.ImageIndex);
+                                       control.SmallImageList.Draw (dc, icon_rect.Location, item.ImageIndex);
                        }
 
                        // draw the item text                   
                        // format for the item text
                        StringFormat format = new StringFormat ();
-                       format.LineAlignment = StringAlignment.Center;
+                       if (control.View == View.SmallIcon)
+                               format.LineAlignment = StringAlignment.Near;
+                       else
+                               format.LineAlignment = StringAlignment.Center;
                        if (control.View == View.LargeIcon)
                                format.Alignment = StringAlignment.Center;
                        else
@@ -1618,42 +1736,27 @@ namespace System.Windows.Forms
                        if (!control.LabelWrap)
                                format.FormatFlags = StringFormatFlags.NoWrap;
                        
-                       if (item.Selected) {
-                               if (control.View == View.Details) {
-                                       if (control.FullRowSelect) {
-                                               // fill the entire rect excluding the checkbox                                          
-                                               full_rect.Location = item.LabelRect.Location;
-                                               dc.FillRectangle (this.ResPool.GetSolidBrush
-                                                                 (this.ColorHighlight), full_rect);
-                                       }
-                                       else {
-                                               Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
-                                                                                               item.Font));
-                                               text_rect.Width = text_size.Width;
-                                               dc.FillRectangle (this.ResPool.GetSolidBrush
-                                                                 (this.ColorHighlight), text_rect);
-                                       }
-                               }
-                               else {
-                                       /*Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
-                                         item.Font));
-                                         Point loc = text_rect.Location;
-                                         loc.X += (text_rect.Width - text_size.Width) / 2;
-                                         text_rect.Width = text_size.Width;*/
-                                       dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorHighlight),
-                                                         text_rect);
-                               }
+                       Rectangle highlight_rect = text_rect;
+                       if (control.View == View.Details && !control.FullRowSelect) {
+                               Size text_size = Size.Ceiling (dc.MeasureString (item.Text, item.Font));
+                               highlight_rect.Width = text_size.Width + 4;
                        }
+
+                       if (item.Selected && control.Focused)
+                               dc.FillRectangle (SystemBrushes.Highlight, highlight_rect);
                        else
                                dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
+                       
+                       Brush textBrush =
+                               !control.Enabled ? SystemBrushes.ControlLight :
+                               (item.Selected && control.Focused) ? SystemBrushes.HighlightText :
+                               this.ResPool.GetSolidBrush (item.ForeColor);
 
                        if (item.Text != null && item.Text.Length > 0) {
-                               if (item.Selected)
-                                       dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
-                                                      (this.ColorHighlightText), text_rect, format);
+                               if (item.Selected && control.Focused)
+                                       dc.DrawString (item.Text, item.Font, textBrush, highlight_rect, format);
                                else
-                                       dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
-                                                      (item.ForeColor), text_rect, format);
+                                       dc.DrawString (item.Text, item.Font, textBrush, text_rect, format);
                        }
 
                        if (control.View == View.Details && control.Columns.Count > 0) {
@@ -1669,61 +1772,61 @@ namespace System.Windows.Forms
 
                                        // set the format for subitems
                                        format.FormatFlags = StringFormatFlags.NoWrap;
-                                       format.Alignment = StringAlignment.Near;
 
                                        // 0th subitem is the item already drawn
                                        for (int index = 1; index < count; index++) {
                                                subItem = subItems [index];
                                                col = control.Columns [index];
-                                               sub_item_rect.X = col.Rect.Left;
+                                               format.Alignment = col.Format.Alignment;
+                                               sub_item_rect.X = col.Rect.X - control.h_marker;
                                                sub_item_rect.Width = col.Wd;
-                                               sub_item_rect.X -= control.h_marker;
+                                               Rectangle sub_item_text_rect = sub_item_rect;
+                                               sub_item_text_rect.X += 3;
+                                               sub_item_text_rect.Width -= 6;
 
                                                SolidBrush sub_item_back_br = null;
                                                SolidBrush sub_item_fore_br = null;
                                                Font sub_item_font = null;
 
                                                if (item.UseItemStyleForSubItems) {
-                                                       sub_item_back_br = this.ResPool.GetSolidBrush
-                                                               (item.BackColor);
-                                                       sub_item_fore_br = this.ResPool.GetSolidBrush
-                                                               (item.ForeColor);
+                                                       sub_item_back_br = ResPool.GetSolidBrush (item.BackColor);
+                                                       sub_item_fore_br = ResPool.GetSolidBrush (item.ForeColor);
                                                        sub_item_font = item.Font;
-                                               }
-                                               else {
-                                                       sub_item_back_br = this.ResPool.GetSolidBrush
-                                                               (subItem.BackColor);
-                                                       sub_item_fore_br = this.ResPool.GetSolidBrush
-                                                               (subItem.ForeColor);
+                                               } else {
+                                                       sub_item_back_br = ResPool.GetSolidBrush (subItem.BackColor);
+                                                       sub_item_fore_br = ResPool.GetSolidBrush (subItem.ForeColor);
                                                        sub_item_font = subItem.Font;
                                                }
 
-                                               // In case of fullrowselect, background is filled
-                                               // for the entire rect above
                                                if (item.Selected && control.FullRowSelect) {
+                                                       dc.FillRectangle (SystemBrushes.Highlight, sub_item_rect);
                                                        if (subItem.Text != null && subItem.Text.Length > 0)
                                                                dc.DrawString (subItem.Text, sub_item_font,
-                                                                              this.ResPool.GetSolidBrush
-                                                                              (this.ColorHighlightText),
-                                                                              sub_item_rect, format);
-                                               }
-                                               else {
+                                                                              SystemBrushes.HighlightText,
+                                                                              sub_item_text_rect, format);
+                                               } else {
                                                        dc.FillRectangle (sub_item_back_br, sub_item_rect);
                                                        if (subItem.Text != null && subItem.Text.Length > 0)
                                                                dc.DrawString (subItem.Text, sub_item_font,
                                                                               sub_item_fore_br,
-                                                                              sub_item_rect, format);
+                                                                              sub_item_text_rect, format);
                                                }
-                                               sub_item_rect.X += col.Wd;
                                        }
                                }
                        }
                        
-                       if (item.Focused) {                             
+                       if (item.Focused && control.Focused) {                          
+                               Rectangle focus_rect = highlight_rect;
+                               if (control.FullRowSelect && control.View == View.Details) {
+                                       int width = 0;
+                                       foreach (ColumnHeader col in control.Columns)
+                                               width += col.Width;
+                                       focus_rect = new Rectangle (0, full_rect.Y, width, full_rect.Height);
+                               }
                                if (item.Selected)
-                                       CPDrawFocusRectangle (dc, text_rect, ColorHighlightText, ColorHighlight);
+                                       CPDrawFocusRectangle (dc, focus_rect, ColorHighlightText, ColorHighlight);
                                else
-                                       CPDrawFocusRectangle (dc, text_rect, control.ForeColor, control.BackColor);
+                                       CPDrawFocusRectangle (dc, focus_rect, control.ForeColor, control.BackColor);
                        }
 
                        format.Dispose ();
@@ -1760,118 +1863,109 @@ namespace System.Windows.Forms
                #endregion      // ListView
                
                #region Menus
-               public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
+               public override void CalcItemSize (Graphics dc, MenuItem item, int y, int x, bool menuBar)
                {
-                       item.rect.Y = y;
-                       item.rect.X = x;
+                       item.X = x;
+                       item.Y = y;
 
-                       if (item.item.Visible == false)
+                       if (item.Visible == false) {
+                               item.Width = 0;
+                               item.Height = 0;
                                return;
+                       }
 
-                       if (item.item.Separator == true) {
-                               item.rect.Height = SEPARATOR_HEIGHT / 2;
-                               item.rect.Width = -1;
+                       if (item.Separator == true) {
+                               item.Height = SEPARATOR_HEIGHT / 2;
+                               item.Width = -1;
                                return;
                        }
                        
-                       if (item.item.MeasureEventDefined) {
-                               MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.pos);
-                               item.item.PerformMeasureItem (mi);
-                               item.rect.Height = mi.ItemHeight;
-                               item.rect.Width = mi.ItemWidth;
+                       if (item.MeasureEventDefined) {
+                               MeasureItemEventArgs mi = new MeasureItemEventArgs (dc, item.Index);
+                               item.PerformMeasureItem (mi);
+                               item.Height = mi.ItemHeight;
+                               item.Width = mi.ItemWidth;
                                return;
                        } else {                
-
                                SizeF size;
-                               size =  dc.MeasureString (item.item.Text, ThemeEngine.Current.MenuFont);
-                               item.rect.Width = (int) size.Width;
-                               item.rect.Height = (int) size.Height;
+                               size =  dc.MeasureString (item.Text, MenuFont);
+                               item.Width = (int) size.Width;
+                               item.Height = (int) size.Height;
        
                                if (!menuBar) {
-       
-                                       if (item.item.Shortcut != Shortcut.None && item.item.ShowShortcut) {
-                                               item.item.XTab = ThemeEngine.Current.MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
-                                               size =  dc.MeasureString (" " + item.item.GetShortCutText (), ThemeEngine.Current.MenuFont);
-                                               item.rect.Width += MENU_TAB_SPACE + (int) size.Width;
+                                       if (item.Shortcut != Shortcut.None && item.ShowShortcut) {
+                                               item.XTab = MenuCheckSize.Width + MENU_TAB_SPACE + (int) size.Width;
+                                               size =  dc.MeasureString (" " + item.GetShortCutText (), MenuFont);
+                                               item.Width += MENU_TAB_SPACE + (int) size.Width;
                                        }
        
-                                       item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
-                               }
-                               else {
-                                       item.rect.Width += MENU_BAR_ITEMS_SPACE;
-                                       x += item.rect.Width;
+                                       item.Width += 4 + (MenuCheckSize.Width * 2);
+                               } else {
+                                       item.Width += MENU_BAR_ITEMS_SPACE;
+                                       x += item.Width;
                                }
        
-                               if (item.rect.Height < ThemeEngine.Current.MenuHeight)
-                                       item.rect.Height = ThemeEngine.Current.MenuHeight;
-                               }
+                               if (item.Height < MenuHeight)
+                                       item.Height = MenuHeight;
+                       }
                }
                
                // Updates the menu rect and returns the height
-               public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, int width)
+               public override int CalcMenuBarSize (Graphics dc, Menu menu, int width)
                {
                        int x = 0;
-                       int i = 0;
                        int y = 0;
-                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
                        menu.Height = 0;
-                       MenuAPI.MENUITEM item;
 
-                       while (i < menu.items.Count) {
+                       foreach (MenuItem item in menu.MenuItems) {
 
-                               item = (MenuAPI.MENUITEM) menu.items[i];
                                CalcItemSize (dc, item, y, x, true);
-                               i = i + 1;
 
-                               if (x + item.rect.Width > width) {
-                                       item.rect.X = 0;
-                                       y += item.rect.Height;
-                                       item.rect.Y = y;
+                               if (x + item.Width > width) {
+                                       item.X = 0;
+                                       y += item.Height;
+                                       item.Y = y;
                                        x = 0;
                                }
 
-                               x += item.rect.Width;
-                               item.item.MenuBar = true;                               
+                               x += item.Width;
+                               item.MenuBar = true;                            
 
-                               if (y + item.rect.Height > menu.Height)
-                                       menu.Height = item.rect.Height + y;
+                               if (y + item.Height > menu.Height)
+                                       menu.Height = item.Height + y;
                        }
 
                        menu.Width = width;                                             
                        return menu.Height;
                }
 
-               
-               public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
+               public override void CalcPopupMenuSize (Graphics dc, Menu menu)
                {
                        int x = 3;
                        int start = 0;
                        int i, n, y, max;
 
-                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
                        menu.Height = 0;
 
-                       while (start < menu.items.Count) {
+                       while (start < menu.MenuItems.Count) {
                                y = 2;
                                max = 0;
-                               for (i = start; i < menu.items.Count; i++) {
-                                       MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
+                               for (i = start; i < menu.MenuItems.Count; i++) {
+                                       MenuItem item = menu.MenuItems [i];
 
-                                       if ((i != start) && (item.item.Break || item.item.BarBreak))
+                                       if ((i != start) && (item.Break || item.BarBreak))
                                                break;
 
                                        CalcItemSize (dc, item, y, x, false);
-                                       y += item.rect.Height;
+                                       y += item.Height;
 
-                                       if (item.rect.Width > max)
-                                               max = item.rect.Width;
+                                       if (item.Width > max)
+                                               max = item.Width;
                                }
 
-                               // Reemplace the -1 by the menu width (separators)
-                               for (n = start; n < i; n++, start++) {
-                                       MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[n];
-                                       item.rect.Width = max;
-                               }
+                               // Replace the -1 by the menu width (separators)
+                               for (n = start; n < i; n++, start++)
+                                       menu.MenuItems [n].Width = max;
 
                                if (y > menu.Height)
                                        menu.Height = y;
@@ -1890,56 +1984,71 @@ namespace System.Windows.Forms
                }
                
                // Draws a menu bar in a window
-               public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
+               public override void DrawMenuBar (Graphics dc, Menu menu, Rectangle rect)
                {
-                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);                      
-                       Rectangle item_rect;
-
                        if (menu.Height == 0)
-                               ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
-                               
+                               CalcMenuBarSize (dc, menu, rect.Width);
+
+                       bool keynav = (menu as MainMenu).tracker.Navigating;
+                       HotkeyPrefix hp = always_draw_hotkeys || keynav ? HotkeyPrefix.Show : HotkeyPrefix.Hide;
+                       string_format_menu_menubar_text.HotkeyPrefix = hp;
+                       string_format_menu_text.HotkeyPrefix = hp;
+
                        rect.Height = menu.Height;
-                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (menu.Wnd.BackColor), rect);
-                                               
-                       for (int i = 0; i < menu.items.Count; i++) {
-                               MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
-                               item_rect = it.rect;
+                       dc.FillRectangle (SystemBrushes.Menu, rect);
+                       
+                       for (int i = 0; i < menu.MenuItems.Count; i++) {
+                               MenuItem item = menu.MenuItems [i];
+                               Rectangle item_rect = item.bounds;
                                item_rect.X += rect.X;
                                item_rect.Y += rect.Y;
-                               it.item.MenuHeight = menu.Height;
-                               it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
-                                               item_rect, i, it.item.Status));                 
-                               
-                       }                               
+                               item.MenuHeight = menu.Height;
+                               item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont, item_rect, i, item.Status)); 
+                       }       
                }               
                
+               protected Bitmap CreateGlyphBitmap (Size size, MenuGlyph glyph, Color color)
+               {
+                       Color bg_color;
+                       if (color.R == 0 && color.G == 0 && color.B == 0)
+                               bg_color = Color.White;
+                       else
+                               bg_color = Color.Black;
+                       Bitmap  bmp = new Bitmap (size.Width, size.Height);
+                       Graphics gr = Graphics.FromImage (bmp);
+                       Rectangle rect = new Rectangle (Point.Empty, size);
+                       gr.FillRectangle (ResPool.GetSolidBrush (bg_color), rect);
+                       CPDrawMenuGlyph (gr, rect, glyph, color);
+                       bmp.MakeTransparent (bg_color);
+                       gr.Dispose ();
+                       return bmp;
+               }
+
                public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
                {
                        StringFormat string_format;
                        Rectangle rect_text = e.Bounds;
-
+                       
                        if (item.Visible == false)
                                return;
 
-                       if (item.MenuBar) {
+                       if (item.MenuBar)
                                string_format = string_format_menu_menubar_text;
-                       }
-                       else {
+                       else
                                string_format = string_format_menu_text;
-                       }               
 
                        if (item.Separator == true) {
-                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
+                               e.Graphics.DrawLine (SystemPens.ControlDark,
                                        e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
 
-                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlLight),
+                               e.Graphics.DrawLine (SystemPens.ControlLight,
                                        e.Bounds.X, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1);
 
                                return;
                        }
 
                        if (!item.MenuBar)
-                               rect_text.X += ThemeEngine.Current.MenuCheckSize.Width;
+                               rect_text.X += MenuCheckSize.Width;
 
                        if (item.BarBreak) { /* Draw vertical break bar*/
                                Rectangle rect = e.Bounds;
@@ -1947,61 +2056,78 @@ namespace System.Windows.Forms
                                rect.Width = 3;
                                rect.Height = item.MenuHeight - 6;
 
-                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
+                               e.Graphics.DrawLine (SystemPens.ControlDark,
                                        rect.X, rect.Y , rect.X, rect.Y + rect.Height);
 
-                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlLight),
+                               e.Graphics.DrawLine (SystemPens.ControlLight,
                                        rect.X + 1, rect.Y , rect.X +1, rect.Y + rect.Height);
                        }                       
                        
                        Color color_text;
                        Color color_back;
-                       
-                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
-                               color_text = ThemeEngine.Current.ColorHighlightText;
-                               color_back = ThemeEngine.Current.ColorHighlight;
-                       }
-                       else {
-                               color_text = ThemeEngine.Current.ColorMenuText;
-                               color_back = ThemeEngine.Current.ColorMenu;
+                       Brush brush_text = null;
+                       Brush brush_back = null;
+                       
+                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected && !item.MenuBar) {
+                               color_text = ColorHighlightText;
+                               color_back = ColorHighlight;
+                               brush_text = SystemBrushes.HighlightText;
+                               brush_back = SystemBrushes.Highlight;
+                       } else {
+                               color_text = ColorMenuText;
+                               color_back = ColorMenu;
+                               brush_text = ResPool.GetSolidBrush (ColorMenuText);
+                               brush_back = SystemBrushes.Menu;
                        }
 
                        /* Draw background */
                        Rectangle rect_back = e.Bounds;
                        rect_back.X++;
                        rect_back.Width -=2;
-                       e.Graphics.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color_back), rect_back);
+                       if (!item.MenuBar)
+                               e.Graphics.FillRectangle (brush_back, rect_back);
                        
                        if (item.Enabled) {
                                e.Graphics.DrawString (item.Text, e.Font,
-                                       ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
+                                       brush_text,
                                        rect_text, string_format);
-
+                               
                                if (!item.MenuBar && item.Shortcut != Shortcut.None && item.ShowShortcut) {
                                        string str = item.GetShortCutText ();
                                        Rectangle rect = rect_text;
                                        rect.X = item.XTab;
                                        rect.Width -= item.XTab;
 
-                                       e.Graphics.DrawString (str, e.Font, ThemeEngine.Current.ResPool.GetSolidBrush (color_text),
+                                       e.Graphics.DrawString (str, e.Font, brush_text,
                                                rect, string_format_menu_shortcut);
                                }
-                       }
-                       else {
-                               ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font, 
-                                       Color.Black, rect_text, string_format);
+                               
+                               if (item.MenuBar) {
+                                       Border3DStyle border_style = Border3DStyle.Adjust;
+                                       if ((item.Status & DrawItemState.HotLight) != 0)
+                                               border_style = Border3DStyle.RaisedInner;
+                                       else if ((item.Status & DrawItemState.Selected) != 0)
+                                               border_style = Border3DStyle.SunkenOuter;
+                                       
+                                       if (border_style != Border3DStyle.Adjust)
+                                               CPDrawBorder3D(e.Graphics, rect_back, border_style,  Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, ColorMenu);
+                               }
+                       } else {
+                               if ((item.Status & DrawItemState.Selected) != DrawItemState.Selected) {
+                                       e.Graphics.DrawString (item.Text, e.Font, Brushes.White, 
+                                                              new RectangleF(rect_text.X + 1, rect_text.Y + 1, rect_text.Width, rect_text.Height),
+                                                              string_format);
+                               }
+                               
+                               e.Graphics.DrawString (item.Text, e.Font, ResPool.GetSolidBrush(ColorGrayText), rect_text, string_format);
                        }
 
                        /* Draw arrow */
-                       if (item.MenuBar == false && item.IsPopup) {
-
-                               int cx = ThemeEngine.Current.MenuCheckSize.Width;
-                               int cy = ThemeEngine.Current.MenuCheckSize.Height;
-                               Bitmap  bmp = new Bitmap (cx, cy);
-                               Graphics gr = Graphics.FromImage (bmp);
-                               Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
-                               ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Arrow);
-                               bmp.MakeTransparent ();
+                       if (item.MenuBar == false && item.IsPopup || item.MdiList) {
+
+                               int cx = MenuCheckSize.Width;
+                               int cy = MenuCheckSize.Height;
+                               Bitmap  bmp = CreateGlyphBitmap (new Size (cx, cy), MenuGlyph.Arrow, color_text);
                                
                                if (item.Enabled) {
                                        e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
@@ -2011,7 +2137,6 @@ namespace System.Windows.Forms
                                                e.Bounds.Y + ((e.Bounds.Height - cy) /2),  color_back);
                                }
  
-                               gr.Dispose ();
                                bmp.Dispose ();
                        }
 
@@ -2019,57 +2144,50 @@ namespace System.Windows.Forms
                        if (item.MenuBar == false && item.Checked) {
 
                                Rectangle area = e.Bounds;
-                               int cx = ThemeEngine.Current.MenuCheckSize.Width;
-                               int cy = ThemeEngine.Current.MenuCheckSize.Height;
-                               Bitmap  bmp = new Bitmap (cx, cy);
-                               Graphics gr = Graphics.FromImage (bmp);
-                               Rectangle rect_arrow = new Rectangle (0, 0, cx, cy);
-
-                               if (item.RadioCheck)
-                                       ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Bullet);
-                               else
-                                       ControlPaint.DrawMenuGlyph (gr, rect_arrow, MenuGlyph.Checkmark);
+                               int cx = MenuCheckSize.Width;
+                               int cy = MenuCheckSize.Height;
+                               Bitmap  bmp = CreateGlyphBitmap (new Size (cx, cy), item.RadioCheck ? MenuGlyph.Bullet : MenuGlyph.Checkmark, color_text);
 
-                               bmp.MakeTransparent ();
                                e.Graphics.DrawImage (bmp, area.X, e.Bounds.Y + ((e.Bounds.Height - cy) / 2));
 
-                               gr.Dispose ();
                                bmp.Dispose ();
                        }                       
                }               
                        
-               public override void DrawPopupMenu (Graphics dc, IntPtr hMenu, Rectangle cliparea, Rectangle rect)
+               public override void DrawPopupMenu (Graphics dc, Menu menu, Rectangle cliparea, Rectangle rect)
                {
-                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
 
-                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
-                               (ThemeEngine.Current.ColorMenu), cliparea);
+                       dc.FillRectangle (SystemBrushes.Menu, cliparea);
+                       
+                       Pen pen_cht = SystemPens.HighlightText;
+                       Pen pen_ccd = SystemPens.ControlDark;
+                       Pen pen_ccdd = SystemPens.ControlDarkDark;
 
                        /* Draw menu borders */
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHighlightText),
+                       dc.DrawLine (pen_cht,
                                rect.X, rect.Y, rect.X + rect.Width, rect.Y);
 
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHighlightText),
+                       dc.DrawLine (pen_cht,
                                rect.X, rect.Y, rect.X, rect.Y + rect.Height);
 
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
+                       dc.DrawLine (pen_ccd,
                                rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
 
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDarkDark),
+                       dc.DrawLine (pen_ccdd,
                                rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
 
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDark),
+                       dc.DrawLine (pen_ccd,
                                rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
 
-                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorControlDarkDark),
+                       dc.DrawLine (pen_ccdd,
                                rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
 
-                       for (int i = 0; i < menu.items.Count; i++)
-                               if (cliparea.IntersectsWith (((MenuAPI.MENUITEM) menu.items[i]).rect)) {
-                                       MenuAPI.MENUITEM it = (MenuAPI.MENUITEM) menu.items[i];
-                                       it.item.MenuHeight = menu.Height;
-                                       it.item.PerformDrawItem (new DrawItemEventArgs (dc, ThemeEngine.Current.MenuFont,
-                                               it.rect, i, it.item.Status));
+                       for (int i = 0; i < menu.MenuItems.Count; i++)
+                               if (cliparea.IntersectsWith (menu.MenuItems [i].bounds)) {
+                                       MenuItem item = menu.MenuItems [i];
+                                       item.MenuHeight = menu.Height;
+                                       item.PerformDrawItem (new DrawItemEventArgs (dc, MenuFont,
+                                               item.bounds, i, item.Status));
                        }
                }
                
@@ -2129,7 +2247,7 @@ namespace System.Windows.Forms
                        // draw the today date if it's set
                        if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle)) 
                        {
-                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
+                               dc.FillRectangle (GetControlBackBrush (mc.BackColor), bottom_rect);
                                if (mc.ShowToday) {
                                        int today_offset = 5;
                                        if (mc.ShowTodayCircle) 
@@ -2152,7 +2270,7 @@ namespace System.Windows.Forms
                                                        Math.Max(client_rectangle.Bottom - date_cell_size.Height, 0),
                                                        Math.Max(client_rectangle.Width - today_offset, 0),
                                                        date_cell_size.Height);
-                                       dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, ResPool.GetSolidBrush (mc.ForeColor), today_rect, text_format);
+                                       dc.DrawString ("Today: " + DateTime.Now.ToShortDateString(), bold_font, GetControlForeBrush (mc.ForeColor), today_rect, text_format);
                                        text_format.Dispose ();
                                        bold_font.Dispose ();
                                }                               
@@ -2161,9 +2279,9 @@ namespace System.Windows.Forms
                        // finally paint the borders of the calendars as required
                        for (int i = 0; i <= mc.CalendarDimensions.Width; i++) {
                                if (i == 0 && clip_rectangle.X == client_rectangle.X) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height));
+                                       dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, 1, client_rectangle.Height);
                                } else if (i == mc.CalendarDimensions.Width && clip_rectangle.Right == client_rectangle.Right) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height));
+                                       dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.Right-1, client_rectangle.Y, 1, client_rectangle.Height);
                                } else { 
                                        Rectangle rect = new Rectangle (
                                                client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
@@ -2171,15 +2289,15 @@ namespace System.Windows.Forms
                                                calendar_spacing.Width,
                                                client_rectangle.Height);
                                        if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
-                                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
+                                               dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
                                        }
                                }
                        }
                        for (int i = 0; i <= mc.CalendarDimensions.Height; i++) {
                                if (i == 0 && clip_rectangle.Y == client_rectangle.Y) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1));
+                                       dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Y, client_rectangle.Width, 1);
                                } else if (i == mc.CalendarDimensions.Height && clip_rectangle.Bottom == client_rectangle.Bottom) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), new Rectangle (client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1));
+                                       dc.FillRectangle (GetControlBackBrush (mc.BackColor), client_rectangle.X, client_rectangle.Bottom-1, client_rectangle.Width, 1);
                                } else { 
                                        Rectangle rect = new Rectangle (
                                                client_rectangle.X,
@@ -2187,7 +2305,7 @@ namespace System.Windows.Forms
                                                client_rectangle.Width,
                                                calendar_spacing.Height);
                                        if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
-                                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
+                                               dc.FillRectangle (GetControlBackBrush (mc.BackColor), rect);
                                        }
                                }
                        }
@@ -2275,7 +2393,7 @@ namespace System.Windows.Forms
                                (7 + col_offset) * date_cell_size.Width,
                                date_cell_size.Height);
                        if (day_name_rect.IntersectsWith (clip_rectangle)) {
-                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), day_name_rect);
+                               dc.FillRectangle (GetControlBackBrush (mc.BackColor), day_name_rect);
                                // draw the day names 
                                DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
                                for (int i=0; i < 7; i++) 
@@ -2328,7 +2446,7 @@ namespace System.Windows.Forms
                
                                bool draw_row = row_rect.IntersectsWith (clip_rectangle);
                                if (draw_row) {
-                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
+                                       dc.FillRectangle (GetControlBackBrush (mc.BackColor), row_rect);
                                }
                                // establish if this is a valid week to draw
                                if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
@@ -2446,7 +2564,7 @@ namespace System.Windows.Forms
                                dc.DrawRectangle (SystemPens.ControlDark, button_rect);
                        }
                        else {
-                               CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
+                               CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                        }
                        // draw the arrow
                        dc.FillPolygon (SystemBrushes.ControlText, arrow_path);                 
@@ -2541,11 +2659,9 @@ namespace System.Windows.Forms
                        }
 
                        // draw the selection grid
-                       if (mc.is_date_clicked && mc.clicked_date == date) {                            
-                               using (Pen pen = new Pen (Color.Black, 1) ) {
-                                       pen.DashStyle = DashStyle.Dot;
-                                       dc.DrawRectangle (pen, interior);
-                               }
+                       if (mc.is_date_clicked && mc.clicked_date == date) {
+                               Pen pen = ResPool.GetDashPen (Color.Black, DashStyle.Dot);
+                               dc.DrawRectangle (pen, interior);
                        }
                        text_format.Dispose ();
                }
@@ -2560,12 +2676,11 @@ namespace System.Windows.Forms
                        curve_points [1] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/9, rhs_circle_rect.Y);
                        curve_points [2] = new Point (lhs_circle_rect.X + lhs_circle_rect.Width/2 + 1, rhs_circle_rect.Y);
 
-                       using (Pen pen = new Pen (circle_color, 2)) {
-                               dc.DrawArc (pen, lhs_circle_rect, 90, 180);
-                               dc.DrawArc (pen, rhs_circle_rect, 270, 180);                                    
-                               dc.DrawCurve (pen, curve_points);
-                               dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
-                       }
+                       Pen pen = ResPool.GetSizedPen(circle_color, 2);
+                       dc.DrawArc (pen, lhs_circle_rect, 90, 180);
+                       dc.DrawArc (pen, rhs_circle_rect, 270, 180);                                    
+                       dc.DrawCurve (pen, curve_points);
+                       dc.DrawLine (ResPool.GetPen (circle_color), curve_points [2], new Point (curve_points [2].X, lhs_circle_rect.Y));
                }
 
                #endregion      // MonthCalendar
@@ -2592,11 +2707,11 @@ namespace System.Windows.Forms
                                        break;
 
                                case PictureBoxSizeMode.CenterImage:
-                                       dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
+                                       dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
                                        dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
                                        break;
                                default:
-                                       dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
+                                       dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
                                        // Normal, AutoSize
                                        dc.DrawImage(pb.Image, 0, 0, pb.Image.Width, pb.Image.Height);
                                        break;
@@ -2606,7 +2721,7 @@ namespace System.Windows.Forms
                        }
 
                        // We only get here if no image is set. At least paint the background
-                       dc.FillRectangle(ResPool.GetSolidBrush(pb.BackColor), clip);
+                       dc.FillRectangle(GetControlBackBrush (pb.BackColor), clip);
                }
 
                public override Size PictureBoxDefaultSize {
@@ -2626,12 +2741,12 @@ namespace System.Windows.Forms
                        int             increment;
                        int             barpos_pixels;
                        
-                       block_width = ((client_area.Height) * 2 ) / 3;
+                       block_width = (client_area.Height * 2 ) / 3;
                        barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
                        increment = block_width + space_betweenblocks;
 
                        /* Draw border */
-                       CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All & ~Border3DSide.Middle, ColorControl);
+                       CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenOuter, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom & ~Border3DSide.Middle, ColorControl);
                        
                        /* Draw Blocks */
                        block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
@@ -2659,7 +2774,7 @@ namespace System.Windows.Forms
                        Rectangle       client_rectangle;
                        Rectangle       text_rectangle;
                        Rectangle       radiobutton_rectangle;
-                       int             radiobutton_size = 12;
+                       int             radiobutton_size = 13;
                        int     radiobutton_space = 4;
 
                        client_rectangle = radio_button.ClientRectangle;
@@ -2811,131 +2926,122 @@ namespace System.Windows.Forms
                        if (radio_button.Checked) {
                                state |= ButtonState.Checked;
                        }
+                       
+                       if (!radio_button.Enabled) {
+                               state |= ButtonState.Inactive;
+                       }
 
                        // Start drawing
                        RadioButton_DrawButton(radio_button, dc, state, radiobutton_rectangle);
                        
+                       if ((radio_button.image != null) || (radio_button.image_list != null))
+                               ButtonBase_DrawImage(radio_button, dc);
+                       
                        RadioButton_DrawText(radio_button, text_rectangle, dc, text_format);
 
-                       RadioButton_DrawFocus(radio_button, dc, text_rectangle);                        
+                       RadioButton_DrawFocus(radio_button, dc, text_rectangle);
+                       
                        text_format.Dispose ();
                }
 
                protected virtual void RadioButton_DrawButton(RadioButton radio_button, Graphics dc, ButtonState state, Rectangle radiobutton_rectangle)
                {
-                       SolidBrush sb = new SolidBrush(radio_button.BackColor);
-                       dc.FillRectangle(sb, radio_button.ClientRectangle);
-                       sb.Dispose();
+                       dc.FillRectangle(GetControlBackBrush (radio_button.BackColor), radio_button.ClientRectangle);
                        
                        if (radio_button.appearance==Appearance.Button) {
-                               if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
-                                       DrawFlatStyleButton(dc, radio_button.ClientRectangle, radio_button);
-                               } else {                                
-                                       CPDrawButton(dc, radio_button.ClientRectangle, state);
-                               }               
+                               ButtonBase_DrawButton (radio_button, dc);
+                               
+                               if ((radio_button.Focused) && radio_button.Enabled)
+                                       ButtonBase_DrawFocus(radio_button, dc);
                        } else {
                                // establish if we are rendering a flat style of some sort
                                if (radio_button.FlatStyle == FlatStyle.Flat || radio_button.FlatStyle == FlatStyle.Popup) {
                                        DrawFlatStyleRadioButton (dc, radiobutton_rectangle, radio_button);
                                } else {
-                                       ControlPaint.DrawRadioButton (dc, radiobutton_rectangle, state);
+                                       CPDrawRadioButton(dc, radiobutton_rectangle, state);
                                }
                        }
                }
                
                protected virtual void RadioButton_DrawText(RadioButton radio_button, Rectangle text_rectangle, Graphics dc, StringFormat text_format)
                {
-                       SolidBrush sb;
-                       
-                       // offset the text if it's pressed and a button
-                       if (radio_button.Appearance == Appearance.Button) {
-                               if (radio_button.Checked || (radio_button.Capture && radio_button.FlatStyle != FlatStyle.Flat)) {
-                                       text_rectangle.X ++;
-                                       text_rectangle.Y ++;
-                               }
-                               
-                               text_rectangle.Inflate(-4,-4);
-                       } 
-                       
-                       /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */                       
-                       dc.DrawString (radio_button.Text, radio_button.Font, ThemeEngine.Current.ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
-                       
-                       if (radio_button.Enabled) {
-                               sb = ResPool.GetSolidBrush(radio_button.ForeColor);
-                               dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
-                       } else if (radio_button.FlatStyle == FlatStyle.Flat) {
-                               dc.DrawString(radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (ControlPaint.DarkDark (this.ColorControl)), text_rectangle, text_format);
-                       } else {
-                               CPDrawStringDisabled(dc, radio_button.Text, radio_button.Font, this.ColorControlText, text_rectangle, text_format);
-                       }
+                       DrawCheckBox_and_RadioButtonText (radio_button, text_rectangle, dc, 
+                                                         text_format, radio_button.Appearance, radio_button.Checked);
                }
                
                protected virtual void RadioButton_DrawFocus(RadioButton radio_button, Graphics dc, Rectangle text_rectangle)
                {
-                       if (radio_button.Focused) {
-                               if (radio_button.FlatStyle != FlatStyle.Flat) {
-                                       DrawInnerFocusRectangle (dc, text_rectangle, radio_button.BackColor);
-                               } else {
-                                       dc.DrawRectangle (ResPool.GetPen (radio_button.ForeColor), text_rectangle);
-                               }
-                       }
+                       if ( radio_button.Focused && radio_button.appearance != Appearance.Button && radio_button.Enabled )
+                               DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor );
                }
-
+               
                // renders a radio button with the Flat and Popup FlatStyle
-               private void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
+               protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
                {
                        int     lineWidth;
                        
                        if (radio_button.Enabled) {
+                               
                                // draw the outer flatstyle arcs
                                if (radio_button.FlatStyle == FlatStyle.Flat) {
-                                       graphics.DrawArc (ResPool.GetPen (radio_button.ForeColor), rectangle, 0, 359);
+                                       graphics.DrawArc (SystemPens.ControlDarkDark, rectangle, 0, 359);
                                        
                                        // fill in the area depending on whether or not the mouse is hovering
-                                       if (radio_button.is_entered && radio_button.Capture) {
-                                               graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.Light (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
+                                       if ((radio_button.is_entered || radio_button.Capture) && !radio_button.is_pressed) {
+                                               graphics.FillPie (SystemBrushes.ControlLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
                                        } else {
-                                               graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
+                                               graphics.FillPie (SystemBrushes.ControlLightLight, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
                                        }
                                } else {
                                        // must be a popup radio button
                                        // fill the control
-                                       graphics.FillPie (ResPool.GetSolidBrush (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 0, 359);
+                                       graphics.FillPie (SystemBrushes.ControlLightLight, rectangle, 0, 359);
 
                                        if (radio_button.is_entered || radio_button.Capture) {
                                                // draw the popup 3d button knob
-                                               graphics.DrawArc (ResPool.GetPen (ControlPaint.Light (radio_button.BackColor)), rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
+                                               graphics.DrawArc (SystemPens.ControlLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 0, 359);
 
-                                               graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (radio_button.BackColor)), rectangle, 135, 180);
-                                               graphics.DrawArc (ResPool.GetPen (ControlPaint.LightLight (radio_button.BackColor)), rectangle, 315, 180);
+                                               graphics.DrawArc (SystemPens.ControlDark, rectangle, 135, 180);
+                                               graphics.DrawArc (SystemPens.ControlLightLight, rectangle, 315, 180);
                                                
                                        } else {
                                                // just draw lighter flatstyle outer circle
-                                               graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark (this.ColorControl)), rectangle, 0, 359);                                           
+                                               graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);                                           
                                        }                                                                               
                                }
                        } else {
                                // disabled
                                // fill control background color regardless of actual backcolor
-                               graphics.FillPie (ResPool.GetSolidBrush (this.ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
+                               graphics.FillPie (SystemBrushes.Control, rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
                                // draw the ark as control dark
-                               graphics.DrawArc (ResPool.GetPen (ControlPaint.Dark(this.ColorControl)), rectangle, 0, 359);
+                               graphics.DrawArc (SystemPens.ControlDark, rectangle, 0, 359);
                        }
 
                        // draw the check
-                       lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
                        if (radio_button.Checked) {
-                               SolidBrush buttonBrush;
+                               lineWidth = Math.Max (1, Math.Min(rectangle.Width, rectangle.Height)/3);
+                               
+                               Pen dot_pen = SystemPens.ControlDarkDark;
+                               Brush dot_brush = SystemBrushes.ControlDarkDark;
 
-                               if (!radio_button.Enabled) {
-                                       buttonBrush = ResPool.GetSolidBrush (ControlPaint.Dark (this.ColorControl));
-                               } else if (radio_button.FlatStyle == FlatStyle.Popup && radio_button.is_entered && radio_button.Capture) {
-                                       buttonBrush = ResPool.GetSolidBrush (this.ColorControlText);
+                               if (!radio_button.Enabled || ((radio_button.FlatStyle == FlatStyle.Popup) && radio_button.is_pressed)) {
+                                       dot_pen = SystemPens.ControlDark;
+                                       dot_brush = SystemBrushes.ControlDark;
+                               } 
+                               
+                               if (rectangle.Height >  13) {
+                                       graphics.FillPie (dot_brush, rectangle.X + lineWidth, rectangle.Y + lineWidth, rectangle.Width - lineWidth * 2, rectangle.Height - lineWidth * 2, 0, 359);
                                } else {
-                                       buttonBrush = ResPool.GetSolidBrush (radio_button.ForeColor);
+                                       int x_half_pos = (rectangle.Width / 2) + rectangle.X;
+                                       int y_half_pos = (rectangle.Height / 2) + rectangle.Y;
+                                       
+                                       graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos, x_half_pos + 2, y_half_pos);
+                                       graphics.DrawLine (dot_pen, x_half_pos - 1, y_half_pos + 1, x_half_pos + 2, y_half_pos + 1);
+                                       
+                                       graphics.DrawLine (dot_pen, x_half_pos, y_half_pos - 1, x_half_pos, y_half_pos + 2);
+                                       graphics.DrawLine (dot_pen, x_half_pos + 1, y_half_pos - 1, x_half_pos + 1, y_half_pos + 2);
                                }
-                               graphics.FillPie (buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
-                       }       
+                       }
                }
 
                public override Size RadioButtonDefaultSize {
@@ -3041,10 +3147,10 @@ namespace System.Windows.Forms
                        Rectangle r = new Rectangle( 0,  
                                                    scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - ( scrollbutton_height * 2 ) );
                        Rectangle intersect = Rectangle.Intersect( clip, r );
-                       
+
                        if ( intersect != Rectangle.Empty )
                        {
-                               Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow);
+                               Brush h = ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White);
                                dc.FillRectangle( h, intersect );
                        }
                }
@@ -3056,7 +3162,7 @@ namespace System.Windows.Forms
                        Rectangle intersect = Rectangle.Intersect( clip, r );
                        
                        if ( intersect != Rectangle.Empty )
-                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow ), intersect );
+                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White ), intersect );
                        
                        r.X = 0;
                        r.Y = thumb_pos.Y + thumb_pos.Height;
@@ -3084,7 +3190,7 @@ namespace System.Windows.Forms
                        
                        intersect = Rectangle.Intersect( clip, r );
                        if ( intersect != Rectangle.Empty )
-                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow), intersect );
+                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
                }
                
                protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_None( int scrollbutton_width, ScrollBar bar, Rectangle clip, Graphics dc )
@@ -3094,7 +3200,7 @@ namespace System.Windows.Forms
                        Rectangle intersect = Rectangle.Intersect( clip, r );
                        
                        if ( intersect != Rectangle.Empty )
-                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow), intersect );
+                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
                }
                
                protected virtual void ScrollBar_Horizontal_Draw_ThumbMoving_Forward( int scrollbutton_width, Rectangle thumb_pos, ScrollBar bar, Rectangle clip, Graphics dc )
@@ -3104,7 +3210,7 @@ namespace System.Windows.Forms
                        Rectangle intersect = Rectangle.Intersect( clip, r );
                        
                        if ( intersect != Rectangle.Empty )
-                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow ), intersect );
+                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
                        
                        r.X = thumb_pos.X + thumb_pos.Width;
                        r.Y = 0;
@@ -3132,7 +3238,7 @@ namespace System.Windows.Forms
                        
                        intersect = Rectangle.Intersect( clip, r );
                        if ( intersect != Rectangle.Empty )
-                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, ColorWindow), intersect );
+                               dc.FillRectangle( ResPool.GetHatchBrush( HatchStyle.Percent50, ColorScrollBar, Color.White), intersect );
                }
 
                public override int ScrollBarButtonSize {
@@ -3145,8 +3251,11 @@ namespace System.Windows.Forms
                        Rectangle area = sb.ClientRectangle;
                        int horz_border = 2;
                        int vert_border = 2;
+                       
+                       bool is_color_control = sb.BackColor.ToArgb () == ColorControl.ToArgb ();
 
-                       dc.FillRectangle (GetControlBackBrush (sb.BackColor), clip);
+                       Brush brush = is_color_control ? SystemBrushes.Control : ResPool.GetSolidBrush (sb.BackColor);
+                       dc.FillRectangle (brush, clip);
                        
                        if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
                                string text = sb.Text;
@@ -3167,7 +3276,7 @@ namespace System.Windows.Forms
                                                new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
                                string_format.Dispose ();
                        } else if (sb.ShowPanels) {
-                               SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
+                               Brush br_forecolor = GetControlForeBrush (sb.ForeColor);
                                int prev_x = area.X + horz_border;
                                int y = area.Y + vert_border;
                                for (int i = 0; i < sb.Panels.Count; i++) {
@@ -3179,24 +3288,29 @@ namespace System.Windows.Forms
                                }
                        }
 
-                       if (sb.SizingGrip)
+                       if (sb.SizingGrip) {
+                               area = new Rectangle (area.Right - 16 - 2, area.Bottom - 12 - 1, 16, 16);
                                CPDrawSizeGrip (dc, ColorControl, area);
+                       }
 
                }
 
 
                protected virtual void DrawStatusBarPanel (Graphics dc, Rectangle area, int index,
-                       SolidBrush br_forecolor, StatusBarPanel panel) {
+                       Brush br_forecolor, StatusBarPanel panel) {
                        int border_size = 3; // this is actually const, even if the border style is none
-
+                       int icon_width = 16;
+                       
                        area.Height -= border_size;
+                       
                        if (panel.BorderStyle != StatusBarPanelBorderStyle.None) {
-                               Border3DStyle border_style = Border3DStyle.SunkenInner;
+                               Border3DStyle border_style = Border3DStyle.SunkenOuter;
                                if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
-                                       border_style = Border3DStyle.RaisedOuter;
-                               CPDrawBorder3D(dc, area, border_style, Border3DSide.All, ColorControl);
+                                       border_style = Border3DStyle.RaisedInner;
+                                       
+                               CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
                        }
-
+                       
                        if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
                                StatusBarDrawItemEventArgs e = new StatusBarDrawItemEventArgs (
                                        dc, panel.Parent.Font, area, index, DrawItemState.Default,
@@ -3205,21 +3319,15 @@ namespace System.Windows.Forms
                                return;
                        }
 
-                       int left = area.Left;
-                       if (panel.Icon != null) {
-                               left += 2;
-                               dc.DrawIcon (panel.Icon, left, area.Top);
-                               left += panel.Icon.Width;
-                       }
-
                        if (panel.Text == String.Empty)
-                               return;
+                                       return;
 
                        string text = panel.Text;
                        StringFormat string_format = new StringFormat ();
                        string_format.Trimming = StringTrimming.Character;
                        string_format.FormatFlags = StringFormatFlags.NoWrap;
 
+                       
                        if (text [0] == '\t') {
                                string_format.Alignment = StringAlignment.Center;
                                text = text.Substring (1);
@@ -3229,14 +3337,55 @@ namespace System.Windows.Forms
                                }
                        }
 
-                       int x = left + border_size;
-                       int y = border_size + 2;
-                       Rectangle r = new Rectangle (x, y, 
-                               area.Right - x - border_size,
-                               area.Bottom - y - border_size);
-                       
-                       dc.DrawString (text, panel.Parent.Font, br_forecolor, r, string_format);
-                       string_format.Dispose ();
+                       Rectangle string_rect = Rectangle.Empty;
+                       int x;
+                       int len;
+                       int icon_x = 0;
+                       int y = (area.Height / 2 - (int) panel.Parent.Font.Size / 2) - 1;
+
+                       switch (panel.Alignment) {
+                       case HorizontalAlignment.Right:
+                               len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
+                               x = area.Right - len - 4;
+                               string_rect = new Rectangle (x, y, 
+                                               area.Right - x - border_size,
+                                               area.Bottom - y - border_size);
+                               if (panel.Icon != null) {
+                                       icon_x = x - icon_width - 2;
+                               }
+                               break;
+                       case HorizontalAlignment.Center:
+                               len = (int) dc.MeasureString (text, panel.Parent.Font).Width;
+                               x = (panel.Width / 2) + (len / 2);
+                               string_rect = new Rectangle (x, y, 
+                                               area.Right - x - border_size,
+                                               area.Bottom - y - border_size);
+
+                               if (panel.Icon != null) {
+                                       icon_x = x - icon_width - 2;
+                               }
+                               break;
+
+                               
+                       default:
+                               int left = area.Left + border_size;;
+                               if (panel.Icon != null) {
+                                       icon_x = area.Left + 2;
+                                       left = icon_x + icon_width + 2;
+                               }
+
+                               x = left;
+                               string_rect = new Rectangle (x, y, 
+                                               area.Right - x - border_size,
+                                               area.Bottom - y - border_size);
+                               break;
+                       }
+
+                       dc.DrawString (text, panel.Parent.Font, br_forecolor, string_rect, string_format);                      
+
+                       if (panel.Icon != null) {
+                               dc.DrawIcon (panel.Icon, new Rectangle (icon_x, y, icon_width, icon_width));
+                       }
                }
 
                public override int StatusBarSizeGripWidth {
@@ -3256,8 +3405,8 @@ namespace System.Windows.Forms
 
                public override void DrawTabControl (Graphics dc, Rectangle area, TabControl tab)
                {
-                       // Do we need to fill the back color? It can't be changed...
-                       dc.FillRectangle (GetControlBackBrush (tab.BackColor), area);
+                       Brush brush = SystemBrushes.Control;
+                       dc.FillRectangle (brush, area);
                        Rectangle panel_rect = GetTabPanelRectExt (tab);
 
                        if (tab.Appearance == TabAppearance.Normal) {
@@ -3407,7 +3556,7 @@ namespace System.Windows.Forms
 
                        StringFormat string_format = new StringFormat ();
                        if (tab.Appearance == TabAppearance.Buttons || tab.Appearance == TabAppearance.FlatButtons) {
-                               dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
+                               dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
 
                                // Separators
                                if (tab.Appearance == TabAppearance.FlatButtons) {
@@ -3419,9 +3568,9 @@ namespace System.Windows.Forms
                                }
 
                                if (is_selected) {
-                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.All);
+                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                                } else if (tab.Appearance != TabAppearance.FlatButtons) {
-                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.All);
+                                       CPDrawBorder3D (dc, bounds, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom);
                                }
 
                                interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
@@ -3431,14 +3580,15 @@ namespace System.Windows.Forms
                                string_format.LineAlignment = StringAlignment.Center;
                                string_format.FormatFlags = StringFormatFlags.NoWrap;
                        } else {
-                               Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
+                               CPColor cpcolor = ResPool.GetCPColor (tab.BackColor);
+                               
+                               Pen light = ResPool.GetPen (cpcolor.LightLight);
 
                                switch (tab.Alignment) {
                                        
                                case TabAlignment.Top:
 
-
-                                       dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
 
                                        dc.DrawLine (light, bounds.Left, bounds.Bottom, bounds.Left, bounds.Top + 3);
                                        dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
@@ -3458,7 +3608,7 @@ namespace System.Windows.Forms
 
                                case TabAlignment.Bottom:
 
-                                       dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
 
                                        dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom - 3);
                                        dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left + 2, bounds.Bottom - 1);
@@ -3480,7 +3630,7 @@ namespace System.Windows.Forms
 
                                case TabAlignment.Left:
 
-                                       dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
 
                                        dc.DrawLine (light, bounds.Left, bounds.Bottom - 3, bounds.Left, bounds.Top + 3);
                                        dc.DrawLine (light, bounds.Left, bounds.Top + 3, bounds.Left + 3, bounds.Top);
@@ -3503,7 +3653,7 @@ namespace System.Windows.Forms
                                default:
                                        // TabAlignment.Right
 
-                                       dc.FillRectangle (GetControlBackBrush (tab.BackColor), bounds);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (tab.BackColor), bounds);
 
                                        dc.DrawLine (light, bounds.Left, bounds.Top, bounds.Right - 3, bounds.Top);
                                        dc.DrawLine (light, bounds.Right - 3, bounds.Top, bounds.Right, bounds.Top + 3);
@@ -3523,33 +3673,33 @@ namespace System.Windows.Forms
 
                                        break;
                                }
+                       }
 
-                               if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
-                                       if (tab.Alignment == TabAlignment.Left) {
-                                               int wo = interior.Width / 2;
-                                               int ho = interior.Height / 2;
-                                               dc.TranslateTransform (interior.X + wo, interior.Y + ho);
-                                               dc.RotateTransform (180);
-                                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
-                                               dc.ResetTransform ();
-                                       } else {
-                                               dc.DrawString (page.Text, page.Font,
-                                                               ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText),
-                                                               interior, string_format);
-                                       }
-                               } else if (page.Text != null) {
-                                       DrawItemState state = DrawItemState.None;
-                                       if (page == tab.SelectedTab)
-                                               state |= DrawItemState.Selected;
-                                       DrawItemEventArgs e = new DrawItemEventArgs (dc,
-                                                       tab.Font, bounds, tab.IndexForTabPage (page),
-                                                       state, page.ForeColor, page.BackColor);
-                                       tab.OnDrawItemInternal (e);
-                                       return res;
-                               }
+                       if (tab.DrawMode == TabDrawMode.Normal && page.Text != null) {
+                               if (tab.Alignment == TabAlignment.Left) {
+                                       int wo = interior.Width / 2;
+                                       int ho = interior.Height / 2;
+                                       dc.TranslateTransform (interior.X + wo, interior.Y + ho);
+                                       dc.RotateTransform (180);
+                                       dc.DrawString (page.Text, page.Font, SystemBrushes.ControlText, 0, 0, string_format);
+                                       dc.ResetTransform ();
+                               } else {
+                                       dc.DrawString (page.Text, page.Font,
+                                                      SystemBrushes.ControlText,
+                                                       interior, string_format);
+                               }
+                       } else if (page.Text != null) {
+                               DrawItemState state = DrawItemState.None;
+                               if (page == tab.SelectedTab)
+                                       state |= DrawItemState.Selected;
+                               DrawItemEventArgs e = new DrawItemEventArgs (dc,
+                                               tab.Font, bounds, tab.IndexForTabPage (page),
+                                               state, page.ForeColor, page.BackColor);
+                               tab.OnDrawItemInternal (e);
+                               return res;
                        }
 
-                       if (page.Focused) {
+                       if (page.parent.Focused && is_selected) {
                                CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
                        }
 
@@ -3557,255 +3707,189 @@ namespace System.Windows.Forms
                }
 
                #region ToolBar
-               public  override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
-                       StringFormat    format = new StringFormat ();
-                       format.Trimming = StringTrimming.EllipsisWord;
-                       if (control.textAlignment == ToolBarTextAlign.Underneath) {
-                               format.LineAlignment = StringAlignment.Center;
+               public  override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) 
+               {
+                       StringFormat format = new StringFormat ();
+                       format.Trimming = StringTrimming.EllipsisCharacter;
+                       format.LineAlignment = StringAlignment.Center;
+                       if (control.TextAlign == ToolBarTextAlign.Underneath)
                                format.Alignment = StringAlignment.Center;
-                       } else {
-                               format.LineAlignment = StringAlignment.Center;
+                       else
                                format.Alignment = StringAlignment.Near;
-                       }
-                       
-                       // Exclude the area for divider
-                       Rectangle paint_area = new Rectangle (0, ToolBarGripWidth / 2, 
-                               control.Width, control.Height - ToolBarGripWidth / 2);
-                       bool flat = (control.Appearance == ToolBarAppearance.Flat);
-                       dc.FillRectangle (ResPool.GetSolidBrush( DefaultControlBackColor ), paint_area);
-                       if (control.Divider)
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), 0, 0, paint_area.Width, 0);
-
-                       foreach (ToolBarButton button in control.Buttons) {
-
-                               Image image = null;
-                               Rectangle buttonArea = button.Rectangle;
-                               Rectangle imgRect = Rectangle.Empty;  // rect to draw the image
-                               Rectangle txtRect = buttonArea;       // rect to draw the text
-                               Rectangle ddRect = Rectangle.Empty;   // rect for the drop down arrow
-
-                               // calculate different rects and draw the frame if its not separator button
-                               if (button.Style != ToolBarButtonStyle.Separator) {
-                                       /* Adjustment for drop down arrow */
-                                       if (button.Style == ToolBarButtonStyle.DropDownButton && control.DropDownArrows) {
-                                               ddRect.X = buttonArea.X + buttonArea.Width - this.ToolBarDropDownWidth;
-                                               ddRect.Y = buttonArea.Y;
-                                               ddRect.Width = this.ToolBarDropDownWidth;
-                                               ddRect.Height = buttonArea.Height;
-                                       }
 
-                                       // calculate txtRect and imgRect, if imageIndex and imageList are present
-                                       if (button.ImageIndex > -1 && control.ImageList != null) {
-                                               if (button.ImageIndex < control.ImageList.Images.Count)
-                                                       image = control.ImageList.Images [button.ImageIndex];
-                                               // draw the image at the centre if textalignment is underneath
-                                               if (control.TextAlign == ToolBarTextAlign.Underneath) {
-                                                       imgRect.X = buttonArea.X + ((buttonArea.Width - ddRect.Width 
-                                                               - control.ImageSize.Width) / 2) 
-                                                               + this.ToolBarImageGripWidth;
-                                                       imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
-                                                       imgRect.Width = control.ImageSize.Width;
-                                                       imgRect.Height = control.ImageSize.Height;
-
-                                                       txtRect.X = buttonArea.X;
-                                                       txtRect.Y = buttonArea.Y + imgRect.Height + 2 * this.ToolBarImageGripWidth;
-                                                       txtRect.Width = buttonArea.Width - ddRect.Width;
-                                                       txtRect.Height = buttonArea.Height - imgRect.Height 
-                                                               - 2 * this.ToolBarImageGripWidth;
-                                               }
-                                               else {
-                                                       imgRect.X = buttonArea.X + this.ToolBarImageGripWidth;
-                                                       imgRect.Y = buttonArea.Y + this.ToolBarImageGripWidth;
-                                                       imgRect.Width = control.ImageSize.Width;
-                                                       imgRect.Height = control.ImageSize.Height;
-
-                                                       txtRect.X = buttonArea.X + imgRect.Width + 2 * this.ToolBarImageGripWidth;
-                                                       txtRect.Y = buttonArea.Y;
-                                                       txtRect.Width = buttonArea.Width - imgRect.Width 
-                                                               - 2 * this.ToolBarImageGripWidth - ddRect.Width;
-                                                       txtRect.Height = buttonArea.Height;
-                                               }
-                                       }
-                                       /* Draw the button frame, only if it is not a separator */
-                                       if (flat) { 
-                                               if (button.Pushed || button.Pressed) {
-                                                       CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenOuter, Border3DSide.All, ColorControl);
-                                               } else if (button.Hilight) {
-                                                       dc.DrawRectangle (ResPool.GetPen (ColorControlText), buttonArea);
-                                                       if (! ddRect.IsEmpty) {
-                                                               dc.DrawLine (ResPool.GetPen (ColorControlText), ddRect.X, ddRect.Y, ddRect.X, 
-                                                                       ddRect.Y + ddRect.Height);
-                                                               buttonArea.Width -= this.ToolBarDropDownWidth;
-                                                       }
-                                               }
+                       if (control is PropertyGrid.PropertyToolBar) {
+                               dc.FillRectangle (ResPool.GetSolidBrush(control.BackColor), clip_rectangle);
+                               
+                               if (clip_rectangle.X == 0) {
+                                       dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.X, control.Bottom);
+                               }
+
+                               if (clip_rectangle.Y < 2) {
+                                       dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
+                               }
+
+                               if (clip_rectangle.Bottom == control.Bottom) {
+                                       dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, clip_rectangle.Bottom - 1, clip_rectangle.Right, clip_rectangle.Bottom - 1);
+                               }
+
+                               if (clip_rectangle.Right == control.Right) {
+                                       dc.DrawLine (SystemPens.ControlDark, clip_rectangle.Right - 1, 1, clip_rectangle.Right - 1, control.Bottom - 1);
+                               }
+                       } else {
+
+                               if (control.Appearance == ToolBarAppearance.Flat && control.Parent != null) {
+                                       if (control.Parent.BackgroundImage != null) {
+                                               using (TextureBrush b = new TextureBrush (control.Parent.BackgroundImage, WrapMode.Tile))
+                                                       dc.FillRectangle (b, clip_rectangle);
+                                       } else {
+                                               dc.FillRectangle (ResPool.GetSolidBrush (control.Parent.BackColor), clip_rectangle);
                                        }
-                                       else { // normal toolbar
-                                               if (button.Pushed || button.Pressed) {
-                                                       CPDrawBorder3D (dc, buttonArea, Border3DStyle.SunkenInner,
-                                                               Border3DSide.All, ColorControl);
-                                                       if (! ddRect.IsEmpty) {
-                                                               CPDrawBorder3D (dc, ddRect, Border3DStyle.SunkenInner,
-                                                                       Border3DSide.Left, ColorControl);
-                                                               buttonArea.Width -= this.ToolBarDropDownWidth;
-                                                       }
-                                               }
-                                               else {
-                                                       CPDrawBorder3D (dc, buttonArea, Border3DStyle.RaisedInner,
-                                                               Border3DSide.All, ColorControl);
-                                                       if (! ddRect.IsEmpty) {
-                                                               CPDrawBorder3D (dc, ddRect, Border3DStyle.RaisedInner,
-                                                                       Border3DSide.Left, ColorControl);
-                                                               buttonArea.Width -= this.ToolBarDropDownWidth;
-                                                       }
-                                               }
+                               } else {
+                                       dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
+                               }
+
+                               if (control.Divider && clip_rectangle.Y < 2) {
+                                       if (clip_rectangle.Y < 1) {
+                                               dc.DrawLine (SystemPens.ControlDark, clip_rectangle.X, 0, clip_rectangle.Right, 0);
                                        }
+                                       dc.DrawLine (SystemPens.ControlLightLight, clip_rectangle.X, 1, clip_rectangle.Right, 1);
                                }
-                               DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
-                                       imgRect, image, txtRect, ddRect, flat);
                        }
+
+                       foreach (ToolBarButton button in control.Buttons)
+                               if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
+                                       DrawToolBarButton (dc, control, button, format);
+
                        format.Dispose ();
                }
 
-               private void DrawToolBarButton (Graphics dc, ToolBarButton button, Font font, StringFormat format,
-                       Rectangle controlArea, Rectangle buttonArea, Rectangle imgRect, 
-                       Image image, Rectangle txtRect, Rectangle ddRect, bool flat) {
-                       if (! button.Visible)
-                               return;
+               protected virtual void DrawToolBarButton (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
+               {
+                       bool is_flat = control.Appearance == ToolBarAppearance.Flat;
+
+                       DrawToolBarButtonBorder (dc, button, is_flat);
 
                        switch (button.Style) {
+                       case ToolBarButtonStyle.DropDownButton:
+                               if (control.DropDownArrows)
+                                       DrawToolBarDropDownArrow (dc, button, is_flat);
+                               DrawToolBarButtonContents (dc, control, button, format);
+                               break;
 
                        case ToolBarButtonStyle.Separator:
-                               // separator is drawn only in the case of flat appearance
-                               if (flat) {
-                                       dc.DrawLine (ResPool.GetPen (ColorControlDark), buttonArea.X + 1, buttonArea.Y, 
-                                               buttonArea.X + 1, buttonArea.Height);
-                                       dc.DrawLine (ResPool.GetPen (ColorControlLight), buttonArea.X + 1 + (int) ResPool.GetPen (ColorControl).Width,
-                                               buttonArea.Y, buttonArea.X + 1 + (int) ResPool.GetPen (ColorControl).Width, buttonArea.Height);
-                                       /* draw a horizontal separator */
-                                       if (button.Wrapper) {
-                                               int y = buttonArea.Height + this.ToolBarSeparatorWidth / 2;
-                                               dc.DrawLine (ResPool.GetPen (ColorControlDark), 0, y, controlArea.Width, y);
-                                               dc.DrawLine (ResPool.GetPen (ColorControlLight), 0, y + 1 + (int) ResPool.GetPen (ColorControl).Width, controlArea.Width,
-                                                       y + 1 + (int) ResPool.GetPen (ColorControl).Width);
-                                       }
-                               }
+                               if (is_flat)
+                                       DrawToolBarSeparator (dc, button);
                                break;
 
                        case ToolBarButtonStyle.ToggleButton:
-                               Rectangle toggleArea = Rectangle.Empty;
-                               toggleArea.X = buttonArea.X + this.ToolBarImageGripWidth;
-                               toggleArea.Y = buttonArea.Y + this.ToolBarImageGripWidth;
-                               toggleArea.Width = buttonArea.Width - 2 * this.ToolBarImageGripWidth;
-                               toggleArea.Height = buttonArea.Height - 2 * this.ToolBarImageGripWidth;
-                               if (button.PartialPush && button.Pushed) {
-                                       dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
-                                       if (! imgRect.IsEmpty) {
-                                               if (button.Enabled && image != null)
-                                                       button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, 
-                                                               imgRect.Height, button.ImageIndex);
-                                               else {
-                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
-                                                       ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
-                                                               Border3DSide.Right | Border3DSide.Bottom);
-                                               }
-                                       }
-                                       if (button.Enabled)
-                                               dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
-                                       else
-                                               CPDrawStringDisabled (dc, button.Text, font, ColorControlLight, txtRect, format);
-                               }
-
-                               else if (button.PartialPush) {
-                                       dc.FillRectangle (SystemBrushes.ControlLight, toggleArea);
-                                       if (! imgRect.IsEmpty) {
-                                               if (button.Enabled && image != null)
-                                                       button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
-                                                               imgRect.Height, button.ImageIndex);
-                                               else {
-                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
-                                                       ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
-                                                               Border3DSide.Right | Border3DSide.Bottom);
-                                               }
-                                       }
-                                       if (button.Enabled)
-                                               dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
-                                       else
-                                               CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
-                                                       txtRect, format);
-                               }
-
-                               else if (button.Pushed) {
-                                       dc.FillRectangle (SystemBrushes.ControlLightLight, toggleArea);
-                                       if (! imgRect.IsEmpty) {
-                                               if (button.Enabled && image != null)
-                                                       button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
-                                                               imgRect.Height, button.ImageIndex);
-                                               else {
-                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
-                                                       CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
-                                                               Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                               }
-                                       }
-                                       if (button.Enabled)
-                                               dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
-                                       else
-                                               CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
-                                                       txtRect, format);
-                               }
+                               DrawToolBarToggleButtonBackground (dc, button);
+                               DrawToolBarButtonContents (dc, control, button, format);
+                               break;
 
-                               else {
-                                       dc.FillRectangle (SystemBrushes.Control, toggleArea);
-                                       if (! imgRect.IsEmpty) {
-                                               if (button.Enabled && image != null)
-                                                       button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
-                                                               imgRect.Height, button.ImageIndex);
-                                               else {
-                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
-                                                       CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
-                                                               Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                               }
-                                       }
-                                       if (button.Enabled)
-                                               dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
-                                       else
-                                               CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
-                                                       txtRect, format);
-                               }
+                       default:
+                               DrawToolBarButtonContents (dc, control, button, format);
                                break;
+                       }
+               }
 
-                       case ToolBarButtonStyle.DropDownButton:
-                               // draw the dropdown arrow
-                               if (! ddRect.IsEmpty) {
-                                       PointF [] vertices = new PointF [3];
-                                       PointF ddCenter = new PointF (ddRect.X + (ddRect.Width/2.0f), ddRect.Y + (ddRect.Height/2.0f));
-                                       vertices [0].X = ddCenter.X - this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
-                                       vertices [0].Y = ddCenter.Y;
-                                       vertices [1].X = ddCenter.X + this.ToolBarDropDownArrowWidth / 2.0f + 0.5f;
-                                       vertices [1].Y = ddCenter.Y;
-                                       vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
-                                       vertices [2].Y = ddCenter.Y + this.ToolBarDropDownArrowHeight;
-                                       dc.FillPolygon (SystemBrushes.ControlText, vertices);
-                               }
-                               goto case ToolBarButtonStyle.PushButton;
-
-                       case ToolBarButtonStyle.PushButton:
-                               if (! imgRect.IsEmpty){
-                                       if (button.Enabled && image != null)
-                                               button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
-                                                       button.ImageIndex);
-                                       else {
-                                               dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
-                                               CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
-                                                       Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                       }
-                               }
-                               if (button.Enabled)
-                                       dc.DrawString (button.Text, font, SystemBrushes.ControlText, txtRect, format);
+               const Border3DSide all_sides = Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom;
+
+               protected virtual void DrawToolBarButtonBorder (Graphics dc, ToolBarButton button, bool is_flat)
+               {
+                       if (button.Style == ToolBarButtonStyle.Separator)
+                               return;
+
+                       Border3DStyle style;
+
+                       if (is_flat) {
+                               if (button.Pushed || button.Pressed)
+                                       style = Border3DStyle.SunkenOuter;
+                               else if (button.Hilight)
+                                       style = Border3DStyle.RaisedInner;
                                else
-                                       CPDrawStringDisabled (dc, button.Text, font, ColorControlLight,
-                                               txtRect, format);
-                               break;
+                                       return;
+
+                       } else {
+                               if (button.Pushed || button.Pressed)
+                                       style = Border3DStyle.Sunken;
+                               else 
+                                       style = Border3DStyle.Raised;
+                       }
+
+                       CPDrawBorder3D (dc, button.Rectangle, style, all_sides);
+               }
+
+               protected virtual void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
+               {
+                       Rectangle area = button.Rectangle;
+                       int offset = (int) SystemPens.Control.Width + 1;
+                       dc.DrawLine (SystemPens.ControlDark, area.X + 1, area.Y, area.X + 1, area.Bottom);
+                       dc.DrawLine (SystemPens.ControlLight, area.X + offset, area.Y, area.X + offset, area.Bottom);
+               }
+
+               protected virtual void DrawToolBarToggleButtonBackground (Graphics dc, ToolBarButton button)
+               {
+                       Rectangle area = button.Rectangle;
+                       area.X += ToolBarImageGripWidth;
+                       area.Y += ToolBarImageGripWidth;
+                       area.Width -= 2 * ToolBarImageGripWidth;
+                       area.Height -= 2 * ToolBarImageGripWidth;
+
+                       if (button.Pushed)
+                               dc.FillRectangle (SystemBrushes.ControlLightLight, area);
+                       else if (button.PartialPush)
+                               dc.FillRectangle (SystemBrushes.ControlLight, area);
+                       else
+                               dc.FillRectangle (SystemBrushes.Control, area);
+               }
+
+               protected virtual void DrawToolBarDropDownArrow (Graphics dc, ToolBarButton button, bool is_flat)
+               {
+                       Rectangle rect = button.Rectangle;
+                       rect.X = button.Rectangle.Right - ToolBarDropDownWidth;
+                       rect.Width = ToolBarDropDownWidth;
+
+                       if (button.dd_pressed) {
+                               CPDrawBorder3D (dc, rect, Border3DStyle.SunkenOuter, all_sides);
+                               CPDrawBorder3D (dc, rect, Border3DStyle.SunkenInner, Border3DSide.Bottom | Border3DSide.Right);
+                       } else if (button.Pushed || button.Pressed)
+                               CPDrawBorder3D (dc, rect, Border3DStyle.Sunken, all_sides);
+                       else if (is_flat) {
+                               if (button.Hilight)
+                                       CPDrawBorder3D (dc, rect, Border3DStyle.RaisedOuter, all_sides);
+                       } else
+                               CPDrawBorder3D (dc, rect, Border3DStyle.Raised, all_sides);
+
+                       PointF [] vertices = new PointF [3];
+                       PointF ddCenter = new PointF (rect.X + (rect.Width/2.0f), rect.Y + (rect.Height/2.0f));
+                       vertices [0].X = ddCenter.X - ToolBarDropDownArrowWidth / 2.0f + 0.5f;
+                       vertices [0].Y = ddCenter.Y;
+                       vertices [1].X = ddCenter.X + ToolBarDropDownArrowWidth / 2.0f + 0.5f;
+                       vertices [1].Y = ddCenter.Y;
+                       vertices [2].X = ddCenter.X + 0.5f; // 0.5 is added for adjustment
+                       vertices [2].Y = ddCenter.Y + ToolBarDropDownArrowHeight;
+                       dc.FillPolygon (SystemBrushes.ControlText, vertices);
+               }
+
+               protected virtual void DrawToolBarButtonContents (Graphics dc, ToolBar control, ToolBarButton button, StringFormat format)
+               {
+                       if (button.Image != null) {
+                               int x = button.ImageRectangle.X + ToolBarImageGripWidth;
+                               int y = button.ImageRectangle.Y + ToolBarImageGripWidth;
+                               if (button.Enabled)
+                                       dc.DrawImage (button.Image, x, y);
+                               else 
+                                       CPDrawImageDisabled (dc, button.Image, x, y, ColorControl);
                        }
+
+                       Rectangle text_rect = button.TextRectangle;
+                       if (text_rect.Width <= 0 || text_rect.Height <= 0)
+                               return;
+
+                       if (button.Enabled)
+                               dc.DrawString (button.Text, control.Font, SystemBrushes.ControlText, text_rect, format);
+                       else
+                               CPDrawStringDisabled (dc, button.Text, control.Font, control.BackColor, text_rect, format);
                }
 
                // Grip width for the ToolBar
@@ -3847,8 +3931,8 @@ namespace System.Windows.Forms
 
                #region ToolTip
                public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
-                       dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfo), control.client_rect);
-                       dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
+                       dc.FillRectangle(SystemBrushes.Info, control.client_rect);
+                       dc.DrawRectangle(SystemPens.WindowFrame, 0, 0, control.Width-1, control.Height-1);
                        dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
                }
 
@@ -3856,7 +3940,7 @@ namespace System.Windows.Forms
                        SizeF   sizef;
 
                        sizef = tt.DeviceContext.MeasureString(text, tt.Font);
-                       return new Size((int)sizef.Width+2, (int)sizef.Height+3);               // Need space for the border
+                       return new Size((int)sizef.Width+8, (int)sizef.Height+3);       // Need space for the border
                }
                #endregion      // ToolTip
 
@@ -3872,6 +3956,7 @@ namespace System.Windows.Forms
                        float pixels_betweenticks;
                        const int space_from_right = 8;
                        const int space_from_left = 8;
+                       const int space_from_bottom = 11;
                        Rectangle area = tb.ClientRectangle;
                        
                        switch (tb.TickStyle)   {
@@ -3906,13 +3991,13 @@ namespace System.Windows.Forms
                        thumb_area.Width = 4;
 
                        /* Draw channel */
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
+                       dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
                                1, thumb_area.Height);
                        
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X + 1, channel_startpoint.Y,
+                       dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X + 1, channel_startpoint.Y,
                                1, thumb_area.Height);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X + 3, channel_startpoint.Y,
+                       dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X + 3, channel_startpoint.Y,
                                1, thumb_area.Height);
 
                        pixel_len = thumb_area.Height - 11;
@@ -3920,19 +4005,19 @@ namespace System.Windows.Forms
                        
                        /* Convert thumb position from mouse position to value*/
                        if (mouse_value) {
-                               
-                               if (value_pos >= channel_startpoint.Y)
-                                       value_pos = (int)(((float) (value_pos - channel_startpoint.Y)) / pixels_betweenticks);
+                               if (value_pos < thumb_area.Bottom)
+                                       value_pos = (int) ((thumb_area.Bottom - value_pos) / pixels_betweenticks);
                                else
                                        value_pos = 0;                  
 
                                if (value_pos + tb.Minimum > tb.Maximum)
                                        value_pos = tb.Maximum - tb.Minimum;
-                                
+
                                tb.Value = value_pos + tb.Minimum;
                        }                       
-                       
-                       thumb_pos.Y = channel_startpoint.Y + (int) (pixels_betweenticks * (float) value_pos);
+
+                       // thumb_pos.Y = channel_startpoint.Y ; // + (int) (pixels_betweenticks * (float) value_pos);
+                       thumb_pos.Y = thumb_area.Bottom - space_from_bottom - (int) (pixels_betweenticks * (float) value_pos);
                        
                        /* Draw thumb fixed 10x22 size */
                        thumb_pos.Width = 10;
@@ -3943,15 +4028,18 @@ namespace System.Windows.Forms
                        case TickStyle.None: {
                                thumb_pos.X = channel_startpoint.X - 8;
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X , thumb_pos.Y + 10);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 16, thumb_pos.Y);
+                               dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y, thumb_pos.X + 16 + 4, thumb_pos.Y + 4);
                                
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y  +9);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y  +9 - 4);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X +1, thumb_pos.Y + 9, thumb_pos.X +15, thumb_pos.Y  +9);
+                               dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y + 9, thumb_pos.X +16 + 4, thumb_pos.Y  +9 - 4);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y  + 10, thumb_pos.X +16, thumb_pos.Y +10);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 16, thumb_pos.Y  + 10, thumb_pos.X  +16 + 5, thumb_pos.Y +10 - 5);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y  + 10, thumb_pos.X +16, thumb_pos.Y +10);
+                               dc.DrawLine (pen, thumb_pos.X + 16, thumb_pos.Y  + 10, thumb_pos.X  +16 + 5, thumb_pos.Y +10 - 5);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 16, 8);
                                dc.FillRectangle (br_thumb, thumb_pos.X + 17, thumb_pos.Y + 2, 1, 6);
@@ -3963,16 +4051,19 @@ namespace System.Windows.Forms
                        case TickStyle.TopLeft: {
                                thumb_pos.X = channel_startpoint.X - 10;
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X + 4 + 16, thumb_pos.Y);
+                               dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 4);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X  + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 4, thumb_pos.Y  + 9, thumb_pos.X, thumb_pos.Y + 5);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X  + 19, thumb_pos.Y + 9, thumb_pos.X  +19 , thumb_pos.Y+ 1);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X  + 4, thumb_pos.Y + 9, thumb_pos.X + 4 + 16 , thumb_pos.Y+ 9);
+                               dc.DrawLine (pen, thumb_pos.X + 4, thumb_pos.Y  + 9, thumb_pos.X, thumb_pos.Y + 5);
+                               dc.DrawLine (pen, thumb_pos.X  + 19, thumb_pos.Y + 9, thumb_pos.X  +19 , thumb_pos.Y+ 1);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X  + 4, thumb_pos.Y+ 10, thumb_pos.X  + 4 + 16, thumb_pos.Y+ 10);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X  + 4, thumb_pos.Y + 10, thumb_pos.X  -1, thumb_pos.Y+ 5);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X  + 4, thumb_pos.Y+ 10, thumb_pos.X  + 4 + 16, thumb_pos.Y+ 10);
+                               dc.DrawLine (pen, thumb_pos.X  + 4, thumb_pos.Y + 10, thumb_pos.X  -1, thumb_pos.Y+ 5);
+                               dc.DrawLine (pen, thumb_pos.X + 20, thumb_pos.Y, thumb_pos.X+ 20, thumb_pos.Y + 10);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 4, thumb_pos.Y + 1, 15, 8);
                                dc.FillRectangle (br_thumb, thumb_pos.X + 3, thumb_pos.Y + 2, 1, 6);
@@ -3984,14 +4075,18 @@ namespace System.Windows.Forms
 
                        case TickStyle.Both: {
                                thumb_pos.X = area.X + 10;
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
+                                       
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 9);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 19, thumb_pos.Y);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y  + 9);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X  + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y  + 8);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 9, thumb_pos.X+ 19, thumb_pos.Y  + 9);
+                               dc.DrawLine (pen, thumb_pos.X  + 10, thumb_pos.Y+ 1, thumb_pos.X + 19, thumb_pos.Y  + 8);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y  +10);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X  + 20, thumb_pos.Y, thumb_pos.X  + 20, thumb_pos.Y+ 9);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 10, thumb_pos.X+ 20, thumb_pos.Y  +10);
+                               dc.DrawLine (pen, thumb_pos.X  + 20, thumb_pos.Y, thumb_pos.X  + 20, thumb_pos.Y+ 9);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 18, 8);
 
@@ -4102,13 +4197,13 @@ namespace System.Windows.Forms
                        thumb_area.Height = 4;
                        
                        /* Draw channel */
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), channel_startpoint.X, channel_startpoint.Y,
+                       dc.FillRectangle (SystemBrushes.ControlDark, channel_startpoint.X, channel_startpoint.Y,
                                thumb_area.Width, 1);
                        
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), channel_startpoint.X, channel_startpoint.Y + 1,
+                       dc.FillRectangle (SystemBrushes.ControlDarkDark, channel_startpoint.X, channel_startpoint.Y + 1,
                                thumb_area.Width, 1);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), channel_startpoint.X, channel_startpoint.Y +3,
+                       dc.FillRectangle (SystemBrushes.ControlLight, channel_startpoint.X, channel_startpoint.Y +3,
                                thumb_area.Width, 1);
 
                        pixel_len = thumb_area.Width - 11;
@@ -4138,15 +4233,18 @@ namespace System.Windows.Forms
                        case TickStyle.None: {
                                thumb_pos.Y = channel_startpoint.Y - 8;
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 10, thumb_pos.Y);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 16);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 16, thumb_pos.X + 4, thumb_pos.Y + 16 + 4);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X +9, thumb_pos.Y +15);
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 16, thumb_pos.X +9 - 4, thumb_pos.Y +16 + 4);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y +16);
+                               dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 16, thumb_pos.X +10 - 5, thumb_pos.Y +16 + 5);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 16);
                                dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 17, 6, 1);
@@ -4157,16 +4255,19 @@ namespace System.Windows.Forms
                        case TickStyle.TopLeft: {
                                thumb_pos.Y = channel_startpoint.Y - 10;
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X, thumb_pos.Y + 4 + 16);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 4, thumb_pos.X + 4, thumb_pos.Y);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 9, thumb_pos.Y + 4 + 16);
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y);
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 19, thumb_pos.X + 1 , thumb_pos.Y +19);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 10, thumb_pos.Y + 4 + 16);
+                               dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y + 4, thumb_pos.X + 5, thumb_pos.Y -1);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 10, thumb_pos.Y + 20);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 4, 8, 15);
                                dc.FillRectangle (br_thumb, thumb_pos.X + 2, thumb_pos.Y + 3, 6, 1);
@@ -4177,14 +4278,18 @@ namespace System.Windows.Forms
 
                        case TickStyle.Both: {
                                thumb_pos.Y = area.Y + 10;
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
+                                       
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X + 9, thumb_pos.Y);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y, thumb_pos.X, thumb_pos.Y + 19);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, thumb_pos.X + 9, thumb_pos.Y + 1, thumb_pos.X + 9, thumb_pos.Y + 19);
+                               dc.DrawLine (pen, thumb_pos.X + 1, thumb_pos.Y + 10, thumb_pos.X + 8, thumb_pos.Y + 19);
 
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDarkDark), thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, thumb_pos.X + 10, thumb_pos.Y, thumb_pos.X +10, thumb_pos.Y + 20);
+                               dc.DrawLine (pen, thumb_pos.X, thumb_pos.Y + 20, thumb_pos.X + 9, thumb_pos.Y + 20);
 
                                dc.FillRectangle (br_thumb, thumb_pos.X + 1, thumb_pos.Y + 1, 8, 18);
 
@@ -4256,26 +4361,29 @@ namespace System.Windows.Forms
 
                        area = tb.ClientRectangle;
 
-                       if (tb.thumb_pressed == true) {
+                       if (!tb.Enabled) {
+                               br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
+                       } else if (tb.thumb_pressed == true) {
                                br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl);
                        } else {
-                               br_thumb = ResPool.GetSolidBrush (ColorControl);
+                               br_thumb = SystemBrushes.Control;
                        }
 
                        
                        /* Control Background */
-                       if (tb.BackColor == DefaultControlBackColor) {
-                               dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), clip_rectangle);
+                       if (tb.BackColor.ToArgb () == DefaultControlBackColor.ToArgb ()) {
+                               dc.FillRectangle (SystemBrushes.Control, clip_rectangle);
                        } else {
                                dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
                        }
                        
 
                        if (tb.Focused) {
-                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, area.Width - 1, 1);
-                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y + area.Height - 1, area.Width - 1, 1);
-                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X, area.Y, 1, area.Height - 1);
-                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black), area.X + area.Width - 1, area.Y, 1, area.Height - 1);
+                               Brush brush = ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControl, Color.Black);
+                               dc.FillRectangle (brush, area.X, area.Y, area.Width - 1, 1);
+                               dc.FillRectangle (brush, area.X, area.Y + area.Height - 1, area.Width - 1, 1);
+                               dc.FillRectangle (brush, area.X, area.Y, 1, area.Height - 1);
+                               dc.FillRectangle (brush, area.X + area.Width - 1, area.Y, 1, area.Height - 1);
                        }
 
                        if (tb.Orientation == Orientation.Vertical) {
@@ -4316,204 +4424,310 @@ namespace System.Windows.Forms
 
                #endregion
 
-               #region ControlPaint
-               private enum DrawFrameControlStates {
-                       ButtonCheck             = 0x0000,
-                       ButtonRadioImage        = 0x0001,
-                       ButtonRadioMask         = 0x0002,
-                       ButtonRadio             = 0x0004,
-                       Button3State            = 0x0008,
-                       ButtonPush              = 0x0010,
-
-                       CaptionClose            = 0x0000,
-                       CaptionMin              = 0x0001,
-                       CaptionMax              = 0x0002,
-                       CaptionRestore          = 0x0004,
-                       CaptionHelp             = 0x0008,
-
-                       MenuArrow               = 0x0000,
-                       MenuCheck               = 0x0001,
-                       MenuBullet              = 0x0002,
-                       MenuArrowRight          = 0x0004,
-
-                       ScrollUp                = 0x0000,
-                       ScrollDown              = 0x0001,
-                       ScrollLeft              = 0x0002,
-                       ScrollRight             = 0x0003,
-                       ScrollComboBox          = 0x0005,
-                       ScrollSizeGrip          = 0x0008,
-                       ScrollSizeGripRight     = 0x0010,
-
-                       Inactive                = 0x0100,
-                       Pushed                  = 0x0200,
-                       Checked                 = 0x0400,
-                       Transparent             = 0x0800,
-                       Hot                     = 0x1000,
-                       AdjustRect              = 0x2000,
-                       Flat                    = 0x4000,
-                       Mono                    = 0x8000
-
-               }
-
-               private enum DrawFrameControlTypes {
-                       Caption = 1,
-                       Menu    = 2,
-                       Scroll  = 3,
-                       Button  = 4
+               public override int ManagedWindowTitleBarHeight (InternalWindowManager wm)
+               {
+                       if (wm.IsToolWindow && !wm.IsMinimized)
+                               return SystemInformation.ToolWindowCaptionHeight;
+                       if (wm.Form.FormBorderStyle == FormBorderStyle.None)
+                               return 0;
+                       return SystemInformation.CaptionHeight;
                }
 
-               public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
-                       ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
-                       Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
-                       int bottomWidth, ButtonBorderStyle bottomStyle) {
-                       DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
-                       DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
-                       DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
-                       DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
+               public override int ManagedWindowBorderWidth (InternalWindowManager wm)
+               {
+                       return 3;
                }
 
-               public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
-                       CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
+               public override int ManagedWindowIconWidth (InternalWindowManager wm)
+               {
+                       return ManagedWindowTitleBarHeight (wm) - 5;
                }
 
-               private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
-                       Pen             penTopLeft;
-                       Pen             penTopLeftInner;
-                       Pen             penBottomRight;
-                       Pen             penBottomRightInner;
-                       Rectangle       rect= new Rectangle(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
-                       bool            doInner = false;
+               public override void ManagedWindowSetButtonLocations (InternalWindowManager wm)
+               {
+                       int bw = ManagedWindowBorderWidth (wm);
+                       Size btsize = ManagedWindowButtonSize (wm);
+                       int btw = btsize.Width;
+                       int bth = btsize.Height;
+
+                       if ((!wm.IsToolWindow || wm.IsMinimized) && wm.HasBorders) {
+                               if (!wm.IsMaximized) {
+                                       wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - btw - 2,
+                                                       bw + 2, btw, bth);
+                                       wm.maximize_button.Rectangle = new Rectangle (wm.close_button.Rectangle.Left - 2 - btw,
+                                                       bw + 2, btw, bth);
+                                       wm.minimize_button.Rectangle = new Rectangle (wm.maximize_button.Rectangle.Left - btw,
+                                                       bw + 2, btw, bth);
+                               } else {
+                                       // Maximized
+                               }
+                       } else if (wm.IsToolWindow) {
+                               wm.close_button.Rectangle = new Rectangle (wm.Form.Width - bw - 2 - btw, bw + 2, btw, bth);
+                       }
+               }
 
-                       if ((style & Border3DStyle.Adjust)!=0) {
-                               rect.Y-=2;
-                               rect.X-=2;
-                               rect.Width+=4;
-                               rect.Height+=4;
+               public override void DrawManagedWindowDecorations (Graphics dc, Rectangle clip, InternalWindowManager wm)
+               {
+                       Form form = wm.Form;
+                       int tbheight = ManagedWindowTitleBarHeight (wm);
+                       int bdwidth = ManagedWindowBorderWidth (wm);
+                       Color titlebar_color = Color.FromArgb (255, 0, 0, 255);
+                       
+                       if (wm.HasBorders) {
+                               Rectangle borders = new Rectangle (0, 0, form.Width, form.Height);
+                               // The 3d border is only 2 pixels wide, so we draw the innermost pixel ourselves
+                               dc.DrawRectangle (new Pen (ColorControl, 1), 2, 2, form.Width - 5, form.Height - 5);
+                               ControlPaint.DrawBorder3D (dc, borders, Border3DStyle.Raised);
                        }
 
-                       /* default to flat */
-                       penTopLeft=ResPool.GetPen(ControlPaint.Dark(control_color));
-                       penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
-                       penBottomRight=ResPool.GetPen(ControlPaint.Dark(control_color));
-                       penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
+                       Color color = ThemeEngine.Current.ColorControlDark;
 
-                       if ((style & Border3DStyle.RaisedOuter)!=0) {
-                               penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
-                               penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
-                               if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
-                                       doInner=true;
-                               }
-                       } else if ((style & Border3DStyle.SunkenOuter)!=0) {
-                               penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
-                               penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
-                               if ((style & (Border3DStyle.RaisedInner | Border3DStyle.SunkenInner))!=0) {
-                                       doInner=true;
-                               }
-                       }
+                       if (wm.IsActive () && !wm.IsMaximized)
+                               color = titlebar_color;
 
-                       if ((style & Border3DStyle.RaisedInner)!=0) {
-                               if (doInner) {
-                                       penTopLeftInner=ResPool.GetPen(control_color);
-                                       penBottomRightInner=ResPool.GetPen(ControlPaint.Dark(control_color));
-                               } else {
-                                       penTopLeft=ResPool.GetPen(ControlPaint.LightLight(control_color));
-                                       penBottomRight=ResPool.GetPen(ControlPaint.DarkDark(control_color));
-                               }
-                       } else if ((style & Border3DStyle.SunkenInner)!=0) {
-                               if (doInner) {
-                                       penTopLeftInner=ResPool.GetPen(ControlPaint.Dark(control_color));
-                                       penBottomRightInner=ResPool.GetPen(control_color);
-                               } else {
-                                       penTopLeft=ResPool.GetPen(ControlPaint.DarkDark(control_color));
-                                       penBottomRight=ResPool.GetPen(ControlPaint.LightLight(control_color));
-                               }
-                       }
+                       Rectangle tb = new Rectangle (bdwidth, bdwidth,
+                                       form.Width - (bdwidth * 2), tbheight);
 
-                       if ((sides & Border3DSide.Middle)!=0) {
-                               graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
-                       }
+                       // HACK: For now always draw the titlebar until we get updates better
+                       // Rectangle vis = Rectangle.Intersect (tb, pe.ClipRectangle);  
+                       //if (vis != Rectangle.Empty)
+                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (color), tb);
 
-                       if ((sides & Border3DSide.Left)!=0) {
-                               graphics.DrawLine(penTopLeft, rect.Left, rect.Bottom-2, rect.Left, rect.Top);
-                               if (doInner) {
-                                       graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Bottom-2, rect.Left+1, rect.Top);
-                               }
+                       dc.DrawLine (new Pen (SystemColors.ControlLight, 1), bdwidth,
+                                       tbheight + bdwidth, form.Width - (bdwidth * 2),
+                                       tbheight + bdwidth);
+
+                       if (!wm.IsToolWindow) {
+                               tb.X += 18; // Room for the icon and the buttons
+                               tb.Width = (form.Width - 62) - tb.X;
                        }
 
-                       if ((sides & Border3DSide.Top)!=0) {
-                               graphics.DrawLine(penTopLeft, rect.Left, rect.Top, rect.Right-2, rect.Top);
+                       if (form.Text != null) {
+                               StringFormat format = new StringFormat ();
+                               format.FormatFlags = StringFormatFlags.NoWrap;
+                               format.Trimming = StringTrimming.EllipsisCharacter;
+                               format.LineAlignment = StringAlignment.Center;
 
-                               if (doInner) {
-                                       if ((sides & Border3DSide.Left)!=0) {
-                                               graphics.DrawLine(penTopLeftInner, rect.Left+1, rect.Top+1, rect.Right-3, rect.Top+1);
-                                       } else {
-                                               graphics.DrawLine(penTopLeftInner, rect.Left, rect.Top+1, rect.Right-3, rect.Top+1);
-                                       }
-                               }
+                               if (tb.IntersectsWith (clip))
+                                       dc.DrawString (form.Text, form.Font,
+                                               ThemeEngine.Current.ResPool.GetSolidBrush (Color.White),
+                                               tb, format);
                        }
 
-                       if ((sides & Border3DSide.Right)!=0) {
-                               graphics.DrawLine(penBottomRight, rect.Right-1, rect.Top, rect.Right-1, rect.Bottom-1);
+                       if (wm.HasBorders) {
+                               if (!wm.IsToolWindow && form.Icon != null) {
+                                       Rectangle icon = new Rectangle (bdwidth + 3,
+                                                       bdwidth + 2, wm.IconWidth, wm.IconWidth);
+                                       if (icon.IntersectsWith (clip))
+                                               dc.DrawIcon (form.Icon, icon);
+                               }
 
-                               if (doInner) {
-                                       if ((sides & Border3DSide.Top)!=0) {
-                                               graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top+1, rect.Right-2, rect.Bottom-2);
-                                       } else {
-                                               graphics.DrawLine(penBottomRightInner, rect.Right-2, rect.Top, rect.Right-2, rect.Bottom-2);
+                               if (!wm.IsMaximized) {
+                                       if (!wm.IsToolWindow || wm.IsMinimized) {
+                                               DrawTitleButton (dc, wm.minimize_button, clip);
+                                               DrawTitleButton (dc, wm.maximize_button, clip);
                                        }
+                                       DrawTitleButton (dc, wm.close_button, clip);
+                               } else {
+                                       //      DrawMaximizedButtons (pe, form.ActiveMenu);
                                }
                        }
+               }
 
-                       if ((sides & Border3DSide.Bottom)!=0) {
-                               int     left=rect.Left;
+               public override Size ManagedWindowButtonSize (InternalWindowManager wm)
+               {
+                       int height = ManagedWindowTitleBarHeight (wm);
+                       if (!wm.IsMaximized && !wm.IsMinimized) {
+                               if (wm.IsToolWindow)
+                                       return new Size (SystemInformation.ToolWindowCaptionButtonSize.Width - 2,
+                                                       height - 5);
+                               if (wm.Form.FormBorderStyle == FormBorderStyle.None)
+                                       return Size.Empty;
+                       } else
+                               height = SystemInformation.CaptionHeight;
 
-                               if ((sides & Border3DSide.Left)!=0) {
-                                       left+=1;
-                               }
+                       return new Size (SystemInformation.CaptionButtonSize.Width - 2,
+                                       height - 5);
+               }
 
-                               graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
+               private void DrawTitleButton (Graphics dc, InternalWindowManager.TitleButton button, Rectangle clip)
+               {
+                       if (!button.Rectangle.IntersectsWith (clip))
+                               return;
 
-                               if (doInner) {
-                                       if ((sides & Border3DSide.Right)!=0) {
-                                               graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
-                                       } else {
-                                               graphics.DrawLine(penBottomRightInner, left, rect.Bottom-2, rect.Right-2, rect.Bottom-2);
-                                       }
-                               }
-                       }
+                       dc.FillRectangle (SystemBrushes.Control, button.Rectangle);
 
+                       ControlPaint.DrawCaptionButton (dc, button.Rectangle,
+                                       button.Caption, ButtonState.Normal);
                }
 
+               #region ControlPaint
+               public override void CPDrawBorder (Graphics graphics, Rectangle bounds, Color leftColor, int leftWidth,
+                       ButtonBorderStyle leftStyle, Color topColor, int topWidth, ButtonBorderStyle topStyle,
+                       Color rightColor, int rightWidth, ButtonBorderStyle rightStyle, Color bottomColor,
+                       int bottomWidth, ButtonBorderStyle bottomStyle) {
+                       DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Left, bounds.Bottom-1, leftWidth, leftColor, leftStyle, Border3DSide.Left);
+                       DrawBorderInternal(graphics, bounds.Left, bounds.Top, bounds.Right-1, bounds.Top, topWidth, topColor, topStyle, Border3DSide.Top);
+                       DrawBorderInternal(graphics, bounds.Right-1, bounds.Top, bounds.Right-1, bounds.Bottom-1, rightWidth, rightColor, rightStyle, Border3DSide.Right);
+                       DrawBorderInternal(graphics, bounds.Left, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1, bottomWidth, bottomColor, bottomStyle, Border3DSide.Bottom);
+               }
 
-               public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
-                       DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonPush;
+               public override void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides) {
+                       CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
+               }
 
-                       if ((state & ButtonState.Pushed)!=0) {
-                               dfcs |= DrawFrameControlStates.Pushed;
+               protected virtual void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color)
+               {
+                       Pen             penTopLeft;
+                       Pen             penTopLeftInner;
+                       Pen             penBottomRight;
+                       Pen             penBottomRightInner;
+                       Rectangle       rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
+                       bool is_ColorControl = control_color.ToArgb () == ColorControl.ToArgb () ? true : false;
+                       
+                       if ((style & Border3DStyle.Adjust) != 0) {
+                               rect.Y -= 2;
+                               rect.X -= 2;
+                               rect.Width += 4;
+                               rect.Height += 4;
                        }
-
-                       if ((state & ButtonState.Checked)!=0) {
-                               dfcs |= DrawFrameControlStates.Checked;
+                       
+                       penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = is_ColorControl ? SystemPens.Control : ResPool.GetPen (control_color);
+                       
+                       CPColor cpcolor = CPColor.Empty;
+                       
+                       if (!is_ColorControl)
+                               cpcolor = ResPool.GetCPColor (control_color);
+                       
+                       switch (style) {
+                       case Border3DStyle.Raised:
+                               penTopLeftInner = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               break;
+                       case Border3DStyle.Sunken:
+                               penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               penTopLeftInner = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               break;
+                       case Border3DStyle.Etched:
+                               penTopLeft = penBottomRightInner = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               break;
+                       case Border3DStyle.RaisedOuter:
+                               penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               break;
+                       case Border3DStyle.SunkenOuter:
+                               penTopLeft = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               penBottomRight = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               break;
+                       case Border3DStyle.RaisedInner:
+                               penTopLeft = is_ColorControl ? SystemPens.ControlLightLight : ResPool.GetPen (cpcolor.LightLight);
+                               penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               break;
+                       case Border3DStyle.SunkenInner:
+                               penTopLeft = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               break;
+                       case Border3DStyle.Flat:
+                               penTopLeft = penBottomRight = is_ColorControl ? SystemPens.ControlDark : ResPool.GetPen (cpcolor.Dark);
+                               break;
+                       case Border3DStyle.Bump:
+                               penTopLeftInner = penBottomRight = is_ColorControl ? SystemPens.ControlDarkDark : ResPool.GetPen (cpcolor.DarkDark);
+                               break;
+                       default:
+                               break;
                        }
-
-                       if ((state & ButtonState.Flat)!=0) {
-                               dfcs |= DrawFrameControlStates.Flat;
+                       
+                       if ((sides & Border3DSide.Middle) != 0) {
+                               Brush brush = is_ColorControl ? SystemBrushes.Control : ResPool.GetSolidBrush (control_color);
+                               graphics.FillRectangle (brush, rect);
                        }
-
-                       if ((state & ButtonState.Inactive)!=0) {
-                               dfcs |= DrawFrameControlStates.Inactive;
+                       
+                       if ((sides & Border3DSide.Left) != 0) {
+                               graphics.DrawLine (penTopLeft, rect.Left, rect.Bottom - 2, rect.Left, rect.Top);
+                               graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Bottom - 2, rect.Left + 1, rect.Top);
+                       }
+                       
+                       if ((sides & Border3DSide.Top) != 0) {
+                               graphics.DrawLine (penTopLeft, rect.Left, rect.Top, rect.Right - 2, rect.Top);
+                               graphics.DrawLine (penTopLeftInner, rect.Left + 1, rect.Top + 1, rect.Right - 3, rect.Top + 1);
+                       }
+                       
+                       if ((sides & Border3DSide.Right) != 0) {
+                               graphics.DrawLine (penBottomRight, rect.Right - 1, rect.Top, rect.Right - 1, rect.Bottom - 1);
+                               graphics.DrawLine (penBottomRightInner, rect.Right - 2, rect.Top + 1, rect.Right - 2, rect.Bottom - 2);
+                       }
+                       
+                       if ((sides & Border3DSide.Bottom) != 0) {
+                               graphics.DrawLine (penBottomRight, rect.Left, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
+                               graphics.DrawLine (penBottomRightInner, rect.Left + 1, rect.Bottom - 2, rect.Right - 2, rect.Bottom - 2);
                        }
-                       DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
                }
 
-
-               public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
-                       Rectangle       captionRect;
-                       int                     lineWidth;
-
-                       CPDrawButton(graphics, rectangle, state);
-
-                       if (rectangle.Width<rectangle.Height) {
+               public override void CPDrawButton (Graphics dc, Rectangle rectangle, ButtonState state)
+               {
+                       // sadly enough, the rectangle gets always filled with a hatchbrush
+                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2);
+                       
+                       if ((state & ButtonState.All) == ButtonState.All || ((state & ButtonState.Checked) == ButtonState.Checked && (state & ButtonState.Flat) == ButtonState.Flat)) {
+                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
+                               
+                               dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
+                       } else
+                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                               dc.DrawRectangle (SystemPens.ControlDark, rectangle.X, rectangle.Y, rectangle.Width - 1, rectangle.Height - 1);
+                       } else
+                       if ((state & ButtonState.Checked) == ButtonState.Checked) {
+                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorControlLight, ColorControl), rectangle.X + 2, rectangle.Y + 2, rectangle.Width - 4, rectangle.Height - 4);
+                               
+                               Pen pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
+                               dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
+                               
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
+                               dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
+                               
+                               pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
+                               dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
+                       } else
+                       if (((state & ButtonState.Pushed) == ButtonState.Pushed) && ((state & ButtonState.Normal) == ButtonState.Normal)) {
+                               Pen pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
+                               dc.DrawLine (pen, rectangle.X + 1, rectangle.Y, rectangle.Right - 2, rectangle.Y);
+                               
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, rectangle.X + 1, rectangle.Y + 1, rectangle.X + 1, rectangle.Bottom - 3);
+                               dc.DrawLine (pen, rectangle.X + 2, rectangle.Y + 1, rectangle.Right - 3, rectangle.Y + 1);
+                               
+                               pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 2, rectangle.Bottom - 1);
+                               dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 1);
+                       } else
+                       if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Normal) == ButtonState.Normal)) {
+                               Pen pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.Right - 2, rectangle.Y);
+                               dc.DrawLine (pen, rectangle.X, rectangle.Y, rectangle.X, rectangle.Bottom - 2);
+                               
+                               pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, rectangle.X + 1, rectangle.Bottom - 2, rectangle.Right - 2, rectangle.Bottom - 2);
+                               dc.DrawLine (pen, rectangle.Right - 2, rectangle.Y + 1, rectangle.Right - 2, rectangle.Bottom - 3);
+                               
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, rectangle.X, rectangle.Bottom - 1, rectangle.Right - 1, rectangle.Bottom - 1);
+                               dc.DrawLine (pen, rectangle.Right - 1, rectangle.Y, rectangle.Right - 1, rectangle.Bottom - 2);
+                       }
+               }
+
+
+               public override void CPDrawCaptionButton (Graphics graphics, Rectangle rectangle, CaptionButton button, ButtonState state) {
+                       Rectangle       captionRect;
+                       int                     lineWidth;
+
+                       CPDrawButton(graphics, rectangle, state);
+
+                       if (rectangle.Width<rectangle.Height) {
                                captionRect=new Rectangle(rectangle.X+1, rectangle.Y+rectangle.Height/2-rectangle.Width/2+1, rectangle.Width-4, rectangle.Width-4);
                        } else {
                                captionRect=new Rectangle(rectangle.X+rectangle.Width/2-rectangle.Height/2+1, rectangle.Y+1, rectangle.Height-4, rectangle.Height-4);
@@ -4531,18 +4745,15 @@ namespace System.Windows.Forms
                                Pen     pen;
 
                                if ((state & ButtonState.Inactive)!=0) {
-                                       pen=new Pen(ColorControlLight, lineWidth);
+                                       pen = ResPool.GetSizedPen (ColorControlLight, lineWidth);
                                        DrawCaptionHelper(graphics, ColorControlLight, pen, lineWidth, 1, captionRect, button);
-                                       pen.Dispose();
 
-                                       pen=new Pen(ColorControlDark, lineWidth);
+                                       pen = ResPool.GetSizedPen (ColorControlDark, lineWidth);
                                        DrawCaptionHelper(graphics, ColorControlDark, pen, lineWidth, 0, captionRect, button);
-                                       pen.Dispose();
                                        return;
                                } else {
-                                       pen=new Pen(ColorControlText, lineWidth);
+                                       pen = ResPool.GetSizedPen (ColorControlText, lineWidth);
                                        DrawCaptionHelper(graphics, ColorControlText, pen, lineWidth, 0, captionRect, button);
-                                       pen.Dispose();
                                        return;
                                }
                        }
@@ -4564,28 +4775,98 @@ namespace System.Windows.Forms
                        }
                }
 
-
-               public override void CPDrawCheckBox (Graphics graphics, Rectangle rectangle, ButtonState state) {
-                       DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonCheck;
-
-                       if ((state & ButtonState.Pushed)!=0) {
-                               dfcs |= DrawFrameControlStates.Pushed;
-                       }
-
-                       if ((state & ButtonState.Checked)!=0) {
-                               dfcs |= DrawFrameControlStates.Checked;
-                       }
-
-                       if ((state & ButtonState.Flat)!=0) {
-                               dfcs |= DrawFrameControlStates.Flat;
+               public override void CPDrawCheckBox (Graphics dc, Rectangle rectangle, ButtonState state)
+               {
+                       Pen check_pen = SystemPens.ControlDarkDark;
+                       
+                       Rectangle cb_rect = new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
+                       
+                       if ((state & ButtonState.All) == ButtonState.All) {
+                               cb_rect.Width -= 2;
+                               cb_rect.Height -= 2;
+                               
+                               dc.FillRectangle (SystemBrushes.Control, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+                               dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+                               
+                               check_pen = SystemPens.ControlDark;
+                       } else
+                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                               cb_rect.Width -= 2;
+                               cb_rect.Height -= 2;
+                               
+                               dc.FillRectangle (SystemBrushes.ControlLight, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+                               dc.DrawRectangle (SystemPens.ControlDark, cb_rect.X, cb_rect.Y, cb_rect.Width - 1, cb_rect.Height - 1);
+                       } else {
+                               cb_rect.Width -= 1;
+                               cb_rect.Height -= 1;
+                               
+                               int check_box_visible_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width : cb_rect.Height;
+                               
+                               int x_pos = Math.Max (0, cb_rect.X + (cb_rect.Width / 2) - check_box_visible_size / 2);
+                               int y_pos = Math.Max (0, cb_rect.Y + (cb_rect.Height / 2) - check_box_visible_size / 2);
+                               
+                               Rectangle rect = new Rectangle (x_pos, y_pos, check_box_visible_size, check_box_visible_size);
+                               
+                               if (((state & ButtonState.Pushed) == ButtonState.Pushed) || ((state & ButtonState.Inactive) == ButtonState.Inactive)) {
+                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
+                               } else
+                                       dc.FillRectangle (SystemBrushes.ControlLightLight, rect.X + 2, rect.Y + 2, rect.Width - 3, rect.Height - 3);
+                               
+                               Pen pen = SystemPens.ControlDark;
+                               dc.DrawLine (pen, rect.X, rect.Y, rect.X, rect.Bottom - 1);
+                               dc.DrawLine (pen, rect.X + 1, rect.Y, rect.Right - 1, rect.Y);
+                               
+                               pen = SystemPens.ControlDarkDark;
+                               dc.DrawLine (pen, rect.X + 1, rect.Y + 1, rect.X + 1, rect.Bottom - 2);
+                               dc.DrawLine (pen, rect.X + 2, rect.Y + 1, rect.Right - 2, rect.Y + 1);
+                               
+                               pen = SystemPens.ControlLight;
+                               dc.DrawLine (pen, rect.Right, rect.Y, rect.Right, rect.Bottom);
+                               dc.DrawLine (pen, rect.X, rect.Bottom, rect.Right, rect.Bottom);
+                               
+                               // oh boy, matching ms is like fighting against windmills
+                               using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl))) {
+                                       dc.DrawLine (h_pen, rect.X + 1, rect.Bottom - 1, rect.Right - 1, rect.Bottom - 1);
+                                       dc.DrawLine (h_pen, rect.Right - 1, rect.Y + 1, rect.Right - 1, rect.Bottom - 1);
+                               }
+                               
+                               if ((state & ButtonState.Inactive) == ButtonState.Inactive)
+                                       check_pen = SystemPens.ControlDark;
                        }
-
-                       if ((state & ButtonState.Inactive)!=0) {
-                               dfcs |= DrawFrameControlStates.Inactive;
+                       
+                       if ((state & ButtonState.Checked) == ButtonState.Checked) {
+                               int check_size = (cb_rect.Height > cb_rect.Width) ? cb_rect.Width / 2: cb_rect.Height / 2;
+                               
+                               if (check_size < 7) {
+                                       int lineWidth = Math.Max (3, check_size / 3);
+                                       int Scale = Math.Max (1, check_size / 9);
+                                       
+                                       Rectangle rect = new Rectangle (cb_rect.X + (cb_rect.Width / 2) - (check_size / 2) - 1, cb_rect.Y + (cb_rect.Height / 2) - (check_size / 2) - 1, 
+                                                                       check_size, check_size);
+                                       
+                                       for (int i = 0; i < lineWidth; i++) {
+                                               dc.DrawLine (check_pen, rect.Left + lineWidth / 2, rect.Top + lineWidth + i, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i);
+                                               dc.DrawLine (check_pen, rect.Left + lineWidth / 2 + 2 * Scale, rect.Top + lineWidth + 2 * Scale + i, rect.Left + lineWidth / 2 + 6 * Scale, rect.Top + lineWidth - 2 * Scale + i);
+                                       }
+                               } else {
+                                       int lineWidth = Math.Max (3, check_size / 3) + 1;
+                                       
+                                       int x_half = cb_rect.Width / 2;
+                                       int y_half = cb_rect.Height / 2;
+                                       
+                                       Rectangle rect = new Rectangle (cb_rect.X + x_half - (check_size / 2) - 1, cb_rect.Y + y_half - (check_size / 2), 
+                                                                       check_size, check_size);
+                                       
+                                       int gradient_left = check_size / 3;
+                                       int gradient_right = check_size - gradient_left - 1;
+                                       
+                                       
+                                       for (int i = 0; i < lineWidth; i++) {
+                                               dc.DrawLine (check_pen, rect.X, rect.Bottom - 1 - gradient_left - i, rect.X + gradient_left, rect.Bottom - 1 - i);
+                                               dc.DrawLine (check_pen, rect.X + gradient_left, rect.Bottom - 1 - i, rect.Right - 1, rect.Bottom - i  - 1 - gradient_right);
+                                       }
+                               }
                        }
-
-                       DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
-
                }
 
                public override void CPDrawComboButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
@@ -4610,7 +4891,7 @@ namespace System.Windows.Forms
                                        // this needs to render like a pushed button - jba
                                        // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
                                        Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
-                                       graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
+                                       graphics.DrawRectangle (SystemPens.ControlDark, trace_rectangle);
                                } else {
                                        CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
                                }
@@ -4636,21 +4917,20 @@ namespace System.Windows.Forms
                        arrow[0]=P1;
                        arrow[1]=P2;
                        arrow[2]=P3;
-
+                       
                        /* Draw the arrow */
                        if ((state & ButtonState.Inactive)!=0) {
-                               graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
-
                                /* Move away from the shadow */
-                               P1.X-=1;                P1.Y-=1;
-                               P2.X-=1;                P2.Y-=1;
-                               P3.X-=1;                P3.Y-=1;
+                               arrow[0].X += 1;        arrow[0].Y += 1;
+                               arrow[1].X += 1;        arrow[1].Y += 1;
+                               arrow[2].X += 1;        arrow[2].Y += 1;
+                               
+                               graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
 
                                arrow[0]=P1;
                                arrow[1]=P2;
                                arrow[2]=P3;
 
-
                                graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
                        } else {
                                graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
@@ -4658,32 +4938,30 @@ namespace System.Windows.Forms
                }
 
 
-               public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds) {
-                       
-                       Pen                     pen     = new Pen(Color.Black, 1);
-                       Rectangle       rect    = new Rectangle(bounds.X, bounds.Y, bounds.Width-1, bounds.Height-1);   // Dunno why, but MS does it that way, too
+               public override void CPDrawContainerGrabHandle (Graphics graphics, Rectangle bounds)
+               {
+                       Pen                     pen     = Pens.Black;
+                       Rectangle       rect    = new Rectangle (bounds.X, bounds.Y, bounds.Width - 1, bounds.Height - 1);      // Dunno why, but MS does it that way, too
                        int                     X;
                        int                     Y;
-
-                       graphics.FillRectangle(ResPool.GetSolidBrush (ColorControlText), rect);
-                       graphics.DrawRectangle(pen, rect);
-
-                       X=rect.X+rect.Width/2;
-                       Y=rect.Y+rect.Height/2;
-
+                       
+                       graphics.FillRectangle (SystemBrushes.ControlLightLight, rect);
+                       graphics.DrawRectangle (pen, rect);
+                       
+                       X = rect.X + rect.Width / 2;
+                       Y = rect.Y + rect.Height / 2;
+                       
                        /* Draw the cross */
-                       graphics.DrawLine(pen, X, rect.Y+2, X, rect.Bottom-2);
-                       graphics.DrawLine(pen, rect.X+2, Y, rect.Right-2, Y);
-
+                       graphics.DrawLine (pen, X, rect.Y + 2, X, rect.Bottom - 2);
+                       graphics.DrawLine (pen, rect.X + 2, Y, rect.Right - 2, Y);
+                       
                        /* Draw 'arrows' for vertical lines */
-                       graphics.DrawLine(pen, X-1, rect.Y+3, X+1, rect.Y+3);
-                       graphics.DrawLine(pen, X-1, rect.Bottom-3, X+1, rect.Bottom-3);
-
+                       graphics.DrawLine (pen, X - 1, rect.Y + 3, X + 1, rect.Y + 3);
+                       graphics.DrawLine (pen, X - 1, rect.Bottom - 3, X + 1, rect.Bottom - 3);
+                       
                        /* Draw 'arrows' for horizontal lines */
-                       graphics.DrawLine(pen, rect.X+3, Y-1, rect.X+3, Y+1);
-                       graphics.DrawLine(pen, rect.Right-3, Y-1, rect.Right-3, Y+1);
-                       pen.Dispose ();
-
+                       graphics.DrawLine (pen, rect.X + 3, Y - 1, rect.X + 3, Y + 1);
+                       graphics.DrawLine (pen, rect.Right - 3, Y - 1, rect.Right - 3, Y + 1);
                }
 
                public virtual void DrawFlatStyleFocusRectangle (Graphics graphics, Rectangle rectangle, ButtonBase button, Color foreColor, Color backColor) {
@@ -4693,7 +4971,7 @@ namespace System.Windows.Forms
                        Color outerColor = foreColor;
                        // adjust focus color according to the flatstyle
                        if (button.FlatStyle == FlatStyle.Popup && !button.is_pressed) {
-                               outerColor = (backColor == ColorControl) ? ControlPaint.Dark(ColorControl) : ColorControlText;                          
+                               outerColor = (backColor.ToArgb () == ColorControl.ToArgb ()) ? ControlPaint.Dark(ColorControl) : ColorControlText;                              
                        }
                        
                        // draw the outer rectangle
@@ -4755,28 +5033,28 @@ namespace System.Windows.Forms
                        pen.Dispose ();
                }
                
-               public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
-                       SolidBrush      sb;
-                       Pen                     pen;
-
-                       if (primary==true) {
-                               pen=new Pen(Color.Black, 1);
-                               if (enabled==true) {
-                                       sb=ResPool.GetSolidBrush (ColorControlText);
+               public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled)
+               {
+                       Brush   sb;
+                       Pen pen;
+                       
+                       if (primary == true) {
+                               pen = Pens.Black;
+                               if (enabled == true) {
+                                       sb = Brushes.White;
                                } else {
-                                       sb=ResPool.GetSolidBrush (ColorControl);
+                                       sb = SystemBrushes.Control;
                                }
                        } else {
-                               pen=new Pen(Color.White, 1);
-                               if (enabled==true) {
-                                       sb=ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black);
+                               pen = Pens.White;
+                               if (enabled == true) {
+                                       sb = Brushes.Black;
                                } else {
-                                       sb=ResPool.GetSolidBrush (ColorControl);
+                                       sb = SystemBrushes.Control;
                                }
                        }
-                       graphics.FillRectangle(sb, rectangle);
-                       graphics.DrawRectangle(pen, rectangle);                 
-                       pen.Dispose();
+                       graphics.FillRectangle (sb, rectangle);
+                       graphics.DrawRectangle (pen, rectangle);                        
                }
 
 
@@ -4787,49 +5065,21 @@ namespace System.Windows.Forms
                        int     s;
 
                        ControlPaint.Color2HBS(backColor, out h, out b, out s);
-
+                       
                        if (b>127) {
                                foreColor=Color.Black;
                        } else {
                                foreColor=Color.White;
                        }
 
-#if false
-                       /* Commented out until I take the time and figure out
-                               which HatchStyle will match requirements. The code below
-                               is only correct for Percent50.
-                       */
-                       if (pixelsBetweenDots.Width==pixelsBetweenDots.Height) {
-                               HatchBrush      brush=null;
-
-                               switch(pixelsBetweenDots.Width) {
-                                       case 2: brush=new HatchBrush(HatchStyle.Percent50, foreColor, backColor); break;
-                                       case 4: brush=new HatchBrush(HatchStyle.Percent25, foreColor, backColor); break;
-                                       case 5: brush=new HatchBrush(HatchStyle.Percent20, foreColor, backColor); break;
-                                       default: {
-                                               /* Have to do it the slow way */
-                                               break;
-                                       }
-                               }
-                               if (brush!=null) {
-                                       graphics.FillRectangle(brush, area);
-                                       pen.Dispose();
-                                       brush.Dispose();
-                                       return;
-                               }
-                       }
-#endif
-                       /* Slow method */
-
-                       Bitmap bitmap = new Bitmap(area.Width, area.Height, graphics);
+                       // still not perfect. it seems that ms calculates the position of the first dot or line
 
-                       for (int x=0; x<area.Width; x+=pixelsBetweenDots.Width) {
-                               for (int y=0; y<area.Height; y+=pixelsBetweenDots.Height) {
-                                       bitmap.SetPixel(x, y, foreColor);
-                               }
+                       using (Pen pen = new Pen (foreColor)) {
+                               pen.DashPattern = new float [] {1.0f, pixelsBetweenDots.Width - 1};
+                               
+                               for (int y = area.Top; y < area.Bottom; y += pixelsBetweenDots.Height)
+                                       graphics.DrawLine (pen, area.X, y, area.Right - 1, y);
                        }
-                       graphics.DrawImage(bitmap, area.X, area.Y, area.Width, area.Height);
-                       bitmap.Dispose();
                }
 
                public override void CPDrawImageDisabled (Graphics graphics, Image image, int x, int y, Color background) {
@@ -4873,28 +5123,25 @@ namespace System.Windows.Forms
                        Pen     penInside;
 
                        if (primary) {
-                               penBorder=new Pen(Color.White, 2);
-                               penInside=new Pen(Color.Black, 1);
+                               penBorder = ResPool.GetSizedPen (Color.White, 2);
+                               penInside = ResPool.GetPen (Color.Black);
                        } else {
-                               penBorder=new Pen(Color.Black, 2);
-                               penInside=new Pen(Color.White, 1);
+                               penBorder = ResPool.GetSizedPen (Color.Black, 2);
+                               penInside = ResPool.GetPen (Color.White);
                        }
                        penBorder.Alignment=PenAlignment.Inset;
                        penInside.Alignment=PenAlignment.Inset;
 
                        graphics.DrawRectangle(penBorder, rectangle);
                        graphics.DrawRectangle(penInside, rectangle.X+2, rectangle.Y+2, rectangle.Width-5, rectangle.Height-5);
-                       penBorder.Dispose();
-                       penInside.Dispose();
                }
 
 
-               public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph) {
+               public override void CPDrawMenuGlyph (Graphics graphics, Rectangle rectangle, MenuGlyph glyph, Color color) {
                        Rectangle       rect;
                        int                     lineWidth;
 
-                       // MS draws always the background white
-                       graphics.FillRectangle(ResPool.GetSolidBrush (Color.White), rectangle);
+                       Brush brush = ResPool.GetSolidBrush (color);
 
                        switch(glyph) {
                        case MenuGlyph.Arrow: {
@@ -4914,7 +5161,7 @@ namespace System.Windows.Forms
                                rect.X-=shiftX;
                                centerX-=shiftX;
 
-                               P1=new Point(centerX, rect.Top-1);
+                               P1=new Point(centerX, rect.Top);
                                P2=new Point(centerX, rect.Bottom);
                                P3=new Point(rect.Right, centerY);
 
@@ -4922,7 +5169,7 @@ namespace System.Windows.Forms
                                arrow[1]=P2;
                                arrow[2]=P3;
 
-                               graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
+                               graphics.FillPolygon(brush, arrow, FillMode.Winding);
 
                                return;
                        }
@@ -4932,13 +5179,14 @@ namespace System.Windows.Forms
                                lineWidth=Math.Max(2, rectangle.Width/3);
                                rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
                                
-                               graphics.FillEllipse(ResPool.GetSolidBrush (ColorControlText), rect);
+                               graphics.FillEllipse(brush, rect);
                                
                                return;
                        }
 
                        case MenuGlyph.Checkmark: {
                                int                     Scale;
+                               Pen pen = ResPool.GetPen (color);
 
                                lineWidth=Math.Max(2, rectangle.Width/6);
                                Scale=Math.Max(1, rectangle.Width/12);
@@ -4946,8 +5194,8 @@ namespace System.Windows.Forms
                                rect=new Rectangle(rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2);
 
                                for (int i=0; i<lineWidth; i++) {
-                                       graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
-                                       graphics.DrawLine(SystemPens.MenuText, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
+                                       graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
+                                       graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
                                }
                                return;
                        }
@@ -4955,29 +5203,82 @@ namespace System.Windows.Forms
 
                }
 
-               public override void CPDrawRadioButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
-                       DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonRadio;
-
-                       if ((state & ButtonState.Pushed)!=0) {
-                               dfcs |= DrawFrameControlStates.Pushed;
-                       }
-
-                       if ((state & ButtonState.Checked)!=0) {
-                               dfcs |= DrawFrameControlStates.Checked;
-                       }
-
-                       if ((state & ButtonState.Flat)!=0) {
-                               dfcs |= DrawFrameControlStates.Flat;
+               public override void CPDrawRadioButton (Graphics dc, Rectangle rectangle, ButtonState state)
+               {
+                       CPColor cpcolor = ResPool.GetCPColor (ColorControl);
+                       
+                       Color dot_color = Color.Black;
+                       
+                       Color top_left_outer = Color.Black;
+                       Color top_left_inner = Color.Black;
+                       Color bottom_right_outer = Color.Black;
+                       Color bottom_right_inner = Color.Black;
+                       
+                       int ellipse_diameter = (rectangle.Width > rectangle.Height) ? (int)(rectangle.Height  * 0.9f) : (int)(rectangle.Width * 0.9f);
+                       int radius = ellipse_diameter / 2;
+                       
+                       Rectangle rb_rect = new Rectangle (rectangle.X + (rectangle.Width / 2) - radius, rectangle.Y + (rectangle.Height / 2) - radius, ellipse_diameter, ellipse_diameter);
+                       
+                       Brush brush = null;
+                       
+                       if ((state & ButtonState.All) == ButtonState.All) {
+                               brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
+                               dot_color = cpcolor.Dark;
+                       } else
+                       if ((state & ButtonState.Flat) == ButtonState.Flat) {
+                               if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
+                                       brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
+                               else
+                                       brush = SystemBrushes.ControlLightLight;
+                       } else {
+                               if (((state & ButtonState.Inactive) == ButtonState.Inactive) || ((state & ButtonState.Pushed) == ButtonState.Pushed))
+                                       brush = ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl);
+                               else
+                                       brush = SystemBrushes.ControlLightLight;
+                               
+                               top_left_outer = cpcolor.Dark;
+                               top_left_inner = cpcolor.DarkDark;
+                               bottom_right_outer = cpcolor.Light;
+                               bottom_right_inner = Color.Transparent;
+                               
+                               if ((state & ButtonState.Inactive) == ButtonState.Inactive)
+                                       dot_color = cpcolor.Dark;
                        }
-
-                       if ((state & ButtonState.Inactive)!=0) {
-                               dfcs |= DrawFrameControlStates.Inactive;
+                       
+                       dc.FillEllipse (brush, rb_rect.X + 1, rb_rect.Y + 1, ellipse_diameter - 1, ellipse_diameter - 1);
+                       
+                       int line_width = Math.Max (1, (int)(ellipse_diameter * 0.08f));
+                       
+                       dc.DrawArc (ResPool.GetSizedPen (top_left_outer, line_width), rb_rect, 135.0f, 180.0f);
+                       dc.DrawArc (ResPool.GetSizedPen (top_left_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 135.0f, 180.0f);
+                       dc.DrawArc (ResPool.GetSizedPen (bottom_right_outer, line_width), rb_rect, 315.0f, 180.0f);
+                       
+                       if (bottom_right_inner != Color.Transparent)
+                               dc.DrawArc (ResPool.GetSizedPen (bottom_right_inner, line_width), Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
+                       else
+                               using (Pen h_pen = new Pen (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (ColorControl.R + 3, ColorControl.G, ColorControl.B), ColorControl), line_width)) {
+                                       dc.DrawArc (h_pen, Rectangle.Inflate (rb_rect, -line_width, -line_width), 315.0f, 180.0f);
+                               }
+                       
+                       if ((state & ButtonState.Checked) == ButtonState.Checked) {
+                               int inflate = line_width * 4;
+                               Rectangle tmp = Rectangle.Inflate (rb_rect, -inflate, -inflate);
+                               if (rectangle.Height >  13) {
+                                       tmp.X += 1;
+                                       tmp.Y += 1;
+                                       tmp.Height -= 1;
+                                       dc.FillEllipse (ResPool.GetSolidBrush (dot_color), tmp);
+                               } else {
+                                       Pen pen = ResPool.GetPen (dot_color);
+                                       dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2), tmp.Right, tmp.Y + (tmp.Height / 2));
+                                       dc.DrawLine (pen, tmp.X, tmp.Y + (tmp.Height / 2) + 1, tmp.Right, tmp.Y + (tmp.Height / 2) + 1);
+                                       
+                                       dc.DrawLine (pen, tmp.X + (tmp.Width / 2), tmp.Y, tmp.X + (tmp.Width / 2), tmp.Bottom);
+                                       dc.DrawLine (pen, tmp.X + (tmp.Width / 2) + 1, tmp.Y, tmp.X + (tmp.Width / 2) + 1, tmp.Bottom);
+                               }
                        }
-                       DrawFrameControl(graphics, rectangle, DrawFrameControlTypes.Button, dfcs);
-
                }
 
-
                public override void CPDrawReversibleFrame (Rectangle rectangle, Color backColor, FrameStyle style) {
 
                }
@@ -4989,157 +5290,248 @@ namespace System.Windows.Forms
 
 
                /* Scroll button: regular button + direction arrow */
-               public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
-                       bool enabled = (state == ButtonState.Inactive) ? false: true;                   
-                                       
+               public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state)
+               {
                        DrawScrollButtonPrimitive (dc, area, state);
-                                               
-                       if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
-                               return;
-
-                       /* Paint arrows */
+                       
+                       bool fill_rect = true;
+                       int offset = 0;
+                       
+                       if ((state & ButtonState.Pushed) != 0)
+                               offset = 1;
+                       
+                       // skip the border
+                       Rectangle rect = new Rectangle (area.X + 2 + offset, area.Y + 2 + offset, area.Width - 4, area.Height - 4);
+                       
+                       Point [] arrow = new Point [3];
+                       for (int i = 0; i < 3; i++)
+                               arrow [i] = new Point ();
+                       
+                       Pen pen = SystemPens.ControlText;
+                       
+                       if ((state & ButtonState.Inactive) != 0) {
+                               pen = SystemPens.ControlDark;
+                       }
+                       
                        switch (type) {
-                       case ScrollButton.Up: {
-                               int x = area.X +  (area.Width / 2) - 4;
-                               int y = area.Y + 9;
-
-                               for (int i = 0; i < 3; i++)
-                                       if (enabled)
-                                               dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y - i, x + i + 6 - 2*i, y - i);
-                                       else
-                                               dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y - i, x + i + 6 - 2*i, y - i);
-
-                               
-                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
-                                       x + 3, area.Y + 6, 1, 1);
+                               default:
+                               case ScrollButton.Down:
+                                       int x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
+                                       int y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
+                                       if (x_middle == 1)
+                                               x_middle = 2;
                                        
-                               break;
-                       }
-                       case ScrollButton.Down: {
-                               int x = area.X +  (area.Width / 2) - 5;
-                               int y = area.Y + 5;
-
-                               for (int i = 4; i != 0; i--)
-                                       if (enabled)
-                                               dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i + 8 - 2*i, y + i);
-                                       else
-                                               dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i + 8 - 2*i, y + i);
-
-                               
-                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
-                                       x + 4, y + 4, 1, 1);
-                               break;
-                       }
-
-                       case ScrollButton.Left: {
-                               int y = area.Y +  (area.Height / 2) - 4;
-                               int x = area.X + 9;
-
-                               for (int i = 0; i < 3; i++)
-                                       if (enabled)
-                                               dc.DrawLine (ResPool.GetPen (arrow_color), x - i, y + i, x - i, y + i + 6 - 2*i);
-                                       else
-                                               dc.DrawLine (ResPool.GetPen (ColorGrayText), x - i, y + i, x - i, y + i + 6 - 2*i);
-
-                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
-                                       x - 3, y + 3, 1, 1);
-                               break;
-                       }
-
-                       case ScrollButton.Right: {
-                               int y = area.Y +  (area.Height / 2) - 5;
-                               int x = area.X + 5;
-
-                               for (int i = 4; i != 0; i--)
-                                       if (enabled)
-                                               dc.DrawLine (ResPool.GetPen (arrow_color), x + i, y + i, x + i, y + i + 8 - 2*i);
-                                       else
-                                               dc.DrawLine (ResPool.GetPen (ColorGrayText), x + i, y + i, x + i, y + i + 8 - 2*i);
-
-                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
-                                       x + 4, y + 4, 1, 1);
-                               break;
-                       }
-
-                       default:
-                               break;
-
+                                       int triangle_height;
+                                       
+                                       if (rect.Height < 8) {
+                                               triangle_height = 2;
+                                               fill_rect = false;
+                                       } else if (rect.Height == 11) {
+                                               triangle_height = 3;
+                                       } else {
+                                               triangle_height = (int)Math.Round (rect.Height / 3.0f);
+                                       }
+                                       
+                                       arrow [0].X = rect.X + x_middle;
+                                       arrow [0].Y = rect.Y + y_middle + triangle_height / 2;
+                                       
+                                       arrow [1].X = arrow [0].X + triangle_height - 1;
+                                       arrow [1].Y = arrow [0].Y - triangle_height + 1;
+                                       arrow [2].X = arrow [0].X - triangle_height + 1;
+                                       arrow [2].Y = arrow [1].Y;
+                                       
+                                       dc.DrawPolygon (pen, arrow);
+                                       
+                                       if ((state & ButtonState.Inactive) != 0) {
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y + 1);
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X, arrow [1].Y + 1, arrow [0].X + 1, arrow [0].Y);
+                                       }
+                                       
+                                       if (fill_rect) {
+                                               for (int i = 0; i < arrow [0].Y - arrow [1].Y; i++) {
+                                                       dc.DrawLine (pen, arrow [1].X, arrow [1].Y + i, arrow [2].X, arrow [1].Y + i);
+                                                       arrow [1].X -= 1;
+                                                       arrow [2].X += 1;
+                                               }
+                                       }
+                                       break;
+                                       
+                               case ScrollButton.Up:
+                                       x_middle = (int)Math.Round (rect.Width / 2.0f) - 1;
+                                       y_middle = (int)Math.Round (rect.Height / 2.0f);
+                                       if (x_middle == 1)
+                                               x_middle = 2;
+                                       
+                                       if (y_middle == 1)
+                                               y_middle = 2;
+                                       
+                                       if (rect.Height < 8) {
+                                               triangle_height = 2;
+                                               fill_rect = false;
+                                       } else if (rect.Height == 11) {
+                                               triangle_height = 3;
+                                       } else {
+                                               triangle_height = (int)Math.Round (rect.Height / 3.0f);
+                                       }
+                                       
+                                       arrow [0].X = rect.X + x_middle;
+                                       arrow [0].Y = rect.Y + y_middle - triangle_height / 2;
+                                       
+                                       arrow [1].X = arrow [0].X + triangle_height - 1;
+                                       arrow [1].Y = arrow [0].Y + triangle_height - 1;
+                                       arrow [2].X = arrow [0].X - triangle_height + 1;
+                                       arrow [2].Y = arrow [1].Y;
+                                       
+                                       dc.DrawPolygon (pen, arrow);
+                                       
+                                       if ((state & ButtonState.Inactive) != 0) {
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [1].Y + 1);
+                                       }
+                                       
+                                       if (fill_rect) {
+                                               for (int i = 0; i < arrow [1].Y - arrow [0].Y; i++) {
+                                                       dc.DrawLine (pen, arrow [2].X, arrow [1].Y - i, arrow [1].X, arrow [1].Y - i);
+                                                       arrow [1].X -= 1;
+                                                       arrow [2].X += 1;
+                                               }
+                                       }
+                                       break;
+                                       
+                               case ScrollButton.Left:
+                                       y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
+                                       if (y_middle == 1)
+                                               y_middle = 2;
+                                       
+                                       int triangle_width;
+                                       
+                                       if (rect.Width < 8) {
+                                               triangle_width = 2;
+                                               fill_rect = false;
+                                       } else if (rect.Width == 11) {
+                                               triangle_width = 3;
+                                       } else {
+                                               triangle_width = (int)Math.Round (rect.Width / 3.0f);
+                                       }
+                                       
+                                       arrow [0].X = rect.Left + triangle_width - 1;
+                                       arrow [0].Y = rect.Y + y_middle;
+                                       
+                                       if (arrow [0].X - 1 == rect.X)
+                                               arrow [0].X += 1;
+                                       
+                                       arrow [1].X = arrow [0].X + triangle_width - 1;
+                                       arrow [1].Y = arrow [0].Y - triangle_width + 1;
+                                       arrow [2].X = arrow [1].X;
+                                       arrow [2].Y = arrow [0].Y + triangle_width - 1;
+                                       
+                                       dc.DrawPolygon (pen, arrow);
+                                       
+                                       if ((state & ButtonState.Inactive) != 0) {
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [1].X + 1, arrow [1].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
+                                       }
+                                       
+                                       if (fill_rect) {
+                                               for (int i = 0; i < arrow [2].X - arrow [0].X; i++) {
+                                                       dc.DrawLine (pen, arrow [2].X - i, arrow [1].Y, arrow [2].X - i, arrow [2].Y);
+                                                       arrow [1].Y += 1;
+                                                       arrow [2].Y -= 1;
+                                               }
+                                       }
+                                       break;
+                                       
+                               case ScrollButton.Right:
+                                       y_middle = (int)Math.Round (rect.Height / 2.0f) - 1;
+                                       if (y_middle == 1)
+                                               y_middle = 2;
+                                       
+                                       if (rect.Width < 8) {
+                                               triangle_width = 2;
+                                               fill_rect = false;
+                                       } else if (rect.Width == 11) {
+                                               triangle_width = 3;
+                                       } else {
+                                               triangle_width = (int)Math.Round (rect.Width / 3.0f);
+                                       }
+                                       
+                                       arrow [0].X = rect.Right - triangle_width - 1;
+                                       arrow [0].Y = rect.Y + y_middle;
+                                       
+                                       if (arrow [0].X - 1 == rect.X)
+                                               arrow [0].X += 1;
+                                       
+                                       arrow [1].X = arrow [0].X - triangle_width + 1;
+                                       arrow [1].Y = arrow [0].Y - triangle_width + 1;
+                                       arrow [2].X = arrow [1].X;
+                                       arrow [2].Y = arrow [0].Y + triangle_width - 1;
+                                       
+                                       dc.DrawPolygon (pen, arrow);
+                                       
+                                       if ((state & ButtonState.Inactive) != 0) {
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X + 1, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y + 1);
+                                               dc.DrawLine (SystemPens.ControlLightLight, arrow [0].X, arrow [0].Y + 1, arrow [2].X + 1, arrow [2].Y);
+                                       }
+                                       
+                                       if (fill_rect) {
+                                               for (int i = 0; i < arrow [0].X - arrow [1].X; i++) {
+                                                       dc.DrawLine (pen, arrow [2].X + i, arrow [1].Y, arrow [2].X + i, arrow [2].Y);
+                                                       arrow [1].Y += 1;
+                                                       arrow [2].Y -= 1;
+                                               }
+                                       }
+                                       break;
                        }
                }
 
-
                public  override void CPDrawSelectionFrame (Graphics graphics, bool active, Rectangle outsideRect, Rectangle insideRect,
                        Color backColor) {
 
                }
 
 
-               public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
-                       Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
-
-                       dc.DrawLine (ResPool.GetPen (ColorControl), pt.X - 12, pt.Y, pt.X, pt.Y);
-                       dc.DrawLine (ResPool.GetPen (ColorControl), pt.X, pt.Y, pt.X, pt.Y - 13);
-
-                       // diagonals
-                       for (int i = 0; i < 11; i += 4) {
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 2);
-                               dc.DrawLine (ResPool.GetPen (ColorControlDark), pt.X - i - 1, pt.Y, pt.X + 1, pt.Y - i - 2);
+               public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds)
+               {
+                       Pen pen_dark = ResPool.GetPen(ControlPaint.Dark(backColor));
+                       Pen pen_light_light = ResPool.GetPen(ControlPaint.LightLight(backColor));
+                       
+                       for (int i = 2; i < bounds.Width - 2; i += 4) {
+                               dc.DrawLine (pen_light_light, bounds.X + i, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i - 1);
+                               dc.DrawLine (pen_dark, bounds.X + i + 1, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i);
+                               dc.DrawLine (pen_dark, bounds.X + i + 2, bounds.Bottom - 2, bounds.Right - 1, bounds.Y + i + 1);
                        }
-
-                       for (int i = 3; i < 13; i += 4)
-                               dc.DrawLine (ResPool.GetPen (ColorControlLight), pt.X - i, pt.Y, pt.X + 1, pt.Y - i - 1);
                }
 
-
-               public  override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
-                       StringFormat format) {                  
-
-                       layoutRectangle.Offset(1.0f, 1.0f);
-                       graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 95)), layoutRectangle, format);                   
-                       layoutRectangle.Offset(-1.0f, -1.0f);
-                       graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 50)), layoutRectangle, format);
+               public  override void CPDrawStringDisabled (Graphics dc, string s, Font font, Color color, RectangleF layoutRectangle, StringFormat format)
+               {
+                       CPColor cpcolor = ResPool.GetCPColor (color);
                        
+                       dc.DrawString (s, font, ResPool.GetSolidBrush(cpcolor.LightLight), 
+                                      new RectangleF(layoutRectangle.X + 1, layoutRectangle.Y + 1, layoutRectangle.Width, layoutRectangle.Height),
+                                      format);
+                       dc.DrawString (s, font, ResPool.GetSolidBrush (cpcolor.Dark), layoutRectangle, format);
                }
 
                private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
                        int width, Color color, ButtonBorderStyle style, Border3DSide side) {
 
-                       Pen     pen=new Pen(color, 1);
-
-                       switch(style) {
-                       case ButtonBorderStyle.Solid: {
-                               pen.DashStyle=DashStyle.Solid;
-                               break;
-                       }
-
-                       case ButtonBorderStyle.Dashed: {
-                               pen.DashStyle=DashStyle.Dash;
-                               break;
-                       }
-
-                       case ButtonBorderStyle.Dotted: {
-                               pen.DashStyle=DashStyle.Dot;
-                               break;
-                       }
-
-                       case ButtonBorderStyle.Inset: {
-                               pen.DashStyle=DashStyle.Solid;
-                               break;
-                       }
-
-                       case ButtonBorderStyle.Outset: {
-                               pen.DashStyle=DashStyle.Solid;
-                               break;
-                       }
+                       Pen pen = null;
 
+                       switch (style) {
+                       case ButtonBorderStyle.Solid:
+                       case ButtonBorderStyle.Inset:
+                       case ButtonBorderStyle.Outset:
+                                       pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Solid);
+                                       break;
+                       case ButtonBorderStyle.Dashed:
+                                       pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dash);
+                                       break;
+                       case ButtonBorderStyle.Dotted:
+                                       pen = ThemeEngine.Current.ResPool.GetDashPen (color, DashStyle.Dot);
+                                       break;
                        default:
-                       case ButtonBorderStyle.None: {
-                               pen.Dispose();
-                               return;
-                       }
+                       case ButtonBorderStyle.None:
+                                       return;
                        }
 
-
                        switch(style) {
                        case ButtonBorderStyle.Outset: {
                                Color           colorGrade;
@@ -5159,33 +5551,29 @@ namespace System.Windows.Forms
                                for (int i=0; i<width; i++) {
                                        switch(side) {
                                        case Border3DSide.Left: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
                                                break;
                                        }
 
                                        case Border3DSide.Right: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
                                                break;
                                        }
 
                                        case Border3DSide.Top: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
                                                break;
                                        }
 
                                        case Border3DSide.Bottom: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
                                                break;
                                        }
@@ -5212,33 +5600,29 @@ namespace System.Windows.Forms
                                for (int i=0; i<width; i++) {
                                        switch(side) {
                                        case Border3DSide.Left: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY+i, endX+i, endY-i);
                                                break;
                                        }
 
                                        case Border3DSide.Right: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX-i, startY+i, endX-i, endY-i);
                                                break;
                                        }
 
                                        case Border3DSide.Top: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Max(0, brightness-brightnessDownSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY+i, endX-i, endY+i);
                                                break;
                                        }
 
                                        case Border3DSide.Bottom: {
-                                               pen.Dispose();
                                                colorGrade=ControlPaint.HBS2Color(hue, Math.Min(255, brightness+brightnessSteps*(width-i)), saturation);
-                                               pen=new Pen(colorGrade, 1);
+                                               pen = ThemeEngine.Current.ResPool.GetPen (colorGrade);
                                                graphics.DrawLine(pen, startX+i, startY-i, endX-i, endY-i);
                                                break;
                                        }
@@ -5285,7 +5669,6 @@ namespace System.Windows.Forms
                                break;
                        }
                        }
-                       pen.Dispose();
                }
 
                /*
@@ -5294,11 +5677,9 @@ namespace System.Windows.Forms
                        still look like MS's scaled caption buttons. (as opposed to scaling a bitmap)
                */
 
-               private static void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
+               private void DrawCaptionHelper(Graphics graphics, Color color, Pen pen, int lineWidth, int shift, Rectangle captionRect, CaptionButton button) {
                        switch(button) {
                        case CaptionButton.Close: {
-                               pen.StartCap=LineCap.Triangle;
-                               pen.EndCap=LineCap.Triangle;
                                if (lineWidth<2) {
                                        graphics.DrawLine(pen, captionRect.Left+2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Right-2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
                                        graphics.DrawLine(pen, captionRect.Right-2*lineWidth+1+shift, captionRect.Top+2*lineWidth+shift, captionRect.Left+2*lineWidth+1+shift, captionRect.Bottom-2*lineWidth+shift);
@@ -5317,7 +5698,7 @@ namespace System.Windows.Forms
                                sf.LineAlignment=StringAlignment.Center;
 
 
-                               graphics.DrawString("?", font, ThemeEngine.Current.ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
+                               graphics.DrawString("?", font, ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
 
                                sf.Dispose();                           
                                font.Dispose();
@@ -5405,157 +5786,43 @@ namespace System.Windows.Forms
                        }
                }
 
-               [MonoTODO("Finish drawing code for Caption, Menu and Scroll")]
-               private void DrawFrameControl(Graphics graphics, Rectangle rectangle, DrawFrameControlTypes Type, DrawFrameControlStates State) {
-                       // make a rectange to trace around border of the button
-                       Rectangle trace_rectangle = new Rectangle(rectangle.X, rectangle.Y, Math.Max (rectangle.Width-1, 0), Math.Max (rectangle.Height-1, 0));
-                       switch(Type) {
-                       case DrawFrameControlTypes.Button: {
-
-                               if ((State & DrawFrameControlStates.ButtonPush)!=0) {
-// JBA 31 oct 2004 - I don't think that button style should be rendered like this
-//                                     /* Goes first, affects the background */
-//                                     if ((State & DrawFrameControlStates.Checked)!=0) {
-//                                             HatchBrush      hatchBrush=new HatchBrush(HatchStyle.Percent50, ColorControlLightLight, ColorControlLight);
-//                                             graphics.FillRectangle(hatchBrush,rectangle);
-//                                             hatchBrush.Dispose();
-//                                     }
-
-                                       if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
-                                               graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorControl)), trace_rectangle);
-                                       } else if ((State & DrawFrameControlStates.Flat)!=0) {
-                                               ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
-                                       } else if ((State & DrawFrameControlStates.Inactive)!=0) {
-                                               /* Same as normal, it would seem */
-                                               CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                       } else {
-                                               CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                       }
-                               } else if ((State & DrawFrameControlStates.ButtonRadio)!=0) {
-                                       Pen                     penFatDark      = new Pen(ColorControlDark, 1);
-                                       Pen                     penFatLight     = new Pen(ColorControlLightLight, 1);
-                                       int                     lineWidth;
-
-                                       graphics.FillPie (ResPool.GetSolidBrush (this.ColorWindow), rectangle.X + 1, rectangle.Y + 1, rectangle.Width - 2, rectangle.Height - 2, 0, 359);
-
-                                       graphics.DrawArc(penFatDark, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 135, 180);
-                                       graphics.DrawArc(penFatLight, rectangle.X+1, rectangle.Y+1, rectangle.Width-2, rectangle.Height-2, 315, 180);
-
-                                       graphics.DrawArc(SystemPens.ControlDark, rectangle, 135, 180);
-                                       graphics.DrawArc(SystemPens.ControlLightLight, rectangle, 315, 180);
-
-                                       lineWidth=Math.Max(1, Math.Min(rectangle.Width, rectangle.Height)/3);
-
-                                       if ((State & DrawFrameControlStates.Checked)!=0) {
-                                               SolidBrush      buttonBrush;
-
-                                               if ((State & DrawFrameControlStates.Inactive)!=0) {
-                                                       buttonBrush=(SolidBrush)SystemBrushes.ControlDark;
-                                               } else {
-                                                       buttonBrush=(SolidBrush)SystemBrushes.ControlText;
-                                               }
-                                               graphics.FillPie(buttonBrush, rectangle.X+lineWidth, rectangle.Y+lineWidth, rectangle.Width-lineWidth*2, rectangle.Height-lineWidth*2, 0, 359);
-                                       }
-                                       penFatDark.Dispose();
-                                       penFatLight.Dispose();
-                               } else if ((State & DrawFrameControlStates.ButtonRadioImage)!=0) {
-                                       throw new NotImplementedException () ;
-                               } else if ((State & DrawFrameControlStates.ButtonRadioMask)!=0) {
-                                       throw new NotImplementedException ();
-                               } else {        /* Must be Checkbox */
-                                       Pen                     pen;
-                                       int                     lineWidth;
-                                       Rectangle       rect;
-                                       int                     Scale;
-
-                                       /* Goes first, affects the background */
-                                       if ((State & DrawFrameControlStates.Pushed)!=0 ||
-                                               (State & DrawFrameControlStates.Inactive)!=0) {
-                                               graphics.FillRectangle(SystemBrushes.Control, rectangle);
-                                       } else {
-                                               graphics.FillRectangle(SystemBrushes.Window, rectangle);
-                                       }
-
-                                       /* Draw the sunken frame */
-                                       if ((State & DrawFrameControlStates.Flat)!=0) {
-                                               ControlPaint.DrawBorder(graphics, rectangle, ColorControlDark, ButtonBorderStyle.Solid);
-                                       } else {
-                                               CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorControl);
-                                       }
-
-                                       /* Make sure we've got at least a line width of 1 */
-                                       lineWidth=Math.Max(3, rectangle.Width/6);
-                                       Scale=Math.Max(1, rectangle.Width/12);
-
-                                       // define a rectangle inside the border area
-                                       rect=new Rectangle(rectangle.X+2, rectangle.Y+2, rectangle.Width-4, rectangle.Height-4);
-                                       if ((State & DrawFrameControlStates.Inactive)!=0) {
-                                               pen=SystemPens.ControlDark;
-                                       } else {
-                                               pen=SystemPens.ControlText;
-                                       }
-
-                                       if ((State & DrawFrameControlStates.Checked)!=0) {
-                                               /* Need to draw a check-mark */
-                                               for (int i=0; i<lineWidth; i++) {
-                                                       graphics.DrawLine(pen, rect.Left+lineWidth/2, rect.Top+lineWidth+i, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i);
-                                                       graphics.DrawLine(pen, rect.Left+lineWidth/2+2*Scale, rect.Top+lineWidth+2*Scale+i, rect.Left+lineWidth/2+6*Scale, rect.Top+lineWidth-2*Scale+i);
-                                               }
-
-                                       }
-                               }
-                               return;
-                       }
-
-                       case DrawFrameControlTypes.Caption: {
-                               // FIXME:
-                               break;
-                       }
-
-                       case DrawFrameControlTypes.Menu: {
-                               // FIXME:
-                               break;
-                       }
-
-                       case DrawFrameControlTypes.Scroll: {
-                               // FIXME:
-                               break;
-                       }
-                       }
-               }
-
                /* Generic scroll button */
                public void DrawScrollButtonPrimitive (Graphics dc, Rectangle area, ButtonState state) {
                        if ((state & ButtonState.Pushed) == ButtonState.Pushed) {
-                               dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 1,
+                               dc.FillRectangle (SystemBrushes.Control, area.X + 1,
                                        area.Y + 1, area.Width - 2 , area.Height - 2);
 
-                               dc.DrawRectangle (ResPool.GetPen (ColorControlDark), area.X,
+                               dc.DrawRectangle (SystemPens.ControlDark, area.X,
                                        area.Y, area.Width, area.Height);
 
                                return;
                        }                       
        
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, area.Width, 1);
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X, area.Y, 1, area.Height);
+                       Brush sb_control = SystemBrushes.Control;
+                       Brush sb_lightlight = SystemBrushes.ControlLightLight;
+                       Brush sb_dark = SystemBrushes.ControlDark;
+                       Brush sb_darkdark = SystemBrushes.ControlDarkDark;
+                       
+                       dc.FillRectangle (sb_control, area.X, area.Y, area.Width, 1);
+                       dc.FillRectangle (sb_control, area.X, area.Y, 1, area.Height);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 1, area.Width - 1, 1);
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlLight), area.X + 1, area.Y + 2, 1,
+                       dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 1, area.Width - 1, 1);
+                       dc.FillRectangle (sb_lightlight, area.X + 1, area.Y + 2, 1,
                                area.Height - 4);
-
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + 1, area.Y + area.Height - 2,
+                       
+                       dc.FillRectangle (sb_dark, area.X + 1, area.Y + area.Height - 2,
                                area.Width - 2, 1);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X, area.Y + area.Height -1,
+                       dc.FillRectangle (sb_darkdark, area.X, area.Y + area.Height -1,
                                area.Width , 1);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDark), area.X + area.Width - 2,
+                       dc.FillRectangle (sb_dark, area.X + area.Width - 2,
                                area.Y + 1, 1, area.Height -3);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControlDarkDark), area.X + area.Width -1,
+                       dc.FillRectangle (sb_darkdark, area.X + area.Width -1,
                                area.Y, 1, area.Height - 1);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (ColorControl), area.X + 2,
+                       dc.FillRectangle (sb_control, area.X + 2,
                                area.Y + 2, area.Width - 4, area.Height - 4);
                        
                }