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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
31 #include "wx/dataobj.h"
32 #include "wx/mstream.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxString
wxDataFormat::GetId() const
51 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
58 } // end of wxDataFormat::GetId()
60 void wxDataFormat::SetId (
64 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
67 } // end of wxDataFormat::SetId
72 CIDataObject(wxDataObject
* pDataObject
);
76 // Operations on the DRAGITEM struct
78 bool GetData( const wxDataFormat
& rFormat
82 void GetDataHere( const wxDataFormat
& rFormat
86 void QueryGetData(const wxDataFormat
& rFormat
);
87 void SetData( const wxDataFormat
& rFormat
91 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
93 }; // end of CLASS CIDataObject
95 bool CIDataObject::GetData ( const wxDataFormat
& rFormat
,
99 QueryGetData(rFormat
);
100 if (rFormat
.GetType() == wxDF_INVALID
)
103 ULONG ulSize
= m_pDataObject
->GetDataSize(rFormat
);
108 // It probably means that the method is just not implemented
112 if (rFormat
.GetType() == wxDF_PRIVATE
)
115 // For custom formats, put the size with the data - alloc the
118 ulSize
+= sizeof(ULONG
);
121 if (ulSize
> ulLen
) // not enough room to copy
132 } // end of CIDataObject::GetData
134 void CIDataObject::GetDataHere(
135 const wxDataFormat
& rFormat
137 , ULONG
WXUNUSED(ulLen
)
140 m_pDataObject
->GetDataHere( rFormat
143 } // end of CIDataObject::GetDataHere
145 void CIDataObject::QueryGetData (
146 const wxDataFormat
& rFormat
149 m_pDataObject
->IsSupportedFormat(rFormat
);
150 } // end of CIDataObject::QueryGetData
152 void CIDataObject::SetData (
153 const wxDataFormat
& rFormat
159 switch (rFormat
.GetType())
165 ulSize
= strlen((const char *)pzBuffer
);
169 case wxDF_UNICODETEXT
:
170 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
176 case wxDF_ENHMETAFILE
:
179 ulSize
= 0; // pass via a handle
194 size_t* p
= (size_t *)pzBuffer
;
200 m_pDataObject
->SetData( rFormat
204 } // end of CIDataObject::SetData
206 //-------------------------------------------------------------------------
208 //-------------------------------------------------------------------------
210 wxDataObject::wxDataObject ()
212 m_pDataObject
= new DRAGITEM
;
213 } // end of wxDataObject::wxDataObject
215 wxDataObject::~wxDataObject ()
217 delete m_pDataObject
;
218 } // end of wxDataObject::~wxDataObject
220 // ----------------------------------------------------------------------------
222 // ----------------------------------------------------------------------------
224 bool wxFileDataObject::GetDataHere( void* pBuf
) const
228 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
230 sFilenames
+= m_filenames
[i
];
231 sFilenames
+= (wxChar
)0;
234 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
238 size_t wxFileDataObject::GetDataSize() const
242 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
244 nRes
+= m_filenames
[i
].Len();
251 bool wxFileDataObject::SetData( size_t WXUNUSED(nSize
),
256 wxString
sFile((const wxChar
*)pBuf
); /* char, not wxChar */
263 void wxFileDataObject::AddFile(
264 const wxString
& rFilename
267 m_filenames
.Add(rFilename
);
270 // ----------------------------------------------------------------------------
271 // wxBitmapDataObject
272 // ----------------------------------------------------------------------------
274 wxBitmapDataObject::wxBitmapDataObject()
279 wxBitmapDataObject::wxBitmapDataObject(
280 const wxBitmap
& rBitmap
282 : wxBitmapDataObjectBase(rBitmap
)
289 wxBitmapDataObject::~wxBitmapDataObject()
294 void wxBitmapDataObject::SetBitmap( const wxBitmap
& rBitmap
)
297 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
301 bool wxBitmapDataObject::GetDataHere( void* pBuf
) const
305 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
308 memcpy(pBuf
, m_pngData
, m_pngSize
);
312 bool wxBitmapDataObject::SetData(
319 m_pngData
= malloc(m_pngSize
);
321 memcpy(m_pngData
, pBuf
, m_pngSize
);
324 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
326 wxPNGHandler vHandler
;
328 if (!vHandler
.LoadFile(&vImage
, vMstream
))
333 m_bitmap
= wxBitmap(vImage
);
334 #endif //wxUSE_STREAMS
336 return m_bitmap
.Ok();
339 void wxBitmapDataObject::DoConvertToPng()
345 wxImage vImage
= m_bitmap
.ConvertToImage();
346 wxPNGHandler vHandler
;
347 wxCountingOutputStream vCount
;
349 vHandler
.SaveFile(&vImage
, vCount
);
351 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
352 m_pngData
= malloc(m_pngSize
);
354 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
356 vHandler
.SaveFile(&vImage
, vMstream
);
360 #endif // wxUSE_DATAOBJ