From 61e323ad37b3571140f9d92e039ffe6f3f3c81ae Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 11 Mar 2014 16:04:22 +0000 Subject: [PATCH] Add wxEnhMetaFile::Detach(). Allow getting the handle from this class, this is useful if it needs to be passed to some other library, for example. Closes #15706. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76117 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/msw/enhmeta.h | 10 +++++++++- src/msw/enhmeta.cpp | 7 ++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f4e8151c9e..86e1ed27a8 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -51,6 +51,7 @@ wxMSW: - Fix loading of bitmap with non-pre-multiplied alpha (Artur Wieczorek). - Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek). - Fix stretchable spacers in vertical toolbars (Artur Wieczorek). +- Add wxEnhMetaFile::Detach() (Luca Bacci). wxOSX/Cocoa: diff --git a/include/wx/msw/enhmeta.h b/include/wx/msw/enhmeta.h index 3951bd7f5a..6ec8731cdf 100644 --- a/include/wx/msw/enhmeta.h +++ b/include/wx/msw/enhmeta.h @@ -52,13 +52,21 @@ public: // this method bool SetClipboard(int width = 0, int height = 0); + // Detach the HENHMETAFILE from this object, i.e. don't delete the handle + // in the dtor -- the caller is now responsible for doing this, e.g. using + // Free() method below. + WXHANDLE Detach() { WXHANDLE h = m_hMF; m_hMF = 0; return h; } + + // Destroy the given HENHMETAFILE object. + static void Free(WXHANDLE handle); + // implementation WXHANDLE GetHENHMETAFILE() const { return m_hMF; } void SetHENHMETAFILE(WXHANDLE hMF) { Free(); m_hMF = hMF; } protected: void Init(); - void Free(); + void Free() { Free(m_hMF); } void Assign(const wxEnhMetaFile& mf); // we don't use these functions (but probably should) but have to implement diff --git a/src/msw/enhmeta.cpp b/src/msw/enhmeta.cpp index f7c0f7abb0..a049016907 100644 --- a/src/msw/enhmeta.cpp +++ b/src/msw/enhmeta.cpp @@ -120,11 +120,12 @@ void wxEnhMetaFile::Assign(const wxEnhMetaFile& mf) } } -void wxEnhMetaFile::Free() +/* static */ +void wxEnhMetaFile::Free(WXHANDLE handle) { - if ( m_hMF ) + if ( handle ) { - if ( !::DeleteEnhMetaFile(GetEMF()) ) + if ( !::DeleteEnhMetaFile((HENHMETAFILE) handle) ) { wxLogLastError(wxT("DeleteEnhMetaFile")); }