]> git.saurik.com Git - wxWidgets.git/commitdiff
new graphics context implementation
authorStefan Csomor <csomor@advancedconcepts.ch>
Fri, 20 Oct 2006 11:46:28 +0000 (11:46 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Fri, 20 Oct 2006 11:46:28 +0000 (11:46 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/carbon/dcmemory.cpp
src/mac/carbon/dcprint.cpp
src/mac/carbon/dcscreen.cpp
src/mac/carbon/metafile.cpp

index ee44e18330239ec7a8548e5dfa571feffe1a7769..393e0a23c223b2e270165bf465fe8117e676e393 100644 (file)
@@ -52,7 +52,7 @@ wxMemoryDC::~wxMemoryDC()
     {
 #if wxMAC_USE_CORE_GRAPHICS
         m_selected.EndRawAccess() ;
-        CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
+        CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
         delete m_graphicContext ;
         m_graphicContext = NULL ;
         CGContextRelease( bmCtx ) ;
@@ -68,7 +68,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
     {
 #if wxMAC_USE_CORE_GRAPHICS
         m_selected.EndRawAccess() ;
-        CGContextRef bmCtx = ((wxMacCGContext*)(m_graphicContext))->GetNativeContext() ;
+        CGContextRef bmCtx = (CGContextRef) m_graphicContext->GetNativeContext() ;
         delete m_graphicContext ;
         m_graphicContext = NULL ;
         CGContextRelease( bmCtx ) ;
@@ -89,6 +89,8 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
         int bytesPerPixel = 4 ;
         int w = bitmap.GetWidth() ;
         int h = bitmap.GetHeight() ;
+               m_width = w;
+               m_height = h;
 
         // TODO: should this be kCGImageAlphaPremultiplied[First,Last] ?
         CGImageAlphaInfo a = kCGImageAlphaNoneSkipFirst ;
@@ -105,7 +107,7 @@ void wxMemoryDC::SelectObject( const wxBitmap& bitmap )
             CGContextTranslateCTM( bmCtx , 0 ,  m_selected.GetHeight() ) ;
             CGContextScaleCTM( bmCtx , 1 , -1 ) ;
 
-            m_graphicContext = new wxMacCGContext( bmCtx ) ;
+                       SetGraphicsContext( wxGraphicsContext::CreateFromNative( bmCtx ) );
             m_graphicContext->SetPen( m_pen ) ;
             m_graphicContext->SetBrush( m_brush ) ;
             m_graphicContext->SetFont( m_font ) ;
index ce17739428f1357165e7c18c6e6eb3d312542faa..f1d1a2f8806b573009871aa0d3e764dea14ab955 100644 (file)
@@ -94,8 +94,8 @@ wxMacCarbonPrinterDC::wxMacCarbonPrinterDC( wxPrintData* data )
     PMPrinterGetOutputResolution( printer, native->m_macPrintSettings, &res) ;
 #else
     m_err = PMGetResolution((PMPageFormat) (native->m_macPageFormat), &res);
-    m_ppi = wxSize(int(res.hRes), int(res.vRes));
 #endif
+    m_ppi = wxSize(int(res.hRes), int(res.vRes));
 }
 
 wxMacCarbonPrinterDC::~wxMacCarbonPrinterDC()
@@ -286,8 +286,10 @@ wxPrinterDC::wxPrinterDC(const wxPrintData& printdata)
             m_mm_to_pix_y = mm2inches * sz.y;        
         }
 #if wxMAC_USE_CORE_GRAPHICS
+/*
         // the cgContext will only be handed over page by page
         m_graphicContext = new wxMacCGContext() ;
+               */
 #endif
     }
 }
@@ -300,8 +302,10 @@ wxSize wxPrinterDC::GetPPI() const
 wxPrinterDC::~wxPrinterDC(void)
 {
 #if wxMAC_USE_CORE_GRAPHICS
+/*
     // this context was borrowed
     ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( NULL ) ;
+       */
 #endif
     delete m_nativePrinterDC ;
 }
