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
)
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 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
194 long wxGetFreeMemory()
199 void wxUsleep(unsigned long milliseconds
)
201 clock_t start
= clock() ;
205 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
208 void wxSleep(int nSecs
)
210 wxUsleep(1000*nSecs
);
213 // Consume all events until no more left
218 #endif // !__DARWIN__
226 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
228 static wxToolkitInfo info
;
229 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
230 info
.name
= _T("wxBase");
238 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
240 static wxToolkitInfo info
;
241 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
242 info
.shortName
= _T("mac");
243 info
.name
= _T("wxMac");
244 #ifdef __WXUNIVERSAL__
245 info
.shortName
<< _T("univ");
246 info
.name
<< _T("/wxUniversal");
251 // Reading and writing resources (eg WIN.INI, .Xdefaults)
253 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
259 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
262 buf
.Printf(wxT("%.4f"), value
);
264 return wxWriteResource(section
, entry
, buf
, file
);
267 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
270 buf
.Printf(wxT("%ld"), value
);
272 return wxWriteResource(section
, entry
, buf
, file
);
275 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
278 buf
.Printf(wxT("%d"), value
);
280 return wxWriteResource(section
, entry
, buf
, file
);
283 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
289 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
292 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
295 *value
= (float)strtod(s
, NULL
);
302 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
305 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
308 *value
= strtol(s
, NULL
, 10);
315 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
318 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
321 *value
= (int)strtol(s
, NULL
, 10);
327 #endif // wxUSE_RESOURCES
329 int gs_wxBusyCursorCount
= 0;
330 extern wxCursor gMacCurrentCursor
;
331 wxCursor gMacStoredActiveCursor
;
333 // Set the cursor to the busy cursor for all windows
334 void wxBeginBusyCursor(wxCursor
*cursor
)
336 if (gs_wxBusyCursorCount
++ == 0)
338 gMacStoredActiveCursor
= gMacCurrentCursor
;
339 cursor
->MacInstall() ;
341 //else: nothing to do, already set
344 // Restore cursor to normal
345 void wxEndBusyCursor()
347 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
348 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
350 if (--gs_wxBusyCursorCount
== 0)
352 gMacStoredActiveCursor
.MacInstall() ;
353 gMacStoredActiveCursor
= wxNullCursor
;
357 // TRUE if we're between the above two calls
360 return (gs_wxBusyCursorCount
> 0);
367 wxString
wxMacFindFolder( short vol
,
369 Boolean createFolder
)
375 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
378 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
380 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
390 // Check whether this window wants to process messages, e.g. Stop button
391 // in long calculations.
392 bool wxCheckForInterrupt(wxWindow
*wnd
)
398 void wxGetMousePosition( int* x
, int* y
)
403 LocalToGlobal( &pt
) ;
408 // Return TRUE if we have a colour display
409 bool wxColourDisplay()
414 // Returns depth of screen
418 SetRect(&globRect
, -32760, -32760, 32760, 32760);
419 GDHandle theMaxDevice
;
422 theMaxDevice
= GetMaxDevice(&globRect
);
423 if (theMaxDevice
!= nil
)
424 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
429 // Get size of display
430 void wxDisplaySize(int *width
, int *height
)
433 GetQDGlobalsScreenBits( &screenBits
);
436 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
438 if (height
!= NULL
) {
439 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
443 void wxDisplaySizeMM(int *width
, int *height
)
445 wxDisplaySize(width
, height
);
446 // on mac 72 is fixed (at least now ;-)
447 float cvPt2Mm
= 25.4 / 72;
450 *width
= int( *width
* cvPt2Mm
);
452 if (height
!= NULL
) {
453 *height
= int( *height
* cvPt2Mm
);
457 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
461 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
467 *width
= r
.right
- r
.left
;
469 *height
= r
.bottom
- r
.top
;
472 GetQDGlobalsScreenBits( &screenBits
);
478 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
480 if (height
!= NULL
) {
481 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
486 GetThemeMenuBarHeight( &mheight
) ;
488 mheight
= LMGetMBarHeight() ;
490 if (height
!= NULL
) {
498 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
500 return wxGenericFindWindowAtPoint(pt
);
507 wxString
wxGetOsDescription()
509 #ifdef WXWIN_OS_DESCRIPTION
510 // use configure generated description if available
511 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
513 return wxT("MacOS") ; //TODO:define further
518 wxChar
*wxGetUserHome (const wxString
& user
)
524 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
534 int pos
= p
.Find(':') ;
535 if ( pos
!= wxNOT_FOUND
) {
544 wxMacStringToPascal( p
, volumeName
) ;
545 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
546 if ( err
== noErr
) {
548 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
551 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
555 return err
== noErr
;
557 #endif // !__DARWIN__
559 //---------------------------------------------------------------------------
560 // wxMac Specific utility functions
561 //---------------------------------------------------------------------------
563 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
565 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
566 int len
= strlen(buf
) ;
571 memcpy( (char*) &to
[1] , buf
, len
) ;
574 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
576 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
580 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
582 TextEncodingBase enc
= 0 ;
583 if ( encoding
== wxFONTENCODING_DEFAULT
)
586 encoding
= wxFont::GetDefaultEncoding() ;
588 encoding
= wxLocale::GetSystemEncoding() ;
594 case wxFONTENCODING_ISO8859_1
:
595 enc
= kTextEncodingISOLatin1
;
597 case wxFONTENCODING_ISO8859_2
:
598 enc
= kTextEncodingISOLatin2
;
600 case wxFONTENCODING_ISO8859_3
:
601 enc
= kTextEncodingISOLatin3
;
603 case wxFONTENCODING_ISO8859_4
:
604 enc
= kTextEncodingISOLatin4
;
606 case wxFONTENCODING_ISO8859_5
:
607 enc
= kTextEncodingISOLatinCyrillic
;
609 case wxFONTENCODING_ISO8859_6
:
610 enc
= kTextEncodingISOLatinArabic
;
612 case wxFONTENCODING_ISO8859_7
:
613 enc
= kTextEncodingISOLatinGreek
;
615 case wxFONTENCODING_ISO8859_8
:
616 enc
= kTextEncodingISOLatinHebrew
;
618 case wxFONTENCODING_ISO8859_9
:
619 enc
= kTextEncodingISOLatin5
;
621 case wxFONTENCODING_ISO8859_10
:
622 enc
= kTextEncodingISOLatin6
;
624 case wxFONTENCODING_ISO8859_13
:
625 enc
= kTextEncodingISOLatin7
;
627 case wxFONTENCODING_ISO8859_14
:
628 enc
= kTextEncodingISOLatin8
;
630 case wxFONTENCODING_ISO8859_15
:
631 enc
= kTextEncodingISOLatin9
;
634 case wxFONTENCODING_KOI8
:
635 enc
= kTextEncodingKOI8_R
;
637 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
638 enc
= kTextEncodingDOSRussian
;
641 case wxFONTENCODING_BULGARIAN :
645 case wxFONTENCODING_CP437
:
646 enc
=kTextEncodingDOSLatinUS
;
648 case wxFONTENCODING_CP850
:
649 enc
= kTextEncodingDOSLatin1
;
651 case wxFONTENCODING_CP852
:
652 enc
= kTextEncodingDOSLatin2
;
654 case wxFONTENCODING_CP855
:
655 enc
= kTextEncodingDOSCyrillic
;
657 case wxFONTENCODING_CP866
:
658 enc
=kTextEncodingDOSRussian
;
660 case wxFONTENCODING_CP874
:
661 enc
= kTextEncodingDOSThai
;
663 case wxFONTENCODING_CP932
:
664 enc
= kTextEncodingDOSJapanese
;
666 case wxFONTENCODING_CP936
:
667 enc
=kTextEncodingDOSChineseSimplif
;
669 case wxFONTENCODING_CP949
:
670 enc
= kTextEncodingDOSKorean
;
672 case wxFONTENCODING_CP950
:
673 enc
= kTextEncodingDOSChineseTrad
;
676 case wxFONTENCODING_CP1250
:
677 enc
= kTextEncodingWindowsLatin2
;
679 case wxFONTENCODING_CP1251
:
680 enc
=kTextEncodingWindowsCyrillic
;
682 case wxFONTENCODING_CP1252
:
683 enc
=kTextEncodingWindowsLatin1
;
685 case wxFONTENCODING_CP1253
:
686 enc
= kTextEncodingWindowsGreek
;
688 case wxFONTENCODING_CP1254
:
689 enc
= kTextEncodingWindowsLatin5
;
691 case wxFONTENCODING_CP1255
:
692 enc
=kTextEncodingWindowsHebrew
;
694 case wxFONTENCODING_CP1256
:
695 enc
=kTextEncodingWindowsArabic
;
697 case wxFONTENCODING_CP1257
:
698 enc
= kTextEncodingWindowsBalticRim
;
701 case wxFONTENCODING_UTF7
:
702 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
704 case wxFONTENCODING_UTF8
:
705 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
707 case wxFONTENCODING_EUC_JP
:
708 enc
= kTextEncodingEUC_JP
;
710 case wxFONTENCODING_UTF16BE
:
711 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
713 case wxFONTENCODING_UTF16LE
:
714 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
716 case wxFONTENCODING_UTF32BE
:
717 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
719 case wxFONTENCODING_UTF32LE
:
720 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
723 case wxFONTENCODING_MACROMAN
:
724 enc
= kTextEncodingMacRoman
;
726 case wxFONTENCODING_MACJAPANESE
:
727 enc
= kTextEncodingMacJapanese
;
729 case wxFONTENCODING_MACCHINESETRAD
:
730 enc
= kTextEncodingMacChineseTrad
;
732 case wxFONTENCODING_MACKOREAN
:
733 enc
= kTextEncodingMacKorean
;
735 case wxFONTENCODING_MACARABIC
:
736 enc
= kTextEncodingMacArabic
;
738 case wxFONTENCODING_MACHEBREW
:
739 enc
= kTextEncodingMacHebrew
;
741 case wxFONTENCODING_MACGREEK
:
742 enc
= kTextEncodingMacGreek
;
744 case wxFONTENCODING_MACCYRILLIC
:
745 enc
= kTextEncodingMacCyrillic
;
747 case wxFONTENCODING_MACDEVANAGARI
:
748 enc
= kTextEncodingMacDevanagari
;
750 case wxFONTENCODING_MACGURMUKHI
:
751 enc
= kTextEncodingMacGurmukhi
;
753 case wxFONTENCODING_MACGUJARATI
:
754 enc
= kTextEncodingMacGujarati
;
756 case wxFONTENCODING_MACORIYA
:
757 enc
= kTextEncodingMacOriya
;
759 case wxFONTENCODING_MACBENGALI
:
760 enc
= kTextEncodingMacBengali
;
762 case wxFONTENCODING_MACTAMIL
:
763 enc
= kTextEncodingMacTamil
;
765 case wxFONTENCODING_MACTELUGU
:
766 enc
= kTextEncodingMacTelugu
;
768 case wxFONTENCODING_MACKANNADA
:
769 enc
= kTextEncodingMacKannada
;
771 case wxFONTENCODING_MACMALAJALAM
:
772 enc
= kTextEncodingMacMalayalam
;
774 case wxFONTENCODING_MACSINHALESE
:
775 enc
= kTextEncodingMacSinhalese
;
777 case wxFONTENCODING_MACBURMESE
:
778 enc
= kTextEncodingMacBurmese
;
780 case wxFONTENCODING_MACKHMER
:
781 enc
= kTextEncodingMacKhmer
;
783 case wxFONTENCODING_MACTHAI
:
784 enc
= kTextEncodingMacThai
;
786 case wxFONTENCODING_MACLAOTIAN
:
787 enc
= kTextEncodingMacLaotian
;
789 case wxFONTENCODING_MACGEORGIAN
:
790 enc
= kTextEncodingMacGeorgian
;
792 case wxFONTENCODING_MACARMENIAN
:
793 enc
= kTextEncodingMacArmenian
;
795 case wxFONTENCODING_MACCHINESESIMP
:
796 enc
= kTextEncodingMacChineseSimp
;
798 case wxFONTENCODING_MACTIBETAN
:
799 enc
= kTextEncodingMacTibetan
;
801 case wxFONTENCODING_MACMONGOLIAN
:
802 enc
= kTextEncodingMacMongolian
;
804 case wxFONTENCODING_MACETHIOPIC
:
805 enc
= kTextEncodingMacEthiopic
;
807 case wxFONTENCODING_MACCENTRALEUR
:
808 enc
= kTextEncodingMacCentralEurRoman
;
810 case wxFONTENCODING_MACVIATNAMESE
:
811 enc
= kTextEncodingMacVietnamese
;
813 case wxFONTENCODING_MACARABICEXT
:
814 enc
= kTextEncodingMacExtArabic
;
816 case wxFONTENCODING_MACSYMBOL
:
817 enc
= kTextEncodingMacSymbol
;
819 case wxFONTENCODING_MACDINGBATS
:
820 enc
= kTextEncodingMacDingbats
;
822 case wxFONTENCODING_MACTURKISH
:
823 enc
= kTextEncodingMacTurkish
;
825 case wxFONTENCODING_MACCROATIAN
:
826 enc
= kTextEncodingMacCroatian
;
828 case wxFONTENCODING_MACICELANDIC
:
829 enc
= kTextEncodingMacIcelandic
;
831 case wxFONTENCODING_MACROMANIAN
:
832 enc
= kTextEncodingMacRomanian
;
834 case wxFONTENCODING_MACCELTIC
:
835 enc
= kTextEncodingMacCeltic
;
837 case wxFONTENCODING_MACGAELIC
:
838 enc
= kTextEncodingMacGaelic
;
840 case wxFONTENCODING_MACKEYBOARD
:
841 enc
= kTextEncodingMacKeyboardGlyphs
;
850 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
852 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
856 case kTextEncodingISOLatin1
:
857 enc
= wxFONTENCODING_ISO8859_1
;
859 case kTextEncodingISOLatin2
:
860 enc
= wxFONTENCODING_ISO8859_2
;
862 case kTextEncodingISOLatin3
:
863 enc
= wxFONTENCODING_ISO8859_3
;
865 case kTextEncodingISOLatin4
:
866 enc
= wxFONTENCODING_ISO8859_4
;
868 case kTextEncodingISOLatinCyrillic
:
869 enc
= wxFONTENCODING_ISO8859_5
;
871 case kTextEncodingISOLatinArabic
:
872 enc
= wxFONTENCODING_ISO8859_6
;
874 case kTextEncodingISOLatinGreek
:
875 enc
= wxFONTENCODING_ISO8859_7
;
877 case kTextEncodingISOLatinHebrew
:
878 enc
= wxFONTENCODING_ISO8859_8
;
880 case kTextEncodingISOLatin5
:
881 enc
= wxFONTENCODING_ISO8859_9
;
883 case kTextEncodingISOLatin6
:
884 enc
= wxFONTENCODING_ISO8859_10
;
886 case kTextEncodingISOLatin7
:
887 enc
= wxFONTENCODING_ISO8859_13
;
889 case kTextEncodingISOLatin8
:
890 enc
= wxFONTENCODING_ISO8859_14
;
892 case kTextEncodingISOLatin9
:
893 enc
=wxFONTENCODING_ISO8859_15
;
896 case kTextEncodingKOI8_R
:
897 enc
= wxFONTENCODING_KOI8
;
901 enc = wxFONTENCODING_BULGARIAN;
904 case kTextEncodingDOSLatinUS
:
905 enc
= wxFONTENCODING_CP437
;
907 case kTextEncodingDOSLatin1
:
908 enc
= wxFONTENCODING_CP850
;
910 case kTextEncodingDOSLatin2
:
911 enc
=wxFONTENCODING_CP852
;
913 case kTextEncodingDOSCyrillic
:
914 enc
= wxFONTENCODING_CP855
;
916 case kTextEncodingDOSRussian
:
917 enc
= wxFONTENCODING_CP866
;
919 case kTextEncodingDOSThai
:
920 enc
=wxFONTENCODING_CP874
;
922 case kTextEncodingDOSJapanese
:
923 enc
= wxFONTENCODING_CP932
;
925 case kTextEncodingDOSChineseSimplif
:
926 enc
= wxFONTENCODING_CP936
;
928 case kTextEncodingDOSKorean
:
929 enc
= wxFONTENCODING_CP949
;
931 case kTextEncodingDOSChineseTrad
:
932 enc
= wxFONTENCODING_CP950
;
935 case kTextEncodingWindowsLatin2
:
936 enc
= wxFONTENCODING_CP1250
;
938 case kTextEncodingWindowsCyrillic
:
939 enc
= wxFONTENCODING_CP1251
;
941 case kTextEncodingWindowsLatin1
:
942 enc
= wxFONTENCODING_CP1252
;
944 case kTextEncodingWindowsGreek
:
945 enc
= wxFONTENCODING_CP1253
;
947 case kTextEncodingWindowsLatin5
:
948 enc
= wxFONTENCODING_CP1254
;
950 case kTextEncodingWindowsHebrew
:
951 enc
= wxFONTENCODING_CP1255
;
953 case kTextEncodingWindowsArabic
:
954 enc
= wxFONTENCODING_CP1256
;
956 case kTextEncodingWindowsBalticRim
:
957 enc
=wxFONTENCODING_CP1257
;
959 case kTextEncodingEUC_JP
:
960 enc
= wxFONTENCODING_EUC_JP
;
963 case wxFONTENCODING_UTF7 :
964 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
966 case wxFONTENCODING_UTF8 :
967 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
969 case wxFONTENCODING_UTF16BE :
970 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
972 case wxFONTENCODING_UTF16LE :
973 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
975 case wxFONTENCODING_UTF32BE :
976 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
978 case wxFONTENCODING_UTF32LE :
979 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
982 case kTextEncodingMacRoman
:
983 enc
= wxFONTENCODING_MACROMAN
;
985 case kTextEncodingMacJapanese
:
986 enc
= wxFONTENCODING_MACJAPANESE
;
988 case kTextEncodingMacChineseTrad
:
989 enc
= wxFONTENCODING_MACCHINESETRAD
;
991 case kTextEncodingMacKorean
:
992 enc
= wxFONTENCODING_MACKOREAN
;
994 case kTextEncodingMacArabic
:
995 enc
=wxFONTENCODING_MACARABIC
;
997 case kTextEncodingMacHebrew
:
998 enc
= wxFONTENCODING_MACHEBREW
;
1000 case kTextEncodingMacGreek
:
1001 enc
= wxFONTENCODING_MACGREEK
;
1003 case kTextEncodingMacCyrillic
:
1004 enc
= wxFONTENCODING_MACCYRILLIC
;
1006 case kTextEncodingMacDevanagari
:
1007 enc
= wxFONTENCODING_MACDEVANAGARI
;
1009 case kTextEncodingMacGurmukhi
:
1010 enc
= wxFONTENCODING_MACGURMUKHI
;
1012 case kTextEncodingMacGujarati
:
1013 enc
= wxFONTENCODING_MACGUJARATI
;
1015 case kTextEncodingMacOriya
:
1016 enc
=wxFONTENCODING_MACORIYA
;
1018 case kTextEncodingMacBengali
:
1019 enc
=wxFONTENCODING_MACBENGALI
;
1021 case kTextEncodingMacTamil
:
1022 enc
= wxFONTENCODING_MACTAMIL
;
1024 case kTextEncodingMacTelugu
:
1025 enc
= wxFONTENCODING_MACTELUGU
;
1027 case kTextEncodingMacKannada
:
1028 enc
= wxFONTENCODING_MACKANNADA
;
1030 case kTextEncodingMacMalayalam
:
1031 enc
= wxFONTENCODING_MACMALAJALAM
;
1033 case kTextEncodingMacSinhalese
:
1034 enc
= wxFONTENCODING_MACSINHALESE
;
1036 case kTextEncodingMacBurmese
:
1037 enc
= wxFONTENCODING_MACBURMESE
;
1039 case kTextEncodingMacKhmer
:
1040 enc
= wxFONTENCODING_MACKHMER
;
1042 case kTextEncodingMacThai
:
1043 enc
= wxFONTENCODING_MACTHAI
;
1045 case kTextEncodingMacLaotian
:
1046 enc
= wxFONTENCODING_MACLAOTIAN
;
1048 case kTextEncodingMacGeorgian
:
1049 enc
= wxFONTENCODING_MACGEORGIAN
;
1051 case kTextEncodingMacArmenian
:
1052 enc
= wxFONTENCODING_MACARMENIAN
;
1054 case kTextEncodingMacChineseSimp
:
1055 enc
= wxFONTENCODING_MACCHINESESIMP
;
1057 case kTextEncodingMacTibetan
:
1058 enc
= wxFONTENCODING_MACTIBETAN
;
1060 case kTextEncodingMacMongolian
:
1061 enc
= wxFONTENCODING_MACMONGOLIAN
;
1063 case kTextEncodingMacEthiopic
:
1064 enc
= wxFONTENCODING_MACETHIOPIC
;
1066 case kTextEncodingMacCentralEurRoman
:
1067 enc
= wxFONTENCODING_MACCENTRALEUR
;
1069 case kTextEncodingMacVietnamese
:
1070 enc
= wxFONTENCODING_MACVIATNAMESE
;
1072 case kTextEncodingMacExtArabic
:
1073 enc
= wxFONTENCODING_MACARABICEXT
;
1075 case kTextEncodingMacSymbol
:
1076 enc
= wxFONTENCODING_MACSYMBOL
;
1078 case kTextEncodingMacDingbats
:
1079 enc
= wxFONTENCODING_MACDINGBATS
;
1081 case kTextEncodingMacTurkish
:
1082 enc
= wxFONTENCODING_MACTURKISH
;
1084 case kTextEncodingMacCroatian
:
1085 enc
= wxFONTENCODING_MACCROATIAN
;
1087 case kTextEncodingMacIcelandic
:
1088 enc
= wxFONTENCODING_MACICELANDIC
;
1090 case kTextEncodingMacRomanian
:
1091 enc
= wxFONTENCODING_MACROMANIAN
;
1093 case kTextEncodingMacCeltic
:
1094 enc
= wxFONTENCODING_MACCELTIC
;
1096 case kTextEncodingMacGaelic
:
1097 enc
= wxFONTENCODING_MACGAELIC
;
1099 case kTextEncodingMacKeyboardGlyphs
:
1100 enc
= wxFONTENCODING_MACKEYBOARD
;
1106 #endif // wxUSE_BASE
1112 // CFStringRefs (Carbon only)
1117 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1118 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1123 wxMacConvertNewlines13To10( &str
) ;
1125 #if SIZEOF_WCHAR_T == 2
1126 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1127 (UniChar
*)str
.wc_str() , str
.Len() );
1129 wxMBConvUTF16BE converter
;
1130 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1131 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1132 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1133 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1134 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1137 #else // not wxUSE_UNICODE
1138 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1139 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1144 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1146 Size cflen
= CFStringGetLength( m_cfs
) ;
1148 wxChar
* buf
= NULL
;
1151 #if SIZEOF_WCHAR_T == 2
1152 buf
= new wxChar
[ cflen
+ 1 ] ;
1153 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1156 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1157 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1159 wxMBConvUTF16BE converter
;
1160 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1161 buf
= new wxChar
[ noChars
+ 1 ] ;
1162 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1167 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1168 '?' , false , NULL
, 0 , &cStrLen
) ;
1169 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1170 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1171 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1176 wxMacConvertNewlines10To13( buf
) ;
1177 wxString
result(buf
) ;
1182 #endif //TARGET_CARBON
1184 void wxMacConvertNewlines13To10( char * data
)
1187 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1194 void wxMacConvertNewlines10To13( char * data
)
1197 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1204 void wxMacConvertNewlines13To10( wxString
* data
)
1206 size_t len
= data
->Length() ;
1208 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1211 wxString
temp(*data
) ;
1212 wxStringBuffer
buf(*data
,len
) ;
1213 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1215 wxMacConvertNewlines13To10( buf
) ;
1218 void wxMacConvertNewlines10To13( wxString
* data
)
1220 size_t len
= data
->Length() ;
1222 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1225 wxString
temp(*data
) ;
1226 wxStringBuffer
buf(*data
,len
) ;
1227 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1228 wxMacConvertNewlines10To13( buf
) ;
1233 void wxMacConvertNewlines13To10( wxChar
* data
)
1235 wxChar
* buf
= data
;
1236 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1243 void wxMacConvertNewlines10To13( wxChar
* data
)
1245 wxChar
* buf
= data
;
1246 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1254 // ----------------------------------------------------------------------------
1255 // debugging support
1256 // ----------------------------------------------------------------------------
1258 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1260 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1262 #ifndef __MetroNubUtils__
1263 #include "MetroNubUtils.h"
1267 #include <Gestalt.h>
1270 #if TARGET_API_MAC_CARBON
1272 #include <CodeFragments.h>
1274 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1276 ProcPtr gCallUniversalProc_Proc
= NULL
;
1280 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1282 static long fRunOnce
= false;
1284 /* ---------------------------------------------------------------------------
1286 --------------------------------------------------------------------------- */
1288 Boolean
IsMetroNubInstalled()
1295 gMetroNubEntry
= NULL
;
1297 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1299 /* look for MetroNub's Gestalt selector */
1300 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1303 #if TARGET_API_MAC_CARBON
1304 if (gCallUniversalProc_Proc
== NULL
)
1306 CFragConnectionID connectionID
;
1309 ProcPtr symbolAddress
;
1311 CFragSymbolClass symbolClass
;
1313 symbolAddress
= NULL
;
1314 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1315 &connectionID
, &mainAddress
, errorString
);
1319 gCallUniversalProc_Proc
= NULL
;
1323 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1324 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1328 gCallUniversalProc_Proc
= NULL
;
1335 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1337 /* make sure the version of the API is compatible */
1338 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1339 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1340 gMetroNubEntry
= block
; /* success! */
1349 #if TARGET_API_MAC_CARBON
1350 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1352 return (gMetroNubEntry
!= NULL
);
1356 /* ---------------------------------------------------------------------------
1357 IsMWDebuggerRunning [v1 API]
1358 --------------------------------------------------------------------------- */
1360 Boolean
IsMWDebuggerRunning()
1362 if (IsMetroNubInstalled())
1363 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1368 /* ---------------------------------------------------------------------------
1369 AmIBeingMWDebugged [v1 API]
1370 --------------------------------------------------------------------------- */
1372 Boolean
AmIBeingMWDebugged()
1374 if (IsMetroNubInstalled())
1375 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1380 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1382 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1387 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1392 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)