wxPython README
 ---------------
 
-Introduction
-------------
-The code in this subtree is a Python Extension Module that enables the
-use of wxWindows from the Python language.  So what is Python?  Go to
-http://www.python.org to learn more but in a nutshell, it's an
-extremly cool object oriented language.  It's easier than Perl and
-nearly as powerful.  It runs on more platforms than Java, and by some
-reports, is even faster than Java with a JIT compiler!
-
-So why would you want to use wxPython over just C++ and wxWindows?
-Personally I prefer using Python for everything.  I only use C++ when
-I absolutly have to eek more performance out of an algorithm, and even
-then I ususally code it as an extension module and leave the majority
-of the program in Python.  Another good thing to use wxPython for is
-quick prototyping of your wxWindows apps.  With C++ you have to
-continuously go though the edit-compile-link-run cycle, which can be
-quite time comsuming.  With Python it is only an edit-run cycle.  You
-can easily build an application in a few hours with Python that would
-normally take a few days with C++.  Converting a wxPython app to a
-C++/wxWindows app should be a straight forward task.
-
-This extension module attempts to mirror the class heiarchy of
-wxWindows as closely as possble.  This means that there is a wxFrame
-class in wxPython that looks, smells, tastes and acts almost the same
-as the wxFrame class in the C++ version.  Unfortunatly, I wasn't able
-to match things exactly because of differences in the languages, but
-the differences should be easy to absorb because they are natural to
-Python.  For example, some methods that return mutliple values via
-argument pointers in C++ will return a tuple of values in Python.
-These differences have not been documented yet so if something isn't
-working the same as described in the wxWindows documents the best
-thing to do is to scan through the wxPython sources, especially the .i
-files, as that is where the interfaces for wxPython are defined.
-
-I have reports of successfully embedding wxPython within a wxWindows
-C++ app on GTK.  It hasn't yet been attempted on MSW (to my knowledge)
-so I don't know how successful such an attempt would be.  However it
-is certainly possible.
+Welcome to the wonderful world of wxPython!
+
+Once you have installed the wxPython extension module, you can try it
+out by going to the [install dir]\wxPython\demo directory and typing:
+
+    python demo.py
+
+There are also some other sample files there for you to play with and
+learn from.
+
+If you selected to install the documentation then point your browser
+to [install dir]\wxPython\docs\index.htm and you will then be looking
+at the docs for wxWindows.  For the most part you can use the C++ docs
+as most classes and methods are used identically.  Where there are
+differences they are documented with a "wxPython Note."
+
+On Win32 systems the binary self-installer creates a program group on
+the Start Menu that contains a link to running the demo and a link to
+the help file.  To help you save disk space I'm now using Microsoft's
+HTML Help format.  If your system doesn't know what to do with the help
+file, you can install the HTML Help Viewer as part of IE 4+, NT
+Service Pack 4+, or the HTML Workshop at
+http://msdn.microsoft.com/workshop/author/htmlhelp/download.asp.
 
 
 
 
        wxpython-users@starship.python.net
 
+----------------------------------------------------------------------
+
+
+What's new in 2.1b1
+--------------------
+Fixed wxComboBox.SetSelection so that it actually sets the selected
+item.  (Actually just removed it from wxPython and let it default to
+wxChoice.SetSelection which was already doing the right thing.)
+
+Added the Printing Framework.
+
+Switched back to using the wxWindows DLL for the pre-built Win32
+version.  The problem was needing to reinitialize static class info
+data after loading each extension module.
+
+Lots of little tweaks and additions to reflect changes to various
+wxWindows classes.
+
+Fixed a bug with attaching objects to tree items.  Actually was a
+symptom of a larger problem with not obtaining the interpreter lock
+when doing any Py_DECREFs.
+
+wxSizer and friends.  Sizers are layout tools that manage a colection
+of windows and sizers.  Different types of sizers apply different
+types of layout algorithms.  You saw it here first!  These classes are
+not even in the wxWindows C++ library yet!
+
 
 
 What's new in 2.0b9
 
 
 wxc    wx.cpp helpers.cpp windows.cpp events.cpp misc.cpp gdi.cpp \
        mdi.cpp controls.cpp controls2.cpp windows2.cpp cmndlgs.cpp \
