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
)
460 GetQDGlobalsScreenBits( &screenBits
);
466 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
468 if (height
!= NULL
) {
469 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
474 GetThemeMenuBarHeight( &mheight
) ;
476 mheight
= LMGetMBarHeight() ;
478 if (height
!= NULL
) {
485 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
487 return wxGenericFindWindowAtPoint(pt
);
494 wxString
wxGetOsDescription()
496 #ifdef WXWIN_OS_DESCRIPTION
497 // use configure generated description if available
498 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
500 return wxT("MacOS") ; //TODO:define further
505 wxChar
*wxGetUserHome (const wxString
& user
)
511 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
521 int pos
= p
.Find(':') ;
522 if ( pos
!= wxNOT_FOUND
) {
531 wxMacStringToPascal( p
, volumeName
) ;
532 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
533 if ( err
== noErr
) {
535 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
538 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
542 return err
== noErr
;
544 #endif // !__DARWIN__
546 //---------------------------------------------------------------------------
547 // wxMac Specific utility functions
548 //---------------------------------------------------------------------------
550 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
552 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
553 int len
= strlen(buf
) ;
558 memcpy( (char*) &to
[1] , buf
, len
) ;
561 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
563 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
567 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
569 TextEncodingBase enc
= 0 ;
570 if ( encoding
== wxFONTENCODING_DEFAULT
)
573 encoding
= wxFont::GetDefaultEncoding() ;
575 encoding
= wxLocale::GetSystemEncoding() ;
581 case wxFONTENCODING_ISO8859_1
:
582 enc
= kTextEncodingISOLatin1
;
584 case wxFONTENCODING_ISO8859_2
:
585 enc
= kTextEncodingISOLatin2
;
587 case wxFONTENCODING_ISO8859_3
:
588 enc
= kTextEncodingISOLatin3
;
590 case wxFONTENCODING_ISO8859_4
:
591 enc
= kTextEncodingISOLatin4
;
593 case wxFONTENCODING_ISO8859_5
:
594 enc
= kTextEncodingISOLatinCyrillic
;
596 case wxFONTENCODING_ISO8859_6
:
597 enc
= kTextEncodingISOLatinArabic
;
599 case wxFONTENCODING_ISO8859_7
:
600 enc
= kTextEncodingISOLatinGreek
;
602 case wxFONTENCODING_ISO8859_8
:
603 enc
= kTextEncodingISOLatinHebrew
;
605 case wxFONTENCODING_ISO8859_9
:
606 enc
= kTextEncodingISOLatin5
;
608 case wxFONTENCODING_ISO8859_10
:
609 enc
= kTextEncodingISOLatin6
;
611 case wxFONTENCODING_ISO8859_13
:
612 enc
= kTextEncodingISOLatin7
;
614 case wxFONTENCODING_ISO8859_14
:
615 enc
= kTextEncodingISOLatin8
;
617 case wxFONTENCODING_ISO8859_15
:
618 enc
= kTextEncodingISOLatin9
;
621 case wxFONTENCODING_KOI8
:
622 enc
= kTextEncodingKOI8_R
;
624 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
625 enc
= kTextEncodingDOSRussian
;
628 case wxFONTENCODING_BULGARIAN :
632 case wxFONTENCODING_CP437
:
633 enc
=kTextEncodingDOSLatinUS
;
635 case wxFONTENCODING_CP850
:
636 enc
= kTextEncodingDOSLatin1
;
638 case wxFONTENCODING_CP852
:
639 enc
= kTextEncodingDOSLatin2
;
641 case wxFONTENCODING_CP855
:
642 enc
= kTextEncodingDOSCyrillic
;
644 case wxFONTENCODING_CP866
:
645 enc
=kTextEncodingDOSRussian
;
647 case wxFONTENCODING_CP874
:
648 enc
= kTextEncodingDOSThai
;
650 case wxFONTENCODING_CP932
:
651 enc
= kTextEncodingDOSJapanese
;
653 case wxFONTENCODING_CP936
:
654 enc
=kTextEncodingDOSChineseSimplif
;
656 case wxFONTENCODING_CP949
:
657 enc
= kTextEncodingDOSKorean
;
659 case wxFONTENCODING_CP950
:
660 enc
= kTextEncodingDOSChineseTrad
;
663 case wxFONTENCODING_CP1250
:
664 enc
= kTextEncodingWindowsLatin2
;
666 case wxFONTENCODING_CP1251
:
667 enc
=kTextEncodingWindowsCyrillic
;
669 case wxFONTENCODING_CP1252
:
670 enc
=kTextEncodingWindowsLatin1
;
672 case wxFONTENCODING_CP1253
:
673 enc
= kTextEncodingWindowsGreek
;
675 case wxFONTENCODING_CP1254
:
676 enc
= kTextEncodingWindowsLatin5
;
678 case wxFONTENCODING_CP1255
:
679 enc
=kTextEncodingWindowsHebrew
;
681 case wxFONTENCODING_CP1256
:
682 enc
=kTextEncodingWindowsArabic
;
684 case wxFONTENCODING_CP1257
:
685 enc
= kTextEncodingWindowsBalticRim
;
688 case wxFONTENCODING_UTF7
:
689 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
691 case wxFONTENCODING_UTF8
:
692 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
694 case wxFONTENCODING_EUC_JP
:
695 enc
= kTextEncodingEUC_JP
;
697 case wxFONTENCODING_UTF16BE
:
698 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
700 case wxFONTENCODING_UTF16LE
:
701 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
703 case wxFONTENCODING_UTF32BE
:
704 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
706 case wxFONTENCODING_UTF32LE
:
707 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
710 case wxFONTENCODING_MACROMAN
:
711 enc
= kTextEncodingMacRoman
;
713 case wxFONTENCODING_MACJAPANESE
:
714 enc
= kTextEncodingMacJapanese
;
716 case wxFONTENCODING_MACCHINESETRAD
:
717 enc
= kTextEncodingMacChineseTrad
;
719 case wxFONTENCODING_MACKOREAN
:
720 enc
= kTextEncodingMacKorean
;
722 case wxFONTENCODING_MACARABIC
:
723 enc
= kTextEncodingMacArabic
;
725 case wxFONTENCODING_MACHEBREW
:
726 enc
= kTextEncodingMacHebrew
;
728 case wxFONTENCODING_MACGREEK
:
729 enc
= kTextEncodingMacGreek
;
731 case wxFONTENCODING_MACCYRILLIC
:
732 enc
= kTextEncodingMacCyrillic
;
734 case wxFONTENCODING_MACDEVANAGARI
:
735 enc
= kTextEncodingMacDevanagari
;
737 case wxFONTENCODING_MACGURMUKHI
:
738 enc
= kTextEncodingMacGurmukhi
;
740 case wxFONTENCODING_MACGUJARATI
:
741 enc
= kTextEncodingMacGujarati
;
743 case wxFONTENCODING_MACORIYA
:
744 enc
= kTextEncodingMacOriya
;
746 case wxFONTENCODING_MACBENGALI
:
747 enc
= kTextEncodingMacBengali
;
749 case wxFONTENCODING_MACTAMIL
:
750 enc
= kTextEncodingMacTamil
;
752 case wxFONTENCODING_MACTELUGU
:
753 enc
= kTextEncodingMacTelugu
;
755 case wxFONTENCODING_MACKANNADA
:
756 enc
= kTextEncodingMacKannada
;
758 case wxFONTENCODING_MACMALAJALAM
:
759 enc
= kTextEncodingMacMalayalam
;
761 case wxFONTENCODING_MACSINHALESE
:
762 enc
= kTextEncodingMacSinhalese
;
764 case wxFONTENCODING_MACBURMESE
:
765 enc
= kTextEncodingMacBurmese
;
767 case wxFONTENCODING_MACKHMER
:
768 enc
= kTextEncodingMacKhmer
;
770 case wxFONTENCODING_MACTHAI
:
771 enc
= kTextEncodingMacThai
;
773 case wxFONTENCODING_MACLAOTIAN
:
774 enc
= kTextEncodingMacLaotian
;
776 case wxFONTENCODING_MACGEORGIAN
:
777 enc
= kTextEncodingMacGeorgian
;
779 case wxFONTENCODING_MACARMENIAN
:
780 enc
= kTextEncodingMacArmenian
;
782 case wxFONTENCODING_MACCHINESESIMP
:
783 enc
= kTextEncodingMacChineseSimp
;
785 case wxFONTENCODING_MACTIBETAN
:
786 enc
= kTextEncodingMacTibetan
;
788 case wxFONTENCODING_MACMONGOLIAN
:
789 enc
= kTextEncodingMacMongolian
;
791 case wxFONTENCODING_MACETHIOPIC
:
792 enc
= kTextEncodingMacEthiopic
;
794 case wxFONTENCODING_MACCENTRALEUR
:
795 enc
= kTextEncodingMacCentralEurRoman
;
797 case wxFONTENCODING_MACVIATNAMESE
:
798 enc
= kTextEncodingMacVietnamese
;
800 case wxFONTENCODING_MACARABICEXT
:
801 enc
= kTextEncodingMacExtArabic
;
803 case wxFONTENCODING_MACSYMBOL
:
804 enc
= kTextEncodingMacSymbol
;
806 case wxFONTENCODING_MACDINGBATS
:
807 enc
= kTextEncodingMacDingbats
;
809 case wxFONTENCODING_MACTURKISH
:
810 enc
= kTextEncodingMacTurkish
;
812 case wxFONTENCODING_MACCROATIAN
:
813 enc
= kTextEncodingMacCroatian
;
815 case wxFONTENCODING_MACICELANDIC
:
816 enc
= kTextEncodingMacIcelandic
;
818 case wxFONTENCODING_MACROMANIAN
:
819 enc
= kTextEncodingMacRomanian
;
821 case wxFONTENCODING_MACCELTIC
:
822 enc
= kTextEncodingMacCeltic
;
824 case wxFONTENCODING_MACGAELIC
:
825 enc
= kTextEncodingMacGaelic
;
827 case wxFONTENCODING_MACKEYBOARD
:
828 enc
= kTextEncodingMacKeyboardGlyphs
;
837 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
839 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
843 case kTextEncodingISOLatin1
:
844 enc
= wxFONTENCODING_ISO8859_1
;
846 case kTextEncodingISOLatin2
:
847 enc
= wxFONTENCODING_ISO8859_2
;
849 case kTextEncodingISOLatin3
:
850 enc
= wxFONTENCODING_ISO8859_3
;
852 case kTextEncodingISOLatin4
:
853 enc
= wxFONTENCODING_ISO8859_4
;
855 case kTextEncodingISOLatinCyrillic
:
856 enc
= wxFONTENCODING_ISO8859_5
;
858 case kTextEncodingISOLatinArabic
:
859 enc
= wxFONTENCODING_ISO8859_6
;
861 case kTextEncodingISOLatinGreek
:
862 enc
= wxFONTENCODING_ISO8859_7
;
864 case kTextEncodingISOLatinHebrew
:
865 enc
= wxFONTENCODING_ISO8859_8
;
867 case kTextEncodingISOLatin5
:
868 enc
= wxFONTENCODING_ISO8859_9
;
870 case kTextEncodingISOLatin6
:
871 enc
= wxFONTENCODING_ISO8859_10
;
873 case kTextEncodingISOLatin7
:
874 enc
= wxFONTENCODING_ISO8859_13
;
876 case kTextEncodingISOLatin8
:
877 enc
= wxFONTENCODING_ISO8859_14
;
879 case kTextEncodingISOLatin9
:
880 enc
=wxFONTENCODING_ISO8859_15
;
883 case kTextEncodingKOI8_R
:
884 enc
= wxFONTENCODING_KOI8
;
888 enc = wxFONTENCODING_BULGARIAN;
891 case kTextEncodingDOSLatinUS
:
892 enc
= wxFONTENCODING_CP437
;
894 case kTextEncodingDOSLatin1
:
895 enc
= wxFONTENCODING_CP850
;
897 case kTextEncodingDOSLatin2
:
898 enc
=wxFONTENCODING_CP852
;
900 case kTextEncodingDOSCyrillic
:
901 enc
= wxFONTENCODING_CP855
;
903 case kTextEncodingDOSRussian
:
904 enc
= wxFONTENCODING_CP866
;
906 case kTextEncodingDOSThai
:
907 enc
=wxFONTENCODING_CP874
;
909 case kTextEncodingDOSJapanese
:
910 enc
= wxFONTENCODING_CP932
;
912 case kTextEncodingDOSChineseSimplif
:
913 enc
= wxFONTENCODING_CP936
;
915 case kTextEncodingDOSKorean
:
916 enc
= wxFONTENCODING_CP949
;
918 case kTextEncodingDOSChineseTrad
:
919 enc
= wxFONTENCODING_CP950
;
922 case kTextEncodingWindowsLatin2
:
923 enc
= wxFONTENCODING_CP1250
;
925 case kTextEncodingWindowsCyrillic
:
926 enc
= wxFONTENCODING_CP1251
;
928 case kTextEncodingWindowsLatin1
:
929 enc
= wxFONTENCODING_CP1252
;
931 case kTextEncodingWindowsGreek
:
932 enc
= wxFONTENCODING_CP1253
;
934 case kTextEncodingWindowsLatin5
:
935 enc
= wxFONTENCODING_CP1254
;
937 case kTextEncodingWindowsHebrew
:
938 enc
= wxFONTENCODING_CP1255
;
940 case kTextEncodingWindowsArabic
:
941 enc
= wxFONTENCODING_CP1256
;
943 case kTextEncodingWindowsBalticRim
:
944 enc
=wxFONTENCODING_CP1257
;
946 case kTextEncodingEUC_JP
:
947 enc
= wxFONTENCODING_EUC_JP
;
950 case wxFONTENCODING_UTF7 :
951 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
953 case wxFONTENCODING_UTF8 :
954 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
956 case wxFONTENCODING_UTF16BE :
957 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
959 case wxFONTENCODING_UTF16LE :
960 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
962 case wxFONTENCODING_UTF32BE :
963 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
965 case wxFONTENCODING_UTF32LE :
966 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
969 case kTextEncodingMacRoman
:
970 enc
= wxFONTENCODING_MACROMAN
;
972 case kTextEncodingMacJapanese
:
973 enc
= wxFONTENCODING_MACJAPANESE
;
975 case kTextEncodingMacChineseTrad
:
976 enc
= wxFONTENCODING_MACCHINESETRAD
;
978 case kTextEncodingMacKorean
:
979 enc
= wxFONTENCODING_MACKOREAN
;
981 case kTextEncodingMacArabic
:
982 enc
=wxFONTENCODING_MACARABIC
;
984 case kTextEncodingMacHebrew
:
985 enc
= wxFONTENCODING_MACHEBREW
;
987 case kTextEncodingMacGreek
:
988 enc
= wxFONTENCODING_MACGREEK
;
990 case kTextEncodingMacCyrillic
:
991 enc
= wxFONTENCODING_MACCYRILLIC
;
993 case kTextEncodingMacDevanagari
:
994 enc
= wxFONTENCODING_MACDEVANAGARI
;
996 case kTextEncodingMacGurmukhi
:
997 enc
= wxFONTENCODING_MACGURMUKHI
;
999 case kTextEncodingMacGujarati
:
1000 enc
= wxFONTENCODING_MACGUJARATI
;
1002 case kTextEncodingMacOriya
:
1003 enc
=wxFONTENCODING_MACORIYA
;
1005 case kTextEncodingMacBengali
:
1006 enc
=wxFONTENCODING_MACBENGALI
;
1008 case kTextEncodingMacTamil
:
1009 enc
= wxFONTENCODING_MACTAMIL
;
1011 case kTextEncodingMacTelugu
:
1012 enc
= wxFONTENCODING_MACTELUGU
;
1014 case kTextEncodingMacKannada
:
1015 enc
= wxFONTENCODING_MACKANNADA
;
1017 case kTextEncodingMacMalayalam
:
1018 enc
= wxFONTENCODING_MACMALAJALAM
;
1020 case kTextEncodingMacSinhalese
:
1021 enc
= wxFONTENCODING_MACSINHALESE
;
1023 case kTextEncodingMacBurmese
:
1024 enc
= wxFONTENCODING_MACBURMESE
;
1026 case kTextEncodingMacKhmer
:
1027 enc
= wxFONTENCODING_MACKHMER
;
1029 case kTextEncodingMacThai
:
1030 enc
= wxFONTENCODING_MACTHAI
;
1032 case kTextEncodingMacLaotian
:
1033 enc
= wxFONTENCODING_MACLAOTIAN
;
1035 case kTextEncodingMacGeorgian
:
1036 enc
= wxFONTENCODING_MACGEORGIAN
;
1038 case kTextEncodingMacArmenian
:
1039 enc
= wxFONTENCODING_MACARMENIAN
;
1041 case kTextEncodingMacChineseSimp
:
1042 enc
= wxFONTENCODING_MACCHINESESIMP
;
1044 case kTextEncodingMacTibetan
:
1045 enc
= wxFONTENCODING_MACTIBETAN
;
1047 case kTextEncodingMacMongolian
:
1048 enc
= wxFONTENCODING_MACMONGOLIAN
;
1050 case kTextEncodingMacEthiopic
:
1051 enc
= wxFONTENCODING_MACETHIOPIC
;
1053 case kTextEncodingMacCentralEurRoman
:
1054 enc
= wxFONTENCODING_MACCENTRALEUR
;
1056 case kTextEncodingMacVietnamese
:
1057 enc
= wxFONTENCODING_MACVIATNAMESE
;
1059 case kTextEncodingMacExtArabic
:
1060 enc
= wxFONTENCODING_MACARABICEXT
;
1062 case kTextEncodingMacSymbol
:
1063 enc
= wxFONTENCODING_MACSYMBOL
;
1065 case kTextEncodingMacDingbats
:
1066 enc
= wxFONTENCODING_MACDINGBATS
;
1068 case kTextEncodingMacTurkish
:
1069 enc
= wxFONTENCODING_MACTURKISH
;
1071 case kTextEncodingMacCroatian
:
1072 enc
= wxFONTENCODING_MACCROATIAN
;
1074 case kTextEncodingMacIcelandic
:
1075 enc
= wxFONTENCODING_MACICELANDIC
;
1077 case kTextEncodingMacRomanian
:
1078 enc
= wxFONTENCODING_MACROMANIAN
;
1080 case kTextEncodingMacCeltic
:
1081 enc
= wxFONTENCODING_MACCELTIC
;
1083 case kTextEncodingMacGaelic
:
1084 enc
= wxFONTENCODING_MACGAELIC
;
1086 case kTextEncodingMacKeyboardGlyphs
:
1087 enc
= wxFONTENCODING_MACKEYBOARD
;
1093 #endif // wxUSE_BASE
1099 // CFStringRefs (Carbon only)
1104 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1105 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1110 wxMacConvertNewlines13To10( &str
) ;
1112 #if SIZEOF_WCHAR_T == 2
1113 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1114 (UniChar
*)str
.wc_str() , str
.Len() );
1116 wxMBConvUTF16BE converter
;
1117 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1118 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1119 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1120 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1121 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1124 #else // not wxUSE_UNICODE
1125 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1126 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1131 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1133 Size cflen
= CFStringGetLength( m_cfs
) ;
1135 wxChar
* buf
= NULL
;
1138 #if SIZEOF_WCHAR_T == 2
1139 buf
= new wxChar
[ cflen
+ 1 ] ;
1140 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1143 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1144 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1146 wxMBConvUTF16BE converter
;
1147 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1148 buf
= new wxChar
[ noChars
+ 1 ] ;
1149 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1154 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1155 '?' , false , NULL
, 0 , &cStrLen
) ;
1156 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1157 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1158 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1163 wxMacConvertNewlines10To13( buf
) ;
1164 wxString
result(buf
) ;
1169 #endif //TARGET_CARBON
1171 void wxMacConvertNewlines13To10( char * data
)
1174 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1181 void wxMacConvertNewlines10To13( char * data
)
1184 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1191 void wxMacConvertNewlines13To10( wxString
* data
)
1193 size_t len
= data
->Length() ;
1195 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1198 wxString
temp(*data
) ;
1199 wxStringBuffer
buf(*data
,len
) ;
1200 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1202 wxMacConvertNewlines13To10( buf
) ;
1205 void wxMacConvertNewlines10To13( wxString
* data
)
1207 size_t len
= data
->Length() ;
1209 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1212 wxString
temp(*data
) ;
1213 wxStringBuffer
buf(*data
,len
) ;
1214 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1215 wxMacConvertNewlines10To13( buf
) ;
1220 void wxMacConvertNewlines13To10( wxChar
* data
)
1222 wxChar
* buf
= data
;
1223 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1230 void wxMacConvertNewlines10To13( wxChar
* data
)
1232 wxChar
* buf
= data
;
1233 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1241 // ----------------------------------------------------------------------------
1242 // debugging support
1243 // ----------------------------------------------------------------------------
1245 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1247 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1249 #ifndef __MetroNubUtils__
1250 #include "MetroNubUtils.h"
1254 #include <Gestalt.h>
1257 #if TARGET_API_MAC_CARBON
1259 #include <CodeFragments.h>
1261 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1263 ProcPtr gCallUniversalProc_Proc
= NULL
;
1267 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1269 static long fRunOnce
= false;
1271 /* ---------------------------------------------------------------------------
1273 --------------------------------------------------------------------------- */
1275 Boolean
IsMetroNubInstalled()
1282 gMetroNubEntry
= NULL
;
1284 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1286 /* look for MetroNub's Gestalt selector */
1287 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1290 #if TARGET_API_MAC_CARBON
1291 if (gCallUniversalProc_Proc
== NULL
)
1293 CFragConnectionID connectionID
;
1296 ProcPtr symbolAddress
;
1298 CFragSymbolClass symbolClass
;
1300 symbolAddress
= NULL
;
1301 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1302 &connectionID
, &mainAddress
, errorString
);
1306 gCallUniversalProc_Proc
= NULL
;
1310 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1311 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1315 gCallUniversalProc_Proc
= NULL
;
1322 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1324 /* make sure the version of the API is compatible */
1325 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1326 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1327 gMetroNubEntry
= block
; /* success! */
1336 #if TARGET_API_MAC_CARBON
1337 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1339 return (gMetroNubEntry
!= NULL
);
1343 /* ---------------------------------------------------------------------------
1344 IsMWDebuggerRunning [v1 API]
1345 --------------------------------------------------------------------------- */
1347 Boolean
IsMWDebuggerRunning()
1349 if (IsMetroNubInstalled())
1350 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1355 /* ---------------------------------------------------------------------------
1356 AmIBeingMWDebugged [v1 API]
1357 --------------------------------------------------------------------------- */
1359 Boolean
AmIBeingMWDebugged()
1361 if (IsMetroNubInstalled())
1362 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1367 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1369 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1374 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1379 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)