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 {
34 [ClassInterface (ClassInterfaceType.AutoDispatch)]
36 [Designer ("System.Windows.Forms.Design.ButtonBaseDesigner, " + Consts.AssemblySystem_Design,
37 "System.ComponentModel.Design.IDesigner")]
39 public class Button : ButtonBase, IButtonControl {
40 #region Local variables
41 DialogResult dialog_result;
42 #endregion // Local variables
44 #region Public Constructors
46 dialog_result = DialogResult.None;
47 SetStyle(ControlStyles.StandardDoubleClick, false);
49 #endregion // Public Constructors
51 #region Internal methods
52 internal override void HaveDoubleClick() {
53 EventHandler eh = (EventHandler)(Events [DoubleClickEvent]);
55 eh (this, EventArgs.Empty);
59 internal override void Draw (PaintEventArgs pevent)
61 // System style does not use any of the new 2.0 stuff
62 if (this.FlatStyle == FlatStyle.System) {
67 // FIXME: This should be called every time something that can affect it
68 // is changed, not every paint. Can only change so many things at a time.
70 // Figure out where our text and image should go
71 Rectangle text_rectangle;
72 Rectangle image_rectangle;
74 ThemeEngine.Current.CalculateButtonTextAndImageLayout (this, out text_rectangle, out image_rectangle);
77 if (this.FlatStyle == FlatStyle.Standard)
78 ThemeEngine.Current.DrawButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
79 else if (this.FlatStyle == FlatStyle.Flat)
80 ThemeEngine.Current.DrawFlatButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
81 else if (this.FlatStyle == FlatStyle.Popup)
82 ThemeEngine.Current.DrawPopupButton (pevent.Graphics, this, text_rectangle, image_rectangle, pevent.ClipRectangle);
85 #endregion // Internal methods
87 #region Public Instance Properties
88 [DefaultValue(DialogResult.None)]
89 public virtual DialogResult DialogResult { // IButtonControl
94 dialog_result = value;
97 #endregion // Public Instance Properties
99 #region Protected Instance Properties
100 protected override CreateParams CreateParams {
102 return base.CreateParams;
105 #endregion // Protected Instance Properties
107 #region Public Instance Methods
108 public virtual void NotifyDefault(bool value) { // IButtonControl
109 this.IsDefault = value;
112 public void PerformClick() { // IButtonControl
114 OnClick(EventArgs.Empty);
117 public override string ToString() {
118 return base.ToString() + ", Text: " + this.Text;
120 #endregion // Public Instance Methods
122 #region Protected Instance Methods
123 protected override void OnClick(EventArgs e) {
124 if (dialog_result != DialogResult.None) {
125 Form p = FindForm ();
128 p.DialogResult = dialog_result;
134 protected override void OnMouseUp(MouseEventArgs e) {
138 protected override bool ProcessMnemonic(char charCode) {
139 if (this.UseMnemonic && IsMnemonic(charCode, Text) == true) {
144 return base.ProcessMnemonic(charCode);
147 protected override void WndProc(ref Message m) {
148 base.WndProc (ref m);
150 #endregion // Protected Instance Methods
153 static object DoubleClickEvent = new object ();
155 // XXX this and HaveDoubleClick above need to be
156 // looked at.. it's far more likely that this just
157 // uses base.DoubleClick, and HaveDoubleClick goes
158 // away in favor of calls to OnDoubleClick.
160 [EditorBrowsable (EditorBrowsableState.Advanced)]
161 public new event EventHandler DoubleClick {
162 add { Events.AddHandler (DoubleClickEvent, value); }
163 remove { Events.RemoveHandler (DoubleClickEvent, value); }
167 public new event MouseEventHandler MouseDoubleClick {
168 add { base.MouseDoubleClick += value; }
169 remove { base.MouseDoubleClick -= value; }
175 protected override void OnFontChanged (EventArgs e)
177 base.OnFontChanged (e);
180 protected override void OnMouseEnter (EventArgs e)
182 base.OnMouseEnter (e);
185 protected override void OnMouseLeave (EventArgs e)
187 base.OnMouseLeave (e);
190 protected override void OnTextChanged (EventArgs e)
192 base.OnTextChanged (e);