#include "wx/intl.h"
#endif //WX_PRECOMP
+#include "wx/dc.h"
+#include "wx/msw/dc.h"
+
#include "wx/metafile.h"
#include "wx/clipbrd.h"
// ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS(wxEnhMetaFile, wxObject)
-IMPLEMENT_ABSTRACT_CLASS(wxEnhMetaFileDC, wxDC)
// ----------------------------------------------------------------------------
// macros
// we must pass NULL if the string is empty to metafile functions
static inline const wxChar *GetMetaFileName(const wxString& fn)
- { return !fn ? (wxChar *)NULL : fn.c_str(); }
+ { return !fn ? (const wxChar *)NULL : (const wxChar*)fn.wx_str(); }
// ============================================================================
// implementation
// wxEnhMetaFile
// ----------------------------------------------------------------------------
+wxGDIRefData *wxEnhMetaFile::CreateGDIRefData() const
+{
+ wxFAIL_MSG( _T("must be implemented if used") );
+
+ return NULL;
+}
+
+wxGDIRefData *
+wxEnhMetaFile::CloneGDIRefData(const wxGDIRefData *WXUNUSED(data)) const
+{
+ wxFAIL_MSG( _T("must be implemented if used") );
+
+ return NULL;
+}
+
void wxEnhMetaFile::Init()
{
if ( m_filename.empty() )
}
else // have valid file name, load metafile from it
{
- m_hMF = (WXHANDLE)::GetEnhMetaFile(m_filename);
+ m_hMF = (WXHANDLE)::GetEnhMetaFile(m_filename.fn_str());
if ( !m_hMF )
wxLogSysError(_("Failed to load metafile from file \"%s\"."),
m_filename.c_str());
rect.bottom = size.y;
}
- if ( !::PlayEnhMetaFile(GetHdcOf(*dc), GetEMF(), &rect) )
+ wxDCImpl *impl = dc->GetImpl();
+ wxMSWDCImpl *msw_impl = wxDynamicCast( impl, wxMSWDCImpl );
+ if (!msw_impl)
+ return false;
+
+ if ( !::PlayEnhMetaFile(GetHdcOf(*msw_impl), GetEMF(), &rect) )
{
wxLogLastError(_T("PlayEnhMetaFile"));
}
// ----------------------------------------------------------------------------
-// wxEnhMetaFileDC
+// wxEnhMetaFileDCImpl
// ----------------------------------------------------------------------------
-wxEnhMetaFileDC::wxEnhMetaFileDC(const wxString& filename,
+class wxEnhMetaFileDCImpl : public wxMSWDCImpl
+{
+public:
+ wxEnhMetaFileDCImpl( wxEnhMetaFileDC *owner,
+ const wxString& filename, int width, int height,
+ const wxString& description );
+ virtual ~wxEnhMetaFileDCImpl();
+
+ // obtain a pointer to the new metafile (caller should delete it)
+ wxEnhMetaFile *Close();
+
+protected:
+ virtual void DoGetSize(int *width, int *height) const;
+
+private:
+ // size passed to ctor and returned by DoGetSize()
+ int m_width,
+ m_height;
+};
+
+
+wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
+ const wxString& filename,
int width, int height,
- const wxString& description)
+ const wxString& description )
+ : wxMSWDCImpl( owner )
{
m_width = width;
m_height = height;
ScreenHDC hdcRef;
m_hDC = (WXHDC)::CreateEnhMetaFile(hdcRef, GetMetaFileName(filename),
- pRect, description);
+ pRect, description.wx_str());
if ( !m_hDC )
{
wxLogLastError(_T("CreateEnhMetaFile"));
}
}
-void wxEnhMetaFileDC::DoGetSize(int *width, int *height) const
+void wxEnhMetaFileDCImpl::DoGetSize(int *width, int *height) const
{
if ( width )
*width = m_width;
*height = m_height;
}
-wxEnhMetaFile *wxEnhMetaFileDC::Close()
+wxEnhMetaFile *wxEnhMetaFileDCImpl::Close()
{
- wxCHECK_MSG( Ok(), NULL, _T("invalid wxEnhMetaFileDC") );
+ wxCHECK_MSG( IsOk(), NULL, _T("invalid wxEnhMetaFileDC") );
HENHMETAFILE hMF = ::CloseEnhMetaFile(GetHdc());
if ( !hMF )
return mf;
}
-wxEnhMetaFileDC::~wxEnhMetaFileDC()
+wxEnhMetaFileDCImpl::~wxEnhMetaFileDCImpl()
{
// avoid freeing it in the base class dtor
m_hDC = 0;
}
+// ----------------------------------------------------------------------------
+// wxEnhMetaFileDC
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxEnhMetaFileDC, wxDC)
+
+wxEnhMetaFileDC::wxEnhMetaFileDC(const wxString& filename,
+ int width, int height,
+ const wxString& description)
+ : wxDC(new wxEnhMetaFileDCImpl(this,
+ filename,
+ width, height,
+ description))
+{
+}
+
+wxEnhMetaFile *wxEnhMetaFileDC::Close()
+{
+ wxEnhMetaFileDCImpl * const
+ impl = wx_static_cast(wxEnhMetaFileDCImpl *, GetImpl());
+ wxCHECK_MSG( impl, NULL, _T("no wxEnhMetaFileDC implementation") );
+
+ return impl->Close();
+}
+
#if wxUSE_DRAG_AND_DROP
// ----------------------------------------------------------------------------