]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxchar.h
wxGLCanvas works again
[wxWidgets.git] / include / wx / wxchar.h
CommitLineData
e35d0039
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: wxchar.h
3// Purpose: Declarations common to wx char/wchar_t usage (wide chars)
4// Author: Joel Farley
5// Modified by:
6// Created: 1998/06/12
7// RCS-ID: $Id$
8// Copyright: (c) wxWindows copyright
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WXCHAR_H_
13#define _WX_WXCHAR_H_
14
15#ifdef __GNUG__
16#pragma interface "wxchar.h"
17#endif
18
19// only do SBCS or _UNICODE
20#if defined (_MBCS )
21#error "MBCS is not supported by wxChar"
22#endif
23
853d7d3d
OK
24// set wxUSE_UNICODE to 1 if UNICODE or _UNICODE is defined
25#if defined(_UNICODE) || defined(UNICODE)
26#undef wxUSE_UNICODE
27#define wxUSE_UNICODE 1
28#else
29#ifndef wxUSE_UNICODE
30#define wxUSE_UNICODE 0
31#endif
32#endif
33
34// and vice versa: define UNICODE and _UNICODE if wxUSE_UNICODE is 1...
35#if wxUSE_UNICODE
36#ifndef _UNICODE
37#define _UNICODE
38#endif
39#ifndef UNICODE
40#define UNICODE
41#endif
42#endif
43
34f9227c 44// Windows (VC++) has broad TCHAR support
3f4a0c5b 45#if defined(__VISUALC__) && defined(__WIN32__)
e35d0039
JS
46
47#include <tchar.h>
1cfecdda 48#if wxUSE_UNICODE // temporary - preserve binary compatibility
e35d0039 49typedef _TCHAR wxChar;
3f4a0c5b 50typedef _TSCHAR wxSChar;
e35d0039 51typedef _TUCHAR wxUChar;
1cfecdda
OK
52#else
53#define wxChar char
54#define wxSChar signed char
55#define wxUChar unsigned char
56#endif
81d425f6
OK
57 // wchar_t is available
58#undef wxUSE_WCHAR_T
59#define wxUSE_WCHAR_T 1
e35d0039
JS
60
61 // ctype.h functions
62#define wxIsalnum _istalnum
63#define wxIsalpha _istalpha
64#define wxIsctrl _istctrl
65#define wxIsdigit _istdigit
66#define wxIsgraph _istgraph
67#define wxIslower _istlower
68#define wxIsprint _istprint
69#define wxIspunct _istpunct
70#define wxIsspace _istspace
71#define wxIsupper _istupper
72#define wxIsxdigit _istxdigit
73#define wxTolower _totlower
74#define wxToupper _totupper
75
76 // locale.h functons
77#define wxSetlocale _tsetlocale
78
79 // string.h functions
80#define wxStrcat _tcscat
81#define wxStrchr _tcschr
82#define wxStrcmp _tcscmp
83#define wxStrcoll _tcscoll
84#define wxStrcpy _tcscpy
85#define wxStrcspn _tcscspn
86#define wxStrftime _tcsftime
853d7d3d
OK
87#define wxStricmp _tcsicmp
88#define wxStrlen_ _tcslen // used in wxStrlen inline function
e35d0039
JS
89#define wxStrncat _tcsncat
90#define wxStrncmp _tcsncmp
91#define wxStrncpy _tcsncpy
92#define wxStrpbrk _tcspbrk
93#define wxStrrchr _tcsrchr
94#define wxStrspn _tcsspn
95#define wxStrstr _tcsstr
96#define wxStrtod _tcstod
e97a90f0 97// is there a _tcstok[_r] ?
e35d0039
JS
98#define wxStrtol _tcstol
99#define wxStrtoul _tcstoul
100#define wxStrxfrm _tcsxfrm
101
102 // stdio.h functions
103#define wxFgetc _fgettc
104#define wxFgetchar _fgettchar
105#define wxFgets _fgetts
106#define wxFopen _tfopen
107#define wxFputc _fputtc
108#define wxFputchar _fputtchar
109#define wxFprintf _ftprintf
110#define wxFreopen _tfreopen
111#define wxFscanf _ftscanf
112#define wxGetc _gettc
113#define wxGetchar _gettchar
114#define wxGets _getts
115#define wxPerror _tperror
116#define wxPrintf _tprintf
117#define wxPutc _puttc
118#define wxPutchar _puttchar
119#define wxPuts _putts
120#define wxRemove _tremove
121#define wxRename _trename
122#define wxScanf _tscanf
123#define wxSprintf _stprintf
124#define wxSscanf _stscanf
125#define wxTmpnam _ttmpnam
126#define wxUngetc _tungetc
127#define wxVfprint _vftprintf
128#define wxVprintf _vtprintf
ea1395db 129#define wxVsscanf _vstscanf
e35d0039
JS
130#define wxVsprintf _vstprintf
131
132 // stdlib.h functions
a982ddd2
OK
133#if !wxUSE_UNICODE
134#define wxAtof atof
135#endif
e35d0039
JS
136#define wxAtoi _ttoi
137#define wxAtol _ttol
138#define wxGetenv _tgetenv
139#define wxSystem _tsystem
140
141 // time.h functions
142#define wxAsctime _tasctime
143#define wxCtime _tctime
144
145// #elif defined(XXX)
146 // #include XXX-specific files here
147 // typeddef YYY wxChar;
148
149 // translate wxZZZ names
150
853d7d3d
OK
151#elif defined(__BORLANDC__) && defined(__WIN32__)
152
153// Borland C++ 4.52 doesn't have much tchar support
154// maybe Borland C++ 5.02 has, can't check right now
155// but I'll use the Win32 API instead here
156
157#include <tchar.h>
158#if wxUSE_UNICODE // temporary - preserve binary compatibility
159typedef _TCHAR wxChar;
160typedef _TSCHAR wxSChar;
161typedef _TUCHAR wxUChar;
162#else
163#define wxChar char
164#define wxSChar signed char
165#define wxUChar unsigned char
166#endif
81d425f6
OK
167 // wchar_t is available
168#undef wxUSE_WCHAR_T
169#define wxUSE_WCHAR_T 1
853d7d3d
OK
170
171#include <windef.h>
172#include <winbase.h>
173#include <winnls.h>
174#include <winnt.h>
175
176 // ctype.h functions
177inline WORD __wxMSW_ctype(wxChar ch)
178{
179 WORD ret;
180 GetStringTypeEx(LOCALE_USER_DEFAULT, CT_CTYPE1, &ch, 1, &ret);
181 return ret;
182}
183#define wxIsalnum(x) IsCharAlphaNumeric
184#define wxIsalpha IsCharAlpha
185#define wxIsctrl(x) (__wxMSW_ctype(x) & C1_CNTRL)
186#define wxIsdigit(x) (__wxMSW_ctype(x) & C1_DIGIT)
187#define wxIsgraph(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_PUNCT|C1_ALPHA))
188#define wxIslower(x) IsCharLower
189#define wxIsprint(x) (__wxMSW_ctype(x) & (C1_DIGIT|C1_SPACE|C1_PUNCT|C1_ALPHA))
190#define wxIspunct(x) (__wxMSW_ctype(x) & C1_PUNCT)
191#define wxIsspace(x) (__wxMSW_ctype(x) & C1_SPACE)
192#define wxIsupper(x) IsCharUpper
193#define wxIsxdigit(x) (__wxMSW_ctype(x) & C1_XDIGIT)
194#define wxTolower(x) (wxChar)CharLower((LPTSTR)(x))
195#define wxToupper(x) (wxChar)CharUpper((LPTSTR)(x))
196
197// #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
198#define wxNEED_WX_STRING_H
199#define wxNEED_WX_STDIO_H
200#define wxNEED_WX_STDLIB_H
201#define wxNEED_WX_TIME_H
202#define wxNEED_WCSLEN
203
81d425f6 204#else//!TCHAR-aware compilers
34f9227c 205
81d425f6
OK
206// check whether we should include wchar.h or equivalent
207#if wxUSE_UNICODE
208#undef wxUSE_WCHAR_T
209#define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
210#elif !defined(wxUSE_WCHAR_T)
211#if defined(__VISUALC__) && (__VISUALC__ < 900)
212#define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
213#else
214#define wxUSE_WCHAR_T 1
215#endif
216#endif
217
218#if wxUSE_WCHAR_T
554936c8
OK
219#ifdef HAVE_WCSTR_H
220#include <wcstr.h>
221#else
65d77246 222#include <wchar.h>
81d425f6 223#endif
554936c8 224#endif
65d77246 225
34f9227c
OK
226// check whether we are doing Unicode
227#if wxUSE_UNICODE
228
34f9227c
OK
229#include <wctype.h>
230
231// this is probably glibc-specific
232#if defined(__WCHAR_TYPE__)
233
234typedef __WCHAR_TYPE__ wxChar;
235typedef signed __WCHAR_TYPE__ wxSChar;
236typedef unsigned __WCHAR_TYPE__ wxUChar;
237
238#define _T(x) L##x
239
240 // ctype.h functions (wctype.h)
241#define wxIsalnum iswalnum
242#define wxIsalpha iswalpha
243#define wxIsctrl iswcntrl
244#define wxIsdigit iswdigit
245#define wxIsgraph iswgraph
246#define wxIslower iswlower
247#define wxIsprint iswprint
248#define wxIspunct iswpunct
249#define wxIsspace iswspace
250#define wxIsupper iswupper
251#define wxIsxdigit iswxdigit
0fea8a59 252
c1160779 253#if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
0fea8a59
VZ
254 // /usr/include/wctype.h incorrectly declares translations tables which
255 // provokes tons of compile-time warnings - try to correct this
256 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
257 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
258#else
259 #define wxTolower towlower
260 #define wxToupper towupper
261#endif // gcc/!gcc
34f9227c
OK
262
263 // string.h functions (wchar.h)
264#define wxStrcat wcscat
265#define wxStrchr wcschr
266#define wxStrcmp wcscmp
267#define wxStrcoll wcscoll
268#define wxStrcpy wcscpy
269#define wxStrcspn wcscspn
853d7d3d 270#define wxStrlen_ wcslen // used in wxStrlen inline function
34f9227c
OK
271#define wxStrncat wcsncat
272#define wxStrncmp wcsncmp
273#define wxStrncpy wcsncpy
274#define wxStrpbrk wcspbrk
275#define wxStrrchr wcsrchr
276#define wxStrspn wcsspn
277#define wxStrstr wcsstr
278#define wxStrtod wcstod
279#define wxStrtok wcstok
280#define wxStrtol wcstol
281#define wxStrtoul wcstoul
282#define wxStrxfrm wcsxfrm
e35d0039 283
34f9227c 284// glibc doesn't have wc equivalents of the other stuff
e97a90f0
OK
285#define wxNEED_WX_STDIO_H
286#define wxNEED_WX_STDLIB_H
287#define wxNEED_WX_TIME_H
34f9227c 288
853d7d3d 289#else//!glibc
e35d0039
JS
290#error "Please define your compiler's Unicode conventions in wxChar.h"
291#endif
34f9227c 292#else//!Unicode
e35d0039 293
e97a90f0
OK
294#include <ctype.h>
295#include <string.h>
296
1cfecdda 297#if 0 // temporary - preserve binary compatibilty
3f4a0c5b
VZ
298typedef char wxChar;
299typedef signed char wxSChar;
300typedef unsigned char wxUChar;
1cfecdda
OK
301#else
302#define wxChar char
303#define wxSChar signed char
304#define wxUChar unsigned char
305#endif
e35d0039 306
3f4a0c5b 307#define _T(x) x
e35d0039
JS
308
309 // ctype.h functions
310#define wxIsalnum isalnum
311#define wxIsalpha isalpha
312#define wxIsctrl isctrl
313#define wxIsdigit isdigit
314#define wxIsgraph isgraph
315#define wxIslower islower
316#define wxIsprint isprint
317#define wxIspunct ispunct
318#define wxIsspace isspace
319#define wxIsupper isupper
320#define wxIsxdigit isxdigit
321#define wxTolower tolower
322#define wxToupper toupper
323
324 // locale.h functons
325#define wxSetlocale setlocale
326
327 // string.h functions
853d7d3d
OK
328#define wxStricmp strcasecmp
329// #define wxStrtok strtok_r // this needs a configure check
330
331 // leave the rest to defaults below
332#define wxNEED_WX_STRING_H
333#define wxNEED_WX_STDIO_H
334#define wxNEED_WX_STDLIB_H
335#define wxNEED_WX_TIME_H
336
337#endif//Unicode
338#endif//TCHAR-aware compilers
339
340// define wxStricmp for various compilers without Unicode possibilities
341#if !defined(wxStricmp) && !wxUSE_UNICODE
342#if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
343 #define wxStricmp stricmp
344#elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
345 #define wxStricmp _stricmp
346#elif defined(__UNIX__) || defined(__GNUWIN32__)
347 #define wxStricmp strcasecmp
348#elif defined(__MWERKS__) && !defined(__INTEL__)
349 // use wxWindows' implementation
350#else
351 // if you leave wxStricmp undefined, wxWindows' implementation will be used
352 #error "Please define string case-insensitive compare for your OS/compiler"
353#endif
354#endif
355
356// if we need to define for standard headers, and we're not using Unicode,
357// just define to standard C library routines
358#if !wxUSE_UNICODE
359#ifdef wxNEED_WX_STRING_H
e35d0039
JS
360#define wxStrcat strcat
361#define wxStrchr strchr
362#define wxStrcmp strcmp
363#define wxStrcoll strcoll
364#define wxStrcpy strcpy
365#define wxStrcspn strcspn
e97a90f0 366#define wxStrdup strdup
853d7d3d 367#define wxStrlen_ strlen // used in wxStrlen inline function
e35d0039
JS
368#define wxStrncat strncat
369#define wxStrncmp strncmp
370#define wxStrncpy strncpy
371#define wxStrpbrk strpbrk
372#define wxStrrchr strrchr
373#define wxStrspn strspn
374#define wxStrstr strstr
375#define wxStrtod strtod
e35d0039
JS
376#define wxStrtol strtol
377#define wxStrtoul strtoul
378#define wxStrxfrm strxfrm
853d7d3d
OK
379#undef wxNEED_WX_STRING_H
380#endif
e35d0039 381
853d7d3d 382#ifdef wxNEED_WX_STDIO_H
e35d0039
JS
383#define wxFgetc fgetc
384#define wxFgetchar fgetchar
385#define wxFgets fgets
386#define wxFopen fopen
387#define wxFputc fputc
388#define wxFputchar fputchar
389#define wxFprintf fprintf
390#define wxFreopen freopen
391#define wxFscanf fscanf
392#define wxGetc getc
393#define wxGetchar getchar
394#define wxGets gets
395#define wxPerror perror
396#define wxPrintf printf
397#define wxPutc putc
398#define wxPutchar putchar
399#define wxPuts puts
400#define wxRemove remove
401#define wxRename rename
402#define wxScanf scanf
403#define wxSprintf sprintf
404#define wxSscanf sscanf
405#define wxTmpnam tmpnam
406#define wxUngetc ungetc
407#define wxVfprint vfprintf
408#define wxVprintf vprintf
ea1395db 409#define wxVsscanf vsscanf
e35d0039 410#define wxVsprintf vsprintf
853d7d3d
OK
411#undef wxNEED_WX_STDIO_H
412#endif
e35d0039 413
853d7d3d 414#ifdef wxNEED_WX_STDLIB_H
e97a90f0 415#define wxAtof atof
e35d0039
JS
416#define wxAtoi atoi
417#define wxAtol atol
418#define wxGetenv getenv
419#define wxSystem system
853d7d3d
OK
420#undef wxNEED_WX_STDLIB_H
421#endif
e35d0039 422
853d7d3d 423#ifdef wxNEED_WX_TIME_H
e35d0039
JS
424#define wxAsctime asctime
425#define wxCtime ctime
34f9227c 426#define wxStrftime strftime
853d7d3d 427#undef wxNEED_WX_TIME_H
34f9227c 428#endif
853d7d3d 429#endif //!Unicode
e35d0039 430
853d7d3d
OK
431#if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
432#define wcslen wxStrlen
433#undef wxNEED_WCSLEN
434#endif
e35d0039
JS
435
436/// checks whether the passed in pointer is NULL and if the string is empty
437inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
438
853d7d3d 439#ifndef wxNEED_WX_STRING_H
e35d0039 440/// safe version of strlen() (returns 0 if passed NULL pointer)
639a9fb5 441inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
853d7d3d 442 { return psz ? wxStrlen_(psz) : 0; }
34f9227c 443#endif
e35d0039 444
81d425f6 445#if wxUSE_WCHAR_T
e97a90f0
OK
446// multibyte<->widechar conversion
447size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
448size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
449#if wxUSE_UNICODE
450#define wxMB2WX wxMB2WC
451#define wxWX2MB wxWC2MB
452#define wxWC2WX wxStrncpy
453#define wxWX2WC wxStrncpy
639a9fb5 454#else
e97a90f0
OK
455#define wxMB2WX wxStrncpy
456#define wxWX2MB wxStrncpy
457#define wxWC2WX wxWC2MB
458#define wxWX2WC wxMB2WC
459#endif
81d425f6 460#endif
e97a90f0
OK
461
462// if libc versions are not available, use replacements defined in wxchar.cpp
463#ifndef wxStrdup
464wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
465#endif
466
0841bffa
OK
467#ifndef wxStricmp
468int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2);
469#endif
470
e97a90f0
OK
471#ifndef wxStrtok
472wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
473#endif
474
475#ifndef wxSetlocale
476wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
477#endif
478
853d7d3d
OK
479#ifdef wxNEED_WCSLEN // for use in buffer.h
480size_t WXDLLEXPORT wcslen(const wchar_t *s);
481#endif
482
483#ifdef wxNEED_WX_STRING_H
81d425f6
OK
484wxChar * WXDLLEXPORT wxStrcat(wxChar *dest, const wxChar *src);
485wxChar * WXDLLEXPORT wxStrchr(const wxChar *s, wxChar c);
486int WXDLLEXPORT wxStrcmp(const wxChar *s1, const wxChar *s2);
487int WXDLLEXPORT wxStrcoll(const wxChar *s1, const wxChar *s2);
488wxChar * WXDLLEXPORT wxStrcpy(wxChar *dest, const wxChar *src);
489size_t WXDLLEXPORT wxStrcspn(const wxChar *s, const wxChar *reject);
853d7d3d 490size_t WXDLLEXPORT wxStrlen(const wxChar *s);
81d425f6
OK
491wxChar * WXDLLEXPORT wxStrncat(wxChar *dest, const wxChar *src, size_t n);
492int WXDLLEXPORT wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
493wxChar * WXDLLEXPORT wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
494wxChar * WXDLLEXPORT wxStrpbrk(const wxChar *s, const wxChar *accept);
495wxChar * WXDLLEXPORT wxStrrchr(const wxChar *s, wxChar c);
496size_t WXDLLEXPORT wxStrspn(const wxChar *s, const wxChar *accept);
497wxChar * WXDLLEXPORT wxStrstr(const wxChar *haystack, const wxChar *needle);
498double WXDLLEXPORT wxStrtod(const wxChar *nptr, wxChar **endptr);
499long int WXDLLEXPORT wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
500unsigned long int WXDLLEXPORT wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
501size_t WXDLLEXPORT wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
853d7d3d
OK
502#endif
503
e97a90f0 504#ifdef wxNEED_WX_STDIO_H
c1160779 505#include <stdio.h>
e97a90f0 506#include <stdarg.h>
7c337432
OK
507int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
508int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
c1160779
OK
509int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
510int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
e97a90f0
OK
511int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
512int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
ea1395db
OK
513int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
514int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
e97a90f0
OK
515#endif
516
a982ddd2 517#ifndef wxAtof
e97a90f0 518double WXDLLEXPORT wxAtof(const wxChar *psz);
a982ddd2
OK
519#endif
520
521#ifdef wxNEED_WX_STDLIB_H
e97a90f0
OK
522int WXDLLEXPORT wxAtoi(const wxChar *psz);
523long WXDLLEXPORT wxAtol(const wxChar *psz);
524wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
525int WXDLLEXPORT wxSystem(const wxChar *psz);
639a9fb5
OK
526#endif
527
e35d0039
JS
528#endif
529 //_WX_WXCHAR_H_