-       frames.cpp stattool.cpp windows3.cpp image.cpp \
-       utils.cpp \
+       frames.cpp stattool.cpp windows3.cpp image.cpp misc2.cpp \
+       utils.cpp printfw.cpp \
        ## comment out the next line to disable wxGLCanvas
        ##_glcanvas.cpp glcanvas.cpp -DWITH_GLCANVAS -lGL -lGLU \
        -I. $(WX_CONFIG_CFLAGS) -I/usr/local/lib/glib/include \
 
 
 mkdir ~/wxgtk_dist/wxGTK/utils/wxPython/lib
 cp ./lib/*.py ~/wxgtk_dist/wxGTK/utils/wxPython/lib
+mkdir ~/wxgtk_dist/wxGTK/utils/wxPython/lib/sizers
+cp ./lib/sizers/*.py ~/wxgtk_dist/wxGTK/utils/wxPython/lib/sizers
 
 mkdir ~/wxgtk_dist/wxGTK/utils/wxPython/tests
 cp ./tests/README.txt ~/wxgtk_dist/wxGTK/utils/wxPython/tests
 
 #define _WX_DATAOBJ_H_BASE_
 
 #if defined(__WXMSW__)
-// ----------------------------------------------------------------------------
-// wxDataFormat identifies the single format of data
-// ----------------------------------------------------------------------------
-
-class WXDLLEXPORT wxDataFormat
-{
-public:
-    // the clipboard formats under Win32 are UINTs
-    typedef unsigned int NativeFormat;
-
-    wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
-    wxDataFormat& operator=(NativeFormat format)
-        { m_format = format; return *this; }
-
-    // defautl copy ctor/assignment operators ok
-
-    // comparison (must have both versions)
-    bool operator==(wxDataFormatId format) const
-        { return m_format == (NativeFormat)format; }
-    bool operator!=(wxDataFormatId format) const
-        { return m_format != (NativeFormat)format; }
-    bool operator==(const wxDataFormat& format) const
-        { return m_format == format.m_format; }
-    bool operator!=(const wxDataFormat& format) const
-        { return m_format != format.m_format; }
-
-    // explicit and implicit conversions to NativeFormat which is one of
-    // standard data types (implicit conversion is useful for preserving the
-    // compatibility with old code)
-    NativeFormat GetFormatId() const { return m_format; }
-    operator NativeFormat() const { return m_format; }
-
-    // this only works with standard ids
-    void SetId(wxDataFormatId format) { m_format = format; }
-
-    // string ids are used for custom types - this SetId() must be used for
-    // application-specific formats
-    wxString GetId() const;
-    void SetId(const wxChar *format);
-
-private:
-    // returns TRUE if the format is one of those defined in wxDataFormatId
-    bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; }
-
-    NativeFormat m_format;
-};
-
     #include "wx/msw/ole/dataobj.h"
 #elif defined(__WXMOTIF__)
     #include "wx/motif/dataobj.h"
 
 class WXDLLEXPORT wxPrivateDataObject : public wxDataObject
 {
-#ifdef __WXGTK__
+#if defined(__WXGTK__) || defined(__WXMOTIF__)
     DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
 #endif
 
 
 typedef void*           WXImage;
 typedef void*           WXCursor;
 typedef void*           WXFontList;
+
+typedef unsigned long   Atom;  /* this might fail on a few architectures */
+
 #endif // Motif
 
 #ifdef __WXGTK__
 
 #include "wx/defs.h"
 #include "wx/setup.h"
 
+#include "wx/dataobj.h"
+
 #include "wx/list.h"
 #include "wx/module.h"
 
   // clears wxTheClipboard and the system's clipboard if possible
   virtual void Clear();
 
