#include "wx/clipbrd.h"
#include "wx/mac/uma.h"
#include "wx/graphics.h"
+#include "wx/mac/carbon/metafile.h"
#include <stdio.h>
#include <string.h>
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; }
if ( !filename.empty() )
{
- wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename)));
+ wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(filename)));
CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
m_pdfDoc.reset(CGPDFDocumentCreateWithURL(url));
{
}
-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
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 );
}
// 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"));
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") );
(*height) = sz.y;
}
-wxMetaFile *wxMetaFileDC::Close()
+wxMetaFile *wxMetafileDCImpl::Close()
{
delete m_graphicContext;
m_graphicContext = NULL;