]>
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 // ----------------------------------------------------------------------------
31 #include "wx/dataobj.h"
32 #include "wx/mstream.h"
34 #include "wx/mac/private.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 // ----------------------------------------------------------------------------
45 wxDataFormat::wxDataFormat()
47 m_type
= wxDF_INVALID
;
51 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
56 wxDataFormat::wxDataFormat( const wxChar
* zId
)
61 wxDataFormat::wxDataFormat( const wxString
& rId
)
66 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
71 void wxDataFormat::SetType( wxDataFormatId Type
)
75 if (m_type
== wxDF_TEXT
)
76 m_format
= kScrapFlavorTypeText
;
77 else if (m_type
== wxDF_UNICODETEXT
)
78 m_format
= kScrapFlavorTypeUnicode
;
79 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
80 m_format
= kScrapFlavorTypePicture
;
81 else if (m_type
== wxDF_FILENAME
)
82 m_format
= kDragFlavorTypeHFS
;
85 wxFAIL_MSG( wxT("invalid dataformat") );
87 // this is '????' but it can't be used in the code because ??' is
88 // parsed as a trigraph!
89 m_format
= 0x3f3f3f3f;
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( void* pBuf
) const
175 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
177 sFilenames
+= m_filenames
[i
];
178 sFilenames
+= (wxChar
)0;
181 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
185 size_t wxFileDataObject::GetDataSize() const
189 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
191 nRes
+= m_filenames
[i
].Len();
198 bool wxFileDataObject::SetData(
199 size_t WXUNUSED(nSize
)
205 AddFile(wxString::FromAscii((char*)pBuf
));
210 void wxFileDataObject::AddFile(
211 const wxString
& rFilename
214 m_filenames
.Add(rFilename
);
217 // ----------------------------------------------------------------------------
218 // wxBitmapDataObject
219 // ----------------------------------------------------------------------------
221 wxBitmapDataObject::wxBitmapDataObject()
226 wxBitmapDataObject::wxBitmapDataObject(
227 const wxBitmap
& rBitmap
229 : wxBitmapDataObjectBase(rBitmap
)
234 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
238 wxBitmapDataObject::~wxBitmapDataObject()
243 void wxBitmapDataObject::SetBitmap(
244 const wxBitmap
& rBitmap
248 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
251 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
255 void wxBitmapDataObject::Init()
257 m_pictHandle
= NULL
;
258 m_pictCreated
= false ;
261 void wxBitmapDataObject::Clear()
263 if ( m_pictCreated
&& m_pictHandle
)
265 KillPicture( (PicHandle
) m_pictHandle
) ;
267 m_pictHandle
= NULL
;
270 bool wxBitmapDataObject::GetDataHere( void* pBuf
) const
274 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
277 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
281 size_t wxBitmapDataObject::GetDataSize() const
283 return GetHandleSize((Handle
)m_pictHandle
) ;
286 bool wxBitmapDataObject::SetData(
292 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
293 memcpy( *picHandle
, pBuf
, nSize
) ;
294 m_pictHandle
= picHandle
;
295 m_pictCreated
= false ;
296 Rect frame
= (**picHandle
).picFrame
;
298 m_bitmap
.SetPict( picHandle
) ;
299 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
300 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
301 return m_bitmap
.Ok();