Store menus titles in menus themselves in wxOSX.
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
This commit is contained in:
parent
8a1459665d
commit
46405e36bf
@ -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 ;
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user