New wxDataObject etc. Almost works.

A few more compatibility funcs for (long*) vs (int*).
  Makefile.in regenerated from filelist...


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4058 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-10-18 22:22:56 +00:00
parent 314260fbd0
commit 1dd989e1bf
17 changed files with 820 additions and 1205 deletions

View File

@@ -1,5 +1,5 @@
# #
# This file was automatically generated by tmake at 15:31, 1999/10/17 # This file was automatically generated by tmake at 22:21, 1999/10/18
# DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T! # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T!
# #
@@ -679,8 +679,11 @@ GTK_GENERICDEPS = \
GTK_COMMONOBJS = \ GTK_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \
choiccmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
ctrlcmn.o \
date.o \ date.o \
datstrm.o \ datstrm.o \
db.o \ db.o \
@@ -766,8 +769,11 @@ GTK_COMMONOBJS = \
GTK_COMMONDEPS = \ GTK_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \
choiccmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
ctrlcmn.d \
date.d \ date.d \
datstrm.d \ datstrm.d \
db.d \ db.d \
@@ -1047,6 +1053,7 @@ MOTIF_GENERICDEPS = \
MOTIF_COMMONOBJS = \ MOTIF_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \
choiccmn.o \ choiccmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
@@ -1137,6 +1144,7 @@ MOTIF_COMMONOBJS = \
MOTIF_COMMONDEPS = \ MOTIF_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \
choiccmn.d \ choiccmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
@@ -1383,6 +1391,7 @@ MSW_GENERICDEPS = \
MSW_COMMONOBJS = \ MSW_COMMONOBJS = \
parser.o \ parser.o \
appcmn.o \
choiccmn.o \ choiccmn.o \
cmndata.o \ cmndata.o \
config.o \ config.o \
@@ -1473,6 +1482,7 @@ MSW_COMMONOBJS = \
MSW_COMMONDEPS = \ MSW_COMMONDEPS = \
parser.d \ parser.d \
appcmn.d \
choiccmn.d \ choiccmn.d \
cmndata.d \ cmndata.d \
config.d \ config.d \
@@ -1737,6 +1747,7 @@ MSW_GUIDEPS = \
BASE_OBJS = \ BASE_OBJS = \
init.o \ init.o \
appcmn.o \
config.o \ config.o \
date.o \ date.o \
dynarray.o \ dynarray.o \
@@ -1771,6 +1782,7 @@ BASE_OBJS = \
BASE_DEPS = \ BASE_DEPS = \
init.d \ init.d \
appcmn.d \
config.d \ config.d \
date.d \ date.d \
dynarray.d \ dynarray.d \

View File

@@ -37,7 +37,7 @@
class WXDLLEXPORT wxPrivateDataObject : public wxDataObject class WXDLLEXPORT wxPrivateDataObject : public wxDataObject
{ {
#if defined(__WXGTK__) || defined(__WXMOTIF__) #if defined(__WXGTK__) || defined(__WXMOTIF__)
DECLARE_DYNAMIC_CLASS( wxPrivateDataObject ) DECLARE_CLASS( wxPrivateDataObject )
#endif #endif
public: public:
@@ -87,7 +87,7 @@ private:
size_t m_size; size_t m_size;
void *m_data; void *m_data;
#if !defined(__WXGTK__) && !defined(__WXMOTIF__) #if !defined(__WXMOTIF__)
// the data format // the data format
wxDataFormat m_format; wxDataFormat m_format;
#endif #endif

View File

@@ -251,6 +251,7 @@ public:
virtual wxCoord GetCharHeight() const = 0; virtual wxCoord GetCharHeight() const = 0;
virtual wxCoord GetCharWidth() const = 0; virtual wxCoord GetCharWidth() const = 0;
void GetTextExtent(const wxString& string, void GetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y, wxCoord *x, wxCoord *y,
wxCoord *descent = NULL, wxCoord *descent = NULL,
@@ -441,6 +442,15 @@ public:
if ( y ) if ( y )
*y = y2; *y = y2;
} }
void GetClippingBox(long *x, long *y, long *w, long *h) const
{
wxCoord xx,yy,ww,hh;
DoGetClippingBox(&xx, &yy, &ww, &hh);
if (x) *x = xx;
if (y) *y = yy;
if (w) *w = ww;
if (h) *h = hh;
}
#endif // !Win16 #endif // !Win16
#if WXWIN_COMPATIBILITY #if WXWIN_COMPATIBILITY

View File

@@ -605,8 +605,15 @@ public:
bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); } bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); }
// Find the position of the event // Find the position of the event
void GetPosition(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; } void GetPosition(long *xpos, long *ypos) const
void Position(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; } { if (xpos) *xpos = m_x;
if (ypos) *ypos = m_y; }
void GetPosition(int *xpos, int *ypos) const
{ if (xpos) *xpos = m_x;
if (ypos) *ypos = m_y; }
void Position(long *xpos, long *ypos) const
{ if (xpos) *xpos = m_x;
if (ypos) *ypos = m_y; }
// Find the position of the event // Find the position of the event
wxPoint GetPosition() const { return wxPoint(m_x, m_y); } wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
@@ -668,7 +675,11 @@ public:
// Find the position of the event // Find the position of the event
void GetPosition(long *xpos, long *ypos) const void GetPosition(long *xpos, long *ypos) const
{ *xpos = m_x; *ypos = m_y; } { if (xpos) *xpos = m_x;
if (ypos) *ypos = m_y; }
void GetPosition(int *xpos, int *ypos) const
{ if (xpos) *xpos = m_x;
if (ypos) *ypos = m_y; }
wxPoint GetPosition() const wxPoint GetPosition() const
{ return wxPoint(m_x, m_y); } { return wxPoint(m_x, m_y); }

View File

@@ -69,18 +69,19 @@ public:
// clears wxTheClipboard and the system's clipboard if possible // clears wxTheClipboard and the system's clipboard if possible
virtual void Clear(); virtual void Clear();
// flushes the clipboard: not available under GTK
virtual bool Flush() { return FALSE; }
/// If primary == TRUE, use primary selection in all further ops, /// If primary == TRUE, use primary selection in all further ops,
/// primary=FALSE resets it. /// primary=FALSE resets it.
inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; } inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; }
// implementation // implementation
bool m_open; bool m_open;
bool m_ownsClipboard; bool m_ownsClipboard;
bool m_ownsPrimarySelection; bool m_ownsPrimarySelection;
wxDataObject *m_data;
wxDataBroker *m_dataBroker;
GtkWidget *m_clipboardWidget; /* for getting and offering data */ GtkWidget *m_clipboardWidget; /* for getting and offering data */
GtkWidget *m_targetsWidget; /* for getting list of supported formats */ GtkWidget *m_targetsWidget; /* for getting list of supported formats */
bool m_waiting; /* querying data or formats is asynchronous */ bool m_waiting; /* querying data or formats is asynchronous */

View File

