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