radiobox.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/cocoa/radiobox.h
  3. // Purpose: wxRadioBox class
  4. // Author: David Elliott
  5. // Modified by:
  6. // Created: 2003/03/18
  7. // Copyright: (c) 2003 David Elliott
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef __WX_COCOA_RADIOBOX_H__
  11. #define __WX_COCOA_RADIOBOX_H__
  12. // #include "wx/cocoa/NSButton.h"
  13. DECLARE_WXCOCOA_OBJC_CLASS(NSMatrix);
  14. // ========================================================================
  15. // wxRadioBox
  16. // ========================================================================
  17. class WXDLLIMPEXP_CORE wxRadioBox: public wxControl, public wxRadioBoxBase// , protected wxCocoaNSButton
  18. {
  19. DECLARE_DYNAMIC_CLASS(wxRadioBox)
  20. DECLARE_EVENT_TABLE()
  21. // NOTE: We explicitly skip NSControl because our primary cocoa view is
  22. // the NSBox but we want to receive action messages from the NSMatrix.
  23. WX_DECLARE_COCOA_OWNER(NSBox,NSView,NSView)
  24. // ------------------------------------------------------------------------
  25. // initialization
  26. // ------------------------------------------------------------------------
  27. public:
  28. wxRadioBox() { }
  29. wxRadioBox(wxWindow *parent, wxWindowID winid,
  30. const wxString& title,
  31. const wxPoint& pos = wxDefaultPosition,
  32. const wxSize& size = wxDefaultSize,
  33. int n = 0, const wxString choices[] = NULL,
  34. int majorDim = 0,
  35. long style = 0, const wxValidator& validator = wxDefaultValidator,
  36. const wxString& name = wxRadioBoxNameStr)
  37. {
  38. Create(parent, winid, title, pos, size, n, choices, majorDim, style, validator, name);
  39. }
  40. wxRadioBox(wxWindow *parent, wxWindowID winid,
  41. const wxString& title,
  42. const wxPoint& pos,
  43. const wxSize& size,
  44. const wxArrayString& choices,
  45. int majorDim = 0,
  46. long style = 0, const wxValidator& validator = wxDefaultValidator,
  47. const wxString& name = wxRadioBoxNameStr)
  48. {
  49. Create(parent, winid, title, pos, size, choices, majorDim, style, validator, name);
  50. }
  51. bool Create(wxWindow *parent, wxWindowID winid,
  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 = 0,
  58. const wxValidator& validator = wxDefaultValidator,
  59. const wxString& name = wxRadioBoxNameStr);
  60. bool Create(wxWindow *parent, wxWindowID winid,
  61. const wxString& title,
  62. const wxPoint& pos,
  63. const wxSize& size,
  64. const wxArrayString& choices,
  65. int majorDim = 0,
  66. long style = 0,
  67. const wxValidator& validator = wxDefaultValidator,
  68. const wxString& name = wxRadioBoxNameStr);
  69. virtual ~wxRadioBox();
  70. // Enabling
  71. virtual bool Enable(unsigned int n, bool enable = true);
  72. virtual bool IsItemEnabled(unsigned int WXUNUSED(n)) const
  73. {
  74. /* TODO */
  75. return true;
  76. }
  77. // Showing
  78. virtual bool Show(unsigned int n, bool show = true);
  79. virtual bool IsItemShown(unsigned int WXUNUSED(n)) const
  80. {
  81. /* TODO */
  82. return true;
  83. }
  84. // ------------------------------------------------------------------------
  85. // Cocoa callbacks
  86. // ------------------------------------------------------------------------
  87. protected:
  88. // Radio boxes cannot be enabled/disabled
  89. virtual void CocoaSetEnabled(bool WXUNUSED(enable)) { }
  90. virtual void CocoaTarget_action(void);
  91. // ------------------------------------------------------------------------
  92. // Implementation
  93. // ------------------------------------------------------------------------
  94. public:
  95. // Pure virtuals
  96. // selection
  97. virtual void SetSelection(int n);
  98. virtual int GetSelection() const;
  99. // string access
  100. virtual unsigned int GetCount() const;
  101. virtual wxString GetString(unsigned int n) const;
  102. virtual void SetString(unsigned int n, const wxString& label);
  103. // change the individual radio button state
  104. protected:
  105. // We don't want the typical wxCocoaNSBox behaviour because our real
  106. // implementation is by using an NSMatrix as the NSBox's contentView.
  107. WX_NSMatrix GetNSMatrix() const;
  108. void AssociateNSBox(WX_NSBox theBox);
  109. void DisassociateNSBox(WX_NSBox theBox);
  110. virtual wxSize DoGetBestSize() const;
  111. int GetRowForIndex(int n) const
  112. {
  113. if(m_windowStyle & wxRA_SPECIFY_COLS)
  114. return n / GetMajorDim();
  115. else
  116. return n % GetMajorDim();
  117. }
  118. int GetColumnForIndex(int n) const
  119. {
  120. if(m_windowStyle & wxRA_SPECIFY_COLS)
  121. return n % GetMajorDim();
  122. else
  123. return n / GetMajorDim();
  124. }
  125. };
  126. #endif // __WX_COCOA_RADIOBOX_H__