]> git.saurik.com Git - wxWidgets.git/blame - include/wx/wxchar.h
Pending() and Dispatch() implemented
[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
34f9227c 24// Windows (VC++) has broad TCHAR support
3f4a0c5b 25#if defined(__VISUALC__) && defined(__WIN32__)
e35d0039
JS
26
27#include <tchar.h>
1cfecdda 28#if wxUSE_UNICODE // temporary - preserve binary compatibility
e35d0039 29typedef _TCHAR wxChar;
3f4a0c5b 30typedef _TSCHAR wxSChar;
e35d0039 31typedef _TUCHAR wxUChar;
1cfecdda
OK
32#else
33#define wxChar char
34#define wxSChar signed char
35#define wxUChar unsigned char
36#endif
e35d0039
JS
37
38 // ctype.h functions
39#define wxIsalnum _istalnum
40#define wxIsalpha _istalpha
41#define wxIsctrl _istctrl
42#define wxIsdigit _istdigit
43#define wxIsgraph _istgraph
44#define wxIslower _istlower
45#define wxIsprint _istprint
46#define wxIspunct _istpunct
47#define wxIsspace _istspace
48#define wxIsupper _istupper
49#define wxIsxdigit _istxdigit
50#define wxTolower _totlower
51#define wxToupper _totupper
52
53 // locale.h functons
54#define wxSetlocale _tsetlocale
55
56 // string.h functions
57#define wxStrcat _tcscat
58#define wxStrchr _tcschr
59#define wxStrcmp _tcscmp
60#define wxStrcoll _tcscoll
61#define wxStrcpy _tcscpy
62#define wxStrcspn _tcscspn
63#define wxStrftime _tcsftime
64#define wxStrncat _tcsncat
65#define wxStrncmp _tcsncmp
66#define wxStrncpy _tcsncpy
67#define wxStrpbrk _tcspbrk
68#define wxStrrchr _tcsrchr
69#define wxStrspn _tcsspn
70#define wxStrstr _tcsstr
71#define wxStrtod _tcstod
e97a90f0 72// is there a _tcstok[_r] ?
e35d0039
JS
73#define wxStrtol _tcstol
74#define wxStrtoul _tcstoul
75#define wxStrxfrm _tcsxfrm
76
77 // stdio.h functions
78#define wxFgetc _fgettc
79#define wxFgetchar _fgettchar
80#define wxFgets _fgetts
81#define wxFopen _tfopen
82#define wxFputc _fputtc
83#define wxFputchar _fputtchar
84#define wxFprintf _ftprintf
85#define wxFreopen _tfreopen
86#define wxFscanf _ftscanf
87#define wxGetc _gettc
88#define wxGetchar _gettchar
89#define wxGets _getts
90#define wxPerror _tperror
91#define wxPrintf _tprintf
92#define wxPutc _puttc
93#define wxPutchar _puttchar
94#define wxPuts _putts
95#define wxRemove _tremove
96#define wxRename _trename
97#define wxScanf _tscanf
98#define wxSprintf _stprintf
99#define wxSscanf _stscanf
100#define wxTmpnam _ttmpnam
101#define wxUngetc _tungetc
102#define wxVfprint _vftprintf
103#define wxVprintf _vtprintf
104#define wxVsprintf _vstprintf
105
106 // stdlib.h functions
a982ddd2
OK
107#if !wxUSE_UNICODE
108#define wxAtof atof
109#endif
e35d0039
JS
110#define wxAtoi _ttoi
111#define wxAtol _ttol
112#define wxGetenv _tgetenv
113#define wxSystem _tsystem
114
115 // time.h functions
116#define wxAsctime _tasctime
117#define wxCtime _tctime
118
119// #elif defined(XXX)
120 // #include XXX-specific files here
121 // typeddef YYY wxChar;
122
123 // translate wxZZZ names
124
34f9227c
OK
125#else//!Windows (VC++)
126
127// check whether we are doing Unicode
128#if wxUSE_UNICODE
129
130#include <wchar.h>
131#include <wctype.h>
132
133// this is probably glibc-specific
134#if defined(__WCHAR_TYPE__)
135
136typedef __WCHAR_TYPE__ wxChar;
137typedef signed __WCHAR_TYPE__ wxSChar;
138typedef unsigned __WCHAR_TYPE__ wxUChar;
139
140#define _T(x) L##x
141
142 // ctype.h functions (wctype.h)
143#define wxIsalnum iswalnum
144#define wxIsalpha iswalpha
145#define wxIsctrl iswcntrl
146#define wxIsdigit iswdigit
147#define wxIsgraph iswgraph
148#define wxIslower iswlower
149#define wxIsprint iswprint
150#define wxIspunct iswpunct
151#define wxIsspace iswspace
152#define wxIsupper iswupper
153#define wxIsxdigit iswxdigit
154#define wxTolower towlower
155#define wxToupper towupper
156
157 // string.h functions (wchar.h)
158#define wxStrcat wcscat
159#define wxStrchr wcschr
160#define wxStrcmp wcscmp
161#define wxStrcoll wcscoll
162#define wxStrcpy wcscpy
163#define wxStrcspn wcscspn
164#define wxStrncat wcsncat
165#define wxStrncmp wcsncmp
166#define wxStrncpy wcsncpy
167#define wxStrpbrk wcspbrk
168#define wxStrrchr wcsrchr
169#define wxStrspn wcsspn
170#define wxStrstr wcsstr
171#define wxStrtod wcstod
172#define wxStrtok wcstok
173#define wxStrtol wcstol
174#define wxStrtoul wcstoul
175#define wxStrxfrm wcsxfrm
e35d0039 176
34f9227c 177// glibc doesn't have wc equivalents of the other stuff
e97a90f0
OK
178#define wxNEED_WX_STDIO_H
179#define wxNEED_WX_STDLIB_H
180#define wxNEED_WX_TIME_H
34f9227c
OK
181
182#else
e35d0039
JS
183#error "Please define your compiler's Unicode conventions in wxChar.h"
184#endif
34f9227c 185#else//!Unicode
e35d0039 186
e97a90f0
OK
187#include <ctype.h>
188#include <string.h>
189
1cfecdda 190#if 0 // temporary - preserve binary compatibilty
3f4a0c5b
VZ
191typedef char wxChar;
192typedef signed char wxSChar;
193typedef unsigned char wxUChar;
1cfecdda
OK
194#else
195#define wxChar char
196#define wxSChar signed char
197#define wxUChar unsigned char
198#endif
e35d0039 199
3f4a0c5b 200#define _T(x) x
e35d0039
JS
201
202 // ctype.h functions
203#define wxIsalnum isalnum
204#define wxIsalpha isalpha
205#define wxIsctrl isctrl
206#define wxIsdigit isdigit
207#define wxIsgraph isgraph
208#define wxIslower islower
209#define wxIsprint isprint
210#define wxIspunct ispunct
211#define wxIsspace isspace
212#define wxIsupper isupper
213#define wxIsxdigit isxdigit
214#define wxTolower tolower
215#define wxToupper toupper
216
217 // locale.h functons
218#define wxSetlocale setlocale
219
220 // string.h functions
221#define wxStrcat strcat
222#define wxStrchr strchr
223#define wxStrcmp strcmp
224#define wxStrcoll strcoll
225#define wxStrcpy strcpy
226#define wxStrcspn strcspn
e97a90f0 227#define wxStrdup strdup
e35d0039
JS
228#define wxStrncat strncat
229#define wxStrncmp strncmp
230#define wxStrncpy strncpy
231#define wxStrpbrk strpbrk
232#define wxStrrchr strrchr
233#define wxStrspn strspn
234#define wxStrstr strstr
235#define wxStrtod strtod
e97a90f0 236// #define wxStrtok strtok_r // this needs a configure check
e35d0039
JS
237#define wxStrtol strtol
238#define wxStrtoul strtoul
239#define wxStrxfrm strxfrm
240
241 // stdio.h functions
242#define wxFgetc fgetc
243#define wxFgetchar fgetchar
244#define wxFgets fgets
245#define wxFopen fopen
246#define wxFputc fputc
247#define wxFputchar fputchar
248#define wxFprintf fprintf
249#define wxFreopen freopen
250#define wxFscanf fscanf
251#define wxGetc getc
252#define wxGetchar getchar
253#define wxGets gets
254#define wxPerror perror
255#define wxPrintf printf
256#define wxPutc putc
257#define wxPutchar putchar
258#define wxPuts puts
259#define wxRemove remove
260#define wxRename rename
261#define wxScanf scanf
262#define wxSprintf sprintf
263#define wxSscanf sscanf
264#define wxTmpnam tmpnam
265#define wxUngetc ungetc
266#define wxVfprint vfprintf
267#define wxVprintf vprintf
268#define wxVsprintf vsprintf
269
270 // stdlib.h functions
e97a90f0 271#define wxAtof atof
e35d0039
JS
272#define wxAtoi atoi
273#define wxAtol atol
274#define wxGetenv getenv
275#define wxSystem system
276
277 // time.h functions
278#define wxAsctime asctime
279#define wxCtime ctime
34f9227c 280#define wxStrftime strftime
e35d0039
JS
281
282#endif//Unicode
34f9227c 283#endif
e35d0039
JS
284
285
286/// checks whether the passed in pointer is NULL and if the string is empty
287inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
288
289/// safe version of strlen() (returns 0 if passed NULL pointer)
639a9fb5 290inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
3f4a0c5b 291#if defined(__VISUALC__)
e35d0039 292 { return psz ? _tcslen(psz) : 0; }
34f9227c
OK
293#elif wxUSE_UNICODE
294 { return psz ? wcslen(psz) : 0; }
e35d0039
JS
295#else
296 { return psz ? strlen(psz) : 0; }
297#endif
298
299/// portable strcasecmp/_stricmp
34f9227c 300inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
3f4a0c5b 301#if defined(__VISUALC__)
e35d0039 302 { return _tcsicmp(psz1, psz2); }
34f9227c 303#elif defined(__BORLANDC__) && !wxUSE_UNICODE
e35d0039 304 { return stricmp(psz1, psz2); }
34f9227c
OK
305#elif defined(__UNIX__) || defined(__GNUWIN32__)
306#if !wxUSE_UNICODE
e35d0039 307 { return strcasecmp(psz1, psz2); }
34f9227c
OK
308#else // glibc doesn't seem to have wide char equivalent
309 {
310 register wxChar c1, c2;
311 do {
312 c1 = wxTolower(*psz1++);
313 c2 = wxTolower(*psz2++);
314 } while ( c1 && (c1 == c2) );
315
316 return c1 - c2;
317 }
318#endif
e35d0039
JS
319#else
320 // almost all compilers/libraries provide this function (unfortunately under
321 // different names), that's why we don't implement our own which will surely
322 // be more efficient than this code (uncomment to use):
323 /*
34f9227c 324 register wxChar c1, c2;
e35d0039 325 do {
34f9227c
OK
326 c1 = wxTolower(*psz1++);
327 c2 = wxTolower(*psz2++);
e35d0039
JS
328 } while ( c1 && (c1 == c2) );
329
330 return c1 - c2;
331 */
3f4a0c5b 332
e35d0039
JS
333 #error "Please define string case-insensitive compare for your OS/compiler"
334#endif // OS/compiler
335
e97a90f0
OK
336// multibyte<->widechar conversion
337size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
338size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
339#if wxUSE_UNICODE
340#define wxMB2WX wxMB2WC
341#define wxWX2MB wxWC2MB
342#define wxWC2WX wxStrncpy
343#define wxWX2WC wxStrncpy
639a9fb5 344#else
e97a90f0
OK
345#define wxMB2WX wxStrncpy
346#define wxWX2MB wxStrncpy
347#define wxWC2WX wxWC2MB
348#define wxWX2WC wxMB2WC
349#endif
350
351// if libc versions are not available, use replacements defined in wxchar.cpp
352#ifndef wxStrdup
353wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
354#endif
355
356#ifndef wxStrtok
357wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
358#endif
359
360#ifndef wxSetlocale
361wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
362#endif
363
364#ifdef wxNEED_WX_STDIO_H
365#include <stdarg.h>
366int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
367int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
368#endif
369
a982ddd2 370#ifndef wxAtof
e97a90f0 371double WXDLLEXPORT wxAtof(const wxChar *psz);
a982ddd2
OK
372#endif
373
374#ifdef wxNEED_WX_STDLIB_H
e97a90f0
OK
375int WXDLLEXPORT wxAtoi(const wxChar *psz);
376long WXDLLEXPORT wxAtol(const wxChar *psz);
377wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
378int WXDLLEXPORT wxSystem(const wxChar *psz);
639a9fb5
OK
379#endif
380
e35d0039
JS
381#endif
382 //_WX_WXCHAR_H_