]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/radiobox.cpp
Use unsigned char for XBM bitmaps data.
[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 #include "wx/radiobut.h"
37 #endif
38
39 #if wxUSE_TOOLTIPS
40 #include "wx/tooltip.h"
41 #endif // wxUSE_TOOLTIPS
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_SPECIFY_ROWS)
77 wxEND_FLAGS( wxRadioBoxStyle )
78
79 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
80
81 wxBEGIN_PROPERTIES_TABLE(wxRadioBox)
82 wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent )
83 wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
84 wxEND_PROPERTIES_TABLE()
85
86 #else
87 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
88 #endif
89
90 /*
91 selection
92 content
93 label
94 dimension
95 item
96 */
97
98 // ===========================================================================
99 // implementation
100 // ===========================================================================
101
102 // ---------------------------------------------------------------------------
103 // wxRadioBox
104 // ---------------------------------------------------------------------------
105
106 void wxRadioBox::Init()
107 {
108 m_pos = wxPoint(0,0);
109 m_size = wxSize(0,0);
110 }
111
112 unsigned int wxRadioBox::GetCount() const
113 {
114 return m_radios.GetCount();
115 }
116
117 bool wxRadioBox::Create(wxWindow *parent,
118 wxWindowID id,
119 const wxString& title,
120 const wxPoint& pos,
121 const wxSize& size,
122 int n,
123 const wxString choices[],
124 int majorDim,
125 long style,
126 const wxValidator& val,
127 const wxString& name)
128 {
129 // initialize members
130 SetMajorDim(majorDim == 0 ? n : majorDim, style);
131
132 if ( GetMajorDim() == 0 || n == 0 )
133 return false;
134
135 // subtype of the native palmOS radio: checkbox or push button?
136 const bool use_checkbox = style & wxRA_USE_CHECKBOX;
137 const bool use_cols = style & wxRA_SPECIFY_COLS;
138
139 // get default size and position for the initial placement
140 m_size = size;
141 m_pos = pos;
142 int minor = n / GetMajorDim();
143 if(n % GetMajorDim() > 0)
144 minor++;
145 if(m_size.x==wxDefaultCoord)
146 m_size.x=36*(use_cols?GetMajorDim():minor);
147 if(m_size.y==wxDefaultCoord)
148 m_size.y=12*(use_cols?minor:GetMajorDim());
149 if(m_pos.x==wxDefaultCoord)
150 m_pos.x=0;
151 if(m_pos.y==wxDefaultCoord)
152 m_pos.y=0;
153
154 m_label = title;
155
156 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
157 return false;
158
159 int i = 0;
160 for ( unsigned int j = 0; j < minor; j++ )
161 {
162 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
163 {
164 if(i<n)
165 {
166 wxPoint start, end;
167 start.x = (use_cols ? (k*m_size.x)/GetMajorDim() : (j*m_size.x)/minor);
168 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/GetMajorDim());
169 end.x = (use_cols ? ((k+1)*m_size.x)/GetMajorDim() : ((j+1)*m_size.x)/minor);
170 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/GetMajorDim());
171 wxRadioButton* rb = new wxRadioButton();
172 rb->SetGroup( id );
173 rb->Create(
174 this,
175 wxID_ANY,
176 choices[i],
177 start,
178 wxSize(end.x-start.x-1,end.y-start.y-1),
179 ( n == 0 ? wxRB_GROUP : 0 ) |
180 use_checkbox ? wxRB_USE_CHECKBOX : 0
181 );
182 m_radios.Put(i,rb);
183 i++;
184 }
185 }
186 }
187 }
188
189 bool wxRadioBox::Create(wxWindow *parent,
190 wxWindowID id,
191 const wxString& title,
192 const wxPoint& pos,
193 const wxSize& size,
194 const wxArrayString& choices,
195 int majorDim,
196 long style,
197 const wxValidator& val,
198 const wxString& name)
199 {
200 wxCArrayString chs(choices);
201
202 return Create( parent, id, title, pos, size, chs.GetCount(),
203 chs.GetStrings(), majorDim, style, val, name );
204 }
205
206 wxRadioBox::~wxRadioBox()
207 {
208 }
209
210 wxRadioButton *wxRadioBox::GetRadioButton(int i) const
211 {
212 return (wxRadioButton *)m_radios.Get(i);
213 }
214
215 void wxRadioBox::DoGetPosition( int *x, int *y ) const
216 {
217 *x = m_pos.x;
218 *y = m_pos.y;
219 }
220
221 void wxRadioBox::DoGetSize( int *width, int *height ) const
222 {
223 *width = m_size.x;
224 *height = m_size.y;
225 }
226
227 void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
228 {
229 wxRect oldRect = GetRect();
230
231 m_pos.x = x;
232 m_pos.y = y;
233 m_size.x = width;
234 m_size.y = height;
235
236 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
237
238 const unsigned int n = GetCount();
239 unsigned int minor = n / GetMajorDim();
240 if(n % GetMajorDim() > 0)
241 minor++;
242
243 unsigned int i = 0;
244 for ( unsigned int j = 0; j < minor; j++ )
245 {
246 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
247 {
248 if(i<n)
249 {
250 wxPoint start, end;
251 start.x = (use_cols ? (k*m_size.x)/GetMajorDim() : (j*m_size.x)/minor);
252 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/GetMajorDim());
253 end.x = (use_cols ? ((k+1)*m_size.x)/GetMajorDim() : ((j+1)*m_size.x)/minor);
254 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/GetMajorDim());
255 wxRadioButton* rb = GetRadioButton(i);
256 if(rb)
257 {
258 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
259 }
260 i++;
261 }
262 }
263 }
264
265 // refresh old and new area
266 GetParent()->RefreshRect(oldRect.Union(GetRect()));
267 }
268
269 // get the origin of the client area in the client coordinates
270 wxPoint wxRadioBox::GetClientAreaOrigin() const
271 {
272 return GetPosition();
273 }
274
275 void wxRadioBox::SetString(unsigned int item, const wxString& label)
276 {
277 wxRadioButton *btn = GetRadioButton(item);
278 if(btn)
279 btn->SetLabel(label);
280 }
281
282 void wxRadioBox::SetSelection(int N)
283 {
284 }
285
286 // Get single selection, for single choice list items
287 int wxRadioBox::GetSelection() const
288 {
289 return 0;
290 }
291
292 // Find string for position
293 wxString wxRadioBox::GetString(unsigned int item) const
294 {
295 wxRadioButton *btn = GetRadioButton(item);
296 if(btn)
297 return btn->GetLabel();
298 return wxEmptyString;
299 }
300
301 // ----------------------------------------------------------------------------
302 // size calculations
303 // ----------------------------------------------------------------------------
304
305 wxSize wxRadioBox::GetMaxButtonSize() const
306 {
307 return wxSize(0,0);
308 }
309
310 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
311 {
312 return wxSize(0,0);
313 }
314
315 wxSize wxRadioBox::DoGetBestSize() const
316 {
317 return wxSize(0,0);
318 }
319
320 void wxRadioBox::SetFocus()
321 {
322 }
323
324 // Enable all subcontrols
325 bool wxRadioBox::Enable(bool enable)
326 {
327 for(unsigned int i=0; i<GetCount(); i++)
328 Enable(i, enable);
329 return true;
330 }
331
332 // Enable a specific button
333 bool wxRadioBox::Enable(unsigned int item, bool enable)
334 {
335 wxRadioButton *btn = GetRadioButton(item);
336 if(btn)
337 return btn->Enable(enable);
338 return false;
339 }
340
341 bool wxRadioBox::Show(bool show)
342 {
343 for(unsigned int i=0; i<GetCount(); i++)
344 Show(i, show);
345 return true;
346 }
347
348 // Show a specific button
349 bool wxRadioBox::Show(unsigned int item, bool show)
350 {
351 wxRadioButton *btn = GetRadioButton(item);
352 if(btn)
353 {
354 bool ret = btn->Show(show);
355 RefreshRect(btn->GetRect());
356 return ret;
357 }
358 return false;
359 }
360
361 wxString wxRadioBox::GetLabel()
362 {
363 return m_label;
364 }
365
366 void wxRadioBox::SetLabel(const wxString& label)
367 {
368 m_label = label;
369 }
370
371 void wxRadioBox::Refresh(bool eraseBack, const wxRect *rect)
372 {
373 wxRect area = GetRect();
374
375 if(rect)
376 {
377 area.Offset(rect->GetPosition());
378 area.SetSize(rect->GetSize());
379 }
380
381 GetParent()->RefreshRect(area);
382 }
383
384 void wxRadioBox::Command(wxCommandEvent & event)
385 {
386 }
387
388 void wxRadioBox::SendNotificationEvent()
389 {
390 }
391
392 bool wxRadioBox::SetFont(const wxFont& font)
393 {
394 return false;
395 }
396
397 #endif // wxUSE_RADIOBOX