2 // System.Windows.Forms.ButtonBase.cs
5 // stubbed out by Jaak Simm (jaaksimm@firm.ee)
6 // implemented for Gtk+ by Rachel Hestilow (hestilow@ximian.com)
7 // Dennis Hayes (dennish@Raytek.com)
8 // WINELib implementation started by John Sohn (jsohn@columbus.rr.com)
9 // Alexandre Pigokine (pigolkine@gmx.de)
11 // (C) Ximian, Inc., 2002/3
15 // Permission is hereby granted, free of charge, to any person obtaining
16 // a copy of this software and associated documentation files (the
17 // "Software"), to deal in the Software without restriction, including
18 // without limitation the rights to use, copy, modify, merge, publish,
19 // distribute, sublicense, and/or sell copies of the Software, and to
20 // permit persons to whom the Software is furnished to do so, subject to
21 // the following conditions:
23 // The above copyright notice and this permission notice shall be
24 // included in all copies or substantial portions of the Software.
26 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
29 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
30 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
31 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
32 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 using System.ComponentModel;
38 namespace System.Windows.Forms {
41 /// Implements the basic functionality common to button controls.
44 public abstract class ButtonBase : Control {
49 ContentAlignment imageAlign;
51 ContentAlignment textAlign;
58 // // --- Constructor ---
59 protected ButtonBase() : base()
61 flatStyle = FlatStyle.Standard;
63 imageAlign = ContentAlignment.MiddleCenter;
65 textAlign = ContentAlignment.MiddleCenter;
66 imeMode = ImeMode.Inherit;
72 protected override CreateParams CreateParams {
73 get { return base.CreateParams; }
76 protected override ImeMode DefaultImeMode {
78 return ImeMode.Inherit;
82 protected override Size DefaultSize {
84 return new Size(75,23);// default size for button.
88 public FlatStyle FlatStyle {
89 get { return flatStyle; }
91 if( flatStyle != value) {
94 if( flatStyle == FlatStyle.System) {
95 Win32.UpdateWindowStyle(Handle, (int)ButtonStyles.BS_OWNERDRAW, 0);
97 Win32.UpdateWindowStyle(Handle, 0, (int)ButtonStyles.BS_OWNERDRAW);
105 get { return image; }
112 public ImageList ImageList {
114 throw new NotImplementedException ();
122 public ContentAlignment ImageAlign {
123 get { return imageAlign; }
125 if( imageAlign != value) {
132 public int ImageIndex {
133 get { return imageIndex; }
134 set { imageIndex=value; }
137 public new ImeMode ImeMode {
145 protected bool IsDefault {
154 internal bool Pushed {
161 public virtual ContentAlignment TextAlign {
166 if( textAlign != value) {
168 Win32.UpdateWindowStyle(Handle, (int)0xF00, (int)Win32.ContentAlignment2SystemButtonStyle(textAlign));
175 protected override void Dispose(bool disposing){
176 base.Dispose(disposing);
179 protected void ResetFlagsandPaint(){
183 protected override AccessibleObject CreateAccessibilityInstance()
185 return base.CreateAccessibilityInstance();
188 /// [methods for events]
189 protected override void OnEnabledChanged (EventArgs e)
191 base.OnEnabledChanged (e);
194 protected override void OnGotFocus (EventArgs e)
199 protected override void OnKeyDown (KeyEventArgs kevent)
201 base.OnKeyDown (kevent);
204 protected override void OnKeyUp (KeyEventArgs kevent)
206 base.OnKeyUp (kevent);
209 protected override void OnLostFocus (EventArgs e)
211 base.OnLostFocus (e);
214 protected override void OnMouseDown (MouseEventArgs mevent)
216 if ((mevent.Button & MouseButtons.Left) == MouseButtons.Left) {
221 base.OnMouseDown (mevent);
224 protected override void OnMouseEnter (EventArgs eventargs)
226 base.OnMouseEnter(eventargs);
227 if( FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
232 protected override void OnMouseLeave (EventArgs eventargs)
234 base.OnMouseLeave(eventargs);
235 if( FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
240 protected override void OnMouseMove (MouseEventArgs mevent)
242 base.OnMouseMove (mevent);
245 protected override void OnMouseUp (MouseEventArgs mevent)
249 base.OnMouseUp (mevent);
252 internal virtual void ButtonPaint (PaintEventArgs pevent) {
255 protected override void OnPaint (PaintEventArgs pevent)
257 base.OnPaint (pevent);
258 ButtonPaint (pevent);
261 protected override void OnParentChanged (EventArgs e)
263 base.OnParentChanged (e);
266 protected override void OnTextChanged (EventArgs e)
268 base.OnTextChanged (e);
271 protected override void OnVisibleChanged (EventArgs e)
273 base.OnVisibleChanged (e);
275 /// end of [methods for events]
277 protected override void WndProc (ref Message m)
279 switch ((Msg) m.Msg) {
280 case Msg.WM_COMMAND: {
281 switch(m.HiWordWParam) {
282 case (uint)ButtonNotification.BN_CLICKED: {
283 OnClick(new ControlEventArgs(this));
284 Win32.SendMessage(Handle, Msg.WM_SETFOCUS, (int)Handle, 0);
285 CallControlWndProc(ref m);
289 case (uint)ButtonNotification.BN_DOUBLECLICKED: {
290 OnClick(new ControlEventArgs(this));
291 CallControlWndProc(ref m);
295 case (uint)ButtonNotification.BN_SETFOCUS: {
296 OnGotFocus(new ControlEventArgs(this));
300 case (uint)ButtonNotification.BN_KILLFOCUS: {
301 OnLostFocus(new ControlEventArgs(this));
306 CallControlWndProc(ref m);
312 case Msg.WM_DRAWITEM: {
313 m.Result = (IntPtr)1;
318 PAINTSTRUCT ps = new PAINTSTRUCT ();
319 IntPtr hdc = Win32.BeginPaint (Handle, ref ps);
320 Rectangle rc = new Rectangle ();
322 rc.X = ps.rcPaint.left;
323 rc.Y = ps.rcPaint.top;
324 rc.Width = ps.rcPaint.right - ps.rcPaint.left;
325 rc.Height = ps.rcPaint.bottom - ps.rcPaint.top;
326 PaintEventArgs paintEventArgs = new PaintEventArgs (Graphics.FromHdc (hdc), rc);
327 OnPaint (paintEventArgs);
328 paintEventArgs.Dispose ();
329 Win32.EndPaint (Handle, ref ps);
334 base.WndProc (ref m);
341 /// --- ButtonBase.ButtonBaseAccessibleObject ---
342 /// the class isonly used for .NET framework
344 //public class ButtonBaseAccessibleObject : Control.ControlAccessibleObject{
345 // private ButtonBaseAccessibleObject() : base(/* need "control" parameter here. "this", "base" no go.*/){