New wxDataObject, DnD and Clipboard code

A few more minor fixes


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1194 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1998-12-14 16:13:49 +00:00
parent 450cab2dff
commit 8b53e5a226
21 changed files with 1347 additions and 666 deletions

19
include/wx/dataobj.h Normal file
View File

@@ -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_

View 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

View 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;
};
//-----------------------------------------------------------------------------

178
include/wx/gtk/dataobj.h Normal file
View File

@@ -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__

View 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"
//-------------------------------------------------------------------------
@@ -36,91 +37,12 @@
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
//-------------------------------------------------------------------------

View 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;
};
//-----------------------------------------------------------------------------

178
include/wx/gtk1/dataobj.h Normal file
View File

@@ -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__

View 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"
//-------------------------------------------------------------------------
@@ -36,91 +37,12 @@
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
//-------------------------------------------------------------------------