Switch to compiler-tester
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ThemeWin32Classic.cs
index 92c695cc8a84f0a627b3a9e09964560b9c12f9e9..51578063651d83307705fa99b81eb2890830bf89 100644 (file)
@@ -17,7 +17,7 @@
 // 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 Novell, Inc.
+// Copyright (c) 2004-2005 Novell, Inc.
 //
 // Authors:
 //     Jordi Mas i Hernandez, jordi@ximian.com
 //     John BouAntoun, jba-mono@optusnet.com.au
 //
 //
-//
-// $Revision: 1.64 $
-// $Modtime: $
-// $Log: ThemeWin32Classic.cs,v $
-// Revision 1.64  2004/11/10 19:22:26  jackson
-//     * ThemeWin32Classic.cs: Don't bother drawing tabs outside of the
-//     clip area.
-//
-// Revision 1.63  2004/11/10 01:04:28  jackson
-//     * TabControl.cs (CalcXPos): New helper method so we can determine
-//     the proper place to start drawing vertical tabs.
-//     * ThemeWin32Classic.cs (DrawTab): Draw right aligned tabs.
-//
-// Revision 1.62  2004/11/09 21:44:54  jackson
-//     * TabControl.cs: Calculate sizing and rects for left aligned tabs.
-//     * ThemeWin32Classic.cs (GetTabControl*ScrollRect): Only handle Top
-//     and Bottom, left and right are illegal values for this and
-//     multiline is enabled when the alignment is set to left or right.
-//     (DrawTab): Each alignment block should draw the text itself now
-//     because Left requires special love. Also add rendering for Left
-//     aligned tabs.
-//
-// Revision 1.61  2004/11/09 11:06:21  jba
-// - (DrawButtonBase): Fix verticle text rect clipping in windows
-// - (DrawCheckBox): Fix CheckAlign.TopCenter and CheckAlign.BottomCenter
-//   rendering and incorrect text rect clipping
-// - (DrawRadioButton): Fix CheckAlign.TopCenter and CheckAlign.BottomCenter
-//   rendering and incorrect text rect clipping
-//
-// Revision 1.60  2004/11/09 03:12:00  jackson
-//     * ThemeWin32Classic.cs (DrawTabControl): Render tabs from top to
-//     bottom when they are bottom aligned so the bottoms of the tabs get
-//     displayed.
-//     * TabControl.cs (DropRow): Move rows up instead of down when the
-//     tab control is bottom aligned.
-//
-// Revision 1.59  2004/11/08 20:40:08  jackson
-// Render the little scrolling jimmi in the correct location with bottom aligned tabs
-//
-// Revision 1.58  2004/11/08 14:15:00  jordi
-// fixes vertical scrollbar and removes dead code
-//
-// Revision 1.57  2004/11/05 05:47:34  jba
-// - Fix Button rendering for FlatStyle = Flat or Popup
-// - Fix RadioButton and CheckBox rendering when Appearance = Button (normal and
-//   flatstyle).
-// - Correct outer rectangle color when drawing focus rectangle
-// - Adjust button bounds to be 1 px smaller when focused
-// - Make button not draw sunken 3d border when pushed (windows compat)
-// - Fix CPDrawBorder3D to not make bottom right hand corner rounded
-// - Offset the text in RadioButton and Checkbox when being rendered as a button.
-// - Hover and Click behaviour for Colored FlatStyle.Flat and Popup radiobuttons
-// - Fixed disabled rendering for colored flatstyle radiobuttons (both)
-// - Fixed disabled text rendering for normally rendered radiobuttons
-//
-// Revision 1.56  2004/11/04 11:26:09  ravindra
-//     - Changed default ListView values signatures (prefixed all with ListView).
-//     - Fixed default size values for VScrollBar and HScrollBar.
-//     - Fixed DrawListViewItem method.
-//
-// Revision 1.55  2004/11/03 18:52:14  jackson
-// Initial implementation of the scrolly widgerywoo
-//
-// Revision 1.54  2004/11/02 20:40:54  jackson
-// Move the row with the selected tab to the bottom
-//
-// Revision 1.53  2004/11/02 02:47:55  jackson
-// New rendering and sizing code for tab controls
-//
-// Revision 1.52  2004/10/30 10:23:02  ravindra
-// Drawing ListView and some default values.
-//
-// Revision 1.51  2004/10/26 09:55:48  ravindra
-// Some formatting for my last checkins.
-//
-// Revision 1.50  2004/10/26 09:36:32  ravindra
-// Implemented DetailView drawing for ListView control and default values.
-//
-// Revision 1.49  2004/10/18 04:49:25  pbartok
-// - Added ToolTip drawing code
-//
-// Revision 1.48  2004/10/15 15:08:49  ravindra
-// Added ColumnHeaderHeight property in Theme for ListView.
-//
-// Revision 1.47  2004/10/13 15:06:37  pbartok
-// - Path from John BouAntoun:
-//   * Fix check rendering (centre correctly for normal style, offset
-//     correctly for FlatStyle).
-//   * Fix border color usage (use backcolor) for FlatStyle.Popup
-//   * Use checkbox.Capture instead of checkbox.is_pressed when rendering
-//     flatstyle states.
-//
-// Revision 1.46  2004/10/13 03:48:15  pbartok
-// - Removed all occurences of SystemColors and replaced them with the
-//   matching theme color
-//
-// Revision 1.45  2004/10/13 03:41:45  pbartok
-// - From John BouAntoun: Added an overload to CPDrawBorder3D to allow him
-//   using the function for flatstyle drawing
-// - Changed functions to use the new version of CPDrawBorder3D
-//
-// Revision 1.44  2004/10/13 02:45:21  pbartok
-// - Fixes from John BouAntoun: now handles forecolors and backcolors for
-//   flatstyle rendered controls much better; It also fixes normal checkbox
-//   rendering when pushed or disabled.
-//
-// Revision 1.43  2004/10/07 14:56:51  jordi
-// Removes deletion of cached brushes
-//
-// Revision 1.42  2004/10/06 09:59:05  jordi
-// removes warnings from compilation
-//
-// Revision 1.41  2004/10/05 16:15:30  jackson
-// Improve rendering of the radio button patch by John BouAntoun
-//
-// Revision 1.40  2004/10/05 09:04:31  ravindra
-//     - Added DrawListView method and ListViewDefaultSize property.
-//     - Changed ControlPaint method calls to CPDrawXXX wherever possible.
-//     - Changed DOS style CRLF to Unix format (dos2unix).
-//
-// Revision 1.39  2004/10/04 07:09:37  jordi
-// fixes right button position causing right button not showing on horizontal scrollbars
-//
-// Revision 1.38  2004/09/28 18:44:25  pbartok
-// - Streamlined Theme interfaces:
-//   * Each DrawXXX method for a control now is passed the object for the
-//     control to be drawn in order to allow accessing any state the theme
-//     might require
-//
-//   * ControlPaint methods for the theme now have a CP prefix to avoid
-//     name clashes with the Draw methods for controls
-//
-//   * Every control now retrieves it's DefaultSize from the current theme
-//
-// Revision 1.37  2004/09/09 08:28:11  pbartok
-// - Improve disabled string look
-//
-// Revision 1.36  2004/09/09 03:03:49  ravindra
-// PictureBox would not draw a null image to avoid crash.
-//
-// Revision 1.35  2004/09/07 17:12:26  jordi
-// GroupBox control
-//
-// Revision 1.34  2004/09/07 09:40:15  jordi
-// LinkLabel fixes, methods, multiple links
-//
-// Revision 1.33  2004/09/05 08:03:51  jordi
-// fixes bugs, adds flashing on certain situations
-//
-// Revision 1.32  2004/09/02 16:32:54  jordi
-// implements resource pool for pens, brushes, and hatchbruses
-//
-// Revision 1.31  2004/08/25 20:04:40  ravindra
-// Added the missing divider code and grip for ToolBar Control.
-//
-// Revision 1.30  2004/08/25 18:29:14  jordi
-// new methods, properties, and fixes for progressbar
-//
-// Revision 1.29  2004/08/25 00:43:13  ravindra
-// Fixed wrapping related issues in ToolBar control.
-//
-// Revision 1.28  2004/08/24 18:37:02  jordi
-// fixes formmating, methods signature, and adds missing events
-//
-// Revision 1.27  2004/08/24 16:16:46  jackson
-// Handle drawing picture boxes in the theme now. Draw picture box borders and obey sizing modes
-//
-// Revision 1.26  2004/08/21 01:52:08  ravindra
-// Improvments in mouse event handling in the ToolBar control.
-//
-// Revision 1.25  2004/08/20 00:12:51  jordi
-// fixes methods signature
-//
-// Revision 1.24  2004/08/19 22:25:31  jordi
-// theme enhancaments
-//
-// Revision 1.23  2004/08/18 19:16:53  jordi
-// Move colors to a table
-//
-// Revision 1.22  2004/08/17 19:29:11  jackson
-// Don't use KnownColor to create colours. It has a large startup time.
-//
-// Revision 1.21  2004/08/15 23:20:54  ravindra
-// Changes to Theme for ToolBar control and also dos2unix format.
-//
-// Revision 1.20  2004/08/13 21:22:18  jordi
-// removes redundant code and fixes issues with tickposition
-//
-// Revision 1.19  2004/08/12 20:29:01  jordi
-// Trackbar enhancement, fix mouse problems, highli thumb, etc
-//
-// Revision 1.18  2004/08/12 18:54:37  jackson
-// Handle owner draw status bars
-//
-// Revision 1.17  2004/08/11 01:31:35  jackson
-// Create Brushes as little as possible
-//
-// Revision 1.16  2004/08/10 19:21:27  jordi
-// scrollbar enhancements and standarize on win colors defaults
-//
-// Revision 1.15  2004/08/10 18:52:30  jackson
-// Implement DrawItem functionality
-//
-// Revision 1.14  2004/08/09 21:34:54  jackson
-// Add support for drawing status bar and get status bar item sizes
-//
-// Revision 1.13  2004/08/09 21:21:49  jackson
-// Use known colors for default control colours
-//
-// Revision 1.12  2004/08/09 21:12:15  jackson
-// Make the default font static, it is static in control so this doesn't change functionality and creating fonts is sloooooow.
-//
-// Revision 1.11  2004/08/09 17:31:13  jackson
-// New names for control properties
-//
-// Revision 1.10  2004/08/09 17:00:00  jackson
-// Add default window color properties
-//
-// Revision 1.9  2004/08/09 16:17:19  jackson
-// Use correct default back color
-//
-// Revision 1.8  2004/08/09 15:53:12  jackson
-// Themes now handle default control properties so coloring will be consistent
-//
-// Revision 1.7  2004/08/08 22:54:21  jordi
-// Label BorderStyles
-//
-// Revision 1.6  2004/08/08 18:09:53  jackson
-// Add pen_buttonface
-//
-// Revision 1.5  2004/08/08 17:34:28  jordi
-// Use Windows Standard Colours
-//
-// Revision 1.4  2004/08/07 23:31:15  jordi
-// fixes label bug and draw method name
-//
-// Revision 1.3  2004/08/07 19:05:44  jordi
-// Theme colour support and GetSysColor defines
-//
-// Revision 1.2  2004/08/07 00:01:39  pbartok
-// - Fixed some rounding issues with float/int
-//
-// Revision 1.1  2004/07/26 17:42:03  jordi
-// Theme support
-//
-//
+
 
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
+using System.Drawing.Text;
 
 namespace System.Windows.Forms
 {
 
        internal class ThemeWin32Classic : Theme
        {               
+               public override Version Version {\r
+                       get {\r
+                               return new Version(0, 1, 0, 0);\r
+                       }\r
+               }\r
+
 
                /* Default colors for Win32 classic theme */
                uint [] theme_colors = {                                                        /* AARRGGBB */
@@ -311,39 +73,55 @@ namespace System.Windows.Forms
                        (uint) XplatUIWin32.GetSysColorIndex.COLOR_INFOBK,                      0xffffffff,
                  
                };              
-               
-               static protected Pen pen_ticks;         
-               static protected SolidBrush br_arrow;
-               static protected SolidBrush br_progressbarblock;                
-               static protected Pen pen_arrow;
                                
-
-               /* Cache */
-               protected SolidBrush label_br_fore_color;
-               protected SolidBrush label_br_back_color;
+               /* Hardcoded colour values not exposed in the API constants in all configurations */
+               static readonly Color arrow_color = Color.Black;
+               static readonly Color pen_ticks_color = Color.Black;
+               static readonly Color progressbarblock_color = Color.FromArgb (255, 0, 0, 128);
+               static StringFormat string_format_menu_text;
+               static StringFormat string_format_menu_shortcut;
+               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;
+               const int SM_CYBORDER = 1;              
+               const int MENU_TAB_SPACE = 8;           // Pixels added to the width of an item because of a tab
+               const int MENU_BAR_ITEMS_SPACE = 8;     // Space between menu bar items
 
                #region Principal Theme Methods
                public ThemeWin32Classic ()
-               {
-                       label_br_fore_color = null;
-                       label_br_back_color = null;                                             
-
+               {                       
                        /* Init Default colour array*/
                        syscolors =  Array.CreateInstance (typeof (Color), (uint) XplatUIWin32.GetSysColorIndex.COLOR_MAXVALUE+1);
                        
                        for (int i = 0; i < theme_colors.Length; i +=2) 
-                               syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);
-                       pen_ticks = new Pen (Color.Black);                      
-                       br_arrow = new SolidBrush (Color.Black);
-                       pen_arrow = new Pen (Color.Black);
-                       br_progressbarblock = new SolidBrush (Color.FromArgb (255, 0, 0, 128));                 
+                               syscolors.SetValue (Color.FromArgb ((int)theme_colors[i+1]), (int) theme_colors[i]);                    
 
-                       defaultWindowBackColor = Color.FromArgb (255, 10, 10, 10);
+                       defaultWindowBackColor = SystemColors.Window;
                        defaultWindowForeColor = ColorButtonText;
                        default_font =  new Font (FontFamily.GenericSansSerif, 8.25f);
+                       
+                       /* Menu string formats */
+                       string_format_menu_text = new StringFormat ();
+                       string_format_menu_text.LineAlignment = StringAlignment.Center;
+                       string_format_menu_text.Alignment = StringAlignment.Near;
+                       string_format_menu_text.HotkeyPrefix = HotkeyPrefix.Show;
+
+                       string_format_menu_shortcut = new StringFormat ();      
+                       string_format_menu_shortcut.LineAlignment = StringAlignment.Center;
+                       string_format_menu_shortcut.Alignment = StringAlignment.Far;
+
+                       string_format_menu_menubar_text = new StringFormat ();
+                       string_format_menu_menubar_text.LineAlignment = StringAlignment.Center;
+                       string_format_menu_menubar_text.Alignment = StringAlignment.Center;
+                       string_format_menu_menubar_text.HotkeyPrefix = HotkeyPrefix.Show;
                }       
 
+               public override void ResetDefaults() {
+                       throw new NotImplementedException("Need to implement ResetDefaults() for Win32 theme");
+               }
+
                public override bool DoubleBufferingSupported {
                        get {return true; }
                }
@@ -390,10 +168,8 @@ namespace System.Windows.Forms
 
                        width = button.ClientSize.Width;
                        height = button.ClientSize.Height;
-
-                       SolidBrush      sb = new SolidBrush(button.BackColor);
-                       dc.FillRectangle(sb, button.ClientRectangle);
-                       sb.Dispose();
+                       
+                       dc.FillRectangle(ResPool.GetSolidBrush (button.BackColor), button.ClientRectangle);                     
                        
                        // set up the button rectangle
                        buttonRectangle = button.ClientRectangle;
@@ -520,10 +296,9 @@ namespace System.Windows.Forms
                                        text_rect.Y++;
                                }
 
-                               if (button.is_enabled) {
-                                       SolidBrush      b = new SolidBrush(button.ForeColor);
-                                       dc.DrawString(button.text, button.Font, b, text_rect, button.text_format);
-                                       b.Dispose();
+                               if (button.is_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.ColorButtonFace)), text_rect, button.text_format);
@@ -644,6 +419,7 @@ namespace System.Windows.Forms
                        text_format = new StringFormat();
                        text_format.Alignment=StringAlignment.Near;
                        text_format.LineAlignment=StringAlignment.Center;
