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:
parent
450cab2dff
commit
8b53e5a226
2
configure
vendored
2
configure
vendored
@ -4570,7 +4570,7 @@ DEFAULT_wxUSE_POSTSCRIPT=1
|
|||||||
DEFAULT_wxUSE_IPC=1
|
DEFAULT_wxUSE_IPC=1
|
||||||
DEFAULT_wxUSE_RESOURCES=1
|
DEFAULT_wxUSE_RESOURCES=1
|
||||||
DEFAULT_wxUSE_CONSTRAINTS=1
|
DEFAULT_wxUSE_CONSTRAINTS=1
|
||||||
DEFAULT_wxUSE_CLIPBOARD=0
|
DEFAULT_wxUSE_CLIPBOARD=1
|
||||||
DEFAULT_wxUSE_DND=1
|
DEFAULT_wxUSE_DND=1
|
||||||
|
|
||||||
DEFAULT_wxUSE_MDI_ARCHITECTURE=1
|
DEFAULT_wxUSE_MDI_ARCHITECTURE=1
|
||||||
|
@ -717,7 +717,7 @@ DEFAULT_wxUSE_POSTSCRIPT=1
|
|||||||
DEFAULT_wxUSE_IPC=1
|
DEFAULT_wxUSE_IPC=1
|
||||||
DEFAULT_wxUSE_RESOURCES=1
|
DEFAULT_wxUSE_RESOURCES=1
|
||||||
DEFAULT_wxUSE_CONSTRAINTS=1
|
DEFAULT_wxUSE_CONSTRAINTS=1
|
||||||
DEFAULT_wxUSE_CLIPBOARD=0
|
DEFAULT_wxUSE_CLIPBOARD=1
|
||||||
DEFAULT_wxUSE_DND=1
|
DEFAULT_wxUSE_DND=1
|
||||||
|
|
||||||
DEFAULT_wxUSE_MDI_ARCHITECTURE=1
|
DEFAULT_wxUSE_MDI_ARCHITECTURE=1
|
||||||
|
19
include/wx/dataobj.h
Normal file
19
include/wx/dataobj.h
Normal 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_
|
@ -721,7 +721,8 @@ enum wxDataFormat
|
|||||||
wxDF_METAFILE = 3, /* CF_METAFILEPICT */
|
wxDF_METAFILE = 3, /* CF_METAFILEPICT */
|
||||||
wxDF_DIB = 8, /* CF_DIB */
|
wxDF_DIB = 8, /* CF_DIB */
|
||||||
wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
|
wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
|
||||||
wxDF_FILENAME = 15 /* CF_HDROP */
|
wxDF_FILENAME = 15, /* CF_HDROP */
|
||||||
|
wxDF_PRIVATE = 20
|
||||||
};
|
};
|
||||||
|
|
||||||
// Virtual keycodes
|
// Virtual keycodes
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
#include "wx/list.h"
|
#include "wx/list.h"
|
||||||
|
#include "wx/dataobj.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/dnd.h" // for wxDataObject
|
|
||||||
#include "wx/module.h"
|
#include "wx/module.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -48,21 +48,32 @@ public:
|
|||||||
wxClipboard();
|
wxClipboard();
|
||||||
~wxClipboard();
|
~wxClipboard();
|
||||||
|
|
||||||
virtual void SetData( wxDataObject *data );
|
// open the clipboard before SetData() and GetData()
|
||||||
|
virtual bool Open();
|
||||||
|
|
||||||
virtual bool IsSupportedFormat( wxDataFormat format );
|
// close the clipboard after SetData() and GetData()
|
||||||
virtual bool ObtainData( wxDataFormat format );
|
virtual void Close();
|
||||||
|
|
||||||
// call these after ObtainData()
|
// can be called several times
|
||||||
virtual size_t GetDataSize() const;
|
virtual bool SetData( wxDataObject *data );
|
||||||
virtual void GetDataHere( void *data ) const;
|
|
||||||
|
// 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
|
// clears wxTheClipboard and the system's clipboard if possible
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
|
|
||||||
|
GdkAtom GetTargetAtom( wxDataFormat format, const wxString &id = "" );
|
||||||
|
|
||||||
|
bool m_open;
|
||||||
|
|
||||||
wxDataObject *m_data;
|
wxList m_dataObjects;
|
||||||
char *m_sentString,
|
char *m_sentString,
|
||||||
*m_receivedString;
|
*m_receivedString;
|
||||||
void *m_receivedTargets;
|
void *m_receivedTargets;
|
||||||
@ -71,8 +82,7 @@ public:
|
|||||||
bool m_formatSupported;
|
bool m_formatSupported;
|
||||||
GdkAtom m_targetRequested;
|
GdkAtom m_targetRequested;
|
||||||
|
|
||||||
size_t m_receivedSize;
|
wxDataObject *m_receivedData;
|
||||||
char *m_receivedData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
178
include/wx/gtk/dataobj.h
Normal file
178
include/wx/gtk/dataobj.h
Normal 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__
|
||||||
|
|
@ -18,6 +18,7 @@
|
|||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
|
#include "wx/dataobj.h"
|
||||||
#include "wx/cursor.h"
|
#include "wx/cursor.h"
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -36,91 +37,12 @@
|
|||||||
|
|
||||||
class wxWindow;
|
class wxWindow;
|
||||||
|
|
||||||
class wxDataObject;
|
|
||||||
class wxTextDataObject;
|
|
||||||
class wxFileDataObject;
|
|
||||||
|
|
||||||
class wxDropTarget;
|
class wxDropTarget;
|
||||||
class wxTextDropTarget;
|
class wxTextDropTarget;
|
||||||
class wxFileDropTarget;
|
class wxFileDropTarget;
|
||||||
|
|
||||||
class wxDropSource;
|
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
|
// wxDropTarget
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
@ -18,8 +18,8 @@
|
|||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
#include "wx/list.h"
|
#include "wx/list.h"
|
||||||
|
#include "wx/dataobj.h"
|
||||||
#include "wx/control.h"
|
#include "wx/control.h"
|
||||||
#include "wx/dnd.h" // for wxDataObject
|
|
||||||
#include "wx/module.h"
|
#include "wx/module.h"
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -48,21 +48,32 @@ public:
|
|||||||
wxClipboard();
|
wxClipboard();
|
||||||
~wxClipboard();
|
~wxClipboard();
|
||||||
|
|
||||||
virtual void SetData( wxDataObject *data );
|
// open the clipboard before SetData() and GetData()
|
||||||
|
virtual bool Open();
|
||||||
|
|
||||||
virtual bool IsSupportedFormat( wxDataFormat format );
|
// close the clipboard after SetData() and GetData()
|
||||||
virtual bool ObtainData( wxDataFormat format );
|
virtual void Close();
|
||||||
|
|
||||||
// call these after ObtainData()
|
// can be called several times
|
||||||
virtual size_t GetDataSize() const;
|
virtual bool SetData( wxDataObject *data );
|
||||||
virtual void GetDataHere( void *data ) const;
|
|
||||||
|
// 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
|
// clears wxTheClipboard and the system's clipboard if possible
|
||||||
virtual void Clear();
|
virtual void Clear();
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
|
|
||||||
|
GdkAtom GetTargetAtom( wxDataFormat format, const wxString &id = "" );
|
||||||
|
|
||||||
|
bool m_open;
|
||||||
|
|
||||||
wxDataObject *m_data;
|
wxList m_dataObjects;
|
||||||
char *m_sentString,
|
char *m_sentString,
|
||||||
*m_receivedString;
|
*m_receivedString;
|
||||||
void *m_receivedTargets;
|
void *m_receivedTargets;
|
||||||
@ -71,8 +82,7 @@ public:
|
|||||||
bool m_formatSupported;
|
bool m_formatSupported;
|
||||||
GdkAtom m_targetRequested;
|
GdkAtom m_targetRequested;
|
||||||
|
|
||||||
size_t m_receivedSize;
|
wxDataObject *m_receivedData;
|
||||||
char *m_receivedData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
178
include/wx/gtk1/dataobj.h
Normal file
178
include/wx/gtk1/dataobj.h
Normal 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__
|
||||||
|
|
@ -18,6 +18,7 @@
|
|||||||
#include "wx/defs.h"
|
#include "wx/defs.h"
|
||||||
#include "wx/object.h"
|
#include "wx/object.h"
|
||||||
#include "wx/string.h"
|
#include "wx/string.h"
|
||||||
|
#include "wx/dataobj.h"
|
||||||
#include "wx/cursor.h"
|
#include "wx/cursor.h"
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@ -36,91 +37,12 @@
|
|||||||
|
|
||||||
class wxWindow;
|
class wxWindow;
|
||||||
|
|
||||||
class wxDataObject;
|
|
||||||
class wxTextDataObject;
|
|
||||||
class wxFileDataObject;
|
|
||||||
|
|
||||||
class wxDropTarget;
|
class wxDropTarget;
|
||||||
class wxTextDropTarget;
|
class wxTextDropTarget;
|
||||||
class wxFileDropTarget;
|
class wxFileDropTarget;
|
||||||
|
|
||||||
class wxDropSource;
|
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
|
// wxDropTarget
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
@ -408,21 +408,41 @@ void MyPanel::OnPasteFromClipboard( wxCommandEvent &WXUNUSED(event) )
|
|||||||
{
|
{
|
||||||
#ifdef __WXGTK__
|
#ifdef __WXGTK__
|
||||||
|
|
||||||
if (!wxTheClipboard->IsSupportedFormat( wxDF_TEXT )) return;
|
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();
|
||||||
|
|
||||||
if (!wxTheClipboard->ObtainData( wxDF_TEXT )) return;
|
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();
|
||||||
|
|
||||||
int size = wxTheClipboard->GetDataSize()+1;
|
*m_text << "Closed the clipboard." << "\n";
|
||||||
|
|
||||||
char *data = new char[size];
|
delete data;
|
||||||
|
|
||||||
data[size-1] = 0;
|
|
||||||
|
|
||||||
wxTheClipboard->GetDataHere( data );
|
|
||||||
|
|
||||||
*m_multitext << data << "\n";
|
|
||||||
|
|
||||||
delete[] data;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -437,8 +457,30 @@ void MyPanel::OnCopyToClipboard( wxCommandEvent &WXUNUSED(event) )
|
|||||||
|
|
||||||
wxTextDataObject *data = new wxTextDataObject( text );
|
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
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,8 +77,6 @@ END_EVENT_TABLE()
|
|||||||
MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size )
|
MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, const wxSize &size )
|
||||||
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
|
: wxScrolledWindow( parent, id, pos, size, wxSUNKEN_BORDER )
|
||||||
{
|
{
|
||||||
wxImage image;
|
|
||||||
|
|
||||||
wxBitmap bitmap( 100, 100 );
|
wxBitmap bitmap( 100, 100 );
|
||||||
|
|
||||||
wxMemoryDC dc;
|
wxMemoryDC dc;
|
||||||
@ -88,14 +86,14 @@ MyCanvas::MyCanvas( wxWindow *parent, const wxWindowID id, const wxPoint &pos, c
|
|||||||
dc.DrawRectangle( 0, 0, 100, 100 );
|
dc.DrawRectangle( 0, 0, 100, 100 );
|
||||||
dc.SelectObject( wxNullBitmap );
|
dc.SelectObject( wxNullBitmap );
|
||||||
|
|
||||||
image = bitmap.ConvertToImage();
|
wxImage image( bitmap );
|
||||||
image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG );
|
image.SaveFile( "../test.png", wxBITMAP_TYPE_PNG );
|
||||||
|
|
||||||
image.LoadFile( "../horse.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 );
|
image.LoadFile( "../test.png", wxBITMAP_TYPE_PNG );
|
||||||
my_square = new wxBitmap( image );
|
my_square = new wxBitmap( image.ConvertToBitmap() );
|
||||||
}
|
}
|
||||||
|
|
||||||
MyCanvas::~MyCanvas(void)
|
MyCanvas::~MyCanvas(void)
|
||||||
|
@ -771,13 +771,13 @@ bool wxVariantDataTime::Write(wxString& str) const
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataTime::Read(istream& str)
|
bool wxVariantDataTime::Read(istream& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataTime::Read(wxString& str)
|
bool wxVariantDataTime::Read(wxString& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -844,13 +844,13 @@ bool wxVariantDataDate::Write(wxString& str) const
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataDate::Read(istream& str)
|
bool wxVariantDataDate::Read(istream& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataDate::Read(wxString& str)
|
bool wxVariantDataDate::Read(wxString& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -921,13 +921,13 @@ bool wxVariantDataVoidPtr::Write(wxString& str) const
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataVoidPtr::Read(istream& str)
|
bool wxVariantDataVoidPtr::Read(istream& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxVariantDataVoidPtr::Read(wxString& str)
|
bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str))
|
||||||
{
|
{
|
||||||
// Not implemented
|
// Not implemented
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -1913,7 +1913,7 @@ void wxListMainWindow::CalculatePositions( void )
|
|||||||
int y = 1;
|
int y = 1;
|
||||||
int entireHeight = m_lines.Number() * lineSpacing + 2;
|
int entireHeight = m_lines.Number() * lineSpacing + 2;
|
||||||
int scroll_pos = GetScrollPos( wxVERTICAL );
|
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 );
|
GetClientSize( &clientWidth, &clientHeight );
|
||||||
|
|
||||||
wxNode* node = m_lines.First();
|
wxNode* node = m_lines.First();
|
||||||
@ -1959,11 +1959,11 @@ void wxListMainWindow::CalculatePositions( void )
|
|||||||
line->GetSize( lineWidth, lineHeight );
|
line->GetSize( lineWidth, lineHeight );
|
||||||
if (lineWidth > maxWidth) maxWidth = lineWidth;
|
if (lineWidth > maxWidth) maxWidth = lineWidth;
|
||||||
y += lineSpacing;
|
y += lineSpacing;
|
||||||
if (y+lineSpacing-7 >= clientHeight) // -7 for earlier "line breaking"
|
if (y+lineSpacing-6 >= clientHeight) // -6 for earlier "line breaking"
|
||||||
{
|
{
|
||||||
y = 5;
|
y = 5;
|
||||||
x += maxWidth+5;
|
x += maxWidth+6;
|
||||||
entireWidth += maxWidth+5;
|
entireWidth += maxWidth+6;
|
||||||
maxWidth = 0;
|
maxWidth = 0;
|
||||||
}
|
}
|
||||||
node = node->Next();
|
node = node->Next();
|
||||||
@ -1976,7 +1976,7 @@ void wxListMainWindow::CalculatePositions( void )
|
|||||||
if (!node) tries = 1; // everything fits, no second try required
|
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 );
|
int scroll_pos = GetScrollPos( wxHORIZONTAL );
|
||||||
SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
|
SetScrollbars( m_xScroll, m_yScroll, (entireWidth+15) / m_xScroll, 0, scroll_pos, 0, TRUE );
|
||||||
|
@ -80,6 +80,7 @@ LIB_CPP_SRC=\
|
|||||||
gtk/combobox.cpp \
|
gtk/combobox.cpp \
|
||||||
gtk/cursor.cpp \
|
gtk/cursor.cpp \
|
||||||
gtk/data.cpp \
|
gtk/data.cpp \
|
||||||
|
gtk/dataobj.cpp \
|
||||||
gtk/dc.cpp \
|
gtk/dc.cpp \
|
||||||
gtk/dcclient.cpp \
|
gtk/dcclient.cpp \
|
||||||
gtk/dcmemory.cpp \
|
gtk/dcmemory.cpp \
|
||||||
|
@ -57,26 +57,26 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
wxClipboard *clipboard )
|
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
|
// make sure we got the data in the correct form
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
|
if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
|
||||||
|
|
||||||
// the atoms we received, holding a list of targets (= formats)
|
// the atoms we received, holding a list of targets (= formats)
|
||||||
GdkAtom *atoms = (GdkAtom *)selection_data->data;
|
GdkAtom *atoms = (GdkAtom *)selection_data->data;
|
||||||
|
|
||||||
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
|
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
|
||||||
{
|
{
|
||||||
if (atoms[i] == clipboard->m_targetRequested)
|
if (atoms[i] == clipboard->m_targetRequested)
|
||||||
{
|
{
|
||||||
clipboard->m_formatSupported = TRUE;
|
clipboard->m_formatSupported = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -88,20 +88,63 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
wxClipboard *clipboard )
|
wxClipboard *clipboard )
|
||||||
{
|
{
|
||||||
if (!wxTheClipboard) return;
|
if (!wxTheClipboard) return;
|
||||||
|
|
||||||
if (selection_data->length <= 0) return;
|
wxDataObject *data_object = clipboard->m_receivedData;
|
||||||
|
|
||||||
|
if (!data_object) return;
|
||||||
|
|
||||||
|
if (selection_data->length <= 0) return;
|
||||||
|
|
||||||
size_t size = (size_t) selection_data->length;
|
// make sure we got the data in the correct format
|
||||||
|
|
||||||
// make sure we got the data in the correct form
|
if (data_object->m_formatAtom != selection_data->target) return;
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
|
|
||||||
|
// make sure we got the data in the correct form (selection type).
|
||||||
clipboard->m_receivedSize = size;
|
// if so, copy data to target object
|
||||||
|
|
||||||
clipboard->m_receivedData = new char[size+1];
|
switch (data_object->GetFormat())
|
||||||
|
{
|
||||||
memcpy( clipboard->m_receivedData, selection_data->data, size);
|
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
|
static gint
|
||||||
selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event) )
|
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
|
// the clipboard is no longer in our hands. we have to delete the
|
||||||
* clipboard data. I hope I got that one right... */
|
// 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
|
static void
|
||||||
selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
|
selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
|
||||||
{
|
{
|
||||||
if (!wxTheClipboard) return;
|
if (!wxTheClipboard) return;
|
||||||
|
|
||||||
wxDataObject *data_object = wxTheClipboard->m_data;
|
wxNode *node = wxTheClipboard->m_dataObjects.First();
|
||||||
|
|
||||||
if (!data_object) return;
|
while (node)
|
||||||
|
{
|
||||||
if (data_object->GetDataSize() == 0) return;
|
wxDataObject *data_object = (wxDataObject *)node->Data();
|
||||||
|
|
||||||
|
if (data_object->m_formatAtom != selection_data->target)
|
||||||
|
{
|
||||||
gint len = data_object->GetDataSize();
|
node = node->Next();
|
||||||
guchar *bin_data = (guchar*) malloc( len );
|
break;
|
||||||
data_object->GetDataHere( (void*)bin_data );
|
}
|
||||||
|
|
||||||
if (selection_data->target == GDK_TARGET_STRING)
|
switch (data_object->GetFormat())
|
||||||
{
|
{
|
||||||
gtk_selection_data_set(
|
case wxDF_TEXT:
|
||||||
selection_data, GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar), bin_data, len );
|
{
|
||||||
}
|
wxTextDataObject *text_object = (wxTextDataObject*) data_object;
|
||||||
/*
|
|
||||||
else if (selection_data->target == g_textAtom)
|
wxString text = text_object->GetText();
|
||||||
{
|
|
||||||
gtk_selection_data_set(
|
char *s = WXSTRINGCAST text;
|
||||||
selection_data, g_textAtom, 8*sizeof(gchar), bin_data, len );
|
int len = (int) text.Length();
|
||||||
}
|
|
||||||
*/
|
gtk_selection_data_set(
|
||||||
free( bin_data );
|
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()
|
wxClipboard::wxClipboard()
|
||||||
{
|
{
|
||||||
m_data = (wxDataObject*) NULL;
|
m_open = FALSE;
|
||||||
|
|
||||||
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
|
||||||
gtk_widget_realize( m_clipboardWidget );
|
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
|
m_dataObjects.DeleteContents( TRUE );
|
||||||
"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_receivedData = (wxDataObject*) NULL;
|
||||||
m_receivedSize = 0;
|
|
||||||
m_formatSupported = FALSE;
|
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
||||||
m_targetRequested = 0;
|
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_formatSupported = FALSE;
|
||||||
|
m_targetRequested = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxClipboard::~wxClipboard()
|
wxClipboard::~wxClipboard()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboard::Clear()
|
void wxClipboard::Clear()
|
||||||
{
|
{
|
||||||
/* As we have data we also own the clipboard. Once we no longer own
|
if (m_dataObjects.GetCount())
|
||||||
it, clear_selection is called which will set m_data to zero */
|
{
|
||||||
|
/* 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)
|
||||||
{
|
{
|
||||||
if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
|
gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dataObjects.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_targetRequested = 0;
|
||||||
|
|
||||||
|
m_formatSupported = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::Open()
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
|
||||||
|
|
||||||
|
m_open = TRUE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::SetData( wxDataObject *data )
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( data, FALSE, "data is invalid" );
|
||||||
|
|
||||||
|
m_dataObjects.Append( data );
|
||||||
|
|
||||||
|
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
|
||||||
|
|
||||||
|
if (data->GetFormat() == wxDF_PRIVATE)
|
||||||
{
|
{
|
||||||
gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxClipboard::Close()
|
||||||
|
{
|
||||||
|
wxCHECK_RET( m_open, "clipboard not open" );
|
||||||
|
|
||||||
|
m_open = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString &id )
|
||||||
|
{
|
||||||
|
m_targetRequested = GetTargetAtom( format, id );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
m_formatSupported = FALSE;
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
if (!m_formatSupported) return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::GetData( wxDataObject *data )
|
||||||
|
{
|
||||||
|
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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_data;
|
data->m_formatAtom = m_targetRequested;
|
||||||
m_data = (wxDataObject*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_receivedSize = 0;
|
wxCHECK_MSG( m_targetRequested, FALSE, "unsupported clipboard format" );
|
||||||
|
|
||||||
if (m_receivedData)
|
m_formatSupported = FALSE;
|
||||||
{
|
|
||||||
delete[] m_receivedData;
|
|
||||||
m_receivedData = (char*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_targetRequested = 0;
|
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 );
|
||||||
|
|
||||||
m_formatSupported = FALSE;
|
gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget),
|
||||||
|
GTK_SIGNAL_FUNC( selection_received ),
|
||||||
|
(gpointer) this );
|
||||||
|
|
||||||
|
wxCHECK_MSG( m_formatSupported, FALSE, "error retrieving data from clipboard" );
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboard::SetData( wxDataObject *data )
|
GdkAtom wxClipboard::GetTargetAtom( wxDataFormat format, const wxString &id )
|
||||||
{
|
{
|
||||||
Clear();
|
// What is X representation of that format?
|
||||||
|
|
||||||
/*
|
switch (format)
|
||||||
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
|
case wxDF_TEXT:
|
||||||
the clipboard, we seem too have to delete it.
|
{
|
||||||
*/
|
return GDK_TARGET_STRING;
|
||||||
|
// g_textAtom
|
||||||
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
}
|
||||||
|
|
||||||
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
case wxDF_BITMAP:
|
||||||
gtk_widget_realize( m_clipboardWidget );
|
{
|
||||||
|
return GDK_TARGET_BITMAP;
|
||||||
if (m_data) delete m_data;
|
break;
|
||||||
m_data = data;
|
}
|
||||||
if (!m_data) return;
|
|
||||||
|
case wxDF_PRIVATE:
|
||||||
if (!gtk_selection_owner_set( m_clipboardWidget,
|
{
|
||||||
g_clipboardAtom,
|
// we create our own X representation
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxClipboard::IsSupportedFormat( wxDataFormat format )
|
|
||||||
{
|
|
||||||
m_targetRequested = 0;
|
|
||||||
|
|
||||||
if (format == wxDF_TEXT)
|
|
||||||
{
|
|
||||||
// m_targetRequested = g_textAtom;
|
|
||||||
m_targetRequested = GDK_TARGET_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_targetRequested == 0) return FALSE;
|
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
|
|
||||||
"selection_received",
|
|
||||||
GTK_SIGNAL_FUNC( targets_selection_received ),
|
|
||||||
(gpointer) this );
|
|
||||||
|
|
||||||
m_formatSupported = FALSE;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
if (!m_formatSupported) return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxClipboard::ObtainData( wxDataFormat format )
|
|
||||||
{
|
|
||||||
m_receivedSize = 0;
|
|
||||||
|
|
||||||
if (m_receivedData)
|
|
||||||
{
|
|
||||||
delete[] m_receivedData;
|
|
||||||
m_receivedData = (char*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_targetRequested = 0;
|
|
||||||
|
|
||||||
if (format == wxDF_TEXT)
|
|
||||||
{
|
|
||||||
// m_targetRequested = g_textAtom;
|
|
||||||
m_targetRequested = GDK_TARGET_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_targetRequested == 0) return FALSE;
|
|
||||||
|
|
||||||
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_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget),
|
|
||||||
GTK_SIGNAL_FUNC( selection_received ),
|
|
||||||
(gpointer) this );
|
|
||||||
|
|
||||||
if (m_receivedSize == 0) return FALSE;
|
return gdk_atom_intern( WXSTRINGCAST( id ), FALSE );
|
||||||
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
default:
|
||||||
|
{
|
||||||
size_t wxClipboard::GetDataSize() const
|
return (GdkAtom) 0;
|
||||||
{
|
}
|
||||||
return m_receivedSize;
|
}
|
||||||
}
|
|
||||||
|
return (GdkAtom) 0;
|
||||||
void wxClipboard::GetDataHere( void *data ) const
|
|
||||||
{
|
|
||||||
memcpy(data, m_receivedData, m_receivedSize );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -354,13 +471,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
|
|||||||
|
|
||||||
bool wxClipboardModule::OnInit()
|
bool wxClipboardModule::OnInit()
|
||||||
{
|
{
|
||||||
wxTheClipboard = new wxClipboard();
|
wxTheClipboard = new wxClipboard();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboardModule::OnExit()
|
void wxClipboardModule::OnExit()
|
||||||
{
|
{
|
||||||
if (wxTheClipboard) delete wxTheClipboard;
|
if (wxTheClipboard) delete wxTheClipboard;
|
||||||
wxTheClipboard = (wxClipboard*) NULL;
|
wxTheClipboard = (wxClipboard*) NULL;
|
||||||
}
|
}
|
||||||
|
56
src/gtk/dataobj.cpp
Normal file
56
src/gtk/dataobj.cpp
Normal file
@ -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 );
|
||||||
|
}
|
||||||
|
|
@ -632,15 +632,43 @@ shape_motion (GtkWidget *widget,
|
|||||||
|
|
||||||
void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
|
void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
|
||||||
{
|
{
|
||||||
wxDataObject *data = source->m_data;
|
wxDataObject *data = source->m_data;
|
||||||
|
|
||||||
size_t size = data->GetDataSize();
|
switch (data->GetFormat())
|
||||||
char *ptr = new char[size];
|
{
|
||||||
data->GetDataHere( ptr );
|
case wxDF_TEXT:
|
||||||
|
{
|
||||||
gtk_widget_dnd_data_set( widget, event, ptr, size );
|
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||||
|
|
||||||
delete ptr;
|
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;
|
source->m_retValue = wxDragCopy;
|
||||||
}
|
}
|
||||||
@ -695,7 +723,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
||||||
|
|
||||||
if (!m_data) return (wxDragResult) wxDragNone;
|
if (!m_data) return (wxDragResult) wxDragNone;
|
||||||
if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
|
|
||||||
|
|
||||||
static GtkWidget *drag_icon = NULL;
|
static GtkWidget *drag_icon = NULL;
|
||||||
static GtkWidget *drop_icon = NULL;
|
static GtkWidget *drop_icon = NULL;
|
||||||
@ -801,7 +828,7 @@ void wxDropSource::RegisterWindow(void)
|
|||||||
|
|
||||||
wxString formats;
|
wxString formats;
|
||||||
|
|
||||||
wxDataFormat df = m_data->GetPreferredFormat();
|
wxDataFormat df = m_data->GetFormat();
|
||||||
|
|
||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
|
@ -57,26 +57,26 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
wxClipboard *clipboard )
|
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
|
// make sure we got the data in the correct form
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
|
if (selection_data->type != GDK_SELECTION_TYPE_ATOM) return;
|
||||||
|
|
||||||
// the atoms we received, holding a list of targets (= formats)
|
// the atoms we received, holding a list of targets (= formats)
|
||||||
GdkAtom *atoms = (GdkAtom *)selection_data->data;
|
GdkAtom *atoms = (GdkAtom *)selection_data->data;
|
||||||
|
|
||||||
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
|
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
|
||||||
{
|
{
|
||||||
if (atoms[i] == clipboard->m_targetRequested)
|
if (atoms[i] == clipboard->m_targetRequested)
|
||||||
{
|
{
|
||||||
clipboard->m_formatSupported = TRUE;
|
clipboard->m_formatSupported = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -88,20 +88,63 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
GtkSelectionData *selection_data,
|
GtkSelectionData *selection_data,
|
||||||
wxClipboard *clipboard )
|
wxClipboard *clipboard )
|
||||||
{
|
{
|
||||||
if (!wxTheClipboard) return;
|
if (!wxTheClipboard) return;
|
||||||
|
|
||||||
if (selection_data->length <= 0) return;
|
wxDataObject *data_object = clipboard->m_receivedData;
|
||||||
|
|
||||||
|
if (!data_object) return;
|
||||||
|
|
||||||
|
if (selection_data->length <= 0) return;
|
||||||
|
|
||||||
size_t size = (size_t) selection_data->length;
|
// make sure we got the data in the correct format
|
||||||
|
|
||||||
// make sure we got the data in the correct form
|
if (data_object->m_formatAtom != selection_data->target) return;
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_STRING) return;
|
|
||||||
|
// make sure we got the data in the correct form (selection type).
|
||||||
clipboard->m_receivedSize = size;
|
// if so, copy data to target object
|
||||||
|
|
||||||
clipboard->m_receivedData = new char[size+1];
|
switch (data_object->GetFormat())
|
||||||
|
{
|
||||||
memcpy( clipboard->m_receivedData, selection_data->data, size);
|
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
|
static gint
|
||||||
selection_clear( GtkWidget *WXUNUSED(widget), GdkEventSelection *WXUNUSED(event) )
|
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
|
// the clipboard is no longer in our hands. we have to delete the
|
||||||
* clipboard data. I hope I got that one right... */
|
// 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
|
static void
|
||||||
selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
|
selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data, gpointer WXUNUSED(data) )
|
||||||
{
|
{
|
||||||
if (!wxTheClipboard) return;
|
if (!wxTheClipboard) return;
|
||||||
|
|
||||||
wxDataObject *data_object = wxTheClipboard->m_data;
|
wxNode *node = wxTheClipboard->m_dataObjects.First();
|
||||||
|
|
||||||
if (!data_object) return;
|
while (node)
|
||||||
|
{
|
||||||
if (data_object->GetDataSize() == 0) return;
|
wxDataObject *data_object = (wxDataObject *)node->Data();
|
||||||
|
|
||||||
|
if (data_object->m_formatAtom != selection_data->target)
|
||||||
|
{
|
||||||
gint len = data_object->GetDataSize();
|
node = node->Next();
|
||||||
guchar *bin_data = (guchar*) malloc( len );
|
break;
|
||||||
data_object->GetDataHere( (void*)bin_data );
|
}
|
||||||
|
|
||||||
if (selection_data->target == GDK_TARGET_STRING)
|
switch (data_object->GetFormat())
|
||||||
{
|
{
|
||||||
gtk_selection_data_set(
|
case wxDF_TEXT:
|
||||||
selection_data, GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar), bin_data, len );
|
{
|
||||||
}
|
wxTextDataObject *text_object = (wxTextDataObject*) data_object;
|
||||||
/*
|
|
||||||
else if (selection_data->target == g_textAtom)
|
wxString text = text_object->GetText();
|
||||||
{
|
|
||||||
gtk_selection_data_set(
|
char *s = WXSTRINGCAST text;
|
||||||
selection_data, g_textAtom, 8*sizeof(gchar), bin_data, len );
|
int len = (int) text.Length();
|
||||||
}
|
|
||||||
*/
|
gtk_selection_data_set(
|
||||||
free( bin_data );
|
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()
|
wxClipboard::wxClipboard()
|
||||||
{
|
{
|
||||||
m_data = (wxDataObject*) NULL;
|
m_open = FALSE;
|
||||||
|
|
||||||
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
|
||||||
gtk_widget_realize( m_clipboardWidget );
|
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
|
m_dataObjects.DeleteContents( TRUE );
|
||||||
"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_receivedData = (wxDataObject*) NULL;
|
||||||
m_receivedSize = 0;
|
|
||||||
m_formatSupported = FALSE;
|
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
||||||
m_targetRequested = 0;
|
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_formatSupported = FALSE;
|
||||||
|
m_targetRequested = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxClipboard::~wxClipboard()
|
wxClipboard::~wxClipboard()
|
||||||
{
|
{
|
||||||
Clear();
|
Clear();
|
||||||
|
|
||||||
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboard::Clear()
|
void wxClipboard::Clear()
|
||||||
{
|
{
|
||||||
/* As we have data we also own the clipboard. Once we no longer own
|
if (m_dataObjects.GetCount())
|
||||||
it, clear_selection is called which will set m_data to zero */
|
{
|
||||||
|
/* 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)
|
||||||
{
|
{
|
||||||
if (gdk_selection_owner_get( g_clipboardAtom) == m_clipboardWidget->window)
|
gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
|
||||||
|
}
|
||||||
|
|
||||||
|
m_dataObjects.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
m_targetRequested = 0;
|
||||||
|
|
||||||
|
m_formatSupported = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::Open()
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( !m_open, FALSE, "clipboard already open" );
|
||||||
|
|
||||||
|
m_open = TRUE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::SetData( wxDataObject *data )
|
||||||
|
{
|
||||||
|
wxCHECK_MSG( data, FALSE, "data is invalid" );
|
||||||
|
|
||||||
|
m_dataObjects.Append( data );
|
||||||
|
|
||||||
|
wxCHECK_MSG( m_open, FALSE, "clipboard not open" );
|
||||||
|
|
||||||
|
if (data->GetFormat() == wxDF_PRIVATE)
|
||||||
{
|
{
|
||||||
gtk_selection_owner_set( (GtkWidget*) NULL, g_clipboardAtom, GDK_CURRENT_TIME );
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxClipboard::Close()
|
||||||
|
{
|
||||||
|
wxCHECK_RET( m_open, "clipboard not open" );
|
||||||
|
|
||||||
|
m_open = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::IsSupportedFormat( wxDataFormat format, const wxString &id )
|
||||||
|
{
|
||||||
|
m_targetRequested = GetTargetAtom( format, id );
|
||||||
|
|
||||||
|
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 );
|
||||||
|
|
||||||
|
m_formatSupported = FALSE;
|
||||||
|
|
||||||
|
// 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 );
|
||||||
|
|
||||||
|
if (!m_formatSupported) return FALSE;
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxClipboard::GetData( wxDataObject *data )
|
||||||
|
{
|
||||||
|
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() );
|
||||||
}
|
}
|
||||||
|
|
||||||
delete m_data;
|
data->m_formatAtom = m_targetRequested;
|
||||||
m_data = (wxDataObject*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_receivedSize = 0;
|
wxCHECK_MSG( m_targetRequested, FALSE, "unsupported clipboard format" );
|
||||||
|
|
||||||
if (m_receivedData)
|
m_formatSupported = FALSE;
|
||||||
{
|
|
||||||
delete[] m_receivedData;
|
|
||||||
m_receivedData = (char*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_targetRequested = 0;
|
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 );
|
||||||
|
|
||||||
m_formatSupported = FALSE;
|
gtk_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget),
|
||||||
|
GTK_SIGNAL_FUNC( selection_received ),
|
||||||
|
(gpointer) this );
|
||||||
|
|
||||||
|
wxCHECK_MSG( m_formatSupported, FALSE, "error retrieving data from clipboard" );
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboard::SetData( wxDataObject *data )
|
GdkAtom wxClipboard::GetTargetAtom( wxDataFormat format, const wxString &id )
|
||||||
{
|
{
|
||||||
Clear();
|
// What is X representation of that format?
|
||||||
|
|
||||||
/*
|
switch (format)
|
||||||
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
|
case wxDF_TEXT:
|
||||||
the clipboard, we seem too have to delete it.
|
{
|
||||||
*/
|
return GDK_TARGET_STRING;
|
||||||
|
// g_textAtom
|
||||||
if (m_clipboardWidget) gtk_widget_destroy( m_clipboardWidget );
|
}
|
||||||
|
|
||||||
m_clipboardWidget = gtk_window_new( GTK_WINDOW_POPUP );
|
case wxDF_BITMAP:
|
||||||
gtk_widget_realize( m_clipboardWidget );
|
{
|
||||||
|
return GDK_TARGET_BITMAP;
|
||||||
if (m_data) delete m_data;
|
break;
|
||||||
m_data = data;
|
}
|
||||||
if (!m_data) return;
|
|
||||||
|
case wxDF_PRIVATE:
|
||||||
if (!gtk_selection_owner_set( m_clipboardWidget,
|
{
|
||||||
g_clipboardAtom,
|
// we create our own X representation
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxClipboard::IsSupportedFormat( wxDataFormat format )
|
|
||||||
{
|
|
||||||
m_targetRequested = 0;
|
|
||||||
|
|
||||||
if (format == wxDF_TEXT)
|
|
||||||
{
|
|
||||||
// m_targetRequested = g_textAtom;
|
|
||||||
m_targetRequested = GDK_TARGET_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_targetRequested == 0) return FALSE;
|
|
||||||
|
|
||||||
gtk_signal_connect( GTK_OBJECT(m_clipboardWidget),
|
|
||||||
"selection_received",
|
|
||||||
GTK_SIGNAL_FUNC( targets_selection_received ),
|
|
||||||
(gpointer) this );
|
|
||||||
|
|
||||||
m_formatSupported = FALSE;
|
|
||||||
|
|
||||||
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 );
|
|
||||||
|
|
||||||
if (!m_formatSupported) return FALSE;
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool wxClipboard::ObtainData( wxDataFormat format )
|
|
||||||
{
|
|
||||||
m_receivedSize = 0;
|
|
||||||
|
|
||||||
if (m_receivedData)
|
|
||||||
{
|
|
||||||
delete[] m_receivedData;
|
|
||||||
m_receivedData = (char*) NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_targetRequested = 0;
|
|
||||||
|
|
||||||
if (format == wxDF_TEXT)
|
|
||||||
{
|
|
||||||
// m_targetRequested = g_textAtom;
|
|
||||||
m_targetRequested = GDK_TARGET_STRING;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_targetRequested == 0) return FALSE;
|
|
||||||
|
|
||||||
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_signal_disconnect_by_func( GTK_OBJECT(m_clipboardWidget),
|
|
||||||
GTK_SIGNAL_FUNC( selection_received ),
|
|
||||||
(gpointer) this );
|
|
||||||
|
|
||||||
if (m_receivedSize == 0) return FALSE;
|
return gdk_atom_intern( WXSTRINGCAST( id ), FALSE );
|
||||||
|
}
|
||||||
return TRUE;
|
|
||||||
}
|
default:
|
||||||
|
{
|
||||||
size_t wxClipboard::GetDataSize() const
|
return (GdkAtom) 0;
|
||||||
{
|
}
|
||||||
return m_receivedSize;
|
}
|
||||||
}
|
|
||||||
|
return (GdkAtom) 0;
|
||||||
void wxClipboard::GetDataHere( void *data ) const
|
|
||||||
{
|
|
||||||
memcpy(data, m_receivedData, m_receivedSize );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
@ -354,13 +471,13 @@ IMPLEMENT_DYNAMIC_CLASS(wxClipboardModule,wxModule)
|
|||||||
|
|
||||||
bool wxClipboardModule::OnInit()
|
bool wxClipboardModule::OnInit()
|
||||||
{
|
{
|
||||||
wxTheClipboard = new wxClipboard();
|
wxTheClipboard = new wxClipboard();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxClipboardModule::OnExit()
|
void wxClipboardModule::OnExit()
|
||||||
{
|
{
|
||||||
if (wxTheClipboard) delete wxTheClipboard;
|
if (wxTheClipboard) delete wxTheClipboard;
|
||||||
wxTheClipboard = (wxClipboard*) NULL;
|
wxTheClipboard = (wxClipboard*) NULL;
|
||||||
}
|
}
|
||||||
|
56
src/gtk1/dataobj.cpp
Normal file
56
src/gtk1/dataobj.cpp
Normal file
@ -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 );
|
||||||
|
}
|
||||||
|
|
@ -632,15 +632,43 @@ shape_motion (GtkWidget *widget,
|
|||||||
|
|
||||||
void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
|
void gtk_drag_callback( GtkWidget *widget, GdkEvent *event, wxDropSource *source )
|
||||||
{
|
{
|
||||||
wxDataObject *data = source->m_data;
|
wxDataObject *data = source->m_data;
|
||||||
|
|
||||||
size_t size = data->GetDataSize();
|
switch (data->GetFormat())
|
||||||
char *ptr = new char[size];
|
{
|
||||||
data->GetDataHere( ptr );
|
case wxDF_TEXT:
|
||||||
|
{
|
||||||
gtk_widget_dnd_data_set( widget, event, ptr, size );
|
wxTextDataObject *text_object = (wxTextDataObject*) data;
|
||||||
|
|
||||||
delete ptr;
|
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;
|
source->m_retValue = wxDragCopy;
|
||||||
}
|
}
|
||||||
@ -695,7 +723,6 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
|
|||||||
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
wxASSERT_MSG( m_data, "wxDragSource: no data" );
|
||||||
|
|
||||||
if (!m_data) return (wxDragResult) wxDragNone;
|
if (!m_data) return (wxDragResult) wxDragNone;
|
||||||
if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone;
|
|
||||||
|
|
||||||
static GtkWidget *drag_icon = NULL;
|
static GtkWidget *drag_icon = NULL;
|
||||||
static GtkWidget *drop_icon = NULL;
|
static GtkWidget *drop_icon = NULL;
|
||||||
@ -801,7 +828,7 @@ void wxDropSource::RegisterWindow(void)
|
|||||||
|
|
||||||
wxString formats;
|
wxString formats;
|
||||||
|
|
||||||
wxDataFormat df = m_data->GetPreferredFormat();
|
wxDataFormat df = m_data->GetFormat();
|
||||||
|
|
||||||
switch (df)
|
switch (df)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user