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"
36 #include "wx/mac/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxDataFormat::wxDataFormat()
48 m_type
= wxDF_INVALID
;
52 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
57 wxDataFormat::wxDataFormat( const wxChar
* zId
)
62 wxDataFormat::wxDataFormat( const wxString
& rId
)
67 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
72 void wxDataFormat::SetType( wxDataFormatId Type
)
76 if (m_type
== wxDF_TEXT
)
78 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
80 else if (m_type
== wxDF_FILENAME
)
81 m_format
= kDragFlavorTypeHFS
;
84 wxFAIL_MSG( wxT("invalid dataformat") );
88 wxDataFormatId
wxDataFormat::GetType() const
93 wxString
wxDataFormat::GetId() const
95 wxString
sRet(""); // TODO: to name of ( m_format ) );
99 void wxDataFormat::SetId( NativeFormat format
)
103 if (m_format
== 'TEXT')
106 if (m_format
== 'PICT')
107 m_type
= wxDF_BITMAP
;
109 if (m_format
== kDragFlavorTypeHFS
)
110 m_type
= wxDF_FILENAME
;
112 m_type
= wxDF_PRIVATE
;
115 void wxDataFormat::SetId( const wxChar
* zId
)
119 m_type
= wxDF_PRIVATE
;
120 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
123 //-------------------------------------------------------------------------
125 //-------------------------------------------------------------------------
127 wxDataObject::wxDataObject()
131 bool wxDataObject::IsSupportedFormat(
132 const wxDataFormat
& rFormat
136 size_t nFormatCount
= GetFormatCount(vDir
);
138 if (nFormatCount
== 1)
140 return rFormat
== GetPreferredFormat();
144 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
145 GetAllFormats( pFormats
151 for (n
= 0; n
< nFormatCount
; n
++)
153 if (pFormats
[n
] == rFormat
)
160 return n
< nFormatCount
;
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 bool wxFileDataObject::GetDataHere(
174 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
176 sFilenames
+= m_filenames
[i
];
177 sFilenames
+= (wxChar
)0;
180 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
184 size_t wxFileDataObject::GetDataSize() const
188 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
190 nRes
+= m_filenames
[i
].Len();
197 bool wxFileDataObject::SetData(
198 size_t WXUNUSED(nSize
)
204 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
211 void wxFileDataObject::AddFile(
212 const wxString
& rFilename
215 m_filenames
.Add(rFilename
);
218 // ----------------------------------------------------------------------------
219 // wxBitmapDataObject
220 // ----------------------------------------------------------------------------
222 wxBitmapDataObject::wxBitmapDataObject()
227 wxBitmapDataObject::wxBitmapDataObject(
228 const wxBitmap
& rBitmap
230 : wxBitmapDataObjectBase(rBitmap
)
237 wxBitmapDataObject::~wxBitmapDataObject()
242 void wxBitmapDataObject::SetBitmap(
243 const wxBitmap
& rBitmap
247 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
251 bool wxBitmapDataObject::GetDataHere(
257 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
260 memcpy(pBuf
, m_pngData
, m_pngSize
);
264 bool wxBitmapDataObject::SetData(
271 m_pngData
= malloc(m_pngSize
);
273 memcpy(m_pngData
, pBuf
, m_pngSize
);
275 wxMemoryInputStream
vMstream((char*)m_pngData
, m_pngSize
);
277 wxPNGHandler vHandler
;
279 if (!vHandler
.LoadFile(&vImage
, vMstream
))
284 m_bitmap
= vImage
.ConvertToBitmap();
285 return m_bitmap
.Ok();
288 void wxBitmapDataObject::DoConvertToPng()
293 wxImage
vImage(m_bitmap
);
294 wxPNGHandler vHandler
;
295 wxCountingOutputStream vCount
;
297 vHandler
.SaveFile(&vImage
, vCount
);
299 m_pngSize
= vCount
.GetSize() + 100; // sometimes the size seems to vary ???
300 m_pngData
= malloc(m_pngSize
);
302 wxMemoryOutputStream
vMstream((char*) m_pngData
, m_pngSize
);
304 vHandler
.SaveFile(&vImage
, vMstream
);