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