]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/core/cfstring.cpp
Applying patch #10784: eliminate gauge flicker
[wxWidgets.git] / src / osx / core / cfstring.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/corefoundation/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// 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
23#include "wx/osx/core/cfstring.h"
24
25#include <CoreFoundation/CoreFoundation.h>
26
27
28void wxMacConvertNewlines13To10( char * data )
29{
30 char * buf = data ;
31 while( (buf=strchr(buf,0x0d)) != NULL )
32 {
33 *buf = 0x0a ;
34 buf++ ;
35 }
36}
37
38void wxMacConvertNewlines10To13( char * data )
39{
40 char * buf = data ;
41 while( (buf=strchr(buf,0x0a)) != NULL )
42 {
43 *buf = 0x0d ;
44 buf++ ;
45 }
46}
47
48const wxString sCR((wxChar)13);
49const wxString sLF((wxChar)10);
50
51void wxMacConvertNewlines13To10( wxString * data )
52{
53 data->Replace( sCR,sLF);
54}
55
56void wxMacConvertNewlines10To13( wxString * data )
57{
58 data->Replace( sLF,sCR);
59}
60
61wxUint32 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) ;
189#endif
190 break ;
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
336wxFontEncoding 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
601wxCFStringRef::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
612#if wxUSE_UNICODE_WCHAR
613 // native = wchar_t 4 bytes for us
614 const wchar_t * const data = str.wc_str();
615 const size_t size = str.length()*sizeof(wchar_t);
616 CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF32Native;
617#elif wxUSE_UNICODE_UTF8
618 // native = utf8
619 const char * const data = str.utf8_str();
620 const size_t size = str.utf8_length();
621 CFStringBuiltInEncodings cfencoding = kCFStringEncodingUTF8;
622#else
623 #error "unsupported Unicode representation"
624#endif
625
626 reset( CFStringCreateWithBytes( kCFAllocatorDefault,
627 (const UInt8*)data, size, cfencoding, false /* no BOM */ ) );
628#else // not wxUSE_UNICODE
629 reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
630 wxMacGetSystemEncFromFontEnc( encoding ) ) );
631#endif
632 }
633}
634
635wxString wxCFStringRef::AsString( CFStringRef ref, wxFontEncoding WXUNUSED_IN_UNICODE(encoding) )
636{
637 if ( !ref )
638 return wxEmptyString ;
639
640 Size cflen = CFStringGetLength( ref ) ;
641 char* buf = NULL ;
642
643 CFStringEncoding cfencoding = 0;
644 wxString result;
645#if wxUSE_UNICODE
646 #if wxUSE_UNICODE_WCHAR
647 cfencoding = kCFStringEncodingUTF32Native;
648 #elif wxUSE_UNICODE_UTF8
649 cfencoding = kCFStringEncodingUTF8;
650 #else
651 #error "unsupported unicode representation"
652 #endif
653#else
654 cfencoding = wxMacGetSystemEncFromFontEnc( encoding );
655#endif
656
657 CFIndex cStrLen ;
658 CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding ,
659 '?' , false , NULL , 0 , &cStrLen ) ;
660 buf = new char[ cStrLen ] ;
661 CFStringGetBytes( ref , CFRangeMake(0, cflen) , cfencoding,
662 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
663
664#if wxUSE_UNICODE
665 #if wxUSE_UNICODE_WCHAR
666 result = wxString( (const wchar_t*) buf , cStrLen/4);
667 #elif wxUSE_UNICODE_UTF8
668 result = wxString::FromUTF8( buf, cStrLen );
669 #else
670 #error "unsupported unicode representation"
671 #endif
672#else
673 result = wxString(buf, cStrLen) ;
674#endif
675
676 delete[] buf ;
677 wxMacConvertNewlines10To13( &result);
678 return result ;
679}
680
681wxString wxCFStringRef::AsString(wxFontEncoding encoding) const
682{
683 return AsString( get(), encoding );
684}
685
686#if wxOSX_USE_COCOA_OR_IPHONE
687wxString wxCFStringRef::AsString( NSString* ref, wxFontEncoding encoding )
688{
689 return AsString( (CFStringRef) ref, encoding );
690}
691#endif
692
693
694//
695// wxMacUniCharBuffer
696//
697
698wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str )
699{
700 m_chars = str.length() ;
701 m_ubuf = NULL ;
702
703#if SIZEOF_WCHAR_T == 4
704 wxMBConvUTF16 converter ;
705#if wxUSE_UNICODE
706 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
707 m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
708 converter.WC2MB( (char*) m_ubuf , str.wc_str(), unicharlen + 2 ) ;
709#else
710 const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
711 size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ;
712 m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ;
713 converter.WC2MB( (char*) m_ubuf , wchar.data() , unicharlen + 2 ) ;
714#endif
715 m_chars = unicharlen / 2 ;
716#else // SIZEOF_WCHAR_T is then 2
717#if wxUSE_UNICODE
718 m_ubuf = malloc( m_chars * 2 + 2 ) ;
719 memcpy( m_ubuf , (UniChar*) str.wc_str() , m_chars * 2 + 2 ) ;
720#else
721 wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ;
722 m_chars = wxWcslen( wchar.data() ) ;
723 m_ubuf = malloc( m_chars * 2 + 2 ) ;
724 memcpy( m_ubuf , (UniChar*) wchar.data() , m_chars * 2 + 2 ) ;
725#endif
726#endif
727}
728
729wxMacUniCharBuffer::~wxMacUniCharBuffer()
730{
731 free( m_ubuf ) ;
732}
733
734UniCharPtr wxMacUniCharBuffer::GetBuffer()
735{
736 return m_ubuf ;
737}
738
739UniCharCount wxMacUniCharBuffer::GetChars()
740{
741 return m_chars ;
742}