]>
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 int count
= GetCount(),
68 numCols
= GetColumnCount(),
69 numRows
= GetRowCount();
71 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
80 else // vertical layout
93 else // vertical layout
104 else // vertical layout
106 if ( ++item
== count
)
114 if ( ++item
== count
)
117 else // vertical layout
124 wxFAIL_MSG( _T("unexpected wxDirection value") );
128 // ensure that the item is in range [0..count)
131 // first map the item to the one in the same column but in the last row
134 // now there are 2 cases: either it is the first item of the last row
135 // in which case we need to wrap again and get to the last item or we
136 // can just go to the previous item
137 if ( item
% (horz
? numCols
: numRows
) )
142 else if ( item
>= count
)
144 // same logic as above
147 // ... except that we need to check if this is not the last item, not
149 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
155 wxASSERT_MSG( item
< count
&& item
>= 0,
156 _T("logic error in wxRadioBox::GetNextItem()") );
163 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
165 wxASSERT_MSG( item
< GetCount(), _T("Invalid item index") );
167 // extend the array to have entries for all our items on first use
168 if ( !m_itemsTooltips
)
170 m_itemsTooltips
= new wxToolTipArray
;
171 m_itemsTooltips
->resize(GetCount());
174 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
181 // delete the tooltip
185 else // nothing to do
190 else // non empty tooltip text
194 // just change the existing tooltip text, don't change the tooltip
195 tooltip
->SetTip(text
);
198 else // no tooltip yet
200 // create the new one
201 tooltip
= new wxToolTip(text
);
207 (*m_itemsTooltips
)[item
] = tooltip
;
208 DoSetItemToolTip(item
, tooltip
);
213 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
214 wxToolTip
* WXUNUSED(tooltip
))
216 // per-item tooltips not implemented by default
219 #endif // wxUSE_TOOLTIPS
221 wxRadioBoxBase::~wxRadioBoxBase()
224 if ( m_itemsTooltips
)
226 const size_t n
= m_itemsTooltips
->size();
227 for ( size_t i
= 0; i
< n
; i
++ )
228 delete (*m_itemsTooltips
)[i
];
230 delete m_itemsTooltips
;
232 #endif // wxUSE_TOOLTIPS
237 // set helptext for a particular item
238 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
240 wxCHECK_RET( n
< GetCount(), _T("Invalid item index") );
242 if ( m_itemsHelpTexts
.empty() )
244 // once-only initialization of the array: reserve space for all items
245 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
248 m_itemsHelpTexts
[n
] = helpText
;
251 // retrieve helptext for a particular item
252 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
254 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, _T("Invalid item index") );
256 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
259 // return help text for the item for which wxEVT_HELP was generated.
260 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
262 wxHelpEvent::Origin origin
) const
264 const int item
= origin
== wxHelpEvent::Origin_HelpButton
265 ? GetItemFromPoint(pt
)
268 if ( item
!= wxNOT_FOUND
)
270 wxString text
= GetItemHelpText(wx_static_cast(unsigned int, item
));
275 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
280 #if WXWIN_COMPATIBILITY_2_4
282 // these functions are deprecated and don't do anything
283 int wxRadioBoxBase::GetNumberOfRowsOrCols() const
288 void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n
))
292 #endif // WXWIN_COMPATIBILITY_2_4
294 #endif // wxUSE_RADIOBOX