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"
39 #include "wx/tooltip.h"
40 #endif // wxUSE_TOOLTIPS
42 #include "wx/radiobut.h"
44 // TODO: wxCONSTRUCTOR
45 #if 0 // wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxRadioBoxStyle
)
48 wxBEGIN_FLAGS( wxRadioBoxStyle
)
49 // new style border flags, we put them first to
50 // use them for streaming out
51 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
52 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
53 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
54 wxFLAGS_MEMBER(wxBORDER_RAISED
)
55 wxFLAGS_MEMBER(wxBORDER_STATIC
)
56 wxFLAGS_MEMBER(wxBORDER_NONE
)
58 // old style border flags
59 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
60 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
61 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
62 wxFLAGS_MEMBER(wxRAISED_BORDER
)
63 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
64 wxFLAGS_MEMBER(wxBORDER
)
66 // standard window styles
67 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
68 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
69 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
70 wxFLAGS_MEMBER(wxWANTS_CHARS
)
71 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
72 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
73 wxFLAGS_MEMBER(wxVSCROLL
)
74 wxFLAGS_MEMBER(wxHSCROLL
)
76 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
77 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
78 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
79 wxFLAGS_MEMBER(wxRA_VERTICAL
)
81 wxEND_FLAGS( wxRadioBoxStyle
)
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
85 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
86 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
87 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
88 wxEND_PROPERTIES_TABLE()
91 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
, wxControl
)
102 // ===========================================================================
104 // ===========================================================================
106 // ---------------------------------------------------------------------------
108 // ---------------------------------------------------------------------------
110 void wxRadioBox::Init()
112 m_pos
= wxPoint(0,0);
113 m_size
= wxSize(0,0);
116 unsigned int wxRadioBox::GetCount() const
118 return m_radios
.GetCount();
121 bool wxRadioBox::Create(wxWindow
*parent
,
123 const wxString
& title
,
127 const wxString choices
[],
130 const wxValidator
& val
,
131 const wxString
& name
)
133 // initialize members
134 SetMajorDim(majorDim
== 0 ? n
: majorDim
, style
);
136 if ( GetMajorDim() == 0 || n
== 0 )
139 // subtype of the native palmOS radio: checkbox or push button?
140 const bool use_checkbox
= style
& wxRA_USE_CHECKBOX
;
141 const bool use_cols
= style
& wxRA_SPECIFY_COLS
;
143 // get default size and position for the initial placement
146 int minor
= n
/ GetMajorDim();
147 if(n
% GetMajorDim() > 0)
149 if(m_size
.x
==wxDefaultCoord
)
150 m_size
.x
=36*(use_cols
?GetMajorDim():minor
);
151 if(m_size
.y
==wxDefaultCoord
)
152 m_size
.y
=12*(use_cols
?minor
:GetMajorDim());
153 if(m_pos
.x
==wxDefaultCoord
)
155 if(m_pos
.y
==wxDefaultCoord
)
160 if(!wxControl::Create(parent
, id
, m_pos
, m_size
, style
, val
, name
))
164 for ( unsigned int j
= 0; j
< minor
; j
++ )
166 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
171 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
172 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
173 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
174 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
175 wxRadioButton
* rb
= new wxRadioButton();
182 wxSize(end
.x
-start
.x
-1,end
.y
-start
.y
-1),
183 ( n
== 0 ? wxRB_GROUP
: 0 ) |
184 use_checkbox
? wxRB_USE_CHECKBOX
: 0
193 bool wxRadioBox::Create(wxWindow
*parent
,
195 const wxString
& title
,
198 const wxArrayString
& choices
,
201 const wxValidator
& val
,
202 const wxString
& name
)
204 wxCArrayString
chs(choices
);
206 return Create( parent
, id
, title
, pos
, size
, chs
.GetCount(),
207 chs
.GetStrings(), majorDim
, style
, val
, name
);
210 wxRadioBox::~wxRadioBox()
214 wxRadioButton
*wxRadioBox::GetRadioButton(int i
) const
216 return (wxRadioButton
*)m_radios
.Get(i
);
219 void wxRadioBox::DoGetPosition( int *x
, int *y
) const
225 void wxRadioBox::DoGetSize( int *width
, int *height
) const
231 void wxRadioBox::DoMoveWindow(int x
, int y
, int width
, int height
)
233 wxRect oldRect
= GetRect();
240 const bool use_cols
= HasFlag(wxRA_SPECIFY_COLS
);
242 const unsigned int n
= GetCount();
243 unsigned int minor
= n
/ GetMajorDim();
244 if(n
% GetMajorDim() > 0)
248 for ( unsigned int j
= 0; j
< minor
; j
++ )
250 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
255 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
256 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
257 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
258 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
259 wxRadioButton
* rb
= GetRadioButton(i
);
262 rb
->SetSize(start
.x
,start
.y
,end
.x
-start
.x
-1,end
.y
-start
.y
-1);
269 // refresh old and new area
270 GetParent()->RefreshRect(oldRect
.Union(GetRect()));
273 // get the origin of the client area in the client coordinates
274 wxPoint
wxRadioBox::GetClientAreaOrigin() const
276 return GetPosition();
279 void wxRadioBox::SetString(unsigned int item
, const wxString
& label
)
281 wxRadioButton
*btn
= GetRadioButton(item
);
283 btn
->SetLabel(label
);
286 void wxRadioBox::SetSelection(int N
)
290 // Get single selection, for single choice list items
291 int wxRadioBox::GetSelection() const
296 // Find string for position
297 wxString
wxRadioBox::GetString(unsigned int item
) const
299 wxRadioButton
*btn
= GetRadioButton(item
);
301 return btn
->GetLabel();
302 return wxEmptyString
;
305 // ----------------------------------------------------------------------------
307 // ----------------------------------------------------------------------------
309 wxSize
wxRadioBox::GetMaxButtonSize() const
314 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
319 wxSize
wxRadioBox::DoGetBestSize() const
324 void wxRadioBox::SetFocus()
328 // Enable all subcontrols
329 bool wxRadioBox::Enable(bool enable
)
331 for(unsigned int i
=0; i
<GetCount(); i
++)
336 // Enable a specific button
337 bool wxRadioBox::Enable(unsigned int item
, bool enable
)
339 wxRadioButton
*btn
= GetRadioButton(item
);
341 return btn
->Enable(enable
);
345 bool wxRadioBox::Show(bool show
)
347 for(unsigned int i
=0; i
<GetCount(); i
++)
352 // Show a specific button
353 bool wxRadioBox::Show(unsigned int item
, bool show
)
355 wxRadioButton
*btn
= GetRadioButton(item
);
358 bool ret
= btn
->Show(show
);
359 RefreshRect(btn
->GetRect());
365 wxString
wxRadioBox::GetLabel()
370 void wxRadioBox::SetLabel(const wxString
& label
)
375 void wxRadioBox::Refresh(bool eraseBack
, const wxRect
*rect
)
377 wxRect area
= GetRect();
381 area
.Offset(rect
->GetPosition());
382 area
.SetSize(rect
->GetSize());
385 GetParent()->RefreshRect(area
);
388 void wxRadioBox::Command(wxCommandEvent
& event
)
392 void wxRadioBox::SendNotificationEvent()
396 bool wxRadioBox::SetFont(const wxFont
& font
)
401 #endif // wxUSE_RADIOBOX