]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/radiobox.cpp
fixed to make wxVariant compatible with both ANSI and Unicode modes
[wxWidgets.git] / src / msw / radiobox.cpp
index 95f6f127c47762f878edb580a24af2b73e4e5ccf..f73e2ba3c2d36bd234b681afd6e540261669b952 100644 (file)
@@ -170,7 +170,7 @@ bool wxRadioBox::Create(wxWindow *parent,
         long newId = NewControlId();
 
         HWND hwndBtn = ::CreateWindow(_T("BUTTON"),
-                                      choices[i],
+                                      choices[i].wx_str(),
                                       styleBtn,
                                       0, 0, 0, 0,   // will be set in SetSize()
                                       GetHwndOf(parent),
@@ -270,9 +270,14 @@ bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id)
         const unsigned int count = GetCount();
         for ( unsigned int i = 0; i < count; i++ )
         {
-            if ( id == wxGetWindowId((*m_radioButtons)[i]) )
+            const HWND hwndBtn = (*m_radioButtons)[i];
+            if ( id == wxGetWindowId(hwndBtn) )
             {
-                selectedButton = i;
+                // we can get BN_CLICKED for a button which just became focused
+                // but it may not be checked, in which case we shouldn't
+                // generate a radiobox selection changed event for it
+                if ( ::SendMessage(hwndBtn, BM_GETCHECK, 0, 0) == BST_CHECKED )
+                    selectedButton = i;
 
                 break;
             }
@@ -323,7 +328,7 @@ void wxRadioBox::SendNotificationEvent()
 
 unsigned int wxRadioBox::GetCount() const
 {
-    return m_radioButtons->GetCount();
+    return m_radioButtons ? m_radioButtons->GetCount() : 0u;
 }
 
 void wxRadioBox::SetString(unsigned int item, const wxString& label)
@@ -505,6 +510,13 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const
 
 wxSize wxRadioBox::DoGetBestSize() const
 {
+    if ( !m_radioButtons )
+    {
+        // if we're not fully initialized yet, we can't meaningfully compute
+        // our best size, we'll do it later
+        return wxSize(1, 1);
+    }
+
     wxSize best = GetTotalButtonSize(GetMaxButtonSize());
     CacheBestSize(best);
     return best;