button.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/button.h
  3. // Purpose: wxButton for wxUniversal
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 15.08.00
  7. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_BUTTON_H_
  11. #define _WX_UNIV_BUTTON_H_
  12. class WXDLLIMPEXP_FWD_CORE wxInputHandler;
  13. #include "wx/bitmap.h"
  14. // ----------------------------------------------------------------------------
  15. // the actions supported by this control
  16. // ----------------------------------------------------------------------------
  17. #define wxACTION_BUTTON_TOGGLE wxT("toggle") // press/release the button
  18. #define wxACTION_BUTTON_PRESS wxT("press") // press the button
  19. #define wxACTION_BUTTON_RELEASE wxT("release") // release the button
  20. #define wxACTION_BUTTON_CLICK wxT("click") // generate button click event
  21. // ----------------------------------------------------------------------------
  22. // wxButton: a push button
  23. // ----------------------------------------------------------------------------
  24. class WXDLLIMPEXP_CORE wxButton : public wxButtonBase
  25. {
  26. public:
  27. wxButton() { Init(); }
  28. wxButton(wxWindow *parent,
  29. wxWindowID id,
  30. const wxBitmap& bitmap,
  31. const wxString& label = wxEmptyString,
  32. const wxPoint& pos = wxDefaultPosition,
  33. const wxSize& size = wxDefaultSize,
  34. long style = 0,
  35. const wxValidator& validator = wxDefaultValidator,
  36. const wxString& name = wxButtonNameStr)
  37. {
  38. Init();
  39. Create(parent, id, bitmap, label, pos, size, style, validator, name);
  40. }
  41. wxButton(wxWindow *parent,
  42. wxWindowID id,
  43. const wxString& label = wxEmptyString,
  44. const wxPoint& pos = wxDefaultPosition,
  45. const wxSize& size = wxDefaultSize,
  46. long style = 0,
  47. const wxValidator& validator = wxDefaultValidator,
  48. const wxString& name = wxButtonNameStr)
  49. {
  50. Init();
  51. Create(parent, id, label, pos, size, style, validator, name);
  52. }
  53. bool Create(wxWindow *parent,
  54. wxWindowID id,
  55. const wxString& label = wxEmptyString,
  56. const wxPoint& pos = wxDefaultPosition,
  57. const wxSize& size = wxDefaultSize,
  58. long style = 0,
  59. const wxValidator& validator = wxDefaultValidator,
  60. const wxString& name = wxButtonNameStr)
  61. {
  62. return Create(parent, id, wxNullBitmap, label,
  63. pos, size, style, validator, name);
  64. }
  65. bool Create(wxWindow *parent,
  66. wxWindowID id,
  67. const wxBitmap& bitmap,
  68. const wxString& label = wxEmptyString,
  69. const wxPoint& pos = wxDefaultPosition,
  70. const wxSize& size = wxDefaultSize,
  71. long style = 0,
  72. const wxValidator& validator = wxDefaultValidator,
  73. const wxString& name = wxButtonNameStr);
  74. virtual ~wxButton();
  75. virtual wxWindow *SetDefault();
  76. virtual bool IsPressed() const { return m_isPressed; }
  77. virtual bool IsDefault() const { return m_isDefault; }
  78. // wxButton actions
  79. virtual void Toggle();
  80. virtual void Press();
  81. virtual void Release();
  82. virtual void Click();
  83. virtual bool PerformAction(const wxControlAction& action,
  84. long numArg = -1,
  85. const wxString& strArg = wxEmptyString);
  86. virtual bool CanBeHighlighted() const { return true; }
  87. static wxInputHandler *GetStdInputHandler(wxInputHandler *handlerDef);
  88. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
  89. {
  90. return GetStdInputHandler(handlerDef);
  91. }
  92. protected:
  93. virtual wxSize DoGetBestClientSize() const;
  94. virtual bool DoDrawBackground(wxDC& dc);
  95. virtual void DoDraw(wxControlRenderer *renderer);
  96. virtual void DoSetBitmap(const wxBitmap& bitmap, State which);
  97. virtual void DoSetBitmapMargins(wxCoord x, wxCoord y);
  98. // common part of all ctors
  99. void Init();
  100. // current state
  101. bool m_isPressed,
  102. m_isDefault;
  103. // the (optional) image to show and the margins around it
  104. wxBitmap m_bitmap;
  105. wxCoord m_marginBmpX,
  106. m_marginBmpY;
  107. private:
  108. DECLARE_DYNAMIC_CLASS(wxButton)
  109. };
  110. #endif // _WX_UNIV_BUTTON_H_