2008-06-10 George Giolfan <georgegiolfan@yahoo.com>
authorGeorge Giolfan <ggiolfan@mono-cvs.ximian.com>
Tue, 10 Jun 2008 00:37:33 +0000 (00:37 -0000)
committerGeorge Giolfan <ggiolfan@mono-cvs.ximian.com>
Tue, 10 Jun 2008 00:37:33 +0000 (00:37 -0000)
* ComboBox.cs, Theme.cs, ThemeVisualStyles.cs, ThemeWin32Classic.cs: Added
support for rendering the border with VisualStyles.
* VisualStyleElement.cs: Added ComboBox border part and state constants.

svn path=/trunk/mcs/; revision=105385

mcs/class/Managed.Windows.Forms/System.Windows.Forms.VisualStyles/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms.VisualStyles/VisualStyleElement.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ComboBox.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/Theme.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeVisualStyles.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/ThemeWin32Classic.cs

index 31c5acf55c29bd79b8ff2f267aa3f8f4a61d9be5..d418bfbc32a8e6233595d27af6cc97623a198fb3 100644 (file)
@@ -1,3 +1,7 @@
+2008-06-10  George Giolfan  <georgegiolfan@yahoo.com>
+
+       * VisualStyleElement.cs: Added ComboBox border part and state constants.
+
 2008-06-10  George Giolfan  <georgegiolfan@yahoo.com>
 
        * GtkPlus.cs, IVisualStyles.cs, VisualStylesEngine.cs,
index 4d466d1bde2033dbfd3d3f167b83417547dfc267..df47033f22b802aa8b0e4774097de0c9a262e527 100644 (file)
@@ -37,7 +37,20 @@ namespace System.Windows.Forms.VisualStyles
                #region Class name/part/state constants
                private const string BUTTON = "BUTTON";
                private const string CLOCK = "CLOCK";
+               #region COMBOXBOX
                private const string COMBOBOX = "COMBOBOX";
+               enum COMBOBOXPARTS
+               {
+                       CP_BORDER = 4
+               }
+               enum BORDERSTATES
+               {
+                       CBB_NORMAL = 1,
+                       CBB_HOT,
+                       CBB_FOCUSED,
+                       CBB_DISABLED
+               }
+               #endregion
                private const string EDIT = "EDIT";
                private const string EXPLORERBAR = "EXPLORERBAR";
                private const string HEADER = "HEADER";
@@ -168,6 +181,41 @@ namespace System.Windows.Forms.VisualStyles
                                public static VisualStyleElement Normal { get { return VisualStyleElement.CreateElement (VisualStyleElement.COMBOBOX, 1, 1); } }
                                public static VisualStyleElement Pressed { get { return VisualStyleElement.CreateElement (VisualStyleElement.COMBOBOX, 1, 3); } }
                        }
+                       internal static class Border
+                       {
+                               public static VisualStyleElement Normal {
+                                       get {
+                                               return new VisualStyleElement (
+                                                       COMBOBOX,
+                                                       (int)COMBOBOXPARTS.CP_BORDER,
+                                                       (int)BORDERSTATES.CBB_NORMAL);
+                                       }
+                               }
+                               public static VisualStyleElement Hot {
+                                       get {
+                                               return new VisualStyleElement (
+                                                       COMBOBOX,
+                                                       (int)COMBOBOXPARTS.CP_BORDER,
+                                                       (int)BORDERSTATES.CBB_HOT);
+                                       }
+                               }
+                               public static VisualStyleElement Focused {
+                                       get {
+                                               return new VisualStyleElement (
+                                                       COMBOBOX,
+                                                       (int)COMBOBOXPARTS.CP_BORDER,
+                                                       (int)BORDERSTATES.CBB_FOCUSED);
+                                       }
+                               }
+                               public static VisualStyleElement Disabled {
+                                       get {
+                                               return new VisualStyleElement (
+                                                       COMBOBOX,
+                                                       (int)COMBOBOXPARTS.CP_BORDER,
+                                                       (int)BORDERSTATES.CBB_DISABLED);
+                                       }
+                               }
+                       }
                }
                #endregion
                #region ExplorerBar
