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:
Julian Smart 2007-08-11 17:54:59 +00:00
parent afb6a92fee
commit 52af3158e9
39 changed files with 304 additions and 195 deletions

View File

@ -102,8 +102,8 @@ public:
virtual void EnableTop(size_t pos, bool enable);
virtual bool IsEnabledTop(size_t pos) const;
virtual void SetLabelTop(size_t pos, const wxString& label);
virtual wxString GetLabelTop(size_t pos) const;
virtual void SetMenuLabel(size_t pos, const wxString& label);
virtual wxString GetMenuLabel(size_t pos) const;
virtual void Attach(wxFrame *frame);
virtual void Detach();

View File

@ -63,7 +63,7 @@ protected:
// ------------------------------------------------------------------------
public:
// override base class virtuals to update the item appearance on screen
virtual void SetText(const wxString& text);
virtual void SetItemLabel(const wxString& text);
virtual void SetCheckable(bool checkable);
virtual void Enable(bool enable = TRUE);

View File

@ -34,8 +34,8 @@ public:
virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
void SetLayoutDirection(wxLayoutDirection dir);
wxLayoutDirection GetLayoutDirection() const;

View File

@ -28,7 +28,8 @@ public:
virtual ~wxMenuItem();
// implement base class virtuals
virtual void SetText( const wxString& str );
virtual void SetItemLabel( const wxString& str );
virtual wxString GetItemLabel() const;
virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE );
virtual bool IsChecked() const;
@ -77,6 +78,5 @@ private:
DECLARE_DYNAMIC_CLASS(wxMenuItem)
};
#endif
//__GTKMENUITEMH__

View File

@ -34,8 +34,8 @@ public:
virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
// implementation only from now on
void SetInvokingWindow( wxWindow *win );

View File

@ -28,7 +28,8 @@ public:
virtual ~wxMenuItem();
// implement base class virtuals
virtual void SetText( const wxString& str );
virtual void SetItemLabel( const wxString& str );
virtual wxString GetItemLabel() const;
virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE );
virtual bool IsChecked() const;
@ -73,6 +74,5 @@ private:
DECLARE_DYNAMIC_CLASS(wxMenuItem)
};
#endif
//__GTKMENUITEMH__

View File

@ -119,8 +119,8 @@ public:
virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
virtual bool Enable( bool enable = TRUE );
// for virtual function hiding
virtual void Enable( int itemid, bool enable )

View File

@ -35,7 +35,7 @@ public:
virtual ~wxMenuItem();
// override base class virtuals
virtual void SetText(const wxString& strName);
virtual void SetItemLabel(const wxString& strName);
virtual void Enable(bool bDoEnable = true);
virtual void Check(bool bDoCheck = true);

View File

@ -237,6 +237,9 @@ public:
void SetLabel(int itemid, const wxString& label);
wxString GetLabel(int itemid) const;
// Returns the stripped label
wxString GetLabelText(int itemid) const { return wxMenuItem::GetLabelText(GetLabel(itemid)); }
virtual void SetHelpString(int itemid, const wxString& helpString);
virtual wxString GetHelpString(int itemid) const;
@ -424,8 +427,11 @@ public:
virtual bool IsEnabledTop(size_t WXUNUSED(pos)) const { return true; }
// get or change the label of the menu at given position
virtual void SetLabelTop(size_t pos, const wxString& label) = 0;
virtual wxString GetLabelTop(size_t pos) const = 0;
virtual void SetMenuLabel(size_t pos, const wxString& label) = 0;
virtual wxString GetMenuLabel(size_t pos) const = 0;
// get the stripped label of the menu at given position
virtual wxString GetMenuLabelText(size_t pos) const { return wxMenuItem::GetLabelText(GetMenuLabel(pos)); }
// item search
// -----------
@ -490,6 +496,12 @@ public:
virtual bool CanBeOutsideClientArea() const { return true; }
#if WXWIN_COMPATIBILITY_2_8
// get or change the label of the menu at given position
wxDEPRECATED( void SetLabelTop(size_t pos, const wxString& label) );
wxDEPRECATED( wxString GetLabelTop(size_t pos) const );
#endif
protected:
// the list of all our menus
wxMenuList m_menus;
@ -500,6 +512,19 @@ protected:
DECLARE_NO_COPY_CLASS(wxMenuBarBase)
};
#if WXWIN_COMPATIBILITY_2_8
// get or change the label of the menu at given position
void wxMenuBarBase::SetLabelTop(size_t pos, const wxString& label)
{
SetMenuLabel(pos, label);
}
wxString wxMenuBarBase::GetLabelTop(size_t pos) const
{
return GetMenuLabel(pos);
}
#endif
// ----------------------------------------------------------------------------
// include the real class declaration
// ----------------------------------------------------------------------------