@@ -309,7 +313,7 @@ wxPrinterDC::~wxPrinterDC(void)
 #if wxMAC_USE_CORE_GRAPHICS
 void wxPrinterDC::MacSetCGContext( void * cg )
 {
-    ((wxMacCGContext*)(m_graphicContext))->SetNativeContext( (CGContextRef) cg ) ;
+    SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
     m_graphicContext->SetPen( m_pen ) ;
     m_graphicContext->SetBrush( m_brush ) ;
 }
index e8ccf9807ac1318b3255d5c346fde618b776477e..10f209b4b0b68cd46375c301eb57fffcbe5ea69f 100644 (file)
@@ -20,7 +20,28 @@ IMPLEMENT_DYNAMIC_CLASS(wxScreenDC, wxWindowDC)
 // Create a DC representing the whole screen
 wxScreenDC::wxScreenDC()
 {
-#ifndef __LP64__
+#if wxMAC_USE_CORE_GRAPHICS
+       CGDirectDisplayID display = CGMainDisplayID();
+       m_displayId = (UInt32) display;
+       CGError err = CGDisplayCaptureWithOptions(display,kCGCaptureNoFill);
+       wxASSERT( err == kCGErrorSuccess ); 
+       CGContextRef cg = CGDisplayGetDrawingContext(display);
+       CGRect bounds ;
+    bounds = CGDisplayBounds(display);
+       /*
+    m_macLocalOrigin.x = 0;
+    m_macLocalOrigin.y = 0;
+       */ // TODO
+    SInt16 height;
+    GetThemeMenuBarHeight( &height );
+    m_minY = height;
+       m_minX = 0;
+    m_maxX = bounds.size.width;
+    m_maxY = bounds.size.height - height;
+    SetGraphicsContext( wxGraphicsContext::CreateFromNative( cg ) );
+       m_width = bounds.size.width;
+       m_height = bounds.size.height - height;
+#else
     m_macPort = CreateNewPort() ;
     GrafPtr port ;
     GetPort( &port ) ;
@@ -30,9 +51,7 @@ wxScreenDC::wxScreenDC()
     SetPort( port ) ;
     m_macLocalOrigin.x = -pt.h ;
     m_macLocalOrigin.y = -pt.v ;
-#if wxMAC_USE_CORE_GRAPHICS
-    m_macLocalOriginInPort = m_macLocalOrigin ;
-#endif
+
     BitMap screenBits;
     GetQDGlobalsScreenBits( &screenBits );
     m_minX = screenBits.bounds.left ;
@@ -44,25 +63,21 @@ wxScreenDC::wxScreenDC()
     m_maxX = screenBits.bounds.right  ;
     m_maxY = screenBits.bounds.bottom ;
 
-#if wxMAC_USE_CORE_GRAPHICS
-    m_graphicContext = new wxMacCGContext( port ) ;
-#else
     MacSetRectRgn( (RgnHandle) m_macBoundaryClipRgn , m_minX , m_minY , m_maxX , m_maxY ) ;
     OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
     CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
 #endif
-    m_ok = true ;
-#endif
+       m_ok = true ;
 }
 
 wxScreenDC::~wxScreenDC()
 {
 #if wxMAC_USE_CORE_GRAPHICS
-    delete m_graphicContext ;
-    m_graphicContext = NULL ;
-#endif
-
-#ifndef __LP64__
+    delete m_graphicContext;
+    m_graphicContext = NULL;
+       CGDirectDisplayID display = (CGDirectDisplayID) m_displayId;
+       CGDisplayRelease( display );
+#else
     if ( m_macPort )
         DisposePort( (CGrafPtr) m_macPort ) ;
 #endif
index 00a3fdc09a1862f019a1896f2dba112be42f33d9..1ed5081a6b1eeb162f1468df2e2317e1a82ea95d 100644 (file)
@@ -166,7 +166,7 @@ bool wxMetaFile::Play(wxDC *dc)
 #if wxMAC_USE_CORE_GRAPHICS
 #ifndef __LP64__
         QDPictRef cgPictRef = M_METAFILEDATA->m_qdPictRef;
-        CGContextRef cg = ((wxMacCGContext*)(dc->GetGraphicContext()))->GetNativeContext();
+        CGContextRef cg = (CGContextRef) dc->GetGraphicContext()->GetNativeContext();
         CGRect bounds = QDPictGetBounds( cgPictRef );
 
         CGContextSaveGState( cg );