+  /// If primary == TRUE, use primary selection in all further ops,
+  /// primary=FALSE resets it.
+  inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; }
+    
  // implementation 
  
   bool              m_open;
   wxList            m_data;
+  bool              m_usePrimary;
 };
 
 /* The clipboard */
 
 // classes
 //-------------------------------------------------------------------------
 
-class WXDLLEXPORT wxDataObject;
-class WXDLLEXPORT wxTextDataObject;
-class WXDLLEXPORT wxBitmapDataObject;
-class WXDLLEXPORT wxPrivateDataObject;
-class WXDLLEXPORT wxFileDataObject;
+class wxDataFormat;
+class wxDataObject;
+class wxTextDataObject;
 
 //-------------------------------------------------------------------------
-// wxDataObject
+// wxDataFormat
 //-------------------------------------------------------------------------
 
-class WXDLLEXPORT wxDataObject: public wxObject
+class wxDataFormat : public wxObject
 {
-  DECLARE_ABSTRACT_CLASS( wxDataObject )
+    DECLARE_CLASS( wxDataFormat )
 
 public:
+    wxDataFormat();
+    wxDataFormat( wxDataFormatId type );
+    wxDataFormat( const wxString &id );
+    wxDataFormat( const wxChar *id );
+    wxDataFormat( const wxDataFormat &format );
+    wxDataFormat( const Atom atom );
 
-  wxDataObject() {}
-  ~wxDataObject() {}
+    void SetType( wxDataFormatId type );
+    wxDataFormatId GetType() const;
 
-  virtual wxDataFormat GetFormat() const = 0;
-  
-  // implementation
-};
+    /* the string Id identifies the format of clipboard or DnD data. a word
+     * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
+     * to the clipboard - the latter with the Id "application/wxword", an
+     * image manipulation program would put a wxBitmapDataObject and a
+     * wxPrivateDataObject to the clipboard - the latter with "image/png". */
 
-// ----------------------------------------------------------------------------
-// wxTextDataObject is a specialization of wxDataObject for text data
-// ----------------------------------------------------------------------------
+    wxString GetId() const;
+    void SetId( const wxChar *id );
 
-class WXDLLEXPORT wxTextDataObject : public wxDataObject
-{
-  DECLARE_DYNAMIC_CLASS( wxTextDataObject )
+    Atom GetAtom();
+    void SetAtom(Atom atom) { m_hasAtom = TRUE; m_atom = atom; }
 
-public:
+    // implicit conversion to wxDataFormatId
+    operator wxDataFormatId() const { return m_type; }
 
-  wxTextDataObject() {}
-  wxTextDataObject( const wxString& strText ) 
-    : m_strText(strText) { }
-  
-  virtual wxDataFormat GetFormat() const
-    { return wxDF_TEXT; }
-    
-  void SetText( const wxString& strText) 
-    { m_strText = strText; }
-    
-  wxString GetText() const
-    { return m_strText; }
+    bool operator==(wxDataFormatId type) const { return m_type == type; }
+    bool operator!=(wxDataFormatId type) const { return m_type != type; }
 
 private:
-  wxString  m_strText;
-
+    wxDataFormatId  m_type;
+    wxString    m_id;
+    bool        m_hasAtom;
+    Atom        m_atom;
 };
 
-// ----------------------------------------------------------------------------
-// wxFileDataObject is a specialization of wxDataObject for file names
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxDataObject to be placed in wxDataBroker
+//----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxFileDataObject : public wxDataObject
+class wxDataObject : public wxObject
 {
-  DECLARE_DYNAMIC_CLASS( wxFileDataObject )
+  DECLARE_DYNAMIC_CLASS( wxDataObject )
 
 public:
 
-  wxFileDataObject(void) {}
-  
-  virtual wxDataFormat GetFormat() const
-    { return wxDF_FILENAME; }
-    
-  void AddFile( const wxString &file )
-    { m_files += file; m_files += (char)0; }
-    
-  wxString GetFiles() const
-    { return m_files; }
-    
-private:
-  wxString  m_files;
-  
-};
+  /* constructor */
+  wxDataObject();
 
