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 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
92 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
94 #ifndef __MetroNubUtils__
95 #include "MetroNubUtils.h"
102 #if TARGET_API_MAC_CARBON
104 #include <CodeFragments.h>
106 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
108 ProcPtr gCallUniversalProc_Proc
= NULL
;
112 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
114 static long fRunOnce
= false;
116 /* ---------------------------------------------------------------------------
118 --------------------------------------------------------------------------- */
120 Boolean
IsMetroNubInstalled()
127 gMetroNubEntry
= NULL
;
129 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
131 /* look for MetroNub's Gestalt selector */
132 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
135 #if TARGET_API_MAC_CARBON
136 if (gCallUniversalProc_Proc
== NULL
)
138 CFragConnectionID connectionID
;
141 ProcPtr symbolAddress
;
143 CFragSymbolClass symbolClass
;
145 symbolAddress
= NULL
;
146 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
147 &connectionID
, &mainAddress
, errorString
);
151 gCallUniversalProc_Proc
= NULL
;
155 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
156 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
160 gCallUniversalProc_Proc
= NULL
;
167 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
169 /* make sure the version of the API is compatible */
170 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
171 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
172 gMetroNubEntry
= block
; /* success! */
181 #if TARGET_API_MAC_CARBON
182 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
184 return (gMetroNubEntry
!= NULL
);
188 /* ---------------------------------------------------------------------------
189 IsMWDebuggerRunning [v1 API]
190 --------------------------------------------------------------------------- */
192 Boolean
IsMWDebuggerRunning()
194 if (IsMetroNubInstalled())
195 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
200 /* ---------------------------------------------------------------------------
201 AmIBeingMWDebugged [v1 API]
202 --------------------------------------------------------------------------- */
204 Boolean
AmIBeingMWDebugged()
206 if (IsMetroNubInstalled())
207 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
212 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
214 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
219 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
224 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
228 // defined in unix/utilsunx.cpp for Mac OS X
230 // get full hostname (with domain name if possible)
231 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
233 return wxGetHostName(buf
, maxSize
);
236 // Get hostname only (without domain name)
237 bool wxGetHostName(wxChar
*buf
, int maxSize
)
239 // Gets Chooser name of user by examining a System resource.
241 const short kComputerNameID
= -16413;
243 short oldResFile
= CurResFile() ;
245 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
246 UseResFile(oldResFile
);
248 if (chooserName
&& *chooserName
)
250 HLock( (Handle
) chooserName
) ;
251 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
252 HUnlock( (Handle
) chooserName
) ;
253 ReleaseResource( (Handle
) chooserName
) ;
254 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
262 // Get user ID e.g. jacs
263 bool wxGetUserId(wxChar
*buf
, int maxSize
)
265 return wxGetUserName( buf
, maxSize
) ;
268 const wxChar
* wxGetHomeDir(wxString
*pstr
)
270 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
271 return pstr
->c_str() ;
274 // Get user name e.g. Stefan Csomor
275 bool wxGetUserName(wxChar
*buf
, int maxSize
)
277 // Gets Chooser name of user by examining a System resource.
279 const short kChooserNameID
= -16096;
281 short oldResFile
= CurResFile() ;
283 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
284 UseResFile(oldResFile
);
286 if (chooserName
&& *chooserName
)
288 HLock( (Handle
) chooserName
) ;
289 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
290 HUnlock( (Handle
) chooserName
) ;
291 ReleaseResource( (Handle
) chooserName
) ;
292 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
300 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
306 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // set the env var name to the given value, return TRUE on success
313 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
315 // TODO : under classic there is no environement support, under X yes
320 // Execute a program in an Interactive Shell
322 bool wxShell(const wxString
& command
)
328 // Shutdown or reboot the PC
329 bool wxShutdown(wxShutdownFlags wFlags
)
335 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
336 long wxGetFreeMemory()
341 void wxUsleep(unsigned long milliseconds
)
343 // TODO remove if we don't encounter any other problemsy
345 clock_t start = clock() ;
349 } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ;
351 wxThread::Sleep( milliseconds
) ;
354 void wxSleep(int nSecs
)
356 wxUsleep(1000*nSecs
);
359 // Consume all events until no more left
364 #endif // !__DARWIN__
372 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
374 static wxToolkitInfo info
;
375 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
376 info
.name
= _T("wxBase");
384 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
386 static wxToolkitInfo info
;
387 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
388 info
.shortName
= _T("mac");
389 info
.name
= _T("wxMac");
390 #ifdef __WXUNIVERSAL__
391 info
.shortName
<< _T("univ");
392 info
.name
<< _T("/wxUniversal");
397 // Reading and writing resources (eg WIN.INI, .Xdefaults)
399 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
408 buf
.Printf(wxT("%.4f"), value
);
410 return wxWriteResource(section
, entry
, buf
, file
);
413 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
416 buf
.Printf(wxT("%ld"), value
);
418 return wxWriteResource(section
, entry
, buf
, file
);
421 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
424 buf
.Printf(wxT("%d"), value
);
426 return wxWriteResource(section
, entry
, buf
, file
);
429 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
435 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
438 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
441 *value
= (float)strtod(s
, NULL
);
448 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
451 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
454 *value
= strtol(s
, NULL
, 10);
461 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
464 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
467 *value
= (int)strtol(s
, NULL
, 10);
473 #endif // wxUSE_RESOURCES
475 int gs_wxBusyCursorCount
= 0;
476 extern wxCursor gMacCurrentCursor
;
477 wxCursor gMacStoredActiveCursor
;
479 // Set the cursor to the busy cursor for all windows
480 void wxBeginBusyCursor(wxCursor
*cursor
)
482 if (gs_wxBusyCursorCount
++ == 0)
484 gMacStoredActiveCursor
= gMacCurrentCursor
;
485 cursor
->MacInstall() ;
487 //else: nothing to do, already set
490 // Restore cursor to normal
491 void wxEndBusyCursor()
493 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
494 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
496 if (--gs_wxBusyCursorCount
== 0)
498 gMacStoredActiveCursor
.MacInstall() ;
499 gMacStoredActiveCursor
= wxNullCursor
;
503 // TRUE if we're between the above two calls
506 return (gs_wxBusyCursorCount
> 0);
513 wxString
wxMacFindFolder( short vol
,
515 Boolean createFolder
)
521 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
524 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
526 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
536 // Check whether this window wants to process messages, e.g. Stop button
537 // in long calculations.
538 bool wxCheckForInterrupt(wxWindow
*wnd
)
544 void wxGetMousePosition( int* x
, int* y
)
549 LocalToGlobal( &pt
) ;
554 // Return TRUE if we have a colour display
555 bool wxColourDisplay()
560 // Returns depth of screen
564 SetRect(&globRect
, -32760, -32760, 32760, 32760);
565 GDHandle theMaxDevice
;
568 theMaxDevice
= GetMaxDevice(&globRect
);
569 if (theMaxDevice
!= nil
)
570 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
575 // Get size of display
576 void wxDisplaySize(int *width
, int *height
)
579 GetQDGlobalsScreenBits( &screenBits
);
582 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
584 if (height
!= NULL
) {
585 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
589 void wxDisplaySizeMM(int *width
, int *height
)
591 wxDisplaySize(width
, height
);
592 // on mac 72 is fixed (at least now ;-)
593 float cvPt2Mm
= 25.4 / 72;
596 *width
= int( *width
* cvPt2Mm
);
598 if (height
!= NULL
) {
599 *height
= int( *height
* cvPt2Mm
);
603 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
606 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
612 *width
= r
.right
- r
.left
;
614 *height
= r
.bottom
- r
.top
;
617 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
619 return wxGenericFindWindowAtPoint(pt
);
626 wxString
wxGetOsDescription()
628 #ifdef WXWIN_OS_DESCRIPTION
629 // use configure generated description if available
630 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
632 return wxT("MacOS") ; //TODO:define further
637 wxChar
*wxGetUserHome (const wxString
& user
)
643 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
653 int pos
= p
.Find(':') ;
654 if ( pos
!= wxNOT_FOUND
) {
663 wxMacStringToPascal( p
, volumeName
) ;
664 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
665 if ( err
== noErr
) {
667 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
670 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
674 return err
== noErr
;
676 #endif // !__DARWIN__
678 //---------------------------------------------------------------------------
679 // wxMac Specific utility functions
680 //---------------------------------------------------------------------------
682 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
684 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
685 int len
= strlen(buf
) ;
690 memcpy( (char*) &to
[1] , buf
, len
) ;
693 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
695 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
699 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
701 TextEncodingBase enc
= 0 ;
702 if ( encoding
== wxFONTENCODING_DEFAULT
)
705 encoding
= wxFont::GetDefaultEncoding() ;
707 encoding
= wxLocale::GetSystemEncoding() ;
713 case wxFONTENCODING_ISO8859_1
:
714 enc
= kTextEncodingISOLatin1
;
716 case wxFONTENCODING_ISO8859_2
:
717 enc
= kTextEncodingISOLatin2
;
719 case wxFONTENCODING_ISO8859_3
:
720 enc
= kTextEncodingISOLatin3
;
722 case wxFONTENCODING_ISO8859_4
:
723 enc
= kTextEncodingISOLatin4
;
725 case wxFONTENCODING_ISO8859_5
:
726 enc
= kTextEncodingISOLatinCyrillic
;
728 case wxFONTENCODING_ISO8859_6
:
729 enc
= kTextEncodingISOLatinArabic
;
731 case wxFONTENCODING_ISO8859_7
:
732 enc
= kTextEncodingISOLatinGreek
;
734 case wxFONTENCODING_ISO8859_8
:
735 enc
= kTextEncodingISOLatinHebrew
;
737 case wxFONTENCODING_ISO8859_9
:
738 enc
= kTextEncodingISOLatin5
;
740 case wxFONTENCODING_ISO8859_10
:
741 enc
= kTextEncodingISOLatin6
;
743 case wxFONTENCODING_ISO8859_13
:
744 enc
= kTextEncodingISOLatin7
;
746 case wxFONTENCODING_ISO8859_14
:
747 enc
= kTextEncodingISOLatin8
;
749 case wxFONTENCODING_ISO8859_15
:
750 enc
= kTextEncodingISOLatin9
;
753 case wxFONTENCODING_KOI8
:
754 enc
= kTextEncodingKOI8_R
;
756 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
757 enc
= kTextEncodingDOSRussian
;
760 case wxFONTENCODING_BULGARIAN :
764 case wxFONTENCODING_CP437
:
765 enc
=kTextEncodingDOSLatinUS
;
767 case wxFONTENCODING_CP850
:
768 enc
= kTextEncodingDOSLatin1
;
770 case wxFONTENCODING_CP852
:
771 enc
= kTextEncodingDOSLatin2
;
773 case wxFONTENCODING_CP855
:
774 enc
= kTextEncodingDOSCyrillic
;
776 case wxFONTENCODING_CP866
:
777 enc
=kTextEncodingDOSRussian
;
779 case wxFONTENCODING_CP874
:
780 enc
= kTextEncodingDOSThai
;
782 case wxFONTENCODING_CP932
:
783 enc
= kTextEncodingDOSJapanese
;
785 case wxFONTENCODING_CP936
:
786 enc
=kTextEncodingDOSChineseSimplif
;
788 case wxFONTENCODING_CP949
:
789 enc
= kTextEncodingDOSKorean
;
791 case wxFONTENCODING_CP950
:
792 enc
= kTextEncodingDOSChineseTrad
;
795 case wxFONTENCODING_CP1250
:
796 enc
= kTextEncodingWindowsLatin2
;
798 case wxFONTENCODING_CP1251
:
799 enc
=kTextEncodingWindowsCyrillic
;
801 case wxFONTENCODING_CP1252
:
802 enc
=kTextEncodingWindowsLatin1
;
804 case wxFONTENCODING_CP1253
:
805 enc
= kTextEncodingWindowsGreek
;
807 case wxFONTENCODING_CP1254
:
808 enc
= kTextEncodingWindowsLatin5
;
810 case wxFONTENCODING_CP1255
:
811 enc
=kTextEncodingWindowsHebrew
;
813 case wxFONTENCODING_CP1256
:
814 enc
=kTextEncodingWindowsArabic
;
816 case wxFONTENCODING_CP1257
:
817 enc
= kTextEncodingWindowsBalticRim
;
820 case wxFONTENCODING_UTF7
:
821 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
823 case wxFONTENCODING_UTF8
:
824 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
826 case wxFONTENCODING_EUC_JP
:
827 enc
= kTextEncodingEUC_JP
;
829 case wxFONTENCODING_UTF16BE
:
830 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
832 case wxFONTENCODING_UTF16LE
:
833 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
835 case wxFONTENCODING_UTF32BE
:
836 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
838 case wxFONTENCODING_UTF32LE
:
839 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
842 case wxFONTENCODING_MACROMAN
:
843 enc
= kTextEncodingMacRoman
;
845 case wxFONTENCODING_MACJAPANESE
:
846 enc
= kTextEncodingMacJapanese
;
848 case wxFONTENCODING_MACCHINESETRAD
:
849 enc
= kTextEncodingMacChineseTrad
;
851 case wxFONTENCODING_MACKOREAN
:
852 enc
= kTextEncodingMacKorean
;
854 case wxFONTENCODING_MACARABIC
:
855 enc
= kTextEncodingMacArabic
;
857 case wxFONTENCODING_MACHEBREW
:
858 enc
= kTextEncodingMacHebrew
;
860 case wxFONTENCODING_MACGREEK
:
861 enc
= kTextEncodingMacGreek
;
863 case wxFONTENCODING_MACCYRILLIC
:
864 enc
= kTextEncodingMacCyrillic
;
866 case wxFONTENCODING_MACDEVANAGARI
:
867 enc
= kTextEncodingMacDevanagari
;
869 case wxFONTENCODING_MACGURMUKHI
:
870 enc
= kTextEncodingMacGurmukhi
;
872 case wxFONTENCODING_MACGUJARATI
:
873 enc
= kTextEncodingMacGujarati
;
875 case wxFONTENCODING_MACORIYA
:
876 enc
= kTextEncodingMacOriya
;
878 case wxFONTENCODING_MACBENGALI
:
879 enc
= kTextEncodingMacBengali
;
881 case wxFONTENCODING_MACTAMIL
:
882 enc
= kTextEncodingMacTamil
;
884 case wxFONTENCODING_MACTELUGU
:
885 enc
= kTextEncodingMacTelugu
;
887 case wxFONTENCODING_MACKANNADA
:
888 enc
= kTextEncodingMacKannada
;
890 case wxFONTENCODING_MACMALAJALAM
:
891 enc
= kTextEncodingMacMalayalam
;
893 case wxFONTENCODING_MACSINHALESE
:
894 enc
= kTextEncodingMacSinhalese
;
896 case wxFONTENCODING_MACBURMESE
:
897 enc
= kTextEncodingMacBurmese
;
899 case wxFONTENCODING_MACKHMER
:
900 enc
= kTextEncodingMacKhmer
;
902 case wxFONTENCODING_MACTHAI
:
903 enc
= kTextEncodingMacThai
;
905 case wxFONTENCODING_MACLAOTIAN
:
906 enc
= kTextEncodingMacLaotian
;
908 case wxFONTENCODING_MACGEORGIAN
:
909 enc
= kTextEncodingMacGeorgian
;
911 case wxFONTENCODING_MACARMENIAN
:
912 enc
= kTextEncodingMacArmenian
;
914 case wxFONTENCODING_MACCHINESESIMP
:
915 enc
= kTextEncodingMacChineseSimp
;
917 case wxFONTENCODING_MACTIBETAN
:
918 enc
= kTextEncodingMacTibetan
;
920 case wxFONTENCODING_MACMONGOLIAN
:
921 enc
= kTextEncodingMacMongolian
;
923 case wxFONTENCODING_MACETHIOPIC
:
924 enc
= kTextEncodingMacEthiopic
;
926 case wxFONTENCODING_MACCENTRALEUR
:
927 enc
= kTextEncodingMacCentralEurRoman
;
929 case wxFONTENCODING_MACVIATNAMESE
:
930 enc
= kTextEncodingMacVietnamese
;
932 case wxFONTENCODING_MACARABICEXT
:
933 enc
= kTextEncodingMacExtArabic
;
935 case wxFONTENCODING_MACSYMBOL
:
936 enc
= kTextEncodingMacSymbol
;
938 case wxFONTENCODING_MACDINGBATS
:
939 enc
= kTextEncodingMacDingbats
;
941 case wxFONTENCODING_MACTURKISH
:
942 enc
= kTextEncodingMacTurkish
;
944 case wxFONTENCODING_MACCROATIAN
:
945 enc
= kTextEncodingMacCroatian
;
947 case wxFONTENCODING_MACICELANDIC
:
948 enc
= kTextEncodingMacIcelandic
;
950 case wxFONTENCODING_MACROMANIAN
:
951 enc
= kTextEncodingMacRomanian
;
953 case wxFONTENCODING_MACCELTIC
:
954 enc
= kTextEncodingMacCeltic
;
956 case wxFONTENCODING_MACGAELIC
:
957 enc
= kTextEncodingMacGaelic
;
959 case wxFONTENCODING_MACKEYBOARD
:
960 enc
= kTextEncodingMacKeyboardGlyphs
;
969 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
971 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
975 case kTextEncodingISOLatin1
:
976 enc
= wxFONTENCODING_ISO8859_1
;
978 case kTextEncodingISOLatin2
:
979 enc
= wxFONTENCODING_ISO8859_2
;
981 case kTextEncodingISOLatin3
:
982 enc
= wxFONTENCODING_ISO8859_3
;
984 case kTextEncodingISOLatin4
:
985 enc
= wxFONTENCODING_ISO8859_4
;
987 case kTextEncodingISOLatinCyrillic
:
988 enc
= wxFONTENCODING_ISO8859_5
;
990 case kTextEncodingISOLatinArabic
:
991 enc
= wxFONTENCODING_ISO8859_6
;
993 case kTextEncodingISOLatinGreek
:
994 enc
= wxFONTENCODING_ISO8859_7
;
996 case kTextEncodingISOLatinHebrew
:
997 enc
= wxFONTENCODING_ISO8859_8
;
999 case kTextEncodingISOLatin5
:
1000 enc
= wxFONTENCODING_ISO8859_9
;
1002 case kTextEncodingISOLatin6
:
1003 enc
= wxFONTENCODING_ISO8859_10
;
1005 case kTextEncodingISOLatin7
:
1006 enc
= wxFONTENCODING_ISO8859_13
;
1008 case kTextEncodingISOLatin8
:
1009 enc
= wxFONTENCODING_ISO8859_14
;
1011 case kTextEncodingISOLatin9
:
1012 enc
=wxFONTENCODING_ISO8859_15
;
1015 case kTextEncodingKOI8_R
:
1016 enc
= wxFONTENCODING_KOI8
;
1020 enc = wxFONTENCODING_BULGARIAN;
1023 case kTextEncodingDOSLatinUS
:
1024 enc
= wxFONTENCODING_CP437
;
1026 case kTextEncodingDOSLatin1
:
1027 enc
= wxFONTENCODING_CP850
;
1029 case kTextEncodingDOSLatin2
:
1030 enc
=wxFONTENCODING_CP852
;
1032 case kTextEncodingDOSCyrillic
:
1033 enc
= wxFONTENCODING_CP855
;
1035 case kTextEncodingDOSRussian
:
1036 enc
= wxFONTENCODING_CP866
;
1038 case kTextEncodingDOSThai
:
1039 enc
=wxFONTENCODING_CP874
;
1041 case kTextEncodingDOSJapanese
:
1042 enc
= wxFONTENCODING_CP932
;
1044 case kTextEncodingDOSChineseSimplif
:
1045 enc
= wxFONTENCODING_CP936
;
1047 case kTextEncodingDOSKorean
:
1048 enc
= wxFONTENCODING_CP949
;
1050 case kTextEncodingDOSChineseTrad
:
1051 enc
= wxFONTENCODING_CP950
;
1054 case kTextEncodingWindowsLatin2
:
1055 enc
= wxFONTENCODING_CP1250
;
1057 case kTextEncodingWindowsCyrillic
:
1058 enc
= wxFONTENCODING_CP1251
;
1060 case kTextEncodingWindowsLatin1
:
1061 enc
= wxFONTENCODING_CP1252
;
1063 case kTextEncodingWindowsGreek
:
1064 enc
= wxFONTENCODING_CP1253
;
1066 case kTextEncodingWindowsLatin5
:
1067 enc
= wxFONTENCODING_CP1254
;
1069 case kTextEncodingWindowsHebrew
:
1070 enc
= wxFONTENCODING_CP1255
;
1072 case kTextEncodingWindowsArabic
:
1073 enc
= wxFONTENCODING_CP1256
;
1075 case kTextEncodingWindowsBalticRim
:
1076 enc
=wxFONTENCODING_CP1257
;
1078 case kTextEncodingEUC_JP
:
1079 enc
= wxFONTENCODING_EUC_JP
;
1082 case wxFONTENCODING_UTF7 :
1083 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1085 case wxFONTENCODING_UTF8 :
1086 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1088 case wxFONTENCODING_UTF16BE :
1089 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1091 case wxFONTENCODING_UTF16LE :
1092 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1094 case wxFONTENCODING_UTF32BE :
1095 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1097 case wxFONTENCODING_UTF32LE :
1098 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1101 case kTextEncodingMacRoman
:
1102 enc
= wxFONTENCODING_MACROMAN
;
1104 case kTextEncodingMacJapanese
:
1105 enc
= wxFONTENCODING_MACJAPANESE
;
1107 case kTextEncodingMacChineseTrad
:
1108 enc
= wxFONTENCODING_MACCHINESETRAD
;
1110 case kTextEncodingMacKorean
:
1111 enc
= wxFONTENCODING_MACKOREAN
;
1113 case kTextEncodingMacArabic
:
1114 enc
=wxFONTENCODING_MACARABIC
;
1116 case kTextEncodingMacHebrew
:
1117 enc
= wxFONTENCODING_MACHEBREW
;
1119 case kTextEncodingMacGreek
:
1120 enc
= wxFONTENCODING_MACGREEK
;
1122 case kTextEncodingMacCyrillic
:
1123 enc
= wxFONTENCODING_MACCYRILLIC
;
1125 case kTextEncodingMacDevanagari
:
1126 enc
= wxFONTENCODING_MACDEVANAGARI
;
1128 case kTextEncodingMacGurmukhi
:
1129 enc
= wxFONTENCODING_MACGURMUKHI
;
1131 case kTextEncodingMacGujarati
:
1132 enc
= wxFONTENCODING_MACGUJARATI
;
1134 case kTextEncodingMacOriya
:
1135 enc
=wxFONTENCODING_MACORIYA
;
1137 case kTextEncodingMacBengali
:
1138 enc
=wxFONTENCODING_MACBENGALI
;
1140 case kTextEncodingMacTamil
:
1141 enc
= wxFONTENCODING_MACTAMIL
;
1143 case kTextEncodingMacTelugu
:
1144 enc
= wxFONTENCODING_MACTELUGU
;
1146 case kTextEncodingMacKannada
:
1147 enc
= wxFONTENCODING_MACKANNADA
;
1149 case kTextEncodingMacMalayalam
:
1150 enc
= wxFONTENCODING_MACMALAJALAM
;
1152 case kTextEncodingMacSinhalese
:
1153 enc
= wxFONTENCODING_MACSINHALESE
;
1155 case kTextEncodingMacBurmese
:
1156 enc
= wxFONTENCODING_MACBURMESE
;
1158 case kTextEncodingMacKhmer
:
1159 enc
= wxFONTENCODING_MACKHMER
;
1161 case kTextEncodingMacThai
:
1162 enc
= wxFONTENCODING_MACTHAI
;
1164 case kTextEncodingMacLaotian
:
1165 enc
= wxFONTENCODING_MACLAOTIAN
;
1167 case kTextEncodingMacGeorgian
:
1168 enc
= wxFONTENCODING_MACGEORGIAN
;
1170 case kTextEncodingMacArmenian
:
1171 enc
= wxFONTENCODING_MACARMENIAN
;
1173 case kTextEncodingMacChineseSimp
:
1174 enc
= wxFONTENCODING_MACCHINESESIMP
;
1176 case kTextEncodingMacTibetan
:
1177 enc
= wxFONTENCODING_MACTIBETAN
;
1179 case kTextEncodingMacMongolian
:
1180 enc
= wxFONTENCODING_MACMONGOLIAN
;
1182 case kTextEncodingMacEthiopic
:
1183 enc
= wxFONTENCODING_MACETHIOPIC
;
1185 case kTextEncodingMacCentralEurRoman
:
1186 enc
= wxFONTENCODING_MACCENTRALEUR
;
1188 case kTextEncodingMacVietnamese
:
1189 enc
= wxFONTENCODING_MACVIATNAMESE
;
1191 case kTextEncodingMacExtArabic
:
1192 enc
= wxFONTENCODING_MACARABICEXT
;
1194 case kTextEncodingMacSymbol
:
1195 enc
= wxFONTENCODING_MACSYMBOL
;
1197 case kTextEncodingMacDingbats
:
1198 enc
= wxFONTENCODING_MACDINGBATS
;
1200 case kTextEncodingMacTurkish
:
1201 enc
= wxFONTENCODING_MACTURKISH
;
1203 case kTextEncodingMacCroatian
:
1204 enc
= wxFONTENCODING_MACCROATIAN
;
1206 case kTextEncodingMacIcelandic
:
1207 enc
= wxFONTENCODING_MACICELANDIC
;
1209 case kTextEncodingMacRomanian
:
1210 enc
= wxFONTENCODING_MACROMANIAN
;
1212 case kTextEncodingMacCeltic
:
1213 enc
= wxFONTENCODING_MACCELTIC
;
1215 case kTextEncodingMacGaelic
:
1216 enc
= wxFONTENCODING_MACGAELIC
;
1218 case kTextEncodingMacKeyboardGlyphs
:
1219 enc
= wxFONTENCODING_MACKEYBOARD
;
1227 // CFStringRefs (Carbon only)
1232 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1233 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1238 wxMacConvertNewlines13To10( &str
) ;
1240 #if SIZEOF_WCHAR_T == 2
1241 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1242 (UniChar
*)str
.wc_str() , str
.Len() );
1244 wxMBConvUTF16BE converter
;
1245 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1246 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1247 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1248 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1249 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1252 #else // not wxUSE_UNICODE
1253 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1254 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1259 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1261 Size cflen
= CFStringGetLength( m_cfs
) ;
1263 wxChar
* buf
= NULL
;
1266 #if SIZEOF_WCHAR_T == 2
1267 buf
= new wxChar
[ cflen
+ 1 ] ;
1268 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1271 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1272 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1274 wxMBConvUTF16BE converter
;
1275 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1276 buf
= new wxChar
[ noChars
+ 1 ] ;
1277 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1282 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1283 '?' , false , NULL
, 0 , &cStrLen
) ;
1284 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1285 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1286 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1291 wxMacConvertNewlines10To13( buf
) ;
1292 wxString
result(buf
) ;
1297 #endif //TARGET_CARBON
1299 void wxMacConvertNewlines13To10( char * data
)
1302 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1309 void wxMacConvertNewlines10To13( char * data
)
1312 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1319 void wxMacConvertNewlines13To10( wxString
* data
)
1321 size_t len
= data
->Length() ;
1323 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1326 wxString
temp(*data
) ;
1327 wxStringBuffer
buf(*data
,len
) ;
1328 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1330 wxMacConvertNewlines13To10( buf
) ;
1333 void wxMacConvertNewlines10To13( wxString
* data
)
1335 size_t len
= data
->Length() ;
1337 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1340 wxString
temp(*data
) ;
1341 wxStringBuffer
buf(*data
,len
) ;
1342 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1343 wxMacConvertNewlines10To13( buf
) ;
1348 void wxMacConvertNewlines13To10( wxChar
* data
)
1350 wxChar
* buf
= data
;
1351 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1358 void wxMacConvertNewlines10To13( wxChar
* data
)
1360 wxChar
* buf
= data
;
1361 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1369 // ----------------------------------------------------------------------------
1370 // Common Event Support
1371 // ----------------------------------------------------------------------------
1374 extern ProcessSerialNumber gAppProcess
;
1378 ProcessSerialNumber psn
;
1380 psn
.highLongOfPSN
= 0 ;
1381 psn
.lowLongOfPSN
= kCurrentProcess
;
1382 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1386 EventRef dummyEvent
;
1387 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1388 kEventAttributeNone
, &dummyEvent
);
1391 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1392 kEventPriorityHigh
);
1395 PostEvent( nullEvent
, 0 ) ;
1400 WakeUpProcess( &gAppProcess
) ;
1404 #endif // wxUSE_BASE
1409 // ----------------------------------------------------------------------------
1410 // Carbon Event Support
1411 // ----------------------------------------------------------------------------
1414 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1416 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1419 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1421 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1424 // ----------------------------------------------------------------------------
1425 // Control Access Support
1426 // ----------------------------------------------------------------------------
1428 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
)
1430 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1433 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
)
1435 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1438 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1440 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1443 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1445 #if TARGET_API_MAC_OSX
1446 return SendEventToEventTargetWithOptions( event
,
1447 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1449 #pragma unused(inOptions)
1450 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1454 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1456 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1457 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1458 return SendEvent( event
, inOptions
) ;
1461 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1464 memset( &command
, 0 , sizeof(command
) ) ;
1465 command
.commandID
= commandID
;
1466 return SendHICommand( command
, inOptions
) ;
1469 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1471 HiliteControl( m_controlRef
, part
) ;
1472 unsigned long finalTicks
;
1473 Delay( ticks
, &finalTicks
) ;
1474 HiliteControl( m_controlRef
, kControlNoPart
) ;