]>
Commit | Line | Data |
---|---|---|
2646f485 | 1 | ///////////////////////////////////////////////////////////////////////////// |
0ba6a836 | 2 | // Name: src/mac/classic/utils.cpp |
2646f485 SC |
3 | // Purpose: Various utilities |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 1998-01-01 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Stefan Csomor | |
88a7a4e1 | 9 | // Licence: wxWindows licence |
2646f485 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
0ba6a836 WS |
12 | #include "wx/wxprec.h" |
13 | ||
2646f485 | 14 | #include "wx/utils.h" |
88a7a4e1 WS |
15 | |
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/intl.h" | |
670f9935 | 18 | #include "wx/app.h" |
88a7a4e1 WS |
19 | #endif |
20 | ||
2646f485 SC |
21 | #include "wx/apptrait.h" |
22 | ||
23 | #if wxUSE_GUI | |
24 | #include "wx/mac/uma.h" | |
9d8aca48 | 25 | #include "wx/font.h" |
2646f485 SC |
26 | #endif |
27 | ||
28 | #include <ctype.h> | |
29 | ||
30 | #include <stdio.h> | |
31 | #include <stdlib.h> | |
32 | #include <string.h> | |
33 | #include <stdarg.h> | |
34 | ||
35 | #ifdef __DARWIN__ | |
36 | # include "MoreFilesX.h" | |
37 | #else | |
38 | # include "MoreFiles.h" | |
39 | # include "MoreFilesExtras.h" | |
40 | #endif | |
41 | ||
42 | #ifndef __DARWIN__ | |
43 | #include <Threads.h> | |
44 | #include <Sound.h> | |
45 | #endif | |
46 | ||
47 | #include <ATSUnicode.h> | |
48 | #include <TextCommon.h> | |
49 | #include <TextEncodingConverter.h> | |
50 | ||
51 | #include "wx/mac/private.h" // includes mac headers | |
52 | ||
53 | #if defined(__MWERKS__) && wxUSE_UNICODE | |
54 | #include <wtime.h> | |
55 | #endif | |
56 | ||
57 | // --------------------------------------------------------------------------- | |
58 | // code used in both base and GUI compilation | |
59 | // --------------------------------------------------------------------------- | |
60 | ||
61 | // our OS version is the same in non GUI and GUI cases | |
62 | static int DoGetOSVersion(int *majorVsn, int *minorVsn) | |
63 | { | |
64 | long theSystem ; | |
65 | ||
66 | // are there x-platform conventions ? | |
67 | ||
68 | Gestalt(gestaltSystemVersion, &theSystem) ; | |
69 | if (minorVsn != NULL) { | |
70 | *minorVsn = (theSystem & 0xFF ) ; | |
71 | } | |
72 | if (majorVsn != NULL) { | |
73 | *majorVsn = (theSystem >> 8 ) ; | |
74 | } | |
75 | #ifdef __DARWIN__ | |
76 | return wxMAC_DARWIN; | |
77 | #else | |
78 | return wxMAC; | |
79 | #endif | |
80 | } | |
81 | ||
82 | #if wxUSE_BASE | |
83 | ||
84 | #ifndef __DARWIN__ | |
85 | // defined in unix/utilsunx.cpp for Mac OS X | |
86 | ||
87 | // get full hostname (with domain name if possible) | |
88 | bool wxGetFullHostName(wxChar *buf, int maxSize) | |
89 | { | |
90 | return wxGetHostName(buf, maxSize); | |
91 | } | |
92 | ||
93 | // Get hostname only (without domain name) | |
94 | bool wxGetHostName(wxChar *buf, int maxSize) | |
95 | { | |
96 | // Gets Chooser name of user by examining a System resource. | |
97 | ||
98 | const short kComputerNameID = -16413; | |
99 | ||
100 | short oldResFile = CurResFile() ; | |
101 | UseResFile(0); | |
102 | StringHandle chooserName = (StringHandle)::GetString(kComputerNameID); | |
103 | UseResFile(oldResFile); | |
104 | ||
105 | if (chooserName && *chooserName) | |
106 | { | |
107 | HLock( (Handle) chooserName ) ; | |
108 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
109 | HUnlock( (Handle) chooserName ) ; | |
110 | ReleaseResource( (Handle) chooserName ) ; | |
111 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
112 | } | |
113 | else | |
114 | buf[0] = 0 ; | |
115 | ||
9d8aca48 | 116 | return true; |
2646f485 SC |
117 | } |
118 | ||
119 | // Get user ID e.g. jacs | |
120 | bool wxGetUserId(wxChar *buf, int maxSize) | |
121 | { | |
122 | return wxGetUserName( buf , maxSize ) ; | |
123 | } | |
124 | ||
125 | const wxChar* wxGetHomeDir(wxString *pstr) | |
126 | { | |
127 | *pstr = wxMacFindFolder( (short) kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder ) ; | |
128 | return pstr->c_str() ; | |
129 | } | |
130 | ||
131 | // Get user name e.g. Stefan Csomor | |
132 | bool wxGetUserName(wxChar *buf, int maxSize) | |
133 | { | |
134 | // Gets Chooser name of user by examining a System resource. | |
135 | ||
136 | const short kChooserNameID = -16096; | |
137 | ||
138 | short oldResFile = CurResFile() ; | |
139 | UseResFile(0); | |
140 | StringHandle chooserName = (StringHandle)::GetString(kChooserNameID); | |
141 | UseResFile(oldResFile); | |
142 | ||
143 | if (chooserName && *chooserName) | |
144 | { | |
145 | HLock( (Handle) chooserName ) ; | |
146 | wxString name = wxMacMakeStringFromPascal( *chooserName ) ; | |
147 | HUnlock( (Handle) chooserName ) ; | |
148 | ReleaseResource( (Handle) chooserName ) ; | |
149 | wxStrncpy( buf , name , maxSize - 1 ) ; | |
150 | } | |
151 | else | |
152 | buf[0] = 0 ; | |
153 | ||
9d8aca48 | 154 | return true; |
2646f485 SC |
155 | } |
156 | ||
e0f6b731 | 157 | int wxKill(long pid, wxSignal sig , wxKillError *rc, int flags) |
2646f485 SC |
158 | { |
159 | // TODO | |
160 | return 0; | |
161 | } | |
162 | ||
163 | WXDLLEXPORT bool wxGetEnv(const wxString& var, wxString *value) | |
164 | { | |
165 | // TODO : under classic there is no environement support, under X yes | |
166 | return false ; | |
167 | } | |
168 | ||
9d8aca48 | 169 | // set the env var name to the given value, return true on success |
2646f485 SC |
170 | WXDLLEXPORT bool wxSetEnv(const wxString& var, const wxChar *value) |
171 | { | |
172 | // TODO : under classic there is no environement support, under X yes | |
173 | return false ; | |
174 | } | |
175 | ||
176 | // | |
177 | // Execute a program in an Interactive Shell | |
178 | // | |
179 | bool wxShell(const wxString& command) | |
180 | { | |
181 | // TODO | |
9d8aca48 | 182 | return false; |
2646f485 SC |
183 | } |
184 | ||
185 | // Shutdown or reboot the PC | |
186 | bool wxShutdown(wxShutdownFlags wFlags) | |
187 | { | |
188 | // TODO | |
9d8aca48 | 189 | return false; |
2646f485 SC |
190 | } |
191 | ||
192 | // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX) | |
9d8aca48 | 193 | wxMemorySize wxGetFreeMemory() |
2646f485 | 194 | { |
9d8aca48 | 195 | return (wxMemorySize)FreeMem() ; |
2646f485 SC |
196 | } |
197 | ||
198 | void wxUsleep(unsigned long milliseconds) | |
199 | { | |
200 | clock_t start = clock() ; | |
201 | do | |
202 | { | |
203 | YieldToAnyThread() ; | |
204 | } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ; | |
205 | } | |
206 | ||
207 | void wxSleep(int nSecs) | |
208 | { | |
209 | wxUsleep(1000*nSecs); | |
210 | } | |
211 | ||
212 | // Consume all events until no more left | |
213 | void wxFlushEvents() | |
214 | { | |
215 | } | |
216 | ||
217 | #endif // !__DARWIN__ | |
218 | ||
219 | // Emit a beeeeeep | |
220 | void wxBell() | |
221 | { | |
222 | SysBeep(30); | |
223 | } | |
224 | ||
225 | wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() | |
226 | { | |
227 | static wxToolkitInfo info; | |
228 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); | |
229 | info.name = _T("wxBase"); | |
230 | return info; | |
231 | } | |
232 | ||
233 | #endif // wxUSE_BASE | |
234 | ||
235 | #if wxUSE_GUI | |
236 | ||
237 | wxToolkitInfo& wxGUIAppTraits::GetToolkitInfo() | |
238 | { | |
239 | static wxToolkitInfo info; | |
240 | info.os = DoGetOSVersion(&info.versionMajor, &info.versionMinor); | |
241 | info.shortName = _T("mac"); | |
242 | info.name = _T("wxMac"); | |
243 | #ifdef __WXUNIVERSAL__ | |
244 | info.shortName << _T("univ"); | |
245 | info.name << _T("/wxUniversal"); | |
246 | #endif | |
247 | return info; | |
248 | } | |
249 | ||
250 | // Reading and writing resources (eg WIN.INI, .Xdefaults) | |
251 | #if wxUSE_RESOURCES | |
252 | bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file) | |
253 | { | |
254 | // TODO | |
9d8aca48 | 255 | return false; |
2646f485 SC |
256 | } |
257 | ||
258 | bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file) | |
259 | { | |
260 | wxString buf; | |
261 | buf.Printf(wxT("%.4f"), value); | |
262 | ||
263 | return wxWriteResource(section, entry, buf, file); | |
264 | } | |
265 | ||
266 | bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file) | |
267 | { | |
268 | wxString buf; | |
269 | buf.Printf(wxT("%ld"), value); | |
270 | ||
271 | return wxWriteResource(section, entry, buf, file); | |
272 | } | |
273 | ||
274 | bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file) | |
275 | { | |
276 | wxString buf; | |
277 | buf.Printf(wxT("%d"), value); | |
278 | ||
279 | return wxWriteResource(section, entry, buf, file); | |
280 | } | |
281 | ||
282 | bool wxGetResource(const wxString& section, const wxString& entry, char **value, const wxString& file) | |
283 | { | |
284 | // TODO | |
9d8aca48 | 285 | return false; |
2646f485 SC |
286 | } |
287 | ||
288 | bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file) | |
289 | { | |
290 | char *s = NULL; | |
291 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
292 | if (succ) | |
293 | { | |
294 | *value = (float)strtod(s, NULL); | |
295 | delete[] s; | |
9d8aca48 | 296 | return true; |
2646f485 | 297 | } |
9d8aca48 | 298 | else return false; |
2646f485 SC |
299 | } |
300 | ||
301 | bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file) | |
302 | { | |
303 | char *s = NULL; | |
304 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
305 | if (succ) | |
306 | { | |
307 | *value = strtol(s, NULL, 10); | |
308 | delete[] s; | |
9d8aca48 | 309 | return true; |
2646f485 | 310 | } |
9d8aca48 | 311 | else return false; |
2646f485 SC |
312 | } |
313 | ||
314 | bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file) | |
315 | { | |
316 | char *s = NULL; | |
317 | bool succ = wxGetResource(section, entry, (char **)&s, file); | |
318 | if (succ) | |
319 | { | |
320 | *value = (int)strtol(s, NULL, 10); | |
321 | delete[] s; | |
9d8aca48 | 322 | return true; |
2646f485 | 323 | } |
9d8aca48 | 324 | else return false; |
2646f485 SC |
325 | } |
326 | #endif // wxUSE_RESOURCES | |
327 | ||
328 | int gs_wxBusyCursorCount = 0; | |
329 | extern wxCursor gMacCurrentCursor ; | |
330 | wxCursor gMacStoredActiveCursor ; | |
331 | ||
332 | // Set the cursor to the busy cursor for all windows | |
f516d986 | 333 | void wxBeginBusyCursor(const wxCursor *cursor) |
2646f485 SC |
334 | { |
335 | if (gs_wxBusyCursorCount++ == 0) | |
336 | { | |
337 | gMacStoredActiveCursor = gMacCurrentCursor ; | |
338 | cursor->MacInstall() ; | |
339 | } | |
340 | //else: nothing to do, already set | |
341 | } | |
342 | ||
343 | // Restore cursor to normal | |
344 | void wxEndBusyCursor() | |
345 | { | |
346 | wxCHECK_RET( gs_wxBusyCursorCount > 0, | |
347 | wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") ); | |
348 | ||
349 | if (--gs_wxBusyCursorCount == 0) | |
350 | { | |
351 | gMacStoredActiveCursor.MacInstall() ; | |
352 | gMacStoredActiveCursor = wxNullCursor ; | |
353 | } | |
354 | } | |
355 | ||
9d8aca48 | 356 | // true if we're between the above two calls |
2646f485 SC |
357 | bool wxIsBusy() |
358 | { | |
359 | return (gs_wxBusyCursorCount > 0); | |
360 | } | |
361 | ||
362 | #endif // wxUSE_GUI | |
363 | ||
364 | #if wxUSE_BASE | |
365 | ||
17af82fb | 366 | wxString wxMacFindFolderNoSeparator( short vol, |
2646f485 SC |
367 | OSType folderType, |
368 | Boolean createFolder) | |
369 | { | |
370 | short vRefNum ; | |
371 | long dirID ; | |
372 | wxString strDir ; | |
373 | ||
374 | if ( FindFolder( vol, folderType, createFolder, &vRefNum, &dirID) == noErr) | |
375 | { | |
376 | FSSpec file ; | |
377 | if ( FSMakeFSSpec( vRefNum , dirID , "\p" , &file ) == noErr ) | |
378 | { | |
17af82fb | 379 | strDir = wxMacFSSpec2MacFilename( &file ); |
2646f485 SC |
380 | } |
381 | } | |
382 | return strDir ; | |
383 | } | |
384 | ||
17af82fb VZ |
385 | wxString wxMacFindFolder( short vol, |
386 | OSType folderType, | |
387 | Boolean createFolder) | |
388 | { | |
389 | return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH; | |
390 | } | |
391 | ||
2646f485 SC |
392 | #endif // wxUSE_BASE |
393 | ||
394 | #if wxUSE_GUI | |
395 | ||
396 | // Check whether this window wants to process messages, e.g. Stop button | |
397 | // in long calculations. | |
398 | bool wxCheckForInterrupt(wxWindow *wnd) | |
399 | { | |
400 | // TODO | |
9d8aca48 | 401 | return false; |
2646f485 SC |
402 | } |
403 | ||
404 | void wxGetMousePosition( int* x, int* y ) | |
405 | { | |
406 | Point pt ; | |
407 | ||
408 | GetMouse( &pt ) ; | |
409 | LocalToGlobal( &pt ) ; | |
410 | *x = pt.h ; | |
411 | *y = pt.v ; | |
412 | }; | |
413 | ||
9d8aca48 | 414 | // Return true if we have a colour display |
2646f485 SC |
415 | bool wxColourDisplay() |
416 | { | |
9d8aca48 | 417 | return true; |
2646f485 SC |
418 | } |
419 | ||
420 | // Returns depth of screen | |
421 | int wxDisplayDepth() | |
422 | { | |
423 | Rect globRect ; | |
424 | SetRect(&globRect, -32760, -32760, 32760, 32760); | |
425 | GDHandle theMaxDevice; | |
426 | ||
427 | int theDepth = 8; | |
428 | theMaxDevice = GetMaxDevice(&globRect); | |
429 | if (theMaxDevice != nil) | |
430 | theDepth = (**(**theMaxDevice).gdPMap).pixelSize; | |
431 | ||
432 | return theDepth ; | |
433 | } | |
434 | ||
435 | // Get size of display | |
436 | void wxDisplaySize(int *width, int *height) | |
437 | { | |
438 | BitMap screenBits; | |
439 | GetQDGlobalsScreenBits( &screenBits ); | |
440 | ||
441 | if (width != NULL) { | |
442 | *width = screenBits.bounds.right - screenBits.bounds.left ; | |
443 | } | |
444 | if (height != NULL) { | |
445 | *height = screenBits.bounds.bottom - screenBits.bounds.top ; | |
446 | } | |
447 | } | |
448 | ||
449 | void wxDisplaySizeMM(int *width, int *height) | |
450 | { | |
451 | wxDisplaySize(width, height); | |
452 | // on mac 72 is fixed (at least now ;-) | |
453 | float cvPt2Mm = 25.4 / 72; | |
454 | ||
455 | if (width != NULL) { | |
456 | *width = int( *width * cvPt2Mm ); | |
457 | } | |
458 | if (height != NULL) { | |
459 | *height = int( *height * cvPt2Mm ); | |
460 | } | |
461 | } | |
462 | ||
463 | void wxClientDisplayRect(int *x, int *y, int *width, int *height) | |
464 | { | |
465 | #if TARGET_CARBON | |
466 | Rect r ; | |
467 | GetAvailableWindowPositioningBounds( GetMainDevice() , &r ) ; | |
468 | if ( x ) | |
469 | *x = r.left ; | |
470 | if ( y ) | |
471 | *y = r.top ; | |
472 | if ( width ) | |
473 | *width = r.right - r.left ; | |
474 | if ( height ) | |
475 | *height = r.bottom - r.top ; | |
476 | #else | |
477 | BitMap screenBits; | |
478 | GetQDGlobalsScreenBits( &screenBits ); | |
479 | ||
480 | if (x) *x = 0; | |
481 | if (y) *y = 0; | |
482 | ||
483 | if (width != NULL) { | |
484 | *width = screenBits.bounds.right - screenBits.bounds.left ; | |
485 | } | |
486 | if (height != NULL) { | |
487 | *height = screenBits.bounds.bottom - screenBits.bounds.top ; | |
488 | } | |
489 | ||
490 | SInt16 mheight ; | |
491 | #if TARGET_CARBON | |
492 | GetThemeMenuBarHeight( &mheight ) ; | |
493 | #else | |
494 | mheight = LMGetMBarHeight() ; | |
495 | #endif | |
496 | if (height != NULL) { | |
497 | *height -= mheight ; | |
498 | } | |
499 | if (y) | |
500 | *y = mheight ; | |
501 | #endif | |
502 | } | |
503 | ||
504 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) | |
505 | { | |
506 | return wxGenericFindWindowAtPoint(pt); | |
507 | } | |
508 | ||
509 | #endif // wxUSE_GUI | |
510 | ||
511 | #if wxUSE_BASE | |
512 | ||
513 | wxString wxGetOsDescription() | |
514 | { | |
515 | #ifdef WXWIN_OS_DESCRIPTION | |
516 | // use configure generated description if available | |
517 | return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")")); | |
518 | #else | |
519 | return wxT("MacOS") ; //TODO:define further | |
520 | #endif | |
521 | } | |
522 | ||
523 | #ifndef __DARWIN__ | |
524 | wxChar *wxGetUserHome (const wxString& user) | |
525 | { | |
526 | // TODO | |
527 | return NULL; | |
528 | } | |
529 | ||
7ba7c4e6 | 530 | bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree) |
2646f485 SC |
531 | { |
532 | if ( path.empty() ) | |
9d8aca48 | 533 | return false; |
2646f485 SC |
534 | |
535 | wxString p = path ; | |
536 | if (p[0u] == ':' ) { | |
537 | p = wxGetCwd() + p ; | |
538 | } | |
539 | ||
540 | int pos = p.Find(':') ; | |
541 | if ( pos != wxNOT_FOUND ) { | |
542 | p = p.Mid(1,pos) ; | |
543 | } | |
544 | ||
545 | p = p + wxT(":") ; | |
546 | ||
547 | Str255 volumeName ; | |
548 | XVolumeParam pb ; | |
549 | ||
550 | wxMacStringToPascal( p , volumeName ) ; | |
551 | OSErr err = XGetVolumeInfoNoName( volumeName , 0 , &pb ) ; | |
552 | if ( err == noErr ) { | |
553 | if ( pTotal ) { | |
7ba7c4e6 | 554 | (*pTotal) = wxDiskspaceSize_t( pb.ioVTotalBytes ) ; |
2646f485 SC |
555 | } |
556 | if ( pFree ) { | |
7ba7c4e6 | 557 | (*pFree) = wxDiskspaceSize_t( pb.ioVFreeBytes ) ; |
2646f485 SC |
558 | } |
559 | } | |
560 | ||
561 | return err == noErr ; | |
562 | } | |
563 | #endif // !__DARWIN__ | |
564 | ||
565 | //--------------------------------------------------------------------------- | |
566 | // wxMac Specific utility functions | |
567 | //--------------------------------------------------------------------------- | |
568 | ||
569 | void wxMacStringToPascal( const wxString&from , StringPtr to ) | |
570 | { | |
571 | wxCharBuffer buf = from.mb_str( wxConvLocal ) ; | |
572 | int len = strlen(buf) ; | |
573 | ||
574 | if ( len > 255 ) | |
575 | len = 255 ; | |
576 | to[0] = len ; | |
577 | memcpy( (char*) &to[1] , buf , len ) ; | |
578 | } | |
579 | ||
580 | wxString wxMacMakeStringFromPascal( ConstStringPtr from ) | |
581 | { | |
582 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ) ; | |
583 | } | |
584 | ||
585 | ||
586 | wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) | |
9d8aca48 WS |
587 | { |
588 | TextEncodingBase enc = 0 ; | |
589 | if ( encoding == wxFONTENCODING_DEFAULT ) | |
590 | { | |
2646f485 | 591 | #if wxUSE_GUI |
9d8aca48 | 592 | encoding = wxFont::GetDefaultEncoding() ; |
2646f485 | 593 | #else |
9d8aca48 | 594 | encoding = wxLocale::GetSystemEncoding() ; |
2646f485 | 595 | #endif |
9d8aca48 WS |
596 | } |
597 | ||
598 | switch( encoding) | |
599 | { | |
600 | case wxFONTENCODING_ISO8859_1 : | |
601 | enc = kTextEncodingISOLatin1 ; | |
602 | break ; | |
603 | case wxFONTENCODING_ISO8859_2 : | |
604 | enc = kTextEncodingISOLatin2; | |
605 | break ; | |
606 | case wxFONTENCODING_ISO8859_3 : | |
607 | enc = kTextEncodingISOLatin3 ; | |
608 | break ; | |
609 | case wxFONTENCODING_ISO8859_4 : | |
610 | enc = kTextEncodingISOLatin4; | |
611 | break ; | |
612 | case wxFONTENCODING_ISO8859_5 : | |
613 | enc = kTextEncodingISOLatinCyrillic; | |
614 | break ; | |
615 | case wxFONTENCODING_ISO8859_6 : | |
616 | enc = kTextEncodingISOLatinArabic; | |
617 | break ; | |
618 | case wxFONTENCODING_ISO8859_7 : | |
619 | enc = kTextEncodingISOLatinGreek; | |
620 | break ; | |
621 | case wxFONTENCODING_ISO8859_8 : | |
622 | enc = kTextEncodingISOLatinHebrew; | |
623 | break ; | |
624 | case wxFONTENCODING_ISO8859_9 : | |
625 | enc = kTextEncodingISOLatin5; | |
626 | break ; | |
627 | case wxFONTENCODING_ISO8859_10 : | |
628 | enc = kTextEncodingISOLatin6; | |
629 | break ; | |
630 | case wxFONTENCODING_ISO8859_13 : | |
631 | enc = kTextEncodingISOLatin7; | |
632 | break ; | |
633 | case wxFONTENCODING_ISO8859_14 : | |
634 | enc = kTextEncodingISOLatin8; | |
635 | break ; | |
636 | case wxFONTENCODING_ISO8859_15 : | |
637 | enc = kTextEncodingISOLatin9; | |
638 | break ; | |
639 | ||
640 | case wxFONTENCODING_KOI8 : | |
641 | enc = kTextEncodingKOI8_R; | |
642 | break ; | |
643 | case wxFONTENCODING_ALTERNATIVE : // MS-DOS CP866 | |
644 | enc = kTextEncodingDOSRussian; | |
645 | break ; | |
2646f485 | 646 | /* |
9d8aca48 WS |
647 | case wxFONTENCODING_BULGARIAN : |
648 | enc = ; | |
649 | break ; | |
650 | */ | |
651 | case wxFONTENCODING_CP437 : | |
652 | enc =kTextEncodingDOSLatinUS ; | |
653 | break ; | |
654 | case wxFONTENCODING_CP850 : | |
655 | enc = kTextEncodingDOSLatin1; | |
656 | break ; | |
657 | case wxFONTENCODING_CP852 : | |
658 | enc = kTextEncodingDOSLatin2; | |
659 | break ; | |
660 | case wxFONTENCODING_CP855 : | |
661 | enc = kTextEncodingDOSCyrillic; | |
662 | break ; | |
663 | case wxFONTENCODING_CP866 : | |
664 | enc =kTextEncodingDOSRussian ; | |
665 | break ; | |
666 | case wxFONTENCODING_CP874 : | |
667 | enc = kTextEncodingDOSThai; | |
668 | break ; | |
669 | case wxFONTENCODING_CP932 : | |
670 | enc = kTextEncodingDOSJapanese; | |
671 | break ; | |
672 | case wxFONTENCODING_CP936 : | |
673 | enc =kTextEncodingDOSChineseSimplif ; | |
674 | break ; | |
675 | case wxFONTENCODING_CP949 : | |
676 | enc = kTextEncodingDOSKorean; | |
677 | break ; | |
678 | case wxFONTENCODING_CP950 : | |
679 | enc = kTextEncodingDOSChineseTrad; | |
680 | break ; | |
681 | ||
682 | case wxFONTENCODING_CP1250 : | |
683 | enc = kTextEncodingWindowsLatin2; | |
684 | break ; | |
685 | case wxFONTENCODING_CP1251 : | |
686 | enc =kTextEncodingWindowsCyrillic ; | |
687 | break ; | |
688 | case wxFONTENCODING_CP1252 : | |
689 | enc =kTextEncodingWindowsLatin1 ; | |
690 | break ; | |
691 | case wxFONTENCODING_CP1253 : | |
692 | enc = kTextEncodingWindowsGreek; | |
693 | break ; | |
694 | case wxFONTENCODING_CP1254 : | |
695 | enc = kTextEncodingWindowsLatin5; | |
696 | break ; | |
697 | case wxFONTENCODING_CP1255 : | |
698 | enc =kTextEncodingWindowsHebrew ; | |
699 | break ; | |
700 | case wxFONTENCODING_CP1256 : | |
701 | enc =kTextEncodingWindowsArabic ; | |
702 | break ; | |
703 | case wxFONTENCODING_CP1257 : | |
704 | enc = kTextEncodingWindowsBalticRim; | |
705 | break ; | |
706 | ||
707 | case wxFONTENCODING_UTF7 : | |
708 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
709 | break ; | |
710 | case wxFONTENCODING_UTF8 : | |
711 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ; | |
712 | break ; | |
713 | case wxFONTENCODING_EUC_JP : | |
714 | enc = kTextEncodingEUC_JP; | |
715 | break ; | |
716 | case wxFONTENCODING_UTF16BE : | |
717 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
718 | break ; | |
719 | case wxFONTENCODING_UTF16LE : | |
720 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
721 | break ; | |
722 | case wxFONTENCODING_UTF32BE : | |
723 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
724 | break ; | |
725 | case wxFONTENCODING_UTF32LE : | |
726 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
727 | break ; | |
2646f485 SC |
728 | |
729 | case wxFONTENCODING_MACROMAN : | |
730 | enc = kTextEncodingMacRoman ; | |
731 | break ; | |
732 | case wxFONTENCODING_MACJAPANESE : | |
733 | enc = kTextEncodingMacJapanese ; | |
734 | break ; | |
735 | case wxFONTENCODING_MACCHINESETRAD : | |
736 | enc = kTextEncodingMacChineseTrad ; | |
737 | break ; | |
738 | case wxFONTENCODING_MACKOREAN : | |
739 | enc = kTextEncodingMacKorean ; | |
740 | break ; | |
741 | case wxFONTENCODING_MACARABIC : | |
742 | enc = kTextEncodingMacArabic ; | |
743 | break ; | |
744 | case wxFONTENCODING_MACHEBREW : | |
745 | enc = kTextEncodingMacHebrew ; | |
746 | break ; | |
747 | case wxFONTENCODING_MACGREEK : | |
748 | enc = kTextEncodingMacGreek ; | |
749 | break ; | |
750 | case wxFONTENCODING_MACCYRILLIC : | |
751 | enc = kTextEncodingMacCyrillic ; | |
752 | break ; | |
753 | case wxFONTENCODING_MACDEVANAGARI : | |
754 | enc = kTextEncodingMacDevanagari ; | |
755 | break ; | |
756 | case wxFONTENCODING_MACGURMUKHI : | |
757 | enc = kTextEncodingMacGurmukhi ; | |
758 | break ; | |
759 | case wxFONTENCODING_MACGUJARATI : | |
760 | enc = kTextEncodingMacGujarati ; | |
761 | break ; | |
762 | case wxFONTENCODING_MACORIYA : | |
763 | enc = kTextEncodingMacOriya ; | |
764 | break ; | |
765 | case wxFONTENCODING_MACBENGALI : | |
766 | enc = kTextEncodingMacBengali ; | |
767 | break ; | |
768 | case wxFONTENCODING_MACTAMIL : | |
769 | enc = kTextEncodingMacTamil ; | |
770 | break ; | |
771 | case wxFONTENCODING_MACTELUGU : | |
772 | enc = kTextEncodingMacTelugu ; | |
773 | break ; | |
774 | case wxFONTENCODING_MACKANNADA : | |
775 | enc = kTextEncodingMacKannada ; | |
776 | break ; | |
777 | case wxFONTENCODING_MACMALAJALAM : | |
778 | enc = kTextEncodingMacMalayalam ; | |
779 | break ; | |
780 | case wxFONTENCODING_MACSINHALESE : | |
781 | enc = kTextEncodingMacSinhalese ; | |
782 | break ; | |
783 | case wxFONTENCODING_MACBURMESE : | |
784 | enc = kTextEncodingMacBurmese ; | |
785 | break ; | |
786 | case wxFONTENCODING_MACKHMER : | |
787 | enc = kTextEncodingMacKhmer ; | |
788 | break ; | |
789 | case wxFONTENCODING_MACTHAI : | |
790 | enc = kTextEncodingMacThai ; | |
791 | break ; | |
792 | case wxFONTENCODING_MACLAOTIAN : | |
793 | enc = kTextEncodingMacLaotian ; | |
794 | break ; | |
795 | case wxFONTENCODING_MACGEORGIAN : | |
796 | enc = kTextEncodingMacGeorgian ; | |
797 | break ; | |
798 | case wxFONTENCODING_MACARMENIAN : | |
799 | enc = kTextEncodingMacArmenian ; | |
800 | break ; | |
801 | case wxFONTENCODING_MACCHINESESIMP : | |
802 | enc = kTextEncodingMacChineseSimp ; | |
803 | break ; | |
804 | case wxFONTENCODING_MACTIBETAN : | |
805 | enc = kTextEncodingMacTibetan ; | |
806 | break ; | |
807 | case wxFONTENCODING_MACMONGOLIAN : | |
808 | enc = kTextEncodingMacMongolian ; | |
809 | break ; | |
810 | case wxFONTENCODING_MACETHIOPIC : | |
811 | enc = kTextEncodingMacEthiopic ; | |
812 | break ; | |
813 | case wxFONTENCODING_MACCENTRALEUR : | |
814 | enc = kTextEncodingMacCentralEurRoman ; | |
815 | break ; | |
816 | case wxFONTENCODING_MACVIATNAMESE : | |
817 | enc = kTextEncodingMacVietnamese ; | |
818 | break ; | |
819 | case wxFONTENCODING_MACARABICEXT : | |
820 | enc = kTextEncodingMacExtArabic ; | |
821 | break ; | |
822 | case wxFONTENCODING_MACSYMBOL : | |
823 | enc = kTextEncodingMacSymbol ; | |
824 | break ; | |
825 | case wxFONTENCODING_MACDINGBATS : | |
826 | enc = kTextEncodingMacDingbats ; | |
827 | break ; | |
828 | case wxFONTENCODING_MACTURKISH : | |
829 | enc = kTextEncodingMacTurkish ; | |
830 | break ; | |
831 | case wxFONTENCODING_MACCROATIAN : | |
832 | enc = kTextEncodingMacCroatian ; | |
833 | break ; | |
834 | case wxFONTENCODING_MACICELANDIC : | |
835 | enc = kTextEncodingMacIcelandic ; | |
836 | break ; | |
837 | case wxFONTENCODING_MACROMANIAN : | |
838 | enc = kTextEncodingMacRomanian ; | |
839 | break ; | |
840 | case wxFONTENCODING_MACCELTIC : | |
841 | enc = kTextEncodingMacCeltic ; | |
842 | break ; | |
843 | case wxFONTENCODING_MACGAELIC : | |
844 | enc = kTextEncodingMacGaelic ; | |
845 | break ; | |
846 | case wxFONTENCODING_MACKEYBOARD : | |
847 | enc = kTextEncodingMacKeyboardGlyphs ; | |
9d8aca48 WS |
848 | break ; |
849 | default : | |
850 | // to make gcc happy | |
851 | break ; | |
852 | } ; | |
853 | return enc ; | |
2646f485 SC |
854 | } |
855 | ||
856 | wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) | |
9d8aca48 WS |
857 | { |
858 | wxFontEncoding enc = wxFONTENCODING_DEFAULT ; | |
859 | ||
860 | switch( encoding) | |
861 | { | |
862 | case kTextEncodingISOLatin1 : | |
863 | enc = wxFONTENCODING_ISO8859_1 ; | |
864 | break ; | |
865 | case kTextEncodingISOLatin2 : | |
866 | enc = wxFONTENCODING_ISO8859_2; | |
867 | break ; | |
868 | case kTextEncodingISOLatin3 : | |
869 | enc = wxFONTENCODING_ISO8859_3 ; | |
870 | break ; | |
871 | case kTextEncodingISOLatin4 : | |
872 | enc = wxFONTENCODING_ISO8859_4; | |
873 | break ; | |
874 | case kTextEncodingISOLatinCyrillic : | |
875 | enc = wxFONTENCODING_ISO8859_5; | |
876 | break ; | |
877 | case kTextEncodingISOLatinArabic : | |
878 | enc = wxFONTENCODING_ISO8859_6; | |
879 | break ; | |
880 | case kTextEncodingISOLatinGreek : | |
881 | enc = wxFONTENCODING_ISO8859_7; | |
882 | break ; | |
883 | case kTextEncodingISOLatinHebrew : | |
884 | enc = wxFONTENCODING_ISO8859_8; | |
885 | break ; | |
886 | case kTextEncodingISOLatin5 : | |
887 | enc = wxFONTENCODING_ISO8859_9; | |
888 | break ; | |
889 | case kTextEncodingISOLatin6 : | |
890 | enc = wxFONTENCODING_ISO8859_10; | |
891 | break ; | |
892 | case kTextEncodingISOLatin7 : | |
893 | enc = wxFONTENCODING_ISO8859_13; | |
894 | break ; | |
895 | case kTextEncodingISOLatin8 : | |
896 | enc = wxFONTENCODING_ISO8859_14; | |
897 | break ; | |
898 | case kTextEncodingISOLatin9 : | |
899 | enc =wxFONTENCODING_ISO8859_15 ; | |
900 | break ; | |
901 | ||
902 | case kTextEncodingKOI8_R : | |
903 | enc = wxFONTENCODING_KOI8; | |
904 | break ; | |
2646f485 | 905 | /* |
9d8aca48 WS |
906 | case : |
907 | enc = wxFONTENCODING_BULGARIAN; | |
908 | break ; | |
909 | */ | |
910 | case kTextEncodingDOSLatinUS : | |
911 | enc = wxFONTENCODING_CP437; | |
912 | break ; | |
913 | case kTextEncodingDOSLatin1 : | |
914 | enc = wxFONTENCODING_CP850; | |
915 | break ; | |
916 | case kTextEncodingDOSLatin2 : | |
917 | enc =wxFONTENCODING_CP852 ; | |
918 | break ; | |
919 | case kTextEncodingDOSCyrillic : | |
920 | enc = wxFONTENCODING_CP855; | |
921 | break ; | |
922 | case kTextEncodingDOSRussian : | |
923 | enc = wxFONTENCODING_CP866; | |
924 | break ; | |
925 | case kTextEncodingDOSThai : | |
926 | enc =wxFONTENCODING_CP874 ; | |
927 | break ; | |
928 | case kTextEncodingDOSJapanese : | |
929 | enc = wxFONTENCODING_CP932; | |
930 | break ; | |
931 | case kTextEncodingDOSChineseSimplif : | |
932 | enc = wxFONTENCODING_CP936; | |
933 | break ; | |
934 | case kTextEncodingDOSKorean : | |
935 | enc = wxFONTENCODING_CP949; | |
936 | break ; | |
937 | case kTextEncodingDOSChineseTrad : | |
938 | enc = wxFONTENCODING_CP950; | |
939 | break ; | |
940 | ||
941 | case kTextEncodingWindowsLatin2 : | |
942 | enc = wxFONTENCODING_CP1250; | |
943 | break ; | |
944 | case kTextEncodingWindowsCyrillic : | |
945 | enc = wxFONTENCODING_CP1251; | |
946 | break ; | |
947 | case kTextEncodingWindowsLatin1 : | |
948 | enc = wxFONTENCODING_CP1252; | |
949 | break ; | |
950 | case kTextEncodingWindowsGreek : | |
951 | enc = wxFONTENCODING_CP1253; | |
952 | break ; | |
953 | case kTextEncodingWindowsLatin5 : | |
954 | enc = wxFONTENCODING_CP1254; | |
955 | break ; | |
956 | case kTextEncodingWindowsHebrew : | |
957 | enc = wxFONTENCODING_CP1255; | |
958 | break ; | |
959 | case kTextEncodingWindowsArabic : | |
960 | enc = wxFONTENCODING_CP1256; | |
961 | break ; | |
962 | case kTextEncodingWindowsBalticRim : | |
963 | enc =wxFONTENCODING_CP1257 ; | |
964 | break ; | |
965 | case kTextEncodingEUC_JP : | |
966 | enc = wxFONTENCODING_EUC_JP; | |
967 | break ; | |
968 | /* | |
969 | case wxFONTENCODING_UTF7 : | |
970 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ; | |
971 | break ; | |
972 | case wxFONTENCODING_UTF8 : | |
973 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ; | |
974 | break ; | |
975 | case wxFONTENCODING_UTF16BE : | |
976 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
977 | break ; | |
978 | case wxFONTENCODING_UTF16LE : | |
979 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ; | |
980 | break ; | |
981 | case wxFONTENCODING_UTF32BE : | |
982 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
983 | break ; | |
984 | case wxFONTENCODING_UTF32LE : | |
985 | enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ; | |
986 | break ; | |
2646f485 SC |
987 | */ |
988 | case kTextEncodingMacRoman : | |
989 | enc = wxFONTENCODING_MACROMAN ; | |
990 | break ; | |
991 | case kTextEncodingMacJapanese : | |
992 | enc = wxFONTENCODING_MACJAPANESE ; | |
993 | break ; | |
994 | case kTextEncodingMacChineseTrad : | |
995 | enc = wxFONTENCODING_MACCHINESETRAD ; | |
996 | break ; | |
997 | case kTextEncodingMacKorean : | |
998 | enc = wxFONTENCODING_MACKOREAN ; | |
999 | break ; | |
1000 | case kTextEncodingMacArabic : | |
1001 | enc =wxFONTENCODING_MACARABIC ; | |
1002 | break ; | |
1003 | case kTextEncodingMacHebrew : | |
1004 | enc = wxFONTENCODING_MACHEBREW ; | |
1005 | break ; | |
1006 | case kTextEncodingMacGreek : | |
1007 | enc = wxFONTENCODING_MACGREEK ; | |
1008 | break ; | |
1009 | case kTextEncodingMacCyrillic : | |
1010 | enc = wxFONTENCODING_MACCYRILLIC ; | |
1011 | break ; | |
1012 | case kTextEncodingMacDevanagari : | |
1013 | enc = wxFONTENCODING_MACDEVANAGARI ; | |
1014 | break ; | |
1015 | case kTextEncodingMacGurmukhi : | |
1016 | enc = wxFONTENCODING_MACGURMUKHI ; | |
1017 | break ; | |
1018 | case kTextEncodingMacGujarati : | |
1019 | enc = wxFONTENCODING_MACGUJARATI ; | |
1020 | break ; | |
1021 | case kTextEncodingMacOriya : | |
1022 | enc =wxFONTENCODING_MACORIYA ; | |
1023 | break ; | |
1024 | case kTextEncodingMacBengali : | |
1025 | enc =wxFONTENCODING_MACBENGALI ; | |
1026 | break ; | |
1027 | case kTextEncodingMacTamil : | |
1028 | enc = wxFONTENCODING_MACTAMIL ; | |
1029 | break ; | |
1030 | case kTextEncodingMacTelugu : | |
1031 | enc = wxFONTENCODING_MACTELUGU ; | |
1032 | break ; | |
1033 | case kTextEncodingMacKannada : | |
1034 | enc = wxFONTENCODING_MACKANNADA ; | |
1035 | break ; | |
1036 | case kTextEncodingMacMalayalam : | |
1037 | enc = wxFONTENCODING_MACMALAJALAM ; | |
1038 | break ; | |
1039 | case kTextEncodingMacSinhalese : | |
1040 | enc = wxFONTENCODING_MACSINHALESE ; | |
1041 | break ; | |
1042 | case kTextEncodingMacBurmese : | |
1043 | enc = wxFONTENCODING_MACBURMESE ; | |
1044 | break ; | |
1045 | case kTextEncodingMacKhmer : | |
1046 | enc = wxFONTENCODING_MACKHMER ; | |
1047 | break ; | |
1048 | case kTextEncodingMacThai : | |
1049 | enc = wxFONTENCODING_MACTHAI ; | |
1050 | break ; | |
1051 | case kTextEncodingMacLaotian : | |
1052 | enc = wxFONTENCODING_MACLAOTIAN ; | |
1053 | break ; | |
1054 | case kTextEncodingMacGeorgian : | |
1055 | enc = wxFONTENCODING_MACGEORGIAN ; | |
1056 | break ; | |
1057 | case kTextEncodingMacArmenian : | |
1058 | enc = wxFONTENCODING_MACARMENIAN ; | |
1059 | break ; | |
1060 | case kTextEncodingMacChineseSimp : | |
1061 | enc = wxFONTENCODING_MACCHINESESIMP ; | |
1062 | break ; | |
1063 | case kTextEncodingMacTibetan : | |
1064 | enc = wxFONTENCODING_MACTIBETAN ; | |
1065 | break ; | |
1066 | case kTextEncodingMacMongolian : | |
1067 | enc = wxFONTENCODING_MACMONGOLIAN ; | |
1068 | break ; | |
1069 | case kTextEncodingMacEthiopic : | |
1070 | enc = wxFONTENCODING_MACETHIOPIC ; | |
1071 | break ; | |
1072 | case kTextEncodingMacCentralEurRoman: | |
1073 | enc = wxFONTENCODING_MACCENTRALEUR ; | |
1074 | break ; | |
1075 | case kTextEncodingMacVietnamese: | |
1076 | enc = wxFONTENCODING_MACVIATNAMESE ; | |
1077 | break ; | |
1078 | case kTextEncodingMacExtArabic : | |
1079 | enc = wxFONTENCODING_MACARABICEXT ; | |
1080 | break ; | |
1081 | case kTextEncodingMacSymbol : | |
1082 | enc = wxFONTENCODING_MACSYMBOL ; | |
1083 | break ; | |
1084 | case kTextEncodingMacDingbats : | |
1085 | enc = wxFONTENCODING_MACDINGBATS ; | |
1086 | break ; | |
1087 | case kTextEncodingMacTurkish : | |
1088 | enc = wxFONTENCODING_MACTURKISH ; | |
1089 | break ; | |
1090 | case kTextEncodingMacCroatian : | |
1091 | enc = wxFONTENCODING_MACCROATIAN ; | |
1092 | break ; | |
1093 | case kTextEncodingMacIcelandic : | |
1094 | enc = wxFONTENCODING_MACICELANDIC ; | |
1095 | break ; | |
1096 | case kTextEncodingMacRomanian : | |
1097 | enc = wxFONTENCODING_MACROMANIAN ; | |
1098 | break ; | |
1099 | case kTextEncodingMacCeltic : | |
1100 | enc = wxFONTENCODING_MACCELTIC ; | |
1101 | break ; | |
1102 | case kTextEncodingMacGaelic : | |
1103 | enc = wxFONTENCODING_MACGAELIC ; | |
1104 | break ; | |
1105 | case kTextEncodingMacKeyboardGlyphs : | |
1106 | enc = wxFONTENCODING_MACKEYBOARD ; | |
9d8aca48 WS |
1107 | break ; |
1108 | } ; | |
1109 | return enc ; | |
2646f485 SC |
1110 | } |
1111 | ||
1112 | #endif // wxUSE_BASE | |
1113 | ||
1114 | #if wxUSE_GUI | |
1115 | ||
1116 | ||
1117 | // | |
1118 | // CFStringRefs (Carbon only) | |
1119 | // | |
1120 | ||
1121 | #if TARGET_CARBON | |
1122 | ||
1123 | // converts this string into a carbon foundation string with optional pc 2 mac encoding | |
1124 | void wxMacCFStringHolder::Assign( const wxString &st , wxFontEncoding encoding ) | |
1125 | { | |
9d8aca48 | 1126 | Release() ; |
2646f485 | 1127 | |
9d8aca48 | 1128 | wxString str = st ; |
2646f485 SC |
1129 | wxMacConvertNewlines13To10( &str ) ; |
1130 | #if wxUSE_UNICODE | |
1131 | #if SIZEOF_WCHAR_T == 2 | |
9d8aca48 WS |
1132 | m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault, |
1133 | (UniChar*)str.wc_str() , str.Len() ); | |
2646f485 | 1134 | #else |
9d8aca48 | 1135 | wxMBConvUTF16BE converter ; |
2646f485 SC |
1136 | size_t unicharlen = converter.WC2MB( NULL , str.wc_str() , 0 ) ; |
1137 | UniChar *unibuf = new UniChar[ unicharlen / sizeof(UniChar) + 1 ] ; | |
1138 | converter.WC2MB( (char*)unibuf , str.wc_str() , unicharlen ) ; | |
1139 | m_cfs = CFStringCreateWithCharacters( kCFAllocatorDefault , | |
1140 | unibuf , unicharlen / sizeof(UniChar) ) ; | |
1141 | delete[] unibuf ; | |
1142 | #endif | |
1143 | #else // not wxUSE_UNICODE | |
1144 | m_cfs = CFStringCreateWithCString( kCFAllocatorSystemDefault , str.c_str() , | |
1145 | wxMacGetSystemEncFromFontEnc( encoding ) ) ; | |
1146 | #endif | |
1147 | m_release = true ; | |
1148 | } | |
1149 | ||
1150 | wxString wxMacCFStringHolder::AsString(wxFontEncoding encoding) | |
1151 | { | |
1152 | Size cflen = CFStringGetLength( m_cfs ) ; | |
1153 | size_t noChars ; | |
1154 | wxChar* buf = NULL ; | |
9d8aca48 | 1155 | |
2646f485 SC |
1156 | #if wxUSE_UNICODE |
1157 | #if SIZEOF_WCHAR_T == 2 | |
9d8aca48 | 1158 | buf = new wxChar[ cflen + 1 ] ; |
2646f485 SC |
1159 | CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) buf ) ; |
1160 | noChars = cflen ; | |
1161 | #else | |
1162 | UniChar* unibuf = new UniChar[ cflen + 1 ] ; | |
1163 | CFStringGetCharacters( m_cfs , CFRangeMake( 0 , cflen ) , (UniChar*) unibuf ) ; | |
1164 | unibuf[cflen] = 0 ; | |
9d8aca48 WS |
1165 | wxMBConvUTF16BE converter ; |
1166 | noChars = converter.MB2WC( NULL , (const char*)unibuf , 0 ) ; | |
2646f485 SC |
1167 | buf = new wxChar[ noChars + 1 ] ; |
1168 | converter.MB2WC( buf , (const char*)unibuf , noChars ) ; | |
1169 | delete[] unibuf ; | |
1170 | #endif | |
1171 | #else | |
1172 | CFIndex cStrLen ; | |
1173 | CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , | |
1174 | '?' , false , NULL , 0 , &cStrLen ) ; | |
9d8aca48 | 1175 | buf = new wxChar[ cStrLen + 1 ] ; |
2646f485 SC |
1176 | CFStringGetBytes( m_cfs , CFRangeMake(0, cflen) , wxMacGetSystemEncFromFontEnc( encoding ) , |
1177 | '?' , false , (unsigned char*) buf , cStrLen , &cStrLen) ; | |
1178 | noChars = cStrLen ; | |
1179 | #endif | |
1180 | ||
1181 | buf[noChars] = 0 ; | |
1182 | wxMacConvertNewlines10To13( buf ) ; | |
1183 | wxString result(buf) ; | |
1184 | delete[] buf ; | |
1185 | return result ; | |
1186 | } | |
1187 | ||
1188 | #endif //TARGET_CARBON | |
1189 | ||
9d8aca48 WS |
1190 | void wxMacConvertNewlines13To10( char * data ) |
1191 | { | |
1192 | char * buf = data ; | |
2646f485 SC |
1193 | while( (buf=strchr(buf,0x0d)) != NULL ) |
1194 | { | |
1195 | *buf = 0x0a ; | |
1196 | buf++ ; | |
1197 | } | |
1198 | } | |
1199 | ||
1200 | void wxMacConvertNewlines10To13( char * data ) | |
9d8aca48 WS |
1201 | { |
1202 | char * buf = data ; | |
2646f485 SC |
1203 | while( (buf=strchr(buf,0x0a)) != NULL ) |
1204 | { | |
1205 | *buf = 0x0d ; | |
1206 | buf++ ; | |
1207 | } | |
1208 | } | |
1209 | ||
9d8aca48 WS |
1210 | void wxMacConvertNewlines13To10( wxString * data ) |
1211 | { | |
88a7a4e1 | 1212 | size_t len = data->length() ; |
2646f485 SC |
1213 | |
1214 | if ( len == 0 || wxStrchr(data->c_str(),0x0d)==NULL) | |
1215 | return ; | |
9d8aca48 | 1216 | |
2646f485 SC |
1217 | wxString temp(*data) ; |
1218 | wxStringBuffer buf(*data,len ) ; | |
9d8aca48 | 1219 | memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; |
2646f485 | 1220 | |
9d8aca48 | 1221 | wxMacConvertNewlines13To10( buf ) ; |
2646f485 SC |
1222 | } |
1223 | ||
1224 | void wxMacConvertNewlines10To13( wxString * data ) | |
9d8aca48 | 1225 | { |
88a7a4e1 | 1226 | size_t len = data->length() ; |
2646f485 | 1227 | |
88a7a4e1 | 1228 | if ( data->empty() || wxStrchr(data->c_str(),0x0a)==NULL) |
2646f485 SC |
1229 | return ; |
1230 | ||
1231 | wxString temp(*data) ; | |
1232 | wxStringBuffer buf(*data,len ) ; | |
9d8aca48 WS |
1233 | memcpy( buf , temp.c_str() , (len+1)*sizeof(wxChar) ) ; |
1234 | wxMacConvertNewlines10To13( buf ) ; | |
2646f485 SC |
1235 | } |
1236 | ||
1237 | ||
1238 | #if wxUSE_UNICODE | |
9d8aca48 WS |
1239 | void wxMacConvertNewlines13To10( wxChar * data ) |
1240 | { | |
1241 | wxChar * buf = data ; | |
2646f485 SC |
1242 | while( (buf=wxStrchr(buf,0x0d)) != NULL ) |
1243 | { | |
1244 | *buf = 0x0a ; | |
1245 | buf++ ; | |
1246 | } | |
1247 | } | |
1248 | ||
1249 | void wxMacConvertNewlines10To13( wxChar * data ) | |
9d8aca48 WS |
1250 | { |
1251 | wxChar * buf = data ; | |
2646f485 SC |
1252 | while( (buf=wxStrchr(buf,0x0a)) != NULL ) |
1253 | { | |
1254 | *buf = 0x0d ; | |
1255 | buf++ ; | |
1256 | } | |
1257 | } | |
1258 | #endif | |
1259 | ||
1260 | // ---------------------------------------------------------------------------- | |
1261 | // debugging support | |
1262 | // ---------------------------------------------------------------------------- | |
1263 | ||
1264 | #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400) | |
1265 | ||
1266 | // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds... | |
1267 | ||
1268 | #ifndef __MetroNubUtils__ | |
1269 | #include "MetroNubUtils.h" | |
1270 | #endif | |
1271 | ||
1272 | #ifndef __GESTALT__ | |
1273 | #include <Gestalt.h> | |
1274 | #endif | |
1275 | ||
1276 | #if TARGET_API_MAC_CARBON | |
1277 | ||
1278 | #include <CodeFragments.h> | |
1279 | ||
1280 | extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr, ProcInfoType procInfo, ...); | |
1281 | ||
1282 | ProcPtr gCallUniversalProc_Proc = NULL; | |
1283 | ||
1284 | #endif | |
1285 | ||
1286 | static MetroNubUserEntryBlock* gMetroNubEntry = NULL; | |
1287 | ||
1288 | static long fRunOnce = false; | |
1289 | ||
1290 | /* --------------------------------------------------------------------------- | |
1291 | IsMetroNubInstalled | |
1292 | --------------------------------------------------------------------------- */ | |
1293 | ||
1294 | Boolean IsMetroNubInstalled() | |
1295 | { | |
1296 | if (!fRunOnce) | |
1297 | { | |
1298 | long result, value; | |
1299 | ||
1300 | fRunOnce = true; | |
1301 | gMetroNubEntry = NULL; | |
1302 | ||
1303 | if (Gestalt(gestaltSystemVersion, &value) == noErr && value < 0x1000) | |
1304 | { | |
1305 | /* look for MetroNub's Gestalt selector */ | |
1306 | if (Gestalt(kMetroNubUserSignature, &result) == noErr) | |
1307 | { | |
1308 | ||
1309 | #if TARGET_API_MAC_CARBON | |
1310 | if (gCallUniversalProc_Proc == NULL) | |
1311 | { | |
1312 | CFragConnectionID connectionID; | |
1313 | Ptr mainAddress; | |
1314 | Str255 errorString; | |
1315 | ProcPtr symbolAddress; | |
1316 | OSErr err; | |
1317 | CFragSymbolClass symbolClass; | |
1318 | ||
1319 | symbolAddress = NULL; | |
1320 | err = GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch, kFindCFrag, | |
1321 | &connectionID, &mainAddress, errorString); | |
1322 | ||
1323 | if (err != noErr) | |
1324 | { | |
1325 | gCallUniversalProc_Proc = NULL; | |
1326 | goto end; | |
1327 | } | |
1328 | ||
1329 | err = FindSymbol(connectionID, "\pCallUniversalProc", | |
1330 | (Ptr *) &gCallUniversalProc_Proc, &symbolClass); | |
1331 | ||
1332 | if (err != noErr) | |
1333 | { | |
1334 | gCallUniversalProc_Proc = NULL; | |
1335 | goto end; | |
1336 | } | |
1337 | } | |
1338 | #endif | |
1339 | ||
1340 | { | |
1341 | MetroNubUserEntryBlock* block = (MetroNubUserEntryBlock *)result; | |
1342 | ||
1343 | /* make sure the version of the API is compatible */ | |
1344 | if (block->apiLowVersion <= kMetroNubUserAPIVersion && | |
1345 | kMetroNubUserAPIVersion <= block->apiHiVersion) | |
1346 | gMetroNubEntry = block; /* success! */ | |
1347 | } | |
1348 | ||
1349 | } | |
1350 | } | |
1351 | } | |
1352 | ||
1353 | end: | |
1354 | ||
1355 | #if TARGET_API_MAC_CARBON | |
1356 | return (gMetroNubEntry != NULL && gCallUniversalProc_Proc != NULL); | |
1357 | #else | |
1358 | return (gMetroNubEntry != NULL); | |
1359 | #endif | |
1360 | } | |
1361 | ||
1362 | /* --------------------------------------------------------------------------- | |
1363 | IsMWDebuggerRunning [v1 API] | |
1364 | --------------------------------------------------------------------------- */ | |
1365 | ||
1366 | Boolean IsMWDebuggerRunning() | |
1367 | { | |
1368 | if (IsMetroNubInstalled()) | |
1369 | return CallIsDebuggerRunningProc(gMetroNubEntry->isDebuggerRunning); | |
1370 | else | |
1371 | return false; | |
1372 | } | |
1373 | ||
1374 | /* --------------------------------------------------------------------------- | |
1375 | AmIBeingMWDebugged [v1 API] | |
1376 | --------------------------------------------------------------------------- */ | |
1377 | ||
1378 | Boolean AmIBeingMWDebugged() | |
1379 | { | |
1380 | if (IsMetroNubInstalled()) | |
1381 | return CallAmIBeingDebuggedProc(gMetroNubEntry->amIBeingDebugged); | |
1382 | else | |
1383 | return false; | |
1384 | } | |
1385 | ||
1386 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
1387 | { | |
1388 | return IsMWDebuggerRunning() && AmIBeingMWDebugged(); | |
1389 | } | |
1390 | ||
1391 | #else | |
1392 | ||
1393 | extern bool WXDLLEXPORT wxIsDebuggerRunning() | |
1394 | { | |
1395 | return false; | |
1396 | } | |
1397 | ||
1398 | #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400) | |
1399 | ||
1400 | #endif // wxUSE_GUI |