radiobox.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/radiobox.h
  3. // Purpose: wxRadioBox declaration
  4. // Author: Vadim Zeitlin
  5. // Modified by:
  6. // Created: 10.09.00
  7. // Copyright: (c) Vadim Zeitlin
  8. // Licence: wxWindows licence
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_RADIOBOX_H_BASE_
  11. #define _WX_RADIOBOX_H_BASE_
  12. #include "wx/defs.h"
  13. #if wxUSE_RADIOBOX
  14. #include "wx/ctrlsub.h"
  15. #if wxUSE_TOOLTIPS
  16. #include "wx/dynarray.h"
  17. class WXDLLIMPEXP_FWD_CORE wxToolTip;
  18. WX_DEFINE_EXPORTED_ARRAY_PTR(wxToolTip *, wxToolTipArray);
  19. #endif // wxUSE_TOOLTIPS
  20. extern WXDLLIMPEXP_DATA_CORE(const char) wxRadioBoxNameStr[];
  21. // ----------------------------------------------------------------------------
  22. // wxRadioBoxBase is not a normal base class, but rather a mix-in because the
  23. // real wxRadioBox derives from different classes on different platforms: for
  24. // example, it is a wxStaticBox in wxUniv and wxMSW but not in other ports
  25. // ----------------------------------------------------------------------------
  26. class WXDLLIMPEXP_CORE wxRadioBoxBase : public wxItemContainerImmutable
  27. {
  28. public:
  29. virtual ~wxRadioBoxBase();
  30. // change/query the individual radio button state
  31. virtual bool Enable(unsigned int n, bool enable = true) = 0;
  32. virtual bool Show(unsigned int n, bool show = true) = 0;
  33. virtual bool IsItemEnabled(unsigned int n) const = 0;
  34. virtual bool IsItemShown(unsigned int n) const = 0;
  35. // return number of columns/rows in this radiobox
  36. unsigned int GetColumnCount() const { return m_numCols; }
  37. unsigned int GetRowCount() const { return m_numRows; }
  38. // return the next active (i.e. shown and not disabled) item above/below/to
  39. // the left/right of the given one
  40. int GetNextItem(int item, wxDirection dir, long style) const;
  41. #if wxUSE_TOOLTIPS
  42. // set the tooltip text for a radio item, empty string unsets any tooltip
  43. void SetItemToolTip(unsigned int item, const wxString& text);
  44. // get the individual items tooltip; returns NULL if none
  45. wxToolTip *GetItemToolTip(unsigned int item) const
  46. { return m_itemsTooltips ? (*m_itemsTooltips)[item] : NULL; }
  47. #endif // wxUSE_TOOLTIPS
  48. #if wxUSE_HELP
  49. // set helptext for a particular item, pass an empty string to erase it
  50. void SetItemHelpText(unsigned int n, const wxString& helpText);
  51. // retrieve helptext for a particular item, empty string means no help text
  52. wxString GetItemHelpText(unsigned int n) const;
  53. #else // wxUSE_HELP
  54. // just silently ignore the help text, it's better than requiring using
  55. // conditional compilation in all code using this function
  56. void SetItemHelpText(unsigned int WXUNUSED(n),
  57. const wxString& WXUNUSED(helpText))
  58. {
  59. }
  60. #endif // wxUSE_HELP
  61. // returns the radio item at the given position or wxNOT_FOUND if none
  62. // (currently implemented only under MSW and GTK)
  63. virtual int GetItemFromPoint(const wxPoint& WXUNUSED(pt)) const
  64. {
  65. return wxNOT_FOUND;
  66. }
  67. protected:
  68. wxRadioBoxBase()
  69. {
  70. m_numCols =
  71. m_numRows =
  72. m_majorDim = 0;
  73. #if wxUSE_TOOLTIPS
  74. m_itemsTooltips = NULL;
  75. #endif // wxUSE_TOOLTIPS
  76. }
  77. virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; }
  78. // return the number of items in major direction (which depends on whether
  79. // we have wxRA_SPECIFY_COLS or wxRA_SPECIFY_ROWS style)
  80. unsigned int GetMajorDim() const { return m_majorDim; }
  81. // sets m_majorDim and also updates m_numCols/Rows
  82. //
  83. // the style parameter should be the style of the radiobox itself
  84. void SetMajorDim(unsigned int majorDim, long style);
  85. #if wxUSE_TOOLTIPS
  86. // called from SetItemToolTip() to really set the tooltip for the specified
  87. // item in the box (or, if tooltip is NULL, to remove any existing one).
  88. //
  89. // NB: this function should really be pure virtual but to avoid breaking
  90. // the build of the ports for which it's not implemented yet we provide
  91. // an empty stub in the base class for now
  92. virtual void DoSetItemToolTip(unsigned int item, wxToolTip *tooltip);
  93. // returns true if we have any item tooltips
  94. bool HasItemToolTips() const { return m_itemsTooltips != NULL; }
  95. #endif // wxUSE_TOOLTIPS
  96. #if wxUSE_HELP
  97. // Retrieve help text for an item: this is a helper for the implementation
  98. // of wxWindow::GetHelpTextAtPoint() in the real radiobox class
  99. wxString DoGetHelpTextAtPoint(const wxWindow *derived,
  100. const wxPoint& pt,
  101. wxHelpEvent::Origin origin) const;
  102. #endif // wxUSE_HELP
  103. private:
  104. // the number of elements in major dimension (i.e. number of columns if
  105. // wxRA_SPECIFY_COLS or the number of rows if wxRA_SPECIFY_ROWS) and also
  106. // the number of rows/columns calculated from it
  107. unsigned int m_majorDim,
  108. m_numCols,
  109. m_numRows;
  110. #if wxUSE_TOOLTIPS
  111. // array of tooltips for the individual items
  112. //
  113. // this array is initially NULL and initialized on first use
  114. wxToolTipArray *m_itemsTooltips;
  115. #endif
  116. #if wxUSE_HELP
  117. // help text associated with a particular item or empty string if none
  118. wxArrayString m_itemsHelpTexts;
  119. #endif // wxUSE_HELP
  120. };
  121. #if defined(__WXUNIVERSAL__)
  122. #include "wx/univ/radiobox.h"
  123. #elif defined(__WXMSW__)
  124. #include "wx/msw/radiobox.h"
  125. #elif defined(__WXMOTIF__)
  126. #include "wx/motif/radiobox.h"
  127. #elif defined(__WXGTK20__)
  128. #include "wx/gtk/radiobox.h"
  129. #elif defined(__WXGTK__)
  130. #include "wx/gtk1/radiobox.h"
  131. #elif defined(__WXMAC__)
  132. #include "wx/osx/radiobox.h"
  133. #elif defined(__WXCOCOA__)
  134. #include "wx/cocoa/radiobox.h"
  135. #elif defined(__WXPM__)
  136. #include "wx/os2/radiobox.h"
  137. #endif
  138. #endif // wxUSE_RADIOBOX
  139. #endif // _WX_RADIOBOX_H_BASE_