]>
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
)
253 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
257 wxBitmapDataObject::~wxBitmapDataObject()
262 void wxBitmapDataObject::SetBitmap(
263 const wxBitmap
& rBitmap
267 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
270 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
274 void wxBitmapDataObject::Init()
276 m_pictHandle
= NULL
;
277 m_pictCreated
= false ;
280 void wxBitmapDataObject::Clear()
282 if ( m_pictCreated
&& m_pictHandle
)
284 KillPicture( (PicHandle
) m_pictHandle
) ;
286 m_pictHandle
= NULL
;
289 bool wxBitmapDataObject::GetDataHere(
295 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
298 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
302 size_t wxBitmapDataObject::GetDataSize() const
304 return GetHandleSize((Handle
)m_pictHandle
) ;
307 bool wxBitmapDataObject::SetData(
313 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
314 memcpy( *picHandle
, pBuf
, nSize
) ;
315 m_pictHandle
= picHandle
;
316 m_pictCreated
= false ;
317 Rect frame
= (**picHandle
).picFrame
;
319 m_bitmap
.SetPict( picHandle
) ;
320 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
321 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
322 return m_bitmap
.Ok();