X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f1c8bd4d13ee2e1a6830c68770b7acdad7ca946..a55d039a23c730975a8b5efedab6b4940fb4009b:/src/mac/carbon/utils.cpp?ds=inline diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index cef9733b64..b3756d3fa3 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: utils.cpp +// Name: src/mac/carbon/utils.cpp // Purpose: Various utilities // Author: Stefan Csomor // Modified by: @@ -9,11 +9,6 @@ // 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" @@ -50,9 +45,13 @@ #include #endif +#ifdef __DARWIN__ +#include +#else #include #include #include +#endif #endif // wxUSE_GUI #include "wx/mac/private.h" // includes mac headers @@ -93,7 +92,7 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn) // 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... @@ -736,8 +735,10 @@ void wxMacWakeUp() 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(), @@ -745,12 +746,20 @@ void wxMacWakeUp() } 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 @@ -770,7 +779,7 @@ void wxMacWakeUp() // ---------------------------------------------------------------------------- -void wxMacRectToNative( const wxRect *wx , Rect *n ) +void wxMacRectToNative( const wxRect *wx , Rect *n ) { n->left = wx->x ; n->top = wx->y ; @@ -778,7 +787,7 @@ void wxMacRectToNative( const wxRect *wx , Rect *n ) 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 ; @@ -786,13 +795,13 @@ void wxMacNativeToRect( const Rect *n , wxRect* wx ) 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 ; @@ -825,7 +834,7 @@ wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl ) m_isCompositing = peer->MacGetTopLevelWindow()->MacUsesCompositing() ; } -wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) +wxMacControl::wxMacControl( wxWindow* peer , ControlRef control ) { Init() ; m_peer = peer ; @@ -964,7 +973,7 @@ bool wxMacControl::HasFocus() const return control == m_controlRef ; } -void wxMacControl::SetNeedsFocusRect( bool needs ) +void wxMacControl::SetNeedsFocusRect( bool needs ) { m_needsFocusRect = needs ; } @@ -1107,10 +1116,25 @@ void wxMacControl::SetDrawingEnabled( bool enable ) bool wxMacControl::GetNeedsDisplay() const { #if TARGET_API_MAC_OSX - return HIViewGetNeedsDisplay( m_controlRef ) ; -#else - return false ; + if ( m_isCompositing ) + { + return HIViewGetNeedsDisplay( m_controlRef ) ; + } + else #endif + { + 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 ; + } + } #endif @@ -1118,7 +1142,7 @@ void wxMacControl::SetNeedsDisplay( RgnHandle where ) { if ( !IsVisible() ) return ; - + #if TARGET_API_MAC_OSX if ( m_isCompositing ) { @@ -1127,12 +1151,12 @@ void wxMacControl::SetNeedsDisplay( RgnHandle where ) 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 ) ; } } @@ -1157,7 +1181,7 @@ void wxMacControl::SetNeedsDisplay( Rect* where ) else #endif { - Rect controlBounds ; + Rect controlBounds ; GetControlBounds( m_controlRef, &controlBounds ) ; if ( where ) { @@ -1165,7 +1189,7 @@ void wxMacControl::SetNeedsDisplay( Rect* where ) OffsetRect( &whereLocal , controlBounds.left , controlBounds.top ) ; SectRect( &controlBounds , &whereLocal, &controlBounds ) ; } - InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ) ; + InvalWindowRect( GetControlOwner( m_controlRef) , &controlBounds ) ; } } @@ -1191,8 +1215,8 @@ void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to 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 ; } @@ -1220,9 +1244,11 @@ void wxMacControl::SetRect( Rect *r ) 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() ; if( parent->m_isRootControl == false ) { @@ -1230,7 +1256,7 @@ void wxMacControl::SetRect( Rect *r ) GetControlBounds( parent->m_controlRef , &superRect ) ; OffsetRect( &controlBounds , superRect.left , superRect.top ) ; } - + SetControlBounds( m_controlRef , &controlBounds ) ; if ( vis ) { @@ -1244,7 +1270,7 @@ void wxMacControl::GetRect( Rect *r ) 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 ) ; @@ -1254,7 +1280,7 @@ void wxMacControl::GetRect( Rect *r ) r->left = 0 ; r->top = 0 ; } - else + else { wxMacControl* parent = m_peer->GetParent()->GetPeer() ; if( parent->m_isRootControl == false ) @@ -1278,7 +1304,7 @@ void wxMacControl::GetBestRect( Rect *r ) GetBestControlRect( m_controlRef , r , &baselineoffset ) ; } -void wxMacControl::SetTitle( const wxString &title ) +void wxMacControl::SetLabel( const wxString &title ) { wxFontEncoding encoding; @@ -1305,7 +1331,7 @@ OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region ) Rect r ; GetControlBounds(m_controlRef, &r ) ; if ( !EmptyRgn( region ) ) - OffsetRgn( region , -r.left , -r.top ) ; + OffsetRgn( region , -r.left , -r.top ) ; } } return err ; @@ -1351,12 +1377,29 @@ void wxMacControl::InvalidateWithChildren() #endif } -void wxMacControl::ScrollRect( const wxRect &r , int dx , int dy ) +void wxMacControl::ScrollRect( wxRect *r , int dx , int dy ) { + wxASSERT( r != NULL ) ; #if TARGET_API_MAC_OSX - HIRect scrollarea = CGRectMake( r.x , r.y , r.width , r.height) ; - HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ; + if ( m_isCompositing ) + { + HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height) ; + HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy ) ; + } + 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 ) ; + } } @@ -1457,5 +1500,83 @@ OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable ) return ::SetTabEnabled( m_controlRef , tabNo , enable ) ; } -#endif // wxUSE_GUI +// +// Quartz Support +// + +#ifdef __WXMAC_OSX__ +// snippets from Sketch Sample from Apple : + +#define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc" +/* + 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) ); + } + + if (cachedRGBProfileRef) + { + // clone the profile reference so that the caller has their own reference, not our cached one + CMCloneProfileRef(cachedRGBProfileRef); + } + + return cachedRGBProfileRef; +} + +/* + Return the generic RGB color space. This is a 'get' function and the caller should + 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 wxMacCFRefHolder genericRGBColorSpace ; + + if (genericRGBColorSpace == NULL) + { + 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