+#include <Xm/Xm.h>
+#include "wx/utils.h"
+
+//-------------------------------------------------------------------------
+// global data
+//-------------------------------------------------------------------------
+
+Atom  g_textAtom        = 0;
+
+//-------------------------------------------------------------------------
+// wxDataFormat
+//-------------------------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataFormat, wxObject)
+
+wxDataFormat::wxDataFormat()
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
+    m_type = wxDF_INVALID;
+    m_hasAtom = FALSE;
+    m_atom = (Atom) 0;
+}
+
+wxDataFormat::wxDataFormat( wxDataFormatId type )
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
+    SetType( type );
+}
+
+wxDataFormat::wxDataFormat( const wxChar *id )
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
+    SetId( id );
+}
+
+wxDataFormat::wxDataFormat( const wxString &id )
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
+    SetId( id );
+}
+
+wxDataFormat::wxDataFormat( const wxDataFormat &format )
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "STRING", FALSE );
+    m_type = format.GetType();
+    m_id = format.GetId();
+    m_hasAtom = TRUE;
+    m_atom = ((wxDataFormat &)format).GetAtom();    // const_cast
+}
+
+wxDataFormat::wxDataFormat( const Atom atom )
+{
+    if (!g_textAtom) g_textAtom = XInternAtom( (Display*) wxGetDisplay(), "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 = XGetAtomName( (Display*) wxGetDisplay(),  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;
+}
+
+Atom 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 = XInternAtom( (Display*) wxGetDisplay(), MBSTRINGCAST m_id.mbc_str(), FALSE );
+        }
+       else
+       if (m_type == wxDF_FILENAME)
+       {
+           m_atom = XInternAtom( (Display*) wxGetDisplay(), "file:ALL", FALSE );
+       }
+       else
+       {
+           m_hasAtom = FALSE;
+           m_atom = (Atom) 0;
+       }
+    }
+
+    return m_atom;
+}
+