]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/wxchar.h
Drag works.
[wxWidgets.git] / include / wx / wxchar.h
... / ...
CommitLineData
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
24// Windows (VC++) has broad TCHAR support
25#if defined(__VISUALC__) && defined(__WIN32__)
26
27#include <tchar.h>
28#if wxUSE_UNICODE // temporary - preserve binary compatibility
29typedef _TCHAR wxChar;
30typedef _TSCHAR wxSChar;
31typedef _TUCHAR wxUChar;
32#else
33#define wxChar char
34#define wxSChar signed char
35#define wxUChar unsigned char
36#endif
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
72// is there a _tcstok[_r] ?
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 wxVsscanf _vstscanf
105#define wxVsprintf _vstprintf
106
107 // stdlib.h functions
108#if !wxUSE_UNICODE
109#define wxAtof atof
110#endif
111#define wxAtoi _ttoi
112#define wxAtol _ttol
113#define wxGetenv _tgetenv
114#define wxSystem _tsystem
115
116 // time.h functions
117#define wxAsctime _tasctime
118#define wxCtime _tctime
119
120// #elif defined(XXX)
121 // #include XXX-specific files here
122 // typeddef YYY wxChar;
123
124 // translate wxZZZ names
125
126#else//!Windows (VC++)
127
128// check whether we are doing Unicode
129#if wxUSE_UNICODE
130
131#include <wchar.h>
132#include <wctype.h>
133
134// this is probably glibc-specific
135#if defined(__WCHAR_TYPE__)
136
137typedef __WCHAR_TYPE__ wxChar;
138typedef signed __WCHAR_TYPE__ wxSChar;
139typedef unsigned __WCHAR_TYPE__ wxUChar;
140
141#define _T(x) L##x
142
143 // ctype.h functions (wctype.h)
144#define wxIsalnum iswalnum
145#define wxIsalpha iswalpha
146#define wxIsctrl iswcntrl
147#define wxIsdigit iswdigit
148#define wxIsgraph iswgraph
149#define wxIslower iswlower
150#define wxIsprint iswprint
151#define wxIspunct iswpunct
152#define wxIsspace iswspace
153#define wxIsupper iswupper
154#define wxIsxdigit iswxdigit
155
156#if defined(__GLIBC__) && (__GLIBC__ == 2) && (__GLIBC_MINOR__ == 0)
157 // /usr/include/wctype.h incorrectly declares translations tables which
158 // provokes tons of compile-time warnings - try to correct this
159 #define wxTolower(wc) towctrans((wc), (wctrans_t)__ctype_tolower)
160 #define wxToupper(wc) towctrans((wc), (wctrans_t)__ctype_toupper)
161#else
162 #define wxTolower towlower
163 #define wxToupper towupper
164#endif // gcc/!gcc
165
166 // string.h functions (wchar.h)
167#define wxStrcat wcscat
168#define wxStrchr wcschr
169#define wxStrcmp wcscmp
170#define wxStrcoll wcscoll
171#define wxStrcpy wcscpy
172#define wxStrcspn wcscspn
173#define wxStrncat wcsncat
174#define wxStrncmp wcsncmp
175#define wxStrncpy wcsncpy
176#define wxStrpbrk wcspbrk
177#define wxStrrchr wcsrchr
178#define wxStrspn wcsspn
179#define wxStrstr wcsstr
180#define wxStrtod wcstod
181#define wxStrtok wcstok
182#define wxStrtol wcstol
183#define wxStrtoul wcstoul
184#define wxStrxfrm wcsxfrm
185
186// glibc doesn't have wc equivalents of the other stuff
187#define wxNEED_WX_STDIO_H
188#define wxNEED_WX_STDLIB_H
189#define wxNEED_WX_TIME_H
190
191#else
192#error "Please define your compiler's Unicode conventions in wxChar.h"
193#endif
194#else//!Unicode
195
196#include <ctype.h>
197#include <string.h>
198
199#if 0 // temporary - preserve binary compatibilty
200typedef char wxChar;
201typedef signed char wxSChar;
202typedef unsigned char wxUChar;
203#else
204#define wxChar char
205#define wxSChar signed char
206#define wxUChar unsigned char
207#endif
208
209#define _T(x) x
210
211 // ctype.h functions
212#define wxIsalnum isalnum
213#define wxIsalpha isalpha
214#define wxIsctrl isctrl
215#define wxIsdigit isdigit
216#define wxIsgraph isgraph
217#define wxIslower islower
218#define wxIsprint isprint
219#define wxIspunct ispunct
220#define wxIsspace isspace
221#define wxIsupper isupper
222#define wxIsxdigit isxdigit
223#define wxTolower tolower
224#define wxToupper toupper
225
226 // locale.h functons
227#define wxSetlocale setlocale
228
229 // string.h functions
230#define wxStrcat strcat
231#define wxStrchr strchr
232#define wxStrcmp strcmp
233#define wxStrcoll strcoll
234#define wxStrcpy strcpy
235#define wxStrcspn strcspn
236#define wxStrdup strdup
237#define wxStrncat strncat
238#define wxStrncmp strncmp
239#define wxStrncpy strncpy
240#define wxStrpbrk strpbrk
241#define wxStrrchr strrchr
242#define wxStrspn strspn
243#define wxStrstr strstr
244#define wxStrtod strtod
245// #define wxStrtok strtok_r // this needs a configure check
246#define wxStrtol strtol
247#define wxStrtoul strtoul
248#define wxStrxfrm strxfrm
249
250 // stdio.h functions
251#define wxFgetc fgetc
252#define wxFgetchar fgetchar
253#define wxFgets fgets
254#define wxFopen fopen
255#define wxFputc fputc
256#define wxFputchar fputchar
257#define wxFprintf fprintf
258#define wxFreopen freopen
259#define wxFscanf fscanf
260#define wxGetc getc
261#define wxGetchar getchar
262#define wxGets gets
263#define wxPerror perror
264#define wxPrintf printf
265#define wxPutc putc
266#define wxPutchar putchar
267#define wxPuts puts
268#define wxRemove remove
269#define wxRename rename
270#define wxScanf scanf
271#define wxSprintf sprintf
272#define wxSscanf sscanf
273#define wxTmpnam tmpnam
274#define wxUngetc ungetc
275#define wxVfprint vfprintf
276#define wxVprintf vprintf
277#define wxVsscanf vsscanf
278#define wxVsprintf vsprintf
279
280 // stdlib.h functions
281#define wxAtof atof
282#define wxAtoi atoi
283#define wxAtol atol
284#define wxGetenv getenv
285#define wxSystem system
286
287 // time.h functions
288#define wxAsctime asctime
289#define wxCtime ctime
290#define wxStrftime strftime
291
292#endif//Unicode
293#endif
294
295
296/// checks whether the passed in pointer is NULL and if the string is empty
297inline bool WXDLLEXPORT wxIsEmpty(const wxChar *p) { return !p || !*p; }
298
299/// safe version of strlen() (returns 0 if passed NULL pointer)
300inline size_t WXDLLEXPORT wxStrlen(const wxChar *psz)
301#if defined(__VISUALC__)
302 { return psz ? _tcslen(psz) : 0; }
303#elif wxUSE_UNICODE
304 { return psz ? wcslen(psz) : 0; }
305#else
306 { return psz ? strlen(psz) : 0; }
307#endif
308
309/// portable strcasecmp/_stricmp
310inline int WXDLLEXPORT wxStricmp(const wxChar *psz1, const wxChar *psz2)
311#if defined(__VISUALC__)
312 { return _tcsicmp(psz1, psz2); }
313#elif defined(__BORLANDC__) && !wxUSE_UNICODE
314 { return stricmp(psz1, psz2); }
315#elif defined(__UNIX__) || defined(__GNUWIN32__)
316#if !wxUSE_UNICODE
317 { return strcasecmp(psz1, psz2); }
318#else // glibc doesn't seem to have wide char equivalent
319 {
320 register wxChar c1, c2;
321 do {
322 c1 = wxTolower(*psz1++);
323 c2 = wxTolower(*psz2++);
324 } while ( c1 && (c1 == c2) );
325
326 return c1 - c2;
327 }
328#endif
329#else
330 // almost all compilers/libraries provide this function (unfortunately under
331 // different names), that's why we don't implement our own which will surely
332 // be more efficient than this code (uncomment to use):
333 /*
334 register wxChar c1, c2;
335 do {
336 c1 = wxTolower(*psz1++);
337 c2 = wxTolower(*psz2++);
338 } while ( c1 && (c1 == c2) );
339
340 return c1 - c2;
341 */
342
343 #error "Please define string case-insensitive compare for your OS/compiler"
344#endif // OS/compiler
345
346// multibyte<->widechar conversion
347size_t WXDLLEXPORT wxMB2WC(wchar_t *buf, const char *psz, size_t n);
348size_t WXDLLEXPORT wxWC2MB(char *buf, const wchar_t *psz, size_t n);
349#if wxUSE_UNICODE
350#define wxMB2WX wxMB2WC
351#define wxWX2MB wxWC2MB
352#define wxWC2WX wxStrncpy
353#define wxWX2WC wxStrncpy
354#else
355#define wxMB2WX wxStrncpy
356#define wxWX2MB wxStrncpy
357#define wxWC2WX wxWC2MB
358#define wxWX2WC wxMB2WC
359#endif
360
361// if libc versions are not available, use replacements defined in wxchar.cpp
362#ifndef wxStrdup
363wxChar * WXDLLEXPORT wxStrdup(const wxChar *psz);
364#endif
365
366#ifndef wxStrtok
367wxChar * WXDLLEXPORT wxStrtok(wxChar *psz, const wxChar *delim, wxChar **save_ptr);
368#endif
369
370#ifndef wxSetlocale
371wxChar * WXDLLEXPORT wxSetlocale(int category, const wxChar *locale);
372#endif
373
374#ifdef wxNEED_WX_STDIO_H
375#include <stdio.h>
376#include <stdarg.h>
377int WXDLLEXPORT wxPrintf(const wxChar *fmt, ...);
378int WXDLLEXPORT wxVprintf(const wxChar *fmt, va_list argptr);
379int WXDLLEXPORT wxFprintf(FILE *stream, const wxChar *fmt, ...);
380int WXDLLEXPORT wxVfprintf(FILE *stream, const wxChar *fmt, va_list argptr);
381int WXDLLEXPORT wxSprintf(wxChar *buf, const wxChar *fmt, ...);
382int WXDLLEXPORT wxVsprintf(wxChar *buf, const wxChar *fmt, va_list argptr);
383int WXDLLEXPORT wxSscanf(const wxChar *buf, const wxChar *fmt, ...);
384int WXDLLEXPORT wxVsscanf(const wxChar *buf, const wxChar *fmt, va_list argptr);
385#endif
386
387#ifndef wxAtof
388double WXDLLEXPORT wxAtof(const wxChar *psz);
389#endif
390
391#ifdef wxNEED_WX_STDLIB_H
392int WXDLLEXPORT wxAtoi(const wxChar *psz);
393long WXDLLEXPORT wxAtol(const wxChar *psz);
394wxChar * WXDLLEXPORT wxGetenv(const wxChar *name);
395int WXDLLEXPORT wxSystem(const wxChar *psz);
396#endif
397
398#endif
399 //_WX_WXCHAR_H_