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