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
This commit is contained in:
Vadim Zeitlin 2013-10-14 15:07:57 +00:00
parent a33511aeeb
commit 13a119cca8
3 changed files with 36 additions and 12 deletions

View File

@ -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

View File

@ -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());

View File

@ -18,6 +18,7 @@
wxTestableFrame::wxTestableFrame() : wxFrame(NULL, wxID_ANY, "Test Frame")
{
Move(2000, 200);
}
void wxTestableFrame::OnEvent(wxEvent& evt)