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"
30 #include "wx/bitmap.h"
32 #include "wx/radiobox.h"
33 #include "wx/settings.h"
38 #include "wx/tooltip.h"
39 #endif // wxUSE_TOOLTIPS
41 #include "wx/radiobut.h"
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 int wxRadioBox::GetCount() const
117 return m_radios
.GetCount();
120 int wxRadioBox::GetColumnCount() const
125 int wxRadioBox::GetRowCount() const
130 // returns the number of rows
131 int wxRadioBox::GetNumVer() const
136 // returns the number of columns
137 int wxRadioBox::GetNumHor() const
142 bool wxRadioBox::Create(wxWindow
*parent
,
144 const wxString
& title
,
148 const wxString choices
[],
151 const wxValidator
& val
,
152 const wxString
& name
)
154 // initialize members
155 m_majorDim
= majorDim
== 0 ? n
: wxMin(majorDim
, n
);
156 if(m_majorDim
==0 || n
==0) return false;
158 // subtype of the native palmOS radio: checkbox or push button?
159 const bool use_checkbox
= style
& wxRA_USE_CHECKBOX
;
160 const bool use_cols
= style
& wxRA_SPECIFY_COLS
;
162 // get default size and position for the initial placement
165 int minor
= n
/ m_majorDim
;
166 if(n
% m_majorDim
> 0) minor
++;
167 if(m_size
.x
==wxDefaultCoord
)
168 m_size
.x
=36*(use_cols
?m_majorDim
:minor
);
169 if(m_size
.y
==wxDefaultCoord
)
170 m_size
.y
=12*(use_cols
?minor
:m_majorDim
);
171 if(m_pos
.x
==wxDefaultCoord
)
173 if(m_pos
.y
==wxDefaultCoord
)
178 if(!wxControl::Create(parent
, id
, m_pos
, m_size
, style
, val
, name
))
182 for ( int j
= 0; j
< minor
; j
++ )
184 for ( int k
= 0; k
< m_majorDim
; k
++ )
189 start
.x
= (use_cols
? (k
*m_size
.x
)/m_majorDim
: (j
*m_size
.x
)/minor
);
190 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/m_majorDim
);
191 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/m_majorDim
: ((j
+1)*m_size
.x
)/minor
);
192 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/m_majorDim
);
193 wxRadioButton
* rb
= new wxRadioButton();
200 wxSize(end
.x
-start
.x
-1,end
.y
-start
.y
-1),
201 ( n
== 0 ? wxRB_GROUP
: 0 ) |
202 use_checkbox
? wxRB_USE_CHECKBOX
: 0
211 bool wxRadioBox::Create(wxWindow
*parent
,
213 const wxString
& title
,
216 const wxArrayString
& choices
,
219 const wxValidator
& val
,
220 const wxString
& name
)
222 wxCArrayString
chs(choices
);
224 return Create( parent
, id
, title
, pos
, size
, chs
.GetCount(),
225 chs
.GetStrings(), majorDim
, style
, val
, name
);
228 wxRadioBox::~wxRadioBox()
232 wxRadioButton
*wxRadioBox::GetRadioButton(int i
) const
234 return (wxRadioButton
*)m_radios
.Get(i
);
237 void wxRadioBox::DoGetPosition( int *x
, int *y
) const
243 void wxRadioBox::DoGetSize( int *width
, int *height
) const
249 void wxRadioBox::DoMoveWindow(int x
, int y
, int width
, int height
)
251 wxRect oldRect
= GetRect();
258 const bool use_cols
= HasFlag(wxRA_SPECIFY_COLS
);
260 const int n
= GetCount();
261 int minor
= n
/ m_majorDim
;
262 if(n
% m_majorDim
> 0) minor
++;
265 for ( int j
= 0; j
< minor
; j
++ )
267 for ( int k
= 0; k
< m_majorDim
; k
++ )
272 start
.x
= (use_cols
? (k
*m_size
.x
)/m_majorDim
: (j
*m_size
.x
)/minor
);
273 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/m_majorDim
);
274 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/m_majorDim
: ((j
+1)*m_size
.x
)/minor
);
275 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/m_majorDim
);
276 wxRadioButton
* rb
= GetRadioButton(i
);
279 rb
->SetSize(start
.x
,start
.y
,end
.x
-start
.x
-1,end
.y
-start
.y
-1);
286 // refresh old and new area
287 GetParent()->RefreshRect(oldRect
.Union(GetRect()));
290 // get the origin of the client area in the client coordinates
291 wxPoint
wxRadioBox::GetClientAreaOrigin() const
293 return GetPosition();
296 void wxRadioBox::SetString(int item
, const wxString
& label
)
298 wxRadioButton
*btn
= GetRadioButton(item
);
300 btn
->SetLabel(label
);
303 void wxRadioBox::SetSelection(int N
)
307 // Get single selection, for single choice list items
308 int wxRadioBox::GetSelection() const
313 // Find string for position
314 wxString
wxRadioBox::GetString(int item
) const
316 wxRadioButton
*btn
= GetRadioButton(item
);
318 return btn
->GetLabel();
319 return wxEmptyString
;
322 // ----------------------------------------------------------------------------
324 // ----------------------------------------------------------------------------
326 wxSize
wxRadioBox::GetMaxButtonSize() const
331 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
336 wxSize
wxRadioBox::DoGetBestSize() const
341 void wxRadioBox::SetFocus()
345 // Enable all subcontrols
346 bool wxRadioBox::Enable(bool enable
)
348 for(int i
=0; i
<GetCount(); i
++)
353 // Enable a specific button
354 bool wxRadioBox::Enable(int item
, bool enable
)
356 wxRadioButton
*btn
= GetRadioButton(item
);
358 return btn
->Enable(enable
);
362 bool wxRadioBox::Show(bool show
)
364 for(int i
=0; i
<GetCount(); i
++)
369 // Show a specific button
370 bool wxRadioBox::Show(int item
, bool show
)
372 wxRadioButton
*btn
= GetRadioButton(item
);
375 bool ret
= btn
->Show(show
);
376 RefreshRect(btn
->GetRect());
382 wxString
wxRadioBox::GetLabel()
387 void wxRadioBox::SetLabel(const wxString
& label
)
392 void wxRadioBox::Refresh(bool eraseBack
, const wxRect
*rect
)
394 wxRect area
= GetRect();
398 area
.Offset(rect
->GetPosition());
399 area
.SetSize(rect
->GetSize());
402 GetParent()->RefreshRect(area
);
405 void wxRadioBox::Command(wxCommandEvent
& event
)
409 void wxRadioBox::SendNotificationEvent()
413 bool wxRadioBox::SetFont(const wxFont
& font
)
418 #endif // wxUSE_RADIOBOX