2008-12-02 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / RadioButton.cs
index 0e9694fbc73a7a0a411a90a70bde95de977726af..0ef26cc1576ee1428cd2590e1c9de0c2ccafb348 100644 (file)
@@ -35,7 +35,8 @@ namespace System.Windows.Forms {
        [ClassInterface (ClassInterfaceType.AutoDispatch)]
        [ComVisible (true)]
        [DefaultBindingProperty ("Checked")]
-       [ToolboxItem ("")]
+       [ToolboxItem ("System.Windows.Forms.Design.AutoSizeToolboxItem," + Consts.AssemblySystem_Design)]
+       [Designer ("System.Windows.Forms.Design.RadioButtonDesigner, " + Consts.AssemblySystem_Design)]
 #endif
        public class RadioButton : ButtonBase {
                #region Local Variables
@@ -47,7 +48,11 @@ namespace System.Windows.Forms {
 
                #region RadioButtonAccessibleObject Subclass
                [ComVisible(true)]
+#if NET_2_0
+               public class RadioButtonAccessibleObject : ButtonBaseAccessibleObject {
+#else
                public class RadioButtonAccessibleObject : ControlAccessibleObject {
+#endif
                        #region RadioButtonAccessibleObject Local Variables
                        private new RadioButton owner;
                        #endregion      // RadioButtonAccessibleObject Local Variables
@@ -107,7 +112,7 @@ namespace System.Windows.Forms {
                        appearance = Appearance.Normal;
                        auto_check = true;
                        radiobutton_alignment = ContentAlignment.MiddleLeft;
-                       text_alignment = ContentAlignment.MiddleLeft;
+                       TextAlign = ContentAlignment.MiddleLeft;
                        TabStop = false;
                }
                #endregion      // Public Constructors
@@ -137,8 +142,36 @@ namespace System.Windows.Forms {
                }
 
                internal override void Draw (PaintEventArgs pe) {
+#if NET_2_0
+                       // FIXME: This should be called every time something that can affect it
+                       // is changed, not every paint.  Can only change so many things at a time.
+
+                       // Figure out where our text and image should go
+                       Rectangle glyph_rectangle;
+                       Rectangle text_rectangle;
+                       Rectangle image_rectangle;
+
+                       ThemeEngine.Current.CalculateRadioButtonTextAndImageLayout (this, Point.Empty, out glyph_rectangle, out text_rectangle, out image_rectangle);
+
+                       // Draw our button
+                       if (FlatStyle != FlatStyle.System)
+                               ThemeEngine.Current.DrawRadioButton (pe.Graphics, this, glyph_rectangle, text_rectangle, image_rectangle, pe.ClipRectangle);
+                       else
+                               ThemeEngine.Current.DrawRadioButton (pe.Graphics, this.ClientRectangle, this);
+#else
                        ThemeEngine.Current.DrawRadioButton (pe.Graphics, this.ClientRectangle, this);
+#endif
+               }
+
+#if NET_2_0
+               internal override Size GetPreferredSizeCore (Size proposedSize)
+               {
+                       if (this.AutoSize)
+                               return ThemeEngine.Current.CalculateRadioButtonAutoSize (this);
+
+                       return base.GetPreferredSizeCore (proposedSize);
                }
+#endif
                #endregion      // Private Methods
 
                #region Public Instance Properties
@@ -155,7 +188,9 @@ namespace System.Windows.Forms {
                                        EventHandler eh = (EventHandler)(Events [AppearanceChangedEvent]);
                                        if (eh != null)
                                                eh (this, EventArgs.Empty);
-                                       Redraw();
+                                       if (Parent != null)
+                                               Parent.PerformLayout (this, "Appearance");
+                                       Invalidate();
                                }
                        }
                }
@@ -185,7 +220,7 @@ namespace System.Windows.Forms {
                                if (value != radiobutton_alignment) {
                                        radiobutton_alignment = value;
 
-                                       Redraw();
+                                       Invalidate();
                                }
                        }
                }
@@ -207,11 +242,11 @@ namespace System.Windows.Forms {
                                if (value && (check_state != CheckState.Checked)) {
                                        UpdateSiblings();
                                        check_state = CheckState.Checked;
-                                       Redraw();
+                                       Invalidate();
                                        OnCheckedChanged(EventArgs.Empty);
                                } else if (!value && (check_state != CheckState.Unchecked)) {
                                        check_state = CheckState.Unchecked;
-                                       Redraw();
+                                       Invalidate();
                                        OnCheckedChanged(EventArgs.Empty);
                                }
                        }
@@ -226,16 +261,8 @@ namespace System.Windows.Forms {
                [DefaultValue(ContentAlignment.MiddleLeft)]
                [Localizable(true)]
                public override ContentAlignment TextAlign {
-                       get {
-                               return text_alignment;
-                       }
-
-                       set {
-                               if (value != text_alignment) {
-                                       text_alignment = value;
-                                       Redraw();
-                               }
-                       }
+                       get { return base.TextAlign; }
+                       set { base.TextAlign = value; }
                }
                #endregion      // Public Instance Properties
 
@@ -339,6 +366,8 @@ namespace System.Windows.Forms {
                }
                
 #if NET_2_0
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Never)]
                public new event MouseEventHandler MouseDoubleClick { 
                        add { base.MouseDoubleClick += value; }
                        remove { base.MouseDoubleClick -= value; }