radiobox.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/univ/radiobox.h
  3. // Purpose: wxRadioBox declaration
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 11.09.00
  7. // Copyright: (c) 2000 SciTech Software, Inc. (www.scitechsoft.com)
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_UNIV_RADIOBOX_H_
  11. #define _WX_UNIV_RADIOBOX_H_
  12. class WXDLLIMPEXP_FWD_CORE wxRadioButton;
  13. #include "wx/statbox.h"
  14. #include "wx/dynarray.h"
  15. WX_DEFINE_EXPORTED_ARRAY_PTR(wxRadioButton *, wxArrayRadioButtons);
  16. // ----------------------------------------------------------------------------
  17. // wxRadioBox: a box full of radio buttons
  18. // ----------------------------------------------------------------------------
  19. class WXDLLIMPEXP_CORE wxRadioBox : public wxStaticBox,
  20. public wxRadioBoxBase
  21. {
  22. public:
  23. // wxRadioBox construction
  24. wxRadioBox() { Init(); }
  25. wxRadioBox(wxWindow *parent,
  26. wxWindowID id,
  27. const wxString& title,
  28. const wxPoint& pos = wxDefaultPosition,
  29. const wxSize& size = wxDefaultSize,
  30. int n = 0, const wxString *choices = NULL,
  31. int majorDim = 0,
  32. long style = wxRA_SPECIFY_COLS,
  33. const wxValidator& val = wxDefaultValidator,
  34. const wxString& name = wxRadioBoxNameStr)
  35. {
  36. Init();
  37. (void)Create(parent, id, title, pos, size, n, choices,
  38. majorDim, style, val, name);
  39. }
  40. wxRadioBox(wxWindow *parent,
  41. wxWindowID id,
  42. const wxString& title,
  43. const wxPoint& pos,
  44. const wxSize& size,
  45. const wxArrayString& choices,
  46. int majorDim = 0,
  47. long style = wxRA_SPECIFY_COLS,
  48. const wxValidator& val = wxDefaultValidator,
  49. const wxString& name = wxRadioBoxNameStr);
  50. bool Create(wxWindow *parent,
  51. wxWindowID id,
  52. const wxString& title,
  53. const wxPoint& pos = wxDefaultPosition,
  54. const wxSize& size = wxDefaultSize,
  55. int n = 0, const wxString *choices = NULL,
  56. int majorDim = 0,
  57. long style = wxRA_SPECIFY_COLS,
  58. const wxValidator& val = wxDefaultValidator,
  59. const wxString& name = wxRadioBoxNameStr);
  60. bool Create(wxWindow *parent,
  61. wxWindowID id,
  62. const wxString& title,
  63. const wxPoint& pos,
  64. const wxSize& size,
  65. const wxArrayString& choices,
  66. int majorDim = 0,
  67. long style = wxRA_SPECIFY_COLS,
  68. const wxValidator& val = wxDefaultValidator,
  69. const wxString& name = wxRadioBoxNameStr);
  70. virtual ~wxRadioBox();
  71. // implement wxRadioBox interface
  72. virtual void SetSelection(int n);
  73. virtual int GetSelection() const;
  74. virtual unsigned int GetCount() const
  75. { return (unsigned int)m_buttons.GetCount(); }
  76. virtual wxString GetString(unsigned int n) const;
  77. virtual void SetString(unsigned int n, const wxString& label);
  78. virtual bool Enable(unsigned int n, bool enable = true);
  79. virtual bool Show(unsigned int n, bool show = true);
  80. virtual bool IsItemEnabled(unsigned int n) const;
  81. virtual bool IsItemShown(unsigned int n) const;
  82. // we also override the wxControl methods to avoid virtual function hiding
  83. virtual bool Enable(bool enable = true);
  84. virtual bool Show(bool show = true);
  85. virtual wxString GetLabel() const;
  86. virtual void SetLabel(const wxString& label);
  87. // we inherit a version always returning false from wxStaticBox, override
  88. // it to behave normally
  89. virtual bool AcceptsFocus() const { return wxControl::AcceptsFocus(); }
  90. #if wxUSE_TOOLTIPS
  91. virtual void DoSetToolTip( wxToolTip *tip );
  92. #endif // wxUSE_TOOLTIPS
  93. // wxUniversal-only methods
  94. // another Append() version
  95. void Append(int n, const wxString *choices);
  96. // implementation only: called by wxRadioHookHandler
  97. void OnRadioButton(wxEvent& event);
  98. bool OnKeyDown(wxKeyEvent& event);
  99. protected:
  100. virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  101. // override the base class methods dealing with window positioning/sizing
  102. // as we must move/size the buttons as well
  103. virtual void DoMoveWindow(int x, int y, int width, int height);
  104. virtual wxSize DoGetBestClientSize() const;
  105. // generate a radiobutton click event for the current item
  106. void SendRadioEvent();
  107. // common part of all ctors
  108. void Init();
  109. // calculate the max size of all buttons
  110. wxSize GetMaxButtonSize() const;
  111. // the currently selected radio button or -1
  112. int m_selection;
  113. // all radio buttons
  114. wxArrayRadioButtons m_buttons;
  115. // the event handler which is used to translate radiobutton events into
  116. // radiobox one
  117. wxEvtHandler *m_evtRadioHook;
  118. private:
  119. DECLARE_DYNAMIC_CLASS(wxRadioBox)
  120. };
  121. #endif // _WX_UNIV_RADIOBOX_H_