2010-05-02 Carlos Alberto Cortez <calberto.cortez@gmail.com>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / ButtonBase.cs
1 // Permission is hereby granted, free of charge, to any person obtaining
2 // a copy of this software and associated documentation files (the
3 // "Software"), to deal in the Software without restriction, including
4 // without limitation the rights to use, copy, modify, merge, publish,
5 // distribute, sublicense, and/or sell copies of the Software, and to
6 // permit persons to whom the Software is furnished to do so, subject to
7 // the following conditions:
8 //
9 // The above copyright notice and this permission notice shall be
10 // included in all copies or substantial portions of the Software.
11 //
12 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
13 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
14 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
15 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
16 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
17 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
18 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 //
20 // Copyright (c) 2004-2006 Novell, Inc.
21 //
22 // Authors:
23 //      Peter Bartok    pbartok@novell.com
24 //
25
26 using System.ComponentModel;
27 using System.ComponentModel.Design;
28 using System.Drawing;
29 using System.Drawing.Text;
30 using System.Runtime.InteropServices;
31
32 namespace System.Windows.Forms {
33 #if NET_2_0
34         [ClassInterface (ClassInterfaceType.AutoDispatch)]
35         [ComVisible (true)]
36         [Designer ("System.Windows.Forms.Design.ButtonBaseDesigner, " + Consts.AssemblySystem_Design,
37                    "System.ComponentModel.Design.IDesigner")]
38 #endif
39         public abstract class ButtonBase : Control
40         {
41                 #region Local Variables
42                 private FlatStyle               flat_style;
43                 private int                     image_index;
44                 internal Image                  image;
45                 internal ImageList              image_list;
46                 private ContentAlignment        image_alignment;
47                 internal ContentAlignment       text_alignment;
48                 private bool                    is_default;
49                 internal bool                   is_pressed;
50 //              private bool                    enter_state;
51                 internal StringFormat           text_format;
52                 internal bool                   paint_as_acceptbutton;
53                 
54                 // Properties are 2.0, but variables used in 1.1 for common drawing code
55                 private bool                    auto_ellipsis;
56                 private FlatButtonAppearance    flat_button_appearance;
57 #if NET_2_0             
58                 private string                  image_key;
59 #endif
60                 private TextImageRelation       text_image_relation;
61                 private TextFormatFlags         text_format_flags;
62                 private bool                    use_mnemonic;
63                 private bool                    use_visual_style_back_color;
64                 #endregion      // Local Variables
65
66                 #region Public Constructors
67                 protected ButtonBase() : base()
68                 {
69                         flat_style      = FlatStyle.Standard;
70                         flat_button_appearance = new FlatButtonAppearance (this);
71 #if NET_2_0
72                         this.image_key = string.Empty;
73                         this.text_image_relation = TextImageRelation.Overlay;
74                         this.use_mnemonic = true;
75                         use_visual_style_back_color = true;
76 #endif
77                         image_index     = -1;
78                         image           = null;
79                         image_list      = null;
80                         image_alignment = ContentAlignment.MiddleCenter;
81                         ImeMode         = ImeMode.Disable;
82                         text_alignment  = ContentAlignment.MiddleCenter;
83                         is_default      = false;
84                         is_pressed      = false;
85                         text_format     = new StringFormat();
86                         text_format.Alignment = StringAlignment.Center;
87                         text_format.LineAlignment = StringAlignment.Center;
88                         text_format.HotkeyPrefix = HotkeyPrefix.Show;
89                         text_format.FormatFlags |= StringFormatFlags.LineLimit;
90
91                         text_format_flags = TextFormatFlags.HorizontalCenter;
92                         text_format_flags |= TextFormatFlags.VerticalCenter;
93                         text_format_flags |= TextFormatFlags.TextBoxControl;
94
95                         SetStyle (ControlStyles.ResizeRedraw | 
96                                 ControlStyles.Opaque | 
97                                 ControlStyles.UserMouse | 
98                                 ControlStyles.SupportsTransparentBackColor | 
99                                 ControlStyles.CacheText |
100 #if NET_2_0
101                                 ControlStyles.OptimizedDoubleBuffer, true);
102 #else
103                                 ControlStyles.DoubleBuffer, true);
104 #endif
105                         SetStyle (ControlStyles.StandardClick, false);
106                 }
107                 #endregion      // Public Constructors
108
109                 #region Public Properties
110                 [Browsable (true)]
111                 [DefaultValue (false)]
112                 [EditorBrowsable (EditorBrowsableState.Always)]
113                 [MWFCategory("Behavior")]
114 #if NET_2_0
115                 public
116 #else
117                 internal
118 #endif
119                 bool AutoEllipsis {
120                         get { return this.auto_ellipsis; }
121                         set
122                         {
123                                 if (this.auto_ellipsis != value) {
124                                         this.auto_ellipsis = value;
125
126                                         if (this.auto_ellipsis) {
127                                                 text_format_flags |= TextFormatFlags.EndEllipsis;
128                                                 text_format_flags &= ~TextFormatFlags.WordBreak;
129                                         } else {
130                                                 text_format_flags &= ~TextFormatFlags.EndEllipsis;
131                                                 text_format_flags |= TextFormatFlags.WordBreak;
132                                         }
133
134                                         if (Parent != null)
135                                                 Parent.PerformLayout (this, "AutoEllipsis");
136                                         this.Invalidate ();
137                                 }
138                         }
139                 }
140
141 #if NET_2_0
142                 [Browsable (true)]
143                 [EditorBrowsable (EditorBrowsableState.Always)]
144                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
145                 [MWFCategory("Layout")]
146                 public override bool AutoSize {
147                         get { return base.AutoSize; }
148                         set { base.AutoSize = value; }
149                 }
150
151                 public override Color BackColor {
152                         get { return base.BackColor; }
153                         set { base.BackColor = value; }
154                 }
155 #endif
156
157                 [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
158                 [Browsable (true)]
159                 [MWFCategory("Appearance")]
160 #if NET_2_0
161                 public
162 #else
163                 internal
164 #endif
165                 FlatButtonAppearance FlatAppearance {
166                         get { return flat_button_appearance; }
167                 }
168
169                 [Localizable(true)]
170                 [DefaultValue(FlatStyle.Standard)]
171                 [MWFDescription("Determines look of button"), MWFCategory("Appearance")]
172                 public FlatStyle FlatStyle {
173                         get { return flat_style; }
174                         set { 
175                                 if (flat_style != value) {
176                                         flat_style = value;
177
178                                         if (Parent != null)
179                                                 Parent.PerformLayout (this, "FlatStyle");
180                                         Invalidate();
181                                 }
182                         }
183                 }
184
185                 [Localizable(true)]
186                 [MWFDescription("Sets image to be displayed on button face"), MWFCategory("Appearance")]
187                 public Image Image {
188                         get {
189                                 if (this.image != null)
190                                         return this.image;
191
192                                 if (this.image_index >= 0)
193                                         if (this.image_list != null)
194                                                 return this.image_list.Images[this.image_index];
195
196 #if NET_2_0
197                                 if (!string.IsNullOrEmpty (this.image_key))
198                                         if (this.image_list != null)
199                                                 return this.image_list.Images[this.image_key];
200 #endif
201                                 return null;
202                         }
203                         set {
204                                 if (this.image != value) {
205                                         this.image = value;
206                                         this.image_index = -1;
207 #if NET_2_0
208                                         this.image_key = string.Empty;
209 #endif
210                                         this.image_list = null;
211
212 #if NET_2_0
213                                         if (this.AutoSize && this.Parent != null)
214                                                 this.Parent.PerformLayout (this, "Image");
215 #endif
216
217                                         Invalidate ();
218                                 }
219                         }
220                 }
221
222                 internal bool ShouldSerializeImage ()
223                 {
224                         return this.Image != null;
225                 }
226
227                 [Localizable(true)]
228                 [DefaultValue(ContentAlignment.MiddleCenter)]
229                 [MWFDescription("Sets the alignment of the image to be displayed on button face"), MWFCategory("Appearance")]
230                 public ContentAlignment ImageAlign {
231                         get { return image_alignment; }
232                         set {
233                                 if (image_alignment != value) {
234                                         image_alignment = value;
235                                         Invalidate ();
236                                 }
237                         }
238                 }
239
240                 [Localizable(true)]
241                 [DefaultValue(-1)]
242                 [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
243                 [TypeConverter(typeof(ImageIndexConverter))]
244                 [MWFDescription("Index of image to display, if ImageList is used for button face images"), MWFCategory("Appearance")]
245 #if NET_2_0
246                 [RefreshProperties (RefreshProperties.Repaint)]
247 #endif
248                 public int ImageIndex {
249                         get {
250                                 if (image_list == null)
251                                         return -1;
252
253                                 return image_index;
254                         }
255                         set {
256                                 if (this.image_index != value) {
257                                         this.image_index = value;
258                                         this.image = null;
259 #if NET_2_0
260                                         this.image_key = string.Empty;
261 #endif
262                                         Invalidate ();
263                                 }
264                         }
265                 }
266
267 #if NET_2_0
268                 [Localizable (true)]
269                 [DefaultValue ("")]
270                 [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
271                 [RefreshProperties (RefreshProperties.Repaint)]
272                 [TypeConverter (typeof (ImageKeyConverter))]
273                 [MWFCategory("Appearance")]
274                 public string ImageKey {
275                         get { return this.image_key; }
276                         set {
277                                 if (this.image_key != value) {
278                                         this.image = null;
279                                         this.image_index = -1;
280                                         this.image_key = value;
281                                         this.Invalidate ();
282                                 }
283                         }
284                 }
285 #endif
286
287                 [DefaultValue(null)]
288                 [MWFDescription("ImageList used for ImageIndex"), MWFCategory("Appearance")]
289 #if NET_2_0
290                 [RefreshProperties (RefreshProperties.Repaint)]
291 #endif
292                 public ImageList ImageList {
293                         get { return image_list; }
294                         set {
295                                 if (image_list != value) {
296                                         image_list = value;
297                                 
298                                         if (value != null && image != null)
299                                                 image = null;
300                                 
301                                         Invalidate ();
302                                 }
303                         }
304                 }
305
306                 [Browsable(false)]
307                 [EditorBrowsable (EditorBrowsableState.Never)]
308                 public new ImeMode ImeMode {
309                         get { return base.ImeMode; }
310                         set { base.ImeMode = value; }
311                 }
312
313 #if NET_2_0
314                 [SettingsBindable (true)]
315                 [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
316                          "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
317                 public override string Text {
318                         get { return base.Text; }
319                         set { base.Text = value; }
320                 }
321 #endif
322
323                 [Localizable(true)]
324                 [DefaultValue(ContentAlignment.MiddleCenter)]
325                 [MWFDescription("Alignment for button text"), MWFCategory("Appearance")]
326                 public virtual ContentAlignment TextAlign {
327                         get { return text_alignment; }
328                         set {
329                                 if (text_alignment != value) {
330                                         text_alignment = value;
331
332                                         text_format_flags &= ~TextFormatFlags.Bottom;
333                                         text_format_flags &= ~TextFormatFlags.Top;
334                                         text_format_flags &= ~TextFormatFlags.Left;
335                                         text_format_flags &= ~TextFormatFlags.Right;
336                                         text_format_flags &= ~TextFormatFlags.HorizontalCenter;
337                                         text_format_flags &= ~TextFormatFlags.VerticalCenter;
338                                         
339                                         switch (text_alignment) {
340                                                 case ContentAlignment.TopLeft:
341                                                         text_format.Alignment=StringAlignment.Near;
342                                                         text_format.LineAlignment=StringAlignment.Near;
343                                                         break;
344
345                                                 case ContentAlignment.TopCenter:
346                                                         text_format.Alignment=StringAlignment.Center;
347                                                         text_format.LineAlignment=StringAlignment.Near;
348                                                         text_format_flags |= TextFormatFlags.HorizontalCenter;
349                                                         break;
350
351                                                 case ContentAlignment.TopRight:
352                                                         text_format.Alignment=StringAlignment.Far;
353                                                         text_format.LineAlignment=StringAlignment.Near;
354                                                         text_format_flags |= TextFormatFlags.Right;
355                                                         break;
356
357                                                 case ContentAlignment.MiddleLeft:
358                                                         text_format.Alignment=StringAlignment.Near;
359                                                         text_format.LineAlignment=StringAlignment.Center;
360                                                         text_format_flags |= TextFormatFlags.VerticalCenter;
361                                                         break;
362
363                                                 case ContentAlignment.MiddleCenter:
364                                                         text_format.Alignment=StringAlignment.Center;
365                                                         text_format.LineAlignment=StringAlignment.Center;
366                                                         text_format_flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
367                                                         break;
368
369                                                 case ContentAlignment.MiddleRight:
370                                                         text_format.Alignment=StringAlignment.Far;
371                                                         text_format.LineAlignment=StringAlignment.Center;
372                                                         text_format_flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
373                                                         break;
374
375                                                 case ContentAlignment.BottomLeft:
376                                                         text_format.Alignment=StringAlignment.Near;
377                                                         text_format.LineAlignment=StringAlignment.Far;
378                                                         text_format_flags |= TextFormatFlags.Bottom;
379                                                         break;
380
381                                                 case ContentAlignment.BottomCenter:
382                                                         text_format.Alignment=StringAlignment.Center;
383                                                         text_format.LineAlignment=StringAlignment.Far;
384                                                         text_format_flags |= TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom;
385                                                         break;
386
387                                                 case ContentAlignment.BottomRight:
388                                                         text_format.Alignment=StringAlignment.Far;
389                                                         text_format.LineAlignment=StringAlignment.Far;
390                                                         text_format_flags |= TextFormatFlags.Bottom | TextFormatFlags.Right;
391                                                         break;
392                                         }
393                                         
394                                         Invalidate();
395                                 }
396                         }
397                 }
398
399 #if NET_2_0
400                 [Localizable (true)]
401                 [DefaultValue (TextImageRelation.Overlay)]
402                 [MWFCategory("Appearance")]
403                 public
404 #else
405                 internal
406 #endif
407                 TextImageRelation TextImageRelation {
408                         get { return this.text_image_relation; }
409                         set {
410                                 if (!Enum.IsDefined (typeof (TextImageRelation), value))
411                                         throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for TextImageRelation", value));
412
413                                 if (this.text_image_relation != value) {
414                                         this.text_image_relation = value;
415                                         
416 #if NET_2_0
417                                         if (this.AutoSize && this.Parent != null)
418                                                 this.Parent.PerformLayout (this, "TextImageRelation");
419 #endif
420                                         
421                                         this.Invalidate ();
422                                 }
423                         }
424                 }
425
426                 [DefaultValue (false)]
427                 [MWFCategory("Behavior")]
428 #if NET_2_0
429                 public
430 #else
431                 internal
432 #endif
433                 bool UseCompatibleTextRendering {
434                         get { return use_compatible_text_rendering; }
435                         set {
436                                 if (use_compatible_text_rendering != value) {
437                                         use_compatible_text_rendering = value;
438                                         if (Parent != null)
439                                                 Parent.PerformLayout (this, "UseCompatibleTextRendering");
440                                         Invalidate ();
441                                 }
442                         }
443                 }
444                 
445                 [DefaultValue (true)]
446                 [MWFCategory("Appearance")]
447 #if NET_2_0
448                 public
449 #else
450                 internal
451 #endif
452                 bool UseMnemonic {
453                         get { return this.use_mnemonic; }
454                         set {
455                                 if (this.use_mnemonic != value) {
456                                         this.use_mnemonic = value;
457
458                                         if (this.use_mnemonic)
459                                                 text_format_flags &= ~TextFormatFlags.NoPrefix;
460                                         else
461                                                 text_format_flags |= TextFormatFlags.NoPrefix;
462
463                                         this.Invalidate ();
464                                 }
465                         }
466                 }
467
468                 [MWFCategory("Appearance")]
469 #if NET_2_0
470                 public
471 #else
472                 internal
473 #endif
474                 bool UseVisualStyleBackColor {
475                         get { return use_visual_style_back_color; }
476                         set {
477                                 if (use_visual_style_back_color != value) {
478                                         use_visual_style_back_color = value;
479                                         Invalidate ();
480                                 }
481                         }
482                 }
483                 #endregion      // Public Instance Properties
484
485                 #region Protected Properties
486                 protected override CreateParams CreateParams {
487                         get { return base.CreateParams; }
488                 }
489
490                 protected override ImeMode DefaultImeMode {
491                         get { return ImeMode.Disable; }
492                 }
493
494                 protected override Size DefaultSize {
495                         get { return ThemeEngine.Current.ButtonBaseDefaultSize; }
496                 }
497
498                 protected internal bool IsDefault {
499                         get { return is_default; }
500                         set {
501                                 if (is_default != value) {
502                                         is_default = value;
503                                         Invalidate ();
504                                 }
505                         }
506                 }
507                 #endregion      // Public Instance Properties
508
509                 #region Public Methods
510 #if NET_2_0
511                 // The base calls into GetPreferredSizeCore, which we will override in our subclasses
512                 public override Size GetPreferredSize (Size proposedSize)
513                 {
514                         return base.GetPreferredSize (proposedSize);
515                 }
516 #endif
517                 #endregion
518                 
519                 #region Protected Methods
520                 protected override AccessibleObject CreateAccessibilityInstance ()
521                 {
522                         return new ButtonBaseAccessibleObject (this);
523                 }
524
525                 protected override void Dispose (bool disposing)
526                 {
527                         base.Dispose (disposing);
528                 }
529
530                 protected override void OnEnabledChanged (EventArgs e)
531                 {
532                         base.OnEnabledChanged (e);
533                 }
534
535                 protected override void OnGotFocus (EventArgs e)
536                 {
537                         Invalidate ();
538                         base.OnGotFocus (e);
539                 }
540
541                 protected override void OnKeyDown (KeyEventArgs kevent)
542                 {
543                         if (kevent.KeyData == Keys.Space) {
544                                 is_pressed = true;
545                                 Invalidate ();
546                                 kevent.Handled = true;
547                         }
548                         
549                         base.OnKeyDown (kevent);
550                 }
551
552                 protected override void OnKeyUp (KeyEventArgs kevent)
553                 {
554                         if (kevent.KeyData == Keys.Space) {
555                                 is_pressed = false;
556                                 Invalidate ();
557                                 OnClick (EventArgs.Empty);
558                                 kevent.Handled = true;
559                         }
560                         
561                         base.OnKeyUp (kevent);
562                 }
563
564                 protected override void OnLostFocus (EventArgs e)
565                 {
566                         Invalidate ();
567                         base.OnLostFocus (e);
568                 }
569
570                 protected override void OnMouseDown (MouseEventArgs mevent)
571                 {
572                         if ((mevent.Button & MouseButtons.Left) != 0) {
573                                 is_pressed = true;
574                                 Invalidate ();
575                         }
576
577                         base.OnMouseDown (mevent);
578                 }
579
580                 protected override void OnMouseEnter (EventArgs eventargs)
581                 {
582                         is_entered = true;
583                         Invalidate ();
584                         base.OnMouseEnter (eventargs);
585                 }
586
587                 protected override void OnMouseLeave (EventArgs eventargs)
588                 {
589                         is_entered = false;
590                         Invalidate ();
591                         base.OnMouseLeave (eventargs);
592                 }
593
594                 protected override void OnMouseMove (MouseEventArgs mevent) {
595                         bool inside = false;
596                         bool redraw = false;
597
598                         if (ClientRectangle.Contains (mevent.Location))
599                                 inside = true;
600
601                         // If the button was pressed and we leave, release the button press and vice versa
602                         if ((mevent.Button & MouseButtons.Left) != 0) {
603                                 if (this.Capture && (inside != is_pressed)) {
604                                         is_pressed = inside;
605                                         redraw = true;
606                                 }
607                         }
608
609                         if (is_entered != inside) {
610                                 is_entered = inside;
611                                 redraw = true;
612                         }
613
614                         if (redraw)
615                                 Invalidate ();
616
617                         base.OnMouseMove (mevent);
618                 }
619
620                 protected override void OnMouseUp (MouseEventArgs mevent)
621                 {
622                         if (this.Capture && ((mevent.Button & MouseButtons.Left) != 0)) {
623                                 this.Capture = false;
624
625                                 if (is_pressed) {
626                                         is_pressed = false;
627                                         Invalidate ();
628                                 } else if ((this.flat_style == FlatStyle.Flat) || (this.flat_style == FlatStyle.Popup)) {
629                                         Invalidate ();
630                                 }
631
632                                 if (ClientRectangle.Contains (mevent.Location))
633                                         if (!ValidationFailed) {
634                                                 OnClick (EventArgs.Empty);
635 #if NET_2_0
636                                                 OnMouseClick (mevent);
637 #endif
638                                         }
639                         }
640                         
641                         base.OnMouseUp (mevent);
642                 }
643
644                 protected override void OnPaint (PaintEventArgs pevent)
645                 {
646                         Draw (pevent);
647                         base.OnPaint (pevent);
648                 }
649
650                 protected override void OnParentChanged (EventArgs e)
651                 {
652                         base.OnParentChanged (e);
653                 }
654
655                 protected override void OnTextChanged (EventArgs e)
656                 {
657                         Invalidate ();
658                         base.OnTextChanged (e);
659                 }
660
661                 protected override void OnVisibleChanged (EventArgs e)
662                 {
663                         if (!Visible) {
664                                 is_pressed = false;
665                                 is_entered = false;
666                         }
667                         
668                         base.OnVisibleChanged (e);
669                 }
670
671                 protected void ResetFlagsandPaint ()
672                 {
673                         // Nothing to do; MS internal
674                         // Should we do Invalidate (); ?
675                 }
676
677                 protected override void WndProc (ref Message m)
678                 {
679                         switch ((Msg)m.Msg) {
680                                 case Msg.WM_LBUTTONDBLCLK: {
681                                         HaveDoubleClick ();
682                                         break;
683                                 }
684
685                                 case Msg.WM_MBUTTONDBLCLK: {
686                                         HaveDoubleClick ();
687                                         break;
688                                 }
689
690                                 case Msg.WM_RBUTTONDBLCLK: {
691                                         HaveDoubleClick ();
692                                         break;
693                                 }
694                         }
695                         
696                         base.WndProc (ref m);
697                 }
698                 #endregion      // Public Instance Properties
699
700                 #region Public Events
701 #if NET_2_0
702                 [Browsable (true)]
703                 [EditorBrowsable (EditorBrowsableState.Always)]
704                 public new event EventHandler AutoSizeChanged {
705                         add { base.AutoSizeChanged += value; }
706                         remove { base.AutoSizeChanged -= value; }
707                 }
708 #endif
709
710                 [Browsable (false)]
711                 [EditorBrowsable (EditorBrowsableState.Never)]
712                 public new event EventHandler ImeModeChanged {
713                         add { base.ImeModeChanged += value; }
714                         remove { base.ImeModeChanged -= value; }
715                 }
716                 #endregion      // Events
717
718                 #region Internal Properties
719                 internal ButtonState ButtonState {
720                         get {
721                                 ButtonState ret = ButtonState.Normal;
722
723                                 if (Enabled) {
724                                         // Popup style is only followed as long as the mouse isn't "in" the control
725                                         if (is_entered) {
726                                                 if (flat_style == FlatStyle.Flat) {
727                                                         ret |= ButtonState.Flat;
728                                                 }
729                                         } else {
730                                                 if (flat_style == FlatStyle.Flat || flat_style == FlatStyle.Popup) {
731                                                         ret |= ButtonState.Flat;
732                                                 }
733                                         }
734
735                                         if (is_entered && is_pressed) {
736                                                 ret |= ButtonState.Pushed;
737                                         }
738                                 } else {
739                                         ret |= ButtonState.Inactive;
740                                         if ((flat_style == FlatStyle.Flat) || (flat_style == FlatStyle.Popup)) {
741                                                 ret |= ButtonState.Flat;
742                                         }
743                                 }
744                                 return ret;
745                         }
746                 }
747
748                 internal bool Pressed {
749                         get { return this.is_pressed; }
750                 }
751                 
752                 // The flags to be used for MeasureText and DrawText
753                 internal TextFormatFlags TextFormatFlags {
754                         get { return this.text_format_flags; }
755                 }
756                 #endregion
757                 
758                 #region Internal Methods
759                 // Derived classes should override Draw method and we dont want
760                 // to break the control signature, hence this approach.
761                 internal virtual void Draw (PaintEventArgs pevent)
762                 {
763                         ThemeEngine.Current.DrawButtonBase (pevent.Graphics, pevent.ClipRectangle, this);
764                 }
765                 
766                 internal virtual void HaveDoubleClick ()
767                 {
768                         // override me
769                 }
770
771                 internal override void OnPaintBackgroundInternal (PaintEventArgs e)
772                 {
773                         base.OnPaintBackground (e);
774                 }
775                 #endregion      // Internal Methods
776
777                 #region ButtonBaseAccessibleObject sub-class
778                 [ComVisible (true)]
779                 public class ButtonBaseAccessibleObject : ControlAccessibleObject
780                 {
781                         #region ButtonBaseAccessibleObject Local Variables
782                         private new Control owner;
783                         #endregion      // ButtonBaseAccessibleObject Local Variables
784
785                         #region ButtonBaseAccessibleObject Constructors
786                         public ButtonBaseAccessibleObject (Control owner) : base (owner)
787                         {
788                                 if (owner == null)
789                                         throw new ArgumentNullException ("owner");
790                                         
791                                 this.owner = owner;
792                                 default_action = "Press";
793                                 role = AccessibleRole.PushButton;
794                         }
795                         #endregion      // ButtonBaseAccessibleObject Constructors
796
797                         #region Public Properties
798 #if NET_2_0
799                         public override AccessibleStates State {
800                                 get { return base.State; }
801                         }
802 #endif
803                         #endregion
804                         
805                         #region ButtonBaseAccessibleObject Methods
806                         public override void DoDefaultAction ()
807                         {
808                                 ((ButtonBase)owner).OnClick (EventArgs.Empty);
809                         }
810                         #endregion      // ButtonBaseAccessibleObject Methods
811                 }
812                 #endregion      // ButtonBaseAccessibleObject sub-class
813         }
814 }