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 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
340 wxMemorySize
wxGetFreeMemory()
342 return (wxMemorySize
)FreeMem() ;
347 void wxMicroSleep(unsigned long microseconds
)
349 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
350 MPDelayUntil( & wakeup
);
353 void wxMilliSleep(unsigned long milliseconds
)
355 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
356 MPDelayUntil( & wakeup
);
359 void wxSleep(int nSecs
)
361 wxMilliSleep(1000*nSecs
);
366 // Consume all events until no more left
371 #endif // !__DARWIN__
379 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
381 static wxToolkitInfo info
;
382 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
383 info
.name
= _T("wxBase");
391 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
393 static wxToolkitInfo info
;
394 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
395 info
.shortName
= _T("mac");
396 info
.name
= _T("wxMac");
397 #ifdef __WXUNIVERSAL__
398 info
.shortName
<< _T("univ");
399 info
.name
<< _T("/wxUniversal");
404 // Reading and writing resources (eg WIN.INI, .Xdefaults)
406 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
412 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
415 buf
.Printf(wxT("%.4f"), value
);
417 return wxWriteResource(section
, entry
, buf
, file
);
420 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
423 buf
.Printf(wxT("%ld"), value
);
425 return wxWriteResource(section
, entry
, buf
, file
);
428 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
431 buf
.Printf(wxT("%d"), value
);
433 return wxWriteResource(section
, entry
, buf
, file
);
436 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
442 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
445 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
448 *value
= (float)strtod(s
, NULL
);
455 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
458 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
461 *value
= strtol(s
, NULL
, 10);
468 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
471 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
474 *value
= (int)strtol(s
, NULL
, 10);
480 #endif // wxUSE_RESOURCES
482 int gs_wxBusyCursorCount
= 0;
483 extern wxCursor gMacCurrentCursor
;
484 wxCursor gMacStoredActiveCursor
;
486 // Set the cursor to the busy cursor for all windows
487 void wxBeginBusyCursor(wxCursor
*cursor
)
489 if (gs_wxBusyCursorCount
++ == 0)
491 gMacStoredActiveCursor
= gMacCurrentCursor
;
492 cursor
->MacInstall() ;
494 //else: nothing to do, already set
497 // Restore cursor to normal
498 void wxEndBusyCursor()
500 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
501 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
503 if (--gs_wxBusyCursorCount
== 0)
505 gMacStoredActiveCursor
.MacInstall() ;
506 gMacStoredActiveCursor
= wxNullCursor
;
510 // true if we're between the above two calls
513 return (gs_wxBusyCursorCount
> 0);
520 wxString
wxMacFindFolder( short vol
,
522 Boolean createFolder
)
527 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
528 strDir
= wxMacFSRefToPath( &fsRef
) + wxFILE_SEP_PATH
;
537 // Check whether this window wants to process messages, e.g. Stop button
538 // in long calculations.
539 bool wxCheckForInterrupt(wxWindow
*wnd
)
545 void wxGetMousePosition( int* x
, int* y
)
550 LocalToGlobal( &pt
) ;
555 // Return true if we have a colour display
556 bool wxColourDisplay()
561 // Returns depth of screen
565 SetRect(&globRect
, -32760, -32760, 32760, 32760);
566 GDHandle theMaxDevice
;
569 theMaxDevice
= GetMaxDevice(&globRect
);
570 if (theMaxDevice
!= nil
)
571 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
576 // Get size of display
577 void wxDisplaySize(int *width
, int *height
)
580 GetQDGlobalsScreenBits( &screenBits
);
583 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
585 if (height
!= NULL
) {
586 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
590 void wxDisplaySizeMM(int *width
, int *height
)
592 wxDisplaySize(width
, height
);
593 // on mac 72 is fixed (at least now ;-)
594 float cvPt2Mm
= 25.4 / 72;
597 *width
= int( *width
* cvPt2Mm
);
599 if (height
!= NULL
) {
600 *height
= int( *height
* cvPt2Mm
);
604 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
607 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
) ;
613 *width
= r
.right
- r
.left
;
615 *height
= r
.bottom
- r
.top
;
618 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
620 return wxGenericFindWindowAtPoint(pt
);
627 wxString
wxGetOsDescription()
629 #ifdef WXWIN_OS_DESCRIPTION
630 // use configure generated description if available
631 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
633 return wxT("MacOS") ; //TODO:define further
638 wxChar
*wxGetUserHome (const wxString
& user
)
644 bool wxGetDiskSpace(const wxString
& path
, wxLongLong
*pTotal
, wxLongLong
*pFree
)
654 int pos
= p
.Find(':') ;
655 if ( pos
!= wxNOT_FOUND
) {
664 err
= wxMacPathToFSRef( p
, &fsRef
) ;
667 FSVolumeRefNum vRefNum
;
668 err
= FSGetVRefNum( &fsRef
, &vRefNum
) ;
671 UInt64 freeBytes
, totalBytes
;
672 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
) ;
676 *pTotal
= wxLongLong( totalBytes
) ;
678 *pFree
= wxLongLong( freeBytes
) ;
683 return err
== noErr
;
685 #endif // !__DARWIN__
687 //---------------------------------------------------------------------------
688 // wxMac Specific utility functions
689 //---------------------------------------------------------------------------
691 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
693 wxCharBuffer buf
= from
.mb_str( wxConvLocal
) ;
694 int len
= strlen(buf
) ;
699 memcpy( (char*) &to
[1] , buf
, len
) ;
702 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
704 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] ) ;
708 // ----------------------------------------------------------------------------
709 // Common Event Support
710 // ----------------------------------------------------------------------------
713 extern ProcessSerialNumber gAppProcess
;
717 ProcessSerialNumber psn
;
719 psn
.highLongOfPSN
= 0 ;
720 psn
.lowLongOfPSN
= kCurrentProcess
;
721 SameProcess( &gAppProcess
, &psn
, &isSame
) ;
725 static wxMacCarbonEvent s_wakeupEvent
;
726 OSStatus err
= noErr
;
727 if ( !s_wakeupEvent
.IsValid() )
729 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
730 kEventAttributeNone
) ;
734 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
736 s_wakeupEvent
.SetTime(0) ;
737 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
741 PostEvent( nullEvent
, 0 ) ;
746 WakeUpProcess( &gAppProcess
) ;
755 // ----------------------------------------------------------------------------
756 // Carbon Event Support
757 // ----------------------------------------------------------------------------
760 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
762 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
) ;
765 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
767 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
) ;
770 // ----------------------------------------------------------------------------
771 // Control Access Support
772 // ----------------------------------------------------------------------------
774 void wxMacControl::Dispose()
776 ::DisposeControl( m_controlRef
) ;
777 m_controlRef
= NULL
;
780 void wxMacControl::SetReference( SInt32 data
)
782 SetControlReference( m_controlRef
, data
) ;
785 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
787 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
) ;
790 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
792 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
) ;
795 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
797 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
) ;
800 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
802 #if TARGET_API_MAC_OSX
803 return SendEventToEventTargetWithOptions( event
,
804 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
806 #pragma unused(inOptions)
807 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) ) ;
811 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
813 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
) ;
814 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
) ;
815 return SendEvent( event
, inOptions
) ;
818 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
821 memset( &command
, 0 , sizeof(command
) ) ;
822 command
.commandID
= commandID
;
823 return SendHICommand( command
, inOptions
) ;
826 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
828 HiliteControl( m_controlRef
, part
) ;
829 unsigned long finalTicks
;
830 Delay( ticks
, &finalTicks
) ;
831 HiliteControl( m_controlRef
, kControlNoPart
) ;
834 SInt32
wxMacControl::GetValue() const
836 return ::GetControl32BitValue( m_controlRef
) ;
839 SInt32
wxMacControl::GetMaximum() const
841 return ::GetControl32BitMaximum( m_controlRef
) ;
844 SInt32
wxMacControl::GetMinimum() const
846 return ::GetControl32BitMinimum( m_controlRef
) ;
849 void wxMacControl::SetValue( SInt32 v
)
851 ::SetControl32BitValue( m_controlRef
, v
) ;
854 void wxMacControl::SetMinimum( SInt32 v
)
856 ::SetControl32BitMinimum( m_controlRef
, v
) ;
859 void wxMacControl::SetMaximum( SInt32 v
)
861 ::SetControl32BitMaximum( m_controlRef
, v
) ;
864 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
866 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
867 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
868 ::SetControl32BitValue( m_controlRef
, value
) ;
871 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
873 return SetKeyboardFocus( GetControlOwner( m_controlRef
) ,
874 m_controlRef
, focusPart
) ;
877 bool wxMacControl::HasFocus() const
880 GetKeyboardFocus( GetUserFocusWindow() , &control
) ;
881 return control
== m_controlRef
;
884 bool wxMacControl::NeedsFocusRect() const
889 void wxMacControl::VisibilityChanged(bool shown
)
893 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
896 ControlFontStyleRec fontStyle
;
897 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
899 switch( font
.MacGetThemeFontID() )
901 case kThemeSmallSystemFont
: fontStyle
.font
= kControlFontSmallSystemFont
; break ;
902 case 109 /*mini font */ : fontStyle
.font
= -5 ; break ;
903 case kThemeSystemFont
: fontStyle
.font
= kControlFontBigSystemFont
; break ;
904 default : fontStyle
.font
= kControlFontBigSystemFont
; break ;
906 fontStyle
.flags
= kControlUseFontMask
;
910 fontStyle
.font
= font
.MacGetFontNum() ;
911 fontStyle
.style
= font
.MacGetFontStyle() ;
912 fontStyle
.size
= font
.MacGetFontSize() ;
913 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
916 fontStyle
.just
= teJustLeft
;
917 fontStyle
.flags
|= kControlUseJustMask
;
918 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
919 fontStyle
.just
= teJustCenter
;
920 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
921 fontStyle
.just
= teJustRight
;
924 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
925 // won't get grayed out by the system anymore
927 if ( foreground
!= *wxBLACK
)
929 fontStyle
.foreColor
= MAC_WXCOLORREF(foreground
.GetPixel() ) ;
930 fontStyle
.flags
|= kControlUseForeColorMask
;
933 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
936 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
939 // setting up a color proc is not recommended anymore
942 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
944 ::SetControl32BitMinimum( m_controlRef
, minimum
) ;
945 ::SetControl32BitMaximum( m_controlRef
, maximum
) ;
948 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
950 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
) ;
953 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
955 SetControlAction( m_controlRef
, actionProc
) ;
958 void wxMacControl::SetViewSize( SInt32 viewSize
)
960 SetControlViewSize(m_controlRef
, viewSize
) ;
963 SInt32
wxMacControl::GetViewSize() const
965 return GetControlViewSize( m_controlRef
) ;
968 bool wxMacControl::IsVisible() const
970 return IsControlVisible( m_controlRef
) ;
973 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
975 SetControlVisibility( m_controlRef
, visible
, redraw
) ;
978 bool wxMacControl::IsEnabled() const
980 #if TARGET_API_MAC_OSX
981 return IsControlEnabled( m_controlRef
) ;
983 return IsControlActive( m_controlRef
) ;
987 bool wxMacControl::IsActive() const
989 return IsControlActive( m_controlRef
) ;
992 void wxMacControl::Enable( bool enable
)
994 #if TARGET_API_MAC_OSX
996 EnableControl( m_controlRef
) ;
998 DisableControl( m_controlRef
) ;
1001 ActivateControl( m_controlRef
) ;
1003 DeactivateControl( m_controlRef
) ;
1007 void wxMacControl::SetDrawingEnabled( bool enable
)
1009 #if TARGET_API_MAC_OSX
1010 HIViewSetDrawingEnabled( m_controlRef
, enable
) ;
1014 bool wxMacControl::GetNeedsDisplay() const
1016 #if TARGET_API_MAC_OSX
1017 return HIViewGetNeedsDisplay( m_controlRef
) ;
1023 void wxMacControl::SetNeedsDisplay( bool needsDisplay
, RgnHandle where
)
1025 #if TARGET_API_MAC_OSX
1026 if ( where
!= NULL
)
1027 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, needsDisplay
) ;
1029 HIViewSetNeedsDisplay( m_controlRef
, needsDisplay
) ;
1033 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1035 #if TARGET_API_MAC_OSX
1039 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
) ;
1040 pt
->x
= (int)hiPoint
.x
;
1041 pt
->y
= (int)hiPoint
.y
;
1045 void wxMacControl::SetRect( Rect
*r
)
1047 #if TARGET_API_MAC_OSX
1048 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1049 //CGPoint and CGSize, which have two floats each
1050 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} } ;
1051 HIViewSetFrame ( m_controlRef
, &hir
) ;
1053 SetControlBounds( m_controlRef
, r
) ;
1058 void wxMacControl::GetRect( Rect
*r
)
1060 GetControlBounds( m_controlRef
, r
) ;
1063 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1065 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
) ;
1068 void wxMacControl::GetBestRect( Rect
*r
)
1070 short baselineoffset
;
1071 GetBestControlRect( m_controlRef
, r
, &baselineoffset
) ;
1074 void wxMacControl::SetTitle( const wxString
&title
)
1076 wxFontEncoding encoding
;
1079 encoding
= m_font
.GetEncoding();
1081 encoding
= wxFont::GetDefaultEncoding();
1083 UMASetControlTitle( m_controlRef
, title
, encoding
) ;
1086 void wxMacControl::GetFeatures( UInt32
* features
)
1088 GetControlFeatures( m_controlRef
, features
) ;
1091 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1093 return GetControlRegion( m_controlRef
, partCode
, region
) ;
1096 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1098 #if TARGET_API_MAC_OSX
1099 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1100 (other
!= NULL
) ? other
->m_controlRef
: NULL
) ;
1107 #if TARGET_API_MAC_OSX
1108 // SetNeedsDisplay would not invalidate the children
1109 static void InvalidateControlAndChildren( HIViewRef control
)
1111 HIViewSetNeedsDisplay( control
, true ) ;
1112 UInt16 childrenCount
= 0 ;
1113 OSStatus err
= CountSubControls( control
, &childrenCount
) ;
1114 if ( err
== errControlIsNotEmbedder
)
1116 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") ) ;
1118 for ( UInt16 i
= childrenCount
; i
>=1 ; --i
)
1121 err
= GetIndexedSubControl( control
, i
, & child
) ;
1122 if ( err
== errControlIsNotEmbedder
)
1124 InvalidateControlAndChildren( child
) ;
1129 void wxMacControl::InvalidateWithChildren()
1131 #if TARGET_API_MAC_OSX
1132 InvalidateControlAndChildren( m_controlRef
) ;
1136 void wxMacControl::ScrollRect( const wxRect
&r
, int dx
, int dy
)
1138 #if TARGET_API_MAC_OSX
1139 HIRect scrollarea
= CGRectMake( r
.x
, r
.y
, r
.width
, r
.height
) ;
1140 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
) ;
1145 // SetNeedsDisplay would not invalidate the children
1151 OSStatus
wxMacControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1153 return SetDataBrowserSelectionFlags( m_controlRef
, options
) ;
1156 OSStatus
wxMacControl::AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1157 DataBrowserTableViewColumnIndex position
)
1159 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
) ;
1162 OSStatus
wxMacControl::AutoSizeListViewColumns()
1164 return AutoSizeDataBrowserListViewColumns(m_controlRef
) ;
1167 OSStatus
wxMacControl::SetHasScrollBars( bool horiz
, bool vert
)
1169 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
) ;
1172 OSStatus
wxMacControl::SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1174 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
) ;
1177 OSStatus
wxMacControl::SetListViewHeaderBtnHeight(UInt16 height
)
1179 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
,height
) ;
1182 OSStatus
wxMacControl::SetCallbacks(const DataBrowserCallbacks
* callbacks
)
1184 return SetDataBrowserCallbacks( m_controlRef
, callbacks
) ;
1187 OSStatus
wxMacControl::UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
1188 const DataBrowserItemID
* items
,
1189 DataBrowserPropertyID preSortProperty
,
1190 DataBrowserPropertyID propertyID
)
1192 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
) ;
1195 bool wxMacControl::IsItemSelected( DataBrowserItemID item
)
1197 return IsDataBrowserItemSelected( m_controlRef
, item
) ;
1200 OSStatus
wxMacControl::AddItems( DataBrowserItemID container
, UInt32 numItems
,
1201 const DataBrowserItemID
* items
,
1202 DataBrowserPropertyID preSortProperty
)
1204 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1207 OSStatus
wxMacControl::RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
1208 const DataBrowserItemID
* items
,
1209 DataBrowserPropertyID preSortProperty
)
1211 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
) ;
1214 OSStatus
wxMacControl::RevealItem( DataBrowserItemID item
,
1215 DataBrowserPropertyID propertyID
,
1216 DataBrowserRevealOptions options
)
1218 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
) ;
1221 OSStatus
wxMacControl::SetSelectedItems(UInt32 numItems
,
1222 const DataBrowserItemID
* items
,
1223 DataBrowserSetOption operation
)
1225 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
) ;
1228 OSStatus
wxMacControl::GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
)
1230 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
) ;
1237 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
1239 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
) ;