@@ -32,123 +32,111 @@ class wxPrivateDataObject;
class wxFileDataObject; class wxFileDataObject;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat (internal) // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDataFormat : public wxObject class wxDataFormat
{ {
public: public:
// the clipboard formats under GDK are GdkAtoms
typedef GdkAtom NativeFormat;
wxDataFormat(); wxDataFormat();
wxDataFormat( wxDataFormatId type ); wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id ); wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id ); wxDataFormat( const wxChar *id );
wxDataFormat( const wxDataFormat &format ); wxDataFormat( NativeFormat format );
wxDataFormat( const GdkAtom atom );
void SetType( wxDataFormatId type ); wxDataFormat& operator=(NativeFormat format)
wxDataFormatId GetType() const; { SetId(format); return *this; }
wxDataFormat& operator=(const wxDataFormat& format)
{ SetId(format); return *this; }
/* the string Id identifies the format of clipboard or DnD data. a word // comparison (must have both versions)
* processor would e.g. add a wxTextDataObject and a wxPrivateDataObject bool operator==(wxDataFormatId type) const
* to the clipboard - the latter with the Id "application/wxword", an { return m_type == (wxDataFormatId)type; }
* image manipulation program would put a wxBitmapDataObject and a bool operator!=(wxDataFormatId type) const
* wxPrivateDataObject to the clipboard - the latter with "image/png". */ { 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 );
// this only works with standard ids
void SetId( NativeFormat format );
// string ids are used for custom types - this SetId() must be used for
// application-specific formats
wxString GetId() const; wxString GetId() const;
void SetId( const wxChar *id ); void SetId( const wxChar *id );
GdkAtom GetAtom(); // implementation
void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } wxDataFormatId GetType() const;
// 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: private:
wxDataFormatId m_type; wxDataFormatId m_type;
wxString m_id; NativeFormat m_format;
bool m_hasAtom;
GdkAtom m_atom;
void PrepareFormats(); void PrepareFormats();
void SetType( wxDataFormatId type );
private:
DECLARE_CLASS( wxDataFormat )
};
//-------------------------------------------------------------------------
// wxDataBroker (internal)
//-------------------------------------------------------------------------
class wxDataBroker : public wxObject
{
public:
/* 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 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;
private:
DECLARE_CLASS( wxDataBroker )
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxDataObject to be placed in wxDataBroker // wxDataObject
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
class wxDataObject : public wxObject class wxDataObject : public wxObject
{ {
public: public:
/* constructor */
wxDataObject(); wxDataObject();
/* destructor */
~wxDataObject(); ~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;
wxDataFormat &GetFormat(); 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;
wxDataFormatId GetFormatType() const; // a simpler name which makes more sense for data objects supporting
wxString GetFormatId() const; // only one format
GdkAtom GetFormatAtom() const; 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: private:
DECLARE_DYNAMIC_CLASS( wxDataObject ) DECLARE_DYNAMIC_CLASS( wxDataObject )
@@ -161,34 +149,27 @@ private:
class wxTextDataObject : public wxDataObject class wxTextDataObject : public wxDataObject
{ {
public: public:
/* default constructor. call SetText() later or override // ctors
WriteData() and GetSize() for working on-demand */
wxTextDataObject(); wxTextDataObject();
wxTextDataObject(const wxString& strText);
void Init(const wxString& strText) { m_strText = strText; }
/* constructor */ virtual wxDataFormat GetPreferredFormat() const
wxTextDataObject( const wxString& data ); { 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);
/* set current text data */ // additional helpers
void SetText( const wxString& data ); void SetText(const wxString& strText) { m_strText = strText; }
wxString GetText() const { return 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;
public:
/* implementation */
wxString m_data;
private:
wxString m_strText;
private: private:
DECLARE_DYNAMIC_CLASS( wxTextDataObject ) DECLARE_DYNAMIC_CLASS( wxTextDataObject )
}; };
@@ -200,24 +181,21 @@ private:
class wxFileDataObject : public wxDataObject class wxFileDataObject : public wxDataObject
{ {
public: public:
/* default constructor */
wxFileDataObject(); wxFileDataObject();
/* add file name to list */
void AddFile( const wxString &file ); 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; wxString GetFiles() const;
/* write list of filenames */ virtual wxDataFormat GetPreferredFormat() const
virtual void WriteData( void *dest ) const; { return wxDF_FILENAME; }
virtual bool IsSupportedFormat(const wxDataFormat& format) const
/* return length of list of filenames */ { return format == wxDF_FILENAME; }
virtual size_t GetSize() const;
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);
public: public:
/* implementation */
wxString m_files; wxString m_files;
private: private:
@@ -231,26 +209,38 @@ private:
class wxBitmapDataObject : public wxDataObject class wxBitmapDataObject : public wxDataObject
{ {
public: public:
/* see wxTextDataObject for explanation */ // ctors
wxBitmapDataObject(); wxBitmapDataObject();
wxBitmapDataObject( const wxBitmap& bitmap ); wxBitmapDataObject(const wxBitmap& bitmap);
// destr
~wxBitmapDataObject(); ~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 ); // 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;
// sets PNG data
virtual bool SetData(const wxDataFormat& format, const void *buf);
// sets PNG data
virtual void SetPngData(const void *buf, size_t size);
void *GetData()
{ return m_pngData; }
private: private:
wxBitmap m_bitmap; wxBitmap m_bitmap;
size_t m_pngSize; size_t m_pngSize;
char *m_pngData; void *m_pngData;
void DoConvertToPng(); void DoConvertToPng();

View File

@@ -119,27 +119,20 @@ public:
// wxPrivateDropTarget // wxPrivateDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/*
class wxPrivateDropTarget: public wxDropTarget class wxPrivateDropTarget: public wxDropTarget
{ {
public: public:
/* sets id to "application/myprogram" where "myprogram" is the
same as wxApp->GetAppName() */
wxPrivateDropTarget(); wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id ); wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y ); virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y ); virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y ); virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
/* 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" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; } void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; } wxString GetId() { return m_id; }
@@ -147,6 +140,7 @@ private:
wxString m_id; wxString m_id;
}; };
*/
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer) // A drop target which accepts files (dragged from File Manager or Explorer)
@@ -162,9 +156,7 @@ public:
virtual bool OnDrop( long x, long y ); virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y ); virtual bool OnData( long x, long y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -187,23 +179,11 @@ public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource(); ~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject& data ); void SetData( wxDataObject& data );
// this one isn't portable to wxMSW -- deprecated
void SetData( wxDataObject *data );
/* start drag action */ /* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE ); wxDragResult DoDragDrop( bool bAllowMove = FALSE );
@@ -218,7 +198,7 @@ public:
GtkWidget *m_widget; GtkWidget *m_widget;
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxDataBroker *m_data; wxDataObject *m_data;
wxCursor m_defaultCursor; wxCursor m_defaultCursor;
wxCursor m_goaheadCursor; wxCursor m_goaheadCursor;

View File

@@ -69,18 +69,19 @@ public:
// clears wxTheClipboard and the system's clipboard if possible // clears wxTheClipboard and the system's clipboard if possible
virtual void Clear(); virtual void Clear();
// flushes the clipboard: not available under GTK
virtual bool Flush() { return FALSE; }
/// If primary == TRUE, use primary selection in all further ops, /// If primary == TRUE, use primary selection in all further ops,
/// primary=FALSE resets it. /// primary=FALSE resets it.
inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; } inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; }
// implementation // implementation
bool m_open; bool m_open;
bool m_ownsClipboard; bool m_ownsClipboard;
bool m_ownsPrimarySelection; bool m_ownsPrimarySelection;
wxDataObject *m_data;
wxDataBroker *m_dataBroker;
GtkWidget *m_clipboardWidget; /* for getting and offering data */ GtkWidget *m_clipboardWidget; /* for getting and offering data */
GtkWidget *m_targetsWidget; /* for getting list of supported formats */ GtkWidget *m_targetsWidget; /* for getting list of supported formats */
bool m_waiting; /* querying data or formats is asynchronous */ bool m_waiting; /* querying data or formats is asynchronous */

View File

