]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/chartype.h
3 * Purpose: Declarations of wxChar and related types
4 * Author: Joel Farley, Ove Kåven
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
14 #ifndef _WX_WXCHARTYPE_H_
15 #define _WX_WXCHARTYPE_H_
17 /* defs.h indirectly includes this file, so don't include it here */
18 #include "wx/platform.h"
20 /* check whether we have wchar_t and which size it is if we do */
21 #if !defined(wxUSE_WCHAR_T)
23 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
24 #define wxUSE_WCHAR_T 1
26 #define wxUSE_WCHAR_T 0
28 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
29 #define wxUSE_WCHAR_T 0
30 #elif defined(__WATCOMC__)
31 #define wxUSE_WCHAR_T 0
32 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
33 #define wxUSE_WCHAR_T 0
35 /* add additional compiler checks if this fails */
36 #define wxUSE_WCHAR_T 1
38 #endif /* !defined(wxUSE_WCHAR_T) */
40 /* Unicode support requires wchar_t */
42 #error "wchar_t must be available"
46 non Unix compilers which do have wchar.h (but not tchar.h which is included
47 below and which includes wchar.h anyhow).
49 Actually MinGW has tchar.h, but it does not include wchar.h
51 #if defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
58 /* the current (as of Nov 2002) version of cygwin has a bug in its */
59 /* wchar.h -- there is no extern "C" around the declarations in it */
60 /* and this results in linking errors later; also, at least on some */
61 /* Cygwin versions, wchar.h requires sys/types.h */
63 #include <sys/types.h>
71 #if defined(__CYGWIN__) && defined(__cplusplus)
73 #endif /* Cygwin and C++ */
75 #elif defined(HAVE_WCSTR_H)
76 /* old compilers have relevant declarations here */
78 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
79 /* include stdlib.h for wchar_t */
81 #endif /* HAVE_WCHAR_H */
87 /* -------------------------------------------------------------------------- */
88 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
89 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and */
90 /* have the function mapping _tfoo() -> foo() or wfoo() */
91 /* -------------------------------------------------------------------------- */
93 /* VC++ and BC++ starting with 5.2 have TCHAR support */
95 #define wxHAVE_TCHAR_SUPPORT
96 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
97 #define wxHAVE_TCHAR_SUPPORT
99 #elif defined(__WATCOMC__)
100 #define wxHAVE_TCHAR_SUPPORT
101 #elif defined(__DMC__)
102 #define wxHAVE_TCHAR_SUPPORT
103 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
104 #define wxHAVE_TCHAR_SUPPORT
108 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
109 /* VZ: the old VisualAge definitions were completely wrong and had no */
110 /* chance at all to work in Unicode build anyhow so let's pretend */
111 /* that VisualAge does _not_ support TCHAR for the moment (as */
112 /* indicated by "0 &&" above) until someone really has time to delve */
113 /* into Unicode issues under OS/2 */
115 /* VisualAge 4.0+ supports TCHAR */
116 #define wxHAVE_TCHAR_SUPPORT
117 #endif /* compilers with (good) TCHAR support */
119 #ifdef wxHAVE_TCHAR_SUPPORT
120 /* get TCHAR definition if we've got it */
123 /* we surely do have wchar_t if we have TCHAR */
124 #ifndef wxUSE_WCHAR_T
125 #define wxUSE_WCHAR_T 1
126 #endif /* !defined(wxUSE_WCHAR_T) */
127 #endif /* wxHAVE_TCHAR_SUPPORT */
129 /* ------------------------------------------------------------------------- */
130 /* define wxChar type */
131 /* ------------------------------------------------------------------------- */
133 /* TODO: define wxCharInt to be equal to either int or wint_t? */
137 typedef signed char wxSChar
;
138 typedef unsigned char wxUChar
;
140 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
141 /* signed/unsigned version of it which (a) makes sense to me (unlike */
142 /* char wchar_t is always unsigned) and (b) was how the previous */
143 /* definitions worked so keep it like this */
145 /* Sun's SunPro compiler supports the wchar_t type and wide character */
146 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
147 /* allow unicode enabled builds. */
148 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
149 #define __WCHAR_TYPE__ wxchar_t
152 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
154 #if !defined(__WCHAR_TYPE__) || \
155 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
157 typedef wchar_t wxChar
;
158 typedef wchar_t wxSChar
;
159 typedef wchar_t wxUChar
;
160 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
161 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. */
162 /* However, this doesn't work with new GCC 3.x compilers because */
163 /* wchar_t is C++'s builtin type in the new standard. OTOH, old */
164 /* compilers (GCC 2.x) won't accept new definition of */
165 /* wx{S,U}CharType, so we have to define wxChar */
166 /* conditionally depending on detected compiler & compiler */
169 /* with old definition of wxChar. */
170 #define wchar_t __WCHAR_TYPE__
171 typedef __WCHAR_TYPE__ wxChar
;
172 typedef __WCHAR_TYPE__ wxSChar
;
173 typedef __WCHAR_TYPE__ wxUChar
;
174 #endif /* __WCHAR_TYPE__ */
175 #endif /* ASCII/Unicode */
177 /* ------------------------------------------------------------------------- */
178 /* define wxStringCharType */
179 /* ------------------------------------------------------------------------- */
181 /* depending on the platform, Unicode build can either store wxStrings as
182 wchar_t* or UTF-8 encoded char*: */
184 /* FIXME-UTF8: what would be better place for this? */
185 #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8)
186 #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8"
188 #ifndef wxUSE_UTF8_LOCALE_ONLY
189 #define wxUSE_UTF8_LOCALE_ONLY 0
192 #ifndef wxUSE_UNICODE_UTF8
193 #define wxUSE_UNICODE_UTF8 0
196 #if wxUSE_UNICODE_UTF8
197 #define wxUSE_UNICODE_WCHAR 0
199 #define wxUSE_UNICODE_WCHAR 1
202 #define wxUSE_UNICODE_WCHAR 0
203 #define wxUSE_UNICODE_UTF8 0
204 #define wxUSE_UTF8_LOCALE_ONLY 0
207 /* define char type used by wxString internal representation: */
208 #if wxUSE_UNICODE_WCHAR
209 typedef wchar_t wxStringCharType
;
210 #else /* wxUSE_UNICODE_UTF8 || ANSI */
211 typedef char wxStringCharType
;
215 /* ------------------------------------------------------------------------- */
216 /* define wxT() and related macros */
217 /* ------------------------------------------------------------------------- */
219 /* BSD systems define _T() to be something different in ctype.h, override it */
220 #if defined(__FreeBSD__) || defined(__DARWIN__)
226 wxT ("wx text") macro turns a literal string constant into a wide char
227 constant. It is mostly unnecessary with wx 2.9 but defined for
235 Notice that we use an intermediate macro to allow x to be expanded
236 if it's a macro itself.
238 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
239 #define wxT(x) wxCONCAT_HELPER(L, x)
241 #define wxT(x) wxPREPEND_L(x)
243 #endif /* ASCII/Unicode */
244 #endif /* !defined(wxT) */
247 wxT_2 exists only for compatibility with wx 2.x and is the same as wxT() in
248 that version but nothing in the newer ones.
253 wxS ("wx string") macro can be used to create literals using the same
254 representation as wxString does internally, i.e. wchar_t in Unicode build
255 under Windows or char in UTF-8-based Unicode builds and (deprecated) ANSI
256 builds everywhere (see wxStringCharType definition above).
258 #if wxUSE_UNICODE_WCHAR
260 As above with wxT(), wxS() argument is expanded if it's a macro.
262 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
263 #define wxS(x) wxCONCAT_HELPER(L, x)
265 #define wxS(x) wxPREPEND_L(x)
267 #else /* wxUSE_UNICODE_UTF8 || ANSI */
272 _T() is a synonym for wxT() familiar to Windows programmers. As this macro
273 has even higher risk of conflicting with system headers, its use is
274 discouraged and you may predefine wxNO__T to disable it. Additionally, we
275 do it ourselves for Sun CC which is known to use it in its standard headers
278 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
284 #if !defined(_T) && !defined(wxNO__T)
288 /* a helper macro allowing to make another macro Unicode-friendly, see below */
289 #define wxAPPLY_T(x) wxT(x)
291 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
293 #define __TFILE__ wxAPPLY_T(__FILE__)
297 #define __TDATE__ wxAPPLY_T(__DATE__)
301 #define __TTIME__ wxAPPLY_T(__TIME__)
304 #endif /* _WX_WXCHARTYPE_H_ */