]>
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 // ----------------------------------------------------------------------------
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"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxDataFormat::wxDataFormat()
49 m_type
= wxDF_INVALID
;
53 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
58 wxDataFormat::wxDataFormat( const wxChar
* zId
)
63 wxDataFormat::wxDataFormat( const wxString
& rId
)
68 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
73 void wxDataFormat::SetType( wxDataFormatId Type
)
77 if (m_type
== wxDF_TEXT
)
78 m_format
= kScrapFlavorTypeText
;
79 else if (m_type
== wxDF_UNICODETEXT
)
80 m_format
= kScrapFlavorTypeUnicode
;
81 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
82 m_format
= kScrapFlavorTypePicture
;
83 else if (m_type
== wxDF_FILENAME
)
84 m_format
= kDragFlavorTypeHFS
;
87 wxFAIL_MSG( wxT("invalid dataformat") );
91 wxDataFormatId
wxDataFormat::GetType() const
96 wxString
wxDataFormat::GetId() const
99 strncpy( text
, (char*) m_format
, 4 ) ;
101 return wxString::FromAscii( text
) ;
104 void wxDataFormat::SetId( NativeFormat format
)
108 if (m_format
== kScrapFlavorTypeText
)
111 if (m_format
== kScrapFlavorTypeUnicode
)
112 m_type
= wxDF_UNICODETEXT
;
114 if (m_format
== kScrapFlavorTypePicture
)
115 m_type
= wxDF_BITMAP
;
117 if (m_format
== kDragFlavorTypeHFS
)
118 m_type
= wxDF_FILENAME
;
120 m_type
= wxDF_PRIVATE
;
123 void wxDataFormat::SetId( const wxChar
* zId
)
127 m_type
= wxDF_PRIVATE
;
128 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
131 //-------------------------------------------------------------------------
133 //-------------------------------------------------------------------------
135 wxDataObject::wxDataObject()
139 bool wxDataObject::IsSupportedFormat(
140 const wxDataFormat
& rFormat
144 size_t nFormatCount
= GetFormatCount(vDir
);
146 if (nFormatCount
== 1)
148 return rFormat
== GetPreferredFormat();
152 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
153 GetAllFormats( pFormats
159 for (n
= 0; n
< nFormatCount
; n
++)
161 if (pFormats
[n
] == rFormat
)
168 return n
< nFormatCount
;
172 // ----------------------------------------------------------------------------
174 // ----------------------------------------------------------------------------
176 bool wxFileDataObject::GetDataHere(
182 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
184 sFilenames
+= m_filenames
[i
];
185 sFilenames
+= (wxChar
)0;
188 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
192 size_t wxFileDataObject::GetDataSize() const
196 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
198 nRes
+= m_filenames
[i
].Len();
205 bool wxFileDataObject::SetData(
206 size_t WXUNUSED(nSize
)
212 AddFile(wxString::FromAscii((char*)pBuf
));
217 void wxFileDataObject::AddFile(
218 const wxString
& rFilename
221 m_filenames
.Add(rFilename
);
224 // ----------------------------------------------------------------------------
225 // wxBitmapDataObject
226 // ----------------------------------------------------------------------------
228 wxBitmapDataObject::wxBitmapDataObject()
233 wxBitmapDataObject::wxBitmapDataObject(
234 const wxBitmap
& rBitmap
236 : wxBitmapDataObjectBase(rBitmap
)
241 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
245 wxBitmapDataObject::~wxBitmapDataObject()
250 void wxBitmapDataObject::SetBitmap(
251 const wxBitmap
& rBitmap
255 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
258 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
262 void wxBitmapDataObject::Init()
264 m_pictHandle
= NULL
;
265 m_pictCreated
= false ;
268 void wxBitmapDataObject::Clear()
270 if ( m_pictCreated
&& m_pictHandle
)
272 KillPicture( (PicHandle
) m_pictHandle
) ;
274 m_pictHandle
= NULL
;
277 bool wxBitmapDataObject::GetDataHere(
283 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
286 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
290 size_t wxBitmapDataObject::GetDataSize() const
292 return GetHandleSize((Handle
)m_pictHandle
) ;
295 bool wxBitmapDataObject::SetData(
301 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
302 memcpy( *picHandle
, pBuf
, nSize
) ;
303 m_pictHandle
= picHandle
;
304 m_pictCreated
= false ;
305 Rect frame
= (**picHandle
).picFrame
;
307 m_bitmap
.SetPict( picHandle
) ;
308 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
309 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
310 return m_bitmap
.Ok();