Added wxMenu::Delete() and fixed some menu deleted memory
leaks. Some. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -128,11 +128,11 @@ public:
|
||||
|
||||
~wxMenu();
|
||||
|
||||
// operations
|
||||
// title
|
||||
// title
|
||||
void SetTitle(const wxString& label);
|
||||
const wxString GetTitle() const;
|
||||
// menu creation
|
||||
|
||||
// menu creation
|
||||
void AppendSeparator();
|
||||
void Append(int id, const wxString &item,
|
||||
const wxString &helpStr = "", bool checkable = FALSE);
|
||||
@@ -141,6 +141,9 @@ public:
|
||||
void Append(wxMenuItem *pItem);
|
||||
void Break() { }
|
||||
|
||||
// delete item. don't delete the wxMenu if it's a submenu
|
||||
void Delete( int id );
|
||||
|
||||
// find item by name/id
|
||||
int FindItem( const wxString itemString ) const;
|
||||
wxMenuItem *FindItem( int id ) const;
|
||||
|
@@ -40,6 +40,7 @@ DECLARE_DYNAMIC_CLASS(wxMenuItem)
|
||||
|
||||
public:
|
||||
wxMenuItem();
|
||||
~wxMenuItem();
|
||||
|
||||
// accessors
|
||||
// id
|
||||
|
@@ -128,11 +128,11 @@ public:
|
||||
|
||||
~wxMenu();
|
||||
|
||||
// operations
|
||||
// title
|
||||
// title
|
||||
void SetTitle(const wxString& label);
|
||||
const wxString GetTitle() const;
|
||||
// menu creation
|
||||
|
||||
// menu creation
|
||||
void AppendSeparator();
|
||||
void Append(int id, const wxString &item,
|
||||
const wxString &helpStr = "", bool checkable = FALSE);
|
||||
@@ -141,6 +141,9 @@ public:
|
||||
void Append(wxMenuItem *pItem);
|
||||
void Break() { }
|
||||
|
||||
// delete item. don't delete the wxMenu if it's a submenu
|
||||
void Delete( int id );
|
||||
|
||||
// find item by name/id
|
||||
int FindItem( const wxString itemString ) const;
|
||||
wxMenuItem *FindItem( int id ) const;
|
||||
|
@@ -40,6 +40,7 @@ DECLARE_DYNAMIC_CLASS(wxMenuItem)
|
||||
|
||||
public:
|
||||
wxMenuItem();
|
||||
~wxMenuItem();
|
||||
|
||||
// accessors
|
||||
// id
|
||||
|
@@ -133,7 +133,9 @@ enum
|
||||
Menu_CopyBitmap,
|
||||
Menu_PasteBitmap,
|
||||
Menu_HasText,
|
||||
Menu_HasBitmap
|
||||
Menu_HasBitmap,
|
||||
Menu_ToBeGreyed, /* for testing */
|
||||
Menu_ToBeDeleted /* for testing */
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
||||
@@ -184,11 +186,19 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
||||
|
||||
CreateStatusBar();
|
||||
|
||||
// construct sub menu for testing
|
||||
wxMenu *sub_menu = new wxMenu;
|
||||
sub_menu->Append(Menu_Quit, "E&xit");
|
||||
sub_menu->Append(Menu_Quit, "E&xit");
|
||||
sub_menu->Append(Menu_Quit, "E&xit");
|
||||
|
||||
// construct menu
|
||||
wxMenu *file_menu = new wxMenu;
|
||||
file_menu->Append(Menu_Drag, "&Test drag...");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append(Menu_Quit, "E&xit");
|
||||
file_menu->AppendSeparator();
|
||||
file_menu->Append( 0, "More exit menus", sub_menu);
|
||||
|
||||
wxMenu *log_menu = new wxMenu;
|
||||
log_menu->Append(Menu_Clear, "Clear");
|
||||
@@ -417,6 +427,11 @@ void DnDFrame::OnRightDown(wxMouseEvent &event )
|
||||
menu->Append(Menu_Drag, "&Test drag...");
|
||||
menu->Append(Menu_About, "&About");
|
||||
menu->Append(Menu_Quit, "E&xit");
|
||||
menu->Append(Menu_ToBeDeleted, "To be deleted");
|
||||
menu->Append(Menu_ToBeGreyed, "To be greyed");
|
||||
|
||||
menu->Delete( Menu_ToBeDeleted );
|
||||
menu->Enable( Menu_ToBeGreyed, FALSE );
|
||||
|
||||
PopupMenu( menu, event.GetX(), event.GetY() );
|
||||
}
|
||||
|
@@ -104,7 +104,7 @@ wxMenuBar::wxMenuBar()
|
||||
|
||||
wxMenuBar::~wxMenuBar()
|
||||
{
|
||||
// how to destroy a GtkItemFactory ?
|
||||
// gtk_object_unref( GTK_OBJECT(m_factory) ); why not ?
|
||||
}
|
||||
|
||||
static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
|
||||
@@ -584,6 +584,11 @@ wxMenuItem::wxMenuItem()
|
||||
m_menuItem = (GtkWidget *) NULL;
|
||||
}
|
||||
|
||||
wxMenuItem::~wxMenuItem()
|
||||
{
|
||||
// don't delete menu items, the menus take care of that
|
||||
}
|
||||
|
||||
// it's valid for this function to be called even if m_menuItem == NULL
|
||||
void wxMenuItem::SetName( const wxString& str )
|
||||
{
|
||||
@@ -717,9 +722,19 @@ wxMenu::Init( const wxString& title,
|
||||
|
||||
wxMenu::~wxMenu()
|
||||
{
|
||||
/* how do we delete an item-factory ? */
|
||||
gtk_widget_destroy( m_menu );
|
||||
wxNode *node = m_items.First();
|
||||
while (node)
|
||||
{
|
||||
wxMenuItem *item = (wxMenuItem*)node->Data();
|
||||
wxMenu *submenu = item->GetSubMenu();
|
||||
if (submenu)
|
||||
delete submenu;
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
gtk_widget_destroy( m_menu );
|
||||
|
||||
gtk_object_unref( GTK_OBJECT(m_factory) );
|
||||
}
|
||||
|
||||
void wxMenu::SetTitle( const wxString& title )
|
||||
@@ -964,6 +979,22 @@ void wxMenu::Append( wxMenuItem *item )
|
||||
item->SetMenuItem(menuItem);
|
||||
}
|
||||
|
||||
void wxMenu::Delete( int id )
|
||||
{
|
||||
wxNode *node = m_items.First();
|
||||
while (node)
|
||||
{
|
||||
wxMenuItem *item = (wxMenuItem*)node->Data();
|
||||
if (item->GetId() == id)
|
||||
{
|
||||
gtk_widget_destroy( item->GetMenuItem() );
|
||||
m_items.DeleteNode( node );
|
||||
return;
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
int wxMenu::FindItem( const wxString itemString ) const
|
||||
{
|
||||
wxString s = wxT("");
|
||||
|
@@ -104,7 +104,7 @@ wxMenuBar::wxMenuBar()
|
||||
|
||||
wxMenuBar::~wxMenuBar()
|
||||
{
|
||||
// how to destroy a GtkItemFactory ?
|
||||
// gtk_object_unref( GTK_OBJECT(m_factory) ); why not ?
|
||||
}
|
||||
|
||||
static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
|
||||
@@ -584,6 +584,11 @@ wxMenuItem::wxMenuItem()
|
||||
m_menuItem = (GtkWidget *) NULL;
|
||||
}
|
||||
|
||||
wxMenuItem::~wxMenuItem()
|
||||
{
|
||||
// don't delete menu items, the menus take care of that
|
||||
}
|
||||
|
||||
// it's valid for this function to be called even if m_menuItem == NULL
|
||||
void wxMenuItem::SetName( const wxString& str )
|
||||
{
|
||||
@@ -717,9 +722,19 @@ wxMenu::Init( const wxString& title,
|
||||
|
||||
wxMenu::~wxMenu()
|
||||
{
|
||||
/* how do we delete an item-factory ? */
|
||||
gtk_widget_destroy( m_menu );
|
||||
wxNode *node = m_items.First();
|
||||
while (node)
|
||||
{
|
||||
wxMenuItem *item = (wxMenuItem*)node->Data();
|
||||
wxMenu *submenu = item->GetSubMenu();
|
||||
if (submenu)
|
||||
delete submenu;
|
||||
node = node->Next();
|
||||
}
|
||||
|
||||
gtk_widget_destroy( m_menu );
|
||||
|
||||
gtk_object_unref( GTK_OBJECT(m_factory) );
|
||||
}
|
||||
|
||||
void wxMenu::SetTitle( const wxString& title )
|
||||
@@ -964,6 +979,22 @@ void wxMenu::Append( wxMenuItem *item )
|
||||
item->SetMenuItem(menuItem);
|
||||
}
|
||||
|
||||
void wxMenu::Delete( int id )
|
||||
{
|
||||
wxNode *node = m_items.First();
|
||||
while (node)
|
||||
{
|
||||
wxMenuItem *item = (wxMenuItem*)node->Data();
|
||||
if (item->GetId() == id)
|
||||
{
|
||||
gtk_widget_destroy( item->GetMenuItem() );
|
||||
m_items.DeleteNode( node );
|
||||
return;
|
||||
}
|
||||
node = node->Next();
|
||||
}
|
||||
}
|
||||
|
||||
int wxMenu::FindItem( const wxString itemString ) const
|
||||
{
|
||||
wxString s = wxT("");
|
||||
|
Reference in New Issue
Block a user