]> git.saurik.com Git - wxWidgets.git/commitdiff
New wxDataObject, DnD and Clipboard code
authorRobert Roebling <robert@roebling.de>
Mon, 14 Dec 1998 16:13:49 +0000 (16:13 +0000)
committerRobert Roebling <robert@roebling.de>
Mon, 14 Dec 1998 16:13:49 +0000 (16:13 +0000)
  A few more minor fixes

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

21 files changed:
configure
configure.in
include/wx/dataobj.h [new file with mode: 0644]
include/wx/defs.h
include/wx/gtk/clipbrd.h
include/wx/gtk/dataobj.h [new file with mode: 0644]
include/wx/gtk/dnd.h
include/wx/gtk1/clipbrd.h
include/wx/gtk1/dataobj.h [new file with mode: 0644]
include/wx/gtk1/dnd.h
samples/controls/controls.cpp
samples/image/image.cpp
src/common/variant.cpp
src/generic/listctrl.cpp
src/gtk.inc
src/gtk/clipbrd.cpp
src/gtk/dataobj.cpp [new file with mode: 0644]
src/gtk/dnd.cpp
src/gtk1/clipbrd.cpp
src/gtk1/dataobj.cpp [new file with mode: 0644]
src/gtk1/dnd.cpp

index 5bd21457fe3a1542ea608c672e061edc12b9266a..7aca4c2ffa0ef6b1c04e5527179bff7730f00f28 100755 (executable)
--- a/configure
+++ b/configure
@@ -4570,7 +4570,7 @@ DEFAULT_wxUSE_POSTSCRIPT=1
 DEFAULT_wxUSE_IPC=1
 DEFAULT_wxUSE_RESOURCES=1
 DEFAULT_wxUSE_CONSTRAINTS=1
-DEFAULT_wxUSE_CLIPBOARD=0
+DEFAULT_wxUSE_CLIPBOARD=1
 DEFAULT_wxUSE_DND=1
 
 DEFAULT_wxUSE_MDI_ARCHITECTURE=1
index 5ac599ba21367b8ddd1405a844bee8dca022e992..6baea894c109098aa5ee2462d4d6554fdfab3f0e 100644 (file)
@@ -717,7 +717,7 @@ DEFAULT_wxUSE_POSTSCRIPT=1
 DEFAULT_wxUSE_IPC=1
 DEFAULT_wxUSE_RESOURCES=1
 DEFAULT_wxUSE_CONSTRAINTS=1
-DEFAULT_wxUSE_CLIPBOARD=0
+DEFAULT_wxUSE_CLIPBOARD=1
 DEFAULT_wxUSE_DND=1
 
 DEFAULT_wxUSE_MDI_ARCHITECTURE=1
diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h
new file mode 100644 (file)
index 0000000..ef2a979
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef _WX_DATAOBJ_H_BASE_
+#define _WX_DATAOBJ_H_BASE_
+
+#if defined(__WXMSW__)
+#include "wx/msw/ole/dataobj.h"
+#elif defined(__WXMOTIF__)
+#include "wx/motif/dnd.h"
+#elif defined(__WXGTK__)
+#include "wx/gtk/dataobj.h"
+#elif defined(__WXQT__)
+#include "wx/qt/dnd.h"
+#elif defined(__WXMAC__)
+#include "wx/mac/dnd.h"
+#elif defined(__WXSTUBS__)
+#include "wx/stubs/dnd.h"
+#endif
+
+#endif
+    // _WX_DATAOBJ_H_BASE_
index cc731991c3bee92a08ab654dd06d0c913ece28d0..41987323ee543c97e15d838a92fc07419e4199f1 100644 (file)
@@ -721,7 +721,8 @@ enum wxDataFormat
   wxDF_METAFILE =         3,  /* CF_METAFILEPICT */
   wxDF_DIB =              8,  /* CF_DIB */
   wxDF_OEMTEXT =          7,  /* CF_OEMTEXT */
-  wxDF_FILENAME =         15  /* CF_HDROP */
+  wxDF_FILENAME =         15, /* CF_HDROP */
+  wxDF_PRIVATE =          20
 };
 
 // Virtual keycodes
index b8d488a7471f4b66cc00a250b2f0b33548c2fb10..5f7a92eead4d654426a58d8f1ba164270e2a078f 100644 (file)
@@ -18,8 +18,8 @@
 #include "wx/defs.h"
 #include "wx/object.h"
 #include "wx/list.h"
+#include "wx/dataobj.h"
 #include "wx/control.h"
-#include "wx/dnd.h"      // for wxDataObject
 #include "wx/module.h"
 
 //-----------------------------------------------------------------------------
@@ -48,21 +48,32 @@ public:
   wxClipboard();
   ~wxClipboard();
 
-  virtual void SetData( wxDataObject *data );
+  // open the clipboard before SetData() and GetData()
+  virtual bool Open();
   
-  virtual bool IsSupportedFormat( wxDataFormat format );
-  virtual bool ObtainData( wxDataFormat format );
+  // close the clipboard after SetData() and GetData()
+  virtual void Close();
   
-  // call these after ObtainData()
-  virtual size_t GetDataSize() const;
-  virtual void GetDataHere( void *data ) const;
+  // can be called several times
+  virtual bool SetData( wxDataObject *data );
+
+  // format available on the clipboard ? 
+  // supply ID if private format, the same as wxPrivateDataObject::SetId() 
+  virtual bool IsSupportedFormat( wxDataFormat format, const wxString &id = "" );
+  
+  // fill data with data on the clipboard (if available)
+  virtual bool GetData( wxDataObject *data );
   
   // clears wxTheClipboard and the system's clipboard if possible
   virtual void Clear();
 
  // implementation 
+  GdkAtom    GetTargetAtom( wxDataFormat format, const wxString &id = "" );
+  bool              m_open;
   
-  wxDataObject     *m_data;
+  wxList            m_dataObjects;
   char             *m_sentString, 
                   *m_receivedString;
   void             *m_receivedTargets;
@@ -71,8 +82,7 @@ public:
   bool              m_formatSupported;
   GdkAtom           m_targetRequested;
 
-  size_t            m_receivedSize;
-  char              *m_receivedData;
+  wxDataObject      *m_receivedData;
 };
 
 //-----------------------------------------------------------------------------
diff --git a/include/wx/gtk/dataobj.h b/include/wx/gtk/dataobj.h
new file mode 100644 (file)
index 0000000..8128475
--- /dev/null
@@ -0,0 +1,178 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.h
+// Purpose:     declaration of the wxDataObject class
+// Author:      Robert Roebling
+// RCS-ID:      $Id$
+// Copyright:   (c) 1998 Vadim Zeitlin, Robert Roebling
+// Licence:     wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef __GTKDATAOBJECTH__
+#define __GTKDATAOBJECTH__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "wx/defs.h"
+#include "wx/object.h"
+#include "wx/string.h"
+#include "wx/bitmap.h"
+
+//-------------------------------------------------------------------------
+// classes
+//-------------------------------------------------------------------------
+
+class wxDataObject;
+class wxTextDataObject;
+class wxBitmapDataObject;
+class wxPrivateDataObject;
+class wxFileDataObject;
+
+//-------------------------------------------------------------------------
+// wxDataObject
+//-------------------------------------------------------------------------
+
+class wxDataObject: public wxObject
+{
+  DECLARE_ABSTRACT_CLASS( wxDataObject )
+
+public:
+
+  wxDataObject() {}
+  ~wxDataObject() {}
+
+  virtual wxDataFormat GetFormat() const = 0;
+  
+  // implementation
+  
+  GdkAtom  m_formatAtom;
+};
+
+// ----------------------------------------------------------------------------
+// wxTextDataObject is a specialization of wxDataObject for text data
+// ----------------------------------------------------------------------------
+
+class wxTextDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxTextDataObject )
+
+public:
+
+  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() 
+    { return m_strText; }
+
+private:
+  wxString  m_strText;
+
+};
+
+// ----------------------------------------------------------------------------
+// wxFileDataObject is a specialization of wxDataObject for file names
+// ----------------------------------------------------------------------------
+
+class wxFileDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxFileDataObject )
+
+public:
+
+  wxFileDataObject(void) {}
+  
+  virtual wxDataFormat GetFormat() const
+    { return wxDF_FILENAME; }
+    
+  void AddFile( const wxString &file )
+    { m_files += file; m_files += (char)0; }
+    
+  wxString GetFiles()
+    { return m_files; }
+    
+private:
+  wxString  m_files;
+  
+};
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
+// ----------------------------------------------------------------------------
+
+class wxBitmapDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
+
+public:
+
+  wxBitmapDataObject(void) {}
+  
+  virtual wxDataFormat GetFormat() const
+    { return wxDF_BITMAP; }
+    
+  void SetBitmap( const wxBitmap &bitmap )
+    { m_bitmap = bitmap; }
+    
+  wxBitmap GetBitmap()
+    { return m_bitmap; }
+    
+private:
+  wxBitmap  m_bitmap;
+};
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject is a specialization of wxDataObject for app specific data
+// ----------------------------------------------------------------------------
+
+class wxPrivateDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
+
+public:
+
+  wxPrivateDataObject() 
+    { m_size = 0; m_data = (char*) NULL; }
+    
+  ~wxPrivateDataObject()
+    { if (m_data) delete[] m_data; }
+  
+  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()
+    { return m_id; }
+
+  // will make internal copy
+  void SetData( const char *data, size_t size );
+    
+  size_t GetDataSize()
+    { return m_size; }
+    
+  char* GetData()
+    { return m_data; }
+    
+private:
+  size_t     m_size;
+  char*      m_data;
+  wxString   m_id;
+};
+
+
+#endif  
+       //__GTKDNDH__
+
index 937fe1aa896ddba3a793568d0b45aefeaaa1493f..e319f0d415ef7ed6a7723f74d911bda823b62563 100644 (file)
@@ -18,6 +18,7 @@
 #include "wx/defs.h"
 #include "wx/object.h"
 #include "wx/string.h"
