From b068c4e8a1f4919360329c345eae36ff95ab5a10 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 21 Oct 1999 10:23:30 +0000 Subject: [PATCH] Made wxGTK compile and link again. Broke wxMSW a little. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4098 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- Makefile.in | 8 +- distrib/msw/tmake/filelist.txt | 1 + include/wx/clipbrd.h | 42 ++++------ include/wx/dataobj.h | 4 +- include/wx/dnd.h | 22 +++-- include/wx/gtk/dataobj.h | 4 + include/wx/gtk/dataobj2.h | 3 +- include/wx/gtk/dnd.h | 147 ++++++--------------------------- include/wx/gtk1/dataobj.h | 4 + include/wx/gtk1/dataobj2.h | 3 +- include/wx/gtk1/dnd.h | 147 ++++++--------------------------- src/common/clipcmn.cpp | 59 +++++++++++++ src/gtk/clipbrd.cpp | 146 ++++++++++++++++---------------- src/gtk/dataobj.cpp | 93 ++++++++------------- src/gtk/dnd.cpp | 52 ++++-------- src/gtk1/clipbrd.cpp | 146 ++++++++++++++++---------------- src/gtk1/dataobj.cpp | 93 ++++++++------------- src/gtk1/dnd.cpp | 52 ++++-------- 18 files changed, 413 insertions(+), 613 deletions(-) create mode 100644 src/common/clipcmn.cpp diff --git a/Makefile.in b/Makefile.in index ded2afb57b..a401b17434 100644 --- a/Makefile.in +++ b/Makefile.in @@ -1,5 +1,5 @@ # -# This file was automatically generated by tmake at 04:13, 1999/10/21 +# This file was automatically generated by tmake at 11:02, 1999/10/21 # DO NOT CHANGE THIS FILE, YOUR CHANGES WILL BE LOST! CHANGE UNX.T! # @@ -685,6 +685,7 @@ GTK_COMMONOBJS = \ parser.o \ appcmn.o \ choiccmn.o \ + clipcmn.o \ cmndata.o \ config.o \ ctrlcmn.o \ @@ -776,6 +777,7 @@ GTK_COMMONDEPS = \ parser.d \ appcmn.d \ choiccmn.d \ + clipcmn.d \ cmndata.d \ config.d \ ctrlcmn.d \ @@ -1061,6 +1063,7 @@ MOTIF_COMMONOBJS = \ parser.o \ appcmn.o \ choiccmn.o \ + clipcmn.o \ cmndata.o \ config.o \ ctrlcmn.o \ @@ -1153,6 +1156,7 @@ MOTIF_COMMONDEPS = \ parser.d \ appcmn.d \ choiccmn.d \ + clipcmn.d \ cmndata.d \ config.d \ ctrlcmn.d \ @@ -1401,6 +1405,7 @@ MSW_COMMONOBJS = \ parser.o \ appcmn.o \ choiccmn.o \ + clipcmn.o \ cmndata.o \ config.o \ ctrlcmn.o \ @@ -1493,6 +1498,7 @@ MSW_COMMONDEPS = \ parser.d \ appcmn.d \ choiccmn.d \ + clipcmn.d \ cmndata.d \ config.d \ ctrlcmn.d \ diff --git a/distrib/msw/tmake/filelist.txt b/distrib/msw/tmake/filelist.txt index 7de559b05b..0d3fba3e17 100644 --- a/distrib/msw/tmake/filelist.txt +++ b/distrib/msw/tmake/filelist.txt @@ -94,6 +94,7 @@ wizard.cpp G appcmn.cpp C B choiccmn.cpp C cmndata.cpp C +clipcmn.cpp C config.cpp C B ctrlcmn.cpp C date.cpp C B diff --git a/include/wx/clipbrd.h b/include/wx/clipbrd.h index ad50734933..7f79269aed 100644 --- a/include/wx/clipbrd.h +++ b/include/wx/clipbrd.h @@ -12,10 +12,15 @@ #ifndef _WX_CLIPBRD_H_BASE_ #define _WX_CLIPBRD_H_BASE_ +#ifdef __GNUG__ + #pragma interface "clipboardbase.h" +#endif + #include "wx/defs.h" #if wxUSE_CLIPBOARD + #include "wx/object.h" #include "wx/wxchar.h" @@ -33,30 +38,32 @@ class WXDLLEXPORT wxDataObject; class WXDLLEXPORT wxClipboardBase : public wxObject { public: + wxClipboardBase(); + // open the clipboard before Add/SetData() and GetData() - virtual bool Open(); + virtual bool Open() = 0; // close the clipboard after Add/SetData() and GetData() - virtual void Close(); + virtual void Close() = 0; // add to the clipboard data // // NB: the clipboard owns the pointer and will delete it, so data must be // allocated on the heap - virtual bool AddData( wxDataObject *data ); + virtual bool AddData( wxDataObject *data ) = 0; // set the clipboard data, this is the same as Clear() followed by // AddData() - virtual bool SetData( wxDataObject *data ); + virtual bool SetData( wxDataObject *data ) = 0; // ask if data in correct format is available - virtual bool IsSupported( const wxDataFormat& format ); + virtual bool IsSupported( const wxDataFormat& format ) = 0; // fill data with data on the clipboard (if available) - virtual bool GetData( wxDataObject& data ); - + virtual bool GetData( wxDataObject& data ) = 0; + // clears wxTheClipboard and the system's clipboard if possible - virtual void Clear(); + virtual void Clear() = 0; // flushes the clipboard: this means that the data which is currently on // clipboard will stay available even after the application exits (possibly @@ -104,25 +111,6 @@ public: // The global clipboard object WXDLLEXPORT_DATA(extern wxClipboard *) wxTheClipboard; -// ---------------------------------------------------------------------------- -// wxClipboardModule: module responsible for initializing the global clipboard -// object -// -// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp -// ---------------------------------------------------------------------------- - -class wxClipboardModule : public wxModule -{ -public: - bool OnInit() - { wxTheClipboard = new wxClipboard; return TRUE; } - void OnExit() - { delete wxTheClipboard; wxTheClipboard = (wxClipboard *)NULL; } - -private: - DECLARE_DYNAMIC_CLASS(wxClipboardModule) -}; - #endif // wxUSE_CLIPBOARD #endif // _WX_CLIPBRD_H_BASE_ diff --git a/include/wx/dataobj.h b/include/wx/dataobj.h index 572b4f12d2..aa49135e6a 100644 --- a/include/wx/dataobj.h +++ b/include/wx/dataobj.h @@ -331,7 +331,7 @@ public: virtual wxBitmap GetBitmap() const { return m_bitmap; } virtual void SetBitmap(const wxBitmap& bitmap) { m_bitmap = bitmap; } -private: +protected: wxBitmap m_bitmap; }; @@ -349,7 +349,7 @@ public: wxFileDataObjectBase() : wxDataObjectSimple(wxDF_FILENAME) { } // get a reference to our array - const wxArrayString& GetFilenames() { return m_filenames; } + const wxArrayString& GetFilenames() const { return m_filenames; } // the Get() functions do nothing for us virtual size_t GetDataSize() const { return 0; } diff --git a/include/wx/dnd.h b/include/wx/dnd.h index 36d3e506cd..82fb690739 100644 --- a/include/wx/dnd.h +++ b/include/wx/dnd.h @@ -44,7 +44,9 @@ public: virtual ~wxDropSourceBase() { } // set the data which is transfered by drag and drop - void SetData(wxDataObject& data) { delete m_data; m_data = &data; } + void SetData(wxDataObject& data) + { if (m_data) delete m_data; + m_data = &data; } // start drag action, see enum wxDragResult for return value description // @@ -80,7 +82,7 @@ public: // ctor takes a pointer to heap-allocated wxDataObject which will be owned // by wxDropTarget and deleted by it automatically. If you don't give it // here, you can use SetDataObject() later. - wxDropTargetBase(wxDataObject *dataObject = NULL) + wxDropTargetBase(wxDataObject *dataObject = (wxDataObject*)NULL) { m_dataObject = dataObject; } // dtor deletes our data object virtual ~wxDropTargetBase() @@ -90,13 +92,23 @@ public: wxDataObject *GetDataObject() const { return m_dataObject; } void SetDataObject(wxDataObject *dataObject) - { delete m_dataObject; m_dataObject = dataObject; } + { if (m_dataObject) delete m_dataObject; + m_dataObject = dataObject; } // called when mouse enters/leaves the window: might be used to give // some visual feedback to the user - virtual void OnEnter() { } virtual void OnLeave() { } - + + // this function is called when data enters over position (x, y) - if it + // returns TRUE, the dragging icon can indicate that the window would + // accept a drop here + virtual bool OnEnter(wxCoord x, wxCoord y) = 0; + + // this function is called when data is move over position (x, y) - if it + // returns TRUE, the dragging icon can indicate that the window would + // accept a drop here + virtual bool OnMove(wxCoord x, wxCoord y) = 0; + // this function is called when data is dropped at position (x, y) - if it // returns TRUE, OnData() will be called immediately afterwards which will // allow to retrieve the data dropped. diff --git a/include/wx/gtk/dataobj.h b/include/wx/gtk/dataobj.h index 79430ddce6..0794fcf51f 100644 --- a/include/wx/gtk/dataobj.h +++ b/include/wx/gtk/dataobj.h @@ -20,6 +20,10 @@ class wxDataObject : public wxDataObjectBase { +public: + wxDataObject(); + + virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const; }; #endif // _WX_GTK_DATAOBJ_H_ diff --git a/include/wx/gtk/dataobj2.h b/include/wx/gtk/dataobj2.h index 8f42fa8703..9751638eb9 100644 --- a/include/wx/gtk/dataobj2.h +++ b/include/wx/gtk/dataobj2.h @@ -46,7 +46,6 @@ protected: void Clear() { free(m_pngData); } void ClearAll() { Clear(); Init(); } -private: size_t m_pngSize; void *m_pngData; @@ -63,6 +62,8 @@ public: // implement base class pure virtuals // ---------------------------------- + void AddFile( const wxString &filename ); + virtual size_t GetDataSize() const; virtual bool GetDataHere(void *buf) const; virtual bool SetData(size_t len, const void *buf); diff --git a/include/wx/gtk/dnd.h b/include/wx/gtk/dnd.h index c67cb053e8..edc321382d 100644 --- a/include/wx/gtk/dnd.h +++ b/include/wx/gtk/dnd.h @@ -41,135 +41,40 @@ class wxDropSource; // wxDropTarget //------------------------------------------------------------------------- -class wxDropTarget: public wxObject +class wxDropTarget: public wxDropTargetBase { public: - - wxDropTarget(); - ~wxDropTarget(); - - /* may be overridden to react to events */ - virtual void OnEnter(); - virtual void OnLeave(); - - /* may be overridden to reject certain formats or drops - on certain areas. always returns TRUE by default - indicating that you'd accept the data from the drag. */ - virtual bool OnMove( long x, long y ); - - /* has to be overridden to accept a drop event. call - IsSupported() to ask which formats are available - and then call RequestData() to indicate the format - you request. */ - virtual bool OnDrop( long x, long y ); - - /* this gets called once the data has actually arrived. get - it with GetData(). this has to be overridden. */ - virtual bool OnData( long x, long y ); - - /* called from within OnDrop() to request a certain format - from the drop event. */ - bool RequestData( wxDataFormat format ); - - /* called to query what formats are available */ - bool IsSupported( wxDataFormat format ); - - /* fill data with data from the dragging source */ - bool GetData( wxDataObject *data ); - - virtual size_t GetFormatCount() const = 0; - virtual wxDataFormat GetFormat(size_t n) const = 0; - -// implementation - - void RegisterWidget( GtkWidget *widget ); - void UnregisterWidget( GtkWidget *widget ); - - GdkDragContext *m_dragContext; - GtkWidget *m_dragWidget; - GtkSelectionData *m_dragData; - guint m_dragTime; - bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ - - void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } - void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } - void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } - void SetDragTime( guint time ) { m_dragTime = time; } -}; - -//------------------------------------------------------------------------- -// wxTextDropTarget -//------------------------------------------------------------------------- - -class wxTextDropTarget: public wxDropTarget -{ -public: - - wxTextDropTarget() {} - - virtual bool OnData( long x, long y ); - - /* you have to override OnDropData to get at the text */ - virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; - - virtual size_t GetFormatCount() const - { return 1; } - virtual wxDataFormat GetFormat(size_t n) const - { return wxDF_TEXT; } -}; - -//------------------------------------------------------------------------- -// wxPrivateDropTarget -//------------------------------------------------------------------------- - -/* -class wxPrivateDropTarget: public wxDropTarget -{ -public: - - wxPrivateDropTarget(); - 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 ); - - virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; - - void SetId( const wxString& id ) { m_id = id; } - wxString GetId() { return m_id; } - -private: - - wxString m_id; -}; -*/ - -//---------------------------------------------------------------------------- -// A drop target which accepts files (dragged from File Manager or Explorer) -//---------------------------------------------------------------------------- - -class wxFileDropTarget: public wxDropTarget -{ -public: - - wxFileDropTarget() {} - - virtual bool OnData( long x, long y ); - - virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; - - virtual size_t GetFormatCount() const - { return 1; } - virtual wxDataFormat GetFormat(size_t n) const - { return wxDF_FILENAME; } + wxDropTarget(wxDataObject *dataObject = (wxDataObject*) NULL ); + + virtual bool OnEnter(wxCoord x, wxCoord y) ; + virtual bool OnMove(wxCoord x, wxCoord y); + virtual bool OnDrop(wxCoord x, wxCoord y); + virtual bool OnData(wxCoord x, wxCoord y); + virtual bool GetData(); + + // implementation + + GdkAtom GetMatchingPair(); + void RegisterWidget( GtkWidget *widget ); + void UnregisterWidget( GtkWidget *widget ); + + GdkDragContext *m_dragContext; + GtkWidget *m_dragWidget; + GtkSelectionData *m_dragData; + guint m_dragTime; + bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ + + void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } + void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } + void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } + void SetDragTime( guint time ) { m_dragTime = time; } }; //------------------------------------------------------------------------- // wxDropSource //------------------------------------------------------------------------- -class wxDropSource: public wxObject +class wxDropSource: public wxDropSourceBase { public: /* constructor. set data later with SetData() */ diff --git a/include/wx/gtk1/dataobj.h b/include/wx/gtk1/dataobj.h index 79430ddce6..0794fcf51f 100644 --- a/include/wx/gtk1/dataobj.h +++ b/include/wx/gtk1/dataobj.h @@ -20,6 +20,10 @@ class wxDataObject : public wxDataObjectBase { +public: + wxDataObject(); + + virtual bool IsSupportedFormat( const wxDataFormat& format, Direction dir = Get ) const; }; #endif // _WX_GTK_DATAOBJ_H_ diff --git a/include/wx/gtk1/dataobj2.h b/include/wx/gtk1/dataobj2.h index 8f42fa8703..9751638eb9 100644 --- a/include/wx/gtk1/dataobj2.h +++ b/include/wx/gtk1/dataobj2.h @@ -46,7 +46,6 @@ protected: void Clear() { free(m_pngData); } void ClearAll() { Clear(); Init(); } -private: size_t m_pngSize; void *m_pngData; @@ -63,6 +62,8 @@ public: // implement base class pure virtuals // ---------------------------------- + void AddFile( const wxString &filename ); + virtual size_t GetDataSize() const; virtual bool GetDataHere(void *buf) const; virtual bool SetData(size_t len, const void *buf); diff --git a/include/wx/gtk1/dnd.h b/include/wx/gtk1/dnd.h index c67cb053e8..edc321382d 100644 --- a/include/wx/gtk1/dnd.h +++ b/include/wx/gtk1/dnd.h @@ -41,135 +41,40 @@ class wxDropSource; // wxDropTarget //------------------------------------------------------------------------- -class wxDropTarget: public wxObject +class wxDropTarget: public wxDropTargetBase { public: - - wxDropTarget(); - ~wxDropTarget(); - - /* may be overridden to react to events */ - virtual void OnEnter(); - virtual void OnLeave(); - - /* may be overridden to reject certain formats or drops - on certain areas. always returns TRUE by default - indicating that you'd accept the data from the drag. */ - virtual bool OnMove( long x, long y ); - - /* has to be overridden to accept a drop event. call - IsSupported() to ask which formats are available - and then call RequestData() to indicate the format - you request. */ - virtual bool OnDrop( long x, long y ); - - /* this gets called once the data has actually arrived. get - it with GetData(). this has to be overridden. */ - virtual bool OnData( long x, long y ); - - /* called from within OnDrop() to request a certain format - from the drop event. */ - bool RequestData( wxDataFormat format ); - - /* called to query what formats are available */ - bool IsSupported( wxDataFormat format ); - - /* fill data with data from the dragging source */ - bool GetData( wxDataObject *data ); - - virtual size_t GetFormatCount() const = 0; - virtual wxDataFormat GetFormat(size_t n) const = 0; - -// implementation - - void RegisterWidget( GtkWidget *widget ); - void UnregisterWidget( GtkWidget *widget ); - - GdkDragContext *m_dragContext; - GtkWidget *m_dragWidget; - GtkSelectionData *m_dragData; - guint m_dragTime; - bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ - - void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } - void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } - void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } - void SetDragTime( guint time ) { m_dragTime = time; } -}; - -//------------------------------------------------------------------------- -// wxTextDropTarget -//------------------------------------------------------------------------- - -class wxTextDropTarget: public wxDropTarget -{ -public: - - wxTextDropTarget() {} - - virtual bool OnData( long x, long y ); - - /* you have to override OnDropData to get at the text */ - virtual bool OnDropText( long x, long y, const wxChar *text ) = 0; - - virtual size_t GetFormatCount() const - { return 1; } - virtual wxDataFormat GetFormat(size_t n) const - { return wxDF_TEXT; } -}; - -//------------------------------------------------------------------------- -// wxPrivateDropTarget -//------------------------------------------------------------------------- - -/* -class wxPrivateDropTarget: public wxDropTarget -{ -public: - - wxPrivateDropTarget(); - 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 ); - - virtual bool OnDropData( long x, long y, void *data, size_t size ) = 0; - - void SetId( const wxString& id ) { m_id = id; } - wxString GetId() { return m_id; } - -private: - - wxString m_id; -}; -*/ - -//---------------------------------------------------------------------------- -// A drop target which accepts files (dragged from File Manager or Explorer) -//---------------------------------------------------------------------------- - -class wxFileDropTarget: public wxDropTarget -{ -public: - - wxFileDropTarget() {} - - virtual bool OnData( long x, long y ); - - virtual bool OnDropFiles( long x, long y, size_t nFiles, const wxChar * const aszFiles[] ) = 0; - - virtual size_t GetFormatCount() const - { return 1; } - virtual wxDataFormat GetFormat(size_t n) const - { return wxDF_FILENAME; } + wxDropTarget(wxDataObject *dataObject = (wxDataObject*) NULL ); + + virtual bool OnEnter(wxCoord x, wxCoord y) ; + virtual bool OnMove(wxCoord x, wxCoord y); + virtual bool OnDrop(wxCoord x, wxCoord y); + virtual bool OnData(wxCoord x, wxCoord y); + virtual bool GetData(); + + // implementation + + GdkAtom GetMatchingPair(); + void RegisterWidget( GtkWidget *widget ); + void UnregisterWidget( GtkWidget *widget ); + + GdkDragContext *m_dragContext; + GtkWidget *m_dragWidget; + GtkSelectionData *m_dragData; + guint m_dragTime; + bool m_firstMotion; /* gdk has no "gdk_drag_enter" event */ + + void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } + void SetDragWidget( GtkWidget *w ) { m_dragWidget = w; } + void SetDragData( GtkSelectionData *sd ) { m_dragData = sd; } + void SetDragTime( guint time ) { m_dragTime = time; } }; //------------------------------------------------------------------------- // wxDropSource //------------------------------------------------------------------------- -class wxDropSource: public wxObject +class wxDropSource: public wxDropSourceBase { public: /* constructor. set data later with SetData() */ diff --git a/src/common/clipcmn.cpp b/src/common/clipcmn.cpp new file mode 100644 index 0000000000..7dc2ef2030 --- /dev/null +++ b/src/common/clipcmn.cpp @@ -0,0 +1,59 @@ +///////////////////////////////////////////////////////////////////////////// +// Name: common/clipcmn.cpp +// Purpose: common (to all ports) wxClipboard functions +// Author: Robert Roebling +// Modified by: +// Created: 28.06.99 +// RCS-ID: $Id$ +// Copyright: (c) Robert Roebling +// Licence: wxWindows license +///////////////////////////////////////////////////////////////////////////// + +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- + +#ifdef __GNUG__ + #pragma implementation "clipboardbase.h" +#endif + +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#include "wx/clipbrd.h" + +//-------------------------------------------------------------------------- +// wxClipboardBase +//-------------------------------------------------------------------------- + +wxClipboardBase::wxClipboardBase() +{ +} + +// ---------------------------------------------------------------------------- +// wxClipboardModule: module responsible for initializing the global clipboard +// object +// +// NB: IMPLEMENT_DYNAMIC_CLASS() for it is in common/appcmn.cpp +// ---------------------------------------------------------------------------- + +class wxClipboardModule : public wxModule +{ +public: + bool OnInit() + { wxTheClipboard = new wxClipboard; return TRUE; } + void OnExit() + { delete wxTheClipboard; wxTheClipboard = (wxClipboard *)NULL; } + +private: + DECLARE_DYNAMIC_CLASS(wxClipboardModule) +}; + diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 79e3bc58bb..1304b0ddf1 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -17,6 +17,7 @@ #include "wx/dataobj.h" #include "wx/utils.h" +#include "wx/log.h" #include "glib.h" #include "gdk/gdk.h" @@ -148,9 +149,11 @@ selection_received( GtkWidget *WXUNUSED(widget), clipboard->m_waiting = FALSE; return; } + + wxDataFormat format( selection_data->target ); /* make sure we got the data in the correct format */ - if (data_object->GetFormat() != selection_data->target) + if (!data_object->IsSupportedFormat( format ) ) { clipboard->m_waiting = FALSE; return; @@ -159,7 +162,7 @@ selection_received( GtkWidget *WXUNUSED(widget), /* make sure we got the data in the correct form (selection type). if so, copy data to target object */ - switch (data_object->GetFormat().GetType()) + switch (format.GetType()) { case wxDF_TEXT: { @@ -188,7 +191,7 @@ selection_received( GtkWidget *WXUNUSED(widget), wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; - bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length ); + bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data ); break; } @@ -201,9 +204,7 @@ selection_received( GtkWidget *WXUNUSED(widget), return; } - wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object; - - private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length ); + data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data ); break; } @@ -271,9 +272,11 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data wxDataObject *data = wxTheClipboard->m_data; - if (!data->IsSupportedFormat( selection_data->target )) return; + wxDataFormat format( selection_data->target ); + + if (!data->IsSupportedFormat( format )) return; - if (data->GetFormat().GetType() == wxDF_TEXT) + if (format.GetType() == wxDF_TEXT) { wxTextDataObject *text_object = (wxTextDataObject*) data; wxString text( text_object->GetText() ); @@ -295,23 +298,23 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data return; } - if (data->GetFormat().GetType() == wxDF_BITMAP) + if (format.GetType() == wxDF_BITMAP) { wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data; - if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return; + if (bitmap_object->GetDataSize() == 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) ); + (unsigned char*) bitmap_object->GetPngData(), + (int) bitmap_object->GetDataSize() ); return; } - int size = data->GetDataSize( selection_data->target ); + int size = data->GetDataSize( format ); if (size == 0) return; @@ -456,54 +459,46 @@ bool wxClipboard::AddData( wxDataObject *data ) wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); - // we can only store one wxDataObject + /* we can only store one wxDataObject */ Clear(); m_data = data; - /* get native format id of new data object */ - GdkAtom format = data->GetFormat(); - - wxCHECK_MSG( format, FALSE, wxT("data has invalid format") ); - /* This should happen automatically, but to be on the safe side */ m_ownsClipboard = FALSE; m_ownsPrimarySelection = FALSE; - /* Add handlers if someone requests data */ - -#if (GTK_MINOR_VERSION > 0) - - gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), + /* get formats from wxDataObjects */ + wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; + m_data->GetAllFormats( array ); + + for (size_t i = 0; i < m_data->GetFormatCount(); i++) + { + GdkAtom atom = array[i]; + wxLogDebug( wxT("Clipboard Supported atom %s"), gdk_atom_name( atom ) ); + + /* Add handlers if someone requests data. We currently always + offer data to the clipboard and the primary selection. Maybe + we should make that depend on the usePrimary flag */ + + gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), GDK_SELECTION_PRIMARY, - format, + atom, 0 ); /* what is info ? */ - gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), + gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), g_clipboardAtom, - format, + atom, 0 ); /* what is info ? */ + } + + delete[] array; gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), "selection_get", GTK_SIGNAL_FUNC(selection_handler), (gpointer) NULL ); -#else - - gtk_selection_add_handler( m_clipboardWidget, - g_clipboardAtom, - format, - selection_handler, - (gpointer) NULL ); - - gtk_selection_add_handler( m_clipboardWidget, - GDK_SELECTION_PRIMARY, - format, - selection_handler, - (gpointer) NULL ); -#endif - #if wxUSE_THREADS /* disable GUI threads */ wxapp_uninstall_thread_wakeup(); @@ -585,47 +580,56 @@ bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); - /* is data supported by clipboard ? */ - - if (!IsSupported( data->GetFormat() )) return FALSE; + /* get formats from wxDataObjects */ + wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ]; + data.GetAllFormats( array ); - /* store pointer to data object to be filled up by callbacks */ + for (size_t i = 0; i < data.GetFormatCount(); i++) + { + /* is data supported by clipboard ? */ + if (!IsSupported( array[i] )) + continue; - m_receivedData = data; + /* store pointer to data object to be filled up by callbacks */ + m_receivedData = &data; - /* store requested format to be asked for by callbacks */ - - m_targetRequested = data->GetFormat(); + /* store requested format to be asked for by callbacks */ + m_targetRequested = array[i]; - wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); + wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); - /* start query */ - - m_formatSupported = FALSE; + /* start query */ + m_formatSupported = FALSE; - /* ask for clipboard contents. this will set - m_formatSupported to TRUE if m_targetRequested - is supported. - also, we have to wait for the "answer" from the - clipboard owner which is an asynchronous process. - therefore we set m_waiting = TRUE here and wait - until the callback "targets_selection_received" - sets it to FALSE */ - - m_waiting = TRUE; - - gtk_selection_convert( m_clipboardWidget, + /* ask for clipboard contents. this will set + m_formatSupported to TRUE if m_targetRequested + is supported. + also, we have to wait for the "answer" from the + clipboard owner which is an asynchronous process. + therefore we set m_waiting = TRUE here and wait + until the callback "targets_selection_received" + sets it to FALSE */ + + m_waiting = TRUE; + + gtk_selection_convert( m_clipboardWidget, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, m_targetRequested, GDK_CURRENT_TIME ); - while (m_waiting) gtk_main_iteration(); + while (m_waiting) gtk_main_iteration(); - /* this is a true error as we checked for the presence of such data before */ - - wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") ); + /* this is a true error as we checked for the presence of such data before */ + wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") ); + + /* return success */ + delete[] array; + return TRUE; + } - return TRUE; + /* return failure */ + delete[] array; + return FALSE; } #endif diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index dc7effd747..643d09aa76 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -128,25 +128,19 @@ void wxDataFormat::PrepareFormats() // wxDataObject //------------------------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject ) - wxDataObject::wxDataObject() { } -wxDataObject::~wxDataObject() +bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const { -} - -bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const -{ - size_t nFormatCount = GetFormatCount(); + size_t nFormatCount = GetFormatCount(dir); if ( nFormatCount == 1 ) { return format == GetPreferredFormat(); } else { wxDataFormat *formats = new wxDataFormat[nFormatCount]; - GetAllFormats(formats); + GetAllFormats(formats,dir); size_t n; for ( n = 0; n < nFormatCount; n++ ) { @@ -167,7 +161,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const bool wxFileDataObject::GetDataHere(void *buf) const { - const wxString& filenames = GetFilenames(); + wxString filenames; + + for (size_t i = 0; i < m_filenames.GetCount(); i++) + { + filenames += m_filenames[i]; + filenames += (wxChar) 0; + } + memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); return TRUE; @@ -175,16 +176,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const size_t wxFileDataObject::GetDataSize() const { - return GetFilenames().Len() + 1; + size_t res = 0; + + for (size_t i = 0; i < m_filenames.GetCount(); i++) + { + res += m_filenames[i].Len(); + res += 1; + } + + return res + 1; } -bool wxFileDataObject::SetData(const void *buf) +bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf) { - SetFilenames((const wxChar *)buf); + /* TODO */ + + wxString file( (const char *)buf ); /* char, not wxChar */ + + AddFile( file ); return TRUE; } +void wxFileDataObject::AddFile( const wxString &filename ) +{ + m_filenames.Add( filename ); +} + // ---------------------------------------------------------------------------- // wxBitmapDataObject // ---------------------------------------------------------------------------- @@ -248,6 +266,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf) } m_bitmap = image.ConvertToBitmap(); + + return m_bitmap.Ok(); } void wxBitmapDataObject::DoConvertToPng() @@ -268,51 +288,4 @@ void wxBitmapDataObject::DoConvertToPng() handler.SaveFile( &image, mstream ); } -// ---------------------------------------------------------------------------- -// wxPrivateDataObject -// ---------------------------------------------------------------------------- - -IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject ) - -void wxPrivateDataObject::Free() -{ - if ( m_data ) - free(m_data); -} - -wxPrivateDataObject::wxPrivateDataObject() -{ - wxString id = wxT("application/"); - id += wxTheApp->GetAppName(); - - m_format.SetId( id ); - - m_size = 0; - m_data = (void *)NULL; -} - -void wxPrivateDataObject::SetData( const void *data, size_t size ) -{ - Free(); - - m_size = size; - m_data = malloc(size); - - memcpy( m_data, data, size ); -} - -void wxPrivateDataObject::WriteData( void *dest ) const -{ - WriteData( m_data, dest ); -} - -size_t wxPrivateDataObject::GetSize() const -{ - return m_size; -} - -void wxPrivateDataObject::WriteData( const void *data, void *dest ) const -{ - memcpy( dest, data, GetSize() ); -} diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index db461c3d44..f59b86d330 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -349,35 +349,27 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), // wxDropTarget //---------------------------------------------------------------------------- -wxDropTarget::wxDropTarget( wxDataObject *data ) +wxDropTarget::wxDropTarget( wxDataObject *data ) + : wxDropTargetBase( data ) { m_firstMotion = TRUE; m_dragContext = (GdkDragContext*) NULL; m_dragWidget = (GtkWidget*) NULL; m_dragData = (GtkSelectionData*) NULL; m_dragTime = 0; - m_data = data; -} - -wxDropTarget::~wxDropTarget() -{ } bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); } -void wxDropTarget::OnLeave() -{ -} - bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); @@ -385,7 +377,7 @@ bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); @@ -393,7 +385,7 @@ bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; if (GetMatchingPair() == (GdkAtom) 0) @@ -404,7 +396,7 @@ bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) GdkAtom wxDropTarget::GetMatchingPair() { - if (!m_data) + if (!m_dataObject) return (GdkAtom) 0; if (!m_dragContext) @@ -420,7 +412,7 @@ GdkAtom wxDropTarget::GetMatchingPair() char *name = gdk_atom_name( formatAtom ); if (name) wxLogDebug( "Drop target: drag has format: %s", name ); #endif - if (m_data->IsSupportedFormat( format )) + if (m_dataObject->IsSupportedFormat( format )) return formatAtom; child = child->next; @@ -434,25 +426,25 @@ bool wxDropTarget::GetData() if (!m_dragData) return FALSE; - if (!m_data) + if (!m_dataObject) return FALSE; wxDataFormat dragFormat( m_dragData->target ); - if (!m_data->IsSupportedFormat( dragFormat )) + if (!m_dataObject->IsSupportedFormat( dragFormat )) return FALSE; if (dragFormat.GetType() == wxDF_TEXT) { - wxTextDataObject *text_object = (wxTextDataObject*)m_data; + wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject; text_object->SetText( (const char*)m_dragData->data ); return TRUE; } if (dragFormat.GetType() == wxDF_FILENAME) { - wxFileDataObject *file_object = (wxFileDataObject*)m_data; - file_object->SetFiles( (const char*)m_dragData->data ); + wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject; + file_object->SetData( 0, (const char*)m_dragData->data ); return TRUE; } @@ -633,7 +625,6 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop m_widget = win->m_widget; if (win->m_wxwindow) m_widget = win->m_wxwindow; - m_data = (wxDataObject*) NULL; m_retValue = wxDragCancel; m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); @@ -649,14 +640,14 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go, const wxIcon &stop ) { m_waiting = TRUE; + + SetData( data ); 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 ); @@ -666,19 +657,8 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); } -void wxDropSource::SetData( wxDataObject& data ) -{ - if (m_data) - delete m_data; - - m_data = &data; -} - wxDropSource::~wxDropSource() { - if (m_data) -// delete m_data; - g_blockEventsOnDrag = FALSE; } @@ -701,7 +681,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; - m_data->GetAllFormats( array, TRUE ); + m_data->GetAllFormats( array ); for (size_t i = 0; i < m_data->GetFormatCount(); i++) { GdkAtom atom = array[i]; diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 79e3bc58bb..1304b0ddf1 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -17,6 +17,7 @@ #include "wx/dataobj.h" #include "wx/utils.h" +#include "wx/log.h" #include "glib.h" #include "gdk/gdk.h" @@ -148,9 +149,11 @@ selection_received( GtkWidget *WXUNUSED(widget), clipboard->m_waiting = FALSE; return; } + + wxDataFormat format( selection_data->target ); /* make sure we got the data in the correct format */ - if (data_object->GetFormat() != selection_data->target) + if (!data_object->IsSupportedFormat( format ) ) { clipboard->m_waiting = FALSE; return; @@ -159,7 +162,7 @@ selection_received( GtkWidget *WXUNUSED(widget), /* make sure we got the data in the correct form (selection type). if so, copy data to target object */ - switch (data_object->GetFormat().GetType()) + switch (format.GetType()) { case wxDF_TEXT: { @@ -188,7 +191,7 @@ selection_received( GtkWidget *WXUNUSED(widget), wxBitmapDataObject *bitmap_object = (wxBitmapDataObject *) data_object; - bitmap_object->SetPngData( (const void*) selection_data->data, (size_t) selection_data->length ); + bitmap_object->SetData( (size_t) selection_data->length, (const void*) selection_data->data ); break; } @@ -201,9 +204,7 @@ selection_received( GtkWidget *WXUNUSED(widget), return; } - wxPrivateDataObject *private_object = (wxPrivateDataObject *) data_object; - - private_object->SetData( (const char*) selection_data->data, (size_t) selection_data->length ); + data_object->SetData( format, (size_t) selection_data->length, (const char*) selection_data->data ); break; } @@ -271,9 +272,11 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data wxDataObject *data = wxTheClipboard->m_data; - if (!data->IsSupportedFormat( selection_data->target )) return; + wxDataFormat format( selection_data->target ); + + if (!data->IsSupportedFormat( format )) return; - if (data->GetFormat().GetType() == wxDF_TEXT) + if (format.GetType() == wxDF_TEXT) { wxTextDataObject *text_object = (wxTextDataObject*) data; wxString text( text_object->GetText() ); @@ -295,23 +298,23 @@ selection_handler( GtkWidget *WXUNUSED(widget), GtkSelectionData *selection_data return; } - if (data->GetFormat().GetType() == wxDF_BITMAP) + if (format.GetType() == wxDF_BITMAP) { wxBitmapDataObject *bitmap_object = (wxBitmapDataObject*) data; - if (bitmap_object->GetDataSize(wxDF_BITMAP) == 0) return; + if (bitmap_object->GetDataSize() == 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) ); + (unsigned char*) bitmap_object->GetPngData(), + (int) bitmap_object->GetDataSize() ); return; } - int size = data->GetDataSize( selection_data->target ); + int size = data->GetDataSize( format ); if (size == 0) return; @@ -456,54 +459,46 @@ bool wxClipboard::AddData( wxDataObject *data ) wxCHECK_MSG( data, FALSE, wxT("data is invalid") ); - // we can only store one wxDataObject + /* we can only store one wxDataObject */ Clear(); m_data = data; - /* get native format id of new data object */ - GdkAtom format = data->GetFormat(); - - wxCHECK_MSG( format, FALSE, wxT("data has invalid format") ); - /* This should happen automatically, but to be on the safe side */ m_ownsClipboard = FALSE; m_ownsPrimarySelection = FALSE; - /* Add handlers if someone requests data */ - -#if (GTK_MINOR_VERSION > 0) - - gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), + /* get formats from wxDataObjects */ + wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; + m_data->GetAllFormats( array ); + + for (size_t i = 0; i < m_data->GetFormatCount(); i++) + { + GdkAtom atom = array[i]; + wxLogDebug( wxT("Clipboard Supported atom %s"), gdk_atom_name( atom ) ); + + /* Add handlers if someone requests data. We currently always + offer data to the clipboard and the primary selection. Maybe + we should make that depend on the usePrimary flag */ + + gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), GDK_SELECTION_PRIMARY, - format, + atom, 0 ); /* what is info ? */ - gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), + gtk_selection_add_target( GTK_WIDGET(m_clipboardWidget), g_clipboardAtom, - format, + atom, 0 ); /* what is info ? */ + } + + delete[] array; gtk_signal_connect( GTK_OBJECT(m_clipboardWidget), "selection_get", GTK_SIGNAL_FUNC(selection_handler), (gpointer) NULL ); -#else - - gtk_selection_add_handler( m_clipboardWidget, - g_clipboardAtom, - format, - selection_handler, - (gpointer) NULL ); - - gtk_selection_add_handler( m_clipboardWidget, - GDK_SELECTION_PRIMARY, - format, - selection_handler, - (gpointer) NULL ); -#endif - #if wxUSE_THREADS /* disable GUI threads */ wxapp_uninstall_thread_wakeup(); @@ -585,47 +580,56 @@ bool wxClipboard::GetData( wxDataObject& data ) { wxCHECK_MSG( m_open, FALSE, wxT("clipboard not open") ); - /* is data supported by clipboard ? */ - - if (!IsSupported( data->GetFormat() )) return FALSE; + /* get formats from wxDataObjects */ + wxDataFormat *array = new wxDataFormat[ data.GetFormatCount() ]; + data.GetAllFormats( array ); - /* store pointer to data object to be filled up by callbacks */ + for (size_t i = 0; i < data.GetFormatCount(); i++) + { + /* is data supported by clipboard ? */ + if (!IsSupported( array[i] )) + continue; - m_receivedData = data; + /* store pointer to data object to be filled up by callbacks */ + m_receivedData = &data; - /* store requested format to be asked for by callbacks */ - - m_targetRequested = data->GetFormat(); + /* store requested format to be asked for by callbacks */ + m_targetRequested = array[i]; - wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); + wxCHECK_MSG( m_targetRequested, FALSE, wxT("invalid clipboard format") ); - /* start query */ - - m_formatSupported = FALSE; + /* start query */ + m_formatSupported = FALSE; - /* ask for clipboard contents. this will set - m_formatSupported to TRUE if m_targetRequested - is supported. - also, we have to wait for the "answer" from the - clipboard owner which is an asynchronous process. - therefore we set m_waiting = TRUE here and wait - until the callback "targets_selection_received" - sets it to FALSE */ - - m_waiting = TRUE; - - gtk_selection_convert( m_clipboardWidget, + /* ask for clipboard contents. this will set + m_formatSupported to TRUE if m_targetRequested + is supported. + also, we have to wait for the "answer" from the + clipboard owner which is an asynchronous process. + therefore we set m_waiting = TRUE here and wait + until the callback "targets_selection_received" + sets it to FALSE */ + + m_waiting = TRUE; + + gtk_selection_convert( m_clipboardWidget, m_usePrimary ? GDK_SELECTION_PRIMARY : g_clipboardAtom, m_targetRequested, GDK_CURRENT_TIME ); - while (m_waiting) gtk_main_iteration(); + while (m_waiting) gtk_main_iteration(); - /* this is a true error as we checked for the presence of such data before */ - - wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") ); + /* this is a true error as we checked for the presence of such data before */ + wxCHECK_MSG( m_formatSupported, FALSE, wxT("error retrieving data from clipboard") ); + + /* return success */ + delete[] array; + return TRUE; + } - return TRUE; + /* return failure */ + delete[] array; + return FALSE; } #endif diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index dc7effd747..643d09aa76 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -128,25 +128,19 @@ void wxDataFormat::PrepareFormats() // wxDataObject //------------------------------------------------------------------------- -IMPLEMENT_ABSTRACT_CLASS( wxDataObject, wxObject ) - wxDataObject::wxDataObject() { } -wxDataObject::~wxDataObject() +bool wxDataObject::IsSupportedFormat(const wxDataFormat& format, Direction dir) const { -} - -bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const -{ - size_t nFormatCount = GetFormatCount(); + size_t nFormatCount = GetFormatCount(dir); if ( nFormatCount == 1 ) { return format == GetPreferredFormat(); } else { wxDataFormat *formats = new wxDataFormat[nFormatCount]; - GetAllFormats(formats); + GetAllFormats(formats,dir); size_t n; for ( n = 0; n < nFormatCount; n++ ) { @@ -167,7 +161,14 @@ bool wxDataObject::IsSupportedFormat(const wxDataFormat& format) const bool wxFileDataObject::GetDataHere(void *buf) const { - const wxString& filenames = GetFilenames(); + wxString filenames; + + for (size_t i = 0; i < m_filenames.GetCount(); i++) + { + filenames += m_filenames[i]; + filenames += (wxChar) 0; + } + memcpy( buf, filenames.mbc_str(), filenames.Len() + 1 ); return TRUE; @@ -175,16 +176,33 @@ bool wxFileDataObject::GetDataHere(void *buf) const size_t wxFileDataObject::GetDataSize() const { - return GetFilenames().Len() + 1; + size_t res = 0; + + for (size_t i = 0; i < m_filenames.GetCount(); i++) + { + res += m_filenames[i].Len(); + res += 1; + } + + return res + 1; } -bool wxFileDataObject::SetData(const void *buf) +bool wxFileDataObject::SetData(size_t WXUNUSED(size), const void *buf) { - SetFilenames((const wxChar *)buf); + /* TODO */ + + wxString file( (const char *)buf ); /* char, not wxChar */ + + AddFile( file ); return TRUE; } +void wxFileDataObject::AddFile( const wxString &filename ) +{ + m_filenames.Add( filename ); +} + // ---------------------------------------------------------------------------- // wxBitmapDataObject // ---------------------------------------------------------------------------- @@ -248,6 +266,8 @@ bool wxBitmapDataObject::SetData(size_t size, const void *buf) } m_bitmap = image.ConvertToBitmap(); + + return m_bitmap.Ok(); } void wxBitmapDataObject::DoConvertToPng() @@ -268,51 +288,4 @@ void wxBitmapDataObject::DoConvertToPng() handler.SaveFile( &image, mstream ); } -// ---------------------------------------------------------------------------- -// wxPrivateDataObject -// ---------------------------------------------------------------------------- - -IMPLEMENT_CLASS( wxPrivateDataObject, wxDataObject ) - -void wxPrivateDataObject::Free() -{ - if ( m_data ) - free(m_data); -} - -wxPrivateDataObject::wxPrivateDataObject() -{ - wxString id = wxT("application/"); - id += wxTheApp->GetAppName(); - - m_format.SetId( id ); - - m_size = 0; - m_data = (void *)NULL; -} - -void wxPrivateDataObject::SetData( const void *data, size_t size ) -{ - Free(); - - m_size = size; - m_data = malloc(size); - - memcpy( m_data, data, size ); -} - -void wxPrivateDataObject::WriteData( void *dest ) const -{ - WriteData( m_data, dest ); -} - -size_t wxPrivateDataObject::GetSize() const -{ - return m_size; -} - -void wxPrivateDataObject::WriteData( const void *data, void *dest ) const -{ - memcpy( dest, data, GetSize() ); -} diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index db461c3d44..f59b86d330 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -349,35 +349,27 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget), // wxDropTarget //---------------------------------------------------------------------------- -wxDropTarget::wxDropTarget( wxDataObject *data ) +wxDropTarget::wxDropTarget( wxDataObject *data ) + : wxDropTargetBase( data ) { m_firstMotion = TRUE; m_dragContext = (GdkDragContext*) NULL; m_dragWidget = (GtkWidget*) NULL; m_dragData = (GtkSelectionData*) NULL; m_dragTime = 0; - m_data = data; -} - -wxDropTarget::~wxDropTarget() -{ } bool wxDropTarget::OnEnter( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); } -void wxDropTarget::OnLeave() -{ -} - bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); @@ -385,7 +377,7 @@ bool wxDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; return (GetMatchingPair() != (GdkAtom) 0); @@ -393,7 +385,7 @@ bool wxDropTarget::OnDrop( int WXUNUSED(x), int WXUNUSED(y) ) bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) { - if (!m_data) + if (!m_dataObject) return FALSE; if (GetMatchingPair() == (GdkAtom) 0) @@ -404,7 +396,7 @@ bool wxDropTarget::OnData( int WXUNUSED(x), int WXUNUSED(y) ) GdkAtom wxDropTarget::GetMatchingPair() { - if (!m_data) + if (!m_dataObject) return (GdkAtom) 0; if (!m_dragContext) @@ -420,7 +412,7 @@ GdkAtom wxDropTarget::GetMatchingPair() char *name = gdk_atom_name( formatAtom ); if (name) wxLogDebug( "Drop target: drag has format: %s", name ); #endif - if (m_data->IsSupportedFormat( format )) + if (m_dataObject->IsSupportedFormat( format )) return formatAtom; child = child->next; @@ -434,25 +426,25 @@ bool wxDropTarget::GetData() if (!m_dragData) return FALSE; - if (!m_data) + if (!m_dataObject) return FALSE; wxDataFormat dragFormat( m_dragData->target ); - if (!m_data->IsSupportedFormat( dragFormat )) + if (!m_dataObject->IsSupportedFormat( dragFormat )) return FALSE; if (dragFormat.GetType() == wxDF_TEXT) { - wxTextDataObject *text_object = (wxTextDataObject*)m_data; + wxTextDataObject *text_object = (wxTextDataObject*)m_dataObject; text_object->SetText( (const char*)m_dragData->data ); return TRUE; } if (dragFormat.GetType() == wxDF_FILENAME) { - wxFileDataObject *file_object = (wxFileDataObject*)m_data; - file_object->SetFiles( (const char*)m_dragData->data ); + wxFileDataObject *file_object = (wxFileDataObject*)m_dataObject; + file_object->SetData( 0, (const char*)m_dragData->data ); return TRUE; } @@ -633,7 +625,6 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop m_widget = win->m_widget; if (win->m_wxwindow) m_widget = win->m_wxwindow; - m_data = (wxDataObject*) NULL; m_retValue = wxDragCancel; m_defaultCursor = wxCursor( wxCURSOR_NO_ENTRY ); @@ -649,14 +640,14 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, const wxIcon &go, const wxIcon &stop ) { m_waiting = TRUE; + + SetData( data ); 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 ); @@ -666,19 +657,8 @@ wxDropSource::wxDropSource( wxDataObject& data, wxWindow *win, if (wxNullIcon == stop) m_stopIcon = wxIcon( gv_xpm ); } -void wxDropSource::SetData( wxDataObject& data ) -{ - if (m_data) - delete m_data; - - m_data = &data; -} - wxDropSource::~wxDropSource() { - if (m_data) -// delete m_data; - g_blockEventsOnDrag = FALSE; } @@ -701,7 +681,7 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 ); wxDataFormat *array = new wxDataFormat[ m_data->GetFormatCount() ]; - m_data->GetAllFormats( array, TRUE ); + m_data->GetAllFormats( array ); for (size_t i = 0; i < m_data->GetFormatCount(); i++) { GdkAtom atom = array[i]; -- 2.45.2