Added wxCountingStream for measuring the size of streamed data
Added wxBitmapObject for putting it on the clipboard git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@3439 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -37,8 +37,6 @@ class wxFileDataObject;
|
|||||||
|
|
||||||
class wxDataFormat : public wxObject
|
class wxDataFormat : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_CLASS( wxDataFormat )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxDataFormat();
|
wxDataFormat();
|
||||||
wxDataFormat( wxDataFormatId type );
|
wxDataFormat( wxDataFormatId type );
|
||||||
@@ -73,6 +71,11 @@ private:
|
|||||||
wxString m_id;
|
wxString m_id;
|
||||||
bool m_hasAtom;
|
bool m_hasAtom;
|
||||||
GdkAtom m_atom;
|
GdkAtom m_atom;
|
||||||
|
|
||||||
|
void PrepareFormats();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS( wxDataFormat )
|
||||||
};
|
};
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -81,44 +84,41 @@ private:
|
|||||||
|
|
||||||
class wxDataBroker : public wxObject
|
class wxDataBroker : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_CLASS( wxDataBroker )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* constructor */
|
||||||
|
wxDataBroker();
|
||||||
|
|
||||||
/* constructor */
|
/* add data object */
|
||||||
wxDataBroker();
|
void Add( wxDataObject *dataObject, bool preferred = FALSE );
|
||||||
|
|
||||||
/* add data object */
|
|
||||||
void Add( wxDataObject *dataObject, bool preferred = FALSE );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/* OLE implementation, the methods don't need to be overridden */
|
||||||
|
|
||||||
/* OLE implementation, the methods don't need to be overridden */
|
/* get number of supported formats */
|
||||||
|
virtual size_t GetFormatCount() const;
|
||||||
|
|
||||||
/* get number of supported formats */
|
/* return nth supported format */
|
||||||
virtual size_t GetFormatCount() const;
|
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
|
||||||
|
|
||||||
/* return nth supported format */
|
/* return preferrd/best supported format */
|
||||||
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
|
virtual wxDataFormatId GetPreferredFormat() const;
|
||||||
|
|
||||||
/* return preferrd/best supported format */
|
/* search through m_dataObjects, return TRUE if found */
|
||||||
virtual wxDataFormatId GetPreferredFormat() const;
|
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects, return TRUE if found */
|
/* search through m_dataObjects and call child's GetSize() */
|
||||||
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
|
virtual size_t GetSize( wxDataFormat& format ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects and call child's GetSize() */
|
/* search through m_dataObjects and call child's WriteData(dest) */
|
||||||
virtual size_t GetSize( wxDataFormat& format ) const;
|
virtual void WriteData( wxDataFormat& format, void *dest ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects and call child's WriteData(dest) */
|
|
||||||
virtual void WriteData( wxDataFormat& format, void *dest ) const;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
wxList m_dataObjects;
|
wxList m_dataObjects;
|
||||||
size_t m_preferred;
|
size_t m_preferred;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS( wxDataBroker )
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -127,31 +127,31 @@ public:
|
|||||||
|
|
||||||
class wxDataObject : public wxObject
|
class wxDataObject : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxDataObject )
|
public:
|
||||||
|
/* 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;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
|
wxDataFormat m_format;
|
||||||
|
|
||||||
|
wxDataFormat &GetFormat();
|
||||||
|
|
||||||
/* constructor */
|
wxDataFormatId GetFormatType() const;
|
||||||
wxDataObject();
|
wxString GetFormatId() const;
|
||||||
|
GdkAtom GetFormatAtom() const;
|
||||||
|
|
||||||
/* destructor */
|
private:
|
||||||
~wxDataObject();
|
DECLARE_DYNAMIC_CLASS( 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();
|
|
||||||
|
|
||||||
wxDataFormatId GetFormatType() const;
|
|
||||||
wxString GetFormatId() const;
|
|
||||||
GdkAtom GetFormatAtom() const;
|
|
||||||
|
|
||||||
wxDataFormat m_format;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -160,37 +160,37 @@ public:
|
|||||||
|
|
||||||
class wxTextDataObject : public wxDataObject
|
class wxTextDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
|
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:
|
public:
|
||||||
|
/* implementation */
|
||||||
|
wxString m_data;
|
||||||
|
|
||||||
/* default constructor. call SetText() later or override
|
private:
|
||||||
WriteData() and GetSize() for working on-demand */
|
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
|
||||||
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;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
wxString m_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -199,29 +199,29 @@ public:
|
|||||||
|
|
||||||
class wxFileDataObject : public wxDataObject
|
class wxFileDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxFileDataObject )
|
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;
|
||||||
|
|
||||||
|
/* return length of list of filenames */
|
||||||
|
virtual size_t GetSize() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
/* default constructor */
|
wxString m_files;
|
||||||
wxFileDataObject();
|
|
||||||
|
private:
|
||||||
/* add file name to list */
|
DECLARE_DYNAMIC_CLASS( wxFileDataObject )
|
||||||
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;
|
|
||||||
|
|
||||||
/* return length of list of filenames */
|
|
||||||
virtual size_t GetSize() const;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
wxString m_files;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -230,27 +230,32 @@ public:
|
|||||||
|
|
||||||
class wxBitmapDataObject : public wxDataObject
|
class wxBitmapDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* see wxTextDataObject for explanation */
|
||||||
|
wxBitmapDataObject();
|
||||||
|
wxBitmapDataObject( const wxBitmap& bitmap );
|
||||||
|
~wxBitmapDataObject();
|
||||||
|
|
||||||
/* see wxTextDataObject for explanation */
|
void SetBitmap( const wxBitmap &bitmap );
|
||||||
|
wxBitmap GetBitmap() const;
|
||||||
|
|
||||||
wxBitmapDataObject();
|
virtual void WriteData( void *dest ) const;
|
||||||
wxBitmapDataObject( const wxBitmap& bitmap );
|
virtual size_t GetSize() const;
|
||||||
|
void *GetData() const { return (void*)m_pngData; }
|
||||||
|
|
||||||
void SetBitmap( const wxBitmap &bitmap );
|
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
|
||||||
wxBitmap GetBitmap() const;
|
|
||||||
|
void SetPngData( const char *pngData, size_t pngSize );
|
||||||
virtual void WriteData( void *dest ) const;
|
|
||||||
virtual size_t GetSize() const;
|
|
||||||
|
|
||||||
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
|
|
||||||
|
|
||||||
// implementation
|
|
||||||
|
|
||||||
wxBitmap m_bitmap;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxBitmap m_bitmap;
|
||||||
|
size_t m_pngSize;
|
||||||
|
char *m_pngData;
|
||||||
|
|
||||||
|
void DoConvertToPng();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -37,8 +37,6 @@ class wxFileDataObject;
|
|||||||
|
|
||||||
class wxDataFormat : public wxObject
|
class wxDataFormat : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_CLASS( wxDataFormat )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
wxDataFormat();
|
wxDataFormat();
|
||||||
wxDataFormat( wxDataFormatId type );
|
wxDataFormat( wxDataFormatId type );
|
||||||
@@ -73,6 +71,11 @@ private:
|
|||||||
wxString m_id;
|
wxString m_id;
|
||||||
bool m_hasAtom;
|
bool m_hasAtom;
|
||||||
GdkAtom m_atom;
|
GdkAtom m_atom;
|
||||||
|
|
||||||
|
void PrepareFormats();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS( wxDataFormat )
|
||||||
};
|
};
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -81,44 +84,41 @@ private:
|
|||||||
|
|
||||||
class wxDataBroker : public wxObject
|
class wxDataBroker : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_CLASS( wxDataBroker )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* constructor */
|
||||||
|
wxDataBroker();
|
||||||
|
|
||||||
/* constructor */
|
/* add data object */
|
||||||
wxDataBroker();
|
void Add( wxDataObject *dataObject, bool preferred = FALSE );
|
||||||
|
|
||||||
/* add data object */
|
|
||||||
void Add( wxDataObject *dataObject, bool preferred = FALSE );
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
/* OLE implementation, the methods don't need to be overridden */
|
||||||
|
|
||||||
/* OLE implementation, the methods don't need to be overridden */
|
/* get number of supported formats */
|
||||||
|
virtual size_t GetFormatCount() const;
|
||||||
|
|
||||||
/* get number of supported formats */
|
/* return nth supported format */
|
||||||
virtual size_t GetFormatCount() const;
|
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
|
||||||
|
|
||||||
/* return nth supported format */
|
/* return preferrd/best supported format */
|
||||||
virtual wxDataFormat &GetNthFormat( size_t nth ) const;
|
virtual wxDataFormatId GetPreferredFormat() const;
|
||||||
|
|
||||||
/* return preferrd/best supported format */
|
/* search through m_dataObjects, return TRUE if found */
|
||||||
virtual wxDataFormatId GetPreferredFormat() const;
|
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects, return TRUE if found */
|
/* search through m_dataObjects and call child's GetSize() */
|
||||||
virtual bool IsSupportedFormat( wxDataFormat &format ) const;
|
virtual size_t GetSize( wxDataFormat& format ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects and call child's GetSize() */
|
/* search through m_dataObjects and call child's WriteData(dest) */
|
||||||
virtual size_t GetSize( wxDataFormat& format ) const;
|
virtual void WriteData( wxDataFormat& format, void *dest ) const;
|
||||||
|
|
||||||
/* search through m_dataObjects and call child's WriteData(dest) */
|
|
||||||
virtual void WriteData( wxDataFormat& format, void *dest ) const;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
wxList m_dataObjects;
|
wxList m_dataObjects;
|
||||||
size_t m_preferred;
|
size_t m_preferred;
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_CLASS( wxDataBroker )
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -127,31 +127,31 @@ public:
|
|||||||
|
|
||||||
class wxDataObject : public wxObject
|
class wxDataObject : public wxObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxDataObject )
|
public:
|
||||||
|
/* 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;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
|
wxDataFormat m_format;
|
||||||
|
|
||||||
|
wxDataFormat &GetFormat();
|
||||||
|
|
||||||
/* constructor */
|
wxDataFormatId GetFormatType() const;
|
||||||
wxDataObject();
|
wxString GetFormatId() const;
|
||||||
|
GdkAtom GetFormatAtom() const;
|
||||||
|
|
||||||
/* destructor */
|
private:
|
||||||
~wxDataObject();
|
DECLARE_DYNAMIC_CLASS( 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();
|
|
||||||
|
|
||||||
wxDataFormatId GetFormatType() const;
|
|
||||||
wxString GetFormatId() const;
|
|
||||||
GdkAtom GetFormatAtom() const;
|
|
||||||
|
|
||||||
wxDataFormat m_format;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -160,37 +160,37 @@ public:
|
|||||||
|
|
||||||
class wxTextDataObject : public wxDataObject
|
class wxTextDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
|
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:
|
public:
|
||||||
|
/* implementation */
|
||||||
|
wxString m_data;
|
||||||
|
|
||||||
/* default constructor. call SetText() later or override
|
private:
|
||||||
WriteData() and GetSize() for working on-demand */
|
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
|
||||||
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;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
wxString m_data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -199,29 +199,29 @@ public:
|
|||||||
|
|
||||||
class wxFileDataObject : public wxDataObject
|
class wxFileDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxFileDataObject )
|
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;
|
||||||
|
|
||||||
|
/* return length of list of filenames */
|
||||||
|
virtual size_t GetSize() const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* implementation */
|
||||||
/* default constructor */
|
wxString m_files;
|
||||||
wxFileDataObject();
|
|
||||||
|
private:
|
||||||
/* add file name to list */
|
DECLARE_DYNAMIC_CLASS( wxFileDataObject )
|
||||||
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;
|
|
||||||
|
|
||||||
/* return length of list of filenames */
|
|
||||||
virtual size_t GetSize() const;
|
|
||||||
|
|
||||||
/* implementation */
|
|
||||||
|
|
||||||
wxString m_files;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
@@ -230,27 +230,32 @@ public:
|
|||||||
|
|
||||||
class wxBitmapDataObject : public wxDataObject
|
class wxBitmapDataObject : public wxDataObject
|
||||||
{
|
{
|
||||||
DECLARE_DYNAMIC_CLASS( wxBitmapDataObject )
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
/* see wxTextDataObject for explanation */
|
||||||
|
wxBitmapDataObject();
|
||||||
|
wxBitmapDataObject( const wxBitmap& bitmap );
|
||||||
|
~wxBitmapDataObject();
|
||||||
|
|
||||||
/* see wxTextDataObject for explanation */
|
void SetBitmap( const wxBitmap &bitmap );
|
||||||
|
wxBitmap GetBitmap() const;
|
||||||
|
|
||||||
wxBitmapDataObject();
|
virtual void WriteData( void *dest ) const;
|
||||||
wxBitmapDataObject( const wxBitmap& bitmap );
|
virtual size_t GetSize() const;
|
||||||
|
void *GetData() const { return (void*)m_pngData; }
|
||||||
|
|
||||||
void SetBitmap( const wxBitmap &bitmap );
|
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
|
||||||
wxBitmap GetBitmap() const;
|
|
||||||
|
void SetPngData( const char *pngData, size_t pngSize );
|
||||||
virtual void WriteData( void *dest ) const;
|
|
||||||
virtual size_t GetSize() const;
|
|
||||||
|
|
||||||
void WriteBitmap( const wxBitmap &bitmap, void *dest ) const;
|
|
||||||
|
|
||||||
// implementation
|
|
||||||
|
|
||||||
wxBitmap m_bitmap;
|
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxBitmap m_bitmap;
|
||||||
|
size_t m_pngSize;
|
||||||
|
char *m_pngData;
|
||||||
|
|
||||||
|
void DoConvertToPng();
|
||||||
|
|
||||||
|
private:
|
||||||
|
DECLARE_DYNAMIC_CLASS( wxBitmapDataObject );
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -136,6 +136,28 @@ class WXDLLEXPORT wxOutputStream: public wxStreamBase {
|
|||||||
wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
|
wxOutputStream& operator<<( __wxOutputManip func) { return func(*this); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// A stream for measuring streamed output
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class wxCountingOutputStream: public wxOutputStream {
|
||||||
|
public:
|
||||||
|
wxCountingOutputStream();
|
||||||
|
|
||||||
|
size_t GetSize() const;
|
||||||
|
bool Ok() const { return TRUE; }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
size_t OnSysWrite(const void *buffer, size_t size);
|
||||||
|
off_t OnSysSeek(off_t pos, wxSeekMode mode);
|
||||||
|
off_t OnSysTell() const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
size_t m_currentPos;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// "Filter" streams
|
// "Filter" streams
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
@@ -13,6 +13,8 @@ top_srcdir = @top_srcdir@
|
|||||||
top_builddir = ../..
|
top_builddir = ../..
|
||||||
program_dir = samples/dnd
|
program_dir = samples/dnd
|
||||||
|
|
||||||
|
DATAFILES=julian.png
|
||||||
|
|
||||||
PROGRAM=dnd
|
PROGRAM=dnd
|
||||||
|
|
||||||
OBJECTS=$(PROGRAM).o
|
OBJECTS=$(PROGRAM).o
|
||||||
|
@@ -19,22 +19,23 @@
|
|||||||
#include "wx/wx.h"
|
#include "wx/wx.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __WXMOTIF__
|
||||||
|
#error Sorry, drag and drop is not yet implemented on wxMotif.
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "wx/intl.h"
|
#include "wx/intl.h"
|
||||||
#include "wx/log.h"
|
#include "wx/log.h"
|
||||||
|
|
||||||
#include "wx/dnd.h"
|
#include "wx/dnd.h"
|
||||||
#include "wx/dirdlg.h"
|
#include "wx/dirdlg.h"
|
||||||
|
#include "wx/filedlg.h"
|
||||||
#ifdef __WXMOTIF__
|
#include "wx/image.h"
|
||||||
#error Sorry, drag and drop is not yet implemented on wxMotif.
|
#include "wx/clipbrd.h"
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
#if defined(__WXGTK__) || defined(__WXMOTIF__)
|
||||||
#include "mondrian.xpm"
|
#include "mondrian.xpm"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/clipbrd.h"
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Derive two simple classes which just put in the listbox the strings (text or
|
// Derive two simple classes which just put in the listbox the strings (text or
|
||||||
// file names) we drop on them
|
// file names) we drop on them
|
||||||
@@ -95,6 +96,10 @@ public:
|
|||||||
void OnLogClear(wxCommandEvent& event);
|
void OnLogClear(wxCommandEvent& event);
|
||||||
void OnCopy(wxCommandEvent& event);
|
void OnCopy(wxCommandEvent& event);
|
||||||
void OnPaste(wxCommandEvent& event);
|
void OnPaste(wxCommandEvent& event);
|
||||||
|
void OnCopyBitmap(wxCommandEvent& event);
|
||||||
|
void OnPasteBitmap(wxCommandEvent& event);
|
||||||
|
void OnClipboardHasText(wxCommandEvent& event);
|
||||||
|
void OnClipboardHasBitmap(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnLeftDown(wxMouseEvent& event);
|
void OnLeftDown(wxMouseEvent& event);
|
||||||
void OnRightDown(wxMouseEvent& event);
|
void OnRightDown(wxMouseEvent& event);
|
||||||
@@ -102,13 +107,14 @@ public:
|
|||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxListBox *m_ctrlFile,
|
wxListBox *m_ctrlFile,
|
||||||
*m_ctrlText;
|
*m_ctrlText;
|
||||||
wxTextCtrl *m_ctrlLog;
|
wxTextCtrl *m_ctrlLog;
|
||||||
|
|
||||||
wxLog *m_pLog, *m_pLogPrev;
|
wxLog *m_pLog, *m_pLogPrev;
|
||||||
|
|
||||||
wxString m_strText;
|
wxString m_strText;
|
||||||
|
wxBitmap m_bitmap;
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -123,26 +129,38 @@ enum
|
|||||||
Menu_Help,
|
Menu_Help,
|
||||||
Menu_Clear,
|
Menu_Clear,
|
||||||
Menu_Copy,
|
Menu_Copy,
|
||||||
Menu_Paste
|
Menu_Paste,
|
||||||
|
Menu_CopyBitmap,
|
||||||
|
Menu_PasteBitmap,
|
||||||
|
Menu_HasText,
|
||||||
|
Menu_HasBitmap
|
||||||
};
|
};
|
||||||
|
|
||||||
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
BEGIN_EVENT_TABLE(DnDFrame, wxFrame)
|
||||||
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
EVT_MENU(Menu_Quit, DnDFrame::OnQuit)
|
||||||
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
EVT_MENU(Menu_About, DnDFrame::OnAbout)
|
||||||
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
EVT_MENU(Menu_Drag, DnDFrame::OnDrag)
|
||||||
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
|
EVT_MENU(Menu_Help, DnDFrame::OnHelp)
|
||||||
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
|
EVT_MENU(Menu_Clear, DnDFrame::OnLogClear)
|
||||||
EVT_MENU(Menu_Copy, DnDFrame::OnCopy)
|
EVT_MENU(Menu_Copy, DnDFrame::OnCopy)
|
||||||
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
|
EVT_MENU(Menu_Paste, DnDFrame::OnPaste)
|
||||||
|
EVT_MENU(Menu_CopyBitmap, DnDFrame::OnCopyBitmap)
|
||||||
|
EVT_MENU(Menu_PasteBitmap,DnDFrame::OnPasteBitmap)
|
||||||
|
EVT_MENU(Menu_HasText, DnDFrame::OnClipboardHasText)
|
||||||
|
EVT_MENU(Menu_HasBitmap, DnDFrame::OnClipboardHasBitmap)
|
||||||
|
|
||||||
EVT_LEFT_DOWN( DnDFrame::OnLeftDown)
|
EVT_LEFT_DOWN( DnDFrame::OnLeftDown)
|
||||||
EVT_RIGHT_DOWN( DnDFrame::OnRightDown)
|
EVT_RIGHT_DOWN( DnDFrame::OnRightDown)
|
||||||
EVT_PAINT( DnDFrame::OnPaint)
|
EVT_PAINT( DnDFrame::OnPaint)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// `Main program' equivalent, creating windows and returning main app frame
|
// `Main program' equivalent, creating windows and returning main app frame
|
||||||
bool DnDApp::OnInit()
|
bool DnDApp::OnInit()
|
||||||
{
|
{
|
||||||
|
#if wxUSE_LIBPNG
|
||||||
|
wxImage::AddHandler( new wxPNGHandler );
|
||||||
|
#endif
|
||||||
|
|
||||||
// create the main frame window
|
// create the main frame window
|
||||||
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
|
DnDFrame *frame = new DnDFrame((wxFrame *) NULL,
|
||||||
"Drag-and-Drop/Clipboard wxWindows Sample",
|
"Drag-and-Drop/Clipboard wxWindows Sample",
|
||||||
@@ -181,9 +199,15 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
|||||||
help_menu->Append(Menu_About, "&About");
|
help_menu->Append(Menu_About, "&About");
|
||||||
|
|
||||||
wxMenu *clip_menu = new wxMenu;
|
wxMenu *clip_menu = new wxMenu;
|
||||||
clip_menu->Append(Menu_Copy, "&Copy\tCtrl+C");
|
clip_menu->Append(Menu_Copy, "&Copy text\tCtrl+C");
|
||||||
clip_menu->Append(Menu_Paste, "&Paste\tCtrl+V");
|
clip_menu->Append(Menu_Paste, "&Paste text\tCtrl+V");
|
||||||
|
clip_menu->AppendSeparator();
|
||||||
|
clip_menu->Append(Menu_CopyBitmap, "&Copy bitmap");
|
||||||
|
clip_menu->Append(Menu_PasteBitmap, "&Paste bitmap");
|
||||||
|
clip_menu->AppendSeparator();
|
||||||
|
clip_menu->Append(Menu_HasText, "Clipboard has &text\tCtrl+T");
|
||||||
|
clip_menu->Append(Menu_HasBitmap, "Clipboard has a &bitmap\tCtrl+B");
|
||||||
|
|
||||||
wxMenuBar *menu_bar = new wxMenuBar;
|
wxMenuBar *menu_bar = new wxMenuBar;
|
||||||
menu_bar->Append(file_menu, "&File");
|
menu_bar->Append(file_menu, "&File");
|
||||||
menu_bar->Append(log_menu, "&Log");
|
menu_bar->Append(log_menu, "&Log");
|
||||||
@@ -198,58 +222,55 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
|
|||||||
|
|
||||||
wxString strFile("Drop files here!"), strText("Drop text on me");
|
wxString strFile("Drop files here!"), strText("Drop text on me");
|
||||||
|
|
||||||
m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL);
|
m_ctrlFile = new wxListBox(this, -1, pos, size, 1, &strFile, wxLB_HSCROLL | wxLB_ALWAYS_SB );
|
||||||
m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL);
|
m_ctrlText = new wxListBox(this, -1, pos, size, 1, &strText, wxLB_HSCROLL | wxLB_ALWAYS_SB );
|
||||||
|
|
||||||
m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size,
|
m_ctrlLog = new wxTextCtrl(this, -1, "", pos, size,
|
||||||
wxTE_MULTILINE | wxTE_READONLY |
|
wxTE_MULTILINE | wxTE_READONLY |
|
||||||
wxSUNKEN_BORDER );
|
wxSUNKEN_BORDER );
|
||||||
|
// redirect log messages to the text window (don't forget to delete it!)
|
||||||
|
m_pLog = new wxLogTextCtrl(m_ctrlLog);
|
||||||
|
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
// associate drop targets with 2 text controls
|
||||||
// redirect log messages to the text window (don't forget to delete it!)
|
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
|
||||||
m_pLog = new wxLogTextCtrl(m_ctrlLog);
|
m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
|
||||||
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// associate drop targets with 2 text controls
|
wxLayoutConstraints *c;
|
||||||
m_ctrlFile->SetDropTarget(new DnDFile(m_ctrlFile));
|
|
||||||
m_ctrlText->SetDropTarget(new DnDText(m_ctrlText));
|
|
||||||
|
|
||||||
wxLayoutConstraints *c;
|
// Top-left listbox
|
||||||
|
c = new wxLayoutConstraints;
|
||||||
|
c->left.SameAs(this, wxLeft);
|
||||||
|
c->top.SameAs(this, wxTop);
|
||||||
|
c->right.PercentOf(this, wxRight, 50);
|
||||||
|
c->height.PercentOf(this, wxHeight, 30);
|
||||||
|
m_ctrlFile->SetConstraints(c);
|
||||||
|
|
||||||
// Top-left listbox
|
// Top-right listbox
|
||||||
c = new wxLayoutConstraints;
|
c = new wxLayoutConstraints;
|
||||||
c->left.SameAs(this, wxLeft);
|
c->left.SameAs (m_ctrlFile, wxRight);
|
||||||
c->top.SameAs(this, wxTop);
|
c->top.SameAs (this, wxTop);
|
||||||
c->right.PercentOf(this, wxRight, 50);
|
c->right.SameAs (this, wxRight);
|
||||||
c->height.PercentOf(this, wxHeight, 40);
|
c->height.PercentOf(this, wxHeight, 30);
|
||||||
m_ctrlFile->SetConstraints(c);
|
m_ctrlText->SetConstraints(c);
|
||||||
|
|
||||||
// Top-right listbox
|
// Lower text control
|
||||||
c = new wxLayoutConstraints;
|
c = new wxLayoutConstraints;
|
||||||
c->left.SameAs (m_ctrlFile, wxRight);
|
c->left.SameAs (this, wxLeft);
|
||||||
c->top.SameAs (this, wxTop);
|
c->right.SameAs (this, wxRight);
|
||||||
c->right.SameAs (this, wxRight);
|
c->height.PercentOf(this, wxHeight, 30);
|
||||||
c->height.PercentOf(this, wxHeight, 40);
|
c->top.SameAs(m_ctrlText, wxBottom);
|
||||||
m_ctrlText->SetConstraints(c);
|
m_ctrlLog->SetConstraints(c);
|
||||||
|
|
||||||
// Lower text control
|
SetAutoLayout(TRUE);
|
||||||
c = new wxLayoutConstraints;
|
|
||||||
c->left.SameAs (this, wxLeft);
|
|
||||||
c->right.SameAs (this, wxRight);
|
|
||||||
c->height.PercentOf(this, wxHeight, 40);
|
|
||||||
c->top.SameAs(m_ctrlText, wxBottom);
|
|
||||||
m_ctrlLog->SetConstraints(c);
|
|
||||||
|
|
||||||
SetAutoLayout(TRUE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DnDFrame::OnQuit(wxCommandEvent& /* event */)
|
void DnDFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
Close(TRUE);
|
Close(TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DnDFrame::OnPaint(wxPaintEvent& /*event*/)
|
void DnDFrame::OnPaint(wxPaintEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
int w = 0;
|
int w = 0;
|
||||||
int h = 0;
|
int h = 0;
|
||||||
@@ -257,10 +278,55 @@ void DnDFrame::OnPaint(wxPaintEvent& /*event*/)
|
|||||||
|
|
||||||
wxPaintDC dc(this);
|
wxPaintDC dc(this);
|
||||||
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
|
dc.SetFont( wxFont( 24, wxDECORATIVE, wxNORMAL, wxNORMAL, FALSE, "charter" ) );
|
||||||
dc.DrawText( "Drag text from here!", 20, h-35 );
|
dc.DrawText( "Drag text from here!", 20, h-50 );
|
||||||
|
|
||||||
|
if (m_bitmap.Ok())
|
||||||
|
dc.DrawBitmap( m_bitmap, 280, h-120, TRUE );
|
||||||
}
|
}
|
||||||
|
|
||||||
void DnDFrame::OnDrag(wxCommandEvent& /* event */)
|
void DnDFrame::OnClipboardHasText(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if ( !wxTheClipboard->Open() )
|
||||||
|
{
|
||||||
|
wxLogError( _T("Can't open clipboard.") );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !wxTheClipboard->IsSupported( wxDF_TEXT ) )
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("No text is on the clipboard") );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("There is text is on the clipboard") );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnDFrame::OnClipboardHasBitmap(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if ( !wxTheClipboard->Open() )
|
||||||
|
{
|
||||||
|
wxLogError( _T("Can't open clipboard.") );
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !wxTheClipboard->IsSupported( wxDF_BITMAP ) )
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("No bitmap is on the clipboard") );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("A bitmap is on the clipboard") );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnDFrame::OnDrag(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxString strText = wxGetTextFromUser
|
wxString strText = wxGetTextFromUser
|
||||||
(
|
(
|
||||||
@@ -274,7 +340,7 @@ void DnDFrame::OnDrag(wxCommandEvent& /* event */)
|
|||||||
m_strText = strText;
|
m_strText = strText;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DnDFrame::OnAbout(wxCommandEvent& /* event */)
|
void DnDFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||||
{
|
{
|
||||||
wxMessageBox("Drag-&-Drop Demo\n"
|
wxMessageBox("Drag-&-Drop Demo\n"
|
||||||
"Please see \"Help|Help...\" for details\n"
|
"Please see \"Help|Help...\" for details\n"
|
||||||
@@ -357,16 +423,108 @@ void DnDFrame::OnRightDown(wxMouseEvent &event )
|
|||||||
|
|
||||||
DnDFrame::~DnDFrame()
|
DnDFrame::~DnDFrame()
|
||||||
{
|
{
|
||||||
#if wxUSE_STD_IOSTREAM
|
|
||||||
if ( m_pLog != NULL ) {
|
if ( m_pLog != NULL ) {
|
||||||
if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
|
if ( wxLog::SetActiveTarget(m_pLogPrev) == m_pLog )
|
||||||
delete m_pLog;
|
delete m_pLog;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
// clipboard
|
// bitmap clipboard
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
void DnDFrame::OnCopyBitmap(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
wxFileDialog dialog(this, "Open a PNG file", "", "", "PNG files (*.png)|*.png", 0);
|
||||||
|
|
||||||
|
if (dialog.ShowModal() != wxID_OK)
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("Aborted file open") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialog.GetPath().IsEmpty())
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("Returned empty string.") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wxFileExists(dialog.GetPath()))
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("File doesn't exist.") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxImage image;
|
||||||
|
image.LoadFile( dialog.GetPath(), wxBITMAP_TYPE_PNG );
|
||||||
|
if (!image.Ok())
|
||||||
|
{
|
||||||
|
wxLogMessage( _T("Invalid image file...") );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLogMessage( _T("Decoding image file...") );
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
wxBitmap bitmap( image.ConvertToBitmap() );
|
||||||
|
|
||||||
|
if ( !wxTheClipboard->Open() )
|
||||||
|
{
|
||||||
|
wxLogError(_T("Can't open clipboard."));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxLogMessage( _T("Creating wxBitmapDataObject...") );
|
||||||
|
wxYield();
|
||||||
|
|
||||||
|
if ( !wxTheClipboard->AddData(new wxBitmapDataObject(bitmap)) )
|
||||||
|
{
|
||||||
|
wxLogError(_T("Can't copy image to the clipboard."));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogMessage(_T("Image has been put on the clipboard.") );
|
||||||
|
wxLogMessage(_T("You can paste it now and look at it.") );
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void DnDFrame::OnPasteBitmap(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{
|
||||||
|
if ( !wxTheClipboard->Open() )
|
||||||
|
{
|
||||||
|
wxLogError(_T("Can't open clipboard."));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !wxTheClipboard->IsSupported(wxDF_BITMAP) )
|
||||||
|
{
|
||||||
|
wxLogWarning(_T("No bitmap on clipboard"));
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmapDataObject data;
|
||||||
|
if ( !wxTheClipboard->GetData(&data) )
|
||||||
|
{
|
||||||
|
wxLogError(_T("Can't paste bitmap from the clipboard"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxLogMessage(_T("Bitmap pasted from the clipboard") );
|
||||||
|
m_bitmap = data.GetBitmap();
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// text clipboard
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
void DnDFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
|
void DnDFrame::OnCopy(wxCommandEvent& WXUNUSED(event))
|
||||||
@@ -403,6 +561,7 @@ void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|||||||
{
|
{
|
||||||
wxLogWarning(_T("No text data on clipboard"));
|
wxLogWarning(_T("No text data on clipboard"));
|
||||||
|
|
||||||
|
wxTheClipboard->Close();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -423,6 +582,7 @@ void DnDFrame::OnPaste(wxCommandEvent& WXUNUSED(event))
|
|||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Notifications called by the base class
|
// Notifications called by the base class
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool DnDText::OnDropText( wxDropPointCoord, wxDropPointCoord, const wxChar *psz )
|
bool DnDText::OnDropText( wxDropPointCoord, wxDropPointCoord, const wxChar *psz )
|
||||||
{
|
{
|
||||||
m_pOwner->Append(psz);
|
m_pOwner->Append(psz);
|
||||||
|
BIN
samples/dnd/julian.png
Normal file
BIN
samples/dnd/julian.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
@@ -645,9 +645,56 @@ wxOutputStream& wxOutputStream::operator<<(wxObject& obj)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// wxCountingOutputStream
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
wxCountingOutputStream::wxCountingOutputStream ()
|
||||||
|
: wxOutputStream()
|
||||||
|
{
|
||||||
|
m_currentPos = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t wxCountingOutputStream::GetSize() const
|
||||||
|
{
|
||||||
|
return m_lastcount;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t wxCountingOutputStream::OnSysWrite(const void *buffer, size_t size)
|
||||||
|
{
|
||||||
|
m_currentPos += size;
|
||||||
|
if (m_currentPos > m_lastcount) m_lastcount = m_currentPos;
|
||||||
|
return m_currentPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxCountingOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
|
||||||
|
{
|
||||||
|
if (mode == wxFromStart)
|
||||||
|
{
|
||||||
|
m_currentPos = pos;
|
||||||
|
}
|
||||||
|
if (mode == wxFromEnd)
|
||||||
|
{
|
||||||
|
m_currentPos = m_lastcount + pos;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_currentPos += pos;
|
||||||
|
}
|
||||||
|
if (m_currentPos > m_lastcount) m_lastcount = m_currentPos;
|
||||||
|
|
||||||
|
return m_currentPos; // ?
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t wxCountingOutputStream::OnSysTell() const
|
||||||
|
{
|
||||||
|
return m_currentPos; // ?
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxFilterInputStream
|
// wxFilterInputStream
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
wxFilterInputStream::wxFilterInputStream()
|
wxFilterInputStream::wxFilterInputStream()
|
||||||
: wxInputStream()
|
: wxInputStream()
|
||||||
{
|
{
|
||||||
|
@@ -153,7 +153,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
clipboard->m_waiting = FALSE;
|
clipboard->m_waiting = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure we got the data in the correct form (selection type).
|
/* make sure we got the data in the correct form (selection type).
|
||||||
if so, copy data to target object */
|
if so, copy data to target object */
|
||||||
|
|
||||||
@@ -178,12 +178,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
{
|
{
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_BITMAP)
|
if (selection_data->type != GDK_SELECTION_TYPE_STRING)
|
||||||
{
|
{
|
||||||
clipboard->m_waiting = FALSE;
|
clipboard->m_waiting = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
|
||||||
|
|
||||||
|
bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +272,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxDataObject *data_object = (wxDataObject *)node->Data();
|
wxDataObject *data_object = (wxDataObject *)node->Data();
|
||||||
|
|
||||||
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
||||||
{
|
{
|
||||||
node = node->Next();
|
node = node->Next();
|
||||||
@@ -303,10 +307,17 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
|||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
{
|
{
|
||||||
// wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object;
|
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object;
|
||||||
|
|
||||||
// how do we do that ?
|
if (bitmap_object->GetSize() == 0) return;
|
||||||
|
|
||||||
|
gtk_selection_data_set(
|
||||||
|
selection_data,
|
||||||
|
GDK_SELECTION_TYPE_STRING,
|
||||||
|
8*sizeof(gchar),
|
||||||
|
(unsigned char*) bitmap_object->GetData(),
|
||||||
|
(int) bitmap_object->GetSize() );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
#include "wx/dataobj.h"
|
#include "wx/dataobj.h"
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
#include "wx/debug.h"
|
#include "wx/debug.h"
|
||||||
|
#include "wx/mstream.h"
|
||||||
|
#include "wx/image.h"
|
||||||
|
|
||||||
#include "gdk/gdk.h"
|
#include "gdk/gdk.h"
|
||||||
|
|
||||||
@@ -23,6 +25,7 @@
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
GdkAtom g_textAtom = 0;
|
GdkAtom g_textAtom = 0;
|
||||||
|
GdkAtom g_pngAtom = 0;
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataFormat
|
// wxDataFormat
|
||||||
@@ -32,7 +35,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject)
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat()
|
wxDataFormat::wxDataFormat()
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_type = wxDF_INVALID;
|
m_type = wxDF_INVALID;
|
||||||
m_hasAtom = FALSE;
|
m_hasAtom = FALSE;
|
||||||
m_atom = (GdkAtom) 0;
|
m_atom = (GdkAtom) 0;
|
||||||
@@ -40,25 +43,25 @@ wxDataFormat::wxDataFormat()
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat( wxDataFormatId type )
|
wxDataFormat::wxDataFormat( wxDataFormatId type )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetType( type );
|
SetType( type );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxChar *id )
|
wxDataFormat::wxDataFormat( const wxChar *id )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetId( id );
|
SetId( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxString &id )
|
wxDataFormat::wxDataFormat( const wxString &id )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetId( id );
|
SetId( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_type = format.GetType();
|
m_type = format.GetType();
|
||||||
m_id = format.GetId();
|
m_id = format.GetId();
|
||||||
m_hasAtom = TRUE;
|
m_hasAtom = TRUE;
|
||||||
@@ -67,7 +70,7 @@ wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat( const GdkAtom atom )
|
wxDataFormat::wxDataFormat( const GdkAtom atom )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_hasAtom = TRUE;
|
m_hasAtom = TRUE;
|
||||||
|
|
||||||
m_atom = atom;
|
m_atom = atom;
|
||||||
@@ -102,7 +105,7 @@ void wxDataFormat::SetType( wxDataFormatId type )
|
|||||||
else
|
else
|
||||||
if (m_type == wxDF_BITMAP)
|
if (m_type == wxDF_BITMAP)
|
||||||
{
|
{
|
||||||
m_id = _T("BITMAP");
|
m_id = _T("image/png");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (m_type == wxDF_FILENAME)
|
if (m_type == wxDF_FILENAME)
|
||||||
@@ -169,6 +172,12 @@ GdkAtom wxDataFormat::GetAtom()
|
|||||||
return m_atom;
|
return m_atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDataFormat::PrepareFormats()
|
||||||
|
{
|
||||||
|
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||||
|
if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataBroker
|
// wxDataBroker
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -385,18 +394,28 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
|
|||||||
wxBitmapDataObject::wxBitmapDataObject()
|
wxBitmapDataObject::wxBitmapDataObject()
|
||||||
{
|
{
|
||||||
m_format.SetType( wxDF_BITMAP );
|
m_format.SetType( wxDF_BITMAP );
|
||||||
|
m_pngData = (char*)NULL;
|
||||||
|
m_pngSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
m_format.SetType( wxDF_BITMAP );
|
m_format.SetType( wxDF_BITMAP );
|
||||||
|
m_pngData = (char*)NULL;
|
||||||
|
m_pngSize = 0;
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
DoConvertToPng();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmapDataObject::~wxBitmapDataObject()
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
|
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
|
||||||
{
|
{
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
DoConvertToPng();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxBitmapDataObject::GetBitmap() const
|
wxBitmap wxBitmapDataObject::GetBitmap() const
|
||||||
@@ -411,12 +430,44 @@ void wxBitmapDataObject::WriteData( void *dest ) const
|
|||||||
|
|
||||||
size_t wxBitmapDataObject::GetSize() const
|
size_t wxBitmapDataObject::GetSize() const
|
||||||
{
|
{
|
||||||
return 0;
|
return m_pngSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const
|
void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const
|
||||||
{
|
{
|
||||||
memcpy( dest, m_bitmap.GetPixmap(), GetSize() );
|
// if (m_bitmap == bitmap)
|
||||||
|
memcpy( dest, m_pngData, m_pngSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
|
m_pngData = (char*) NULL;
|
||||||
|
m_pngSize = pngSize;
|
||||||
|
m_pngData = new char[m_pngSize];
|
||||||
|
memcpy( m_pngData, pngData, m_pngSize );
|
||||||
|
|
||||||
|
wxMemoryInputStream mstream( pngData, pngSize );
|
||||||
|
wxImage image;
|
||||||
|
wxPNGHandler handler;
|
||||||
|
handler.LoadFile( &image, mstream );
|
||||||
|
m_bitmap = image.ConvertToBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapDataObject::DoConvertToPng()
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
|
|
||||||
|
wxImage image( m_bitmap );
|
||||||
|
wxPNGHandler handler;
|
||||||
|
|
||||||
|
wxCountingOutputStream count;
|
||||||
|
handler.SaveFile( &image, count );
|
||||||
|
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
|
||||||
|
m_pngData = new char[m_pngSize];
|
||||||
|
|
||||||
|
wxMemoryOutputStream mstream( m_pngData, m_pngSize );
|
||||||
|
handler.SaveFile( &image, mstream );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -153,7 +153,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
clipboard->m_waiting = FALSE;
|
clipboard->m_waiting = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* make sure we got the data in the correct form (selection type).
|
/* make sure we got the data in the correct form (selection type).
|
||||||
if so, copy data to target object */
|
if so, copy data to target object */
|
||||||
|
|
||||||
@@ -178,12 +178,16 @@ selection_received( GtkWidget *WXUNUSED(widget),
|
|||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
{
|
{
|
||||||
if (selection_data->type != GDK_SELECTION_TYPE_BITMAP)
|
if (selection_data->type != GDK_SELECTION_TYPE_STRING)
|
||||||
{
|
{
|
||||||
clipboard->m_waiting = FALSE;
|
clipboard->m_waiting = FALSE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
|
||||||
|
|
||||||
|
bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,7 +272,7 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
|||||||
while (node)
|
while (node)
|
||||||
{
|
{
|
||||||
wxDataObject *data_object = (wxDataObject *)node->Data();
|
wxDataObject *data_object = (wxDataObject *)node->Data();
|
||||||
|
|
||||||
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
if (data_object->GetFormat().GetAtom() != selection_data->target)
|
||||||
{
|
{
|
||||||
node = node->Next();
|
node = node->Next();
|
||||||
@@ -303,10 +307,17 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
|
|||||||
|
|
||||||
case wxDF_BITMAP:
|
case wxDF_BITMAP:
|
||||||
{
|
{
|
||||||
// wxBitmapDataObject *private_object = (wxBitmapDataObject*) data_object;
|
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object;
|
||||||
|
|
||||||
// how do we do that ?
|
if (bitmap_object->GetSize() == 0) return;
|
||||||
|
|
||||||
|
gtk_selection_data_set(
|
||||||
|
selection_data,
|
||||||
|
GDK_SELECTION_TYPE_STRING,
|
||||||
|
8*sizeof(gchar),
|
||||||
|
(unsigned char*) bitmap_object->GetData(),
|
||||||
|
(int) bitmap_object->GetSize() );
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -14,6 +14,8 @@
|
|||||||
#include "wx/dataobj.h"
|
#include "wx/dataobj.h"
|
||||||
#include "wx/app.h"
|
#include "wx/app.h"
|
||||||
#include "wx/debug.h"
|
#include "wx/debug.h"
|
||||||
|
#include "wx/mstream.h"
|
||||||
|
#include "wx/image.h"
|
||||||
|
|
||||||
#include "gdk/gdk.h"
|
#include "gdk/gdk.h"
|
||||||
|
|
||||||
@@ -23,6 +25,7 @@
|
|||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
|
|
||||||
GdkAtom g_textAtom = 0;
|
GdkAtom g_textAtom = 0;
|
||||||
|
GdkAtom g_pngAtom = 0;
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataFormat
|
// wxDataFormat
|
||||||
@@ -32,7 +35,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject)
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat()
|
wxDataFormat::wxDataFormat()
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_type = wxDF_INVALID;
|
m_type = wxDF_INVALID;
|
||||||
m_hasAtom = FALSE;
|
m_hasAtom = FALSE;
|
||||||
m_atom = (GdkAtom) 0;
|
m_atom = (GdkAtom) 0;
|
||||||
@@ -40,25 +43,25 @@ wxDataFormat::wxDataFormat()
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat( wxDataFormatId type )
|
wxDataFormat::wxDataFormat( wxDataFormatId type )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetType( type );
|
SetType( type );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxChar *id )
|
wxDataFormat::wxDataFormat( const wxChar *id )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetId( id );
|
SetId( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxString &id )
|
wxDataFormat::wxDataFormat( const wxString &id )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
SetId( id );
|
SetId( id );
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_type = format.GetType();
|
m_type = format.GetType();
|
||||||
m_id = format.GetId();
|
m_id = format.GetId();
|
||||||
m_hasAtom = TRUE;
|
m_hasAtom = TRUE;
|
||||||
@@ -67,7 +70,7 @@ wxDataFormat::wxDataFormat( const wxDataFormat &format )
|
|||||||
|
|
||||||
wxDataFormat::wxDataFormat( const GdkAtom atom )
|
wxDataFormat::wxDataFormat( const GdkAtom atom )
|
||||||
{
|
{
|
||||||
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
PrepareFormats();
|
||||||
m_hasAtom = TRUE;
|
m_hasAtom = TRUE;
|
||||||
|
|
||||||
m_atom = atom;
|
m_atom = atom;
|
||||||
@@ -102,7 +105,7 @@ void wxDataFormat::SetType( wxDataFormatId type )
|
|||||||
else
|
else
|
||||||
if (m_type == wxDF_BITMAP)
|
if (m_type == wxDF_BITMAP)
|
||||||
{
|
{
|
||||||
m_id = _T("BITMAP");
|
m_id = _T("image/png");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
if (m_type == wxDF_FILENAME)
|
if (m_type == wxDF_FILENAME)
|
||||||
@@ -169,6 +172,12 @@ GdkAtom wxDataFormat::GetAtom()
|
|||||||
return m_atom;
|
return m_atom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxDataFormat::PrepareFormats()
|
||||||
|
{
|
||||||
|
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
|
||||||
|
if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE );
|
||||||
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
// wxDataBroker
|
// wxDataBroker
|
||||||
//-------------------------------------------------------------------------
|
//-------------------------------------------------------------------------
|
||||||
@@ -385,18 +394,28 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
|
|||||||
wxBitmapDataObject::wxBitmapDataObject()
|
wxBitmapDataObject::wxBitmapDataObject()
|
||||||
{
|
{
|
||||||
m_format.SetType( wxDF_BITMAP );
|
m_format.SetType( wxDF_BITMAP );
|
||||||
|
m_pngData = (char*)NULL;
|
||||||
|
m_pngSize = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
|
||||||
{
|
{
|
||||||
m_format.SetType( wxDF_BITMAP );
|
m_format.SetType( wxDF_BITMAP );
|
||||||
|
m_pngData = (char*)NULL;
|
||||||
|
m_pngSize = 0;
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
DoConvertToPng();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxBitmapDataObject::~wxBitmapDataObject()
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
|
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
|
||||||
{
|
{
|
||||||
m_bitmap = bitmap;
|
m_bitmap = bitmap;
|
||||||
|
DoConvertToPng();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxBitmap wxBitmapDataObject::GetBitmap() const
|
wxBitmap wxBitmapDataObject::GetBitmap() const
|
||||||
@@ -411,12 +430,44 @@ void wxBitmapDataObject::WriteData( void *dest ) const
|
|||||||
|
|
||||||
size_t wxBitmapDataObject::GetSize() const
|
size_t wxBitmapDataObject::GetSize() const
|
||||||
{
|
{
|
||||||
return 0;
|
return m_pngSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const
|
void wxBitmapDataObject::WriteBitmap( const wxBitmap &bitmap, void *dest ) const
|
||||||
{
|
{
|
||||||
memcpy( dest, m_bitmap.GetPixmap(), GetSize() );
|
// if (m_bitmap == bitmap)
|
||||||
|
memcpy( dest, m_pngData, m_pngSize );
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
|
m_pngData = (char*) NULL;
|
||||||
|
m_pngSize = pngSize;
|
||||||
|
m_pngData = new char[m_pngSize];
|
||||||
|
memcpy( m_pngData, pngData, m_pngSize );
|
||||||
|
|
||||||
|
wxMemoryInputStream mstream( pngData, pngSize );
|
||||||
|
wxImage image;
|
||||||
|
wxPNGHandler handler;
|
||||||
|
handler.LoadFile( &image, mstream );
|
||||||
|
m_bitmap = image.ConvertToBitmap();
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxBitmapDataObject::DoConvertToPng()
|
||||||
|
{
|
||||||
|
if (m_pngData) delete[] m_pngData;
|
||||||
|
|
||||||
|
wxImage image( m_bitmap );
|
||||||
|
wxPNGHandler handler;
|
||||||
|
|
||||||
|
wxCountingOutputStream count;
|
||||||
|
handler.SaveFile( &image, count );
|
||||||
|
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
|
||||||
|
m_pngData = new char[m_pngSize];
|
||||||
|
|
||||||
|
wxMemoryOutputStream mstream( m_pngData, m_pngSize );
|
||||||
|
handler.SaveFile( &image, mstream );
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "wx/wxprec.h"
|
#include "wx/wxprec.h"
|
||||||
|
|
||||||
|
#include "wx/object.h"
|
||||||
|
|
||||||
typedef struct wxCDtime {
|
typedef struct wxCDtime {
|
||||||
wxUint8 track;
|
wxUint8 track;
|
||||||
wxUint8 hour, min, sec;
|
wxUint8 hour, min, sec;
|
||||||
|
Reference in New Issue
Block a user