]> git.saurik.com Git - wxWidgets.git/blame - include/wx/osx/core/private/strconv_cf.h
Fixed typo.
[wxWidgets.git] / include / wx / osx / core / private / strconv_cf.h
CommitLineData
5c6eb3a8 1/////////////////////////////////////////////////////////////////////////////
233f5738 2// Name: wx/osx/core/private/strconv_cf.h
5c6eb3a8
SC
3// Purpose: Unicode conversion classes
4// Author: David Elliott, Ryan Norton
5// Modified by:
6// Created: 2007-07-06
7// RCS-ID: $Id$
8// Copyright: (c) 2004 Ryan Norton
9// (c) 2007 David Elliott
10// Licence: wxWindows licence
11/////////////////////////////////////////////////////////////////////////////
12
13#include "wx/strconv.h"
14
15#include <CoreFoundation/CFString.h>
16#include <CoreFoundation/CFStringEncodingExt.h>
17
18// ============================================================================
19// CoreFoundation conversion classes
20// ============================================================================
21
22inline CFStringEncoding wxCFStringEncFromFontEnc(wxFontEncoding encoding)
23{
24 CFStringEncoding enc = kCFStringEncodingInvalidId ;
25
26 switch (encoding)
27 {
28 case wxFONTENCODING_DEFAULT :
29 enc = CFStringGetSystemEncoding();
30 break ;
31
32 case wxFONTENCODING_ISO8859_1 :
33 enc = kCFStringEncodingISOLatin1 ;
34 break ;
35 case wxFONTENCODING_ISO8859_2 :
36 enc = kCFStringEncodingISOLatin2;
37 break ;
38 case wxFONTENCODING_ISO8859_3 :
39 enc = kCFStringEncodingISOLatin3 ;
40 break ;
41 case wxFONTENCODING_ISO8859_4 :
42 enc = kCFStringEncodingISOLatin4;
43 break ;
44 case wxFONTENCODING_ISO8859_5 :
45 enc = kCFStringEncodingISOLatinCyrillic;
46 break ;
47 case wxFONTENCODING_ISO8859_6 :
48 enc = kCFStringEncodingISOLatinArabic;
49 break ;
50 case wxFONTENCODING_ISO8859_7 :
51 enc = kCFStringEncodingISOLatinGreek;
52 break ;
53 case wxFONTENCODING_ISO8859_8 :
54 enc = kCFStringEncodingISOLatinHebrew;
55 break ;
56 case wxFONTENCODING_ISO8859_9 :
57 enc = kCFStringEncodingISOLatin5;
58 break ;
59 case wxFONTENCODING_ISO8859_10 :
60 enc = kCFStringEncodingISOLatin6;
61 break ;
62 case wxFONTENCODING_ISO8859_11 :
63 enc = kCFStringEncodingISOLatinThai;
64 break ;
65 case wxFONTENCODING_ISO8859_13 :
66 enc = kCFStringEncodingISOLatin7;
67 break ;
68 case wxFONTENCODING_ISO8859_14 :
69 enc = kCFStringEncodingISOLatin8;
70 break ;
71 case wxFONTENCODING_ISO8859_15 :
72 enc = kCFStringEncodingISOLatin9;
73 break ;
74
75 case wxFONTENCODING_KOI8 :
76 enc = kCFStringEncodingKOI8_R;
77 break ;
78 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
79 enc = kCFStringEncodingDOSRussian;
80 break ;
81
82// case wxFONTENCODING_BULGARIAN :
83// enc = ;
84// break ;
85
86 case wxFONTENCODING_CP437 :
87 enc = kCFStringEncodingDOSLatinUS ;
88 break ;
89 case wxFONTENCODING_CP850 :
90 enc = kCFStringEncodingDOSLatin1;
91 break ;
92 case wxFONTENCODING_CP852 :
93 enc = kCFStringEncodingDOSLatin2;
94 break ;
95 case wxFONTENCODING_CP855 :
96 enc = kCFStringEncodingDOSCyrillic;
97 break ;
98 case wxFONTENCODING_CP866 :
99 enc = kCFStringEncodingDOSRussian ;
100 break ;
101 case wxFONTENCODING_CP874 :
102 enc = kCFStringEncodingDOSThai;
103 break ;
104 case wxFONTENCODING_CP932 :
105 enc = kCFStringEncodingDOSJapanese;
106 break ;
107 case wxFONTENCODING_CP936 :
108 enc = kCFStringEncodingDOSChineseSimplif ;
109 break ;
110 case wxFONTENCODING_CP949 :
111 enc = kCFStringEncodingDOSKorean;
112 break ;
113 case wxFONTENCODING_CP950 :
114 enc = kCFStringEncodingDOSChineseTrad;
115 break ;
116 case wxFONTENCODING_CP1250 :
117 enc = kCFStringEncodingWindowsLatin2;
118 break ;
119 case wxFONTENCODING_CP1251 :
120 enc = kCFStringEncodingWindowsCyrillic ;
121 break ;
122 case wxFONTENCODING_CP1252 :
123 enc = kCFStringEncodingWindowsLatin1 ;
124 break ;
125 case wxFONTENCODING_CP1253 :
126 enc = kCFStringEncodingWindowsGreek;
127 break ;
128 case wxFONTENCODING_CP1254 :
129 enc = kCFStringEncodingWindowsLatin5;
130 break ;
131 case wxFONTENCODING_CP1255 :
132 enc = kCFStringEncodingWindowsHebrew ;
133 break ;
134 case wxFONTENCODING_CP1256 :
135 enc = kCFStringEncodingWindowsArabic ;
136 break ;
137 case wxFONTENCODING_CP1257 :
138 enc = kCFStringEncodingWindowsBalticRim;
139 break ;
140// This only really encodes to UTF7 (if that) evidently
141// case wxFONTENCODING_UTF7 :
142// enc = kCFStringEncodingNonLossyASCII ;
143// break ;
144 case wxFONTENCODING_UTF8 :
145 enc = kCFStringEncodingUTF8 ;
146 break ;
147 case wxFONTENCODING_EUC_JP :
148 enc = kCFStringEncodingEUC_JP;
149 break ;
150/* Don't support conversion to/from UTF16 as wxWidgets can do this better.
151 * In particular, ToWChar would fail miserably using strlen on an input UTF16.
152 case wxFONTENCODING_UTF16 :
153 enc = kCFStringEncodingUnicode ;
154 break ;
155*/
156 case wxFONTENCODING_MACROMAN :
157 enc = kCFStringEncodingMacRoman ;
158 break ;
159 case wxFONTENCODING_MACJAPANESE :
160 enc = kCFStringEncodingMacJapanese ;
161 break ;
162 case wxFONTENCODING_MACCHINESETRAD :
163 enc = kCFStringEncodingMacChineseTrad ;
164 break ;
165 case wxFONTENCODING_MACKOREAN :
166 enc = kCFStringEncodingMacKorean ;
167 break ;
168 case wxFONTENCODING_MACARABIC :
169 enc = kCFStringEncodingMacArabic ;
170 break ;
171 case wxFONTENCODING_MACHEBREW :
172 enc = kCFStringEncodingMacHebrew ;
173 break ;
174 case wxFONTENCODING_MACGREEK :
175 enc = kCFStringEncodingMacGreek ;
176 break ;
177 case wxFONTENCODING_MACCYRILLIC :
178 enc = kCFStringEncodingMacCyrillic ;
179 break ;
180 case wxFONTENCODING_MACDEVANAGARI :
181 enc = kCFStringEncodingMacDevanagari ;
182 break ;
183 case wxFONTENCODING_MACGURMUKHI :
184 enc = kCFStringEncodingMacGurmukhi ;
185 break ;
186 case wxFONTENCODING_MACGUJARATI :
187 enc = kCFStringEncodingMacGujarati ;
188 break ;
189 case wxFONTENCODING_MACORIYA :
190 enc = kCFStringEncodingMacOriya ;
191 break ;
192 case wxFONTENCODING_MACBENGALI :
193 enc = kCFStringEncodingMacBengali ;
194 break ;
195 case wxFONTENCODING_MACTAMIL :
196 enc = kCFStringEncodingMacTamil ;
197 break ;
198 case wxFONTENCODING_MACTELUGU :
199 enc = kCFStringEncodingMacTelugu ;
200 break ;
201 case wxFONTENCODING_MACKANNADA :
202 enc = kCFStringEncodingMacKannada ;
203 break ;
204 case wxFONTENCODING_MACMALAJALAM :
205 enc = kCFStringEncodingMacMalayalam ;
206 break ;
207 case wxFONTENCODING_MACSINHALESE :
208 enc = kCFStringEncodingMacSinhalese ;
209 break ;
210 case wxFONTENCODING_MACBURMESE :
211 enc = kCFStringEncodingMacBurmese ;
212 break ;
213 case wxFONTENCODING_MACKHMER :
214 enc = kCFStringEncodingMacKhmer ;
215 break ;
216 case wxFONTENCODING_MACTHAI :
217 enc = kCFStringEncodingMacThai ;
218 break ;
219 case wxFONTENCODING_MACLAOTIAN :
220 enc = kCFStringEncodingMacLaotian ;
221 break ;
222 case wxFONTENCODING_MACGEORGIAN :
223 enc = kCFStringEncodingMacGeorgian ;
224 break ;
225 case wxFONTENCODING_MACARMENIAN :
226 enc = kCFStringEncodingMacArmenian ;
227 break ;
228 case wxFONTENCODING_MACCHINESESIMP :
229 enc = kCFStringEncodingMacChineseSimp ;
230 break ;
231 case wxFONTENCODING_MACTIBETAN :
232 enc = kCFStringEncodingMacTibetan ;
233 break ;
234 case wxFONTENCODING_MACMONGOLIAN :
235 enc = kCFStringEncodingMacMongolian ;
236 break ;
237 case wxFONTENCODING_MACETHIOPIC :
238 enc = kCFStringEncodingMacEthiopic ;
239 break ;
240 case wxFONTENCODING_MACCENTRALEUR :
241 enc = kCFStringEncodingMacCentralEurRoman ;
242 break ;
243 case wxFONTENCODING_MACVIATNAMESE :
244 enc = kCFStringEncodingMacVietnamese ;
245 break ;
246 case wxFONTENCODING_MACARABICEXT :
247 enc = kCFStringEncodingMacExtArabic ;
248 break ;
249 case wxFONTENCODING_MACSYMBOL :
250 enc = kCFStringEncodingMacSymbol ;
251 break ;
252 case wxFONTENCODING_MACDINGBATS :
253 enc = kCFStringEncodingMacDingbats ;
254 break ;
255 case wxFONTENCODING_MACTURKISH :
256 enc = kCFStringEncodingMacTurkish ;
257 break ;
258 case wxFONTENCODING_MACCROATIAN :
259 enc = kCFStringEncodingMacCroatian ;
260 break ;
261 case wxFONTENCODING_MACICELANDIC :
262 enc = kCFStringEncodingMacIcelandic ;
263 break ;
264 case wxFONTENCODING_MACROMANIAN :
265 enc = kCFStringEncodingMacRomanian ;
266 break ;
267 case wxFONTENCODING_MACCELTIC :
268 enc = kCFStringEncodingMacCeltic ;
269 break ;
270 case wxFONTENCODING_MACGAELIC :
271 enc = kCFStringEncodingMacGaelic ;
272 break ;
273 /* CFString is known to support this back to the original CarbonLib */
274 /* http://developer.apple.com/samplecode/CarbonMDEF/listing2.html */
275 case wxFONTENCODING_MACKEYBOARD :
276 /* We don't wish to pollute the namespace too much, even though we're a private header. */
277 /* The constant is well-defined as 41 and is not expected to change. */
278 enc = 41 /*kTextEncodingMacKeyboardGlyphs*/ ;
279 break ;
280
281 default :
282 // because gcc is picky
283 break ;
284 }
285
286 return enc ;
287}
288
289
290class wxMBConv_cf : public wxMBConv
291{
292public:
293 wxMBConv_cf()
294 {
295 Init(CFStringGetSystemEncoding()) ;
296 }
297
298 wxMBConv_cf(const wxMBConv_cf& conv)
299 {
300 m_encoding = conv.m_encoding;
301 }
302
303#if wxUSE_FONTMAP
304 wxMBConv_cf(const char* name)
305 {
306 Init( wxCFStringEncFromFontEnc(wxFontMapperBase::Get()->CharsetToEncoding(name, false) ) ) ;
307 }
308#endif
309
310 wxMBConv_cf(wxFontEncoding encoding)
311 {
312 Init( wxCFStringEncFromFontEnc(encoding) );
313 }
314
315 virtual ~wxMBConv_cf()
316 {
317 }
318
319 void Init( CFStringEncoding encoding)
320 {
321 m_encoding = encoding ;
322 }
323
324 virtual size_t ToWChar(wchar_t * dst, size_t dstSize, const char * src, size_t srcSize = wxNO_LEN) const;
325 virtual size_t FromWChar(char *dst, size_t dstSize, const wchar_t *src, size_t srcSize = wxNO_LEN) const;
326
327 virtual wxMBConv *Clone() const { return new wxMBConv_cf(*this); }
328
329 bool IsOk() const
330 {
331 return m_encoding != kCFStringEncodingInvalidId &&
332 CFStringIsEncodingAvailable(m_encoding);
333 }
334
335private:
336 CFStringEncoding m_encoding ;
337};
338