1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
16 #include "wx/apptrait.h"
19 #include "wx/mac/uma.h"
33 # include "MoreFilesX.h"
35 # include "MoreFiles.h"
36 # include "MoreFilesExtras.h"
44 #include <ATSUnicode.h>
45 #include <TextCommon.h>
46 #include <TextEncodingConverter.h>
48 #include "wx/mac/private.h" // includes mac headers
50 #if defined(__MWERKS__) && wxUSE_UNICODE
54 // ---------------------------------------------------------------------------
55 // code used in both base and GUI compilation
56 // ---------------------------------------------------------------------------
58 // our OS version is the same in non GUI and GUI cases
59 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
63 // are there x-platform conventions ?
65 Gestalt(gestaltSystemVersion
, &theSystem
) ;
66 if (minorVsn
!= NULL
) {
67 *minorVsn
= (theSystem
& 0xFF ) ;
69 if (majorVsn
!= NULL
) {
70 *majorVsn
= (theSystem
>> 8 ) ;
82 // defined in unix/utilsunx.cpp for Mac OS X
84 // get full hostname (with domain name if possible)
85 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
87 return wxGetHostName(buf
, maxSize
);
90 // Get hostname only (without domain name)
91 bool wxGetHostName(wxChar
*buf
, int maxSize
)
93 // Gets Chooser name of user by examining a System resource.
95 const short kComputerNameID
= -16413;
97 short oldResFile
= CurResFile() ;
99 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
100 UseResFile(oldResFile
);
102 if (chooserName
&& *chooserName
)
104 HLock( (Handle
) chooserName
) ;
105 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
106 HUnlock( (Handle
) chooserName
) ;
107 ReleaseResource( (Handle
) chooserName
) ;
108 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
116 // Get user ID e.g. jacs
117 bool wxGetUserId(wxChar
*buf
, int maxSize
)
119 return wxGetUserName( buf
, maxSize
) ;
122 const wxChar
* wxGetHomeDir(wxString
*pstr
)
124 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
125 return pstr
->c_str() ;
128 // Get user name e.g. Stefan Csomor
129 bool wxGetUserName(wxChar
*buf
, int maxSize
)
131 // Gets Chooser name of user by examining a System resource.
133 const short kChooserNameID
= -16096;
135 short oldResFile
= CurResFile() ;
137 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
138 UseResFile(oldResFile
);
140 if (chooserName
&& *chooserName
)
142 HLock( (Handle
) chooserName
) ;
143 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
144 HUnlock( (Handle
) chooserName
) ;
145 ReleaseResource( (Handle
) chooserName
) ;
146 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
154 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
160 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
162 // TODO : under classic there is no environement support, under X yes
166 // set the env var name to the given value, return true on success
167 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
169 // TODO : under classic there is no environement support, under X yes
174 // Execute a program in an Interactive Shell
176 bool wxShell(const wxString
& command
)
182 // Shutdown or reboot the PC
183 bool wxShutdown(wxShutdownFlags wFlags
)
189 wxPowerType
wxGetPowerType()
192 return wxPOWER_UNKNOWN
;
195 wxBatteryState
wxGetBatteryState()
198 return wxBATTERY_UNKNOWN_STATE
;
201 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
202 wxMemorySize
wxGetFreeMemory()
204 return (wxMemorySize
)FreeMem() ;
207 void wxUsleep(unsigned long milliseconds
)
209 clock_t start
= clock() ;
213 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
216 void wxSleep(int nSecs
)
218 wxUsleep(1000*nSecs
);
221 // Consume all events until no more left
226 #endif // !__DARWIN__
234 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
236 static wxToolkitInfo info
;
237 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
238 info
.name
= _T("wxBase");
246 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
248 static wxToolkitInfo info
;
249 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
250 info
.shortName
= _T("mac");
251 info
.name
= _T("wxMac");
252 #ifdef __WXUNIVERSAL__
253 info
.shortName
<< _T("univ");
254 info
.name
<< _T("/wxUniversal");
259 // Reading and writing resources (eg WIN.INI, .Xdefaults)
261 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
267 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
270 buf
.Printf(wxT("%.4f"), value
);
272 return wxWriteResource(section
, entry
, buf
, file
);
275 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
278 buf
.Printf(wxT("%ld"), value
);
280 return wxWriteResource(section
, entry
, buf
, file
);
283 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
286 buf
.Printf(wxT("%d"), value
);
288 return wxWriteResource(section
, entry
, buf
, file
);
291 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
297 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
300 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
303 *value
= (float)strtod(s
, NULL
);
310 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
313 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
316 *value
= strtol(s
, NULL
, 10);
323 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
326 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
329 *value
= (int)strtol(s
, NULL
, 10);
335 #endif // wxUSE_RESOURCES
337 int gs_wxBusyCursorCount
= 0;
338 extern wxCursor gMacCurrentCursor
;
339 wxCursor gMacStoredActiveCursor
;
341 // Set the cursor to the busy cursor for all windows
342 void wxBeginBusyCursor(wxCursor
*cursor
)
344 if (gs_wxBusyCursorCount
++ == 0)
346 gMacStoredActiveCursor
= gMacCurrentCursor
;
347 cursor
->MacInstall() ;
349 //else: nothing to do, already set
352 // Restore cursor to normal
353 void wxEndBusyCursor()
355 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
356 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
358 if (--gs_wxBusyCursorCount
== 0)
360 gMacStoredActiveCursor
.MacInstall() ;
361 gMacStoredActiveCursor
= wxNullCursor
;
365 // true if we're between the above two calls
368 return (gs_wxBusyCursorCount
> 0);
375 wxString
wxMacFindFolder( short vol
,
377 Boolean createFolder
)
383 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
386 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
388 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
398 // Check whether this window wants to process messages, e.g. Stop button
399 // in long calculations.
400 bool wxCheckForInterrupt(wxWindow
*wnd
)
406 void wxGetMousePosition( int* x
, int* y
)
411 LocalToGlobal( &pt
) ;
416 // Return true if we have a colour display
417 bool wxColourDisplay()
422 // Returns depth of screen
426 SetRect(&globRect
, -32760, -32760, 32760, 32760);
427 GDHandle theMaxDevice
;
430 theMaxDevice
= GetMaxDevice(&globRect
);
431 if (theMaxDevice
!= nil
)
432 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
437 // Get size of display
438 void wxDisplaySize(int *width
, int *height
)
441 GetQDGlobalsScreenBits( &screenBits
);
444 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
446 if (height
!= NULL
) {
447 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
451 void wxDisplaySizeMM(int *width
, int *height
)
453 wxDisplaySize(width
, height
);
454 // on mac 72 is fixed (at least now ;-)
455 float cvPt2Mm
= 25.4 / 72;
458 *width
= int( *width
* cvPt2Mm
);
460 if (height
!= NULL
) {
461 *height
= int( *height
* cvPt2Mm
);
465 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
469 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
475 *width
= r
.right
- r
.left
;
477 *height
= r
.bottom
- r
.top
;
480 GetQDGlobalsScreenBits( &screenBits
);
486 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
488 if (height
!= NULL
) {
489 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
494 GetThemeMenuBarHeight( &mheight
) ;
496 mheight
= LMGetMBarHeight() ;
498 if (height
!= NULL
) {
506 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
508 return wxGenericFindWindowAtPoint(pt
);
515 wxString
wxGetOsDescription()
517 #ifdef WXWIN_OS_DESCRIPTION
518 // use configure generated description if available
519 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
521 return wxT("MacOS") ; //TODO:define further
526 wxChar
*wxGetUserHome (const wxString
& user
)
532 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
542 int pos
= p
.Find(':') ;
543 if ( pos
!= wxNOT_FOUND
) {
552 wxMacStringToPascal( p
, volumeName
) ;
553 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
554 if ( err
== noErr
) {
556 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
559 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
563 return err
== noErr
;
565 #endif // !__DARWIN__
567 //---------------------------------------------------------------------------
568 // wxMac Specific utility functions
569 //---------------------------------------------------------------------------
571 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
573 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
574 int len
= strlen(buf
) ;
579 memcpy( (char*) &to
[1] , buf
, len
) ;
582 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
584 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
588 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
590 TextEncodingBase enc
= 0 ;
591 if ( encoding
== wxFONTENCODING_DEFAULT
)
594 encoding
= wxFont::GetDefaultEncoding() ;
596 encoding
= wxLocale::GetSystemEncoding() ;
602 case wxFONTENCODING_ISO8859_1
:
603 enc
= kTextEncodingISOLatin1
;
605 case wxFONTENCODING_ISO8859_2
:
606 enc
= kTextEncodingISOLatin2
;
608 case wxFONTENCODING_ISO8859_3
:
609 enc
= kTextEncodingISOLatin3
;
611 case wxFONTENCODING_ISO8859_4
:
612 enc
= kTextEncodingISOLatin4
;
614 case wxFONTENCODING_ISO8859_5
:
615 enc
= kTextEncodingISOLatinCyrillic
;
617 case wxFONTENCODING_ISO8859_6
:
618 enc
= kTextEncodingISOLatinArabic
;
620 case wxFONTENCODING_ISO8859_7
:
621 enc
= kTextEncodingISOLatinGreek
;
623 case wxFONTENCODING_ISO8859_8
:
624 enc
= kTextEncodingISOLatinHebrew
;
626 case wxFONTENCODING_ISO8859_9
:
627 enc
= kTextEncodingISOLatin5
;
629 case wxFONTENCODING_ISO8859_10
:
630 enc
= kTextEncodingISOLatin6
;
632 case wxFONTENCODING_ISO8859_13
:
633 enc
= kTextEncodingISOLatin7
;
635 case wxFONTENCODING_ISO8859_14
:
636 enc
= kTextEncodingISOLatin8
;
638 case wxFONTENCODING_ISO8859_15
:
639 enc
= kTextEncodingISOLatin9
;
642 case wxFONTENCODING_KOI8
:
643 enc
= kTextEncodingKOI8_R
;
645 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
646 enc
= kTextEncodingDOSRussian
;
649 case wxFONTENCODING_BULGARIAN :
653 case wxFONTENCODING_CP437
:
654 enc
=kTextEncodingDOSLatinUS
;
656 case wxFONTENCODING_CP850
:
657 enc
= kTextEncodingDOSLatin1
;
659 case wxFONTENCODING_CP852
:
660 enc
= kTextEncodingDOSLatin2
;
662 case wxFONTENCODING_CP855
:
663 enc
= kTextEncodingDOSCyrillic
;
665 case wxFONTENCODING_CP866
:
666 enc
=kTextEncodingDOSRussian
;
668 case wxFONTENCODING_CP874
:
669 enc
= kTextEncodingDOSThai
;
671 case wxFONTENCODING_CP932
:
672 enc
= kTextEncodingDOSJapanese
;
674 case wxFONTENCODING_CP936
:
675 enc
=kTextEncodingDOSChineseSimplif
;
677 case wxFONTENCODING_CP949
:
678 enc
= kTextEncodingDOSKorean
;
680 case wxFONTENCODING_CP950
:
681 enc
= kTextEncodingDOSChineseTrad
;
684 case wxFONTENCODING_CP1250
:
685 enc
= kTextEncodingWindowsLatin2
;
687 case wxFONTENCODING_CP1251
:
688 enc
=kTextEncodingWindowsCyrillic
;
690 case wxFONTENCODING_CP1252
:
691 enc
=kTextEncodingWindowsLatin1
;
693 case wxFONTENCODING_CP1253
:
694 enc
= kTextEncodingWindowsGreek
;
696 case wxFONTENCODING_CP1254
:
697 enc
= kTextEncodingWindowsLatin5
;
699 case wxFONTENCODING_CP1255
:
700 enc
=kTextEncodingWindowsHebrew
;
702 case wxFONTENCODING_CP1256
:
703 enc
=kTextEncodingWindowsArabic
;
705 case wxFONTENCODING_CP1257
:
706 enc
= kTextEncodingWindowsBalticRim
;
709 case wxFONTENCODING_UTF7
:
710 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
712 case wxFONTENCODING_UTF8
:
713 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
715 case wxFONTENCODING_EUC_JP
:
716 enc
= kTextEncodingEUC_JP
;
718 case wxFONTENCODING_UTF16BE
:
719 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
721 case wxFONTENCODING_UTF16LE
:
722 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
724 case wxFONTENCODING_UTF32BE
:
725 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
727 case wxFONTENCODING_UTF32LE
:
728 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
731 case wxFONTENCODING_MACROMAN
:
732 enc
= kTextEncodingMacRoman
;
734 case wxFONTENCODING_MACJAPANESE
:
735 enc
= kTextEncodingMacJapanese
;
737 case wxFONTENCODING_MACCHINESETRAD
:
738 enc
= kTextEncodingMacChineseTrad
;
740 case wxFONTENCODING_MACKOREAN
:
741 enc
= kTextEncodingMacKorean
;
743 case wxFONTENCODING_MACARABIC
:
744 enc
= kTextEncodingMacArabic
;
746 case wxFONTENCODING_MACHEBREW
:
747 enc
= kTextEncodingMacHebrew
;
749 case wxFONTENCODING_MACGREEK
:
750 enc
= kTextEncodingMacGreek
;
752 case wxFONTENCODING_MACCYRILLIC
:
753 enc
= kTextEncodingMacCyrillic
;
755 case wxFONTENCODING_MACDEVANAGARI
:
756 enc
= kTextEncodingMacDevanagari
;
758 case wxFONTENCODING_MACGURMUKHI
:
759 enc
= kTextEncodingMacGurmukhi
;
761 case wxFONTENCODING_MACGUJARATI
:
762 enc
= kTextEncodingMacGujarati
;
764 case wxFONTENCODING_MACORIYA
:
765 enc
= kTextEncodingMacOriya
;
767 case wxFONTENCODING_MACBENGALI
:
768 enc
= kTextEncodingMacBengali
;
770 case wxFONTENCODING_MACTAMIL
:
771 enc
= kTextEncodingMacTamil
;
773 case wxFONTENCODING_MACTELUGU
:
774 enc
= kTextEncodingMacTelugu
;
776 case wxFONTENCODING_MACKANNADA
:
777 enc
= kTextEncodingMacKannada
;
779 case wxFONTENCODING_MACMALAJALAM
:
780 enc
= kTextEncodingMacMalayalam
;
782 case wxFONTENCODING_MACSINHALESE
:
783 enc
= kTextEncodingMacSinhalese
;
785 case wxFONTENCODING_MACBURMESE
:
786 enc
= kTextEncodingMacBurmese
;
788 case wxFONTENCODING_MACKHMER
:
789 enc
= kTextEncodingMacKhmer
;
791 case wxFONTENCODING_MACTHAI
:
792 enc
= kTextEncodingMacThai
;
794 case wxFONTENCODING_MACLAOTIAN
:
795 enc
= kTextEncodingMacLaotian
;
797 case wxFONTENCODING_MACGEORGIAN
:
798 enc
= kTextEncodingMacGeorgian
;
800 case wxFONTENCODING_MACARMENIAN
:
801 enc
= kTextEncodingMacArmenian
;
803 case wxFONTENCODING_MACCHINESESIMP
:
804 enc
= kTextEncodingMacChineseSimp
;
806 case wxFONTENCODING_MACTIBETAN
:
807 enc
= kTextEncodingMacTibetan
;
809 case wxFONTENCODING_MACMONGOLIAN
:
810 enc
= kTextEncodingMacMongolian
;
812 case wxFONTENCODING_MACETHIOPIC
:
813 enc
= kTextEncodingMacEthiopic
;
815 case wxFONTENCODING_MACCENTRALEUR
:
816 enc
= kTextEncodingMacCentralEurRoman
;
818 case wxFONTENCODING_MACVIATNAMESE
:
819 enc
= kTextEncodingMacVietnamese
;
821 case wxFONTENCODING_MACARABICEXT
:
822 enc
= kTextEncodingMacExtArabic
;
824 case wxFONTENCODING_MACSYMBOL
:
825 enc
= kTextEncodingMacSymbol
;
827 case wxFONTENCODING_MACDINGBATS
:
828 enc
= kTextEncodingMacDingbats
;
830 case wxFONTENCODING_MACTURKISH
:
831 enc
= kTextEncodingMacTurkish
;
833 case wxFONTENCODING_MACCROATIAN
:
834 enc
= kTextEncodingMacCroatian
;
836 case wxFONTENCODING_MACICELANDIC
:
837 enc
= kTextEncodingMacIcelandic
;
839 case wxFONTENCODING_MACROMANIAN
:
840 enc
= kTextEncodingMacRomanian
;
842 case wxFONTENCODING_MACCELTIC
:
843 enc
= kTextEncodingMacCeltic
;
845 case wxFONTENCODING_MACGAELIC
:
846 enc
= kTextEncodingMacGaelic
;
848 case wxFONTENCODING_MACKEYBOARD
:
849 enc
= kTextEncodingMacKeyboardGlyphs
;
858 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
860 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
864 case kTextEncodingISOLatin1
:
865 enc
= wxFONTENCODING_ISO8859_1
;
867 case kTextEncodingISOLatin2
:
868 enc
= wxFONTENCODING_ISO8859_2
;
870 case kTextEncodingISOLatin3
:
871 enc
= wxFONTENCODING_ISO8859_3
;
873 case kTextEncodingISOLatin4
:
874 enc
= wxFONTENCODING_ISO8859_4
;
876 case kTextEncodingISOLatinCyrillic
:
877 enc
= wxFONTENCODING_ISO8859_5
;
879 case kTextEncodingISOLatinArabic
:
880 enc
= wxFONTENCODING_ISO8859_6
;
882 case kTextEncodingISOLatinGreek
:
883 enc
= wxFONTENCODING_ISO8859_7
;
885 case kTextEncodingISOLatinHebrew
:
886 enc
= wxFONTENCODING_ISO8859_8
;
888 case kTextEncodingISOLatin5
:
889 enc
= wxFONTENCODING_ISO8859_9
;
891 case kTextEncodingISOLatin6
:
892 enc
= wxFONTENCODING_ISO8859_10
;
894 case kTextEncodingISOLatin7
:
895 enc
= wxFONTENCODING_ISO8859_13
;
897 case kTextEncodingISOLatin8
:
898 enc
= wxFONTENCODING_ISO8859_14
;
900 case kTextEncodingISOLatin9
:
901 enc
=wxFONTENCODING_ISO8859_15
;
904 case kTextEncodingKOI8_R
:
905 enc
= wxFONTENCODING_KOI8
;
909 enc = wxFONTENCODING_BULGARIAN;
912 case kTextEncodingDOSLatinUS
:
913 enc
= wxFONTENCODING_CP437
;
915 case kTextEncodingDOSLatin1
:
916 enc
= wxFONTENCODING_CP850
;
918 case kTextEncodingDOSLatin2
:
919 enc
=wxFONTENCODING_CP852
;
921 case kTextEncodingDOSCyrillic
:
922 enc
= wxFONTENCODING_CP855
;
924 case kTextEncodingDOSRussian
:
925 enc
= wxFONTENCODING_CP866
;
927 case kTextEncodingDOSThai
:
928 enc
=wxFONTENCODING_CP874
;
930 case kTextEncodingDOSJapanese
:
931 enc
= wxFONTENCODING_CP932
;
933 case kTextEncodingDOSChineseSimplif
:
934 enc
= wxFONTENCODING_CP936
;
936 case kTextEncodingDOSKorean
:
937 enc
= wxFONTENCODING_CP949
;
939 case kTextEncodingDOSChineseTrad
:
940 enc
= wxFONTENCODING_CP950
;
943 case kTextEncodingWindowsLatin2
:
944 enc
= wxFONTENCODING_CP1250
;
946 case kTextEncodingWindowsCyrillic
:
947 enc
= wxFONTENCODING_CP1251
;
949 case kTextEncodingWindowsLatin1
:
950 enc
= wxFONTENCODING_CP1252
;
952 case kTextEncodingWindowsGreek
:
953 enc
= wxFONTENCODING_CP1253
;
955 case kTextEncodingWindowsLatin5
:
956 enc
= wxFONTENCODING_CP1254
;
958 case kTextEncodingWindowsHebrew
:
959 enc
= wxFONTENCODING_CP1255
;
961 case kTextEncodingWindowsArabic
:
962 enc
= wxFONTENCODING_CP1256
;
964 case kTextEncodingWindowsBalticRim
:
965 enc
=wxFONTENCODING_CP1257
;
967 case kTextEncodingEUC_JP
:
968 enc
= wxFONTENCODING_EUC_JP
;
971 case wxFONTENCODING_UTF7 :
972 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
974 case wxFONTENCODING_UTF8 :
975 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
977 case wxFONTENCODING_UTF16BE :
978 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
980 case wxFONTENCODING_UTF16LE :
981 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
983 case wxFONTENCODING_UTF32BE :
984 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
986 case wxFONTENCODING_UTF32LE :
987 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
990 case kTextEncodingMacRoman
:
991 enc
= wxFONTENCODING_MACROMAN
;
993 case kTextEncodingMacJapanese
:
994 enc
= wxFONTENCODING_MACJAPANESE
;
996 case kTextEncodingMacChineseTrad
:
997 enc
= wxFONTENCODING_MACCHINESETRAD
;
999 case kTextEncodingMacKorean
:
1000 enc
= wxFONTENCODING_MACKOREAN
;
1002 case kTextEncodingMacArabic
:
1003 enc
=wxFONTENCODING_MACARABIC
;
1005 case kTextEncodingMacHebrew
:
1006 enc
= wxFONTENCODING_MACHEBREW
;
1008 case kTextEncodingMacGreek
:
1009 enc
= wxFONTENCODING_MACGREEK
;
1011 case kTextEncodingMacCyrillic
:
1012 enc
= wxFONTENCODING_MACCYRILLIC
;
1014 case kTextEncodingMacDevanagari
:
1015 enc
= wxFONTENCODING_MACDEVANAGARI
;
1017 case kTextEncodingMacGurmukhi
:
1018 enc
= wxFONTENCODING_MACGURMUKHI
;
1020 case kTextEncodingMacGujarati
:
1021 enc
= wxFONTENCODING_MACGUJARATI
;
1023 case kTextEncodingMacOriya
:
1024 enc
=wxFONTENCODING_MACORIYA
;
1026 case kTextEncodingMacBengali
:
1027 enc
=wxFONTENCODING_MACBENGALI
;
1029 case kTextEncodingMacTamil
:
1030 enc
= wxFONTENCODING_MACTAMIL
;
1032 case kTextEncodingMacTelugu
:
1033 enc
= wxFONTENCODING_MACTELUGU
;
1035 case kTextEncodingMacKannada
:
1036 enc
= wxFONTENCODING_MACKANNADA
;
1038 case kTextEncodingMacMalayalam
:
1039 enc
= wxFONTENCODING_MACMALAJALAM
;
1041 case kTextEncodingMacSinhalese
:
1042 enc
= wxFONTENCODING_MACSINHALESE
;
1044 case kTextEncodingMacBurmese
:
1045 enc
= wxFONTENCODING_MACBURMESE
;
1047 case kTextEncodingMacKhmer
:
1048 enc
= wxFONTENCODING_MACKHMER
;
1050 case kTextEncodingMacThai
:
1051 enc
= wxFONTENCODING_MACTHAI
;
1053 case kTextEncodingMacLaotian
:
1054 enc
= wxFONTENCODING_MACLAOTIAN
;
1056 case kTextEncodingMacGeorgian
:
1057 enc
= wxFONTENCODING_MACGEORGIAN
;
1059 case kTextEncodingMacArmenian
:
1060 enc
= wxFONTENCODING_MACARMENIAN
;
1062 case kTextEncodingMacChineseSimp
:
1063 enc
= wxFONTENCODING_MACCHINESESIMP
;
1065 case kTextEncodingMacTibetan
:
1066 enc
= wxFONTENCODING_MACTIBETAN
;
1068 case kTextEncodingMacMongolian
:
1069 enc
= wxFONTENCODING_MACMONGOLIAN
;
1071 case kTextEncodingMacEthiopic
:
1072 enc
= wxFONTENCODING_MACETHIOPIC
;
1074 case kTextEncodingMacCentralEurRoman
:
1075 enc
= wxFONTENCODING_MACCENTRALEUR
;
1077 case kTextEncodingMacVietnamese
:
1078 enc
= wxFONTENCODING_MACVIATNAMESE
;
1080 case kTextEncodingMacExtArabic
:
1081 enc
= wxFONTENCODING_MACARABICEXT
;
1083 case kTextEncodingMacSymbol
:
1084 enc
= wxFONTENCODING_MACSYMBOL
;
1086 case kTextEncodingMacDingbats
:
1087 enc
= wxFONTENCODING_MACDINGBATS
;
1089 case kTextEncodingMacTurkish
:
1090 enc
= wxFONTENCODING_MACTURKISH
;
1092 case kTextEncodingMacCroatian
:
1093 enc
= wxFONTENCODING_MACCROATIAN
;
1095 case kTextEncodingMacIcelandic
:
1096 enc
= wxFONTENCODING_MACICELANDIC
;
1098 case kTextEncodingMacRomanian
:
1099 enc
= wxFONTENCODING_MACROMANIAN
;
1101 case kTextEncodingMacCeltic
:
1102 enc
= wxFONTENCODING_MACCELTIC
;
1104 case kTextEncodingMacGaelic
:
1105 enc
= wxFONTENCODING_MACGAELIC
;
1107 case kTextEncodingMacKeyboardGlyphs
:
1108 enc
= wxFONTENCODING_MACKEYBOARD
;
1114 #endif // wxUSE_BASE
1120 // CFStringRefs (Carbon only)
1125 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1126 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1131 wxMacConvertNewlines13To10( &str
) ;
1133 #if SIZEOF_WCHAR_T == 2
1134 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1135 (UniChar
*)str
.wc_str() , str
.Len() );
1137 wxMBConvUTF16BE converter
;
1138 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1139 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1140 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1141 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1142 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1145 #else // not wxUSE_UNICODE
1146 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1147 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1152 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1154 Size cflen
= CFStringGetLength( m_cfs
) ;
1156 wxChar
* buf
= NULL
;
1159 #if SIZEOF_WCHAR_T == 2
1160 buf
= new wxChar
[ cflen
+ 1 ] ;
1161 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1164 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1165 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1167 wxMBConvUTF16BE converter
;
1168 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1169 buf
= new wxChar
[ noChars
+ 1 ] ;
1170 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1175 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1176 '?' , false , NULL
, 0 , &cStrLen
) ;
1177 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1178 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1179 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1184 wxMacConvertNewlines10To13( buf
) ;
1185 wxString
result(buf
) ;
1190 #endif //TARGET_CARBON
1192 void wxMacConvertNewlines13To10( char * data
)
1195 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1202 void wxMacConvertNewlines10To13( char * data
)
1205 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1212 void wxMacConvertNewlines13To10( wxString
* data
)
1214 size_t len
= data
->Length() ;
1216 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1219 wxString
temp(*data
) ;
1220 wxStringBuffer
buf(*data
,len
) ;
1221 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1223 wxMacConvertNewlines13To10( buf
) ;
1226 void wxMacConvertNewlines10To13( wxString
* data
)
1228 size_t len
= data
->Length() ;
1230 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1233 wxString
temp(*data
) ;
1234 wxStringBuffer
buf(*data
,len
) ;
1235 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1236 wxMacConvertNewlines10To13( buf
) ;
1241 void wxMacConvertNewlines13To10( wxChar
* data
)
1243 wxChar
* buf
= data
;
1244 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1251 void wxMacConvertNewlines10To13( wxChar
* data
)
1253 wxChar
* buf
= data
;
1254 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1262 // ----------------------------------------------------------------------------
1263 // debugging support
1264 // ----------------------------------------------------------------------------
1266 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1268 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1270 #ifndef __MetroNubUtils__
1271 #include "MetroNubUtils.h"
1275 #include <Gestalt.h>
1278 #if TARGET_API_MAC_CARBON
1280 #include <CodeFragments.h>
1282 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1284 ProcPtr gCallUniversalProc_Proc
= NULL
;
1288 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1290 static long fRunOnce
= false;
1292 /* ---------------------------------------------------------------------------
1294 --------------------------------------------------------------------------- */
1296 Boolean
IsMetroNubInstalled()
1303 gMetroNubEntry
= NULL
;
1305 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1307 /* look for MetroNub's Gestalt selector */
1308 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1311 #if TARGET_API_MAC_CARBON
1312 if (gCallUniversalProc_Proc
== NULL
)
1314 CFragConnectionID connectionID
;
1317 ProcPtr symbolAddress
;
1319 CFragSymbolClass symbolClass
;
1321 symbolAddress
= NULL
;
1322 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1323 &connectionID
, &mainAddress
, errorString
);
1327 gCallUniversalProc_Proc
= NULL
;
1331 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1332 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1336 gCallUniversalProc_Proc
= NULL
;
1343 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1345 /* make sure the version of the API is compatible */
1346 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1347 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1348 gMetroNubEntry
= block
; /* success! */
1357 #if TARGET_API_MAC_CARBON
1358 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1360 return (gMetroNubEntry
!= NULL
);
1364 /* ---------------------------------------------------------------------------
1365 IsMWDebuggerRunning [v1 API]
1366 --------------------------------------------------------------------------- */
1368 Boolean
IsMWDebuggerRunning()
1370 if (IsMetroNubInstalled())
1371 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1376 /* ---------------------------------------------------------------------------
1377 AmIBeingMWDebugged [v1 API]
1378 --------------------------------------------------------------------------- */
1380 Boolean
AmIBeingMWDebugged()
1382 if (IsMetroNubInstalled())
1383 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1388 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1390 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1395 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1400 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)