Drag works.

Drop works,
  Drag'n'Drop doesn't work.


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@2147 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
1999-04-13 16:46:55 +00:00
parent fde7d98ecd
commit 4ba47b4019
4 changed files with 360 additions and 98 deletions

View File

@@ -94,6 +94,8 @@ public:
wxIcon m_goIcon; wxIcon m_goIcon;
wxIcon m_stopIcon; wxIcon m_stopIcon;
bool m_waiting;
}; };
#include "gtk/gtk.h" #include "gtk/gtk.h"

View File

@@ -94,6 +94,8 @@ public:
wxIcon m_goIcon; wxIcon m_goIcon;
wxIcon m_stopIcon; wxIcon m_stopIcon;
bool m_waiting;
}; };
#include "gtk/gtk.h" #include "gtk/gtk.h"

View File

@@ -128,6 +128,7 @@ static char * page_xpm[] = {
#include "gtk/gtkdnd.h" #include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h" #include "gtk/gtkselection.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// "drag_leave" // "drag_leave"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -211,6 +212,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
the drop, call gtk_drag_finish() with success == FALSE the drop, call gtk_drag_finish() with success == FALSE
otherwise call gtk_drag_data_get()" */ otherwise call gtk_drag_data_get()" */
// printf( "drop.\n" );
/* this seems to make a difference between not accepting /* this seems to make a difference between not accepting
due to wrong target area and due to wrong format. let due to wrong target area and due to wrong format. let
us hope that this is not required.. */ us hope that this is not required.. */
@@ -274,6 +277,8 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
/* Owen Taylor: "call gtk_drag_finish() with /* Owen Taylor: "call gtk_drag_finish() with
success == TRUE" */ success == TRUE" */
// printf( "data received.\n" );
/* strangely, we get a "drag_data_received" event even when /* strangely, we get a "drag_data_received" event even when
we don't request them. this checks this. */ we don't request them. this checks this. */
if (!drop_target->m_currentDataObject) return; if (!drop_target->m_currentDataObject) return;
@@ -362,8 +367,8 @@ bool wxDropTarget::IsSupported( wxDataFormat format )
{ {
GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data); GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data);
/* char *name = gdk_atom_name( formatAtom ); // char *name = gdk_atom_name( formatAtom );
if (name) printf( "Format available: %s.\n", name ); */ // if (name) printf( "Format available: %s.\n", name );
if (formatAtom == format.GetAtom()) return TRUE; if (formatAtom == format.GetAtom()) return TRUE;
child = child->next; child = child->next;
@@ -387,8 +392,13 @@ bool wxDropTarget::GetData( wxDataObject *data )
m_dragTime ); m_dragTime );
/* wait for the "drag_data_received" event */ /* wait for the "drag_data_received" event */
// printf( "pre wait.\n" );
m_waiting = TRUE; m_waiting = TRUE;
while (m_waiting) gtk_main_iteration(); while (m_waiting) wxYield();
// printf( "post wait.\n" );
m_currentDataObject = (wxDataObject*) NULL; m_currentDataObject = (wxDataObject*) NULL;
@@ -542,14 +552,99 @@ void wxFileDropTarget::OnData( int x, int y )
free( files ); free( files );
} }
//------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxDropSource // "drag_data_get"
//------------------------------------------------------------------------- //----------------------------------------------------------------------------
static void
source_drag_data_get (GtkWidget *WXUNUSED(widget),
GdkDragContext *context,
GtkSelectionData *selection_data,
guint WXUNUSED(info),
guint WXUNUSED(time),
wxDropSource *drop_source )
{
char *name = gdk_atom_name( selection_data->target );
if (name) printf( "Format requested: %s.\n", name );
wxNode *node = drop_source->m_data->m_dataObjects.First();
while (node)
{
wxDataObject *data_object = (wxDataObject*) node->Data();
if (data_object->GetFormat().GetAtom() == selection_data->target)
{
size_t data_size = data_object->GetSize();
if (data_size > 0)
{
guchar *buffer = new guchar[data_size];
data_object->WriteData( buffer );
gtk_selection_data_set( selection_data,
selection_data->target,
8, /* 8-bit */
buffer,
data_size );
free( buffer );
/* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy;
return;
}
}
node = node->Next();
}
drop_source->m_retValue = wxDragCancel;
}
//----------------------------------------------------------------------------
// "drag_data_delete"
//----------------------------------------------------------------------------
static void source_drag_data_delete( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *drop_source )
{
// printf( "Delete the data!\n" );
drop_source->m_retValue = wxDragMove;
}
//----------------------------------------------------------------------------
// "drag_begin"
//----------------------------------------------------------------------------
static void source_drag_begin( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *WXUNUSED(drop_source) )
{
// printf( "drag_begin.\n" );
}
//----------------------------------------------------------------------------
// "drag_end"
//----------------------------------------------------------------------------
static void source_drag_end( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *drop_source )
{
// printf( "drag_end.\n" );
drop_source->m_waiting = FALSE;
}
//---------------------------------------------------------------------------
// wxDropSource
//---------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop ) wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop )
{ {
g_blockEventsOnDrag = TRUE; g_blockEventsOnDrag = TRUE;
m_waiting = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
@@ -569,7 +664,7 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop ) wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop )
{ {
g_blockEventsOnDrag = TRUE; m_waiting = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
@@ -597,8 +692,6 @@ wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go,
wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win ) wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
{ {
g_blockEventsOnDrag = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
@@ -645,53 +738,89 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
if (!m_data) return (wxDragResult) wxDragNone; if (!m_data) return (wxDragResult) wxDragNone;
static GtkWidget *drag_icon = (GtkWidget*) NULL; g_blockEventsOnDrag = TRUE;
static GtkWidget *drop_icon = (GtkWidget*) NULL;
GdkPoint hotspot_1 = {0,-5 }; RegisterWindow();
if (!drag_icon) m_waiting = TRUE;
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
gtk_target_list_add( target_list, gdk_atom_intern( "STRING", FALSE ), 0, 0 );
GdkEventMotion event;
event.window = m_widget->window;
int x = 0;
int y = 0;
GdkModifierType state;
gdk_window_get_pointer( event.window, &x, &y, &state );
event.x = x;
event.y = y;
event.state = state;
/* GTK wants to know which button was pressed which caused the dragging */
int button_number = 0;
if (event.state & GDK_BUTTON1_MASK) button_number = 1;
else if (event.state & GDK_BUTTON2_MASK) button_number = 2;
else if (event.state & GDK_BUTTON3_MASK) button_number = 3;
/* don't start dragging if no button is down */
if (button_number)
{ {
/* GdkDragContext *context = gtk_drag_begin( m_widget,
drag_icon = shape_create_icon ( m_stopIcon, target_list,
440, 140, 0,0, GTK_WINDOW_POPUP); GDK_ACTION_COPY,
button_number, /* number of mouse button which started drag */
(GdkEvent*) &event );
gtk_signal_connect (GTK_OBJECT (drag_icon), "destroy", wxMask *mask = m_goIcon.GetMask();
GTK_SIGNAL_FUNC(gtk_widget_destroyed), GdkBitmap *bm = (GdkBitmap *) NULL;
&drag_icon); if (mask) bm = mask->GetBitmap();
GdkPixmap *pm = m_goIcon.GetPixmap();
gtk_widget_hide (drag_icon); gtk_drag_set_icon_pixmap( context,
*/ gtk_widget_get_colormap( m_widget ),
pm,
bm,
0,
0 );
while (m_waiting) wxYield();
} }
GdkPoint hotspot_2 = {-5,-5}; g_blockEventsOnDrag = FALSE;
if (!drop_icon) UnregisterWindow();
{
/*
drop_icon = shape_create_icon ( m_goIcon,
440, 140, 0,0, GTK_WINDOW_POPUP);
gtk_signal_connect (GTK_OBJECT (drop_icon), "destroy", return m_retValue;
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&drop_icon);
gtk_widget_hide (drop_icon);
*/
} }
void wxDropSource::RegisterWindow()
return FALSE;
}
void wxDropSource::RegisterWindow(void)
{
if (!m_data) return;
}
void wxDropSource::UnregisterWindow(void)
{ {
if (!m_widget) return; if (!m_widget) return;
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_data_get",
GTK_SIGNAL_FUNC (source_drag_data_get), (gpointer) this);
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_data_delete",
GTK_SIGNAL_FUNC (source_drag_data_delete), (gpointer) this );
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_begin",
GTK_SIGNAL_FUNC (source_drag_begin), (gpointer) this );
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_end",
GTK_SIGNAL_FUNC (source_drag_end), (gpointer) this );
}
void wxDropSource::UnregisterWindow()
{
if (!m_widget) return;
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_data_get), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_data_delete), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_begin), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_end), (gpointer) this );
} }

