]>
git.saurik.com Git - wxWidgets.git/blob - src/common/radiocmn.cpp
6b85a15b8648f225b2feb0588e722a473abfd648
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 extern WXDLLEXPORT_DATA(const char) wxRadioBoxNameStr
[] = "radioBox";
43 // ============================================================================
45 // ============================================================================
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // TODO: wxCONSTRUCTOR
52 #if 0 // wxUSE_EXTENDED_RTTI
53 wxDEFINE_FLAGS( wxRadioBoxStyle
)
55 wxBEGIN_FLAGS( wxRadioBoxStyle
)
56 // new style border flags, we put them first to
57 // use them for streaming out
58 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
59 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
60 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
61 wxFLAGS_MEMBER(wxBORDER_RAISED
)
62 wxFLAGS_MEMBER(wxBORDER_STATIC
)
63 wxFLAGS_MEMBER(wxBORDER_NONE
)
65 // old style border flags
66 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
67 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
68 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
69 wxFLAGS_MEMBER(wxRAISED_BORDER
)
70 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
71 wxFLAGS_MEMBER(wxBORDER
)
73 // standard window styles
74 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
75 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
76 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
77 wxFLAGS_MEMBER(wxWANTS_CHARS
)
78 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
79 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
80 wxFLAGS_MEMBER(wxVSCROLL
)
81 wxFLAGS_MEMBER(wxHSCROLL
)
83 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
84 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
85 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
86 wxFLAGS_MEMBER(wxRA_VERTICAL
)
88 wxEND_FLAGS( wxRadioBoxStyle
)
90 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
92 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
93 wxEVENT_PROPERTY( Select
, wxEVT_RADIOBOX
, wxCommandEvent
)
94 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
95 wxEND_PROPERTIES_TABLE()
108 // ----------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
112 void wxRadioBoxBase::SetMajorDim(unsigned int majorDim
, long style
)
114 wxCHECK_RET( majorDim
!= 0, wxT("major radiobox dimension can't be 0") );
116 m_majorDim
= majorDim
;
118 int minorDim
= (GetCount() + m_majorDim
- 1) / m_majorDim
;
120 if ( style
& wxRA_SPECIFY_COLS
)
122 m_numCols
= majorDim
;
123 m_numRows
= minorDim
;
125 else // wxRA_SPECIFY_ROWS
127 m_numCols
= minorDim
;
128 m_numRows
= majorDim
;
132 int wxRadioBoxBase::GetNextItem(int item
, wxDirection dir
, long style
) const
134 const int itemStart
= item
;
136 int count
= GetCount(),
137 numCols
= GetColumnCount(),
138 numRows
= GetRowCount();
140 bool horz
= (style
& wxRA_SPECIFY_COLS
) != 0;
151 else // vertical layout
164 else // vertical layout
175 else // vertical layout
177 if ( ++item
== count
)
185 if ( ++item
== count
)
188 else // vertical layout
195 wxFAIL_MSG( wxT("unexpected wxDirection value") );
199 // ensure that the item is in range [0..count)
202 // first map the item to the one in the same column but in the last
206 // now there are 2 cases: either it is the first item of the last
207 // row in which case we need to wrap again and get to the last item
208 // or we can just go to the previous item
209 if ( item
% (horz
? numCols
: numRows
) )
214 else if ( item
>= count
)
216 // same logic as above
219 // ... except that we need to check if this is not the last item,
221 if ( (item
+ 1) % (horz
? numCols
: numRows
) )
227 wxASSERT_MSG( item
< count
&& item
>= 0,
228 wxT("logic error in wxRadioBox::GetNextItem()") );
230 // we shouldn't select the non-active items, continue looking for a
231 // visible and shown one unless we came back to the item we started from in
232 // which case bail out to avoid infinite loop
233 while ( !(IsItemShown(item
) && IsItemEnabled(item
)) && item
!= itemStart
);
240 void wxRadioBoxBase::SetItemToolTip(unsigned int item
, const wxString
& text
)
242 wxASSERT_MSG( item
< GetCount(), wxT("Invalid item index") );
244 // extend the array to have entries for all our items on first use
245 if ( !m_itemsTooltips
)
247 m_itemsTooltips
= new wxToolTipArray
;
248 m_itemsTooltips
->resize(GetCount());
251 wxToolTip
*tooltip
= (*m_itemsTooltips
)[item
];
258 // delete the tooltip
261 else // nothing to do
266 else // non empty tooltip text
270 // just change the existing tooltip text, don't change the tooltip
271 tooltip
->SetTip(text
);
274 else // no tooltip yet
276 // create the new one
277 tooltip
= new wxToolTip(text
);
283 (*m_itemsTooltips
)[item
] = tooltip
;
284 DoSetItemToolTip(item
, tooltip
);
289 wxRadioBoxBase::DoSetItemToolTip(unsigned int WXUNUSED(item
),
290 wxToolTip
* WXUNUSED(tooltip
))
292 // per-item tooltips not implemented by default
295 #endif // wxUSE_TOOLTIPS
297 wxRadioBoxBase::~wxRadioBoxBase()
300 if ( m_itemsTooltips
)
302 const size_t n
= m_itemsTooltips
->size();
303 for ( size_t i
= 0; i
< n
; i
++ )
304 delete (*m_itemsTooltips
)[i
];
306 delete m_itemsTooltips
;
308 #endif // wxUSE_TOOLTIPS
313 // set helptext for a particular item
314 void wxRadioBoxBase::SetItemHelpText(unsigned int n
, const wxString
& helpText
)
316 wxCHECK_RET( n
< GetCount(), wxT("Invalid item index") );
318 if ( m_itemsHelpTexts
.empty() )
320 // once-only initialization of the array: reserve space for all items
321 m_itemsHelpTexts
.Add(wxEmptyString
, GetCount());
324 m_itemsHelpTexts
[n
] = helpText
;
327 // retrieve helptext for a particular item
328 wxString
wxRadioBoxBase::GetItemHelpText( unsigned int n
) const
330 wxCHECK_MSG( n
< GetCount(), wxEmptyString
, wxT("Invalid item index") );
332 return m_itemsHelpTexts
.empty() ? wxString() : m_itemsHelpTexts
[n
];
335 // return help text for the item for which wxEVT_HELP was generated.
336 wxString
wxRadioBoxBase::DoGetHelpTextAtPoint(const wxWindow
*derived
,
338 wxHelpEvent::Origin origin
) const
343 case wxHelpEvent::Origin_HelpButton
:
344 item
= GetItemFromPoint(pt
);
347 case wxHelpEvent::Origin_Keyboard
:
348 item
= GetSelection();
352 wxFAIL_MSG( "unknown help even origin" );
355 case wxHelpEvent::Origin_Unknown
:
356 // this value is used when we're called from GetHelpText() for the
357 // radio box itself, so don't return item-specific text in this case
361 if ( item
!= wxNOT_FOUND
)
363 wxString text
= GetItemHelpText(static_cast<unsigned int>(item
));
368 return derived
->wxWindowBase::GetHelpTextAtPoint(pt
, origin
);
373 #endif // wxUSE_RADIOBOX