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 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
466 *width
= r
.right
- r
.left
;
468 *height
= r
.bottom
- r
.top
;
471 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
473 return wxGenericFindWindowAtPoint(pt
);
480 wxString
wxGetOsDescription()
482 #ifdef WXWIN_OS_DESCRIPTION
483 // use configure generated description if available
484 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
486 return wxT("MacOS") ; //TODO:define further
491 wxChar
*wxGetUserHome (const wxString
& user
)
497 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
507 int pos
= p
.Find(':') ;
508 if ( pos
!= wxNOT_FOUND
) {
517 wxMacStringToPascal( p
, volumeName
) ;
518 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
519 if ( err
== noErr
) {
521 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
524 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
528 return err
== noErr
;
530 #endif // !__DARWIN__
532 //---------------------------------------------------------------------------
533 // wxMac Specific utility functions
534 //---------------------------------------------------------------------------
536 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
)
540 window
->MacGetBoundsForControl( pos
, size
, x
, y
, w
, h
) ;
541 Rect bounds
= { y
, x
, y
+h
, x
+w
};
545 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
547 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
548 int len
= strlen(buf
) ;
553 memcpy( (char*) &to
[1] , buf
, len
) ;
556 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
558 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
562 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
564 TextEncodingBase enc
= 0 ;
565 if ( encoding
== wxFONTENCODING_DEFAULT
)
568 encoding
= wxFont::GetDefaultEncoding() ;
570 encoding
= wxLocale::GetSystemEncoding() ;
576 case wxFONTENCODING_ISO8859_1
:
577 enc
= kTextEncodingISOLatin1
;
579 case wxFONTENCODING_ISO8859_2
:
580 enc
= kTextEncodingISOLatin2
;
582 case wxFONTENCODING_ISO8859_3
:
583 enc
= kTextEncodingISOLatin3
;
585 case wxFONTENCODING_ISO8859_4
:
586 enc
= kTextEncodingISOLatin4
;
588 case wxFONTENCODING_ISO8859_5
:
589 enc
= kTextEncodingISOLatinCyrillic
;
591 case wxFONTENCODING_ISO8859_6
:
592 enc
= kTextEncodingISOLatinArabic
;
594 case wxFONTENCODING_ISO8859_7
:
595 enc
= kTextEncodingISOLatinGreek
;
597 case wxFONTENCODING_ISO8859_8
:
598 enc
= kTextEncodingISOLatinHebrew
;
600 case wxFONTENCODING_ISO8859_9
:
601 enc
= kTextEncodingISOLatin5
;
603 case wxFONTENCODING_ISO8859_10
:
604 enc
= kTextEncodingISOLatin6
;
606 case wxFONTENCODING_ISO8859_13
:
607 enc
= kTextEncodingISOLatin7
;
609 case wxFONTENCODING_ISO8859_14
:
610 enc
= kTextEncodingISOLatin8
;
612 case wxFONTENCODING_ISO8859_15
:
613 enc
= kTextEncodingISOLatin9
;
616 case wxFONTENCODING_KOI8
:
617 enc
= kTextEncodingKOI8_R
;
619 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
620 enc
= kTextEncodingDOSRussian
;
623 case wxFONTENCODING_BULGARIAN :
627 case wxFONTENCODING_CP437
:
628 enc
=kTextEncodingDOSLatinUS
;
630 case wxFONTENCODING_CP850
:
631 enc
= kTextEncodingDOSLatin1
;
633 case wxFONTENCODING_CP852
:
634 enc
= kTextEncodingDOSLatin2
;
636 case wxFONTENCODING_CP855
:
637 enc
= kTextEncodingDOSCyrillic
;
639 case wxFONTENCODING_CP866
:
640 enc
=kTextEncodingDOSRussian
;
642 case wxFONTENCODING_CP874
:
643 enc
= kTextEncodingDOSThai
;
645 case wxFONTENCODING_CP932
:
646 enc
= kTextEncodingDOSJapanese
;
648 case wxFONTENCODING_CP936
:
649 enc
=kTextEncodingDOSChineseSimplif
;
651 case wxFONTENCODING_CP949
:
652 enc
= kTextEncodingDOSKorean
;
654 case wxFONTENCODING_CP950
:
655 enc
= kTextEncodingDOSChineseTrad
;
658 case wxFONTENCODING_CP1250
:
659 enc
= kTextEncodingWindowsLatin2
;
661 case wxFONTENCODING_CP1251
:
662 enc
=kTextEncodingWindowsCyrillic
;
664 case wxFONTENCODING_CP1252
:
665 enc
=kTextEncodingWindowsLatin1
;
667 case wxFONTENCODING_CP1253
:
668 enc
= kTextEncodingWindowsGreek
;
670 case wxFONTENCODING_CP1254
:
671 enc
= kTextEncodingWindowsLatin5
;
673 case wxFONTENCODING_CP1255
:
674 enc
=kTextEncodingWindowsHebrew
;
676 case wxFONTENCODING_CP1256
:
677 enc
=kTextEncodingWindowsArabic
;
679 case wxFONTENCODING_CP1257
:
680 enc
= kTextEncodingWindowsBalticRim
;
683 case wxFONTENCODING_UTF7
:
684 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
686 case wxFONTENCODING_UTF8
:
687 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
689 case wxFONTENCODING_EUC_JP
:
690 enc
= kTextEncodingEUC_JP
;
692 case wxFONTENCODING_UTF16BE
:
693 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
695 case wxFONTENCODING_UTF16LE
:
696 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
698 case wxFONTENCODING_UTF32BE
:
699 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
701 case wxFONTENCODING_UTF32LE
:
702 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
705 case wxFONTENCODING_MACROMAN
:
706 enc
= kTextEncodingMacRoman
;
708 case wxFONTENCODING_MACJAPANESE
:
709 enc
= kTextEncodingMacJapanese
;
711 case wxFONTENCODING_MACCHINESETRAD
:
712 enc
= kTextEncodingMacChineseTrad
;
714 case wxFONTENCODING_MACKOREAN
:
715 enc
= kTextEncodingMacKorean
;
717 case wxFONTENCODING_MACARABIC
:
718 enc
= kTextEncodingMacArabic
;
720 case wxFONTENCODING_MACHEBREW
:
721 enc
= kTextEncodingMacHebrew
;
723 case wxFONTENCODING_MACGREEK
:
724 enc
= kTextEncodingMacGreek
;
726 case wxFONTENCODING_MACCYRILLIC
:
727 enc
= kTextEncodingMacCyrillic
;
729 case wxFONTENCODING_MACDEVANAGARI
:
730 enc
= kTextEncodingMacDevanagari
;
732 case wxFONTENCODING_MACGURMUKHI
:
733 enc
= kTextEncodingMacGurmukhi
;
735 case wxFONTENCODING_MACGUJARATI
:
736 enc
= kTextEncodingMacGujarati
;
738 case wxFONTENCODING_MACORIYA
:
739 enc
= kTextEncodingMacOriya
;
741 case wxFONTENCODING_MACBENGALI
:
742 enc
= kTextEncodingMacBengali
;
744 case wxFONTENCODING_MACTAMIL
:
745 enc
= kTextEncodingMacTamil
;
747 case wxFONTENCODING_MACTELUGU
:
748 enc
= kTextEncodingMacTelugu
;
750 case wxFONTENCODING_MACKANNADA
:
751 enc
= kTextEncodingMacKannada
;
753 case wxFONTENCODING_MACMALAJALAM
:
754 enc
= kTextEncodingMacMalayalam
;
756 case wxFONTENCODING_MACSINHALESE
:
757 enc
= kTextEncodingMacSinhalese
;
759 case wxFONTENCODING_MACBURMESE
:
760 enc
= kTextEncodingMacBurmese
;
762 case wxFONTENCODING_MACKHMER
:
763 enc
= kTextEncodingMacKhmer
;
765 case wxFONTENCODING_MACTHAI
:
766 enc
= kTextEncodingMacThai
;
768 case wxFONTENCODING_MACLAOTIAN
:
769 enc
= kTextEncodingMacLaotian
;
771 case wxFONTENCODING_MACGEORGIAN
:
772 enc
= kTextEncodingMacGeorgian
;
774 case wxFONTENCODING_MACARMENIAN
:
775 enc
= kTextEncodingMacArmenian
;
777 case wxFONTENCODING_MACCHINESESIMP
:
778 enc
= kTextEncodingMacChineseSimp
;
780 case wxFONTENCODING_MACTIBETAN
:
781 enc
= kTextEncodingMacTibetan
;
783 case wxFONTENCODING_MACMONGOLIAN
:
784 enc
= kTextEncodingMacMongolian
;
786 case wxFONTENCODING_MACETHIOPIC
:
787 enc
= kTextEncodingMacEthiopic
;
789 case wxFONTENCODING_MACCENTRALEUR
:
790 enc
= kTextEncodingMacCentralEurRoman
;
792 case wxFONTENCODING_MACVIATNAMESE
:
793 enc
= kTextEncodingMacVietnamese
;
795 case wxFONTENCODING_MACARABICEXT
:
796 enc
= kTextEncodingMacExtArabic
;
798 case wxFONTENCODING_MACSYMBOL
:
799 enc
= kTextEncodingMacSymbol
;
801 case wxFONTENCODING_MACDINGBATS
:
802 enc
= kTextEncodingMacDingbats
;
804 case wxFONTENCODING_MACTURKISH
:
805 enc
= kTextEncodingMacTurkish
;
807 case wxFONTENCODING_MACCROATIAN
:
808 enc
= kTextEncodingMacCroatian
;
810 case wxFONTENCODING_MACICELANDIC
:
811 enc
= kTextEncodingMacIcelandic
;
813 case wxFONTENCODING_MACROMANIAN
:
814 enc
= kTextEncodingMacRomanian
;
816 case wxFONTENCODING_MACCELTIC
:
817 enc
= kTextEncodingMacCeltic
;
819 case wxFONTENCODING_MACGAELIC
:
820 enc
= kTextEncodingMacGaelic
;
822 case wxFONTENCODING_MACKEYBOARD
:
823 enc
= kTextEncodingMacKeyboardGlyphs
;
832 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
834 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
838 case kTextEncodingISOLatin1
:
839 enc
= wxFONTENCODING_ISO8859_1
;
841 case kTextEncodingISOLatin2
:
842 enc
= wxFONTENCODING_ISO8859_2
;
844 case kTextEncodingISOLatin3
:
845 enc
= wxFONTENCODING_ISO8859_3
;
847 case kTextEncodingISOLatin4
:
848 enc
= wxFONTENCODING_ISO8859_4
;
850 case kTextEncodingISOLatinCyrillic
:
851 enc
= wxFONTENCODING_ISO8859_5
;
853 case kTextEncodingISOLatinArabic
:
854 enc
= wxFONTENCODING_ISO8859_6
;
856 case kTextEncodingISOLatinGreek
:
857 enc
= wxFONTENCODING_ISO8859_7
;
859 case kTextEncodingISOLatinHebrew
:
860 enc
= wxFONTENCODING_ISO8859_8
;
862 case kTextEncodingISOLatin5
:
863 enc
= wxFONTENCODING_ISO8859_9
;
865 case kTextEncodingISOLatin6
:
866 enc
= wxFONTENCODING_ISO8859_10
;
868 case kTextEncodingISOLatin7
:
869 enc
= wxFONTENCODING_ISO8859_13
;
871 case kTextEncodingISOLatin8
:
872 enc
= wxFONTENCODING_ISO8859_14
;
874 case kTextEncodingISOLatin9
:
875 enc
=wxFONTENCODING_ISO8859_15
;
878 case kTextEncodingKOI8_R
:
879 enc
= wxFONTENCODING_KOI8
;
883 enc = wxFONTENCODING_BULGARIAN;
886 case kTextEncodingDOSLatinUS
:
887 enc
= wxFONTENCODING_CP437
;
889 case kTextEncodingDOSLatin1
:
890 enc
= wxFONTENCODING_CP850
;
892 case kTextEncodingDOSLatin2
:
893 enc
=wxFONTENCODING_CP852
;
895 case kTextEncodingDOSCyrillic
:
896 enc
= wxFONTENCODING_CP855
;
898 case kTextEncodingDOSRussian
:
899 enc
= wxFONTENCODING_CP866
;
901 case kTextEncodingDOSThai
:
902 enc
=wxFONTENCODING_CP874
;
904 case kTextEncodingDOSJapanese
:
905 enc
= wxFONTENCODING_CP932
;
907 case kTextEncodingDOSChineseSimplif
:
908 enc
= wxFONTENCODING_CP936
;
910 case kTextEncodingDOSKorean
:
911 enc
= wxFONTENCODING_CP949
;
913 case kTextEncodingDOSChineseTrad
:
914 enc
= wxFONTENCODING_CP950
;
917 case kTextEncodingWindowsLatin2
:
918 enc
= wxFONTENCODING_CP1250
;
920 case kTextEncodingWindowsCyrillic
:
921 enc
= wxFONTENCODING_CP1251
;
923 case kTextEncodingWindowsLatin1
:
924 enc
= wxFONTENCODING_CP1252
;
926 case kTextEncodingWindowsGreek
:
927 enc
= wxFONTENCODING_CP1253
;
929 case kTextEncodingWindowsLatin5
:
930 enc
= wxFONTENCODING_CP1254
;
932 case kTextEncodingWindowsHebrew
:
933 enc
= wxFONTENCODING_CP1255
;
935 case kTextEncodingWindowsArabic
:
936 enc
= wxFONTENCODING_CP1256
;
938 case kTextEncodingWindowsBalticRim
:
939 enc
=wxFONTENCODING_CP1257
;
941 case kTextEncodingEUC_JP
:
942 enc
= wxFONTENCODING_EUC_JP
;
945 case wxFONTENCODING_UTF7 :
946 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
948 case wxFONTENCODING_UTF8 :
949 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
951 case wxFONTENCODING_UTF16BE :
952 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
954 case wxFONTENCODING_UTF16LE :
955 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
957 case wxFONTENCODING_UTF32BE :
958 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
960 case wxFONTENCODING_UTF32LE :
961 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
964 case kTextEncodingMacRoman
:
965 enc
= wxFONTENCODING_MACROMAN
;
967 case kTextEncodingMacJapanese
:
968 enc
= wxFONTENCODING_MACJAPANESE
;
970 case kTextEncodingMacChineseTrad
:
971 enc
= wxFONTENCODING_MACCHINESETRAD
;
973 case kTextEncodingMacKorean
:
974 enc
= wxFONTENCODING_MACKOREAN
;
976 case kTextEncodingMacArabic
:
977 enc
=wxFONTENCODING_MACARABIC
;
979 case kTextEncodingMacHebrew
:
980 enc
= wxFONTENCODING_MACHEBREW
;
982 case kTextEncodingMacGreek
:
983 enc
= wxFONTENCODING_MACGREEK
;
985 case kTextEncodingMacCyrillic
:
986 enc
= wxFONTENCODING_MACCYRILLIC
;
988 case kTextEncodingMacDevanagari
:
989 enc
= wxFONTENCODING_MACDEVANAGARI
;
991 case kTextEncodingMacGurmukhi
:
992 enc
= wxFONTENCODING_MACGURMUKHI
;
994 case kTextEncodingMacGujarati
:
995 enc
= wxFONTENCODING_MACGUJARATI
;
997 case kTextEncodingMacOriya
:
998 enc
=wxFONTENCODING_MACORIYA
;
1000 case kTextEncodingMacBengali
:
1001 enc
=wxFONTENCODING_MACBENGALI
;
1003 case kTextEncodingMacTamil
:
1004 enc
= wxFONTENCODING_MACTAMIL
;
1006 case kTextEncodingMacTelugu
:
1007 enc
= wxFONTENCODING_MACTELUGU
;
1009 case kTextEncodingMacKannada
:
1010 enc
= wxFONTENCODING_MACKANNADA
;
1012 case kTextEncodingMacMalayalam
:
1013 enc
= wxFONTENCODING_MACMALAJALAM
;
1015 case kTextEncodingMacSinhalese
:
1016 enc
= wxFONTENCODING_MACSINHALESE
;
1018 case kTextEncodingMacBurmese
:
1019 enc
= wxFONTENCODING_MACBURMESE
;
1021 case kTextEncodingMacKhmer
:
1022 enc
= wxFONTENCODING_MACKHMER
;
1024 case kTextEncodingMacThai
:
1025 enc
= wxFONTENCODING_MACTHAI
;
1027 case kTextEncodingMacLaotian
:
1028 enc
= wxFONTENCODING_MACLAOTIAN
;
1030 case kTextEncodingMacGeorgian
:
1031 enc
= wxFONTENCODING_MACGEORGIAN
;
1033 case kTextEncodingMacArmenian
:
1034 enc
= wxFONTENCODING_MACARMENIAN
;
1036 case kTextEncodingMacChineseSimp
:
1037 enc
= wxFONTENCODING_MACCHINESESIMP
;
1039 case kTextEncodingMacTibetan
:
1040 enc
= wxFONTENCODING_MACTIBETAN
;
1042 case kTextEncodingMacMongolian
:
1043 enc
= wxFONTENCODING_MACMONGOLIAN
;
1045 case kTextEncodingMacEthiopic
:
1046 enc
= wxFONTENCODING_MACETHIOPIC
;
1048 case kTextEncodingMacCentralEurRoman
:
1049 enc
= wxFONTENCODING_MACCENTRALEUR
;
1051 case kTextEncodingMacVietnamese
:
1052 enc
= wxFONTENCODING_MACVIATNAMESE
;
1054 case kTextEncodingMacExtArabic
:
1055 enc
= wxFONTENCODING_MACARABICEXT
;
1057 case kTextEncodingMacSymbol
:
1058 enc
= wxFONTENCODING_MACSYMBOL
;
1060 case kTextEncodingMacDingbats
:
1061 enc
= wxFONTENCODING_MACDINGBATS
;
1063 case kTextEncodingMacTurkish
:
1064 enc
= wxFONTENCODING_MACTURKISH
;
1066 case kTextEncodingMacCroatian
:
1067 enc
= wxFONTENCODING_MACCROATIAN
;
1069 case kTextEncodingMacIcelandic
:
1070 enc
= wxFONTENCODING_MACICELANDIC
;
1072 case kTextEncodingMacRomanian
:
1073 enc
= wxFONTENCODING_MACROMANIAN
;
1075 case kTextEncodingMacCeltic
:
1076 enc
= wxFONTENCODING_MACCELTIC
;
1078 case kTextEncodingMacGaelic
:
1079 enc
= wxFONTENCODING_MACGAELIC
;
1081 case kTextEncodingMacKeyboardGlyphs
:
1082 enc
= wxFONTENCODING_MACKEYBOARD
;
1088 #endif // wxUSE_BASE
1094 // CFStringRefs (Carbon only)
1099 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1100 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1105 wxMacConvertNewlines13To10( &str
) ;
1107 #if SIZEOF_WCHAR_T == 2
1108 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1109 (UniChar
*)str
.wc_str() , str
.Len() );
1111 wxMBConvUTF16BE converter
;
1112 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1113 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1114 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1115 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1116 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1119 #else // not wxUSE_UNICODE
1120 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1121 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1126 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1128 Size cflen
= CFStringGetLength( m_cfs
) ;
1130 wxChar
* buf
= NULL
;
1133 #if SIZEOF_WCHAR_T == 2
1134 buf
= new wxChar
[ cflen
+ 1 ] ;
1135 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1138 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1139 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1141 wxMBConvUTF16BE converter
;
1142 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1143 buf
= new wxChar
[ noChars
+ 1 ] ;
1144 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1149 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1150 '?' , false , NULL
, 0 , &cStrLen
) ;
1151 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1152 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1153 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1158 wxMacConvertNewlines10To13( buf
) ;
1159 wxString
result(buf
) ;
1164 #endif //TARGET_CARBON
1166 void wxMacConvertNewlines13To10( char * data
)
1169 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1176 void wxMacConvertNewlines10To13( char * data
)
1179 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1186 void wxMacConvertNewlines13To10( wxString
* data
)
1188 size_t len
= data
->Length() ;
1190 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1193 wxString
temp(*data
) ;
1194 wxStringBuffer
buf(*data
,len
) ;
1195 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1197 wxMacConvertNewlines13To10( buf
) ;
1200 void wxMacConvertNewlines10To13( wxString
* data
)
1202 size_t len
= data
->Length() ;
1204 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1207 wxString
temp(*data
) ;
1208 wxStringBuffer
buf(*data
,len
) ;
1209 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1210 wxMacConvertNewlines10To13( buf
) ;
1215 void wxMacConvertNewlines13To10( wxChar
* data
)
1217 wxChar
* buf
= data
;
1218 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1225 void wxMacConvertNewlines10To13( wxChar
* data
)
1227 wxChar
* buf
= data
;
1228 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1236 // ----------------------------------------------------------------------------
1237 // Carbon Event Support
1238 // ----------------------------------------------------------------------------
1241 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1243 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1246 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, void * inData
)
1248 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1251 // ----------------------------------------------------------------------------
1252 // debugging support
1253 // ----------------------------------------------------------------------------
1255 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1257 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1259 #ifndef __MetroNubUtils__
1260 #include "MetroNubUtils.h"
1264 #include <Gestalt.h>
1267 #if TARGET_API_MAC_CARBON
1269 #include <CodeFragments.h>
1271 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1273 ProcPtr gCallUniversalProc_Proc
= NULL
;
1277 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1279 static long fRunOnce
= false;
1281 /* ---------------------------------------------------------------------------
1283 --------------------------------------------------------------------------- */
1285 Boolean
IsMetroNubInstalled()
1292 gMetroNubEntry
= NULL
;
1294 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1296 /* look for MetroNub's Gestalt selector */
1297 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1300 #if TARGET_API_MAC_CARBON
1301 if (gCallUniversalProc_Proc
== NULL
)
1303 CFragConnectionID connectionID
;
1306 ProcPtr symbolAddress
;
1308 CFragSymbolClass symbolClass
;
1310 symbolAddress
= NULL
;
1311 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1312 &connectionID
, &mainAddress
, errorString
);
1316 gCallUniversalProc_Proc
= NULL
;
1320 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1321 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1325 gCallUniversalProc_Proc
= NULL
;
1332 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1334 /* make sure the version of the API is compatible */
1335 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1336 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1337 gMetroNubEntry
= block
; /* success! */
1346 #if TARGET_API_MAC_CARBON
1347 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1349 return (gMetroNubEntry
!= NULL
);
1353 /* ---------------------------------------------------------------------------
1354 IsMWDebuggerRunning [v1 API]
1355 --------------------------------------------------------------------------- */
1357 Boolean
IsMWDebuggerRunning()
1359 if (IsMetroNubInstalled())
1360 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1365 /* ---------------------------------------------------------------------------
1366 AmIBeingMWDebugged [v1 API]
1367 --------------------------------------------------------------------------- */
1369 Boolean
AmIBeingMWDebugged()
1371 if (IsMetroNubInstalled())
1372 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1377 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1379 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1384 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1389 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)