]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/radiobut.cpp
reverted wxSocket changes of rev 48723 as they broke linking under non-Unix systems
[wxWidgets.git] / src / msw / radiobut.cpp
index c49c9600452cb02260bbf22e71f325bb96d042f5..dddab3e26a2d23f1a86d2e19068d3cf498e4d940 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        msw/radiobut.cpp
+// Name:        src/msw/radiobut.cpp
 // Purpose:     wxRadioButton
 // Author:      Julian Smart
 // Modified by:
 // headers
 // ----------------------------------------------------------------------------
 
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-    #pragma implementation "radiobut.h"
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -30,8 +26,9 @@
 
 #if wxUSE_RADIOBTN
 
+#include "wx/radiobut.h"
+
 #ifndef WX_PRECOMP
-    #include "wx/radiobut.h"
     #include "wx/settings.h"
     #include "wx/dcscreen.h"
 #endif
@@ -168,6 +165,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?") );
@@ -187,9 +190,12 @@ void wxRadioButton::SetValue(bool value)
                     // A wxRB_SINGLE button isn't part of this group
                     break;
                 }
-                
+
                 if (btn)
                 {
+                    if (btn == pFocusWnd)
+                        shouldSetFocus = true;
+
                     btn->SetValue(false);
 
                     if ( btn->HasFlag(wxRB_GROUP) )
@@ -217,8 +223,15 @@ void wxRadioButton::SetValue(bool value)
             }
 
             if (btn)
+            {
+                if (btn == pFocusWnd)
+                        shouldSetFocus = true;
+
                 btn->SetValue(false);
+            }
         }
+        if (shouldSetFocus)
+            SetFocus();
     }
 }
 
@@ -284,7 +297,7 @@ wxSize wxRadioButton::DoGetBestSize() const
     int wRadio, hRadio;
     if ( !str.empty() )
     {
-        GetTextExtent(str, &wRadio, &hRadio);
+        GetTextExtent(GetLabelText(str), &wRadio, &hRadio);
         wRadio += s_radioSize + GetCharWidth();
 
         if ( hRadio < s_radioSize )
@@ -296,8 +309,19 @@ wxSize wxRadioButton::DoGetBestSize() const
         hRadio = s_radioSize;
     }
 
-    return wxSize(wRadio, hRadio);
+    wxSize best(wRadio, hRadio);
+    CacheBestSize(best);
+    return best;
 }
 
-#endif // wxUSE_RADIOBTN
+WXDWORD wxRadioButton::MSWGetStyle(long style, WXDWORD *exstyle) const
+{
+    WXDWORD styleMSW = wxControl::MSWGetStyle(style, exstyle);
+
+    if ( style & wxRB_GROUP )
+        styleMSW |= WS_GROUP;
 
+    return styleMSW;
+}
+
+#endif // wxUSE_RADIOBTN