]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
Quick and dirty fix for building with COMPATIBILITY_2_4 off.
[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
af49c4b8 15#if defined(__GNUG__) && !defined(__APPLE__)
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// ----------------------------------------------------------------------------
6001e347 36// wxMBConv (base class for conversions, using libc conversion itself)
e90c1d2a 37// ----------------------------------------------------------------------------
6001e347 38
bddd7a8d 39class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
40{
41public:
e90c1d2a
VZ
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;
6001e347 49
6001e347 50#if wxUSE_UNICODE
e90c1d2a
VZ
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; }
f6bcfd97 54 const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
e90c1d2a
VZ
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
2b5f62a0
VZ
61
62 // virtual dtor for any base class
63 virtual ~wxMBConv();
6001e347
RR
64};
65
bddd7a8d 66WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc;
6001e347 67
e90c1d2a 68// ----------------------------------------------------------------------------
6001e347 69// wxMBConvUTF7 (for conversion using UTF7 encoding)
e90c1d2a 70// ----------------------------------------------------------------------------
6001e347 71
bddd7a8d 72class WXDLLIMPEXP_BASE wxMBConvUTF7 : public wxMBConv
6001e347
RR
73{
74public:
e90c1d2a
VZ
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;
6001e347
RR
77};
78
bddd7a8d 79WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF7) wxConvUTF7;
6001e347 80
e90c1d2a 81// ----------------------------------------------------------------------------
6001e347 82// wxMBConvUTF8 (for conversion using UTF8 encoding)
e90c1d2a 83// ----------------------------------------------------------------------------
6001e347 84
bddd7a8d 85class WXDLLIMPEXP_BASE wxMBConvUTF8 : public wxMBConv
6001e347
RR
86{
87public:
e90c1d2a
VZ
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;
6001e347
RR
90};
91
bddd7a8d 92WXDLLIMPEXP_DATA_BASE(extern wxMBConvUTF8) wxConvUTF8;
6001e347
RR
93
94#ifdef __WXGTK12__
e90c1d2a
VZ
95
96// ----------------------------------------------------------------------------
6001e347 97// wxMBConvUTF8 (for conversion using GDK's internal converions)
e90c1d2a 98// ----------------------------------------------------------------------------
6001e347 99
bddd7a8d 100class WXDLLIMPEXP_BASE wxMBConvGdk : public wxMBConv
6001e347
RR
101{
102public:
e90c1d2a
VZ
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;
6001e347
RR
105};
106
bddd7a8d 107WXDLLIMPEXP_DATA_BASE(extern wxMBConvGdk) wxConvGdk;
6001e347 108
e90c1d2a 109#endif // wxGTK 1.2
6001e347 110
e90c1d2a
VZ
111// ----------------------------------------------------------------------------
112// wxCSConv (for conversion based on loadable char sets)
113// ----------------------------------------------------------------------------
6001e347 114
bddd7a8d 115class WXDLLIMPEXP_BASE wxCharacterSet;
e90c1d2a 116
bddd7a8d 117class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
6001e347 118{
6001e347 119public:
e90c1d2a 120 wxCSConv(const wxChar *charset);
54380f29 121 wxCSConv(const wxCSConv& conv);
e90c1d2a
VZ
122 virtual ~wxCSConv();
123
54380f29 124 wxCSConv& operator=(const wxCSConv& conv);
2b5f62a0 125
e90c1d2a
VZ
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
65e50848
JS
131 void Clear() ;
132
e90c1d2a
VZ
133private:
134 void SetName(const wxChar *charset);
135
dccce9ea
VZ
136 // note that we can't use wxString here because of compilation
137 // dependencies: we're included from wx/string.h
e90c1d2a
VZ
138 wxChar *m_name;
139 wxCharacterSet *m_cset;
140 bool m_deferred;
6001e347
RR
141};
142
b1ac3b56 143#define wxConvFile wxConvLocal
bddd7a8d
VZ
144WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvLocal;
145WXDLLIMPEXP_DATA_BASE(extern wxCSConv) wxConvISO8859_1;
146WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347 147
e90c1d2a 148// ----------------------------------------------------------------------------
6001e347 149// filename conversion macros
e90c1d2a 150// ----------------------------------------------------------------------------
6001e347
RR
151
152// filenames are multibyte on Unix and probably widechar on Windows?
c4e41ce3 153#if defined(__UNIX__) || defined(__BORLANDC__) || defined(__WXMAC__ )
e90c1d2a 154 #define wxMBFILES 1
6001e347 155#else
e90c1d2a 156 #define wxMBFILES 0
6001e347
RR
157#endif
158
80df4d31 159#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
160 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
161 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 162#else
e90c1d2a
VZ
163 #define wxFNCONV(name) name
164 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
165#endif
166
167#else
168 // !wxUSE_WCHAR_T
169
e90c1d2a 170// ----------------------------------------------------------------------------
6001e347 171// stand-ins in absence of wchar_t
e90c1d2a 172// ----------------------------------------------------------------------------
6001e347 173
bddd7a8d 174class WXDLLIMPEXP_BASE wxMBConv
6001e347
RR
175{
176public:
e90c1d2a
VZ
177 const char* cMB2WX(const char *psz) const { return psz; }
178 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 179};
e90c1d2a 180
bddd7a8d
VZ
181WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc, wxConvFile, wxConvLocal, wxConvISO8859_1, wxConvUTF8;
182WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
6001e347
RR
183
184#define wxFNCONV(name) name
e90c1d2a 185#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
186
187#endif
188 // wxUSE_WCHAR_T
189
e90c1d2a
VZ
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
6001e347
RR
204 // _WX_WXSTRCONVH__
205