* ThemeWin32Classic.cs:
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
index 1dcb7cceef22d1412815aadd0112ca4c1f3a6e2a..f0bda348a155c115345cb4b889dc510a257b34aa 100644 (file)
@@ -24,6 +24,7 @@
 //     Peter Bartok, pbartok@novell.com
 //     John BouAntoun, jba-mono@optusnet.com.au
 //     Marek Safar, marek.safar@seznam.cz
+//     Alexander Olk, alex.olk@googlemail.com
 //
 
 
@@ -108,7 +109,7 @@ namespace System.Windows.Forms
                #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;
                        }
@@ -288,9 +289,12 @@ namespace System.Windows.Forms
                                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);
+                                       Rectangle rect_white = new Rectangle (text_rect.X + 1, text_rect.Y + 1, text_rect.Width, text_rect.Height);
+                                       
+                                       dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorControlLightLight), rect_white, button.text_format);
+                                       dc.DrawString(button.text, button.Font, ResPool.GetSolidBrush (ColorGrayText), text_rect, button.text_format);
                                }
                        }
                }
@@ -335,7 +339,7 @@ namespace System.Windows.Forms
                                } else {
                                        // popup has a ButtonColorText forecolor, not a button.ForeCOlor
                                        if (button.FlatStyle == FlatStyle.Popup) {
-                                               rect_fore_color = this.ColorControlText;
+                                               rect_fore_color = ColorGrayText;
                                        }
                                        
                                        // fill then draw outer rect
@@ -363,7 +367,7 @@ namespace System.Windows.Forms
                                bool draw_popup_checked = false;
                                
                                if (button.FlatStyle == FlatStyle.Popup) {
-                                       rect_fore_color = this.ColorControlText;
+                                       rect_fore_color = ColorGrayText;
                                
                                        // see if we should draw a disabled checked popup button
                                        draw_popup_checked = ((checkbox != null && checkbox.Checked) ||
@@ -605,6 +609,11 @@ namespace System.Windows.Forms
                        }
                        
                        /* 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)(checkbox.Font.Height * 1.5f) > text_rectangle.Height) {
+                               text_format.FormatFlags |= StringFormatFlags.NoWrap;
+                       }
                        if (checkbox.Enabled) {
                                sb = ResPool.GetSolidBrush(checkbox.ForeColor);
                                dc.DrawString(checkbox.Text, checkbox.Font, sb, text_rectangle, text_format);                   
@@ -666,7 +675,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);                           
@@ -771,7 +780,7 @@ namespace System.Windows.Forms
                #region ComboBox
                
                // Drawing
-               
+               // TODO: get rid of that and use BorderStyle Fixed3D
                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 
@@ -780,8 +789,8 @@ namespace System.Windows.Forms
                        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);                            
+                       dc.DrawLine (ResPool.GetPen (ColorControl), cl.X + cl.Width - 1, cl.Y, cl.X + cl.Width - 1, cl.Y + cl.Height); //right
+                       dc.DrawLine (ResPool.GetPen (ColorControlLight), cl.X + cl.Width - 2, cl.Y + 1 , cl.X + cl.Width - 2, cl.Y + cl.Height - 1);                            
                }               
                
                // Sizing                               
@@ -1197,7 +1206,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)) {
@@ -1258,7 +1267,7 @@ namespace System.Windows.Forms
                        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;
@@ -1389,7 +1398,7 @@ namespace System.Windows.Forms
                                back_color = e.BackColor;
                                fore_color = e.ForeColor;
                        }
-                       
+
                        e.Graphics.FillRectangle (ResPool.GetSolidBrush
                                (back_color), e.Bounds);
 
@@ -1407,31 +1416,16 @@ namespace System.Windows.Forms
 
                #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.HeaderStyle != ColumnHeaderStyle.None && 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);
-                       
+                       bool details = control.View == View.Details;
+
                        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.LastVisibleIndex; i ++) {                                      
-                                       if (clip.IntersectsWith (control.Items[i].GetBounds (ItemBoundsPortion.Entire)))
-                                               DrawListViewItem (dc, control, control.Items[i]);
-                               }                               
+                       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
@@ -1477,7 +1471,7 @@ namespace System.Windows.Forms
 
                }
                
-               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);
                                
@@ -1497,6 +1491,8 @@ namespace System.Windows.Forms
                                                this.CPDrawButton (dc, rect, state);
                                                rect.X += 3;
                                                rect.Width -= 8;
+                                               if (rect.Width <= 0)
+                                                       continue;
                                                dc.DrawString (col.Text, DefaultFont,
                                                               ResPool.GetSolidBrush (ColorControlText),
                                                               rect, col.Format);
@@ -1505,14 +1501,39 @@ namespace System.Windows.Forms
                        }
                }
 
-               // draws the ListViewItem of the given index
+               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);
+                       Pen pen = new Pen (ColorHighlight, 2);
+                       dc.DrawLine (pen, 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
@@ -1559,20 +1580,16 @@ 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 &&
-                                   item.ImageIndex < control.LargeImageList.Images.Count)
-                                       control.LargeImageList.Draw (dc, rect_iconrect.Location,
-                                                                    item.ImageIndex);
-                       }
-                       else {
-                               if (item.ImageIndex > -1 &&
-                                   control.SmallImageList != null &&
+                               if (control.LargeImageList == null) {
+                                       Pen pen = new Pen (ColorWindowText, 2);
+                                       dc.DrawLine (pen, icon_rect.Left, icon_rect.Y, icon_rect.Left + 11, icon_rect.Y);
+                               } else if (item.ImageIndex > -1 && item.ImageIndex < control.LargeImageList.Images.Count)
+                                       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                   
@@ -1593,10 +1610,7 @@ namespace System.Windows.Forms
                        if (item.Selected) {
                                if (control.View == View.Details) {
                                        if (control.FullRowSelect) {
-                                               // fill the entire rect excluding the checkbox                                          
-                                               full_rect.Location = item.GetBounds (ItemBoundsPortion.Label).Location;
-                                               dc.FillRectangle (this.ResPool.GetSolidBrush
-                                                                 (this.ColorHighlight), full_rect);
+                                               dc.FillRectangle (ResPool.GetSolidBrush (ColorHighlight), text_rect);
                                        }
                                        else {
                                                Size text_size = Size.Ceiling (dc.MeasureString (item.Text,
@@ -1647,55 +1661,56 @@ namespace System.Windows.Forms
                                                subItem = subItems [index];
                                                col = control.Columns [index];
                                                format.Alignment = col.Format.Alignment;
-                                               sub_item_rect.X = col.Rect.Left + 3;
-                                               sub_item_rect.Width = col.Wd - 6;
-                                               sub_item_rect.X -= control.h_marker;
+                                               sub_item_rect.X = col.Rect.X - control.h_marker;
+                                               sub_item_rect.Width = col.Wd;
+                                               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 (ResPool.GetSolidBrush (ColorHighlight), 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 {
+                                                                              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) {                             
+                               Rectangle focus_rect = text_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 ();
@@ -1876,6 +1891,23 @@ namespace System.Windows.Forms
                        }                               
                }               
                
+               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;
@@ -1956,11 +1988,7 @@ namespace System.Windows.Forms
 
                                int cx = MenuCheckSize.Width;
                                int cy = 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 ();
+                               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,
@@ -1970,7 +1998,6 @@ namespace System.Windows.Forms
                                                e.Bounds.Y + ((e.Bounds.Height - cy) /2),  color_back);
                                }
  
-                               gr.Dispose ();
                                bmp.Dispose ();
                        }
 
@@ -1980,19 +2007,10 @@ namespace System.Windows.Forms
                                Rectangle area = e.Bounds;
                                int cx = MenuCheckSize.Width;
                                int cy = 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);
+                               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 ();
                        }                       
                }               
@@ -2404,7 +2422,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);                 
@@ -2584,12 +2602,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.SunkenInner, 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);
@@ -2803,8 +2821,6 @@ namespace System.Windows.Forms
                
                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)) {
@@ -2816,11 +2832,14 @@ namespace System.Windows.Forms
                        } 
                        
                        /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */                       
-                       dc.DrawString (radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (radio_button.ForeColor), text_rectangle, text_format);
-                       
+
+                       // Windows seems to not wrap text in certain situations, this matches as close as I could get it
+                       if ((float)(radio_button.Font.Height * 1.5f) > text_rectangle.Height) {
+                               text_format.FormatFlags |= StringFormatFlags.NoWrap;
+                       }
+
                        if (radio_button.Enabled) {
-                               sb = ResPool.GetSolidBrush(radio_button.ForeColor);
-                               dc.DrawString(radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
+                               dc.DrawString (radio_button.Text, radio_button.Font, ResPool.GetSolidBrush (radio_button.ForeColor), 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 {
@@ -3152,7 +3171,7 @@ namespace System.Windows.Forms
                                Border3DStyle border_style = Border3DStyle.SunkenInner;
                                if (panel.BorderStyle == StatusBarPanelBorderStyle.Raised)
                                        border_style = Border3DStyle.RaisedOuter;
-                               CPDrawBorder3D(dc, area, border_style, Border3DSide.All, panel.Parent.BackColor);
+                               CPDrawBorder3D(dc, area, border_style, Border3DSide.Left | Border3DSide.Right | Border3DSide.Top | Border3DSide.Bottom, panel.Parent.BackColor);
                        }
 
                        if (panel.Style == StatusBarPanelStyle.OwnerDraw) {
@@ -3377,9 +3396,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);
@@ -3507,7 +3526,7 @@ namespace System.Windows.Forms
                                return res;
                        }
 
-                       if (page.Focused) {
+                       if (page.parent.Focused && is_selected) {
                                CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
                        }
 
@@ -3515,255 +3534,148 @@ namespace System.Windows.Forms
                }
 
                #region ToolBar
-               public  override void DrawToolBar (Graphics dc, Rectangle clip_rectangle, ToolBar control) {
-                       StringFormat    format = new StringFormat ();
+               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;
+                       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;
-                                       }
+                       dc.FillRectangle (ResPool.GetSolidBrush( DefaultControlBackColor ), clip_rectangle);
+
+                       foreach (ToolBarButton button in control.Buttons)
+                               if (button.Visible && clip_rectangle.IntersectsWith (button.Rectangle))
+                                       DrawToolBarButton (dc, control, button, format);
 
-                                       // 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;
-                                                       }
-                                               }
-                                       }
-                                       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;
-                                                       }
-                                               }
-                                       }
-                               }
-                               DrawToolBarButton (dc, button, control.Font, format, paint_area, buttonArea,
-                                       imgRect, image, txtRect, ddRect, flat);
-                       }
                        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;
