]>
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"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
50 wxDataFormat::wxDataFormat()
52 m_type
= wxDF_INVALID
;
56 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
61 wxDataFormat::wxDataFormat( const wxChar
* zId
)
66 wxDataFormat::wxDataFormat( const wxString
& rId
)
71 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
76 void wxDataFormat::SetType( wxDataFormatId Type
)
80 if (m_type
== wxDF_TEXT
)
81 m_format
= kScrapFlavorTypeText
;
82 else if (m_type
== wxDF_UNICODETEXT
)
83 m_format
= kScrapFlavorTypeUnicode
;
84 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
85 m_format
= kScrapFlavorTypePicture
;
86 else if (m_type
== wxDF_FILENAME
)
87 m_format
= kDragFlavorTypeHFS
;
90 wxFAIL_MSG( wxT("invalid dataformat") );
92 // this is '????' but it can't be used in the code because ??' is
93 // parsed as a trigraph!
94 m_format
= 0x3f3f3f3f;
98 wxString
wxDataFormat::GetId() const
100 // note that m_format is not a pointer to string, it *is* itself a 4
103 strncpy( text
, (char*) &m_format
, 4 ) ;
106 return wxString::FromAscii( text
) ;
109 void wxDataFormat::SetId( NativeFormat format
)
113 if (m_format
== kScrapFlavorTypeText
)
115 else if (m_format
== kScrapFlavorTypeUnicode
)
116 m_type
= wxDF_UNICODETEXT
;
117 else if (m_format
== kScrapFlavorTypePicture
)
118 m_type
= wxDF_BITMAP
;
119 else if (m_format
== kDragFlavorTypeHFS
)
120 m_type
= wxDF_FILENAME
;
122 m_type
= wxDF_PRIVATE
;
125 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 // ----------------------------------------------------------------------------
177 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
179 *formats
++ = wxDataFormat( wxDF_TEXT
);
180 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
189 bool wxFileDataObject::GetDataHere(
195 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
197 sFilenames
+= m_filenames
[i
];
198 sFilenames
+= (wxChar
)0;
201 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
205 size_t wxFileDataObject::GetDataSize() const
209 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
211 nRes
+= m_filenames
[i
].Len();
218 bool wxFileDataObject::SetData(
219 size_t WXUNUSED(nSize
)
225 // only add if this is not an empty string
226 // we can therefore clear the list by just setting an empty string
227 if ( (*(char*)pBuf
) != 0 )
228 AddFile(wxString::FromAscii((char*)pBuf
));
233 void wxFileDataObject::AddFile(
234 const wxString
& rFilename
237 m_filenames
.Add(rFilename
);
240 // ----------------------------------------------------------------------------
241 // wxBitmapDataObject
242 // ----------------------------------------------------------------------------
244 wxBitmapDataObject::wxBitmapDataObject()
249 wxBitmapDataObject::wxBitmapDataObject(
250 const wxBitmap
& rBitmap
252 : wxBitmapDataObjectBase(rBitmap
)
257 m_pictHandle
= wxMacCreatePicHandle( rBitmap
) ;
258 m_pictCreated
= true ;
262 wxBitmapDataObject::~wxBitmapDataObject()
267 void wxBitmapDataObject::SetBitmap(
268 const wxBitmap
& rBitmap
272 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
275 m_pictHandle
= wxMacCreatePicHandle( rBitmap
) ;
276 m_pictCreated
= true ;
280 void wxBitmapDataObject::Init()
282 m_pictHandle
= NULL
;
283 m_pictCreated
= false ;
286 void wxBitmapDataObject::Clear()
288 if ( m_pictCreated
&& m_pictHandle
)
290 KillPicture( (PicHandle
) m_pictHandle
) ;
292 m_pictHandle
= NULL
;
295 bool wxBitmapDataObject::GetDataHere(
301 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
304 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
308 size_t wxBitmapDataObject::GetDataSize() const
310 return GetHandleSize((Handle
)m_pictHandle
) ;
313 bool wxBitmapDataObject::SetData(
319 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
320 memcpy( *picHandle
, pBuf
, nSize
) ;
321 m_pictHandle
= picHandle
;
322 // ownership is transferred to the bitmap
323 m_pictCreated
= false ;
324 Rect frame
= (**picHandle
).picFrame
;
327 mf
.SetHMETAFILE( (WXHMETAFILE
) m_pictHandle
) ;
329 m_bitmap
.Create( frame
.right
- frame
.left
,frame
.bottom
- frame
.top
) ;
330 mdc
.SelectObject(m_bitmap
) ;
332 mdc
.SelectObject( wxNullBitmap
) ;
334 return m_bitmap
.Ok();