+#include "wx/dataobj.h"
 #include "wx/cursor.h"
 
 //-------------------------------------------------------------------------
 
 class wxWindow;
 
-class wxDataObject;
-class wxTextDataObject;
-class wxFileDataObject;
-
 class wxDropTarget;
 class wxTextDropTarget;
 class wxFileDropTarget;
 
 class wxDropSource;
 
-//-------------------------------------------------------------------------
-// wxDataObject
-//-------------------------------------------------------------------------
-
-class wxDataObject: public wxObject
-{
-public:
-
-  wxDataObject() {};
-  ~wxDataObject() {};
-
-  virtual wxDataFormat GetPreferredFormat() const = 0;
-  virtual bool IsSupportedFormat( wxDataFormat format ) const = 0;
-  virtual size_t GetDataSize() const = 0;
-  virtual void GetDataHere( void *data ) const = 0;
-
-};
-
-// ----------------------------------------------------------------------------
-// wxTextDataObject is a specialization of wxDataObject for text data
-// ----------------------------------------------------------------------------
-
-class wxTextDataObject : public wxDataObject
-{
-public:
-
-  wxTextDataObject() { }
-  wxTextDataObject(const wxString& strText) : m_strText(strText) { }
-  void Init(const wxString& strText) { m_strText = strText; }
-
-  virtual wxDataFormat GetPreferredFormat() const
-    { return wxDF_TEXT; }
-    
-  virtual bool IsSupportedFormat(wxDataFormat format) const
-    { return format == wxDF_TEXT; }
-
-  virtual size_t GetDataSize() const
-    { return m_strText.Len() + 1; } // +1 for trailing '\0'
-    
-  virtual void GetDataHere( void *data ) const
-    { memcpy(data, m_strText.c_str(), GetDataSize()); }
-
-private:
-  wxString  m_strText;
-  
-};
-
-// ----------------------------------------------------------------------------
-// wxFileDataObject is a specialization of wxDataObject for file names
-// ----------------------------------------------------------------------------
-
-class wxFileDataObject : public wxDataObject
-{
-public:
-
-  wxFileDataObject(void) { }
-  void AddFile( const wxString &file )
-    { m_files += file; m_files += '\0'; }
-
-  virtual wxDataFormat GetPreferredFormat() const
-    { return wxDF_FILENAME; }
-    
-  virtual bool IsSupportedFormat( wxDataFormat format ) const
-    { return format == wxDF_FILENAME; }
-    
-  virtual size_t GetDataSize() const
-    { return m_files.Len(); } // no trailing '\0'
-    
-  virtual void GetDataHere( void *data ) const
-    { memcpy(data, m_files.c_str(), GetDataSize()); }
-
-private:
-  wxString  m_files;
-  
-};
 //-------------------------------------------------------------------------
 // wxDropTarget
 //-------------------------------------------------------------------------
index b8d488a7471f4b66cc00a250b2f0b33548c2fb10..5f7a92eead4d654426a58d8f1ba164270e2a078f 100644 (file)
@@ -18,8 +18,8 @@
 #include "wx/defs.h"
 #include "wx/object.h"
 #include "wx/list.h"
+#include "wx/dataobj.h"
 #include "wx/control.h"
-#include "wx/dnd.h"      // for wxDataObject
 #include "wx/module.h"
 
 //-----------------------------------------------------------------------------
@@ -48,21 +48,32 @@ public:
   wxClipboard();
   ~wxClipboard();
 
-  virtual void SetData( wxDataObject *data );
+  // open the clipboard before SetData() and GetData()
+  virtual bool Open();
   
-  virtual bool IsSupportedFormat( wxDataFormat format );
-  virtual bool ObtainData( wxDataFormat format );
+  // close the clipboard after SetData() and GetData()
+  virtual void Close();
   
-  // call these after ObtainData()
-  virtual size_t GetDataSize() const;
-  virtual void GetDataHere( void *data ) const;
+  // can be called several times
+  virtual bool SetData( wxDataObject *data );
+
+  // format available on the clipboard ? 
+  // supply ID if private format, the same as wxPrivateDataObject::SetId() 
+  virtual bool IsSupportedFormat( wxDataFormat format, const wxString &id = "" );
+  
+  // fill data with data on the clipboard (if available)
+  virtual bool GetData( wxDataObject *data );
   
   // clears wxTheClipboard and the system's clipboard if possible
   virtual void Clear();
 
  // implementation 
+  GdkAtom    GetTargetAtom( wxDataFormat format, const wxString &id = "" );
+  bool              m_open;
   
-  wxDataObject     *m_data;
+  wxList            m_dataObjects;
   char             *m_sentString, 
                   *m_receivedString;
   void             *m_receivedTargets;
@@ -71,8 +82,7 @@ public:
   bool              m_formatSupported;
   GdkAtom           m_targetRequested;
 
-  size_t            m_receivedSize;
-  char              *m_receivedData;
+  wxDataObject      *m_receivedData;
 };
 
 //-----------------------------------------------------------------------------
