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