From 634629fa2847aa34c60f4fb20377b3a14f59bfc7 Mon Sep 17 00:00:00 2001
From: =?utf8?q?W=C5=82odzimierz=20Skiba?= <abx@abx.art.pl>
Date: Mon, 31 Jan 2005 17:57:35 +0000
Subject: [PATCH] Enhanced wxGetStockLabel() with parameters which replace
 platform specific #ifdefs for wxPalmOS and wxWinCE and better serve for
 getting consistent wxMenuItem and wxToolBar labels (with documentation).

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
---
 docs/latex/wx/function.tex | 22 ++++++++++++++++++++++
 include/wx/stockitem.h     |  5 ++++-
 src/common/stockitem.cpp   | 25 ++++++++++++++++---------
 src/msw/wince/menuce.cpp   |  2 +-
 src/palmos/button.cpp      |  5 +++--
 5 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/docs/latex/wx/function.tex b/docs/latex/wx/function.tex
index 4d40bb80ab..6082a2867d 100644
--- a/docs/latex/wx/function.tex
+++ b/docs/latex/wx/function.tex
@@ -2911,6 +2911,28 @@ See also \helpref{wxWriteResource}{wxwriteresource}, \helpref{wxConfigBase}{wxco
 <wx/utils.h>
 
 
+\membersection{::wxGetStockLabel}\label{wxgetstocklabel}
+
+\func{wxString}{wxGetStockLabel}{\param{wxWindowID }{id}, \param{bool }{withCodes = true}, \param{wxString }{accelerator = wxEmptyString}}
+
+Returns label that should be used for given {\it id} element.
+
+\wxheading{Parameters}
+
+\docparam{id}{given id of the \helpref{wxMenuItem}{wxmenuitem}, \helpref{wxButton}{wxbutton}, \helpref{wxToolBar}{wxtoolbar} tool, etc.}
+
+\docparam{withCodes}{if false then strip accelerator code from the label;
+usefull for getting labels without accelerator char code like for toolbar tooltip or
+under platforms without traditional keyboard like smartphones}
+
+\docparam{accelerator}{optional accelerator string automatically added to label; useful
+for building labels for \helpref{wxMenuItem}{wxmenuitem}}
+
+\wxheading{Include files}
+
+<wx/stockitem.h>
+
+
 \membersection{::wxGetTopLevelParent}\label{wxgettoplevelparent}
 
 \func{wxWindow *}{wxGetTopLevelParent}{\param{wxWindow }{*win}}
diff --git a/include/wx/stockitem.h b/include/wx/stockitem.h
index 7cb4afaaa7..aa95845f4f 100644
--- a/include/wx/stockitem.h
+++ b/include/wx/stockitem.h
@@ -17,6 +17,7 @@
 #endif
 
 #include "wx/defs.h"
+#include "wx/wxchar.h"
 #include "wx/string.h"
 
 // ----------------------------------------------------------------------------
@@ -32,7 +33,9 @@ WXDLLEXPORT bool wxIsStockLabel(wxWindowID id, const wxString& label);
 
 // Returns label that should be used for given stock UI element (e.g. "&OK"
 // for wxSTOCK_OK):
-WXDLLEXPORT wxString wxGetStockLabel(wxWindowID id);
+WXDLLEXPORT wxString wxGetStockLabel(wxWindowID id,
+                                     bool withCodes = true,
+                                     wxString accelerator = wxEmptyString);
 
 #ifdef __WXGTK20__
 // Translates stock ID to GTK+'s stock item string indentifier:
diff --git a/src/common/stockitem.cpp b/src/common/stockitem.cpp
index 5f4bc508ba..1946b288ae 100644
--- a/src/common/stockitem.cpp
+++ b/src/common/stockitem.cpp
@@ -93,17 +93,14 @@ bool wxIsStockID(wxWindowID id)
     };
 }
 
-wxString wxGetStockLabel(wxWindowID id)
+wxString wxGetStockLabel(wxWindowID id, bool withCodes, wxString accelerator)
 {
-#if defined(__SMARTPHONE__) || defined(__WXPALMOS__)
-    #define STOCKITEM(stockid, label) \
-        case stockid:                 \
-            return wxStripMenuCodes(label);
-#else
+    wxString stockLabel;
+
     #define STOCKITEM(stockid, label) \
         case stockid:                 \
-            return label;
-#endif
+            stockLabel = label;       \
+            break;
 
     switch (id)
     {
@@ -165,7 +162,17 @@ wxString wxGetStockLabel(wxWindowID id)
 
     #undef STOCKITEM
 
-    return wxEmptyString;
+    if(!withCodes)
+    {
+        stockLabel = wxStripMenuCodes( stockLabel );
+    }
+    else if (!stockLabel.empty() && !accelerator.empty())
+    {
+        stockLabel += _T("\t");
+        stockLabel += accelerator;
+    }
+
+    return stockLabel;
 }
 
 bool wxIsStockLabel(wxWindowID id, const wxString& label)
diff --git a/src/msw/wince/menuce.cpp b/src/msw/wince/menuce.cpp
index 8ef705abce..707bcc9af5 100644
--- a/src/msw/wince/menuce.cpp
+++ b/src/msw/wince/menuce.cpp
@@ -84,7 +84,7 @@ void wxTopLevelWindowMSW::ButtonMenu::SetButton(int id, const wxString& label, w
     m_assigned = true;
     m_id = id;
     if(label.empty() && wxIsStockID(id))
-        m_label = wxGetStockLabel(id);
+        m_label = wxGetStockLabel(id, false);
     else
         m_label = label;
     m_menu = subMenu;
diff --git a/src/palmos/button.cpp b/src/palmos/button.cpp
index a0d0f088a5..f8ec74481c 100644
--- a/src/palmos/button.cpp
+++ b/src/palmos/button.cpp
@@ -40,9 +40,10 @@
     #include "wx/dcscreen.h"
     #include "wx/frame.h"
     #include "wx/dialog.h"
-    #include "wx/stockitem.h"
 #endif
 
+#include "wx/stockitem.h"
+
 // ----------------------------------------------------------------------------
 // macros
 // ----------------------------------------------------------------------------
@@ -168,7 +169,7 @@ bool wxButton::Create(wxWindow *parent,
     // take the stock label
     wxString palmLabel = label;
     if( palmLabel.empty() && wxIsStockID(id) )
-        palmLabel = wxGetStockLabel(id);
+        palmLabel = wxGetStockLabel(id, false);
 
     if(!wxControl::Create(parent, id, palmPos, palmSize, style, validator, name))
         return false;
-- 
2.50.0