diff --git a/include/wx/gtk1/dataobj.h b/include/wx/gtk1/dataobj.h
new file mode 100644 (file)
index 0000000..8128475
--- /dev/null
@@ -0,0 +1,178 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.h
+// Purpose:     declaration of the wxDataObject class
+// Author:      Robert Roebling
+// RCS-ID:      $Id$
+// Copyright:   (c) 1998 Vadim Zeitlin, Robert Roebling
+// Licence:     wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef __GTKDATAOBJECTH__
+#define __GTKDATAOBJECTH__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "wx/defs.h"
+#include "wx/object.h"
+#include "wx/string.h"
+#include "wx/bitmap.h"
+
+//-------------------------------------------------------------------------
+// classes
+//-------------------------------------------------------------------------
+
+class wxDataObject;
+class wxTextDataObject;
+class wxBitmapDataObject;
+class wxPrivateDataObject;
+class wxFileDataObject;
+
+//-------------------------------------------------------------------------
+// wxDataObject
+//-------------------------------------------------------------------------
+
+class wxDataObject: public wxObject
+{
+  DECLARE_ABSTRACT_CLASS( wxDataObject )
+
+public:
+
+  wxDataObject() {}
+  ~wxDataObject() {}
+
+  virtual wxDataFormat GetFormat() const = 0;
+  
+  // implementation
+  
+  GdkAtom  m_formatAtom;
+};
+
+// ----------------------------------------------------------------------------
+// wxTextDataObject is a specialization of wxDataObject for text data
+// ----------------------------------------------------------------------------
+
+class wxTextDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxTextDataObject )
+
+public:
+
+  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() 
+    { return m_strText; }
+
+private:
+  wxString  m_strText;
+
+};
+
+// ----------------------------------------------------------------------------
+// wxFileDataObject is a specialization of wxDataObject for file names
+// ----------------------------------------------------------------------------
+
+class wxFileDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxFileDataObject )
+
+public:
+
+  wxFileDataObject(void) {}
+  
+  virtual wxDataFormat GetFormat() const
+    { return wxDF_FILENAME; }
+    
+  void AddFile( const wxString &file )
+    { m_files += file; m_files += (char)0; }
+    
+  wxString GetFiles()
+    { return m_files; }
+    
+private:
+  wxString  m_files;
+  
+};
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
+// ----------------------------------------------------------------------------
+
+class wxBitmapDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
+
+public:
+
+  wxBitmapDataObject(void) {}
+  
+  virtual wxDataFormat GetFormat() const
+    { return wxDF_BITMAP; }
+    
+  void SetBitmap( const wxBitmap &bitmap )
+    { m_bitmap = bitmap; }
+    
+  wxBitmap GetBitmap()
+    { return m_bitmap; }
+    
+private:
+  wxBitmap  m_bitmap;
+};
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject is a specialization of wxDataObject for app specific data
+// ----------------------------------------------------------------------------
+
+class wxPrivateDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
+
+public:
+
+  wxPrivateDataObject() 
+    { m_size = 0; m_data = (char*) NULL; }
+    
+  ~wxPrivateDataObject()
+    { if (m_data) delete[] m_data; }
+  
+  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()
+    { return m_id; }
+
+  // will make internal copy
+  void SetData( const char *data, size_t size );
+    
+  size_t GetDataSize()
+    { return m_size; }
+    
+  char* GetData()
+    { return m_data; }
+    
+private:
+  size_t     m_size;
+  char*      m_data;
+  wxString   m_id;
+};
+
+
+#endif  
+       //__GTKDNDH__
+
index 937fe1aa896ddba3a793568d0b45aefeaaa1493f..e319f0d415ef7ed6a7723f74d911bda823b62563 100644 (file)
@@ -18,6 +18,7 @@
 #include "wx/defs.h"
 #include "wx/object.h"
 #include "wx/string.h"
+#include "wx/dataobj.h"
 #include "wx/cursor.h"
 
 //-------------------------------------------------------------------------
 
 class wxWindow;
 
-class wxDataObject;
-class wxTextDataObject;
-class wxFileDataObject;
-
 class wxDropTarget;
 class wxTextDropTarget;
 class wxFileDropTarget;
 
 class wxDropSource;
 
-//-------------------------------------------------------------------------
-// wxDataObject
-//-------------------------------------------------------------------------
-
-class wxDataObject: public wxObject
-{
-public:
-
-  wxDataObject() {};
-  ~wxDataObject() {};
-
-  virtual wxDataFormat GetPreferredFormat() const = 0;
-  virtual bool IsSupportedFormat( wxDataFormat format ) const = 0;
-  virtual size_t GetDataSize() const = 0;
-  virtual void GetDataHere( void *data ) const = 0;
-
-};
-
-// ----------------------------------------------------------------------------
-// wxTextDataObject is a specialization of wxDataObject for text data
-// ----------------------------------------------------------------------------
-
-class wxTextDataObject : public wxDataObject
-{
-public:
-
-  wxTextDataObject() { }
-  wxTextDataObject(const wxString& strText) : m_strText(strText) { }
-  void Init(const wxString& strText) { m_strText = strText; }
-
-  virtual wxDataFormat GetPreferredFormat() const
-    { return wxDF_TEXT; }
-    
-  virtual bool IsSupportedFormat(wxDataFormat format) const
-    { return format == wxDF_TEXT; }
-
-  virtual size_t GetDataSize() const
-    { return m_strText.Len() + 1; } // +1 for trailing '\0'
-    
-  virtual void GetDataHere( void *data ) const
-    { memcpy(data, m_strText.c_str(), GetDataSize()); }
-
-private:
-  wxString  m_strText;
-  
-};
-
-// ----------------------------------------------------------------------------
-// wxFileDataObject is a specialization of wxDataObject for file names
-// ----------------------------------------------------------------------------
-
-class wxFileDataObject : public wxDataObject
-{
-public:
-
-  wxFileDataObject(void) { }
-  void AddFile( const wxString &file )
-    { m_files += file; m_files += '\0'; }
-
-  virtual wxDataFormat GetPreferredFormat() const
-    { return wxDF_FILENAME; }
-    
-  virtual bool IsSupportedFormat( wxDataFormat format ) const
-    { return format == wxDF_FILENAME; }
-    
-  virtual size_t GetDataSize() const
-    { return m_files.Len(); } // no trailing '\0'
-    
-  virtual void GetDataHere( void *data ) const
-    { memcpy(data, m_files.c_str(), GetDataSize()); }
-
-private:
-  wxString  m_files;
-  
-};
 //-------------------------------------------------------------------------
 // wxDropTarget
 //-------------------------------------------------------------------------
index 371df8a09ef7a40e1433e712a93696b90d5a0c10..52ef792d97da75ec7daf5be9d06118db2ad718c9 100644 (file)
@@ -408,21 +408,41 @@ void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
 {
 #ifdef __WXGTK__
 
-  if (!wxTheClipboard->IsSupportedFormat( wxDF_TEXT )) return;
-  
-  if (!wxTheClipboard->ObtainData( wxDF_TEXT )) return;
-  
-  int size = wxTheClipboard->GetDataSize()+1;
-  
-  char *data = new char[size];
-  
-  data[size-1] = 0;
+  if (!wxTheClipboard->IsSupportedFormat( wxDF_TEXT ))
+  {
+     *m_text << "The clipboard doesn't contain any data in the requested format." << "\n";
+     
+     return;
+  }
+
+  if (!wxTheClipboard->Open())
+  {
+     *m_text << "Error opening the clipboard." << "\n";
+     
+     return;
+  }
+  else
+  {
+     *m_text << "Successfully opened the clipboard." << "\n";
+  }
+
+  wxTextDataObject *data = new wxTextDataObject();
   
-  wxTheClipboard->GetDataHere( data );
+  if (wxTheClipboard->GetData( data ))
+  {
+     *m_text << "Successfully retrieved data from the clipboard." << "\n";
+     *m_multitext << data->GetText() << "\n";
+  }
+  else
+  {
+     *m_text << "Error getting data from the clipboard." << "\n";
+  }
+     
+  wxTheClipboard->Close();
   
-  *m_multitext << data << "\n";
+  *m_text << "Closed the clipboard." << "\n";
   
-  delete[] data;
+  delete data;
 
 #endif
 }
@@ -437,8 +457,30 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
   
   wxTextDataObject *data = new wxTextDataObject( text );
   
-  wxTheClipboard->SetData( data );
+  if (!wxTheClipboard->Open())
+  {
+     *m_text << "Error opening the clipboard." << "\n";
+     
+     return;
+  }
+  else
+  {
+     *m_text << "Successfully opened the clipboard." << "\n";
+  }
 
+  if (!wxTheClipboard->SetData( data ))
+  {
+     *m_text << "Error while copying to the clipboard." << "\n";
+  }
+  else
+  {
+     *m_text << "Successfully copied data to the clipboard." << "\n";
+  }
+
+  wxTheClipboard->Close();
+  
+  *m_text << "Closed the clipboard." << "\n";
+  
 #endif
 }
 
index 4e5146080765cc598395abcd8947c0bd2c1e11dd..1c64b7aedc764e104c1b82ff83ddf7aafd352c84 100644 (file)
@@ -77,8 +77,6 @@ END_EVENT_TABLE()
 MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size ) 
   : wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER ) 
 {
-  wxImage image;
-
   wxBitmap bitmap( 100, 100 );
   
   wxMemoryDC dc;
@@ -88,14 +86,14 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c
   dc.DrawRectangle( 0, 0, 100, 100 );
   dc.SelectObject( wxNullBitmap );
   
-  image = bitmap.ConvertToImage();
+  wxImage image( bitmap );
   image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG );
   
   image.LoadFile( "../horse.png", wxBITMAP_TYPE_PNG );
-  my_horse = new wxBitmap( image );
+  my_horse = new wxBitmap( image.ConvertToBitmap() );
   
   image.LoadFile( "../test.png", wxBITMAP_TYPE_PNG );
-  my_square = new wxBitmap( image );
+  my_square = new wxBitmap( image.ConvertToBitmap() );
 }
 
 MyCanvas::~MyCanvas(void)
