]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataobj.cpp
6096d47388640f283388b078897d44a19536eac1
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 // note that m_format is not a pointer to string, it *is* itself a 4
105 strncpy( text
, (char*) &m_format
, 4 ) ;
108 return wxString::FromAscii( text
) ;
111 void wxDataFormat::SetId( NativeFormat format
)
115 if (m_format
== kScrapFlavorTypeText
)
117 else if (m_format
== kScrapFlavorTypeUnicode
)
118 m_type
= wxDF_UNICODETEXT
;
119 else if (m_format
== kScrapFlavorTypePicture
)
120 m_type
= wxDF_BITMAP
;
121 else if (m_format
== kDragFlavorTypeHFS
)
122 m_type
= wxDF_FILENAME
;
124 m_type
= wxDF_PRIVATE
;
127 void wxDataFormat::SetId( const wxChar
* zId
)
129 m_type
= wxDF_PRIVATE
;
130 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
133 //-------------------------------------------------------------------------
135 //-------------------------------------------------------------------------
137 wxDataObject::wxDataObject()
141 bool wxDataObject::IsSupportedFormat(
142 const wxDataFormat
& rFormat
146 size_t nFormatCount
= GetFormatCount(vDir
);
148 if (nFormatCount
== 1)
150 return rFormat
== GetPreferredFormat();
154 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
155 GetAllFormats( pFormats
161 for (n
= 0; n
< nFormatCount
; n
++)
163 if (pFormats
[n
] == rFormat
)
170 return n
< nFormatCount
;
174 // ----------------------------------------------------------------------------
176 // ----------------------------------------------------------------------------
179 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
181 *formats
++ = wxDataFormat( wxDF_TEXT
);
182 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
187 // ----------------------------------------------------------------------------
189 // ----------------------------------------------------------------------------
191 bool wxFileDataObject::GetDataHere(
197 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
199 sFilenames
+= m_filenames
[i
];
200 sFilenames
+= (wxChar
)0;
203 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
207 size_t wxFileDataObject::GetDataSize() const
211 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
213 nRes
+= m_filenames
[i
].Len();
220 bool wxFileDataObject::SetData(
221 size_t WXUNUSED(nSize
)
227 // only add if this is not an empty string
228 // we can therefore clear the list by just setting an empty string
229 if ( (*(char*)pBuf
) != 0 )
230 AddFile(wxString::FromAscii((char*)pBuf
));
235 void wxFileDataObject::AddFile(
236 const wxString
& rFilename
239 m_filenames
.Add(rFilename
);
242 // ----------------------------------------------------------------------------
243 // wxBitmapDataObject
244 // ----------------------------------------------------------------------------
246 wxBitmapDataObject::wxBitmapDataObject()
251 wxBitmapDataObject::wxBitmapDataObject(
252 const wxBitmap
& rBitmap
254 : wxBitmapDataObjectBase(rBitmap
)
259 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
260 m_pictCreated
= false ;
264 wxBitmapDataObject::~wxBitmapDataObject()
269 void wxBitmapDataObject::SetBitmap(
270 const wxBitmap
& rBitmap
274 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
277 m_pictHandle
= m_bitmap
.GetBitmapData()->GetPictHandle() ;
278 m_pictCreated
= false ;
282 void wxBitmapDataObject::Init()
284 m_pictHandle
= NULL
;
285 m_pictCreated
= false ;
288 void wxBitmapDataObject::Clear()
290 if ( m_pictCreated
&& m_pictHandle
)
292 KillPicture( (PicHandle
) m_pictHandle
) ;
294 m_pictHandle
= NULL
;
297 bool wxBitmapDataObject::GetDataHere(
303 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
306 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
310 size_t wxBitmapDataObject::GetDataSize() const
312 return GetHandleSize((Handle
)m_pictHandle
) ;
315 bool wxBitmapDataObject::SetData(
321 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
322 memcpy( *picHandle
, pBuf
, nSize
) ;
323 m_pictHandle
= picHandle
;
324 // ownership is transferred to the bitmap
325 m_pictCreated
= false ;
326 Rect frame
= (**picHandle
).picFrame
;
329 mf
.SetHMETAFILE( (WXHMETAFILE
) m_pictHandle
) ;
331 m_bitmap
.Create( frame
.right
- frame
.left
,frame
.bottom
- frame
.top
) ;
332 mdc
.SelectObject(m_bitmap
) ;
334 mdc
.SelectObject( wxNullBitmap
) ;
336 return m_bitmap
.Ok();