+                       text_format.HotkeyPrefix = HotkeyPrefix.Show;
 
                        /* Calculate the position of text and checkbox rectangle */
                        if (checkbox.appearance!=Appearance.Button) {
@@ -799,11 +575,8 @@ namespace System.Windows.Forms
                        
                        
                        // Start drawing
-
-                       sb=new SolidBrush(checkbox.BackColor);
-                       dc.FillRectangle(sb, checkbox.ClientRectangle);
-                       sb.Dispose();
                        
+                       dc.FillRectangle (ResPool.GetSolidBrush (checkbox.BackColor), checkbox.ClientRectangle);                        
                        // render as per normal button
                        if (checkbox.appearance==Appearance.Button) {
                                if (checkbox.FlatStyle == FlatStyle.Flat || checkbox.FlatStyle == FlatStyle.Popup) {
@@ -842,9 +615,9 @@ namespace System.Windows.Forms
 
                        if (checkbox.Focused) {
                                if (checkbox.FlatStyle != FlatStyle.Flat) {
-                                       DrawInnerFocusRectangle (dc, Rectangle.Inflate (client_rectangle, -4, -4), checkbox.BackColor);
+                                       DrawInnerFocusRectangle (dc, Rectangle.Inflate (text_rectangle, -1, -1), checkbox.BackColor);
                                } else {
-                                       dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (client_rectangle, -4, -4));
+                                       dc.DrawRectangle (ResPool.GetPen (checkbox.ForeColor), Rectangle.Inflate (text_rectangle, -1, -1));
                                }
                        }
                }
@@ -933,13 +706,228 @@ namespace System.Windows.Forms
 
 
                #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)
+                               state = ButtonState.Checked;
+                       else
+                               state = ButtonState.Normal;
+
+                       if (ctrl.ThreeDCheckBoxes == false)
+                               state |= ButtonState.Flat;
+
+                       ControlPaint.DrawCheckBox (e.Graphics,
+                               item_rect.X + checkbox_rect.X, item_rect.Y + checkbox_rect.Y,
+                               checkbox_rect.Width, checkbox_rect.Height,
+                               state);
+
+                       item_rect.X += checkbox_rect.Width + checkbox_rect.X * 2;
+                       item_rect.Width -= checkbox_rect.Width + checkbox_rect.X * 2;
+                       
+                       /* Draw text*/
+                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
+                               back_color = ThemeEngine.Current.ColorHilight;
+                               fore_color = ThemeEngine.Current.ColorHilightText;
+                       }
+                       else {
+                               back_color = e.BackColor;
+                               fore_color = e.ForeColor;
+                       }
+                       
+                       e.Graphics.FillRectangle (ThemeEngine.Current.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);
+                                       
+                       if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
+                               ThemeEngine.Current.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 (ColorButtonShadow), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top 
+                       dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
+                       dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
+                       dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
+                       dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
+                       dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2); 
+                       dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
+                       dc.DrawLine (ResPool.GetPen (ColorButtonHilight), 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);
+                       }                       
+               }
+               
+               public override void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e)
+               {
+                       Color back_color, fore_color;
+                       Rectangle text_draw = e.Bounds;
+                       StringFormat string_format = new StringFormat ();
+                       string_format.FormatFlags = StringFormatFlags.LineLimit;
+                       
+                       if ((e.State & DrawItemState.Selected) == DrawItemState.Selected) {
+                               back_color = ThemeEngine.Current.ColorHilight;
+                               fore_color = ThemeEngine.Current.ColorHilightText;
+                       }
+                       else {
+                               back_color = e.BackColor;
+                               fore_color = e.ForeColor;
+                       }                       
+                                                       
+                       e.Graphics.FillRectangle (ThemeEngine.Current.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),
+                                       text_draw, string_format);
+                       }
+                       
+                       if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
+                               ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds, fore_color, back_color);
+                       }
+               }
+               
+               #endregion ComboBox
+               
+               #region Datagrid
+               public override int DataGridPreferredColumnWidth { get { return 75;} }
+               public override int DataGridMinimumColumnCheckBoxHeight { get { return 16;} }
+               public override int DataGridMinimumColumnCheckBoxWidth { get { return 16;} }
+               public override Color DataGridAlternatingBackColor { get { return ColorWindow;} }
+               public override Color DataGridBackgroundColor { get  { return ColorWindow;} }
+               public override Color DataGridCaptionBackColor { get  { return ColorActiveTitle;} }
+               public override Color DataGridCaptionForeColor { get  { return SystemColors.ActiveCaptionText;} }
+               public override Color DataGridGridLineColor { get { return SystemColors.Control;} }
+               public override Color DataGridHeaderBackColor { get  { return SystemColors.Control;} }
+               public override Color DataGridHeaderForeColor { get  { return SystemColors.ControlText;} }
+               public override Color DataGridLinkColor { get  { return SystemColors.HotTrack;} }
+               public override Color DataGridLinkHoverColor { get  { return SystemColors.HotTrack;} }
+               public override Color DataGridParentRowsBackColor { get  { return SystemColors.Control;} }
+               public override Color DataGridParentRowsForeColor { get  { return SystemColors.WindowText;} }
+               public override Color DataGridSelectionBackColor { get  { return ColorActiveTitle;} }
+               public override Color DataGridSelectionForeColor { get  { return ColorTitleText;} }
+               #endregion // Datagrid
+               
+               #region DateTimePicker
+       
+               public override void DrawDateTimePicker (Graphics dc,  Rectangle clip_rectangle, DateTimePicker dtp) {
+                       // if not showing the numeric updown control then render border
+                       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);
+                               
+                               // deflate by the border width
+                               if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
+                                       button_bounds.Inflate (-2,-2);
+                                       ButtonState state = dtp.is_drop_down_visible ? ButtonState.Pushed : ButtonState.Normal;
+                                       this.CPDrawComboButton ( 
+                                         dc, 
+                                         dtp.drop_down_arrow_rect, 
+                                         state);
+                               }
+                       }
+
+                       // 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);
+                               
+                               // fill the currently highlighted area
+                               if (dtp.hilight_date_area != Rectangle.Empty) {
+                                       dc.FillRectangle (ResPool.GetSolidBrush (ThemeEngine.Current.ColorHilight), dtp.hilight_date_area);
+                               }
+                               
+                               // draw the text part
+                               // TODO: if date format is CUstom then we need to draw the dates as separate parts
+                               StringFormat text_format = new StringFormat();
+                               text_format.LineAlignment = StringAlignment.Center;
+                               text_format.Alignment = StringAlignment.Near;                                   
+                               dc.DrawString (dtp.Text, dtp.Font, ResPool.GetSolidBrush (dtp.ForeColor), Rectangle.Inflate(dtp.date_area_rect, -1, -1), text_format);
+                       }
+               }
+               
+               #endregion // DateTimePicker
 
                #region GroupBox
                public override void DrawGroupBox (Graphics dc,  Rectangle area, GroupBox box) {
-                       SizeF size;
-                       int width, y;
-                       Rectangle rect = box.ClientRectangle;
-                       Color disabled = ColorGrayText;
+                       StringFormat    text_format;
+                       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));
@@ -950,6 +938,9 @@ namespace System.Windows.Forms
 
                        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;
                        
@@ -975,11 +966,12 @@ namespace System.Windows.Forms
                        
                        
                        /* Text */
-                       if (box.Enabled)
-                               dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0);
-                       else
+                       if (box.Enabled) {
+                               dc.DrawString (box.Text, box.Font, new SolidBrush (box.ForeColor), 10, 0, text_format);
+                       } else {
                                CPDrawStringDisabled (dc, box.Text, box.Font, box.ForeColor, 
-                                       new RectangleF (10, 0, width,  box.Font.Height), new StringFormat ());                                  
+                                       new RectangleF (10, 0, width,  box.Font.Height), text_format);
+                       }
                                
                }
 
@@ -1000,21 +992,14 @@ namespace System.Windows.Forms
                #endregion      // HScrollBar
 
                #region Label
-               public  override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) {
-                       if (label_br_fore_color == null || label_br_fore_color.Color != label.ForeColor) {
-                               label_br_fore_color = GetControlForeBrush (label.ForeColor);
-                       }
-
-                       if (label_br_back_color == null || label_br_back_color.Color != label.BackColor) {
-                               label_br_back_color = GetControlBackBrush (label.BackColor);
-                       }
-
-                       dc.FillRectangle (label_br_back_color, clip_rectangle);
+               public  override void DrawLabel (Graphics dc, Rectangle clip_rectangle, Label label) 
+               {               
+                       dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);
                        
-                       CPDrawBorderStyle (dc, clip_rectangle, label.BorderStyle);              
+                       CPDrawBorderStyle (dc, label.ClientRectangle, label.BorderStyle);               
 
                        if (label.Enabled) {
-                               dc.DrawString (label.Text, label.Font, label_br_fore_color, clip_rectangle, label.string_format);
+                               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);
                        }
@@ -1026,45 +1011,197 @@ namespace System.Windows.Forms
                                return new Size (100, 23);
                        }
                }
