- implemented handling of double ampersands '&' in wxGTK menu item texts in
order to allow embedding an ampersand character in the menu item text - documented use of double ampersands for menu item texts git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18036 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -36,7 +36,9 @@ Constructs a wxMenuItem object.
|
||||
|
||||
\docparam{id}{Identifier for this menu item, or ID\_SEPARATOR to indicate a separator.}
|
||||
|
||||
\docparam{text}{Text for the menu item, as shown on the menu.}
|
||||
\docparam{text}{Text for the menu item, as shown on the menu. An accelerator
|
||||
key can be specified using the ampersand '\&' character. In order to embed an
|
||||
ampersand character in the menu item text, the ampersand must be doubled.}
|
||||
|
||||
\docparam{helpString}{Optional help string that will be shown on the status bar.}
|
||||
|
||||
|
@@ -113,9 +113,16 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
||||
|
||||
/* GTK 1.2 wants to have "_" instead of "&" for accelerators */
|
||||
wxString str;
|
||||
for ( pc = title; *pc != wxT('\0'); pc++ )
|
||||
pc = title;
|
||||
while (*pc != wxT('\0'))
|
||||
{
|
||||
if (*pc == wxT('&'))
|
||||
if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
|
||||
{
|
||||
// "&" is doubled to indicate "&" instead of accelerator
|
||||
++pc;
|
||||
str << wxT('&');
|
||||
}
|
||||
else if (*pc == wxT('&'))
|
||||
{
|
||||
#if GTK_CHECK_VERSION(1, 2, 0)
|
||||
str << wxT('_');
|
||||
@@ -149,6 +156,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
||||
|
||||
str << *pc;
|
||||
}
|
||||
++pc;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -577,10 +585,9 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
||||
wxString text( menu->GetTitle() );
|
||||
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
|
||||
// '_' is the escape character for GTK+
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -789,12 +796,6 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( *pc == wxT('&') )
|
||||
{
|
||||
// wxMSW escapes &
|
||||
continue;
|
||||
}
|
||||
|
||||
label += *pc;
|
||||
}
|
||||
|
||||
@@ -848,13 +849,18 @@ void wxMenuItem::DoSetText( const wxString& str )
|
||||
// '\t' is the deliminator indicating a hot key
|
||||
m_text.Empty();
|
||||
const wxChar *pc = str;
|
||||
for (; (*pc != wxT('\0')) && (*pc != wxT('\t')); pc++ )
|
||||
while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) )
|
||||
{
|
||||
if (*pc == wxT('&'))
|
||||
if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
|
||||
{
|
||||
// "&" is doubled to indicate "&" instead of accelerator
|
||||
++pc;
|
||||
m_text << wxT('&');
|
||||
}
|
||||
else if (*pc == wxT('&'))
|
||||
{
|
||||
m_text << wxT('_');
|
||||
}
|
||||
|
||||
#if GTK_CHECK_VERSION(2, 0, 0)
|
||||
else if ( *pc == wxT('_') ) // escape underscores
|
||||
{
|
||||
@@ -878,10 +884,12 @@ void wxMenuItem::DoSetText( const wxString& str )
|
||||
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
||||
}
|
||||
#endif
|
||||
else
|
||||
else {
|
||||
m_text << *pc;
|
||||
}
|
||||
++pc;
|
||||
}
|
||||
|
||||
|
||||
m_hotKey = wxT("");
|
||||
|
||||
if(*pc == wxT('\t'))
|
||||
@@ -957,9 +965,9 @@ wxString wxMenuItem::GetFactoryPath() const
|
||||
|
||||
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
||||
{
|
||||
if ( *pc == wxT('_') || *pc == wxT('&') )
|
||||
if ( *pc == wxT('_') )
|
||||
{
|
||||
// remove '_' and '&' unconditionally
|
||||
// remove '_' unconditionally
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -113,9 +113,16 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
||||
|
||||
/* GTK 1.2 wants to have "_" instead of "&" for accelerators */
|
||||
wxString str;
|
||||
for ( pc = title; *pc != wxT('\0'); pc++ )
|
||||
pc = title;
|
||||
while (*pc != wxT('\0'))
|
||||
{
|
||||
if (*pc == wxT('&'))
|
||||
if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
|
||||
{
|
||||
// "&" is doubled to indicate "&" instead of accelerator
|
||||
++pc;
|
||||
str << wxT('&');
|
||||
}
|
||||
else if (*pc == wxT('&'))
|
||||
{
|
||||
#if GTK_CHECK_VERSION(1, 2, 0)
|
||||
str << wxT('_');
|
||||
@@ -149,6 +156,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
||||
|
||||
str << *pc;
|
||||
}
|
||||
++pc;
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@@ -577,10 +585,9 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
||||
wxString text( menu->GetTitle() );
|
||||
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
|
||||
// '_' is the escape character for GTK+
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -789,12 +796,6 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( *pc == wxT('&') )
|
||||
{
|
||||
// wxMSW escapes &
|
||||
continue;
|
||||
}
|
||||
|
||||
label += *pc;
|
||||
}
|
||||
|
||||
@@ -848,13 +849,18 @@ void wxMenuItem::DoSetText( const wxString& str )
|
||||
// '\t' is the deliminator indicating a hot key
|
||||
m_text.Empty();
|
||||
const wxChar *pc = str;
|
||||
for (; (*pc != wxT('\0')) && (*pc != wxT('\t')); pc++ )
|
||||
while ( (*pc != wxT('\0')) && (*pc != wxT('\t')) )
|
||||
{
|
||||
if (*pc == wxT('&'))
|
||||
if ((*pc == wxT('&')) && (*(pc+1) == wxT('&')))
|
||||
{
|
||||
// "&" is doubled to indicate "&" instead of accelerator
|
||||
++pc;
|
||||
m_text << wxT('&');
|
||||
}
|
||||
else if (*pc == wxT('&'))
|
||||
{
|
||||
m_text << wxT('_');
|
||||
}
|
||||
|
||||
#if GTK_CHECK_VERSION(2, 0, 0)
|
||||
else if ( *pc == wxT('_') ) // escape underscores
|
||||
{
|
||||
@@ -878,10 +884,12 @@ void wxMenuItem::DoSetText( const wxString& str )
|
||||
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
||||
}
|
||||
#endif
|
||||
else
|
||||
else {
|
||||
m_text << *pc;
|
||||
}
|
||||
++pc;
|
||||
}
|
||||
|
||||
|
||||
m_hotKey = wxT("");
|
||||
|
||||
if(*pc == wxT('\t'))
|
||||
@@ -957,9 +965,9 @@ wxString wxMenuItem::GetFactoryPath() const
|
||||
|
||||
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
||||
{
|
||||
if ( *pc == wxT('_') || *pc == wxT('&') )
|
||||
if ( *pc == wxT('_') )
|
||||
{
|
||||
// remove '_' and '&' unconditionally
|
||||
// remove '_' unconditionally
|
||||
continue;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user