1 /////////////////////////////////////////////////////////////////////////////
2 // Name: include/wx/mac/corefoundation/strconv_cf.h
3 // Purpose: Unicode conversion classes
4 // Author: David Elliott, Ryan Norton
8 // Copyright: (c) 2004 Ryan Norton
9 // (c) 2007 David Elliott
10 // Licence: wxWindows licence
11 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/strconv.h"
15 #include <CoreFoundation/CFString.h>
16 #include <CoreFoundation/CFStringEncodingExt.h>
18 // ============================================================================
19 // CoreFoundation conversion classes
20 // ============================================================================
22 inline CFStringEncoding
wxCFStringEncFromFontEnc(wxFontEncoding encoding
)
24 CFStringEncoding enc
= kCFStringEncodingInvalidId
;
28 case wxFONTENCODING_DEFAULT
:
29 enc
= CFStringGetSystemEncoding();
32 case wxFONTENCODING_ISO8859_1
:
33 enc
= kCFStringEncodingISOLatin1
;
35 case wxFONTENCODING_ISO8859_2
:
36 enc
= kCFStringEncodingISOLatin2
;
38 case wxFONTENCODING_ISO8859_3
:
39 enc
= kCFStringEncodingISOLatin3
;
41 case wxFONTENCODING_ISO8859_4
:
42 enc
= kCFStringEncodingISOLatin4
;
44 case wxFONTENCODING_ISO8859_5
:
45 enc
= kCFStringEncodingISOLatinCyrillic
;
47 case wxFONTENCODING_ISO8859_6
:
48 enc
= kCFStringEncodingISOLatinArabic
;
50 case wxFONTENCODING_ISO8859_7
:
51 enc
= kCFStringEncodingISOLatinGreek
;
53 case wxFONTENCODING_ISO8859_8
:
54 enc
= kCFStringEncodingISOLatinHebrew
;
56 case wxFONTENCODING_ISO8859_9
:
57 enc
= kCFStringEncodingISOLatin5
;
59 case wxFONTENCODING_ISO8859_10
:
60 enc
= kCFStringEncodingISOLatin6
;
62 case wxFONTENCODING_ISO8859_11
:
63 enc
= kCFStringEncodingISOLatinThai
;
65 case wxFONTENCODING_ISO8859_13
:
66 enc
= kCFStringEncodingISOLatin7
;
68 case wxFONTENCODING_ISO8859_14
:
69 enc
= kCFStringEncodingISOLatin8
;
71 case wxFONTENCODING_ISO8859_15
:
72 enc
= kCFStringEncodingISOLatin9
;
75 case wxFONTENCODING_KOI8
:
76 enc
= kCFStringEncodingKOI8_R
;
78 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
79 enc
= kCFStringEncodingDOSRussian
;
82 // case wxFONTENCODING_BULGARIAN :
86 case wxFONTENCODING_CP437
:
87 enc
= kCFStringEncodingDOSLatinUS
;
89 case wxFONTENCODING_CP850
:
90 enc
= kCFStringEncodingDOSLatin1
;
92 case wxFONTENCODING_CP852
:
93 enc
= kCFStringEncodingDOSLatin2
;
95 case wxFONTENCODING_CP855
:
96 enc
= kCFStringEncodingDOSCyrillic
;
98 case wxFONTENCODING_CP866
:
99 enc
= kCFStringEncodingDOSRussian
;
101 case wxFONTENCODING_CP874
:
102 enc
= kCFStringEncodingDOSThai
;
104 case wxFONTENCODING_CP932
:
105 enc
= kCFStringEncodingDOSJapanese
;
107 case wxFONTENCODING_CP936
:
108 enc
= kCFStringEncodingDOSChineseSimplif
;
110 case wxFONTENCODING_CP949
:
111 enc
= kCFStringEncodingDOSKorean
;
113 case wxFONTENCODING_CP950
:
114 enc
= kCFStringEncodingDOSChineseTrad
;
116 case wxFONTENCODING_CP1250
:
117 enc
= kCFStringEncodingWindowsLatin2
;
119 case wxFONTENCODING_CP1251
:
120 enc
= kCFStringEncodingWindowsCyrillic
;
122 case wxFONTENCODING_CP1252
:
123 enc
= kCFStringEncodingWindowsLatin1
;
125 case wxFONTENCODING_CP1253
:
126 enc
= kCFStringEncodingWindowsGreek
;
128 case wxFONTENCODING_CP1254
:
129 enc
= kCFStringEncodingWindowsLatin5
;
131 case wxFONTENCODING_CP1255
:
132 enc
= kCFStringEncodingWindowsHebrew
;
134 case wxFONTENCODING_CP1256
:
135 enc
= kCFStringEncodingWindowsArabic
;
137 case wxFONTENCODING_CP1257
:
138 enc
= kCFStringEncodingWindowsBalticRim
;
140 // This only really encodes to UTF7 (if that) evidently
141 // case wxFONTENCODING_UTF7 :
142 // enc = kCFStringEncodingNonLossyASCII ;
144 case wxFONTENCODING_UTF8
:
145 enc
= kCFStringEncodingUTF8
;
147 case wxFONTENCODING_EUC_JP
:
148 enc
= kCFStringEncodingEUC_JP
;
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 ;
156 case wxFONTENCODING_MACROMAN
:
157 enc
= kCFStringEncodingMacRoman
;
159 case wxFONTENCODING_MACJAPANESE
:
160 enc
= kCFStringEncodingMacJapanese
;
162 case wxFONTENCODING_MACCHINESETRAD
:
163 enc
= kCFStringEncodingMacChineseTrad
;
165 case wxFONTENCODING_MACKOREAN
:
166 enc
= kCFStringEncodingMacKorean
;
168 case wxFONTENCODING_MACARABIC
:
169 enc
= kCFStringEncodingMacArabic
;
171 case wxFONTENCODING_MACHEBREW
:
172 enc
= kCFStringEncodingMacHebrew
;
174 case wxFONTENCODING_MACGREEK
:
175 enc
= kCFStringEncodingMacGreek
;
177 case wxFONTENCODING_MACCYRILLIC
:
178 enc
= kCFStringEncodingMacCyrillic
;
180 case wxFONTENCODING_MACDEVANAGARI
:
181 enc
= kCFStringEncodingMacDevanagari
;
183 case wxFONTENCODING_MACGURMUKHI
:
184 enc
= kCFStringEncodingMacGurmukhi
;
186 case wxFONTENCODING_MACGUJARATI
:
187 enc
= kCFStringEncodingMacGujarati
;
189 case wxFONTENCODING_MACORIYA
:
190 enc
= kCFStringEncodingMacOriya
;
192 case wxFONTENCODING_MACBENGALI
:
193 enc
= kCFStringEncodingMacBengali
;
195 case wxFONTENCODING_MACTAMIL
:
196 enc
= kCFStringEncodingMacTamil
;
198 case wxFONTENCODING_MACTELUGU
:
199 enc
= kCFStringEncodingMacTelugu
;
201 case wxFONTENCODING_MACKANNADA
:
202 enc
= kCFStringEncodingMacKannada
;
204 case wxFONTENCODING_MACMALAJALAM
:
205 enc
= kCFStringEncodingMacMalayalam
;
207 case wxFONTENCODING_MACSINHALESE
:
208 enc
= kCFStringEncodingMacSinhalese
;
210 case wxFONTENCODING_MACBURMESE
:
211 enc
= kCFStringEncodingMacBurmese
;
213 case wxFONTENCODING_MACKHMER
:
214 enc
= kCFStringEncodingMacKhmer
;
216 case wxFONTENCODING_MACTHAI
:
217 enc
= kCFStringEncodingMacThai
;
219 case wxFONTENCODING_MACLAOTIAN
:
220 enc
= kCFStringEncodingMacLaotian
;
222 case wxFONTENCODING_MACGEORGIAN
:
223 enc
= kCFStringEncodingMacGeorgian
;
225 case wxFONTENCODING_MACARMENIAN
:
226 enc
= kCFStringEncodingMacArmenian
;
228 case wxFONTENCODING_MACCHINESESIMP
:
229 enc
= kCFStringEncodingMacChineseSimp
;
231 case wxFONTENCODING_MACTIBETAN
:
232 enc
= kCFStringEncodingMacTibetan
;
234 case wxFONTENCODING_MACMONGOLIAN
:
235 enc
= kCFStringEncodingMacMongolian
;
237 case wxFONTENCODING_MACETHIOPIC
:
238 enc
= kCFStringEncodingMacEthiopic
;
240 case wxFONTENCODING_MACCENTRALEUR
:
241 enc
= kCFStringEncodingMacCentralEurRoman
;
243 case wxFONTENCODING_MACVIATNAMESE
:
244 enc
= kCFStringEncodingMacVietnamese
;
246 case wxFONTENCODING_MACARABICEXT
:
247 enc
= kCFStringEncodingMacExtArabic
;
249 case wxFONTENCODING_MACSYMBOL
:
250 enc
= kCFStringEncodingMacSymbol
;
252 case wxFONTENCODING_MACDINGBATS
:
253 enc
= kCFStringEncodingMacDingbats
;
255 case wxFONTENCODING_MACTURKISH
:
256 enc
= kCFStringEncodingMacTurkish
;
258 case wxFONTENCODING_MACCROATIAN
:
259 enc
= kCFStringEncodingMacCroatian
;
261 case wxFONTENCODING_MACICELANDIC
:
262 enc
= kCFStringEncodingMacIcelandic
;
264 case wxFONTENCODING_MACROMANIAN
:
265 enc
= kCFStringEncodingMacRomanian
;
267 case wxFONTENCODING_MACCELTIC
:
268 enc
= kCFStringEncodingMacCeltic
;
270 case wxFONTENCODING_MACGAELIC
:
271 enc
= kCFStringEncodingMacGaelic
;
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*/ ;
282 // because gcc is picky
290 class wxMBConv_cf
: public wxMBConv
295 Init(CFStringGetSystemEncoding()) ;
298 wxMBConv_cf(const wxMBConv_cf
& conv
)
300 m_encoding
= conv
.m_encoding
;
304 wxMBConv_cf(const char* name
)
306 Init( wxCFStringEncFromFontEnc(wxFontMapperBase::Get()->CharsetToEncoding(name
, false) ) ) ;
310 wxMBConv_cf(wxFontEncoding encoding
)
312 Init( wxCFStringEncFromFontEnc(encoding
) );
315 virtual ~wxMBConv_cf()
319 void Init( CFStringEncoding encoding
)
321 m_encoding
= encoding
;
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;
327 virtual wxMBConv
*Clone() const { return new wxMBConv_cf(*this); }
331 return m_encoding
!= kCFStringEncodingInvalidId
&&
332 CFStringIsEncodingAvailable(m_encoding
);
336 CFStringEncoding m_encoding
;