~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);
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;
public:
wxMenuItem();
+ ~wxMenuItem();
// accessors
// id
~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);
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;
public:
wxMenuItem();
+ ~wxMenuItem();
// accessors
// id
Menu_CopyBitmap,
Menu_PasteBitmap,
Menu_HasText,
- Menu_HasBitmap
+ Menu_HasBitmap,
+ Menu_ToBeGreyed, /* for testing */
+ Menu_ToBeDeleted /* for testing */
};
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
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");
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() );
}
wxMenuBar::~wxMenuBar()
{
- // how to destroy a GtkItemFactory ?
+// gtk_object_unref( GTK_OBJECT(m_factory) ); why not ?
}
static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
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 )
{
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 )
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("");
wxMenuBar::~wxMenuBar()
{
- // how to destroy a GtkItemFactory ?
+// gtk_object_unref( GTK_OBJECT(m_factory) ); why not ?
}
static void wxMenubarUnsetInvokingWindow( wxMenu *menu, wxWindow *win )
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 )
{
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 )
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("");