View File

@ -60,16 +60,23 @@ public:
// the item's text (or name)
//
// NB: the item's text includes the accelerators and mnemonics info (if
// NB: the item's label includes the accelerators and mnemonics info (if
// any), i.e. it may contain '&' or '_' or "\t..." and thus is
// different from the item's label which only contains the text shown
// in the menu
virtual void SetText(const wxString& str);
wxString GetLabel() const { return GetLabelFromText(m_text); }
const wxString& GetText() const { return m_text; }
// different from the item's text which only contains the text shown
// in the menu. This used to be called SetText.
virtual void SetItemLabel(const wxString& str);
// get the label from text (implemented in platform-specific code)
static wxString GetLabelFromText(const wxString& text);
// return the item label including any mnemonics and accelerators.
// This used to be called GetText.
virtual wxString GetItemLabel() const { return m_text; }
// return just the text of the item label, without any mnemonics
// This used to be called GetLabel.
virtual wxString GetItemLabelText() const { return GetLabelText(m_text); }
// return just the text part of the given label (implemented in platform-specific code)
// This used to be called GetLabelFromText.
static wxString GetLabelText(const wxString& label);
// what kind of menu item we are
wxItemKind GetKind() const { return m_kind; }
@ -111,7 +118,19 @@ public:
#if WXWIN_COMPATIBILITY_2_8
// compatibility only, use new functions in the new code
wxDEPRECATED( void SetName(const wxString& str) );
wxDEPRECATED( const wxString& GetName() const );
wxDEPRECATED( wxString GetName() const );
// Now use GetItemLabelText
wxDEPRECATED( wxString GetLabel() const ) ;
// Now use GetItemLabel
wxDEPRECATED( const wxString& GetText() const );
// Now use GetLabelText to strip the accelerators
wxDEPRECATED( static wxString GetLabelFromText(const wxString& text) );
// Now use SetItemLabel
wxDEPRECATED( virtual void SetText(const wxString& str) );
#endif // WXWIN_COMPATIBILITY_2_8
static wxMenuItem *New(wxMenu *parentMenu,
@ -152,9 +171,13 @@ private:
#if WXWIN_COMPATIBILITY_2_8
inline void wxMenuItemBase::SetName(const wxString &str)
{ SetText(str); }
inline const wxString& wxMenuItemBase::GetName() const
{ return GetText(); }
{ SetItemLabel(str); }
inline wxString wxMenuItemBase::GetName() const
{ return GetItemLabel(); }
inline wxString wxMenuItemBase::GetLabel() const
{ return GetLabelFromText(m_text); }
inline const wxString& wxMenuItemBase::GetText() const { return m_text; }
inline void wxMenuItemBase::SetText(const wxString& text) { SetItemLabel(text); }
#endif // WXWIN_COMPATIBILITY_2_8
// ----------------------------------------------------------------------------

View File

@ -130,8 +130,8 @@ public:
virtual wxMenuItem* FindItem( int id, wxMenu **menu = NULL ) const;
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
// implementation only from now on
// -------------------------------

View File

@ -33,7 +33,7 @@ public:
virtual ~wxMenuItem();
// accessors (some more are inherited from wxOwnerDrawn or are below)
virtual void SetText(const wxString& label);
virtual void SetItemLabel(const wxString& label);
virtual void Enable(bool enable = true);
virtual void Check(bool check = true);
// included SetBitmap and GetBitmap as copied from the GTK include file

View File

@ -163,8 +163,8 @@ public:
virtual wxMenu *Remove(size_t pos);
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
// implementation from now on
WXHMENU Create();

View File

@ -40,7 +40,7 @@ public:
virtual ~wxMenuItem();
// override base class virtuals
virtual void SetText(const wxString& strName);
virtual void SetItemLabel(const wxString& strName);
virtual void SetCheckable(bool checkable);
virtual void Enable(bool bDoEnable = true);

View File

@ -226,10 +226,10 @@ public:
virtual void EnableTop( size_t nPos
,bool bFlag
);
virtual void SetLabelTop( size_t nPos
virtual void SetMenuLabel( size_t nPos
,const wxString& rLabel
);
virtual wxString GetLabelTop(size_t nPos) const;
virtual wxString GetMenuLabel(size_t nPos) const;
//
// Implementation from now on

View File

@ -64,7 +64,7 @@ public:
//
// Override base class virtuals
//
virtual void SetText(const wxString& rStrName);
virtual void SetItemLabel(const wxString& rStrName);
virtual void SetCheckable(bool bCheckable);
virtual void Enable(bool bDoEnable = true);

View File

@ -144,8 +144,8 @@ public:
virtual wxMenu *Remove(size_t pos);
virtual void EnableTop( size_t pos, bool flag );
virtual void SetLabelTop( size_t pos, const wxString& label );
virtual wxString GetLabelTop( size_t pos ) const;
virtual void SetMenuLabel( size_t pos, const wxString& label );
virtual wxString GetMenuLabel( size_t pos ) const;
// implementation from now on
WXHMENU Create();

View File

@ -40,7 +40,7 @@ public:
virtual ~wxMenuItem();
// override base class virtuals
virtual void SetText(const wxString& strName);
virtual void SetItemLabel(const wxString& strName);
virtual void SetCheckable(bool checkable);
virtual void Enable(bool bDoEnable = TRUE);

View File

@ -155,8 +155,8 @@ public:
virtual void EnableTop(size_t pos, bool enable);
virtual bool IsEnabledTop(size_t pos) const;
virtual void SetLabelTop(size_t pos, const wxString& label);
virtual wxString GetLabelTop(size_t pos) const;
virtual void SetMenuLabel(size_t pos, const wxString& label);
virtual wxString GetMenuLabel(size_t pos) const;
virtual void Attach(wxFrame *frame);
virtual void Detach();

View File

@ -29,7 +29,7 @@ public:
virtual ~wxMenuItem();
// override base class virtuals to update the item appearance on screen
virtual void SetText(const wxString& text);
virtual void SetItemLabel(const wxString& text);
virtual void SetCheckable(bool checkable);
virtual void Enable(bool enable = true);

View File

@ -719,7 +719,7 @@ void MyFrame::OnGetLabelMenu(wxCommandEvent& WXUNUSED(event))
wxCHECK_RET( count, _T("no last menu?") );
wxLogMessage(_T("The label of the last menu item is '%s'"),
mbar->GetLabelTop(count - 1).c_str());
mbar->GetMenuLabel(count - 1).c_str());
}
#if wxUSE_TEXTDLG
@ -734,13 +734,13 @@ void MyFrame::OnSetLabelMenu(wxCommandEvent& WXUNUSED(event))
(
_T("Enter new label: "),
_T("Change last menu text"),
mbar->GetLabelTop(count - 1),
mbar->GetMenuLabel(count - 1),
this
);
if ( !label.empty() )
{
mbar->SetLabelTop(count - 1, label);
mbar->SetMenuLabel(count - 1, label);
}
}
@ -874,14 +874,14 @@ void MyFrame::OnSetLabelMenuItem(wxCommandEvent& WXUNUSED(event))
(
_T("Enter new label: "),
_T("Change last menu item text"),
item->GetLabel(),
item->GetItemLabel(),
this
);
label.Replace( _T("\\t"), _T("\t") );
if ( !label.empty() )
{
item->SetText(label);
item->SetItemLabel(label);
}
}
}

