radiobox.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/radiobox.h
  3. // Purpose: wxRadioBox class
  4. // Author: Julian Smart
  5. // Modified by:
  6. // Created: 01/02/97
  7. // Copyright: (c) Julian Smart
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RADIOBOX_H_
  11. #define _WX_RADIOBOX_H_
  12. #include "wx/statbox.h"
  13. class WXDLLIMPEXP_FWD_CORE wxSubwindows;
  14. // ----------------------------------------------------------------------------
  15. // wxRadioBox
  16. // ----------------------------------------------------------------------------
  17. class WXDLLIMPEXP_CORE wxRadioBox : public wxStaticBox, public wxRadioBoxBase
  18. {
  19. public:
  20. wxRadioBox() { Init(); }
  21. wxRadioBox(wxWindow *parent,
  22. wxWindowID id,
  23. const wxString& title,
  24. const wxPoint& pos = wxDefaultPosition,
  25. const wxSize& size = wxDefaultSize,
  26. int n = 0, const wxString choices[] = NULL,
  27. int majorDim = 0,
  28. long style = wxRA_SPECIFY_COLS,
  29. const wxValidator& val = wxDefaultValidator,
  30. const wxString& name = wxRadioBoxNameStr)
  31. {
  32. Init();
  33. (void)Create(parent, id, title, pos, size, n, choices, majorDim,
  34. style, val, name);
  35. }
  36. wxRadioBox(wxWindow *parent,
  37. wxWindowID id,
  38. const wxString& title,
  39. const wxPoint& pos,
  40. const wxSize& size,
  41. const wxArrayString& choices,
  42. int majorDim = 0,
  43. long style = wxRA_SPECIFY_COLS,
  44. const wxValidator& val = wxDefaultValidator,
  45. const wxString& name = wxRadioBoxNameStr)
  46. {
  47. Init();
  48. (void)Create(parent, id, title, pos, size, choices, majorDim,
  49. style, val, name);
  50. }
  51. virtual ~wxRadioBox();
  52. bool Create(wxWindow *parent,
  53. wxWindowID id,
  54. const wxString& title,
  55. const wxPoint& pos = wxDefaultPosition,
  56. const wxSize& size = wxDefaultSize,
  57. int n = 0, const wxString choices[] = NULL,
  58. int majorDim = 0,
  59. long style = wxRA_SPECIFY_COLS,
  60. const wxValidator& val = wxDefaultValidator,
  61. const wxString& name = wxRadioBoxNameStr);
  62. bool Create(wxWindow *parent,
  63. wxWindowID id,
  64. const wxString& title,
  65. const wxPoint& pos,
  66. const wxSize& size,
  67. const wxArrayString& choices,
  68. int majorDim = 0,
  69. long style = wxRA_SPECIFY_COLS,
  70. const wxValidator& val = wxDefaultValidator,
  71. const wxString& name = wxRadioBoxNameStr);
  72. // implement the radiobox interface
  73. virtual void SetSelection(int n);
  74. virtual int GetSelection() const { return m_selectedButton; }
  75. virtual unsigned int GetCount() const;
  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. virtual int GetItemFromPoint(const wxPoint& pt) const;
  83. // override some base class methods
  84. virtual bool Show(bool show = true);
  85. virtual bool Enable(bool enable = true);
  86. virtual bool CanBeFocused() const;
  87. virtual void SetFocus();
  88. virtual bool SetFont(const wxFont& font);
  89. virtual bool ContainsHWND(WXHWND hWnd) const;
  90. #if wxUSE_TOOLTIPS
  91. virtual bool HasToolTips() const;
  92. #endif // wxUSE_TOOLTIPS
  93. #if wxUSE_HELP
  94. // override virtual function with a platform-independent implementation
  95. virtual wxString GetHelpTextAtPoint(const wxPoint & pt, wxHelpEvent::Origin origin) const
  96. {
  97. return wxRadioBoxBase::DoGetHelpTextAtPoint( this, pt, origin );
  98. }
  99. #endif // wxUSE_HELP
  100. virtual bool Reparent(wxWindowBase *newParent);
  101. // returns true if the platform should explicitly apply a theme border
  102. virtual bool CanApplyThemeBorder() const { return false; }
  103. void SetLabelFont(const wxFont& WXUNUSED(font)) {}
  104. void SetButtonFont(const wxFont& font) { SetFont(font); }
  105. // implementation only from now on
  106. // -------------------------------
  107. // This function can be used to check if the given radio button HWND
  108. // belongs to one of our radio boxes. If it doesn't, NULL is returned.
  109. static wxRadioBox *GetFromRadioButtonHWND(WXHWND hwnd);
  110. virtual bool MSWCommand(WXUINT param, WXWORD id);
  111. void Command(wxCommandEvent& event);
  112. void SendNotificationEvent();
  113. protected:
  114. // common part of all ctors
  115. void Init();
  116. // subclass one radio button
  117. void SubclassRadioButton(WXHWND hWndBtn);
  118. // get the max size of radio buttons
  119. wxSize GetMaxButtonSize() const;
  120. // get the total size occupied by the radio box buttons
  121. wxSize GetTotalButtonSize(const wxSize& sizeBtn) const;
  122. // Adjust all the buttons to the new window size.
  123. void PositionAllButtons(int x, int y, int width, int height);
  124. virtual void DoSetSize(int x, int y,
  125. int width, int height,
  126. int sizeFlags = wxSIZE_AUTO);
  127. virtual void DoMoveWindow(int x, int y, int width, int height);
  128. virtual wxSize DoGetBestSize() const;
  129. #if wxUSE_TOOLTIPS
  130. virtual void DoSetItemToolTip(unsigned int n, wxToolTip * tooltip);
  131. #endif
  132. #ifndef __WXWINCE__
  133. virtual WXHRGN MSWGetRegionWithoutChildren();
  134. #endif // __WXWINCE__
  135. // resolve ambiguity in base classes
  136. virtual wxBorder GetDefaultBorder() const { return wxRadioBoxBase::GetDefaultBorder(); }
  137. // the buttons we contain
  138. wxSubwindows *m_radioButtons;
  139. // and the special dummy button used only as a tab group boundary
  140. WXHWND m_dummyHwnd;
  141. wxWindowIDRef m_dummyId;
  142. // array of widths and heights of the buttons, may be wxDefaultCoord if the
  143. // corresponding quantity should be computed
  144. int *m_radioWidth;
  145. int *m_radioHeight;
  146. // currently selected button or wxNOT_FOUND if none
  147. int m_selectedButton;
  148. private:
  149. DECLARE_DYNAMIC_CLASS(wxRadioBox)
  150. wxDECLARE_NO_COPY_CLASS(wxRadioBox);
  151. };
  152. #endif
  153. // _WX_RADIOBOX_H_