// classes
//-------------------------------------------------------------------------
+class wxDataFormat;
+class wxDataBroker;
class wxDataObject;
class wxTextDataObject;
class wxBitmapDataObject;
class wxFileDataObject;
//-------------------------------------------------------------------------
-// wxDataObject
+// wxDataFormat (internal)
//-------------------------------------------------------------------------
-class wxDataObject: public wxObject
+class wxDataFormat : public wxObject
{
- DECLARE_ABSTRACT_CLASS( wxDataObject )
+public:
+ wxDataFormat();
+ wxDataFormat( wxDataFormatId type );
+ wxDataFormat( const wxString &id );
+ wxDataFormat( const wxChar *id );
+ wxDataFormat( const wxDataFormat &format );
+ wxDataFormat( const GdkAtom atom );
+
+ 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; }
+
+ // 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; }
+
+private:
+ wxDataFormatId m_type;
+ wxString m_id;
+ bool m_hasAtom;
+ GdkAtom m_atom;
+
+ void PrepareFormats();
+
+private:
+ DECLARE_CLASS( wxDataFormat )
+};
+
+//-------------------------------------------------------------------------
+// wxDataBroker (internal)
+//-------------------------------------------------------------------------
+
+class wxDataBroker : public wxObject
+{
public:
+ /* constructor */
+ wxDataBroker();
- wxDataObject() {}
- ~wxDataObject() {}
+ /* add data object */
+ void Add( wxDataObject *dataObject, bool preferred = FALSE );
- virtual wxDataFormat GetFormat() const = 0;
-
- // implementation
+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 wxDataFormatId 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;
+
+ /* search through m_dataObjects and call child's WriteData(dest) */
+ virtual void WriteData( wxDataFormat& format, void *dest ) const;
+
+public:
+ /* implementation */
+ wxList m_dataObjects;
+ size_t m_preferred;
- GdkAtom m_formatAtom;
+private:
+ DECLARE_CLASS( wxDataBroker )
};
-// ----------------------------------------------------------------------------
-// wxTextDataObject is a specialization of wxDataObject for text data
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxDataObject to be placed in wxDataBroker
+//----------------------------------------------------------------------------
-class wxTextDataObject : public wxDataObject
+class wxDataObject : public wxObject
{
- DECLARE_DYNAMIC_CLASS( wxTextDataObject )
-
public:
+ /* constructor */
+ wxDataObject();
- wxTextDataObject() {}
- wxTextDataObject( const wxString& strText )
- : m_strText(strText) { }
-
- virtual wxDataFormat GetFormat() const
- { return wxDF_TEXT; }
-
- void SetText( const wxString& strText)
- { m_strText = strText; }
+ /* destructor */
+ ~wxDataObject();
+
+ /* write data to dest */
+ virtual void WriteData( void *dest ) const = 0;
+
+ /* get size of data */
+ virtual size_t GetSize() const = 0;
+
+public:
+ /* implementation */
+ wxDataFormat m_format;
- wxString GetText() const
- { return m_strText; }
+ wxDataFormat &GetFormat();
-private:
- wxString m_strText;
+ wxDataFormatId GetFormatType() const;
+ wxString GetFormatId() const;
+ GdkAtom GetFormatAtom() const;
+private:
+ DECLARE_DYNAMIC_CLASS( wxDataObject )
};
-// ----------------------------------------------------------------------------
-// wxFileDataObject is a specialization of wxDataObject for file names
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxTextDataObject is a specialization of wxDataObject for text data
+//----------------------------------------------------------------------------
-class wxFileDataObject : public wxDataObject
+class wxTextDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxFileDataObject )
+public:
+ /* 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 );
+
+ /* 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;
public:
+ /* implementation */
+ wxString m_data;
- wxFileDataObject(void) {}
-
- virtual wxDataFormat GetFormat() const
- { return wxDF_FILENAME; }
-
- void AddFile( const wxString &file )
- { m_files += file; m_files += (char)0; }
-
- wxString GetFiles() const
- { return m_files; }
-
private:
- wxString m_files;
-
+ DECLARE_DYNAMIC_CLASS( wxTextDataObject )
};
-// ----------------------------------------------------------------------------
-// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxFileDataObject is a specialization of wxDataObject for file names
+//----------------------------------------------------------------------------
-class wxBitmapDataObject : public wxDataObject
+class wxFileDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
-
public:
+ /* default constructor */
+ wxFileDataObject();
+
+ /* add file name to list */
+ void AddFile( const wxString &file );
+
+ /* 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;
- wxBitmapDataObject(void) {}
+ /* return length of list of filenames */
+ virtual size_t GetSize() const;
+
+public:
+ /* implementation */
+ wxString m_files;
- virtual wxDataFormat GetFormat() const
- { return wxDF_BITMAP; }
-
- void SetBitmap( const wxBitmap &bitmap )
- { m_bitmap = bitmap; }
-
- wxBitmap GetBitmap() const
- { return m_bitmap; }
-
private:
- wxBitmap m_bitmap;
+ DECLARE_DYNAMIC_CLASS( wxFileDataObject )
};
-// ----------------------------------------------------------------------------
-// wxPrivateDataObject is a specialization of wxDataObject for app specific data
-// ----------------------------------------------------------------------------
+//----------------------------------------------------------------------------
+// wxBitmapDataObject is a specialization of wxDataObject for bitmaps
+//----------------------------------------------------------------------------
-class wxPrivateDataObject : public wxDataObject
+class wxBitmapDataObject : public wxDataObject
{
- DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
-
public:
+ /* see wxTextDataObject for explanation */
+ wxBitmapDataObject();
+ wxBitmapDataObject( const wxBitmap& bitmap );
+ ~wxBitmapDataObject();
- 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() const
- { return m_id; }
+ void SetBitmap( const wxBitmap &bitmap );
+ wxBitmap GetBitmap() const;
- // will make internal copy
- void SetData( const char *data, size_t size );
-
- size_t GetDataSize() const
- { return m_size; }
-
- char* GetData() const
- { return m_data; }
+ 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;
-private:
- size_t m_size;
- char* m_data;
- wxString m_id;
-};
+ 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 );
+};
-#endif
+#endif
//__GTKDNDH__