]>
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
37 // ============================================================================
39 // ============================================================================
41 void wxRadioBoxBase::SetMajorDim(unsigned int majorDim
, long style
)
43 wxCHECK_RET( majorDim
!= 0, _T("major radiobox dimension can't be 0") );
45 m_majorDim
= majorDim
;
47 int minorDim
= (GetCount() + m_majorDim
- 1) / m_majorDim
;
49 if ( style
& wxRA_SPECIFY_COLS
)
54 else // wxRA_SPECIFY_ROWS
61 int wxRadioBoxBase::GetNextItem(int item
, wxDirection dir
, long style
) const
63 int count
= GetCount(),
64 numCols
= GetColumnCount(),
65 numRows
= GetRowCount();
67 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
76 else // vertical layout
89 else // vertical layout
100 else // vertical layout
102 if ( ++item
== count
)
110 if ( ++item
== count
)
113 else // vertical layout
120 wxFAIL_MSG( _T("unexpected wxDirection value") );
124 // ensure that the item is in range [0..count)
127 // first map the item to the one in the same column but in the last row
130 // now there are 2 cases: either it is the first item of the last row
131 // in which case we need to wrap again and get to the last item or we
132 // can just go to the previous item
133 if ( item
% (horz
? numCols
: numRows
) )
138 else if ( item
>= count
)
140 // same logic as above
143 // ... except that we need to check if this is not the last item, not
145 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
151 wxASSERT_MSG( item
< count
&& item
>= 0,
152 _T("logic error in wxRadioBox::GetNextItem()") );
159 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
161 wxASSERT_MSG( item
< GetCount(), _T("Invalid item index") );
163 // extend the array to have entries for all our items on first use
164 if ( !m_itemsTooltips
)
166 m_itemsTooltips
= new wxToolTipArray
;
167 m_itemsTooltips
->resize(GetCount());
170 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
177 // delete the tooltip
181 else // nothing to do
186 else // non empty tooltip text
190 // just change the existing tooltip text, don't change the tooltip
191 tooltip
->SetTip(text
);
194 else // no tooltip yet
196 // create the new one
197 tooltip
= new wxToolTip(text
);
203 (*m_itemsTooltips
)[item
] = tooltip
;
204 DoSetItemToolTip(item
, tooltip
);
209 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
210 wxToolTip
* WXUNUSED(tooltip
))
212 // per-item tooltips not implemented by default
215 #endif // wxUSE_TOOLTIPS
217 wxRadioBoxBase::~wxRadioBoxBase()
220 if ( m_itemsTooltips
)
222 const size_t n
= m_itemsTooltips
->size();
223 for ( size_t i
= 0; i
< n
; i
++ )
224 delete (*m_itemsTooltips
)[i
];
226 delete m_itemsTooltips
;
228 #endif // wxUSE_TOOLTIPS
231 #if WXWIN_COMPATIBILITY_2_4
233 // these functions are deprecated and don't do anything
234 int wxRadioBoxBase::GetNumberOfRowsOrCols() const
239 void wxRadioBoxBase::SetNumberOfRowsOrCols(int WXUNUSED(n
))
243 #endif // WXWIN_COMPATIBILITY_2_4
245 #endif // wxUSE_RADIOBOX