- 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{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.}
|
\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 */
|
/* GTK 1.2 wants to have "_" instead of "&" for accelerators */
|
||||||
wxString str;
|
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)
|
#if GTK_CHECK_VERSION(1, 2, 0)
|
||||||
str << wxT('_');
|
str << wxT('_');
|
||||||
@@ -149,6 +156,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
|||||||
|
|
||||||
str << *pc;
|
str << *pc;
|
||||||
}
|
}
|
||||||
|
++pc;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -577,10 +585,9 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
|||||||
wxString text( menu->GetTitle() );
|
wxString text( menu->GetTitle() );
|
||||||
for ( const wxChar *pc = text.c_str(); *pc; pc++ )
|
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
|
// '_' is the escape character for GTK+
|
||||||
// wxWindows - skip both of them
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,12 +796,6 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( *pc == wxT('&') )
|
|
||||||
{
|
|
||||||
// wxMSW escapes &
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
label += *pc;
|
label += *pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,13 +849,18 @@ void wxMenuItem::DoSetText( const wxString& str )
|
|||||||
// '\t' is the deliminator indicating a hot key
|
// '\t' is the deliminator indicating a hot key
|
||||||
m_text.Empty();
|
m_text.Empty();
|
||||||
const wxChar *pc = str;
|
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('_');
|
m_text << wxT('_');
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION(2, 0, 0)
|
#if GTK_CHECK_VERSION(2, 0, 0)
|
||||||
else if ( *pc == wxT('_') ) // escape underscores
|
else if ( *pc == wxT('_') ) // escape underscores
|
||||||
{
|
{
|
||||||
@@ -878,8 +884,10 @@ void wxMenuItem::DoSetText( const wxString& str )
|
|||||||
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else {
|
||||||
m_text << *pc;
|
m_text << *pc;
|
||||||
|
}
|
||||||
|
++pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hotKey = wxT("");
|
m_hotKey = wxT("");
|
||||||
@@ -957,9 +965,9 @@ wxString wxMenuItem::GetFactoryPath() const
|
|||||||
|
|
||||||
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
||||||
{
|
{
|
||||||
if ( *pc == wxT('_') || *pc == wxT('&') )
|
if ( *pc == wxT('_') )
|
||||||
{
|
{
|
||||||
// remove '_' and '&' unconditionally
|
// remove '_' unconditionally
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -113,9 +113,16 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
|||||||
|
|
||||||
/* GTK 1.2 wants to have "_" instead of "&" for accelerators */
|
/* GTK 1.2 wants to have "_" instead of "&" for accelerators */
|
||||||
wxString str;
|
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)
|
#if GTK_CHECK_VERSION(1, 2, 0)
|
||||||
str << wxT('_');
|
str << wxT('_');
|
||||||
@@ -149,6 +156,7 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
|||||||
|
|
||||||
str << *pc;
|
str << *pc;
|
||||||
}
|
}
|
||||||
|
++pc;
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
@@ -577,10 +585,9 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
|||||||
wxString text( menu->GetTitle() );
|
wxString text( menu->GetTitle() );
|
||||||
for ( const wxChar *pc = text.c_str(); *pc; pc++ )
|
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
|
// '_' is the escape character for GTK+
|
||||||
// wxWindows - skip both of them
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -789,12 +796,6 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( *pc == wxT('&') )
|
|
||||||
{
|
|
||||||
// wxMSW escapes &
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
label += *pc;
|
label += *pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -848,13 +849,18 @@ void wxMenuItem::DoSetText( const wxString& str )
|
|||||||
// '\t' is the deliminator indicating a hot key
|
// '\t' is the deliminator indicating a hot key
|
||||||
m_text.Empty();
|
m_text.Empty();
|
||||||
const wxChar *pc = str;
|
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('_');
|
m_text << wxT('_');
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GTK_CHECK_VERSION(2, 0, 0)
|
#if GTK_CHECK_VERSION(2, 0, 0)
|
||||||
else if ( *pc == wxT('_') ) // escape underscores
|
else if ( *pc == wxT('_') ) // escape underscores
|
||||||
{
|
{
|
||||||
@@ -878,8 +884,10 @@ void wxMenuItem::DoSetText( const wxString& str )
|
|||||||
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
m_text << wxT('\\'); /* ... and replace them with back slashes */
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
else
|
else {
|
||||||
m_text << *pc;
|
m_text << *pc;
|
||||||
|
}
|
||||||
|
++pc;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_hotKey = wxT("");
|
m_hotKey = wxT("");
|
||||||
@@ -957,9 +965,9 @@ wxString wxMenuItem::GetFactoryPath() const
|
|||||||
|
|
||||||
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
for ( const wxChar *pc = m_text.c_str(); *pc; pc++ )
|
||||||
{
|
{
|
||||||
if ( *pc == wxT('_') || *pc == wxT('&') )
|
if ( *pc == wxT('_') )
|
||||||
{
|
{
|
||||||
// remove '_' and '&' unconditionally
|
// remove '_' unconditionally
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user