+               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 (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 (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 (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 (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 (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;
+
+               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.RaisedOuter;
                                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);
+               }
+
+               void DrawToolBarSeparator (Graphics dc, ToolBarButton button)
+               {
+                       Rectangle area = button.Rectangle;
+                       int offset = (int) ResPool.GetPen (ColorControl).Width + 1;
+                       dc.DrawLine (ResPool.GetPen (ColorControlDark), area.X + 1, area.Y, area.X + 1, area.Bottom);
+                       dc.DrawLine (ResPool.GetPen (ColorControlLight), area.X + offset, area.Y, area.X + offset, area.Bottom);
+               }
+
+               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);
+               }
+
+               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);
+               }
+
+               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);
+                       }
+
+                       if (button.Enabled)
+                               dc.DrawString (button.Text, control.Font, ResPool.GetSolidBrush (ColorControlText), button.TextRectangle, format);
+                       else
+                               CPDrawStringDisabled (dc, button.Text, control.Font, ColorControlLight, button.TextRectangle, format);
                }
 
                // Grip width for the ToolBar
@@ -3830,6 +3742,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)   {
@@ -3878,19 +3791,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;
@@ -4334,115 +4247,87 @@ namespace System.Windows.Forms
                        CPDrawBorder3D(graphics, rectangle, style, sides, ColorControl);
                }
 
