+
+#define M_METAFILEREFDATA( a ) ((wxMetafileRefData*)(a).GetRefData())
+
+class wxMetafileRefData: public wxGDIRefData
+{
+public:
+#if wxMAC_USE_CORE_GRAPHICS
+ // creates a metafile from memory, assumes ownership
+ wxMetafileRefData(CFDataRef data);
+#else
+ // creates a metafile from memory, assumes ownership
+ wxMetafileRefData(PicHandle data);
+#endif
+ // 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();
+
+ void Init();
+
+ int GetWidth() const { return m_width; }
+ int GetHeight() const { return m_height; }
+
+#if wxMAC_USE_CORE_GRAPHICS
+ CGPDFDocumentRef GetPDFDocument() const { return m_pdfDoc; }
+ void UpdateDocumentFromData() ;
+
+ const wxCFDataRef& GetData() const { return m_data; }
+ CGContextRef GetContext() const { return m_context; }
+#else
+ PicHandle GetHandle() const { return m_metafile; }
+#endif
+ // ends the recording
+ void Close();
+private:
+#if wxMAC_USE_CORE_GRAPHICS
+ wxCFDataRef m_data;
+ wxCFRef<CGPDFDocumentRef> m_pdfDoc;
+ CGContextRef m_context;
+#else
+ PicHandle m_metafile;
+#endif
+ int m_width ;
+ int m_height ;
+};
+
+#if !wxMAC_USE_CORE_GRAPHICS
+wxMetafileRefData::wxMetafileRefData(PicHandle pict)
+{
+ Init();
+ m_metafile = pict;
+
+ Rect r;
+ wxMacGetPictureBounds( m_metafile, &r );
+ m_width = r.right - r.left;
+ m_height = r.bottom - r.top;
+}
+#else
+wxMetafileRefData::wxMetafileRefData(CFDataRef data) :
+ m_data(data)
+{
+ Init();
+ UpdateDocumentFromData();
+}
+#endif
+
+wxMetafileRefData::wxMetafileRefData( const wxString& filename )
+{
+ Init();
+#if wxMAC_USE_CORE_GRAPHICS
+ if ( !filename.empty() )
+ {
+ wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxMacCFStringHolder(filename)));
+ CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
+ wxCFRef<CFURLRef> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
+ m_pdfDoc.reset(CGPDFDocumentCreateWithURL(url));
+ }
+#else
+ wxASSERT_MSG( filename.empty(), wxT("no file-based metafile support yet") );
+ m_metafile = NULL;