index 90e577e68e2a484e9006b7f922bb1c10fc8d6135..86d5c831755cbca604f3b81346a2c63b4774c786 100644 (file)
@@ -771,13 +771,13 @@ bool wxVariantDataTime::Write(wxString& str) const
     return TRUE;
 }
 
-bool wxVariantDataTime::Read(istream& str)
+bool wxVariantDataTime::Read(istream& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
 }
 
-bool wxVariantDataTime::Read(wxString& str)
+bool wxVariantDataTime::Read(wxString& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
@@ -844,13 +844,13 @@ bool wxVariantDataDate::Write(wxString& str) const
     return TRUE;
 }
 
-bool wxVariantDataDate::Read(istream& str)
+bool wxVariantDataDate::Read(istream& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
 }
 
-bool wxVariantDataDate::Read(wxString& str)
+bool wxVariantDataDate::Read(wxString& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
@@ -921,13 +921,13 @@ bool wxVariantDataVoidPtr::Write(wxString& str) const
     return TRUE;
 }
 
-bool wxVariantDataVoidPtr::Read(istream& str)
+bool wxVariantDataVoidPtr::Read(istream& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
 }
 
-bool wxVariantDataVoidPtr::Read(wxString& str)
+bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str))
 {
     // Not implemented
     return FALSE;
index 7b63d0044a49becce1e6cf0350914977a228c3d8..6db8a65314b8aa97c3daa32d6c5f271fa93b1dd6 100644 (file)
@@ -1913,7 +1913,7 @@ void wxListMainWindow::CalculatePositions( void )
         int y = 1;
         int entireHeight = m_lines.Number() * lineSpacing + 2;
         int scroll_pos = GetScrollPos( wxVERTICAL );
-        SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15-6) / m_yScroll, 0, scroll_pos, TRUE );
+        SetScrollbars( m_xScroll, m_yScroll, 0, (entireHeight+15) / m_yScroll, 0, scroll_pos, TRUE );
         GetClientSize( &clientWidth, &clientHeight );
 
         wxNode* node = m_lines.First();
@@ -1959,11 +1959,11 @@ void wxListMainWindow::CalculatePositions( void )
                 line->GetSize( lineWidth, lineHeight );
                 if (lineWidth > maxWidth) maxWidth = lineWidth;
                 y += lineSpacing;
-                if (y+lineSpacing-7 >= clientHeight) // -7 for earlier "line breaking"
+                if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
                 {
                     y = 5;
-                    x += maxWidth+5;
-                    entireWidth += maxWidth+5;
+                    x += maxWidth+6;
+                    entireWidth += maxWidth+6;
                     maxWidth = 0;
                 }
                 node = node->Next();
@@ -1976,7 +1976,7 @@ void wxListMainWindow::CalculatePositions( void )
                 if (!node) tries = 1;  // everything fits, no second try required
             }
         }
-        m_visibleLines = (clientHeight+7) / (lineSpacing); // +7 for earlier "line breaking"
+        m_visibleLines = (clientHeight+6) / (lineSpacing); // +6 for earlier "line breaking"
        
         int scroll_pos = GetScrollPos( wxHORIZONTAL );
         SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
index 3e3457f3ee7c826db22978b7b0bf839d0d2c5f3d..edf6038a34bafe3cb10d48a7b55061b96f5aea95 100644 (file)
@@ -80,6 +80,7 @@ LIB_CPP_SRC=\
  gtk/combobox.cpp \
  gtk/cursor.cpp \
  gtk/data.cpp \
+ gtk/dataobj.cpp \
  gtk/dc.cpp \
  gtk/dcclient.cpp \
  gtk/dcmemory.cpp \
index d7812a880f0a6bbbf69ea24ffa0e13c24a81e8c8..253a7157a75b8ab9c27b7e37e4299ef22b95fe47 100644 (file)
@@ -57,26 +57,26 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
                             GtkSelectionData *selection_data, 
                            wxClipboard *clipboard )
 {
-  if (!wxTheClipboard) return;
+    if (!wxTheClipboard) return;
   
-  if (selection_data->length <= 0) return;
+    if (selection_data->length <= 0) return;
   
-  // make sure we got the data in the correct form 
-  if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
+    // make sure we got the data in the correct form 
+    if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
   
-  // the atoms we received, holding a list of targets (= formats) 
-  GdkAtom *atoms = (GdkAtom *)selection_data->data;
+    // the atoms we received, holding a list of targets (= formats) 
+    GdkAtom *atoms = (GdkAtom *)selection_data->data;
 
-  for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
-  {
-     if (atoms[i] == clipboard->m_targetRequested)
-     {
-       clipboard->m_formatSupported = TRUE;
-       return;
-     }
-  }
+    for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
+    {
+        if (atoms[i] == clipboard->m_targetRequested)
+        {
+            clipboard->m_formatSupported = TRUE;
+            return;
+        }
+    }
 
-  return;
+    return;
 }
 
 //-----------------------------------------------------------------------------
@@ -88,20 +88,63 @@ selection_received( GtkWidget *WXUNUSED(widget),
                     GtkSelectionData *selection_data, 
                    wxClipboard *clipboard )
 {
-  if (!wxTheClipboard) return;
-  
-  if (selection_data->length <= 0) return;
-  
-  size_t size = (size_t) selection_data->length;
+    if (!wxTheClipboard) return;
   
-  // make sure we got the data in the correct form 
-  if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
-  
-  clipboard->m_receivedSize = size;
-  
-  clipboard->m_receivedData = new char[size+1];
+    wxDataObject *data_object = clipboard->m_receivedData;
+    
+    if (!data_object) return;
+    
+    if (selection_data->length <= 0) return;
   
-  memcpy( clipboard->m_receivedData, selection_data->data, size);  
+    // make sure we got the data in the correct format
+    
+    if (data_object->m_formatAtom != selection_data->target) return;
+    
+    // make sure we got the data in the correct form (selection type).
+    // if so, copy data to target object
+    
+    switch (data_object->GetFormat())
+    {
+        case wxDF_TEXT:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
+           
+           wxTextDataObject *text_object = (wxTextDataObject *) data_object;
+           
+           wxString text = (const char*) selection_data->data;
+           
+           text_object->SetText( text );
+           
+           break;
+       }
+       
+       case wxDF_BITMAP:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_BITMAP) return;
+           
+           return;
+           
+           break;
+       }
+       
+       case wxDF_PRIVATE:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
+           
+           wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object;
+           
+           private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length );
+           
+           break;
+       }
+       
+       default:
+       {
+           return;
+       }
+    }
+    
+    wxTheClipboard->m_formatSupported = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -111,14 +154,14 @@ selection_received( GtkWidget *WXUNUSED(widget),
 static gint
 selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event) )
 {
-  if (!wxTheClipboard) return TRUE;
+    if (!wxTheClipboard) return TRUE;
   
-  /* the clipboard is no longer in our hands. we can delete the
-   * clipboard data. I hope I got that one right... */
+    // the clipboard is no longer in our hands. we have to delete the
+    // clipboard data.
     
-  wxTheClipboard->SetData( (wxDataObject*) NULL );
+    wxTheClipboard->m_dataObjects.Clear();
   
-  return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -128,33 +171,70 @@ selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event)
 static void
 selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
 {
-  if (!wxTheClipboard) return;
-  
-  wxDataObject *data_object = wxTheClipboard->m_data;
+    if (!wxTheClipboard) return;
   
-  if (!data_object) return;
-  
-  if (data_object->GetDataSize() == 0) return;
-
-  
-  
-  gint len = data_object->GetDataSize();
-  guchar *bin_data = (guchar*) malloc( len );
-  data_object->GetDataHere( (void*)bin_data );
-  
-  if (selection_data->target == GDK_TARGET_STRING)
-  {
-    gtk_selection_data_set( 
-      selection_data, GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar), bin_data, len );
-  }
-/*
-  else if (selection_data->target == g_textAtom)
-  {
-    gtk_selection_data_set( 
-      selection_data, g_textAtom, 8*sizeof(gchar), bin_data, len );
-  }
-*/
-  free( bin_data );
+    wxNode *node = wxTheClipboard->m_dataObjects.First();
+    
+    while (node)
+    {
+        wxDataObject *data_object = (wxDataObject *)node->Data();
+    
+       if (data_object->m_formatAtom != selection_data->target)
+       {
+           node = node->Next();
+           break;
+       }
+       
+       switch (data_object->GetFormat())
+       {
+           case wxDF_TEXT:
+           {
+               wxTextDataObject *text_object = (wxTextDataObject*) data_object;
+           
+               wxString text = text_object->GetText();
+           
+               char *s = WXSTRINGCAST text;
+               int len = (int) text.Length();
+               
+                gtk_selection_data_set( 
+                    selection_data, 
+                   GDK_SELECTION_TYPE_STRING, 
+                   8*sizeof(gchar),
+                   (unsigned char*) s, 
+                   len ); 
+                   
+               break;
+           }
+           
+           case wxDF_BITMAP:
+           {
+               // wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object;
+           
+               // how do we do that ?
+               
+               break;
+           }
+           
+           case wxDF_PRIVATE:
+            {
+               wxPrivateDataObject *private_object = (wxPrivateDataObject*) data_object;
+           
+               if (private_object->GetDataSize() == 0) return;
+           
+                gtk_selection_data_set( 
+                    selection_data, 
+                   GDK_SELECTION_TYPE_STRING, 
+                   8*sizeof(gchar), 
+                   (unsigned char*) private_object->GetData(), 
+                   (int) private_object->GetDataSize() );
+           }
+           
+           default:
+             break;
+        }
+       
+       node = node->Next();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -165,185 +245,222 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
 
 wxClipboard::wxClipboard()
 {
-  m_data = (wxDataObject*) NULL;
+    m_open = FALSE;
+
+    m_dataObjects.DeleteContents( TRUE );
   
-  m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
-  gtk_widget_realize( m_clipboardWidget );
+    m_receivedData = (wxDataObject*) NULL;
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_clear_event",
-                     GTK_SIGNAL_FUNC( selection_clear ), 
-                     (gpointer) NULL );
+    m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
+    gtk_widget_realize( m_clipboardWidget );
+
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_clear_event",
+                       GTK_SIGNAL_FUNC( selection_clear ), 
+                       (gpointer) NULL );
                      
