]>
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 // Licence: 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, wxT("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( wxT("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 wxT("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(), wxT("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
194 else // nothing to do
199 else // non empty tooltip text
203 // just change the existing tooltip text, don't change the tooltip
204 tooltip
->SetTip(text
);
207 else // no tooltip yet
209 // create the new one
210 tooltip
= new wxToolTip(text
);
216 (*m_itemsTooltips
)[item
] = tooltip
;
217 DoSetItemToolTip(item
, tooltip
);
222 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
223 wxToolTip
* WXUNUSED(tooltip
))
225 // per-item tooltips not implemented by default
228 #endif // wxUSE_TOOLTIPS
230 wxRadioBoxBase::~wxRadioBoxBase()
233 if ( m_itemsTooltips
)
235 const size_t n
= m_itemsTooltips
->size();
236 for ( size_t i
= 0; i
< n
; i
++ )
237 delete (*m_itemsTooltips
)[i
];
239 delete m_itemsTooltips
;
241 #endif // wxUSE_TOOLTIPS
246 // set helptext for a particular item
247 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
249 wxCHECK_RET( n
< GetCount(), wxT("Invalid item index") );
251 if ( m_itemsHelpTexts
.empty() )
253 // once-only initialization of the array: reserve space for all items
254 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
257 m_itemsHelpTexts
[n
] = helpText
;
260 // retrieve helptext for a particular item
261 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
263 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, wxT("Invalid item index") );
265 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
268 // return help text for the item for which wxEVT_HELP was generated.
269 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
271 wxHelpEvent::Origin origin
) const
276 case wxHelpEvent::Origin_HelpButton
:
277 item
= GetItemFromPoint(pt
);
280 case wxHelpEvent::Origin_Keyboard
:
281 item
= GetSelection();
285 wxFAIL_MSG( "unknown help even origin" );
288 case wxHelpEvent::Origin_Unknown
:
289 // this value is used when we're called from GetHelpText() for the
290 // radio box itself, so don't return item-specific text in this case
294 if ( item
!= wxNOT_FOUND
)
296 wxString text
= GetItemHelpText(static_cast<unsigned int>(item
));
301 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
306 #endif // wxUSE_RADIOBOX