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