-               #endregion      // Label
+               #endregion      // Label\r
+\r
+               #region LinkLabel\r
+               public  override void DrawLinkLabel (Graphics dc, Rectangle clip_rectangle, LinkLabel label)\r
+               {\r
+                       Color color;\r
+\r
+                       dc.FillRectangle (ResPool.GetSolidBrush (label.BackColor), clip_rectangle);\r
+                       CPDrawBorderStyle (dc, label.ClientRectangle, label.BorderStyle);                                               
+\r
+                       for (int i = 0; i < label.num_pieces; i++) {
+                               
+                               if (clip_rectangle.IntersectsWith (label.pieces[i].rect) == false) {
+                                       continue;
+                               }                               
+                               \r
+                               color = label.GetLinkColor (label.pieces[i], i);\r
+\r
+                               if (label.pieces[i].link == null)\r
+                                       dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (Color.Black),\r
+                                               label.pieces[i].rect.X, label.pieces[i].rect.Y);\r
+                               else\r
+                                       dc.DrawString (label.pieces[i].text, label.GetPieceFont (label.pieces[i]), ResPool.GetSolidBrush (color),\r
+                                               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);
+                               }\r
+                       }                       
+                       \r
+               }\r
+               #endregion      // LinkLabel\r
+               #region ListBox
+               
+               // Drawing              
+               public override void DrawListBoxDecorations (Graphics dc, ListBox ctrl)
+               {                       
+                       Rectangle cl = ctrl.LBoxInfo.client_rect;
+                       
+                       // Draw decorations
+                       switch (ctrl.BorderStyle) {
+                       case BorderStyle.Fixed3D: {                             
+                               dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X + cl.Width, cl.Y); //top 
+                               dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + cl.Width - 2, cl.Y + 1);
+                               dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X, cl.Y + cl.Height - 2, cl.X + cl.Width, cl.Y + cl.Height - 2); //down
+                               dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X, cl.Y + cl.Height - 1, cl.X + cl.Width, cl.Y + cl.Height - 1);
+                               dc.DrawLine (ResPool.GetPen (ColorButtonShadow), cl.X, cl.Y, cl.X, cl.Y + cl.Height); //left
+                               dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), cl.X + 1, cl.Y + 1, cl.X + 1, cl.Y + cl.Height - 2); 
+                               dc.DrawLine (ResPool.GetPen (ColorButtonFace), cl.X + cl.Width - 2, cl.Y, cl.X + cl.Width - 2, cl.Y + cl.Height); //right
+                               dc.DrawLine (ResPool.GetPen (ColorButtonHilight), cl.X + cl.Width - 1, cl.Y + 1 , cl.X + cl.Width - 1, cl.Y + cl.Height - 1);           
+                               break;
+                       }
+                       case BorderStyle.FixedSingle:
+                               dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), cl.X, cl.Y, cl.Width - 1, cl.Height - 1);
+                               break;
+                       case BorderStyle.None:
+                       default:
+                               break;
+                       }               
+               }               
+               
+               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 int DrawListBoxDecorationTop  (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
+               public override int DrawListBoxDecorationBottom  (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
+               public override int DrawListBoxDecorationRight (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
+               public override int DrawListBoxDecorationLeft (BorderStyle border_style) { return DrawListBoxDecorationSize (border_style);}
+               
+               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.ColorHilight;
+                               fore_color = ThemeEngine.Current.ColorHilightText;
+                       }
+                       else {
+                               back_color = e.BackColor;
+                               fore_color = e.ForeColor;
+                       }
+                       
+                       e.Graphics.FillRectangle (ThemeEngine.Current.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, string_format);
+                                       
+                       if ((e.State & DrawItemState.Focus) == DrawItemState.Focus) {
+                               ThemeEngine.Current.CPDrawFocusRectangle (e.Graphics, e.Bounds,
+                                       fore_color, back_color);
+                       }
+               }
+               
+               #endregion ListBox
 
                #region ListView
                // Drawing
-               public override void DrawListView (Graphics dc, Rectangle clip_rectangle, ListView control)
+               public override void DrawListView (Graphics dc, Rectangle clip, ListView control)
                {
-                       Rectangle control_area = control.ClientRectangle;
                        bool details = (control.View == View.Details);
 
-                       // Draw the border of the list view with a background
-                       dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), control_area);
-                       this.CPDrawBorderStyle (dc, control_area, control.BorderStyle);
-                       if (details) {
+                       dc.FillRectangle (ResPool.GetSolidBrush (control.BackColor), clip);
+
+                       // border is drawn directly in the Paint method
+                       if (details && control.HeaderStyle != ColumnHeaderStyle.None) {
                                dc.FillRectangle (ResPool.GetSolidBrush (SystemColors.Control),
-                                                 0, 0, control.TotalWidth, control.Font.Height);
+                                                 0, 0, control.TotalWidth, control.Font.Height + 5);
                                if (control.Columns.Count > 0) {
-                                       foreach (ColumnHeader col in control.Columns) {
-                                               this.CPDrawButton (dc, col.Rect, ButtonState.Normal);
-                                               dc.DrawString (col.Text, control.Font,
-                                                              ResPool.GetSolidBrush (this.ColorButtonText),
-                                                              col.Rect, col.Format);
+                                       if (control.HeaderStyle == ColumnHeaderStyle.Clickable) {
+                                               foreach (ColumnHeader col in control.Columns) {
+                                                       this.CPDrawButton (dc, col.Rect,
+                                                                          (col.Pressed ?
+                                                                           ButtonState.Pushed :
+                                                                           ButtonState.Normal));
+                                                       dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
+                                                                      ResPool.GetSolidBrush
+                                                                      (this.ColorButtonText),
+                                                                      //col.Rect,
+                                                                       col.Rect.X + 3,
+                                                                       col.Rect.Y + col.Rect.Height/2 + 1,
+                                                                       col.Format);
+                                               }
+                                       }
+                                       // Non-clickable columns
+                                       else {
+                                               foreach (ColumnHeader col in control.Columns) {
+                                                       this.CPDrawButton (dc, col.Rect, ButtonState.Flat);
+                                                       dc.DrawString (col.Text, ThemeEngine.Current.DefaultFont,
+                                                                      ResPool.GetSolidBrush
+                                                                      (this.ColorButtonText),
+                                                                       //col.Rect,
+                                                                       col.Rect.X + 3,
+                                                                       col.Rect.Y + col.Rect.Height/2 + 1,
+                                                                       col.Format);
+                                               }
                                        }
-                               }
-                               if (control.GridLines) {
-                                       // draw vertical gridlines
-                                       foreach (ColumnHeader col in control.Columns)
-                                               dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
-                                                            col.Rect.Right, col.Rect.Bottom,
-                                                            col.Rect.Right, control.TotalHeight);
-                                       // draw horizontal gridlines
-                                       foreach (ListViewItem item in control.Items)
-                                               dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
-                                                            item.EntireRect.Left, item.EntireRect.Bottom,
-                                                            control.TotalWidth, item.EntireRect.Bottom);
                                }
                        }
 
-                       foreach (ListViewItem item in control.Items)
-                               this.DrawListViewItem (dc, control, item);
+                       // In case of details view draw the items only if
+                       // columns are non-zero
+                       if (!details || control.Columns.Count > 0)
+                               foreach (ListViewItem item in control.Items) {
+                                       if (clip.IntersectsWith (item.EntireRect))
+                                               DrawListViewItem (dc, control, item);
+                               }
+
+                       // draw the gridlines
+                       if (details && control.GridLines) {
+                               int top = (control.HeaderStyle == ColumnHeaderStyle.None) ?
+                                       2 : control.Font.Height + 2;
+
+                               // draw vertical gridlines
+                               foreach (ColumnHeader col in control.Columns)
+                                       dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
+                                                    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.ColorButtonFace),
+                                                    item.EntireRect.Left, item.EntireRect.Top,
+                                                    control.TotalWidth, item.EntireRect.Top);
+                                       last_item = item;
+                               }
+
+                               // draw a line after at the bottom of the last item
+                               if (last_item != null) {
+                                       dc.DrawLine (this.ResPool.GetPen (this.ColorButtonFace),
+                                                    last_item.EntireRect.Left,
+                                                    last_item.EntireRect.Bottom,
+                                                    control.TotalWidth,
+                                                    last_item.EntireRect.Bottom);
+                               }
+                       }
                }
 
                // draws the ListViewItem of the given index
@@ -1076,12 +1213,15 @@ namespace System.Windows.Forms
                                        int check_wd = Math.Max (3, item.CheckRect.Width / 6);
                                        int scale = Math.Max (1, item.CheckRect.Width / 12);
 
+                                       // set the checkbox background
+                                       dc.FillRectangle (this.ResPool.GetSolidBrush (this.ColorWindow),
+                                                         item.CheckRect);
                                        // define a rectangle inside the border area
                                        Rectangle rect = new Rectangle (item.CheckRect.X + 2,
                                                                        item.CheckRect.Y + 2,
                                                                        item.CheckRect.Width - 4,
                                                                        item.CheckRect.Height - 4);
-                                       Pen pen = new Pen (SystemColors.WindowText, 2);
+                                       Pen pen = new Pen (this.ColorWindowText, 2);
                                        dc.DrawRectangle (pen, rect);
 
                                        // Need to draw a check-mark
@@ -1129,108 +1269,957 @@ namespace System.Windows.Forms
                                                                     item.ImageIndex);
                        }
 
-                       // draw the item text
-                       Rectangle text_rect = Rectangle.Empty;
-                       text_rect.X = item.LabelRect.X + 1;
-                       text_rect.Y = item.LabelRect.Y + 1;
-                       text_rect.Width = item.LabelRect.Width - 3;
-                       text_rect.Height = item.LabelRect.Height - 2;
+                       // draw the item text
+                       Rectangle text_rect = item.LabelRect;
+                       // format for the item text
+                       StringFormat format = new StringFormat ();
+                       format.LineAlignment = StringAlignment.Center;
+                       if (control.View == View.LargeIcon)
+                               format.Alignment = StringAlignment.Center;
+                       else
+                               format.Alignment = StringAlignment.Near;
+                       
+                       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
+                                               Rectangle full_rect = item.EntireRect;
+                                               full_rect.Location = item.LabelRect.Location;
+                                               dc.FillRectangle (this.ResPool.GetSolidBrush
+                                                                 (this.ColorHilight), 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.ColorHilight), 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.ColorHilight),
+                                                         text_rect);
+                               }
+                       }
+                       else
+                               dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
+
+                       if (item.Text != null && item.Text.Length > 0) {
+                               if (item.Selected)
+                                       dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
+                                                      (this.ColorHilightText), text_rect, format);
+                               else
+                                       dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
+                                                      (item.ForeColor), text_rect, format);
+                       }
+
+                       if (control.View == View.Details && control.Columns.Count > 0) {
+                               // draw subitems for details view
+                               ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
+                               int count = (control.Columns.Count < subItems.Count ? 
+                                            control.Columns.Count : subItems.Count);
+
+                               if (count > 0) {
+                                       ColumnHeader col;
+                                       ListViewItem.ListViewSubItem subItem;
+                                       Rectangle sub_item_rect = item.LabelRect;
+
+                                       // 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;
+                                               sub_item_rect.Width = col.Wd;
+
+                                               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_font = item.Font;
+                                               }
+                                               else {
+                                                       sub_item_back_br = this.ResPool.GetSolidBrush
+                                                               (subItem.BackColor);
+                                                       sub_item_fore_br = this.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) {
+                                                       if (subItem.Text != null && subItem.Text.Length > 0)
+                                                               dc.DrawString (subItem.Text, sub_item_font,
+                                                                              this.ResPool.GetSolidBrush
+                                                                              (this.ColorHilightText),
+                                                                              sub_item_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_rect.X += col.Wd;
+                                       }
+                               }
+                       }
+               }
+
+               // Sizing
+               public override Size ListViewCheckBoxSize {
+                       get { return new Size (16, 16); }
+               }
+
+               public override int ListViewColumnHeaderHeight {
+                       get { return 16; }
+               }
+
+               public override int ListViewDefaultColumnWidth {
+                       get { return 60; }
+               }
+
+               public override int ListViewVerticalSpacing {
+                       get { return 22; }
+               }
+
+               public override int ListViewEmptyColumnWidth {
+                       get { return 10; }
+               }
+
+               public override int ListViewHorizontalSpacing {
+                       get { return 10; }
+               }
+
+               public override Size ListViewDefaultSize {
+                       get { return new Size (121, 97); }
+               }
+               #endregion      // ListView
+               
+               #region Menus
+               public override void CalcItemSize (Graphics dc, MenuAPI.MENUITEM item, int y, int x, bool menuBar)
+               {
+                       item.rect.Y = y;
+                       item.rect.X = x;
+
+                       if (item.item.Visible == false)
+                               return;
+
+                       if (item.item.Separator == true) {
+                               item.rect.Height = SEPARATOR_HEIGHT / 2;
+                               item.rect.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;
+                               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;
+       
+                               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;
+                                       }
+       
+                                       item.rect.Width += 4 + (ThemeEngine.Current.MenuCheckSize.Width * 2);
+                               }
+                               else {
+                                       item.rect.Width += MENU_BAR_ITEMS_SPACE;
+                                       x += item.rect.Width;
+                               }
+       
+                               if (item.rect.Height < ThemeEngine.Current.MenuHeight)
+                                       item.rect.Height = ThemeEngine.Current.MenuHeight;
+                               }
+               }
+               
+               // Updates the menu rect and returns the height
+               public override int CalcMenuBarSize (Graphics dc, IntPtr hMenu, 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) {
+
+                               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;
+                                       x = 0;
+                               }
+
+                               x += item.rect.Width;
+                               item.item.MenuBar = true;                               
+
+                               if (y + item.rect.Height > menu.Height)
+                                       menu.Height = item.rect.Height + y;
+                       }
+
+                       menu.Width = width;                                             
+                       return menu.Height;
+               }
+
+               
+               public override void CalcPopupMenuSize (Graphics dc, IntPtr hMenu)
+               {
+                       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) {
+                               y = 2;
+                               max = 0;
+                               for (i = start; i < menu.items.Count; i++) {
+                                       MenuAPI.MENUITEM item = (MenuAPI.MENUITEM) menu.items[i];
+
+                                       if ((i != start) && (item.item.Break || item.item.BarBreak))
+                                               break;
+
+                                       CalcItemSize (dc, item, y, x, false);
+                                       y += item.rect.Height;
+
+                                       if (item.rect.Width > max)
+                                               max = item.rect.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;
+                               }
+
+                               if (y > menu.Height)
+                                       menu.Height = y;
+
+                               x+= max;
+                       }
+
+                       menu.Width = x;
+
+                       //space for border
+                       menu.Width += 2;
+                       menu.Height += 2;
+
+                       menu.Width += SM_CXBORDER;
+                       menu.Height += SM_CYBORDER;
+               }
+               
+               // Draws a menu bar in a window
+               public override void DrawMenuBar (Graphics dc, IntPtr hMenu, Rectangle rect)
+               {
+                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);                      
+                       Rectangle item_rect;
+
+                       if (menu.Height == 0)
+                               ThemeEngine.Current.CalcMenuBarSize (dc, hMenu, rect.Width);
+                               
+                       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;
+                               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));                 
+                               
+                       }                               
+               }               
+               
+               public override void DrawMenuItem (MenuItem item, DrawItemEventArgs e)
+               {
+                       StringFormat string_format;
+                       Rectangle rect_text = e.Bounds;
+
+                       if (item.Visible == false)
+                               return;
+
+                       if (item.MenuBar) {
+                               string_format = string_format_menu_menubar_text;
+                       }
+                       else {
+                               string_format = string_format_menu_text;
+                       }               
+
+                       if (item.Separator == true) {
+                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+                                       e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);
+
+                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
+                                       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;
+
+                       if (item.BarBreak) { /* Draw vertical break bar*/
+                               Rectangle rect = e.Bounds;
+                               rect.Y++;
+                               rect.Width = 3;
+                               rect.Height = item.MenuHeight - 6;
+
+                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+                                       rect.X, rect.Y , rect.X, rect.Y + rect.Height);
+
+                               e.Graphics.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonHilight),
+                                       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.ColorHilightText;
+                               color_back = ThemeEngine.Current.ColorHilight;
+                       }
+                       else {
+                               color_text = ThemeEngine.Current.ColorMenuText;
+                               color_back = ThemeEngine.Current.ColorMenu;
+                       }
+
+                       /* 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.Enabled) {
+                               e.Graphics.DrawString (item.Text, e.Font,
+                                       ThemeEngine.Current.ResPool.GetSolidBrush (color_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),
+                                               rect, string_format_menu_shortcut);
+                               }
+                       }
+                       else {
+                               ControlPaint.DrawStringDisabled (e.Graphics, item.Text, e.Font, 
+                                       Color.Black, 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.Enabled) {
+                                       e.Graphics.DrawImage (bmp, e.Bounds.X + e.Bounds.Width - cx,
+                                               e.Bounds.Y + ((e.Bounds.Height - cy) /2));
+                               } else {
+                                       ControlPaint.DrawImageDisabled (e.Graphics, bmp, e.Bounds.X + e.Bounds.Width - cx,
+                                               e.Bounds.Y + ((e.Bounds.Height - cy) /2),  color_back);
+                               }
+                               gr.Dispose ();
+                               bmp.Dispose ();
+                       }
+
+                       /* Draw checked or radio */
+                       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);
+
+                               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)
+               {
+                       MenuAPI.MENU menu = MenuAPI.GetMenuFromID (hMenu);
+
+                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush
+                               (ThemeEngine.Current.ColorMenu), cliparea);
+
+                       /* Draw menu borders */
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
+                               rect.X, rect.Y, rect.X + rect.Width, rect.Y);
+
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorHilightText),
+                               rect.X, rect.Y, rect.X, rect.Y + rect.Height);
 
