X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dc26eeb36a7415bd73d3e442c79b7acc0aeed6eb..d39a744d765cbfcab396a595178c4e98f5ea4cce:/src/msw/radiobox.cpp diff --git a/src/msw/radiobox.cpp b/src/msw/radiobox.cpp index 66534b1e2a..b29e5eb3e2 100644 --- a/src/msw/radiobox.cpp +++ b/src/msw/radiobox.cpp @@ -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), @@ -211,7 +211,7 @@ bool wxRadioBox::Create(wxWindow *parent, SetSize(pos.x, pos.y, size.x, size.y); // Now that we have items determine what is the best size and set it. - SetBestSize(size); + SetInitialSize(size); return true; } @@ -258,8 +258,10 @@ void wxRadioBox::SubclassRadioButton(WXHWND hWndBtn) // events generation // ---------------------------------------------------------------------------- -bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id) +bool wxRadioBox::MSWCommand(WXUINT cmd, WXWORD id_) { + const int id = (signed short)id_; + if ( cmd == BN_CLICKED ) { if (id == GetId()) @@ -270,9 +272,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 +330,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) @@ -495,7 +502,7 @@ wxSize wxRadioBox::GetTotalButtonSize(const wxSize& sizeBtn) const // and also wide enough for its label int widthLabel; - GetTextExtent(wxStripMenuCodes(GetLabel()), &widthLabel, NULL); + GetTextExtent(GetLabelText(), &widthLabel, NULL); widthLabel += RADIO_SIZE; // FIXME this is bogus too if ( widthLabel > width ) width = widthLabel; @@ -505,6 +512,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;