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