]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/radiobox.cpp
regenerated after version.bkl changes fixing -compatibility_version for Darwin
[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 #ifndef WX_PRECOMP
30 #include "wx/bitmap.h"
31 #include "wx/brush.h"
32 #include "wx/radiobox.h"
33 #include "wx/settings.h"
34 #include "wx/log.h"
35 #endif
36
37 #if wxUSE_TOOLTIPS
38 #include "wx/tooltip.h"
39 #endif // wxUSE_TOOLTIPS
40
41 #include "wx/radiobut.h"
42
43 // TODO: wxCONSTRUCTOR
44 #if 0 // wxUSE_EXTENDED_RTTI
45 WX_DEFINE_FLAGS( wxRadioBoxStyle )
46
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)
56
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)
64
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)
74
75 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
76 wxFLAGS_MEMBER(wxRA_HORIZONTAL)
77 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
78 wxFLAGS_MEMBER(wxRA_VERTICAL)
79
80 wxEND_FLAGS( wxRadioBoxStyle )
81
82 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
83
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()
88
89 #else
90 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
91 #endif
92
93 /*
94 selection
95 content
96 label
97 dimension
98 item
99 */
100
101 // ===========================================================================
102 // implementation
103 // ===========================================================================
104
105 // ---------------------------------------------------------------------------
106 // wxRadioBox
107 // ---------------------------------------------------------------------------
108
109 void wxRadioBox::Init()
110 {
111 m_pos = wxPoint(0,0);
112 m_size = wxSize(0,0);
113 }
114
115 int wxRadioBox::GetCount() const
116 {
117 return m_radios.GetCount();
118 }
119
120 int wxRadioBox::GetColumnCount() const
121 {
122 return 0;
123 }
124
125 int wxRadioBox::GetRowCount() const
126 {
127 return 0;
128 }
129
130 // returns the number of rows
131 int wxRadioBox::GetNumVer() const
132 {
133 return 0;
134 }
135
136 // returns the number of columns
137 int wxRadioBox::GetNumHor() const
138 {
139 return 0;
140 }
141
142 bool wxRadioBox::Create(wxWindow *parent,
143 wxWindowID id,
144 const wxString& title,
145 const wxPoint& pos,
146 const wxSize& size,
147 int n,
148 const wxString choices[],
149 int majorDim,
150 long style,
151 const wxValidator& val,
152 const wxString& name)
153 {
154 // initialize members
155 m_majorDim = majorDim == 0 ? n : wxMin(majorDim, n);
156 if(m_majorDim==0 || n==0) return false;
157
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;
161
162 // get default size and position for the initial placement
163 m_size = size;
164 m_pos = pos;
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)
172 m_pos.x=0;
173 if(m_pos.y==wxDefaultCoord)
174 m_pos.y=0;
175
176 m_label = title;
177
178 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
179 return false;
180
181 int i = 0;
182 for ( int j = 0; j < minor; j++ )
183 {
184 for ( int k = 0; k < m_majorDim; k++ )
185 {
186 if(i<n)
187 {
188 wxPoint start, end;
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();
194 rb->SetGroup( id );
195 rb->Create(
196 this,
197 wxID_ANY,
198 choices[i],
199 start,
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
203 );
204 m_radios.Put(i,rb);
205 i++;
206 }
207 }
208 }
209 }
210
211 bool wxRadioBox::Create(wxWindow *parent,
212 wxWindowID id,
213 const wxString& title,
214 const wxPoint& pos,
215 const wxSize& size,
216 const wxArrayString& choices,
217 int majorDim,
218 long style,
219 const wxValidator& val,
220 const wxString& name)
221 {
222 wxCArrayString chs(choices);
223
224 return Create( parent, id, title, pos, size, chs.GetCount(),
225 chs.GetStrings(), majorDim, style, val, name );
226 }
227
228 wxRadioBox::~wxRadioBox()
229 {
230 }
231
232 wxRadioButton *wxRadioBox::GetRadioButton(int i) const
233 {
234 return (wxRadioButton *)m_radios.Get(i);
235 }
236
237 void wxRadioBox::DoGetPosition( int *x, int *y ) const
238 {
239 *x = m_pos.x;
240 *y = m_pos.y;
241 }
242
243 void wxRadioBox::DoGetSize( int *width, int *height ) const
244 {
245 *width = m_size.x;
246 *height = m_size.y;
247 }
248
249 void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
250 {
251 wxRect oldRect = GetRect();
252
253 m_pos.x = x;
254 m_pos.y = y;
255 m_size.x = width;
256 m_size.y = height;
257
258 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
259
260 const int n = GetCount();
261 int minor = n / m_majorDim;
262 if(n % m_majorDim > 0) minor++;
263
264 int i = 0;
265 for ( int j = 0; j < minor; j++ )
266 {
267 for ( int k = 0; k < m_majorDim; k++ )
268 {
269 if(i<n)
270 {
271 wxPoint start, end;
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);
277 if(rb)
278 {
279 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
280 }
281 i++;
282 }
283 }
284 }
285
286 // refresh old and new area
287 GetParent()->RefreshRect(oldRect.Union(GetRect()));
288 }
289
290 // get the origin of the client area in the client coordinates
291 wxPoint wxRadioBox::GetClientAreaOrigin() const
292 {
293 return GetPosition();
294 }
295
296 void wxRadioBox::SetString(int item, const wxString& label)
297 {
298 wxRadioButton *btn = GetRadioButton(item);
299 if(btn)
300 btn->SetLabel(label);
301 }
302
303 void wxRadioBox::SetSelection(int N)
304 {
305 }
306
307 // Get single selection, for single choice list items
308 int wxRadioBox::GetSelection() const
309 {
310 return 0;
311 }
312
313 // Find string for position
314 wxString wxRadioBox::GetString(int item) const
315 {
316 wxRadioButton *btn = GetRadioButton(item);
317 if(btn)
318 return btn->GetLabel();
319 return wxEmptyString;
320 }
321
322 // ----------------------------------------------------------------------------
323 // size calculations
324 // ----------------------------------------------------------------------------
325
326 wxSize wxRadioBox::GetMaxButtonSize() const
327 {
328 return wxSize(0,0);
329 }
330
331 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
332 {
333 return wxSize(0,0);
334 }
335
336 wxSize wxRadioBox::DoGetBestSize() const
337 {
338 return wxSize(0,0);
339 }
340
341 void wxRadioBox::SetFocus()
342 {
343 }
344
345 // Enable all subcontrols
346 bool wxRadioBox::Enable(bool enable)
347 {
348 for(int i=0; i<GetCount(); i++)
349 Enable(i, enable);
350 return true;
351 }
352
353 // Enable a specific button
354 bool wxRadioBox::Enable(int item, bool enable)
355 {
356 wxRadioButton *btn = GetRadioButton(item);
357 if(btn)
358 return btn->Enable(enable);
359 return false;
360 }
361
362 bool wxRadioBox::Show(bool show)
363 {
364 for(int i=0; i<GetCount(); i++)
365 Show(i, show);
366 return true;
367 }
368
369 // Show a specific button
370 bool wxRadioBox::Show(int item, bool show)
371 {
372 wxRadioButton *btn = GetRadioButton(item);
373 if(btn)
374 {
375 bool ret = btn->Show(show);
376 RefreshRect(btn->GetRect());
377 return ret;
378 }
379 return false;
380 }
381
382 wxString wxRadioBox::GetLabel()
383 {
384 return m_label;
385 }
386
387 void wxRadioBox::SetLabel(const wxString& label)
388 {
389 m_label = label;
390 }
391
392 void wxRadioBox::Refresh(bool eraseBack, const wxRect *rect)
393 {
394 wxRect area = GetRect();
395
396 if(rect)
397 {
398 area.Offset(rect->GetPosition());
399 area.SetSize(rect->GetSize());
400 }
401
402 GetParent()->RefreshRect(area);
403 }
404
405 void wxRadioBox::Command(wxCommandEvent & event)
406 {
407 }
408
409 void wxRadioBox::SendNotificationEvent()
410 {
411 }
412
413 bool wxRadioBox::SetFont(const wxFont& font)
414 {
415 return false;
416 }
417
418 #endif // wxUSE_RADIOBOX