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 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 wxString
wxDataFormat::GetId() const
53 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
60 } // end of wxDataFormat::GetId()
62 void wxDataFormat::SetId (
66 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
69 } // end of wxDataFormat::SetId
74 CIDataObject(wxDataObject
* pDataObject
);
78 // Operations on the DRAGITEM struct
80 bool GetData( const wxDataFormat
& rFormat
84 void GetDataHere( const wxDataFormat
& rFormat
88 void QueryGetData(const wxDataFormat
& rFormat
);
89 void SetData( const wxDataFormat
& rFormat
93 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
95 }; // end of CLASS CIDataObject
97 bool CIDataObject::GetData (
98 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(
234 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
236 sFilenames
+= m_filenames
[i
];
237 sFilenames
+= (wxChar
)0;
240 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
244 size_t wxFileDataObject::GetDataSize() const
248 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
250 nRes
+= m_filenames
[i
].Len();
257 bool wxFileDataObject::SetData(
258 size_t WXUNUSED(nSize
)
264 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
271 void wxFileDataObject::AddFile(
272 const wxString
& rFilename
275 m_filenames
.Add(rFilename
);
278 // ----------------------------------------------------------------------------
279 // wxBitmapDataObject
280 // ----------------------------------------------------------------------------
282 wxBitmapDataObject::wxBitmapDataObject()
287 wxBitmapDataObject::wxBitmapDataObject(
288 const wxBitmap
& rBitmap
290 : wxBitmapDataObjectBase(rBitmap
)
297 wxBitmapDataObject::~wxBitmapDataObject()
302 void wxBitmapDataObject::SetBitmap(
303 const wxBitmap
& rBitmap
307 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
311 bool wxBitmapDataObject::GetDataHere(
317 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
320 memcpy(pBuf
, m_pngData
, m_pngSize
);
324 bool wxBitmapDataObject::SetData(
331 m_pngData
= malloc(m_pngSize
);
333 memcpy(m_pngData
, pBuf
, m_pngSize
);
336 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
338 wxPNGHandler vHandler
;
340 if (!vHandler
.LoadFile(&vImage
, vMstream
))
345 m_bitmap
= wxBitmap(vImage
);
346 #endif //wxUSE_STREAMS
348 return m_bitmap
.Ok();
351 void wxBitmapDataObject::DoConvertToPng()
357 wxImage vImage
= m_bitmap
.ConvertToImage();
358 wxPNGHandler vHandler
;
359 wxCountingOutputStream vCount
;
361 vHandler
.SaveFile(&vImage
, vCount
);
363 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
364 m_pngData
= malloc(m_pngSize
);
366 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
368 vHandler
.SaveFile(&vImage
, vMstream
);