1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/radiobox.cpp
3 // Purpose: wxRadioBox implementation
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "radiobox.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/bitmap.h"
36 #include "wx/radiobox.h"
37 #include "wx/settings.h"
41 #include "wx/msw/private.h"
44 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
47 #include "wx/tooltip.h"
48 #endif // wxUSE_TOOLTIPS
50 // TODO: wxCONSTRUCTOR
51 #if 0 // wxUSE_EXTENDED_RTTI
52 WX_DEFINE_FLAGS( wxRadioBoxStyle
)
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
)
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
)
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
)
82 wxFLAGS_MEMBER(wxRA_SPECIFY_COLS
)
83 wxFLAGS_MEMBER(wxRA_HORIZONTAL
)
84 wxFLAGS_MEMBER(wxRA_SPECIFY_ROWS
)
85 wxFLAGS_MEMBER(wxRA_VERTICAL
)
87 wxEND_FLAGS( wxRadioBoxStyle
)
89 IMPLEMENT_DYNAMIC_CLASS_XTI(wxRadioBox
, wxControl
,"wx/radiobox.h")
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()
97 IMPLEMENT_DYNAMIC_CLASS(wxRadioBox
, wxControl
)
108 // there are two possible ways to create the radio buttons: either as children
109 // of the radiobox or as siblings of it - allow playing with both variants for
110 // now, eventually we will choose the best one for our purposes
112 // two main problems are the keyboard navigation inside the radiobox (arrows
113 // should switch between buttons, not pass focus to the next control) and the
114 // tooltips - a tooltip is associated with the radiobox itself, not the
117 // the problems with setting this to 1:
118 // a) Alt-<mnemonic of radiobox> isn't handled properly by IsDialogMessage()
119 // because it sets focus to the next control accepting it which is not a
120 // radio button but a radiobox sibling in this case - the only solution to
121 // this would be to handle Alt-<mnemonic> ourselves
122 // b) the problems with setting radiobox colours under Win98/2K were reported
123 // but I couldn't reproduce it so I have no idea about what causes it
125 // the problems with setting this to 0:
126 // a) the tooltips are not shown for the radiobox - possible solution: make
127 // TTM_WINDOWFROMPOS handling code in msw/tooltip.cpp work (easier said than
128 // done because I don't know why it doesn't work)
129 #define RADIOBTN_PARENT_IS_RADIOBOX 0
131 // ---------------------------------------------------------------------------
133 // ---------------------------------------------------------------------------
135 // wnd proc for radio buttons
137 LRESULT APIENTRY _EXPORT
wxRadioBtnWndProc(HWND hWnd
,
142 // ---------------------------------------------------------------------------
144 // ---------------------------------------------------------------------------
146 // the pointer to standard radio button wnd proc
147 static WXFARPROC s_wndprocRadioBtn
= (WXFARPROC
)NULL
;
151 // ===========================================================================
153 // ===========================================================================
155 // ---------------------------------------------------------------------------
157 // ---------------------------------------------------------------------------
159 int wxRadioBox::GetCount() const
164 int wxRadioBox::GetColumnCount() const
169 int wxRadioBox::GetRowCount() const
174 // returns the number of rows
175 int wxRadioBox::GetNumVer() const
177 if ( m_windowStyle
& wxRA_SPECIFY_ROWS
)
183 return (m_noItems
+ m_majorDim
- 1)/m_majorDim
;
187 // returns the number of columns
188 int wxRadioBox::GetNumHor() const
190 if ( m_windowStyle
& wxRA_SPECIFY_ROWS
)
192 return (m_noItems
+ m_majorDim
- 1)/m_majorDim
;
200 bool wxRadioBox::MSWCommand(WXUINT cmd
, WXWORD id
)
202 if ( cmd
== BN_CLICKED
)
207 int selectedButton
= -1;
209 for ( int i
= 0; i
< m_noItems
; i
++ )
211 if ( id
== wxGetWindowId(m_radioButtons
[i
]) )
219 if ( selectedButton
== -1 )
221 // just ignore it - due to a hack with WM_NCHITTEST handling in our
222 // wnd proc, we can receive dummy click messages when we click near
223 // the radiobox edge (this is ugly but Julian wouldn't let me get
228 if ( selectedButton
!= m_selectedButton
)
230 m_selectedButton
= selectedButton
;
232 SendNotificationEvent();
234 //else: don't generate events when the selection doesn't change
243 wxRadioBox::wxRadioBox()
245 m_selectedButton
= -1;
248 m_radioButtons
= NULL
;
251 m_radioHeight
= NULL
;
254 bool wxRadioBox::Create(wxWindow
*parent
,
256 const wxString
& title
,
260 const wxString choices
[],
263 const wxValidator
& val
,
264 const wxString
& name
)
266 // initialize members
267 m_selectedButton
= -1;
270 m_majorDim
= majorDim
== 0 ? n
: majorDim
;
271 m_noRowsOrCols
= majorDim
;
273 // common initialization
274 if ( !CreateControl(parent
, id
, pos
, size
, style
, val
, name
) )
277 // create the static box
278 if ( !MSWCreateControl(wxT("BUTTON"), BS_GROUPBOX
| WS_GROUP
,
279 pos
, size
, title
, 0) )
282 // and now create the buttons
284 #if RADIOBTN_PARENT_IS_RADIOBOX
285 HWND hwndParent
= GetHwnd();
287 HWND hwndParent
= GetHwndOf(parent
);
290 // Some radio boxes test consecutive id.
291 (void)NewControlId();
292 m_radioButtons
= new WXHWND
[n
];
293 m_radioWidth
= new int[n
];
294 m_radioHeight
= new int[n
];
297 wxFont font
= GetFont();
300 hfont
= font
.GetResourceHandle();
303 for ( int i
= 0; i
< n
; i
++ )
306 m_radioHeight
[i
] = -1;
307 long styleBtn
= BS_AUTORADIOBUTTON
| WS_TABSTOP
| WS_CHILD
| WS_VISIBLE
;
308 if ( i
== 0 && style
== 0 )
309 styleBtn
|= WS_GROUP
;
311 long newId
= NewControlId();
313 HWND hwndBtn
= ::CreateWindow(_T("BUTTON"),
316 0, 0, 0, 0, // will be set in SetSize()
324 wxLogLastError(wxT("CreateWindow(radio btn)"));
329 m_radioButtons
[i
] = (WXHWND
)hwndBtn
;
331 SubclassRadioButton((WXHWND
)hwndBtn
);
335 ::SendMessage(hwndBtn
, WM_SETFONT
, (WPARAM
)hfont
, 0L);
338 m_subControls
.Add(newId
);
341 // Create a dummy radio control to end the group.
342 (void)::CreateWindow(_T("BUTTON"),
344 WS_GROUP
| BS_AUTORADIOBUTTON
| WS_CHILD
,
345 0, 0, 0, 0, hwndParent
,
346 (HMENU
)NewControlId(), wxGetInstance(), NULL
);
349 SetSize(pos
.x
, pos
.y
, size
.x
, size
.y
);
351 // Now that we have items determine what is the best size and set it.
357 bool wxRadioBox::Create(wxWindow
*parent
,
359 const wxString
& title
,
362 const wxArrayString
& choices
,
365 const wxValidator
& val
,
366 const wxString
& name
)
368 wxCArrayString
chs(choices
);
369 return Create(parent
, id
, title
, pos
, size
, chs
.GetCount(),
370 chs
.GetStrings(), majorDim
, style
, val
, name
);
373 wxRadioBox::~wxRadioBox()
375 m_isBeingDeleted
= TRUE
;
380 for (i
= 0; i
< m_noItems
; i
++)
381 ::DestroyWindow((HWND
)m_radioButtons
[i
]);
382 delete[] m_radioButtons
;
386 delete[] m_radioWidth
;
388 delete[] m_radioHeight
;
392 void wxRadioBox::SetString(int item
, const wxString
& label
)
394 wxCHECK_RET( item
>= 0 && item
< m_noItems
, wxT("invalid radiobox index") );
396 m_radioWidth
[item
] = m_radioHeight
[item
] = -1;
397 SetWindowText((HWND
)m_radioButtons
[item
], label
.c_str());
400 void wxRadioBox::SetSelection(int N
)
402 wxCHECK_RET( (N
>= 0) && (N
< m_noItems
), wxT("invalid radiobox index") );
404 // Following necessary for Win32s, because Win32s translate BM_SETCHECK
405 if (m_selectedButton
>= 0 && m_selectedButton
< m_noItems
)
406 ::SendMessage((HWND
) m_radioButtons
[m_selectedButton
], BM_SETCHECK
, 0, 0L);
408 ::SendMessage((HWND
)m_radioButtons
[N
], BM_SETCHECK
, 1, 0L);
410 m_selectedButton
= N
;
413 // Get single selection, for single choice list items
414 int wxRadioBox::GetSelection() const
416 return m_selectedButton
;
419 // Find string for position
420 wxString
wxRadioBox::GetString(int item
) const
422 wxCHECK_MSG( item
>= 0 && item
< m_noItems
, wxEmptyString
,
423 wxT("invalid radiobox index") );
425 return wxGetWindowText(m_radioButtons
[item
]);
428 // ----------------------------------------------------------------------------
430 // ----------------------------------------------------------------------------
432 wxSize
wxRadioBox::GetMaxButtonSize() const
434 // calculate the max button size
437 for ( int i
= 0 ; i
< m_noItems
; i
++ )
440 if ( m_radioWidth
[i
] < 0 )
442 GetTextExtent(wxGetWindowText(m_radioButtons
[i
]), &width
, &height
);
444 // adjust the size to take into account the radio box itself
445 // FIXME this is totally bogus!
452 width
= m_radioWidth
[i
];
453 height
= m_radioHeight
[i
];
456 if ( widthMax
< width
)
458 if ( heightMax
< height
)
462 return wxSize(widthMax
, heightMax
);
465 wxSize
wxRadioBox::GetTotalButtonSize(const wxSize
& sizeBtn
) const
467 // the radiobox should be big enough for its buttons
469 wxGetCharSize(m_hWnd
, &cx1
, &cy1
, GetFont());
471 int extraHeight
= cy1
;
473 /* We'll assume the adjustments below are OK for Win 3.1 too
474 #if defined(CTL3D) && !CTL3D
475 // Requires a bigger group box in plain Windows
481 int height
= GetNumVer() * sizeBtn
.y
+ cy1
/2 + extraHeight
;
482 int width
= GetNumHor() * (sizeBtn
.x
+ cx1
) + cx1
;
484 // Add extra space under the label, if it exists.
485 if (!wxControl::GetLabel().IsEmpty())
488 // and also wide enough for its label
490 GetTextExtent(GetTitle(), &widthLabel
, NULL
);
491 widthLabel
+= RADIO_SIZE
; // FIXME this is bogus too
492 if ( widthLabel
> width
)
495 return wxSize(width
, height
);
498 wxSize
wxRadioBox::DoGetBestSize() const
500 return GetTotalButtonSize(GetMaxButtonSize());
503 // Restored old code.
504 void wxRadioBox::DoSetSize(int x
, int y
, int width
, int height
, int sizeFlags
)
506 int currentX
, currentY
;
507 GetPosition(¤tX
, ¤tY
);
508 int widthOld
, heightOld
;
509 GetSize(&widthOld
, &heightOld
);
514 if (x
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
516 if (y
== -1 && !(sizeFlags
& wxSIZE_ALLOW_MINUS_ONE
))
519 #if RADIOBTN_PARENT_IS_RADIOBOX
528 wxGetCharSize(m_hWnd
, &cx1
, &cy1
, GetFont());
530 // Attempt to have a look coherent with other platforms: We compute the
531 // biggest toggle dim, then we align all items according this value.
532 wxSize maxSize
= GetMaxButtonSize();
533 int maxWidth
= maxSize
.x
,
534 maxHeight
= maxSize
.y
;
536 wxSize totSize
= GetTotalButtonSize(maxSize
);
537 int totWidth
= totSize
.x
,
538 totHeight
= totSize
.y
;
540 // only change our width/height if asked for
543 if ( sizeFlags
& wxSIZE_AUTO_WIDTH
)
551 if ( sizeFlags
& wxSIZE_AUTO_HEIGHT
)
557 ::MoveWindow(GetHwnd(), xx
, yy
, width
, height
, TRUE
);
559 // Now position all the buttons: the current button will be put at
560 // wxPoint(x_offset, y_offset) and the new row/column will start at
561 // startX/startY. The size of all buttons will be the same wxSize(maxWidth,
562 // maxHeight) except for the buttons in the last column which should extend
563 // to the right border of radiobox and thus can be wider than this.
565 // Also, remember that wxRA_SPECIFY_COLS means that we arrange buttons in
566 // left to right order and m_majorDim is the number of columns while
567 // wxRA_SPECIFY_ROWS means that the buttons are arranged top to bottom and
568 // m_majorDim is the number of rows.
573 // Add extra space under the label, if it exists.
574 if (!wxControl::GetLabel().IsEmpty())
577 int startX
= x_offset
;
578 int startY
= y_offset
;
580 for ( int i
= 0; i
< m_noItems
; i
++ )
582 // the last button in the row may be wider than the other ones as the
583 // radiobox may be wider than the sum of the button widths (as it
584 // happens, for example, when the radiobox label is very long)
586 if ( m_windowStyle
& wxRA_SPECIFY_COLS
)
588 // item is the last in its row if it is a multiple of the number of
589 // columns or if it is just the last item
591 isLastInTheRow
= ((n
% m_majorDim
) == 0) || (n
== m_noItems
);
593 else // wxRA_SPECIFY_ROWS
595 // item is the last in the row if it is in the last columns
596 isLastInTheRow
= i
>= (m_noItems
/m_majorDim
)*m_majorDim
;
599 // is this the start of new row/column?
600 if ( i
&& (i
% m_majorDim
== 0) )
602 if ( m_windowStyle
& wxRA_SPECIFY_ROWS
)
604 // start of new column
606 x_offset
+= maxWidth
+ cx1
;
608 else // start of new row
611 y_offset
+= maxHeight
;
612 if (m_radioWidth
[0]>0)
618 if ( isLastInTheRow
)
620 // make the button go to the end of radio box
621 widthBtn
= startX
+ width
- x_offset
- 2*cx1
;
622 if ( widthBtn
< maxWidth
)
627 // normal button, always of the same size
631 // VZ: make all buttons of the same, maximal size - like this they
632 // cover the radiobox entirely and the radiobox tooltips are always
633 // shown (otherwise they are not when the mouse pointer is in the
634 // radiobox part not belonging to any radiobutton)
635 ::MoveWindow((HWND
)m_radioButtons
[i
],
636 x_offset
, y_offset
, widthBtn
, maxHeight
,
639 // where do we put the next button?
640 if ( m_windowStyle
& wxRA_SPECIFY_ROWS
)
643 y_offset
+= maxHeight
;
644 if (m_radioWidth
[0]>0)
649 // to the right of this one
650 x_offset
+= widthBtn
+ cx1
;
655 void wxRadioBox::GetSize(int *width
, int *height
) const
658 rect
.left
= -1; rect
.right
= -1; rect
.top
= -1; rect
.bottom
= -1;
661 wxFindMaxSize(m_hWnd
, &rect
);
664 for (i
= 0; i
< m_noItems
; i
++)
665 wxFindMaxSize(m_radioButtons
[i
], &rect
);
667 *width
= rect
.right
- rect
.left
;
668 *height
= rect
.bottom
- rect
.top
;
671 void wxRadioBox::GetPosition(int *x
, int *y
) const
673 wxWindow
*parent
= GetParent();
674 RECT rect
= { -1, -1, -1, -1 };
677 for (i
= 0; i
< m_noItems
; i
++)
678 wxFindMaxSize(m_radioButtons
[i
], &rect
);
681 wxFindMaxSize(m_hWnd
, &rect
);
683 // Since we now have the absolute screen coords, if there's a parent we
684 // must subtract its top left corner
690 ::ScreenToClient((HWND
) parent
->GetHWND(), &point
);
693 // We may be faking the client origin. So a window that's really at (0, 30)
694 // may appear (to wxWin apps) to be at (0, 0).
697 wxPoint
pt(GetParent()->GetClientAreaOrigin());
706 void wxRadioBox::SetFocus()
710 ::SetFocus((HWND
)m_radioButtons
[m_selectedButton
== -1
712 : m_selectedButton
]);
717 bool wxRadioBox::Show(bool show
)
719 if ( !wxControl::Show(show
) )
722 int nCmdShow
= show
? SW_SHOW
: SW_HIDE
;
723 for ( int i
= 0; i
< m_noItems
; i
++ )
725 ::ShowWindow((HWND
)m_radioButtons
[i
], nCmdShow
);
731 // Enable a specific button
732 void wxRadioBox::Enable(int item
, bool enable
)
734 wxCHECK_RET( item
>= 0 && item
< m_noItems
,
735 wxT("invalid item in wxRadioBox::Enable()") );
737 ::EnableWindow((HWND
) m_radioButtons
[item
], enable
);
740 // Enable all controls
741 bool wxRadioBox::Enable(bool enable
)
743 if ( !wxControl::Enable(enable
) )
746 for (int i
= 0; i
< m_noItems
; i
++)
747 ::EnableWindow((HWND
) m_radioButtons
[i
], enable
);
752 // Show a specific button
753 void wxRadioBox::Show(int item
, bool show
)
755 wxCHECK_RET( item
>= 0 && item
< m_noItems
,
756 wxT("invalid item in wxRadioBox::Show()") );
758 ::ShowWindow((HWND
)m_radioButtons
[item
], show
? SW_SHOW
: SW_HIDE
);
761 bool wxRadioBox::ContainsHWND(WXHWND hWnd
) const
763 size_t count
= GetCount();
764 for ( size_t i
= 0; i
< count
; i
++ )
766 if ( GetRadioButtons()[i
] == hWnd
)
773 void wxRadioBox::Command(wxCommandEvent
& event
)
775 SetSelection (event
.m_commandInt
);
777 ProcessCommand (event
);
780 // NB: if this code is changed, wxGetWindowForHWND() which relies on having the
781 // radiobox pointer in GWL_USERDATA for radio buttons must be updated too!
782 void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn
)
784 HWND hwndBtn
= (HWND
)hWndBtn
;
786 if ( !s_wndprocRadioBtn
)
787 s_wndprocRadioBtn
= (WXFARPROC
)wxGetWindowProc(hwndBtn
);
789 wxSetWindowProc(hwndBtn
, wxRadioBtnWndProc
);
790 wxSetWindowUserData(hwndBtn
, this);
793 void wxRadioBox::SendNotificationEvent()
795 wxCommandEvent
event(wxEVT_COMMAND_RADIOBOX_SELECTED
, m_windowId
);
796 event
.SetInt( m_selectedButton
);
797 event
.SetString( GetString(m_selectedButton
) );
798 event
.SetEventObject( this );
799 ProcessCommand(event
);
802 bool wxRadioBox::SetFont(const wxFont
& font
)
804 if ( !wxControl::SetFont(font
) )
810 // also set the font of our radio buttons
811 WXHFONT hfont
= wxFont(font
).GetResourceHandle();
812 for ( int n
= 0; n
< m_noItems
; n
++ )
814 HWND hwndBtn
= (HWND
)m_radioButtons
[n
];
815 ::SendMessage(hwndBtn
, WM_SETFONT
, (WPARAM
)hfont
, 0L);
817 // otherwise the buttons are not redrawn correctly
818 ::InvalidateRect(hwndBtn
, NULL
, FALSE
/* don't erase bg */);
824 // ----------------------------------------------------------------------------
826 // ----------------------------------------------------------------------------
828 WXLRESULT
wxRadioBox::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
833 case WM_CTLCOLORSTATIC
:
834 // set the colour of the radio buttons to be the same as ours
836 HDC hdc
= (HDC
)wParam
;
838 const wxColour
& colBack
= GetBackgroundColour();
839 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
840 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
842 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
844 return (WXLRESULT
)brush
->GetResourceHandle();
848 // VZ: this code breaks radiobox redrawing under Windows XP, don't use
849 // it. If you need to get messages from the static controls,
850 // create them as a child of another (non static) window
852 // This is required for the radiobox to be sensitive to mouse input,
853 // e.g. for Dialog Editor.
856 int xPos
= LOWORD(lParam
); // horizontal position of cursor
857 int yPos
= HIWORD(lParam
); // vertical position of cursor
859 ScreenToClient(&xPos
, &yPos
);
861 // Make sure you can drag by the top of the groupbox, but let
862 // other (enclosed) controls get mouse events also
864 return (long)HTCLIENT
;
870 return wxControl::MSWWindowProc(nMsg
, wParam
, lParam
);
873 WXHBRUSH
wxRadioBox::OnCtlColor(WXHDC pDC
, WXHWND
WXUNUSED(pWnd
), WXUINT
WXUNUSED(nCtlColor
),
879 WXUINT
WXUNUSED(message
),
880 WXWPARAM
WXUNUSED(wParam
),
881 WXLPARAM
WXUNUSED(lParam
)
888 HBRUSH hbrush
= Ctl3dCtlColorEx(message
, wParam
, lParam
);
889 return (WXHBRUSH
) hbrush
;
891 #endif // wxUSE_CTL3D
894 wxColour colBack
= GetBackgroundColour();
896 ::SetBkColor(hdc
, wxColourToRGB(colBack
));
897 ::SetTextColor(hdc
, wxColourToRGB(GetForegroundColour()));
899 wxBrush
*brush
= wxTheBrushList
->FindOrCreateBrush(colBack
, wxSOLID
);
901 return (WXHBRUSH
)brush
->GetResourceHandle();
905 // ---------------------------------------------------------------------------
906 // window proc for radio buttons
907 // ---------------------------------------------------------------------------
911 LRESULT APIENTRY _EXPORT
wxRadioBtnWndProc(HWND hwnd
,
919 // we must tell IsDialogMessage()/our kbd processing code that we
920 // want to process arrows ourselves because neither of them is
921 // smart enough to handle arrows properly for us
923 long lDlgCode
= ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn
, hwnd
,
924 message
, wParam
, lParam
);
926 return lDlgCode
| DLGC_WANTARROWS
;
932 NMHDR
* hdr
= (NMHDR
*)lParam
;
933 if ( hdr
->code
== TTN_NEEDTEXT
)
936 radiobox
= (wxRadioBox
*)wxGetWindowUserData(hwnd
);
938 wxCHECK_MSG( radiobox
, 0,
939 wxT("radio button without radio box?") );
941 wxToolTip
*tooltip
= radiobox
->GetToolTip();
944 TOOLTIPTEXT
*ttt
= (TOOLTIPTEXT
*)lParam
;
945 ttt
->lpszText
= (wxChar
*)tooltip
->GetTip().c_str();
953 #endif // wxUSE_TOOLTIPS
957 wxRadioBox
*radiobox
= (wxRadioBox
*)wxGetWindowUserData(hwnd
);
959 wxCHECK_MSG( radiobox
, 0, wxT("radio button without radio box?") );
961 bool processed
= TRUE
;
985 // just to suppress the compiler warning
991 int selOld
= radiobox
->GetSelection();
992 int selNew
= radiobox
->GetNextItem
996 radiobox
->GetWindowStyle()
999 if ( selNew
!= selOld
)
1001 radiobox
->SetSelection(selNew
);
1002 radiobox
->SetFocus();
1004 // emulate the button click
1005 radiobox
->SendNotificationEvent();
1016 wxRadioBox
*radiobox
= (wxRadioBox
*)wxGetWindowUserData(hwnd
);
1018 wxCHECK_MSG( radiobox
, 0, wxT("radio button without radio box?") );
1020 // if we don't do this, no focus events are generated for the
1021 // radiobox and, besides, we need to notify the parent about
1022 // the focus change, otherwise the focus handling logic in
1023 // wxControlContainer doesn't work
1024 if ( message
== WM_SETFOCUS
)
1025 radiobox
->HandleSetFocus((WXHWND
)wParam
);
1027 radiobox
->HandleKillFocus((WXHWND
)wParam
);
1034 wxRadioBox
*radiobox
= (wxRadioBox
*)wxGetWindowUserData(hwnd
);
1036 wxCHECK_MSG( radiobox
, 0, wxT("radio button without radio box?") );
1038 bool processed
wxDUMMY_INITIALIZE(true);
1040 // HELPINFO doesn't seem to be supported on WinCE.
1042 HELPINFO
* info
= (HELPINFO
*) lParam
;
1043 // Don't yet process menu help events, just windows
1044 if (info
->iContextType
== HELPINFO_WINDOW
)
1047 wxWindow
* subjectOfHelp
= radiobox
;
1048 bool eventProcessed
= FALSE
;
1049 while (subjectOfHelp
&& !eventProcessed
)
1051 wxHelpEvent
helpEvent(wxEVT_HELP
, subjectOfHelp
->GetId(),
1055 wxPoint(info
->MousePos
.x
, info
->MousePos
.y
)
1057 ) ; // info->iCtrlId);
1058 helpEvent
.SetEventObject(radiobox
);
1059 eventProcessed
= radiobox
->GetEventHandler()->ProcessEvent(helpEvent
);
1061 // Go up the window hierarchy until the event is handled (or not)
1062 subjectOfHelp
= subjectOfHelp
->GetParent();
1064 processed
= eventProcessed
;
1067 else if (info
->iContextType
== HELPINFO_MENUITEM
)
1069 wxHelpEvent
helpEvent(wxEVT_HELP
, info
->iCtrlId
) ;
1070 helpEvent
.SetEventObject(radiobox
);
1071 processed
= radiobox
->GetEventHandler()->ProcessEvent(helpEvent
);
1084 return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn
, hwnd
, message
, wParam
, lParam
);
1089 #endif // wxUSE_RADIOBOX