]> git.saurik.com Git - wxWidgets.git/blame - src/mac/corefoundation/cfstring.cpp
replaced all int/size_t indices in wxControlWithItems API with unsigned int (committi...
[wxWidgets.git] / src / mac / corefoundation / cfstring.cpp
CommitLineData
5185263f
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/mac/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/mac/carbon/utils.cpp)
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/string.h"
15 #include "wx/intl.h"
16#endif
17#include "wx/mac/corefoundation/cfstring.h"
18
19#if wxUSE_GUI
20 #include "wx/font.h"
21#endif
22
23#ifdef __DARWIN__
24 #include <CoreServices/CoreServices.h>
25#else
26 #include <TextCommon.h>
27#endif
28
29void wxMacConvertNewlines13To10( char * data )
30{
31 char * buf = data ;
32 while( (buf=strchr(buf,0x0d)) != NULL )
33 {
34 *buf = 0x0a ;
35 buf++ ;
36 }
37}
38
39void wxMacConvertNewlines10To13( char * data )
40{
41 char * buf = data ;
42 while( (buf=strchr(buf,0x0a)) != NULL )
43 {
44 *buf = 0x0d ;
45 buf++ ;
46 }
47}
48
49void wxMacConvertNewlines13To10( wxString * data )
50{
51 size_t len = data->Length() ;
52
53 if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL)
54 return ;
55
56 wxString temp(*data) ;
57 wxStringBuffer buf(*data,len ) ;
58 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
59
60 wxMacConvertNewlines13To10( buf ) ;
61}
62
63void wxMacConvertNewlines10To13( wxString * data )
64{
65 size_t len = data->Length() ;
66
67 if ( data->Length() == 0 || wxStrchr(data->c_str(),0x0a)==NULL)
68 return ;
69
70 wxString temp(*data) ;
71 wxStringBuffer buf(*data,len ) ;
72 memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ;
73 wxMacConvertNewlines10To13( buf ) ;
74}
75
76
77#if wxUSE_UNICODE
78void wxMacConvertNewlines13To10( wxChar * data )
79{
80 wxChar * buf = data ;
81 while( (buf=wxStrchr(buf,0x0d)) != NULL )
82 {
83 *buf = 0x0a ;
84 buf++ ;
85 }
86}
87
88void wxMacConvertNewlines10To13( wxChar * data )
89{
90 wxChar * buf = data ;
91 while( (buf=wxStrchr(buf,0x0a)) != NULL )
92 {
93 *buf = 0x0d ;
94 buf++ ;
95 }
96}
97#endif
98
99wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding)
100{
101 TextEncodingBase enc = 0 ;
102 if ( encoding == wxFONTENCODING_DEFAULT )
103 {
104#if wxUSE_GUI
105 encoding = wxFont::GetDefaultEncoding() ;
106#else
107 encoding = wxLocale::GetSystemEncoding() ;
108#endif
109 }
a4ea2d8d
SC
110 if ( encoding == wxFONTENCODING_SYSTEM )
111 {
112 enc = CFStringGetSystemEncoding();
113 }
5185263f
DE
114
115 switch( encoding)
116 {
117 case wxFONTENCODING_ISO8859_1 :
118 enc = kTextEncodingISOLatin1 ;
119 break ;
120 case wxFONTENCODING_ISO8859_2 :
121 enc = kTextEncodingISOLatin2;
122 break ;
123 case wxFONTENCODING_ISO8859_3 :
124 enc = kTextEncodingISOLatin3 ;
125 break ;
126 case wxFONTENCODING_ISO8859_4 :
127 enc = kTextEncodingISOLatin4;
128 break ;
129 case wxFONTENCODING_ISO8859_5 :
130 enc = kTextEncodingISOLatinCyrillic;
131 break ;
132 case wxFONTENCODING_ISO8859_6 :
133 enc = kTextEncodingISOLatinArabic;
134 break ;
135 case wxFONTENCODING_ISO8859_7 :
136 enc = kTextEncodingISOLatinGreek;
137 break ;
138 case wxFONTENCODING_ISO8859_8 :
139 enc = kTextEncodingISOLatinHebrew;
140 break ;
141 case wxFONTENCODING_ISO8859_9 :
142 enc = kTextEncodingISOLatin5;
143 break ;
144 case wxFONTENCODING_ISO8859_10 :
145 enc = kTextEncodingISOLatin6;
146 break ;
147 case wxFONTENCODING_ISO8859_13 :
148 enc = kTextEncodingISOLatin7;
149 break ;
150 case wxFONTENCODING_ISO8859_14 :
151 enc = kTextEncodingISOLatin8;
152 break ;
153 case wxFONTENCODING_ISO8859_15 :
154 enc = kTextEncodingISOLatin9;
155 break ;
156
157 case wxFONTENCODING_KOI8 :
158 enc = kTextEncodingKOI8_R;
159 break ;
160 case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866
161 enc = kTextEncodingDOSRussian;
162 break ;
163/*
164 case wxFONTENCODING_BULGARIAN :
165 enc = ;
166 break ;
167*/
168 case wxFONTENCODING_CP437 :
169 enc =kTextEncodingDOSLatinUS ;
170 break ;
171 case wxFONTENCODING_CP850 :
172 enc = kTextEncodingDOSLatin1;
173 break ;
174 case wxFONTENCODING_CP852 :
175 enc = kTextEncodingDOSLatin2;
176 break ;
177 case wxFONTENCODING_CP855 :
178 enc = kTextEncodingDOSCyrillic;
179 break ;
180 case wxFONTENCODING_CP866 :
181 enc =kTextEncodingDOSRussian ;
182 break ;
183 case wxFONTENCODING_CP874 :
184 enc = kTextEncodingDOSThai;
185 break ;
186 case wxFONTENCODING_CP932 :
187 enc = kTextEncodingDOSJapanese;
188 break ;
189 case wxFONTENCODING_CP936 :
190 enc = kTextEncodingDOSChineseSimplif ;
191 break ;
192 case wxFONTENCODING_CP949 :
193 enc = kTextEncodingDOSKorean;
194 break ;
195 case wxFONTENCODING_CP950 :
196 enc = kTextEncodingDOSChineseTrad;
197 break ;
198
199 case wxFONTENCODING_CP1250 :
200 enc = kTextEncodingWindowsLatin2;
201 break ;
202 case wxFONTENCODING_CP1251 :
203 enc =kTextEncodingWindowsCyrillic ;
204 break ;
205 case wxFONTENCODING_CP1252 :
206 enc =kTextEncodingWindowsLatin1 ;
207 break ;
208 case wxFONTENCODING_CP1253 :
209 enc = kTextEncodingWindowsGreek;
210 break ;
211 case wxFONTENCODING_CP1254 :
212 enc = kTextEncodingWindowsLatin5;
213 break ;
214 case wxFONTENCODING_CP1255 :
215 enc =kTextEncodingWindowsHebrew ;
216 break ;
217 case wxFONTENCODING_CP1256 :
218 enc =kTextEncodingWindowsArabic ;
219 break ;
220 case wxFONTENCODING_CP1257 :
221 enc = kTextEncodingWindowsBalticRim;
222 break ;
223
224 case wxFONTENCODING_UTF7 :
225 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
226 break ;
227 case wxFONTENCODING_UTF8 :
228 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
229 break ;
230 case wxFONTENCODING_EUC_JP :
231 enc = kTextEncodingEUC_JP;
232 break ;
233 case wxFONTENCODING_UTF16BE :
234 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
235 break ;
236 case wxFONTENCODING_UTF16LE :
237 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
238 break ;
239 case wxFONTENCODING_UTF32BE :
240 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
241 break ;
242 case wxFONTENCODING_UTF32LE :
243 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
244 break ;
245
246 case wxFONTENCODING_MACROMAN :
247 enc = kTextEncodingMacRoman ;
248 break ;
249 case wxFONTENCODING_MACJAPANESE :
250 enc = kTextEncodingMacJapanese ;
251 break ;
252 case wxFONTENCODING_MACCHINESETRAD :
253 enc = kTextEncodingMacChineseTrad ;
254 break ;
255 case wxFONTENCODING_MACKOREAN :
256 enc = kTextEncodingMacKorean ;
257 break ;
258 case wxFONTENCODING_MACARABIC :
259 enc = kTextEncodingMacArabic ;
260 break ;
261 case wxFONTENCODING_MACHEBREW :
262 enc = kTextEncodingMacHebrew ;
263 break ;
264 case wxFONTENCODING_MACGREEK :
265 enc = kTextEncodingMacGreek ;
266 break ;
267 case wxFONTENCODING_MACCYRILLIC :
268 enc = kTextEncodingMacCyrillic ;
269 break ;
270 case wxFONTENCODING_MACDEVANAGARI :
271 enc = kTextEncodingMacDevanagari ;
272 break ;
273 case wxFONTENCODING_MACGURMUKHI :
274 enc = kTextEncodingMacGurmukhi ;
275 break ;
276 case wxFONTENCODING_MACGUJARATI :
277 enc = kTextEncodingMacGujarati ;
278 break ;
279 case wxFONTENCODING_MACORIYA :
280 enc = kTextEncodingMacOriya ;
281 break ;
282 case wxFONTENCODING_MACBENGALI :
283 enc = kTextEncodingMacBengali ;
284 break ;
285 case wxFONTENCODING_MACTAMIL :
286 enc = kTextEncodingMacTamil ;
287 break ;
288 case wxFONTENCODING_MACTELUGU :
289 enc = kTextEncodingMacTelugu ;
290 break ;
291 case wxFONTENCODING_MACKANNADA :
292 enc = kTextEncodingMacKannada ;
293 break ;
294 case wxFONTENCODING_MACMALAJALAM :
295 enc = kTextEncodingMacMalayalam ;
296 break ;
297 case wxFONTENCODING_MACSINHALESE :
298 enc = kTextEncodingMacSinhalese ;
299 break ;
300 case wxFONTENCODING_MACBURMESE :
301 enc = kTextEncodingMacBurmese ;
302 break ;
303 case wxFONTENCODING_MACKHMER :
304 enc = kTextEncodingMacKhmer ;
305 break ;
306 case wxFONTENCODING_MACTHAI :
307 enc = kTextEncodingMacThai ;
308 break ;
309 case wxFONTENCODING_MACLAOTIAN :
310 enc = kTextEncodingMacLaotian ;
311 break ;
312 case wxFONTENCODING_MACGEORGIAN :
313 enc = kTextEncodingMacGeorgian ;
314 break ;
315 case wxFONTENCODING_MACARMENIAN :
316 enc = kTextEncodingMacArmenian ;
317 break ;
318 case wxFONTENCODING_MACCHINESESIMP :
319 enc = kTextEncodingMacChineseSimp ;
320 break ;
321 case wxFONTENCODING_MACTIBETAN :
322 enc = kTextEncodingMacTibetan ;
323 break ;
324 case wxFONTENCODING_MACMONGOLIAN :
325 enc = kTextEncodingMacMongolian ;
326 break ;
327 case wxFONTENCODING_MACETHIOPIC :
328 enc = kTextEncodingMacEthiopic ;
329 break ;
330 case wxFONTENCODING_MACCENTRALEUR :
331 enc = kTextEncodingMacCentralEurRoman ;
332 break ;
333 case wxFONTENCODING_MACVIATNAMESE :
334 enc = kTextEncodingMacVietnamese ;
335 break ;
336 case wxFONTENCODING_MACARABICEXT :
337 enc = kTextEncodingMacExtArabic ;
338 break ;
339 case wxFONTENCODING_MACSYMBOL :
340 enc = kTextEncodingMacSymbol ;
341 break ;
342 case wxFONTENCODING_MACDINGBATS :
343 enc = kTextEncodingMacDingbats ;
344 break ;
345 case wxFONTENCODING_MACTURKISH :
346 enc = kTextEncodingMacTurkish ;
347 break ;
348 case wxFONTENCODING_MACCROATIAN :
349 enc = kTextEncodingMacCroatian ;
350 break ;
351 case wxFONTENCODING_MACICELANDIC :
352 enc = kTextEncodingMacIcelandic ;
353 break ;
354 case wxFONTENCODING_MACROMANIAN :
355 enc = kTextEncodingMacRomanian ;
356 break ;
357 case wxFONTENCODING_MACCELTIC :
358 enc = kTextEncodingMacCeltic ;
359 break ;
360 case wxFONTENCODING_MACGAELIC :
361 enc = kTextEncodingMacGaelic ;
362 break ;
363 case wxFONTENCODING_MACKEYBOARD :
364 enc = kTextEncodingMacKeyboardGlyphs ;
365 break ;
366 default : // to make gcc happy
367 break ;
368 };
369 return enc ;
370}
371
372wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding)
373{
374 wxFontEncoding enc = wxFONTENCODING_DEFAULT ;
375
376 switch( encoding)
377 {
378 case kTextEncodingISOLatin1 :
379 enc = wxFONTENCODING_ISO8859_1 ;
380 break ;
381 case kTextEncodingISOLatin2 :
382 enc = wxFONTENCODING_ISO8859_2;
383 break ;
384 case kTextEncodingISOLatin3 :
385 enc = wxFONTENCODING_ISO8859_3 ;
386 break ;
387 case kTextEncodingISOLatin4 :
388 enc = wxFONTENCODING_ISO8859_4;
389 break ;
390 case kTextEncodingISOLatinCyrillic :
391 enc = wxFONTENCODING_ISO8859_5;
392 break ;
393 case kTextEncodingISOLatinArabic :
394 enc = wxFONTENCODING_ISO8859_6;
395 break ;
396 case kTextEncodingISOLatinGreek :
397 enc = wxFONTENCODING_ISO8859_7;
398 break ;
399 case kTextEncodingISOLatinHebrew :
400 enc = wxFONTENCODING_ISO8859_8;
401 break ;
402 case kTextEncodingISOLatin5 :
403 enc = wxFONTENCODING_ISO8859_9;
404 break ;
405 case kTextEncodingISOLatin6 :
406 enc = wxFONTENCODING_ISO8859_10;
407 break ;
408 case kTextEncodingISOLatin7 :
409 enc = wxFONTENCODING_ISO8859_13;
410 break ;
411 case kTextEncodingISOLatin8 :
412 enc = wxFONTENCODING_ISO8859_14;
413 break ;
414 case kTextEncodingISOLatin9 :
415 enc =wxFONTENCODING_ISO8859_15 ;
416 break ;
417
418 case kTextEncodingKOI8_R :
419 enc = wxFONTENCODING_KOI8;
420 break ;
421/*
422 case :
423 enc = wxFONTENCODING_BULGARIAN;
424 break ;
425*/
426 case kTextEncodingDOSLatinUS :
427 enc = wxFONTENCODING_CP437;
428 break ;
429 case kTextEncodingDOSLatin1 :
430 enc = wxFONTENCODING_CP850;
431 break ;
432 case kTextEncodingDOSLatin2 :
433 enc =wxFONTENCODING_CP852 ;
434 break ;
435 case kTextEncodingDOSCyrillic :
436 enc = wxFONTENCODING_CP855;
437 break ;
438 case kTextEncodingDOSRussian :
439 enc = wxFONTENCODING_CP866;
440 break ;
441 case kTextEncodingDOSThai :
442 enc =wxFONTENCODING_CP874 ;
443 break ;
444 case kTextEncodingDOSJapanese :
445 enc = wxFONTENCODING_CP932;
446 break ;
447 case kTextEncodingDOSChineseSimplif :
448 enc = wxFONTENCODING_CP936;
449 break ;
450 case kTextEncodingDOSKorean :
451 enc = wxFONTENCODING_CP949;
452 break ;
453 case kTextEncodingDOSChineseTrad :
454 enc = wxFONTENCODING_CP950;
455 break ;
456
457 case kTextEncodingWindowsLatin2 :
458 enc = wxFONTENCODING_CP1250;
459 break ;
460 case kTextEncodingWindowsCyrillic :
461 enc = wxFONTENCODING_CP1251;
462 break ;
463 case kTextEncodingWindowsLatin1 :
464 enc = wxFONTENCODING_CP1252;
465 break ;
466 case kTextEncodingWindowsGreek :
467 enc = wxFONTENCODING_CP1253;
468 break ;
469 case kTextEncodingWindowsLatin5 :
470 enc = wxFONTENCODING_CP1254;
471 break ;
472 case kTextEncodingWindowsHebrew :
473 enc = wxFONTENCODING_CP1255;
474 break ;
475 case kTextEncodingWindowsArabic :
476 enc = wxFONTENCODING_CP1256;
477 break ;
478 case kTextEncodingWindowsBalticRim :
479 enc =wxFONTENCODING_CP1257 ;
480 break ;
481 case kTextEncodingEUC_JP :
482 enc = wxFONTENCODING_EUC_JP;
483 break ;
484#if 0
485 case wxFONTENCODING_UTF7 :
486 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
487 break ;
488 case wxFONTENCODING_UTF8 :
489 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
490 break ;
491 case wxFONTENCODING_UTF16BE :
492 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
493 break ;
494 case wxFONTENCODING_UTF16LE :
495 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
496 break ;
497 case wxFONTENCODING_UTF32BE :
498 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
499 break ;
500 case wxFONTENCODING_UTF32LE :
501 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
502 break ;
503#endif
504 case kTextEncodingMacRoman :
505 enc = wxFONTENCODING_MACROMAN ;
506 break ;
507 case kTextEncodingMacJapanese :
508 enc = wxFONTENCODING_MACJAPANESE ;
509 break ;
510 case kTextEncodingMacChineseTrad :
511 enc = wxFONTENCODING_MACCHINESETRAD ;
512 break ;
513 case kTextEncodingMacKorean :
514 enc = wxFONTENCODING_MACKOREAN ;
515 break ;
516 case kTextEncodingMacArabic :
517 enc =wxFONTENCODING_MACARABIC ;
518 break ;
519 case kTextEncodingMacHebrew :
520 enc = wxFONTENCODING_MACHEBREW ;
521 break ;
522 case kTextEncodingMacGreek :
523 enc = wxFONTENCODING_MACGREEK ;
524 break ;
525 case kTextEncodingMacCyrillic :
526 enc = wxFONTENCODING_MACCYRILLIC ;
527 break ;
528 case kTextEncodingMacDevanagari :
529 enc = wxFONTENCODING_MACDEVANAGARI ;
530 break ;
531 case kTextEncodingMacGurmukhi :
532 enc = wxFONTENCODING_MACGURMUKHI ;
533 break ;
534 case kTextEncodingMacGujarati :
535 enc = wxFONTENCODING_MACGUJARATI ;
536 break ;
537 case kTextEncodingMacOriya :
538 enc =wxFONTENCODING_MACORIYA ;
539 break ;
540 case kTextEncodingMacBengali :
541 enc =wxFONTENCODING_MACBENGALI ;
542 break ;
543 case kTextEncodingMacTamil :
544 enc = wxFONTENCODING_MACTAMIL ;
545 break ;
546 case kTextEncodingMacTelugu :
547 enc = wxFONTENCODING_MACTELUGU ;
548 break ;
549 case kTextEncodingMacKannada :
550 enc = wxFONTENCODING_MACKANNADA ;
551 break ;
552 case kTextEncodingMacMalayalam :
553 enc = wxFONTENCODING_MACMALAJALAM ;
554 break ;
555 case kTextEncodingMacSinhalese :
556 enc = wxFONTENCODING_MACSINHALESE ;
557 break ;
558 case kTextEncodingMacBurmese :
559 enc = wxFONTENCODING_MACBURMESE ;
560 break ;
561 case kTextEncodingMacKhmer :
562 enc = wxFONTENCODING_MACKHMER ;
563 break ;
564 case kTextEncodingMacThai :
565 enc = wxFONTENCODING_MACTHAI ;
566 break ;
567 case kTextEncodingMacLaotian :
568 enc = wxFONTENCODING_MACLAOTIAN ;
569 break ;
570 case kTextEncodingMacGeorgian :
571 enc = wxFONTENCODING_MACGEORGIAN ;
572 break ;
573 case kTextEncodingMacArmenian :
574 enc = wxFONTENCODING_MACARMENIAN ;
575 break ;
576 case kTextEncodingMacChineseSimp :
577 enc = wxFONTENCODING_MACCHINESESIMP ;
578 break ;
579 case kTextEncodingMacTibetan :
580 enc = wxFONTENCODING_MACTIBETAN ;
581 break ;
582 case kTextEncodingMacMongolian :
583 enc = wxFONTENCODING_MACMONGOLIAN ;
584 break ;
585 case kTextEncodingMacEthiopic :
586 enc = wxFONTENCODING_MACETHIOPIC ;
587 break ;
588 case kTextEncodingMacCentralEurRoman:
589 enc = wxFONTENCODING_MACCENTRALEUR ;
590 break ;
591 case kTextEncodingMacVietnamese:
592 enc = wxFONTENCODING_MACVIATNAMESE ;
593 break ;
594 case kTextEncodingMacExtArabic :
595 enc = wxFONTENCODING_MACARABICEXT ;
596 break ;
597 case kTextEncodingMacSymbol :
598 enc = wxFONTENCODING_MACSYMBOL ;
599 break ;
600 case kTextEncodingMacDingbats :
601 enc = wxFONTENCODING_MACDINGBATS ;
602 break ;
603 case kTextEncodingMacTurkish :
604 enc = wxFONTENCODING_MACTURKISH ;
605 break ;
606 case kTextEncodingMacCroatian :
607 enc = wxFONTENCODING_MACCROATIAN ;
608 break ;
609 case kTextEncodingMacIcelandic :
610 enc = wxFONTENCODING_MACICELANDIC ;
611 break ;
612 case kTextEncodingMacRomanian :
613 enc = wxFONTENCODING_MACROMANIAN ;
614 break ;
615 case kTextEncodingMacCeltic :
616 enc = wxFONTENCODING_MACCELTIC ;
617 break ;
618 case kTextEncodingMacGaelic :
619 enc = wxFONTENCODING_MACGAELIC ;
620 break ;
621 case kTextEncodingMacKeyboardGlyphs :
622 enc = wxFONTENCODING_MACKEYBOARD ;
623 break ;
624 } ;
625 return enc ;
626}
627
628
629//
630// CFStringRefs (Carbon only)
631//
632
633// converts this string into a carbon foundation string with optional pc 2 mac encoding
634void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding )
635{
a4ea2d8d
SC
636 Release() ;
637 if (st.IsEmpty())
2539aa88
SC
638 {
639 m_cfs = CFSTR("") ;
640 CFRetain( m_cfs ) ;
641 }
642 else
643 {
644 wxString str = st ;
645 wxMacConvertNewlines13To10( &str ) ;
5185263f
DE
646#if wxUSE_UNICODE
647#if SIZEOF_WCHAR_T == 2
2539aa88
SC
648 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault,
649 (UniChar*)str.wc_str() , str.Len() );
5185263f 650#else
d9d488cf 651 wxMBConvUTF16 converter ;
2539aa88
SC
652 size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ;
653 UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ;
654 converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ;
655 m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault ,
656 unibuf , unicharlen / sizeof(UniChar) ) ;
657 delete[] unibuf ;
5185263f
DE
658#endif
659#else // not wxUSE_UNICODE
2539aa88
SC
660 m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() ,
661 wxMacGetSystemEncFromFontEnc( encoding ) ) ;
5185263f 662#endif
2539aa88 663 }
5185263f
DE
664 m_release = true ;
665}
666
667wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding)
668{
669 Size cflen = CFStringGetLength( m_cfs ) ;
670 size_t noChars ;
671 wxChar* buf = NULL ;
672
673#if wxUSE_UNICODE
674#if SIZEOF_WCHAR_T == 2
675 buf = new wxChar[ cflen + 1 ] ;
676 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ;
677 noChars = cflen ;
678#else
679 UniChar* unibuf = new UniChar[ cflen + 1 ] ;
680 CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ;
681 unibuf[cflen] = 0 ;
d9d488cf 682 wxMBConvUTF16 converter ;
5185263f
DE
683 noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ;
684 buf = new wxChar[ noChars + 1 ] ;
685 converter.MB2WC( buf , (const char*)unibuf , noChars ) ;
686 delete[] unibuf ;
687#endif
688#else
689 CFIndex cStrLen ;
690 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
691 '?' , false , NULL , 0 , &cStrLen ) ;
692 buf = new wxChar[ cStrLen + 1 ] ;
693 CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) ,
694 '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ;
695 noChars = cStrLen ;
696#endif
697
698 buf[noChars] = 0 ;
699 wxMacConvertNewlines10To13( buf ) ;
700 wxString result(buf) ;
701 delete[] buf ;
702 return result ;
703}
704