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"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
43 static const wxChar
*GetTymedName(DWORD tymed
);
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxDataFormat::wxDataFormat(
55 m_vType
= wxDF_INVALID
;
59 wxDataFormat::wxDataFormat(
67 wxDataFormat::wxDataFormat(
75 wxDataFormat::wxDataFormat(
83 wxDataFormat::wxDataFormat(
91 void wxDataFormat::SetType(
97 if (m_vType
== wxDF_TEXT
)
100 if (m_vType
== wxDF_BITMAP
)
103 if (m_vType
== wxDF_FILENAME
)
107 wxFAIL_MSG( wxT("invalid dataformat") );
111 wxDataFormatId
wxDataFormat::GetType() const
116 wxString
wxDataFormat::GetId() const
118 wxString
sRet(""); // TODO: gdk_atom_name( m_format ) );
122 void wxDataFormat::SetId(
129 if (m_format == g_textAtom)
132 if (m_format == g_pngAtom)
133 m_type = wxDF_BITMAP;
135 if (m_format == g_fileAtom)
136 m_type = wxDF_FILENAME;
138 m_type = wxDF_PRIVATE;
142 void wxDataFormat::SetId(
148 m_vType
= wxDF_PRIVATE
;
149 m_vFormat
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
152 void wxDataFormat::PrepareFormats()
157 g_textAtom = gdk_atom_intern( "STRING", FALSE );
159 g_pngAtom = gdk_atom_intern( "image/png", FALSE );
161 g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
165 //-------------------------------------------------------------------------
167 //-------------------------------------------------------------------------
169 wxDataObject::wxDataObject()
173 bool wxDataObject::IsSupportedFormat(
174 const wxDataFormat
& rFormat
178 size_t nFormatCount
= GetFormatCount(vDir
);
180 if (nFormatCount
== 1)
182 return rFormat
== GetPreferredFormat();
186 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
187 GetAllFormats( rFormats
193 for (n
= 0; n
< nFormatCount
; n
++)
195 if (rFormats
[n
] == rFormat
)
202 return n
< nFormatCount
;
206 // ----------------------------------------------------------------------------
208 // ----------------------------------------------------------------------------
210 bool wxFileDataObject::GetDataHere(
216 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
218 filenames
+= m_filenames
[i
];
219 filenames
+= (wxChar
)0;
222 memcpy(pBuf
, filenames
.mbc_str(), filenames
.Len() + 1);
226 size_t wxFileDataObject::GetDataSize() const
230 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
232 nRes
+= m_filenames
[i
].Len();
239 bool wxFileDataObject::SetData(
240 size_t WXUNUSED(nSize
)
246 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
253 void wxFileDataObject::AddFile(
254 const wxString
& rFilename
257 m_filenames
.Add(rFilename
);
260 // ----------------------------------------------------------------------------
261 // wxBitmapDataObject
262 // ----------------------------------------------------------------------------
264 wxBitmapDataObject::wxBitmapDataObject()
269 wxBitmapDataObject::wxBitmapDataObject(
270 const wxBitmap
& rBitmap
272 : wxBitmapDataObjectBase(rBitmap
)
279 wxBitmapDataObject::~wxBitmapDataObject()
284 void wxBitmapDataObject::SetBitmap(
285 const wxBitmap
& rBitmap
289 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
293 bool wxBitmapDataObject::GetDataHere(
299 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
302 memcpy(pBuf
, m_pngData
, m_pngSize
);
306 bool wxBitmapDataObject::SetData(
313 m_pngData
= malloc(m_pngSize
);
315 memcpy(m_pngData
, pBuf
, m_pngSize
);
317 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
319 wxPNGHandler vHandler
;
321 if (!vHandler
.LoadFile(&vImage
, vMstream
))
326 m_bitmap
= vImage
.ConvertToBitmap();
327 return m_bitmap
.Ok();
330 void wxBitmapDataObject::DoConvertToPng()
335 wxImage
vImage(m_bitmap
);
336 wxPNGHandler vHandler
;
337 wxCountingOutputStream vCount
;
339 vHandler
.SaveFile(&rImage
, vCount
);
341 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
342 m_pngData
= malloc(m_pngSize
);
344 wxMemoryOutputStream
mstream((char*) m_pngData
, m_pngSize
);
345 vHandler
.SaveFile(&vImage
, vMstream
);