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 #if TARGET_API_MAC_OSX
49 #include <CoreServices/CoreServices.h>
51 #include <DriverServices.h>
52 #include <Multiprocessing.h>
55 #include <ATSUnicode.h>
56 #include <TextCommon.h>
57 #include <TextEncodingConverter.h>
59 #include "wx/mac/private.h" // includes mac headers
61 #if defined(__MWERKS__) && wxUSE_UNICODE
65 // ---------------------------------------------------------------------------
66 // code used in both base and GUI compilation
67 // ---------------------------------------------------------------------------
69 // our OS version is the same in non GUI and GUI cases
70 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
74 // are there x-platform conventions ?
76 Gestalt(gestaltSystemVersion
, &theSystem
) ;
77 if (minorVsn
!= NULL
) {
78 *minorVsn
= (theSystem
& 0xFF ) ;
80 if (majorVsn
!= NULL
) {
81 *majorVsn
= (theSystem
>> 8 ) ;
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
99 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
101 #ifndef __MetroNubUtils__
102 #include "MetroNubUtils.h"
109 #if TARGET_API_MAC_CARBON
111 #include <CodeFragments.h>
113 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
115 ProcPtr gCallUniversalProc_Proc
= NULL
;
119 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
121 static long fRunOnce
= false;
123 /* ---------------------------------------------------------------------------
125 --------------------------------------------------------------------------- */
127 Boolean
IsMetroNubInstalled()
134 gMetroNubEntry
= NULL
;
136 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
138 /* look for MetroNub's Gestalt selector */
139 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
142 #if TARGET_API_MAC_CARBON
143 if (gCallUniversalProc_Proc
== NULL
)
145 CFragConnectionID connectionID
;
148 ProcPtr symbolAddress
;
150 CFragSymbolClass symbolClass
;
152 symbolAddress
= NULL
;
153 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
154 &connectionID
, &mainAddress
, errorString
);
158 gCallUniversalProc_Proc
= NULL
;
162 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
163 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
167 gCallUniversalProc_Proc
= NULL
;
174 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
176 /* make sure the version of the API is compatible */
177 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
178 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
179 gMetroNubEntry
= block
; /* success! */
188 #if TARGET_API_MAC_CARBON
189 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
191 return (gMetroNubEntry
!= NULL
);
195 /* ---------------------------------------------------------------------------
196 IsMWDebuggerRunning [v1 API]
197 --------------------------------------------------------------------------- */
199 Boolean
IsMWDebuggerRunning()
201 if (IsMetroNubInstalled())
202 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
207 /* ---------------------------------------------------------------------------
208 AmIBeingMWDebugged [v1 API]
209 --------------------------------------------------------------------------- */
211 Boolean
AmIBeingMWDebugged()
213 if (IsMetroNubInstalled())
214 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
219 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
221 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
226 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
231 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
235 // defined in unix/utilsunx.cpp for Mac OS X
237 // get full hostname (with domain name if possible)
238 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
240 return wxGetHostName(buf
, maxSize
);
243 // Get hostname only (without domain name)
244 bool wxGetHostName(wxChar
*buf
, int maxSize
)
246 // Gets Chooser name of user by examining a System resource.
248 const short kComputerNameID
= -16413;
250 short oldResFile
= CurResFile() ;
252 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
253 UseResFile(oldResFile
);
255 if (chooserName
&& *chooserName
)
257 HLock( (Handle
) chooserName
) ;
258 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
259 HUnlock( (Handle
) chooserName
) ;
260 ReleaseResource( (Handle
) chooserName
) ;
261 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
269 // Get user ID e.g. jacs
270 bool wxGetUserId(wxChar
*buf
, int maxSize
)
272 return wxGetUserName( buf
, maxSize
) ;
275 const wxChar
* wxGetHomeDir(wxString
*pstr
)
277 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
278 return pstr
->c_str() ;
281 // Get user name e.g. Stefan Csomor
282 bool wxGetUserName(wxChar
*buf
, int maxSize
)
284 // Gets Chooser name of user by examining a System resource.
286 const short kChooserNameID
= -16096;
288 short oldResFile
= CurResFile() ;
290 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
291 UseResFile(oldResFile
);
293 if (chooserName
&& *chooserName
)
295 HLock( (Handle
) chooserName
) ;
296 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
297 HUnlock( (Handle
) chooserName
) ;
298 ReleaseResource( (Handle
) chooserName
) ;
299 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
307 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
)
313 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
315 // TODO : under classic there is no environement support, under X yes
319 // set the env var name to the given value, return TRUE on success
320 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
322 // TODO : under classic there is no environement support, under X yes
327 // Execute a program in an Interactive Shell
329 bool wxShell(const wxString
& command
)
335 // Shutdown or reboot the PC
336 bool wxShutdown(wxShutdownFlags wFlags
)
342 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
343 long wxGetFreeMemory()
350 void wxMicroSleep(unsigned long microseconds
)
352 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
353 MPDelayUntil( & wakeup
);
356 void wxMilliSleep(unsigned long milliseconds
)
358 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
359 MPDelayUntil( & wakeup
);
362 void wxSleep(int nSecs
)
364 wxMilliSleep(1000*nSecs
);
369 // Consume all events until no more left
374 #endif // !__DARWIN__
382 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
384 static wxToolkitInfo info
;
385 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
386 info
.name
= _T("wxBase");
394 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
396 static wxToolkitInfo info
;
397 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
398 info
.shortName
= _T("mac");
399 info
.name
= _T("wxMac");
400 #ifdef __WXUNIVERSAL__
401 info
.shortName
<< _T("univ");
402 info
.name
<< _T("/wxUniversal");
407 // Reading and writing resources (eg WIN.INI, .Xdefaults)
409 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
415 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
418 buf
.Printf(wxT("%.4f"), value
);
420 return wxWriteResource(section
, entry
, buf
, file
);
423 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
426 buf
.Printf(wxT("%ld"), value
);
428 return wxWriteResource(section
, entry
, buf
, file
);
431 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
434 buf
.Printf(wxT("%d"), value
);
436 return wxWriteResource(section
, entry
, buf
, file
);
439 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
445 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
448 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
451 *value
= (float)strtod(s
, NULL
);
458 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
461 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
464 *value
= strtol(s
, NULL
, 10);
471 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
474 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
477 *value
= (int)strtol(s
, NULL
, 10);
483 #endif // wxUSE_RESOURCES
485 int gs_wxBusyCursorCount
= 0;
486 extern wxCursor gMacCurrentCursor
;
487 wxCursor gMacStoredActiveCursor
;
489 // Set the cursor to the busy cursor for all windows
490 void wxBeginBusyCursor(wxCursor
*cursor
)
492 if (gs_wxBusyCursorCount
++ == 0)
494 gMacStoredActiveCursor
= gMacCurrentCursor
;
495 cursor
->MacInstall() ;
497 //else: nothing to do, already set
500 // Restore cursor to normal
501 void wxEndBusyCursor()
503 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
504 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
506 if (--gs_wxBusyCursorCount
== 0)
508 gMacStoredActiveCursor
.MacInstall() ;
509 gMacStoredActiveCursor
= wxNullCursor
;
513 // TRUE if we're between the above two calls
516 return (gs_wxBusyCursorCount
> 0);
523 wxString
wxMacFindFolder( short vol
,
525 Boolean createFolder
)
531 if ( FindFolder( vol
, folderType
, createFolder
, &vRefNum
, &dirID
) == noErr
)
534 if ( FSMakeFSSpec( vRefNum
, dirID
, "\p" , &file
) == noErr
)
536 strDir
= wxMacFSSpec2MacFilename( &file
) + wxFILE_SEP_PATH
;
546 // Check whether this window wants to process messages, e.g. Stop button
547 // in long calculations.
548 bool wxCheckForInterrupt(wxWindow
*wnd
)
554 void wxGetMousePosition( int* x
, int* y
)
559 LocalToGlobal( &pt
) ;
564 // Return TRUE if we have a colour display
565 bool wxColourDisplay()
570 // Returns depth of screen
574 SetRect(&globRect
, -32760, -32760, 32760, 32760);
575 GDHandle theMaxDevice
;
578 theMaxDevice
= GetMaxDevice(&globRect
);
579 if (theMaxDevice
!= nil
)
580 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
585 // Get size of display
586 void wxDisplaySize(int *width
, int *height
)
589 GetQDGlobalsScreenBits( &screenBits
);
592 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
594 if (height
!= NULL
) {
595 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
599 void wxDisplaySizeMM(int *width
, int *height
)
601 wxDisplaySize(width
, height
);
602 // on mac 72 is fixed (at least now ;-)
603 float cvPt2Mm
= 25.4 / 72;
606 *width
= int( *width
* cvPt2Mm
);
608 if (height
!= NULL
) {
609 *height
= int( *height
* cvPt2Mm
);
613 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
616 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
622 *width
= r
.right
- r
.left
;
624 *height
= r
.bottom
- r
.top
;
627 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
629 return wxGenericFindWindowAtPoint(pt
);
636 wxString
wxGetOsDescription()
638 #ifdef WXWIN_OS_DESCRIPTION
639 // use configure generated description if available
640 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
642 return wxT("MacOS") ; //TODO:define further
647 wxChar
*wxGetUserHome (const wxString
& user
)
653 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
663 int pos
= p
.Find(':') ;
664 if ( pos
!= wxNOT_FOUND
) {
673 wxMacStringToPascal( p
, volumeName
) ;
674 OSErr err
= XGetVolumeInfoNoName( volumeName
, 0 , &pb
) ;
675 if ( err
== noErr
) {
677 (*pTotal
) = wxLongLong( pb
.ioVTotalBytes
) ;
680 (*pFree
) = wxLongLong( pb
.ioVFreeBytes
) ;
684 return err
== noErr
;
686 #endif // !__DARWIN__
688 //---------------------------------------------------------------------------
689 // wxMac Specific utility functions
690 //---------------------------------------------------------------------------
692 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
694 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
695 int len
= strlen(buf
) ;
700 memcpy( (char*) &to
[1] , buf
, len
) ;
703 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
705 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
709 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
)
711 TextEncodingBase enc
= 0 ;
712 if ( encoding
== wxFONTENCODING_DEFAULT
)
715 encoding
= wxFont::GetDefaultEncoding() ;
717 encoding
= wxLocale::GetSystemEncoding() ;
723 case wxFONTENCODING_ISO8859_1
:
724 enc
= kTextEncodingISOLatin1
;
726 case wxFONTENCODING_ISO8859_2
:
727 enc
= kTextEncodingISOLatin2
;
729 case wxFONTENCODING_ISO8859_3
:
730 enc
= kTextEncodingISOLatin3
;
732 case wxFONTENCODING_ISO8859_4
:
733 enc
= kTextEncodingISOLatin4
;
735 case wxFONTENCODING_ISO8859_5
:
736 enc
= kTextEncodingISOLatinCyrillic
;
738 case wxFONTENCODING_ISO8859_6
:
739 enc
= kTextEncodingISOLatinArabic
;
741 case wxFONTENCODING_ISO8859_7
:
742 enc
= kTextEncodingISOLatinGreek
;
744 case wxFONTENCODING_ISO8859_8
:
745 enc
= kTextEncodingISOLatinHebrew
;
747 case wxFONTENCODING_ISO8859_9
:
748 enc
= kTextEncodingISOLatin5
;
750 case wxFONTENCODING_ISO8859_10
:
751 enc
= kTextEncodingISOLatin6
;
753 case wxFONTENCODING_ISO8859_13
:
754 enc
= kTextEncodingISOLatin7
;
756 case wxFONTENCODING_ISO8859_14
:
757 enc
= kTextEncodingISOLatin8
;
759 case wxFONTENCODING_ISO8859_15
:
760 enc
= kTextEncodingISOLatin9
;
763 case wxFONTENCODING_KOI8
:
764 enc
= kTextEncodingKOI8_R
;
766 case wxFONTENCODING_ALTERNATIVE
: // MS-DOS CP866
767 enc
= kTextEncodingDOSRussian
;
770 case wxFONTENCODING_BULGARIAN :
774 case wxFONTENCODING_CP437
:
775 enc
=kTextEncodingDOSLatinUS
;
777 case wxFONTENCODING_CP850
:
778 enc
= kTextEncodingDOSLatin1
;
780 case wxFONTENCODING_CP852
:
781 enc
= kTextEncodingDOSLatin2
;
783 case wxFONTENCODING_CP855
:
784 enc
= kTextEncodingDOSCyrillic
;
786 case wxFONTENCODING_CP866
:
787 enc
=kTextEncodingDOSRussian
;
789 case wxFONTENCODING_CP874
:
790 enc
= kTextEncodingDOSThai
;
792 case wxFONTENCODING_CP932
:
793 enc
= kTextEncodingDOSJapanese
;
795 case wxFONTENCODING_CP936
:
796 enc
=kTextEncodingDOSChineseSimplif
;
798 case wxFONTENCODING_CP949
:
799 enc
= kTextEncodingDOSKorean
;
801 case wxFONTENCODING_CP950
:
802 enc
= kTextEncodingDOSChineseTrad
;
805 case wxFONTENCODING_CP1250
:
806 enc
= kTextEncodingWindowsLatin2
;
808 case wxFONTENCODING_CP1251
:
809 enc
=kTextEncodingWindowsCyrillic
;
811 case wxFONTENCODING_CP1252
:
812 enc
=kTextEncodingWindowsLatin1
;
814 case wxFONTENCODING_CP1253
:
815 enc
= kTextEncodingWindowsGreek
;
817 case wxFONTENCODING_CP1254
:
818 enc
= kTextEncodingWindowsLatin5
;
820 case wxFONTENCODING_CP1255
:
821 enc
=kTextEncodingWindowsHebrew
;
823 case wxFONTENCODING_CP1256
:
824 enc
=kTextEncodingWindowsArabic
;
826 case wxFONTENCODING_CP1257
:
827 enc
= kTextEncodingWindowsBalticRim
;
830 case wxFONTENCODING_UTF7
:
831 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF7Format
) ;
833 case wxFONTENCODING_UTF8
:
834 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicodeUTF8Format
) ;
836 case wxFONTENCODING_EUC_JP
:
837 enc
= kTextEncodingEUC_JP
;
839 case wxFONTENCODING_UTF16BE
:
840 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
842 case wxFONTENCODING_UTF16LE
:
843 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode16BitFormat
) ;
845 case wxFONTENCODING_UTF32BE
:
846 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
848 case wxFONTENCODING_UTF32LE
:
849 enc
= CreateTextEncoding(kTextEncodingUnicodeDefault
,0,kUnicode32BitFormat
) ;
852 case wxFONTENCODING_MACROMAN
:
853 enc
= kTextEncodingMacRoman
;
855 case wxFONTENCODING_MACJAPANESE
:
856 enc
= kTextEncodingMacJapanese
;
858 case wxFONTENCODING_MACCHINESETRAD
:
859 enc
= kTextEncodingMacChineseTrad
;
861 case wxFONTENCODING_MACKOREAN
:
862 enc
= kTextEncodingMacKorean
;
864 case wxFONTENCODING_MACARABIC
:
865 enc
= kTextEncodingMacArabic
;
867 case wxFONTENCODING_MACHEBREW
:
868 enc
= kTextEncodingMacHebrew
;
870 case wxFONTENCODING_MACGREEK
:
871 enc
= kTextEncodingMacGreek
;
873 case wxFONTENCODING_MACCYRILLIC
:
874 enc
= kTextEncodingMacCyrillic
;
876 case wxFONTENCODING_MACDEVANAGARI
:
877 enc
= kTextEncodingMacDevanagari
;
879 case wxFONTENCODING_MACGURMUKHI
:
880 enc
= kTextEncodingMacGurmukhi
;
882 case wxFONTENCODING_MACGUJARATI
:
883 enc
= kTextEncodingMacGujarati
;
885 case wxFONTENCODING_MACORIYA
:
886 enc
= kTextEncodingMacOriya
;
888 case wxFONTENCODING_MACBENGALI
:
889 enc
= kTextEncodingMacBengali
;
891 case wxFONTENCODING_MACTAMIL
:
892 enc
= kTextEncodingMacTamil
;
894 case wxFONTENCODING_MACTELUGU
:
895 enc
= kTextEncodingMacTelugu
;
897 case wxFONTENCODING_MACKANNADA
:
898 enc
= kTextEncodingMacKannada
;
900 case wxFONTENCODING_MACMALAJALAM
:
901 enc
= kTextEncodingMacMalayalam
;
903 case wxFONTENCODING_MACSINHALESE
:
904 enc
= kTextEncodingMacSinhalese
;
906 case wxFONTENCODING_MACBURMESE
:
907 enc
= kTextEncodingMacBurmese
;
909 case wxFONTENCODING_MACKHMER
:
910 enc
= kTextEncodingMacKhmer
;
912 case wxFONTENCODING_MACTHAI
:
913 enc
= kTextEncodingMacThai
;
915 case wxFONTENCODING_MACLAOTIAN
:
916 enc
= kTextEncodingMacLaotian
;
918 case wxFONTENCODING_MACGEORGIAN
:
919 enc
= kTextEncodingMacGeorgian
;
921 case wxFONTENCODING_MACARMENIAN
:
922 enc
= kTextEncodingMacArmenian
;
924 case wxFONTENCODING_MACCHINESESIMP
:
925 enc
= kTextEncodingMacChineseSimp
;
927 case wxFONTENCODING_MACTIBETAN
:
928 enc
= kTextEncodingMacTibetan
;
930 case wxFONTENCODING_MACMONGOLIAN
:
931 enc
= kTextEncodingMacMongolian
;
933 case wxFONTENCODING_MACETHIOPIC
:
934 enc
= kTextEncodingMacEthiopic
;
936 case wxFONTENCODING_MACCENTRALEUR
:
937 enc
= kTextEncodingMacCentralEurRoman
;
939 case wxFONTENCODING_MACVIATNAMESE
:
940 enc
= kTextEncodingMacVietnamese
;
942 case wxFONTENCODING_MACARABICEXT
:
943 enc
= kTextEncodingMacExtArabic
;
945 case wxFONTENCODING_MACSYMBOL
:
946 enc
= kTextEncodingMacSymbol
;
948 case wxFONTENCODING_MACDINGBATS
:
949 enc
= kTextEncodingMacDingbats
;
951 case wxFONTENCODING_MACTURKISH
:
952 enc
= kTextEncodingMacTurkish
;
954 case wxFONTENCODING_MACCROATIAN
:
955 enc
= kTextEncodingMacCroatian
;
957 case wxFONTENCODING_MACICELANDIC
:
958 enc
= kTextEncodingMacIcelandic
;
960 case wxFONTENCODING_MACROMANIAN
:
961 enc
= kTextEncodingMacRomanian
;
963 case wxFONTENCODING_MACCELTIC
:
964 enc
= kTextEncodingMacCeltic
;
966 case wxFONTENCODING_MACGAELIC
:
967 enc
= kTextEncodingMacGaelic
;
969 case wxFONTENCODING_MACKEYBOARD
:
970 enc
= kTextEncodingMacKeyboardGlyphs
;
979 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
)
981 wxFontEncoding enc
= wxFONTENCODING_DEFAULT
;
985 case kTextEncodingISOLatin1
:
986 enc
= wxFONTENCODING_ISO8859_1
;
988 case kTextEncodingISOLatin2
:
989 enc
= wxFONTENCODING_ISO8859_2
;
991 case kTextEncodingISOLatin3
:
992 enc
= wxFONTENCODING_ISO8859_3
;
994 case kTextEncodingISOLatin4
:
995 enc
= wxFONTENCODING_ISO8859_4
;
997 case kTextEncodingISOLatinCyrillic
:
998 enc
= wxFONTENCODING_ISO8859_5
;
1000 case kTextEncodingISOLatinArabic
:
1001 enc
= wxFONTENCODING_ISO8859_6
;
1003 case kTextEncodingISOLatinGreek
:
1004 enc
= wxFONTENCODING_ISO8859_7
;
1006 case kTextEncodingISOLatinHebrew
:
1007 enc
= wxFONTENCODING_ISO8859_8
;
1009 case kTextEncodingISOLatin5
:
1010 enc
= wxFONTENCODING_ISO8859_9
;
1012 case kTextEncodingISOLatin6
:
1013 enc
= wxFONTENCODING_ISO8859_10
;
1015 case kTextEncodingISOLatin7
:
1016 enc
= wxFONTENCODING_ISO8859_13
;
1018 case kTextEncodingISOLatin8
:
1019 enc
= wxFONTENCODING_ISO8859_14
;
1021 case kTextEncodingISOLatin9
:
1022 enc
=wxFONTENCODING_ISO8859_15
;
1025 case kTextEncodingKOI8_R
:
1026 enc
= wxFONTENCODING_KOI8
;
1030 enc = wxFONTENCODING_BULGARIAN;
1033 case kTextEncodingDOSLatinUS
:
1034 enc
= wxFONTENCODING_CP437
;
1036 case kTextEncodingDOSLatin1
:
1037 enc
= wxFONTENCODING_CP850
;
1039 case kTextEncodingDOSLatin2
:
1040 enc
=wxFONTENCODING_CP852
;
1042 case kTextEncodingDOSCyrillic
:
1043 enc
= wxFONTENCODING_CP855
;
1045 case kTextEncodingDOSRussian
:
1046 enc
= wxFONTENCODING_CP866
;
1048 case kTextEncodingDOSThai
:
1049 enc
=wxFONTENCODING_CP874
;
1051 case kTextEncodingDOSJapanese
:
1052 enc
= wxFONTENCODING_CP932
;
1054 case kTextEncodingDOSChineseSimplif
:
1055 enc
= wxFONTENCODING_CP936
;
1057 case kTextEncodingDOSKorean
:
1058 enc
= wxFONTENCODING_CP949
;
1060 case kTextEncodingDOSChineseTrad
:
1061 enc
= wxFONTENCODING_CP950
;
1064 case kTextEncodingWindowsLatin2
:
1065 enc
= wxFONTENCODING_CP1250
;
1067 case kTextEncodingWindowsCyrillic
:
1068 enc
= wxFONTENCODING_CP1251
;
1070 case kTextEncodingWindowsLatin1
:
1071 enc
= wxFONTENCODING_CP1252
;
1073 case kTextEncodingWindowsGreek
:
1074 enc
= wxFONTENCODING_CP1253
;
1076 case kTextEncodingWindowsLatin5
:
1077 enc
= wxFONTENCODING_CP1254
;
1079 case kTextEncodingWindowsHebrew
:
1080 enc
= wxFONTENCODING_CP1255
;
1082 case kTextEncodingWindowsArabic
:
1083 enc
= wxFONTENCODING_CP1256
;
1085 case kTextEncodingWindowsBalticRim
:
1086 enc
=wxFONTENCODING_CP1257
;
1088 case kTextEncodingEUC_JP
:
1089 enc
= wxFONTENCODING_EUC_JP
;
1092 case wxFONTENCODING_UTF7 :
1093 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF7Format) ;
1095 case wxFONTENCODING_UTF8 :
1096 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicodeUTF8Format) ;
1098 case wxFONTENCODING_UTF16BE :
1099 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1101 case wxFONTENCODING_UTF16LE :
1102 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode16BitFormat) ;
1104 case wxFONTENCODING_UTF32BE :
1105 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1107 case wxFONTENCODING_UTF32LE :
1108 enc = CreateTextEncoding(kTextEncodingUnicodeDefault,0,kUnicode32BitFormat) ;
1111 case kTextEncodingMacRoman
:
1112 enc
= wxFONTENCODING_MACROMAN
;
1114 case kTextEncodingMacJapanese
:
1115 enc
= wxFONTENCODING_MACJAPANESE
;
1117 case kTextEncodingMacChineseTrad
:
1118 enc
= wxFONTENCODING_MACCHINESETRAD
;
1120 case kTextEncodingMacKorean
:
1121 enc
= wxFONTENCODING_MACKOREAN
;
1123 case kTextEncodingMacArabic
:
1124 enc
=wxFONTENCODING_MACARABIC
;
1126 case kTextEncodingMacHebrew
:
1127 enc
= wxFONTENCODING_MACHEBREW
;
1129 case kTextEncodingMacGreek
:
1130 enc
= wxFONTENCODING_MACGREEK
;
1132 case kTextEncodingMacCyrillic
:
1133 enc
= wxFONTENCODING_MACCYRILLIC
;
1135 case kTextEncodingMacDevanagari
:
1136 enc
= wxFONTENCODING_MACDEVANAGARI
;
1138 case kTextEncodingMacGurmukhi
:
1139 enc
= wxFONTENCODING_MACGURMUKHI
;
1141 case kTextEncodingMacGujarati
:
1142 enc
= wxFONTENCODING_MACGUJARATI
;
1144 case kTextEncodingMacOriya
:
1145 enc
=wxFONTENCODING_MACORIYA
;
1147 case kTextEncodingMacBengali
:
1148 enc
=wxFONTENCODING_MACBENGALI
;
1150 case kTextEncodingMacTamil
:
1151 enc
= wxFONTENCODING_MACTAMIL
;
1153 case kTextEncodingMacTelugu
:
1154 enc
= wxFONTENCODING_MACTELUGU
;
1156 case kTextEncodingMacKannada
:
1157 enc
= wxFONTENCODING_MACKANNADA
;
1159 case kTextEncodingMacMalayalam
:
1160 enc
= wxFONTENCODING_MACMALAJALAM
;
1162 case kTextEncodingMacSinhalese
:
1163 enc
= wxFONTENCODING_MACSINHALESE
;
1165 case kTextEncodingMacBurmese
:
1166 enc
= wxFONTENCODING_MACBURMESE
;
1168 case kTextEncodingMacKhmer
:
1169 enc
= wxFONTENCODING_MACKHMER
;
1171 case kTextEncodingMacThai
:
1172 enc
= wxFONTENCODING_MACTHAI
;
1174 case kTextEncodingMacLaotian
:
1175 enc
= wxFONTENCODING_MACLAOTIAN
;
1177 case kTextEncodingMacGeorgian
:
1178 enc
= wxFONTENCODING_MACGEORGIAN
;
1180 case kTextEncodingMacArmenian
:
1181 enc
= wxFONTENCODING_MACARMENIAN
;
1183 case kTextEncodingMacChineseSimp
:
1184 enc
= wxFONTENCODING_MACCHINESESIMP
;
1186 case kTextEncodingMacTibetan
:
1187 enc
= wxFONTENCODING_MACTIBETAN
;
1189 case kTextEncodingMacMongolian
:
1190 enc
= wxFONTENCODING_MACMONGOLIAN
;
1192 case kTextEncodingMacEthiopic
:
1193 enc
= wxFONTENCODING_MACETHIOPIC
;
1195 case kTextEncodingMacCentralEurRoman
:
1196 enc
= wxFONTENCODING_MACCENTRALEUR
;
1198 case kTextEncodingMacVietnamese
:
1199 enc
= wxFONTENCODING_MACVIATNAMESE
;
1201 case kTextEncodingMacExtArabic
:
1202 enc
= wxFONTENCODING_MACARABICEXT
;
1204 case kTextEncodingMacSymbol
:
1205 enc
= wxFONTENCODING_MACSYMBOL
;
1207 case kTextEncodingMacDingbats
:
1208 enc
= wxFONTENCODING_MACDINGBATS
;
1210 case kTextEncodingMacTurkish
:
1211 enc
= wxFONTENCODING_MACTURKISH
;
1213 case kTextEncodingMacCroatian
:
1214 enc
= wxFONTENCODING_MACCROATIAN
;
1216 case kTextEncodingMacIcelandic
:
1217 enc
= wxFONTENCODING_MACICELANDIC
;
1219 case kTextEncodingMacRomanian
:
1220 enc
= wxFONTENCODING_MACROMANIAN
;
1222 case kTextEncodingMacCeltic
:
1223 enc
= wxFONTENCODING_MACCELTIC
;
1225 case kTextEncodingMacGaelic
:
1226 enc
= wxFONTENCODING_MACGAELIC
;
1228 case kTextEncodingMacKeyboardGlyphs
:
1229 enc
= wxFONTENCODING_MACKEYBOARD
;
1237 // CFStringRefs (Carbon only)
1242 // converts this string into a carbon foundation string with optional pc 2 mac encoding
1243 void wxMacCFStringHolder::Assign( const wxString
&st
, wxFontEncoding encoding
)
1248 wxMacConvertNewlines13To10( &str
) ;
1250 #if SIZEOF_WCHAR_T == 2
1251 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1252 (UniChar
*)str
.wc_str() , str
.Len() );
1254 wxMBConvUTF16BE converter
;
1255 size_t unicharlen
= converter
.WC2MB( NULL
, str
.wc_str() , 0 ) ;
1256 UniChar
*unibuf
= new UniChar
[ unicharlen
/ sizeof(UniChar
) + 1 ] ;
1257 converter
.WC2MB( (char*)unibuf
, str
.wc_str() , unicharlen
) ;
1258 m_cfs
= CFStringCreateWithCharacters( kCFAllocatorDefault
,
1259 unibuf
, unicharlen
/ sizeof(UniChar
) ) ;
1262 #else // not wxUSE_UNICODE
1263 m_cfs
= CFStringCreateWithCString( kCFAllocatorSystemDefault
, str
.c_str() ,
1264 wxMacGetSystemEncFromFontEnc( encoding
) ) ;
1269 wxString
wxMacCFStringHolder::AsString(wxFontEncoding encoding
)
1271 Size cflen
= CFStringGetLength( m_cfs
) ;
1273 wxChar
* buf
= NULL
;
1276 #if SIZEOF_WCHAR_T == 2
1277 buf
= new wxChar
[ cflen
+ 1 ] ;
1278 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) buf
) ;
1281 UniChar
* unibuf
= new UniChar
[ cflen
+ 1 ] ;
1282 CFStringGetCharacters( m_cfs
, CFRangeMake( 0 , cflen
) , (UniChar
*) unibuf
) ;
1284 wxMBConvUTF16BE converter
;
1285 noChars
= converter
.MB2WC( NULL
, (const char*)unibuf
, 0 ) ;
1286 buf
= new wxChar
[ noChars
+ 1 ] ;
1287 converter
.MB2WC( buf
, (const char*)unibuf
, noChars
) ;
1292 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1293 '?' , false , NULL
, 0 , &cStrLen
) ;
1294 buf
= new wxChar
[ cStrLen
+ 1 ] ;
1295 CFStringGetBytes( m_cfs
, CFRangeMake(0, cflen
) , wxMacGetSystemEncFromFontEnc( encoding
) ,
1296 '?' , false , (unsigned char*) buf
, cStrLen
, &cStrLen
) ;
1301 wxMacConvertNewlines10To13( buf
) ;
1302 wxString
result(buf
) ;
1307 #endif //TARGET_CARBON
1309 void wxMacConvertNewlines13To10( char * data
)
1312 while( (buf
=strchr(buf
,0x0d)) != NULL
)
1319 void wxMacConvertNewlines10To13( char * data
)
1322 while( (buf
=strchr(buf
,0x0a)) != NULL
)
1329 void wxMacConvertNewlines13To10( wxString
* data
)
1331 size_t len
= data
->Length() ;
1333 if ( len
== 0 || wxStrchr(data
->c_str(),0x0d)==NULL
)
1336 wxString
temp(*data
) ;
1337 wxStringBuffer
buf(*data
,len
) ;
1338 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1340 wxMacConvertNewlines13To10( buf
) ;
1343 void wxMacConvertNewlines10To13( wxString
* data
)
1345 size_t len
= data
->Length() ;
1347 if ( data
->Length() == 0 || wxStrchr(data
->c_str(),0x0a)==NULL
)
1350 wxString
temp(*data
) ;
1351 wxStringBuffer
buf(*data
,len
) ;
1352 memcpy( buf
, temp
.c_str() , (len
+1)*sizeof(wxChar
) ) ;
1353 wxMacConvertNewlines10To13( buf
) ;
1358 void wxMacConvertNewlines13To10( wxChar
* data
)
1360 wxChar
* buf
= data
;
1361 while( (buf
=wxStrchr(buf
,0x0d)) != NULL
)
1368 void wxMacConvertNewlines10To13( wxChar
* data
)
1370 wxChar
* buf
= data
;
1371 while( (buf
=wxStrchr(buf
,0x0a)) != NULL
)
1379 // ----------------------------------------------------------------------------
1380 // Common Event Support
1381 // ----------------------------------------------------------------------------
1384 extern ProcessSerialNumber gAppProcess
;
1388 ProcessSerialNumber psn
;
1390 psn
.highLongOfPSN
= 0 ;
1391 psn
.lowLongOfPSN
= kCurrentProcess
;
1392 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
1396 EventRef dummyEvent
;
1397 OSStatus err
= MacCreateEvent(nil
, 'WXMC', 'WXMC', GetCurrentEventTime(),
1398 kEventAttributeNone
, &dummyEvent
);
1401 err
= PostEventToQueue(GetMainEventQueue(), dummyEvent
,
1402 kEventPriorityHigh
);
1405 PostEvent( nullEvent
, 0 ) ;
1410 WakeUpProcess( &gAppProcess
) ;
1414 #endif // wxUSE_BASE
1419 // ----------------------------------------------------------------------------
1420 // Carbon Event Support
1421 // ----------------------------------------------------------------------------
1424 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
1426 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
1429 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
1431 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
1434 // ----------------------------------------------------------------------------
1435 // Control Access Support
1436 // ----------------------------------------------------------------------------
1438 void wxMacControl::Dispose()
1440 ::DisposeControl( m_controlRef
) ;
1441 m_controlRef
= NULL
;
1444 void wxMacControl::SetReference( SInt32 data
)
1446 SetControlReference( m_controlRef
, data
) ;
1449 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
1451 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
1454 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
1456 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
1459 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
1461 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
1464 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
1466 #if TARGET_API_MAC_OSX
1467 return SendEventToEventTargetWithOptions( event
,
1468 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
1470 #pragma unused(inOptions)
1471 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
1475 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
1477 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
1478 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
1479 return SendEvent( event
, inOptions
) ;
1482 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
1485 memset( &command
, 0 , sizeof(command
) ) ;
1486 command
.commandID
= commandID
;
1487 return SendHICommand( command
, inOptions
) ;
1490 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
1492 HiliteControl( m_controlRef
, part
) ;
1493 unsigned long finalTicks
;
1494 Delay( ticks
, &finalTicks
) ;
1495 HiliteControl( m_controlRef
, kControlNoPart
) ;
1498 SInt32
wxMacControl::GetValue() const
1500 return ::GetControl32BitValue( m_controlRef
) ;
1503 SInt32
wxMacControl::GetMaximum() const
1505 return ::GetControl32BitMaximum( m_controlRef
) ;
1508 SInt32
wxMacControl::GetMinimum() const
1510 return ::GetControl32BitMinimum( m_controlRef
) ;
1513 void wxMacControl::SetValue( SInt32 v
)
1515 ::SetControl32BitValue( m_controlRef
, v
) ;
1518 void wxMacControl::SetMinimum( SInt32 v
)
1520 ::SetControl32BitMinimum( m_controlRef
, v
) ;
1523 void wxMacControl::SetMaximum( SInt32 v
)
1525 ::SetControl32BitMaximum( m_controlRef
, v
) ;
1528 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
1530 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1531 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1532 ::SetControl32BitValue( m_controlRef
, value
) ;
1535 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
1537 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
1538 m_controlRef
, focusPart
) ;
1541 bool wxMacControl::HasFocus() const
1543 ControlRef control
;
1544 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
1545 return control
== m_controlRef
;
1548 bool wxMacControl::NeedsFocusRect() const
1553 void wxMacControl::VisibilityChanged(bool shown
)
1557 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1560 ControlFontStyleRec fontStyle
;
1561 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1563 switch( font
.MacGetThemeFontID() )
1565 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
1566 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
1567 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
1568 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
1570 fontStyle
.flags
= kControlUseFontMask
;
1574 fontStyle
.font
= font
.MacGetFontNum() ;
1575 fontStyle
.style
= font
.MacGetFontStyle() ;
1576 fontStyle
.size
= font
.MacGetFontSize() ;
1577 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1580 fontStyle
.just
= teJustLeft
;
1581 fontStyle
.flags
|= kControlUseJustMask
;
1582 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1583 fontStyle
.just
= teJustCenter
;
1584 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1585 fontStyle
.just
= teJustRight
;
1588 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1589 // won't get grayed out by the system anymore
1591 if ( foreground
!= *wxBLACK
)
1593 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
1594 fontStyle
.flags
|= kControlUseForeColorMask
;
1597 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1600 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1603 // setting up a color proc is not recommended anymore
1606 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1608 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
1609 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
1612 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1614 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
1617 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1619 SetControlAction( m_controlRef
, actionProc
) ;
1622 void wxMacControl::SetViewSize( SInt32 viewSize
)
1624 SetControlViewSize(m_controlRef
, viewSize
) ;
1627 SInt32
wxMacControl::GetViewSize() const
1629 return GetControlViewSize( m_controlRef
) ;
1632 bool wxMacControl::IsVisible() const
1634 return IsControlVisible( m_controlRef
) ;
1637 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1639 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
1642 bool wxMacControl::IsEnabled() const
1644 #if TARGET_API_MAC_OSX
1645 return IsControlEnabled( m_controlRef
) ;
1647 return IsControlActive( m_controlRef
) ;
1651 bool wxMacControl::IsActive() const
1653 return IsControlActive( m_controlRef
) ;
1656 void wxMacControl::Enable( bool enable
)
1658 #if TARGET_API_MAC_OSX
1660 EnableControl( m_controlRef
) ;
1662 DisableControl( m_controlRef
) ;
1665 ActivateControl( m_controlRef
) ;
1667 DeactivateControl( m_controlRef
) ;
1671 void wxMacControl::SetDrawingEnabled( bool enable
)
1673 #if TARGET_API_MAC_OSX
1674 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1678 bool wxMacControl::GetNeedsDisplay() const
1680 #if TARGET_API_MAC_OSX
1681 return HIViewGetNeedsDisplay( m_controlRef
) ;
1687 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1689 #if TARGET_API_MAC_OSX
1690 if ( where
!= NULL
)
1691 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1693 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1697 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1699 #if TARGET_API_MAC_OSX
1703 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1704 pt
->x
= (int)hiPoint
.x
;
1705 pt
->y
= (int)hiPoint
.y
;
1709 void wxMacControl::SetRect( Rect
*r
)
1711 #if TARGET_API_MAC_OSX
1712 HIRect hir
= { r
->left
, r
->top
, r
->right
- r
->left
, r
->bottom
- r
->top
} ;
1713 HIViewSetFrame ( m_controlRef
, &hir
) ;
1715 SetControlBounds( m_controlRef
, r
) ;
1720 void wxMacControl::GetRect( Rect
*r
)
1722 GetControlBounds( m_controlRef
, r
) ;
1725 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1727 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1730 void wxMacControl::GetBestRect( Rect
*r
)
1732 short baselineoffset
;
1733 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1736 void wxMacControl::SetTitle( const wxString
&title
)
1738 wxFontEncoding encoding
;
1741 encoding
= m_font
.GetEncoding();
1743 encoding
= wxFont::GetDefaultEncoding();
1745 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1748 void wxMacControl::GetFeatures( UInt32
* features
)
1750 GetControlFeatures( m_controlRef
, features
) ;
1753 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1755 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1758 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1760 #if TARGET_API_MAC_OSX
1761 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1762 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1769 #if TARGET_API_MAC_OSX
1770 // SetNeedsDisplay would not invalidate the children
1771 static void InvalidateControlAndChildren( HIViewRef control
)
1773 HIViewSetNeedsDisplay( control
, true ) ;
1774 UInt16 childrenCount
= 0 ;
1775 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1776 if ( err
== errControlIsNotEmbedder
)
1778 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1780 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1783 err
= GetIndexedSubControl( control
, i
, & child
) ;
1784 if ( err
== errControlIsNotEmbedder
)
1786 InvalidateControlAndChildren( child
) ;
1791 void wxMacControl::InvalidateWithChildren()
1793 #if TARGET_API_MAC_OSX
1794 InvalidateControlAndChildren( m_controlRef
) ;
1798 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1800 #if TARGET_API_MAC_OSX
1801 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1802 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1807 // SetNeedsDisplay would not invalidate the children
1813 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1815 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1818 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1819 DataBrowserTableViewColumnIndex position
)
1821 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1824 OSStatus
wxMacControl::AutoSizeListViewColumns()
1826 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1829 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1831 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1834 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1836 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1839 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1841 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1844 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1846 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1849 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1850 const DataBrowserItemID
* items
,
1851 DataBrowserPropertyID preSortProperty
,
1852 DataBrowserPropertyID propertyID
)
1854 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1857 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1859 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1862 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1863 const DataBrowserItemID
* items
,
1864 DataBrowserPropertyID preSortProperty
)
1866 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1869 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1870 const DataBrowserItemID
* items
,
1871 DataBrowserPropertyID preSortProperty
)
1873 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1876 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1877 DataBrowserPropertyID propertyID
,
1878 DataBrowserRevealOptions options
)
1880 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1883 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1884 const DataBrowserItemID
* items
,
1885 DataBrowserSetOption operation
)
1887 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1894 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1896 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;