X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/98c4eb39105531b0316a9d8dbf87d7939e4c4270..b02dd12239c8a59b9a545d9fcb04974f8ad02c6b:/include/wx/chartype.h diff --git a/include/wx/chartype.h b/include/wx/chartype.h index c73722946a..a0c527ba26 100644 --- a/include/wx/chartype.h +++ b/include/wx/chartype.h @@ -1,7 +1,7 @@ /* * Name: wx/chartype.h * Purpose: Declarations of wxChar and related types - * Author: Joel Farley, Ove Kåven + * Author: Joel Farley, Ove KÃ¥ven * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee * Created: 1998/06/12 * RCS-ID: $Id$ @@ -38,8 +38,8 @@ #endif /* !defined(wxUSE_WCHAR_T) */ /* Unicode support requires wchar_t */ -#if wxUSE_UNICODE && !wxUSE_WCHAR_T - #error "wchar_t must be available in Unicode build" +#if !wxUSE_WCHAR_T + #error "wchar_t must be available" #endif /* Unicode */ /* @@ -59,37 +59,35 @@ #endif #endif -#if wxUSE_WCHAR_T - #ifdef HAVE_WCHAR_H - /* the current (as of Nov 2002) version of cygwin has a bug in its */ - /* wchar.h -- there is no extern "C" around the declarations in it */ - /* and this results in linking errors later; also, at least on some */ - /* Cygwin versions, wchar.h requires sys/types.h */ - #ifdef __CYGWIN__ - #include - #ifdef __cplusplus - extern "C" { - #endif - #endif /* Cygwin */ - - #include - - #if defined(__CYGWIN__) && defined(__cplusplus) - } - #endif /* Cygwin and C++ */ - - #elif defined(HAVE_WCSTR_H) - /* old compilers have relevant declarations here */ - #include - #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__) - /* include stdlib.h for wchar_t */ - #include - #endif /* HAVE_WCHAR_H */ - - #ifdef HAVE_WIDEC_H - #include - #endif -#endif /* wxUSE_WCHAR_T */ +#ifdef HAVE_WCHAR_H + /* the current (as of Nov 2002) version of cygwin has a bug in its */ + /* wchar.h -- there is no extern "C" around the declarations in it */ + /* and this results in linking errors later; also, at least on some */ + /* Cygwin versions, wchar.h requires sys/types.h */ + #ifdef __CYGWIN__ + #include + #ifdef __cplusplus + extern "C" { + #endif + #endif /* Cygwin */ + + #include + + #if defined(__CYGWIN__) && defined(__cplusplus) + } + #endif /* Cygwin and C++ */ + +#elif defined(HAVE_WCSTR_H) + /* old compilers have relevant declarations here */ + #include +#elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__) + /* include stdlib.h for wchar_t */ + #include +#endif /* HAVE_WCHAR_H */ + +#ifdef HAVE_WIDEC_H + #include +#endif /* -------------------------------------------------------------------------- */ /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */ @@ -107,8 +105,6 @@ #define wxHAVE_TCHAR_SUPPORT #elif defined(__DMC__) #define wxHAVE_TCHAR_SUPPORT -#elif defined(__WXPALMOS__) - #include #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 ) #define wxHAVE_TCHAR_SUPPORT #include @@ -145,7 +141,7 @@ typedef char wxChar; typedef signed char wxSChar; typedef unsigned char wxUChar; -#else /* Unicode */ +#else /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */ /* signed/unsigned version of it which (a) makes sense to me (unlike */ /* char wchar_t is always unsigned) and (b) was how the previous */ @@ -154,8 +150,8 @@ /* Sun's SunPro compiler supports the wchar_t type and wide character */ /* functions, but does not define __WCHAR_TYPE__. Define it here to */ /* allow unicode enabled builds. */ - #if defined(__SUNPRO_CC) || defined(__SUNPRO_C) - #define __WCHAR_TYPE__ wxchar_t + #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__) + #define __WCHAR_TYPE__ wxchar_t #endif /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */ @@ -184,7 +180,45 @@ #endif /* ASCII/Unicode */ /* ------------------------------------------------------------------------- */ -/* define _T() and related macros */ +/* define wxStringCharType */ +/* ------------------------------------------------------------------------- */ + +/* depending on the platform, Unicode build can either store wxStrings as + wchar_t* or UTF-8 encoded char*: */ +#if wxUSE_UNICODE + /* FIXME-UTF8: what would be better place for this? */ + #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8) + #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8" + #endif + #ifndef wxUSE_UTF8_LOCALE_ONLY + #define wxUSE_UTF8_LOCALE_ONLY 0 + #endif + + #ifndef wxUSE_UNICODE_UTF8 + #define wxUSE_UNICODE_UTF8 0 + #endif + + #if wxUSE_UNICODE_UTF8 + #define wxUSE_UNICODE_WCHAR 0 + #else + #define wxUSE_UNICODE_WCHAR 1 + #endif +#else + #define wxUSE_UNICODE_WCHAR 0 + #define wxUSE_UNICODE_UTF8 0 + #define wxUSE_UTF8_LOCALE_ONLY 0 +#endif + +/* define char type used by wxString internal representation: */ +#if wxUSE_UNICODE_WCHAR + typedef wchar_t wxStringCharType; +#else /* wxUSE_UNICODE_UTF8 || ANSI */ + typedef char wxStringCharType; +#endif + + +/* ------------------------------------------------------------------------- */ +/* define wxT() and related macros */ /* ------------------------------------------------------------------------- */ /* BSD systems define _T() to be something different in ctype.h, override it */ @@ -193,23 +227,71 @@ #undef _T #endif -/* could already be defined by tchar.h (it's quasi standard) */ -#ifndef _T +/* + wxT ("wx text") macro turns a literal string constant into a wide char + constant. It is mostly unnecessary with wx 2.9 but defined for + compatibility. + */ +#ifndef wxT #if !wxUSE_UNICODE - #define _T(x) x + #define wxT(x) x #else /* Unicode */ - /* use wxCONCAT_HELPER so that x could be expanded if it's a macro */ - #define _T(x) wxCONCAT_HELPER(L, x) + /* + Notice that we use an intermediate macro to allow x to be expanded + if it's a macro itself. + */ + #ifndef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxT(x) wxCONCAT_HELPER(L, x) + #else + #define wxT(x) wxPREPEND_L(x) + #endif #endif /* ASCII/Unicode */ -#endif /* !defined(_T) */ +#endif /* !defined(wxT) */ -/* although global macros with such names are normally bad, we want to have */ -/* another name for _T() which should be used to avoid confusion between */ -/* _T() and _() in wxWidgets sources */ -#define wxT(x) _T(x) +/* + 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 + under Windows or char in UTF-8-based Unicode builds and (deprecated) ANSI + builds everywhere (see wxStringCharType definition above). + */ +#if wxUSE_UNICODE_WCHAR + /* + As above with wxT(), wxS() argument is expanded if it's a macro. + */ + #ifndef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxS(x) wxCONCAT_HELPER(L, x) + #else + #define wxS(x) wxPREPEND_L(x) + #endif +#else /* wxUSE_UNICODE_UTF8 || ANSI */ + #define wxS(x) x +#endif + +/* + _T() is a synonym for wxT() familiar to Windows programmers. As this macro + has even higher risk of conflicting with system headers, its use is + discouraged and you may predefine wxNO__T to disable it. Additionally, we + do it ourselves for Sun CC which is known to use it in its standard headers + (see #10660). + */ +#if defined(__SUNPRO_C) || defined(__SUNPRO_CC) + #ifndef wxNO__T + #define wxNO__T + #endif +#endif + +#if !defined(_T) && !defined(wxNO__T) + #define _T(x) wxT(x) +#endif /* a helper macro allowing to make another macro Unicode-friendly, see below */ -#define wxAPPLY_T(x) _T(x) +#define wxAPPLY_T(x) wxT(x) /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */ #ifndef __TFILE__