-#if wxMAC_USE_CORE_GRAPHICS
- CGContextRef cg = (CGContextRef) dc->GetGraphicsContext()->GetNativeContext();
- CGPDFDocumentRef doc = M_METAFILEDATA->GetPDFDocument();
- CGPDFPageRef page = CGPDFDocumentGetPage( doc, 1 );
- wxMacCGContextStateSaver save(cg);
- CGContextDrawPDFPage( cg, page );
+ wxDCImpl *impl = dc->GetImpl();
+ wxGCDCImpl *gc_impl = wxDynamicCast(impl, wxGCDCImpl);
+ if (gc_impl)
+ {
+ CGContextRef cg = (CGContextRef) (gc_impl->GetGraphicsContext()->GetNativeContext());
+ CGPDFDocumentRef doc = M_METAFILEDATA->GetPDFDocument();
+ CGPDFPageRef page = CGPDFDocumentGetPage( doc, 1 );
+ wxMacCGContextStateSaver save(cg);
+ CGContextDrawPDFPage( cg, page );
+ }