class wxFileDataObject;
//-------------------------------------------------------------------------
-// wxDataType (internal)
+// wxDataFormat
//-------------------------------------------------------------------------
-enum wxDataType
+class wxDataFormat
{
- wxDF_INVALID = 0,
- wxDF_TEXT = 1, /* CF_TEXT */
- wxDF_BITMAP = 2, /* CF_BITMAP */
- wxDF_METAFILE = 3, /* CF_METAFILEPICT */
- wxDF_SYLK = 4,
- wxDF_DIF = 5,
- wxDF_TIFF = 6,
- wxDF_OEMTEXT = 7, /* CF_OEMTEXT */
- wxDF_DIB = 8, /* CF_DIB */
- wxDF_PALETTE = 9,
- wxDF_PENDATA = 10,
- wxDF_RIFF = 11,
- wxDF_WAVE = 12,
- wxDF_UNICODETEXT = 13,
- wxDF_ENHMETAFILE = 14,
- wxDF_FILENAME = 15, /* CF_HDROP */
- wxDF_LOCALE = 16,
- wxDF_PRIVATE = 20
-};
-
-//-------------------------------------------------------------------------
-// wxDataFormat (internal)
-//-------------------------------------------------------------------------
-
-class wxDataFormat : public wxObject
-{
- DECLARE_CLASS( wxDataFormat )
-
public:
-
- wxDataFormat();
- wxDataFormat( wxDataType type );
- wxDataFormat( const wxString &id );
- wxDataFormat( const char *id );
- wxDataFormat( wxDataFormat &format );
- wxDataFormat( const GdkAtom atom );
-
- void SetType( wxDataType type );
- wxDataType GetType() const;
-
- wxString GetId() const;
- void SetId( const char *id );
-
- GdkAtom GetAtom();
-
-private:
-
- wxDataType m_type;
- wxString m_id;
- bool m_hasAtom;
- GdkAtom m_atom;
-};
+ // the clipboard formats under GDK are GdkAtoms
+ typedef GdkAtom NativeFormat;
+
+ wxDataFormat();
+ wxDataFormat( wxDataFormatId type );
+ wxDataFormat( const wxString &id );
+ wxDataFormat( const wxChar *id );
+ wxDataFormat( NativeFormat format );
+
+ wxDataFormat& operator=(NativeFormat format)
+ { SetId(format); return *this; }
+ wxDataFormat& operator=(const wxDataFormat& format)
+ { SetId(format); return *this; }
+
+ // comparison (must have both versions)
+ bool operator==(wxDataFormatId type) const
+ { return m_type == (wxDataFormatId)type; }
+ bool operator!=(wxDataFormatId type) const
+ { return m_type != (wxDataFormatId)type; }
+ bool operator==(NativeFormat format) const
+ { return m_format == (NativeFormat)format; }
+ bool operator!=(NativeFormat format) const
+ { return m_format != (NativeFormat)format; }
+ bool operator==(const wxDataFormat& format) const
+ { return m_format == format.m_format; }
+ bool operator!=(const wxDataFormat& format) const
+ { return m_format != format.m_format; }
+
+ // explicit and implicit conversions to NativeFormat which is one of
+ // standard data types (implicit conversion is useful for preserving the
+ // compatibility with old code)
+ NativeFormat GetFormatId() const { return m_format; }
+ operator NativeFormat() const { return m_format; }
+
+ // this only works with standard ids
+ void SetId( wxDataFormatId type );
-//-------------------------------------------------------------------------
-// wxDataBroker (internal)
-//-------------------------------------------------------------------------
+ // this only works with standard ids
+ void SetId( NativeFormat format );
-class wxDataBroker : public wxObject
-{
- DECLARE_CLASS( wxDataBroker )
+ // string ids are used for custom types - this SetId() must be used for
+ // application-specific formats
+ wxString GetId() const;
+ void SetId( const wxChar *id );
-public:
+ // implementation
+ wxDataFormatId GetType() const;
- /* constructor */
- wxDataBroker();
-
- /* add data object */
- void Add( wxDataObject *dataObject, bool preferred = FALSE );
-
-private:
-
- /* OLE implementation, the methods don't need to be overridden */
-
- /* get number of supported formats */
- virtual size_t GetFormatCount() const;
-
- /* return nth supported format */
- virtual wxDataFormat &GetNthFormat( size_t nth ) const;
-
- /* return preferrd/best supported format */
- virtual wxDataFormat &GetPreferredFormat() const;
-
- /* search through m_dataObjects, return TRUE if found */
- virtual bool IsSupportedFormat( wxDataFormat &format ) const;
-
- /* search through m_dataObjects and call child's GetSize() */
- virtual size_t GetSize( wxDataFormat& format ) const;
+private:
+ wxDataFormatId m_type;
+ NativeFormat m_format;
- /* search through m_dataObjects and call child's WriteData(dest) */
- virtual void WriteData( wxDataFormat& format, void *dest ) const;
-
- /* implementation */
-
-public:
-
- wxList m_dataObjects;
- size_t m_preferred;
+ void PrepareFormats();
+ void SetType( wxDataFormatId type );
};
//----------------------------------------------------------------------------
-// wxDataObject to be placed in wxDataBroker
+// wxDataObject
//----------------------------------------------------------------------------
class wxDataObject : public wxObject
{
- DECLARE_DYNAMIC_CLASS( wxDataObject )
-
public:
+ wxDataObject();
+ ~wxDataObject();
+
+ virtual wxDataFormat GetPreferredFormat() const = 0;
+
+ // get the number of formats we support: it is understood that if we
+ // can accept data in some format, then we can render data in this
+ // format as well, but the contrary is not necessarily true. For the
+ // default value of the argument, all formats we support should be
+ // returned, but if outputOnlyToo == FALSE, then we should only return
+ // the formats which our SetData() understands
+ virtual size_t GetFormatCount(bool outputOnlyToo = TRUE) const
+ { return 1; }
+
+ // return all formats in the provided array (of size GetFormatCount())
+ virtual void GetAllFormats(wxDataFormat *formats,
+ bool outputOnlyToo = TRUE) const
+ { formats[0] = GetPreferredFormat(); }
+
+ // get the (total) size of data for the given format
+ virtual size_t GetDataSize(const wxDataFormat& format) const = 0;
+
+ // copy raw data (in the specified format) to provided pointer
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const = 0;
+
+ // get data from the buffer (in the given format)
+ virtual bool SetData(const wxDataFormat& format, const void *buf) = 0;
- /* constructor */
- wxDataObject();
-
- /* destructor */
- ~wxDataObject();
-
- /* write data to dest */
- virtual void WriteData( void *dest ) const = 0;
-
- /* get size of data */
- virtual size_t GetSize() const = 0;
-
- /* implementation */
-
- wxDataFormat &GetFormat();
-
- wxDataType GetFormatType() const;
- wxString GetFormatId() const;
- GdkAtom GetFormatAtom() const;
-
- wxDataFormat m_format;
+ // a simpler name which makes more sense for data objects supporting
+ // only one format
+ wxDataFormat GetFormat() const { return GetPreferredFormat(); }
+
+ // old interface
+ // decide if we support this format (can be either standard or custom
+ // format) -- now uses GetAllFormats()
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const;
+
+private:
+ DECLARE_DYNAMIC_CLASS( wxDataObject )
};
//----------------------------------------------------------------------------
class wxTextDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxTextDataObject )
-
public:
+ // ctors
+ wxTextDataObject();
+ wxTextDataObject(const wxString& strText);
+ void Init(const wxString& strText) { m_strText = strText; }
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_TEXT; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_TEXT; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
+
+ // additional helpers
+ void SetText(const wxString& strText) { m_strText = strText; }
+ wxString GetText() const { return m_strText; }
- /* default constructor. call SetText() later or override
- WriteData() and GetSize() for working on-demand */
- wxTextDataObject();
-
- /* constructor */
- wxTextDataObject( const wxString& data );
-
- /* set current text data */
- void SetText( const wxString& data );
+private:
+ wxString m_strText;
- /* get current text data */
- wxString GetText() const;
-
- /* 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;
-
- /* 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;
-
- /* write string to dest */
- void WriteString( const wxString &str, void *dest ) const;
-
- /* implementation */
-
- wxString m_data;
+private:
+ DECLARE_DYNAMIC_CLASS( wxTextDataObject )
};
//----------------------------------------------------------------------------
class wxFileDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxFileDataObject )
-
public:
-
- /* default constructor */
- wxFileDataObject();
+ wxFileDataObject();
- /* add file name to list */
- void AddFile( const wxString &file );
+ void AddFile( const wxString &file );
+ void SetFiles( const wxString &files )
+ { m_files = files; }
+ wxString GetFiles() const;
- /* get all filename as one string. each file name is 0 terminated,
- the list is double zero terminated */
- wxString GetFiles() const;
-
- /* write list of filenames */
- virtual void WriteData( void *dest ) const;
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_FILENAME; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_FILENAME; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
- /* return length of list of filenames */
- virtual size_t GetSize() const;
+public:
+ wxString m_files;
- /* implementation */
-
- wxString m_files;
+private:
+ DECLARE_DYNAMIC_CLASS( wxFileDataObject )
};
//----------------------------------------------------------------------------
class wxBitmapDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
-
-public:
-
- /* see wxTextDataObject for explanation */
-
- wxBitmapDataObject();
- wxBitmapDataObject( const wxBitmap& bitmap );
-
- void SetBitmap( const wxBitmap &bitmap );
- wxBitmap GetBitmap() const;
-
- virtual void WriteData( void *dest ) const;
- virtual size_t GetSize() const;
-
- void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
-
- // implementation
-
- wxBitmap m_bitmap;
-
-};
-
-//----------------------------------------------------------------------------
-// wxPrivateDataObject is a specialization of wxDataObject for app specific data
-//----------------------------------------------------------------------------
-
-class wxPrivateDataObject : public wxDataObject
-{
- DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
-
public:
+ // ctors
+ wxBitmapDataObject();
+ wxBitmapDataObject(const wxBitmap& bitmap);
- /* see wxTextDataObject for explanation of functions */
-
- wxPrivateDataObject();
- ~wxPrivateDataObject();
-
- /* 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". */
+ // destr
+ ~wxBitmapDataObject();
- void SetId( const wxString& id );
+ // set/get our bitmap
+ void SetBitmap(const wxBitmap& bitmap);
+ const wxBitmap GetBitmap() const { return m_bitmap; }
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_BITMAP; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_BITMAP; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
- /* get id */
- wxString GetId() const;
+ // sets PNG data
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
- /* set data. will make internal copy. */
- void SetData( const char *data, size_t size );
+ // sets PNG data
+ virtual void SetPngData(const void *buf, size_t size);
- /* returns pointer to data */
- char* GetData() const;
-
- virtual void WriteData( void *dest ) const;
- virtual size_t GetSize() const;
-
- void WriteData( const char *data, void *dest ) const;
+ void *GetData()
+ { return m_pngData; }
- // implementation
-
- size_t m_size;
- char* m_data;
- wxString m_id;
+private:
+ wxBitmap m_bitmap;
+ size_t m_pngSize;
+ void *m_pngData;
+
+ void DoConvertToPng();
+
+private:
+ DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
};
-
-#endif
+#endif
//__GTKDNDH__