-// ----------------------------------------------------------------------------
-// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
-// ----------------------------------------------------------------------------
+  /* destructor */
+  ~wxDataObject();
 
-class WXDLLEXPORT wxBitmapDataObject : public wxDataObject
-{
-  DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
+  /* write data to dest */
+  virtual void WriteData( void *dest ) const = 0;
 
-public:
+  /* get size of data */
+  virtual size_t GetSize() const = 0;
 
-  wxBitmapDataObject(void) {}
-  
-  virtual wxDataFormat GetFormat() const
-    { return wxDF_BITMAP; }
-    
-  void SetBitmap( const wxBitmap &bitmap )
-    { m_bitmap = bitmap; }
-    
-  wxBitmap GetBitmap() const
-    { return m_bitmap; }
-    
-private:
-  wxBitmap  m_bitmap;
+  /* implementation */
+
+  wxDataFormat &GetFormat();
+
+  wxDataFormatId GetFormatType() const;
+  wxString   GetFormatId() const;
+  Atom    GetFormatAtom() const;
+
+  wxDataFormat m_format;
 };
 
-// ----------------------------------------------------------------------------
-// wxPrivateDataObject is a specialization of wxDataObject for app specific data
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxTextDataObject is a specialization of wxDataObject for text data
+//----------------------------------------------------------------------------
 
-class WXDLLEXPORT wxPrivateDataObject : public wxDataObject
+class wxTextDataObject : public wxDataObject
 {
-  DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
+  DECLARE_DYNAMIC_CLASS( wxTextDataObject )
 
 public:
 
-  wxPrivateDataObject();
-    
-  ~wxPrivateDataObject();
-  
-  virtual wxDataFormat GetFormat() const
-    { return wxDF_PRIVATE; }
-    
-  // the string ID identifies the format of clipboard or DnD data. a word
-  // processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
-  // to the clipboard - the latter with the Id "WXWORD_FORMAT".
-    
-  void SetId( const wxString& id )
-    { m_id = id; }
-    
-  wxString GetId() const
-    { return m_id; }
-
-  // will make internal copy
-  void SetData( const char *data, size_t size );
-    
-  size_t GetDataSize() const
-    { return m_size; }
-    
-  char* GetData() const
-    { return m_data; }
-    
-private:
-  size_t     m_size;
-  char*      m_data;
-  wxString   m_id;
+  /* default constructor. call SetText() later or override
+     WriteData() and GetSize() for working on-demand */
+  wxTextDataObject();
+
+  /* constructor */
+  wxTextDataObject( const wxString& data );
+
+  /* set current text data */
+  void SetText( const wxString& data );
+
+  /* get current text data */
+  wxString GetText() const;
+
+  /* by default calls WriteString() with string set by constructor or
+     by SetText(). can be overridden for working on-demand */
+  virtual void WriteData( void *dest ) const;
+
+  /* by default, returns length of string as set by constructor or
+     by SetText(). can be overridden for working on-demand */
+  virtual size_t GetSize() const;
+
+  /* write string to dest */
+  void WriteString( const wxString &str, void *dest ) const;
+
+  /* implementation */
+
+  wxString  m_data;
 };
 
 
 
     virtual int ShowModal();
     virtual void EndModal(int retCode);
 
+    void SetReturnCode(int returnCode) { m_returnCode = returnCode; }
+    int GetReturnCode() const { return m_returnCode; }
+
     // Standard buttons
     void OnOK(wxCommandEvent& event);
     void OnApply(wxCommandEvent& event);
     //// Motif-specific
     bool          m_modalShowing;
     wxString      m_dialogTitle;
