]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
better-looking icons
[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
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
e90c1d2a 27// ----------------------------------------------------------------------------
6001e347 28// wxMBConv (base class for conversions, using libc conversion itself)
e90c1d2a 29// ----------------------------------------------------------------------------
6001e347
RR
30
31class WXDLLEXPORT wxMBConv
32{
33public:
e90c1d2a
VZ
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;
6001e347 41
6001e347 42#if wxUSE_UNICODE
e90c1d2a
VZ
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
6001e347
RR
53};
54
55WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
56
e90c1d2a 57// ----------------------------------------------------------------------------
6001e347 58// wxMBConvFile (for conversion to filenames)
e90c1d2a 59// ----------------------------------------------------------------------------
6001e347 60
e90c1d2a 61class WXDLLEXPORT wxMBConvFile : public wxMBConv
6001e347
RR
62{
63public:
e90c1d2a
VZ
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;
6001e347
RR
66};
67
68WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
69
e90c1d2a 70// ----------------------------------------------------------------------------
6001e347 71// wxMBConvUTF7 (for conversion using UTF7 encoding)
e90c1d2a 72// ----------------------------------------------------------------------------
6001e347 73
e90c1d2a 74class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
6001e347
RR
75{
76public:
e90c1d2a
VZ
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;
6001e347
RR
79};
80
81WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
82
e90c1d2a 83// ----------------------------------------------------------------------------
6001e347 84// wxMBConvUTF8 (for conversion using UTF8 encoding)
e90c1d2a 85// ----------------------------------------------------------------------------
6001e347 86
e90c1d2a 87class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
6001e347
RR
88{
89public:
e90c1d2a
VZ
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;
6001e347
RR
92};
93
94WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
95
96#ifdef __WXGTK12__
e90c1d2a
VZ
97
98// ----------------------------------------------------------------------------
6001e347 99// wxMBConvUTF8 (for conversion using GDK's internal converions)
e90c1d2a 100// ----------------------------------------------------------------------------
6001e347 101
e90c1d2a 102class WXDLLEXPORT wxMBConvGdk : public wxMBConv
6001e347
RR
103{
104public:
e90c1d2a
VZ
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;
6001e347
RR
107};
108
109WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
6001e347 110
e90c1d2a 111#endif // wxGTK 1.2
6001e347 112
e90c1d2a
VZ
113// ----------------------------------------------------------------------------
114// wxCSConv (for conversion based on loadable char sets)
115// ----------------------------------------------------------------------------
6001e347 116
e90c1d2a
VZ
117class WXDLLEXPORT wxCharacterSet;
118
119class WXDLLEXPORT wxCSConv : public wxMBConv
6001e347 120{
6001e347 121public:
e90c1d2a
VZ
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
130private:
131 void SetName(const wxChar *charset);
132
133 wxChar *m_name;
134 wxCharacterSet *m_cset;
135 bool m_deferred;
6001e347
RR
136};
137
138WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
6001e347 139WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
6001e347 140
e90c1d2a 141// ----------------------------------------------------------------------------
6001e347 142// filename conversion macros
e90c1d2a 143// ----------------------------------------------------------------------------
6001e347
RR
144
145// filenames are multibyte on Unix and probably widechar on Windows?
146#if defined(__UNIX__) || defined(__BORLANDC__)
e90c1d2a 147 #define wxMBFILES 1
6001e347 148#else
e90c1d2a 149 #define wxMBFILES 0
6001e347
RR
150#endif
151
80df4d31 152#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
153 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
154 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 155#else
e90c1d2a
VZ
156 #define wxFNCONV(name) name
157 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
158#endif
159
160#else
161 // !wxUSE_WCHAR_T
162
e90c1d2a 163// ----------------------------------------------------------------------------
6001e347 164// stand-ins in absence of wchar_t
e90c1d2a 165// ----------------------------------------------------------------------------
6001e347 166
e90c1d2a 167class WXDLLEXPORT wxMBConv
6001e347
RR
168{
169public:
e90c1d2a
VZ
170 const char* cMB2WX(const char *psz) const { return psz; }
171 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 172};
e90c1d2a 173
6001e347
RR
174WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
175WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
176
177#define wxFNCONV(name) name
e90c1d2a 178#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
179
180#endif
181 // wxUSE_WCHAR_T
182
e90c1d2a
VZ
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
6001e347
RR
197 // _WX_WXSTRCONVH__
198