#include "wx/tooltip.h"
#endif // wxUSE_TOOLTIPS
+#if wxUSE_HELP
+ #include "wx/cshelp.h"
+#endif
+
// ============================================================================
// implementation
// ============================================================================
int wxRadioBoxBase::GetNextItem(int item, wxDirection dir, long style) const
{
+ const int itemStart = item;
+
int count = GetCount(),
numCols = GetColumnCount(),
numRows = GetRowCount();
bool horz = (style & wxRA_SPECIFY_COLS) != 0;
- switch ( dir )
+ do
{
- case wxUP:
- if ( horz )
- {
- item -= numCols;
- }
- else // vertical layout
- {
- if ( !item-- )
- item = count - 1;
- }
- break;
-
- case wxLEFT:
- if ( horz )
- {
- if ( !item-- )
- item = count - 1;
- }
- else // vertical layout
- {
- item -= numRows;
- }
- break;
-
- case wxDOWN:
- if ( horz )
- {
- item += numCols;
- }
- else // vertical layout
- {
- if ( ++item == count )
- item = 0;
- }
- break;
-
- case wxRIGHT:
- if ( horz )
- {
- if ( ++item == count )
- item = 0;
- }
- else // vertical layout
- {
- item += numRows;
- }
- break;
-
- default:
- wxFAIL_MSG( _T("unexpected wxDirection value") );
- return wxNOT_FOUND;
- }
+ switch ( dir )
+ {
+ case wxUP:
+ if ( horz )
+ {
+ item -= numCols;
+ }
+ else // vertical layout
+ {
+ if ( !item-- )
+ item = count - 1;
+ }
+ break;
+
+ case wxLEFT:
+ if ( horz )
+ {
+ if ( !item-- )
+ item = count - 1;
+ }
+ else // vertical layout
+ {
+ item -= numRows;
+ }
+ break;
+
+ case wxDOWN:
+ if ( horz )
+ {
+ item += numCols;
+ }
+ else // vertical layout
+ {
+ if ( ++item == count )
+ item = 0;
+ }
+ break;
+
+ case wxRIGHT:
+ if ( horz )
+ {
+ if ( ++item == count )
+ item = 0;
+ }
+ else // vertical layout
+ {
+ item += numRows;
+ }
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unexpected wxDirection value") );
+ return wxNOT_FOUND;
+ }
- // ensure that the item is in range [0..count)
- if ( item < 0 )
- {
- // first map the item to the one in the same column but in the last row
- item += count;
-
- // now there are 2 cases: either it is the first item of the last row
- // in which case we need to wrap again and get to the last item or we
- // can just go to the previous item
- if ( item % (horz ? numCols : numRows) )
- item--;
- else
- item = count - 1;
- }
- else if ( item >= count )
- {
- // same logic as above
- item -= count;
-
- // ... except that we need to check if this is not the last item, not
- // the first one
- if ( (item + 1) % (horz ? numCols : numRows) )
- item++;
- else
- item = 0;
- }
+ // ensure that the item is in range [0..count)
+ if ( item < 0 )
+ {
+ // first map the item to the one in the same column but in the last
+ // row
+ item += count;
+
+ // now there are 2 cases: either it is the first item of the last
+ // row in which case we need to wrap again and get to the last item
+ // or we can just go to the previous item
+ if ( item % (horz ? numCols : numRows) )
+ item--;
+ else
+ item = count - 1;
+ }
+ else if ( item >= count )
+ {
+ // same logic as above
+ item -= count;
+
+ // ... except that we need to check if this is not the last item,
+ // not the first one
+ if ( (item + 1) % (horz ? numCols : numRows) )
+ item++;
+ else
+ item = 0;
+ }
- wxASSERT_MSG( item < count && item >= 0,
- _T("logic error in wxRadioBox::GetNextItem()") );
+ wxASSERT_MSG( item < count && item >= 0,
+ _T("logic error in wxRadioBox::GetNextItem()") );
+ }
+ // we shouldn't select the non-active items, continue looking for a
+ // visible and shown one unless we came back to the item we started from in
+ // which case bail out to avoid infinite loop
+ while ( !(IsItemShown(item) && IsItemEnabled(item)) && item != itemStart );
return item;
}
#endif // wxUSE_TOOLTIPS
}
-#if WXWIN_COMPATIBILITY_2_4
+#if wxUSE_HELP
-// these functions are deprecated and don't do anything
-int wxRadioBoxBase::GetNumberOfRowsOrCols() const
+// set helptext for a particular item
+void wxRadioBoxBase::SetItemHelpText(unsigned int n, const wxString& helpText)
{
- return 1;
+ 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;
}
-void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n))
+// retrieve helptext for a particular item
+wxString wxRadioBoxBase::GetItemHelpText( unsigned int n ) const
{
+ wxCHECK_MSG( n < GetCount(), wxEmptyString, _T("Invalid item index") );
+
+ return m_itemsHelpTexts.empty() ? wxString() : m_itemsHelpTexts[n];
+}
+
+// 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
+{
+ 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_4
+#endif // wxUSE_HELP
#endif // wxUSE_RADIOBOX