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 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
538 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
539 int len
= strlen(buf
) ;
544 memcpy( (char*) &to
[1] , buf
, len
) ;
547 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
549 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
553 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
555 TextEncodingBase enc
= 0 ;
556 if ( encoding
== wxFONTENCODING_DEFAULT
)
559 encoding
= wxFont::GetDefaultEncoding() ;
561 encoding
= wxLocale::GetSystemEncoding() ;
567 case wxFONTENCODING_ISO8859_1
:
568 enc
= kTextEncodingISOLatin1
;
570 case wxFONTENCODING_ISO8859_2
:
571 enc
= kTextEncodingISOLatin2
;
573 case wxFONTENCODING_ISO8859_3
:
574 enc
= kTextEncodingISOLatin3
;
576 case wxFONTENCODING_ISO8859_4
:
577 enc
= kTextEncodingISOLatin4
;
579 case wxFONTENCODING_ISO8859_5
:
580 enc
= kTextEncodingISOLatinCyrillic
;
582 case wxFONTENCODING_ISO8859_6
:
583 enc
= kTextEncodingISOLatinArabic
;
585 case wxFONTENCODING_ISO8859_7
:
586 enc
= kTextEncodingISOLatinGreek
;
588 case wxFONTENCODING_ISO8859_8
:
589 enc
= kTextEncodingISOLatinHebrew
;
591 case wxFONTENCODING_ISO8859_9
:
592 enc
= kTextEncodingISOLatin5
;
594 case wxFONTENCODING_ISO8859_10
:
595 enc
= kTextEncodingISOLatin6
;
597 case wxFONTENCODING_ISO8859_13
:
598 enc
= kTextEncodingISOLatin7
;
600 case wxFONTENCODING_ISO8859_14
:
601 enc
= kTextEncodingISOLatin8
;
603 case wxFONTENCODING_ISO8859_15
:
604 enc
= kTextEncodingISOLatin9
;
607 case wxFONTENCODING_KOI8
:
608 enc
= kTextEncodingKOI8_R
;
610 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
611 enc
= kTextEncodingDOSRussian
;
614 case wxFONTENCODING_BULGARIAN :
618 case wxFONTENCODING_CP437
:
619 enc
=kTextEncodingDOSLatinUS
;
621 case wxFONTENCODING_CP850
:
622 enc
= kTextEncodingDOSLatin1
;
624 case wxFONTENCODING_CP852
:
625 enc
= kTextEncodingDOSLatin2
;
627 case wxFONTENCODING_CP855
:
628 enc
= kTextEncodingDOSCyrillic
;
630 case wxFONTENCODING_CP866
:
631 enc
=kTextEncodingDOSRussian
;
633 case wxFONTENCODING_CP874
:
634 enc
= kTextEncodingDOSThai
;
636 case wxFONTENCODING_CP932
:
637 enc
= kTextEncodingDOSJapanese
;
639 case wxFONTENCODING_CP936
:
640 enc
=kTextEncodingDOSChineseSimplif
;
642 case wxFONTENCODING_CP949
:
643 enc
= kTextEncodingDOSKorean
;
645 case wxFONTENCODING_CP950
:
646 enc
= kTextEncodingDOSChineseTrad
;
649 case wxFONTENCODING_CP1250
:
650 enc
= kTextEncodingWindowsLatin2
;
652 case wxFONTENCODING_CP1251
:
653 enc
=kTextEncodingWindowsCyrillic
;
655 case wxFONTENCODING_CP1252
:
656 enc
=kTextEncodingWindowsLatin1
;
658 case wxFONTENCODING_CP1253
:
659 enc
= kTextEncodingWindowsGreek
;
661 case wxFONTENCODING_CP1254
:
662 enc
= kTextEncodingWindowsLatin5
;
664 case wxFONTENCODING_CP1255
:
665 enc
=kTextEncodingWindowsHebrew
;
667 case wxFONTENCODING_CP1256
:
668 enc
=kTextEncodingWindowsArabic
;
670 case wxFONTENCODING_CP1257
:
671 enc
= kTextEncodingWindowsBalticRim
;
674 case wxFONTENCODING_UTF7
:
675 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
677 case wxFONTENCODING_UTF8
:
678 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
680 case wxFONTENCODING_EUC_JP
:
681 enc
= kTextEncodingEUC_JP
;
683 case wxFONTENCODING_UTF16BE
:
684 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
686 case wxFONTENCODING_UTF16LE
:
687 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
689 case wxFONTENCODING_UTF32BE
:
690 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
692 case wxFONTENCODING_UTF32LE
:
693 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
696 case wxFONTENCODING_MACROMAN
:
697 enc
= kTextEncodingMacRoman
;
699 case wxFONTENCODING_MACJAPANESE
:
700 enc
= kTextEncodingMacJapanese
;
702 case wxFONTENCODING_MACCHINESETRAD
:
703 enc
= kTextEncodingMacChineseTrad
;
705 case wxFONTENCODING_MACKOREAN
:
706 enc
= kTextEncodingMacKorean
;
708 case wxFONTENCODING_MACARABIC
:
709 enc
= kTextEncodingMacArabic
;
711 case wxFONTENCODING_MACHEBREW
:
712 enc
= kTextEncodingMacHebrew
;
714 case wxFONTENCODING_MACGREEK
:
715 enc
= kTextEncodingMacGreek
;
717 case wxFONTENCODING_MACCYRILLIC
:
718 enc
= kTextEncodingMacCyrillic
;
720 case wxFONTENCODING_MACDEVANAGARI
:
721 enc
= kTextEncodingMacDevanagari
;
723 case wxFONTENCODING_MACGURMUKHI
:
724 enc
= kTextEncodingMacGurmukhi
;
726 case wxFONTENCODING_MACGUJARATI
:
727 enc
= kTextEncodingMacGujarati
;
729 case wxFONTENCODING_MACORIYA
:
730 enc
= kTextEncodingMacOriya
;
732 case wxFONTENCODING_MACBENGALI
:
733 enc
= kTextEncodingMacBengali
;
735 case wxFONTENCODING_MACTAMIL
:
736 enc
= kTextEncodingMacTamil
;
738 case wxFONTENCODING_MACTELUGU
:
739 enc
= kTextEncodingMacTelugu
;
741 case wxFONTENCODING_MACKANNADA
:
742 enc
= kTextEncodingMacKannada
;
744 case wxFONTENCODING_MACMALAJALAM
:
745 enc
= kTextEncodingMacMalayalam
;
747 case wxFONTENCODING_MACSINHALESE
:
748 enc
= kTextEncodingMacSinhalese
;
750 case wxFONTENCODING_MACBURMESE
:
751 enc
= kTextEncodingMacBurmese
;
753 case wxFONTENCODING_MACKHMER
:
754 enc
= kTextEncodingMacKhmer
;
756 case wxFONTENCODING_MACTHAI
:
757 enc
= kTextEncodingMacThai
;
759 case wxFONTENCODING_MACLAOTIAN
:
760 enc
= kTextEncodingMacLaotian
;
762 case wxFONTENCODING_MACGEORGIAN
:
763 enc
= kTextEncodingMacGeorgian
;
765 case wxFONTENCODING_MACARMENIAN
:
766 enc
= kTextEncodingMacArmenian
;
768 case wxFONTENCODING_MACCHINESESIMP
:
769 enc
= kTextEncodingMacChineseSimp
;
771 case wxFONTENCODING_MACTIBETAN
:
772 enc
= kTextEncodingMacTibetan
;
774 case wxFONTENCODING_MACMONGOLIAN
:
775 enc
= kTextEncodingMacMongolian
;
777 case wxFONTENCODING_MACETHIOPIC
:
778 enc
= kTextEncodingMacEthiopic
;
780 case wxFONTENCODING_MACCENTRALEUR
:
781 enc
= kTextEncodingMacCentralEurRoman
;
783 case wxFONTENCODING_MACVIATNAMESE
:
784 enc
= kTextEncodingMacVietnamese
;
786 case wxFONTENCODING_MACARABICEXT
:
787 enc
= kTextEncodingMacExtArabic
;
789 case wxFONTENCODING_MACSYMBOL
:
790 enc
= kTextEncodingMacSymbol
;
792 case wxFONTENCODING_MACDINGBATS
:
793 enc
= kTextEncodingMacDingbats
;
795 case wxFONTENCODING_MACTURKISH
:
796 enc
= kTextEncodingMacTurkish
;
798 case wxFONTENCODING_MACCROATIAN
:
799 enc
= kTextEncodingMacCroatian
;
801 case wxFONTENCODING_MACICELANDIC
:
802 enc
= kTextEncodingMacIcelandic
;
804 case wxFONTENCODING_MACROMANIAN
:
805 enc
= kTextEncodingMacRomanian
;
807 case wxFONTENCODING_MACCELTIC
:
808 enc
= kTextEncodingMacCeltic
;
810 case wxFONTENCODING_MACGAELIC
:
811 enc
= kTextEncodingMacGaelic
;
813 case wxFONTENCODING_MACKEYBOARD
:
814 enc
= kTextEncodingMacKeyboardGlyphs
;
823 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
825 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
829 case kTextEncodingISOLatin1
:
830 enc
= wxFONTENCODING_ISO8859_1
;
832 case kTextEncodingISOLatin2
:
833 enc
= wxFONTENCODING_ISO8859_2
;
835 case kTextEncodingISOLatin3
:
836 enc
= wxFONTENCODING_ISO8859_3
;
838 case kTextEncodingISOLatin4
:
839 enc
= wxFONTENCODING_ISO8859_4
;
841 case kTextEncodingISOLatinCyrillic
:
842 enc
= wxFONTENCODING_ISO8859_5
;
844 case kTextEncodingISOLatinArabic
:
845 enc
= wxFONTENCODING_ISO8859_6
;
847 case kTextEncodingISOLatinGreek
:
848 enc
= wxFONTENCODING_ISO8859_7
;
850 case kTextEncodingISOLatinHebrew
:
851 enc
= wxFONTENCODING_ISO8859_8
;
853 case kTextEncodingISOLatin5
:
854 enc
= wxFONTENCODING_ISO8859_9
;
856 case kTextEncodingISOLatin6
:
857 enc
= wxFONTENCODING_ISO8859_10
;
859 case kTextEncodingISOLatin7
:
860 enc
= wxFONTENCODING_ISO8859_13
;
862 case kTextEncodingISOLatin8
:
863 enc
= wxFONTENCODING_ISO8859_14
;
865 case kTextEncodingISOLatin9
:
866 enc
=wxFONTENCODING_ISO8859_15
;
869 case kTextEncodingKOI8_R
:
870 enc
= wxFONTENCODING_KOI8
;
874 enc = wxFONTENCODING_BULGARIAN;
877 case kTextEncodingDOSLatinUS
:
878 enc
= wxFONTENCODING_CP437
;
880 case kTextEncodingDOSLatin1
:
881 enc
= wxFONTENCODING_CP850
;
883 case kTextEncodingDOSLatin2
:
884 enc
=wxFONTENCODING_CP852
;
886 case kTextEncodingDOSCyrillic
:
887 enc
= wxFONTENCODING_CP855
;
889 case kTextEncodingDOSRussian
:
890 enc
= wxFONTENCODING_CP866
;
892 case kTextEncodingDOSThai
:
893 enc
=wxFONTENCODING_CP874
;
895 case kTextEncodingDOSJapanese
:
896 enc
= wxFONTENCODING_CP932
;
898 case kTextEncodingDOSChineseSimplif
:
899 enc
= wxFONTENCODING_CP936
;
901 case kTextEncodingDOSKorean
:
902 enc
= wxFONTENCODING_CP949
;
904 case kTextEncodingDOSChineseTrad
:
905 enc
= wxFONTENCODING_CP950
;
908 case kTextEncodingWindowsLatin2
:
909 enc
= wxFONTENCODING_CP1250
;
911 case kTextEncodingWindowsCyrillic
:
912 enc
= wxFONTENCODING_CP1251
;
914 case kTextEncodingWindowsLatin1
:
915 enc
= wxFONTENCODING_CP1252
;
917 case kTextEncodingWindowsGreek
:
918 enc
= wxFONTENCODING_CP1253
;
920 case kTextEncodingWindowsLatin5
:
921 enc
= wxFONTENCODING_CP1254
;
923 case kTextEncodingWindowsHebrew
:
924 enc
= wxFONTENCODING_CP1255
;
926 case kTextEncodingWindowsArabic
:
927 enc
= wxFONTENCODING_CP1256
;
929 case kTextEncodingWindowsBalticRim
:
930 enc
=wxFONTENCODING_CP1257
;
932 case kTextEncodingEUC_JP
:
933 enc
= wxFONTENCODING_EUC_JP
;
936 case wxFONTENCODING_UTF7 :
937 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
939 case wxFONTENCODING_UTF8 :
940 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
942 case wxFONTENCODING_UTF16BE :
943 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
945 case wxFONTENCODING_UTF16LE :
946 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
948 case wxFONTENCODING_UTF32BE :
949 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
951 case wxFONTENCODING_UTF32LE :
952 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
955 case kTextEncodingMacRoman
:
956 enc
= wxFONTENCODING_MACROMAN
;
958 case kTextEncodingMacJapanese
:
959 enc
= wxFONTENCODING_MACJAPANESE
;
961 case kTextEncodingMacChineseTrad
:
962 enc
= wxFONTENCODING_MACCHINESETRAD
;
964 case kTextEncodingMacKorean
:
965 enc
= wxFONTENCODING_MACKOREAN
;
967 case kTextEncodingMacArabic
:
968 enc
=wxFONTENCODING_MACARABIC
;
970 case kTextEncodingMacHebrew
:
971 enc
= wxFONTENCODING_MACHEBREW
;
973 case kTextEncodingMacGreek
:
974 enc
= wxFONTENCODING_MACGREEK
;
976 case kTextEncodingMacCyrillic
:
977 enc
= wxFONTENCODING_MACCYRILLIC
;
979 case kTextEncodingMacDevanagari
:
980 enc
= wxFONTENCODING_MACDEVANAGARI
;
982 case kTextEncodingMacGurmukhi
:
983 enc
= wxFONTENCODING_MACGURMUKHI
;
985 case kTextEncodingMacGujarati
:
986 enc
= wxFONTENCODING_MACGUJARATI
;
988 case kTextEncodingMacOriya
:
989 enc
=wxFONTENCODING_MACORIYA
;
991 case kTextEncodingMacBengali
:
992 enc
=wxFONTENCODING_MACBENGALI
;
994 case kTextEncodingMacTamil
:
995 enc
= wxFONTENCODING_MACTAMIL
;
997 case kTextEncodingMacTelugu
:
998 enc
= wxFONTENCODING_MACTELUGU
;
1000 case kTextEncodingMacKannada
:
1001 enc
= wxFONTENCODING_MACKANNADA
;
1003 case kTextEncodingMacMalayalam
:
1004 enc
= wxFONTENCODING_MACMALAJALAM
;
1006 case kTextEncodingMacSinhalese
:
1007 enc
= wxFONTENCODING_MACSINHALESE
;
1009 case kTextEncodingMacBurmese
:
1010 enc
= wxFONTENCODING_MACBURMESE
;
1012 case kTextEncodingMacKhmer
:
1013 enc
= wxFONTENCODING_MACKHMER
;
1015 case kTextEncodingMacThai
:
1016 enc
= wxFONTENCODING_MACTHAI
;
1018 case kTextEncodingMacLaotian
:
1019 enc
= wxFONTENCODING_MACLAOTIAN
;
1021 case kTextEncodingMacGeorgian
:
1022 enc
= wxFONTENCODING_MACGEORGIAN
;
1024 case kTextEncodingMacArmenian
:
1025 enc
= wxFONTENCODING_MACARMENIAN
;
1027 case kTextEncodingMacChineseSimp
:
1028 enc
= wxFONTENCODING_MACCHINESESIMP
;
1030 case kTextEncodingMacTibetan
:
1031 enc
= wxFONTENCODING_MACTIBETAN
;
1033 case kTextEncodingMacMongolian
:
1034 enc
= wxFONTENCODING_MACMONGOLIAN
;
1036 case kTextEncodingMacEthiopic
:
1037 enc
= wxFONTENCODING_MACETHIOPIC
;
1039 case kTextEncodingMacCentralEurRoman
:
1040 enc
= wxFONTENCODING_MACCENTRALEUR
;
1042 case kTextEncodingMacVietnamese
:
1043 enc
= wxFONTENCODING_MACVIATNAMESE
;
1045 case kTextEncodingMacExtArabic
:
1046 enc
= wxFONTENCODING_MACARABICEXT
;
1048 case kTextEncodingMacSymbol
:
1049 enc
= wxFONTENCODING_MACSYMBOL
;
1051 case kTextEncodingMacDingbats
:
1052 enc
= wxFONTENCODING_MACDINGBATS
;
1054 case kTextEncodingMacTurkish
:
1055 enc
= wxFONTENCODING_MACTURKISH
;
1057 case kTextEncodingMacCroatian
:
1058 enc
= wxFONTENCODING_MACCROATIAN
;
1060 case kTextEncodingMacIcelandic
:
1061 enc
= wxFONTENCODING_MACICELANDIC
;
1063 case kTextEncodingMacRomanian
:
1064 enc
= wxFONTENCODING_MACROMANIAN
;
1066 case kTextEncodingMacCeltic
:
1067 enc
= wxFONTENCODING_MACCELTIC
;
1069 case kTextEncodingMacGaelic
:
1070 enc
= wxFONTENCODING_MACGAELIC
;
1072 case kTextEncodingMacKeyboardGlyphs
:
1073 enc
= wxFONTENCODING_MACKEYBOARD
;
1079 #endif // wxUSE_BASE
1085 // CFStringRefs (Carbon only)
1090 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1091 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1096 wxMacConvertNewlines13To10( &str
) ;
1098 #if SIZEOF_WCHAR_T == 2
1099 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1100 (UniChar
*)str
.wc_str() , str
.Len() );
1102 wxMBConvUTF16BE converter
;
1103 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1104 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1105 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1106 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1107 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1110 #else // not wxUSE_UNICODE
1111 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1112 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1117 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1119 Size cflen
= CFStringGetLength( m_cfs
) ;
1121 wxChar
* buf
= NULL
;
1124 #if SIZEOF_WCHAR_T == 2
1125 buf
= new wxChar
[ cflen
+ 1 ] ;
1126 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1129 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1130 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1132 wxMBConvUTF16BE converter
;
1133 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1134 buf
= new wxChar
[ noChars
+ 1 ] ;
1135 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1140 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1141 '?' , false , NULL
, 0 , &cStrLen
) ;
1142 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1143 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1144 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1149 wxMacConvertNewlines10To13( buf
) ;
1150 wxString
result(buf
) ;
1155 #endif //TARGET_CARBON
1157 void wxMacConvertNewlines13To10( char * data
)
1160 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1167 void wxMacConvertNewlines10To13( char * data
)
1170 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1177 void wxMacConvertNewlines13To10( wxString
* data
)
1179 size_t len
= data
->Length() ;
1181 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1184 wxString
temp(*data
) ;
1185 wxStringBuffer
buf(*data
,len
) ;
1186 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1188 wxMacConvertNewlines13To10( buf
) ;
1191 void wxMacConvertNewlines10To13( wxString
* data
)
1193 size_t len
= data
->Length() ;
1195 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1198 wxString
temp(*data
) ;
1199 wxStringBuffer
buf(*data
,len
) ;
1200 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1201 wxMacConvertNewlines10To13( buf
) ;
1206 void wxMacConvertNewlines13To10( wxChar
* data
)
1208 wxChar
* buf
= data
;
1209 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1216 void wxMacConvertNewlines10To13( wxChar
* data
)
1218 wxChar
* buf
= data
;
1219 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1227 // ----------------------------------------------------------------------------
1228 // Carbon Event Support
1229 // ----------------------------------------------------------------------------
1232 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1234 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1237 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, void * inData
)
1239 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1242 // ----------------------------------------------------------------------------
1243 // debugging support
1244 // ----------------------------------------------------------------------------
1246 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1248 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1250 #ifndef __MetroNubUtils__
1251 #include "MetroNubUtils.h"
1255 #include <Gestalt.h>
1258 #if TARGET_API_MAC_CARBON
1260 #include <CodeFragments.h>
1262 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1264 ProcPtr gCallUniversalProc_Proc
= NULL
;
1268 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1270 static long fRunOnce
= false;
1272 /* ---------------------------------------------------------------------------
1274 --------------------------------------------------------------------------- */
1276 Boolean
IsMetroNubInstalled()
1283 gMetroNubEntry
= NULL
;
1285 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1287 /* look for MetroNub's Gestalt selector */
1288 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1291 #if TARGET_API_MAC_CARBON
1292 if (gCallUniversalProc_Proc
== NULL
)
1294 CFragConnectionID connectionID
;
1297 ProcPtr symbolAddress
;
1299 CFragSymbolClass symbolClass
;
1301 symbolAddress
= NULL
;
1302 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1303 &connectionID
, &mainAddress
, errorString
);
1307 gCallUniversalProc_Proc
= NULL
;
1311 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1312 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1316 gCallUniversalProc_Proc
= NULL
;
1323 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1325 /* make sure the version of the API is compatible */
1326 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1327 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1328 gMetroNubEntry
= block
; /* success! */
1337 #if TARGET_API_MAC_CARBON
1338 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1340 return (gMetroNubEntry
!= NULL
);
1344 /* ---------------------------------------------------------------------------
1345 IsMWDebuggerRunning [v1 API]
1346 --------------------------------------------------------------------------- */
1348 Boolean
IsMWDebuggerRunning()
1350 if (IsMetroNubInstalled())
1351 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1356 /* ---------------------------------------------------------------------------
1357 AmIBeingMWDebugged [v1 API]
1358 --------------------------------------------------------------------------- */
1360 Boolean
AmIBeingMWDebugged()
1362 if (IsMetroNubInstalled())
1363 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1368 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1370 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1375 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1380 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)