]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
Added (and documented) GetTraceMasks so userspace can probe the currently
[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
6001e347
RR
57};
58
59WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
60
e90c1d2a 61// ----------------------------------------------------------------------------
6001e347 62// wxMBConvUTF7 (for conversion using UTF7 encoding)
e90c1d2a 63// ----------------------------------------------------------------------------
6001e347 64
e90c1d2a 65class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
6001e347
RR
66{
67public:
e90c1d2a
VZ
68 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
69 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
6001e347
RR
70};
71
72WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
73
e90c1d2a 74// ----------------------------------------------------------------------------
6001e347 75// wxMBConvUTF8 (for conversion using UTF8 encoding)
e90c1d2a 76// ----------------------------------------------------------------------------
6001e347 77
e90c1d2a 78class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
6001e347
RR
79{
80public:
e90c1d2a
VZ
81 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
82 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
6001e347
RR
83};
84
85WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
86
87#ifdef __WXGTK12__
e90c1d2a
VZ
88
89// ----------------------------------------------------------------------------
6001e347 90// wxMBConvUTF8 (for conversion using GDK's internal converions)
e90c1d2a 91// ----------------------------------------------------------------------------
6001e347 92
e90c1d2a 93class WXDLLEXPORT wxMBConvGdk : public wxMBConv
6001e347
RR
94{
95public:
e90c1d2a
VZ
96 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
97 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
6001e347
RR
98};
99
100WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
6001e347 101
e90c1d2a 102#endif // wxGTK 1.2
6001e347 103
e90c1d2a
VZ
104// ----------------------------------------------------------------------------
105// wxCSConv (for conversion based on loadable char sets)
106// ----------------------------------------------------------------------------
6001e347 107
e90c1d2a
VZ
108class WXDLLEXPORT wxCharacterSet;
109
110class WXDLLEXPORT wxCSConv : public wxMBConv
6001e347 111{
6001e347 112public:
e90c1d2a 113 wxCSConv(const wxChar *charset);
54380f29 114 wxCSConv(const wxCSConv& conv);
e90c1d2a
VZ
115 virtual ~wxCSConv();
116
54380f29
GD
117 wxCSConv& operator=(const wxCSConv& conv);
118
e90c1d2a
VZ
119 void LoadNow();
120
121 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
122 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
123
65e50848
JS
124 void Clear() ;
125
e90c1d2a
VZ
126private:
127 void SetName(const wxChar *charset);
128
dccce9ea
VZ
129 // note that we can't use wxString here because of compilation
130 // dependencies: we're included from wx/string.h
e90c1d2a
VZ
131 wxChar *m_name;
132 wxCharacterSet *m_cset;
133 bool m_deferred;
6001e347
RR
134};
135
b1ac3b56 136#define wxConvFile wxConvLocal
6001e347 137WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
6001e347 138WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
6001e347 139
e90c1d2a 140// ----------------------------------------------------------------------------
6001e347 141// filename conversion macros
e90c1d2a 142// ----------------------------------------------------------------------------
6001e347
RR
143
144// filenames are multibyte on Unix and probably widechar on Windows?
145#if defined(__UNIX__) || defined(__BORLANDC__)
e90c1d2a 146 #define wxMBFILES 1
6001e347 147#else
e90c1d2a 148 #define wxMBFILES 0
6001e347
RR
149#endif
150
80df4d31 151#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
152 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
153 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 154#else
e90c1d2a
VZ
155 #define wxFNCONV(name) name
156 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
157#endif
158
159#else
160 // !wxUSE_WCHAR_T
161
e90c1d2a 162// ----------------------------------------------------------------------------
6001e347 163// stand-ins in absence of wchar_t
e90c1d2a 164// ----------------------------------------------------------------------------
6001e347 165
e90c1d2a 166class WXDLLEXPORT wxMBConv
6001e347
RR
167{
168public:
e90c1d2a
VZ
169 const char* cMB2WX(const char *psz) const { return psz; }
170 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 171};
e90c1d2a 172
6001e347
RR
173WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
174WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
175
176#define wxFNCONV(name) name
e90c1d2a 177#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
178
179#endif
180 // wxUSE_WCHAR_T
181
e90c1d2a
VZ
182// ----------------------------------------------------------------------------
183// macros for the most common conversions
184// ----------------------------------------------------------------------------
185
186#if wxUSE_UNICODE
187 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
188 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
189#else // ANSI
190 // no conversions to do
191 #define wxConvertWX2MB(s) (s)
192 #define wxConvertMB2WX(s) (s)
193#endif // Unicode/ANSI
194
195#endif
6001e347
RR
196 // _WX_WXSTRCONVH__
197