#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"
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
//-------------------------------------------------------------------------
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
#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"
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
//-------------------------------------------------------------------------
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
wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
-GdkAtom g_textAtom = 0;
GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0;
(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;
#include "gdk/gdk.h"
+
+//-------------------------------------------------------------------------
+// global data
+//-------------------------------------------------------------------------
+
+GdkAtom g_textAtom = 0;
+
//-------------------------------------------------------------------------
// wxDataFormat
//-------------------------------------------------------------------------
wxDataFormat::wxDataFormat()
{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = wxDF_INVALID;
m_hasAtom = FALSE;
m_atom = (GdkAtom) 0;
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;
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
if (m_type == wxDF_TEXT)
{
- m_id = "STRING";
+ m_id = "TEXT";
}
else
if (m_type == wxDF_BITMAP)
if (m_type == wxDF_TEXT)
{
- m_atom = GDK_TARGET_STRING;
- }
+ m_atom = g_textAtom;
+ }
else
if (m_type == wxDF_BITMAP)
{
extern bool g_blockEventsOnDrag;
-#ifdef NEW_GTK_DND_CODE
+#if (GTK_MINOR_VERSION > 0)
#include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h"
// ----------------------------------------------------------------------------
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 );
}
// ----------------------------------------------------------------------------
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;
}
{
}
+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
wxClipboard *wxTheClipboard = (wxClipboard*) NULL;
-GdkAtom g_textAtom = 0;
GdkAtom g_clipboardAtom = 0;
GdkAtom g_targetsAtom = 0;
(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;
#include "gdk/gdk.h"
+
+//-------------------------------------------------------------------------
+// global data
+//-------------------------------------------------------------------------
+
+GdkAtom g_textAtom = 0;
+
//-------------------------------------------------------------------------
// wxDataFormat
//-------------------------------------------------------------------------
wxDataFormat::wxDataFormat()
{
+ if (!g_textAtom) g_textAtom = gdk_atom_intern( "TEXT", FALSE );
m_type = wxDF_INVALID;
m_hasAtom = FALSE;
m_atom = (GdkAtom) 0;
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;
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
if (m_type == wxDF_TEXT)
{
- m_id = "STRING";
+ m_id = "TEXT";
}
else
if (m_type == wxDF_BITMAP)
if (m_type == wxDF_TEXT)
{
- m_atom = GDK_TARGET_STRING;
- }
+ m_atom = g_textAtom;
+ }
else
if (m_type == wxDF_BITMAP)
{
extern bool g_blockEventsOnDrag;
-#ifdef NEW_GTK_DND_CODE
+#if (GTK_MINOR_VERSION > 0)
#include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h"
// ----------------------------------------------------------------------------
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 );
}
// ----------------------------------------------------------------------------
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;
}
{
}
+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
// 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)
{