]>
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
;
87 wxFAIL_MSG( wxT("invalid dataformat") );
93 wxString
wxDataFormat::GetId() const
95 // note that m_format is not a pointer to string, it *is* itself a 4
98 strncpy( text
, (char*) &m_format
, 4 ) ;
101 return wxString::FromAscii( text
) ;
104 void wxDataFormat::SetId( NativeFormat format
)
108 if (m_format
== kScrapFlavorTypeText
)
110 else if (m_format
== kScrapFlavorTypeUnicode
)
111 m_type
= wxDF_UNICODETEXT
;
112 else if (m_format
== kScrapFlavorTypePicture
)
113 m_type
= wxDF_BITMAP
;
114 else if (m_format
== kDragFlavorTypeHFS
)
115 m_type
= wxDF_FILENAME
;
117 m_type
= wxDF_PRIVATE
;
120 void wxDataFormat::SetId( const wxChar
* zId
)
122 m_type
= wxDF_PRIVATE
;
123 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
126 //-------------------------------------------------------------------------
128 //-------------------------------------------------------------------------
130 wxDataObject::wxDataObject()
134 bool wxDataObject::IsSupportedFormat(
135 const wxDataFormat
& rFormat
139 size_t nFormatCount
= GetFormatCount(vDir
);
141 if (nFormatCount
== 1)
143 return rFormat
== GetPreferredFormat();
147 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
148 GetAllFormats( pFormats
154 for (n
= 0; n
< nFormatCount
; n
++)
156 if (pFormats
[n
] == rFormat
)
163 return n
< nFormatCount
;
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 bool wxFileDataObject::GetDataHere(
177 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
179 sFilenames
+= m_filenames
[i
];
180 sFilenames
+= (wxChar
)0;
183 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
187 size_t wxFileDataObject::GetDataSize() const
191 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
193 nRes
+= m_filenames
[i
].Len();
200 bool wxFileDataObject::SetData(
201 size_t WXUNUSED(nSize
)
207 AddFile(wxString::FromAscii((char*)pBuf
));
212 void wxFileDataObject::AddFile(
213 const wxString
& rFilename
216 m_filenames
.Add(rFilename
);
219 // ----------------------------------------------------------------------------
220 // wxBitmapDataObject
221 // ----------------------------------------------------------------------------
223 wxBitmapDataObject::wxBitmapDataObject()
228 wxBitmapDataObject::wxBitmapDataObject(
229 const wxBitmap
& rBitmap
231 : wxBitmapDataObjectBase(rBitmap
)
236 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
240 wxBitmapDataObject::~wxBitmapDataObject()
245 void wxBitmapDataObject::SetBitmap(
246 const wxBitmap
& rBitmap
250 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
253 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
257 void wxBitmapDataObject::Init()
259 m_pictHandle
= NULL
;
260 m_pictCreated
= false ;
263 void wxBitmapDataObject::Clear()
265 if ( m_pictCreated
&& m_pictHandle
)
267 KillPicture( (PicHandle
) m_pictHandle
) ;
269 m_pictHandle
= NULL
;
272 bool wxBitmapDataObject::GetDataHere(
278 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
281 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
285 size_t wxBitmapDataObject::GetDataSize() const
287 return GetHandleSize((Handle
)m_pictHandle
) ;
290 bool wxBitmapDataObject::SetData(
296 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
297 memcpy( *picHandle
, pBuf
, nSize
) ;
298 m_pictHandle
= picHandle
;
299 m_pictCreated
= false ;
300 Rect frame
= (**picHandle
).picFrame
;
302 m_bitmap
.SetPict( picHandle
) ;
303 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
304 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
305 return m_bitmap
.Ok();