]> git.saurik.com Git - wxWidgets.git/commitdiff
Enhanced wxGetStockLabel() with parameters which replace platform specific #ifdefs...
authorWłodzimierz Skiba <abx@abx.art.pl>
Mon, 31 Jan 2005 17:57:35 +0000 (17:57 +0000)
committerWłodzimierz Skiba <abx@abx.art.pl>
Mon, 31 Jan 2005 17:57:35 +0000 (17:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@31673 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/function.tex
include/wx/stockitem.h
src/common/stockitem.cpp
src/msw/wince/menuce.cpp
src/palmos/button.cpp

index 4d40bb80ab44b1ebce9cef27f7835a6f7f7e1f45..6082a2867d27c5413fdcd20aa61189eb7f064a4b 100644 (file)
@@ -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}}
index 7cb4afaaa771ae90c7c0f1d7677e28d68c5d1e29..aa95845f4fc2ccbef5a790c4970b09d24e8a2e6d 100644 (file)
@@ -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:
index 5f4bc508ba557bc1b19a0bd5911fac109f8bf327..1946b288aed0355ea5eea4d0cb049604c579fe36 100644 (file)
@@ -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)
index 8ef705abcef29c0a1149dbbc84856258d45c6b6d..707bcc9af59cbd52ee4620a5744e2620738dfe8b 100644 (file)
@@ -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;
index a0d0f088a541050a526878fdc1bc12632110792b..f8ec74481c13eba54fddd0d3eb7104f65fc6574f 100644 (file)
     #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;