From 3b59cdbfaf7df79499424c92ff6177736429ff8a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Jan 2000 13:58:41 +0000 Subject: [PATCH] wxMenuItem::GetLabelFromText() added/documented, bug in wxMenu::FindItem() fixed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5339 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/menuitem.tex | 24 ++++++++++++++++++++++-- include/wx/app.h | 6 +----- include/wx/gtk/menuitem.h | 1 - include/wx/gtk1/menuitem.h | 1 - include/wx/menuitem.h | 11 ++++++----- include/wx/motif/menuitem.h | 3 +-- include/wx/msw/menuitem.h | 1 - src/common/menucmn.cpp | 2 +- src/gtk/menu.cpp | 7 ++++--- src/gtk1/menu.cpp | 7 ++++--- src/motif/menuitem.cpp | 4 ++-- src/msw/menuitem.cpp | 3 ++- 12 files changed, 43 insertions(+), 27 deletions(-) diff --git a/docs/latex/wx/menuitem.tex b/docs/latex/wx/menuitem.tex index 0d46f86854..f224111716 100644 --- a/docs/latex/wx/menuitem.tex +++ b/docs/latex/wx/menuitem.tex @@ -104,7 +104,26 @@ characaters it might contain. \wxheading{See also} -\helpref{GetText}{wxmenuitemgettext} +\helpref{GetText}{wxmenuitemgettext}, +\helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext} + +\membersection{wxMenuItem::GetLabelFromText}\label{wxmenuitemgetlabelfromtext} + +\func{static wxString}{GetLabelFromText}{\param{const wxString\& }{text}} + +Strips all accelerator characeters 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{GetText}{wxmenuitemgettext}, +\helpref{GetLabel}{wxmenuitemgetlabel} \membersection{wxMenuItem::GetMarginWidth}\label{wxmenuitemgetmarginwidth} @@ -131,7 +150,8 @@ wxMenuItem constructor, i.e. with any accelerator characters it may contain. \wxheading{See also} -\helpref{GetLabel}{wxmenuitemgetlabel} +\helpref{GetLabel}{wxmenuitemgetlabel}, +\helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext} \membersection{wxMenuItem::GetSubMenu}\label{wxmenuitemgetsubmenu} diff --git a/include/wx/app.h b/include/wx/app.h index 559fdebc4f..7d408278bb 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -369,11 +369,7 @@ public: #elif defined(__WXMSW__) && defined(WXUSINGDLL) // NT defines APIENTRY, 3.x not #if !defined(WXAPIENTRY) - #ifdef __WATCOMC__ - #define WXAPIENTRY PASCAL - #else - #define WXAPIENTRY FAR PASCAL - #endif + #define WXAPIENTRY FAR wxSTDCALL #endif #define IMPLEMENT_WXWIN_MAIN \ diff --git a/include/wx/gtk/menuitem.h b/include/wx/gtk/menuitem.h index ba846a4b9c..54d91d04f1 100644 --- a/include/wx/gtk/menuitem.h +++ b/include/wx/gtk/menuitem.h @@ -31,7 +31,6 @@ public: // implement base class virtuals virtual void SetText( const wxString& str ); - virtual wxString GetLabel() const; virtual void Enable( bool enable = TRUE ); virtual void Check( bool check = TRUE ); virtual bool IsChecked() const; diff --git a/include/wx/gtk1/menuitem.h b/include/wx/gtk1/menuitem.h index ba846a4b9c..54d91d04f1 100644 --- a/include/wx/gtk1/menuitem.h +++ b/include/wx/gtk1/menuitem.h @@ -31,7 +31,6 @@ public: // implement base class virtuals virtual void SetText( const wxString& str ); - virtual wxString GetLabel() const; virtual void Enable( bool enable = TRUE ); virtual void Check( bool check = TRUE ); virtual bool IsChecked() const; diff --git a/include/wx/menuitem.h b/include/wx/menuitem.h index b804976522..20f143ed22 100644 --- a/include/wx/menuitem.h +++ b/include/wx/menuitem.h @@ -34,7 +34,6 @@ class WXDLLEXPORT wxMenu; class WXDLLEXPORT wxMenuItemBase : public wxObject { public: - // creation static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, int id = wxID_SEPARATOR, @@ -61,9 +60,12 @@ public: // different from the item's label which only contains the text shown // in the menu virtual void SetText(const wxString& str) { m_text = str; } - virtual wxString GetLabel() const { return m_text; } + wxString GetLabel() const { return GetLabelFromText(m_text); } const wxString& GetText() const { return m_text; } + // get the label from text (implemented in platform-specific code) + static wxString GetLabelFromText(const wxString& text); + // what kind of menu item we are virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; } bool IsCheckable() const { return m_isCheckable; } @@ -107,9 +109,8 @@ protected: bool m_isChecked; // is checked? bool m_isEnabled; // is enabled? - // some compilers need a default constructor here, do not use - wxMenuItemBase() - { } + // some compilers need a default constructor here, do not remove + wxMenuItemBase() { } }; // ---------------------------------------------------------------------------- diff --git a/include/wx/motif/menuitem.h b/include/wx/motif/menuitem.h index 4822d8013c..d2c865aa66 100644 --- a/include/wx/motif/menuitem.h +++ b/include/wx/motif/menuitem.h @@ -2,7 +2,7 @@ // Name: menuitem.h // Purpose: wxMenuItem class // Author: Vadim Zeitlin -// Modified by: +// Modified by: // Created: 11.11.97 // RCS-ID: $Id$ // Copyright: (c) 1998 Vadim Zeitlin @@ -36,7 +36,6 @@ public: // accessors (some more are inherited from wxOwnerDrawn or are below) virtual void SetText(const wxString& label); - virtual wxString GetLabel() const; virtual void Enable(bool enable = TRUE); virtual void Check(bool check = TRUE); diff --git a/include/wx/msw/menuitem.h b/include/wx/msw/menuitem.h index df414512df..1be7c53921 100644 --- a/include/wx/msw/menuitem.h +++ b/include/wx/msw/menuitem.h @@ -45,7 +45,6 @@ public: // override base class virtuals virtual void SetText(const wxString& strName); - virtual wxString GetLabel() const; virtual void SetCheckable(bool checkable); virtual void Enable(bool bDoEnable = TRUE); diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 74818ae0a9..9f16ca8512 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -252,7 +252,7 @@ bool wxMenuBase::DoDestroy(wxMenuItem *item) // Finds the item id matching the given string, -1 if not found. int wxMenuBase::FindItem(const wxString& text) const { - wxString label = wxMenuItem(NULL, wxID_SEPARATOR, text).GetLabel(); + wxString label = wxMenuItem::GetLabelFromText(text); for ( wxMenuItemList::Node *node = m_items.GetFirst(); node; node = node->GetNext() ) diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index 47ac10d93f..daff7c92be 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -625,11 +625,12 @@ wxMenuItem::~wxMenuItem() } // return the menu item text without any menu accels -wxString wxMenuItem::GetLabel() const +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { wxString label; #if (GTK_MINOR_VERSION > 0) - for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) + for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { if ( *pc == wxT('_') ) { @@ -640,7 +641,7 @@ wxString wxMenuItem::GetLabel() const label += *pc; } #else // GTK+ 1.0 - label = m_text; + label = text; #endif // GTK+ 1.2/1.0 return label; diff --git a/src/gtk1/menu.cpp b/src/gtk1/menu.cpp index 47ac10d93f..daff7c92be 100644 --- a/src/gtk1/menu.cpp +++ b/src/gtk1/menu.cpp @@ -625,11 +625,12 @@ wxMenuItem::~wxMenuItem() } // return the menu item text without any menu accels -wxString wxMenuItem::GetLabel() const +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { wxString label; #if (GTK_MINOR_VERSION > 0) - for ( const wxChar *pc = m_text.c_str(); *pc; pc++ ) + for ( const wxChar *pc = text.c_str(); *pc; pc++ ) { if ( *pc == wxT('_') ) { @@ -640,7 +641,7 @@ wxString wxMenuItem::GetLabel() const label += *pc; } #else // GTK+ 1.0 - label = m_text; + label = text; #endif // GTK+ 1.2/1.0 return label; diff --git a/src/motif/menuitem.cpp b/src/motif/menuitem.cpp index deaad78a6f..e07a652c58 100644 --- a/src/motif/menuitem.cpp +++ b/src/motif/menuitem.cpp @@ -154,12 +154,12 @@ void wxMenuItem::Check(bool bDoCheck) } } -wxString wxMenuItem::GetLabel() const +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { return wxStripMenuCodes(m_text); } - // ---------------------------------------------------------------------------- // wxMenuItemBase // ---------------------------------------------------------------------------- diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 9b6dbe9b52..1c0fa7137a 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -141,7 +141,8 @@ bool wxMenuItem::IsChecked() const return (flag & MF_CHECKED) != 0; } -wxString wxMenuItem::GetLabel() const +/* static */ +wxString wxMenuItemBase::GetLabelFromText(const wxString& text) { return wxStripMenuCodes(m_text); }