From 13a119cca8522fb9588de7cd2ffc6987196ea48d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 14 Oct 2013 15:07:57 +0000 Subject: [PATCH] Fix wxDataFormat comparison operators for wxDF_HTML under wxMSW. This format is special as it doesn't have a fixed value and is registered dynamically instead. So we need to call HtmlFormatFixup(), which checks if the given custom format is actually wxDF_HTML, before comparing formats to ensure that the real value assigned to this format compares correctly to the fixed wxDF_HTML value. Closes #15280. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74997 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/ole/dataform.h | 12 ++++-------- src/msw/ole/dataobj.cpp | 35 +++++++++++++++++++++++++++++++---- tests/testableframe.cpp | 1 + 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/include/wx/msw/ole/dataform.h b/include/wx/msw/ole/dataform.h index 8ad64542d2..26959099f7 100644 --- a/include/wx/msw/ole/dataform.h +++ b/include/wx/msw/ole/dataform.h @@ -39,14 +39,10 @@ public: // default copy ctor/assignment operators ok // comparison (must have both versions) - bool operator==(wxDataFormatId format) const - { return m_format == (NativeFormat)format; } - bool operator!=(wxDataFormatId format) const - { return m_format != (NativeFormat)format; } - bool operator==(const wxDataFormat& format) const - { return m_format == format.m_format; } - bool operator!=(const wxDataFormat& format) const - { return m_format != format.m_format; } + bool operator==(wxDataFormatId format) const; + bool operator!=(wxDataFormatId format) const; + bool operator==(const wxDataFormat& format) const; + bool operator!=(const wxDataFormat& format) const; // explicit and implicit conversions to NativeFormat which is one of // standard data types (implicit conversion is useful for preserving the diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 510aa9d574..2055a0a0de 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -77,12 +77,19 @@ wxDataFormat HtmlFormatFixup(wxDataFormat format) // format does not match the native constant in the way other formats do, // so for the format checks below to work, we must change the native // id to the wxDF_HTML constant. - wxChar s_szBuf[256]; - if (::GetClipboardFormatName(format, s_szBuf, WXSIZEOF(s_szBuf))) + // + // But skip this for the standard constants which are never going to match + // wxDF_HTML anyhow. + if ( !format.IsStandard() ) { - if (s_szBuf == wxString("HTML Format")) - format = wxDF_HTML; + wxChar szBuf[256]; + if ( ::GetClipboardFormatName(format, szBuf, WXSIZEOF(szBuf)) ) + { + if ( wxStrcmp(szBuf, wxT("HTML Format")) == 0 ) + format = wxDF_HTML; + } } + return format; } @@ -342,6 +349,26 @@ wxIDataObject::SaveSystemData(FORMATETC *pformatetc, // wxDataFormat // ---------------------------------------------------------------------------- +bool wxDataFormat::operator==(wxDataFormatId format) const +{ + return HtmlFormatFixup(*this).m_format == (NativeFormat)format; +} + +bool wxDataFormat::operator!=(wxDataFormatId format) const +{ + return !(*this == format); +} + +bool wxDataFormat::operator==(const wxDataFormat& format) const +{ + return HtmlFormatFixup(*this).m_format == HtmlFormatFixup(format).m_format; +} + +bool wxDataFormat::operator!=(const wxDataFormat& format) const +{ + return !(*this == format); +} + void wxDataFormat::SetId(const wxString& format) { m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.t_str()); diff --git a/tests/testableframe.cpp b/tests/testableframe.cpp index b260adaa45..e76c76f5d9 100644 --- a/tests/testableframe.cpp +++ b/tests/testableframe.cpp @@ -18,6 +18,7 @@ wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame") { + Move(2000, 200); } void wxTestableFrame::OnEvent(wxEvent& evt)