-  if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
-  if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
-  if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
-  
-  m_receivedData = (char*)NULL;
-  m_receivedSize = 0;
-  m_formatSupported = FALSE;
-  m_targetRequested = 0;
+    if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
+    if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
+    if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
+  
+    m_formatSupported = FALSE;
+    m_targetRequested = 0;
 }
 
 wxClipboard::~wxClipboard()
 {
-  Clear();  
+    Clear();  
   
-  if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
+    if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
 }
 
 void wxClipboard::Clear()
 {
-  /* As we have data we also own the clipboard. Once we no longer own
-     it, clear_selection is called which will set m_data to zero */
+    if (m_dataObjects.GetCount())
+    { 
+        /*  As we have data we also own the clipboard. Once we no longer own
+            it, clear_selection is called which will set m_data to zero */
      
-  if (m_data)
-  { 
-    if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
-    {
-        gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
-    }
+        if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
+        {
+            gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
+        }
     
-    delete m_data;
-    m_data = (wxDataObject*) NULL;
-  }
+        m_dataObjects.Clear();
+    }
   
-  m_receivedSize = 0;
+    m_targetRequested = 0;
   
-  if (m_receivedData)
-  {
-    delete[] m_receivedData;
-    m_receivedData = (char*) NULL;
-  }
+    m_formatSupported = FALSE;
+}
+
+bool wxClipboard::Open()
+{
+    wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
   
-  m_targetRequested = 0;
+    m_open = TRUE;
   
-  m_formatSupported = FALSE;
+    return TRUE;
 }
 
-void wxClipboard::SetData( wxDataObject *data )
+bool wxClipboard::SetData( wxDataObject *data )
 {
-  Clear();
+    wxCHECK_MSG( data, FALSE, "data is invalid" );
   
-/*
-   GTK 1.0.X cannot remove a target from a widget so if a widget
-   at first offers text and then a bitmap (and no longer text) to 
-   the clipboard, we seem too have to delete it.
-*/
+    m_dataObjects.Append( data );
+  
+    wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+  
+    if (data->GetFormat() == wxDF_PRIVATE)
+    {
+        wxPrivateDataObject* pd = (wxPrivateDataObject*) data;
+       
+        wxCHECK_MSG( !pd->GetId().IsEmpty(), FALSE, "private clipboard format requires ID string" );
+       
+        data->m_formatAtom = GetTargetAtom( data->GetFormat(), pd->GetId() );
+    }
+    else
+    {
+        data->m_formatAtom = GetTargetAtom( data->GetFormat() );
+    }
+      
+    // Add handlers if someone requests data
+  
+    gtk_selection_add_handler( m_clipboardWidget, 
+                               g_clipboardAtom,
+                              data->m_formatAtom,
+                              selection_handler,
+                              NULL );
+                              
+    // Tell the world we offer clipboard data
+  
+    if (!gtk_selection_owner_set( m_clipboardWidget, 
+                                  g_clipboardAtom,
+                                 GDK_CURRENT_TIME ))
+    {
+        return FALSE;
+    }
+                            
+    return TRUE;
+}
 
-  if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
-  
-  m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
-  gtk_widget_realize( m_clipboardWidget );
-
-  if (m_data) delete m_data;
-  m_data = data;
-  if (!m_data) return;
-  if (!gtk_selection_owner_set( m_clipboardWidget, 
-                                g_clipboardAtom,
-                               GDK_CURRENT_TIME))
-  {
-    delete m_data;
-    m_data = (wxDataObject*) NULL;
-    return;
-  }
-  
-  switch (m_data->GetPreferredFormat())
-  {
-    case wxDF_TEXT:
-      gtk_selection_add_handler( m_clipboardWidget, 
-                                 g_clipboardAtom, 
-                               // g_textAtom,
-                                GDK_TARGET_STRING,
-                                selection_handler,
-                                NULL );
-      break;
-    default:
-      break;
-  }
+void wxClipboard::Close()
+{
+    wxCHECK_RET( m_open, "clipboard not open" );
+    
+    m_open = FALSE;
 }
 
-bool wxClipboard::IsSupportedFormat( wxDataFormat format )
+bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString &id )
 {
-  m_targetRequested = 0;
-  
-  if (format == wxDF_TEXT)
-  {
-//     m_targetRequested = g_textAtom;
-     m_targetRequested = GDK_TARGET_STRING;
-  }
+    m_targetRequested = GetTargetAtom( format, id );
   
-  if (m_targetRequested == 0) return FALSE;
+    if (m_targetRequested == 0) return FALSE;
+    
+    // add handler for target (= format) query
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_received",
-                     GTK_SIGNAL_FUNC( targets_selection_received ), 
-                     (gpointer) this );
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_received",
+                       GTK_SIGNAL_FUNC( targets_selection_received ), 
+                       (gpointer) this );
   
-  m_formatSupported = FALSE;
+    m_formatSupported = FALSE;
   
-  gtk_selection_convert( m_clipboardWidget,
-                        g_clipboardAtom, 
-                        g_targetsAtom,
-                        GDK_CURRENT_TIME );
+    // perform query. this will set m_formatSupported to 
+    // TRUE if m_targetRequested is supported
+    
+    gtk_selection_convert( m_clipboardWidget,
+                          g_clipboardAtom, 
+                          g_targetsAtom,
+                          GDK_CURRENT_TIME );
 
-  gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
-                                GTK_SIGNAL_FUNC( targets_selection_received ),
-                                (gpointer) this );
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
+                                  GTK_SIGNAL_FUNC( targets_selection_received ),
+                                  (gpointer) this );
   
-  if (!m_formatSupported) return FALSE;
+    if (!m_formatSupported) return FALSE;
   
-  return TRUE;
+    return TRUE;
 }
 
