]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/radiobox.cpp
wxArrayString::Sort() wasn't MT-safe even though it tried to
[wxWidgets.git] / src / palmos / radiobox.cpp
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
6 // Created: 10/13/04
7 // RCS-ID: $Id$
8 // Copyright: (c) William Osborne, Wlodzimierz Skiba
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #if wxUSE_RADIOBOX
28
29 #include "wx/radiobox.h"
30
31 #ifndef WX_PRECOMP
32 #include "wx/bitmap.h"
33 #include "wx/brush.h"
34 #include "wx/settings.h"
35 #include "wx/log.h"
36 #endif
37
38 #if wxUSE_TOOLTIPS
39 #include "wx/tooltip.h"
40 #endif // wxUSE_TOOLTIPS
41
42 #include "wx/radiobut.h"
43
44 // TODO: wxCONSTRUCTOR
45 #if 0 // wxUSE_EXTENDED_RTTI
46 WX_DEFINE_FLAGS( wxRadioBoxStyle )
47
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)
57
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)
65
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)
75
76 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
77 wxFLAGS_MEMBER(wxRA_HORIZONTAL)
78 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
79 wxFLAGS_MEMBER(wxRA_VERTICAL)
80
81 wxEND_FLAGS( wxRadioBoxStyle )
82
83 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
84
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()
89
90 #else
91 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
92 #endif
93
94 /*
95 selection
96 content
97 label
98 dimension
99 item
100 */
101
102 // ===========================================================================
103 // implementation
104 // ===========================================================================
105
106 // ---------------------------------------------------------------------------
107 // wxRadioBox
108 // ---------------------------------------------------------------------------
109
110 void wxRadioBox::Init()
111 {
112 m_pos = wxPoint(0,0);
113 m_size = wxSize(0,0);
114 }
115
116 unsigned int wxRadioBox::GetCount() const
117 {
118 return m_radios.GetCount();
119 }
120
121 bool wxRadioBox::Create(wxWindow *parent,
122 wxWindowID id,
123 const wxString& title,
124 const wxPoint& pos,
125 const wxSize& size,
126 int n,
127 const wxString choices[],
128 int majorDim,
129 long style,
130 const wxValidator& val,
131 const wxString& name)
132 {
133 // initialize members
134 SetMajorDim(majorDim == 0 ? n : majorDim, style);
135
136 if ( GetMajorDim() == 0 || n == 0 )
137 return false;
138
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;
142
143 // get default size and position for the initial placement
144 m_size = size;
145 m_pos = pos;
146 int minor = n / GetMajorDim();
147 if(n % GetMajorDim() > 0)
148 minor++;
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)
154 m_pos.x=0;
155 if(m_pos.y==wxDefaultCoord)
156 m_pos.y=0;
157
158 m_label = title;
159
160 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
161 return false;
162
163 int i = 0;
164 for ( unsigned int j = 0; j < minor; j++ )
165 {
166 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
167 {
168 if(i<n)
169 {
170 wxPoint start, end;
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();
176 rb->SetGroup( id );
177 rb->Create(
178 this,
179 wxID_ANY,
180 choices[i],
181 start,
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
185 );
186 m_radios.Put(i,rb);
187 i++;
188 }
189 }
190 }
191 }
192
193 bool wxRadioBox::Create(wxWindow *parent,
194 wxWindowID id,
195 const wxString& title,
196 const wxPoint& pos,
197 const wxSize& size,
198 const wxArrayString& choices,
199 int majorDim,
200 long style,
201 const wxValidator& val,
202 const wxString& name)
203 {
204 wxCArrayString chs(choices);
205
206 return Create( parent, id, title, pos, size, chs.GetCount(),
207 chs.GetStrings(), majorDim, style, val, name );
208 }
209
210 wxRadioBox::~wxRadioBox()
211 {
212 }
213
214 wxRadioButton *wxRadioBox::GetRadioButton(int i) const
215 {
216 return (wxRadioButton *)m_radios.Get(i);
217 }
218
219 void wxRadioBox::DoGetPosition( int *x, int *y ) const
220 {
221 *x = m_pos.x;
222 *y = m_pos.y;
223 }
224
225 void wxRadioBox::DoGetSize( int *width, int *height ) const
226 {
227 *width = m_size.x;
228 *height = m_size.y;
229 }
230
231 void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
232 {
233 wxRect oldRect = GetRect();
234
235 m_pos.x = x;
236 m_pos.y = y;
237 m_size.x = width;
238 m_size.y = height;
239
240 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
241
242 const unsigned int n = GetCount();
243 unsigned int minor = n / GetMajorDim();
244 if(n % GetMajorDim() > 0)
245 minor++;
246
247 unsigned int i = 0;
248 for ( unsigned int j = 0; j < minor; j++ )
249 {
250 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
251 {
252 if(i<n)
253 {
254 wxPoint start, end;
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);
260 if(rb)
261 {
262 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
263 }
264 i++;
265 }
266 }
267 }
268
269 // refresh old and new area
270 GetParent()->RefreshRect(oldRect.Union(GetRect()));
271 }
272
273 // get the origin of the client area in the client coordinates
274 wxPoint wxRadioBox::GetClientAreaOrigin() const
275 {
276 return GetPosition();
277 }
278
279 void wxRadioBox::SetString(unsigned int item, const wxString& label)
280 {
281 wxRadioButton *btn = GetRadioButton(item);
282 if(btn)
283 btn->SetLabel(label);
284 }
285
286 void wxRadioBox::SetSelection(int N)
287 {
288 }
289
290 // Get single selection, for single choice list items
291 int wxRadioBox::GetSelection() const
292 {
293 return 0;
294 }
295
296 // Find string for position
297 wxString wxRadioBox::GetString(unsigned int item) const
298 {
299 wxRadioButton *btn = GetRadioButton(item);
300 if(btn)
301 return btn->GetLabel();
302 return wxEmptyString;
303 }
304
305 // ----------------------------------------------------------------------------
306 // size calculations
307 // ----------------------------------------------------------------------------
308
309 wxSize wxRadioBox::GetMaxButtonSize() const
310 {
311 return wxSize(0,0);
312 }
313
314 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
315 {
316 return wxSize(0,0);
317 }
318
319 wxSize wxRadioBox::DoGetBestSize() const
320 {
321 return wxSize(0,0);
322 }
323
324 void wxRadioBox::SetFocus()
325 {
326 }
327
328 // Enable all subcontrols
329 bool wxRadioBox::Enable(bool enable)
330 {
331 for(unsigned int i=0; i<GetCount(); i++)
332 Enable(i, enable);
333 return true;
334 }
335
336 // Enable a specific button
337 bool wxRadioBox::Enable(unsigned int item, bool enable)
338 {
339 wxRadioButton *btn = GetRadioButton(item);
340 if(btn)
341 return btn->Enable(enable);
342 return false;
343 }
344
345 bool wxRadioBox::Show(bool show)
346 {
347 for(unsigned int i=0; i<GetCount(); i++)
348 Show(i, show);
349 return true;
350 }
351
352 // Show a specific button
353 bool wxRadioBox::Show(unsigned int item, bool show)
354 {
355 wxRadioButton *btn = GetRadioButton(item);
356 if(btn)
357 {
358 bool ret = btn->Show(show);
359 RefreshRect(btn->GetRect());
360 return ret;
361 }
362 return false;
363 }
364
365 wxString wxRadioBox::GetLabel()
366 {
367 return m_label;
368 }
369
370 void wxRadioBox::SetLabel(const wxString& label)
371 {
372 m_label = label;
373 }
374
375 void wxRadioBox::Refresh(bool eraseBack, const wxRect *rect)
376 {
377 wxRect area = GetRect();
378
379 if(rect)
380 {
381 area.Offset(rect->GetPosition());
382 area.SetSize(rect->GetSize());
383 }
384
385 GetParent()->RefreshRect(area);
386 }
387
388 void wxRadioBox::Command(wxCommandEvent & event)
389 {
390 }
391
392 void wxRadioBox::SendNotificationEvent()
393 {
394 }
395
396 bool wxRadioBox::SetFont(const wxFont& font)
397 {
398 return false;
399 }
400
401 #endif // wxUSE_RADIOBOX