index 0f196f4190e8b17b916581a89571d25db9657e0a..040c099b31c1e64aa44cdbb07aacc3071d2d0789 100644 (file)
@@ -1,3 +1,8 @@
+2008-06-10  George Giolfan  <georgegiolfan@yahoo.com>
+
+       * ComboBox.cs, Theme.cs, ThemeVisualStyles.cs, ThemeWin32Classic.cs: Added
+       support for rendering the border with VisualStyles.
+
 2008-06-10  George Giolfan  <georgegiolfan@yahoo.com>
 
        * InternalWindowManager.cs: Added ShowIcon. Fixed IconRectangleContains when
index ea7413c23ad0fe1633421c243c7e39e59a5f3a69..85b0ae97d3e2945a7f3b58185c47ec1f8062e245 100644 (file)
@@ -112,6 +112,7 @@ namespace System.Windows.Forms
                        MouseUp += new MouseEventHandler (OnMouseUpCB);
                        MouseMove += new MouseEventHandler (OnMouseMoveCB);
                        MouseWheel += new MouseEventHandler (OnMouseWheelCB);
+                       MouseEnter += new EventHandler (OnMouseEnter);
                        MouseLeave += new EventHandler (OnMouseLeave);
                        KeyDown +=new KeyEventHandler(OnKeyDownCB);
                }
@@ -792,6 +793,16 @@ namespace System.Windows.Forms
 
                #endregion Public Properties
 
+               #region Internal Properties
+               internal Rectangle ButtonArea {
+                       get { return button_area; }
+               }
+
+               internal Rectangle TextArea {
+                       get { return text_area; }
+               }
+               #endregion
+
                #region Public Methods
 #if NET_2_0
                [Obsolete ("This method has been deprecated")]
@@ -1428,21 +1439,7 @@ namespace System.Windows.Forms
                        is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
 #endif
 
-                       if (!Enabled)
-                               dc.FillRectangle (theme.ResPool.GetSolidBrush (theme.ColorControl), bounds);
-
-                       if (DropDownStyle == ComboBoxStyle.Simple)
-                               dc.FillRectangle (theme.ResPool.GetSolidBrush (Parent.BackColor), ClientRectangle);
-
-                       if (style == FlatStyle.Popup && (is_entered || Focused)) {
-                               Rectangle area = text_area;
-                               area.Height -= 1;
-                               area.Width -= 1;
-                               dc.DrawRectangle (theme.ResPool.GetPen (SystemColors.ControlDark), area);
-                               dc.DrawLine (theme.ResPool.GetPen (SystemColors.ControlDark), button_area.X - 1, button_area.Top, button_area.X - 1, button_area.Bottom);
-                       }
-                       if (!is_flat && clip.IntersectsWith (text_area))
-                               ControlPaint.DrawBorder3D (dc, text_area, Border3DStyle.Sunken);
+                       theme.ComboBoxDrawBackground (this, dc, clip, style);
 
                        int border = theme.Border3DSize.Width;
 
@@ -1718,10 +1715,21 @@ namespace System.Windows.Forms
                        Capture = true;
                }
 
+               void OnMouseEnter (object sender, EventArgs e)
+               {
+                       if (ThemeEngine.Current.CombBoxBackgroundHasHotElementStyle (this))
+                               Invalidate ();
+               }
+
                void OnMouseLeave (object sender, EventArgs e)
                {
-                       if (show_dropdown_button)
-                               DropDownButtonEntered = false;
+                       if (ThemeEngine.Current.CombBoxBackgroundHasHotElementStyle (this)) {
+                               drop_down_button_entered = false;
+                               Invalidate ();
+                       } else {
+                               if (show_dropdown_button)
+                                       DropDownButtonEntered = false;
+                       }
                }
 
                void OnMouseMoveCB (object sender, MouseEventArgs e)
index eb5e1f126c0f4abd293c9f3fc6454d83f4fcdf2d..af95708f548683bef9c2eccae43f0ae16425f6a6 100644 (file)
@@ -745,6 +745,8 @@ namespace System.Windows.Forms
                public abstract void ComboBoxDrawNormalDropDownButton (ComboBox comboBox, Graphics g, Rectangle clippingArea, Rectangle area, ButtonState state);
                public abstract bool ComboBoxNormalDropDownButtonHasTransparentBackground (ComboBox comboBox, ButtonState state);
                public abstract bool ComboBoxDropDownButtonHasHotElementStyle (ComboBox comboBox);
