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"
36 #include "MoreFilesX.h"
44 #if TARGET_API_MAC_OSX
45 #include <CoreServices/CoreServices.h>
47 #include <DriverServices.h>
48 #include <Multiprocessing.h>
51 #include <ATSUnicode.h>
52 #include <TextCommon.h>
53 #include <TextEncodingConverter.h>
56 #include "wx/mac/private.h" // includes mac headers
58 #if defined(__MWERKS__) && wxUSE_UNICODE
62 // ---------------------------------------------------------------------------
63 // code used in both base and GUI compilation
64 // ---------------------------------------------------------------------------
66 // our OS version is the same in non GUI and GUI cases
67 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
71 // are there x-platform conventions ?
73 Gestalt(gestaltSystemVersion
, &theSystem
) ;
74 if (minorVsn
!= NULL
) {
75 *minorVsn
= (theSystem
& 0xFF ) ;
77 if (majorVsn
!= NULL
) {
78 *majorVsn
= (theSystem
>> 8 ) ;
90 // ----------------------------------------------------------------------------
92 // ----------------------------------------------------------------------------
94 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
96 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
98 #ifndef __MetroNubUtils__
99 #include "MetroNubUtils.h"
106 #if TARGET_API_MAC_CARBON
108 #include <CodeFragments.h>
110 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
112 ProcPtr gCallUniversalProc_Proc
= NULL
;
116 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
118 static long fRunOnce
= false;
120 /* ---------------------------------------------------------------------------
122 --------------------------------------------------------------------------- */
124 Boolean
IsMetroNubInstalled()
131 gMetroNubEntry
= NULL
;
133 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
135 /* look for MetroNub's Gestalt selector */
136 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
139 #if TARGET_API_MAC_CARBON
140 if (gCallUniversalProc_Proc
== NULL
)
142 CFragConnectionID connectionID
;
145 ProcPtr symbolAddress
;
147 CFragSymbolClass symbolClass
;
149 symbolAddress
= NULL
;
150 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
151 &connectionID
, &mainAddress
, errorString
);
155 gCallUniversalProc_Proc
= NULL
;
159 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
160 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
164 gCallUniversalProc_Proc
= NULL
;
171 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
173 /* make sure the version of the API is compatible */
174 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
175 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
176 gMetroNubEntry
= block
; /* success! */
185 #if TARGET_API_MAC_CARBON
186 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
188 return (gMetroNubEntry
!= NULL
);
192 /* ---------------------------------------------------------------------------
193 IsMWDebuggerRunning [v1 API]
194 --------------------------------------------------------------------------- */
196 Boolean
IsMWDebuggerRunning()
198 if (IsMetroNubInstalled())
199 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
204 /* ---------------------------------------------------------------------------
205 AmIBeingMWDebugged [v1 API]
206 --------------------------------------------------------------------------- */
208 Boolean
AmIBeingMWDebugged()
210 if (IsMetroNubInstalled())
211 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
216 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
218 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
223 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
228 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
232 // defined in unix/utilsunx.cpp for Mac OS X
234 // get full hostname (with domain name if possible)
235 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
237 return wxGetHostName(buf
, maxSize
);
240 // Get hostname only (without domain name)
241 bool wxGetHostName(wxChar
*buf
, int maxSize
)
243 // Gets Chooser name of user by examining a System resource.
245 const short kComputerNameID
= -16413;
247 short oldResFile
= CurResFile() ;
249 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
250 UseResFile(oldResFile
);
252 if (chooserName
&& *chooserName
)
254 HLock( (Handle
) chooserName
) ;
255 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
256 HUnlock( (Handle
) chooserName
) ;
257 ReleaseResource( (Handle
) chooserName
) ;
258 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
266 // Get user ID e.g. jacs
267 bool wxGetUserId(wxChar
*buf
, int maxSize
)
269 return wxGetUserName( buf
, maxSize
) ;
272 const wxChar
* wxGetHomeDir(wxString
*pstr
)
274 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
275 return pstr
->c_str() ;
278 // Get user name e.g. Stefan Csomor
279 bool wxGetUserName(wxChar
*buf
, int maxSize
)
281 // Gets Chooser name of user by examining a System resource.
283 const short kChooserNameID
= -16096;
285 short oldResFile
= CurResFile() ;
287 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
288 UseResFile(oldResFile
);
290 if (chooserName
&& *chooserName
)
292 HLock( (Handle
) chooserName
) ;
293 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
294 HUnlock( (Handle
) chooserName
) ;
295 ReleaseResource( (Handle
) chooserName
) ;
296 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
304 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
310 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
312 // TODO : under classic there is no environement support, under X yes
316 // set the env var name to the given value, return TRUE on success
317 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
319 // TODO : under classic there is no environement support, under X yes
324 // Execute a program in an Interactive Shell
326 bool wxShell(const wxString
& command
)
332 // Shutdown or reboot the PC
333 bool wxShutdown(wxShutdownFlags wFlags
)
339 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
340 long wxGetFreeMemory()
347 void wxMicroSleep(unsigned long microseconds
)
349 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
350 MPDelayUntil( & wakeup
);
353 void wxMilliSleep(unsigned long milliseconds
)
355 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
356 MPDelayUntil( & wakeup
);
359 void wxSleep(int nSecs
)
361 wxMilliSleep(1000*nSecs
);
366 // Consume all events until no more left
371 #endif // !__DARWIN__
379 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
381 static wxToolkitInfo info
;
382 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
383 info
.name
= _T("wxBase");
391 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
393 static wxToolkitInfo info
;
394 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
395 info
.shortName
= _T("mac");
396 info
.name
= _T("wxMac");
397 #ifdef __WXUNIVERSAL__
398 info
.shortName
<< _T("univ");
399 info
.name
<< _T("/wxUniversal");
404 // Reading and writing resources (eg WIN.INI, .Xdefaults)
406 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
412 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
415 buf
.Printf(wxT("%.4f"), value
);
417 return wxWriteResource(section
, entry
, buf
, file
);
420 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
423 buf
.Printf(wxT("%ld"), value
);
425 return wxWriteResource(section
, entry
, buf
, file
);
428 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
431 buf
.Printf(wxT("%d"), value
);
433 return wxWriteResource(section
, entry
, buf
, file
);
436 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
442 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
445 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
448 *value
= (float)strtod(s
, NULL
);
455 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
458 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
461 *value
= strtol(s
, NULL
, 10);
468 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
471 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
474 *value
= (int)strtol(s
, NULL
, 10);
480 #endif // wxUSE_RESOURCES
482 int gs_wxBusyCursorCount
= 0;
483 extern wxCursor gMacCurrentCursor
;
484 wxCursor gMacStoredActiveCursor
;
486 // Set the cursor to the busy cursor for all windows
487 void wxBeginBusyCursor(wxCursor
*cursor
)
489 if (gs_wxBusyCursorCount
++ == 0)
491 gMacStoredActiveCursor
= gMacCurrentCursor
;
492 cursor
->MacInstall() ;
494 //else: nothing to do, already set
497 // Restore cursor to normal
498 void wxEndBusyCursor()
500 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
501 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
503 if (--gs_wxBusyCursorCount
== 0)
505 gMacStoredActiveCursor
.MacInstall() ;
506 gMacStoredActiveCursor
= wxNullCursor
;
510 // TRUE if we're between the above two calls
513 return (gs_wxBusyCursorCount
> 0);
520 wxString
wxMacFindFolder( short vol
,
522 Boolean createFolder
)
527 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
528 strDir
= wxMacFSRefToPath( &fsRef
) + wxFILE_SEP_PATH
;
537 // Check whether this window wants to process messages, e.g. Stop button
538 // in long calculations.
539 bool wxCheckForInterrupt(wxWindow
*wnd
)
545 void wxGetMousePosition( int* x
, int* y
)
550 LocalToGlobal( &pt
) ;
555 // Return TRUE if we have a colour display
556 bool wxColourDisplay()
561 // Returns depth of screen
565 SetRect(&globRect
, -32760, -32760, 32760, 32760);
566 GDHandle theMaxDevice
;
569 theMaxDevice
= GetMaxDevice(&globRect
);
570 if (theMaxDevice
!= nil
)
571 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
576 // Get size of display
577 void wxDisplaySize(int *width
, int *height
)
580 GetQDGlobalsScreenBits( &screenBits
);
583 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
585 if (height
!= NULL
) {
586 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
590 void wxDisplaySizeMM(int *width
, int *height
)
592 wxDisplaySize(width
, height
);
593 // on mac 72 is fixed (at least now ;-)
594 float cvPt2Mm
= 25.4 / 72;
597 *width
= int( *width
* cvPt2Mm
);
599 if (height
!= NULL
) {
600 *height
= int( *height
* cvPt2Mm
);
604 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
607 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
613 *width
= r
.right
- r
.left
;
615 *height
= r
.bottom
- r
.top
;
618 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
620 return wxGenericFindWindowAtPoint(pt
);
627 wxString
wxGetOsDescription()
629 #ifdef WXWIN_OS_DESCRIPTION
630 // use configure generated description if available
631 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
633 return wxT("MacOS") ; //TODO:define further
638 wxChar
*wxGetUserHome (const wxString
& user
)
644 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
654 int pos
= p
.Find(':') ;
655 if ( pos
!= wxNOT_FOUND
) {
664 err
= wxMacPathToFSRef( p
, &fsRef
) ;
667 FSVolumeRefNum vRefNum
;
668 err
= FSGetVRefNum( &fsRef
, &vRefNum
) ;
671 UInt64 freeBytes
, totalBytes
;
672 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
) ;
676 *pTotal
= wxLongLong( totalBytes
) ;
678 *pFree
= wxLongLong( freeBytes
) ;
683 return err
== noErr
;
685 #endif // !__DARWIN__
687 //---------------------------------------------------------------------------
688 // wxMac Specific utility functions
689 //---------------------------------------------------------------------------
691 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
693 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
694 int len
= strlen(buf
) ;
699 memcpy( (char*) &to
[1] , buf
, len
) ;
702 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
704 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
708 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
710 TextEncodingBase enc
= 0 ;
711 if ( encoding
== wxFONTENCODING_DEFAULT
)
714 encoding
= wxFont::GetDefaultEncoding() ;
716 encoding
= wxLocale::GetSystemEncoding() ;
722 case wxFONTENCODING_ISO8859_1
:
723 enc
= kTextEncodingISOLatin1
;
725 case wxFONTENCODING_ISO8859_2
:
726 enc
= kTextEncodingISOLatin2
;
728 case wxFONTENCODING_ISO8859_3
:
729 enc
= kTextEncodingISOLatin3
;
731 case wxFONTENCODING_ISO8859_4
:
732 enc
= kTextEncodingISOLatin4
;
734 case wxFONTENCODING_ISO8859_5
:
735 enc
= kTextEncodingISOLatinCyrillic
;
737 case wxFONTENCODING_ISO8859_6
:
738 enc
= kTextEncodingISOLatinArabic
;
740 case wxFONTENCODING_ISO8859_7
:
741 enc
= kTextEncodingISOLatinGreek
;
743 case wxFONTENCODING_ISO8859_8
:
744 enc
= kTextEncodingISOLatinHebrew
;
746 case wxFONTENCODING_ISO8859_9
:
747 enc
= kTextEncodingISOLatin5
;
749 case wxFONTENCODING_ISO8859_10
:
750 enc
= kTextEncodingISOLatin6
;
752 case wxFONTENCODING_ISO8859_13
:
753 enc
= kTextEncodingISOLatin7
;
755 case wxFONTENCODING_ISO8859_14
:
756 enc
= kTextEncodingISOLatin8
;
758 case wxFONTENCODING_ISO8859_15
:
759 enc
= kTextEncodingISOLatin9
;
762 case wxFONTENCODING_KOI8
:
763 enc
= kTextEncodingKOI8_R
;
765 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
766 enc
= kTextEncodingDOSRussian
;
769 case wxFONTENCODING_BULGARIAN :
773 case wxFONTENCODING_CP437
:
774 enc
=kTextEncodingDOSLatinUS
;
776 case wxFONTENCODING_CP850
:
777 enc
= kTextEncodingDOSLatin1
;
779 case wxFONTENCODING_CP852
:
780 enc
= kTextEncodingDOSLatin2
;
782 case wxFONTENCODING_CP855
:
783 enc
= kTextEncodingDOSCyrillic
;
785 case wxFONTENCODING_CP866
:
786 enc
=kTextEncodingDOSRussian
;
788 case wxFONTENCODING_CP874
:
789 enc
= kTextEncodingDOSThai
;
791 case wxFONTENCODING_CP932
:
792 enc
= kTextEncodingDOSJapanese
;
794 case wxFONTENCODING_CP936
:
795 enc
=kTextEncodingDOSChineseSimplif
;
797 case wxFONTENCODING_CP949
:
798 enc
= kTextEncodingDOSKorean
;
800 case wxFONTENCODING_CP950
:
801 enc
= kTextEncodingDOSChineseTrad
;
804 case wxFONTENCODING_CP1250
:
805 enc
= kTextEncodingWindowsLatin2
;
807 case wxFONTENCODING_CP1251
:
808 enc
=kTextEncodingWindowsCyrillic
;
810 case wxFONTENCODING_CP1252
:
811 enc
=kTextEncodingWindowsLatin1
;
813 case wxFONTENCODING_CP1253
:
814 enc
= kTextEncodingWindowsGreek
;
816 case wxFONTENCODING_CP1254
:
817 enc
= kTextEncodingWindowsLatin5
;
819 case wxFONTENCODING_CP1255
:
820 enc
=kTextEncodingWindowsHebrew
;
822 case wxFONTENCODING_CP1256
:
823 enc
=kTextEncodingWindowsArabic
;
825 case wxFONTENCODING_CP1257
:
826 enc
= kTextEncodingWindowsBalticRim
;
829 case wxFONTENCODING_UTF7
:
830 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
832 case wxFONTENCODING_UTF8
:
833 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
835 case wxFONTENCODING_EUC_JP
:
836 enc
= kTextEncodingEUC_JP
;
838 case wxFONTENCODING_UTF16BE
:
839 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
841 case wxFONTENCODING_UTF16LE
:
842 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
844 case wxFONTENCODING_UTF32BE
:
845 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
847 case wxFONTENCODING_UTF32LE
:
848 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
851 case wxFONTENCODING_MACROMAN
:
852 enc
= kTextEncodingMacRoman
;
854 case wxFONTENCODING_MACJAPANESE
:
855 enc
= kTextEncodingMacJapanese
;
857 case wxFONTENCODING_MACCHINESETRAD
:
858 enc
= kTextEncodingMacChineseTrad
;
860 case wxFONTENCODING_MACKOREAN
:
861 enc
= kTextEncodingMacKorean
;
863 case wxFONTENCODING_MACARABIC
:
864 enc
= kTextEncodingMacArabic
;
866 case wxFONTENCODING_MACHEBREW
:
867 enc
= kTextEncodingMacHebrew
;
869 case wxFONTENCODING_MACGREEK
:
870 enc
= kTextEncodingMacGreek
;
872 case wxFONTENCODING_MACCYRILLIC
:
873 enc
= kTextEncodingMacCyrillic
;
875 case wxFONTENCODING_MACDEVANAGARI
:
876 enc
= kTextEncodingMacDevanagari
;
878 case wxFONTENCODING_MACGURMUKHI
:
879 enc
= kTextEncodingMacGurmukhi
;
881 case wxFONTENCODING_MACGUJARATI
:
882 enc
= kTextEncodingMacGujarati
;
884 case wxFONTENCODING_MACORIYA
:
885 enc
= kTextEncodingMacOriya
;
887 case wxFONTENCODING_MACBENGALI
:
888 enc
= kTextEncodingMacBengali
;
890 case wxFONTENCODING_MACTAMIL
:
891 enc
= kTextEncodingMacTamil
;
893 case wxFONTENCODING_MACTELUGU
:
894 enc
= kTextEncodingMacTelugu
;
896 case wxFONTENCODING_MACKANNADA
:
897 enc
= kTextEncodingMacKannada
;
899 case wxFONTENCODING_MACMALAJALAM
:
900 enc
= kTextEncodingMacMalayalam
;
902 case wxFONTENCODING_MACSINHALESE
:
903 enc
= kTextEncodingMacSinhalese
;
905 case wxFONTENCODING_MACBURMESE
:
906 enc
= kTextEncodingMacBurmese
;
908 case wxFONTENCODING_MACKHMER
:
909 enc
= kTextEncodingMacKhmer
;
911 case wxFONTENCODING_MACTHAI
:
912 enc
= kTextEncodingMacThai
;
914 case wxFONTENCODING_MACLAOTIAN
:
915 enc
= kTextEncodingMacLaotian
;
917 case wxFONTENCODING_MACGEORGIAN
:
918 enc
= kTextEncodingMacGeorgian
;
920 case wxFONTENCODING_MACARMENIAN
:
921 enc
= kTextEncodingMacArmenian
;
923 case wxFONTENCODING_MACCHINESESIMP
:
924 enc
= kTextEncodingMacChineseSimp
;
926 case wxFONTENCODING_MACTIBETAN
:
927 enc
= kTextEncodingMacTibetan
;
929 case wxFONTENCODING_MACMONGOLIAN
:
930 enc
= kTextEncodingMacMongolian
;
932 case wxFONTENCODING_MACETHIOPIC
:
933 enc
= kTextEncodingMacEthiopic
;
935 case wxFONTENCODING_MACCENTRALEUR
:
936 enc
= kTextEncodingMacCentralEurRoman
;
938 case wxFONTENCODING_MACVIATNAMESE
:
939 enc
= kTextEncodingMacVietnamese
;
941 case wxFONTENCODING_MACARABICEXT
:
942 enc
= kTextEncodingMacExtArabic
;
944 case wxFONTENCODING_MACSYMBOL
:
945 enc
= kTextEncodingMacSymbol
;
947 case wxFONTENCODING_MACDINGBATS
:
948 enc
= kTextEncodingMacDingbats
;
950 case wxFONTENCODING_MACTURKISH
:
951 enc
= kTextEncodingMacTurkish
;
953 case wxFONTENCODING_MACCROATIAN
:
954 enc
= kTextEncodingMacCroatian
;
956 case wxFONTENCODING_MACICELANDIC
:
957 enc
= kTextEncodingMacIcelandic
;
959 case wxFONTENCODING_MACROMANIAN
:
960 enc
= kTextEncodingMacRomanian
;
962 case wxFONTENCODING_MACCELTIC
:
963 enc
= kTextEncodingMacCeltic
;
965 case wxFONTENCODING_MACGAELIC
:
966 enc
= kTextEncodingMacGaelic
;
968 case wxFONTENCODING_MACKEYBOARD
:
969 enc
= kTextEncodingMacKeyboardGlyphs
;
978 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
980 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
984 case kTextEncodingISOLatin1
:
985 enc
= wxFONTENCODING_ISO8859_1
;
987 case kTextEncodingISOLatin2
:
988 enc
= wxFONTENCODING_ISO8859_2
;
990 case kTextEncodingISOLatin3
:
991 enc
= wxFONTENCODING_ISO8859_3
;
993 case kTextEncodingISOLatin4
:
994 enc
= wxFONTENCODING_ISO8859_4
;
996 case kTextEncodingISOLatinCyrillic
:
997 enc
= wxFONTENCODING_ISO8859_5
;
999 case kTextEncodingISOLatinArabic
:
1000 enc
= wxFONTENCODING_ISO8859_6
;
1002 case kTextEncodingISOLatinGreek
:
1003 enc
= wxFONTENCODING_ISO8859_7
;
1005 case kTextEncodingISOLatinHebrew
:
1006 enc
= wxFONTENCODING_ISO8859_8
;
1008 case kTextEncodingISOLatin5
:
1009 enc
= wxFONTENCODING_ISO8859_9
;
1011 case kTextEncodingISOLatin6
:
1012 enc
= wxFONTENCODING_ISO8859_10
;
1014 case kTextEncodingISOLatin7
:
1015 enc
= wxFONTENCODING_ISO8859_13
;
1017 case kTextEncodingISOLatin8
:
1018 enc
= wxFONTENCODING_ISO8859_14
;
1020 case kTextEncodingISOLatin9
:
1021 enc
=wxFONTENCODING_ISO8859_15
;
1024 case kTextEncodingKOI8_R
:
1025 enc
= wxFONTENCODING_KOI8
;
1029 enc = wxFONTENCODING_BULGARIAN;
1032 case kTextEncodingDOSLatinUS
:
1033 enc
= wxFONTENCODING_CP437
;
1035 case kTextEncodingDOSLatin1
:
1036 enc
= wxFONTENCODING_CP850
;
1038 case kTextEncodingDOSLatin2
:
1039 enc
=wxFONTENCODING_CP852
;
1041 case kTextEncodingDOSCyrillic
:
1042 enc
= wxFONTENCODING_CP855
;
1044 case kTextEncodingDOSRussian
:
1045 enc
= wxFONTENCODING_CP866
;
1047 case kTextEncodingDOSThai
:
1048 enc
=wxFONTENCODING_CP874
;
1050 case kTextEncodingDOSJapanese
:
1051 enc
= wxFONTENCODING_CP932
;
1053 case kTextEncodingDOSChineseSimplif
:
1054 enc
= wxFONTENCODING_CP936
;
1056 case kTextEncodingDOSKorean
:
1057 enc
= wxFONTENCODING_CP949
;
1059 case kTextEncodingDOSChineseTrad
:
1060 enc
= wxFONTENCODING_CP950
;
1063 case kTextEncodingWindowsLatin2
:
1064 enc
= wxFONTENCODING_CP1250
;
1066 case kTextEncodingWindowsCyrillic
:
1067 enc
= wxFONTENCODING_CP1251
;
1069 case kTextEncodingWindowsLatin1
:
1070 enc
= wxFONTENCODING_CP1252
;
1072 case kTextEncodingWindowsGreek
:
1073 enc
= wxFONTENCODING_CP1253
;
1075 case kTextEncodingWindowsLatin5
:
1076 enc
= wxFONTENCODING_CP1254
;
1078 case kTextEncodingWindowsHebrew
:
1079 enc
= wxFONTENCODING_CP1255
;
1081 case kTextEncodingWindowsArabic
:
1082 enc
= wxFONTENCODING_CP1256
;
1084 case kTextEncodingWindowsBalticRim
:
1085 enc
=wxFONTENCODING_CP1257
;
1087 case kTextEncodingEUC_JP
:
1088 enc
= wxFONTENCODING_EUC_JP
;
1091 case wxFONTENCODING_UTF7 :
1092 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1094 case wxFONTENCODING_UTF8 :
1095 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1097 case wxFONTENCODING_UTF16BE :
1098 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1100 case wxFONTENCODING_UTF16LE :
1101 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1103 case wxFONTENCODING_UTF32BE :
1104 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1106 case wxFONTENCODING_UTF32LE :
1107 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1110 case kTextEncodingMacRoman
:
1111 enc
= wxFONTENCODING_MACROMAN
;
1113 case kTextEncodingMacJapanese
:
1114 enc
= wxFONTENCODING_MACJAPANESE
;
1116 case kTextEncodingMacChineseTrad
:
1117 enc
= wxFONTENCODING_MACCHINESETRAD
;
1119 case kTextEncodingMacKorean
:
1120 enc
= wxFONTENCODING_MACKOREAN
;
1122 case kTextEncodingMacArabic
:
1123 enc
=wxFONTENCODING_MACARABIC
;
1125 case kTextEncodingMacHebrew
:
1126 enc
= wxFONTENCODING_MACHEBREW
;
1128 case kTextEncodingMacGreek
:
1129 enc
= wxFONTENCODING_MACGREEK
;
1131 case kTextEncodingMacCyrillic
:
1132 enc
= wxFONTENCODING_MACCYRILLIC
;
1134 case kTextEncodingMacDevanagari
:
1135 enc
= wxFONTENCODING_MACDEVANAGARI
;
1137 case kTextEncodingMacGurmukhi
:
1138 enc
= wxFONTENCODING_MACGURMUKHI
;
1140 case kTextEncodingMacGujarati
:
1141 enc
= wxFONTENCODING_MACGUJARATI
;
1143 case kTextEncodingMacOriya
:
1144 enc
=wxFONTENCODING_MACORIYA
;
1146 case kTextEncodingMacBengali
:
1147 enc
=wxFONTENCODING_MACBENGALI
;
1149 case kTextEncodingMacTamil
:
1150 enc
= wxFONTENCODING_MACTAMIL
;
1152 case kTextEncodingMacTelugu
:
1153 enc
= wxFONTENCODING_MACTELUGU
;
1155 case kTextEncodingMacKannada
:
1156 enc
= wxFONTENCODING_MACKANNADA
;
1158 case kTextEncodingMacMalayalam
:
1159 enc
= wxFONTENCODING_MACMALAJALAM
;
1161 case kTextEncodingMacSinhalese
:
1162 enc
= wxFONTENCODING_MACSINHALESE
;
1164 case kTextEncodingMacBurmese
:
1165 enc
= wxFONTENCODING_MACBURMESE
;
1167 case kTextEncodingMacKhmer
:
1168 enc
= wxFONTENCODING_MACKHMER
;
1170 case kTextEncodingMacThai
:
1171 enc
= wxFONTENCODING_MACTHAI
;
1173 case kTextEncodingMacLaotian
:
1174 enc
= wxFONTENCODING_MACLAOTIAN
;
1176 case kTextEncodingMacGeorgian
:
1177 enc
= wxFONTENCODING_MACGEORGIAN
;
1179 case kTextEncodingMacArmenian
:
1180 enc
= wxFONTENCODING_MACARMENIAN
;
1182 case kTextEncodingMacChineseSimp
:
1183 enc
= wxFONTENCODING_MACCHINESESIMP
;
1185 case kTextEncodingMacTibetan
:
1186 enc
= wxFONTENCODING_MACTIBETAN
;
1188 case kTextEncodingMacMongolian
:
1189 enc
= wxFONTENCODING_MACMONGOLIAN
;
1191 case kTextEncodingMacEthiopic
:
1192 enc
= wxFONTENCODING_MACETHIOPIC
;
1194 case kTextEncodingMacCentralEurRoman
:
1195 enc
= wxFONTENCODING_MACCENTRALEUR
;
1197 case kTextEncodingMacVietnamese
:
1198 enc
= wxFONTENCODING_MACVIATNAMESE
;
1200 case kTextEncodingMacExtArabic
:
1201 enc
= wxFONTENCODING_MACARABICEXT
;
1203 case kTextEncodingMacSymbol
:
1204 enc
= wxFONTENCODING_MACSYMBOL
;
1206 case kTextEncodingMacDingbats
:
1207 enc
= wxFONTENCODING_MACDINGBATS
;
1209 case kTextEncodingMacTurkish
:
1210 enc
= wxFONTENCODING_MACTURKISH
;
1212 case kTextEncodingMacCroatian
:
1213 enc
= wxFONTENCODING_MACCROATIAN
;
1215 case kTextEncodingMacIcelandic
:
1216 enc
= wxFONTENCODING_MACICELANDIC
;
1218 case kTextEncodingMacRomanian
:
1219 enc
= wxFONTENCODING_MACROMANIAN
;
1221 case kTextEncodingMacCeltic
:
1222 enc
= wxFONTENCODING_MACCELTIC
;
1224 case kTextEncodingMacGaelic
:
1225 enc
= wxFONTENCODING_MACGAELIC
;
1227 case kTextEncodingMacKeyboardGlyphs
:
1228 enc
= wxFONTENCODING_MACKEYBOARD
;
1236 // CFStringRefs (Carbon only)
1241 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1242 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1247 wxMacConvertNewlines13To10( &str
) ;
1249 #if SIZEOF_WCHAR_T == 2
1250 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1251 (UniChar
*)str
.wc_str() , str
.Len() );
1253 wxMBConvUTF16BE converter
;
1254 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1255 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1256 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1257 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1258 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1261 #else // not wxUSE_UNICODE
1262 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1263 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1268 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1270 Size cflen
= CFStringGetLength( m_cfs
) ;
1272 wxChar
* buf
= NULL
;
1275 #if SIZEOF_WCHAR_T == 2
1276 buf
= new wxChar
[ cflen
+ 1 ] ;
1277 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1280 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1281 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1283 wxMBConvUTF16BE converter
;
1284 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1285 buf
= new wxChar
[ noChars
+ 1 ] ;
1286 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1291 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1292 '?' , false , NULL
, 0 , &cStrLen
) ;
1293 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1294 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1295 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1300 wxMacConvertNewlines10To13( buf
) ;
1301 wxString
result(buf
) ;
1306 #endif //TARGET_CARBON
1308 void wxMacConvertNewlines13To10( char * data
)
1311 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1318 void wxMacConvertNewlines10To13( char * data
)
1321 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1328 void wxMacConvertNewlines13To10( wxString
* data
)
1330 size_t len
= data
->Length() ;
1332 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1335 wxString
temp(*data
) ;
1336 wxStringBuffer
buf(*data
,len
) ;
1337 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1339 wxMacConvertNewlines13To10( buf
) ;
1342 void wxMacConvertNewlines10To13( wxString
* data
)
1344 size_t len
= data
->Length() ;
1346 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1349 wxString
temp(*data
) ;
1350 wxStringBuffer
buf(*data
,len
) ;
1351 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1352 wxMacConvertNewlines10To13( buf
) ;
1357 void wxMacConvertNewlines13To10( wxChar
* data
)
1359 wxChar
* buf
= data
;
1360 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1367 void wxMacConvertNewlines10To13( wxChar
* data
)
1369 wxChar
* buf
= data
;
1370 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1378 // ----------------------------------------------------------------------------
1379 // Common Event Support
1380 // ----------------------------------------------------------------------------
1383 extern ProcessSerialNumber gAppProcess
;
1387 ProcessSerialNumber psn
;
1389 psn
.highLongOfPSN
= 0 ;
1390 psn
.lowLongOfPSN
= kCurrentProcess
;
1391 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1395 EventRef dummyEvent
;
1396 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1397 kEventAttributeNone
, &dummyEvent
);
1400 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1401 kEventPriorityHigh
);
1404 PostEvent( nullEvent
, 0 ) ;
1409 WakeUpProcess( &gAppProcess
) ;
1413 #endif // wxUSE_BASE
1418 // ----------------------------------------------------------------------------
1419 // Carbon Event Support
1420 // ----------------------------------------------------------------------------
1423 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1425 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1428 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1430 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1433 // ----------------------------------------------------------------------------
1434 // Control Access Support
1435 // ----------------------------------------------------------------------------
1437 void wxMacControl::Dispose()
1439 ::DisposeControl( m_controlRef
) ;
1440 m_controlRef
= NULL
;
1443 void wxMacControl::SetReference( SInt32 data
)
1445 SetControlReference( m_controlRef
, data
) ;
1448 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
1450 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1453 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
1455 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1458 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1460 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1463 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1465 #if TARGET_API_MAC_OSX
1466 return SendEventToEventTargetWithOptions( event
,
1467 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1469 #pragma unused(inOptions)
1470 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1474 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1476 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1477 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1478 return SendEvent( event
, inOptions
) ;
1481 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1484 memset( &command
, 0 , sizeof(command
) ) ;
1485 command
.commandID
= commandID
;
1486 return SendHICommand( command
, inOptions
) ;
1489 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1491 HiliteControl( m_controlRef
, part
) ;
1492 unsigned long finalTicks
;
1493 Delay( ticks
, &finalTicks
) ;
1494 HiliteControl( m_controlRef
, kControlNoPart
) ;
1497 SInt32
wxMacControl::GetValue() const
1499 return ::GetControl32BitValue( m_controlRef
) ;
1502 SInt32
wxMacControl::GetMaximum() const
1504 return ::GetControl32BitMaximum( m_controlRef
) ;
1507 SInt32
wxMacControl::GetMinimum() const
1509 return ::GetControl32BitMinimum( m_controlRef
) ;
1512 void wxMacControl::SetValue( SInt32 v
)
1514 ::SetControl32BitValue( m_controlRef
, v
) ;
1517 void wxMacControl::SetMinimum( SInt32 v
)
1519 ::SetControl32BitMinimum( m_controlRef
, v
) ;
1522 void wxMacControl::SetMaximum( SInt32 v
)
1524 ::SetControl32BitMaximum( m_controlRef
, v
) ;
1527 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
1529 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1530 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1531 ::SetControl32BitValue( m_controlRef
, value
) ;
1534 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
1536 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
1537 m_controlRef
, focusPart
) ;
1540 bool wxMacControl::HasFocus() const
1542 ControlRef control
;
1543 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1544 return control
== m_controlRef
;
1547 bool wxMacControl::NeedsFocusRect() const
1552 void wxMacControl::VisibilityChanged(bool shown
)
1556 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1559 ControlFontStyleRec fontStyle
;
1560 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1562 switch( font
.MacGetThemeFontID() )
1564 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
1565 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
1566 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
1567 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
1569 fontStyle
.flags
= kControlUseFontMask
;
1573 fontStyle
.font
= font
.MacGetFontNum() ;
1574 fontStyle
.style
= font
.MacGetFontStyle() ;
1575 fontStyle
.size
= font
.MacGetFontSize() ;
1576 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1579 fontStyle
.just
= teJustLeft
;
1580 fontStyle
.flags
|= kControlUseJustMask
;
1581 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1582 fontStyle
.just
= teJustCenter
;
1583 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1584 fontStyle
.just
= teJustRight
;
1587 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1588 // won't get grayed out by the system anymore
1590 if ( foreground
!= *wxBLACK
)
1592 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
1593 fontStyle
.flags
|= kControlUseForeColorMask
;
1596 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1599 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1602 // setting up a color proc is not recommended anymore
1605 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1607 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1608 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1611 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1613 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
1616 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1618 SetControlAction( m_controlRef
, actionProc
) ;
1621 void wxMacControl::SetViewSize( SInt32 viewSize
)
1623 SetControlViewSize(m_controlRef
, viewSize
) ;
1626 SInt32
wxMacControl::GetViewSize() const
1628 return GetControlViewSize( m_controlRef
) ;
1631 bool wxMacControl::IsVisible() const
1633 return IsControlVisible( m_controlRef
) ;
1636 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1638 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
1641 bool wxMacControl::IsEnabled() const
1643 #if TARGET_API_MAC_OSX
1644 return IsControlEnabled( m_controlRef
) ;
1646 return IsControlActive( m_controlRef
) ;
1650 bool wxMacControl::IsActive() const
1652 return IsControlActive( m_controlRef
) ;
1655 void wxMacControl::Enable( bool enable
)
1657 #if TARGET_API_MAC_OSX
1659 EnableControl( m_controlRef
) ;
1661 DisableControl( m_controlRef
) ;
1664 ActivateControl( m_controlRef
) ;
1666 DeactivateControl( m_controlRef
) ;
1670 void wxMacControl::SetDrawingEnabled( bool enable
)
1672 #if TARGET_API_MAC_OSX
1673 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1677 bool wxMacControl::GetNeedsDisplay() const
1679 #if TARGET_API_MAC_OSX
1680 return HIViewGetNeedsDisplay( m_controlRef
) ;
1686 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1688 #if TARGET_API_MAC_OSX
1689 if ( where
!= NULL
)
1690 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1692 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1696 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1698 #if TARGET_API_MAC_OSX
1702 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1703 pt
->x
= (int)hiPoint
.x
;
1704 pt
->y
= (int)hiPoint
.y
;
1708 void wxMacControl::SetRect( Rect
*r
)
1710 #if TARGET_API_MAC_OSX
1711 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1712 //CGPoint and CGSize, which have two floats each
1713 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} } ;
1714 HIViewSetFrame ( m_controlRef
, &hir
) ;
1716 SetControlBounds( m_controlRef
, r
) ;
1721 void wxMacControl::GetRect( Rect
*r
)
1723 GetControlBounds( m_controlRef
, r
) ;
1726 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1728 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1731 void wxMacControl::GetBestRect( Rect
*r
)
1733 short baselineoffset
;
1734 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1737 void wxMacControl::SetTitle( const wxString
&title
)
1739 wxFontEncoding encoding
;
1742 encoding
= m_font
.GetEncoding();
1744 encoding
= wxFont::GetDefaultEncoding();
1746 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1749 void wxMacControl::GetFeatures( UInt32
* features
)
1751 GetControlFeatures( m_controlRef
, features
) ;
1754 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1756 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1759 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1761 #if TARGET_API_MAC_OSX
1762 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1763 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1770 #if TARGET_API_MAC_OSX
1771 // SetNeedsDisplay would not invalidate the children
1772 static void InvalidateControlAndChildren( HIViewRef control
)
1774 HIViewSetNeedsDisplay( control
, true ) ;
1775 UInt16 childrenCount
= 0 ;
1776 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1777 if ( err
== errControlIsNotEmbedder
)
1779 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1781 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1784 err
= GetIndexedSubControl( control
, i
, & child
) ;
1785 if ( err
== errControlIsNotEmbedder
)
1787 InvalidateControlAndChildren( child
) ;
1792 void wxMacControl::InvalidateWithChildren()
1794 #if TARGET_API_MAC_OSX
1795 InvalidateControlAndChildren( m_controlRef
) ;
1799 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1801 #if TARGET_API_MAC_OSX
1802 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1803 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1808 // SetNeedsDisplay would not invalidate the children
1814 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1816 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1819 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1820 DataBrowserTableViewColumnIndex position
)
1822 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1825 OSStatus
wxMacControl::AutoSizeListViewColumns()
1827 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1830 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1832 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1835 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1837 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1840 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1842 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1845 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1847 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1850 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1851 const DataBrowserItemID
* items
,
1852 DataBrowserPropertyID preSortProperty
,
1853 DataBrowserPropertyID propertyID
)
1855 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1858 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1860 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1863 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1864 const DataBrowserItemID
* items
,
1865 DataBrowserPropertyID preSortProperty
)
1867 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1870 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1871 const DataBrowserItemID
* items
,
1872 DataBrowserPropertyID preSortProperty
)
1874 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1877 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1878 DataBrowserPropertyID propertyID
,
1879 DataBrowserRevealOptions options
)
1881 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1884 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1885 const DataBrowserItemID
* items
,
1886 DataBrowserSetOption operation
)
1888 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1895 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1897 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;