1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/apptrait.h"
18 #include "wx/mac/uma.h"
32 # include "MoreFilesX.h"
34 # include "MoreFiles.h"
35 # include "MoreFilesExtras.h"
43 #include <ATSUnicode.h>
44 #include <TextCommon.h>
45 #include <TextEncodingConverter.h>
47 #include "wx/mac/private.h" // includes mac headers
49 #if defined(__MWERKS__) && wxUSE_UNICODE
53 // ---------------------------------------------------------------------------
54 // code used in both base and GUI compilation
55 // ---------------------------------------------------------------------------
57 // our OS version is the same in non GUI and GUI cases
58 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
62 // are there x-platform conventions ?
64 Gestalt(gestaltSystemVersion
, &theSystem
) ;
65 if (minorVsn
!= NULL
) {
66 *minorVsn
= (theSystem
& 0xFF ) ;
68 if (majorVsn
!= NULL
) {
69 *majorVsn
= (theSystem
>> 8 ) ;
81 // defined in unix/utilsunx.cpp for Mac OS X
83 // get full hostname (with domain name if possible)
84 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
86 return wxGetHostName(buf
, maxSize
);
89 // Get hostname only (without domain name)
90 bool wxGetHostName(wxChar
*buf
, int maxSize
)
92 // Gets Chooser name of user by examining a System resource.
94 const short kComputerNameID
= -16413;
96 short oldResFile
= CurResFile() ;
98 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
99 UseResFile(oldResFile
);
101 if (chooserName
&& *chooserName
)
103 HLock( (Handle
) chooserName
) ;
104 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
105 HUnlock( (Handle
) chooserName
) ;
106 ReleaseResource( (Handle
) chooserName
) ;
107 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
115 // Get user ID e.g. jacs
116 bool wxGetUserId(wxChar
*buf
, int maxSize
)
118 return wxGetUserName( buf
, maxSize
) ;
121 const wxChar
* wxGetHomeDir(wxString
*pstr
)
123 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
124 return pstr
->c_str() ;
127 // Get user name e.g. Stefan Csomor
128 bool wxGetUserName(wxChar
*buf
, int maxSize
)
130 // Gets Chooser name of user by examining a System resource.
132 const short kChooserNameID
= -16096;
134 short oldResFile
= CurResFile() ;
136 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
137 UseResFile(oldResFile
);
139 if (chooserName
&& *chooserName
)
141 HLock( (Handle
) chooserName
) ;
142 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
143 HUnlock( (Handle
) chooserName
) ;
144 ReleaseResource( (Handle
) chooserName
) ;
145 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
153 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
159 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
161 // TODO : under classic there is no environement support, under X yes
165 // set the env var name to the given value, return true on success
166 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
168 // TODO : under classic there is no environement support, under X yes
173 // Execute a program in an Interactive Shell
175 bool wxShell(const wxString
& command
)
181 // Shutdown or reboot the PC
182 bool wxShutdown(wxShutdownFlags wFlags
)
188 wxPowerType
wxGetPowerType()
191 return wxPOWER_UNKNOWN
;
194 wxBatteryState
wxGetBatteryState()
197 return wxBATTERY_UNKNOWN_STATE
;
200 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
201 wxMemorySize
wxGetFreeMemory()
203 return (wxMemorySize
)FreeMem() ;
206 void wxUsleep(unsigned long milliseconds
)
208 clock_t start
= clock() ;
212 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
215 void wxSleep(int nSecs
)
217 wxUsleep(1000*nSecs
);
220 // Consume all events until no more left
225 #endif // !__DARWIN__
233 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
235 static wxToolkitInfo info
;
236 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
237 info
.name
= _T("wxBase");
245 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
247 static wxToolkitInfo info
;
248 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
249 info
.shortName
= _T("mac");
250 info
.name
= _T("wxMac");
251 #ifdef __WXUNIVERSAL__
252 info
.shortName
<< _T("univ");
253 info
.name
<< _T("/wxUniversal");
258 // Reading and writing resources (eg WIN.INI, .Xdefaults)
260 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
266 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
269 buf
.Printf(wxT("%.4f"), value
);
271 return wxWriteResource(section
, entry
, buf
, file
);
274 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
277 buf
.Printf(wxT("%ld"), value
);
279 return wxWriteResource(section
, entry
, buf
, file
);
282 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
285 buf
.Printf(wxT("%d"), value
);
287 return wxWriteResource(section
, entry
, buf
, file
);
290 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
296 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
299 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
302 *value
= (float)strtod(s
, NULL
);
309 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
312 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
315 *value
= strtol(s
, NULL
, 10);
322 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
325 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
328 *value
= (int)strtol(s
, NULL
, 10);
334 #endif // wxUSE_RESOURCES
336 int gs_wxBusyCursorCount
= 0;
337 extern wxCursor gMacCurrentCursor
;
338 wxCursor gMacStoredActiveCursor
;
340 // Set the cursor to the busy cursor for all windows
341 void wxBeginBusyCursor(wxCursor
*cursor
)
343 if (gs_wxBusyCursorCount
++ == 0)
345 gMacStoredActiveCursor
= gMacCurrentCursor
;
346 cursor
->MacInstall() ;
348 //else: nothing to do, already set
351 // Restore cursor to normal
352 void wxEndBusyCursor()
354 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
355 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
357 if (--gs_wxBusyCursorCount
== 0)
359 gMacStoredActiveCursor
.MacInstall() ;
360 gMacStoredActiveCursor
= wxNullCursor
;
364 // true if we're between the above two calls
367 return (gs_wxBusyCursorCount
> 0);
374 wxString
wxMacFindFolder( short vol
,
376 Boolean createFolder
)
382 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
385 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
387 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
397 // Check whether this window wants to process messages, e.g. Stop button
398 // in long calculations.
399 bool wxCheckForInterrupt(wxWindow
*wnd
)
405 void wxGetMousePosition( int* x
, int* y
)
410 LocalToGlobal( &pt
) ;
415 // Return true if we have a colour display
416 bool wxColourDisplay()
421 // Returns depth of screen
425 SetRect(&globRect
, -32760, -32760, 32760, 32760);
426 GDHandle theMaxDevice
;
429 theMaxDevice
= GetMaxDevice(&globRect
);
430 if (theMaxDevice
!= nil
)
431 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
436 // Get size of display
437 void wxDisplaySize(int *width
, int *height
)
440 GetQDGlobalsScreenBits( &screenBits
);
443 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
445 if (height
!= NULL
) {
446 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
450 void wxDisplaySizeMM(int *width
, int *height
)
452 wxDisplaySize(width
, height
);
453 // on mac 72 is fixed (at least now ;-)
454 float cvPt2Mm
= 25.4 / 72;
457 *width
= int( *width
* cvPt2Mm
);
459 if (height
!= NULL
) {
460 *height
= int( *height
* cvPt2Mm
);
464 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
468 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
474 *width
= r
.right
- r
.left
;
476 *height
= r
.bottom
- r
.top
;
479 GetQDGlobalsScreenBits( &screenBits
);
485 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
487 if (height
!= NULL
) {
488 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
493 GetThemeMenuBarHeight( &mheight
) ;
495 mheight
= LMGetMBarHeight() ;
497 if (height
!= NULL
) {
505 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
507 return wxGenericFindWindowAtPoint(pt
);
514 wxString
wxGetOsDescription()
516 #ifdef WXWIN_OS_DESCRIPTION
517 // use configure generated description if available
518 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
520 return wxT("MacOS") ; //TODO:define further
525 wxChar
*wxGetUserHome (const wxString
& user
)
531 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
541 int pos
= p
.Find(':') ;
542 if ( pos
!= wxNOT_FOUND
) {
551 wxMacStringToPascal( p
, volumeName
) ;
552 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
553 if ( err
== noErr
) {
555 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
558 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
562 return err
== noErr
;
564 #endif // !__DARWIN__
566 //---------------------------------------------------------------------------
567 // wxMac Specific utility functions
568 //---------------------------------------------------------------------------
570 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
572 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
573 int len
= strlen(buf
) ;
578 memcpy( (char*) &to
[1] , buf
, len
) ;
581 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
583 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
587 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
589 TextEncodingBase enc
= 0 ;
590 if ( encoding
== wxFONTENCODING_DEFAULT
)
593 encoding
= wxFont::GetDefaultEncoding() ;
595 encoding
= wxLocale::GetSystemEncoding() ;
601 case wxFONTENCODING_ISO8859_1
:
602 enc
= kTextEncodingISOLatin1
;
604 case wxFONTENCODING_ISO8859_2
:
605 enc
= kTextEncodingISOLatin2
;
607 case wxFONTENCODING_ISO8859_3
:
608 enc
= kTextEncodingISOLatin3
;
610 case wxFONTENCODING_ISO8859_4
:
611 enc
= kTextEncodingISOLatin4
;
613 case wxFONTENCODING_ISO8859_5
:
614 enc
= kTextEncodingISOLatinCyrillic
;
616 case wxFONTENCODING_ISO8859_6
:
617 enc
= kTextEncodingISOLatinArabic
;
619 case wxFONTENCODING_ISO8859_7
:
620 enc
= kTextEncodingISOLatinGreek
;
622 case wxFONTENCODING_ISO8859_8
:
623 enc
= kTextEncodingISOLatinHebrew
;
625 case wxFONTENCODING_ISO8859_9
:
626 enc
= kTextEncodingISOLatin5
;
628 case wxFONTENCODING_ISO8859_10
:
629 enc
= kTextEncodingISOLatin6
;
631 case wxFONTENCODING_ISO8859_13
:
632 enc
= kTextEncodingISOLatin7
;
634 case wxFONTENCODING_ISO8859_14
:
635 enc
= kTextEncodingISOLatin8
;
637 case wxFONTENCODING_ISO8859_15
:
638 enc
= kTextEncodingISOLatin9
;
641 case wxFONTENCODING_KOI8
:
642 enc
= kTextEncodingKOI8_R
;
644 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
645 enc
= kTextEncodingDOSRussian
;
648 case wxFONTENCODING_BULGARIAN :
652 case wxFONTENCODING_CP437
:
653 enc
=kTextEncodingDOSLatinUS
;
655 case wxFONTENCODING_CP850
:
656 enc
= kTextEncodingDOSLatin1
;
658 case wxFONTENCODING_CP852
:
659 enc
= kTextEncodingDOSLatin2
;
661 case wxFONTENCODING_CP855
:
662 enc
= kTextEncodingDOSCyrillic
;
664 case wxFONTENCODING_CP866
:
665 enc
=kTextEncodingDOSRussian
;
667 case wxFONTENCODING_CP874
:
668 enc
= kTextEncodingDOSThai
;
670 case wxFONTENCODING_CP932
:
671 enc
= kTextEncodingDOSJapanese
;
673 case wxFONTENCODING_CP936
:
674 enc
=kTextEncodingDOSChineseSimplif
;
676 case wxFONTENCODING_CP949
:
677 enc
= kTextEncodingDOSKorean
;
679 case wxFONTENCODING_CP950
:
680 enc
= kTextEncodingDOSChineseTrad
;
683 case wxFONTENCODING_CP1250
:
684 enc
= kTextEncodingWindowsLatin2
;
686 case wxFONTENCODING_CP1251
:
687 enc
=kTextEncodingWindowsCyrillic
;
689 case wxFONTENCODING_CP1252
:
690 enc
=kTextEncodingWindowsLatin1
;
692 case wxFONTENCODING_CP1253
:
693 enc
= kTextEncodingWindowsGreek
;
695 case wxFONTENCODING_CP1254
:
696 enc
= kTextEncodingWindowsLatin5
;
698 case wxFONTENCODING_CP1255
:
699 enc
=kTextEncodingWindowsHebrew
;
701 case wxFONTENCODING_CP1256
:
702 enc
=kTextEncodingWindowsArabic
;
704 case wxFONTENCODING_CP1257
:
705 enc
= kTextEncodingWindowsBalticRim
;
708 case wxFONTENCODING_UTF7
:
709 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
711 case wxFONTENCODING_UTF8
:
712 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
714 case wxFONTENCODING_EUC_JP
:
715 enc
= kTextEncodingEUC_JP
;
717 case wxFONTENCODING_UTF16BE
:
718 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
720 case wxFONTENCODING_UTF16LE
:
721 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
723 case wxFONTENCODING_UTF32BE
:
724 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
726 case wxFONTENCODING_UTF32LE
:
727 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
730 case wxFONTENCODING_MACROMAN
:
731 enc
= kTextEncodingMacRoman
;
733 case wxFONTENCODING_MACJAPANESE
:
734 enc
= kTextEncodingMacJapanese
;
736 case wxFONTENCODING_MACCHINESETRAD
:
737 enc
= kTextEncodingMacChineseTrad
;
739 case wxFONTENCODING_MACKOREAN
:
740 enc
= kTextEncodingMacKorean
;
742 case wxFONTENCODING_MACARABIC
:
743 enc
= kTextEncodingMacArabic
;
745 case wxFONTENCODING_MACHEBREW
:
746 enc
= kTextEncodingMacHebrew
;
748 case wxFONTENCODING_MACGREEK
:
749 enc
= kTextEncodingMacGreek
;
751 case wxFONTENCODING_MACCYRILLIC
:
752 enc
= kTextEncodingMacCyrillic
;
754 case wxFONTENCODING_MACDEVANAGARI
:
755 enc
= kTextEncodingMacDevanagari
;
757 case wxFONTENCODING_MACGURMUKHI
:
758 enc
= kTextEncodingMacGurmukhi
;
760 case wxFONTENCODING_MACGUJARATI
:
761 enc
= kTextEncodingMacGujarati
;
763 case wxFONTENCODING_MACORIYA
:
764 enc
= kTextEncodingMacOriya
;
766 case wxFONTENCODING_MACBENGALI
:
767 enc
= kTextEncodingMacBengali
;
769 case wxFONTENCODING_MACTAMIL
:
770 enc
= kTextEncodingMacTamil
;
772 case wxFONTENCODING_MACTELUGU
:
773 enc
= kTextEncodingMacTelugu
;
775 case wxFONTENCODING_MACKANNADA
:
776 enc
= kTextEncodingMacKannada
;
778 case wxFONTENCODING_MACMALAJALAM
:
779 enc
= kTextEncodingMacMalayalam
;
781 case wxFONTENCODING_MACSINHALESE
:
782 enc
= kTextEncodingMacSinhalese
;
784 case wxFONTENCODING_MACBURMESE
:
785 enc
= kTextEncodingMacBurmese
;
787 case wxFONTENCODING_MACKHMER
:
788 enc
= kTextEncodingMacKhmer
;
790 case wxFONTENCODING_MACTHAI
:
791 enc
= kTextEncodingMacThai
;
793 case wxFONTENCODING_MACLAOTIAN
:
794 enc
= kTextEncodingMacLaotian
;
796 case wxFONTENCODING_MACGEORGIAN
:
797 enc
= kTextEncodingMacGeorgian
;
799 case wxFONTENCODING_MACARMENIAN
:
800 enc
= kTextEncodingMacArmenian
;
802 case wxFONTENCODING_MACCHINESESIMP
:
803 enc
= kTextEncodingMacChineseSimp
;
805 case wxFONTENCODING_MACTIBETAN
:
806 enc
= kTextEncodingMacTibetan
;
808 case wxFONTENCODING_MACMONGOLIAN
:
809 enc
= kTextEncodingMacMongolian
;
811 case wxFONTENCODING_MACETHIOPIC
:
812 enc
= kTextEncodingMacEthiopic
;
814 case wxFONTENCODING_MACCENTRALEUR
:
815 enc
= kTextEncodingMacCentralEurRoman
;
817 case wxFONTENCODING_MACVIATNAMESE
:
818 enc
= kTextEncodingMacVietnamese
;
820 case wxFONTENCODING_MACARABICEXT
:
821 enc
= kTextEncodingMacExtArabic
;
823 case wxFONTENCODING_MACSYMBOL
:
824 enc
= kTextEncodingMacSymbol
;
826 case wxFONTENCODING_MACDINGBATS
:
827 enc
= kTextEncodingMacDingbats
;
829 case wxFONTENCODING_MACTURKISH
:
830 enc
= kTextEncodingMacTurkish
;
832 case wxFONTENCODING_MACCROATIAN
:
833 enc
= kTextEncodingMacCroatian
;
835 case wxFONTENCODING_MACICELANDIC
:
836 enc
= kTextEncodingMacIcelandic
;
838 case wxFONTENCODING_MACROMANIAN
:
839 enc
= kTextEncodingMacRomanian
;
841 case wxFONTENCODING_MACCELTIC
:
842 enc
= kTextEncodingMacCeltic
;
844 case wxFONTENCODING_MACGAELIC
:
845 enc
= kTextEncodingMacGaelic
;
847 case wxFONTENCODING_MACKEYBOARD
:
848 enc
= kTextEncodingMacKeyboardGlyphs
;
857 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
859 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
863 case kTextEncodingISOLatin1
:
864 enc
= wxFONTENCODING_ISO8859_1
;
866 case kTextEncodingISOLatin2
:
867 enc
= wxFONTENCODING_ISO8859_2
;
869 case kTextEncodingISOLatin3
:
870 enc
= wxFONTENCODING_ISO8859_3
;
872 case kTextEncodingISOLatin4
:
873 enc
= wxFONTENCODING_ISO8859_4
;
875 case kTextEncodingISOLatinCyrillic
:
876 enc
= wxFONTENCODING_ISO8859_5
;
878 case kTextEncodingISOLatinArabic
:
879 enc
= wxFONTENCODING_ISO8859_6
;
881 case kTextEncodingISOLatinGreek
:
882 enc
= wxFONTENCODING_ISO8859_7
;
884 case kTextEncodingISOLatinHebrew
:
885 enc
= wxFONTENCODING_ISO8859_8
;
887 case kTextEncodingISOLatin5
:
888 enc
= wxFONTENCODING_ISO8859_9
;
890 case kTextEncodingISOLatin6
:
891 enc
= wxFONTENCODING_ISO8859_10
;
893 case kTextEncodingISOLatin7
:
894 enc
= wxFONTENCODING_ISO8859_13
;
896 case kTextEncodingISOLatin8
:
897 enc
= wxFONTENCODING_ISO8859_14
;
899 case kTextEncodingISOLatin9
:
900 enc
=wxFONTENCODING_ISO8859_15
;
903 case kTextEncodingKOI8_R
:
904 enc
= wxFONTENCODING_KOI8
;
908 enc = wxFONTENCODING_BULGARIAN;
911 case kTextEncodingDOSLatinUS
:
912 enc
= wxFONTENCODING_CP437
;
914 case kTextEncodingDOSLatin1
:
915 enc
= wxFONTENCODING_CP850
;
917 case kTextEncodingDOSLatin2
:
918 enc
=wxFONTENCODING_CP852
;
920 case kTextEncodingDOSCyrillic
:
921 enc
= wxFONTENCODING_CP855
;
923 case kTextEncodingDOSRussian
:
924 enc
= wxFONTENCODING_CP866
;
926 case kTextEncodingDOSThai
:
927 enc
=wxFONTENCODING_CP874
;
929 case kTextEncodingDOSJapanese
:
930 enc
= wxFONTENCODING_CP932
;
932 case kTextEncodingDOSChineseSimplif
:
933 enc
= wxFONTENCODING_CP936
;
935 case kTextEncodingDOSKorean
:
936 enc
= wxFONTENCODING_CP949
;
938 case kTextEncodingDOSChineseTrad
:
939 enc
= wxFONTENCODING_CP950
;
942 case kTextEncodingWindowsLatin2
:
943 enc
= wxFONTENCODING_CP1250
;
945 case kTextEncodingWindowsCyrillic
:
946 enc
= wxFONTENCODING_CP1251
;
948 case kTextEncodingWindowsLatin1
:
949 enc
= wxFONTENCODING_CP1252
;
951 case kTextEncodingWindowsGreek
:
952 enc
= wxFONTENCODING_CP1253
;
954 case kTextEncodingWindowsLatin5
:
955 enc
= wxFONTENCODING_CP1254
;
957 case kTextEncodingWindowsHebrew
:
958 enc
= wxFONTENCODING_CP1255
;
960 case kTextEncodingWindowsArabic
:
961 enc
= wxFONTENCODING_CP1256
;
963 case kTextEncodingWindowsBalticRim
:
964 enc
=wxFONTENCODING_CP1257
;
966 case kTextEncodingEUC_JP
:
967 enc
= wxFONTENCODING_EUC_JP
;
970 case wxFONTENCODING_UTF7 :
971 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
973 case wxFONTENCODING_UTF8 :
974 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
976 case wxFONTENCODING_UTF16BE :
977 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
979 case wxFONTENCODING_UTF16LE :
980 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
982 case wxFONTENCODING_UTF32BE :
983 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
985 case wxFONTENCODING_UTF32LE :
986 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
989 case kTextEncodingMacRoman
:
990 enc
= wxFONTENCODING_MACROMAN
;
992 case kTextEncodingMacJapanese
:
993 enc
= wxFONTENCODING_MACJAPANESE
;
995 case kTextEncodingMacChineseTrad
:
996 enc
= wxFONTENCODING_MACCHINESETRAD
;
998 case kTextEncodingMacKorean
:
999 enc
= wxFONTENCODING_MACKOREAN
;
1001 case kTextEncodingMacArabic
:
1002 enc
=wxFONTENCODING_MACARABIC
;
1004 case kTextEncodingMacHebrew
:
1005 enc
= wxFONTENCODING_MACHEBREW
;
1007 case kTextEncodingMacGreek
:
1008 enc
= wxFONTENCODING_MACGREEK
;
1010 case kTextEncodingMacCyrillic
:
1011 enc
= wxFONTENCODING_MACCYRILLIC
;
1013 case kTextEncodingMacDevanagari
:
1014 enc
= wxFONTENCODING_MACDEVANAGARI
;
1016 case kTextEncodingMacGurmukhi
:
1017 enc
= wxFONTENCODING_MACGURMUKHI
;
1019 case kTextEncodingMacGujarati
:
1020 enc
= wxFONTENCODING_MACGUJARATI
;
1022 case kTextEncodingMacOriya
:
1023 enc
=wxFONTENCODING_MACORIYA
;
1025 case kTextEncodingMacBengali
:
1026 enc
=wxFONTENCODING_MACBENGALI
;
1028 case kTextEncodingMacTamil
:
1029 enc
= wxFONTENCODING_MACTAMIL
;
1031 case kTextEncodingMacTelugu
:
1032 enc
= wxFONTENCODING_MACTELUGU
;
1034 case kTextEncodingMacKannada
:
1035 enc
= wxFONTENCODING_MACKANNADA
;
1037 case kTextEncodingMacMalayalam
:
1038 enc
= wxFONTENCODING_MACMALAJALAM
;
1040 case kTextEncodingMacSinhalese
:
1041 enc
= wxFONTENCODING_MACSINHALESE
;
1043 case kTextEncodingMacBurmese
:
1044 enc
= wxFONTENCODING_MACBURMESE
;
1046 case kTextEncodingMacKhmer
:
1047 enc
= wxFONTENCODING_MACKHMER
;
1049 case kTextEncodingMacThai
:
1050 enc
= wxFONTENCODING_MACTHAI
;
1052 case kTextEncodingMacLaotian
:
1053 enc
= wxFONTENCODING_MACLAOTIAN
;
1055 case kTextEncodingMacGeorgian
:
1056 enc
= wxFONTENCODING_MACGEORGIAN
;
1058 case kTextEncodingMacArmenian
:
1059 enc
= wxFONTENCODING_MACARMENIAN
;
1061 case kTextEncodingMacChineseSimp
:
1062 enc
= wxFONTENCODING_MACCHINESESIMP
;
1064 case kTextEncodingMacTibetan
:
1065 enc
= wxFONTENCODING_MACTIBETAN
;
1067 case kTextEncodingMacMongolian
:
1068 enc
= wxFONTENCODING_MACMONGOLIAN
;
1070 case kTextEncodingMacEthiopic
:
1071 enc
= wxFONTENCODING_MACETHIOPIC
;
1073 case kTextEncodingMacCentralEurRoman
:
1074 enc
= wxFONTENCODING_MACCENTRALEUR
;
1076 case kTextEncodingMacVietnamese
:
1077 enc
= wxFONTENCODING_MACVIATNAMESE
;
1079 case kTextEncodingMacExtArabic
:
1080 enc
= wxFONTENCODING_MACARABICEXT
;
1082 case kTextEncodingMacSymbol
:
1083 enc
= wxFONTENCODING_MACSYMBOL
;
1085 case kTextEncodingMacDingbats
:
1086 enc
= wxFONTENCODING_MACDINGBATS
;
1088 case kTextEncodingMacTurkish
:
1089 enc
= wxFONTENCODING_MACTURKISH
;
1091 case kTextEncodingMacCroatian
:
1092 enc
= wxFONTENCODING_MACCROATIAN
;
1094 case kTextEncodingMacIcelandic
:
1095 enc
= wxFONTENCODING_MACICELANDIC
;
1097 case kTextEncodingMacRomanian
:
1098 enc
= wxFONTENCODING_MACROMANIAN
;
1100 case kTextEncodingMacCeltic
:
1101 enc
= wxFONTENCODING_MACCELTIC
;
1103 case kTextEncodingMacGaelic
:
1104 enc
= wxFONTENCODING_MACGAELIC
;
1106 case kTextEncodingMacKeyboardGlyphs
:
1107 enc
= wxFONTENCODING_MACKEYBOARD
;
1113 #endif // wxUSE_BASE
1119 // CFStringRefs (Carbon only)
1124 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1125 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1130 wxMacConvertNewlines13To10( &str
) ;
1132 #if SIZEOF_WCHAR_T == 2
1133 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1134 (UniChar
*)str
.wc_str() , str
.Len() );
1136 wxMBConvUTF16BE converter
;
1137 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1138 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1139 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1140 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1141 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1144 #else // not wxUSE_UNICODE
1145 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1146 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1151 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1153 Size cflen
= CFStringGetLength( m_cfs
) ;
1155 wxChar
* buf
= NULL
;
1158 #if SIZEOF_WCHAR_T == 2
1159 buf
= new wxChar
[ cflen
+ 1 ] ;
1160 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1163 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1164 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1166 wxMBConvUTF16BE converter
;
1167 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1168 buf
= new wxChar
[ noChars
+ 1 ] ;
1169 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1174 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1175 '?' , false , NULL
, 0 , &cStrLen
) ;
1176 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1177 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1178 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1183 wxMacConvertNewlines10To13( buf
) ;
1184 wxString
result(buf
) ;
1189 #endif //TARGET_CARBON
1191 void wxMacConvertNewlines13To10( char * data
)
1194 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1201 void wxMacConvertNewlines10To13( char * data
)
1204 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1211 void wxMacConvertNewlines13To10( wxString
* data
)
1213 size_t len
= data
->Length() ;
1215 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1218 wxString
temp(*data
) ;
1219 wxStringBuffer
buf(*data
,len
) ;
1220 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1222 wxMacConvertNewlines13To10( buf
) ;
1225 void wxMacConvertNewlines10To13( wxString
* data
)
1227 size_t len
= data
->Length() ;
1229 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1232 wxString
temp(*data
) ;
1233 wxStringBuffer
buf(*data
,len
) ;
1234 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1235 wxMacConvertNewlines10To13( buf
) ;
1240 void wxMacConvertNewlines13To10( wxChar
* data
)
1242 wxChar
* buf
= data
;
1243 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1250 void wxMacConvertNewlines10To13( wxChar
* data
)
1252 wxChar
* buf
= data
;
1253 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1261 // ----------------------------------------------------------------------------
1262 // debugging support
1263 // ----------------------------------------------------------------------------
1265 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1267 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1269 #ifndef __MetroNubUtils__
1270 #include "MetroNubUtils.h"
1274 #include <Gestalt.h>
1277 #if TARGET_API_MAC_CARBON
1279 #include <CodeFragments.h>
1281 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1283 ProcPtr gCallUniversalProc_Proc
= NULL
;
1287 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1289 static long fRunOnce
= false;
1291 /* ---------------------------------------------------------------------------
1293 --------------------------------------------------------------------------- */
1295 Boolean
IsMetroNubInstalled()
1302 gMetroNubEntry
= NULL
;
1304 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1306 /* look for MetroNub's Gestalt selector */
1307 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1310 #if TARGET_API_MAC_CARBON
1311 if (gCallUniversalProc_Proc
== NULL
)
1313 CFragConnectionID connectionID
;
1316 ProcPtr symbolAddress
;
1318 CFragSymbolClass symbolClass
;
1320 symbolAddress
= NULL
;
1321 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1322 &connectionID
, &mainAddress
, errorString
);
1326 gCallUniversalProc_Proc
= NULL
;
1330 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1331 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1335 gCallUniversalProc_Proc
= NULL
;
1342 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1344 /* make sure the version of the API is compatible */
1345 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1346 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1347 gMetroNubEntry
= block
; /* success! */
1356 #if TARGET_API_MAC_CARBON
1357 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1359 return (gMetroNubEntry
!= NULL
);
1363 /* ---------------------------------------------------------------------------
1364 IsMWDebuggerRunning [v1 API]
1365 --------------------------------------------------------------------------- */
1367 Boolean
IsMWDebuggerRunning()
1369 if (IsMetroNubInstalled())
1370 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1375 /* ---------------------------------------------------------------------------
1376 AmIBeingMWDebugged [v1 API]
1377 --------------------------------------------------------------------------- */
1379 Boolean
AmIBeingMWDebugged()
1381 if (IsMetroNubInstalled())
1382 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1387 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1389 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1394 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1399 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)