1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation "utils.h"
20 #include "wx/apptrait.h"
23 #include "wx/mac/uma.h"
34 # include "MoreFilesX.h"
36 # include "MoreFiles.h"
37 # include "MoreFilesExtras.h"
45 #include "ATSUnicode.h"
46 #include "TextCommon.h"
47 #include "TextEncodingConverter.h"
49 #include "wx/mac/private.h" // includes mac headers
51 #if defined(__MWERKS__) && wxUSE_UNICODE
55 // ---------------------------------------------------------------------------
56 // code used in both base and GUI compilation
57 // ---------------------------------------------------------------------------
59 // our OS version is the same in non GUI and GUI cases
60 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
64 // are there x-platform conventions ?
66 Gestalt(gestaltSystemVersion
, &theSystem
) ;
67 if (minorVsn
!= NULL
) {
68 *minorVsn
= (theSystem
& 0xFF ) ;
70 if (majorVsn
!= NULL
) {
71 *majorVsn
= (theSystem
>> 8 ) ;
83 // defined in unix/utilsunx.cpp for Mac OS X
85 // get full hostname (with domain name if possible)
86 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
88 return wxGetHostName(buf
, maxSize
);
91 // Get hostname only (without domain name)
92 bool wxGetHostName(wxChar
*buf
, int maxSize
)
94 // Gets Chooser name of user by examining a System resource.
96 const short kComputerNameID
= -16413;
98 short oldResFile
= CurResFile() ;
100 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
101 UseResFile(oldResFile
);
103 if (chooserName
&& *chooserName
)
105 HLock( (Handle
) chooserName
) ;
106 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
107 HUnlock( (Handle
) chooserName
) ;
108 ReleaseResource( (Handle
) chooserName
) ;
109 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
117 // Get user ID e.g. jacs
118 bool wxGetUserId(wxChar
*buf
, int maxSize
)
120 return wxGetUserName( buf
, maxSize
) ;
123 const wxChar
* wxGetHomeDir(wxString
*pstr
)
125 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
126 return pstr
->c_str() ;
129 // Get user name e.g. Stefan Csomor
130 bool wxGetUserName(wxChar
*buf
, int maxSize
)
132 // Gets Chooser name of user by examining a System resource.
134 const short kChooserNameID
= -16096;
136 short oldResFile
= CurResFile() ;
138 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
139 UseResFile(oldResFile
);
141 if (chooserName
&& *chooserName
)
143 HLock( (Handle
) chooserName
) ;
144 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
145 HUnlock( (Handle
) chooserName
) ;
146 ReleaseResource( (Handle
) chooserName
) ;
147 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
155 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
161 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
163 // TODO : under classic there is no environement support, under X yes
167 // set the env var name to the given value, return TRUE on success
168 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
170 // TODO : under classic there is no environement support, under X yes
175 // Execute a program in an Interactive Shell
177 bool wxShell(const wxString
& command
)
183 // Shutdown or reboot the PC
184 bool wxShutdown(wxShutdownFlags wFlags
)
190 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
191 long wxGetFreeMemory()
196 void wxUsleep(unsigned long milliseconds
)
198 clock_t start
= clock() ;
202 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
205 void wxSleep(int nSecs
)
207 wxUsleep(1000*nSecs
);
210 // Consume all events until no more left
215 #endif // !__DARWIN__
223 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
225 static wxToolkitInfo info
;
226 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
227 info
.name
= _T("wxBase");
235 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
237 static wxToolkitInfo info
;
238 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
239 info
.shortName
= _T("mac");
240 info
.name
= _T("wxMac");
241 #ifdef __WXUNIVERSAL__
242 info
.shortName
<< _T("univ");
243 info
.name
<< _T("/wxUniversal");
248 // Reading and writing resources (eg WIN.INI, .Xdefaults)
250 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
256 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
259 buf
.Printf(wxT("%.4f"), value
);
261 return wxWriteResource(section
, entry
, buf
, file
);
264 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
267 buf
.Printf(wxT("%ld"), value
);
269 return wxWriteResource(section
, entry
, buf
, file
);
272 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
275 buf
.Printf(wxT("%d"), value
);
277 return wxWriteResource(section
, entry
, buf
, file
);
280 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
286 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
289 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
292 *value
= (float)strtod(s
, NULL
);
299 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
302 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
305 *value
= strtol(s
, NULL
, 10);
312 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
315 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
318 *value
= (int)strtol(s
, NULL
, 10);
324 #endif // wxUSE_RESOURCES
326 int gs_wxBusyCursorCount
= 0;
327 extern wxCursor gMacCurrentCursor
;
328 wxCursor gMacStoredActiveCursor
;
330 // Set the cursor to the busy cursor for all windows
331 void wxBeginBusyCursor(wxCursor
*cursor
)
333 if (gs_wxBusyCursorCount
++ == 0)
335 gMacStoredActiveCursor
= gMacCurrentCursor
;
336 cursor
->MacInstall() ;
338 //else: nothing to do, already set
341 // Restore cursor to normal
342 void wxEndBusyCursor()
344 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
345 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
347 if (--gs_wxBusyCursorCount
== 0)
349 gMacStoredActiveCursor
.MacInstall() ;
350 gMacStoredActiveCursor
= wxNullCursor
;
354 // TRUE if we're between the above two calls
357 return (gs_wxBusyCursorCount
> 0);
364 wxString
wxMacFindFolder( short vol
,
366 Boolean createFolder
)
372 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
375 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
377 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
387 // Check whether this window wants to process messages, e.g. Stop button
388 // in long calculations.
389 bool wxCheckForInterrupt(wxWindow
*wnd
)
395 void wxGetMousePosition( int* x
, int* y
)
400 LocalToGlobal( &pt
) ;
405 // Return TRUE if we have a colour display
406 bool wxColourDisplay()
411 // Returns depth of screen
415 SetRect(&globRect
, -32760, -32760, 32760, 32760);
416 GDHandle theMaxDevice
;
419 theMaxDevice
= GetMaxDevice(&globRect
);
420 if (theMaxDevice
!= nil
)
421 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
426 // Get size of display
427 void wxDisplaySize(int *width
, int *height
)
430 GetQDGlobalsScreenBits( &screenBits
);
433 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
435 if (height
!= NULL
) {
436 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
440 void wxDisplaySizeMM(int *width
, int *height
)
442 wxDisplaySize(width
, height
);
443 // on mac 72 is fixed (at least now ;-)
444 float cvPt2Mm
= 25.4 / 72;
447 *width
= int( *width
* cvPt2Mm
);
449 if (height
!= NULL
) {
450 *height
= int( *height
* cvPt2Mm
);
454 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
457 GetQDGlobalsScreenBits( &screenBits
);
463 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
465 if (height
!= NULL
) {
466 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
471 GetThemeMenuBarHeight( &mheight
) ;
473 mheight
= LMGetMBarHeight() ;
475 if (height
!= NULL
) {
482 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
484 return wxGenericFindWindowAtPoint(pt
);
491 wxString
wxGetOsDescription()
493 #ifdef WXWIN_OS_DESCRIPTION
494 // use configure generated description if available
495 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
497 return wxT("MacOS") ; //TODO:define further
502 wxChar
*wxGetUserHome (const wxString
& user
)
508 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
518 int pos
= p
.Find(':') ;
519 if ( pos
!= wxNOT_FOUND
) {
528 wxMacStringToPascal( p
, volumeName
) ;
529 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
530 if ( err
== noErr
) {
532 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
535 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
539 return err
== noErr
;
541 #endif // !__DARWIN__
543 //---------------------------------------------------------------------------
544 // wxMac Specific utility functions
545 //---------------------------------------------------------------------------
549 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
550 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
551 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
552 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
553 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
554 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
556 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
557 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
558 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
559 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
560 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
561 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
563 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
568 for( int i
= 0 ; i
< len
; ++ i
)
570 c
= strchr( StringANSI
, *from
) ;
573 *to
= StringMac
[ c
- StringANSI
] ;
581 for( int i
= 0 ; i
< len
; ++ i
)
583 c
= strchr( StringANSI
, *from
) ;
586 *to
= StringMac
[ c
- StringANSI
] ;
598 void wxMacConvertToPC( const char *from
, char *to
, int len
)
603 for( int i
= 0 ; i
< len
; ++ i
)
605 c
= strchr( StringMac
, *from
) ;
608 *to
= StringANSI
[ c
- StringMac
] ;
616 for( int i
= 0 ; i
< len
; ++ i
)
618 c
= strchr( StringMac
, *from
) ;
621 *to
= StringANSI
[ c
- StringMac
] ;
633 TECObjectRef s_TECNativeCToUnicode
= NULL
;
634 TECObjectRef s_TECUnicodeToNativeC
= NULL
;
636 void wxMacSetupConverters()
638 // if we assume errors are happening here we need low level debugging
639 // since the high level assert will use the encoders that are not yet
642 const TextEncodingBase kEncoding
= CFStringGetSystemEncoding();
644 const TextEncodingBase kEncoding
= kTextEncodingMacRoman
;
646 OSStatus status
= noErr
;
647 status
= TECCreateConverter(&s_TECNativeCToUnicode
,
649 kTextEncodingUnicodeDefault
);
651 status
= TECCreateConverter(&s_TECUnicodeToNativeC
,
652 kTextEncodingUnicodeDefault
,
655 #if (wxUSE_UNICODE == 1) && (SIZEOF_WCHAR_T == 4)
656 TextEncoding kUnicode32
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
658 status
= TECCreateConverter(&s_TECUnicode16To32
,
659 kTextEncodingUnicodeDefault
,
661 status
= TECCreateConverter(&s_TECUnicode32To16
,
663 kTextEncodingUnicodeDefault
);
667 void wxMacCleanupConverters()
669 OSStatus status
= noErr
;
670 status
= TECDisposeConverter(s_TECNativeCToUnicode
);
671 status
= TECDisposeConverter(s_TECUnicodeToNativeC
);
674 wxWCharBuffer
wxMacStringToWString( const wxString
&from
)
677 wxWCharBuffer
result( from
.wc_str() ) ;
679 OSStatus status
= noErr
;
680 ByteCount byteOutLen
;
681 ByteCount byteInLen
= from
.Length() ;
682 ByteCount byteBufferLen
= byteInLen
* SIZEOF_WCHAR_T
;
683 wxWCharBuffer
result( from
.Length() ) ;
684 status
= TECConvertText(s_TECNativeCToUnicode
, (ConstTextPtr
)from
.c_str() , byteInLen
, &byteInLen
,
685 (TextPtr
)result
.data(), byteBufferLen
, &byteOutLen
);
686 result
.data()[byteOutLen
/SIZEOF_WCHAR_T
] = 0 ;
692 wxString
wxMacMakeStringFromCString( const char * from
, int len
)
694 OSStatus status
= noErr
;
696 wxChar
* buf
= result
.GetWriteBuf( len
) ;
698 ByteCount byteOutLen
;
699 ByteCount byteInLen
= len
;
700 ByteCount byteBufferLen
= len
* SIZEOF_WCHAR_T
;
702 status
= TECConvertText(s_TECNativeCToUnicode
, (ConstTextPtr
)from
, byteInLen
, &byteInLen
,
703 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
705 memcpy( buf
, from
, len
) ;
708 result
.UngetWriteBuf() ;
712 wxString
wxMacMakeStringFromCString( const char * from
)
714 return wxMacMakeStringFromCString( from
, strlen(from
) ) ;
717 wxCharBuffer
wxMacStringToCString( const wxString
&from
)
720 OSStatus status
= noErr
;
721 ByteCount byteOutLen
;
722 ByteCount byteInLen
= from
.Length() * SIZEOF_WCHAR_T
;
723 ByteCount byteBufferLen
= from
.Length() ;
724 wxCharBuffer
result( from
.Length() ) ;
725 status
= TECConvertText(s_TECUnicodeToNativeC
, (ConstTextPtr
)from
.wc_str() , byteInLen
, &byteInLen
,
726 (TextPtr
)result
.data(), byteBufferLen
, &byteOutLen
);
729 return wxCharBuffer( from
.c_str() ) ;
734 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
736 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
737 int len
= strlen(buf
) ;
742 memcpy( (char*) &to
[1] , buf
, len
) ;
745 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
747 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
751 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
753 TextEncodingBase enc
= 0 ;
757 case wxFONTENCODING_ISO8859_1
:
758 enc
= kTextEncodingISOLatin1
;
760 case wxFONTENCODING_ISO8859_2
:
761 enc
= kTextEncodingISOLatin2
;
763 case wxFONTENCODING_ISO8859_3
:
764 enc
= kTextEncodingISOLatin3
;
766 case wxFONTENCODING_ISO8859_4
:
767 enc
= kTextEncodingISOLatin4
;
769 case wxFONTENCODING_ISO8859_5
:
770 enc
= kTextEncodingISOLatinCyrillic
;
772 case wxFONTENCODING_ISO8859_6
:
773 enc
= kTextEncodingISOLatinArabic
;
775 case wxFONTENCODING_ISO8859_7
:
776 enc
= kTextEncodingISOLatinGreek
;
778 case wxFONTENCODING_ISO8859_8
:
779 enc
= kTextEncodingISOLatinHebrew
;
781 case wxFONTENCODING_ISO8859_9
:
782 enc
= kTextEncodingISOLatin5
;
784 case wxFONTENCODING_ISO8859_10
:
785 enc
= kTextEncodingISOLatin6
;
787 case wxFONTENCODING_ISO8859_13
:
788 enc
= kTextEncodingISOLatin7
;
790 case wxFONTENCODING_ISO8859_14
:
791 enc
= kTextEncodingISOLatin8
;
793 case wxFONTENCODING_ISO8859_15
:
794 enc
= kTextEncodingISOLatin9
;
797 case wxFONTENCODING_KOI8
:
798 enc
= kTextEncodingKOI8_R
;
800 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
801 enc
= kTextEncodingDOSRussian
;
804 case wxFONTENCODING_BULGARIAN :
808 case wxFONTENCODING_CP437
:
809 enc
=kTextEncodingDOSLatinUS
;
811 case wxFONTENCODING_CP850
:
812 enc
= kTextEncodingDOSLatin1
;
814 case wxFONTENCODING_CP852
:
815 enc
= kTextEncodingDOSLatin2
;
817 case wxFONTENCODING_CP855
:
818 enc
= kTextEncodingDOSCyrillic
;
820 case wxFONTENCODING_CP866
:
821 enc
=kTextEncodingDOSRussian
;
823 case wxFONTENCODING_CP874
:
824 enc
= kTextEncodingDOSThai
;
826 case wxFONTENCODING_CP932
:
827 enc
= kTextEncodingDOSJapanese
;
829 case wxFONTENCODING_CP936
:
830 enc
=kTextEncodingDOSChineseSimplif
;
832 case wxFONTENCODING_CP949
:
833 enc
= kTextEncodingDOSKorean
;
835 case wxFONTENCODING_CP950
:
836 enc
= kTextEncodingDOSChineseTrad
;
839 case wxFONTENCODING_CP1250
:
840 enc
= kTextEncodingWindowsLatin2
;
842 case wxFONTENCODING_CP1251
:
843 enc
=kTextEncodingWindowsCyrillic
;
845 case wxFONTENCODING_CP1252
:
846 enc
=kTextEncodingWindowsLatin1
;
848 case wxFONTENCODING_CP1253
:
849 enc
= kTextEncodingWindowsGreek
;
851 case wxFONTENCODING_CP1254
:
852 enc
= kTextEncodingWindowsLatin5
;
854 case wxFONTENCODING_CP1255
:
855 enc
=kTextEncodingWindowsHebrew
;
857 case wxFONTENCODING_CP1256
:
858 enc
=kTextEncodingWindowsArabic
;
860 case wxFONTENCODING_CP1257
:
861 enc
= kTextEncodingWindowsBalticRim
;
864 case wxFONTENCODING_UTF7
:
865 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
867 case wxFONTENCODING_UTF8
:
868 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
870 case wxFONTENCODING_EUC_JP
:
871 enc
= kTextEncodingEUC_JP
;
873 case wxFONTENCODING_UTF16BE
:
874 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
876 case wxFONTENCODING_UTF16LE
:
877 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
879 case wxFONTENCODING_UTF32BE
:
880 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
882 case wxFONTENCODING_UTF32LE
:
883 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
886 case wxFONTENCODING_MACROMAN
:
887 enc
= kTextEncodingMacRoman
;
889 case wxFONTENCODING_MACJAPANESE
:
890 enc
= kTextEncodingMacJapanese
;
892 case wxFONTENCODING_MACCHINESETRAD
:
893 enc
= kTextEncodingMacChineseTrad
;
895 case wxFONTENCODING_MACKOREAN
:
896 enc
= kTextEncodingMacKorean
;
898 case wxFONTENCODING_MACARABIC
:
899 enc
= kTextEncodingMacArabic
;
901 case wxFONTENCODING_MACHEBREW
:
902 enc
= kTextEncodingMacHebrew
;
904 case wxFONTENCODING_MACGREEK
:
905 enc
= kTextEncodingMacGreek
;
907 case wxFONTENCODING_MACCYRILLIC
:
908 enc
= kTextEncodingMacCyrillic
;
910 case wxFONTENCODING_MACDEVANAGARI
:
911 enc
= kTextEncodingMacDevanagari
;
913 case wxFONTENCODING_MACGURMUKHI
:
914 enc
= kTextEncodingMacGurmukhi
;
916 case wxFONTENCODING_MACGUJARATI
:
917 enc
= kTextEncodingMacGujarati
;
919 case wxFONTENCODING_MACORIYA
:
920 enc
= kTextEncodingMacOriya
;
922 case wxFONTENCODING_MACBENGALI
:
923 enc
= kTextEncodingMacBengali
;
925 case wxFONTENCODING_MACTAMIL
:
926 enc
= kTextEncodingMacTamil
;
928 case wxFONTENCODING_MACTELUGU
:
929 enc
= kTextEncodingMacTelugu
;
931 case wxFONTENCODING_MACKANNADA
:
932 enc
= kTextEncodingMacKannada
;
934 case wxFONTENCODING_MACMALAJALAM
:
935 enc
= kTextEncodingMacMalayalam
;
937 case wxFONTENCODING_MACSINHALESE
:
938 enc
= kTextEncodingMacSinhalese
;
940 case wxFONTENCODING_MACBURMESE
:
941 enc
= kTextEncodingMacBurmese
;
943 case wxFONTENCODING_MACKHMER
:
944 enc
= kTextEncodingMacKhmer
;
946 case wxFONTENCODING_MACTHAI
:
947 enc
= kTextEncodingMacThai
;
949 case wxFONTENCODING_MACLAOTIAN
:
950 enc
= kTextEncodingMacLaotian
;
952 case wxFONTENCODING_MACGEORGIAN
:
953 enc
= kTextEncodingMacGeorgian
;
955 case wxFONTENCODING_MACARMENIAN
:
956 enc
= kTextEncodingMacArmenian
;
958 case wxFONTENCODING_MACCHINESESIMP
:
959 enc
= kTextEncodingMacChineseSimp
;
961 case wxFONTENCODING_MACTIBETAN
:
962 enc
= kTextEncodingMacTibetan
;
964 case wxFONTENCODING_MACMONGOLIAN
:
965 enc
= kTextEncodingMacMongolian
;
967 case wxFONTENCODING_MACETHIOPIC
:
968 enc
= kTextEncodingMacEthiopic
;
970 case wxFONTENCODING_MACCENTRALEUR
:
971 enc
= kTextEncodingMacCentralEurRoman
;
973 case wxFONTENCODING_MACVIATNAMESE
:
974 enc
= kTextEncodingMacVietnamese
;
976 case wxFONTENCODING_MACARABICEXT
:
977 enc
= kTextEncodingMacExtArabic
;
979 case wxFONTENCODING_MACSYMBOL
:
980 enc
= kTextEncodingMacSymbol
;
982 case wxFONTENCODING_MACDINGBATS
:
983 enc
= kTextEncodingMacDingbats
;
985 case wxFONTENCODING_MACTURKISH
:
986 enc
= kTextEncodingMacTurkish
;
988 case wxFONTENCODING_MACCROATIAN
:
989 enc
= kTextEncodingMacCroatian
;
991 case wxFONTENCODING_MACICELANDIC
:
992 enc
= kTextEncodingMacIcelandic
;
994 case wxFONTENCODING_MACROMANIAN
:
995 enc
= kTextEncodingMacRomanian
;
997 case wxFONTENCODING_MACCELTIC
:
998 enc
= kTextEncodingMacCeltic
;
1000 case wxFONTENCODING_MACGAELIC
:
1001 enc
= kTextEncodingMacGaelic
;
1003 case wxFONTENCODING_MACKEYBOARD
:
1004 enc
= kTextEncodingMacKeyboardGlyphs
;
1010 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
1012 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
1016 case kTextEncodingISOLatin1
:
1017 enc
= wxFONTENCODING_ISO8859_1
;
1019 case kTextEncodingISOLatin2
:
1020 enc
= wxFONTENCODING_ISO8859_2
;
1022 case kTextEncodingISOLatin3
:
1023 enc
= wxFONTENCODING_ISO8859_3
;
1025 case kTextEncodingISOLatin4
:
1026 enc
= wxFONTENCODING_ISO8859_4
;
1028 case kTextEncodingISOLatinCyrillic
:
1029 enc
= wxFONTENCODING_ISO8859_5
;
1031 case kTextEncodingISOLatinArabic
:
1032 enc
= wxFONTENCODING_ISO8859_6
;
1034 case kTextEncodingISOLatinGreek
:
1035 enc
= wxFONTENCODING_ISO8859_7
;
1037 case kTextEncodingISOLatinHebrew
:
1038 enc
= wxFONTENCODING_ISO8859_8
;
1040 case kTextEncodingISOLatin5
:
1041 enc
= wxFONTENCODING_ISO8859_9
;
1043 case kTextEncodingISOLatin6
:
1044 enc
= wxFONTENCODING_ISO8859_10
;
1046 case kTextEncodingISOLatin7
:
1047 enc
= wxFONTENCODING_ISO8859_13
;
1049 case kTextEncodingISOLatin8
:
1050 enc
= wxFONTENCODING_ISO8859_14
;
1052 case kTextEncodingISOLatin9
:
1053 enc
=wxFONTENCODING_ISO8859_15
;
1056 case kTextEncodingKOI8_R
:
1057 enc
= wxFONTENCODING_KOI8
;
1061 enc = wxFONTENCODING_BULGARIAN;
1064 casekTextEncodingDOSLatinUS
:
1065 enc
= wxFONTENCODING_CP437
;
1067 case kTextEncodingDOSLatin1
:
1068 enc
= wxFONTENCODING_CP850
;
1070 case kTextEncodingDOSLatin2
:
1071 enc
=wxFONTENCODING_CP852
;
1073 case kTextEncodingDOSCyrillic
:
1074 enc
= wxFONTENCODING_CP855
;
1076 case kTextEncodingDOSRussian
:
1077 enc
= wxFONTENCODING_CP866
;
1079 case kTextEncodingDOSThai
:
1080 enc
=wxFONTENCODING_CP874
;
1082 case kTextEncodingDOSJapanese
:
1083 enc
= wxFONTENCODING_CP932
;
1085 case kTextEncodingDOSChineseSimplif
:
1086 enc
= wxFONTENCODING_CP936
;
1088 case kTextEncodingDOSKorean
:
1089 enc
= wxFONTENCODING_CP949
;
1091 case kTextEncodingDOSChineseTrad
:
1092 enc
= wxFONTENCODING_CP950
;
1095 case kTextEncodingWindowsLatin2
:
1096 enc
= wxFONTENCODING_CP1250
;
1098 case kTextEncodingWindowsCyrillic
:
1099 enc
= wxFONTENCODING_CP1251
;
1101 case kTextEncodingWindowsLatin1
:
1102 enc
= wxFONTENCODING_CP1252
;
1104 case kTextEncodingWindowsGreek
:
1105 enc
= wxFONTENCODING_CP1253
;
1107 case kTextEncodingWindowsLatin5
:
1108 enc
= wxFONTENCODING_CP1254
;
1110 case kTextEncodingWindowsHebrew
:
1111 enc
= wxFONTENCODING_CP1255
;
1113 case kTextEncodingWindowsArabic
:
1114 enc
= wxFONTENCODING_CP1256
;
1116 case kTextEncodingWindowsBalticRim
:
1117 enc
=wxFONTENCODING_CP1257
;
1119 case kTextEncodingEUC_JP
:
1120 enc
= wxFONTENCODING_EUC_JP
;
1123 case wxFONTENCODING_UTF7 :
1124 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1126 case wxFONTENCODING_UTF8 :
1127 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1129 case wxFONTENCODING_UTF16BE :
1130 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1132 case wxFONTENCODING_UTF16LE :
1133 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1135 case wxFONTENCODING_UTF32BE :
1136 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1138 case wxFONTENCODING_UTF32LE :
1139 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1142 case kTextEncodingMacRoman
:
1143 enc
= wxFONTENCODING_MACROMAN
;
1145 case kTextEncodingMacJapanese
:
1146 enc
= wxFONTENCODING_MACJAPANESE
;
1148 case kTextEncodingMacChineseTrad
:
1149 enc
= wxFONTENCODING_MACCHINESETRAD
;
1151 case kTextEncodingMacKorean
:
1152 enc
= wxFONTENCODING_MACKOREAN
;
1154 case kTextEncodingMacArabic
:
1155 enc
=wxFONTENCODING_MACARABIC
;
1157 case kTextEncodingMacHebrew
:
1158 enc
= wxFONTENCODING_MACHEBREW
;
1160 case kTextEncodingMacGreek
:
1161 enc
= wxFONTENCODING_MACGREEK
;
1163 case kTextEncodingMacCyrillic
:
1164 enc
= wxFONTENCODING_MACCYRILLIC
;
1166 case kTextEncodingMacDevanagari
:
1167 enc
= wxFONTENCODING_MACDEVANAGARI
;
1169 case kTextEncodingMacGurmukhi
:
1170 enc
= wxFONTENCODING_MACGURMUKHI
;
1172 case kTextEncodingMacGujarati
:
1173 enc
= wxFONTENCODING_MACGUJARATI
;
1175 case kTextEncodingMacOriya
:
1176 enc
=wxFONTENCODING_MACORIYA
;
1178 case kTextEncodingMacBengali
:
1179 enc
=wxFONTENCODING_MACBENGALI
;
1181 case kTextEncodingMacTamil
:
1182 enc
= wxFONTENCODING_MACTAMIL
;
1184 case kTextEncodingMacTelugu
:
1185 enc
= wxFONTENCODING_MACTELUGU
;
1187 case kTextEncodingMacKannada
:
1188 enc
= wxFONTENCODING_MACKANNADA
;
1190 case kTextEncodingMacMalayalam
:
1191 enc
= wxFONTENCODING_MACMALAJALAM
;
1193 case kTextEncodingMacSinhalese
:
1194 enc
= wxFONTENCODING_MACSINHALESE
;
1196 case kTextEncodingMacBurmese
:
1197 enc
= wxFONTENCODING_MACBURMESE
;
1199 case kTextEncodingMacKhmer
:
1200 enc
= wxFONTENCODING_MACKHMER
;
1202 case kTextEncodingMacThai
:
1203 enc
= wxFONTENCODING_MACTHAI
;
1205 case kTextEncodingMacLaotian
:
1206 enc
= wxFONTENCODING_MACLAOTIAN
;
1208 case kTextEncodingMacGeorgian
:
1209 enc
= wxFONTENCODING_MACGEORGIAN
;
1211 case kTextEncodingMacArmenian
:
1212 enc
= wxFONTENCODING_MACARMENIAN
;
1214 case kTextEncodingMacChineseSimp
:
1215 enc
= wxFONTENCODING_MACCHINESESIMP
;
1217 case kTextEncodingMacTibetan
:
1218 enc
= wxFONTENCODING_MACTIBETAN
;
1220 case kTextEncodingMacMongolian
:
1221 enc
= wxFONTENCODING_MACMONGOLIAN
;
1223 case kTextEncodingMacEthiopic
:
1224 enc
= wxFONTENCODING_MACETHIOPIC
;
1226 case kTextEncodingMacCentralEurRoman
:
1227 enc
= wxFONTENCODING_MACCENTRALEUR
;
1229 case kTextEncodingMacVietnamese
:
1230 enc
= wxFONTENCODING_MACVIATNAMESE
;
1232 case kTextEncodingMacExtArabic
:
1233 enc
= wxFONTENCODING_MACARABICEXT
;
1235 case kTextEncodingMacSymbol
:
1236 enc
= wxFONTENCODING_MACSYMBOL
;
1238 case kTextEncodingMacDingbats
:
1239 enc
= wxFONTENCODING_MACDINGBATS
;
1241 case kTextEncodingMacTurkish
:
1242 enc
= wxFONTENCODING_MACTURKISH
;
1244 case kTextEncodingMacCroatian
:
1245 enc
= wxFONTENCODING_MACCROATIAN
;
1247 case kTextEncodingMacIcelandic
:
1248 enc
= wxFONTENCODING_MACICELANDIC
;
1250 case kTextEncodingMacRomanian
:
1251 enc
= wxFONTENCODING_MACROMANIAN
;
1253 case kTextEncodingMacCeltic
:
1254 enc
= wxFONTENCODING_MACCELTIC
;
1256 case kTextEncodingMacGaelic
:
1257 enc
= wxFONTENCODING_MACGAELIC
;
1259 case kTextEncodingMacKeyboardGlyphs
:
1260 enc
= wxFONTENCODING_MACKEYBOARD
;
1266 #endif // wxUSE_BASE
1272 // CFStringRefs (Carbon only)
1277 #if (wxUSE_UNICODE == 1) && (SIZEOF_WCHAR_T == 4)
1279 TECObjectRef s_TECUnicode32To16
= NULL
;
1280 TECObjectRef s_TECUnicode16To32
= NULL
;
1282 class wxMacUnicodeConverters
1285 wxMacUnicodeConverters() ;
1286 ~wxMacUnicodeConverters() ;
1289 wxMacUnicodeConverters guard
;
1291 wxMacUnicodeConverters::wxMacUnicodeConverters()
1293 OSStatus status
= noErr
;
1294 TextEncoding kUnicode32
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
1295 TextEncoding kUnicode16
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
1297 status
= TECCreateConverter(&s_TECUnicode16To32
,
1300 status
= TECCreateConverter(&s_TECUnicode32To16
,
1305 wxMacUnicodeConverters::~wxMacUnicodeConverters()
1307 OSStatus status
= noErr
;
1308 status
= TECDisposeConverter(s_TECUnicode32To16
);
1309 status
= TECDisposeConverter(s_TECUnicode16To32
);
1312 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1313 void wxMacCFStringHolder::Assign( const wxString
&st
)
1316 wxMacConvertNewlines13To10( &str
) ;
1317 size_t len
= str
.Len() ;
1320 #if SIZEOF_WCHAR_T == 2
1321 unibuf
= (UniChar
*)str
.wc_str() ;
1323 OSStatus status
= noErr
;
1324 ByteCount byteOutLen
;
1325 ByteCount byteInLen
= len
* SIZEOF_WCHAR_T
;
1326 ByteCount byteBufferLen
= len
* sizeof( UniChar
) ;
1327 unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1328 status
= TECConvertText( s_TECUnicode32To16
, (ConstTextPtr
)str
.wc_str() , byteInLen
, &byteInLen
,
1329 (TextPtr
)unibuf
, byteBufferLen
, &byteOutLen
);
1331 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1333 #if SIZEOF_WCHAR_T == 2
1334 // as long as UniChar is the same as wchar_t nothing to do here
1339 #else // not wxUSE_UNICODE
1340 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1341 CFStringGetSystemEncoding() ) ;
1346 wxString
wxMacCFStringHolder::AsString()
1349 Size len
= CFStringGetLength( m_cfs
) ;
1350 wxChar
* buf
= result
.GetWriteBuf( len
) ;
1352 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , len
) , (UniChar
*) buf
) ;
1354 CFStringGetCString( m_cfs
, buf
, len
+1 , CFStringGetSystemEncoding() ) ;
1357 wxMacConvertNewlines10To13( buf
) ;
1358 result
.UngetWriteBuf() ;
1362 #endif //TARGET_CARBON
1364 void wxMacConvertNewlines13To10( char * data
)
1367 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1374 void wxMacConvertNewlines10To13( char * data
)
1377 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1384 void wxMacConvertNewlines13To10( wxString
* data
)
1386 size_t len
= data
->Length() ;
1388 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1391 wxString
temp(*data
) ;
1392 wxStringBuffer
buf(*data
,len
) ;
1393 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1395 wxMacConvertNewlines13To10( buf
) ;
1398 void wxMacConvertNewlines10To13( wxString
* data
)
1400 size_t len
= data
->Length() ;
1402 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1405 wxString
temp(*data
) ;
1406 wxStringBuffer
buf(*data
,len
) ;
1407 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1408 wxMacConvertNewlines10To13( buf
) ;
1413 void wxMacConvertNewlines13To10( wxChar
* data
)
1415 wxChar
* buf
= data
;
1416 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1423 void wxMacConvertNewlines10To13( wxChar
* data
)
1425 wxChar
* buf
= data
;
1426 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1434 // ----------------------------------------------------------------------------
1435 // debugging support
1436 // ----------------------------------------------------------------------------
1438 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1440 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1442 #ifndef __MetroNubUtils__
1443 #include "MetroNubUtils.h"
1447 #include <Gestalt.h>
1450 #if TARGET_API_MAC_CARBON
1452 #include <CodeFragments.h>
1454 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1456 ProcPtr gCallUniversalProc_Proc
= NULL
;
1460 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1462 static long fRunOnce
= false;
1464 /* ---------------------------------------------------------------------------
1466 --------------------------------------------------------------------------- */
1468 Boolean
IsMetroNubInstalled()
1475 gMetroNubEntry
= NULL
;
1477 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1479 /* look for MetroNub's Gestalt selector */
1480 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1483 #if TARGET_API_MAC_CARBON
1484 if (gCallUniversalProc_Proc
== NULL
)
1486 CFragConnectionID connectionID
;
1489 ProcPtr symbolAddress
;
1491 CFragSymbolClass symbolClass
;
1493 symbolAddress
= NULL
;
1494 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1495 &connectionID
, &mainAddress
, errorString
);
1499 gCallUniversalProc_Proc
= NULL
;
1503 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1504 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1508 gCallUniversalProc_Proc
= NULL
;
1515 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1517 /* make sure the version of the API is compatible */
1518 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1519 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1520 gMetroNubEntry
= block
; /* success! */
1529 #if TARGET_API_MAC_CARBON
1530 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1532 return (gMetroNubEntry
!= NULL
);
1536 /* ---------------------------------------------------------------------------
1537 IsMWDebuggerRunning [v1 API]
1538 --------------------------------------------------------------------------- */
1540 Boolean
IsMWDebuggerRunning()
1542 if (IsMetroNubInstalled())
1543 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1548 /* ---------------------------------------------------------------------------
1549 AmIBeingMWDebugged [v1 API]
1550 --------------------------------------------------------------------------- */
1552 Boolean
AmIBeingMWDebugged()
1554 if (IsMetroNubInstalled())
1555 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1560 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1562 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1567 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1572 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)