Switch deferred sizing off for radioboxes because with them, the radio buttons
[wxWidgets.git] / src / msw / radiobox.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/radiobox.cpp
3 // Purpose: wxRadioBox implementation
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
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
41 #include "wx/msw/subwin.h"
42
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
47
48 #if wxUSE_TOOLTIPS
49 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
50 #include <commctrl.h>
51 #endif
52 #include "wx/tooltip.h"
53 #endif // wxUSE_TOOLTIPS
54
55 // TODO: wxCONSTRUCTOR
56 #if 0 // wxUSE_EXTENDED_RTTI
57 WX_DEFINE_FLAGS( wxRadioBoxStyle )
58
59 wxBEGIN_FLAGS( wxRadioBoxStyle )
60 // new style border flags, we put them first to
61 // use them for streaming out
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)
68
69 // old style border flags
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)
75 wxFLAGS_MEMBER(wxBORDER)
76
77 // standard window styles
78 wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
79 wxFLAGS_MEMBER(wxCLIP_CHILDREN)
80 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
81 wxFLAGS_MEMBER(wxWANTS_CHARS)
82 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
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 )
93
94 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox, wxControl,"wx/radiobox.h")
95
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()
100
101 #else
102 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox, wxControl)
103 #endif
104
105 /*
106 selection
107 content
108 label
109 dimension
110 item
111 */
112
113 // ---------------------------------------------------------------------------
114 // private functions
115 // ---------------------------------------------------------------------------
116
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
128 static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
129
130 // ===========================================================================
131 // implementation
132 // ===========================================================================
133
134 // ---------------------------------------------------------------------------
135 // wxRadioBox creation
136 // ---------------------------------------------------------------------------
137
138 // Radio box item
139 void wxRadioBox::Init()
140 {
141 m_selectedButton = wxNOT_FOUND;
142 m_radioButtons = NULL;
143 m_majorDim = 0;
144 m_radioWidth = NULL;
145 m_radioHeight = NULL;
146 }
147
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)
159 {
160 // initialize members
161 m_majorDim = majorDim == 0 ? n : majorDim;
162
163 // common initialization
164 if ( !wxStaticBox::Create(parent, id, title, pos, size, style, name) )
165 return false;
166
167 #if wxUSE_VALIDATORS
168 SetValidator(val);
169 #else
170 wxUnusedVar(val);
171 #endif // wxUSE_VALIDATORS/!wxUSE_VALIDATORS
172
173 m_radioButtons = new wxSubwindows(n);
174 m_radioWidth = new int[n];
175 m_radioHeight = new int[n];
176
177 for ( int i = 0; i < n; i++ )
178 {
179 m_radioWidth[i] =
180 m_radioHeight[i] = wxDefaultCoord;
181 long styleBtn = BS_AUTORADIOBUTTON | WS_TABSTOP | WS_CHILD | WS_VISIBLE;
182 if ( i == 0 )
183 styleBtn |= WS_GROUP;
184
185 long newId = NewControlId();
186
187 HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
188 choices[i],
189 styleBtn,
190 0, 0, 0, 0, // will be set in SetSize()
191 GetHwnd(),
192 (HMENU)newId,
193 wxGetInstance(),
194 NULL);
195
196 if ( !hwndBtn )
197 {
198 wxLogLastError(wxT("CreateWindow(radio btn)"));
199
200 return false;
201 }
202
203 (*m_radioButtons)[i] = hwndBtn;
204
205 SubclassRadioButton((WXHWND)hwndBtn);
206
207 m_subControls.Add(newId);
208 }
209
210 // Create a dummy radio control to end the group.
211 (void)::CreateWindow(_T("BUTTON"),
212 wxEmptyString,
213 WS_GROUP | BS_AUTORADIOBUTTON | WS_CHILD,
214 0, 0, 0, 0, GetHwnd(),
215 (HMENU)NewControlId(), wxGetInstance(), NULL);
216
217 m_radioButtons->SetFont(GetFont());
218
219 #ifdef __WXWINCE__
220 // Set the z-order correctly
221 SetWindowPos(GetHwnd(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE);
222 #endif
223
224 SetSelection(0);
225 SetSize(pos.x, pos.y, size.x, size.y);
226
227 // Now that we have items determine what is the best size and set it.
228 SetBestSize(size);
229
230 return true;
231 }
232
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
249 wxRadioBox::~wxRadioBox()
250 {
251 m_isBeingDeleted = true;
252
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 )
278 {
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;
313 }
314 else
315 return false;
316 }
317
318 void wxRadioBox::Command(wxCommandEvent & event)
319 {
320 SetSelection (event.GetInt());
321 SetFocus();
322 ProcessCommand(event);
323 }
324
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);
332 }
333
334 // ----------------------------------------------------------------------------
335 // simple accessors
336 // ----------------------------------------------------------------------------
337
338 int wxRadioBox::GetCount() const
339 {
340 return m_radioButtons->GetCount();
341 }
342
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 }
354 }
355
356 // returns the number of columns
357 int wxRadioBox::GetNumHor() const
358 {
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 }
368
369 void wxRadioBox::SetString(int item, const wxString& label)
370 {
371 wxCHECK_RET( IsValid(item), wxT("invalid radiobox index") );
372
373 m_radioWidth[item] =
374 m_radioHeight[item] = wxDefaultCoord;
375
376 ::SetWindowText((*m_radioButtons)[item], label.c_str());
377 }
378
379 void wxRadioBox::SetSelection(int N)
380 {
381 wxCHECK_RET( IsValid(N), wxT("invalid radiobox index") );
382
383 // unselect the old button
384 if ( m_selectedButton != wxNOT_FOUND )
385 ::SendMessage((*m_radioButtons)[m_selectedButton], BM_SETCHECK, 0, 0L);
386
387 // and select the new one
388 ::SendMessage((*m_radioButtons)[N], BM_SETCHECK, 1, 0L);
389
390 m_selectedButton = N;
391 }
392
393 // Find string for position
394 wxString wxRadioBox::GetString(int item) const
395 {
396 wxCHECK_MSG( IsValid(item), wxEmptyString,
397 wxT("invalid radiobox index") );
398
399 return wxGetWindowText((*m_radioButtons)[item]);
400 }
401
402 void wxRadioBox::SetFocus()
403 {
404 if ( GetCount() > 0 )
405 {
406 ::SetFocus((*m_radioButtons)[m_selectedButton == wxNOT_FOUND
407 ? 0
408 : m_selectedButton]);
409 }
410 }
411
412 // Enable a specific button
413 bool wxRadioBox::Enable(int item, bool enable)
414 {
415 wxCHECK_MSG( IsValid(item), false,
416 wxT("invalid item in wxRadioBox::Enable()") );
417
418 BOOL ret = ::EnableWindow((*m_radioButtons)[item], enable);
419
420 return (ret == 0) == enable;
421 }
422
423 // Show a specific button
424 bool wxRadioBox::Show(int item, bool show)
425 {
426 wxCHECK_MSG( IsValid(item), false,
427 wxT("invalid item in wxRadioBox::Show()") );
428
429 BOOL ret = ::ShowWindow((*m_radioButtons)[item], show ? SW_SHOW : SW_HIDE);
430
431 return (ret != 0) == show;
432 }
433
434 WX_FORWARD_STD_METHODS_TO_SUBWINDOWS(wxRadioBox, wxStaticBox, m_radioButtons)
435
436 // ----------------------------------------------------------------------------
437 // size calculations
438 // ----------------------------------------------------------------------------
439
440 wxSize wxRadioBox::GetMaxButtonSize() const
441 {
442 // calculate the max button size
443 int widthMax = 0,
444 heightMax = 0;
445 const int count = GetCount();
446 for ( int i = 0 ; i < count; i++ )
447 {
448 int width, height;
449 if ( m_radioWidth[i] < 0 )
450 {
451 GetTextExtent(wxGetWindowText((*m_radioButtons)[i]), &width, &height);
452
453 // adjust the size to take into account the radio box itself
454 // FIXME this is totally bogus!
455 width += RADIO_SIZE;
456 height *= 3;
457 height /= 2;
458 }
459 else
460 {
461 width = m_radioWidth[i];
462 height = m_radioHeight[i];
463 }
464
465 if ( widthMax < width )
466 widthMax = width;
467 if ( heightMax < height )
468 heightMax = height;
469 }
470
471 return wxSize(widthMax, heightMax);
472 }
473
474 wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
475 {
476 // the radiobox should be big enough for its buttons
477 int cx1, cy1;
478 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
479
480 int extraHeight = cy1;
481
482 int height = GetNumVer() * sizeBtn.y + cy1/2 + extraHeight;
483 int width = GetNumHor() * (sizeBtn.x + cx1) + cx1;
484
485 // Add extra space under the label, if it exists.
486 if (!wxControl::GetLabel().empty())
487 height += cy1/2;
488
489 // and also wide enough for its label
490 int widthLabel;
491 GetTextExtent(GetTitle(), &widthLabel, NULL);
492 widthLabel += RADIO_SIZE; // FIXME this is bogus too
493 if ( widthLabel > width )
494 width = widthLabel;
495
496 return wxSize(width, height);
497 }
498
499 wxSize wxRadioBox::DoGetBestSize() const
500 {
501 return GetTotalButtonSize(GetMaxButtonSize());
502 }
503
504 // Restored old code.
505 void wxRadioBox::DoSetSize(int x, int y, int width, int height, int sizeFlags)
506 {
507 int currentX, currentY;
508 GetPosition(&currentX, &currentY);
509 int widthOld, heightOld;
510 GetSize(&widthOld, &heightOld);
511
512 int xx = x;
513 int yy = y;
514
515 if (x == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
516 xx = currentX;
517 if (y == wxDefaultCoord && !(sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
518 yy = currentY;
519
520 int y_offset = 0;
521 int x_offset = 0;
522
523 int cx1, cy1;
524 wxGetCharSize(m_hWnd, &cx1, &cy1, GetFont());
525
526 // Attempt to have a look coherent with other platforms: We compute the
527 // biggest toggle dim, then we align all items according this value.
528 wxSize maxSize = GetMaxButtonSize();
529 int maxWidth = maxSize.x,
530 maxHeight = maxSize.y;
531
532 wxSize totSize = GetTotalButtonSize(maxSize);
533 int totWidth = totSize.x,
534 totHeight = totSize.y;
535
536 // only change our width/height if asked for
537 if ( width == wxDefaultCoord )
538 {
539 if ( sizeFlags & wxSIZE_AUTO_WIDTH )
540 width = totWidth;
541 else
542 width = widthOld;
543 }
544
545 if ( height == wxDefaultCoord )
546 {
547 if ( sizeFlags & wxSIZE_AUTO_HEIGHT )
548 height = totHeight;
549 else
550 height = heightOld;
551 }
552
553 // if our parent had prepared a defer window handle for us, use it (unless
554 // we are a top level window)
555 wxWindowMSW *parent = GetParent();
556
557 #if USE_DEFERRED_SIZING
558 HDWP hdwp = parent && !IsTopLevel() ? (HDWP)parent->m_hDWP : NULL;
559 #else
560 HDWP hdwp = 0;
561 #endif
562
563 wxMoveWindowDeferred(hdwp, this, GetHwnd(), xx, yy, width, height);
564
565 // Now position all the buttons: the current button will be put at
566 // wxPoint(x_offset, y_offset) and the new row/column will start at
567 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
568 // maxHeight) except for the buttons in the last column which should extend
569 // to the right border of radiobox and thus can be wider than this.
570
571 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
572 // left to right order and m_majorDim is the number of columns while
573 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
574 // m_majorDim is the number of rows.
575
576 x_offset += cx1;
577 y_offset += cy1;
578
579 // Add extra space under the label, if it exists.
580 if (!wxControl::GetLabel().empty())
581 y_offset += cy1/2;
582
583 int startX = x_offset;
584 int startY = y_offset;
585
586 const int count = GetCount();
587 for ( int i = 0; i < count; i++ )
588 {
589 // the last button in the row may be wider than the other ones as the
590 // radiobox may be wider than the sum of the button widths (as it
591 // happens, for example, when the radiobox label is very long)
592 bool isLastInTheRow;
593 if ( m_windowStyle & wxRA_SPECIFY_COLS )
594 {
595 // item is the last in its row if it is a multiple of the number of
596 // columns or if it is just the last item
597 int n = i + 1;
598 isLastInTheRow = ((n % m_majorDim) == 0) || (n == count);
599 }
600 else // wxRA_SPECIFY_ROWS
601 {
602 // item is the last in the row if it is in the last columns
603 isLastInTheRow = i >= (count/m_majorDim)*m_majorDim;
604 }
605
606 // is this the start of new row/column?
607 if ( i && (i % m_majorDim == 0) )
608 {
609 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
610 {
611 // start of new column
612 y_offset = startY;
613 x_offset += maxWidth + cx1;
614 }
615 else // start of new row
616 {
617 x_offset = startX;
618 y_offset += maxHeight;
619 if (m_radioWidth[0]>0)
620 y_offset += cy1/2;
621 }
622 }
623
624 int widthBtn;
625 if ( isLastInTheRow )
626 {
627 // make the button go to the end of radio box
628 widthBtn = startX + width - x_offset - 2*cx1;
629 if ( widthBtn < maxWidth )
630 widthBtn = maxWidth;
631 }
632 else
633 {
634 // normal button, always of the same size
635 widthBtn = maxWidth;
636 }
637
638 // make all buttons of the same, maximal size - like this they cover
639 // the radiobox entirely and the radiobox tooltips are always shown
640 // (otherwise they are not when the mouse pointer is in the radiobox
641 // part not belonging to any radiobutton)
642 ::MoveWindow((*m_radioButtons)[i],
643 x_offset, y_offset, widthBtn, maxHeight,
644 TRUE);
645
646 // where do we put the next button?
647 if ( m_windowStyle & wxRA_SPECIFY_ROWS )
648 {
649 // below this one
650 y_offset += maxHeight;
651 if (m_radioWidth[0]>0)
652 y_offset += cy1/2;
653 }
654 else
655 {
656 // to the right of this one
657 x_offset += widthBtn + cx1;
658 }
659 }
660 if (hdwp)
661 {
662 // Store the size so we can report it accurately
663 wxExtraWindowData* extraData = (wxExtraWindowData*) m_windowReserved;
664 if (!extraData)
665 {
666 extraData = new wxExtraWindowData;
667 m_windowReserved = (void*) extraData;
668 }
669 extraData->m_pos = wxPoint(xx, yy);
670 extraData->m_size = wxSize(width, height);
671 extraData->m_deferring = true;
672
673 // hdwp must be updated as it may have been changed
674 parent->m_hDWP = (WXHANDLE)hdwp;
675 }
676 }
677
678 // ----------------------------------------------------------------------------
679 // radio box drawing
680 // ----------------------------------------------------------------------------
681
682 #ifndef __WXWINCE__
683
684 WXHRGN wxRadioBox::MSWGetRegionWithoutChildren()
685 {
686 RECT rc;
687 ::GetWindowRect(GetHwnd(), &rc);
688 HRGN hrgn = ::CreateRectRgn(rc.left, rc.top, rc.right + 1, rc.bottom + 1);
689
690 const size_t count = GetCount();
691 for ( size_t i = 0; i < count; ++i )
692 {
693 ::GetWindowRect((*m_radioButtons)[i], &rc);
694 AutoHRGN hrgnchild(::CreateRectRgnIndirect(&rc));
695 ::CombineRgn(hrgn, hrgn, hrgnchild, RGN_DIFF);
696 }
697
698 return (WXHRGN)hrgn;
699 }
700
701 WXLRESULT
702 wxRadioBox::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
703 {
704 if ( nMsg == WM_PRINTCLIENT )
705 {
706 // we have to process WM_PRINTCLIENT ourselves as otherwise the radio
707 // buttons background would never be drawn unless we have a parent with
708 // non default background
709
710 // so check first if we have one
711 if ( !HandlePrintClient((WXHDC)wParam) )
712 {
713 // no, we don't, erase the background ourselves (don't use our own
714 // colour as with static box, see comments there)
715 wxBrush brush(GetParent()->GetBackgroundColour());
716 wxFillRect(GetHwnd(), (HDC)wParam, GetHbrushOf(brush));
717 }
718
719 return 0;
720 }
721 // FIXME: Without this, the radiobox corrupts other controls as it moves
722 // in a dynamic layout. Refreshing causes flicker, but it's better than
723 // leaving droppings. Note that for some reason, wxStaticBox doesn't need
724 // this (perhaps because it has no real children?)
725 else if (nMsg == WM_MOVE)
726 {
727 WXLRESULT res = wxControl::MSWWindowProc(nMsg, wParam, lParam);
728 wxRect rect = GetRect();
729 GetParent()->Refresh(true, & rect);
730 return res;
731 }
732
733 return wxStaticBox::MSWWindowProc(nMsg, wParam, lParam);
734 }
735
736 #endif // __WXWINCE__
737
738 // ---------------------------------------------------------------------------
739 // window proc for radio buttons
740 // ---------------------------------------------------------------------------
741
742 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
743 UINT message,
744 WPARAM wParam,
745 LPARAM lParam)
746 {
747 switch ( message )
748 {
749 case WM_GETDLGCODE:
750 // we must tell IsDialogMessage()/our kbd processing code that we
751 // want to process arrows ourselves because neither of them is
752 // smart enough to handle arrows properly for us
753 {
754 long lDlgCode = ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd,
755 message, wParam, lParam);
756
757 return lDlgCode | DLGC_WANTARROWS;
758 }
759
760 #if wxUSE_TOOLTIPS
761 case WM_NOTIFY:
762 {
763 NMHDR* hdr = (NMHDR *)lParam;
764 if ( hdr->code == TTN_NEEDTEXT )
765 {
766 wxRadioBox *
767 radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
768
769 wxCHECK_MSG( radiobox, 0,
770 wxT("radio button without radio box?") );
771
772 wxToolTip *tooltip = radiobox->GetToolTip();
773 if ( tooltip )
774 {
775 TOOLTIPTEXT *ttt = (TOOLTIPTEXT *)lParam;
776 ttt->lpszText = (wxChar *)tooltip->GetTip().c_str();
777 }
778
779 // processed
780 return 0;
781 }
782 }
783 break;
784 #endif // wxUSE_TOOLTIPS
785
786 case WM_KEYDOWN:
787 {
788 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
789
790 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
791
792 bool processed = true;
793
794 wxDirection dir;
795 switch ( wParam )
796 {
797 case VK_UP:
798 dir = wxUP;
799 break;
800
801 case VK_LEFT:
802 dir = wxLEFT;
803 break;
804
805 case VK_DOWN:
806 dir = wxDOWN;
807 break;
808
809 case VK_RIGHT:
810 dir = wxRIGHT;
811 break;
812
813 default:
814 processed = false;
815
816 // just to suppress the compiler warning
817 dir = wxALL;
818 }
819
820 if ( processed )
821 {
822 int selOld = radiobox->GetSelection();
823 int selNew = radiobox->GetNextItem
824 (
825 selOld,
826 dir,
827 radiobox->GetWindowStyle()
828 );
829
830 if ( selNew != selOld )
831 {
832 radiobox->SetSelection(selNew);
833 radiobox->SetFocus();
834
835 // emulate the button click
836 radiobox->SendNotificationEvent();
837
838 return 0;
839 }
840 }
841 }
842 break;
843
844 case WM_SETFOCUS:
845 case WM_KILLFOCUS:
846 {
847 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
848
849 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
850
851 // if we don't do this, no focus events are generated for the
852 // radiobox and, besides, we need to notify the parent about
853 // the focus change, otherwise the focus handling logic in
854 // wxControlContainer doesn't work
855 if ( message == WM_SETFOCUS )
856 radiobox->HandleSetFocus((WXHWND)wParam);
857 else
858 radiobox->HandleKillFocus((WXHWND)wParam);
859 }
860 break;
861
862 #ifndef __WXWINCE__
863 case WM_HELP:
864 {
865 wxRadioBox *radiobox = (wxRadioBox *)wxGetWindowUserData(hwnd);
866
867 wxCHECK_MSG( radiobox, 0, wxT("radio button without radio box?") );
868
869 bool processed = false;
870
871 wxEvtHandler * const handler = radiobox->GetEventHandler();
872
873 HELPINFO* info = (HELPINFO*) lParam;
874 if ( info->iContextType == HELPINFO_WINDOW )
875 {
876 for ( wxWindow* subjectOfHelp = radiobox;
877 subjectOfHelp;
878 subjectOfHelp = subjectOfHelp->GetParent() )
879 {
880 wxHelpEvent helpEvent(wxEVT_HELP,
881 subjectOfHelp->GetId(),
882 wxPoint(info->MousePos.x,
883 info->MousePos.y));
884 helpEvent.SetEventObject(radiobox);
885 if ( handler->ProcessEvent(helpEvent) )
886 {
887 processed = true;
888 break;
889 }
890 }
891 }
892 else if (info->iContextType == HELPINFO_MENUITEM)
893 {
894 wxHelpEvent helpEvent(wxEVT_HELP, info->iCtrlId);
895 helpEvent.SetEventObject(radiobox);
896 processed = handler->ProcessEvent(helpEvent);
897 }
898
899 if ( processed )
900 return 0;
901 }
902 break;
903 #endif // !__WXWINCE__
904 }
905
906 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, message, wParam, lParam);
907 }
908
909 #endif // wxUSE_RADIOBOX
910