]> git.saurik.com Git - wxWidgets.git/commitdiff
added possibility to strip only mnemonics, not accels, in wxStripMenuCodes(); added...
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 Jul 2006 18:40:04 +0000 (18:40 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 25 Jul 2006 18:40:04 +0000 (18:40 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40329 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/control.tex
docs/latex/wx/function.tex
include/wx/control.h
include/wx/utils.h
src/common/ctrlcmn.cpp
src/common/utilscmn.cpp

index 317ab1f7e65593d41591a97c484a5781a43fadbd..eade0d1ddd3289a14eabb6c9a219efef240b3507 100644 (file)
@@ -31,12 +31,23 @@ Simulates the effect of the user issuing a command to the item. See \helpref{wxC
 
 \membersection{wxControl::GetLabel}\label{wxcontrolgetlabel}
 
-\func{wxString\&}{GetLabel}{\void}
+\constfunc{const wxString\&}{GetLabel}{\void}
 
 Returns the control's text.
 
 Note that the returned string contains the mnemonics (\texttt{\&} characters) if
-any.
+any, use \helpref{wxControl::GetLabelText}{wxcontrolgetlabeltext} if they are
+undesired.
+
+
+\membersection{wxControl::GetLabelText}\label{wxcontrolgetlabeltext}
+
+\constfunc{const wxString\&}{GetLabelText}{\void}
+
+\func{static const wxString\&}{GetLabelText}{\param{const wxString\& }{label}}
+
+Returns the control's label or the given \arg{label} string for the static
+version without the mnemonics characters.
 
 
 \membersection{wxControl::SetLabel}\label{wxcontrolsetlabel}
index 74b7136158eefe052c40059d594b2e39b8411c98..4a8f89a7a137bd92c84f91e6f9f21a837a4636d7 100644 (file)
@@ -3222,18 +3222,20 @@ See also \helpref{wxGetDisplayName}{wxgetdisplayname}.
 
 \membersection{::wxStripMenuCodes}\label{wxstripmenucodes}
 
-\func{wxString}{wxStripMenuCodes}{\param{const wxString\& }{in}}
+\func{wxString}{wxStripMenuCodes}{\param{const wxString\& }{str}, \param{int }{flags = wxStrip\_All}}
 
-\func{void}{wxStripMenuCodes}{\param{char *}{in}, \param{char *}{out}}
+Strips any menu codes from \arg{str} and returns the result.
 
-{\bf NB:} This function is obsolete, please use
-\helpref{wxMenuItem::GetLabelFromText}{wxmenuitemgetlabelfromtext} instead.
-
-Strips any menu codes from {\it in} and places the result
-in {\it out} (or returns the new string, in the first form).
+By default, the functions strips both the mnemonics character (\texttt{'\&'})
+which is used to indicate a keyboard shortkey, and the accelerators, which are
+used only in the menu items and are separated from the main text by the
+\texttt{$\backslash$t} (TAB) character. By using \arg{flags} of
+\texttt{wxStrip\_Mnemonics} or \texttt{wxStrip\_Accel} to strip only the former
+or the latter part, respectively.
 
-Menu codes include \& (mark the next character with an underline
-as a keyboard shortkey in Windows and Motif) and $\backslash$t (tab in Windows).
+Notice that in most cases 
+\helpref{wxMenuItem::GetLabelFromText}{wxmenuitemgetlabelfromtext} or 
+\helpref{wxControl::GetLabelText}{wxcontrolgetlabeltext} can be used instead.
 
 \wxheading{Include files}
 
index 1432d67e5cf14169993ddac808546f18b19bac71..aed113f80304f5032dd4e4d1c3bbe4ecca845022 100644 (file)
@@ -46,6 +46,11 @@ public:
     // get the control alignment (left/right/centre, top/bottom/centre)
     int GetAlignment() const { return m_windowStyle & wxALIGN_MASK; }
 
+    // get the string without mnemonic characters ('&')
+    static wxString GetLabelText(const wxString& label);
+
+    // get just the text of the label, without mnemonic characters ('&')
+    wxString GetLabelText() const { return GetLabelText(GetLabel()); }
 
     // controls by default inherit the colours of their parents, if a
     // particular control class doesn't want to do it, it can override
index 1141a3004e16f6aa1fdbc0e14e20912793b49390..237793b05d91610f38f9774c8fa783ce80008a18 100644 (file)
@@ -532,8 +532,29 @@ WXDLLIMPEXP_BASE bool wxGetDiskSpace(const wxString& path,
 // Menu accelerators related things
 // ----------------------------------------------------------------------------
 
-WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = (wxChar *) NULL);
-WXDLLEXPORT wxString wxStripMenuCodes(const wxString& str);
+// flags for wxStripMenuCodes
+enum
+{
+    // strip '&' characters
+    wxStrip_Mnemonics = 1,
+
+    // strip everything after '\t'
+    wxStrip_Accel = 2,
+
+    // strip everything (this is the default)
+    wxStrip_All = wxStrip_Mnemonics | wxStrip_Accel
+};
+
+// strip mnemonics and/or accelerators from the label
+WXDLLEXPORT wxString
+wxStripMenuCodes(const wxString& str, int flags = wxStrip_All);
+
+// obsolete and deprecated version, do not use
+#if WXWIN_COMPATIBILITY_2_6
+wxDEPRECATED(
+    WXDLLEXPORT wxChar* wxStripMenuCodes(const wxChar *in, wxChar *out = NULL)
+);
+#endif
 
 #if wxUSE_ACCEL
 class WXDLLEXPORT wxAcceleratorEntry;
index 46532a9cda5ef460ac42a556655f9c0c8ec5751d..2bb9ab4520052522d7c1afc91d185da90d507412 100644 (file)
@@ -33,6 +33,7 @@
     #include "wx/radiobut.h"
     #include "wx/statbmp.h"
     #include "wx/bitmap.h"
+    #include "wx/utils.h"       // for wxStripMenuCodes()
 #endif
 
 const wxChar wxControlNameStr[] = wxT("control");
@@ -85,6 +86,13 @@ bool wxControlBase::CreateControl(wxWindowBase *parent,
     return true;
 }
 
+/* static */
+wxString wxControlBase::GetLabelText(const wxString& label)
+{
+    // we don't want strip the TABs here, just the mnemonics
+    return wxStripMenuCodes(label, wxStrip_Mnemonics);
+}
+
 void wxControlBase::Command(wxCommandEvent& event)
 {
     (void)GetEventHandler()->ProcessEvent(event);
index eadd15283b657e9b1260cf8e96d2971780611419..303e31881fb976462a922ccb4820b30d8c9febfe 100644 (file)
@@ -941,8 +941,10 @@ wxChar *wxStripMenuCodes(const wxChar *in, wxChar *out)
     return out;
 }
 
-wxString wxStripMenuCodes(const wxString& in)
+wxString wxStripMenuCodes(const wxString& in, int flags)
 {
+    wxASSERT_MSG( flags, _T("this is useless to call without any flags") );
+
     wxString out;
 
     size_t len = in.length();
@@ -951,7 +953,7 @@ wxString wxStripMenuCodes(const wxString& in)
     for ( size_t n = 0; n < len; n++ )
     {
         wxChar ch = in[n];
-        if ( ch == _T('&') )
+        if ( (flags & wxStrip_Mnemonics) && ch == _T('&') )
         {
             // skip it, it is used to introduce the accel char (or to quote
             // itself in which case it should still be skipped): note that it
@@ -966,7 +968,7 @@ wxString wxStripMenuCodes(const wxString& in)
                 ch = in[n];
             }
         }
-        else if ( ch == _T('\t') )
+        else if ( (flags & wxStrip_Accel) && ch == _T('\t') )
         {
             // everything after TAB is accel string, exit the loop
             break;