-bool wxClipboard::ObtainData( wxDataFormat format )
+bool wxClipboard::GetData( wxDataObject *data )
 {
-  m_receivedSize = 0;
-  
-  if (m_receivedData)
-  {
-    delete[] m_receivedData;
-    m_receivedData = (char*) NULL;
-  }
+    wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+    
+    m_receivedData = data;
+    
+    wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" );
+    
+    if (m_receivedData->GetFormat() == wxDF_PRIVATE)
+    {
+        wxPrivateDataObject* pd = (wxPrivateDataObject*) m_receivedData;
+       
+        wxCHECK_MSG( !pd->GetId().IsEmpty(), FALSE, "private clipboard format requires ID string" );
+       
+        m_targetRequested = GetTargetAtom( m_receivedData->GetFormat(), pd->GetId() );
+    }
+    else
+    {
+        m_targetRequested = GetTargetAtom( m_receivedData->GetFormat() );
+    }
+    
+    data->m_formatAtom = m_targetRequested;
   
-  m_targetRequested = 0;
+    wxCHECK_MSG( m_targetRequested, FALSE, "unsupported clipboard format" );
   
-  if (format == wxDF_TEXT)
-  {
-//     m_targetRequested = g_textAtom;
-     m_targetRequested = GDK_TARGET_STRING;
-  }
+    m_formatSupported = FALSE;
   
-  if (m_targetRequested == 0) return FALSE;
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_received",
+                       GTK_SIGNAL_FUNC( selection_received ), 
+                       (gpointer) this );
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_received",
-                     GTK_SIGNAL_FUNC( selection_received ), 
-                     (gpointer) this );
-
-  gtk_selection_convert( m_clipboardWidget,
-                        g_clipboardAtom, 
-                        m_targetRequested,
-                        GDK_CURRENT_TIME );
+    gtk_selection_convert( m_clipboardWidget,
+                          g_clipboardAtom, 
+                          m_targetRequested,
+                          GDK_CURRENT_TIME );
   
-  gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
-                                GTK_SIGNAL_FUNC( selection_received ),
-                                (gpointer) this );
-    
-  if (m_receivedSize == 0) return FALSE;
-  
-  return TRUE;
-}
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
+                                  GTK_SIGNAL_FUNC( selection_received ),
+                                  (gpointer) this );
 
-size_t wxClipboard::GetDataSize() const
-{
-  return m_receivedSize;
+    wxCHECK_MSG( m_formatSupported, FALSE, "error retrieving data from clipboard" );
+  
+    return TRUE;
 }
 
-void wxClipboard::GetDataHere( void *data ) const
+GdkAtom wxClipboard::GetTargetAtom( wxDataFormat format, const wxString &id )
 {
-  memcpy(data, m_receivedData, m_receivedSize );
+    // What is X representation of that format?
+  
+    switch (format)
+    {
+        case wxDF_TEXT:
+        {
+            return GDK_TARGET_STRING;
+                               // g_textAtom
+        }
+      
+        case wxDF_BITMAP:
+        {
+            return GDK_TARGET_BITMAP;
+            break;
+        }
+      
+        case wxDF_PRIVATE:
+        {
+            // we create our own X representation
+    
+            return gdk_atom_intern( WXSTRINGCAST( id ), FALSE );
+        }
+       
+       default:
+       {
+           return (GdkAtom) 0;
+       }
+    }
+       
+    return (GdkAtom) 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -354,13 +471,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
 
 bool wxClipboardModule::OnInit()
 {
-  wxTheClipboard = new wxClipboard();
+    wxTheClipboard = new wxClipboard();
   
-  return TRUE;
+    return TRUE;
 }
 
 void wxClipboardModule::OnExit()
 {
-  if (wxTheClipboard) delete wxTheClipboard;
-  wxTheClipboard = (wxClipboard*) NULL;
+    if (wxTheClipboard) delete wxTheClipboard;
+    wxTheClipboard = (wxClipboard*) NULL;
 }
diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp
new file mode 100644 (file)
index 0000000..e8c256e
--- /dev/null
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.cpp
+// Purpose:     wxDataObject class
+// Author:      Robert Roebling
+// Id:          $Id$
+// Copyright:   (c) 1998 Robert Roebling
+// Licence:    wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "dataobj.h"
+#endif
+
+#include "wx/dataobj.h"
+
+//-------------------------------------------------------------------------
+// wxDataObject
+//-------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
+
+// ----------------------------------------------------------------------------
+// wxTextDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxFileDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
+
+void wxPrivateDataObject::SetData( const char *data, size_t size )
+{
+    m_size = size;
+    
+    if (m_data) delete[] m_data;
+    
+    m_data = new char[size];
+
+    memcpy( m_data, data, size );  
+}
+
index e36ee810cbef2333a09ef0634815ae6f7e7c79e8..180e6ba727a1499df92bcf1b5191f996abe81d14 100644 (file)
@@ -632,15 +632,43 @@ shape_motion (GtkWidget      *widget,
 
 void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
 {
-  wxDataObject *data = source->m_data;
-  
-  size_t size = data->GetDataSize();
-  char *ptr = new char[size];
-  data->GetDataHere( ptr );
-  
-  gtk_widget_dnd_data_set( widget, event, ptr, size );
-  
-  delete ptr;
+    wxDataObject *data = source->m_data;
+
+    switch (data->GetFormat())
+    {
+        case wxDF_TEXT:
+       {
+           wxTextDataObject *text_object = (wxTextDataObject*) data;
+           
+           wxString text = text_object->GetText();
+           
+            gtk_widget_dnd_data_set( widget, 
+                                    event, 
+                                    (unsigned char*) text.c_str, 
+                                    (int) text.Length() );
+       
+           break;
+       }
+       
+        case wxDF_FILENAME:
+       {
+           wxFileDataObject *file_object = (wxFileDataObject*) data;
+           
+           wxString text = file_object->GetFiles();
+           
+            gtk_widget_dnd_data_set( widget, 
+                                    event, 
+                                    (unsigned char*) text.c_str, 
+                                    (int) text.Length() );
+       
+           break;
+       }
+       
+       default:
+       {
+           return;
+       }
+   }
   
   source->m_retValue = wxDragCopy;
 }
@@ -695,7 +723,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
   wxASSERT_MSG( m_data, "wxDragSource: no data" );
   
   if (!m_data) return (wxDragResult) wxDragNone;
-  if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
   
   static GtkWidget *drag_icon = NULL;
   static GtkWidget *drop_icon = NULL;
@@ -801,7 +828,7 @@ void wxDropSource::RegisterWindow(void)
 
   wxString formats;
     
-  wxDataFormat df = m_data->GetPreferredFormat();
+  wxDataFormat df = m_data->GetFormat();
   
     switch (df) 
     {
index d7812a880f0a6bbbf69ea24ffa0e13c24a81e8c8..253a7157a75b8ab9c27b7e37e4299ef22b95fe47 100644 (file)
@@ -57,26 +57,26 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
                             GtkSelectionData *selection_data, 
                            wxClipboard *clipboard )
 {
-  if (!wxTheClipboard) return;
+    if (!wxTheClipboard) return;
   
-  if (selection_data->length <= 0) return;
+    if (selection_data->length <= 0) return;
   
-  // make sure we got the data in the correct form 
-  if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
+    // make sure we got the data in the correct form 
+    if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
   
-  // the atoms we received, holding a list of targets (= formats) 
-  GdkAtom *atoms = (GdkAtom *)selection_data->data;
+    // the atoms we received, holding a list of targets (= formats) 
+    GdkAtom *atoms = (GdkAtom *)selection_data->data;
 
-  for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
-  {
-     if (atoms[i] == clipboard->m_targetRequested)
-     {
-       clipboard->m_formatSupported = TRUE;
-       return;
-     }
-  }
+    for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
+    {
+        if (atoms[i] == clipboard->m_targetRequested)
+        {
+            clipboard->m_formatSupported = TRUE;
+            return;
+        }
+    }
 
-  return;
+    return;
 }
 
 //-----------------------------------------------------------------------------
@@ -88,20 +88,63 @@ selection_received( GtkWidget *WXUNUSED(widget),
                     GtkSelectionData *selection_data, 
                    wxClipboard *clipboard )
 {
-  if (!wxTheClipboard) return;
-  
-  if (selection_data->length <= 0) return;
-  
-  size_t size = (size_t) selection_data->length;
+    if (!wxTheClipboard) return;
   
-  // make sure we got the data in the correct form 
-  if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
-  
-  clipboard->m_receivedSize = size;
-  
-  clipboard->m_receivedData = new char[size+1];
+    wxDataObject *data_object = clipboard->m_receivedData;
+    
+    if (!data_object) return;
+    
+    if (selection_data->length <= 0) return;
   
-  memcpy( clipboard->m_receivedData, selection_data->data, size);  
+    // make sure we got the data in the correct format
+    
+    if (data_object->m_formatAtom != selection_data->target) return;
+    
+    // make sure we got the data in the correct form (selection type).
+    // if so, copy data to target object
+    
+    switch (data_object->GetFormat())
+    {
+        case wxDF_TEXT:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
+           
+           wxTextDataObject *text_object = (wxTextDataObject *) data_object;
+           
+           wxString text = (const char*) selection_data->data;
+           
+           text_object->SetText( text );
+           
+           break;
+       }
+       
+       case wxDF_BITMAP:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_BITMAP) return;
+           
+           return;
+           
+           break;
+       }
+       
+       case wxDF_PRIVATE:
+       {
+            if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
+           
+           wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object;
+           
+           private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length );
+           
+           break;
+       }
+       
+       default:
+       {
+           return;
+       }
+    }
+    
+    wxTheClipboard->m_formatSupported = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -111,14 +154,14 @@ selection_received( GtkWidget *WXUNUSED(widget),
 static gint
 selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event) )
 {
-  if (!wxTheClipboard) return TRUE;
+    if (!wxTheClipboard) return TRUE;
   
-  /* the clipboard is no longer in our hands. we can delete the
-   * clipboard data. I hope I got that one right... */
+    // the clipboard is no longer in our hands. we have to delete the
+    // clipboard data.
     
-  wxTheClipboard->SetData( (wxDataObject*) NULL );
+    wxTheClipboard->m_dataObjects.Clear();
   
-  return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -128,33 +171,70 @@ selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event)
 static void
 selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
 {
-  if (!wxTheClipboard) return;
-  
-  wxDataObject *data_object = wxTheClipboard->m_data;
+    if (!wxTheClipboard) return;
   
-  if (!data_object) return;
-  
-  if (data_object->GetDataSize() == 0) return;
-
-  
-  
-  gint len = data_object->GetDataSize();
-  guchar *bin_data = (guchar*) malloc( len );
-  data_object->GetDataHere( (void*)bin_data );
-  
-  if (selection_data->target == GDK_TARGET_STRING)
-  {
-    gtk_selection_data_set( 
-      selection_data, GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar), bin_data, len );
-  }
-/*
-  else if (selection_data->target == g_textAtom)
-  {
-    gtk_selection_data_set( 
-      selection_data, g_textAtom, 8*sizeof(gchar), bin_data, len );
-  }
-*/
-  free( bin_data );
+    wxNode *node = wxTheClipboard->m_dataObjects.First();
+    
+    while (node)
+    {
+        wxDataObject *data_object = (wxDataObject *)node->Data();
+    
+       if (data_object->m_formatAtom != selection_data->target)
+       {
+           node = node->Next();
+           break;
+       }
+       
+       switch (data_object->GetFormat())
+       {
+           case wxDF_TEXT:
+           {
+               wxTextDataObject *text_object = (wxTextDataObject*) data_object;
+           
+               wxString text = text_object->GetText();
+           
+               char *s = WXSTRINGCAST text;
+               int len = (int) text.Length();
+               
+                gtk_selection_data_set( 
+                    selection_data, 
+                   GDK_SELECTION_TYPE_STRING, 
+                   8*sizeof(gchar),
+                   (unsigned char*) s, 
+                   len ); 
+                   
+               break;
+           }
+           
+           case wxDF_BITMAP:
+           {
+               // wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object;
+           
+               // how do we do that ?
+               
+               break;
+           }
+           
+           case wxDF_PRIVATE:
+            {
+               wxPrivateDataObject *private_object = (wxPrivateDataObject*) data_object;
+           
+               if (private_object->GetDataSize() == 0) return;
+           
+                gtk_selection_data_set( 
+                    selection_data, 
+                   GDK_SELECTION_TYPE_STRING, 
+                   8*sizeof(gchar), 
+                   (unsigned char*) private_object->GetData(), 
+                   (int) private_object->GetDataSize() );
+           }
+           
+           default:
+             break;
+        }
+       
+       node = node->Next();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -165,185 +245,222 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboard,wxObject)
 
 wxClipboard::wxClipboard()
 {
-  m_data = (wxDataObject*) NULL;
+    m_open = FALSE;
+
+    m_dataObjects.DeleteContents( TRUE );
   
-  m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
-  gtk_widget_realize( m_clipboardWidget );
+    m_receivedData = (wxDataObject*) NULL;
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_clear_event",
-                     GTK_SIGNAL_FUNC( selection_clear ), 
-                     (gpointer) NULL );
+    m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
+    gtk_widget_realize( m_clipboardWidget );
+
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_clear_event",
+                       GTK_SIGNAL_FUNC( selection_clear ), 
+                       (gpointer) NULL );
                      
