Correct form of mnemonics returned by wxGTK wxMenu::GetTitle().
wxMenu::GetTitle() returned a string in GTK+ format (i.e. using underscores instead of ampersands) instead of the expected wx one. This is, of course, the right thing to do and it also fixes wxMenuBar::FindMenuItem() as a side effect. Closes #12672. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66175 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -78,6 +78,9 @@ public:
|
|||||||
void SetLayoutDirection(const wxLayoutDirection dir);
|
void SetLayoutDirection(const wxLayoutDirection dir);
|
||||||
wxLayoutDirection GetLayoutDirection() const;
|
wxLayoutDirection GetLayoutDirection() const;
|
||||||
|
|
||||||
|
// Returns the title, with mnemonics translated to wx format
|
||||||
|
const wxString GetTitle() const;
|
||||||
|
|
||||||
// TODO: virtual void SetTitle(const wxString& title);
|
// TODO: virtual void SetTitle(const wxString& title);
|
||||||
|
|
||||||
// implementation GTK only
|
// implementation GTK only
|
||||||
|
@@ -73,6 +73,9 @@ public:
|
|||||||
virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
|
virtual wxMenuItem* DoInsert(size_t pos, wxMenuItem *item);
|
||||||
virtual wxMenuItem* DoRemove(wxMenuItem *item);
|
virtual wxMenuItem* DoRemove(wxMenuItem *item);
|
||||||
|
|
||||||
|
// Returns the title, with mnemonics translated to wx format
|
||||||
|
const wxString GetTitle() const;
|
||||||
|
|
||||||
// TODO: virtual void SetTitle(const wxString& title);
|
// TODO: virtual void SetTitle(const wxString& title);
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
|
@@ -333,7 +333,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
|||||||
|
|
||||||
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
|
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
|
||||||
{
|
{
|
||||||
if (wxMenuItem::GetLabelText(wxConvertMnemonicsFromGTK(menu->GetTitle())) == wxMenuItem::GetLabelText(menuString))
|
if (wxMenuItem::GetLabelText(menu->GetTitle()) == wxMenuItem::GetLabelText(menuString))
|
||||||
{
|
{
|
||||||
int res = menu->FindItem( itemString );
|
int res = menu->FindItem( itemString );
|
||||||
if (res != wxNOT_FOUND)
|
if (res != wxNOT_FOUND)
|
||||||
@@ -426,7 +426,7 @@ wxString wxMenuBar::GetMenuLabel( size_t pos ) const
|
|||||||
|
|
||||||
wxMenu* menu = node->GetData();
|
wxMenu* menu = node->GetData();
|
||||||
|
|
||||||
return wxConvertMnemonicsFromGTK(menu->GetTitle());
|
return menu->GetTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
|
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
|
||||||
@@ -747,6 +747,11 @@ wxLayoutDirection wxMenu::GetLayoutDirection() const
|
|||||||
return wxWindow::GTKGetLayout(m_owner);
|
return wxWindow::GTKGetLayout(m_owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wxString wxMenu::GetTitle() const
|
||||||
|
{
|
||||||
|
return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
|
||||||
|
}
|
||||||
|
|
||||||
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
||||||
{
|
{
|
||||||
GtkWidget *menuItem;
|
GtkWidget *menuItem;
|
||||||
|
@@ -432,7 +432,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
|||||||
|
|
||||||
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
|
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
|
||||||
{
|
{
|
||||||
if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelText(menuString))
|
if (wxMenuItem::GetLabelText(menu->GetTitle()) == wxMenuItem::GetLabelText(menuString))
|
||||||
{
|
{
|
||||||
int res = menu->FindItem( itemString );
|
int res = menu->FindItem( itemString );
|
||||||
if (res != wxNOT_FOUND)
|
if (res != wxNOT_FOUND)
|
||||||
@@ -525,7 +525,7 @@ wxString wxMenuBar::GetMenuLabel( size_t pos ) const
|
|||||||
|
|
||||||
wxMenu* menu = node->GetData();
|
wxMenu* menu = node->GetData();
|
||||||
|
|
||||||
return wxConvertFromGTKToWXLabel(menu->GetTitle());
|
return menu->GetTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
|
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
|
||||||
@@ -964,6 +964,11 @@ wxMenu::~wxMenu()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const wxString wxMenu::GetTitle() const
|
||||||
|
{
|
||||||
|
return wxConvertMnemonicsFromGTK(wxMenuBase::GetTitle());
|
||||||
|
}
|
||||||
|
|
||||||
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
||||||
{
|
{
|
||||||
GtkWidget *menuItem;
|
GtkWidget *menuItem;
|
||||||
|
@@ -83,6 +83,7 @@ private:
|
|||||||
CPPUNIT_TEST( FindInMenubar );
|
CPPUNIT_TEST( FindInMenubar );
|
||||||
CPPUNIT_TEST( FindInMenu );
|
CPPUNIT_TEST( FindInMenu );
|
||||||
CPPUNIT_TEST( Count );
|
CPPUNIT_TEST( Count );
|
||||||
|
CPPUNIT_TEST( Labels );
|
||||||
CPPUNIT_TEST_SUITE_END();
|
CPPUNIT_TEST_SUITE_END();
|
||||||
|
|
||||||
void CreateFrame();
|
void CreateFrame();
|
||||||
@@ -90,6 +91,7 @@ private:
|
|||||||
void FindInMenubar();
|
void FindInMenubar();
|
||||||
void FindInMenu();
|
void FindInMenu();
|
||||||
void Count();
|
void Count();
|
||||||
|
void Labels();
|
||||||
|
|
||||||
wxFrame* m_frame;
|
wxFrame* m_frame;
|
||||||
|
|
||||||
@@ -170,10 +172,13 @@ void MenuTestCase::FindInMenubar()
|
|||||||
// Find by menu name plus item name:
|
// Find by menu name plus item name:
|
||||||
CPPUNIT_ASSERT( bar->FindMenuItem("File", "Foo") != wxNOT_FOUND );
|
CPPUNIT_ASSERT( bar->FindMenuItem("File", "Foo") != wxNOT_FOUND );
|
||||||
CPPUNIT_ASSERT( bar->FindMenuItem("&File", "&Foo") != wxNOT_FOUND );
|
CPPUNIT_ASSERT( bar->FindMenuItem("&File", "&Foo") != wxNOT_FOUND );
|
||||||
// and using the menu title
|
// and using the menu label
|
||||||
int index = bar->FindMenu("&File");
|
int index = bar->FindMenu("&File");
|
||||||
CPPUNIT_ASSERT( index != wxNOT_FOUND );
|
CPPUNIT_ASSERT( index != wxNOT_FOUND );
|
||||||
wxString menutitle = bar->GetMenuLabel(index);
|
wxString menulabel = bar->GetMenuLabel(index);
|
||||||
|
CPPUNIT_ASSERT( bar->FindMenuItem(menulabel, "&Foo") != wxNOT_FOUND );
|
||||||
|
// and title
|
||||||
|
wxString menutitle = bar->GetMenu(index)->GetTitle();
|
||||||
CPPUNIT_ASSERT( bar->FindMenuItem(menutitle, "&Foo") != wxNOT_FOUND );
|
CPPUNIT_ASSERT( bar->FindMenuItem(menutitle, "&Foo") != wxNOT_FOUND );
|
||||||
|
|
||||||
// Find by position:
|
// Find by position:
|
||||||
@@ -195,7 +200,7 @@ void MenuTestCase::FindInMenubar()
|
|||||||
item = bar->FindItem(m_submenuItemId, &menu);
|
item = bar->FindItem(m_submenuItemId, &menu);
|
||||||
CPPUNIT_ASSERT( item );
|
CPPUNIT_ASSERT( item );
|
||||||
CPPUNIT_ASSERT( menu );
|
CPPUNIT_ASSERT( menu );
|
||||||
// and, for completeness, a submenu one:
|
// and, for completeness, a subsubmenu one:
|
||||||
item = bar->FindItem(m_subsubmenuItemId, &menu);
|
item = bar->FindItem(m_subsubmenuItemId, &menu);
|
||||||
CPPUNIT_ASSERT( item );
|
CPPUNIT_ASSERT( item );
|
||||||
CPPUNIT_ASSERT( menu );
|
CPPUNIT_ASSERT( menu );
|
||||||
@@ -264,3 +269,38 @@ void MenuTestCase::Count()
|
|||||||
}
|
}
|
||||||
CPPUNIT_ASSERT_EQUAL( count, m_itemCount );
|
CPPUNIT_ASSERT_EQUAL( count, m_itemCount );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MenuTestCase::Labels()
|
||||||
|
{
|
||||||
|
wxMenuBar* bar = m_frame->GetMenuBar();
|
||||||
|
CPPUNIT_ASSERT( bar );
|
||||||
|
wxMenu* filemenu;
|
||||||
|
wxMenuItem* itemFoo = bar->FindItem(MenuTestCase_Foo, &filemenu);
|
||||||
|
CPPUNIT_ASSERT( itemFoo );
|
||||||
|
CPPUNIT_ASSERT( filemenu );
|
||||||
|
|
||||||
|
// These return labels including mnemonics/accelerators:
|
||||||
|
|
||||||
|
// wxMenuBar
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "&File", bar->GetMenuLabel(0) );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "&Foo\tCtrl-F", bar->GetLabel(MenuTestCase_Foo) );
|
||||||
|
|
||||||
|
// wxMenu
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "&File", filemenu->GetTitle() );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "&Foo\tCtrl-F", filemenu->GetLabel(MenuTestCase_Foo) );
|
||||||
|
|
||||||
|
// wxMenuItem
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "&Foo\tCtrl-F", itemFoo->GetItemLabel() );
|
||||||
|
|
||||||
|
// These return labels stripped of mnemonics/accelerators:
|
||||||
|
|
||||||
|
// wxMenuBar
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "File", bar->GetMenuLabelText(0) );
|
||||||
|
|
||||||
|
// wxMenu
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "Foo", filemenu->GetLabelText(MenuTestCase_Foo) );
|
||||||
|
|
||||||
|
// wxMenuItem
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "Foo", itemFoo->GetItemLabelText() );
|
||||||
|
CPPUNIT_ASSERT_EQUAL( "Foo", wxMenuItem::GetLabelText("&Foo\tCtrl-F") );
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user