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
14 using System.ComponentModel;
17 namespace System.Windows.Forms {
20 /// Implements the basic functionality common to button controls.
23 public abstract class ButtonBase : Control {
28 ContentAlignment imageAlign;
30 ContentAlignment textAlign;
37 // // --- Constructor ---
38 protected ButtonBase() : base()
40 flatStyle = FlatStyle.Standard;
42 imageAlign = ContentAlignment.MiddleCenter;
44 textAlign = ContentAlignment.MiddleCenter;
45 imeMode = ImeMode.Inherit;
51 protected override CreateParams CreateParams {
52 get { return base.CreateParams; }
55 protected override ImeMode DefaultImeMode {
57 return ImeMode.Inherit;
61 protected override Size DefaultSize {
63 return new Size(75,23);// default size for button.
67 public FlatStyle FlatStyle {
68 get { return flatStyle; }
70 if( flatStyle != value) {
73 if( flatStyle == FlatStyle.System) {
74 Win32.UpdateWindowStyle(Handle, (int)ButtonStyles.BS_OWNERDRAW, 0);
76 Win32.UpdateWindowStyle(Handle, 0, (int)ButtonStyles.BS_OWNERDRAW);
91 public ImageList ImageList {
93 throw new NotImplementedException ();
101 public ContentAlignment ImageAlign {
102 get { return imageAlign; }
104 if( imageAlign != value) {
111 public int ImageIndex {
112 get { return imageIndex; }
113 set { imageIndex=value; }
116 public new ImeMode ImeMode {
124 protected bool IsDefault {
133 internal bool Pushed {
140 public virtual ContentAlignment TextAlign {
145 if( textAlign != value) {
147 Win32.UpdateWindowStyle(Handle, (int)0xF00, (int)Win32.ContentAlignment2SystemButtonStyle(textAlign));
154 protected override void Dispose(bool disposing){
155 base.Dispose(disposing);
158 protected void ResetFlagsandPaint(){
162 protected override AccessibleObject CreateAccessibilityInstance()
164 return base.CreateAccessibilityInstance();
167 /// [methods for events]
168 protected override void OnEnabledChanged (EventArgs e)
170 base.OnEnabledChanged (e);
173 protected override void OnGotFocus (EventArgs e)
178 protected override void OnKeyDown (KeyEventArgs kevent)
180 base.OnKeyDown (kevent);
183 protected override void OnKeyUp (KeyEventArgs kevent)
185 base.OnKeyUp (kevent);
188 protected override void OnLostFocus (EventArgs e)
190 base.OnLostFocus (e);
193 protected override void OnMouseDown (MouseEventArgs mevent)
195 if ((mevent.Button & MouseButtons.Left) == MouseButtons.Left) {
200 base.OnMouseDown (mevent);
203 protected override void OnMouseEnter (EventArgs eventargs)
205 base.OnMouseEnter(eventargs);
206 if( FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
211 protected override void OnMouseLeave (EventArgs eventargs)
213 base.OnMouseLeave(eventargs);
214 if( FlatStyle == FlatStyle.Flat || FlatStyle == FlatStyle.Popup) {
219 protected override void OnMouseMove (MouseEventArgs mevent)
221 base.OnMouseMove (mevent);
224 protected override void OnMouseUp (MouseEventArgs mevent)
228 base.OnMouseUp (mevent);
231 internal virtual void ButtonPaint (PaintEventArgs pevent) {
234 protected override void OnPaint (PaintEventArgs pevent)
236 base.OnPaint (pevent);
237 ButtonPaint (pevent);
240 protected override void OnParentChanged (EventArgs e)
242 base.OnParentChanged (e);
245 protected override void OnTextChanged (EventArgs e)
247 base.OnTextChanged (e);
250 protected override void OnVisibleChanged (EventArgs e)
252 base.OnVisibleChanged (e);
254 /// end of [methods for events]
256 protected override void WndProc (ref Message m)
258 switch ((Msg) m.Msg) {
259 case Msg.WM_COMMAND: {
260 switch(m.HiWordWParam) {
261 case (uint)ButtonNotification.BN_CLICKED: {
262 OnClick(new ControlEventArgs(this));
263 Win32.SendMessage(Handle, Msg.WM_SETFOCUS, (int)Handle, 0);
264 CallControlWndProc(ref m);
268 case (uint)ButtonNotification.BN_DOUBLECLICKED: {
269 OnClick(new ControlEventArgs(this));
270 CallControlWndProc(ref m);
274 case (uint)ButtonNotification.BN_SETFOCUS: {
275 OnGotFocus(new ControlEventArgs(this));
279 case (uint)ButtonNotification.BN_KILLFOCUS: {
280 OnLostFocus(new ControlEventArgs(this));
285 CallControlWndProc(ref m);
291 case Msg.WM_DRAWITEM: {
292 m.Result = (IntPtr)1;
297 PAINTSTRUCT ps = new PAINTSTRUCT ();
298 IntPtr hdc = Win32.BeginPaint (Handle, ref ps);
299 Rectangle rc = new Rectangle ();
301 rc.X = ps.rcPaint.left;
302 rc.Y = ps.rcPaint.top;
303 rc.Width = ps.rcPaint.right - ps.rcPaint.left;
304 rc.Height = ps.rcPaint.bottom - ps.rcPaint.top;
305 PaintEventArgs paintEventArgs = new PaintEventArgs (Graphics.FromHdc (hdc), rc);
306 OnPaint (paintEventArgs);
307 paintEventArgs.Dispose ();
308 Win32.EndPaint (Handle, ref ps);
313 base.WndProc (ref m);
320 /// --- ButtonBase.ButtonBaseAccessibleObject ---
321 /// the class isonly used for .NET framework
323 //public class ButtonBaseAccessibleObject : Control.ControlAccessibleObject{
324 // private ButtonBaseAccessibleObject() : base(/* need "control" parameter here. "this", "base" no go.*/){