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 ) ;
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
87 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
89 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
91 #ifndef __MetroNubUtils__
92 #include "MetroNubUtils.h"
99 #if TARGET_API_MAC_CARBON
101 #include <CodeFragments.h>
103 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
105 ProcPtr gCallUniversalProc_Proc
= NULL
;
109 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
111 static long fRunOnce
= false;
113 /* ---------------------------------------------------------------------------
115 --------------------------------------------------------------------------- */
117 Boolean
IsMetroNubInstalled()
124 gMetroNubEntry
= NULL
;
126 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
128 /* look for MetroNub's Gestalt selector */
129 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
132 #if TARGET_API_MAC_CARBON
133 if (gCallUniversalProc_Proc
== NULL
)
135 CFragConnectionID connectionID
;
138 ProcPtr symbolAddress
;
140 CFragSymbolClass symbolClass
;
142 symbolAddress
= NULL
;
143 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
144 &connectionID
, &mainAddress
, errorString
);
148 gCallUniversalProc_Proc
= NULL
;
152 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
153 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
157 gCallUniversalProc_Proc
= NULL
;
164 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
166 /* make sure the version of the API is compatible */
167 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
168 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
169 gMetroNubEntry
= block
; /* success! */
178 #if TARGET_API_MAC_CARBON
179 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
181 return (gMetroNubEntry
!= NULL
);
185 /* ---------------------------------------------------------------------------
186 IsMWDebuggerRunning [v1 API]
187 --------------------------------------------------------------------------- */
189 Boolean
IsMWDebuggerRunning()
191 if (IsMetroNubInstalled())
192 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
197 /* ---------------------------------------------------------------------------
198 AmIBeingMWDebugged [v1 API]
199 --------------------------------------------------------------------------- */
201 Boolean
AmIBeingMWDebugged()
203 if (IsMetroNubInstalled())
204 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
209 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
211 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
216 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
221 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
226 // defined in unix/utilsunx.cpp for Mac OS X
228 // get full hostname (with domain name if possible)
229 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
231 return wxGetHostName(buf
, maxSize
);
234 // Get hostname only (without domain name)
235 bool wxGetHostName(wxChar
*buf
, int maxSize
)
237 // Gets Chooser name of user by examining a System resource.
239 const short kComputerNameID
= -16413;
241 short oldResFile
= CurResFile() ;
243 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
244 UseResFile(oldResFile
);
246 if (chooserName
&& *chooserName
)
248 HLock( (Handle
) chooserName
) ;
249 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
250 HUnlock( (Handle
) chooserName
) ;
251 ReleaseResource( (Handle
) chooserName
) ;
252 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
260 // Get user ID e.g. jacs
261 bool wxGetUserId(wxChar
*buf
, int maxSize
)
263 return wxGetUserName( buf
, maxSize
) ;
266 const wxChar
* wxGetHomeDir(wxString
*pstr
)
268 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
269 return pstr
->c_str() ;
272 // Get user name e.g. Stefan Csomor
273 bool wxGetUserName(wxChar
*buf
, int maxSize
)
275 // Gets Chooser name of user by examining a System resource.
277 const short kChooserNameID
= -16096;
279 short oldResFile
= CurResFile() ;
281 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
282 UseResFile(oldResFile
);
284 if (chooserName
&& *chooserName
)
286 HLock( (Handle
) chooserName
) ;
287 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
288 HUnlock( (Handle
) chooserName
) ;
289 ReleaseResource( (Handle
) chooserName
) ;
290 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
298 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
304 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
306 // TODO : under classic there is no environement support, under X yes
310 // set the env var name to the given value, return TRUE on success
311 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
313 // TODO : under classic there is no environement support, under X yes
318 // Execute a program in an Interactive Shell
320 bool wxShell(const wxString
& command
)
326 // Shutdown or reboot the PC
327 bool wxShutdown(wxShutdownFlags wFlags
)
333 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
334 long wxGetFreeMemory()
339 void wxUsleep(unsigned long milliseconds
)
341 // TODO remove if we don't encounter any other problemsy
343 clock_t start = clock() ;
347 } while( clock() - start < milliseconds / 1000.0 * CLOCKS_PER_SEC ) ;
349 wxThread::Sleep( milliseconds
) ;
352 void wxSleep(int nSecs
)
354 wxUsleep(1000*nSecs
);
357 // Consume all events until no more left
362 #endif // !__DARWIN__
370 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
372 static wxToolkitInfo info
;
373 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
374 info
.name
= _T("wxBase");
382 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
384 static wxToolkitInfo info
;
385 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
386 info
.shortName
= _T("mac");
387 info
.name
= _T("wxMac");
388 #ifdef __WXUNIVERSAL__
389 info
.shortName
<< _T("univ");
390 info
.name
<< _T("/wxUniversal");
395 // Reading and writing resources (eg WIN.INI, .Xdefaults)
397 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
403 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
406 buf
.Printf(wxT("%.4f"), value
);
408 return wxWriteResource(section
, entry
, buf
, file
);
411 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
414 buf
.Printf(wxT("%ld"), value
);
416 return wxWriteResource(section
, entry
, buf
, file
);
419 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
422 buf
.Printf(wxT("%d"), value
);
424 return wxWriteResource(section
, entry
, buf
, file
);
427 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
433 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
436 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
439 *value
= (float)strtod(s
, NULL
);
446 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
449 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
452 *value
= strtol(s
, NULL
, 10);
459 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
462 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
465 *value
= (int)strtol(s
, NULL
, 10);
471 #endif // wxUSE_RESOURCES
473 int gs_wxBusyCursorCount
= 0;
474 extern wxCursor gMacCurrentCursor
;
475 wxCursor gMacStoredActiveCursor
;
477 // Set the cursor to the busy cursor for all windows
478 void wxBeginBusyCursor(wxCursor
*cursor
)
480 if (gs_wxBusyCursorCount
++ == 0)
482 gMacStoredActiveCursor
= gMacCurrentCursor
;
483 cursor
->MacInstall() ;
485 //else: nothing to do, already set
488 // Restore cursor to normal
489 void wxEndBusyCursor()
491 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
492 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
494 if (--gs_wxBusyCursorCount
== 0)
496 gMacStoredActiveCursor
.MacInstall() ;
497 gMacStoredActiveCursor
= wxNullCursor
;
501 // TRUE if we're between the above two calls
504 return (gs_wxBusyCursorCount
> 0);
511 wxString
wxMacFindFolder( short vol
,
513 Boolean createFolder
)
519 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
522 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
524 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
534 // Check whether this window wants to process messages, e.g. Stop button
535 // in long calculations.
536 bool wxCheckForInterrupt(wxWindow
*wnd
)
542 void wxGetMousePosition( int* x
, int* y
)
547 LocalToGlobal( &pt
) ;
552 // Return TRUE if we have a colour display
553 bool wxColourDisplay()
558 // Returns depth of screen
562 SetRect(&globRect
, -32760, -32760, 32760, 32760);
563 GDHandle theMaxDevice
;
566 theMaxDevice
= GetMaxDevice(&globRect
);
567 if (theMaxDevice
!= nil
)
568 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
573 // Get size of display
574 void wxDisplaySize(int *width
, int *height
)
577 GetQDGlobalsScreenBits( &screenBits
);
580 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
582 if (height
!= NULL
) {
583 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
587 void wxDisplaySizeMM(int *width
, int *height
)
589 wxDisplaySize(width
, height
);
590 // on mac 72 is fixed (at least now ;-)
591 float cvPt2Mm
= 25.4 / 72;
594 *width
= int( *width
* cvPt2Mm
);
596 if (height
!= NULL
) {
597 *height
= int( *height
* cvPt2Mm
);
601 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
604 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
610 *width
= r
.right
- r
.left
;
612 *height
= r
.bottom
- r
.top
;
615 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
617 return wxGenericFindWindowAtPoint(pt
);
624 wxString
wxGetOsDescription()
626 #ifdef WXWIN_OS_DESCRIPTION
627 // use configure generated description if available
628 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
630 return wxT("MacOS") ; //TODO:define further
635 wxChar
*wxGetUserHome (const wxString
& user
)
641 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
651 int pos
= p
.Find(':') ;
652 if ( pos
!= wxNOT_FOUND
) {
661 wxMacStringToPascal( p
, volumeName
) ;
662 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
663 if ( err
== noErr
) {
665 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
668 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
672 return err
== noErr
;
674 #endif // !__DARWIN__
676 //---------------------------------------------------------------------------
677 // wxMac Specific utility functions
678 //---------------------------------------------------------------------------
680 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
682 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
683 int len
= strlen(buf
) ;
688 memcpy( (char*) &to
[1] , buf
, len
) ;
691 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
693 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
697 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
699 TextEncodingBase enc
= 0 ;
700 if ( encoding
== wxFONTENCODING_DEFAULT
)
703 encoding
= wxFont::GetDefaultEncoding() ;
705 encoding
= wxLocale::GetSystemEncoding() ;
711 case wxFONTENCODING_ISO8859_1
:
712 enc
= kTextEncodingISOLatin1
;
714 case wxFONTENCODING_ISO8859_2
:
715 enc
= kTextEncodingISOLatin2
;
717 case wxFONTENCODING_ISO8859_3
:
718 enc
= kTextEncodingISOLatin3
;
720 case wxFONTENCODING_ISO8859_4
:
721 enc
= kTextEncodingISOLatin4
;
723 case wxFONTENCODING_ISO8859_5
:
724 enc
= kTextEncodingISOLatinCyrillic
;
726 case wxFONTENCODING_ISO8859_6
:
727 enc
= kTextEncodingISOLatinArabic
;
729 case wxFONTENCODING_ISO8859_7
:
730 enc
= kTextEncodingISOLatinGreek
;
732 case wxFONTENCODING_ISO8859_8
:
733 enc
= kTextEncodingISOLatinHebrew
;
735 case wxFONTENCODING_ISO8859_9
:
736 enc
= kTextEncodingISOLatin5
;
738 case wxFONTENCODING_ISO8859_10
:
739 enc
= kTextEncodingISOLatin6
;
741 case wxFONTENCODING_ISO8859_13
:
742 enc
= kTextEncodingISOLatin7
;
744 case wxFONTENCODING_ISO8859_14
:
745 enc
= kTextEncodingISOLatin8
;
747 case wxFONTENCODING_ISO8859_15
:
748 enc
= kTextEncodingISOLatin9
;
751 case wxFONTENCODING_KOI8
:
752 enc
= kTextEncodingKOI8_R
;
754 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
755 enc
= kTextEncodingDOSRussian
;
758 case wxFONTENCODING_BULGARIAN :
762 case wxFONTENCODING_CP437
:
763 enc
=kTextEncodingDOSLatinUS
;
765 case wxFONTENCODING_CP850
:
766 enc
= kTextEncodingDOSLatin1
;
768 case wxFONTENCODING_CP852
:
769 enc
= kTextEncodingDOSLatin2
;
771 case wxFONTENCODING_CP855
:
772 enc
= kTextEncodingDOSCyrillic
;
774 case wxFONTENCODING_CP866
:
775 enc
=kTextEncodingDOSRussian
;
777 case wxFONTENCODING_CP874
:
778 enc
= kTextEncodingDOSThai
;
780 case wxFONTENCODING_CP932
:
781 enc
= kTextEncodingDOSJapanese
;
783 case wxFONTENCODING_CP936
:
784 enc
=kTextEncodingDOSChineseSimplif
;
786 case wxFONTENCODING_CP949
:
787 enc
= kTextEncodingDOSKorean
;
789 case wxFONTENCODING_CP950
:
790 enc
= kTextEncodingDOSChineseTrad
;
793 case wxFONTENCODING_CP1250
:
794 enc
= kTextEncodingWindowsLatin2
;
796 case wxFONTENCODING_CP1251
:
797 enc
=kTextEncodingWindowsCyrillic
;
799 case wxFONTENCODING_CP1252
:
800 enc
=kTextEncodingWindowsLatin1
;
802 case wxFONTENCODING_CP1253
:
803 enc
= kTextEncodingWindowsGreek
;
805 case wxFONTENCODING_CP1254
:
806 enc
= kTextEncodingWindowsLatin5
;
808 case wxFONTENCODING_CP1255
:
809 enc
=kTextEncodingWindowsHebrew
;
811 case wxFONTENCODING_CP1256
:
812 enc
=kTextEncodingWindowsArabic
;
814 case wxFONTENCODING_CP1257
:
815 enc
= kTextEncodingWindowsBalticRim
;
818 case wxFONTENCODING_UTF7
:
819 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
821 case wxFONTENCODING_UTF8
:
822 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
824 case wxFONTENCODING_EUC_JP
:
825 enc
= kTextEncodingEUC_JP
;
827 case wxFONTENCODING_UTF16BE
:
828 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
830 case wxFONTENCODING_UTF16LE
:
831 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
833 case wxFONTENCODING_UTF32BE
:
834 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
836 case wxFONTENCODING_UTF32LE
:
837 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
840 case wxFONTENCODING_MACROMAN
:
841 enc
= kTextEncodingMacRoman
;
843 case wxFONTENCODING_MACJAPANESE
:
844 enc
= kTextEncodingMacJapanese
;
846 case wxFONTENCODING_MACCHINESETRAD
:
847 enc
= kTextEncodingMacChineseTrad
;
849 case wxFONTENCODING_MACKOREAN
:
850 enc
= kTextEncodingMacKorean
;
852 case wxFONTENCODING_MACARABIC
:
853 enc
= kTextEncodingMacArabic
;
855 case wxFONTENCODING_MACHEBREW
:
856 enc
= kTextEncodingMacHebrew
;
858 case wxFONTENCODING_MACGREEK
:
859 enc
= kTextEncodingMacGreek
;
861 case wxFONTENCODING_MACCYRILLIC
:
862 enc
= kTextEncodingMacCyrillic
;
864 case wxFONTENCODING_MACDEVANAGARI
:
865 enc
= kTextEncodingMacDevanagari
;
867 case wxFONTENCODING_MACGURMUKHI
:
868 enc
= kTextEncodingMacGurmukhi
;
870 case wxFONTENCODING_MACGUJARATI
:
871 enc
= kTextEncodingMacGujarati
;
873 case wxFONTENCODING_MACORIYA
:
874 enc
= kTextEncodingMacOriya
;
876 case wxFONTENCODING_MACBENGALI
:
877 enc
= kTextEncodingMacBengali
;
879 case wxFONTENCODING_MACTAMIL
:
880 enc
= kTextEncodingMacTamil
;
882 case wxFONTENCODING_MACTELUGU
:
883 enc
= kTextEncodingMacTelugu
;
885 case wxFONTENCODING_MACKANNADA
:
886 enc
= kTextEncodingMacKannada
;
888 case wxFONTENCODING_MACMALAJALAM
:
889 enc
= kTextEncodingMacMalayalam
;
891 case wxFONTENCODING_MACSINHALESE
:
892 enc
= kTextEncodingMacSinhalese
;
894 case wxFONTENCODING_MACBURMESE
:
895 enc
= kTextEncodingMacBurmese
;
897 case wxFONTENCODING_MACKHMER
:
898 enc
= kTextEncodingMacKhmer
;
900 case wxFONTENCODING_MACTHAI
:
901 enc
= kTextEncodingMacThai
;
903 case wxFONTENCODING_MACLAOTIAN
:
904 enc
= kTextEncodingMacLaotian
;
906 case wxFONTENCODING_MACGEORGIAN
:
907 enc
= kTextEncodingMacGeorgian
;
909 case wxFONTENCODING_MACARMENIAN
:
910 enc
= kTextEncodingMacArmenian
;
912 case wxFONTENCODING_MACCHINESESIMP
:
913 enc
= kTextEncodingMacChineseSimp
;
915 case wxFONTENCODING_MACTIBETAN
:
916 enc
= kTextEncodingMacTibetan
;
918 case wxFONTENCODING_MACMONGOLIAN
:
919 enc
= kTextEncodingMacMongolian
;
921 case wxFONTENCODING_MACETHIOPIC
:
922 enc
= kTextEncodingMacEthiopic
;
924 case wxFONTENCODING_MACCENTRALEUR
:
925 enc
= kTextEncodingMacCentralEurRoman
;
927 case wxFONTENCODING_MACVIATNAMESE
:
928 enc
= kTextEncodingMacVietnamese
;
930 case wxFONTENCODING_MACARABICEXT
:
931 enc
= kTextEncodingMacExtArabic
;
933 case wxFONTENCODING_MACSYMBOL
:
934 enc
= kTextEncodingMacSymbol
;
936 case wxFONTENCODING_MACDINGBATS
:
937 enc
= kTextEncodingMacDingbats
;
939 case wxFONTENCODING_MACTURKISH
:
940 enc
= kTextEncodingMacTurkish
;
942 case wxFONTENCODING_MACCROATIAN
:
943 enc
= kTextEncodingMacCroatian
;
945 case wxFONTENCODING_MACICELANDIC
:
946 enc
= kTextEncodingMacIcelandic
;
948 case wxFONTENCODING_MACROMANIAN
:
949 enc
= kTextEncodingMacRomanian
;
951 case wxFONTENCODING_MACCELTIC
:
952 enc
= kTextEncodingMacCeltic
;
954 case wxFONTENCODING_MACGAELIC
:
955 enc
= kTextEncodingMacGaelic
;
957 case wxFONTENCODING_MACKEYBOARD
:
958 enc
= kTextEncodingMacKeyboardGlyphs
;
967 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
969 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
973 case kTextEncodingISOLatin1
:
974 enc
= wxFONTENCODING_ISO8859_1
;
976 case kTextEncodingISOLatin2
:
977 enc
= wxFONTENCODING_ISO8859_2
;
979 case kTextEncodingISOLatin3
:
980 enc
= wxFONTENCODING_ISO8859_3
;
982 case kTextEncodingISOLatin4
:
983 enc
= wxFONTENCODING_ISO8859_4
;
985 case kTextEncodingISOLatinCyrillic
:
986 enc
= wxFONTENCODING_ISO8859_5
;
988 case kTextEncodingISOLatinArabic
:
989 enc
= wxFONTENCODING_ISO8859_6
;
991 case kTextEncodingISOLatinGreek
:
992 enc
= wxFONTENCODING_ISO8859_7
;
994 case kTextEncodingISOLatinHebrew
:
995 enc
= wxFONTENCODING_ISO8859_8
;
997 case kTextEncodingISOLatin5
:
998 enc
= wxFONTENCODING_ISO8859_9
;
1000 case kTextEncodingISOLatin6
:
1001 enc
= wxFONTENCODING_ISO8859_10
;
1003 case kTextEncodingISOLatin7
:
1004 enc
= wxFONTENCODING_ISO8859_13
;
1006 case kTextEncodingISOLatin8
:
1007 enc
= wxFONTENCODING_ISO8859_14
;
1009 case kTextEncodingISOLatin9
:
1010 enc
=wxFONTENCODING_ISO8859_15
;
1013 case kTextEncodingKOI8_R
:
1014 enc
= wxFONTENCODING_KOI8
;
1018 enc = wxFONTENCODING_BULGARIAN;
1021 case kTextEncodingDOSLatinUS
:
1022 enc
= wxFONTENCODING_CP437
;
1024 case kTextEncodingDOSLatin1
:
1025 enc
= wxFONTENCODING_CP850
;
1027 case kTextEncodingDOSLatin2
:
1028 enc
=wxFONTENCODING_CP852
;
1030 case kTextEncodingDOSCyrillic
:
1031 enc
= wxFONTENCODING_CP855
;
1033 case kTextEncodingDOSRussian
:
1034 enc
= wxFONTENCODING_CP866
;
1036 case kTextEncodingDOSThai
:
1037 enc
=wxFONTENCODING_CP874
;
1039 case kTextEncodingDOSJapanese
:
1040 enc
= wxFONTENCODING_CP932
;
1042 case kTextEncodingDOSChineseSimplif
:
1043 enc
= wxFONTENCODING_CP936
;
1045 case kTextEncodingDOSKorean
:
1046 enc
= wxFONTENCODING_CP949
;
1048 case kTextEncodingDOSChineseTrad
:
1049 enc
= wxFONTENCODING_CP950
;
1052 case kTextEncodingWindowsLatin2
:
1053 enc
= wxFONTENCODING_CP1250
;
1055 case kTextEncodingWindowsCyrillic
:
1056 enc
= wxFONTENCODING_CP1251
;
1058 case kTextEncodingWindowsLatin1
:
1059 enc
= wxFONTENCODING_CP1252
;
1061 case kTextEncodingWindowsGreek
:
1062 enc
= wxFONTENCODING_CP1253
;
1064 case kTextEncodingWindowsLatin5
:
1065 enc
= wxFONTENCODING_CP1254
;
1067 case kTextEncodingWindowsHebrew
:
1068 enc
= wxFONTENCODING_CP1255
;
1070 case kTextEncodingWindowsArabic
:
1071 enc
= wxFONTENCODING_CP1256
;
1073 case kTextEncodingWindowsBalticRim
:
1074 enc
=wxFONTENCODING_CP1257
;
1076 case kTextEncodingEUC_JP
:
1077 enc
= wxFONTENCODING_EUC_JP
;
1080 case wxFONTENCODING_UTF7 :
1081 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1083 case wxFONTENCODING_UTF8 :
1084 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1086 case wxFONTENCODING_UTF16BE :
1087 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1089 case wxFONTENCODING_UTF16LE :
1090 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1092 case wxFONTENCODING_UTF32BE :
1093 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1095 case wxFONTENCODING_UTF32LE :
1096 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1099 case kTextEncodingMacRoman
:
1100 enc
= wxFONTENCODING_MACROMAN
;
1102 case kTextEncodingMacJapanese
:
1103 enc
= wxFONTENCODING_MACJAPANESE
;
1105 case kTextEncodingMacChineseTrad
:
1106 enc
= wxFONTENCODING_MACCHINESETRAD
;
1108 case kTextEncodingMacKorean
:
1109 enc
= wxFONTENCODING_MACKOREAN
;
1111 case kTextEncodingMacArabic
:
1112 enc
=wxFONTENCODING_MACARABIC
;
1114 case kTextEncodingMacHebrew
:
1115 enc
= wxFONTENCODING_MACHEBREW
;
1117 case kTextEncodingMacGreek
:
1118 enc
= wxFONTENCODING_MACGREEK
;
1120 case kTextEncodingMacCyrillic
:
1121 enc
= wxFONTENCODING_MACCYRILLIC
;
1123 case kTextEncodingMacDevanagari
:
1124 enc
= wxFONTENCODING_MACDEVANAGARI
;
1126 case kTextEncodingMacGurmukhi
:
1127 enc
= wxFONTENCODING_MACGURMUKHI
;
1129 case kTextEncodingMacGujarati
:
1130 enc
= wxFONTENCODING_MACGUJARATI
;
1132 case kTextEncodingMacOriya
:
1133 enc
=wxFONTENCODING_MACORIYA
;
1135 case kTextEncodingMacBengali
:
1136 enc
=wxFONTENCODING_MACBENGALI
;
1138 case kTextEncodingMacTamil
:
1139 enc
= wxFONTENCODING_MACTAMIL
;
1141 case kTextEncodingMacTelugu
:
1142 enc
= wxFONTENCODING_MACTELUGU
;
1144 case kTextEncodingMacKannada
:
1145 enc
= wxFONTENCODING_MACKANNADA
;
1147 case kTextEncodingMacMalayalam
:
1148 enc
= wxFONTENCODING_MACMALAJALAM
;
1150 case kTextEncodingMacSinhalese
:
1151 enc
= wxFONTENCODING_MACSINHALESE
;
1153 case kTextEncodingMacBurmese
:
1154 enc
= wxFONTENCODING_MACBURMESE
;
1156 case kTextEncodingMacKhmer
:
1157 enc
= wxFONTENCODING_MACKHMER
;
1159 case kTextEncodingMacThai
:
1160 enc
= wxFONTENCODING_MACTHAI
;
1162 case kTextEncodingMacLaotian
:
1163 enc
= wxFONTENCODING_MACLAOTIAN
;
1165 case kTextEncodingMacGeorgian
:
1166 enc
= wxFONTENCODING_MACGEORGIAN
;
1168 case kTextEncodingMacArmenian
:
1169 enc
= wxFONTENCODING_MACARMENIAN
;
1171 case kTextEncodingMacChineseSimp
:
1172 enc
= wxFONTENCODING_MACCHINESESIMP
;
1174 case kTextEncodingMacTibetan
:
1175 enc
= wxFONTENCODING_MACTIBETAN
;
1177 case kTextEncodingMacMongolian
:
1178 enc
= wxFONTENCODING_MACMONGOLIAN
;
1180 case kTextEncodingMacEthiopic
:
1181 enc
= wxFONTENCODING_MACETHIOPIC
;
1183 case kTextEncodingMacCentralEurRoman
:
1184 enc
= wxFONTENCODING_MACCENTRALEUR
;
1186 case kTextEncodingMacVietnamese
:
1187 enc
= wxFONTENCODING_MACVIATNAMESE
;
1189 case kTextEncodingMacExtArabic
:
1190 enc
= wxFONTENCODING_MACARABICEXT
;
1192 case kTextEncodingMacSymbol
:
1193 enc
= wxFONTENCODING_MACSYMBOL
;
1195 case kTextEncodingMacDingbats
:
1196 enc
= wxFONTENCODING_MACDINGBATS
;
1198 case kTextEncodingMacTurkish
:
1199 enc
= wxFONTENCODING_MACTURKISH
;
1201 case kTextEncodingMacCroatian
:
1202 enc
= wxFONTENCODING_MACCROATIAN
;
1204 case kTextEncodingMacIcelandic
:
1205 enc
= wxFONTENCODING_MACICELANDIC
;
1207 case kTextEncodingMacRomanian
:
1208 enc
= wxFONTENCODING_MACROMANIAN
;
1210 case kTextEncodingMacCeltic
:
1211 enc
= wxFONTENCODING_MACCELTIC
;
1213 case kTextEncodingMacGaelic
:
1214 enc
= wxFONTENCODING_MACGAELIC
;
1216 case kTextEncodingMacKeyboardGlyphs
:
1217 enc
= wxFONTENCODING_MACKEYBOARD
;
1225 // CFStringRefs (Carbon only)
1230 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1231 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1236 wxMacConvertNewlines13To10( &str
) ;
1238 #if SIZEOF_WCHAR_T == 2
1239 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1240 (UniChar
*)str
.wc_str() , str
.Len() );
1242 wxMBConvUTF16BE converter
;
1243 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1244 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1245 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1246 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1247 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1250 #else // not wxUSE_UNICODE
1251 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1252 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1257 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1259 Size cflen
= CFStringGetLength( m_cfs
) ;
1261 wxChar
* buf
= NULL
;
1264 #if SIZEOF_WCHAR_T == 2
1265 buf
= new wxChar
[ cflen
+ 1 ] ;
1266 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1269 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1270 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1272 wxMBConvUTF16BE converter
;
1273 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1274 buf
= new wxChar
[ noChars
+ 1 ] ;
1275 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1280 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1281 '?' , false , NULL
, 0 , &cStrLen
) ;
1282 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1283 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1284 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1289 wxMacConvertNewlines10To13( buf
) ;
1290 wxString
result(buf
) ;
1295 #endif //TARGET_CARBON
1297 void wxMacConvertNewlines13To10( char * data
)
1300 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1307 void wxMacConvertNewlines10To13( char * data
)
1310 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1317 void wxMacConvertNewlines13To10( wxString
* data
)
1319 size_t len
= data
->Length() ;
1321 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1324 wxString
temp(*data
) ;
1325 wxStringBuffer
buf(*data
,len
) ;
1326 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1328 wxMacConvertNewlines13To10( buf
) ;
1331 void wxMacConvertNewlines10To13( wxString
* data
)
1333 size_t len
= data
->Length() ;
1335 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1338 wxString
temp(*data
) ;
1339 wxStringBuffer
buf(*data
,len
) ;
1340 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1341 wxMacConvertNewlines10To13( buf
) ;
1346 void wxMacConvertNewlines13To10( wxChar
* data
)
1348 wxChar
* buf
= data
;
1349 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1356 void wxMacConvertNewlines10To13( wxChar
* data
)
1358 wxChar
* buf
= data
;
1359 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1367 // ----------------------------------------------------------------------------
1368 // Common Event Support
1369 // ----------------------------------------------------------------------------
1372 extern ProcessSerialNumber gAppProcess
;
1376 ProcessSerialNumber psn
;
1378 psn
.highLongOfPSN
= 0 ;
1379 psn
.lowLongOfPSN
= kCurrentProcess
;
1380 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1384 EventRef dummyEvent
;
1385 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1386 kEventAttributeNone
, &dummyEvent
);
1389 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1390 kEventPriorityHigh
);
1393 PostEvent( nullEvent
, 0 ) ;
1398 WakeUpProcess( &gAppProcess
) ;
1402 #endif // wxUSE_BASE
1407 // ----------------------------------------------------------------------------
1408 // Carbon Event Support
1409 // ----------------------------------------------------------------------------
1412 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1414 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1417 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1419 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1422 // ----------------------------------------------------------------------------
1423 // Control Access Support
1424 // ----------------------------------------------------------------------------
1426 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
)
1428 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1431 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
)
1433 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1436 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1438 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1441 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1443 #if TARGET_API_MAC_OSX
1444 return SendEventToEventTargetWithOptions( event
,
1445 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1447 #pragma unused(inOptions)
1448 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1452 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1454 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1455 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1456 return SendEvent( event
, inOptions
) ;
1459 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1462 memset( &command
, 0 , sizeof(command
) ) ;
1463 command
.commandID
= commandID
;
1464 return SendHICommand( command
, inOptions
) ;
1467 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1469 HiliteControl( m_controlRef
, part
) ;
1470 unsigned long finalTicks
;
1471 Delay( ticks
, &finalTicks
) ;
1472 HiliteControl( m_controlRef
, kControlNoPart
) ;