]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dataobj.cpp
Use InheritAttributes for wxGTK widgets so they will check
[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
8681f66c 176#if wxUSE_UNICODE
4fd899b6
DW
177 case wxDF_UNICODETEXT:
178 ulSize = ::wcslen((const wchar_t *)pzBuffer);
179 break;
8681f66c 180#endif
4fd899b6
DW
181
182 case wxDF_BITMAP:
183 case wxDF_METAFILE:
184 case wxDF_ENHMETAFILE:
185 case wxDF_TIFF:
186 case wxDF_DIB:
187 ulSize = 0; // pass via a handle
188 break;
189
190
191 case wxDF_SYLK:
192 case wxDF_DIF:
193 case wxDF_PALETTE:
194 case wxDF_PENDATA:
195 case wxDF_RIFF:
196 case wxDF_WAVE:
197 case wxDF_LOCALE:
198 //PUNT
199 break;
200
201 case wxDF_PRIVATE:
202 size_t* p = (size_t *)pzBuffer;
203
204 ulSize = *p++;
205 pzBuffer = (char*)p;
206 break;
207 }
208 m_pDataObject->SetData( rFormat
209 ,ulSize
210 ,(void*)pzBuffer
211 );
212} // end of CIDataObject::SetData
6dddc146
DW
213
214//-------------------------------------------------------------------------
215// wxDataObject
216//-------------------------------------------------------------------------
217
4fd899b6 218wxDataObject::wxDataObject ()
6dddc146 219{
4fd899b6
DW
220 m_pDataObject = new DRAGITEM;
221} // end of wxDataObject::wxDataObject
6dddc146 222
4fd899b6 223wxDataObject::~wxDataObject ()
6dddc146 224{
4fd899b6
DW
225 delete m_pDataObject;
226} // end of wxDataObject::~wxDataObject
6dddc146
DW
227
228// ----------------------------------------------------------------------------
229// wxFileDataObject
230// ----------------------------------------------------------------------------
231
232bool wxFileDataObject::GetDataHere(
233 void* pBuf
234) const
235{
236 wxString sFilenames;
237
238 for (size_t i = 0; i < m_filenames.GetCount(); i++)
239 {
e6ebb514
DW
240 sFilenames += m_filenames[i];
241 sFilenames += (wxChar)0;
6dddc146
DW
242 }
243
e6ebb514 244 memcpy(pBuf, sFilenames.mbc_str(), sFilenames.Len() + 1);
6dddc146
DW
245 return TRUE;
246}
247
248size_t wxFileDataObject::GetDataSize() const
249{
250 size_t nRes = 0;
251
252 for (size_t i = 0; i < m_filenames.GetCount(); i++)
253 {
254 nRes += m_filenames[i].Len();
255 nRes += 1;
256 }
257
258 return nRes + 1;
259}
260
261bool wxFileDataObject::SetData(
262 size_t WXUNUSED(nSize)
263, const void* pBuf
264)
265{
266 /* TODO */
267
268 wxString sFile( (const char *)pBuf); /* char, not wxChar */
269
270 AddFile(sFile);
271
272 return TRUE;
273}
274
275void wxFileDataObject::AddFile(
276 const wxString& rFilename
277)
278{
279 m_filenames.Add(rFilename);
280}
281
282// ----------------------------------------------------------------------------
283// wxBitmapDataObject
284// ----------------------------------------------------------------------------
285
286wxBitmapDataObject::wxBitmapDataObject()
287{
288 Init();
289}
290
291wxBitmapDataObject::wxBitmapDataObject(
292 const wxBitmap& rBitmap
293)
294: wxBitmapDataObjectBase(rBitmap)
295{
296 Init();
297
298 DoConvertToPng();
299}
300
301wxBitmapDataObject::~wxBitmapDataObject()
302{
303 Clear();
304}
305
306void wxBitmapDataObject::SetBitmap(
307 const wxBitmap& rBitmap
308)
309{
310 ClearAll();
311 wxBitmapDataObjectBase::SetBitmap(rBitmap);
312 DoConvertToPng();
313}
314
315bool wxBitmapDataObject::GetDataHere(
316 void* pBuf
317) const
318{
319 if (!m_pngSize)
320 {
321 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
322 return FALSE;
323 }
324 memcpy(pBuf, m_pngData, m_pngSize);
325 return TRUE;
326}
327
328bool wxBitmapDataObject::SetData(
329 size_t nSize
330, const void* pBuf
331)
332{
333 Clear();
334 m_pngSize = nSize;
335 m_pngData = malloc(m_pngSize);
336
337 memcpy(m_pngData, pBuf, m_pngSize);
338
7e99520b 339#if wxUSE_STREAMS
6dddc146
DW
340 wxMemoryInputStream vMstream((char*)m_pngData, m_pngSize);
341 wxImage vImage;
342 wxPNGHandler vHandler;
343
344 if (!vHandler.LoadFile(&vImage, vMstream))
345 {
346 return FALSE;
347 }
348
3437f881 349 m_bitmap = wxBitmap(vImage);
7e99520b
DW
350#endif //wxUSE_STREAMS
351
6dddc146
DW
352 return m_bitmap.Ok();
353}
354
355void wxBitmapDataObject::DoConvertToPng()
356{
357 if (!m_bitmap.Ok())
358 return;
359
7e99520b 360#if wxUSE_STREAMS
3437f881 361 wxImage vImage = m_bitmap.ConvertToImage();
6dddc146
DW
362 wxPNGHandler vHandler;
363 wxCountingOutputStream vCount;
364
e6ebb514 365 vHandler.SaveFile(&vImage, vCount);
6dddc146
DW
366
367 m_pngSize = vCount.GetSize() + 100; // sometimes the size seems to vary ???
368 m_pngData = malloc(m_pngSize);
369
e6ebb514
DW
370 wxMemoryOutputStream vMstream((char*) m_pngData, m_pngSize);
371
6dddc146 372 vHandler.SaveFile(&vImage, vMstream );
7e99520b 373#endif
6dddc146
DW
374}
375