]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/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 // ----------------------------------------------------------------------------
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"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 wxDataFormat::wxDataFormat()
49 m_type
= wxDF_INVALID
;
53 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
58 wxDataFormat::wxDataFormat( const wxChar
* zId
)
63 wxDataFormat::wxDataFormat( const wxString
& rId
)
68 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
73 void wxDataFormat::SetType( wxDataFormatId Type
)
77 if (m_type
== wxDF_TEXT
)
78 m_format
= kScrapFlavorTypeText
;
79 else if (m_type
== wxDF_UNICODETEXT
)
80 m_format
= kScrapFlavorTypeUnicode
;
81 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
82 m_format
= kScrapFlavorTypePicture
;
83 else if (m_type
== wxDF_FILENAME
)
84 m_format
= kDragFlavorTypeHFS
;
88 wxFAIL_MSG( wxT("invalid dataformat") );
92 wxDataFormatId
wxDataFormat::GetType() const
97 wxString
wxDataFormat::GetId() const
100 strncpy( text
, (char*) &m_format
, 4 ) ;
102 return wxString::FromAscii( text
) ;
105 void wxDataFormat::SetId( NativeFormat format
)
109 if (m_format
== kScrapFlavorTypeText
)
112 if (m_format
== kScrapFlavorTypeUnicode
)
113 m_type
= wxDF_UNICODETEXT
;
115 if (m_format
== kScrapFlavorTypePicture
)
116 m_type
= wxDF_BITMAP
;
118 if (m_format
== kDragFlavorTypeHFS
)
119 m_type
= wxDF_FILENAME
;
121 m_type
= wxDF_PRIVATE
;
124 void wxDataFormat::SetId( const wxChar
* zId
)
128 m_type
= wxDF_PRIVATE
;
129 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
132 //-------------------------------------------------------------------------
134 //-------------------------------------------------------------------------
136 wxDataObject::wxDataObject()
140 bool wxDataObject::IsSupportedFormat(
141 const wxDataFormat
& rFormat
145 size_t nFormatCount
= GetFormatCount(vDir
);
147 if (nFormatCount
== 1)
149 return rFormat
== GetPreferredFormat();
153 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
154 GetAllFormats( pFormats
160 for (n
= 0; n
< nFormatCount
; n
++)
162 if (pFormats
[n
] == rFormat
)
169 return n
< nFormatCount
;
173 // ----------------------------------------------------------------------------
175 // ----------------------------------------------------------------------------
177 bool wxFileDataObject::GetDataHere(
183 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
185 sFilenames
+= m_filenames
[i
];
186 sFilenames
+= (wxChar
)0;
189 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
193 size_t wxFileDataObject::GetDataSize() const
197 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
199 nRes
+= m_filenames
[i
].Len();
206 bool wxFileDataObject::SetData(
207 size_t WXUNUSED(nSize
)
213 AddFile(wxString::FromAscii((char*)pBuf
));
218 void wxFileDataObject::AddFile(
219 const wxString
& rFilename
222 m_filenames
.Add(rFilename
);
225 // ----------------------------------------------------------------------------
226 // wxBitmapDataObject
227 // ----------------------------------------------------------------------------
229 wxBitmapDataObject::wxBitmapDataObject()
234 wxBitmapDataObject::wxBitmapDataObject(
235 const wxBitmap
& rBitmap
237 : wxBitmapDataObjectBase(rBitmap
)
242 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
246 wxBitmapDataObject::~wxBitmapDataObject()
251 void wxBitmapDataObject::SetBitmap(
252 const wxBitmap
& rBitmap
256 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
259 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
263 void wxBitmapDataObject::Init()
265 m_pictHandle
= NULL
;
266 m_pictCreated
= false ;
269 void wxBitmapDataObject::Clear()
271 if ( m_pictCreated
&& m_pictHandle
)
273 KillPicture( (PicHandle
) m_pictHandle
) ;
275 m_pictHandle
= NULL
;
278 bool wxBitmapDataObject::GetDataHere(
284 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
287 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
291 size_t wxBitmapDataObject::GetDataSize() const
293 return GetHandleSize((Handle
)m_pictHandle
) ;
296 bool wxBitmapDataObject::SetData(
302 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
303 memcpy( *picHandle
, pBuf
, nSize
) ;
304 m_pictHandle
= picHandle
;
305 m_pictCreated
= false ;
306 Rect frame
= (**picHandle
).picFrame
;
308 m_bitmap
.SetPict( picHandle
) ;
309 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
310 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
311 return m_bitmap
.Ok();