]>
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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
30 #include "wx/dataobj.h"
31 #include "wx/dcmemory.h"
32 #include "wx/mstream.h"
34 #include "wx/metafile.h"
35 #include "wx/mac/private.h"
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 wxDataFormat::wxDataFormat()
50 m_type
= wxDF_INVALID
;
54 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
59 wxDataFormat::wxDataFormat( const wxChar
* zId
)
64 wxDataFormat::wxDataFormat( const wxString
& rId
)
69 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
74 void wxDataFormat::SetType( wxDataFormatId Type
)
78 if (m_type
== wxDF_TEXT
)
79 m_format
= kScrapFlavorTypeText
;
80 else if (m_type
== wxDF_UNICODETEXT
)
81 m_format
= kScrapFlavorTypeUnicode
;
82 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
83 m_format
= kScrapFlavorTypePicture
;
84 else if (m_type
== wxDF_FILENAME
)
85 m_format
= kDragFlavorTypeHFS
;
88 wxFAIL_MSG( wxT("invalid dataformat") );
90 // this is '????' but it can't be used in the code because ??' is
91 // parsed as a trigraph!
92 m_format
= 0x3f3f3f3f;
96 wxString
wxDataFormat::GetId() const
98 wxCHECK_MSG( !IsStandard(), wxEmptyString
,
99 wxT("name of predefined format cannot be retrieved") );
104 void wxDataFormat::SetId( NativeFormat format
)
108 if (m_format
== kScrapFlavorTypeText
)
110 else if (m_format
== kScrapFlavorTypeUnicode
)
111 m_type
= wxDF_UNICODETEXT
;
112 else if (m_format
== kScrapFlavorTypePicture
)
113 m_type
= wxDF_BITMAP
;
114 else if (m_format
== kDragFlavorTypeHFS
)
115 m_type
= wxDF_FILENAME
;
118 m_type
= wxDF_PRIVATE
;
120 strncpy( text
, (char*) &format
, 4 ) ;
122 m_id
= wxString::FromAscii( text
) ;
126 void wxDataFormat::SetId( const wxChar
* zId
)
128 m_type
= wxDF_PRIVATE
;
133 bool wxDataFormat::operator==(const wxDataFormat
& format
) const
135 if ( IsStandard() || format
.IsStandard() )
137 return ( format
.m_type
== m_type
) ;
141 return ( m_id
== format
.m_id
) ;
145 //-------------------------------------------------------------------------
147 //-------------------------------------------------------------------------
149 wxDataObject::wxDataObject()
153 bool wxDataObject::IsSupportedFormat(
154 const wxDataFormat
& rFormat
158 size_t nFormatCount
= GetFormatCount(vDir
);
160 if (nFormatCount
== 1)
162 return rFormat
== GetPreferredFormat();
166 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
167 GetAllFormats( pFormats
173 for (n
= 0; n
< nFormatCount
; n
++)
175 if (pFormats
[n
] == rFormat
)
182 return n
< nFormatCount
;
186 // ----------------------------------------------------------------------------
188 // ----------------------------------------------------------------------------
191 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
193 *formats
++ = wxDataFormat( wxDF_TEXT
);
194 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
199 // ----------------------------------------------------------------------------
201 // ----------------------------------------------------------------------------
203 bool wxFileDataObject::GetDataHere(
209 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
211 sFilenames
+= m_filenames
[i
];
212 sFilenames
+= (wxChar
)0;
215 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
219 size_t wxFileDataObject::GetDataSize() const
223 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
225 nRes
+= m_filenames
[i
].Len();
232 bool wxFileDataObject::SetData(
233 size_t WXUNUSED(nSize
)
239 // only add if this is not an empty string
240 // we can therefore clear the list by just setting an empty string
241 if ( (*(char*)pBuf
) != 0 )
242 AddFile(wxString::FromAscii((char*)pBuf
));
247 void wxFileDataObject::AddFile(
248 const wxString
& rFilename
251 m_filenames
.Add(rFilename
);
254 // ----------------------------------------------------------------------------
255 // wxBitmapDataObject
256 // ----------------------------------------------------------------------------
258 wxBitmapDataObject::wxBitmapDataObject()
263 wxBitmapDataObject::wxBitmapDataObject(
264 const wxBitmap
& rBitmap
266 : wxBitmapDataObjectBase(rBitmap
)
271 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
272 m_pictCreated
= false ;
276 wxBitmapDataObject::~wxBitmapDataObject()
281 void wxBitmapDataObject::SetBitmap(
282 const wxBitmap
& rBitmap
286 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
289 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
290 m_pictCreated
= false ;
294 void wxBitmapDataObject::Init()
296 m_pictHandle
= NULL
;
297 m_pictCreated
= false ;
300 void wxBitmapDataObject::Clear()
302 if ( m_pictCreated
&& m_pictHandle
)
304 KillPicture( (PicHandle
) m_pictHandle
) ;
306 m_pictHandle
= NULL
;
309 bool wxBitmapDataObject::GetDataHere(
315 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
318 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
322 size_t wxBitmapDataObject::GetDataSize() const
324 return GetHandleSize((Handle
)m_pictHandle
) ;
327 bool wxBitmapDataObject::SetData(
333 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
334 memcpy( *picHandle
, pBuf
, nSize
) ;
335 m_pictHandle
= picHandle
;
336 // ownership is transferred to the bitmap
337 m_pictCreated
= false ;
338 Rect frame
= (**picHandle
).picFrame
;
341 mf
.SetHMETAFILE( (WXHMETAFILE
) m_pictHandle
) ;
343 m_bitmap
.Create( frame
.right
- frame
.left
,frame
.bottom
- frame
.top
) ;
344 mdc
.SelectObject(m_bitmap
) ;
346 mdc
.SelectObject( wxNullBitmap
) ;
348 return m_bitmap
.Ok();