View File

@ -215,11 +215,11 @@ bool wxMenuBar::IsEnabledTop(size_t pos) const
return false;
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxMenu *menu = GetMenu(pos);
int itemindex = [m_cocoaNSMenu indexOfItemWithSubmenu:menu->GetNSMenu()];

View File

@ -98,7 +98,7 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
}
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}
@ -281,9 +281,9 @@ void wxMenuItem::Check(bool check)
}
}
void wxMenuItem::SetText(const wxString& label)
void wxMenuItem::SetItemLabel(const wxString& label)
{
wxMenuItemBase::SetText(label);
wxMenuItemBase::SetItemLabel(label);
wxCHECK_RET(m_kind != wxITEM_SEPARATOR, wxT("Separator items do not have titles."));
[m_cocoaNSMenuItem setTitle: wxNSStringWithWxString(wxStripMenuCodes(label))];
CocoaSetKeyEquivalent();

View File

@ -71,7 +71,7 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu,
if (m_id == wxID_SEPARATOR)
m_kind = wxITEM_SEPARATOR;
SetText(text);
SetItemLabel(text);
SetHelp(help);
}
@ -84,7 +84,7 @@ wxMenuItemBase::~wxMenuItemBase()
wxAcceleratorEntry *wxMenuItemBase::GetAccel() const
{
return wxAcceleratorEntry::Create(GetText());
return wxAcceleratorEntry::Create(GetItemLabel());
}
void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
@ -96,12 +96,12 @@ void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel)
text += accel->ToString();
}
SetText(text);
SetItemLabel(text);
}
#endif // wxUSE_ACCEL
void wxMenuItemBase::SetText(const wxString& str)
void wxMenuItemBase::SetItemLabel(const wxString& str)
{
m_text = str;
@ -125,6 +125,13 @@ void wxMenuItemBase::SetHelp(const wxString& str)
}
}
#if WXWIN_COMPATIBILITY_2_8
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{
return GetLabelText(text);
}
#endif
bool wxMenuBase::ms_locked = true;
// ----------------------------------------------------------------------------
@ -283,7 +290,7 @@ bool wxMenuBase::DoDestroy(wxMenuItem *item)
// Finds the item id matching the given string, wxNOT_FOUND if not found.
int wxMenuBase::FindItem(const wxString& text) const
{
wxString label = wxMenuItem::GetLabelFromText(text);
wxString label = wxMenuItem::GetLabelText(text);
for ( wxMenuItemList::compatibility_iterator node = m_items.GetFirst();
node;
node = node->GetNext() )
@ -545,7 +552,7 @@ void wxMenuBase::SetLabel( int id, const wxString &label )
wxCHECK_RET( item, wxT("wxMenu::SetLabel: no such item") );
item->SetText(label);
item->SetItemLabel(label);
}
wxString wxMenuBase::GetLabel( int id ) const
@ -554,7 +561,7 @@ wxString wxMenuBase::GetLabel( int id ) const
wxCHECK_MSG( item, wxEmptyString, wxT("wxMenu::GetLabel: no such item") );
return item->GetText();
return item->GetItemLabel();
}
void wxMenuBase::SetHelpString( int id, const wxString& helpString )
@ -665,14 +672,14 @@ wxMenu *wxMenuBarBase::Remove(size_t pos)
int wxMenuBarBase::FindMenu(const wxString& title) const
{
wxString label = wxMenuItem::GetLabelFromText(title);
wxString label = wxMenuItem::GetLabelText(title);
size_t count = GetMenuCount();
for ( size_t i = 0; i < count; i++ )
{
wxString title2 = GetLabelTop(i);
wxString title2 = GetMenuLabel(i);
if ( (title2 == title) ||
(wxMenuItem::GetLabelFromText(title2) == label) )
(wxMenuItem::GetLabelText(title2) == label) )
{
// found
return (int)i;
@ -723,13 +730,13 @@ wxMenuItem *wxMenuBarBase::FindItem(int id, wxMenu **menu) const
int wxMenuBarBase::FindMenuItem(const wxString& menu, const wxString& item) const
{
wxString label = wxMenuItem::GetLabelFromText(menu);
wxString label = wxMenuItem::GetLabelText(menu);
int i = 0;
wxMenuList::compatibility_iterator node;
for ( node = m_menus.GetFirst(); node; node = node->GetNext(), i++ )
{
if ( label == wxMenuItem::GetLabelFromText(GetLabelTop(i)) )
if ( label == wxMenuItem::GetLabelText(GetMenuLabel(i)) )
return node->GetData()->FindItem(item);
}
@ -783,7 +790,7 @@ void wxMenuBarBase::SetLabel(int id, const wxString& label)
wxCHECK_RET( item, wxT("wxMenuBar::SetLabel(): no such item") );
item->SetText(label);
item->SetItemLabel(label);
}
wxString wxMenuBarBase::GetLabel(int id) const
@ -793,7 +800,7 @@ wxString wxMenuBarBase::GetLabel(int id) const
wxCHECK_MSG( item, wxEmptyString,
wxT("wxMenuBar::GetLabel(): no such item") );
return item->GetText();
return item->GetItemLabel();
}
void wxMenuBarBase::SetHelpString(int id, const wxString& helpString)

View File

@ -1153,7 +1153,7 @@ bool wxLaunchDefaultBrowser(const wxString& urlOrig, int flags)
wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out)
{
#if wxUSE_MENUS
wxString s = wxMenuItem::GetLabelFromText(in);
wxString s = wxMenuItem::GetLabelText(in);
#else
wxString str(in);
wxString s = wxStripMenuCodes(str);

View File

@ -90,6 +90,40 @@ 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
//-----------------------------------------------------------------------------
@ -419,7 +453,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)
@ -504,7 +538,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 );
@ -512,26 +546,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 );
@ -728,8 +746,19 @@ wxMenuItem::~wxMenuItem()
// return the menu item text without any menu accels
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
// TODO: this is now wrong, because it will be used by public APIs
// to convert from label-with-wxWidgets-hotkeys to plain text,
// and this function converts from GTK+ hotkeys to plain 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++ )
@ -763,12 +792,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& str )
wxString wxMenuItem::GetItemLabel() const
{
return wxConvertFromGTKToWXLabel(m_text);
}
void wxMenuItem::SetItemLabel( const wxString& str )
{
// cache some data which must be used later
bool isstock = wxIsStockID(GetId());
@ -863,7 +898,7 @@ void wxMenuItem::SetText( const wxString& str )
}
// NOTE: this function is different from the similar functions GTKProcessMnemonics()
// implemented in control.cpp and from wxMenuItemBase::GetLabelFromText...
// implemented in control.cpp and from wxMenuItemBase::GetLabelText...
// so there's no real code duplication
wxString wxMenuItem::GTKProcessMenuItemLabel(const wxString& str, wxString *hotKey)
{
@ -1047,7 +1082,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
GtkWidget *menuItem;
// cache some data used later
wxString text = mitem->GetText();
wxString text = mitem->GetItemLabel();
int id = mitem->GetId();
bool isstock = wxIsStockID(id);
const char *stockid = NULL;
@ -1113,7 +1148,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
}
else // a normal item
{
// NB: 'text' variable has "_" instead of "&" after mitem->SetText()
// NB: 'text' variable has "_" instead of "&" after mitem->SetItemLabel()
// so don't use it
switch ( mitem->GetKind() )
@ -1161,7 +1196,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
GdkModifierType accel_mods;
wxCharBuffer buf = wxGTK_CONV_SYS( 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() );
if (buf[(size_t)0] != '\0')
{
gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);

View File

@ -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)
{

View File

@ -852,7 +852,7 @@ bool wxMenuBar::Enable(bool enable)
return true;
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
@ -870,10 +870,10 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
}
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetLabelTop") );
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return m_titles[pos];
}

