1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: os2/dataobj.cpp
3 // Purpose: implementation of wx[I]DataObject class
4 // Author: David Webster
8 // Copyright: (c) 1999 David Webster
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"
33 #include "wx/dataobj.h"
34 #include "wx/mstream.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
45 static const wxChar
*GetTymedName(DWORD tymed
);
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxString
wxDataFormat::GetId() const
57 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
64 } // end of wxDataFormat::GetId()
66 void wxDataFormat::SetId (
70 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
73 } // end of wxDataFormat::SetId
78 CIDataObject(wxDataObject
* pDataObject
);
82 // Operations on the DRAGITEM struct
84 bool GetData( const wxDataFormat
& rFormat
88 void GetDataHere( const wxDataFormat
& rFormat
92 void QueryGetData(const wxDataFormat
& rFormat
);
93 void SetData( const wxDataFormat
& rFormat
97 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
99 }; // end of CLASS CIDataObject
101 bool CIDataObject::GetData (
102 const wxDataFormat
& rFormat
107 QueryGetData(rFormat
);
108 if (rFormat
.GetType() == wxDF_INVALID
)
111 ULONG ulSize
= m_pDataObject
->GetDataSize(rFormat
);
116 // It probably means that the method is just not implemented
120 if (rFormat
.GetType() == wxDF_PRIVATE
)
123 // For custom formats, put the size with the data - alloc the
126 ulSize
+= sizeof(ULONG
);
129 if (ulSize
> ulLen
) // not enough room to copy
140 } // end of CIDataObject::GetData
142 void CIDataObject::GetDataHere(
143 const wxDataFormat
& rFormat
145 , ULONG
WXUNUSED(ulLen
)
148 m_pDataObject
->GetDataHere( rFormat
151 } // end of CIDataObject::GetDataHere
153 void CIDataObject::QueryGetData (
154 const wxDataFormat
& rFormat
157 m_pDataObject
->IsSupportedFormat(rFormat
);
158 } // end of CIDataObject::QueryGetData
160 void CIDataObject::SetData (
161 const wxDataFormat
& rFormat
167 switch (rFormat
.GetType())
173 ulSize
= strlen((const char *)pzBuffer
);
176 case wxDF_UNICODETEXT
:
177 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
182 case wxDF_ENHMETAFILE
:
185 ulSize
= 0; // pass via a handle
200 size_t* p
= (size_t *)pzBuffer
;
206 m_pDataObject
->SetData( rFormat
210 } // end of CIDataObject::SetData
212 //-------------------------------------------------------------------------
214 //-------------------------------------------------------------------------
216 wxDataObject::wxDataObject ()
218 m_pDataObject
= new DRAGITEM
;
219 } // end of wxDataObject::wxDataObject
221 wxDataObject::~wxDataObject ()
223 delete m_pDataObject
;
224 } // end of wxDataObject::~wxDataObject
226 // ----------------------------------------------------------------------------
228 // ----------------------------------------------------------------------------
230 bool wxFileDataObject::GetDataHere(
236 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
238 sFilenames
+= m_filenames
[i
];
239 sFilenames
+= (wxChar
)0;
242 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
246 size_t wxFileDataObject::GetDataSize() const
250 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
252 nRes
+= m_filenames
[i
].Len();
259 bool wxFileDataObject::SetData(
260 size_t WXUNUSED(nSize
)
266 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
273 void wxFileDataObject::AddFile(
274 const wxString
& rFilename
277 m_filenames
.Add(rFilename
);
280 // ----------------------------------------------------------------------------
281 // wxBitmapDataObject
282 // ----------------------------------------------------------------------------
284 wxBitmapDataObject::wxBitmapDataObject()
289 wxBitmapDataObject::wxBitmapDataObject(
290 const wxBitmap
& rBitmap
292 : wxBitmapDataObjectBase(rBitmap
)
299 wxBitmapDataObject::~wxBitmapDataObject()
304 void wxBitmapDataObject::SetBitmap(
305 const wxBitmap
& rBitmap
309 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
313 bool wxBitmapDataObject::GetDataHere(
319 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
322 memcpy(pBuf
, m_pngData
, m_pngSize
);
326 bool wxBitmapDataObject::SetData(
333 m_pngData
= malloc(m_pngSize
);
335 memcpy(m_pngData
, pBuf
, m_pngSize
);
338 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
340 wxPNGHandler vHandler
;
342 if (!vHandler
.LoadFile(&vImage
, vMstream
))
347 m_bitmap
= wxBitmap(vImage
);
348 #endif //wxUSE_STREAMS
350 return m_bitmap
.Ok();
353 void wxBitmapDataObject::DoConvertToPng()
359 wxImage vImage
= m_bitmap
.ConvertToImage();
360 wxPNGHandler vHandler
;
361 wxCountingOutputStream vCount
;
363 vHandler
.SaveFile(&vImage
, vCount
);
365 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
366 m_pngData
= malloc(m_pngSize
);
368 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
370 vHandler
.SaveFile(&vImage
, vMstream
);