X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1987af7e9f5685198b0c19e2326eebf7e56b7834..88961c3ecae1afa141c201dc69d51174a55b1ea8:/src/common/menucmn.cpp diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 33ccd66f39..fd1cc38a1e 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -24,6 +24,8 @@ // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#include + #ifdef __BORLANDC__ #pragma hdrstop #endif @@ -51,7 +53,8 @@ WX_DEFINE_LIST(wxMenuItemList); wxMenuItemBase::~wxMenuItemBase() { - delete m_subMenu; + if (m_subMenu) + delete m_subMenu; } #if wxUSE_ACCEL @@ -124,11 +127,16 @@ void wxMenuBase::Init(long style) m_style = style; m_clientData = (void *)NULL; m_eventHandler = this; + +#if wxUSE_MENU_CALLBACK + m_callback = (wxFunction) NULL; +#endif // wxUSE_MENU_CALLBACK } wxMenuBase::~wxMenuBase() { - // nothing to do, wxMenuItemList dtor will delete the menu items + // nothing to do, wxMenuItemList dtor will delete the menu items. + // Actually, in GTK, the submenus have to get deleted first. } // ---------------------------------------------------------------------------- @@ -147,10 +155,18 @@ bool wxMenuBase::DoAppend(wxMenuItem *item) bool wxMenuBase::Insert(size_t pos, wxMenuItem *item) { wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Insert") ); - wxCHECK_MSG( pos < GetMenuItemCount(), FALSE, - wxT("invalid index in wxMenu::Insert") ); - return DoInsert(pos, item); + if ( pos == GetMenuItemCount() ) + { + return DoAppend(item); + } + else + { + wxCHECK_MSG( pos < GetMenuItemCount(), FALSE, + wxT("invalid index in wxMenu::Insert") ); + + return DoInsert(pos, item); + } } bool wxMenuBase::DoInsert(size_t pos, wxMenuItem *item) @@ -196,7 +212,7 @@ wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) bool wxMenuBase::Delete(wxMenuItem *item) { - wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Delete") ); + wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Delete") ); return DoDelete(item); } @@ -216,7 +232,7 @@ bool wxMenuBase::DoDelete(wxMenuItem *item) bool wxMenuBase::Destroy(wxMenuItem *item) { - wxCHECK_MSG( item, NULL, wxT("invalid item in wxMenu::Destroy") ); + wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Destroy") ); return DoDestroy(item); } @@ -238,7 +254,7 @@ bool wxMenuBase::DoDestroy(wxMenuItem *item) // Finds the item id matching the given string, -1 if not found. int wxMenuBase::FindItem(const wxString& text) const { - wxString label = wxMenuItem(NULL, wxID_SEPARATOR, text).GetLabel(); + wxString label = wxMenuItem::GetLabelFromText(text); for ( wxMenuItemList::Node *node = m_items.GetFirst(); node; node = node->GetNext() ) @@ -301,9 +317,12 @@ wxMenuItem *wxMenuBase::FindChildItem(int id, size_t *ppos) const size_t pos; for ( pos = 0; node; pos++ ) { - item = node->GetData(); - if ( item->GetId() == id ) + if ( node->GetData()->GetId() == id ) + { + item = node->GetData(); + break; + } node = node->GetNext(); } @@ -478,16 +497,23 @@ bool wxMenuBarBase::Append(wxMenu *menu, const wxString& WXUNUSED(title)) } bool wxMenuBarBase::Insert(size_t pos, wxMenu *menu, - const wxString& WXUNUSED(title)) + const wxString& title) { - wxCHECK_MSG( menu, FALSE, wxT("can't insert NULL menu") ); + if ( pos == m_menus.GetCount() ) + { + return wxMenuBarBase::Append(menu, title); + } + else + { + wxCHECK_MSG( menu, FALSE, wxT("can't insert NULL menu") ); - wxMenuList::Node *node = m_menus.Item(pos); - wxCHECK_MSG( node, FALSE, wxT("bad index in wxMenuBar::Insert()") ); + wxMenuList::Node *node = m_menus.Item(pos); + wxCHECK_MSG( node, FALSE, wxT("bad index in wxMenuBar::Insert()") ); - m_menus.Insert(node, menu); + m_menus.Insert(node, menu); - return TRUE; + return TRUE; + } } wxMenu *wxMenuBarBase::Replace(size_t pos, wxMenu *menu, @@ -518,6 +544,26 @@ wxMenu *wxMenuBarBase::Remove(size_t pos) return menu; } +int wxMenuBarBase::FindMenu(const wxString& title) const +{ + wxString label = wxMenuItem::GetLabelFromText(title); + + size_t count = GetMenuCount(); + for ( size_t i = 0; i < count; i++ ) + { + wxString title2 = GetLabelTop(i); + if ( (title2 == title) || + (wxMenuItem::GetLabelFromText(title2) == label) ) + { + // found + return (int)i; + } + } + + return wxNOT_FOUND; + +} + // --------------------------------------------------------------------------- // wxMenuBar functions forwarded to wxMenuItem // ---------------------------------------------------------------------------