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"
35 #include "wx/dataobj.h"
36 #include "wx/mstream.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxString
wxDataFormat::GetId() const
55 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
62 } // end of wxDataFormat::GetId()
64 void wxDataFormat::SetId (
68 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
71 } // end of wxDataFormat::SetId
76 CIDataObject(wxDataObject
* pDataObject
);
80 // Operations on the DRAGITEM struct
82 bool GetData( const wxDataFormat
& rFormat
86 void GetDataHere( const wxDataFormat
& rFormat
90 void QueryGetData(const wxDataFormat
& rFormat
);
91 void SetData( const wxDataFormat
& rFormat
95 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
97 }; // end of CLASS CIDataObject
99 bool CIDataObject::GetData ( const wxDataFormat
& rFormat
,
103 QueryGetData(rFormat
);
104 if (rFormat
.GetType() == wxDF_INVALID
)
107 ULONG ulSize
= m_pDataObject
->GetDataSize(rFormat
);
112 // It probably means that the method is just not implemented
116 if (rFormat
.GetType() == wxDF_PRIVATE
)
119 // For custom formats, put the size with the data - alloc the
122 ulSize
+= sizeof(ULONG
);
125 if (ulSize
> ulLen
) // not enough room to copy
136 } // end of CIDataObject::GetData
138 void CIDataObject::GetDataHere(
139 const wxDataFormat
& rFormat
141 , ULONG
WXUNUSED(ulLen
)
144 m_pDataObject
->GetDataHere( rFormat
147 } // end of CIDataObject::GetDataHere
149 void CIDataObject::QueryGetData (
150 const wxDataFormat
& rFormat
153 m_pDataObject
->IsSupportedFormat(rFormat
);
154 } // end of CIDataObject::QueryGetData
156 void CIDataObject::SetData (
157 const wxDataFormat
& rFormat
163 switch (rFormat
.GetType())
169 ulSize
= strlen((const char *)pzBuffer
);
173 case wxDF_UNICODETEXT
:
174 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
180 case wxDF_ENHMETAFILE
:
183 ulSize
= 0; // pass via a handle
198 size_t* p
= (size_t *)pzBuffer
;
204 m_pDataObject
->SetData( rFormat
208 } // end of CIDataObject::SetData
210 //-------------------------------------------------------------------------
212 //-------------------------------------------------------------------------
214 wxDataObject::wxDataObject ()
216 m_pDataObject
= new DRAGITEM
;
217 } // end of wxDataObject::wxDataObject
219 wxDataObject::~wxDataObject ()
221 delete m_pDataObject
;
222 } // end of wxDataObject::~wxDataObject
224 // ----------------------------------------------------------------------------
226 // ----------------------------------------------------------------------------
228 bool wxFileDataObject::GetDataHere( void* pBuf
) const
232 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
234 sFilenames
+= m_filenames
[i
];
235 sFilenames
+= (wxChar
)0;
238 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
242 size_t wxFileDataObject::GetDataSize() const
246 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
248 nRes
+= m_filenames
[i
].Len();
255 bool wxFileDataObject::SetData( size_t WXUNUSED(nSize
),
260 wxString
sFile((const wxChar
*)pBuf
); /* char, not wxChar */
267 void wxFileDataObject::AddFile(
268 const wxString
& rFilename
271 m_filenames
.Add(rFilename
);
274 // ----------------------------------------------------------------------------
275 // wxBitmapDataObject
276 // ----------------------------------------------------------------------------
278 wxBitmapDataObject::wxBitmapDataObject()
283 wxBitmapDataObject::wxBitmapDataObject(
284 const wxBitmap
& rBitmap
286 : wxBitmapDataObjectBase(rBitmap
)
293 wxBitmapDataObject::~wxBitmapDataObject()
298 void wxBitmapDataObject::SetBitmap( const wxBitmap
& rBitmap
)
301 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
305 bool wxBitmapDataObject::GetDataHere( void* pBuf
) const
309 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
312 memcpy(pBuf
, m_pngData
, m_pngSize
);
316 bool wxBitmapDataObject::SetData(
323 m_pngData
= malloc(m_pngSize
);
325 memcpy(m_pngData
, pBuf
, m_pngSize
);
328 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
330 wxPNGHandler vHandler
;
332 if (!vHandler
.LoadFile(&vImage
, vMstream
))
337 m_bitmap
= wxBitmap(vImage
);
338 #endif //wxUSE_STREAMS
340 return m_bitmap
.Ok();
343 void wxBitmapDataObject::DoConvertToPng()
349 wxImage vImage
= m_bitmap
.ConvertToImage();
350 wxPNGHandler vHandler
;
351 wxCountingOutputStream vCount
;
353 vHandler
.SaveFile(&vImage
, vCount
);
355 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
356 m_pngData
= malloc(m_pngSize
);
358 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
360 vHandler
.SaveFile(&vImage
, vMstream
);
364 #endif // wxUSE_DATAOBJ