From 4a5bf490ab2a7634b7eefb36af65d542ac5ad0b7 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Tue, 18 Jul 2000 17:02:09 +0000 Subject: [PATCH] r329: Prevent dragging from a pinboard selection to itself, or onto the desktop background. --- ROX-Filer/Help/Changes | 5 +++++ ROX-Filer/Help/TODO | 1 + ROX-Filer/src/dnd.c | 6 +++--- ROX-Filer/src/pinboard.c | 54 +++++++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 60 insertions(+), 6 deletions(-) diff --git a/ROX-Filer/Help/Changes b/ROX-Filer/Help/Changes index 1348d7cd..62945a7a 100644 --- a/ROX-Filer/Help/Changes +++ b/ROX-Filer/Help/Changes @@ -2,6 +2,11 @@ A RISC OS-like filer for X by Thomas Leonard +18-Jul-2000 +~~~~~~~~~~~ +Prevent dragging from a pinboard selection to itself, or onto the desktop +background. + 17-Jul-2000 ~~~~~~~~~~~ Clicking on the root window works (button-1 clears the selection, diff --git a/ROX-Filer/Help/TODO b/ROX-Filer/Help/TODO index 4d8fc571..002c8107 100644 --- a/ROX-Filer/Help/TODO +++ b/ROX-Filer/Help/TODO @@ -8,6 +8,7 @@ someone sends patches!). BUGS +Copy box - should supply text/uri-list? Rename box - use action window (currently doesn't work across file systems) GNOME toolbar diff --git a/ROX-Filer/src/dnd.c b/ROX-Filer/src/dnd.c index 34d7febd..6aa4a71a 100644 --- a/ROX-Filer/src/dnd.c +++ b/ROX-Filer/src/dnd.c @@ -549,7 +549,7 @@ void drag_set_pinboard_dest(GtkWidget *widget) }; gtk_drag_dest_set(widget, - GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, + GTK_DEST_DEFAULT_DROP, target_table, sizeof(target_table) / sizeof(*target_table), GDK_ACTION_LINK); @@ -833,14 +833,14 @@ static void desktop_drag_data_received(GtkWidget *widget, { GSList *uris, *next; gint dx, dy; - + if (!selection_data->data) { /* Timeout? */ return; } - gdk_window_get_position (widget->window, &dx, &dy); + gdk_window_get_position(widget->window, &dx, &dy); x += dx; y += dy; diff --git a/ROX-Filer/src/pinboard.c b/ROX-Filer/src/pinboard.c index ee5e46bf..c7fed60b 100644 --- a/ROX-Filer/src/pinboard.c +++ b/ROX-Filer/src/pinboard.c @@ -101,6 +101,11 @@ typedef enum { } PinDragType; static PinDragType pin_drag_type = DRAG_NONE; +/* This is TRUE while the user is dragging from a pinned icon. + * We use it to prevent dragging from the pinboard to itself. + */ +static gboolean pinboard_drag_in_progress = FALSE; + /* Static prototypes */ static void set_size_and_shape(PinIcon *icon, int *rwidth, int *rheight); @@ -156,6 +161,15 @@ static void selection_get(GtkWidget *widget, guint info, guint time, gpointer data); +static gboolean bg_drag_motion(GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time, + gpointer data); +static void drag_end(GtkWidget *widget, + GdkDragContext *context, + FilerWindow *filer_window); @@ -894,6 +908,8 @@ static void start_drag(PinIcon *icon, GdkEventMotion *event) selected = pinboard_get_selected(); g_return_if_fail(selected != NULL); + pinboard_drag_in_progress = TRUE; + if (selected->next == NULL) drag_one_item(widget, event, icon->path, &icon->item, FALSE); else @@ -987,7 +1003,12 @@ static gboolean add_root_handlers(void) gtk_signal_connect(GTK_OBJECT(proxy_invisible), "button_press_event", GTK_SIGNAL_FUNC(root_button_press), NULL); + + /* Drag and drop handlers */ drag_set_pinboard_dest(proxy_invisible); + gtk_signal_connect(GTK_OBJECT(proxy_invisible), "drag_motion", + GTK_SIGNAL_FUNC(bg_drag_motion), + NULL); /* The proxy window is also used to hold the selection... */ gtk_signal_connect(GTK_OBJECT(proxy_invisible), @@ -1210,6 +1231,8 @@ static void drag_set_pinicon_dest(PinIcon *icon) GTK_SIGNAL_FUNC(drag_motion), icon); gtk_signal_connect(obj, "drag_leave", GTK_SIGNAL_FUNC(drag_leave), icon); + gtk_signal_connect(obj, "drag_end", + GTK_SIGNAL_FUNC(drag_end), icon); /* gtk_signal_connect(obj, "drag_end", @@ -1231,6 +1254,12 @@ static gboolean drag_motion(GtkWidget *widget, char *type = NULL; DirItem *item = &icon->item; + if (gtk_drag_get_source_widget(context) == widget) + goto out; /* Can't drag something to itself! */ + + if (icon->selected) + goto out; /* Can't drag a selection to itself */ + if (provides(context, _rox_run_action)) { /* This is a special internal type. The user is dragging @@ -1253,9 +1282,6 @@ static gboolean drag_motion(GtkWidget *widget, goto out; } - if (gtk_drag_get_source_widget(context) == widget) - goto out; /* Can't drag something to itself! */ - if (item->base_type == TYPE_DIRECTORY && !(item->flags & ITEM_FLAG_APPDIR)) { @@ -1381,3 +1407,25 @@ static gint lose_selection(GtkWidget *widget, GdkEventSelection *event) return TRUE; } +static gboolean bg_drag_motion(GtkWidget *widget, + GdkDragContext *context, + gint x, + gint y, + guint time, + gpointer data) +{ + /* Dragging from the pinboard to the pinboard is not allowed */ + if (pinboard_drag_in_progress) + return FALSE; + + gdk_drag_status(context, context->suggested_action, time); + return TRUE; +} + +static void drag_end(GtkWidget *widget, + GdkDragContext *context, + FilerWindow *filer_window) +{ + pinboard_drag_in_progress = FALSE; + pinboard_clear_selection(); +} -- 2.11.4.GIT