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"
37 # include "MoreFilesX.h"
39 # include "MoreFiles.h"
40 # include "MoreFilesExtras.h"
48 #include "ATSUnicode.h"
49 #include "TextCommon.h"
50 #include "TextEncodingConverter.h"
52 #include "wx/mac/private.h" // includes mac headers
54 #if defined(__MWERKS__) && wxUSE_UNICODE
58 // ---------------------------------------------------------------------------
59 // code used in both base and GUI compilation
60 // ---------------------------------------------------------------------------
62 // our OS version is the same in non GUI and GUI cases
63 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
67 // are there x-platform conventions ?
69 Gestalt(gestaltSystemVersion
, &theSystem
) ;
70 if (minorVsn
!= NULL
) {
71 *minorVsn
= (theSystem
& 0xFF ) ;
73 if (majorVsn
!= NULL
) {
74 *majorVsn
= (theSystem
>> 8 ) ;
86 // defined in unix/utilsunx.cpp for Mac OS X
88 // get full hostname (with domain name if possible)
89 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
91 return wxGetHostName(buf
, maxSize
);
94 // Get hostname only (without domain name)
95 bool wxGetHostName(wxChar
*buf
, int maxSize
)
97 // Gets Chooser name of user by examining a System resource.
99 const short kComputerNameID
= -16413;
101 short oldResFile
= CurResFile() ;
103 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
104 UseResFile(oldResFile
);
106 if (chooserName
&& *chooserName
)
108 HLock( (Handle
) chooserName
) ;
109 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
110 HUnlock( (Handle
) chooserName
) ;
111 ReleaseResource( (Handle
) chooserName
) ;
112 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
120 // Get user ID e.g. jacs
121 bool wxGetUserId(wxChar
*buf
, int maxSize
)
123 return wxGetUserName( buf
, maxSize
) ;
126 const wxChar
* wxGetHomeDir(wxString
*pstr
)
128 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
129 return pstr
->c_str() ;
132 // Get user name e.g. Stefan Csomor
133 bool wxGetUserName(wxChar
*buf
, int maxSize
)
135 // Gets Chooser name of user by examining a System resource.
137 const short kChooserNameID
= -16096;
139 short oldResFile
= CurResFile() ;
141 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
142 UseResFile(oldResFile
);
144 if (chooserName
&& *chooserName
)
146 HLock( (Handle
) chooserName
) ;
147 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
148 HUnlock( (Handle
) chooserName
) ;
149 ReleaseResource( (Handle
) chooserName
) ;
150 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
158 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
164 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
166 // TODO : under classic there is no environement support, under X yes
170 // set the env var name to the given value, return TRUE on success
171 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
173 // TODO : under classic there is no environement support, under X yes
178 // Execute a program in an Interactive Shell
180 bool wxShell(const wxString
& command
)
186 // Shutdown or reboot the PC
187 bool wxShutdown(wxShutdownFlags wFlags
)
193 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
194 long wxGetFreeMemory()
199 void wxUsleep(unsigned long milliseconds
)
201 clock_t start
= clock() ;
205 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
208 void wxSleep(int nSecs
)
210 wxUsleep(1000*nSecs
);
213 // Consume all events until no more left
218 #endif // !__DARWIN__
226 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
228 static wxToolkitInfo info
;
229 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
230 info
.name
= _T("wxBase");
238 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
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");
251 // Reading and writing resources (eg WIN.INI, .Xdefaults)
253 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
259 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
262 buf
.Printf(wxT("%.4f"), value
);
264 return wxWriteResource(section
, entry
, buf
, file
);
267 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
270 buf
.Printf(wxT("%ld"), value
);
272 return wxWriteResource(section
, entry
, buf
, file
);
275 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
278 buf
.Printf(wxT("%d"), value
);
280 return wxWriteResource(section
, entry
, buf
, file
);
283 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
289 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
292 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
295 *value
= (float)strtod(s
, NULL
);
302 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
305 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
308 *value
= strtol(s
, NULL
, 10);
315 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
318 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
321 *value
= (int)strtol(s
, NULL
, 10);
327 #endif // wxUSE_RESOURCES
329 int gs_wxBusyCursorCount
= 0;
330 extern wxCursor gMacCurrentCursor
;
331 wxCursor gMacStoredActiveCursor
;
333 // Set the cursor to the busy cursor for all windows
334 void wxBeginBusyCursor(wxCursor
*cursor
)
336 if (gs_wxBusyCursorCount
++ == 0)
338 gMacStoredActiveCursor
= gMacCurrentCursor
;
339 cursor
->MacInstall() ;
341 //else: nothing to do, already set
344 // Restore cursor to normal
345 void wxEndBusyCursor()
347 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
348 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
350 if (--gs_wxBusyCursorCount
== 0)
352 gMacStoredActiveCursor
.MacInstall() ;
353 gMacStoredActiveCursor
= wxNullCursor
;
357 // TRUE if we're between the above two calls
360 return (gs_wxBusyCursorCount
> 0);
367 wxString
wxMacFindFolder( short vol
,
369 Boolean createFolder
)
375 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
378 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
380 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
390 // Check whether this window wants to process messages, e.g. Stop button
391 // in long calculations.
392 bool wxCheckForInterrupt(wxWindow
*wnd
)
398 void wxGetMousePosition( int* x
, int* y
)
403 LocalToGlobal( &pt
) ;
408 // Return TRUE if we have a colour display
409 bool wxColourDisplay()
414 // Returns depth of screen
418 SetRect(&globRect
, -32760, -32760, 32760, 32760);
419 GDHandle theMaxDevice
;
422 theMaxDevice
= GetMaxDevice(&globRect
);
423 if (theMaxDevice
!= nil
)
424 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
429 // Get size of display
430 void wxDisplaySize(int *width
, int *height
)
433 GetQDGlobalsScreenBits( &screenBits
);
436 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
438 if (height
!= NULL
) {
439 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
443 void wxDisplaySizeMM(int *width
, int *height
)
445 wxDisplaySize(width
, height
);
446 // on mac 72 is fixed (at least now ;-)
447 float cvPt2Mm
= 25.4 / 72;
450 *width
= int( *width
* cvPt2Mm
);
452 if (height
!= NULL
) {
453 *height
= int( *height
* cvPt2Mm
);
457 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
460 GetQDGlobalsScreenBits( &screenBits
);
466 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
468 if (height
!= NULL
) {
469 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
474 GetThemeMenuBarHeight( &mheight
) ;
476 mheight
= LMGetMBarHeight() ;
478 if (height
!= NULL
) {
485 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
487 return wxGenericFindWindowAtPoint(pt
);
494 wxString
wxGetOsDescription()
496 #ifdef WXWIN_OS_DESCRIPTION
497 // use configure generated description if available
498 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
500 return wxT("MacOS") ; //TODO:define further
505 wxChar
*wxGetUserHome (const wxString
& user
)
511 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
521 int pos
= p
.Find(':') ;
522 if ( pos
!= wxNOT_FOUND
) {
531 wxMacStringToPascal( p
, volumeName
) ;
532 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
533 if ( err
== noErr
) {
535 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
538 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
542 return err
== noErr
;
544 #endif // !__DARWIN__
546 //---------------------------------------------------------------------------
547 // wxMac Specific utility functions
548 //---------------------------------------------------------------------------
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" ;
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" ;
566 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
571 for( int i
= 0 ; i
< len
; ++ i
)
573 c
= strchr( StringANSI
, *from
) ;
576 *to
= StringMac
[ c
- StringANSI
] ;
584 for( int i
= 0 ; i
< len
; ++ i
)
586 c
= strchr( StringANSI
, *from
) ;
589 *to
= StringMac
[ c
- StringANSI
] ;
601 void wxMacConvertToPC( const char *from
, char *to
, int len
)
606 for( int i
= 0 ; i
< len
; ++ i
)
608 c
= strchr( StringMac
, *from
) ;
611 *to
= StringANSI
[ c
- StringMac
] ;
619 for( int i
= 0 ; i
< len
; ++ i
)
621 c
= strchr( StringMac
, *from
) ;
624 *to
= StringANSI
[ c
- StringMac
] ;
636 TECObjectRef s_TECNativeCToUnicode
= NULL
;
637 TECObjectRef s_TECUnicodeToNativeC
= NULL
;
639 void wxMacSetupConverters()
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
645 const TextEncodingBase kEncoding
= CFStringGetSystemEncoding();
647 const TextEncodingBase kEncoding
= kTextEncodingMacRoman
;
649 OSStatus status
= noErr
;
650 status
= TECCreateConverter(&s_TECNativeCToUnicode
,
652 kTextEncodingUnicodeDefault
);
654 status
= TECCreateConverter(&s_TECUnicodeToNativeC
,
655 kTextEncodingUnicodeDefault
,
658 #if (wxUSE_UNICODE == 1) && (SIZEOF_WCHAR_T == 4)
659 TextEncoding kUnicode32
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
661 status
= TECCreateConverter(&s_TECUnicode16To32
,
662 kTextEncodingUnicodeDefault
,
664 status
= TECCreateConverter(&s_TECUnicode32To16
,
666 kTextEncodingUnicodeDefault
);
670 void wxMacCleanupConverters()
672 OSStatus status
= noErr
;
673 status
= TECDisposeConverter(s_TECNativeCToUnicode
);
674 status
= TECDisposeConverter(s_TECUnicodeToNativeC
);
677 wxWCharBuffer
wxMacStringToWString( const wxString
&from
)
680 wxWCharBuffer
result( from
.wc_str() ) ;
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 ;
695 wxString
wxMacMakeStringFromCString( const char * from
, int len
)
697 OSStatus status
= noErr
;
699 wxChar
* buf
= result
.GetWriteBuf( len
) ;
701 ByteCount byteOutLen
;
702 ByteCount byteInLen
= len
;
703 ByteCount byteBufferLen
= len
* SIZEOF_WCHAR_T
;
705 status
= TECConvertText(s_TECNativeCToUnicode
, (ConstTextPtr
)from
, byteInLen
, &byteInLen
,
706 (TextPtr
)buf
, byteBufferLen
, &byteOutLen
);
708 memcpy( buf
, from
, len
) ;
711 result
.UngetWriteBuf() ;
715 wxString
wxMacMakeStringFromCString( const char * from
)
717 return wxMacMakeStringFromCString( from
, strlen(from
) ) ;
720 wxCharBuffer
wxMacStringToCString( const wxString
&from
)
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
);
732 return wxCharBuffer( from
.c_str() ) ;
737 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
739 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
740 int len
= strlen(buf
) ;
745 memcpy( (char*) &to
[1] , buf
, len
) ;
748 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
750 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
754 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
756 TextEncodingBase enc
= 0 ;
757 if ( encoding
== wxFONTENCODING_DEFAULT
)
760 encoding
= wxFont::GetDefaultEncoding() ;
762 encoding
= wxLocale::GetSystemEncoding() ;
768 case wxFONTENCODING_ISO8859_1
:
769 enc
= kTextEncodingISOLatin1
;
771 case wxFONTENCODING_ISO8859_2
:
772 enc
= kTextEncodingISOLatin2
;
774 case wxFONTENCODING_ISO8859_3
:
775 enc
= kTextEncodingISOLatin3
;
777 case wxFONTENCODING_ISO8859_4
:
778 enc
= kTextEncodingISOLatin4
;
780 case wxFONTENCODING_ISO8859_5
:
781 enc
= kTextEncodingISOLatinCyrillic
;
783 case wxFONTENCODING_ISO8859_6
:
784 enc
= kTextEncodingISOLatinArabic
;
786 case wxFONTENCODING_ISO8859_7
:
787 enc
= kTextEncodingISOLatinGreek
;
789 case wxFONTENCODING_ISO8859_8
:
790 enc
= kTextEncodingISOLatinHebrew
;
792 case wxFONTENCODING_ISO8859_9
:
793 enc
= kTextEncodingISOLatin5
;
795 case wxFONTENCODING_ISO8859_10
:
796 enc
= kTextEncodingISOLatin6
;
798 case wxFONTENCODING_ISO8859_13
:
799 enc
= kTextEncodingISOLatin7
;
801 case wxFONTENCODING_ISO8859_14
:
802 enc
= kTextEncodingISOLatin8
;
804 case wxFONTENCODING_ISO8859_15
:
805 enc
= kTextEncodingISOLatin9
;
808 case wxFONTENCODING_KOI8
:
809 enc
= kTextEncodingKOI8_R
;
811 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
812 enc
= kTextEncodingDOSRussian
;
815 case wxFONTENCODING_BULGARIAN :
819 case wxFONTENCODING_CP437
:
820 enc
=kTextEncodingDOSLatinUS
;
822 case wxFONTENCODING_CP850
:
823 enc
= kTextEncodingDOSLatin1
;
825 case wxFONTENCODING_CP852
:
826 enc
= kTextEncodingDOSLatin2
;
828 case wxFONTENCODING_CP855
:
829 enc
= kTextEncodingDOSCyrillic
;
831 case wxFONTENCODING_CP866
:
832 enc
=kTextEncodingDOSRussian
;
834 case wxFONTENCODING_CP874
:
835 enc
= kTextEncodingDOSThai
;
837 case wxFONTENCODING_CP932
:
838 enc
= kTextEncodingDOSJapanese
;
840 case wxFONTENCODING_CP936
:
841 enc
=kTextEncodingDOSChineseSimplif
;
843 case wxFONTENCODING_CP949
:
844 enc
= kTextEncodingDOSKorean
;
846 case wxFONTENCODING_CP950
:
847 enc
= kTextEncodingDOSChineseTrad
;
850 case wxFONTENCODING_CP1250
:
851 enc
= kTextEncodingWindowsLatin2
;
853 case wxFONTENCODING_CP1251
:
854 enc
=kTextEncodingWindowsCyrillic
;
856 case wxFONTENCODING_CP1252
:
857 enc
=kTextEncodingWindowsLatin1
;
859 case wxFONTENCODING_CP1253
:
860 enc
= kTextEncodingWindowsGreek
;
862 case wxFONTENCODING_CP1254
:
863 enc
= kTextEncodingWindowsLatin5
;
865 case wxFONTENCODING_CP1255
:
866 enc
=kTextEncodingWindowsHebrew
;
868 case wxFONTENCODING_CP1256
:
869 enc
=kTextEncodingWindowsArabic
;
871 case wxFONTENCODING_CP1257
:
872 enc
= kTextEncodingWindowsBalticRim
;
875 case wxFONTENCODING_UTF7
:
876 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
878 case wxFONTENCODING_UTF8
:
879 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
881 case wxFONTENCODING_EUC_JP
:
882 enc
= kTextEncodingEUC_JP
;
884 case wxFONTENCODING_UTF16BE
:
885 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
887 case wxFONTENCODING_UTF16LE
:
888 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
890 case wxFONTENCODING_UTF32BE
:
891 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
893 case wxFONTENCODING_UTF32LE
:
894 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
897 case wxFONTENCODING_MACROMAN
:
898 enc
= kTextEncodingMacRoman
;
900 case wxFONTENCODING_MACJAPANESE
:
901 enc
= kTextEncodingMacJapanese
;
903 case wxFONTENCODING_MACCHINESETRAD
:
904 enc
= kTextEncodingMacChineseTrad
;
906 case wxFONTENCODING_MACKOREAN
:
907 enc
= kTextEncodingMacKorean
;
909 case wxFONTENCODING_MACARABIC
:
910 enc
= kTextEncodingMacArabic
;
912 case wxFONTENCODING_MACHEBREW
:
913 enc
= kTextEncodingMacHebrew
;
915 case wxFONTENCODING_MACGREEK
:
916 enc
= kTextEncodingMacGreek
;
918 case wxFONTENCODING_MACCYRILLIC
:
919 enc
= kTextEncodingMacCyrillic
;
921 case wxFONTENCODING_MACDEVANAGARI
:
922 enc
= kTextEncodingMacDevanagari
;
924 case wxFONTENCODING_MACGURMUKHI
:
925 enc
= kTextEncodingMacGurmukhi
;
927 case wxFONTENCODING_MACGUJARATI
:
928 enc
= kTextEncodingMacGujarati
;
930 case wxFONTENCODING_MACORIYA
:
931 enc
= kTextEncodingMacOriya
;
933 case wxFONTENCODING_MACBENGALI
:
934 enc
= kTextEncodingMacBengali
;
936 case wxFONTENCODING_MACTAMIL
:
937 enc
= kTextEncodingMacTamil
;
939 case wxFONTENCODING_MACTELUGU
:
940 enc
= kTextEncodingMacTelugu
;
942 case wxFONTENCODING_MACKANNADA
:
943 enc
= kTextEncodingMacKannada
;
945 case wxFONTENCODING_MACMALAJALAM
:
946 enc
= kTextEncodingMacMalayalam
;
948 case wxFONTENCODING_MACSINHALESE
:
949 enc
= kTextEncodingMacSinhalese
;
951 case wxFONTENCODING_MACBURMESE
:
952 enc
= kTextEncodingMacBurmese
;
954 case wxFONTENCODING_MACKHMER
:
955 enc
= kTextEncodingMacKhmer
;
957 case wxFONTENCODING_MACTHAI
:
958 enc
= kTextEncodingMacThai
;
960 case wxFONTENCODING_MACLAOTIAN
:
961 enc
= kTextEncodingMacLaotian
;
963 case wxFONTENCODING_MACGEORGIAN
:
964 enc
= kTextEncodingMacGeorgian
;
966 case wxFONTENCODING_MACARMENIAN
:
967 enc
= kTextEncodingMacArmenian
;
969 case wxFONTENCODING_MACCHINESESIMP
:
970 enc
= kTextEncodingMacChineseSimp
;
972 case wxFONTENCODING_MACTIBETAN
:
973 enc
= kTextEncodingMacTibetan
;
975 case wxFONTENCODING_MACMONGOLIAN
:
976 enc
= kTextEncodingMacMongolian
;
978 case wxFONTENCODING_MACETHIOPIC
:
979 enc
= kTextEncodingMacEthiopic
;
981 case wxFONTENCODING_MACCENTRALEUR
:
982 enc
= kTextEncodingMacCentralEurRoman
;
984 case wxFONTENCODING_MACVIATNAMESE
:
985 enc
= kTextEncodingMacVietnamese
;
987 case wxFONTENCODING_MACARABICEXT
:
988 enc
= kTextEncodingMacExtArabic
;
990 case wxFONTENCODING_MACSYMBOL
:
991 enc
= kTextEncodingMacSymbol
;
993 case wxFONTENCODING_MACDINGBATS
:
994 enc
= kTextEncodingMacDingbats
;
996 case wxFONTENCODING_MACTURKISH
:
997 enc
= kTextEncodingMacTurkish
;
999 case wxFONTENCODING_MACCROATIAN
:
1000 enc
= kTextEncodingMacCroatian
;
1002 case wxFONTENCODING_MACICELANDIC
:
1003 enc
= kTextEncodingMacIcelandic
;
1005 case wxFONTENCODING_MACROMANIAN
:
1006 enc
= kTextEncodingMacRomanian
;
1008 case wxFONTENCODING_MACCELTIC
:
1009 enc
= kTextEncodingMacCeltic
;
1011 case wxFONTENCODING_MACGAELIC
:
1012 enc
= kTextEncodingMacGaelic
;
1014 case wxFONTENCODING_MACKEYBOARD
:
1015 enc
= kTextEncodingMacKeyboardGlyphs
;
1021 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
1023 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
1027 case kTextEncodingISOLatin1
:
1028 enc
= wxFONTENCODING_ISO8859_1
;
1030 case kTextEncodingISOLatin2
:
1031 enc
= wxFONTENCODING_ISO8859_2
;
1033 case kTextEncodingISOLatin3
:
1034 enc
= wxFONTENCODING_ISO8859_3
;
1036 case kTextEncodingISOLatin4
:
1037 enc
= wxFONTENCODING_ISO8859_4
;
1039 case kTextEncodingISOLatinCyrillic
:
1040 enc
= wxFONTENCODING_ISO8859_5
;
1042 case kTextEncodingISOLatinArabic
:
1043 enc
= wxFONTENCODING_ISO8859_6
;
1045 case kTextEncodingISOLatinGreek
:
1046 enc
= wxFONTENCODING_ISO8859_7
;
1048 case kTextEncodingISOLatinHebrew
:
1049 enc
= wxFONTENCODING_ISO8859_8
;
1051 case kTextEncodingISOLatin5
:
1052 enc
= wxFONTENCODING_ISO8859_9
;
1054 case kTextEncodingISOLatin6
:
1055 enc
= wxFONTENCODING_ISO8859_10
;
1057 case kTextEncodingISOLatin7
:
1058 enc
= wxFONTENCODING_ISO8859_13
;
1060 case kTextEncodingISOLatin8
:
1061 enc
= wxFONTENCODING_ISO8859_14
;
1063 case kTextEncodingISOLatin9
:
1064 enc
=wxFONTENCODING_ISO8859_15
;
1067 case kTextEncodingKOI8_R
:
1068 enc
= wxFONTENCODING_KOI8
;
1072 enc = wxFONTENCODING_BULGARIAN;
1075 case kTextEncodingDOSLatinUS
:
1076 enc
= wxFONTENCODING_CP437
;
1078 case kTextEncodingDOSLatin1
:
1079 enc
= wxFONTENCODING_CP850
;
1081 case kTextEncodingDOSLatin2
:
1082 enc
=wxFONTENCODING_CP852
;
1084 case kTextEncodingDOSCyrillic
:
1085 enc
= wxFONTENCODING_CP855
;
1087 case kTextEncodingDOSRussian
:
1088 enc
= wxFONTENCODING_CP866
;
1090 case kTextEncodingDOSThai
:
1091 enc
=wxFONTENCODING_CP874
;
1093 case kTextEncodingDOSJapanese
:
1094 enc
= wxFONTENCODING_CP932
;
1096 case kTextEncodingDOSChineseSimplif
:
1097 enc
= wxFONTENCODING_CP936
;
1099 case kTextEncodingDOSKorean
:
1100 enc
= wxFONTENCODING_CP949
;
1102 case kTextEncodingDOSChineseTrad
:
1103 enc
= wxFONTENCODING_CP950
;
1106 case kTextEncodingWindowsLatin2
:
1107 enc
= wxFONTENCODING_CP1250
;
1109 case kTextEncodingWindowsCyrillic
:
1110 enc
= wxFONTENCODING_CP1251
;
1112 case kTextEncodingWindowsLatin1
:
1113 enc
= wxFONTENCODING_CP1252
;
1115 case kTextEncodingWindowsGreek
:
1116 enc
= wxFONTENCODING_CP1253
;
1118 case kTextEncodingWindowsLatin5
:
1119 enc
= wxFONTENCODING_CP1254
;
1121 case kTextEncodingWindowsHebrew
:
1122 enc
= wxFONTENCODING_CP1255
;
1124 case kTextEncodingWindowsArabic
:
1125 enc
= wxFONTENCODING_CP1256
;
1127 case kTextEncodingWindowsBalticRim
:
1128 enc
=wxFONTENCODING_CP1257
;
1130 case kTextEncodingEUC_JP
:
1131 enc
= wxFONTENCODING_EUC_JP
;
1134 case wxFONTENCODING_UTF7 :
1135 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1137 case wxFONTENCODING_UTF8 :
1138 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1140 case wxFONTENCODING_UTF16BE :
1141 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1143 case wxFONTENCODING_UTF16LE :
1144 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1146 case wxFONTENCODING_UTF32BE :
1147 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1149 case wxFONTENCODING_UTF32LE :
1150 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1153 case kTextEncodingMacRoman
:
1154 enc
= wxFONTENCODING_MACROMAN
;
1156 case kTextEncodingMacJapanese
:
1157 enc
= wxFONTENCODING_MACJAPANESE
;
1159 case kTextEncodingMacChineseTrad
:
1160 enc
= wxFONTENCODING_MACCHINESETRAD
;
1162 case kTextEncodingMacKorean
:
1163 enc
= wxFONTENCODING_MACKOREAN
;
1165 case kTextEncodingMacArabic
:
1166 enc
=wxFONTENCODING_MACARABIC
;
1168 case kTextEncodingMacHebrew
:
1169 enc
= wxFONTENCODING_MACHEBREW
;
1171 case kTextEncodingMacGreek
:
1172 enc
= wxFONTENCODING_MACGREEK
;
1174 case kTextEncodingMacCyrillic
:
1175 enc
= wxFONTENCODING_MACCYRILLIC
;
1177 case kTextEncodingMacDevanagari
:
1178 enc
= wxFONTENCODING_MACDEVANAGARI
;
1180 case kTextEncodingMacGurmukhi
:
1181 enc
= wxFONTENCODING_MACGURMUKHI
;
1183 case kTextEncodingMacGujarati
:
1184 enc
= wxFONTENCODING_MACGUJARATI
;
1186 case kTextEncodingMacOriya
:
1187 enc
=wxFONTENCODING_MACORIYA
;
1189 case kTextEncodingMacBengali
:
1190 enc
=wxFONTENCODING_MACBENGALI
;
1192 case kTextEncodingMacTamil
:
1193 enc
= wxFONTENCODING_MACTAMIL
;
1195 case kTextEncodingMacTelugu
:
1196 enc
= wxFONTENCODING_MACTELUGU
;
1198 case kTextEncodingMacKannada
:
1199 enc
= wxFONTENCODING_MACKANNADA
;
1201 case kTextEncodingMacMalayalam
:
1202 enc
= wxFONTENCODING_MACMALAJALAM
;
1204 case kTextEncodingMacSinhalese
:
1205 enc
= wxFONTENCODING_MACSINHALESE
;
1207 case kTextEncodingMacBurmese
:
1208 enc
= wxFONTENCODING_MACBURMESE
;
1210 case kTextEncodingMacKhmer
:
1211 enc
= wxFONTENCODING_MACKHMER
;
1213 case kTextEncodingMacThai
:
1214 enc
= wxFONTENCODING_MACTHAI
;
1216 case kTextEncodingMacLaotian
:
1217 enc
= wxFONTENCODING_MACLAOTIAN
;
1219 case kTextEncodingMacGeorgian
:
1220 enc
= wxFONTENCODING_MACGEORGIAN
;
1222 case kTextEncodingMacArmenian
:
1223 enc
= wxFONTENCODING_MACARMENIAN
;
1225 case kTextEncodingMacChineseSimp
:
1226 enc
= wxFONTENCODING_MACCHINESESIMP
;
1228 case kTextEncodingMacTibetan
:
1229 enc
= wxFONTENCODING_MACTIBETAN
;
1231 case kTextEncodingMacMongolian
:
1232 enc
= wxFONTENCODING_MACMONGOLIAN
;
1234 case kTextEncodingMacEthiopic
:
1235 enc
= wxFONTENCODING_MACETHIOPIC
;
1237 case kTextEncodingMacCentralEurRoman
:
1238 enc
= wxFONTENCODING_MACCENTRALEUR
;
1240 case kTextEncodingMacVietnamese
:
1241 enc
= wxFONTENCODING_MACVIATNAMESE
;
1243 case kTextEncodingMacExtArabic
:
1244 enc
= wxFONTENCODING_MACARABICEXT
;
1246 case kTextEncodingMacSymbol
:
1247 enc
= wxFONTENCODING_MACSYMBOL
;
1249 case kTextEncodingMacDingbats
:
1250 enc
= wxFONTENCODING_MACDINGBATS
;
1252 case kTextEncodingMacTurkish
:
1253 enc
= wxFONTENCODING_MACTURKISH
;
1255 case kTextEncodingMacCroatian
:
1256 enc
= wxFONTENCODING_MACCROATIAN
;
1258 case kTextEncodingMacIcelandic
:
1259 enc
= wxFONTENCODING_MACICELANDIC
;
1261 case kTextEncodingMacRomanian
:
1262 enc
= wxFONTENCODING_MACROMANIAN
;
1264 case kTextEncodingMacCeltic
:
1265 enc
= wxFONTENCODING_MACCELTIC
;
1267 case kTextEncodingMacGaelic
:
1268 enc
= wxFONTENCODING_MACGAELIC
;
1270 case kTextEncodingMacKeyboardGlyphs
:
1271 enc
= wxFONTENCODING_MACKEYBOARD
;
1277 #endif // wxUSE_BASE
1283 // CFStringRefs (Carbon only)
1288 #if (wxUSE_UNICODE == 1) && (SIZEOF_WCHAR_T == 4)
1290 wxMBConvUTF16BE gMacUTFConverter
;
1293 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1294 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1298 wxMacConvertNewlines13To10( &str
) ;
1300 size_t len
= str
.Len() ;
1302 #if SIZEOF_WCHAR_T == 2
1303 unibuf
= (UniChar
*)str
.wc_str() ;
1305 ByteCount byteBufferLen
= len
* sizeof( UniChar
) ;
1306 unibuf
= (UniChar
*) malloc(byteBufferLen
) ;
1307 wxMBConvUTF16BE converter
;
1308 converter
.WC2MB( (char*) unibuf
, str
.wc_str() , byteBufferLen
) ;
1310 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1312 #if SIZEOF_WCHAR_T == 2
1313 // as long as UniChar is the same as wchar_t nothing to do here
1318 #else // not wxUSE_UNICODE
1319 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1320 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1325 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1328 Size len
= CFStringGetLength( m_cfs
) ;
1329 wxChar
* buf
= result
.GetWriteBuf( len
) ;
1332 #if SIZEOF_WCHAR_T == 2
1333 unibuf
= (UniChar
*) buf
;
1335 unibuf
= (UniChar
*) malloc( len
* sizeof( UniChar
) ) ;
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
1341 wxMBConvUTF16BE converter
;
1342 converter
.MB2WC( buf
, (const char*)unibuf
, len
* sizeof( UniChar
) ) ;
1346 CFStringGetCString( m_cfs
, buf
, len
+1 , wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1349 wxMacConvertNewlines10To13( buf
) ;
1350 result
.UngetWriteBuf() ;
1354 #endif //TARGET_CARBON
1356 void wxMacConvertNewlines13To10( char * data
)
1359 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1366 void wxMacConvertNewlines10To13( char * data
)
1369 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1376 void wxMacConvertNewlines13To10( wxString
* data
)
1378 size_t len
= data
->Length() ;
1380 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1383 wxString
temp(*data
) ;
1384 wxStringBuffer
buf(*data
,len
) ;
1385 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1387 wxMacConvertNewlines13To10( buf
) ;
1390 void wxMacConvertNewlines10To13( wxString
* data
)
1392 size_t len
= data
->Length() ;
1394 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1397 wxString
temp(*data
) ;
1398 wxStringBuffer
buf(*data
,len
) ;
1399 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1400 wxMacConvertNewlines10To13( buf
) ;
1405 void wxMacConvertNewlines13To10( wxChar
* data
)
1407 wxChar
* buf
= data
;
1408 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1415 void wxMacConvertNewlines10To13( wxChar
* data
)
1417 wxChar
* buf
= data
;
1418 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1426 // ----------------------------------------------------------------------------
1427 // debugging support
1428 // ----------------------------------------------------------------------------
1430 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1432 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1434 #ifndef __MetroNubUtils__
1435 #include "MetroNubUtils.h"
1439 #include <Gestalt.h>
1442 #if TARGET_API_MAC_CARBON
1444 #include <CodeFragments.h>
1446 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1448 ProcPtr gCallUniversalProc_Proc
= NULL
;
1452 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1454 static long fRunOnce
= false;
1456 /* ---------------------------------------------------------------------------
1458 --------------------------------------------------------------------------- */
1460 Boolean
IsMetroNubInstalled()
1467 gMetroNubEntry
= NULL
;
1469 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1471 /* look for MetroNub's Gestalt selector */
1472 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1475 #if TARGET_API_MAC_CARBON
1476 if (gCallUniversalProc_Proc
== NULL
)
1478 CFragConnectionID connectionID
;
1481 ProcPtr symbolAddress
;
1483 CFragSymbolClass symbolClass
;
1485 symbolAddress
= NULL
;
1486 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1487 &connectionID
, &mainAddress
, errorString
);
1491 gCallUniversalProc_Proc
= NULL
;
1495 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1496 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1500 gCallUniversalProc_Proc
= NULL
;
1507 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1509 /* make sure the version of the API is compatible */
1510 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1511 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1512 gMetroNubEntry
= block
; /* success! */
1521 #if TARGET_API_MAC_CARBON
1522 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1524 return (gMetroNubEntry
!= NULL
);
1528 /* ---------------------------------------------------------------------------
1529 IsMWDebuggerRunning [v1 API]
1530 --------------------------------------------------------------------------- */
1532 Boolean
IsMWDebuggerRunning()
1534 if (IsMetroNubInstalled())
1535 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1540 /* ---------------------------------------------------------------------------
1541 AmIBeingMWDebugged [v1 API]
1542 --------------------------------------------------------------------------- */
1544 Boolean
AmIBeingMWDebugged()
1546 if (IsMetroNubInstalled())
1547 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1552 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1554 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1559 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1564 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)