]>
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 | ||
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 | #endif | |
189 | break ; | |
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 SIZEOF_WCHAR_T == 2 | |
612 | reset( CFStringCreateWithCharacters( kCFAllocatorDefault, | |
613 | (UniChar*)str.wc_str() , str.Len() ) ); | |
614 | #else | |
615 | wxMBConvUTF16 converter ; | |
616 | size_t unicharbytes = converter.FromWChar( NULL , 0 , str.wc_str() , str.Length() ) ; | |
617 | wxASSERT( unicharbytes != wxCONV_FAILED ); | |
618 | if ( unicharbytes == wxCONV_FAILED ) | |
619 | { | |
620 | // create an empty string | |
621 | reset( wxCFRetain( CFSTR("") ) ); | |
622 | } | |
623 | else | |
624 | { | |
625 | // unicharbytes: number of bytes needed for UTF-16 encoded string (without terminating null) | |
626 | // unichars: number of UTF-16 characters (without terminating null) | |
627 | size_t unichars = unicharbytes / sizeof(UniChar) ; | |
628 | UniChar *unibuf = new UniChar[ unichars ] ; | |
629 | converter.FromWChar( (char*)unibuf , unicharbytes , str.wc_str() , str.Length() ) ; | |
630 | reset( CFStringCreateWithCharacters( kCFAllocatorDefault , unibuf , unichars ) ) ; | |
631 | delete[] unibuf ; | |
632 | } | |
633 | #endif | |
634 | #else // not wxUSE_UNICODE | |
635 | reset( CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , | |
636 | wxMacGetSystemEncFromFontEnc( encoding ) ) ); | |
637 | #endif | |
638 | } | |
639 | } | |
640 | ||
641 | wxString wxCFStringRef::AsString(wxFontEncoding WXUNUSED_IN_UNICODE(encoding)) | |
642 | { | |
643 | if ( !get() ) | |
644 | return wxEmptyString ; | |
645 | ||
646 | Size cflen = CFStringGetLength( get() ) ; | |
647 | size_t noChars ; | |
648 | wxChar* buf = NULL ; | |
649 | ||
650 | #if wxUSE_UNICODE | |
651 | #if SIZEOF_WCHAR_T == 2 | |
652 | buf = new wxChar[ cflen + 1 ] ; | |
653 | CFStringGetCharacters( get() , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ; | |
654 | noChars = cflen ; | |
655 | #else | |
656 | UniChar* unibuf = new UniChar[ cflen + 1 ] ; | |
657 | CFStringGetCharacters( get() , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ; | |
658 | unibuf[cflen] = 0 ; | |
659 | wxMBConvUTF16 converter ; | |
660 | noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ; | |
661 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Unable to count the number of characters in this string!") ); | |
662 | buf = new wxChar[ noChars + 1 ] ; | |
663 | noChars = converter.MB2WC( buf , (const char*)unibuf , noChars + 1 ) ; | |
664 | wxASSERT_MSG( noChars != wxCONV_FAILED, _T("Conversion of string failed!") ); | |
665 | delete[] unibuf ; | |
666 | #endif | |
667 | #else | |
668 | CFIndex cStrLen ; | |
669 | CFStringGetBytes( get() , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , | |
670 | '?' , false , NULL , 0 , &cStrLen ) ; | |
671 | buf = new wxChar[ cStrLen + 1 ] ; | |
672 | CFStringGetBytes( get() , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , | |
673 | '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ; | |
674 | noChars = cStrLen ; | |
675 | #endif | |
676 | ||
677 | buf[noChars] = 0 ; | |
678 | wxString result(buf) ; | |
679 | delete[] buf ; | |
680 | wxMacConvertNewlines10To13( &result); | |
681 | return result ; | |
682 | } | |
683 | ||
684 | // | |
685 | // wxMacUniCharBuffer | |
686 | // | |
687 | ||
688 | wxMacUniCharBuffer::wxMacUniCharBuffer( const wxString &str ) | |
689 | { | |
690 | m_chars = str.length() ; | |
691 | m_ubuf = NULL ; | |
692 | ||
693 | #if SIZEOF_WCHAR_T == 4 | |
694 | wxMBConvUTF16 converter ; | |
695 | #if wxUSE_UNICODE | |
696 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; | |
697 | m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
698 | converter.WC2MB( (char*) m_ubuf , str.wc_str(), unicharlen + 2 ) ; | |
699 | #else | |
700 | const wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
701 | size_t unicharlen = converter.WC2MB( NULL , wchar.data() , 0 ) ; | |
702 | m_ubuf = (UniChar*) malloc( unicharlen + 2 ) ; | |
703 | converter.WC2MB( (char*) m_ubuf , wchar.data() , unicharlen + 2 ) ; | |
704 | #endif | |
705 | m_chars = unicharlen / 2 ; | |
706 | #else // SIZEOF_WCHAR_T is then 2 | |
707 | #if wxUSE_UNICODE | |
708 | m_ubuf = malloc( m_chars * 2 + 2 ) ; | |
709 | memcpy( m_ubuf , (UniChar*) str.wc_str() , m_chars * 2 + 2 ) ; | |
710 | #else | |
711 | wxWCharBuffer wchar = str.wc_str( wxConvLocal ) ; | |
712 | m_chars = wxWcslen( wchar.data() ) ; | |
713 | m_ubuf = malloc( m_chars * 2 + 2 ) ; | |
714 | memcpy( m_ubuf , (UniChar*) wchar.data() , m_chars * 2 + 2 ) ; | |
715 | #endif | |
716 | #endif | |
717 | } | |
718 | ||
719 | wxMacUniCharBuffer::~wxMacUniCharBuffer() | |
720 | { | |
721 | free( m_ubuf ) ; | |
722 | } | |
723 | ||
724 | UniCharPtr wxMacUniCharBuffer::GetBuffer() | |
725 | { | |
726 | return m_ubuf ; | |
727 | } | |
728 | ||
729 | UniCharCount wxMacUniCharBuffer::GetChars() | |
730 | { | |
731 | return m_chars ; | |
732 | } |