]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: mac/dataobj.cpp
3 // Purpose: implementation of wxDataObject class
4 // Author: Stefan Csomor
8 // Copyright: (c) 1999 Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "dataobj.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
34 #include "wx/dataobj.h"
35 #include "wx/dcmemory.h"
36 #include "wx/mstream.h"
38 #include "wx/metafile.h"
39 #include "wx/mac/private.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 // ----------------------------------------------------------------------------
52 wxDataFormat::wxDataFormat()
54 m_type
= wxDF_INVALID
;
58 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
63 wxDataFormat::wxDataFormat( const wxChar
* zId
)
68 wxDataFormat::wxDataFormat( const wxString
& rId
)
73 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
78 void wxDataFormat::SetType( wxDataFormatId Type
)
82 if (m_type
== wxDF_TEXT
)
83 m_format
= kScrapFlavorTypeText
;
84 else if (m_type
== wxDF_UNICODETEXT
)
85 m_format
= kScrapFlavorTypeUnicode
;
86 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
87 m_format
= kScrapFlavorTypePicture
;
88 else if (m_type
== wxDF_FILENAME
)
89 m_format
= kDragFlavorTypeHFS
;
92 wxFAIL_MSG( wxT("invalid dataformat") );
94 // this is '????' but it can't be used in the code because ??' is
95 // parsed as a trigraph!
96 m_format
= 0x3f3f3f3f;
100 wxString
wxDataFormat::GetId() const
102 wxCHECK_MSG( !IsStandard(), wxEmptyString
,
103 wxT("name of predefined format cannot be retrieved") );
108 void wxDataFormat::SetId( NativeFormat format
)
112 if (m_format
== kScrapFlavorTypeText
)
114 else if (m_format
== kScrapFlavorTypeUnicode
)
115 m_type
= wxDF_UNICODETEXT
;
116 else if (m_format
== kScrapFlavorTypePicture
)
117 m_type
= wxDF_BITMAP
;
118 else if (m_format
== kDragFlavorTypeHFS
)
119 m_type
= wxDF_FILENAME
;
122 m_type
= wxDF_PRIVATE
;
124 strncpy( text
, (char*) &format
, 4 ) ;
126 m_id
= wxString::FromAscii( text
) ;
130 void wxDataFormat::SetId( const wxChar
* zId
)
132 m_type
= wxDF_PRIVATE
;
137 bool wxDataFormat::operator==(const wxDataFormat
& format
) const
139 if ( IsStandard() || format
.IsStandard() )
141 return ( format
.m_type
== m_type
) ;
145 return ( m_id
== format
.m_id
) ;
149 //-------------------------------------------------------------------------
151 //-------------------------------------------------------------------------
153 wxDataObject::wxDataObject()
157 bool wxDataObject::IsSupportedFormat(
158 const wxDataFormat
& rFormat
162 size_t nFormatCount
= GetFormatCount(vDir
);
164 if (nFormatCount
== 1)
166 return rFormat
== GetPreferredFormat();
170 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
171 GetAllFormats( pFormats
177 for (n
= 0; n
< nFormatCount
; n
++)
179 if (pFormats
[n
] == rFormat
)
186 return n
< nFormatCount
;
190 // ----------------------------------------------------------------------------
192 // ----------------------------------------------------------------------------
195 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
197 *formats
++ = wxDataFormat( wxDF_TEXT
);
198 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
203 // ----------------------------------------------------------------------------
205 // ----------------------------------------------------------------------------
207 bool wxFileDataObject::GetDataHere(
213 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
215 sFilenames
+= m_filenames
[i
];
216 sFilenames
+= (wxChar
)0;
219 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
223 size_t wxFileDataObject::GetDataSize() const
227 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
229 nRes
+= m_filenames
[i
].Len();
236 bool wxFileDataObject::SetData(
237 size_t WXUNUSED(nSize
)
243 // only add if this is not an empty string
244 // we can therefore clear the list by just setting an empty string
245 if ( (*(char*)pBuf
) != 0 )
246 AddFile(wxString::FromAscii((char*)pBuf
));
251 void wxFileDataObject::AddFile(
252 const wxString
& rFilename
255 m_filenames
.Add(rFilename
);
258 // ----------------------------------------------------------------------------
259 // wxBitmapDataObject
260 // ----------------------------------------------------------------------------
262 wxBitmapDataObject::wxBitmapDataObject()
267 wxBitmapDataObject::wxBitmapDataObject(
268 const wxBitmap
& rBitmap
270 : wxBitmapDataObjectBase(rBitmap
)
275 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
276 m_pictCreated
= false ;
280 wxBitmapDataObject::~wxBitmapDataObject()
285 void wxBitmapDataObject::SetBitmap(
286 const wxBitmap
& rBitmap
290 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
293 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
294 m_pictCreated
= false ;
298 void wxBitmapDataObject::Init()
300 m_pictHandle
= NULL
;
301 m_pictCreated
= false ;
304 void wxBitmapDataObject::Clear()
306 if ( m_pictCreated
&& m_pictHandle
)
308 KillPicture( (PicHandle
) m_pictHandle
) ;
310 m_pictHandle
= NULL
;
313 bool wxBitmapDataObject::GetDataHere(
319 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
322 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
326 size_t wxBitmapDataObject::GetDataSize() const
328 return GetHandleSize((Handle
)m_pictHandle
) ;
331 bool wxBitmapDataObject::SetData(
337 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
338 memcpy( *picHandle
, pBuf
, nSize
) ;
339 m_pictHandle
= picHandle
;
340 // ownership is transferred to the bitmap
341 m_pictCreated
= false ;
342 Rect frame
= (**picHandle
).picFrame
;
345 mf
.SetHMETAFILE( (WXHMETAFILE
) m_pictHandle
) ;
347 m_bitmap
.Create( frame
.right
- frame
.left
,frame
.bottom
- frame
.top
) ;
348 mdc
.SelectObject(m_bitmap
) ;
350 mdc
.SelectObject( wxNullBitmap
) ;
352 return m_bitmap
.Ok();