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"
25 #include "wx/dataobj.h"
33 #include "wx/mstream.h"
35 #include "wx/os2/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 wxString
wxDataFormat::GetId() const
50 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
57 } // end of wxDataFormat::GetId()
59 void wxDataFormat::SetId (
63 m_uFormat
= ::WinAddAtom( ::WinQuerySystemAtomTable()
66 } // end of wxDataFormat::SetId
71 CIDataObject(wxDataObject
* pDataObject
);
75 // Operations on the DRAGITEM struct
77 bool GetData( const wxDataFormat
& rFormat
81 void GetDataHere( const wxDataFormat
& rFormat
85 void QueryGetData(const wxDataFormat
& rFormat
);
86 void SetData( const wxDataFormat
& rFormat
90 wxDataObject
* m_pDataObject
; // pointer to C++ class we belong to
92 }; // end of CLASS CIDataObject
94 bool CIDataObject::GetData ( const wxDataFormat
& rFormat
,
98 QueryGetData(rFormat
);
99 if (rFormat
.GetType() == wxDF_INVALID
)
102 ULONG ulSize
= m_pDataObject
->GetDataSize(rFormat
);
107 // It probably means that the method is just not implemented
111 if (rFormat
.GetType() == wxDF_PRIVATE
)
114 // For custom formats, put the size with the data - alloc the
117 ulSize
+= sizeof(ULONG
);
120 if (ulSize
> ulLen
) // not enough room to copy
131 } // end of CIDataObject::GetData
133 void CIDataObject::GetDataHere(
134 const wxDataFormat
& rFormat
136 , ULONG
WXUNUSED(ulLen
)
139 m_pDataObject
->GetDataHere( rFormat
142 } // end of CIDataObject::GetDataHere
144 void CIDataObject::QueryGetData (
145 const wxDataFormat
& rFormat
148 m_pDataObject
->IsSupportedFormat(rFormat
);
149 } // end of CIDataObject::QueryGetData
151 void CIDataObject::SetData (
152 const wxDataFormat
& rFormat
158 switch (rFormat
.GetType())
164 ulSize
= strlen((const char *)pzBuffer
);
168 case wxDF_UNICODETEXT
:
169 ulSize
= ::wcslen((const wchar_t *)pzBuffer
);
175 case wxDF_ENHMETAFILE
:
178 ulSize
= 0; // pass via a handle
193 size_t* p
= (size_t *)pzBuffer
;
199 m_pDataObject
->SetData( rFormat
203 } // end of CIDataObject::SetData
205 //-------------------------------------------------------------------------
207 //-------------------------------------------------------------------------
209 wxDataObject::wxDataObject ()
211 m_pDataObject
= new DRAGITEM
;
212 } // end of wxDataObject::wxDataObject
214 wxDataObject::~wxDataObject ()
216 delete m_pDataObject
;
217 } // end of wxDataObject::~wxDataObject
219 // ----------------------------------------------------------------------------
221 // ----------------------------------------------------------------------------
223 bool wxFileDataObject::GetDataHere( void* pBuf
) const
227 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
229 sFilenames
+= m_filenames
[i
];
230 sFilenames
+= (wxChar
)0;
233 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.length() + 1);
237 size_t wxFileDataObject::GetDataSize() const
241 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
243 nRes
+= m_filenames
[i
].length();
250 bool wxFileDataObject::SetData( size_t WXUNUSED(nSize
),
255 wxString
sFile((const wxChar
*)pBuf
); /* char, not wxChar */
262 void wxFileDataObject::AddFile(
263 const wxString
& rFilename
266 m_filenames
.Add(rFilename
);
269 // ----------------------------------------------------------------------------
270 // wxBitmapDataObject
271 // ----------------------------------------------------------------------------
273 wxBitmapDataObject::wxBitmapDataObject()
278 wxBitmapDataObject::wxBitmapDataObject(
279 const wxBitmap
& rBitmap
281 : wxBitmapDataObjectBase(rBitmap
)
288 wxBitmapDataObject::~wxBitmapDataObject()
293 void wxBitmapDataObject::SetBitmap( const wxBitmap
& rBitmap
)
296 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
300 bool wxBitmapDataObject::GetDataHere( void* pBuf
) const
304 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
307 memcpy(pBuf
, m_pngData
, m_pngSize
);
311 bool wxBitmapDataObject::SetData( size_t nSize
, const void* pBuf
)
315 m_pngData
= malloc(m_pngSize
);
317 memcpy(m_pngData
, pBuf
, m_pngSize
);
320 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
322 wxPNGHandler vHandler
;
324 if (!vHandler
.LoadFile(&vImage
, vMstream
))
329 m_bitmap
= wxBitmap(vImage
);
330 #endif //wxUSE_STREAMS
332 return m_bitmap
.Ok();
335 void wxBitmapDataObject::DoConvertToPng()
341 wxImage vImage
= m_bitmap
.ConvertToImage();
342 wxPNGHandler vHandler
;
343 wxCountingOutputStream vCount
;
345 vHandler
.SaveFile(&vImage
, vCount
);
347 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
348 m_pngData
= malloc(m_pngSize
);
350 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
352 vHandler
.SaveFile(&vImage
, vMstream
);
356 #endif // wxUSE_DATAOBJ