@@ -32,123 +32,111 @@ class wxPrivateDataObject;
class wxFileDataObject; class wxFileDataObject;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat (internal) // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
class wxDataFormat : public wxObject class wxDataFormat
{ {
public: public:
// the clipboard formats under GDK are GdkAtoms
typedef GdkAtom NativeFormat;
wxDataFormat(); wxDataFormat();
wxDataFormat( wxDataFormatId type ); wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id ); wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id ); wxDataFormat( const wxChar *id );
wxDataFormat( const wxDataFormat &format ); wxDataFormat( NativeFormat format );
wxDataFormat( const GdkAtom atom );
void SetType( wxDataFormatId type ); wxDataFormat& operator=(NativeFormat format)
wxDataFormatId GetType() const; { SetId(format); return *this; }
wxDataFormat& operator=(const wxDataFormat& format)
{ SetId(format); return *this; }
/* the string Id identifies the format of clipboard or DnD data. a word // comparison (must have both versions)
* processor would e.g. add a wxTextDataObject and a wxPrivateDataObject bool operator==(wxDataFormatId type) const
* to the clipboard - the latter with the Id "application/wxword", an { return m_type == (wxDataFormatId)type; }
* image manipulation program would put a wxBitmapDataObject and a bool operator!=(wxDataFormatId type) const
* wxPrivateDataObject to the clipboard - the latter with "image/png". */ { 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 );
// this only works with standard ids
void SetId( NativeFormat format );
// string ids are used for custom types - this SetId() must be used for
// application-specific formats
wxString GetId() const; wxString GetId() const;
void SetId( const wxChar *id ); void SetId( const wxChar *id );
GdkAtom GetAtom(); // implementation
void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; } wxDataFormatId GetType() const;
// 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: private:
wxDataFormatId m_type; wxDataFormatId m_type;
wxString m_id; NativeFormat m_format;
bool m_hasAtom;
GdkAtom m_atom;
void PrepareFormats(); void PrepareFormats();
void SetType( wxDataFormatId type );
private:
DECLARE_CLASS( wxDataFormat )
};
//-------------------------------------------------------------------------
// wxDataBroker (internal)
//-------------------------------------------------------------------------
class wxDataBroker : public wxObject
{
public:
/* 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 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;
private:
DECLARE_CLASS( wxDataBroker )
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxDataObject to be placed in wxDataBroker // wxDataObject
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
class wxDataObject : public wxObject class wxDataObject : public wxObject
{ {
public: public:
/* constructor */
wxDataObject(); wxDataObject();
/* destructor */
~wxDataObject(); ~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;
wxDataFormat &GetFormat(); 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;
wxDataFormatId GetFormatType() const; // a simpler name which makes more sense for data objects supporting
wxString GetFormatId() const; // only one format
GdkAtom GetFormatAtom() const; 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: private:
DECLARE_DYNAMIC_CLASS( wxDataObject ) DECLARE_DYNAMIC_CLASS( wxDataObject )
@@ -161,34 +149,27 @@ private:
class wxTextDataObject : public wxDataObject class wxTextDataObject : public wxDataObject
{ {
public: public:
/* default constructor. call SetText() later or override // ctors
WriteData() and GetSize() for working on-demand */
wxTextDataObject(); wxTextDataObject();
wxTextDataObject(const wxString& strText);
void Init(const wxString& strText) { m_strText = strText; }
/* constructor */ virtual wxDataFormat GetPreferredFormat() const
wxTextDataObject( const wxString& data ); { 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);
/* set current text data */ // additional helpers
void SetText( const wxString& data ); void SetText(const wxString& strText) { m_strText = strText; }
wxString GetText() const { return 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;
public:
/* implementation */
wxString m_data;
private:
wxString m_strText;
private: private:
DECLARE_DYNAMIC_CLASS( wxTextDataObject ) DECLARE_DYNAMIC_CLASS( wxTextDataObject )
}; };
@@ -200,24 +181,21 @@ private:
class wxFileDataObject : public wxDataObject class wxFileDataObject : public wxDataObject
{ {
public: public:
/* default constructor */
wxFileDataObject(); wxFileDataObject();
/* add file name to list */
void AddFile( const wxString &file ); 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; wxString GetFiles() const;
/* write list of filenames */ virtual wxDataFormat GetPreferredFormat() const
virtual void WriteData( void *dest ) const; { return wxDF_FILENAME; }
virtual bool IsSupportedFormat(const wxDataFormat& format) const
/* return length of list of filenames */ { return format == wxDF_FILENAME; }
virtual size_t GetSize() const;
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);
public: public:
/* implementation */
wxString m_files; wxString m_files;
private: private:
@@ -231,26 +209,38 @@ private:
class wxBitmapDataObject : public wxDataObject class wxBitmapDataObject : public wxDataObject
{ {
public: public:
/* see wxTextDataObject for explanation */ // ctors
wxBitmapDataObject(); wxBitmapDataObject();
wxBitmapDataObject( const wxBitmap& bitmap ); wxBitmapDataObject(const wxBitmap& bitmap);
// destr
~wxBitmapDataObject(); ~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 ); // 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;
// sets PNG data
virtual bool SetData(const wxDataFormat& format, const void *buf);
// sets PNG data
virtual void SetPngData(const void *buf, size_t size);
void *GetData()
{ return m_pngData; }
private: private:
wxBitmap m_bitmap; wxBitmap m_bitmap;
size_t m_pngSize; size_t m_pngSize;
char *m_pngData; void *m_pngData;
void DoConvertToPng(); void DoConvertToPng();

View File

@@ -119,27 +119,20 @@ public:
// wxPrivateDropTarget // wxPrivateDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/*
class wxPrivateDropTarget: public wxDropTarget class wxPrivateDropTarget: public wxDropTarget
{ {
public: public:
/* sets id to "application/myprogram" where "myprogram" is the
same as wxApp->GetAppName() */
wxPrivateDropTarget(); wxPrivateDropTarget();
/* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id ); wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y ); virtual bool OnMove( long x, long y );
virtual bool OnDrop( long x, long y ); virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y ); virtual bool OnData( long x, long y );
/* you have to override OnDropData to get at the data */
virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0;
/* 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" or
"image/png". */
void SetId( const wxString& id ) { m_id = id; } void SetId( const wxString& id ) { m_id = id; }
wxString GetId() { return m_id; } wxString GetId() { return m_id; }
@@ -147,6 +140,7 @@ private:
wxString m_id; wxString m_id;
}; };
*/
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer) // A drop target which accepts files (dragged from File Manager or Explorer)
@@ -162,9 +156,7 @@ public:
virtual bool OnDrop( long x, long y ); virtual bool OnDrop( long x, long y );
virtual bool OnData( long x, long y ); virtual bool OnData( long x, long y );
/* you have to override OnDropFiles to get at the file names */
virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0;
}; };
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -187,23 +179,11 @@ public:
/* constructor. set data later with SetData() */ /* constructor. set data later with SetData() */
wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); wxDropSource( wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting one data object */
wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon ); wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go = wxNullIcon, const wxIcon &stop = wxNullIcon );
/* constructor for setting several data objects via wxDataBroker */
wxDropSource( wxDataBroker *data, wxWindow *win );
~wxDropSource(); ~wxDropSource();
/* set several dataobjects via wxDataBroker */
void SetData( wxDataBroker *data );
/* set one dataobject */
void SetData( wxDataObject& data ); void SetData( wxDataObject& data );
// this one isn't portable to wxMSW -- deprecated
void SetData( wxDataObject *data );
/* start drag action */ /* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE ); wxDragResult DoDragDrop( bool bAllowMove = FALSE );
@@ -218,7 +198,7 @@ public:
GtkWidget *m_widget; GtkWidget *m_widget;
wxWindow *m_window; wxWindow *m_window;
wxDragResult m_retValue; wxDragResult m_retValue;
wxDataBroker *m_data; wxDataObject *m_data;
wxCursor m_defaultCursor; wxCursor m_defaultCursor;
wxCursor m_goaheadCursor; wxCursor m_goaheadCursor;

View File

@@ -181,7 +181,7 @@ public:
// to implement in derived classes // to implement in derived classes
virtual Kind GetKind() const = 0; virtual Kind GetKind() const = 0;
virtual void Draw(wxDC& dc) = 0 virtual void Draw(wxDC& dc)
{ {
dc.SetPen(wxPen(m_col, 1, wxSOLID)); dc.SetPen(wxPen(m_col, 1, wxSOLID));
} }
@@ -228,7 +228,9 @@ public:
dc.DrawLine(p2, p3); dc.DrawLine(p2, p3);
dc.DrawLine(p3, p1); dc.DrawLine(p3, p1);
#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
#endif
} }
}; };
@@ -257,7 +259,9 @@ public:
dc.DrawLine(p3, p4); dc.DrawLine(p3, p4);
dc.DrawLine(p4, p1); dc.DrawLine(p4, p1);
#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
#endif
} }
}; };
@@ -278,7 +282,9 @@ public:
dc.DrawEllipse(m_pos, m_size); dc.DrawEllipse(m_pos, m_size);
#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER); dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
#endif
} }
}; };
@@ -654,9 +660,11 @@ DnDFrame::DnDFrame(wxFrame *frame, char *title, int x, int y, int w, int h)
wxTE_MULTILINE | wxTE_READONLY | wxTE_MULTILINE | wxTE_READONLY |
wxSUNKEN_BORDER ); wxSUNKEN_BORDER );
#ifdef __WXMSW__
// redirect log messages to the text window and switch on OLE messages // redirect log messages to the text window and switch on OLE messages
// logging // logging
wxLog::AddTraceMask(wxTRACE_OleCalls); wxLog::AddTraceMask(wxTRACE_OleCalls);
#endif
m_pLog = new wxLogTextCtrl(m_ctrlLog); m_pLog = new wxLogTextCtrl(m_ctrlLog);
m_pLogPrev = wxLog::SetActiveTarget(m_pLog); m_pLogPrev = wxLog::SetActiveTarget(m_pLog);

View File

@@ -100,7 +100,8 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++) for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
{ {
/* char *name = gdk_atom_name (atoms[i]); /*
char *name = gdk_atom_name (atoms[i]);
if (name) printf( "Format available: %s.\n", name ); */ if (name) printf( "Format available: %s.\n", name ); */
if (atoms[i] == clipboard->m_targetRequested) if (atoms[i] == clipboard->m_targetRequested)
@@ -134,7 +135,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
} }
wxDataObject *data_object = clipboard->m_receivedData; wxDataObject *data_object = clipboard->m_receivedData;
if (!data_object) if (!data_object)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
@@ -148,7 +149,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
} }
/* make sure we got the data in the correct format */ /* make sure we got the data in the correct format */
if (data_object->GetFormat().GetAtom() != selection_data->target) if (data_object->GetFormat() != selection_data->target)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
@@ -186,7 +187,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length ); bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length );
break; break;
} }
@@ -245,10 +246,10 @@ selection_clear_clip( GtkWidget *WXUNUSED(widget), GdkEventSelection *event )
(!wxTheClipboard->m_ownsClipboard)) (!wxTheClipboard->m_ownsClipboard))
{ {
/* the clipboard is no longer in our hands. we can the delete clipboard data. */ /* the clipboard is no longer in our hands. we can the delete clipboard data. */
if (wxTheClipboard->m_dataBroker) if (wxTheClipboard->m_data)
{ {
delete wxTheClipboard->m_dataBroker; delete wxTheClipboard->m_data;
wxTheClipboard->m_dataBroker = (wxDataBroker*) NULL; wxTheClipboard->m_data = (wxDataObject*) NULL;
} }
} }
@@ -265,82 +266,64 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
{ {
if (!wxTheClipboard) return; if (!wxTheClipboard) return;
if (!wxTheClipboard->m_dataBroker) return; if (!wxTheClipboard->m_data) return;
wxNode *node = wxTheClipboard->m_dataBroker->m_dataObjects.First(); wxDataObject *data = wxTheClipboard->m_data;
while (node) if (!data->IsSupportedFormat( selection_data->target )) return;
if (data->GetFormat().GetType() == wxDF_TEXT)
{ {
wxDataObject *data_object = (wxDataObject *)node->Data(); wxTextDataObject *text_object = (wxTextDataObject*) data;
wxString text( text_object->GetText() );
if (data_object->GetFormat().GetAtom() != selection_data->target)
{
node = node->Next();
continue;
}
switch (data_object->GetFormat().GetType())
{
case wxDF_TEXT:
{
wxTextDataObject *text_object = (wxTextDataObject*) data_object;
wxString text = text_object->GetText();
#if wxUSE_UNICODE #if wxUSE_UNICODE
const wxWX2MBbuf s = text.mbc_str(); const wxWX2MBbuf s = text.mbc_str();
int len = strlen(s); int len = strlen(s);
#else // more efficient in non-Unicode #else // more efficient in non-Unicode
const char *s = text.c_str(); const char *s = text.c_str();
int len = (int) text.Length(); int len = (int) text.Length();
#endif #endif
gtk_selection_data_set(
gtk_selection_data_set( selection_data,
selection_data, GDK_SELECTION_TYPE_STRING,
GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar),
8*sizeof(gchar), (unsigned char*) (const char*) s,
(unsigned char*) (const char*) s, len );
len );
break; return;
}
case wxDF_BITMAP:
{
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object;
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;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject *private_object = (wxPrivateDataObject*) data_object;
if (private_object->GetSize() == 0) return;
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) private_object->GetData(),
(int) private_object->GetSize() );
}
default:
break;
}
node = node->Next();
} }
if (data->GetFormat().GetType() == wxDF_BITMAP)
{
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) bitmap_object->GetData(),
(int) bitmap_object->GetDataSize(wxDF_BITMAP) );
return;
}
int size = data->GetDataSize( selection_data->target );
if (size == 0) return;
char *d = new char[size];
data->GetDataHere( selection_data->target, (void*) d );
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) d,
size );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -356,8 +339,7 @@ wxClipboard::wxClipboard()
m_ownsClipboard = FALSE; m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE; m_ownsPrimarySelection = FALSE;
m_dataBroker = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
m_receivedData = (wxDataObject*) NULL; m_receivedData = (wxDataObject*) NULL;
/* we use m_targetsWidget to query what formats are available */ /* we use m_targetsWidget to query what formats are available */
@@ -404,8 +386,8 @@ wxClipboard::~wxClipboard()
void wxClipboard::Clear() void wxClipboard::Clear()
{ {
if (m_dataBroker) if (m_data)
{ {
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@@ -431,10 +413,10 @@ void wxClipboard::Clear()
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
} }
if (m_dataBroker) if (m_data)
{ {
delete m_dataBroker; delete m_data;
m_dataBroker = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
} }
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -444,7 +426,6 @@ void wxClipboard::Clear()
} }
m_targetRequested = 0; m_targetRequested = 0;
m_formatSupported = FALSE; m_formatSupported = FALSE;
} }
@@ -474,14 +455,13 @@ bool wxClipboard::AddData( wxDataObject *data )
wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
/* if clipboard has been cleared before, create new data broker */ // we can only store one wxDataObject
if (!m_dataBroker) m_dataBroker = new wxDataBroker(); Clear();
/* add new data to list of offered data objects */ m_data = data;
m_dataBroker->Add( data );
/* get native format id of new data object */ /* get native format id of new data object */
GdkAtom format = data->GetFormat().GetAtom(); GdkAtom format = data->GetFormat();
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") ); wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
@@ -570,11 +550,9 @@ void wxClipboard::Close()
bool wxClipboard::IsSupported( wxDataFormat format ) bool wxClipboard::IsSupported( wxDataFormat format )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */
m_targetRequested = format.GetAtom(); m_targetRequested = format;
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -591,7 +569,7 @@ bool wxClipboard::IsSupported( wxDataFormat format )
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_targetsWidget, gtk_selection_convert( m_targetsWidget,
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
g_targetsAtom, g_targetsAtom,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );
@@ -616,7 +594,7 @@ bool wxClipboard::GetData( wxDataObject *data )
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */
m_targetRequested = data->GetFormat().GetAtom(); m_targetRequested = data->GetFormat();
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -636,7 +614,7 @@ bool wxClipboard::GetData( wxDataObject *data )
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget, gtk_selection_convert( m_clipboardWidget,
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested, m_targetRequested,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );

