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 licence
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
);
177 case wxDF_UNICODETEXT
:
178 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
184 case wxDF_ENHMETAFILE
:
187 ulSize
= 0; // pass via a handle
202 size_t* p
= (size_t *)pzBuffer
;
208 m_pDataObject
->SetData( rFormat
212 } // end of CIDataObject::SetData
214 //-------------------------------------------------------------------------
216 //-------------------------------------------------------------------------
218 wxDataObject::wxDataObject ()
220 m_pDataObject
= new DRAGITEM
;
221 } // end of wxDataObject::wxDataObject
223 wxDataObject::~wxDataObject ()
225 delete m_pDataObject
;
226 } // end of wxDataObject::~wxDataObject
228 // ----------------------------------------------------------------------------
230 // ----------------------------------------------------------------------------
232 bool wxFileDataObject::GetDataHere(
238 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
240 sFilenames
+= m_filenames
[i
];
241 sFilenames
+= (wxChar
)0;
244 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
248 size_t wxFileDataObject::GetDataSize() const
252 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
254 nRes
+= m_filenames
[i
].Len();
261 bool wxFileDataObject::SetData(
262 size_t WXUNUSED(nSize
)
268 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
275 void wxFileDataObject::AddFile(
276 const wxString
& rFilename
279 m_filenames
.Add(rFilename
);
282 // ----------------------------------------------------------------------------
283 // wxBitmapDataObject
284 // ----------------------------------------------------------------------------
286 wxBitmapDataObject::wxBitmapDataObject()
291 wxBitmapDataObject::wxBitmapDataObject(
292 const wxBitmap
& rBitmap
294 : wxBitmapDataObjectBase(rBitmap
)
301 wxBitmapDataObject::~wxBitmapDataObject()
306 void wxBitmapDataObject::SetBitmap(
307 const wxBitmap
& rBitmap
311 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
315 bool wxBitmapDataObject::GetDataHere(
321 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
324 memcpy(pBuf
, m_pngData
, m_pngSize
);
328 bool wxBitmapDataObject::SetData(
335 m_pngData
= malloc(m_pngSize
);
337 memcpy(m_pngData
, pBuf
, m_pngSize
);
340 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
342 wxPNGHandler vHandler
;
344 if (!vHandler
.LoadFile(&vImage
, vMstream
))
349 m_bitmap
= wxBitmap(vImage
);
350 #endif //wxUSE_STREAMS
352 return m_bitmap
.Ok();
355 void wxBitmapDataObject::DoConvertToPng()
361 wxImage vImage
= m_bitmap
.ConvertToImage();
362 wxPNGHandler vHandler
;
363 wxCountingOutputStream vCount
;
365 vHandler
.SaveFile(&vImage
, vCount
);
367 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
368 m_pngData
= malloc(m_pngSize
);
370 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
372 vHandler
.SaveFile(&vImage
, vMstream
);