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_type
= wxDF_INVALID
;
51 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
56 wxDataFormat::wxDataFormat( const wxChar
* zId
)
61 wxDataFormat::wxDataFormat( const wxString
& rId
)
66 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
71 void wxDataFormat::SetType( wxDataFormatId Type
)
75 if (m_type
== wxDF_TEXT
)
77 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
79 else if (m_type
== wxDF_FILENAME
)
83 wxFAIL_MSG( wxT("invalid dataformat") );
87 wxDataFormatId
wxDataFormat::GetType() const
92 wxString
wxDataFormat::GetId() const
94 wxString
sRet(""); // TODO: to name of ( m_format ) );
98 void wxDataFormat::SetId( NativeFormat format
)
102 if (m_format
== 'TEXT')
105 if (m_format
== 'PICT')
106 m_type
= wxDF_BITMAP
;
108 if (m_format
== 'SPEC')
109 m_type
= wxDF_FILENAME
;
111 m_type
= wxDF_PRIVATE
;
114 void wxDataFormat::SetId( const wxChar
* zId
)
118 m_type
= wxDF_PRIVATE
;
119 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
122 //-------------------------------------------------------------------------
124 //-------------------------------------------------------------------------
126 wxDataObject::wxDataObject()
130 bool wxDataObject::IsSupportedFormat(
131 const wxDataFormat
& rFormat
135 size_t nFormatCount
= GetFormatCount(vDir
);
137 if (nFormatCount
== 1)
139 return rFormat
== GetPreferredFormat();
143 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
144 GetAllFormats( pFormats
150 for (n
= 0; n
< nFormatCount
; n
++)
152 if (pFormats
[n
] == rFormat
)
159 return n
< nFormatCount
;
163 // ----------------------------------------------------------------------------
165 // ----------------------------------------------------------------------------
167 bool wxFileDataObject::GetDataHere(
173 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
175 sFilenames
+= m_filenames
[i
];
176 sFilenames
+= (wxChar
)0;
179 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
183 size_t wxFileDataObject::GetDataSize() const
187 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
189 nRes
+= m_filenames
[i
].Len();
196 bool wxFileDataObject::SetData(
197 size_t WXUNUSED(nSize
)
203 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
210 void wxFileDataObject::AddFile(
211 const wxString
& rFilename
214 m_filenames
.Add(rFilename
);
217 // ----------------------------------------------------------------------------
218 // wxBitmapDataObject
219 // ----------------------------------------------------------------------------
221 wxBitmapDataObject::wxBitmapDataObject()
226 wxBitmapDataObject::wxBitmapDataObject(
227 const wxBitmap
& rBitmap
229 : wxBitmapDataObjectBase(rBitmap
)
236 wxBitmapDataObject::~wxBitmapDataObject()
241 void wxBitmapDataObject::SetBitmap(
242 const wxBitmap
& rBitmap
246 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
250 bool wxBitmapDataObject::GetDataHere(
256 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
259 memcpy(pBuf
, m_pngData
, m_pngSize
);
263 bool wxBitmapDataObject::SetData(
270 m_pngData
= malloc(m_pngSize
);
272 memcpy(m_pngData
, pBuf
, m_pngSize
);
274 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
276 wxPNGHandler vHandler
;
278 if (!vHandler
.LoadFile(&vImage
, vMstream
))
283 m_bitmap
= vImage
.ConvertToBitmap();
284 return m_bitmap
.Ok();
287 void wxBitmapDataObject::DoConvertToPng()
292 wxImage
vImage(m_bitmap
);
293 wxPNGHandler vHandler
;
294 wxCountingOutputStream vCount
;
296 vHandler
.SaveFile(&vImage
, vCount
);
298 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
299 m_pngData
= malloc(m_pngSize
);
301 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
303 vHandler
.SaveFile(&vImage
, vMstream
);