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
, int flags
)
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 wxPowerType
wxGetPowerType()
342 return wxPOWER_UNKNOWN
;
345 wxBatteryState
wxGetBatteryState()
348 return wxBATTERY_UNKNOWN_STATE
;
351 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
352 wxMemorySize
wxGetFreeMemory()
354 return (wxMemorySize
)FreeMem() ;
359 void wxMicroSleep(unsigned long microseconds
)
361 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
362 MPDelayUntil( & wakeup
);
365 void wxMilliSleep(unsigned long milliseconds
)
367 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
368 MPDelayUntil( & wakeup
);
371 void wxSleep(int nSecs
)
373 wxMilliSleep(1000*nSecs
);
378 // Consume all events until no more left
383 #endif // !__DARWIN__
391 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
393 static wxToolkitInfo info
;
394 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
395 info
.name
= _T("wxBase");
403 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
405 static wxToolkitInfo info
;
406 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
407 info
.shortName
= _T("mac");
408 info
.name
= _T("wxMac");
409 #ifdef __WXUNIVERSAL__
410 info
.shortName
<< _T("univ");
411 info
.name
<< _T("/wxUniversal");
416 // Reading and writing resources (eg WIN.INI, .Xdefaults)
418 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
424 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
427 buf
.Printf(wxT("%.4f"), value
);
429 return wxWriteResource(section
, entry
, buf
, file
);
432 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
435 buf
.Printf(wxT("%ld"), value
);
437 return wxWriteResource(section
, entry
, buf
, file
);
440 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
443 buf
.Printf(wxT("%d"), value
);
445 return wxWriteResource(section
, entry
, buf
, file
);
448 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
454 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
457 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
460 *value
= (float)strtod(s
, NULL
);
467 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
470 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
473 *value
= strtol(s
, NULL
, 10);
480 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
483 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
486 *value
= (int)strtol(s
, NULL
, 10);
492 #endif // wxUSE_RESOURCES
494 int gs_wxBusyCursorCount
= 0;
495 extern wxCursor gMacCurrentCursor
;
496 wxCursor gMacStoredActiveCursor
;
498 // Set the cursor to the busy cursor for all windows
499 void wxBeginBusyCursor(wxCursor
*cursor
)
501 if (gs_wxBusyCursorCount
++ == 0)
503 gMacStoredActiveCursor
= gMacCurrentCursor
;
504 cursor
->MacInstall() ;
506 //else: nothing to do, already set
509 // Restore cursor to normal
510 void wxEndBusyCursor()
512 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
513 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
515 if (--gs_wxBusyCursorCount
== 0)
517 gMacStoredActiveCursor
.MacInstall() ;
518 gMacStoredActiveCursor
= wxNullCursor
;
522 // true if we're between the above two calls
525 return (gs_wxBusyCursorCount
> 0);
532 wxString
wxMacFindFolder( short vol
,
534 Boolean createFolder
)
539 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
540 strDir
= wxMacFSRefToPath( &fsRef
) + wxFILE_SEP_PATH
;
549 // Check whether this window wants to process messages, e.g. Stop button
550 // in long calculations.
551 bool wxCheckForInterrupt(wxWindow
*wnd
)
557 void wxGetMousePosition( int* x
, int* y
)
562 LocalToGlobal( &pt
) ;
567 // Return true if we have a colour display
568 bool wxColourDisplay()
573 // Returns depth of screen
577 SetRect(&globRect
, -32760, -32760, 32760, 32760);
578 GDHandle theMaxDevice
;
581 theMaxDevice
= GetMaxDevice(&globRect
);
582 if (theMaxDevice
!= nil
)
583 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
588 // Get size of display
589 void wxDisplaySize(int *width
, int *height
)
592 GetQDGlobalsScreenBits( &screenBits
);
595 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
597 if (height
!= NULL
) {
598 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
602 void wxDisplaySizeMM(int *width
, int *height
)
604 wxDisplaySize(width
, height
);
605 // on mac 72 is fixed (at least now ;-)
606 float cvPt2Mm
= 25.4 / 72;
609 *width
= int( *width
* cvPt2Mm
);
611 if (height
!= NULL
) {
612 *height
= int( *height
* cvPt2Mm
);
616 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
619 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
625 *width
= r
.right
- r
.left
;
627 *height
= r
.bottom
- r
.top
;
630 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
632 return wxGenericFindWindowAtPoint(pt
);
639 wxString
wxGetOsDescription()
641 #ifdef WXWIN_OS_DESCRIPTION
642 // use configure generated description if available
643 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
645 return wxT("MacOS") ; //TODO:define further
650 wxChar
*wxGetUserHome (const wxString
& user
)
656 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
666 int pos
= p
.Find(':') ;
667 if ( pos
!= wxNOT_FOUND
) {
676 err
= wxMacPathToFSRef( p
, &fsRef
) ;
679 FSVolumeRefNum vRefNum
;
680 err
= FSGetVRefNum( &fsRef
, &vRefNum
) ;
683 UInt64 freeBytes
, totalBytes
;
684 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
) ;
688 *pTotal
= wxLongLong( totalBytes
) ;
690 *pFree
= wxLongLong( freeBytes
) ;
695 return err
== noErr
;
697 #endif // !__DARWIN__
699 //---------------------------------------------------------------------------
700 // wxMac Specific utility functions
701 //---------------------------------------------------------------------------
703 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
705 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
706 int len
= strlen(buf
) ;
711 memcpy( (char*) &to
[1] , buf
, len
) ;
714 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
716 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
720 // ----------------------------------------------------------------------------
721 // Common Event Support
722 // ----------------------------------------------------------------------------
725 extern ProcessSerialNumber gAppProcess
;
729 ProcessSerialNumber psn
;
731 psn
.highLongOfPSN
= 0 ;
732 psn
.lowLongOfPSN
= kCurrentProcess
;
733 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
737 static wxMacCarbonEvent s_wakeupEvent
;
738 OSStatus err
= noErr
;
739 if ( !s_wakeupEvent
.IsValid() )
741 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
742 kEventAttributeNone
) ;
746 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
748 s_wakeupEvent
.SetTime(0) ;
749 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
753 PostEvent( nullEvent
, 0 ) ;
758 WakeUpProcess( &gAppProcess
) ;
767 // ----------------------------------------------------------------------------
768 // Carbon Event Support
769 // ----------------------------------------------------------------------------
772 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
774 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
777 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
779 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
782 // ----------------------------------------------------------------------------
783 // Control Access Support
784 // ----------------------------------------------------------------------------
786 void wxMacControl::Dispose()
788 ::DisposeControl( m_controlRef
) ;
789 m_controlRef
= NULL
;
792 void wxMacControl::SetReference( SInt32 data
)
794 SetControlReference( m_controlRef
, data
) ;
797 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
799 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
802 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
804 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
807 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
809 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
812 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
814 #if TARGET_API_MAC_OSX
815 return SendEventToEventTargetWithOptions( event
,
816 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
818 #pragma unused(inOptions)
819 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
823 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
825 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
826 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
827 return SendEvent( event
, inOptions
) ;
830 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
833 memset( &command
, 0 , sizeof(command
) ) ;
834 command
.commandID
= commandID
;
835 return SendHICommand( command
, inOptions
) ;
838 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
840 HiliteControl( m_controlRef
, part
) ;
841 unsigned long finalTicks
;
842 Delay( ticks
, &finalTicks
) ;
843 HiliteControl( m_controlRef
, kControlNoPart
) ;
846 SInt32
wxMacControl::GetValue() const
848 return ::GetControl32BitValue( m_controlRef
) ;
851 SInt32
wxMacControl::GetMaximum() const
853 return ::GetControl32BitMaximum( m_controlRef
) ;
856 SInt32
wxMacControl::GetMinimum() const
858 return ::GetControl32BitMinimum( m_controlRef
) ;
861 void wxMacControl::SetValue( SInt32 v
)
863 ::SetControl32BitValue( m_controlRef
, v
) ;
866 void wxMacControl::SetMinimum( SInt32 v
)
868 ::SetControl32BitMinimum( m_controlRef
, v
) ;
871 void wxMacControl::SetMaximum( SInt32 v
)
873 ::SetControl32BitMaximum( m_controlRef
, v
) ;
876 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
878 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
879 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
880 ::SetControl32BitValue( m_controlRef
, value
) ;
883 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
885 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
886 m_controlRef
, focusPart
) ;
889 bool wxMacControl::HasFocus() const
892 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
893 return control
== m_controlRef
;
896 bool wxMacControl::NeedsFocusRect() const
901 void wxMacControl::VisibilityChanged(bool shown
)
905 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
908 ControlFontStyleRec fontStyle
;
909 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
911 switch( font
.MacGetThemeFontID() )
913 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
914 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
915 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
916 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
918 fontStyle
.flags
= kControlUseFontMask
;
922 fontStyle
.font
= font
.MacGetFontNum() ;
923 fontStyle
.style
= font
.MacGetFontStyle() ;
924 fontStyle
.size
= font
.MacGetFontSize() ;
925 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
928 fontStyle
.just
= teJustLeft
;
929 fontStyle
.flags
|= kControlUseJustMask
;
930 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
931 fontStyle
.just
= teJustCenter
;
932 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
933 fontStyle
.just
= teJustRight
;
936 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
937 // won't get grayed out by the system anymore
939 if ( foreground
!= *wxBLACK
)
941 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
942 fontStyle
.flags
|= kControlUseForeColorMask
;
945 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
948 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
951 // setting up a color proc is not recommended anymore
954 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
956 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
957 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
960 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
962 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
965 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
967 SetControlAction( m_controlRef
, actionProc
) ;
970 void wxMacControl::SetViewSize( SInt32 viewSize
)
972 SetControlViewSize(m_controlRef
, viewSize
) ;
975 SInt32
wxMacControl::GetViewSize() const
977 return GetControlViewSize( m_controlRef
) ;
980 bool wxMacControl::IsVisible() const
982 return IsControlVisible( m_controlRef
) ;
985 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
987 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
990 bool wxMacControl::IsEnabled() const
992 #if TARGET_API_MAC_OSX
993 return IsControlEnabled( m_controlRef
) ;
995 return IsControlActive( m_controlRef
) ;
999 bool wxMacControl::IsActive() const
1001 return IsControlActive( m_controlRef
) ;
1004 void wxMacControl::Enable( bool enable
)
1006 #if TARGET_API_MAC_OSX
1008 EnableControl( m_controlRef
) ;
1010 DisableControl( m_controlRef
) ;
1013 ActivateControl( m_controlRef
) ;
1015 DeactivateControl( m_controlRef
) ;
1019 void wxMacControl::SetDrawingEnabled( bool enable
)
1021 #if TARGET_API_MAC_OSX
1022 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1026 bool wxMacControl::GetNeedsDisplay() const
1028 #if TARGET_API_MAC_OSX
1029 return HIViewGetNeedsDisplay( m_controlRef
) ;
1035 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1037 #if TARGET_API_MAC_OSX
1038 if ( where
!= NULL
)
1039 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1041 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1045 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1047 #if TARGET_API_MAC_OSX
1051 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1052 pt
->x
= (int)hiPoint
.x
;
1053 pt
->y
= (int)hiPoint
.y
;
1057 void wxMacControl::SetRect( Rect
*r
)
1059 #if TARGET_API_MAC_OSX
1060 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1061 //CGPoint and CGSize, which have two floats each
1062 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} } ;
1063 HIViewSetFrame ( m_controlRef
, &hir
) ;
1065 SetControlBounds( m_controlRef
, r
) ;
1070 void wxMacControl::GetRect( Rect
*r
)
1072 GetControlBounds( m_controlRef
, r
) ;
1075 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1077 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1080 void wxMacControl::GetBestRect( Rect
*r
)
1082 short baselineoffset
;
1083 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1086 void wxMacControl::SetTitle( const wxString
&title
)
1088 wxFontEncoding encoding
;
1091 encoding
= m_font
.GetEncoding();
1093 encoding
= wxFont::GetDefaultEncoding();
1095 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1098 void wxMacControl::GetFeatures( UInt32
* features
)
1100 GetControlFeatures( m_controlRef
, features
) ;
1103 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1105 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1108 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1110 #if TARGET_API_MAC_OSX
1111 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1112 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1119 #if TARGET_API_MAC_OSX
1120 // SetNeedsDisplay would not invalidate the children
1121 static void InvalidateControlAndChildren( HIViewRef control
)
1123 HIViewSetNeedsDisplay( control
, true ) ;
1124 UInt16 childrenCount
= 0 ;
1125 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1126 if ( err
== errControlIsNotEmbedder
)
1128 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1130 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1133 err
= GetIndexedSubControl( control
, i
, & child
) ;
1134 if ( err
== errControlIsNotEmbedder
)
1136 InvalidateControlAndChildren( child
) ;
1141 void wxMacControl::InvalidateWithChildren()
1143 #if TARGET_API_MAC_OSX
1144 InvalidateControlAndChildren( m_controlRef
) ;
1148 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1150 #if TARGET_API_MAC_OSX
1151 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1152 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1157 // SetNeedsDisplay would not invalidate the children
1163 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1165 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1168 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1169 DataBrowserTableViewColumnIndex position
)
1171 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1174 OSStatus
wxMacControl::AutoSizeListViewColumns()
1176 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1179 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1181 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1184 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1186 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1189 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1191 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1194 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1196 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1199 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1200 const DataBrowserItemID
* items
,
1201 DataBrowserPropertyID preSortProperty
,
1202 DataBrowserPropertyID propertyID
)
1204 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1207 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1209 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1212 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1213 const DataBrowserItemID
* items
,
1214 DataBrowserPropertyID preSortProperty
)
1216 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1219 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1220 const DataBrowserItemID
* items
,
1221 DataBrowserPropertyID preSortProperty
)
1223 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1226 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1227 DataBrowserPropertyID propertyID
,
1228 DataBrowserRevealOptions options
)
1230 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1233 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1234 const DataBrowserItemID
* items
,
1235 DataBrowserSetOption operation
)
1237 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1240 OSStatus
wxMacControl::GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
)
1242 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
) ;
1249 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1251 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;