+    int           m_returnCode;
 
 protected:
     virtual void DoSetSize(int x, int y,
 
     int GetPixmapWidth() const { return m_pixmapWidth; }
     int GetPixmapHeight() const { return m_pixmapHeight; }
 
+public:
     // Change properties
     virtual void ChangeFont(bool keepOriginalSize = TRUE);             // Change to the current font (often overridden)
     virtual void DoChangeForegroundColour(WXWidget widget, wxColour& foregroundColour);
     // Change foreground colour using current foreground colour setting
     virtual void ChangeForegroundColour();
 
+protected:
     // Adds the widget to the hash table and adds event handlers.
     bool AttachWidget(wxWindow* parent, WXWidget mainWidget,
                       WXWidget formWidget, int x, int y, int width, int height);
 
 #ifndef   _WX_OLEDATAOBJ_H
 #define   _WX_OLEDATAOBJ_H
 
+// ----------------------------------------------------------------------------
+// wxDataFormat identifies the single format of data
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxDataFormat
+{
+public:
+    // the clipboard formats under Win32 are UINTs
+    typedef unsigned int NativeFormat;
+
+    wxDataFormat(NativeFormat format = wxDF_INVALID) { m_format = format; }
+    wxDataFormat& operator=(NativeFormat format)
+        { m_format = format; return *this; }
+
+    // defautl copy ctor/assignment operators ok
+
+    // comparison (must have both versions)
+    bool operator==(wxDataFormatId format) const
+        { return m_format == (NativeFormat)format; }
+    bool operator!=(wxDataFormatId format) const
+        { return m_format != (NativeFormat)format; }
+    bool operator==(const wxDataFormat& format) const
+        { return m_format == format.m_format; }
+    bool operator!=(const wxDataFormat& format) const
+        { return m_format != format.m_format; }
+
+    // explicit and implicit conversions to NativeFormat which is one of
+    // standard data types (implicit conversion is useful for preserving the
+    // compatibility with old code)
+    NativeFormat GetFormatId() const { return m_format; }
+    operator NativeFormat() const { return m_format; }
+
+    // this only works with standard ids
+    void SetId(wxDataFormatId format) { m_format = format; }
+
+    // string ids are used for custom types - this SetId() must be used for
+    // application-specific formats
+    wxString GetId() const;
+    void SetId(const wxChar *format);
+
+private:
+    // returns TRUE if the format is one of those defined in wxDataFormatId
+    bool IsStandard() const { return m_format > 0 && m_format < wxDF_MAX; }
+
+    NativeFormat m_format;
+};
+
 // ----------------------------------------------------------------------------
 // forward declarations
 // ----------------------------------------------------------------------------
 
     SetIcon(wxICON(mondrian));
 
     // create a menu bar
-    wxMenu *menuFile = new wxMenu(wxMENU_TEAROFF);
+    wxMenu *menuFile = new wxMenu;
+//    wxMenu *menuFile = new wxMenu(wxMENU_TEAROFF);
 
     menuFile->Append(Minimal_About, "&About...\tCtrl-A", "Show about dialog");
     menuFile->AppendSeparator();
 
  spinbutt.cpp \
  statbmp.cpp \
  statbox.cpp \
- statline.cpp \
  stattext.cpp \
  textctrl.cpp \
  timer.cpp \
- tooltip.cpp \
- utilsres.cpp \
- wave.cpp \
+ toolbar.cpp \
+ utils.cpp \
  window.cpp
 
 # propform.cpp \
 
     
     m_mainWidget = (WXWidget) buttonWidget;
     
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
     
     ChangeBackgroundColour ();
 
     m_windowStyle = style;
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     
     parent->AddChild((wxButton *)this);
     
     XmString text = XmStringCreateSimple ((char*) (const char*) label1);
     Widget parentWidget = (Widget) parent->GetClientWidget();
     
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
     
     /*
     * Patch Note (important)
 void wxButton::SetDefault()
 {
     wxWindow *parent = (wxWindow *)GetParent();
+/*
+    TODO
     if (parent)
         parent->SetDefaultItem(this);
+*/
     
     // We initially do not set XmNdefaultShadowThickness, to have small buttons.
     // Unfortunately, buttons are now mis-aligned. We try to correct this
 
     m_windowStyle = style;
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     
     if (parent) parent->AddChild(this);
     
     
     XmString text = XmStringCreateSimple (label1);
     Widget parentWidget = (Widget) parent->GetClientWidget();
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
     
     m_mainWidget = (WXWidget) XtVaCreateManagedWidget ("toggle",
         xmToggleButtonWidgetClass, parentWidget,
 
     
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     
     Widget parentWidget = (Widget) parent->GetClientWidget();
     
     
     DoChangeBackgroundColour((WXWidget) w, m_backgroundColour);
     
-    if (m_windowFont.Ok())
+    if (m_font.Ok())
         XtVaSetValues (w,
-        XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay((Widget) m_formWidget)),
+        XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_formWidget)),
         NULL);
     
     WXWidget *new_widgetList = new WXWidget[m_noStrings + 1];
     // Note that this causes the widget to be resized back
     // to its original size! We therefore have to set the size
     // back again. TODO: a better way in Motif?
