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"
43 #if TARGET_API_MAC_OSX
44 #include <CoreServices/CoreServices.h>
46 #include <DriverServices.h>
47 #include <Multiprocessing.h>
50 #include <ATSUnicode.h>
51 #include <TextCommon.h>
52 #include <TextEncodingConverter.h>
54 #include "wx/mac/private.h" // includes mac headers
56 #if defined(__MWERKS__) && wxUSE_UNICODE
60 // ---------------------------------------------------------------------------
61 // code used in both base and GUI compilation
62 // ---------------------------------------------------------------------------
64 // our OS version is the same in non GUI and GUI cases
65 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
69 // are there x-platform conventions ?
71 Gestalt(gestaltSystemVersion
, &theSystem
) ;
72 if (minorVsn
!= NULL
) {
73 *minorVsn
= (theSystem
& 0xFF ) ;
75 if (majorVsn
!= NULL
) {
76 *majorVsn
= (theSystem
>> 8 ) ;
88 // ----------------------------------------------------------------------------
90 // ----------------------------------------------------------------------------
92 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
94 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
96 #ifndef __MetroNubUtils__
97 #include "MetroNubUtils.h"
104 #if TARGET_API_MAC_CARBON
106 #include <CodeFragments.h>
108 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
110 ProcPtr gCallUniversalProc_Proc
= NULL
;
114 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
116 static long fRunOnce
= false;
118 /* ---------------------------------------------------------------------------
120 --------------------------------------------------------------------------- */
122 Boolean
IsMetroNubInstalled()
129 gMetroNubEntry
= NULL
;
131 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
133 /* look for MetroNub's Gestalt selector */
134 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
137 #if TARGET_API_MAC_CARBON
138 if (gCallUniversalProc_Proc
== NULL
)
140 CFragConnectionID connectionID
;
143 ProcPtr symbolAddress
;
145 CFragSymbolClass symbolClass
;
147 symbolAddress
= NULL
;
148 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
149 &connectionID
, &mainAddress
, errorString
);
153 gCallUniversalProc_Proc
= NULL
;
157 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
158 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
162 gCallUniversalProc_Proc
= NULL
;
169 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
171 /* make sure the version of the API is compatible */
172 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
173 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
174 gMetroNubEntry
= block
; /* success! */
183 #if TARGET_API_MAC_CARBON
184 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
186 return (gMetroNubEntry
!= NULL
);
190 /* ---------------------------------------------------------------------------
191 IsMWDebuggerRunning [v1 API]
192 --------------------------------------------------------------------------- */
194 Boolean
IsMWDebuggerRunning()
196 if (IsMetroNubInstalled())
197 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
202 /* ---------------------------------------------------------------------------
203 AmIBeingMWDebugged [v1 API]
204 --------------------------------------------------------------------------- */
206 Boolean
AmIBeingMWDebugged()
208 if (IsMetroNubInstalled())
209 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
216 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
221 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
226 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
230 // defined in unix/utilsunx.cpp for Mac OS X
232 // get full hostname (with domain name if possible)
233 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
235 return wxGetHostName(buf
, maxSize
);
238 // Get hostname only (without domain name)
239 bool wxGetHostName(wxChar
*buf
, int maxSize
)
241 // Gets Chooser name of user by examining a System resource.
243 const short kComputerNameID
= -16413;
245 short oldResFile
= CurResFile() ;
247 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
248 UseResFile(oldResFile
);
250 if (chooserName
&& *chooserName
)
252 HLock( (Handle
) chooserName
) ;
253 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
254 HUnlock( (Handle
) chooserName
) ;
255 ReleaseResource( (Handle
) chooserName
) ;
256 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
264 // Get user ID e.g. jacs
265 bool wxGetUserId(wxChar
*buf
, int maxSize
)
267 return wxGetUserName( buf
, maxSize
) ;
270 const wxChar
* wxGetHomeDir(wxString
*pstr
)
272 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
273 return pstr
->c_str() ;
276 // Get user name e.g. Stefan Csomor
277 bool wxGetUserName(wxChar
*buf
, int maxSize
)
279 // Gets Chooser name of user by examining a System resource.
281 const short kChooserNameID
= -16096;
283 short oldResFile
= CurResFile() ;
285 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
286 UseResFile(oldResFile
);
288 if (chooserName
&& *chooserName
)
290 HLock( (Handle
) chooserName
) ;
291 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
292 HUnlock( (Handle
) chooserName
) ;
293 ReleaseResource( (Handle
) chooserName
) ;
294 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
302 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
308 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
310 // TODO : under classic there is no environement support, under X yes
314 // set the env var name to the given value, return TRUE on success
315 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
317 // TODO : under classic there is no environement support, under X yes
322 // Execute a program in an Interactive Shell
324 bool wxShell(const wxString
& command
)
330 // Shutdown or reboot the PC
331 bool wxShutdown(wxShutdownFlags wFlags
)
337 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
338 long wxGetFreeMemory()
345 void wxMicroSleep(unsigned long microseconds
)
347 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
348 MPDelayUntil( & wakeup
);
351 void wxMilliSleep(unsigned long milliseconds
)
353 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
354 MPDelayUntil( & wakeup
);
357 void wxSleep(int nSecs
)
359 wxMilliSleep(1000*nSecs
);
364 // Consume all events until no more left
369 #endif // !__DARWIN__
377 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
379 static wxToolkitInfo info
;
380 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
381 info
.name
= _T("wxBase");
389 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
391 static wxToolkitInfo info
;
392 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
393 info
.shortName
= _T("mac");
394 info
.name
= _T("wxMac");
395 #ifdef __WXUNIVERSAL__
396 info
.shortName
<< _T("univ");
397 info
.name
<< _T("/wxUniversal");
402 // Reading and writing resources (eg WIN.INI, .Xdefaults)
404 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
410 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
413 buf
.Printf(wxT("%.4f"), value
);
415 return wxWriteResource(section
, entry
, buf
, file
);
418 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
421 buf
.Printf(wxT("%ld"), value
);
423 return wxWriteResource(section
, entry
, buf
, file
);
426 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
429 buf
.Printf(wxT("%d"), value
);
431 return wxWriteResource(section
, entry
, buf
, file
);
434 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
440 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
443 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
446 *value
= (float)strtod(s
, NULL
);
453 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
456 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
459 *value
= strtol(s
, NULL
, 10);
466 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
469 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
472 *value
= (int)strtol(s
, NULL
, 10);
478 #endif // wxUSE_RESOURCES
480 int gs_wxBusyCursorCount
= 0;
481 extern wxCursor gMacCurrentCursor
;
482 wxCursor gMacStoredActiveCursor
;
484 // Set the cursor to the busy cursor for all windows
485 void wxBeginBusyCursor(wxCursor
*cursor
)
487 if (gs_wxBusyCursorCount
++ == 0)
489 gMacStoredActiveCursor
= gMacCurrentCursor
;
490 cursor
->MacInstall() ;
492 //else: nothing to do, already set
495 // Restore cursor to normal
496 void wxEndBusyCursor()
498 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
499 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
501 if (--gs_wxBusyCursorCount
== 0)
503 gMacStoredActiveCursor
.MacInstall() ;
504 gMacStoredActiveCursor
= wxNullCursor
;
508 // TRUE if we're between the above two calls
511 return (gs_wxBusyCursorCount
> 0);
518 wxString
wxMacFindFolder( short vol
,
520 Boolean createFolder
)
525 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
526 strDir
= wxMacFSRefToPath( &fsRef
) + wxFILE_SEP_PATH
;
535 // Check whether this window wants to process messages, e.g. Stop button
536 // in long calculations.
537 bool wxCheckForInterrupt(wxWindow
*wnd
)
543 void wxGetMousePosition( int* x
, int* y
)
548 LocalToGlobal( &pt
) ;
553 // Return TRUE if we have a colour display
554 bool wxColourDisplay()
559 // Returns depth of screen
563 SetRect(&globRect
, -32760, -32760, 32760, 32760);
564 GDHandle theMaxDevice
;
567 theMaxDevice
= GetMaxDevice(&globRect
);
568 if (theMaxDevice
!= nil
)
569 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
574 // Get size of display
575 void wxDisplaySize(int *width
, int *height
)
578 GetQDGlobalsScreenBits( &screenBits
);
581 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
583 if (height
!= NULL
) {
584 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
588 void wxDisplaySizeMM(int *width
, int *height
)
590 wxDisplaySize(width
, height
);
591 // on mac 72 is fixed (at least now ;-)
592 float cvPt2Mm
= 25.4 / 72;
595 *width
= int( *width
* cvPt2Mm
);
597 if (height
!= NULL
) {
598 *height
= int( *height
* cvPt2Mm
);
602 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
605 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
611 *width
= r
.right
- r
.left
;
613 *height
= r
.bottom
- r
.top
;
616 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
618 return wxGenericFindWindowAtPoint(pt
);
625 wxString
wxGetOsDescription()
627 #ifdef WXWIN_OS_DESCRIPTION
628 // use configure generated description if available
629 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
631 return wxT("MacOS") ; //TODO:define further
636 wxChar
*wxGetUserHome (const wxString
& user
)
642 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
652 int pos
= p
.Find(':') ;
653 if ( pos
!= wxNOT_FOUND
) {
662 err
= wxMacPathToFSRef( p
, &fsRef
) ;
665 FSVolumeRefNum vRefNum
;
666 err
= FSGetVRefNum( &fsRef
, &vRefNum
) ;
669 UInt64 freeBytes
, totalBytes
;
670 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
) ;
674 *pTotal
= wxLongLong( totalBytes
) ;
676 *pFree
= wxLongLong( freeBytes
) ;
681 return err
== noErr
;
683 #endif // !__DARWIN__
685 //---------------------------------------------------------------------------
686 // wxMac Specific utility functions
687 //---------------------------------------------------------------------------
689 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
691 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
692 int len
= strlen(buf
) ;
697 memcpy( (char*) &to
[1] , buf
, len
) ;
700 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
702 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
706 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
708 TextEncodingBase enc
= 0 ;
709 if ( encoding
== wxFONTENCODING_DEFAULT
)
712 encoding
= wxFont::GetDefaultEncoding() ;
714 encoding
= wxLocale::GetSystemEncoding() ;
720 case wxFONTENCODING_ISO8859_1
:
721 enc
= kTextEncodingISOLatin1
;
723 case wxFONTENCODING_ISO8859_2
:
724 enc
= kTextEncodingISOLatin2
;
726 case wxFONTENCODING_ISO8859_3
:
727 enc
= kTextEncodingISOLatin3
;
729 case wxFONTENCODING_ISO8859_4
:
730 enc
= kTextEncodingISOLatin4
;
732 case wxFONTENCODING_ISO8859_5
:
733 enc
= kTextEncodingISOLatinCyrillic
;
735 case wxFONTENCODING_ISO8859_6
:
736 enc
= kTextEncodingISOLatinArabic
;
738 case wxFONTENCODING_ISO8859_7
:
739 enc
= kTextEncodingISOLatinGreek
;
741 case wxFONTENCODING_ISO8859_8
:
742 enc
= kTextEncodingISOLatinHebrew
;
744 case wxFONTENCODING_ISO8859_9
:
745 enc
= kTextEncodingISOLatin5
;
747 case wxFONTENCODING_ISO8859_10
:
748 enc
= kTextEncodingISOLatin6
;
750 case wxFONTENCODING_ISO8859_13
:
751 enc
= kTextEncodingISOLatin7
;
753 case wxFONTENCODING_ISO8859_14
:
754 enc
= kTextEncodingISOLatin8
;
756 case wxFONTENCODING_ISO8859_15
:
757 enc
= kTextEncodingISOLatin9
;
760 case wxFONTENCODING_KOI8
:
761 enc
= kTextEncodingKOI8_R
;
763 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
764 enc
= kTextEncodingDOSRussian
;
767 case wxFONTENCODING_BULGARIAN :
771 case wxFONTENCODING_CP437
:
772 enc
=kTextEncodingDOSLatinUS
;
774 case wxFONTENCODING_CP850
:
775 enc
= kTextEncodingDOSLatin1
;
777 case wxFONTENCODING_CP852
:
778 enc
= kTextEncodingDOSLatin2
;
780 case wxFONTENCODING_CP855
:
781 enc
= kTextEncodingDOSCyrillic
;
783 case wxFONTENCODING_CP866
:
784 enc
=kTextEncodingDOSRussian
;
786 case wxFONTENCODING_CP874
:
787 enc
= kTextEncodingDOSThai
;
789 case wxFONTENCODING_CP932
:
790 enc
= kTextEncodingDOSJapanese
;
792 case wxFONTENCODING_CP936
:
793 enc
=kTextEncodingDOSChineseSimplif
;
795 case wxFONTENCODING_CP949
:
796 enc
= kTextEncodingDOSKorean
;
798 case wxFONTENCODING_CP950
:
799 enc
= kTextEncodingDOSChineseTrad
;
802 case wxFONTENCODING_CP1250
:
803 enc
= kTextEncodingWindowsLatin2
;
805 case wxFONTENCODING_CP1251
:
806 enc
=kTextEncodingWindowsCyrillic
;
808 case wxFONTENCODING_CP1252
:
809 enc
=kTextEncodingWindowsLatin1
;
811 case wxFONTENCODING_CP1253
:
812 enc
= kTextEncodingWindowsGreek
;
814 case wxFONTENCODING_CP1254
:
815 enc
= kTextEncodingWindowsLatin5
;
817 case wxFONTENCODING_CP1255
:
818 enc
=kTextEncodingWindowsHebrew
;
820 case wxFONTENCODING_CP1256
:
821 enc
=kTextEncodingWindowsArabic
;
823 case wxFONTENCODING_CP1257
:
824 enc
= kTextEncodingWindowsBalticRim
;
827 case wxFONTENCODING_UTF7
:
828 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
830 case wxFONTENCODING_UTF8
:
831 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
833 case wxFONTENCODING_EUC_JP
:
834 enc
= kTextEncodingEUC_JP
;
836 case wxFONTENCODING_UTF16BE
:
837 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
839 case wxFONTENCODING_UTF16LE
:
840 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
842 case wxFONTENCODING_UTF32BE
:
843 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
845 case wxFONTENCODING_UTF32LE
:
846 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
849 case wxFONTENCODING_MACROMAN
:
850 enc
= kTextEncodingMacRoman
;
852 case wxFONTENCODING_MACJAPANESE
:
853 enc
= kTextEncodingMacJapanese
;
855 case wxFONTENCODING_MACCHINESETRAD
:
856 enc
= kTextEncodingMacChineseTrad
;
858 case wxFONTENCODING_MACKOREAN
:
859 enc
= kTextEncodingMacKorean
;
861 case wxFONTENCODING_MACARABIC
:
862 enc
= kTextEncodingMacArabic
;
864 case wxFONTENCODING_MACHEBREW
:
865 enc
= kTextEncodingMacHebrew
;
867 case wxFONTENCODING_MACGREEK
:
868 enc
= kTextEncodingMacGreek
;
870 case wxFONTENCODING_MACCYRILLIC
:
871 enc
= kTextEncodingMacCyrillic
;
873 case wxFONTENCODING_MACDEVANAGARI
:
874 enc
= kTextEncodingMacDevanagari
;
876 case wxFONTENCODING_MACGURMUKHI
:
877 enc
= kTextEncodingMacGurmukhi
;
879 case wxFONTENCODING_MACGUJARATI
:
880 enc
= kTextEncodingMacGujarati
;
882 case wxFONTENCODING_MACORIYA
:
883 enc
= kTextEncodingMacOriya
;
885 case wxFONTENCODING_MACBENGALI
:
886 enc
= kTextEncodingMacBengali
;
888 case wxFONTENCODING_MACTAMIL
:
889 enc
= kTextEncodingMacTamil
;
891 case wxFONTENCODING_MACTELUGU
:
892 enc
= kTextEncodingMacTelugu
;
894 case wxFONTENCODING_MACKANNADA
:
895 enc
= kTextEncodingMacKannada
;
897 case wxFONTENCODING_MACMALAJALAM
:
898 enc
= kTextEncodingMacMalayalam
;
900 case wxFONTENCODING_MACSINHALESE
:
901 enc
= kTextEncodingMacSinhalese
;
903 case wxFONTENCODING_MACBURMESE
:
904 enc
= kTextEncodingMacBurmese
;
906 case wxFONTENCODING_MACKHMER
:
907 enc
= kTextEncodingMacKhmer
;
909 case wxFONTENCODING_MACTHAI
:
910 enc
= kTextEncodingMacThai
;
912 case wxFONTENCODING_MACLAOTIAN
:
913 enc
= kTextEncodingMacLaotian
;
915 case wxFONTENCODING_MACGEORGIAN
:
916 enc
= kTextEncodingMacGeorgian
;
918 case wxFONTENCODING_MACARMENIAN
:
919 enc
= kTextEncodingMacArmenian
;
921 case wxFONTENCODING_MACCHINESESIMP
:
922 enc
= kTextEncodingMacChineseSimp
;
924 case wxFONTENCODING_MACTIBETAN
:
925 enc
= kTextEncodingMacTibetan
;
927 case wxFONTENCODING_MACMONGOLIAN
:
928 enc
= kTextEncodingMacMongolian
;
930 case wxFONTENCODING_MACETHIOPIC
:
931 enc
= kTextEncodingMacEthiopic
;
933 case wxFONTENCODING_MACCENTRALEUR
:
934 enc
= kTextEncodingMacCentralEurRoman
;
936 case wxFONTENCODING_MACVIATNAMESE
:
937 enc
= kTextEncodingMacVietnamese
;
939 case wxFONTENCODING_MACARABICEXT
:
940 enc
= kTextEncodingMacExtArabic
;
942 case wxFONTENCODING_MACSYMBOL
:
943 enc
= kTextEncodingMacSymbol
;
945 case wxFONTENCODING_MACDINGBATS
:
946 enc
= kTextEncodingMacDingbats
;
948 case wxFONTENCODING_MACTURKISH
:
949 enc
= kTextEncodingMacTurkish
;
951 case wxFONTENCODING_MACCROATIAN
:
952 enc
= kTextEncodingMacCroatian
;
954 case wxFONTENCODING_MACICELANDIC
:
955 enc
= kTextEncodingMacIcelandic
;
957 case wxFONTENCODING_MACROMANIAN
:
958 enc
= kTextEncodingMacRomanian
;
960 case wxFONTENCODING_MACCELTIC
:
961 enc
= kTextEncodingMacCeltic
;
963 case wxFONTENCODING_MACGAELIC
:
964 enc
= kTextEncodingMacGaelic
;
966 case wxFONTENCODING_MACKEYBOARD
:
967 enc
= kTextEncodingMacKeyboardGlyphs
;
976 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
978 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
982 case kTextEncodingISOLatin1
:
983 enc
= wxFONTENCODING_ISO8859_1
;
985 case kTextEncodingISOLatin2
:
986 enc
= wxFONTENCODING_ISO8859_2
;
988 case kTextEncodingISOLatin3
:
989 enc
= wxFONTENCODING_ISO8859_3
;
991 case kTextEncodingISOLatin4
:
992 enc
= wxFONTENCODING_ISO8859_4
;
994 case kTextEncodingISOLatinCyrillic
:
995 enc
= wxFONTENCODING_ISO8859_5
;
997 case kTextEncodingISOLatinArabic
:
998 enc
= wxFONTENCODING_ISO8859_6
;
1000 case kTextEncodingISOLatinGreek
:
1001 enc
= wxFONTENCODING_ISO8859_7
;
1003 case kTextEncodingISOLatinHebrew
:
1004 enc
= wxFONTENCODING_ISO8859_8
;
1006 case kTextEncodingISOLatin5
:
1007 enc
= wxFONTENCODING_ISO8859_9
;
1009 case kTextEncodingISOLatin6
:
1010 enc
= wxFONTENCODING_ISO8859_10
;
1012 case kTextEncodingISOLatin7
:
1013 enc
= wxFONTENCODING_ISO8859_13
;
1015 case kTextEncodingISOLatin8
:
1016 enc
= wxFONTENCODING_ISO8859_14
;
1018 case kTextEncodingISOLatin9
:
1019 enc
=wxFONTENCODING_ISO8859_15
;
1022 case kTextEncodingKOI8_R
:
1023 enc
= wxFONTENCODING_KOI8
;
1027 enc = wxFONTENCODING_BULGARIAN;
1030 case kTextEncodingDOSLatinUS
:
1031 enc
= wxFONTENCODING_CP437
;
1033 case kTextEncodingDOSLatin1
:
1034 enc
= wxFONTENCODING_CP850
;
1036 case kTextEncodingDOSLatin2
:
1037 enc
=wxFONTENCODING_CP852
;
1039 case kTextEncodingDOSCyrillic
:
1040 enc
= wxFONTENCODING_CP855
;
1042 case kTextEncodingDOSRussian
:
1043 enc
= wxFONTENCODING_CP866
;
1045 case kTextEncodingDOSThai
:
1046 enc
=wxFONTENCODING_CP874
;
1048 case kTextEncodingDOSJapanese
:
1049 enc
= wxFONTENCODING_CP932
;
1051 case kTextEncodingDOSChineseSimplif
:
1052 enc
= wxFONTENCODING_CP936
;
1054 case kTextEncodingDOSKorean
:
1055 enc
= wxFONTENCODING_CP949
;
1057 case kTextEncodingDOSChineseTrad
:
1058 enc
= wxFONTENCODING_CP950
;
1061 case kTextEncodingWindowsLatin2
:
1062 enc
= wxFONTENCODING_CP1250
;
1064 case kTextEncodingWindowsCyrillic
:
1065 enc
= wxFONTENCODING_CP1251
;
1067 case kTextEncodingWindowsLatin1
:
1068 enc
= wxFONTENCODING_CP1252
;
1070 case kTextEncodingWindowsGreek
:
1071 enc
= wxFONTENCODING_CP1253
;
1073 case kTextEncodingWindowsLatin5
:
1074 enc
= wxFONTENCODING_CP1254
;
1076 case kTextEncodingWindowsHebrew
:
1077 enc
= wxFONTENCODING_CP1255
;
1079 case kTextEncodingWindowsArabic
:
1080 enc
= wxFONTENCODING_CP1256
;
1082 case kTextEncodingWindowsBalticRim
:
1083 enc
=wxFONTENCODING_CP1257
;
1085 case kTextEncodingEUC_JP
:
1086 enc
= wxFONTENCODING_EUC_JP
;
1089 case wxFONTENCODING_UTF7 :
1090 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1092 case wxFONTENCODING_UTF8 :
1093 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1095 case wxFONTENCODING_UTF16BE :
1096 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1098 case wxFONTENCODING_UTF16LE :
1099 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1101 case wxFONTENCODING_UTF32BE :
1102 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1104 case wxFONTENCODING_UTF32LE :
1105 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1108 case kTextEncodingMacRoman
:
1109 enc
= wxFONTENCODING_MACROMAN
;
1111 case kTextEncodingMacJapanese
:
1112 enc
= wxFONTENCODING_MACJAPANESE
;
1114 case kTextEncodingMacChineseTrad
:
1115 enc
= wxFONTENCODING_MACCHINESETRAD
;
1117 case kTextEncodingMacKorean
:
1118 enc
= wxFONTENCODING_MACKOREAN
;
1120 case kTextEncodingMacArabic
:
1121 enc
=wxFONTENCODING_MACARABIC
;
1123 case kTextEncodingMacHebrew
:
1124 enc
= wxFONTENCODING_MACHEBREW
;
1126 case kTextEncodingMacGreek
:
1127 enc
= wxFONTENCODING_MACGREEK
;
1129 case kTextEncodingMacCyrillic
:
1130 enc
= wxFONTENCODING_MACCYRILLIC
;
1132 case kTextEncodingMacDevanagari
:
1133 enc
= wxFONTENCODING_MACDEVANAGARI
;
1135 case kTextEncodingMacGurmukhi
:
1136 enc
= wxFONTENCODING_MACGURMUKHI
;
1138 case kTextEncodingMacGujarati
:
1139 enc
= wxFONTENCODING_MACGUJARATI
;
1141 case kTextEncodingMacOriya
:
1142 enc
=wxFONTENCODING_MACORIYA
;
1144 case kTextEncodingMacBengali
:
1145 enc
=wxFONTENCODING_MACBENGALI
;
1147 case kTextEncodingMacTamil
:
1148 enc
= wxFONTENCODING_MACTAMIL
;
1150 case kTextEncodingMacTelugu
:
1151 enc
= wxFONTENCODING_MACTELUGU
;
1153 case kTextEncodingMacKannada
:
1154 enc
= wxFONTENCODING_MACKANNADA
;
1156 case kTextEncodingMacMalayalam
:
1157 enc
= wxFONTENCODING_MACMALAJALAM
;
1159 case kTextEncodingMacSinhalese
:
1160 enc
= wxFONTENCODING_MACSINHALESE
;
1162 case kTextEncodingMacBurmese
:
1163 enc
= wxFONTENCODING_MACBURMESE
;
1165 case kTextEncodingMacKhmer
:
1166 enc
= wxFONTENCODING_MACKHMER
;
1168 case kTextEncodingMacThai
:
1169 enc
= wxFONTENCODING_MACTHAI
;
1171 case kTextEncodingMacLaotian
:
1172 enc
= wxFONTENCODING_MACLAOTIAN
;
1174 case kTextEncodingMacGeorgian
:
1175 enc
= wxFONTENCODING_MACGEORGIAN
;
1177 case kTextEncodingMacArmenian
:
1178 enc
= wxFONTENCODING_MACARMENIAN
;
1180 case kTextEncodingMacChineseSimp
:
1181 enc
= wxFONTENCODING_MACCHINESESIMP
;
1183 case kTextEncodingMacTibetan
:
1184 enc
= wxFONTENCODING_MACTIBETAN
;
1186 case kTextEncodingMacMongolian
:
1187 enc
= wxFONTENCODING_MACMONGOLIAN
;
1189 case kTextEncodingMacEthiopic
:
1190 enc
= wxFONTENCODING_MACETHIOPIC
;
1192 case kTextEncodingMacCentralEurRoman
:
1193 enc
= wxFONTENCODING_MACCENTRALEUR
;
1195 case kTextEncodingMacVietnamese
:
1196 enc
= wxFONTENCODING_MACVIATNAMESE
;
1198 case kTextEncodingMacExtArabic
:
1199 enc
= wxFONTENCODING_MACARABICEXT
;
1201 case kTextEncodingMacSymbol
:
1202 enc
= wxFONTENCODING_MACSYMBOL
;
1204 case kTextEncodingMacDingbats
:
1205 enc
= wxFONTENCODING_MACDINGBATS
;
1207 case kTextEncodingMacTurkish
:
1208 enc
= wxFONTENCODING_MACTURKISH
;
1210 case kTextEncodingMacCroatian
:
1211 enc
= wxFONTENCODING_MACCROATIAN
;
1213 case kTextEncodingMacIcelandic
:
1214 enc
= wxFONTENCODING_MACICELANDIC
;
1216 case kTextEncodingMacRomanian
:
1217 enc
= wxFONTENCODING_MACROMANIAN
;
1219 case kTextEncodingMacCeltic
:
1220 enc
= wxFONTENCODING_MACCELTIC
;
1222 case kTextEncodingMacGaelic
:
1223 enc
= wxFONTENCODING_MACGAELIC
;
1225 case kTextEncodingMacKeyboardGlyphs
:
1226 enc
= wxFONTENCODING_MACKEYBOARD
;
1234 // CFStringRefs (Carbon only)
1239 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1240 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1245 wxMacConvertNewlines13To10( &str
) ;
1247 #if SIZEOF_WCHAR_T == 2
1248 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1249 (UniChar
*)str
.wc_str() , str
.Len() );
1251 wxMBConvUTF16BE converter
;
1252 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1253 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1254 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1255 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1256 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1259 #else // not wxUSE_UNICODE
1260 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1261 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1266 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1268 Size cflen
= CFStringGetLength( m_cfs
) ;
1270 wxChar
* buf
= NULL
;
1273 #if SIZEOF_WCHAR_T == 2
1274 buf
= new wxChar
[ cflen
+ 1 ] ;
1275 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1278 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1279 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1281 wxMBConvUTF16BE converter
;
1282 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1283 buf
= new wxChar
[ noChars
+ 1 ] ;
1284 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1289 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1290 '?' , false , NULL
, 0 , &cStrLen
) ;
1291 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1292 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1293 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1298 wxMacConvertNewlines10To13( buf
) ;
1299 wxString
result(buf
) ;
1304 #endif //TARGET_CARBON
1306 void wxMacConvertNewlines13To10( char * data
)
1309 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1316 void wxMacConvertNewlines10To13( char * data
)
1319 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1326 void wxMacConvertNewlines13To10( wxString
* data
)
1328 size_t len
= data
->Length() ;
1330 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1333 wxString
temp(*data
) ;
1334 wxStringBuffer
buf(*data
,len
) ;
1335 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1337 wxMacConvertNewlines13To10( buf
) ;
1340 void wxMacConvertNewlines10To13( wxString
* data
)
1342 size_t len
= data
->Length() ;
1344 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1347 wxString
temp(*data
) ;
1348 wxStringBuffer
buf(*data
,len
) ;
1349 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1350 wxMacConvertNewlines10To13( buf
) ;
1355 void wxMacConvertNewlines13To10( wxChar
* data
)
1357 wxChar
* buf
= data
;
1358 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1365 void wxMacConvertNewlines10To13( wxChar
* data
)
1367 wxChar
* buf
= data
;
1368 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1376 // ----------------------------------------------------------------------------
1377 // Common Event Support
1378 // ----------------------------------------------------------------------------
1381 extern ProcessSerialNumber gAppProcess
;
1385 ProcessSerialNumber psn
;
1387 psn
.highLongOfPSN
= 0 ;
1388 psn
.lowLongOfPSN
= kCurrentProcess
;
1389 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1393 EventRef dummyEvent
;
1394 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1395 kEventAttributeNone
, &dummyEvent
);
1398 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1399 kEventPriorityHigh
);
1402 PostEvent( nullEvent
, 0 ) ;
1407 WakeUpProcess( &gAppProcess
) ;
1411 #endif // wxUSE_BASE
1416 // ----------------------------------------------------------------------------
1417 // Carbon Event Support
1418 // ----------------------------------------------------------------------------
1421 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1423 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1426 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1428 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1431 // ----------------------------------------------------------------------------
1432 // Control Access Support
1433 // ----------------------------------------------------------------------------
1435 void wxMacControl::Dispose()
1437 ::DisposeControl( m_controlRef
) ;
1438 m_controlRef
= NULL
;
1441 void wxMacControl::SetReference( SInt32 data
)
1443 SetControlReference( m_controlRef
, data
) ;
1446 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
1448 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1451 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
1453 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1456 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1458 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1461 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1463 #if TARGET_API_MAC_OSX
1464 return SendEventToEventTargetWithOptions( event
,
1465 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1467 #pragma unused(inOptions)
1468 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1472 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1474 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1475 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1476 return SendEvent( event
, inOptions
) ;
1479 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1482 memset( &command
, 0 , sizeof(command
) ) ;
1483 command
.commandID
= commandID
;
1484 return SendHICommand( command
, inOptions
) ;
1487 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1489 HiliteControl( m_controlRef
, part
) ;
1490 unsigned long finalTicks
;
1491 Delay( ticks
, &finalTicks
) ;
1492 HiliteControl( m_controlRef
, kControlNoPart
) ;
1495 SInt32
wxMacControl::GetValue() const
1497 return ::GetControl32BitValue( m_controlRef
) ;
1500 SInt32
wxMacControl::GetMaximum() const
1502 return ::GetControl32BitMaximum( m_controlRef
) ;
1505 SInt32
wxMacControl::GetMinimum() const
1507 return ::GetControl32BitMinimum( m_controlRef
) ;
1510 void wxMacControl::SetValue( SInt32 v
)
1512 ::SetControl32BitValue( m_controlRef
, v
) ;
1515 void wxMacControl::SetMinimum( SInt32 v
)
1517 ::SetControl32BitMinimum( m_controlRef
, v
) ;
1520 void wxMacControl::SetMaximum( SInt32 v
)
1522 ::SetControl32BitMaximum( m_controlRef
, v
) ;
1525 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
1527 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1528 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1529 ::SetControl32BitValue( m_controlRef
, value
) ;
1532 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
1534 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
1535 m_controlRef
, focusPart
) ;
1538 bool wxMacControl::HasFocus() const
1540 ControlRef control
;
1541 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1542 return control
== m_controlRef
;
1545 bool wxMacControl::NeedsFocusRect() const
1550 void wxMacControl::VisibilityChanged(bool shown
)
1554 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1557 ControlFontStyleRec fontStyle
;
1558 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1560 switch( font
.MacGetThemeFontID() )
1562 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
1563 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
1564 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
1565 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
1567 fontStyle
.flags
= kControlUseFontMask
;
1571 fontStyle
.font
= font
.MacGetFontNum() ;
1572 fontStyle
.style
= font
.MacGetFontStyle() ;
1573 fontStyle
.size
= font
.MacGetFontSize() ;
1574 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1577 fontStyle
.just
= teJustLeft
;
1578 fontStyle
.flags
|= kControlUseJustMask
;
1579 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1580 fontStyle
.just
= teJustCenter
;
1581 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1582 fontStyle
.just
= teJustRight
;
1585 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1586 // won't get grayed out by the system anymore
1588 if ( foreground
!= *wxBLACK
)
1590 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
1591 fontStyle
.flags
|= kControlUseForeColorMask
;
1594 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1597 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1600 // setting up a color proc is not recommended anymore
1603 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1605 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1606 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1609 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1611 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
1614 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1616 SetControlAction( m_controlRef
, actionProc
) ;
1619 void wxMacControl::SetViewSize( SInt32 viewSize
)
1621 SetControlViewSize(m_controlRef
, viewSize
) ;
1624 SInt32
wxMacControl::GetViewSize() const
1626 return GetControlViewSize( m_controlRef
) ;
1629 bool wxMacControl::IsVisible() const
1631 return IsControlVisible( m_controlRef
) ;
1634 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1636 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
1639 bool wxMacControl::IsEnabled() const
1641 #if TARGET_API_MAC_OSX
1642 return IsControlEnabled( m_controlRef
) ;
1644 return IsControlActive( m_controlRef
) ;
1648 bool wxMacControl::IsActive() const
1650 return IsControlActive( m_controlRef
) ;
1653 void wxMacControl::Enable( bool enable
)
1655 #if TARGET_API_MAC_OSX
1657 EnableControl( m_controlRef
) ;
1659 DisableControl( m_controlRef
) ;
1662 ActivateControl( m_controlRef
) ;
1664 DeactivateControl( m_controlRef
) ;
1668 void wxMacControl::SetDrawingEnabled( bool enable
)
1670 #if TARGET_API_MAC_OSX
1671 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1675 bool wxMacControl::GetNeedsDisplay() const
1677 #if TARGET_API_MAC_OSX
1678 return HIViewGetNeedsDisplay( m_controlRef
) ;
1684 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1686 #if TARGET_API_MAC_OSX
1687 if ( where
!= NULL
)
1688 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1690 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1694 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1696 #if TARGET_API_MAC_OSX
1700 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1701 pt
->x
= (int)hiPoint
.x
;
1702 pt
->y
= (int)hiPoint
.y
;
1706 void wxMacControl::SetRect( Rect
*r
)
1708 #if TARGET_API_MAC_OSX
1709 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1710 //CGPoint and CGSize, which have two floats each
1711 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} } ;
1712 HIViewSetFrame ( m_controlRef
, &hir
) ;
1714 SetControlBounds( m_controlRef
, r
) ;
1719 void wxMacControl::GetRect( Rect
*r
)
1721 GetControlBounds( m_controlRef
, r
) ;
1724 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1726 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1729 void wxMacControl::GetBestRect( Rect
*r
)
1731 short baselineoffset
;
1732 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1735 void wxMacControl::SetTitle( const wxString
&title
)
1737 wxFontEncoding encoding
;
1740 encoding
= m_font
.GetEncoding();
1742 encoding
= wxFont::GetDefaultEncoding();
1744 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1747 void wxMacControl::GetFeatures( UInt32
* features
)
1749 GetControlFeatures( m_controlRef
, features
) ;
1752 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1754 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1757 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1759 #if TARGET_API_MAC_OSX
1760 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1761 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1768 #if TARGET_API_MAC_OSX
1769 // SetNeedsDisplay would not invalidate the children
1770 static void InvalidateControlAndChildren( HIViewRef control
)
1772 HIViewSetNeedsDisplay( control
, true ) ;
1773 UInt16 childrenCount
= 0 ;
1774 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1775 if ( err
== errControlIsNotEmbedder
)
1777 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1779 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1782 err
= GetIndexedSubControl( control
, i
, & child
) ;
1783 if ( err
== errControlIsNotEmbedder
)
1785 InvalidateControlAndChildren( child
) ;
1790 void wxMacControl::InvalidateWithChildren()
1792 #if TARGET_API_MAC_OSX
1793 InvalidateControlAndChildren( m_controlRef
) ;
1797 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1799 #if TARGET_API_MAC_OSX
1800 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1801 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1806 // SetNeedsDisplay would not invalidate the children
1812 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1814 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1817 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1818 DataBrowserTableViewColumnIndex position
)
1820 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1823 OSStatus
wxMacControl::AutoSizeListViewColumns()
1825 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1828 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1830 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1833 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1835 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1838 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1840 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1843 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1845 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1848 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1849 const DataBrowserItemID
* items
,
1850 DataBrowserPropertyID preSortProperty
,
1851 DataBrowserPropertyID propertyID
)
1853 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1856 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1858 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1861 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1862 const DataBrowserItemID
* items
,
1863 DataBrowserPropertyID preSortProperty
)
1865 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1868 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1869 const DataBrowserItemID
* items
,
1870 DataBrowserPropertyID preSortProperty
)
1872 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1875 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1876 DataBrowserPropertyID propertyID
,
1877 DataBrowserRevealOptions options
)
1879 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1882 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1883 const DataBrowserItemID
* items
,
1884 DataBrowserSetOption operation
)
1886 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1893 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1895 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;