]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxchar.h
wxFrame::GetClientSize -> DoGetClientSize
[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 170
57f6da0d 171#define wxNEED_WX_CTYPE_H
853d7d3d
OK
172// #define wxStrtok strtok_r // Borland C++ 4.52 doesn't have strtok_r
173#define wxNEED_WX_STRING_H
174#define wxNEED_WX_STDIO_H
175#define wxNEED_WX_STDLIB_H
176#define wxNEED_WX_TIME_H
177#define wxNEED_WCSLEN
178
81d425f6 179#else//!TCHAR-aware compilers
34f9227c 180
81d425f6
OK
181// check whether we should include wchar.h or equivalent
182#if wxUSE_UNICODE
a89ae1e4
OK
183 #undef wxUSE_WCHAR_T
184 #define wxUSE_WCHAR_T 1 // wchar_t *must* be available in Unicode mode
81d425f6 185#elif !defined(wxUSE_WCHAR_T)
a89ae1e4
OK
186 #if defined(__VISUALC__) && (__VISUALC__ < 900)
187 #define wxUSE_WCHAR_T 0 // wchar_t is not available for MSVC++ 1.5
188 #elif defined(__UNIX__)
31276cb5 189 #if defined(HAVE_WCSTR_H) || defined(HAVE_WCHAR_H) || defined(__FreeBSD__)
a89ae1e4
OK
190 #define wxUSE_WCHAR_T 1
191 #else
192 #define wxUSE_WCHAR_T 0
193 #endif
6776a0b2
JS
194 #elif defined(__GNUWIN32__) && !defined(__MINGW32__) // Cygwin (not Mingw32) doesn't have wcslen.h, needed in buffer.h
195 #define wxUSE_WCHAR_T 0
a89ae1e4
OK
196 #else
197 // add additional compiler checks if this fails
198 #define wxUSE_WCHAR_T 1
199 #endif
200#endif//wxUSE_UNICODE
81d425f6
OK
201
202#if wxUSE_WCHAR_T
31276cb5
RR
203 #ifdef HAVE_WCSTR_H
204 #include <wcstr.h>
205 #else
206 #ifndef __FreeBSD__
207 #include <wchar.h>
208 #else
209 #include <stdlib.h>
210 #define wxNEED_WCSLEN
211 #endif
212 #endif
554936c8 213#endif
65d77246 214
34f9227c
OK
215// check whether we are doing Unicode
216#if wxUSE_UNICODE
217
34f9227c
OK
218#include <wctype.h>
219
220// this is probably glibc-specific
221#if defined(__WCHAR_TYPE__)
222
223typedef __WCHAR_TYPE__ wxChar;
224typedef signed __WCHAR_TYPE__ wxSChar;
225typedef unsigned __WCHAR_TYPE__ wxUChar;
226
227#define _T(x) L##x
228
229 // ctype.h functions (wctype.h)
230#define wxIsalnum iswalnum
231#define wxIsalpha iswalpha
232#define wxIsctrl iswcntrl
233#define wxIsdigit iswdigit
234#define wxIsgraph iswgraph
235#define wxIslower iswlower
236#define wxIsprint iswprint
237#define wxIspunct iswpunct
238#define wxIsspace iswspace
239#define wxIsupper iswupper
240#define wxIsxdigit iswxdigit
0fea8a59 241
c1160779 242#if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
0fea8a59
VZ
243 // /usr/include/wctype.h incorrectly declares translations tables which
244 // provokes tons of compile-time warnings - try to correct this
245 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
246 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
247#else
248 #define wxTolower towlower
249 #define wxToupper towupper
250#endif // gcc/!gcc
34f9227c
OK
251
252 // string.h functions (wchar.h)
253#define wxStrcat wcscat
254#define wxStrchr wcschr
255#define wxStrcmp wcscmp
256#define wxStrcoll wcscoll
257#define wxStrcpy wcscpy
258#define wxStrcspn wcscspn
853d7d3d 259#define wxStrlen_ wcslen // used in wxStrlen inline function
34f9227c
OK
260#define wxStrncat wcsncat
261#define wxStrncmp wcsncmp
262#define wxStrncpy wcsncpy
263#define wxStrpbrk wcspbrk
264#define wxStrrchr wcsrchr
265#define wxStrspn wcsspn
266#define wxStrstr wcsstr
267#define wxStrtod wcstod
268#define wxStrtok wcstok
269#define wxStrtol wcstol
270#define wxStrtoul wcstoul
271#define wxStrxfrm wcsxfrm
e35d0039 272
34f9227c 273// glibc doesn't have wc equivalents of the other stuff
e97a90f0
OK
274#define wxNEED_WX_STDIO_H
275#define wxNEED_WX_STDLIB_H
276#define wxNEED_WX_TIME_H
34f9227c 277
853d7d3d 278#else//!glibc
e35d0039
JS
279#error "Please define your compiler's Unicode conventions in wxChar.h"
280#endif
34f9227c 281#else//!Unicode
e35d0039 282
e97a90f0
OK
283#include <ctype.h>
284#include <string.h>
285
1cfecdda 286#if 0 // temporary - preserve binary compatibilty
3f4a0c5b
VZ
287typedef char wxChar;
288typedef signed char wxSChar;
289typedef unsigned char wxUChar;
1cfecdda
OK
290#else
291#define wxChar char
292#define wxSChar signed char
293#define wxUChar unsigned char
294#endif
e35d0039 295
31276cb5
RR
296#ifdef __FreeBSD__
297 #undef _T
298#endif
3f4a0c5b 299#define _T(x) x
e35d0039
JS
300
301 // ctype.h functions
302#define wxIsalnum isalnum
303#define wxIsalpha isalpha
304#define wxIsctrl isctrl
305#define wxIsdigit isdigit
306#define wxIsgraph isgraph
307#define wxIslower islower
308#define wxIsprint isprint
309#define wxIspunct ispunct
310#define wxIsspace isspace
311#define wxIsupper isupper
312#define wxIsxdigit isxdigit
313#define wxTolower tolower
314#define wxToupper toupper
315
316 // locale.h functons
317#define wxSetlocale setlocale
318
319 // string.h functions
853d7d3d
OK
320#define wxStricmp strcasecmp
321// #define wxStrtok strtok_r // this needs a configure check
322
323 // leave the rest to defaults below
324#define wxNEED_WX_STRING_H
325#define wxNEED_WX_STDIO_H
326#define wxNEED_WX_STDLIB_H
327#define wxNEED_WX_TIME_H
328
329#endif//Unicode
330#endif//TCHAR-aware compilers
331
332// define wxStricmp for various compilers without Unicode possibilities
333#if !defined(wxStricmp) && !wxUSE_UNICODE
334#if defined(__BORLANDC__) || defined(__WATCOMC__) || defined(__SALFORDC__)
335 #define wxStricmp stricmp
336#elif defined(__SC__) || defined(__VISUALC__) || (defined(__MWERKS) && defined(__INTEL__))
337 #define wxStricmp _stricmp
338#elif defined(__UNIX__) || defined(__GNUWIN32__)
339 #define wxStricmp strcasecmp
340#elif defined(__MWERKS__) && !defined(__INTEL__)
341 // use wxWindows' implementation
342#else
343 // if you leave wxStricmp undefined, wxWindows' implementation will be used
344 #error "Please define string case-insensitive compare for your OS/compiler"
345#endif
346#endif
347
348// if we need to define for standard headers, and we're not using Unicode,
349// just define to standard C library routines
350#if !wxUSE_UNICODE
351#ifdef wxNEED_WX_STRING_H
e35d0039
JS
352#define wxStrcat strcat
353#define wxStrchr strchr
354#define wxStrcmp strcmp
355#define wxStrcoll strcoll
356#define wxStrcpy strcpy
357#define wxStrcspn strcspn
e97a90f0 358#define wxStrdup strdup
853d7d3d 359#define wxStrlen_ strlen // used in wxStrlen inline function
e35d0039
JS
360#define wxStrncat strncat
361#define wxStrncmp strncmp
362#define wxStrncpy strncpy
363#define wxStrpbrk strpbrk
364#define wxStrrchr strrchr
365#define wxStrspn strspn
366#define wxStrstr strstr
367#define wxStrtod strtod
e35d0039
JS
368#define wxStrtol strtol
369#define wxStrtoul strtoul
370#define wxStrxfrm strxfrm
853d7d3d
OK
371#undef wxNEED_WX_STRING_H
372#endif
e35d0039 373
853d7d3d 374#ifdef wxNEED_WX_STDIO_H
e35d0039
JS
375#define wxFgetc fgetc
376#define wxFgetchar fgetchar
377#define wxFgets fgets
378#define wxFopen fopen
379#define wxFputc fputc
380#define wxFputchar fputchar
381#define wxFprintf fprintf
382#define wxFreopen freopen
383#define wxFscanf fscanf
384#define wxGetc getc
385#define wxGetchar getchar
386#define wxGets gets
387#define wxPerror perror
388#define wxPrintf printf
389#define wxPutc putc
390#define wxPutchar putchar
391#define wxPuts puts
392#define wxRemove remove
393#define wxRename rename
394#define wxScanf scanf
395#define wxSprintf sprintf
396#define wxSscanf sscanf
397#define wxTmpnam tmpnam
398#define wxUngetc ungetc
399#define wxVfprint vfprintf
400#define wxVprintf vprintf
ea1395db 401#define wxVsscanf vsscanf
e35d0039 402#define wxVsprintf vsprintf
853d7d3d
OK
403#undef wxNEED_WX_STDIO_H
404#endif
e35d0039 405
853d7d3d 406#ifdef wxNEED_WX_STDLIB_H
e97a90f0 407#define wxAtof atof
e35d0039
JS
408#define wxAtoi atoi
409#define wxAtol atol
410#define wxGetenv getenv
411#define wxSystem system
853d7d3d
OK
412#undef wxNEED_WX_STDLIB_H
413#endif
e35d0039 414
853d7d3d 415#ifdef wxNEED_WX_TIME_H
e35d0039
JS
416#define wxAsctime asctime
417#define wxCtime ctime
34f9227c 418#define wxStrftime strftime
853d7d3d 419#undef wxNEED_WX_TIME_H
34f9227c 420#endif
853d7d3d 421#endif //!Unicode
e35d0039 422
853d7d3d
OK
423#if defined(wxNEED_WCSLEN) && wxUSE_UNICODE
424#define wcslen wxStrlen
425#undef wxNEED_WCSLEN
426#endif
e35d0039
JS
427
428/// checks whether the passed in pointer is NULL and if the string is empty
429inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
430
853d7d3d 431#ifndef wxNEED_WX_STRING_H
e35d0039 432/// safe version of strlen() (returns 0 if passed NULL pointer)
639a9fb5 433inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
853d7d3d 434 { return psz ? wxStrlen_(psz) : 0; }
34f9227c 435#endif
e35d0039 436
81d425f6 437#if wxUSE_WCHAR_T
e97a90f0
OK
438// multibyte<->widechar conversion
439size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
440size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
441#if wxUSE_UNICODE
442#define wxMB2WX wxMB2WC
443#define wxWX2MB wxWC2MB
444#define wxWC2WX wxStrncpy
445#define wxWX2WC wxStrncpy
639a9fb5 446#else
e97a90f0
OK
447#define wxMB2WX wxStrncpy
448#define wxWX2MB wxStrncpy
449#define wxWC2WX wxWC2MB
450#define wxWX2WC wxMB2WC
451#endif
0f3e3e0c
JS
452#else
453// No wxUSE_WCHAR_T: we have to do something (JACS)
454#define wxMB2WC wxStrncpy
455#define wxWC2MB wxStrncpy
456#define wxMB2WX wxStrncpy
457#define wxWX2MB wxStrncpy
458#define wxWC2WX wxWC2MB
459#define wxWX2WC wxMB2WC
81d425f6 460#endif
0f3e3e0c 461
434d2cb3 462bool WXDLLEXPORT wxOKlibc(); // for internal use
e97a90f0
OK
463
464// if libc versions are not available, use replacements defined in wxchar.cpp
465#ifndef wxStrdup
466wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
467#endif
468
0841bffa
OK
469#ifndef wxStricmp
470int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2);
471#endif
472
e97a90f0
OK
473#ifndef wxStrtok
474wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
475#endif
476
477#ifndef wxSetlocale
478wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
479#endif
480
853d7d3d
OK
481#ifdef wxNEED_WCSLEN // for use in buffer.h
482size_t WXDLLEXPORT wcslen(const wchar_t *s);
483#endif
484
57f6da0d
OK
485#ifdef wxNEED_WX_CTYPE_H
486int WXDLLEXPORT wxIsalnum(wxChar ch);
487int WXDLLEXPORT wxIsalpha(wxChar ch);
488int WXDLLEXPORT wxIsctrl(wxChar ch);
489int WXDLLEXPORT wxIsdigit(wxChar ch);
490int WXDLLEXPORT wxIsgraph(wxChar ch);
491int WXDLLEXPORT wxIslower(wxChar ch);
492int WXDLLEXPORT wxIsprint(wxChar ch);
493int WXDLLEXPORT wxIspunct(wxChar ch);
494int WXDLLEXPORT wxIsspace(wxChar ch);
495int WXDLLEXPORT wxIsupper(wxChar ch);
496int WXDLLEXPORT wxIsxdigit(wxChar ch);
497int WXDLLEXPORT wxTolower(wxChar ch);
498int WXDLLEXPORT wxToupper(wxChar ch);
499#endif
500
853d7d3d 501#ifdef wxNEED_WX_STRING_H
81d425f6
OK
502wxChar * WXDLLEXPORT wxStrcat(wxChar *dest, const wxChar *src);
503wxChar * WXDLLEXPORT wxStrchr(const wxChar *s, wxChar c);
504int WXDLLEXPORT wxStrcmp(const wxChar *s1, const wxChar *s2);
505int WXDLLEXPORT wxStrcoll(const wxChar *s1, const wxChar *s2);
506wxChar * WXDLLEXPORT wxStrcpy(wxChar *dest, const wxChar *src);
507size_t WXDLLEXPORT wxStrcspn(const wxChar *s, const wxChar *reject);
853d7d3d 508size_t WXDLLEXPORT wxStrlen(const wxChar *s);
81d425f6
OK
509wxChar * WXDLLEXPORT wxStrncat(wxChar *dest, const wxChar *src, size_t n);
510int WXDLLEXPORT wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
511wxChar * WXDLLEXPORT wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
512wxChar * WXDLLEXPORT wxStrpbrk(const wxChar *s, const wxChar *accept);
513wxChar * WXDLLEXPORT wxStrrchr(const wxChar *s, wxChar c);
514size_t WXDLLEXPORT wxStrspn(const wxChar *s, const wxChar *accept);
515wxChar * WXDLLEXPORT wxStrstr(const wxChar *haystack, const wxChar *needle);
516double WXDLLEXPORT wxStrtod(const wxChar *nptr, wxChar **endptr);
517long int WXDLLEXPORT wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
518unsigned long int WXDLLEXPORT wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);
519size_t WXDLLEXPORT wxStrxfrm(wxChar *dest, const wxChar *src, size_t n);
853d7d3d
OK
520#endif
521
e97a90f0 522#ifdef wxNEED_WX_STDIO_H
c1160779 523#include <stdio.h>
e97a90f0 524#include <stdarg.h>
7c337432
OK
525int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
526int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
c1160779
OK
527int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
528int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
e97a90f0
OK
529int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
530int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
ea1395db
OK
531int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
532int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
e97a90f0
OK
533#endif
534
a982ddd2 535#ifndef wxAtof
e97a90f0 536double WXDLLEXPORT wxAtof(const wxChar *psz);
a982ddd2
OK
537#endif
538
539#ifdef wxNEED_WX_STDLIB_H
e97a90f0
OK
540int WXDLLEXPORT wxAtoi(const wxChar *psz);
541long WXDLLEXPORT wxAtol(const wxChar *psz);
542wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
543int WXDLLEXPORT wxSystem(const wxChar *psz);
639a9fb5
OK
544#endif
545
e35d0039
JS
546#endif
547 //_WX_WXCHAR_H_