checkbox.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/checkbox.h
  3. // Purpose: wxCheckBox declaration
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 07.09.00
  7. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_CHECKBOX_H_
  11. #define _WX_UNIV_CHECKBOX_H_
  12. #include "wx/button.h" // for wxStdButtonInputHandler
  13. // ----------------------------------------------------------------------------
  14. // the actions supported by wxCheckBox
  15. // ----------------------------------------------------------------------------
  16. #define wxACTION_CHECKBOX_CHECK wxT("check") // SetValue(true)
  17. #define wxACTION_CHECKBOX_CLEAR wxT("clear") // SetValue(false)
  18. #define wxACTION_CHECKBOX_TOGGLE wxT("toggle") // toggle the check state
  19. // additionally it accepts wxACTION_BUTTON_PRESS and RELEASE
  20. // ----------------------------------------------------------------------------
  21. // wxCheckBox
  22. // ----------------------------------------------------------------------------
  23. class WXDLLIMPEXP_CORE wxCheckBox : public wxCheckBoxBase
  24. {
  25. public:
  26. // checkbox constants
  27. enum State
  28. {
  29. State_Normal,
  30. State_Pressed,
  31. State_Disabled,
  32. State_Current,
  33. State_Max
  34. };
  35. enum Status
  36. {
  37. Status_Checked,
  38. Status_Unchecked,
  39. Status_3rdState,
  40. Status_Max
  41. };
  42. // constructors
  43. wxCheckBox() { Init(); }
  44. wxCheckBox(wxWindow *parent,
  45. wxWindowID id,
  46. const wxString& label,
  47. const wxPoint& pos = wxDefaultPosition,
  48. const wxSize& size = wxDefaultSize,
  49. long style = 0,
  50. const wxValidator& validator = wxDefaultValidator,
  51. const wxString& name = wxCheckBoxNameStr)
  52. {
  53. Init();
  54. Create(parent, id, label, pos, size, style, validator, name);
  55. }
  56. bool Create(wxWindow *parent,
  57. wxWindowID id,
  58. const wxString& label,
  59. const wxPoint& pos = wxDefaultPosition,
  60. const wxSize& size = wxDefaultSize,
  61. long style = 0,
  62. const wxValidator& validator = wxDefaultValidator,
  63. const wxString& name = wxCheckBoxNameStr);
  64. // implement the checkbox interface
  65. virtual void SetValue(bool value);
  66. virtual bool GetValue() const;
  67. // set/get the bitmaps to use for the checkbox indicator
  68. void SetBitmap(const wxBitmap& bmp, State state, Status status);
  69. virtual wxBitmap GetBitmap(State state, Status status) const;
  70. // wxCheckBox actions
  71. void Toggle();
  72. virtual void Press();
  73. virtual void Release();
  74. virtual void ChangeValue(bool value);
  75. // overridden base class virtuals
  76. virtual bool IsPressed() const { return m_isPressed; }
  77. virtual bool PerformAction(const wxControlAction& action,
  78. long numArg = -1,
  79. const wxString& strArg = wxEmptyString);
  80. virtual bool CanBeHighlighted() const { return true; }
  81. virtual wxInputHandler *CreateStdInputHandler(wxInputHandler *handlerDef);
  82. virtual wxInputHandler *DoGetStdInputHandler(wxInputHandler *handlerDef)
  83. {
  84. return CreateStdInputHandler(handlerDef);
  85. }
  86. protected:
  87. virtual void DoSet3StateValue(wxCheckBoxState WXUNUSED(state));
  88. virtual wxCheckBoxState DoGet3StateValue() const;
  89. virtual void DoDraw(wxControlRenderer *renderer);
  90. virtual wxSize DoGetBestClientSize() const;
  91. // get the size of the bitmap using either the current one or the default
  92. // one (query renderer then)
  93. virtual wxSize GetBitmapSize() const;
  94. // common part of all ctors
  95. void Init();
  96. // send command event notifying about the checkbox state change
  97. virtual void SendEvent();
  98. // called when the checkbox becomes checked - radio button hook
  99. virtual void OnCheck();
  100. // get the state corresponding to the flags (combination of wxCONTROL_XXX)
  101. wxCheckBox::State GetState(int flags) const;
  102. // directly access the bitmaps array without trying to find a valid bitmap
  103. // to use as GetBitmap() does
  104. wxBitmap DoGetBitmap(State state, Status status) const
  105. { return m_bitmaps[state][status]; }
  106. // get the current status
  107. Status GetStatus() const { return m_status; }
  108. private:
  109. // the current check status
  110. Status m_status;
  111. // the bitmaps to use for the different states
  112. wxBitmap m_bitmaps[State_Max][Status_Max];
  113. // is the checkbox currently pressed?
  114. bool m_isPressed;
  115. DECLARE_DYNAMIC_CLASS(wxCheckBox)
  116. };
  117. #endif // _WX_UNIV_CHECKBOX_H_