-                       // format for the item text
-                       StringFormat format = new StringFormat ();
-                       format.LineAlignment = StringAlignment.Center;
-                       if (control.View == View.LargeIcon)
-                               format.Alignment = StringAlignment.Center;
-                       else
-                               format.Alignment = StringAlignment.Near;
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+                               rect.X + rect.Width - 1 , rect.Y , rect.X + rect.Width - 1, rect.Y + rect.Height);
 
-                       if (!control.LabelWrap)
-                               format.FormatFlags = StringFormatFlags.NoWrap;
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
+                               rect.X + rect.Width, rect.Y , rect.X + rect.Width, rect.Y + rect.Height);
 
-                       dc.FillRectangle (ResPool.GetSolidBrush (item.BackColor), text_rect);
-                       if (item.Text != null && item.Text.Length > 0)
-                               dc.DrawString (item.Text, item.Font, this.ResPool.GetSolidBrush
-                                              (item.ForeColor), text_rect, format);
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonShadow),
+                               rect.X , rect.Y + rect.Height - 1 , rect.X + rect.Width - 1, rect.Y + rect.Height -1);
 
-                       if (control.View == View.Details && control.Columns.Count > 0) {
-                               // draw subitems for details view
-                               ListViewItem.ListViewSubItemCollection subItems = item.SubItems;
-                               int count = (control.Columns.Count < subItems.Count ? 
-                                            control.Columns.Count : subItems.Count);
+                       dc.DrawLine (ThemeEngine.Current.ResPool.GetPen (ThemeEngine.Current.ColorButtonDkShadow),
+                               rect.X , rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height);
 
-                               if (count > 0) {
-                                       Rectangle sub_item_rect = Rectangle.Empty;
-                                       sub_item_rect.X = item.LabelRect.Right + 1;
-                                       sub_item_rect.Y = item.LabelRect.Y + 1;
-                                       sub_item_rect.Height = item.LabelRect.Height - 2;
+                       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));
+                       }
+               }
+               
+               #endregion // Menus
 
-                                       ListViewItem.ListViewSubItem subItem;
-                                       ColumnHeader col;
+               #region MonthCalendar
 
-                                       // set the format for subitems
-                                       format.FormatFlags = StringFormatFlags.NoWrap;
-                                       format.Alignment = StringAlignment.Near;
+               // draw the month calendar
+               public override void DrawMonthCalendar(Graphics dc, Rectangle clip_rectangle, MonthCalendar mc) \r
+               {
+                       Rectangle client_rectangle = mc.ClientRectangle;
+                       Size month_size = mc.SingleMonthSize;
+                       // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
+                       Size calendar_spacing = (Size)((object)mc.calendar_spacing);
+                       Size date_cell_size = (Size)((object)mc.date_cell_size);
+                       
+                       // draw the singlecalendars
+                       int x_offset = 1;
+                       int y_offset = 1;
+                       // adjust for the position of the specific month
+                       for (int i=0; i < mc.CalendarDimensions.Height; i++) \r
+                       {
+                               if (i > 0) \r
+                               {
+                                       y_offset += month_size.Height + calendar_spacing.Height;
+                               }
+                               // now adjust for x position    
+                               for (int j=0; j < mc.CalendarDimensions.Width; j++) \r
+                               {
+                                       if (j > 0) \r
+                                       {
+                                               x_offset += month_size.Width + calendar_spacing.Width;
+                                       } \r
+                                       else \r
+                                       {
+                                               x_offset = 1;
+                                       }
 
-                                       // 0th subitem is the item already drawn
-                                       for (int index = 1; index < count; index++) {
-                                               subItem = subItems [index];
-                                               col = control.Columns [index];
-                                               sub_item_rect.Width = col.Wd - 3;
+                                       Rectangle month_rect = new Rectangle (x_offset, y_offset, month_size.Width, month_size.Height);
+                                       if (month_rect.IntersectsWith (clip_rectangle)) {
+                                               DrawSingleMonth (
+                                                       dc,
+                                                       clip_rectangle,
+                                                       month_rect,
+                                                       mc,
+                                                       i,
+                                                       j);
+                                       }
+                               }
+                       }
+                       
+                       Rectangle bottom_rect = new Rectangle (
+                                               client_rectangle.X,
+                                               Math.Max(client_rectangle.Bottom - date_cell_size.Height - 3, 0),
+                                               client_rectangle.Width,
+                                               date_cell_size.Height + 2);
+                       // draw the today date if it's set
+                       if (mc.ShowToday && bottom_rect.IntersectsWith (clip_rectangle)) \r
+                       {
+                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), bottom_rect);
+                               if (mc.ShowToday) {
+                                       int today_offset = 5;
+                                       if (mc.ShowTodayCircle) \r
+                                       {
+                                               Rectangle today_circle_rect = new Rectangle (
+                                                       client_rectangle.X + 5,
+                                                       Math.Max(client_rectangle.Bottom - date_cell_size.Height - 2, 0),
+                                                       date_cell_size.Width,
+                                                       date_cell_size.Height);
+                                                       DrawTodayCircle (dc, today_circle_rect);
+                                               today_offset += date_cell_size.Width + 5;
+                                       }
+                                       // draw today's date
+                                       StringFormat text_format = new StringFormat();
+                                       text_format.LineAlignment = StringAlignment.Center;
+                                       text_format.Alignment = StringAlignment.Near;
+                                       Font bold_font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
+                                       Rectangle today_rect = new Rectangle (
+                                                       today_offset + client_rectangle.X,
+                                                       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);
+                               }                               
+                       }
+                       
+                       // 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));
+                               } 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));
+                               } else { 
+                                       Rectangle rect = new Rectangle (
+                                               client_rectangle.X + (month_size.Width*i) + (calendar_spacing.Width * (i-1)) + 1,
+                                               client_rectangle.Y,
+                                               calendar_spacing.Width,
+                                               client_rectangle.Height);
+                                       if (i < mc.CalendarDimensions.Width && i > 0 && clip_rectangle.IntersectsWith (rect)) {
+                                               dc.FillRectangle (ResPool.GetSolidBrush (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));
+                               } 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));
+                               } else { 
+                                       Rectangle rect = new Rectangle (
+                                               client_rectangle.X,
+                                               client_rectangle.Y + (month_size.Height*i) + (calendar_spacing.Height*(i-1)) + 1,
+                                               client_rectangle.Width,
+                                               calendar_spacing.Height);
+                                       if (i < mc.CalendarDimensions.Height && i > 0 && clip_rectangle.IntersectsWith (rect)) {
+                                               dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), rect);
+                                       }
+                               }
+                       }
+                       
+                       // draw the drop down border if need
+                       if (mc.owner != null) {
+                               Rectangle bounds = mc.ClientRectangle;
+                               if (clip_rectangle.Contains (mc.Location)) {
+                                       // find out if top or left line to draw
+                                       if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
+                                       
+                                               dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.X, bounds.Bottom-1);
+                                       }
+                                       if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
+                                               dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Y, bounds.Right-1, bounds.Y);
+                                       }
+                               }
+                               if (clip_rectangle.Contains (new Point(bounds.Right, bounds.Bottom))) {
+                                       // find out if bottom or right line to draw
+                                       if(clip_rectangle.Contains (new Point (bounds.Left, bounds.Bottom))) {
+                                               dc.DrawLine (SystemPens.ControlText, bounds.X, bounds.Bottom-1, bounds.Right-1, bounds.Bottom-1);
+                                       }
+                                       if(clip_rectangle.Contains (new Point (bounds.Right, bounds.Y))) {
+                                               dc.DrawLine (SystemPens.ControlText, bounds.Right-1, bounds.Y, bounds.Right-1, bounds.Bottom-1);
+                                       }
+                               }
+                       }
+               }
 
-                                               if (item.UseItemStyleForSubItems) {
-                                                       dc.FillRectangle (this.ResPool.GetSolidBrush
-                                                                         (item.BackColor), sub_item_rect);
-                                                       if (subItem.Text != null && subItem.Text.Length > 0)
-                                                               dc.DrawString (subItem.Text, item.Font,
-                                                                              this.ResPool.GetSolidBrush
-                                                                              (item.ForeColor),
-                                                                              sub_item_rect, format);
-                                               }
-                                               else {
-                                                       dc.FillRectangle (this.ResPool.GetSolidBrush
-                                                                         (subItem.BackColor),
-                                                                         sub_item_rect);
-                                                       if (subItem.Text != null && subItem.Text.Length > 0)
-                                                               dc.DrawString (subItem.Text, subItem.Font,
-                                                                              this.ResPool.GetSolidBrush
-                                                                              (subItem.ForeColor),
-                                                                              sub_item_rect, format);
+               // darws a single part of the month calendar (with one month)
+               private void DrawSingleMonth(Graphics dc, Rectangle clip_rectangle, Rectangle rectangle, MonthCalendar mc, int row, int col) \r
+               {
+                       // cache local copies of Marshal-by-ref internal members (gets around error CS0197)
+                       Size title_size = (Size)((object)mc.title_size);
+                       Size date_cell_size = (Size)((object)mc.date_cell_size);
+                       DateTime current_month = (DateTime)((object)mc.current_month);
+                       
+                       // set up some standard string formating variables
+                       StringFormat text_format = new StringFormat();
+                       text_format.LineAlignment = StringAlignment.Center;
+                       text_format.Alignment = StringAlignment.Center;
+                       
+
+                       // draw the title back ground
+                       DateTime this_month = current_month.AddMonths (row*mc.CalendarDimensions.Width+col);
+                       Rectangle title_rect = new Rectangle(rectangle.X, rectangle.Y, title_size.Width, title_size.Height);
+                       if (title_rect.IntersectsWith (clip_rectangle)) {
+                               dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), title_rect);
+                               // draw the title                               
+                               string title_text = this_month.ToString ("MMMM yyyy");
+                               dc.DrawString (title_text, mc.Font, ResPool.GetSolidBrush (mc.TitleForeColor), title_rect, text_format);
+
+                               // draw previous and next buttons if it's time
+                               if (row == 0 && col == 0) \r
+                               {
+                                       // draw previous button
+                                       DrawMonthCalendarButton (
+                                               dc,
+                                               rectangle,
+                                               mc,
+                                               title_size,
+                                               mc.button_x_offset,
+                                               (System.Drawing.Size)((object)mc.button_size),
+                                               true);
+                               }
+                               if (row == 0 && col == mc.CalendarDimensions.Width-1) \r
+                               {
+                                       // draw next button
+                                       DrawMonthCalendarButton (
+                                               dc,
+                                               rectangle,
+                                               mc,
+                                               title_size,
+                                               mc.button_x_offset,
+                                               (System.Drawing.Size)((object)mc.button_size),
+                                               false);
+                               }
+                       }
+                       
+                       // set the week offset and draw week nums if needed
+                       int col_offset = (mc.ShowWeekNumbers) ? 1 : 0;
+                       Rectangle day_name_rect = new Rectangle(
+                               rectangle.X,
+                               rectangle.Y + title_size.Height,
+                               (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);
+                               // draw the day names 
+                               DayOfWeek first_day_of_week = mc.GetDayOfWeek(mc.FirstDayOfWeek);
+                               for (int i=0; i < 7; i++) \r
+                               {
+                                       int position = i - (int) first_day_of_week;
+                                       if (position < 0) \r
+                                       {
+                                               position = 7 + position;
+                                       }
+                                       // draw it
+                                       Rectangle day_rect = new Rectangle(
+                                               day_name_rect.X + ((i + col_offset)* date_cell_size.Width),
+                                               day_name_rect.Y,
+                                               date_cell_size.Width,
+                                               date_cell_size.Height);
+                                       dc.DrawString (((DayOfWeek)i).ToString().Substring(0, 3), mc.Font, ResPool.GetSolidBrush (mc.TitleBackColor), day_rect, text_format);
+                               }
+                               
+                               // draw the vertical divider
+                               int vert_divider_y = Math.Max(title_size.Height+ date_cell_size.Height-1, 0);
+                               dc.DrawLine (
+                                       ResPool.GetPen (mc.ForeColor),
+                                       rectangle.X + (col_offset * date_cell_size.Width) + mc.divider_line_offset,
+                                       rectangle.Y + vert_divider_y,
+                                       rectangle.Right - mc.divider_line_offset,
+                                       rectangle.Y + vert_divider_y);
+                       }
+
+
+                       // draw the actual date items in the grid (including the week numbers)
+                       Rectangle date_rect = new Rectangle (
+                               rectangle.X,
+                               rectangle.Y + title_size.Height + date_cell_size.Height,
+                               date_cell_size.Width,
+                               date_cell_size.Height);
+                       int month_row_count = 0;
+                       bool draw_week_num_divider = false;
+                       DateTime current_date = mc.GetFirstDateInMonthGrid ( new DateTime (this_month.Year, this_month.Month, 1));
+                       for (int i=0; i < 6; i++) \r
+                       {
+                               // establish if this row is in our clip_area
+                               Rectangle row_rect = new Rectangle (
+                                       rectangle.X,
+                                       rectangle.Y + title_size.Height + (date_cell_size.Height * (i+1)),
+                                       date_cell_size.Width * 7,
+                                       date_cell_size.Height);
+                               if (mc.ShowWeekNumbers) {
+                                       row_rect.Width += date_cell_size.Width;
+                               }
+               
+                               bool draw_row = row_rect.IntersectsWith (clip_rectangle);
+                               if (draw_row) {
+                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.BackColor), row_rect);
+                               }
+                               // establish if this is a valid week to draw
+                               if (mc.IsValidWeekToDraw (this_month, current_date, row, col)) {
+                                       month_row_count = i;
+                               }
+                               
+                               // draw the week number if required
+                               if (mc.ShowWeekNumbers && month_row_count == i) {
+                                       if (!draw_week_num_divider) {
+                                               draw_week_num_divider = draw_row;
+                                       }
+                                       // get the week for this row
+                                       int week = mc.GetWeekOfYear (current_date);     
+
+                                       if (draw_row) {
+                                               dc.DrawString (
+                                                       week.ToString(),
+                                                       mc.Font,
+                                                       ResPool.GetSolidBrush (mc.TitleBackColor),
+                                                       date_rect,
+                                                       text_format);
+                                       }
+                                       date_rect.Offset(date_cell_size.Width, 0);
+                               }
+                                                               
+                               // only draw the days if we have to
+                               if(month_row_count == i) {
+                                       for (int j=0; j < 7; j++) \r
+                                       {
+                                               if (draw_row) {
+                                                       DrawMonthCalendarDate (
+                                                               dc,
+                                                               date_rect,
+                                                               mc,
+                                                               current_date,
+                                                               this_month,
+                                                               row,
+                                                               col);
                                                }
-                                               sub_item_rect.X += col.Wd;
+
+                                               // move the day on
+                                               current_date = current_date.AddDays(1);
+                                               date_rect.Offset(date_cell_size.Width, 0);
                                        }
+
+                                       // shift the rectangle down one row
+                                       int offset = (mc.ShowWeekNumbers) ? -8 : -7;
+                                       date_rect.Offset(offset*date_cell_size.Width, date_cell_size.Height);
                                }
                        }
