]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: os2/dataobj.cpp
3 // Purpose: implementation of wx[I]DataObject class
4 // Author: David Webster
8 // Copyright: (c) 1999 David Webster
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dataobj.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
33 #include "wx/dataobj.h"
34 #include "wx/mstream.h"
36 #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
)
78 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
80 else if (m_type
== wxDF_FILENAME
)
81 m_format
= kDragFlavorTypeHFS
;
84 wxFAIL_MSG( wxT("invalid dataformat") );
88 wxDataFormatId
wxDataFormat::GetType() const
93 wxString
wxDataFormat::GetId() const
95 wxString
sRet(""); // TODO: to name of ( m_format ) );
99 void wxDataFormat::SetId( NativeFormat format
)
103 if (m_format
== 'TEXT')
106 if (m_format
== 'PICT')
107 m_type
= wxDF_BITMAP
;
109 if (m_format
== kDragFlavorTypeHFS
)
110 m_type
= wxDF_FILENAME
;
112 m_type
= wxDF_PRIVATE
;
115 void wxDataFormat::SetId( const wxChar
* zId
)
119 m_type
= wxDF_PRIVATE
;
120 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
123 //-------------------------------------------------------------------------
125 //-------------------------------------------------------------------------
127 wxDataObject::wxDataObject()
131 bool wxDataObject::IsSupportedFormat(
132 const wxDataFormat
& rFormat
136 size_t nFormatCount
= GetFormatCount(vDir
);
138 if (nFormatCount
== 1)
140 return rFormat
== GetPreferredFormat();
144 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
145 GetAllFormats( pFormats
151 for (n
= 0; n
< nFormatCount
; n
++)
153 if (pFormats
[n
] == rFormat
)
160 return n
< nFormatCount
;
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
168 bool wxFileDataObject::GetDataHere(
174 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
176 sFilenames
+= m_filenames
[i
];
177 sFilenames
+= (wxChar
)0;
180 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
184 size_t wxFileDataObject::GetDataSize() const
188 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
190 nRes
+= m_filenames
[i
].Len();
197 bool wxFileDataObject::SetData(
198 size_t WXUNUSED(nSize
)
204 wxString
sFile( (const char *)pBuf
); /* char, not wxChar */
211 void wxFileDataObject::AddFile(
212 const wxString
& rFilename
215 m_filenames
.Add(rFilename
);
218 // ----------------------------------------------------------------------------
219 // wxBitmapDataObject
220 // ----------------------------------------------------------------------------
222 wxBitmapDataObject::wxBitmapDataObject()
227 wxBitmapDataObject::wxBitmapDataObject(
228 const wxBitmap
& rBitmap
230 : wxBitmapDataObjectBase(rBitmap
)
235 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
239 wxBitmapDataObject::~wxBitmapDataObject()
244 void wxBitmapDataObject::SetBitmap(
245 const wxBitmap
& rBitmap
249 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
252 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
256 void wxBitmapDataObject::Init()
258 m_pictHandle
= NULL
;
259 m_pictCreated
= false ;
262 void wxBitmapDataObject::Clear()
264 if ( m_pictCreated
&& m_pictHandle
)
266 KillPicture( (PicHandle
) m_pictHandle
) ;
268 m_pictHandle
= NULL
;
271 bool wxBitmapDataObject::GetDataHere(
277 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
280 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
284 size_t wxBitmapDataObject::GetDataSize() const
286 return GetHandleSize((Handle
)m_pictHandle
) ;
289 bool wxBitmapDataObject::SetData(
295 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
296 memcpy( *picHandle
, pBuf
, nSize
) ;
297 m_pictHandle
= picHandle
;
298 m_pictCreated
= false ;
299 Rect frame
= (**picHandle
).picFrame
;
301 m_bitmap
.SetPict( picHandle
) ;
302 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
303 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
304 return m_bitmap
.Ok();