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:
@@ -51,7 +51,7 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
// common part of Append and Insert
|
// 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);
|
void Init(size_t n, wxMenu *menus[], const wxString titles[], long style);
|
||||||
|
|
||||||
@@ -99,7 +99,7 @@ private:
|
|||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
// common part of Append (if pos == -1) and Insert
|
// 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)
|
DECLARE_DYNAMIC_CLASS(wxMenu)
|
||||||
|
@@ -230,13 +230,15 @@ void wxMenuBar::Detach()
|
|||||||
|
|
||||||
bool wxMenuBar::Append( wxMenu *menu, const wxString &title )
|
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 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());
|
menu->SetLayoutDirection(GetLayoutDirection());
|
||||||
|
|
||||||
@@ -251,7 +253,10 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
|
|||||||
const wxString str(wxStripMenuCodes(item->GetItemLabel()));
|
const wxString str(wxStripMenuCodes(item->GetItemLabel()));
|
||||||
|
|
||||||
if ( item->IsSubMenu() )
|
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 ) );
|
menu->m_owner = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( str ) );
|
||||||
|
|
||||||
@@ -282,21 +287,16 @@ bool wxMenuBar::GtkAppend(wxMenu *menu, const wxString& title, int pos)
|
|||||||
|
|
||||||
if ( m_menuBarFrame )
|
if ( m_menuBarFrame )
|
||||||
AttachToFrame( menu, m_menuBarFrame );
|
AttachToFrame( menu, m_menuBarFrame );
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
|
bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
|
||||||
{
|
{
|
||||||
if ( !wxMenuBarBase::Insert(pos, menu, title) )
|
if (wxMenuBarBase::Insert(pos, menu, title))
|
||||||
return false;
|
{
|
||||||
|
GtkAppend(menu, title, int(pos));
|
||||||
// TODO
|
|
||||||
|
|
||||||
if ( !GtkAppend(menu, title, (int)pos) )
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
||||||
@@ -745,7 +745,7 @@ wxString wxMenu::GetTitle() const
|
|||||||
return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
|
return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
void wxMenu::GtkAppend(wxMenuItem* mitem, int pos)
|
||||||
{
|
{
|
||||||
GtkWidget *menuItem;
|
GtkWidget *menuItem;
|
||||||
switch (mitem->GetKind())
|
switch (mitem->GetKind())
|
||||||
@@ -763,9 +763,9 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
|||||||
wxMenuItem* radioGroupItem = NULL;
|
wxMenuItem* radioGroupItem = NULL;
|
||||||
|
|
||||||
const size_t numItems = GetMenuItemCount();
|
const size_t numItems = GetMenuItemCount();
|
||||||
const size_t n = pos == -1 ? numItems
|
const size_t n = pos == -1 ? numItems - 1 : size_t(pos);
|
||||||
: static_cast<size_t>(pos);
|
|
||||||
if ( n > 0 )
|
if (n != 0)
|
||||||
{
|
{
|
||||||
wxMenuItem* const itemPrev = FindItemByPosition(n - 1);
|
wxMenuItem* const itemPrev = FindItemByPosition(n - 1);
|
||||||
if ( itemPrev->GetKind() == wxITEM_RADIO )
|
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 )
|
if ( itemNext->GetKind() == wxITEM_RADIO )
|
||||||
{
|
{
|
||||||
// Inserting an item before an existing radio item
|
// Inserting an item before an existing radio item
|
||||||
@@ -850,24 +850,26 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
|||||||
mitem);
|
mitem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
|
wxMenuItem* wxMenu::DoAppend(wxMenuItem *mitem)
|
||||||
{
|
{
|
||||||
if (!GtkAppend(mitem))
|
if (wxMenuBase::DoAppend(mitem))
|
||||||
|
{
|
||||||
|
GtkAppend(mitem);
|
||||||
|
return mitem;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return wxMenuBase::DoAppend(mitem);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenuItem* wxMenu::DoInsert(size_t pos, wxMenuItem *item)
|
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 NULL;
|
||||||
|
|
||||||
return wxMenuBase::DoInsert(pos, item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
|
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item)
|
||||||
|
Reference in New Issue
Block a user