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 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
193 wxMemorySize
wxGetFreeMemory()
195 return (wxMemorySize
)FreeMem() ;
198 void wxUsleep(unsigned long milliseconds
)
200 clock_t start
= clock() ;
204 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
207 void wxSleep(int nSecs
)
209 wxUsleep(1000*nSecs
);
212 // Consume all events until no more left
217 #endif // !__DARWIN__
225 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
227 static wxToolkitInfo info
;
228 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
229 info
.name
= _T("wxBase");
237 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
239 static wxToolkitInfo info
;
240 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
241 info
.shortName
= _T("mac");
242 info
.name
= _T("wxMac");
243 #ifdef __WXUNIVERSAL__
244 info
.shortName
<< _T("univ");
245 info
.name
<< _T("/wxUniversal");
250 // Reading and writing resources (eg WIN.INI, .Xdefaults)
252 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
258 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
261 buf
.Printf(wxT("%.4f"), value
);
263 return wxWriteResource(section
, entry
, buf
, file
);
266 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
269 buf
.Printf(wxT("%ld"), value
);
271 return wxWriteResource(section
, entry
, buf
, file
);
274 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
277 buf
.Printf(wxT("%d"), value
);
279 return wxWriteResource(section
, entry
, buf
, file
);
282 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
288 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
291 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
294 *value
= (float)strtod(s
, NULL
);
301 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
304 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
307 *value
= strtol(s
, NULL
, 10);
314 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
317 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
320 *value
= (int)strtol(s
, NULL
, 10);
326 #endif // wxUSE_RESOURCES
328 int gs_wxBusyCursorCount
= 0;
329 extern wxCursor gMacCurrentCursor
;
330 wxCursor gMacStoredActiveCursor
;
332 // Set the cursor to the busy cursor for all windows
333 void wxBeginBusyCursor(const wxCursor
*cursor
)
335 if (gs_wxBusyCursorCount
++ == 0)
337 gMacStoredActiveCursor
= gMacCurrentCursor
;
338 cursor
->MacInstall() ;
340 //else: nothing to do, already set
343 // Restore cursor to normal
344 void wxEndBusyCursor()
346 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
347 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
349 if (--gs_wxBusyCursorCount
== 0)
351 gMacStoredActiveCursor
.MacInstall() ;
352 gMacStoredActiveCursor
= wxNullCursor
;
356 // true if we're between the above two calls
359 return (gs_wxBusyCursorCount
> 0);
366 wxString
wxMacFindFolderNoSeparator( short vol
,
368 Boolean createFolder
)
374 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
377 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
379 strDir
= wxMacFSSpec2MacFilename( &file
);
385 wxString
wxMacFindFolder( short vol
,
387 Boolean createFolder
)
389 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
396 // Check whether this window wants to process messages, e.g. Stop button
397 // in long calculations.
398 bool wxCheckForInterrupt(wxWindow
*wnd
)
404 void wxGetMousePosition( int* x
, int* y
)
409 LocalToGlobal( &pt
) ;
414 // Return true if we have a colour display
415 bool wxColourDisplay()
420 // Returns depth of screen
424 SetRect(&globRect
, -32760, -32760, 32760, 32760);
425 GDHandle theMaxDevice
;
428 theMaxDevice
= GetMaxDevice(&globRect
);
429 if (theMaxDevice
!= nil
)
430 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
435 // Get size of display
436 void wxDisplaySize(int *width
, int *height
)
439 GetQDGlobalsScreenBits( &screenBits
);
442 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
444 if (height
!= NULL
) {
445 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
449 void wxDisplaySizeMM(int *width
, int *height
)
451 wxDisplaySize(width
, height
);
452 // on mac 72 is fixed (at least now ;-)
453 float cvPt2Mm
= 25.4 / 72;
456 *width
= int( *width
* cvPt2Mm
);
458 if (height
!= NULL
) {
459 *height
= int( *height
* cvPt2Mm
);
463 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
467 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
473 *width
= r
.right
- r
.left
;
475 *height
= r
.bottom
- r
.top
;
478 GetQDGlobalsScreenBits( &screenBits
);
484 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
486 if (height
!= NULL
) {
487 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
492 GetThemeMenuBarHeight( &mheight
) ;
494 mheight
= LMGetMBarHeight() ;
496 if (height
!= NULL
) {
504 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
506 return wxGenericFindWindowAtPoint(pt
);
513 wxString
wxGetOsDescription()
515 #ifdef WXWIN_OS_DESCRIPTION
516 // use configure generated description if available
517 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
519 return wxT("MacOS") ; //TODO:define further
524 wxChar
*wxGetUserHome (const wxString
& user
)
530 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
540 int pos
= p
.Find(':') ;
541 if ( pos
!= wxNOT_FOUND
) {
550 wxMacStringToPascal( p
, volumeName
) ;
551 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
552 if ( err
== noErr
) {
554 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
557 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
561 return err
== noErr
;
563 #endif // !__DARWIN__
565 //---------------------------------------------------------------------------
566 // wxMac Specific utility functions
567 //---------------------------------------------------------------------------
569 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
571 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
572 int len
= strlen(buf
) ;
577 memcpy( (char*) &to
[1] , buf
, len
) ;
580 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
582 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
586 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
588 TextEncodingBase enc
= 0 ;
589 if ( encoding
== wxFONTENCODING_DEFAULT
)
592 encoding
= wxFont::GetDefaultEncoding() ;
594 encoding
= wxLocale::GetSystemEncoding() ;
600 case wxFONTENCODING_ISO8859_1
:
601 enc
= kTextEncodingISOLatin1
;
603 case wxFONTENCODING_ISO8859_2
:
604 enc
= kTextEncodingISOLatin2
;
606 case wxFONTENCODING_ISO8859_3
:
607 enc
= kTextEncodingISOLatin3
;
609 case wxFONTENCODING_ISO8859_4
:
610 enc
= kTextEncodingISOLatin4
;
612 case wxFONTENCODING_ISO8859_5
:
613 enc
= kTextEncodingISOLatinCyrillic
;
615 case wxFONTENCODING_ISO8859_6
:
616 enc
= kTextEncodingISOLatinArabic
;
618 case wxFONTENCODING_ISO8859_7
:
619 enc
= kTextEncodingISOLatinGreek
;
621 case wxFONTENCODING_ISO8859_8
:
622 enc
= kTextEncodingISOLatinHebrew
;
624 case wxFONTENCODING_ISO8859_9
:
625 enc
= kTextEncodingISOLatin5
;
627 case wxFONTENCODING_ISO8859_10
:
628 enc
= kTextEncodingISOLatin6
;
630 case wxFONTENCODING_ISO8859_13
:
631 enc
= kTextEncodingISOLatin7
;
633 case wxFONTENCODING_ISO8859_14
:
634 enc
= kTextEncodingISOLatin8
;
636 case wxFONTENCODING_ISO8859_15
:
637 enc
= kTextEncodingISOLatin9
;
640 case wxFONTENCODING_KOI8
:
641 enc
= kTextEncodingKOI8_R
;
643 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
644 enc
= kTextEncodingDOSRussian
;
647 case wxFONTENCODING_BULGARIAN :
651 case wxFONTENCODING_CP437
:
652 enc
=kTextEncodingDOSLatinUS
;
654 case wxFONTENCODING_CP850
:
655 enc
= kTextEncodingDOSLatin1
;
657 case wxFONTENCODING_CP852
:
658 enc
= kTextEncodingDOSLatin2
;
660 case wxFONTENCODING_CP855
:
661 enc
= kTextEncodingDOSCyrillic
;
663 case wxFONTENCODING_CP866
:
664 enc
=kTextEncodingDOSRussian
;
666 case wxFONTENCODING_CP874
:
667 enc
= kTextEncodingDOSThai
;
669 case wxFONTENCODING_CP932
:
670 enc
= kTextEncodingDOSJapanese
;
672 case wxFONTENCODING_CP936
:
673 enc
=kTextEncodingDOSChineseSimplif
;
675 case wxFONTENCODING_CP949
:
676 enc
= kTextEncodingDOSKorean
;
678 case wxFONTENCODING_CP950
:
679 enc
= kTextEncodingDOSChineseTrad
;
682 case wxFONTENCODING_CP1250
:
683 enc
= kTextEncodingWindowsLatin2
;
685 case wxFONTENCODING_CP1251
:
686 enc
=kTextEncodingWindowsCyrillic
;
688 case wxFONTENCODING_CP1252
:
689 enc
=kTextEncodingWindowsLatin1
;
691 case wxFONTENCODING_CP1253
:
692 enc
= kTextEncodingWindowsGreek
;
694 case wxFONTENCODING_CP1254
:
695 enc
= kTextEncodingWindowsLatin5
;
697 case wxFONTENCODING_CP1255
:
698 enc
=kTextEncodingWindowsHebrew
;
700 case wxFONTENCODING_CP1256
:
701 enc
=kTextEncodingWindowsArabic
;
703 case wxFONTENCODING_CP1257
:
704 enc
= kTextEncodingWindowsBalticRim
;
707 case wxFONTENCODING_UTF7
:
708 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
710 case wxFONTENCODING_UTF8
:
711 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
713 case wxFONTENCODING_EUC_JP
:
714 enc
= kTextEncodingEUC_JP
;
716 case wxFONTENCODING_UTF16BE
:
717 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
719 case wxFONTENCODING_UTF16LE
:
720 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
722 case wxFONTENCODING_UTF32BE
:
723 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
725 case wxFONTENCODING_UTF32LE
:
726 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
729 case wxFONTENCODING_MACROMAN
:
730 enc
= kTextEncodingMacRoman
;
732 case wxFONTENCODING_MACJAPANESE
:
733 enc
= kTextEncodingMacJapanese
;
735 case wxFONTENCODING_MACCHINESETRAD
:
736 enc
= kTextEncodingMacChineseTrad
;
738 case wxFONTENCODING_MACKOREAN
:
739 enc
= kTextEncodingMacKorean
;
741 case wxFONTENCODING_MACARABIC
:
742 enc
= kTextEncodingMacArabic
;
744 case wxFONTENCODING_MACHEBREW
:
745 enc
= kTextEncodingMacHebrew
;
747 case wxFONTENCODING_MACGREEK
:
748 enc
= kTextEncodingMacGreek
;
750 case wxFONTENCODING_MACCYRILLIC
:
751 enc
= kTextEncodingMacCyrillic
;
753 case wxFONTENCODING_MACDEVANAGARI
:
754 enc
= kTextEncodingMacDevanagari
;
756 case wxFONTENCODING_MACGURMUKHI
:
757 enc
= kTextEncodingMacGurmukhi
;
759 case wxFONTENCODING_MACGUJARATI
:
760 enc
= kTextEncodingMacGujarati
;
762 case wxFONTENCODING_MACORIYA
:
763 enc
= kTextEncodingMacOriya
;
765 case wxFONTENCODING_MACBENGALI
:
766 enc
= kTextEncodingMacBengali
;
768 case wxFONTENCODING_MACTAMIL
:
769 enc
= kTextEncodingMacTamil
;
771 case wxFONTENCODING_MACTELUGU
:
772 enc
= kTextEncodingMacTelugu
;
774 case wxFONTENCODING_MACKANNADA
:
775 enc
= kTextEncodingMacKannada
;
777 case wxFONTENCODING_MACMALAJALAM
:
778 enc
= kTextEncodingMacMalayalam
;
780 case wxFONTENCODING_MACSINHALESE
:
781 enc
= kTextEncodingMacSinhalese
;
783 case wxFONTENCODING_MACBURMESE
:
784 enc
= kTextEncodingMacBurmese
;
786 case wxFONTENCODING_MACKHMER
:
787 enc
= kTextEncodingMacKhmer
;
789 case wxFONTENCODING_MACTHAI
:
790 enc
= kTextEncodingMacThai
;
792 case wxFONTENCODING_MACLAOTIAN
:
793 enc
= kTextEncodingMacLaotian
;
795 case wxFONTENCODING_MACGEORGIAN
:
796 enc
= kTextEncodingMacGeorgian
;
798 case wxFONTENCODING_MACARMENIAN
:
799 enc
= kTextEncodingMacArmenian
;
801 case wxFONTENCODING_MACCHINESESIMP
:
802 enc
= kTextEncodingMacChineseSimp
;
804 case wxFONTENCODING_MACTIBETAN
:
805 enc
= kTextEncodingMacTibetan
;
807 case wxFONTENCODING_MACMONGOLIAN
:
808 enc
= kTextEncodingMacMongolian
;
810 case wxFONTENCODING_MACETHIOPIC
:
811 enc
= kTextEncodingMacEthiopic
;
813 case wxFONTENCODING_MACCENTRALEUR
:
814 enc
= kTextEncodingMacCentralEurRoman
;
816 case wxFONTENCODING_MACVIATNAMESE
:
817 enc
= kTextEncodingMacVietnamese
;
819 case wxFONTENCODING_MACARABICEXT
:
820 enc
= kTextEncodingMacExtArabic
;
822 case wxFONTENCODING_MACSYMBOL
:
823 enc
= kTextEncodingMacSymbol
;
825 case wxFONTENCODING_MACDINGBATS
:
826 enc
= kTextEncodingMacDingbats
;
828 case wxFONTENCODING_MACTURKISH
:
829 enc
= kTextEncodingMacTurkish
;
831 case wxFONTENCODING_MACCROATIAN
:
832 enc
= kTextEncodingMacCroatian
;
834 case wxFONTENCODING_MACICELANDIC
:
835 enc
= kTextEncodingMacIcelandic
;
837 case wxFONTENCODING_MACROMANIAN
:
838 enc
= kTextEncodingMacRomanian
;
840 case wxFONTENCODING_MACCELTIC
:
841 enc
= kTextEncodingMacCeltic
;
843 case wxFONTENCODING_MACGAELIC
:
844 enc
= kTextEncodingMacGaelic
;
846 case wxFONTENCODING_MACKEYBOARD
:
847 enc
= kTextEncodingMacKeyboardGlyphs
;
856 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
858 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
862 case kTextEncodingISOLatin1
:
863 enc
= wxFONTENCODING_ISO8859_1
;
865 case kTextEncodingISOLatin2
:
866 enc
= wxFONTENCODING_ISO8859_2
;
868 case kTextEncodingISOLatin3
:
869 enc
= wxFONTENCODING_ISO8859_3
;
871 case kTextEncodingISOLatin4
:
872 enc
= wxFONTENCODING_ISO8859_4
;
874 case kTextEncodingISOLatinCyrillic
:
875 enc
= wxFONTENCODING_ISO8859_5
;
877 case kTextEncodingISOLatinArabic
:
878 enc
= wxFONTENCODING_ISO8859_6
;
880 case kTextEncodingISOLatinGreek
:
881 enc
= wxFONTENCODING_ISO8859_7
;
883 case kTextEncodingISOLatinHebrew
:
884 enc
= wxFONTENCODING_ISO8859_8
;
886 case kTextEncodingISOLatin5
:
887 enc
= wxFONTENCODING_ISO8859_9
;
889 case kTextEncodingISOLatin6
:
890 enc
= wxFONTENCODING_ISO8859_10
;
892 case kTextEncodingISOLatin7
:
893 enc
= wxFONTENCODING_ISO8859_13
;
895 case kTextEncodingISOLatin8
:
896 enc
= wxFONTENCODING_ISO8859_14
;
898 case kTextEncodingISOLatin9
:
899 enc
=wxFONTENCODING_ISO8859_15
;
902 case kTextEncodingKOI8_R
:
903 enc
= wxFONTENCODING_KOI8
;
907 enc = wxFONTENCODING_BULGARIAN;
910 case kTextEncodingDOSLatinUS
:
911 enc
= wxFONTENCODING_CP437
;
913 case kTextEncodingDOSLatin1
:
914 enc
= wxFONTENCODING_CP850
;
916 case kTextEncodingDOSLatin2
:
917 enc
=wxFONTENCODING_CP852
;
919 case kTextEncodingDOSCyrillic
:
920 enc
= wxFONTENCODING_CP855
;
922 case kTextEncodingDOSRussian
:
923 enc
= wxFONTENCODING_CP866
;
925 case kTextEncodingDOSThai
:
926 enc
=wxFONTENCODING_CP874
;
928 case kTextEncodingDOSJapanese
:
929 enc
= wxFONTENCODING_CP932
;
931 case kTextEncodingDOSChineseSimplif
:
932 enc
= wxFONTENCODING_CP936
;
934 case kTextEncodingDOSKorean
:
935 enc
= wxFONTENCODING_CP949
;
937 case kTextEncodingDOSChineseTrad
:
938 enc
= wxFONTENCODING_CP950
;
941 case kTextEncodingWindowsLatin2
:
942 enc
= wxFONTENCODING_CP1250
;
944 case kTextEncodingWindowsCyrillic
:
945 enc
= wxFONTENCODING_CP1251
;
947 case kTextEncodingWindowsLatin1
:
948 enc
= wxFONTENCODING_CP1252
;
950 case kTextEncodingWindowsGreek
:
951 enc
= wxFONTENCODING_CP1253
;
953 case kTextEncodingWindowsLatin5
:
954 enc
= wxFONTENCODING_CP1254
;
956 case kTextEncodingWindowsHebrew
:
957 enc
= wxFONTENCODING_CP1255
;
959 case kTextEncodingWindowsArabic
:
960 enc
= wxFONTENCODING_CP1256
;
962 case kTextEncodingWindowsBalticRim
:
963 enc
=wxFONTENCODING_CP1257
;
965 case kTextEncodingEUC_JP
:
966 enc
= wxFONTENCODING_EUC_JP
;
969 case wxFONTENCODING_UTF7 :
970 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
972 case wxFONTENCODING_UTF8 :
973 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
975 case wxFONTENCODING_UTF16BE :
976 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
978 case wxFONTENCODING_UTF16LE :
979 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
981 case wxFONTENCODING_UTF32BE :
982 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
984 case wxFONTENCODING_UTF32LE :
985 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
988 case kTextEncodingMacRoman
:
989 enc
= wxFONTENCODING_MACROMAN
;
991 case kTextEncodingMacJapanese
:
992 enc
= wxFONTENCODING_MACJAPANESE
;
994 case kTextEncodingMacChineseTrad
:
995 enc
= wxFONTENCODING_MACCHINESETRAD
;
997 case kTextEncodingMacKorean
:
998 enc
= wxFONTENCODING_MACKOREAN
;
1000 case kTextEncodingMacArabic
:
1001 enc
=wxFONTENCODING_MACARABIC
;
1003 case kTextEncodingMacHebrew
:
1004 enc
= wxFONTENCODING_MACHEBREW
;
1006 case kTextEncodingMacGreek
:
1007 enc
= wxFONTENCODING_MACGREEK
;
1009 case kTextEncodingMacCyrillic
:
1010 enc
= wxFONTENCODING_MACCYRILLIC
;
1012 case kTextEncodingMacDevanagari
:
1013 enc
= wxFONTENCODING_MACDEVANAGARI
;
1015 case kTextEncodingMacGurmukhi
:
1016 enc
= wxFONTENCODING_MACGURMUKHI
;
1018 case kTextEncodingMacGujarati
:
1019 enc
= wxFONTENCODING_MACGUJARATI
;
1021 case kTextEncodingMacOriya
:
1022 enc
=wxFONTENCODING_MACORIYA
;
1024 case kTextEncodingMacBengali
:
1025 enc
=wxFONTENCODING_MACBENGALI
;
1027 case kTextEncodingMacTamil
:
1028 enc
= wxFONTENCODING_MACTAMIL
;
1030 case kTextEncodingMacTelugu
:
1031 enc
= wxFONTENCODING_MACTELUGU
;
1033 case kTextEncodingMacKannada
:
1034 enc
= wxFONTENCODING_MACKANNADA
;
1036 case kTextEncodingMacMalayalam
:
1037 enc
= wxFONTENCODING_MACMALAJALAM
;
1039 case kTextEncodingMacSinhalese
:
1040 enc
= wxFONTENCODING_MACSINHALESE
;
1042 case kTextEncodingMacBurmese
:
1043 enc
= wxFONTENCODING_MACBURMESE
;
1045 case kTextEncodingMacKhmer
:
1046 enc
= wxFONTENCODING_MACKHMER
;
1048 case kTextEncodingMacThai
:
1049 enc
= wxFONTENCODING_MACTHAI
;
1051 case kTextEncodingMacLaotian
:
1052 enc
= wxFONTENCODING_MACLAOTIAN
;
1054 case kTextEncodingMacGeorgian
:
1055 enc
= wxFONTENCODING_MACGEORGIAN
;
1057 case kTextEncodingMacArmenian
:
1058 enc
= wxFONTENCODING_MACARMENIAN
;
1060 case kTextEncodingMacChineseSimp
:
1061 enc
= wxFONTENCODING_MACCHINESESIMP
;
1063 case kTextEncodingMacTibetan
:
1064 enc
= wxFONTENCODING_MACTIBETAN
;
1066 case kTextEncodingMacMongolian
:
1067 enc
= wxFONTENCODING_MACMONGOLIAN
;
1069 case kTextEncodingMacEthiopic
:
1070 enc
= wxFONTENCODING_MACETHIOPIC
;
1072 case kTextEncodingMacCentralEurRoman
:
1073 enc
= wxFONTENCODING_MACCENTRALEUR
;
1075 case kTextEncodingMacVietnamese
:
1076 enc
= wxFONTENCODING_MACVIATNAMESE
;
1078 case kTextEncodingMacExtArabic
:
1079 enc
= wxFONTENCODING_MACARABICEXT
;
1081 case kTextEncodingMacSymbol
:
1082 enc
= wxFONTENCODING_MACSYMBOL
;
1084 case kTextEncodingMacDingbats
:
1085 enc
= wxFONTENCODING_MACDINGBATS
;
1087 case kTextEncodingMacTurkish
:
1088 enc
= wxFONTENCODING_MACTURKISH
;
1090 case kTextEncodingMacCroatian
:
1091 enc
= wxFONTENCODING_MACCROATIAN
;
1093 case kTextEncodingMacIcelandic
:
1094 enc
= wxFONTENCODING_MACICELANDIC
;
1096 case kTextEncodingMacRomanian
:
1097 enc
= wxFONTENCODING_MACROMANIAN
;
1099 case kTextEncodingMacCeltic
:
1100 enc
= wxFONTENCODING_MACCELTIC
;
1102 case kTextEncodingMacGaelic
:
1103 enc
= wxFONTENCODING_MACGAELIC
;
1105 case kTextEncodingMacKeyboardGlyphs
:
1106 enc
= wxFONTENCODING_MACKEYBOARD
;
1112 #endif // wxUSE_BASE
1118 // CFStringRefs (Carbon only)
1123 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1124 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1129 wxMacConvertNewlines13To10( &str
) ;
1131 #if SIZEOF_WCHAR_T == 2
1132 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1133 (UniChar
*)str
.wc_str() , str
.Len() );
1135 wxMBConvUTF16BE converter
;
1136 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1137 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1138 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1139 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1140 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1143 #else // not wxUSE_UNICODE
1144 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1145 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1150 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1152 Size cflen
= CFStringGetLength( m_cfs
) ;
1154 wxChar
* buf
= NULL
;
1157 #if SIZEOF_WCHAR_T == 2
1158 buf
= new wxChar
[ cflen
+ 1 ] ;
1159 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1162 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1163 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1165 wxMBConvUTF16BE converter
;
1166 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1167 buf
= new wxChar
[ noChars
+ 1 ] ;
1168 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1173 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1174 '?' , false , NULL
, 0 , &cStrLen
) ;
1175 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1176 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1177 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1182 wxMacConvertNewlines10To13( buf
) ;
1183 wxString
result(buf
) ;
1188 #endif //TARGET_CARBON
1190 void wxMacConvertNewlines13To10( char * data
)
1193 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1200 void wxMacConvertNewlines10To13( char * data
)
1203 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1210 void wxMacConvertNewlines13To10( wxString
* data
)
1212 size_t len
= data
->length() ;
1214 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1217 wxString
temp(*data
) ;
1218 wxStringBuffer
buf(*data
,len
) ;
1219 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1221 wxMacConvertNewlines13To10( buf
) ;
1224 void wxMacConvertNewlines10To13( wxString
* data
)
1226 size_t len
= data
->length() ;
1228 if ( data
->empty() || wxStrchr(data
->c_str(),0x0a)==NULL
)
1231 wxString
temp(*data
) ;
1232 wxStringBuffer
buf(*data
,len
) ;
1233 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1234 wxMacConvertNewlines10To13( buf
) ;
1239 void wxMacConvertNewlines13To10( wxChar
* data
)
1241 wxChar
* buf
= data
;
1242 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1249 void wxMacConvertNewlines10To13( wxChar
* data
)
1251 wxChar
* buf
= data
;
1252 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1260 // ----------------------------------------------------------------------------
1261 // debugging support
1262 // ----------------------------------------------------------------------------
1264 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1266 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1268 #ifndef __MetroNubUtils__
1269 #include "MetroNubUtils.h"
1273 #include <Gestalt.h>
1276 #if TARGET_API_MAC_CARBON
1278 #include <CodeFragments.h>
1280 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1282 ProcPtr gCallUniversalProc_Proc
= NULL
;
1286 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1288 static long fRunOnce
= false;
1290 /* ---------------------------------------------------------------------------
1292 --------------------------------------------------------------------------- */
1294 Boolean
IsMetroNubInstalled()
1301 gMetroNubEntry
= NULL
;
1303 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1305 /* look for MetroNub's Gestalt selector */
1306 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1309 #if TARGET_API_MAC_CARBON
1310 if (gCallUniversalProc_Proc
== NULL
)
1312 CFragConnectionID connectionID
;
1315 ProcPtr symbolAddress
;
1317 CFragSymbolClass symbolClass
;
1319 symbolAddress
= NULL
;
1320 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1321 &connectionID
, &mainAddress
, errorString
);
1325 gCallUniversalProc_Proc
= NULL
;
1329 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1330 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1334 gCallUniversalProc_Proc
= NULL
;
1341 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1343 /* make sure the version of the API is compatible */
1344 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1345 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1346 gMetroNubEntry
= block
; /* success! */
1355 #if TARGET_API_MAC_CARBON
1356 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1358 return (gMetroNubEntry
!= NULL
);
1362 /* ---------------------------------------------------------------------------
1363 IsMWDebuggerRunning [v1 API]
1364 --------------------------------------------------------------------------- */
1366 Boolean
IsMWDebuggerRunning()
1368 if (IsMetroNubInstalled())
1369 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1374 /* ---------------------------------------------------------------------------
1375 AmIBeingMWDebugged [v1 API]
1376 --------------------------------------------------------------------------- */
1378 Boolean
AmIBeingMWDebugged()
1380 if (IsMetroNubInstalled())
1381 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1386 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1388 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1393 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1398 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)