]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
Added wxFIXED_SIZE.
[wxWidgets.git] / include / wx / strconv.h
CommitLineData
6001e347
RR
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
371a5b4e 9// Licence: wxWindows licence
6001e347
RR
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_WXSTRCONVH__
13#define _WX_WXSTRCONVH__
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
6001e347
RR
16 #pragma interface "strconv.h"
17#endif
18
19#include "wx/defs.h"
20#include "wx/wxchar.h"
21#include "wx/buffer.h"
22
7db39dd6
CE
23#ifdef __DIGITALMARS__
24#include "typeinfo.h"
25#endif
26
9dea36ef
DW
27#if defined(__VISAGECPP__) && __IBMCPP__ >= 400
28# undef __BSEXCPT__
29#endif
dccce9ea 30
6001e347
RR
31#include <stdlib.h>
32
33#if wxUSE_WCHAR_T
34
e90c1d2a 35// ----------------------------------------------------------------------------
bde4baac 36// wxMBConv (abstract base class for conversions)
e90c1d2a 37// ----------------------------------------------------------------------------
6001e347 38
bddd7a8d 39class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
40{
41public:
e90c1d2a 42 // the actual conversion takes place here
bde4baac
VZ
43 //
44 // note that n is the size of the output buffer, not the length of input
45 // (which is always supposed to be NUL-terminated)
46 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const = 0;
47 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const = 0;
e90c1d2a 48
bde4baac 49 // MB <-> WC
e90c1d2a
VZ
50 const wxWCharBuffer cMB2WC(const char *psz) const;
51 const wxCharBuffer cWC2MB(const wchar_t *psz) const;
6001e347 52
bde4baac 53 // convenience functions for converting MB or WC to/from wxWin default
6001e347 54#if wxUSE_UNICODE
e90c1d2a
VZ
55 const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
56 const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
57 const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
f6bcfd97 58 const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
e90c1d2a
VZ
59#else // ANSI
60 const char* cMB2WX(const char *psz) const { return psz; }
61 const char* cWX2MB(const char *psz) const { return psz; }
62 const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
63 const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
64#endif // Unicode/ANSI
2b5f62a0
VZ
65
66 // virtual dtor for any base class
67 virtual ~wxMBConv();
6001e347
RR
68};
69
bde4baac
VZ
70// ----------------------------------------------------------------------------
71// wxMBConvLibc uses standard mbstowcs() and wcstombs() functions for
72// conversion (hence it depends on the current locale)
73// ----------------------------------------------------------------------------
74
75class WXDLLIMPEXP_BASE wxMBConvLibc : public wxMBConv
76{
77public:
78 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
79 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
80};
81
82// not very accurately named because it is not necessarily of type wxMBConvLibc
83// (but the name can't eb changed because of backwards compatibility) default
84// conversion
85WXDLLIMPEXP_DATA_BASE(extern wxMBConv&) wxConvLibc;
6001e347 86
e90c1d2a 87// ----------------------------------------------------------------------------
6001e347 88// wxMBConvUTF7 (for conversion using UTF7 encoding)
e90c1d2a 89// ----------------------------------------------------------------------------
6001e347 90
bddd7a8d 91class WXDLLIMPEXP_BASE wxMBConvUTF7 : public wxMBConv
6001e347
RR
92{
93public:
e90c1d2a
VZ
94 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
95 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
6001e347
RR
96};
97
bde4baac 98WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF7&) wxConvUTF7;
6001e347 99
e90c1d2a 100// ----------------------------------------------------------------------------
6001e347 101// wxMBConvUTF8 (for conversion using UTF8 encoding)
e90c1d2a 102// ----------------------------------------------------------------------------
6001e347 103
bddd7a8d 104class WXDLLIMPEXP_BASE wxMBConvUTF8 : public wxMBConv
6001e347
RR
105{
106public:
e90c1d2a
VZ
107 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
108 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
6001e347
RR
109};
110
bde4baac 111WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF8&) wxConvUTF8;
6001e347 112
e90c1d2a 113// ----------------------------------------------------------------------------
c91830cb
VZ
114// wxMBConvUTF16LE (for conversion using UTF16 Little Endian encoding)
115// ----------------------------------------------------------------------------
116
117class WXDLLIMPEXP_BASE wxMBConvUTF16LE : public wxMBConv
118{
119public:
120 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
121 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
122};
123
124// ----------------------------------------------------------------------------
125// wxMBConvUTF16BE (for conversion using UTF16 Big Endian encoding)
126// ----------------------------------------------------------------------------
127
128class WXDLLIMPEXP_BASE wxMBConvUTF16BE : public wxMBConv
129{
130public:
131 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
132 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
133};
134
135// ----------------------------------------------------------------------------
136// wxMBConvUCS4LE (for conversion using UTF32 Little Endian encoding)
137// ----------------------------------------------------------------------------
138
139class WXDLLIMPEXP_BASE wxMBConvUTF32LE : public wxMBConv
140{
141public:
142 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
143 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
144};
145
146// ----------------------------------------------------------------------------
147// wxMBConvUCS4BE (for conversion using UTF32 Big Endian encoding)
148// ----------------------------------------------------------------------------
149
150class WXDLLIMPEXP_BASE wxMBConvUTF32BE : public wxMBConv
151{
152public:
153 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
154 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
155};
156
157// ----------------------------------------------------------------------------
e90c1d2a
VZ
158// wxCSConv (for conversion based on loadable char sets)
159// ----------------------------------------------------------------------------
6001e347 160
8b04d4c4
VZ
161#include "wx/fontenc.h"
162
bddd7a8d 163class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
6001e347 164{
6001e347 165public:
e95354ec
VZ
166 // we can be created either from charset name or from an encoding constant
167 // but we can't have both at once
e90c1d2a 168 wxCSConv(const wxChar *charset);
8b04d4c4 169 wxCSConv(wxFontEncoding encoding);
e95354ec 170
54380f29 171 wxCSConv(const wxCSConv& conv);
e90c1d2a
VZ
172 virtual ~wxCSConv();
173
54380f29 174 wxCSConv& operator=(const wxCSConv& conv);
2b5f62a0 175
e90c1d2a
VZ
176 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
177 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
178
65e50848
JS
179 void Clear() ;
180
e90c1d2a 181private:
8b04d4c4
VZ
182 // common part of all ctors
183 void Init();
184
e95354ec
VZ
185 // creates m_convReal if necessary
186 void CreateConvIfNeeded() const;
187
188 // do create m_convReal (unconditionally)
189 wxMBConv *DoCreate() const;
190
bda3d86a
VZ
191 // set the name (may be only called when m_name == NULL), makes copy of
192 // charset string
e90c1d2a
VZ
193 void SetName(const wxChar *charset);
194
e95354ec 195
dccce9ea
VZ
196 // note that we can't use wxString here because of compilation
197 // dependencies: we're included from wx/string.h
e90c1d2a 198 wxChar *m_name;
8b04d4c4 199 wxFontEncoding m_encoding;
e95354ec
VZ
200
201 // use CreateConvIfNeeded() before accessing m_convReal!
202 wxMBConv *m_convReal;
e90c1d2a 203 bool m_deferred;
6001e347
RR
204};
205
b1ac3b56 206#define wxConvFile wxConvLocal
bde4baac
VZ
207WXDLLIMPEXP_DATA_BASE(extern wxCSConv&) wxConvLocal;
208WXDLLIMPEXP_DATA_BASE(extern wxCSConv&) wxConvISO8859_1;
bddd7a8d 209WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347 210
e95354ec
VZ
211// ----------------------------------------------------------------------------
212// endianness-dependent conversions
213// ----------------------------------------------------------------------------
214
215#ifdef WORDS_BIGENDIAN
216 typedef wxMBConvUTF16BE wxMBConvUTF16;
217 typedef wxMBConvUTF32BE wxMBConvUTF32;
218#else
219 typedef wxMBConvUTF16LE wxMBConvUTF16;
220 typedef wxMBConvUTF32LE wxMBConvUTF32;
221#endif
222
e90c1d2a 223// ----------------------------------------------------------------------------
6001e347 224// filename conversion macros
e90c1d2a 225// ----------------------------------------------------------------------------
6001e347
RR
226
227// filenames are multibyte on Unix and probably widechar on Windows?
c4e41ce3 228#if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
e90c1d2a 229 #define wxMBFILES 1
6001e347 230#else
e90c1d2a 231 #define wxMBFILES 0
6001e347
RR
232#endif
233
80df4d31 234#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
235 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
236 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 237#else
e90c1d2a
VZ
238 #define wxFNCONV(name) name
239 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
240#endif
241
242#else
243 // !wxUSE_WCHAR_T
244
e90c1d2a 245// ----------------------------------------------------------------------------
6001e347 246// stand-ins in absence of wchar_t
e90c1d2a 247// ----------------------------------------------------------------------------
6001e347 248
bddd7a8d 249class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
250{
251public:
e90c1d2a
VZ
252 const char* cMB2WX(const char *psz) const { return psz; }
253 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 254};
e90c1d2a 255
bde4baac
VZ
256#define wxConvFile wxConvLocal
257
8b04d4c4 258WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc,
8b04d4c4
VZ
259 wxConvLocal,
260 wxConvISO8859_1,
261 wxConvUTF8;
bddd7a8d 262WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347
RR
263
264#define wxFNCONV(name) name
e90c1d2a 265#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
266
267#endif
268 // wxUSE_WCHAR_T
269
e90c1d2a
VZ
270// ----------------------------------------------------------------------------
271// macros for the most common conversions
272// ----------------------------------------------------------------------------
273
274#if wxUSE_UNICODE
275 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
276 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
277#else // ANSI
278 // no conversions to do
279 #define wxConvertWX2MB(s) (s)
280 #define wxConvertMB2WX(s) (s)
281#endif // Unicode/ANSI
282
283#endif
6001e347
RR
284 // _WX_WXSTRCONVH__
285