]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/radiobox.cpp
compilation fix for !WX_PRECOMP (missing wx/app.h)
[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
cc11cc69
WS
29#include "wx/radiobox.h"
30
ffecfa5a
JS
31#ifndef WX_PRECOMP
32 #include "wx/bitmap.h"
33 #include "wx/brush.h"
ffecfa5a
JS
34 #include "wx/settings.h"
35 #include "wx/log.h"
b0b5881a 36 #include "wx/radiobut.h"
ffecfa5a
JS
37#endif
38
ffecfa5a
JS
39#if wxUSE_TOOLTIPS
40 #include "wx/tooltip.h"
41#endif // wxUSE_TOOLTIPS
42
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
aa61d352 115unsigned int wxRadioBox::GetCount() const
ffecfa5a 116{
1a87edf2 117 return m_radios.GetCount();
ffecfa5a
JS
118}
119
ffecfa5a
JS
120bool 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{
8be10866 132 // initialize members
21e0a4d5
VZ
133 SetMajorDim(majorDim == 0 ? n : majorDim, style);
134
135 if ( GetMajorDim() == 0 || n == 0 )
136 return false;
1a87edf2
WS
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;
21e0a4d5
VZ
145 int minor = n / GetMajorDim();
146 if(n % GetMajorDim() > 0)
147 minor++;
1a87edf2 148 if(m_size.x==wxDefaultCoord)
21e0a4d5 149 m_size.x=36*(use_cols?GetMajorDim():minor);
1a87edf2 150 if(m_size.y==wxDefaultCoord)
21e0a4d5 151 m_size.y=12*(use_cols?minor:GetMajorDim());
1a87edf2
WS
152 if(m_pos.x==wxDefaultCoord)
153 m_pos.x=0;
154 if(m_pos.y==wxDefaultCoord)
155 m_pos.y=0;
156
11f4a344
WS
157 m_label = title;
158
1a87edf2 159 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
8be10866
WS
160 return false;
161
1a87edf2 162 int i = 0;
aa61d352 163 for ( unsigned int j = 0; j < minor; j++ )
8be10866 164 {
aa61d352 165 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
1a87edf2
WS
166 {
167 if(i<n)
168 {
169 wxPoint start, end;
21e0a4d5
VZ
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());
1a87edf2
WS
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 }
8be10866 189 }
ffecfa5a
JS
190}
191
192bool 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{
8be10866
WS
203 wxCArrayString chs(choices);
204
205 return Create( parent, id, title, pos, size, chs.GetCount(),
206 chs.GetStrings(), majorDim, style, val, name );
ffecfa5a
JS
207}
208
209wxRadioBox::~wxRadioBox()
210{
211}
212
17fb3524 213wxRadioButton *wxRadioBox::GetRadioButton(int i) const
1a87edf2
WS
214{
215 return (wxRadioButton *)m_radios.Get(i);
216}
217
218void wxRadioBox::DoGetPosition( int *x, int *y ) const
219{
220 *x = m_pos.x;
221 *y = m_pos.y;
222}
223
224void wxRadioBox::DoGetSize( int *width, int *height ) const
225{
226 *width = m_size.x;
227 *height = m_size.y;
228}
229
230void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
231{
17fb3524
WS
232 wxRect oldRect = GetRect();
233
d2893292
WS
234 m_pos.x = x;
235 m_pos.y = y;
1a87edf2
WS
236 m_size.x = width;
237 m_size.y = height;
238
239 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
240
aa61d352
VZ
241 const unsigned int n = GetCount();
242 unsigned int minor = n / GetMajorDim();
21e0a4d5
VZ
243 if(n % GetMajorDim() > 0)
244 minor++;
1a87edf2 245
aa61d352
VZ
246 unsigned int i = 0;
247 for ( unsigned int j = 0; j < minor; j++ )
1a87edf2 248 {
aa61d352 249 for ( unsigned int k = 0; k < GetMajorDim(); k++ )
1a87edf2
WS
250 {
251 if(i<n)
252 {
253 wxPoint start, end;
21e0a4d5
VZ
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());
1a87edf2
WS
258 wxRadioButton* rb = GetRadioButton(i);
259 if(rb)
11f4a344
WS
260 {
261 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
262 }
1a87edf2
WS
263 i++;
264 }
265 }
266 }
17fb3524
WS
267
268 // refresh old and new area
269 GetParent()->RefreshRect(oldRect.Union(GetRect()));
1a87edf2
WS
270}
271
272// get the origin of the client area in the client coordinates
273wxPoint wxRadioBox::GetClientAreaOrigin() const
274{
d2893292 275 return GetPosition();
1a87edf2
WS
276}
277
aa61d352 278void wxRadioBox::SetString(unsigned int item, const wxString& label)
ffecfa5a 279{
17fb3524
WS
280 wxRadioButton *btn = GetRadioButton(item);
281 if(btn)
282 btn->SetLabel(label);
ffecfa5a
JS
283}
284
285void wxRadioBox::SetSelection(int N)
286{
287}
288
289// Get single selection, for single choice list items
290int wxRadioBox::GetSelection() const
291{
292 return 0;
293}
294
295// Find string for position
aa61d352 296wxString wxRadioBox::GetString(unsigned int item) const
ffecfa5a 297{
17fb3524
WS
298 wxRadioButton *btn = GetRadioButton(item);
299 if(btn)
300 return btn->GetLabel();
301 return wxEmptyString;
ffecfa5a
JS
302}
303
304// ----------------------------------------------------------------------------
305// size calculations
306// ----------------------------------------------------------------------------
307
308wxSize wxRadioBox::GetMaxButtonSize() const
309{
310 return wxSize(0,0);
311}
312
313wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
314{
315 return wxSize(0,0);
316}
317
318wxSize wxRadioBox::DoGetBestSize() const
319{
320 return wxSize(0,0);
321}
322
ffecfa5a
JS
323void wxRadioBox::SetFocus()
324{
325}
326
11f4a344
WS
327// Enable all subcontrols
328bool wxRadioBox::Enable(bool enable)
ffecfa5a 329{
aa61d352
VZ
330 for(unsigned int i=0; i<GetCount(); i++)
331 Enable(i, enable);
11f4a344 332 return true;
ffecfa5a
JS
333}
334
335// Enable a specific button
aa61d352 336bool wxRadioBox::Enable(unsigned int item, bool enable)
ffecfa5a 337{
1a87edf2
WS
338 wxRadioButton *btn = GetRadioButton(item);
339 if(btn)
340 return btn->Enable(enable);
341 return false;
ffecfa5a
JS
342}
343
11f4a344 344bool wxRadioBox::Show(bool show)
ffecfa5a 345{
aa61d352
VZ
346 for(unsigned int i=0; i<GetCount(); i++)
347 Show(i, show);
17fb3524 348 return true;
ffecfa5a
JS
349}
350
351// Show a specific button
aa61d352 352bool wxRadioBox::Show(unsigned int item, bool show)
ffecfa5a 353{
17fb3524
WS
354 wxRadioButton *btn = GetRadioButton(item);
355 if(btn)
356 {
357 bool ret = btn->Show(show);
358 RefreshRect(btn->GetRect());
359 return ret;
360 }
fa50c0e3 361 return false;
ffecfa5a
JS
362}
363
11f4a344
WS
364wxString wxRadioBox::GetLabel()
365{
366 return m_label;
367}
368
369void wxRadioBox::SetLabel(const wxString& label)
370{
371 m_label = label;
372}
373
374void 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
17fb3524 384 GetParent()->RefreshRect(area);
11f4a344
WS
385}
386
ffecfa5a
JS
387void wxRadioBox::Command(wxCommandEvent & event)
388{
389}
390
ffecfa5a
JS
391void wxRadioBox::SendNotificationEvent()
392{
393}
394
395bool wxRadioBox::SetFont(const wxFont& font)
396{
397 return false;
398}
399
ffecfa5a 400#endif // wxUSE_RADIOBOX