]>
git.saurik.com Git - wxWidgets.git/blob - src/common/dobjcmn.cpp
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 // VZ: I don't need this in MSW finally, so if it is needed in wxGTK, it should
179 // be moved to gtk/dataobj.cpp
182 wxString
wxFileDataObjectBase::GetFilenames() const
185 size_t count
= m_filenames
.GetCount();
186 for ( size_t n
= 0; n
< count
; n
++ )
188 str
<< m_filenames
[n
] << wxT('\0');
194 void wxFileDataObjectBase::SetFilenames(const wxChar
* filenames
)
199 for ( const wxChar
*pc
= filenames
; ; pc
++ )
209 // 2 consecutive NULs - this is the end of the string
213 m_filenames
.Add(current
);
221 // ----------------------------------------------------------------------------
222 // wxCustomDataObject
223 // ----------------------------------------------------------------------------
225 wxCustomDataObject::~wxCustomDataObject()
230 void wxCustomDataObject::TakeData(size_t size
, void *data
)
238 void *wxCustomDataObject::Alloc(size_t size
)
240 return (void *)new char[size
];
243 void wxCustomDataObject::Free()
247 m_data
= (void *)NULL
;
250 size_t wxCustomDataObject::GetDataSize() const
255 bool wxCustomDataObject::GetDataHere(void *buf
) const
257 void *data
= GetData();
261 memcpy(buf
, data
, GetSize());
266 bool wxCustomDataObject::SetData(size_t size
, const void *buf
)
270 m_data
= Alloc(size
);
274 memcpy(m_data
, buf
, m_size
= size
);