ButtonBase.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803
  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 [email protected]
  24. //
  25. using System.ComponentModel;
  26. using System.ComponentModel.Design;
  27. using System.Drawing;
  28. using System.Drawing.Text;
  29. using System.Runtime.InteropServices;
  30. namespace System.Windows.Forms {
  31. #if NET_2_0
  32. [ClassInterface (ClassInterfaceType.AutoDispatch)]
  33. [ComVisible (true)]
  34. [Designer ("System.Windows.Forms.Design.ButtonBaseDesigner, " + Consts.AssemblySystem_Design,
  35. "System.ComponentModel.Design.IDesigner")]
  36. #endif
  37. public abstract class ButtonBase : Control
  38. {
  39. #region Local Variables
  40. private FlatStyle flat_style;
  41. private int image_index;
  42. internal Image image;
  43. internal ImageList image_list;
  44. private ContentAlignment image_alignment;
  45. internal ContentAlignment text_alignment;
  46. private bool is_default;
  47. internal bool is_pressed;
  48. // private bool enter_state;
  49. internal StringFormat text_format;
  50. internal bool paint_as_acceptbutton;
  51. // Properties are 2.0, but variables used in 1.1 for common drawing code
  52. private bool auto_ellipsis;
  53. private FlatButtonAppearance flat_button_appearance;
  54. #if NET_2_0
  55. private string image_key;
  56. #endif
  57. private TextImageRelation text_image_relation;
  58. private TextFormatFlags text_format_flags;
  59. private bool use_mnemonic;
  60. private bool use_visual_style_back_color;
  61. #endregion // Local Variables
  62. #region Public Constructors
  63. protected ButtonBase() : base()
  64. {
  65. flat_style = FlatStyle.Standard;
  66. #if NET_2_0
  67. flat_button_appearance = new FlatButtonAppearance (this);
  68. this.image_key = string.Empty;
  69. this.text_image_relation = TextImageRelation.Overlay;
  70. this.use_mnemonic = true;
  71. use_visual_style_back_color = true;
  72. #endif
  73. image_index = -1;
  74. image = null;
  75. image_list = null;
  76. image_alignment = ContentAlignment.MiddleCenter;
  77. ImeMode = ImeMode.Disable;
  78. text_alignment = ContentAlignment.MiddleCenter;
  79. is_default = false;
  80. is_pressed = false;
  81. text_format = new StringFormat();
  82. text_format.Alignment = StringAlignment.Center;
  83. text_format.LineAlignment = StringAlignment.Center;
  84. text_format.HotkeyPrefix = HotkeyPrefix.Show;
  85. text_format.FormatFlags |= StringFormatFlags.LineLimit;
  86. text_format_flags = TextFormatFlags.HorizontalCenter;
  87. text_format_flags |= TextFormatFlags.VerticalCenter;
  88. text_format_flags |= TextFormatFlags.TextBoxControl;
  89. SetStyle (ControlStyles.ResizeRedraw |
  90. ControlStyles.Opaque |
  91. ControlStyles.UserMouse |
  92. ControlStyles.SupportsTransparentBackColor |
  93. ControlStyles.CacheText |
  94. #if NET_2_0
  95. ControlStyles.OptimizedDoubleBuffer, true);
  96. #else
  97. ControlStyles.DoubleBuffer, true);
  98. #endif
  99. SetStyle (ControlStyles.StandardClick, false);
  100. }
  101. #endregion // Public Constructors
  102. #region Public Properties
  103. [Browsable (true)]
  104. [DefaultValue (false)]
  105. [EditorBrowsable (EditorBrowsableState.Always)]
  106. [MWFCategory("Behavior")]
  107. #if NET_2_0
  108. public
  109. #else
  110. internal
  111. #endif
  112. bool AutoEllipsis {
  113. get { return this.auto_ellipsis; }
  114. set
  115. {
  116. if (this.auto_ellipsis != value) {
  117. this.auto_ellipsis = value;
  118. if (this.auto_ellipsis) {
  119. text_format_flags |= TextFormatFlags.EndEllipsis;
  120. text_format_flags &= ~TextFormatFlags.WordBreak;
  121. } else {
  122. text_format_flags &= ~TextFormatFlags.EndEllipsis;
  123. text_format_flags |= TextFormatFlags.WordBreak;
  124. }
  125. this.Invalidate ();
  126. }
  127. }
  128. }
  129. #if NET_2_0
  130. [Browsable (true)]
  131. [EditorBrowsable (EditorBrowsableState.Always)]
  132. [DesignerSerializationVisibility (DesignerSerializationVisibility.Visible)]
  133. [MWFCategory("Layout")]
  134. public override bool AutoSize {
  135. get { return base.AutoSize; }
  136. set { base.AutoSize = value; }
  137. }
  138. public override Color BackColor {
  139. get { return base.BackColor; }
  140. set { base.BackColor = value; }
  141. }
  142. #endif
  143. [DesignerSerializationVisibility (DesignerSerializationVisibility.Content)]
  144. [Browsable (true)]
  145. [MWFCategory("Appearance")]
  146. #if NET_2_0
  147. public
  148. #else
  149. internal
  150. #endif
  151. FlatButtonAppearance FlatAppearance {
  152. get { return flat_button_appearance; }
  153. }
  154. [Localizable(true)]
  155. [DefaultValue(FlatStyle.Standard)]
  156. [MWFDescription("Determines look of button"), MWFCategory("Appearance")]
  157. public FlatStyle FlatStyle {
  158. get { return flat_style; }
  159. set {
  160. if (flat_style != value) {
  161. flat_style = value;
  162. Invalidate();
  163. }
  164. }
  165. }
  166. [Localizable(true)]
  167. [MWFDescription("Sets image to be displayed on button face"), MWFCategory("Appearance")]
  168. public Image Image {
  169. get {
  170. if (this.image != null)
  171. return this.image;
  172. if (this.image_index >= 0)
  173. if (this.image_list != null)
  174. return this.image_list.Images[this.image_index];
  175. #if NET_2_0
  176. if (!string.IsNullOrEmpty (this.image_key))
  177. if (this.image_list != null)
  178. return this.image_list.Images[this.image_key];
  179. #endif
  180. return null;
  181. }
  182. set {
  183. if (this.image != value) {
  184. this.image = value;
  185. this.image_index = -1;
  186. #if NET_2_0
  187. this.image_key = string.Empty;
  188. #endif
  189. this.image_list = null;
  190. #if NET_2_0
  191. if (this.AutoSize && this.Parent != null)
  192. this.Parent.PerformLayout (this, "Image");
  193. #endif
  194. Invalidate ();
  195. }
  196. }
  197. }
  198. internal bool ShouldSerializeImage ()
  199. {
  200. return this.Image != null;
  201. }
  202. [Localizable(true)]
  203. [DefaultValue(ContentAlignment.MiddleCenter)]
  204. [MWFDescription("Sets the alignment of the image to be displayed on button face"), MWFCategory("Appearance")]
  205. public ContentAlignment ImageAlign {
  206. get { return image_alignment; }
  207. set {
  208. if (image_alignment != value) {
  209. image_alignment = value;
  210. Invalidate ();
  211. }
  212. }
  213. }
  214. [Localizable(true)]
  215. [DefaultValue(-1)]
  216. [Editor("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof(System.Drawing.Design.UITypeEditor))]
  217. [TypeConverter(typeof(ImageIndexConverter))]
  218. [MWFDescription("Index of image to display, if ImageList is used for button face images"), MWFCategory("Appearance")]
  219. #if NET_2_0
  220. [RefreshProperties (RefreshProperties.Repaint)]
  221. #endif
  222. public int ImageIndex {
  223. get {
  224. if (image_list == null)
  225. return -1;
  226. return image_index;
  227. }
  228. set {
  229. if (this.image_index != value) {
  230. this.image_index = value;
  231. this.image = null;
  232. #if NET_2_0
  233. this.image_key = string.Empty;
  234. #endif
  235. Invalidate ();
  236. }
  237. }
  238. }
  239. #if NET_2_0
  240. [Localizable (true)]
  241. [DefaultValue ("")]
  242. [Editor ("System.Windows.Forms.Design.ImageIndexEditor, " + Consts.AssemblySystem_Design, typeof (System.Drawing.Design.UITypeEditor))]
  243. [RefreshProperties (RefreshProperties.Repaint)]
  244. [TypeConverter (typeof (ImageKeyConverter))]
  245. [MWFCategory("Appearance")]
  246. public string ImageKey {
  247. get { return this.image_key; }
  248. set {
  249. if (this.image_key != value) {
  250. this.image = null;
  251. this.image_index = -1;
  252. this.image_key = value;
  253. this.Invalidate ();
  254. }
  255. }
  256. }
  257. #endif
  258. [DefaultValue(null)]
  259. [MWFDescription("ImageList used for ImageIndex"), MWFCategory("Appearance")]
  260. #if NET_2_0
  261. [RefreshProperties (RefreshProperties.Repaint)]
  262. #endif
  263. public ImageList ImageList {
  264. get { return image_list; }
  265. set {
  266. if (image_list != value) {
  267. image_list = value;
  268. if (value != null && image != null)
  269. image = null;
  270. Invalidate ();
  271. }
  272. }
  273. }
  274. [Browsable(false)]
  275. [EditorBrowsable (EditorBrowsableState.Never)]
  276. public new ImeMode ImeMode {
  277. get { return base.ImeMode; }
  278. set { base.ImeMode = value; }
  279. }
  280. #if NET_2_0
  281. [SettingsBindable (true)]
  282. [Editor ("System.ComponentModel.Design.MultilineStringEditor, " + Consts.AssemblySystem_Design,
  283. "System.Drawing.Design.UITypeEditor, " + Consts.AssemblySystem_Drawing)]
  284. public override string Text {
  285. get { return base.Text; }
  286. set { base.Text = value; }
  287. }
  288. #endif
  289. [Localizable(true)]
  290. [DefaultValue(ContentAlignment.MiddleCenter)]
  291. [MWFDescription("Alignment for button text"), MWFCategory("Appearance")]
  292. public virtual ContentAlignment TextAlign {
  293. get { return text_alignment; }
  294. set {
  295. if (text_alignment != value) {
  296. text_alignment = value;
  297. text_format_flags &= ~TextFormatFlags.Bottom;
  298. text_format_flags &= ~TextFormatFlags.Top;
  299. text_format_flags &= ~TextFormatFlags.Left;
  300. text_format_flags &= ~TextFormatFlags.Right;
  301. text_format_flags &= ~TextFormatFlags.HorizontalCenter;
  302. text_format_flags &= ~TextFormatFlags.VerticalCenter;
  303. switch (text_alignment) {
  304. case ContentAlignment.TopLeft:
  305. text_format.Alignment=StringAlignment.Near;
  306. text_format.LineAlignment=StringAlignment.Near;
  307. break;
  308. case ContentAlignment.TopCenter:
  309. text_format.Alignment=StringAlignment.Center;
  310. text_format.LineAlignment=StringAlignment.Near;
  311. text_format_flags |= TextFormatFlags.HorizontalCenter;
  312. break;
  313. case ContentAlignment.TopRight:
  314. text_format.Alignment=StringAlignment.Far;
  315. text_format.LineAlignment=StringAlignment.Near;
  316. text_format_flags |= TextFormatFlags.Right;
  317. break;
  318. case ContentAlignment.MiddleLeft:
  319. text_format.Alignment=StringAlignment.Near;
  320. text_format.LineAlignment=StringAlignment.Center;
  321. text_format_flags |= TextFormatFlags.VerticalCenter;
  322. break;
  323. case ContentAlignment.MiddleCenter:
  324. text_format.Alignment=StringAlignment.Center;
  325. text_format.LineAlignment=StringAlignment.Center;
  326. text_format_flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter;
  327. break;
  328. case ContentAlignment.MiddleRight:
  329. text_format.Alignment=StringAlignment.Far;
  330. text_format.LineAlignment=StringAlignment.Center;
  331. text_format_flags |= TextFormatFlags.VerticalCenter | TextFormatFlags.Right;
  332. break;
  333. case ContentAlignment.BottomLeft:
  334. text_format.Alignment=StringAlignment.Near;
  335. text_format.LineAlignment=StringAlignment.Far;
  336. text_format_flags |= TextFormatFlags.Bottom;
  337. break;
  338. case ContentAlignment.BottomCenter:
  339. text_format.Alignment=StringAlignment.Center;
  340. text_format.LineAlignment=StringAlignment.Far;
  341. text_format_flags |= TextFormatFlags.HorizontalCenter | TextFormatFlags.Bottom;
  342. break;
  343. case ContentAlignment.BottomRight:
  344. text_format.Alignment=StringAlignment.Far;
  345. text_format.LineAlignment=StringAlignment.Far;
  346. text_format_flags |= TextFormatFlags.Bottom | TextFormatFlags.Right;
  347. break;
  348. }
  349. Invalidate();
  350. }
  351. }
  352. }
  353. #if NET_2_0
  354. [Localizable (true)]
  355. [DefaultValue (TextImageRelation.Overlay)]
  356. [MWFCategory("Appearance")]
  357. public
  358. #else
  359. internal
  360. #endif
  361. TextImageRelation TextImageRelation {
  362. get { return this.text_image_relation; }
  363. set {
  364. if (!Enum.IsDefined (typeof (TextImageRelation), value))
  365. throw new InvalidEnumArgumentException (string.Format ("Enum argument value '{0}' is not valid for TextImageRelation", value));
  366. if (this.text_image_relation != value) {
  367. this.text_image_relation = value;
  368. #if NET_2_0
  369. if (this.AutoSize && this.Parent != null)
  370. this.Parent.PerformLayout (this, "TextImageRelation");
  371. #endif
  372. this.Invalidate ();
  373. }
  374. }
  375. }
  376. [DefaultValue (false)]
  377. [MWFCategory("Behavior")]
  378. #if NET_2_0
  379. public
  380. #else
  381. internal
  382. #endif
  383. bool UseCompatibleTextRendering {
  384. get { return use_compatible_text_rendering; }
  385. set {
  386. if (use_compatible_text_rendering != value) {
  387. use_compatible_text_rendering = value;
  388. Invalidate ();
  389. }
  390. }
  391. }
  392. [DefaultValue (true)]
  393. [MWFCategory("Appearance")]
  394. #if NET_2_0
  395. public
  396. #else
  397. internal
  398. #endif
  399. bool UseMnemonic {
  400. get { return this.use_mnemonic; }
  401. set {
  402. if (this.use_mnemonic != value) {
  403. this.use_mnemonic = value;
  404. if (this.use_mnemonic)
  405. text_format_flags &= ~TextFormatFlags.NoPrefix;
  406. else
  407. text_format_flags |= TextFormatFlags.NoPrefix;
  408. this.Invalidate ();
  409. }
  410. }
  411. }
  412. [MWFCategory("Appearance")]
  413. #if NET_2_0
  414. public
  415. #else
  416. internal
  417. #endif
  418. bool UseVisualStyleBackColor {
  419. get { return use_visual_style_back_color; }
  420. set {
  421. if (use_visual_style_back_color != value) {
  422. use_visual_style_back_color = value;
  423. Invalidate ();
  424. }
  425. }
  426. }
  427. #endregion // Public Instance Properties
  428. #region Protected Properties
  429. protected override CreateParams CreateParams {
  430. get { return base.CreateParams; }
  431. }
  432. protected override ImeMode DefaultImeMode {
  433. get { return ImeMode.Disable; }
  434. }
  435. protected override Size DefaultSize {
  436. get { return ThemeEngine.Current.ButtonBaseDefaultSize; }
  437. }
  438. protected internal bool IsDefault {
  439. get { return is_default; }
  440. set {
  441. if (is_default != value) {
  442. is_default = value;
  443. Invalidate ();
  444. }
  445. }
  446. }
  447. #endregion // Public Instance Properties
  448. #region Public Methods
  449. #if NET_2_0
  450. // The base calls into GetPreferredSizeCore, which we will override in our subclasses
  451. public override Size GetPreferredSize (Size proposedSize)
  452. {
  453. return base.GetPreferredSize (proposedSize);
  454. }
  455. #endif
  456. #endregion
  457. #region Protected Methods
  458. protected override AccessibleObject CreateAccessibilityInstance ()
  459. {
  460. return new ButtonBaseAccessibleObject (this);
  461. }
  462. protected override void Dispose (bool disposing)
  463. {
  464. base.Dispose (disposing);
  465. }
  466. protected override void OnEnabledChanged (EventArgs e)
  467. {
  468. base.OnEnabledChanged (e);
  469. }
  470. protected override void OnGotFocus (EventArgs e)
  471. {
  472. Invalidate ();
  473. base.OnGotFocus (e);
  474. }
  475. protected override void OnKeyDown (KeyEventArgs kevent)
  476. {
  477. if (kevent.KeyData == Keys.Space) {
  478. is_pressed = true;
  479. Invalidate ();
  480. kevent.Handled = true;
  481. }
  482. base.OnKeyDown (kevent);
  483. }
  484. protected override void OnKeyUp (KeyEventArgs kevent)
  485. {
  486. if (kevent.KeyData == Keys.Space) {
  487. is_pressed = false;
  488. Invalidate ();
  489. OnClick (EventArgs.Empty);
  490. kevent.Handled = true;
  491. }
  492. base.OnKeyUp (kevent);
  493. }
  494. protected override void OnLostFocus (EventArgs e)
  495. {
  496. Invalidate ();
  497. base.OnLostFocus (e);
  498. }
  499. protected override void OnMouseDown (MouseEventArgs mevent)
  500. {
  501. if ((mevent.Button & MouseButtons.Left) != 0) {
  502. is_pressed = true;
  503. Invalidate ();
  504. }
  505. base.OnMouseDown (mevent);
  506. }
  507. protected override void OnMouseEnter (EventArgs eventargs)
  508. {
  509. is_entered = true;
  510. Invalidate ();
  511. base.OnMouseEnter (eventargs);
  512. }
  513. protected override void OnMouseLeave (EventArgs eventargs)
  514. {
  515. is_entered = false;
  516. Invalidate ();
  517. base.OnMouseLeave (eventargs);
  518. }
  519. protected override void OnMouseMove (MouseEventArgs mevent) {
  520. bool inside = false;
  521. bool redraw = false;
  522. if (ClientRectangle.Contains (mevent.Location))
  523. inside = true;
  524. // If the button was pressed and we leave, release the button press and vice versa
  525. if ((mevent.Button & MouseButtons.Left) != 0) {
  526. if (this.Capture && (inside != is_pressed)) {
  527. is_pressed = inside;
  528. redraw = true;
  529. }
  530. }
  531. if (is_entered != inside) {
  532. is_entered = inside;
  533. redraw = true;
  534. }
  535. if (redraw)
  536. Invalidate ();
  537. base.OnMouseMove (mevent);
  538. }
  539. protected override void OnMouseUp (MouseEventArgs mevent)
  540. {
  541. if (this.Capture && ((mevent.Button & MouseButtons.Left) != 0)) {
  542. this.Capture = false;
  543. if (is_pressed) {
  544. is_pressed = false;
  545. Invalidate ();
  546. } else if ((this.flat_style == FlatStyle.Flat) || (this.flat_style == FlatStyle.Popup)) {
  547. Invalidate ();
  548. }
  549. if (ClientRectangle.Contains (mevent.Location))
  550. if (!ValidationFailed)
  551. OnClick (EventArgs.Empty);
  552. }
  553. base.OnMouseUp (mevent);
  554. }
  555. protected override void OnPaint (PaintEventArgs pevent)
  556. {
  557. Draw (pevent);
  558. base.OnPaint (pevent);
  559. }
  560. protected override void OnParentChanged (EventArgs e)
  561. {
  562. base.OnParentChanged (e);
  563. }
  564. protected override void OnTextChanged (EventArgs e)
  565. {
  566. Invalidate ();
  567. base.OnTextChanged (e);
  568. }
  569. protected override void OnVisibleChanged (EventArgs e)
  570. {
  571. if (!Visible) {
  572. is_pressed = false;
  573. is_entered = false;
  574. }
  575. base.OnVisibleChanged (e);
  576. }
  577. protected void ResetFlagsandPaint ()
  578. {
  579. // Nothing to do; MS internal
  580. // Should we do Invalidate (); ?
  581. }
  582. protected override void WndProc (ref Message m)
  583. {
  584. switch ((Msg)m.Msg) {
  585. case Msg.WM_LBUTTONDBLCLK: {
  586. HaveDoubleClick ();
  587. break;
  588. }
  589. case Msg.WM_MBUTTONDBLCLK: {
  590. HaveDoubleClick ();
  591. break;
  592. }
  593. case Msg.WM_RBUTTONDBLCLK: {
  594. HaveDoubleClick ();
  595. break;
  596. }
  597. }
  598. base.WndProc (ref m);
  599. }
  600. #endregion // Public Instance Properties
  601. #region Public Events
  602. #if NET_2_0
  603. [Browsable (true)]
  604. [EditorBrowsable (EditorBrowsableState.Always)]
  605. public new event EventHandler AutoSizeChanged {
  606. add { base.AutoSizeChanged += value; }
  607. remove { base.AutoSizeChanged -= value; }
  608. }
  609. #endif
  610. [Browsable (false)]
  611. [EditorBrowsable (EditorBrowsableState.Never)]
  612. public new event EventHandler ImeModeChanged {
  613. add { base.ImeModeChanged += value; }
  614. remove { base.ImeModeChanged -= value; }
  615. }
  616. #endregion // Events
  617. #region Internal Properties
  618. internal ButtonState ButtonState {
  619. get {
  620. ButtonState ret = ButtonState.Normal;
  621. if (Enabled) {
  622. // Popup style is only followed as long as the mouse isn't "in" the control
  623. if (is_entered) {
  624. if (flat_style == FlatStyle.Flat) {
  625. ret |= ButtonState.Flat;
  626. }
  627. } else {
  628. if (flat_style == FlatStyle.Flat || flat_style == FlatStyle.Popup) {
  629. ret |= ButtonState.Flat;
  630. }
  631. }
  632. if (is_entered && is_pressed) {
  633. ret |= ButtonState.Pushed;
  634. }
  635. } else {
  636. ret |= ButtonState.Inactive;
  637. if ((flat_style == FlatStyle.Flat) || (flat_style == FlatStyle.Popup)) {
  638. ret |= ButtonState.Flat;
  639. }
  640. }
  641. return ret;
  642. }
  643. }
  644. internal bool Pressed {
  645. get { return this.is_pressed; }
  646. }
  647. // The flags to be used for MeasureText and DrawText
  648. internal TextFormatFlags TextFormatFlags {
  649. get { return this.text_format_flags; }
  650. }
  651. #endregion
  652. #region Internal Methods
  653. // Derived classes should override Draw method and we dont want
  654. // to break the control signature, hence this approach.
  655. internal virtual void Draw (PaintEventArgs pevent)
  656. {
  657. ThemeEngine.Current.DrawButtonBase (pevent.Graphics, pevent.ClipRectangle, this);
  658. }
  659. internal virtual void HaveDoubleClick ()
  660. {
  661. // override me
  662. }
  663. internal override void OnPaintBackgroundInternal (PaintEventArgs e)
  664. {
  665. base.OnPaintBackground (e);
  666. }
  667. #endregion // Internal Methods
  668. #region ButtonBaseAccessibleObject sub-class
  669. [ComVisible (true)]
  670. public class ButtonBaseAccessibleObject : ControlAccessibleObject
  671. {
  672. #region ButtonBaseAccessibleObject Local Variables
  673. private new Control owner;
  674. #endregion // ButtonBaseAccessibleObject Local Variables
  675. #region ButtonBaseAccessibleObject Constructors
  676. public ButtonBaseAccessibleObject (Control owner) : base (owner)
  677. {
  678. if (owner == null)
  679. throw new ArgumentNullException ("owner");
  680. this.owner = owner;
  681. default_action = "Press";
  682. role = AccessibleRole.PushButton;
  683. }
  684. #endregion // ButtonBaseAccessibleObject Constructors
  685. #region Public Properties
  686. #if NET_2_0
  687. public override AccessibleStates State {
  688. get { return base.State; }
  689. }
  690. #endif
  691. #endregion
  692. #region ButtonBaseAccessibleObject Methods
  693. public override void DoDefaultAction ()
  694. {
  695. ((ButtonBase)owner).OnClick (EventArgs.Empty);
  696. }
  697. #endregion // ButtonBaseAccessibleObject Methods
  698. }
  699. #endregion // ButtonBaseAccessibleObject sub-class
  700. }
  701. }