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"
24 #include "wx/apptrait.h"
27 #include "wx/mac/uma.h"
38 # include "MoreFilesX.h"
40 # include "MoreFiles.h"
41 # include "MoreFilesExtras.h"
49 #include <ATSUnicode.h>
50 #include <TextCommon.h>
51 #include <TextEncodingConverter.h>
53 #include "wx/mac/private.h" // includes mac headers
55 #if defined(__MWERKS__) && wxUSE_UNICODE
59 // ---------------------------------------------------------------------------
60 // code used in both base and GUI compilation
61 // ---------------------------------------------------------------------------
63 // our OS version is the same in non GUI and GUI cases
64 wxOperatingSystemId
wxGetOsVersion(int *verMaj
, int *verMin
)
68 // are there x-platform conventions ?
70 Gestalt(gestaltSystemVersion
, &theSystem
);
72 *minorVsn
= (theSystem
& 0xFF);
75 *majorVsn
= (theSystem
>> 8);
77 #if defined( __DARWIN__ )
78 return wxOS_MAC_OSX_DARWIN
;
87 // defined in unix/utilsunx.cpp for Mac OS X
89 // get full hostname (with domain name if possible)
90 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
92 return wxGetHostName(buf
, maxSize
);
95 // Get hostname only (without domain name)
96 bool wxGetHostName(wxChar
*buf
, int maxSize
)
98 // Gets Chooser name of user by examining a System resource.
100 const short kComputerNameID
= -16413;
102 short oldResFile
= CurResFile() ;
104 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
105 UseResFile(oldResFile
);
107 if (chooserName
&& *chooserName
)
109 HLock( (Handle
) chooserName
) ;
110 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
111 HUnlock( (Handle
) chooserName
) ;
112 ReleaseResource( (Handle
) chooserName
) ;
113 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
121 // Get user ID e.g. jacs
122 bool wxGetUserId(wxChar
*buf
, int maxSize
)
124 return wxGetUserName( buf
, maxSize
) ;
127 const wxChar
* wxGetHomeDir(wxString
*pstr
)
129 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
130 return pstr
->c_str() ;
133 // Get user name e.g. Stefan Csomor
134 bool wxGetUserName(wxChar
*buf
, int maxSize
)
136 // Gets Chooser name of user by examining a System resource.
138 const short kChooserNameID
= -16096;
140 short oldResFile
= CurResFile() ;
142 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
143 UseResFile(oldResFile
);
145 if (chooserName
&& *chooserName
)
147 HLock( (Handle
) chooserName
) ;
148 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
149 HUnlock( (Handle
) chooserName
) ;
150 ReleaseResource( (Handle
) chooserName
) ;
151 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
159 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
165 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
167 // TODO : under classic there is no environement support, under X yes
171 // set the env var name to the given value, return true on success
172 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
174 // TODO : under classic there is no environement support, under X yes
179 // Execute a program in an Interactive Shell
181 bool wxShell(const wxString
& command
)
187 // Shutdown or reboot the PC
188 bool wxShutdown(wxShutdownFlags wFlags
)
194 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
195 wxMemorySize
wxGetFreeMemory()
197 return (wxMemorySize
)FreeMem() ;
200 void wxUsleep(unsigned long milliseconds
)
202 clock_t start
= clock() ;
206 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
209 void wxSleep(int nSecs
)
211 wxUsleep(1000*nSecs
);
214 // Consume all events until no more left
219 #endif // !__DARWIN__
231 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
233 // We suppose that toolkit version is the same as OS version under Mac
234 wxGetOsVersion(verMaj
, verMin
);
239 // Reading and writing resources (eg WIN.INI, .Xdefaults)
241 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
247 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
250 buf
.Printf(wxT("%.4f"), value
);
252 return wxWriteResource(section
, entry
, buf
, file
);
255 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
258 buf
.Printf(wxT("%ld"), value
);
260 return wxWriteResource(section
, entry
, buf
, file
);
263 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
266 buf
.Printf(wxT("%d"), value
);
268 return wxWriteResource(section
, entry
, buf
, file
);
271 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
277 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
280 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
283 *value
= (float)strtod(s
, NULL
);
290 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
293 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
296 *value
= strtol(s
, NULL
, 10);
303 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
306 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
309 *value
= (int)strtol(s
, NULL
, 10);
315 #endif // wxUSE_RESOURCES
317 int gs_wxBusyCursorCount
= 0;
318 extern wxCursor gMacCurrentCursor
;
319 wxCursor gMacStoredActiveCursor
;
321 // Set the cursor to the busy cursor for all windows
322 void wxBeginBusyCursor(const wxCursor
*cursor
)
324 if (gs_wxBusyCursorCount
++ == 0)
326 gMacStoredActiveCursor
= gMacCurrentCursor
;
327 cursor
->MacInstall() ;
329 //else: nothing to do, already set
332 // Restore cursor to normal
333 void wxEndBusyCursor()
335 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
336 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
338 if (--gs_wxBusyCursorCount
== 0)
340 gMacStoredActiveCursor
.MacInstall() ;
341 gMacStoredActiveCursor
= wxNullCursor
;
345 // true if we're between the above two calls
348 return (gs_wxBusyCursorCount
> 0);
355 wxString
wxMacFindFolderNoSeparator( short vol
,
357 Boolean createFolder
)
363 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
366 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
368 strDir
= wxMacFSSpec2MacFilename( &file
);
374 wxString
wxMacFindFolder( short vol
,
376 Boolean createFolder
)
378 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
385 // Check whether this window wants to process messages, e.g. Stop button
386 // in long calculations.
387 bool wxCheckForInterrupt(wxWindow
*wnd
)
393 void wxGetMousePosition( int* x
, int* y
)
398 LocalToGlobal( &pt
) ;
403 // Return true if we have a colour display
404 bool wxColourDisplay()
409 // Returns depth of screen
413 SetRect(&globRect
, -32760, -32760, 32760, 32760);
414 GDHandle theMaxDevice
;
417 theMaxDevice
= GetMaxDevice(&globRect
);
418 if (theMaxDevice
!= nil
)
419 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
424 // Get size of display
425 void wxDisplaySize(int *width
, int *height
)
428 GetQDGlobalsScreenBits( &screenBits
);
431 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
433 if (height
!= NULL
) {
434 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
438 void wxDisplaySizeMM(int *width
, int *height
)
440 wxDisplaySize(width
, height
);
441 // on mac 72 is fixed (at least now ;-)
442 float cvPt2Mm
= 25.4 / 72;
445 *width
= int( *width
* cvPt2Mm
);
447 if (height
!= NULL
) {
448 *height
= int( *height
* cvPt2Mm
);
452 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
456 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
462 *width
= r
.right
- r
.left
;
464 *height
= r
.bottom
- r
.top
;
467 GetQDGlobalsScreenBits( &screenBits
);
473 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
475 if (height
!= NULL
) {
476 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
481 GetThemeMenuBarHeight( &mheight
) ;
483 mheight
= LMGetMBarHeight() ;
485 if (height
!= NULL
) {
493 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
495 return wxGenericFindWindowAtPoint(pt
);
502 wxString
wxGetOsDescription()
504 #ifdef WXWIN_OS_DESCRIPTION
505 // use configure generated description if available
506 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
508 return wxT("MacOS") ; //TODO:define further
513 wxChar
*wxGetUserHome (const wxString
& user
)
519 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
529 int pos
= p
.Find(':') ;
530 if ( pos
!= wxNOT_FOUND
) {
539 wxMacStringToPascal( p
, volumeName
) ;
540 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
541 if ( err
== noErr
) {
543 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
546 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
550 return err
== noErr
;
552 #endif // !__DARWIN__
554 //---------------------------------------------------------------------------
555 // wxMac Specific utility functions
556 //---------------------------------------------------------------------------
558 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
560 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
561 int len
= strlen(buf
) ;
566 memcpy( (char*) &to
[1] , buf
, len
) ;
569 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
571 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
575 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
577 TextEncodingBase enc
= 0 ;
578 if ( encoding
== wxFONTENCODING_DEFAULT
)
581 encoding
= wxFont::GetDefaultEncoding() ;
583 encoding
= wxLocale::GetSystemEncoding() ;
589 case wxFONTENCODING_ISO8859_1
:
590 enc
= kTextEncodingISOLatin1
;
592 case wxFONTENCODING_ISO8859_2
:
593 enc
= kTextEncodingISOLatin2
;
595 case wxFONTENCODING_ISO8859_3
:
596 enc
= kTextEncodingISOLatin3
;
598 case wxFONTENCODING_ISO8859_4
:
599 enc
= kTextEncodingISOLatin4
;
601 case wxFONTENCODING_ISO8859_5
:
602 enc
= kTextEncodingISOLatinCyrillic
;
604 case wxFONTENCODING_ISO8859_6
:
605 enc
= kTextEncodingISOLatinArabic
;
607 case wxFONTENCODING_ISO8859_7
:
608 enc
= kTextEncodingISOLatinGreek
;
610 case wxFONTENCODING_ISO8859_8
:
611 enc
= kTextEncodingISOLatinHebrew
;
613 case wxFONTENCODING_ISO8859_9
:
614 enc
= kTextEncodingISOLatin5
;
616 case wxFONTENCODING_ISO8859_10
:
617 enc
= kTextEncodingISOLatin6
;
619 case wxFONTENCODING_ISO8859_13
:
620 enc
= kTextEncodingISOLatin7
;
622 case wxFONTENCODING_ISO8859_14
:
623 enc
= kTextEncodingISOLatin8
;
625 case wxFONTENCODING_ISO8859_15
:
626 enc
= kTextEncodingISOLatin9
;
629 case wxFONTENCODING_KOI8
:
630 enc
= kTextEncodingKOI8_R
;
632 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
633 enc
= kTextEncodingDOSRussian
;
636 case wxFONTENCODING_BULGARIAN :
640 case wxFONTENCODING_CP437
:
641 enc
=kTextEncodingDOSLatinUS
;
643 case wxFONTENCODING_CP850
:
644 enc
= kTextEncodingDOSLatin1
;
646 case wxFONTENCODING_CP852
:
647 enc
= kTextEncodingDOSLatin2
;
649 case wxFONTENCODING_CP855
:
650 enc
= kTextEncodingDOSCyrillic
;
652 case wxFONTENCODING_CP866
:
653 enc
=kTextEncodingDOSRussian
;
655 case wxFONTENCODING_CP874
:
656 enc
= kTextEncodingDOSThai
;
658 case wxFONTENCODING_CP932
:
659 enc
= kTextEncodingDOSJapanese
;
661 case wxFONTENCODING_CP936
:
662 enc
=kTextEncodingDOSChineseSimplif
;
664 case wxFONTENCODING_CP949
:
665 enc
= kTextEncodingDOSKorean
;
667 case wxFONTENCODING_CP950
:
668 enc
= kTextEncodingDOSChineseTrad
;
671 case wxFONTENCODING_CP1250
:
672 enc
= kTextEncodingWindowsLatin2
;
674 case wxFONTENCODING_CP1251
:
675 enc
=kTextEncodingWindowsCyrillic
;
677 case wxFONTENCODING_CP1252
:
678 enc
=kTextEncodingWindowsLatin1
;
680 case wxFONTENCODING_CP1253
:
681 enc
= kTextEncodingWindowsGreek
;
683 case wxFONTENCODING_CP1254
:
684 enc
= kTextEncodingWindowsLatin5
;
686 case wxFONTENCODING_CP1255
:
687 enc
=kTextEncodingWindowsHebrew
;
689 case wxFONTENCODING_CP1256
:
690 enc
=kTextEncodingWindowsArabic
;
692 case wxFONTENCODING_CP1257
:
693 enc
= kTextEncodingWindowsBalticRim
;
696 case wxFONTENCODING_UTF7
:
697 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
699 case wxFONTENCODING_UTF8
:
700 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
702 case wxFONTENCODING_EUC_JP
:
703 enc
= kTextEncodingEUC_JP
;
705 case wxFONTENCODING_UTF16BE
:
706 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
708 case wxFONTENCODING_UTF16LE
:
709 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
711 case wxFONTENCODING_UTF32BE
:
712 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
714 case wxFONTENCODING_UTF32LE
:
715 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
718 case wxFONTENCODING_MACROMAN
:
719 enc
= kTextEncodingMacRoman
;
721 case wxFONTENCODING_MACJAPANESE
:
722 enc
= kTextEncodingMacJapanese
;
724 case wxFONTENCODING_MACCHINESETRAD
:
725 enc
= kTextEncodingMacChineseTrad
;
727 case wxFONTENCODING_MACKOREAN
:
728 enc
= kTextEncodingMacKorean
;
730 case wxFONTENCODING_MACARABIC
:
731 enc
= kTextEncodingMacArabic
;
733 case wxFONTENCODING_MACHEBREW
:
734 enc
= kTextEncodingMacHebrew
;
736 case wxFONTENCODING_MACGREEK
:
737 enc
= kTextEncodingMacGreek
;
739 case wxFONTENCODING_MACCYRILLIC
:
740 enc
= kTextEncodingMacCyrillic
;
742 case wxFONTENCODING_MACDEVANAGARI
:
743 enc
= kTextEncodingMacDevanagari
;
745 case wxFONTENCODING_MACGURMUKHI
:
746 enc
= kTextEncodingMacGurmukhi
;
748 case wxFONTENCODING_MACGUJARATI
:
749 enc
= kTextEncodingMacGujarati
;
751 case wxFONTENCODING_MACORIYA
:
752 enc
= kTextEncodingMacOriya
;
754 case wxFONTENCODING_MACBENGALI
:
755 enc
= kTextEncodingMacBengali
;
757 case wxFONTENCODING_MACTAMIL
:
758 enc
= kTextEncodingMacTamil
;
760 case wxFONTENCODING_MACTELUGU
:
761 enc
= kTextEncodingMacTelugu
;
763 case wxFONTENCODING_MACKANNADA
:
764 enc
= kTextEncodingMacKannada
;
766 case wxFONTENCODING_MACMALAJALAM
:
767 enc
= kTextEncodingMacMalayalam
;
769 case wxFONTENCODING_MACSINHALESE
:
770 enc
= kTextEncodingMacSinhalese
;
772 case wxFONTENCODING_MACBURMESE
:
773 enc
= kTextEncodingMacBurmese
;
775 case wxFONTENCODING_MACKHMER
:
776 enc
= kTextEncodingMacKhmer
;
778 case wxFONTENCODING_MACTHAI
:
779 enc
= kTextEncodingMacThai
;
781 case wxFONTENCODING_MACLAOTIAN
:
782 enc
= kTextEncodingMacLaotian
;
784 case wxFONTENCODING_MACGEORGIAN
:
785 enc
= kTextEncodingMacGeorgian
;
787 case wxFONTENCODING_MACARMENIAN
:
788 enc
= kTextEncodingMacArmenian
;
790 case wxFONTENCODING_MACCHINESESIMP
:
791 enc
= kTextEncodingMacChineseSimp
;
793 case wxFONTENCODING_MACTIBETAN
:
794 enc
= kTextEncodingMacTibetan
;
796 case wxFONTENCODING_MACMONGOLIAN
:
797 enc
= kTextEncodingMacMongolian
;
799 case wxFONTENCODING_MACETHIOPIC
:
800 enc
= kTextEncodingMacEthiopic
;
802 case wxFONTENCODING_MACCENTRALEUR
:
803 enc
= kTextEncodingMacCentralEurRoman
;
805 case wxFONTENCODING_MACVIATNAMESE
:
806 enc
= kTextEncodingMacVietnamese
;
808 case wxFONTENCODING_MACARABICEXT
:
809 enc
= kTextEncodingMacExtArabic
;
811 case wxFONTENCODING_MACSYMBOL
:
812 enc
= kTextEncodingMacSymbol
;
814 case wxFONTENCODING_MACDINGBATS
:
815 enc
= kTextEncodingMacDingbats
;
817 case wxFONTENCODING_MACTURKISH
:
818 enc
= kTextEncodingMacTurkish
;
820 case wxFONTENCODING_MACCROATIAN
:
821 enc
= kTextEncodingMacCroatian
;
823 case wxFONTENCODING_MACICELANDIC
:
824 enc
= kTextEncodingMacIcelandic
;
826 case wxFONTENCODING_MACROMANIAN
:
827 enc
= kTextEncodingMacRomanian
;
829 case wxFONTENCODING_MACCELTIC
:
830 enc
= kTextEncodingMacCeltic
;
832 case wxFONTENCODING_MACGAELIC
:
833 enc
= kTextEncodingMacGaelic
;
835 case wxFONTENCODING_MACKEYBOARD
:
836 enc
= kTextEncodingMacKeyboardGlyphs
;
845 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
847 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
851 case kTextEncodingISOLatin1
:
852 enc
= wxFONTENCODING_ISO8859_1
;
854 case kTextEncodingISOLatin2
:
855 enc
= wxFONTENCODING_ISO8859_2
;
857 case kTextEncodingISOLatin3
:
858 enc
= wxFONTENCODING_ISO8859_3
;
860 case kTextEncodingISOLatin4
:
861 enc
= wxFONTENCODING_ISO8859_4
;
863 case kTextEncodingISOLatinCyrillic
:
864 enc
= wxFONTENCODING_ISO8859_5
;
866 case kTextEncodingISOLatinArabic
:
867 enc
= wxFONTENCODING_ISO8859_6
;
869 case kTextEncodingISOLatinGreek
:
870 enc
= wxFONTENCODING_ISO8859_7
;
872 case kTextEncodingISOLatinHebrew
:
873 enc
= wxFONTENCODING_ISO8859_8
;
875 case kTextEncodingISOLatin5
:
876 enc
= wxFONTENCODING_ISO8859_9
;
878 case kTextEncodingISOLatin6
:
879 enc
= wxFONTENCODING_ISO8859_10
;
881 case kTextEncodingISOLatin7
:
882 enc
= wxFONTENCODING_ISO8859_13
;
884 case kTextEncodingISOLatin8
:
885 enc
= wxFONTENCODING_ISO8859_14
;
887 case kTextEncodingISOLatin9
:
888 enc
=wxFONTENCODING_ISO8859_15
;
891 case kTextEncodingKOI8_R
:
892 enc
= wxFONTENCODING_KOI8
;
896 enc = wxFONTENCODING_BULGARIAN;
899 case kTextEncodingDOSLatinUS
:
900 enc
= wxFONTENCODING_CP437
;
902 case kTextEncodingDOSLatin1
:
903 enc
= wxFONTENCODING_CP850
;
905 case kTextEncodingDOSLatin2
:
906 enc
=wxFONTENCODING_CP852
;
908 case kTextEncodingDOSCyrillic
:
909 enc
= wxFONTENCODING_CP855
;
911 case kTextEncodingDOSRussian
:
912 enc
= wxFONTENCODING_CP866
;
914 case kTextEncodingDOSThai
:
915 enc
=wxFONTENCODING_CP874
;
917 case kTextEncodingDOSJapanese
:
918 enc
= wxFONTENCODING_CP932
;
920 case kTextEncodingDOSChineseSimplif
:
921 enc
= wxFONTENCODING_CP936
;
923 case kTextEncodingDOSKorean
:
924 enc
= wxFONTENCODING_CP949
;
926 case kTextEncodingDOSChineseTrad
:
927 enc
= wxFONTENCODING_CP950
;
930 case kTextEncodingWindowsLatin2
:
931 enc
= wxFONTENCODING_CP1250
;
933 case kTextEncodingWindowsCyrillic
:
934 enc
= wxFONTENCODING_CP1251
;
936 case kTextEncodingWindowsLatin1
:
937 enc
= wxFONTENCODING_CP1252
;
939 case kTextEncodingWindowsGreek
:
940 enc
= wxFONTENCODING_CP1253
;
942 case kTextEncodingWindowsLatin5
:
943 enc
= wxFONTENCODING_CP1254
;
945 case kTextEncodingWindowsHebrew
:
946 enc
= wxFONTENCODING_CP1255
;
948 case kTextEncodingWindowsArabic
:
949 enc
= wxFONTENCODING_CP1256
;
951 case kTextEncodingWindowsBalticRim
:
952 enc
=wxFONTENCODING_CP1257
;
954 case kTextEncodingEUC_JP
:
955 enc
= wxFONTENCODING_EUC_JP
;
958 case wxFONTENCODING_UTF7 :
959 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
961 case wxFONTENCODING_UTF8 :
962 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
964 case wxFONTENCODING_UTF16BE :
965 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
967 case wxFONTENCODING_UTF16LE :
968 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
970 case wxFONTENCODING_UTF32BE :
971 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
973 case wxFONTENCODING_UTF32LE :
974 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
977 case kTextEncodingMacRoman
:
978 enc
= wxFONTENCODING_MACROMAN
;
980 case kTextEncodingMacJapanese
:
981 enc
= wxFONTENCODING_MACJAPANESE
;
983 case kTextEncodingMacChineseTrad
:
984 enc
= wxFONTENCODING_MACCHINESETRAD
;
986 case kTextEncodingMacKorean
:
987 enc
= wxFONTENCODING_MACKOREAN
;
989 case kTextEncodingMacArabic
:
990 enc
=wxFONTENCODING_MACARABIC
;
992 case kTextEncodingMacHebrew
:
993 enc
= wxFONTENCODING_MACHEBREW
;
995 case kTextEncodingMacGreek
:
996 enc
= wxFONTENCODING_MACGREEK
;
998 case kTextEncodingMacCyrillic
:
999 enc
= wxFONTENCODING_MACCYRILLIC
;
1001 case kTextEncodingMacDevanagari
:
1002 enc
= wxFONTENCODING_MACDEVANAGARI
;
1004 case kTextEncodingMacGurmukhi
:
1005 enc
= wxFONTENCODING_MACGURMUKHI
;
1007 case kTextEncodingMacGujarati
:
1008 enc
= wxFONTENCODING_MACGUJARATI
;
1010 case kTextEncodingMacOriya
:
1011 enc
=wxFONTENCODING_MACORIYA
;
1013 case kTextEncodingMacBengali
:
1014 enc
=wxFONTENCODING_MACBENGALI
;
1016 case kTextEncodingMacTamil
:
1017 enc
= wxFONTENCODING_MACTAMIL
;
1019 case kTextEncodingMacTelugu
:
1020 enc
= wxFONTENCODING_MACTELUGU
;
1022 case kTextEncodingMacKannada
:
1023 enc
= wxFONTENCODING_MACKANNADA
;
1025 case kTextEncodingMacMalayalam
:
1026 enc
= wxFONTENCODING_MACMALAJALAM
;
1028 case kTextEncodingMacSinhalese
:
1029 enc
= wxFONTENCODING_MACSINHALESE
;
1031 case kTextEncodingMacBurmese
:
1032 enc
= wxFONTENCODING_MACBURMESE
;
1034 case kTextEncodingMacKhmer
:
1035 enc
= wxFONTENCODING_MACKHMER
;
1037 case kTextEncodingMacThai
:
1038 enc
= wxFONTENCODING_MACTHAI
;
1040 case kTextEncodingMacLaotian
:
1041 enc
= wxFONTENCODING_MACLAOTIAN
;
1043 case kTextEncodingMacGeorgian
:
1044 enc
= wxFONTENCODING_MACGEORGIAN
;
1046 case kTextEncodingMacArmenian
:
1047 enc
= wxFONTENCODING_MACARMENIAN
;
1049 case kTextEncodingMacChineseSimp
:
1050 enc
= wxFONTENCODING_MACCHINESESIMP
;
1052 case kTextEncodingMacTibetan
:
1053 enc
= wxFONTENCODING_MACTIBETAN
;
1055 case kTextEncodingMacMongolian
:
1056 enc
= wxFONTENCODING_MACMONGOLIAN
;
1058 case kTextEncodingMacEthiopic
:
1059 enc
= wxFONTENCODING_MACETHIOPIC
;
1061 case kTextEncodingMacCentralEurRoman
:
1062 enc
= wxFONTENCODING_MACCENTRALEUR
;
1064 case kTextEncodingMacVietnamese
:
1065 enc
= wxFONTENCODING_MACVIATNAMESE
;
1067 case kTextEncodingMacExtArabic
:
1068 enc
= wxFONTENCODING_MACARABICEXT
;
1070 case kTextEncodingMacSymbol
:
1071 enc
= wxFONTENCODING_MACSYMBOL
;
1073 case kTextEncodingMacDingbats
:
1074 enc
= wxFONTENCODING_MACDINGBATS
;
1076 case kTextEncodingMacTurkish
:
1077 enc
= wxFONTENCODING_MACTURKISH
;
1079 case kTextEncodingMacCroatian
:
1080 enc
= wxFONTENCODING_MACCROATIAN
;
1082 case kTextEncodingMacIcelandic
:
1083 enc
= wxFONTENCODING_MACICELANDIC
;
1085 case kTextEncodingMacRomanian
:
1086 enc
= wxFONTENCODING_MACROMANIAN
;
1088 case kTextEncodingMacCeltic
:
1089 enc
= wxFONTENCODING_MACCELTIC
;
1091 case kTextEncodingMacGaelic
:
1092 enc
= wxFONTENCODING_MACGAELIC
;
1094 case kTextEncodingMacKeyboardGlyphs
:
1095 enc
= wxFONTENCODING_MACKEYBOARD
;
1101 #endif // wxUSE_BASE
1107 // CFStringRefs (Carbon only)
1112 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1113 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1118 wxMacConvertNewlines13To10( &str
) ;
1120 #if SIZEOF_WCHAR_T == 2
1121 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1122 (UniChar
*)str
.wc_str() , str
.Len() );
1124 wxMBConvUTF16BE converter
;
1125 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1126 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1127 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1128 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1129 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1132 #else // not wxUSE_UNICODE
1133 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1134 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1139 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1141 Size cflen
= CFStringGetLength( m_cfs
) ;
1143 wxChar
* buf
= NULL
;
1146 #if SIZEOF_WCHAR_T == 2
1147 buf
= new wxChar
[ cflen
+ 1 ] ;
1148 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1151 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1152 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1154 wxMBConvUTF16BE converter
;
1155 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1156 buf
= new wxChar
[ noChars
+ 1 ] ;
1157 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1162 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1163 '?' , false , NULL
, 0 , &cStrLen
) ;
1164 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1165 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1166 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1171 wxMacConvertNewlines10To13( buf
) ;
1172 wxString
result(buf
) ;
1177 #endif //TARGET_CARBON
1179 void wxMacConvertNewlines13To10( char * data
)
1182 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1189 void wxMacConvertNewlines10To13( char * data
)
1192 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1199 void wxMacConvertNewlines13To10( wxString
* data
)
1201 size_t len
= data
->length() ;
1203 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1206 wxString
temp(*data
) ;
1207 wxStringBuffer
buf(*data
,len
) ;
1208 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1210 wxMacConvertNewlines13To10( buf
) ;
1213 void wxMacConvertNewlines10To13( wxString
* data
)
1215 size_t len
= data
->length() ;
1217 if ( data
->empty() || wxStrchr(data
->c_str(),0x0a)==NULL
)
1220 wxString
temp(*data
) ;
1221 wxStringBuffer
buf(*data
,len
) ;
1222 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1223 wxMacConvertNewlines10To13( buf
) ;
1228 void wxMacConvertNewlines13To10( wxChar
* data
)
1230 wxChar
* buf
= data
;
1231 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1238 void wxMacConvertNewlines10To13( wxChar
* data
)
1240 wxChar
* buf
= data
;
1241 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1249 // ----------------------------------------------------------------------------
1250 // debugging support
1251 // ----------------------------------------------------------------------------
1253 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1255 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1257 #ifndef __MetroNubUtils__
1258 #include "MetroNubUtils.h"
1262 #include <Gestalt.h>
1265 #if TARGET_API_MAC_CARBON
1267 #include <CodeFragments.h>
1269 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1271 ProcPtr gCallUniversalProc_Proc
= NULL
;
1275 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1277 static long fRunOnce
= false;
1279 /* ---------------------------------------------------------------------------
1281 --------------------------------------------------------------------------- */
1283 Boolean
IsMetroNubInstalled()
1290 gMetroNubEntry
= NULL
;
1292 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1294 /* look for MetroNub's Gestalt selector */
1295 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1298 #if TARGET_API_MAC_CARBON
1299 if (gCallUniversalProc_Proc
== NULL
)
1301 CFragConnectionID connectionID
;
1304 ProcPtr symbolAddress
;
1306 CFragSymbolClass symbolClass
;
1308 symbolAddress
= NULL
;
1309 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1310 &connectionID
, &mainAddress
, errorString
);
1314 gCallUniversalProc_Proc
= NULL
;
1318 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1319 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1323 gCallUniversalProc_Proc
= NULL
;
1330 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1332 /* make sure the version of the API is compatible */
1333 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1334 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1335 gMetroNubEntry
= block
; /* success! */
1344 #if TARGET_API_MAC_CARBON
1345 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1347 return (gMetroNubEntry
!= NULL
);
1351 /* ---------------------------------------------------------------------------
1352 IsMWDebuggerRunning [v1 API]
1353 --------------------------------------------------------------------------- */
1355 Boolean
IsMWDebuggerRunning()
1357 if (IsMetroNubInstalled())
1358 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1363 /* ---------------------------------------------------------------------------
1364 AmIBeingMWDebugged [v1 API]
1365 --------------------------------------------------------------------------- */
1367 Boolean
AmIBeingMWDebugged()
1369 if (IsMetroNubInstalled())
1370 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1375 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1377 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1382 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1387 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)