]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dataobj.cpp
bec4f2bd605d14d75b1c96f681471ddaebefa93a
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") );
89 // this is '????' but it can't be used in the code because ??' is
90 // parsed as a trigraph!
91 m_format
= 0x3f3f3f3f;
95 wxString
wxDataFormat::GetId() const
97 // note that m_format is not a pointer to string, it *is* itself a 4
100 strncpy( text
, (char*) &m_format
, 4 ) ;
103 return wxString::FromAscii( text
) ;
106 void wxDataFormat::SetId( NativeFormat format
)
110 if (m_format
== kScrapFlavorTypeText
)
112 else if (m_format
== kScrapFlavorTypeUnicode
)
113 m_type
= wxDF_UNICODETEXT
;
114 else if (m_format
== kScrapFlavorTypePicture
)
115 m_type
= wxDF_BITMAP
;
116 else if (m_format
== kDragFlavorTypeHFS
)
117 m_type
= wxDF_FILENAME
;
119 m_type
= wxDF_PRIVATE
;
122 void wxDataFormat::SetId( const wxChar
* zId
)
124 m_type
= wxDF_PRIVATE
;
125 m_format
= 0;// TODO: get the format gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE );
128 //-------------------------------------------------------------------------
130 //-------------------------------------------------------------------------
132 wxDataObject::wxDataObject()
136 bool wxDataObject::IsSupportedFormat(
137 const wxDataFormat
& rFormat
141 size_t nFormatCount
= GetFormatCount(vDir
);
143 if (nFormatCount
== 1)
145 return rFormat
== GetPreferredFormat();
149 wxDataFormat
* pFormats
= new wxDataFormat
[nFormatCount
];
150 GetAllFormats( pFormats
156 for (n
= 0; n
< nFormatCount
; n
++)
158 if (pFormats
[n
] == rFormat
)
165 return n
< nFormatCount
;
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
174 void wxTextDataObject::GetAllFormats(wxDataFormat
*formats
, wxDataObjectBase::Direction dir
) const
176 *formats
++ = wxDataFormat( wxDF_TEXT
);
177 *formats
= wxDataFormat( wxDF_UNICODETEXT
);
182 // ----------------------------------------------------------------------------
184 // ----------------------------------------------------------------------------
186 bool wxFileDataObject::GetDataHere(
192 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
194 sFilenames
+= m_filenames
[i
];
195 sFilenames
+= (wxChar
)0;
198 memcpy(pBuf
, sFilenames
.mbc_str(), sFilenames
.Len() + 1);
202 size_t wxFileDataObject::GetDataSize() const
206 for (size_t i
= 0; i
< m_filenames
.GetCount(); i
++)
208 nRes
+= m_filenames
[i
].Len();
215 bool wxFileDataObject::SetData(
216 size_t WXUNUSED(nSize
)
222 // only add if this is not an empty string
223 // we can therefore clear the list by just setting an empty string
224 if ( (*(char*)pBuf
) != 0 )
225 AddFile(wxString::FromAscii((char*)pBuf
));
230 void wxFileDataObject::AddFile(
231 const wxString
& rFilename
234 m_filenames
.Add(rFilename
);
237 // ----------------------------------------------------------------------------
238 // wxBitmapDataObject
239 // ----------------------------------------------------------------------------
241 wxBitmapDataObject::wxBitmapDataObject()
246 wxBitmapDataObject::wxBitmapDataObject(
247 const wxBitmap
& rBitmap
249 : wxBitmapDataObjectBase(rBitmap
)
254 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
258 wxBitmapDataObject::~wxBitmapDataObject()
263 void wxBitmapDataObject::SetBitmap(
264 const wxBitmap
& rBitmap
268 wxBitmapDataObjectBase::SetBitmap(rBitmap
);
271 m_pictHandle
= m_bitmap
.GetPict( &m_pictCreated
) ;
275 void wxBitmapDataObject::Init()
277 m_pictHandle
= NULL
;
278 m_pictCreated
= false ;
281 void wxBitmapDataObject::Clear()
283 if ( m_pictCreated
&& m_pictHandle
)
285 KillPicture( (PicHandle
) m_pictHandle
) ;
287 m_pictHandle
= NULL
;
290 bool wxBitmapDataObject::GetDataHere(
296 wxFAIL_MSG(wxT("attempt to copy empty bitmap failed"));
299 memcpy(pBuf
, *(Handle
)m_pictHandle
, GetHandleSize((Handle
)m_pictHandle
));
303 size_t wxBitmapDataObject::GetDataSize() const
305 return GetHandleSize((Handle
)m_pictHandle
) ;
308 bool wxBitmapDataObject::SetData(
314 PicHandle picHandle
= (PicHandle
) NewHandle( nSize
) ;
315 memcpy( *picHandle
, pBuf
, nSize
) ;
316 m_pictHandle
= picHandle
;
317 m_pictCreated
= false ;
318 Rect frame
= (**picHandle
).picFrame
;
320 m_bitmap
.SetPict( picHandle
) ;
321 m_bitmap
.SetWidth( frame
.right
- frame
.left
) ;
322 m_bitmap
.SetHeight( frame
.bottom
- frame
.top
) ;
323 return m_bitmap
.Ok();