]> git.saurik.com Git - wxWidgets.git/blob - include/wx/chartype.h
split wxchar.h into several smaller headers
[wxWidgets.git] / include / wx / chartype.h
1 /*
2 * Name: 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
6 * Created: 1998/06/12
7 * RCS-ID: $Id$
8 * Copyright: (c) 1998-2006 wxWidgets dev team
9 * Licence: wxWindows licence
10 */
11
12 /* THIS IS A C FILE, DON'T USE C++ FEATURES (IN PARTICULAR COMMENTS) IN IT */
13
14 #ifndef _WX_WXCHARTYPE_H_
15 #define _WX_WXCHARTYPE_H_
16
17 /* defs.h indirectly includes this file, so don't include it here */
18 #include "wx/platform.h"
19
20 /* check whether we have wchar_t and which size it is if we do */
21 #if !defined(wxUSE_WCHAR_T)
22 #if defined(__UNIX__)
23 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__) || defined(__DARWIN__)
24 #define wxUSE_WCHAR_T 1
25 #else
26 #define wxUSE_WCHAR_T 0
27 #endif
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
34 #else
35 /* add additional compiler checks if this fails */
36 #define wxUSE_WCHAR_T 1
37 #endif
38 #endif /* !defined(wxUSE_WCHAR_T) */
39
40 /* Unicode support requires wchar_t */
41 #if wxUSE_UNICODE && !wxUSE_WCHAR_T
42 #error "wchar_t must be available in Unicode build"
43 #endif /* Unicode */
44
45 /*
46 non Unix compilers which do have wchar.h (but not tchar.h which is included
47 below and which includes wchar.h anyhow).
48
49 Actually MinGW has tchar.h, but it does not include wchar.h
50 */
51 #if defined(__MWERKS__) || defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
52 #ifndef HAVE_WCHAR_H
53 #define HAVE_WCHAR_H
54 #endif
55 #endif
56 #if defined(__MWERKS__) && !defined(__MACH__)
57 #ifndef HAVE_WCSLEN
58 #define HAVE_WCSLEN
59 #endif
60 #endif
61
62 #if wxUSE_WCHAR_T
63 #ifdef HAVE_WCHAR_H
64 /* the current (as of Nov 2002) version of cygwin has a bug in its */
65 /* wchar.h -- there is no extern "C" around the declarations in it */
66 /* and this results in linking errors later; also, at least on some */
67 /* Cygwin versions, wchar.h requires sys/types.h */
68 #ifdef __CYGWIN__
69 #include <sys/types.h>
70 #ifdef __cplusplus
71 extern "C" {
72 #endif
73 #endif /* Cygwin */
74
75 #include <wchar.h>
76
77 #if defined(__CYGWIN__) && defined(__cplusplus)
78 }
79 #endif /* Cygwin and C++ */
80
81 #elif defined(HAVE_WCSTR_H)
82 /* old compilers have relevant declarations here */
83 #include <wcstr.h>
84 #elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
85 /* include stdlib.h for wchar_t */
86 #include <stdlib.h>
87 #endif /* HAVE_WCHAR_H */
88
89 #ifdef HAVE_WIDEC_H
90 #include <widec.h>
91 #endif
92
93 #if !defined(__GNUC__) || defined(__DARWIN__)
94 #define wxWINT_T_IS_TYPEDEF
95 #endif
96 #endif /* wxUSE_WCHAR_T */
97
98 /* -------------------------------------------------------------------------- */
99 /* define wxHAVE_TCHAR_SUPPORT for the compilers which support the TCHAR type */
100 /* mapped to either char or wchar_t depending on the ASCII/Unicode mode and */
101 /* have the function mapping _tfoo() -> foo() or wfoo() */
102 /* -------------------------------------------------------------------------- */
103
104 /* VC++ and BC++ starting with 5.2 have TCHAR support */
105 #ifdef __VISUALC__
106 #define wxHAVE_TCHAR_SUPPORT
107 #elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
108 #define wxHAVE_TCHAR_SUPPORT
109 #include <ctype.h>
110 #elif defined(__WATCOMC__)
111 #define wxHAVE_TCHAR_SUPPORT
112 #elif defined(__DMC__)
113 #define wxHAVE_TCHAR_SUPPORT
114 #elif defined(__WXPALMOS__)
115 #include <stddef.h>
116 #elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
117 #define wxHAVE_TCHAR_SUPPORT
118 #include <stddef.h>
119 #include <string.h>
120 #include <ctype.h>
121 #elif 0 && defined(__VISAGECPP__) && (__IBMCPP__ >= 400)
122 /* VZ: the old VisualAge definitions were completely wrong and had no */
123 /* chance at all to work in Unicode build anyhow so let's pretend */
124 /* that VisualAge does _not_ support TCHAR for the moment (as */
125 /* indicated by "0 &&" above) until someone really has time to delve */
126 /* into Unicode issues under OS/2 */
127
128 /* VisualAge 4.0+ supports TCHAR */
129 #define wxHAVE_TCHAR_SUPPORT
130 #endif /* compilers with (good) TCHAR support */
131
132 #ifdef wxHAVE_TCHAR_SUPPORT
133 /* get TCHAR definition if we've got it */
134 #include <tchar.h>
135
136 /* we surely do have wchar_t if we have TCHAR */
137 #ifndef wxUSE_WCHAR_T
138 #define wxUSE_WCHAR_T 1
139 #endif /* !defined(wxUSE_WCHAR_T) */
140 #endif /* wxHAVE_TCHAR_SUPPORT */
141
142 /* ------------------------------------------------------------------------- */
143 /* define wxChar type */
144 /* ------------------------------------------------------------------------- */
145
146 /* TODO: define wxCharInt to be equal to either int or wint_t? */
147
148 #if !wxUSE_UNICODE
149 typedef char wxChar;
150 typedef signed char wxSChar;
151 typedef unsigned char wxUChar;
152 #else /* Unicode */
153 /* VZ: note that VC++ defines _T[SU]CHAR simply as wchar_t and not as */
154 /* signed/unsigned version of it which (a) makes sense to me (unlike */
155 /* char wchar_t is always unsigned) and (b) was how the previous */
156 /* definitions worked so keep it like this */
157
158 /* Sun's SunPro compiler supports the wchar_t type and wide character */
159 /* functions, but does not define __WCHAR_TYPE__. Define it here to */
160 /* allow unicode enabled builds. */
161 #if defined(__SUNPRO_CC) || defined(__SUNPRO_C)
162 #define __WCHAR_TYPE__ wxchar_t
163 #endif
164
165 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
166 /* comment below */
167 #if !defined(__WCHAR_TYPE__) || \
168 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
169 /* standard case */
170 typedef wchar_t wxChar;
171 typedef wchar_t wxSChar;
172 typedef wchar_t wxUChar;
173 #else /* __WCHAR_TYPE__ and gcc < 2.96 */
174 /* VS: wxWidgets used to define wxChar as __WCHAR_TYPE__ here. */
175 /* However, this doesn't work with new GCC 3.x compilers because */
176 /* wchar_t is C++'s builtin type in the new standard. OTOH, old */
177 /* compilers (GCC 2.x) won't accept new definition of */
178 /* wx{S,U}CharType, so we have to define wxChar */
179 /* conditionally depending on detected compiler & compiler */
180 /* version. */
181
182 /* with old definition of wxChar. */
183 #define wchar_t __WCHAR_TYPE__
184 typedef __WCHAR_TYPE__ wxChar;
185 typedef __WCHAR_TYPE__ wxSChar;
186 typedef __WCHAR_TYPE__ wxUChar;
187 #endif /* __WCHAR_TYPE__ */
188 #endif /* ASCII/Unicode */
189
190 /* ------------------------------------------------------------------------- */
191 /* define _T() and related macros */
192 /* ------------------------------------------------------------------------- */
193
194 /* BSD systems define _T() to be something different in ctype.h, override it */
195 #if defined(__FreeBSD__) || defined(__DARWIN__)
196 #include <ctype.h>
197 #undef _T
198 #endif
199
200 /* could already be defined by tchar.h (it's quasi standard) */
201 #ifndef _T
202 #if !wxUSE_UNICODE
203 #define _T(x) x
204 #else /* Unicode */
205 /* use wxCONCAT_HELPER so that x could be expanded if it's a macro */
206 #define _T(x) wxCONCAT_HELPER(L, x)
207 #endif /* ASCII/Unicode */
208 #endif /* !defined(_T) */
209
210 /* although global macros with such names are normally bad, we want to have */
211 /* another name for _T() which should be used to avoid confusion between */
212 /* _T() and _() in wxWidgets sources */
213 #define wxT(x) _T(x)
214
215 /* a helper macro allowing to make another macro Unicode-friendly, see below */
216 #define wxAPPLY_T(x) _T(x)
217
218 /* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
219 #ifndef __TFILE__
220 #define __TFILE__ wxAPPLY_T(__FILE__)
221 #endif
222
223 #ifndef __TDATE__
224 #define __TDATE__ wxAPPLY_T(__DATE__)
225 #endif
226
227 #ifndef __TTIME__
228 #define __TTIME__ wxAPPLY_T(__TIME__)
229 #endif
230
231 #endif /* _WX_WXCHARTYPE_H_ */
232