]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/radiobox.cpp
Consistent wxWindow::Enable with wxRadioBox::Enable for control and its items. wxRadi...
[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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "radiobox.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #if wxUSE_RADIOBOX
32
33 #ifndef WX_PRECOMP
34 #include "wx/bitmap.h"
35 #include "wx/brush.h"
36 #include "wx/radiobox.h"
37 #include "wx/settings.h"
38 #include "wx/log.h"
39 #endif
40
41 #if wxUSE_TOOLTIPS
42 #include "wx/tooltip.h"
43 #endif // wxUSE_TOOLTIPS
44
45 #include "wx/radiobut.h"
46
47 // TODO: wxCONSTRUCTOR
48 #if 0 // wxUSE_EXTENDED_RTTI
49 WX_DEFINE_FLAGS( wxRadioBoxStyle )
50
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)
60
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)
68
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)
78
79 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS)
80 wxFLAGS_MEMBER(wxRA_HORIZONTAL)
81 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS)
82 wxFLAGS_MEMBER(wxRA_VERTICAL)
83
84 wxEND_FLAGS( wxRadioBoxStyle )
85
86 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
87
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()
92
93 #else
94 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
95 #endif
96
97 /*
98 selection
99 content
100 label
101 dimension
102 item
103 */
104
105 // ===========================================================================
106 // implementation
107 // ===========================================================================
108
109 // ---------------------------------------------------------------------------
110 // wxRadioBox
111 // ---------------------------------------------------------------------------
112
113 void wxRadioBox::Init()
114 {
115 m_pos = wxPoint(0,0);
116 m_size = wxSize(0,0);
117 }
118
119 int wxRadioBox::GetCount() const
120 {
121 return m_radios.GetCount();
122 }
123
124 int wxRadioBox::GetColumnCount() const
125 {
126 return 0;
127 }
128
129 int wxRadioBox::GetRowCount() const
130 {
131 return 0;
132 }
133
134 // returns the number of rows
135 int wxRadioBox::GetNumVer() const
136 {
137 return 0;
138 }
139
140 // returns the number of columns
141 int wxRadioBox::GetNumHor() const
142 {
143 return 0;
144 }
145
146 bool wxRadioBox::Create(wxWindow *parent,
147 wxWindowID id,
148 const wxString& title,
149 const wxPoint& pos,
150 const wxSize& size,
151 int n,
152 const wxString choices[],
153 int majorDim,
154 long style,
155 const wxValidator& val,
156 const wxString& name)
157 {
158 // initialize members
159 m_majorDim = majorDim == 0 ? n : wxMin(majorDim, n);
160 if(m_majorDim==0 || n==0) return false;
161
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;
165
166 // get default size and position for the initial placement
167 m_size = size;
168 m_pos = pos;
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)
176 m_pos.x=0;
177 if(m_pos.y==wxDefaultCoord)
178 m_pos.y=0;
179
180 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
181 return false;
182
183 int i = 0;
184 for ( int j = 0; j < minor; j++ )
185 {
186 for ( int k = 0; k < m_majorDim; k++ )
187 {
188 if(i<n)
189 {
190 wxPoint start, end;
191 start.x = (use_cols ? (k*m_size.x)/m_majorDim : (j*m_size.x)/minor);
192 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/m_majorDim);
193 end.x = (use_cols ? ((k+1)*m_size.x)/m_majorDim : ((j+1)*m_size.x)/minor);
194 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/m_majorDim);
195 wxRadioButton* rb = new wxRadioButton();
196 rb->SetGroup( id );
197 rb->Create(
198 this,
199 wxID_ANY,
200 choices[i],
201 start,
202 wxSize(end.x-start.x-1,end.y-start.y-1),
203 ( n == 0 ? wxRB_GROUP : 0 ) |
204 use_checkbox ? wxRB_USE_CHECKBOX : 0
205 );
206 m_radios.Put(i,rb);
207 i++;
208 }
209 }
210 }
211 }
212
213 bool wxRadioBox::Create(wxWindow *parent,
214 wxWindowID id,
215 const wxString& title,
216 const wxPoint& pos,
217 const wxSize& size,
218 const wxArrayString& choices,
219 int majorDim,
220 long style,
221 const wxValidator& val,
222 const wxString& name)
223 {
224 wxCArrayString chs(choices);
225
226 return Create( parent, id, title, pos, size, chs.GetCount(),
227 chs.GetStrings(), majorDim, style, val, name );
228 }
229
230 wxRadioBox::~wxRadioBox()
231 {
232 }
233
234 wxRadioButton *wxRadioBox::GetRadioButton(int i)
235 {
236 return (wxRadioButton *)m_radios.Get(i);
237 }
238
239 void wxRadioBox::DoGetPosition( int *x, int *y ) const
240 {
241 *x = m_pos.x;
242 *y = m_pos.y;
243 }
244
245 void wxRadioBox::DoGetSize( int *width, int *height ) const
246 {
247 *width = m_size.x;
248 *height = m_size.y;
249 }
250
251 void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
252 {
253 m_size.x = width;
254 m_size.y = height;
255
256 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
257
258 const int n = GetCount();
259 int minor = n / m_majorDim;
260 if(n % m_majorDim > 0) minor++;
261
262 int i = 0;
263 for ( int j = 0; j < minor; j++ )
264 {
265 for ( int k = 0; k < m_majorDim; k++ )
266 {
267 if(i<n)
268 {
269 wxPoint start, end;
270 start.x = (use_cols ? (k*m_size.x)/m_majorDim : (j*m_size.x)/minor);
271 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/m_majorDim);
272 end.x = (use_cols ? ((k+1)*m_size.x)/m_majorDim : ((j+1)*m_size.x)/minor);
273 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/m_majorDim);
274 wxRadioButton* rb = GetRadioButton(i);
275 if(rb)
276 rb->SetSize(end.x-start.x-1,end.y-start.y-1);
277 i++;
278 }
279 }
280 }
281 }
282
283 // get the origin of the client area in the client coordinates
284 wxPoint wxRadioBox::GetClientAreaOrigin() const
285 {
286 return GetParent()->GetClientAreaOrigin() + GetPosition();
287 }
288
289 void wxRadioBox::SetString(int item, const wxString& label)
290 {
291 }
292
293 void wxRadioBox::SetSelection(int N)
294 {
295 }
296
297 // Get single selection, for single choice list items
298 int wxRadioBox::GetSelection() const
299 {
300 return 0;
301 }
302
303 // Find string for position
304 wxString wxRadioBox::GetString(int item) const
305 {
306 wxString ret;
307
308 return ret;
309 }
310
311 // ----------------------------------------------------------------------------
312 // size calculations
313 // ----------------------------------------------------------------------------
314
315 wxSize wxRadioBox::GetMaxButtonSize() const
316 {
317 return wxSize(0,0);
318 }
319
320 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
321 {
322 return wxSize(0,0);
323 }
324
325 wxSize wxRadioBox::DoGetBestSize() const
326 {
327 return wxSize(0,0);
328 }
329
330 void wxRadioBox::SetFocus()
331 {
332 }
333
334 bool wxRadioBox::Show(bool show)
335 {
336 return false;
337 }
338
339 // Enable a specific button
340 bool wxRadioBox::Enable(int item, bool enable)
341 {
342 wxRadioButton *btn = GetRadioButton(item);
343 if(btn)
344 return btn->Enable(enable);
345 return false;
346 }
347
348 // Enable all subcontrols
349 bool wxRadioBox::Enable(bool enable)
350 {
351 for(int i=0; i<GetCount(); i++)
352 Enable(i, enable);
353 return true;
354 }
355
356 // Show a specific button
357 void wxRadioBox::Show(int item, bool show)
358 {
359 }
360
361 void wxRadioBox::Command(wxCommandEvent & event)
362 {
363 }
364
365 void wxRadioBox::SendNotificationEvent()
366 {
367 }
368
369 bool wxRadioBox::SetFont(const wxFont& font)
370 {
371 return false;
372 }
373
374 #endif // wxUSE_RADIOBOX