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),
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;
}
// 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())
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;
}
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)
// 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;
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;