1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
30 #include "wx/dataobj.h"
31 #include "wx/mstream.h"
34 #include "wx/os2/private.h"
36 // ----------------------------------------------------------------------------
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 wxString
wxDataFormat::GetId() const
49 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
56 } // end of wxDataFormat::GetId()
58 void wxDataFormat::SetId (
62 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
65 } // end of wxDataFormat::SetId
70 CIDataObject(wxDataObject
* pDataObject
);
74 // Operations on the DRAGITEM struct
76 bool GetData( const wxDataFormat
& rFormat
80 void GetDataHere( const wxDataFormat
& rFormat
84 void QueryGetData(const wxDataFormat
& rFormat
);
85 void SetData( const wxDataFormat
& rFormat
89 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
91 }; // end of CLASS CIDataObject
93 bool CIDataObject::GetData ( const wxDataFormat
& rFormat
,
97 QueryGetData(rFormat
);
98 if (rFormat
.GetType() == wxDF_INVALID
)
101 ULONG ulSize
= m_pDataObject
->GetDataSize(rFormat
);
106 // It probably means that the method is just not implemented
110 if (rFormat
.GetType() == wxDF_PRIVATE
)
113 // For custom formats, put the size with the data - alloc the
116 ulSize
+= sizeof(ULONG
);
119 if (ulSize
> ulLen
) // not enough room to copy
130 } // end of CIDataObject::GetData
132 void CIDataObject::GetDataHere(
133 const wxDataFormat
& rFormat
135 , ULONG
WXUNUSED(ulLen
)
138 m_pDataObject
->GetDataHere( rFormat
141 } // end of CIDataObject::GetDataHere
143 void CIDataObject::QueryGetData (
144 const wxDataFormat
& rFormat
147 m_pDataObject
->IsSupportedFormat(rFormat
);
148 } // end of CIDataObject::QueryGetData
150 void CIDataObject::SetData (
151 const wxDataFormat
& rFormat
157 switch (rFormat
.GetType())
163 ulSize
= strlen((const char *)pzBuffer
);
167 case wxDF_UNICODETEXT
:
168 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
174 case wxDF_ENHMETAFILE
:
177 ulSize
= 0; // pass via a handle
192 size_t* p
= (size_t *)pzBuffer
;
198 m_pDataObject
->SetData( rFormat
202 } // end of CIDataObject::SetData
204 //-------------------------------------------------------------------------
206 //-------------------------------------------------------------------------
208 wxDataObject::wxDataObject ()
210 m_pDataObject
= new DRAGITEM
;
211 } // end of wxDataObject::wxDataObject
213 wxDataObject::~wxDataObject ()
215 delete m_pDataObject
;
216 } // end of wxDataObject::~wxDataObject
218 // ----------------------------------------------------------------------------
220 // ----------------------------------------------------------------------------
222 bool wxFileDataObject::GetDataHere( void* pBuf
) const
226 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
228 sFilenames
+= m_filenames
[i
];
229 sFilenames
+= (wxChar
)0;
232 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
236 size_t wxFileDataObject::GetDataSize() const
240 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
242 nRes
+= m_filenames
[i
].Len();
249 bool wxFileDataObject::SetData( size_t WXUNUSED(nSize
),
254 wxString
sFile((const wxChar
*)pBuf
); /* char, not wxChar */
261 void wxFileDataObject::AddFile(
262 const wxString
& rFilename
265 m_filenames
.Add(rFilename
);
268 // ----------------------------------------------------------------------------
269 // wxBitmapDataObject
270 // ----------------------------------------------------------------------------
272 wxBitmapDataObject::wxBitmapDataObject()
277 wxBitmapDataObject::wxBitmapDataObject(
278 const wxBitmap
& rBitmap
280 : wxBitmapDataObjectBase(rBitmap
)
287 wxBitmapDataObject::~wxBitmapDataObject()
292 void wxBitmapDataObject::SetBitmap( const wxBitmap
& rBitmap
)
295 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
299 bool wxBitmapDataObject::GetDataHere( void* pBuf
) const
303 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
306 memcpy(pBuf
, m_pngData
, m_pngSize
);
310 bool wxBitmapDataObject::SetData( size_t nSize
, const void* pBuf
)
314 m_pngData
= malloc(m_pngSize
);
316 memcpy(m_pngData
, pBuf
, m_pngSize
);
319 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
321 wxPNGHandler vHandler
;
323 if (!vHandler
.LoadFile(&vImage
, vMstream
))
328 m_bitmap
= wxBitmap(vImage
);
329 #endif //wxUSE_STREAMS
331 return m_bitmap
.Ok();
334 void wxBitmapDataObject::DoConvertToPng()
340 wxImage vImage
= m_bitmap
.ConvertToImage();
341 wxPNGHandler vHandler
;
342 wxCountingOutputStream vCount
;
344 vHandler
.SaveFile(&vImage
, vCount
);
346 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
347 m_pngData
= malloc(m_pngSize
);
349 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
351 vHandler
.SaveFile(&vImage
, vMstream
);
355 #endif // wxUSE_DATAOBJ