]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dataobj.cpp
Remove deprecated methods use.
[wxWidgets.git] / src / os2 / dataobj.cpp
CommitLineData
6dddc146
DW
1///////////////////////////////////////////////////////////////////////////////
2// Name: os2/dataobj.cpp
3// Purpose: implementation of wx[I]DataObject class
4// Author: David Webster
5// Modified by:
6// Created: 10/21/99
7// RCS-ID: $Id$
8// Copyright: (c) 1999 David Webster
6aa89a22 9// Licence: wxWindows licence
6dddc146
DW
10///////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "dataobj.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifndef WX_PRECOMP
28#include "wx/intl.h"
29#endif
30#include "wx/defs.h"
31
32#include "wx/log.h"
33#include "wx/dataobj.h"
e6ebb514
DW
34#include "wx/mstream.h"
35#include "wx/image.h"
6dddc146
DW
36
37#define INCL_DOS
38#include <os2.h>
39
40// ----------------------------------------------------------------------------
41// functions
42// ----------------------------------------------------------------------------
43
44#ifdef __WXDEBUG__
45 static const wxChar *GetTymedName(DWORD tymed);
46#endif // Debug
47
48// ----------------------------------------------------------------------------
49// wxDataFormat
50// ----------------------------------------------------------------------------
51
4fd899b6 52wxString wxDataFormat::GetId() const
6dddc146 53{
4fd899b6
DW
54 char zBuf[256];
55 wxString sRet;
56
57 ::WinQueryAtomName( ::WinQuerySystemAtomTable()
58 ,m_uFormat
59 ,zBuf
60 ,256
61 );
62 sRet = zBuf;
63 return sRet;
64} // end of wxDataFormat::GetId()
6dddc146 65
4fd899b6 66void wxDataFormat::SetId (
6dddc146
DW
67 const wxChar* zId
68)
69{
4fd899b6
DW
70 m_uFormat = ::WinAddAtom( ::WinQuerySystemAtomTable()
71 ,zId
72 );
73} // end of wxDataFormat::SetId
6dddc146 74
4fd899b6 75class CIDataObject
6dddc146 76{
4fd899b6
DW
77public:
78 CIDataObject(wxDataObject* pDataObject);
79 ~CIDataObject();
80
81 //
82 // Operations on the DRAGITEM struct
83 //
84 bool GetData( const wxDataFormat& rFormat
85 ,char* pzBuffer
86 ,ULONG ulLen
87 );
88 void GetDataHere( const wxDataFormat& rFormat
89 ,char* pzBuffer
90 ,ULONG ulLen
91 );
92 void QueryGetData(const wxDataFormat& rFormat);
93 void SetData( const wxDataFormat& rFormat
94 ,char* pzBuffer
95 );
96private:
97 wxDataObject* m_pDataObject; // pointer to C++ class we belong to
98 DRAGITEM m_vDragItem;
99}; // end of CLASS CIDataObject
100
101bool CIDataObject::GetData (
102 const wxDataFormat& rFormat
103, char* pzBuffer
104, ULONG ulLen
6dddc146
DW
105)
106{
4fd899b6
DW
107 QueryGetData(rFormat);
108 if (rFormat.GetType() == wxDF_INVALID)
109 return FALSE;
6dddc146 110
4fd899b6
DW
111 ULONG ulSize = m_pDataObject->GetDataSize(rFormat);
112
113 if (ulSize == 0)
114 {
115 //
116 // It probably means that the method is just not implemented
117 //
118 return FALSE;
119 }
120 if (rFormat.GetType() == wxDF_PRIVATE)
6dddc146 121 {
4fd899b6
DW
122 //
123 // For custom formats, put the size with the data - alloc the
124 // space for it
125 //
126 ulSize += sizeof(ULONG);
6dddc146 127 }
6dddc146 128
4fd899b6
DW
129 if (ulSize > ulLen) // not enough room to copy
130 return FALSE;
6dddc146 131
4fd899b6
DW
132 //
133 // Copy the data
134 //
135 GetDataHere( rFormat
136 ,pzBuffer
137 ,ulSize
138 );
139 return TRUE;
140} // end of CIDataObject::GetData
6dddc146 141
4fd899b6
DW
142void CIDataObject::GetDataHere(
143 const wxDataFormat& rFormat
144, char* pzBuffer
145, ULONG WXUNUSED(ulLen)
6dddc146
DW
146)
147{
4fd899b6
DW
148 m_pDataObject->GetDataHere( rFormat
149 ,(void*)pzBuffer
150 );
151} // end of CIDataObject::GetDataHere
152
153void CIDataObject::QueryGetData (
154 const wxDataFormat& rFormat
6dddc146
DW
155)
156{
4fd899b6
DW
157 m_pDataObject->IsSupportedFormat(rFormat);
158} // end of CIDataObject::QueryGetData
6dddc146 159
4fd899b6
DW
160void CIDataObject::SetData (
161 const wxDataFormat& rFormat
162, char* pzBuffer
163)
6dddc146 164{
4fd899b6
DW
165 ULONG ulSize;
166
167 switch (rFormat.GetType())
168 {
169 case wxDF_TEXT:
170 case wxDF_OEMTEXT:
171 case wxDF_FILENAME:
172 case wxDF_HTML:
173 ulSize = strlen((const char *)pzBuffer);
174 break;
175
176 case wxDF_UNICODETEXT:
177 ulSize = ::wcslen((const wchar_t *)pzBuffer);
178 break;
179
180 case wxDF_BITMAP:
181 case wxDF_METAFILE:
182 case wxDF_ENHMETAFILE:
183 case wxDF_TIFF:
184 case wxDF_DIB:
185 ulSize = 0; // pass via a handle
186 break;
187
188
189 case wxDF_SYLK:
190 case wxDF_DIF:
191 case wxDF_PALETTE:
192 case wxDF_PENDATA:
193 case wxDF_RIFF:
194 case wxDF_WAVE:
195 case wxDF_LOCALE:
196 //PUNT
197 break;
198
199 case wxDF_PRIVATE:
200 size_t* p = (size_t *)pzBuffer;
201
202 ulSize = *p++;
203 pzBuffer = (char*)p;
204 break;
205 }
206 m_pDataObject->SetData( rFormat
207 ,ulSize
208 ,(void*)pzBuffer
209 );
210} // end of CIDataObject::SetData
6dddc146
DW
211
212//-------------------------------------------------------------------------
213// wxDataObject
214//-------------------------------------------------------------------------
215
4fd899b6 216wxDataObject::wxDataObject ()
6dddc146 217{
4fd899b6
DW
218 m_pDataObject = new DRAGITEM;
219} // end of wxDataObject::wxDataObject
6dddc146 220
4fd899b6 221wxDataObject::~wxDataObject ()
6dddc146 222{
4fd899b6
DW
223 delete m_pDataObject;
224} // end of wxDataObject::~wxDataObject
6dddc146
DW
225
226// ----------------------------------------------------------------------------
227// wxFileDataObject
228// ----------------------------------------------------------------------------
229
230bool wxFileDataObject::GetDataHere(
231 void* pBuf
232) const
233{
234 wxString sFilenames;
235
236 for (size_t i = 0; i < m_filenames.GetCount(); i++)
237 {
e6ebb514
DW
238 sFilenames += m_filenames[i];
239 sFilenames += (wxChar)0;
6dddc146
DW
240 }
241
e6ebb514 242 memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1);
6dddc146
DW
243 return TRUE;
244}
245
246size_t wxFileDataObject::GetDataSize() const
247{
248 size_t nRes = 0;
249
250 for (size_t i = 0; i < m_filenames.GetCount(); i++)
251 {
252 nRes += m_filenames[i].Len();
253 nRes += 1;
254 }
255
256 return nRes + 1;
257}
258
259bool wxFileDataObject::SetData(
260 size_t WXUNUSED(nSize)
261, const void* pBuf
262)
263{
264 /* TODO */
265
266 wxString sFile( (const char *)pBuf); /* char, not wxChar */
267
268 AddFile(sFile);
269
270 return TRUE;
271}
272
273void wxFileDataObject::AddFile(
274 const wxString& rFilename
275)
276{
277 m_filenames.Add(rFilename);
278}
279
280// ----------------------------------------------------------------------------
281// wxBitmapDataObject
282// ----------------------------------------------------------------------------
283
284wxBitmapDataObject::wxBitmapDataObject()
285{
286 Init();
287}
288
289wxBitmapDataObject::wxBitmapDataObject(
290 const wxBitmap& rBitmap
291)
292: wxBitmapDataObjectBase(rBitmap)
293{
294 Init();
295
296 DoConvertToPng();
297}
298
299wxBitmapDataObject::~wxBitmapDataObject()
300{
301 Clear();
302}
303
304void wxBitmapDataObject::SetBitmap(
305 const wxBitmap& rBitmap
306)
307{
308 ClearAll();
309 wxBitmapDataObjectBase::SetBitmap(rBitmap);
310 DoConvertToPng();
311}
312
313bool wxBitmapDataObject::GetDataHere(
314 void* pBuf
315) const
316{
317 if (!m_pngSize)
318 {
319 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
320 return FALSE;
321 }
322 memcpy(pBuf, m_pngData, m_pngSize);
323 return TRUE;
324}
325
326bool wxBitmapDataObject::SetData(
327 size_t nSize
328, const void* pBuf
329)
330{
331 Clear();
332 m_pngSize = nSize;
333 m_pngData = malloc(m_pngSize);
334
335 memcpy(m_pngData, pBuf, m_pngSize);
336
7e99520b 337#if wxUSE_STREAMS
6dddc146
DW
338 wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize);
339 wxImage vImage;
340 wxPNGHandler vHandler;
341
342 if (!vHandler.LoadFile(&vImage, vMstream))
343 {
344 return FALSE;
345 }
346
3437f881 347 m_bitmap = wxBitmap(vImage);
7e99520b
DW
348#endif //wxUSE_STREAMS
349
6dddc146
DW
350 return m_bitmap.Ok();
351}
352
353void wxBitmapDataObject::DoConvertToPng()
354{
355 if (!m_bitmap.Ok())
356 return;
357
7e99520b 358#if wxUSE_STREAMS
3437f881 359 wxImage vImage = m_bitmap.ConvertToImage();
6dddc146
DW
360 wxPNGHandler vHandler;
361 wxCountingOutputStream vCount;
362
e6ebb514 363 vHandler.SaveFile(&vImage, vCount);
6dddc146
DW
364
365 m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
366 m_pngData = malloc(m_pngSize);
367
e6ebb514
DW
368 wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize);
369
6dddc146 370 vHandler.SaveFile(&vImage, vMstream );
7e99520b 371#endif
6dddc146
DW
372}
373