+class CFSTR_SHELLURLDataObject : public wxCustomDataObject
+{
+public:
+ CFSTR_SHELLURLDataObject() : wxCustomDataObject(CFSTR_SHELLURL) {}
+
+ virtual size_t GetBufferOffset( const wxDataFormat& WXUNUSED(format) )
+ {
+ return 0;
+ }
+
+ virtual const void* GetSizeFromBuffer( const void* buffer, size_t* size,
+ const wxDataFormat& WXUNUSED(format) )
+ {
+ // CFSTR_SHELLURL is _always_ ANSI text
+ *size = strlen( (const char*)buffer );
+
+ return buffer;
+ }
+
+ virtual void* SetSizeInBuffer( void* buffer, size_t WXUNUSED(size),
+ const wxDataFormat& WXUNUSED(format) )
+ {
+ 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);
+};
+
+
+
+wxURLDataObject::wxURLDataObject(const wxString& url)
+{
+ // we support CF_TEXT and CFSTR_SHELLURL formats which are basically the
+ // same but it seems that some browsers only provide one of them so we have
+ // to support both
+ Add(new wxTextDataObject);
+ Add(new CFSTR_SHELLURLDataObject());
+
+ // we don't have any data yet
+ m_dataObjectLast = NULL;
+
+ if ( !url.empty() )
+ SetURL(url);
+}
+
+bool wxURLDataObject::SetData(const wxDataFormat& format,
+ size_t len,
+ const void *buf)
+{
+ m_dataObjectLast = GetObject(format);
+
+ wxCHECK_MSG( m_dataObjectLast, FALSE,
+ wxT("unsupported format in wxURLDataObject"));
+
+ return m_dataObjectLast->SetData(len, buf);
+}
+
+wxString wxURLDataObject::GetURL() const
+{
+ wxString url;
+ wxCHECK_MSG( m_dataObjectLast, url, _T("no data in wxURLDataObject") );
+
+ size_t len = m_dataObjectLast->GetDataSize();
+
+ m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
+
+ return url;
+}
+
+void wxURLDataObject::SetURL(const wxString& url)
+{
+ wxCharBuffer urlMB(url.mb_str());
+ if ( urlMB )
+ {
+ const size_t len = strlen(urlMB) + 1; // size with trailing NUL
+#if !wxUSE_UNICODE
+ SetData(wxDF_TEXT, len, urlMB);
+#endif
+ SetData(wxDataFormat(CFSTR_SHELLURL), len, urlMB);
+ }
+
+#if wxUSE_UNICODE
+ SetData(wxDF_UNICODETEXT, url.length() + 1, url.wc_str());
+#endif
+}
+
+// ----------------------------------------------------------------------------
+// private functions
+// ----------------------------------------------------------------------------
+
+#ifdef __WXDEBUG__
+
+static const wxChar *GetTymedName(DWORD tymed)
+{
+ static wxChar s_szBuf[128];
+ switch ( tymed ) {
+ case TYMED_HGLOBAL: return wxT("TYMED_HGLOBAL");
+ case TYMED_FILE: return wxT("TYMED_FILE");
+ case TYMED_ISTREAM: return wxT("TYMED_ISTREAM");
+ case TYMED_ISTORAGE: return wxT("TYMED_ISTORAGE");
+ case TYMED_GDI: return wxT("TYMED_GDI");
+ case TYMED_MFPICT: return wxT("TYMED_MFPICT");
+ case TYMED_ENHMF: return wxT("TYMED_ENHMF");
+ default:
+ wxSprintf(s_szBuf, wxT("type of media format %ld (unknown)"), tymed);
+ return s_szBuf;
+ }
+}
+
+#endif // Debug
+
+#else // not using OLE at all
+
+// ----------------------------------------------------------------------------
+// wxDataObject
+// ----------------------------------------------------------------------------
+
+#if wxUSE_DATAOBJ
+
+wxDataObject::wxDataObject()
+{
+}
+
+wxDataObject::~wxDataObject()
+{
+}
+
+void wxDataObject::SetAutoDelete()
+{
+}
+
+#ifdef __WXDEBUG__
+const wxChar *wxDataObject::GetFormatName(wxDataFormat WXUNUSED(format))
+{
+ return NULL;
+}
+#endif // __WXDEBUG__
+
+#endif // wxUSE_DATAOBJ
+
+#endif // wxUSE_OLE/!wxUSE_OLE
+
+