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_HORIZONTAL
)
77 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
78 wxFLAGS_MEMBER(wxRA_VERTICAL
)
80 wxEND_FLAGS( wxRadioBoxStyle
)
82 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
84 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
85 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
86 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
87 wxEND_PROPERTIES_TABLE()
90 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
, wxControl
)
101 // ===========================================================================
103 // ===========================================================================
105 // ---------------------------------------------------------------------------
107 // ---------------------------------------------------------------------------
109 void wxRadioBox::Init()
111 m_pos
= wxPoint(0,0);
112 m_size
= wxSize(0,0);
115 unsigned int wxRadioBox::GetCount() const
117 return m_radios
.GetCount();
120 bool wxRadioBox::Create(wxWindow
*parent
,
122 const wxString
& title
,
126 const wxString choices
[],
129 const wxValidator
& val
,
130 const wxString
& name
)
132 // initialize members
133 SetMajorDim(majorDim
== 0 ? n
: majorDim
, style
);
135 if ( GetMajorDim() == 0 || n
== 0 )
138 // subtype of the native palmOS radio: checkbox or push button?
139 const bool use_checkbox
= style
& wxRA_USE_CHECKBOX
;
140 const bool use_cols
= style
& wxRA_SPECIFY_COLS
;
142 // get default size and position for the initial placement
145 int minor
= n
/ GetMajorDim();
146 if(n
% GetMajorDim() > 0)
148 if(m_size
.x
==wxDefaultCoord
)
149 m_size
.x
=36*(use_cols
?GetMajorDim():minor
);
150 if(m_size
.y
==wxDefaultCoord
)
151 m_size
.y
=12*(use_cols
?minor
:GetMajorDim());
152 if(m_pos
.x
==wxDefaultCoord
)
154 if(m_pos
.y
==wxDefaultCoord
)
159 if(!wxControl::Create(parent
, id
, m_pos
, m_size
, style
, val
, name
))
163 for ( unsigned int j
= 0; j
< minor
; j
++ )
165 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
170 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
171 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
172 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
173 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
174 wxRadioButton
* rb
= new wxRadioButton();
181 wxSize(end
.x
-start
.x
-1,end
.y
-start
.y
-1),
182 ( n
== 0 ? wxRB_GROUP
: 0 ) |
183 use_checkbox
? wxRB_USE_CHECKBOX
: 0
192 bool wxRadioBox::Create(wxWindow
*parent
,
194 const wxString
& title
,
197 const wxArrayString
& choices
,
200 const wxValidator
& val
,
201 const wxString
& name
)
203 wxCArrayString
chs(choices
);
205 return Create( parent
, id
, title
, pos
, size
, chs
.GetCount(),
206 chs
.GetStrings(), majorDim
, style
, val
, name
);
209 wxRadioBox::~wxRadioBox()
213 wxRadioButton
*wxRadioBox::GetRadioButton(int i
) const
215 return (wxRadioButton
*)m_radios
.Get(i
);
218 void wxRadioBox::DoGetPosition( int *x
, int *y
) const
224 void wxRadioBox::DoGetSize( int *width
, int *height
) const
230 void wxRadioBox::DoMoveWindow(int x
, int y
, int width
, int height
)
232 wxRect oldRect
= GetRect();
239 const bool use_cols
= HasFlag(wxRA_SPECIFY_COLS
);
241 const unsigned int n
= GetCount();
242 unsigned int minor
= n
/ GetMajorDim();
243 if(n
% GetMajorDim() > 0)
247 for ( unsigned int j
= 0; j
< minor
; j
++ )
249 for ( unsigned int k
= 0; k
< GetMajorDim(); k
++ )
254 start
.x
= (use_cols
? (k
*m_size
.x
)/GetMajorDim() : (j
*m_size
.x
)/minor
);
255 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/GetMajorDim());
256 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/GetMajorDim() : ((j
+1)*m_size
.x
)/minor
);
257 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/GetMajorDim());
258 wxRadioButton
* rb
= GetRadioButton(i
);
261 rb
->SetSize(start
.x
,start
.y
,end
.x
-start
.x
-1,end
.y
-start
.y
-1);
268 // refresh old and new area
269 GetParent()->RefreshRect(oldRect
.Union(GetRect()));
272 // get the origin of the client area in the client coordinates
273 wxPoint
wxRadioBox::GetClientAreaOrigin() const
275 return GetPosition();
278 void wxRadioBox::SetString(unsigned int item
, const wxString
& label
)
280 wxRadioButton
*btn
= GetRadioButton(item
);
282 btn
->SetLabel(label
);
285 void wxRadioBox::SetSelection(int N
)
289 // Get single selection, for single choice list items
290 int wxRadioBox::GetSelection() const
295 // Find string for position
296 wxString
wxRadioBox::GetString(unsigned int item
) const
298 wxRadioButton
*btn
= GetRadioButton(item
);
300 return btn
->GetLabel();
301 return wxEmptyString
;
304 // ----------------------------------------------------------------------------
306 // ----------------------------------------------------------------------------
308 wxSize
wxRadioBox::GetMaxButtonSize() const
313 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
318 wxSize
wxRadioBox::DoGetBestSize() const
323 void wxRadioBox::SetFocus()
327 // Enable all subcontrols
328 bool wxRadioBox::Enable(bool enable
)
330 for(unsigned int i
=0; i
<GetCount(); i
++)
335 // Enable a specific button
336 bool wxRadioBox::Enable(unsigned int item
, bool enable
)
338 wxRadioButton
*btn
= GetRadioButton(item
);
340 return btn
->Enable(enable
);
344 bool wxRadioBox::Show(bool show
)
346 for(unsigned int i
=0; i
<GetCount(); i
++)
351 // Show a specific button
352 bool wxRadioBox::Show(unsigned int item
, bool show
)
354 wxRadioButton
*btn
= GetRadioButton(item
);
357 bool ret
= btn
->Show(show
);
358 RefreshRect(btn
->GetRect());
364 wxString
wxRadioBox::GetLabel()
369 void wxRadioBox::SetLabel(const wxString
& label
)
374 void wxRadioBox::Refresh(bool eraseBack
, const wxRect
*rect
)
376 wxRect area
= GetRect();
380 area
.Offset(rect
->GetPosition());
381 area
.SetSize(rect
->GetSize());
384 GetParent()->RefreshRect(area
);
387 void wxRadioBox::Command(wxCommandEvent
& event
)
391 void wxRadioBox::SendNotificationEvent()
395 bool wxRadioBox::SetFont(const wxFont
& font
)
400 #endif // wxUSE_RADIOBOX