]>
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
7 * Copyright: (c) 1998-2006 wxWidgets dev team
8 * Licence: wxWindows licence
11 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13 #ifndef _WX_WXCHARTYPE_H_
14 #define _WX_WXCHARTYPE_H_
16 /* defs.h indirectly includes this file, so don't include it here */
17 #include "wx/platform.h"
19 /* check whether we have wchar_t and which size it is if we do */
20 #if !defined(wxUSE_WCHAR_T)
22 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
23 #define wxUSE_WCHAR_T 1
25 #define wxUSE_WCHAR_T 0
27 #elif defined(__GNUWIN32__) && !defined(__MINGW32__)
28 #define wxUSE_WCHAR_T 0
29 #elif defined(__WATCOMC__)
30 #define wxUSE_WCHAR_T 0
31 #elif defined(__VISAGECPP__) && (__IBMCPP__ < 400)
32 #define wxUSE_WCHAR_T 0
34 /* add additional compiler checks if this fails */
35 #define wxUSE_WCHAR_T 1
37 #endif /* !defined(wxUSE_WCHAR_T) */
39 /* Unicode support requires wchar_t */
41 #error "wchar_t must be available"
45 non Unix compilers which do have wchar.h (but not tchar.h which is included
46 below and which includes wchar.h anyhow).
48 Actually MinGW has tchar.h, but it does not include wchar.h
50 #if defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
57 /* the current (as of Nov 2002) version of cygwin has a bug in its */
58 /* wchar.h -- there is no extern "C" around the declarations in it */
59 /* and this results in linking errors later; also, at least on some */
60 /* Cygwin versions, wchar.h requires sys/types.h */
62 #include <sys/types.h>
70 #if defined(__CYGWIN__) && defined(__cplusplus)
72 #endif /* Cygwin and C++ */
74 #elif defined(HAVE_WCSTR_H)
75 /* old compilers have relevant declarations here */
77 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
78 /* include stdlib.h for wchar_t */
80 #endif /* HAVE_WCHAR_H */
86 /* -------------------------------------------------------------------------- */
87 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
88 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and */
89 /* have the function mapping _tfoo() -> foo() or wfoo() */
90 /* -------------------------------------------------------------------------- */
92 /* VC++ and BC++ starting with 5.2 have TCHAR support */
94 #define wxHAVE_TCHAR_SUPPORT
95 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
96 #define wxHAVE_TCHAR_SUPPORT
98 #elif defined(__WATCOMC__)
99 #define wxHAVE_TCHAR_SUPPORT
100 #elif defined(__DMC__)
101 #define wxHAVE_TCHAR_SUPPORT
102 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
103 #define wxHAVE_TCHAR_SUPPORT
107 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
108 /* VZ: the old VisualAge definitions were completely wrong and had no */
109 /* chance at all to work in Unicode build anyhow so let's pretend */
110 /* that VisualAge does _not_ support TCHAR for the moment (as */
111 /* indicated by "0 &&" above) until someone really has time to delve */
112 /* into Unicode issues under OS/2 */
114 /* VisualAge 4.0+ supports TCHAR */
115 #define wxHAVE_TCHAR_SUPPORT
116 #endif /* compilers with (good) TCHAR support */
118 #ifdef wxHAVE_TCHAR_SUPPORT
119 /* get TCHAR definition if we've got it */
122 /* we surely do have wchar_t if we have TCHAR */
123 #ifndef wxUSE_WCHAR_T
124 #define wxUSE_WCHAR_T 1
125 #endif /* !defined(wxUSE_WCHAR_T) */
126 #endif /* wxHAVE_TCHAR_SUPPORT */
128 /* ------------------------------------------------------------------------- */
129 /* define wxChar type */
130 /* ------------------------------------------------------------------------- */
132 /* TODO: define wxCharInt to be equal to either int or wint_t? */
136 typedef signed char wxSChar
;
137 typedef unsigned char wxUChar
;
139 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
140 /* signed/unsigned version of it which (a) makes sense to me (unlike */
141 /* char wchar_t is always unsigned) and (b) was how the previous */
142 /* definitions worked so keep it like this */
144 /* Sun's SunPro compiler supports the wchar_t type and wide character */
145 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
146 /* allow unicode enabled builds. */
147 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
148 #define __WCHAR_TYPE__ wxchar_t
151 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
153 #if !defined(__WCHAR_TYPE__) || \
154 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
156 typedef wchar_t wxChar
;
157 typedef wchar_t wxSChar
;
158 typedef wchar_t wxUChar
;
159 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
160 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. */
161 /* However, this doesn't work with new GCC 3.x compilers because */
162 /* wchar_t is C++'s builtin type in the new standard. OTOH, old */
163 /* compilers (GCC 2.x) won't accept new definition of */
164 /* wx{S,U}CharType, so we have to define wxChar */
165 /* conditionally depending on detected compiler & compiler */
168 /* with old definition of wxChar. */
169 #define wchar_t __WCHAR_TYPE__
170 typedef __WCHAR_TYPE__ wxChar
;
171 typedef __WCHAR_TYPE__ wxSChar
;
172 typedef __WCHAR_TYPE__ wxUChar
;
173 #endif /* __WCHAR_TYPE__ */
174 #endif /* ASCII/Unicode */
176 /* ------------------------------------------------------------------------- */
177 /* define wxStringCharType */
178 /* ------------------------------------------------------------------------- */
180 /* depending on the platform, Unicode build can either store wxStrings as
181 wchar_t* or UTF-8 encoded char*: */
183 /* FIXME-UTF8: what would be better place for this? */
184 #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8)
185 #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8"
187 #ifndef wxUSE_UTF8_LOCALE_ONLY
188 #define wxUSE_UTF8_LOCALE_ONLY 0
191 #ifndef wxUSE_UNICODE_UTF8
192 #define wxUSE_UNICODE_UTF8 0
195 #if wxUSE_UNICODE_UTF8
196 #define wxUSE_UNICODE_WCHAR 0
198 #define wxUSE_UNICODE_WCHAR 1
201 #define wxUSE_UNICODE_WCHAR 0
202 #define wxUSE_UNICODE_UTF8 0
203 #define wxUSE_UTF8_LOCALE_ONLY 0
206 /* define char type used by wxString internal representation: */
207 #if wxUSE_UNICODE_WCHAR
208 typedef wchar_t wxStringCharType
;
209 #else /* wxUSE_UNICODE_UTF8 || ANSI */
210 typedef char wxStringCharType
;
214 /* ------------------------------------------------------------------------- */
215 /* define wxT() and related macros */
216 /* ------------------------------------------------------------------------- */
218 /* BSD systems define _T() to be something different in ctype.h, override it */
219 #if defined(__FreeBSD__) || defined(__DARWIN__)
225 wxT ("wx text") macro turns a literal string constant into a wide char
226 constant. It is mostly unnecessary with wx 2.9 but defined for
234 Notice that we use an intermediate macro to allow x to be expanded
235 if it's a macro itself.
237 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
238 #define wxT(x) wxCONCAT_HELPER(L, x)
240 #define wxT(x) wxPREPEND_L(x)
242 #endif /* ASCII/Unicode */
243 #endif /* !defined(wxT) */
246 wxT_2 exists only for compatibility with wx 2.x and is the same as wxT() in
247 that version but nothing in the newer ones.
252 wxS ("wx string") macro can be used to create literals using the same
253 representation as wxString does internally, i.e. wchar_t in Unicode build
254 under Windows or char in UTF-8-based Unicode builds and (deprecated) ANSI
255 builds everywhere (see wxStringCharType definition above).
257 #if wxUSE_UNICODE_WCHAR
259 As above with wxT(), wxS() argument is expanded if it's a macro.
261 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
262 #define wxS(x) wxCONCAT_HELPER(L, x)
264 #define wxS(x) wxPREPEND_L(x)
266 #else /* wxUSE_UNICODE_UTF8 || ANSI */
271 _T() is a synonym for wxT() familiar to Windows programmers. As this macro
272 has even higher risk of conflicting with system headers, its use is
273 discouraged and you may predefine wxNO__T to disable it. Additionally, we
274 do it ourselves for Sun CC which is known to use it in its standard headers
277 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
283 #if !defined(_T) && !defined(wxNO__T)
287 /* a helper macro allowing to make another macro Unicode-friendly, see below */
288 #define wxAPPLY_T(x) wxT(x)
290 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
292 #define __TFILE__ wxAPPLY_T(__FILE__)
296 #define __TDATE__ wxAPPLY_T(__DATE__)
300 #define __TTIME__ wxAPPLY_T(__TIME__)
303 #endif /* _WX_WXCHARTYPE_H_ */