View File

@ -233,13 +233,13 @@ void wxMenuItem::Check(bool bDoCheck)
}
}
void wxMenuItem::SetText(const wxString& text)
void wxMenuItem::SetItemLabel(const wxString& text)
{
// don't do anything if label didn't change
if ( m_text == text )
return;
wxMenuItemBase::SetText(text);
wxMenuItemBase::SetItemLabel(text);
UpdateItemText() ;
}
@ -273,7 +273,7 @@ void wxMenuItem::SetRadioGroupEnd(int end)
// ----------------------------------------------------------------------------
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}

View File

@ -221,7 +221,7 @@ void wxMenuBar::EnableTop(size_t WXUNUSED(pos), bool WXUNUSED(flag))
// wxLogWarning("wxMenuBar::EnableTop not yet implemented.");
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxMenu *menu = GetMenu(pos);
if ( !menu )
@ -236,26 +236,14 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
XmNlabelString, label_str(),
NULL);
}
m_titles[i] = label;
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxMenu *menu = GetMenu(pos);
if ( menu )
{
Widget w = (Widget)menu->GetButtonWidget();
if (w)
{
XmString text;
XtVaGetValues(w,
XmNlabelString, &text,
NULL);
return wxXmStringToString( text );
}
}
return wxEmptyString;
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return m_titles[pos];
}
bool wxMenuBar::Append(wxMenu * menu, const wxString& title)

