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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "radiobox.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/bitmap.h"
36 #include "wx/radiobox.h"
37 #include "wx/settings.h"
42 #include "wx/tooltip.h"
43 #endif // wxUSE_TOOLTIPS
45 #include "wx/radiobut.h"
47 // TODO: wxCONSTRUCTOR
48 #if 0 // wxUSE_EXTENDED_RTTI
49 WX_DEFINE_FLAGS( wxRadioBoxStyle
)
51 wxBEGIN_FLAGS( wxRadioBoxStyle
)
52 // new style border flags, we put them first to
53 // use them for streaming out
54 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
55 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
56 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
57 wxFLAGS_MEMBER(wxBORDER_RAISED
)
58 wxFLAGS_MEMBER(wxBORDER_STATIC
)
59 wxFLAGS_MEMBER(wxBORDER_NONE
)
61 // old style border flags
62 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
63 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
64 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
65 wxFLAGS_MEMBER(wxRAISED_BORDER
)
66 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
67 wxFLAGS_MEMBER(wxBORDER
)
69 // standard window styles
70 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
71 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
72 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
73 wxFLAGS_MEMBER(wxWANTS_CHARS
)
74 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
75 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
76 wxFLAGS_MEMBER(wxVSCROLL
)
77 wxFLAGS_MEMBER(wxHSCROLL
)
79 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
80 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
81 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
82 wxFLAGS_MEMBER(wxRA_VERTICAL
)
84 wxEND_FLAGS( wxRadioBoxStyle
)
86 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
88 wxBEGIN_PROPERTIES_TABLE(wxRadioBox
)
89 wxEVENT_PROPERTY( Select
, wxEVT_COMMAND_RADIOBOX_SELECTED
, wxCommandEvent
)
90 wxPROPERTY_FLAGS( WindowStyle
, wxRadioBoxStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
91 wxEND_PROPERTIES_TABLE()
94 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
, wxControl
)
105 // ===========================================================================
107 // ===========================================================================
109 // ---------------------------------------------------------------------------
111 // ---------------------------------------------------------------------------
113 void wxRadioBox::Init()
115 m_pos
= wxPoint(0,0);
116 m_size
= wxSize(0,0);
119 int wxRadioBox::GetCount() const
121 return m_radios
.GetCount();
124 int wxRadioBox::GetColumnCount() const
129 int wxRadioBox::GetRowCount() const
134 // returns the number of rows
135 int wxRadioBox::GetNumVer() const
140 // returns the number of columns
141 int wxRadioBox::GetNumHor() const
146 bool wxRadioBox::Create(wxWindow
*parent
,
148 const wxString
& title
,
152 const wxString choices
[],
155 const wxValidator
& val
,
156 const wxString
& name
)
158 // initialize members
159 m_majorDim
= majorDim
== 0 ? n
: wxMin(majorDim
, n
);
160 if(m_majorDim
==0 || n
==0) return false;
162 // subtype of the native palmOS radio: checkbox or push button?
163 const bool use_checkbox
= style
& wxRA_USE_CHECKBOX
;
164 const bool use_cols
= style
& wxRA_SPECIFY_COLS
;
166 // get default size and position for the initial placement
169 int minor
= n
/ m_majorDim
;
170 if(n
% m_majorDim
> 0) minor
++;
171 if(m_size
.x
==wxDefaultCoord
)
172 m_size
.x
=36*(use_cols
?m_majorDim
:minor
);
173 if(m_size
.y
==wxDefaultCoord
)
174 m_size
.y
=12*(use_cols
?minor
:m_majorDim
);
175 if(m_pos
.x
==wxDefaultCoord
)
177 if(m_pos
.y
==wxDefaultCoord
)
182 if(!wxControl::Create(parent
, id
, m_pos
, m_size
, style
, val
, name
))
186 for ( int j
= 0; j
< minor
; j
++ )
188 for ( int k
= 0; k
< m_majorDim
; k
++ )
193 start
.x
= (use_cols
? (k
*m_size
.x
)/m_majorDim
: (j
*m_size
.x
)/minor
);
194 start
.y
= (use_cols
? (j
*m_size
.y
)/minor
: (k
*m_size
.y
)/m_majorDim
);
195 end
.x
= (use_cols
? ((k
+1)*m_size
.x
)/m_majorDim
: ((j
+1)*m_size
.x
)/minor
);
196 end
.y
= (use_cols
? ((j
+1)*m_size
.y
)/minor
: ((k
+1)*m_size
.y
)/m_majorDim
);
197 wxRadioButton
* rb
= new wxRadioButton();
204 wxSize(end
.x
-start
.x
-1,end
.y
-start
.y
-1),
205 ( n
== 0 ? wxRB_GROUP
: 0 ) |
206 use_checkbox
? wxRB_USE_CHECKBOX
: 0
215 bool wxRadioBox::Create(wxWindow
*parent
,
217 const wxString
& title
,
220 const wxArrayString
& choices
,
223 const wxValidator
& val
,
224 const wxString
& name
)
226 wxCArrayString
chs(choices
);
228 return Create( parent
, id
, title
, pos
, size
, chs
.GetCount(),
229 chs
.GetStrings(), majorDim
, style
, val
, name
);
232 wxRadioBox::~wxRadioBox()
236 wxRadioButton
*wxRadioBox::GetRadioButton(int i
)
238 return (wxRadioButton
*)m_radios
.Get(i
);
241 void wxRadioBox::DoGetPosition( int *x
, int *y
) const
247 void wxRadioBox::DoGetSize( int *width
, int *height
) const
253 void wxRadioBox::DoMoveWindow(int x
, int y
, int width
, int height
)
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);
287 // get the origin of the client area in the client coordinates
288 wxPoint
wxRadioBox::GetClientAreaOrigin() const
290 return GetParent()->GetClientAreaOrigin() + GetPosition();
293 void wxRadioBox::SetString(int item
, const wxString
& label
)
297 void wxRadioBox::SetSelection(int N
)
301 // Get single selection, for single choice list items
302 int wxRadioBox::GetSelection() const
307 // Find string for position
308 wxString
wxRadioBox::GetString(int item
) const
315 // ----------------------------------------------------------------------------
317 // ----------------------------------------------------------------------------
319 wxSize
wxRadioBox::GetMaxButtonSize() const
324 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
329 wxSize
wxRadioBox::DoGetBestSize() const
334 void wxRadioBox::SetFocus()
338 // Enable all subcontrols
339 bool wxRadioBox::Enable(bool enable
)
341 for(int i
=0; i
<GetCount(); i
++)
346 // Enable a specific button
347 bool wxRadioBox::Enable(int item
, bool enable
)
349 wxRadioButton
*btn
= GetRadioButton(item
);
351 return btn
->Enable(enable
);
355 bool wxRadioBox::Show(bool show
)
360 // Show a specific button
361 void wxRadioBox::Show(int item
, bool show
)
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()->Refresh( eraseBack
, &area
);
388 void wxRadioBox::Command(wxCommandEvent
& event
)
392 void wxRadioBox::SendNotificationEvent()
396 bool wxRadioBox::SetFont(const wxFont
& font
)
401 #endif // wxUSE_RADIOBOX