-  if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
-  if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
-  if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
-  
-  m_receivedData = (char*)NULL;
-  m_receivedSize = 0;
-  m_formatSupported = FALSE;
-  m_targetRequested = 0;
+    if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE );
+    if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
+    if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE);
+  
+    m_formatSupported = FALSE;
+    m_targetRequested = 0;
 }
 
 wxClipboard::~wxClipboard()
 {
-  Clear();  
+    Clear();  
   
-  if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
+    if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
 }
 
 void wxClipboard::Clear()
 {
-  /* As we have data we also own the clipboard. Once we no longer own
-     it, clear_selection is called which will set m_data to zero */
+    if (m_dataObjects.GetCount())
+    { 
+        /*  As we have data we also own the clipboard. Once we no longer own
+            it, clear_selection is called which will set m_data to zero */
      
-  if (m_data)
-  { 
-    if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
-    {
-        gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
-    }
+        if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
+        {
+            gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
+        }
     
-    delete m_data;
-    m_data = (wxDataObject*) NULL;
-  }
+        m_dataObjects.Clear();
+    }
   
-  m_receivedSize = 0;
+    m_targetRequested = 0;
   
-  if (m_receivedData)
-  {
-    delete[] m_receivedData;
-    m_receivedData = (char*) NULL;
-  }
+    m_formatSupported = FALSE;
+}
+
+bool wxClipboard::Open()
+{
+    wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
   
-  m_targetRequested = 0;
+    m_open = TRUE;
   
-  m_formatSupported = FALSE;
+    return TRUE;
 }
 
-void wxClipboard::SetData( wxDataObject *data )
+bool wxClipboard::SetData( wxDataObject *data )
 {
-  Clear();
+    wxCHECK_MSG( data, FALSE, "data is invalid" );
   
-/*
-   GTK 1.0.X cannot remove a target from a widget so if a widget
-   at first offers text and then a bitmap (and no longer text) to 
-   the clipboard, we seem too have to delete it.
-*/
+    m_dataObjects.Append( data );
+  
+    wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+  
+    if (data->GetFormat() == wxDF_PRIVATE)
+    {
+        wxPrivateDataObject* pd = (wxPrivateDataObject*) data;
+       
+        wxCHECK_MSG( !pd->GetId().IsEmpty(), FALSE, "private clipboard format requires ID string" );
+       
+        data->m_formatAtom = GetTargetAtom( data->GetFormat(), pd->GetId() );
+    }
+    else
+    {
+        data->m_formatAtom = GetTargetAtom( data->GetFormat() );
+    }
+      
+    // Add handlers if someone requests data
+  
+    gtk_selection_add_handler( m_clipboardWidget, 
+                               g_clipboardAtom,
+                              data->m_formatAtom,
+                              selection_handler,
+                              NULL );
+                              
+    // Tell the world we offer clipboard data
+  
+    if (!gtk_selection_owner_set( m_clipboardWidget, 
+                                  g_clipboardAtom,
+                                 GDK_CURRENT_TIME ))
+    {
+        return FALSE;
+    }
+                            
+    return TRUE;
+}
 
-  if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
-  
-  m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
-  gtk_widget_realize( m_clipboardWidget );
-
-  if (m_data) delete m_data;
-  m_data = data;
-  if (!m_data) return;
-  if (!gtk_selection_owner_set( m_clipboardWidget, 
-                                g_clipboardAtom,
-                               GDK_CURRENT_TIME))
-  {
-    delete m_data;
-    m_data = (wxDataObject*) NULL;
-    return;
-  }
-  
-  switch (m_data->GetPreferredFormat())
-  {
-    case wxDF_TEXT:
-      gtk_selection_add_handler( m_clipboardWidget, 
-                                 g_clipboardAtom, 
-                               // g_textAtom,
-                                GDK_TARGET_STRING,
-                                selection_handler,
-                                NULL );
-      break;
-    default:
-      break;
-  }
+void wxClipboard::Close()
+{
+    wxCHECK_RET( m_open, "clipboard not open" );
+    
+    m_open = FALSE;
 }
 
