]> git.saurik.com Git - wxWidgets.git/commitdiff
trials for proper synchronizing between different contexts on the same window
authorStefan Csomor <csomor@advancedconcepts.ch>
Mon, 21 Feb 2005 13:57:05 +0000 (13:57 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Mon, 21 Feb 2005 13:57:05 +0000 (13:57 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@32291 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/dccg.cpp
src/mac/carbon/dcclient.cpp

index 71e69dc91147b070d146ffbe987de5fe45bc34df..9beef3c3c83b697bd1f98827cf024945affb103d 100755 (executable)
@@ -205,11 +205,12 @@ wxMacCGContext::~wxMacCGContext()
 {
     if ( m_cgContext )
     {
+        CGContextSynchronize( m_cgContext ) ;
         CGContextRestoreGState( m_cgContext ) ;
         CGContextRestoreGState( m_cgContext ) ;
     }
     if ( m_qdPort )
-        QDEndCGContext( m_qdPort , &m_cgContext ) ;
+        CGContextRelease( m_cgContext ) ;
 }
 
 
@@ -281,7 +282,7 @@ CGContextRef wxMacCGContext::GetNativeContext()
     {
         Rect bounds ;
         GetPortBounds( (CGrafPtr) m_qdPort , &bounds ) ;
-        OSStatus status = QDBeginCGContext( (CGrafPtr) m_qdPort , &m_cgContext ) ;
+        OSStatus status = CreateCGContextForPort((CGrafPtr) m_qdPort , &m_cgContext) ;
         CGContextSaveGState( m_cgContext ) ;
 
         wxASSERT_MSG( status == noErr , wxT("Cannot nest wxDCs on the same window") ) ;
@@ -1272,35 +1273,64 @@ bool  wxDC::DoBlit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height,
         xsrcMask = xsrc; ysrcMask = ysrc;
     }
 
+    wxCoord yysrc = source->YLOG2DEVMAC(ysrc) ;
+    wxCoord xxsrc = source->XLOG2DEVMAC(xsrc)  ;
+    wxCoord wwsrc = source->XLOG2DEVREL(width ) ;
+    wxCoord hhsrc = source->YLOG2DEVREL(height) ;
+    
+    wxCoord yydest = YLOG2DEVMAC(ydest) ;
+    wxCoord xxdest = XLOG2DEVMAC(xdest) ;
+    wxCoord wwdest = XLOG2DEVREL(width ) ;
+    wxCoord hhdest = YLOG2DEVREL(height) ;
+    
     wxMemoryDC* memdc = dynamic_cast<wxMemoryDC*>(source) ;
     if ( memdc && logical_func == wxCOPY )
     {
         wxBitmap blit = memdc->GetSelectedObject() ;
         wxASSERT_MSG( blit.Ok() , wxT("Invalid bitmap for blitting") ) ;
 
-        wxCoord xxdest = XLOG2DEVMAC(xdest);
-        wxCoord yydest = YLOG2DEVMAC(ydest);
-        wxCoord ww = XLOG2DEVREL(width);
-        wxCoord hh = YLOG2DEVREL(height);
-
         wxCoord bmpwidth = blit.GetWidth();
         wxCoord bmpheight = blit.GetHeight();
         
-        if ( xsrc != 0 || ysrc != 0 || bmpwidth != width || bmpheight != height )
+        if ( xxsrc != 0 || yysrc != 0 || bmpwidth != wwsrc || bmpheight != hhsrc )
+        {
+            wwsrc = wxMin( wwsrc , bmpwidth - xxsrc ) ;
+            hhsrc = wxMin( hhsrc , bmpheight - yysrc ) ;
+            if ( wwsrc > 0 && hhsrc > 0 )
+            {
+                if ( xxsrc >= 0 && yysrc >= 0 )
+                {
+                    wxRect subrect( xxsrc, yysrc, wwsrc , hhsrc ) ;
+                    blit = blit.GetSubBitmap( subrect ) ;
+                }
+                else
+                {
+                    // in this case we'd probably have to adjust the different coordinates, but
+                    // we have to find out proper contract first
+                    blit = wxNullBitmap ;
+                }
+            }
+            else
+            {
+                blit = wxNullBitmap ;
+            }
+        }
+        if ( blit.Ok() )
         {
-            wxRect subrect( xsrc, ysrc, width , height ) ;
-            blit = blit.GetSubBitmap( subrect ) ;
+            CGContextRef cg = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ;
+            CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ;
+            HIRect r = CGRectMake( xxdest , yydest , wwdest , hhdest ) ;
+            HIViewDrawCGImage( cg , &r , image ) ;
+            CGImageRelease( image ) ;
         }
-        
-        CGContextRef cg = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ;
-        CGImageRef image = (CGImageRef)( blit.CGImageCreate() ) ;
-        HIRect r = CGRectMake( xxdest , yydest , ww , hh ) ;
-        HIViewDrawCGImage( cg , &r , image ) ;
-        CGImageRelease( image ) ;
            
     }
     else
     {
+    /*
+        CGContextRef cg = dynamic_cast<wxMacCGContext*>(source->GetGraphicContext())->GetNativeContext() ;
+        void *data = CGBitmapContextGetData( cg ) ;
+    */
         return FALSE ; // wxFAIL_MSG( wxT("Blitting is only supported from bitmap contexts") ) ;
     }
     return TRUE;
@@ -1695,35 +1725,38 @@ void wxDC::MacInstallFont() const
         m_macATSUIStyle = NULL ;
     }
 
-    OSStatus status = noErr ;
-    status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ;
-    wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
-
-    Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ;
-    RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ;
-    ATSUAttributeTag atsuTags[] =
-    {
-            kATSUSizeTag ,
-            kATSUColorTag ,
-    } ;
-    ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+    if ( m_font.Ok() )
     {
-            sizeof( Fixed ) ,
-            sizeof( RGBColor ) ,
-    } ;
-//    Boolean kTrue = true ;
-//    Boolean kFalse = false ;
+        OSStatus status = noErr ;
+        status = ATSUCreateAndCopyStyle( (ATSUStyle) m_font.MacGetATSUStyle() , (ATSUStyle*) &m_macATSUIStyle ) ;
+        wxASSERT_MSG( status == noErr , wxT("couldn't set create ATSU style") ) ;
 
-//    ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
-    ATSUAttributeValuePtr    atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
-    {
-            &atsuSize ,
-            &atsuColor ,
-    } ;
-    status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
-        atsuTags, atsuSizes, atsuValues);
+        Fixed atsuSize = IntToFixed( int(m_scaleY * m_font.MacGetFontSize()) ) ;
+        RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColour.GetPixel() ) ;
+        ATSUAttributeTag atsuTags[] =
+        {
+                kATSUSizeTag ,
+                kATSUColorTag ,
+        } ;
+        ByteCount atsuSizes[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+        {
+                sizeof( Fixed ) ,
+                sizeof( RGBColor ) ,
+        } ;
+    //    Boolean kTrue = true ;
+    //    Boolean kFalse = false ;
 
-    wxASSERT_MSG( status == noErr , wxT("couldn't Modify ATSU style") ) ;
+    //    ATSUVerticalCharacterType kHorizontal = kATSUStronglyHorizontal;
+        ATSUAttributeValuePtr    atsuValues[sizeof(atsuTags)/sizeof(ATSUAttributeTag)] =
+        {
+                &atsuSize ,
+                &atsuColor ,
+        } ;
+        status = ::ATSUSetAttributes((ATSUStyle)m_macATSUIStyle, sizeof(atsuTags)/sizeof(ATSUAttributeTag) ,
+            atsuTags, atsuSizes, atsuValues);
+
+        wxASSERT_MSG( status == noErr , wxT("couldn't Modify ATSU style") ) ;
+    }
 }
 
 // ---------------------------------------------------------------------------
index 1164a856d4c62cf7cb6c324d95d1134c30baf243..ea1d197c0d973ce3dbc6924e27723af8b339cb2f 100644 (file)
@@ -230,6 +230,15 @@ wxClientDC::wxClientDC(wxWindow *window)
 
 wxClientDC::~wxClientDC()
 {
+#if wxMAC_USE_CORE_GRAPHICS
+/*
+    if ( m_window->MacGetCGContextRef() == 0)
+    {
+        CGContextRef cgContext = dynamic_cast<wxMacCGContext*>(m_graphicContext)->GetNativeContext() ;
+        CGContextFlush( cgContext ) ;
+    }
+*/
+#endif
 }
 
 void wxClientDC::DoGetSize(int *width, int *height) const