+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject supports CF_DIB format
+// ----------------------------------------------------------------------------
+
+size_t wxBitmapDataObject::GetDataSize() const
+{
+ return wxConvertBitmapToDIB(NULL, GetBitmap());
+}
+
+bool wxBitmapDataObject::GetDataHere(void *buf) const
+{
+ return wxConvertBitmapToDIB((LPBITMAPINFO)buf, GetBitmap()) != 0;
+}
+
+bool wxBitmapDataObject::SetData(size_t WXUNUSED(len), const void *buf)
+{
+ wxBitmap bitmap(wxConvertDIBToBitmap((const LPBITMAPINFO)buf));
+
+ if ( !bitmap.Ok() ) {
+ wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
+
+ return FALSE;
+ }
+
+ SetBitmap(bitmap);
+
+ return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject2 supports CF_BITMAP format
+// ----------------------------------------------------------------------------
+
+// the bitmaps aren't passed by value as other types of data (i.e. by copying
+// the data into a global memory chunk and passing it to the clipboard or
+// another application or whatever), but by handle, so these generic functions
+// don't make much sense to them.
+
+size_t wxBitmapDataObject2::GetDataSize() const
+{
+ return 0;
+}
+
+bool wxBitmapDataObject2::GetDataHere(void *pBuf) const
+{
+ // we put a bitmap handle into pBuf
+ *(WXHBITMAP *)pBuf = GetBitmap().GetHBITMAP();
+
+ return TRUE;
+}
+
+bool wxBitmapDataObject2::SetData(size_t WXUNUSED(len), const void *pBuf)
+{
+ HBITMAP hbmp = *(HBITMAP *)pBuf;
+
+ BITMAP bmp;
+ if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) )
+ {
+ wxLogLastError(wxT("GetObject(HBITMAP)"));
+ }
+
+ wxBitmap bitmap(bmp.bmWidth, bmp.bmHeight, bmp.bmPlanes);
+ bitmap.SetHBITMAP((WXHBITMAP)hbmp);
+
+ if ( !bitmap.Ok() ) {
+ wxFAIL_MSG(wxT("pasting/dropping invalid bitmap"));
+
+ return FALSE;
+ }
+
+ SetBitmap(bitmap);
+
+ return TRUE;
+}
+
+#if 0
+
+size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
+{
+ if ( format.GetFormatId() == CF_DIB )
+ {
+ // create the DIB
+ ScreenHDC hdc;
+
+ // shouldn't be selected into a DC or GetDIBits() would fail
+ wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
+ wxT("can't copy bitmap selected into wxMemoryDC") );
+
+ // first get the info
+ BITMAPINFO bi;
+ if ( !GetDIBits(hdc, (HBITMAP)m_bitmap.GetHBITMAP(), 0, 0,
+ NULL, &bi, DIB_RGB_COLORS) )
+ {
+ wxLogLastError(wxT("GetDIBits(NULL)"));
+
+ return 0;
+ }
+
+ return sizeof(BITMAPINFO) + bi.bmiHeader.biSizeImage;
+ }
+ else // CF_BITMAP
+ {
+ // no data to copy - we don't pass HBITMAP via global memory
+ return 0;
+ }
+}
+
+bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format,
+ void *pBuf) const
+{
+ wxASSERT_MSG( m_bitmap.Ok(), wxT("copying invalid bitmap") );
+
+ HBITMAP hbmp = (HBITMAP)m_bitmap.GetHBITMAP();
+ if ( format.GetFormatId() == CF_DIB )
+ {
+ // create the DIB
+ ScreenHDC hdc;
+
+ // shouldn't be selected into a DC or GetDIBits() would fail
+ wxASSERT_MSG( !m_bitmap.GetSelectedInto(),
+ wxT("can't copy bitmap selected into wxMemoryDC") );
+
+ // first get the info
+ BITMAPINFO *pbi = (BITMAPINFO *)pBuf;
+ if ( !GetDIBits(hdc, hbmp, 0, 0, NULL, pbi, DIB_RGB_COLORS) )
+ {
+ wxLogLastError(wxT("GetDIBits(NULL)"));
+
+ return 0;
+ }
+
+ // and now copy the bits
+ if ( !GetDIBits(hdc, hbmp, 0, pbi->bmiHeader.biHeight, pbi + 1,
+ pbi, DIB_RGB_COLORS) )
+ {
+ wxLogLastError(wxT("GetDIBits"));
+
+ return FALSE;
+ }
+ }
+ else // CF_BITMAP
+ {
+ // we put a bitmap handle into pBuf
+ *(HBITMAP *)pBuf = hbmp;
+ }
+
+ return TRUE;
+}
+
+bool wxBitmapDataObject::SetData(const wxDataFormat& format,
+ size_t size, const void *pBuf)
+{
+ HBITMAP hbmp;
+ if ( format.GetFormatId() == CF_DIB )
+ {
+ // here we get BITMAPINFO struct followed by the actual bitmap bits and
+ // BITMAPINFO starts with BITMAPINFOHEADER followed by colour info
+ ScreenHDC hdc;
+
+ BITMAPINFO *pbmi = (BITMAPINFO *)pBuf;
+ BITMAPINFOHEADER *pbmih = &pbmi->bmiHeader;
+ hbmp = CreateDIBitmap(hdc, pbmih, CBM_INIT,
+ pbmi + 1, pbmi, DIB_RGB_COLORS);
+ if ( !hbmp )
+ {
+ wxLogLastError(wxT("CreateDIBitmap"));
+ }
+
+ m_bitmap.SetWidth(pbmih->biWidth);
+ m_bitmap.SetHeight(pbmih->biHeight);
+ }
+ else // CF_BITMAP
+ {
+ // it's easy with bitmaps: we pass them by handle
+ hbmp = *(HBITMAP *)pBuf;
+
+ BITMAP bmp;
+ if ( !GetObject(hbmp, sizeof(BITMAP), &bmp) )
+ {
+ wxLogLastError(wxT("GetObject(HBITMAP)"));
+ }
+
+ m_bitmap.SetWidth(bmp.bmWidth);
+ m_bitmap.SetHeight(bmp.bmHeight);
+ m_bitmap.SetDepth(bmp.bmPlanes);
+ }
+
+ m_bitmap.SetHBITMAP((WXHBITMAP)hbmp);
+
+ wxASSERT_MSG( m_bitmap.Ok(), wxT("pasting invalid bitmap") );
+
+ return TRUE;