-    if (m_windowFont.Ok())
+    if (m_font.Ok())
     {
         int width, height, width1, height1;
         GetSize(& width, & height);
         
-        XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay((Widget) m_mainWidget));
+        XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) m_mainWidget));
         XtVaSetValues ((Widget) m_mainWidget, XmNfontList, fontList, NULL);
         XtVaSetValues ((Widget) m_buttonWidget, XmNfontList, fontList, NULL);
         
 
 wxDataFormat  wxEnumClipboardFormats(wxDataFormat dataFormat)
 {
     // Only wxDF_TEXT supported
-    if (dataFormat == (wxDataFormat) 0)
+    if (dataFormat == wxDF_TEXT)
        return wxDF_TEXT;
     else
-       return (wxDataFormat) 0;
+       return wxDF_INVALID;
 }
 
 wxDataFormat  wxRegisterClipboardFormat(char *formatName)
 {
     // Not supported
-    return (wxDataFormat) 0;
+    return (wxDataFormat) wxDF_INVALID;
 }
 
 bool wxGetClipboardFormatName(wxDataFormat dataFormat, char *formatName, int maxCount)
             return wxSetClipboardData(data->GetFormat(), (wxObject*) (const char*) str);
             break;
         }
+/*
         case wxDF_BITMAP:
         case wxDF_DIB:
         {
             return wxSetClipboardData(data->GetFormat(), & bitmap);
             break;
         }
+*/
         default:
         {
             return FALSE;
                 return FALSE;
             break;
         }
+/*
         case wxDF_BITMAP:
         case wxDF_DIB:
         {
                 return FALSE;
             break;
         }
+*/
         default:
         {
             return FALSE;
 
     
     SetValue(value);
     
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
     
     SetCanAddEventHandler(TRUE);
 
 {
     // If we delete an item, we should initialize the parent panel,
     // because it could now be invalid.
+/*
+    TODO
     wxWindow *parent = (wxWindow *)GetParent();
     if (parent)
     {
         if (parent->GetDefaultItem() == (wxButton*) this)
             parent->SetDefaultItem((wxButton*) NULL);
     }
+*/
 }
 
 void wxControl::SetLabel(const wxString& label)
 
 #include "wx/dataobj.h"
 #include "wx/app.h"
 
+#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;
+}
+
 //-------------------------------------------------------------------------
 // wxDataObject
 //-------------------------------------------------------------------------
 
 IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
 
+wxDataObject::wxDataObject()
+{
+}
+
+wxDataObject::~wxDataObject()
+{
+}
+
+wxDataFormat &wxDataObject::GetFormat()
+{
+    return m_format;
+}
+
+wxDataFormatId wxDataObject::GetFormatType() const
+{
+    return m_format.GetType();
+}
+
+wxString wxDataObject::GetFormatId() const
+{
+    return m_format.GetId();
+}
+
+Atom wxDataObject::GetFormatAtom() const
+{
+    Atom ret = ((wxDataObject*) this)->m_format.GetAtom();
+    return ret;
+}
+
 // ----------------------------------------------------------------------------
 // wxTextDataObject
 // ----------------------------------------------------------------------------
 
 IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
 
