Menu label consistency changes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48023 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -91,6 +91,41 @@ static wxString wxReplaceUnderscore( const wxString& title )
|
||||
return str;
|
||||
}
|
||||
|
||||
static wxString wxConvertFromGTKToWXLabel(const wxString& gtkLabel)
|
||||
{
|
||||
wxString label;
|
||||
for ( const wxChar *pc = gtkLabel.c_str(); *pc; pc++ )
|
||||
{
|
||||
// '_' is the escape character for GTK+.
|
||||
|
||||
if ( *pc == wxT('_') && *(pc+1) == wxT('_'))
|
||||
{
|
||||
// An underscore was escaped.
|
||||
label += wxT('_');
|
||||
pc++;
|
||||
}
|
||||
else if ( *pc == wxT('_') )
|
||||
{
|
||||
// Convert GTK+ hotkey symbol to wxWidgets/Windows standard
|
||||
label += wxT('&');
|
||||
}
|
||||
else if ( *pc == wxT('&') )
|
||||
{
|
||||
// Double the ampersand to escape it as far as wxWidgets is concerned
|
||||
label += wxT("&&");
|
||||
}
|
||||
else
|
||||
{
|
||||
// don't remove ampersands '&' since if we have them in the menu title
|
||||
// it means that they were doubled to indicate "&" instead of accelerator
|
||||
label += *pc;
|
||||
}
|
||||
}
|
||||
|
||||
return label;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// activate message from GTK
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -408,7 +443,7 @@ wxMenu *wxMenuBar::Remove(size_t pos)
|
||||
|
||||
static int FindMenuItemRecursive( const wxMenu *menu, const wxString &menuString, const wxString &itemString )
|
||||
{
|
||||
if (wxMenuItem::GetLabelFromText(menu->GetTitle()) == wxMenuItem::GetLabelFromText(menuString))
|
||||
if (wxMenuItem::GetLabelText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelText(menuString))
|
||||
{
|
||||
int res = menu->FindItem( itemString );
|
||||
if (res != wxNOT_FOUND)
|
||||
@@ -493,7 +528,7 @@ void wxMenuBar::EnableTop( size_t pos, bool flag )
|
||||
gtk_widget_set_sensitive( menu->m_owner, flag );
|
||||
}
|
||||
|
||||
wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
||||
wxString wxMenuBar::GetMenuLabel( size_t pos ) const
|
||||
{
|
||||
wxMenuList::compatibility_iterator node = m_menus.Item( pos );
|
||||
|
||||
@@ -501,26 +536,10 @@ wxString wxMenuBar::GetLabelTop( size_t pos ) const
|
||||
|
||||
wxMenu* menu = node->GetData();
|
||||
|
||||
wxString label;
|
||||
wxString text( menu->GetTitle() );
|
||||
for ( const wxChar *pc = text.c_str(); *pc; pc++ )
|
||||
{
|
||||
if ( *pc == wxT('_') )
|
||||
{
|
||||
// '_' is the escape character for GTK+
|
||||
continue;
|
||||
}
|
||||
|
||||
// don't remove ampersands '&' since if we have them in the menu title
|
||||
// it means that they were doubled to indicate "&" instead of accelerator
|
||||
|
||||
label += *pc;
|
||||
}
|
||||
|
||||
return label;
|
||||
return wxConvertFromGTKToWXLabel(menu->GetTitle());
|
||||
}
|
||||
|
||||
void wxMenuBar::SetLabelTop( size_t pos, const wxString& label )
|
||||
void wxMenuBar::SetMenuLabel( size_t pos, const wxString& label )
|
||||
{
|
||||
wxMenuList::compatibility_iterator node = m_menus.Item( pos );
|
||||
|
||||
@@ -734,8 +753,14 @@ wxMenuItem::~wxMenuItem()
|
||||
|
||||
// return the menu item text without any menu accels
|
||||
/* static */
|
||||
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
||||
wxString wxMenuItemBase::GetLabelText(const wxString& text)
|
||||
{
|
||||
// The argument to this function will now always be in wxWidgets standard label
|
||||
// format, not GTK+ format, so we do what the other ports do.
|
||||
|
||||
return wxStripMenuCodes(text);
|
||||
|
||||
#if 0
|
||||
wxString label;
|
||||
|
||||
for ( const wxChar *pc = text.c_str(); *pc; pc++ )
|
||||
@@ -761,12 +786,18 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
|
||||
label += *pc;
|
||||
}
|
||||
|
||||
// wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() );
|
||||
// wxPrintf( wxT("GetLabelText(): text %s label %s\n"), text.c_str(), label.c_str() );
|
||||
|
||||
return label;
|
||||
#endif
|
||||
}
|
||||
|
||||
void wxMenuItem::SetText( const wxString& string )
|
||||
wxString wxMenuItem::GetItemLabel() const
|
||||
{
|
||||
return wxConvertFromGTKToWXLabel(m_text);
|
||||
}
|
||||
|
||||
void wxMenuItem::SetItemLabel( const wxString& string )
|
||||
{
|
||||
wxString str = string;
|
||||
if ( str.empty() && !IsSeparator() )
|
||||
@@ -996,7 +1027,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
||||
}
|
||||
else if (mitem->GetBitmap().Ok())
|
||||
{
|
||||
text = mitem->GetText();
|
||||
text = mitem->GetItemLabel();
|
||||
const wxBitmap *bitmap = &mitem->GetBitmap();
|
||||
|
||||
// TODO
|
||||
@@ -1008,8 +1039,8 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
||||
}
|
||||
else // a normal item
|
||||
{
|
||||
// text has "_" instead of "&" after mitem->SetText() so don't use it
|
||||
text = mitem->GetText() ;
|
||||
// text has "_" instead of "&" after mitem->SetItemLabel() so don't use it
|
||||
text = mitem->GetItemLabel() ;
|
||||
|
||||
switch ( mitem->GetKind() )
|
||||
{
|
||||
@@ -1062,7 +1093,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
|
||||
GdkModifierType accel_mods;
|
||||
wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*mitem) );
|
||||
|
||||
// wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
|
||||
// wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetItemLabel().c_str(), GetGtkHotKey(*mitem).c_str() );
|
||||
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
|
||||
if (accel_key != 0)
|
||||
{
|
||||
|
Reference in New Issue
Block a user