Rewrote wxMSW radio menu items code to support not only appending them.

Previously the radio menu items could only be appended to a menu in wxMSW,
inserting them (either in an existing radio group or to start a new one) not
only didn't work but could even result in crashes because invalid iterators in
the menu items list could be used.

Fix this by storing the ranges of all radio groups in wxMenu itself instead of
storing the information about the radio group an item belongs to in the item
itself and by updating this data whenever a new radio item is inserted. Also
get rid of the notion of "current radio group" in wxMenu which doesn't really
make any sense.

Finally add a unit test checking that inserting radio items works as expected.

Closes #13200.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67720 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-05-10 08:50:38 +00:00
parent a6ca624a27
commit 89511b4268
5 changed files with 194 additions and 129 deletions

View File

@@ -494,9 +494,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu,
void wxMenuItem::Init()
{
m_radioGroup.start = -1;
m_isRadioGroupStart = false;
#if wxUSE_OWNER_DRAWN
// when the color is not valid, wxOwnerDraw takes the default ones.
@@ -557,30 +554,6 @@ bool wxMenuItem::IsChecked() const
return (flag & MF_CHECKED) != 0;
}
// radio group stuff
// -----------------
void wxMenuItem::SetAsRadioGroupStart()
{
m_isRadioGroupStart = true;
}
void wxMenuItem::SetRadioGroupStart(int start)
{
wxASSERT_MSG( !m_isRadioGroupStart,
wxT("should only be called for the next radio items") );
m_radioGroup.start = start;
}
void wxMenuItem::SetRadioGroupEnd(int end)
{
wxASSERT_MSG( m_isRadioGroupStart,
wxT("should only be called for the first radio item") );
m_radioGroup.end = end;
}
// change item state
// -----------------
@@ -634,17 +607,10 @@ void wxMenuItem::Check(bool check)
int start,
end;
if ( m_isRadioGroupStart )
if ( !m_parentMenu->MSWGetRadioGroupRange(pos, &start, &end) )
{
// we already have all information we need
start = pos;
end = m_radioGroup.end;
}
else // next radio group item
{
// get the radio group end from the start item
start = m_radioGroup.start;
end = items.Item(start)->GetData()->m_radioGroup.end;
wxFAIL_MSG( wxT("Menu radio item not part of radio group?") );
return;
}
#ifdef __WIN32__