View File

@@ -26,19 +26,17 @@
GdkAtom g_textAtom = 0; GdkAtom g_textAtom = 0;
GdkAtom g_pngAtom = 0; GdkAtom g_pngAtom = 0;
GdkAtom g_fileAtom = 0;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
IMPLEMENT_CLASS(wxDataFormat, wxObject)
wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat()
{ {
PrepareFormats(); PrepareFormats();
m_type = wxDF_INVALID; m_type = wxDF_INVALID;
m_hasAtom = FALSE; m_format = (GdkAtom) 0;
m_atom = (GdkAtom) 0;
} }
wxDataFormat::wxDataFormat( wxDataFormatId type ) wxDataFormat::wxDataFormat( wxDataFormatId type )
@@ -59,39 +57,10 @@ wxDataFormat::wxDataFormat( const wxString &id )
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( const wxDataFormat &format ) wxDataFormat::wxDataFormat( NativeFormat format )
{ {
PrepareFormats(); PrepareFormats();
m_type = format.GetType(); SetId( format );
m_id = format.GetId();
m_hasAtom = TRUE;
m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
}
wxDataFormat::wxDataFormat( const GdkAtom atom )
{
PrepareFormats();
m_hasAtom = TRUE;
m_atom = atom;
if (m_atom == g_textAtom)
{
m_type = wxDF_TEXT;
} else
if (m_atom == GDK_TARGET_BITMAP)
{
m_type = wxDF_BITMAP;
} else
{
m_type = wxDF_PRIVATE;
m_id = gdk_atom_name( m_atom );
if (m_id == wxT("file:ALL"))
{
m_type = wxDF_FILENAME;
}
}
} }
void wxDataFormat::SetType( wxDataFormatId type ) void wxDataFormat::SetType( wxDataFormatId type )
@@ -99,25 +68,17 @@ void wxDataFormat::SetType( wxDataFormatId type )
m_type = type; m_type = type;
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ m_format = g_textAtom;
m_id = wxT("STRING");
}
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
{ m_format = g_pngAtom;
m_id = wxT("image/png");
}
else else
if (m_type == wxDF_FILENAME) if (m_type == wxDF_FILENAME)
{ m_format = g_fileAtom;
m_id = wxT("file:ALL");
}
else else
{ {
wxFAIL_MSG( wxT("invalid dataformat") ); wxFAIL_MSG( wxT("invalid dataformat") );
} }
m_hasAtom = FALSE;
} }
wxDataFormatId wxDataFormat::GetType() const wxDataFormatId wxDataFormat::GetType() const
@@ -127,152 +88,41 @@ wxDataFormatId wxDataFormat::GetType() const
wxString wxDataFormat::GetId() const wxString wxDataFormat::GetId() const
{ {
return m_id; wxString ret( gdk_atom_name( m_format ) ); // this will convert from ascii to Unicode
return ret;
}
void wxDataFormat::SetId( NativeFormat format )
{
m_format = format;
if (m_format == g_textAtom)
m_type = wxDF_TEXT;
else
if (m_format == g_pngAtom)
m_type = wxDF_BITMAP;
else
if (m_format == g_fileAtom)
m_type = wxDF_FILENAME;
else
m_type = wxDF_PRIVATE;
} }
void wxDataFormat::SetId( const wxChar *id ) void wxDataFormat::SetId( const wxChar *id )
{ {
m_type = wxDF_PRIVATE; m_type = wxDF_PRIVATE;
m_id = id; wxString tmp( id );
m_hasAtom = FALSE; m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
}
GdkAtom wxDataFormat::GetAtom()
{
if (!m_hasAtom)
{
m_hasAtom = TRUE;
if (m_type == wxDF_TEXT)
{
m_atom = g_textAtom;
}
else
if (m_type == wxDF_BITMAP)
{
m_atom = GDK_TARGET_BITMAP;
}
else
if (m_type == wxDF_PRIVATE)
{
m_atom = gdk_atom_intern( wxMBSTRINGCAST m_id.mbc_str(), FALSE );
}
else
if (m_type == wxDF_FILENAME)
{
m_atom = gdk_atom_intern( "file:ALL", FALSE );
}
else
{
m_hasAtom = FALSE;
m_atom = (GdkAtom) 0;
}
}
return m_atom;
} }
void wxDataFormat::PrepareFormats() void wxDataFormat::PrepareFormats()
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); if (!g_textAtom)
if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); g_textAtom = gdk_atom_intern( "STRING", FALSE );
} if (!g_pngAtom)
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
//------------------------------------------------------------------------- if (!g_fileAtom)
// wxDataBroker g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
//-------------------------------------------------------------------------
IMPLEMENT_CLASS(wxDataBroker,wxObject)
wxDataBroker::wxDataBroker()
{
m_dataObjects.DeleteContents(TRUE);
m_preferred = 0;
}
void wxDataBroker::Add( wxDataObject *dataObject, bool preferred )
{
if (preferred) m_preferred = m_dataObjects.GetCount();
m_dataObjects.Append( dataObject );
}
size_t wxDataBroker::GetFormatCount() const
{
return m_dataObjects.GetCount();
}
wxDataFormatId wxDataBroker::GetPreferredFormat() const
{
wxNode *node = m_dataObjects.Nth( m_preferred );
wxASSERT( node );
wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat().GetType();
}
wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const
{
wxNode *node = m_dataObjects.Nth( nth );
wxASSERT( node );
wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat();
}
bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
return TRUE;
}
node = node->Next();
}
return FALSE;
}
size_t wxDataBroker::GetSize( wxDataFormat& format ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
return dobj->GetSize();
}
node = node->Next();
}
return 0;
}
void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
dobj->WriteData( dest );
}
node = node->Next();
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -289,26 +139,29 @@ wxDataObject::~wxDataObject()
{ {
} }
wxDataFormat &wxDataObject::GetFormat() bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
{ {
return m_format; size_t nFormatCount = GetFormatCount();
if ( nFormatCount == 1 ) {
return format == GetPreferredFormat();
}
else {
wxDataFormat *formats = new wxDataFormat[nFormatCount];
GetAllFormats(formats);
size_t n;
for ( n = 0; n < nFormatCount; n++ ) {
if ( formats[n] == format )
break;
}
delete [] formats;
// found?
return n < nFormatCount;
}
} }
wxDataFormatId wxDataObject::GetFormatType() const
{
return m_format.GetType();
}
wxString wxDataObject::GetFormatId() const
{
return m_format.GetId();
}
GdkAtom wxDataObject::GetFormatAtom() const
{
GdkAtom ret = ((wxDataObject*) this)->m_format.GetAtom();
return ret;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxTextDataObject // wxTextDataObject
@@ -316,41 +169,30 @@ GdkAtom wxDataObject::GetFormatAtom() const
IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
wxTextDataObject::wxTextDataObject() wxTextDataObject::wxTextDataObject()
{ {
m_format.SetType( wxDF_TEXT );
} }
wxTextDataObject::wxTextDataObject( const wxString& data ) wxTextDataObject::wxTextDataObject(const wxString& strText)
{ : m_strText(strText)
m_format.SetType( wxDF_TEXT ); {
m_data = data;
} }
void wxTextDataObject::SetText( const wxString& data ) size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
{ {
m_data = data; return m_strText.Len() + 1; // +1 for trailing '\0'of course
} }
wxString wxTextDataObject::GetText() const bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
return m_data; memcpy(buf, m_strText.c_str(), GetDataSize(format));
return TRUE;
} }
void wxTextDataObject::WriteData( void *dest ) const bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
{ {
WriteString( m_data, dest ); m_strText = (const wxChar *)buf;
} return TRUE;
size_t wxTextDataObject::GetSize() const
{
return m_data.Len() + 1;
}
void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
{
memcpy( dest, str.mb_str(), str.Len()+1 );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -361,7 +203,6 @@ IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
wxFileDataObject::wxFileDataObject() wxFileDataObject::wxFileDataObject()
{ {
m_format.SetType( wxDF_FILENAME );
} }
void wxFileDataObject::AddFile( const wxString &file ) void wxFileDataObject::AddFile( const wxString &file )
@@ -375,16 +216,34 @@ wxString wxFileDataObject::GetFiles() const
return m_files; return m_files;
} }
void wxFileDataObject::WriteData( void *dest ) const bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
memcpy( dest, m_files.mbc_str(), GetSize() ); if (format == wxDF_FILENAME)
{
memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 );
return TRUE;
}
return FALSE;
} }
size_t wxFileDataObject::GetSize() const size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const
{ {
if (format != wxDF_FILENAME) return 0;
return m_files.Len() + 1; return m_files.Len() + 1;
} }
bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf)
{
if (format != wxDF_FILENAME)
return FALSE;
m_files = (char*)(buf); // this is so ugly, I cannot look at it
return TRUE;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxBitmapDataObject // wxBitmapDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -393,15 +252,13 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
wxBitmapDataObject::wxBitmapDataObject() wxBitmapDataObject::wxBitmapDataObject()
{ {
m_format.SetType( wxDF_BITMAP ); m_pngData = (void*)NULL;
m_pngData = (char*)NULL;
m_pngSize = 0; m_pngSize = 0;
} }
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
{ {
m_format.SetType( wxDF_BITMAP ); m_pngData = (void*)NULL;
m_pngData = (char*)NULL;
m_pngSize = 0; m_pngSize = 0;
m_bitmap = bitmap; m_bitmap = bitmap;
DoConvertToPng(); DoConvertToPng();
@@ -409,45 +266,60 @@ wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
wxBitmapDataObject::~wxBitmapDataObject() wxBitmapDataObject::~wxBitmapDataObject()
{ {
if (m_pngData) delete[] m_pngData; if (m_pngData)
delete[] m_pngData;
} }
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
{ {
if (m_pngData)
delete[] m_pngData;
m_pngData = (void*)NULL;
m_pngSize = 0;
m_bitmap = bitmap; m_bitmap = bitmap;
DoConvertToPng(); DoConvertToPng();
} }
wxBitmap wxBitmapDataObject::GetBitmap() const size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
{
return m_bitmap;
}
void wxBitmapDataObject::WriteData( void *dest ) const
{
WriteBitmap( m_bitmap, dest );
}
size_t wxBitmapDataObject::GetSize() const
{ {
if (format != wxDF_BITMAP) return 0;
return m_pngSize; return m_pngSize;
} }
void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
// if (m_bitmap == bitmap) if (format != wxDF_BITMAP) return FALSE;
memcpy( dest, m_pngData, m_pngSize );
if (m_pngSize > 0)
{
memcpy(buf, m_pngData, m_pngSize);
return TRUE;
}
return FALSE;
} }
void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize ) bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
{ {
if (m_pngData) delete[] m_pngData; if (m_pngData) delete[] m_pngData;
m_pngData = (char*) NULL; m_pngData = (void*) NULL;
m_pngSize = pngSize; m_pngSize = 0;
m_pngData = new char[m_pngSize]; m_bitmap = wxNullBitmap;
memcpy( m_pngData, pngData, m_pngSize );
wxMemoryInputStream mstream( pngData, pngSize ); return FALSE;
}
void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
{
if (m_pngData) delete[] m_pngData;
m_pngSize = size;
m_pngData = (void*) new char[m_pngSize];
memcpy( m_pngData, buf, m_pngSize );
wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
wxImage image; wxImage image;
wxPNGHandler handler; wxPNGHandler handler;
handler.LoadFile( &image, mstream ); handler.LoadFile( &image, mstream );
@@ -456,7 +328,7 @@ void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
void wxBitmapDataObject::DoConvertToPng() void wxBitmapDataObject::DoConvertToPng()
{ {
if (m_pngData) delete[] m_pngData; if (!m_bitmap.Ok()) return;
wxImage image( m_bitmap ); wxImage image( m_bitmap );
wxPNGHandler handler; wxPNGHandler handler;
@@ -464,9 +336,9 @@ void wxBitmapDataObject::DoConvertToPng()
wxCountingOutputStream count; wxCountingOutputStream count;
handler.SaveFile( &image, count ); handler.SaveFile( &image, count );
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
m_pngData = new char[m_pngSize]; m_pngData = (void*) new char[m_pngSize];
wxMemoryOutputStream mstream( m_pngData, m_pngSize ); wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
handler.SaveFile( &image, mstream ); handler.SaveFile( &image, mstream );
} }
@@ -474,7 +346,7 @@ void wxBitmapDataObject::DoConvertToPng()
// wxPrivateDataObject // wxPrivateDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject ) IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free() void wxPrivateDataObject::Free()
{ {

View File

@@ -380,7 +380,7 @@ bool wxDropTarget::RequestData( wxDataFormat format )
/* this should trigger an "drag_data_received" event */ /* this should trigger an "drag_data_received" event */
gtk_drag_get_data( m_dragWidget, gtk_drag_get_data( m_dragWidget,
m_dragContext, m_dragContext,
format.GetAtom(), format,
m_dragTime ); m_dragTime );
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -403,7 +403,7 @@ bool wxDropTarget::IsSupported( wxDataFormat format )
// char *name = gdk_atom_name( formatAtom ); // char *name = gdk_atom_name( formatAtom );
// if (name) printf( "Format available: %s.\n", name ); // if (name) printf( "Format available: %s.\n", name );
if (formatAtom == format.GetAtom()) return TRUE; if (formatAtom == format) return TRUE;
child = child->next; child = child->next;
} }
@@ -414,7 +414,7 @@ bool wxDropTarget::GetData( wxDataObject *data_object )
{ {
if (!m_dragData) return FALSE; if (!m_dragData) return FALSE;
if (m_dragData->target != data_object->GetFormat().GetAtom()) return FALSE; if (m_dragData->target != data_object->GetFormat()) return FALSE;
if (data_object->GetFormat().GetType() == wxDF_TEXT) if (data_object->GetFormat().GetType() == wxDF_TEXT)
{ {
@@ -521,6 +521,7 @@ bool wxTextDropTarget::OnData( long x, long y )
// wxPrivateDropTarget // wxPrivateDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/*
wxPrivateDropTarget::wxPrivateDropTarget() wxPrivateDropTarget::wxPrivateDropTarget()
{ {
m_id = wxTheApp->GetAppName(); m_id = wxTheApp->GetAppName();
@@ -558,6 +559,7 @@ bool wxPrivateDropTarget::OnData( long x, long y )
return TRUE; return TRUE;
} }
*/
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer) // A drop target which accepts files (dragged from File Manager or Explorer)
@@ -584,7 +586,7 @@ bool wxFileDropTarget::OnData( long x, long y )
wxFileDataObject data; wxFileDataObject data;
if (!GetData( &data )) return FALSE; if (!GetData( &data )) return FALSE;
/* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */ // get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0
size_t number = 0; size_t number = 0;
size_t i; size_t i;
size_t size = data.GetFiles().Length(); size_t size = data.GetFiles().Length();
@@ -630,51 +632,51 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
// char *name = gdk_atom_name( selection_data->target ); // char *name = gdk_atom_name( selection_data->target );
// if (name) printf( "Format requested: %s.\n", name ); // if (name) printf( "Format requested: %s.\n", name );
wxNode *node = drop_source->m_data->m_dataObjects.First(); drop_source->m_retValue = wxDragCancel;
while (node)
wxDataObject *data = drop_source->m_data;
if (!data)
return;
if (!data->IsSupportedFormat(selection_data->target))
return;
if (data->GetDataSize(selection_data->target) == 0)
return;
size_t size = data->GetDataSize(selection_data->target);
// printf( "data size: %d.\n", (int)data_size );
guchar *d = new guchar[size];
if (!data->GetDataHere( selection_data->target, (void*)d ))
{ {
wxDataObject *data_object = (wxDataObject*) node->Data(); free( d );
if (data_object->GetFormat().GetAtom() == selection_data->target) return;
{ }
// printf( "format found.\n" );
size_t data_size = data_object->GetSize();
if (data_size > 0)
{
// printf( "data size: %d.\n", (int)data_size );
guchar *buffer = new guchar[data_size];
data_object->WriteData( buffer );
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
#endif #endif
gtk_selection_data_set( selection_data, gtk_selection_data_set( selection_data,
selection_data->target, selection_data->target,
8, // 8-bit 8, // 8-bit
buffer, d,
data_size ); size );
#if wxUSE_THREADS #if wxUSE_THREADS
/* enable GUI threads */ /* enable GUI threads */
wxapp_install_thread_wakeup(); wxapp_install_thread_wakeup();
#endif #endif
free( buffer );
/* so far only copy, no moves. TODO. */ free( d );
drop_source->m_retValue = wxDragCopy;
/* so far only copy, no moves. TODO. */
return; drop_source->m_retValue = wxDragCopy;
}
}
node = node->Next();
}
drop_source->m_retValue = wxDragCancel;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -733,7 +735,7 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
m_widget = win->m_widget; m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_data = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
@@ -755,8 +757,7 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_data = new wxDataBroker; m_data = &data;
m_data->Add(&data);
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND ); m_goaheadCursor = wxCursor( wxCURSOR_HAND );
@@ -767,53 +768,18 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
} }
wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
{
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
m_data = data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
void wxDropSource::SetData( wxDataObject& data ) void wxDropSource::SetData( wxDataObject& data )
{ {
if ( m_data ) if (m_data)
delete m_data; delete m_data;
m_data = new wxDataBroker; m_data = &data;
m_data->Add(&data);
}
void wxDropSource::SetData( wxDataObject *data )
{
if (m_data) delete m_data;
if (data)
{
m_data = new wxDataBroker();
m_data->Add( data );
}
else
{
m_data = (wxDataBroker*) NULL;
}
}
void wxDropSource::SetData( wxDataBroker *data )
{
if (m_data) delete m_data;
m_data = data;
} }
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
if (m_data) delete m_data; if (m_data)
// delete m_data;
g_blockEventsOnDrag = FALSE; g_blockEventsOnDrag = FALSE;
} }

View File

@@ -100,7 +100,8 @@ targets_selection_received( GtkWidget *WXUNUSED(widget),
for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++) for (unsigned int i=0; i<selection_data->length/sizeof(GdkAtom); i++)
{ {
/* char *name = gdk_atom_name (atoms[i]); /*
char *name = gdk_atom_name (atoms[i]);
if (name) printf( "Format available: %s.\n", name ); */ if (name) printf( "Format available: %s.\n", name ); */
if (atoms[i] == clipboard->m_targetRequested) if (atoms[i] == clipboard->m_targetRequested)
@@ -134,7 +135,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
} }
wxDataObject *data_object = clipboard->m_receivedData; wxDataObject *data_object = clipboard->m_receivedData;
if (!data_object) if (!data_object)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
@@ -148,7 +149,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
} }
/* make sure we got the data in the correct format */ /* make sure we got the data in the correct format */
if (data_object->GetFormat().GetAtom() != selection_data->target) if (data_object->GetFormat() != selection_data->target)
{ {
clipboard->m_waiting = FALSE; clipboard->m_waiting = FALSE;
return; return;
@@ -186,7 +187,7 @@ selection_received( GtkWidget *WXUNUSED(widget),
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object;
bitmap_object->SetPngData( (const char*) selection_data->data, (size_t) selection_data->length ); bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length );
break; break;
} }
@@ -245,10 +246,10 @@ selection_clear_clip( GtkWidget *WXUNUSED(widget), GdkEventSelection *event )
(!wxTheClipboard->m_ownsClipboard)) (!wxTheClipboard->m_ownsClipboard))
{ {
/* the clipboard is no longer in our hands. we can the delete clipboard data. */ /* the clipboard is no longer in our hands. we can the delete clipboard data. */
if (wxTheClipboard->m_dataBroker) if (wxTheClipboard->m_data)
{ {
delete wxTheClipboard->m_dataBroker; delete wxTheClipboard->m_data;
wxTheClipboard->m_dataBroker = (wxDataBroker*) NULL; wxTheClipboard->m_data = (wxDataObject*) NULL;
} }
} }
@@ -265,82 +266,64 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data
{ {
if (!wxTheClipboard) return; if (!wxTheClipboard) return;
if (!wxTheClipboard->m_dataBroker) return; if (!wxTheClipboard->m_data) return;
wxNode *node = wxTheClipboard->m_dataBroker->m_dataObjects.First(); wxDataObject *data = wxTheClipboard->m_data;
while (node) if (!data->IsSupportedFormat( selection_data->target )) return;
if (data->GetFormat().GetType() == wxDF_TEXT)
{ {
wxDataObject *data_object = (wxDataObject *)node->Data(); wxTextDataObject *text_object = (wxTextDataObject*) data;
wxString text( text_object->GetText() );
if (data_object->GetFormat().GetAtom() != selection_data->target)
{
node = node->Next();
continue;
}
switch (data_object->GetFormat().GetType())
{
case wxDF_TEXT:
{
wxTextDataObject *text_object = (wxTextDataObject*) data_object;
wxString text = text_object->GetText();
#if wxUSE_UNICODE #if wxUSE_UNICODE
const wxWX2MBbuf s = text.mbc_str(); const wxWX2MBbuf s = text.mbc_str();
int len = strlen(s); int len = strlen(s);
#else // more efficient in non-Unicode #else // more efficient in non-Unicode
const char *s = text.c_str(); const char *s = text.c_str();
int len = (int) text.Length(); int len = (int) text.Length();
#endif #endif
gtk_selection_data_set(
gtk_selection_data_set( selection_data,
selection_data, GDK_SELECTION_TYPE_STRING,
GDK_SELECTION_TYPE_STRING, 8*sizeof(gchar),
8*sizeof(gchar), (unsigned char*) (const char*) s,
(unsigned char*) (const char*) s, len );
len );
break; return;
}
case wxDF_BITMAP:
{
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data_object;
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;
}
case wxDF_PRIVATE:
{
wxPrivateDataObject *private_object = (wxPrivateDataObject*) data_object;
if (private_object->GetSize() == 0) return;
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) private_object->GetData(),
(int) private_object->GetSize() );
}
default:
break;
}
node = node->Next();
} }
if (data->GetFormat().GetType() == wxDF_BITMAP)
{
wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) bitmap_object->GetData(),
(int) bitmap_object->GetDataSize(wxDF_BITMAP) );
return;
}
int size = data->GetDataSize( selection_data->target );
if (size == 0) return;
char *d = new char[size];
data->GetDataHere( selection_data->target, (void*) d );
gtk_selection_data_set(
selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar),
(unsigned char*) d,
size );
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@@ -356,8 +339,7 @@ wxClipboard::wxClipboard()
m_ownsClipboard = FALSE; m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE; m_ownsPrimarySelection = FALSE;
m_dataBroker = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
m_receivedData = (wxDataObject*) NULL; m_receivedData = (wxDataObject*) NULL;
/* we use m_targetsWidget to query what formats are available */ /* we use m_targetsWidget to query what formats are available */
@@ -404,8 +386,8 @@ wxClipboard::~wxClipboard()
void wxClipboard::Clear() void wxClipboard::Clear()
{ {
if (m_dataBroker) if (m_data)
{ {
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
@@ -431,10 +413,10 @@ void wxClipboard::Clear()
while (m_waiting) gtk_main_iteration(); while (m_waiting) gtk_main_iteration();
} }
if (m_dataBroker) if (m_data)
{ {
delete m_dataBroker; delete m_data;
m_dataBroker = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
} }
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -444,7 +426,6 @@ void wxClipboard::Clear()
} }
m_targetRequested = 0; m_targetRequested = 0;
m_formatSupported = FALSE; m_formatSupported = FALSE;
} }
@@ -474,14 +455,13 @@ bool wxClipboard::AddData( wxDataObject *data )
wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
/* if clipboard has been cleared before, create new data broker */ // we can only store one wxDataObject
if (!m_dataBroker) m_dataBroker = new wxDataBroker(); Clear();
/* add new data to list of offered data objects */ m_data = data;
m_dataBroker->Add( data );
/* get native format id of new data object */ /* get native format id of new data object */
GdkAtom format = data->GetFormat().GetAtom(); GdkAtom format = data->GetFormat();
wxCHECK_MSG( format, FALSE, wxT("data has invalid format") ); wxCHECK_MSG( format, FALSE, wxT("data has invalid format") );
@@ -570,11 +550,9 @@ void wxClipboard::Close()
bool wxClipboard::IsSupported( wxDataFormat format ) bool wxClipboard::IsSupported( wxDataFormat format )
{ {
wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */
m_targetRequested = format.GetAtom(); m_targetRequested = format;
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -591,7 +569,7 @@ bool wxClipboard::IsSupported( wxDataFormat format )
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_targetsWidget, gtk_selection_convert( m_targetsWidget,
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
g_targetsAtom, g_targetsAtom,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );
@@ -616,7 +594,7 @@ bool wxClipboard::GetData( wxDataObject *data )
/* store requested format to be asked for by callbacks */ /* store requested format to be asked for by callbacks */
m_targetRequested = data->GetFormat().GetAtom(); m_targetRequested = data->GetFormat();
wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") );
@@ -636,7 +614,7 @@ bool wxClipboard::GetData( wxDataObject *data )
m_waiting = TRUE; m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget, gtk_selection_convert( m_clipboardWidget,
m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested, m_targetRequested,
GDK_CURRENT_TIME ); GDK_CURRENT_TIME );

View File

@@ -26,19 +26,17 @@
GdkAtom g_textAtom = 0; GdkAtom g_textAtom = 0;
GdkAtom g_pngAtom = 0; GdkAtom g_pngAtom = 0;
GdkAtom g_fileAtom = 0;
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// wxDataFormat // wxDataFormat
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
IMPLEMENT_CLASS(wxDataFormat, wxObject)
wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat()
{ {
PrepareFormats(); PrepareFormats();
m_type = wxDF_INVALID; m_type = wxDF_INVALID;
m_hasAtom = FALSE; m_format = (GdkAtom) 0;
m_atom = (GdkAtom) 0;
} }
wxDataFormat::wxDataFormat( wxDataFormatId type ) wxDataFormat::wxDataFormat( wxDataFormatId type )
@@ -59,39 +57,10 @@ wxDataFormat::wxDataFormat( const wxString &id )
SetId( id ); SetId( id );
} }
wxDataFormat::wxDataFormat( const wxDataFormat &format ) wxDataFormat::wxDataFormat( NativeFormat format )
{ {
PrepareFormats(); PrepareFormats();
m_type = format.GetType(); SetId( format );
m_id = format.GetId();
m_hasAtom = TRUE;
m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
}
wxDataFormat::wxDataFormat( const GdkAtom atom )
{
PrepareFormats();
m_hasAtom = TRUE;
m_atom = atom;
if (m_atom == g_textAtom)
{
m_type = wxDF_TEXT;
} else
if (m_atom == GDK_TARGET_BITMAP)
{
m_type = wxDF_BITMAP;
} else
{
m_type = wxDF_PRIVATE;
m_id = gdk_atom_name( m_atom );
if (m_id == wxT("file:ALL"))
{
m_type = wxDF_FILENAME;
}
}
} }
void wxDataFormat::SetType( wxDataFormatId type ) void wxDataFormat::SetType( wxDataFormatId type )
@@ -99,25 +68,17 @@ void wxDataFormat::SetType( wxDataFormatId type )
m_type = type; m_type = type;
if (m_type == wxDF_TEXT) if (m_type == wxDF_TEXT)
{ m_format = g_textAtom;
m_id = wxT("STRING");
}
else else
if (m_type == wxDF_BITMAP) if (m_type == wxDF_BITMAP)
{ m_format = g_pngAtom;
m_id = wxT("image/png");
}
else else
if (m_type == wxDF_FILENAME) if (m_type == wxDF_FILENAME)
{ m_format = g_fileAtom;
m_id = wxT("file:ALL");
}
else else
{ {
wxFAIL_MSG( wxT("invalid dataformat") ); wxFAIL_MSG( wxT("invalid dataformat") );
} }
m_hasAtom = FALSE;
} }
wxDataFormatId wxDataFormat::GetType() const wxDataFormatId wxDataFormat::GetType() const
@@ -127,152 +88,41 @@ wxDataFormatId wxDataFormat::GetType() const
wxString wxDataFormat::GetId() const wxString wxDataFormat::GetId() const
{ {
return m_id; wxString ret( gdk_atom_name( m_format ) ); // this will convert from ascii to Unicode
return ret;
}
void wxDataFormat::SetId( NativeFormat format )
{
m_format = format;
if (m_format == g_textAtom)
m_type = wxDF_TEXT;
else
if (m_format == g_pngAtom)
m_type = wxDF_BITMAP;
else
if (m_format == g_fileAtom)
m_type = wxDF_FILENAME;
else
m_type = wxDF_PRIVATE;
} }
void wxDataFormat::SetId( const wxChar *id ) void wxDataFormat::SetId( const wxChar *id )
{ {
m_type = wxDF_PRIVATE; m_type = wxDF_PRIVATE;
m_id = id; wxString tmp( id );
m_hasAtom = FALSE; m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
}
GdkAtom wxDataFormat::GetAtom()
{
if (!m_hasAtom)
{
m_hasAtom = TRUE;
if (m_type == wxDF_TEXT)
{
m_atom = g_textAtom;
}
else
if (m_type == wxDF_BITMAP)
{
m_atom = GDK_TARGET_BITMAP;
}
else
if (m_type == wxDF_PRIVATE)
{
m_atom = gdk_atom_intern( wxMBSTRINGCAST m_id.mbc_str(), FALSE );
}
else
if (m_type == wxDF_FILENAME)
{
m_atom = gdk_atom_intern( "file:ALL", FALSE );
}
else
{
m_hasAtom = FALSE;
m_atom = (GdkAtom) 0;
}
}
return m_atom;
} }
void wxDataFormat::PrepareFormats() void wxDataFormat::PrepareFormats()
{ {
if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE ); if (!g_textAtom)
if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE ); g_textAtom = gdk_atom_intern( "STRING", FALSE );
} if (!g_pngAtom)
g_pngAtom = gdk_atom_intern( "image/png", FALSE );
//------------------------------------------------------------------------- if (!g_fileAtom)
// wxDataBroker g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
//-------------------------------------------------------------------------
IMPLEMENT_CLASS(wxDataBroker,wxObject)
wxDataBroker::wxDataBroker()
{
m_dataObjects.DeleteContents(TRUE);
m_preferred = 0;
}
void wxDataBroker::Add( wxDataObject *dataObject, bool preferred )
{
if (preferred) m_preferred = m_dataObjects.GetCount();
m_dataObjects.Append( dataObject );
}
size_t wxDataBroker::GetFormatCount() const
{
return m_dataObjects.GetCount();
}
wxDataFormatId wxDataBroker::GetPreferredFormat() const
{
wxNode *node = m_dataObjects.Nth( m_preferred );
wxASSERT( node );
wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat().GetType();
}
wxDataFormat &wxDataBroker::GetNthFormat( size_t nth ) const
{
wxNode *node = m_dataObjects.Nth( nth );
wxASSERT( node );
wxDataObject* data_obj = (wxDataObject*)node->Data();
return data_obj->GetFormat();
}
bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
return TRUE;
}
node = node->Next();
}
return FALSE;
}
size_t wxDataBroker::GetSize( wxDataFormat& format ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
return dobj->GetSize();
}
node = node->Next();
}
return 0;
}
void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
{
wxNode *node = m_dataObjects.First();
while (node)
{
wxDataObject *dobj = (wxDataObject*)node->Data();
if (dobj->GetFormat().GetAtom() == format.GetAtom())
{
dobj->WriteData( dest );
}
node = node->Next();
}
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
@@ -289,26 +139,29 @@ wxDataObject::~wxDataObject()
{ {
} }
wxDataFormat &wxDataObject::GetFormat() bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const
{ {
return m_format; size_t nFormatCount = GetFormatCount();
if ( nFormatCount == 1 ) {
return format == GetPreferredFormat();
}
else {
wxDataFormat *formats = new wxDataFormat[nFormatCount];
GetAllFormats(formats);
size_t n;
for ( n = 0; n < nFormatCount; n++ ) {
if ( formats[n] == format )
break;
}
delete [] formats;
// found?
return n < nFormatCount;
}
} }
wxDataFormatId wxDataObject::GetFormatType() const
{
return m_format.GetType();
}
wxString wxDataObject::GetFormatId() const
{
return m_format.GetId();
}
GdkAtom wxDataObject::GetFormatAtom() const
{
GdkAtom ret = ((wxDataObject*) this)->m_format.GetAtom();
return ret;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxTextDataObject // wxTextDataObject
@@ -316,41 +169,30 @@ GdkAtom wxDataObject::GetFormatAtom() const
IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject ) IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
wxTextDataObject::wxTextDataObject() wxTextDataObject::wxTextDataObject()
{ {
m_format.SetType( wxDF_TEXT );
} }
wxTextDataObject::wxTextDataObject( const wxString& data ) wxTextDataObject::wxTextDataObject(const wxString& strText)
{ : m_strText(strText)
m_format.SetType( wxDF_TEXT ); {
m_data = data;
} }
void wxTextDataObject::SetText( const wxString& data ) size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
{ {
m_data = data; return m_strText.Len() + 1; // +1 for trailing '\0'of course
} }
wxString wxTextDataObject::GetText() const bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
return m_data; memcpy(buf, m_strText.c_str(), GetDataSize(format));
return TRUE;
} }
void wxTextDataObject::WriteData( void *dest ) const bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
{ {
WriteString( m_data, dest ); m_strText = (const wxChar *)buf;
} return TRUE;
size_t wxTextDataObject::GetSize() const
{
return m_data.Len() + 1;
}
void wxTextDataObject::WriteString( const wxString &str, void *dest ) const
{
memcpy( dest, str.mb_str(), str.Len()+1 );
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -361,7 +203,6 @@ IMPLEMENT_DYNAMIC_CLASS( wxFileDataObject, wxDataObject )
wxFileDataObject::wxFileDataObject() wxFileDataObject::wxFileDataObject()
{ {
m_format.SetType( wxDF_FILENAME );
} }
void wxFileDataObject::AddFile( const wxString &file ) void wxFileDataObject::AddFile( const wxString &file )
@@ -375,16 +216,34 @@ wxString wxFileDataObject::GetFiles() const
return m_files; return m_files;
} }
void wxFileDataObject::WriteData( void *dest ) const bool wxFileDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
memcpy( dest, m_files.mbc_str(), GetSize() ); if (format == wxDF_FILENAME)
{
memcpy( buf, m_files.mbc_str(), m_files.Len() + 1 );
return TRUE;
}
return FALSE;
} }
size_t wxFileDataObject::GetSize() const size_t wxFileDataObject::GetDataSize(const wxDataFormat& format) const
{ {
if (format != wxDF_FILENAME) return 0;
return m_files.Len() + 1; return m_files.Len() + 1;
} }
bool wxFileDataObject::SetData(const wxDataFormat& format, const void *buf)
{
if (format != wxDF_FILENAME)
return FALSE;
m_files = (char*)(buf); // this is so ugly, I cannot look at it
return TRUE;
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxBitmapDataObject // wxBitmapDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -393,15 +252,13 @@ IMPLEMENT_DYNAMIC_CLASS( wxBitmapDataObject, wxDataObject )
wxBitmapDataObject::wxBitmapDataObject() wxBitmapDataObject::wxBitmapDataObject()
{ {
m_format.SetType( wxDF_BITMAP ); m_pngData = (void*)NULL;
m_pngData = (char*)NULL;
m_pngSize = 0; m_pngSize = 0;
} }
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap ) wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
{ {
m_format.SetType( wxDF_BITMAP ); m_pngData = (void*)NULL;
m_pngData = (char*)NULL;
m_pngSize = 0; m_pngSize = 0;
m_bitmap = bitmap; m_bitmap = bitmap;
DoConvertToPng(); DoConvertToPng();
@@ -409,45 +266,60 @@ wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
wxBitmapDataObject::~wxBitmapDataObject() wxBitmapDataObject::~wxBitmapDataObject()
{ {
if (m_pngData) delete[] m_pngData; if (m_pngData)
delete[] m_pngData;
} }
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap ) void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
{ {
if (m_pngData)
delete[] m_pngData;
m_pngData = (void*)NULL;
m_pngSize = 0;
m_bitmap = bitmap; m_bitmap = bitmap;
DoConvertToPng(); DoConvertToPng();
} }
wxBitmap wxBitmapDataObject::GetBitmap() const size_t wxBitmapDataObject::GetDataSize(const wxDataFormat& format) const
{
return m_bitmap;
}
void wxBitmapDataObject::WriteData( void *dest ) const
{
WriteBitmap( m_bitmap, dest );
}
size_t wxBitmapDataObject::GetSize() const
{ {
if (format != wxDF_BITMAP) return 0;
return m_pngSize; return m_pngSize;
} }
void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{ {
// if (m_bitmap == bitmap) if (format != wxDF_BITMAP) return FALSE;
memcpy( dest, m_pngData, m_pngSize );
if (m_pngSize > 0)
{
memcpy(buf, m_pngData, m_pngSize);
return TRUE;
}
return FALSE;
} }
void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize ) bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
{ {
if (m_pngData) delete[] m_pngData; if (m_pngData) delete[] m_pngData;
m_pngData = (char*) NULL; m_pngData = (void*) NULL;
m_pngSize = pngSize; m_pngSize = 0;
m_pngData = new char[m_pngSize]; m_bitmap = wxNullBitmap;
memcpy( m_pngData, pngData, m_pngSize );
wxMemoryInputStream mstream( pngData, pngSize ); return FALSE;
}
void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
{
if (m_pngData) delete[] m_pngData;
m_pngSize = size;
m_pngData = (void*) new char[m_pngSize];
memcpy( m_pngData, buf, m_pngSize );
wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
wxImage image; wxImage image;
wxPNGHandler handler; wxPNGHandler handler;
handler.LoadFile( &image, mstream ); handler.LoadFile( &image, mstream );
@@ -456,7 +328,7 @@ void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
void wxBitmapDataObject::DoConvertToPng() void wxBitmapDataObject::DoConvertToPng()
{ {
if (m_pngData) delete[] m_pngData; if (!m_bitmap.Ok()) return;
wxImage image( m_bitmap ); wxImage image( m_bitmap );
wxPNGHandler handler; wxPNGHandler handler;
@@ -464,9 +336,9 @@ void wxBitmapDataObject::DoConvertToPng()
wxCountingOutputStream count; wxCountingOutputStream count;
handler.SaveFile( &image, count ); handler.SaveFile( &image, count );
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ??? m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
m_pngData = new char[m_pngSize]; m_pngData = (void*) new char[m_pngSize];
wxMemoryOutputStream mstream( m_pngData, m_pngSize ); wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
handler.SaveFile( &image, mstream ); handler.SaveFile( &image, mstream );
} }
@@ -474,7 +346,7 @@ void wxBitmapDataObject::DoConvertToPng()
// wxPrivateDataObject // wxPrivateDataObject
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject ) IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free() void wxPrivateDataObject::Free()
{ {

View File

@@ -380,7 +380,7 @@ bool wxDropTarget::RequestData( wxDataFormat format )
/* this should trigger an "drag_data_received" event */ /* this should trigger an "drag_data_received" event */
gtk_drag_get_data( m_dragWidget, gtk_drag_get_data( m_dragWidget,
m_dragContext, m_dragContext,
format.GetAtom(), format,
m_dragTime ); m_dragTime );
#if wxUSE_THREADS #if wxUSE_THREADS
@@ -403,7 +403,7 @@ bool wxDropTarget::IsSupported( wxDataFormat format )
// char *name = gdk_atom_name( formatAtom ); // char *name = gdk_atom_name( formatAtom );
// if (name) printf( "Format available: %s.\n", name ); // if (name) printf( "Format available: %s.\n", name );
if (formatAtom == format.GetAtom()) return TRUE; if (formatAtom == format) return TRUE;
child = child->next; child = child->next;
} }
@@ -414,7 +414,7 @@ bool wxDropTarget::GetData( wxDataObject *data_object )
{ {
if (!m_dragData) return FALSE; if (!m_dragData) return FALSE;
if (m_dragData->target != data_object->GetFormat().GetAtom()) return FALSE; if (m_dragData->target != data_object->GetFormat()) return FALSE;
if (data_object->GetFormat().GetType() == wxDF_TEXT) if (data_object->GetFormat().GetType() == wxDF_TEXT)
{ {
@@ -521,6 +521,7 @@ bool wxTextDropTarget::OnData( long x, long y )
// wxPrivateDropTarget // wxPrivateDropTarget
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
/*
wxPrivateDropTarget::wxPrivateDropTarget() wxPrivateDropTarget::wxPrivateDropTarget()
{ {
m_id = wxTheApp->GetAppName(); m_id = wxTheApp->GetAppName();
@@ -558,6 +559,7 @@ bool wxPrivateDropTarget::OnData( long x, long y )
return TRUE; return TRUE;
} }
*/
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer) // A drop target which accepts files (dragged from File Manager or Explorer)
@@ -584,7 +586,7 @@ bool wxFileDropTarget::OnData( long x, long y )
wxFileDataObject data; wxFileDataObject data;
if (!GetData( &data )) return FALSE; if (!GetData( &data )) return FALSE;
/* get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0 */ // get number of substrings /root/mytext.txt/0/root/myothertext.txt/0/0
size_t number = 0; size_t number = 0;
size_t i; size_t i;
size_t size = data.GetFiles().Length(); size_t size = data.GetFiles().Length();
@@ -630,51 +632,51 @@ source_drag_data_get (GtkWidget *WXUNUSED(widget),
// char *name = gdk_atom_name( selection_data->target ); // char *name = gdk_atom_name( selection_data->target );
// if (name) printf( "Format requested: %s.\n", name ); // if (name) printf( "Format requested: %s.\n", name );
wxNode *node = drop_source->m_data->m_dataObjects.First(); drop_source->m_retValue = wxDragCancel;
while (node)
wxDataObject *data = drop_source->m_data;
if (!data)
return;
if (!data->IsSupportedFormat(selection_data->target))
return;
if (data->GetDataSize(selection_data->target) == 0)
return;
size_t size = data->GetDataSize(selection_data->target);
// printf( "data size: %d.\n", (int)data_size );
guchar *d = new guchar[size];
if (!data->GetDataHere( selection_data->target, (void*)d ))
{ {
wxDataObject *data_object = (wxDataObject*) node->Data(); free( d );
if (data_object->GetFormat().GetAtom() == selection_data->target) return;
{ }
// printf( "format found.\n" );
size_t data_size = data_object->GetSize();
if (data_size > 0)
{
// printf( "data size: %d.\n", (int)data_size );
guchar *buffer = new guchar[data_size];
data_object->WriteData( buffer );
#if wxUSE_THREADS #if wxUSE_THREADS
/* disable GUI threads */ /* disable GUI threads */
wxapp_uninstall_thread_wakeup(); wxapp_uninstall_thread_wakeup();
#endif #endif
gtk_selection_data_set( selection_data, gtk_selection_data_set( selection_data,
selection_data->target, selection_data->target,
8, // 8-bit 8, // 8-bit
buffer, d,
data_size ); size );
#if wxUSE_THREADS #if wxUSE_THREADS
/* enable GUI threads */ /* enable GUI threads */
wxapp_install_thread_wakeup(); wxapp_install_thread_wakeup();
#endif #endif
free( buffer );
/* so far only copy, no moves. TODO. */ free( d );
drop_source->m_retValue = wxDragCopy;
/* so far only copy, no moves. TODO. */
return; drop_source->m_retValue = wxDragCopy;
}
}
node = node->Next();
}
drop_source->m_retValue = wxDragCancel;
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@@ -733,7 +735,7 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
m_widget = win->m_widget; m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_data = (wxDataBroker*) NULL; m_data = (wxDataObject*) NULL;
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
@@ -755,8 +757,7 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel; m_retValue = wxDragCancel;
m_data = new wxDataBroker; m_data = &data;
m_data->Add(&data);
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND ); m_goaheadCursor = wxCursor( wxCURSOR_HAND );
@@ -767,53 +768,18 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win,
if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm );
} }
wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
{
m_window = win;
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
m_data = data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
}
void wxDropSource::SetData( wxDataObject& data ) void wxDropSource::SetData( wxDataObject& data )
{ {
if ( m_data ) if (m_data)
delete m_data; delete m_data;
m_data = new wxDataBroker; m_data = &data;
m_data->Add(&data);
}
void wxDropSource::SetData( wxDataObject *data )
{
if (m_data) delete m_data;
if (data)
{
m_data = new wxDataBroker();
m_data->Add( data );
}
else
{
m_data = (wxDataBroker*) NULL;
}
}
void wxDropSource::SetData( wxDataBroker *data )
{
if (m_data) delete m_data;
m_data = data;
} }
wxDropSource::~wxDropSource() wxDropSource::~wxDropSource()
{ {
if (m_data) delete m_data; if (m_data)
// delete m_data;
g_blockEventsOnDrag = FALSE; g_blockEventsOnDrag = FALSE;
} }