-               }
 
-               // Sizing
-               public override Size ListViewCheckBoxSize {
-                       get { return new Size (16, 16); }
-               }
+                       // month_row_count is zero based, so add one
+                       month_row_count++;
 
-               public override int ListViewColumnHeaderHeight {
-                       get { return 16; }
+                       // draw week numbers if required
+                       if (draw_week_num_divider) {
+                               col_offset = 1;
+                               dc.DrawLine (
+                                       ResPool.GetPen (mc.ForeColor),
+                                       rectangle.X + date_cell_size.Width - 1,
+                                       rectangle.Y + title_size.Height + date_cell_size.Height + mc.divider_line_offset,
+                                       rectangle.X + date_cell_size.Width - 1,
+                                       rectangle.Y + title_size.Height + date_cell_size.Height + (month_row_count * date_cell_size.Height) - mc.divider_line_offset);
+                       }
                }
 
-               public override int ListViewDefaultColumnWidth {
-                       get { return 60; }
+               // draws the pervious or next button
+               private void DrawMonthCalendarButton (Graphics dc, Rectangle rectangle, MonthCalendar mc, Size title_size, int x_offset, Size button_size, bool is_previous) \r
+               {
+                       bool is_clicked = false;
+                       Rectangle button_rect;
+                       Rectangle arrow_rect = new Rectangle (rectangle.X, rectangle.Y, 4, 7);
+                       Point[] arrow_path = new Point[3];
+                       // prepare the button
+                       if (is_previous) \r
+                       {
+                               is_clicked = mc.is_previous_clicked;
+                               button_rect = new Rectangle (
+                                       rectangle.X + 1 + x_offset,
+                                       rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
+                                       Math.Max(button_size.Width - 1, 0),
+                                       Math.Max(button_size.Height - 1, 0));
+                               arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
+                               arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
+                               if (is_clicked) {
+                                       arrow_rect.Offset(1,1);
+                               }
+                               arrow_path[0] = new Point (arrow_rect.Right, arrow_rect.Y);
+                               arrow_path[1] = new Point (arrow_rect.X, arrow_rect.Y + arrow_rect.Height/2);
+                               arrow_path[2] = new Point (arrow_rect.Right, arrow_rect.Bottom);
+                       }
+                       else
+                       {
+                               is_clicked = mc.is_next_clicked;
+                               button_rect = new Rectangle (
+                                       rectangle.Right - 1 - x_offset - button_size.Width,
+                                       rectangle.Y + 1 + ((title_size.Height - button_size.Height)/2),
+                                       Math.Max(button_size.Width - 1, 0),
+                                       Math.Max(button_size.Height - 1, 0));
+                               arrow_rect.X = button_rect.X + ((button_rect.Width - arrow_rect.Width)/2);
+                               arrow_rect.Y = button_rect.Y + ((button_rect.Height - arrow_rect.Height)/2);
+                               if (is_clicked) {
+                                       arrow_rect.Offset(1,1);
+                               }
+                               arrow_path[0] = new Point (arrow_rect.X, arrow_rect.Y);
+                               arrow_path[1] = new Point (arrow_rect.Right, arrow_rect.Y + arrow_rect.Height/2);
+                               arrow_path[2] = new Point (arrow_rect.X, arrow_rect.Bottom);                            
+                       }
+
+                       // fill the background
+                       dc.FillRectangle (SystemBrushes.Control, button_rect);
+                       // draw the border
+                       if (is_clicked) {
+                               dc.DrawRectangle (SystemPens.ControlDark, button_rect);
+                       }
+                       else {
+                               CPDrawBorder3D (dc, button_rect, Border3DStyle.Raised, Border3DSide.All);
+                       }
+                       // draw the arrow
+                       dc.FillPolygon (SystemBrushes.ControlText, arrow_path);                 
                }
+               
 
-               public override int ListViewVerticalSpacing {
-                       get { return 22; }
-               }
+               // draws one day in the calendar grid
+               private void DrawMonthCalendarDate (Graphics dc, Rectangle rectangle, MonthCalendar mc, DateTime date, DateTime month, int row, int col) {
+                       Color date_color = mc.ForeColor;
+                       Rectangle interior = new Rectangle (rectangle.X, rectangle.Y, Math.Max(rectangle.Width - 1, 0), Math.Max(rectangle.Height - 1, 0));
+
+                       // find out if we are the lead of the first calendar or the trail of the last calendar                                          
+                       if (date.Year != month.Year || date.Month != month.Month) {
+                               DateTime check_date = month.AddMonths (-1);
+                               // check if it's the month before 
+                               if (check_date.Year == date.Year && check_date.Month == date.Month && row == 0 && col == 0) {
+                                       date_color = mc.TrailingForeColor;
+                               } else {
+                                       // check if it's the month after
+                                       check_date = month.AddMonths (1);
+                                       if (check_date.Year == date.Year && check_date.Month == date.Month && row == mc.CalendarDimensions.Height-1 && col == mc.CalendarDimensions.Width-1) {
+                                               date_color = mc.TrailingForeColor;
+                                       } else {
+                                               return;
+                                       }
+                               }
+                       } else {
+                               date_color = mc.ForeColor;
+                       }
+
+
+                       if (date == mc.SelectionStart && date == mc.SelectionEnd) {
+                               // see if the date is in the start of selection
+                               date_color = mc.BackColor;
+                               // draw the left hand of the back ground
+                               Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);                                
+                               dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 0, 359);
+                       } else if (date == mc.SelectionStart) {
+                               // see if the date is in the start of selection
+                               date_color = mc.BackColor;
+                               // draw the left hand of the back ground
+                               Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);                                
+                               dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 90, 180);
+                               // fill the other side as a straight rect
+                               if (date < mc.SelectionEnd) \r
+                               {
+                                       // use rectangle instead of rectangle to go all the way to edge of rect
+                                       selection_rect.X = (int) Math.Floor((double)(rectangle.X + rectangle.Width / 2));
+                                       selection_rect.Width = Math.Max(rectangle.Right - selection_rect.X, 0);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
+                               }
+                       } else if (date == mc.SelectionEnd) {
+                               // see if it is the end of selection
+                               date_color = mc.BackColor;
+                               // draw the left hand of the back ground
+                               Rectangle selection_rect = Rectangle.Inflate(rectangle, -3, -3);
+                               dc.FillPie (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect, 270, 180);
+                               // fill the other side as a straight rect
+                               if (date > mc.SelectionStart) {
+                                       selection_rect.X = rectangle.X;
+                                       selection_rect.Width = rectangle.Width - (rectangle.Width / 2);
+                                       dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
+                               }
+                       } else if (date > mc.SelectionStart && date < mc.SelectionEnd) {
+                               // now see if it's in the middle
+                               date_color = mc.BackColor;
+                               // draw the left hand of the back ground
+                               Rectangle selection_rect = Rectangle.Inflate(rectangle, 0, -3);
+                               dc.FillRectangle (ResPool.GetSolidBrush (mc.TitleBackColor), selection_rect);
+                       }
+
+                       // set up some standard string formating variables
+                       StringFormat text_format = new StringFormat();
+                       text_format.LineAlignment = StringAlignment.Center;
+                       text_format.Alignment = StringAlignment.Center;
+                       
 
-               public override int ListViewEmptyColumnWidth {
-                       get { return 10; }
-               }
+                       // establish if it's a bolded font
+                       Font font;
+                       if (mc.IsBoldedDate (date)) {
+                               font = new Font (mc.Font.FontFamily, mc.Font.Size, mc.Font.Style | FontStyle.Bold);
+                       } else {
+                               font = mc.Font;
+                       }
 
-               public override int ListViewHorizontalSpacing {
-                       get { return 10; }
+                       // just draw the date now
+                       dc.DrawString (date.Day.ToString(), font, ResPool.GetSolidBrush (date_color), rectangle, text_format);
+
+                       // today circle if needed
+                       if (mc.ShowTodayCircle && date == DateTime.Now.Date) {
+                               DrawTodayCircle (dc, interior);
+                       }
+
+                       // 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);
+                               }
+                       }
                }
 
-               public override Size ListViewDefaultSize {
-                       get { return new Size (121, 97); }
+               private void DrawTodayCircle (Graphics dc, Rectangle rectangle) {
+                       Color circle_color = Color.FromArgb (248, 0, 0);
+                       // draw the left hand of the circle 
+                       Rectangle lhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 4, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 5, 0));
+                       Rectangle rhs_circle_rect = new Rectangle (rectangle.X + 1, rectangle.Y + 1, Math.Max(rectangle.Width - 2, 0), Math.Max(rectangle.Height - 2, 0));
+                       Point [] curve_points = new Point [3];
+                       curve_points [0] = new Point (lhs_circle_rect.X, rhs_circle_rect.Y + rhs_circle_rect.Height/12);
+                       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));
+                       }
                }
-               #endregion      // ListView
+
+               #endregion      // MonthCalendar
 
                #region Panel
                public override Size PanelDefaultSize {
@@ -1241,32 +2230,23 @@ namespace System.Windows.Forms
                #endregion      // Panel
 
                #region PictureBox
-               public override void DrawPictureBox (Graphics dc, PictureBox pb) {
+               public override void DrawPictureBox (Graphics dc, Rectangle clip, PictureBox pb) {
                        Rectangle client = pb.ClientRectangle;
-                       int x, y, width, height;
-
-                       dc.FillRectangle (new SolidBrush (pb.BackColor), client);
 
-                       x = y = 0;
                        if (pb.Image != null) {
                                switch (pb.SizeMode) {
                                case PictureBoxSizeMode.StretchImage:
-                                       width = client.Width;
-                                       height = client.Height;
+                                       dc.DrawImage (pb.Image, 0, 0, client.Width, client.Height);
                                        break;
+
                                case PictureBoxSizeMode.CenterImage:
-                                       width = client.Width;
-                                       height = client.Height;
-                                       x = width / 2;
-                                       y = (height - pb.Image.Height) / 2;
+                                       dc.DrawImage (pb.Image, (client.Width / 2) - (pb.Image.Width / 2), (client.Height / 2) - (pb.Image.Height / 2));
                                        break;
                                default:
                                        // Normal, AutoSize
-                                       width = client.Width;
-                                       height = client.Height;
+                                       dc.DrawImage(pb.Image, 0, 0);
                                        break;
                                }
-                               dc.DrawImage (pb.Image, x, y, width, height);
                        }
                        CPDrawBorderStyle (dc, client, pb.BorderStyle);
                }
@@ -1279,28 +2259,31 @@ namespace System.Windows.Forms
                #endregion      // PictureBox
 
                #region ProgressBar
-               public override void DrawProgressBar (Graphics dc, Rectangle clip_rectangle, ProgressBar progress_bar) {
-                       Rectangle       client_area             = progress_bar.client_area;
-                       Rectangle       paint_area              = progress_bar.paint_area;
-                       int             steps                   = (progress_bar.Maximum - progress_bar.Minimum) / progress_bar.step;
-                       int             space_betweenblocks     = 2;
-                       int             x;
+               public override void DrawProgressBar (Graphics dc, Rectangle clip_rect, ProgressBar ctrl) 
+               {
+                       Rectangle       block_rect;
+                       Rectangle       client_area = ctrl.client_area;
+                       int             space_betweenblocks     = 2;                    
                        int             block_width;
                        int             increment;
                        int             barpos_pixels;
-
-                       x = client_area.X;
+                       
                        block_width = ((client_area.Height) * 2 ) / 3;
-                       barpos_pixels = ((progress_bar.Value - progress_bar.Minimum) * client_area.Width) / (progress_bar.Maximum - progress_bar.Minimum);
+                       barpos_pixels = ((ctrl.Value - ctrl.Minimum) * client_area.Width) / (ctrl.Maximum - ctrl.Minimum);
                        increment = block_width + space_betweenblocks;
 
                        /* Draw border */
-                       CPDrawBorder3D (dc, progress_bar.paint_area, Border3DStyle.SunkenInner, Border3DSide.All, ColorButtonFace);
+                       CPDrawBorder3D (dc, ctrl.ClientRectangle, Border3DStyle.SunkenInner, Border3DSide.All & ~Border3DSide.Middle, ColorButtonFace);
                        
                        /* Draw Blocks */
-                       while ((x - client_area.X) < barpos_pixels) {
-                               dc.FillRectangle (br_progressbarblock, x, client_area.Y, block_width, client_area.Height);
-                               x  = x + increment;
+                       block_rect = new Rectangle (client_area.X, client_area.Y, block_width, client_area.Height);
+                       while ((block_rect.X - client_area.X) < barpos_pixels) {
+                               
+                               if (clip_rect.IntersectsWith (block_rect) == true) {                            
+                                       dc.FillRectangle (ResPool.GetSolidBrush (progressbarblock_color), block_rect);
+                               }                               
+                               
+                               block_rect.X  += increment;
                        }
                }
                
@@ -1329,6 +2312,7 @@ namespace System.Windows.Forms
                        text_format = new StringFormat();
                        text_format.Alignment = StringAlignment.Near;
                        text_format.LineAlignment = StringAlignment.Center;
+                       text_format.HotkeyPrefix = HotkeyPrefix.Show;
 
                        /* Calculate the position of text and checkbox rectangle */
                        if (radio_button.appearance!=Appearance.Button) {
@@ -1504,10 +2488,9 @@ namespace System.Windows.Forms
                                text_rectangle.Inflate(-4,-4);
                        } 
                        
-                       /* Place the text; to be compatible with Windows place it after the radiobutton has been drawn */
-                       sb=new SolidBrush(radio_button.ForeColor);
-                       dc.DrawString (radio_button.Text, radio_button.Font, sb, text_rectangle, text_format);
-                       sb.Dispose();
+                       /* 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);                           
@@ -1591,7 +2574,8 @@ namespace System.Windows.Forms
                #endregion      // RadioButton
 
                #region ScrollBar
-               public override void DrawScrollBar(Graphics dc, Rectangle clip_rectangle, ScrollBar bar) {
+               public override void DrawScrollBar (Graphics dc, Rectangle clip, ScrollBar bar)
+               {
                        int             scrollbutton_width = bar.scrollbutton_width;
                        int             scrollbutton_height = bar.scrollbutton_height;
                        Rectangle       first_arrow_area;
@@ -1611,47 +2595,66 @@ namespace System.Windows.Forms
                                bar.ThumbPos = thumb_pos;
 
                                /* Buttons */
-                               CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
-                               CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);                          
+                               if (clip.IntersectsWith (first_arrow_area))
+                                       CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Up, bar.firstbutton_state);
+                               if (clip.IntersectsWith (second_arrow_area))
+                                       CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Down, bar.secondbutton_state);
 
                                /* Background */
                                switch (bar.thumb_moving) {
                                case ScrollBar.ThumbMoving.None: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), 0,  
-                                               scrollbutton_height, bar.ClientRectangle.Width, bar.ClientRectangle.Height - (scrollbutton_height * 2));
-                                       
+                                       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, ColorButtonHilight, ColorButtonFace);
+                                               dc.FillRectangle (h, intersect);
+                                        }
                                        break;
                                }
                                case ScrollBar.ThumbMoving.Forward: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
