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 license
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"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 wxDataFormat::wxDataFormat()
47 m_vType
= wxDF_INVALID
;
51 wxDataFormat::wxDataFormat(
59 wxDataFormat::wxDataFormat(
67 wxDataFormat::wxDataFormat(
75 wxDataFormat::wxDataFormat(
83 void wxDataFormat::SetType(
89 if (m_vType
== wxDF_TEXT
)
92 if (m_vType
== wxDF_BITMAP
)
95 if (m_vType
== wxDF_FILENAME
)
99 wxFAIL_MSG( wxT("invalid dataformat") );
103 wxDataFormatId
wxDataFormat::GetType() const
108 wxString
wxDataFormat::GetId() const
110 wxString
sRet(""); // TODO: gdk_atom_name( m_format ) );
114 void wxDataFormat::SetId(
121 if (m_format == g_textAtom)
124 if (m_format == g_pngAtom)
125 m_type = wxDF_BITMAP;
127 if (m_format == g_fileAtom)
128 m_type = wxDF_FILENAME;
130 m_type = wxDF_PRIVATE;
134 void wxDataFormat::SetId(
140 m_vType
= wxDF_PRIVATE
;
141 m_vFormat
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
144 void wxDataFormat::PrepareFormats()
149 g_textAtom = gdk_atom_intern( "STRING", FALSE );
151 g_pngAtom = gdk_atom_intern( "image/png", FALSE );
153 g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
157 //-------------------------------------------------------------------------
159 //-------------------------------------------------------------------------
161 wxDataObject::wxDataObject()
165 bool wxDataObject::IsSupportedFormat(
166 const wxDataFormat
& rFormat
170 size_t nFormatCount
= GetFormatCount(vDir
);
172 if (nFormatCount
== 1)
174 return rFormat
== GetPreferredFormat();
178 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
179 GetAllFormats( pFormats
185 for (n
= 0; n
< nFormatCount
; n
++)
187 if (pFormats
[n
] == rFormat
)
194 return n
< nFormatCount
;
198 // ----------------------------------------------------------------------------
200 // ----------------------------------------------------------------------------
202 bool wxFileDataObject::GetDataHere(
208 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
210 sFilenames
+= m_filenames
[i
];
211 sFilenames
+= (wxChar
)0;
214 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
218 size_t wxFileDataObject::GetDataSize() const
222 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
224 nRes
+= m_filenames
[i
].Len();
231 bool wxFileDataObject::SetData(
232 size_t WXUNUSED(nSize
)
238 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
245 void wxFileDataObject::AddFile(
246 const wxString
& rFilename
249 m_filenames
.Add(rFilename
);
252 // ----------------------------------------------------------------------------
253 // wxBitmapDataObject
254 // ----------------------------------------------------------------------------
256 wxBitmapDataObject::wxBitmapDataObject()
261 wxBitmapDataObject::wxBitmapDataObject(
262 const wxBitmap
& rBitmap
264 : wxBitmapDataObjectBase(rBitmap
)
271 wxBitmapDataObject::~wxBitmapDataObject()
276 void wxBitmapDataObject::SetBitmap(
277 const wxBitmap
& rBitmap
281 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
285 bool wxBitmapDataObject::GetDataHere(
291 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
294 memcpy(pBuf
, m_pngData
, m_pngSize
);
298 bool wxBitmapDataObject::SetData(
305 m_pngData
= malloc(m_pngSize
);
307 memcpy(m_pngData
, pBuf
, m_pngSize
);
309 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
311 wxPNGHandler vHandler
;
313 if (!vHandler
.LoadFile(&vImage
, vMstream
))
318 m_bitmap
= vImage
.ConvertToBitmap();
319 return m_bitmap
.Ok();
322 void wxBitmapDataObject::DoConvertToPng()
327 wxImage
vImage(m_bitmap
);
328 wxPNGHandler vHandler
;
329 wxCountingOutputStream vCount
;
331 vHandler
.SaveFile(&vImage
, vCount
);
333 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
334 m_pngData
= malloc(m_pngSize
);
336 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
338 vHandler
.SaveFile(&vImage
, vMstream
);