#
-# 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!
#
GTK_COMMONOBJS = \
parser.o \
+ appcmn.o \
+ choiccmn.o \
cmndata.o \
config.o \
+ ctrlcmn.o \
date.o \
datstrm.o \
db.o \
GTK_COMMONDEPS = \
parser.d \
+ appcmn.d \
+ choiccmn.d \
cmndata.d \
config.d \
+ ctrlcmn.d \
date.d \
datstrm.d \
db.d \
MOTIF_COMMONOBJS = \
parser.o \
+ appcmn.o \
choiccmn.o \
cmndata.o \
config.o \
MOTIF_COMMONDEPS = \
parser.d \
+ appcmn.d \
choiccmn.d \
cmndata.d \
config.d \
MSW_COMMONOBJS = \
parser.o \
+ appcmn.o \
choiccmn.o \
cmndata.o \
config.o \
MSW_COMMONDEPS = \
parser.d \
+ appcmn.d \
choiccmn.d \
cmndata.d \
config.d \
BASE_OBJS = \
init.o \
+ appcmn.o \
config.o \
date.o \
dynarray.o \
BASE_DEPS = \
init.d \
+ appcmn.d \
config.d \
date.d \
dynarray.d \
class WXDLLEXPORT wxPrivateDataObject : public wxDataObject
{
#if defined(__WXGTK__) || defined(__WXMOTIF__)
- DECLARE_DYNAMIC_CLASS( wxPrivateDataObject )
+ DECLARE_CLASS( wxPrivateDataObject )
#endif
public:
size_t m_size;
void *m_data;
-#if !defined(__WXGTK__) && !defined(__WXMOTIF__)
+#if !defined(__WXMOTIF__)
// the data format
wxDataFormat m_format;
#endif
virtual wxCoord GetCharHeight() const = 0;
virtual wxCoord GetCharWidth() const = 0;
+
void GetTextExtent(const wxString& string,
wxCoord *x, wxCoord *y,
wxCoord *descent = NULL,
if ( y )
*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
#if WXWIN_COMPATIBILITY
bool Leaving() const { return (m_eventType == wxEVT_LEAVE_WINDOW); }
// Find the position of the event
- void GetPosition(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; }
- void Position(long *xpos, long *ypos) const { *xpos = m_x; *ypos = m_y; }
+ void GetPosition(long *xpos, long *ypos) const
+ { 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
wxPoint GetPosition() const { return wxPoint(m_x, m_y); }
// Find the position of the event
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
{ return wxPoint(m_x, m_y); }
// clears wxTheClipboard and the system's clipboard if possible
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,
/// primary=FALSE resets it.
inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; }
- // implementation
-
+ // implementation
bool m_open;
-
bool m_ownsClipboard;
bool m_ownsPrimarySelection;
+ wxDataObject *m_data;
- wxDataBroker *m_dataBroker;
GtkWidget *m_clipboardWidget; /* for getting and offering data */
GtkWidget *m_targetsWidget; /* for getting list of supported formats */
bool m_waiting; /* querying data or formats is asynchronous */
class wxFileDataObject;
//-------------------------------------------------------------------------
-// wxDataFormat (internal)
+// wxDataFormat
//-------------------------------------------------------------------------
-class wxDataFormat : public wxObject
+class wxDataFormat
{
public:
+ // the clipboard formats under GDK are GdkAtoms
+ typedef GdkAtom NativeFormat;
+
wxDataFormat();
wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id );
- wxDataFormat( const wxDataFormat &format );
- wxDataFormat( const GdkAtom atom );
-
- void SetType( wxDataFormatId type );
- wxDataFormatId GetType() const;
+ wxDataFormat( NativeFormat format );
+
+ wxDataFormat& operator=(NativeFormat format)
+ { SetId(format); return *this; }
+ wxDataFormat& operator=(const wxDataFormat& format)
+ { SetId(format); return *this; }
+
+ // comparison (must have both versions)
+ bool operator==(wxDataFormatId type) const
+ { return m_type == (wxDataFormatId)type; }
+ bool operator!=(wxDataFormatId type) const
+ { return m_type != (wxDataFormatId)type; }
+ bool operator==(NativeFormat format) const
+ { return m_format == (NativeFormat)format; }
+ bool operator!=(NativeFormat format) const
+ { return m_format != (NativeFormat)format; }
+ bool operator==(const wxDataFormat& format) const
+ { return m_format == format.m_format; }
+ bool operator!=(const wxDataFormat& format) const
+ { return m_format != format.m_format; }
+
+ // explicit and implicit conversions to NativeFormat which is one of
+ // standard data types (implicit conversion is useful for preserving the
+ // compatibility with old code)
+ NativeFormat GetFormatId() const { return m_format; }
+ operator NativeFormat() const { return m_format; }
+
+ // this only works with standard ids
+ void SetId( wxDataFormatId type );
- /* the string Id identifies the format of clipboard or DnD data. a word
- * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
- * to the clipboard - the latter with the Id "application/wxword", an
- * image manipulation program would put a wxBitmapDataObject and a
- * wxPrivateDataObject to the clipboard - the latter with "image/png". */
+ // 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;
void SetId( const wxChar *id );
- GdkAtom GetAtom();
- void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
-
- // implicit conversion to wxDataFormatId
- operator wxDataFormatId() const { return m_type; }
-
- bool operator==(wxDataFormatId type) const { return m_type == type; }
- bool operator!=(wxDataFormatId type) const { return m_type != type; }
+ // implementation
+ wxDataFormatId GetType() const;
private:
- wxDataFormatId m_type;
- wxString m_id;
- bool m_hasAtom;
- GdkAtom m_atom;
+ wxDataFormatId m_type;
+ NativeFormat m_format;
void PrepareFormats();
-
-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 )
+ void SetType( wxDataFormatId type );
};
//----------------------------------------------------------------------------
-// wxDataObject to be placed in wxDataBroker
+// wxDataObject
//----------------------------------------------------------------------------
class wxDataObject : public wxObject
{
public:
- /* constructor */
wxDataObject();
-
- /* destructor */
~wxDataObject();
-
- /* write data to dest */
- virtual void WriteData( void *dest ) const = 0;
-
- /* get size of data */
- virtual size_t GetSize() const = 0;
-
-public:
- /* 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;
+
+ // a simpler name which makes more sense for data objects supporting
+ // only one format
+ wxDataFormat GetFormat() const { return GetPreferredFormat(); }
- wxDataFormatId GetFormatType() const;
- wxString GetFormatId() const;
- GdkAtom GetFormatAtom() const;
+ // old interface
+ // decide if we support this format (can be either standard or custom
+ // format) -- now uses GetAllFormats()
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const;
private:
DECLARE_DYNAMIC_CLASS( wxDataObject )
class wxTextDataObject : public wxDataObject
{
public:
- /* default constructor. call SetText() later or override
- WriteData() and GetSize() for working on-demand */
+ // ctors
wxTextDataObject();
-
- /* constructor */
- wxTextDataObject( const wxString& data );
-
- /* set current text data */
- void SetText( const wxString& data );
-
- /* get current text data */
- wxString GetText() const;
-
- /* by default calls WriteString() with string set by constructor or
- by SetText(). can be overridden for working on-demand */
- virtual void WriteData( void *dest ) const;
-
- /* by default, returns length of string as set by constructor or
- by SetText(). can be overridden for working on-demand */
- virtual size_t GetSize() const;
-
- /* write string to dest */
- void WriteString( const wxString &str, void *dest ) const;
-
-public:
- /* implementation */
- wxString m_data;
+ wxTextDataObject(const wxString& strText);
+ void Init(const wxString& strText) { m_strText = strText; }
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_TEXT; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_TEXT; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
+
+ // additional helpers
+ void SetText(const wxString& strText) { m_strText = strText; }
+ wxString GetText() const { return m_strText; }
+private:
+ wxString m_strText;
+
private:
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
};
class wxFileDataObject : public wxDataObject
{
public:
- /* default constructor */
wxFileDataObject();
-
- /* add file name to list */
+
void AddFile( const wxString &file );
-
- /* get all filename as one string. each file name is 0 terminated,
- the list is double zero terminated */
wxString GetFiles() const;
-
- /* write list of filenames */
- virtual void WriteData( void *dest ) const;
-
- /* return length of list of filenames */
- virtual size_t GetSize() const;
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_FILENAME; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_FILENAME; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
public:
- /* implementation */
wxString m_files;
private:
class wxBitmapDataObject : public wxDataObject
{
public:
- /* see wxTextDataObject for explanation */
+ // ctors
wxBitmapDataObject();
- wxBitmapDataObject( const wxBitmap& bitmap );
- ~wxBitmapDataObject();
-
- void SetBitmap( const wxBitmap &bitmap );
- wxBitmap GetBitmap() const;
+ wxBitmapDataObject(const wxBitmap& bitmap);
- 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;
+ // destr
+ ~wxBitmapDataObject();
- 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:
wxBitmap m_bitmap;
size_t m_pngSize;
- char *m_pngData;
+ void *m_pngData;
void DoConvertToPng();
// wxPrivateDropTarget
//-------------------------------------------------------------------------
+/*
class wxPrivateDropTarget: public wxDropTarget
{
public:
- /* sets id to "application/myprogram" where "myprogram" is the
- same as wxApp->GetAppName() */
wxPrivateDropTarget();
- /* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( 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;
- /* 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; }
wxString GetId() { return m_id; }
wxString m_id;
};
+*/
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
virtual bool OnDrop( 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;
-
};
//-------------------------------------------------------------------------
/* constructor. set data later with SetData() */
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 );
-
- /* constructor for setting several data objects via wxDataBroker */
- wxDropSource( wxDataBroker *data, wxWindow *win );
-
~wxDropSource();
- /* set several dataobjects via wxDataBroker */
- void SetData( wxDataBroker *data );
-
- /* set one dataobject */
void SetData( wxDataObject& data );
- // this one isn't portable to wxMSW -- deprecated
- void SetData( wxDataObject *data );
-
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
- wxDataBroker *m_data;
+ wxDataObject *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
// clears wxTheClipboard and the system's clipboard if possible
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,
/// primary=FALSE resets it.
inline void UsePrimarySelection(bool primary = TRUE) { m_usePrimary = primary; }
- // implementation
-
+ // implementation
bool m_open;
-
bool m_ownsClipboard;
bool m_ownsPrimarySelection;
+ wxDataObject *m_data;
- wxDataBroker *m_dataBroker;
GtkWidget *m_clipboardWidget; /* for getting and offering data */
GtkWidget *m_targetsWidget; /* for getting list of supported formats */
bool m_waiting; /* querying data or formats is asynchronous */
class wxFileDataObject;
//-------------------------------------------------------------------------
-// wxDataFormat (internal)
+// wxDataFormat
//-------------------------------------------------------------------------
-class wxDataFormat : public wxObject
+class wxDataFormat
{
public:
+ // the clipboard formats under GDK are GdkAtoms
+ typedef GdkAtom NativeFormat;
+
wxDataFormat();
wxDataFormat( wxDataFormatId type );
wxDataFormat( const wxString &id );
wxDataFormat( const wxChar *id );
- wxDataFormat( const wxDataFormat &format );
- wxDataFormat( const GdkAtom atom );
-
- void SetType( wxDataFormatId type );
- wxDataFormatId GetType() const;
+ wxDataFormat( NativeFormat format );
+
+ wxDataFormat& operator=(NativeFormat format)
+ { SetId(format); return *this; }
+ wxDataFormat& operator=(const wxDataFormat& format)
+ { SetId(format); return *this; }
+
+ // comparison (must have both versions)
+ bool operator==(wxDataFormatId type) const
+ { return m_type == (wxDataFormatId)type; }
+ bool operator!=(wxDataFormatId type) const
+ { return m_type != (wxDataFormatId)type; }
+ bool operator==(NativeFormat format) const
+ { return m_format == (NativeFormat)format; }
+ bool operator!=(NativeFormat format) const
+ { return m_format != (NativeFormat)format; }
+ bool operator==(const wxDataFormat& format) const
+ { return m_format == format.m_format; }
+ bool operator!=(const wxDataFormat& format) const
+ { return m_format != format.m_format; }
+
+ // explicit and implicit conversions to NativeFormat which is one of
+ // standard data types (implicit conversion is useful for preserving the
+ // compatibility with old code)
+ NativeFormat GetFormatId() const { return m_format; }
+ operator NativeFormat() const { return m_format; }
+
+ // this only works with standard ids
+ void SetId( wxDataFormatId type );
- /* the string Id identifies the format of clipboard or DnD data. a word
- * processor would e.g. add a wxTextDataObject and a wxPrivateDataObject
- * to the clipboard - the latter with the Id "application/wxword", an
- * image manipulation program would put a wxBitmapDataObject and a
- * wxPrivateDataObject to the clipboard - the latter with "image/png". */
+ // 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;
void SetId( const wxChar *id );
- GdkAtom GetAtom();
- void SetAtom(GdkAtom atom) { m_hasAtom = TRUE; m_atom = atom; }
-
- // implicit conversion to wxDataFormatId
- operator wxDataFormatId() const { return m_type; }
-
- bool operator==(wxDataFormatId type) const { return m_type == type; }
- bool operator!=(wxDataFormatId type) const { return m_type != type; }
+ // implementation
+ wxDataFormatId GetType() const;
private:
- wxDataFormatId m_type;
- wxString m_id;
- bool m_hasAtom;
- GdkAtom m_atom;
+ wxDataFormatId m_type;
+ NativeFormat m_format;
void PrepareFormats();
-
-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 )
+ void SetType( wxDataFormatId type );
};
//----------------------------------------------------------------------------
-// wxDataObject to be placed in wxDataBroker
+// wxDataObject
//----------------------------------------------------------------------------
class wxDataObject : public wxObject
{
public:
- /* constructor */
wxDataObject();
-
- /* destructor */
~wxDataObject();
-
- /* write data to dest */
- virtual void WriteData( void *dest ) const = 0;
-
- /* get size of data */
- virtual size_t GetSize() const = 0;
-
-public:
- /* 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;
+
+ // a simpler name which makes more sense for data objects supporting
+ // only one format
+ wxDataFormat GetFormat() const { return GetPreferredFormat(); }
- wxDataFormatId GetFormatType() const;
- wxString GetFormatId() const;
- GdkAtom GetFormatAtom() const;
+ // old interface
+ // decide if we support this format (can be either standard or custom
+ // format) -- now uses GetAllFormats()
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const;
private:
DECLARE_DYNAMIC_CLASS( wxDataObject )
class wxTextDataObject : public wxDataObject
{
public:
- /* default constructor. call SetText() later or override
- WriteData() and GetSize() for working on-demand */
+ // ctors
wxTextDataObject();
-
- /* constructor */
- wxTextDataObject( const wxString& data );
-
- /* set current text data */
- void SetText( const wxString& data );
-
- /* get current text data */
- wxString GetText() const;
-
- /* by default calls WriteString() with string set by constructor or
- by SetText(). can be overridden for working on-demand */
- virtual void WriteData( void *dest ) const;
-
- /* by default, returns length of string as set by constructor or
- by SetText(). can be overridden for working on-demand */
- virtual size_t GetSize() const;
-
- /* write string to dest */
- void WriteString( const wxString &str, void *dest ) const;
-
-public:
- /* implementation */
- wxString m_data;
+ wxTextDataObject(const wxString& strText);
+ void Init(const wxString& strText) { m_strText = strText; }
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_TEXT; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_TEXT; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
+
+ // additional helpers
+ void SetText(const wxString& strText) { m_strText = strText; }
+ wxString GetText() const { return m_strText; }
+private:
+ wxString m_strText;
+
private:
DECLARE_DYNAMIC_CLASS( wxTextDataObject )
};
class wxFileDataObject : public wxDataObject
{
public:
- /* default constructor */
wxFileDataObject();
-
- /* add file name to list */
+
void AddFile( const wxString &file );
-
- /* get all filename as one string. each file name is 0 terminated,
- the list is double zero terminated */
wxString GetFiles() const;
-
- /* write list of filenames */
- virtual void WriteData( void *dest ) const;
-
- /* return length of list of filenames */
- virtual size_t GetSize() const;
+
+ virtual wxDataFormat GetPreferredFormat() const
+ { return wxDF_FILENAME; }
+ virtual bool IsSupportedFormat(const wxDataFormat& format) const
+ { return format == wxDF_FILENAME; }
+
+ virtual size_t GetDataSize(const wxDataFormat& format) const;
+ virtual bool GetDataHere(const wxDataFormat& format, void *buf) const;
+ virtual bool SetData(const wxDataFormat& format, const void *buf);
public:
- /* implementation */
wxString m_files;
private:
class wxBitmapDataObject : public wxDataObject
{
public:
- /* see wxTextDataObject for explanation */
+ // ctors
wxBitmapDataObject();
- wxBitmapDataObject( const wxBitmap& bitmap );
- ~wxBitmapDataObject();
-
- void SetBitmap( const wxBitmap &bitmap );
- wxBitmap GetBitmap() const;
+ wxBitmapDataObject(const wxBitmap& bitmap);
- 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;
+ // destr
+ ~wxBitmapDataObject();
- 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:
wxBitmap m_bitmap;
size_t m_pngSize;
- char *m_pngData;
+ void *m_pngData;
void DoConvertToPng();
// wxPrivateDropTarget
//-------------------------------------------------------------------------
+/*
class wxPrivateDropTarget: public wxDropTarget
{
public:
- /* sets id to "application/myprogram" where "myprogram" is the
- same as wxApp->GetAppName() */
wxPrivateDropTarget();
- /* see SetId() below for explanation */
wxPrivateDropTarget( const wxString &id );
virtual bool OnMove( long x, long y );
virtual bool OnDrop( 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;
- /* 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; }
wxString GetId() { return m_id; }
wxString m_id;
};
+*/
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
virtual bool OnDrop( 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;
-
};
//-------------------------------------------------------------------------
/* constructor. set data later with SetData() */
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 );
-
- /* constructor for setting several data objects via wxDataBroker */
- wxDropSource( wxDataBroker *data, wxWindow *win );
-
~wxDropSource();
- /* set several dataobjects via wxDataBroker */
- void SetData( wxDataBroker *data );
-
- /* set one dataobject */
void SetData( wxDataObject& data );
- // this one isn't portable to wxMSW -- deprecated
- void SetData( wxDataObject *data );
-
/* start drag action */
wxDragResult DoDragDrop( bool bAllowMove = FALSE );
GtkWidget *m_widget;
wxWindow *m_window;
wxDragResult m_retValue;
- wxDataBroker *m_data;
+ wxDataObject *m_data;
wxCursor m_defaultCursor;
wxCursor m_goaheadCursor;
// to implement in derived classes
virtual Kind GetKind() const = 0;
- virtual void Draw(wxDC& dc) = 0
+ virtual void Draw(wxDC& dc)
{
dc.SetPen(wxPen(m_col, 1, wxSOLID));
}
dc.DrawLine(p2, p3);
dc.DrawLine(p3, p1);
+#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
+#endif
}
};
dc.DrawLine(p3, p4);
dc.DrawLine(p4, p1);
+#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
+#endif
}
};
dc.DrawEllipse(m_pos, m_size);
+#ifdef __WXMSW__
dc.FloodFill(GetCentre(), m_col, wxFLOOD_BORDER);
+#endif
}
};
wxTE_MULTILINE | wxTE_READONLY |
wxSUNKEN_BORDER );
+#ifdef __WXMSW__
// redirect log messages to the text window and switch on OLE messages
// logging
wxLog::AddTraceMask(wxTRACE_OleCalls);
+#endif
m_pLog = new wxLogTextCtrl(m_ctrlLog);
m_pLogPrev = wxLog::SetActiveTarget(m_pLog);
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 (atoms[i] == clipboard->m_targetRequested)
}
wxDataObject *data_object = clipboard->m_receivedData;
-
+
if (!data_object)
{
clipboard->m_waiting = FALSE;
}
/* 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;
return;
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;
}
(!wxTheClipboard->m_ownsClipboard))
{
/* 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;
- wxTheClipboard->m_dataBroker = (wxDataBroker*) NULL;
+ delete wxTheClipboard->m_data;
+ wxTheClipboard->m_data = (wxDataObject*) NULL;
}
}
{
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();
-
- 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();
-
+ wxTextDataObject *text_object = (wxTextDataObject*) data;
+ wxString text( text_object->GetText() );
+
#if wxUSE_UNICODE
- const wxWX2MBbuf s = text.mbc_str();
- int len = strlen(s);
+ const wxWX2MBbuf s = text.mbc_str();
+ int len = strlen(s);
#else // more efficient in non-Unicode
- const char *s = text.c_str();
- int len = (int) text.Length();
+ const char *s = text.c_str();
+ int len = (int) text.Length();
#endif
-
- gtk_selection_data_set(
- selection_data,
- GDK_SELECTION_TYPE_STRING,
- 8*sizeof(gchar),
- (unsigned char*) (const char*) s,
- len );
+ gtk_selection_data_set(
+ selection_data,
+ GDK_SELECTION_TYPE_STRING,
+ 8*sizeof(gchar),
+ (unsigned char*) (const char*) s,
+ len );
- break;
- }
-
- 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;
+ return;
+ }
+
+ if (data->GetFormat().GetType() == wxDF_BITMAP)
+ {
+ wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
- if (private_object->GetSize() == 0) return;
+ if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
- gtk_selection_data_set(
- selection_data,
- GDK_SELECTION_TYPE_STRING,
- 8*sizeof(gchar),
- (unsigned char*) private_object->GetData(),
- (int) private_object->GetSize() );
- }
+ gtk_selection_data_set(
+ selection_data,
+ GDK_SELECTION_TYPE_STRING,
+ 8*sizeof(gchar),
+ (unsigned char*) bitmap_object->GetData(),
+ (int) bitmap_object->GetDataSize(wxDF_BITMAP) );
- default:
- break;
- }
-
- node = node->Next();
+ 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 );
}
//-----------------------------------------------------------------------------
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
- m_dataBroker = (wxDataBroker*) NULL;
-
+ m_data = (wxDataObject*) NULL;
m_receivedData = (wxDataObject*) NULL;
/* we use m_targetsWidget to query what formats are available */
void wxClipboard::Clear()
{
- if (m_dataBroker)
- {
+ if (m_data)
+ {
#if wxUSE_THREADS
/* disable GUI threads */
wxapp_uninstall_thread_wakeup();
while (m_waiting) gtk_main_iteration();
}
- if (m_dataBroker)
- {
- delete m_dataBroker;
- m_dataBroker = (wxDataBroker*) NULL;
+ if (m_data)
+ {
+ delete m_data;
+ m_data = (wxDataObject*) NULL;
}
#if wxUSE_THREADS
}
m_targetRequested = 0;
-
m_formatSupported = FALSE;
}
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
- /* if clipboard has been cleared before, create new data broker */
- if (!m_dataBroker) m_dataBroker = new wxDataBroker();
+ // we can only store one wxDataObject
+ Clear();
- /* add new data to list of offered data objects */
- m_dataBroker->Add( data );
-
+ m_data = data;
+
/* 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") );
bool wxClipboard::IsSupported( wxDataFormat format )
{
- wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
-
/* 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") );
m_waiting = TRUE;
gtk_selection_convert( m_targetsWidget,
- m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
g_targetsAtom,
GDK_CURRENT_TIME );
/* 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") );
m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget,
- m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested,
GDK_CURRENT_TIME );
GdkAtom g_textAtom = 0;
GdkAtom g_pngAtom = 0;
+GdkAtom g_fileAtom = 0;
//-------------------------------------------------------------------------
// wxDataFormat
//-------------------------------------------------------------------------
-IMPLEMENT_CLASS(wxDataFormat, wxObject)
-
wxDataFormat::wxDataFormat()
{
PrepareFormats();
m_type = wxDF_INVALID;
- m_hasAtom = FALSE;
- m_atom = (GdkAtom) 0;
+ m_format = (GdkAtom) 0;
}
wxDataFormat::wxDataFormat( wxDataFormatId type )
SetId( id );
}
-wxDataFormat::wxDataFormat( const wxDataFormat &format )
-{
- PrepareFormats();
- m_type = format.GetType();
- m_id = format.GetId();
- m_hasAtom = TRUE;
- m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
-}
-
-wxDataFormat::wxDataFormat( const GdkAtom atom )
+wxDataFormat::wxDataFormat( NativeFormat format )
{
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;
- }
- }
+ SetId( format );
}
void wxDataFormat::SetType( wxDataFormatId type )
m_type = type;
if (m_type == wxDF_TEXT)
- {
- m_id = wxT("STRING");
- }
+ m_format = g_textAtom;
else
if (m_type == wxDF_BITMAP)
- {
- m_id = wxT("image/png");
- }
+ m_format = g_pngAtom;
else
if (m_type == wxDF_FILENAME)
- {
- m_id = wxT("file:ALL");
- }
+ m_format = g_fileAtom;
else
{
wxFAIL_MSG( wxT("invalid dataformat") );
}
-
- m_hasAtom = FALSE;
}
wxDataFormatId wxDataFormat::GetType() const
wxString wxDataFormat::GetId() const
{
- return m_id;
-}
-
-void wxDataFormat::SetId( const wxChar *id )
-{
- m_type = wxDF_PRIVATE;
- m_id = id;
- m_hasAtom = FALSE;
-}
-
-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()
-{
- if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
- if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE );
-}
-
-//-------------------------------------------------------------------------
-// wxDataBroker
-//-------------------------------------------------------------------------
-
-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();
+ wxString ret( gdk_atom_name( m_format ) ); // this will convert from ascii to Unicode
+ return ret;
}
-bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
+void wxDataFormat::SetId( NativeFormat format )
{
- wxNode *node = m_dataObjects.First();
- while (node)
- {
- wxDataObject *dobj = (wxDataObject*)node->Data();
-
- if (dobj->GetFormat().GetAtom() == format.GetAtom())
- {
- return TRUE;
- }
-
- node = node->Next();
- }
+ m_format = format;
- return FALSE;
+ 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;
}
-size_t wxDataBroker::GetSize( wxDataFormat& format ) const
+void wxDataFormat::SetId( const wxChar *id )
{
- 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;
+ m_type = wxDF_PRIVATE;
+ wxString tmp( id );
+ m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
}
-void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
+void wxDataFormat::PrepareFormats()
{
- wxNode *node = m_dataObjects.First();
- while (node)
- {
- wxDataObject *dobj = (wxDataObject*)node->Data();
-
- if (dobj->GetFormat().GetAtom() == format.GetAtom())
- {
- dobj->WriteData( dest );
- }
-
- node = node->Next();
- }
+ if (!g_textAtom)
+ g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ if (!g_pngAtom)
+ g_pngAtom = gdk_atom_intern( "image/png", FALSE );
+ if (!g_fileAtom)
+ g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
}
//-------------------------------------------------------------------------
{
}
-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;
+ }
-wxDataFormatId wxDataObject::GetFormatType() const
-{
- return m_format.GetType();
-}
+ delete [] formats;
-wxString wxDataObject::GetFormatId() const
-{
- return m_format.GetId();
+ // found?
+ return n < nFormatCount;
+ }
}
-GdkAtom wxDataObject::GetFormatAtom() const
-{
- GdkAtom ret = ((wxDataObject*) this)->m_format.GetAtom();
- return ret;
-}
// ----------------------------------------------------------------------------
// wxTextDataObject
IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
-wxTextDataObject::wxTextDataObject()
-{
- m_format.SetType( wxDF_TEXT );
-}
-
-wxTextDataObject::wxTextDataObject( const wxString& data )
-{
- m_format.SetType( wxDF_TEXT );
-
- m_data = data;
+wxTextDataObject::wxTextDataObject()
+{
}
-void wxTextDataObject::SetText( const wxString& data )
-{
- m_data = data;
+wxTextDataObject::wxTextDataObject(const wxString& strText)
+ : m_strText(strText)
+{
}
-wxString wxTextDataObject::GetText() const
-{
- return m_data;
+size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
+{
+ return m_strText.Len() + 1; // +1 for trailing '\0'of course
}
-void wxTextDataObject::WriteData( void *dest ) const
-{
- WriteString( m_data, dest );
+bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+{
+ memcpy(buf, m_strText.c_str(), GetDataSize(format));
+ 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 );
+bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
+{
+ m_strText = (const wxChar *)buf;
+ return TRUE;
}
// ----------------------------------------------------------------------------
wxFileDataObject::wxFileDataObject()
{
- m_format.SetType( wxDF_FILENAME );
}
void wxFileDataObject::AddFile( const wxString &file )
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;
}
+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::wxBitmapDataObject()
{
- m_format.SetType( wxDF_BITMAP );
- m_pngData = (char*)NULL;
+ m_pngData = (void*)NULL;
m_pngSize = 0;
}
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
{
- m_format.SetType( wxDF_BITMAP );
- m_pngData = (char*)NULL;
+ m_pngData = (void*)NULL;
m_pngSize = 0;
m_bitmap = bitmap;
DoConvertToPng();
wxBitmapDataObject::~wxBitmapDataObject()
{
- if (m_pngData) delete[] m_pngData;
+ if (m_pngData)
+ delete[] m_pngData;
}
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
{
+ if (m_pngData)
+ delete[] m_pngData;
+ m_pngData = (void*)NULL;
+ m_pngSize = 0;
+
m_bitmap = bitmap;
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 );
+ if (format != wxDF_BITMAP) return 0;
+
+ return m_pngSize;
}
-size_t wxBitmapDataObject::GetSize() const
+bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{
- return m_pngSize;
+ if (format != wxDF_BITMAP) return FALSE;
+
+ if (m_pngSize > 0)
+ {
+ memcpy(buf, m_pngData, m_pngSize);
+ return TRUE;
+ }
+
+ return FALSE;
}
-void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const
+bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
{
-// if (m_bitmap == bitmap)
- memcpy( dest, m_pngData, m_pngSize );
+ if (m_pngData) delete[] m_pngData;
+ m_pngData = (void*) NULL;
+ m_pngSize = 0;
+ m_bitmap = wxNullBitmap;
+
+ return FALSE;
}
-void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
+void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
{
if (m_pngData) delete[] m_pngData;
- m_pngData = (char*) NULL;
- m_pngSize = pngSize;
- m_pngData = new char[m_pngSize];
- memcpy( m_pngData, pngData, m_pngSize );
+ m_pngSize = size;
+ m_pngData = (void*) new char[m_pngSize];
- wxMemoryInputStream mstream( pngData, pngSize );
+ memcpy( m_pngData, buf, m_pngSize );
+
+ wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
wxImage image;
wxPNGHandler handler;
handler.LoadFile( &image, mstream );
void wxBitmapDataObject::DoConvertToPng()
{
- if (m_pngData) delete[] m_pngData;
+ if (!m_bitmap.Ok()) return;
wxImage image( m_bitmap );
wxPNGHandler handler;
wxCountingOutputStream count;
handler.SaveFile( &image, count );
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
- m_pngData = new char[m_pngSize];
+ m_pngData = (void*) new char[m_pngSize];
- wxMemoryOutputStream mstream( m_pngData, m_pngSize );
+ wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
handler.SaveFile( &image, mstream );
}
// wxPrivateDataObject
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
+IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free()
{
/* this should trigger an "drag_data_received" event */
gtk_drag_get_data( m_dragWidget,
m_dragContext,
- format.GetAtom(),
+ format,
m_dragTime );
#if wxUSE_THREADS
// char *name = gdk_atom_name( formatAtom );
// if (name) printf( "Format available: %s.\n", name );
- if (formatAtom == format.GetAtom()) return TRUE;
+ if (formatAtom == format) return TRUE;
child = child->next;
}
{
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)
{
// wxPrivateDropTarget
//-------------------------------------------------------------------------
+/*
wxPrivateDropTarget::wxPrivateDropTarget()
{
m_id = wxTheApp->GetAppName();
return TRUE;
}
+*/
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
wxFileDataObject data;
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 i;
size_t size = data.GetFiles().Length();
// char *name = gdk_atom_name( selection_data->target );
// if (name) printf( "Format requested: %s.\n", name );
- wxNode *node = drop_source->m_data->m_dataObjects.First();
- while (node)
- {
- wxDataObject *data_object = (wxDataObject*) node->Data();
- if (data_object->GetFormat().GetAtom() == selection_data->target)
- {
-// printf( "format found.\n" );
+ drop_source->m_retValue = wxDragCancel;
+
+ wxDataObject *data = drop_source->m_data;
+
+ if (!data)
+ return;
+
+ if (!data->IsSupportedFormat(selection_data->target))
+ return;
- size_t data_size = data_object->GetSize();
+ if (data->GetDataSize(selection_data->target) == 0)
+ return;
+
+ size_t size = data->GetDataSize(selection_data->target);
- if (data_size > 0)
- {
-// printf( "data size: %d.\n", (int)data_size );
+// printf( "data size: %d.\n", (int)data_size );
- guchar *buffer = new guchar[data_size];
- data_object->WriteData( buffer );
+ guchar *d = new guchar[size];
+
+ if (!data->GetDataHere( selection_data->target, (void*)d ))
+ {
+ free( d );
+ return;
+ }
#if wxUSE_THREADS
- /* disable GUI threads */
- wxapp_uninstall_thread_wakeup();
+ /* disable GUI threads */
+ wxapp_uninstall_thread_wakeup();
#endif
gtk_selection_data_set( selection_data,
selection_data->target,
8, // 8-bit
- buffer,
- data_size );
+ d,
+ size );
#if wxUSE_THREADS
- /* enable GUI threads */
- wxapp_install_thread_wakeup();
+ /* enable GUI threads */
+ wxapp_install_thread_wakeup();
#endif
- free( buffer );
- /* so far only copy, no moves. TODO. */
- drop_source->m_retValue = wxDragCopy;
-
- return;
- }
- }
-
- node = node->Next();
- }
-
- drop_source->m_retValue = wxDragCancel;
+ free( d );
+
+ /* so far only copy, no moves. TODO. */
+ drop_source->m_retValue = wxDragCopy;
}
//----------------------------------------------------------------------------
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
- m_data = (wxDataBroker*) NULL;
+ m_data = (wxDataObject*) NULL;
m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
- m_data = new wxDataBroker;
- m_data->Add(&data);
+ m_data = &data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
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 )
{
- if ( m_data )
+ if (m_data)
delete m_data;
- m_data = new wxDataBroker;
- 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;
+ m_data = &data;
}
wxDropSource::~wxDropSource()
{
- if (m_data) delete m_data;
+ if (m_data)
+// delete m_data;
g_blockEventsOnDrag = FALSE;
}
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 (atoms[i] == clipboard->m_targetRequested)
}
wxDataObject *data_object = clipboard->m_receivedData;
-
+
if (!data_object)
{
clipboard->m_waiting = FALSE;
}
/* 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;
return;
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;
}
(!wxTheClipboard->m_ownsClipboard))
{
/* 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;
- wxTheClipboard->m_dataBroker = (wxDataBroker*) NULL;
+ delete wxTheClipboard->m_data;
+ wxTheClipboard->m_data = (wxDataObject*) NULL;
}
}
{
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();
-
- 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();
-
+ wxTextDataObject *text_object = (wxTextDataObject*) data;
+ wxString text( text_object->GetText() );
+
#if wxUSE_UNICODE
- const wxWX2MBbuf s = text.mbc_str();
- int len = strlen(s);
+ const wxWX2MBbuf s = text.mbc_str();
+ int len = strlen(s);
#else // more efficient in non-Unicode
- const char *s = text.c_str();
- int len = (int) text.Length();
+ const char *s = text.c_str();
+ int len = (int) text.Length();
#endif
-
- gtk_selection_data_set(
- selection_data,
- GDK_SELECTION_TYPE_STRING,
- 8*sizeof(gchar),
- (unsigned char*) (const char*) s,
- len );
+ gtk_selection_data_set(
+ selection_data,
+ GDK_SELECTION_TYPE_STRING,
+ 8*sizeof(gchar),
+ (unsigned char*) (const char*) s,
+ len );
- break;
- }
-
- 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;
+ return;
+ }
+
+ if (data->GetFormat().GetType() == wxDF_BITMAP)
+ {
+ wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data;
- if (private_object->GetSize() == 0) return;
+ if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return;
- gtk_selection_data_set(
- selection_data,
- GDK_SELECTION_TYPE_STRING,
- 8*sizeof(gchar),
- (unsigned char*) private_object->GetData(),
- (int) private_object->GetSize() );
- }
+ gtk_selection_data_set(
+ selection_data,
+ GDK_SELECTION_TYPE_STRING,
+ 8*sizeof(gchar),
+ (unsigned char*) bitmap_object->GetData(),
+ (int) bitmap_object->GetDataSize(wxDF_BITMAP) );
- default:
- break;
- }
-
- node = node->Next();
+ 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 );
}
//-----------------------------------------------------------------------------
m_ownsClipboard = FALSE;
m_ownsPrimarySelection = FALSE;
- m_dataBroker = (wxDataBroker*) NULL;
-
+ m_data = (wxDataObject*) NULL;
m_receivedData = (wxDataObject*) NULL;
/* we use m_targetsWidget to query what formats are available */
void wxClipboard::Clear()
{
- if (m_dataBroker)
- {
+ if (m_data)
+ {
#if wxUSE_THREADS
/* disable GUI threads */
wxapp_uninstall_thread_wakeup();
while (m_waiting) gtk_main_iteration();
}
- if (m_dataBroker)
- {
- delete m_dataBroker;
- m_dataBroker = (wxDataBroker*) NULL;
+ if (m_data)
+ {
+ delete m_data;
+ m_data = (wxDataObject*) NULL;
}
#if wxUSE_THREADS
}
m_targetRequested = 0;
-
m_formatSupported = FALSE;
}
wxCHECK_MSG( data, FALSE, wxT("data is invalid") );
- /* if clipboard has been cleared before, create new data broker */
- if (!m_dataBroker) m_dataBroker = new wxDataBroker();
+ // we can only store one wxDataObject
+ Clear();
- /* add new data to list of offered data objects */
- m_dataBroker->Add( data );
-
+ m_data = data;
+
/* 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") );
bool wxClipboard::IsSupported( wxDataFormat format )
{
- wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") );
-
/* 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") );
m_waiting = TRUE;
gtk_selection_convert( m_targetsWidget,
- m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
g_targetsAtom,
GDK_CURRENT_TIME );
/* 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") );
m_waiting = TRUE;
gtk_selection_convert( m_clipboardWidget,
- m_usePrimary?GDK_SELECTION_PRIMARY:g_clipboardAtom,
+ m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom,
m_targetRequested,
GDK_CURRENT_TIME );
GdkAtom g_textAtom = 0;
GdkAtom g_pngAtom = 0;
+GdkAtom g_fileAtom = 0;
//-------------------------------------------------------------------------
// wxDataFormat
//-------------------------------------------------------------------------
-IMPLEMENT_CLASS(wxDataFormat, wxObject)
-
wxDataFormat::wxDataFormat()
{
PrepareFormats();
m_type = wxDF_INVALID;
- m_hasAtom = FALSE;
- m_atom = (GdkAtom) 0;
+ m_format = (GdkAtom) 0;
}
wxDataFormat::wxDataFormat( wxDataFormatId type )
SetId( id );
}
-wxDataFormat::wxDataFormat( const wxDataFormat &format )
-{
- PrepareFormats();
- m_type = format.GetType();
- m_id = format.GetId();
- m_hasAtom = TRUE;
- m_atom = ((wxDataFormat &)format).GetAtom(); // const_cast
-}
-
-wxDataFormat::wxDataFormat( const GdkAtom atom )
+wxDataFormat::wxDataFormat( NativeFormat format )
{
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;
- }
- }
+ SetId( format );
}
void wxDataFormat::SetType( wxDataFormatId type )
m_type = type;
if (m_type == wxDF_TEXT)
- {
- m_id = wxT("STRING");
- }
+ m_format = g_textAtom;
else
if (m_type == wxDF_BITMAP)
- {
- m_id = wxT("image/png");
- }
+ m_format = g_pngAtom;
else
if (m_type == wxDF_FILENAME)
- {
- m_id = wxT("file:ALL");
- }
+ m_format = g_fileAtom;
else
{
wxFAIL_MSG( wxT("invalid dataformat") );
}
-
- m_hasAtom = FALSE;
}
wxDataFormatId wxDataFormat::GetType() const
wxString wxDataFormat::GetId() const
{
- return m_id;
-}
-
-void wxDataFormat::SetId( const wxChar *id )
-{
- m_type = wxDF_PRIVATE;
- m_id = id;
- m_hasAtom = FALSE;
-}
-
-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()
-{
- if (!g_textAtom) g_textAtom = gdk_atom_intern( "STRING", FALSE );
- if (!g_pngAtom) g_pngAtom = gdk_atom_intern( "image/png", FALSE );
-}
-
-//-------------------------------------------------------------------------
-// wxDataBroker
-//-------------------------------------------------------------------------
-
-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();
+ wxString ret( gdk_atom_name( m_format ) ); // this will convert from ascii to Unicode
+ return ret;
}
-bool wxDataBroker::IsSupportedFormat( wxDataFormat &format ) const
+void wxDataFormat::SetId( NativeFormat format )
{
- wxNode *node = m_dataObjects.First();
- while (node)
- {
- wxDataObject *dobj = (wxDataObject*)node->Data();
-
- if (dobj->GetFormat().GetAtom() == format.GetAtom())
- {
- return TRUE;
- }
-
- node = node->Next();
- }
+ m_format = format;
- return FALSE;
+ 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;
}
-size_t wxDataBroker::GetSize( wxDataFormat& format ) const
+void wxDataFormat::SetId( const wxChar *id )
{
- 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;
+ m_type = wxDF_PRIVATE;
+ wxString tmp( id );
+ m_format = gdk_atom_intern( wxMBSTRINGCAST tmp.mbc_str(), FALSE ); // what is the string cast for?
}
-void wxDataBroker::WriteData( wxDataFormat& format, void *dest ) const
+void wxDataFormat::PrepareFormats()
{
- wxNode *node = m_dataObjects.First();
- while (node)
- {
- wxDataObject *dobj = (wxDataObject*)node->Data();
-
- if (dobj->GetFormat().GetAtom() == format.GetAtom())
- {
- dobj->WriteData( dest );
- }
-
- node = node->Next();
- }
+ if (!g_textAtom)
+ g_textAtom = gdk_atom_intern( "STRING", FALSE );
+ if (!g_pngAtom)
+ g_pngAtom = gdk_atom_intern( "image/png", FALSE );
+ if (!g_fileAtom)
+ g_fileAtom = gdk_atom_intern( "file:ALL", FALSE );
}
//-------------------------------------------------------------------------
{
}
-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;
+ }
-wxDataFormatId wxDataObject::GetFormatType() const
-{
- return m_format.GetType();
-}
+ delete [] formats;
-wxString wxDataObject::GetFormatId() const
-{
- return m_format.GetId();
+ // found?
+ return n < nFormatCount;
+ }
}
-GdkAtom wxDataObject::GetFormatAtom() const
-{
- GdkAtom ret = ((wxDataObject*) this)->m_format.GetAtom();
- return ret;
-}
// ----------------------------------------------------------------------------
// wxTextDataObject
IMPLEMENT_DYNAMIC_CLASS( wxTextDataObject, wxDataObject )
-wxTextDataObject::wxTextDataObject()
-{
- m_format.SetType( wxDF_TEXT );
-}
-
-wxTextDataObject::wxTextDataObject( const wxString& data )
-{
- m_format.SetType( wxDF_TEXT );
-
- m_data = data;
+wxTextDataObject::wxTextDataObject()
+{
}
-void wxTextDataObject::SetText( const wxString& data )
-{
- m_data = data;
+wxTextDataObject::wxTextDataObject(const wxString& strText)
+ : m_strText(strText)
+{
}
-wxString wxTextDataObject::GetText() const
-{
- return m_data;
+size_t wxTextDataObject::GetDataSize(const wxDataFormat& format) const
+{
+ return m_strText.Len() + 1; // +1 for trailing '\0'of course
}
-void wxTextDataObject::WriteData( void *dest ) const
-{
- WriteString( m_data, dest );
+bool wxTextDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
+{
+ memcpy(buf, m_strText.c_str(), GetDataSize(format));
+ 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 );
+bool wxTextDataObject::SetData(const wxDataFormat& format, const void *buf)
+{
+ m_strText = (const wxChar *)buf;
+ return TRUE;
}
// ----------------------------------------------------------------------------
wxFileDataObject::wxFileDataObject()
{
- m_format.SetType( wxDF_FILENAME );
}
void wxFileDataObject::AddFile( const wxString &file )
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;
}
+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::wxBitmapDataObject()
{
- m_format.SetType( wxDF_BITMAP );
- m_pngData = (char*)NULL;
+ m_pngData = (void*)NULL;
m_pngSize = 0;
}
wxBitmapDataObject::wxBitmapDataObject( const wxBitmap& bitmap )
{
- m_format.SetType( wxDF_BITMAP );
- m_pngData = (char*)NULL;
+ m_pngData = (void*)NULL;
m_pngSize = 0;
m_bitmap = bitmap;
DoConvertToPng();
wxBitmapDataObject::~wxBitmapDataObject()
{
- if (m_pngData) delete[] m_pngData;
+ if (m_pngData)
+ delete[] m_pngData;
}
void wxBitmapDataObject::SetBitmap( const wxBitmap &bitmap )
{
+ if (m_pngData)
+ delete[] m_pngData;
+ m_pngData = (void*)NULL;
+ m_pngSize = 0;
+
m_bitmap = bitmap;
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 );
+ if (format != wxDF_BITMAP) return 0;
+
+ return m_pngSize;
}
-size_t wxBitmapDataObject::GetSize() const
+bool wxBitmapDataObject::GetDataHere(const wxDataFormat& format, void *buf) const
{
- return m_pngSize;
+ if (format != wxDF_BITMAP) return FALSE;
+
+ if (m_pngSize > 0)
+ {
+ memcpy(buf, m_pngData, m_pngSize);
+ return TRUE;
+ }
+
+ return FALSE;
}
-void wxBitmapDataObject::WriteBitmap( const wxBitmap &WXUNUSED(bitmap), void *dest ) const
+bool wxBitmapDataObject::SetData(const wxDataFormat& format, const void *buf)
{
-// if (m_bitmap == bitmap)
- memcpy( dest, m_pngData, m_pngSize );
+ if (m_pngData) delete[] m_pngData;
+ m_pngData = (void*) NULL;
+ m_pngSize = 0;
+ m_bitmap = wxNullBitmap;
+
+ return FALSE;
}
-void wxBitmapDataObject::SetPngData( const char *pngData, size_t pngSize )
+void wxBitmapDataObject::SetPngData(const void *buf, size_t size)
{
if (m_pngData) delete[] m_pngData;
- m_pngData = (char*) NULL;
- m_pngSize = pngSize;
- m_pngData = new char[m_pngSize];
- memcpy( m_pngData, pngData, m_pngSize );
+ m_pngSize = size;
+ m_pngData = (void*) new char[m_pngSize];
- wxMemoryInputStream mstream( pngData, pngSize );
+ memcpy( m_pngData, buf, m_pngSize );
+
+ wxMemoryInputStream mstream( (char*) m_pngData, m_pngSize );
wxImage image;
wxPNGHandler handler;
handler.LoadFile( &image, mstream );
void wxBitmapDataObject::DoConvertToPng()
{
- if (m_pngData) delete[] m_pngData;
+ if (!m_bitmap.Ok()) return;
wxImage image( m_bitmap );
wxPNGHandler handler;
wxCountingOutputStream count;
handler.SaveFile( &image, count );
m_pngSize = count.GetSize() + 100; // sometimes the size seems to vary ???
- m_pngData = new char[m_pngSize];
+ m_pngData = (void*) new char[m_pngSize];
- wxMemoryOutputStream mstream( m_pngData, m_pngSize );
+ wxMemoryOutputStream mstream( (char*) m_pngData, m_pngSize );
handler.SaveFile( &image, mstream );
}
// wxPrivateDataObject
// ----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS( wxPrivateDataObject, wxDataObject )
+IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject )
void wxPrivateDataObject::Free()
{
/* this should trigger an "drag_data_received" event */
gtk_drag_get_data( m_dragWidget,
m_dragContext,
- format.GetAtom(),
+ format,
m_dragTime );
#if wxUSE_THREADS
// char *name = gdk_atom_name( formatAtom );
// if (name) printf( "Format available: %s.\n", name );
- if (formatAtom == format.GetAtom()) return TRUE;
+ if (formatAtom == format) return TRUE;
child = child->next;
}
{
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)
{
// wxPrivateDropTarget
//-------------------------------------------------------------------------
+/*
wxPrivateDropTarget::wxPrivateDropTarget()
{
m_id = wxTheApp->GetAppName();
return TRUE;
}
+*/
//----------------------------------------------------------------------------
// A drop target which accepts files (dragged from File Manager or Explorer)
wxFileDataObject data;
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 i;
size_t size = data.GetFiles().Length();
// char *name = gdk_atom_name( selection_data->target );
// if (name) printf( "Format requested: %s.\n", name );
- wxNode *node = drop_source->m_data->m_dataObjects.First();
- while (node)
- {
- wxDataObject *data_object = (wxDataObject*) node->Data();
- if (data_object->GetFormat().GetAtom() == selection_data->target)
- {
-// printf( "format found.\n" );
+ drop_source->m_retValue = wxDragCancel;
+
+ wxDataObject *data = drop_source->m_data;
+
+ if (!data)
+ return;
+
+ if (!data->IsSupportedFormat(selection_data->target))
+ return;
- size_t data_size = data_object->GetSize();
+ if (data->GetDataSize(selection_data->target) == 0)
+ return;
+
+ size_t size = data->GetDataSize(selection_data->target);
- if (data_size > 0)
- {
-// printf( "data size: %d.\n", (int)data_size );
+// printf( "data size: %d.\n", (int)data_size );
- guchar *buffer = new guchar[data_size];
- data_object->WriteData( buffer );
+ guchar *d = new guchar[size];
+
+ if (!data->GetDataHere( selection_data->target, (void*)d ))
+ {
+ free( d );
+ return;
+ }
#if wxUSE_THREADS
- /* disable GUI threads */
- wxapp_uninstall_thread_wakeup();
+ /* disable GUI threads */
+ wxapp_uninstall_thread_wakeup();
#endif
gtk_selection_data_set( selection_data,
selection_data->target,
8, // 8-bit
- buffer,
- data_size );
+ d,
+ size );
#if wxUSE_THREADS
- /* enable GUI threads */
- wxapp_install_thread_wakeup();
+ /* enable GUI threads */
+ wxapp_install_thread_wakeup();
#endif
- free( buffer );
- /* so far only copy, no moves. TODO. */
- drop_source->m_retValue = wxDragCopy;
-
- return;
- }
- }
-
- node = node->Next();
- }
-
- drop_source->m_retValue = wxDragCancel;
+ free( d );
+
+ /* so far only copy, no moves. TODO. */
+ drop_source->m_retValue = wxDragCopy;
}
//----------------------------------------------------------------------------
m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow;
- m_data = (wxDataBroker*) NULL;
+ m_data = (wxDataObject*) NULL;
m_retValue = wxDragCancel;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
if (win->m_wxwindow) m_widget = win->m_wxwindow;
m_retValue = wxDragCancel;
- m_data = new wxDataBroker;
- m_data->Add(&data);
+ m_data = &data;
m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY );
m_goaheadCursor = wxCursor( wxCURSOR_HAND );
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 )
{
- if ( m_data )
+ if (m_data)
delete m_data;
- m_data = new wxDataBroker;
- 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;
+ m_data = &data;
}
wxDropSource::~wxDropSource()
{
- if (m_data) delete m_data;
+ if (m_data)
+// delete m_data;
g_blockEventsOnDrag = FALSE;
}