]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/radiobox.cpp
* Committing new wxSocket core (socket.cpp sckint.cpp). It has to be improved ...
[wxWidgets.git] / src / msw / radiobox.cpp
index 6ce66a88eac8eec6e005b2891a9d357bc70b47d0..5d237df03d7d4acfb05dcb2a7e85dbd295ebacdf 100644 (file)
 #endif // Win32/16
 
 // wnd proc for radio buttons
+#ifdef __WIN32__
 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hWnd,
                                            UINT message,
                                            WPARAM wParam,
                                            LPARAM lParam);
+#endif
 
 // ---------------------------------------------------------------------------
 // global vars
 // ---------------------------------------------------------------------------
 
 // the pointer to standard radio button wnd proc
-static WNDPROC s_wndprocRadioBtn = (WNDPROC)NULL;
+// static WNDPROC s_wndprocRadioBtn = (WNDPROC)NULL;
+static WXFARPROC s_wndprocRadioBtn = (WXFARPROC)NULL;
 
 // ===========================================================================
 // implementation
@@ -102,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?" );
+
+        if ( selectedButton != m_selectedButton )
+        {
+            m_selectedButton = selectedButton;
 
-        wxCommandEvent event(wxEVT_COMMAND_RADIOBOX_SELECTED, m_windowId);
-        event.SetInt( m_selectedButton );
-        event.SetEventObject( this );
-        ProcessCommand(event);
+            SendNotificationEvent();
+        }
+        //else: don't generate events when the selection doesn't change
 
         return TRUE;
     }
@@ -704,16 +710,29 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn)
     HWND hwndBtn = (HWND)hWndBtn;
 
     if ( !s_wndprocRadioBtn )
-        s_wndprocRadioBtn = (WNDPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
+        s_wndprocRadioBtn = (WXFARPROC)::GetWindowLong(hwndBtn, GWL_WNDPROC);
 
+    // No GWL_USERDATA in Win16, so omit this subclassing.
+#ifdef __WIN32__
     ::SetWindowLong(hwndBtn, GWL_WNDPROC, (long)wxRadioBtnWndProc);
     ::SetWindowLong(hwndBtn, GWL_USERDATA, (long)this);
+#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
 // ---------------------------------------------------------------------------
 
+#ifdef __WIN32__
+
 LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
                                            UINT msg,
                                            WPARAM wParam,
@@ -768,13 +787,19 @@ LRESULT APIENTRY _EXPORT wxRadioBtnWndProc(HWND hwnd,
         if ( processed )
         {
             if ( sel >= 0 && sel < radiobox->Number() )
+            {
                 radiobox->SetSelection(sel);
+
+                // emulate the button click
+                radiobox->SendNotificationEvent();
+            }
         }
     }
 
     if ( !processed )
-        return ::CallWindowProc(s_wndprocRadioBtn, hwnd, msg, wParam, lParam);
+        return ::CallWindowProc(CASTWNDPROC s_wndprocRadioBtn, hwnd, msg, wParam, lParam);
     else
         return 0;
 }
+#endif