summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>1998-11-27 17:16:36 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-11-27 17:16:36 +0000
commitf26c189e5b89bc21a24411358fa1fff4472ccca6 (patch)
treeed2edf81fc2e41a6f9bdffa325d088a00070e8d7
parent4ab10dc891a84331551f00bb7ba24f5319c4a8c6 (diff)
downloadgdk-pixbuf-f26c189e5b89bc21a24411358fa1fff4472ccca6.tar.gz
New function to get the source widget of a drag.
Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to get the source widget of a drag. * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP] to restrict certain targets to the same widget or to the same application. * gtk/testdnd.c: Test gtk_drag_get_source_widget().
-rw-r--r--ChangeLog11
-rw-r--r--ChangeLog.pre-2-011
-rw-r--r--ChangeLog.pre-2-1011
-rw-r--r--ChangeLog.pre-2-211
-rw-r--r--ChangeLog.pre-2-411
-rw-r--r--ChangeLog.pre-2-611
-rw-r--r--ChangeLog.pre-2-811
-rw-r--r--gtk/gtkdnd.c61
-rw-r--r--gtk/gtkdnd.h9
-rw-r--r--gtk/testdnd.c9
-rw-r--r--tests/testdnd.c9
11 files changed, 158 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 37b37b7d1..9596e33bc 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,14 @@
+Fri Nov 27 12:17:15 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkdnd.[ch] (gtk_drag_get_source_widget): New function to
+ get the source widget of a drag.
+
+ * gtk/gtkdnd.[ch]: Target flags GTK_TARGET_SAME_[WIDGET/APP]
+ to restrict certain targets to the same widget or to
+ the same application.
+
+ * gtk/testdnd.c: Test gtk_drag_get_source_widget().
+
Thu Nov 26 19:11:46 1998 Lars Hamann <lars@gtk.org>
* gtk/gtk-boxed.defs (GtkCTreeNode): define GtkCTreeNode as boxed type
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
index 7b8ee5ef6..d4400b3d9 100644
--- a/gtk/gtkdnd.c
+++ b/gtk/gtkdnd.c
@@ -26,6 +26,7 @@
#include "gtkdrawwindow.h"
static GSList *drag_widgets = NULL;
+static GSList *source_widgets = NULL;
typedef struct _GtkDragSourceSite GtkDragSourceSite;
typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
@@ -151,7 +152,8 @@ static GdkCursor * gtk_drag_get_cursor (GdkDragAction action);
static GtkWidget *gtk_drag_get_ipc_widget (void);
static void gtk_drag_release_ipc_widget (GtkWidget *widget);
-static GdkAtom gtk_drag_dest_find_target (GtkDragDestSite *site,
+static GdkAtom gtk_drag_dest_find_target (GtkWidget *widget,
+ GtkDragDestSite *site,
GdkDragContext *context);
static void gtk_drag_selection_received (GtkWidget *widget,
GtkSelectionData *selection_data,
@@ -521,6 +523,42 @@ gtk_drag_get_data (GtkWidget *widget,
time);
}
+
+/*************************************************************
+ * gtk_drag_get_source_widget:
+ * Get the widget the was the source of this drag, if
+ * the drag originated from this application.
+ * arguments:
+ * context: The drag context for this drag
+ * results:
+ * The source widget, or NULL if the drag originated from
+ * a different application.
+ *************************************************************/
+
+GtkWidget *
+gtk_drag_get_source_widget (GdkDragContext *context)
+{
+ GSList *tmp_list;
+
+ tmp_list = source_widgets;
+ while (tmp_list)
+ {
+ GtkWidget *ipc_widget = tmp_list->data;
+
+ if (ipc_widget->window == context->source_window)
+ {
+ GtkDragSourceInfo *info;
+ info = gtk_object_get_data (GTK_OBJECT (ipc_widget), "gtk-info");
+
+ return info ? info->widget : NULL;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+
+ return NULL;
+}
+
/*************************************************************
* gtk_drag_finish:
* Notify the drag source that the transfer of data
@@ -877,11 +915,13 @@ gtk_drag_dest_handle_event (GtkWidget *toplevel,
*************************************************************/
static GdkAtom
-gtk_drag_dest_find_target (GtkDragDestSite *site,
+gtk_drag_dest_find_target (GtkWidget *widget,
+ GtkDragDestSite *site,
GdkDragContext *context)
{
GList *tmp_target;
GList *tmp_source = NULL;
+ GtkWidget *source_widget = gtk_drag_get_source_widget (context);
tmp_target = site->target_list->list;
while (tmp_target)
@@ -891,7 +931,13 @@ gtk_drag_dest_find_target (GtkDragDestSite *site,
while (tmp_source)
{
if (tmp_source->data == GUINT_TO_POINTER (pair->target))
- return pair->target;
+ {
+ if ((!(pair->flags & GTK_TARGET_SAME_APP) || source_widget) &&
+ (!(pair->flags & GTK_TARGET_SAME_WIDGET) || (source_widget == widget)))
+ return pair->target;
+ else
+ break;
+ }
tmp_source = tmp_source->next;
}
tmp_target = tmp_target->next;
@@ -1273,7 +1319,7 @@ gtk_drag_dest_motion (GtkWidget *widget,
}
}
- if (action && gtk_drag_dest_find_target (site, context))
+ if (action && gtk_drag_dest_find_target (widget, site, context))
{
if (!site->have_drag)
{
@@ -1377,7 +1423,7 @@ gtk_drag_dest_drop (GtkWidget *widget,
if (site->flags & GTK_DEST_DEFAULT_MOTION)
{
- GdkAtom target = gtk_drag_dest_find_target (site, context);
+ GdkAtom target = gtk_drag_dest_find_target (widget, site, context);
if (target == GDK_NONE)
return FALSE;
@@ -1429,6 +1475,9 @@ gtk_drag_begin (GtkWidget *widget,
info = g_new0 (GtkDragSourceInfo, 1);
info->ipc_widget = gtk_drag_get_ipc_widget ();
+ source_widgets = g_slist_prepend (source_widgets, info->ipc_widget);
+
+ gtk_object_set_data (GTK_OBJECT (info->ipc_widget), "gtk-info", info);
tmp_list = g_list_last (target_list->list);
while (tmp_list)
@@ -2238,6 +2287,8 @@ gtk_drag_source_info_destroy (gpointer data)
gtk_signal_disconnect_by_data (GTK_OBJECT (info->ipc_widget), info);
gtk_selection_remove_all (info->ipc_widget);
+ gtk_object_set_data (GTK_OBJECT (info->ipc_widget), "gtk-info", NULL);
+ source_widgets = g_slist_remove (source_widgets, info->ipc_widget);
gtk_drag_release_ipc_widget (info->ipc_widget);
gtk_target_list_unref (info->target_list);
diff --git a/gtk/gtkdnd.h b/gtk/gtkdnd.h
index 98ca190a3..e464e1dd9 100644
--- a/gtk/gtkdnd.h
+++ b/gtk/gtkdnd.h
@@ -35,6 +35,13 @@ typedef enum {
GTK_DEST_DEFAULT_ALL = 0x07
} GtkDestDefaults;
+/* Flags for the GtkTargetEntry on the destination side
+ */
+typedef enum {
+ GTK_TARGET_SAME_APP = 1 << 0, /*< nick=same-app >*/
+ GTK_TARGET_SAME_WIDGET = 1 << 1 /*< nick=same-widget >*/
+} GtkTargetFlags;
+
/* Destination side */
void gtk_drag_get_data (GtkWidget *widget,
@@ -46,6 +53,8 @@ void gtk_drag_finish (GdkDragContext *context,
gboolean del,
guint32 time);
+GtkWidget *gtk_drag_get_source_widget (GdkDragContext *context);
+
void gtk_drag_highlight (GtkWidget *widget);
void gtk_drag_unhighlight (GtkWidget *widget);
diff --git a/gtk/testdnd.c b/gtk/testdnd.c
index 26c38f3d2..2736bf393 100644
--- a/gtk/testdnd.c
+++ b/gtk/testdnd.c
@@ -302,12 +302,19 @@ target_drag_motion (GtkWidget *widget,
gint y,
guint time)
{
+ GtkWidget *source_widget;
+
if (!have_drag)
{
have_drag = TRUE;
gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_open, trashcan_open_mask);
}
- g_print("motion\n");
+
+ source_widget = gtk_drag_get_source_widget (context);
+ g_print("motion, source %s\n", source_widget ?
+ gtk_type_name (GTK_OBJECT (source_widget)->klass->type) :
+ "unknown");
+
gdk_drag_status (context, context->suggested_action, time);
return TRUE;
}
diff --git a/tests/testdnd.c b/tests/testdnd.c
index 26c38f3d2..2736bf393 100644
--- a/tests/testdnd.c
+++ b/tests/testdnd.c
@@ -302,12 +302,19 @@ target_drag_motion (GtkWidget *widget,
gint y,
guint time)
{
+ GtkWidget *source_widget;
+
if (!have_drag)
{
have_drag = TRUE;
gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_open, trashcan_open_mask);
}
- g_print("motion\n");
+
+ source_widget = gtk_drag_get_source_widget (context);
+ g_print("motion, source %s\n", source_widget ?
+ gtk_type_name (GTK_OBJECT (source_widget)->klass->type) :
+ "unknown");
+
gdk_drag_status (context, context->suggested_action, time);
return TRUE;
}