From fb9c1ff9cb7be729351eed0575e32758bdd85c75 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Mon, 13 Aug 2007 17:07:01 +0000 Subject: [PATCH] Binary compatible API fixes for menu label retrieval with and without mnemonics/accelerators. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48053 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 4 ++ docs/latex/wx/menu.tex | 98 ++++++++++++++++++++++++++++++- docs/latex/wx/menuitem.tex | 60 ++++++++++++++++++- include/wx/cocoa/menu.h | 10 +++- include/wx/cocoa/menuitem.h | 10 +++- include/wx/gtk/menu.h | 7 +++ include/wx/gtk/menuitem.h | 8 +++ include/wx/gtk1/menu.h | 7 +++ include/wx/gtk1/menuitem.h | 8 +++ include/wx/mac/carbon/menu.h | 9 ++- include/wx/mac/carbon/menuitem.h | 10 +++- include/wx/mac/classic/menu.h | 9 ++- include/wx/mac/classic/menuitem.h | 8 +++ include/wx/menu.h | 23 ++++++++ include/wx/menuitem.h | 21 +++++++ include/wx/motif/menu.h | 7 +++ include/wx/motif/menuitem.h | 9 +++ include/wx/msw/menu.h | 7 +++ include/wx/msw/menuitem.h | 8 +++ include/wx/os2/menu.h | 7 +++ include/wx/os2/menuitem.h | 9 +++ include/wx/palmos/menu.h | 7 +++ include/wx/palmos/menuitem.h | 8 +++ include/wx/univ/menu.h | 7 +++ include/wx/univ/menuitem.h | 10 +++- src/cocoa/menu.mm | 7 +++ src/common/menucmn.cpp | 12 ++++ src/gtk/menu.cpp | 75 ++++++++++++++++++----- src/gtk1/menu.cpp | 75 ++++++++++++++++++----- src/mac/carbon/menu.cpp | 55 +++++++++-------- src/mac/carbon/menuitem.cpp | 6 +- src/mac/classic/menu.cpp | 9 +++ src/motif/menu.cpp | 15 +++++ src/msw/menu.cpp | 13 +++- src/os2/menu.cpp | 12 +++- src/palmos/menu.cpp | 9 +++ src/univ/menu.cpp | 18 +++++- version-script.in | 8 +++ 38 files changed, 615 insertions(+), 70 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 93c1622392..be8e4b07b5 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -108,6 +108,10 @@ All (GUI): - Fixed wxXPMHandler::SaveFile for images with more than 92 colors. - Fixed a crash in wxGrid on creation due to OnSize being called too soon. - Added XRC handler for wxPropertySheetDialog (Sander Berents). +- API consistency fixes: added wxMenuBar::SetMenuLabel, wxMenuBar::GetMenuLabel, + wxMenuBar::GetMenuLabelText, wxMenu::GetLabelText, wxMenuItem::SetItemLabel, + wxMenuItem::GetItemLabel, wxMenuItem::GetItemLabelText, wxMenuItem::GetLabelText. + Retrieval of labels with and without mnemonics/accelerators is now possible. wxMSW: diff --git a/docs/latex/wx/menu.tex b/docs/latex/wx/menu.tex index 6f6a0805bc..9b6d5bac77 100644 --- a/docs/latex/wx/menu.tex +++ b/docs/latex/wx/menu.tex @@ -423,7 +423,7 @@ item was not found. \constfunc{wxString}{GetLabel}{\param{int}{ id}} -Returns a menu item label. +Returns a menu item label, including any mnemonics and accelerators. \wxheading{Parameters} @@ -435,7 +435,26 @@ The item label, or the empty string if the item was not found. \wxheading{See also} -\helpref{wxMenu::SetLabel}{wxmenusetlabel} +\helpref{wxMenu::GetLabelText}{wxmenugetlabeltext}, \helpref{wxMenu::SetLabel}{wxmenusetlabel} + + +\membersection{wxMenu::GetLabelText}\label{wxmenugetlabeltext} + +\constfunc{wxString}{GetLabelText}{\param{int}{ id}} + +Returns a menu item label, without any of the original mnemonics and accelerators. + +\wxheading{Parameters} + +\docparam{id}{The menu item identifier.} + +\wxheading{Return value} + +The item label, or the empty string if the item was not found. + +\wxheading{See also} + +\helpref{wxMenu::GetLabel}{wxmenugetlabel}, \helpref{wxMenu::SetLabel}{wxmenusetlabel} \membersection{wxMenu::GetMenuItemCount}\label{wxmenugetmenuitemcount} @@ -958,6 +977,8 @@ The menu label, or the empty string if the menu was not found. Use only after the menubar has been associated with a frame. +This function is deprecated in favour of \helpref{GetMenuLabel}{wxmenubargetmenulabel} and \helpref{GetMenuLabelText}{wxmenubargetmenulabeltext}. + \wxheading{See also} \helpref{wxMenuBar::SetLabelTop}{wxmenubarsetlabeltop} @@ -977,6 +998,56 @@ Returns the menu at {\it menuIndex} (zero-based). Returns the number of menus in this menubar. +\membersection{wxMenuBar::GetMenuLabel}\label{wxmenubargetmenulabel} + +\constfunc{wxString}{GetMenuLabel}{\param{int}{ pos}} + +Returns the label of a top-level menu. Note that the returned string +includes the accelerator characters that have been specified in the menu +title string during its construction. + +\wxheading{Parameters} + +\docparam{pos}{Position of the menu on the menu bar, starting from zero.} + +\wxheading{Return value} + +The menu label, or the empty string if the menu was not found. + +\wxheading{Remarks} + +Use only after the menubar has been associated with a frame. + +\wxheading{See also} + +\helpref{wxMenuBar::GetMenuLabelText}{wxmenubargetmenulabeltext}, \helpref{wxMenuBar::SetMenuLabel}{wxmenubarsetmenulabel} + + +\membersection{wxMenuBar::GetMenuLabelText}\label{wxmenubargetmenulabeltext} + +\constfunc{wxString}{GetMenuLabelText}{\param{int}{ pos}} + +Returns the label of a top-level menu. Note that the returned string does not +include any accelerator characters that may have been specified in the menu +title string during its construction. + +\wxheading{Parameters} + +\docparam{pos}{Position of the menu on the menu bar, starting from zero.} + +\wxheading{Return value} + +The menu label, or the empty string if the menu was not found. + +\wxheading{Remarks} + +Use only after the menubar has been associated with a frame. + +\wxheading{See also} + +\helpref{wxMenuBar::GetMenuLabel}{wxmenubargetmenulabel}, \helpref{wxMenuBar::SetMenuLabel}{wxmenubarsetmenulabel} + + \membersection{wxMenuBar::Insert}\label{wxmenubarinsert} \func{bool}{Insert}{\param{size\_t }{pos}, \param{wxMenu *}{menu}, \param{const wxString\& }{title}} @@ -1133,7 +1204,30 @@ Sets the label of a top-level menu. Use only after the menubar has been associated with a frame. +This function has been deprecated in favour of \helpref{SetMenuLabel}{wxmenubarsetmenulabel}. + \wxheading{See also} \helpref{wxMenuBar::GetLabelTop}{wxmenubargetlabeltop} + +\membersection{wxMenuBar::SetMenuLabel}\label{wxmenubarsetmenulabel} + +\func{void}{SetMenuLabel}{\param{int}{ pos}, \param{const wxString\& }{label}} + +Sets the label of a top-level menu. + +\wxheading{Parameters} + +\docparam{pos}{The position of a menu on the menu bar, starting from zero.} + +\docparam{label}{The menu label.} + +\wxheading{Remarks} + +Use only after the menubar has been associated with a frame. + +\wxheading{See also} + +\helpref{wxMenuBar::GetMenuLabel}{wxmenubargetmenulabel}, \helpref{wxMenuBar::GetMenuLabelText}{wxmenubargetmenulabeltext} + diff --git a/docs/latex/wx/menuitem.tex b/docs/latex/wx/menuitem.tex index d5cc838779..538e36c466 100644 --- a/docs/latex/wx/menuitem.tex +++ b/docs/latex/wx/menuitem.tex @@ -148,6 +148,31 @@ Returns the help string associated with the menu item. Returns the menu item identifier. +\membersection{wxMenuItem::GetItemLabel}\label{wxmenuitemgetitemlabel} + +\constfunc{wxString}{GetItemLabel}{\void} + +Returns the text associated with the menu item including any accelerator +characters that were passed to the constructor or SetItemLabel. + +\wxheading{See also} + +\helpref{GetItemLabelText}{wxmenuitemgetitemlabeltext}, +\helpref{GetLabelText}{wxmenuitemgetlabeltext} + + +\membersection{wxMenuItem::GetItemLabelText}\label{wxmenuitemgetitemlabeltext} + +\constfunc{wxString}{GetItemLabelText}{\void} + +Returns the text associated with the menu item, without any accelerator +characters. + +\wxheading{See also} + +\helpref{GetItemLabel}{wxmenuitemgetitemlabel}, +\helpref{GetLabelText}{wxmenuitemgetlabeltext} + \membersection{wxMenuItem::GetKind}\label{wxmenuitemgetkind} @@ -164,12 +189,33 @@ Returns the item kind, one of {\tt wxITEM\_SEPARATOR}, {\tt wxITEM\_NORMAL}, Returns the text associated with the menu item without any accelerator characters it might contain. +This function is deprecated in favour of \helpref{GetItemLabelText}{wxmenuitemgetitemlabeltext}. + \wxheading{See also} \helpref{GetText}{wxmenuitemgettext}, \helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext} +\membersection{wxMenuItem::GetLabelText}\label{wxmenuitemgetlabeltext} + +\func{static wxString}{GetLabelText}{\param{const wxString\& }{text}} + +Strips all accelerator characters and mnemonics from the given {\it text}. +For example, + +\begin{verbatim} +wxMenuItem::GetLabelFromText("&Hello\tCtrl-H"); +\end{verbatim} + +will return just {\tt "Hello"}. + +\wxheading{See also} + +\helpref{GetItemLabelText}{wxmenuitemgetitemlabeltext}, +\helpref{GetItemLabel}{wxmenuitemgetitemlabel} + + \membersection{wxMenuItem::GetLabelFromText}\label{wxmenuitemgetlabelfromtext} \func{static wxString}{GetLabelFromText}{\param{const wxString\& }{text}} @@ -183,12 +229,13 @@ wxMenuItem::GetLabelFromText("&Hello\tCtrl-H"); will return just {\tt "Hello"}. +This function is deprecated; please use \helpref{wxMenuItem::GetLabelText}{wxmenuitemgetlabeltext} instead. + \wxheading{See also} \helpref{GetText}{wxmenuitemgettext}, \helpref{GetLabel}{wxmenuitemgetlabel} - \membersection{wxMenuItem::GetMarginWidth}\label{wxmenuitemgetmarginwidth} \constfunc{int}{GetMarginWidth}{\void} @@ -221,6 +268,8 @@ instead. Returns the text associated with the menu item, such as it was passed to the wxMenuItem constructor, i.e. with any accelerator characters it may contain. +This function is deprecated in favour of \helpref{GetItemLabel}{wxmenuitemgetitemlabel}. + \wxheading{See also} \helpref{GetLabel}{wxmenuitemgetlabel}, @@ -314,6 +363,13 @@ Sets the font associated with the menu item (Windows only). Sets the help string. +\membersection{wxMenuItem::SetItemLabel}\label{wxmenuitemsetitemlabel} + +\func{void}{SetItemLabel}{\param{const wxString\& }{label}} + +Sets the label associated with the menu item. + + \membersection{wxMenuItem::SetMarginWidth}\label{wxmenuitemsetmarginwidth} \constfunc{void}{SetMarginWidth}{\param{int}{ width}} @@ -341,6 +397,8 @@ Sets the submenu of this menu item. Sets the text associated with the menu item. +This function is deprecated in favour of \helpref{SetItemLabel}{wxmenuitemsetitemlabel}. + \membersection{wxMenuItem::SetTextColour}\label{wxmenuitemsettextcolour} diff --git a/include/wx/cocoa/menu.h b/include/wx/cocoa/menu.h index bbd33a9565..6b9f89eb25 100644 --- a/include/wx/cocoa/menu.h +++ b/include/wx/cocoa/menu.h @@ -4,7 +4,7 @@ // Author: David Elliott // Modified by: // Created: 2002/12/09 -// RCS-ID: $Id: +// RCS-ID: $Id: // Copyright: (c) 2002 David Elliott // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -183,6 +183,14 @@ private: bool m_shouldShowMenu; DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif + }; #endif // _WX_COCOA_MENU_H_ diff --git a/include/wx/cocoa/menuitem.h b/include/wx/cocoa/menuitem.h index d5ba585ac6..76fda6fe2e 100644 --- a/include/wx/cocoa/menuitem.h +++ b/include/wx/cocoa/menuitem.h @@ -4,7 +4,7 @@ // Author: David Elliott // Modified by: // Created: 2002/12/13 -// RCS-ID: $Id: +// RCS-ID: $Id: // Copyright: (c) 2002 David Elliott // Licence: wxWindows licence /////////////////////////////////////////////////////////////////////////////// @@ -94,6 +94,14 @@ protected: private: DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif }; #endif // _WX_COCOA_MENUITEM_H_ diff --git a/include/wx/gtk/menu.h b/include/wx/gtk/menu.h index cc00c2fd7c..dc80fa95a3 100644 --- a/include/wx/gtk/menu.h +++ b/include/wx/gtk/menu.h @@ -57,6 +57,13 @@ private: void Init(size_t n, wxMenu *menus[], const wxString titles[], long style); DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; //----------------------------------------------------------------------------- diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index 7ac723e239..02eb97f997 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -75,6 +75,14 @@ private: GtkWidget* m_labelWidget; // Label widget DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const; +#endif + }; diff --git a/include/wx/gtk1/menu.h b/include/wx/gtk1/menu.h index f2aef5abb5..b4e0c2c137 100644 --- a/include/wx/gtk1/menu.h +++ b/include/wx/gtk1/menu.h @@ -53,6 +53,13 @@ private: void Init(size_t n, wxMenu *menus[], const wxString titles[], long style); DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; //----------------------------------------------------------------------------- diff --git a/include/wx/gtk1/menuitem.h b/include/wx/gtk1/menuitem.h index 95312d428c..52ed8cf9a8 100644 --- a/include/wx/gtk1/menuitem.h +++ b/include/wx/gtk1/menuitem.h @@ -71,6 +71,14 @@ private: GtkWidget* m_labelWidget; // Label widget DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const; +#endif }; diff --git a/include/wx/mac/carbon/menu.h b/include/wx/mac/carbon/menu.h index 4430389dec..2aac51e68d 100644 --- a/include/wx/mac/carbon/menu.h +++ b/include/wx/mac/carbon/menu.h @@ -43,7 +43,7 @@ public: // implementation only from now on // ------------------------------- - int MacGetIndexFromId( int id ) ; + int MacGetIndexFromId( int id ) ; int MacGetIndexFromItem( wxMenuItem *pItem ) ; void MacEnableMenu( bool bDoEnable ) ; // MacOS needs to know about submenus somewhere within this menu @@ -174,6 +174,13 @@ private: static wxMenuBar* s_macCommonMenuBar ; DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MENU_H_ diff --git a/include/wx/mac/carbon/menuitem.h b/include/wx/mac/carbon/menuitem.h index dc2b80ecd1..4af335e5aa 100644 --- a/include/wx/mac/carbon/menuitem.h +++ b/include/wx/mac/carbon/menuitem.h @@ -47,7 +47,7 @@ public: void UpdateItemBitmap() ; void UpdateItemText() ; void UpdateItemStatus() ; - + void DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) ; // mark item as belonging to the given radio group @@ -75,6 +75,14 @@ private: void* m_menu ; // the appropriate menu , may also be a system menu DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif }; #endif //_MENUITEM_H diff --git a/include/wx/mac/classic/menu.h b/include/wx/mac/classic/menu.h index 3add9b86e6..3ae9f0641b 100644 --- a/include/wx/mac/classic/menu.h +++ b/include/wx/mac/classic/menu.h @@ -47,7 +47,7 @@ public: // implementation only from now on // ------------------------------- - int MacGetIndexFromId( int id ) ; + int MacGetIndexFromId( int id ) ; int MacGetIndexFromItem( wxMenuItem *pItem ) ; void MacEnableMenu( bool bDoEnable ) ; // MacOS needs to know about submenus somewhere within this menu @@ -160,6 +160,13 @@ private: static wxMenuBar* s_macCommonMenuBar ; DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MENU_H_ diff --git a/include/wx/mac/classic/menuitem.h b/include/wx/mac/classic/menuitem.h index 94fb5e02c0..6018bfba7f 100644 --- a/include/wx/mac/classic/menuitem.h +++ b/include/wx/mac/classic/menuitem.h @@ -72,6 +72,14 @@ private: void* m_menu ; // the appropriate menu , may also be a system menu DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const; +#endif }; #endif //_MENUITEM_H diff --git a/include/wx/menu.h b/include/wx/menu.h index 9967d81d0d..9269597b02 100644 --- a/include/wx/menu.h +++ b/include/wx/menu.h @@ -375,6 +375,14 @@ protected: static bool ms_locked; DECLARE_NO_COPY_CLASS(wxMenuBase) + +public: + +#if wxABI_VERSION >= 20805 + // Returns the stripped label + wxString GetLabelText(int itemid) const { return wxMenuItem::GetLabelFromText(GetLabel(itemid)); } +#endif + }; // ---------------------------------------------------------------------------- @@ -496,6 +504,21 @@ protected: wxFrame *m_menuBarFrame; DECLARE_NO_COPY_CLASS(wxMenuBarBase) + +public: + +#if wxABI_VERSION >= 20805 + // Replacement for SetLabelTop + void SetMenuLabel(size_t pos, const wxString& label) { SetLabelTop(pos, label); } + + // Gets the original label at the top-level of the menubar + // Implemented per port, since we can't have virtual functions in the stable branch. + // wxString GetMenuLabel(size_t pos) const; + + // Get the text only, from the label at the top-level of the menubar + wxString GetMenuLabelText(size_t pos) const; +#endif + }; // ---------------------------------------------------------------------------- diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index 2a619da623..3425f1014a 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -65,6 +65,7 @@ public: // 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; } @@ -146,6 +147,26 @@ private: // declare them ourselves - but don't implement as they shouldn't be used wxMenuItemBase(const wxMenuItemBase& item); wxMenuItemBase& operator=(const wxMenuItemBase& item); + +public: + +#if wxABI_VERSION >= 20805 + // Sets the label. This function replaces SetText. + void SetItemLabel(const wxString& str) { SetText(str); } + + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + // We can't implement this in the base class (no new virtuals in stable branch) + // wxString GetItemLabel() const; + + // return just the text of the item label, without any mnemonics + // This used to be called GetLabel. + wxString GetItemLabelText() const { return GetLabelText(m_text); } + + // return just the text part of the given label. In 2.9 and up, this is implemented in + // platform-specific code, but is now implemented in terms of GetLabelFromText. + static wxString GetLabelText(const wxString& label); +#endif }; // ---------------------------------------------------------------------------- diff --git a/include/wx/motif/menu.h b/include/wx/motif/menu.h index 788c7c2248..57cba42ad4 100644 --- a/include/wx/motif/menu.h +++ b/include/wx/motif/menu.h @@ -170,6 +170,13 @@ public: wxFont m_font; DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MOTIF_MENU_H_ diff --git a/include/wx/motif/menuitem.h b/include/wx/motif/menuitem.h index e9c6bc965d..a3f1dc91ae 100644 --- a/include/wx/motif/menuitem.h +++ b/include/wx/motif/menuitem.h @@ -63,6 +63,15 @@ private: wxBitmap m_bitmap; // Bitmap for menuitem, if any DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif + }; #endif // _WX_MOTIF_MENUITEM_H diff --git a/include/wx/msw/menu.h b/include/wx/msw/menu.h index 89bc911dab..99c6e7933a 100644 --- a/include/wx/msw/menu.h +++ b/include/wx/msw/menu.h @@ -229,6 +229,13 @@ protected: private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MENU_H_ diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index 3b9d7875d3..b6238e9b78 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -87,6 +87,14 @@ private: bool m_isRadioGroupStart; DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif }; #endif //_MENUITEM_H diff --git a/include/wx/os2/menu.h b/include/wx/os2/menu.h index b871f900e4..7bf3d2ba68 100644 --- a/include/wx/os2/menu.h +++ b/include/wx/os2/menu.h @@ -287,6 +287,13 @@ private: { wxWindow::Refresh(bErase, pRect); } DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MENU_H_ diff --git a/include/wx/os2/menuitem.h b/include/wx/os2/menuitem.h index 1e9d1d89b8..7b8a597602 100644 --- a/include/wx/os2/menuitem.h +++ b/include/wx/os2/menuitem.h @@ -117,6 +117,15 @@ private: bool m_bIsRadioGroupStart; DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif + }; // end of CLASS wxMenuItem #endif //_MENUITEM_H diff --git a/include/wx/palmos/menu.h b/include/wx/palmos/menu.h index 9f8ea2e4c4..3f46bb26e7 100644 --- a/include/wx/palmos/menu.h +++ b/include/wx/palmos/menu.h @@ -192,6 +192,13 @@ protected: private: DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_MENU_H_ diff --git a/include/wx/palmos/menuitem.h b/include/wx/palmos/menuitem.h index 9954fd3827..153bc3158d 100644 --- a/include/wx/palmos/menuitem.h +++ b/include/wx/palmos/menuitem.h @@ -82,6 +82,14 @@ private: bool m_isRadioGroupStart; DECLARE_DYNAMIC_CLASS_NO_COPY(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif }; #endif //_MENUITEM_H diff --git a/include/wx/univ/menu.h b/include/wx/univ/menu.h index e023830bf0..a100c41445 100644 --- a/include/wx/univ/menu.h +++ b/include/wx/univ/menu.h @@ -270,6 +270,13 @@ private: DECLARE_EVENT_TABLE() DECLARE_DYNAMIC_CLASS(wxMenuBar) + +public: + +#if wxABI_VERSION >= 20805 + // Gets the original label at the top-level of the menubar + wxString GetMenuLabel(size_t pos) const; +#endif }; #endif // _WX_UNIV_MENU_H_ diff --git a/include/wx/univ/menuitem.h b/include/wx/univ/menuitem.h index da63e3afa0..aec22127ec 100644 --- a/include/wx/univ/menuitem.h +++ b/include/wx/univ/menuitem.h @@ -94,7 +94,7 @@ protected: // the bitmaps (may be invalid, then they're not used) wxBitmap m_bmpChecked, m_bmpUnchecked, - m_bmpDisabled; + m_bmpDisabled; // the positions of the first and last items of the radio group this item // belongs to or -1: start is the radio group start and is valid for all @@ -121,6 +121,14 @@ protected: private: DECLARE_DYNAMIC_CLASS(wxMenuItem) + +public: + +#if wxABI_VERSION >= 20805 + // return the item label including any mnemonics and accelerators. + // This used to be called GetText. + wxString GetItemLabel() const { return GetText(); } +#endif }; #endif // _WX_UNIV_MENUITEM_H_ diff --git a/src/cocoa/menu.mm b/src/cocoa/menu.mm index 55e0f3035b..b139c21909 100644 --- a/src/cocoa/menu.mm +++ b/src/cocoa/menu.mm @@ -227,6 +227,13 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const return wxStringWithNSString([[m_cocoaNSMenu itemAtIndex:itemindex] title]); } +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + // TODO: restore the original mnemonics + return GetLabelTop(pos); +} + void wxMenuBar::Attach(wxFrame *frame) { wxMenuBarBase::Attach(frame); diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 87969e0411..ed2132ecea 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -445,6 +445,11 @@ void wxMenuItemBase::SetHelp(const wxString& str) } } +wxString wxMenuItemBase::GetLabelText(const wxString& label) +{ + return GetLabelFromText(label); +} + bool wxMenuBase::ms_locked = true; // ---------------------------------------------------------------------------- @@ -1152,4 +1157,11 @@ void wxMenuBarBase::UpdateMenus( void ) } } +// Get the text only, from the label +wxString wxMenuBarBase::GetMenuLabelText(size_t pos) const +{ + return wxMenuItem::GetLabelText(((wxMenuBar*)this)->GetMenuLabel(pos)); +} + + #endif // wxUSE_MENUS diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 5b827b1e79..987047917b 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -91,6 +91,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 //----------------------------------------------------------------------------- @@ -425,7 +459,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::GetLabelFromText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelFromText(menuString)) { int res = menu->FindItem( itemString ); if (res != wxNOT_FOUND) @@ -518,23 +552,19 @@ 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; - } + return wxStripMenuCodes(wxConvertFromGTKToWXLabel(menu->GetTitle())); +} - // don't remove ampersands '&' since if we have them in the menu title - // it means that they were doubled to indicate "&" instead of accelerator +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxMenuList::compatibility_iterator node = m_menus.Item( pos ); - label += *pc; - } + wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") ); - return label; + wxMenu* menu = node->GetData(); + + return wxConvertFromGTKToWXLabel(menu->GetTitle()); } void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) @@ -743,6 +773,12 @@ wxMenuItem::~wxMenuItem() /* static */ wxString wxMenuItemBase::GetLabelFromText(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++ ) @@ -779,6 +815,7 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() ); return label; +#endif } void wxMenuItem::SetText( const wxString& str ) @@ -986,6 +1023,14 @@ bool wxMenuItem::IsChecked() const return ((GtkCheckMenuItem*)m_menuItem)->active != 0; } +wxString wxMenuItem::GetItemLabel() const +{ + wxString label = wxConvertFromGTKToWXLabel(m_text); + if (!m_hotKey.IsEmpty()) + label = label + wxT("\t") + m_hotKey; + return label; +} + //----------------------------------------------------------------------------- // wxMenu //----------------------------------------------------------------------------- diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 32295957b9..c7076518c3 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -91,6 +91,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 //----------------------------------------------------------------------------- @@ -408,7 +442,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::GetLabelFromText(wxConvertFromGTKToWXLabel(menu->GetTitle())) == wxMenuItem::GetLabelFromText(menuString)) { int res = menu->FindItem( itemString ); if (res != wxNOT_FOUND) @@ -501,23 +535,19 @@ 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; - } + return wxStripMenuCodes(wxConvertFromGTKToWXLabel(menu->GetTitle())); +} - // don't remove ampersands '&' since if we have them in the menu title - // it means that they were doubled to indicate "&" instead of accelerator +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxMenuList::compatibility_iterator node = m_menus.Item( pos ); - label += *pc; - } + wxCHECK_MSG( node, wxT("invalid"), wxT("menu not found") ); - return label; + wxMenu* menu = node->GetData(); + + return wxConvertFromGTKToWXLabel(menu->GetTitle()); } void wxMenuBar::SetLabelTop( size_t pos, const wxString& label ) @@ -736,6 +766,12 @@ wxMenuItem::~wxMenuItem() /* static */ wxString wxMenuItemBase::GetLabelFromText(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++ ) @@ -762,6 +798,7 @@ wxString wxMenuItemBase::GetLabelFromText(const wxString& text) } // wxPrintf( wxT("GetLabelFromText(): text %s label %s\n"), text.c_str(), label.c_str() ); +#endif return label; } @@ -927,6 +964,14 @@ bool wxMenuItem::IsChecked() const return ((GtkCheckMenuItem*)m_menuItem)->active != 0; } +wxString wxMenuItem::GetItemLabel() const +{ + wxString label = wxConvertFromGTKToWXLabel(m_text); + if (!m_hotKey.IsEmpty()) + label = label + wxT("\t") + m_hotKey; + return label; +} + //----------------------------------------------------------------------------- // wxMenu //----------------------------------------------------------------------------- diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 305374bb50..b0d4629acf 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -94,14 +94,14 @@ void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter subMenu = item->GetSubMenu() ; if (subMenu) { - wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); + wxInsertMenuItemsInMenu(subMenu, (MenuRef)subMenu->GetHMenu(), 0); } if ( item->IsSeparator() ) { if ( wm && newItems) InsertMenuItemTextWithCFString( wm, - CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); - + CFSTR(""), insertAfter, kMenuItemAttrSeparator, 0); + newItems = false; } else @@ -110,9 +110,9 @@ void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter entry = wxAcceleratorEntry::Create( item->GetText() ) ; MenuItemIndex winListPos = (MenuItemIndex)-1; - OSStatus err = GetIndMenuItemWithCommandID(wm, + OSStatus err = GetIndMenuItemWithCommandID(wm, wxIdToMacCommand ( item->GetId() ), 1, NULL, &winListPos); - + if ( wm && err == menuItemNotFoundErr ) { // NB: the only way to determine whether or not we should add @@ -126,7 +126,7 @@ void wxInsertMenuItemsInMenu(wxMenu* menu, MenuRef wm, MenuItemIndex insertAfter delete entry ; } - } + } } // ============================================================================ @@ -210,10 +210,10 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { if ( pos == (size_t)-1 ) AppendMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), - CFSTR(""), kMenuItemAttrSeparator, 0,NULL); + CFSTR(""), kMenuItemAttrSeparator, 0,NULL); else InsertMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), - CFSTR(""), pos, kMenuItemAttrSeparator, 0); + CFSTR(""), pos, kMenuItemAttrSeparator, 0); } else { @@ -655,10 +655,10 @@ void wxMenuBar::MacInstallMenuBar() // However, the change from 10.2 to 10.3 suggests it is preferred #if TARGET_API_MAC_OSX InsertMenuItemTextWithCFString( appleMenu, - CFSTR(""), 0, kMenuItemAttrSeparator, 0); + CFSTR(""), 0, kMenuItemAttrSeparator, 0); #endif InsertMenuItemTextWithCFString( appleMenu, - CFSTR("About..."), 0, 0, 0); + CFSTR("About..."), 0, 0, 0); MacInsertMenu( appleMenu , 0 ) ; // clean-up the help menu before adding new items @@ -738,7 +738,7 @@ void wxMenuBar::MacInstallMenuBar() { if ( mh ) AppendMenuItemTextWithCFString( mh, - CFSTR(""), kMenuItemAttrSeparator, 0,NULL); + CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { @@ -766,42 +766,42 @@ void wxMenuBar::MacInstallMenuBar() } } } - - else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) + + else if ( ( m_titles[i] == wxT("Window") || m_titles[i] == wxT("&Window") ) && GetAutoWindowMenu() ) - { + { if ( MacGetWindowMenuHMenu() == NULL ) { CreateStandardWindowMenu( 0 , (MenuHandle*) &s_macWindowMenuHandle ) ; } - + MenuRef wm = (MenuRef)MacGetWindowMenuHMenu(); if ( wm == NULL ) break; - + // get the insertion point in the standard menu MenuItemIndex winListStart; - GetIndMenuItemWithCommandID(wm, + GetIndMenuItemWithCommandID(wm, kHICommandWindowListSeparator, 1, NULL, &winListStart); - + // add a separator so that the standard items and the custom items // aren't mixed together, but only if this is the first run - OSStatus err = GetIndMenuItemWithCommandID(wm, + OSStatus err = GetIndMenuItemWithCommandID(wm, 'WXWM', 1, NULL, NULL); - + if ( err == menuItemNotFoundErr ) { InsertMenuItemTextWithCFString( wm, CFSTR(""), winListStart-1, kMenuItemAttrSeparator, 'WXWM'); } - - wxInsertMenuItemsInMenu(menu, wm, winListStart); + + wxInsertMenuItemsInMenu(menu, wm, winListStart); } else { UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ; menu->MacBeforeDisplay(false) ; - + ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0); } } @@ -876,6 +876,15 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetLabelTop") ); + return wxStripMenuCodes(m_titles[pos]); +} + +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + return m_titles[pos]; } diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 402f8b5b65..2d9c47353a 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -66,10 +66,10 @@ void wxMenuItem::UpdateItemBitmap() DoUpdateItemBitmap( mhandle, index ); } -void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) +void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) { MenuHandle mhandle = (MenuHandle) menu; - + if ( mhandle == NULL || index == 0) return ; @@ -83,7 +83,7 @@ void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( mhandle , index , kMenuIconRefType , (Handle) info.u.iconRef ) ; - else if ( info.contentType == kControlContentCGImageRef ) + else if ( info.contentType == kControlContentCGImageRef ) SetMenuItemIconHandle( mhandle , index , kMenuCGImageRefType , (Handle) info.u.imageRef ) ; } diff --git a/src/mac/classic/menu.cpp b/src/mac/classic/menu.cpp index cb384236e0..7c00903321 100644 --- a/src/mac/classic/menu.cpp +++ b/src/mac/classic/menu.cpp @@ -639,6 +639,15 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetLabelTop") ); + return wxStripMenuCodes(m_titles[pos]); +} + +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + return m_titles[pos]; } diff --git a/src/motif/menu.cpp b/src/motif/menu.cpp index abbe28a365..9643b1a868 100644 --- a/src/motif/menu.cpp +++ b/src/motif/menu.cpp @@ -234,6 +234,8 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) if ( !menu ) return; + m_titles[pos] = label; + Widget w = (Widget)menu->GetButtonWidget(); if (w) { @@ -247,6 +249,8 @@ void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) wxString wxMenuBar::GetLabelTop(size_t pos) const { + return wxStripMenuCodes(m_titles[pos]); +#if 0 wxMenu *menu = GetMenu(pos); if ( menu ) { @@ -263,8 +267,19 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const } return wxEmptyString; +#endif } +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_titles[pos]; +} + + bool wxMenuBar::Append(wxMenu * menu, const wxString& title) { return Insert(GetMenuCount(), menu, title); diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index 45650b97c5..9005fb4514 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -433,7 +433,7 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) !pItem->GetBackgroundColour().Ok() && !pItem->GetFont().Ok() ) { - // try to use InsertMenuItem() as it's guaranteed to look correct + // try to use InsertMenuItem() as it's guaranteed to look correct // while our owner-drawn code is not // first compile-time check @@ -441,7 +441,7 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) #if defined(MIIM_BITMAP) && (_WIN32_WINNT >= 0x0500) WinStruct mii; if ( wxGetWinVersion() >= wxWinVersion_98 ) - { + { mii.fMask = MIIM_STRING | MIIM_DATA | MIIM_BITMAP; if ( pItem->IsCheckable() ) { @@ -1086,6 +1086,15 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const return wxMenuItem::GetLabelFromText(m_titles[pos]); } +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_titles[pos]; +} + // --------------------------------------------------------------------------- // wxMenuBar construction // --------------------------------------------------------------------------- diff --git a/src/os2/menu.cpp b/src/os2/menu.cpp index ae8c5db5fc..6f3e895688 100644 --- a/src/os2/menu.cpp +++ b/src/os2/menu.cpp @@ -892,9 +892,19 @@ wxString wxMenuBar::GetLabelTop( { wxCHECK_MSG( nPos < GetMenuCount(), wxEmptyString, wxT("invalid menu index in wxMenuBar::GetLabelTop") ); - return m_titles[nPos]; + return wxStripMenuCodes(m_titles[nPos]); } // end of wxMenuBar::GetLabelTop +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_titles[pos]; +} + + // --------------------------------------------------------------------------- // wxMenuBar construction // --------------------------------------------------------------------------- diff --git a/src/palmos/menu.cpp b/src/palmos/menu.cpp index 7274757921..cd20a8ca2c 100644 --- a/src/palmos/menu.cpp +++ b/src/palmos/menu.cpp @@ -395,6 +395,15 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const return wxMenuItem::GetLabelFromText(m_titles[pos]); } +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_titles[pos]; +} + // --------------------------------------------------------------------------- // wxMenuBar construction // --------------------------------------------------------------------------- diff --git a/src/univ/menu.cpp b/src/univ/menu.cpp index 2d3fa88a55..0612c2fc39 100644 --- a/src/univ/menu.cpp +++ b/src/univ/menu.cpp @@ -67,6 +67,8 @@ public: void SetLabel(const wxString& text) { + m_originalLabel = text; + // remember the accel char (may be -1 if none) m_indexAccel = wxControl::FindAccelIndex(text, &m_label); @@ -79,6 +81,7 @@ public: // accessors const wxString& GetLabel() const { return m_label; } + const wxString& GetOriginalLabel() const { return m_originalLabel; } bool IsEnabled() const { return m_isEnabled; } wxCoord GetWidth(wxMenuBar *menubar) const { @@ -105,6 +108,7 @@ private: } wxString m_label; + wxString m_originalLabel; wxCoord m_width; int m_indexAccel; bool m_isEnabled; @@ -1822,9 +1826,9 @@ bool wxMenuBar::IsEnabledTop(size_t pos) const void wxMenuBar::SetLabelTop(size_t pos, const wxString& label) { - wxCHECK_RET( pos < GetCount(), _T("invalid index in EnableTop") ); + wxCHECK_RET( pos < GetCount(), _T("invalid index in SetLabelTop") ); - if ( label != m_menuInfos[pos].GetLabel() ) + if ( label != m_menuInfos[pos].GetOriginalLabel() ) { m_menuInfos[pos].SetLabel(label); @@ -1840,6 +1844,16 @@ wxString wxMenuBar::GetLabelTop(size_t pos) const return m_menuInfos[pos].GetLabel(); } +// Gets the original label at the top-level of the menubar +wxString wxMenuBar::GetMenuLabel(size_t pos) const +{ + wxCHECK_MSG( pos < GetMenuCount(), wxEmptyString, + wxT("invalid menu index in wxMenuBar::GetMenuLabel") ); + + return m_menuInfos[pos].GetOriginalLabel(); +} + + // ---------------------------------------------------------------------------- // wxMenuBar drawing // ---------------------------------------------------------------------------- diff --git a/version-script.in b/version-script.in index a2035761b1..91bf0f6ac9 100644 --- a/version-script.in +++ b/version-script.in @@ -39,6 +39,14 @@ *wxLog*DoCreateOnDemand*; *wxLogChain*DetachOldLog*; *wxMemoryFSHandler*AddFileWithMimeType*; + *wxMenuBar*GetMenuLabel*; + *wxMenuBarBase*SetMenuLabel*; + *wxMenuBarBase*GetMenuLabelText*; + *wxMenuBase*GetLabelText*; + *wxMenuItemBase*SetItemLabel*; + *wxMenuItemBase*GetItemLabelText*; + *wxMenuItemBase*GetLabelText*; + *wxMenuItem*GetItemLabel*; *wxMetafileDC*DoGetTextExtent*; *wxWindowMSW*GetThemedBorderStyle*; *wxWizard*GetBitmap*;