]> git.saurik.com Git - wxWidgets.git/blame - src/msw/ole/dataobj.cpp
Added missing wx_aui.dsp file
[wxWidgets.git] / src / msw / ole / dataobj.cpp
CommitLineData
269a5a34
VZ
1///////////////////////////////////////////////////////////////////////////////
2// Name: msw/ole/dataobj.cpp
3// Purpose: implementation of wx[I]DataObject class
4// Author: Vadim Zeitlin
3f4a0c5b 5// Modified by:
269a5a34
VZ
6// Created: 10.05.98
7// RCS-ID: $Id$
8// Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
65571936 9// Licence: wxWindows licence
269a5a34
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
269a5a34
VZ
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#if defined(__BORLANDC__)
0d0512bd 24 #pragma hdrstop
269a5a34 25#endif
0d0512bd 26
7dee726c 27#ifndef WX_PRECOMP
0d0512bd
VZ
28 #include "wx/intl.h"
29 #include "wx/log.h"
7dee726c 30#endif
5260b1c5 31
3f480da3 32#include "wx/dataobj.h"
17b74d79 33
21709999
JS
34#if wxUSE_OLE && defined(__WIN32__) && !defined(__GNUWIN32_OLD__)
35
0d0512bd
VZ
36#include "wx/msw/private.h" // includes <windows.h>
37
4676948b
JS
38#ifdef __WXWINCE__
39#include <winreg.h>
40#endif
41
a7b4607f 42// for some compilers, the entire ole2.h must be included, not only oleauto.h
4676948b 43#if wxUSE_NORLANDER_HEADERS || defined(__WATCOMC__) || defined(__WXWINCE__)
7dee726c
RS
44 #include <ole2.h>
45#endif
269a5a34 46
a7b4607f 47#include <oleauto.h>
8b85d24e
VZ
48#include <shlobj.h>
49
0d0512bd
VZ
50#include "wx/msw/ole/oleutils.h"
51
52#include "wx/msw/dib.h"
17b74d79 53
dcbd7ce2
VS
54#ifndef CFSTR_SHELLURL
55#define CFSTR_SHELLURL _T("UniformResourceLocator")
56#endif
57
269a5a34
VZ
58// ----------------------------------------------------------------------------
59// functions
60// ----------------------------------------------------------------------------
61
8e193f38 62#ifdef __WXDEBUG__
d59ceba5 63 static const wxChar *GetTymedName(DWORD tymed);
1e8335b0 64#else // !Debug
fda7962d 65 #define GetTymedName(tymed) wxEmptyString
1e8335b0 66#endif // Debug/!Debug
269a5a34
VZ
67
68// ----------------------------------------------------------------------------
69// wxIEnumFORMATETC interface implementation
70// ----------------------------------------------------------------------------
8e193f38 71
269a5a34
VZ
72class wxIEnumFORMATETC : public IEnumFORMATETC
73{
74public:
8e193f38 75 wxIEnumFORMATETC(const wxDataFormat* formats, ULONG nCount);
33ac7e6f 76 virtual ~wxIEnumFORMATETC() { delete [] m_formats; }
269a5a34 77
8e193f38
VZ
78 // IEnumFORMATETC
79 STDMETHODIMP Next(ULONG celt, FORMATETC *rgelt, ULONG *pceltFetched);
80 STDMETHODIMP Skip(ULONG celt);
81 STDMETHODIMP Reset();
82 STDMETHODIMP Clone(IEnumFORMATETC **ppenum);
269a5a34 83
6f02a879
VZ
84 DECLARE_IUNKNOWN_METHODS;
85
269a5a34 86private:
8e193f38
VZ
87 CLIPFORMAT *m_formats; // formats we can provide data in
88 ULONG m_nCount, // number of formats we support
89 m_nCurrent; // current enum position
22f3361e
VZ
90
91 DECLARE_NO_COPY_CLASS(wxIEnumFORMATETC)
269a5a34
VZ
92};
93
94// ----------------------------------------------------------------------------
95// wxIDataObject implementation of IDataObject interface
96// ----------------------------------------------------------------------------
8e193f38 97
269a5a34
VZ
98class wxIDataObject : public IDataObject
99{
100public:
8e193f38 101 wxIDataObject(wxDataObject *pDataObject);
33ac7e6f 102 virtual ~wxIDataObject();
d59ceba5
VZ
103
104 // normally, wxDataObject controls our lifetime (i.e. we're deleted when it
3103e8a9 105 // is), but in some cases, the situation is reversed, that is we delete it
d59ceba5 106 // when this object is deleted - setting this flag enables such logic
17a6a2e0 107 void SetDeleteFlag() { m_mustDelete = true; }
269a5a34 108
8e193f38
VZ
109 // IDataObject
110 STDMETHODIMP GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium);
111 STDMETHODIMP GetDataHere(FORMATETC *pformatetc, STGMEDIUM *pmedium);
112 STDMETHODIMP QueryGetData(FORMATETC *pformatetc);
113 STDMETHODIMP GetCanonicalFormatEtc(FORMATETC *In, FORMATETC *pOut);
114 STDMETHODIMP SetData(FORMATETC *pfetc, STGMEDIUM *pmedium, BOOL fRelease);
115 STDMETHODIMP EnumFormatEtc(DWORD dwDirection, IEnumFORMATETC **ppenumFEtc);
116 STDMETHODIMP DAdvise(FORMATETC *pfetc, DWORD ad, IAdviseSink *p, DWORD *pdw);
117 STDMETHODIMP DUnadvise(DWORD dwConnection);
118 STDMETHODIMP EnumDAdvise(IEnumSTATDATA **ppenumAdvise);
269a5a34 119
6f02a879
VZ
120 DECLARE_IUNKNOWN_METHODS;
121
269a5a34 122private:
8e193f38 123 wxDataObject *m_pDataObject; // pointer to C++ class we belong to
d59ceba5
VZ
124
125 bool m_mustDelete;
22f3361e
VZ
126
127 DECLARE_NO_COPY_CLASS(wxIDataObject)
d59ceba5
VZ
128};
129
269a5a34
VZ
130// ============================================================================
131// implementation
132// ============================================================================
133
3f480da3
VZ
134// ----------------------------------------------------------------------------
135// wxDataFormat
136// ----------------------------------------------------------------------------
137
138void wxDataFormat::SetId(const wxChar *format)
139{
33ac7e6f 140 m_format = (wxDataFormat::NativeFormat)::RegisterClipboardFormat(format);
3f480da3
VZ
141 if ( !m_format )
142 {
143 wxLogError(_("Couldn't register clipboard format '%s'."), format);
144 }
145}
146
147wxString wxDataFormat::GetId() const
148{
149 static const int max = 256;
150
151 wxString s;
152
153 wxCHECK_MSG( !IsStandard(), s,
223d09f6 154 wxT("name of predefined format cannot be retrieved") );
3f480da3 155
de564874 156 int len = ::GetClipboardFormatName(m_format, wxStringBuffer(s, max), max);
3f480da3
VZ
157
158 if ( !len )
159 {
160 wxLogError(_("The clipboard format '%d' doesn't exist."), m_format);
161 }
162
163 return s;
164}
165
269a5a34
VZ
166// ----------------------------------------------------------------------------
167// wxIEnumFORMATETC
168// ----------------------------------------------------------------------------
169
170BEGIN_IID_TABLE(wxIEnumFORMATETC)
8e193f38
VZ
171 ADD_IID(Unknown)
172 ADD_IID(EnumFORMATETC)
269a5a34
VZ
173END_IID_TABLE;
174
175IMPLEMENT_IUNKNOWN_METHODS(wxIEnumFORMATETC)
176
8e193f38 177wxIEnumFORMATETC::wxIEnumFORMATETC(const wxDataFormat *formats, ULONG nCount)
269a5a34 178{
8e193f38
VZ
179 m_nCurrent = 0;
180 m_nCount = nCount;
181 m_formats = new CLIPFORMAT[nCount];
182 for ( ULONG n = 0; n < nCount; n++ ) {
183 m_formats[n] = formats[n].GetFormatId();
184 }
269a5a34
VZ
185}
186
187STDMETHODIMP wxIEnumFORMATETC::Next(ULONG celt,
188 FORMATETC *rgelt,
1f1c4210 189 ULONG *pceltFetched)
269a5a34 190{
8e193f38 191 wxLogTrace(wxTRACE_OleCalls, wxT("wxIEnumFORMATETC::Next"));
269a5a34 192
1f1c4210
VZ
193 ULONG numFetched = 0;
194 while (m_nCurrent < m_nCount && numFetched < celt) {
8e193f38
VZ
195 FORMATETC format;
196 format.cfFormat = m_formats[m_nCurrent++];
197 format.ptd = NULL;
198 format.dwAspect = DVASPECT_CONTENT;
199 format.lindex = -1;
200 format.tymed = TYMED_HGLOBAL;
269a5a34 201
1f1c4210
VZ
202 *rgelt++ = format;
203 numFetched++;
8e193f38 204 }
1f1c4210
VZ
205
206 if (pceltFetched)
207 *pceltFetched = numFetched;
208
209 return numFetched == celt ? S_OK : S_FALSE;
269a5a34
VZ
210}
211
212STDMETHODIMP wxIEnumFORMATETC::Skip(ULONG celt)
213{
8e193f38
VZ
214 wxLogTrace(wxTRACE_OleCalls, wxT("wxIEnumFORMATETC::Skip"));
215
216 m_nCurrent += celt;
217 if ( m_nCurrent < m_nCount )
218 return S_OK;
269a5a34 219
8e193f38
VZ
220 // no, can't skip this many elements
221 m_nCurrent -= celt;
269a5a34 222
8e193f38 223 return S_FALSE;
269a5a34
VZ
224}
225
226STDMETHODIMP wxIEnumFORMATETC::Reset()
227{
8e193f38 228 wxLogTrace(wxTRACE_OleCalls, wxT("wxIEnumFORMATETC::Reset"));
269a5a34 229
8e193f38 230 m_nCurrent = 0;
269a5a34 231
8e193f38 232 return S_OK;
269a5a34
VZ
233}
234
235STDMETHODIMP wxIEnumFORMATETC::Clone(IEnumFORMATETC **ppenum)
236{
8e193f38
VZ
237 wxLogTrace(wxTRACE_OleCalls, wxT("wxIEnumFORMATETC::Clone"));
238
239 // unfortunately, we can't reuse the code in ctor - types are different
240 wxIEnumFORMATETC *pNew = new wxIEnumFORMATETC(NULL, 0);
241 pNew->m_nCount = m_nCount;
242 pNew->m_formats = new CLIPFORMAT[m_nCount];
243 for ( ULONG n = 0; n < m_nCount; n++ ) {
244 pNew->m_formats[n] = m_formats[n];
245 }
246 pNew->AddRef();
247 *ppenum = pNew;
269a5a34 248
8e193f38 249 return S_OK;
269a5a34
VZ
250}
251
252// ----------------------------------------------------------------------------
253// wxIDataObject
254// ----------------------------------------------------------------------------
255
256BEGIN_IID_TABLE(wxIDataObject)
8e193f38
VZ
257 ADD_IID(Unknown)
258 ADD_IID(DataObject)
269a5a34
VZ
259END_IID_TABLE;
260
261IMPLEMENT_IUNKNOWN_METHODS(wxIDataObject)
262
263wxIDataObject::wxIDataObject(wxDataObject *pDataObject)
264{
8e193f38 265 m_pDataObject = pDataObject;
17a6a2e0 266 m_mustDelete = false;
d59ceba5
VZ
267}
268
269wxIDataObject::~wxIDataObject()
270{
271 if ( m_mustDelete )
272 {
273 delete m_pDataObject;
274 }
269a5a34
VZ
275}
276
277// get data functions
278STDMETHODIMP wxIDataObject::GetData(FORMATETC *pformatetcIn, STGMEDIUM *pmedium)
279{
8e193f38 280 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::GetData"));
269a5a34 281
8e193f38
VZ
282 // is data is in our format?
283 HRESULT hr = QueryGetData(pformatetcIn);
284 if ( FAILED(hr) )
285 return hr;
269a5a34 286
8e193f38
VZ
287 // for the bitmaps and metafiles we use the handles instead of global memory
288 // to pass the data
f4d0cce0 289 wxDataFormat format = (wxDataFormat::NativeFormat)pformatetcIn->cfFormat;
269a5a34 290
8e193f38
VZ
291 switch ( format )
292 {
293 case wxDF_BITMAP:
294 pmedium->tymed = TYMED_GDI;
295 break;
296
d9317fd4
VZ
297 case wxDF_ENHMETAFILE:
298 pmedium->tymed = TYMED_ENHMF;
299 break;
300
4676948b 301#ifndef __WXWINCE__
8e193f38 302 case wxDF_METAFILE:
265b0c07
VZ
303 pmedium->hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE,
304 sizeof(METAFILEPICT));
305 if ( !pmedium->hGlobal ) {
f6bcfd97 306 wxLogLastError(wxT("GlobalAlloc"));
265b0c07
VZ
307 return E_OUTOFMEMORY;
308 }
8e193f38
VZ
309 pmedium->tymed = TYMED_MFPICT;
310 break;
4676948b 311#endif
8e193f38
VZ
312 default:
313 // alloc memory
314 size_t size = m_pDataObject->GetDataSize(format);
315 if ( !size ) {
316 // it probably means that the method is just not implemented
317 wxLogDebug(wxT("Invalid data size - can't be 0"));
318
319 return DV_E_FORMATETC;
320 }
321
a8e24848
VZ
322 // we may need extra space for the buffer size
323 size += m_pDataObject->GetBufferOffset( format );
9e2896e5 324
8e193f38
VZ
325 HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, size);
326 if ( hGlobal == NULL ) {
f6bcfd97 327 wxLogLastError(wxT("GlobalAlloc"));
8e193f38
VZ
328 return E_OUTOFMEMORY;
329 }
330
331 // copy data
332 pmedium->tymed = TYMED_HGLOBAL;
333 pmedium->hGlobal = hGlobal;
334 }
269a5a34 335
8e193f38
VZ
336 pmedium->pUnkForRelease = NULL;
337
338 // do copy the data
339 hr = GetDataHere(pformatetcIn, pmedium);
340 if ( FAILED(hr) ) {
341 // free resources we allocated
265b0c07 342 if ( pmedium->tymed & (TYMED_HGLOBAL | TYMED_MFPICT) ) {
8e193f38
VZ
343 GlobalFree(pmedium->hGlobal);
344 }
345
346 return hr;
347 }
269a5a34 348
8e193f38 349 return S_OK;
269a5a34
VZ
350}
351
352STDMETHODIMP wxIDataObject::GetDataHere(FORMATETC *pformatetc,
353 STGMEDIUM *pmedium)
354{
8e193f38 355 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::GetDataHere"));
269a5a34 356
8e193f38
VZ
357 // put data in caller provided medium
358 switch ( pmedium->tymed )
359 {
360 case TYMED_GDI:
d59ceba5
VZ
361 if ( !m_pDataObject->GetDataHere(wxDF_BITMAP, &pmedium->hBitmap) )
362 return E_UNEXPECTED;
8e193f38
VZ
363 break;
364
d9317fd4
VZ
365 case TYMED_ENHMF:
366 if ( !m_pDataObject->GetDataHere(wxDF_ENHMETAFILE,
367 &pmedium->hEnhMetaFile) )
368 return E_UNEXPECTED;
369 break;
370
8e193f38 371 case TYMED_MFPICT:
d9317fd4
VZ
372 // fall through - we pass METAFILEPICT through HGLOBAL
373
8e193f38
VZ
374 case TYMED_HGLOBAL:
375 {
376 // copy data
9e2896e5
VZ
377 HGLOBAL hGlobal = pmedium->hGlobal;
378 void *pBuf = GlobalLock(hGlobal);
8e193f38
VZ
379 if ( pBuf == NULL ) {
380 wxLogLastError(wxT("GlobalLock"));
381 return E_OUTOFMEMORY;
382 }
383
e1b435af 384 wxDataFormat format = pformatetc->cfFormat;
a8e24848
VZ
385
386 // possibly put the size in the beginning of the buffer
387 pBuf = m_pDataObject->SetSizeInBuffer
388 (
389 pBuf,
390 ::GlobalSize(hGlobal),
391 format
392 );
9e2896e5 393
d59ceba5
VZ
394 if ( !m_pDataObject->GetDataHere(format, pBuf) )
395 return E_UNEXPECTED;
8e193f38 396
9e2896e5 397 GlobalUnlock(hGlobal);
8e193f38
VZ
398 }
399 break;
400
401 default:
402 return DV_E_TYMED;
403 }
269a5a34 404
8e193f38 405 return S_OK;
269a5a34
VZ
406}
407
d26fad77 408
9e2896e5 409// set data functions
269a5a34
VZ
410STDMETHODIMP wxIDataObject::SetData(FORMATETC *pformatetc,
411 STGMEDIUM *pmedium,
412 BOOL fRelease)
413{
d59ceba5 414 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::SetData"));
8e193f38 415
d59ceba5
VZ
416 switch ( pmedium->tymed )
417 {
418 case TYMED_GDI:
9e2896e5 419 m_pDataObject->SetData(wxDF_BITMAP, 0, &pmedium->hBitmap);
d59ceba5
VZ
420 break;
421
d9317fd4
VZ
422 case TYMED_ENHMF:
423 m_pDataObject->SetData(wxDF_ENHMETAFILE, 0, &pmedium->hEnhMetaFile);
424 break;
425
d59ceba5 426 case TYMED_MFPICT:
d9317fd4 427 // fall through - we pass METAFILEPICT through HGLOBAL
d59ceba5
VZ
428 case TYMED_HGLOBAL:
429 {
51edda6a
VZ
430 wxDataFormat format = pformatetc->cfFormat;
431
432 // this is quite weird, but for file drag and drop, explorer
433 // calls our SetData() with the formats we do *not* support!
434 //
435 // as we can't fix this bug in explorer (it's a bug because it
436 // should only use formats returned by EnumFormatEtc), do the
437 // check here
5015e022 438 if ( !m_pDataObject->IsSupported(format, wxDataObject::Set) ) {
51edda6a
VZ
439 // go away!
440 return DV_E_FORMATETC;
441 }
442
d59ceba5 443 // copy data
e1b435af 444 const void *pBuf = GlobalLock(pmedium->hGlobal);
d59ceba5 445 if ( pBuf == NULL ) {
f6bcfd97 446 wxLogLastError(wxT("GlobalLock"));
d59ceba5
VZ
447
448 return E_OUTOFMEMORY;
449 }
450
9e2896e5
VZ
451 // we've got a problem with SetData() here because the base
452 // class version requires the size parameter which we don't
453 // have anywhere in OLE data transfer - so we need to
454 // synthetise it for known formats and we suppose that all data
455 // in custom formats starts with a DWORD containing the size
456 size_t size;
51edda6a 457 switch ( format )
9e2896e5
VZ
458 {
459 case CF_TEXT:
460 case CF_OEMTEXT:
461 size = strlen((const char *)pBuf);
462 break;
afd23c22 463#if !(defined(__BORLANDC__) && (__BORLANDC__ < 0x500))
9e2896e5 464 case CF_UNICODETEXT:
de85a884
VZ
465#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
466 || ( defined(__MWERKS__) && defined(__WXMSW__) )
e1b435af 467 size = std::wcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
d834f22c 468#else
17ebae65 469 size = wxWcslen((const wchar_t *)pBuf) * sizeof(wchar_t);
d834f22c 470#endif
9e2896e5 471 break;
4d85bcd1 472#endif
9e2896e5 473 case CF_BITMAP:
4676948b 474#ifndef __WXWINCE__
9e2896e5
VZ
475 case CF_HDROP:
476 // these formats don't use size at all, anyhow (but
477 // pass data by handle, which is always a single DWORD)
478 size = 0;
479 break;
4676948b 480#endif
9e2896e5 481
8ee9d618
VZ
482 case CF_DIB:
483 // the handler will calculate size itself (it's too
484 // complicated to do it here)
485 size = 0;
486 break;
487
4676948b 488#ifndef __WXWINCE__
265b0c07
VZ
489 case CF_METAFILEPICT:
490 size = sizeof(METAFILEPICT);
491 break;
4676948b 492#endif
9e2896e5 493 default:
a8e24848
VZ
494 pBuf = m_pDataObject->
495 GetSizeFromBuffer(pBuf, &size, format);
496 size -= m_pDataObject->GetBufferOffset(format);
9e2896e5
VZ
497 }
498
9e2896e5 499 bool ok = m_pDataObject->SetData(format, size, pBuf);
d59ceba5
VZ
500
501 GlobalUnlock(pmedium->hGlobal);
9e2896e5
VZ
502
503 if ( !ok ) {
504 return E_UNEXPECTED;
505 }
d59ceba5
VZ
506 }
507 break;
508
509 default:
510 return DV_E_TYMED;
511 }
512
513 if ( fRelease ) {
265b0c07
VZ
514 // we own the medium, so we must release it - but do *not* free any
515 // data we pass by handle because we have copied it elsewhere
516 switch ( pmedium->tymed )
d59ceba5 517 {
265b0c07
VZ
518 case TYMED_GDI:
519 pmedium->hBitmap = 0;
520 break;
521
522 case TYMED_MFPICT:
523 pmedium->hMetaFilePict = 0;
524 break;
d9317fd4
VZ
525
526 case TYMED_ENHMF:
527 pmedium->hEnhMetaFile = 0;
528 break;
d59ceba5
VZ
529 }
530
531 ReleaseStgMedium(pmedium);
532 }
533
534 return S_OK;
269a5a34
VZ
535}
536
537// information functions
538STDMETHODIMP wxIDataObject::QueryGetData(FORMATETC *pformatetc)
539{
d59ceba5
VZ
540 // do we accept data in this format?
541 if ( pformatetc == NULL ) {
542 wxLogTrace(wxTRACE_OleCalls,
543 wxT("wxIDataObject::QueryGetData: invalid ptr."));
8e193f38 544
d59ceba5
VZ
545 return E_INVALIDARG;
546 }
269a5a34 547
d59ceba5
VZ
548 // the only one allowed by current COM implementation
549 if ( pformatetc->lindex != -1 ) {
550 wxLogTrace(wxTRACE_OleCalls,
9b601c24 551 wxT("wxIDataObject::QueryGetData: bad lindex %ld"),
d59ceba5 552 pformatetc->lindex);
269a5a34 553
d59ceba5
VZ
554 return DV_E_LINDEX;
555 }
269a5a34 556
d59ceba5
VZ
557 // we don't support anything other (THUMBNAIL, ICON, DOCPRINT...)
558 if ( pformatetc->dwAspect != DVASPECT_CONTENT ) {
559 wxLogTrace(wxTRACE_OleCalls,
9b601c24 560 wxT("wxIDataObject::QueryGetData: bad dwAspect %ld"),
d59ceba5
VZ
561 pformatetc->dwAspect);
562
563 return DV_E_DVASPECT;
564 }
565
566 // and now check the type of data requested
9e2896e5 567 wxDataFormat format = pformatetc->cfFormat;
d59ceba5 568 if ( m_pDataObject->IsSupportedFormat(format) ) {
d59ceba5 569 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::QueryGetData: %s ok"),
1e8335b0 570 wxGetFormatName(format));
d59ceba5
VZ
571 }
572 else {
573 wxLogTrace(wxTRACE_OleCalls,
574 wxT("wxIDataObject::QueryGetData: %s unsupported"),
1e8335b0 575 wxGetFormatName(format));
9e2896e5 576
d59ceba5
VZ
577 return DV_E_FORMATETC;
578 }
579
580 // we only transfer data by global memory, except for some particular cases
581 DWORD tymed = pformatetc->tymed;
582 if ( (format == wxDF_BITMAP && !(tymed & TYMED_GDI)) &&
583 !(tymed & TYMED_HGLOBAL) ) {
584 // it's not what we're waiting for
d59ceba5
VZ
585 wxLogTrace(wxTRACE_OleCalls,
586 wxT("wxIDataObject::QueryGetData: %s != %s"),
587 GetTymedName(tymed),
588 GetTymedName(format == wxDF_BITMAP ? TYMED_GDI
589 : TYMED_HGLOBAL));
d59ceba5
VZ
590
591 return DV_E_TYMED;
592 }
593
269a5a34 594 return S_OK;
269a5a34
VZ
595}
596
33ac7e6f 597STDMETHODIMP wxIDataObject::GetCanonicalFormatEtc(FORMATETC *WXUNUSED(pFormatetcIn),
269a5a34
VZ
598 FORMATETC *pFormatetcOut)
599{
8e193f38
VZ
600 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::GetCanonicalFormatEtc"));
601
602 // TODO we might want something better than this trivial implementation here
603 if ( pFormatetcOut != NULL )
604 pFormatetcOut->ptd = NULL;
269a5a34 605
8e193f38 606 return DATA_S_SAMEFORMATETC;
269a5a34
VZ
607}
608
9e2896e5 609STDMETHODIMP wxIDataObject::EnumFormatEtc(DWORD dwDir,
269a5a34
VZ
610 IEnumFORMATETC **ppenumFormatEtc)
611{
8e193f38 612 wxLogTrace(wxTRACE_OleCalls, wxT("wxIDataObject::EnumFormatEtc"));
269a5a34 613
9e2896e5
VZ
614 wxDataObject::Direction dir = dwDir == DATADIR_GET ? wxDataObject::Get
615 : wxDataObject::Set;
269a5a34 616
4a10ea8b 617 ULONG nFormatCount = wx_truncate_cast(ULONG, m_pDataObject->GetFormatCount(dir));
33ac7e6f 618 wxDataFormat format;
c5639a87 619 wxDataFormat *formats;
9e2896e5
VZ
620 formats = nFormatCount == 1 ? &format : new wxDataFormat[nFormatCount];
621 m_pDataObject->GetAllFormats(formats, dir);
8e193f38
VZ
622
623 wxIEnumFORMATETC *pEnum = new wxIEnumFORMATETC(formats, nFormatCount);
624 pEnum->AddRef();
625 *ppenumFormatEtc = pEnum;
626
627 if ( formats != &format ) {
628 delete [] formats;
629 }
269a5a34 630
8e193f38 631 return S_OK;
269a5a34
VZ
632}
633
9e2896e5 634// ----------------------------------------------------------------------------
269a5a34 635// advise sink functions (not implemented)
9e2896e5
VZ
636// ----------------------------------------------------------------------------
637
33ac7e6f
KB
638STDMETHODIMP wxIDataObject::DAdvise(FORMATETC *WXUNUSED(pformatetc),
639 DWORD WXUNUSED(advf),
640 IAdviseSink *WXUNUSED(pAdvSink),
641 DWORD *WXUNUSED(pdwConnection))
269a5a34
VZ
642{
643 return OLE_E_ADVISENOTSUPPORTED;
644}
645
33ac7e6f 646STDMETHODIMP wxIDataObject::DUnadvise(DWORD WXUNUSED(dwConnection))
269a5a34
VZ
647{
648 return OLE_E_ADVISENOTSUPPORTED;
649}
650
33ac7e6f 651STDMETHODIMP wxIDataObject::EnumDAdvise(IEnumSTATDATA **WXUNUSED(ppenumAdvise))
269a5a34
VZ
652{
653 return OLE_E_ADVISENOTSUPPORTED;
654}
655
656// ----------------------------------------------------------------------------
657// wxDataObject
658// ----------------------------------------------------------------------------
659
660wxDataObject::wxDataObject()
661{
d59ceba5
VZ
662 m_pIDataObject = new wxIDataObject(this);
663 m_pIDataObject->AddRef();
269a5a34
VZ
664}
665
666wxDataObject::~wxDataObject()
667{
d59ceba5
VZ
668 ReleaseInterface(m_pIDataObject);
669}
670
671void wxDataObject::SetAutoDelete()
672{
673 ((wxIDataObject *)m_pIDataObject)->SetDeleteFlag();
674 m_pIDataObject->Release();
675
676 // so that the dtor doesnt' crash
677 m_pIDataObject = NULL;
269a5a34
VZ
678}
679
a8e24848 680size_t wxDataObject::GetBufferOffset(const wxDataFormat& format )
e1b435af 681{
a8e24848
VZ
682 // if we prepend the size of the data to the buffer itself, account for it
683 return NeedsVerbatimData(format) ? 0 : sizeof(size_t);
e1b435af
MB
684}
685
686const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size,
a8e24848 687 const wxDataFormat& format )
e1b435af 688{
51d05226
MW
689 size_t realsz = ::HeapSize(::GetProcessHeap(), 0, buffer);
690 if ( realsz == (size_t)-1 )
a8e24848
VZ
691 {
692 // note that HeapSize() does not set last error
693 wxLogApiError(wxT("HeapSize"), 0);
694 return NULL;
695 }
696
697 *size = realsz;
e1b435af 698
a8e24848
VZ
699 // check if this data has its size prepended (as it was by default for wx
700 // programs prior 2.6.3):
701 size_t *p = (size_t *)buffer;
702 if ( *p == realsz )
703 {
704 if ( NeedsVerbatimData(format) )
705 wxLogDebug(wxT("Apparent data format mismatch: size not needed"));
706
707 p++; // this data has its size prepended; skip first DWORD
708 }
709
710 return p;
e1b435af
MB
711}
712
713void* wxDataObject::SetSizeInBuffer( void* buffer, size_t size,
a8e24848 714 const wxDataFormat& format )
e1b435af 715{
a8e24848
VZ
716 size_t* p = (size_t *)buffer;
717 if ( !NeedsVerbatimData(format) )
718 {
719 // prepend the size to the data and skip it
720 *p++ = size;
721 }
e1b435af 722
a8e24848 723 return p;
e1b435af
MB
724}
725
d9317fd4 726#ifdef __WXDEBUG__
8e193f38 727
f6bcfd97 728const wxChar *wxDataObject::GetFormatName(wxDataFormat format)
d9317fd4
VZ
729{
730 // case 'xxx' is not a valid value for switch of enum 'wxDataFormat'
731 #ifdef __VISUALC__
732 #pragma warning(disable:4063)
733 #endif // VC++
734
f6bcfd97 735 static wxChar s_szBuf[256];
d9317fd4 736 switch ( format ) {
f6bcfd97
BP
737 case CF_TEXT: return wxT("CF_TEXT");
738 case CF_BITMAP: return wxT("CF_BITMAP");
f6bcfd97
BP
739 case CF_SYLK: return wxT("CF_SYLK");
740 case CF_DIF: return wxT("CF_DIF");
741 case CF_TIFF: return wxT("CF_TIFF");
742 case CF_OEMTEXT: return wxT("CF_OEMTEXT");
743 case CF_DIB: return wxT("CF_DIB");
744 case CF_PALETTE: return wxT("CF_PALETTE");
745 case CF_PENDATA: return wxT("CF_PENDATA");
746 case CF_RIFF: return wxT("CF_RIFF");
747 case CF_WAVE: return wxT("CF_WAVE");
748 case CF_UNICODETEXT: return wxT("CF_UNICODETEXT");
569f027b
VS
749#ifndef __WXWINCE__
750 case CF_METAFILEPICT: return wxT("CF_METAFILEPICT");
f6bcfd97 751 case CF_ENHMETAFILE: return wxT("CF_ENHMETAFILE");
f6bcfd97 752 case CF_LOCALE: return wxT("CF_LOCALE");
569f027b
VS
753 case CF_HDROP: return wxT("CF_HDROP");
754#endif
8e193f38 755
d9317fd4 756 default:
c77ae1d9 757 if ( !::GetClipboardFormatName(format, s_szBuf, WXSIZEOF(s_szBuf)) )
d9317fd4
VZ
758 {
759 // it must be a new predefined format we don't know the name of
f6bcfd97 760 wxSprintf(s_szBuf, wxT("unknown CF (0x%04x)"), format.GetFormatId());
d9317fd4 761 }
8e193f38 762
d9317fd4 763 return s_szBuf;
8e193f38 764 }
1e8335b0 765
d9317fd4
VZ
766 #ifdef __VISUALC__
767 #pragma warning(default:4063)
768 #endif // VC++
269a5a34
VZ
769}
770
1e8335b0
VZ
771#endif // Debug
772
3f480da3 773// ----------------------------------------------------------------------------
9e2896e5 774// wxBitmapDataObject supports CF_DIB format
3f480da3
VZ
775// ----------------------------------------------------------------------------
776
be69f971
VZ
777// TODO: support CF_DIB under Windows CE as well
778
9e2896e5 779size_t wxBitmapDataObject::GetDataSize() const
3f480da3 780{
be69f971 781#if wxUSE_WXDIB && !defined(__WXWINCE__)
22be0335 782 return wxDIB::ConvertFromBitmap(NULL, GetHbitmapOf(GetBitmap()));
4cb88a72
JS
783#else
784 return 0;
785#endif
3f480da3
VZ
786}
787
9e2896e5 788bool wxBitmapDataObject::GetDataHere(void *buf) const
3f480da3 789{
be69f971 790#if wxUSE_WXDIB && !defined(__WXWINCE__)
22be0335
VZ
791 BITMAPINFO * const pbi = (BITMAPINFO *)buf;
792
793 return wxDIB::ConvertFromBitmap(pbi, GetHbitmapOf(GetBitmap())) != 0;
4cb88a72 794#else
17a6a2e0
WS
795 wxUnusedVar(buf);
796 return false;
4cb88a72 797#endif
3f480da3
VZ
798}
799
33ac7e6f 800bool wxBitmapDataObject::SetData(size_t WXUNUSED(len), const void *buf)
3f480da3 801{
be69f971 802#if wxUSE_WXDIB && !defined(__WXWINCE__)
22be0335 803 const BITMAPINFO * const pbmi = (const BITMAPINFO *)buf;
9e2896e5 804
22be0335 805 HBITMAP hbmp = wxDIB::ConvertToBitmap(pbmi);
3f480da3 806
22be0335
VZ
807 wxCHECK_MSG( hbmp, FALSE, wxT("pasting/dropping invalid bitmap") );
808
809 const BITMAPINFOHEADER * const pbmih = &pbmi->bmiHeader;
810 wxBitmap bitmap(pbmih->biWidth, pbmih->biHeight, pbmih->biBitCount);
811 bitmap.SetHBITMAP((WXHBITMAP)hbmp);
812
813 // TODO: create wxPalette if the bitmap has any
9e2896e5
VZ
814
815 SetBitmap(bitmap);
3f480da3 816
17a6a2e0 817 return true;
4cb88a72 818#else
17a6a2e0
WS
819 wxUnusedVar(buf);
820 return false;
4cb88a72 821#endif
3f480da3
VZ
822}
823
9e2896e5
VZ
824// ----------------------------------------------------------------------------
825// wxBitmapDataObject2 supports CF_BITMAP format
826// ----------------------------------------------------------------------------
827
828// the bitmaps aren't passed by value as other types of data (i.e. by copying
829// the data into a global memory chunk and passing it to the clipboard or
830// another application or whatever), but by handle, so these generic functions
831// don't make much sense to them.
832
833size_t wxBitmapDataObject2::GetDataSize() const
3f480da3 834{
9e2896e5 835 return 0;
3f480da3
VZ
836}
837
9e2896e5 838bool wxBitmapDataObject2::GetDataHere(void *pBuf) const
3f480da3 839{
9e2896e5
VZ
840 // we put a bitmap handle into pBuf
841 *(WXHBITMAP *)pBuf = GetBitmap().GetHBITMAP();
842
17a6a2e0 843 return true;
3f480da3
VZ
844}
845
265b0c07 846bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf)
3f480da3 847{
9e2896e5 848 HBITMAP hbmp = *(HBITMAP *)pBuf;
3f480da3 849
9e2896e5
VZ
850 BITMAP bmp;
851 if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) )
852 {
f6bcfd97 853 wxLogLastError(wxT("GetObject(HBITMAP)"));
9e2896e5 854 }
8e193f38 855
9e2896e5
VZ
856 wxBitmap bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes);
857 bitmap.SetHBITMAP((WXHBITMAP)hbmp);
d59ceba5 858
9e2896e5
VZ
859 if ( !bitmap.Ok() ) {
860 wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
861
17a6a2e0 862 return false;
9e2896e5
VZ
863 }
864
865 SetBitmap(bitmap);
866
17a6a2e0 867 return true;
d59ceba5
VZ
868}
869
9e2896e5 870#if 0
8e193f38
VZ
871
872size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
873{
d59ceba5
VZ
874 if ( format.GetFormatId() == CF_DIB )
875 {
876 // create the DIB
877 ScreenHDC hdc;
878
879 // shouldn't be selected into a DC or GetDIBits() would fail
880 wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
881 wxT("can't copy bitmap selected into wxMemoryDC") );
882
883 // first get the info
884 BITMAPINFO bi;
885 if ( !GetDIBits(hdc, (HBITMAP)m_bitmap.GetHBITMAP(), 0, 0,
886 NULL, &bi, DIB_RGB_COLORS) )
887 {
f6bcfd97 888 wxLogLastError(wxT("GetDIBits(NULL)"));
d59ceba5
VZ
889
890 return 0;
891 }
892
893 return sizeof(BITMAPINFO) + bi.bmiHeader.biSizeImage;
894 }
895 else // CF_BITMAP
896 {
897 // no data to copy - we don't pass HBITMAP via global memory
898 return 0;
899 }
8e193f38
VZ
900}
901
d59ceba5 902bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format,
8e193f38
VZ
903 void *pBuf) const
904{
d59ceba5
VZ
905 wxASSERT_MSG( m_bitmap.Ok(), wxT("copying invalid bitmap") );
906
907 HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP();
908 if ( format.GetFormatId() == CF_DIB )
909 {
910 // create the DIB
911 ScreenHDC hdc;
912
913 // shouldn't be selected into a DC or GetDIBits() would fail
914 wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
915 wxT("can't copy bitmap selected into wxMemoryDC") );
916
917 // first get the info
918 BITMAPINFO *pbi = (BITMAPINFO *)pBuf;
919 if ( !GetDIBits(hdc, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) )
920 {
f6bcfd97 921 wxLogLastError(wxT("GetDIBits(NULL)"));
d59ceba5
VZ
922
923 return 0;
924 }
925
926 // and now copy the bits
927 if ( !GetDIBits(hdc, hbmp, 0, pbi->bmiHeader.biHeight, pbi + 1,
928 pbi, DIB_RGB_COLORS) )
929 {
f6bcfd97 930 wxLogLastError(wxT("GetDIBits"));
d59ceba5 931
17a6a2e0 932 return false;
d59ceba5
VZ
933 }
934 }
935 else // CF_BITMAP
936 {
937 // we put a bitmap handle into pBuf
938 *(HBITMAP *)pBuf = hbmp;
939 }
940
17a6a2e0 941 return true;
d59ceba5
VZ
942}
943
9e2896e5
VZ
944bool wxBitmapDataObject::SetData(const wxDataFormat& format,
945 size_t size, const void *pBuf)
d59ceba5
VZ
946{
947 HBITMAP hbmp;
948 if ( format.GetFormatId() == CF_DIB )
949 {
950 // here we get BITMAPINFO struct followed by the actual bitmap bits and
951 // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
952 ScreenHDC hdc;
953
954 BITMAPINFO *pbmi = (BITMAPINFO *)pBuf;
955 BITMAPINFOHEADER *pbmih = &pbmi->bmiHeader;
956 hbmp = CreateDIBitmap(hdc, pbmih, CBM_INIT,
957 pbmi + 1, pbmi, DIB_RGB_COLORS);
958 if ( !hbmp )
959 {
f6bcfd97 960 wxLogLastError(wxT("CreateDIBitmap"));
d59ceba5
VZ
961 }
962
963 m_bitmap.SetWidth(pbmih->biWidth);
964 m_bitmap.SetHeight(pbmih->biHeight);
965 }
966 else // CF_BITMAP
967 {
968 // it's easy with bitmaps: we pass them by handle
969 hbmp = *(HBITMAP *)pBuf;
970
971 BITMAP bmp;
972 if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) )
973 {
f6bcfd97 974 wxLogLastError(wxT("GetObject(HBITMAP)"));
d59ceba5
VZ
975 }
976
977 m_bitmap.SetWidth(bmp.bmWidth);
978 m_bitmap.SetHeight(bmp.bmHeight);
979 m_bitmap.SetDepth(bmp.bmPlanes);
980 }
981
982 m_bitmap.SetHBITMAP((WXHBITMAP)hbmp);
983
984 wxASSERT_MSG( m_bitmap.Ok(), wxT("pasting invalid bitmap") );
985
17a6a2e0 986 return true;
8e193f38
VZ
987}
988
9e2896e5
VZ
989#endif // 0
990
991// ----------------------------------------------------------------------------
992// wxFileDataObject
993// ----------------------------------------------------------------------------
994
0c0d1521
WS
995bool wxFileDataObject::SetData(size_t WXUNUSED(size),
996 const void *WXUNUSED_IN_WINCE(pData))
9e2896e5 997{
4676948b 998#ifndef __WXWINCE__
9e2896e5
VZ
999 m_filenames.Empty();
1000
1001 // the documentation states that the first member of DROPFILES structure is
1002 // a "DWORD offset of double NUL terminated file list". What they mean by
1003 // this (I wonder if you see it immediately) is that the list starts at
1004 // ((char *)&(pDropFiles.pFiles)) + pDropFiles.pFiles. We're also advised
1005 // to use DragQueryFile to work with this structure, but not told where and
1006 // how to get HDROP.
1007 HDROP hdrop = (HDROP)pData; // NB: it works, but I'm not sure about it
1008
1009 // get number of files (magic value -1)
1010 UINT nFiles = ::DragQueryFile(hdrop, (unsigned)-1, NULL, 0u);
1011
51edda6a
VZ
1012 wxCHECK_MSG ( nFiles != (UINT)-1, FALSE, wxT("wrong HDROP handle") );
1013
9e2896e5
VZ
1014 // for each file get the length, allocate memory and then get the name
1015 wxString str;
1016 UINT len, n;
1017 for ( n = 0; n < nFiles; n++ ) {
1018 // +1 for terminating NUL
1019 len = ::DragQueryFile(hdrop, n, NULL, 0) + 1;
1020
de564874 1021 UINT len2 = ::DragQueryFile(hdrop, n, wxStringBuffer(str, len), len);
9e2896e5
VZ
1022 m_filenames.Add(str);
1023
1024 if ( len2 != len - 1 ) {
f6bcfd97
BP
1025 wxLogDebug(wxT("In wxFileDropTarget::OnDrop DragQueryFile returned\
1026 %d characters, %d expected."), len2, len - 1);
9e2896e5
VZ
1027 }
1028 }
1029
17a6a2e0 1030 return true;
4676948b 1031#else
17a6a2e0 1032 return false;
4676948b 1033#endif
9e2896e5
VZ
1034}
1035
8b85d24e
VZ
1036void wxFileDataObject::AddFile(const wxString& file)
1037{
1038 // just add file to filenames array
1039 // all useful data (such as DROPFILES struct) will be
1040 // created later as necessary
1041 m_filenames.Add(file);
1042}
1043
1044size_t wxFileDataObject::GetDataSize() const
1045{
4676948b 1046#ifndef __WXWINCE__
8b85d24e
VZ
1047 // size returned will be the size of the DROPFILES structure,
1048 // plus the list of filesnames (null byte separated), plus
1049 // a double null at the end
1050
1051 // if no filenames in list, size is 0
dd10a646
VZ
1052 if ( m_filenames.GetCount() == 0 )
1053 return 0;
8b85d24e
VZ
1054
1055 // inital size of DROPFILES struct + null byte
b51320ce 1056 size_t sz = sizeof(DROPFILES) + (1 * sizeof(wxChar));
8b85d24e 1057
dd10a646
VZ
1058 size_t count = m_filenames.GetCount();
1059 for ( size_t i = 0; i < count; i++ )
8b85d24e
VZ
1060 {
1061 // add filename length plus null byte
b51320ce 1062 sz += (m_filenames[i].Len() + 1) * sizeof(wxChar);
8b85d24e 1063 }
dd10a646 1064
8b85d24e 1065 return sz;
4676948b
JS
1066#else
1067 return 0;
1068#endif
8b85d24e
VZ
1069}
1070
0c0d1521 1071bool wxFileDataObject::GetDataHere(void *WXUNUSED_IN_WINCE(pData)) const
8b85d24e 1072{
4676948b 1073#ifndef __WXWINCE__
8b85d24e
VZ
1074 // pData points to an externally allocated memory block
1075 // created using the size returned by GetDataSize()
1076
1077 // if pData is NULL, or there are no files, return
dd10a646 1078 if ( !pData || m_filenames.GetCount() == 0 )
17a6a2e0 1079 return false;
8b85d24e
VZ
1080
1081 // convert data pointer to a DROPFILES struct pointer
1082 LPDROPFILES pDrop = (LPDROPFILES) pData;
1083
1084 // initialize DROPFILES struct
1085 pDrop->pFiles = sizeof(DROPFILES);
dd10a646
VZ
1086 pDrop->fNC = FALSE; // not non-client coords
1087#if wxUSE_UNICODE
1088 pDrop->fWide = TRUE;
1089#else // ANSI
8b85d24e 1090 pDrop->fWide = FALSE;
dd10a646 1091#endif // Unicode/Ansi
8b85d24e
VZ
1092
1093 // set start of filenames list (null separated)
51babd09 1094 wxChar *pbuf = (wxChar*) ((BYTE *)pDrop + sizeof(DROPFILES));
8b85d24e 1095
dd10a646
VZ
1096 size_t count = m_filenames.GetCount();
1097 for (size_t i = 0; i < count; i++ )
8b85d24e
VZ
1098 {
1099 // copy filename to pbuf and add null terminator
1100 size_t len = m_filenames[i].Len();
bf5d9fa4 1101 memcpy(pbuf, m_filenames[i], len*sizeof(wxChar));
8b85d24e 1102 pbuf += len;
dd10a646 1103 *pbuf++ = wxT('\0');
8b85d24e 1104 }
dd10a646 1105
c5639a87
VZ
1106 // add final null terminator
1107 *pbuf = wxT('\0');
8b85d24e 1108
17a6a2e0 1109 return true;
4676948b 1110#else
17a6a2e0 1111 return false;
4676948b 1112#endif
8b85d24e
VZ
1113}
1114
444ad3a7
VZ
1115// ----------------------------------------------------------------------------
1116// wxURLDataObject
1117// ----------------------------------------------------------------------------
1118
4a09bc4e 1119class CFSTR_SHELLURLDataObject : public wxCustomDataObject
e1b435af
MB
1120{
1121public:
1122 CFSTR_SHELLURLDataObject() : wxCustomDataObject(CFSTR_SHELLURL) {}
6f02a879 1123
574c939e 1124 virtual size_t GetBufferOffset( const wxDataFormat& WXUNUSED(format) )
e1b435af
MB
1125 {
1126 return 0;
1127 }
1128
1129 virtual const void* GetSizeFromBuffer( const void* buffer, size_t* size,
574c939e 1130 const wxDataFormat& WXUNUSED(format) )
e1b435af
MB
1131 {
1132 // CFSTR_SHELLURL is _always_ ANSI text
1133 *size = strlen( (const char*)buffer );
1134
1135 return buffer;
1136 }
1137
574c939e
KB
1138 virtual void* SetSizeInBuffer( void* buffer, size_t WXUNUSED(size),
1139 const wxDataFormat& WXUNUSED(format) )
e1b435af
MB
1140 {
1141 return buffer;
1142 }
4a09bc4e 1143
e1b435af
MB
1144#if wxUSE_UNICODE
1145 virtual bool GetDataHere( void* buffer ) const
1146 {
1147 // CFSTR_SHELLURL is _always_ ANSI!
1148 wxCharBuffer char_buffer( GetDataSize() );
1149 wxCustomDataObject::GetDataHere( (void*)char_buffer.data() );
2b5f62a0 1150 wxString unicode_buffer( char_buffer, wxConvLibc );
e1b435af
MB
1151 memcpy( buffer, unicode_buffer.c_str(),
1152 ( unicode_buffer.length() + 1 ) * sizeof(wxChar) );
1153
17a6a2e0 1154 return true;
e1b435af 1155 }
7dbfc030
JS
1156 virtual bool GetDataHere(const wxDataFormat& WXUNUSED(format),
1157 void *buf) const
1158 { return GetDataHere(buf); }
e1b435af 1159#endif
2eb10e2a
VZ
1160
1161 DECLARE_NO_COPY_CLASS(CFSTR_SHELLURLDataObject)
e1b435af
MB
1162};
1163
4a09bc4e
RD
1164
1165
444ad3a7
VZ
1166wxURLDataObject::wxURLDataObject()
1167{
1168 // we support CF_TEXT and CFSTR_SHELLURL formats which are basicly the same
e1b435af 1169 // but it seems that some browsers only provide one of them so we have to
444ad3a7 1170 // support both
444ad3a7 1171 Add(new wxTextDataObject);
e6d318c2 1172 Add(new CFSTR_SHELLURLDataObject());
444ad3a7
VZ
1173
1174 // we don't have any data yet
1175 m_dataObjectLast = NULL;
1176}
1177
1178bool wxURLDataObject::SetData(const wxDataFormat& format,
1179 size_t len,
1180 const void *buf)
1181{
1182 m_dataObjectLast = GetObject(format);
1183
1184 wxCHECK_MSG( m_dataObjectLast, FALSE,
1185 wxT("unsupported format in wxURLDataObject"));
1186
1187 return m_dataObjectLast->SetData(len, buf);
1188}
1189
1190wxString wxURLDataObject::GetURL() const
1191{
1192 wxString url;
1193 wxCHECK_MSG( m_dataObjectLast, url, _T("no data in wxURLDataObject") );
1194
1195 size_t len = m_dataObjectLast->GetDataSize();
1196
de564874 1197 m_dataObjectLast->GetDataHere(wxStringBuffer(url, len));
444ad3a7
VZ
1198
1199 return url;
1200}
1201
e6d318c2
RD
1202void wxURLDataObject::SetURL(const wxString& url)
1203{
4a09bc4e
RD
1204 SetData(wxDataFormat(wxUSE_UNICODE ? wxDF_UNICODETEXT : wxDF_TEXT),
1205 url.Length()+1, url.c_str());
1206
1207 // CFSTR_SHELLURL is always supposed to be ANSI...
1208 wxWX2MBbuf urlA = (wxWX2MBbuf)url.mbc_str();
1209 size_t len = strlen(urlA);
1210 SetData(wxDataFormat(CFSTR_SHELLURL), len+1, (const char*)urlA);
e6d318c2
RD
1211}
1212
269a5a34
VZ
1213// ----------------------------------------------------------------------------
1214// private functions
1215// ----------------------------------------------------------------------------
8e193f38
VZ
1216
1217#ifdef __WXDEBUG__
1218
d59ceba5
VZ
1219static const wxChar *GetTymedName(DWORD tymed)
1220{
1221 static wxChar s_szBuf[128];
1222 switch ( tymed ) {
1223 case TYMED_HGLOBAL: return wxT("TYMED_HGLOBAL");
1224 case TYMED_FILE: return wxT("TYMED_FILE");
1225 case TYMED_ISTREAM: return wxT("TYMED_ISTREAM");
1226 case TYMED_ISTORAGE: return wxT("TYMED_ISTORAGE");
1227 case TYMED_GDI: return wxT("TYMED_GDI");
1228 case TYMED_MFPICT: return wxT("TYMED_MFPICT");
1229 case TYMED_ENHMF: return wxT("TYMED_ENHMF");
1230 default:
dfd2e675 1231 wxSprintf(s_szBuf, wxT("type of media format %ld (unknown)"), tymed);
d59ceba5
VZ
1232 return s_szBuf;
1233 }
269a5a34 1234}
5260b1c5 1235
8e193f38 1236#endif // Debug
2845ddc2 1237
21709999 1238#else // not using OLE at all
9205cb3f 1239
21709999
JS
1240// ----------------------------------------------------------------------------
1241// wxDataObject
1242// ----------------------------------------------------------------------------
1243
461dae94
VZ
1244#if wxUSE_DATAOBJ
1245
21709999
JS
1246wxDataObject::wxDataObject()
1247{
1248}
1249
1250wxDataObject::~wxDataObject()
1251{
1252}
1253
1254void wxDataObject::SetAutoDelete()
1255{
1256}
1257
bd52bee1 1258#ifdef __WXDEBUG__
9205cb3f 1259const wxChar *wxDataObject::GetFormatName(wxDataFormat WXUNUSED(format))
21709999
JS
1260{
1261 return NULL;
1262}
9205cb3f 1263#endif // __WXDEBUG__
21709999 1264
9205cb3f
VZ
1265#endif // wxUSE_DATAOBJ
1266
1267#endif // wxUSE_OLE/!wxUSE_OLE
5260b1c5 1268
461dae94 1269