]> git.saurik.com Git - wxWidgets.git/commitdiff
radiobox now sends notification messages when the selection is changed from
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 17 Apr 1999 20:29:40 +0000 (20:29 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 17 Apr 1999 20:29:40 +0000 (20:29 +0000)
keyboard, but doesn't send them when the selection does not change (when the
already selected button is clicked with the mouse)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2221 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/radiobox.h
src/msw/radiobox.cpp

index caab028ae7d7f55069b8f5ae0098dc7c0ee7376c..db7ad5f524fe7bc1b19b3a9990a39846b2445b3d 100644 (file)
@@ -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);
 
index eff9d9a74b40ead73566f4e5041deb73d8082fe1..5d237df03d7d4acfb05dcb2a7e85dbd295ebacdf 100644 (file)
@@ -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();
+            }
         }
     }