View File

@@ -128,6 +128,7 @@ static char * page_xpm[] = {
#include "gtk/gtkdnd.h" #include "gtk/gtkdnd.h"
#include "gtk/gtkselection.h" #include "gtk/gtkselection.h"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// "drag_leave" // "drag_leave"
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -211,6 +212,8 @@ static gboolean target_drag_drop( GtkWidget *widget,
the drop, call gtk_drag_finish() with success == FALSE the drop, call gtk_drag_finish() with success == FALSE
otherwise call gtk_drag_data_get()" */ otherwise call gtk_drag_data_get()" */
// printf( "drop.\n" );
/* this seems to make a difference between not accepting /* this seems to make a difference between not accepting
due to wrong target area and due to wrong format. let due to wrong target area and due to wrong format. let
us hope that this is not required.. */ us hope that this is not required.. */
@@ -274,6 +277,8 @@ static void target_drag_data_received( GtkWidget *WXUNUSED(widget),
/* Owen Taylor: "call gtk_drag_finish() with /* Owen Taylor: "call gtk_drag_finish() with
success == TRUE" */ success == TRUE" */
// printf( "data received.\n" );
/* strangely, we get a "drag_data_received" event even when /* strangely, we get a "drag_data_received" event even when
we don't request them. this checks this. */ we don't request them. this checks this. */
if (!drop_target->m_currentDataObject) return; if (!drop_target->m_currentDataObject) return;
@@ -362,8 +367,8 @@ bool wxDropTarget::IsSupported( wxDataFormat format )
{ {
GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data); GdkAtom formatAtom = (GdkAtom) GPOINTER_TO_INT(child->data);
/* char *name = gdk_atom_name( formatAtom ); // char *name = gdk_atom_name( formatAtom );
if (name) printf( "Format available: %s.\n", name ); */ // if (name) printf( "Format available: %s.\n", name );
if (formatAtom == format.GetAtom()) return TRUE; if (formatAtom == format.GetAtom()) return TRUE;
child = child->next; child = child->next;
@@ -387,8 +392,13 @@ bool wxDropTarget::GetData( wxDataObject *data )
m_dragTime ); m_dragTime );
/* wait for the "drag_data_received" event */ /* wait for the "drag_data_received" event */
// printf( "pre wait.\n" );
m_waiting = TRUE; m_waiting = TRUE;
while (m_waiting) gtk_main_iteration(); while (m_waiting) wxYield();
// printf( "post wait.\n" );
m_currentDataObject = (wxDataObject*) NULL; m_currentDataObject = (wxDataObject*) NULL;
@@ -542,14 +552,99 @@ void wxFileDropTarget::OnData( int x, int y )
free( files ); free( files );
} }
//------------------------------------------------------------------------- //----------------------------------------------------------------------------
// wxDropSource // "drag_data_get"
//------------------------------------------------------------------------- //----------------------------------------------------------------------------
static void
source_drag_data_get (GtkWidget *WXUNUSED(widget),
GdkDragContext *context,
GtkSelectionData *selection_data,
guint WXUNUSED(info),
guint WXUNUSED(time),
wxDropSource *drop_source )
{
char *name = gdk_atom_name( selection_data->target );
if (name) printf( "Format requested: %s.\n", name );
wxNode *node = drop_source->m_data->m_dataObjects.First();
while (node)
{
wxDataObject *data_object = (wxDataObject*) node->Data();
if (data_object->GetFormat().GetAtom() == selection_data->target)
{
size_t data_size = data_object->GetSize();
if (data_size > 0)
{
guchar *buffer = new guchar[data_size];
data_object->WriteData( buffer );
gtk_selection_data_set( selection_data,
selection_data->target,
8, /* 8-bit */
buffer,
data_size );
free( buffer );
/* so far only copy, no moves. TODO. */
drop_source->m_retValue = wxDragCopy;
return;
}
}
node = node->Next();
}
drop_source->m_retValue = wxDragCancel;
}
//----------------------------------------------------------------------------
// "drag_data_delete"
//----------------------------------------------------------------------------
static void source_drag_data_delete( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *drop_source )
{
// printf( "Delete the data!\n" );
drop_source->m_retValue = wxDragMove;
}
//----------------------------------------------------------------------------
// "drag_begin"
//----------------------------------------------------------------------------
static void source_drag_begin( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *WXUNUSED(drop_source) )
{
// printf( "drag_begin.\n" );
}
//----------------------------------------------------------------------------
// "drag_end"
//----------------------------------------------------------------------------
static void source_drag_end( GtkWidget *WXUNUSED(widget),
GdkDragContext *WXUNUSED(context),
wxDropSource *drop_source )
{
// printf( "drag_end.\n" );
drop_source->m_waiting = FALSE;
}
//---------------------------------------------------------------------------
// wxDropSource
//---------------------------------------------------------------------------
wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop ) wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop )
{ {
g_blockEventsOnDrag = TRUE; g_blockEventsOnDrag = TRUE;
m_waiting = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
@@ -569,7 +664,7 @@ wxDropSource::wxDropSource( wxWindow *win, const wxIcon &go, const wxIcon &stop
wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop ) wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go, const wxIcon &stop )
{ {
g_blockEventsOnDrag = TRUE; m_waiting = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
@@ -597,8 +692,6 @@ wxDropSource::wxDropSource( wxDataObject *data, wxWindow *win, const wxIcon &go,
wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win ) wxDropSource::wxDropSource( wxDataBroker *data, wxWindow *win )
{ {
g_blockEventsOnDrag = TRUE;
m_window = win; m_window = win;
m_widget = win->m_widget; m_widget = win->m_widget;
if (win->m_wxwindow) m_widget = win->m_wxwindow; if (win->m_wxwindow) m_widget = win->m_wxwindow;
@@ -645,53 +738,89 @@ wxDragResult wxDropSource::DoDragDrop( bool WXUNUSED(bAllowMove) )
if (!m_data) return (wxDragResult) wxDragNone; if (!m_data) return (wxDragResult) wxDragNone;
static GtkWidget *drag_icon = (GtkWidget*) NULL; g_blockEventsOnDrag = TRUE;
static GtkWidget *drop_icon = (GtkWidget*) NULL;
GdkPoint hotspot_1 = {0,-5 }; RegisterWindow();
if (!drag_icon) m_waiting = TRUE;
GtkTargetList *target_list = gtk_target_list_new( (GtkTargetEntry*) NULL, 0 );
gtk_target_list_add( target_list, gdk_atom_intern( "STRING", FALSE ), 0, 0 );
GdkEventMotion event;
event.window = m_widget->window;
int x = 0;
int y = 0;
GdkModifierType state;
gdk_window_get_pointer( event.window, &x, &y, &state );
event.x = x;
event.y = y;
event.state = state;
/* GTK wants to know which button was pressed which caused the dragging */
int button_number = 0;
if (event.state & GDK_BUTTON1_MASK) button_number = 1;
else if (event.state & GDK_BUTTON2_MASK) button_number = 2;
else if (event.state & GDK_BUTTON3_MASK) button_number = 3;
/* don't start dragging if no button is down */
if (button_number)
{ {
/* GdkDragContext *context = gtk_drag_begin( m_widget,
drag_icon = shape_create_icon ( m_stopIcon, target_list,
440, 140, 0,0, GTK_WINDOW_POPUP); GDK_ACTION_COPY,
button_number, /* number of mouse button which started drag */
(GdkEvent*) &event );
gtk_signal_connect (GTK_OBJECT (drag_icon), "destroy", wxMask *mask = m_goIcon.GetMask();
GTK_SIGNAL_FUNC(gtk_widget_destroyed), GdkBitmap *bm = (GdkBitmap *) NULL;
&drag_icon); if (mask) bm = mask->GetBitmap();
GdkPixmap *pm = m_goIcon.GetPixmap();
gtk_widget_hide (drag_icon); gtk_drag_set_icon_pixmap( context,
*/ gtk_widget_get_colormap( m_widget ),
pm,
bm,
0,
0 );
while (m_waiting) wxYield();
} }
GdkPoint hotspot_2 = {-5,-5}; g_blockEventsOnDrag = FALSE;
if (!drop_icon) UnregisterWindow();
{
/*
drop_icon = shape_create_icon ( m_goIcon,
440, 140, 0,0, GTK_WINDOW_POPUP);
gtk_signal_connect (GTK_OBJECT (drop_icon), "destroy", return m_retValue;
GTK_SIGNAL_FUNC(gtk_widget_destroyed),
&drop_icon);
gtk_widget_hide (drop_icon);
*/
} }
void wxDropSource::RegisterWindow()
return FALSE;
}
void wxDropSource::RegisterWindow(void)
{
if (!m_data) return;
}
void wxDropSource::UnregisterWindow(void)
{ {
if (!m_widget) return; if (!m_widget) return;
gtk_signal_connect( GTK_OBJECT(m_widget), "drag_data_get",
GTK_SIGNAL_FUNC (source_drag_data_get), (gpointer) this);
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_data_delete",
GTK_SIGNAL_FUNC (source_drag_data_delete), (gpointer) this );
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_begin",
GTK_SIGNAL_FUNC (source_drag_begin), (gpointer) this );
gtk_signal_connect (GTK_OBJECT(m_widget), "drag_end",
GTK_SIGNAL_FUNC (source_drag_end), (gpointer) this );
}
void wxDropSource::UnregisterWindow()
{
if (!m_widget) return;
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_data_get), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_data_delete), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_begin), (gpointer) this );
gtk_signal_disconnect_by_func( GTK_OBJECT(m_widget),
GTK_SIGNAL_FUNC(source_drag_end), (gpointer) this );
} }