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()
343 void wxMicroSleep(unsigned long microseconds
)
345 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
346 MPDelayUntil( & wakeup
);
349 void wxMilliSleep(unsigned long milliseconds
)
351 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
352 MPDelayUntil( & wakeup
);
355 void wxSleep(int nSecs
)
357 wxMilliSleep(1000*nSecs
);
362 // Consume all events until no more left
367 #endif // !__DARWIN__
375 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
377 static wxToolkitInfo info
;
378 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
379 info
.name
= _T("wxBase");
387 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
389 static wxToolkitInfo info
;
390 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
391 info
.shortName
= _T("mac");
392 info
.name
= _T("wxMac");
393 #ifdef __WXUNIVERSAL__
394 info
.shortName
<< _T("univ");
395 info
.name
<< _T("/wxUniversal");
400 // Reading and writing resources (eg WIN.INI, .Xdefaults)
402 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
408 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
411 buf
.Printf(wxT("%.4f"), value
);
413 return wxWriteResource(section
, entry
, buf
, file
);
416 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
419 buf
.Printf(wxT("%ld"), value
);
421 return wxWriteResource(section
, entry
, buf
, file
);
424 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
427 buf
.Printf(wxT("%d"), value
);
429 return wxWriteResource(section
, entry
, buf
, file
);
432 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
438 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
441 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
444 *value
= (float)strtod(s
, NULL
);
451 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
454 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
457 *value
= strtol(s
, NULL
, 10);
464 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
467 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
470 *value
= (int)strtol(s
, NULL
, 10);
476 #endif // wxUSE_RESOURCES
478 int gs_wxBusyCursorCount
= 0;
479 extern wxCursor gMacCurrentCursor
;
480 wxCursor gMacStoredActiveCursor
;
482 // Set the cursor to the busy cursor for all windows
483 void wxBeginBusyCursor(wxCursor
*cursor
)
485 if (gs_wxBusyCursorCount
++ == 0)
487 gMacStoredActiveCursor
= gMacCurrentCursor
;
488 cursor
->MacInstall() ;
490 //else: nothing to do, already set
493 // Restore cursor to normal
494 void wxEndBusyCursor()
496 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
497 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
499 if (--gs_wxBusyCursorCount
== 0)
501 gMacStoredActiveCursor
.MacInstall() ;
502 gMacStoredActiveCursor
= wxNullCursor
;
506 // TRUE if we're between the above two calls
509 return (gs_wxBusyCursorCount
> 0);
516 wxString
wxMacFindFolder( short vol
,
518 Boolean createFolder
)
524 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
527 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
529 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
539 // Check whether this window wants to process messages, e.g. Stop button
540 // in long calculations.
541 bool wxCheckForInterrupt(wxWindow
*wnd
)
547 void wxGetMousePosition( int* x
, int* y
)
552 LocalToGlobal( &pt
) ;
557 // Return TRUE if we have a colour display
558 bool wxColourDisplay()
563 // Returns depth of screen
567 SetRect(&globRect
, -32760, -32760, 32760, 32760);
568 GDHandle theMaxDevice
;
571 theMaxDevice
= GetMaxDevice(&globRect
);
572 if (theMaxDevice
!= nil
)
573 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
578 // Get size of display
579 void wxDisplaySize(int *width
, int *height
)
582 GetQDGlobalsScreenBits( &screenBits
);
585 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
587 if (height
!= NULL
) {
588 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
592 void wxDisplaySizeMM(int *width
, int *height
)
594 wxDisplaySize(width
, height
);
595 // on mac 72 is fixed (at least now ;-)
596 float cvPt2Mm
= 25.4 / 72;
599 *width
= int( *width
* cvPt2Mm
);
601 if (height
!= NULL
) {
602 *height
= int( *height
* cvPt2Mm
);
606 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
609 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
615 *width
= r
.right
- r
.left
;
617 *height
= r
.bottom
- r
.top
;
620 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
622 return wxGenericFindWindowAtPoint(pt
);
629 wxString
wxGetOsDescription()
631 #ifdef WXWIN_OS_DESCRIPTION
632 // use configure generated description if available
633 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
635 return wxT("MacOS") ; //TODO:define further
640 wxChar
*wxGetUserHome (const wxString
& user
)
646 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
656 int pos
= p
.Find(':') ;
657 if ( pos
!= wxNOT_FOUND
) {
666 wxMacStringToPascal( p
, volumeName
) ;
667 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
668 if ( err
== noErr
) {
670 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
673 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
677 return err
== noErr
;
679 #endif // !__DARWIN__
681 //---------------------------------------------------------------------------
682 // wxMac Specific utility functions
683 //---------------------------------------------------------------------------
685 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
687 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
688 int len
= strlen(buf
) ;
693 memcpy( (char*) &to
[1] , buf
, len
) ;
696 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
698 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
702 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
704 TextEncodingBase enc
= 0 ;
705 if ( encoding
== wxFONTENCODING_DEFAULT
)
708 encoding
= wxFont::GetDefaultEncoding() ;
710 encoding
= wxLocale::GetSystemEncoding() ;
716 case wxFONTENCODING_ISO8859_1
:
717 enc
= kTextEncodingISOLatin1
;
719 case wxFONTENCODING_ISO8859_2
:
720 enc
= kTextEncodingISOLatin2
;
722 case wxFONTENCODING_ISO8859_3
:
723 enc
= kTextEncodingISOLatin3
;
725 case wxFONTENCODING_ISO8859_4
:
726 enc
= kTextEncodingISOLatin4
;
728 case wxFONTENCODING_ISO8859_5
:
729 enc
= kTextEncodingISOLatinCyrillic
;
731 case wxFONTENCODING_ISO8859_6
:
732 enc
= kTextEncodingISOLatinArabic
;
734 case wxFONTENCODING_ISO8859_7
:
735 enc
= kTextEncodingISOLatinGreek
;
737 case wxFONTENCODING_ISO8859_8
:
738 enc
= kTextEncodingISOLatinHebrew
;
740 case wxFONTENCODING_ISO8859_9
:
741 enc
= kTextEncodingISOLatin5
;
743 case wxFONTENCODING_ISO8859_10
:
744 enc
= kTextEncodingISOLatin6
;
746 case wxFONTENCODING_ISO8859_13
:
747 enc
= kTextEncodingISOLatin7
;
749 case wxFONTENCODING_ISO8859_14
:
750 enc
= kTextEncodingISOLatin8
;
752 case wxFONTENCODING_ISO8859_15
:
753 enc
= kTextEncodingISOLatin9
;
756 case wxFONTENCODING_KOI8
:
757 enc
= kTextEncodingKOI8_R
;
759 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
760 enc
= kTextEncodingDOSRussian
;
763 case wxFONTENCODING_BULGARIAN :
767 case wxFONTENCODING_CP437
:
768 enc
=kTextEncodingDOSLatinUS
;
770 case wxFONTENCODING_CP850
:
771 enc
= kTextEncodingDOSLatin1
;
773 case wxFONTENCODING_CP852
:
774 enc
= kTextEncodingDOSLatin2
;
776 case wxFONTENCODING_CP855
:
777 enc
= kTextEncodingDOSCyrillic
;
779 case wxFONTENCODING_CP866
:
780 enc
=kTextEncodingDOSRussian
;
782 case wxFONTENCODING_CP874
:
783 enc
= kTextEncodingDOSThai
;
785 case wxFONTENCODING_CP932
:
786 enc
= kTextEncodingDOSJapanese
;
788 case wxFONTENCODING_CP936
:
789 enc
=kTextEncodingDOSChineseSimplif
;
791 case wxFONTENCODING_CP949
:
792 enc
= kTextEncodingDOSKorean
;
794 case wxFONTENCODING_CP950
:
795 enc
= kTextEncodingDOSChineseTrad
;
798 case wxFONTENCODING_CP1250
:
799 enc
= kTextEncodingWindowsLatin2
;
801 case wxFONTENCODING_CP1251
:
802 enc
=kTextEncodingWindowsCyrillic
;
804 case wxFONTENCODING_CP1252
:
805 enc
=kTextEncodingWindowsLatin1
;
807 case wxFONTENCODING_CP1253
:
808 enc
= kTextEncodingWindowsGreek
;
810 case wxFONTENCODING_CP1254
:
811 enc
= kTextEncodingWindowsLatin5
;
813 case wxFONTENCODING_CP1255
:
814 enc
=kTextEncodingWindowsHebrew
;
816 case wxFONTENCODING_CP1256
:
817 enc
=kTextEncodingWindowsArabic
;
819 case wxFONTENCODING_CP1257
:
820 enc
= kTextEncodingWindowsBalticRim
;
823 case wxFONTENCODING_UTF7
:
824 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
826 case wxFONTENCODING_UTF8
:
827 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
829 case wxFONTENCODING_EUC_JP
:
830 enc
= kTextEncodingEUC_JP
;
832 case wxFONTENCODING_UTF16BE
:
833 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
835 case wxFONTENCODING_UTF16LE
:
836 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
838 case wxFONTENCODING_UTF32BE
:
839 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
841 case wxFONTENCODING_UTF32LE
:
842 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
845 case wxFONTENCODING_MACROMAN
:
846 enc
= kTextEncodingMacRoman
;
848 case wxFONTENCODING_MACJAPANESE
:
849 enc
= kTextEncodingMacJapanese
;
851 case wxFONTENCODING_MACCHINESETRAD
:
852 enc
= kTextEncodingMacChineseTrad
;
854 case wxFONTENCODING_MACKOREAN
:
855 enc
= kTextEncodingMacKorean
;
857 case wxFONTENCODING_MACARABIC
:
858 enc
= kTextEncodingMacArabic
;
860 case wxFONTENCODING_MACHEBREW
:
861 enc
= kTextEncodingMacHebrew
;
863 case wxFONTENCODING_MACGREEK
:
864 enc
= kTextEncodingMacGreek
;
866 case wxFONTENCODING_MACCYRILLIC
:
867 enc
= kTextEncodingMacCyrillic
;
869 case wxFONTENCODING_MACDEVANAGARI
:
870 enc
= kTextEncodingMacDevanagari
;
872 case wxFONTENCODING_MACGURMUKHI
:
873 enc
= kTextEncodingMacGurmukhi
;
875 case wxFONTENCODING_MACGUJARATI
:
876 enc
= kTextEncodingMacGujarati
;
878 case wxFONTENCODING_MACORIYA
:
879 enc
= kTextEncodingMacOriya
;
881 case wxFONTENCODING_MACBENGALI
:
882 enc
= kTextEncodingMacBengali
;
884 case wxFONTENCODING_MACTAMIL
:
885 enc
= kTextEncodingMacTamil
;
887 case wxFONTENCODING_MACTELUGU
:
888 enc
= kTextEncodingMacTelugu
;
890 case wxFONTENCODING_MACKANNADA
:
891 enc
= kTextEncodingMacKannada
;
893 case wxFONTENCODING_MACMALAJALAM
:
894 enc
= kTextEncodingMacMalayalam
;
896 case wxFONTENCODING_MACSINHALESE
:
897 enc
= kTextEncodingMacSinhalese
;
899 case wxFONTENCODING_MACBURMESE
:
900 enc
= kTextEncodingMacBurmese
;
902 case wxFONTENCODING_MACKHMER
:
903 enc
= kTextEncodingMacKhmer
;
905 case wxFONTENCODING_MACTHAI
:
906 enc
= kTextEncodingMacThai
;
908 case wxFONTENCODING_MACLAOTIAN
:
909 enc
= kTextEncodingMacLaotian
;
911 case wxFONTENCODING_MACGEORGIAN
:
912 enc
= kTextEncodingMacGeorgian
;
914 case wxFONTENCODING_MACARMENIAN
:
915 enc
= kTextEncodingMacArmenian
;
917 case wxFONTENCODING_MACCHINESESIMP
:
918 enc
= kTextEncodingMacChineseSimp
;
920 case wxFONTENCODING_MACTIBETAN
:
921 enc
= kTextEncodingMacTibetan
;
923 case wxFONTENCODING_MACMONGOLIAN
:
924 enc
= kTextEncodingMacMongolian
;
926 case wxFONTENCODING_MACETHIOPIC
:
927 enc
= kTextEncodingMacEthiopic
;
929 case wxFONTENCODING_MACCENTRALEUR
:
930 enc
= kTextEncodingMacCentralEurRoman
;
932 case wxFONTENCODING_MACVIATNAMESE
:
933 enc
= kTextEncodingMacVietnamese
;
935 case wxFONTENCODING_MACARABICEXT
:
936 enc
= kTextEncodingMacExtArabic
;
938 case wxFONTENCODING_MACSYMBOL
:
939 enc
= kTextEncodingMacSymbol
;
941 case wxFONTENCODING_MACDINGBATS
:
942 enc
= kTextEncodingMacDingbats
;
944 case wxFONTENCODING_MACTURKISH
:
945 enc
= kTextEncodingMacTurkish
;
947 case wxFONTENCODING_MACCROATIAN
:
948 enc
= kTextEncodingMacCroatian
;
950 case wxFONTENCODING_MACICELANDIC
:
951 enc
= kTextEncodingMacIcelandic
;
953 case wxFONTENCODING_MACROMANIAN
:
954 enc
= kTextEncodingMacRomanian
;
956 case wxFONTENCODING_MACCELTIC
:
957 enc
= kTextEncodingMacCeltic
;
959 case wxFONTENCODING_MACGAELIC
:
960 enc
= kTextEncodingMacGaelic
;
962 case wxFONTENCODING_MACKEYBOARD
:
963 enc
= kTextEncodingMacKeyboardGlyphs
;
972 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
974 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
978 case kTextEncodingISOLatin1
:
979 enc
= wxFONTENCODING_ISO8859_1
;
981 case kTextEncodingISOLatin2
:
982 enc
= wxFONTENCODING_ISO8859_2
;
984 case kTextEncodingISOLatin3
:
985 enc
= wxFONTENCODING_ISO8859_3
;
987 case kTextEncodingISOLatin4
:
988 enc
= wxFONTENCODING_ISO8859_4
;
990 case kTextEncodingISOLatinCyrillic
:
991 enc
= wxFONTENCODING_ISO8859_5
;
993 case kTextEncodingISOLatinArabic
:
994 enc
= wxFONTENCODING_ISO8859_6
;
996 case kTextEncodingISOLatinGreek
:
997 enc
= wxFONTENCODING_ISO8859_7
;
999 case kTextEncodingISOLatinHebrew
:
1000 enc
= wxFONTENCODING_ISO8859_8
;
1002 case kTextEncodingISOLatin5
:
1003 enc
= wxFONTENCODING_ISO8859_9
;
1005 case kTextEncodingISOLatin6
:
1006 enc
= wxFONTENCODING_ISO8859_10
;
1008 case kTextEncodingISOLatin7
:
1009 enc
= wxFONTENCODING_ISO8859_13
;
1011 case kTextEncodingISOLatin8
:
1012 enc
= wxFONTENCODING_ISO8859_14
;
1014 case kTextEncodingISOLatin9
:
1015 enc
=wxFONTENCODING_ISO8859_15
;
1018 case kTextEncodingKOI8_R
:
1019 enc
= wxFONTENCODING_KOI8
;
1023 enc = wxFONTENCODING_BULGARIAN;
1026 case kTextEncodingDOSLatinUS
:
1027 enc
= wxFONTENCODING_CP437
;
1029 case kTextEncodingDOSLatin1
:
1030 enc
= wxFONTENCODING_CP850
;
1032 case kTextEncodingDOSLatin2
:
1033 enc
=wxFONTENCODING_CP852
;
1035 case kTextEncodingDOSCyrillic
:
1036 enc
= wxFONTENCODING_CP855
;
1038 case kTextEncodingDOSRussian
:
1039 enc
= wxFONTENCODING_CP866
;
1041 case kTextEncodingDOSThai
:
1042 enc
=wxFONTENCODING_CP874
;
1044 case kTextEncodingDOSJapanese
:
1045 enc
= wxFONTENCODING_CP932
;
1047 case kTextEncodingDOSChineseSimplif
:
1048 enc
= wxFONTENCODING_CP936
;
1050 case kTextEncodingDOSKorean
:
1051 enc
= wxFONTENCODING_CP949
;
1053 case kTextEncodingDOSChineseTrad
:
1054 enc
= wxFONTENCODING_CP950
;
1057 case kTextEncodingWindowsLatin2
:
1058 enc
= wxFONTENCODING_CP1250
;
1060 case kTextEncodingWindowsCyrillic
:
1061 enc
= wxFONTENCODING_CP1251
;
1063 case kTextEncodingWindowsLatin1
:
1064 enc
= wxFONTENCODING_CP1252
;
1066 case kTextEncodingWindowsGreek
:
1067 enc
= wxFONTENCODING_CP1253
;
1069 case kTextEncodingWindowsLatin5
:
1070 enc
= wxFONTENCODING_CP1254
;
1072 case kTextEncodingWindowsHebrew
:
1073 enc
= wxFONTENCODING_CP1255
;
1075 case kTextEncodingWindowsArabic
:
1076 enc
= wxFONTENCODING_CP1256
;
1078 case kTextEncodingWindowsBalticRim
:
1079 enc
=wxFONTENCODING_CP1257
;
1081 case kTextEncodingEUC_JP
:
1082 enc
= wxFONTENCODING_EUC_JP
;
1085 case wxFONTENCODING_UTF7 :
1086 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1088 case wxFONTENCODING_UTF8 :
1089 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1091 case wxFONTENCODING_UTF16BE :
1092 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1094 case wxFONTENCODING_UTF16LE :
1095 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1097 case wxFONTENCODING_UTF32BE :
1098 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1100 case wxFONTENCODING_UTF32LE :
1101 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1104 case kTextEncodingMacRoman
:
1105 enc
= wxFONTENCODING_MACROMAN
;
1107 case kTextEncodingMacJapanese
:
1108 enc
= wxFONTENCODING_MACJAPANESE
;
1110 case kTextEncodingMacChineseTrad
:
1111 enc
= wxFONTENCODING_MACCHINESETRAD
;
1113 case kTextEncodingMacKorean
:
1114 enc
= wxFONTENCODING_MACKOREAN
;
1116 case kTextEncodingMacArabic
:
1117 enc
=wxFONTENCODING_MACARABIC
;
1119 case kTextEncodingMacHebrew
:
1120 enc
= wxFONTENCODING_MACHEBREW
;
1122 case kTextEncodingMacGreek
:
1123 enc
= wxFONTENCODING_MACGREEK
;
1125 case kTextEncodingMacCyrillic
:
1126 enc
= wxFONTENCODING_MACCYRILLIC
;
1128 case kTextEncodingMacDevanagari
:
1129 enc
= wxFONTENCODING_MACDEVANAGARI
;
1131 case kTextEncodingMacGurmukhi
:
1132 enc
= wxFONTENCODING_MACGURMUKHI
;
1134 case kTextEncodingMacGujarati
:
1135 enc
= wxFONTENCODING_MACGUJARATI
;
1137 case kTextEncodingMacOriya
:
1138 enc
=wxFONTENCODING_MACORIYA
;
1140 case kTextEncodingMacBengali
:
1141 enc
=wxFONTENCODING_MACBENGALI
;
1143 case kTextEncodingMacTamil
:
1144 enc
= wxFONTENCODING_MACTAMIL
;
1146 case kTextEncodingMacTelugu
:
1147 enc
= wxFONTENCODING_MACTELUGU
;
1149 case kTextEncodingMacKannada
:
1150 enc
= wxFONTENCODING_MACKANNADA
;
1152 case kTextEncodingMacMalayalam
:
1153 enc
= wxFONTENCODING_MACMALAJALAM
;
1155 case kTextEncodingMacSinhalese
:
1156 enc
= wxFONTENCODING_MACSINHALESE
;
1158 case kTextEncodingMacBurmese
:
1159 enc
= wxFONTENCODING_MACBURMESE
;
1161 case kTextEncodingMacKhmer
:
1162 enc
= wxFONTENCODING_MACKHMER
;
1164 case kTextEncodingMacThai
:
1165 enc
= wxFONTENCODING_MACTHAI
;
1167 case kTextEncodingMacLaotian
:
1168 enc
= wxFONTENCODING_MACLAOTIAN
;
1170 case kTextEncodingMacGeorgian
:
1171 enc
= wxFONTENCODING_MACGEORGIAN
;
1173 case kTextEncodingMacArmenian
:
1174 enc
= wxFONTENCODING_MACARMENIAN
;
1176 case kTextEncodingMacChineseSimp
:
1177 enc
= wxFONTENCODING_MACCHINESESIMP
;
1179 case kTextEncodingMacTibetan
:
1180 enc
= wxFONTENCODING_MACTIBETAN
;
1182 case kTextEncodingMacMongolian
:
1183 enc
= wxFONTENCODING_MACMONGOLIAN
;
1185 case kTextEncodingMacEthiopic
:
1186 enc
= wxFONTENCODING_MACETHIOPIC
;
1188 case kTextEncodingMacCentralEurRoman
:
1189 enc
= wxFONTENCODING_MACCENTRALEUR
;
1191 case kTextEncodingMacVietnamese
:
1192 enc
= wxFONTENCODING_MACVIATNAMESE
;
1194 case kTextEncodingMacExtArabic
:
1195 enc
= wxFONTENCODING_MACARABICEXT
;
1197 case kTextEncodingMacSymbol
:
1198 enc
= wxFONTENCODING_MACSYMBOL
;
1200 case kTextEncodingMacDingbats
:
1201 enc
= wxFONTENCODING_MACDINGBATS
;
1203 case kTextEncodingMacTurkish
:
1204 enc
= wxFONTENCODING_MACTURKISH
;
1206 case kTextEncodingMacCroatian
:
1207 enc
= wxFONTENCODING_MACCROATIAN
;
1209 case kTextEncodingMacIcelandic
:
1210 enc
= wxFONTENCODING_MACICELANDIC
;
1212 case kTextEncodingMacRomanian
:
1213 enc
= wxFONTENCODING_MACROMANIAN
;
1215 case kTextEncodingMacCeltic
:
1216 enc
= wxFONTENCODING_MACCELTIC
;
1218 case kTextEncodingMacGaelic
:
1219 enc
= wxFONTENCODING_MACGAELIC
;
1221 case kTextEncodingMacKeyboardGlyphs
:
1222 enc
= wxFONTENCODING_MACKEYBOARD
;
1230 // CFStringRefs (Carbon only)
1235 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1236 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1241 wxMacConvertNewlines13To10( &str
) ;
1243 #if SIZEOF_WCHAR_T == 2
1244 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1245 (UniChar
*)str
.wc_str() , str
.Len() );
1247 wxMBConvUTF16BE converter
;
1248 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1249 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1250 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1251 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1252 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1255 #else // not wxUSE_UNICODE
1256 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1257 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1262 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1264 Size cflen
= CFStringGetLength( m_cfs
) ;
1266 wxChar
* buf
= NULL
;
1269 #if SIZEOF_WCHAR_T == 2
1270 buf
= new wxChar
[ cflen
+ 1 ] ;
1271 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1274 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1275 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1277 wxMBConvUTF16BE converter
;
1278 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1279 buf
= new wxChar
[ noChars
+ 1 ] ;
1280 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1285 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1286 '?' , false , NULL
, 0 , &cStrLen
) ;
1287 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1288 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1289 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1294 wxMacConvertNewlines10To13( buf
) ;
1295 wxString
result(buf
) ;
1300 #endif //TARGET_CARBON
1302 void wxMacConvertNewlines13To10( char * data
)
1305 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1312 void wxMacConvertNewlines10To13( char * data
)
1315 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1322 void wxMacConvertNewlines13To10( wxString
* data
)
1324 size_t len
= data
->Length() ;
1326 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1329 wxString
temp(*data
) ;
1330 wxStringBuffer
buf(*data
,len
) ;
1331 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1333 wxMacConvertNewlines13To10( buf
) ;
1336 void wxMacConvertNewlines10To13( wxString
* data
)
1338 size_t len
= data
->Length() ;
1340 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1343 wxString
temp(*data
) ;
1344 wxStringBuffer
buf(*data
,len
) ;
1345 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1346 wxMacConvertNewlines10To13( buf
) ;
1351 void wxMacConvertNewlines13To10( wxChar
* data
)
1353 wxChar
* buf
= data
;
1354 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1361 void wxMacConvertNewlines10To13( wxChar
* data
)
1363 wxChar
* buf
= data
;
1364 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1372 // ----------------------------------------------------------------------------
1373 // Common Event Support
1374 // ----------------------------------------------------------------------------
1377 extern ProcessSerialNumber gAppProcess
;
1381 ProcessSerialNumber psn
;
1383 psn
.highLongOfPSN
= 0 ;
1384 psn
.lowLongOfPSN
= kCurrentProcess
;
1385 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1389 EventRef dummyEvent
;
1390 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1391 kEventAttributeNone
, &dummyEvent
);
1394 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1395 kEventPriorityHigh
);
1398 PostEvent( nullEvent
, 0 ) ;
1403 WakeUpProcess( &gAppProcess
) ;
1407 #endif // wxUSE_BASE
1412 // ----------------------------------------------------------------------------
1413 // Carbon Event Support
1414 // ----------------------------------------------------------------------------
1417 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1419 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1422 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1424 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1427 // ----------------------------------------------------------------------------
1428 // Control Access Support
1429 // ----------------------------------------------------------------------------
1431 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
)
1433 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1436 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
)
1438 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1441 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1443 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1446 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1448 #if TARGET_API_MAC_OSX
1449 return SendEventToEventTargetWithOptions( event
,
1450 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1452 #pragma unused(inOptions)
1453 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1457 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1459 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1460 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1461 return SendEvent( event
, inOptions
) ;
1464 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1467 memset( &command
, 0 , sizeof(command
) ) ;
1468 command
.commandID
= commandID
;
1469 return SendHICommand( command
, inOptions
) ;
1472 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1474 HiliteControl( m_controlRef
, part
) ;
1475 unsigned long finalTicks
;
1476 Delay( ticks
, &finalTicks
) ;
1477 HiliteControl( m_controlRef
, kControlNoPart
) ;
1480 SInt32
wxMacControl::GetValue() const
1482 return ::GetControl32BitValue( m_controlRef
) ;
1485 SInt32
wxMacControl::GetMaximum() const
1487 return ::GetControl32BitMaximum( m_controlRef
) ;
1490 SInt32
wxMacControl::GetMinimum() const
1492 return ::GetControl32BitMinimum( m_controlRef
) ;
1495 void wxMacControl::SetValue( SInt32 v
)
1497 ::SetControl32BitValue( m_controlRef
, v
) ;
1500 void wxMacControl::SetMinimum( SInt32 v
)
1502 ::SetControl32BitMinimum( m_controlRef
, v
) ;
1505 void wxMacControl::SetMaximum( SInt32 v
)
1507 ::SetControl32BitMaximum( m_controlRef
, v
) ;
1510 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
1512 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1513 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1514 ::SetControl32BitValue( m_controlRef
, value
) ;
1517 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1519 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1520 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;