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