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