]>
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/dcmemory.h"
34 #include "wx/mstream.h"
36 #include "wx/metafile.h"
37 #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 // note that m_format is not a pointer to string, it *is* itself a 4
101 strncpy( text
, (char*) &m_format
, 4 ) ;
104 return wxString::FromAscii( text
) ;
107 void wxDataFormat::SetId( NativeFormat format
)
111 if (m_format
== kScrapFlavorTypeText
)
113 else if (m_format
== kScrapFlavorTypeUnicode
)
114 m_type
= wxDF_UNICODETEXT
;
115 else if (m_format
== kScrapFlavorTypePicture
)
116 m_type
= wxDF_BITMAP
;
117 else if (m_format
== kDragFlavorTypeHFS
)
118 m_type
= wxDF_FILENAME
;
120 m_type
= wxDF_PRIVATE
;
123 void wxDataFormat::SetId( const wxChar
* zId
)
125 m_type
= wxDF_PRIVATE
;
126 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
129 //-------------------------------------------------------------------------
131 //-------------------------------------------------------------------------
133 wxDataObject::wxDataObject()
137 bool wxDataObject::IsSupportedFormat(
138 const wxDataFormat
& rFormat
142 size_t nFormatCount
= GetFormatCount(vDir
);
144 if (nFormatCount
== 1)
146 return rFormat
== GetPreferredFormat();
150 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
151 GetAllFormats( pFormats
157 for (n
= 0; n
< nFormatCount
; n
++)
159 if (pFormats
[n
] == rFormat
)
166 return n
< nFormatCount
;
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
175 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
177 *formats
++ = wxDataFormat( wxDF_TEXT
);
178 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
183 // ----------------------------------------------------------------------------
185 // ----------------------------------------------------------------------------
187 bool wxFileDataObject::GetDataHere(
193 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
195 sFilenames
+= m_filenames
[i
];
196 sFilenames
+= (wxChar
)0;
199 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
203 size_t wxFileDataObject::GetDataSize() const
207 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
209 nRes
+= m_filenames
[i
].Len();
216 bool wxFileDataObject::SetData(
217 size_t WXUNUSED(nSize
)
223 // only add if this is not an empty string
224 // we can therefore clear the list by just setting an empty string
225 if ( (*(char*)pBuf
) != 0 )
226 AddFile(wxString::FromAscii((char*)pBuf
));
231 void wxFileDataObject::AddFile(
232 const wxString
& rFilename
235 m_filenames
.Add(rFilename
);
238 // ----------------------------------------------------------------------------
239 // wxBitmapDataObject
240 // ----------------------------------------------------------------------------
242 wxBitmapDataObject::wxBitmapDataObject()
247 wxBitmapDataObject::wxBitmapDataObject(
248 const wxBitmap
& rBitmap
250 : wxBitmapDataObjectBase(rBitmap
)
255 m_pictHandle
= wxMacCreatePicHandle( rBitmap
) ;
256 m_pictCreated
= true ;
260 wxBitmapDataObject::~wxBitmapDataObject()
265 void wxBitmapDataObject::SetBitmap(
266 const wxBitmap
& rBitmap
270 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
273 m_pictHandle
= wxMacCreatePicHandle( rBitmap
) ;
274 m_pictCreated
= true ;
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
;
325 mf
.SetHMETAFILE( (WXHMETAFILE
) m_pictHandle
) ;
327 m_bitmap
.Create( frame
.right
- frame
.left
,frame
.bottom
- frame
.top
) ;
328 mdc
.SelectObject(m_bitmap
) ;
330 mdc
.SelectObject( wxNullBitmap
) ;
332 return m_bitmap
.Ok();