]> git.saurik.com Git - wxWidgets.git/blame - include/wx/strconv.h
wxCalendarCtrl::Destroy() now deletes year spin control and
[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
VZ
126 wxCSConv(const wxChar *charset);
127 virtual ~wxCSConv();
128
129 void LoadNow();
130
131 virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
132 virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
133
134private:
135 void SetName(const wxChar *charset);
136
dccce9ea
VZ
137 // note that we can't use wxString here because of compilation
138 // dependencies: we're included from wx/string.h
e90c1d2a
VZ
139 wxChar *m_name;
140 wxCharacterSet *m_cset;
141 bool m_deferred;
6001e347
RR
142};
143
144WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
6001e347 145WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
6001e347 146
e90c1d2a 147// ----------------------------------------------------------------------------
6001e347 148// filename conversion macros
e90c1d2a 149// ----------------------------------------------------------------------------
6001e347
RR
150
151// filenames are multibyte on Unix and probably widechar on Windows?
152#if defined(__UNIX__) || defined(__BORLANDC__)
e90c1d2a 153 #define wxMBFILES 1
6001e347 154#else
e90c1d2a 155 #define wxMBFILES 0
6001e347
RR
156#endif
157
80df4d31 158#if wxMBFILES && wxUSE_UNICODE
e90c1d2a
VZ
159 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
160 #define wxFNSTRINGCAST wxMBSTRINGCAST
6001e347 161#else
e90c1d2a
VZ
162 #define wxFNCONV(name) name
163 #define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
164#endif
165
166#else
167 // !wxUSE_WCHAR_T
168
e90c1d2a 169// ----------------------------------------------------------------------------
6001e347 170// stand-ins in absence of wchar_t
e90c1d2a 171// ----------------------------------------------------------------------------
6001e347 172
e90c1d2a 173class WXDLLEXPORT wxMBConv
6001e347
RR
174{
175public:
e90c1d2a
VZ
176 const char* cMB2WX(const char *psz) const { return psz; }
177 const char* cWX2MB(const char *psz) const { return psz; }
6001e347 178};
e90c1d2a 179
6001e347
RR
180WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
181WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
182
183#define wxFNCONV(name) name
e90c1d2a 184#define wxFNSTRINGCAST WXSTRINGCAST
6001e347
RR
185
186#endif
187 // wxUSE_WCHAR_T
188
e90c1d2a
VZ
189// ----------------------------------------------------------------------------
190// macros for the most common conversions
191// ----------------------------------------------------------------------------
192
193#if wxUSE_UNICODE
194 #define wxConvertWX2MB(s) wxConvCurrent->cWX2MB(s)
195 #define wxConvertMB2WX(s) wxConvCurrent->cMB2WX(s)
196#else // ANSI
197 // no conversions to do
198 #define wxConvertWX2MB(s) (s)
199 #define wxConvertMB2WX(s) (s)
200#endif // Unicode/ANSI
201
202#endif
6001e347
RR
203 // _WX_WXSTRCONVH__
204