From d76419bd541e46b6a423dca04efc12875da5cfa6 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Sun, 7 Jan 2001 14:55:03 +0000 Subject: [PATCH] Make wxMenuItem::GetLabel() handle escaped underscores (which are '__') correctly. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9062 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/menu.cpp | 34 ++++++++++++++++++++++++---------- src/gtk1/menu.cpp | 34 ++++++++++++++++++++++++---------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 029aa9c12f..e56488272a 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -726,21 +726,25 @@ wxMenuItem::~wxMenuItem() wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { wxString label; -#if (GTK_MINOR_VERSION > 0) + for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { - if ( *pc == wxT('_') || *pc == wxT('&') ) + if ( *pc == wxT('_') ) { - // '_' is the escape character for GTK+ and '&' is the one for - // wxWindows - skip both of them + // wxGTK escapes "xxx_xxx" to "xxx__xxx" + pc++; + label += *pc; + continue; + } + + if ( *pc == wxT('&') ) + { + // wxMSW escapes & continue; } label += *pc; } -#else // GTK+ 1.0 - label = text; -#endif // GTK+ 1.2/1.0 return label; } @@ -855,11 +859,21 @@ bool wxMenuItem::IsChecked() const wxString wxMenuItem::GetFactoryPath() const { - /* in order to get the pointer to the item we need the item text _without_ - underscores */ + /* in order to get the pointer to the item we need the item text + _without_ underscores */ wxString path( wxT("
/") ); - path += GetLabel(); + for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) + { + if ( *pc == wxT('_') || *pc == wxT('&') ) + { + // remove '_' and '&' unconditionally + continue; + } + + path += *pc; + } + return path; } diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 029aa9c12f..e56488272a 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -726,21 +726,25 @@ wxMenuItem::~wxMenuItem() wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { wxString label; -#if (GTK_MINOR_VERSION > 0) + for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { - if ( *pc == wxT('_') || *pc == wxT('&') ) + if ( *pc == wxT('_') ) { - // '_' is the escape character for GTK+ and '&' is the one for - // wxWindows - skip both of them + // wxGTK escapes "xxx_xxx" to "xxx__xxx" + pc++; + label += *pc; + continue; + } + + if ( *pc == wxT('&') ) + { + // wxMSW escapes & continue; } label += *pc; } -#else // GTK+ 1.0 - label = text; -#endif // GTK+ 1.2/1.0 return label; } @@ -855,11 +859,21 @@ bool wxMenuItem::IsChecked() const wxString wxMenuItem::GetFactoryPath() const { - /* in order to get the pointer to the item we need the item text _without_ - underscores */ + /* in order to get the pointer to the item we need the item text + _without_ underscores */ wxString path( wxT("
/") ); - path += GetLabel(); + for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) + { + if ( *pc == wxT('_') || *pc == wxT('&') ) + { + // remove '_' and '&' unconditionally + continue; + } + + path += *pc; + } + return path; } -- 2.45.2