View File

@ -137,7 +137,7 @@ void wxMenuItem::Check(bool bDoCheck)
}
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}
@ -308,7 +308,7 @@ void wxMenuItem::DestroyItem(bool full)
}
}
void wxMenuItem::SetText(const wxString& label)
void wxMenuItem::SetItemLabel(const wxString& label)
{
char mnem = wxFindMnemonic (label);
wxString label2 = wxStripMenuCodes(label);

View File

@ -398,7 +398,7 @@ void wxFrame::AttachMenuBar(wxMenuBar *menubar)
if( menubar->GetMenuCount() == 1 )
{
autoMenu = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(menubar->GetMenu(0));
SetRightMenu(wxID_ANY, menubar->GetLabelTop(0), autoMenu);
SetRightMenu(wxID_ANY, menubar->GetMenuLabel(0), autoMenu);
}
else
{
@ -407,7 +407,7 @@ void wxFrame::AttachMenuBar(wxMenuBar *menubar)
for( size_t n = 0; n < menubar->GetMenuCount(); n++ )
{
wxMenu *item = menubar->GetMenu(n);
wxString label = menubar->GetLabelTop(n);
wxString label = menubar->GetMenuLabel(n);
wxMenu *new_item = wxTopLevelWindowMSW::ButtonMenu::DuplicateMenu(item);
autoMenu->Append(wxID_ANY, label, new_item);
}

View File

@ -227,7 +227,7 @@ const wxMenuInfoList& wxMenuBar::GetMenuInfos() const
for( size_t i = 0 ; i < GetMenuCount() ; ++i )
{
wxMenuInfo* info = new wxMenuInfo() ;
info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetLabelTop(i) ) ;
info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetMenuLabel(i) ) ;
list->Append( info ) ;
}
return m_menuInfos ;
@ -331,7 +331,7 @@ void wxMenu::UpdateAccel(wxMenuItem *item)
}
// find the (new) accel for this item
wxAcceleratorEntry *accel = wxAcceleratorEntry::Create(item->GetText());
wxAcceleratorEntry *accel = wxAcceleratorEntry::Create(item->GetItemLabel());
if ( accel )
accel->m_command = item->GetId();
@ -404,7 +404,7 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
// prepare to insert the item in the menu
wxString itemText = pItem->GetText();
wxString itemText = pItem->GetItemLabel();
LPCTSTR pData = NULL;
if ( pos == (size_t)-1 )
{
@ -545,7 +545,7 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos)
flags |= MF_STRING;
#ifdef __WXWINCE__
itemText = wxMenuItem::GetLabelFromText(itemText);
itemText = wxMenuItem::GetLabelText(itemText);
#endif
pData = (wxChar*)itemText.wx_str();
@ -949,7 +949,7 @@ WXHMENU wxMenuBar::Create()
{
HMENU hPopupMenu = (HMENU) GetMenu(i)->GetHMenu();
tbButton.dwData = (DWORD)hPopupMenu;
wxString label = wxStripMenuCodes(GetLabelTop(i));
wxString label = wxStripMenuCodes(GetMenuLabel(i));
tbButton.iString = (int) label.wx_str();
tbButton.idCommand = NewControlId();
@ -1036,7 +1036,7 @@ void wxMenuBar::EnableTop(size_t pos, bool enable)
Refresh();
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
@ -1094,12 +1094,12 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
Refresh();
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetLabelTop") );
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return wxMenuItem::GetLabelFromText(m_titles[pos]);
return m_titles[pos];
}
// ---------------------------------------------------------------------------

