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