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