ButtonBase.cs 20 KB

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