/////////////////////////////////////////////////////////////////////////////
-// Name: utils.cpp
+// Name: src/mac/carbon/utils.cpp
// Purpose: Various utilities
// Author: Stefan Csomor
// Modified by:
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-// Note: this is done in utilscmn.cpp now.
-// #pragma implementation "utils.h"
-#endif
-
#include "wx/wxprec.h"
#include "wx/utils.h"
#include <Multiprocessing.h>
#endif
+#ifdef __DARWIN__
+#include <Carbon/Carbon.h>
+#else
#include <ATSUnicode.h>
#include <TextCommon.h>
#include <TextEncodingConverter.h>
+#endif
#endif // wxUSE_GUI
#include "wx/mac/private.h" // includes mac headers
// debugging support
// ----------------------------------------------------------------------------
-#if defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
+#if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
// MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
if ( isSame )
{
#if TARGET_CARBON
- static wxMacCarbonEvent s_wakeupEvent ;
OSStatus err = noErr ;
+#if 0
+ // lead sometimes to race conditions, although all calls used should be thread safe ...
+ static wxMacCarbonEvent s_wakeupEvent ;
if ( !s_wakeupEvent.IsValid() )
{
err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
}
if ( err == noErr )
{
+
if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
return ;
- s_wakeupEvent.SetTime(0) ;
+ s_wakeupEvent.SetCurrentTime() ;
err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
- kEventPriorityHigh);
+ kEventPriorityHigh );
}
+#else
+ wxMacCarbonEvent wakeupEvent ;
+ wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
+ kEventAttributeNone ) ;
+ err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
+ kEventPriorityHigh );
+#endif
#else
PostEvent( nullEvent , 0 ) ;
#endif
// ----------------------------------------------------------------------------
-void wxMacRectToNative( const wxRect *wx , Rect *n )
+void wxMacRectToNative( const wxRect *wx , Rect *n )
{
n->left = wx->x ;
n->top = wx->y ;
n->bottom = wx->y + wx->height ;
}
-void wxMacNativeToRect( const Rect *n , wxRect* wx )
+void wxMacNativeToRect( const Rect *n , wxRect* wx )
{
wx->x = n->left ;
wx->y = n->top ;
wx->height = n->bottom - n->top ;
}
-void wxMacPointToNative( const wxPoint* wx , Point *n )
+void wxMacPointToNative( const wxPoint* wx , Point *n )
{
n->h = wx->x ;
n->v = wx->y ;
}
-void wxMacNativeToPoint( const Point *n , wxPoint* wx )
+void wxMacNativeToPoint( const Point *n , wxPoint* wx )
{
wx->x = n->h ;
wx->y = n->v ;
m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing() ;
}
-wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
+wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
{
Init() ;
m_peer = peer ;
return control == m_controlRef ;
}
-void wxMacControl::SetNeedsFocusRect( bool needs )
+void wxMacControl::SetNeedsFocusRect( bool needs )
{
m_needsFocusRect = needs ;
}
if ( m_isCompositing )
{
return HIViewGetNeedsDisplay( m_controlRef ) ;
- }
- else
+ }
+ else
#endif
- {
- if ( !IsVisible() )
+ {
+ if ( !IsVisible() )
return false ;
-
- Rect controlBounds ;
- GetControlBounds( m_controlRef, &controlBounds ) ;
- RgnHandle rgn = NewRgn() ;
- GetWindowRegion ( GetControlOwner( m_controlRef ) , kWindowUpdateRgn , rgn ) ;
- Boolean intersect = RectInRgn ( &controlBounds , rgn ) ;
- DisposeRgn( rgn ) ;
- return intersect ;
- }
+
+ Rect controlBounds ;
+ GetControlBounds( m_controlRef, &controlBounds ) ;
+ RgnHandle rgn = NewRgn() ;
+ GetWindowRegion ( GetControlOwner( m_controlRef ) , kWindowUpdateRgn , rgn ) ;
+ Boolean intersect = RectInRgn ( &controlBounds , rgn ) ;
+ DisposeRgn( rgn ) ;
+ return intersect ;
+ }
}
#endif
{
if ( !IsVisible() )
return ;
-
+
#if TARGET_API_MAC_OSX
if ( m_isCompositing )
{
else
#endif
{
- Rect controlBounds ;
+ Rect controlBounds ;
GetControlBounds( m_controlRef, &controlBounds ) ;
RgnHandle update = NewRgn() ;
CopyRgn( where , update ) ;
OffsetRgn( update , controlBounds.left , controlBounds.top ) ;
- InvalWindowRgn( GetControlOwner( m_controlRef) , update ) ;
+ InvalWindowRgn( GetControlOwner( m_controlRef) , update ) ;
}
}
else
#endif
{
- Rect controlBounds ;
+ Rect controlBounds ;
GetControlBounds( m_controlRef, &controlBounds ) ;
if ( where )
{
OffsetRect( &whereLocal , controlBounds.left , controlBounds.top ) ;
SectRect( &controlBounds , &whereLocal, &controlBounds ) ;
}
- InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ) ;
+ InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ) ;
}
}
if ( from->m_isRootControl )
fromRect.left = fromRect.top = 0 ;
if ( to->m_isRootControl )
- toRect.left = toRect.top = 0 ;
-
+ toRect.left = toRect.top = 0 ;
+
pt->x = pt->x + fromRect.left - toRect.left ;
pt->y = pt->y + fromRect.top - toRect.top ;
}
GetControlBounds( m_controlRef , &former ) ;
InvalWindowRect( GetControlOwner( m_controlRef ) , &former ) ;
}
-
+
Rect controlBounds = *r ;
-
+
// since the rect passed in is always (even in non-compositing) relative
// to the (native) parent, we have to adjust to window relative here
wxMacControl* parent = m_peer->GetParent()->GetPeer() ;
GetControlBounds( parent->m_controlRef , &superRect ) ;
OffsetRect( &controlBounds , superRect.left , superRect.top ) ;
}
-
+
SetControlBounds( m_controlRef , &controlBounds ) ;
if ( vis )
{
GetControlBounds( m_controlRef , r ) ;
if ( m_isCompositing == false )
{
- // correct the case of the root control
+ // correct the case of the root control
if ( m_isRootControl )
{
WindowRef wr = GetControlOwner( m_controlRef ) ;
r->left = 0 ;
r->top = 0 ;
}
- else
+ else
{
wxMacControl* parent = m_peer->GetParent()->GetPeer() ;
if( parent->m_isRootControl == false )
GetBestControlRect( m_controlRef , r , &baselineoffset ) ;
}
-void wxMacControl::SetTitle( const wxString &title )
+void wxMacControl::SetLabel( const wxString &title )
{
wxFontEncoding encoding;
Rect r ;
GetControlBounds(m_controlRef, &r ) ;
if ( !EmptyRgn( region ) )
- OffsetRgn( region , -r.left , -r.top ) ;
+ OffsetRgn( region , -r.left , -r.top ) ;
}
}
return err ;
#endif
}
-void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
+void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
{
- wxASSERT( r != NULL ) ;
+ wxASSERT( r != NULL ) ;
#if TARGET_API_MAC_OSX
- if ( m_isCompositing )
- {
- HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height) ;
+ if ( m_isCompositing )
+ {
+ HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height) ;
HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ;
- }
- else
+ }
+ else
#endif
- {
- Rect bounds ;
- GetControlBounds( m_controlRef , &bounds ) ;
- bounds.left += r->x ;
- bounds.top += r->y ;
- bounds.bottom = bounds.top + r->height ;
- bounds.right = bounds.left + r->width ;
- wxMacWindowClipper clip( m_peer ) ;
- RgnHandle updateRgn = NewRgn() ;
- ::ScrollRect( &bounds , dx , dy , updateRgn ) ;
- InvalWindowRgn( GetControlOwner( m_controlRef ) , updateRgn ) ;
- }
+ {
+ Rect bounds ;
+ GetControlBounds( m_controlRef , &bounds ) ;
+ bounds.left += r->x ;
+ bounds.top += r->y ;
+ bounds.bottom = bounds.top + r->height ;
+ bounds.right = bounds.left + r->width ;
+ wxMacWindowClipper clip( m_peer ) ;
+ RgnHandle updateRgn = NewRgn() ;
+ ::ScrollRect( &bounds , dx , dy , updateRgn ) ;
+ InvalWindowRgn( GetControlOwner( m_controlRef ) , updateRgn ) ;
+ }
}
#ifdef __WXMAC_OSX__
// snippets from Sketch Sample from Apple :
-#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
+#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
/*
- This function locates, opens, and returns the profile reference for the calibrated
+ This function locates, opens, and returns the profile reference for the calibrated
Generic RGB color space. It is up to the caller to call CMCloseProfile when done
with the profile reference this function returns.
*/
CMProfileRef wxMacOpenGenericProfile(void)
{
static CMProfileRef cachedRGBProfileRef = NULL;
-
+
// we only create the profile reference once
if (cachedRGBProfileRef == NULL)
{
- CMProfileLocation loc;
-
- loc.locType = cmPathBasedProfile;
- strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
-
- verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
+ CMProfileLocation loc;
+
+ loc.locType = cmPathBasedProfile;
+ strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
+
+ verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
}
if (cachedRGBProfileRef)
{
- // clone the profile reference so that the caller has their own reference, not our cached one
- CMCloneProfileRef(cachedRGBProfileRef);
+ // clone the profile reference so that the caller has their own reference, not our cached one
+ CMCloneProfileRef(cachedRGBProfileRef);
}
return cachedRGBProfileRef;
not release the returned value unless the caller retains it first. Usually callers
of this routine will immediately use the returned colorspace with CoreGraphics
so they typically do not need to retain it themselves.
-
+
This function creates the generic RGB color space once and hangs onto it so it can
return it whenever this function is called.
*/
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_4
+#define kCGColorSpaceGenericRGB CFSTR("kCGColorSpaceGenericRGB")
+#endif
+
CGColorSpaceRef wxMacGetGenericRGBColorSpace()
{
- static CGColorSpaceRef genericRGBColorSpace = NULL;
+ static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace ;
if (genericRGBColorSpace == NULL)
{
- CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
-
- if (genericRGBProfile)
- {
- genericRGBColorSpace = CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile);
- wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ) ;
-
- // we opened the profile so it is up to us to close it
- CMCloseProfile(genericRGBProfile);
- }
+ if ( UMAGetSystemVersion() >= 0x1040 )
+ {
+ genericRGBColorSpace.Set( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) ) ;
+ }
+ else
+ {
+ CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
+
+ if (genericRGBProfile)
+ {
+ genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) ) ;
+ wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") ) ;
+
+ // we opened the profile so it is up to us to close it
+ CMCloseProfile(genericRGBProfile);
+ }
+ }
}
return genericRGBColorSpace;
}
#endif
#endif // wxUSE_GUI
-