-                                               0,  scrollbutton_height,
-                                               bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
-                                                                                               
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
-                                               0, thumb_pos.Y + thumb_pos.Height,
-                                               bar.ClientRectangle.Width, bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);
-                                               
+                                       Rectangle r = new Rectangle (0,  scrollbutton_height,
+                                                       bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
+                                       Rectangle intersect = Rectangle.Intersect (clip, r);
+
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
+
+                                       r.X = 0;
+                                       r.Y = thumb_pos.Y + thumb_pos.Height;
+                                       r.Width = bar.ClientRectangle.Width;
+                                       r.Height = bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
+
+                                       intersect = Rectangle.Intersect (clip, r);
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
                                        break;
                                }
                                
                                case ScrollBar.ThumbMoving.Backwards: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
-                                               0,  scrollbutton_height,
-                                               bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
-                                                                                               
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
-                                               0, thumb_pos.Y + thumb_pos.Height,
-                                               bar.ClientRectangle.Width, bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height);                                               
-                                               
+                                       Rectangle r = new Rectangle (0,  scrollbutton_height,
+                                                       bar.ClientRectangle.Width, thumb_pos.Y - scrollbutton_height);
+                                       Rectangle intersect = Rectangle.Intersect (clip, r);
+
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
+
+                                       r.X = 0;
+                                       r.Y = thumb_pos.Y + thumb_pos.Height;
+                                       r.Width = bar.ClientRectangle.Width; 
+                                       r.Height = bar.ClientRectangle.Height -  (thumb_pos.Y + thumb_pos.Height) - scrollbutton_height;
+
+                                       intersect = Rectangle.Intersect (clip, r);
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
                                        break;
                                }
                                
                                default:
                                        break;
                                }
-                                       
-                       }
-                       else {
+                       } else {
                                first_arrow_area = new Rectangle(0, 0, scrollbutton_width, bar.Height);
                                bar.FirstArrowArea = first_arrow_area;
 
@@ -1662,54 +2665,66 @@ namespace System.Windows.Forms
                                bar.ThumbPos = thumb_pos;
 
                                /* Buttons */
-                               CPDrawScrollButton (dc, bar.FirstArrowArea, ScrollButton.Left, bar.firstbutton_state);
-                               CPDrawScrollButton (dc, bar.SecondArrowArea, ScrollButton.Right, bar.secondbutton_state);
+                               if (clip.IntersectsWith (first_arrow_area))
+                                       CPDrawScrollButton (dc, first_arrow_area, ScrollButton.Left, bar.firstbutton_state);
+                               if (clip.IntersectsWith (second_arrow_area))
+                                       CPDrawScrollButton (dc, second_arrow_area, ScrollButton.Right, bar.secondbutton_state);
 
-                               /* Background */
-                               //dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width, 
-                               //      0, area.Width - (scrollbutton_width * 2), area.Height);
-                                       
+                               /* Background */                                        
                                switch (bar.thumb_moving) {
                                case ScrollBar.ThumbMoving.None: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), scrollbutton_width,
-                                               0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
-                                       
+                                       Rectangle r = new Rectangle (scrollbutton_width,
+                                                       0, bar.ClientRectangle.Width - (scrollbutton_width * 2), bar.ClientRectangle.Height);
+                                       Rectangle intersect = Rectangle.Intersect (clip, r);
+
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
                                        break;
                                }
                                
                                case ScrollBar.ThumbMoving.Forward: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
-                                               scrollbutton_width,  0,
-                                               thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
-                                                                                               
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
-                                               thumb_pos.X + thumb_pos.Width, 0,
-                                               bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
-                                               
+                                       Rectangle r = new Rectangle (scrollbutton_width,  0,
+                                                       thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
+                                       Rectangle intersect = Rectangle.Intersect (clip, r);
+
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
+
+                                       r.X = thumb_pos.X + thumb_pos.Width;
+                                       r.Y = 0;
+                                       r.Width = bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
+                                       r.Height = bar.ClientRectangle.Height;
+
+                                       intersect = Rectangle.Intersect (clip, r);
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
                                        break;
                                }
                                
                                case ScrollBar.ThumbMoving.Backwards: {
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black),
-                                               scrollbutton_width,  0,
-                                               thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
-                                                                                               
-                                       dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace),
-                                               thumb_pos.X + thumb_pos.Width, 0,
-                                               bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width, bar.ClientRectangle.Height);
+                                       Rectangle r = new Rectangle (scrollbutton_width,  0,
+                                                       thumb_pos.X - scrollbutton_width, bar.ClientRectangle.Height);
+                                       Rectangle intersect = Rectangle.Intersect (clip, r);
 
-                                               
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, Color.FromArgb (255, 63,63,63), Color.Black), intersect);
+
+                                       r.X = thumb_pos.X + thumb_pos.Width;
+                                       r.Y = 0;
+                                       r.Width = bar.ClientRectangle.Width -  (thumb_pos.X + thumb_pos.Width) - scrollbutton_width;
+                                       r.Height = bar.ClientRectangle.Height;
+
+                                       intersect = Rectangle.Intersect (clip, r);
+                                       if (intersect != Rectangle.Empty)
+                                               dc.FillRectangle (ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace), intersect);
                                        break;
                                }
-                               
-                               default:
-                                       break;
                                }
                        }
 
                        /* Thumb */
-                       if (bar.Enabled)
-                               DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);
+                       if (bar.Enabled && thumb_pos.Width > 0 && thumb_pos.Height > 0 && clip.IntersectsWith (thumb_pos))
+                               DrawScrollButtonPrimitive (dc, thumb_pos, ButtonState.Normal);                          
                }
 
                public override int ScrollBarButtonSize {
@@ -1718,23 +2733,30 @@ namespace System.Windows.Forms
                #endregion      // ScrollBar
 
                #region StatusBar
-               public  override void DrawStatusBar (Graphics dc, Rectangle clip_rectangle, StatusBar sb) {
-                       Rectangle       area        = sb.paint_area;
-                       int             horz_border = 2;
-                       int             vert_border = 2;
+               public  override void DrawStatusBar (Graphics dc, Rectangle clip, StatusBar sb) {
+                       Rectangle area = sb.ClientRectangle;
+                       int horz_border = 2;
+                       int vert_border = 2;
 
-                       dc.FillRectangle (GetControlBackBrush (sb.BackColor), area);
+                       dc.FillRectangle (GetControlBackBrush (sb.BackColor), clip);
                        
-                       if (sb.ShowPanels && sb.Panels.Count == 0) {
-                               // Create a default panel.
-                               SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
-                               
-                               StatusBarPanel panel = new StatusBarPanel ();
-                               Rectangle new_area = new Rectangle (area.X + horz_border,
-                                       area.Y + horz_border,
-                                       area.Width - StatusBarSizeGripWidth - horz_border,
-                                       area.Height - horz_border);
-                               DrawStatusBarPanel (dc, new_area, -1, br_forecolor, panel);
+                       if (sb.Panels.Count == 0 && sb.Text != String.Empty) {
+                               string text = sb.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);
+                                       if (text [0] == '\t') {
+                                               string_format.Alignment = StringAlignment.Far;
+                                               text = text.Substring (1);
+                                       }
+                               }
+               
+                               dc.DrawString (text, sb.Font, ResPool.GetSolidBrush (sb.ForeColor),
+                                               new Rectangle(area.X + 2, area.Y + 2, area.Width - 4, area.Height - 4), string_format);
                        } else if (sb.ShowPanels) {
                                SolidBrush br_forecolor = GetControlForeBrush (sb.ForeColor);
                                int prev_x = area.X + horz_border;
@@ -1743,7 +2765,8 @@ namespace System.Windows.Forms
                                        Rectangle pr = new Rectangle (prev_x, y,
                                                sb.Panels [i].Width, area.Height);
                                        prev_x += pr.Width + StatusBarHorzGapWidth;
-                                       DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
+                                       if (pr.IntersectsWith (clip))
+                                               DrawStatusBarPanel (dc, pr, i, br_forecolor, sb.Panels [i]);
                                }
                        }
 
@@ -1776,8 +2799,6 @@ namespace System.Windows.Forms
                        int left = area.Left;
                        if (panel.Icon != null) {
                                left += 2;
-                               int size = area.Height - border_size;
-                               Rectangle ia = new Rectangle (left, border_size, size, size);
                                dc.DrawIcon (panel.Icon, left, area.Top);
                                left += panel.Icon.Width;
                        }
@@ -1787,8 +2808,7 @@ namespace System.Windows.Forms
 
                        string text = panel.Text;
                        StringFormat string_format = new StringFormat ();
-                       string_format.LineAlignment = StringAlignment.Center;
-                       string_format.Alignment = StringAlignment.Near;
+                       string_format.Trimming = StringTrimming.Character;
                        string_format.FormatFlags = StringFormatFlags.NoWrap;
 
                        if (text [0] == '\t') {
@@ -1800,10 +2820,13 @@ namespace System.Windows.Forms
                                }
                        }
 
-                       float x = left + border_size;
-                       float y = ((area.Bottom - area.Top) / 2.0F) + border_size;
-
-                       dc.DrawString (text, panel.Parent.Font, br_forecolor, x, y, string_format);
+                       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);
                }
 
                public override int StatusBarSizeGripWidth {
@@ -1834,7 +2857,7 @@ namespace System.Windows.Forms
 
                        if (tab.Alignment == TabAlignment.Top) {
                                for (int r = tab.TabPages.Count; r > 0; r--) {
-                                       for (int i = 0; i < tab.TabPages.Count; i++) {
+                                       for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
                                                if (i == tab.SelectedIndex)
                                                        continue;
                                                if (r != tab.TabPages [i].Row)
@@ -1847,7 +2870,7 @@ namespace System.Windows.Forms
                                }
                        } else {
                                for (int r = 0; r < tab.TabPages.Count; r++) {
-                                       for (int i = 0; i < tab.TabPages.Count; i++) {
+                                       for (int i = tab.SliderPos; i < tab.TabPages.Count; i++) {
                                                if (i == tab.SelectedIndex)
                                                        continue;
                                                if (r != tab.TabPages [i].Row)
@@ -1860,8 +2883,10 @@ namespace System.Windows.Forms
                                }
                        }
 
-                       if (tab.SelectedIndex != -1) {
-                               DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, tab.GetTabRect (tab.SelectedIndex), true);
+                       if (tab.SelectedIndex != -1 && tab.SelectedIndex >= tab.SliderPos) {
+                               Rectangle rect = tab.GetTabRect (tab.SelectedIndex);
+                               if (rect.IntersectsWith (area))
+                                       DrawTab (dc, tab.TabPages [tab.SelectedIndex], tab, rect, true);
                        }
 
                        if (tab.ShowSlider) {
@@ -1962,8 +2987,7 @@ namespace System.Windows.Forms
 
                private int DrawTab (Graphics dc, TabPage page, TabControl tab, Rectangle bounds, bool is_selected)
                {
-                       int FlatButtonSpacing = 8;
-                       int RoundCornerSize = 5;
+                       int FlatButtonSpacing = 8;                      
                        Rectangle interior;
                        int res = bounds.Width;
 
@@ -1989,6 +3013,16 @@ namespace System.Windows.Forms
                                }
 
                                interior = new Rectangle (bounds.Left + 2, bounds.Top + 2, bounds.Width - 4, bounds.Height - 4);
+
+                                
+                               StringFormat string_format = new StringFormat ();
+                               string_format.Alignment = StringAlignment.Center;
+                               string_format.LineAlignment = StringAlignment.Center;
+                               string_format.FormatFlags = StringFormatFlags.NoWrap;
+
+                               interior.Y++;
+                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
+                               interior.Y--;
                        } else {
                                Pen light = ResPool.GetPen (ControlPaint.LightLight (tab.BackColor));
 
@@ -2015,7 +3049,8 @@ namespace System.Windows.Forms
                                                string_format.LineAlignment = StringAlignment.Center;
                                                string_format.FormatFlags = StringFormatFlags.NoWrap;
                                                interior.Y++;
-                                               dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
+                                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
+                                               interior.Y--;
                                        }
 
                                        break;
@@ -2042,7 +3077,8 @@ namespace System.Windows.Forms
                                                string_format.LineAlignment = StringAlignment.Center;
                                                string_format.FormatFlags = StringFormatFlags.NoWrap;
                                                interior.Y++;
-                                               dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
+                                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
+                                               interior.Y--;
                                        }
 
                                        break;
@@ -2073,7 +3109,7 @@ namespace System.Windows.Forms
                                                int ho = interior.Height / 2;
                                                dc.TranslateTransform (interior.X + wo, interior.Y + ho);
                                                dc.RotateTransform (180);
-                                               dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), 0, 0, string_format);
+                                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), 0, 0, string_format);
                                                dc.ResetTransform ();
                                        }
 
