]> git.saurik.com Git - wxWidgets.git/blame - include/wx/chartype.h
Fix wrong format specifiers in the samples.
[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
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 */
93928d51
VS
41#if !wxUSE_WCHAR_T
42 #error "wchar_t must be available"
e3f6cbd9
VS
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 */
2415cf67 51#if defined(__VISAGECPP__) || defined(__MINGW32__) || defined(__WATCOMC__)
e3f6cbd9
VS
52 #ifndef HAVE_WCHAR_H
53 #define HAVE_WCHAR_H
54 #endif
55#endif
e3f6cbd9 56
8d94819c
VS
57#ifdef HAVE_WCHAR_H
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 */
62 #ifdef __CYGWIN__
63 #include <sys/types.h>
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 #endif /* Cygwin */
e3f6cbd9 68
8d94819c 69 #include <wchar.h>
e3f6cbd9 70
8d94819c
VS
71 #if defined(__CYGWIN__) && defined(__cplusplus)
72 }
73 #endif /* Cygwin and C++ */
e3f6cbd9 74
8d94819c
VS
75#elif defined(HAVE_WCSTR_H)
76 /* old compilers have relevant declarations here */
77 #include <wcstr.h>
78#elif defined(__FreeBSD__) || defined(__DARWIN__) || defined(__EMX__)
79 /* include stdlib.h for wchar_t */
80 #include <stdlib.h>
81#endif /* HAVE_WCHAR_H */
e3f6cbd9 82
8d94819c
VS
83#ifdef HAVE_WIDEC_H
84 #include <widec.h>
85#endif
e3f6cbd9
VS
86
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/* -------------------------------------------------------------------------- */
92
93/* VC++ and BC++ starting with 5.2 have TCHAR support */
94#ifdef __VISUALC__
95 #define wxHAVE_TCHAR_SUPPORT
96#elif defined(__BORLANDC__) && (__BORLANDC__ >= 0x520)
97 #define wxHAVE_TCHAR_SUPPORT
98 #include <ctype.h>
99#elif defined(__WATCOMC__)
100 #define wxHAVE_TCHAR_SUPPORT
101#elif defined(__DMC__)
102 #define wxHAVE_TCHAR_SUPPORT
e3f6cbd9
VS
103#elif defined(__MINGW32__) && wxCHECK_W32API_VERSION( 1, 0 )
104 #define wxHAVE_TCHAR_SUPPORT
105 #include <stddef.h>
106 #include <string.h>
107 #include <ctype.h>
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 */
114
115 /* VisualAge 4.0+ supports TCHAR */
116 #define wxHAVE_TCHAR_SUPPORT
117#endif /* compilers with (good) TCHAR support */
118
119#ifdef wxHAVE_TCHAR_SUPPORT
120 /* get TCHAR definition if we've got it */
121 #include <tchar.h>
122
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 */
128
129/* ------------------------------------------------------------------------- */
130/* define wxChar type */
131/* ------------------------------------------------------------------------- */
132
133/* TODO: define wxCharInt to be equal to either int or wint_t? */
134
135#if !wxUSE_UNICODE
136 typedef char wxChar;
137 typedef signed char wxSChar;
138 typedef unsigned char wxUChar;
9a6d1438 139#else
e3f6cbd9
VS
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 */
144
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. */
b69ae27a
VZ
148 #if (defined(__SUNPRO_CC) || defined(__SUNPRO_C)) && !defined(__WCHAR_TYPE__)
149 #define __WCHAR_TYPE__ wxchar_t
e3f6cbd9
VS
150 #endif
151
152 /* GNU libc has __WCHAR_TYPE__ which requires special treatment, see */
153 /* comment below */
154 #if !defined(__WCHAR_TYPE__) || \
155 (!defined(__GNUC__) || wxCHECK_GCC_VERSION(2, 96))
156 /* standard case */
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 */
167 /* version. */
168
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 */
176
8f93a29f
VS
177/* ------------------------------------------------------------------------- */
178/* define wxStringCharType */
179/* ------------------------------------------------------------------------- */
180
181/* depending on the platform, Unicode build can either store wxStrings as
182 wchar_t* or UTF-8 encoded char*: */
183#if wxUSE_UNICODE
28efe654 184 /* FIXME-UTF8: what would be better place for this? */
cb352236
VS
185 #if defined(wxUSE_UTF8_LOCALE_ONLY) && !defined(wxUSE_UNICODE_UTF8)
186 #error "wxUSE_UTF8_LOCALE_ONLY only makes sense with wxUSE_UNICODE_UTF8"
187 #endif
188 #ifndef wxUSE_UTF8_LOCALE_ONLY
189 #define wxUSE_UTF8_LOCALE_ONLY 0
190 #endif
191
81727065
VS
192 #ifndef wxUSE_UNICODE_UTF8
193 #define wxUSE_UNICODE_UTF8 0
194 #endif
195
196 #if wxUSE_UNICODE_UTF8
197 #define wxUSE_UNICODE_WCHAR 0
198 #else
199 #define wxUSE_UNICODE_WCHAR 1
200 #endif
8f93a29f
VS
201#else
202 #define wxUSE_UNICODE_WCHAR 0
203 #define wxUSE_UNICODE_UTF8 0
5becc841 204 #define wxUSE_UTF8_LOCALE_ONLY 0
8f93a29f
VS
205#endif
206
207/* define char type used by wxString internal representation: */
a0516656 208#if wxUSE_UNICODE_WCHAR
8f93a29f 209 typedef wchar_t wxStringCharType;
a0516656 210#else /* wxUSE_UNICODE_UTF8 || ANSI */
8f93a29f
VS
211 typedef char wxStringCharType;
212#endif
213
214
e3f6cbd9 215/* ------------------------------------------------------------------------- */
9a83f860 216/* define wxT() and related macros */
e3f6cbd9
VS
217/* ------------------------------------------------------------------------- */
218
219/* BSD systems define _T() to be something different in ctype.h, override it */
220#if defined(__FreeBSD__) || defined(__DARWIN__)
221 #include <ctype.h>
222 #undef _T
223#endif
224
9a83f860
VZ
225/*
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
228 compatibility.
229 */
230#ifndef wxT
e3f6cbd9 231 #if !wxUSE_UNICODE
9a83f860 232 #define wxT(x) x
e3f6cbd9 233 #else /* Unicode */
25859335
VZ
234 /*
235 Notice that we use an intermediate macro to allow x to be expanded
236 if it's a macro itself.
237 */
238 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
239 #define wxT(x) wxCONCAT_HELPER(L, x)
240 #else
241 #define wxT(x) wxPREPEND_L(x)
242 #endif
e3f6cbd9 243 #endif /* ASCII/Unicode */
9a83f860 244#endif /* !defined(wxT) */
e3f6cbd9 245
9204fde6
VZ
246/*
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.
249 */
250#define wxT_2(x) x
251
a0516656
VZ
252/*
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).
257 */
258#if wxUSE_UNICODE_WCHAR
25859335
VZ
259 /*
260 As above with wxT(), wxS() argument is expanded if it's a macro.
261 */
262 #ifndef wxCOMPILER_BROKEN_CONCAT_OPER
263 #define wxS(x) wxCONCAT_HELPER(L, x)
264 #else
265 #define wxS(x) wxPREPEND_L(x)
266 #endif
a0516656
VZ
267#else /* wxUSE_UNICODE_UTF8 || ANSI */
268 #define wxS(x) x
269#endif
270
9a83f860
VZ
271/*
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
276 (see #10660).
277 */
278#if defined(__SUNPRO_C) || defined(__SUNPRO_CC)
279 #ifndef wxNO__T
280 #define wxNO__T
281 #endif
282#endif
283
284#if !defined(_T) && !defined(wxNO__T)
285 #define _T(x) wxT(x)
286#endif
e3f6cbd9
VS
287
288/* a helper macro allowing to make another macro Unicode-friendly, see below */
9a83f860 289#define wxAPPLY_T(x) wxT(x)
e3f6cbd9
VS
290
291/* Unicode-friendly __FILE__, __DATE__ and __TIME__ analogs */
292#ifndef __TFILE__
293 #define __TFILE__ wxAPPLY_T(__FILE__)
294#endif
295
296#ifndef __TDATE__
297 #define __TDATE__ wxAPPLY_T(__DATE__)
298#endif
299
300#ifndef __TTIME__
301 #define __TTIME__ wxAPPLY_T(__TIME__)
302#endif
303
304#endif /* _WX_WXCHARTYPE_H_ */
305