+#include "wx/app.h"
+#include "wx/debug.h"
+
+#include "gdk/gdk.h"
+
+
+//-------------------------------------------------------------------------
+// global data
+//-------------------------------------------------------------------------
+
+GdkAtom g_textAtom = 0;
+
+//-------------------------------------------------------------------------
+// wxDataFormat
+//-------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataFormat, wxObject)
+
+wxDataFormat::wxDataFormat()
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ m_type = wxDF_INVALID;
+ m_hasAtom = FALSE;
+ m_atom = (GdkAtom) 0;
+}
+
+wxDataFormat::wxDataFormat( wxDataFormatId type )
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ SetType( type );
+}
+
+wxDataFormat::wxDataFormat( const wxChar *id )
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ SetId( id );
+}
+
+wxDataFormat::wxDataFormat( const wxString &id )
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ SetId( id );
+}
+
+wxDataFormat::wxDataFormat( const wxDataFormat &format )
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ m_type = format.GetType();
+ m_id = format.GetId();
+ m_hasAtom = TRUE;
+ m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
+}
+
+wxDataFormat::wxDataFormat( const GdkAtom atom )
+{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ m_hasAtom = TRUE;
+
+ m_atom = atom;
+
+ if (m_atom == g_textAtom)
+ {
+ m_type = wxDF_TEXT;
+ } else
+ if (m_atom == GDK_TARGET_BITMAP)
+ {
+ m_type = wxDF_BITMAP;
+ } else
+ {
+ m_type = wxDF_PRIVATE;
+ m_id = gdk_atom_name( m_atom );
+
+ if (m_id == _T("file:ALL"))
+ {
+ m_type = wxDF_FILENAME;
+ }
+ }
+}
+
+void wxDataFormat::SetType( wxDataFormatId type )
+{
+ m_type = type;
+
+ if (m_type == wxDF_TEXT)
+ {
+ m_id = _T("STRING");
+ }
+ else
+ if (m_type == wxDF_BITMAP)
+ {
+ m_id = _T("BITMAP");
+ }
+ else
+ if (m_type == wxDF_FILENAME)
+ {
+ m_id = _T("file:ALL");
+ }
+ else
+ {
+ wxFAIL_MSG( _T("invalid dataformat") );
+ }
+
+ m_hasAtom = FALSE;
+}
+
+wxDataFormatId wxDataFormat::GetType() const
+{
+ return m_type;
+}
+
+wxString wxDataFormat::GetId() const
+{
+ return m_id;
+}
+
+void wxDataFormat::SetId( const wxChar *id )
+{
+ m_type = wxDF_PRIVATE;
+ m_id = id;
+ m_hasAtom = FALSE;
+}
+
+GdkAtom wxDataFormat::GetAtom()
+{
+ if (!m_hasAtom)
+ {
+ m_hasAtom = TRUE;
+
+ if (m_type == wxDF_TEXT)
+ {
+ m_atom = g_textAtom;
+ }
+ else
+ if (m_type == wxDF_BITMAP)
+ {
+ m_atom = GDK_TARGET_BITMAP;
+ }
+ else
+ if (m_type == wxDF_PRIVATE)
+ {
+ m_atom = gdk_atom_intern( MBSTRINGCAST m_id.mbc_str(), FALSE );
+ }
+ else
+ if (m_type == wxDF_FILENAME)
+ {
+ m_atom = gdk_atom_intern( "file:ALL", FALSE );
+ }
+ else
+ {
+ m_hasAtom = FALSE;
+ m_atom = (GdkAtom) 0;
+ }
+ }
+
+ return m_atom;
+}
+
+//-------------------------------------------------------------------------
+// wxDataBroker
+//-------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataBroker,wxObject)
+
+wxDataBroker::wxDataBroker()
+{
+ m_dataObjects.DeleteContents(TRUE);
+ m_preferred = 0;
+}
+
+void wxDataBroker::Add( wxDataObject *dataObject, bool preferred )
+{
+ if (preferred) m_preferred = m_dataObjects.GetCount();
+ m_dataObjects.Append( dataObject );
+}
+
+size_t wxDataBroker::GetFormatCount() const
+{
+ return m_dataObjects.GetCount();
+}
+
+wxDataFormatId wxDataBroker::GetPreferredFormat() const
+{
+ wxNode *node = m_dataObjects.Nth( m_preferred );
+
+ wxASSERT( node );
+
+ wxDataObject* data_obj = (wxDataObject*)node->Data();
+
+ return data_obj->GetFormat().GetType();
+}
+
+wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const
+{
+ wxNode *node = m_dataObjects.Nth( nth );
+
+ wxASSERT( node );
+
+ wxDataObject* data_obj = (wxDataObject*)node->Data();
+
+ return data_obj->GetFormat();
+}
+
+bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
+{
+ wxNode *node = m_dataObjects.First();
+ while (node)
+ {
+ wxDataObject *dobj = (wxDataObject*)node->Data();
+
+ if (dobj->GetFormat().GetAtom() == format.GetAtom())
+ {
+ return TRUE;
+ }
+
+ node = node->Next();
+ }
+
+ return FALSE;
+}
+
+size_t wxDataBroker::GetSize( wxDataFormat& format ) const
+{
+ wxNode *node = m_dataObjects.First();
+ while (node)
+ {
+ wxDataObject *dobj = (wxDataObject*)node->Data();
+
+ if (dobj->GetFormat().GetAtom() == format.GetAtom())
+ {
+ return dobj->GetSize();
+ }
+
+ node = node->Next();
+ }
+
+ return 0;
+}
+
+void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
+{
+ wxNode *node = m_dataObjects.First();
+ while (node)
+ {
+ wxDataObject *dobj = (wxDataObject*)node->Data();
+
+ if (dobj->GetFormat().GetAtom() == format.GetAtom())
+ {
+ dobj->WriteData( dest );
+ }
+
+ node = node->Next();
+ }
+}