wxConvGdk is not used anymore
[wxWidgets.git] / include / wx / strconv.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: strconv.h
3 // Purpose: conversion routines for char sets any Unicode
4 // Author: Robert Roebling, Ove Kaaven
5 // Modified by:
6 // Created: 29/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) 1998 Ove Kaaven, Robert Roebling, Vadim Zeitlin
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXSTRCONVH__
13 #define _WX_WXSTRCONVH__
14
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "strconv.h"
17 #endif
18
19 #include "wx/defs.h"
20 #include "wx/wxchar.h"
21 #include "wx/buffer.h"
22
23 #ifdef __DIGITALMARS__
24 #include "typeinfo.h"
25 #endif
26
27 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
28 # undef __BSEXCPT__
29 #endif
30
31 #include <stdlib.h>
32
33 #if wxUSE_WCHAR_T
34
35 // ----------------------------------------------------------------------------
36 // wxMBConv (base class for conversions, using libc conversion itself)
37 // ----------------------------------------------------------------------------
38
39 class WXDLLIMPEXP_BASE wxMBConv
40 {
41 public:
42 // the actual conversion takes place here
43 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
44 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
45
46 // No longer inline since BC++ complains.
47 const wxWCharBuffer cMB2WC(const char *psz) const;
48 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
49
50 #if wxUSE_UNICODE
51 const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
52 const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
53 const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
54 const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
55 #else // ANSI
56 const char* cMB2WX(const char *psz) const { return psz; }
57 const char* cWX2MB(const char *psz) const { return psz; }
58 const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
59 const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
60 #endif // Unicode/ANSI
61
62 // virtual dtor for any base class
63 virtual ~wxMBConv();
64 };
65
66 WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc;
67
68 // ----------------------------------------------------------------------------
69 // wxMBConvUTF7 (for conversion using UTF7 encoding)
70 // ----------------------------------------------------------------------------
71
72 class WXDLLIMPEXP_BASE wxMBConvUTF7 : public wxMBConv
73 {
74 public:
75 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
76 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
77 };
78
79 WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF7) wxConvUTF7;
80
81 // ----------------------------------------------------------------------------
82 // wxMBConvUTF8 (for conversion using UTF8 encoding)
83 // ----------------------------------------------------------------------------
84
85 class WXDLLIMPEXP_BASE wxMBConvUTF8 : public wxMBConv
86 {
87 public:
88 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
89 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
90 };
91
92 WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF8) wxConvUTF8;
93
94 // ----------------------------------------------------------------------------
95 // wxCSConv (for conversion based on loadable char sets)
96 // ----------------------------------------------------------------------------
97
98 class WXDLLIMPEXP_BASE wxCharacterSet;
99
100 class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
101 {
102 public:
103 wxCSConv(const wxChar *charset);
104 wxCSConv(const wxCSConv& conv);
105 virtual ~wxCSConv();
106
107 wxCSConv& operator=(const wxCSConv& conv);
108
109 void LoadNow();
110
111 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
112 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
113
114 void Clear() ;
115
116 private:
117 void SetName(const wxChar *charset);
118
119 // note that we can't use wxString here because of compilation
120 // dependencies: we're included from wx/string.h
121 wxChar *m_name;
122 wxCharacterSet *m_cset;
123 bool m_deferred;
124 };
125
126 #define wxConvFile wxConvLocal
127 WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvLocal;
128 WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvISO8859_1;
129 WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
130
131 // ----------------------------------------------------------------------------
132 // filename conversion macros
133 // ----------------------------------------------------------------------------
134
135 // filenames are multibyte on Unix and probably widechar on Windows?
136 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
137 #define wxMBFILES 1
138 #else
139 #define wxMBFILES 0
140 #endif
141
142 #if wxMBFILES && wxUSE_UNICODE
143 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
144 #define wxFNSTRINGCAST wxMBSTRINGCAST
145 #else
146 #define wxFNCONV(name) name
147 #define wxFNSTRINGCAST WXSTRINGCAST
148 #endif
149
150 #else
151 // !wxUSE_WCHAR_T
152
153 // ----------------------------------------------------------------------------
154 // stand-ins in absence of wchar_t
155 // ----------------------------------------------------------------------------
156
157 class WXDLLIMPEXP_BASE wxMBConv
158 {
159 public:
160 const char* cMB2WX(const char *psz) const { return psz; }
161 const char* cWX2MB(const char *psz) const { return psz; }
162 };
163
164 WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc, wxConvFile, wxConvLocal, wxConvISO8859_1, wxConvUTF8;
165 WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
166
167 #define wxFNCONV(name) name
168 #define wxFNSTRINGCAST WXSTRINGCAST
169
170 #endif
171 // wxUSE_WCHAR_T
172
173 // ----------------------------------------------------------------------------
174 // macros for the most common conversions
175 // ----------------------------------------------------------------------------
176
177 #if wxUSE_UNICODE
178 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
179 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
180 #else // ANSI
181 // no conversions to do
182 #define wxConvertWX2MB(s) (s)
183 #define wxConvertMB2WX(s) (s)
184 #endif // Unicode/ANSI
185
186 #endif
187 // _WX_WXSTRCONVH__
188