1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/osx/core/private/strconv_cf.h
3 // Purpose: Unicode conversion classes
4 // Author: David Elliott, Ryan Norton
7 // Copyright: (c) 2004 Ryan Norton
8 // (c) 2007 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/strconv.h"
14 #include <CoreFoundation/CFString.h>
15 #include <CoreFoundation/CFStringEncodingExt.h>
17 // ============================================================================
18 // CoreFoundation conversion classes
19 // ============================================================================
21 inline CFStringEncoding
wxCFStringEncFromFontEnc(wxFontEncoding encoding
)
23 CFStringEncoding enc
= kCFStringEncodingInvalidId
;
27 case wxFONTENCODING_DEFAULT
:
28 enc
= CFStringGetSystemEncoding();
31 case wxFONTENCODING_ISO8859_1
:
32 enc
= kCFStringEncodingISOLatin1
;
34 case wxFONTENCODING_ISO8859_2
:
35 enc
= kCFStringEncodingISOLatin2
;
37 case wxFONTENCODING_ISO8859_3
:
38 enc
= kCFStringEncodingISOLatin3
;
40 case wxFONTENCODING_ISO8859_4
:
41 enc
= kCFStringEncodingISOLatin4
;
43 case wxFONTENCODING_ISO8859_5
:
44 enc
= kCFStringEncodingISOLatinCyrillic
;
46 case wxFONTENCODING_ISO8859_6
:
47 enc
= kCFStringEncodingISOLatinArabic
;
49 case wxFONTENCODING_ISO8859_7
:
50 enc
= kCFStringEncodingISOLatinGreek
;
52 case wxFONTENCODING_ISO8859_8
:
53 enc
= kCFStringEncodingISOLatinHebrew
;
55 case wxFONTENCODING_ISO8859_9
:
56 enc
= kCFStringEncodingISOLatin5
;
58 case wxFONTENCODING_ISO8859_10
:
59 enc
= kCFStringEncodingISOLatin6
;
61 case wxFONTENCODING_ISO8859_11
:
62 enc
= kCFStringEncodingISOLatinThai
;
64 case wxFONTENCODING_ISO8859_13
:
65 enc
= kCFStringEncodingISOLatin7
;
67 case wxFONTENCODING_ISO8859_14
:
68 enc
= kCFStringEncodingISOLatin8
;
70 case wxFONTENCODING_ISO8859_15
:
71 enc
= kCFStringEncodingISOLatin9
;
74 case wxFONTENCODING_KOI8
:
75 enc
= kCFStringEncodingKOI8_R
;
77 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
78 enc
= kCFStringEncodingDOSRussian
;
81 // case wxFONTENCODING_BULGARIAN :
85 case wxFONTENCODING_CP437
:
86 enc
= kCFStringEncodingDOSLatinUS
;
88 case wxFONTENCODING_CP850
:
89 enc
= kCFStringEncodingDOSLatin1
;
91 case wxFONTENCODING_CP852
:
92 enc
= kCFStringEncodingDOSLatin2
;
94 case wxFONTENCODING_CP855
:
95 enc
= kCFStringEncodingDOSCyrillic
;
97 case wxFONTENCODING_CP866
:
98 enc
= kCFStringEncodingDOSRussian
;
100 case wxFONTENCODING_CP874
:
101 enc
= kCFStringEncodingDOSThai
;
103 case wxFONTENCODING_CP932
:
104 enc
= kCFStringEncodingDOSJapanese
;
106 case wxFONTENCODING_CP936
:
107 enc
= kCFStringEncodingDOSChineseSimplif
;
109 case wxFONTENCODING_CP949
:
110 enc
= kCFStringEncodingDOSKorean
;
112 case wxFONTENCODING_CP950
:
113 enc
= kCFStringEncodingDOSChineseTrad
;
115 case wxFONTENCODING_CP1250
:
116 enc
= kCFStringEncodingWindowsLatin2
;
118 case wxFONTENCODING_CP1251
:
119 enc
= kCFStringEncodingWindowsCyrillic
;
121 case wxFONTENCODING_CP1252
:
122 enc
= kCFStringEncodingWindowsLatin1
;
124 case wxFONTENCODING_CP1253
:
125 enc
= kCFStringEncodingWindowsGreek
;
127 case wxFONTENCODING_CP1254
:
128 enc
= kCFStringEncodingWindowsLatin5
;
130 case wxFONTENCODING_CP1255
:
131 enc
= kCFStringEncodingWindowsHebrew
;
133 case wxFONTENCODING_CP1256
:
134 enc
= kCFStringEncodingWindowsArabic
;
136 case wxFONTENCODING_CP1257
:
137 enc
= kCFStringEncodingWindowsBalticRim
;
139 // This only really encodes to UTF7 (if that) evidently
140 // case wxFONTENCODING_UTF7 :
141 // enc = kCFStringEncodingNonLossyASCII ;
143 case wxFONTENCODING_UTF8
:
144 enc
= kCFStringEncodingUTF8
;
146 case wxFONTENCODING_EUC_JP
:
147 enc
= kCFStringEncodingEUC_JP
;
149 /* Don't support conversion to/from UTF16 as wxWidgets can do this better.
150 * In particular, ToWChar would fail miserably using strlen on an input UTF16.
151 case wxFONTENCODING_UTF16 :
152 enc = kCFStringEncodingUnicode ;
155 case wxFONTENCODING_MACROMAN
:
156 enc
= kCFStringEncodingMacRoman
;
158 case wxFONTENCODING_MACJAPANESE
:
159 enc
= kCFStringEncodingMacJapanese
;
161 case wxFONTENCODING_MACCHINESETRAD
:
162 enc
= kCFStringEncodingMacChineseTrad
;
164 case wxFONTENCODING_MACKOREAN
:
165 enc
= kCFStringEncodingMacKorean
;
167 case wxFONTENCODING_MACARABIC
:
168 enc
= kCFStringEncodingMacArabic
;
170 case wxFONTENCODING_MACHEBREW
:
171 enc
= kCFStringEncodingMacHebrew
;
173 case wxFONTENCODING_MACGREEK
:
174 enc
= kCFStringEncodingMacGreek
;
176 case wxFONTENCODING_MACCYRILLIC
:
177 enc
= kCFStringEncodingMacCyrillic
;
179 case wxFONTENCODING_MACDEVANAGARI
:
180 enc
= kCFStringEncodingMacDevanagari
;
182 case wxFONTENCODING_MACGURMUKHI
:
183 enc
= kCFStringEncodingMacGurmukhi
;
185 case wxFONTENCODING_MACGUJARATI
:
186 enc
= kCFStringEncodingMacGujarati
;
188 case wxFONTENCODING_MACORIYA
:
189 enc
= kCFStringEncodingMacOriya
;
191 case wxFONTENCODING_MACBENGALI
:
192 enc
= kCFStringEncodingMacBengali
;
194 case wxFONTENCODING_MACTAMIL
:
195 enc
= kCFStringEncodingMacTamil
;
197 case wxFONTENCODING_MACTELUGU
:
198 enc
= kCFStringEncodingMacTelugu
;
200 case wxFONTENCODING_MACKANNADA
:
201 enc
= kCFStringEncodingMacKannada
;
203 case wxFONTENCODING_MACMALAJALAM
:
204 enc
= kCFStringEncodingMacMalayalam
;
206 case wxFONTENCODING_MACSINHALESE
:
207 enc
= kCFStringEncodingMacSinhalese
;
209 case wxFONTENCODING_MACBURMESE
:
210 enc
= kCFStringEncodingMacBurmese
;
212 case wxFONTENCODING_MACKHMER
:
213 enc
= kCFStringEncodingMacKhmer
;
215 case wxFONTENCODING_MACTHAI
:
216 enc
= kCFStringEncodingMacThai
;
218 case wxFONTENCODING_MACLAOTIAN
:
219 enc
= kCFStringEncodingMacLaotian
;
221 case wxFONTENCODING_MACGEORGIAN
:
222 enc
= kCFStringEncodingMacGeorgian
;
224 case wxFONTENCODING_MACARMENIAN
:
225 enc
= kCFStringEncodingMacArmenian
;
227 case wxFONTENCODING_MACCHINESESIMP
:
228 enc
= kCFStringEncodingMacChineseSimp
;
230 case wxFONTENCODING_MACTIBETAN
:
231 enc
= kCFStringEncodingMacTibetan
;
233 case wxFONTENCODING_MACMONGOLIAN
:
234 enc
= kCFStringEncodingMacMongolian
;
236 case wxFONTENCODING_MACETHIOPIC
:
237 enc
= kCFStringEncodingMacEthiopic
;
239 case wxFONTENCODING_MACCENTRALEUR
:
240 enc
= kCFStringEncodingMacCentralEurRoman
;
242 case wxFONTENCODING_MACVIATNAMESE
:
243 enc
= kCFStringEncodingMacVietnamese
;
245 case wxFONTENCODING_MACARABICEXT
:
246 enc
= kCFStringEncodingMacExtArabic
;
248 case wxFONTENCODING_MACSYMBOL
:
249 enc
= kCFStringEncodingMacSymbol
;
251 case wxFONTENCODING_MACDINGBATS
:
252 enc
= kCFStringEncodingMacDingbats
;
254 case wxFONTENCODING_MACTURKISH
:
255 enc
= kCFStringEncodingMacTurkish
;
257 case wxFONTENCODING_MACCROATIAN
:
258 enc
= kCFStringEncodingMacCroatian
;
260 case wxFONTENCODING_MACICELANDIC
:
261 enc
= kCFStringEncodingMacIcelandic
;
263 case wxFONTENCODING_MACROMANIAN
:
264 enc
= kCFStringEncodingMacRomanian
;
266 case wxFONTENCODING_MACCELTIC
:
267 enc
= kCFStringEncodingMacCeltic
;
269 case wxFONTENCODING_MACGAELIC
:
270 enc
= kCFStringEncodingMacGaelic
;
272 /* CFString is known to support this back to the original CarbonLib */
273 /* http://developer.apple.com/samplecode/CarbonMDEF/listing2.html */
274 case wxFONTENCODING_MACKEYBOARD
:
275 /* We don't wish to pollute the namespace too much, even though we're a private header. */
276 /* The constant is well-defined as 41 and is not expected to change. */
277 enc
= 41 /*kTextEncodingMacKeyboardGlyphs*/ ;
281 // because gcc is picky
289 class wxMBConv_cf
: public wxMBConv
294 Init(CFStringGetSystemEncoding()) ;
297 wxMBConv_cf(const wxMBConv_cf
& conv
) : wxMBConv()
299 m_encoding
= conv
.m_encoding
;
303 wxMBConv_cf(const char* name
)
305 Init( wxCFStringEncFromFontEnc(wxFontMapperBase::Get()->CharsetToEncoding(name
, false) ) ) ;
309 wxMBConv_cf(wxFontEncoding encoding
)
311 Init( wxCFStringEncFromFontEnc(encoding
) );
314 virtual ~wxMBConv_cf()
318 void Init( CFStringEncoding encoding
)
320 m_encoding
= encoding
;
323 virtual size_t ToWChar(wchar_t * dst
, size_t dstSize
, const char * src
, size_t srcSize
= wxNO_LEN
) const;
324 virtual size_t FromWChar(char *dst
, size_t dstSize
, const wchar_t *src
, size_t srcSize
= wxNO_LEN
) const;
326 virtual wxMBConv
*Clone() const { return new wxMBConv_cf(*this); }
330 return m_encoding
!= kCFStringEncodingInvalidId
&&
331 CFStringIsEncodingAvailable(m_encoding
);
335 CFStringEncoding m_encoding
;