]> git.saurik.com Git - wxWidgets.git/blob - include/wx/strconv.h
removed WXUSINGDLL_FOO, one WXUSINGDLL is enough
[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 #ifdef __WXGTK12__
95
96 // ----------------------------------------------------------------------------
97 // wxMBConvUTF8 (for conversion using GDK's internal converions)
98 // ----------------------------------------------------------------------------
99
100 class WXDLLIMPEXP_BASE wxMBConvGdk : public wxMBConv
101 {
102 public:
103 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
104 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
105 };
106
107 WXDLLIMPEXP_DATA_BASE(extern wxMBConvGdk) wxConvGdk;
108
109 #endif // wxGTK 1.2
110
111 // ----------------------------------------------------------------------------
112 // wxCSConv (for conversion based on loadable char sets)
113 // ----------------------------------------------------------------------------
114
115 class WXDLLIMPEXP_BASE wxCharacterSet;
116
117 class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
118 {
119 public:
120 wxCSConv(const wxChar *charset);
121 wxCSConv(const wxCSConv& conv);
122 virtual ~wxCSConv();
123
124 wxCSConv& operator=(const wxCSConv& conv);
125
126 void LoadNow();
127
128 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
129 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
130
131 void Clear() ;
132
133 private:
134 void SetName(const wxChar *charset);
135
136 // note that we can't use wxString here because of compilation
137 // dependencies: we're included from wx/string.h
138 wxChar *m_name;
139 wxCharacterSet *m_cset;
140 bool m_deferred;
141 };
142
143 #define wxConvFile wxConvLocal
144 WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvLocal;
145 WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvISO8859_1;
146 WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
147
148 // ----------------------------------------------------------------------------
149 // filename conversion macros
150 // ----------------------------------------------------------------------------
151
152 // filenames are multibyte on Unix and probably widechar on Windows?
153 #if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
154 #define wxMBFILES 1
155 #else
156 #define wxMBFILES 0
157 #endif
158
159 #if wxMBFILES && wxUSE_UNICODE
160 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
161 #define wxFNSTRINGCAST wxMBSTRINGCAST
162 #else
163 #define wxFNCONV(name) name
164 #define wxFNSTRINGCAST WXSTRINGCAST
165 #endif
166
167 #else
168 // !wxUSE_WCHAR_T
169
170 // ----------------------------------------------------------------------------
171 // stand-ins in absence of wchar_t
172 // ----------------------------------------------------------------------------
173
174 class WXDLLIMPEXP_BASE wxMBConv
175 {
176 public:
177 const char* cMB2WX(const char *psz) const { return psz; }
178 const char* cWX2MB(const char *psz) const { return psz; }
179 };
180
181 WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc, wxConvFile, wxConvLocal, wxConvISO8859_1, wxConvUTF8;
182 WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
183
184 #define wxFNCONV(name) name
185 #define wxFNSTRINGCAST WXSTRINGCAST
186
187 #endif
188 // wxUSE_WCHAR_T
189
190 // ----------------------------------------------------------------------------
191 // macros for the most common conversions
192 // ----------------------------------------------------------------------------
193
194 #if wxUSE_UNICODE
195 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
196 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
197 #else // ANSI
198 // no conversions to do
199 #define wxConvertWX2MB(s) (s)
200 #define wxConvertMB2WX(s) (s)
201 #endif // Unicode/ANSI
202
203 #endif
204 // _WX_WXSTRCONVH__
205