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