]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/dataobj.cpp
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()
28 m_type
= wxDF_INVALID
;
33 wxDataFormat::wxDataFormat( wxDataType type
)
38 wxDataFormat::wxDataFormat( const wxString
&id
)
43 wxDataFormat::wxDataFormat( wxDataFormat
&format
)
45 m_type
= format
.GetType();
46 m_id
= format
.GetId();
48 m_atom
= format
.GetAtom();
51 wxDataFormat::wxDataFormat( const GdkAtom atom
)
57 if (m_atom
== GDK_TARGET_STRING
)
61 if (m_atom
== GDK_TARGET_BITMAP
)
66 m_type
= wxDF_PRIVATE
;
67 m_id
= gdk_atom_name( m_atom
);
69 if (m_id
== "file:ALL")
71 m_type
= wxDF_FILENAME
;
76 void wxDataFormat::SetType( wxDataType type
)
80 if (m_type
== wxDF_TEXT
)
85 if (m_type
== wxDF_BITMAP
)
90 if (m_type
== wxDF_FILENAME
)
96 wxFAIL_MSG( "invalid dataformat" );
102 wxDataType
wxDataFormat::GetType() const
107 wxString
wxDataFormat::GetId() const
112 void wxDataFormat::SetId( const wxString
&id
)
114 m_type
= wxDF_PRIVATE
;
119 GdkAtom
wxDataFormat::GetAtom()
125 if (m_type
== wxDF_TEXT
)
127 m_atom
= GDK_TARGET_STRING
;
130 if (m_type
== wxDF_BITMAP
)
132 m_atom
= GDK_TARGET_BITMAP
;
135 if (m_type
== wxDF_PRIVATE
)
137 m_atom
= gdk_atom_intern( WXSTRINGCAST( m_id
), FALSE
);
140 if (m_type
== wxDF_FILENAME
)
142 m_atom
= gdk_atom_intern( "file:ALL", FALSE
);
147 m_atom
= (GdkAtom
) 0;
154 //-------------------------------------------------------------------------
156 //-------------------------------------------------------------------------
158 IMPLEMENT_CLASS(wxDataBroker
,wxObject
)
160 wxDataBroker::wxDataBroker()
162 m_dataObjects
.DeleteContents(TRUE
);
166 void wxDataBroker::Add( wxDataObject
*dataObject
, bool preferred
)
168 if (preferred
) m_preferred
= m_dataObjects
.GetCount();
169 m_dataObjects
.Append( dataObject
);
172 size_t wxDataBroker::GetFormatCount() const
174 return m_dataObjects
.GetCount();
177 wxDataFormat
&wxDataBroker::GetPreferredFormat() const
179 wxNode
*node
= m_dataObjects
.Nth( m_preferred
);
183 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
185 return data_obj
->GetFormat();
188 wxDataFormat
&wxDataBroker::GetNthFormat( size_t nth
) const
190 wxNode
*node
= m_dataObjects
.Nth( nth
);
194 wxDataObject
* data_obj
= (wxDataObject
*)node
->Data();
196 return data_obj
->GetFormat();
199 bool wxDataBroker::IsSupportedFormat( wxDataFormat
&format
) const
201 wxNode
*node
= m_dataObjects
.First();
204 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
206 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
217 size_t wxDataBroker::GetSize( wxDataFormat
& format
) const
219 wxNode
*node
= m_dataObjects
.First();
222 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
224 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
226 return dobj
->GetSize();
235 void wxDataBroker::WriteData( wxDataFormat
& format
, void *dest
) const
237 wxNode
*node
= m_dataObjects
.First();
240 wxDataObject
*dobj
= (wxDataObject
*)node
->Data();
242 if (dobj
->GetFormat().GetAtom() == format
.GetAtom())
244 return dobj
->WriteData( dest
);
251 //-------------------------------------------------------------------------
253 //-------------------------------------------------------------------------
255 IMPLEMENT_ABSTRACT_CLASS( wxDataObject
, wxObject
)
257 wxDataObject::wxDataObject()
261 wxDataObject::~wxDataObject()
265 wxDataFormat
&wxDataObject::GetFormat()
270 wxDataType
wxDataObject::GetFormatType() const
272 return m_format
.GetType();
275 wxString
wxDataObject::GetFormatId() const
277 return m_format
.GetId();
280 GdkAtom
wxDataObject::GetFormatAtom() const
282 GdkAtom ret
= m_format
.GetAtom();
286 // ----------------------------------------------------------------------------
288 // ----------------------------------------------------------------------------
290 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject
, wxDataObject
)
292 wxTextDataObject::wxTextDataObject()
294 m_format
.SetType( wxDF_TEXT
);
297 wxTextDataObject::wxTextDataObject( const wxString
& data
)
299 m_format
.SetType( wxDF_TEXT
);
304 void wxTextDataObject::SetText( const wxString
& data
)
309 wxString
wxTextDataObject::GetText() const
314 void wxTextDataObject::WriteData( void *dest
) const
316 WriteString( m_data
, dest
);
319 size_t wxTextDataObject::GetSize() const
321 return m_data
.Len() + 1;
324 void wxTextDataObject::WriteString( const wxString
&str
, void *dest
) const
326 memcpy( dest
, m_data
.c_str(), GetSize() );
329 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
333 IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject
, wxDataObject
)
335 wxFileDataObject::wxFileDataObject()
337 m_format
.SetType( wxDF_FILENAME
);
340 void wxFileDataObject::AddFile( const wxString
&file
)
346 wxString
wxFileDataObject::GetFiles() const
351 void wxFileDataObject::WriteData( void *dest
) const
353 memcpy( dest
, m_files
.c_str(), GetSize() );
356 size_t wxFileDataObject::GetSize() const
358 return m_files
.Len() + 1;
361 // ----------------------------------------------------------------------------
362 // wxBitmapDataObject
363 // ----------------------------------------------------------------------------
365 IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject
, wxDataObject
)
367 wxBitmapDataObject::wxBitmapDataObject()
369 m_format
.SetType( wxDF_BITMAP
);
372 wxBitmapDataObject::wxBitmapDataObject( const wxBitmap
& bitmap
)
374 m_format
.SetType( wxDF_BITMAP
);
379 void wxBitmapDataObject::SetBitmap( const wxBitmap
&bitmap
)
384 wxBitmap
wxBitmapDataObject::GetBitmap() const
389 void wxBitmapDataObject::WriteData( void *dest
) const
391 WriteBitmap( m_bitmap
, dest
);
394 size_t wxBitmapDataObject::GetSize() const
399 void wxBitmapDataObject::WriteBitmap( const wxBitmap
&bitmap
, void *dest
) const
401 memcpy( dest
, m_bitmap
.GetPixmap(), GetSize() );
404 // ----------------------------------------------------------------------------
405 // wxPrivateDataObject
406 // ----------------------------------------------------------------------------
408 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject
, wxDataObject
)
410 wxPrivateDataObject::wxPrivateDataObject()
412 m_id
= "application/";
413 m_id
+= wxTheApp
->GetAppName();
415 m_format
.SetId( m_id
);
418 m_data
= (char*) NULL
;
421 wxPrivateDataObject::~wxPrivateDataObject()
423 if (m_data
) delete[] m_data
;
426 void wxPrivateDataObject::SetId( const wxString
& id
)
429 m_format
.SetId( m_id
);
432 wxString
wxPrivateDataObject::GetId() const
437 void wxPrivateDataObject::SetData( const char *data
, size_t size
)
441 if (m_data
) delete[] m_data
;
443 m_data
= new char[size
];
445 memcpy( m_data
, data
, size
);
448 char* wxPrivateDataObject::GetData() const
453 void wxPrivateDataObject::WriteData( void *dest
) const
455 WriteData( m_data
, dest
);
458 size_t wxPrivateDataObject::GetSize() const
463 void wxPrivateDataObject::WriteData( const char *data
, void *dest
) const
465 memcpy( dest
, data
, GetSize() );