]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk1/dataobj.cpp
59dac39832df747963925cf201f312a9219ebe35
1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDataObject class
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 ///////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "dataobj.h"
14 #include "wx/dataobj.h"
20 //-------------------------------------------------------------------------
22 //-------------------------------------------------------------------------
24 IMPLEMENT_CLASS(wxDataFormat
, wxObject
)
26 wxDataFormat::wxDataFormat( wxDataType type
)
30 if (m_type
== wxDF_TEXT
)
35 if (m_type
== wxDF_BITMAP
)
40 if (m_type
== wxDF_FILENAME
)
46 wxFAIL_MSG( "invalid dataformat" )
52 wxDataFormat::wxDataFormat( const wxString
&id
)
54 m_type
= wxDF_PRIVATE
;
59 wxDataFormat::wxDataFormat( wxDataFormat
&format
)
61 m_type
= format
.GetType();
62 m_id
= format
.GetId();
64 m_atom
= format
.GetAtom();
67 wxDataFormat::wxDataFormat( const GdkAtom atom
)
73 if (m_atom
== GDK_TARGET_STRING
)
77 if (m_atom
== GDK_TARGET_BITMAP
)
82 m_type
= wxDF_PRIVATE
;
83 m_id
= gdk_atom_name( m_atom
);
85 if (m_id
== "file:ALL")
87 m_type
= wxDF_FILENAME
;
92 int wxDataFormat::GetType() const
97 wxString
wxDataFormat::GetId() const
102 void wxDataFormat::SetId( const wxString
&id
)
104 m_type
= wxDF_PRIVATE
;
109 GdkAtom
wxDataFormat::GetAtom()
115 if (m_type
== wxDF_TEXT
)
117 m_atom
= GDK_TARGET_STRING
;
120 if (m_type
== wxDF_BITMAP
)
122 m_atom
= GDK_TARGET_BITMAP
;
125 if (m_type
== wxDF_PRIVATE
)
127 m_atom
= gdk_atom_intern( WXSTRINGCAST( m_id
), FALSE
);
130 if (m_type
== wxDF_FILENAME
)
132 m_atom
= gdk_atom_intern( "file:ALL", FALSE
);
137 m_atom
= (GdkAtom
) 0;
144 //-------------------------------------------------------------------------
146 //-------------------------------------------------------------------------
148 IMPLEMENT_CLASS(wxDataBroker
,wxObject
)
150 wxDataBroker::wxDataBroker()
152 m_dataObjects
.DeleteContents(TRUE
);
156 void wxDataBroker::Add( wxDataObject
*dataObject
, bool preferred
)
158 if (preferred
) m_preferred
= m_dataObjects
.GetCount();
159 m_dataObjects
.Append( dataObject
);
162 size_t wxDataBroker::GetFormatCount() const
164 return m_dataObjects
.GetCount();
167 wxDataFormat
&wxDataBroker::GetPreferredFormat() const
169 wxNode
*node
= m_dataObjects
.Nth( m_preferred
);
173 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
175 return data_obj
->GetFormat();
178 wxDataFormat
&wxDataBroker::GetNthFormat( size_t nth
) const
180 wxNode
*node
= m_dataObjects
.Nth( nth
);
184 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
186 return data_obj
->GetFormat();
189 bool wxDataBroker::IsSupportedFormat( wxDataFormat
&format
) const
191 wxNode
*node
= m_dataObjects
.First();
194 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
196 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
207 size_t wxDataBroker::GetSize( wxDataFormat
& format
) const
209 wxNode
*node
= m_dataObjects
.First();
212 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
214 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
216 return dobj
->GetSize();
225 void wxDataBroker::WriteData( wxDataFormat
& format
, void *dest
) const
227 wxNode
*node
= m_dataObjects
.First();
230 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
232 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
234 return dobj
->WriteData( dest
);
241 //-------------------------------------------------------------------------
243 //-------------------------------------------------------------------------
245 IMPLEMENT_ABSTRACT_CLASS( wxDataObject
, wxObject
)
247 wxDataObject::wxDataObject()
249 m_format
= (wxDataFormat
*) NULL
;
252 wxDataObject::~wxDataObject()
254 if (m_format
) delete m_format
;
257 wxDataFormat
&wxDataObject::GetFormat() const
259 wxASSERT( m_format
);
264 // ----------------------------------------------------------------------------
266 // ----------------------------------------------------------------------------
268 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject
, wxDataObject
)
270 wxTextDataObject::wxTextDataObject()
272 m_format
= new wxDataFormat( wxDF_TEXT
);
275 wxTextDataObject::wxTextDataObject( const wxString
& data
)
277 m_format
= new wxDataFormat( wxDF_TEXT
);
282 void wxTextDataObject::SetText( const wxString
& data
)
287 wxString
wxTextDataObject::GetText() const
292 void wxTextDataObject::WriteData( void *dest
) const
294 WriteString( m_data
, dest
);
297 size_t wxTextDataObject::GetSize() const
299 return m_data
.Len() + 1;
302 void wxTextDataObject::WriteString( const wxString
&str
, void *dest
) const
304 memcpy( dest
, m_data
.c_str(), GetSize() );
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
311 IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject
, wxDataObject
)
313 wxFileDataObject::wxFileDataObject(void)
315 m_format
= new wxDataFormat( wxDF_FILENAME
);
318 void wxFileDataObject::AddFile( const wxString
&file
)
324 wxString
wxFileDataObject::GetFiles() const
329 void wxFileDataObject::WriteData( void *dest
) const
331 memcpy( dest
, m_files
.c_str(), GetSize() );
334 size_t wxFileDataObject::GetSize() const
336 return m_files
.Len() + 1;
339 // ----------------------------------------------------------------------------
340 // wxBitmapDataObject
341 // ----------------------------------------------------------------------------
343 IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject
, wxDataObject
)
345 wxBitmapDataObject::wxBitmapDataObject()
347 m_format
= new wxDataFormat( wxDF_BITMAP
);
350 wxBitmapDataObject::wxBitmapDataObject( const wxBitmap
& bitmap
)
352 m_format
= new wxDataFormat( wxDF_BITMAP
);
357 void wxBitmapDataObject::SetBitmap( const wxBitmap
&bitmap
)
362 wxBitmap
wxBitmapDataObject::GetBitmap() const
367 void wxBitmapDataObject::WriteData( void *dest
) const
369 WriteBitmap( m_bitmap
, dest
);
372 size_t wxBitmapDataObject::GetSize() const
377 void wxBitmapDataObject::WriteBitmap( const wxBitmap
&bitmap
, void *dest
) const
379 memcpy( dest
, m_bitmap
.GetPixmap(), GetSize() );
382 // ----------------------------------------------------------------------------
383 // wxPrivateDataObject
384 // ----------------------------------------------------------------------------
386 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
388 wxPrivateDataObject::wxPrivateDataObject()
390 m_id
= "application/";
391 m_id
+= wxTheApp
->GetAppName();
393 m_format
= new wxDataFormat( m_id
);
396 m_data
= (char*) NULL
;
399 wxPrivateDataObject::~wxPrivateDataObject()
401 if (m_data
) delete[] m_data
;
404 void wxPrivateDataObject::SetId( const wxString
& id
)
407 m_format
->SetId( m_id
);
410 wxString
wxPrivateDataObject::GetId() const
415 void wxPrivateDataObject::SetData( const char *data
, size_t size
)
419 if (m_data
) delete[] m_data
;
421 m_data
= new char[size
];
423 memcpy( m_data
, data
, size
);
426 char* wxPrivateDataObject::GetData() const
431 void wxPrivateDataObject::WriteData( void *dest
) const
433 WriteData( m_data
, dest
);
436 size_t wxPrivateDataObject::GetSize() const
441 void wxPrivateDataObject::WriteData( const char *data
, void *dest
) const
443 memcpy( dest
, data
, GetSize() );