1998-12-14 11:13:49 -05:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// 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
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
class wxDataFormat;
|
|
|
|
class wxDataBroker;
|
1998-12-14 11:13:49 -05:00
|
|
|
class wxDataObject;
|
|
|
|
class wxTextDataObject;
|
|
|
|
class wxBitmapDataObject;
|
|
|
|
class wxPrivateDataObject;
|
|
|
|
class wxFileDataObject;
|
|
|
|
|
1999-01-29 19:15:17 -05:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
// wxDataFormat (internal)
|
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
class wxDataFormat : public wxObject
|
|
|
|
{
|
1998-12-14 11:13:49 -05:00
|
|
|
public:
|
1999-05-26 18:39:42 -04:00
|
|
|
wxDataFormat();
|
|
|
|
wxDataFormat( wxDataFormatId type );
|
|
|
|
wxDataFormat( const wxString &id );
|
|
|
|
wxDataFormat( const wxChar *id );
|
1999-05-27 08:49:40 -04:00
|
|
|
wxDataFormat( const wxDataFormat &format );
|
1999-05-26 18:39:42 -04:00
|
|
|
wxDataFormat( const GdkAtom atom );
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-05-26 18:39:42 -04:00
|
|
|
void SetType( wxDataFormatId type );
|
|
|
|
wxDataFormatId GetType() const;
|
|
|
|
|
|
|
|
/* the string Id identifies the format of clipboard or DnD data. a word
|
|
|
|
* processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
|
|
|
|
* to the clipboard - the latter with the Id "application/wxword", an
|
|
|
|
* image manipulation program would put a wxBitmapDataObject and a
|
|
|
|
* wxPrivateDataObject to the clipboard - the latter with "image/png". */
|
|
|
|
|
|
|
|
wxString GetId() const;
|
|
|
|
void SetId( const wxChar *id );
|
|
|
|
|
|
|
|
GdkAtom GetAtom();
|
|
|
|
void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
|
|
|
|
|
1999-05-27 08:49:40 -04:00
|
|
|
// implicit conversion to wxDataFormatId
|
|
|
|
operator wxDataFormatId() const { return m_type; }
|
|
|
|
|
|
|
|
bool operator==(wxDataFormatId type) const { return m_type == type; }
|
|
|
|
bool operator!=(wxDataFormatId type) const { return m_type != type; }
|
|
|
|
|
1999-05-26 18:39:42 -04:00
|
|
|
private:
|
|
|
|
wxDataFormatId m_type;
|
|
|
|
wxString m_id;
|
|
|
|
bool m_hasAtom;
|
|
|
|
GdkAtom m_atom;
|
1999-08-22 10:10:50 -04:00
|
|
|
|
|
|
|
void PrepareFormats();
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_CLASS( wxDataFormat )
|
1999-01-19 11:33:16 -05:00
|
|
|
};
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
//-------------------------------------------------------------------------
|
1999-01-29 19:15:17 -05:00
|
|
|
// wxDataBroker (internal)
|
1999-01-19 11:33:16 -05:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxDataBroker : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* constructor */
|
|
|
|
wxDataBroker();
|
1999-01-19 11:33:16 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* add data object */
|
|
|
|
void Add( wxDataObject *dataObject, bool preferred = FALSE );
|
1999-05-26 18:39:42 -04:00
|
|
|
|
|
|
|
private:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* OLE implementation, the methods don't need to be overridden */
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* get number of supported formats */
|
|
|
|
virtual size_t GetFormatCount() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* return nth supported format */
|
|
|
|
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* return preferrd/best supported format */
|
|
|
|
virtual wxDataFormatId GetPreferredFormat() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* search through m_dataObjects, return TRUE if found */
|
|
|
|
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* search through m_dataObjects and call child's GetSize() */
|
|
|
|
virtual size_t GetSize( wxDataFormat& format ) const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* search through m_dataObjects and call child's WriteData(dest) */
|
|
|
|
virtual void WriteData( wxDataFormat& format, void *dest ) const;
|
1999-01-19 11:33:16 -05:00
|
|
|
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* implementation */
|
|
|
|
wxList m_dataObjects;
|
|
|
|
size_t m_preferred;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_CLASS( wxDataBroker )
|
1998-12-14 11:13:49 -05:00
|
|
|
};
|
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// wxDataObject to be placed in wxDataBroker
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class wxDataObject : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* constructor */
|
|
|
|
wxDataObject();
|
1999-01-19 11:33:16 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* destructor */
|
|
|
|
~wxDataObject();
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* write data to dest */
|
|
|
|
virtual void WriteData( void *dest ) const = 0;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* get size of data */
|
|
|
|
virtual size_t GetSize() const = 0;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
public:
|
|
|
|
/* implementation */
|
|
|
|
wxDataFormat m_format;
|
|
|
|
|
|
|
|
wxDataFormat &GetFormat();
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
wxDataFormatId GetFormatType() const;
|
|
|
|
wxString GetFormatId() const;
|
|
|
|
GdkAtom GetFormatAtom() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS( wxDataObject )
|
1999-01-19 11:33:16 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
// wxTextDataObject is a specialization of wxDataObject for text data
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
|
|
|
|
class wxTextDataObject : public wxDataObject
|
|
|
|
{
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* default constructor. call SetText() later or override
|
|
|
|
WriteData() and GetSize() for working on-demand */
|
|
|
|
wxTextDataObject();
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* constructor */
|
|
|
|
wxTextDataObject( const wxString& data );
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* set current text data */
|
|
|
|
void SetText( const wxString& data );
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* get current text data */
|
|
|
|
wxString GetText() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* by default calls WriteString() with string set by constructor or
|
|
|
|
by SetText(). can be overridden for working on-demand */
|
|
|
|
virtual void WriteData( void *dest ) const;
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* by default, returns length of string as set by constructor or
|
|
|
|
by SetText(). can be overridden for working on-demand */
|
|
|
|
virtual size_t GetSize() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* write string to dest */
|
|
|
|
void WriteString( const wxString &str, void *dest ) const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
public:
|
|
|
|
/* implementation */
|
|
|
|
wxString m_data;
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
|
1998-12-14 11:13:49 -05:00
|
|
|
};
|
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
// wxFileDataObject is a specialization of wxDataObject for file names
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
|
|
|
|
class wxFileDataObject : public wxDataObject
|
|
|
|
{
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* default constructor */
|
|
|
|
wxFileDataObject();
|
1998-12-14 11:13:49 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* add file name to list */
|
|
|
|
void AddFile( const wxString &file );
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* get all filename as one string. each file name is 0 terminated,
|
|
|
|
the list is double zero terminated */
|
|
|
|
wxString GetFiles() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* write list of filenames */
|
|
|
|
virtual void WriteData( void *dest ) const;
|
1999-01-19 11:33:16 -05:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
/* return length of list of filenames */
|
|
|
|
virtual size_t GetSize() const;
|
1999-05-26 18:39:42 -04:00
|
|
|
|
1999-08-22 10:10:50 -04:00
|
|
|
public:
|
|
|
|
/* implementation */
|
|
|
|
wxString m_files;
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS( wxFileDataObject )
|
1998-12-14 11:13:49 -05:00
|
|
|
};
|
|
|
|
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
|
1999-01-19 11:33:16 -05:00
|
|
|
//----------------------------------------------------------------------------
|
1998-12-14 11:13:49 -05:00
|
|
|
|
|
|
|
class wxBitmapDataObject : public wxDataObject
|
|
|
|
{
|
|
|
|
public:
|
1999-08-22 10:10:50 -04:00
|
|
|
/* see wxTextDataObject for explanation */
|
|
|
|
wxBitmapDataObject();
|
|
|
|
wxBitmapDataObject( const wxBitmap& bitmap );
|
|
|
|
~wxBitmapDataObject();
|
|
|
|
|
|
|
|
void SetBitmap( const wxBitmap &bitmap );
|
|
|
|
wxBitmap GetBitmap() const;
|
|
|
|
|
|
|
|
virtual void WriteData( void *dest ) const;
|
|
|
|
virtual size_t GetSize() const;
|
|
|
|
void *GetData() const { return (void*)m_pngData; }
|
|
|
|
|
|
|
|
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
|
|
|
|
|
|
|
|
void SetPngData( const char *pngData, size_t pngSize );
|
|
|
|
|
|
|
|
private:
|
|
|
|
wxBitmap m_bitmap;
|
|
|
|
size_t m_pngSize;
|
|
|
|
char *m_pngData;
|
|
|
|
|
|
|
|
void DoConvertToPng();
|
|
|
|
|
|
|
|
private:
|
|
|
|
DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
|
1998-12-14 11:13:49 -05:00
|
|
|
};
|
|
|
|
|
1999-05-26 18:39:42 -04:00
|
|
|
#endif
|
1998-12-14 11:13:49 -05:00
|
|
|
//__GTKDNDH__
|
|
|
|
|