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 // TODO remove if we don't encounter any other problemsy
203 clock_t start = clock() ;
207 } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ;
209 wxThread::Sleep( milliseconds
) ;
212 void wxSleep(int nSecs
)
214 wxUsleep(1000*nSecs
);
217 // Consume all events until no more left
222 #endif // !__DARWIN__
230 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
232 static wxToolkitInfo info
;
233 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
234 info
.name
= _T("wxBase");
242 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
244 static wxToolkitInfo info
;
245 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
246 info
.shortName
= _T("mac");
247 info
.name
= _T("wxMac");
248 #ifdef __WXUNIVERSAL__
249 info
.shortName
<< _T("univ");
250 info
.name
<< _T("/wxUniversal");
255 // Reading and writing resources (eg WIN.INI, .Xdefaults)
257 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
263 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
266 buf
.Printf(wxT("%.4f"), value
);
268 return wxWriteResource(section
, entry
, buf
, file
);
271 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
274 buf
.Printf(wxT("%ld"), value
);
276 return wxWriteResource(section
, entry
, buf
, file
);
279 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
282 buf
.Printf(wxT("%d"), value
);
284 return wxWriteResource(section
, entry
, buf
, file
);
287 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
293 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
296 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
299 *value
= (float)strtod(s
, NULL
);
306 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
309 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
312 *value
= strtol(s
, NULL
, 10);
319 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
322 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
325 *value
= (int)strtol(s
, NULL
, 10);
331 #endif // wxUSE_RESOURCES
333 int gs_wxBusyCursorCount
= 0;
334 extern wxCursor gMacCurrentCursor
;
335 wxCursor gMacStoredActiveCursor
;
337 // Set the cursor to the busy cursor for all windows
338 void wxBeginBusyCursor(wxCursor
*cursor
)
340 if (gs_wxBusyCursorCount
++ == 0)
342 gMacStoredActiveCursor
= gMacCurrentCursor
;
343 cursor
->MacInstall() ;
345 //else: nothing to do, already set
348 // Restore cursor to normal
349 void wxEndBusyCursor()
351 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
352 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
354 if (--gs_wxBusyCursorCount
== 0)
356 gMacStoredActiveCursor
.MacInstall() ;
357 gMacStoredActiveCursor
= wxNullCursor
;
361 // TRUE if we're between the above two calls
364 return (gs_wxBusyCursorCount
> 0);
371 wxString
wxMacFindFolder( short vol
,
373 Boolean createFolder
)
379 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
382 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
384 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
394 // Check whether this window wants to process messages, e.g. Stop button
395 // in long calculations.
396 bool wxCheckForInterrupt(wxWindow
*wnd
)
402 void wxGetMousePosition( int* x
, int* y
)
407 LocalToGlobal( &pt
) ;
412 // Return TRUE if we have a colour display
413 bool wxColourDisplay()
418 // Returns depth of screen
422 SetRect(&globRect
, -32760, -32760, 32760, 32760);
423 GDHandle theMaxDevice
;
426 theMaxDevice
= GetMaxDevice(&globRect
);
427 if (theMaxDevice
!= nil
)
428 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
433 // Get size of display
434 void wxDisplaySize(int *width
, int *height
)
437 GetQDGlobalsScreenBits( &screenBits
);
440 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
442 if (height
!= NULL
) {
443 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
447 void wxDisplaySizeMM(int *width
, int *height
)
449 wxDisplaySize(width
, height
);
450 // on mac 72 is fixed (at least now ;-)
451 float cvPt2Mm
= 25.4 / 72;
454 *width
= int( *width
* cvPt2Mm
);
456 if (height
!= NULL
) {
457 *height
= int( *height
* cvPt2Mm
);
461 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
464 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
470 *width
= r
.right
- r
.left
;
472 *height
= r
.bottom
- r
.top
;
475 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
477 return wxGenericFindWindowAtPoint(pt
);
484 wxString
wxGetOsDescription()
486 #ifdef WXWIN_OS_DESCRIPTION
487 // use configure generated description if available
488 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
490 return wxT("MacOS") ; //TODO:define further
495 wxChar
*wxGetUserHome (const wxString
& user
)
501 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
511 int pos
= p
.Find(':') ;
512 if ( pos
!= wxNOT_FOUND
) {
521 wxMacStringToPascal( p
, volumeName
) ;
522 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
523 if ( err
== noErr
) {
525 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
528 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
532 return err
== noErr
;
534 #endif // !__DARWIN__
536 //---------------------------------------------------------------------------
537 // wxMac Specific utility functions
538 //---------------------------------------------------------------------------
540 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
542 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
543 int len
= strlen(buf
) ;
548 memcpy( (char*) &to
[1] , buf
, len
) ;
551 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
553 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
557 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
559 TextEncodingBase enc
= 0 ;
560 if ( encoding
== wxFONTENCODING_DEFAULT
)
563 encoding
= wxFont::GetDefaultEncoding() ;
565 encoding
= wxLocale::GetSystemEncoding() ;
571 case wxFONTENCODING_ISO8859_1
:
572 enc
= kTextEncodingISOLatin1
;
574 case wxFONTENCODING_ISO8859_2
:
575 enc
= kTextEncodingISOLatin2
;
577 case wxFONTENCODING_ISO8859_3
:
578 enc
= kTextEncodingISOLatin3
;
580 case wxFONTENCODING_ISO8859_4
:
581 enc
= kTextEncodingISOLatin4
;
583 case wxFONTENCODING_ISO8859_5
:
584 enc
= kTextEncodingISOLatinCyrillic
;
586 case wxFONTENCODING_ISO8859_6
:
587 enc
= kTextEncodingISOLatinArabic
;
589 case wxFONTENCODING_ISO8859_7
:
590 enc
= kTextEncodingISOLatinGreek
;
592 case wxFONTENCODING_ISO8859_8
:
593 enc
= kTextEncodingISOLatinHebrew
;
595 case wxFONTENCODING_ISO8859_9
:
596 enc
= kTextEncodingISOLatin5
;
598 case wxFONTENCODING_ISO8859_10
:
599 enc
= kTextEncodingISOLatin6
;
601 case wxFONTENCODING_ISO8859_13
:
602 enc
= kTextEncodingISOLatin7
;
604 case wxFONTENCODING_ISO8859_14
:
605 enc
= kTextEncodingISOLatin8
;
607 case wxFONTENCODING_ISO8859_15
:
608 enc
= kTextEncodingISOLatin9
;
611 case wxFONTENCODING_KOI8
:
612 enc
= kTextEncodingKOI8_R
;
614 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
615 enc
= kTextEncodingDOSRussian
;
618 case wxFONTENCODING_BULGARIAN :
622 case wxFONTENCODING_CP437
:
623 enc
=kTextEncodingDOSLatinUS
;
625 case wxFONTENCODING_CP850
:
626 enc
= kTextEncodingDOSLatin1
;
628 case wxFONTENCODING_CP852
:
629 enc
= kTextEncodingDOSLatin2
;
631 case wxFONTENCODING_CP855
:
632 enc
= kTextEncodingDOSCyrillic
;
634 case wxFONTENCODING_CP866
:
635 enc
=kTextEncodingDOSRussian
;
637 case wxFONTENCODING_CP874
:
638 enc
= kTextEncodingDOSThai
;
640 case wxFONTENCODING_CP932
:
641 enc
= kTextEncodingDOSJapanese
;
643 case wxFONTENCODING_CP936
:
644 enc
=kTextEncodingDOSChineseSimplif
;
646 case wxFONTENCODING_CP949
:
647 enc
= kTextEncodingDOSKorean
;
649 case wxFONTENCODING_CP950
:
650 enc
= kTextEncodingDOSChineseTrad
;
653 case wxFONTENCODING_CP1250
:
654 enc
= kTextEncodingWindowsLatin2
;
656 case wxFONTENCODING_CP1251
:
657 enc
=kTextEncodingWindowsCyrillic
;
659 case wxFONTENCODING_CP1252
:
660 enc
=kTextEncodingWindowsLatin1
;
662 case wxFONTENCODING_CP1253
:
663 enc
= kTextEncodingWindowsGreek
;
665 case wxFONTENCODING_CP1254
:
666 enc
= kTextEncodingWindowsLatin5
;
668 case wxFONTENCODING_CP1255
:
669 enc
=kTextEncodingWindowsHebrew
;
671 case wxFONTENCODING_CP1256
:
672 enc
=kTextEncodingWindowsArabic
;
674 case wxFONTENCODING_CP1257
:
675 enc
= kTextEncodingWindowsBalticRim
;
678 case wxFONTENCODING_UTF7
:
679 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
681 case wxFONTENCODING_UTF8
:
682 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
684 case wxFONTENCODING_EUC_JP
:
685 enc
= kTextEncodingEUC_JP
;
687 case wxFONTENCODING_UTF16BE
:
688 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
690 case wxFONTENCODING_UTF16LE
:
691 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
693 case wxFONTENCODING_UTF32BE
:
694 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
696 case wxFONTENCODING_UTF32LE
:
697 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
700 case wxFONTENCODING_MACROMAN
:
701 enc
= kTextEncodingMacRoman
;
703 case wxFONTENCODING_MACJAPANESE
:
704 enc
= kTextEncodingMacJapanese
;
706 case wxFONTENCODING_MACCHINESETRAD
:
707 enc
= kTextEncodingMacChineseTrad
;
709 case wxFONTENCODING_MACKOREAN
:
710 enc
= kTextEncodingMacKorean
;
712 case wxFONTENCODING_MACARABIC
:
713 enc
= kTextEncodingMacArabic
;
715 case wxFONTENCODING_MACHEBREW
:
716 enc
= kTextEncodingMacHebrew
;
718 case wxFONTENCODING_MACGREEK
:
719 enc
= kTextEncodingMacGreek
;
721 case wxFONTENCODING_MACCYRILLIC
:
722 enc
= kTextEncodingMacCyrillic
;
724 case wxFONTENCODING_MACDEVANAGARI
:
725 enc
= kTextEncodingMacDevanagari
;
727 case wxFONTENCODING_MACGURMUKHI
:
728 enc
= kTextEncodingMacGurmukhi
;
730 case wxFONTENCODING_MACGUJARATI
:
731 enc
= kTextEncodingMacGujarati
;
733 case wxFONTENCODING_MACORIYA
:
734 enc
= kTextEncodingMacOriya
;
736 case wxFONTENCODING_MACBENGALI
:
737 enc
= kTextEncodingMacBengali
;
739 case wxFONTENCODING_MACTAMIL
:
740 enc
= kTextEncodingMacTamil
;
742 case wxFONTENCODING_MACTELUGU
:
743 enc
= kTextEncodingMacTelugu
;
745 case wxFONTENCODING_MACKANNADA
:
746 enc
= kTextEncodingMacKannada
;
748 case wxFONTENCODING_MACMALAJALAM
:
749 enc
= kTextEncodingMacMalayalam
;
751 case wxFONTENCODING_MACSINHALESE
:
752 enc
= kTextEncodingMacSinhalese
;
754 case wxFONTENCODING_MACBURMESE
:
755 enc
= kTextEncodingMacBurmese
;
757 case wxFONTENCODING_MACKHMER
:
758 enc
= kTextEncodingMacKhmer
;
760 case wxFONTENCODING_MACTHAI
:
761 enc
= kTextEncodingMacThai
;
763 case wxFONTENCODING_MACLAOTIAN
:
764 enc
= kTextEncodingMacLaotian
;
766 case wxFONTENCODING_MACGEORGIAN
:
767 enc
= kTextEncodingMacGeorgian
;
769 case wxFONTENCODING_MACARMENIAN
:
770 enc
= kTextEncodingMacArmenian
;
772 case wxFONTENCODING_MACCHINESESIMP
:
773 enc
= kTextEncodingMacChineseSimp
;
775 case wxFONTENCODING_MACTIBETAN
:
776 enc
= kTextEncodingMacTibetan
;
778 case wxFONTENCODING_MACMONGOLIAN
:
779 enc
= kTextEncodingMacMongolian
;
781 case wxFONTENCODING_MACETHIOPIC
:
782 enc
= kTextEncodingMacEthiopic
;
784 case wxFONTENCODING_MACCENTRALEUR
:
785 enc
= kTextEncodingMacCentralEurRoman
;
787 case wxFONTENCODING_MACVIATNAMESE
:
788 enc
= kTextEncodingMacVietnamese
;
790 case wxFONTENCODING_MACARABICEXT
:
791 enc
= kTextEncodingMacExtArabic
;
793 case wxFONTENCODING_MACSYMBOL
:
794 enc
= kTextEncodingMacSymbol
;
796 case wxFONTENCODING_MACDINGBATS
:
797 enc
= kTextEncodingMacDingbats
;
799 case wxFONTENCODING_MACTURKISH
:
800 enc
= kTextEncodingMacTurkish
;
802 case wxFONTENCODING_MACCROATIAN
:
803 enc
= kTextEncodingMacCroatian
;
805 case wxFONTENCODING_MACICELANDIC
:
806 enc
= kTextEncodingMacIcelandic
;
808 case wxFONTENCODING_MACROMANIAN
:
809 enc
= kTextEncodingMacRomanian
;
811 case wxFONTENCODING_MACCELTIC
:
812 enc
= kTextEncodingMacCeltic
;
814 case wxFONTENCODING_MACGAELIC
:
815 enc
= kTextEncodingMacGaelic
;
817 case wxFONTENCODING_MACKEYBOARD
:
818 enc
= kTextEncodingMacKeyboardGlyphs
;
827 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
829 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
833 case kTextEncodingISOLatin1
:
834 enc
= wxFONTENCODING_ISO8859_1
;
836 case kTextEncodingISOLatin2
:
837 enc
= wxFONTENCODING_ISO8859_2
;
839 case kTextEncodingISOLatin3
:
840 enc
= wxFONTENCODING_ISO8859_3
;
842 case kTextEncodingISOLatin4
:
843 enc
= wxFONTENCODING_ISO8859_4
;
845 case kTextEncodingISOLatinCyrillic
:
846 enc
= wxFONTENCODING_ISO8859_5
;
848 case kTextEncodingISOLatinArabic
:
849 enc
= wxFONTENCODING_ISO8859_6
;
851 case kTextEncodingISOLatinGreek
:
852 enc
= wxFONTENCODING_ISO8859_7
;
854 case kTextEncodingISOLatinHebrew
:
855 enc
= wxFONTENCODING_ISO8859_8
;
857 case kTextEncodingISOLatin5
:
858 enc
= wxFONTENCODING_ISO8859_9
;
860 case kTextEncodingISOLatin6
:
861 enc
= wxFONTENCODING_ISO8859_10
;
863 case kTextEncodingISOLatin7
:
864 enc
= wxFONTENCODING_ISO8859_13
;
866 case kTextEncodingISOLatin8
:
867 enc
= wxFONTENCODING_ISO8859_14
;
869 case kTextEncodingISOLatin9
:
870 enc
=wxFONTENCODING_ISO8859_15
;
873 case kTextEncodingKOI8_R
:
874 enc
= wxFONTENCODING_KOI8
;
878 enc = wxFONTENCODING_BULGARIAN;
881 case kTextEncodingDOSLatinUS
:
882 enc
= wxFONTENCODING_CP437
;
884 case kTextEncodingDOSLatin1
:
885 enc
= wxFONTENCODING_CP850
;
887 case kTextEncodingDOSLatin2
:
888 enc
=wxFONTENCODING_CP852
;
890 case kTextEncodingDOSCyrillic
:
891 enc
= wxFONTENCODING_CP855
;
893 case kTextEncodingDOSRussian
:
894 enc
= wxFONTENCODING_CP866
;
896 case kTextEncodingDOSThai
:
897 enc
=wxFONTENCODING_CP874
;
899 case kTextEncodingDOSJapanese
:
900 enc
= wxFONTENCODING_CP932
;
902 case kTextEncodingDOSChineseSimplif
:
903 enc
= wxFONTENCODING_CP936
;
905 case kTextEncodingDOSKorean
:
906 enc
= wxFONTENCODING_CP949
;
908 case kTextEncodingDOSChineseTrad
:
909 enc
= wxFONTENCODING_CP950
;
912 case kTextEncodingWindowsLatin2
:
913 enc
= wxFONTENCODING_CP1250
;
915 case kTextEncodingWindowsCyrillic
:
916 enc
= wxFONTENCODING_CP1251
;
918 case kTextEncodingWindowsLatin1
:
919 enc
= wxFONTENCODING_CP1252
;
921 case kTextEncodingWindowsGreek
:
922 enc
= wxFONTENCODING_CP1253
;
924 case kTextEncodingWindowsLatin5
:
925 enc
= wxFONTENCODING_CP1254
;
927 case kTextEncodingWindowsHebrew
:
928 enc
= wxFONTENCODING_CP1255
;
930 case kTextEncodingWindowsArabic
:
931 enc
= wxFONTENCODING_CP1256
;
933 case kTextEncodingWindowsBalticRim
:
934 enc
=wxFONTENCODING_CP1257
;
936 case kTextEncodingEUC_JP
:
937 enc
= wxFONTENCODING_EUC_JP
;
940 case wxFONTENCODING_UTF7 :
941 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
943 case wxFONTENCODING_UTF8 :
944 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
946 case wxFONTENCODING_UTF16BE :
947 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
949 case wxFONTENCODING_UTF16LE :
950 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
952 case wxFONTENCODING_UTF32BE :
953 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
955 case wxFONTENCODING_UTF32LE :
956 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
959 case kTextEncodingMacRoman
:
960 enc
= wxFONTENCODING_MACROMAN
;
962 case kTextEncodingMacJapanese
:
963 enc
= wxFONTENCODING_MACJAPANESE
;
965 case kTextEncodingMacChineseTrad
:
966 enc
= wxFONTENCODING_MACCHINESETRAD
;
968 case kTextEncodingMacKorean
:
969 enc
= wxFONTENCODING_MACKOREAN
;
971 case kTextEncodingMacArabic
:
972 enc
=wxFONTENCODING_MACARABIC
;
974 case kTextEncodingMacHebrew
:
975 enc
= wxFONTENCODING_MACHEBREW
;
977 case kTextEncodingMacGreek
:
978 enc
= wxFONTENCODING_MACGREEK
;
980 case kTextEncodingMacCyrillic
:
981 enc
= wxFONTENCODING_MACCYRILLIC
;
983 case kTextEncodingMacDevanagari
:
984 enc
= wxFONTENCODING_MACDEVANAGARI
;
986 case kTextEncodingMacGurmukhi
:
987 enc
= wxFONTENCODING_MACGURMUKHI
;
989 case kTextEncodingMacGujarati
:
990 enc
= wxFONTENCODING_MACGUJARATI
;
992 case kTextEncodingMacOriya
:
993 enc
=wxFONTENCODING_MACORIYA
;
995 case kTextEncodingMacBengali
:
996 enc
=wxFONTENCODING_MACBENGALI
;
998 case kTextEncodingMacTamil
:
999 enc
= wxFONTENCODING_MACTAMIL
;
1001 case kTextEncodingMacTelugu
:
1002 enc
= wxFONTENCODING_MACTELUGU
;
1004 case kTextEncodingMacKannada
:
1005 enc
= wxFONTENCODING_MACKANNADA
;
1007 case kTextEncodingMacMalayalam
:
1008 enc
= wxFONTENCODING_MACMALAJALAM
;
1010 case kTextEncodingMacSinhalese
:
1011 enc
= wxFONTENCODING_MACSINHALESE
;
1013 case kTextEncodingMacBurmese
:
1014 enc
= wxFONTENCODING_MACBURMESE
;
1016 case kTextEncodingMacKhmer
:
1017 enc
= wxFONTENCODING_MACKHMER
;
1019 case kTextEncodingMacThai
:
1020 enc
= wxFONTENCODING_MACTHAI
;
1022 case kTextEncodingMacLaotian
:
1023 enc
= wxFONTENCODING_MACLAOTIAN
;
1025 case kTextEncodingMacGeorgian
:
1026 enc
= wxFONTENCODING_MACGEORGIAN
;
1028 case kTextEncodingMacArmenian
:
1029 enc
= wxFONTENCODING_MACARMENIAN
;
1031 case kTextEncodingMacChineseSimp
:
1032 enc
= wxFONTENCODING_MACCHINESESIMP
;
1034 case kTextEncodingMacTibetan
:
1035 enc
= wxFONTENCODING_MACTIBETAN
;
1037 case kTextEncodingMacMongolian
:
1038 enc
= wxFONTENCODING_MACMONGOLIAN
;
1040 case kTextEncodingMacEthiopic
:
1041 enc
= wxFONTENCODING_MACETHIOPIC
;
1043 case kTextEncodingMacCentralEurRoman
:
1044 enc
= wxFONTENCODING_MACCENTRALEUR
;
1046 case kTextEncodingMacVietnamese
:
1047 enc
= wxFONTENCODING_MACVIATNAMESE
;
1049 case kTextEncodingMacExtArabic
:
1050 enc
= wxFONTENCODING_MACARABICEXT
;
1052 case kTextEncodingMacSymbol
:
1053 enc
= wxFONTENCODING_MACSYMBOL
;
1055 case kTextEncodingMacDingbats
:
1056 enc
= wxFONTENCODING_MACDINGBATS
;
1058 case kTextEncodingMacTurkish
:
1059 enc
= wxFONTENCODING_MACTURKISH
;
1061 case kTextEncodingMacCroatian
:
1062 enc
= wxFONTENCODING_MACCROATIAN
;
1064 case kTextEncodingMacIcelandic
:
1065 enc
= wxFONTENCODING_MACICELANDIC
;
1067 case kTextEncodingMacRomanian
:
1068 enc
= wxFONTENCODING_MACROMANIAN
;
1070 case kTextEncodingMacCeltic
:
1071 enc
= wxFONTENCODING_MACCELTIC
;
1073 case kTextEncodingMacGaelic
:
1074 enc
= wxFONTENCODING_MACGAELIC
;
1076 case kTextEncodingMacKeyboardGlyphs
:
1077 enc
= wxFONTENCODING_MACKEYBOARD
;
1083 #endif // wxUSE_BASE
1089 // CFStringRefs (Carbon only)
1094 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1095 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1100 wxMacConvertNewlines13To10( &str
) ;
1102 #if SIZEOF_WCHAR_T == 2
1103 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1104 (UniChar
*)str
.wc_str() , str
.Len() );
1106 wxMBConvUTF16BE converter
;
1107 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1108 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1109 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1110 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1111 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1114 #else // not wxUSE_UNICODE
1115 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1116 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1121 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1123 Size cflen
= CFStringGetLength( m_cfs
) ;
1125 wxChar
* buf
= NULL
;
1128 #if SIZEOF_WCHAR_T == 2
1129 buf
= new wxChar
[ cflen
+ 1 ] ;
1130 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1133 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1134 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1136 wxMBConvUTF16BE converter
;
1137 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1138 buf
= new wxChar
[ noChars
+ 1 ] ;
1139 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1144 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1145 '?' , false , NULL
, 0 , &cStrLen
) ;
1146 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1147 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1148 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1153 wxMacConvertNewlines10To13( buf
) ;
1154 wxString
result(buf
) ;
1159 #endif //TARGET_CARBON
1161 void wxMacConvertNewlines13To10( char * data
)
1164 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1171 void wxMacConvertNewlines10To13( char * data
)
1174 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1181 void wxMacConvertNewlines13To10( wxString
* data
)
1183 size_t len
= data
->Length() ;
1185 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1188 wxString
temp(*data
) ;
1189 wxStringBuffer
buf(*data
,len
) ;
1190 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1192 wxMacConvertNewlines13To10( buf
) ;
1195 void wxMacConvertNewlines10To13( wxString
* data
)
1197 size_t len
= data
->Length() ;
1199 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1202 wxString
temp(*data
) ;
1203 wxStringBuffer
buf(*data
,len
) ;
1204 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1205 wxMacConvertNewlines10To13( buf
) ;
1210 void wxMacConvertNewlines13To10( wxChar
* data
)
1212 wxChar
* buf
= data
;
1213 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1220 void wxMacConvertNewlines10To13( wxChar
* data
)
1222 wxChar
* buf
= data
;
1223 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1231 // ----------------------------------------------------------------------------
1232 // Common Event Support
1233 // ----------------------------------------------------------------------------
1239 extern ProcessSerialNumber gAppProcess
;
1243 ProcessSerialNumber psn
;
1245 psn
.highLongOfPSN
= 0 ;
1246 psn
.lowLongOfPSN
= kCurrentProcess
;
1247 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1251 EventRef dummyEvent
;
1252 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1253 kEventAttributeNone
, &dummyEvent
);
1256 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1257 kEventPriorityHigh
);
1260 PostEvent( nullEvent
, 0 ) ;
1265 WakeUpProcess( &gAppProcess
) ;
1269 #endif // wxUSE_BASE
1274 // ----------------------------------------------------------------------------
1275 // Carbon Event Support
1276 // ----------------------------------------------------------------------------
1279 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1281 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1284 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, void * inData
)
1286 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1289 // ----------------------------------------------------------------------------
1290 // Control Access Support
1291 // ----------------------------------------------------------------------------
1293 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
)
1295 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1298 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
)
1300 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1303 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1305 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1308 // ----------------------------------------------------------------------------
1309 // debugging support
1310 // ----------------------------------------------------------------------------
1312 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
1314 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
1316 #ifndef __MetroNubUtils__
1317 #include "MetroNubUtils.h"
1321 #include <Gestalt.h>
1324 #if TARGET_API_MAC_CARBON
1326 #include <CodeFragments.h>
1328 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
1330 ProcPtr gCallUniversalProc_Proc
= NULL
;
1334 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
1336 static long fRunOnce
= false;
1338 /* ---------------------------------------------------------------------------
1340 --------------------------------------------------------------------------- */
1342 Boolean
IsMetroNubInstalled()
1349 gMetroNubEntry
= NULL
;
1351 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
1353 /* look for MetroNub's Gestalt selector */
1354 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
1357 #if TARGET_API_MAC_CARBON
1358 if (gCallUniversalProc_Proc
== NULL
)
1360 CFragConnectionID connectionID
;
1363 ProcPtr symbolAddress
;
1365 CFragSymbolClass symbolClass
;
1367 symbolAddress
= NULL
;
1368 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
1369 &connectionID
, &mainAddress
, errorString
);
1373 gCallUniversalProc_Proc
= NULL
;
1377 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
1378 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
1382 gCallUniversalProc_Proc
= NULL
;
1389 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
1391 /* make sure the version of the API is compatible */
1392 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
1393 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
1394 gMetroNubEntry
= block
; /* success! */
1403 #if TARGET_API_MAC_CARBON
1404 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
1406 return (gMetroNubEntry
!= NULL
);
1410 /* ---------------------------------------------------------------------------
1411 IsMWDebuggerRunning [v1 API]
1412 --------------------------------------------------------------------------- */
1414 Boolean
IsMWDebuggerRunning()
1416 if (IsMetroNubInstalled())
1417 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
1422 /* ---------------------------------------------------------------------------
1423 AmIBeingMWDebugged [v1 API]
1424 --------------------------------------------------------------------------- */
1426 Boolean
AmIBeingMWDebugged()
1428 if (IsMetroNubInstalled())
1429 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
1434 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1436 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
1441 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
1446 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)