From: Vadim Zeitlin Date: Sat, 6 May 2006 16:59:59 +0000 (+0000) Subject: allow to specify the value for unknown ids in GetXRCID() (patch 1448981) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9b2a74693ea0ac096f5099caac4a5ead3268e07f allow to specify the value for unknown ids in GetXRCID() (patch 1448981) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39068 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/latex/wx/xmlres.tex b/docs/latex/wx/xmlres.tex index 7ef4cf75df..8d0e7b8382 100644 --- a/docs/latex/wx/xmlres.tex +++ b/docs/latex/wx/xmlres.tex @@ -121,12 +121,14 @@ Returns version information (a.b.c.d = d+ 256*c + 256\textasciicircum2*b + 256\t \membersection{wxXmlResource::GetXRCID}\label{wxxmlresourcegetxmlid} -\func{int}{GetXRCID}{\param{const wxChar* }{str\_id}} +\func{int}{GetXRCID}{\param{const wxChar* }{str\_id}, \param{int }{value\_if\_not\_found = -2}} Returns a numeric ID that is equivalent to the string ID used in an XML -resource. To be used in event tables. -The macro {\tt XRCID(name)} is provided for convenience. - +resource. If an unknown \arg{str\_id} is requested (i.e. other than wxID\_XXX +or integer), a new record is created which associates the given string with +a number. If \arg{value\_if\_not\_found} is \texttt{wxID\_NONE}, the number is obtained via +\helpref{wxNewId()}{wxnewid}. Otherwise \arg{value\_if\_not\_found} is used. +Macro {\tt XRCID(name)} is provided for convenient use in event tables. \membersection{wxXmlResource::InitAllHandlers}\label{wxxmlresourceinitallhandlers} diff --git a/include/wx/xrc/xmlres.h b/include/wx/xrc/xmlres.h index e48c0728c8..fe475b80b3 100644 --- a/include/wx/xrc/xmlres.h +++ b/include/wx/xrc/xmlres.h @@ -211,10 +211,13 @@ public: bool AttachUnknownControl(const wxString& name, wxWindow *control, wxWindow *parent = NULL); - // Returns a numeric ID that is equivalent to the string id used in an XML - // resource. To be used in event tables. - // Macro XRCID is provided for convenience - static int GetXRCID(const wxChar *str_id); + // Returns a numeric ID that is equivalent to the string ID used in an XML + // resource. If an unknown str_id is requested (i.e. other than wxID_XXX + // or integer), a new record is created which associates the given string + // with a number. If value_if_not_found == wxID_NONE, the number is obtained via + // wxNewId(). Otherwise value_if_not_found is used. + // Macro XRCID(name) is provided for convenient use in event tables. + static int GetXRCID(const wxChar *str_id, int value_if_not_found = wxID_NONE); // Returns version information (a.b.c.d = d+ 256*c + 256^2*b + 256^3*a). long GetVersion() const { return m_version; } diff --git a/src/xrc/xmlres.cpp b/src/xrc/xmlres.cpp index e8d66785f7..238bda8e31 100644 --- a/src/xrc/xmlres.cpp +++ b/src/xrc/xmlres.cpp @@ -1497,7 +1497,7 @@ struct XRCID_record static XRCID_record *XRCID_Records[XRCID_TABLE_SIZE] = {NULL}; -static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2) +static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = wxID_NONE) { int index = 0; @@ -1521,7 +1521,7 @@ static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2) (*rec_var)->next = NULL; wxChar *end; - if (value_if_not_found != -2) + if (value_if_not_found != wxID_NONE) (*rec_var)->id = value_if_not_found; else { @@ -1542,7 +1542,8 @@ static int XRCID_Lookup(const wxChar *str_id, int value_if_not_found = -2) static void AddStdXRCID_Records(); -/*static*/ int wxXmlResource::GetXRCID(const wxChar *str_id) +/*static*/ +int wxXmlResource::GetXRCID(const wxChar *str_id, int value_if_not_found) { static bool s_stdIDsAdded = false; @@ -1552,7 +1553,7 @@ static void AddStdXRCID_Records(); AddStdXRCID_Records(); } - return XRCID_Lookup(str_id); + return XRCID_Lookup(str_id, value_if_not_found); }