@@ -2102,19 +3138,16 @@ namespace System.Windows.Forms
                                                string_format.FormatFlags = StringFormatFlags.NoWrap;
                                                string_format.FormatFlags = StringFormatFlags.DirectionVertical;
                                                interior.X++;
-                                               dc.DrawString (page.Text, page.Font, new SolidBrush (SystemColors.ControlText), interior, string_format);
+                                               dc.DrawString (page.Text, page.Font, ThemeEngine.Current.ResPool.GetSolidBrush (SystemColors.ControlText), interior, string_format);
+                                               interior.X--;
                                        }
 
                                        break;
                                }
                        }
 
-                       
                        if (page.Focused) {
-                               using (Pen pen = new Pen (Color.Black, 1) ) {
-                                       pen.DashStyle = DashStyle.Dot;
-                                       dc.DrawRectangle (pen, interior);
-                               }
+                               CPDrawFocusRectangle (dc, interior, tab.ForeColor, tab.BackColor);
                        }
 
                        return res;
@@ -2269,7 +3302,7 @@ namespace System.Windows.Forms
                                                        button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, 
                                                                imgRect.Height, button.ImageIndex);
                                                else {
-                                                       dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
+                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
                                                        ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
                                                                Border3DSide.Right | Border3DSide.Bottom);
                                                }
@@ -2287,7 +3320,7 @@ namespace System.Windows.Forms
                                                        button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
                                                                imgRect.Height, button.ImageIndex);
                                                else {
-                                                       dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
+                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
                                                        ControlPaint.DrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
                                                                Border3DSide.Right | Border3DSide.Bottom);
                                                }
@@ -2306,7 +3339,7 @@ namespace System.Windows.Forms
                                                        button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
                                                                imgRect.Height, button.ImageIndex);
                                                else {
-                                                       dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
+                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
                                                        CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
                                                                Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
                                                }
@@ -2325,7 +3358,7 @@ namespace System.Windows.Forms
                                                        button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width,
                                                                imgRect.Height, button.ImageIndex);
                                                else {
-                                                       dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
+                                                       dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
                                                        CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
                                                                Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
                                                }
@@ -2359,7 +3392,7 @@ namespace System.Windows.Forms
                                                button.Parent.ImageList.Draw (dc, imgRect.X, imgRect.Y, imgRect.Width, imgRect.Height,
                                                        button.ImageIndex);
                                        else {
-                                               dc.FillRectangle (new SolidBrush (ColorGrayText), imgRect);
+                                               dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (ColorGrayText), imgRect);
                                                CPDrawBorder3D (dc, imgRect, Border3DStyle.SunkenOuter,
                                                        Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
                                        }
@@ -2411,25 +3444,22 @@ namespace System.Windows.Forms
                #endregion      // ToolBar
 
                #region ToolTip
-               public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip tt) {
-                       Control control;
-
-                       control = tt.tooltip_window;
+               public override void DrawToolTip(Graphics dc, Rectangle clip_rectangle, ToolTip.ToolTipWindow control) {
                        dc.FillRectangle(ResPool.GetSolidBrush(this.ColorInfoWindow), control.client_rect);
                        dc.DrawRectangle(ResPool.GetPen(this.ColorWindowFrame), 0, 0, control.Width-1, control.Height-1);
-                       dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, tt.tooltip_window.string_format);
+                       dc.DrawString(control.text, control.Font, ResPool.GetSolidBrush(this.ColorInfoText), control.client_rect, control.string_format);
                }
 
-               public override Size ToolTipSize(ToolTip tt, string text) {
+               public override Size ToolTipSize(ToolTip.ToolTipWindow tt, string text) {
                        SizeF   sizef;
 
-                       sizef = tt.tooltip_window.DeviceContext.MeasureString(text, tt.tooltip_window.Font);\r
-                       return new Size((int)sizef.Width+2, (int)sizef.Height+3);               // Need space for the border\r
+                       sizef = tt.DeviceContext.MeasureString(text, tt.Font);
+                       return new Size((int)sizef.Width+2, (int)sizef.Height+3);               // Need space for the border
                }
                #endregion      // ToolTip
 
                #region TrackBar
-               private void DrawTrackBar_Vertical (Graphics dc, Rectangle area, TrackBar tb,
+               private void DrawTrackBar_Vertical (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
                        ref Rectangle thumb_pos, ref Rectangle thumb_area,  Brush br_thumb,
                        float ticks, int value_pos, bool mouse_value) {                 
 
@@ -2439,7 +3469,8 @@ namespace System.Windows.Forms
                        float pixel_len;
                        float pixels_betweenticks;
                        const int space_from_right = 8;
-                       const int space_from_left = 8;                  
+                       const int space_from_left = 8;
+                       Rectangle area = tb.ClientRectangle;
                        
                        switch (tb.TickStyle)   {
                        case TickStyle.BottomRight:
@@ -2570,38 +3601,49 @@ namespace System.Windows.Forms
                        }
 
                        pixel_len = thumb_area.Height - 11;
-                       pixels_betweenticks = pixel_len / ticks;                                
+                       pixels_betweenticks = pixel_len / ticks;
+                       
+                       thumb_area.X = thumb_pos.X;
+                       thumb_area.Y = channel_startpoint.Y;
+                       thumb_area.Width = thumb_pos.Height;
                        
                        /* Draw ticks*/
-                       if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
-                               ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { 
-                               
-                               for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks)  {                                       
-                                       if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
-                                               dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y  + inc, 
-                                                       area.X + bottomtick_startpoint.X  + 3, area.Y + bottomtick_startpoint.Y + inc);
-                                       else
-                                               dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y  + inc, 
-                                                       area.X + bottomtick_startpoint.X  + 2, area.Y + bottomtick_startpoint.Y + inc);
+                       Region outside = new Region (area);
+                       outside.Exclude (thumb_area);                   
+                       
+                       if (outside.IsVisible (clip_rectangle)) {                               
+                               if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
+                                       ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) { 
+                                       
+                                       for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks)  {                                       
+                                               if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X , area.Y + bottomtick_startpoint.Y  + inc, 
+                                                               area.X + bottomtick_startpoint.X  + 3, area.Y + bottomtick_startpoint.Y + inc);
+                                               else
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X, area.Y + bottomtick_startpoint.Y  + inc, 
+                                                               area.X + bottomtick_startpoint.X  + 2, area.Y + bottomtick_startpoint.Y + inc);
+                                       }
+                               }
+       
+                               if (pixels_betweenticks > 0 &&  ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
+                                       ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+       
+                                       pixel_len = thumb_area.Height - 11;
+                                       pixels_betweenticks = pixel_len / ticks;
+                                       
+                                       for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
+                                               if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X  - 3 , area.Y + toptick_startpoint.Y + inc, 
+                                                               area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
+                                               else
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X  - 2, area.Y + toptick_startpoint.Y + inc, 
+                                                               area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y  + inc);
+                                       }                       
                                }
                        }
-
-                       if (pixels_betweenticks > 0 &&  ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
-                               ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-
-                               pixel_len = thumb_area.Height - 11;
-                               pixels_betweenticks = pixel_len / ticks;
-                               
-                               for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {
-                                       //Console.WriteLine ("{0} {1} {2}", pixel_len, inc, pixels_betweenticks );
-                                       if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
-                                               dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X  - 3 , area.Y + toptick_startpoint.Y + inc, 
-                                                       area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y + inc);
-                                       else
-                                               dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X  - 2, area.Y + toptick_startpoint.Y + inc, 
-                                                       area.X + toptick_startpoint.X, area.Y + toptick_startpoint.Y  + inc);
-                               }                       
-                       }
+                       
+                       outside.Dispose ();
+                       
                }
 
                /* 
@@ -2614,7 +3656,7 @@ namespace System.Windows.Forms
                                - Ticks are draw at (channel.Witdh - 10) / (Maximum - Minimum)
                                
                */
-               private void DrawTrackBar_Horizontal (Graphics dc, Rectangle area, TrackBar tb,
+               private void DrawTrackBar_Horizontal (Graphics dc, Rectangle clip_rectangle, TrackBar tb,
                        ref Rectangle thumb_pos, ref Rectangle thumb_area, Brush br_thumb,
                        float ticks, int value_pos, bool mouse_value) {                 
                        Point toptick_startpoint = new Point ();
@@ -2623,7 +3665,8 @@ namespace System.Windows.Forms
                        float pixel_len;
                        float pixels_betweenticks;
                        const int space_from_right = 8;
-                       const int space_from_left = 8;          
+                       const int space_from_left = 8;
+                       Rectangle area = tb.ClientRectangle;
                                                
                        switch (tb.TickStyle) {
                        case TickStyle.BottomRight:
@@ -2754,39 +3797,45 @@ namespace System.Windows.Forms
                        pixels_betweenticks = pixel_len / ticks;
 
                        /* Draw ticks*/
-                       if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
-                               ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {                         
-                               
-                               for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
-                                       if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
-                                               dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y, 
-                                                       area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
-                                       else
-                                               dc.DrawLine (pen_ticks, area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y, 
-                                                       area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
+                       thumb_area.Y = thumb_pos.Y;
+                       thumb_area.X = channel_startpoint.X;
+                       thumb_area.Height = thumb_pos.Height;
+                       Region outside = new Region (area);
+                       outside.Exclude (thumb_area);                   
+                       
+                       if (outside.IsVisible (clip_rectangle)) {                               
+                               if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.BottomRight) == TickStyle.BottomRight ||
+                                       ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {                         
+                                       
+                                       for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
+                                               if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y, 
+                                                               area.X + bottomtick_startpoint.X + inc , area.Y + bottomtick_startpoint.Y + 3);
+                                               else
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y, 
+                                                               area.X + bottomtick_startpoint.X + inc, area.Y + bottomtick_startpoint.Y + 2);
+                                       }
+                               }
+       
+                               if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
+                                       ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
+                                       
+                                       for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
+                                               if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3, 
+                                                               area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
+                                               else
+                                                       dc.DrawLine (ResPool.GetPen (pen_ticks_color), area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2, 
+                                                               area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
+                                       }                       
                                }
                        }
-
-                       if (pixels_betweenticks > 0 && ((tb.TickStyle & TickStyle.TopLeft) == TickStyle.TopLeft ||
-                               ((tb.TickStyle & TickStyle.Both) == TickStyle.Both))) {
-                               
-                               for (float inc = 0; inc < (pixel_len + 1); inc += pixels_betweenticks) {                                        
-                                       if (inc == 0 || (inc +  pixels_betweenticks) >= pixel_len +1)
-                                               dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y - 3, 
-                                                       area.X + toptick_startpoint.X + inc , area.Y + toptick_startpoint.Y);
-                                       else
-                                               dc.DrawLine (pen_ticks, area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y - 2, 
-                                                       area.X + toptick_startpoint.X + inc, area.Y + toptick_startpoint.Y );
-                               }                       
-                       }
+                       
+                       outside.Dispose ();                     
                }
 
-               public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb) {
-//public override void DrawTrackBar (Graphics dc, 
-//Rectangle area, 
-//TrackBar tb,
-//ref Rectangle thumb_pos, 
-//ref Rectangle thumb_area,  
+               public override void DrawTrackBar (Graphics dc, Rectangle clip_rectangle, TrackBar tb) 
+               {
                        Brush           br_thumb;
                        int             value_pos;
                        bool            mouse_value;
@@ -2794,7 +3843,7 @@ namespace System.Windows.Forms
                        Rectangle       area;
                        Rectangle       thumb_pos = tb.ThumbPos;
                        Rectangle       thumb_area = tb.ThumbArea;
-
+                       
                        if (tb.thumb_pressed) {
                                value_pos = tb.thumb_mouseclick;
                                mouse_value = true;
@@ -2803,7 +3852,7 @@ namespace System.Windows.Forms
                                mouse_value = false;
                        }
 
-                       area = tb.paint_area;
+                       area = tb.ClientRectangle;
 
                        if (tb.thumb_pressed == true) {
                                br_thumb = (Brush) ResPool.GetHatchBrush (HatchStyle.Percent50, ColorButtonHilight, ColorButtonFace);
@@ -2814,9 +3863,9 @@ namespace System.Windows.Forms
                        
                        /* Control Background */
                        if (tb.BackColor == DefaultControlBackColor) {
-                               dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area);
+                               dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), clip_rectangle);
                        } else {
-                               dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), area);
+                               dc.FillRectangle (ResPool.GetSolidBrush (tb.BackColor), clip_rectangle);
                        }
                        
 
