]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/radiobut.cpp
Patch from OSAF that maintains radio button selection if Realize is recalled.
[wxWidgets.git] / src / msw / radiobut.cpp
index 2b3b4925cca385208aab87af2b2f59d5ca6f74cb..e88d6d7829b0dd21ea24c0dd930611c7f812909c 100644 (file)
@@ -168,6 +168,12 @@ void wxRadioButton::SetValue(bool value)
     // buttons in the same group: Windows doesn't do it automatically
     if ( m_isChecked )
     {
+        // If another radiobutton in the group currently has the focus, we have to 
+        // set it to this radiobutton, else the old readiobutton will be reselected
+        // automatically, if a parent window loses the focus and regains it.
+        bool shouldSetFocus = false;
+        wxWindow* pFocusWnd = FindFocus();
+
         const wxWindowList& siblings = GetParent()->GetChildren();
         wxWindowList::compatibility_iterator nodeThis = siblings.Find(this);
         wxCHECK_RET( nodeThis, _T("radio button not a child of its parent?") );
@@ -190,6 +196,9 @@ void wxRadioButton::SetValue(bool value)
                 
                 if (btn)
                 {
+                    if (btn == pFocusWnd)
+                        shouldSetFocus = true;
+
                     btn->SetValue(false);
 
                     if ( btn->HasFlag(wxRB_GROUP) )
@@ -217,8 +226,15 @@ void wxRadioButton::SetValue(bool value)
             }
 
             if (btn)
+            {
+                if (btn == pFocusWnd)
+                        shouldSetFocus = true;
+
                 btn->SetValue(false);
+            }
         }
+        if (shouldSetFocus)
+            SetFocus();
     }
 }
 
@@ -237,7 +253,7 @@ bool wxRadioButton::GetValue() const
 
 void wxRadioButton::Command (wxCommandEvent& event)
 {
-    SetValue(event.m_commandInt != 0);
+    SetValue(event.GetInt() != 0);
     ProcessCommand(event);
 }