-bool wxClipboard::IsSupportedFormat( wxDataFormat format )
+bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString &id )
 {
-  m_targetRequested = 0;
-  
-  if (format == wxDF_TEXT)
-  {
-//     m_targetRequested = g_textAtom;
-     m_targetRequested = GDK_TARGET_STRING;
-  }
+    m_targetRequested = GetTargetAtom( format, id );
   
-  if (m_targetRequested == 0) return FALSE;
+    if (m_targetRequested == 0) return FALSE;
+    
+    // add handler for target (= format) query
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_received",
-                     GTK_SIGNAL_FUNC( targets_selection_received ), 
-                     (gpointer) this );
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_received",
+                       GTK_SIGNAL_FUNC( targets_selection_received ), 
+                       (gpointer) this );
   
-  m_formatSupported = FALSE;
+    m_formatSupported = FALSE;
   
-  gtk_selection_convert( m_clipboardWidget,
-                        g_clipboardAtom, 
-                        g_targetsAtom,
-                        GDK_CURRENT_TIME );
+    // perform query. this will set m_formatSupported to 
+    // TRUE if m_targetRequested is supported
+    
+    gtk_selection_convert( m_clipboardWidget,
+                          g_clipboardAtom, 
+                          g_targetsAtom,
+                          GDK_CURRENT_TIME );
 
-  gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
-                                GTK_SIGNAL_FUNC( targets_selection_received ),
-                                (gpointer) this );
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
+                                  GTK_SIGNAL_FUNC( targets_selection_received ),
+                                  (gpointer) this );
   
-  if (!m_formatSupported) return FALSE;
+    if (!m_formatSupported) return FALSE;
   
-  return TRUE;
+    return TRUE;
 }
 
-bool wxClipboard::ObtainData( wxDataFormat format )
+bool wxClipboard::GetData( wxDataObject *data )
 {
-  m_receivedSize = 0;
-  
-  if (m_receivedData)
-  {
-    delete[] m_receivedData;
-    m_receivedData = (char*) NULL;
-  }
+    wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
+    
+    m_receivedData = data;
+    
+    wxCHECK_MSG( m_receivedData, FALSE, "invalid data object" );
+    
+    if (m_receivedData->GetFormat() == wxDF_PRIVATE)
+    {
+        wxPrivateDataObject* pd = (wxPrivateDataObject*) m_receivedData;
+       
+        wxCHECK_MSG( !pd->GetId().IsEmpty(), FALSE, "private clipboard format requires ID string" );
+       
+        m_targetRequested = GetTargetAtom( m_receivedData->GetFormat(), pd->GetId() );
+    }
+    else
+    {
+        m_targetRequested = GetTargetAtom( m_receivedData->GetFormat() );
+    }
+    
+    data->m_formatAtom = m_targetRequested;
   
-  m_targetRequested = 0;
+    wxCHECK_MSG( m_targetRequested, FALSE, "unsupported clipboard format" );
   
-  if (format == wxDF_TEXT)
-  {
-//     m_targetRequested = g_textAtom;
-     m_targetRequested = GDK_TARGET_STRING;
-  }
+    m_formatSupported = FALSE;
   
-  if (m_targetRequested == 0) return FALSE;
+    gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
+                        "selection_received",
+                       GTK_SIGNAL_FUNC( selection_received ), 
+                       (gpointer) this );
 
-  gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), 
-                      "selection_received",
-                     GTK_SIGNAL_FUNC( selection_received ), 
-                     (gpointer) this );
-
-  gtk_selection_convert( m_clipboardWidget,
-                        g_clipboardAtom, 
-                        m_targetRequested,
-                        GDK_CURRENT_TIME );
+    gtk_selection_convert( m_clipboardWidget,
+                          g_clipboardAtom, 
+                          m_targetRequested,
+                          GDK_CURRENT_TIME );
   
-  gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
-                                GTK_SIGNAL_FUNC( selection_received ),
-                                (gpointer) this );
-    
-  if (m_receivedSize == 0) return FALSE;
-  
-  return TRUE;
-}
+    gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget), 
+                                  GTK_SIGNAL_FUNC( selection_received ),
+                                  (gpointer) this );
 
-size_t wxClipboard::GetDataSize() const
-{
-  return m_receivedSize;
+    wxCHECK_MSG( m_formatSupported, FALSE, "error retrieving data from clipboard" );
+  
+    return TRUE;
 }
 
-void wxClipboard::GetDataHere( void *data ) const
+GdkAtom wxClipboard::GetTargetAtom( wxDataFormat format, const wxString &id )
 {
-  memcpy(data, m_receivedData, m_receivedSize );
+    // What is X representation of that format?
+  
+    switch (format)
+    {
+        case wxDF_TEXT:
+        {
+            return GDK_TARGET_STRING;
+                               // g_textAtom
+        }
+      
+        case wxDF_BITMAP:
+        {
+            return GDK_TARGET_BITMAP;
+            break;
+        }
+      
+        case wxDF_PRIVATE:
+        {
+            // we create our own X representation
+    
+            return gdk_atom_intern( WXSTRINGCAST( id ), FALSE );
+        }
+       
+       default:
+       {
+           return (GdkAtom) 0;
+       }
+    }
+       
+    return (GdkAtom) 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -354,13 +471,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
 
 bool wxClipboardModule::OnInit()
 {
-  wxTheClipboard = new wxClipboard();
+    wxTheClipboard = new wxClipboard();
   
-  return TRUE;
+    return TRUE;
 }
 
 void wxClipboardModule::OnExit()
 {
-  if (wxTheClipboard) delete wxTheClipboard;
-  wxTheClipboard = (wxClipboard*) NULL;
+    if (wxTheClipboard) delete wxTheClipboard;
+    wxTheClipboard = (wxClipboard*) NULL;
 }
diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp
new file mode 100644 (file)
index 0000000..e8c256e
--- /dev/null
@@ -0,0 +1,56 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.cpp
+// Purpose:     wxDataObject class
+// Author:      Robert Roebling
+// Id:          $Id$
+// Copyright:   (c) 1998 Robert Roebling
+// Licence:    wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "dataobj.h"
+#endif
+
+#include "wx/dataobj.h"
+
+//-------------------------------------------------------------------------
+// wxDataObject
+//-------------------------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject )
+
+// ----------------------------------------------------------------------------
+// wxTextDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxFileDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
+
+void wxPrivateDataObject::SetData( const char *data, size_t size )
+{
+    m_size = size;
+    
+    if (m_data) delete[] m_data;
+    
+    m_data = new char[size];
+
+    memcpy( m_data, data, size );  
+}
+
index e36ee810cbef2333a09ef0634815ae6f7e7c79e8..180e6ba727a1499df92bcf1b5191f996abe81d14 100644 (file)
@@ -632,15 +632,43 @@ shape_motion (GtkWidget      *widget,
 
 void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
 {
-  wxDataObject *data = source->m_data;
-  
-  size_t size = data->GetDataSize();
-  char *ptr = new char[size];
-  data->GetDataHere( ptr );
-  
-  gtk_widget_dnd_data_set( widget, event, ptr, size );
-  
-  delete ptr;
+    wxDataObject *data = source->m_data;
+
+    switch (data->GetFormat())
+    {
+        case wxDF_TEXT:
+       {
+           wxTextDataObject *text_object = (wxTextDataObject*) data;
+           
+           wxString text = text_object->GetText();
+           
+            gtk_widget_dnd_data_set( widget, 
+                                    event, 
+                                    (unsigned char*) text.c_str, 
+                                    (int) text.Length() );
+       
+           break;
+       }
+       
+        case wxDF_FILENAME:
+       {
+           wxFileDataObject *file_object = (wxFileDataObject*) data;
+           
+           wxString text = file_object->GetFiles();
+           
+            gtk_widget_dnd_data_set( widget, 
+                                    event, 
+                                    (unsigned char*) text.c_str, 
+                                    (int) text.Length() );
+       
+           break;
+       }
+       
+       default:
+       {
+           return;
+       }
+   }
   
   source->m_retValue = wxDragCopy;
 }
@@ -695,7 +723,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
   wxASSERT_MSG( m_data, "wxDragSource: no data" );
   
   if (!m_data) return (wxDragResult) wxDragNone;
-  if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
   
   static GtkWidget *drag_icon = NULL;
   static GtkWidget *drop_icon = NULL;
@@ -801,7 +828,7 @@ void wxDropSource::RegisterWindow(void)
 
   wxString formats;
     
-  wxDataFormat df = m_data->GetPreferredFormat();
+  wxDataFormat df = m_data->GetFormat();
   
     switch (df) 
     {