X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/371a5b4e62eb415107e045588f614fa49e866e78..aac7dbf3aa68d419365cfeb1dcbacc467271e67c:/include/wx/radiobox.h diff --git a/include/wx/radiobox.h b/include/wx/radiobox.h index 6c850b5dfd..153927aec8 100644 --- a/include/wx/radiobox.h +++ b/include/wx/radiobox.h @@ -5,93 +5,148 @@ // Modified by: // Created: 10.09.00 // RCS-ID: $Id$ -// Copyright: (c) wxWindows team +// Copyright: (c) Vadim Zeitlin // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// #ifndef _WX_RADIOBOX_H_BASE_ #define _WX_RADIOBOX_H_BASE_ -#if defined(__GNUG__) && !defined(__APPLE__) - #pragma interface "radioboxbase.h" -#endif - #if wxUSE_RADIOBOX -#include "wx/control.h" +#include "wx/ctrlsub.h" + +#if wxUSE_TOOLTIPS + +#include "wx/dynarray.h" + +class WXDLLIMPEXP_FWD_CORE wxToolTip; + +WX_DEFINE_EXPORTED_ARRAY_PTR(wxToolTip *, wxToolTipArray); -WXDLLEXPORT_DATA(extern const wxChar*) wxRadioBoxNameStr; +#endif // wxUSE_TOOLTIPS + +extern WXDLLIMPEXP_DATA_CORE(const char) wxRadioBoxNameStr[]; // ---------------------------------------------------------------------------- // wxRadioBoxBase is not a normal base class, but rather a mix-in because the // real wxRadioBox derives from different classes on different platforms: for -// example, it is a wxStaticBox in wxUniv but not in wxMSW +// example, it is a wxStaticBox in wxUniv and wxMSW but not in other ports // ---------------------------------------------------------------------------- -class WXDLLEXPORT wxRadioBoxBase +class WXDLLIMPEXP_CORE wxRadioBoxBase : public wxItemContainerImmutable { public: - // selection - virtual void SetSelection(int n) = 0; - virtual int GetSelection() const = 0; - - virtual wxString GetStringSelection() const - { - wxString s; - int sel = GetSelection(); - if ( sel != wxNOT_FOUND ) - s = GetString(sel); + virtual ~wxRadioBoxBase(); - return s; - } + // change/query the individual radio button state + virtual bool Enable(unsigned int n, bool enable = true) = 0; + virtual bool Show(unsigned int n, bool show = true) = 0; + virtual bool IsItemEnabled(unsigned int n) const = 0; + virtual bool IsItemShown(unsigned int n) const = 0; - virtual bool SetStringSelection(const wxString& s) - { - int sel = FindString(s); - if ( sel != wxNOT_FOUND ) - { - SetSelection(sel); + // return number of columns/rows in this radiobox + unsigned int GetColumnCount() const { return m_numCols; } + unsigned int GetRowCount() const { return m_numRows; } - return TRUE; - } + // return the item above/below/to the left/right of the given one + int GetNextItem(int item, wxDirection dir, long style) const; - return FALSE; +#if wxUSE_TOOLTIPS + // set the tooltip text for a radio item, empty string unsets any tooltip + void SetItemToolTip(unsigned int item, const wxString& text); + + // get the individual items tooltip; returns NULL if none + wxToolTip *GetItemToolTip(unsigned int item) const + { return m_itemsTooltips ? (*m_itemsTooltips)[item] : NULL; } +#endif // wxUSE_TOOLTIPS + +#if wxUSE_HELP + // set helptext for a particular item, pass an empty string to erase it + void SetItemHelpText(unsigned int n, const wxString& helpText); + + // retrieve helptext for a particular item, empty string means no help text + wxString GetItemHelpText(unsigned int n) const; +#else // wxUSE_HELP + // just silently ignore the help text, it's better than requiring using + // conditional compilation in all code using this function + void SetItemHelpText(unsigned int WXUNUSED(n), + const wxString& WXUNUSED(helpText)) + { } +#endif // wxUSE_HELP - // string access - virtual int GetCount() const = 0; - virtual int FindString(const wxString& s) const + // returns the radio item at the given position or wxNOT_FOUND if none + // (currently implemented only under MSW and GTK) + virtual int GetItemFromPoint(const wxPoint& WXUNUSED(pt)) const { - int count = GetCount(); - for ( int n = 0; n < count; n++ ) - { - if ( GetString(n) == s ) - return n; - } - return wxNOT_FOUND; } - virtual wxString GetString(int n) const = 0; - virtual void SetString(int n, const wxString& label) = 0; - // change the individual radio button state - virtual void Enable(int n, bool enable = TRUE) = 0; - virtual void Show(int n, bool show = TRUE) = 0; +protected: + wxRadioBoxBase() + { + m_numCols = + m_numRows = + m_majorDim = 0; - // layout parameters - virtual int GetColumnCount() const = 0; - virtual int GetRowCount() const = 0; +#if wxUSE_TOOLTIPS + m_itemsTooltips = NULL; +#endif // wxUSE_TOOLTIPS + } - // return the item above/below/to the left/right of the given one - int GetNextItem(int item, wxDirection dir, long style) const; + virtual wxBorder GetDefaultBorder() const { return wxBORDER_NONE; } + + // return the number of items in major direction (which depends on whether + // we have wxRA_SPECIFY_COLS or wxRA_SPECIFY_ROWS style) + unsigned int GetMajorDim() const { return m_majorDim; } + + // sets m_majorDim and also updates m_numCols/Rows + // + // the style parameter should be the style of the radiobox itself + void SetMajorDim(unsigned int majorDim, long style); + +#if wxUSE_TOOLTIPS + // called from SetItemToolTip() to really set the tooltip for the specified + // item in the box (or, if tooltip is NULL, to remove any existing one). + // + // NB: this function should really be pure virtual but to avoid breaking + // the build of the ports for which it's not implemented yet we provide + // an empty stub in the base class for now + virtual void DoSetItemToolTip(unsigned int item, wxToolTip *tooltip); + + // returns true if we have any item tooltips + bool HasItemToolTips() const { return m_itemsTooltips != NULL; } +#endif // wxUSE_TOOLTIPS + +#if wxUSE_HELP + // Retrieve help text for an item: this is a helper for the implementation + // of wxWindow::GetHelpTextAtPoint() in the real radiobox class + wxString DoGetHelpTextAtPoint(const wxWindow *derived, + const wxPoint& pt, + wxHelpEvent::Origin origin) const; +#endif // wxUSE_HELP + +private: + // the number of elements in major dimension (i.e. number of columns if + // wxRA_SPECIFY_COLS or the number of rows if wxRA_SPECIFY_ROWS) and also + // the number of rows/columns calculated from it + unsigned int m_majorDim, + m_numCols, + m_numRows; + +#if wxUSE_TOOLTIPS + // array of tooltips for the individual items + // + // this array is initially NULL and initialized on first use + wxToolTipArray *m_itemsTooltips; +#endif - // for compatibility only, don't use these methods in new code! -#if WXWIN_COMPATIBILITY_2_2 - int Number() const { return GetCount(); } - wxString GetLabel(int n) const { return GetString(n); } - void SetLabel(int n, const wxString& label) { SetString(n, label); } -#endif // WXWIN_COMPATIBILITY_2_2 +#if wxUSE_HELP + // help text associated with a particular item or empty string if none + wxArrayString m_itemsHelpTexts; +#endif // wxUSE_HELP }; #if defined(__WXUNIVERSAL__) @@ -100,15 +155,20 @@ public: #include "wx/msw/radiobox.h" #elif defined(__WXMOTIF__) #include "wx/motif/radiobox.h" -#elif defined(__WXGTK__) +#elif defined(__WXGTK20__) #include "wx/gtk/radiobox.h" +#elif defined(__WXGTK__) + #include "wx/gtk1/radiobox.h" #elif defined(__WXMAC__) #include "wx/mac/radiobox.h" +#elif defined(__WXCOCOA__) + #include "wx/cocoa/radiobox.h" #elif defined(__WXPM__) #include "wx/os2/radiobox.h" +#elif defined(__WXPALMOS__) + #include "wx/palmos/radiobox.h" #endif #endif // wxUSE_RADIOBOX -#endif - // _WX_RADIOBOX_H_BASE_ +#endif // _WX_RADIOBOX_H_BASE_