]>
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"
32 #include "wx/dataobj.h"
33 #include "wx/mstream.h"
35 #include "wx/mac/private.h"
38 // ----------------------------------------------------------------------------
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 wxDataFormat::wxDataFormat()
48 m_type
= wxDF_INVALID
;
52 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
57 wxDataFormat::wxDataFormat( const wxChar
* zId
)
62 wxDataFormat::wxDataFormat( const wxString
& rId
)
67 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
72 void wxDataFormat::SetType( wxDataFormatId Type
)
76 if (m_type
== wxDF_TEXT
)
77 m_format
= kScrapFlavorTypeText
;
78 else if (m_type
== wxDF_UNICODETEXT
)
79 m_format
= kScrapFlavorTypeUnicode
;
80 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
81 m_format
= kScrapFlavorTypePicture
;
82 else if (m_type
== wxDF_FILENAME
)
83 m_format
= kDragFlavorTypeHFS
;
86 wxFAIL_MSG( wxT("invalid dataformat") );
88 // this is '????' but it can't be used in the code because ??' is
89 // parsed as a trigraph!
90 m_format
= 0x3f3f3f3f;
94 wxString
wxDataFormat::GetId() const
96 // note that m_format is not a pointer to string, it *is* itself a 4
99 strncpy( text
, (char*) &m_format
, 4 ) ;
102 return wxString::FromAscii( text
) ;
105 void wxDataFormat::SetId( NativeFormat format
)
109 if (m_format
== kScrapFlavorTypeText
)
111 else if (m_format
== kScrapFlavorTypeUnicode
)
112 m_type
= wxDF_UNICODETEXT
;
113 else if (m_format
== kScrapFlavorTypePicture
)
114 m_type
= wxDF_BITMAP
;
115 else if (m_format
== kDragFlavorTypeHFS
)
116 m_type
= wxDF_FILENAME
;
118 m_type
= wxDF_PRIVATE
;
121 void wxDataFormat::SetId( const wxChar
* zId
)
123 m_type
= wxDF_PRIVATE
;
124 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
127 //-------------------------------------------------------------------------
129 //-------------------------------------------------------------------------
131 wxDataObject::wxDataObject()
135 bool wxDataObject::IsSupportedFormat(
136 const wxDataFormat
& rFormat
140 size_t nFormatCount
= GetFormatCount(vDir
);
142 if (nFormatCount
== 1)
144 return rFormat
== GetPreferredFormat();
148 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
149 GetAllFormats( pFormats
155 for (n
= 0; n
< nFormatCount
; n
++)
157 if (pFormats
[n
] == rFormat
)
164 return n
< nFormatCount
;
168 // ----------------------------------------------------------------------------
170 // ----------------------------------------------------------------------------
173 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
175 *formats
++ = wxDataFormat( wxDF_TEXT
);
176 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
181 // ----------------------------------------------------------------------------
183 // ----------------------------------------------------------------------------
185 bool wxFileDataObject::GetDataHere(
191 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
193 sFilenames
+= m_filenames
[i
];
194 sFilenames
+= (wxChar
)0;
197 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
201 size_t wxFileDataObject::GetDataSize() const
205 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
207 nRes
+= m_filenames
[i
].Len();
214 bool wxFileDataObject::SetData(
215 size_t WXUNUSED(nSize
)
221 // only add if this is not an empty string
222 // we can therefore clear the list by just setting an empty string
223 if ( (*(char*)pBuf
) != 0 )
224 AddFile(wxString::FromAscii((char*)pBuf
));
229 void wxFileDataObject::AddFile(
230 const wxString
& rFilename
233 m_filenames
.Add(rFilename
);
236 // ----------------------------------------------------------------------------
237 // wxBitmapDataObject
238 // ----------------------------------------------------------------------------
240 wxBitmapDataObject::wxBitmapDataObject()
245 wxBitmapDataObject::wxBitmapDataObject(
246 const wxBitmap
& rBitmap
248 : wxBitmapDataObjectBase(rBitmap
)
254 m_pictHandle = m_bitmap.GetBitmapData()->GetPict( &m_pictCreated ) ;
259 wxBitmapDataObject::~wxBitmapDataObject()
264 void wxBitmapDataObject::SetBitmap(
265 const wxBitmap
& rBitmap
269 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
273 m_pictHandle = m_bitmap.GetBitmapData()->GetPict( &m_pictCreated ) ;
278 void wxBitmapDataObject::Init()
280 m_pictHandle
= NULL
;
281 m_pictCreated
= false ;
284 void wxBitmapDataObject::Clear()
286 if ( m_pictCreated
&& m_pictHandle
)
288 KillPicture( (PicHandle
) m_pictHandle
) ;
290 m_pictHandle
= NULL
;
293 bool wxBitmapDataObject::GetDataHere(
299 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
302 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
306 size_t wxBitmapDataObject::GetDataSize() const
308 return GetHandleSize((Handle
)m_pictHandle
) ;
311 bool wxBitmapDataObject::SetData(
317 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
318 memcpy( *picHandle
, pBuf
, nSize
) ;
319 m_pictHandle
= picHandle
;
320 // ownership is transferred to the bitmap
321 m_pictCreated
= false ;
322 Rect frame
= (**picHandle
).picFrame
;
324 m_bitmap.GetBitmapData()->SetPict( (WXHMETAFILE) picHandle ) ;
325 m_bitmap.SetWidth( frame.right - frame.left ) ;
326 m_bitmap.SetHeight( frame.bottom - frame.top ) ;
328 return m_bitmap
.Ok();