From d6086ea66340f82b3a4988c820cb351d128fe0d1 Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Tue, 6 Apr 1999 17:24:14 +0000 Subject: [PATCH] Changed clipboard text format id from "STRING" to "TEXT" DnD might now actually compile (but nothing else) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/dnd.h | 230 +++++++++++++++++++++--------- include/wx/gtk1/dnd.h | 230 +++++++++++++++++++++--------- src/gtk/clipbrd.cpp | 2 - src/gtk/dataobj.cpp | 20 ++- src/gtk/dnd.cpp | 315 +++++++++++++++++------------------------- src/gtk1/clipbrd.cpp | 2 - src/gtk1/dataobj.cpp | 20 ++- src/gtk1/dnd.cpp | 315 +++++++++++++++++------------------------- src/unix/utilsunx.cpp | 2 +- 9 files changed, 619 insertions(+), 517 deletions(-) diff --git a/include/wx/gtk/dnd.h b/include/wx/gtk/dnd.h index 2eccb9c9d6..3c918bad23 100644 --- a/include/wx/gtk/dnd.h +++ b/include/wx/gtk/dnd.h @@ -17,14 +17,6 @@ #include "wx/defs.h" -//------------------------------------------------------------------------- -// conditional compilation -//------------------------------------------------------------------------- - -#if (GTK_MINOR_VERSION > 0) -#define NEW_GTK_DND_CODE -#endif - #if wxUSE_DRAG_AND_DROP #include "wx/object.h" @@ -47,6 +39,172 @@ class wxPrivateDropTarget; class wxDropSource; +//------------------------------------------------------------------------- +// wxDropSource +//------------------------------------------------------------------------- + +enum wxDragResult +{ + wxDragError, // error prevented the d&d operation from completing + wxDragNone, // drag target didn't accept the data + wxDragCopy, // the data was successfully copied + wxDragMove, // the data was successfully moved (MSW only) + wxDragCancel // the operation was cancelled by user (not an error) +}; + +class wxDropSource: public wxObject +{ +public: + + /* 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 ); + + /* start drag action */ + wxDragResult DoDragDrop( bool bAllowMove = FALSE ); + + /* override to give feedback */ + virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } + + /* GTK implementation */ + + void RegisterWindow(); + void UnregisterWindow(); + + GtkWidget *m_widget; + wxWindow *m_window; + wxDragResult m_retValue; + wxDataBroker *m_data; + + wxCursor m_defaultCursor; + wxCursor m_goaheadCursor; + + wxIcon m_goIcon; + wxIcon m_stopIcon; +}; + +#include "gtk/gtk.h" +#if (GTK_MINOR_VERSION > 0) + +//------------------------------------------------------------------------- +// wxDropTarget +//------------------------------------------------------------------------- + +class wxDropTarget: public wxObject +{ +public: + + wxDropTarget(); + ~wxDropTarget(); + + /* may be overridden to react to events */ + virtual void OnEnter(); + virtual void OnLeave(); + virtual bool OnMove( int x, int y ); + + /* has te be overridden to get data */ + virtual bool OnDrop( int x, int y ); + + /* called to query formats available */ + bool IsSupported( wxDataFormat format ); + + /* fill data with data on the clipboard (if available) */ + bool GetData( wxDataObject *data ); + +// implementation + + void RegisterWidget( GtkWidget *widget ); + void UnregisterWidget( GtkWidget *widget ); + + GdkDragContext *m_dragContext; + + void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } + GdkDragContext *GetDragContext() { return m_dragContext; } +}; + +//------------------------------------------------------------------------- +// wxTextDropTarget +//------------------------------------------------------------------------- + +class wxTextDropTarget: public wxDropTarget +{ +public: + + wxTextDropTarget() {} + + virtual bool OnMove( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropData to get at the text */ + virtual bool OnDropText( int x, int y, const char *text ) = 0; + +}; + +//------------------------------------------------------------------------- +// 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( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropData to get at the data */ + virtual bool OnDropData( int x, int 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; } + +private: + + wxString m_id; +}; + +//---------------------------------------------------------------------------- +// A drop target which accepts files (dragged from File Manager or Explorer) +//---------------------------------------------------------------------------- + +class wxFileDropTarget: public wxDropTarget +{ +public: + + wxFileDropTarget() {} + + virtual bool OnMove( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropFiles to get at the file names */ + virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0; + +}; + +#else + //------------------------------------------------------------------------- // wxDropTarget //------------------------------------------------------------------------- @@ -141,62 +299,8 @@ class wxFileDropTarget: public wxDropTarget virtual size_t GetFormatCount() const; }; -//------------------------------------------------------------------------- -// wxDropSource -//------------------------------------------------------------------------- - -enum wxDragResult -{ - wxDragError, // error prevented the d&d operation from completing - wxDragNone, // drag target didn't accept the data - wxDragCopy, // the data was successfully copied - wxDragMove, // the data was successfully moved (MSW only) - wxDragCancel // the operation was cancelled by user (not an error) -}; - -class wxDropSource: public wxObject -{ - public: +#endif - /* 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(void); - - /* set one dataobject */ - void SetData( wxDataBroker *data ); - - /* set severa dataobjects via wxDataBroker */ - void SetData( wxDataObject *data ); - - /* start drag action */ - wxDragResult DoDragDrop( bool bAllowMove = FALSE ); - - /* override to give feedback */ - virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } - - /* GTK implementation */ - - void RegisterWindow(void); - void UnregisterWindow(void); - - GtkWidget *m_widget; - wxWindow *m_window; - wxDragResult m_retValue; - wxDataBroker *m_data; - - wxCursor m_defaultCursor; - wxCursor m_goaheadCursor; - - wxIcon m_goIcon; - wxIcon m_stopIcon; -}; #endif diff --git a/include/wx/gtk1/dnd.h b/include/wx/gtk1/dnd.h index 2eccb9c9d6..3c918bad23 100644 --- a/include/wx/gtk1/dnd.h +++ b/include/wx/gtk1/dnd.h @@ -17,14 +17,6 @@ #include "wx/defs.h" -//------------------------------------------------------------------------- -// conditional compilation -//------------------------------------------------------------------------- - -#if (GTK_MINOR_VERSION > 0) -#define NEW_GTK_DND_CODE -#endif - #if wxUSE_DRAG_AND_DROP #include "wx/object.h" @@ -47,6 +39,172 @@ class wxPrivateDropTarget; class wxDropSource; +//------------------------------------------------------------------------- +// wxDropSource +//------------------------------------------------------------------------- + +enum wxDragResult +{ + wxDragError, // error prevented the d&d operation from completing + wxDragNone, // drag target didn't accept the data + wxDragCopy, // the data was successfully copied + wxDragMove, // the data was successfully moved (MSW only) + wxDragCancel // the operation was cancelled by user (not an error) +}; + +class wxDropSource: public wxObject +{ +public: + + /* 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 ); + + /* start drag action */ + wxDragResult DoDragDrop( bool bAllowMove = FALSE ); + + /* override to give feedback */ + virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } + + /* GTK implementation */ + + void RegisterWindow(); + void UnregisterWindow(); + + GtkWidget *m_widget; + wxWindow *m_window; + wxDragResult m_retValue; + wxDataBroker *m_data; + + wxCursor m_defaultCursor; + wxCursor m_goaheadCursor; + + wxIcon m_goIcon; + wxIcon m_stopIcon; +}; + +#include "gtk/gtk.h" +#if (GTK_MINOR_VERSION > 0) + +//------------------------------------------------------------------------- +// wxDropTarget +//------------------------------------------------------------------------- + +class wxDropTarget: public wxObject +{ +public: + + wxDropTarget(); + ~wxDropTarget(); + + /* may be overridden to react to events */ + virtual void OnEnter(); + virtual void OnLeave(); + virtual bool OnMove( int x, int y ); + + /* has te be overridden to get data */ + virtual bool OnDrop( int x, int y ); + + /* called to query formats available */ + bool IsSupported( wxDataFormat format ); + + /* fill data with data on the clipboard (if available) */ + bool GetData( wxDataObject *data ); + +// implementation + + void RegisterWidget( GtkWidget *widget ); + void UnregisterWidget( GtkWidget *widget ); + + GdkDragContext *m_dragContext; + + void SetDragContext( GdkDragContext *dc ) { m_dragContext = dc; } + GdkDragContext *GetDragContext() { return m_dragContext; } +}; + +//------------------------------------------------------------------------- +// wxTextDropTarget +//------------------------------------------------------------------------- + +class wxTextDropTarget: public wxDropTarget +{ +public: + + wxTextDropTarget() {} + + virtual bool OnMove( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropData to get at the text */ + virtual bool OnDropText( int x, int y, const char *text ) = 0; + +}; + +//------------------------------------------------------------------------- +// 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( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropData to get at the data */ + virtual bool OnDropData( int x, int 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; } + +private: + + wxString m_id; +}; + +//---------------------------------------------------------------------------- +// A drop target which accepts files (dragged from File Manager or Explorer) +//---------------------------------------------------------------------------- + +class wxFileDropTarget: public wxDropTarget +{ +public: + + wxFileDropTarget() {} + + virtual bool OnMove( int x, int y ); + virtual bool OnDrop( int x, int y ); + + /* you have to override OnDropFiles to get at the file names */ + virtual bool OnDropFiles( int x, int y, size_t nFiles, const char * const aszFiles[] ) = 0; + +}; + +#else + //------------------------------------------------------------------------- // wxDropTarget //------------------------------------------------------------------------- @@ -141,62 +299,8 @@ class wxFileDropTarget: public wxDropTarget virtual size_t GetFormatCount() const; }; -//------------------------------------------------------------------------- -// wxDropSource -//------------------------------------------------------------------------- - -enum wxDragResult -{ - wxDragError, // error prevented the d&d operation from completing - wxDragNone, // drag target didn't accept the data - wxDragCopy, // the data was successfully copied - wxDragMove, // the data was successfully moved (MSW only) - wxDragCancel // the operation was cancelled by user (not an error) -}; - -class wxDropSource: public wxObject -{ - public: +#endif - /* 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(void); - - /* set one dataobject */ - void SetData( wxDataBroker *data ); - - /* set severa dataobjects via wxDataBroker */ - void SetData( wxDataObject *data ); - - /* start drag action */ - wxDragResult DoDragDrop( bool bAllowMove = FALSE ); - - /* override to give feedback */ - virtual bool GiveFeedback( wxDragResult WXUNUSED(effect), bool WXUNUSED(bScrolling) ) { return TRUE; } - - /* GTK implementation */ - - void RegisterWindow(void); - void UnregisterWindow(void); - - GtkWidget *m_widget; - wxWindow *m_window; - wxDragResult m_retValue; - wxDataBroker *m_data; - - wxCursor m_defaultCursor; - wxCursor m_goaheadCursor; - - wxIcon m_goIcon; - wxIcon m_stopIcon; -}; #endif diff --git a/src/gtk/clipbrd.cpp b/src/gtk/clipbrd.cpp index 1e061e3201..9dd96f96b6 100644 --- a/src/gtk/clipbrd.cpp +++ b/src/gtk/clipbrd.cpp @@ -25,7 +25,6 @@ wxClipboard *wxTheClipboard = (wxClipboard*) NULL; -GdkAtom g_textAtom = 0; GdkAtom g_clipboardAtom = 0; GdkAtom g_targetsAtom = 0; @@ -295,7 +294,6 @@ wxClipboard::wxClipboard() (gpointer) NULL ); if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE ); - if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE); m_formatSupported = FALSE; diff --git a/src/gtk/dataobj.cpp b/src/gtk/dataobj.cpp index 331a728254..a3ed60aa98 100644 --- a/src/gtk/dataobj.cpp +++ b/src/gtk/dataobj.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" + +//------------------------------------------------------------------------- +// global data +//------------------------------------------------------------------------- + +GdkAtom g_textAtom = 0; + //------------------------------------------------------------------------- // wxDataFormat //------------------------------------------------------------------------- @@ -25,6 +32,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject) wxDataFormat::wxDataFormat() { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_type = wxDF_INVALID; m_hasAtom = FALSE; m_atom = (GdkAtom) 0; @@ -32,16 +40,19 @@ wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat( wxDataType type ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); SetType( type ); } wxDataFormat::wxDataFormat( const wxString &id ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); SetId( id ); } wxDataFormat::wxDataFormat( wxDataFormat &format ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_type = format.GetType(); m_id = format.GetId(); m_hasAtom = TRUE; @@ -50,11 +61,12 @@ wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( const GdkAtom atom ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_hasAtom = TRUE; m_atom = atom; - if (m_atom == GDK_TARGET_STRING) + if (m_atom == g_textAtom) { m_type = wxDF_TEXT; } else @@ -79,7 +91,7 @@ void wxDataFormat::SetType( wxDataType type ) if (m_type == wxDF_TEXT) { - m_id = "STRING"; + m_id = "TEXT"; } else if (m_type == wxDF_BITMAP) @@ -124,8 +136,8 @@ GdkAtom wxDataFormat::GetAtom() if (m_type == wxDF_TEXT) { - m_atom = GDK_TARGET_STRING; - } + m_atom = g_textAtom; + } else if (m_type == wxDF_BITMAP) { diff --git a/src/gtk/dnd.cpp b/src/gtk/dnd.cpp index 5ea4529238..08aa539a42 100644 --- a/src/gtk/dnd.cpp +++ b/src/gtk/dnd.cpp @@ -33,7 +33,7 @@ extern bool g_blockEventsOnDrag; -#ifdef NEW_GTK_DND_CODE +#if (GTK_MINOR_VERSION > 0) #include "gtk/gtkdnd.h" #include "gtk/gtkselection.h" @@ -43,10 +43,13 @@ extern bool g_blockEventsOnDrag; // ---------------------------------------------------------------------------- static void target_drag_leave( GtkWidget *WXUNUSED(widget), - GdkDragContext *WXUNUSED(context), - guint WXUNUSED(time) ) + GdkDragContext *context, + guint WXUNUSED(time), + wxDropTarget *dt ) { - printf( "leave.\n" ); + dt->SetDragContext( context ); + dt->OnLeave(); + dt->SetDragContext( (GdkDragContext*) NULL ); } // ---------------------------------------------------------------------------- @@ -55,12 +58,23 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget), static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), GdkDragContext *context, - gint WXUNUSED(x), - gint WXUNUSED(y), - guint time ) + gint x, + gint y, + guint time, + wxDropTarget *dt ) { - printf( "motion.\n" ); - gdk_drag_status( context, context->suggested_action, time ); + dt->SetDragContext( context ); + + if (dt->OnMove( x, y )) + { + gdk_drag_status( context, context->suggested_action, time ); + } + else + { + gdk_drag_status( context, (GdkDragAction)0, time ); + } + + dt->SetDragContext( (GdkDragContext*) NULL ); return TRUE; } @@ -123,259 +137,182 @@ wxDropTarget::~wxDropTarget() { } +void wxDropTarget::OnEnter() +{ +} + +void wxDropTarget::OnLeave() +{ +} + +bool wxDropTarget::OnMove( int x, int y ) +{ + printf( "mouse move %d %d.\n", x, y ); + return TRUE; +} + +bool wxDropTarget::OnDrop( int x, int y ) +{ + printf( "mouse move %d %d.\n", x, y ); + return TRUE; +} + +bool wxDropTarget::IsSupported( wxDataFormat format ) +{ + return TRUE; +} + +bool wxDropTarget::GetData( wxDataObject *data ) +{ + return FALSE; +} + void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); + wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); - gtk_drag_dest_set( widget, + gtk_drag_dest_set( widget, (GtkDestDefaults) 0, (GtkTargetEntry*) NULL, 0, (GdkDragAction) 0 ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, "register widget is NULL" ); - - GtkTargetEntry format; - format.info = 0; - format.flags = 0; - char buf[100]; + wxCHECK_RET( widget != NULL, "register widget is NULL" ); - int valid = 0; - for ( size_t i = 0; i < GetFormatCount(); i++ ) - { - wxDataFormat df = GetFormat( i ); - switch (df) - { - case wxDF_TEXT: - format.target = "text/plain"; - valid++; - break; - case wxDF_FILENAME: - format.target = "file:ALL"; - valid++; - break; - case wxDF_PRIVATE: - wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this; - strcpy( buf, WXSTRINGCAST pdt->GetID() ); - format.target = buf; - valid++; - default: - break; - } - } + GtkTargetEntry format; + format.info = 0; + format.flags = 0; + char buf[100]; + strcpy( buf, "text/plain" ); - wxASSERT_MSG( valid != 0, "No valid DnD format supported." ); - - gtk_drag_dest_set( widget, + gtk_drag_dest_set( widget, GTK_DEST_DEFAULT_ALL, &format, 1, (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE) ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", + gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", + gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", + gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", + gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } -// ---------------------------------------------------------------------------- +//------------------------------------------------------------------------- // wxTextDropTarget -// ---------------------------------------------------------------------------- - -bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) -{ - OnDropText( x, y, (const char*)data ); - return TRUE; -} - -bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) -{ - printf( "Got dropped text: %s.\n", psz ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - return TRUE; -} +//------------------------------------------------------------------------- -size_t wxTextDropTarget::GetFormatCount() const +bool wxTextDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - return 1; + return IsSupported( wxDF_TEXT ); // same as "TEXT" } -wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const +bool wxTextDropTarget::OnDrop( int x, int y ) { - return wxDF_TEXT; -} + if (!IsSupported( wxDF_TEXT )) return FALSE; -// ---------------------------------------------------------------------------- -// wxFileDropTarget -// ---------------------------------------------------------------------------- - -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) -{ - printf( "Got %d dropped files.\n", (int)nFiles ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - for (size_t i = 0; i < nFiles; i++) - { - printf( aszFiles[i] ); - printf( "\n" ); - } - return TRUE; -} - -bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) -{ - size_t number = 0; - size_t i; - char *text = (char*) data; - for (i = 0; i < size; i++) - if (text[i] == 0) number++; - - if (number == 0) return TRUE; + wxTextDataObject data; + if (!GetData( &data )) return FALSE; - char **files = new char*[number]; - - text = (char*) data; - for (i = 0; i < number; i++) - { - files[i] = text; - int len = strlen( text ); - text += len+1; - } - - bool ret = OnDropFiles( x, y, 1, files ); - - free( files ); - - return ret; -} - -size_t wxFileDropTarget::GetFormatCount() const -{ - return 1; -} - -wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const -{ - return wxDF_FILENAME; + return OnDropText( x, y, data.GetText() ); } //------------------------------------------------------------------------- -// wxDropSource +// wxPrivateDropTarget //------------------------------------------------------------------------- -wxDropSource::wxDropSource( wxWindow *win ) +wxPrivateDropTarget::wxPrivateDropTarget() { - g_blockEventsOnDrag = TRUE; - - m_window = win; - 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 ); - m_goaheadCursor = wxCursor( wxCURSOR_HAND ); + m_id = wxTheApp->GetAppName(); } -wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win ) +wxPrivateDropTarget::wxPrivateDropTarget( const wxString &id ) { - g_blockEventsOnDrag = TRUE; - - 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 ); + m_id = id; } -void wxDropSource::SetData( wxDataObject &data ) +bool wxPrivateDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - m_data = &data; + return IsSupported( m_id ); } -wxDropSource::~wxDropSource(void) +bool wxPrivateDropTarget::OnDrop( int x, int y ) { -// if (m_data) delete m_data; + if (!IsSupported( m_id )) return FALSE; - g_blockEventsOnDrag = FALSE; + wxPrivateDataObject data; + if (!GetData( &data )) return FALSE; + + return OnDropData( x, y, data.GetData(), data.GetSize() ); } - -wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) + +//---------------------------------------------------------------------------- +// A drop target which accepts files (dragged from File Manager or Explorer) +//---------------------------------------------------------------------------- + +bool wxFileDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - wxASSERT_MSG( m_data, "wxDragSource: no data" ); - - if (!m_data) return (wxDragResult) wxDragNone; - if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone; - - RegisterWindow(); - - // TODO - - UnregisterWindow(); - - g_blockEventsOnDrag = FALSE; - - return m_retValue; + return IsSupported( wxDF_FILENAME ); // same as "file:ALL" } -void wxDropSource::RegisterWindow(void) +bool wxFileDropTarget::OnDrop( int x, int y ) { - if (!m_data) return; + if (!IsSupported( wxDF_FILENAME )) return FALSE; + + wxFileDataObject data; + if (!GetData( &data )) return FALSE; - wxString formats; + /* 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 *text = WXSTRINGCAST data.GetFiles(); + for ( i = 0; i < size; i++) + if (text[i] == 0) number++; + + if (number == 0) return TRUE; - wxDataFormat df = m_data->GetPreferredFormat(); + char **files = new char*[number]; - switch (df) + text = WXSTRINGCAST data.GetFiles(); + for (i = 0; i < number; i++) { - case wxDF_TEXT: - formats += "text/plain"; - break; - case wxDF_FILENAME: - formats += "file:ALL"; - break; - default: - break; + files[i] = text; + int len = strlen( text ); + text += len+1; } - - char *str = WXSTRINGCAST formats; - - // TODO -} -void wxDropSource::UnregisterWindow(void) -{ - if (!m_widget) return; + bool ret = OnDropFiles( x, y, number, files ); + + free( files ); - // TODO + return ret; } +//------------------------------------------------------------------------- +// wxDropSource +//------------------------------------------------------------------------- #else // NEW_CODE diff --git a/src/gtk1/clipbrd.cpp b/src/gtk1/clipbrd.cpp index 1e061e3201..9dd96f96b6 100644 --- a/src/gtk1/clipbrd.cpp +++ b/src/gtk1/clipbrd.cpp @@ -25,7 +25,6 @@ wxClipboard *wxTheClipboard = (wxClipboard*) NULL; -GdkAtom g_textAtom = 0; GdkAtom g_clipboardAtom = 0; GdkAtom g_targetsAtom = 0; @@ -295,7 +294,6 @@ wxClipboard::wxClipboard() (gpointer) NULL ); if (!g_clipboardAtom) g_clipboardAtom = gdk_atom_intern( "CLIPBOARD", FALSE ); - if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); if (!g_targetsAtom) g_targetsAtom = gdk_atom_intern ("TARGETS", FALSE); m_formatSupported = FALSE; diff --git a/src/gtk1/dataobj.cpp b/src/gtk1/dataobj.cpp index 331a728254..a3ed60aa98 100644 --- a/src/gtk1/dataobj.cpp +++ b/src/gtk1/dataobj.cpp @@ -17,6 +17,13 @@ #include "gdk/gdk.h" + +//------------------------------------------------------------------------- +// global data +//------------------------------------------------------------------------- + +GdkAtom g_textAtom = 0; + //------------------------------------------------------------------------- // wxDataFormat //------------------------------------------------------------------------- @@ -25,6 +32,7 @@ IMPLEMENT_CLASS(wxDataFormat, wxObject) wxDataFormat::wxDataFormat() { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_type = wxDF_INVALID; m_hasAtom = FALSE; m_atom = (GdkAtom) 0; @@ -32,16 +40,19 @@ wxDataFormat::wxDataFormat() wxDataFormat::wxDataFormat( wxDataType type ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); SetType( type ); } wxDataFormat::wxDataFormat( const wxString &id ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); SetId( id ); } wxDataFormat::wxDataFormat( wxDataFormat &format ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_type = format.GetType(); m_id = format.GetId(); m_hasAtom = TRUE; @@ -50,11 +61,12 @@ wxDataFormat::wxDataFormat( wxDataFormat &format ) wxDataFormat::wxDataFormat( const GdkAtom atom ) { + if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE ); m_hasAtom = TRUE; m_atom = atom; - if (m_atom == GDK_TARGET_STRING) + if (m_atom == g_textAtom) { m_type = wxDF_TEXT; } else @@ -79,7 +91,7 @@ void wxDataFormat::SetType( wxDataType type ) if (m_type == wxDF_TEXT) { - m_id = "STRING"; + m_id = "TEXT"; } else if (m_type == wxDF_BITMAP) @@ -124,8 +136,8 @@ GdkAtom wxDataFormat::GetAtom() if (m_type == wxDF_TEXT) { - m_atom = GDK_TARGET_STRING; - } + m_atom = g_textAtom; + } else if (m_type == wxDF_BITMAP) { diff --git a/src/gtk1/dnd.cpp b/src/gtk1/dnd.cpp index 5ea4529238..08aa539a42 100644 --- a/src/gtk1/dnd.cpp +++ b/src/gtk1/dnd.cpp @@ -33,7 +33,7 @@ extern bool g_blockEventsOnDrag; -#ifdef NEW_GTK_DND_CODE +#if (GTK_MINOR_VERSION > 0) #include "gtk/gtkdnd.h" #include "gtk/gtkselection.h" @@ -43,10 +43,13 @@ extern bool g_blockEventsOnDrag; // ---------------------------------------------------------------------------- static void target_drag_leave( GtkWidget *WXUNUSED(widget), - GdkDragContext *WXUNUSED(context), - guint WXUNUSED(time) ) + GdkDragContext *context, + guint WXUNUSED(time), + wxDropTarget *dt ) { - printf( "leave.\n" ); + dt->SetDragContext( context ); + dt->OnLeave(); + dt->SetDragContext( (GdkDragContext*) NULL ); } // ---------------------------------------------------------------------------- @@ -55,12 +58,23 @@ static void target_drag_leave( GtkWidget *WXUNUSED(widget), static gboolean target_drag_motion( GtkWidget *WXUNUSED(widget), GdkDragContext *context, - gint WXUNUSED(x), - gint WXUNUSED(y), - guint time ) + gint x, + gint y, + guint time, + wxDropTarget *dt ) { - printf( "motion.\n" ); - gdk_drag_status( context, context->suggested_action, time ); + dt->SetDragContext( context ); + + if (dt->OnMove( x, y )) + { + gdk_drag_status( context, context->suggested_action, time ); + } + else + { + gdk_drag_status( context, (GdkDragAction)0, time ); + } + + dt->SetDragContext( (GdkDragContext*) NULL ); return TRUE; } @@ -123,259 +137,182 @@ wxDropTarget::~wxDropTarget() { } +void wxDropTarget::OnEnter() +{ +} + +void wxDropTarget::OnLeave() +{ +} + +bool wxDropTarget::OnMove( int x, int y ) +{ + printf( "mouse move %d %d.\n", x, y ); + return TRUE; +} + +bool wxDropTarget::OnDrop( int x, int y ) +{ + printf( "mouse move %d %d.\n", x, y ); + return TRUE; +} + +bool wxDropTarget::IsSupported( wxDataFormat format ) +{ + return TRUE; +} + +bool wxDropTarget::GetData( wxDataObject *data ) +{ + return FALSE; +} + void wxDropTarget::UnregisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); + wxCHECK_RET( widget != NULL, "unregister widget is NULL" ); - gtk_drag_dest_set( widget, + gtk_drag_dest_set( widget, (GtkDestDefaults) 0, (GtkTargetEntry*) NULL, 0, (GdkDragAction) 0 ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); - gtk_signal_disconnect_by_func( GTK_OBJECT(widget), + gtk_signal_disconnect_by_func( GTK_OBJECT(widget), GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } void wxDropTarget::RegisterWidget( GtkWidget *widget ) { - wxCHECK_RET( widget != NULL, "register widget is NULL" ); - - GtkTargetEntry format; - format.info = 0; - format.flags = 0; - char buf[100]; + wxCHECK_RET( widget != NULL, "register widget is NULL" ); - int valid = 0; - for ( size_t i = 0; i < GetFormatCount(); i++ ) - { - wxDataFormat df = GetFormat( i ); - switch (df) - { - case wxDF_TEXT: - format.target = "text/plain"; - valid++; - break; - case wxDF_FILENAME: - format.target = "file:ALL"; - valid++; - break; - case wxDF_PRIVATE: - wxPrivateDropTarget *pdt = (wxPrivateDropTarget *)this; - strcpy( buf, WXSTRINGCAST pdt->GetID() ); - format.target = buf; - valid++; - default: - break; - } - } + GtkTargetEntry format; + format.info = 0; + format.flags = 0; + char buf[100]; + strcpy( buf, "text/plain" ); - wxASSERT_MSG( valid != 0, "No valid DnD format supported." ); - - gtk_drag_dest_set( widget, + gtk_drag_dest_set( widget, GTK_DEST_DEFAULT_ALL, &format, 1, (GdkDragAction)(GDK_ACTION_COPY | GDK_ACTION_MOVE) ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", + gtk_signal_connect( GTK_OBJECT(widget), "drag_leave", GTK_SIGNAL_FUNC(target_drag_leave), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", + gtk_signal_connect( GTK_OBJECT(widget), "drag_motion", GTK_SIGNAL_FUNC(target_drag_motion), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", + gtk_signal_connect( GTK_OBJECT(widget), "drag_drop", GTK_SIGNAL_FUNC(target_drag_drop), (gpointer) this ); - gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", + gtk_signal_connect( GTK_OBJECT(widget), "drag_data_received", GTK_SIGNAL_FUNC(target_drag_data_received), (gpointer) this ); } -// ---------------------------------------------------------------------------- +//------------------------------------------------------------------------- // wxTextDropTarget -// ---------------------------------------------------------------------------- - -bool wxTextDropTarget::OnDrop( long x, long y, const void *data, size_t WXUNUSED(size) ) -{ - OnDropText( x, y, (const char*)data ); - return TRUE; -} - -bool wxTextDropTarget::OnDropText( long x, long y, const char *psz ) -{ - printf( "Got dropped text: %s.\n", psz ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - return TRUE; -} +//------------------------------------------------------------------------- -size_t wxTextDropTarget::GetFormatCount() const +bool wxTextDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - return 1; + return IsSupported( wxDF_TEXT ); // same as "TEXT" } -wxDataFormat wxTextDropTarget::GetFormat(size_t WXUNUSED(n)) const +bool wxTextDropTarget::OnDrop( int x, int y ) { - return wxDF_TEXT; -} + if (!IsSupported( wxDF_TEXT )) return FALSE; -// ---------------------------------------------------------------------------- -// wxFileDropTarget -// ---------------------------------------------------------------------------- - -bool wxFileDropTarget::OnDropFiles( long x, long y, size_t nFiles, const char * const aszFiles[] ) -{ - printf( "Got %d dropped files.\n", (int)nFiles ); - printf( "At x: %d, y: %d.\n", (int)x, (int)y ); - for (size_t i = 0; i < nFiles; i++) - { - printf( aszFiles[i] ); - printf( "\n" ); - } - return TRUE; -} - -bool wxFileDropTarget::OnDrop(long x, long y, const void *data, size_t size ) -{ - size_t number = 0; - size_t i; - char *text = (char*) data; - for (i = 0; i < size; i++) - if (text[i] == 0) number++; - - if (number == 0) return TRUE; + wxTextDataObject data; + if (!GetData( &data )) return FALSE; - char **files = new char*[number]; - - text = (char*) data; - for (i = 0; i < number; i++) - { - files[i] = text; - int len = strlen( text ); - text += len+1; - } - - bool ret = OnDropFiles( x, y, 1, files ); - - free( files ); - - return ret; -} - -size_t wxFileDropTarget::GetFormatCount() const -{ - return 1; -} - -wxDataFormat wxFileDropTarget::GetFormat(size_t WXUNUSED(n)) const -{ - return wxDF_FILENAME; + return OnDropText( x, y, data.GetText() ); } //------------------------------------------------------------------------- -// wxDropSource +// wxPrivateDropTarget //------------------------------------------------------------------------- -wxDropSource::wxDropSource( wxWindow *win ) +wxPrivateDropTarget::wxPrivateDropTarget() { - g_blockEventsOnDrag = TRUE; - - m_window = win; - 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 ); - m_goaheadCursor = wxCursor( wxCURSOR_HAND ); + m_id = wxTheApp->GetAppName(); } -wxDropSource::wxDropSource( wxDataObject &data, wxWindow *win ) +wxPrivateDropTarget::wxPrivateDropTarget( const wxString &id ) { - g_blockEventsOnDrag = TRUE; - - 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 ); + m_id = id; } -void wxDropSource::SetData( wxDataObject &data ) +bool wxPrivateDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - m_data = &data; + return IsSupported( m_id ); } -wxDropSource::~wxDropSource(void) +bool wxPrivateDropTarget::OnDrop( int x, int y ) { -// if (m_data) delete m_data; + if (!IsSupported( m_id )) return FALSE; - g_blockEventsOnDrag = FALSE; + wxPrivateDataObject data; + if (!GetData( &data )) return FALSE; + + return OnDropData( x, y, data.GetData(), data.GetSize() ); } - -wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) ) + +//---------------------------------------------------------------------------- +// A drop target which accepts files (dragged from File Manager or Explorer) +//---------------------------------------------------------------------------- + +bool wxFileDropTarget::OnMove( int WXUNUSED(x), int WXUNUSED(y) ) { - wxASSERT_MSG( m_data, "wxDragSource: no data" ); - - if (!m_data) return (wxDragResult) wxDragNone; - if (m_data->GetDataSize() == 0) return (wxDragResult) wxDragNone; - - RegisterWindow(); - - // TODO - - UnregisterWindow(); - - g_blockEventsOnDrag = FALSE; - - return m_retValue; + return IsSupported( wxDF_FILENAME ); // same as "file:ALL" } -void wxDropSource::RegisterWindow(void) +bool wxFileDropTarget::OnDrop( int x, int y ) { - if (!m_data) return; + if (!IsSupported( wxDF_FILENAME )) return FALSE; + + wxFileDataObject data; + if (!GetData( &data )) return FALSE; - wxString formats; + /* 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 *text = WXSTRINGCAST data.GetFiles(); + for ( i = 0; i < size; i++) + if (text[i] == 0) number++; + + if (number == 0) return TRUE; - wxDataFormat df = m_data->GetPreferredFormat(); + char **files = new char*[number]; - switch (df) + text = WXSTRINGCAST data.GetFiles(); + for (i = 0; i < number; i++) { - case wxDF_TEXT: - formats += "text/plain"; - break; - case wxDF_FILENAME: - formats += "file:ALL"; - break; - default: - break; + files[i] = text; + int len = strlen( text ); + text += len+1; } - - char *str = WXSTRINGCAST formats; - - // TODO -} -void wxDropSource::UnregisterWindow(void) -{ - if (!m_widget) return; + bool ret = OnDropFiles( x, y, number, files ); + + free( files ); - // TODO + return ret; } +//------------------------------------------------------------------------- +// wxDropSource +//------------------------------------------------------------------------- #else // NEW_CODE diff --git a/src/unix/utilsunx.cpp b/src/unix/utilsunx.cpp index 546a34d86f..e2696eee7b 100644 --- a/src/unix/utilsunx.cpp +++ b/src/unix/utilsunx.cpp @@ -265,7 +265,7 @@ long wxExecute( char **argv, bool sync, wxProcess *process ) // These three lines close the open file descriptors to to avoid any // input/output which might block the process or irritate the user. If - // one wants proper IO for the subprocess, the "right thing to do is + // one wants proper IO for the subprocess, the right thing to do is // to start an xterm executing it. if (sync == 0) { -- 2.45.2