X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/315e9e5a66cdd61b517667de11907de7688af216..6cef0db28018fd2644ee4e38af715872e5242459:/src/mac/carbon/metafile.cpp?ds=sidebyside diff --git a/src/mac/carbon/metafile.cpp b/src/mac/carbon/metafile.cpp index 629eefff3c..73d5b77f9a 100644 --- a/src/mac/carbon/metafile.cpp +++ b/src/mac/carbon/metafile.cpp @@ -26,26 +26,36 @@ #include "wx/clipbrd.h" #include "wx/mac/uma.h" #include "wx/graphics.h" +#include "wx/mac/carbon/metafile.h" #include #include IMPLEMENT_DYNAMIC_CLASS(wxMetafile, wxObject) IMPLEMENT_ABSTRACT_CLASS(wxMetafileDC, wxDC) +IMPLEMENT_ABSTRACT_CLASS(wxMetafileDCImpl, wxGCDCImpl) #define M_METAFILEREFDATA( a ) ((wxMetafileRefData*)(a).GetRefData()) -class wxMetafileRefData: public wxGDIRefData +class wxMetafileRefData : public wxGDIRefData { public: + // default ctor needed for CreateGDIRefData(), must be initialized later + wxMetafileRefData() { Init(); } + // creates a metafile from memory, assumes ownership wxMetafileRefData(CFDataRef data); + // prepares a recording metafile wxMetafileRefData( int width, int height); + // prepares a metafile to be read from a file (if filename is not empty) wxMetafileRefData( const wxString& filename); + virtual ~wxMetafileRefData(); + virtual bool IsOk() const { return m_data != NULL; } + void Init(); int GetWidth() const { return m_width; } @@ -81,7 +91,7 @@ wxMetafileRefData::wxMetafileRefData( const wxString& filename ) if ( !filename.empty() ) { - wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename))); + wxCFRef cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(filename))); CFStringNormalize(cfMutableString,kCFStringNormalizationFormD); wxCFRef url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false)); m_pdfDoc.reset(CGPDFDocumentCreateWithURL(url)); @@ -100,7 +110,7 @@ wxMetafileRefData::wxMetafileRefData( int width, int height) CFMutableDataRef data = CFDataCreateMutable(kCFAllocatorDefault, 0); m_data.reset(data); - CGDataConsumerRef dataConsumer = UMACGDataConsumerCreateWithCFData(data); + CGDataConsumerRef dataConsumer = wxMacCGDataConsumerCreateWithCFData(data); m_context = CGPDFContextCreate( dataConsumer, (width != 0 && height != 0) ? &r : NULL , NULL ); CGDataConsumerRelease( dataConsumer ); if ( m_context ) @@ -140,7 +150,7 @@ void wxMetafileRefData::Close() void wxMetafileRefData::UpdateDocumentFromData() { - wxCFRef provider(UMACGDataProviderCreateWithCFData(m_data)); + wxCFRef provider(wxMacCGDataProviderCreateWithCFData(m_data)); m_pdfDoc.reset(CGPDFDocumentCreateWithProvider(provider)); if ( m_pdfDoc != NULL ) { @@ -160,9 +170,14 @@ wxMetaFile::~wxMetaFile() { } -bool wxMetaFile::IsOk() const +wxGDIRefData *wxMetaFile::CreateGDIRefData() const { - return (M_METAFILEDATA && (M_METAFILEDATA->GetData() != NULL)); + return new wxMetafileRefData; +} + +wxGDIRefData *wxMetaFile::CloneGDIRefData(const wxGDIRefData *data) const +{ + return new wxMetafileRefData(*wx_static_cast(const wxMetafileRefData *, data)); } WXHMETAFILE wxMetaFile::GetHMETAFILE() const @@ -201,6 +216,7 @@ void wxMetafile::SetHMETAFILE(WXHMETAFILE mf) m_refData = new wxMetafileRefData((CFDataRef)mf); } +#ifndef __LP64__ void wxMetafile::SetPICT(void* pictHandle) { UnRef(); @@ -208,7 +224,7 @@ void wxMetafile::SetPICT(void* pictHandle) Handle picHandle = (Handle) pictHandle; HLock(picHandle); CFDataRef data = CFDataCreateWithBytesNoCopy( kCFAllocatorDefault, (const UInt8*) *picHandle, GetHandleSize(picHandle), kCFAllocatorNull); - wxCFRef provider(UMACGDataProviderCreateWithCFData(data)); + wxCFRef provider(wxMacCGDataProviderCreateWithCFData(data)); QDPictRef pictRef = QDPictCreateWithProvider(provider); CGRect rect = QDPictGetBounds(pictRef); m_refData = new wxMetafileRefData(wx_static_cast(int, rect.size.width), @@ -218,21 +234,27 @@ void wxMetafile::SetPICT(void* pictHandle) QDPictRelease( pictRef ); ((wxMetafileRefData*) m_refData)->Close(); } +#endif bool wxMetaFile::Play(wxDC *dc) { if (!m_refData) return false; - if (!dc->Ok()) + if (!dc->IsOk()) return false; { - 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 ); + } // CGContextTranslateCTM( cg, 0, bounds.size.width ); // CGContextScaleCTM( cg, 1, -1 ); } @@ -258,10 +280,12 @@ wxSize wxMetaFile::GetSize() const // New constructor that takes origin and extent. If you use this, don't // give origin/extent arguments to wxMakeMetaFilePlaceable. -wxMetaFileDC::wxMetaFileDC( +wxMetafileDCImpl::wxMetafileDCImpl( + wxDC *owner, const wxString& filename, int width, int height, - const wxString& WXUNUSED(description) ) + const wxString& WXUNUSED(description) ) : + wxGCDCImpl( owner ) { wxASSERT_MSG( width != 0 || height != 0, wxT("no arbitration of metafile size supported") ); wxASSERT_MSG( filename.empty(), wxT("no file based metafile support yet")); @@ -277,11 +301,11 @@ wxMetaFileDC::wxMetaFileDC( SetMapMode( wxMM_TEXT ); } -wxMetaFileDC::~wxMetaFileDC() +wxMetafileDCImpl::~wxMetafileDCImpl() { } -void wxMetaFileDC::DoGetSize(int *width, int *height) const +void wxMetafileDCImpl::DoGetSize(int *width, int *height) const { wxCHECK_RET( m_metaFile, wxT("GetSize() doesn't work without a metafile") ); @@ -292,7 +316,7 @@ void wxMetaFileDC::DoGetSize(int *width, int *height) const (*height) = sz.y; } -wxMetaFile *wxMetaFileDC::Close() +wxMetaFile *wxMetafileDCImpl::Close() { delete m_graphicContext; m_graphicContext = NULL;