]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dobjcmn.cpp
f806dcdec6b798a940f9e2fe36090606b2c29644
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: common/dobjcmn.cpp
3 // Purpose: implementation of data object methods common to all platforms
4 // Author: Vadim Zeitlin, Robert Roebling
8 // Copyright: (c) wxWindows Team
9 // Licence: wxWindows license
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "dataobjbase.h"
24 #include "wx/wxprec.h"
35 #include "wx/dataobj.h"
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
41 #include "wx/listimpl.cpp"
43 WX_DEFINE_LIST(wxSimpleDataObjectList
);
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 wxDataObjectBase::~wxDataObjectBase()
57 // ----------------------------------------------------------------------------
58 // wxDataObjectComposite
59 // ----------------------------------------------------------------------------
62 wxDataObjectComposite::GetObject(const wxDataFormat
& format
) const
64 wxSimpleDataObjectList::Node
*node
= m_dataObjects
.GetFirst();
67 wxDataObjectSimple
*dataObj
= node
->GetData();
69 if ( dataObj
->GetFormat() == format
)
74 node
= node
->GetNext();
77 return (wxDataObjectSimple
*)NULL
;
80 void wxDataObjectComposite::Add(wxDataObjectSimple
*dataObject
, bool preferred
)
83 m_preferred
= m_dataObjects
.GetCount();
85 m_dataObjects
.Append( dataObject
);
89 wxDataObjectComposite::GetPreferredFormat(Direction
WXUNUSED(dir
)) const
91 wxSimpleDataObjectList::Node
*node
= m_dataObjects
.Item( m_preferred
);
93 wxCHECK_MSG( node
, wxDF_INVALID
, wxT("no preferred format") );
95 wxDataObjectSimple
* dataObj
= node
->GetData();
97 return dataObj
->GetFormat();
100 size_t wxDataObjectComposite::GetFormatCount(Direction
WXUNUSED(dir
)) const
102 // TODO what about the Get/Set only formats?
103 return m_dataObjects
.GetCount();
106 void wxDataObjectComposite::GetAllFormats(wxDataFormat
*formats
,
107 Direction
WXUNUSED(dir
)) const
110 wxSimpleDataObjectList::Node
*node
;
111 for ( node
= m_dataObjects
.GetFirst(); node
; node
= node
->GetNext() )
113 // TODO if ( !outputOnlyToo ) && this one counts ...
114 formats
[n
++] = node
->GetData()->GetFormat();
118 size_t wxDataObjectComposite::GetDataSize(const wxDataFormat
& format
) const
120 wxDataObjectSimple
*dataObj
= GetObject(format
);
122 wxCHECK_MSG( dataObj
, 0,
123 wxT("unsupported format in wxDataObjectComposite"));
125 return dataObj
->GetDataSize();
128 bool wxDataObjectComposite::GetDataHere(const wxDataFormat
& format
,
131 wxDataObjectSimple
*dataObj
= GetObject(format
);
133 wxCHECK_MSG( dataObj
, FALSE
,
134 wxT("unsupported format in wxDataObjectComposite"));
136 return dataObj
->GetDataHere(buf
);
139 bool wxDataObjectComposite::SetData(const wxDataFormat
& format
,
143 wxDataObjectSimple
*dataObj
= GetObject(format
);
145 wxCHECK_MSG( dataObj
, FALSE
,
146 wxT("unsupported format in wxDataObjectComposite"));
148 return dataObj
->SetData(len
, buf
);
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 size_t wxTextDataObject::GetDataSize() const
157 return GetTextLength();
160 bool wxTextDataObject::GetDataHere(void *buf
) const
162 strcpy((char *)buf
, GetText().mb_str());
167 bool wxTextDataObject::SetData(size_t WXUNUSED(len
), const void *buf
)
169 SetText(wxString((const char *)buf
));
174 // ----------------------------------------------------------------------------
175 // wxFileDataObjectBase
176 // ----------------------------------------------------------------------------
178 wxString
wxFileDataObjectBase::GetFilenames() const
181 size_t count
= m_filenames
.GetCount();
182 for ( size_t n
= 0; n
< count
; n
++ )
184 str
<< m_filenames
[n
] << wxT('\0');
190 void wxFileDataObjectBase::SetFilenames(const wxChar
* filenames
)
195 for ( const wxChar
*pc
= filenames
; ; pc
++ )
205 // 2 consecutive NULs - this is the end of the string
209 m_filenames
.Add(current
);
215 // ----------------------------------------------------------------------------
216 // wxCustomDataObject
217 // ----------------------------------------------------------------------------
219 wxCustomDataObject::~wxCustomDataObject()
224 void wxCustomDataObject::TakeData(size_t size
, void *data
)
232 void *wxCustomDataObject::Alloc(size_t size
)
234 return (void *)new char[size
];
237 void wxCustomDataObject::Free()
241 m_data
= (void *)NULL
;
244 size_t wxCustomDataObject::GetDataSize() const
249 bool wxCustomDataObject::GetDataHere(void *buf
) const
251 void *data
= GetData();
255 memcpy(buf
, data
, GetSize());
260 bool wxCustomDataObject::SetData(size_t len
, const void *buf
)
264 m_data
= Alloc(size
);
268 memcpy(m_data
, buf
, m_size
= len
);