]> git.saurik.com Git - wxWidgets.git/blame - src/palmos/radiobox.cpp
Bump subrelease number
[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
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
ffecfa5a
JS
41#if wxUSE_TOOLTIPS
42 #include "wx/tooltip.h"
43#endif // wxUSE_TOOLTIPS
44
8be10866
WS
45#include "wx/radiobut.h"
46
ffecfa5a
JS
47// TODO: wxCONSTRUCTOR
48#if 0 // wxUSE_EXTENDED_RTTI
49WX_DEFINE_FLAGS( wxRadioBoxStyle )
50
51wxBEGIN_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)
e2731512 60
ffecfa5a
JS
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
84wxEND_FLAGS( wxRadioBoxStyle )
85
86IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
87
88wxBEGIN_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
91wxEND_PROPERTIES_TABLE()
92
93#else
94IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
95#endif
96
97/*
98 selection
99 content
100 label
101 dimension
102 item
103*/
104
ffecfa5a
JS
105// ===========================================================================
106// implementation
107// ===========================================================================
108
109// ---------------------------------------------------------------------------
110// wxRadioBox
111// ---------------------------------------------------------------------------
112
1a87edf2
WS
113void wxRadioBox::Init()
114{
115 m_pos = wxPoint(0,0);
116 m_size = wxSize(0,0);
117}
118
ffecfa5a
JS
119int wxRadioBox::GetCount() const
120{
1a87edf2 121 return m_radios.GetCount();
ffecfa5a
JS
122}
123
124int wxRadioBox::GetColumnCount() const
125{
126 return 0;
127}
128
129int wxRadioBox::GetRowCount() const
130{
131 return 0;
132}
133
134// returns the number of rows
135int wxRadioBox::GetNumVer() const
136{
137 return 0;
138}
139
140// returns the number of columns
141int wxRadioBox::GetNumHor() const
142{
143 return 0;
144}
145
ffecfa5a
JS
146bool 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{
8be10866 158 // initialize members
1a87edf2
WS
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
11f4a344
WS
180 m_label = title;
181
1a87edf2 182 if(!wxControl::Create(parent, id, m_pos, m_size, style, val, name))
8be10866
WS
183 return false;
184
1a87edf2
WS
185 int i = 0;
186 for ( int j = 0; j < minor; j++ )
8be10866 187 {
1a87edf2
WS
188 for ( int k = 0; k < m_majorDim; k++ )
189 {
190 if(i<n)
191 {
192 wxPoint start, end;
193 start.x = (use_cols ? (k*m_size.x)/m_majorDim : (j*m_size.x)/minor);
194 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/m_majorDim);
195 end.x = (use_cols ? ((k+1)*m_size.x)/m_majorDim : ((j+1)*m_size.x)/minor);
196 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/m_majorDim);
197 wxRadioButton* rb = new wxRadioButton();
198 rb->SetGroup( id );
199 rb->Create(
200 this,
201 wxID_ANY,
202 choices[i],
203 start,
204 wxSize(end.x-start.x-1,end.y-start.y-1),
205 ( n == 0 ? wxRB_GROUP : 0 ) |
206 use_checkbox ? wxRB_USE_CHECKBOX : 0
207 );
208 m_radios.Put(i,rb);
209 i++;
210 }
211 }
8be10866 212 }
ffecfa5a
JS
213}
214
215bool wxRadioBox::Create(wxWindow *parent,
216 wxWindowID id,
217 const wxString& title,
218 const wxPoint& pos,
219 const wxSize& size,
220 const wxArrayString& choices,
221 int majorDim,
222 long style,
223 const wxValidator& val,
224 const wxString& name)
225{
8be10866
WS
226 wxCArrayString chs(choices);
227
228 return Create( parent, id, title, pos, size, chs.GetCount(),
229 chs.GetStrings(), majorDim, style, val, name );
ffecfa5a
JS
230}
231
232wxRadioBox::~wxRadioBox()
233{
234}
235
17fb3524 236wxRadioButton *wxRadioBox::GetRadioButton(int i) const
1a87edf2
WS
237{
238 return (wxRadioButton *)m_radios.Get(i);
239}
240
241void wxRadioBox::DoGetPosition( int *x, int *y ) const
242{
243 *x = m_pos.x;
244 *y = m_pos.y;
245}
246
247void wxRadioBox::DoGetSize( int *width, int *height ) const
248{
249 *width = m_size.x;
250 *height = m_size.y;
251}
252
253void wxRadioBox::DoMoveWindow(int x, int y, int width, int height)
254{
17fb3524
WS
255 wxRect oldRect = GetRect();
256
d2893292
WS
257 m_pos.x = x;
258 m_pos.y = y;
1a87edf2
WS
259 m_size.x = width;
260 m_size.y = height;
261
262 const bool use_cols = HasFlag(wxRA_SPECIFY_COLS);
263
264 const int n = GetCount();
265 int minor = n / m_majorDim;
266 if(n % m_majorDim > 0) minor++;
267
268 int i = 0;
269 for ( int j = 0; j < minor; j++ )
270 {
271 for ( int k = 0; k < m_majorDim; k++ )
272 {
273 if(i<n)
274 {
275 wxPoint start, end;
276 start.x = (use_cols ? (k*m_size.x)/m_majorDim : (j*m_size.x)/minor);
277 start.y = (use_cols ? (j*m_size.y)/minor : (k*m_size.y)/m_majorDim);
278 end.x = (use_cols ? ((k+1)*m_size.x)/m_majorDim : ((j+1)*m_size.x)/minor);
279 end.y = (use_cols ? ((j+1)*m_size.y)/minor : ((k+1)*m_size.y)/m_majorDim);
280 wxRadioButton* rb = GetRadioButton(i);
281 if(rb)
11f4a344
WS
282 {
283 rb->SetSize(start.x,start.y,end.x-start.x-1,end.y-start.y-1);
284 }
1a87edf2
WS
285 i++;
286 }
287 }
288 }
17fb3524
WS
289
290 // refresh old and new area
291 GetParent()->RefreshRect(oldRect.Union(GetRect()));
1a87edf2
WS
292}
293
294// get the origin of the client area in the client coordinates
295wxPoint wxRadioBox::GetClientAreaOrigin() const
296{
d2893292 297 return GetPosition();
1a87edf2
WS
298}
299
ffecfa5a
JS
300void wxRadioBox::SetString(int item, const wxString& label)
301{
17fb3524
WS
302 wxRadioButton *btn = GetRadioButton(item);
303 if(btn)
304 btn->SetLabel(label);
ffecfa5a
JS
305}
306
307void wxRadioBox::SetSelection(int N)
308{
309}
310
311// Get single selection, for single choice list items
312int wxRadioBox::GetSelection() const
313{
314 return 0;
315}
316
317// Find string for position
318wxString wxRadioBox::GetString(int item) const
319{
17fb3524
WS
320 wxRadioButton *btn = GetRadioButton(item);
321 if(btn)
322 return btn->GetLabel();
323 return wxEmptyString;
ffecfa5a
JS
324}
325
326// ----------------------------------------------------------------------------
327// size calculations
328// ----------------------------------------------------------------------------
329
330wxSize wxRadioBox::GetMaxButtonSize() const
331{
332 return wxSize(0,0);
333}
334
335wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
336{
337 return wxSize(0,0);
338}
339
340wxSize wxRadioBox::DoGetBestSize() const
341{
342 return wxSize(0,0);
343}
344
ffecfa5a
JS
345void wxRadioBox::SetFocus()
346{
347}
348
11f4a344
WS
349// Enable all subcontrols
350bool wxRadioBox::Enable(bool enable)
ffecfa5a 351{
11f4a344
WS
352 for(int i=0; i<GetCount(); i++)
353 Enable(i, enable);
354 return true;
ffecfa5a
JS
355}
356
357// Enable a specific button
1a87edf2 358bool wxRadioBox::Enable(int item, bool enable)
ffecfa5a 359{
1a87edf2
WS
360 wxRadioButton *btn = GetRadioButton(item);
361 if(btn)
362 return btn->Enable(enable);
363 return false;
ffecfa5a
JS
364}
365
11f4a344 366bool wxRadioBox::Show(bool show)
ffecfa5a 367{
17fb3524
WS
368 for(int i=0; i<GetCount(); i++)
369 Show(i, show);
370 return true;
ffecfa5a
JS
371}
372
373// Show a specific button
fa50c0e3 374bool wxRadioBox::Show(int item, bool show)
ffecfa5a 375{
17fb3524
WS
376 wxRadioButton *btn = GetRadioButton(item);
377 if(btn)
378 {
379 bool ret = btn->Show(show);
380 RefreshRect(btn->GetRect());
381 return ret;
382 }
fa50c0e3 383 return false;
ffecfa5a
JS
384}
385
11f4a344
WS
386wxString wxRadioBox::GetLabel()
387{
388 return m_label;
389}
390
391void wxRadioBox::SetLabel(const wxString& label)
392{
393 m_label = label;
394}
395
396void wxRadioBox::Refresh(bool eraseBack, const wxRect *rect)
397{
398 wxRect area = GetRect();
399
400 if(rect)
401 {
402 area.Offset(rect->GetPosition());
403 area.SetSize(rect->GetSize());
404 }
405
17fb3524 406 GetParent()->RefreshRect(area);
11f4a344
WS
407}
408
ffecfa5a
JS
409void wxRadioBox::Command(wxCommandEvent & event)
410{
411}
412
ffecfa5a
JS
413void wxRadioBox::SendNotificationEvent()
414{
415}
416
417bool wxRadioBox::SetFont(const wxFont& font)
418{
419 return false;
420}
421
ffecfa5a 422#endif // wxUSE_RADIOBOX