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