1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 // Note: this is done in utilscmn.cpp now.
14 // #pragma implementation "utils.h"
17 #include "wx/wxprec.h"
21 #include "wx/apptrait.h"
24 #include "wx/mac/uma.h"
37 #include "MoreFilesX.h"
45 #if TARGET_API_MAC_OSX
46 #include <CoreServices/CoreServices.h>
48 #include <DriverServices.h>
49 #include <Multiprocessing.h>
52 #include <ATSUnicode.h>
53 #include <TextCommon.h>
54 #include <TextEncodingConverter.h>
57 #include "wx/mac/private.h" // includes mac headers
59 #if defined(__MWERKS__) && wxUSE_UNICODE
63 // ---------------------------------------------------------------------------
64 // code used in both base and GUI compilation
65 // ---------------------------------------------------------------------------
67 // our OS version is the same in non GUI and GUI cases
68 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
72 // are there x-platform conventions ?
74 Gestalt(gestaltSystemVersion
, &theSystem
) ;
75 if (minorVsn
!= NULL
) {
76 *minorVsn
= (theSystem
& 0xFF ) ;
78 if (majorVsn
!= NULL
) {
79 *majorVsn
= (theSystem
>> 8 ) ;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
97 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
99 #ifndef __MetroNubUtils__
100 #include "MetroNubUtils.h"
107 #if TARGET_API_MAC_CARBON
109 #include <CodeFragments.h>
111 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
113 ProcPtr gCallUniversalProc_Proc
= NULL
;
117 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
119 static long fRunOnce
= false;
121 /* ---------------------------------------------------------------------------
123 --------------------------------------------------------------------------- */
125 Boolean
IsMetroNubInstalled()
132 gMetroNubEntry
= NULL
;
134 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
136 /* look for MetroNub's Gestalt selector */
137 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
140 #if TARGET_API_MAC_CARBON
141 if (gCallUniversalProc_Proc
== NULL
)
143 CFragConnectionID connectionID
;
146 ProcPtr symbolAddress
;
148 CFragSymbolClass symbolClass
;
150 symbolAddress
= NULL
;
151 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
152 &connectionID
, &mainAddress
, errorString
);
156 gCallUniversalProc_Proc
= NULL
;
160 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
161 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
165 gCallUniversalProc_Proc
= NULL
;
172 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
174 /* make sure the version of the API is compatible */
175 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
176 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
177 gMetroNubEntry
= block
; /* success! */
186 #if TARGET_API_MAC_CARBON
187 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
189 return (gMetroNubEntry
!= NULL
);
193 /* ---------------------------------------------------------------------------
194 IsMWDebuggerRunning [v1 API]
195 --------------------------------------------------------------------------- */
197 Boolean
IsMWDebuggerRunning()
199 if (IsMetroNubInstalled())
200 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
205 /* ---------------------------------------------------------------------------
206 AmIBeingMWDebugged [v1 API]
207 --------------------------------------------------------------------------- */
209 Boolean
AmIBeingMWDebugged()
211 if (IsMetroNubInstalled())
212 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
217 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
219 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
224 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
229 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
233 // defined in unix/utilsunx.cpp for Mac OS X
235 // get full hostname (with domain name if possible)
236 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
238 return wxGetHostName(buf
, maxSize
);
241 // Get hostname only (without domain name)
242 bool wxGetHostName(wxChar
*buf
, int maxSize
)
244 // Gets Chooser name of user by examining a System resource.
246 const short kComputerNameID
= -16413;
248 short oldResFile
= CurResFile() ;
250 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
251 UseResFile(oldResFile
);
253 if (chooserName
&& *chooserName
)
255 HLock( (Handle
) chooserName
) ;
256 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
257 HUnlock( (Handle
) chooserName
) ;
258 ReleaseResource( (Handle
) chooserName
) ;
259 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
267 // Get user ID e.g. jacs
268 bool wxGetUserId(wxChar
*buf
, int maxSize
)
270 return wxGetUserName( buf
, maxSize
) ;
273 const wxChar
* wxGetHomeDir(wxString
*pstr
)
275 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
) ;
276 return pstr
->c_str() ;
279 // Get user name e.g. Stefan Csomor
280 bool wxGetUserName(wxChar
*buf
, int maxSize
)
282 // Gets Chooser name of user by examining a System resource.
284 const short kChooserNameID
= -16096;
286 short oldResFile
= CurResFile() ;
288 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
289 UseResFile(oldResFile
);
291 if (chooserName
&& *chooserName
)
293 HLock( (Handle
) chooserName
) ;
294 wxString name
= wxMacMakeStringFromPascal( *chooserName
) ;
295 HUnlock( (Handle
) chooserName
) ;
296 ReleaseResource( (Handle
) chooserName
) ;
297 wxStrncpy( buf
, name
, maxSize
- 1 ) ;
305 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
311 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
313 // TODO : under classic there is no environement support, under X yes
317 // set the env var name to the given value, return true on success
318 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
320 // TODO : under classic there is no environement support, under X yes
325 // Execute a program in an Interactive Shell
327 bool wxShell(const wxString
& command
)
333 // Shutdown or reboot the PC
334 bool wxShutdown(wxShutdownFlags wFlags
)
340 wxPowerType
wxGetPowerType()
343 return wxPOWER_UNKNOWN
;
346 wxBatteryState
wxGetBatteryState()
349 return wxBATTERY_UNKNOWN_STATE
;
352 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
353 wxMemorySize
wxGetFreeMemory()
355 return (wxMemorySize
)FreeMem() ;
360 void wxMicroSleep(unsigned long microseconds
)
362 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
363 MPDelayUntil( & wakeup
);
366 void wxMilliSleep(unsigned long milliseconds
)
368 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
369 MPDelayUntil( & wakeup
);
372 void wxSleep(int nSecs
)
374 wxMilliSleep(1000*nSecs
);
379 // Consume all events until no more left
384 #endif // !__DARWIN__
392 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
394 static wxToolkitInfo info
;
395 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
396 info
.name
= _T("wxBase");
404 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
406 static wxToolkitInfo info
;
407 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
408 info
.shortName
= _T("mac");
409 info
.name
= _T("wxMac");
410 #ifdef __WXUNIVERSAL__
411 info
.shortName
<< _T("univ");
412 info
.name
<< _T("/wxUniversal");
417 // Reading and writing resources (eg WIN.INI, .Xdefaults)
419 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
425 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
428 buf
.Printf(wxT("%.4f"), value
);
430 return wxWriteResource(section
, entry
, buf
, file
);
433 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
436 buf
.Printf(wxT("%ld"), value
);
438 return wxWriteResource(section
, entry
, buf
, file
);
441 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
444 buf
.Printf(wxT("%d"), value
);
446 return wxWriteResource(section
, entry
, buf
, file
);
449 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
455 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
458 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
461 *value
= (float)strtod(s
, NULL
);
468 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
471 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
474 *value
= strtol(s
, NULL
, 10);
481 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
484 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
487 *value
= (int)strtol(s
, NULL
, 10);
493 #endif // wxUSE_RESOURCES
495 int gs_wxBusyCursorCount
= 0;
496 extern wxCursor gMacCurrentCursor
;
497 wxCursor gMacStoredActiveCursor
;
499 // Set the cursor to the busy cursor for all windows
500 void wxBeginBusyCursor(wxCursor
*cursor
)
502 if (gs_wxBusyCursorCount
++ == 0)
504 gMacStoredActiveCursor
= gMacCurrentCursor
;
505 cursor
->MacInstall() ;
507 //else: nothing to do, already set
510 // Restore cursor to normal
511 void wxEndBusyCursor()
513 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
514 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
516 if (--gs_wxBusyCursorCount
== 0)
518 gMacStoredActiveCursor
.MacInstall() ;
519 gMacStoredActiveCursor
= wxNullCursor
;
523 // true if we're between the above two calls
526 return (gs_wxBusyCursorCount
> 0);
533 wxString
wxMacFindFolder( short vol
,
535 Boolean createFolder
)
540 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
541 strDir
= wxMacFSRefToPath( &fsRef
) + wxFILE_SEP_PATH
;
550 // Check whether this window wants to process messages, e.g. Stop button
551 // in long calculations.
552 bool wxCheckForInterrupt(wxWindow
*wnd
)
558 void wxGetMousePosition( int* x
, int* y
)
563 LocalToGlobal( &pt
) ;
568 // Return true if we have a colour display
569 bool wxColourDisplay()
574 // Returns depth of screen
578 SetRect(&globRect
, -32760, -32760, 32760, 32760);
579 GDHandle theMaxDevice
;
582 theMaxDevice
= GetMaxDevice(&globRect
);
583 if (theMaxDevice
!= nil
)
584 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
589 // Get size of display
590 void wxDisplaySize(int *width
, int *height
)
593 GetQDGlobalsScreenBits( &screenBits
);
596 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
598 if (height
!= NULL
) {
599 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
603 void wxDisplaySizeMM(int *width
, int *height
)
605 wxDisplaySize(width
, height
);
606 // on mac 72 is fixed (at least now ;-)
607 float cvPt2Mm
= 25.4 / 72;
610 *width
= int( *width
* cvPt2Mm
);
612 if (height
!= NULL
) {
613 *height
= int( *height
* cvPt2Mm
);
617 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
620 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
626 *width
= r
.right
- r
.left
;
628 *height
= r
.bottom
- r
.top
;
631 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
633 return wxGenericFindWindowAtPoint(pt
);
640 wxString
wxGetOsDescription()
642 #ifdef WXWIN_OS_DESCRIPTION
643 // use configure generated description if available
644 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
646 return wxT("MacOS") ; //TODO:define further
651 wxChar
*wxGetUserHome (const wxString
& user
)
657 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
667 int pos
= p
.Find(':') ;
668 if ( pos
!= wxNOT_FOUND
) {
677 err
= wxMacPathToFSRef( p
, &fsRef
) ;
680 FSVolumeRefNum vRefNum
;
681 err
= FSGetVRefNum( &fsRef
, &vRefNum
) ;
684 UInt64 freeBytes
, totalBytes
;
685 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
) ;
689 *pTotal
= wxLongLong( totalBytes
) ;
691 *pFree
= wxLongLong( freeBytes
) ;
696 return err
== noErr
;
698 #endif // !__DARWIN__
700 //---------------------------------------------------------------------------
701 // wxMac Specific utility functions
702 //---------------------------------------------------------------------------
704 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
706 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
707 int len
= strlen(buf
) ;
712 memcpy( (char*) &to
[1] , buf
, len
) ;
715 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
717 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
721 // ----------------------------------------------------------------------------
722 // Common Event Support
723 // ----------------------------------------------------------------------------
726 extern ProcessSerialNumber gAppProcess
;
730 ProcessSerialNumber psn
;
732 psn
.highLongOfPSN
= 0 ;
733 psn
.lowLongOfPSN
= kCurrentProcess
;
734 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
738 static wxMacCarbonEvent s_wakeupEvent
;
739 OSStatus err
= noErr
;
740 if ( !s_wakeupEvent
.IsValid() )
742 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
743 kEventAttributeNone
) ;
747 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
749 s_wakeupEvent
.SetTime(0) ;
750 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
754 PostEvent( nullEvent
, 0 ) ;
759 WakeUpProcess( &gAppProcess
) ;
768 // ----------------------------------------------------------------------------
769 // Carbon Event Support
770 // ----------------------------------------------------------------------------
773 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
775 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
778 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
780 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
783 // ----------------------------------------------------------------------------
784 // Control Access Support
785 // ----------------------------------------------------------------------------
787 void wxMacControl::Dispose()
789 ::DisposeControl( m_controlRef
) ;
790 m_controlRef
= NULL
;
793 void wxMacControl::SetReference( SInt32 data
)
795 SetControlReference( m_controlRef
, data
) ;
798 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
800 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
803 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
805 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
808 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
810 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
813 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
815 #if TARGET_API_MAC_OSX
816 return SendEventToEventTargetWithOptions( event
,
817 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
819 #pragma unused(inOptions)
820 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
824 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
826 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
827 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
828 return SendEvent( event
, inOptions
) ;
831 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
834 memset( &command
, 0 , sizeof(command
) ) ;
835 command
.commandID
= commandID
;
836 return SendHICommand( command
, inOptions
) ;
839 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
841 HiliteControl( m_controlRef
, part
) ;
842 unsigned long finalTicks
;
843 Delay( ticks
, &finalTicks
) ;
844 HiliteControl( m_controlRef
, kControlNoPart
) ;
847 SInt32
wxMacControl::GetValue() const
849 return ::GetControl32BitValue( m_controlRef
) ;
852 SInt32
wxMacControl::GetMaximum() const
854 return ::GetControl32BitMaximum( m_controlRef
) ;
857 SInt32
wxMacControl::GetMinimum() const
859 return ::GetControl32BitMinimum( m_controlRef
) ;
862 void wxMacControl::SetValue( SInt32 v
)
864 ::SetControl32BitValue( m_controlRef
, v
) ;
867 void wxMacControl::SetMinimum( SInt32 v
)
869 ::SetControl32BitMinimum( m_controlRef
, v
) ;
872 void wxMacControl::SetMaximum( SInt32 v
)
874 ::SetControl32BitMaximum( m_controlRef
, v
) ;
877 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
879 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
880 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
881 ::SetControl32BitValue( m_controlRef
, value
) ;
884 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
886 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
887 m_controlRef
, focusPart
) ;
890 bool wxMacControl::HasFocus() const
893 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
894 return control
== m_controlRef
;
897 bool wxMacControl::NeedsFocusRect() const
902 void wxMacControl::VisibilityChanged(bool shown
)
906 void wxMacControl::SuperChangedPosition()
910 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
913 ControlFontStyleRec fontStyle
;
914 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
916 switch( font
.MacGetThemeFontID() )
918 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
919 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
920 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
921 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
923 fontStyle
.flags
= kControlUseFontMask
;
927 fontStyle
.font
= font
.MacGetFontNum() ;
928 fontStyle
.style
= font
.MacGetFontStyle() ;
929 fontStyle
.size
= font
.MacGetFontSize() ;
930 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
933 fontStyle
.just
= teJustLeft
;
934 fontStyle
.flags
|= kControlUseJustMask
;
935 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
936 fontStyle
.just
= teJustCenter
;
937 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
938 fontStyle
.just
= teJustRight
;
941 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
942 // won't get grayed out by the system anymore
944 if ( foreground
!= *wxBLACK
)
946 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
947 fontStyle
.flags
|= kControlUseForeColorMask
;
950 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
953 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
956 // setting up a color proc is not recommended anymore
959 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
961 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
962 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
965 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
967 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
970 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
972 SetControlAction( m_controlRef
, actionProc
) ;
975 void wxMacControl::SetViewSize( SInt32 viewSize
)
977 SetControlViewSize(m_controlRef
, viewSize
) ;
980 SInt32
wxMacControl::GetViewSize() const
982 return GetControlViewSize( m_controlRef
) ;
985 bool wxMacControl::IsVisible() const
987 return IsControlVisible( m_controlRef
) ;
990 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
992 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
995 bool wxMacControl::IsEnabled() const
997 #if TARGET_API_MAC_OSX
998 return IsControlEnabled( m_controlRef
) ;
1000 return IsControlActive( m_controlRef
) ;
1004 bool wxMacControl::IsActive() const
1006 return IsControlActive( m_controlRef
) ;
1009 void wxMacControl::Enable( bool enable
)
1011 #if TARGET_API_MAC_OSX
1013 EnableControl( m_controlRef
) ;
1015 DisableControl( m_controlRef
) ;
1018 ActivateControl( m_controlRef
) ;
1020 DeactivateControl( m_controlRef
) ;
1024 void wxMacControl::SetDrawingEnabled( bool enable
)
1026 #if TARGET_API_MAC_OSX
1027 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1031 #if TARGET_API_MAC_OSX
1032 bool wxMacControl::GetNeedsDisplay() const
1034 #if TARGET_API_MAC_OSX
1035 return HIViewGetNeedsDisplay( m_controlRef
) ;
1041 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1043 #if TARGET_API_MAC_OSX
1044 if ( where
!= NULL
)
1045 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1047 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1052 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1054 #if TARGET_API_MAC_OSX
1058 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1059 pt
->x
= (int)hiPoint
.x
;
1060 pt
->y
= (int)hiPoint
.y
;
1064 from
->GetRect( &fromRect
) ;
1065 to
->GetRect( &toRect
) ;
1067 // correct the case of the root control
1068 if ( fromRect
.left
== -32768 && fromRect
.top
== -32768 && fromRect
.bottom
== 32767 && fromRect
.right
== 32767)
1069 fromRect
.left
= fromRect
.top
= 0 ;
1071 if ( toRect
.left
== -32768 && toRect
.top
== -32768 && toRect
.bottom
== 32767 && toRect
.right
== 32767 )
1072 toRect
.left
= toRect
.top
= 0 ;
1074 pt
->x
= pt
->x
+ fromRect
.left
- toRect
.left
;
1075 pt
->y
= pt
->y
+ fromRect
.top
- toRect
.top
;
1079 void wxMacControl::SetRect( Rect
*r
)
1081 #if TARGET_API_MAC_OSX
1082 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1083 //CGPoint and CGSize, which have two floats each
1084 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} } ;
1085 HIViewSetFrame ( m_controlRef
, &hir
) ;
1087 SetControlBounds( m_controlRef
, r
) ;
1092 void wxMacControl::GetRect( Rect
*r
)
1094 GetControlBounds( m_controlRef
, r
) ;
1097 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1099 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1102 void wxMacControl::GetBestRect( Rect
*r
)
1104 short baselineoffset
;
1105 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1108 void wxMacControl::SetTitle( const wxString
&title
)
1110 wxFontEncoding encoding
;
1113 encoding
= m_font
.GetEncoding();
1115 encoding
= wxFont::GetDefaultEncoding();
1117 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1120 void wxMacControl::GetFeatures( UInt32
* features
)
1122 GetControlFeatures( m_controlRef
, features
) ;
1125 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1127 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1130 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1132 #if TARGET_API_MAC_OSX
1133 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1134 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1141 #if TARGET_API_MAC_OSX
1142 // SetNeedsDisplay would not invalidate the children
1143 static void InvalidateControlAndChildren( HIViewRef control
)
1145 HIViewSetNeedsDisplay( control
, true ) ;
1146 UInt16 childrenCount
= 0 ;
1147 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1148 if ( err
== errControlIsNotEmbedder
)
1150 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1152 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1155 err
= GetIndexedSubControl( control
, i
, & child
) ;
1156 if ( err
== errControlIsNotEmbedder
)
1158 InvalidateControlAndChildren( child
) ;
1163 void wxMacControl::InvalidateWithChildren()
1165 #if TARGET_API_MAC_OSX
1166 InvalidateControlAndChildren( m_controlRef
) ;
1170 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1172 #if TARGET_API_MAC_OSX
1173 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1174 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1179 // SetNeedsDisplay would not invalidate the children
1185 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1187 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1190 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1191 DataBrowserTableViewColumnIndex position
)
1193 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1196 OSStatus
wxMacControl::AutoSizeListViewColumns()
1198 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1201 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1203 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1206 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1208 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1211 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1213 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1216 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1218 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1221 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1222 const DataBrowserItemID
* items
,
1223 DataBrowserPropertyID preSortProperty
,
1224 DataBrowserPropertyID propertyID
)
1226 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1229 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1231 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1234 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1235 const DataBrowserItemID
* items
,
1236 DataBrowserPropertyID preSortProperty
)
1238 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1241 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1242 const DataBrowserItemID
* items
,
1243 DataBrowserPropertyID preSortProperty
)
1245 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1248 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1249 DataBrowserPropertyID propertyID
,
1250 DataBrowserRevealOptions options
)
1252 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1255 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1256 const DataBrowserItemID
* items
,
1257 DataBrowserSetOption operation
)
1259 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1262 OSStatus
wxMacControl::GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
)
1264 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
) ;
1271 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1273 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;