]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/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 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
29 #include "wx/dataobj.h"
30 #include "wx/mstream.h"
32 #include "wx/mac/private.h"
35 // ----------------------------------------------------------------------------
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 wxDataFormat::wxDataFormat()
45 m_type
= wxDF_INVALID
;
49 wxDataFormat::wxDataFormat( wxDataFormatId vType
)
54 wxDataFormat::wxDataFormat( const wxChar
* zId
)
59 wxDataFormat::wxDataFormat( const wxString
& rId
)
64 wxDataFormat::wxDataFormat( NativeFormat vFormat
)
69 void wxDataFormat::SetType( wxDataFormatId Type
)
73 if (m_type
== wxDF_TEXT
)
74 m_format
= kScrapFlavorTypeText
;
75 else if (m_type
== wxDF_UNICODETEXT
)
76 m_format
= kScrapFlavorTypeUnicode
;
77 else if (m_type
== wxDF_BITMAP
|| m_type
== wxDF_METAFILE
)
78 m_format
= kScrapFlavorTypePicture
;
79 else if (m_type
== wxDF_FILENAME
)
80 m_format
= kDragFlavorTypeHFS
;
83 wxFAIL_MSG( wxT("invalid dataformat") );
85 // this is '????' but it can't be used in the code because ??' is
86 // parsed as a trigraph!
87 m_format
= 0x3f3f3f3f;
91 wxString
wxDataFormat::GetId() const
93 // note that m_format is not a pointer to string, it *is* itself a 4
96 strncpy( text
, (char*) &m_format
, 4 ) ;
99 return wxString::FromAscii( text
) ;
102 void wxDataFormat::SetId( NativeFormat format
)
106 if (m_format
== kScrapFlavorTypeText
)
108 else if (m_format
== kScrapFlavorTypeUnicode
)
109 m_type
= wxDF_UNICODETEXT
;
110 else if (m_format
== kScrapFlavorTypePicture
)
111 m_type
= wxDF_BITMAP
;
112 else if (m_format
== kDragFlavorTypeHFS
)
113 m_type
= wxDF_FILENAME
;
115 m_type
= wxDF_PRIVATE
;
118 void wxDataFormat::SetId( const wxChar
* zId
)
120 m_type
= wxDF_PRIVATE
;
121 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
124 //-------------------------------------------------------------------------
126 //-------------------------------------------------------------------------
128 wxDataObject::wxDataObject()
132 bool wxDataObject::IsSupportedFormat(
133 const wxDataFormat
& rFormat
137 size_t nFormatCount
= GetFormatCount(vDir
);
139 if (nFormatCount
== 1)
141 return rFormat
== GetPreferredFormat();
145 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
146 GetAllFormats( pFormats
152 for (n
= 0; n
< nFormatCount
; n
++)
154 if (pFormats
[n
] == rFormat
)
161 return n
< nFormatCount
;
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 bool wxFileDataObject::GetDataHere(
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(
276 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
279 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
283 size_t wxBitmapDataObject::GetDataSize() const
285 return GetHandleSize((Handle
)m_pictHandle
) ;
288 bool wxBitmapDataObject::SetData(
294 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
295 memcpy( *picHandle
, pBuf
, nSize
) ;
296 m_pictHandle
= picHandle
;
297 m_pictCreated
= false ;
298 Rect frame
= (**picHandle
).picFrame
;
300 m_bitmap
.SetPict( picHandle
) ;
301 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
302 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
303 return m_bitmap
.Ok();