2007-01-25 Rolf Bjarne Kvinge <RKvinge@novell.com>
authorRolf Bjarne Kvinge <RKvinge@novell.com>
Thu, 25 Jan 2007 12:41:38 +0000 (12:41 -0000)
committerRolf Bjarne Kvinge <RKvinge@novell.com>
Thu, 25 Jan 2007 12:41:38 +0000 (12:41 -0000)
* ComboBox.cs: Implemented FlatStyle and DropDownHeight, and added
a few other missing 2.0 properties.
* Theme.cs: Added DrawFlatStyleComboBox.
* ThemeWin32Classic.cs: Implemented DrawFlatStyleComboBox.

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

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/ThemeWin32Classic.cs

index e23499e61567724c9f3a823f71277b1eb96b8153..cb87a0ff62f413be6af44e7dce023f2c2c79aecf 100644 (file)
@@ -1,3 +1,10 @@
+2007-01-25  Rolf Bjarne Kvinge  <RKvinge@novell.com>
+
+       * ComboBox.cs: Implemented FlatStyle and DropDownHeight, and added
+       a few other missing 2.0 properties.
+       * Theme.cs: Added DrawFlatStyleComboBox.
+       * ThemeWin32Classic.cs: Implemented DrawFlatStyleComboBox.
+
 2007-01-24  Chris Toshok  <toshok@ximian.com>
 
        * XplatUIX11.cs: fix the wake_waiting logic - we always clear the
index a19b7686e2c72a32b41b4f869ce6b757ad40678c..821428f634dc8d1a364b5ed24636bcc9fb1e8938 100644 (file)
@@ -74,6 +74,8 @@ namespace System.Windows.Forms
                private AutoCompleteStringCollection auto_complete_custom_source = null;
                private AutoCompleteMode auto_complete_mode = AutoCompleteMode.None;
                private AutoCompleteSource auto_complete_source = AutoCompleteSource.None;
+               private int drop_down_height;
+               private FlatStyle flat_style;
 #endif
 
                [ComVisible(true)]
@@ -99,6 +101,11 @@ namespace System.Windows.Forms
                        BackColor = ThemeEngine.Current.ColorWindow;
                        border_style = BorderStyle.None;
 
+#if NET_2_0
+                       drop_down_height = 106;
+                       flat_style = FlatStyle.Standard;
+#endif
+
                        /* Events */
                        MouseDown += new MouseEventHandler (OnMouseDownCB);
                        MouseUp += new MouseEventHandler (OnMouseUpCB);
@@ -251,10 +258,28 @@ namespace System.Windows.Forms
                        }
                }
 
+#if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public override ImageLayout BackgroundImageLayout {
+                       get { return base.BackgroundImageLayout; }
+                       set { base.BackgroundImageLayout = value; }
+               }
+#endif
+
                protected override CreateParams CreateParams {
                        get { return base.CreateParams;}
                }
 
+#if NET_2_0
+               [DefaultValue ((string)null)]
+               [AttributeProvider (typeof (IListSource))]
+               [RefreshProperties (RefreshProperties.Repaint)]
+               public object DataSource {
+                       get { return base.DataSource; }
+                       set { base.DataSource = value; }
+               }
+#endif
                protected override Size DefaultSize {
                        get { return new Size (121, 21); }
                }
@@ -280,6 +305,24 @@ namespace System.Windows.Forms
                        }
                }
 
+#if NET_2_0
+               [Browsable (true)]
+               [DefaultValue (106)]
+               [EditorBrowsable (EditorBrowsableState.Always)]
+               public int DropDownHeight {
+                       get {
+                               return drop_down_height;
+                       }
+                       set {
+                               if (value < 1)
+                                       throw new ArgumentOutOfRangeException ("DropDownHeight", "DropDownHeight must be greater than 0.");
+                                       
+                               drop_down_height = value;
+                               IntegralHeight = false;
+                       }
+               }
+#endif
+
                [DefaultValue (ComboBoxStyle.DropDown)]
                [RefreshProperties(RefreshProperties.Repaint)]
                public ComboBoxStyle DropDownStyle {
@@ -391,6 +434,24 @@ namespace System.Windows.Forms
                        }
                }               
 
+#if NET_2_0
+               [DefaultValue (FlatStyle.Standard)]
+               [Localizable (true)]
+               public FlatStyle FlatStyle {
+                       get { return flat_style; }
+                       set {
+                               if (!Enum.IsDefined (typeof (FlatStyle), value))
+                                       throw new InvalidEnumArgumentException ("FlatStyle", (int) value, typeof (FlatStyle));
+                               
+                               flat_style = value;
+                               LayoutComboBox ();
+                               Invalidate ();
+                       }
+               }
+
+#endif
+
                public override bool Focused {
                        get { return base.Focused; }
                }
@@ -469,6 +530,14 @@ namespace System.Windows.Forms
                        }
                }
 
+#if NET_2_0
+               public override Size MaximumSize {
+                       get { return base.MaximumSize; }
+                       set {
+                               base.MaximumSize = new Size (value.Width, 0);
+                       }
+               }
+#endif
                [DefaultValue (0)]
                [Localizable (true)]
                public int MaxLength {
@@ -490,6 +559,23 @@ namespace System.Windows.Forms
                        }
                }
 