+               public abstract void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style);
+               public abstract bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox);
                #endregion      // ComboBox
 
                #region Control
index 0f8d986311d275b5294db522fb8ffe4c88ae0c19..59e179ce132e12115bd4fbc7ef51b1802b8cf93c 100644 (file)
@@ -164,6 +164,48 @@ namespace System.Windows.Forms
 #endif
                        return true;
                }
+               static bool ComboBoxShouldPaintBackground (ComboBox comboBox)
+               {
+                       if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
+                               return false;
+#if NET_2_0
+                       switch (comboBox.FlatStyle) {
+                       case FlatStyle.Flat:
+                       case FlatStyle.Popup:
+                               return false;
+                       }
+#endif 
+                       return true;
+               }
+               public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
+               {
+                       if (!ComboBoxShouldPaintBackground (comboBox)) {
+                               base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
+                               return;
+                       }
+                       VisualStyleElement element;
+                       if (!comboBox.Enabled)
+                               element = VisualStyleElement.ComboBox.Border.Disabled;
+                       else if (comboBox.Entered)
+                               element = VisualStyleElement.ComboBox.Border.Hot;
+                       else if (comboBox.Focused)
+                               element = VisualStyleElement.ComboBox.Border.Focused;
+                       else
+                               element = VisualStyleElement.ComboBox.Border.Normal;
+                       if (!VisualStyleRenderer.IsElementDefined (element)) {
+                               base.ComboBoxDrawBackground (comboBox, g, clippingArea, style);
+                               return;
+                       }
+                       new VisualStyleRenderer (element).DrawBackground (g, new Rectangle (Point.Empty, comboBox.Size), clippingArea);
+               }
+               public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
+               {
+                       if (ComboBoxShouldPaintBackground (comboBox) &&
+                               comboBox.Enabled &&
+                               VisualStyleRenderer.IsElementDefined (VisualStyleElement.ComboBox.Border.Hot))
+                               return true;
+                       return base.CombBoxBackgroundHasHotElementStyle (comboBox);
+               }
                #endregion
                #region ControlPaint
                #region DrawButton
index 4e6ed4b5afa0ad62a74b8a95cf6d301bc9d3d2f0..024ae92149e909d04a31107d99d934635bd26492 100644 (file)
@@ -1596,6 +1596,29 @@ namespace System.Windows.Forms
                {
                        return false;
                }
+               public override void ComboBoxDrawBackground (ComboBox comboBox, Graphics g, Rectangle clippingArea, FlatStyle style)
+               {
+                       if (!comboBox.Enabled)
+                               g.FillRectangle (ResPool.GetSolidBrush (ColorControl), comboBox.Bounds);
+
+                       if (comboBox.DropDownStyle == ComboBoxStyle.Simple)
+                               g.FillRectangle (ResPool.GetSolidBrush (comboBox.Parent.BackColor), comboBox.ClientRectangle);
+
+                       if (style == FlatStyle.Popup && (comboBox.Entered || comboBox.Focused)) {
+                               Rectangle area = comboBox.TextArea;
+                               area.Height -= 1;
+                               area.Width -= 1;
+                               g.DrawRectangle (ResPool.GetPen (SystemColors.ControlDark), area);
+                               g.DrawLine (ResPool.GetPen (SystemColors.ControlDark), comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Top, comboBox.ButtonArea.X - 1, comboBox.ButtonArea.Bottom);
+                       }
+                       bool is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
+                       if (!is_flat && clippingArea.IntersectsWith (comboBox.TextArea))
+                               ControlPaint.DrawBorder3D (g, comboBox.TextArea, Border3DStyle.Sunken);
+               }
+               public override bool CombBoxBackgroundHasHotElementStyle (ComboBox comboBox)
+               {
+                       return false;
+               }
                #endregion ComboBox
                
                #region Datagrid