2007-09-28 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / Button.cs
index 45b14847b3623d913180735a10755051aa51af1f..8772aa4e6888260efd8e619e2ab86a74601b92b7 100644 (file)
@@ -42,114 +42,167 @@ namespace System.Windows.Forms {
                #endregion      // Local variables
 
                #region Public Constructors
-               public Button() {
+               public Button ()
+               {
                        dialog_result = DialogResult.None;
-                       SetStyle(ControlStyles.StandardDoubleClick, false);
+                       SetStyle (ControlStyles.StandardDoubleClick, false);
                }
                #endregion      // Public Constructors
 
-               #region Internal methods
-               internal override void HaveDoubleClick() {
-                       EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
-                       if (eh != null)
-                               eh (this, EventArgs.Empty);
+               #region Public Properties
+#if NET_2_0
+               [Browsable (true)]
+               [Localizable (true)]
+               [DefaultValue (AutoSizeMode.GrowOnly)]
+               public AutoSizeMode AutoSizeMode {
+                       get { return base.GetAutoSizeMode (); }
+                       set { base.SetAutoSizeMode (value); }
                }
-               #endregion      // Internal methods
+#endif
 
-               #region Public Instance Properties
-               [DefaultValue(DialogResult.None)]
-               public virtual DialogResult DialogResult {              // IButtonControl
-                       get {
-                               return dialog_result;
-                       }
-                       set {
-                               dialog_result = value;
-                       }
+               [DefaultValue (DialogResult.None)]
+               public virtual DialogResult DialogResult {      // IButtonControl
+                       get { return dialog_result; }
+                       set { dialog_result = value; }
                }
-               #endregion      // Public Instance Properties
+               #endregion      // Public Properties
 
-               #region Protected Instance Properties
+               #region Protected Properties
                protected override CreateParams CreateParams {
-                       get {
-                               return base.CreateParams;
-                       }
+                       get { return base.CreateParams; }
                }
-               #endregion      // Protected Instance Properties
+               #endregion      // Protected Properties
 
-               #region Public Instance Methods
-               public virtual void NotifyDefault(bool value) { // IButtonControl
+               #region Public Methods
+               public virtual void NotifyDefault (bool value)  // IButtonControl
+               {       
                        this.IsDefault = value;
                }
 
-               public void PerformClick() {                    // IButtonControl
+               public void PerformClick ()                     // IButtonControl
+               {                       
                        if (CanSelect)
-                               OnClick(EventArgs.Empty);
+                               OnClick (EventArgs.Empty);
                }
 
-               public override string ToString() {
-                       return base.ToString() + ", Text: " + this.Text;
+               public override string ToString ()
+               {
+                       return base.ToString () + ", Text: " + this.Text;
                }
-               #endregion      // Public Instance Methods
+               #endregion      // Public Methods
 
-               #region Protected Instance Methods
-               protected override void OnClick(EventArgs e) {
+               #region Protected Methods
+               protected override void OnClick (EventArgs e)
+               {
                        if (dialog_result != DialogResult.None) {
-                               Form p = Parent as Form;
+                               Form p = FindForm ();
 
-                               if (p != null) {
+                               if (p != null)
                                        p.DialogResult = dialog_result;
-                               }
                        }
-                       base.OnClick(e);
+                       
+                       base.OnClick (e);
                }
 
-               protected override void OnMouseUp(MouseEventArgs e) {
+#if NET_2_0
+               protected override void OnFontChanged (EventArgs e)
+               {
+                       base.OnFontChanged (e);
+               }
+               
+               protected override void OnMouseEnter (EventArgs e)
+               {
+                       base.OnMouseEnter (e);
+               }
+               
+               protected override void OnMouseLeave (EventArgs e)
+               {
+                       base.OnMouseLeave (e);
+               }
+#endif
+
+               protected override void OnMouseUp (MouseEventArgs e)
+               {
                        base.OnMouseUp (e);
                }
 
-               protected override bool ProcessMnemonic(char charCode) {
-                       if (IsMnemonic(charCode, Text) == true) {
-                               PerformClick();
+#if NET_2_0
+               protected override void OnTextChanged (EventArgs e)
+               {
+                       base.OnTextChanged (e);
+               }
+#endif
+
+               protected override bool ProcessMnemonic (char charCode)
+               {
+                       if (this.UseMnemonic && IsMnemonic (charCode, Text) == true) {
+                               PerformClick ();
                                return true;
                        }
-                       
-                       return base.ProcessMnemonic(charCode);
+
+                       return base.ProcessMnemonic (charCode);
                }
 
-               protected override void WndProc(ref Message m) {
+               protected override void WndProc (ref Message m)
+               {
                        base.WndProc (ref m);
                }
-               #endregion      // Protected Instance Methods
+               #endregion      // Protected Methods
 
                #region Events
-               static object DoubleClickEvent = new object ();
-
-               // XXX this and HaveDoubleClick above need to be
-               // looked at.. it's far more likely that this just
-               // uses base.DoubleClick, and HaveDoubleClick goes
-               // away in favor of calls to OnDoubleClick.
-               [Browsable(false)]
+               [Browsable (false)]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public new event EventHandler DoubleClick {
-                       add { Events.AddHandler (DoubleClickEvent, value); }
-                       remove { Events.RemoveHandler (DoubleClickEvent, value); }
+                       add { base.DoubleClick += value; }
+                       remove { base.DoubleClick -= value; }
                }
-               #endregion      // Events
+
 #if NET_2_0
-               protected override void OnMouseEnter (EventArgs e)
-               {
-                       base.OnMouseEnter (e);
+               [Browsable (false)]
+               [EditorBrowsable (EditorBrowsableState.Advanced)]
+               public new event MouseEventHandler MouseDoubleClick {
+                       add { base.MouseDoubleClick += value; }
+                       remove { base.MouseDoubleClick -= value; }
                }
-               
-               protected override void OnMouseLeave (EventArgs e)
+#endif
+               #endregion      // Events
+
+               #region Internal methods
+#if NET_2_0
+               internal override void Draw (PaintEventArgs pevent)
                {
-                       base.OnMouseLeave (e);
+                       // System style does not use any of the new 2.0 stuff
+                       if (this.FlatStyle == FlatStyle.System) {
+                               base.Draw (pevent);
+                               return;
+                       }
+
+                       // 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 text_rectangle;
+                       Rectangle image_rectangle;
+
+                       ThemeEngine.Current.CalculateButtonTextAndImageLayout (this, out text_rectangle, out image_rectangle);
+
+                       // Draw our button
+                       if (this.FlatStyle == FlatStyle.Standard)
+                               ThemeEngine.Current.DrawButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
+                       else if (this.FlatStyle == FlatStyle.Flat)
+                               ThemeEngine.Current.DrawFlatButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
+                       else if (this.FlatStyle == FlatStyle.Popup)
+                               ThemeEngine.Current.DrawPopupButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
                }
 
-               protected override void OnTextChanged (EventArgs e)
+               internal override Size GetPreferredSizeCore (Size proposedSize)
                {
-                       base.OnTextChanged (e);
+                       if (this.AutoSize)
+                               return ThemeEngine.Current.CalculateButtonAutoSize (this);
+                               
+                       return base.GetPreferredSizeCore (proposedSize);
                }
 #endif
+               #endregion      // Internal methods
        }
 }