View File

@ -207,7 +207,7 @@ bool wxMenuItem::IsChecked() const
}
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}
@ -337,7 +337,7 @@ void wxMenuItem::Check(bool check)
wxMenuItemBase::Check(check);
}
void wxMenuItem::SetText(const wxString& txt)
void wxMenuItem::SetItemLabel(const wxString& txt)
{
wxString text = txt;
@ -346,7 +346,7 @@ void wxMenuItem::SetText(const wxString& txt)
return;
// wxMenuItemBase will do stock ID checks
wxMenuItemBase::SetText(text);
wxMenuItemBase::SetItemLabel(text);
// m_text could now be different from 'text' if we are a stock menu item,
// so use only m_text below

View File

@ -847,7 +847,7 @@ void wxMenuBar::EnableTop(
Refresh();
} // end of wxMenuBar::EnableTop
void wxMenuBar::SetLabelTop(
void wxMenuBar::SetMenuLabel(
size_t nPos
, const wxString& rLabel
)
@ -884,16 +884,16 @@ void wxMenuBar::SetLabelTop(
wxLogLastError(wxT("ModifyMenu"));
}
Refresh();
} // end of wxMenuBar::SetLabelTop
} // end of wxMenuBar::SetMenuLabel
wxString wxMenuBar::GetLabelTop(
wxString wxMenuBar::GetMenuLabel(
size_t nPos
) const
{
wxCHECK_MSG( nPos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetLabelTop") );
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return m_titles[nPos];
} // end of wxMenuBar::GetLabelTop
} // end of wxMenuBar::GetMenuLabel
// ---------------------------------------------------------------------------
// wxMenuBar construction

View File

@ -180,7 +180,7 @@ bool wxMenuItem::IsChecked() const
return (uFlag & MIA_CHECKED) == MIA_CHECKED ;
} // end of wxMenuItem::IsChecked
wxString wxMenuItemBase::GetLabelFromText(
wxString wxMenuItemBase::GetLabelText(
const wxString& rsText
)
{
@ -199,7 +199,7 @@ wxString wxMenuItemBase::GetLabelFromText(
sLabel += *zPc;
}
return sLabel;
} // end of wxMenuItemBase::GetLabelFromText
} // end of wxMenuItemBase::GetLabelText
//
// Radio group stuff
@ -363,7 +363,7 @@ void wxMenuItem::Check(
wxMenuItemBase::Check(bCheck);
} // end of wxMenuItem::Check
void wxMenuItem::SetText( const wxString& rText )
void wxMenuItem::SetItemLabel( const wxString& rText )
{
//
// Don't do anything if label didn't change
@ -374,7 +374,7 @@ void wxMenuItem::SetText( const wxString& rText )
return;
// wxMenuItemBase will do stock ID checks
wxMenuItemBase::SetText(sText);
wxMenuItemBase::SetItemLabel(sText);
// m_text could now be different from 'text' if we are a stock menu item,
// so use only m_text below

View File

@ -152,7 +152,7 @@ const wxMenuInfoList& wxMenuBar::GetMenuInfos() const
for( size_t i = 0 ; i < GetMenuCount() ; ++i )
{
wxMenuInfo* info = new wxMenuInfo() ;
info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetLabelTop(i) ) ;
info->Create( const_cast<wxMenuBar*>(this)->GetMenu(i) , GetMenuLabel(i) ) ;
list->Append( info ) ;
}
return m_menuInfos ;
@ -372,11 +372,11 @@ void wxMenuBar::EnableTop(size_t pos, bool enable)
// Palm OS does not have support for grayed or disabled items
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetMenuCount(), wxT("invalid menu index") );
m_titles[pos]=wxStripMenuCodes(label);
m_titles[pos] = label;
if ( !IsAttached() )
{
@ -387,12 +387,12 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
Refresh();
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString,
wxT("invalid menu index in wxMenuBar::GetLabelTop") );
wxT("invalid menu index in wxMenuBar::GetMenuLabel") );
return wxMenuItem::GetLabelFromText(m_titles[pos]);
return m_titles[pos];
}
// ---------------------------------------------------------------------------
@ -405,7 +405,7 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title)
if ( !menuOld )
return NULL;
m_titles[pos]=wxStripMenuCodes(title);
m_titles[pos] = title;
if ( IsAttached() )
{
@ -421,7 +421,7 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title)
if ( !wxMenuBarBase::Insert(pos, menu, title) )
return false;
m_titles.Insert(wxStripMenuCodes(title), pos);
m_titles.Insert(title, pos);
if ( IsAttached() )
{
@ -437,7 +437,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title)
if ( !wxMenuBarBase::Append(menu, title) )
return false;
m_titles.Add(wxStripMenuCodes(title));
m_titles.Add(title);
if(IsAttached())
{

View File

@ -159,7 +159,7 @@ bool wxMenuItem::IsChecked() const
}
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}
@ -190,7 +190,7 @@ void wxMenuItem::Check(bool check)
{
}
void wxMenuItem::SetText(const wxString& text)
void wxMenuItem::SetItemLabel(const wxString& text)
{
}

