]> git.saurik.com Git - wxWidgets.git/blame - include/wx/chartype.h
Better name for wxXmlResource::GetDirection() argument.
[wxWidgets.git] / include / wx / chartype.h
CommitLineData
e3f6cbd9
VS
1/*
2 * Name: wx/chartype.h
3 * Purpose: Declarations of wxChar and related types
e9670814 4 * Author: Joel Farley, Ove Kåven
e3f6cbd9
VS
5 * Modified by: Vadim Zeitlin, Robert Roebling, Ron Lee
6 * Created: 1998/06/12
e3f6cbd9
VS
7 * Copyright: (c) 1998-2006 wxWidgets dev team
8 * Licence: wxWindows licence
9 */
10
11/* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
12
13#ifndef _WX_WXCHARTYPE_H_
14#define _WX_WXCHARTYPE_H_
15
16/* defs.h indirectly includes this file, so don't include it here */
17#include "wx/platform.h"
18
19/* check whether we have wchar_t and which size it is if we do */
20#if !defined(wxUSE_WCHAR_T)
21 #if defined(__UNIX__)
22 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
23 #define wxUSE_WCHAR_T 1
24 #else
25 #define wxUSE_WCHAR_T 0
26 #endif
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
33 #else
34 /* add additional compiler checks if this fails */
35 #define wxUSE_WCHAR_T 1
36 #endif
37#endif /* !defined(wxUSE_WCHAR_T) */
38
39/* Unicode support requires wchar_t */
93928d51
VS
40#if !wxUSE_WCHAR_T
41 #error "wchar_t must be available"
e3f6cbd9
VS
42#endif /* Unicode */
43
44/*
45 non Unix compilers which do have wchar.h (but not tchar.h which is included
46 below and which includes wchar.h anyhow).
47
48 Actually MinGW has tchar.h, but it does not include wchar.h
49 */
2415cf67 50#if defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
e3f6cbd9
VS
51 #ifndef HAVE_WCHAR_H
52 #define HAVE_WCHAR_H
53 #endif
54#endif
e3f6cbd9 55
8d94819c
VS
56#ifdef HAVE_WCHAR_H
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 */
61 #ifdef __CYGWIN__
62 #include <sys/types.h>
63 #ifdef __cplusplus
64 extern "C" {
65 #endif
66 #endif /* Cygwin */
e3f6cbd9 67
8d94819c 68 #include <wchar.h>
e3f6cbd9 69
8d94819c
VS
70 #if defined(__CYGWIN__) && defined(__cplusplus)
71 }
72 #endif /* Cygwin and C++ */
e3f6cbd9 73
8d94819c
VS
74#elif defined(HAVE_WCSTR_H)
75 /* old compilers have relevant declarations here */
76 #include <wcstr.h>
77#elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
78 /* include stdlib.h for wchar_t */
79 #include <stdlib.h>
80#endif /* HAVE_WCHAR_H */
e3f6cbd9 81
8d94819c
VS
82#ifdef HAVE_WIDEC_H
83 #include <widec.h>
84#endif
e3f6cbd9
VS
85
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/* -------------------------------------------------------------------------- */
91
92/* VC++ and BC++ starting with 5.2 have TCHAR support */
93#ifdef __VISUALC__
94 #define wxHAVE_TCHAR_SUPPORT
95#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
96 #define wxHAVE_TCHAR_SUPPORT
97 #include <ctype.h>
98#elif defined(__WATCOMC__)
99 #define wxHAVE_TCHAR_SUPPORT
100#elif defined(__DMC__)
101 #define wxHAVE_TCHAR_SUPPORT
e3f6cbd9
VS
102#elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
103 #define wxHAVE_TCHAR_SUPPORT
104 #include <stddef.h>
105 #include <string.h>
106 #include <ctype.h>
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 */
113
114 /* VisualAge 4.0+ supports TCHAR */
115 #define wxHAVE_TCHAR_SUPPORT
116#endif /* compilers with (good) TCHAR support */
117
118#ifdef wxHAVE_TCHAR_SUPPORT
119 /* get TCHAR definition if we've got it */
120 #include <tchar.h>
121
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 */
127
128/* ------------------------------------------------------------------------- */
129/* define wxChar type */
130/* ------------------------------------------------------------------------- */
131
132/* TODO: define wxCharInt to be equal to either int or wint_t? */
133
134#if !wxUSE_UNICODE
135 typedef char wxChar;
136 typedef signed char wxSChar;
137 typedef unsigned char wxUChar;
9a6d1438 138#else
e3f6cbd9
VS
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 */
143
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. */
b69ae27a
VZ
147 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
148 #define __WCHAR_TYPE__ wxchar_t
e3f6cbd9
VS
149 #endif
150
151 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
152 /* comment below */
153 #if !defined(__WCHAR_TYPE__) || \
154 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
155 /* standard case */
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 */
166 /* version. */
167
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 */
175
8f93a29f
VS
176/* ------------------------------------------------------------------------- */
177/* define wxStringCharType */
178/* ------------------------------------------------------------------------- */
179
180/* depending on the platform, Unicode build can either store wxStrings as
181 wchar_t* or UTF-8 encoded char*: */
182#if wxUSE_UNICODE
28efe654 183 /* FIXME-UTF8: what would be better place for this? */
cb352236
VS
184 #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8)
185 #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8"
186 #endif
187 #ifndef wxUSE_UTF8_LOCALE_ONLY
188 #define wxUSE_UTF8_LOCALE_ONLY 0
189 #endif
190
81727065
VS
191 #ifndef wxUSE_UNICODE_UTF8
192 #define wxUSE_UNICODE_UTF8 0
193 #endif
194
195 #if wxUSE_UNICODE_UTF8
196 #define wxUSE_UNICODE_WCHAR 0
197 #else
198 #define wxUSE_UNICODE_WCHAR 1
199 #endif
8f93a29f
VS
200#else
201 #define wxUSE_UNICODE_WCHAR 0
202 #define wxUSE_UNICODE_UTF8 0
5becc841 203 #define wxUSE_UTF8_LOCALE_ONLY 0
8f93a29f
VS
204#endif
205
206/* define char type used by wxString internal representation: */
a0516656 207#if wxUSE_UNICODE_WCHAR
8f93a29f 208 typedef wchar_t wxStringCharType;
a0516656 209#else /* wxUSE_UNICODE_UTF8 || ANSI */
8f93a29f
VS
210 typedef char wxStringCharType;
211#endif
212
213
e3f6cbd9 214/* ------------------------------------------------------------------------- */
9a83f860 215/* define wxT() and related macros */
e3f6cbd9
VS
216/* ------------------------------------------------------------------------- */
217
218/* BSD systems define _T() to be something different in ctype.h, override it */
219#if defined(__FreeBSD__) || defined(__DARWIN__)
220 #include <ctype.h>
221 #undef _T
222#endif
223
9a83f860
VZ
224/*
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
227 compatibility.
228 */
229#ifndef wxT
e3f6cbd9 230 #if !wxUSE_UNICODE
9a83f860 231 #define wxT(x) x
e3f6cbd9 232 #else /* Unicode */
25859335
VZ
233 /*
234 Notice that we use an intermediate macro to allow x to be expanded
235 if it's a macro itself.
236 */
237 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
238 #define wxT(x) wxCONCAT_HELPER(L, x)
239 #else
240 #define wxT(x) wxPREPEND_L(x)
241 #endif
e3f6cbd9 242 #endif /* ASCII/Unicode */
9a83f860 243#endif /* !defined(wxT) */
e3f6cbd9 244
9204fde6
VZ
245/*
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.
248 */
249#define wxT_2(x) x
250
a0516656
VZ
251/*
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).
256 */
257#if wxUSE_UNICODE_WCHAR
25859335
VZ
258 /*
259 As above with wxT(), wxS() argument is expanded if it's a macro.
260 */
261 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
262 #define wxS(x) wxCONCAT_HELPER(L, x)
263 #else
264 #define wxS(x) wxPREPEND_L(x)
265 #endif
a0516656
VZ
266#else /* wxUSE_UNICODE_UTF8 || ANSI */
267 #define wxS(x) x
268#endif
269
9a83f860
VZ
270/*
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
275 (see #10660).
276 */
277#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
278 #ifndef wxNO__T
279 #define wxNO__T
280 #endif
281#endif
282
283#if !defined(_T) && !defined(wxNO__T)
284 #define _T(x) wxT(x)
285#endif
e3f6cbd9
VS
286
287/* a helper macro allowing to make another macro Unicode-friendly, see below */
9a83f860 288#define wxAPPLY_T(x) wxT(x)
e3f6cbd9
VS
289
290/* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
291#ifndef __TFILE__
292 #define __TFILE__ wxAPPLY_T(__FILE__)
293#endif
294
295#ifndef __TDATE__
296 #define __TDATE__ wxAPPLY_T(__DATE__)
297#endif
298
299#ifndef __TTIME__
300 #define __TTIME__ wxAPPLY_T(__TIME__)
301#endif
302
303#endif /* _WX_WXCHARTYPE_H_ */
304