]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/radiobox.cpp
added wxIsSameDouble() which wraps double comparison in a pragmas disabling icc warni...
[wxWidgets.git] / src / palmos / radiobox.cpp
CommitLineData
ffecfa5a 1/////////////////////////////////////////////////////////////////////////////
e2731512 2// Name: src/palmos/radiobox.cpp
ffecfa5a 3// Purpose: wxRadioBox implementation
e2731512 4// Author: William Osborne - minimal working wxPalmOS port
a152561c 5// Modified by: Wlodzimierz ABX Skiba - native wxRadioBox implementation
ffecfa5a 6// Created: 10/13/04
e2731512 7// RCS-ID: $Id$
a152561c 8// Copyright: (c) William Osborne, Wlodzimierz Skiba
ffecfa5a
JS
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
ffecfa5a
JS
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
ffecfa5a
JS
37#if wxUSE_TOOLTIPS
38 #include "wx/tooltip.h"
39#endif // wxUSE_TOOLTIPS
40
8be10866
WS
41#include "wx/radiobut.h"
42
ffecfa5a
JS
43// TODO: wxCONSTRUCTOR
44#if 0 // wxUSE_EXTENDED_RTTI
45WX_DEFINE_FLAGS( wxRadioBoxStyle )
46
47wxBEGIN_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)
e2731512 56
ffecfa5a
JS
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
80wxEND_FLAGS( wxRadioBoxStyle )
81
82IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
83
84wxBEGIN_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
87wxEND_PROPERTIES_TABLE()
88
89#else
90IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
91#endif
92
93/*
94 selection
95 content
96 label
97 dimension
98 item
99*/
100
ffecfa5a
JS
101// ===========================================================================
102// implementation
103// ===========================================================================
104
105// ---------------------------------------------------------------------------
106// wxRadioBox
107// ---------------------------------------------------------------------------
108
1a87edf2
WS
109void wxRadioBox::Init()
110{
111 m_pos = wxPoint(0,0);
112 m_size = wxSize(0,0);
113}
114
ffecfa5a
JS
115int wxRadioBox::GetCount() const
116{
1a87edf2 117 return m_radios.GetCount();
ffecfa5a
JS
118}
119
120int wxRadioBox::GetColumnCount() const
121{
122 return 0;
123}
124
125int wxRadioBox::GetRowCount() const
126{
127 return 0;
128}
129
130// returns the number of rows
131int wxRadioBox::GetNumVer() const
132{
133 return 0;
134}
135
136// returns the number of columns
137int wxRadioBox::GetNumHor() const
138{
139 return 0;
140}
141
ffecfa5a
JS
142bool 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{
8be10866 154 // initialize members
1a87edf2
WS
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
11f4a344
WS
176 m_label = title;
177
1a87edf2 178 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
8be10866
WS
179 return false;
180
1a87edf2
WS
181 int i = 0;
182 for ( int j = 0; j < minor; j++ )
8be10866 183 {
1a87edf2
WS
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 }
8be10866 208 }
ffecfa5a
JS
209}
210
211bool 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{
8be10866
WS
222 wxCArrayString chs(choices);
223
224 return Create( parent, id, title, pos, size, chs.GetCount(),
225 chs.GetStrings(), majorDim, style, val, name );
ffecfa5a
JS
226}
227
228wxRadioBox::~wxRadioBox()
229{
230}
231
17fb3524 232wxRadioButton *wxRadioBox::GetRadioButton(int i) const
1a87edf2
WS
233{
234 return (wxRadioButton *)m_radios.Get(i);
235}
236
237void wxRadioBox::DoGetPosition( int *x, int *y ) const
238{
239 *x = m_pos.x;
240 *y = m_pos.y;
241}
242
243void wxRadioBox::DoGetSize( int *width, int *height ) const
244{
245 *width = m_size.x;
246 *height = m_size.y;
247}
248
249void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
250{
17fb3524
WS
251 wxRect oldRect = GetRect();
252
d2893292
WS
253 m_pos.x = x;
254 m_pos.y = y;
1a87edf2
WS
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)
11f4a344
WS
278 {
279 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
280 }
1a87edf2
WS
281 i++;
282 }
283 }
284 }
17fb3524
WS
285
286 // refresh old and new area
287 GetParent()->RefreshRect(oldRect.Union(GetRect()));
1a87edf2
WS
288}
289
290// get the origin of the client area in the client coordinates
291wxPoint wxRadioBox::GetClientAreaOrigin() const
292{
d2893292 293 return GetPosition();
1a87edf2
WS
294}
295
ffecfa5a
JS
296void wxRadioBox::SetString(int item, const wxString& label)
297{
17fb3524
WS
298 wxRadioButton *btn = GetRadioButton(item);
299 if(btn)
300 btn->SetLabel(label);
ffecfa5a
JS
301}
302
303void wxRadioBox::SetSelection(int N)
304{
305}
306
307// Get single selection, for single choice list items
308int wxRadioBox::GetSelection() const
309{
310 return 0;
311}
312
313// Find string for position
314wxString wxRadioBox::GetString(int item) const
315{
17fb3524
WS
316 wxRadioButton *btn = GetRadioButton(item);
317 if(btn)
318 return btn->GetLabel();
319 return wxEmptyString;
ffecfa5a
JS
320}
321
322// ----------------------------------------------------------------------------
323// size calculations
324// ----------------------------------------------------------------------------
325
326wxSize wxRadioBox::GetMaxButtonSize() const
327{
328 return wxSize(0,0);
329}
330
331wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
332{
333 return wxSize(0,0);
334}
335
336wxSize wxRadioBox::DoGetBestSize() const
337{
338 return wxSize(0,0);
339}
340
ffecfa5a
JS
341void wxRadioBox::SetFocus()
342{
343}
344
11f4a344
WS
345// Enable all subcontrols
346bool wxRadioBox::Enable(bool enable)
ffecfa5a 347{
11f4a344
WS
348 for(int i=0; i<GetCount(); i++)
349 Enable(i, enable);
350 return true;
ffecfa5a
JS
351}
352
353// Enable a specific button
1a87edf2 354bool wxRadioBox::Enable(int item, bool enable)
ffecfa5a 355{
1a87edf2
WS
356 wxRadioButton *btn = GetRadioButton(item);
357 if(btn)
358 return btn->Enable(enable);
359 return false;
ffecfa5a
JS
360}
361
11f4a344 362bool wxRadioBox::Show(bool show)
ffecfa5a 363{
17fb3524
WS
364 for(int i=0; i<GetCount(); i++)
365 Show(i, show);
366 return true;
ffecfa5a
JS
367}
368
369// Show a specific button
fa50c0e3 370bool wxRadioBox::Show(int item, bool show)
ffecfa5a 371{
17fb3524
WS
372 wxRadioButton *btn = GetRadioButton(item);
373 if(btn)
374 {
375 bool ret = btn->Show(show);
376 RefreshRect(btn->GetRect());
377 return ret;
378 }
fa50c0e3 379 return false;
ffecfa5a
JS
380}
381
11f4a344
WS
382wxString wxRadioBox::GetLabel()
383{
384 return m_label;
385}
386
387void wxRadioBox::SetLabel(const wxString& label)
388{
389 m_label = label;
390}
391
392void 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
17fb3524 402 GetParent()->RefreshRect(area);
11f4a344
WS
403}
404
ffecfa5a
JS
405void wxRadioBox::Command(wxCommandEvent & event)
406{
407}
408
ffecfa5a
JS
409void wxRadioBox::SendNotificationEvent()
410{
411}
412
413bool wxRadioBox::SetFont(const wxFont& font)
414{
415 return false;
416}
417
ffecfa5a 418#endif // wxUSE_RADIOBOX