View File

@ -1516,7 +1516,7 @@ wxMenuItem *wxMenuItemBase::New(wxMenu *parentMenu,
}
/* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
wxString wxMenuItemBase::GetLabelText(const wxString& text)
{
return wxStripMenuCodes(text);
}
@ -1538,13 +1538,13 @@ void wxMenuItem::UpdateAccelInfo()
m_strAccel = m_text.AfterFirst(_T('\t'));
}
void wxMenuItem::SetText(const wxString& text)
void wxMenuItem::SetItemLabel(const wxString& text)
{
if ( text != m_text )
{
// first call the base class version to change m_text
// (and also check if we don't have a stock menu item)
wxMenuItemBase::SetText(text);
wxMenuItemBase::SetItemLabel(text);
UpdateAccelInfo();
@ -1820,9 +1820,9 @@ bool wxMenuBar::IsEnabledTop(size_t pos) const
return m_menuInfos[pos].IsEnabled();
}
void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
void wxMenuBar::SetMenuLabel(size_t pos, const wxString& label)
{
wxCHECK_RET( pos < GetCount(), _T("invalid index in EnableTop") );
wxCHECK_RET( pos < GetCount(), _T("invalid index in SetMenuLabel") );
if ( label != m_menuInfos[pos].GetLabel() )
{
@ -1833,9 +1833,9 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label)
//else: nothing to do
}
wxString wxMenuBar::GetLabelTop(size_t pos) const
wxString wxMenuBar::GetMenuLabel(size_t pos) const
{
wxCHECK_MSG( pos < GetCount(), wxEmptyString, _T("invalid index in GetLabelTop") );
wxCHECK_MSG( pos < GetCount(), wxEmptyString, _T("invalid index in GetMenuLabel") );
return m_menuInfos[pos].GetLabel();
}
@ -1960,7 +1960,7 @@ wxSize wxMenuBar::DoGetBestClientSize() const
{
wxClientDC dc(wxConstCast(this, wxMenuBar));
dc.SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
dc.GetTextExtent(GetLabelTop(0), &size.x, &size.y);
dc.GetTextExtent(GetMenuLabel(0), &size.x, &size.y);
// adjust for the renderer we use
size = GetRenderer()->GetMenuBarItemSize(size);