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