]>
git.saurik.com Git - wxWidgets.git/blob - src/common/radiocmn.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/radiocmn.cpp
3 // Purpose: wxRadioBox methods common to all ports
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/radiobox.h"
34 #include "wx/tooltip.h"
35 #endif // wxUSE_TOOLTIPS
38 #include "wx/cshelp.h"
41 // ============================================================================
43 // ============================================================================
45 void wxRadioBoxBase::SetMajorDim(unsigned int majorDim
, long style
)
47 wxCHECK_RET( majorDim
!= 0, _T("major radiobox dimension can't be 0") );
49 m_majorDim
= majorDim
;
51 int minorDim
= (GetCount() + m_majorDim
- 1) / m_majorDim
;
53 if ( style
& wxRA_SPECIFY_COLS
)
58 else // wxRA_SPECIFY_ROWS
65 int wxRadioBoxBase::GetNextItem(int item
, wxDirection dir
, long style
) const
67 const int itemStart
= item
;
69 int count
= GetCount(),
70 numCols
= GetColumnCount(),
71 numRows
= GetRowCount();
73 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
84 else // vertical layout
97 else // vertical layout
108 else // vertical layout
110 if ( ++item
== count
)
118 if ( ++item
== count
)
121 else // vertical layout
128 wxFAIL_MSG( _T("unexpected wxDirection value") );
132 // ensure that the item is in range [0..count)
135 // first map the item to the one in the same column but in the last
139 // now there are 2 cases: either it is the first item of the last
140 // row in which case we need to wrap again and get to the last item
141 // or we can just go to the previous item
142 if ( item
% (horz
? numCols
: numRows
) )
147 else if ( item
>= count
)
149 // same logic as above
152 // ... except that we need to check if this is not the last item,
154 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
160 wxASSERT_MSG( item
< count
&& item
>= 0,
161 _T("logic error in wxRadioBox::GetNextItem()") );
163 // we shouldn't select the non-active items, continue looking for a
164 // visible and shown one unless we came back to the item we started from in
165 // which case bail out to avoid infinite loop
166 while ( !(IsItemShown(item
) && IsItemEnabled(item
)) && item
!= itemStart
);
173 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
175 wxASSERT_MSG( item
< GetCount(), _T("Invalid item index") );
177 // extend the array to have entries for all our items on first use
178 if ( !m_itemsTooltips
)
180 m_itemsTooltips
= new wxToolTipArray
;
181 m_itemsTooltips
->resize(GetCount());
184 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
191 // delete the tooltip
195 else // nothing to do
200 else // non empty tooltip text
204 // just change the existing tooltip text, don't change the tooltip
205 tooltip
->SetTip(text
);
208 else // no tooltip yet
210 // create the new one
211 tooltip
= new wxToolTip(text
);
217 (*m_itemsTooltips
)[item
] = tooltip
;
218 DoSetItemToolTip(item
, tooltip
);
223 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
224 wxToolTip
* WXUNUSED(tooltip
))
226 // per-item tooltips not implemented by default
229 #endif // wxUSE_TOOLTIPS
231 wxRadioBoxBase::~wxRadioBoxBase()
234 if ( m_itemsTooltips
)
236 const size_t n
= m_itemsTooltips
->size();
237 for ( size_t i
= 0; i
< n
; i
++ )
238 delete (*m_itemsTooltips
)[i
];
240 delete m_itemsTooltips
;
242 #endif // wxUSE_TOOLTIPS
247 // set helptext for a particular item
248 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
250 wxCHECK_RET( n
< GetCount(), _T("Invalid item index") );
252 if ( m_itemsHelpTexts
.empty() )
254 // once-only initialization of the array: reserve space for all items
255 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
258 m_itemsHelpTexts
[n
] = helpText
;
261 // retrieve helptext for a particular item
262 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
264 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, _T("Invalid item index") );
266 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
269 // return help text for the item for which wxEVT_HELP was generated.
270 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
272 wxHelpEvent::Origin origin
) const
277 case wxHelpEvent::Origin_HelpButton
:
278 item
= GetItemFromPoint(pt
);
281 case wxHelpEvent::Origin_Keyboard
:
282 item
= GetSelection();
286 wxFAIL_MSG( "unknown help even origin" );
289 case wxHelpEvent::Origin_Unknown
:
290 // this value is used when we're called from GetHelpText() for the
291 // radio box itself, so don't return item-specific text in this case
295 if ( item
!= wxNOT_FOUND
)
297 wxString text
= GetItemHelpText(static_cast<unsigned int>(item
));
302 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
307 #endif // wxUSE_RADIOBOX