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 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // TODO: wxCONSTRUCTOR
50 #if 0 // wxUSE_EXTENDED_RTTI
51 wxDEFINE_FLAGS( wxRadioBoxStyle
)
53 wxBEGIN_FLAGS( wxRadioBoxStyle
)
54 // new style border flags, we put them first to
55 // use them for streaming out
56 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
57 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
58 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
59 wxFLAGS_MEMBER(wxBORDER_RAISED
)
60 wxFLAGS_MEMBER(wxBORDER_STATIC
)
61 wxFLAGS_MEMBER(wxBORDER_NONE
)
63 // old style border flags
64 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
65 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
66 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
67 wxFLAGS_MEMBER(wxRAISED_BORDER
)
68 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
69 wxFLAGS_MEMBER(wxBORDER
)
71 // standard window styles
72 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
73 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
74 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
75 wxFLAGS_MEMBER(wxWANTS_CHARS
)
76 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
77 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
78 wxFLAGS_MEMBER(wxVSCROLL
)
79 wxFLAGS_MEMBER(wxHSCROLL
)
81 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
82 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
83 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
84 wxFLAGS_MEMBER(wxRA_VERTICAL
)
86 wxEND_FLAGS( wxRadioBoxStyle
)
88 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
90 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
91 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
92 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
93 wxEND_PROPERTIES_TABLE()
106 // ----------------------------------------------------------------------------
108 // ----------------------------------------------------------------------------
110 void wxRadioBoxBase::SetMajorDim(unsigned int majorDim
, long style
)
112 wxCHECK_RET( majorDim
!= 0, wxT("major radiobox dimension can't be 0") );
114 m_majorDim
= majorDim
;
116 int minorDim
= (GetCount() + m_majorDim
- 1) / m_majorDim
;
118 if ( style
& wxRA_SPECIFY_COLS
)
120 m_numCols
= majorDim
;
121 m_numRows
= minorDim
;
123 else // wxRA_SPECIFY_ROWS
125 m_numCols
= minorDim
;
126 m_numRows
= majorDim
;
130 int wxRadioBoxBase::GetNextItem(int item
, wxDirection dir
, long style
) const
132 const int itemStart
= item
;
134 int count
= GetCount(),
135 numCols
= GetColumnCount(),
136 numRows
= GetRowCount();
138 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
149 else // vertical layout
162 else // vertical layout
173 else // vertical layout
175 if ( ++item
== count
)
183 if ( ++item
== count
)
186 else // vertical layout
193 wxFAIL_MSG( wxT("unexpected wxDirection value") );
197 // ensure that the item is in range [0..count)
200 // first map the item to the one in the same column but in the last
204 // now there are 2 cases: either it is the first item of the last
205 // row in which case we need to wrap again and get to the last item
206 // or we can just go to the previous item
207 if ( item
% (horz
? numCols
: numRows
) )
212 else if ( item
>= count
)
214 // same logic as above
217 // ... except that we need to check if this is not the last item,
219 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
225 wxASSERT_MSG( item
< count
&& item
>= 0,
226 wxT("logic error in wxRadioBox::GetNextItem()") );
228 // we shouldn't select the non-active items, continue looking for a
229 // visible and shown one unless we came back to the item we started from in
230 // which case bail out to avoid infinite loop
231 while ( !(IsItemShown(item
) && IsItemEnabled(item
)) && item
!= itemStart
);
238 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
240 wxASSERT_MSG( item
< GetCount(), wxT("Invalid item index") );
242 // extend the array to have entries for all our items on first use
243 if ( !m_itemsTooltips
)
245 m_itemsTooltips
= new wxToolTipArray
;
246 m_itemsTooltips
->resize(GetCount());
249 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
256 // delete the tooltip
259 else // nothing to do
264 else // non empty tooltip text
268 // just change the existing tooltip text, don't change the tooltip
269 tooltip
->SetTip(text
);
272 else // no tooltip yet
274 // create the new one
275 tooltip
= new wxToolTip(text
);
281 (*m_itemsTooltips
)[item
] = tooltip
;
282 DoSetItemToolTip(item
, tooltip
);
287 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
288 wxToolTip
* WXUNUSED(tooltip
))
290 // per-item tooltips not implemented by default
293 #endif // wxUSE_TOOLTIPS
295 wxRadioBoxBase::~wxRadioBoxBase()
298 if ( m_itemsTooltips
)
300 const size_t n
= m_itemsTooltips
->size();
301 for ( size_t i
= 0; i
< n
; i
++ )
302 delete (*m_itemsTooltips
)[i
];
304 delete m_itemsTooltips
;
306 #endif // wxUSE_TOOLTIPS
311 // set helptext for a particular item
312 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
314 wxCHECK_RET( n
< GetCount(), wxT("Invalid item index") );
316 if ( m_itemsHelpTexts
.empty() )
318 // once-only initialization of the array: reserve space for all items
319 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
322 m_itemsHelpTexts
[n
] = helpText
;
325 // retrieve helptext for a particular item
326 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
328 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, wxT("Invalid item index") );
330 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
333 // return help text for the item for which wxEVT_HELP was generated.
334 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
336 wxHelpEvent::Origin origin
) const
341 case wxHelpEvent::Origin_HelpButton
:
342 item
= GetItemFromPoint(pt
);
345 case wxHelpEvent::Origin_Keyboard
:
346 item
= GetSelection();
350 wxFAIL_MSG( "unknown help even origin" );
353 case wxHelpEvent::Origin_Unknown
:
354 // this value is used when we're called from GetHelpText() for the
355 // radio box itself, so don't return item-specific text in this case
359 if ( item
!= wxNOT_FOUND
)
361 wxString text
= GetItemHelpText(static_cast<unsigned int>(item
));
366 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
371 #endif // wxUSE_RADIOBOX