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
, int flags
)
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 wxPowerType
wxGetPowerType()
196 return wxPOWER_UNKNOWN
;
199 wxBatteryState
wxGetBatteryState()
202 return wxBATTERY_UNKNOWN_STATE
;
205 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
206 wxMemorySize
wxGetFreeMemory()
208 return (wxMemorySize
)FreeMem() ;
211 void wxUsleep(unsigned long milliseconds
)
213 clock_t start
= clock() ;
217 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
220 void wxSleep(int nSecs
)
222 wxUsleep(1000*nSecs
);
225 // Consume all events until no more left
230 #endif // !__DARWIN__
238 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
240 static wxToolkitInfo info
;
241 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
242 info
.name
= _T("wxBase");
250 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
252 static wxToolkitInfo info
;
253 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
254 info
.shortName
= _T("mac");
255 info
.name
= _T("wxMac");
256 #ifdef __WXUNIVERSAL__
257 info
.shortName
<< _T("univ");
258 info
.name
<< _T("/wxUniversal");
263 // Reading and writing resources (eg WIN.INI, .Xdefaults)
265 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
271 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
274 buf
.Printf(wxT("%.4f"), value
);
276 return wxWriteResource(section
, entry
, buf
, file
);
279 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
282 buf
.Printf(wxT("%ld"), value
);
284 return wxWriteResource(section
, entry
, buf
, file
);
287 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
290 buf
.Printf(wxT("%d"), value
);
292 return wxWriteResource(section
, entry
, buf
, file
);
295 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
301 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
304 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
307 *value
= (float)strtod(s
, NULL
);
314 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
317 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
320 *value
= strtol(s
, NULL
, 10);
327 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
330 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
333 *value
= (int)strtol(s
, NULL
, 10);
339 #endif // wxUSE_RESOURCES
341 int gs_wxBusyCursorCount
= 0;
342 extern wxCursor gMacCurrentCursor
;
343 wxCursor gMacStoredActiveCursor
;
345 // Set the cursor to the busy cursor for all windows
346 void wxBeginBusyCursor(wxCursor
*cursor
)
348 if (gs_wxBusyCursorCount
++ == 0)
350 gMacStoredActiveCursor
= gMacCurrentCursor
;
351 cursor
->MacInstall() ;
353 //else: nothing to do, already set
356 // Restore cursor to normal
357 void wxEndBusyCursor()
359 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
360 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
362 if (--gs_wxBusyCursorCount
== 0)
364 gMacStoredActiveCursor
.MacInstall() ;
365 gMacStoredActiveCursor
= wxNullCursor
;
369 // true if we're between the above two calls
372 return (gs_wxBusyCursorCount
> 0);
379 wxString
wxMacFindFolder( short vol
,
381 Boolean createFolder
)
387 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
390 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
392 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
402 // Check whether this window wants to process messages, e.g. Stop button
403 // in long calculations.
404 bool wxCheckForInterrupt(wxWindow
*wnd
)
410 void wxGetMousePosition( int* x
, int* y
)
415 LocalToGlobal( &pt
) ;
420 // Return true if we have a colour display
421 bool wxColourDisplay()
426 // Returns depth of screen
430 SetRect(&globRect
, -32760, -32760, 32760, 32760);
431 GDHandle theMaxDevice
;
434 theMaxDevice
= GetMaxDevice(&globRect
);
435 if (theMaxDevice
!= nil
)
436 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
441 // Get size of display
442 void wxDisplaySize(int *width
, int *height
)
445 GetQDGlobalsScreenBits( &screenBits
);
448 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
450 if (height
!= NULL
) {
451 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
455 void wxDisplaySizeMM(int *width
, int *height
)
457 wxDisplaySize(width
, height
);
458 // on mac 72 is fixed (at least now ;-)
459 float cvPt2Mm
= 25.4 / 72;
462 *width
= int( *width
* cvPt2Mm
);
464 if (height
!= NULL
) {
465 *height
= int( *height
* cvPt2Mm
);
469 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
473 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
479 *width
= r
.right
- r
.left
;
481 *height
= r
.bottom
- r
.top
;
484 GetQDGlobalsScreenBits( &screenBits
);
490 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
492 if (height
!= NULL
) {
493 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
498 GetThemeMenuBarHeight( &mheight
) ;
500 mheight
= LMGetMBarHeight() ;
502 if (height
!= NULL
) {
510 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
512 return wxGenericFindWindowAtPoint(pt
);
519 wxString
wxGetOsDescription()
521 #ifdef WXWIN_OS_DESCRIPTION
522 // use configure generated description if available
523 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
525 return wxT("MacOS") ; //TODO:define further
530 wxChar
*wxGetUserHome (const wxString
& user
)
536 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
546 int pos
= p
.Find(':') ;
547 if ( pos
!= wxNOT_FOUND
) {
556 wxMacStringToPascal( p
, volumeName
) ;
557 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
558 if ( err
== noErr
) {
560 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
563 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
567 return err
== noErr
;
569 #endif // !__DARWIN__
571 //---------------------------------------------------------------------------
572 // wxMac Specific utility functions
573 //---------------------------------------------------------------------------
575 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
577 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
578 int len
= strlen(buf
) ;
583 memcpy( (char*) &to
[1] , buf
, len
) ;
586 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
588 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
592 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
594 TextEncodingBase enc
= 0 ;
595 if ( encoding
== wxFONTENCODING_DEFAULT
)
598 encoding
= wxFont::GetDefaultEncoding() ;
600 encoding
= wxLocale::GetSystemEncoding() ;
606 case wxFONTENCODING_ISO8859_1
:
607 enc
= kTextEncodingISOLatin1
;
609 case wxFONTENCODING_ISO8859_2
:
610 enc
= kTextEncodingISOLatin2
;
612 case wxFONTENCODING_ISO8859_3
:
613 enc
= kTextEncodingISOLatin3
;
615 case wxFONTENCODING_ISO8859_4
:
616 enc
= kTextEncodingISOLatin4
;
618 case wxFONTENCODING_ISO8859_5
:
619 enc
= kTextEncodingISOLatinCyrillic
;
621 case wxFONTENCODING_ISO8859_6
:
622 enc
= kTextEncodingISOLatinArabic
;
624 case wxFONTENCODING_ISO8859_7
:
625 enc
= kTextEncodingISOLatinGreek
;
627 case wxFONTENCODING_ISO8859_8
:
628 enc
= kTextEncodingISOLatinHebrew
;
630 case wxFONTENCODING_ISO8859_9
:
631 enc
= kTextEncodingISOLatin5
;
633 case wxFONTENCODING_ISO8859_10
:
634 enc
= kTextEncodingISOLatin6
;
636 case wxFONTENCODING_ISO8859_13
:
637 enc
= kTextEncodingISOLatin7
;
639 case wxFONTENCODING_ISO8859_14
:
640 enc
= kTextEncodingISOLatin8
;
642 case wxFONTENCODING_ISO8859_15
:
643 enc
= kTextEncodingISOLatin9
;
646 case wxFONTENCODING_KOI8
:
647 enc
= kTextEncodingKOI8_R
;
649 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
650 enc
= kTextEncodingDOSRussian
;
653 case wxFONTENCODING_BULGARIAN :
657 case wxFONTENCODING_CP437
:
658 enc
=kTextEncodingDOSLatinUS
;
660 case wxFONTENCODING_CP850
:
661 enc
= kTextEncodingDOSLatin1
;
663 case wxFONTENCODING_CP852
:
664 enc
= kTextEncodingDOSLatin2
;
666 case wxFONTENCODING_CP855
:
667 enc
= kTextEncodingDOSCyrillic
;
669 case wxFONTENCODING_CP866
:
670 enc
=kTextEncodingDOSRussian
;
672 case wxFONTENCODING_CP874
:
673 enc
= kTextEncodingDOSThai
;
675 case wxFONTENCODING_CP932
:
676 enc
= kTextEncodingDOSJapanese
;
678 case wxFONTENCODING_CP936
:
679 enc
=kTextEncodingDOSChineseSimplif
;
681 case wxFONTENCODING_CP949
:
682 enc
= kTextEncodingDOSKorean
;
684 case wxFONTENCODING_CP950
:
685 enc
= kTextEncodingDOSChineseTrad
;
688 case wxFONTENCODING_CP1250
:
689 enc
= kTextEncodingWindowsLatin2
;
691 case wxFONTENCODING_CP1251
:
692 enc
=kTextEncodingWindowsCyrillic
;
694 case wxFONTENCODING_CP1252
:
695 enc
=kTextEncodingWindowsLatin1
;
697 case wxFONTENCODING_CP1253
:
698 enc
= kTextEncodingWindowsGreek
;
700 case wxFONTENCODING_CP1254
:
701 enc
= kTextEncodingWindowsLatin5
;
703 case wxFONTENCODING_CP1255
:
704 enc
=kTextEncodingWindowsHebrew
;
706 case wxFONTENCODING_CP1256
:
707 enc
=kTextEncodingWindowsArabic
;
709 case wxFONTENCODING_CP1257
:
710 enc
= kTextEncodingWindowsBalticRim
;
713 case wxFONTENCODING_UTF7
:
714 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
716 case wxFONTENCODING_UTF8
:
717 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
719 case wxFONTENCODING_EUC_JP
:
720 enc
= kTextEncodingEUC_JP
;
722 case wxFONTENCODING_UTF16BE
:
723 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
725 case wxFONTENCODING_UTF16LE
:
726 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
728 case wxFONTENCODING_UTF32BE
:
729 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
731 case wxFONTENCODING_UTF32LE
:
732 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
735 case wxFONTENCODING_MACROMAN
:
736 enc
= kTextEncodingMacRoman
;
738 case wxFONTENCODING_MACJAPANESE
:
739 enc
= kTextEncodingMacJapanese
;
741 case wxFONTENCODING_MACCHINESETRAD
:
742 enc
= kTextEncodingMacChineseTrad
;
744 case wxFONTENCODING_MACKOREAN
:
745 enc
= kTextEncodingMacKorean
;
747 case wxFONTENCODING_MACARABIC
:
748 enc
= kTextEncodingMacArabic
;
750 case wxFONTENCODING_MACHEBREW
:
751 enc
= kTextEncodingMacHebrew
;
753 case wxFONTENCODING_MACGREEK
:
754 enc
= kTextEncodingMacGreek
;
756 case wxFONTENCODING_MACCYRILLIC
:
757 enc
= kTextEncodingMacCyrillic
;
759 case wxFONTENCODING_MACDEVANAGARI
:
760 enc
= kTextEncodingMacDevanagari
;
762 case wxFONTENCODING_MACGURMUKHI
:
763 enc
= kTextEncodingMacGurmukhi
;
765 case wxFONTENCODING_MACGUJARATI
:
766 enc
= kTextEncodingMacGujarati
;
768 case wxFONTENCODING_MACORIYA
:
769 enc
= kTextEncodingMacOriya
;
771 case wxFONTENCODING_MACBENGALI
:
772 enc
= kTextEncodingMacBengali
;
774 case wxFONTENCODING_MACTAMIL
:
775 enc
= kTextEncodingMacTamil
;
777 case wxFONTENCODING_MACTELUGU
:
778 enc
= kTextEncodingMacTelugu
;
780 case wxFONTENCODING_MACKANNADA
:
781 enc
= kTextEncodingMacKannada
;
783 case wxFONTENCODING_MACMALAJALAM
:
784 enc
= kTextEncodingMacMalayalam
;
786 case wxFONTENCODING_MACSINHALESE
:
787 enc
= kTextEncodingMacSinhalese
;
789 case wxFONTENCODING_MACBURMESE
:
790 enc
= kTextEncodingMacBurmese
;
792 case wxFONTENCODING_MACKHMER
:
793 enc
= kTextEncodingMacKhmer
;
795 case wxFONTENCODING_MACTHAI
:
796 enc
= kTextEncodingMacThai
;
798 case wxFONTENCODING_MACLAOTIAN
:
799 enc
= kTextEncodingMacLaotian
;
801 case wxFONTENCODING_MACGEORGIAN
:
802 enc
= kTextEncodingMacGeorgian
;
804 case wxFONTENCODING_MACARMENIAN
:
805 enc
= kTextEncodingMacArmenian
;
807 case wxFONTENCODING_MACCHINESESIMP
:
808 enc
= kTextEncodingMacChineseSimp
;
810 case wxFONTENCODING_MACTIBETAN
:
811 enc
= kTextEncodingMacTibetan
;
813 case wxFONTENCODING_MACMONGOLIAN
:
814 enc
= kTextEncodingMacMongolian
;
816 case wxFONTENCODING_MACETHIOPIC
:
817 enc
= kTextEncodingMacEthiopic
;
819 case wxFONTENCODING_MACCENTRALEUR
:
820 enc
= kTextEncodingMacCentralEurRoman
;
822 case wxFONTENCODING_MACVIATNAMESE
:
823 enc
= kTextEncodingMacVietnamese
;
825 case wxFONTENCODING_MACARABICEXT
:
826 enc
= kTextEncodingMacExtArabic
;
828 case wxFONTENCODING_MACSYMBOL
:
829 enc
= kTextEncodingMacSymbol
;
831 case wxFONTENCODING_MACDINGBATS
:
832 enc
= kTextEncodingMacDingbats
;
834 case wxFONTENCODING_MACTURKISH
:
835 enc
= kTextEncodingMacTurkish
;
837 case wxFONTENCODING_MACCROATIAN
:
838 enc
= kTextEncodingMacCroatian
;
840 case wxFONTENCODING_MACICELANDIC
:
841 enc
= kTextEncodingMacIcelandic
;
843 case wxFONTENCODING_MACROMANIAN
:
844 enc
= kTextEncodingMacRomanian
;
846 case wxFONTENCODING_MACCELTIC
:
847 enc
= kTextEncodingMacCeltic
;
849 case wxFONTENCODING_MACGAELIC
:
850 enc
= kTextEncodingMacGaelic
;
852 case wxFONTENCODING_MACKEYBOARD
:
853 enc
= kTextEncodingMacKeyboardGlyphs
;
862 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
864 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
868 case kTextEncodingISOLatin1
:
869 enc
= wxFONTENCODING_ISO8859_1
;
871 case kTextEncodingISOLatin2
:
872 enc
= wxFONTENCODING_ISO8859_2
;
874 case kTextEncodingISOLatin3
:
875 enc
= wxFONTENCODING_ISO8859_3
;
877 case kTextEncodingISOLatin4
:
878 enc
= wxFONTENCODING_ISO8859_4
;
880 case kTextEncodingISOLatinCyrillic
:
881 enc
= wxFONTENCODING_ISO8859_5
;
883 case kTextEncodingISOLatinArabic
:
884 enc
= wxFONTENCODING_ISO8859_6
;
886 case kTextEncodingISOLatinGreek
:
887 enc
= wxFONTENCODING_ISO8859_7
;
889 case kTextEncodingISOLatinHebrew
:
890 enc
= wxFONTENCODING_ISO8859_8
;
892 case kTextEncodingISOLatin5
:
893 enc
= wxFONTENCODING_ISO8859_9
;
895 case kTextEncodingISOLatin6
:
896 enc
= wxFONTENCODING_ISO8859_10
;
898 case kTextEncodingISOLatin7
:
899 enc
= wxFONTENCODING_ISO8859_13
;
901 case kTextEncodingISOLatin8
:
902 enc
= wxFONTENCODING_ISO8859_14
;
904 case kTextEncodingISOLatin9
:
905 enc
=wxFONTENCODING_ISO8859_15
;
908 case kTextEncodingKOI8_R
:
909 enc
= wxFONTENCODING_KOI8
;
913 enc = wxFONTENCODING_BULGARIAN;
916 case kTextEncodingDOSLatinUS
:
917 enc
= wxFONTENCODING_CP437
;
919 case kTextEncodingDOSLatin1
:
920 enc
= wxFONTENCODING_CP850
;
922 case kTextEncodingDOSLatin2
:
923 enc
=wxFONTENCODING_CP852
;
925 case kTextEncodingDOSCyrillic
:
926 enc
= wxFONTENCODING_CP855
;
928 case kTextEncodingDOSRussian
:
929 enc
= wxFONTENCODING_CP866
;
931 case kTextEncodingDOSThai
:
932 enc
=wxFONTENCODING_CP874
;
934 case kTextEncodingDOSJapanese
:
935 enc
= wxFONTENCODING_CP932
;
937 case kTextEncodingDOSChineseSimplif
:
938 enc
= wxFONTENCODING_CP936
;
940 case kTextEncodingDOSKorean
:
941 enc
= wxFONTENCODING_CP949
;
943 case kTextEncodingDOSChineseTrad
:
944 enc
= wxFONTENCODING_CP950
;
947 case kTextEncodingWindowsLatin2
:
948 enc
= wxFONTENCODING_CP1250
;
950 case kTextEncodingWindowsCyrillic
:
951 enc
= wxFONTENCODING_CP1251
;
953 case kTextEncodingWindowsLatin1
:
954 enc
= wxFONTENCODING_CP1252
;
956 case kTextEncodingWindowsGreek
:
957 enc
= wxFONTENCODING_CP1253
;
959 case kTextEncodingWindowsLatin5
:
960 enc
= wxFONTENCODING_CP1254
;
962 case kTextEncodingWindowsHebrew
:
963 enc
= wxFONTENCODING_CP1255
;
965 case kTextEncodingWindowsArabic
:
966 enc
= wxFONTENCODING_CP1256
;
968 case kTextEncodingWindowsBalticRim
:
969 enc
=wxFONTENCODING_CP1257
;
971 case kTextEncodingEUC_JP
:
972 enc
= wxFONTENCODING_EUC_JP
;
975 case wxFONTENCODING_UTF7 :
976 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
978 case wxFONTENCODING_UTF8 :
979 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
981 case wxFONTENCODING_UTF16BE :
982 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
984 case wxFONTENCODING_UTF16LE :
985 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
987 case wxFONTENCODING_UTF32BE :
988 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
990 case wxFONTENCODING_UTF32LE :
991 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
994 case kTextEncodingMacRoman
:
995 enc
= wxFONTENCODING_MACROMAN
;
997 case kTextEncodingMacJapanese
:
998 enc
= wxFONTENCODING_MACJAPANESE
;
1000 case kTextEncodingMacChineseTrad
:
1001 enc
= wxFONTENCODING_MACCHINESETRAD
;
1003 case kTextEncodingMacKorean
:
1004 enc
= wxFONTENCODING_MACKOREAN
;
1006 case kTextEncodingMacArabic
:
1007 enc
=wxFONTENCODING_MACARABIC
;
1009 case kTextEncodingMacHebrew
:
1010 enc
= wxFONTENCODING_MACHEBREW
;
1012 case kTextEncodingMacGreek
:
1013 enc
= wxFONTENCODING_MACGREEK
;
1015 case kTextEncodingMacCyrillic
:
1016 enc
= wxFONTENCODING_MACCYRILLIC
;
1018 case kTextEncodingMacDevanagari
:
1019 enc
= wxFONTENCODING_MACDEVANAGARI
;
1021 case kTextEncodingMacGurmukhi
:
1022 enc
= wxFONTENCODING_MACGURMUKHI
;
1024 case kTextEncodingMacGujarati
:
1025 enc
= wxFONTENCODING_MACGUJARATI
;
1027 case kTextEncodingMacOriya
:
1028 enc
=wxFONTENCODING_MACORIYA
;
1030 case kTextEncodingMacBengali
:
1031 enc
=wxFONTENCODING_MACBENGALI
;
1033 case kTextEncodingMacTamil
:
1034 enc
= wxFONTENCODING_MACTAMIL
;
1036 case kTextEncodingMacTelugu
:
1037 enc
= wxFONTENCODING_MACTELUGU
;
1039 case kTextEncodingMacKannada
:
1040 enc
= wxFONTENCODING_MACKANNADA
;
1042 case kTextEncodingMacMalayalam
:
1043 enc
= wxFONTENCODING_MACMALAJALAM
;
1045 case kTextEncodingMacSinhalese
:
1046 enc
= wxFONTENCODING_MACSINHALESE
;
1048 case kTextEncodingMacBurmese
:
1049 enc
= wxFONTENCODING_MACBURMESE
;
1051 case kTextEncodingMacKhmer
:
1052 enc
= wxFONTENCODING_MACKHMER
;
1054 case kTextEncodingMacThai
:
1055 enc
= wxFONTENCODING_MACTHAI
;
1057 case kTextEncodingMacLaotian
:
1058 enc
= wxFONTENCODING_MACLAOTIAN
;
1060 case kTextEncodingMacGeorgian
:
1061 enc
= wxFONTENCODING_MACGEORGIAN
;
1063 case kTextEncodingMacArmenian
:
1064 enc
= wxFONTENCODING_MACARMENIAN
;
1066 case kTextEncodingMacChineseSimp
:
1067 enc
= wxFONTENCODING_MACCHINESESIMP
;
1069 case kTextEncodingMacTibetan
:
1070 enc
= wxFONTENCODING_MACTIBETAN
;
1072 case kTextEncodingMacMongolian
:
1073 enc
= wxFONTENCODING_MACMONGOLIAN
;
1075 case kTextEncodingMacEthiopic
:
1076 enc
= wxFONTENCODING_MACETHIOPIC
;
1078 case kTextEncodingMacCentralEurRoman
:
1079 enc
= wxFONTENCODING_MACCENTRALEUR
;
1081 case kTextEncodingMacVietnamese
:
1082 enc
= wxFONTENCODING_MACVIATNAMESE
;
1084 case kTextEncodingMacExtArabic
:
1085 enc
= wxFONTENCODING_MACARABICEXT
;
1087 case kTextEncodingMacSymbol
:
1088 enc
= wxFONTENCODING_MACSYMBOL
;
1090 case kTextEncodingMacDingbats
:
1091 enc
= wxFONTENCODING_MACDINGBATS
;
1093 case kTextEncodingMacTurkish
:
1094 enc
= wxFONTENCODING_MACTURKISH
;
1096 case kTextEncodingMacCroatian
:
1097 enc
= wxFONTENCODING_MACCROATIAN
;
1099 case kTextEncodingMacIcelandic
:
1100 enc
= wxFONTENCODING_MACICELANDIC
;
1102 case kTextEncodingMacRomanian
:
1103 enc
= wxFONTENCODING_MACROMANIAN
;
1105 case kTextEncodingMacCeltic
:
1106 enc
= wxFONTENCODING_MACCELTIC
;
1108 case kTextEncodingMacGaelic
:
1109 enc
= wxFONTENCODING_MACGAELIC
;
1111 case kTextEncodingMacKeyboardGlyphs
:
1112 enc
= wxFONTENCODING_MACKEYBOARD
;
1118 #endif // wxUSE_BASE
1124 // CFStringRefs (Carbon only)
1129 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1130 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1135 wxMacConvertNewlines13To10( &str
) ;
1137 #if SIZEOF_WCHAR_T == 2
1138 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1139 (UniChar
*)str
.wc_str() , str
.Len() );
1141 wxMBConvUTF16BE converter
;
1142 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1143 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1144 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1145 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1146 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1149 #else // not wxUSE_UNICODE
1150 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1151 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1156 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1158 Size cflen
= CFStringGetLength( m_cfs
) ;
1160 wxChar
* buf
= NULL
;
1163 #if SIZEOF_WCHAR_T == 2
1164 buf
= new wxChar
[ cflen
+ 1 ] ;
1165 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1168 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1169 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1171 wxMBConvUTF16BE converter
;
1172 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1173 buf
= new wxChar
[ noChars
+ 1 ] ;
1174 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1179 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1180 '?' , false , NULL
, 0 , &cStrLen
) ;
1181 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1182 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1183 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1188 wxMacConvertNewlines10To13( buf
) ;
1189 wxString
result(buf
) ;
1194 #endif //TARGET_CARBON
1196 void wxMacConvertNewlines13To10( char * data
)
1199 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1206 void wxMacConvertNewlines10To13( char * data
)
1209 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1216 void wxMacConvertNewlines13To10( wxString
* data
)
1218 size_t len
= data
->Length() ;
1220 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1223 wxString
temp(*data
) ;
1224 wxStringBuffer
buf(*data
,len
) ;
1225 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1227 wxMacConvertNewlines13To10( buf
) ;
1230 void wxMacConvertNewlines10To13( wxString
* data
)
1232 size_t len
= data
->Length() ;
1234 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1237 wxString
temp(*data
) ;
1238 wxStringBuffer
buf(*data
,len
) ;
1239 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1240 wxMacConvertNewlines10To13( buf
) ;
1245 void wxMacConvertNewlines13To10( wxChar
* data
)
1247 wxChar
* buf
= data
;
1248 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1255 void wxMacConvertNewlines10To13( wxChar
* data
)
1257 wxChar
* buf
= data
;
1258 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1266 // ----------------------------------------------------------------------------
1267 // debugging support
1268 // ----------------------------------------------------------------------------
1270 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1272 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1274 #ifndef __MetroNubUtils__
1275 #include "MetroNubUtils.h"
1279 #include <Gestalt.h>
1282 #if TARGET_API_MAC_CARBON
1284 #include <CodeFragments.h>
1286 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1288 ProcPtr gCallUniversalProc_Proc
= NULL
;
1292 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1294 static long fRunOnce
= false;
1296 /* ---------------------------------------------------------------------------
1298 --------------------------------------------------------------------------- */
1300 Boolean
IsMetroNubInstalled()
1307 gMetroNubEntry
= NULL
;
1309 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1311 /* look for MetroNub's Gestalt selector */
1312 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1315 #if TARGET_API_MAC_CARBON
1316 if (gCallUniversalProc_Proc
== NULL
)
1318 CFragConnectionID connectionID
;
1321 ProcPtr symbolAddress
;
1323 CFragSymbolClass symbolClass
;
1325 symbolAddress
= NULL
;
1326 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1327 &connectionID
, &mainAddress
, errorString
);
1331 gCallUniversalProc_Proc
= NULL
;
1335 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1336 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1340 gCallUniversalProc_Proc
= NULL
;
1347 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1349 /* make sure the version of the API is compatible */
1350 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1351 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1352 gMetroNubEntry
= block
; /* success! */
1361 #if TARGET_API_MAC_CARBON
1362 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1364 return (gMetroNubEntry
!= NULL
);
1368 /* ---------------------------------------------------------------------------
1369 IsMWDebuggerRunning [v1 API]
1370 --------------------------------------------------------------------------- */
1372 Boolean
IsMWDebuggerRunning()
1374 if (IsMetroNubInstalled())
1375 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1380 /* ---------------------------------------------------------------------------
1381 AmIBeingMWDebugged [v1 API]
1382 --------------------------------------------------------------------------- */
1384 Boolean
AmIBeingMWDebugged()
1386 if (IsMetroNubInstalled())
1387 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1392 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1394 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1399 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1404 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)