diff --git a/include/wx/msw/radiobox.h b/include/wx/msw/radiobox.h index caab028ae7..db7ad5f524 100644 --- a/include/wx/msw/radiobox.h +++ b/include/wx/msw/radiobox.h @@ -90,6 +90,7 @@ public: // Implementation WXHWND *GetRadioButtons() const { return m_radioButtons; } bool ContainsHWND(WXHWND hWnd) const; + void SendNotificationEvent(); long MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index eff9d9a74b..5d237df03d 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -105,24 +105,27 @@ bool wxRadioBox::MSWCommand(WXUINT param, WXWORD id) { if ( param == BN_CLICKED ) { - m_selectedButton = -1; + int selectedButton = -1; for ( int i = 0; i < m_noItems; i++ ) { if ( id == GET_WIN_ID(m_radioButtons[i]) ) { - m_selectedButton = i; + selectedButton = i; break; } } - wxASSERT_MSG( m_selectedButton != -1, "click from alien button?" ); + wxASSERT_MSG( selectedButton != -1, "click from alien button?" ); - wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId); - event.SetInt( m_selectedButton ); - event.SetEventObject( this ); - ProcessCommand(event); + if ( selectedButton != m_selectedButton ) + { + m_selectedButton = selectedButton; + + SendNotificationEvent(); + } + //else: don't generate events when the selection doesn't change return TRUE; } @@ -708,7 +711,6 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) if ( !s_wndprocRadioBtn ) s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC); -// s_wndprocRadioBtn = (WNDPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC); // No GWL_USERDATA in Win16, so omit this subclassing. #ifdef __WIN32__ @@ -717,6 +719,14 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) #endif } +void wxRadioBox::SendNotificationEvent() +{ + wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId); + event.SetInt( m_selectedButton ); + event.SetEventObject( this ); + ProcessCommand(event); +} + // --------------------------------------------------------------------------- // window proc for radio buttons // --------------------------------------------------------------------------- @@ -777,7 +787,12 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd, if ( processed ) { if ( sel >= 0 && sel < radiobox->Number() ) + { radiobox->SetSelection(sel); + + // emulate the button click + radiobox->SendNotificationEvent(); + } } }