X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8907154c1a8a6882c6797d1f16393ddfb23e7f3a..d10e22fe8ad283f37b1809349028ffc282e393ce:/src/common/radiocmn.cpp?ds=sidebyside diff --git a/src/common/radiocmn.cpp b/src/common/radiocmn.cpp index 9f4572fa6e..d31889c4b3 100644 --- a/src/common/radiocmn.cpp +++ b/src/common/radiocmn.cpp @@ -30,20 +30,36 @@ #include "wx/radiobox.h" #endif //WX_PRECOMP +#if wxUSE_TOOLTIPS + #include "wx/tooltip.h" +#endif // wxUSE_TOOLTIPS + +#if wxUSE_HELP + #include "wx/cshelp.h" +#endif + // ============================================================================ // implementation // ============================================================================ -int wxRadioBoxBase::FindString(const wxString& s) const +void wxRadioBoxBase::SetMajorDim(unsigned int majorDim, long style) { - int count = GetCount(); - for ( int n = 0; n < count; n++ ) + wxCHECK_RET( majorDim != 0, _T("major radiobox dimension can't be 0") ); + + m_majorDim = majorDim; + + int minorDim = (GetCount() + m_majorDim - 1) / m_majorDim; + + if ( style & wxRA_SPECIFY_COLS ) { - if ( GetString(n) == s ) - return n; + m_numCols = majorDim; + m_numRows = minorDim; + } + else // wxRA_SPECIFY_ROWS + { + m_numCols = minorDim; + m_numRows = majorDim; } - - return wxNOT_FOUND; } int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const @@ -142,38 +158,137 @@ int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const return item; } -#if WXWIN_COMPATIBILITY_2_4 +#if wxUSE_TOOLTIPS -// these functions are deprecated and don't do anything -int wxRadioBoxBase::GetNumberOfRowsOrCols() const +void wxRadioBoxBase::SetItemToolTip(unsigned int item, const wxString& text) { - return 1; + wxASSERT_MSG( item < GetCount(), _T("Invalid item index") ); + + // extend the array to have entries for all our items on first use + if ( !m_itemsTooltips ) + { + m_itemsTooltips = new wxToolTipArray; + m_itemsTooltips->resize(GetCount()); + } + + wxToolTip *tooltip = (*m_itemsTooltips)[item]; + + bool changed = true; + if ( text.empty() ) + { + if ( tooltip ) + { + // delete the tooltip + delete tooltip; + tooltip = NULL; + } + else // nothing to do + { + changed = false; + } + } + else // non empty tooltip text + { + if ( tooltip ) + { + // just change the existing tooltip text, don't change the tooltip + tooltip->SetTip(text); + changed = false; + } + else // no tooltip yet + { + // create the new one + tooltip = new wxToolTip(text); + } + } + + if ( changed ) + { + (*m_itemsTooltips)[item] = tooltip; + DoSetItemToolTip(item, tooltip); + } } -void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n)) +void +wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item), + wxToolTip * WXUNUSED(tooltip)) { + // per-item tooltips not implemented by default } -#endif // WXWIN_COMPATIBILITY_2_4 +#endif // wxUSE_TOOLTIPS -#if WXWIN_COMPATIBILITY_2_2 +wxRadioBoxBase::~wxRadioBoxBase() +{ +#if wxUSE_TOOLTIPS + if ( m_itemsTooltips ) + { + const size_t n = m_itemsTooltips->size(); + for ( size_t i = 0; i < n; i++ ) + delete (*m_itemsTooltips)[i]; -int wxRadioBoxBase::Number() const + delete m_itemsTooltips; + } +#endif // wxUSE_TOOLTIPS +} + +#if wxUSE_HELP + +// set helptext for a particular item +void wxRadioBoxBase::SetItemHelpText(unsigned int n, const wxString& helpText) { - return GetCount(); + wxCHECK_RET( n < GetCount(), _T("Invalid item index") ); + + if ( m_itemsHelpTexts.empty() ) + { + // once-only initialization of the array: reserve space for all items + m_itemsHelpTexts.Add(wxEmptyString, GetCount()); + } + + m_itemsHelpTexts[n] = helpText; } -wxString wxRadioBoxBase::GetLabel(int n) const +// retrieve helptext for a particular item +wxString wxRadioBoxBase::GetItemHelpText( unsigned int n ) const { - return GetString(n); + wxCHECK_MSG( n < GetCount(), wxEmptyString, _T("Invalid item index") ); + + return m_itemsHelpTexts.empty() ? wxString() : m_itemsHelpTexts[n]; } -void wxRadioBoxBase::SetLabel(int n, const wxString& label) +// return help text for the item for which wxEVT_HELP was generated. +wxString wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow *derived, + const wxPoint& pt, + wxHelpEvent::Origin origin) const { - SetString(n, label); + const int item = origin == wxHelpEvent::Origin_HelpButton + ? GetItemFromPoint(pt) + : GetSelection(); + + if ( item != wxNOT_FOUND ) + { + wxString text = GetItemHelpText(wx_static_cast(unsigned int, item)); + if( !text.empty() ) + return text; + } + + return derived->wxWindowBase::GetHelpTextAtPoint(pt, origin); } -#endif // WXWIN_COMPATIBILITY_2_2 +#endif // wxUSE_HELP -#endif // wxUSE_RADIOBOX +#if WXWIN_COMPATIBILITY_2_4 + +// these functions are deprecated and don't do anything +int wxRadioBoxBase::GetNumberOfRowsOrCols() const +{ + return 1; +} +void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n)) +{ +} + +#endif // WXWIN_COMPATIBILITY_2_4 + +#endif // wxUSE_RADIOBOX