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(const 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
wxMacFindFolderNoSeparator( 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
);
394 wxString
wxMacFindFolder( short vol
,
396 Boolean createFolder
)
398 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
405 // Check whether this window wants to process messages, e.g. Stop button
406 // in long calculations.
407 bool wxCheckForInterrupt(wxWindow
*wnd
)
413 void wxGetMousePosition( int* x
, int* y
)
418 LocalToGlobal( &pt
) ;
423 // Return true if we have a colour display
424 bool wxColourDisplay()
429 // Returns depth of screen
433 SetRect(&globRect
, -32760, -32760, 32760, 32760);
434 GDHandle theMaxDevice
;
437 theMaxDevice
= GetMaxDevice(&globRect
);
438 if (theMaxDevice
!= nil
)
439 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
444 // Get size of display
445 void wxDisplaySize(int *width
, int *height
)
448 GetQDGlobalsScreenBits( &screenBits
);
451 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
453 if (height
!= NULL
) {
454 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
458 void wxDisplaySizeMM(int *width
, int *height
)
460 wxDisplaySize(width
, height
);
461 // on mac 72 is fixed (at least now ;-)
462 float cvPt2Mm
= 25.4 / 72;
465 *width
= int( *width
* cvPt2Mm
);
467 if (height
!= NULL
) {
468 *height
= int( *height
* cvPt2Mm
);
472 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
476 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
482 *width
= r
.right
- r
.left
;
484 *height
= r
.bottom
- r
.top
;
487 GetQDGlobalsScreenBits( &screenBits
);
493 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
495 if (height
!= NULL
) {
496 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
501 GetThemeMenuBarHeight( &mheight
) ;
503 mheight
= LMGetMBarHeight() ;
505 if (height
!= NULL
) {
513 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
515 return wxGenericFindWindowAtPoint(pt
);
522 wxString
wxGetOsDescription()
524 #ifdef WXWIN_OS_DESCRIPTION
525 // use configure generated description if available
526 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
528 return wxT("MacOS") ; //TODO:define further
533 wxChar
*wxGetUserHome (const wxString
& user
)
539 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
549 int pos
= p
.Find(':') ;
550 if ( pos
!= wxNOT_FOUND
) {
559 wxMacStringToPascal( p
, volumeName
) ;
560 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
561 if ( err
== noErr
) {
563 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
566 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
570 return err
== noErr
;
572 #endif // !__DARWIN__
574 //---------------------------------------------------------------------------
575 // wxMac Specific utility functions
576 //---------------------------------------------------------------------------
578 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
580 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
581 int len
= strlen(buf
) ;
586 memcpy( (char*) &to
[1] , buf
, len
) ;
589 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
591 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
595 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
597 TextEncodingBase enc
= 0 ;
598 if ( encoding
== wxFONTENCODING_DEFAULT
)
601 encoding
= wxFont::GetDefaultEncoding() ;
603 encoding
= wxLocale::GetSystemEncoding() ;
609 case wxFONTENCODING_ISO8859_1
:
610 enc
= kTextEncodingISOLatin1
;
612 case wxFONTENCODING_ISO8859_2
:
613 enc
= kTextEncodingISOLatin2
;
615 case wxFONTENCODING_ISO8859_3
:
616 enc
= kTextEncodingISOLatin3
;
618 case wxFONTENCODING_ISO8859_4
:
619 enc
= kTextEncodingISOLatin4
;
621 case wxFONTENCODING_ISO8859_5
:
622 enc
= kTextEncodingISOLatinCyrillic
;
624 case wxFONTENCODING_ISO8859_6
:
625 enc
= kTextEncodingISOLatinArabic
;
627 case wxFONTENCODING_ISO8859_7
:
628 enc
= kTextEncodingISOLatinGreek
;
630 case wxFONTENCODING_ISO8859_8
:
631 enc
= kTextEncodingISOLatinHebrew
;
633 case wxFONTENCODING_ISO8859_9
:
634 enc
= kTextEncodingISOLatin5
;
636 case wxFONTENCODING_ISO8859_10
:
637 enc
= kTextEncodingISOLatin6
;
639 case wxFONTENCODING_ISO8859_13
:
640 enc
= kTextEncodingISOLatin7
;
642 case wxFONTENCODING_ISO8859_14
:
643 enc
= kTextEncodingISOLatin8
;
645 case wxFONTENCODING_ISO8859_15
:
646 enc
= kTextEncodingISOLatin9
;
649 case wxFONTENCODING_KOI8
:
650 enc
= kTextEncodingKOI8_R
;
652 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
653 enc
= kTextEncodingDOSRussian
;
656 case wxFONTENCODING_BULGARIAN :
660 case wxFONTENCODING_CP437
:
661 enc
=kTextEncodingDOSLatinUS
;
663 case wxFONTENCODING_CP850
:
664 enc
= kTextEncodingDOSLatin1
;
666 case wxFONTENCODING_CP852
:
667 enc
= kTextEncodingDOSLatin2
;
669 case wxFONTENCODING_CP855
:
670 enc
= kTextEncodingDOSCyrillic
;
672 case wxFONTENCODING_CP866
:
673 enc
=kTextEncodingDOSRussian
;
675 case wxFONTENCODING_CP874
:
676 enc
= kTextEncodingDOSThai
;
678 case wxFONTENCODING_CP932
:
679 enc
= kTextEncodingDOSJapanese
;
681 case wxFONTENCODING_CP936
:
682 enc
=kTextEncodingDOSChineseSimplif
;
684 case wxFONTENCODING_CP949
:
685 enc
= kTextEncodingDOSKorean
;
687 case wxFONTENCODING_CP950
:
688 enc
= kTextEncodingDOSChineseTrad
;
691 case wxFONTENCODING_CP1250
:
692 enc
= kTextEncodingWindowsLatin2
;
694 case wxFONTENCODING_CP1251
:
695 enc
=kTextEncodingWindowsCyrillic
;
697 case wxFONTENCODING_CP1252
:
698 enc
=kTextEncodingWindowsLatin1
;
700 case wxFONTENCODING_CP1253
:
701 enc
= kTextEncodingWindowsGreek
;
703 case wxFONTENCODING_CP1254
:
704 enc
= kTextEncodingWindowsLatin5
;
706 case wxFONTENCODING_CP1255
:
707 enc
=kTextEncodingWindowsHebrew
;
709 case wxFONTENCODING_CP1256
:
710 enc
=kTextEncodingWindowsArabic
;
712 case wxFONTENCODING_CP1257
:
713 enc
= kTextEncodingWindowsBalticRim
;
716 case wxFONTENCODING_UTF7
:
717 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
719 case wxFONTENCODING_UTF8
:
720 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
722 case wxFONTENCODING_EUC_JP
:
723 enc
= kTextEncodingEUC_JP
;
725 case wxFONTENCODING_UTF16BE
:
726 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
728 case wxFONTENCODING_UTF16LE
:
729 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
731 case wxFONTENCODING_UTF32BE
:
732 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
734 case wxFONTENCODING_UTF32LE
:
735 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
738 case wxFONTENCODING_MACROMAN
:
739 enc
= kTextEncodingMacRoman
;
741 case wxFONTENCODING_MACJAPANESE
:
742 enc
= kTextEncodingMacJapanese
;
744 case wxFONTENCODING_MACCHINESETRAD
:
745 enc
= kTextEncodingMacChineseTrad
;
747 case wxFONTENCODING_MACKOREAN
:
748 enc
= kTextEncodingMacKorean
;
750 case wxFONTENCODING_MACARABIC
:
751 enc
= kTextEncodingMacArabic
;
753 case wxFONTENCODING_MACHEBREW
:
754 enc
= kTextEncodingMacHebrew
;
756 case wxFONTENCODING_MACGREEK
:
757 enc
= kTextEncodingMacGreek
;
759 case wxFONTENCODING_MACCYRILLIC
:
760 enc
= kTextEncodingMacCyrillic
;
762 case wxFONTENCODING_MACDEVANAGARI
:
763 enc
= kTextEncodingMacDevanagari
;
765 case wxFONTENCODING_MACGURMUKHI
:
766 enc
= kTextEncodingMacGurmukhi
;
768 case wxFONTENCODING_MACGUJARATI
:
769 enc
= kTextEncodingMacGujarati
;
771 case wxFONTENCODING_MACORIYA
:
772 enc
= kTextEncodingMacOriya
;
774 case wxFONTENCODING_MACBENGALI
:
775 enc
= kTextEncodingMacBengali
;
777 case wxFONTENCODING_MACTAMIL
:
778 enc
= kTextEncodingMacTamil
;
780 case wxFONTENCODING_MACTELUGU
:
781 enc
= kTextEncodingMacTelugu
;
783 case wxFONTENCODING_MACKANNADA
:
784 enc
= kTextEncodingMacKannada
;
786 case wxFONTENCODING_MACMALAJALAM
:
787 enc
= kTextEncodingMacMalayalam
;
789 case wxFONTENCODING_MACSINHALESE
:
790 enc
= kTextEncodingMacSinhalese
;
792 case wxFONTENCODING_MACBURMESE
:
793 enc
= kTextEncodingMacBurmese
;
795 case wxFONTENCODING_MACKHMER
:
796 enc
= kTextEncodingMacKhmer
;
798 case wxFONTENCODING_MACTHAI
:
799 enc
= kTextEncodingMacThai
;
801 case wxFONTENCODING_MACLAOTIAN
:
802 enc
= kTextEncodingMacLaotian
;
804 case wxFONTENCODING_MACGEORGIAN
:
805 enc
= kTextEncodingMacGeorgian
;
807 case wxFONTENCODING_MACARMENIAN
:
808 enc
= kTextEncodingMacArmenian
;
810 case wxFONTENCODING_MACCHINESESIMP
:
811 enc
= kTextEncodingMacChineseSimp
;
813 case wxFONTENCODING_MACTIBETAN
:
814 enc
= kTextEncodingMacTibetan
;
816 case wxFONTENCODING_MACMONGOLIAN
:
817 enc
= kTextEncodingMacMongolian
;
819 case wxFONTENCODING_MACETHIOPIC
:
820 enc
= kTextEncodingMacEthiopic
;
822 case wxFONTENCODING_MACCENTRALEUR
:
823 enc
= kTextEncodingMacCentralEurRoman
;
825 case wxFONTENCODING_MACVIATNAMESE
:
826 enc
= kTextEncodingMacVietnamese
;
828 case wxFONTENCODING_MACARABICEXT
:
829 enc
= kTextEncodingMacExtArabic
;
831 case wxFONTENCODING_MACSYMBOL
:
832 enc
= kTextEncodingMacSymbol
;
834 case wxFONTENCODING_MACDINGBATS
:
835 enc
= kTextEncodingMacDingbats
;
837 case wxFONTENCODING_MACTURKISH
:
838 enc
= kTextEncodingMacTurkish
;
840 case wxFONTENCODING_MACCROATIAN
:
841 enc
= kTextEncodingMacCroatian
;
843 case wxFONTENCODING_MACICELANDIC
:
844 enc
= kTextEncodingMacIcelandic
;
846 case wxFONTENCODING_MACROMANIAN
:
847 enc
= kTextEncodingMacRomanian
;
849 case wxFONTENCODING_MACCELTIC
:
850 enc
= kTextEncodingMacCeltic
;
852 case wxFONTENCODING_MACGAELIC
:
853 enc
= kTextEncodingMacGaelic
;
855 case wxFONTENCODING_MACKEYBOARD
:
856 enc
= kTextEncodingMacKeyboardGlyphs
;
865 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
867 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
871 case kTextEncodingISOLatin1
:
872 enc
= wxFONTENCODING_ISO8859_1
;
874 case kTextEncodingISOLatin2
:
875 enc
= wxFONTENCODING_ISO8859_2
;
877 case kTextEncodingISOLatin3
:
878 enc
= wxFONTENCODING_ISO8859_3
;
880 case kTextEncodingISOLatin4
:
881 enc
= wxFONTENCODING_ISO8859_4
;
883 case kTextEncodingISOLatinCyrillic
:
884 enc
= wxFONTENCODING_ISO8859_5
;
886 case kTextEncodingISOLatinArabic
:
887 enc
= wxFONTENCODING_ISO8859_6
;
889 case kTextEncodingISOLatinGreek
:
890 enc
= wxFONTENCODING_ISO8859_7
;
892 case kTextEncodingISOLatinHebrew
:
893 enc
= wxFONTENCODING_ISO8859_8
;
895 case kTextEncodingISOLatin5
:
896 enc
= wxFONTENCODING_ISO8859_9
;
898 case kTextEncodingISOLatin6
:
899 enc
= wxFONTENCODING_ISO8859_10
;
901 case kTextEncodingISOLatin7
:
902 enc
= wxFONTENCODING_ISO8859_13
;
904 case kTextEncodingISOLatin8
:
905 enc
= wxFONTENCODING_ISO8859_14
;
907 case kTextEncodingISOLatin9
:
908 enc
=wxFONTENCODING_ISO8859_15
;
911 case kTextEncodingKOI8_R
:
912 enc
= wxFONTENCODING_KOI8
;
916 enc = wxFONTENCODING_BULGARIAN;
919 case kTextEncodingDOSLatinUS
:
920 enc
= wxFONTENCODING_CP437
;
922 case kTextEncodingDOSLatin1
:
923 enc
= wxFONTENCODING_CP850
;
925 case kTextEncodingDOSLatin2
:
926 enc
=wxFONTENCODING_CP852
;
928 case kTextEncodingDOSCyrillic
:
929 enc
= wxFONTENCODING_CP855
;
931 case kTextEncodingDOSRussian
:
932 enc
= wxFONTENCODING_CP866
;
934 case kTextEncodingDOSThai
:
935 enc
=wxFONTENCODING_CP874
;
937 case kTextEncodingDOSJapanese
:
938 enc
= wxFONTENCODING_CP932
;
940 case kTextEncodingDOSChineseSimplif
:
941 enc
= wxFONTENCODING_CP936
;
943 case kTextEncodingDOSKorean
:
944 enc
= wxFONTENCODING_CP949
;
946 case kTextEncodingDOSChineseTrad
:
947 enc
= wxFONTENCODING_CP950
;
950 case kTextEncodingWindowsLatin2
:
951 enc
= wxFONTENCODING_CP1250
;
953 case kTextEncodingWindowsCyrillic
:
954 enc
= wxFONTENCODING_CP1251
;
956 case kTextEncodingWindowsLatin1
:
957 enc
= wxFONTENCODING_CP1252
;
959 case kTextEncodingWindowsGreek
:
960 enc
= wxFONTENCODING_CP1253
;
962 case kTextEncodingWindowsLatin5
:
963 enc
= wxFONTENCODING_CP1254
;
965 case kTextEncodingWindowsHebrew
:
966 enc
= wxFONTENCODING_CP1255
;
968 case kTextEncodingWindowsArabic
:
969 enc
= wxFONTENCODING_CP1256
;
971 case kTextEncodingWindowsBalticRim
:
972 enc
=wxFONTENCODING_CP1257
;
974 case kTextEncodingEUC_JP
:
975 enc
= wxFONTENCODING_EUC_JP
;
978 case wxFONTENCODING_UTF7 :
979 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
981 case wxFONTENCODING_UTF8 :
982 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
984 case wxFONTENCODING_UTF16BE :
985 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
987 case wxFONTENCODING_UTF16LE :
988 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
990 case wxFONTENCODING_UTF32BE :
991 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
993 case wxFONTENCODING_UTF32LE :
994 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
997 case kTextEncodingMacRoman
:
998 enc
= wxFONTENCODING_MACROMAN
;
1000 case kTextEncodingMacJapanese
:
1001 enc
= wxFONTENCODING_MACJAPANESE
;
1003 case kTextEncodingMacChineseTrad
:
1004 enc
= wxFONTENCODING_MACCHINESETRAD
;
1006 case kTextEncodingMacKorean
:
1007 enc
= wxFONTENCODING_MACKOREAN
;
1009 case kTextEncodingMacArabic
:
1010 enc
=wxFONTENCODING_MACARABIC
;
1012 case kTextEncodingMacHebrew
:
1013 enc
= wxFONTENCODING_MACHEBREW
;
1015 case kTextEncodingMacGreek
:
1016 enc
= wxFONTENCODING_MACGREEK
;
1018 case kTextEncodingMacCyrillic
:
1019 enc
= wxFONTENCODING_MACCYRILLIC
;
1021 case kTextEncodingMacDevanagari
:
1022 enc
= wxFONTENCODING_MACDEVANAGARI
;
1024 case kTextEncodingMacGurmukhi
:
1025 enc
= wxFONTENCODING_MACGURMUKHI
;
1027 case kTextEncodingMacGujarati
:
1028 enc
= wxFONTENCODING_MACGUJARATI
;
1030 case kTextEncodingMacOriya
:
1031 enc
=wxFONTENCODING_MACORIYA
;
1033 case kTextEncodingMacBengali
:
1034 enc
=wxFONTENCODING_MACBENGALI
;
1036 case kTextEncodingMacTamil
:
1037 enc
= wxFONTENCODING_MACTAMIL
;
1039 case kTextEncodingMacTelugu
:
1040 enc
= wxFONTENCODING_MACTELUGU
;
1042 case kTextEncodingMacKannada
:
1043 enc
= wxFONTENCODING_MACKANNADA
;
1045 case kTextEncodingMacMalayalam
:
1046 enc
= wxFONTENCODING_MACMALAJALAM
;
1048 case kTextEncodingMacSinhalese
:
1049 enc
= wxFONTENCODING_MACSINHALESE
;
1051 case kTextEncodingMacBurmese
:
1052 enc
= wxFONTENCODING_MACBURMESE
;
1054 case kTextEncodingMacKhmer
:
1055 enc
= wxFONTENCODING_MACKHMER
;
1057 case kTextEncodingMacThai
:
1058 enc
= wxFONTENCODING_MACTHAI
;
1060 case kTextEncodingMacLaotian
:
1061 enc
= wxFONTENCODING_MACLAOTIAN
;
1063 case kTextEncodingMacGeorgian
:
1064 enc
= wxFONTENCODING_MACGEORGIAN
;
1066 case kTextEncodingMacArmenian
:
1067 enc
= wxFONTENCODING_MACARMENIAN
;
1069 case kTextEncodingMacChineseSimp
:
1070 enc
= wxFONTENCODING_MACCHINESESIMP
;
1072 case kTextEncodingMacTibetan
:
1073 enc
= wxFONTENCODING_MACTIBETAN
;
1075 case kTextEncodingMacMongolian
:
1076 enc
= wxFONTENCODING_MACMONGOLIAN
;
1078 case kTextEncodingMacEthiopic
:
1079 enc
= wxFONTENCODING_MACETHIOPIC
;
1081 case kTextEncodingMacCentralEurRoman
:
1082 enc
= wxFONTENCODING_MACCENTRALEUR
;
1084 case kTextEncodingMacVietnamese
:
1085 enc
= wxFONTENCODING_MACVIATNAMESE
;
1087 case kTextEncodingMacExtArabic
:
1088 enc
= wxFONTENCODING_MACARABICEXT
;
1090 case kTextEncodingMacSymbol
:
1091 enc
= wxFONTENCODING_MACSYMBOL
;
1093 case kTextEncodingMacDingbats
:
1094 enc
= wxFONTENCODING_MACDINGBATS
;
1096 case kTextEncodingMacTurkish
:
1097 enc
= wxFONTENCODING_MACTURKISH
;
1099 case kTextEncodingMacCroatian
:
1100 enc
= wxFONTENCODING_MACCROATIAN
;
1102 case kTextEncodingMacIcelandic
:
1103 enc
= wxFONTENCODING_MACICELANDIC
;
1105 case kTextEncodingMacRomanian
:
1106 enc
= wxFONTENCODING_MACROMANIAN
;
1108 case kTextEncodingMacCeltic
:
1109 enc
= wxFONTENCODING_MACCELTIC
;
1111 case kTextEncodingMacGaelic
:
1112 enc
= wxFONTENCODING_MACGAELIC
;
1114 case kTextEncodingMacKeyboardGlyphs
:
1115 enc
= wxFONTENCODING_MACKEYBOARD
;
1121 #endif // wxUSE_BASE
1127 // CFStringRefs (Carbon only)
1132 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1133 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1138 wxMacConvertNewlines13To10( &str
) ;
1140 #if SIZEOF_WCHAR_T == 2
1141 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1142 (UniChar
*)str
.wc_str() , str
.Len() );
1144 wxMBConvUTF16BE converter
;
1145 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1146 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1147 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1148 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1149 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1152 #else // not wxUSE_UNICODE
1153 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1154 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1159 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1161 Size cflen
= CFStringGetLength( m_cfs
) ;
1163 wxChar
* buf
= NULL
;
1166 #if SIZEOF_WCHAR_T == 2
1167 buf
= new wxChar
[ cflen
+ 1 ] ;
1168 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1171 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1172 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1174 wxMBConvUTF16BE converter
;
1175 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1176 buf
= new wxChar
[ noChars
+ 1 ] ;
1177 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1182 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1183 '?' , false , NULL
, 0 , &cStrLen
) ;
1184 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1185 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1186 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1191 wxMacConvertNewlines10To13( buf
) ;
1192 wxString
result(buf
) ;
1197 #endif //TARGET_CARBON
1199 void wxMacConvertNewlines13To10( char * data
)
1202 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1209 void wxMacConvertNewlines10To13( char * data
)
1212 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1219 void wxMacConvertNewlines13To10( wxString
* data
)
1221 size_t len
= data
->Length() ;
1223 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1226 wxString
temp(*data
) ;
1227 wxStringBuffer
buf(*data
,len
) ;
1228 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1230 wxMacConvertNewlines13To10( buf
) ;
1233 void wxMacConvertNewlines10To13( wxString
* data
)
1235 size_t len
= data
->Length() ;
1237 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1240 wxString
temp(*data
) ;
1241 wxStringBuffer
buf(*data
,len
) ;
1242 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1243 wxMacConvertNewlines10To13( buf
) ;
1248 void wxMacConvertNewlines13To10( wxChar
* data
)
1250 wxChar
* buf
= data
;
1251 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1258 void wxMacConvertNewlines10To13( wxChar
* data
)
1260 wxChar
* buf
= data
;
1261 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1269 // ----------------------------------------------------------------------------
1270 // debugging support
1271 // ----------------------------------------------------------------------------
1273 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1275 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1277 #ifndef __MetroNubUtils__
1278 #include "MetroNubUtils.h"
1282 #include <Gestalt.h>
1285 #if TARGET_API_MAC_CARBON
1287 #include <CodeFragments.h>
1289 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1291 ProcPtr gCallUniversalProc_Proc
= NULL
;
1295 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1297 static long fRunOnce
= false;
1299 /* ---------------------------------------------------------------------------
1301 --------------------------------------------------------------------------- */
1303 Boolean
IsMetroNubInstalled()
1310 gMetroNubEntry
= NULL
;
1312 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1314 /* look for MetroNub's Gestalt selector */
1315 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1318 #if TARGET_API_MAC_CARBON
1319 if (gCallUniversalProc_Proc
== NULL
)
1321 CFragConnectionID connectionID
;
1324 ProcPtr symbolAddress
;
1326 CFragSymbolClass symbolClass
;
1328 symbolAddress
= NULL
;
1329 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1330 &connectionID
, &mainAddress
, errorString
);
1334 gCallUniversalProc_Proc
= NULL
;
1338 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1339 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1343 gCallUniversalProc_Proc
= NULL
;
1350 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1352 /* make sure the version of the API is compatible */
1353 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1354 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1355 gMetroNubEntry
= block
; /* success! */
1364 #if TARGET_API_MAC_CARBON
1365 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1367 return (gMetroNubEntry
!= NULL
);
1371 /* ---------------------------------------------------------------------------
1372 IsMWDebuggerRunning [v1 API]
1373 --------------------------------------------------------------------------- */
1375 Boolean
IsMWDebuggerRunning()
1377 if (IsMetroNubInstalled())
1378 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1383 /* ---------------------------------------------------------------------------
1384 AmIBeingMWDebugged [v1 API]
1385 --------------------------------------------------------------------------- */
1387 Boolean
AmIBeingMWDebugged()
1389 if (IsMetroNubInstalled())
1390 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1395 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1397 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1402 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1407 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)