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"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
45 static const wxChar
*GetTymedName(DWORD tymed
);
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxDataFormat::wxDataFormat()
54 m_vType
= wxDF_INVALID
;
58 wxDataFormat::wxDataFormat(
66 wxDataFormat::wxDataFormat(
74 wxDataFormat::wxDataFormat(
82 wxDataFormat::wxDataFormat(
90 void wxDataFormat::SetType(
96 if (m_vType
== wxDF_TEXT
)
99 if (m_vType
== wxDF_BITMAP
)
102 if (m_vType
== wxDF_FILENAME
)
106 wxFAIL_MSG( wxT("invalid dataformat") );
110 wxDataFormatId
wxDataFormat::GetType() const
115 wxString
wxDataFormat::GetId() const
117 wxString
sRet(""); // TODO: gdk_atom_name( m_format ) );
121 void wxDataFormat::SetId(
128 if (m_format == g_textAtom)
131 if (m_format == g_pngAtom)
132 m_type = wxDF_BITMAP;
134 if (m_format == g_fileAtom)
135 m_type = wxDF_FILENAME;
137 m_type = wxDF_PRIVATE;
141 void wxDataFormat::SetId(
147 m_vType
= wxDF_PRIVATE
;
148 m_vFormat
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
151 void wxDataFormat::PrepareFormats()
156 g_textAtom = gdk_atom_intern( "STRING", FALSE );
158 g_pngAtom = gdk_atom_intern( "image/png", FALSE );
160 g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
164 //-------------------------------------------------------------------------
166 //-------------------------------------------------------------------------
168 wxDataObject::wxDataObject()
172 bool wxDataObject::IsSupportedFormat(
173 const wxDataFormat
& rFormat
177 size_t nFormatCount
= GetFormatCount(vDir
);
179 if (nFormatCount
== 1)
181 return rFormat
== GetPreferredFormat();
185 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
186 GetAllFormats( pFormats
192 for (n
= 0; n
< nFormatCount
; n
++)
194 if (pFormats
[n
] == rFormat
)
201 return n
< nFormatCount
;
205 // ----------------------------------------------------------------------------
207 // ----------------------------------------------------------------------------
209 bool wxFileDataObject::GetDataHere(
215 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
217 sFilenames
+= m_filenames
[i
];
218 sFilenames
+= (wxChar
)0;
221 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
225 size_t wxFileDataObject::GetDataSize() const
229 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
231 nRes
+= m_filenames
[i
].Len();
238 bool wxFileDataObject::SetData(
239 size_t WXUNUSED(nSize
)
245 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
252 void wxFileDataObject::AddFile(
253 const wxString
& rFilename
256 m_filenames
.Add(rFilename
);
259 // ----------------------------------------------------------------------------
260 // wxBitmapDataObject
261 // ----------------------------------------------------------------------------
263 wxBitmapDataObject::wxBitmapDataObject()
268 wxBitmapDataObject::wxBitmapDataObject(
269 const wxBitmap
& rBitmap
271 : wxBitmapDataObjectBase(rBitmap
)
278 wxBitmapDataObject::~wxBitmapDataObject()
283 void wxBitmapDataObject::SetBitmap(
284 const wxBitmap
& rBitmap
288 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
292 bool wxBitmapDataObject::GetDataHere(
298 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
301 memcpy(pBuf
, m_pngData
, m_pngSize
);
305 bool wxBitmapDataObject::SetData(
312 m_pngData
= malloc(m_pngSize
);
314 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
= wxBitmap(vImage
);
327 #endif //wxUSE_STREAMS
329 return m_bitmap
.Ok();
332 void wxBitmapDataObject::DoConvertToPng()
338 wxImage vImage
= m_bitmap
.ConvertToImage();
339 wxPNGHandler vHandler
;
340 wxCountingOutputStream vCount
;
342 vHandler
.SaveFile(&vImage
, vCount
);
344 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
345 m_pngData
= malloc(m_pngSize
);
347 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
349 vHandler
.SaveFile(&vImage
, vMstream
);