1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/radiobox.cpp
3 // Purpose: wxRadioBox implementation
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by: Wlodzimierz ABX Skiba - native wxRadioBox implementation
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/radiobox.h"
32 #include "wx/bitmap.h"
34 #include "wx/settings.h"
36 #include "wx/radiobut.h"
40 #include "wx/tooltip.h"
41 #endif // wxUSE_TOOLTIPS
43 // TODO: wxCONSTRUCTOR
44 #if 0 // wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxRadioBoxStyle
)
47 wxBEGIN_FLAGS( wxRadioBoxStyle
)
48 // new style border flags, we put them first to
49 // use them for streaming out
50 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
51 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
52 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
53 wxFLAGS_MEMBER(wxBORDER_RAISED
)
54 wxFLAGS_MEMBER(wxBORDER_STATIC
)
55 wxFLAGS_MEMBER(wxBORDER_NONE
)
57 // old style border flags
58 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
59 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
60 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
61 wxFLAGS_MEMBER(wxRAISED_BORDER
)
62 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
63 wxFLAGS_MEMBER(wxBORDER
)
65 // standard window styles
66 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
67 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
68 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
69 wxFLAGS_MEMBER(wxWANTS_CHARS
)
70 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
71 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
72 wxFLAGS_MEMBER(wxVSCROLL
)
73 wxFLAGS_MEMBER(wxHSCROLL
)
75 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
76 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
77 wxEND_FLAGS( wxRadioBoxStyle
)
79 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
81 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
82 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
83 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
84 wxEND_PROPERTIES_TABLE()
87 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
, wxControl
)
98 // ===========================================================================
100 // ===========================================================================
102 // ---------------------------------------------------------------------------
104 // ---------------------------------------------------------------------------
106 void wxRadioBox::Init()
108 m_pos
= wxPoint(0,0);
109 m_size
= wxSize(0,0);
112 unsigned int wxRadioBox::GetCount() const
114 return m_radios
.GetCount();
117 bool wxRadioBox::Create(wxWindow
*parent
,
119 const wxString
& title
,
123 const wxString choices
[],
126 const wxValidator
& val
,
127 const wxString
& name
)
129 // initialize members
130 SetMajorDim(majorDim
== 0 ? n
: majorDim
, style
);
132 if ( GetMajorDim() == 0 || n
== 0 )
135 // subtype of the native palmOS radio: checkbox or push button?
136 const bool use_checkbox
= style
& wxRA_USE_CHECKBOX
;
137 const bool use_cols
= style
& wxRA_SPECIFY_COLS
;
139 // get default size and position for the initial placement
142 int minor
= n
/ GetMajorDim();
143 if(n
% GetMajorDim() > 0)
145 if(m_size
.x
==wxDefaultCoord
)
146 m_size
.x
=36*(use_cols
?GetMajorDim():minor
);
147 if(m_size
.y
==wxDefaultCoord
)
148 m_size
.y
=12*(use_cols
?minor
:GetMajorDim());
149 if(m_pos
.x
==wxDefaultCoord
)
151 if(m_pos
.y
==wxDefaultCoord
)
156 if(!wxControl::Create(parent
, id
, m_pos
, m_size
, style
, val
, name
))
160 for ( unsigned int j
= 0; j
< minor
; j
++ )
162 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
167 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
168 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
169 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
170 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
171 wxRadioButton
* rb
= new wxRadioButton();
178 wxSize(end
.x
-start
.x
-1,end
.y
-start
.y
-1),
179 ( n
== 0 ? wxRB_GROUP
: 0 ) |
180 use_checkbox
? wxRB_USE_CHECKBOX
: 0
189 bool wxRadioBox::Create(wxWindow
*parent
,
191 const wxString
& title
,
194 const wxArrayString
& choices
,
197 const wxValidator
& val
,
198 const wxString
& name
)
200 wxCArrayString
chs(choices
);
202 return Create( parent
, id
, title
, pos
, size
, chs
.GetCount(),
203 chs
.GetStrings(), majorDim
, style
, val
, name
);
206 wxRadioBox::~wxRadioBox()
210 wxRadioButton
*wxRadioBox::GetRadioButton(int i
) const
212 return (wxRadioButton
*)m_radios
.Get(i
);
215 void wxRadioBox::DoGetPosition( int *x
, int *y
) const
221 void wxRadioBox::DoGetSize( int *width
, int *height
) const
227 void wxRadioBox::DoMoveWindow(int x
, int y
, int width
, int height
)
229 wxRect oldRect
= GetRect();
236 const bool use_cols
= HasFlag(wxRA_SPECIFY_COLS
);
238 const unsigned int n
= GetCount();
239 unsigned int minor
= n
/ GetMajorDim();
240 if(n
% GetMajorDim() > 0)
244 for ( unsigned int j
= 0; j
< minor
; j
++ )
246 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
251 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
252 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
253 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
254 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
255 wxRadioButton
* rb
= GetRadioButton(i
);
258 rb
->SetSize(start
.x
,start
.y
,end
.x
-start
.x
-1,end
.y
-start
.y
-1);
265 // refresh old and new area
266 GetParent()->RefreshRect(oldRect
.Union(GetRect()));
269 // get the origin of the client area in the client coordinates
270 wxPoint
wxRadioBox::GetClientAreaOrigin() const
272 return GetPosition();
275 void wxRadioBox::SetString(unsigned int item
, const wxString
& label
)
277 wxRadioButton
*btn
= GetRadioButton(item
);
279 btn
->SetLabel(label
);
282 void wxRadioBox::SetSelection(int N
)
286 // Get single selection, for single choice list items
287 int wxRadioBox::GetSelection() const
292 // Find string for position
293 wxString
wxRadioBox::GetString(unsigned int item
) const
295 wxRadioButton
*btn
= GetRadioButton(item
);
297 return btn
->GetLabel();
298 return wxEmptyString
;
301 // ----------------------------------------------------------------------------
303 // ----------------------------------------------------------------------------
305 wxSize
wxRadioBox::GetMaxButtonSize() const
310 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
315 wxSize
wxRadioBox::DoGetBestSize() const
320 void wxRadioBox::SetFocus()
324 // Enable all subcontrols
325 bool wxRadioBox::Enable(bool enable
)
327 for(unsigned int i
=0; i
<GetCount(); i
++)
332 // Enable a specific button
333 bool wxRadioBox::Enable(unsigned int item
, bool enable
)
335 wxRadioButton
*btn
= GetRadioButton(item
);
337 return btn
->Enable(enable
);
341 bool wxRadioBox::Show(bool show
)
343 for(unsigned int i
=0; i
<GetCount(); i
++)
348 // Show a specific button
349 bool wxRadioBox::Show(unsigned int item
, bool show
)
351 wxRadioButton
*btn
= GetRadioButton(item
);
354 bool ret
= btn
->Show(show
);
355 RefreshRect(btn
->GetRect());
361 wxString
wxRadioBox::GetLabel()
366 void wxRadioBox::SetLabel(const wxString
& label
)
371 void wxRadioBox::Refresh(bool eraseBack
, const wxRect
*rect
)
373 wxRect area
= GetRect();
377 area
.Offset(rect
->GetPosition());
378 area
.SetSize(rect
->GetSize());
381 GetParent()->RefreshRect(area
);
384 void wxRadioBox::Command(wxCommandEvent
& event
)
388 void wxRadioBox::SendNotificationEvent()
392 bool wxRadioBox::SetFont(const wxFont
& font
)
397 #endif // wxUSE_RADIOBOX