Use RIAA wrapper for wxSpinCtrl event disabling in wxGTK.
[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 * 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 */
40 #if !wxUSE_WCHAR_T
41 #error "wchar_t must be available"
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 */
50 #if defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
51 #ifndef HAVE_WCHAR_H
52 #define HAVE_WCHAR_H
53 #endif
54 #endif
55
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 */
67
68 #include <wchar.h>
69
70 #if defined(__CYGWIN__) && defined(__cplusplus)
71 }
72 #endif /* Cygwin and C++ */
73
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 */
81
82 #ifdef HAVE_WIDEC_H
83 #include <widec.h>
84 #endif
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
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;
138 #else
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. */
147 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
148 #define __WCHAR_TYPE__ wxchar_t
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
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
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"
186 #endif
187 #ifndef wxUSE_UTF8_LOCALE_ONLY
188 #define wxUSE_UTF8_LOCALE_ONLY 0
189 #endif
190
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
200 #else
201 #define wxUSE_UNICODE_WCHAR 0
202 #define wxUSE_UNICODE_UTF8 0
203 #define wxUSE_UTF8_LOCALE_ONLY 0
204 #endif
205
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;
211 #endif
212
213
214 /* ------------------------------------------------------------------------- */
215 /* define wxT() and related macros */
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
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
230 #if !wxUSE_UNICODE
231 #define wxT(x) x
232 #else /* Unicode */
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
242 #endif /* ASCII/Unicode */
243 #endif /* !defined(wxT) */
244
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
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
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
266 #else /* wxUSE_UNICODE_UTF8 || ANSI */
267 #define wxS(x) x
268 #endif
269
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
286
287 /* a helper macro allowing to make another macro Unicode-friendly, see below */
288 #define wxAPPLY_T(x) wxT(x)
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