///////////////////////////////////////////////////////////////////////////////
-// Name: msw/ole/dataobj.cpp
+// Name: src/msw/ole/dataobj.cpp
// Purpose: implementation of wx[I]DataObject class
// Author: Vadim Zeitlin
// Modified by:
#define GetTymedName(tymed) wxEmptyString
#endif // wxDEBUG_LEVEL/!wxDEBUG_LEVEL
+wxDataFormat HtmlFormatFixup(wxDataFormat format)
+{
+ // Since the HTML format is dynamically registered, the wxDF_HTML
+ // 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)))
+ {
+ if (s_szBuf == wxString("HTML Format"))
+ format = wxDF_HTML;
+ }
+ return format;
+}
+
// ----------------------------------------------------------------------------
// wxIEnumFORMATETC interface implementation
// ----------------------------------------------------------------------------
void wxDataFormat::SetId(const wxString& format)
{
- m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.wx_str());
+ m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format.t_str());
if ( !m_format )
{
wxLogError(_("Couldn't register clipboard format '%s'."), format);
m_nCount = nCount;
m_formats = new CLIPFORMAT[nCount];
for ( ULONG n = 0; n < nCount; n++ ) {
- m_formats[n] = formats[n].GetFormatId();
+ if (formats[n].GetFormatId() != wxDF_HTML)
+ m_formats[n] = formats[n].GetFormatId();
+ else
+ m_formats[n] = ::RegisterClipboardFormat(wxT("HTML Format"));
}
}
// for the bitmaps and metafiles we use the handles instead of global memory
// to pass the data
wxDataFormat format = (wxDataFormat::NativeFormat)pformatetcIn->cfFormat;
+ format = HtmlFormatFixup(format);
switch ( format )
{
{
wxDataFormat format = pformatetc->cfFormat;
+ format = HtmlFormatFixup(format);
+
// this is quite weird, but for file drag and drop, explorer
// calls our SetData() with the formats we do *not* support!
//
size_t size;
switch ( format )
{
+ case wxDF_HTML:
case CF_TEXT:
case CF_OEMTEXT:
size = strlen((const char *)pBuf);
break;
#if !(defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
case CF_UNICODETEXT:
-#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
- || ( defined(__MWERKS__) && defined(__WXMSW__) )
+#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) )
size = std::wcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
#else
size = wxWcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
// and now check the type of data requested
wxDataFormat format = pformatetc->cfFormat;
+ format = HtmlFormatFixup(format);
+
if ( m_pDataObject->IsSupportedFormat(format) ) {
wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::QueryGetData: %s ok"),
wxGetFormatName(format));
wxBitmap bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes);
bitmap.SetHBITMAP((WXHBITMAP)hbmp);
- if ( !bitmap.Ok() ) {
+ if ( !bitmap.IsOk() ) {
wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
return false;
bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format,
void *pBuf) const
{
- wxASSERT_MSG( m_bitmap.Ok(), wxT("copying invalid bitmap") );
+ wxASSERT_MSG( m_bitmap.IsOk(), wxT("copying invalid bitmap") );
HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP();
if ( format.GetFormatId() == CF_DIB )
m_bitmap.SetHBITMAP((WXHBITMAP)hbmp);
- wxASSERT_MSG( m_bitmap.Ok(), wxT("pasting invalid bitmap") );
+ wxASSERT_MSG( m_bitmap.IsOk(), wxT("pasting invalid bitmap") );
return true;
}
#endif // wxUSE_UNICODE_MSLU
{
len = m_filenames[i].length();
- memcpy(pbuf, m_filenames[i].wx_str(), len*sizeOfChar);
+ memcpy(pbuf, m_filenames[i].t_str(), len*sizeOfChar);
}
pbuf += len*sizeOfChar;
return buffer;
}
-#if wxUSE_UNICODE
- virtual bool GetDataHere( void* buffer ) const
- {
- // CFSTR_SHELLURL is _always_ ANSI!
- wxCharBuffer char_buffer( GetDataSize() );
- wxCustomDataObject::GetDataHere( (void*)char_buffer.data() );
- wxString unicode_buffer( char_buffer, wxConvLibc );
- memcpy( buffer, unicode_buffer.c_str(),
- ( unicode_buffer.length() + 1 ) * sizeof(wxChar) );
-
- return true;
- }
- virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
- void *buf) const
- { return GetDataHere(buf); }
-#endif
-
wxDECLARE_NO_COPY_CLASS(CFSTR_SHELLURLDataObject);
};
wxString url;
wxCHECK_MSG( m_dataObjectLast, url, wxT("no data in wxURLDataObject") );
- size_t len = m_dataObjectLast->GetDataSize();
+ if ( m_dataObjectLast->GetPreferredFormat() == CFSTR_SHELLURL )
+ {
+ const size_t len = m_dataObjectLast->GetDataSize();
+ if ( !len )
+ return wxString();
- m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
+ // CFSTR_SHELLURL is always ANSI so we need to convert it from it in
+ // Unicode build
+#if wxUSE_UNICODE
+ wxCharBuffer buf(len);
+
+ if ( m_dataObjectLast->GetDataHere(buf.data()) )
+ url = buf;
+#else // !wxUSE_UNICODE
+ // in ANSI build no conversion is necessary
+ m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
+#endif // wxUSE_UNICODE/!wxUSE_UNICODE
+ }
+ else // must be wxTextDataObject
+ {
+ url = static_cast<wxTextDataObject *>(m_dataObjectLast)->GetText();
+ }
return url;
}