]> git.saurik.com Git - wxWidgets.git/blob - include/wx/strconv.h
added wxSpinCtrl::SetSelection()
[wxWidgets.git] / include / wx / strconv.h
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 #if defined(__VISAGECPP__) && __IBMCPP__ >= 400
24 # undef __BSEXCPT__
25 #endif
26
27 #include <stdlib.h>
28
29 #if wxUSE_WCHAR_T
30
31 // ----------------------------------------------------------------------------
32 // wxMBConv (base class for conversions, using libc conversion itself)
33 // ----------------------------------------------------------------------------
34
35 class WXDLLEXPORT wxMBConv
36 {
37 public:
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;
45
46 #if wxUSE_UNICODE
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; }
50 const wchar_t* cWX2WC(const wchar_t *psz) const { return psz; }
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
57 };
58
59 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
60
61 // ----------------------------------------------------------------------------
62 // wxMBConvUTF7 (for conversion using UTF7 encoding)
63 // ----------------------------------------------------------------------------
64
65 class WXDLLEXPORT wxMBConvUTF7 : public wxMBConv
66 {
67 public:
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;
70 };
71
72 WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
73
74 // ----------------------------------------------------------------------------
75 // wxMBConvUTF8 (for conversion using UTF8 encoding)
76 // ----------------------------------------------------------------------------
77
78 class WXDLLEXPORT wxMBConvUTF8 : public wxMBConv
79 {
80 public:
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;
83 };
84
85 WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
86
87 #ifdef __WXGTK12__
88
89 // ----------------------------------------------------------------------------
90 // wxMBConvUTF8 (for conversion using GDK's internal converions)
91 // ----------------------------------------------------------------------------
92
93 class WXDLLEXPORT wxMBConvGdk : public wxMBConv
94 {
95 public:
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;
98 };
99
100 WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
101
102 #endif // wxGTK 1.2
103
104 // ----------------------------------------------------------------------------
105 // wxCSConv (for conversion based on loadable char sets)
106 // ----------------------------------------------------------------------------
107
108 class WXDLLEXPORT wxCharacterSet;
109
110 class WXDLLEXPORT wxCSConv : public wxMBConv
111 {
112 public:
113 wxCSConv(const wxChar *charset);
114 wxCSConv(const wxCSConv& conv);
115 virtual ~wxCSConv();
116
117 wxCSConv& operator=(const wxCSConv& conv);
118
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
124 void Clear() ;
125
126 private:
127 void SetName(const wxChar *charset);
128
129 // note that we can't use wxString here because of compilation
130 // dependencies: we're included from wx/string.h
131 wxChar *m_name;
132 wxCharacterSet *m_cset;
133 bool m_deferred;
134 };
135
136 #define wxConvFile wxConvLocal
137 WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
138 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
139
140 // ----------------------------------------------------------------------------
141 // filename conversion macros
142 // ----------------------------------------------------------------------------
143
144 // filenames are multibyte on Unix and probably widechar on Windows?
145 #if defined(__UNIX__) || defined(__BORLANDC__)
146 #define wxMBFILES 1
147 #else
148 #define wxMBFILES 0
149 #endif
150
151 #if wxMBFILES && wxUSE_UNICODE
152 #define wxFNCONV(name) wxConvFile.cWX2MB(name)
153 #define wxFNSTRINGCAST wxMBSTRINGCAST
154 #else
155 #define wxFNCONV(name) name
156 #define wxFNSTRINGCAST WXSTRINGCAST
157 #endif
158
159 #else
160 // !wxUSE_WCHAR_T
161
162 // ----------------------------------------------------------------------------
163 // stand-ins in absence of wchar_t
164 // ----------------------------------------------------------------------------
165
166 class WXDLLEXPORT wxMBConv
167 {
168 public:
169 const char* cMB2WX(const char *psz) const { return psz; }
170 const char* cWX2MB(const char *psz) const { return psz; }
171 };
172
173 WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
174 WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
175
176 #define wxFNCONV(name) name
177 #define wxFNSTRINGCAST WXSTRINGCAST
178
179 #endif
180 // wxUSE_WCHAR_T
181
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
196 // _WX_WXSTRCONVH__
197