]>
Commit | Line | Data |
---|---|---|
489468fe | 1 | ///////////////////////////////////////////////////////////////////////////// |
524c47aa | 2 | // Name: src/osx/corefoundation/cfstring.cpp |
489468fe SC |
3 | // Purpose: wxCFStringHolder and other string functions |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
524c47aa | 6 | // Created: 2004-10-29 (from code in src/osx/carbon/utils.cpp) |
489468fe SC |
7 | // RCS-ID: $Id$ |
8 | // Copyright: (c) Stefan Csomor | |
9 | // Licence: wxWindows licence | |
10 | // Usage: Darwin (base library) | |
11 | ///////////////////////////////////////////////////////////////////////////// | |
12 | ||
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/string.h" | |
17 | #include "wx/intl.h" | |
18 | #if wxUSE_GUI | |
19 | #include "wx/font.h" | |
20 | #endif | |
21 | #endif | |
22 | ||
c8ef3d55 | 23 | #include "wx/osx/core/cfstring.h" |
489468fe SC |
24 | |
25 | #include <CoreFoundation/CoreFoundation.h> | |
26 | ||
f5f17248 | 27 | |
489468fe SC |
28 | void wxMacConvertNewlines13To10( char * data ) |
29 | { | |
30 | char * buf = data ; | |
31 | while( (buf=strchr(buf,0x0d)) != NULL ) | |
32 | { | |
33 | *buf = 0x0a ; | |
34 | buf++ ; | |
35 | } | |
36 | } | |
37 | ||
38 | void wxMacConvertNewlines10To13( char * data ) | |
39 | { | |
40 | char * buf = data ; | |
41 | while( (buf=strchr(buf,0x0a)) != NULL ) | |
42 | { | |
43 | *buf = 0x0d ; | |
44 | buf++ ; | |
45 | } | |
46 | } | |
47 | ||
48 | const wxString sCR((wxChar)13); | |
49 | const wxString sLF((wxChar)10); | |
50 | ||
51 | void wxMacConvertNewlines13To10( wxString * data ) | |
52 | { | |
53 | data->Replace( sCR,sLF); | |
54 | } | |
55 | ||
56 | void wxMacConvertNewlines10To13( wxString * data ) | |
57 | { | |
58 | data->Replace( sLF,sCR); | |
59 | } | |
60 | ||
61 | wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) | |
62 | { | |
63 | CFStringEncoding enc = 0 ; | |
64 | if ( encoding == wxFONTENCODING_DEFAULT ) | |
65 | { | |
66 | #if wxUSE_GUI | |
67 | encoding = wxFont::GetDefaultEncoding() ; | |
68 | #else | |
69 | encoding = wxFONTENCODING_SYSTEM; // to be set below | |
70 | #endif | |
71 | } | |
72 | ||
73 | if ( encoding == wxFONTENCODING_SYSTEM ) | |
74 | { | |
75 | enc = CFStringGetSystemEncoding(); | |
76 | } | |
77 | ||
78 | switch( encoding) | |
79 | { | |
80 | case wxFONTENCODING_ISO8859_1 : | |
81 | enc = kCFStringEncodingISOLatin1 ; | |
82 | break ; | |
83 | case wxFONTENCODING_ISO8859_2 : | |
84 | enc = kCFStringEncodingISOLatin2; | |
85 | break ; | |
86 | case wxFONTENCODING_ISO8859_3 : | |
87 | enc = kCFStringEncodingISOLatin3 ; | |
88 | break ; | |
89 | case wxFONTENCODING_ISO8859_4 : | |
90 | enc = kCFStringEncodingISOLatin4; | |
91 | break ; | |
92 | case wxFONTENCODING_ISO8859_5 : | |
93 | enc = kCFStringEncodingISOLatinCyrillic; | |
94 | break ; | |
95 | case wxFONTENCODING_ISO8859_6 : | |
96 | enc = kCFStringEncodingISOLatinArabic; | |
97 | break ; | |
98 | case wxFONTENCODING_ISO8859_7 : | |
99 | enc = kCFStringEncodingISOLatinGreek; | |
100 | break ; | |
101 | case wxFONTENCODING_ISO8859_8 : | |
102 | enc = kCFStringEncodingISOLatinHebrew; | |
103 | break ; | |
104 | case wxFONTENCODING_ISO8859_9 : | |
105 | enc = kCFStringEncodingISOLatin5; | |
106 | break ; | |
107 | case wxFONTENCODING_ISO8859_10 : | |
108 | enc = kCFStringEncodingISOLatin6; | |
109 | break ; | |
110 | case wxFONTENCODING_ISO8859_13 : | |
111 | enc = kCFStringEncodingISOLatin7; | |
112 | break ; | |
113 | case wxFONTENCODING_ISO8859_14 : | |
114 | enc = kCFStringEncodingISOLatin8; | |
115 | break ; | |
116 | case wxFONTENCODING_ISO8859_15 : | |
117 | enc = kCFStringEncodingISOLatin9; | |
118 | break ; | |
119 | ||
120 | case wxFONTENCODING_KOI8 : | |
121 | enc = kCFStringEncodingKOI8_R; | |
122 | break ; | |
123 | case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866 | |
124 | enc = kCFStringEncodingDOSRussian; | |
125 | break ; | |
126 | /* | |
127 | case wxFONTENCODING_BULGARIAN : | |
128 | enc = ; | |
129 | break ; | |
130 | */ | |
131 | case wxFONTENCODING_CP437 : | |
132 | enc =kCFStringEncodingDOSLatinUS ; | |
133 | break ; | |
134 | case wxFONTENCODING_CP850 : | |
135 | enc = kCFStringEncodingDOSLatin1; | |
136 | break ; | |
137 | case wxFONTENCODING_CP852 : | |
138 | enc = kCFStringEncodingDOSLatin2; | |
139 | break ; | |
140 | case wxFONTENCODING_CP855 : | |
141 | enc = kCFStringEncodingDOSCyrillic; | |
142 | break ; | |
143 | case wxFONTENCODING_CP866 : | |
144 | enc =kCFStringEncodingDOSRussian ; | |
145 | break ; | |
146 | case wxFONTENCODING_CP874 : | |
147 | enc = kCFStringEncodingDOSThai; | |
148 | break ; | |
149 | case wxFONTENCODING_CP932 : | |
150 | enc = kCFStringEncodingDOSJapanese; | |
151 | break ; | |
152 | case wxFONTENCODING_CP936 : | |
153 | enc = kCFStringEncodingDOSChineseSimplif ; | |
154 | break ; | |
155 | case wxFONTENCODING_CP949 : | |
156 | enc = kCFStringEncodingDOSKorean; | |
157 | break ; | |
158 | case wxFONTENCODING_CP950 : | |
159 | enc = kCFStringEncodingDOSChineseTrad; | |
160 | break ; | |
161 | ||
162 | case wxFONTENCODING_CP1250 : | |
163 | enc = kCFStringEncodingWindowsLatin2; | |
164 | break ; | |
165 | case wxFONTENCODING_CP1251 : | |
166 | enc =kCFStringEncodingWindowsCyrillic ; | |
167 | break ; | |
168 | case wxFONTENCODING_CP1252 : | |
169 | enc =kCFStringEncodingWindowsLatin1 ; | |
170 | break ; | |
171 | case wxFONTENCODING_CP1253 : | |
172 | enc = kCFStringEncodingWindowsGreek; | |
173 | break ; | |
174 | case wxFONTENCODING_CP1254 : | |
175 | enc = kCFStringEncodingWindowsLatin5; | |
176 | break ; | |
177 | case wxFONTENCODING_CP1255 : | |
178 | enc =kCFStringEncodingWindowsHebrew ; | |
179 | break ; | |
180 | case wxFONTENCODING_CP1256 : | |
181 | enc =kCFStringEncodingWindowsArabic ; | |
182 | break ; | |
183 | case wxFONTENCODING_CP1257 : | |
184 | enc = kCFStringEncodingWindowsBalticRim; | |
185 | break ; | |
186 | #if 0 | |
187 | case wxFONTENCODING_UTF7 : | |
188 | enc = CreateTextEncoding(kCFStringEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
489468fe | 189 | break ; |
65391c8f | 190 | #endif |
489468fe SC |
191 | case wxFONTENCODING_UTF8 : |
192 | enc = kCFStringEncodingUTF8; | |
193 | break ; | |
194 | case wxFONTENCODING_EUC_JP : | |
195 | enc = kCFStringEncodingEUC_JP; | |
196 | break ; | |
197 | case wxFONTENCODING_UTF16BE : | |
198 | enc = kCFStringEncodingUTF16BE; | |
199 | break ; | |
200 | case wxFONTENCODING_UTF16LE : | |
201 | enc = kCFStringEncodingUTF16LE; | |
202 | break ; | |
203 | case wxFONTENCODING_UTF32BE : | |
204 | enc = kCFStringEncodingUTF32BE; | |
205 | break ; | |
206 | case wxFONTENCODING_UTF32LE : | |
207 | enc = kCFStringEncodingUTF32LE; | |
208 | break ; | |
209 | ||
210 | case wxFONTENCODING_MACROMAN : | |
211 | enc = kCFStringEncodingMacRoman ; | |
212 | break ; | |
213 | case wxFONTENCODING_MACJAPANESE : | |
214 | enc = kCFStringEncodingMacJapanese ; | |
215 | break ; | |
216 | case wxFONTENCODING_MACCHINESETRAD : | |
217 | enc = kCFStringEncodingMacChineseTrad ; | |
218 | break ; | |
219 | case wxFONTENCODING_MACKOREAN : | |
220 | enc = kCFStringEncodingMacKorean ; | |
221 | break ; | |
222 | case wxFONTENCODING_MACARABIC : | |
223 | enc = kCFStringEncodingMacArabic ; | |
224 | break ; | |
225 | case wxFONTENCODING_MACHEBREW : | |
226 | enc = kCFStringEncodingMacHebrew ; | |
227 | break ; | |
228 | case wxFONTENCODING_MACGREEK : | |
229 | enc = kCFStringEncodingMacGreek ; | |
230 | break ; | |
231 | case wxFONTENCODING_MACCYRILLIC : | |
232 | enc = kCFStringEncodingMacCyrillic ; | |
233 | break ; | |
234 | case wxFONTENCODING_MACDEVANAGARI : | |
235 | enc = kCFStringEncodingMacDevanagari ; | |
236 | break ; | |
237 | case wxFONTENCODING_MACGURMUKHI : | |
238 | enc = kCFStringEncodingMacGurmukhi ; | |
239 | break ; | |
240 | case wxFONTENCODING_MACGUJARATI : | |
241 | enc = kCFStringEncodingMacGujarati ; | |
242 | break ; | |
243 | case wxFONTENCODING_MACORIYA : | |
244 | enc = kCFStringEncodingMacOriya ; | |
245 | break ; | |
246 | case wxFONTENCODING_MACBENGALI : | |
247 | enc = kCFStringEncodingMacBengali ; | |
248 | break ; | |
249 | case wxFONTENCODING_MACTAMIL : | |
250 | enc = kCFStringEncodingMacTamil ; | |
251 | break ; | |
252 | case wxFONTENCODING_MACTELUGU : | |
253 | enc = kCFStringEncodingMacTelugu ; | |
254 | break ; | |
255 | case wxFONTENCODING_MACKANNADA : | |
256 | enc = kCFStringEncodingMacKannada ; | |
257 | break ; | |
258 | case wxFONTENCODING_MACMALAJALAM : | |
259 | enc = kCFStringEncodingMacMalayalam ; | |
260 | break ; | |
261 | case wxFONTENCODING_MACSINHALESE : | |
262 | enc = kCFStringEncodingMacSinhalese ; | |
263 | break ; | |
264 | case wxFONTENCODING_MACBURMESE : | |
265 | enc = kCFStringEncodingMacBurmese ; | |
266 | break ; | |
267 | case wxFONTENCODING_MACKHMER : | |
268 | enc = kCFStringEncodingMacKhmer ; | |
269 | break ; | |
270 | case wxFONTENCODING_MACTHAI : | |
271 | enc = kCFStringEncodingMacThai ; | |
272 | break ; | |
273 | case wxFONTENCODING_MACLAOTIAN : | |
274 | enc = kCFStringEncodingMacLaotian ; | |
275 | break ; | |
276 | case wxFONTENCODING_MACGEORGIAN : | |
277 | enc = kCFStringEncodingMacGeorgian ; | |
278 | break ; | |
279 | case wxFONTENCODING_MACARMENIAN : | |
280 | enc = kCFStringEncodingMacArmenian ; | |
281 | break ; | |
282 | case wxFONTENCODING_MACCHINESESIMP : | |
283 | enc = kCFStringEncodingMacChineseSimp ; | |
284 | break ; | |
285 | case wxFONTENCODING_MACTIBETAN : | |
286 | enc = kCFStringEncodingMacTibetan ; | |
287 | break ; | |
288 | case wxFONTENCODING_MACMONGOLIAN : | |
289 | enc = kCFStringEncodingMacMongolian ; | |
290 | break ; | |
291 | case wxFONTENCODING_MACETHIOPIC : | |
292 | enc = kCFStringEncodingMacEthiopic ; | |
293 | break ; | |
294 | case wxFONTENCODING_MACCENTRALEUR : | |
295 | enc = kCFStringEncodingMacCentralEurRoman ; | |
296 | break ; | |
297 | case wxFONTENCODING_MACVIATNAMESE : | |
298 | enc = kCFStringEncodingMacVietnamese ; | |
299 | break ; | |
300 | case wxFONTENCODING_MACARABICEXT : | |
301 | enc = kCFStringEncodingMacExtArabic ; | |
302 | break ; | |
303 | case wxFONTENCODING_MACSYMBOL : | |
304 | enc = kCFStringEncodingMacSymbol ; | |
305 | break ; | |
306 | case wxFONTENCODING_MACDINGBATS : | |
307 | enc = kCFStringEncodingMacDingbats ; | |
308 | break ; | |
309 | case wxFONTENCODING_MACTURKISH : | |
310 | enc = kCFStringEncodingMacTurkish ; | |
311 | break ; | |
312 | case wxFONTENCODING_MACCROATIAN : | |
313 | enc = kCFStringEncodingMacCroatian ; | |
314 | break ; | |
315 | case wxFONTENCODING_MACICELANDIC : | |
316 | enc = kCFStringEncodingMacIcelandic ; | |
317 | break ; | |
318 | case wxFONTENCODING_MACROMANIAN : | |
319 | enc = kCFStringEncodingMacRomanian ; | |
320 | break ; | |
321 | case wxFONTENCODING_MACCELTIC : | |
322 | enc = kCFStringEncodingMacCeltic ; | |
323 | break ; | |
324 | case wxFONTENCODING_MACGAELIC : | |
325 | enc = kCFStringEncodingMacGaelic ; | |
326 | break ; | |
327 | case wxFONTENCODING_MACKEYBOARD : | |
328 | enc = 41; /* kTextEncodingMacKeyboardGlyphs ; */ | |
329 | break ; | |
330 | default : // to make gcc happy | |
331 | break ; | |
332 | }; | |
333 | return enc ; | |
334 | } | |
335 | ||
336 | wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) | |
337 | { | |
338 | wxFontEncoding enc = wxFONTENCODING_DEFAULT ; | |
339 | ||
340 | switch( encoding) | |
341 | { | |
342 | case kCFStringEncodingISOLatin1 : | |
343 | enc = wxFONTENCODING_ISO8859_1 ; | |
344 | break ; | |
345 | case kCFStringEncodingISOLatin2 : | |
346 | enc = wxFONTENCODING_ISO8859_2; | |
347 | break ; | |
348 | case kCFStringEncodingISOLatin3 : | |
349 | enc = wxFONTENCODING_ISO8859_3 ; | |
350 | break ; | |
351 | case kCFStringEncodingISOLatin4 : | |
352 | enc = wxFONTENCODING_ISO8859_4; | |
353 | break ; | |
354 | case kCFStringEncodingISOLatinCyrillic : | |
355 | enc = wxFONTENCODING_ISO8859_5; | |
356 | break ; | |
357 | case kCFStringEncodingISOLatinArabic : | |
358 | enc = wxFONTENCODING_ISO8859_6; | |
359 | break ; | |
360 | case kCFStringEncodingISOLatinGreek : | |
361 | enc = wxFONTENCODING_ISO8859_7; | |
362 | break ; | |
363 | case kCFStringEncodingISOLatinHebrew : | |
364 | enc = wxFONTENCODING_ISO8859_8; | |
365 | break ; | |
366 | case kCFStringEncodingISOLatin5 : | |
367 | enc = wxFONTENCODING_ISO8859_9; | |
368 | break ; | |
369 | case kCFStringEncodingISOLatin6 : | |
370 | enc = wxFONTENCODING_ISO8859_10; | |
371 | break ; | |
372 | case kCFStringEncodingISOLatin7 : | |
373 | enc = wxFONTENCODING_ISO8859_13; | |
374 | break ; | |
375 | case kCFStringEncodingISOLatin8 : | |
376 | enc = wxFONTENCODING_ISO8859_14; | |
377 | break ; | |
378 | case kCFStringEncodingISOLatin9 : | |
379 | enc =wxFONTENCODING_ISO8859_15 ; | |
380 | break ; | |
381 | ||
382 | case kCFStringEncodingKOI8_R : | |
383 | enc = wxFONTENCODING_KOI8; | |
384 | break ; | |
385 | /* | |
386 | case : | |
387 | enc = wxFONTENCODING_BULGARIAN; | |
388 | break ; | |
389 | */ | |
390 | case kCFStringEncodingDOSLatinUS : | |
391 | enc = wxFONTENCODING_CP437; | |
392 | break ; | |
393 | case kCFStringEncodingDOSLatin1 : | |
394 | enc = wxFONTENCODING_CP850; | |
395 | break ; | |
396 | case kCFStringEncodingDOSLatin2 : | |
397 | enc =wxFONTENCODING_CP852 ; | |
398 | break ; | |
399 | case kCFStringEncodingDOSCyrillic : | |
400 | enc = wxFONTENCODING_CP855; | |
401 | break ; | |
402 | case kCFStringEncodingDOSRussian : | |
403 | enc = wxFONTENCODING_CP866; | |
404 | break ; | |
405 | case kCFStringEncodingDOSThai : | |
406 | enc =wxFONTENCODING_CP874 ; | |
407 | break ; | |
408 | case kCFStringEncodingDOSJapanese : | |
409 | enc = wxFONTENCODING_CP932; | |
410 | break ; | |
411 | case kCFStringEncodingDOSChineseSimplif : | |
412 | enc = wxFONTENCODING_CP936; | |
413 | break ; | |
414 | case kCFStringEncodingDOSKorean : | |
415 | enc = wxFONTENCODING_CP949; | |
416 | break ; | |
417 | case kCFStringEncodingDOSChineseTrad : | |
418 | enc = wxFONTENCODING_CP950; | |
419 | break ; | |
420 | ||
421 | case kCFStringEncodingWindowsLatin2 : | |
422 | enc = wxFONTENCODING_CP1250; | |
423 | break ; | |
424 | case kCFStringEncodingWindowsCyrillic : | |
425 | enc = wxFONTENCODING_CP1251; | |
426 | break ; | |
427 | case kCFStringEncodingWindowsLatin1 : | |
428 | enc = wxFONTENCODING_CP1252; | |
429 | break ; | |
430 | case kCFStringEncodingWindowsGreek : | |
431 | enc = wxFONTENCODING_CP1253; | |
432 | break ; | |
433 | case kCFStringEncodingWindowsLatin5 : | |
434 | enc = wxFONTENCODING_CP1254; | |
435 | break ; | |
436 | case kCFStringEncodingWindowsHebrew : | |
437 | enc = wxFONTENCODING_CP1255; | |
438 | break ; | |
439 | case kCFStringEncodingWindowsArabic : | |
440 | enc = wxFONTENCODING_CP1256; | |
441 | break ; | |
442 | case kCFStringEncodingWindowsBalticRim : | |
443 | enc =wxFONTENCODING_CP1257 ; | |
444 | break ; | |
445 | case kCFStringEncodingEUC_JP : | |
446 | enc = wxFONTENCODING_EUC_JP; | |
447 | break ; | |
448 | ||
449 | case kCFStringEncodingUTF8 : | |
450 | enc = wxFONTENCODING_UTF8; | |
451 | break ; | |
452 | case kCFStringEncodingUTF16BE : | |
453 | enc = wxFONTENCODING_UTF16BE; | |
454 | break ; | |
455 | case kCFStringEncodingUTF16LE : | |
456 | enc = wxFONTENCODING_UTF16LE; | |
457 | break ; | |
458 | case kCFStringEncodingUTF32BE : | |
459 | enc = wxFONTENCODING_UTF32BE; | |
460 | break ; | |
461 | case kCFStringEncodingUTF32LE : | |
462 | enc = wxFONTENCODING_UTF32LE; | |
463 | break ; | |
464 | ||
465 | #if 0 | |
466 | case wxFONTENCODING_UTF7 : | |
467 | enc = CreateTextEncoding(kCFStringEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
468 | break ; | |
469 | #endif | |
470 | case kCFStringEncodingMacRoman : | |
471 | enc = wxFONTENCODING_MACROMAN ; | |
472 | break ; | |
473 | case kCFStringEncodingMacJapanese : | |
474 | enc = wxFONTENCODING_MACJAPANESE ; | |
475 | break ; | |
476 | case kCFStringEncodingMacChineseTrad : | |
477 | enc = wxFONTENCODING_MACCHINESETRAD ; | |
478 | break ; | |
479 | case kCFStringEncodingMacKorean : | |
480 | enc = wxFONTENCODING_MACKOREAN ; | |
481 | break ; | |
482 | case kCFStringEncodingMacArabic : | |
483 | enc =wxFONTENCODING_MACARABIC ; | |
484 | break ; | |
485 | case kCFStringEncodingMacHebrew : | |
486 | enc = wxFONTENCODING_MACHEBREW ; | |
487 | break ; | |
488 | case kCFStringEncodingMacGreek : | |
489 | enc = wxFONTENCODING_MACGREEK ; | |
490 | break ; | |
491 | case kCFStringEncodingMacCyrillic : | |
492 | enc = wxFONTENCODING_MACCYRILLIC ; | |
493 | break ; | |
494 | case kCFStringEncodingMacDevanagari : | |
495 | enc = wxFONTENCODING_MACDEVANAGARI ; | |
496 | break ; | |
497 | case kCFStringEncodingMacGurmukhi : | |
498 | enc = wxFONTENCODING_MACGURMUKHI ; | |
499 | break ; | |
500 | case kCFStringEncodingMacGujarati : | |
501 | enc = wxFONTENCODING_MACGUJARATI ; | |
502 | break ; | |
503 | case kCFStringEncodingMacOriya : | |
504 | enc =wxFONTENCODING_MACORIYA ; | |
505 | break ; | |
506 | case kCFStringEncodingMacBengali : | |
507 | enc =wxFONTENCODING_MACBENGALI ; | |
508 | break ; | |
509 | case kCFStringEncodingMacTamil : | |
510 | enc = wxFONTENCODING_MACTAMIL ; | |
511 | break ; | |
512 | case kCFStringEncodingMacTelugu : | |
513 | enc = wxFONTENCODING_MACTELUGU ; | |
514 | break ; | |
515 | case kCFStringEncodingMacKannada : | |
516 | enc = wxFONTENCODING_MACKANNADA ; | |
517 | break ; | |
518 | case kCFStringEncodingMacMalayalam : | |
519 | enc = wxFONTENCODING_MACMALAJALAM ; | |
520 | break ; | |
521 | case kCFStringEncodingMacSinhalese : | |
522 | enc = wxFONTENCODING_MACSINHALESE ; | |
523 | break ; | |
524 | case kCFStringEncodingMacBurmese : | |
525 | enc = wxFONTENCODING_MACBURMESE ; | |
526 | break ; | |
527 | case kCFStringEncodingMacKhmer : | |
528 | enc = wxFONTENCODING_MACKHMER ; | |
529 | break ; | |
530 | case kCFStringEncodingMacThai : | |
531 | enc = wxFONTENCODING_MACTHAI ; | |
532 | break ; | |
533 | case kCFStringEncodingMacLaotian : | |
534 | enc = wxFONTENCODING_MACLAOTIAN ; | |
535 | break ; | |
536 | case kCFStringEncodingMacGeorgian : | |
537 | enc = wxFONTENCODING_MACGEORGIAN ; | |
538 | break ; | |
539 | case kCFStringEncodingMacArmenian : | |
540 | enc = wxFONTENCODING_MACARMENIAN ; | |
541 | break ; | |
542 | case kCFStringEncodingMacChineseSimp : | |
543 | enc = wxFONTENCODING_MACCHINESESIMP ; | |
544 | break ; | |
545 | case kCFStringEncodingMacTibetan : | |
546 | enc = wxFONTENCODING_MACTIBETAN ; | |
547 | break ; | |
548 | case kCFStringEncodingMacMongolian : | |
549 | enc = wxFONTENCODING_MACMONGOLIAN ; | |
550 | break ; | |
551 | case kCFStringEncodingMacEthiopic : | |
552 | enc = wxFONTENCODING_MACETHIOPIC ; | |
553 | break ; | |
554 | case kCFStringEncodingMacCentralEurRoman: | |
555 | enc = wxFONTENCODING_MACCENTRALEUR ; | |
556 | break ; | |
557 | case kCFStringEncodingMacVietnamese: | |
558 | enc = wxFONTENCODING_MACVIATNAMESE ; | |
559 | break ; | |
560 | case kCFStringEncodingMacExtArabic : | |
561 | enc = wxFONTENCODING_MACARABICEXT ; | |
562 | break ; | |
563 | case kCFStringEncodingMacSymbol : | |
564 | enc = wxFONTENCODING_MACSYMBOL ; | |
565 | break ; | |
566 | case kCFStringEncodingMacDingbats : | |
567 | enc = wxFONTENCODING_MACDINGBATS ; | |
568 | break ; | |
569 | case kCFStringEncodingMacTurkish : | |
570 | enc = wxFONTENCODING_MACTURKISH ; | |
571 | break ; | |
572 | case kCFStringEncodingMacCroatian : | |
573 | enc = wxFONTENCODING_MACCROATIAN ; | |
574 | break ; | |
575 | case kCFStringEncodingMacIcelandic : | |
576 | enc = wxFONTENCODING_MACICELANDIC ; | |
577 | break ; | |
578 | case kCFStringEncodingMacRomanian : | |
579 | enc = wxFONTENCODING_MACROMANIAN ; | |
580 | break ; | |
581 | case kCFStringEncodingMacCeltic : | |
582 | enc = wxFONTENCODING_MACCELTIC ; | |
583 | break ; | |
584 | case kCFStringEncodingMacGaelic : | |
585 | enc = wxFONTENCODING_MACGAELIC ; | |
586 | break ; | |
587 | case 41 /* kTextEncodingMacKeyboardGlyphs */ : | |
588 | enc = wxFONTENCODING_MACKEYBOARD ; | |
589 | break ; | |
590 | } ; | |
591 | return enc ; | |
592 | } | |
593 | ||
594 | ||
595 | // | |
596 | // CFStringRefs | |
597 | // | |
598 | ||
599 | // converts this string into a core foundation string with optional pc 2 mac encoding | |
600 | ||
601 | wxCFStringRef::wxCFStringRef( const wxString &st , wxFontEncoding WXUNUSED_IN_UNICODE(encoding) ) | |
602 | { | |
603 | if (st.IsEmpty()) | |
604 | { | |
605 | reset( wxCFRetain( CFSTR("") ) ); | |
606 | } | |
607 | else | |
608 | { | |
609 | wxString str = st ; | |
610 | wxMacConvertNewlines13To10( &str ) ; | |
611 | #if wxUSE_UNICODE | |
3143722d SC |
612 | #if wxUSE_UNICODE_WCHAR |
613 | // native = wchar_t 4 bytes for us | |
d19fe998 VZ |
614 | const wchar_t * const data = str.wc_str(); |
615 | const size_t size = str.length()*sizeof(wchar_t); | |
2daa5d2c | 616 | CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF32Native; |
3143722d SC |
617 | #elif wxUSE_UNICODE_UTF8 |
618 | // native = utf8 | |
d19fe998 VZ |
619 | const char * const data = str.utf8_str(); |
620 | const size_t size = str.utf8_length(); | |
2daa5d2c | 621 | CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF8; |
489468fe | 622 | #else |
d19fe998 | 623 | #error "unsupported Unicode representation" |
489468fe | 624 | #endif |
d19fe998 VZ |
625 | |
626 | reset( CFStringCreateWithBytes( kCFAllocatorDefault, | |
2daa5d2c | 627 | (const UInt8*)data, size, cfencoding, false /* no BOM */ ) ); |
489468fe SC |
628 | #else // not wxUSE_UNICODE |
629 | reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , | |
630 | wxMacGetSystemEncFromFontEnc( encoding ) ) ); | |
631 | #endif | |
632 | } | |
633 | } | |
634 | ||
f66ecdc4 | 635 | wxString wxCFStringRef::AsString( CFStringRef ref, wxFontEncoding WXUNUSED_IN_UNICODE(encoding) ) |
489468fe | 636 | { |
f66ecdc4 | 637 | if ( !ref ) |
489468fe SC |
638 | return wxEmptyString ; |
639 | ||
f66ecdc4 | 640 | Size cflen = CFStringGetLength( ref ) ; |
489468fe | 641 | |
65391c8f | 642 | CFStringEncoding cfencoding; |
03647350 | 643 | wxString result; |
489468fe | 644 | #if wxUSE_UNICODE |
3143722d | 645 | #if wxUSE_UNICODE_WCHAR |
f5f17248 | 646 | cfencoding = kCFStringEncodingUTF32Native; |
3143722d SC |
647 | #elif wxUSE_UNICODE_UTF8 |
648 | cfencoding = kCFStringEncodingUTF8; | |
649 | #else | |
650 | #error "unsupported unicode representation" | |
651 | #endif | |
489468fe | 652 | #else |
3143722d | 653 | cfencoding = wxMacGetSystemEncFromFontEnc( encoding ); |
489468fe | 654 | #endif |
3143722d | 655 | |
489468fe | 656 | CFIndex cStrLen ; |
f66ecdc4 | 657 | CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding , |
489468fe | 658 | '?' , false , NULL , 0 , &cStrLen ) ; |
65391c8f | 659 | char* buf = new char[cStrLen]; |
f66ecdc4 | 660 | CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding, |
489468fe | 661 | '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ; |
03647350 | 662 | |
3143722d SC |
663 | #if wxUSE_UNICODE |
664 | #if wxUSE_UNICODE_WCHAR | |
665 | result = wxString( (const wchar_t*) buf , cStrLen/4); | |
666 | #elif wxUSE_UNICODE_UTF8 | |
667 | result = wxString::FromUTF8( buf, cStrLen ); | |
668 | #else | |
669 | #error "unsupported unicode representation" | |
670 | #endif | |
671 | #else | |
e3d6cbb9 | 672 | result = wxString(buf, cStrLen) ; |
489468fe | 673 | #endif |
03647350 | 674 | |
489468fe SC |
675 | delete[] buf ; |
676 | wxMacConvertNewlines10To13( &result); | |
677 | return result ; | |
678 | } | |
679 | ||
f66ecdc4 SC |
680 | wxString wxCFStringRef::AsString(wxFontEncoding encoding) const |
681 | { | |
682 | return AsString( get(), encoding ); | |
683 | } | |
684 | ||
685 | #if wxOSX_USE_COCOA_OR_IPHONE | |
03647350 | 686 | wxString wxCFStringRef::AsString( NSString* ref, wxFontEncoding encoding ) |
f66ecdc4 SC |
687 | { |
688 | return AsString( (CFStringRef) ref, encoding ); | |
689 | } | |
690 | #endif | |
691 | ||
692 | ||
489468fe SC |
693 | // |
694 | // wxMacUniCharBuffer | |
695 | // | |
696 | ||
697 | wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str ) | |
698 | { | |
699 | m_chars = str.length() ; | |
700 | m_ubuf = NULL ; | |
701 | ||
702 | #if SIZEOF_WCHAR_T == 4 | |
703 | wxMBConvUTF16 converter ; | |
704 | #if wxUSE_UNICODE | |
705 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; | |
706 | m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
707 | converter.WC2MB( (char*) m_ubuf , str.wc_str(), unicharlen + 2 ) ; | |
708 | #else | |
709 | const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
710 | size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; | |
711 | m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
712 | converter.WC2MB( (char*) m_ubuf , wchar.data() , unicharlen + 2 ) ; | |
713 | #endif | |
714 | m_chars = unicharlen / 2 ; | |
715 | #else // SIZEOF_WCHAR_T is then 2 | |
716 | #if wxUSE_UNICODE | |
717 | m_ubuf = malloc( m_chars * 2 + 2 ) ; | |
718 | memcpy( m_ubuf , (UniChar*) str.wc_str() , m_chars * 2 + 2 ) ; | |
719 | #else | |
720 | wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
721 | m_chars = wxWcslen( wchar.data() ) ; | |
722 | m_ubuf = malloc( m_chars * 2 + 2 ) ; | |
723 | memcpy( m_ubuf , (UniChar*) wchar.data() , m_chars * 2 + 2 ) ; | |
724 | #endif | |
725 | #endif | |
726 | } | |
727 | ||
728 | wxMacUniCharBuffer::~wxMacUniCharBuffer() | |
729 | { | |
730 | free( m_ubuf ) ; | |
731 | } | |
732 | ||
03647350 | 733 | UniCharPtr wxMacUniCharBuffer::GetBuffer() |
489468fe SC |
734 | { |
735 | return m_ubuf ; | |
736 | } | |
03647350 | 737 | |
489468fe SC |
738 | UniCharCount wxMacUniCharBuffer::GetChars() |
739 | { | |
740 | return m_chars ; | |
741 | } |