Fix crash when appending menuitem after removing it from another menu.

Also remove unused return value from GtkAppend

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@69878 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Paul Cornett
2011-12-01 06:57:44 +00:00
parent 516ed23a94
commit 0f29501b66
2 changed files with 37 additions and 35 deletions

View File

@@ -51,7 +51,7 @@ public:
private:
// common part of Append and Insert
bool GtkAppend(wxMenu *menu, const wxString& title, int pos=-1);
void GtkAppend(wxMenu* menu, const wxString& title, int pos = -1);
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
@@ -99,7 +99,7 @@ private:
void Init();
// common part of Append (if pos == -1) and Insert
bool GtkAppend(wxMenuItem *item, int pos=-1);
void GtkAppend(wxMenuItem* item, int pos = -1);
DECLARE_DYNAMIC_CLASS(wxMenu)

View File

@@ -230,13 +230,15 @@ void wxMenuBar::Detach()
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
{
if ( !wxMenuBarBase::Append( menu, title ) )
if (wxMenuBarBase::Append(menu, title))
{
GtkAppend(menu, title);
return true;
}
return false;
return GtkAppend(menu, title);
}
bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
void wxMenuBar::GtkAppend(wxMenu* menu, const wxString& title, int pos)
{
menu->SetLayoutDirection(GetLayoutDirection());
@@ -251,7 +253,10 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
const wxString str(wxStripMenuCodes(item->GetItemLabel()));
if ( item->IsSubMenu() )
return GtkAppend(item->GetSubMenu(), str, pos);
{
GtkAppend(item->GetSubMenu(), str, pos);
return;
}
menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
@@ -282,22 +287,17 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
if ( m_menuBarFrame )
AttachToFrame( menu, m_menuBarFrame );
return true;
}
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
{
if ( !wxMenuBarBase::Insert(pos, menu, title) )
return false;
// TODO
if ( !GtkAppend(menu, title, (int)pos) )
return false;
if (wxMenuBarBase::Insert(pos, menu, title))
{
GtkAppend(menu, title, int(pos));
return true;
}
return false;
}
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
{
@@ -745,7 +745,7 @@ wxString wxMenu::GetTitle() const
return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
}
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
void wxMenu::GtkAppend(wxMenuItem* mitem, int pos)
{
GtkWidget *menuItem;
switch (mitem->GetKind())
@@ -763,9 +763,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
wxMenuItem* radioGroupItem = NULL;
const size_t numItems = GetMenuItemCount();
const size_t n = pos == -1 ? numItems
: static_cast<size_t>(pos);
if ( n > 0 )
const size_t n = pos == -1 ? numItems - 1 : size_t(pos);
if (n != 0)
{
wxMenuItem* const itemPrev = FindItemByPosition(n - 1);
if ( itemPrev->GetKind() == wxITEM_RADIO )
@@ -776,9 +776,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
}
}
if ( n < numItems )
if (radioGroupItem == NULL && n != numItems - 1)
{
wxMenuItem* const itemNext = FindItemByPosition(n);
wxMenuItem* const itemNext = FindItemByPosition(n + 1);
if ( itemNext->GetKind() == wxITEM_RADIO )
{
// Inserting an item before an existing radio item
@@ -850,24 +850,26 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
mitem);
}
}
return true;
}
wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
{
if (!GtkAppend(mitem))
if (wxMenuBase::DoAppend(mitem))
{
GtkAppend(mitem);
return mitem;
}
return NULL;
return wxMenuBase::DoAppend(mitem);
}
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
{
if ( !GtkAppend(item, (int)pos) )
if (wxMenuBase::DoInsert(pos, item))
{
GtkAppend(item, int(pos));
return item;
}
return NULL;
return wxMenuBase::DoInsert(pos, item);
}
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)