]> git.saurik.com Git - wxWidgets.git/commitdiff
add ability to create wxEnhMetaFileDC based on a reference DC
authorVáclav Slavík <vslavik@fastmail.fm>
Sun, 31 May 2009 19:11:15 +0000 (19:11 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sun, 31 May 2009 19:11:15 +0000 (19:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@60843 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/enhmeta.h
include/wx/msw/private.h
src/msw/enhmeta.cpp
src/msw/utilsgui.cpp

index 950b061e817b16353117183bbd981a2cc27ee723..e4cd9b3284c71aa89a5867953b1c2ea2a6f59aa0 100644 (file)
@@ -87,6 +87,13 @@ public:
                     int width = 0, int height = 0,
                     const wxString& description = wxEmptyString);
 
+    // as above, but takes reference DC as first argument to take resolution,
+    // size, font metrics etc. from
+    wxEnhMetaFileDC(const wxDC& referenceDC,
+                    const wxString& filename = wxEmptyString,
+                    int width = 0, int height = 0,
+                    const wxString& description = wxEmptyString);
+
     // obtain a pointer to the new metafile (caller should delete it)
     wxEnhMetaFile *Close();
 
index a840110a976c907f44444a3b5da995453be37229..6f8f86e5a2b45994e927168c8c56d973ffc54f19 100644 (file)
@@ -289,7 +289,9 @@ inline void wxCopyRectToRECT(const wxRect& rect, RECT& rc)
 // translations between HIMETRIC units (which OLE likes) and pixels (which are
 // liked by all the others) - implemented in msw/utilsexc.cpp
 extern void HIMETRICToPixel(LONG *x, LONG *y);
+extern void HIMETRICToPixel(LONG *x, LONG *y, HDC hdcRef);
 extern void PixelToHIMETRIC(LONG *x, LONG *y);
+extern void PixelToHIMETRIC(LONG *x, LONG *y, HDC hdcRef);
 
 // Windows convention of the mask is opposed to the wxWidgets one, so we need
 // to invert the mask each time we pass one/get one to/from Windows
index 82d4adf106c93c072ef8a265ed75a63c4e21422e..fd2e73ac75e16e09d4a650250b4aad0a34bd31b3 100644 (file)
@@ -218,6 +218,10 @@ public:
     wxEnhMetaFileDCImpl( wxEnhMetaFileDC *owner,
                          const wxString& filename, int width, int height,
                          const wxString& description );
+    wxEnhMetaFileDCImpl( wxEnhMetaFileDC *owner,
+                         const wxDC& referenceDC,
+                         const wxString& filename, int width, int height,
+                         const wxString& description );
     virtual ~wxEnhMetaFileDCImpl();
 
     // obtain a pointer to the new metafile (caller should delete it)
@@ -227,6 +231,10 @@ protected:
     virtual void DoGetSize(int *width, int *height) const;
 
 private:
+    void Create(HDC hdcRef,
+                const wxString& filename, int width, int height,
+                const wxString& description);
+
     // size passed to ctor and returned by DoGetSize()
     int m_width,
         m_height;
@@ -238,6 +246,24 @@ wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
                                  int width, int height,
                                  const wxString& description )
                    : wxMSWDCImpl( owner )
+{
+    Create(ScreenHDC(), filename, width, height, description);
+}
+
+wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
+                                 const wxDC& referenceDC,
+                                 const wxString& filename,
+                                 int width, int height,
+                                 const wxString& description )
+                   : wxMSWDCImpl( owner )
+{
+    Create(GetHdcOf(referenceDC), filename, width, height, description);
+}
+
+void wxEnhMetaFileDCImpl::Create(HDC hdcRef,
+                                 const wxString& filename,
+                                 int width, int height,
+                                 const wxString& description)
 {
     m_width = width;
     m_height = height;
@@ -252,7 +278,7 @@ wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
         rect.bottom = height;
 
         // CreateEnhMetaFile() wants them in HIMETRIC
-        PixelToHIMETRIC(&rect.right, &rect.bottom);
+        PixelToHIMETRIC(&rect.right, &rect.bottom, hdcRef);
 
         pRect = &rect;
     }
@@ -262,7 +288,6 @@ wxEnhMetaFileDCImpl::wxEnhMetaFileDCImpl( wxEnhMetaFileDC* owner,
         pRect = (LPRECT)NULL;
     }
 
-    ScreenHDC hdcRef;
     m_hDC = (WXHDC)::CreateEnhMetaFile(hdcRef, GetMetaFileName(filename),
                                        pRect, description.wx_str());
     if ( !m_hDC )
@@ -318,6 +343,18 @@ wxEnhMetaFileDC::wxEnhMetaFileDC(const wxString& filename,
 {
 }
 
+wxEnhMetaFileDC::wxEnhMetaFileDC(const wxDC& referenceDC,
+                                 const wxString& filename,
+                                 int width, int height,
+                                 const wxString& description)
+               : wxDC(new wxEnhMetaFileDCImpl(this,
+                                              referenceDC,
+                                              filename,
+                                              width, height,
+                                              description))
+{
+}
+
 wxEnhMetaFile *wxEnhMetaFileDC::Close()
 {
     wxEnhMetaFileDCImpl * const
index e74c0326a74644173cf69c0eb80c92d47923dbe7..1ee21a202644e9a79a18a34320c875c3f6ba6f15 100644 (file)
@@ -304,10 +304,8 @@ int WXDLLEXPORT wxGetWindowId(WXHWND hWnd)
 // Metafile helpers
 // ----------------------------------------------------------------------------
 
-extern void PixelToHIMETRIC(LONG *x, LONG *y)
+void PixelToHIMETRIC(LONG *x, LONG *y, HDC hdcRef)
 {
-    ScreenHDC hdcRef;
-
     int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
         iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
         iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
@@ -319,10 +317,8 @@ extern void PixelToHIMETRIC(LONG *x, LONG *y)
     *y /= iHeightPels;
 }
 
-extern void HIMETRICToPixel(LONG *x, LONG *y)
+void HIMETRICToPixel(LONG *x, LONG *y, HDC hdcRef)
 {
-    ScreenHDC hdcRef;
-
     int iWidthMM = GetDeviceCaps(hdcRef, HORZSIZE),
         iHeightMM = GetDeviceCaps(hdcRef, VERTSIZE),
         iWidthPels = GetDeviceCaps(hdcRef, HORZRES),
@@ -334,6 +330,16 @@ extern void HIMETRICToPixel(LONG *x, LONG *y)
     *y /= (iHeightMM * 100);
 }
 
+void HIMETRICToPixel(LONG *x, LONG *y)
+{
+    HIMETRICToPixel(x, y, ScreenHDC());
+}
+
+void PixelToHIMETRIC(LONG *x, LONG *y)
+{
+    PixelToHIMETRIC(x, y, ScreenHDC());
+}
+
 void wxDrawLine(HDC hdc, int x1, int y1, int x2, int y2)
 {
 #ifdef __WXWINCE__