]>
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
7 // Copyright: (c) 2001 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
29 #include "wx/radiobox.h"
33 #include "wx/tooltip.h"
34 #endif // wxUSE_TOOLTIPS
37 #include "wx/cshelp.h"
40 extern WXDLLEXPORT_DATA(const char) wxRadioBoxNameStr
[] = "radioBox";
42 // ============================================================================
44 // ============================================================================
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // TODO: wxCONSTRUCTOR
51 #if 0 // wxUSE_EXTENDED_RTTI
52 wxDEFINE_FLAGS( wxRadioBoxStyle
)
54 wxBEGIN_FLAGS( wxRadioBoxStyle
)
55 // new style border flags, we put them first to
56 // use them for streaming out
57 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
58 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
59 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
60 wxFLAGS_MEMBER(wxBORDER_RAISED
)
61 wxFLAGS_MEMBER(wxBORDER_STATIC
)
62 wxFLAGS_MEMBER(wxBORDER_NONE
)
64 // old style border flags
65 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
66 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
67 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
68 wxFLAGS_MEMBER(wxRAISED_BORDER
)
69 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
70 wxFLAGS_MEMBER(wxBORDER
)
72 // standard window styles
73 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
74 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
75 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
76 wxFLAGS_MEMBER(wxWANTS_CHARS
)
77 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
78 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
79 wxFLAGS_MEMBER(wxVSCROLL
)
80 wxFLAGS_MEMBER(wxHSCROLL
)
82 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
83 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
84 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
85 wxFLAGS_MEMBER(wxRA_VERTICAL
)
87 wxEND_FLAGS( wxRadioBoxStyle
)
89 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
91 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
92 wxEVENT_PROPERTY( Select
, wxEVT_RADIOBOX
, wxCommandEvent
)
93 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
94 wxEND_PROPERTIES_TABLE()
107 // ----------------------------------------------------------------------------
109 // ----------------------------------------------------------------------------
111 void wxRadioBoxBase::SetMajorDim(unsigned int majorDim
, long style
)
113 wxCHECK_RET( majorDim
!= 0, wxT("major radiobox dimension can't be 0") );
115 m_majorDim
= majorDim
;
117 int minorDim
= (GetCount() + m_majorDim
- 1) / m_majorDim
;
119 if ( style
& wxRA_SPECIFY_COLS
)
121 m_numCols
= majorDim
;
122 m_numRows
= minorDim
;
124 else // wxRA_SPECIFY_ROWS
126 m_numCols
= minorDim
;
127 m_numRows
= majorDim
;
131 int wxRadioBoxBase::GetNextItem(int item
, wxDirection dir
, long style
) const
133 const int itemStart
= item
;
135 int count
= GetCount(),
136 numCols
= GetColumnCount(),
137 numRows
= GetRowCount();
139 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
150 else // vertical layout
163 else // vertical layout
174 else // vertical layout
176 if ( ++item
== count
)
184 if ( ++item
== count
)
187 else // vertical layout
194 wxFAIL_MSG( wxT("unexpected wxDirection value") );
198 // ensure that the item is in range [0..count)
201 // first map the item to the one in the same column but in the last
205 // now there are 2 cases: either it is the first item of the last
206 // row in which case we need to wrap again and get to the last item
207 // or we can just go to the previous item
208 if ( item
% (horz
? numCols
: numRows
) )
213 else if ( item
>= count
)
215 // same logic as above
218 // ... except that we need to check if this is not the last item,
220 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
226 wxASSERT_MSG( item
< count
&& item
>= 0,
227 wxT("logic error in wxRadioBox::GetNextItem()") );
229 // we shouldn't select the non-active items, continue looking for a
230 // visible and shown one unless we came back to the item we started from in
231 // which case bail out to avoid infinite loop
232 while ( !(IsItemShown(item
) && IsItemEnabled(item
)) && item
!= itemStart
);
239 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
241 wxASSERT_MSG( item
< GetCount(), wxT("Invalid item index") );
243 // extend the array to have entries for all our items on first use
244 if ( !m_itemsTooltips
)
246 m_itemsTooltips
= new wxToolTipArray
;
247 m_itemsTooltips
->resize(GetCount());
250 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
257 // delete the tooltip
260 else // nothing to do
265 else // non empty tooltip text
269 // just change the existing tooltip text, don't change the tooltip
270 tooltip
->SetTip(text
);
273 else // no tooltip yet
275 // create the new one
276 tooltip
= new wxToolTip(text
);
282 (*m_itemsTooltips
)[item
] = tooltip
;
283 DoSetItemToolTip(item
, tooltip
);
288 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
289 wxToolTip
* WXUNUSED(tooltip
))
291 // per-item tooltips not implemented by default
294 #endif // wxUSE_TOOLTIPS
296 wxRadioBoxBase::~wxRadioBoxBase()
299 if ( m_itemsTooltips
)
301 const size_t n
= m_itemsTooltips
->size();
302 for ( size_t i
= 0; i
< n
; i
++ )
303 delete (*m_itemsTooltips
)[i
];
305 delete m_itemsTooltips
;
307 #endif // wxUSE_TOOLTIPS
312 // set helptext for a particular item
313 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
315 wxCHECK_RET( n
< GetCount(), wxT("Invalid item index") );
317 if ( m_itemsHelpTexts
.empty() )
319 // once-only initialization of the array: reserve space for all items
320 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
323 m_itemsHelpTexts
[n
] = helpText
;
326 // retrieve helptext for a particular item
327 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
329 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, wxT("Invalid item index") );
331 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
334 // return help text for the item for which wxEVT_HELP was generated.
335 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
337 wxHelpEvent::Origin origin
) const
342 case wxHelpEvent::Origin_HelpButton
:
343 item
= GetItemFromPoint(pt
);
346 case wxHelpEvent::Origin_Keyboard
:
347 item
= GetSelection();
351 wxFAIL_MSG( "unknown help even origin" );
354 case wxHelpEvent::Origin_Unknown
:
355 // this value is used when we're called from GetHelpText() for the
356 // radio box itself, so don't return item-specific text in this case
360 if ( item
!= wxNOT_FOUND
)
362 wxString text
= GetItemHelpText(static_cast<unsigned int>(item
));
367 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
372 #endif // wxUSE_RADIOBOX