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
61 // our OS version is the same in non GUI and GUI cases
62 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
65 Gestalt(gestaltSystemVersion
, &theSystem
);
67 if ( majorVsn
!= NULL
)
68 *majorVsn
= (theSystem
>> 8);
70 if ( minorVsn
!= NULL
)
71 *minorVsn
= (theSystem
& 0xFF);
74 #if defined( __DARWIN__ )
75 return wxOS_MAC_OSX_DARWIN
;
82 // defined in unix/utilsunx.cpp for Mac OS X
84 // get full hostname (with domain name if possible)
85 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
87 return wxGetHostName(buf
, maxSize
);
90 // Get hostname only (without domain name)
91 bool wxGetHostName(wxChar
*buf
, int maxSize
)
93 // Gets Chooser name of user by examining a System resource.
95 const short kComputerNameID
= -16413;
97 short oldResFile
= CurResFile() ;
99 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
100 UseResFile(oldResFile
);
102 if (chooserName
&& *chooserName
)
104 HLock( (Handle
) chooserName
) ;
105 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
106 HUnlock( (Handle
) chooserName
) ;
107 ReleaseResource( (Handle
) chooserName
) ;
108 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
116 // Get user ID e.g. jacs
117 bool wxGetUserId(wxChar
*buf
, int maxSize
)
119 return wxGetUserName( buf
, maxSize
) ;
122 const wxChar
* wxGetHomeDir(wxString
*pstr
)
124 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
125 return pstr
->c_str() ;
128 // Get user name e.g. Stefan Csomor
129 bool wxGetUserName(wxChar
*buf
, int maxSize
)
131 // Gets Chooser name of user by examining a System resource.
133 const short kChooserNameID
= -16096;
135 short oldResFile
= CurResFile() ;
137 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
138 UseResFile(oldResFile
);
140 if (chooserName
&& *chooserName
)
142 HLock( (Handle
) chooserName
) ;
143 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
144 HUnlock( (Handle
) chooserName
) ;
145 ReleaseResource( (Handle
) chooserName
) ;
146 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
154 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
160 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
162 // TODO : under classic there is no environement support, under X yes
166 // set the env var name to the given value, return true on success
167 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
169 // TODO : under classic there is no environement support, under X yes
174 // Execute a program in an Interactive Shell
176 bool wxShell(const wxString
& command
)
182 // Shutdown or reboot the PC
183 bool wxShutdown(wxShutdownFlags wFlags
)
189 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
190 wxMemorySize
wxGetFreeMemory()
192 return (wxMemorySize
)FreeMem() ;
195 void wxUsleep(unsigned long milliseconds
)
197 clock_t start
= clock() ;
201 } while( clock() - start
< milliseconds
/ 1000.0 * CLOCKS_PER_SEC
) ;
204 void wxSleep(int nSecs
)
206 wxUsleep(1000*nSecs
);
209 // Consume all events until no more left
214 #endif // !__DARWIN__
226 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
228 // We suppose that toolkit version is the same as OS version under Mac
229 wxGetOsVersion(verMaj
, verMin
);
234 // Reading and writing resources (eg WIN.INI, .Xdefaults)
236 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
242 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
245 buf
.Printf(wxT("%.4f"), value
);
247 return wxWriteResource(section
, entry
, buf
, file
);
250 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
253 buf
.Printf(wxT("%ld"), value
);
255 return wxWriteResource(section
, entry
, buf
, file
);
258 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
261 buf
.Printf(wxT("%d"), value
);
263 return wxWriteResource(section
, entry
, buf
, file
);
266 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
272 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
275 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
278 *value
= (float)strtod(s
, NULL
);
285 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
288 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
291 *value
= strtol(s
, NULL
, 10);
298 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
301 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
304 *value
= (int)strtol(s
, NULL
, 10);
310 #endif // wxUSE_RESOURCES
312 int gs_wxBusyCursorCount
= 0;
313 extern wxCursor gMacCurrentCursor
;
314 wxCursor gMacStoredActiveCursor
;
316 // Set the cursor to the busy cursor for all windows
317 void wxBeginBusyCursor(const wxCursor
*cursor
)
319 if (gs_wxBusyCursorCount
++ == 0)
321 gMacStoredActiveCursor
= gMacCurrentCursor
;
322 cursor
->MacInstall() ;
324 //else: nothing to do, already set
327 // Restore cursor to normal
328 void wxEndBusyCursor()
330 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
331 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
333 if (--gs_wxBusyCursorCount
== 0)
335 gMacStoredActiveCursor
.MacInstall() ;
336 gMacStoredActiveCursor
= wxNullCursor
;
340 // true if we're between the above two calls
343 return (gs_wxBusyCursorCount
> 0);
350 wxString
wxMacFindFolderNoSeparator( short vol
,
352 Boolean createFolder
)
358 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
361 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
363 strDir
= wxMacFSSpec2MacFilename( &file
);
369 wxString
wxMacFindFolder( short vol
,
371 Boolean createFolder
)
373 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
380 // Check whether this window wants to process messages, e.g. Stop button
381 // in long calculations.
382 bool wxCheckForInterrupt(wxWindow
*wnd
)
388 void wxGetMousePosition( int* x
, int* y
)
393 LocalToGlobal( &pt
) ;
398 // Return true if we have a colour display
399 bool wxColourDisplay()
404 // Returns depth of screen
408 SetRect(&globRect
, -32760, -32760, 32760, 32760);
409 GDHandle theMaxDevice
;
412 theMaxDevice
= GetMaxDevice(&globRect
);
413 if (theMaxDevice
!= nil
)
414 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
419 // Get size of display
420 void wxDisplaySize(int *width
, int *height
)
423 GetQDGlobalsScreenBits( &screenBits
);
426 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
428 if (height
!= NULL
) {
429 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
433 void wxDisplaySizeMM(int *width
, int *height
)
435 wxDisplaySize(width
, height
);
436 // on mac 72 is fixed (at least now ;-)
437 float cvPt2Mm
= 25.4 / 72;
440 *width
= int( *width
* cvPt2Mm
);
442 if (height
!= NULL
) {
443 *height
= int( *height
* cvPt2Mm
);
447 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
451 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
457 *width
= r
.right
- r
.left
;
459 *height
= r
.bottom
- r
.top
;
462 GetQDGlobalsScreenBits( &screenBits
);
468 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
470 if (height
!= NULL
) {
471 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
476 GetThemeMenuBarHeight( &mheight
) ;
478 mheight
= LMGetMBarHeight() ;
480 if (height
!= NULL
) {
488 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
490 return wxGenericFindWindowAtPoint(pt
);
497 wxString
wxGetOsDescription()
499 #ifdef WXWIN_OS_DESCRIPTION
500 // use configure generated description if available
501 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
503 return wxT("MacOS") ; //TODO:define further
508 wxChar
*wxGetUserHome (const wxString
& user
)
514 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
524 int pos
= p
.Find(':') ;
525 if ( pos
!= wxNOT_FOUND
) {
534 wxMacStringToPascal( p
, volumeName
) ;
535 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
536 if ( err
== noErr
) {
538 (*pTotal
) = wxDiskspaceSize_t( pb
.ioVTotalBytes
) ;
541 (*pFree
) = wxDiskspaceSize_t( pb
.ioVFreeBytes
) ;
545 return err
== noErr
;
547 #endif // !__DARWIN__
549 //---------------------------------------------------------------------------
550 // wxMac Specific utility functions
551 //---------------------------------------------------------------------------
553 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
555 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
556 int len
= strlen(buf
) ;
561 memcpy( (char*) &to
[1] , buf
, len
) ;
564 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
566 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
570 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
572 TextEncodingBase enc
= 0 ;
573 if ( encoding
== wxFONTENCODING_DEFAULT
)
576 encoding
= wxFont::GetDefaultEncoding() ;
578 encoding
= wxLocale::GetSystemEncoding() ;
584 case wxFONTENCODING_ISO8859_1
:
585 enc
= kTextEncodingISOLatin1
;
587 case wxFONTENCODING_ISO8859_2
:
588 enc
= kTextEncodingISOLatin2
;
590 case wxFONTENCODING_ISO8859_3
:
591 enc
= kTextEncodingISOLatin3
;
593 case wxFONTENCODING_ISO8859_4
:
594 enc
= kTextEncodingISOLatin4
;
596 case wxFONTENCODING_ISO8859_5
:
597 enc
= kTextEncodingISOLatinCyrillic
;
599 case wxFONTENCODING_ISO8859_6
:
600 enc
= kTextEncodingISOLatinArabic
;
602 case wxFONTENCODING_ISO8859_7
:
603 enc
= kTextEncodingISOLatinGreek
;
605 case wxFONTENCODING_ISO8859_8
:
606 enc
= kTextEncodingISOLatinHebrew
;
608 case wxFONTENCODING_ISO8859_9
:
609 enc
= kTextEncodingISOLatin5
;
611 case wxFONTENCODING_ISO8859_10
:
612 enc
= kTextEncodingISOLatin6
;
614 case wxFONTENCODING_ISO8859_13
:
615 enc
= kTextEncodingISOLatin7
;
617 case wxFONTENCODING_ISO8859_14
:
618 enc
= kTextEncodingISOLatin8
;
620 case wxFONTENCODING_ISO8859_15
:
621 enc
= kTextEncodingISOLatin9
;
624 case wxFONTENCODING_KOI8
:
625 enc
= kTextEncodingKOI8_R
;
627 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
628 enc
= kTextEncodingDOSRussian
;
631 case wxFONTENCODING_BULGARIAN :
635 case wxFONTENCODING_CP437
:
636 enc
=kTextEncodingDOSLatinUS
;
638 case wxFONTENCODING_CP850
:
639 enc
= kTextEncodingDOSLatin1
;
641 case wxFONTENCODING_CP852
:
642 enc
= kTextEncodingDOSLatin2
;
644 case wxFONTENCODING_CP855
:
645 enc
= kTextEncodingDOSCyrillic
;
647 case wxFONTENCODING_CP866
:
648 enc
=kTextEncodingDOSRussian
;
650 case wxFONTENCODING_CP874
:
651 enc
= kTextEncodingDOSThai
;
653 case wxFONTENCODING_CP932
:
654 enc
= kTextEncodingDOSJapanese
;
656 case wxFONTENCODING_CP936
:
657 enc
=kTextEncodingDOSChineseSimplif
;
659 case wxFONTENCODING_CP949
:
660 enc
= kTextEncodingDOSKorean
;
662 case wxFONTENCODING_CP950
:
663 enc
= kTextEncodingDOSChineseTrad
;
666 case wxFONTENCODING_CP1250
:
667 enc
= kTextEncodingWindowsLatin2
;
669 case wxFONTENCODING_CP1251
:
670 enc
=kTextEncodingWindowsCyrillic
;
672 case wxFONTENCODING_CP1252
:
673 enc
=kTextEncodingWindowsLatin1
;
675 case wxFONTENCODING_CP1253
:
676 enc
= kTextEncodingWindowsGreek
;
678 case wxFONTENCODING_CP1254
:
679 enc
= kTextEncodingWindowsLatin5
;
681 case wxFONTENCODING_CP1255
:
682 enc
=kTextEncodingWindowsHebrew
;
684 case wxFONTENCODING_CP1256
:
685 enc
=kTextEncodingWindowsArabic
;
687 case wxFONTENCODING_CP1257
:
688 enc
= kTextEncodingWindowsBalticRim
;
691 case wxFONTENCODING_UTF7
:
692 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
694 case wxFONTENCODING_UTF8
:
695 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
697 case wxFONTENCODING_EUC_JP
:
698 enc
= kTextEncodingEUC_JP
;
700 case wxFONTENCODING_UTF16BE
:
701 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
703 case wxFONTENCODING_UTF16LE
:
704 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
706 case wxFONTENCODING_UTF32BE
:
707 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
709 case wxFONTENCODING_UTF32LE
:
710 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
713 case wxFONTENCODING_MACROMAN
:
714 enc
= kTextEncodingMacRoman
;
716 case wxFONTENCODING_MACJAPANESE
:
717 enc
= kTextEncodingMacJapanese
;
719 case wxFONTENCODING_MACCHINESETRAD
:
720 enc
= kTextEncodingMacChineseTrad
;
722 case wxFONTENCODING_MACKOREAN
:
723 enc
= kTextEncodingMacKorean
;
725 case wxFONTENCODING_MACARABIC
:
726 enc
= kTextEncodingMacArabic
;
728 case wxFONTENCODING_MACHEBREW
:
729 enc
= kTextEncodingMacHebrew
;
731 case wxFONTENCODING_MACGREEK
:
732 enc
= kTextEncodingMacGreek
;
734 case wxFONTENCODING_MACCYRILLIC
:
735 enc
= kTextEncodingMacCyrillic
;
737 case wxFONTENCODING_MACDEVANAGARI
:
738 enc
= kTextEncodingMacDevanagari
;
740 case wxFONTENCODING_MACGURMUKHI
:
741 enc
= kTextEncodingMacGurmukhi
;
743 case wxFONTENCODING_MACGUJARATI
:
744 enc
= kTextEncodingMacGujarati
;
746 case wxFONTENCODING_MACORIYA
:
747 enc
= kTextEncodingMacOriya
;
749 case wxFONTENCODING_MACBENGALI
:
750 enc
= kTextEncodingMacBengali
;
752 case wxFONTENCODING_MACTAMIL
:
753 enc
= kTextEncodingMacTamil
;
755 case wxFONTENCODING_MACTELUGU
:
756 enc
= kTextEncodingMacTelugu
;
758 case wxFONTENCODING_MACKANNADA
:
759 enc
= kTextEncodingMacKannada
;
761 case wxFONTENCODING_MACMALAJALAM
:
762 enc
= kTextEncodingMacMalayalam
;
764 case wxFONTENCODING_MACSINHALESE
:
765 enc
= kTextEncodingMacSinhalese
;
767 case wxFONTENCODING_MACBURMESE
:
768 enc
= kTextEncodingMacBurmese
;
770 case wxFONTENCODING_MACKHMER
:
771 enc
= kTextEncodingMacKhmer
;
773 case wxFONTENCODING_MACTHAI
:
774 enc
= kTextEncodingMacThai
;
776 case wxFONTENCODING_MACLAOTIAN
:
777 enc
= kTextEncodingMacLaotian
;
779 case wxFONTENCODING_MACGEORGIAN
:
780 enc
= kTextEncodingMacGeorgian
;
782 case wxFONTENCODING_MACARMENIAN
:
783 enc
= kTextEncodingMacArmenian
;
785 case wxFONTENCODING_MACCHINESESIMP
:
786 enc
= kTextEncodingMacChineseSimp
;
788 case wxFONTENCODING_MACTIBETAN
:
789 enc
= kTextEncodingMacTibetan
;
791 case wxFONTENCODING_MACMONGOLIAN
:
792 enc
= kTextEncodingMacMongolian
;
794 case wxFONTENCODING_MACETHIOPIC
:
795 enc
= kTextEncodingMacEthiopic
;
797 case wxFONTENCODING_MACCENTRALEUR
:
798 enc
= kTextEncodingMacCentralEurRoman
;
800 case wxFONTENCODING_MACVIATNAMESE
:
801 enc
= kTextEncodingMacVietnamese
;
803 case wxFONTENCODING_MACARABICEXT
:
804 enc
= kTextEncodingMacExtArabic
;
806 case wxFONTENCODING_MACSYMBOL
:
807 enc
= kTextEncodingMacSymbol
;
809 case wxFONTENCODING_MACDINGBATS
:
810 enc
= kTextEncodingMacDingbats
;
812 case wxFONTENCODING_MACTURKISH
:
813 enc
= kTextEncodingMacTurkish
;
815 case wxFONTENCODING_MACCROATIAN
:
816 enc
= kTextEncodingMacCroatian
;
818 case wxFONTENCODING_MACICELANDIC
:
819 enc
= kTextEncodingMacIcelandic
;
821 case wxFONTENCODING_MACROMANIAN
:
822 enc
= kTextEncodingMacRomanian
;
824 case wxFONTENCODING_MACCELTIC
:
825 enc
= kTextEncodingMacCeltic
;
827 case wxFONTENCODING_MACGAELIC
:
828 enc
= kTextEncodingMacGaelic
;
830 case wxFONTENCODING_MACKEYBOARD
:
831 enc
= kTextEncodingMacKeyboardGlyphs
;
840 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
842 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
846 case kTextEncodingISOLatin1
:
847 enc
= wxFONTENCODING_ISO8859_1
;
849 case kTextEncodingISOLatin2
:
850 enc
= wxFONTENCODING_ISO8859_2
;
852 case kTextEncodingISOLatin3
:
853 enc
= wxFONTENCODING_ISO8859_3
;
855 case kTextEncodingISOLatin4
:
856 enc
= wxFONTENCODING_ISO8859_4
;
858 case kTextEncodingISOLatinCyrillic
:
859 enc
= wxFONTENCODING_ISO8859_5
;
861 case kTextEncodingISOLatinArabic
:
862 enc
= wxFONTENCODING_ISO8859_6
;
864 case kTextEncodingISOLatinGreek
:
865 enc
= wxFONTENCODING_ISO8859_7
;
867 case kTextEncodingISOLatinHebrew
:
868 enc
= wxFONTENCODING_ISO8859_8
;
870 case kTextEncodingISOLatin5
:
871 enc
= wxFONTENCODING_ISO8859_9
;
873 case kTextEncodingISOLatin6
:
874 enc
= wxFONTENCODING_ISO8859_10
;
876 case kTextEncodingISOLatin7
:
877 enc
= wxFONTENCODING_ISO8859_13
;
879 case kTextEncodingISOLatin8
:
880 enc
= wxFONTENCODING_ISO8859_14
;
882 case kTextEncodingISOLatin9
:
883 enc
=wxFONTENCODING_ISO8859_15
;
886 case kTextEncodingKOI8_R
:
887 enc
= wxFONTENCODING_KOI8
;
891 enc = wxFONTENCODING_BULGARIAN;
894 case kTextEncodingDOSLatinUS
:
895 enc
= wxFONTENCODING_CP437
;
897 case kTextEncodingDOSLatin1
:
898 enc
= wxFONTENCODING_CP850
;
900 case kTextEncodingDOSLatin2
:
901 enc
=wxFONTENCODING_CP852
;
903 case kTextEncodingDOSCyrillic
:
904 enc
= wxFONTENCODING_CP855
;
906 case kTextEncodingDOSRussian
:
907 enc
= wxFONTENCODING_CP866
;
909 case kTextEncodingDOSThai
:
910 enc
=wxFONTENCODING_CP874
;
912 case kTextEncodingDOSJapanese
:
913 enc
= wxFONTENCODING_CP932
;
915 case kTextEncodingDOSChineseSimplif
:
916 enc
= wxFONTENCODING_CP936
;
918 case kTextEncodingDOSKorean
:
919 enc
= wxFONTENCODING_CP949
;
921 case kTextEncodingDOSChineseTrad
:
922 enc
= wxFONTENCODING_CP950
;
925 case kTextEncodingWindowsLatin2
:
926 enc
= wxFONTENCODING_CP1250
;
928 case kTextEncodingWindowsCyrillic
:
929 enc
= wxFONTENCODING_CP1251
;
931 case kTextEncodingWindowsLatin1
:
932 enc
= wxFONTENCODING_CP1252
;
934 case kTextEncodingWindowsGreek
:
935 enc
= wxFONTENCODING_CP1253
;
937 case kTextEncodingWindowsLatin5
:
938 enc
= wxFONTENCODING_CP1254
;
940 case kTextEncodingWindowsHebrew
:
941 enc
= wxFONTENCODING_CP1255
;
943 case kTextEncodingWindowsArabic
:
944 enc
= wxFONTENCODING_CP1256
;
946 case kTextEncodingWindowsBalticRim
:
947 enc
=wxFONTENCODING_CP1257
;
949 case kTextEncodingEUC_JP
:
950 enc
= wxFONTENCODING_EUC_JP
;
953 case wxFONTENCODING_UTF7 :
954 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
956 case wxFONTENCODING_UTF8 :
957 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
959 case wxFONTENCODING_UTF16BE :
960 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
962 case wxFONTENCODING_UTF16LE :
963 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
965 case wxFONTENCODING_UTF32BE :
966 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
968 case wxFONTENCODING_UTF32LE :
969 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
972 case kTextEncodingMacRoman
:
973 enc
= wxFONTENCODING_MACROMAN
;
975 case kTextEncodingMacJapanese
:
976 enc
= wxFONTENCODING_MACJAPANESE
;
978 case kTextEncodingMacChineseTrad
:
979 enc
= wxFONTENCODING_MACCHINESETRAD
;
981 case kTextEncodingMacKorean
:
982 enc
= wxFONTENCODING_MACKOREAN
;
984 case kTextEncodingMacArabic
:
985 enc
=wxFONTENCODING_MACARABIC
;
987 case kTextEncodingMacHebrew
:
988 enc
= wxFONTENCODING_MACHEBREW
;
990 case kTextEncodingMacGreek
:
991 enc
= wxFONTENCODING_MACGREEK
;
993 case kTextEncodingMacCyrillic
:
994 enc
= wxFONTENCODING_MACCYRILLIC
;
996 case kTextEncodingMacDevanagari
:
997 enc
= wxFONTENCODING_MACDEVANAGARI
;
999 case kTextEncodingMacGurmukhi
:
1000 enc
= wxFONTENCODING_MACGURMUKHI
;
1002 case kTextEncodingMacGujarati
:
1003 enc
= wxFONTENCODING_MACGUJARATI
;
1005 case kTextEncodingMacOriya
:
1006 enc
=wxFONTENCODING_MACORIYA
;
1008 case kTextEncodingMacBengali
:
1009 enc
=wxFONTENCODING_MACBENGALI
;
1011 case kTextEncodingMacTamil
:
1012 enc
= wxFONTENCODING_MACTAMIL
;
1014 case kTextEncodingMacTelugu
:
1015 enc
= wxFONTENCODING_MACTELUGU
;
1017 case kTextEncodingMacKannada
:
1018 enc
= wxFONTENCODING_MACKANNADA
;
1020 case kTextEncodingMacMalayalam
:
1021 enc
= wxFONTENCODING_MACMALAJALAM
;
1023 case kTextEncodingMacSinhalese
:
1024 enc
= wxFONTENCODING_MACSINHALESE
;
1026 case kTextEncodingMacBurmese
:
1027 enc
= wxFONTENCODING_MACBURMESE
;
1029 case kTextEncodingMacKhmer
:
1030 enc
= wxFONTENCODING_MACKHMER
;
1032 case kTextEncodingMacThai
:
1033 enc
= wxFONTENCODING_MACTHAI
;
1035 case kTextEncodingMacLaotian
:
1036 enc
= wxFONTENCODING_MACLAOTIAN
;
1038 case kTextEncodingMacGeorgian
:
1039 enc
= wxFONTENCODING_MACGEORGIAN
;
1041 case kTextEncodingMacArmenian
:
1042 enc
= wxFONTENCODING_MACARMENIAN
;
1044 case kTextEncodingMacChineseSimp
:
1045 enc
= wxFONTENCODING_MACCHINESESIMP
;
1047 case kTextEncodingMacTibetan
:
1048 enc
= wxFONTENCODING_MACTIBETAN
;
1050 case kTextEncodingMacMongolian
:
1051 enc
= wxFONTENCODING_MACMONGOLIAN
;
1053 case kTextEncodingMacEthiopic
:
1054 enc
= wxFONTENCODING_MACETHIOPIC
;
1056 case kTextEncodingMacCentralEurRoman
:
1057 enc
= wxFONTENCODING_MACCENTRALEUR
;
1059 case kTextEncodingMacVietnamese
:
1060 enc
= wxFONTENCODING_MACVIATNAMESE
;
1062 case kTextEncodingMacExtArabic
:
1063 enc
= wxFONTENCODING_MACARABICEXT
;
1065 case kTextEncodingMacSymbol
:
1066 enc
= wxFONTENCODING_MACSYMBOL
;
1068 case kTextEncodingMacDingbats
:
1069 enc
= wxFONTENCODING_MACDINGBATS
;
1071 case kTextEncodingMacTurkish
:
1072 enc
= wxFONTENCODING_MACTURKISH
;
1074 case kTextEncodingMacCroatian
:
1075 enc
= wxFONTENCODING_MACCROATIAN
;
1077 case kTextEncodingMacIcelandic
:
1078 enc
= wxFONTENCODING_MACICELANDIC
;
1080 case kTextEncodingMacRomanian
:
1081 enc
= wxFONTENCODING_MACROMANIAN
;
1083 case kTextEncodingMacCeltic
:
1084 enc
= wxFONTENCODING_MACCELTIC
;
1086 case kTextEncodingMacGaelic
:
1087 enc
= wxFONTENCODING_MACGAELIC
;
1089 case kTextEncodingMacKeyboardGlyphs
:
1090 enc
= wxFONTENCODING_MACKEYBOARD
;
1096 #endif // wxUSE_BASE
1102 // CFStringRefs (Carbon only)
1107 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1108 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1113 wxMacConvertNewlines13To10( &str
) ;
1115 #if SIZEOF_WCHAR_T == 2
1116 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1117 (UniChar
*)str
.wc_str() , str
.Len() );
1119 wxMBConvUTF16BE converter
;
1120 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1121 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1122 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1123 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1124 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1127 #else // not wxUSE_UNICODE
1128 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1129 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1134 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1136 Size cflen
= CFStringGetLength( m_cfs
) ;
1138 wxChar
* buf
= NULL
;
1141 #if SIZEOF_WCHAR_T == 2
1142 buf
= new wxChar
[ cflen
+ 1 ] ;
1143 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1146 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1147 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1149 wxMBConvUTF16BE converter
;
1150 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1151 buf
= new wxChar
[ noChars
+ 1 ] ;
1152 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1157 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1158 '?' , false , NULL
, 0 , &cStrLen
) ;
1159 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1160 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1161 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1166 wxMacConvertNewlines10To13( buf
) ;
1167 wxString
result(buf
) ;
1172 #endif //TARGET_CARBON
1174 void wxMacConvertNewlines13To10( char * data
)
1177 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1184 void wxMacConvertNewlines10To13( char * data
)
1187 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1194 void wxMacConvertNewlines13To10( wxString
* data
)
1196 size_t len
= data
->length() ;
1198 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1201 wxString
temp(*data
) ;
1202 wxStringBuffer
buf(*data
,len
) ;
1203 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1205 wxMacConvertNewlines13To10( buf
) ;
1208 void wxMacConvertNewlines10To13( wxString
* data
)
1210 size_t len
= data
->length() ;
1212 if ( data
->empty() || wxStrchr(data
->c_str(),0x0a)==NULL
)
1215 wxString
temp(*data
) ;
1216 wxStringBuffer
buf(*data
,len
) ;
1217 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1218 wxMacConvertNewlines10To13( buf
) ;
1223 void wxMacConvertNewlines13To10( wxChar
* data
)
1225 wxChar
* buf
= data
;
1226 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1233 void wxMacConvertNewlines10To13( wxChar
* data
)
1235 wxChar
* buf
= data
;
1236 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1244 // ----------------------------------------------------------------------------
1245 // debugging support
1246 // ----------------------------------------------------------------------------
1248 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1250 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1252 #ifndef __MetroNubUtils__
1253 #include "MetroNubUtils.h"
1257 #include <Gestalt.h>
1260 #if TARGET_API_MAC_CARBON
1262 #include <CodeFragments.h>
1264 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1266 ProcPtr gCallUniversalProc_Proc
= NULL
;
1270 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1272 static long fRunOnce
= false;
1274 /* ---------------------------------------------------------------------------
1276 --------------------------------------------------------------------------- */
1278 Boolean
IsMetroNubInstalled()
1285 gMetroNubEntry
= NULL
;
1287 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1289 /* look for MetroNub's Gestalt selector */
1290 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1293 #if TARGET_API_MAC_CARBON
1294 if (gCallUniversalProc_Proc
== NULL
)
1296 CFragConnectionID connectionID
;
1299 ProcPtr symbolAddress
;
1301 CFragSymbolClass symbolClass
;
1303 symbolAddress
= NULL
;
1304 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1305 &connectionID
, &mainAddress
, errorString
);
1309 gCallUniversalProc_Proc
= NULL
;
1313 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1314 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1318 gCallUniversalProc_Proc
= NULL
;
1325 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1327 /* make sure the version of the API is compatible */
1328 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1329 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1330 gMetroNubEntry
= block
; /* success! */
1339 #if TARGET_API_MAC_CARBON
1340 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1342 return (gMetroNubEntry
!= NULL
);
1346 /* ---------------------------------------------------------------------------
1347 IsMWDebuggerRunning [v1 API]
1348 --------------------------------------------------------------------------- */
1350 Boolean
IsMWDebuggerRunning()
1352 if (IsMetroNubInstalled())
1353 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1358 /* ---------------------------------------------------------------------------
1359 AmIBeingMWDebugged [v1 API]
1360 --------------------------------------------------------------------------- */
1362 Boolean
AmIBeingMWDebugged()
1364 if (IsMetroNubInstalled())
1365 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1370 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1372 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1377 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1382 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)