-// ----------------------------------------------------------------------------
-// wxFileDataObject
-// ----------------------------------------------------------------------------
+wxTextDataObject::wxTextDataObject()
+{
+    m_format.SetType( wxDF_TEXT );
+}
 
-IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
+wxTextDataObject::wxTextDataObject( const wxString& data )
+{
+    m_format.SetType( wxDF_TEXT );
 
-// ----------------------------------------------------------------------------
-// wxBitmapDataObject
-// ----------------------------------------------------------------------------
+    m_data = data;
+}
+
+void wxTextDataObject::SetText( const wxString& data )
+{
+    m_data = data;
+}
+
+wxString wxTextDataObject::GetText() const
+{
+    return m_data;
+}
 
-IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
+void wxTextDataObject::WriteData( void *dest ) const
+{
+    WriteString( m_data, dest );
+}
+
+size_t wxTextDataObject::GetSize() const
+{
+    return m_data.Len() + 1;
+}
+
+void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
+{
+    memcpy( dest, str.mb_str(), str.Len()+1 );
+}
 
 // ----------------------------------------------------------------------------
 // wxPrivateDataObject
 
 IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
 
-wxPrivateDataObject::wxPrivateDataObject() 
-{ 
-    m_size = 0; 
-    m_data = (char*) NULL; 
-    m_id = wxTheApp->GetAppName();
+void wxPrivateDataObject::Free()
+{
+    if ( m_data )
+        free(m_data);
 }
-    
-wxPrivateDataObject::~wxPrivateDataObject()
-{ 
-    if (m_data) delete[] m_data; 
+
+wxPrivateDataObject::wxPrivateDataObject()
+{
+    wxString id = _T("application/");
+    id += wxTheApp->GetAppName();
+
+    m_format.SetId( id );
+
+    m_size = 0;
+    m_data = (void *)NULL;
 }
-  
-void wxPrivateDataObject::SetData( const char *data, size_t size )
+
+void wxPrivateDataObject::SetData( const void *data, size_t size )
 {
+    Free();
+
     m_size = size;
-    
-    if (m_data) delete[] m_data;
-    
-    m_data = new char[size];
+    m_data = malloc(size);
 
-    memcpy( m_data, data, size );  
+    memcpy( m_data, data, size );
+}
+
+void wxPrivateDataObject::WriteData( void *dest ) const
+{
+    WriteData( m_data, dest );
+}
+
+size_t wxPrivateDataObject::GetSize() const
+{
+    return m_size;
+}
+
+void wxPrivateDataObject::WriteData( const void *data, void *dest ) const
+{
+    memcpy( dest, data, GetSize() );
 }
 
 
 wxList wxModelessWindows;  // Frames and modeless dialogs
 extern wxList wxPendingDelete;
 
+extern wxHashTable *wxWidgetHashTable;
+
 #define wxUSE_INVISIBLE_RESIZE 1
 
 #if !USE_SHARED_LIBRARY
         XmStringFree(str);
     }
     
-    m_windowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+    m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
     ChangeFont(FALSE);
     
     wxAddWindowToTable(dialogShell, this);
 
 
 #include "wx/motif/private.h"
 
+extern wxHashTable *wxWidgetHashTable;
+
 void wxCloseFrameCallback(Widget, XtPointer, XmAnyCallbackStruct *cbs);
 void wxFrameFocusProc(Widget workArea, XtPointer clientData, 
                       XmAnyCallbackStruct *cbs);
     m_frameMenuBar = NULL;
     m_frameStatusBar = NULL;
     
-    m_windowParent = NULL;
+    m_parent = NULL;
     m_iconized = FALSE;
     
     //// Motif-specific
     
     m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
     m_foregroundColour = *wxBLACK;
-    m_windowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+    m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
     
     if ( id > -1 )
         m_windowId = id;
 
     if (height == -1)
         height = 80;
     
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
     
     SetCanAddEventHandler(TRUE);
 
     XtAddCallback (listWidget, XmNdefaultActionCallback, (XtCallbackProc) wxListBoxDefaultActionProc,
         (XtPointer) this);
 
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
 
     SetCanAddEventHandler(TRUE);
 
     
     m_backgroundColour = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_APPWORKSPACE);
     m_foregroundColour = *wxBLACK;
