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
This commit is contained in:
Vadim Zeitlin 2000-01-11 13:58:41 +00:00
parent ba2d860554
commit 3b59cdbfaf
12 changed files with 43 additions and 27 deletions

View File

@ -104,7 +104,26 @@ characaters it might contain.
\wxheading{See also} \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} \membersection{wxMenuItem::GetMarginWidth}\label{wxmenuitemgetmarginwidth}
@ -131,7 +150,8 @@ wxMenuItem constructor, i.e. with any accelerator characters it may contain.
\wxheading{See also} \wxheading{See also}
\helpref{GetLabel}{wxmenuitemgetlabel} \helpref{GetLabel}{wxmenuitemgetlabel},
\helpref{GetLabelFromText}{wxmenuitemgetlabelfromtext}
\membersection{wxMenuItem::GetSubMenu}\label{wxmenuitemgetsubmenu} \membersection{wxMenuItem::GetSubMenu}\label{wxmenuitemgetsubmenu}

View File

@ -369,11 +369,7 @@ public:
#elif defined(__WXMSW__) && defined(WXUSINGDLL) #elif defined(__WXMSW__) && defined(WXUSINGDLL)
// NT defines APIENTRY, 3.x not // NT defines APIENTRY, 3.x not
#if !defined(WXAPIENTRY) #if !defined(WXAPIENTRY)
#ifdef __WATCOMC__ #define WXAPIENTRY FAR wxSTDCALL
#define WXAPIENTRY PASCAL
#else
#define WXAPIENTRY FAR PASCAL
#endif
#endif #endif
#define IMPLEMENT_WXWIN_MAIN \ #define IMPLEMENT_WXWIN_MAIN \

View File

@ -31,7 +31,6 @@ public:
// implement base class virtuals // implement base class virtuals
virtual void SetText( const wxString& str ); virtual void SetText( const wxString& str );
virtual wxString GetLabel() const;
virtual void Enable( bool enable = TRUE ); virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE ); virtual void Check( bool check = TRUE );
virtual bool IsChecked() const; virtual bool IsChecked() const;

View File

@ -31,7 +31,6 @@ public:
// implement base class virtuals // implement base class virtuals
virtual void SetText( const wxString& str ); virtual void SetText( const wxString& str );
virtual wxString GetLabel() const;
virtual void Enable( bool enable = TRUE ); virtual void Enable( bool enable = TRUE );
virtual void Check( bool check = TRUE ); virtual void Check( bool check = TRUE );
virtual bool IsChecked() const; virtual bool IsChecked() const;

View File

@ -34,7 +34,6 @@ class WXDLLEXPORT wxMenu;
class WXDLLEXPORT wxMenuItemBase : public wxObject class WXDLLEXPORT wxMenuItemBase : public wxObject
{ {
public: public:
// creation // creation
static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL, static wxMenuItem *New(wxMenu *parentMenu = (wxMenu *)NULL,
int id = wxID_SEPARATOR, int id = wxID_SEPARATOR,
@ -61,9 +60,12 @@ public:
// different from the item's label which only contains the text shown // different from the item's label which only contains the text shown
// in the menu // in the menu
virtual void SetText(const wxString& str) { m_text = str; } 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; } 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 // what kind of menu item we are
virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; } virtual void SetCheckable(bool checkable) { m_isCheckable = checkable; }
bool IsCheckable() const { return m_isCheckable; } bool IsCheckable() const { return m_isCheckable; }
@ -107,9 +109,8 @@ protected:
bool m_isChecked; // is checked? bool m_isChecked; // is checked?
bool m_isEnabled; // is enabled? bool m_isEnabled; // is enabled?
// some compilers need a default constructor here, do not use // some compilers need a default constructor here, do not remove
wxMenuItemBase() wxMenuItemBase() { }
{ }
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -2,7 +2,7 @@
// Name: menuitem.h // Name: menuitem.h
// Purpose: wxMenuItem class // Purpose: wxMenuItem class
// Author: Vadim Zeitlin // Author: Vadim Zeitlin
// Modified by: // Modified by:
// Created: 11.11.97 // Created: 11.11.97
// RCS-ID: $Id$ // RCS-ID: $Id$
// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
@ -36,7 +36,6 @@ public:
// accessors (some more are inherited from wxOwnerDrawn or are below) // accessors (some more are inherited from wxOwnerDrawn or are below)
virtual void SetText(const wxString& label); virtual void SetText(const wxString& label);
virtual wxString GetLabel() const;
virtual void Enable(bool enable = TRUE); virtual void Enable(bool enable = TRUE);
virtual void Check(bool check = TRUE); virtual void Check(bool check = TRUE);

View File

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

View File

@ -252,7 +252,7 @@ bool wxMenuBase::DoDestroy(wxMenuItem *item)
// Finds the item id matching the given string, -1 if not found. // Finds the item id matching the given string, -1 if not found.
int wxMenuBase::FindItem(const wxString& text) const 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(); for ( wxMenuItemList::Node *node = m_items.GetFirst();
node; node;
node = node->GetNext() ) node = node->GetNext() )

View File

@ -625,11 +625,12 @@ wxMenuItem::~wxMenuItem()
} }
// return the menu item text without any menu accels // return the menu item text without any menu accels
wxString wxMenuItem::GetLabel() const /* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{ {
wxString label; wxString label;
#if (GTK_MINOR_VERSION > 0) #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('_') ) if ( *pc == wxT('_') )
{ {
@ -640,7 +641,7 @@ wxString wxMenuItem::GetLabel() const
label += *pc; label += *pc;
} }
#else // GTK+ 1.0 #else // GTK+ 1.0
label = m_text; label = text;
#endif // GTK+ 1.2/1.0 #endif // GTK+ 1.2/1.0
return label; return label;

View File

@ -625,11 +625,12 @@ wxMenuItem::~wxMenuItem()
} }
// return the menu item text without any menu accels // return the menu item text without any menu accels
wxString wxMenuItem::GetLabel() const /* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{ {
wxString label; wxString label;
#if (GTK_MINOR_VERSION > 0) #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('_') ) if ( *pc == wxT('_') )
{ {
@ -640,7 +641,7 @@ wxString wxMenuItem::GetLabel() const
label += *pc; label += *pc;
} }
#else // GTK+ 1.0 #else // GTK+ 1.0
label = m_text; label = text;
#endif // GTK+ 1.2/1.0 #endif // GTK+ 1.2/1.0
return label; return label;

View File

@ -154,12 +154,12 @@ void wxMenuItem::Check(bool bDoCheck)
} }
} }
wxString wxMenuItem::GetLabel() const /* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{ {
return wxStripMenuCodes(m_text); return wxStripMenuCodes(m_text);
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxMenuItemBase // wxMenuItemBase
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -141,7 +141,8 @@ bool wxMenuItem::IsChecked() const
return (flag & MF_CHECKED) != 0; return (flag & MF_CHECKED) != 0;
} }
wxString wxMenuItem::GetLabel() const /* static */
wxString wxMenuItemBase::GetLabelFromText(const wxString& text)
{ {
return wxStripMenuCodes(m_text); return wxStripMenuCodes(m_text);
} }