]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
3ca6a5f0 BP |
2 | // Name: msw/radiobox.cpp |
3 | // Purpose: wxRadioBox implementation | |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
e373f51b VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
da07e033 | 21 | #pragma implementation "radiobox.h" |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
da07e033 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
1e6feb95 VZ |
31 | #if wxUSE_RADIOBOX |
32 | ||
2bda0e17 | 33 | #ifndef WX_PRECOMP |
da07e033 VZ |
34 | #include "wx/bitmap.h" |
35 | #include "wx/brush.h" | |
36 | #include "wx/radiobox.h" | |
f6bcfd97 | 37 | #include "wx/settings.h" |
381dd4bf | 38 | #include "wx/log.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
bd0a76e2 | 41 | #include "wx/msw/subwin.h" |
2bda0e17 | 42 | |
177895fb JS |
43 | // This is switched off because in some situations, the radiobox |
44 | // buttons simply don't appear when deferred sizing is on. | |
45 | // Instead, refreshing on WM_MOVE seems to at least cure the droppings. | |
46 | #define USE_DEFERRED_SIZING 0 | |
8e44f3ca | 47 | |
f048e32f | 48 | #if wxUSE_TOOLTIPS |
ae090fdb | 49 | #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__) |
8614c467 | 50 | #include <commctrl.h> |
5ace0213 | 51 | #endif |
f048e32f VZ |
52 | #include "wx/tooltip.h" |
53 | #endif // wxUSE_TOOLTIPS | |
54 | ||
3ff066a4 | 55 | // TODO: wxCONSTRUCTOR |
bc9fb572 JS |
56 | #if 0 // wxUSE_EXTENDED_RTTI |
57 | WX_DEFINE_FLAGS( wxRadioBoxStyle ) | |
58 | ||
3ff066a4 | 59 | wxBEGIN_FLAGS( wxRadioBoxStyle ) |
bc9fb572 JS |
60 | // new style border flags, we put them first to |
61 | // use them for streaming out | |
3ff066a4 SC |
62 | wxFLAGS_MEMBER(wxBORDER_SIMPLE) |
63 | wxFLAGS_MEMBER(wxBORDER_SUNKEN) | |
64 | wxFLAGS_MEMBER(wxBORDER_DOUBLE) | |
65 | wxFLAGS_MEMBER(wxBORDER_RAISED) | |
66 | wxFLAGS_MEMBER(wxBORDER_STATIC) | |
67 | wxFLAGS_MEMBER(wxBORDER_NONE) | |
4d08943e | 68 | |
bc9fb572 | 69 | // old style border flags |
3ff066a4 SC |
70 | wxFLAGS_MEMBER(wxSIMPLE_BORDER) |
71 | wxFLAGS_MEMBER(wxSUNKEN_BORDER) | |
72 | wxFLAGS_MEMBER(wxDOUBLE_BORDER) | |
73 | wxFLAGS_MEMBER(wxRAISED_BORDER) | |
74 | wxFLAGS_MEMBER(wxSTATIC_BORDER) | |
cb0afb26 | 75 | wxFLAGS_MEMBER(wxBORDER) |
bc9fb572 JS |
76 | |
77 | // standard window styles | |
3ff066a4 SC |
78 | wxFLAGS_MEMBER(wxTAB_TRAVERSAL) |
79 | wxFLAGS_MEMBER(wxCLIP_CHILDREN) | |
80 | wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW) | |
81 | wxFLAGS_MEMBER(wxWANTS_CHARS) | |
cb0afb26 | 82 | wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE) |
3ff066a4 SC |
83 | wxFLAGS_MEMBER(wxALWAYS_SHOW_SB ) |
84 | wxFLAGS_MEMBER(wxVSCROLL) | |
85 | wxFLAGS_MEMBER(wxHSCROLL) | |
86 | ||
87 | wxFLAGS_MEMBER(wxRA_SPECIFY_COLS) | |
88 | wxFLAGS_MEMBER(wxRA_HORIZONTAL) | |
89 | wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS) | |
90 | wxFLAGS_MEMBER(wxRA_VERTICAL) | |
91 | ||
92 | wxEND_FLAGS( wxRadioBoxStyle ) | |
bc9fb572 JS |
93 | |
94 | IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h") | |
95 | ||
3ff066a4 SC |
96 | wxBEGIN_PROPERTIES_TABLE(wxRadioBox) |
97 | wxEVENT_PROPERTY( Select , wxEVT_COMMAND_RADIOBOX_SELECTED , wxCommandEvent ) | |
98 | wxPROPERTY_FLAGS( WindowStyle , wxRadioBoxStyle , long , SetWindowStyleFlag , GetWindowStyleFlag , , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style | |
99 | wxEND_PROPERTIES_TABLE() | |
bc9fb572 JS |
100 | |
101 | #else | |
d3acd369 | 102 | IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl) |
bc9fb572 | 103 | #endif |
2bda0e17 | 104 | |
066f1b7a | 105 | /* |
4d08943e WS |
106 | selection |
107 | content | |
108 | label | |
109 | dimension | |
110 | item | |
066f1b7a SC |
111 | */ |
112 | ||
e373f51b VZ |
113 | // --------------------------------------------------------------------------- |
114 | // private functions | |
115 | // --------------------------------------------------------------------------- | |
116 | ||
e373f51b VZ |
117 | // wnd proc for radio buttons |
118 | LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd, | |
119 | UINT message, | |
120 | WPARAM wParam, | |
121 | LPARAM lParam); | |
122 | ||
123 | // --------------------------------------------------------------------------- | |
124 | // global vars | |
125 | // --------------------------------------------------------------------------- | |
126 | ||
127 | // the pointer to standard radio button wnd proc | |
457e6c54 | 128 | static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL; |
e373f51b VZ |
129 | |
130 | // =========================================================================== | |
131 | // implementation | |
132 | // =========================================================================== | |
133 | ||
134 | // --------------------------------------------------------------------------- | |
bd0a76e2 | 135 | // wxRadioBox creation |
e373f51b VZ |
136 | // --------------------------------------------------------------------------- |
137 | ||
2bda0e17 | 138 | // Radio box item |
bd0a76e2 | 139 | void wxRadioBox::Init() |
2bda0e17 | 140 | { |
bd0a76e2 | 141 | m_selectedButton = wxNOT_FOUND; |
da07e033 | 142 | m_radioButtons = NULL; |
e373f51b VZ |
143 | m_majorDim = 0; |
144 | m_radioWidth = NULL; | |
145 | m_radioHeight = NULL; | |
2bda0e17 KB |
146 | } |
147 | ||
f048e32f VZ |
148 | bool wxRadioBox::Create(wxWindow *parent, |
149 | wxWindowID id, | |
150 | const wxString& title, | |
151 | const wxPoint& pos, | |
152 | const wxSize& size, | |
153 | int n, | |
154 | const wxString choices[], | |
155 | int majorDim, | |
156 | long style, | |
157 | const wxValidator& val, | |
158 | const wxString& name) | |
2bda0e17 | 159 | { |
f048e32f | 160 | // initialize members |
3ca6a5f0 | 161 | m_majorDim = majorDim == 0 ? n : majorDim; |
da07e033 | 162 | |
f048e32f | 163 | // common initialization |
bd0a76e2 | 164 | if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) ) |
4d08943e | 165 | return false; |
2bda0e17 | 166 | |
bd0a76e2 VZ |
167 | #if wxUSE_VALIDATORS |
168 | SetValidator(val); | |
169 | #else | |
170 | wxUnusedVar(val); | |
171 | #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS | |
da07e033 | 172 | |
bd0a76e2 | 173 | m_radioButtons = new wxSubwindows(n); |
e373f51b VZ |
174 | m_radioWidth = new int[n]; |
175 | m_radioHeight = new int[n]; | |
f048e32f | 176 | |
f048e32f VZ |
177 | for ( int i = 0; i < n; i++ ) |
178 | { | |
179 | m_radioWidth[i] = | |
4d08943e | 180 | m_radioHeight[i] = wxDefaultCoord; |
d3acd369 | 181 | long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE; |
1f621c2f | 182 | if ( i == 0 ) |
f048e32f VZ |
183 | styleBtn |= WS_GROUP; |
184 | ||
da07e033 | 185 | long newId = NewControlId(); |
da07e033 | 186 | |
f048e32f VZ |
187 | HWND hwndBtn = ::CreateWindow(_T("BUTTON"), |
188 | choices[i], | |
189 | styleBtn, | |
190 | 0, 0, 0, 0, // will be set in SetSize() | |
eba99da4 | 191 | GetHwnd(), |
f048e32f VZ |
192 | (HMENU)newId, |
193 | wxGetInstance(), | |
e373f51b | 194 | NULL); |
2bda0e17 | 195 | |
f048e32f VZ |
196 | if ( !hwndBtn ) |
197 | { | |
f6bcfd97 | 198 | wxLogLastError(wxT("CreateWindow(radio btn)")); |
f048e32f | 199 | |
4d08943e | 200 | return false; |
f048e32f VZ |
201 | } |
202 | ||
bd0a76e2 | 203 | (*m_radioButtons)[i] = hwndBtn; |
42e69d6b | 204 | |
e373f51b | 205 | SubclassRadioButton((WXHWND)hwndBtn); |
2bda0e17 | 206 | |
f048e32f | 207 | m_subControls.Add(newId); |
da07e033 | 208 | } |
e373f51b | 209 | |
da07e033 | 210 | // Create a dummy radio control to end the group. |
f048e32f | 211 | (void)::CreateWindow(_T("BUTTON"), |
fda7962d | 212 | wxEmptyString, |
f048e32f | 213 | WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD, |
eba99da4 | 214 | 0, 0, 0, 0, GetHwnd(), |
e373f51b | 215 | (HMENU)NewControlId(), wxGetInstance(), NULL); |
2bda0e17 | 216 | |
bd0a76e2 VZ |
217 | m_radioButtons->SetFont(GetFont()); |
218 | ||
64133c38 JS |
219 | #ifdef __WXWINCE__ |
220 | // Set the z-order correctly | |
d26e1ab2 | 221 | SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); |
64133c38 JS |
222 | #endif |
223 | ||
da07e033 | 224 | SetSelection(0); |
f048e32f | 225 | SetSize(pos.x, pos.y, size.x, size.y); |
2bda0e17 | 226 | |
7a5a5718 RD |
227 | // Now that we have items determine what is the best size and set it. |
228 | SetBestSize(size); | |
4d08943e WS |
229 | |
230 | return true; | |
2bda0e17 | 231 | } |
2bda0e17 | 232 | |
584ad2a3 MB |
233 | bool wxRadioBox::Create(wxWindow *parent, |
234 | wxWindowID id, | |
235 | const wxString& title, | |
236 | const wxPoint& pos, | |
237 | const wxSize& size, | |
238 | const wxArrayString& choices, | |
239 | int majorDim, | |
240 | long style, | |
241 | const wxValidator& val, | |
242 | const wxString& name) | |
243 | { | |
244 | wxCArrayString chs(choices); | |
245 | return Create(parent, id, title, pos, size, chs.GetCount(), | |
246 | chs.GetStrings(), majorDim, style, val, name); | |
247 | } | |
248 | ||
e373f51b | 249 | wxRadioBox::~wxRadioBox() |
2bda0e17 | 250 | { |
4d08943e | 251 | m_isBeingDeleted = true; |
1eb20d4a | 252 | |
bd0a76e2 VZ |
253 | delete m_radioButtons; |
254 | delete[] m_radioWidth; | |
255 | delete[] m_radioHeight; | |
256 | } | |
257 | ||
258 | // NB: if this code is changed, wxGetWindowForHWND() which relies on having the | |
259 | // radiobox pointer in GWL_USERDATA for radio buttons must be updated too! | |
260 | void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) | |
261 | { | |
262 | HWND hwndBtn = (HWND)hWndBtn; | |
263 | ||
264 | if ( !s_wndprocRadioBtn ) | |
265 | s_wndprocRadioBtn = (WXFARPROC)wxGetWindowProc(hwndBtn); | |
266 | ||
267 | wxSetWindowProc(hwndBtn, wxRadioBtnWndProc); | |
268 | wxSetWindowUserData(hwndBtn, this); | |
269 | } | |
270 | ||
271 | // ---------------------------------------------------------------------------- | |
272 | // events generation | |
273 | // ---------------------------------------------------------------------------- | |
274 | ||
275 | bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id) | |
276 | { | |
277 | if ( cmd == BN_CLICKED ) | |
da07e033 | 278 | { |
bd0a76e2 VZ |
279 | if (id == GetId()) |
280 | return true; | |
281 | ||
282 | int selectedButton = wxNOT_FOUND; | |
283 | ||
284 | int count = GetCount(); | |
285 | for ( int i = 0; i < count; i++ ) | |
286 | { | |
287 | if ( id == wxGetWindowId((*m_radioButtons)[i]) ) | |
288 | { | |
289 | selectedButton = i; | |
290 | ||
291 | break; | |
292 | } | |
293 | } | |
294 | ||
295 | if ( selectedButton == wxNOT_FOUND ) | |
296 | { | |
297 | // just ignore it - due to a hack with WM_NCHITTEST handling in our | |
298 | // wnd proc, we can receive dummy click messages when we click near | |
299 | // the radiobox edge (this is ugly but Julian wouldn't let me get | |
300 | // rid of this...) | |
301 | return false; | |
302 | } | |
303 | ||
304 | if ( selectedButton != m_selectedButton ) | |
305 | { | |
306 | m_selectedButton = selectedButton; | |
307 | ||
308 | SendNotificationEvent(); | |
309 | } | |
310 | //else: don't generate events when the selection doesn't change | |
311 | ||
312 | return true; | |
da07e033 | 313 | } |
bd0a76e2 VZ |
314 | else |
315 | return false; | |
316 | } | |
42e69d6b | 317 | |
bd0a76e2 VZ |
318 | void wxRadioBox::Command(wxCommandEvent & event) |
319 | { | |
687706f5 | 320 | SetSelection (event.GetInt()); |
bd0a76e2 VZ |
321 | SetFocus(); |
322 | ProcessCommand(event); | |
323 | } | |
2bda0e17 | 324 | |
bd0a76e2 VZ |
325 | void wxRadioBox::SendNotificationEvent() |
326 | { | |
327 | wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId); | |
328 | event.SetInt( m_selectedButton ); | |
329 | event.SetString( GetString(m_selectedButton) ); | |
330 | event.SetEventObject( this ); | |
331 | ProcessCommand(event); | |
2bda0e17 KB |
332 | } |
333 | ||
bd0a76e2 VZ |
334 | // ---------------------------------------------------------------------------- |
335 | // simple accessors | |
336 | // ---------------------------------------------------------------------------- | |
337 | ||
338 | int wxRadioBox::GetCount() const | |
2bda0e17 | 339 | { |
bd0a76e2 VZ |
340 | return m_radioButtons->GetCount(); |
341 | } | |
d66a042c | 342 | |
bd0a76e2 VZ |
343 | // returns the number of rows |
344 | int wxRadioBox::GetNumVer() const | |
345 | { | |
346 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) | |
347 | { | |
348 | return m_majorDim; | |
349 | } | |
350 | else | |
351 | { | |
352 | return (GetCount() + m_majorDim - 1)/m_majorDim; | |
353 | } | |
2bda0e17 KB |
354 | } |
355 | ||
bd0a76e2 VZ |
356 | // returns the number of columns |
357 | int wxRadioBox::GetNumHor() const | |
2bda0e17 | 358 | { |
bd0a76e2 VZ |
359 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) |
360 | { | |
361 | return (GetCount() + m_majorDim - 1)/m_majorDim; | |
362 | } | |
363 | else | |
364 | { | |
365 | return m_majorDim; | |
366 | } | |
367 | } | |
2bda0e17 | 368 | |
bd0a76e2 VZ |
369 | void wxRadioBox::SetString(int item, const wxString& label) |
370 | { | |
789f6795 | 371 | wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") ); |
e373f51b | 372 | |
bd0a76e2 VZ |
373 | m_radioWidth[item] = |
374 | m_radioHeight[item] = wxDefaultCoord; | |
2bda0e17 | 375 | |
bd0a76e2 | 376 | ::SetWindowText((*m_radioButtons)[item], label.c_str()); |
31582e4e RD |
377 | |
378 | InvalidateBestSize(); | |
2bda0e17 KB |
379 | } |
380 | ||
bd0a76e2 | 381 | void wxRadioBox::SetSelection(int N) |
2bda0e17 | 382 | { |
789f6795 | 383 | wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") ); |
bd0a76e2 | 384 | |
27758ba7 VZ |
385 | // unselect the old button |
386 | if ( m_selectedButton != wxNOT_FOUND ) | |
387 | ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L); | |
388 | ||
389 | // and select the new one | |
bd0a76e2 VZ |
390 | ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L); |
391 | ||
392 | m_selectedButton = N; | |
2bda0e17 KB |
393 | } |
394 | ||
395 | // Find string for position | |
1e6feb95 | 396 | wxString wxRadioBox::GetString(int item) const |
2bda0e17 | 397 | { |
789f6795 | 398 | wxCHECK_MSG( IsValid(item), wxEmptyString, |
1e6feb95 VZ |
399 | wxT("invalid radiobox index") ); |
400 | ||
bd0a76e2 VZ |
401 | return wxGetWindowText((*m_radioButtons)[item]); |
402 | } | |
403 | ||
404 | void wxRadioBox::SetFocus() | |
405 | { | |
406 | if ( GetCount() > 0 ) | |
407 | { | |
408 | ::SetFocus((*m_radioButtons)[m_selectedButton == wxNOT_FOUND | |
409 | ? 0 | |
410 | : m_selectedButton]); | |
411 | } | |
412 | } | |
413 | ||
414 | // Enable a specific button | |
1a87edf2 | 415 | bool wxRadioBox::Enable(int item, bool enable) |
bd0a76e2 | 416 | { |
789f6795 | 417 | wxCHECK_MSG( IsValid(item), false, |
bd0a76e2 VZ |
418 | wxT("invalid item in wxRadioBox::Enable()") ); |
419 | ||
789f6795 WS |
420 | BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable); |
421 | ||
422 | return (ret == 0) == enable; | |
2bda0e17 KB |
423 | } |
424 | ||
bd0a76e2 | 425 | // Show a specific button |
789f6795 | 426 | bool wxRadioBox::Show(int item, bool show) |
bd0a76e2 | 427 | { |
789f6795 | 428 | wxCHECK_MSG( IsValid(item), false, |
bd0a76e2 VZ |
429 | wxT("invalid item in wxRadioBox::Show()") ); |
430 | ||
789f6795 WS |
431 | BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE); |
432 | ||
31582e4e RD |
433 | bool changed = (ret != 0) == show; |
434 | if( changed ) | |
435 | InvalidateBestSize(); | |
436 | return changed; | |
bd0a76e2 VZ |
437 | } |
438 | ||
439 | WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons) | |
440 | ||
3ca6a5f0 BP |
441 | // ---------------------------------------------------------------------------- |
442 | // size calculations | |
443 | // ---------------------------------------------------------------------------- | |
444 | ||
445 | wxSize wxRadioBox::GetMaxButtonSize() const | |
446 | { | |
447 | // calculate the max button size | |
448 | int widthMax = 0, | |
449 | heightMax = 0; | |
bd0a76e2 VZ |
450 | const int count = GetCount(); |
451 | for ( int i = 0 ; i < count; i++ ) | |
3ca6a5f0 BP |
452 | { |
453 | int width, height; | |
454 | if ( m_radioWidth[i] < 0 ) | |
455 | { | |
bd0a76e2 | 456 | GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height); |
3ca6a5f0 BP |
457 | |
458 | // adjust the size to take into account the radio box itself | |
459 | // FIXME this is totally bogus! | |
460 | width += RADIO_SIZE; | |
461 | height *= 3; | |
462 | height /= 2; | |
463 | } | |
464 | else | |
465 | { | |
466 | width = m_radioWidth[i]; | |
467 | height = m_radioHeight[i]; | |
468 | } | |
469 | ||
470 | if ( widthMax < width ) | |
471 | widthMax = width; | |
472 | if ( heightMax < height ) | |
473 | heightMax = height; | |
474 | } | |
475 | ||
476 | return wxSize(widthMax, heightMax); | |
477 | } | |
478 | ||
479 | wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const | |
480 | { | |
481 | // the radiobox should be big enough for its buttons | |
482 | int cx1, cy1; | |
7a5e53ab | 483 | wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); |
3ca6a5f0 BP |
484 | |
485 | int extraHeight = cy1; | |
486 | ||
3ca6a5f0 BP |
487 | int height = GetNumVer() * sizeBtn.y + cy1/2 + extraHeight; |
488 | int width = GetNumHor() * (sizeBtn.x + cx1) + cx1; | |
489 | ||
c7fd6717 | 490 | // Add extra space under the label, if it exists. |
1a87edf2 | 491 | if (!wxControl::GetLabel().empty()) |
c7fd6717 JS |
492 | height += cy1/2; |
493 | ||
3ca6a5f0 BP |
494 | // and also wide enough for its label |
495 | int widthLabel; | |
496 | GetTextExtent(GetTitle(), &widthLabel, NULL); | |
497 | widthLabel += RADIO_SIZE; // FIXME this is bogus too | |
498 | if ( widthLabel > width ) | |
499 | width = widthLabel; | |
500 | ||
501 | return wxSize(width, height); | |
502 | } | |
503 | ||
504 | wxSize wxRadioBox::DoGetBestSize() const | |
505 | { | |
31582e4e RD |
506 | wxSize best = GetTotalButtonSize(GetMaxButtonSize()); |
507 | CacheBestSize(best); | |
508 | return best; | |
3ca6a5f0 BP |
509 | } |
510 | ||
1f916a19 | 511 | // Restored old code. |
bfc6fde4 | 512 | void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags) |
1f916a19 | 513 | { |
4438caf4 VZ |
514 | int currentX, currentY; |
515 | GetPosition(¤tX, ¤tY); | |
c219cecc VZ |
516 | int widthOld, heightOld; |
517 | GetSize(&widthOld, &heightOld); | |
518 | ||
4438caf4 VZ |
519 | int xx = x; |
520 | int yy = y; | |
521 | ||
4d08943e | 522 | if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
4438caf4 | 523 | xx = currentX; |
4d08943e | 524 | if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE)) |
4438caf4 VZ |
525 | yy = currentY; |
526 | ||
eba99da4 JS |
527 | int y_offset = 0; |
528 | int x_offset = 0; | |
f048e32f | 529 | |
3ca6a5f0 | 530 | int cx1, cy1; |
7a5e53ab | 531 | wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont()); |
4438caf4 VZ |
532 | |
533 | // Attempt to have a look coherent with other platforms: We compute the | |
534 | // biggest toggle dim, then we align all items according this value. | |
3ca6a5f0 BP |
535 | wxSize maxSize = GetMaxButtonSize(); |
536 | int maxWidth = maxSize.x, | |
537 | maxHeight = maxSize.y; | |
4438caf4 | 538 | |
3ca6a5f0 BP |
539 | wxSize totSize = GetTotalButtonSize(maxSize); |
540 | int totWidth = totSize.x, | |
541 | totHeight = totSize.y; | |
542 | ||
543 | // only change our width/height if asked for | |
4d08943e | 544 | if ( width == wxDefaultCoord ) |
1f916a19 | 545 | { |
3ca6a5f0 BP |
546 | if ( sizeFlags & wxSIZE_AUTO_WIDTH ) |
547 | width = totWidth; | |
4438caf4 | 548 | else |
3ca6a5f0 | 549 | width = widthOld; |
1f916a19 | 550 | } |
1f916a19 | 551 | |
4d08943e | 552 | if ( height == wxDefaultCoord ) |
4438caf4 | 553 | { |
3ca6a5f0 BP |
554 | if ( sizeFlags & wxSIZE_AUTO_HEIGHT ) |
555 | height = totHeight; | |
4438caf4 | 556 | else |
3ca6a5f0 BP |
557 | height = heightOld; |
558 | } | |
4438caf4 | 559 | |
8e44f3ca JS |
560 | // if our parent had prepared a defer window handle for us, use it (unless |
561 | // we are a top level window) | |
8e44f3ca JS |
562 | |
563 | #if USE_DEFERRED_SIZING | |
3d104ec3 | 564 | wxWindowMSW *parent = GetParent(); |
8e44f3ca JS |
565 | HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL; |
566 | #else | |
567 | HDWP hdwp = 0; | |
3d104ec3 | 568 | #endif |
8e44f3ca JS |
569 | |
570 | wxMoveWindowDeferred(hdwp, this, GetHwnd(), xx, yy, width, height); | |
c219cecc | 571 | |
3ca6a5f0 BP |
572 | // Now position all the buttons: the current button will be put at |
573 | // wxPoint(x_offset, y_offset) and the new row/column will start at | |
574 | // startX/startY. The size of all buttons will be the same wxSize(maxWidth, | |
575 | // maxHeight) except for the buttons in the last column which should extend | |
576 | // to the right border of radiobox and thus can be wider than this. | |
c219cecc | 577 | |
3ca6a5f0 BP |
578 | // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in |
579 | // left to right order and m_majorDim is the number of columns while | |
580 | // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and | |
581 | // m_majorDim is the number of rows. | |
4438caf4 | 582 | |
3ca6a5f0 BP |
583 | x_offset += cx1; |
584 | y_offset += cy1; | |
1f916a19 | 585 | |
c7fd6717 | 586 | // Add extra space under the label, if it exists. |
1a87edf2 | 587 | if (!wxControl::GetLabel().empty()) |
c7fd6717 | 588 | y_offset += cy1/2; |
3ca6a5f0 | 589 | |
4438caf4 VZ |
590 | int startX = x_offset; |
591 | int startY = y_offset; | |
1f916a19 | 592 | |
bd0a76e2 VZ |
593 | const int count = GetCount(); |
594 | for ( int i = 0; i < count; i++ ) | |
1f916a19 | 595 | { |
3ca6a5f0 BP |
596 | // the last button in the row may be wider than the other ones as the |
597 | // radiobox may be wider than the sum of the button widths (as it | |
598 | // happens, for example, when the radiobox label is very long) | |
599 | bool isLastInTheRow; | |
600 | if ( m_windowStyle & wxRA_SPECIFY_COLS ) | |
601 | { | |
602 | // item is the last in its row if it is a multiple of the number of | |
603 | // columns or if it is just the last item | |
604 | int n = i + 1; | |
bd0a76e2 | 605 | isLastInTheRow = ((n % m_majorDim) == 0) || (n == count); |
3ca6a5f0 BP |
606 | } |
607 | else // wxRA_SPECIFY_ROWS | |
4438caf4 | 608 | { |
3ca6a5f0 | 609 | // item is the last in the row if it is in the last columns |
bd0a76e2 | 610 | isLastInTheRow = i >= (count/m_majorDim)*m_majorDim; |
3ca6a5f0 BP |
611 | } |
612 | ||
613 | // is this the start of new row/column? | |
614 | if ( i && (i % m_majorDim == 0) ) | |
615 | { | |
616 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) | |
4438caf4 | 617 | { |
3ca6a5f0 | 618 | // start of new column |
4438caf4 VZ |
619 | y_offset = startY; |
620 | x_offset += maxWidth + cx1; | |
621 | } | |
3ca6a5f0 | 622 | else // start of new row |
4438caf4 VZ |
623 | { |
624 | x_offset = startX; | |
625 | y_offset += maxHeight; | |
626 | if (m_radioWidth[0]>0) | |
627 | y_offset += cy1/2; | |
628 | } | |
629 | } | |
3ca6a5f0 BP |
630 | |
631 | int widthBtn; | |
632 | if ( isLastInTheRow ) | |
4438caf4 | 633 | { |
3ca6a5f0 BP |
634 | // make the button go to the end of radio box |
635 | widthBtn = startX + width - x_offset - 2*cx1; | |
636 | if ( widthBtn < maxWidth ) | |
637 | widthBtn = maxWidth; | |
4438caf4 VZ |
638 | } |
639 | else | |
640 | { | |
3ca6a5f0 BP |
641 | // normal button, always of the same size |
642 | widthBtn = maxWidth; | |
4438caf4 | 643 | } |
1f916a19 | 644 | |
bd0a76e2 VZ |
645 | // make all buttons of the same, maximal size - like this they cover |
646 | // the radiobox entirely and the radiobox tooltips are always shown | |
647 | // (otherwise they are not when the mouse pointer is in the radiobox | |
648 | // part not belonging to any radiobutton) | |
649 | ::MoveWindow((*m_radioButtons)[i], | |
3ca6a5f0 | 650 | x_offset, y_offset, widthBtn, maxHeight, |
f048e32f | 651 | TRUE); |
4438caf4 | 652 | |
3ca6a5f0 BP |
653 | // where do we put the next button? |
654 | if ( m_windowStyle & wxRA_SPECIFY_ROWS ) | |
4438caf4 | 655 | { |
3ca6a5f0 | 656 | // below this one |
4438caf4 VZ |
657 | y_offset += maxHeight; |
658 | if (m_radioWidth[0]>0) | |
659 | y_offset += cy1/2; | |
660 | } | |
661 | else | |
3ca6a5f0 BP |
662 | { |
663 | // to the right of this one | |
664 | x_offset += widthBtn + cx1; | |
665 | } | |
1f916a19 | 666 | } |
8e44f3ca | 667 | |
55079b43 JS |
668 | #if USE_DEFERRED_SIZING |
669 | if (parent) | |
670 | { | |
8e44f3ca JS |
671 | // hdwp must be updated as it may have been changed |
672 | parent->m_hDWP = (WXHANDLE)hdwp; | |
673 | } | |
55079b43 | 674 | #endif |
1f916a19 JS |
675 | } |
676 | ||
c3732409 VZ |
677 | // ---------------------------------------------------------------------------- |
678 | // radio box drawing | |
679 | // ---------------------------------------------------------------------------- | |
680 | ||
681 | #ifndef __WXWINCE__ | |
682 | ||
683 | WXHRGN wxRadioBox::MSWGetRegionWithoutChildren() | |
684 | { | |
685 | RECT rc; | |
686 | ::GetWindowRect(GetHwnd(), &rc); | |
687 | HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1); | |
688 | ||
689 | const size_t count = GetCount(); | |
690 | for ( size_t i = 0; i < count; ++i ) | |
691 | { | |
692 | ::GetWindowRect((*m_radioButtons)[i], &rc); | |
693 | AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc)); | |
694 | ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF); | |
695 | } | |
696 | ||
697 | return (WXHRGN)hrgn; | |
698 | } | |
699 | ||
1a784dfc VZ |
700 | WXLRESULT |
701 | wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam) | |
702 | { | |
8e44f3ca JS |
703 | // FIXME: Without this, the radiobox corrupts other controls as it moves |
704 | // in a dynamic layout. Refreshing causes flicker, but it's better than | |
705 | // leaving droppings. Note that for some reason, wxStaticBox doesn't need | |
706 | // this (perhaps because it has no real children?) | |
9705fbe9 | 707 | if ( nMsg == WM_MOVE ) |
8e44f3ca JS |
708 | { |
709 | WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam); | |
710 | wxRect rect = GetRect(); | |
711 | GetParent()->Refresh(true, & rect); | |
712 | return res; | |
713 | } | |
1a784dfc VZ |
714 | |
715 | return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam); | |
716 | } | |
717 | ||
c3732409 VZ |
718 | #endif // __WXWINCE__ |
719 | ||
e373f51b VZ |
720 | // --------------------------------------------------------------------------- |
721 | // window proc for radio buttons | |
722 | // --------------------------------------------------------------------------- | |
723 | ||
724 | LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, | |
8614c467 | 725 | UINT message, |
e373f51b VZ |
726 | WPARAM wParam, |
727 | LPARAM lParam) | |
728 | { | |
8614c467 | 729 | switch ( message ) |
e373f51b | 730 | { |
8614c467 VZ |
731 | case WM_GETDLGCODE: |
732 | // we must tell IsDialogMessage()/our kbd processing code that we | |
733 | // want to process arrows ourselves because neither of them is | |
734 | // smart enough to handle arrows properly for us | |
735 | { | |
8ad6ad99 | 736 | long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, |
8614c467 | 737 | message, wParam, lParam); |
8ad6ad99 | 738 | |
8614c467 VZ |
739 | return lDlgCode | DLGC_WANTARROWS; |
740 | } | |
e373f51b | 741 | |
8614c467 VZ |
742 | #if wxUSE_TOOLTIPS |
743 | case WM_NOTIFY: | |
f048e32f | 744 | { |
8614c467 | 745 | NMHDR* hdr = (NMHDR *)lParam; |
2b5f62a0 | 746 | if ( hdr->code == TTN_NEEDTEXT ) |
e373f51b | 747 | { |
975b6bcf VZ |
748 | wxRadioBox * |
749 | radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd); | |
e373f51b | 750 | |
8614c467 VZ |
751 | wxCHECK_MSG( radiobox, 0, |
752 | wxT("radio button without radio box?") ); | |
753 | ||
754 | wxToolTip *tooltip = radiobox->GetToolTip(); | |
755 | if ( tooltip ) | |
756 | { | |
757 | TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam; | |
758 | ttt->lpszText = (wxChar *)tooltip->GetTip().c_str(); | |
759 | } | |
760 | ||
761 | // processed | |
762 | return 0; | |
e373f51b | 763 | } |
f048e32f | 764 | } |
8614c467 | 765 | break; |
f048e32f | 766 | #endif // wxUSE_TOOLTIPS |
f048e32f | 767 | |
8614c467 | 768 | case WM_KEYDOWN: |
9a5ccab4 | 769 | { |
975b6bcf | 770 | wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd); |
f048e32f | 771 | |
8614c467 | 772 | wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") ); |
f048e32f | 773 | |
4d08943e | 774 | bool processed = true; |
f048e32f | 775 | |
e421922f | 776 | wxDirection dir; |
8614c467 VZ |
777 | switch ( wParam ) |
778 | { | |
779 | case VK_UP: | |
1e6feb95 | 780 | dir = wxUP; |
8614c467 | 781 | break; |
f048e32f | 782 | |
8614c467 | 783 | case VK_LEFT: |
1e6feb95 | 784 | dir = wxLEFT; |
8614c467 | 785 | break; |
f048e32f | 786 | |
8614c467 | 787 | case VK_DOWN: |
1e6feb95 | 788 | dir = wxDOWN; |
8614c467 | 789 | break; |
f048e32f | 790 | |
8614c467 | 791 | case VK_RIGHT: |
1e6feb95 | 792 | dir = wxRIGHT; |
8614c467 VZ |
793 | break; |
794 | ||
795 | default: | |
4d08943e | 796 | processed = false; |
1e6feb95 VZ |
797 | |
798 | // just to suppress the compiler warning | |
799 | dir = wxALL; | |
8614c467 VZ |
800 | } |
801 | ||
802 | if ( processed ) | |
f048e32f | 803 | { |
1e6feb95 VZ |
804 | int selOld = radiobox->GetSelection(); |
805 | int selNew = radiobox->GetNextItem | |
806 | ( | |
807 | selOld, | |
808 | dir, | |
809 | radiobox->GetWindowStyle() | |
810 | ); | |
3ca6a5f0 | 811 | |
8614c467 VZ |
812 | if ( selNew != selOld ) |
813 | { | |
814 | radiobox->SetSelection(selNew); | |
974931fe | 815 | radiobox->SetFocus(); |
8614c467 VZ |
816 | |
817 | // emulate the button click | |
818 | radiobox->SendNotificationEvent(); | |
9a5ccab4 | 819 | |
8614c467 VZ |
820 | return 0; |
821 | } | |
f048e32f | 822 | } |
9a5ccab4 | 823 | } |
21687069 VZ |
824 | break; |
825 | ||
1dab049c VZ |
826 | case WM_SETFOCUS: |
827 | case WM_KILLFOCUS: | |
828 | { | |
975b6bcf | 829 | wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd); |
1dab049c VZ |
830 | |
831 | wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") ); | |
832 | ||
833 | // if we don't do this, no focus events are generated for the | |
834 | // radiobox and, besides, we need to notify the parent about | |
835 | // the focus change, otherwise the focus handling logic in | |
836 | // wxControlContainer doesn't work | |
837 | if ( message == WM_SETFOCUS ) | |
838 | radiobox->HandleSetFocus((WXHWND)wParam); | |
839 | else | |
840 | radiobox->HandleKillFocus((WXHWND)wParam); | |
841 | } | |
842 | break; | |
843 | ||
bd0a76e2 | 844 | #ifndef __WXWINCE__ |
fac93396 | 845 | case WM_HELP: |
e421922f | 846 | { |
975b6bcf | 847 | wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd); |
fac93396 | 848 | |
e421922f | 849 | wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") ); |
fac93396 | 850 | |
bd0a76e2 VZ |
851 | bool processed = false; |
852 | ||
853 | wxEvtHandler * const handler = radiobox->GetEventHandler(); | |
fac93396 | 854 | |
e421922f | 855 | HELPINFO* info = (HELPINFO*) lParam; |
bd0a76e2 | 856 | if ( info->iContextType == HELPINFO_WINDOW ) |
fac93396 | 857 | { |
bd0a76e2 VZ |
858 | for ( wxWindow* subjectOfHelp = radiobox; |
859 | subjectOfHelp; | |
860 | subjectOfHelp = subjectOfHelp->GetParent() ) | |
e421922f | 861 | { |
bd0a76e2 VZ |
862 | wxHelpEvent helpEvent(wxEVT_HELP, |
863 | subjectOfHelp->GetId(), | |
864 | wxPoint(info->MousePos.x, | |
865 | info->MousePos.y)); | |
e421922f | 866 | helpEvent.SetEventObject(radiobox); |
bd0a76e2 VZ |
867 | if ( handler->ProcessEvent(helpEvent) ) |
868 | { | |
869 | processed = true; | |
870 | break; | |
871 | } | |
e421922f | 872 | } |
fac93396 | 873 | } |
e421922f VZ |
874 | else if (info->iContextType == HELPINFO_MENUITEM) |
875 | { | |
bd0a76e2 | 876 | wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId); |
e421922f | 877 | helpEvent.SetEventObject(radiobox); |
bd0a76e2 | 878 | processed = handler->ProcessEvent(helpEvent); |
e421922f | 879 | } |
bd0a76e2 VZ |
880 | |
881 | if ( processed ) | |
e421922f | 882 | return 0; |
e421922f | 883 | } |
c3732409 | 884 | break; |
bd0a76e2 | 885 | #endif // !__WXWINCE__ |
e373f51b VZ |
886 | } |
887 | ||
8ad6ad99 | 888 | return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam); |
e373f51b | 889 | } |
42e69d6b | 890 | |
1e6feb95 | 891 | #endif // wxUSE_RADIOBOX |
bd0a76e2 | 892 |