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:
@@ -126,10 +126,6 @@ public:
|
|||||||
virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
|
virtual wxMenu *Replace(size_t pos, wxMenu *menu, const wxString& title);
|
||||||
virtual wxMenu *Remove(size_t pos);
|
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 EnableTop( size_t pos, bool flag );
|
||||||
virtual void SetMenuLabel( size_t pos, const wxString& label );
|
virtual void SetMenuLabel( size_t pos, const wxString& label );
|
||||||
virtual wxString GetMenuLabel( size_t pos ) const;
|
virtual wxString GetMenuLabel( size_t pos ) const;
|
||||||
@@ -141,7 +137,6 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// implementation from now on
|
// implementation from now on
|
||||||
int FindMenu(const wxString& title);
|
|
||||||
void Detach();
|
void Detach();
|
||||||
|
|
||||||
// returns TRUE if we're attached to a frame
|
// returns TRUE if we're attached to a frame
|
||||||
@@ -169,7 +164,6 @@ protected:
|
|||||||
// common part of all ctors
|
// common part of all ctors
|
||||||
void Init();
|
void Init();
|
||||||
|
|
||||||
wxArrayString m_titles;
|
|
||||||
static bool s_macAutoWindowMenu ;
|
static bool s_macAutoWindowMenu ;
|
||||||
static WXHMENU s_macWindowMenuHandle ;
|
static WXHMENU s_macWindowMenuHandle ;
|
||||||
|
|
||||||
|
@@ -567,12 +567,9 @@ wxMenuBar::wxMenuBar(size_t count, wxMenu *menus[], const wxString titles[], lon
|
|||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
|
|
||||||
m_titles.Alloc(count);
|
|
||||||
|
|
||||||
for ( size_t i = 0; i < count; i++ )
|
for ( size_t i = 0; i < count; i++ )
|
||||||
{
|
{
|
||||||
m_menus.Append(menus[i]);
|
m_menus.Append(menus[i]);
|
||||||
m_titles.Add(titles[i]);
|
|
||||||
|
|
||||||
menus[i]->Attach(this);
|
menus[i]->Attach(this);
|
||||||
Append( menus[i], titles[i] );
|
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") );
|
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
|
||||||
|
|
||||||
m_titles[pos] = label;
|
|
||||||
|
|
||||||
if ( !IsAttached() )
|
|
||||||
return;
|
|
||||||
|
|
||||||
GetMenu(pos)->SetTitle( label ) ;
|
GetMenu(pos)->SetTitle( label ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -836,22 +828,7 @@ wxString wxMenuBar::GetMenuLabel(size_t pos) const
|
|||||||
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
|
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
|
||||||
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
|
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
|
||||||
|
|
||||||
return m_titles[pos];
|
return GetMenu(pos)->GetTitle();
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -866,8 +843,6 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
|
|||||||
if ( !menuOld )
|
if ( !menuOld )
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
m_titles[pos] = title;
|
|
||||||
|
|
||||||
wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
|
wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
|
||||||
m_rootMenu->Remove(item);
|
m_rootMenu->Remove(item);
|
||||||
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
|
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) )
|
if ( !wxMenuBarBase::Insert(pos, menu, title) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_titles.Insert(title, pos);
|
|
||||||
|
|
||||||
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
|
m_rootMenu->Insert( pos+firstMenuPos, wxMenuItem::New( m_rootMenu, wxID_ANY, title, "", wxITEM_NORMAL, menu ) );
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -896,8 +869,6 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
|||||||
wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
|
wxMenuItem* item = m_rootMenu->FindItemByPosition(pos+firstMenuPos);
|
||||||
m_rootMenu->Remove(item);
|
m_rootMenu->Remove(item);
|
||||||
|
|
||||||
m_titles.RemoveAt(pos);
|
|
||||||
|
|
||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -909,9 +880,8 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
|
|||||||
if ( !wxMenuBarBase::Append(menu, title) )
|
if ( !wxMenuBarBase::Append(menu, title) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_titles.Add(title);
|
|
||||||
|
|
||||||
m_rootMenu->AppendSubMenu(menu, title);
|
m_rootMenu->AppendSubMenu(menu, title);
|
||||||
|
menu->SetTitle(title);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -926,37 +896,4 @@ void wxMenuBar::Attach(wxFrame *frame)
|
|||||||
wxMenuBarBase::Attach( frame ) ;
|
wxMenuBarBase::Attach( frame ) ;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
#endif // wxUSE_MENUS
|
||||||
// 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
|
|
||||||
|
Reference in New Issue
Block a user