]> git.saurik.com Git - wxWidgets.git/blob - include/wx/strconv.h
Added missing costructor
[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 license
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_WXSTRCONVH__
13 #define _WX_WXSTRCONVH__
14
15 #ifdef __GNUG__
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 #include <stdlib.h>
24
25 #if wxUSE_WCHAR_T
26
27 // ----------------------------------------------------------------------------
28 // wxMBConv (base class for conversions, using libc conversion itself)
29 // ----------------------------------------------------------------------------
30
31 class WXDLLEXPORT wxMBConv
32 {
33 public:
34 // the actual conversion takes place here
35 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
36 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
37
38 // No longer inline since BC++ complains.
39 const wxWCharBuffer cMB2WC(const char *psz) const;
40 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
41
42 #if wxUSE_UNICODE
43 const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
44 const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
45 const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
46 const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
47 #else // ANSI
48 const char* cMB2WX(const char *psz) const { return psz; }
49 const char* cWX2MB(const char *psz) const { return psz; }
50 const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
51 const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
52 #endif // Unicode/ANSI
53 };
54
55 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
56
57 // ----------------------------------------------------------------------------
58 // wxMBConvFile (for conversion to filenames)
59 // ----------------------------------------------------------------------------
60
61 class WXDLLEXPORT wxMBConvFile : public wxMBConv
62 {
63 public:
64 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
65 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
66 };
67
68 WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
69
70 // ----------------------------------------------------------------------------
71 // wxMBConvUTF7 (for conversion using UTF7 encoding)
72 // ----------------------------------------------------------------------------
73
74 class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
75 {
76 public:
77 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
78 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
79 };
80
81 WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
82
83 // ----------------------------------------------------------------------------
84 // wxMBConvUTF8 (for conversion using UTF8 encoding)
85 // ----------------------------------------------------------------------------
86
87 class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
88 {
89 public:
90 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
91 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
92 };
93
94 WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
95
96 #ifdef __WXGTK12__
97
98 // ----------------------------------------------------------------------------
99 // wxMBConvUTF8 (for conversion using GDK's internal converions)
100 // ----------------------------------------------------------------------------
101
102 class WXDLLEXPORT wxMBConvGdk : public wxMBConv
103 {
104 public:
105 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
106 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
107 };
108
109 WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
110
111 #endif // wxGTK 1.2
112
113 // ----------------------------------------------------------------------------
114 // wxCSConv (for conversion based on loadable char sets)
115 // ----------------------------------------------------------------------------
116
117 class WXDLLEXPORT wxCharacterSet;
118
119 class WXDLLEXPORT wxCSConv : public wxMBConv
120 {
121 public:
122 wxCSConv(const wxChar *charset);
123 virtual ~wxCSConv();
124
125 void LoadNow();
126
127 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
128 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
129
130 private:
131 void SetName(const wxChar *charset);
132
133 wxChar *m_name;
134 wxCharacterSet *m_cset;
135 bool m_deferred;
136 };
137
138 WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
139 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
140
141 // ----------------------------------------------------------------------------
142 // filename conversion macros
143 // ----------------------------------------------------------------------------
144
145 // filenames are multibyte on Unix and probably widechar on Windows?
146 #if defined(__UNIX__) || defined(__BORLANDC__)
147 #define wxMBFILES 1
148 #else
149 #define wxMBFILES 0
150 #endif
151
152 #if wxMBFILES
153 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
154 #define wxFNSTRINGCAST wxMBSTRINGCAST
155 #else
156 #define wxFNCONV(name) name
157 #define wxFNSTRINGCAST WXSTRINGCAST
158 #endif
159
160 #else
161 // !wxUSE_WCHAR_T
162
163 // ----------------------------------------------------------------------------
164 // stand-ins in absence of wchar_t
165 // ----------------------------------------------------------------------------
166
167 class WXDLLEXPORT wxMBConv
168 {
169 public:
170 const char* cMB2WX(const char *psz) const { return psz; }
171 const char* cWX2MB(const char *psz) const { return psz; }
172 };
173
174 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
175 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
176
177 #define wxFNCONV(name) name
178 #define wxFNSTRINGCAST WXSTRINGCAST
179
180 #endif
181 // wxUSE_WCHAR_T
182
183 // ----------------------------------------------------------------------------
184 // macros for the most common conversions
185 // ----------------------------------------------------------------------------
186
187 #if wxUSE_UNICODE
188 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
189 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
190 #else // ANSI
191 // no conversions to do
192 #define wxConvertWX2MB(s) (s)
193 #define wxConvertMB2WX(s) (s)
194 #endif // Unicode/ANSI
195
196 #endif
197 // _WX_WXSTRCONVH__
198