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