From: Vadim Zeitlin Date: Sat, 19 Feb 2011 13:44:19 +0000 (+0000) Subject: Add wxT_2() macro for compatibility with wxWidgets 2 API. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/9204fde6ee1673146131e808b7f15e6689a0ef10 Add wxT_2() macro for compatibility with wxWidgets 2 API. This macro can be used to make the same code compile with both v2 and v3 as it expands to wxT() in 2.8 and nothing in later versions. See #12925. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66968 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/docs/changes.txt b/docs/changes.txt index d1769863ed..22af6ab4bf 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -46,7 +46,9 @@ changes: - Some structure fields which used to be of type "const wxChar *" (such as wxCmdLineEntryDesc::shortName, longName and description fields) are now of type "const char *", you need to remove wxT() or _T() around the values used - to initialize them (which should normally always be ASCII). + to initialize them (which should normally always be ASCII). If you want your + code to remain compatible with Unicode build of previous wx version, please + use the special wxT_2, which is the same as wxT in 2.x only, instead. - wxIPC classes didn't work correctly in Unicode build before, this was fixed but at a price of breaking backwards compatibility: many methods which used diff --git a/include/wx/chartype.h b/include/wx/chartype.h index c0658eaf97..3c3944a360 100644 --- a/include/wx/chartype.h +++ b/include/wx/chartype.h @@ -250,6 +250,12 @@ #endif /* ASCII/Unicode */ #endif /* !defined(wxT) */ +/* + wxT_2 exists only for compatibility with wx 2.x and is the same as wxT() in + that version but nothing in the newer ones. + */ +#define wxT_2(x) x + /* wxS ("wx string") macro can be used to create literals using the same representation as wxString does internally, i.e. wchar_t in Unicode build diff --git a/interface/wx/chartype.h b/interface/wx/chartype.h index cf7e724e38..7678cec9c8 100644 --- a/interface/wx/chartype.h +++ b/interface/wx/chartype.h @@ -32,6 +32,32 @@ */ #define wxT(string) +/** + Compatibility macro which expands to wxT() in wxWidgets 2 only. + + This macro can be used in the code which needs to compile with both + wxWidgets 2 and 3 versions in places where v2 API requires a Unicode string + (in Unicode build) and v3 API only accepts a standard standard narrow + string as in e.g. wxCmdLineEntryDesc structure objects initializers. + + Example of use: + @code + const wxCmdLineEntryDesc cmdLineDesc[] = + { + { wxCMD_LINE_SWITCH, wxT_2("q"), wxT_2("quiet"), + wxT_2("Don't output verbose messages") }, + wxCMD_LINE_DESC_END + }; + @endcode + + Without @c wxT_2 the code above wouldn't compile with wxWidgets 2, with @c + wxT instead of it, it wouldn't compile with wxWidgets 3. + + @see wxT() + + @header{wx/chartype.h} + */ + /** wxS is macro which can be used with character and string literals (in other words, @c 'x' or @c "foo") to either convert them to wide characters or wide strings