]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/enhmeta.cpp
another file which needs wx/thread.h inclusion now
[wxWidgets.git] / src / msw / enhmeta.cpp
index 037b749003b3458ea9797daf81f111754848d052..fe4d384aca7b243f12cdbe0b96c39fc73bf3d7d2 100644 (file)
@@ -1,5 +1,5 @@
 ///////////////////////////////////////////////////////////////////////////////
-// Name:        msw/enhmeta.cpp
+// Name:        src/msw/enhmeta.cpp
 // Purpose:     implementation of wxEnhMetaFileXXX classes
 // Author:      Vadim Zeitlin
 // Modified by:
@@ -32,6 +32,9 @@
     #include "wx/intl.h"
 #endif //WX_PRECOMP
 
+#include "wx/dc.h"
+#include "wx/msw/dc.h"
+
 #include "wx/metafile.h"
 #include "wx/clipbrd.h"
 
@@ -42,7 +45,6 @@
 // ----------------------------------------------------------------------------
 
 IMPLEMENT_DYNAMIC_CLASS(wxEnhMetaFile, wxObject)
-IMPLEMENT_ABSTRACT_CLASS(wxEnhMetaFileDC, wxDC)
 
 // ----------------------------------------------------------------------------
 // macros
@@ -57,7 +59,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxEnhMetaFileDC, wxDC)
 
 // 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
@@ -75,7 +77,7 @@ void wxEnhMetaFile::Init()
     }
     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());
@@ -136,7 +138,12 @@ bool wxEnhMetaFile::Play(wxDC *dc, wxRect *rectBound)
         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"));
 
@@ -190,11 +197,49 @@ bool wxEnhMetaFile::SetClipboard(int WXUNUSED(width), int WXUNUSED(height))
 // 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 )
@@ -215,17 +260,26 @@ wxEnhMetaFileDC::wxEnhMetaFileDC(const wxString& filename,
         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 )
@@ -240,7 +294,7 @@ wxEnhMetaFile *wxEnhMetaFileDC::Close()
     return mf;
 }
 
-wxEnhMetaFileDC::~wxEnhMetaFileDC()
+wxEnhMetaFileDCImpl::~wxEnhMetaFileDCImpl()
 {
     // avoid freeing it in the base class dtor
     m_hDC = 0;