2 // Permission is hereby granted, free of charge, to any person obtaining
3 // a copy of this software and associated documentation files (the
4 // "Software"), to deal in the Software without restriction, including
5 // without limitation the rights to use, copy, modify, merge, publish,
6 // distribute, sublicense, and/or sell copies of the Software, and to
7 // permit persons to whom the Software is furnished to do so, subject to
8 // the following conditions:
10 // The above copyright notice and this permission notice shall be
11 // included in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
17 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
18 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 // Copyright (c) 2004-2005 Novell, Inc.
24 // Peter Bartok pbartok@novell.com
27 using System.ComponentModel;
29 using System.Drawing.Text;
30 using System.Runtime.InteropServices;
32 namespace System.Windows.Forms {
33 [ClassInterface (ClassInterfaceType.AutoDispatch)]
35 [Designer ("System.Windows.Forms.Design.ButtonBaseDesigner, " + Consts.AssemblySystem_Design,
36 "System.ComponentModel.Design.IDesigner")]
37 public class Button : ButtonBase, IButtonControl {
38 #region Local variables
39 DialogResult dialog_result;
40 #endregion // Local variables
42 #region Public Constructors
45 dialog_result = DialogResult.None;
46 SetStyle (ControlStyles.StandardDoubleClick, false);
48 #endregion // Public Constructors
50 #region Public Properties
53 [DefaultValue (AutoSizeMode.GrowOnly)]
54 [MWFCategory("Layout")]
55 public AutoSizeMode AutoSizeMode {
56 get { return base.GetAutoSizeMode (); }
57 set { base.SetAutoSizeMode (value); }
60 [DefaultValue (DialogResult.None)]
61 [MWFCategory("Behavior")]
62 public virtual DialogResult DialogResult { // IButtonControl
63 get { return dialog_result; }
64 set { dialog_result = value; }
66 #endregion // Public Properties
68 #region Protected Properties
69 protected override CreateParams CreateParams {
70 get { return base.CreateParams; }
72 #endregion // Protected Properties
74 #region Public Methods
75 public virtual void NotifyDefault (bool value) // IButtonControl
77 this.IsDefault = value;
80 public void PerformClick () // IButtonControl
83 OnClick (EventArgs.Empty);
86 public override string ToString ()
88 return base.ToString () + ", Text: " + this.Text;
90 #endregion // Public Methods
92 #region Protected Methods
93 protected override void OnClick (EventArgs e)
95 if (dialog_result != DialogResult.None) {
99 p.DialogResult = dialog_result;
105 protected override void OnFontChanged (EventArgs e)
107 base.OnFontChanged (e);
110 protected override void OnMouseEnter (EventArgs e)
112 base.OnMouseEnter (e);
115 protected override void OnMouseLeave (EventArgs e)
117 base.OnMouseLeave (e);
120 protected override void OnMouseUp (MouseEventArgs mevent)
122 base.OnMouseUp (mevent);
125 protected override void OnTextChanged (EventArgs e)
127 base.OnTextChanged (e);
130 protected override bool ProcessMnemonic (char charCode)
132 if (this.UseMnemonic && IsMnemonic (charCode, Text) == true) {
137 return base.ProcessMnemonic (charCode);
140 protected override void WndProc (ref Message m)
142 base.WndProc (ref m);
144 #endregion // Protected Methods
148 [EditorBrowsable (EditorBrowsableState.Advanced)]
149 public new event EventHandler DoubleClick {
150 add { base.DoubleClick += value; }
151 remove { base.DoubleClick -= value; }
155 [EditorBrowsable (EditorBrowsableState.Advanced)]
156 public new event MouseEventHandler MouseDoubleClick {
157 add { base.MouseDoubleClick += value; }
158 remove { base.MouseDoubleClick -= value; }
162 #region Internal methods
163 internal override void Draw (PaintEventArgs pevent)
165 // System style does not use any of the new 2.0 stuff
166 if (this.FlatStyle == FlatStyle.System) {
171 // FIXME: This should be called every time something that can affect it
172 // is changed, not every paint. Can only change so many things at a time.
174 // Figure out where our text and image should go
175 Rectangle text_rectangle;
176 Rectangle image_rectangle;
178 ThemeEngine.Current.CalculateButtonTextAndImageLayout (this, out text_rectangle, out image_rectangle);
181 if (this.FlatStyle == FlatStyle.Standard)
182 ThemeEngine.Current.DrawButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
183 else if (this.FlatStyle == FlatStyle.Flat)
184 ThemeEngine.Current.DrawFlatButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
185 else if (this.FlatStyle == FlatStyle.Popup)
186 ThemeEngine.Current.DrawPopupButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
189 internal override Size GetPreferredSizeCore (Size proposedSize)
192 return ThemeEngine.Current.CalculateButtonAutoSize (this);
194 return base.GetPreferredSizeCore (proposedSize);
196 #endregion // Internal methods