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"
21 #include "wx/apptrait.h"
24 #include "wx/mac/uma.h"
36 # include "MoreFilesX.h"
38 # include "MoreFiles.h"
39 # include "MoreFilesExtras.h"
47 #include <ATSUnicode.h>
48 #include <TextCommon.h>
49 #include <TextEncodingConverter.h>
51 #include "wx/mac/private.h" // includes mac headers
53 #if defined(__MWERKS__) && wxUSE_UNICODE
57 // ---------------------------------------------------------------------------
58 // code used in both base and GUI compilation
59 // ---------------------------------------------------------------------------
61 // our OS version is the same in non GUI and GUI cases
62 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
66 // are there x-platform conventions ?
68 Gestalt(gestaltSystemVersion
, &theSystem
) ;
69 if (minorVsn
!= NULL
) {
70 *minorVsn
= (theSystem
& 0xFF ) ;
72 if (majorVsn
!= NULL
) {
73 *majorVsn
= (theSystem
>> 8 ) ;
85 // defined in unix/utilsunx.cpp for Mac OS X
87 // get full hostname (with domain name if possible)
88 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
90 return wxGetHostName(buf
, maxSize
);
93 // Get hostname only (without domain name)
94 bool wxGetHostName(wxChar
*buf
, int maxSize
)
96 // Gets Chooser name of user by examining a System resource.
98 const short kComputerNameID
= -16413;
100 short oldResFile
= CurResFile() ;
102 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
103 UseResFile(oldResFile
);
105 if (chooserName
&& *chooserName
)
107 HLock( (Handle
) chooserName
) ;
108 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
109 HUnlock( (Handle
) chooserName
) ;
110 ReleaseResource( (Handle
) chooserName
) ;
111 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
119 // Get user ID e.g. jacs
120 bool wxGetUserId(wxChar
*buf
, int maxSize
)
122 return wxGetUserName( buf
, maxSize
) ;
125 const wxChar
* wxGetHomeDir(wxString
*pstr
)
127 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
128 return pstr
->c_str() ;
131 // Get user name e.g. Stefan Csomor
132 bool wxGetUserName(wxChar
*buf
, int maxSize
)
134 // Gets Chooser name of user by examining a System resource.
136 const short kChooserNameID
= -16096;
138 short oldResFile
= CurResFile() ;
140 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
141 UseResFile(oldResFile
);
143 if (chooserName
&& *chooserName
)
145 HLock( (Handle
) chooserName
) ;
146 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
147 HUnlock( (Handle
) chooserName
) ;
148 ReleaseResource( (Handle
) chooserName
) ;
149 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
157 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
163 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
165 // TODO : under classic there is no environement support, under X yes
169 // set the env var name to the given value, return true on success
170 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
172 // TODO : under classic there is no environement support, under X yes
177 // Execute a program in an Interactive Shell
179 bool wxShell(const wxString
& command
)
185 // Shutdown or reboot the PC
186 bool wxShutdown(wxShutdownFlags wFlags
)
192 wxPowerType
wxGetPowerType()
195 return wxPOWER_UNKNOWN
;
198 wxBatteryState
wxGetBatteryState()
201 return wxBATTERY_UNKNOWN_STATE
;
204 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
205 wxMemorySize
wxGetFreeMemory()
207 return (wxMemorySize
)FreeMem() ;
210 void wxUsleep(unsigned long milliseconds
)
212 clock_t start
= clock() ;
216 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
219 void wxSleep(int nSecs
)
221 wxUsleep(1000*nSecs
);
224 // Consume all events until no more left
229 #endif // !__DARWIN__
237 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
239 static wxToolkitInfo info
;
240 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
241 info
.name
= _T("wxBase");
249 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
251 static wxToolkitInfo info
;
252 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
253 info
.shortName
= _T("mac");
254 info
.name
= _T("wxMac");
255 #ifdef __WXUNIVERSAL__
256 info
.shortName
<< _T("univ");
257 info
.name
<< _T("/wxUniversal");
262 // Reading and writing resources (eg WIN.INI, .Xdefaults)
264 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
270 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
273 buf
.Printf(wxT("%.4f"), value
);
275 return wxWriteResource(section
, entry
, buf
, file
);
278 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
281 buf
.Printf(wxT("%ld"), value
);
283 return wxWriteResource(section
, entry
, buf
, file
);
286 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
289 buf
.Printf(wxT("%d"), value
);
291 return wxWriteResource(section
, entry
, buf
, file
);
294 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
300 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
303 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
306 *value
= (float)strtod(s
, NULL
);
313 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
316 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
319 *value
= strtol(s
, NULL
, 10);
326 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
329 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
332 *value
= (int)strtol(s
, NULL
, 10);
338 #endif // wxUSE_RESOURCES
340 int gs_wxBusyCursorCount
= 0;
341 extern wxCursor gMacCurrentCursor
;
342 wxCursor gMacStoredActiveCursor
;
344 // Set the cursor to the busy cursor for all windows
345 void wxBeginBusyCursor(const wxCursor
*cursor
)
347 if (gs_wxBusyCursorCount
++ == 0)
349 gMacStoredActiveCursor
= gMacCurrentCursor
;
350 cursor
->MacInstall() ;
352 //else: nothing to do, already set
355 // Restore cursor to normal
356 void wxEndBusyCursor()
358 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
359 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
361 if (--gs_wxBusyCursorCount
== 0)
363 gMacStoredActiveCursor
.MacInstall() ;
364 gMacStoredActiveCursor
= wxNullCursor
;
368 // true if we're between the above two calls
371 return (gs_wxBusyCursorCount
> 0);
378 wxString
wxMacFindFolderNoSeparator( short vol
,
380 Boolean createFolder
)
386 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
389 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
391 strDir
= wxMacFSSpec2MacFilename( &file
);
397 wxString
wxMacFindFolder( short vol
,
399 Boolean createFolder
)
401 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
408 // Check whether this window wants to process messages, e.g. Stop button
409 // in long calculations.
410 bool wxCheckForInterrupt(wxWindow
*wnd
)
416 void wxGetMousePosition( int* x
, int* y
)
421 LocalToGlobal( &pt
) ;
426 // Return true if we have a colour display
427 bool wxColourDisplay()
432 // Returns depth of screen
436 SetRect(&globRect
, -32760, -32760, 32760, 32760);
437 GDHandle theMaxDevice
;
440 theMaxDevice
= GetMaxDevice(&globRect
);
441 if (theMaxDevice
!= nil
)
442 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
447 // Get size of display
448 void wxDisplaySize(int *width
, int *height
)
451 GetQDGlobalsScreenBits( &screenBits
);
454 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
456 if (height
!= NULL
) {
457 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
461 void wxDisplaySizeMM(int *width
, int *height
)
463 wxDisplaySize(width
, height
);
464 // on mac 72 is fixed (at least now ;-)
465 float cvPt2Mm
= 25.4 / 72;
468 *width
= int( *width
* cvPt2Mm
);
470 if (height
!= NULL
) {
471 *height
= int( *height
* cvPt2Mm
);
475 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
479 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
485 *width
= r
.right
- r
.left
;
487 *height
= r
.bottom
- r
.top
;
490 GetQDGlobalsScreenBits( &screenBits
);
496 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
498 if (height
!= NULL
) {
499 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
504 GetThemeMenuBarHeight( &mheight
) ;
506 mheight
= LMGetMBarHeight() ;
508 if (height
!= NULL
) {
516 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
518 return wxGenericFindWindowAtPoint(pt
);
525 wxString
wxGetOsDescription()
527 #ifdef WXWIN_OS_DESCRIPTION
528 // use configure generated description if available
529 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
531 return wxT("MacOS") ; //TODO:define further
536 wxChar
*wxGetUserHome (const wxString
& user
)
542 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
552 int pos
= p
.Find(':') ;
553 if ( pos
!= wxNOT_FOUND
) {
562 wxMacStringToPascal( p
, volumeName
) ;
563 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
564 if ( err
== noErr
) {
566 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
569 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
573 return err
== noErr
;
575 #endif // !__DARWIN__
577 //---------------------------------------------------------------------------
578 // wxMac Specific utility functions
579 //---------------------------------------------------------------------------
581 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
583 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
584 int len
= strlen(buf
) ;
589 memcpy( (char*) &to
[1] , buf
, len
) ;
592 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
594 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
598 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
600 TextEncodingBase enc
= 0 ;
601 if ( encoding
== wxFONTENCODING_DEFAULT
)
604 encoding
= wxFont::GetDefaultEncoding() ;
606 encoding
= wxLocale::GetSystemEncoding() ;
612 case wxFONTENCODING_ISO8859_1
:
613 enc
= kTextEncodingISOLatin1
;
615 case wxFONTENCODING_ISO8859_2
:
616 enc
= kTextEncodingISOLatin2
;
618 case wxFONTENCODING_ISO8859_3
:
619 enc
= kTextEncodingISOLatin3
;
621 case wxFONTENCODING_ISO8859_4
:
622 enc
= kTextEncodingISOLatin4
;
624 case wxFONTENCODING_ISO8859_5
:
625 enc
= kTextEncodingISOLatinCyrillic
;
627 case wxFONTENCODING_ISO8859_6
:
628 enc
= kTextEncodingISOLatinArabic
;
630 case wxFONTENCODING_ISO8859_7
:
631 enc
= kTextEncodingISOLatinGreek
;
633 case wxFONTENCODING_ISO8859_8
:
634 enc
= kTextEncodingISOLatinHebrew
;
636 case wxFONTENCODING_ISO8859_9
:
637 enc
= kTextEncodingISOLatin5
;
639 case wxFONTENCODING_ISO8859_10
:
640 enc
= kTextEncodingISOLatin6
;
642 case wxFONTENCODING_ISO8859_13
:
643 enc
= kTextEncodingISOLatin7
;
645 case wxFONTENCODING_ISO8859_14
:
646 enc
= kTextEncodingISOLatin8
;
648 case wxFONTENCODING_ISO8859_15
:
649 enc
= kTextEncodingISOLatin9
;
652 case wxFONTENCODING_KOI8
:
653 enc
= kTextEncodingKOI8_R
;
655 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
656 enc
= kTextEncodingDOSRussian
;
659 case wxFONTENCODING_BULGARIAN :
663 case wxFONTENCODING_CP437
:
664 enc
=kTextEncodingDOSLatinUS
;
666 case wxFONTENCODING_CP850
:
667 enc
= kTextEncodingDOSLatin1
;
669 case wxFONTENCODING_CP852
:
670 enc
= kTextEncodingDOSLatin2
;
672 case wxFONTENCODING_CP855
:
673 enc
= kTextEncodingDOSCyrillic
;
675 case wxFONTENCODING_CP866
:
676 enc
=kTextEncodingDOSRussian
;
678 case wxFONTENCODING_CP874
:
679 enc
= kTextEncodingDOSThai
;
681 case wxFONTENCODING_CP932
:
682 enc
= kTextEncodingDOSJapanese
;
684 case wxFONTENCODING_CP936
:
685 enc
=kTextEncodingDOSChineseSimplif
;
687 case wxFONTENCODING_CP949
:
688 enc
= kTextEncodingDOSKorean
;
690 case wxFONTENCODING_CP950
:
691 enc
= kTextEncodingDOSChineseTrad
;
694 case wxFONTENCODING_CP1250
:
695 enc
= kTextEncodingWindowsLatin2
;
697 case wxFONTENCODING_CP1251
:
698 enc
=kTextEncodingWindowsCyrillic
;
700 case wxFONTENCODING_CP1252
:
701 enc
=kTextEncodingWindowsLatin1
;
703 case wxFONTENCODING_CP1253
:
704 enc
= kTextEncodingWindowsGreek
;
706 case wxFONTENCODING_CP1254
:
707 enc
= kTextEncodingWindowsLatin5
;
709 case wxFONTENCODING_CP1255
:
710 enc
=kTextEncodingWindowsHebrew
;
712 case wxFONTENCODING_CP1256
:
713 enc
=kTextEncodingWindowsArabic
;
715 case wxFONTENCODING_CP1257
:
716 enc
= kTextEncodingWindowsBalticRim
;
719 case wxFONTENCODING_UTF7
:
720 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
722 case wxFONTENCODING_UTF8
:
723 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
725 case wxFONTENCODING_EUC_JP
:
726 enc
= kTextEncodingEUC_JP
;
728 case wxFONTENCODING_UTF16BE
:
729 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
731 case wxFONTENCODING_UTF16LE
:
732 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
734 case wxFONTENCODING_UTF32BE
:
735 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
737 case wxFONTENCODING_UTF32LE
:
738 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
741 case wxFONTENCODING_MACROMAN
:
742 enc
= kTextEncodingMacRoman
;
744 case wxFONTENCODING_MACJAPANESE
:
745 enc
= kTextEncodingMacJapanese
;
747 case wxFONTENCODING_MACCHINESETRAD
:
748 enc
= kTextEncodingMacChineseTrad
;
750 case wxFONTENCODING_MACKOREAN
:
751 enc
= kTextEncodingMacKorean
;
753 case wxFONTENCODING_MACARABIC
:
754 enc
= kTextEncodingMacArabic
;
756 case wxFONTENCODING_MACHEBREW
:
757 enc
= kTextEncodingMacHebrew
;
759 case wxFONTENCODING_MACGREEK
:
760 enc
= kTextEncodingMacGreek
;
762 case wxFONTENCODING_MACCYRILLIC
:
763 enc
= kTextEncodingMacCyrillic
;
765 case wxFONTENCODING_MACDEVANAGARI
:
766 enc
= kTextEncodingMacDevanagari
;
768 case wxFONTENCODING_MACGURMUKHI
:
769 enc
= kTextEncodingMacGurmukhi
;
771 case wxFONTENCODING_MACGUJARATI
:
772 enc
= kTextEncodingMacGujarati
;
774 case wxFONTENCODING_MACORIYA
:
775 enc
= kTextEncodingMacOriya
;
777 case wxFONTENCODING_MACBENGALI
:
778 enc
= kTextEncodingMacBengali
;
780 case wxFONTENCODING_MACTAMIL
:
781 enc
= kTextEncodingMacTamil
;
783 case wxFONTENCODING_MACTELUGU
:
784 enc
= kTextEncodingMacTelugu
;
786 case wxFONTENCODING_MACKANNADA
:
787 enc
= kTextEncodingMacKannada
;
789 case wxFONTENCODING_MACMALAJALAM
:
790 enc
= kTextEncodingMacMalayalam
;
792 case wxFONTENCODING_MACSINHALESE
:
793 enc
= kTextEncodingMacSinhalese
;
795 case wxFONTENCODING_MACBURMESE
:
796 enc
= kTextEncodingMacBurmese
;
798 case wxFONTENCODING_MACKHMER
:
799 enc
= kTextEncodingMacKhmer
;
801 case wxFONTENCODING_MACTHAI
:
802 enc
= kTextEncodingMacThai
;
804 case wxFONTENCODING_MACLAOTIAN
:
805 enc
= kTextEncodingMacLaotian
;
807 case wxFONTENCODING_MACGEORGIAN
:
808 enc
= kTextEncodingMacGeorgian
;
810 case wxFONTENCODING_MACARMENIAN
:
811 enc
= kTextEncodingMacArmenian
;
813 case wxFONTENCODING_MACCHINESESIMP
:
814 enc
= kTextEncodingMacChineseSimp
;
816 case wxFONTENCODING_MACTIBETAN
:
817 enc
= kTextEncodingMacTibetan
;
819 case wxFONTENCODING_MACMONGOLIAN
:
820 enc
= kTextEncodingMacMongolian
;
822 case wxFONTENCODING_MACETHIOPIC
:
823 enc
= kTextEncodingMacEthiopic
;
825 case wxFONTENCODING_MACCENTRALEUR
:
826 enc
= kTextEncodingMacCentralEurRoman
;
828 case wxFONTENCODING_MACVIATNAMESE
:
829 enc
= kTextEncodingMacVietnamese
;
831 case wxFONTENCODING_MACARABICEXT
:
832 enc
= kTextEncodingMacExtArabic
;
834 case wxFONTENCODING_MACSYMBOL
:
835 enc
= kTextEncodingMacSymbol
;
837 case wxFONTENCODING_MACDINGBATS
:
838 enc
= kTextEncodingMacDingbats
;
840 case wxFONTENCODING_MACTURKISH
:
841 enc
= kTextEncodingMacTurkish
;
843 case wxFONTENCODING_MACCROATIAN
:
844 enc
= kTextEncodingMacCroatian
;
846 case wxFONTENCODING_MACICELANDIC
:
847 enc
= kTextEncodingMacIcelandic
;
849 case wxFONTENCODING_MACROMANIAN
:
850 enc
= kTextEncodingMacRomanian
;
852 case wxFONTENCODING_MACCELTIC
:
853 enc
= kTextEncodingMacCeltic
;
855 case wxFONTENCODING_MACGAELIC
:
856 enc
= kTextEncodingMacGaelic
;
858 case wxFONTENCODING_MACKEYBOARD
:
859 enc
= kTextEncodingMacKeyboardGlyphs
;
868 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
870 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
874 case kTextEncodingISOLatin1
:
875 enc
= wxFONTENCODING_ISO8859_1
;
877 case kTextEncodingISOLatin2
:
878 enc
= wxFONTENCODING_ISO8859_2
;
880 case kTextEncodingISOLatin3
:
881 enc
= wxFONTENCODING_ISO8859_3
;
883 case kTextEncodingISOLatin4
:
884 enc
= wxFONTENCODING_ISO8859_4
;
886 case kTextEncodingISOLatinCyrillic
:
887 enc
= wxFONTENCODING_ISO8859_5
;
889 case kTextEncodingISOLatinArabic
:
890 enc
= wxFONTENCODING_ISO8859_6
;
892 case kTextEncodingISOLatinGreek
:
893 enc
= wxFONTENCODING_ISO8859_7
;
895 case kTextEncodingISOLatinHebrew
:
896 enc
= wxFONTENCODING_ISO8859_8
;
898 case kTextEncodingISOLatin5
:
899 enc
= wxFONTENCODING_ISO8859_9
;
901 case kTextEncodingISOLatin6
:
902 enc
= wxFONTENCODING_ISO8859_10
;
904 case kTextEncodingISOLatin7
:
905 enc
= wxFONTENCODING_ISO8859_13
;
907 case kTextEncodingISOLatin8
:
908 enc
= wxFONTENCODING_ISO8859_14
;
910 case kTextEncodingISOLatin9
:
911 enc
=wxFONTENCODING_ISO8859_15
;
914 case kTextEncodingKOI8_R
:
915 enc
= wxFONTENCODING_KOI8
;
919 enc = wxFONTENCODING_BULGARIAN;
922 case kTextEncodingDOSLatinUS
:
923 enc
= wxFONTENCODING_CP437
;
925 case kTextEncodingDOSLatin1
:
926 enc
= wxFONTENCODING_CP850
;
928 case kTextEncodingDOSLatin2
:
929 enc
=wxFONTENCODING_CP852
;
931 case kTextEncodingDOSCyrillic
:
932 enc
= wxFONTENCODING_CP855
;
934 case kTextEncodingDOSRussian
:
935 enc
= wxFONTENCODING_CP866
;
937 case kTextEncodingDOSThai
:
938 enc
=wxFONTENCODING_CP874
;
940 case kTextEncodingDOSJapanese
:
941 enc
= wxFONTENCODING_CP932
;
943 case kTextEncodingDOSChineseSimplif
:
944 enc
= wxFONTENCODING_CP936
;
946 case kTextEncodingDOSKorean
:
947 enc
= wxFONTENCODING_CP949
;
949 case kTextEncodingDOSChineseTrad
:
950 enc
= wxFONTENCODING_CP950
;
953 case kTextEncodingWindowsLatin2
:
954 enc
= wxFONTENCODING_CP1250
;
956 case kTextEncodingWindowsCyrillic
:
957 enc
= wxFONTENCODING_CP1251
;
959 case kTextEncodingWindowsLatin1
:
960 enc
= wxFONTENCODING_CP1252
;
962 case kTextEncodingWindowsGreek
:
963 enc
= wxFONTENCODING_CP1253
;
965 case kTextEncodingWindowsLatin5
:
966 enc
= wxFONTENCODING_CP1254
;
968 case kTextEncodingWindowsHebrew
:
969 enc
= wxFONTENCODING_CP1255
;
971 case kTextEncodingWindowsArabic
:
972 enc
= wxFONTENCODING_CP1256
;
974 case kTextEncodingWindowsBalticRim
:
975 enc
=wxFONTENCODING_CP1257
;
977 case kTextEncodingEUC_JP
:
978 enc
= wxFONTENCODING_EUC_JP
;
981 case wxFONTENCODING_UTF7 :
982 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
984 case wxFONTENCODING_UTF8 :
985 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
987 case wxFONTENCODING_UTF16BE :
988 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
990 case wxFONTENCODING_UTF16LE :
991 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
993 case wxFONTENCODING_UTF32BE :
994 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
996 case wxFONTENCODING_UTF32LE :
997 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1000 case kTextEncodingMacRoman
:
1001 enc
= wxFONTENCODING_MACROMAN
;
1003 case kTextEncodingMacJapanese
:
1004 enc
= wxFONTENCODING_MACJAPANESE
;
1006 case kTextEncodingMacChineseTrad
:
1007 enc
= wxFONTENCODING_MACCHINESETRAD
;
1009 case kTextEncodingMacKorean
:
1010 enc
= wxFONTENCODING_MACKOREAN
;
1012 case kTextEncodingMacArabic
:
1013 enc
=wxFONTENCODING_MACARABIC
;
1015 case kTextEncodingMacHebrew
:
1016 enc
= wxFONTENCODING_MACHEBREW
;
1018 case kTextEncodingMacGreek
:
1019 enc
= wxFONTENCODING_MACGREEK
;
1021 case kTextEncodingMacCyrillic
:
1022 enc
= wxFONTENCODING_MACCYRILLIC
;
1024 case kTextEncodingMacDevanagari
:
1025 enc
= wxFONTENCODING_MACDEVANAGARI
;
1027 case kTextEncodingMacGurmukhi
:
1028 enc
= wxFONTENCODING_MACGURMUKHI
;
1030 case kTextEncodingMacGujarati
:
1031 enc
= wxFONTENCODING_MACGUJARATI
;
1033 case kTextEncodingMacOriya
:
1034 enc
=wxFONTENCODING_MACORIYA
;
1036 case kTextEncodingMacBengali
:
1037 enc
=wxFONTENCODING_MACBENGALI
;
1039 case kTextEncodingMacTamil
:
1040 enc
= wxFONTENCODING_MACTAMIL
;
1042 case kTextEncodingMacTelugu
:
1043 enc
= wxFONTENCODING_MACTELUGU
;
1045 case kTextEncodingMacKannada
:
1046 enc
= wxFONTENCODING_MACKANNADA
;
1048 case kTextEncodingMacMalayalam
:
1049 enc
= wxFONTENCODING_MACMALAJALAM
;
1051 case kTextEncodingMacSinhalese
:
1052 enc
= wxFONTENCODING_MACSINHALESE
;
1054 case kTextEncodingMacBurmese
:
1055 enc
= wxFONTENCODING_MACBURMESE
;
1057 case kTextEncodingMacKhmer
:
1058 enc
= wxFONTENCODING_MACKHMER
;
1060 case kTextEncodingMacThai
:
1061 enc
= wxFONTENCODING_MACTHAI
;
1063 case kTextEncodingMacLaotian
:
1064 enc
= wxFONTENCODING_MACLAOTIAN
;
1066 case kTextEncodingMacGeorgian
:
1067 enc
= wxFONTENCODING_MACGEORGIAN
;
1069 case kTextEncodingMacArmenian
:
1070 enc
= wxFONTENCODING_MACARMENIAN
;
1072 case kTextEncodingMacChineseSimp
:
1073 enc
= wxFONTENCODING_MACCHINESESIMP
;
1075 case kTextEncodingMacTibetan
:
1076 enc
= wxFONTENCODING_MACTIBETAN
;
1078 case kTextEncodingMacMongolian
:
1079 enc
= wxFONTENCODING_MACMONGOLIAN
;
1081 case kTextEncodingMacEthiopic
:
1082 enc
= wxFONTENCODING_MACETHIOPIC
;
1084 case kTextEncodingMacCentralEurRoman
:
1085 enc
= wxFONTENCODING_MACCENTRALEUR
;
1087 case kTextEncodingMacVietnamese
:
1088 enc
= wxFONTENCODING_MACVIATNAMESE
;
1090 case kTextEncodingMacExtArabic
:
1091 enc
= wxFONTENCODING_MACARABICEXT
;
1093 case kTextEncodingMacSymbol
:
1094 enc
= wxFONTENCODING_MACSYMBOL
;
1096 case kTextEncodingMacDingbats
:
1097 enc
= wxFONTENCODING_MACDINGBATS
;
1099 case kTextEncodingMacTurkish
:
1100 enc
= wxFONTENCODING_MACTURKISH
;
1102 case kTextEncodingMacCroatian
:
1103 enc
= wxFONTENCODING_MACCROATIAN
;
1105 case kTextEncodingMacIcelandic
:
1106 enc
= wxFONTENCODING_MACICELANDIC
;
1108 case kTextEncodingMacRomanian
:
1109 enc
= wxFONTENCODING_MACROMANIAN
;
1111 case kTextEncodingMacCeltic
:
1112 enc
= wxFONTENCODING_MACCELTIC
;
1114 case kTextEncodingMacGaelic
:
1115 enc
= wxFONTENCODING_MACGAELIC
;
1117 case kTextEncodingMacKeyboardGlyphs
:
1118 enc
= wxFONTENCODING_MACKEYBOARD
;
1124 #endif // wxUSE_BASE
1130 // CFStringRefs (Carbon only)
1135 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1136 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1141 wxMacConvertNewlines13To10( &str
) ;
1143 #if SIZEOF_WCHAR_T == 2
1144 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1145 (UniChar
*)str
.wc_str() , str
.Len() );
1147 wxMBConvUTF16BE converter
;
1148 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1149 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1150 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1151 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1152 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1155 #else // not wxUSE_UNICODE
1156 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1157 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1162 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1164 Size cflen
= CFStringGetLength( m_cfs
) ;
1166 wxChar
* buf
= NULL
;
1169 #if SIZEOF_WCHAR_T == 2
1170 buf
= new wxChar
[ cflen
+ 1 ] ;
1171 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1174 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1175 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1177 wxMBConvUTF16BE converter
;
1178 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1179 buf
= new wxChar
[ noChars
+ 1 ] ;
1180 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1185 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1186 '?' , false , NULL
, 0 , &cStrLen
) ;
1187 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1188 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1189 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1194 wxMacConvertNewlines10To13( buf
) ;
1195 wxString
result(buf
) ;
1200 #endif //TARGET_CARBON
1202 void wxMacConvertNewlines13To10( char * data
)
1205 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1212 void wxMacConvertNewlines10To13( char * data
)
1215 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1222 void wxMacConvertNewlines13To10( wxString
* data
)
1224 size_t len
= data
->length() ;
1226 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1229 wxString
temp(*data
) ;
1230 wxStringBuffer
buf(*data
,len
) ;
1231 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1233 wxMacConvertNewlines13To10( buf
) ;
1236 void wxMacConvertNewlines10To13( wxString
* data
)
1238 size_t len
= data
->length() ;
1240 if ( data
->empty() || wxStrchr(data
->c_str(),0x0a)==NULL
)
1243 wxString
temp(*data
) ;
1244 wxStringBuffer
buf(*data
,len
) ;
1245 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1246 wxMacConvertNewlines10To13( buf
) ;
1251 void wxMacConvertNewlines13To10( wxChar
* data
)
1253 wxChar
* buf
= data
;
1254 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1261 void wxMacConvertNewlines10To13( wxChar
* data
)
1263 wxChar
* buf
= data
;
1264 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1272 // ----------------------------------------------------------------------------
1273 // debugging support
1274 // ----------------------------------------------------------------------------
1276 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1278 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1280 #ifndef __MetroNubUtils__
1281 #include "MetroNubUtils.h"
1285 #include <Gestalt.h>
1288 #if TARGET_API_MAC_CARBON
1290 #include <CodeFragments.h>
1292 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1294 ProcPtr gCallUniversalProc_Proc
= NULL
;
1298 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1300 static long fRunOnce
= false;
1302 /* ---------------------------------------------------------------------------
1304 --------------------------------------------------------------------------- */
1306 Boolean
IsMetroNubInstalled()
1313 gMetroNubEntry
= NULL
;
1315 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1317 /* look for MetroNub's Gestalt selector */
1318 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1321 #if TARGET_API_MAC_CARBON
1322 if (gCallUniversalProc_Proc
== NULL
)
1324 CFragConnectionID connectionID
;
1327 ProcPtr symbolAddress
;
1329 CFragSymbolClass symbolClass
;
1331 symbolAddress
= NULL
;
1332 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1333 &connectionID
, &mainAddress
, errorString
);
1337 gCallUniversalProc_Proc
= NULL
;
1341 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1342 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1346 gCallUniversalProc_Proc
= NULL
;
1353 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1355 /* make sure the version of the API is compatible */
1356 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1357 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1358 gMetroNubEntry
= block
; /* success! */
1367 #if TARGET_API_MAC_CARBON
1368 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1370 return (gMetroNubEntry
!= NULL
);
1374 /* ---------------------------------------------------------------------------
1375 IsMWDebuggerRunning [v1 API]
1376 --------------------------------------------------------------------------- */
1378 Boolean
IsMWDebuggerRunning()
1380 if (IsMetroNubInstalled())
1381 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1386 /* ---------------------------------------------------------------------------
1387 AmIBeingMWDebugged [v1 API]
1388 --------------------------------------------------------------------------- */
1390 Boolean
AmIBeingMWDebugged()
1392 if (IsMetroNubInstalled())
1393 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1398 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1400 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1405 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1410 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)