]> git.saurik.com Git - wxWidgets.git/commitdiff
Store menus titles in menus themselves in wxOSX.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 19 Dec 2010 15:02:45 +0000 (15:02 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 19 Dec 2010 15:02:45 +0000 (15:02 +0000)
Get rid of wxMenuBar::m_titles array which doesn't seem to be needed and just
store the titles in the menus themselves instead. This makes wxMenu::GetTitle()
work as in the other ports and fixes unit test failures in menu test.

It also makes it unnecessary to duplicate the base class Find[Menu]Item()
methods in wxOSX wxMenuBar so simply remove them entirely.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66402 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/osx/menu.h
src/osx/menu_osx.cpp

index b37bd9dae336ae78f26f39ec54bd75a8a7df9519..97b4ce320df5250bd0d6a488e82d78d8cee4afe1 100644 (file)
@@ -126,10 +126,6 @@ public:
     virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
     virtual wxMenu *Remove(size_t pos);
 
-    virtual int FindMenuItem(const wxString& menuString,
-                             const wxString& itemString) const;
-    virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
-
     virtual void EnableTop( size_t pos, bool flag );
     virtual void SetMenuLabel( size_t pos, const wxString& label );
     virtual wxString GetMenuLabel( size_t pos ) const;
@@ -141,7 +137,6 @@ public:
     }
 
     // implementation from now on
-    int  FindMenu(const wxString& title);
     void Detach();
 
         // returns TRUE if we're attached to a frame
@@ -169,7 +164,6 @@ protected:
     // common part of all ctors
     void Init();
 
-    wxArrayString   m_titles;
     static bool     s_macAutoWindowMenu ;
     static WXHMENU  s_macWindowMenuHandle ;
 
index 31f935a0bfcc45fe87ceda50d42296f6cb22115a..e357f2bb7f00f2810315d8eb60e54819dd85c796 100644 (file)
@@ -567,12 +567,9 @@ wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], lon
 {
     Init();
 
-    m_titles.Alloc(count);
-
     for ( size_t i = 0; i < count; i++ )
     {
         m_menus.Append(menus[i]);
-        m_titles.Add(titles[i]);
 
         menus[i]->Attach(this);
         Append( menus[i], titles[i] );
@@ -823,11 +820,6 @@ void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
 {
     wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
 
-    m_titles[pos] = label;
-
-    if ( !IsAttached() )
-        return;
-
     GetMenu(pos)->SetTitle( label ) ;
 }
 
@@ -836,22 +828,7 @@ wxString wxMenuBar::GetMenuLabel(size_t pos) const
     wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
                  wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
 
-    return m_titles[pos];
-}
-
-int wxMenuBar::FindMenu(const wxString& title)
-{
-    wxString menuTitle = wxStripMenuCodes(title);
-
-    size_t count = GetMenuCount();
-    for ( size_t i = 0; i < count; i++ )
-    {
-        wxString title = wxStripMenuCodes(m_titles[i]);
-        if ( menuTitle == title )
-            return i;
-    }
-
-    return wxNOT_FOUND;
+    return GetMenu(pos)->GetTitle();
 }
 
 // ---------------------------------------------------------------------------
@@ -866,8 +843,6 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
     if ( !menuOld )
         return NULL;
 
-    m_titles[pos] = title;
-
     wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
     m_rootMenu->Remove(item);
     m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
@@ -880,8 +855,6 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
     if ( !wxMenuBarBase::Insert(pos, menu, title) )
         return false;
 
-    m_titles.Insert(title, pos);
-
     m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
 
     return true;
@@ -896,8 +869,6 @@ wxMenu *wxMenuBar::Remove(size_t pos)
     wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
     m_rootMenu->Remove(item);
 
-    m_titles.RemoveAt(pos);
-
     return menu;
 }
 
@@ -909,9 +880,8 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
     if ( !wxMenuBarBase::Append(menu, title) )
         return false;
 
-    m_titles.Add(title);
-
     m_rootMenu->AppendSubMenu(menu, title);
+    menu->SetTitle(title);
 
     return true;
 }
@@ -926,37 +896,4 @@ void wxMenuBar::Attach(wxFrame *frame)
     wxMenuBarBase::Attach( frame ) ;
 }
 
-// ---------------------------------------------------------------------------
-// wxMenuBar searching for menu items
-// ---------------------------------------------------------------------------
-
-// Find the itemString in menuString, and return the item id or wxNOT_FOUND
-int wxMenuBar::FindMenuItem(const wxString& menuString,
-                            const wxString& itemString) const
-{
-    wxString menuLabel = wxStripMenuCodes(menuString);
-    size_t count = GetMenuCount();
-    for ( size_t i = 0; i < count; i++ )
-    {
-        wxString title = wxStripMenuCodes(m_titles[i]);
-        if ( menuLabel == title )
-            return GetMenu(i)->FindItem(itemString);
-    }
-
-    return wxNOT_FOUND;
-}
-
-wxMenuItem *wxMenuBar::FindItem(int id, wxMenu **itemMenu) const
-{
-    if ( itemMenu )
-        *itemMenu = NULL;
-
-    wxMenuItem *item = NULL;
-    size_t count = GetMenuCount();
-    for ( size_t i = 0; !item && (i < count); i++ )
-        item = GetMenu(i)->FindItem(id, itemMenu);
-
-    return item;
-}
-
-#endif
+#endif // wxUSE_MENUS