]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/dataobj.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/dataobj.cpp
3 // Purpose: implementation of wxDataObject class
4 // Author: Stefan Csomor
8 // Copyright: (c) 1999 Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
18 // ============================================================================
20 // ============================================================================
22 // ----------------------------------------------------------------------------
24 // ----------------------------------------------------------------------------
26 #include "wx/dataobj.h"
34 #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 // ----------------------------------------------------------------------------
172 bool wxFileDataObject::GetDataHere( void* pBuf
) const
176 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
178 sFilenames
+= m_filenames
[i
];
179 sFilenames
+= (wxChar
)0;
182 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.length() + 1);
186 size_t wxFileDataObject::GetDataSize() const
190 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
192 nRes
+= m_filenames
[i
].length();
199 bool wxFileDataObject::SetData(
200 size_t WXUNUSED(nSize
)
206 AddFile(wxString::FromAscii((char*)pBuf
));
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( void* pBuf
) const
275 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
278 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
282 size_t wxBitmapDataObject::GetDataSize() const
284 return GetHandleSize((Handle
)m_pictHandle
) ;
287 bool wxBitmapDataObject::SetData(
293 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
294 memcpy( *picHandle
, pBuf
, nSize
) ;
295 m_pictHandle
= picHandle
;
296 m_pictCreated
= false ;
297 Rect frame
= (**picHandle
).picFrame
;
299 m_bitmap
.SetPict( picHandle
) ;
300 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
301 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
302 return m_bitmap
.Ok();