+#if NET_2_0
+               public override Size MinimumSize {
+                       get { return base.MinimumSize; }
+                       set {
+                               base.MinimumSize = new Size (value.Width, 0);
+                       }
+               }
+               
+               [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               [Browsable (false)]
+               public Padding Padding  {
+                       get { return base.Padding; }
+                       set { base.Padding = value; }
+               }
+#endif
+
                [DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
                [Browsable (false)]             
                public int PreferredHeight {
@@ -1008,11 +1094,19 @@ namespace System.Windows.Forms
 
                protected override void OnMouseLeave (EventArgs e)
                {
+#if NET_2_0
+                       if (flat_style == FlatStyle.Popup)
+                               Invalidate ();
+#endif
                        base.OnMouseLeave (e);
                }
                
                protected override void OnMouseEnter (EventArgs e)
                {
+#if NET_2_0
+                       if (flat_style == FlatStyle.Popup)
+                               Invalidate ();
+#endif
                        base.OnMouseEnter (e);
                }
 #endif
@@ -1149,6 +1243,13 @@ namespace System.Windows.Forms
                                button_area.Y = text_area.Y + border;
                                button_area.Width = button_width;
                                button_area.Height = text_area.Height - 2 * border;
+#if NET_2_0
+                               if (flat_style == FlatStyle.Popup || flat_style == FlatStyle.Flat) {
+                                       button_area.Inflate (1, 1);
+                                       button_area.X += 2;
+                                       button_area.Width -= 2;
+                               }
+#endif
                        }
 
                        if (button_area != prev_button_area) {
@@ -1180,11 +1281,25 @@ namespace System.Windows.Forms
                internal void Draw (Rectangle clip, Graphics dc)
                {                               
                        Theme theme = ThemeEngine.Current;
+                       FlatStyle style = FlatStyle.Standard;
+                       bool is_flat = false;
+
+#if NET_2_0
+                       style = this.FlatStyle;
+                       is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
+#endif
 
                        if (DropDownStyle == ComboBoxStyle.Simple)
                                dc.FillRectangle (theme.ResPool.GetSolidBrush (Parent.BackColor), ClientRectangle);
 
-                       if (clip.IntersectsWith (text_area))
+                       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);
 
                        int border = theme.Border3DSize.Width;
@@ -1213,7 +1328,11 @@ namespace System.Windows.Forms
                                if (!is_enabled)
                                        button_state = ButtonState.Inactive;
                                
-                               theme.CPDrawComboButton (dc, button_area, button_state);
+                               if (is_flat) {
+                                       theme.DrawFlatStyleComboButton (dc, button_area, button_state);
+                               } else {
+                                       theme.CPDrawComboButton (dc, button_area, button_state);
+                               }
                        }                       
                }
 
@@ -1813,7 +1932,11 @@ namespace System.Windows.Forms
                                                }
                                                
                                        } else  {
+#if NET_2_0
+                                               height = owner.DropDownHeight;
+#else          
                                                height = owner.ItemHeight * count;
+#endif
                                        }
                                }
                                
index 70b61f32f3c99005a6a3c64ee3e7e509d81031b4..7592ed330f375bfa60503d6a9453513221561074 100644 (file)
@@ -709,6 +709,7 @@ namespace System.Windows.Forms
                #region ComboBox
                // Drawing
                public abstract void DrawComboBoxItem (ComboBox ctrl, DrawItemEventArgs e);
+               public abstract void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state);
                #endregion      // ComboBox
 
                #region Control
index 8cadf6fcee923a307bb643f2209c6c3918018e01..583b65f51e51cc01622b5eed8d540a11bd1439ed 100644 (file)
@@ -825,6 +825,58 @@ namespace System.Windows.Forms
 
                        string_format.Dispose ();
                }
+               
+               public override void DrawFlatStyleComboButton (Graphics graphics, Rectangle rectangle, ButtonState state)
+               {
+                       Point[]                 arrow = new Point[3];
+                       Point                           P1;
+                       Point                           P2;
+                       Point                           P3;
+                       int                             centerX;
+                       int                             centerY;
+                       int                             shiftX;
+                       int                             shiftY;
+                       Rectangle               rect;
+
+                       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);
+
+                       if ((state & ButtonState.Pushed)!=0) {
+                               shiftX++;
+                               shiftY++;
+                       }
+
+                       rect.Y-=shiftY;
+                       centerY-=shiftY;
+                       P1=new Point(rect.Left + 1, centerY);
+                       P2=new Point(rect.Right - 1, centerY);
+                       P3=new Point(centerX, rect.Bottom - 1);
+
+                       arrow[0]=P1;
+                       arrow[1]=P2;
+                       arrow[2]=P3;
+                       
+                       /* Draw the arrow */
+                       if ((state & ButtonState.Inactive)!=0) {
+                               /* Move away from the shadow */
+                               arrow[0].X += 1;        arrow[0].Y += 1;
+                               arrow[1].X += 1;        arrow[1].Y += 1;
+                               arrow[2].X += 1;        arrow[2].Y += 1;
+                               
+                               graphics.FillPolygon(SystemBrushes.ControlLightLight, arrow, FillMode.Winding);
+
+                               arrow[0]=P1;
+                               arrow[1]=P2;
+                               arrow[2]=P3;
+
+                               graphics.FillPolygon(SystemBrushes.ControlDark, arrow, FillMode.Winding);
+                       } else {
+                               graphics.FillPolygon(SystemBrushes.ControlText, arrow, FillMode.Winding);
+                       }               
+               }
                #endregion ComboBox
                
                #region Datagrid
@@ -3264,6 +3316,7 @@ namespace System.Windows.Forms
                                DrawInnerFocusRectangle( dc, text_rectangle, radio_button.BackColor );
                }
                
+               
                // renders a radio button with the Flat and Popup FlatStyle
                protected virtual void DrawFlatStyleRadioButton (Graphics graphics, Rectangle rectangle, RadioButton radio_button)
                {