]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/ole/dataobj.cpp
46cfd66c4b35f2ce6e1f2d690fae43f7a80a8e44
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/dataobj.cpp
3 // Purpose: implementation of wx[I]DataObject class
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr>
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dataobj.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #if defined(__WIN32__) && !defined(__GNUWIN32__) || defined(wxUSE_NORLANDER_HEADERS)
38 #include "wx/dataobj.h"
41 #ifdef wxUSE_NORLANDER_HEADERS
51 #include "wx/msw/ole/oleutils.h"
53 // ----------------------------------------------------------------------------
55 // ----------------------------------------------------------------------------
58 static const wxChar
*GetTymedName(DWORD tymed
);
61 // to be moved into wx/msw/bitmap.h
62 extern size_t wxConvertBitmapToDIB(BITMAPINFO
*pbi
, const wxBitmap
& bitmap
);
63 extern wxBitmap
wxConvertDIBToBitmap(const BITMAPINFO
*bmi
);
65 // ----------------------------------------------------------------------------
66 // wxIEnumFORMATETC interface implementation
67 // ----------------------------------------------------------------------------
69 class wxIEnumFORMATETC
: public IEnumFORMATETC
72 wxIEnumFORMATETC(const wxDataFormat
* formats
, ULONG nCount
);
73 ~wxIEnumFORMATETC() { delete [] m_formats
; }
75 DECLARE_IUNKNOWN_METHODS
;
78 STDMETHODIMP
Next(ULONG celt
, FORMATETC
*rgelt
, ULONG
*pceltFetched
);
79 STDMETHODIMP
Skip(ULONG celt
);
81 STDMETHODIMP
Clone(IEnumFORMATETC
**ppenum
);
84 CLIPFORMAT
*m_formats
; // formats we can provide data in
85 ULONG m_nCount
, // number of formats we support
86 m_nCurrent
; // current enum position
89 // ----------------------------------------------------------------------------
90 // wxIDataObject implementation of IDataObject interface
91 // ----------------------------------------------------------------------------
93 class wxIDataObject
: public IDataObject
96 wxIDataObject(wxDataObject
*pDataObject
);
99 // normally, wxDataObject controls our lifetime (i.e. we're deleted when it
100 // is), but in some cases, the situation is inversed, that is we delete it
101 // when this object is deleted - setting this flag enables such logic
102 void SetDeleteFlag() { m_mustDelete
= TRUE
; }
104 DECLARE_IUNKNOWN_METHODS
;
107 STDMETHODIMP
GetData(FORMATETC
*pformatetcIn
, STGMEDIUM
*pmedium
);
108 STDMETHODIMP
GetDataHere(FORMATETC
*pformatetc
, STGMEDIUM
*pmedium
);
109 STDMETHODIMP
QueryGetData(FORMATETC
*pformatetc
);
110 STDMETHODIMP
GetCanonicalFormatEtc(FORMATETC
*In
, FORMATETC
*pOut
);
111 STDMETHODIMP
SetData(FORMATETC
*pfetc
, STGMEDIUM
*pmedium
, BOOL fRelease
);
112 STDMETHODIMP
EnumFormatEtc(DWORD dwDirection
, IEnumFORMATETC
**ppenumFEtc
);
113 STDMETHODIMP
DAdvise(FORMATETC
*pfetc
, DWORD ad
, IAdviseSink
*p
, DWORD
*pdw
);
114 STDMETHODIMP
DUnadvise(DWORD dwConnection
);
115 STDMETHODIMP
EnumDAdvise(IEnumSTATDATA
**ppenumAdvise
);
118 wxDataObject
*m_pDataObject
; // pointer to C++ class we belong to
123 // ----------------------------------------------------------------------------
124 // small helper class for getting screen DC (we're working with bitmaps and
126 // ----------------------------------------------------------------------------
131 ScreenHDC() { m_hdc
= GetDC(NULL
); }
132 ~ScreenHDC() { ReleaseDC(NULL
, m_hdc
); }
133 operator HDC() const { return m_hdc
; }
139 // ============================================================================
141 // ============================================================================
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
147 void wxDataFormat::SetId(const wxChar
*format
)
149 m_format
= ::RegisterClipboardFormat(format
);
152 wxLogError(_("Couldn't register clipboard format '%s'."), format
);
156 wxString
wxDataFormat::GetId() const
158 static const int max
= 256;
162 wxCHECK_MSG( !IsStandard(), s
,
163 wxT("name of predefined format cannot be retrieved") );
165 int len
= ::GetClipboardFormatName(m_format
, s
.GetWriteBuf(max
), max
);
170 wxLogError(_("The clipboard format '%d' doesn't exist."), m_format
);
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 BEGIN_IID_TABLE(wxIEnumFORMATETC
)
182 ADD_IID(EnumFORMATETC
)
185 IMPLEMENT_IUNKNOWN_METHODS(wxIEnumFORMATETC
)
187 wxIEnumFORMATETC::wxIEnumFORMATETC(const wxDataFormat
*formats
, ULONG nCount
)
192 m_formats
= new CLIPFORMAT
[nCount
];
193 for ( ULONG n
= 0; n
< nCount
; n
++ ) {
194 m_formats
[n
] = formats
[n
].GetFormatId();
198 STDMETHODIMP
wxIEnumFORMATETC::Next(ULONG celt
,
202 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumFORMATETC::Next"));
205 // we only return 1 element at a time - mainly because I'm too lazy to
206 // implement something which you're never asked for anyhow
210 if ( m_nCurrent
< m_nCount
) {
212 format
.cfFormat
= m_formats
[m_nCurrent
++];
214 format
.dwAspect
= DVASPECT_CONTENT
;
216 format
.tymed
= TYMED_HGLOBAL
;
227 STDMETHODIMP
wxIEnumFORMATETC::Skip(ULONG celt
)
229 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumFORMATETC::Skip"));
232 if ( m_nCurrent
< m_nCount
)
235 // no, can't skip this many elements
241 STDMETHODIMP
wxIEnumFORMATETC::Reset()
243 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumFORMATETC::Reset"));
250 STDMETHODIMP
wxIEnumFORMATETC::Clone(IEnumFORMATETC
**ppenum
)
252 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIEnumFORMATETC::Clone"));
254 // unfortunately, we can't reuse the code in ctor - types are different
255 wxIEnumFORMATETC
*pNew
= new wxIEnumFORMATETC(NULL
, 0);
256 pNew
->m_nCount
= m_nCount
;
257 pNew
->m_formats
= new CLIPFORMAT
[m_nCount
];
258 for ( ULONG n
= 0; n
< m_nCount
; n
++ ) {
259 pNew
->m_formats
[n
] = m_formats
[n
];
267 // ----------------------------------------------------------------------------
269 // ----------------------------------------------------------------------------
271 BEGIN_IID_TABLE(wxIDataObject
)
276 IMPLEMENT_IUNKNOWN_METHODS(wxIDataObject
)
278 wxIDataObject::wxIDataObject(wxDataObject
*pDataObject
)
281 m_pDataObject
= pDataObject
;
282 m_mustDelete
= FALSE
;
285 wxIDataObject::~wxIDataObject()
289 delete m_pDataObject
;
293 // get data functions
294 STDMETHODIMP
wxIDataObject::GetData(FORMATETC
*pformatetcIn
, STGMEDIUM
*pmedium
)
296 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::GetData"));
298 // is data is in our format?
299 HRESULT hr
= QueryGetData(pformatetcIn
);
303 // for the bitmaps and metafiles we use the handles instead of global memory
305 wxDataFormat format
= (wxDataFormatId
)pformatetcIn
->cfFormat
;
310 pmedium
->tymed
= TYMED_GDI
;
314 pmedium
->tymed
= TYMED_MFPICT
;
319 size_t size
= m_pDataObject
->GetDataSize(format
);
321 // it probably means that the method is just not implemented
322 wxLogDebug(wxT("Invalid data size - can't be 0"));
324 return DV_E_FORMATETC
;
327 if ( !format
.IsStandard() ) {
328 // for custom formats, put the size with the data - alloc the
330 size
+= sizeof(size_t);
333 HGLOBAL hGlobal
= GlobalAlloc(GMEM_MOVEABLE
| GMEM_SHARE
, size
);
334 if ( hGlobal
== NULL
) {
335 wxLogLastError("GlobalAlloc");
336 return E_OUTOFMEMORY
;
340 pmedium
->tymed
= TYMED_HGLOBAL
;
341 pmedium
->hGlobal
= hGlobal
;
344 pmedium
->pUnkForRelease
= NULL
;
347 hr
= GetDataHere(pformatetcIn
, pmedium
);
349 // free resources we allocated
350 if ( pmedium
->tymed
== TYMED_HGLOBAL
) {
351 GlobalFree(pmedium
->hGlobal
);
360 STDMETHODIMP
wxIDataObject::GetDataHere(FORMATETC
*pformatetc
,
363 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::GetDataHere"));
365 // put data in caller provided medium
366 switch ( pmedium
->tymed
)
369 if ( !m_pDataObject
->GetDataHere(wxDF_BITMAP
, &pmedium
->hBitmap
) )
374 // this should be copied on bitmaps - but I don't have time for
376 wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject"));
382 HGLOBAL hGlobal
= pmedium
->hGlobal
;
383 void *pBuf
= GlobalLock(hGlobal
);
384 if ( pBuf
== NULL
) {
385 wxLogLastError(wxT("GlobalLock"));
386 return E_OUTOFMEMORY
;
389 if ( !wxDataFormat(pformatetc
->cfFormat
).IsStandard() ) {
390 // for custom formats, put the size with the data
391 size_t *p
= (size_t *)pBuf
;
392 *p
++ = GlobalSize(hGlobal
);
396 wxDataFormat format
= pformatetc
->cfFormat
;
397 if ( !m_pDataObject
->GetDataHere(format
, pBuf
) )
400 GlobalUnlock(hGlobal
);
411 // set data functions
412 STDMETHODIMP
wxIDataObject::SetData(FORMATETC
*pformatetc
,
416 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::SetData"));
418 switch ( pmedium
->tymed
)
421 m_pDataObject
->SetData(wxDF_BITMAP
, 0, &pmedium
->hBitmap
);
425 // this should be copied on bitmaps - but I don't have time for
427 wxFAIL_MSG(wxT("TODO - no support for metafiles in wxDataObject"));
433 void *pBuf
= GlobalLock(pmedium
->hGlobal
);
434 if ( pBuf
== NULL
) {
435 wxLogLastError("GlobalLock");
437 return E_OUTOFMEMORY
;
440 // we've got a problem with SetData() here because the base
441 // class version requires the size parameter which we don't
442 // have anywhere in OLE data transfer - so we need to
443 // synthetise it for known formats and we suppose that all data
444 // in custom formats starts with a DWORD containing the size
446 switch ( pformatetc
->cfFormat
)
450 size
= strlen((const char *)pBuf
);
454 size
= wcslen((const wchar_t *)pBuf
);
459 // these formats don't use size at all, anyhow (but
460 // pass data by handle, which is always a single DWORD)
466 // we suppose that the size precedes the data
467 size_t *p
= (size_t *)pBuf
;
473 wxDataFormat format
= pformatetc
->cfFormat
;
474 bool ok
= m_pDataObject
->SetData(format
, size
, pBuf
);
476 GlobalUnlock(pmedium
->hGlobal
);
489 // we own the medium, so we must release it - but do *not* free the
490 // bitmap handle fi we have it because we have copied it elsewhere
491 if ( pmedium
->tymed
== TYMED_GDI
)
493 pmedium
->hBitmap
= 0;
496 ReleaseStgMedium(pmedium
);
502 // information functions
503 STDMETHODIMP
wxIDataObject::QueryGetData(FORMATETC
*pformatetc
)
505 // do we accept data in this format?
506 if ( pformatetc
== NULL
) {
507 wxLogTrace(wxTRACE_OleCalls
,
508 wxT("wxIDataObject::QueryGetData: invalid ptr."));
513 // the only one allowed by current COM implementation
514 if ( pformatetc
->lindex
!= -1 ) {
515 wxLogTrace(wxTRACE_OleCalls
,
516 wxT("wxIDataObject::QueryGetData: bad lindex %d"),
522 // we don't support anything other (THUMBNAIL, ICON, DOCPRINT...)
523 if ( pformatetc
->dwAspect
!= DVASPECT_CONTENT
) {
524 wxLogTrace(wxTRACE_OleCalls
,
525 wxT("wxIDataObject::QueryGetData: bad dwAspect %d"),
526 pformatetc
->dwAspect
);
528 return DV_E_DVASPECT
;
531 // and now check the type of data requested
532 wxDataFormat format
= pformatetc
->cfFormat
;
533 if ( m_pDataObject
->IsSupportedFormat(format
) ) {
535 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::QueryGetData: %s ok"),
536 wxDataObject::GetFormatName(format
));
540 wxLogTrace(wxTRACE_OleCalls
,
541 wxT("wxIDataObject::QueryGetData: %s unsupported"),
542 wxDataObject::GetFormatName(format
));
544 return DV_E_FORMATETC
;
547 // we only transfer data by global memory, except for some particular cases
548 DWORD tymed
= pformatetc
->tymed
;
549 if ( (format
== wxDF_BITMAP
&& !(tymed
& TYMED_GDI
)) &&
550 !(tymed
& TYMED_HGLOBAL
) ) {
551 // it's not what we're waiting for
553 wxLogTrace(wxTRACE_OleCalls
,
554 wxT("wxIDataObject::QueryGetData: %s != %s"),
556 GetTymedName(format
== wxDF_BITMAP
? TYMED_GDI
566 STDMETHODIMP
wxIDataObject::GetCanonicalFormatEtc(FORMATETC
*pFormatetcIn
,
567 FORMATETC
*pFormatetcOut
)
569 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::GetCanonicalFormatEtc"));
571 // TODO we might want something better than this trivial implementation here
572 if ( pFormatetcOut
!= NULL
)
573 pFormatetcOut
->ptd
= NULL
;
575 return DATA_S_SAMEFORMATETC
;
578 STDMETHODIMP
wxIDataObject::EnumFormatEtc(DWORD dwDir
,
579 IEnumFORMATETC
**ppenumFormatEtc
)
581 wxLogTrace(wxTRACE_OleCalls
, wxT("wxIDataObject::EnumFormatEtc"));
583 wxDataObject::Direction dir
= dwDir
== DATADIR_GET
? wxDataObject::Get
586 size_t nFormatCount
= m_pDataObject
->GetFormatCount(dir
);
587 wxDataFormat format
, *formats
;
588 formats
= nFormatCount
== 1 ? &format
: new wxDataFormat
[nFormatCount
];
589 m_pDataObject
->GetAllFormats(formats
, dir
);
591 wxIEnumFORMATETC
*pEnum
= new wxIEnumFORMATETC(formats
, nFormatCount
);
593 *ppenumFormatEtc
= pEnum
;
595 if ( formats
!= &format
) {
602 // ----------------------------------------------------------------------------
603 // advise sink functions (not implemented)
604 // ----------------------------------------------------------------------------
606 STDMETHODIMP
wxIDataObject::DAdvise(FORMATETC
*pformatetc
,
608 IAdviseSink
*pAdvSink
,
609 DWORD
*pdwConnection
)
611 return OLE_E_ADVISENOTSUPPORTED
;
614 STDMETHODIMP
wxIDataObject::DUnadvise(DWORD dwConnection
)
616 return OLE_E_ADVISENOTSUPPORTED
;
619 STDMETHODIMP
wxIDataObject::EnumDAdvise(IEnumSTATDATA
**ppenumAdvise
)
621 return OLE_E_ADVISENOTSUPPORTED
;
624 // ----------------------------------------------------------------------------
626 // ----------------------------------------------------------------------------
628 wxDataObject::wxDataObject()
630 m_pIDataObject
= new wxIDataObject(this);
631 m_pIDataObject
->AddRef();
634 wxDataObject::~wxDataObject()
636 ReleaseInterface(m_pIDataObject
);
639 void wxDataObject::SetAutoDelete()
641 ((wxIDataObject
*)m_pIDataObject
)->SetDeleteFlag();
642 m_pIDataObject
->Release();
644 // so that the dtor doesnt' crash
645 m_pIDataObject
= NULL
;
648 bool wxDataObject::IsSupportedFormat(const wxDataFormat
& format
) const
650 size_t nFormatCount
= GetFormatCount();
651 if ( nFormatCount
== 1 ) {
652 return format
== GetPreferredFormat();
655 wxDataFormat
*formats
= new wxDataFormat
[nFormatCount
];
656 GetAllFormats(formats
);
659 for ( n
= 0; n
< nFormatCount
; n
++ ) {
660 if ( formats
[n
] == format
)
667 return n
< nFormatCount
;
672 const char *wxDataObject::GetFormatName(wxDataFormat format
)
674 // case 'xxx' is not a valid value for switch of enum 'wxDataFormat'
676 #pragma warning(disable:4063)
679 static char s_szBuf
[128];
681 case CF_TEXT
: return "CF_TEXT";
682 case CF_BITMAP
: return "CF_BITMAP";
683 case CF_METAFILEPICT
: return "CF_METAFILEPICT";
684 case CF_SYLK
: return "CF_SYLK";
685 case CF_DIF
: return "CF_DIF";
686 case CF_TIFF
: return "CF_TIFF";
687 case CF_OEMTEXT
: return "CF_OEMTEXT";
688 case CF_DIB
: return "CF_DIB";
689 case CF_PALETTE
: return "CF_PALETTE";
690 case CF_PENDATA
: return "CF_PENDATA";
691 case CF_RIFF
: return "CF_RIFF";
692 case CF_WAVE
: return "CF_WAVE";
693 case CF_UNICODETEXT
: return "CF_UNICODETEXT";
694 case CF_ENHMETAFILE
: return "CF_ENHMETAFILE";
695 case CF_HDROP
: return "CF_HDROP";
696 case CF_LOCALE
: return "CF_LOCALE";
698 sprintf(s_szBuf
, "clipboard format 0x%x (unknown)", format
);
703 #pragma warning(default:4063)
708 // ----------------------------------------------------------------------------
709 // wxBitmapDataObject supports CF_DIB format
710 // ----------------------------------------------------------------------------
712 size_t wxBitmapDataObject::GetDataSize() const
714 return wxConvertBitmapToDIB(NULL
, GetBitmap());
717 bool wxBitmapDataObject::GetDataHere(void *buf
) const
719 return wxConvertBitmapToDIB((BITMAPINFO
*)buf
, GetBitmap()) != 0;
722 bool wxBitmapDataObject::SetData(size_t len
, const void *buf
)
724 wxBitmap
bitmap(wxConvertDIBToBitmap((const BITMAPINFO
*)buf
));
726 if ( !bitmap
.Ok() ) {
727 wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
737 // ----------------------------------------------------------------------------
738 // wxBitmapDataObject2 supports CF_BITMAP format
739 // ----------------------------------------------------------------------------
741 // the bitmaps aren't passed by value as other types of data (i.e. by copying
742 // the data into a global memory chunk and passing it to the clipboard or
743 // another application or whatever), but by handle, so these generic functions
744 // don't make much sense to them.
746 size_t wxBitmapDataObject2::GetDataSize() const
751 bool wxBitmapDataObject2::GetDataHere(void *pBuf
) const
753 // we put a bitmap handle into pBuf
754 *(WXHBITMAP
*)pBuf
= GetBitmap().GetHBITMAP();
759 bool wxBitmapDataObject2::SetData(size_t len
, const void *pBuf
)
761 HBITMAP hbmp
= *(HBITMAP
*)pBuf
;
764 if ( !GetObject(hbmp
, sizeof(BITMAP
), &bmp
) )
766 wxLogLastError("GetObject(HBITMAP)");
769 wxBitmap
bitmap(bmp
.bmWidth
, bmp
.bmHeight
, bmp
.bmPlanes
);
770 bitmap
.SetHBITMAP((WXHBITMAP
)hbmp
);
772 if ( !bitmap
.Ok() ) {
773 wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
785 size_t wxBitmapDataObject::GetDataSize(const wxDataFormat
& format
) const
787 if ( format
.GetFormatId() == CF_DIB
)
792 // shouldn't be selected into a DC or GetDIBits() would fail
793 wxASSERT_MSG( !m_bitmap
.GetSelectedInto(),
794 wxT("can't copy bitmap selected into wxMemoryDC") );
796 // first get the info
798 if ( !GetDIBits(hdc
, (HBITMAP
)m_bitmap
.GetHBITMAP(), 0, 0,
799 NULL
, &bi
, DIB_RGB_COLORS
) )
801 wxLogLastError("GetDIBits(NULL)");
806 return sizeof(BITMAPINFO
) + bi
.bmiHeader
.biSizeImage
;
810 // no data to copy - we don't pass HBITMAP via global memory
815 bool wxBitmapDataObject::GetDataHere(const wxDataFormat
& format
,
818 wxASSERT_MSG( m_bitmap
.Ok(), wxT("copying invalid bitmap") );
820 HBITMAP hbmp
= (HBITMAP
)m_bitmap
.GetHBITMAP();
821 if ( format
.GetFormatId() == CF_DIB
)
826 // shouldn't be selected into a DC or GetDIBits() would fail
827 wxASSERT_MSG( !m_bitmap
.GetSelectedInto(),
828 wxT("can't copy bitmap selected into wxMemoryDC") );
830 // first get the info
831 BITMAPINFO
*pbi
= (BITMAPINFO
*)pBuf
;
832 if ( !GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbi
, DIB_RGB_COLORS
) )
834 wxLogLastError("GetDIBits(NULL)");
839 // and now copy the bits
840 if ( !GetDIBits(hdc
, hbmp
, 0, pbi
->bmiHeader
.biHeight
, pbi
+ 1,
841 pbi
, DIB_RGB_COLORS
) )
843 wxLogLastError("GetDIBits");
850 // we put a bitmap handle into pBuf
851 *(HBITMAP
*)pBuf
= hbmp
;
857 bool wxBitmapDataObject::SetData(const wxDataFormat
& format
,
858 size_t size
, const void *pBuf
)
861 if ( format
.GetFormatId() == CF_DIB
)
863 // here we get BITMAPINFO struct followed by the actual bitmap bits and
864 // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
867 BITMAPINFO
*pbmi
= (BITMAPINFO
*)pBuf
;
868 BITMAPINFOHEADER
*pbmih
= &pbmi
->bmiHeader
;
869 hbmp
= CreateDIBitmap(hdc
, pbmih
, CBM_INIT
,
870 pbmi
+ 1, pbmi
, DIB_RGB_COLORS
);
873 wxLogLastError("CreateDIBitmap");
876 m_bitmap
.SetWidth(pbmih
->biWidth
);
877 m_bitmap
.SetHeight(pbmih
->biHeight
);
881 // it's easy with bitmaps: we pass them by handle
882 hbmp
= *(HBITMAP
*)pBuf
;
885 if ( !GetObject(hbmp
, sizeof(BITMAP
), &bmp
) )
887 wxLogLastError("GetObject(HBITMAP)");
890 m_bitmap
.SetWidth(bmp
.bmWidth
);
891 m_bitmap
.SetHeight(bmp
.bmHeight
);
892 m_bitmap
.SetDepth(bmp
.bmPlanes
);
895 m_bitmap
.SetHBITMAP((WXHBITMAP
)hbmp
);
897 wxASSERT_MSG( m_bitmap
.Ok(), wxT("pasting invalid bitmap") );
904 // ----------------------------------------------------------------------------
906 // ----------------------------------------------------------------------------
908 bool wxFileDataObject::SetData(size_t WXUNUSED(size
), const void *pData
)
912 // the documentation states that the first member of DROPFILES structure is
913 // a "DWORD offset of double NUL terminated file list". What they mean by
914 // this (I wonder if you see it immediately) is that the list starts at
915 // ((char *)&(pDropFiles.pFiles)) + pDropFiles.pFiles. We're also advised
916 // to use DragQueryFile to work with this structure, but not told where and
918 HDROP hdrop
= (HDROP
)pData
; // NB: it works, but I'm not sure about it
920 // get number of files (magic value -1)
921 UINT nFiles
= ::DragQueryFile(hdrop
, (unsigned)-1, NULL
, 0u);
923 // for each file get the length, allocate memory and then get the name
926 for ( n
= 0; n
< nFiles
; n
++ ) {
927 // +1 for terminating NUL
928 len
= ::DragQueryFile(hdrop
, n
, NULL
, 0) + 1;
930 UINT len2
= ::DragQueryFile(hdrop
, n
, str
.GetWriteBuf(len
), len
);
932 m_filenames
.Add(str
);
934 if ( len2
!= len
- 1 ) {
935 wxLogDebug(wxT("In wxFileDropTarget::OnDrop DragQueryFile returned"
936 " %d characters, %d expected."), len2
, len
- 1);
943 // ----------------------------------------------------------------------------
945 // ----------------------------------------------------------------------------
947 // otherwise VC++ would give here:
948 // "local variable 'bi' may be used without having been initialized"
949 // even though in fact it may not
951 #pragma warning(disable:4701)
952 #endif // __VISUALC__
954 size_t wxConvertBitmapToDIB(BITMAPINFO
*pbi
, const wxBitmap
& bitmap
)
956 // shouldn't be selected into a DC or GetDIBits() would fail
957 wxASSERT_MSG( !bitmap
.GetSelectedInto(),
958 wxT("can't copy bitmap selected into wxMemoryDC") );
960 HBITMAP hbmp
= (HBITMAP
)bitmap
.GetHBITMAP();
964 // first get the info
966 if ( !GetDIBits(hdc
, hbmp
, 0, 0, NULL
, pbi
? pbi
: &bi
, DIB_RGB_COLORS
) )
968 wxLogLastError("GetDIBits(NULL)");
975 // we were only asked for size needed for the buffer, not to actually
977 return sizeof(BITMAPINFO
) + bi
.bmiHeader
.biSizeImage
;
980 // and now copy the bits
981 if ( !GetDIBits(hdc
, hbmp
, 0, pbi
->bmiHeader
.biHeight
, pbi
+ 1,
982 pbi
, DIB_RGB_COLORS
) )
984 wxLogLastError("GetDIBits");
989 return sizeof(BITMAPINFO
) + pbi
->bmiHeader
.biSizeImage
;
993 #pragma warning(default:4701)
994 #endif // __VISUALC__
996 wxBitmap
wxConvertDIBToBitmap(const BITMAPINFO
*pbmi
)
998 // here we get BITMAPINFO struct followed by the actual bitmap bits and
999 // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
1000 const BITMAPINFOHEADER
*pbmih
= &pbmi
->bmiHeader
;
1003 HBITMAP hbmp
= CreateDIBitmap(hdc
, pbmih
, CBM_INIT
,
1004 pbmi
+ 1, pbmi
, DIB_RGB_COLORS
);
1007 wxLogLastError("CreateDIBitmap");
1010 wxBitmap
bitmap(pbmih
->biWidth
, pbmih
->biHeight
, pbmih
->biBitCount
);
1011 bitmap
.SetHBITMAP((WXHBITMAP
)hbmp
);
1018 static const wxChar
*GetTymedName(DWORD tymed
)
1020 static wxChar s_szBuf
[128];
1022 case TYMED_HGLOBAL
: return wxT("TYMED_HGLOBAL");
1023 case TYMED_FILE
: return wxT("TYMED_FILE");
1024 case TYMED_ISTREAM
: return wxT("TYMED_ISTREAM");
1025 case TYMED_ISTORAGE
: return wxT("TYMED_ISTORAGE");
1026 case TYMED_GDI
: return wxT("TYMED_GDI");
1027 case TYMED_MFPICT
: return wxT("TYMED_MFPICT");
1028 case TYMED_ENHMF
: return wxT("TYMED_ENHMF");
1030 wxSprintf(s_szBuf
, wxT("type of media format %d (unknown)"), tymed
);
1037 #endif // not using OLE at all