-               private void CPDrawBorder3D (Graphics graphics, Rectangle rectangle, Border3DStyle style, Border3DSide sides, Color control_color) {
+               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;
-
-                       if ((style & Border3DStyle.Adjust)!=0) {
-                               rect.Y-=2;
-                               rect.X-=2;
-                               rect.Width+=4;
-                               rect.Height+=4;
-                       }
-
-                       /* 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));
-
-                       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;
-                               }
+                       Rectangle       rect= new Rectangle (rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
+                       
+                       if ((style & Border3DStyle.Adjust) != 0) {
+                               rect.Y -= 2;
+                               rect.X -= 2;
+                               rect.Width += 4;
+                               rect.Height += 4;
                        }
-
-                       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));
-                               }
+                       
+                       penTopLeft = penTopLeftInner = penBottomRight = penBottomRightInner = ResPool.GetPen (control_color);
+                       
+                       switch (style) {
+                       case Border3DStyle.Raised:
+                               penTopLeftInner = ResPool.GetPen (ControlPaint.LightLight (control_color));
+                               penBottomRight = ResPool.GetPen (ControlPaint.DarkDark (control_color));
+                               penBottomRightInner = ResPool.GetPen (ColorInactiveCaption);
+                               break;
+                       case Border3DStyle.Sunken:
+                               penTopLeft = ResPool.GetPen (ColorInactiveCaption);
+                               penTopLeftInner = ResPool.GetPen (ControlPaint.DarkDark (control_color));
+                               penBottomRight = ResPool.GetPen (ControlPaint.LightLight (control_color));
+                               break;
+                       case Border3DStyle.Etched:
+                               penTopLeft = penBottomRightInner = ResPool.GetPen (ColorInactiveCaption);
+                               penTopLeftInner = penBottomRight = ResPool.GetPen (ControlPaint.LightLight (control_color));
+                               break;
+                       case Border3DStyle.RaisedOuter:
+                               penBottomRight = ResPool.GetPen (ControlPaint.DarkDark (control_color));
+                               break;
+                       case Border3DStyle.SunkenOuter:
+                               penTopLeft = ResPool.GetPen (ColorInactiveCaption);
+                               penBottomRight = ResPool.GetPen (ControlPaint.LightLight (control_color));
+                               break;
+                       case Border3DStyle.RaisedInner:
+                               penTopLeft = ResPool.GetPen (ControlPaint.LightLight (control_color));
+                               penBottomRight = ResPool.GetPen (ColorInactiveCaption);
+                               break;
+                       case Border3DStyle.SunkenInner:
+                               penTopLeft = ResPool.GetPen (ControlPaint.DarkDark (control_color));
+                               break;
+                       case Border3DStyle.Flat:
+                               penTopLeft = penBottomRight = ResPool.GetPen (ColorInactiveCaption);
+                               break;
+                       case Border3DStyle.Bump:
+                               penTopLeftInner = penBottomRight = ResPool.GetPen (ControlPaint.DarkDark (control_color));
+                               break;
+                       default:
+                               break;
                        }
-
-                       if ((sides & Border3DSide.Middle)!=0) {
-                               graphics.FillRectangle(ResPool.GetSolidBrush(control_color), rect);
+                       
+                       if ((sides & Border3DSide.Middle) != 0) {
+                               graphics.FillRectangle (ResPool.GetSolidBrush (control_color), rect);
                        }
-
-                       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);
-                               }
+                       
+                       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);
-
-                               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 ((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);
-
-                               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 ((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) {
-                               int     left=rect.Left;
-
-                               if ((sides & Border3DSide.Left)!=0) {
-                                       left+=1;
-                               }
-
-                               graphics.DrawLine(penBottomRight, rect.Left, rect.Bottom-1, rect.Right-1, rect.Bottom-1);
-
-                               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);
-                                       }
-                               }
+                       
+                       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);
                        }
-
                }
 
-
                public override void CPDrawButton (Graphics graphics, Rectangle rectangle, ButtonState state) {
                        DrawFrameControlStates  dfcs=DrawFrameControlStates.ButtonPush;
 
@@ -4847,12 +4732,11 @@ namespace System.Windows.Forms
                }
 
 
-               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: {
@@ -4880,7 +4764,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;
                        }
@@ -4890,13 +4774,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);
@@ -4904,8 +4789,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;
                        }
@@ -4950,8 +4835,21 @@ namespace System.Windows.Forms
                public override void CPDrawScrollButton (Graphics dc, Rectangle area, ScrollButton type, ButtonState state) {
                        DrawScrollButtonPrimitive (dc, area, state);
 
+                       int arrow_y_pos_diff = 3;
+                       
+                       switch (type) {
+                       case ScrollButton.Up:
+                               arrow_y_pos_diff = 2;
+                               break;
+                       case ScrollButton.Down:
+                               arrow_y_pos_diff = 4;
+                               break;
+                       default:
+                               break;
+                       }
+                       
                        // A lot of the following is adapted from the rewind project
-                       Rectangle rect = new Rectangle (area.X - 3, area.Y - 3,
+                       Rectangle rect = new Rectangle (area.X - 3, area.Y - arrow_y_pos_diff,
                                        area.Width + 6, area.Height + 6);
                        int small_diam = rect.Width > rect.Height ? rect.Height : rect.Width;
                        if (rect.Width < rect.Height) {
@@ -4997,6 +4895,15 @@ namespace System.Windows.Forms
                                arrow [1].Y = arrow [2].Y + tri;
                                arrow [0].X = arrow [1].X = arrow [2].X + tri;
                                break;
+                               // Left and Right are not drawn correctly because of libgdiplus problems
+                               // once that is solved change it to the code below to match ms
+//                     case ScrollButton.Left:
+//                             arrow [2].X = rect.Right - (687 * small_diam / 1000 + 1);
+//                             arrow [2].Y = (rect.Top + 470 * small_diam / 1000 + 2) - 1;
+//                             arrow [1].Y = arrow [2].Y + tri;
+//                             arrow [0].Y = arrow [2].Y - tri + 1;
+//                             arrow [0].X = arrow [1].X = arrow [2].X + tri;
+//                             break;
                        case ScrollButton.Right:
                                arrow [2].X = rect.Left + 687 * small_diam / 1000 + 1;
                                arrow [2].Y = rect.Top + 470 * small_diam / 1000 + 2;
@@ -5028,19 +4935,27 @@ namespace System.Windows.Forms
 
 
                public override void CPDrawSizeGrip (Graphics dc, Color backColor, Rectangle bounds) {
+                       
                        Point pt = new Point (bounds.Right - 2, bounds.Bottom - 1);
 
+                       Pen pen = ResPool.GetPen (ColorControlDark);
+                       
+                       dc.DrawLine (pen, pt.X - 11, pt.Y, pt.X, pt.Y - 11);
+                       dc.DrawLine (pen, pt.X - 10, pt.Y, pt.X, pt.Y - 10);
+                       
+                       dc.DrawLine (pen, pt.X - 7, pt.Y, pt.X, pt.Y - 7);
+                       dc.DrawLine (pen, pt.X - 6, pt.Y, pt.X, pt.Y - 6);
+                       
+                       dc.DrawLine (pen, pt.X - 3, pt.Y, pt.X, pt.Y - 3);
+                       dc.DrawLine (pen, pt.X - 2, pt.Y, pt.X, pt.Y - 2);
+                       
+                       pen = ResPool.GetPen (ColorControlLight);
+                       
+                       dc.DrawLine (pen, pt.X - 12, pt.Y, pt.X, pt.Y - 12);
+                       dc.DrawLine (pen, pt.X - 8, pt.Y, pt.X, pt.Y - 8);
+                       dc.DrawLine (pen, pt.X - 4, pt.Y, pt.X, pt.Y - 4);
+                       
                        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);
-                       }
-
-                       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);
                }
 
 
@@ -5375,12 +5290,8 @@ namespace System.Windows.Forms
                                                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 
+                                               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);