-    m_windowFont = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
+    m_font = wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT);
     
     if ( id > -1 )
         m_windowId = id;
 
     m_radioButtonLabels = (wxString*) NULL;
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
 
     SetName(name);
     SetValidator(val);
 
     m_formWidget = (WXWidget) formWidget;
 
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
     if (label1 != "")
     {
         text = XmStringCreateSimple ((char*) (const char*) label1);
     }
     SetSelection (0);
 
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
 
     //    XtManageChild((Widget) m_formWidget);
 {
     wxWindow::ChangeFont(keepOriginalSize);
 
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay((Widget) GetTopWidget()));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay((Widget) GetTopWidget()));
 
     int i;
     for (i = 0; i < m_noItems; i++)
 
     SetValidator(validator);
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     
     if (parent) parent->AddChild(this);
     
     
     XmString text = XmStringCreateSimple ((char*) (const char*) label1);
     
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
     
     Widget radioButtonWidget = XtVaCreateManagedWidget ("toggle",
 #if wxUSE_GADGETS
 
     
     XtAddCallback (sliderWidget, XmNdragCallback, (XtCallbackProc) wxSliderCallback, (XtPointer) this);
     
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     
     ChangeFont(FALSE);
     SetCanAddEventHandler(TRUE);
 
                     XmNlabelType, XmPIXMAP,
                     NULL);
 
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
 
     SetCanAddEventHandler(TRUE);
 
 IMPLEMENT_DYNAMIC_CLASS(wxStaticBox, wxControl)
 
 BEGIN_EVENT_TABLE(wxStaticBox, wxControl)
-       EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
+//     EVT_ERASE_BACKGROUND(wxStaticBox::OnEraseBackground)
 END_EVENT_TABLE()
 
 #endif
     m_labelWidget = (WXWidget) 0;
     m_backgroundColour = parent->GetBackgroundColour();
     m_foregroundColour = parent->GetForegroundColour();
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
 
     SetName(name);
 
 
     if (hasLabel)
     {
-        XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+        XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
 
         wxString label1(wxStripMenuCodes(label));
         XmString text = XmStringCreateSimple ((char*) (const char*) label1);
 
            m_windowId = id;
 
     m_windowStyle = style;
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
 
     char* label1 = (label.IsNull() ? "" : (char*) (const char*) label);
 
 //    XmString text = XmStringCreateSimple (label1);
     XmString text = XmStringCreateLtoR (label1, XmSTRING_DEFAULT_CHARSET);
 
-    XmFontList fontList = (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(parentWidget));
+    XmFontList fontList = (XmFontList) m_font.GetFontList(1.0, XtDisplay(parentWidget));
 
     m_mainWidget = (WXWidget) XtVaCreateManagedWidget ((char*) (const char*) name,
                                          xmLabelWidgetClass,
 
     XtAddCallback((Widget) m_mainWidget, XmNlosingFocusCallback, (XtCallbackProc)wxTextWindowLoseFocusProc, (XtPointer)this);
 
     // font
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
 
     SetCanAddEventHandler(TRUE);
 
 
     m_mainWidget = (WXWidget) toolbar;
 
-    m_windowFont = parent->GetFont();
+    m_font = parent->GetFont();
     ChangeFont(FALSE);
 
     SetCanAddEventHandler(TRUE);
 
     else
     {
         // Restore old cursor
-        if (win->GetCursor()->Ok())
-            attrs.cursor = (Cursor) win->GetCursor()->GetXCursor(display);
+        if (win->GetCursor().Ok())
+            attrs.cursor = (Cursor) win->GetCursor().GetXCursor(display);
         else
             attrs.cursor = None;
     }