@@ -2828,11 +3877,11 @@ namespace System.Windows.Forms
                        }
 
                        if (tb.Orientation == Orientation.Vertical) {
-                               DrawTrackBar_Vertical (dc, area, tb, ref thumb_pos, ref thumb_area,
+                               DrawTrackBar_Vertical (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
                                        br_thumb, ticks, value_pos, mouse_value);
                        
                        } else {
-                               DrawTrackBar_Horizontal (dc, area, tb, ref thumb_pos, ref thumb_area,
+                               DrawTrackBar_Horizontal (dc, clip_rectangle, tb, ref thumb_pos, ref thumb_area,
                                        br_thumb, ticks, value_pos, mouse_value);
                        }
 
@@ -2856,6 +3905,15 @@ namespace System.Windows.Forms
                }
                #endregion      // VScrollBar
 
+               #region TreeView
+               public override Size TreeViewDefaultSize {\r
+                       get {\r
+                               return new Size (121, 97);\r
+                       }\r
+               }\r
+
+               #endregion
+
                #region ControlPaint
                private enum DrawFrameControlStates {
                        ButtonCheck             = 0x0000,
@@ -3147,7 +4205,10 @@ namespace System.Windows.Forms
                                ControlPaint.DrawBorder(graphics, rectangle, ColorButtonShadow, ButtonBorderStyle.Solid);
                        } else {
                                if ((state & (ButtonState.Pushed | ButtonState.Checked))!=0) {
-                                       CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
+                                       // this needs to render like a pushed button - jba
+                                       // CPDrawBorder3D(graphics, rectangle, Border3DStyle.Sunken, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
+                                       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 (ColorButtonFace)), trace_rectangle);
                                } else {
                                        CPDrawBorder3D(graphics, rectangle, Border3DStyle.Raised, Border3DSide.Left | Border3DSide.Top | Border3DSide.Right | Border3DSide.Bottom, ColorButtonFace);
                                }
@@ -3261,20 +4322,29 @@ namespace System.Windows.Forms
                }
                                
 
-               public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) {
-                       // 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));
-                       
-                       //Color                 colorForeInverted;
-                       Pen                     pen;
-
-                       //colorForeInverted=Color.FromArgb(Math.Abs(foreColor.R-255), Math.Abs(foreColor.G-255), Math.Abs(foreColor.B-255));
-                       //pen=new Pen(colorForeInverted, 1);
-                       // MS seems to always use black
-                       pen = ResPool.GetPen (Color.Black);
-                       graphics.DrawRectangle(pen, trace_rectangle);
+               public override void CPDrawFocusRectangle (Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) 
+               {                       
+                       Rectangle rect = rectangle;
+                       Pen pen;
+                       HatchBrush brush;
+                               
+                       if (backColor.GetBrightness () >= 0.5) {
+                               foreColor = Color.Transparent;
+                               backColor = Color.Black;
+                               
+                       } else {
+                               backColor = Color.FromArgb (Math.Abs (backColor.R-255), Math.Abs (backColor.G-255), Math.Abs (backColor.B-255));
+                               foreColor = Color.Black;
+                       }
+                                               
+                       brush = ResPool.GetHatchBrush (HatchStyle.Percent50, backColor, foreColor);
+                       pen = new Pen (brush, 1);
+                                               
+                       rect.Width--;
+                       rect.Height--;                  
                        
-                       DrawInnerFocusRectangle (graphics, Rectangle.Inflate (rectangle, -4, -4), backColor);
+                       graphics.DrawRectangle (pen, rect);
+                       pen.Dispose ();
                }
                
                public override void CPDrawGrabHandle (Graphics graphics, Rectangle rectangle, bool primary, bool enabled) {
@@ -3291,7 +4361,7 @@ namespace System.Windows.Forms
                        } else {
                                pen=new Pen(Color.White, 1);
                                if (enabled==true) {
-                                       sb=new SolidBrush(Color.Black);
+                                       sb=ThemeEngine.Current.ResPool.GetSolidBrush (Color.Black);
                                } else {
                                        sb=ResPool.GetSolidBrush (ColorButtonFace);
                                }
@@ -3360,30 +4430,33 @@ namespace System.Windows.Forms
                                the image grayscale. At least when having > 256 colors on
                                the display.
                        */
-
-                       ImageAttributes imageAttributes=new ImageAttributes();
-                       ColorMatrix                     colorMatrix=new ColorMatrix(new float[][] {
-                                                                                                         // This table would create a perfect grayscale image, based on luminance
-                                                                                                         //                            new float[]{0.3f,0.3f,0.3f,0,0},
-                                                                                                         //                            new float[]{0.59f,0.59f,0.59f,0,0},
-                                                                                                         //                            new float[]{0.11f,0.11f,0.11f,0,0},
-                                                                                                         //                            new float[]{0,0,0,1,0,0},
-                                                                                                         //                            new float[]{0,0,0,0,1,0},
-                                                                                                         //                            new float[]{0,0,0,0,0,1}
-
-                                                                                                         // This table generates a image that is grayscaled and then
-                                                                                                         // brightened up. Seems to match MS close enough.
-                                                                                                         new float[]{0.2f,0.2f,0.2f,0,0},
-                                                                                                         new float[]{0.41f,0.41f,0.41f,0,0},
-                                                                                                         new float[]{0.11f,0.11f,0.11f,0,0},
-                                                                                                         new float[]{0.15f,0.15f,0.15f,1,0,0},
-                                                                                                         new float[]{0.15f,0.15f,0.15f,0,1,0},
-                                                                                                         new float[]{0.15f,0.15f,0.15f,0,0,1}
-                                                                                                 });
-
-                       imageAttributes.SetColorMatrix(colorMatrix);
-                       graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttributes);
-                       imageAttributes.Dispose();
+                       
+                       if (imagedisabled_attributes == null) {                         
+                               imagedisabled_attributes = new ImageAttributes ();
+                               ColorMatrix colorMatrix=new ColorMatrix(new float[][] {
+                                         // This table would create a perfect grayscale image, based on luminance
+                                         //                            new float[]{0.3f,0.3f,0.3f,0,0},
+                                         //                            new float[]{0.59f,0.59f,0.59f,0,0},
+                                         //                            new float[]{0.11f,0.11f,0.11f,0,0},
+                                         //                            new float[]{0,0,0,1,0,0},
+                                         //                            new float[]{0,0,0,0,1,0},
+                                         //                            new float[]{0,0,0,0,0,1}
+               
+                                         // This table generates a image that is grayscaled and then
+                                         // brightened up. Seems to match MS close enough.
+                                         new float[]{0.2f,0.2f,0.2f,0,0},
+                                         new float[]{0.41f,0.41f,0.41f,0,0},
+                                         new float[]{0.11f,0.11f,0.11f,0,0},
+                                         new float[]{0.15f,0.15f,0.15f,1,0,0},
+                                         new float[]{0.15f,0.15f,0.15f,0,1,0},
+                                         new float[]{0.15f,0.15f,0.15f,0,0,1}
+                                 });
+                                 
+                                imagedisabled_attributes.SetColorMatrix (colorMatrix);
+                       }
+                       
+                       graphics.DrawImage(image, new Rectangle(x, y, image.Width, image.Height), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imagedisabled_attributes);
+                       
                }
 
 
@@ -3424,13 +4497,11 @@ namespace System.Windows.Forms
                                int                             centerX;
                                int                             centerY;
                                int                             shiftX;
-                               int                             shiftY;
 
                                rect=new Rectangle(rectangle.X+rectangle.Width/4, rectangle.Y+rectangle.Height/4, rectangle.Width/2, rectangle.Height/2);
                                centerX=rect.Left+rect.Width/2;
                                centerY=rect.Top+rect.Height/2;
                                shiftX=Math.Max(1, rect.Width/8);
-                               shiftY=Math.Max(1, rect.Height/8);
 
                                rect.X-=shiftX;
                                centerX-=shiftX;
@@ -3514,6 +4585,9 @@ namespace System.Windows.Forms
                        bool enabled = (state == ButtonState.Inactive) ? false: true;                   
                                        
                        DrawScrollButtonPrimitive (dc, area, state);
+                                               
+                       if (area.Width < 12 || area.Height < 12) /* Cannot see a thing at smaller sizes */
+                               return;
 
                        /* Paint arrows */
                        switch (type) {
@@ -3523,26 +4597,29 @@ namespace System.Windows.Forms
 
                                for (int i = 0; i < 3; i++)
                                        if (enabled)
-                                               dc.DrawLine (pen_arrow, x + i, y - i, x + i + 6 - 2*i, y - i);
+                                               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 (br_arrow, x + 3, area.Y + 6, 1, 1);                           
+                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
+                                       x + 3, area.Y + 6, 1, 1);
+                                       
                                break;
                        }
                        case ScrollButton.Down: {
-                               int x = area.X +  (area.Width / 2) - 4;
+                               int x = area.X +  (area.Width / 2) - 5;
                                int y = area.Y + 5;
 
                                for (int i = 4; i != 0; i--)
                                        if (enabled)
-                                               dc.DrawLine (pen_arrow, x + i, y + i, x + i + 8 - 2*i, y + i);
+                                               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 (br_arrow, x + 4, y + 4, 1, 1);
+                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
+                                       x + 4, y + 4, 1, 1);
                                break;
                        }
 
@@ -3552,25 +4629,27 @@ namespace System.Windows.Forms
 
                                for (int i = 0; i < 3; i++)
                                        if (enabled)
-                                               dc.DrawLine (pen_arrow, x - i, y + i, x - i, y + i + 6 - 2*i);
+                                               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 (br_arrow, x - 3, y + 3, 1, 1);
+                               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) - 4;
+                               int y = area.Y +  (area.Height / 2) - 5;
                                int x = area.X + 5;
 
                                for (int i = 4; i != 0; i--)
                                        if (enabled)
-                                               dc.DrawLine (pen_arrow, x + i, y + i, x + i, y + i + 8 - 2*i);
+                                               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 (br_arrow, x + 4, y + 4, 1, 1);                                
+                               dc.FillRectangle (enabled ? ResPool.GetSolidBrush (arrow_color) :  ResPool.GetSolidBrush (ColorGrayText),
+                                       x + 4, y + 4, 1, 1);
                                break;
                        }
 
@@ -3605,19 +4684,13 @@ namespace System.Windows.Forms
 
 
                public  override void CPDrawStringDisabled (Graphics graphics, string s, Font font, Color color, RectangleF layoutRectangle,
-                       StringFormat format) {
-                       SolidBrush      brush;
-
-                       brush=new SolidBrush(ControlPaint.Light(color, 95));
+                       StringFormat format) {                  
 
                        layoutRectangle.Offset(1.0f, 1.0f);
-                       graphics.DrawString(s, font, brush, layoutRectangle, format);
-
-                       brush.Color=ControlPaint.Light(color, 50);
+                       graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 95)), layoutRectangle, format);                   
                        layoutRectangle.Offset(-1.0f, -1.0f);
-                       graphics.DrawString(s, font, brush, layoutRectangle, format);
-
-                       brush.Dispose();
+                       graphics.DrawString(s, font, ResPool.GetSolidBrush (ControlPaint.Light(color, 50)), layoutRectangle, format);
+                       
                }
 
                private static void DrawBorderInternal(Graphics graphics, int startX, int startY, int endX, int endY,
@@ -3829,18 +4902,16 @@ namespace System.Windows.Forms
                        }
 
                        case CaptionButton.Help: {
-                               StringFormat    sf = new StringFormat();
-                               SolidBrush              sb = new SolidBrush(color);
+                               StringFormat    sf = new StringFormat();                                
                                Font                            font = new Font("Microsoft Sans Serif", captionRect.Height, FontStyle.Bold, GraphicsUnit.Pixel);
 
                                sf.Alignment=StringAlignment.Center;
                                sf.LineAlignment=StringAlignment.Center;
 
 
-                               graphics.DrawString("?", font, sb, captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
+                               graphics.DrawString("?", font, ThemeEngine.Current.ResPool.GetSolidBrush (color), captionRect.X+captionRect.Width/2+shift, captionRect.Y+captionRect.Height/2+shift+lineWidth/2, sf);
 
-                               sf.Dispose();
-                               sb.Dispose();
+                               sf.Dispose();                           
                                font.Dispose();
 
                                return;
@@ -3942,6 +5013,9 @@ namespace System.Windows.Forms
 //                                             hatchBrush.Dispose();
 //                                     }
 
+                                       // Clear the background
+                                       graphics.FillRectangle (SystemBrushes.Control, rectangle);
+
                                        if ((State & DrawFrameControlStates.Pushed)!=0 || (State & DrawFrameControlStates.Checked)!=0) {
                                                graphics.DrawRectangle (ResPool.GetPen (ControlPaint.Dark (ColorButtonFace)), trace_rectangle);
                                        } else if ((State & DrawFrameControlStates.Flat)!=0) {
@@ -4056,9 +5130,7 @@ namespace System.Windows.Forms
 
                                return;
                        }                       
-
-                       dc.FillRectangle (new SolidBrush (Color.Blue), area);
-                       
+       
                        dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, area.Width, 1);
                        dc.FillRectangle (ResPool.GetSolidBrush (ColorButtonFace), area.X, area.Y, 1, area.Height);
 
@@ -4085,13 +5157,19 @@ namespace System.Windows.Forms
                
                public override void CPDrawBorderStyle (Graphics dc, Rectangle area, BorderStyle border_style) {
                        switch (border_style){
-                       case BorderStyle.Fixed3D:                               
+                       case BorderStyle.Fixed3D:
                                dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X +area.Width, area.Y);
                                dc.DrawLine (ResPool.GetPen (ColorButtonShadow), area.X, area.Y, area.X, area.Y + area.Height);
                                dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X , area.Y + area.Height - 1, area.X + area.Width , 
                                        area.Y + area.Height - 1);
                                dc.DrawLine (ResPool.GetPen (ColorButtonHilight), area.X + area.Width -1 , area.Y, area.X + area.Width -1, 
                                        area.Y + area.Height);
+
+                               // FIXME: These colors are not correct. Microsoft uses different ones but I didn't find them.
+                               dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.X + 1, area.Bottom - 2, area.Right - 2, area.Bottom - 2);
+                               dc.DrawLine (ResPool.GetPen (ColorButtonLight), area.Right - 2, area.Top + 1, area.Right - 2, area.Bottom - 2);
+                               dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.X + 1, area.Bottom - 3);
+                               dc.DrawLine (ResPool.GetPen (ColorButtonDkShadow), area.X + 1, area.Top + 1, area.Right - 3, area.Top + 1);
                                break;
                        case BorderStyle.FixedSingle:
                                dc.DrawRectangle (ResPool.GetPen (ColorWindowFrame), area.X, area.Y, area.Width - 1, area.Height - 1);