Added wxMotif data object classes
authorJulian Smart <julian@anthemion.co.uk>
Thu, 14 Jan 1999 15:18:41 +0000 (15:18 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Thu, 14 Jan 1999 15:18:41 +0000 (15:18 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1409 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/motif/dataobj.h [new file with mode: 0644]
src/motif/dataobj.cpp [new file with mode: 0644]

diff --git a/include/wx/motif/dataobj.h b/include/wx/motif/dataobj.h
new file mode 100644 (file)
index 0000000..8c8150a
--- /dev/null
@@ -0,0 +1,174 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.h
+// Purpose:     declaration of the wxDataObject class
+// Author:      Julian Smart
+// RCS-ID:      $Id$
+// Copyright:   (c) 1998 Julian Smart
+// Licence:     wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_DATAOBJ_H_
+#define _WX_DATAOBJ_H_
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "wx/defs.h"
+#include "wx/object.h"
+#include "wx/string.h"
+#include "wx/bitmap.h"
+
+//-------------------------------------------------------------------------
+// classes
+//-------------------------------------------------------------------------
+
+class WXDLLEXPORT wxDataObject;
+class WXDLLEXPORT wxTextDataObject;
+class WXDLLEXPORT wxBitmapDataObject;
+class WXDLLEXPORT wxPrivateDataObject;
+class WXDLLEXPORT wxFileDataObject;
+
+//-------------------------------------------------------------------------
+// wxDataObject
+//-------------------------------------------------------------------------
+
+class WXDLLEXPORT wxDataObject: public wxObject
+{
+  DECLARE_ABSTRACT_CLASS( wxDataObject )
+
+public:
+
+  wxDataObject() {}
+  ~wxDataObject() {}
+
+  virtual wxDataFormat GetFormat() const = 0;
+  
+  // implementation
+};
+
+// ----------------------------------------------------------------------------
+// wxTextDataObject is a specialization of wxDataObject for text data
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT 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() const
+    { return m_strText; }
+
+private:
+  wxString  m_strText;
+
+};
+
+// ----------------------------------------------------------------------------
+// wxFileDataObject is a specialization of wxDataObject for file names
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT 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() const
+    { return m_files; }
+    
+private:
+  wxString  m_files;
+  
+};
+
+// ----------------------------------------------------------------------------
+// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT 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() const
+    { return m_bitmap; }
+    
+private:
+  wxBitmap  m_bitmap;
+};
+
+// ----------------------------------------------------------------------------
+// wxPrivateDataObject is a specialization of wxDataObject for app specific data
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxPrivateDataObject : public wxDataObject
+{
+  DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
+
+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;
+};
+
+
+#endif  
+       //_WX_DATAOBJ_H_
+
diff --git a/src/motif/dataobj.cpp b/src/motif/dataobj.cpp
new file mode 100644 (file)
index 0000000..465bc56
--- /dev/null
@@ -0,0 +1,69 @@
+///////////////////////////////////////////////////////////////////////////////
+// Name:        dataobj.cpp
+// Purpose:     wxDataObject class
+// Author:      Julian Smart
+// Id:          $Id$
+// Copyright:   (c) 1998 Julian Smart
+// Licence:    wxWindows licence
+///////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "dataobj.h"
+#endif
+
+#include "wx/dataobj.h"
+#include "wx/app.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 )
+
+wxPrivateDataObject::wxPrivateDataObject() 
+{ 
+    m_size = 0; 
+    m_data = (char*) NULL; 
+    m_id = wxTheApp->GetAppName();
+}
+    
+wxPrivateDataObject::~wxPrivateDataObject()
+{ 
+    if (m_data) delete[] m_data; 
+}
+  
+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 );  
+}
+