///////////////////////////////////////////////////////////////////////////////
-// Name: msw/enhmeta.cpp
+// Name: src/msw/enhmeta.cpp
// Purpose: implementation of wxEnhMetaFileXXX classes
// Author: Vadim Zeitlin
// Modified by:
#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 = 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
// ----------------------------------------------------------------------------
+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;
+};
+
+
+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))
{
- ScreenHDC hdcRef;
+}
+
+
+wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
+ const wxString& filename,
+ int width, int height,
+ const wxString& description )
+ : wxMSWDCImpl( owner )
+{
+ m_width = width;
+ m_height = height;
+
RECT rect;
RECT *pRect;
if ( width && height )
pRect = (LPRECT)NULL;
}
+ ScreenHDC hdcRef;
m_hDC = (WXHDC)::CreateEnhMetaFile(hdcRef, GetMetaFileName(filename),
- pRect, description);
+ pRect, description.wx_str());
if ( !m_hDC )
{
wxLogLastError(_T("CreateEnhMetaFile"));
}
}
-wxEnhMetaFile *wxEnhMetaFileDC::Close()
+void wxEnhMetaFileDCImpl::DoGetSize(int *width, int *height) const
+{
+ if ( width )
+ *width = m_width;
+ if ( height )
+ *height = m_height;
+}
+
+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;