summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@gtk.org>1998-10-18 22:51:24 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-10-18 22:51:24 +0000
commitf7bcb456072dac59b1ce5bd5329282ba95a3b495 (patch)
treea9085af76de35b5c883776673b7a59521e52c043
parent7dbb5755a4cafc45108ec66ac89dfc1f11639494 (diff)
downloadgtk+-f7bcb456072dac59b1ce5bd5329282ba95a3b495.tar.gz
Added a modular client-message-filter mechanism, that is used for the DND
Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org> * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter mechanism, that is used for the DND messages. Removed all the old DND code. * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to get the visual of a given colormap. * gtk/gtkcolorsel.c: Conversion to new DND, drag a color-swatch. * gdk/gdk.h gdk/gdkdnd.c: The low-level X oriented portions of drag and drop protocols. Sending and receiving client messages, and navigating window trees. * gdk/gdkimage.c: added a gdk_flush() when destroying SHM images to hopefully make it more likely that X will gracefully handle the segment being destroyed. * gdk/gdkprivate.h gtk/gtkdebug.h: Add new DND debugging flags. * gtk/gtkeditable.[ch]: Updates for the selection handling changes. * gtk/gtkselection.[ch]: Added GtkTargetList, a refcounted data structure for keeping track of lists of GdkAtom + information. Removed selection_handler_add in favor of a "drag_data_get" signal. * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop dependent) parts of the DND protocols, display of drag icons, drag-under highlighting, and the "default handlers". * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen windows that are used for reliable pointer grabs and selection handling in the DND code. * gtk/testdnd.c: New test program for new DND. (Old DND tests in testgtk still need to be converted.) * gtk/testselection.c: Use the new selection API. * docs/dnd_internals: Start at describing how all the new code works inside. * docs/Changes-1.2.txt: New file describing source-incompatible changes in GTK+-1.2. Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org> * gdk/gdkwindow.c (gdk_window_remove_filter): Free the right list node. * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent to the XID table so we can receive events on it. Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function to get the timestamp from a generic event. Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com> * gtk/gtkwidget.c (gtk_widget_add_events): Added function that safely adds additional events to a widget's event mask, even if the widget has previously been realized. (We can do this, but not remove events from the event mask). Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdkproperty.c (gdk_property_get): Allow type == 0, for AnyPropertyType. Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdkproperty.c (gdk_atom_intern): Add client-local hashing. Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial isn't a timestamp. Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.c (gdk_event_translate): Removed printing of unknown window lookup warnings. (Made it a GDK_NOTE) - they happen in many circumstances.
-rw-r--r--ChangeLog111
-rw-r--r--ChangeLog.pre-2-0111
-rw-r--r--ChangeLog.pre-2-10111
-rw-r--r--ChangeLog.pre-2-2111
-rw-r--r--ChangeLog.pre-2-4111
-rw-r--r--ChangeLog.pre-2-6111
-rw-r--r--ChangeLog.pre-2-8111
-rw-r--r--TODO18
-rw-r--r--docs/Changes-1.2.txt49
-rw-r--r--docs/dnd_internals.txt210
-rw-r--r--gdk/gdk.c1004
-rw-r--r--gdk/gdk.h129
-rw-r--r--gdk/gdkcolor.c12
-rw-r--r--gdk/gdkdnd.c2908
-rw-r--r--gdk/gdkimage.c2
-rw-r--r--gdk/gdkprivate.h8
-rw-r--r--gdk/gdkproperty.c19
-rw-r--r--gdk/gdktypes.h193
-rw-r--r--gdk/gdkwindow.c200
-rw-r--r--gdk/x11/gdkcolor-x11.c12
-rw-r--r--gdk/x11/gdkdnd-x11.c2908
-rw-r--r--gdk/x11/gdkimage-x11.c2
-rw-r--r--gdk/x11/gdkmain-x11.c1004
-rw-r--r--gdk/x11/gdkproperty-x11.c19
-rw-r--r--gdk/x11/gdkwindow-x11.c200
-rw-r--r--gtk/Makefile.am10
-rw-r--r--gtk/gtk-boxed.defs3
-rw-r--r--gtk/gtk.h1
-rw-r--r--gtk/gtkcolorsel.c180
-rw-r--r--gtk/gtkdebug.h3
-rw-r--r--gtk/gtkdnd.c2343
-rw-r--r--gtk/gtkdnd.h129
-rw-r--r--gtk/gtkeditable.c87
-rw-r--r--gtk/gtkmain.c24
-rw-r--r--gtk/gtkmarshal.list4
-rw-r--r--gtk/gtkmarshalers.list4
-rw-r--r--gtk/gtkmenu.h4
-rw-r--r--gtk/gtkselection.c430
-rw-r--r--gtk/gtkselection.h69
-rw-r--r--gtk/gtksignal.c2
-rw-r--r--gtk/gtkstyle.h1
-rw-r--r--gtk/gtkwidget.c310
-rw-r--r--gtk/gtkwidget.h89
-rw-r--r--gtk/testgtk.c4
-rw-r--r--gtk/testselection.c112
-rw-r--r--tests/testgtk.c4
-rw-r--r--tests/testselection.c112
47 files changed, 10688 insertions, 2911 deletions
diff --git a/ChangeLog b/ChangeLog
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-0
+++ b/ChangeLog.pre-2-0
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-10
+++ b/ChangeLog.pre-2-10
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-2
+++ b/ChangeLog.pre-2-2
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-4
+++ b/ChangeLog.pre-2-4
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-6
+++ b/ChangeLog.pre-2-6
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8
index 95ed025751..11e3e441c8 100644
--- a/ChangeLog.pre-2-8
+++ b/ChangeLog.pre-2-8
@@ -1,3 +1,114 @@
+Sun Oct 18 18:16:39 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdk.c gdkprivate.h: Added a modular client-message-filter
+ mechanism, that is used for the DND messages.
+
+ Removed all the old DND code.
+
+ * gdk/gdkcolormap.c gdk/gdkcolormap.h: Add a function to
+ get the visual of a given colormap.
+
+ * gtk/gtkcolorsel.c: Conversion to new DND, drag
+ a color-swatch.
+
+ * gdk/gdk.h gdk/gdkdnd.c: The low-level
+ X oriented portions of drag and drop protocols.
+ Sending and receiving client messages, and navigating
+ window trees.
+
+ * gdk/gdkimage.c: added a gdk_flush() when destroying
+ SHM images to hopefully make it more likely that
+ X will gracefully handle the segment being destroyed.
+
+ * gdk/gdkprivate.h gtk/gtkdebug.h: Add new
+ DND debugging flags.
+
+ * gtk/gtkeditable.[ch]: Updates for the selection handling
+ changes.
+
+ * gtk/gtkselection.[ch]: Added GtkTargetList, a
+ refcounted data structure for keeping track of lists
+ of GdkAtom + information. Removed selection_handler_add
+ in favor of a "drag_data_get" signal.
+
+ * gtk/gtkdnd.[ch] gtk/gtk.h: New files - highlevel (event loop
+ dependent) parts of the DND protocols, display of drag icons,
+ drag-under highlighting, and the "default handlers".
+
+ * gtk/gtkinvisible.[ch]: New widget - InputOnly offscreen
+ windows that are used for reliable pointer grabs and
+ selection handling in the DND code.
+
+ * gtk/testdnd.c: New test program for new DND. (Old
+ DND tests in testgtk still need to be converted.)
+
+ * gtk/testselection.c: Use the new selection API.
+
+ * docs/dnd_internals: Start at describing how
+ all the new code works inside.
+
+ * docs/Changes-1.2.txt: New file describing source-incompatible
+ changes in GTK+-1.2.
+
+Sat Oct 17 22:50:34 1998 Owen Taylor <otaylor@gtk.org>
+
+ * gdk/gdkwindow.c (gdk_window_remove_filter): Free
+ the right list node.
+
+ * gdk/gdkwindow.c (gdk_window_init): Add gdk_root_parent
+ to the XID table so we can receive events on it.
+
+Wed Oct 14 12:57:40 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c gdk/gdk.h (gdk_event_get_time): New function
+ to get the timestamp from a generic event.
+
+Fri Oct 9 13:16:04 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkwidget.c (gtk_widget_add_events): Added function
+ that safely adds additional events to a widget's event
+ mask, even if the widget has previously been realized.
+ (We can do this, but not remove events from the event
+ mask).
+
+Fri Oct 2 17:35:35 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_property_get): Allow type == 0,
+ for AnyPropertyType.
+
+Fri Oct 2 10:32:21 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdkproperty.c (gdk_atom_intern): Add client-local
+ hashing.
+
+Thu Sep 24 20:33:54 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_send_clientmessage_toall): serial
+ isn't a timestamp.
+
+Thu Sep 17 14:23:03 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gdk/gdk.c (gdk_event_translate): Removed printing
+ of unknown window lookup warnings. (Made it
+ a GDK_NOTE) - they happen in many circumstances.
+
+Tue Sep 8 12:38:43 1998 Owen Taylor <otaylor@redhat.com>
+
+ * Call XFilterEvent() on events we get for unknown
+ windows, since it may be the window Xlib uses to
+ communicate with the IM.
+ (From Yung-Ching Hsiao <yhsiao@cae.wisc.edu>)
+
+Tue Sep 1 10:53:52 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtkprogress.c (gtk_progress_finalize): Unref
+ the adjustment.
+
+Thu Aug 27 12:03:14 1998 Owen Taylor <otaylor@redhat.com>
+
+ * gtk/gtksignal.c (gtk_signal_newv): Improve warning
+ message for return_value + GTK_RUN_FIRST.
+
1998-10-18 Martin Baulig <martin@home-of-linux.org>
* gtk/gtktext.c (gtk_text_set_line_wrap): new function to toggle
diff --git a/TODO b/TODO
index 563a52c89a..adc0292720 100644
--- a/TODO
+++ b/TODO
@@ -297,3 +297,21 @@ Calendar Widget:
- The keyboard support has to be finished.
+DND
+===
+
+ - Use a cursor instead of an ICON when over Motif windows,
+ to get rid of the current junk that Motif leaves because
+ of it's XCopyArea stupidity for doing highlighting.
+
+ - Add a GTK_DRAG_VERIFY target flag and a "drag_data_verify"
+ signal so that apps can easily check if a, say,
+ text/uri-list URL looks OK during the drop.
+
+ - Check more for memory leaks.
+
+ - Drag and drop for Entry and Text widgets.
+
+ - Send synthetic motion events on structure changes so
+ drag_enter/leave get sent properly. (See the popup
+ in testdnd)
diff --git a/docs/Changes-1.2.txt b/docs/Changes-1.2.txt
new file mode 100644
index 0000000000..6cda1761de
--- /dev/null
+++ b/docs/Changes-1.2.txt
@@ -0,0 +1,49 @@
+Incompatible Changes from GTK+-1.0 to GTK+-1.2:
+
+* GtkAcceleratorTable has been replaced with GtkAccelGroup
+
+* GtkMenuFactory has been replaced with GtkItemFactory, although
+ a version of GtkMenuFactory is provided to ease compatibility.
+
+* GtkButton has been changed to derive from GtkBin.
+
+ To access a button's child, use GTK_BIN (button)->child, instead
+ of the old GTK_BUTTON (button)->child.
+
+* The selection API has been slightly modified:
+
+ gtk_selection_add_handler() and gtk_selection_add_handler_full()
+ have been removed. To supply the selection, one now register
+ the targets one is interested in with:
+
+ void gtk_selection_add_target (GtkWidget *widget,
+ GdkAtom selection,
+ GdkAtom target,
+ guint info);
+
+ or:
+
+ void gtk_selection_add_targets (GtkWidget *widget,
+ GdkAtom selection,
+ GtkTargetEntry *targets,
+ guint ntargets);
+
+ When a request for a selection is received, the new "selection_get"
+ signal will be called:
+
+ void "selection_get" (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time);
+
+ A "time" parameter has also been added to the "selection_received"
+ signal.
+
+ void "selection_received" (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint time);
+
+* The old drag and drop API has been completely removed and replaced.
+ See the reference documentation for details on the new API.
+
+
diff --git a/docs/dnd_internals.txt b/docs/dnd_internals.txt
new file mode 100644
index 0000000000..46156dfdd9
--- /dev/null
+++ b/docs/dnd_internals.txt
@@ -0,0 +1,210 @@
+This document describes some of the internals of the DND handling
+code.
+
+Organization
+============
+
+The DND code is split between a lowlevel part - gdkdnd.c and a
+highlevel part - gtkdnd.c. To put it simply, gdkdnd.c contain the
+portions of DND code that are easiest to do in raw X, while gtkdnd.c
+contains the portions of DND that are easiest to do with an event loop
+and high level selection handling.
+
+Except for a few details of selection handling, most of the
+dependencies on the DND protocol are confined to gdkdnd.c.
+There are two or three supported protocols - Motif DND,
+Xdnd and a pseudo-protocol ROOTWIN, which is used for drops
+on root windows that aren't really accepting drops.
+gdkdnd.c divides into 4 pieces:
+
+ 1) Utility functions (finding client windows)
+ 2) Motif specific code (the biggest chunk)
+ 3) Xdnd specific code
+ 4) The public interfaces
+
+The code in gtkdnd.c roughly consists of three parts
+
+ 1) General utility functions
+ 2) Destination side code
+ 3) Source side code.
+
+Both on the source and dest side, there is some division
+between the low level layers and the default handlers,
+though they are rather mixed in many cases.
+
+Structures and Memory Management
+================================
+
+Information about source sites and drop sites is stored
+in the structures GtkSourceSite and GtkDestSite.
+
+Information about in-progress drags and drops is stored
+in the structures GtkSourceInfo and GtkDestInfo.
+
+The GtkSourceInfo structure is created when the drag
+begins, and persists until the drag either completes
+or times out. A pointer to it is stored in
+dataset-data for the GdkDragContext, however there
+is no ownership. If the SourceInfo is destroyed
+before the context, the field is simply cleared.
+
+A GtkDestInfo is attached to each GdkDragContext
+that is received for an incoming drag. In contrast
+to the SourceInfo the DestInfo is "owned" by the
+context, and when the context is destroyed, destroyed.
+
+The GDK API
+===========
+
+It is expect that the GDK DND API will never be
+used by anything other than the DND code in GTK+.
+
+/* Drag and Drop */
+
+GdkDragContext * gdk_drag_context_new (void);
+void gdk_drag_context_ref (GdkDragContext *context);
+void gdk_drag_context_unref (GdkDragContext *context);
+
+These create and refcount GdkDragContexts in a
+straightforward manner.
+
+/* Destination side */
+
+void gdk_drag_status (GdkDragContext *context,
+ GdkDragAction action,
+ guint32 time);
+void gdk_drop_reply (GdkDragContext *context,
+ gboolean ok,
+ guint32 time);
+void gdk_drop_finish (GdkDragContext *context,
+ gboolean success,
+ guint32 time);
+GdkAtom gdk_drag_get_selection (GdkDragContext *context);
+
+/* Source side */
+
+GdkDragContext * gdk_drag_begin (GdkWindow *window,
+ GList *targets,
+ GdkDragAction actions);
+gboolean gdk_drag_get_protocol (guint32 xid,
+ GdkDragProtocol *protocol);
+void gdk_drag_find_window (GdkDragContext *context,
+ GdkWindow *drag_window,
+ gint x_root,
+ gint y_root,
+ GdkWindow **dest_window,
+ GdkDragProtocol *protocol);
+gboolean gdk_drag_motion (GdkDragContext *context,
+ GdkWindow *dest_window,
+ GdkDragProtocol protocol,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time);
+void gdk_drag_drop (GdkDragContext *context,
+ guint32 time);
+void gdk_drag_abort (GdkDragContext *context,
+ guint32 time);
+
+GdkAtom gdk_drag_get_selection (GdkDragContext *context);
+
+Retrieves the selection that will be used to communicate
+the data for the drag context (valid on both source
+and dest sides)
+
+Cursors and window heirarchies
+==============================
+
+The DND code, when possible (and it isn't possible over
+Motif window) uses a shaped window as a drag icon.
+Because the cursor may fall inside this window during the
+drag, we actually have to figure out which window
+the cursor is in _ourselves_ so we can ignore the
+drag icon properly. (Oh for OutputOnly windows!)
+
+To avoid obscene amounts of server traffic (which are only
+slighly observerable locally, but would really kill a
+session over a slow link), the code in GDK does
+XGetWindowAttributes for every child of the root window at
+the beginning of the drag, then selects with
+SubstructureNotifyMask on the root window, so that
+it can update this list.
+
+It probably would be easier to just reread the entire
+list when one of these events occurs, instead of
+incrementally updating, but updating the list in
+sync was sort of fun code, so I did it that way ;-)
+
+There is also a problem of trying to follow the
+mouse cursor as well as possible. Currently, the
+code uses PointerMotionHint, and an XQueryPointer
+on MotionNotify events. This results in pretty
+good syncing, but may result in somewhat poor
+accuracy for drops. (Because the coordinates of
+the drop are the coordinates when the server receives
+the button press, which might actually be before
+the XQueryPointer for the previous MotionNotify
+event is done.)
+
+Probably better is doing MotionNotify compression
+and discarding MotionNotify events when there
+are more on the queue before the next ButtonPress/Release.
+
+Proxying
+========
+
+A perhaps rather unusual feature of GTK's DND is proxying. A
+dest site can be specified as a proxy drop site for another
+window. This is most needed for the plug-socket code - the
+socket needs to pass on drags to the plug since the original
+source only sees toplevel windows. However, it can also be
+used as a user visible proxy - i.e., dragging to buttons on
+the taskbar.
+
+Internally, when the outer drag enters a proxy dest site, a
+new source drag is created, with SourceInfo and
+GdkDragContext. From the GDK side, it looks much like a
+normal source drag; on the GTK+ side, most of the code is
+disjoint. The need to pass in a specific target window
+is the reason why the GDK DND API splits
+gdk_drag_find_window() and gdk_drag_motion().
+
+For proxy drags, the GtkDestInfo and GtkSourceInfo for the
+drag point at each other.
+
+Because the abstraction of the drag protocol is at the GDK
+level, a proxy drag from Motif to Xdnd or vice versa happens
+pretty much automatically during the drag, though the
+drop can get complicated. For Xdnd <-> Motif,
+Motif <-> Xdnd, or Motif <-> Motif drags, it is necessary to
+for the Proxy to retrieve the data and pass it on to
+the true destination, since either the selection names
+differ or (Motif<->Motif), the proxy needs to know
+about the XmDRAG_SUCCESS/FAILURE selection targets.
+
+Further Reading:
+================
+
+Xdnd:
+
+The spec is at:
+
+ http://www.cco.caltech.edu/~jafl/xdnd/
+
+Motif:
+
+The Motif DND protocol is best described in the
+Hungry Programmers _Inside Lesstif_ book, available
+from:
+
+ http://www.igpm.rwth-aachen.de/~albrecht/hungry.html
+
+Harald Albrecht and Mitch Miers have done a far
+better job at documenting the DND protocol then
+anything the OpenGroup has produced.
+
+
+
+Owen Taylor
+otaylor@redhat.com
+Oct 18, 1998
diff --git a/gdk/gdk.c b/gdk/gdk.c
index 867dadef60..ca0d47504b 100644
--- a/gdk/gdk.c
+++ b/gdk/gdk.c
@@ -116,13 +116,6 @@ static Bool gdk_event_get_type (Display *display,
static void gdk_synthesize_click (GdkEvent *event,
gint nclicks);
-static void gdk_dnd_drag_begin (GdkWindow *initial_window);
-static void gdk_dnd_drag_enter (Window dest);
-static void gdk_dnd_drag_leave (Window dest);
-static void gdk_dnd_drag_end (Window dest,
- GdkPoint coords);
-static GdkAtom gdk_dnd_check_types (GdkWindow *window,
- XEvent *xevent);
#ifdef DEBUG_DND
static void gdk_print_atom (GdkAtom anatom);
#endif
@@ -163,6 +156,10 @@ static gint gdk_im_open (XrmDatabase db,
static void gdk_im_close (void);
static void gdk_ic_cleanup (void);
+GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
#endif /* USE_XIM */
/* Private variable declarations
@@ -217,6 +214,8 @@ static GdkWindowPrivate *xgrab_window = NULL; /* Window that currently holds
* x pointer grab
*/
+static GList *client_filters; /* Filters for client messages */
+
#ifdef USE_XIM
static gint xim_using; /* using XIM Protocol if TRUE */
static GdkIM xim_im; /* global IM */
@@ -549,14 +548,6 @@ gdk_init (int *argc,
gdk_wm_window_protocols[1] = gdk_wm_take_focus;
gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);
- gdk_dnd.gdk_XdeEnter = gdk_atom_intern("_XDE_ENTER", FALSE);
- gdk_dnd.gdk_XdeLeave = gdk_atom_intern("_XDE_LEAVE", FALSE);
- gdk_dnd.gdk_XdeRequest = gdk_atom_intern("_XDE_REQUEST", FALSE);
- gdk_dnd.gdk_XdeDataAvailable = gdk_atom_intern("_XDE_DATA_AVAILABLE", FALSE);
- gdk_dnd.gdk_XdeTypelist = gdk_atom_intern("_XDE_TYPELIST", FALSE);
- gdk_dnd.c->gdk_cursor_dragdefault = XCreateFontCursor(gdk_display, XC_bogosity);
- gdk_dnd.c->gdk_cursor_dragok = XCreateFontCursor(gdk_display, XC_heart);
-
XGetKeyboardControl (gdk_display, &keyboard_state);
autorepeat = keyboard_state.global_auto_repeat;
@@ -577,6 +568,10 @@ gdk_init (int *argc,
gdk_window_init ();
gdk_image_init ();
gdk_input_init ();
+ gdk_dnd_init ();
+
+ gdk_add_client_message_filter (gdk_wm_protocols,
+ gdk_wm_protocols_filter, NULL);
#ifdef USE_XIM
/* initialize XIM Protocol variables */
@@ -928,13 +923,15 @@ gdk_event_copy (GdkEvent *event)
gdk_window_ref (event->crossing.subwindow);
break;
- case GDK_DROP_DATA_AVAIL:
- new_event->dropdataavailable.data_type = g_strdup (event->dropdataavailable.data_type);
- new_event->dropdataavailable.data = g_malloc (event->dropdataavailable.data_numbytes);
- memcpy (new_event->dropdataavailable.data,
- event->dropdataavailable.data,
- event->dropdataavailable.data_numbytes);
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ gdk_drag_context_ref (event->dnd.context);
break;
+
default:
break;
@@ -983,14 +980,15 @@ gdk_event_free (GdkEvent *event)
gdk_window_unref (event->crossing.subwindow);
break;
- case GDK_DROP_DATA_AVAIL:
- g_free (event->dropdataavailable.data_type);
- g_free (event->dropdataavailable.data);
- break;
-
- case GDK_DRAG_REQUEST:
- g_free (event->dragrequest.data_type);
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ gdk_drag_context_unref (event->dnd.context);
break;
+
default:
break;
@@ -1019,6 +1017,60 @@ gdk_event_free (GdkEvent *event)
*--------------------------------------------------------------
*/
+/*
+ *--------------------------------------------------------------
+ * gdk_event_get_time:
+ * Get the timestamp from an event.
+ * arguments:
+ * event:
+ * results:
+ * The event's time stamp, if it has one, otherwise
+ * GDK_CURRENT_TIME.
+ *--------------------------------------------------------------
+ */
+
+guint32
+gdk_event_get_time (GdkEvent *event)
+{
+ if (event)
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ return event->motion.time;
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ return event->button.time;
+ case GDK_KEY_PRESS:
+ case GDK_KEY_RELEASE:
+ return event->key.time;
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ return event->crossing.time;
+ case GDK_PROPERTY_NOTIFY:
+ return event->property.time;
+ case GDK_SELECTION_CLEAR:
+ case GDK_SELECTION_REQUEST:
+ case GDK_SELECTION_NOTIFY:
+ return event->selection.time;
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+ return event->proximity.time;
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ return event->dnd.time;
+ default: /* use current time */
+ break;
+ }
+
+ return GDK_CURRENT_TIME;
+}
+
void
gdk_set_show_events (int show_events)
{
@@ -1773,6 +1825,20 @@ gdk_event_apply_filters (XEvent *xevent,
return GDK_FILTER_CONTINUE;
}
+void
+gdk_add_client_message_filter (GdkAtom message_type,
+ GdkFilterFunc func,
+ gpointer data)
+{
+ GdkClientFilter *filter = g_new (GdkClientFilter, 1);
+
+ filter->type = message_type;
+ filter->function = func;
+ filter->data = data;
+
+ client_filters = g_list_prepend (client_filters, filter);
+}
+
static gint
gdk_event_translate (GdkEvent *event,
XEvent *xevent)
@@ -1793,15 +1859,9 @@ gdk_event_translate (GdkEvent *event,
return_val = FALSE;
- /* We need to play catch-up with the dnd motion events */
- if(gdk_dnd.drag_really && xevent->type == MotionNotify)
- while (XCheckTypedEvent(xevent->xany.display,MotionNotify,xevent));
-
/* Find the GdkWindow that this event occurred in.
- * All events occur in some GdkWindow (otherwise, why
- * would we be receiving them). It really is an error
- * to receive an event for which we cannot find the
- * corresponding GdkWindow. We handle events with window=None
+ *
+ * We handle events with window=None
* specially - they are generated by XFree86's XInput under
* some circumstances.
*/
@@ -1822,15 +1882,20 @@ gdk_event_translate (GdkEvent *event,
if (window != NULL)
gdk_window_ref (window);
- else if (gdk_null_window_warnings)
- {
- /* Special purpose programs that
- * get events for other windows may
- * want to disable this
- */
- g_warning ("xwindow(%#lx) lookup reveals NULL", xevent->xany.window);
- }
+#ifdef USE_XIM
+ else if (XFilterEvent(xevent, None)) /* for xlib XIM handling */
+ return FALSE;
+#endif
+ else
+ GDK_NOTE (EVENTS,
+ g_message ("Got event for unknown window: %#lx\n", xevent->xany.window));
+
+ event->any.window = window;
+ event->any.send_event = xevent->xany.send_event;
+ if (window_private && window_private->destroyed)
+ return FALSE;
+
/* Check for filters for this window */
{
@@ -1845,7 +1910,7 @@ gdk_event_translate (GdkEvent *event,
return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
}
}
-
+
/* We do a "manual" conversion of the XEvent to a
* GdkEvent. The structures are mostly the same so
* the conversion is fairly straightforward. We also
@@ -2031,44 +2096,7 @@ gdk_event_translate (GdkEvent *event,
button_number[1] = -1;
button_number[0] = event->button.button;
}
- if(window_private
- && window_private->dnd_drag_enabled
- && !gdk_dnd.drag_perhaps
- && event->button.button == 1
- && !gdk_dnd.drag_really)
- {
- gdk_dnd.drag_perhaps = 1;
- gdk_dnd.dnd_drag_start.x = xevent->xbutton.x_root;
- gdk_dnd.dnd_drag_start.y = xevent->xbutton.y_root;
- gdk_dnd.real_sw = window_private;
-
- if(gdk_dnd.drag_startwindows)
- {
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- }
- gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
- gdk_dnd.dnd_grabbed = FALSE;
-
- {
- /* Set motion mask for first DnD'd window, since it
- will be the one that is actually dragged */
- XWindowAttributes dnd_winattr;
- XSetWindowAttributes dnd_setwinattr;
-
- /* We need to get motion events while the button is down, so
- we can know whether to really start dragging or not... */
- XGetWindowAttributes(gdk_display, (Window)window_private->xwindow,
- &dnd_winattr);
-
- window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
- dnd_setwinattr.event_mask =
- window_private->dnd_drag_eventmask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask | ExposureMask;
- XChangeWindowAttributes(gdk_display, window_private->xwindow,
- CWEventMask, &dnd_setwinattr);
- }
- }
+
return_val = window_private && !window_private->destroyed;
break;
@@ -2102,66 +2130,18 @@ gdk_event_translate (GdkEvent *event,
event->button.source = GDK_SOURCE_MOUSE;
event->button.deviceid = GDK_CORE_POINTER;
- gdk_dnd.last_drop_time = xevent->xbutton.time;
- if(gdk_dnd.drag_perhaps)
- {
- {
- XSetWindowAttributes attrs;
- /* Reset event mask to pre-drag value, assuming event_mask
- doesn't change during drag */
- attrs.event_mask = gdk_dnd.real_sw->dnd_drag_savedeventmask;
- XChangeWindowAttributes(gdk_display, gdk_dnd.real_sw->xwindow,
- CWEventMask, &attrs);
- }
-
- if (gdk_dnd.dnd_grabbed)
- {
- gdk_dnd_display_drag_cursor(-2,
- -2,
- FALSE, TRUE);
- XUngrabPointer(gdk_display, CurrentTime);
- gdk_dnd.dnd_grabbed = FALSE;
- }
-
- if(gdk_dnd.drag_really)
- {
- GdkPoint foo;
- foo.x = xevent->xbutton.x_root;
- foo.y = xevent->xbutton.y_root;
-
- if(gdk_dnd.dnd_drag_target != None)
- gdk_dnd_drag_end(gdk_dnd.dnd_drag_target, foo);
- gdk_dnd.drag_really = 0;
-
- gdk_dnd.drag_numwindows = 0;
- if(gdk_dnd.drag_startwindows)
- {
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- }
-
- gdk_dnd.real_sw = NULL;
- }
-
- gdk_dnd.drag_perhaps = 0;
- gdk_dnd.dnd_drag_start.x = gdk_dnd.dnd_drag_start.y = 0;
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0;
- gdk_dnd.dnd_drag_curwin = None;
- return_val = window_private?TRUE:FALSE;
- } else
- return_val = window_private && !window_private->destroyed;
+ return_val = window_private && !window_private->destroyed;
+
break;
case MotionNotify:
/* Print debugging info.
*/
GDK_NOTE (EVENTS,
- g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s d:%d r%d",
+ g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
xevent->xmotion.window - base_id,
xevent->xmotion.x, xevent->xmotion.y,
- (xevent->xmotion.is_hint) ? "true" : "false",
- gdk_dnd.drag_perhaps, gdk_dnd.drag_really));
+ (xevent->xmotion.is_hint) ? "true" : "false"));
if (window_private &&
(window_private->extension_events != 0) &&
@@ -2183,114 +2163,7 @@ gdk_event_translate (GdkEvent *event,
event->motion.source = GDK_SOURCE_MOUSE;
event->motion.deviceid = GDK_CORE_POINTER;
-#define IS_IN_ZONE(cx, cy) (cx >= gdk_dnd.dnd_drag_dropzone.x \
- && cy >= gdk_dnd.dnd_drag_dropzone.y \
- && cx < (gdk_dnd.dnd_drag_dropzone.x + gdk_dnd.dnd_drag_dropzone.width) \
- && cy < (gdk_dnd.dnd_drag_dropzone.y + gdk_dnd.dnd_drag_dropzone.height))
-
- if(gdk_dnd.drag_perhaps && gdk_dnd.drag_really
- /* && event->motion.is_hint */ /* HINTME */)
- {
- /* First, we have to find what window the motion was in... */
- /* XXX there has to be a better way to do this, perhaps with
- XTranslateCoordinates or XQueryTree - I don't know how,
- and this sort of works */
- static Window lastwin = None, curwin = None;
-#if 0
- Window twin;
-#endif
- Window childwin = gdk_root_window;
- int x, y, ox, oy;
-
- /* Interlude - display cursor for the drag ASAP */
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- FALSE);
-
- lastwin = curwin;
- curwin = gdk_root_window;
- ox = x = xevent->xmotion.x_root;
- oy = y = xevent->xmotion.y_root;
-#if 1
- curwin = gdk_window_xid_at_coords(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- gdk_dnd.c->xids,TRUE);
- XTranslateCoordinates(gdk_display, gdk_root_window, curwin,
- x, y, &x, &y, &childwin);
-#else
- while(childwin != None)
- {
- ox = x; oy = y;
- curwin = childwin;
- XTranslateCoordinates(gdk_display, curwin, curwin,
- x, y, &x, &y, &childwin);
- if(childwin != None)
- {
- XTranslateCoordinates(gdk_display, curwin, childwin,
- x, y, &x, &y, &twin);
- }
- }
-#endif
- GDK_NOTE (DND,
- g_message("Drag is now in window %#lx, lastwin was %#lx, ddc = %#lx",
- curwin, lastwin, gdk_dnd.dnd_drag_curwin));
- if(curwin != gdk_dnd.dnd_drag_curwin && curwin != lastwin)
- {
- /* We have left one window and entered another
- (do leave & enter bits) */
- if(gdk_dnd.dnd_drag_curwin != None)
- gdk_dnd_drag_leave(gdk_dnd.dnd_drag_curwin);
- gdk_dnd.dnd_drag_curwin = curwin;
- gdk_dnd_drag_enter(gdk_dnd.dnd_drag_curwin);
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0;
- gdk_dnd.dnd_drag_target = None;
- GDK_NOTE (DND,
- g_message("curwin = %#lx, lastwin = %#lx, dnd_drag_curwin = %#lx",
- curwin, lastwin, gdk_dnd.dnd_drag_curwin));
-
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
- else if(gdk_dnd.dnd_drag_dropzone.width > 0
- && gdk_dnd.dnd_drag_dropzone.height > 0
- && curwin == gdk_dnd.dnd_drag_curwin)
- {
- /* Handle all that dropzone stuff - thanks John ;-) */
- if (gdk_dnd.dnd_drag_target != None)
- {
- gboolean in_zone = IS_IN_ZONE(xevent->xmotion.x_root,
- xevent->xmotion.y_root);
- gboolean old_in_zone = IS_IN_ZONE(gdk_dnd.dnd_drag_oldpos.x,
- gdk_dnd.dnd_drag_oldpos.y);
-
- if (!in_zone && old_in_zone)
- {
- /* We were in the drop zone and moved out */
- gdk_dnd.dnd_drag_target = None;
- gdk_dnd_drag_leave(curwin);
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
- else if (!in_zone && !old_in_zone)
- {
- /* We were outside drop zone but in the window
- - have to send enter events */
- gdk_dnd_drag_enter(curwin);
- gdk_dnd.dnd_drag_curwin = curwin;
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_target = None;
- }
- }
- } /* else
- dnd_drag_curwin = None; */
- return_val = FALSE;
- }
- else
- return_val = window_private && !window_private->destroyed;
+ return_val = window_private && !window_private->destroyed;
break;
case EnterNotify:
@@ -2366,35 +2239,7 @@ gdk_event_translate (GdkEvent *event,
event->crossing.focus = xevent->xcrossing.focus;
event->crossing.state = xevent->xcrossing.state;
-
-#ifdef G_ENABLE_DEBUG
- if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps)
- {
- g_message("We may[%d] have a drag into %#lx = %#lx",
- gdk_dnd.drag_really,
- xevent->xcrossing.window, gdk_dnd.real_sw->xwindow);
- }
-#endif /* G_ENABLE_DEBUG */
-
- if (gdk_dnd.drag_perhaps && gdk_dnd.drag_really &&
- (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow))
- {
-#if 0
- gdk_dnd.drag_really = 0;
-
- GDK_NOTE (DND, g_message("Ungrabbed"));
-
- gdk_dnd.drag_numwindows = 0;
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- /* We don't want to ungrab the pointer here, or we'll
- * start getting spurious enter/leave events */
-#endif
-#if 0
- XChangeActivePointerGrab (gdk_display, 0, None, CurrentTime);
-#endif
- }
-
+
return_val = window_private && !window_private->destroyed;
break;
@@ -2465,37 +2310,6 @@ gdk_event_translate (GdkEvent *event,
event->crossing.focus = xevent->xcrossing.focus;
event->crossing.state = xevent->xcrossing.state;
-#ifdef G_ENABLE_DEBUG
- if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps)
- {
- g_message("We may[%d] have a drag out of %#lx = %#lx",
- gdk_dnd.drag_really,
- xevent->xcrossing.window, gdk_dnd.real_sw->xwindow);
- }
-#endif /* G_ENABLE_DEBUG */
- if (gdk_dnd.drag_perhaps && !gdk_dnd.drag_really &&
- (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow))
- {
- gboolean xgpret;
- gdk_dnd_drag_addwindow((GdkWindow *) gdk_dnd.real_sw);
- gdk_dnd_drag_begin((GdkWindow *) gdk_dnd.real_sw);
- xgpret =
- XGrabPointer(gdk_display, gdk_dnd.real_sw->xwindow, False,
- ButtonMotionMask | PointerMotionMask |
- /* PointerMotionHintMask | */ /* HINTME */
- ButtonPressMask | ButtonReleaseMask,
- GrabModeAsync, GrabModeAsync, None,
- None, CurrentTime);
-#ifdef G_ENABLE_DEBUG
- GDK_NOTE(DND, g_message("xgpret = %d", xgpret));
-#endif
- gdk_dnd.dnd_grabbed = TRUE;
- gdk_dnd.drag_really = 1;
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
-
return_val = window_private && !window_private->destroyed;
break;
@@ -2852,231 +2666,50 @@ gdk_event_translate (GdkEvent *event,
break;
case ClientMessage:
- /* Print debugging info.
- */
- GDK_NOTE (EVENTS,
- g_message ("client message:\twindow: %ld",
- xevent->xclient.window - base_id));
-
- /* Client messages are the means of the window manager
- * communicating with a program. We'll first check to
- * see if this is really the window manager talking
- * to us.
- */
- if (xevent->xclient.message_type == gdk_wm_protocols)
- {
- if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
- {
- /* The delete window request specifies a window
- * to delete. We don't actually destroy the
- * window because "it is only a request". (The
- * window might contain vital data that the
- * program does not want destroyed). Instead
- * the event is passed along to the program,
- * which should then destroy the window.
- */
-
- /* Print debugging info.
- */
- GDK_NOTE (EVENTS,
- g_message ("delete window:\t\twindow: %ld",
- xevent->xclient.window - base_id));
-
- event->any.type = GDK_DELETE;
- event->any.window = window;
-
- return_val = window_private && !window_private->destroyed;
- }
- else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
- {
- }
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter)
- {
- Atom reptype = 0;
-
- event->dropenter.u.allflags = xevent->xclient.data.l[1];
-
- GDK_NOTE (DND, g_message ("GDK_DROP_ENTER [%d][%d]",
- window_private->dnd_drop_enabled, event->dropenter.u.flags.sendreply));
- return_val = FALSE;
-
- /* Now figure out if we really want this drop...
- * If someone is trying funky clipboard stuff, ignore
- */
- if (window_private
- && window_private->dnd_drop_enabled
- && event->dropenter.u.flags.sendreply
- && (reptype = gdk_dnd_check_types (window, xevent)))
- {
- XEvent replyev;
-
- replyev.xclient.type = ClientMessage;
- replyev.xclient.window = xevent->xclient.data.l[0];
- replyev.xclient.format = 32;
- replyev.xclient.message_type = gdk_dnd.gdk_XdeRequest;
- replyev.xclient.data.l[0] = window_private->xwindow;
-
- event->dragrequest.u.allflags = 0;
- event->dragrequest.u.flags.protocol_version =
- DND_PROTOCOL_VERSION;
- event->dragrequest.u.flags.willaccept = 1;
- event->dragrequest.u.flags.delete_data =
- (window_private->dnd_drop_destructive_op) ? 1 : 0;
-
- replyev.xclient.data.l[1] = event->dragrequest.u.allflags;
- replyev.xclient.data.l[2] = replyev.xclient.data.l[3] = 0;
- replyev.xclient.data.l[4] = reptype;
-
- if (!gdk_send_xevent (replyev.xclient.window, False,
- NoEventMask, &replyev))
- GDK_NOTE (DND, g_message("Sending XdeRequest to %#lx failed",
- replyev.xclient.window));
-
- event->any.type = GDK_DROP_ENTER;
- event->any.window = window;
- event->dropenter.requestor = replyev.xclient.window;
- event->dropenter.u.allflags = xevent->xclient.data.l[1];
-
- GDK_NOTE (DND, g_message("We sent a GDK_DROP_ENTER on to Gtk"));
- return_val = TRUE;
- }
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeLeave)
- {
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message ("GDK_DROP_LEAVE");
-#endif
-
- if (window_private && window_private->dnd_drop_enabled)
- {
- event->dropleave.type = GDK_DROP_LEAVE;
- event->dropleave.window = window;
- event->dropleave.requestor = xevent->xclient.data.l[0];
- event->dropleave.u.allflags = xevent->xclient.data.l[1];
- return_val = TRUE;
- }
- else
+ {
+ GList *tmp_list;
+ GdkFilterReturn result = GDK_FILTER_CONTINUE;
+
+ /* Print debugging info.
+ */
+ GDK_NOTE (EVENTS,
+ g_message ("client message:\twindow: %ld",
+ xevent->xclient.window - base_id));
+
+ tmp_list = client_filters;
+ while (tmp_list)
+ {
+ GdkClientFilter *filter = tmp_list->data;
+ if (filter->type == xevent->xclient.message_type)
+ {
+ result = (*filter->function) (xevent, event, filter->data);
+ break;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+
+ switch (result)
+ {
+ case GDK_FILTER_REMOVE:
return_val = FALSE;
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeRequest)
- {
- /*
- * make sure to only handle requests from the window the cursor is
- * over
- */
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message ("GDK_DRAG_REQUEST");
-#endif
- event->dragrequest.u.allflags = xevent->xclient.data.l[1];
- return_val = FALSE;
-
- if (window && gdk_dnd.drag_really &&
- xevent->xclient.data.l[0] == gdk_dnd.dnd_drag_curwin &&
- event->dragrequest.u.flags.sendreply == 0)
- {
- /* Got request - do we need to ask user? */
- if (!event->dragrequest.u.flags.willaccept
- && event->dragrequest.u.flags.senddata)
- {
- /* Yes we do :) */
- event->dragrequest.type = GDK_DRAG_REQUEST;
- event->dragrequest.window = window;
- event->dragrequest.requestor = xevent->xclient.data.l[0];
- event->dragrequest.isdrop = 0;
- event->dragrequest.drop_coords.x =
- event->dragrequest.drop_coords.y = 0;
- return_val = TRUE;
- }
- else if (event->dragrequest.u.flags.willaccept)
- {
- window_private->dnd_drag_destructive_op =
- event->dragrequest.u.flags.delete_data;
- window_private->dnd_drag_accepted = 1;
- window_private->dnd_drag_data_type =
- xevent->xclient.data.l[4];
-
- gdk_dnd.dnd_drag_target = gdk_dnd.dnd_drag_curwin;
- gdk_dnd_display_drag_cursor(-1, -1, TRUE, TRUE);
- }
- gdk_dnd.dnd_drag_dropzone.x = xevent->xclient.data.l[2] & 65535;
- gdk_dnd.dnd_drag_dropzone.y =
- (xevent->xclient.data.l[2] >> 16) & 65535;
- gdk_dnd.dnd_drag_dropzone.width = xevent->xclient.data.l[3] & 65535;
- gdk_dnd.dnd_drag_dropzone.height =
- (xevent->xclient.data.l[3] >> 16) & 65535;
- }
- }
- else if(xevent->xclient.message_type == gdk_dnd.gdk_XdeDataAvailable)
- {
- gint tmp_int; Atom tmp_atom;
- gulong tmp_long;
- guchar *tmp_charptr;
-
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message("GDK_DROP_DATA_AVAIL");
-#endif
- event->dropdataavailable.u.allflags = xevent->xclient.data.l[1];
- event->dropdataavailable.timestamp = xevent->xclient.data.l[4];
- event->dropdataavailable.coords.x =
- xevent->xclient.data.l[3] & 0xffff;
- event->dropdataavailable.coords.y =
- (xevent->xclient.data.l[3] >> 16) & 0xffff;
- if(window
- /* No preview of data ATM */
- && event->dropdataavailable.u.flags.isdrop)
- {
- event->dropdataavailable.type = GDK_DROP_DATA_AVAIL;
- event->dropdataavailable.window = window;
- event->dropdataavailable.requestor = xevent->xclient.data.l[0];
- event->dropdataavailable.data_type =
- gdk_atom_name(xevent->xclient.data.l[2]);
- if(XGetWindowProperty (gdk_display,
- event->dropdataavailable.requestor,
- xevent->xclient.data.l[2],
- 0, LONG_MAX - 1,
- False, XA_PRIMARY, &tmp_atom,
- &tmp_int,
- &event->dropdataavailable.data_numbytes,
- &tmp_long,
- &tmp_charptr)
- != Success)
- {
- g_warning("XGetWindowProperty on %#x may have failed\n",
- event->dropdataavailable.requestor);
- event->dropdataavailable.data = NULL;
- }
- else
- {
- GDK_NOTE (DND, g_message("XGetWindowProperty got us %ld bytes",
- event->dropdataavailable.data_numbytes));
- event->dropdataavailable.data =
- g_malloc (event->dropdataavailable.data_numbytes);
- memcpy (event->dropdataavailable.data,
- tmp_charptr, event->dropdataavailable.data_numbytes);
- XFree(tmp_charptr);
- return_val = TRUE;
- }
- return_val = TRUE;
- }
- }
- else
- {
- /* Send unknown ClientMessage's on to Gtk for it to use */
- event->client.type = GDK_CLIENT_EVENT;
- event->client.window = window;
- event->client.message_type = xevent->xclient.message_type;
- event->client.data_format = xevent->xclient.format;
- memcpy(&event->client.data, &xevent->xclient.data,
- sizeof(event->client.data));
- if(window)
+ break;
+ case GDK_FILTER_TRANSLATE:
return_val = TRUE;
- else
- return_val = FALSE;
- }
+ break;
+ case GDK_FILTER_CONTINUE:
+ /* Send unknown ClientMessage's on to Gtk for it to use */
+ event->client.type = GDK_CLIENT_EVENT;
+ event->client.window = window;
+ event->client.message_type = xevent->xclient.message_type;
+ event->client.data_format = xevent->xclient.format;
+ memcpy(&event->client.data, &xevent->xclient.data,
+ sizeof(event->client.data));
+
+ return_val = (window != NULL);
+ }
+ }
+
if(window_private)
return_val = return_val && !window_private->destroyed;
break;
@@ -3129,6 +2762,38 @@ gdk_event_translate (GdkEvent *event,
return return_val;
}
+GdkFilterReturn
+gdk_wm_protocols_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+
+ if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
+ {
+ /* The delete window request specifies a window
+ * to delete. We don't actually destroy the
+ * window because "it is only a request". (The
+ * window might contain vital data that the
+ * program does not want destroyed). Instead
+ * the event is passed along to the program,
+ * which should then destroy the window.
+ */
+ GDK_NOTE (EVENTS,
+ g_message ("delete window:\t\twindow: %ld",
+ xevent->xclient.window - base_id));
+
+ event->any.type = GDK_DELETE;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
+ {
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
#if 0
static Bool
gdk_event_get_type (Display *display,
@@ -3344,67 +3009,6 @@ gdk_signal (int sig_num)
#endif /* !G_ENABLE_DEBUG */
}
-static void
-gdk_dnd_drag_begin (GdkWindow *initial_window)
-{
- GdkEvent tev;
-
- GDK_NOTE(DND, g_message("------- STARTING DRAG from %p", initial_window));
-
- tev.type = GDK_DRAG_BEGIN;
- tev.dragbegin.window = initial_window;
- tev.dragbegin.u.allflags = 0;
- tev.dragbegin.u.flags.protocol_version = DND_PROTOCOL_VERSION;
-
- gdk_event_put (&tev);
-}
-
-static void
-gdk_dnd_drag_enter (Window dest)
-{
- XEvent sev;
- GdkEventDropEnter tev;
- int i;
- GdkWindowPrivate *wp;
-
- sev.xclient.type = ClientMessage;
- sev.xclient.format = 32;
- sev.xclient.message_type = gdk_dnd.gdk_XdeEnter;
- sev.xclient.window = dest;
-
- tev.u.allflags = 0;
- tev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tev.u.flags.sendreply = 1;
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- if (wp->dnd_drag_data_numtypesavail)
- {
- sev.xclient.data.l[0] = wp->xwindow;
- tev.u.flags.extended_typelist = (wp->dnd_drag_data_numtypesavail > 3)?1:0;
- sev.xclient.data.l[1] = tev.u.allflags;
- sev.xclient.data.l[2] = wp->dnd_drag_data_typesavail[0];
- if (wp->dnd_drag_data_numtypesavail > 1)
- {
- sev.xclient.data.l[3] = wp->dnd_drag_data_typesavail[1];
- if (wp->dnd_drag_data_numtypesavail > 2)
- {
- sev.xclient.data.l[4] = wp->dnd_drag_data_typesavail[2];
- }
- else
- sev.xclient.data.l[4] = None;
- }
- else
- sev.xclient.data.l[3] = sev.xclient.data.l[4] = None;
- if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeEnter to %#lx failed",
- dest));
- }
-
- }
-}
-
-
#ifdef USE_XIM
/* The following routines duplicate functionality in Xlib to
@@ -4051,145 +3655,58 @@ _g_mbtowc (wchar_t *wstr, const char *str, size_t len)
#endif /* X_LOCALE */
-static void
-gdk_dnd_drag_leave (Window dest)
-{
- XEvent sev;
- GdkEventDropLeave tev;
- int i;
- GdkWindowPrivate *wp;
-
- tev.u.allflags = 0;
-
- tev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- sev.xclient.type = ClientMessage;
- sev.xclient.window = dest;
- sev.xclient.format = 32;
- sev.xclient.message_type = gdk_dnd.gdk_XdeLeave;
- sev.xclient.data.l[1] = tev.u.allflags;
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- sev.xclient.data.l[0] = wp->xwindow;
- if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeLeave to %#lx failed",
- dest));
- wp->dnd_drag_accepted = 0;
- }
-}
-
/*
- * when a drop occurs, we go through the list of windows being dragged and
- * tell them that it has occurred, so that they can set things up and reply
- * to 'dest' window
+ * used for debugging only
*/
+#ifdef DEBUG_DND
static void
-gdk_dnd_drag_end (Window dest,
- GdkPoint coords)
+gdk_print_atom (GdkAtom anatom)
{
- GdkWindowPrivate *wp;
- GdkEvent tev;
- int i;
-
- tev.dragrequest.type = GDK_DRAG_REQUEST;
- tev.dragrequest.drop_coords = coords;
- tev.dragrequest.requestor = dest;
- tev.dragrequest.u.allflags = 0;
- tev.dragrequest.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tev.dragrequest.isdrop = 1;
-
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- if (wp->dnd_drag_accepted)
- {
- tev.dragrequest.window = (GdkWindow *) wp;
- tev.dragrequest.u.flags.delete_data = wp->dnd_drag_destructive_op;
- tev.dragrequest.timestamp = gdk_dnd.last_drop_time;
- tev.dragrequest.data_type =
- gdk_atom_name(wp->dnd_drag_data_type);
-
- gdk_event_put(&tev);
- }
- }
+ gchar *tmpstr = NULL;
+ tmpstr = (anatom!=None)?gdk_atom_name(anatom):"(none)";
+ g_message("Atom %lu has name %s", anatom, tmpstr);
+ if(tmpstr)
+ g_free(tmpstr);
}
+#endif
-static GdkAtom
-gdk_dnd_check_types (GdkWindow *window,
- XEvent *xevent)
+#ifdef WE_HAVE_MOTIF_DROPS_DONE
+static GdkWindow *
+gdk_drop_get_real_window (GdkWindow *w,
+ guint16 *x,
+ guint16 *y)
{
- GdkWindowPrivate *wp = (GdkWindowPrivate *) window;
- int i, j;
- GdkEventDropEnter event;
+ GdkWindow *retval = w;
+ GdkWindowPrivate *awin;
+ GList *children;
+ gint16 myx = *x, myy = *y;
- g_return_val_if_fail(window != NULL, 0);
- g_return_val_if_fail(xevent != NULL, 0);
- g_return_val_if_fail(xevent->type == ClientMessage, 0);
- g_return_val_if_fail(xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter, 0);
+ g_return_val_if_fail (w != NULL && x != NULL && y != NULL, NULL);
- if(wp->dnd_drop_data_numtypesavail <= 0 ||
- !wp->dnd_drop_data_typesavail)
- return 0;
+ myx = *x;
+ myy = *y;
- for (i = 2; i <= 4; i++)
+ descend:
+ for (children = gdk_window_get_children(retval);
+ children && children->next;
+ children = children->next)
{
- for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++)
+ awin = (GdkWindowPrivate *) children->data;
+ if ((myx >= awin->x) && (myy >= awin->y)
+ && (myx < (awin->x + awin->width))
+ && (myy < (awin->y + awin->height)))
{
- if (xevent->xclient.data.l[i] == wp->dnd_drop_data_typesavail[j])
- return xevent->xclient.data.l[i];
+ retval = (GdkWindow *) awin;
+ myx -= awin->x;
+ myy -= awin->y;
+ goto descend;
}
}
- /* Now we get the extended type list if it's available */
- event.u.allflags = xevent->xclient.data.l[1];
- if (event.u.flags.extended_typelist)
- {
- Atom *exttypes, realtype;
- gulong nitems, nbar;
- gint realfmt;
-
- if (XGetWindowProperty(gdk_display, xevent->xclient.data.l[0],
- gdk_dnd.gdk_XdeTypelist, 0L, LONG_MAX - 1,
- False, AnyPropertyType, &realtype, &realfmt,
- &nitems, &nbar, (unsigned char **) &exttypes)
- != Success)
- return 0;
-
- if (realfmt != (sizeof(Atom) * 8))
- {
- g_warning("XdeTypelist property had format of %d instead of the expected %ld, on window %#lx\n",
- realfmt, (glong)sizeof(Atom) * 8, xevent->xclient.data.l[0]);
- return 0;
- }
-
- for (i = 0; i <= nitems; i++)
- {
- for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++)
- {
- if (exttypes[i] == wp->dnd_drop_data_typesavail[j])
- {
- XFree (exttypes);
- return exttypes[i];
- }
- }
- }
- XFree (exttypes);
- }
- return 0;
-}
-
-/*
- * used for debugging only
- */
-#ifdef DEBUG_DND
-static void
-gdk_print_atom (GdkAtom anatom)
-{
- gchar *tmpstr = NULL;
- tmpstr = (anatom!=None)?gdk_atom_name(anatom):"(none)";
- g_message("Atom %lu has name %s", anatom, tmpstr);
- if(tmpstr)
- g_free(tmpstr);
+ *x = myx;
+ *y = myy;
+
+ return retval;
}
#endif
@@ -4199,7 +3716,7 @@ gdk_print_atom (GdkAtom anatom)
static Window
getchildren (Display *dpy,
Window win,
- Atom WM_STATE)
+ Atom wm_state_atom)
{
Window root, parent, *children, inf = 0;
Atom type = None;
@@ -4213,7 +3730,7 @@ getchildren (Display *dpy,
for (i = 0; !inf && (i < nchildren); i++)
{
- XGetWindowProperty (dpy, children[i], WM_STATE, 0, 0, False,
+ XGetWindowProperty (dpy, children[i], wm_state_atom, 0, 0, False,
AnyPropertyType, &type, &format, &nitems,
&after, &data);
if (type != 0)
@@ -4222,7 +3739,7 @@ getchildren (Display *dpy,
}
for (i = 0; !inf && (i < nchildren); i++)
- inf = getchildren (dpy, children[i], WM_STATE);
+ inf = getchildren (dpy, children[i], wm_state_atom);
if (children != None)
XFree ((char *) children);
@@ -4239,7 +3756,7 @@ Window
gdk_get_client_window (Display *dpy,
Window win)
{
- Atom WM_STATE;
+ static Atom wm_state_atom = None;
Atom type = None;
int format;
unsigned long nitems, after;
@@ -4249,15 +3766,18 @@ gdk_get_client_window (Display *dpy,
if (win == 0)
return DefaultRootWindow(dpy);
- if ((WM_STATE = XInternAtom (dpy, "WM_STATE", True)) == 0)
+ if ((wm_state_atom = XInternAtom (dpy, "WM_STATE", True)) == 0)
return win;
-
- XGetWindowProperty (dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
+
+ XGetWindowProperty (dpy, win, wm_state_atom, 0, 0, False, AnyPropertyType,
&type, &format, &nitems, &after, &data);
if (type)
- return win;
+ {
+ XFree (data);
+ return win;
+ }
- inf = getchildren (dpy, win, WM_STATE);
+ inf = getchildren (dpy, win, wm_state_atom);
if (inf == 0)
return win;
@@ -4265,46 +3785,6 @@ gdk_get_client_window (Display *dpy,
return inf;
}
-#ifdef WE_HAVE_MOTIF_DROPS_DONE
-static GdkWindow *
-gdk_drop_get_real_window (GdkWindow *w,
- guint16 *x,
- guint16 *y)
-{
- GdkWindow *retval = w;
- GdkWindowPrivate *awin;
- GList *children;
- gint16 myx = *x, myy = *y;
-
- g_return_val_if_fail (w != NULL && x != NULL && y != NULL, NULL);
-
- myx = *x;
- myy = *y;
-
- descend:
- for (children = gdk_window_get_children(retval);
- children && children->next;
- children = children->next)
- {
- awin = (GdkWindowPrivate *) children->data;
- if ((myx >= awin->x) && (myy >= awin->y)
- && (myx < (awin->x + awin->width))
- && (myy < (awin->y + awin->height)))
- {
- retval = (GdkWindow *) awin;
- myx -= awin->x;
- myy -= awin->y;
- goto descend;
- }
- }
-
- *x = myx;
- *y = myy;
-
- return retval;
-}
-#endif
-
/* Sends a ClientMessage to all toplevel client windows */
void
gdk_event_send_clientmessage_toall (GdkEvent *event)
@@ -4320,7 +3800,6 @@ gdk_event_send_clientmessage_toall (GdkEvent *event)
sev.xclient.type = ClientMessage;
sev.xclient.display = gdk_display;
sev.xclient.format = event->client.data_format;
- sev.xclient.serial = CurrentTime;
memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
sev.xclient.message_type = event->client.message_type;
@@ -4352,13 +3831,14 @@ gdk_send_xevent (Window window, gboolean propagate, glong event_mask,
XEvent *event_send)
{
Status result;
+ gint old_warnings = gdk_error_warnings;
gdk_error_code = 0;
gdk_error_warnings = 0;
result = XSendEvent (gdk_display, window, propagate, event_mask, event_send);
XSync (gdk_display, False);
- gdk_error_warnings = 1;
+ gdk_error_warnings = old_warnings;
return result && (gdk_error_code != -1);
}
diff --git a/gdk/gdk.h b/gdk/gdk.h
index 6ee99665a3..1d188c78a1 100644
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -40,8 +40,9 @@ GdkEvent *gdk_event_get (void);
GdkEvent *gdk_event_get_graphics_expose (GdkWindow *window);
void gdk_event_put (GdkEvent *event);
-GdkEvent *gdk_event_copy (GdkEvent *event);
-void gdk_event_free (GdkEvent *event);
+GdkEvent *gdk_event_copy (GdkEvent *event);
+void gdk_event_free (GdkEvent *event);
+guint32 gdk_event_get_time (GdkEvent *event);
void gdk_set_show_events (gint show_events);
void gdk_set_use_xshm (gint use_xshm);
@@ -196,51 +197,61 @@ void gdk_window_shape_combine_mask (GdkWindow *window,
gint offset_x,
gint offset_y);
-/*
- * Drag & Drop
- * Algorithm (drop source):
- * A window being dragged will be sent a GDK_DRAG_BEGIN message.
- * It will then do gdk_dnd_drag_addwindow() for any other windows that are to be
- * dragged.
- * When we get a DROP_ENTER incoming, we send it on to the window in question.
- * That window needs to use gdk_dnd_drop_enter_reply() to indicate the state of
- * things (it must call that even if it's not going to accept the drop)
- *
- * These two turn on/off drag or drop, and if enabling it also
- * sets the list of types supported. The list of types passed in
- * should be in order of decreasing preference.
- */
-void gdk_window_dnd_drag_set (GdkWindow *window,
- guint8 drag_enable,
- gchar **typelist,
- guint numtypes);
-
-/*
- *XXX todo: add a GDK_DROP_ENTER which can look at actual data
- */
-void gdk_window_dnd_drop_set (GdkWindow *window,
- guint8 drop_enable,
- gchar **typelist,
- guint numtypes,
- guint8 destructive_op);
-
-/*
- * This is used by the GDK_DRAG_BEGIN handler. An example of usage would be a
- * file manager where multiple icons were selected and the drag began.
- * The icon that the drag actually began on would gdk_dnd_drag_addwindow
- * for all the other icons that were being dragged...
+/*
+ * The following function adds a global filter for all client
+ * messages of type message_type
*/
-void gdk_dnd_drag_addwindow (GdkWindow *window);
-void gdk_window_dnd_data_set (GdkWindow *window,
- GdkEvent *event,
- gpointer data,
- gulong data_numbytes);
-void gdk_dnd_set_drag_cursors(GdkCursor *default_cursor,
- GdkCursor *goahead_cursor);
-void gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin,
- GdkPoint *default_hotspot,
- GdkWindow *goahead_pixmapwin,
- GdkPoint *goahead_hotspot);
+void gdk_add_client_message_filter (GdkAtom message_type,
+ GdkFilterFunc func,
+ gpointer data);
+
+/* Drag and Drop */
+
+GdkDragContext * gdk_drag_context_new (void);
+void gdk_drag_context_ref (GdkDragContext *context);
+void gdk_drag_context_unref (GdkDragContext *context);
+
+/* Destination side */
+
+void gdk_drag_status (GdkDragContext *context,
+ GdkDragAction action,
+ guint32 time);
+void gdk_drop_reply (GdkDragContext *context,
+ gboolean ok,
+ guint32 time);
+void gdk_drop_finish (GdkDragContext *context,
+ gboolean success,
+ guint32 time);
+GdkAtom gdk_drag_get_selection (GdkDragContext *context);
+
+/* Source side */
+
+GdkDragContext * gdk_drag_begin (GdkWindow *window,
+ GList *targets,
+ GdkDragAction actions);
+gboolean gdk_drag_get_protocol (guint32 xid,
+ GdkDragProtocol *protocol);
+void gdk_drag_find_window (GdkDragContext *context,
+ GdkWindow *drag_window,
+ gint x_root,
+ gint y_root,
+ GdkWindow **dest_window,
+ GdkDragProtocol *protocol);
+gboolean gdk_drag_motion (GdkDragContext *context,
+ GdkWindow *dest_window,
+ GdkDragProtocol protocol,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time);
+void gdk_drag_drop (GdkDragContext *context,
+ guint32 time);
+void gdk_drag_abort (GdkDragContext *context,
+ guint32 time);
+
+GdkAtom gdk_drag_get_selection (GdkDragContext *context);
+
+/* GdkWindow */
void gdk_window_set_hints (GdkWindow *window,
gint x,
@@ -309,6 +320,8 @@ void gdk_window_set_functions (GdkWindow *window,
GdkWMFunction functions);
GList * gdk_window_get_toplevels (void);
+void gdk_window_register_dnd (GdkWindow *window);
+
void gdk_drawable_set_data (GdkDrawable *drawable,
const gchar *key,
gpointer data,
@@ -477,14 +490,24 @@ gboolean gdk_colormap_alloc_color (GdkColormap *colormap,
void gdk_colormap_free_colors (GdkColormap *colormap,
GdkColor *colors,
gint ncolors);
-
-void gdk_colors_store (GdkColormap *colormap,
- GdkColor *colors,
- gint ncolors);
+GdkVisual *gdk_colormap_get_visual (GdkColormap *colormap);
+
GdkColor *gdk_color_copy (GdkColor *color);
void gdk_color_free (GdkColor *color);
+gint gdk_color_parse (const gchar *spec,
+ GdkColor *color);
+guint gdk_color_hash (const GdkColor *colora,
+ const GdkColor *colorb);
+gint gdk_color_equal (const GdkColor *colora,
+ const GdkColor *colorb);
+
+
+/* The following functions are deprecated */
+void gdk_colors_store (GdkColormap *colormap,
+ GdkColor *colors,
+ gint ncolors);
gint gdk_colors_alloc (GdkColormap *colormap,
gint contiguous,
gulong *planes,
@@ -499,16 +522,10 @@ gint gdk_color_white (GdkColormap *colormap,
GdkColor *color);
gint gdk_color_black (GdkColormap *colormap,
GdkColor *color);
-gint gdk_color_parse (const gchar *spec,
- GdkColor *color);
gint gdk_color_alloc (GdkColormap *colormap,
GdkColor *color);
gint gdk_color_change (GdkColormap *colormap,
GdkColor *color);
-guint gdk_color_hash (const GdkColor *colora,
- const GdkColor *colorb);
-gint gdk_color_equal (const GdkColor *colora,
- const GdkColor *colorb);
/* Fonts
diff --git a/gdk/gdkcolor.c b/gdk/gdkcolor.c
index 36b6c8593c..f84f570255 100644
--- a/gdk/gdkcolor.c
+++ b/gdk/gdkcolor.c
@@ -179,6 +179,18 @@ gdk_colormap_unref (GdkColormap *cmap)
gdk_colormap_real_destroy (cmap);
}
+GdkVisual *
+gdk_colormap_get_visual (GdkColormap *colormap)
+{
+ GdkColormapPrivate *private;
+
+ g_return_val_if_fail (colormap != NULL, NULL);
+
+ private = (GdkColormapPrivate *)colormap;
+
+ return private->visual;
+}
+
#define MIN_SYNC_TIME 2
void
diff --git a/gdk/gdkdnd.c b/gdk/gdkdnd.c
index 331aad7ef7..67720ad6bd 100644
--- a/gdk/gdkdnd.c
+++ b/gdk/gdkdnd.c
@@ -20,157 +20,2853 @@
#include <X11/Xatom.h>
#include <string.h>
#include "gdkx.h"
+#include "gdk/gdkprivate.h"
#include "gdk.h"
-/* Nothing much here now, but we have to make a start some time ;-) */
+typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
-void
-gdk_dnd_set_drag_cursors(GdkCursor *default_cursor, GdkCursor *goahead_cursor)
+typedef enum {
+ GDK_DRAG_STATUS_DRAG,
+ GDK_DRAG_STATUS_MOTION_WAIT,
+ GDK_DRAG_STATUS_ACTION_WAIT,
+ GDK_DRAG_STATUS_DROP
+} GtkDragStatus;
+
+typedef struct {
+ guint32 xid;
+ gint x, y, width, height;
+ gboolean mapped;
+} GdkCacheChild;
+
+typedef struct {
+ GList *children;
+ GHashTable *child_hash;
+ guint old_event_mask;
+} GdkWindowCache;
+
+/* Structure that holds information about a drag in progress.
+ * this is used on both source and destination sides.
+ */
+struct _GdkDragContextPrivate {
+ GdkDragContext context;
+
+ GdkAtom motif_selection;
+ GdkAtom xdnd_selection;
+ guint ref_count;
+
+ guint16 last_x; /* Coordinates from last event */
+ guint16 last_y;
+ GdkDragAction old_action; /* The last action we sent to the source */
+
+ Window dest_xid;
+ guint xdnd_targets_set : 1; /* Whether we've already set XdndTypeList */
+ guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
+ guint drag_status : 4; /* current status of drag */
+
+ GdkWindowCache *window_cache;
+};
+
+GdkDragContext *current_dest_drag = NULL;
+
+/* Forward declarations */
+
+static void gdk_window_cache_destroy (GdkWindowCache *cache);
+
+static void motif_read_target_table (void);
+static GdkFilterReturn motif_dnd_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+/* Drag Contexts */
+
+static GList *contexts;
+
+GdkDragContext *
+gdk_drag_context_new (void)
+{
+ GdkDragContextPrivate *result;
+
+ result = g_new0 (GdkDragContextPrivate, 1);
+
+ result->ref_count = 1;
+
+ contexts = g_list_prepend (contexts, result);
+
+ return (GdkDragContext *)result;
+}
+
+void
+gdk_drag_context_ref (GdkDragContext *context)
+{
+ ((GdkDragContextPrivate *)context)->ref_count++;
+}
+
+void
+gdk_drag_context_unref (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ private->ref_count--;
+
+ if (private->ref_count == 0)
+ {
+ g_dataset_destroy (private);
+
+ g_list_free (context->targets);
+
+ if (context->source_window)
+ gdk_window_unref (context->source_window);
+
+ if (context->dest_window)
+ gdk_window_unref (context->dest_window);
+
+ if (private->window_cache)
+ gdk_window_cache_destroy (private->window_cache);
+
+ contexts = g_list_remove (contexts, private);
+ g_free (private);
+ }
+}
+
+static GdkDragContext *
+gdk_drag_context_find (gboolean is_source,
+ Window source_xid,
+ Window dest_xid)
+{
+ GList *tmp_list = contexts;
+
+ while (tmp_list)
+ {
+ GdkDragContext *context = (GdkDragContext *)tmp_list->data;
+
+ if ((!context->is_source == !is_source) &&
+ ((source_xid == None) || (context->source_window &&
+ (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
+ ((dest_xid == None) || (context->dest_window &&
+ (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
+ return context;
+
+ tmp_list = tmp_list->next;
+ }
+
+ return NULL;
+}
+
+/* Utility functions */
+
+static void
+gdk_window_cache_add (GdkWindowCache *cache,
+ guint32 xid,
+ gint x, gint y, gint width, gint height,
+ gboolean mapped)
+{
+ GdkCacheChild *child = g_new (GdkCacheChild, 1);
+
+ child->xid = xid;
+ child->x = x;
+ child->y = y;
+ child->width = width;
+ child->height = height;
+ child->mapped = mapped;
+
+ cache->children = g_list_prepend (cache->children, child);
+ g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
+ cache->children);
+}
+
+static GdkFilterReturn
+gdk_window_cache_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ GdkWindowCache *cache = data;
+
+ switch (xevent->type)
+ {
+ case CirculateNotify:
+ break;
+ case ConfigureNotify:
+ {
+ XConfigureEvent *xce = &xevent->xconfigure;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xce->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->x = xce->x;
+ child->y = xce->y;
+ child->width = xce->width;
+ child->height = xce->height;
+ if (xce->above == None && (node->next))
+ {
+ GList *last = g_list_last (cache->children);
+ cache->children = g_list_remove_link (cache->children, node);
+ last->next = node;
+ node->next = NULL;
+ node->prev = last;
+ }
+ else
+ {
+ GList *above_node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xce->above));
+ if (above_node && node->prev != above_node)
+ {
+ cache->children = g_list_remove_link (cache->children, node);
+ node->next = above_node->next;
+ node->prev = above_node;
+ above_node->next = node;
+ }
+ }
+ }
+ break;
+ }
+ case CreateNotify:
+ {
+ XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
+ if (!g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xcwe->window)))
+ gdk_window_cache_add (cache, xcwe->window,
+ xcwe->x, xcwe->y, xcwe->width, xcwe->height,
+ FALSE);
+ break;
+ }
+ case DestroyNotify:
+ {
+ XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xdwe->window));
+ if (node)
+ {
+ g_hash_table_remove (cache->child_hash,
+ GUINT_TO_POINTER (xdwe->window));
+ cache->children = g_list_remove_link (cache->children, node);
+ g_free (node->data);
+ g_list_free_1 (node);
+ }
+ break;
+ }
+ case MapNotify:
+ {
+ XMapEvent *xme = &xevent->xmap;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xme->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->mapped = TRUE;
+ }
+ break;
+ }
+ case ReparentNotify:
+ break;
+ case UnmapNotify:
+ {
+ XMapEvent *xume = &xevent->xmap;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xume->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->mapped = FALSE;
+ }
+ break;
+ }
+ default:
+ return GDK_FILTER_CONTINUE;
+ }
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkWindowCache *
+gdk_window_cache_new (void)
+{
+ XWindowAttributes xwa;
+ Window root, parent, *children;
+ unsigned int nchildren;
+ int i;
+
+ gint old_warnings = gdk_error_warnings;
+
+ GdkWindowCache *result = g_new (GdkWindowCache, 1);
+
+ result->children = NULL;
+ result->child_hash = g_hash_table_new (g_direct_hash, NULL);
+
+ XGetWindowAttributes (gdk_display, gdk_root_window, &xwa);
+ result->old_event_mask = xwa.your_event_mask;
+ XSelectInput (gdk_display, gdk_root_window,
+ result->old_event_mask | SubstructureNotifyMask);
+ gdk_window_add_filter ((GdkWindow *)&gdk_root_parent,
+ gdk_window_cache_filter, result);
+
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ if (XQueryTree(gdk_display, gdk_root_window,
+ &root, &parent, &children, &nchildren) == 0)
+ return result;
+
+ for (i = 0; i < nchildren ; i++)
+ {
+ XGetWindowAttributes (gdk_display, children[i], &xwa);
+
+ gdk_window_cache_add (result, children[i],
+ xwa.x, xwa.y, xwa.width, xwa.height,
+ xwa.map_state != IsUnmapped);
+
+ if (gdk_error_code != 0)
+ gdk_error_code = 0;
+ else
+ {
+ gdk_window_cache_add (result, children[i],
+ xwa.x, xwa.y, xwa.width, xwa.height,
+ (xwa.map_state != IsUnmapped));
+ }
+ }
+
+ XFree (children);
+
+ gdk_error_warnings = old_warnings;
+
+ return result;
+}
+
+static void
+gdk_window_cache_destroy (GdkWindowCache *cache)
+{
+ XSelectInput (gdk_display, gdk_root_window, cache->old_event_mask);
+ gdk_window_remove_filter ((GdkWindow *)&gdk_root_parent,
+ gdk_window_cache_filter, cache);
+
+ g_list_foreach (cache->children, (GFunc)g_free, NULL);
+ g_list_free (cache->children);
+ g_hash_table_destroy (cache->child_hash);
+}
+
+static Window
+get_client_window_at_coords_recurse (Window win,
+ gint x_root,
+ gint y_root)
+{
+ Window child;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+ int dest_x, dest_y;
+
+ static Atom wm_state_atom = None;
+
+ if (!wm_state_atom)
+ wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ wm_state_atom, 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (type != None)
+ {
+ XFree (data);
+ return win;
+ }
+
+ XTranslateCoordinates (gdk_display, gdk_root_window, win,
+ x_root, y_root, &dest_x, &dest_y, &child);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (child)
+ return get_client_window_at_coords_recurse (child, x_root, y_root);
+ else
+ return None;
+}
+
+Window
+get_client_window_at_coords (GdkWindowCache *cache,
+ Window ignore,
+ gint x_root,
+ gint y_root)
{
- gdk_dnd.c->gdk_cursor_dragdefault =
- ((GdkCursorPrivate *)default_cursor)->xcursor;
- gdk_dnd.c->gdk_cursor_dragok = ((GdkCursorPrivate *)goahead_cursor)->xcursor;
+ GList *tmp_list;
+ Window retval = None;
+
+ gint old_warnings = gdk_error_warnings;
- if(gdk_dnd.dnd_grabbed)
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ tmp_list = cache->children;
+
+ while (tmp_list && !retval)
{
- if(gdk_dnd.c->drag_pm_default)
- /* We were displaying pixmaps for the drag */
+ GdkCacheChild *child = tmp_list->data;
+
+ if ((child->xid != ignore) && (child->mapped))
{
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- gdk_window_unref(gdk_dnd.c->drag_pm_default);
- if(gdk_dnd.c->drag_pm_ok)
+ if ((x_root >= child->x) && (x_root < child->x + child->width) &&
+ (y_root >= child->y) && (y_root < child->y + child->height))
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_unref(gdk_dnd.c->drag_pm_ok);
+ retval = get_client_window_at_coords_recurse (child->xid,
+ x_root, y_root);
+ if (!retval)
+ retval = child->xid;
}
- gdk_dnd.c->drag_pm_default = gdk_dnd.c->drag_pm_ok = NULL;
- g_list_free(gdk_dnd.c->xids);
- gdk_dnd.c->xids = NULL;
+
}
- gdk_dnd_display_drag_cursor(-1, -1,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- TRUE);
+ tmp_list = tmp_list->next;
}
+
+ gdk_error_warnings = old_warnings;
+ if (retval)
+ return retval;
+ else
+ return gdk_root_window;
}
-void
-gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin,
- GdkPoint *default_hotspot,
- GdkWindow *goahead_pixmapwin,
- GdkPoint *goahead_hotspot)
+#if 0
+static Window
+get_client_window_at_coords_recurse (Window win,
+ gint x_root,
+ gint y_root)
{
- g_return_if_fail(default_pixmapwin != NULL);
+ Window child;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+ int dest_x, dest_y;
- g_list_free(gdk_dnd.c->xids); gdk_dnd.c->xids = NULL;
- if(gdk_dnd.c->drag_pm_default)
+ static Atom wm_state_atom = None;
+
+ if (!wm_state_atom)
+ wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ wm_state_atom, 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (type != None)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- gdk_window_unref(gdk_dnd.c->drag_pm_default);
+ XFree (data);
+ return win;
}
- if(gdk_dnd.c->drag_pm_ok)
+
+ XTranslateCoordinates (gdk_display, gdk_root_window, win,
+ x_root, y_root, &dest_x, &dest_y, &child);
+
+ if (gdk_error_code != 0)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_unref(gdk_dnd.c->drag_pm_ok);
+ gdk_error_code = 0;
+ return None;
}
+
+ if (child)
+ return get_client_window_at_coords_recurse (child, x_root, y_root);
+ else
+ return None;
+}
+
+Window
+get_client_window_at_coords (Window ignore,
+ gint x_root,
+ gint y_root)
+{
+ Window root, parent, *children;
+ unsigned int nchildren;
+ int i;
+ Window retval = None;
+
+ gint old_warnings = gdk_error_warnings;
- gdk_dnd.c->drag_pm_ok = NULL;
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ if (XQueryTree(gdk_display, gdk_root_window,
+ &root, &parent, &children, &nchildren) == 0)
+ return 0;
- gdk_window_ref(default_pixmapwin);
- gdk_dnd.c->drag_pm_default = default_pixmapwin;
- gdk_dnd.c->default_hotspot = *default_hotspot;
- gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow));
- if(goahead_pixmapwin)
+ for (i = nchildren - 1; (i >= 0) && (retval == None); i--)
+ {
+ if (children[i] != ignore)
+ {
+ XWindowAttributes xwa;
+
+ XGetWindowAttributes (gdk_display, children[i], &xwa);
+
+ if (gdk_error_code != 0)
+ gdk_error_code = 0;
+ else if ((xwa.map_state == IsViewable) &&
+ (x_root >= xwa.x) && (x_root < xwa.x + (gint)xwa.width) &&
+ (y_root >= xwa.y) && (y_root < xwa.y + (gint)xwa.height))
+ {
+ retval = get_client_window_at_coords_recurse (children[i],
+ x_root, y_root);
+ if (!retval)
+ retval = children[i];
+ }
+ }
+ }
+
+ XFree (children);
+
+ gdk_error_warnings = old_warnings;
+ if (retval)
+ return retval;
+ else
+ return gdk_root_window;
+}
+#endif
+
+/*************************************************************
+ ***************************** MOTIF *************************
+ *************************************************************/
+
+/* values used in the message type for Motif DND */
+enum {
+ XmTOP_LEVEL_ENTER,
+ XmTOP_LEVEL_LEAVE,
+ XmDRAG_MOTION,
+ XmDROP_SITE_ENTER,
+ XmDROP_SITE_LEAVE,
+ XmDROP_START,
+ XmDROP_FINISH,
+ XmDRAG_DROP_FINISH,
+ XmOPERATION_CHANGED
+};
+
+/* Values used to specify type of protocol to use */
+enum {
+ XmDRAG_NONE,
+ XmDRAG_DROP_ONLY,
+ XmDRAG_PREFER_PREREGISTER,
+ XmDRAG_PREREGISTER,
+ XmDRAG_PREFER_DYNAMIC,
+ XmDRAG_DYNAMIC,
+ XmDRAG_PREFER_RECEIVER
+};
+
+/* Operation codes */
+enum {
+ XmDROP_NOOP,
+ XmDROP_MOVE = 0x01,
+ XmDROP_COPY = 0x02,
+ XmDROP_LINK = 0x04
+};
+
+/* Drop site status */
+enum {
+ XmNO_DROP_SITE = 0x01,
+ XmDROP_SITE_INVALID = 0x02,
+ XmDROP_SITE_VALID = 0x03
+};
+
+/* completion status */
+enum {
+ XmDROP,
+ XmDROP_HELP,
+ XmDROP_CANCEL,
+ XmDROP_INTERRUPT
+};
+
+/* Static data for MOTIF DND */
+static GList **motif_target_lists = NULL;
+static gint motif_n_target_lists = -1;
+
+/* Byte swapping routines. The motif specification leaves it
+ * up to us to save a few bytes in the client messages
+ */
+static gchar local_byte_order = '\0';
+
+#ifdef G_ENABLE_DEBUG
+static void
+print_target_list (GList *targets)
+{
+ while (targets)
+ {
+ gchar *name = gdk_atom_name (GPOINTER_TO_INT (targets->data));
+ g_message ("\t%s", name);
+ g_free (name);
+ targets = targets->next;
+ }
+}
+#endif /* G_ENABLE_DEBUG */
+
+static void
+init_byte_order (void)
+{
+ guint32 myint = 0x01020304;
+ local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
+}
+
+static guint16
+card16_to_host (guint16 x, gchar byte_order) {
+ if (byte_order == local_byte_order)
+ return x;
+ else
+ return (x << 8) | (x >> 8);
+}
+
+static guint32
+card32_to_host (guint32 x, gchar byte_order) {
+ if (byte_order == local_byte_order)
+ return x;
+ else
+ return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
+}
+
+
+/***** Dest side ***********/
+
+/* Property placed on source windows */
+typedef struct _MotifDragInitiatorInfo {
+ guint8 byte_order;
+ guint8 protocol_version;
+ guint16 targets_index;
+ guint32 selection_atom;
+} MotifDragInitiatorInfo;
+
+/* Header for target table on the drag window */
+typedef struct _MotifTargetTableHeader {
+ guchar byte_order;
+ guchar protocol_version;
+ guint16 n_lists;
+ guint32 total_size;
+} MotifTargetTableHeader;
+
+/* Property placed on target windows */
+typedef struct _MotifDragReceiverInfo {
+ guint8 byte_order;
+ guint8 protocol_version;
+ guint8 protocol_style;
+ guint8 pad;
+ guint32 proxy_window;
+ guint16 num_drop_sites;
+ guint16 padding;
+ guint32 total_size;
+} MotifDragReceiverInfo;
+
+static Window motif_drag_window = None;
+static GdkWindow *motif_drag_gdk_window = NULL;
+
+static GdkAtom motif_drag_targets_atom = GDK_NONE;
+static GdkAtom motif_drag_receiver_info_atom = GDK_NONE;
+
+/* Target table handling */
+
+GdkFilterReturn
+motif_drag_window_filter (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xev = (XEvent *)xevent;
+
+ switch (xev->xany.type)
{
- gdk_window_ref(goahead_pixmapwin);
- gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow));
- gdk_dnd.c->drag_pm_ok = goahead_pixmapwin;
- gdk_dnd.c->ok_hotspot = *goahead_hotspot;
+ case DestroyNotify:
+ motif_drag_window = None;
+ motif_drag_gdk_window = NULL;
+ break;
+ case PropertyNotify:
+ if (motif_target_lists &&
+ motif_drag_targets_atom &&
+ (xev->xproperty.atom == motif_drag_targets_atom))
+ motif_read_target_table();
+ break;
}
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkAtom motif_drag_window_atom = GDK_NONE;
+
+static Window
+motif_lookup_drag_window (Display *display)
+{
+ Window retval = None;
+ gulong bytes_after, nitems;
+ GdkAtom type;
+ gint format;
+ guchar *data;
+
+ XGetWindowProperty (gdk_display, gdk_root_window, motif_drag_window_atom,
+ 0, sizeof(Window)/4, FALSE,
+ XA_WINDOW, &type, &format, &nitems, &bytes_after,
+ &data);
- if(gdk_dnd.dnd_grabbed)
+ if ((format == 8*sizeof(Window)) && (nitems == 1) && (bytes_after == 0))
{
- gdk_dnd_display_drag_cursor(-1, -1,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- TRUE);
- XChangeActivePointerGrab (gdk_display,
- ButtonMotionMask |
- ButtonPressMask |
- ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask,
- None,
- CurrentTime);
+ retval = *(Window *)data;
+ GDK_NOTE(DND,
+ g_message ("Found drag window %#lx\n", motif_drag_window));
}
+
+ if (type != None)
+ XFree (data);
+
+ return retval;
}
-void
-gdk_dnd_display_drag_cursor(gint x, gint y, gboolean drag_ok,
- gboolean change_made)
+/* Finds the window where global Motif drag information is stored.
+ * If it doesn't exist and 'create' is TRUE, create one.
+ */
+Window
+motif_find_drag_window (gboolean create)
+{
+ if (!motif_drag_window)
+ {
+ if (!motif_drag_window_atom)
+ motif_drag_window_atom = gdk_atom_intern ("_MOTIF_DRAG_WINDOW", TRUE);
+
+ motif_drag_window = motif_lookup_drag_window (gdk_display);
+
+ if (!motif_drag_window && create)
+ {
+ /* Create a persistant window. (Copied from LessTif) */
+
+ Display *display;
+ XSetWindowAttributes attr;
+ display = XOpenDisplay (NULL);
+ XSetCloseDownMode (display, RetainPermanent);
+
+ XGrabServer (display);
+
+ motif_drag_window = motif_lookup_drag_window (display);
+
+ if (!motif_drag_window)
+ {
+ attr.override_redirect = True;
+ attr.event_mask = PropertyChangeMask;
+
+ motif_drag_window =
+ XCreateWindow(display, DefaultRootWindow(display),
+ -100, -100, 10, 10, 0, 0,
+ InputOnly, CopyFromParent,
+ (CWOverrideRedirect | CWEventMask), &attr);
+
+ GDK_NOTE (DND,
+ g_message ("Created drag window %#lx\n", motif_drag_window));
+
+ XChangeProperty (display, gdk_root_window,
+ motif_drag_window_atom, XA_WINDOW,
+ 32, PropModeReplace,
+ (guchar *)&motif_drag_window_atom, 1);
+
+ }
+ XUngrabServer (display);
+ XCloseDisplay (display);
+ }
+
+ /* There is a miniscule race condition here if the drag window
+ * gets destroyed exactly now.
+ */
+ if (motif_drag_window)
+ {
+ motif_drag_gdk_window = gdk_window_foreign_new (motif_drag_window);
+ gdk_window_add_filter (motif_drag_gdk_window,
+ motif_drag_window_filter,
+ NULL);
+ }
+ }
+
+ return motif_drag_window;
+}
+
+static void
+motif_read_target_table (void)
{
- if(!gdk_dnd.dnd_grabbed)
- return;
+ gulong bytes_after, nitems;
+ GdkAtom type;
+ gint format;
+ gint i, j;
+
+ if (!motif_drag_targets_atom)
+ motif_drag_targets_atom = gdk_atom_intern ("_MOTIF_DRAG_TARGETS", FALSE);
+
+ if (motif_target_lists)
+ {
+ for (i=0; i<motif_n_target_lists; i++)
+ g_list_free (motif_target_lists[i]);
+
+ g_free (motif_target_lists);
+ motif_target_lists = NULL;
+ motif_n_target_lists = 0;
+ }
+
+ if (motif_find_drag_window (FALSE))
+ {
+ MotifTargetTableHeader *header = NULL;
+ guchar *target_bytes = NULL;
+ guchar *p;
+ gboolean success = FALSE;
+
+ XGetWindowProperty (gdk_display, motif_drag_window,
+ motif_drag_targets_atom,
+ 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
+ motif_drag_targets_atom,
+ &type, &format, &nitems, &bytes_after,
+ (guchar **)&header);
+
+ if ((format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
+ goto error;
+
+ header->n_lists = card16_to_host (header->n_lists, header->byte_order);
+ header->total_size = card32_to_host (header->total_size, header->byte_order);
+
+ XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
+ (sizeof(MotifTargetTableHeader)+3)/4,
+ (header->total_size - sizeof(MotifTargetTableHeader) + 3)/4,
+ FALSE,
+ motif_drag_targets_atom, &type, &format, &nitems,
+ &bytes_after, &target_bytes);
+
+ if ((format != 8) || (bytes_after != 0) ||
+ (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
+ goto error;
+
+ motif_n_target_lists = header->n_lists;
+ motif_target_lists = g_new0 (GList *, motif_n_target_lists);
+
+ p = target_bytes;
+ for (i=0; i<header->n_lists; i++)
+ {
+ gint n_targets;
+ guint32 *targets;
+
+ if (p + sizeof(guint16) - target_bytes > nitems)
+ goto error;
+
+ n_targets = card16_to_host (*(gushort *)p, header->byte_order);
+ targets = (guint32 *)(p + sizeof(guint16));
+
+ p += sizeof(guint16) + n_targets * sizeof(guint32);
+ if (p - target_bytes > nitems)
+ goto error;
+
+ for (j=0; j<n_targets; j++)
+ motif_target_lists[i] =
+ g_list_prepend (motif_target_lists[i],
+ GUINT_TO_POINTER (card32_to_host (targets[j],
+ header->byte_order)));
+
+ motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
+ }
+
+ success = TRUE;
+
+ error:
+ if (header)
+ XFree (header);
+
+ if (target_bytes)
+ XFree (target_bytes);
+
+ if (!success)
+ {
+ if (motif_target_lists)
+ {
+ g_free (motif_target_lists);
+ motif_target_lists = NULL;
+ motif_n_target_lists = 0;
+ }
+ g_warning ("Error reading Motif target table\n");
+ }
+ }
+}
+
+static gint
+targets_sort_func (gconstpointer a, gconstpointer b)
+{
+ return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
+ -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
+}
+
+/* Check if given (sorted) list is in the targets table */
+static gboolean
+motif_target_table_check (GList *sorted)
+{
+ GList *tmp_list1, *tmp_list2;
+ gint i;
+
+ for (i=0; i<motif_n_target_lists; i++)
+ {
+ tmp_list1 = motif_target_lists[i];
+ tmp_list2 = sorted;
+
+ while (tmp_list1 && tmp_list2)
+ {
+ if (tmp_list1->data != tmp_list2->data)
+ break;
+
+ tmp_list1 = tmp_list1->next;
+ tmp_list2 = tmp_list2->next;
+ }
+ if (!tmp_list1 && !tmp_list2) /* Found it */
+ return i;
+ }
+
+ return -1;
+}
+
+static gint
+motif_add_to_target_table (GList *targets)
+{
+ GList *sorted = NULL;
+ gint index = -1;
+ gint i;
+ GList *tmp_list;
+
+ /* make a sorted copy of the list */
- if(gdk_dnd.c->drag_pm_default)
+ while (targets)
+ {
+ sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
+ targets = targets->next;
+ }
+
+ /* First check if it is their already */
+
+ if (motif_target_lists)
+ index = motif_target_table_check (sorted);
+
+ /* We need to grab the server while doing this, to ensure
+ * atomiticity. Ugh
+ */
+
+ if (index < 0)
{
- /* We're doing pixmaps here... */
- GdkWindow *mypix, *opix;
- GdkPoint *myhotspot;
- gint itmp;
- guint masktmp;
- Window wtmp;
+ /* We need to make sure that it exists _before_ we grab the
+ * server, since we can't open a new connection after we
+ * grab the server.
+ */
+ motif_find_drag_window (TRUE);
+
+ XGrabServer(gdk_display);
+ motif_read_target_table();
+
+ /* Check again, in case it was added in the meantime */
- if(x == -2 && y == -2) /* Hide the cursors */
+ if (motif_target_lists)
+ index = motif_target_table_check (sorted);
+
+ if (index < 0)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- GDK_NOTE(DND, g_message("Hiding both drag cursors\n"));
- return;
+ guint32 total_size = 0;
+ guchar *data;
+ guchar *p;
+ guint16 *p16;
+ guint32 *p32;
+ MotifTargetTableHeader *header;
+
+ if (!motif_target_lists)
+ {
+ motif_target_lists = g_new (GList *, 1);
+ motif_n_target_lists = 1;
+ }
+ else
+ {
+ motif_n_target_lists++;
+ motif_target_lists = g_realloc (motif_target_lists,
+ sizeof(GList *) * motif_n_target_lists);
+ }
+ motif_target_lists[motif_n_target_lists - 1] = sorted;
+ sorted = NULL;
+ index = motif_n_target_lists - 1;
+
+ total_size = sizeof (MotifTargetTableHeader);
+ for (i = 0; i < motif_n_target_lists ; i++)
+ total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
+
+ data = g_malloc (total_size);
+
+ header = (MotifTargetTableHeader *)data;
+ p = data + sizeof(MotifTargetTableHeader);
+
+ header->byte_order = local_byte_order;
+ header->protocol_version = 0;
+ header->n_lists = motif_n_target_lists;
+ header->total_size = total_size;
+
+ for (i = 0; i < motif_n_target_lists ; i++)
+ {
+ guint16 count = 0;
+
+ p16 = (guint16 *)p;
+ p += sizeof(guint16);
+ p32 = (guint32 *)p;
+ tmp_list = motif_target_lists[i];
+ while (tmp_list)
+ {
+ *p32++ = GPOINTER_TO_UINT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ count++;
+ }
+ *p16 = count;
+ p = (guchar *)p32;
+ }
+
+ XChangeProperty (gdk_display, motif_drag_window,
+ motif_drag_targets_atom,
+ motif_drag_targets_atom,
+ 8, PropModeReplace,
+ data, total_size);
}
+ XUngrabServer(gdk_display);
+ }
+
+ g_list_free (sorted);
+ return index;
+}
+
+/* Translate flags */
+
+static void
+motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
+{
+ guint recommended_op = flags & 0x000f;
+ guint possible_ops = (flags & 0x0f0) >> 4;
+
+ switch (recommended_op)
+ {
+ case XmDROP_MOVE:
+ context->suggested_action = GDK_ACTION_MOVE;
+ break;
+ case XmDROP_COPY:
+ context->suggested_action = GDK_ACTION_COPY;
+ break;
+ case XmDROP_LINK:
+ context->suggested_action = GDK_ACTION_LINK;
+ break;
+ default:
+ context->suggested_action = GDK_ACTION_COPY;
+ break;
+ }
+
+ context->actions = 0;
+ if (possible_ops & XmDROP_MOVE)
+ context->actions |= GDK_ACTION_MOVE;
+ if (possible_ops & XmDROP_COPY)
+ context->actions |= GDK_ACTION_COPY;
+ if (possible_ops & XmDROP_LINK)
+ context->actions |= GDK_ACTION_LINK;
+}
+
+static guint16
+motif_dnd_get_flags (GdkDragContext *context)
+{
+ guint16 flags = 0;
+
+ switch (context->suggested_action)
+ {
+ case GDK_ACTION_MOVE:
+ flags = XmDROP_MOVE;
+ break;
+ case GDK_ACTION_COPY:
+ flags = XmDROP_COPY;
+ break;
+ case GDK_ACTION_LINK:
+ flags = XmDROP_LINK;
+ break;
+ default:
+ flags = XmDROP_NOOP;
+ break;
+ }
+
+ if (context->actions & GDK_ACTION_MOVE)
+ flags |= XmDROP_MOVE << 8;
+ if (context->actions & GDK_ACTION_COPY)
+ flags |= XmDROP_COPY << 8;
+ if (context->actions & GDK_ACTION_LINK)
+ flags |= XmDROP_LINK << 8;
+
+ return flags;
+}
+
+/* Source Side */
+
+static void
+motif_set_targets (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ MotifDragInitiatorInfo info;
+ gint i;
+ static GdkAtom motif_drag_initiator_info = GDK_NONE;
+
+ if (!motif_drag_initiator_info)
+ motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
+
+ info.byte_order = local_byte_order;
+ info.protocol_version = 0;
+
+ info.targets_index = motif_add_to_target_table (context->targets);
+
+ for (i=0; ; i++)
+ {
+ gchar buf[20];
+ g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
- if(x == -1 && y == -1) /* We're supposed to find it out for ourselves */
- XQueryPointer(gdk_display, gdk_root_window,
- &wtmp, &wtmp, &x, &y, &itmp, &itmp, &masktmp);
+ private->motif_selection = gdk_atom_intern (buf, FALSE);
+ if (!XGetSelectionOwner (gdk_display, private->motif_selection))
+ break;
+ }
+
+ info.selection_atom = private->motif_selection;
+
+ XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
+ GDK_WINDOW_XWINDOW (context->source_window),
+ private->motif_selection,
+ motif_drag_initiator_info, 8, PropModeReplace,
+ (guchar *)&info, sizeof (info));
+
+ private->motif_targets_set = 1;
+}
+
+gboolean
+motif_check_dest (Window win)
+{
+ gboolean retval = FALSE;
+ MotifDragReceiverInfo *info;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+
+ if (!motif_drag_receiver_info_atom)
+ motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ motif_drag_receiver_info_atom,
+ 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ (guchar **)&info);
+
+ if (type != None)
+ {
+ if ((format == 8) && (nitems == sizeof(*info)))
+ {
+ if ((info->protocol_version == 0) &&
+ ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
+ (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
+ (info->protocol_style == XmDRAG_DYNAMIC)))
+ retval = TRUE;
+ }
+ else
+ {
+ GDK_NOTE (DND,
+ g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
+ }
+
+ XFree (info);
+ }
+
+ return retval;
+
+}
+
+static void
+motif_send_enter (GdkDragContext *context,
+ guint32 time)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmTOP_LEVEL_ENTER;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = 0;
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (!private->motif_targets_set)
+ motif_set_targets (context);
+
+ xev.xclient.data.l[3] = private->motif_selection;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+static void
+motif_send_leave (GdkDragContext *context,
+ guint32 time)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmTOP_LEVEL_LEAVE;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = 0;
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[3] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+static gboolean
+motif_send_motion (GdkDragContext *context,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ gboolean retval;
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = motif_dnd_get_flags (context);
+ xev.xclient.data.l[1] = time;
+
+ if (context->suggested_action != private->old_action)
+ {
+ xev.xclient.data.b[0] = XmOPERATION_CHANGED;
+
+ private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
+ retval = TRUE;
+ }
+ else
+ {
+ xev.xclient.data.b[0] = XmDRAG_MOTION;
+
+ xev.xclient.data.s[4] = x_root;
+ xev.xclient.data.s[5] = y_root;
- if(drag_ok)
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+ retval = FALSE;
+ }
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+
+ return retval;
+}
+
+static void
+motif_send_drop (GdkDragContext *context, guint32 time)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmDROP_START;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = motif_dnd_get_flags (context);
+ xev.xclient.data.l[1] = time;
+
+ xev.xclient.data.s[4] = private->last_x;
+ xev.xclient.data.s[5] = private->last_y;
+
+ xev.xclient.data.l[3] = private->motif_selection;
+ xev.xclient.data.l[4] = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+/* Target Side */
+
+static gboolean
+motif_read_initiator_info (Window source_window,
+ Atom atom,
+ GList **targets,
+ GdkAtom *selection)
+{
+ GList *tmp_list;
+ static GdkAtom motif_drag_initiator_info = GDK_NONE;
+ GdkAtom type;
+ gint format;
+ gulong nitems;
+ gulong bytes_after;
+
+ MotifDragInitiatorInfo *initiator_info;
+
+ if (!motif_drag_initiator_info)
+ motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
+
+ XGetWindowProperty (gdk_display, source_window, atom,
+ 0, sizeof(*initiator_info), FALSE,
+ motif_drag_initiator_info,
+ &type, &format, &nitems, &bytes_after,
+ (guchar **)&initiator_info);
+
+ if ((format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
+ {
+ g_warning ("Error reading initiator info\n");
+ return FALSE;
+ }
+
+ motif_read_target_table ();
+
+ if (initiator_info->targets_index >= motif_n_target_lists)
+ {
+ g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
+ XFree (initiator_info);
+ return GDK_FILTER_REMOVE;
+ }
+
+ tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
+
+ *targets = NULL;
+ while (tmp_list)
+ {
+ *targets = g_list_prepend (*targets,
+ tmp_list->data);
+ tmp_list = tmp_list->prev;
+ }
+
+#ifdef G_ENABLE_DEBUG
+ if (gdk_debug_flags & GDK_DEBUG_DND)
+ print_target_list (*targets);
+#endif /* G_ENABLE_DEBUG */
+
+ *selection = initiator_info->selection_atom;
+
+ XFree (initiator_info);
+
+ return TRUE;
+}
+
+static GdkDragContext *
+motif_drag_context_new (GdkWindow *dest_window,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom)
+{
+ GdkDragContext *new_context;
+ GdkDragContextPrivate *private;
+
+ /* FIXME, current_dest_drag really shouldn't be NULL'd
+ * if we error below.
+ */
+ if (current_dest_drag != NULL)
+ {
+ if (timestamp >= current_dest_drag->start_time)
{
- GDK_NOTE(DND, g_message("Switching to drag_ok cursor\n"));
- mypix = gdk_dnd.c->drag_pm_ok;
- opix = gdk_dnd.c->drag_pm_default;
- myhotspot = &gdk_dnd.c->ok_hotspot;
+ gdk_drag_context_unref (current_dest_drag);
+ current_dest_drag = NULL;
}
else
+ return NULL;
+ }
+
+ new_context = gdk_drag_context_new ();
+ private = (GdkDragContextPrivate *)new_context;
+
+ new_context->protocol = GDK_DRAG_PROTO_MOTIF;
+ new_context->is_source = FALSE;
+
+ new_context->source_window = gdk_window_lookup (source_window);
+ if (new_context->source_window)
+ gdk_window_ref (new_context->source_window);
+ else
+ {
+ new_context->source_window = gdk_window_foreign_new (source_window);
+ if (!new_context->source_window)
{
- GDK_NOTE(DND, g_message("Switching to drag_default cursor\n"));
- mypix = gdk_dnd.c->drag_pm_default;
- opix = gdk_dnd.c->drag_pm_ok;
- myhotspot = &gdk_dnd.c->default_hotspot;
+ gdk_drag_context_unref (new_context);
+ return NULL;
}
- gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
- if(change_made)
+ }
+
+ new_context->dest_window = dest_window;
+ gdk_window_ref (dest_window);
+ new_context->start_time = timestamp;
+
+ if (!motif_read_initiator_info(source_window,
+ atom,
+ &new_context->targets,
+ &private->motif_selection))
+ {
+ gdk_drag_context_unref (new_context);
+ return NULL;
+ }
+
+ return new_context;
+}
+
+/*
+ * The MOTIF drag protocol has no real provisions for distinguishing
+ * multiple simultaneous drops. If the sources grab the pointer
+ * when doing drags, that shouldn't happen, in any case. If it
+ * does, we can't do much except hope for the best.
+ */
+
+static GdkFilterReturn
+motif_top_level_enter (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom)
+{
+ GdkDragContext *new_context;
+
+ GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
+ flags, timestamp, source_window, atom));
+
+ new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
+ if (!new_context)
+ return GDK_FILTER_REMOVE;
+
+ event->dnd.type = GDK_DRAG_ENTER;
+ event->dnd.context = new_context;
+ gdk_drag_context_ref (new_context);
+
+ current_dest_drag = new_context;
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+GdkFilterReturn
+motif_top_level_leave (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
+ flags, timestamp));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ event->dnd.type = GDK_DRAG_LEAVE;
+ /* Pass ownership of context to the event */
+ event->dnd.context = current_dest_drag;
+
+ current_dest_drag = NULL;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_motion (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ gint16 x_root,
+ gint16 y_root)
+{
+ GdkDragContextPrivate *private;
+
+ GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
+ flags, timestamp, x_root, y_root));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = timestamp;
+
+ motif_dnd_translate_flags (current_dest_drag, flags);
+
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ private->last_x = x_root;
+ private->last_y = y_root;
+
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_operation_changed (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GdkDragContextPrivate *private;
+
+ GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
+ flags, timestamp));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.send_event = FALSE;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = timestamp;
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ motif_dnd_translate_flags (current_dest_drag, flags);
+
+ event->dnd.x_root = private->last_x;
+ event->dnd.y_root = private->last_y;
+
+ private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_drop_start (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom,
+ gint16 x_root,
+ gint16 y_root)
+{
+ GdkDragContext *new_context;
+
+
+ GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
+ flags, timestamp, x_root, y_root, source_window, atom));
+
+ new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
+ if (!new_context)
+ return GDK_FILTER_REMOVE;
+
+ motif_dnd_translate_flags (new_context, flags);
+
+ event->dnd.type = GDK_DROP_START;
+ event->dnd.context = new_context;
+ event->dnd.time = timestamp;
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ gdk_drag_context_ref (new_context);
+ current_dest_drag = new_context;
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+GdkFilterReturn
+motif_drag_status (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("Motif status message: flags %x", flags));
+
+ context = gdk_drag_context_find (TRUE,
+ GDK_WINDOW_XWINDOW (event->any.window),
+ None);
+
+ if (context)
+ {
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ event->dnd.type = GDK_DRAG_STATUS;
+ event->dnd.send_event = FALSE;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ event->dnd.time = timestamp;
+
+ if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
+ {
+ switch (flags & 0x000f)
+ {
+ case XmDROP_NOOP:
+ context->action = 0;
+ break;
+ case XmDROP_MOVE:
+ context->action = GDK_ACTION_MOVE;
+ break;
+ case XmDROP_COPY:
+ context->action = GDK_ACTION_COPY;
+ break;
+ case XmDROP_LINK:
+ context->action = GDK_ACTION_LINK;
+ break;
+ }
+ }
+ else
+ context->action = 0;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_dnd_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ XClientMessageEvent *xce = &xevent->xclient;
+
+ guint8 reason;
+ gchar byte_order;
+ guint16 flags;
+ guint32 timestamp;
+ guint32 source_window;
+ GdkAtom atom;
+ gint16 x_root, y_root;
+ gboolean is_reply;
+
+ /* First read some fields common to all Motif DND messages */
+
+ reason = xce->data.b[0];
+ byte_order = xce->data.b[1];
+ flags = card16_to_host (xce->data.s[1], byte_order);
+ timestamp = card32_to_host (xce->data.l[1], byte_order);
+
+ is_reply = ((reason & 0x80) != 0);
+
+ switch (reason & 0x7f)
+ {
+ case XmTOP_LEVEL_ENTER:
+ source_window = card32_to_host (xce->data.l[2], byte_order);
+ atom = card32_to_host (xce->data.l[3], byte_order);
+ return motif_top_level_enter (event, flags, timestamp, source_window, atom);
+ case XmTOP_LEVEL_LEAVE:
+ return motif_top_level_leave (event, flags, timestamp);
+
+ case XmDRAG_MOTION:
+ x_root = card16_to_host (xce->data.s[4], byte_order);
+ y_root = card16_to_host (xce->data.s[5], byte_order);
+
+ if (!is_reply)
+ return motif_motion (event, flags, timestamp, x_root, y_root);
+ else
+ return motif_drag_status (event, flags, timestamp);
+
+ case XmDROP_SITE_ENTER:
+ return motif_drag_status (event, flags, timestamp);
+
+ case XmDROP_SITE_LEAVE:
+ return motif_drag_status (event,
+ XmNO_DROP_SITE << 8 | XmDROP_NOOP,
+ timestamp);
+ case XmDROP_START:
+ x_root = card16_to_host (xce->data.s[4], byte_order);
+ y_root = card16_to_host (xce->data.s[5], byte_order);
+ atom = card32_to_host (xce->data.l[3], byte_order);
+ source_window = card32_to_host (xce->data.l[4], byte_order);
+
+ if (!is_reply)
+ return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
+
+ break;
+ case XmOPERATION_CHANGED:
+ if (!is_reply)
+ return motif_operation_changed (event, flags, timestamp);
+ else
+ return motif_drag_status (event, flags, timestamp);
+
+ break;
+ /* To the best of my knowledge, these next two messages are
+ * not part of the protocol, though they are defined in
+ * the header files.
+ */
+ case XmDROP_FINISH:
+ case XmDRAG_DROP_FINISH:
+ break;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+/*************************************************************
+ ***************************** XDND **************************
+ *************************************************************/
+
+/* Utility functions */
+
+static struct {
+ gchar *name;
+ GdkAtom atom;
+ GdkDragAction action;
+} xdnd_actions_table[] = {
+ { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
+ { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
+ { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
+ { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
+ { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
+ };
+
+static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
+static gboolean xdnd_actions_initialized = FALSE;
+
+static void
+xdnd_initialize_actions (void)
+{
+ gint i;
+
+ xdnd_actions_initialized = TRUE;
+ for (i=0; i < xdnd_n_actions; i++)
+ xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
+}
+
+static GdkDragAction
+xdnd_action_from_atom (GdkAtom atom)
+{
+ gint i;
+
+ if (!xdnd_actions_initialized)
+ xdnd_initialize_actions();
+
+ for (i=0; i<xdnd_n_actions; i++)
+ if (atom == xdnd_actions_table[i].atom)
+ return xdnd_actions_table[i].action;
+
+ return 0;
+}
+
+static GdkAtom
+xdnd_action_to_atom (GdkDragAction action)
+{
+ gint i;
+
+ if (!xdnd_actions_initialized)
+ xdnd_initialize_actions();
+
+ for (i=0; i<xdnd_n_actions; i++)
+ if (action == xdnd_actions_table[i].action)
+ return xdnd_actions_table[i].atom;
+
+ return GDK_NONE;
+}
+
+static GdkAtom xdnd_aware_atom = GDK_NONE;
+
+/* Source side */
+
+static GdkFilterReturn
+xdnd_status_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 dest_window = xevent->xclient.data.l[0];
+ guint32 flags = xevent->xclient.data.l[1];
+ GdkAtom action = xevent->xclient.data.l[4];
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("XdndStatus: dest_window: %#x action: %ld",
+ dest_window, action));
+
+
+ context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
+ if (context)
+ {
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ event->dnd.send_event = FALSE;
+ event->dnd.type = GDK_DRAG_STATUS;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
+ if (!(action != 0) != !(flags & 1))
+ {
+ GDK_NOTE (DND,
+ g_warning ("Received status event with flags not corresponding to action!\n"));
+ action = 0;
+ }
+
+ context->action = xdnd_action_from_atom (action);
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_finished_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 dest_window = xevent->xclient.data.l[0];
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("XdndFinished: dest_window: %#x", dest_window));
+
+ context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
+ if (context)
+ {
+ event->dnd.type = GDK_DROP_FINISHED;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static void
+xdnd_set_targets (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ GdkAtom *typelist;
+ GList *tmp_list = context->targets;
+ gint i;
+ gint n_targets = g_list_length (context->targets);
+
+ typelist = g_new (GdkAtom, n_targets);
+ i = 0;
+ while (tmp_list)
+ {
+ typelist[i] = GPOINTER_TO_INT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ i++;
+ }
+
+ XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
+ GDK_WINDOW_XWINDOW (context->source_window),
+ gdk_atom_intern ("XdndTypeList", FALSE),
+ XA_ATOM, 32, PropModeReplace,
+ (guchar *)typelist, n_targets);
+
+ private->xdnd_targets_set = 1;
+}
+
+static void
+xdnd_send_enter (GdkDragContext *context)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndEnter", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = (3 << 24); /* version */
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!private->xdnd_selection)
+ private->xdnd_selection = gdk_atom_intern ("XdndSelection", FALSE);
+
+ if (g_list_length (context->targets) > 3)
+ {
+ if (!private->xdnd_targets_set)
+ xdnd_set_targets (context);
+ xev.xclient.data.l[1] |= 1;
+ }
+ else
+ {
+ GList *tmp_list = context->targets;
+ gint i = 2;
+
+ while (tmp_list)
+ {
+ xev.xclient.data.l[i] = GPOINTER_TO_INT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ i++;
+ }
+ }
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_leave (GdkDragContext *context)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndLeave", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_drop (GdkDragContext *context, guint32 time)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndDrop", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = time;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_motion (GdkDragContext *context,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndPosition", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = (x_root << 16) | y_root;
+ xev.xclient.data.l[3] = time;
+ xev.xclient.data.l[4] = xdnd_action_to_atom (action);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+}
+
+static gboolean
+xdnd_check_dest (Window win)
+{
+ gboolean retval = FALSE;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ GdkAtom *version;
+
+ if (!xdnd_aware_atom)
+ xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ xdnd_aware_atom, 0,
+ 1, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ (guchar **)&version);
+
+ if (type != None)
+ {
+ if ((format == 32) && (nitems == 1))
+ {
+ if (*version == 3)
+ retval = TRUE;
+ }
+ else
+ GDK_NOTE (DND,
+ g_warning ("Invalid XdndAware property on window %ld\n", win));
+
+ XFree (version);
+ }
+
+ return retval;
+}
+
+/* Target side */
+
+static GdkFilterReturn
+xdnd_enter_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ GdkDragContext *new_context;
+ gint i;
+
+ guint32 source_window = xevent->xclient.data.l[0];
+ gboolean get_types = ((xevent->xclient.data.l[1] & 1) != 0);
+ gint version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
+
+ GDK_NOTE (DND,
+ g_message ("XdndEnter: source_window: %#x, version: %#x",
+ source_window, version));
+
+ if (version != 3)
+ {
+ /* Old source ignore */
+ GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
+ return GDK_FILTER_REMOVE;
+ }
+
+ if (current_dest_drag != NULL)
+ {
+ gdk_drag_context_unref (current_dest_drag);
+ current_dest_drag = NULL;
+ }
+
+ new_context = gdk_drag_context_new ();
+ new_context->protocol = GDK_DRAG_PROTO_XDND;
+ new_context->is_source = FALSE;
+
+ new_context->source_window = gdk_window_lookup (source_window);
+ if (new_context->source_window)
+ gdk_window_ref (new_context->source_window);
+ else
+ {
+ new_context->source_window = gdk_window_foreign_new (source_window);
+ if (!new_context->source_window)
+ {
+ gdk_drag_context_unref (new_context);
+ return GDK_FILTER_REMOVE;
+ }
+ }
+ new_context->dest_window = event->any.window;
+ gdk_window_ref (new_context->dest_window);
+
+ new_context->targets = NULL;
+ if (get_types)
+ {
+ Atom type;
+ int format;
+ gulong nitems, after;
+ Atom *data;
+
+ XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
+ source_window,
+ gdk_atom_intern ("XdndTypeList", FALSE), 0, 65536,
+ False, XA_ATOM, &type, &format, &nitems,
+ &after, (guchar **)&data);
+
+ if ((format != 32) || (type != XA_ATOM))
+ {
+ gdk_drag_context_unref (new_context);
+ return GDK_FILTER_REMOVE;
+ }
+
+ for (i=0; i<nitems; i++)
+ new_context->targets = g_list_append (new_context->targets,
+ GUINT_TO_POINTER (data[i]));
+
+ XFree(data);
+ }
+ else
+ {
+ for (i=0; i<3; i++)
+ if (xevent->xclient.data.l[2+i])
+ new_context->targets = g_list_append (new_context->targets,
+ GUINT_TO_POINTER (xevent->xclient.data.l[2+i]));
+ }
+
+#ifdef G_ENABLE_DEBUG
+ if (gdk_debug_flags & GDK_DEBUG_DND)
+ print_target_list (new_context->targets);
+#endif /* G_ENABLE_DEBUG */
+
+ event->dnd.type = GDK_DRAG_ENTER;
+ event->dnd.context = new_context;
+ gdk_drag_context_ref (new_context);
+
+ current_dest_drag = new_context;
+ ((GdkDragContextPrivate *)new_context)->xdnd_selection =
+ gdk_atom_intern ("XdndSelection", FALSE);
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+static GdkFilterReturn
+xdnd_leave_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+
+ GDK_NOTE (DND,
+ g_message ("XdndLeave: source_window: %#x",
+ source_window));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ event->dnd.type = GDK_DRAG_LEAVE;
+ /* Pass ownership of context to the event */
+ event->dnd.context = current_dest_drag;
+
+ current_dest_drag = NULL;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_position_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+ gint16 x_root = xevent->xclient.data.l[2] >> 16;
+ gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
+ guint32 time = xevent->xclient.data.l[3];
+ GdkAtom action = xevent->xclient.data.l[4];
+
+ GDK_NOTE (DND,
+ g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
+ source_window, x_root, y_root, time, action));
+
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = time;
+
+ current_dest_drag->suggested_action = xdnd_action_from_atom (action);
+
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ ((GdkDragContextPrivate *)current_dest_drag)->last_x = x_root;
+ ((GdkDragContextPrivate *)current_dest_drag)->last_y = y_root;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_drop_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+ guint32 time = xevent->xclient.data.l[2];
+
+ GDK_NOTE (DND,
+ g_message ("XdndDrop: source_window: %#x time: %d",
+ source_window, time));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ GdkDragContextPrivate *private;
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ event->dnd.type = GDK_DROP_START;
+
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = time;
+ event->dnd.x_root = private->last_x;
+ event->dnd.y_root = private->last_y;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+/*************************************************************
+ ************************** Public API ***********************
+ *************************************************************/
+
+void
+gdk_dnd_init (void)
+{
+ init_byte_order();
+
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
+ motif_dnd_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndEnter", FALSE),
+ xdnd_enter_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndLeave", FALSE),
+ xdnd_leave_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndPosition", FALSE),
+ xdnd_position_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndStatus", FALSE),
+ xdnd_status_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndFinished", FALSE),
+ xdnd_finished_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndDrop", FALSE),
+ xdnd_drop_filter, NULL);
+}
+
+/* Source side */
+
+static void
+gdk_drag_do_leave (GdkDragContext *context, guint32 time)
+{
+ if (context->dest_window)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_leave (context, time);
+ break;
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_leave (context);
+ break;
+ case GDK_DRAG_PROTO_ROOTWIN:
+ break;
+ }
+
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+GdkDragContext *
+gdk_drag_begin (GdkWindow *window,
+ GList *targets,
+ GdkDragAction actions)
+{
+ GList *tmp_list;
+ GdkDragContext *new_context;
+
+ g_return_val_if_fail (window != NULL, NULL);
+
+ new_context = gdk_drag_context_new ();
+ new_context->is_source = TRUE;
+ new_context->source_window = window;
+ gdk_window_ref (window);
+
+ tmp_list = g_list_last (targets);
+ new_context->targets = NULL;
+ while (tmp_list)
+ {
+ new_context->targets = g_list_prepend (new_context->targets,
+ tmp_list->data);
+ tmp_list = tmp_list->prev;
+ }
+
+ new_context->actions = actions;
+
+ return new_context;
+}
+
+gboolean
+gdk_drag_get_protocol (guint32 xid,
+ GdkDragProtocol *protocol)
+{
+ if (xdnd_check_dest (xid))
+ {
+ *protocol = GDK_DRAG_PROTO_XDND;
+ GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
+ return TRUE;
+ }
+ else if (motif_check_dest (xid))
+ {
+ *protocol = GDK_DRAG_PROTO_MOTIF;
+ GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
+ return TRUE;
+ }
+ else
+ {
+ /* Check if this is a root window */
+
+ gboolean rootwin = FALSE;
+ gint old_warnings = gdk_error_warnings;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+
+ if (xid == gdk_root_window)
+ rootwin = TRUE;
+
+ if (!rootwin)
+ {
+ gdk_error_code = 0;
+
+ XGetWindowProperty (gdk_display, xid,
+ gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE),
+ 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+ if ((gdk_error_code == 0) && type != None)
+ {
+ XFree (data);
+ rootwin = TRUE;
+ }
+ }
+
+ /* Until I find out what window manager the next one is for,
+ * I'm leaving it commented out. It's supported in the
+ * xscreensaver sources, though.
+ */
+#if 0
+ if (!rootwin)
{
- GDK_NOTE(DND, g_message("Cursors switched, hide & show\n"));
- gdk_window_hide(opix);
+ gdk_error_code = 0;
+
+ XGetWindowProperty (gdk_display, win,
+ gdk_atom_intern ("__SWM_VROOT", FALSE),
+ 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &data);
+ if ((gdk_error_code == 0) && type != None)
+ rootwin = TRUE;
+ }
+#endif
+
+ gdk_error_warnings = old_warnings;
+
+ if (rootwin)
+ {
+ *protocol = GDK_DRAG_PROTO_ROOTWIN;
+ return TRUE;
}
- gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
- if (change_made)
- {
- gdk_window_show(mypix); /* There ought to be a way to know if
- a window is already mapped etc. */
- }
}
- else if(change_made)
+
+ return FALSE;
+}
+
+void
+gdk_drag_find_window (GdkDragContext *context,
+ GdkWindow *drag_window,
+ gint x_root,
+ gint y_root,
+ GdkWindow **dest_window,
+ GdkDragProtocol *protocol)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ Window dest;
+
+ if (!private->window_cache)
+ private->window_cache = gdk_window_cache_new();
+
+ dest = get_client_window_at_coords (private->window_cache,
+ drag_window ?
+ GDK_WINDOW_XWINDOW (drag_window) : GDK_NONE,
+ x_root, y_root);
+
+ if (private->dest_xid != dest)
{
- Cursor c;
- /* Move cursors around */
- if(drag_ok)
- c = gdk_dnd.c->gdk_cursor_dragok;
+ private->dest_xid = dest;
+
+ /* Check if new destination accepts drags, and which protocol */
+
+ if (gdk_drag_get_protocol (dest, protocol))
+ {
+ *dest_window = gdk_window_lookup (dest);
+ if (*dest_window)
+ gdk_window_ref (*dest_window);
+ else
+ *dest_window = gdk_window_foreign_new (dest);
+ }
else
- c = gdk_dnd.c->gdk_cursor_dragdefault;
- XChangeActivePointerGrab (gdk_display,
- ButtonMotionMask |
- ButtonPressMask |
- ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask,
- c,
- CurrentTime);
+ *dest_window = NULL;
+ }
+ else
+ {
+ *dest_window = context->dest_window;
+ if (*dest_window)
+ gdk_window_ref (*dest_window);
+ *protocol = context->protocol;
}
}
+
+gboolean
+gdk_drag_motion (GdkDragContext *context,
+ GdkWindow *dest_window,
+ GdkDragProtocol protocol,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ if (context->dest_window != dest_window)
+ {
+ GdkEvent temp_event;
+
+ /* Send a leave to the last destination */
+ gdk_drag_do_leave (context, time);
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ /* Check if new destination accepts drags, and which protocol */
+
+ if (dest_window)
+ {
+ context->dest_window = dest_window;
+ gdk_window_ref (context->dest_window);
+ context->protocol = protocol;
+
+ switch (protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_enter (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_enter (context);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ break;
+ }
+ private->old_action = action;
+ context->suggested_action = action;
+ }
+ else
+ {
+ context->dest_window = NULL;
+ context->action = 0;
+ }
+
+ /* Push a status event, to let the client know that
+ * the drag changed
+ */
+
+ temp_event.dnd.type = GDK_DRAG_STATUS;
+ temp_event.dnd.window = context->source_window;
+ /* We use this to signal a synthetic status. Perhaps
+ * we should use an extra field...
+ */
+ temp_event.dnd.send_event = TRUE;
+
+ temp_event.dnd.context = context;
+ temp_event.dnd.time = time;
+
+ gdk_event_put (&temp_event);
+ }
+ else
+ {
+ private->old_action = context->suggested_action;
+ context->suggested_action = action;
+ }
+
+ /* Send a drag-motion event */
+
+ private->last_x = x_root;
+ private->last_y = y_root;
+
+ if (context->dest_window)
+ {
+ if (private->drag_status == GDK_DRAG_STATUS_DRAG)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_motion (context, x_root, y_root, action, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_motion (context, x_root, y_root, action, time);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ {
+ GdkEvent temp_event;
+
+ if (g_list_find (context->targets,
+ GUINT_TO_POINTER (gdk_atom_intern ("application/x-rootwin-drop", FALSE))))
+ context->action = context->suggested_action;
+ else
+ context->action = 0;
+
+ temp_event.dnd.type = GDK_DRAG_STATUS;
+ temp_event.dnd.window = context->source_window;
+ temp_event.dnd.send_event = FALSE;
+ temp_event.dnd.context = context;
+ temp_event.dnd.time = time;
+
+ gdk_event_put (&temp_event);
+ }
+ break;
+ }
+ }
+ else
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void
+gdk_drag_drop (GdkDragContext *context,
+ guint32 time)
+{
+ if (context->dest_window)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_leave (context, time);
+ motif_send_drop (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_drop (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
+ break;
+ }
+ }
+}
+
+void
+gdk_drag_abort (GdkDragContext *context,
+ guint32 time)
+{
+ gdk_drag_do_leave (context, time);
+}
+
+/* Destination side */
+
+void
+gdk_drag_status (GdkDragContext *context,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private;
+ XEvent xev;
+
+ g_return_if_fail (context != 0);
+
+ private = (GdkDragContextPrivate *)context;
+
+ context->action = action;
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
+ {
+ xev.xclient.data.b[0] = XmOPERATION_CHANGED | 0x80;
+ }
+ else
+ {
+ if ((action != 0) != (private->old_action != 0))
+ {
+ if (action != 0)
+ xev.xclient.data.b[0] = XmDROP_SITE_ENTER | 0x80;
+ else
+ xev.xclient.data.b[0] = XmDROP_SITE_LEAVE | 0x80;
+ }
+ else
+ xev.xclient.data.b[0] = XmDRAG_MOTION | 0x80;
+ }
+
+ xev.xclient.data.b[1] = local_byte_order;
+
+ switch (action)
+ {
+ case GDK_ACTION_MOVE:
+ xev.xclient.data.s[1] = XmDROP_MOVE;
+ break;
+ case GDK_ACTION_COPY:
+ xev.xclient.data.s[1] = XmDROP_COPY;
+ break;
+ case GDK_ACTION_LINK:
+ xev.xclient.data.s[1] = XmDROP_LINK;
+ break;
+ default:
+ xev.xclient.data.s[1] = XmDROP_NOOP;
+ break;
+ }
+
+ if (action)
+ xev.xclient.data.s[1] |= (XmDROP_SITE_VALID << 4);
+ else
+ xev.xclient.data.s[1] |= (XmNO_DROP_SITE << 4);
+
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.s[4] = private->last_x;
+ xev.xclient.data.s[5] = private->last_y;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+ else if (context->protocol == GDK_DRAG_PROTO_XDND)
+ {
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndStatus", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = xdnd_action_to_atom (action);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+
+ private->old_action = action;
+}
+
+void
+gdk_drop_reply (GdkDragContext *context,
+ gboolean ok,
+ guint32 time)
+{
+ GdkDragContextPrivate *private;
+
+ g_return_if_fail (context != 0);
+
+ private = (GdkDragContextPrivate *)context;
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+
+ xev.xclient.data.b[0] = XmDROP_START | 0x80;
+ xev.xclient.data.b[1] = local_byte_order;
+ if (ok)
+ xev.xclient.data.s[2] = XmDROP_COPY |
+ (XmDROP_SITE_VALID << 4) |
+ (XmDROP_NOOP << 8) |
+ (XmDROP << 12);
+ else
+ xev.xclient.data.s[2] = XmDROP_NOOP |
+ (XmNO_DROP_SITE << 4) |
+ (XmDROP_NOOP << 8) |
+ (XmDROP_CANCEL << 12);
+ xev.xclient.data.s[2] = private->last_x;
+ xev.xclient.data.s[3] = private->last_y;
+
+ gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev);
+ }
+}
+
+void
+gdk_drop_finish (GdkDragContext *context,
+ gboolean success,
+ guint32 time)
+{
+ if (context->protocol == GDK_DRAG_PROTO_XDND)
+ {
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndFinished", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+}
+
+
+void
+gdk_window_register_dnd (GdkWindow *window)
+{
+ static guint32 xdnd_version = 3;
+
+ MotifDragReceiverInfo info;
+
+ /* Set Motif drag receiver information property */
+
+ if (!motif_drag_receiver_info_atom)
+ motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
+
+ info.byte_order = local_byte_order;
+ info.protocol_version = 0;
+ info.protocol_style = XmDRAG_DYNAMIC;
+ info.proxy_window = GDK_NONE;
+ info.num_drop_sites = 0;
+ info.total_size = sizeof(info);
+
+ XChangeProperty (gdk_display, GDK_WINDOW_XWINDOW (window),
+ motif_drag_receiver_info_atom,
+ motif_drag_receiver_info_atom,
+ 8, PropModeReplace,
+ (guchar *)&info,
+ sizeof (info));
+
+ /* Set XdndAware */
+
+ if (!xdnd_aware_atom)
+ xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
+
+ /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
+ XChangeProperty (GDK_WINDOW_XDISPLAY (window),
+ GDK_WINDOW_XWINDOW (window),
+ xdnd_aware_atom, XA_ATOM,
+ 32, PropModeReplace,
+ (guchar *)&xdnd_version,
+ sizeof (xdnd_version));
+}
+
+/*************************************************************
+ * gdk_drag_get_selection:
+ * Returns the selection atom for the current source window
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+GdkAtom
+gdk_drag_get_selection (GdkDragContext *context)
+{
+ g_return_val_if_fail (context != NULL, GDK_NONE);
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ return ((GdkDragContextPrivate *)context)->motif_selection;
+ else if (context->protocol == GDK_DRAG_PROTO_XDND)
+ return ((GdkDragContextPrivate *)context)->xdnd_selection;
+ else
+ return GDK_NONE;
+}
+
diff --git a/gdk/gdkimage.c b/gdk/gdkimage.c
index 5c7a5de5c1..4d009f9f42 100644
--- a/gdk/gdkimage.c
+++ b/gdk/gdkimage.c
@@ -409,6 +409,8 @@ gdk_image_destroy (GdkImage *image)
case GDK_IMAGE_SHARED:
#ifdef USE_SHM
+ gdk_flush();
+
XShmDetach (private->xdisplay, private->x_shm_info);
XDestroyImage (private->ximage);
diff --git a/gdk/gdkprivate.h b/gdk/gdkprivate.h
index 9ed85a4663..781db81b1f 100644
--- a/gdk/gdkprivate.h
+++ b/gdk/gdkprivate.h
@@ -46,6 +46,7 @@ typedef struct _GdkVisualPrivate GdkVisualPrivate;
typedef struct _GdkFontPrivate GdkFontPrivate;
typedef struct _GdkCursorPrivate GdkCursorPrivate;
typedef struct _GdkEventFilter GdkEventFilter;
+typedef struct _GdkClientFilter GdkClientFilter;
typedef struct _GdkColorContextPrivate GdkColorContextPrivate;
typedef struct _GdkRegionPrivate GdkRegionPrivate;
@@ -193,6 +194,12 @@ struct _GdkEventFilter {
gpointer data;
};
+struct _GdkClientFilter {
+ GdkAtom type;
+ GdkFilterFunc function;
+ gpointer data;
+};
+
#ifdef USE_XIM
struct _GdkICPrivate
@@ -228,6 +235,7 @@ typedef enum {
void gdk_window_init (void);
void gdk_visual_init (void);
+void gdk_dnd_init (void);
void gdk_image_init (void);
void gdk_image_exit (void);
diff --git a/gdk/gdkproperty.c b/gdk/gdkproperty.c
index 38665ca0c4..5b18ba71e7 100644
--- a/gdk/gdkproperty.c
+++ b/gdk/gdkproperty.c
@@ -22,12 +22,21 @@
#include "gdk.h"
#include "gdkprivate.h"
-
GdkAtom
gdk_atom_intern (const gchar *atom_name,
gint only_if_exists)
{
- return XInternAtom (gdk_display, atom_name, only_if_exists);
+ GdkAtom retval;
+ static GHashTable *atom_hash = NULL;
+
+ if (!atom_hash)
+ atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
+ if (!retval)
+ retval = XInternAtom (gdk_display, atom_name, only_if_exists);
+
+ return retval;
}
gchar *
@@ -35,14 +44,16 @@ gdk_atom_name (GdkAtom atom)
{
gchar *t;
gchar *name;
+ gint old_error_warnings;
/* If this atom doesn't exist, we'll die with an X error unless
we take precautions */
+ old_error_warnings = gdk_error_warnings;
gdk_error_warnings = 0;
gdk_error_code = 0;
t = XGetAtomName (gdk_display, atom);
- gdk_error_warnings = 1;
+ gdk_error_warnings = old_error_warnings;
if (gdk_error_code == -1)
{
@@ -115,7 +126,7 @@ gdk_property_get (GdkWindow *window,
if (actual_format_type)
*actual_format_type = ret_format;
- if (ret_prop_type != type)
+ if ((type != AnyPropertyType) && (ret_prop_type != type))
{
gchar *rn, *pn;
diff --git a/gdk/gdktypes.h b/gdk/gdktypes.h
index 67f9fb3533..5970840e91 100644
--- a/gdk/gdktypes.h
+++ b/gdk/gdktypes.h
@@ -60,6 +60,7 @@ typedef struct _GdkFont GdkFont;
typedef struct _GdkCursor GdkCursor;
typedef struct _GdkColorContextDither GdkColorContextDither;
typedef struct _GdkColorContext GdkColorContext;
+typedef struct _GdkDragContext GdkDragContext;
typedef struct _GdkEventAny GdkEventAny;
typedef struct _GdkEventExpose GdkEventExpose;
@@ -74,14 +75,12 @@ typedef struct _GdkEventConfigure GdkEventConfigure;
typedef struct _GdkEventProperty GdkEventProperty;
typedef struct _GdkEventSelection GdkEventSelection;
typedef struct _GdkEventProximity GdkEventProximity;
-typedef struct _GdkEventOther GdkEventOther;
-typedef struct _GdkEventDragBegin GdkEventDragBegin;
-typedef struct _GdkEventDragRequest GdkEventDragRequest;
-typedef struct _GdkEventDropEnter GdkEventDropEnter;
-typedef struct _GdkEventDropDataAvailable GdkEventDropDataAvailable;
-typedef struct _GdkEventDropLeave GdkEventDropLeave;
typedef struct _GdkEventClient GdkEventClient;
+
+typedef struct _GdkEventDND GdkEventDND;
+
typedef union _GdkEvent GdkEvent;
+
typedef struct _GdkDeviceKey GdkDeviceKey;
typedef struct _GdkDeviceInfo GdkDeviceInfo;
typedef struct _GdkTimeCoord GdkTimeCoord;
@@ -380,15 +379,15 @@ typedef enum
GDK_SELECTION_NOTIFY = 19,
GDK_PROXIMITY_IN = 20,
GDK_PROXIMITY_OUT = 21,
- GDK_DRAG_BEGIN = 22,
- GDK_DRAG_REQUEST = 23,
- GDK_DROP_ENTER = 24,
- GDK_DROP_LEAVE = 25,
- GDK_DROP_DATA_AVAIL = 26,
- GDK_CLIENT_EVENT = 27,
- GDK_VISIBILITY_NOTIFY = 28,
- GDK_NO_EXPOSE = 29,
- GDK_OTHER_EVENT = 9999 /* Deprecated, use filters instead */
+ GDK_DRAG_ENTER = 22,
+ GDK_DRAG_LEAVE = 23,
+ GDK_DRAG_MOTION = 24,
+ GDK_DRAG_STATUS = 25,
+ GDK_DROP_START = 26,
+ GDK_DROP_FINISHED = 27,
+ GDK_CLIENT_EVENT = 28,
+ GDK_VISIBILITY_NOTIFY = 29,
+ GDK_NO_EXPOSE = 30,
} GdkEventType;
/* Event masks. (Used to select what types of events a window
@@ -539,24 +538,6 @@ typedef enum
GDK_PROP_MODE_APPEND
} GdkPropMode;
-/* These definitions are for version 1 of the OffiX D&D protocol,
- taken from <OffiX/DragAndDropTypes.h> */
-typedef enum
-{
- GDK_DNDTYPE_NOTDND = -1,
- GDK_DNDTYPE_UNKNOWN = 0,
- GDK_DNDTYPE_RAWDATA = 1,
- GDK_DNDTYPE_FILE = 2,
- GDK_DNDTYPE_FILES = 3,
- GDK_DNDTYPE_TEXT = 4,
- GDK_DNDTYPE_DIR = 5,
- GDK_DNDTYPE_LINK = 6,
- GDK_DNDTYPE_EXE = 7,
- GDK_DNDTYPE_URL = 8,
- GDK_DNDTYPE_MIME = 9,
- GDK_DNDTYPE_END = 10
-} GdkDndType;
-
/* Enums for XInput support */
typedef enum
@@ -697,6 +678,22 @@ typedef enum
GDK_OVERLAP_RECTANGLE_PART
} GdkOverlapType;
+typedef enum {
+ GDK_ACTION_DEFAULT = 1 << 0,
+ GDK_ACTION_COPY = 1 << 1,
+ GDK_ACTION_MOVE = 1 << 2,
+ GDK_ACTION_LINK = 1 << 3,
+ GDK_ACTION_PRIVATE = 1 << 4,
+ GDK_ACTION_ASK = 1 << 5
+} GdkDragAction;
+
+typedef enum {
+ GDK_DRAG_PROTO_MOTIF,
+ GDK_DRAG_PROTO_XDND,
+ GDK_DRAG_PROTO_ROOTWIN /* A root window with nobody claiming
+ * drags */
+} GdkDragProtocol;
+
/* The color type.
* A color consists of red, green and blue values in the
* range 0-65535 and a pixel value. The pixel value is highly
@@ -938,6 +935,25 @@ struct _GdkTimeCoord
gdouble ytilt;
};
+/* Structure that holds information about a drag in progress.
+ * this is used on both source and destination sides.
+ */
+struct _GdkDragContext {
+ GdkDragProtocol protocol;
+
+ gboolean is_source;
+
+ GdkWindow *source_window;
+ GdkWindow *dest_window;
+
+ GList *targets;
+ GdkDragAction actions;
+ GdkDragAction suggested_action;
+ GdkDragAction action;
+
+ guint32 start_time;
+};
+
/* Event filtering */
typedef void GdkXEvent; /* Can be cast to XEvent */
@@ -1096,100 +1112,6 @@ struct _GdkEventProximity
guint32 deviceid;
};
-struct _GdkEventDragRequest
-{
- GdkEventType type;
- GdkWindow *window;
- gint8 send_event;
- guint32 requestor;
- union {
- struct {
- guint protocol_version:4;
- guint sendreply:1;
- guint willaccept:1;
- guint delete_data:1; /* Do *not* delete if link is sent, only
- if data is sent */
- guint senddata:1;
- guint reserved:22;
- } flags;
- glong allflags;
- } u;
- guint8 isdrop; /* This gdk event can be generated by a couple of
- X events - this lets the app know whether the
- drop really occurred or we just set the data */
-
- GdkPoint drop_coords;
- gchar *data_type;
- guint32 timestamp;
-};
-
-struct _GdkEventDragBegin
-{
- GdkEventType type;
- GdkWindow *window;
- gint8 send_event;
- union {
- struct {
- guint protocol_version:4;
- guint reserved:28;
- } flags;
- glong allflags;
- } u;
-};
-
-struct _GdkEventDropEnter
-{
- GdkEventType type;
- GdkWindow *window;
- gint8 send_event;
- guint32 requestor;
- union {
- struct {
- guint protocol_version:4;
- guint sendreply:1;
- guint extended_typelist:1;
- guint reserved:26;
- } flags;
- glong allflags;
- } u;
-};
-
-struct _GdkEventDropLeave
-{
- GdkEventType type;
- GdkWindow *window;
- gint8 send_event;
- guint32 requestor;
- union {
- struct {
- guint protocol_version:4;
- guint reserved:28;
- } flags;
- glong allflags;
- } u;
-};
-
-struct _GdkEventDropDataAvailable
-{
- GdkEventType type;
- GdkWindow *window;
- gint8 send_event;
- guint32 requestor;
- union {
- struct {
- guint protocol_version:4;
- guint isdrop:1;
- guint reserved:25;
- } flags;
- glong allflags;
- } u;
- gchar *data_type; /* MIME type */
- gulong data_numbytes;
- gpointer data;
- guint32 timestamp;
- GdkPoint coords;
-};
-
struct _GdkEventClient
{
GdkEventType type;
@@ -1204,12 +1126,16 @@ struct _GdkEventClient
} data;
};
-struct _GdkEventOther
-{
+/* Event types for DND */
+
+struct _GdkEventDND {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
- GdkXEvent *xevent;
+ GdkDragContext *context;
+
+ guint32 time;
+ gshort x_root, y_root;
};
union _GdkEvent
@@ -1228,13 +1154,8 @@ union _GdkEvent
GdkEventProperty property;
GdkEventSelection selection;
GdkEventProximity proximity;
- GdkEventDragBegin dragbegin;
- GdkEventDragRequest dragrequest;
- GdkEventDropEnter dropenter;
- GdkEventDropLeave dropleave;
- GdkEventDropDataAvailable dropdataavailable;
GdkEventClient client;
- GdkEventOther other;
+ GdkEventDND dnd;
};
struct _GdkRegion
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 7c2d9b099c..3df6ac8ac1 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -216,6 +216,9 @@ gdk_window_init (void)
gdk_root_parent.height = height;
gdk_root_parent.children = NULL;
gdk_root_parent.colormap = NULL;
+ gdk_root_parent.ref_count = 1;
+
+ gdk_xid_table_insert (&gdk_root_window, &gdk_root_parent);
}
GdkWindow*
@@ -703,11 +706,15 @@ gdk_window_unref (GdkWindow *window)
if (private->ref_count == 0)
{
if (!private->destroyed)
- g_warning ("losing last reference to undestroyed window\n");
+ {
+ if (private->window_type == GDK_WINDOW_FOREIGN)
+ gdk_xid_table_remove (private->xwindow);
+ else
+ g_warning ("losing last reference to undestroyed window\n");
+ }
g_dataset_destroy (window);
g_free (window);
}
-
}
void
@@ -1681,188 +1688,6 @@ gdk_window_shape_combine_mask (GdkWindow *window,
#endif /* HAVE_SHAPE_EXT */
}
-void
-gdk_dnd_drag_addwindow (GdkWindow *window)
-{
- GdkWindowPrivate *window_private;
-
- g_return_if_fail (window != NULL);
-
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- if (window_private->dnd_drag_enabled == 1 && gdk_dnd.drag_really == 0)
- {
- gdk_dnd.drag_numwindows++;
- gdk_dnd.drag_startwindows = g_realloc (gdk_dnd.drag_startwindows,
- gdk_dnd.drag_numwindows
- * sizeof(GdkWindow *));
- gdk_dnd.drag_startwindows[gdk_dnd.drag_numwindows - 1] = window;
- window_private->dnd_drag_accepted = 0;
- }
- else
- g_warning ("dnd_really is 1 or drag is not enabled! can't addwindow\n");
-}
-
-void
-gdk_window_dnd_drag_set (GdkWindow *window,
- guint8 drag_enable,
- gchar **typelist,
- guint numtypes)
-{
- GdkWindowPrivate *window_private;
- int i, wasset = 0;
-
- g_return_if_fail (window != NULL);
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- window_private->dnd_drag_enabled = drag_enable ? 1 : 0;
-
- if (drag_enable)
- {
- g_return_if_fail(typelist != NULL);
-
- if (window_private->dnd_drag_data_numtypesavail > 3)
- wasset = 1;
- window_private->dnd_drag_data_numtypesavail = numtypes;
-
- window_private->dnd_drag_data_typesavail =
- g_realloc (window_private->dnd_drag_data_typesavail,
- (numtypes + 1) * sizeof (GdkAtom));
-
- for (i = 0; i < numtypes; i++)
- {
- /* Allow blanket use of ALL to get anything... */
- if (strcmp (typelist[i], "ALL"))
- window_private->dnd_drag_data_typesavail[i] =
- gdk_atom_intern (typelist[i], FALSE);
- else
- window_private->dnd_drag_data_typesavail[i] = None;
- }
-
- /*
- * set our extended type list if we need to
- */
- if (numtypes > 3)
- gdk_property_change(window, gdk_dnd.gdk_XdeTypelist,
- XA_PRIMARY, 32, GDK_PROP_MODE_REPLACE,
- (guchar *)(window_private->dnd_drag_data_typesavail
- + (sizeof(GdkAtom) * 3)),
- (numtypes - 3) * sizeof(GdkAtom));
- else if (wasset)
- gdk_property_delete (window, gdk_dnd.gdk_XdeTypelist);
- }
- else
- {
- g_free (window_private->dnd_drag_data_typesavail);
- window_private->dnd_drag_data_typesavail = NULL;
- window_private->dnd_drag_data_numtypesavail = 0;
- }
-}
-
-void
-gdk_window_dnd_drop_set (GdkWindow *window,
- guint8 drop_enable,
- gchar **typelist,
- guint numtypes,
- guint8 destructive_op)
-{
- GdkWindowPrivate *window_private;
- int i;
-
- g_return_if_fail (window != NULL);
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- window_private->dnd_drop_enabled = drop_enable ? 1 : 0;
- if (drop_enable)
- {
- g_return_if_fail(typelist != NULL);
-
- window_private->dnd_drop_data_numtypesavail = numtypes;
-
- window_private->dnd_drop_data_typesavail =
- g_realloc (window_private->dnd_drop_data_typesavail,
- (numtypes + 1) * sizeof (GdkAtom));
-
- for (i = 0; i < numtypes; i++)
- window_private->dnd_drop_data_typesavail[i] =
- gdk_atom_intern (typelist[i], FALSE);
-
- window_private->dnd_drop_destructive_op = destructive_op;
- }
-}
-
-/*
- * This is used to reply to a GDK_DRAG_REQUEST event
- * (which may be generated by XdeRequest or a confirmed drop...
- */
-void
-gdk_window_dnd_data_set (GdkWindow *window,
- GdkEvent *event,
- gpointer data,
- gulong data_numbytes)
-{
- GdkWindowPrivate *window_private;
- XEvent sev;
- GdkEventDropDataAvailable tmp_ev;
- gchar *tmp;
-
- g_return_if_fail (window != NULL);
- g_return_if_fail (event != NULL);
- g_return_if_fail (data != NULL);
- g_return_if_fail (data_numbytes > 0);
- g_return_if_fail (event->type == GDK_DRAG_REQUEST);
-
- window_private = (GdkWindowPrivate *) window;
- g_return_if_fail (window_private->dnd_drag_accepted != 0);
- if (window_private->destroyed)
- return;
-
- /* We set the property on our window... */
- gdk_property_change (window, window_private->dnd_drag_data_type,
- XA_PRIMARY, 8, GDK_PROP_MODE_REPLACE, data,
- data_numbytes);
- tmp = gdk_atom_name(window_private->dnd_drag_data_type);
-#ifdef DEBUG_DND
- g_message("DnD type %s on window %ld\n", tmp, window_private->xwindow);
-#endif
- g_free(tmp);
-
- /*
- * Then we send the event to tell the receiving window that the
- * drop has happened
- */
- tmp_ev.u.allflags = 0;
- tmp_ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tmp_ev.u.flags.isdrop = event->dragrequest.isdrop;
-
- sev.xclient.type = ClientMessage;
- sev.xclient.format = 32;
- sev.xclient.window = event->dragrequest.requestor;
- sev.xclient.message_type = gdk_dnd.gdk_XdeDataAvailable;
- sev.xclient.data.l[0] = window_private->xwindow;
- sev.xclient.data.l[1] = tmp_ev.u.allflags;
- sev.xclient.data.l[2] = window_private->dnd_drag_data_type;
-
- if (event->dragrequest.isdrop)
- sev.xclient.data.l[3] = event->dragrequest.drop_coords.x +
- (event->dragrequest.drop_coords.y << 16);
- else
- sev.xclient.data.l[3] = 0;
-
- sev.xclient.data.l[4] = event->dragrequest.timestamp;
-
- if (!gdk_send_xevent (event->dragrequest.requestor, False,
- StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeDataAvailable to %#x failed\n",
- event->dragrequest.requestor));
-}
-
void
gdk_window_add_filter (GdkWindow *window,
GdkFilterFunc function,
@@ -1905,7 +1730,7 @@ gdk_window_remove_filter (GdkWindow *window,
gpointer data)
{
GdkWindowPrivate *private;
- GList *tmp_list;
+ GList *tmp_list, *node;
GdkEventFilter *filter;
private = (GdkWindowPrivate*) window;
@@ -1918,15 +1743,16 @@ gdk_window_remove_filter (GdkWindow *window,
while (tmp_list)
{
filter = (GdkEventFilter *)tmp_list->data;
+ node = tmp_list;
tmp_list = tmp_list->next;
if ((filter->function == function) && (filter->data == data))
{
if(private)
- private->filters = g_list_remove_link (private->filters, tmp_list);
+ private->filters = g_list_remove_link (private->filters, node);
else
gdk_default_filters = g_list_remove_link (gdk_default_filters, tmp_list);
- g_list_free_1 (tmp_list);
+ g_list_free_1 (node);
g_free (filter);
return;
diff --git a/gdk/x11/gdkcolor-x11.c b/gdk/x11/gdkcolor-x11.c
index 36b6c8593c..f84f570255 100644
--- a/gdk/x11/gdkcolor-x11.c
+++ b/gdk/x11/gdkcolor-x11.c
@@ -179,6 +179,18 @@ gdk_colormap_unref (GdkColormap *cmap)
gdk_colormap_real_destroy (cmap);
}
+GdkVisual *
+gdk_colormap_get_visual (GdkColormap *colormap)
+{
+ GdkColormapPrivate *private;
+
+ g_return_val_if_fail (colormap != NULL, NULL);
+
+ private = (GdkColormapPrivate *)colormap;
+
+ return private->visual;
+}
+
#define MIN_SYNC_TIME 2
void
diff --git a/gdk/x11/gdkdnd-x11.c b/gdk/x11/gdkdnd-x11.c
index 331aad7ef7..67720ad6bd 100644
--- a/gdk/x11/gdkdnd-x11.c
+++ b/gdk/x11/gdkdnd-x11.c
@@ -20,157 +20,2853 @@
#include <X11/Xatom.h>
#include <string.h>
#include "gdkx.h"
+#include "gdk/gdkprivate.h"
#include "gdk.h"
-/* Nothing much here now, but we have to make a start some time ;-) */
+typedef struct _GdkDragContextPrivate GdkDragContextPrivate;
-void
-gdk_dnd_set_drag_cursors(GdkCursor *default_cursor, GdkCursor *goahead_cursor)
+typedef enum {
+ GDK_DRAG_STATUS_DRAG,
+ GDK_DRAG_STATUS_MOTION_WAIT,
+ GDK_DRAG_STATUS_ACTION_WAIT,
+ GDK_DRAG_STATUS_DROP
+} GtkDragStatus;
+
+typedef struct {
+ guint32 xid;
+ gint x, y, width, height;
+ gboolean mapped;
+} GdkCacheChild;
+
+typedef struct {
+ GList *children;
+ GHashTable *child_hash;
+ guint old_event_mask;
+} GdkWindowCache;
+
+/* Structure that holds information about a drag in progress.
+ * this is used on both source and destination sides.
+ */
+struct _GdkDragContextPrivate {
+ GdkDragContext context;
+
+ GdkAtom motif_selection;
+ GdkAtom xdnd_selection;
+ guint ref_count;
+
+ guint16 last_x; /* Coordinates from last event */
+ guint16 last_y;
+ GdkDragAction old_action; /* The last action we sent to the source */
+
+ Window dest_xid;
+ guint xdnd_targets_set : 1; /* Whether we've already set XdndTypeList */
+ guint motif_targets_set : 1; /* Whether we've already set motif initiator info */
+ guint drag_status : 4; /* current status of drag */
+
+ GdkWindowCache *window_cache;
+};
+
+GdkDragContext *current_dest_drag = NULL;
+
+/* Forward declarations */
+
+static void gdk_window_cache_destroy (GdkWindowCache *cache);
+
+static void motif_read_target_table (void);
+static GdkFilterReturn motif_dnd_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_enter_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_leave_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_position_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_status_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_finished_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+static GdkFilterReturn xdnd_drop_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
+/* Drag Contexts */
+
+static GList *contexts;
+
+GdkDragContext *
+gdk_drag_context_new (void)
+{
+ GdkDragContextPrivate *result;
+
+ result = g_new0 (GdkDragContextPrivate, 1);
+
+ result->ref_count = 1;
+
+ contexts = g_list_prepend (contexts, result);
+
+ return (GdkDragContext *)result;
+}
+
+void
+gdk_drag_context_ref (GdkDragContext *context)
+{
+ ((GdkDragContextPrivate *)context)->ref_count++;
+}
+
+void
+gdk_drag_context_unref (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ private->ref_count--;
+
+ if (private->ref_count == 0)
+ {
+ g_dataset_destroy (private);
+
+ g_list_free (context->targets);
+
+ if (context->source_window)
+ gdk_window_unref (context->source_window);
+
+ if (context->dest_window)
+ gdk_window_unref (context->dest_window);
+
+ if (private->window_cache)
+ gdk_window_cache_destroy (private->window_cache);
+
+ contexts = g_list_remove (contexts, private);
+ g_free (private);
+ }
+}
+
+static GdkDragContext *
+gdk_drag_context_find (gboolean is_source,
+ Window source_xid,
+ Window dest_xid)
+{
+ GList *tmp_list = contexts;
+
+ while (tmp_list)
+ {
+ GdkDragContext *context = (GdkDragContext *)tmp_list->data;
+
+ if ((!context->is_source == !is_source) &&
+ ((source_xid == None) || (context->source_window &&
+ (GDK_WINDOW_XWINDOW (context->source_window) == source_xid))) &&
+ ((dest_xid == None) || (context->dest_window &&
+ (GDK_WINDOW_XWINDOW (context->dest_window) == dest_xid))))
+ return context;
+
+ tmp_list = tmp_list->next;
+ }
+
+ return NULL;
+}
+
+/* Utility functions */
+
+static void
+gdk_window_cache_add (GdkWindowCache *cache,
+ guint32 xid,
+ gint x, gint y, gint width, gint height,
+ gboolean mapped)
+{
+ GdkCacheChild *child = g_new (GdkCacheChild, 1);
+
+ child->xid = xid;
+ child->x = x;
+ child->y = y;
+ child->width = width;
+ child->height = height;
+ child->mapped = mapped;
+
+ cache->children = g_list_prepend (cache->children, child);
+ g_hash_table_insert (cache->child_hash, GUINT_TO_POINTER (xid),
+ cache->children);
+}
+
+static GdkFilterReturn
+gdk_window_cache_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ GdkWindowCache *cache = data;
+
+ switch (xevent->type)
+ {
+ case CirculateNotify:
+ break;
+ case ConfigureNotify:
+ {
+ XConfigureEvent *xce = &xevent->xconfigure;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xce->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->x = xce->x;
+ child->y = xce->y;
+ child->width = xce->width;
+ child->height = xce->height;
+ if (xce->above == None && (node->next))
+ {
+ GList *last = g_list_last (cache->children);
+ cache->children = g_list_remove_link (cache->children, node);
+ last->next = node;
+ node->next = NULL;
+ node->prev = last;
+ }
+ else
+ {
+ GList *above_node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xce->above));
+ if (above_node && node->prev != above_node)
+ {
+ cache->children = g_list_remove_link (cache->children, node);
+ node->next = above_node->next;
+ node->prev = above_node;
+ above_node->next = node;
+ }
+ }
+ }
+ break;
+ }
+ case CreateNotify:
+ {
+ XCreateWindowEvent *xcwe = &xevent->xcreatewindow;
+ if (!g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xcwe->window)))
+ gdk_window_cache_add (cache, xcwe->window,
+ xcwe->x, xcwe->y, xcwe->width, xcwe->height,
+ FALSE);
+ break;
+ }
+ case DestroyNotify:
+ {
+ XDestroyWindowEvent *xdwe = &xevent->xdestroywindow;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xdwe->window));
+ if (node)
+ {
+ g_hash_table_remove (cache->child_hash,
+ GUINT_TO_POINTER (xdwe->window));
+ cache->children = g_list_remove_link (cache->children, node);
+ g_free (node->data);
+ g_list_free_1 (node);
+ }
+ break;
+ }
+ case MapNotify:
+ {
+ XMapEvent *xme = &xevent->xmap;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xme->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->mapped = TRUE;
+ }
+ break;
+ }
+ case ReparentNotify:
+ break;
+ case UnmapNotify:
+ {
+ XMapEvent *xume = &xevent->xmap;
+ GList *node;
+
+ node = g_hash_table_lookup (cache->child_hash,
+ GUINT_TO_POINTER (xume->window));
+ if (node)
+ {
+ GdkCacheChild *child = node->data;
+ child->mapped = FALSE;
+ }
+ break;
+ }
+ default:
+ return GDK_FILTER_CONTINUE;
+ }
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkWindowCache *
+gdk_window_cache_new (void)
+{
+ XWindowAttributes xwa;
+ Window root, parent, *children;
+ unsigned int nchildren;
+ int i;
+
+ gint old_warnings = gdk_error_warnings;
+
+ GdkWindowCache *result = g_new (GdkWindowCache, 1);
+
+ result->children = NULL;
+ result->child_hash = g_hash_table_new (g_direct_hash, NULL);
+
+ XGetWindowAttributes (gdk_display, gdk_root_window, &xwa);
+ result->old_event_mask = xwa.your_event_mask;
+ XSelectInput (gdk_display, gdk_root_window,
+ result->old_event_mask | SubstructureNotifyMask);
+ gdk_window_add_filter ((GdkWindow *)&gdk_root_parent,
+ gdk_window_cache_filter, result);
+
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ if (XQueryTree(gdk_display, gdk_root_window,
+ &root, &parent, &children, &nchildren) == 0)
+ return result;
+
+ for (i = 0; i < nchildren ; i++)
+ {
+ XGetWindowAttributes (gdk_display, children[i], &xwa);
+
+ gdk_window_cache_add (result, children[i],
+ xwa.x, xwa.y, xwa.width, xwa.height,
+ xwa.map_state != IsUnmapped);
+
+ if (gdk_error_code != 0)
+ gdk_error_code = 0;
+ else
+ {
+ gdk_window_cache_add (result, children[i],
+ xwa.x, xwa.y, xwa.width, xwa.height,
+ (xwa.map_state != IsUnmapped));
+ }
+ }
+
+ XFree (children);
+
+ gdk_error_warnings = old_warnings;
+
+ return result;
+}
+
+static void
+gdk_window_cache_destroy (GdkWindowCache *cache)
+{
+ XSelectInput (gdk_display, gdk_root_window, cache->old_event_mask);
+ gdk_window_remove_filter ((GdkWindow *)&gdk_root_parent,
+ gdk_window_cache_filter, cache);
+
+ g_list_foreach (cache->children, (GFunc)g_free, NULL);
+ g_list_free (cache->children);
+ g_hash_table_destroy (cache->child_hash);
+}
+
+static Window
+get_client_window_at_coords_recurse (Window win,
+ gint x_root,
+ gint y_root)
+{
+ Window child;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+ int dest_x, dest_y;
+
+ static Atom wm_state_atom = None;
+
+ if (!wm_state_atom)
+ wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ wm_state_atom, 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (type != None)
+ {
+ XFree (data);
+ return win;
+ }
+
+ XTranslateCoordinates (gdk_display, gdk_root_window, win,
+ x_root, y_root, &dest_x, &dest_y, &child);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (child)
+ return get_client_window_at_coords_recurse (child, x_root, y_root);
+ else
+ return None;
+}
+
+Window
+get_client_window_at_coords (GdkWindowCache *cache,
+ Window ignore,
+ gint x_root,
+ gint y_root)
{
- gdk_dnd.c->gdk_cursor_dragdefault =
- ((GdkCursorPrivate *)default_cursor)->xcursor;
- gdk_dnd.c->gdk_cursor_dragok = ((GdkCursorPrivate *)goahead_cursor)->xcursor;
+ GList *tmp_list;
+ Window retval = None;
+
+ gint old_warnings = gdk_error_warnings;
- if(gdk_dnd.dnd_grabbed)
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ tmp_list = cache->children;
+
+ while (tmp_list && !retval)
{
- if(gdk_dnd.c->drag_pm_default)
- /* We were displaying pixmaps for the drag */
+ GdkCacheChild *child = tmp_list->data;
+
+ if ((child->xid != ignore) && (child->mapped))
{
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- gdk_window_unref(gdk_dnd.c->drag_pm_default);
- if(gdk_dnd.c->drag_pm_ok)
+ if ((x_root >= child->x) && (x_root < child->x + child->width) &&
+ (y_root >= child->y) && (y_root < child->y + child->height))
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_unref(gdk_dnd.c->drag_pm_ok);
+ retval = get_client_window_at_coords_recurse (child->xid,
+ x_root, y_root);
+ if (!retval)
+ retval = child->xid;
}
- gdk_dnd.c->drag_pm_default = gdk_dnd.c->drag_pm_ok = NULL;
- g_list_free(gdk_dnd.c->xids);
- gdk_dnd.c->xids = NULL;
+
}
- gdk_dnd_display_drag_cursor(-1, -1,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- TRUE);
+ tmp_list = tmp_list->next;
}
+
+ gdk_error_warnings = old_warnings;
+ if (retval)
+ return retval;
+ else
+ return gdk_root_window;
}
-void
-gdk_dnd_set_drag_shape(GdkWindow *default_pixmapwin,
- GdkPoint *default_hotspot,
- GdkWindow *goahead_pixmapwin,
- GdkPoint *goahead_hotspot)
+#if 0
+static Window
+get_client_window_at_coords_recurse (Window win,
+ gint x_root,
+ gint y_root)
{
- g_return_if_fail(default_pixmapwin != NULL);
+ Window child;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+ int dest_x, dest_y;
- g_list_free(gdk_dnd.c->xids); gdk_dnd.c->xids = NULL;
- if(gdk_dnd.c->drag_pm_default)
+ static Atom wm_state_atom = None;
+
+ if (!wm_state_atom)
+ wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ wm_state_atom, 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+
+ if (gdk_error_code != 0)
+ {
+ gdk_error_code = 0;
+ return None;
+ }
+
+ if (type != None)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- gdk_window_unref(gdk_dnd.c->drag_pm_default);
+ XFree (data);
+ return win;
}
- if(gdk_dnd.c->drag_pm_ok)
+
+ XTranslateCoordinates (gdk_display, gdk_root_window, win,
+ x_root, y_root, &dest_x, &dest_y, &child);
+
+ if (gdk_error_code != 0)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_unref(gdk_dnd.c->drag_pm_ok);
+ gdk_error_code = 0;
+ return None;
}
+
+ if (child)
+ return get_client_window_at_coords_recurse (child, x_root, y_root);
+ else
+ return None;
+}
+
+Window
+get_client_window_at_coords (Window ignore,
+ gint x_root,
+ gint y_root)
+{
+ Window root, parent, *children;
+ unsigned int nchildren;
+ int i;
+ Window retval = None;
+
+ gint old_warnings = gdk_error_warnings;
- gdk_dnd.c->drag_pm_ok = NULL;
+ gdk_error_code = 0;
+ gdk_error_warnings = 0;
+
+ if (XQueryTree(gdk_display, gdk_root_window,
+ &root, &parent, &children, &nchildren) == 0)
+ return 0;
- gdk_window_ref(default_pixmapwin);
- gdk_dnd.c->drag_pm_default = default_pixmapwin;
- gdk_dnd.c->default_hotspot = *default_hotspot;
- gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)default_pixmapwin)->xwindow));
- if(goahead_pixmapwin)
+ for (i = nchildren - 1; (i >= 0) && (retval == None); i--)
+ {
+ if (children[i] != ignore)
+ {
+ XWindowAttributes xwa;
+
+ XGetWindowAttributes (gdk_display, children[i], &xwa);
+
+ if (gdk_error_code != 0)
+ gdk_error_code = 0;
+ else if ((xwa.map_state == IsViewable) &&
+ (x_root >= xwa.x) && (x_root < xwa.x + (gint)xwa.width) &&
+ (y_root >= xwa.y) && (y_root < xwa.y + (gint)xwa.height))
+ {
+ retval = get_client_window_at_coords_recurse (children[i],
+ x_root, y_root);
+ if (!retval)
+ retval = children[i];
+ }
+ }
+ }
+
+ XFree (children);
+
+ gdk_error_warnings = old_warnings;
+ if (retval)
+ return retval;
+ else
+ return gdk_root_window;
+}
+#endif
+
+/*************************************************************
+ ***************************** MOTIF *************************
+ *************************************************************/
+
+/* values used in the message type for Motif DND */
+enum {
+ XmTOP_LEVEL_ENTER,
+ XmTOP_LEVEL_LEAVE,
+ XmDRAG_MOTION,
+ XmDROP_SITE_ENTER,
+ XmDROP_SITE_LEAVE,
+ XmDROP_START,
+ XmDROP_FINISH,
+ XmDRAG_DROP_FINISH,
+ XmOPERATION_CHANGED
+};
+
+/* Values used to specify type of protocol to use */
+enum {
+ XmDRAG_NONE,
+ XmDRAG_DROP_ONLY,
+ XmDRAG_PREFER_PREREGISTER,
+ XmDRAG_PREREGISTER,
+ XmDRAG_PREFER_DYNAMIC,
+ XmDRAG_DYNAMIC,
+ XmDRAG_PREFER_RECEIVER
+};
+
+/* Operation codes */
+enum {
+ XmDROP_NOOP,
+ XmDROP_MOVE = 0x01,
+ XmDROP_COPY = 0x02,
+ XmDROP_LINK = 0x04
+};
+
+/* Drop site status */
+enum {
+ XmNO_DROP_SITE = 0x01,
+ XmDROP_SITE_INVALID = 0x02,
+ XmDROP_SITE_VALID = 0x03
+};
+
+/* completion status */
+enum {
+ XmDROP,
+ XmDROP_HELP,
+ XmDROP_CANCEL,
+ XmDROP_INTERRUPT
+};
+
+/* Static data for MOTIF DND */
+static GList **motif_target_lists = NULL;
+static gint motif_n_target_lists = -1;
+
+/* Byte swapping routines. The motif specification leaves it
+ * up to us to save a few bytes in the client messages
+ */
+static gchar local_byte_order = '\0';
+
+#ifdef G_ENABLE_DEBUG
+static void
+print_target_list (GList *targets)
+{
+ while (targets)
+ {
+ gchar *name = gdk_atom_name (GPOINTER_TO_INT (targets->data));
+ g_message ("\t%s", name);
+ g_free (name);
+ targets = targets->next;
+ }
+}
+#endif /* G_ENABLE_DEBUG */
+
+static void
+init_byte_order (void)
+{
+ guint32 myint = 0x01020304;
+ local_byte_order = (*(gchar *)&myint == 1) ? 'B' : 'l';
+}
+
+static guint16
+card16_to_host (guint16 x, gchar byte_order) {
+ if (byte_order == local_byte_order)
+ return x;
+ else
+ return (x << 8) | (x >> 8);
+}
+
+static guint32
+card32_to_host (guint32 x, gchar byte_order) {
+ if (byte_order == local_byte_order)
+ return x;
+ else
+ return (x << 24) | ((x & 0xff00) << 8) | ((x & 0xff0000) >> 8) | (x >> 24);
+}
+
+
+/***** Dest side ***********/
+
+/* Property placed on source windows */
+typedef struct _MotifDragInitiatorInfo {
+ guint8 byte_order;
+ guint8 protocol_version;
+ guint16 targets_index;
+ guint32 selection_atom;
+} MotifDragInitiatorInfo;
+
+/* Header for target table on the drag window */
+typedef struct _MotifTargetTableHeader {
+ guchar byte_order;
+ guchar protocol_version;
+ guint16 n_lists;
+ guint32 total_size;
+} MotifTargetTableHeader;
+
+/* Property placed on target windows */
+typedef struct _MotifDragReceiverInfo {
+ guint8 byte_order;
+ guint8 protocol_version;
+ guint8 protocol_style;
+ guint8 pad;
+ guint32 proxy_window;
+ guint16 num_drop_sites;
+ guint16 padding;
+ guint32 total_size;
+} MotifDragReceiverInfo;
+
+static Window motif_drag_window = None;
+static GdkWindow *motif_drag_gdk_window = NULL;
+
+static GdkAtom motif_drag_targets_atom = GDK_NONE;
+static GdkAtom motif_drag_receiver_info_atom = GDK_NONE;
+
+/* Target table handling */
+
+GdkFilterReturn
+motif_drag_window_filter (GdkXEvent *xevent,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xev = (XEvent *)xevent;
+
+ switch (xev->xany.type)
{
- gdk_window_ref(goahead_pixmapwin);
- gdk_dnd.c->xids = g_list_append(gdk_dnd.c->xids, GUINT_TO_POINTER (((GdkWindowPrivate *)goahead_pixmapwin)->xwindow));
- gdk_dnd.c->drag_pm_ok = goahead_pixmapwin;
- gdk_dnd.c->ok_hotspot = *goahead_hotspot;
+ case DestroyNotify:
+ motif_drag_window = None;
+ motif_drag_gdk_window = NULL;
+ break;
+ case PropertyNotify:
+ if (motif_target_lists &&
+ motif_drag_targets_atom &&
+ (xev->xproperty.atom == motif_drag_targets_atom))
+ motif_read_target_table();
+ break;
}
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkAtom motif_drag_window_atom = GDK_NONE;
+
+static Window
+motif_lookup_drag_window (Display *display)
+{
+ Window retval = None;
+ gulong bytes_after, nitems;
+ GdkAtom type;
+ gint format;
+ guchar *data;
+
+ XGetWindowProperty (gdk_display, gdk_root_window, motif_drag_window_atom,
+ 0, sizeof(Window)/4, FALSE,
+ XA_WINDOW, &type, &format, &nitems, &bytes_after,
+ &data);
- if(gdk_dnd.dnd_grabbed)
+ if ((format == 8*sizeof(Window)) && (nitems == 1) && (bytes_after == 0))
{
- gdk_dnd_display_drag_cursor(-1, -1,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- TRUE);
- XChangeActivePointerGrab (gdk_display,
- ButtonMotionMask |
- ButtonPressMask |
- ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask,
- None,
- CurrentTime);
+ retval = *(Window *)data;
+ GDK_NOTE(DND,
+ g_message ("Found drag window %#lx\n", motif_drag_window));
}
+
+ if (type != None)
+ XFree (data);
+
+ return retval;
}
-void
-gdk_dnd_display_drag_cursor(gint x, gint y, gboolean drag_ok,
- gboolean change_made)
+/* Finds the window where global Motif drag information is stored.
+ * If it doesn't exist and 'create' is TRUE, create one.
+ */
+Window
+motif_find_drag_window (gboolean create)
+{
+ if (!motif_drag_window)
+ {
+ if (!motif_drag_window_atom)
+ motif_drag_window_atom = gdk_atom_intern ("_MOTIF_DRAG_WINDOW", TRUE);
+
+ motif_drag_window = motif_lookup_drag_window (gdk_display);
+
+ if (!motif_drag_window && create)
+ {
+ /* Create a persistant window. (Copied from LessTif) */
+
+ Display *display;
+ XSetWindowAttributes attr;
+ display = XOpenDisplay (NULL);
+ XSetCloseDownMode (display, RetainPermanent);
+
+ XGrabServer (display);
+
+ motif_drag_window = motif_lookup_drag_window (display);
+
+ if (!motif_drag_window)
+ {
+ attr.override_redirect = True;
+ attr.event_mask = PropertyChangeMask;
+
+ motif_drag_window =
+ XCreateWindow(display, DefaultRootWindow(display),
+ -100, -100, 10, 10, 0, 0,
+ InputOnly, CopyFromParent,
+ (CWOverrideRedirect | CWEventMask), &attr);
+
+ GDK_NOTE (DND,
+ g_message ("Created drag window %#lx\n", motif_drag_window));
+
+ XChangeProperty (display, gdk_root_window,
+ motif_drag_window_atom, XA_WINDOW,
+ 32, PropModeReplace,
+ (guchar *)&motif_drag_window_atom, 1);
+
+ }
+ XUngrabServer (display);
+ XCloseDisplay (display);
+ }
+
+ /* There is a miniscule race condition here if the drag window
+ * gets destroyed exactly now.
+ */
+ if (motif_drag_window)
+ {
+ motif_drag_gdk_window = gdk_window_foreign_new (motif_drag_window);
+ gdk_window_add_filter (motif_drag_gdk_window,
+ motif_drag_window_filter,
+ NULL);
+ }
+ }
+
+ return motif_drag_window;
+}
+
+static void
+motif_read_target_table (void)
{
- if(!gdk_dnd.dnd_grabbed)
- return;
+ gulong bytes_after, nitems;
+ GdkAtom type;
+ gint format;
+ gint i, j;
+
+ if (!motif_drag_targets_atom)
+ motif_drag_targets_atom = gdk_atom_intern ("_MOTIF_DRAG_TARGETS", FALSE);
+
+ if (motif_target_lists)
+ {
+ for (i=0; i<motif_n_target_lists; i++)
+ g_list_free (motif_target_lists[i]);
+
+ g_free (motif_target_lists);
+ motif_target_lists = NULL;
+ motif_n_target_lists = 0;
+ }
+
+ if (motif_find_drag_window (FALSE))
+ {
+ MotifTargetTableHeader *header = NULL;
+ guchar *target_bytes = NULL;
+ guchar *p;
+ gboolean success = FALSE;
+
+ XGetWindowProperty (gdk_display, motif_drag_window,
+ motif_drag_targets_atom,
+ 0, (sizeof(MotifTargetTableHeader)+3)/4, FALSE,
+ motif_drag_targets_atom,
+ &type, &format, &nitems, &bytes_after,
+ (guchar **)&header);
+
+ if ((format != 8) || (nitems < sizeof (MotifTargetTableHeader)))
+ goto error;
+
+ header->n_lists = card16_to_host (header->n_lists, header->byte_order);
+ header->total_size = card32_to_host (header->total_size, header->byte_order);
+
+ XGetWindowProperty (gdk_display, motif_drag_window, motif_drag_targets_atom,
+ (sizeof(MotifTargetTableHeader)+3)/4,
+ (header->total_size - sizeof(MotifTargetTableHeader) + 3)/4,
+ FALSE,
+ motif_drag_targets_atom, &type, &format, &nitems,
+ &bytes_after, &target_bytes);
+
+ if ((format != 8) || (bytes_after != 0) ||
+ (nitems != header->total_size - sizeof(MotifTargetTableHeader)))
+ goto error;
+
+ motif_n_target_lists = header->n_lists;
+ motif_target_lists = g_new0 (GList *, motif_n_target_lists);
+
+ p = target_bytes;
+ for (i=0; i<header->n_lists; i++)
+ {
+ gint n_targets;
+ guint32 *targets;
+
+ if (p + sizeof(guint16) - target_bytes > nitems)
+ goto error;
+
+ n_targets = card16_to_host (*(gushort *)p, header->byte_order);
+ targets = (guint32 *)(p + sizeof(guint16));
+
+ p += sizeof(guint16) + n_targets * sizeof(guint32);
+ if (p - target_bytes > nitems)
+ goto error;
+
+ for (j=0; j<n_targets; j++)
+ motif_target_lists[i] =
+ g_list_prepend (motif_target_lists[i],
+ GUINT_TO_POINTER (card32_to_host (targets[j],
+ header->byte_order)));
+
+ motif_target_lists[i] = g_list_reverse (motif_target_lists[i]);
+ }
+
+ success = TRUE;
+
+ error:
+ if (header)
+ XFree (header);
+
+ if (target_bytes)
+ XFree (target_bytes);
+
+ if (!success)
+ {
+ if (motif_target_lists)
+ {
+ g_free (motif_target_lists);
+ motif_target_lists = NULL;
+ motif_n_target_lists = 0;
+ }
+ g_warning ("Error reading Motif target table\n");
+ }
+ }
+}
+
+static gint
+targets_sort_func (gconstpointer a, gconstpointer b)
+{
+ return (GPOINTER_TO_UINT (a) < GPOINTER_TO_UINT (b)) ?
+ -1 : ((GPOINTER_TO_UINT (a) > GPOINTER_TO_UINT (b)) ? 1 : 0);
+}
+
+/* Check if given (sorted) list is in the targets table */
+static gboolean
+motif_target_table_check (GList *sorted)
+{
+ GList *tmp_list1, *tmp_list2;
+ gint i;
+
+ for (i=0; i<motif_n_target_lists; i++)
+ {
+ tmp_list1 = motif_target_lists[i];
+ tmp_list2 = sorted;
+
+ while (tmp_list1 && tmp_list2)
+ {
+ if (tmp_list1->data != tmp_list2->data)
+ break;
+
+ tmp_list1 = tmp_list1->next;
+ tmp_list2 = tmp_list2->next;
+ }
+ if (!tmp_list1 && !tmp_list2) /* Found it */
+ return i;
+ }
+
+ return -1;
+}
+
+static gint
+motif_add_to_target_table (GList *targets)
+{
+ GList *sorted = NULL;
+ gint index = -1;
+ gint i;
+ GList *tmp_list;
+
+ /* make a sorted copy of the list */
- if(gdk_dnd.c->drag_pm_default)
+ while (targets)
+ {
+ sorted = g_list_insert_sorted (sorted, targets->data, targets_sort_func);
+ targets = targets->next;
+ }
+
+ /* First check if it is their already */
+
+ if (motif_target_lists)
+ index = motif_target_table_check (sorted);
+
+ /* We need to grab the server while doing this, to ensure
+ * atomiticity. Ugh
+ */
+
+ if (index < 0)
{
- /* We're doing pixmaps here... */
- GdkWindow *mypix, *opix;
- GdkPoint *myhotspot;
- gint itmp;
- guint masktmp;
- Window wtmp;
+ /* We need to make sure that it exists _before_ we grab the
+ * server, since we can't open a new connection after we
+ * grab the server.
+ */
+ motif_find_drag_window (TRUE);
+
+ XGrabServer(gdk_display);
+ motif_read_target_table();
+
+ /* Check again, in case it was added in the meantime */
- if(x == -2 && y == -2) /* Hide the cursors */
+ if (motif_target_lists)
+ index = motif_target_table_check (sorted);
+
+ if (index < 0)
{
- gdk_window_hide(gdk_dnd.c->drag_pm_ok);
- gdk_window_hide(gdk_dnd.c->drag_pm_default);
- GDK_NOTE(DND, g_message("Hiding both drag cursors\n"));
- return;
+ guint32 total_size = 0;
+ guchar *data;
+ guchar *p;
+ guint16 *p16;
+ guint32 *p32;
+ MotifTargetTableHeader *header;
+
+ if (!motif_target_lists)
+ {
+ motif_target_lists = g_new (GList *, 1);
+ motif_n_target_lists = 1;
+ }
+ else
+ {
+ motif_n_target_lists++;
+ motif_target_lists = g_realloc (motif_target_lists,
+ sizeof(GList *) * motif_n_target_lists);
+ }
+ motif_target_lists[motif_n_target_lists - 1] = sorted;
+ sorted = NULL;
+ index = motif_n_target_lists - 1;
+
+ total_size = sizeof (MotifTargetTableHeader);
+ for (i = 0; i < motif_n_target_lists ; i++)
+ total_size += sizeof(guint16) + sizeof(guint32) * g_list_length (motif_target_lists[i]);
+
+ data = g_malloc (total_size);
+
+ header = (MotifTargetTableHeader *)data;
+ p = data + sizeof(MotifTargetTableHeader);
+
+ header->byte_order = local_byte_order;
+ header->protocol_version = 0;
+ header->n_lists = motif_n_target_lists;
+ header->total_size = total_size;
+
+ for (i = 0; i < motif_n_target_lists ; i++)
+ {
+ guint16 count = 0;
+
+ p16 = (guint16 *)p;
+ p += sizeof(guint16);
+ p32 = (guint32 *)p;
+ tmp_list = motif_target_lists[i];
+ while (tmp_list)
+ {
+ *p32++ = GPOINTER_TO_UINT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ count++;
+ }
+ *p16 = count;
+ p = (guchar *)p32;
+ }
+
+ XChangeProperty (gdk_display, motif_drag_window,
+ motif_drag_targets_atom,
+ motif_drag_targets_atom,
+ 8, PropModeReplace,
+ data, total_size);
}
+ XUngrabServer(gdk_display);
+ }
+
+ g_list_free (sorted);
+ return index;
+}
+
+/* Translate flags */
+
+static void
+motif_dnd_translate_flags (GdkDragContext *context, guint16 flags)
+{
+ guint recommended_op = flags & 0x000f;
+ guint possible_ops = (flags & 0x0f0) >> 4;
+
+ switch (recommended_op)
+ {
+ case XmDROP_MOVE:
+ context->suggested_action = GDK_ACTION_MOVE;
+ break;
+ case XmDROP_COPY:
+ context->suggested_action = GDK_ACTION_COPY;
+ break;
+ case XmDROP_LINK:
+ context->suggested_action = GDK_ACTION_LINK;
+ break;
+ default:
+ context->suggested_action = GDK_ACTION_COPY;
+ break;
+ }
+
+ context->actions = 0;
+ if (possible_ops & XmDROP_MOVE)
+ context->actions |= GDK_ACTION_MOVE;
+ if (possible_ops & XmDROP_COPY)
+ context->actions |= GDK_ACTION_COPY;
+ if (possible_ops & XmDROP_LINK)
+ context->actions |= GDK_ACTION_LINK;
+}
+
+static guint16
+motif_dnd_get_flags (GdkDragContext *context)
+{
+ guint16 flags = 0;
+
+ switch (context->suggested_action)
+ {
+ case GDK_ACTION_MOVE:
+ flags = XmDROP_MOVE;
+ break;
+ case GDK_ACTION_COPY:
+ flags = XmDROP_COPY;
+ break;
+ case GDK_ACTION_LINK:
+ flags = XmDROP_LINK;
+ break;
+ default:
+ flags = XmDROP_NOOP;
+ break;
+ }
+
+ if (context->actions & GDK_ACTION_MOVE)
+ flags |= XmDROP_MOVE << 8;
+ if (context->actions & GDK_ACTION_COPY)
+ flags |= XmDROP_COPY << 8;
+ if (context->actions & GDK_ACTION_LINK)
+ flags |= XmDROP_LINK << 8;
+
+ return flags;
+}
+
+/* Source Side */
+
+static void
+motif_set_targets (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ MotifDragInitiatorInfo info;
+ gint i;
+ static GdkAtom motif_drag_initiator_info = GDK_NONE;
+
+ if (!motif_drag_initiator_info)
+ motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
+
+ info.byte_order = local_byte_order;
+ info.protocol_version = 0;
+
+ info.targets_index = motif_add_to_target_table (context->targets);
+
+ for (i=0; ; i++)
+ {
+ gchar buf[20];
+ g_snprintf(buf, 20, "_GDK_SELECTION_%d", i);
- if(x == -1 && y == -1) /* We're supposed to find it out for ourselves */
- XQueryPointer(gdk_display, gdk_root_window,
- &wtmp, &wtmp, &x, &y, &itmp, &itmp, &masktmp);
+ private->motif_selection = gdk_atom_intern (buf, FALSE);
+ if (!XGetSelectionOwner (gdk_display, private->motif_selection))
+ break;
+ }
+
+ info.selection_atom = private->motif_selection;
+
+ XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
+ GDK_WINDOW_XWINDOW (context->source_window),
+ private->motif_selection,
+ motif_drag_initiator_info, 8, PropModeReplace,
+ (guchar *)&info, sizeof (info));
+
+ private->motif_targets_set = 1;
+}
+
+gboolean
+motif_check_dest (Window win)
+{
+ gboolean retval = FALSE;
+ MotifDragReceiverInfo *info;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+
+ if (!motif_drag_receiver_info_atom)
+ motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ motif_drag_receiver_info_atom,
+ 0, (sizeof(*info)+3)/4, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ (guchar **)&info);
+
+ if (type != None)
+ {
+ if ((format == 8) && (nitems == sizeof(*info)))
+ {
+ if ((info->protocol_version == 0) &&
+ ((info->protocol_style == XmDRAG_PREFER_PREREGISTER) ||
+ (info->protocol_style == XmDRAG_PREFER_DYNAMIC) ||
+ (info->protocol_style == XmDRAG_DYNAMIC)))
+ retval = TRUE;
+ }
+ else
+ {
+ GDK_NOTE (DND,
+ g_warning ("Invalid Motif drag receiver property on window %ld\n", win));
+ }
+
+ XFree (info);
+ }
+
+ return retval;
+
+}
+
+static void
+motif_send_enter (GdkDragContext *context,
+ guint32 time)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmTOP_LEVEL_ENTER;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = 0;
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (!private->motif_targets_set)
+ motif_set_targets (context);
+
+ xev.xclient.data.l[3] = private->motif_selection;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+static void
+motif_send_leave (GdkDragContext *context,
+ guint32 time)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmTOP_LEVEL_LEAVE;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = 0;
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.l[2] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[3] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+static gboolean
+motif_send_motion (GdkDragContext *context,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ gboolean retval;
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = motif_dnd_get_flags (context);
+ xev.xclient.data.l[1] = time;
+
+ if (context->suggested_action != private->old_action)
+ {
+ xev.xclient.data.b[0] = XmOPERATION_CHANGED;
+
+ private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
+ retval = TRUE;
+ }
+ else
+ {
+ xev.xclient.data.b[0] = XmDRAG_MOTION;
+
+ xev.xclient.data.s[4] = x_root;
+ xev.xclient.data.s[5] = y_root;
- if(drag_ok)
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+ retval = FALSE;
+ }
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+
+ return retval;
+}
+
+static void
+motif_send_drop (GdkDragContext *context, guint32 time)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+
+ xev.xclient.data.b[0] = XmDROP_START;
+ xev.xclient.data.b[1] = local_byte_order;
+ xev.xclient.data.s[1] = motif_dnd_get_flags (context);
+ xev.xclient.data.l[1] = time;
+
+ xev.xclient.data.s[4] = private->last_x;
+ xev.xclient.data.s[5] = private->last_y;
+
+ xev.xclient.data.l[3] = private->motif_selection;
+ xev.xclient.data.l[4] = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+}
+
+/* Target Side */
+
+static gboolean
+motif_read_initiator_info (Window source_window,
+ Atom atom,
+ GList **targets,
+ GdkAtom *selection)
+{
+ GList *tmp_list;
+ static GdkAtom motif_drag_initiator_info = GDK_NONE;
+ GdkAtom type;
+ gint format;
+ gulong nitems;
+ gulong bytes_after;
+
+ MotifDragInitiatorInfo *initiator_info;
+
+ if (!motif_drag_initiator_info)
+ motif_drag_initiator_info = gdk_atom_intern ("_MOTIF_DRAG_INITIATOR_INFO", FALSE);
+
+ XGetWindowProperty (gdk_display, source_window, atom,
+ 0, sizeof(*initiator_info), FALSE,
+ motif_drag_initiator_info,
+ &type, &format, &nitems, &bytes_after,
+ (guchar **)&initiator_info);
+
+ if ((format != 8) || (nitems != sizeof (MotifDragInitiatorInfo)) || (bytes_after != 0))
+ {
+ g_warning ("Error reading initiator info\n");
+ return FALSE;
+ }
+
+ motif_read_target_table ();
+
+ if (initiator_info->targets_index >= motif_n_target_lists)
+ {
+ g_warning ("Invalid target index in TOP_LEVEL_ENTER MESSAGE");
+ XFree (initiator_info);
+ return GDK_FILTER_REMOVE;
+ }
+
+ tmp_list = g_list_last (motif_target_lists[initiator_info->targets_index]);
+
+ *targets = NULL;
+ while (tmp_list)
+ {
+ *targets = g_list_prepend (*targets,
+ tmp_list->data);
+ tmp_list = tmp_list->prev;
+ }
+
+#ifdef G_ENABLE_DEBUG
+ if (gdk_debug_flags & GDK_DEBUG_DND)
+ print_target_list (*targets);
+#endif /* G_ENABLE_DEBUG */
+
+ *selection = initiator_info->selection_atom;
+
+ XFree (initiator_info);
+
+ return TRUE;
+}
+
+static GdkDragContext *
+motif_drag_context_new (GdkWindow *dest_window,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom)
+{
+ GdkDragContext *new_context;
+ GdkDragContextPrivate *private;
+
+ /* FIXME, current_dest_drag really shouldn't be NULL'd
+ * if we error below.
+ */
+ if (current_dest_drag != NULL)
+ {
+ if (timestamp >= current_dest_drag->start_time)
{
- GDK_NOTE(DND, g_message("Switching to drag_ok cursor\n"));
- mypix = gdk_dnd.c->drag_pm_ok;
- opix = gdk_dnd.c->drag_pm_default;
- myhotspot = &gdk_dnd.c->ok_hotspot;
+ gdk_drag_context_unref (current_dest_drag);
+ current_dest_drag = NULL;
}
else
+ return NULL;
+ }
+
+ new_context = gdk_drag_context_new ();
+ private = (GdkDragContextPrivate *)new_context;
+
+ new_context->protocol = GDK_DRAG_PROTO_MOTIF;
+ new_context->is_source = FALSE;
+
+ new_context->source_window = gdk_window_lookup (source_window);
+ if (new_context->source_window)
+ gdk_window_ref (new_context->source_window);
+ else
+ {
+ new_context->source_window = gdk_window_foreign_new (source_window);
+ if (!new_context->source_window)
{
- GDK_NOTE(DND, g_message("Switching to drag_default cursor\n"));
- mypix = gdk_dnd.c->drag_pm_default;
- opix = gdk_dnd.c->drag_pm_ok;
- myhotspot = &gdk_dnd.c->default_hotspot;
+ gdk_drag_context_unref (new_context);
+ return NULL;
}
- gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
- if(change_made)
+ }
+
+ new_context->dest_window = dest_window;
+ gdk_window_ref (dest_window);
+ new_context->start_time = timestamp;
+
+ if (!motif_read_initiator_info(source_window,
+ atom,
+ &new_context->targets,
+ &private->motif_selection))
+ {
+ gdk_drag_context_unref (new_context);
+ return NULL;
+ }
+
+ return new_context;
+}
+
+/*
+ * The MOTIF drag protocol has no real provisions for distinguishing
+ * multiple simultaneous drops. If the sources grab the pointer
+ * when doing drags, that shouldn't happen, in any case. If it
+ * does, we can't do much except hope for the best.
+ */
+
+static GdkFilterReturn
+motif_top_level_enter (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom)
+{
+ GdkDragContext *new_context;
+
+ GDK_NOTE(DND, g_message ("Motif DND top level enter: flags: %#4x time: %d source_widow: %#4x atom: %d",
+ flags, timestamp, source_window, atom));
+
+ new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
+ if (!new_context)
+ return GDK_FILTER_REMOVE;
+
+ event->dnd.type = GDK_DRAG_ENTER;
+ event->dnd.context = new_context;
+ gdk_drag_context_ref (new_context);
+
+ current_dest_drag = new_context;
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+GdkFilterReturn
+motif_top_level_leave (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GDK_NOTE(DND, g_message ("Motif DND top level leave: flags: %#4x time: %d",
+ flags, timestamp));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ event->dnd.type = GDK_DRAG_LEAVE;
+ /* Pass ownership of context to the event */
+ event->dnd.context = current_dest_drag;
+
+ current_dest_drag = NULL;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_motion (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ gint16 x_root,
+ gint16 y_root)
+{
+ GdkDragContextPrivate *private;
+
+ GDK_NOTE(DND, g_message ("Motif DND motion: flags: %#4x time: %d (%d, %d)",
+ flags, timestamp, x_root, y_root));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = timestamp;
+
+ motif_dnd_translate_flags (current_dest_drag, flags);
+
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ private->last_x = x_root;
+ private->last_y = y_root;
+
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_operation_changed (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GdkDragContextPrivate *private;
+
+ GDK_NOTE(DND, g_message ("Motif DND operation changed: flags: %#4x time: %d",
+ flags, timestamp));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_MOTIF) &&
+ (timestamp >= current_dest_drag->start_time))
+ {
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.send_event = FALSE;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = timestamp;
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ motif_dnd_translate_flags (current_dest_drag, flags);
+
+ event->dnd.x_root = private->last_x;
+ event->dnd.y_root = private->last_y;
+
+ private->drag_status = GDK_DRAG_STATUS_ACTION_WAIT;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_drop_start (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp,
+ guint32 source_window,
+ guint32 atom,
+ gint16 x_root,
+ gint16 y_root)
+{
+ GdkDragContext *new_context;
+
+
+ GDK_NOTE(DND, g_message ("Motif DND drop start: flags: %#4x time: %d (%d, %d) source_widow: %#4x atom: %d",
+ flags, timestamp, x_root, y_root, source_window, atom));
+
+ new_context = motif_drag_context_new (event->any.window, timestamp, source_window, atom);
+ if (!new_context)
+ return GDK_FILTER_REMOVE;
+
+ motif_dnd_translate_flags (new_context, flags);
+
+ event->dnd.type = GDK_DROP_START;
+ event->dnd.context = new_context;
+ event->dnd.time = timestamp;
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ gdk_drag_context_ref (new_context);
+ current_dest_drag = new_context;
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+GdkFilterReturn
+motif_drag_status (GdkEvent *event,
+ guint16 flags,
+ guint32 timestamp)
+{
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("Motif status message: flags %x", flags));
+
+ context = gdk_drag_context_find (TRUE,
+ GDK_WINDOW_XWINDOW (event->any.window),
+ None);
+
+ if (context)
+ {
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ event->dnd.type = GDK_DRAG_STATUS;
+ event->dnd.send_event = FALSE;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ event->dnd.time = timestamp;
+
+ if ((flags & 0x00f0) >> 4 == XmDROP_SITE_VALID)
+ {
+ switch (flags & 0x000f)
+ {
+ case XmDROP_NOOP:
+ context->action = 0;
+ break;
+ case XmDROP_MOVE:
+ context->action = GDK_ACTION_MOVE;
+ break;
+ case XmDROP_COPY:
+ context->action = GDK_ACTION_COPY;
+ break;
+ case XmDROP_LINK:
+ context->action = GDK_ACTION_LINK;
+ break;
+ }
+ }
+ else
+ context->action = 0;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ return GDK_FILTER_REMOVE;
+}
+
+GdkFilterReturn
+motif_dnd_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ XClientMessageEvent *xce = &xevent->xclient;
+
+ guint8 reason;
+ gchar byte_order;
+ guint16 flags;
+ guint32 timestamp;
+ guint32 source_window;
+ GdkAtom atom;
+ gint16 x_root, y_root;
+ gboolean is_reply;
+
+ /* First read some fields common to all Motif DND messages */
+
+ reason = xce->data.b[0];
+ byte_order = xce->data.b[1];
+ flags = card16_to_host (xce->data.s[1], byte_order);
+ timestamp = card32_to_host (xce->data.l[1], byte_order);
+
+ is_reply = ((reason & 0x80) != 0);
+
+ switch (reason & 0x7f)
+ {
+ case XmTOP_LEVEL_ENTER:
+ source_window = card32_to_host (xce->data.l[2], byte_order);
+ atom = card32_to_host (xce->data.l[3], byte_order);
+ return motif_top_level_enter (event, flags, timestamp, source_window, atom);
+ case XmTOP_LEVEL_LEAVE:
+ return motif_top_level_leave (event, flags, timestamp);
+
+ case XmDRAG_MOTION:
+ x_root = card16_to_host (xce->data.s[4], byte_order);
+ y_root = card16_to_host (xce->data.s[5], byte_order);
+
+ if (!is_reply)
+ return motif_motion (event, flags, timestamp, x_root, y_root);
+ else
+ return motif_drag_status (event, flags, timestamp);
+
+ case XmDROP_SITE_ENTER:
+ return motif_drag_status (event, flags, timestamp);
+
+ case XmDROP_SITE_LEAVE:
+ return motif_drag_status (event,
+ XmNO_DROP_SITE << 8 | XmDROP_NOOP,
+ timestamp);
+ case XmDROP_START:
+ x_root = card16_to_host (xce->data.s[4], byte_order);
+ y_root = card16_to_host (xce->data.s[5], byte_order);
+ atom = card32_to_host (xce->data.l[3], byte_order);
+ source_window = card32_to_host (xce->data.l[4], byte_order);
+
+ if (!is_reply)
+ return motif_drop_start (event, flags, timestamp, source_window, atom, x_root, y_root);
+
+ break;
+ case XmOPERATION_CHANGED:
+ if (!is_reply)
+ return motif_operation_changed (event, flags, timestamp);
+ else
+ return motif_drag_status (event, flags, timestamp);
+
+ break;
+ /* To the best of my knowledge, these next two messages are
+ * not part of the protocol, though they are defined in
+ * the header files.
+ */
+ case XmDROP_FINISH:
+ case XmDRAG_DROP_FINISH:
+ break;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+/*************************************************************
+ ***************************** XDND **************************
+ *************************************************************/
+
+/* Utility functions */
+
+static struct {
+ gchar *name;
+ GdkAtom atom;
+ GdkDragAction action;
+} xdnd_actions_table[] = {
+ { "XdndActionCopy", GDK_NONE, GDK_ACTION_COPY },
+ { "XdndActionMove", GDK_NONE, GDK_ACTION_MOVE },
+ { "XdndActionLink", GDK_NONE, GDK_ACTION_LINK },
+ { "XdndActionAsk", GDK_NONE, GDK_ACTION_ASK },
+ { "XdndActionPrivate", GDK_NONE, GDK_ACTION_COPY },
+ };
+
+static const gint xdnd_n_actions = sizeof(xdnd_actions_table) / sizeof(xdnd_actions_table[0]);
+static gboolean xdnd_actions_initialized = FALSE;
+
+static void
+xdnd_initialize_actions (void)
+{
+ gint i;
+
+ xdnd_actions_initialized = TRUE;
+ for (i=0; i < xdnd_n_actions; i++)
+ xdnd_actions_table[i].atom = gdk_atom_intern (xdnd_actions_table[i].name, FALSE);
+}
+
+static GdkDragAction
+xdnd_action_from_atom (GdkAtom atom)
+{
+ gint i;
+
+ if (!xdnd_actions_initialized)
+ xdnd_initialize_actions();
+
+ for (i=0; i<xdnd_n_actions; i++)
+ if (atom == xdnd_actions_table[i].atom)
+ return xdnd_actions_table[i].action;
+
+ return 0;
+}
+
+static GdkAtom
+xdnd_action_to_atom (GdkDragAction action)
+{
+ gint i;
+
+ if (!xdnd_actions_initialized)
+ xdnd_initialize_actions();
+
+ for (i=0; i<xdnd_n_actions; i++)
+ if (action == xdnd_actions_table[i].action)
+ return xdnd_actions_table[i].atom;
+
+ return GDK_NONE;
+}
+
+static GdkAtom xdnd_aware_atom = GDK_NONE;
+
+/* Source side */
+
+static GdkFilterReturn
+xdnd_status_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 dest_window = xevent->xclient.data.l[0];
+ guint32 flags = xevent->xclient.data.l[1];
+ GdkAtom action = xevent->xclient.data.l[4];
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("XdndStatus: dest_window: %#x action: %ld",
+ dest_window, action));
+
+
+ context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
+ if (context)
+ {
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ if (private->drag_status == GDK_DRAG_STATUS_MOTION_WAIT)
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ event->dnd.send_event = FALSE;
+ event->dnd.type = GDK_DRAG_STATUS;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ event->dnd.time = GDK_CURRENT_TIME; /* FIXME? */
+ if (!(action != 0) != !(flags & 1))
+ {
+ GDK_NOTE (DND,
+ g_warning ("Received status event with flags not corresponding to action!\n"));
+ action = 0;
+ }
+
+ context->action = xdnd_action_from_atom (action);
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_finished_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 dest_window = xevent->xclient.data.l[0];
+ GdkDragContext *context;
+
+ GDK_NOTE (DND,
+ g_message ("XdndFinished: dest_window: %#x", dest_window));
+
+ context = gdk_drag_context_find (TRUE, xevent->xclient.window, dest_window);
+ if (context)
+ {
+ event->dnd.type = GDK_DROP_FINISHED;
+ event->dnd.context = context;
+ gdk_drag_context_ref (context);
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static void
+xdnd_set_targets (GdkDragContext *context)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ GdkAtom *typelist;
+ GList *tmp_list = context->targets;
+ gint i;
+ gint n_targets = g_list_length (context->targets);
+
+ typelist = g_new (GdkAtom, n_targets);
+ i = 0;
+ while (tmp_list)
+ {
+ typelist[i] = GPOINTER_TO_INT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ i++;
+ }
+
+ XChangeProperty (GDK_WINDOW_XDISPLAY (context->source_window),
+ GDK_WINDOW_XWINDOW (context->source_window),
+ gdk_atom_intern ("XdndTypeList", FALSE),
+ XA_ATOM, 32, PropModeReplace,
+ (guchar *)typelist, n_targets);
+
+ private->xdnd_targets_set = 1;
+}
+
+static void
+xdnd_send_enter (GdkDragContext *context)
+{
+ XEvent xev;
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndEnter", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = (3 << 24); /* version */
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!private->xdnd_selection)
+ private->xdnd_selection = gdk_atom_intern ("XdndSelection", FALSE);
+
+ if (g_list_length (context->targets) > 3)
+ {
+ if (!private->xdnd_targets_set)
+ xdnd_set_targets (context);
+ xev.xclient.data.l[1] |= 1;
+ }
+ else
+ {
+ GList *tmp_list = context->targets;
+ gint i = 2;
+
+ while (tmp_list)
+ {
+ xev.xclient.data.l[i] = GPOINTER_TO_INT (tmp_list->data);
+ tmp_list = tmp_list->next;
+ i++;
+ }
+ }
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_leave (GdkDragContext *context)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndLeave", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_drop (GdkDragContext *context, guint32 time)
+{
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndDrop", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = time;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+static void
+xdnd_send_motion (GdkDragContext *context,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndPosition", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->source_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = (x_root << 16) | y_root;
+ xev.xclient.data.l[3] = time;
+ xev.xclient.data.l[4] = xdnd_action_to_atom (action);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->dest_window),
+ FALSE, 0, &xev))
+ {
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->dest_window)));
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+ private->drag_status = GDK_DRAG_STATUS_MOTION_WAIT;
+}
+
+static gboolean
+xdnd_check_dest (Window win)
+{
+ gboolean retval = FALSE;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ GdkAtom *version;
+
+ if (!xdnd_aware_atom)
+ xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
+
+ XGetWindowProperty (gdk_display, win,
+ xdnd_aware_atom, 0,
+ 1, False, AnyPropertyType,
+ &type, &format, &nitems, &after,
+ (guchar **)&version);
+
+ if (type != None)
+ {
+ if ((format == 32) && (nitems == 1))
+ {
+ if (*version == 3)
+ retval = TRUE;
+ }
+ else
+ GDK_NOTE (DND,
+ g_warning ("Invalid XdndAware property on window %ld\n", win));
+
+ XFree (version);
+ }
+
+ return retval;
+}
+
+/* Target side */
+
+static GdkFilterReturn
+xdnd_enter_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ GdkDragContext *new_context;
+ gint i;
+
+ guint32 source_window = xevent->xclient.data.l[0];
+ gboolean get_types = ((xevent->xclient.data.l[1] & 1) != 0);
+ gint version = (xevent->xclient.data.l[1] & 0xff000000) >> 24;
+
+ GDK_NOTE (DND,
+ g_message ("XdndEnter: source_window: %#x, version: %#x",
+ source_window, version));
+
+ if (version != 3)
+ {
+ /* Old source ignore */
+ GDK_NOTE (DND, g_message ("Ignored old XdndEnter message"));
+ return GDK_FILTER_REMOVE;
+ }
+
+ if (current_dest_drag != NULL)
+ {
+ gdk_drag_context_unref (current_dest_drag);
+ current_dest_drag = NULL;
+ }
+
+ new_context = gdk_drag_context_new ();
+ new_context->protocol = GDK_DRAG_PROTO_XDND;
+ new_context->is_source = FALSE;
+
+ new_context->source_window = gdk_window_lookup (source_window);
+ if (new_context->source_window)
+ gdk_window_ref (new_context->source_window);
+ else
+ {
+ new_context->source_window = gdk_window_foreign_new (source_window);
+ if (!new_context->source_window)
+ {
+ gdk_drag_context_unref (new_context);
+ return GDK_FILTER_REMOVE;
+ }
+ }
+ new_context->dest_window = event->any.window;
+ gdk_window_ref (new_context->dest_window);
+
+ new_context->targets = NULL;
+ if (get_types)
+ {
+ Atom type;
+ int format;
+ gulong nitems, after;
+ Atom *data;
+
+ XGetWindowProperty (GDK_WINDOW_XDISPLAY (event->any.window),
+ source_window,
+ gdk_atom_intern ("XdndTypeList", FALSE), 0, 65536,
+ False, XA_ATOM, &type, &format, &nitems,
+ &after, (guchar **)&data);
+
+ if ((format != 32) || (type != XA_ATOM))
+ {
+ gdk_drag_context_unref (new_context);
+ return GDK_FILTER_REMOVE;
+ }
+
+ for (i=0; i<nitems; i++)
+ new_context->targets = g_list_append (new_context->targets,
+ GUINT_TO_POINTER (data[i]));
+
+ XFree(data);
+ }
+ else
+ {
+ for (i=0; i<3; i++)
+ if (xevent->xclient.data.l[2+i])
+ new_context->targets = g_list_append (new_context->targets,
+ GUINT_TO_POINTER (xevent->xclient.data.l[2+i]));
+ }
+
+#ifdef G_ENABLE_DEBUG
+ if (gdk_debug_flags & GDK_DEBUG_DND)
+ print_target_list (new_context->targets);
+#endif /* G_ENABLE_DEBUG */
+
+ event->dnd.type = GDK_DRAG_ENTER;
+ event->dnd.context = new_context;
+ gdk_drag_context_ref (new_context);
+
+ current_dest_drag = new_context;
+ ((GdkDragContextPrivate *)new_context)->xdnd_selection =
+ gdk_atom_intern ("XdndSelection", FALSE);
+
+ return GDK_FILTER_TRANSLATE;
+}
+
+static GdkFilterReturn
+xdnd_leave_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+
+ GDK_NOTE (DND,
+ g_message ("XdndLeave: source_window: %#x",
+ source_window));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ event->dnd.type = GDK_DRAG_LEAVE;
+ /* Pass ownership of context to the event */
+ event->dnd.context = current_dest_drag;
+
+ current_dest_drag = NULL;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_position_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+ gint16 x_root = xevent->xclient.data.l[2] >> 16;
+ gint16 y_root = xevent->xclient.data.l[2] & 0xffff;
+ guint32 time = xevent->xclient.data.l[3];
+ GdkAtom action = xevent->xclient.data.l[4];
+
+ GDK_NOTE (DND,
+ g_message ("XdndPosition: source_window: %#x position: (%d, %d) time: %d action: %ld",
+ source_window, x_root, y_root, time, action));
+
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ event->dnd.type = GDK_DRAG_MOTION;
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = time;
+
+ current_dest_drag->suggested_action = xdnd_action_from_atom (action);
+
+ event->dnd.x_root = x_root;
+ event->dnd.y_root = y_root;
+
+ ((GdkDragContextPrivate *)current_dest_drag)->last_x = x_root;
+ ((GdkDragContextPrivate *)current_dest_drag)->last_y = y_root;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+static GdkFilterReturn
+xdnd_drop_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+ guint32 source_window = xevent->xclient.data.l[0];
+ guint32 time = xevent->xclient.data.l[2];
+
+ GDK_NOTE (DND,
+ g_message ("XdndDrop: source_window: %#x time: %d",
+ source_window, time));
+
+ if ((current_dest_drag != NULL) &&
+ (current_dest_drag->protocol == GDK_DRAG_PROTO_XDND) &&
+ (GDK_WINDOW_XWINDOW (current_dest_drag->source_window) == source_window))
+ {
+ GdkDragContextPrivate *private;
+ private = (GdkDragContextPrivate *)current_dest_drag;
+
+ event->dnd.type = GDK_DROP_START;
+
+ event->dnd.context = current_dest_drag;
+ gdk_drag_context_ref (current_dest_drag);
+
+ event->dnd.time = time;
+ event->dnd.x_root = private->last_x;
+ event->dnd.y_root = private->last_y;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
+/*************************************************************
+ ************************** Public API ***********************
+ *************************************************************/
+
+void
+gdk_dnd_init (void)
+{
+ init_byte_order();
+
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE),
+ motif_dnd_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndEnter", FALSE),
+ xdnd_enter_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndLeave", FALSE),
+ xdnd_leave_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndPosition", FALSE),
+ xdnd_position_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndStatus", FALSE),
+ xdnd_status_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndFinished", FALSE),
+ xdnd_finished_filter, NULL);
+ gdk_add_client_message_filter (
+ gdk_atom_intern ("XdndDrop", FALSE),
+ xdnd_drop_filter, NULL);
+}
+
+/* Source side */
+
+static void
+gdk_drag_do_leave (GdkDragContext *context, guint32 time)
+{
+ if (context->dest_window)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_leave (context, time);
+ break;
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_leave (context);
+ break;
+ case GDK_DRAG_PROTO_ROOTWIN:
+ break;
+ }
+
+ gdk_window_unref (context->dest_window);
+ context->dest_window = NULL;
+ }
+}
+
+GdkDragContext *
+gdk_drag_begin (GdkWindow *window,
+ GList *targets,
+ GdkDragAction actions)
+{
+ GList *tmp_list;
+ GdkDragContext *new_context;
+
+ g_return_val_if_fail (window != NULL, NULL);
+
+ new_context = gdk_drag_context_new ();
+ new_context->is_source = TRUE;
+ new_context->source_window = window;
+ gdk_window_ref (window);
+
+ tmp_list = g_list_last (targets);
+ new_context->targets = NULL;
+ while (tmp_list)
+ {
+ new_context->targets = g_list_prepend (new_context->targets,
+ tmp_list->data);
+ tmp_list = tmp_list->prev;
+ }
+
+ new_context->actions = actions;
+
+ return new_context;
+}
+
+gboolean
+gdk_drag_get_protocol (guint32 xid,
+ GdkDragProtocol *protocol)
+{
+ if (xdnd_check_dest (xid))
+ {
+ *protocol = GDK_DRAG_PROTO_XDND;
+ GDK_NOTE (DND, g_message ("Entering dnd window %#x\n", xid));
+ return TRUE;
+ }
+ else if (motif_check_dest (xid))
+ {
+ *protocol = GDK_DRAG_PROTO_MOTIF;
+ GDK_NOTE (DND, g_message ("Entering motif window %#x\n", xid));
+ return TRUE;
+ }
+ else
+ {
+ /* Check if this is a root window */
+
+ gboolean rootwin = FALSE;
+ gint old_warnings = gdk_error_warnings;
+ Atom type = None;
+ int format;
+ unsigned long nitems, after;
+ unsigned char *data;
+
+ if (xid == gdk_root_window)
+ rootwin = TRUE;
+
+ if (!rootwin)
+ {
+ gdk_error_code = 0;
+
+ XGetWindowProperty (gdk_display, xid,
+ gdk_atom_intern ("ENLIGHTENMENT_DESKTOP", FALSE),
+ 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &after, &data);
+ if ((gdk_error_code == 0) && type != None)
+ {
+ XFree (data);
+ rootwin = TRUE;
+ }
+ }
+
+ /* Until I find out what window manager the next one is for,
+ * I'm leaving it commented out. It's supported in the
+ * xscreensaver sources, though.
+ */
+#if 0
+ if (!rootwin)
{
- GDK_NOTE(DND, g_message("Cursors switched, hide & show\n"));
- gdk_window_hide(opix);
+ gdk_error_code = 0;
+
+ XGetWindowProperty (gdk_display, win,
+ gdk_atom_intern ("__SWM_VROOT", FALSE),
+ 0, 0, False, AnyPropertyType,
+ &type, &format, &nitems, &data);
+ if ((gdk_error_code == 0) && type != None)
+ rootwin = TRUE;
+ }
+#endif
+
+ gdk_error_warnings = old_warnings;
+
+ if (rootwin)
+ {
+ *protocol = GDK_DRAG_PROTO_ROOTWIN;
+ return TRUE;
}
- gdk_window_move(mypix, x - myhotspot->x, y - myhotspot->y);
- if (change_made)
- {
- gdk_window_show(mypix); /* There ought to be a way to know if
- a window is already mapped etc. */
- }
}
- else if(change_made)
+
+ return FALSE;
+}
+
+void
+gdk_drag_find_window (GdkDragContext *context,
+ GdkWindow *drag_window,
+ gint x_root,
+ gint y_root,
+ GdkWindow **dest_window,
+ GdkDragProtocol *protocol)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+ Window dest;
+
+ if (!private->window_cache)
+ private->window_cache = gdk_window_cache_new();
+
+ dest = get_client_window_at_coords (private->window_cache,
+ drag_window ?
+ GDK_WINDOW_XWINDOW (drag_window) : GDK_NONE,
+ x_root, y_root);
+
+ if (private->dest_xid != dest)
{
- Cursor c;
- /* Move cursors around */
- if(drag_ok)
- c = gdk_dnd.c->gdk_cursor_dragok;
+ private->dest_xid = dest;
+
+ /* Check if new destination accepts drags, and which protocol */
+
+ if (gdk_drag_get_protocol (dest, protocol))
+ {
+ *dest_window = gdk_window_lookup (dest);
+ if (*dest_window)
+ gdk_window_ref (*dest_window);
+ else
+ *dest_window = gdk_window_foreign_new (dest);
+ }
else
- c = gdk_dnd.c->gdk_cursor_dragdefault;
- XChangeActivePointerGrab (gdk_display,
- ButtonMotionMask |
- ButtonPressMask |
- ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask,
- c,
- CurrentTime);
+ *dest_window = NULL;
+ }
+ else
+ {
+ *dest_window = context->dest_window;
+ if (*dest_window)
+ gdk_window_ref (*dest_window);
+ *protocol = context->protocol;
}
}
+
+gboolean
+gdk_drag_motion (GdkDragContext *context,
+ GdkWindow *dest_window,
+ GdkDragProtocol protocol,
+ gint x_root,
+ gint y_root,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private = (GdkDragContextPrivate *)context;
+
+ if (context->dest_window != dest_window)
+ {
+ GdkEvent temp_event;
+
+ /* Send a leave to the last destination */
+ gdk_drag_do_leave (context, time);
+ private->drag_status = GDK_DRAG_STATUS_DRAG;
+
+ /* Check if new destination accepts drags, and which protocol */
+
+ if (dest_window)
+ {
+ context->dest_window = dest_window;
+ gdk_window_ref (context->dest_window);
+ context->protocol = protocol;
+
+ switch (protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_enter (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_enter (context);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ break;
+ }
+ private->old_action = action;
+ context->suggested_action = action;
+ }
+ else
+ {
+ context->dest_window = NULL;
+ context->action = 0;
+ }
+
+ /* Push a status event, to let the client know that
+ * the drag changed
+ */
+
+ temp_event.dnd.type = GDK_DRAG_STATUS;
+ temp_event.dnd.window = context->source_window;
+ /* We use this to signal a synthetic status. Perhaps
+ * we should use an extra field...
+ */
+ temp_event.dnd.send_event = TRUE;
+
+ temp_event.dnd.context = context;
+ temp_event.dnd.time = time;
+
+ gdk_event_put (&temp_event);
+ }
+ else
+ {
+ private->old_action = context->suggested_action;
+ context->suggested_action = action;
+ }
+
+ /* Send a drag-motion event */
+
+ private->last_x = x_root;
+ private->last_y = y_root;
+
+ if (context->dest_window)
+ {
+ if (private->drag_status == GDK_DRAG_STATUS_DRAG)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_motion (context, x_root, y_root, action, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_motion (context, x_root, y_root, action, time);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ {
+ GdkEvent temp_event;
+
+ if (g_list_find (context->targets,
+ GUINT_TO_POINTER (gdk_atom_intern ("application/x-rootwin-drop", FALSE))))
+ context->action = context->suggested_action;
+ else
+ context->action = 0;
+
+ temp_event.dnd.type = GDK_DRAG_STATUS;
+ temp_event.dnd.window = context->source_window;
+ temp_event.dnd.send_event = FALSE;
+ temp_event.dnd.context = context;
+ temp_event.dnd.time = time;
+
+ gdk_event_put (&temp_event);
+ }
+ break;
+ }
+ }
+ else
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
+void
+gdk_drag_drop (GdkDragContext *context,
+ guint32 time)
+{
+ if (context->dest_window)
+ {
+ switch (context->protocol)
+ {
+ case GDK_DRAG_PROTO_MOTIF:
+ motif_send_leave (context, time);
+ motif_send_drop (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_XDND:
+ xdnd_send_drop (context, time);
+ break;
+
+ case GDK_DRAG_PROTO_ROOTWIN:
+ g_warning ("Drops for GDK_DRAG_PROTO_ROOTWIN must be handled internally");
+ break;
+ }
+ }
+}
+
+void
+gdk_drag_abort (GdkDragContext *context,
+ guint32 time)
+{
+ gdk_drag_do_leave (context, time);
+}
+
+/* Destination side */
+
+void
+gdk_drag_status (GdkDragContext *context,
+ GdkDragAction action,
+ guint32 time)
+{
+ GdkDragContextPrivate *private;
+ XEvent xev;
+
+ g_return_if_fail (context != 0);
+
+ private = (GdkDragContextPrivate *)context;
+
+ context->action = action;
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ if (private->drag_status == GDK_DRAG_STATUS_ACTION_WAIT)
+ {
+ xev.xclient.data.b[0] = XmOPERATION_CHANGED | 0x80;
+ }
+ else
+ {
+ if ((action != 0) != (private->old_action != 0))
+ {
+ if (action != 0)
+ xev.xclient.data.b[0] = XmDROP_SITE_ENTER | 0x80;
+ else
+ xev.xclient.data.b[0] = XmDROP_SITE_LEAVE | 0x80;
+ }
+ else
+ xev.xclient.data.b[0] = XmDRAG_MOTION | 0x80;
+ }
+
+ xev.xclient.data.b[1] = local_byte_order;
+
+ switch (action)
+ {
+ case GDK_ACTION_MOVE:
+ xev.xclient.data.s[1] = XmDROP_MOVE;
+ break;
+ case GDK_ACTION_COPY:
+ xev.xclient.data.s[1] = XmDROP_COPY;
+ break;
+ case GDK_ACTION_LINK:
+ xev.xclient.data.s[1] = XmDROP_LINK;
+ break;
+ default:
+ xev.xclient.data.s[1] = XmDROP_NOOP;
+ break;
+ }
+
+ if (action)
+ xev.xclient.data.s[1] |= (XmDROP_SITE_VALID << 4);
+ else
+ xev.xclient.data.s[1] |= (XmNO_DROP_SITE << 4);
+
+ xev.xclient.data.l[1] = time;
+ xev.xclient.data.s[4] = private->last_x;
+ xev.xclient.data.s[5] = private->last_y;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+ else if (context->protocol == GDK_DRAG_PROTO_XDND)
+ {
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndStatus", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[1] = (action != 0) ? (2 | 1) : 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = xdnd_action_to_atom (action);
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+
+ private->old_action = action;
+}
+
+void
+gdk_drop_reply (GdkDragContext *context,
+ gboolean ok,
+ guint32 time)
+{
+ GdkDragContextPrivate *private;
+
+ g_return_if_fail (context != 0);
+
+ private = (GdkDragContextPrivate *)context;
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("_MOTIF_DRAG_AND_DROP_MESSAGE", FALSE);
+ xev.xclient.format = 8;
+
+ xev.xclient.data.b[0] = XmDROP_START | 0x80;
+ xev.xclient.data.b[1] = local_byte_order;
+ if (ok)
+ xev.xclient.data.s[2] = XmDROP_COPY |
+ (XmDROP_SITE_VALID << 4) |
+ (XmDROP_NOOP << 8) |
+ (XmDROP << 12);
+ else
+ xev.xclient.data.s[2] = XmDROP_NOOP |
+ (XmNO_DROP_SITE << 4) |
+ (XmDROP_NOOP << 8) |
+ (XmDROP_CANCEL << 12);
+ xev.xclient.data.s[2] = private->last_x;
+ xev.xclient.data.s[3] = private->last_y;
+
+ gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev);
+ }
+}
+
+void
+gdk_drop_finish (GdkDragContext *context,
+ gboolean success,
+ guint32 time)
+{
+ if (context->protocol == GDK_DRAG_PROTO_XDND)
+ {
+ XEvent xev;
+
+ xev.xclient.type = ClientMessage;
+ xev.xclient.message_type = gdk_atom_intern ("XdndFinished", FALSE);
+ xev.xclient.format = 32;
+ xev.xclient.window = GDK_WINDOW_XWINDOW (context->source_window);
+
+ xev.xclient.data.l[0] = GDK_WINDOW_XWINDOW (context->dest_window);
+ xev.xclient.data.l[1] = 0;
+ xev.xclient.data.l[2] = 0;
+ xev.xclient.data.l[3] = 0;
+ xev.xclient.data.l[4] = 0;
+
+ if (!gdk_send_xevent (GDK_WINDOW_XWINDOW (context->source_window),
+ FALSE, 0, &xev))
+ GDK_NOTE (DND,
+ g_message ("Send event to %lx failed",
+ GDK_WINDOW_XWINDOW (context->source_window)));
+ }
+}
+
+
+void
+gdk_window_register_dnd (GdkWindow *window)
+{
+ static guint32 xdnd_version = 3;
+
+ MotifDragReceiverInfo info;
+
+ /* Set Motif drag receiver information property */
+
+ if (!motif_drag_receiver_info_atom)
+ motif_drag_receiver_info_atom = gdk_atom_intern ("_MOTIF_DRAG_RECEIVER_INFO", FALSE);
+
+ info.byte_order = local_byte_order;
+ info.protocol_version = 0;
+ info.protocol_style = XmDRAG_DYNAMIC;
+ info.proxy_window = GDK_NONE;
+ info.num_drop_sites = 0;
+ info.total_size = sizeof(info);
+
+ XChangeProperty (gdk_display, GDK_WINDOW_XWINDOW (window),
+ motif_drag_receiver_info_atom,
+ motif_drag_receiver_info_atom,
+ 8, PropModeReplace,
+ (guchar *)&info,
+ sizeof (info));
+
+ /* Set XdndAware */
+
+ if (!xdnd_aware_atom)
+ xdnd_aware_atom = gdk_atom_intern ("XdndAware", FALSE);
+
+ /* The property needs to be of type XA_ATOM, not XA_INTEGER. Blech */
+ XChangeProperty (GDK_WINDOW_XDISPLAY (window),
+ GDK_WINDOW_XWINDOW (window),
+ xdnd_aware_atom, XA_ATOM,
+ 32, PropModeReplace,
+ (guchar *)&xdnd_version,
+ sizeof (xdnd_version));
+}
+
+/*************************************************************
+ * gdk_drag_get_selection:
+ * Returns the selection atom for the current source window
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+GdkAtom
+gdk_drag_get_selection (GdkDragContext *context)
+{
+ g_return_val_if_fail (context != NULL, GDK_NONE);
+
+ if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ return ((GdkDragContextPrivate *)context)->motif_selection;
+ else if (context->protocol == GDK_DRAG_PROTO_XDND)
+ return ((GdkDragContextPrivate *)context)->xdnd_selection;
+ else
+ return GDK_NONE;
+}
+
diff --git a/gdk/x11/gdkimage-x11.c b/gdk/x11/gdkimage-x11.c
index 5c7a5de5c1..4d009f9f42 100644
--- a/gdk/x11/gdkimage-x11.c
+++ b/gdk/x11/gdkimage-x11.c
@@ -409,6 +409,8 @@ gdk_image_destroy (GdkImage *image)
case GDK_IMAGE_SHARED:
#ifdef USE_SHM
+ gdk_flush();
+
XShmDetach (private->xdisplay, private->x_shm_info);
XDestroyImage (private->ximage);
diff --git a/gdk/x11/gdkmain-x11.c b/gdk/x11/gdkmain-x11.c
index 867dadef60..ca0d47504b 100644
--- a/gdk/x11/gdkmain-x11.c
+++ b/gdk/x11/gdkmain-x11.c
@@ -116,13 +116,6 @@ static Bool gdk_event_get_type (Display *display,
static void gdk_synthesize_click (GdkEvent *event,
gint nclicks);
-static void gdk_dnd_drag_begin (GdkWindow *initial_window);
-static void gdk_dnd_drag_enter (Window dest);
-static void gdk_dnd_drag_leave (Window dest);
-static void gdk_dnd_drag_end (Window dest,
- GdkPoint coords);
-static GdkAtom gdk_dnd_check_types (GdkWindow *window,
- XEvent *xevent);
#ifdef DEBUG_DND
static void gdk_print_atom (GdkAtom anatom);
#endif
@@ -163,6 +156,10 @@ static gint gdk_im_open (XrmDatabase db,
static void gdk_im_close (void);
static void gdk_ic_cleanup (void);
+GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data);
+
#endif /* USE_XIM */
/* Private variable declarations
@@ -217,6 +214,8 @@ static GdkWindowPrivate *xgrab_window = NULL; /* Window that currently holds
* x pointer grab
*/
+static GList *client_filters; /* Filters for client messages */
+
#ifdef USE_XIM
static gint xim_using; /* using XIM Protocol if TRUE */
static GdkIM xim_im; /* global IM */
@@ -549,14 +548,6 @@ gdk_init (int *argc,
gdk_wm_window_protocols[1] = gdk_wm_take_focus;
gdk_selection_property = XInternAtom (gdk_display, "GDK_SELECTION", False);
- gdk_dnd.gdk_XdeEnter = gdk_atom_intern("_XDE_ENTER", FALSE);
- gdk_dnd.gdk_XdeLeave = gdk_atom_intern("_XDE_LEAVE", FALSE);
- gdk_dnd.gdk_XdeRequest = gdk_atom_intern("_XDE_REQUEST", FALSE);
- gdk_dnd.gdk_XdeDataAvailable = gdk_atom_intern("_XDE_DATA_AVAILABLE", FALSE);
- gdk_dnd.gdk_XdeTypelist = gdk_atom_intern("_XDE_TYPELIST", FALSE);
- gdk_dnd.c->gdk_cursor_dragdefault = XCreateFontCursor(gdk_display, XC_bogosity);
- gdk_dnd.c->gdk_cursor_dragok = XCreateFontCursor(gdk_display, XC_heart);
-
XGetKeyboardControl (gdk_display, &keyboard_state);
autorepeat = keyboard_state.global_auto_repeat;
@@ -577,6 +568,10 @@ gdk_init (int *argc,
gdk_window_init ();
gdk_image_init ();
gdk_input_init ();
+ gdk_dnd_init ();
+
+ gdk_add_client_message_filter (gdk_wm_protocols,
+ gdk_wm_protocols_filter, NULL);
#ifdef USE_XIM
/* initialize XIM Protocol variables */
@@ -928,13 +923,15 @@ gdk_event_copy (GdkEvent *event)
gdk_window_ref (event->crossing.subwindow);
break;
- case GDK_DROP_DATA_AVAIL:
- new_event->dropdataavailable.data_type = g_strdup (event->dropdataavailable.data_type);
- new_event->dropdataavailable.data = g_malloc (event->dropdataavailable.data_numbytes);
- memcpy (new_event->dropdataavailable.data,
- event->dropdataavailable.data,
- event->dropdataavailable.data_numbytes);
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ gdk_drag_context_ref (event->dnd.context);
break;
+
default:
break;
@@ -983,14 +980,15 @@ gdk_event_free (GdkEvent *event)
gdk_window_unref (event->crossing.subwindow);
break;
- case GDK_DROP_DATA_AVAIL:
- g_free (event->dropdataavailable.data_type);
- g_free (event->dropdataavailable.data);
- break;
-
- case GDK_DRAG_REQUEST:
- g_free (event->dragrequest.data_type);
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ gdk_drag_context_unref (event->dnd.context);
break;
+
default:
break;
@@ -1019,6 +1017,60 @@ gdk_event_free (GdkEvent *event)
*--------------------------------------------------------------
*/
+/*
+ *--------------------------------------------------------------
+ * gdk_event_get_time:
+ * Get the timestamp from an event.
+ * arguments:
+ * event:
+ * results:
+ * The event's time stamp, if it has one, otherwise
+ * GDK_CURRENT_TIME.
+ *--------------------------------------------------------------
+ */
+
+guint32
+gdk_event_get_time (GdkEvent *event)
+{
+ if (event)
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ return event->motion.time;
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ return event->button.time;
+ case GDK_KEY_PRESS:
+ case GDK_KEY_RELEASE:
+ return event->key.time;
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ return event->crossing.time;
+ case GDK_PROPERTY_NOTIFY:
+ return event->property.time;
+ case GDK_SELECTION_CLEAR:
+ case GDK_SELECTION_REQUEST:
+ case GDK_SELECTION_NOTIFY:
+ return event->selection.time;
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+ return event->proximity.time;
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ return event->dnd.time;
+ default: /* use current time */
+ break;
+ }
+
+ return GDK_CURRENT_TIME;
+}
+
void
gdk_set_show_events (int show_events)
{
@@ -1773,6 +1825,20 @@ gdk_event_apply_filters (XEvent *xevent,
return GDK_FILTER_CONTINUE;
}
+void
+gdk_add_client_message_filter (GdkAtom message_type,
+ GdkFilterFunc func,
+ gpointer data)
+{
+ GdkClientFilter *filter = g_new (GdkClientFilter, 1);
+
+ filter->type = message_type;
+ filter->function = func;
+ filter->data = data;
+
+ client_filters = g_list_prepend (client_filters, filter);
+}
+
static gint
gdk_event_translate (GdkEvent *event,
XEvent *xevent)
@@ -1793,15 +1859,9 @@ gdk_event_translate (GdkEvent *event,
return_val = FALSE;
- /* We need to play catch-up with the dnd motion events */
- if(gdk_dnd.drag_really && xevent->type == MotionNotify)
- while (XCheckTypedEvent(xevent->xany.display,MotionNotify,xevent));
-
/* Find the GdkWindow that this event occurred in.
- * All events occur in some GdkWindow (otherwise, why
- * would we be receiving them). It really is an error
- * to receive an event for which we cannot find the
- * corresponding GdkWindow. We handle events with window=None
+ *
+ * We handle events with window=None
* specially - they are generated by XFree86's XInput under
* some circumstances.
*/
@@ -1822,15 +1882,20 @@ gdk_event_translate (GdkEvent *event,
if (window != NULL)
gdk_window_ref (window);
- else if (gdk_null_window_warnings)
- {
- /* Special purpose programs that
- * get events for other windows may
- * want to disable this
- */
- g_warning ("xwindow(%#lx) lookup reveals NULL", xevent->xany.window);
- }
+#ifdef USE_XIM
+ else if (XFilterEvent(xevent, None)) /* for xlib XIM handling */
+ return FALSE;
+#endif
+ else
+ GDK_NOTE (EVENTS,
+ g_message ("Got event for unknown window: %#lx\n", xevent->xany.window));
+
+ event->any.window = window;
+ event->any.send_event = xevent->xany.send_event;
+ if (window_private && window_private->destroyed)
+ return FALSE;
+
/* Check for filters for this window */
{
@@ -1845,7 +1910,7 @@ gdk_event_translate (GdkEvent *event,
return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
}
}
-
+
/* We do a "manual" conversion of the XEvent to a
* GdkEvent. The structures are mostly the same so
* the conversion is fairly straightforward. We also
@@ -2031,44 +2096,7 @@ gdk_event_translate (GdkEvent *event,
button_number[1] = -1;
button_number[0] = event->button.button;
}
- if(window_private
- && window_private->dnd_drag_enabled
- && !gdk_dnd.drag_perhaps
- && event->button.button == 1
- && !gdk_dnd.drag_really)
- {
- gdk_dnd.drag_perhaps = 1;
- gdk_dnd.dnd_drag_start.x = xevent->xbutton.x_root;
- gdk_dnd.dnd_drag_start.y = xevent->xbutton.y_root;
- gdk_dnd.real_sw = window_private;
-
- if(gdk_dnd.drag_startwindows)
- {
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- }
- gdk_dnd.drag_numwindows = gdk_dnd.drag_really = 0;
- gdk_dnd.dnd_grabbed = FALSE;
-
- {
- /* Set motion mask for first DnD'd window, since it
- will be the one that is actually dragged */
- XWindowAttributes dnd_winattr;
- XSetWindowAttributes dnd_setwinattr;
-
- /* We need to get motion events while the button is down, so
- we can know whether to really start dragging or not... */
- XGetWindowAttributes(gdk_display, (Window)window_private->xwindow,
- &dnd_winattr);
-
- window_private->dnd_drag_savedeventmask = dnd_winattr.your_event_mask;
- dnd_setwinattr.event_mask =
- window_private->dnd_drag_eventmask = ButtonMotionMask | ButtonPressMask | ButtonReleaseMask |
- EnterWindowMask | LeaveWindowMask | ExposureMask;
- XChangeWindowAttributes(gdk_display, window_private->xwindow,
- CWEventMask, &dnd_setwinattr);
- }
- }
+
return_val = window_private && !window_private->destroyed;
break;
@@ -2102,66 +2130,18 @@ gdk_event_translate (GdkEvent *event,
event->button.source = GDK_SOURCE_MOUSE;
event->button.deviceid = GDK_CORE_POINTER;
- gdk_dnd.last_drop_time = xevent->xbutton.time;
- if(gdk_dnd.drag_perhaps)
- {
- {
- XSetWindowAttributes attrs;
- /* Reset event mask to pre-drag value, assuming event_mask
- doesn't change during drag */
- attrs.event_mask = gdk_dnd.real_sw->dnd_drag_savedeventmask;
- XChangeWindowAttributes(gdk_display, gdk_dnd.real_sw->xwindow,
- CWEventMask, &attrs);
- }
-
- if (gdk_dnd.dnd_grabbed)
- {
- gdk_dnd_display_drag_cursor(-2,
- -2,
- FALSE, TRUE);
- XUngrabPointer(gdk_display, CurrentTime);
- gdk_dnd.dnd_grabbed = FALSE;
- }
-
- if(gdk_dnd.drag_really)
- {
- GdkPoint foo;
- foo.x = xevent->xbutton.x_root;
- foo.y = xevent->xbutton.y_root;
-
- if(gdk_dnd.dnd_drag_target != None)
- gdk_dnd_drag_end(gdk_dnd.dnd_drag_target, foo);
- gdk_dnd.drag_really = 0;
-
- gdk_dnd.drag_numwindows = 0;
- if(gdk_dnd.drag_startwindows)
- {
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- }
-
- gdk_dnd.real_sw = NULL;
- }
-
- gdk_dnd.drag_perhaps = 0;
- gdk_dnd.dnd_drag_start.x = gdk_dnd.dnd_drag_start.y = 0;
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0;
- gdk_dnd.dnd_drag_curwin = None;
- return_val = window_private?TRUE:FALSE;
- } else
- return_val = window_private && !window_private->destroyed;
+ return_val = window_private && !window_private->destroyed;
+
break;
case MotionNotify:
/* Print debugging info.
*/
GDK_NOTE (EVENTS,
- g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s d:%d r%d",
+ g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
xevent->xmotion.window - base_id,
xevent->xmotion.x, xevent->xmotion.y,
- (xevent->xmotion.is_hint) ? "true" : "false",
- gdk_dnd.drag_perhaps, gdk_dnd.drag_really));
+ (xevent->xmotion.is_hint) ? "true" : "false"));
if (window_private &&
(window_private->extension_events != 0) &&
@@ -2183,114 +2163,7 @@ gdk_event_translate (GdkEvent *event,
event->motion.source = GDK_SOURCE_MOUSE;
event->motion.deviceid = GDK_CORE_POINTER;
-#define IS_IN_ZONE(cx, cy) (cx >= gdk_dnd.dnd_drag_dropzone.x \
- && cy >= gdk_dnd.dnd_drag_dropzone.y \
- && cx < (gdk_dnd.dnd_drag_dropzone.x + gdk_dnd.dnd_drag_dropzone.width) \
- && cy < (gdk_dnd.dnd_drag_dropzone.y + gdk_dnd.dnd_drag_dropzone.height))
-
- if(gdk_dnd.drag_perhaps && gdk_dnd.drag_really
- /* && event->motion.is_hint */ /* HINTME */)
- {
- /* First, we have to find what window the motion was in... */
- /* XXX there has to be a better way to do this, perhaps with
- XTranslateCoordinates or XQueryTree - I don't know how,
- and this sort of works */
- static Window lastwin = None, curwin = None;
-#if 0
- Window twin;
-#endif
- Window childwin = gdk_root_window;
- int x, y, ox, oy;
-
- /* Interlude - display cursor for the drag ASAP */
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- gdk_dnd.dnd_drag_target?TRUE:FALSE,
- FALSE);
-
- lastwin = curwin;
- curwin = gdk_root_window;
- ox = x = xevent->xmotion.x_root;
- oy = y = xevent->xmotion.y_root;
-#if 1
- curwin = gdk_window_xid_at_coords(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- gdk_dnd.c->xids,TRUE);
- XTranslateCoordinates(gdk_display, gdk_root_window, curwin,
- x, y, &x, &y, &childwin);
-#else
- while(childwin != None)
- {
- ox = x; oy = y;
- curwin = childwin;
- XTranslateCoordinates(gdk_display, curwin, curwin,
- x, y, &x, &y, &childwin);
- if(childwin != None)
- {
- XTranslateCoordinates(gdk_display, curwin, childwin,
- x, y, &x, &y, &twin);
- }
- }
-#endif
- GDK_NOTE (DND,
- g_message("Drag is now in window %#lx, lastwin was %#lx, ddc = %#lx",
- curwin, lastwin, gdk_dnd.dnd_drag_curwin));
- if(curwin != gdk_dnd.dnd_drag_curwin && curwin != lastwin)
- {
- /* We have left one window and entered another
- (do leave & enter bits) */
- if(gdk_dnd.dnd_drag_curwin != None)
- gdk_dnd_drag_leave(gdk_dnd.dnd_drag_curwin);
- gdk_dnd.dnd_drag_curwin = curwin;
- gdk_dnd_drag_enter(gdk_dnd.dnd_drag_curwin);
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_dropzone.width = gdk_dnd.dnd_drag_dropzone.height = 0;
- gdk_dnd.dnd_drag_target = None;
- GDK_NOTE (DND,
- g_message("curwin = %#lx, lastwin = %#lx, dnd_drag_curwin = %#lx",
- curwin, lastwin, gdk_dnd.dnd_drag_curwin));
-
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
- else if(gdk_dnd.dnd_drag_dropzone.width > 0
- && gdk_dnd.dnd_drag_dropzone.height > 0
- && curwin == gdk_dnd.dnd_drag_curwin)
- {
- /* Handle all that dropzone stuff - thanks John ;-) */
- if (gdk_dnd.dnd_drag_target != None)
- {
- gboolean in_zone = IS_IN_ZONE(xevent->xmotion.x_root,
- xevent->xmotion.y_root);
- gboolean old_in_zone = IS_IN_ZONE(gdk_dnd.dnd_drag_oldpos.x,
- gdk_dnd.dnd_drag_oldpos.y);
-
- if (!in_zone && old_in_zone)
- {
- /* We were in the drop zone and moved out */
- gdk_dnd.dnd_drag_target = None;
- gdk_dnd_drag_leave(curwin);
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
- else if (!in_zone && !old_in_zone)
- {
- /* We were outside drop zone but in the window
- - have to send enter events */
- gdk_dnd_drag_enter(curwin);
- gdk_dnd.dnd_drag_curwin = curwin;
- gdk_dnd.dnd_drag_dropzone.x = gdk_dnd.dnd_drag_dropzone.y = 0;
- gdk_dnd.dnd_drag_target = None;
- }
- }
- } /* else
- dnd_drag_curwin = None; */
- return_val = FALSE;
- }
- else
- return_val = window_private && !window_private->destroyed;
+ return_val = window_private && !window_private->destroyed;
break;
case EnterNotify:
@@ -2366,35 +2239,7 @@ gdk_event_translate (GdkEvent *event,
event->crossing.focus = xevent->xcrossing.focus;
event->crossing.state = xevent->xcrossing.state;
-
-#ifdef G_ENABLE_DEBUG
- if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps)
- {
- g_message("We may[%d] have a drag into %#lx = %#lx",
- gdk_dnd.drag_really,
- xevent->xcrossing.window, gdk_dnd.real_sw->xwindow);
- }
-#endif /* G_ENABLE_DEBUG */
-
- if (gdk_dnd.drag_perhaps && gdk_dnd.drag_really &&
- (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow))
- {
-#if 0
- gdk_dnd.drag_really = 0;
-
- GDK_NOTE (DND, g_message("Ungrabbed"));
-
- gdk_dnd.drag_numwindows = 0;
- g_free(gdk_dnd.drag_startwindows);
- gdk_dnd.drag_startwindows = NULL;
- /* We don't want to ungrab the pointer here, or we'll
- * start getting spurious enter/leave events */
-#endif
-#if 0
- XChangeActivePointerGrab (gdk_display, 0, None, CurrentTime);
-#endif
- }
-
+
return_val = window_private && !window_private->destroyed;
break;
@@ -2465,37 +2310,6 @@ gdk_event_translate (GdkEvent *event,
event->crossing.focus = xevent->xcrossing.focus;
event->crossing.state = xevent->xcrossing.state;
-#ifdef G_ENABLE_DEBUG
- if ((gdk_debug_flags & GDK_DEBUG_DND) & gdk_dnd.drag_perhaps)
- {
- g_message("We may[%d] have a drag out of %#lx = %#lx",
- gdk_dnd.drag_really,
- xevent->xcrossing.window, gdk_dnd.real_sw->xwindow);
- }
-#endif /* G_ENABLE_DEBUG */
- if (gdk_dnd.drag_perhaps && !gdk_dnd.drag_really &&
- (xevent->xcrossing.window == gdk_dnd.real_sw->xwindow))
- {
- gboolean xgpret;
- gdk_dnd_drag_addwindow((GdkWindow *) gdk_dnd.real_sw);
- gdk_dnd_drag_begin((GdkWindow *) gdk_dnd.real_sw);
- xgpret =
- XGrabPointer(gdk_display, gdk_dnd.real_sw->xwindow, False,
- ButtonMotionMask | PointerMotionMask |
- /* PointerMotionHintMask | */ /* HINTME */
- ButtonPressMask | ButtonReleaseMask,
- GrabModeAsync, GrabModeAsync, None,
- None, CurrentTime);
-#ifdef G_ENABLE_DEBUG
- GDK_NOTE(DND, g_message("xgpret = %d", xgpret));
-#endif
- gdk_dnd.dnd_grabbed = TRUE;
- gdk_dnd.drag_really = 1;
- gdk_dnd_display_drag_cursor(xevent->xmotion.x_root,
- xevent->xmotion.y_root,
- FALSE, TRUE);
- }
-
return_val = window_private && !window_private->destroyed;
break;
@@ -2852,231 +2666,50 @@ gdk_event_translate (GdkEvent *event,
break;
case ClientMessage:
- /* Print debugging info.
- */
- GDK_NOTE (EVENTS,
- g_message ("client message:\twindow: %ld",
- xevent->xclient.window - base_id));
-
- /* Client messages are the means of the window manager
- * communicating with a program. We'll first check to
- * see if this is really the window manager talking
- * to us.
- */
- if (xevent->xclient.message_type == gdk_wm_protocols)
- {
- if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
- {
- /* The delete window request specifies a window
- * to delete. We don't actually destroy the
- * window because "it is only a request". (The
- * window might contain vital data that the
- * program does not want destroyed). Instead
- * the event is passed along to the program,
- * which should then destroy the window.
- */
-
- /* Print debugging info.
- */
- GDK_NOTE (EVENTS,
- g_message ("delete window:\t\twindow: %ld",
- xevent->xclient.window - base_id));
-
- event->any.type = GDK_DELETE;
- event->any.window = window;
-
- return_val = window_private && !window_private->destroyed;
- }
- else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
- {
- }
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter)
- {
- Atom reptype = 0;
-
- event->dropenter.u.allflags = xevent->xclient.data.l[1];
-
- GDK_NOTE (DND, g_message ("GDK_DROP_ENTER [%d][%d]",
- window_private->dnd_drop_enabled, event->dropenter.u.flags.sendreply));
- return_val = FALSE;
-
- /* Now figure out if we really want this drop...
- * If someone is trying funky clipboard stuff, ignore
- */
- if (window_private
- && window_private->dnd_drop_enabled
- && event->dropenter.u.flags.sendreply
- && (reptype = gdk_dnd_check_types (window, xevent)))
- {
- XEvent replyev;
-
- replyev.xclient.type = ClientMessage;
- replyev.xclient.window = xevent->xclient.data.l[0];
- replyev.xclient.format = 32;
- replyev.xclient.message_type = gdk_dnd.gdk_XdeRequest;
- replyev.xclient.data.l[0] = window_private->xwindow;
-
- event->dragrequest.u.allflags = 0;
- event->dragrequest.u.flags.protocol_version =
- DND_PROTOCOL_VERSION;
- event->dragrequest.u.flags.willaccept = 1;
- event->dragrequest.u.flags.delete_data =
- (window_private->dnd_drop_destructive_op) ? 1 : 0;
-
- replyev.xclient.data.l[1] = event->dragrequest.u.allflags;
- replyev.xclient.data.l[2] = replyev.xclient.data.l[3] = 0;
- replyev.xclient.data.l[4] = reptype;
-
- if (!gdk_send_xevent (replyev.xclient.window, False,
- NoEventMask, &replyev))
- GDK_NOTE (DND, g_message("Sending XdeRequest to %#lx failed",
- replyev.xclient.window));
-
- event->any.type = GDK_DROP_ENTER;
- event->any.window = window;
- event->dropenter.requestor = replyev.xclient.window;
- event->dropenter.u.allflags = xevent->xclient.data.l[1];
-
- GDK_NOTE (DND, g_message("We sent a GDK_DROP_ENTER on to Gtk"));
- return_val = TRUE;
- }
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeLeave)
- {
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message ("GDK_DROP_LEAVE");
-#endif
-
- if (window_private && window_private->dnd_drop_enabled)
- {
- event->dropleave.type = GDK_DROP_LEAVE;
- event->dropleave.window = window;
- event->dropleave.requestor = xevent->xclient.data.l[0];
- event->dropleave.u.allflags = xevent->xclient.data.l[1];
- return_val = TRUE;
- }
- else
+ {
+ GList *tmp_list;
+ GdkFilterReturn result = GDK_FILTER_CONTINUE;
+
+ /* Print debugging info.
+ */
+ GDK_NOTE (EVENTS,
+ g_message ("client message:\twindow: %ld",
+ xevent->xclient.window - base_id));
+
+ tmp_list = client_filters;
+ while (tmp_list)
+ {
+ GdkClientFilter *filter = tmp_list->data;
+ if (filter->type == xevent->xclient.message_type)
+ {
+ result = (*filter->function) (xevent, event, filter->data);
+ break;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+
+ switch (result)
+ {
+ case GDK_FILTER_REMOVE:
return_val = FALSE;
- }
- else if (xevent->xclient.message_type == gdk_dnd.gdk_XdeRequest)
- {
- /*
- * make sure to only handle requests from the window the cursor is
- * over
- */
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message ("GDK_DRAG_REQUEST");
-#endif
- event->dragrequest.u.allflags = xevent->xclient.data.l[1];
- return_val = FALSE;
-
- if (window && gdk_dnd.drag_really &&
- xevent->xclient.data.l[0] == gdk_dnd.dnd_drag_curwin &&
- event->dragrequest.u.flags.sendreply == 0)
- {
- /* Got request - do we need to ask user? */
- if (!event->dragrequest.u.flags.willaccept
- && event->dragrequest.u.flags.senddata)
- {
- /* Yes we do :) */
- event->dragrequest.type = GDK_DRAG_REQUEST;
- event->dragrequest.window = window;
- event->dragrequest.requestor = xevent->xclient.data.l[0];
- event->dragrequest.isdrop = 0;
- event->dragrequest.drop_coords.x =
- event->dragrequest.drop_coords.y = 0;
- return_val = TRUE;
- }
- else if (event->dragrequest.u.flags.willaccept)
- {
- window_private->dnd_drag_destructive_op =
- event->dragrequest.u.flags.delete_data;
- window_private->dnd_drag_accepted = 1;
- window_private->dnd_drag_data_type =
- xevent->xclient.data.l[4];
-
- gdk_dnd.dnd_drag_target = gdk_dnd.dnd_drag_curwin;
- gdk_dnd_display_drag_cursor(-1, -1, TRUE, TRUE);
- }
- gdk_dnd.dnd_drag_dropzone.x = xevent->xclient.data.l[2] & 65535;
- gdk_dnd.dnd_drag_dropzone.y =
- (xevent->xclient.data.l[2] >> 16) & 65535;
- gdk_dnd.dnd_drag_dropzone.width = xevent->xclient.data.l[3] & 65535;
- gdk_dnd.dnd_drag_dropzone.height =
- (xevent->xclient.data.l[3] >> 16) & 65535;
- }
- }
- else if(xevent->xclient.message_type == gdk_dnd.gdk_XdeDataAvailable)
- {
- gint tmp_int; Atom tmp_atom;
- gulong tmp_long;
- guchar *tmp_charptr;
-
-#ifdef G_ENABLE_DEBUG
- if (gdk_debug_flags & (GDK_DEBUG_EVENTS | GDK_DEBUG_DND))
- g_message("GDK_DROP_DATA_AVAIL");
-#endif
- event->dropdataavailable.u.allflags = xevent->xclient.data.l[1];
- event->dropdataavailable.timestamp = xevent->xclient.data.l[4];
- event->dropdataavailable.coords.x =
- xevent->xclient.data.l[3] & 0xffff;
- event->dropdataavailable.coords.y =
- (xevent->xclient.data.l[3] >> 16) & 0xffff;
- if(window
- /* No preview of data ATM */
- && event->dropdataavailable.u.flags.isdrop)
- {
- event->dropdataavailable.type = GDK_DROP_DATA_AVAIL;
- event->dropdataavailable.window = window;
- event->dropdataavailable.requestor = xevent->xclient.data.l[0];
- event->dropdataavailable.data_type =
- gdk_atom_name(xevent->xclient.data.l[2]);
- if(XGetWindowProperty (gdk_display,
- event->dropdataavailable.requestor,
- xevent->xclient.data.l[2],
- 0, LONG_MAX - 1,
- False, XA_PRIMARY, &tmp_atom,
- &tmp_int,
- &event->dropdataavailable.data_numbytes,
- &tmp_long,
- &tmp_charptr)
- != Success)
- {
- g_warning("XGetWindowProperty on %#x may have failed\n",
- event->dropdataavailable.requestor);
- event->dropdataavailable.data = NULL;
- }
- else
- {
- GDK_NOTE (DND, g_message("XGetWindowProperty got us %ld bytes",
- event->dropdataavailable.data_numbytes));
- event->dropdataavailable.data =
- g_malloc (event->dropdataavailable.data_numbytes);
- memcpy (event->dropdataavailable.data,
- tmp_charptr, event->dropdataavailable.data_numbytes);
- XFree(tmp_charptr);
- return_val = TRUE;
- }
- return_val = TRUE;
- }
- }
- else
- {
- /* Send unknown ClientMessage's on to Gtk for it to use */
- event->client.type = GDK_CLIENT_EVENT;
- event->client.window = window;
- event->client.message_type = xevent->xclient.message_type;
- event->client.data_format = xevent->xclient.format;
- memcpy(&event->client.data, &xevent->xclient.data,
- sizeof(event->client.data));
- if(window)
+ break;
+ case GDK_FILTER_TRANSLATE:
return_val = TRUE;
- else
- return_val = FALSE;
- }
+ break;
+ case GDK_FILTER_CONTINUE:
+ /* Send unknown ClientMessage's on to Gtk for it to use */
+ event->client.type = GDK_CLIENT_EVENT;
+ event->client.window = window;
+ event->client.message_type = xevent->xclient.message_type;
+ event->client.data_format = xevent->xclient.format;
+ memcpy(&event->client.data, &xevent->xclient.data,
+ sizeof(event->client.data));
+
+ return_val = (window != NULL);
+ }
+ }
+
if(window_private)
return_val = return_val && !window_private->destroyed;
break;
@@ -3129,6 +2762,38 @@ gdk_event_translate (GdkEvent *event,
return return_val;
}
+GdkFilterReturn
+gdk_wm_protocols_filter (GdkXEvent *xev,
+ GdkEvent *event,
+ gpointer data)
+{
+ XEvent *xevent = (XEvent *)xev;
+
+ if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
+ {
+ /* The delete window request specifies a window
+ * to delete. We don't actually destroy the
+ * window because "it is only a request". (The
+ * window might contain vital data that the
+ * program does not want destroyed). Instead
+ * the event is passed along to the program,
+ * which should then destroy the window.
+ */
+ GDK_NOTE (EVENTS,
+ g_message ("delete window:\t\twindow: %ld",
+ xevent->xclient.window - base_id));
+
+ event->any.type = GDK_DELETE;
+
+ return GDK_FILTER_TRANSLATE;
+ }
+ else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
+ {
+ }
+
+ return GDK_FILTER_REMOVE;
+}
+
#if 0
static Bool
gdk_event_get_type (Display *display,
@@ -3344,67 +3009,6 @@ gdk_signal (int sig_num)
#endif /* !G_ENABLE_DEBUG */
}
-static void
-gdk_dnd_drag_begin (GdkWindow *initial_window)
-{
- GdkEvent tev;
-
- GDK_NOTE(DND, g_message("------- STARTING DRAG from %p", initial_window));
-
- tev.type = GDK_DRAG_BEGIN;
- tev.dragbegin.window = initial_window;
- tev.dragbegin.u.allflags = 0;
- tev.dragbegin.u.flags.protocol_version = DND_PROTOCOL_VERSION;
-
- gdk_event_put (&tev);
-}
-
-static void
-gdk_dnd_drag_enter (Window dest)
-{
- XEvent sev;
- GdkEventDropEnter tev;
- int i;
- GdkWindowPrivate *wp;
-
- sev.xclient.type = ClientMessage;
- sev.xclient.format = 32;
- sev.xclient.message_type = gdk_dnd.gdk_XdeEnter;
- sev.xclient.window = dest;
-
- tev.u.allflags = 0;
- tev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tev.u.flags.sendreply = 1;
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- if (wp->dnd_drag_data_numtypesavail)
- {
- sev.xclient.data.l[0] = wp->xwindow;
- tev.u.flags.extended_typelist = (wp->dnd_drag_data_numtypesavail > 3)?1:0;
- sev.xclient.data.l[1] = tev.u.allflags;
- sev.xclient.data.l[2] = wp->dnd_drag_data_typesavail[0];
- if (wp->dnd_drag_data_numtypesavail > 1)
- {
- sev.xclient.data.l[3] = wp->dnd_drag_data_typesavail[1];
- if (wp->dnd_drag_data_numtypesavail > 2)
- {
- sev.xclient.data.l[4] = wp->dnd_drag_data_typesavail[2];
- }
- else
- sev.xclient.data.l[4] = None;
- }
- else
- sev.xclient.data.l[3] = sev.xclient.data.l[4] = None;
- if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeEnter to %#lx failed",
- dest));
- }
-
- }
-}
-
-
#ifdef USE_XIM
/* The following routines duplicate functionality in Xlib to
@@ -4051,145 +3655,58 @@ _g_mbtowc (wchar_t *wstr, const char *str, size_t len)
#endif /* X_LOCALE */
-static void
-gdk_dnd_drag_leave (Window dest)
-{
- XEvent sev;
- GdkEventDropLeave tev;
- int i;
- GdkWindowPrivate *wp;
-
- tev.u.allflags = 0;
-
- tev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- sev.xclient.type = ClientMessage;
- sev.xclient.window = dest;
- sev.xclient.format = 32;
- sev.xclient.message_type = gdk_dnd.gdk_XdeLeave;
- sev.xclient.data.l[1] = tev.u.allflags;
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- sev.xclient.data.l[0] = wp->xwindow;
- if (!gdk_send_xevent (dest, False, StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeLeave to %#lx failed",
- dest));
- wp->dnd_drag_accepted = 0;
- }
-}
-
/*
- * when a drop occurs, we go through the list of windows being dragged and
- * tell them that it has occurred, so that they can set things up and reply
- * to 'dest' window
+ * used for debugging only
*/
+#ifdef DEBUG_DND
static void
-gdk_dnd_drag_end (Window dest,
- GdkPoint coords)
+gdk_print_atom (GdkAtom anatom)
{
- GdkWindowPrivate *wp;
- GdkEvent tev;
- int i;
-
- tev.dragrequest.type = GDK_DRAG_REQUEST;
- tev.dragrequest.drop_coords = coords;
- tev.dragrequest.requestor = dest;
- tev.dragrequest.u.allflags = 0;
- tev.dragrequest.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tev.dragrequest.isdrop = 1;
-
- for (i = 0; i < gdk_dnd.drag_numwindows; i++)
- {
- wp = (GdkWindowPrivate *) gdk_dnd.drag_startwindows[i];
- if (wp->dnd_drag_accepted)
- {
- tev.dragrequest.window = (GdkWindow *) wp;
- tev.dragrequest.u.flags.delete_data = wp->dnd_drag_destructive_op;
- tev.dragrequest.timestamp = gdk_dnd.last_drop_time;
- tev.dragrequest.data_type =
- gdk_atom_name(wp->dnd_drag_data_type);
-
- gdk_event_put(&tev);
- }
- }
+ gchar *tmpstr = NULL;
+ tmpstr = (anatom!=None)?gdk_atom_name(anatom):"(none)";
+ g_message("Atom %lu has name %s", anatom, tmpstr);
+ if(tmpstr)
+ g_free(tmpstr);
}
+#endif
-static GdkAtom
-gdk_dnd_check_types (GdkWindow *window,
- XEvent *xevent)
+#ifdef WE_HAVE_MOTIF_DROPS_DONE
+static GdkWindow *
+gdk_drop_get_real_window (GdkWindow *w,
+ guint16 *x,
+ guint16 *y)
{
- GdkWindowPrivate *wp = (GdkWindowPrivate *) window;
- int i, j;
- GdkEventDropEnter event;
+ GdkWindow *retval = w;
+ GdkWindowPrivate *awin;
+ GList *children;
+ gint16 myx = *x, myy = *y;
- g_return_val_if_fail(window != NULL, 0);
- g_return_val_if_fail(xevent != NULL, 0);
- g_return_val_if_fail(xevent->type == ClientMessage, 0);
- g_return_val_if_fail(xevent->xclient.message_type == gdk_dnd.gdk_XdeEnter, 0);
+ g_return_val_if_fail (w != NULL && x != NULL && y != NULL, NULL);
- if(wp->dnd_drop_data_numtypesavail <= 0 ||
- !wp->dnd_drop_data_typesavail)
- return 0;
+ myx = *x;
+ myy = *y;
- for (i = 2; i <= 4; i++)
+ descend:
+ for (children = gdk_window_get_children(retval);
+ children && children->next;
+ children = children->next)
{
- for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++)
+ awin = (GdkWindowPrivate *) children->data;
+ if ((myx >= awin->x) && (myy >= awin->y)
+ && (myx < (awin->x + awin->width))
+ && (myy < (awin->y + awin->height)))
{
- if (xevent->xclient.data.l[i] == wp->dnd_drop_data_typesavail[j])
- return xevent->xclient.data.l[i];
+ retval = (GdkWindow *) awin;
+ myx -= awin->x;
+ myy -= awin->y;
+ goto descend;
}
}
- /* Now we get the extended type list if it's available */
- event.u.allflags = xevent->xclient.data.l[1];
- if (event.u.flags.extended_typelist)
- {
- Atom *exttypes, realtype;
- gulong nitems, nbar;
- gint realfmt;
-
- if (XGetWindowProperty(gdk_display, xevent->xclient.data.l[0],
- gdk_dnd.gdk_XdeTypelist, 0L, LONG_MAX - 1,
- False, AnyPropertyType, &realtype, &realfmt,
- &nitems, &nbar, (unsigned char **) &exttypes)
- != Success)
- return 0;
-
- if (realfmt != (sizeof(Atom) * 8))
- {
- g_warning("XdeTypelist property had format of %d instead of the expected %ld, on window %#lx\n",
- realfmt, (glong)sizeof(Atom) * 8, xevent->xclient.data.l[0]);
- return 0;
- }
-
- for (i = 0; i <= nitems; i++)
- {
- for (j = 0; j < wp->dnd_drop_data_numtypesavail; j++)
- {
- if (exttypes[i] == wp->dnd_drop_data_typesavail[j])
- {
- XFree (exttypes);
- return exttypes[i];
- }
- }
- }
- XFree (exttypes);
- }
- return 0;
-}
-
-/*
- * used for debugging only
- */
-#ifdef DEBUG_DND
-static void
-gdk_print_atom (GdkAtom anatom)
-{
- gchar *tmpstr = NULL;
- tmpstr = (anatom!=None)?gdk_atom_name(anatom):"(none)";
- g_message("Atom %lu has name %s", anatom, tmpstr);
- if(tmpstr)
- g_free(tmpstr);
+ *x = myx;
+ *y = myy;
+
+ return retval;
}
#endif
@@ -4199,7 +3716,7 @@ gdk_print_atom (GdkAtom anatom)
static Window
getchildren (Display *dpy,
Window win,
- Atom WM_STATE)
+ Atom wm_state_atom)
{
Window root, parent, *children, inf = 0;
Atom type = None;
@@ -4213,7 +3730,7 @@ getchildren (Display *dpy,
for (i = 0; !inf && (i < nchildren); i++)
{
- XGetWindowProperty (dpy, children[i], WM_STATE, 0, 0, False,
+ XGetWindowProperty (dpy, children[i], wm_state_atom, 0, 0, False,
AnyPropertyType, &type, &format, &nitems,
&after, &data);
if (type != 0)
@@ -4222,7 +3739,7 @@ getchildren (Display *dpy,
}
for (i = 0; !inf && (i < nchildren); i++)
- inf = getchildren (dpy, children[i], WM_STATE);
+ inf = getchildren (dpy, children[i], wm_state_atom);
if (children != None)
XFree ((char *) children);
@@ -4239,7 +3756,7 @@ Window
gdk_get_client_window (Display *dpy,
Window win)
{
- Atom WM_STATE;
+ static Atom wm_state_atom = None;
Atom type = None;
int format;
unsigned long nitems, after;
@@ -4249,15 +3766,18 @@ gdk_get_client_window (Display *dpy,
if (win == 0)
return DefaultRootWindow(dpy);
- if ((WM_STATE = XInternAtom (dpy, "WM_STATE", True)) == 0)
+ if ((wm_state_atom = XInternAtom (dpy, "WM_STATE", True)) == 0)
return win;
-
- XGetWindowProperty (dpy, win, WM_STATE, 0, 0, False, AnyPropertyType,
+
+ XGetWindowProperty (dpy, win, wm_state_atom, 0, 0, False, AnyPropertyType,
&type, &format, &nitems, &after, &data);
if (type)
- return win;
+ {
+ XFree (data);
+ return win;
+ }
- inf = getchildren (dpy, win, WM_STATE);
+ inf = getchildren (dpy, win, wm_state_atom);
if (inf == 0)
return win;
@@ -4265,46 +3785,6 @@ gdk_get_client_window (Display *dpy,
return inf;
}
-#ifdef WE_HAVE_MOTIF_DROPS_DONE
-static GdkWindow *
-gdk_drop_get_real_window (GdkWindow *w,
- guint16 *x,
- guint16 *y)
-{
- GdkWindow *retval = w;
- GdkWindowPrivate *awin;
- GList *children;
- gint16 myx = *x, myy = *y;
-
- g_return_val_if_fail (w != NULL && x != NULL && y != NULL, NULL);
-
- myx = *x;
- myy = *y;
-
- descend:
- for (children = gdk_window_get_children(retval);
- children && children->next;
- children = children->next)
- {
- awin = (GdkWindowPrivate *) children->data;
- if ((myx >= awin->x) && (myy >= awin->y)
- && (myx < (awin->x + awin->width))
- && (myy < (awin->y + awin->height)))
- {
- retval = (GdkWindow *) awin;
- myx -= awin->x;
- myy -= awin->y;
- goto descend;
- }
- }
-
- *x = myx;
- *y = myy;
-
- return retval;
-}
-#endif
-
/* Sends a ClientMessage to all toplevel client windows */
void
gdk_event_send_clientmessage_toall (GdkEvent *event)
@@ -4320,7 +3800,6 @@ gdk_event_send_clientmessage_toall (GdkEvent *event)
sev.xclient.type = ClientMessage;
sev.xclient.display = gdk_display;
sev.xclient.format = event->client.data_format;
- sev.xclient.serial = CurrentTime;
memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
sev.xclient.message_type = event->client.message_type;
@@ -4352,13 +3831,14 @@ gdk_send_xevent (Window window, gboolean propagate, glong event_mask,
XEvent *event_send)
{
Status result;
+ gint old_warnings = gdk_error_warnings;
gdk_error_code = 0;
gdk_error_warnings = 0;
result = XSendEvent (gdk_display, window, propagate, event_mask, event_send);
XSync (gdk_display, False);
- gdk_error_warnings = 1;
+ gdk_error_warnings = old_warnings;
return result && (gdk_error_code != -1);
}
diff --git a/gdk/x11/gdkproperty-x11.c b/gdk/x11/gdkproperty-x11.c
index 38665ca0c4..5b18ba71e7 100644
--- a/gdk/x11/gdkproperty-x11.c
+++ b/gdk/x11/gdkproperty-x11.c
@@ -22,12 +22,21 @@
#include "gdk.h"
#include "gdkprivate.h"
-
GdkAtom
gdk_atom_intern (const gchar *atom_name,
gint only_if_exists)
{
- return XInternAtom (gdk_display, atom_name, only_if_exists);
+ GdkAtom retval;
+ static GHashTable *atom_hash = NULL;
+
+ if (!atom_hash)
+ atom_hash = g_hash_table_new (g_str_hash, g_str_equal);
+
+ retval = GPOINTER_TO_UINT (g_hash_table_lookup (atom_hash, atom_name));
+ if (!retval)
+ retval = XInternAtom (gdk_display, atom_name, only_if_exists);
+
+ return retval;
}
gchar *
@@ -35,14 +44,16 @@ gdk_atom_name (GdkAtom atom)
{
gchar *t;
gchar *name;
+ gint old_error_warnings;
/* If this atom doesn't exist, we'll die with an X error unless
we take precautions */
+ old_error_warnings = gdk_error_warnings;
gdk_error_warnings = 0;
gdk_error_code = 0;
t = XGetAtomName (gdk_display, atom);
- gdk_error_warnings = 1;
+ gdk_error_warnings = old_error_warnings;
if (gdk_error_code == -1)
{
@@ -115,7 +126,7 @@ gdk_property_get (GdkWindow *window,
if (actual_format_type)
*actual_format_type = ret_format;
- if (ret_prop_type != type)
+ if ((type != AnyPropertyType) && (ret_prop_type != type))
{
gchar *rn, *pn;
diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c
index 7c2d9b099c..3df6ac8ac1 100644
--- a/gdk/x11/gdkwindow-x11.c
+++ b/gdk/x11/gdkwindow-x11.c
@@ -216,6 +216,9 @@ gdk_window_init (void)
gdk_root_parent.height = height;
gdk_root_parent.children = NULL;
gdk_root_parent.colormap = NULL;
+ gdk_root_parent.ref_count = 1;
+
+ gdk_xid_table_insert (&gdk_root_window, &gdk_root_parent);
}
GdkWindow*
@@ -703,11 +706,15 @@ gdk_window_unref (GdkWindow *window)
if (private->ref_count == 0)
{
if (!private->destroyed)
- g_warning ("losing last reference to undestroyed window\n");
+ {
+ if (private->window_type == GDK_WINDOW_FOREIGN)
+ gdk_xid_table_remove (private->xwindow);
+ else
+ g_warning ("losing last reference to undestroyed window\n");
+ }
g_dataset_destroy (window);
g_free (window);
}
-
}
void
@@ -1681,188 +1688,6 @@ gdk_window_shape_combine_mask (GdkWindow *window,
#endif /* HAVE_SHAPE_EXT */
}
-void
-gdk_dnd_drag_addwindow (GdkWindow *window)
-{
- GdkWindowPrivate *window_private;
-
- g_return_if_fail (window != NULL);
-
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- if (window_private->dnd_drag_enabled == 1 && gdk_dnd.drag_really == 0)
- {
- gdk_dnd.drag_numwindows++;
- gdk_dnd.drag_startwindows = g_realloc (gdk_dnd.drag_startwindows,
- gdk_dnd.drag_numwindows
- * sizeof(GdkWindow *));
- gdk_dnd.drag_startwindows[gdk_dnd.drag_numwindows - 1] = window;
- window_private->dnd_drag_accepted = 0;
- }
- else
- g_warning ("dnd_really is 1 or drag is not enabled! can't addwindow\n");
-}
-
-void
-gdk_window_dnd_drag_set (GdkWindow *window,
- guint8 drag_enable,
- gchar **typelist,
- guint numtypes)
-{
- GdkWindowPrivate *window_private;
- int i, wasset = 0;
-
- g_return_if_fail (window != NULL);
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- window_private->dnd_drag_enabled = drag_enable ? 1 : 0;
-
- if (drag_enable)
- {
- g_return_if_fail(typelist != NULL);
-
- if (window_private->dnd_drag_data_numtypesavail > 3)
- wasset = 1;
- window_private->dnd_drag_data_numtypesavail = numtypes;
-
- window_private->dnd_drag_data_typesavail =
- g_realloc (window_private->dnd_drag_data_typesavail,
- (numtypes + 1) * sizeof (GdkAtom));
-
- for (i = 0; i < numtypes; i++)
- {
- /* Allow blanket use of ALL to get anything... */
- if (strcmp (typelist[i], "ALL"))
- window_private->dnd_drag_data_typesavail[i] =
- gdk_atom_intern (typelist[i], FALSE);
- else
- window_private->dnd_drag_data_typesavail[i] = None;
- }
-
- /*
- * set our extended type list if we need to
- */
- if (numtypes > 3)
- gdk_property_change(window, gdk_dnd.gdk_XdeTypelist,
- XA_PRIMARY, 32, GDK_PROP_MODE_REPLACE,
- (guchar *)(window_private->dnd_drag_data_typesavail
- + (sizeof(GdkAtom) * 3)),
- (numtypes - 3) * sizeof(GdkAtom));
- else if (wasset)
- gdk_property_delete (window, gdk_dnd.gdk_XdeTypelist);
- }
- else
- {
- g_free (window_private->dnd_drag_data_typesavail);
- window_private->dnd_drag_data_typesavail = NULL;
- window_private->dnd_drag_data_numtypesavail = 0;
- }
-}
-
-void
-gdk_window_dnd_drop_set (GdkWindow *window,
- guint8 drop_enable,
- gchar **typelist,
- guint numtypes,
- guint8 destructive_op)
-{
- GdkWindowPrivate *window_private;
- int i;
-
- g_return_if_fail (window != NULL);
- window_private = (GdkWindowPrivate *) window;
- if (window_private->destroyed)
- return;
-
- window_private->dnd_drop_enabled = drop_enable ? 1 : 0;
- if (drop_enable)
- {
- g_return_if_fail(typelist != NULL);
-
- window_private->dnd_drop_data_numtypesavail = numtypes;
-
- window_private->dnd_drop_data_typesavail =
- g_realloc (window_private->dnd_drop_data_typesavail,
- (numtypes + 1) * sizeof (GdkAtom));
-
- for (i = 0; i < numtypes; i++)
- window_private->dnd_drop_data_typesavail[i] =
- gdk_atom_intern (typelist[i], FALSE);
-
- window_private->dnd_drop_destructive_op = destructive_op;
- }
-}
-
-/*
- * This is used to reply to a GDK_DRAG_REQUEST event
- * (which may be generated by XdeRequest or a confirmed drop...
- */
-void
-gdk_window_dnd_data_set (GdkWindow *window,
- GdkEvent *event,
- gpointer data,
- gulong data_numbytes)
-{
- GdkWindowPrivate *window_private;
- XEvent sev;
- GdkEventDropDataAvailable tmp_ev;
- gchar *tmp;
-
- g_return_if_fail (window != NULL);
- g_return_if_fail (event != NULL);
- g_return_if_fail (data != NULL);
- g_return_if_fail (data_numbytes > 0);
- g_return_if_fail (event->type == GDK_DRAG_REQUEST);
-
- window_private = (GdkWindowPrivate *) window;
- g_return_if_fail (window_private->dnd_drag_accepted != 0);
- if (window_private->destroyed)
- return;
-
- /* We set the property on our window... */
- gdk_property_change (window, window_private->dnd_drag_data_type,
- XA_PRIMARY, 8, GDK_PROP_MODE_REPLACE, data,
- data_numbytes);
- tmp = gdk_atom_name(window_private->dnd_drag_data_type);
-#ifdef DEBUG_DND
- g_message("DnD type %s on window %ld\n", tmp, window_private->xwindow);
-#endif
- g_free(tmp);
-
- /*
- * Then we send the event to tell the receiving window that the
- * drop has happened
- */
- tmp_ev.u.allflags = 0;
- tmp_ev.u.flags.protocol_version = DND_PROTOCOL_VERSION;
- tmp_ev.u.flags.isdrop = event->dragrequest.isdrop;
-
- sev.xclient.type = ClientMessage;
- sev.xclient.format = 32;
- sev.xclient.window = event->dragrequest.requestor;
- sev.xclient.message_type = gdk_dnd.gdk_XdeDataAvailable;
- sev.xclient.data.l[0] = window_private->xwindow;
- sev.xclient.data.l[1] = tmp_ev.u.allflags;
- sev.xclient.data.l[2] = window_private->dnd_drag_data_type;
-
- if (event->dragrequest.isdrop)
- sev.xclient.data.l[3] = event->dragrequest.drop_coords.x +
- (event->dragrequest.drop_coords.y << 16);
- else
- sev.xclient.data.l[3] = 0;
-
- sev.xclient.data.l[4] = event->dragrequest.timestamp;
-
- if (!gdk_send_xevent (event->dragrequest.requestor, False,
- StructureNotifyMask, &sev))
- GDK_NOTE (DND, g_message("Sending XdeDataAvailable to %#x failed\n",
- event->dragrequest.requestor));
-}
-
void
gdk_window_add_filter (GdkWindow *window,
GdkFilterFunc function,
@@ -1905,7 +1730,7 @@ gdk_window_remove_filter (GdkWindow *window,
gpointer data)
{
GdkWindowPrivate *private;
- GList *tmp_list;
+ GList *tmp_list, *node;
GdkEventFilter *filter;
private = (GdkWindowPrivate*) window;
@@ -1918,15 +1743,16 @@ gdk_window_remove_filter (GdkWindow *window,
while (tmp_list)
{
filter = (GdkEventFilter *)tmp_list->data;
+ node = tmp_list;
tmp_list = tmp_list->next;
if ((filter->function == function) && (filter->data == data))
{
if(private)
- private->filters = g_list_remove_link (private->filters, tmp_list);
+ private->filters = g_list_remove_link (private->filters, node);
else
gdk_default_filters = g_list_remove_link (gdk_default_filters, tmp_list);
- g_list_free_1 (tmp_list);
+ g_list_free_1 (node);
g_free (filter);
return;
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 6eed5d25a8..5a5cd804e5 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -29,6 +29,7 @@ libgtk_la_SOURCES = \
gtkcurve.c \
gtkdata.c \
gtkdialog.c \
+ gtkdnd.c \
gtkdrawingarea.c \
gtkeditable.c \
gtkentry.c \
@@ -49,6 +50,7 @@ libgtk_la_SOURCES = \
gtkhseparator.c \
gtkimage.c \
gtkinputdialog.c \
+ gtkinvisible.c \
gtkitem.c \
gtkitemfactory.c \
gtklabel.c \
@@ -135,6 +137,7 @@ source_headers = \
gtkdata.h \
gtkdebug.h \
gtkdialog.h \
+ gtkdnd.h \
gtkdrawingarea.h \
gtkeditable.h \
gtkentry.h \
@@ -156,6 +159,7 @@ source_headers = \
gtkhseparator.h \
gtkimage.h \
gtkinputdialog.h \
+ gtkinvisible.h \
gtkitem.h \
gtkitemfactory.h \
gtklabel.h \
@@ -306,7 +310,9 @@ EXTRA_DIST = \
INCLUDES = -I$(top_srcdir) @GLIB_CFLAGS@ @x_cflags@
-noinst_PROGRAMS = testgtk testinput testselection testthreads testrgb simple
+noinst_PROGRAMS = testgtk testinput testselection testthreads testrgb testdnd simple
+
+# FIXME, we currently rely on linking against libglib-1.1
DEPS = \
libgtk.la \
@@ -325,6 +331,7 @@ testinput_DEPENDENCIES = $(DEPS)
testthreads_DEPENDENCIES = $(DEPS)
testselection_DEPENDENCIES = $(DEPS)
testrgb_DEPENDENCIES = $(DEPS)
+testdnd_DEPENDENCIES = $(DEPS)
simple_DEPENDENCIES = $(DEPS)
testgtk_LDADD = $(LDADDS)
@@ -332,6 +339,7 @@ testinput_LDADD = $(LDADDS)
testthreads_LDADD = $(LDADDS)
testselection_LDADD = $(LDADDS)
testrgb_LDADD = $(LDADDS)
+testdnd_LDADD = $(LDADDS)
simple_LDADD = $(LDADDS)
.PHONY: files test test-debug
diff --git a/gtk/gtk-boxed.defs b/gtk/gtk-boxed.defs
index 353bc91250..1555e8beee 100644
--- a/gtk/gtk-boxed.defs
+++ b/gtk/gtk-boxed.defs
@@ -42,6 +42,9 @@
gdk_window_ref
gdk_window_unref)
+(define-boxed GdkDragContext
+ gdk_drag_context_ref
+ gdk_drag_context_unref)
(define-boxed GdkEvent
gdk_event_copy
gdk_event_free
diff --git a/gtk/gtk.h b/gtk/gtk.h
index d2129240ac..5ca83e268d 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -44,6 +44,7 @@
#include <gtk/gtkcurve.h>
#include <gtk/gtkdata.h>
#include <gtk/gtkdialog.h>
+#include <gtk/gtkdnd.h>
#include <gtk/gtkdrawingarea.h>
#include <gtk/gtkeditable.h>
#include <gtk/gtkentry.h>
diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c
index b07d953ae2..c8822743a9 100644
--- a/gtk/gtkcolorsel.c
+++ b/gtk/gtkcolorsel.c
@@ -22,6 +22,8 @@
#include <gdk/gdk.h>
#include "gtkcolorsel.h"
#include "gtkhbbox.h"
+#include "gtkdnd.h"
+#include "gtkselection.h"
/*
* If you change the way the color values are stored,
@@ -144,12 +146,23 @@ static gint gtk_color_selection_wheel_events (GtkWidget *area,
static gint gtk_color_selection_wheel_timeout (GtkColorSelection *colorsel);
static void gtk_color_selection_sample_resize (GtkWidget *widget,
gpointer data);
-static void gtk_color_selection_drop_handle (GtkWidget *widget,
- GdkEvent *event,
- GtkWidget *theclorsel);
-static void gtk_color_selection_drag_handle (GtkWidget *widget,
- GdkEvent *event,
- GtkWidget *thecolorsel);
+static void gtk_color_selection_drag_begin (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer data);
+static void gtk_color_selection_drop_handle (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data);
+static void gtk_color_selection_drag_handle (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data);
static void gtk_color_selection_draw_wheel_marker (GtkColorSelection *colorsel);
static void gtk_color_selection_draw_wheel_frame (GtkColorSelection *colorsel);
static void gtk_color_selection_draw_value_marker (GtkColorSelection *colorsel);
@@ -502,7 +515,10 @@ static void
gtk_color_selection_realize (GtkWidget *widget)
{
GtkColorSelection *colorsel;
- gchar *type_accept_list[] = {"application/x-color"};
+
+ GtkTargetEntry targets[] = {
+ { "application/x-color", 0 }
+ };
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_COLOR_SELECTION (widget));
@@ -512,18 +528,30 @@ gtk_color_selection_realize (GtkWidget *widget)
if (GTK_WIDGET_CLASS (color_selection_parent_class)->realize)
(*GTK_WIDGET_CLASS (color_selection_parent_class)->realize) (widget);
- gtk_widget_dnd_drag_set (colorsel->sample_area,
- 1, type_accept_list, 1);
- gtk_widget_dnd_drop_set (colorsel->sample_area,
- 1, type_accept_list, 1, 0);
- gtk_signal_connect_after (GTK_OBJECT (colorsel->sample_area),
- "drop_data_available_event",
- GTK_SIGNAL_FUNC (gtk_color_selection_drop_handle),
- colorsel);
- gtk_signal_connect_after (GTK_OBJECT (colorsel->sample_area),
- "drag_request_event",
- GTK_SIGNAL_FUNC (gtk_color_selection_drag_handle),
- colorsel);
+ gtk_drag_dest_set (colorsel->sample_area,
+ GTK_DEST_DEFAULT_HIGHLIGHT |
+ GTK_DEST_DEFAULT_MOTION |
+ GTK_DEST_DEFAULT_DROP,
+ targets, 1,
+ GDK_ACTION_COPY);
+
+ gtk_drag_source_set (colorsel->sample_area,
+ GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
+ targets, 1,
+ GDK_ACTION_COPY | GDK_ACTION_MOVE);
+
+ gtk_signal_connect (GTK_OBJECT (colorsel->sample_area),
+ "drag_begin",
+ GTK_SIGNAL_FUNC (gtk_color_selection_drag_begin),
+ colorsel);
+ gtk_signal_connect (GTK_OBJECT (colorsel->sample_area),
+ "drag_data_get",
+ GTK_SIGNAL_FUNC (gtk_color_selection_drag_handle),
+ colorsel);
+ gtk_signal_connect (GTK_OBJECT (colorsel->sample_area),
+ "drag_data_received",
+ GTK_SIGNAL_FUNC (gtk_color_selection_drop_handle),
+ colorsel);
}
static void
@@ -824,39 +852,97 @@ gtk_color_selection_sample_resize (GtkWidget *widget,
}
static void
-gtk_color_selection_drop_handle (GtkWidget *widget, GdkEvent *event,
- GtkWidget *thecolorsel)
+gtk_color_selection_drag_begin (GtkWidget *widget,
+ GdkDragContext *context,
+ gpointer data)
+{
+ GtkColorSelection *colorsel = data;
+ GtkWidget *window;
+ gdouble colors[4];
+ GdkColor bg;
+
+ window = gtk_window_new(GTK_WINDOW_POPUP);
+ gtk_widget_set_usize (window, 48, 32);
+ gtk_widget_realize (window);
+
+ gtk_color_selection_get_color (colorsel, colors);
+ bg.red = 0xffff * colors[0];
+ bg.green = 0xffff * colors[1];
+ bg.blue = 0xffff * colors[2];
+
+ gdk_color_alloc (gtk_widget_get_colormap (window), &bg);
+ gdk_window_set_background (window->window, &bg);
+
+ gtk_drag_set_icon_widget (context, window, -2, -2);
+}
+
+static void
+gtk_color_selection_drop_handle (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data)
{
- /* This is currently a gdouble array of the format (I think):
- use_opacity
+ GtkColorSelection *colorsel = data;
+ guint16 *vals;
+ gdouble colors[4];
+
+ /* This is currently a guint16 array of the format:
R
G
B
opacity
*/
- gdouble *v = event->dropdataavailable.data;
- gtk_color_selection_set_opacity(GTK_COLOR_SELECTION(thecolorsel),
- (v[0]==1.0)?TRUE:FALSE);
- gtk_color_selection_set_color(GTK_COLOR_SELECTION(thecolorsel),
- v + 1);
- g_free(event->dropdataavailable.data);
- g_free(event->dropdataavailable.data_type);
+
+ if (selection_data->length < 0)
+ return;
+
+ if ((selection_data->format != 16) ||
+ (selection_data->length != 8))
+ {
+ g_warning ("Received invalid color data\n");
+ return;
+ }
+
+ vals = (guint16 *)selection_data->data;
+
+ colors[0] = (gdouble)vals[0] / 0xffff;
+ colors[1] = (gdouble)vals[1] / 0xffff;
+ colors[2] = (gdouble)vals[2] / 0xffff;
+ colors[3] = (gdouble)vals[3] / 0xffff;
+
+ gtk_color_selection_set_color(colorsel, colors);
}
static void
-gtk_color_selection_drag_handle (GtkWidget *widget, GdkEvent *event,
- GtkWidget *thecolorsel)
+gtk_color_selection_drag_handle (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data)
{
- gdouble sendvals[(BLUE - RED + 1) + 3];
+ GtkColorSelection *colorsel = data;
+ guint16 vals[4];
+ gdouble colors[4];
+
+ gtk_color_selection_get_color(colorsel, colors);
+
+ vals[0] = colors[0] * 0xffff;
+ vals[1] = colors[1] * 0xffff;
+ vals[2] = colors[2] * 0xffff;
+ vals[3] = colorsel->use_opacity ? colors[3] * 0xffff : 0xffff;
- sendvals[0] = (GTK_COLOR_SELECTION(thecolorsel)->use_opacity)?1.0:0.0;
- gtk_color_selection_get_color(GTK_COLOR_SELECTION(thecolorsel),
- sendvals + 1);
+ g_print ("%x %x\n", vals[0], vals[4]);
+ g_print ("%g\n", colorsel->values[OPACITY]);
+ g_print ("%d\n", colorsel->use_opacity);
- gtk_widget_dnd_data_set(widget,
- event,
- (gpointer)sendvals,
- sizeof(sendvals));
+ gtk_selection_data_set (selection_data,
+ gdk_atom_intern ("application/x-color", FALSE),
+ 16, (guchar *)vals, 8);
}
static void
@@ -984,6 +1070,13 @@ gtk_color_selection_value_events (GtkWidget *area,
gtk_color_selection_color_changed (colorsel);
break;
case GDK_MOTION_NOTIFY:
+ /* Even though we select BUTTON_MOTION_MASK, we seem to need
+ * to occasionally get events without buttons pressed.
+ */
+ if (!(event->motion.state &
+ (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)))
+ return FALSE;
+
y = event->motion.y;
if (event->motion.is_hint || (event->motion.window != area->window))
@@ -1074,6 +1167,13 @@ gtk_color_selection_wheel_events (GtkWidget *area,
gtk_color_selection_color_changed (colorsel);
break;
case GDK_MOTION_NOTIFY:
+ /* Even though we select BUTTON_MOTION_MASK, we seem to need
+ * to occasionally get events without buttons pressed.
+ */
+ if (!(event->motion.state &
+ (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)))
+ return FALSE;
+
x = event->motion.x;
y = event->motion.y;
diff --git a/gtk/gtkdebug.h b/gtk/gtkdebug.h
index 545df04256..d85ebfef06 100644
--- a/gtk/gtkdebug.h
+++ b/gtk/gtkdebug.h
@@ -26,7 +26,8 @@ extern "C" {
typedef enum {
GTK_DEBUG_OBJECTS = 1 << 0,
GTK_DEBUG_MISC = 1 << 1,
- GTK_DEBUG_SIGNALS = 1 << 2
+ GTK_DEBUG_SIGNALS = 1 << 2,
+ GTK_DEBUG_DND = 1 << 3
} GtkDebugFlag;
#ifdef G_ENABLE_DEBUG
diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c
new file mode 100644
index 0000000000..e6cda51332
--- /dev/null
+++ b/gtk/gtkdnd.c
@@ -0,0 +1,2343 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gdk/gdkx.h"
+
+#include "gtkdnd.h"
+#include "gtkinvisible.h"
+#include "gtkmain.h"
+#include "gtksignal.h"
+#include "gtkwindow.h"
+
+static GSList *drag_widgets = NULL;
+
+typedef struct _GtkDragSourceSite GtkDragSourceSite;
+typedef struct _GtkDragSourceInfo GtkDragSourceInfo;
+typedef struct _GtkDragDestSite GtkDragDestSite;
+typedef struct _GtkDragDestInfo GtkDragDestInfo;
+typedef struct _GtkDragAnim GtkDragAnim;
+typedef struct _GtkDragFindData GtkDragFindData;
+
+
+typedef enum {
+ GTK_DRAG_STATUS_DRAG,
+ GTK_DRAG_STATUS_WAIT,
+ GTK_DRAG_STATUS_DROP
+} GtkDragStatus;
+
+struct _GtkDragSourceSite {
+ GdkModifierType start_button_mask;
+ GtkTargetList *target_list; /* Targets for drag data */
+ GdkDragAction actions; /* Possible actions */
+ GdkColormap *colormap; /* Colormap for drag icon */
+ GdkPixmap *pixmap; /* Icon for drag data */
+ GdkBitmap *mask;
+
+ /* Stored button press information to detect drag beginning */
+ gint state;
+ gint x, y;
+};
+
+struct _GtkDragSourceInfo {
+ GtkWidget *widget;
+ GtkTargetList *target_list; /* Targets for drag data */
+ GdkDragContext *context; /* drag context */
+ GtkWidget *icon_window; /* Window for drag */
+ GtkWidget *ipc_widget; /* GtkInvisible for grab, message passing */
+ GdkCursor *cursor; /* Cursor for drag */
+ gint hot_x, hot_y; /* Hot spot for drag */
+ gint button; /* mouse button starting drag */
+
+ GtkDragStatus status; /* drag status */
+ GdkEvent *last_event; /* motion event waiting for response */
+
+ gint start_x, start_y; /* Initial position */
+ gint cur_x, cur_y; /* Current Position */
+
+ GList *selections; /* selections we've claimed */
+
+ GtkDragDestInfo *proxy_dest; /* Set if this is a proxy drag */
+
+ guint drop_timeout; /* Timeout for aborting drop */
+};
+
+struct _GtkDragDestSite {
+ GtkDestDefaults flags;
+ GtkTargetList *target_list;
+ GdkDragAction actions;
+ GdkWindow *proxy_window;
+ GdkDragProtocol proxy_protocol;
+ gboolean proxy_coords : 1;
+ gboolean have_drag : 1;
+};
+
+struct _GtkDragDestInfo {
+ GtkWidget *widget; /* Widget in which drag is in */
+ GdkDragContext *context; /* Drag context */
+ GtkDragSourceInfo *proxy_source; /* Set if this is a proxy drag */
+ GtkSelectionData *proxy_data; /* Set while retrieving proxied data */
+ gboolean dropped : 1; /* Set after we receive a drop */
+ guint32 proxy_drop_time; /* Timestamp for proxied drop */
+ gboolean proxy_drop_wait : 1; /* Set if we are waiting for a
+ * status reply before sending
+ * a proxied drop on.
+ */
+ gint drop_x, drop_y; /* Position of drop */
+};
+
+#define DROP_ABORT_TIME 10000
+
+#define ANIM_STEP_TIME 50
+#define ANIM_STEP_LENGTH 50
+#define ANIM_MIN_STEPS 5
+#define ANIM_MAX_STEPS 10
+
+struct _GtkDragAnim {
+ GtkDragSourceInfo *info;
+ gint step;
+ gint n_steps;
+};
+
+struct _GtkDragFindData {
+ gint x;
+ gint y;
+ GdkDragContext *context;
+ GtkDragDestInfo *info;
+ gboolean found;
+ gboolean (*callback) (GtkWidget *widget, GdkDragContext *context,
+ gint x, gint y, guint32 time);
+ guint32 time;
+};
+
+/* Enumeration for some targets we handle internally */
+
+enum {
+ TARGET_MOTIF_SUCCESS = 0x80000000,
+ TARGET_MOTIF_FAILURE,
+ TARGET_DELETE
+};
+
+/* Drag icons */
+
+static GdkPixmap *default_icon_pixmap = NULL;
+static GdkPixmap *default_icon_mask = NULL;
+static GdkColormap *default_icon_colormap = NULL;
+static gint default_icon_hot_x;
+static gint default_icon_hot_y;
+
+/* Forward declarations */
+static GdkDragAction gtk_drag_get_event_action (GdkEvent *event,
+ gint button,
+ GdkDragAction actions);
+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,
+ GdkDragContext *context);
+static void gtk_drag_selection_received (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint32 time,
+ gpointer data);
+static void gtk_drag_find_widget (GtkWidget *widget,
+ GtkDragFindData *data);
+static void gtk_drag_proxy_begin (GtkWidget *widget,
+ GtkDragDestInfo *dest_info);
+static void gtk_drag_dest_info_destroy (gpointer data);
+static void gtk_drag_dest_realized (GtkWidget *widget);
+static void gtk_drag_dest_site_destroy (gpointer data);
+static void gtk_drag_dest_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time);
+static gboolean gtk_drag_dest_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+static gboolean gtk_drag_dest_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+
+static void gtk_drag_source_check_selection (GtkDragSourceInfo *info,
+ GdkAtom selection,
+ guint32 time);
+static void gtk_drag_source_release_selections (GtkDragSourceInfo *info,
+ guint32 time);
+static void gtk_drag_drop (GtkDragSourceInfo *info,
+ guint32 time);
+static void gtk_drag_drop_finished (GtkDragSourceInfo *info,
+ gboolean success,
+ guint time);
+
+static gint gtk_drag_source_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer data);
+static void gtk_drag_source_site_destroy (gpointer data);
+static void gtk_drag_selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint sel_info,
+ guint32 time,
+ gpointer data);
+static gint gtk_drag_anim_timeout (gpointer data);
+static void gtk_drag_remove_icon (GtkDragSourceInfo *info);
+static void gtk_drag_source_info_destroy (gpointer data);
+static gint gtk_drag_motion_cb (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer data);
+static gint gtk_drag_button_release_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer data);
+static gint gtk_drag_abort_timeout (gpointer data);
+
+/************************
+ * Cursor and Icon data *
+ ************************/
+
+#define action_ask_width 16
+#define action_ask_height 16
+static char action_ask_bits[] = {
+ 0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x76, 0xf8, 0xb6, 0xf7,
+ 0xd6, 0xec, 0x66, 0xdb, 0x66, 0xdb, 0x96, 0xec, 0x76, 0xf7, 0x76, 0xfb,
+ 0xf6, 0xfc, 0x72, 0xfb, 0x7a, 0xfb, 0xf8, 0xfc, };
+
+#define action_ask_mask_width 16
+#define action_ask_mask_height 16
+static char action_ask_mask_bits[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x8f, 0x07, 0xcf, 0x0f,
+ 0xef, 0x1f, 0xff, 0x3c, 0xff, 0x3c, 0x6f, 0x1f, 0x8f, 0x0f, 0x8f, 0x07,
+ 0x0f, 0x03, 0x8f, 0x07, 0x87, 0x07, 0x07, 0x03, };
+
+#define action_copy_width 16
+#define action_copy_height 16
+static char action_copy_bits[] = {
+ 0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x76, 0xfb, 0x76, 0xfb,
+ 0x76, 0xfb, 0x06, 0x83, 0xf6, 0xbf, 0xf6, 0xbf, 0x06, 0x83, 0x76, 0xfb,
+ 0x76, 0xfb, 0x72, 0xfb, 0x7a, 0xf8, 0xf8, 0xff, };
+
+#define action_copy_mask_width 16
+#define action_copy_mask_height 16
+static char action_copy_mask_bits[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x8f, 0x07, 0x8f, 0x07,
+ 0x8f, 0x07, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f, 0x8f, 0x07,
+ 0x8f, 0x07, 0x8f, 0x07, 0x87, 0x07, 0x07, 0x00, };
+
+#define action_move_width 16
+#define action_move_height 16
+static char action_move_bits[] = {
+ 0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x96, 0xff, 0x26, 0xff,
+ 0xc6, 0xf8, 0xd6, 0xe3, 0x96, 0x8f, 0xb6, 0xbf, 0x36, 0xc3, 0x76, 0xfb,
+ 0x76, 0xfa, 0xf2, 0xfa, 0xfa, 0xf8, 0xf8, 0xff, };
+
+#define action_move_mask_width 16
+#define action_move_mask_height 16
+static char action_move_mask_bits[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x6f, 0x00, 0xff, 0x00,
+ 0xff, 0x07, 0xef, 0x1f, 0xef, 0x7f, 0xcf, 0x7f, 0xcf, 0x3f, 0x8f, 0x07,
+ 0x8f, 0x07, 0x0f, 0x07, 0x07, 0x07, 0x07, 0x00, };
+
+#define action_link_width 16
+#define action_link_height 16
+static char action_link_bits[] = {
+ 0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0x36, 0xf8, 0xd6, 0xf7,
+ 0x66, 0xec, 0xa6, 0xe8, 0x26, 0xdf, 0xe6, 0xbd, 0xd6, 0xa7, 0xb6, 0xa8,
+ 0xb6, 0xb1, 0x72, 0xdf, 0xfa, 0xe0, 0xf8, 0xff, };
+
+#define action_link_mask_width 16
+#define action_link_mask_height 16
+static char action_link_mask_bits[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0xcf, 0x07, 0xef, 0x0f,
+ 0xff, 0x1f, 0x7f, 0x1f, 0xff, 0x3f, 0xff, 0x7f, 0xef, 0x7f, 0xcf, 0x77,
+ 0xcf, 0x7f, 0x8f, 0x3f, 0x07, 0x1f, 0x07, 0x00, };
+
+#define action_none_width 16
+#define action_none_height 16
+static char action_none_bits[] = {
+ 0x00, 0x00, 0xfe, 0x7f, 0xfe, 0x1f, 0x06, 0xc0, 0xf6, 0xff, 0xf6, 0xff,
+ 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff, 0xf6, 0xff,
+ 0xf6, 0xff, 0xf2, 0xff, 0xfa, 0xff, 0xf8, 0xff, };
+
+#define action_none_mask_width 16
+#define action_none_mask_height 16
+static char action_none_mask_bits[] = {
+ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3f, 0x0f, 0x00, 0x0f, 0x00,
+ 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00, 0x0f, 0x00,
+ 0x0f, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x07, 0x00, };
+
+static char empty_bits[] = {
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
+
+#define CURSOR_WIDTH 16
+#define CURSOR_HEIGHT 16
+
+static struct {
+ GdkDragAction action;
+ char *bits;
+ char *mask;
+ GdkCursor *cursor;
+} drag_cursors[] = {
+ { GDK_ACTION_DEFAULT, 0 },
+ { GDK_ACTION_ASK, action_ask_bits, action_ask_mask_bits, NULL },
+ { GDK_ACTION_COPY, action_copy_bits, action_copy_mask_bits, NULL },
+ { GDK_ACTION_MOVE, action_move_bits, action_move_mask_bits, NULL },
+ { GDK_ACTION_LINK, action_link_bits, action_link_mask_bits, NULL },
+ { 0 , action_none_bits, action_none_mask_bits, NULL },
+};
+
+static gint n_drag_cursors = sizeof(drag_cursors) / sizeof(drag_cursors[0]);
+
+/* XPM */
+static char * drag_default_xpm[] = {
+"32 32 3 1",
+" c None",
+". c #000000",
+"+ c #FFFFFF",
+" ",
+" ",
+" .. ",
+" ..+. ",
+" ..++.. ",
+" ...++++. ",
+" ...++++++.. ",
+" ...+++++++++. ",
+" ...+++++++++++.. ",
+" ..+.++++++++++++.. ",
+" .++.++++++++++++.. ",
+" .+++.++++++++++++.. ",
+" .++++.++++++++++++. ",
+" .+++.+++++++++++++.. ",
+" .++.+++++++++++++++.. ",
+" .+.+++++++++++++++++.. ",
+" ..+++++++++++++++++++.. ",
+" ..++++++++++++++++++++. ",
+" .++++++++++++++++++++.. ",
+" ..+++++++++++++++++.. ",
+" .++++++++++++++++.. ",
+" ..+++++++++++++... ",
+" .++++++++++++.. ",
+" ..+++++++++.. ",
+" .++++++++.. ",
+" ..++++++.. ",
+" .+++++.. ",
+" .++.. ",
+" ... ",
+" .. ",
+" ",
+" "};
+
+/*********************
+ * Utility functions *
+ *********************/
+
+/*************************************************************
+ * gtk_drag_get_ipc_widget:
+ * Return a invisible, off-screen, override-redirect
+ * widget for IPC.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static GtkWidget *
+gtk_drag_get_ipc_widget(void)
+{
+ GtkWidget *result;
+
+ if (drag_widgets)
+ {
+ GSList *tmp = drag_widgets;
+ result = drag_widgets->data;
+ drag_widgets = drag_widgets->next;
+ g_slist_free_1 (tmp);
+ }
+ else
+ {
+ result = gtk_invisible_new();
+ gtk_widget_show (result);
+ }
+
+ return result;
+}
+
+/*************************************************************
+ * gtk_drag_release_ipc_widget:
+ * Releases widget retrieved with gtk_drag_get_ipc_widget()
+ * arguments:
+ * widget: the widget to release.
+ * results:
+ *************************************************************/
+
+static void
+gtk_drag_release_ipc_widget (GtkWidget *widget)
+{
+ drag_widgets = g_slist_prepend (drag_widgets, widget);
+}
+
+static GdkDragAction
+gtk_drag_get_event_action (GdkEvent *event, gint button, GdkDragAction actions)
+{
+ if (event)
+ {
+ GdkModifierType state = 0;
+
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ state = event->motion.state;
+ break;
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ state = event->button.state;
+ break;
+ case GDK_KEY_PRESS:
+ case GDK_KEY_RELEASE:
+ state = event->key.state;
+ break;
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ state = event->crossing.state;
+ break;
+ default:
+ break;
+ }
+
+ if (button == 3)
+ return GDK_ACTION_ASK;
+
+ if (state & (GDK_SHIFT_MASK | GDK_CONTROL_MASK))
+ {
+ if ((state & GDK_SHIFT_MASK) && (state & GDK_CONTROL_MASK))
+ return (actions & GDK_ACTION_LINK) ? GDK_ACTION_LINK : 0;
+ else if (state & GDK_CONTROL_MASK)
+ return (actions & GDK_ACTION_COPY) ? GDK_ACTION_COPY : 0;
+ else
+ return (actions & GDK_ACTION_MOVE) ? GDK_ACTION_MOVE : 0;
+ }
+ else
+ {
+ if (actions & GDK_ACTION_COPY)
+ return GDK_ACTION_COPY;
+ else if (actions & GDK_ACTION_MOVE)
+ return GDK_ACTION_MOVE;
+ else if (actions & GDK_ACTION_LINK)
+ return GDK_ACTION_LINK;
+ }
+ }
+
+ return 0;
+}
+
+static GdkCursor *
+gtk_drag_get_cursor (GdkDragAction action)
+{
+ gint i;
+
+ for (i = 0 ; i < n_drag_cursors - 1; i++)
+ if (drag_cursors[i].action == action)
+ break;
+
+ if (drag_cursors[i].cursor == NULL)
+ {
+ GdkColor fg, bg;
+
+ GdkPixmap *pixmap =
+ gdk_bitmap_create_from_data (NULL,
+ drag_cursors[i].bits,
+ CURSOR_WIDTH, CURSOR_HEIGHT);
+ GdkPixmap *mask =
+ gdk_bitmap_create_from_data (NULL,
+ drag_cursors[i].mask,
+ CURSOR_WIDTH, CURSOR_HEIGHT);
+
+ gdk_color_white (gdk_colormap_get_system(), &bg);
+ gdk_color_black (gdk_colormap_get_system(), &fg);
+
+ drag_cursors[i].cursor = gdk_cursor_new_from_pixmap (pixmap, mask, &fg, &bg, 0, 0);
+
+ gdk_pixmap_unref (pixmap);
+ gdk_pixmap_unref (mask);
+ }
+
+ return drag_cursors[i].cursor;
+}
+
+/********************
+ * Destination side *
+ ********************/
+
+/*************************************************************
+ * gtk_drag_get_data:
+ * Get the data for a drag or drop
+ * arguments:
+ * context - drag context
+ * target - format to retrieve the data in.
+ * time - timestamp of triggering event.
+ *
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_get_data (GtkWidget *widget,
+ GdkDragContext *context,
+ GdkAtom target,
+ guint32 time)
+{
+ GtkWidget *selection_widget;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (context != NULL);
+
+ selection_widget = gtk_drag_get_ipc_widget();
+
+ gdk_drag_context_ref (context);
+ gtk_widget_ref (widget);
+
+ gtk_signal_connect (GTK_OBJECT (selection_widget), "selection_received",
+ GTK_SIGNAL_FUNC (gtk_drag_selection_received), widget);
+
+ gtk_object_set_data (GTK_OBJECT (selection_widget), "drag-context", context);
+
+ gtk_selection_convert (selection_widget,
+ gdk_drag_get_selection(context),
+ target,
+ time);
+}
+
+/*************************************************************
+ * gtk_drag_finish:
+ * Notify the drag source that the transfer of data
+ * is complete.
+ * arguments:
+ * context: The drag context for this drag
+ * success: Was the data successfully transferred?
+ * time: The timestamp to use when notifying the destination.
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_finish (GdkDragContext *context,
+ gboolean success,
+ gboolean delete,
+ guint32 time)
+{
+ GdkAtom target = GDK_NONE;
+
+ g_return_if_fail (context != NULL);
+
+ if (success && delete)
+ {
+ target = gdk_atom_intern ("DELETE", FALSE);
+ }
+ else if (context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ target = gdk_atom_intern (success ?
+ "XmTRANSFER_SUCCESS" :
+ "XmTRANSFER_FAILURE",
+ FALSE);
+ }
+
+ if (target != GDK_NONE)
+ {
+ GtkWidget *selection_widget = gtk_drag_get_ipc_widget();
+
+ gdk_drag_context_ref (context);
+
+ gtk_object_set_data (GTK_OBJECT (selection_widget), "drag-context", context);
+ gtk_signal_connect (GTK_OBJECT (selection_widget), "selection_received",
+ GTK_SIGNAL_FUNC (gtk_drag_selection_received),
+ NULL);
+
+ gtk_selection_convert (selection_widget,
+ gdk_drag_get_selection(context),
+ target,
+ time);
+ }
+
+ if (!delete)
+ gdk_drop_finish (context, success, time);
+}
+
+/*************************************************************
+ * gtk_drag_highlight:
+ * Highlight the given widget in the default manner.
+ * arguments:
+ * widget:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_highlight (GtkWidget *widget)
+{
+ gint x, y;
+
+ g_return_if_fail (widget != NULL);
+
+ if (GTK_WIDGET_NO_WINDOW (widget))
+ {
+ x = widget->allocation.x;
+ y = widget->allocation.y;
+ }
+ else
+ {
+ x = 0;
+ y = 0;
+ }
+
+ gtk_draw_shadow (widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_OUT,
+ x, y,
+ widget->allocation.width,
+ widget->allocation.height);
+
+ gdk_draw_rectangle (widget->window,
+ widget->style->black_gc,
+ FALSE,
+ x, y,
+ widget->allocation.width - 1,
+ widget->allocation.height - 1);
+}
+
+/*************************************************************
+ * gtk_drag_unhighlight:
+ * Refresh the given widget to remove the highlight.
+ * arguments:
+ * widget:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_unhighlight (GtkWidget *widget)
+{
+ gint x, y;
+
+ g_return_if_fail (widget != NULL);
+
+ if (GTK_WIDGET_NO_WINDOW (widget))
+ {
+ x = widget->allocation.x;
+ y = widget->allocation.y;
+ }
+ else
+ {
+ x = 0;
+ y = 0;
+ }
+
+ gdk_window_clear_area_e (widget->window,
+ x, y,
+ widget->allocation.width,
+ widget->allocation.height);
+}
+
+/*************************************************************
+ * gtk_drag_dest_set:
+ * Register a drop site, and possibly add default behaviors.
+ * arguments:
+ * widget:
+ * flags: Which types of default drag behavior to use
+ * targets: Table of targets that can be accepted
+ * n_targets: Number of of entries in targets
+ * actions:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_dest_set (GtkWidget *widget,
+ GtkDestDefaults flags,
+ GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions)
+{
+ GtkDragDestSite *site;
+
+ g_return_if_fail (widget != NULL);
+
+ /* HACK, do this in the destroy */
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");
+ if (site)
+ gtk_signal_disconnect_by_data (GTK_OBJECT (widget), site);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gtk_drag_dest_realized (widget);
+
+ gtk_signal_connect (GTK_OBJECT (widget), "realize",
+ GTK_SIGNAL_FUNC (gtk_drag_dest_realized), NULL);
+
+ site = g_new (GtkDragDestSite, 1);
+
+ site->flags = flags;
+ site->have_drag = FALSE;
+ if (targets)
+ site->target_list = gtk_target_list_new (targets, n_targets);
+ else
+ site->target_list = NULL;
+
+ site->actions = actions;
+ site->proxy_window = NULL;
+
+ gtk_object_set_data_full (GTK_OBJECT (widget), "gtk-drag-dest",
+ site, gtk_drag_dest_site_destroy);
+}
+
+/*************************************************************
+ * gtk_drag_dest_set_proxy:
+ * Set up this widget to proxy drags elsewhere.
+ * arguments:
+ * widget:
+ * proxy_window: window to which forward drag events
+ * protocol: Drag protocol which the dest widget accepts
+ * use_coordinates: If true, send the same coordinates to the
+ * destination, because it is a embedded
+ * subwindow.
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_dest_set_proxy (GtkWidget *widget,
+ GdkWindow *proxy_window,
+ GdkDragProtocol protocol,
+ gboolean use_coordinates)
+{
+ GtkDragDestSite *site;
+
+ g_return_if_fail (widget != NULL);
+
+ /* HACK, do this in the destroy */
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");
+ if (site)
+ gtk_signal_disconnect_by_data (GTK_OBJECT (widget), site);
+
+ if (GTK_WIDGET_REALIZED (widget))
+ gtk_drag_dest_realized (widget);
+
+ gtk_signal_connect (GTK_OBJECT (widget), "realize",
+ GTK_SIGNAL_FUNC (gtk_drag_dest_realized), NULL);
+
+ site = g_new (GtkDragDestSite, 1);
+
+ site->flags = 0;
+ site->have_drag = FALSE;
+ site->target_list = NULL;
+ site->actions = 0;
+ site->proxy_window = proxy_window;
+ gdk_window_ref (proxy_window);
+ site->proxy_protocol = protocol;
+ site->proxy_coords = use_coordinates;
+
+ gtk_object_set_data_full (GTK_OBJECT (widget), "gtk-drag-dest",
+ site, gtk_drag_dest_site_destroy);
+}
+
+/*************************************************************
+ * gtk_drag_dest_unset
+ * Unregister this widget as a drag target.
+ * arguments:
+ * widget:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_dest_unset (GtkWidget *widget)
+{
+ g_return_if_fail (widget != NULL);
+
+ gtk_object_set_data (GTK_OBJECT (widget), "gtk-drag-dest", NULL);
+}
+
+/*************************************************************
+ * gtk_drag_dest_handle_event:
+ * Called from widget event handling code on Drag events
+ * for destinations.
+ *
+ * arguments:
+ * toplevel: Toplevel widget that received the event
+ * event:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_dest_handle_event (GtkWidget *toplevel,
+ GdkEvent *event)
+{
+ GtkDragDestInfo *info;
+ GdkDragContext *context;
+
+ g_return_if_fail (toplevel != NULL);
+ g_return_if_fail (event != NULL);
+
+ context = event->dnd.context;
+
+ info = g_dataset_get_data (context, "gtk-info");
+ if (!info)
+ {
+ info = g_new (GtkDragDestInfo, 1);
+ info->widget = NULL;
+ info->context = event->dnd.context;
+ info->proxy_source = NULL;
+ info->proxy_data = NULL;
+ info->dropped = FALSE;
+ info->proxy_drop_wait = FALSE;
+ g_dataset_set_data_full (context,
+ "gtk-info",
+ info,
+ gtk_drag_dest_info_destroy);
+ }
+
+ /* Find the widget for the event */
+ switch (event->type)
+ {
+ case GDK_DRAG_ENTER:
+ break;
+
+ case GDK_DRAG_LEAVE:
+ if (info->widget)
+ {
+ gtk_drag_dest_leave (info->widget, context, event->dnd.time);
+ info->widget = NULL;
+ }
+ break;
+
+ case GDK_DRAG_MOTION:
+ case GDK_DROP_START:
+ {
+ GtkDragFindData data;
+ gint tx, ty;
+
+ if (event->type == GDK_DROP_START)
+ info->dropped = TRUE;
+
+ gdk_window_get_position (toplevel->window, &tx, &ty);
+
+ data.x = event->dnd.x_root - tx;
+ data.y = event->dnd.y_root - ty;
+ data.context = context;
+ data.info = info;
+ data.found = FALSE;
+ data.callback = (event->type == GDK_DRAG_MOTION) ?
+ gtk_drag_dest_motion : gtk_drag_dest_drop;
+ data.time = event->dnd.time;
+
+ gtk_drag_find_widget (toplevel, &data);
+
+ /* We send a leave here so that the widget unhighlights
+ * properly
+ */
+ if (info->widget &&
+ ((event->type == GDK_DROP_START) || (!data.found)))
+ {
+ gtk_drag_dest_leave (info->widget, context, event->dnd.time);
+ info->widget = NULL;
+ }
+
+ /* Send a reply.
+ */
+ if (event->type == GDK_DRAG_MOTION)
+ {
+ if (!data.found)
+ gdk_drag_status (context, 0, event->dnd.time);
+ }
+ else if (event->type == GDK_DROP_START)
+ gdk_drop_reply (context, data.found, event->dnd.time);
+ }
+ break;
+
+ default:
+ g_assert_not_reached();
+ }
+}
+
+/*************************************************************
+ * gtk_drag_dest_find_target:
+ * Decide on a target for the drag.
+ * arguments:
+ * site:
+ * context:
+ * results:
+ *************************************************************/
+
+static GdkAtom
+gtk_drag_dest_find_target (GtkDragDestSite *site,
+ GdkDragContext *context)
+{
+ GList *tmp_target;
+ GList *tmp_source = NULL;
+
+ tmp_target = site->target_list->list;
+ while (tmp_target)
+ {
+ GtkTargetPair *pair = tmp_target->data;
+ tmp_source = context->targets;
+ while (tmp_source)
+ {
+ if (tmp_source->data == GUINT_TO_POINTER (pair->target))
+ return pair->target;
+ tmp_source = tmp_source->next;
+ }
+ tmp_target = tmp_target->next;
+ }
+
+ return GDK_NONE;
+}
+
+static void
+gtk_drag_selection_received (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint32 time,
+ gpointer data)
+{
+ GdkDragContext *context;
+ GtkDragDestInfo *info;
+ GtkWidget *drop_widget;
+
+ drop_widget = data;
+
+ context = gtk_object_get_data (GTK_OBJECT (widget), "drag-context");
+ info = g_dataset_get_data (context, "gtk-info");
+
+ if (info->proxy_data &&
+ info->proxy_data->target == selection_data->target)
+ {
+ gtk_selection_data_set (info->proxy_data,
+ selection_data->type,
+ selection_data->format,
+ selection_data->data,
+ selection_data->length);
+ gtk_main_quit();
+ return;
+ }
+
+ if (selection_data->target == gdk_atom_intern ("DELETE", FALSE))
+ {
+ gtk_drag_finish (context, TRUE, FALSE, time);
+ }
+ else if ((selection_data->target == gdk_atom_intern ("XmTRANSFER_SUCCESS", FALSE)) ||
+ (selection_data->target == gdk_atom_intern ("XmTRANSFER_SUCCESS", FALSE)))
+ {
+ /* Do nothing */
+ }
+ else
+ {
+ GtkDragDestSite *site;
+
+ site = gtk_object_get_data (GTK_OBJECT (drop_widget), "gtk-drag-dest");
+
+ if (site->target_list)
+ {
+ guint target_info;
+
+ if (gtk_target_list_find (site->target_list,
+ selection_data->target,
+ &target_info))
+ {
+ if (!(site->flags & GTK_DEST_DEFAULT_DROP) ||
+ selection_data->length >= 0)
+ gtk_signal_emit_by_name (GTK_OBJECT (drop_widget),
+ "drag_data_received",
+ context, info->drop_x, info->drop_y,
+ selection_data,
+ target_info, time);
+ }
+ }
+ else
+ {
+ gtk_signal_emit_by_name (GTK_OBJECT (drop_widget),
+ "drag_data_received",
+ context, info->drop_x, info->drop_y,
+ selection_data, 0, time);
+ }
+
+ if (site->flags & GTK_DEST_DEFAULT_DROP)
+ {
+
+ gtk_drag_finish (context,
+ (selection_data->length >= 0),
+ (context->action == GDK_ACTION_MOVE),
+ time);
+ }
+
+ gtk_widget_unref (drop_widget);
+ }
+
+ gtk_signal_disconnect_by_func (GTK_OBJECT (widget),
+ GTK_SIGNAL_FUNC (gtk_drag_selection_received),
+ data);
+
+ gtk_object_set_data (GTK_OBJECT (widget), "drag-context", NULL);
+ gdk_drag_context_unref (context);
+
+ gtk_drag_release_ipc_widget (widget);
+}
+
+/*************************************************************
+ * gtk_drag_find_widget:
+ * Recursive callback used to locate widgets for
+ * DRAG_MOTION and DROP_START events.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static void
+gtk_drag_find_widget (GtkWidget *widget,
+ GtkDragFindData *data)
+{
+ GtkAllocation new_allocation;
+ gint x_offset = 0;
+ gint y_offset = 0;
+
+ new_allocation = widget->allocation;
+
+ if (!GTK_WIDGET_VISIBLE (widget))
+ return;
+
+ if (!GTK_WIDGET_NO_WINDOW (widget))
+ {
+ new_allocation.x = 0;
+ new_allocation.y = 0;
+ }
+
+ if (widget->parent)
+ {
+ GdkWindow *window = widget->window;
+ while (window != widget->parent->window)
+ {
+ gint tx, ty, twidth, theight;
+ gdk_window_get_size (window, &twidth, &theight);
+
+ if (new_allocation.x < 0)
+ {
+ new_allocation.width += new_allocation.x;
+ new_allocation.x = 0;
+ }
+ if (new_allocation.y < 0)
+ {
+ new_allocation.height += new_allocation.y;
+ new_allocation.y = 0;
+ }
+ if (new_allocation.x + new_allocation.width > twidth)
+ new_allocation.width = twidth - new_allocation.x;
+ if (new_allocation.y + new_allocation.height > theight)
+ new_allocation.height = theight - new_allocation.y;
+
+ gdk_window_get_position (window, &tx, &ty);
+ new_allocation.x += tx;
+ x_offset += tx;
+ new_allocation.y += ty;
+ y_offset += ty;
+
+ window = gdk_window_get_parent (window);
+ }
+ }
+
+ if ((data->x >= new_allocation.x) && (data->y >= new_allocation.y) &&
+ (data->x < new_allocation.x + new_allocation.width) &&
+ (data->y < new_allocation.y + new_allocation.height))
+ {
+ /* First, check if the drag is in a valid drop site in
+ * one of our children
+ */
+ if (GTK_IS_CONTAINER (widget))
+ {
+ GtkDragFindData new_data = *data;
+
+ new_data.x -= x_offset;
+ new_data.y -= y_offset;
+ new_data.found = FALSE;
+
+ gtk_container_foreach (GTK_CONTAINER (widget),
+ (GtkCallback)gtk_drag_find_widget,
+ &new_data);
+
+ data->found = new_data.found;
+ }
+
+ /* If not, and this widget is registered as a drop site, check to
+ * emit "drag_motion" to check if we are actually in
+ * a drop site.
+ */
+ if (!data->found &&
+ gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest"))
+ {
+ data->found = data->callback (widget,
+ data->context,
+ data->x - new_allocation.x,
+ data->y - new_allocation.y,
+ data->time);
+ /* If so, send a "drag_leave" to the last widget */
+ if (data->found)
+ {
+ if (data->info->widget && data->info->widget != widget)
+ {
+ gtk_drag_dest_leave (data->info->widget, data->context, data->time);
+ }
+ data->info->widget = widget;
+ }
+ }
+ }
+}
+
+static void
+gtk_drag_proxy_begin (GtkWidget *widget, GtkDragDestInfo *dest_info)
+{
+ GtkDragSourceInfo *source_info;
+ GList *tmp_list;
+
+ source_info = g_new0 (GtkDragSourceInfo, 1);
+ source_info->ipc_widget = gtk_drag_get_ipc_widget ();
+
+ source_info->widget = widget;
+ gtk_widget_ref (source_info->widget);
+ source_info->context = gdk_drag_begin (source_info->ipc_widget->window,
+ dest_info->context->targets,
+ dest_info->context->actions);
+
+ source_info->target_list = gtk_target_list_new (NULL, 0);
+ tmp_list = dest_info->context->targets;
+ while (tmp_list)
+ {
+ gtk_target_list_add (source_info->target_list,
+ GPOINTER_TO_UINT (tmp_list->data), 0, 0);
+ tmp_list = tmp_list->next;
+ }
+
+ source_info->proxy_dest = dest_info;
+
+ g_dataset_set_data (source_info->context, "gtk-info", source_info);
+
+ gtk_signal_connect (GTK_OBJECT (source_info->ipc_widget),
+ "selection_get",
+ GTK_SIGNAL_FUNC (gtk_drag_selection_get),
+ source_info);
+
+ dest_info->proxy_source = source_info;
+}
+
+static void
+gtk_drag_dest_info_destroy (gpointer data)
+{
+ GtkDragDestInfo *info = data;
+
+ g_free (info);
+}
+
+static void
+gtk_drag_dest_realized (GtkWidget *widget)
+{
+ GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
+ gdk_window_register_dnd (toplevel->window);
+}
+
+static void
+gtk_drag_dest_site_destroy (gpointer data)
+{
+ GtkDragDestSite *site = data;
+
+ if (site->target_list)
+ gtk_target_list_unref (site->target_list);
+
+ g_free (site);
+}
+
+/*
+ * Default drag handlers
+ */
+static void
+gtk_drag_dest_leave (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time)
+{
+ GtkDragDestSite *site;
+
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");
+ g_return_if_fail (site != NULL);
+
+ if (site->proxy_window)
+ {
+ GtkDragDestInfo *info = g_dataset_get_data (context, "gtk-info");
+
+ if (info->proxy_source && !info->dropped)
+ gdk_drag_abort (info->proxy_source->context, time);
+
+ return;
+ }
+ else if (site->have_drag)
+ {
+ site->have_drag = FALSE;
+
+ if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
+ gtk_drag_unhighlight (widget);
+
+ gtk_signal_emit_by_name (GTK_OBJECT (widget), "drag_leave",
+ context, time);
+ }
+}
+
+static gboolean
+gtk_drag_dest_motion (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
+{
+ GtkDragDestSite *site;
+ GdkDragAction action = 0;
+ gboolean retval;
+
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");
+ g_return_val_if_fail (site != NULL, FALSE);
+
+ if (site->proxy_window)
+ {
+ GdkAtom selection;
+ GdkEvent *current_event;
+ GtkDragDestInfo *info = g_dataset_get_data (context, "gtk-info");
+
+ if (!info->proxy_source)
+ gtk_drag_proxy_begin (widget, info);
+
+ current_event = gtk_get_current_event ();
+
+ gdk_drag_motion (info->proxy_source->context,
+ site->proxy_window,
+ site->proxy_protocol,
+ current_event->dnd.x_root,
+ current_event->dnd.y_root,
+ context->suggested_action, time);
+
+ selection = gdk_drag_get_selection (info->proxy_source->context);
+ if (selection &&
+ selection != gdk_drag_get_selection (info->context))
+ gtk_drag_source_check_selection (info->proxy_source, selection, time);
+
+ gdk_event_free (current_event);
+
+ return TRUE;
+ }
+
+ if (site->flags & GTK_DEST_DEFAULT_MOTION)
+ {
+ if (context->suggested_action & site->actions)
+ action = context->suggested_action;
+ else
+ {
+ gint i;
+
+ for (i=0; i<8; i++)
+ {
+ if ((site->actions & (1 << i)) &&
+ (context->actions & (1 << i)))
+ {
+ action = (1 << i);
+ break;
+ }
+ }
+ }
+
+ if (action && gtk_drag_dest_find_target (site, context))
+ {
+ if (!site->have_drag)
+ {
+ site->have_drag = TRUE;
+ if (site->flags & GTK_DEST_DEFAULT_HIGHLIGHT)
+ gtk_drag_highlight (widget);
+ }
+
+ gdk_drag_status (context, action, time);
+ }
+ else
+ {
+ gdk_drag_status (context, 0, time);
+ return TRUE;
+ }
+ }
+
+ gtk_signal_emit_by_name (GTK_OBJECT (widget), "drag_motion",
+ context, x, y, time, &retval);
+
+ return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
+}
+
+static gboolean
+gtk_drag_dest_drop (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time)
+{
+ GtkDragDestSite *site;
+ GtkDragDestInfo *info;
+
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-drag-dest");
+ g_return_val_if_fail (site != NULL, FALSE);
+
+ info = g_dataset_get_data (context, "gtk-info");
+ g_return_val_if_fail (info != NULL, FALSE);
+
+ info->drop_x = x;
+ info->drop_y = y;
+
+ if (site->proxy_window)
+ {
+ if (info->proxy_source ||
+ (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN))
+ {
+ gtk_drag_drop (info->proxy_source, time);
+ }
+ else
+ {
+ /* We need to synthesize a motion event, wait for a status,
+ * and, if we get one a good one, do a drop.
+ */
+
+ GdkEvent *current_event;
+ GdkAtom selection;
+
+ gtk_drag_proxy_begin (widget, info);
+ info->proxy_drop_wait = TRUE;
+ info->proxy_drop_time = time;
+
+ current_event = gtk_get_current_event ();
+
+ gdk_drag_motion (info->proxy_source->context,
+ site->proxy_window,
+ site->proxy_protocol,
+ current_event->dnd.x_root,
+ current_event->dnd.y_root,
+ context->suggested_action, time);
+
+ selection = gdk_drag_get_selection (info->proxy_source->context);
+ if (selection &&
+ selection != gdk_drag_get_selection (info->context))
+ gtk_drag_source_check_selection (info->proxy_source, selection, time);
+
+ gdk_event_free (current_event);
+
+ }
+
+ return TRUE;
+ }
+ else
+ {
+ gboolean retval;
+
+ if (site->flags & GTK_DEST_DEFAULT_MOTION)
+ {
+ GdkAtom target = gtk_drag_dest_find_target (site, context);
+
+ if (target == GDK_NONE)
+ return FALSE;
+
+ gtk_drag_get_data (widget, context, target, time);
+ }
+
+ gtk_signal_emit_by_name (GTK_OBJECT (widget), "drag_drop",
+ context, x, y, time, &retval);
+
+ return (site->flags & GTK_DEST_DEFAULT_MOTION) ? TRUE : retval;
+ }
+}
+
+/***************
+ * Source side *
+ ***************/
+
+/*************************************************************
+ * gtk_drag_begin: Start a drag operation
+ *
+ * arguments:
+ * widget: Widget from which drag starts
+ * handlers: List of handlers to supply the data for the drag
+ * button: Button user used to start drag
+ * time: Time of event starting drag
+ *
+ * results:
+ *************************************************************/
+
+GdkDragContext *
+gtk_drag_begin (GtkWidget *widget,
+ GtkTargetList *target_list,
+ GdkDragAction actions,
+ gint button,
+ GdkEvent *event)
+{
+ GtkDragSourceInfo *info;
+ GList *targets = NULL;
+ GList *tmp_list;
+ guint32 time = GDK_CURRENT_TIME;
+
+ g_return_val_if_fail (widget != NULL, NULL);
+ g_return_val_if_fail (GTK_WIDGET_REALIZED (widget), NULL);
+ g_return_val_if_fail (target_list != NULL, NULL);
+
+ if (event)
+ time = gdk_event_get_time (event);
+
+ info = g_new0 (GtkDragSourceInfo, 1);
+ info->ipc_widget = gtk_drag_get_ipc_widget ();
+
+ tmp_list = g_list_last (target_list->list);
+ while (tmp_list)
+ {
+ GtkTargetPair *pair = tmp_list->data;
+ targets = g_list_prepend (targets,
+ GINT_TO_POINTER (pair->target));
+ tmp_list = tmp_list->prev;
+ }
+
+ info->widget = widget;
+ gtk_widget_ref (info->widget);
+
+ info->context = gdk_drag_begin (info->ipc_widget->window,
+ targets, actions);
+ g_list_free (targets);
+
+ g_dataset_set_data (info->context, "gtk-info", info);
+
+ info->button = button;
+ info->target_list = target_list;
+ gtk_target_list_ref (target_list);
+
+ info->cursor = NULL;
+ info->status = GTK_DRAG_STATUS_DRAG;
+ info->last_event = NULL;
+ info->selections = NULL;
+ info->icon_window = NULL;
+
+ if (event)
+ info->cursor = gtk_drag_get_cursor (
+ gtk_drag_get_event_action (event, info->button, actions));
+
+ gtk_signal_emit_by_name (GTK_OBJECT (widget), "drag_begin",
+ info->context, NULL);
+
+ /* We use a GTK grab here to override any grabs that the widget
+ * we are dragging from might have held
+ */
+
+ gtk_grab_add (info->ipc_widget);
+ gdk_pointer_grab (info->ipc_widget->window, FALSE,
+ GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK |
+ GDK_BUTTON_RELEASE_MASK, NULL,
+ info->cursor, time);
+
+ if (event->type == GDK_MOTION_NOTIFY)
+ gtk_drag_motion_cb (info->ipc_widget, (GdkEventMotion *)event, info);
+ else
+ {
+ gint x, y;
+ gdk_window_get_pointer (GDK_ROOT_PARENT(), &x, &y, NULL);
+
+ info->cur_x = x;
+ info->cur_y = y;
+
+ if (info->icon_window)
+ {
+ gdk_window_raise (info->icon_window->window);
+ gtk_widget_set_uposition (info->icon_window, x - info->hot_x, y - info->hot_y);
+ }
+ }
+
+ info->start_x = info->cur_x;
+ info->start_y = info->cur_y;
+
+ gtk_signal_connect (GTK_OBJECT (info->ipc_widget), "button_release_event",
+ GTK_SIGNAL_FUNC (gtk_drag_button_release_cb), info);
+ gtk_signal_connect (GTK_OBJECT (info->ipc_widget), "motion_notify_event",
+ GTK_SIGNAL_FUNC (gtk_drag_motion_cb), info);
+ gtk_signal_connect (GTK_OBJECT (info->ipc_widget), "selection_get",
+ GTK_SIGNAL_FUNC (gtk_drag_selection_get), info);
+
+ return info->context;
+}
+
+/*************************************************************
+ * gtk_drag_source_set:
+ * Register a drop site, and possibly add default behaviors.
+ * arguments:
+ * widget:
+ * start_button_mask: Mask of allowed buttons to start drag
+ * targets: Table of targets for this source
+ * n_targets:
+ * actions: Actions allowed for this source
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_source_set (GtkWidget *widget,
+ GdkModifierType start_button_mask,
+ GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions)
+{
+ GtkDragSourceSite *site;
+
+ g_return_if_fail (widget != NULL);
+
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-site-data");
+
+ gtk_widget_add_events (widget,
+ gtk_widget_get_events (widget) |
+ GDK_BUTTON_PRESS_MASK | GDK_BUTTON_MOTION_MASK);
+
+ if (site)
+ {
+ if (site->target_list)
+ gtk_target_list_unref (site->target_list);
+ }
+ else
+ {
+ site = g_new0 (GtkDragSourceSite, 1);
+
+ gtk_signal_connect (GTK_OBJECT (widget), "button_press_event",
+ GTK_SIGNAL_FUNC (gtk_drag_source_event_cb),
+ site);
+ gtk_signal_connect (GTK_OBJECT (widget), "motion_notify_event",
+ GTK_SIGNAL_FUNC (gtk_drag_source_event_cb),
+ site);
+
+ gtk_object_set_data_full (GTK_OBJECT (widget),
+ "gtk-site-data",
+ site, gtk_drag_source_site_destroy);
+ }
+
+ site->start_button_mask = start_button_mask;
+
+ if (targets)
+ site->target_list = gtk_target_list_new (targets, n_targets);
+ else
+ site->target_list = NULL;
+
+ site->actions = actions;
+
+}
+
+/*************************************************************
+ * gtk_drag_source_set_icon:
+ * Set an icon for drags from this source.
+ * arguments:
+ * colormap: Colormap for this icon
+ * pixmap:
+ * mask
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_source_set_icon (GtkWidget *widget,
+ GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask)
+{
+ GtkDragSourceSite *site;
+
+ g_return_if_fail (widget != NULL);
+
+ site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-site-data");
+ g_return_if_fail (site != NULL);
+
+ if (site->colormap)
+ gdk_colormap_unref (site->colormap);
+ if (site->pixmap)
+ gdk_pixmap_unref (site->pixmap);
+ if (site->mask)
+ gdk_pixmap_unref (site->mask);
+
+ site->colormap = colormap;
+ if (colormap)
+ gdk_colormap_ref (colormap);
+
+ site->pixmap = pixmap;
+ if (pixmap)
+ gdk_pixmap_ref (pixmap);
+
+ site->mask = mask;
+ if (mask)
+ gdk_pixmap_ref (mask);
+}
+
+/*************************************************************
+ * gtk_drag_set_icon_widget:
+ * Set a widget as the icon for a drag.
+ * arguments:
+ * context:
+ * widget:
+ * hot_x: Hot spot
+ * hot_y:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_set_icon_widget (GdkDragContext *context,
+ GtkWidget *widget,
+ gint hot_x,
+ gint hot_y)
+{
+ GtkDragSourceInfo *info;
+
+ g_return_if_fail (context != NULL);
+ g_return_if_fail (widget != NULL);
+
+ info = g_dataset_get_data (context, "gtk-info");
+ gtk_drag_remove_icon (info);
+
+ info->icon_window = widget;
+ if (widget)
+ {
+ gtk_widget_set_uposition (widget, info->cur_x, info->cur_y);
+ gtk_widget_ref (widget);
+ gdk_window_raise (widget->window);
+ gtk_widget_show (widget);
+ }
+
+ info->hot_x = hot_x;
+ info->hot_y = hot_y;
+}
+
+/*************************************************************
+ * gtk_drag_set_icon_pixmap:
+ * Set a widget as the icon for a drag.
+ * arguments:
+ * context:
+ * colormap: Colormap for the icon window.
+ * pixmap:
+ * mask:
+ * hot_x: Hot spot
+ * hot_y:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_set_icon_pixmap (GdkDragContext *context,
+ GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask,
+ gint hot_x,
+ gint hot_y)
+{
+ GtkWidget *window;
+ gint width, height;
+
+ g_return_if_fail (context != NULL);
+ g_return_if_fail (colormap != NULL);
+ g_return_if_fail (pixmap != NULL);
+
+ gdk_window_get_size (pixmap, &width, &height);
+
+ gtk_widget_push_visual (gdk_colormap_get_visual(colormap));
+ gtk_widget_push_colormap (colormap);
+
+ window = gtk_window_new (GTK_WINDOW_POPUP);
+
+ gtk_widget_pop_visual ();
+ gtk_widget_pop_colormap ();
+
+ gtk_widget_set_usize (window, width, height);
+ gtk_widget_realize (window);
+
+ gdk_window_set_back_pixmap (window->window, pixmap, FALSE);
+
+ if (mask)
+ gtk_widget_shape_combine_mask (window, mask, 0, 0);
+
+ gtk_drag_set_icon_widget (context, window, hot_x, hot_y);
+}
+
+/*************************************************************
+ * gtk_drag_set_icon_default:
+ * Set the icon for a drag to the default icon.
+ * arguments:
+ * context:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_set_icon_default (GdkDragContext *context)
+{
+ g_return_if_fail (context != NULL);
+
+ if (!default_icon_pixmap)
+ {
+ default_icon_colormap = gdk_colormap_get_system ();
+ default_icon_pixmap =
+ gdk_pixmap_colormap_create_from_xpm_d (NULL,
+ default_icon_colormap,
+ &default_icon_mask,
+ NULL, drag_default_xpm);
+ default_icon_hot_x = -2;
+ default_icon_hot_y = -2;
+ }
+
+ gtk_drag_set_icon_pixmap (context,
+ default_icon_colormap,
+ default_icon_pixmap,
+ default_icon_mask,
+ default_icon_hot_x,
+ default_icon_hot_y);
+}
+
+/*************************************************************
+ * gtk_drag_set_default_icon:
+ * Set a default icon for all drags as a pixmap.
+ * arguments:
+ * colormap: Colormap for the icon window.
+ * pixmap:
+ * mask:
+ * hot_x: Hot spot
+ * hot_y:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_set_default_icon (GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask,
+ gint hot_x,
+ gint hot_y)
+{
+ g_return_if_fail (colormap != NULL);
+ g_return_if_fail (pixmap != NULL);
+
+ if (default_icon_colormap)
+ gdk_colormap_unref (default_icon_colormap);
+ if (default_icon_pixmap)
+ gdk_pixmap_unref (default_icon_pixmap);
+ if (default_icon_mask)
+ gdk_pixmap_unref (default_icon_pixmap);
+
+ default_icon_colormap = colormap;
+ gdk_colormap_ref (colormap);
+
+ default_icon_pixmap = pixmap;
+ gdk_pixmap_ref (pixmap);
+
+ default_icon_mask = mask;
+ if (mask)
+ gdk_pixmap_ref (mask);
+
+ default_icon_hot_x = hot_x;
+ default_icon_hot_y = hot_y;
+}
+
+
+/*************************************************************
+ * gtk_drag_source_handle_event:
+ * Called from widget event handling code on Drag events
+ * for drag sources.
+ *
+ * arguments:
+ * toplevel: Toplevel widget that received the event
+ * event:
+ * results:
+ *************************************************************/
+
+void
+gtk_drag_source_handle_event (GtkWidget *widget,
+ GdkEvent *event)
+{
+ GtkDragSourceInfo *info;
+ GdkDragContext *context;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (event != NULL);
+
+ context = event->dnd.context;
+ info = g_dataset_get_data (context, "gtk-info");
+ if (!info)
+ return;
+
+ switch (event->type)
+ {
+ case GDK_DRAG_STATUS:
+ {
+ GdkCursor *cursor;
+
+ if (info->proxy_dest)
+ {
+ if (!event->dnd.send_event)
+ {
+ if (info->proxy_dest->proxy_drop_wait)
+ {
+ /* Aha - we can finally pass the MOTIF DROP on... */
+ gdk_drag_drop (info->context, info->proxy_dest->proxy_drop_time);
+ }
+ else
+ {
+ gdk_drag_status (info->proxy_dest->context,
+ event->dnd.context->action,
+ event->dnd.time);
+ }
+ }
+ }
+ else
+ {
+ cursor = gtk_drag_get_cursor (event->dnd.context->action);
+ if (info->cursor != cursor)
+ {
+ XChangeActivePointerGrab (GDK_WINDOW_XDISPLAY (widget->window),
+ PointerMotionMask | PointerMotionHintMask | ButtonReleaseMask,
+ ((GdkCursorPrivate *)cursor)->xcursor,
+ event->dnd.time);
+ info->cursor = cursor;
+ }
+
+ if (info->last_event)
+ {
+ gtk_drag_motion_cb (info->widget,
+ (GdkEventMotion *)info->last_event,
+ info);
+ info->last_event = NULL;
+ }
+ }
+ }
+ break;
+
+ case GDK_DROP_FINISHED:
+ gtk_drag_drop_finished (info, TRUE, event->dnd.time);
+ break;
+ default:
+ g_assert_not_reached();
+ }
+}
+
+/*************************************************************
+ * gtk_drag_source_check_selection:
+ * Check if we've set up handlers/claimed the selection
+ * for a given drag. If not, add them.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static void
+gtk_drag_source_check_selection (GtkDragSourceInfo *info,
+ GdkAtom selection,
+ guint32 time)
+{
+ GList *tmp_list;
+
+ tmp_list = info->selections;
+ while (tmp_list)
+ {
+ if (GPOINTER_TO_UINT (tmp_list->data) == selection)
+ return;
+ tmp_list = tmp_list->next;
+ }
+
+ gtk_selection_owner_set (info->ipc_widget, selection, time);
+ info->selections = g_list_prepend (info->selections,
+ GUINT_TO_POINTER (selection));
+
+ tmp_list = info->target_list->list;
+ while (tmp_list)
+ {
+ GtkTargetPair *pair = tmp_list->data;
+
+ gtk_selection_add_target (info->ipc_widget,
+ selection,
+ pair->target,
+ pair->info);
+ tmp_list = tmp_list->next;
+ }
+
+ if (info->context->protocol == GDK_DRAG_PROTO_MOTIF)
+ {
+ gtk_selection_add_target (info->ipc_widget,
+ selection,
+ gdk_atom_intern ("XmTRANSFER_SUCCESS", FALSE),
+ TARGET_MOTIF_SUCCESS);
+ gtk_selection_add_target (info->ipc_widget,
+ selection,
+ gdk_atom_intern ("XmTRANSFER_FAILURE", FALSE),
+ TARGET_MOTIF_FAILURE);
+ }
+
+ gtk_selection_add_target (info->ipc_widget,
+ selection,
+ gdk_atom_intern ("DELETE", FALSE),
+ TARGET_DELETE);
+}
+
+/*************************************************************
+ * gtk_drag_drop_finished:
+ * Clean up from the drag, and display snapback, if necessary.
+ * arguments:
+ * info:
+ * success:
+ * time:
+ * results:
+ *************************************************************/
+
+static void
+gtk_drag_drop_finished (GtkDragSourceInfo *info,
+ gboolean success,
+ guint time)
+{
+ if (info->proxy_dest)
+ {
+ /* The time from the event isn't reliable for Xdnd drags */
+ gtk_drag_finish (info->proxy_dest->context, success, FALSE,
+ info->proxy_dest->proxy_drop_time);
+ }
+ else
+ {
+ if (success)
+ {
+ gtk_drag_source_info_destroy (info);
+ }
+ else
+ {
+ GtkDragAnim *anim = g_new (GtkDragAnim, 1);
+ anim->info = info;
+ anim->step = 0;
+
+ anim->n_steps = MAX (info->cur_x - info->start_x,
+ info->cur_y - info->start_y) / ANIM_STEP_LENGTH;
+ anim->n_steps = CLAMP (anim->n_steps, ANIM_MIN_STEPS, ANIM_MAX_STEPS);
+
+ gtk_timeout_add (ANIM_STEP_TIME, gtk_drag_anim_timeout, anim);
+ }
+ }
+
+ gtk_drag_source_release_selections (info, GDK_CURRENT_TIME); /* fixme */
+}
+
+static void
+gtk_drag_source_release_selections (GtkDragSourceInfo *info,
+ guint32 time)
+{
+ GList *tmp_list = info->selections;
+ while (tmp_list)
+ {
+ GdkAtom selection = GPOINTER_TO_UINT (tmp_list->data);
+ if (gdk_selection_owner_get (selection) == info->ipc_widget->window)
+ gtk_selection_owner_set (NULL, selection, time);
+ tmp_list = tmp_list->next;
+ }
+
+ g_list_free (info->selections);
+ info->selections = NULL;
+}
+
+/*************************************************************
+ * gtk_drag_drop:
+ * Send a drop event.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static void
+gtk_drag_drop (GtkDragSourceInfo *info, guint32 time)
+{
+ if (info->context->protocol == GDK_DRAG_PROTO_ROOTWIN)
+ {
+ GtkSelectionData selection_data;
+ GList *tmp_list;
+ GdkAtom target = gdk_atom_intern ("application/x-rootwin-drop", FALSE);
+
+ tmp_list = info->target_list->list;
+ while (tmp_list)
+ {
+ GtkTargetPair *pair = tmp_list->data;
+
+ if (pair->target == target)
+ {
+ selection_data.selection = GDK_NONE;
+ selection_data.target = target;
+ selection_data.data = NULL;
+ selection_data.length = -1;
+
+ gtk_signal_emit_by_name (GTK_OBJECT (info->widget), "drag_data_get",
+ info->context, &selection_data,
+ pair->info,
+ time);
+
+ /* FIXME: Should we check for length >= 0 here? */
+ gtk_drag_drop_finished (info, TRUE, time);
+ return;
+ }
+ tmp_list = tmp_list->next;
+ }
+ gtk_drag_drop_finished (info, FALSE, time);
+ }
+ else
+ {
+ gdk_drag_drop (info->context, time);
+ info->drop_timeout = gtk_timeout_add (DROP_ABORT_TIME,
+ gtk_drag_abort_timeout,
+ info);
+ }
+}
+
+/*
+ * Source side callbacks.
+ */
+
+static gint
+gtk_drag_source_event_cb (GtkWidget *widget,
+ GdkEvent *event,
+ gpointer data)
+{
+ GtkDragSourceSite *site;
+ site = (GtkDragSourceSite *)data;
+
+ switch (event->type)
+ {
+ case GDK_BUTTON_PRESS:
+ if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
+ {
+ site->x = event->button.x;
+ site->y = event->button.y;
+ }
+
+ case GDK_MOTION_NOTIFY:
+ if (event->motion.state & site->start_button_mask)
+ {
+ /* FIXME: This is really broken and can leave us
+ * with a stuck grab
+ */
+ int i;
+ for (i=1; i<6; i++)
+ {
+ if (event->motion.state & GDK_BUTTON1_MASK << (i - 1))
+ break;
+ }
+
+ if (MAX (abs(site->x - event->motion.x),
+ abs(site->y - event->motion.y)) > 3)
+ {
+ GtkDragSourceInfo *info;
+ GdkDragContext *context;
+
+ context = gtk_drag_begin (widget, site->target_list,
+ site->actions,
+ i, event);
+
+
+ info = g_dataset_get_data (context, "gtk-info");
+
+ if (!info->icon_window)
+ {
+ if (site->pixmap)
+ gtk_drag_set_icon_pixmap (context,
+ site->colormap,
+ site->pixmap,
+ site->mask, -2, -2);
+ else
+ gtk_drag_set_icon_default (context);
+ }
+
+ return TRUE;
+ }
+ }
+ break;
+
+ default: /* hit for 2/3BUTTON_PRESS */
+ }
+ return FALSE;
+}
+
+static void
+gtk_drag_source_site_destroy (gpointer data)
+{
+ GtkDragSourceSite *site = data;
+
+ if (site->target_list)
+ gtk_target_list_unref (site->target_list);
+
+ if (site->pixmap)
+ gdk_pixmap_unref (site->pixmap);
+
+ if (site->mask)
+ gdk_pixmap_unref (site->mask);
+
+ g_free (site);
+}
+
+static void
+gtk_drag_selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint sel_info,
+ guint32 time,
+ gpointer data)
+{
+ GtkDragSourceInfo *info = data;
+ static GdkAtom null_atom = GDK_NONE;
+ guint target_info;
+
+ if (!null_atom)
+ null_atom = gdk_atom_intern ("NULL", FALSE);
+
+ switch (sel_info)
+ {
+ case TARGET_DELETE:
+ gtk_signal_emit_by_name (GTK_OBJECT (info->widget),
+ "drag_data_delete",
+ info->context);
+ gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
+ break;
+ case TARGET_MOTIF_SUCCESS:
+ gtk_drag_drop_finished (info, TRUE, time);
+ gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
+ break;
+ case TARGET_MOTIF_FAILURE:
+ gtk_drag_drop_finished (info, FALSE, time);
+ gtk_selection_data_set (selection_data, null_atom, 8, NULL, 0);
+ break;
+ default:
+ if (info->proxy_dest)
+ {
+ /* This is sort of dangerous and needs to be thought
+ * through better
+ */
+ info->proxy_dest->proxy_data = selection_data;
+ gtk_drag_get_data (info->widget,
+ info->proxy_dest->context,
+ selection_data->target,
+ time);
+ gtk_main();
+ info->proxy_dest->proxy_data = NULL;
+ }
+ else
+ {
+ if (gtk_target_list_find (info->target_list,
+ selection_data->target,
+ &target_info))
+ {
+ gtk_signal_emit_by_name (GTK_OBJECT (info->widget), "drag_data_get",
+ info->context,
+ selection_data,
+ target_info,
+ time);
+ }
+ }
+ break;
+ }
+}
+
+static gint
+gtk_drag_anim_timeout (gpointer data)
+{
+ GtkDragAnim *anim = data;
+ gint x, y;
+
+ if (anim->step == anim->n_steps)
+ {
+ gtk_drag_source_info_destroy (anim->info);
+ g_free (anim);
+
+ return FALSE;
+ }
+ else
+ {
+ x = (anim->info->start_x * (anim->step + 1) +
+ anim->info->cur_x * (anim->n_steps - anim->step - 1)) / anim->n_steps;
+ y = (anim->info->start_y * (anim->step + 1) +
+ anim->info->cur_y * (anim->n_steps - anim->step - 1)) / anim->n_steps;
+ if (anim->info->icon_window)
+ gtk_widget_set_uposition (anim->info->icon_window, x, y);
+
+ anim->step++;
+
+ return TRUE;
+ }
+}
+
+static void
+gtk_drag_remove_icon (GtkDragSourceInfo *info)
+{
+ if (info->icon_window)
+ {
+ gtk_widget_hide (info->icon_window);
+ gtk_widget_unref (info->icon_window);
+
+ info->icon_window = NULL;
+ }
+}
+
+static void
+gtk_drag_source_info_destroy (gpointer data)
+{
+ GtkDragSourceInfo *info = data;
+
+ gtk_drag_remove_icon (data);
+
+ if (info->widget)
+ gtk_widget_unref (info->widget);
+
+ gtk_signal_disconnect_by_data (GTK_OBJECT (info->ipc_widget), info);
+ gtk_selection_remove_all (info->ipc_widget);
+ gtk_drag_release_ipc_widget (info->ipc_widget);
+
+ gtk_target_list_unref (info->target_list);
+
+ g_dataset_set_data (info->context, "gtk-info", NULL);
+ gdk_drag_context_unref (info->context);
+
+ if (info->drop_timeout)
+ gtk_timeout_remove (info->drop_timeout);
+
+ g_free (info);
+}
+
+/*************************************************************
+ * gtk_drag_motion_cb:
+ * "motion_notify_event" callback during drag.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static gint
+gtk_drag_motion_cb (GtkWidget *widget,
+ GdkEventMotion *event,
+ gpointer data)
+{
+ GtkDragSourceInfo *info = (GtkDragSourceInfo *)data;
+ GdkAtom selection;
+ GdkDragAction action;
+ GdkWindow *window = NULL;
+ GdkWindow *dest_window;
+ GdkDragProtocol protocol;
+ gint x_root, y_root;
+
+ if (event->is_hint)
+ {
+ gdk_window_get_pointer (GDK_ROOT_PARENT(), &x_root, &y_root, NULL);
+ event->x_root = x_root;
+ event->y_root = y_root;
+ }
+
+ action = gtk_drag_get_event_action ((GdkEvent *)event,
+ info->button,
+ info->context->actions);
+
+ info->cur_x = event->x_root - info->hot_x;
+ info->cur_y = event->y_root - info->hot_y;
+
+ if (info->icon_window)
+ {
+ gdk_window_raise (info->icon_window->window);
+ gtk_widget_set_uposition (info->icon_window, info->cur_x, info->cur_y);
+ window = info->icon_window->window;
+ }
+
+ gdk_drag_find_window (info->context,
+ window, event->x_root, event->y_root,
+ &dest_window, &protocol);
+
+ if (gdk_drag_motion (info->context, dest_window, protocol,
+ event->x_root, event->y_root, action,
+ event->time))
+ {
+ if (info->last_event)
+ gdk_event_free ((GdkEvent *)info->last_event);
+
+ info->last_event = gdk_event_copy ((GdkEvent *)event);
+ }
+
+ if (dest_window)
+ gdk_window_unref (dest_window);
+
+ selection = gdk_drag_get_selection (info->context);
+ if (selection)
+ gtk_drag_source_check_selection (info, selection, event->time);
+
+#if 0
+ /* We ignore the response, so we can respond precisely to the drop
+ */
+ if (event->is_hint)
+ gdk_window_get_pointer (widget->window, NULL, NULL, NULL);
+#endif
+
+ return TRUE;
+}
+
+/*************************************************************
+ * gtk_drag_motion_cb:
+ * "button_release_event" callback during drag.
+ * arguments:
+ *
+ * results:
+ *************************************************************/
+
+static gint
+gtk_drag_button_release_cb (GtkWidget *widget,
+ GdkEventButton *event,
+ gpointer data)
+{
+ GtkDragSourceInfo *info = (GtkDragSourceInfo *)data;
+ GtkWidget *source_widget = info->widget;
+ GdkEvent send_event;
+
+ gtk_widget_ref (source_widget);
+
+ if (event->button != info->button)
+ return FALSE;
+
+ gdk_pointer_ungrab (event->time);
+
+ if ((info->context->action != 0) && (info->context->dest_window != NULL))
+ {
+ gtk_drag_drop (info, event->time);
+ }
+ else
+ {
+ gdk_drag_abort (info->context, event->time);
+ gtk_drag_drop_finished (info, FALSE, event->time);
+ }
+
+ gtk_grab_remove (widget);
+
+ send_event.button.type = GDK_BUTTON_RELEASE;
+ send_event.button.window = source_widget->window;
+ send_event.button.x = 0;
+ send_event.button.y = 0;
+ send_event.button.state = event->state;
+ send_event.button.button = event->button;
+
+ send_event.button.time = event->time;
+
+ /* Send on the button release to the original widget to
+ * convince it to release its grab
+ */
+ gtk_widget_event (source_widget, &send_event);
+ gtk_widget_unref (source_widget);
+
+ return TRUE;
+}
+
+static gint
+gtk_drag_abort_timeout (gpointer data)
+{
+ GtkDragSourceInfo *info = data;
+ guint32 time = GDK_CURRENT_TIME;
+
+ if (info->proxy_dest)
+ time = info->proxy_dest->proxy_drop_time;
+
+ info->drop_timeout = 0;
+ gtk_drag_drop_finished (info, FALSE, time);
+
+ return FALSE;
+}
diff --git a/gtk/gtkdnd.h b/gtk/gtkdnd.h
new file mode 100644
index 0000000000..8f313e70ee
--- /dev/null
+++ b/gtk/gtkdnd.h
@@ -0,0 +1,129 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#ifndef __GTK_DND_H__
+#define __GTK_DND_H__
+
+#include <gdk/gdk.h>
+#include <gtk/gtkenums.h>
+#include <gtk/gtkwidget.h>
+#include <gtk/gtkselection.h>
+
+#ifdef __cplusplus
+extern "C" {
+#pragma }
+#endif /* __cplusplus */
+
+typedef enum {
+ GTK_DEST_DEFAULT_MOTION = 1 << 0, /* respond to "drag_motion" */
+ GTK_DEST_DEFAULT_HIGHLIGHT = 1 << 1, /* auto-highlight */
+ GTK_DEST_DEFAULT_DROP = 1 << 2, /* respond to "drag_drop" */
+ GTK_DEST_DEFAULT_ALL = 0x07
+} GtkDestDefaults;
+
+/* Destination side */
+
+void gtk_drag_get_data (GtkWidget *widget,
+ GdkDragContext *context,
+ GdkAtom target,
+ guint32 time);
+void gtk_drag_finish (GdkDragContext *context,
+ gboolean success,
+ gboolean delete,
+ guint32 time);
+
+void gtk_drag_highlight (GtkWidget *widget);
+void gtk_drag_unhighlight (GtkWidget *widget);
+
+void gtk_drag_dest_set (GtkWidget *widget,
+ GtkDestDefaults flags,
+ GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions);
+
+void gtk_drag_dest_set_proxy (GtkWidget *widget,
+ GdkWindow *proxy_window,
+ GdkDragProtocol protocol,
+ gboolean use_coordinates);
+
+/* There probably should be functions for setting the targets
+ * as a GtkTargetList
+ */
+
+void gtk_drag_dest_unset (GtkWidget *widget);
+
+/* Source side */
+
+void gtk_drag_source_set (GtkWidget *widget,
+ GdkModifierType start_button_mask,
+ GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions);
+
+void gtk_drag_source_set_icon (GtkWidget *widget,
+ GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask);
+
+/* There probably should be functions for setting the targets
+ * as a GtkTargetList
+ */
+
+GdkDragContext *gtk_drag_begin (GtkWidget *widget,
+ GtkTargetList *targets,
+ GdkDragAction actions,
+ gint button,
+ GdkEvent *event);
+
+/* Set the image being dragged around
+ */
+void gtk_drag_set_icon_widget (GdkDragContext *context,
+ GtkWidget *widget,
+ gint hot_x,
+ gint hot_y);
+
+void gtk_drag_set_icon_pixmap (GdkDragContext *context,
+ GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask,
+ gint hot_x,
+ gint hot_y);
+
+void gtk_drag_set_icon_default (GdkDragContext *context);
+
+void gtk_drag_set_default_icon (GdkColormap *colormap,
+ GdkPixmap *pixmap,
+ GdkBitmap *mask,
+ gint hot_x,
+ gint hot_y);
+
+
+/* Internal functions */
+void gtk_drag_source_handle_event (GtkWidget *widget,
+ GdkEvent *event);
+void gtk_drag_dest_handle_event (GtkWidget *toplevel,
+ GdkEvent *event);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* __GTK_DND_H__ */
+
+
+
diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c
index 09d28a9ab3..e720395676 100644
--- a/gtk/gtkeditable.c
+++ b/gtk/gtkeditable.c
@@ -58,7 +58,14 @@ enum {
ARG_TEXT_POSITION,
ARG_EDITABLE
};
-
+
+/* values for selection info */
+
+enum {
+ TARGET_STRING,
+ TARGET_TEXT,
+ TARGET_COMPOUND_TEXT,
+};
static void gtk_editable_class_init (GtkEditableClass *klass);
static void gtk_editable_init (GtkEditable *editable);
@@ -71,11 +78,13 @@ static void gtk_editable_get_arg (GtkObject *object,
static void gtk_editable_finalize (GtkObject *object);
static gint gtk_editable_selection_clear (GtkWidget *widget,
GdkEventSelection *event);
-static void gtk_editable_selection_handler (GtkWidget *widget,
- GtkSelectionData *selection_data,
- gpointer data);
+static void gtk_editable_selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time);
static void gtk_editable_selection_received (GtkWidget *widget,
- GtkSelectionData *selection_data);
+ GtkSelectionData *selection_data,
+ guint time);
static void gtk_editable_set_selection (GtkEditable *editable,
gint start,
@@ -90,8 +99,7 @@ static void gtk_editable_real_set_editable (GtkEditable *editable,
static GtkWidgetClass *parent_class = NULL;
static guint editable_signals[LAST_SIGNAL] = { 0 };
-static GdkAtom ctext_atom = GDK_NONE;
-static GdkAtom text_atom = GDK_NONE;
+
static GdkAtom clipboard_atom = GDK_NONE;
GtkType
@@ -287,6 +295,7 @@ gtk_editable_class_init (GtkEditableClass *class)
widget_class->selection_clear_event = gtk_editable_selection_clear;
widget_class->selection_received = gtk_editable_selection_received;
+ widget_class->selection_get = gtk_editable_selection_get;
class->insert_text = NULL;
class->delete_text = NULL;
@@ -362,6 +371,13 @@ gtk_editable_get_arg (GtkObject *object,
static void
gtk_editable_init (GtkEditable *editable)
{
+ static GtkTargetEntry targets[] = {
+ { "STRING", TARGET_STRING },
+ { "TEXT", TARGET_TEXT },
+ { "COMPOUND_TEXT", TARGET_COMPOUND_TEXT }
+ };
+ static gint n_targets = sizeof(targets) / sizeof(targets[0]);
+
GTK_WIDGET_SET_FLAGS (editable, GTK_CAN_FOCUS);
editable->selection_start_pos = 0;
@@ -377,36 +393,10 @@ gtk_editable_init (GtkEditable *editable)
if (!clipboard_atom)
clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
- gtk_selection_add_handler (GTK_WIDGET(editable), GDK_SELECTION_PRIMARY,
- GDK_TARGET_STRING, gtk_editable_selection_handler,
- NULL);
- gtk_selection_add_handler (GTK_WIDGET(editable), clipboard_atom,
- GDK_TARGET_STRING, gtk_editable_selection_handler,
- NULL);
-
- if (!text_atom)
- text_atom = gdk_atom_intern ("TEXT", FALSE);
-
- gtk_selection_add_handler (GTK_WIDGET(editable), GDK_SELECTION_PRIMARY,
- text_atom,
- gtk_editable_selection_handler,
- NULL);
- gtk_selection_add_handler (GTK_WIDGET(editable), clipboard_atom,
- text_atom,
- gtk_editable_selection_handler,
- NULL);
-
- if (!ctext_atom)
- ctext_atom = gdk_atom_intern ("COMPOUND_TEXT", FALSE);
-
- gtk_selection_add_handler (GTK_WIDGET(editable), GDK_SELECTION_PRIMARY,
- ctext_atom,
- gtk_editable_selection_handler,
- NULL);
- gtk_selection_add_handler (GTK_WIDGET(editable), clipboard_atom,
- ctext_atom,
- gtk_editable_selection_handler,
- NULL);
+ gtk_selection_add_targets (GTK_WIDGET (editable), GDK_SELECTION_PRIMARY,
+ targets, n_targets);
+ gtk_selection_add_targets (GTK_WIDGET (editable), clipboard_atom,
+ targets, n_targets);
}
static void
@@ -580,9 +570,10 @@ gtk_editable_selection_clear (GtkWidget *widget,
}
static void
-gtk_editable_selection_handler (GtkWidget *widget,
- GtkSelectionData *selection_data,
- gpointer data)
+gtk_editable_selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time)
{
GtkEditable *editable;
gint selection_start_pos;
@@ -614,14 +605,13 @@ gtk_editable_selection_handler (GtkWidget *widget,
length = strlen (editable->clipboard_text);
}
- if (selection_data->target == GDK_SELECTION_TYPE_STRING)
+ if (info == TARGET_STRING)
{
gtk_selection_data_set (selection_data,
GDK_SELECTION_TYPE_STRING,
8*sizeof(gchar), (guchar *)str, length);
}
- else if (selection_data->target == text_atom ||
- selection_data->target == ctext_atom)
+ else if ((info == TARGET_TEXT) || (info == TARGET_COMPOUND_TEXT))
{
guchar *text;
gchar c;
@@ -643,7 +633,8 @@ gtk_editable_selection_handler (GtkWidget *widget,
static void
gtk_editable_selection_received (GtkWidget *widget,
- GtkSelectionData *selection_data)
+ GtkSelectionData *selection_data,
+ guint time)
{
GtkEditable *editable;
gint reselect;
@@ -658,7 +649,8 @@ gtk_editable_selection_received (GtkWidget *widget,
if (selection_data->type == GDK_TARGET_STRING)
type = STRING;
- else if (selection_data->type == ctext_atom)
+ else if ((selection_data->type == gdk_atom_intern ("COMPOUND_TEXT", FALSE)) ||
+ (selection_data->type == gdk_atom_intern ("TEXT", FALSE)))
type = CTEXT;
else
type = INVALID;
@@ -668,7 +660,7 @@ gtk_editable_selection_received (GtkWidget *widget,
/* avoid infinite loop */
if (selection_data->target != GDK_TARGET_STRING)
gtk_selection_convert (widget, selection_data->selection,
- GDK_TARGET_STRING, GDK_CURRENT_TIME);
+ GDK_TARGET_STRING, time);
return;
}
@@ -934,7 +926,8 @@ gtk_editable_real_paste_clipboard (GtkEditable *editable)
time = gtk_editable_get_event_time (editable);
if (editable->editable)
gtk_selection_convert (GTK_WIDGET(editable),
- clipboard_atom, ctext_atom, time);
+ clipboard_atom,
+ gdk_atom_intern ("COMPOUND_TEXT", FALSE), time);
}
void
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 7d7c7915b2..a7cc42426b 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -22,6 +22,7 @@
#include <string.h>
#include <gmodule.h>
#include "gtkbutton.h"
+#include "gtkdnd.h"
#include "gtkfeatures.h"
#include "gtkhscrollbar.h"
#include "gtkhseparator.h"
@@ -224,7 +225,8 @@ guint gtk_debug_flags = 0; /* Global GTK debug flag */
static GDebugKey gtk_debug_keys[] = {
{"objects", GTK_DEBUG_OBJECTS},
{"misc", GTK_DEBUG_MISC},
- {"signals", GTK_DEBUG_SIGNALS}
+ {"signals", GTK_DEBUG_SIGNALS},
+ {"dnd", GTK_DEBUG_DND}
};
static const guint gtk_ndebug_keys = sizeof (gtk_debug_keys) / sizeof (GDebugKey);
@@ -764,6 +766,9 @@ gtk_main_iteration_do (gboolean blocking)
* 1) these events have no meaning for the grabbing widget
* and 2) redirecting these events to the grabbing widget
* could cause the display to be messed up.
+ *
+ * Drag events are also not redirected, since it isn't
+ * clear what the semantics of that would be.
*/
switch (event->type)
{
@@ -797,11 +802,6 @@ gtk_main_iteration_do (gboolean blocking)
case GDK_SELECTION_REQUEST:
case GDK_SELECTION_NOTIFY:
case GDK_CLIENT_EVENT:
- case GDK_DRAG_BEGIN:
- case GDK_DRAG_REQUEST:
- case GDK_DROP_ENTER:
- case GDK_DROP_LEAVE:
- case GDK_DROP_DATA_AVAIL:
case GDK_VISIBILITY_NOTIFY:
gtk_widget_event (event_widget, event);
break;
@@ -821,7 +821,6 @@ gtk_main_iteration_do (gboolean blocking)
case GDK_BUTTON_RELEASE:
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
- case GDK_OTHER_EVENT:
gtk_propagate_event (grab_widget, event);
break;
@@ -843,6 +842,17 @@ gtk_main_iteration_do (gboolean blocking)
else if (GTK_WIDGET_IS_SENSITIVE (grab_widget))
gtk_widget_event (grab_widget, event);
break;
+
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_FINISHED:
+ gtk_drag_source_handle_event (event_widget, event);
+ break;
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DROP_START:
+ gtk_drag_dest_handle_event (event_widget, event);
+ break;
}
tmp_list = current_events;
diff --git a/gtk/gtkmarshal.list b/gtk/gtkmarshal.list
index 0eaac95c3f..f4ddc3b8f6 100644
--- a/gtk/gtkmarshal.list
+++ b/gtk/gtkmarshal.list
@@ -1,6 +1,8 @@
BOOL:NONE
BOOL:POINTER
BOOL:POINTER,POINTER,INT,INT
+BOOL:POINTER,INT,INT
+BOOL:POINTER,INT,INT,UINT
BOOL:POINTER,STRING,STRING,POINTER
ENUM:ENUM
INT:POINTER
@@ -24,6 +26,8 @@ NONE:POINTER,POINTER,POINTER
NONE:POINTER,STRING,STRING
NONE:POINTER,UINT
NONE:POINTER,UINT,ENUM
+NONE:POINTER,POINTER,UINT,UINT
+NONE:POINTER,UINT,UINT
NONE:POINTER,UINT,UINT
NONE:STRING
NONE:STRING,INT,POINTER
diff --git a/gtk/gtkmarshalers.list b/gtk/gtkmarshalers.list
index 0eaac95c3f..f4ddc3b8f6 100644
--- a/gtk/gtkmarshalers.list
+++ b/gtk/gtkmarshalers.list
@@ -1,6 +1,8 @@
BOOL:NONE
BOOL:POINTER
BOOL:POINTER,POINTER,INT,INT
+BOOL:POINTER,INT,INT
+BOOL:POINTER,INT,INT,UINT
BOOL:POINTER,STRING,STRING,POINTER
ENUM:ENUM
INT:POINTER
@@ -24,6 +26,8 @@ NONE:POINTER,POINTER,POINTER
NONE:POINTER,STRING,STRING
NONE:POINTER,UINT
NONE:POINTER,UINT,ENUM
+NONE:POINTER,POINTER,UINT,UINT
+NONE:POINTER,UINT,UINT
NONE:POINTER,UINT,UINT
NONE:STRING
NONE:STRING,INT,POINTER
diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h
index a3d1db74f1..5b046403ec 100644
--- a/gtk/gtkmenu.h
+++ b/gtk/gtkmenu.h
@@ -58,6 +58,10 @@ struct _GtkMenu
GtkMenuPositionFunc position_func;
gpointer position_func_data;
+ /* Do _not_ touch these widgets directly. We hide the reference
+ * count from the toplevel to the menu, so it must be restored
+ * before operating on these widgets
+ */
GtkWidget *toplevel;
GtkWidget *tearoff_window;
diff --git a/gtk/gtkselection.c b/gtk/gtkselection.c
index 506168f90d..f0094b0218 100644
--- a/gtk/gtkselection.c
+++ b/gtk/gtkselection.c
@@ -70,7 +70,6 @@ typedef struct _GtkSelectionInfo GtkSelectionInfo;
typedef struct _GtkIncrConversion GtkIncrConversion;
typedef struct _GtkIncrInfo GtkIncrInfo;
typedef struct _GtkRetrievalInfo GtkRetrievalInfo;
-typedef struct _GtkSelectionHandler GtkSelectionHandler;
struct _GtkSelectionInfo
{
@@ -117,16 +116,7 @@ struct _GtkRetrievalInfo
guchar *buffer; /* Buffer in which to accumulate results */
gint offset; /* Current offset in buffer, -1 indicates
not yet started */
-};
-
-struct _GtkSelectionHandler
-{
- GdkAtom selection; /* selection thats handled */
- GdkAtom target; /* target thats handled */
- GtkSelectionFunction function; /* callback function */
- GtkCallbackMarshal marshal; /* Marshalling function */
- gpointer data; /* callback data */
- GtkDestroyNotify destroy; /* called when callback is removed */
+ guint32 notify_time; /* Timestamp from SelectionNotify */
};
/* Local Functions */
@@ -135,9 +125,11 @@ static gint gtk_selection_incr_timeout (GtkIncrInfo *info);
static gint gtk_selection_retrieval_timeout (GtkRetrievalInfo *info);
static void gtk_selection_retrieval_report (GtkRetrievalInfo *info,
GdkAtom type, gint format,
- guchar *buffer, gint length);
+ guchar *buffer, gint length,
+ guint32 time);
static void gtk_selection_invoke_handler (GtkWidget *widget,
- GtkSelectionData *data);
+ GtkSelectionData *data,
+ guint time);
static void gtk_selection_default_handler (GtkWidget *widget,
GtkSelectionData *data);
@@ -150,6 +142,136 @@ static GList *current_selections = NULL;
static GdkAtom gtk_selection_atoms[LAST_ATOM];
static const char *gtk_selection_handler_key = "gtk-selection-handlers";
+/****************
+ * Target Lists *
+ ****************/
+
+/*
+ * Target lists
+ */
+
+GtkTargetList *
+gtk_target_list_new (GtkTargetEntry *targets,
+ guint ntargets)
+{
+ GtkTargetList *result = g_new (GtkTargetList, 1);
+ result->list = NULL;
+ result->ref_count = 1;
+
+ if (targets)
+ gtk_target_list_add_table (result, targets, ntargets);
+
+ return result;
+}
+
+void
+gtk_target_list_ref (GtkTargetList *list)
+{
+ list->ref_count++;
+}
+
+void
+gtk_target_list_unref (GtkTargetList *list)
+{
+ list->ref_count--;
+ if (list->ref_count == 0)
+ {
+ GList *tmp_list = list->list;
+ while (tmp_list)
+ {
+ GtkTargetEntry *entry = tmp_list->data;
+ g_free (entry);
+
+ tmp_list = tmp_list->next;
+ }
+ }
+}
+
+void
+gtk_target_list_add (GtkTargetList *list,
+ GdkAtom target,
+ guint flags,
+ guint info)
+{
+ GtkTargetPair *pair;
+
+ g_return_if_fail (list != NULL);
+
+ pair = g_new (GtkTargetPair, 1);
+ pair->target = target;
+ pair->flags = flags;
+ pair->info = info;
+
+ list->list = g_list_append (list->list, pair);
+}
+
+void
+gtk_target_list_add_table (GtkTargetList *list,
+ GtkTargetEntry *targets,
+ guint ntargets)
+{
+ gint i;
+
+ for (i=ntargets-1; i >= 0; i--)
+ {
+ GtkTargetPair *pair = g_new (GtkTargetPair, 1);
+ pair->target = gdk_atom_intern (targets[i].target, FALSE);
+ pair->flags = targets[i].flags;
+ pair->info = targets[i].info;
+
+ list->list = g_list_prepend (list->list, pair);
+ }
+}
+
+void
+gtk_target_list_remove (GtkTargetList *list,
+ GdkAtom target)
+{
+ GList *tmp_list;
+
+ g_return_if_fail (list != NULL);
+
+ tmp_list = list->list;
+ while (tmp_list)
+ {
+ GtkTargetPair *pair = tmp_list->data;
+
+ if (pair->target == target)
+ {
+ g_free (pair);
+
+ list->list = g_list_remove (list->list, tmp_list);
+ g_list_free_1 (tmp_list);
+
+ return;
+ }
+
+ tmp_list = tmp_list->next;
+ }
+}
+
+gboolean
+gtk_target_list_find (GtkTargetList *list,
+ GdkAtom target,
+ guint *info)
+{
+ GList *tmp_list = list->list;
+ while (tmp_list)
+ {
+ GtkTargetPair *pair = tmp_list->data;
+
+ if (pair->target == target)
+ {
+ *info = pair->info;
+ return TRUE;
+ }
+ tmp_list = tmp_list->next;
+ }
+
+ return FALSE;
+}
+
+
/*************************************************************
* gtk_selection_owner_set:
* Claim ownership of a selection.
@@ -252,95 +374,105 @@ gtk_selection_owner_set (GtkWidget *widget,
}
/*************************************************************
- * gtk_selection_add_handler_full:
- * Add a handler for a specified selection/target pair
+ * gtk_selection_add_target
+ * Add specified target to list of supported targets
*
* arguments:
- * widget: The widget the handler applies to
+ * widget: The widget for which this target applies
* selection:
* target:
- * format: Format in which this handler will return data
- * function: Callback function (can be NULL)
- * marshal: Callback marshal function
- * data: User data for callback
- * destroy: Called when handler removed
+ * info: guint to pass to to the selection_get signal
*
* results:
*************************************************************/
-void
-gtk_selection_add_handler (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
- GtkSelectionFunction function,
- gpointer data)
-{
- gtk_selection_add_handler_full (widget, selection, target, function,
- NULL, data, NULL);
-}
+typedef struct _GtkSelectionTargetList GtkSelectionTargetList;
-void
-gtk_selection_add_handler_full (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
- GtkSelectionFunction function,
- GtkCallbackMarshal marshal,
- gpointer data,
- GtkDestroyNotify destroy)
+struct _GtkSelectionTargetList {
+ GdkAtom selection;
+ GtkTargetList *list;
+};
+
+static GtkTargetList *
+gtk_selection_target_list_get (GtkWidget *widget,
+ GdkAtom selection)
{
- GList *selection_handlers;
+ GtkSelectionTargetList *sellist;
GList *tmp_list;
- GtkSelectionHandler *handler;
-
- g_return_if_fail (widget != NULL);
- if (initialize)
- gtk_selection_init ();
-
- selection_handlers = gtk_object_get_data (GTK_OBJECT (widget),
- gtk_selection_handler_key);
+ GList *lists;
+
+ lists = gtk_object_get_data (GTK_OBJECT (widget), gtk_selection_handler_key);
- /* Reuse old handler structure, if present */
- tmp_list = selection_handlers;
+ tmp_list = lists;
while (tmp_list)
{
- handler = (GtkSelectionHandler *)tmp_list->data;
- if ((handler->selection == selection) && (handler->target == target))
- {
- if (handler->destroy)
- (*handler->destroy)(handler->data);
- if (function)
- {
- handler->function = function;
- handler->marshal = marshal;
- handler->data = data;
- handler->destroy = destroy;
- }
- else
- {
- selection_handlers = g_list_remove_link (selection_handlers,
- tmp_list);
- g_list_free (tmp_list);
- g_free (handler);
- }
- return;
- }
+ sellist = tmp_list->data;
+ if (sellist->selection == selection)
+ return sellist->list;
tmp_list = tmp_list->next;
}
+
+ sellist = g_new (GtkSelectionTargetList, 1);
+ sellist->selection = selection;
+ sellist->list = gtk_target_list_new (NULL, 0);
+
+ lists = g_list_prepend (lists, sellist);
+ gtk_object_set_data (GTK_OBJECT (widget), gtk_selection_handler_key, lists);
+
+ return sellist->list;
+}
+
+static void
+gtk_selection_target_list_remove (GtkWidget *widget)
+{
+ GtkSelectionTargetList *sellist;
+ GList *tmp_list;
+ GList *lists;
+
+ lists = gtk_object_get_data (GTK_OBJECT (widget), gtk_selection_handler_key);
- if (tmp_list == NULL && function)
+ tmp_list = lists;
+ while (tmp_list)
{
- handler = g_new (GtkSelectionHandler, 1);
- handler->selection = selection;
- handler->target = target;
- handler->function = function;
- handler->marshal = marshal;
- handler->data = data;
- handler->destroy = destroy;
- selection_handlers = g_list_append (selection_handlers, handler);
+ sellist = tmp_list->data;
+
+ gtk_target_list_unref (sellist->list);
+
+ g_free (sellist);
+ tmp_list = tmp_list->next;
}
+
+ g_list_free (lists);
+ gtk_object_set_data (GTK_OBJECT (widget), gtk_selection_handler_key, NULL);
+}
+
+void
+gtk_selection_add_target (GtkWidget *widget,
+ GdkAtom selection,
+ GdkAtom target,
+ guint info)
+{
+ GtkTargetList *list;
+
+ g_return_if_fail (widget != NULL);
+
+ list = gtk_selection_target_list_get (widget, selection);
+ gtk_target_list_add (list, target, 0, info);
+}
+
+void
+gtk_selection_add_targets (GtkWidget *widget,
+ GdkAtom selection,
+ GtkTargetEntry *targets,
+ guint ntargets)
+{
+ GtkTargetList *list;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (targets != NULL);
- gtk_object_set_data (GTK_OBJECT (widget), gtk_selection_handler_key,
- selection_handlers);
+ list = gtk_selection_target_list_get (widget, selection);
+ gtk_target_list_add_table (list, targets, ntargets);
}
/*************************************************************
@@ -360,8 +492,6 @@ gtk_selection_remove_all (GtkWidget *widget)
GList *tmp_list;
GList *next;
GtkSelectionInfo *selection_info;
- GList *selection_handlers;
- GtkSelectionHandler *handler;
/* Remove pending requests/incrs for this widget */
@@ -413,28 +543,9 @@ gtk_selection_remove_all (GtkWidget *widget)
tmp_list = next;
}
-
- /* Now remove all handlers */
-
- selection_handlers = gtk_object_get_data (GTK_OBJECT (widget),
- gtk_selection_handler_key);
- gtk_object_remove_data (GTK_OBJECT (widget), gtk_selection_handler_key);
-
- tmp_list = selection_handlers;
- while (tmp_list)
- {
- next = tmp_list->next;
- handler = (GtkSelectionHandler *)tmp_list->data;
-
- if (handler->destroy)
- (*handler->destroy)(handler->data);
-
- g_free (handler);
-
- tmp_list = next;
- }
-
- g_list_free (selection_handlers);
+
+ /* Remove all selection lists */
+ gtk_selection_target_list_remove (widget);
}
/*************************************************************
@@ -516,13 +627,15 @@ gtk_selection_convert (GtkWidget *widget,
if (owner_widget != NULL)
{
gtk_selection_invoke_handler (owner_widget,
- &selection_data);
+ &selection_data,
+ time);
gtk_selection_retrieval_report (info,
selection_data.type,
selection_data.format,
selection_data.data,
- selection_data.length);
+ selection_data.length,
+ time);
g_free (selection_data.data);
@@ -666,6 +779,9 @@ gtk_selection_request (GtkWidget *widget,
guchar *mult_atoms;
int i;
+ if (initialize)
+ gtk_selection_init ();
+
/* Check if we own selection */
tmp_list = current_selections;
@@ -704,10 +820,9 @@ gtk_selection_request (GtkWidget *widget,
gint length;
mult_atoms = NULL;
- if (!gdk_property_get (info->requestor, event->property, GDK_SELECTION_TYPE_ATOM,
+ if (!gdk_property_get (info->requestor, event->property, 0, /* AnyPropertyType */
0, GTK_SELECTION_MAX_SIZE, FALSE,
- &type, &format, &length, &mult_atoms) ||
- type != GDK_SELECTION_TYPE_ATOM || format != 8*sizeof(GdkAtom))
+ &type, &format, &length, &mult_atoms))
{
gdk_selection_send_notify (event->requestor, event->selection,
event->target, GDK_NONE, event->time);
@@ -753,7 +868,7 @@ gtk_selection_request (GtkWidget *widget,
event->requestor, event->property);
#endif
- gtk_selection_invoke_handler (widget, &data);
+ gtk_selection_invoke_handler (widget, &data, event->time);
if (data.length < 0)
{
@@ -822,7 +937,7 @@ gtk_selection_request (GtkWidget *widget,
gdk_property_change (info->requestor, event->property,
GDK_SELECTION_TYPE_ATOM, 8*sizeof(GdkAtom),
GDK_PROP_MODE_REPLACE,
- mult_atoms, info->num_conversions);
+ mult_atoms, 2*info->num_conversions);
g_free (mult_atoms);
}
@@ -1051,7 +1166,7 @@ gtk_selection_notify (GtkWidget *widget,
g_list_free (tmp_list);
/* structure will be freed in timeout */
gtk_selection_retrieval_report (info,
- GDK_NONE, 0, NULL, -1);
+ GDK_NONE, 0, NULL, -1, event->time);
return TRUE;
}
@@ -1063,7 +1178,8 @@ gtk_selection_notify (GtkWidget *widget,
{
/* The remainder of the selection will come through PropertyNotify
events */
-
+
+ info->notify_time = event->time;
info->idle_time = 0;
info->offset = 0; /* Mark as OK to proceed */
gdk_window_set_events (widget->window,
@@ -1079,7 +1195,7 @@ gtk_selection_notify (GtkWidget *widget,
info->offset = length;
gtk_selection_retrieval_report (info,
type, format,
- buffer, length);
+ buffer, length, event->time);
}
gdk_property_delete (widget->window, event->property);
@@ -1157,7 +1273,8 @@ gtk_selection_property_notify (GtkWidget *widget,
gtk_selection_retrieval_report (info,
type, format,
(type == GDK_NONE) ? NULL : info->buffer,
- (type == GDK_NONE) ? -1 : info->offset);
+ (type == GDK_NONE) ? -1 : info->offset,
+ info->notify_time);
}
else /* append on newly arrived data */
{
@@ -1219,7 +1336,7 @@ gtk_selection_retrieval_timeout (GtkRetrievalInfo *info)
{
current_retrievals = g_list_remove_link (current_retrievals, tmp_list);
g_list_free (tmp_list);
- gtk_selection_retrieval_report (info, GDK_NONE, 0, NULL, -1);
+ gtk_selection_retrieval_report (info, GDK_NONE, 0, NULL, -1, GDK_CURRENT_TIME);
}
g_free (info->buffer);
@@ -1242,13 +1359,15 @@ gtk_selection_retrieval_timeout (GtkRetrievalInfo *info)
* arguments:
* info: information about the retrieval that completed
* buffer: buffer containing data (NULL => errror)
+ * time: timestamp for data in buffer
* results:
*************************************************************/
static void
gtk_selection_retrieval_report (GtkRetrievalInfo *info,
GdkAtom type, gint format,
- guchar *buffer, gint length)
+ guchar *buffer, gint length,
+ guint32 time)
{
GtkSelectionData data;
@@ -1261,7 +1380,8 @@ gtk_selection_retrieval_report (GtkRetrievalInfo *info,
data.data = buffer;
gtk_signal_emit_by_name (GTK_OBJECT(info->widget),
- "selection_received", &data);
+ "selection_received",
+ &data, time);
}
/*************************************************************
@@ -1273,6 +1393,7 @@ gtk_selection_retrieval_report (GtkRetrievalInfo *info,
* arguments:
* widget: selection owner
* data: selection data [INOUT]
+ * time: time from requeset
*
* results:
* Number of bytes written to buffer, -1 if error
@@ -1280,44 +1401,26 @@ gtk_selection_retrieval_report (GtkRetrievalInfo *info,
static void
gtk_selection_invoke_handler (GtkWidget *widget,
- GtkSelectionData *data)
+ GtkSelectionData *data,
+ guint time)
{
- GList *tmp_list;
- GtkSelectionHandler *handler;
+ GtkTargetList *target_list;
+ guint info;
+
g_return_if_fail (widget != NULL);
-
- tmp_list = gtk_object_get_data (GTK_OBJECT (widget),
- gtk_selection_handler_key);
-
- while (tmp_list)
+
+ target_list = gtk_selection_target_list_get (widget, data->selection);
+ if (target_list &&
+ gtk_target_list_find (target_list, data->target, &info))
{
- handler = (GtkSelectionHandler *)tmp_list->data;
- if ((handler->selection == data->selection) &&
- (handler->target == data->target))
- break;
- tmp_list = tmp_list->next;
+ gtk_signal_emit_by_name (GTK_OBJECT (widget),
+ "selection_get",
+ data,
+ info, time);
}
-
- if (tmp_list == NULL)
- gtk_selection_default_handler (widget, data);
else
- {
- if (handler->marshal)
- {
- GtkArg args[2];
- args[0].type = GTK_TYPE_BOXED;
- args[0].name = NULL;
- GTK_VALUE_BOXED(args[0]) = data;
- args[1].type = GTK_TYPE_NONE;
- args[1].name = NULL;
-
- handler->marshal (GTK_OBJECT(widget), handler->data, 1, args);
- }
- else
- if (handler->function)
- handler->function (widget, data, handler->data);
- }
+ gtk_selection_default_handler (widget, data);
}
/*************************************************************
@@ -1369,18 +1472,16 @@ gtk_selection_default_handler (GtkWidget *widget,
GdkAtom *p;
gint count;
GList *tmp_list;
- GtkSelectionHandler *handler;
+ GtkTargetList *target_list;
+ GtkTargetPair *pair;
count = 3;
- tmp_list = gtk_object_get_data (GTK_OBJECT(widget),
- gtk_selection_handler_key);
+ target_list = gtk_selection_target_list_get (widget,
+ data->selection);
+ tmp_list = target_list->list;
while (tmp_list)
{
- handler = (GtkSelectionHandler *)tmp_list->data;
-
- if (handler->selection == data->selection)
- count++;
-
+ count++;
tmp_list = tmp_list->next;
}
@@ -1395,14 +1496,11 @@ gtk_selection_default_handler (GtkWidget *widget,
*p++ = gtk_selection_atoms[TARGETS];
*p++ = gtk_selection_atoms[MULTIPLE];
- tmp_list = gtk_object_get_data (GTK_OBJECT(widget),
- gtk_selection_handler_key);
+ tmp_list = target_list->list;
while (tmp_list)
{
- handler = (GtkSelectionHandler *)tmp_list->data;
-
- if (handler->selection == data->selection)
- *p++ = handler->target;
+ pair = (GtkTargetPair *)tmp_list->data;
+ *p++ = pair->target;
tmp_list = tmp_list->next;
}
diff --git a/gtk/gtkselection.h b/gtk/gtkselection.h
index 21f9ed2664..75fcd5aeb6 100644
--- a/gtk/gtkselection.h
+++ b/gtk/gtkselection.h
@@ -29,36 +29,63 @@ extern "C" {
#endif /* __cplusplus */
typedef struct _GtkSelectionData GtkSelectioData;
+typedef struct _GtkTargetList GtkTargetList;
+typedef struct _GtkTargetEntry GtkTargetEntry;
-/* a callback function that provides the selection. Arguments are:
- widget: selection owner
- offset: offset into selection
- buffer: buffer into which to store selection
- length: length of buffer
- bytes_after: (sizeof(selection) - offset - length ) (return)
- data: callback data */
+struct _GtkTargetEntry {
+ gchar *target;
+ guint flags;
+ guint info;
+};
-typedef void (*GtkSelectionFunction) (GtkWidget *widget,
- GtkSelectionData *selection_data,
- gpointer data);
+/* These structures not public, and are here only for the convenience of
+ * gtkdnd.c
+ */
+
+typedef struct _GtkTargetPair GtkTargetPair;
+
+/* This structure is a list of destinations, and associated guint id's */
+struct _GtkTargetList {
+ GList *list;
+ guint ref_count;
+};
+
+struct _GtkTargetPair {
+ GdkAtom target;
+ guint flags;
+ guint info;
+};
+
+GtkTargetList *gtk_target_list_new (GtkTargetEntry *targets,
+ guint ntargets);
+void gtk_target_list_ref (GtkTargetList *list);
+void gtk_target_list_unref (GtkTargetList *list);
+void gtk_target_list_add (GtkTargetList *list,
+ GdkAtom target,
+ guint flags,
+ guint info);
+void gtk_target_list_add_table (GtkTargetList *list,
+ GtkTargetEntry *targets,
+ guint ntargets);
+void gtk_target_list_remove (GtkTargetList *list,
+ GdkAtom target);
+gboolean gtk_target_list_find (GtkTargetList *list,
+ GdkAtom target,
+ guint *info);
/* Public interface */
gint gtk_selection_owner_set (GtkWidget *widget,
GdkAtom selection,
guint32 time);
-void gtk_selection_add_handler (GtkWidget *widget,
+void gtk_selection_add_target (GtkWidget *widget,
+ GdkAtom selection,
+ GdkAtom target,
+ guint info);
+void gtk_selection_add_targets (GtkWidget *widget,
GdkAtom selection,
- GdkAtom target,
- GtkSelectionFunction function,
- gpointer data);
-void gtk_selection_add_handler_full (GtkWidget *widget,
- GdkAtom selection,
- GdkAtom target,
- GtkSelectionFunction function,
- GtkCallbackMarshal marshal,
- gpointer data,
- GtkDestroyNotify destroy);
+ GtkTargetEntry *targets,
+ guint ntargets);
gint gtk_selection_convert (GtkWidget *widget,
GdkAtom selection,
GdkAtom target,
diff --git a/gtk/gtksignal.c b/gtk/gtksignal.c
index a35840f656..f9b3bec44c 100644
--- a/gtk/gtksignal.c
+++ b/gtk/gtksignal.c
@@ -290,7 +290,7 @@ gtk_signal_newv (const gchar *r_name,
if (return_val != GTK_TYPE_NONE &&
(signal_flags & GTK_RUN_BOTH) == GTK_RUN_FIRST)
{
- g_warning ("gtk_signal_newv(): signal \"%s\" with return value `%s' excludes GTK_RUN_LAST",
+ g_warning ("gtk_signal_newv(): signal \"%s\" - return value `%s' incompatible with GTK_RUN_FIRST",
name, gtk_type_name (return_val));
g_free (name);
return 0;
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 5d1a5fb12b..0def4b5c52 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -28,7 +28,6 @@
extern "C" {
#endif /* __cplusplus */
-
typedef struct _GtkStyle GtkStyle;
typedef struct _GtkStyleClass GtkStyleClass;
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 6871d48a4f..218428abe9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -72,16 +72,18 @@ enum {
SELECTION_CLEAR_EVENT,
SELECTION_REQUEST_EVENT,
SELECTION_NOTIFY_EVENT,
+ SELECTION_GET,
SELECTION_RECEIVED,
PROXIMITY_IN_EVENT,
PROXIMITY_OUT_EVENT,
- DRAG_BEGIN_EVENT,
- DRAG_REQUEST_EVENT,
- DRAG_END_EVENT,
- DROP_ENTER_EVENT,
- DROP_LEAVE_EVENT,
- DROP_DATA_AVAILABLE_EVENT,
- OTHER_EVENT,
+ DRAG_BEGIN,
+ DRAG_END,
+ DRAG_DATA_DELETE,
+ DRAG_LEAVE,
+ DRAG_MOTION,
+ DRAG_DROP,
+ DRAG_DATA_GET,
+ DRAG_DATA_RECEIVED,
CLIENT_EVENT,
NO_EXPOSE_EVENT,
VISIBILITY_NOTIFY_EVENT,
@@ -548,9 +550,20 @@ gtk_widget_class_init (GtkWidgetClass *klass)
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_received),
- gtk_marshal_NONE__ENUM,
- GTK_TYPE_NONE, 1,
- GTK_TYPE_SELECTION_DATA);
+ gtk_marshal_NONE__POINTER_UINT,
+ GTK_TYPE_NONE, 2,
+ GTK_TYPE_SELECTION_DATA,
+ GTK_TYPE_UINT);
+ widget_signals[SELECTION_GET] =
+ gtk_signal_new ("selection_get",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, selection_get),
+ gtk_marshal_NONE__POINTER_UINT_UINT,
+ GTK_TYPE_NONE, 2,
+ GTK_TYPE_SELECTION_DATA,
+ GTK_TYPE_UINT,
+ GTK_TYPE_UINT);
widget_signals[PROXIMITY_IN_EVENT] =
gtk_signal_new ("proximity_in_event",
GTK_RUN_LAST,
@@ -567,55 +580,83 @@ gtk_widget_class_init (GtkWidgetClass *klass)
gtk_marshal_BOOL__POINTER,
GTK_TYPE_BOOL, 1,
GTK_TYPE_GDK_EVENT);
- widget_signals[DRAG_BEGIN_EVENT] =
- gtk_signal_new ("drag_begin_event",
+ widget_signals[DRAG_LEAVE] =
+ gtk_signal_new ("drag_leave",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
- widget_signals[DRAG_REQUEST_EVENT] =
- gtk_signal_new ("drag_request_event",
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_leave),
+ gtk_marshal_NONE__POINTER_UINT,
+ GTK_TYPE_NONE, 2,
+ GTK_TYPE_GDK_DRAG_CONTEXT,
+ GTK_TYPE_UINT);
+ widget_signals[DRAG_BEGIN] =
+ gtk_signal_new ("drag_begin",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_request_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
- widget_signals[DRAG_END_EVENT] =
- gtk_signal_new ("drag_end_event",
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_begin),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_GDK_DRAG_CONTEXT);
+ widget_signals[DRAG_END] =
+ gtk_signal_new ("drag_end",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
- widget_signals[DROP_ENTER_EVENT] =
- gtk_signal_new ("drop_enter_event",
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_end),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_GDK_DRAG_CONTEXT);
+ widget_signals[DRAG_DATA_DELETE] =
+ gtk_signal_new ("drag_data_delete",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, drop_enter_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
- widget_signals[DROP_LEAVE_EVENT] =
- gtk_signal_new ("drop_leave_event",
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_delete),
+ gtk_marshal_NONE__POINTER,
+ GTK_TYPE_NONE, 1,
+ GTK_TYPE_GDK_DRAG_CONTEXT);
+ widget_signals[DRAG_MOTION] =
+ gtk_signal_new ("drag_motion",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, drop_leave_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
- widget_signals[DROP_DATA_AVAILABLE_EVENT] =
- gtk_signal_new ("drop_data_available_event",
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_motion),
+ gtk_marshal_BOOL__POINTER_INT_INT_UINT,
+ GTK_TYPE_BOOL, 4,
+ GTK_TYPE_GDK_DRAG_CONTEXT,
+ GTK_TYPE_INT,
+ GTK_TYPE_INT,
+ GTK_TYPE_UINT);
+ widget_signals[DRAG_DROP] =
+ gtk_signal_new ("drag_drop",
GTK_RUN_LAST,
object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass,
- drop_data_available_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_drop),
+ gtk_marshal_BOOL__POINTER_INT_INT_UINT,
+ GTK_TYPE_BOOL, 4,
+ GTK_TYPE_GDK_DRAG_CONTEXT,
+ GTK_TYPE_INT,
+ GTK_TYPE_INT,
+ GTK_TYPE_UINT);
+ widget_signals[DRAG_DATA_GET] =
+ gtk_signal_new ("drag_data_get",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_get),
+ gtk_marshal_NONE__POINTER_POINTER_UINT_UINT,
+ GTK_TYPE_NONE, 4,
+ GTK_TYPE_GDK_DRAG_CONTEXT,
+ GTK_TYPE_SELECTION_DATA,
+ GTK_TYPE_UINT,
+ GTK_TYPE_UINT);
+ widget_signals[DRAG_DATA_RECEIVED] =
+ gtk_signal_new ("drag_data_received",
+ GTK_RUN_LAST,
+ object_class->type,
+ GTK_SIGNAL_OFFSET (GtkWidgetClass, drag_data_received),
+ gtk_marshal_NONE__POINTER_POINTER_UINT_UINT,
+ GTK_TYPE_NONE, 4,
+ GTK_TYPE_GDK_DRAG_CONTEXT,
+ GTK_TYPE_SELECTION_DATA,
+ GTK_TYPE_UINT,
+ GTK_TYPE_UINT);
widget_signals[VISIBILITY_NOTIFY_EVENT] =
gtk_signal_new ("visibility_notify_event",
GTK_RUN_LAST,
@@ -640,14 +681,6 @@ gtk_widget_class_init (GtkWidgetClass *klass)
gtk_marshal_BOOL__POINTER,
GTK_TYPE_BOOL, 1,
GTK_TYPE_GDK_EVENT);
- widget_signals[OTHER_EVENT] =
- gtk_signal_new ("other_event",
- GTK_RUN_LAST,
- object_class->type,
- GTK_SIGNAL_OFFSET (GtkWidgetClass, other_event),
- gtk_marshal_BOOL__POINTER,
- GTK_TYPE_BOOL, 1,
- GTK_TYPE_GDK_EVENT);
widget_signals[DEBUG_MSG] =
gtk_signal_new ("debug_msg",
GTK_RUN_LAST | GTK_RUN_ACTION,
@@ -706,13 +739,15 @@ gtk_widget_class_init (GtkWidgetClass *klass)
klass->selection_received = NULL;
klass->proximity_in_event = NULL;
klass->proximity_out_event = NULL;
- klass->drag_begin_event = NULL;
- klass->drag_request_event = NULL;
- klass->drop_enter_event = NULL;
- klass->drop_leave_event = NULL;
- klass->drop_data_available_event = NULL;
+ klass->drag_begin = NULL;
+ klass->drag_end = NULL;
+ klass->drag_data_delete = NULL;
+ klass->drag_leave = NULL;
+ klass->drag_motion = NULL;
+ klass->drag_drop = NULL;
+ klass->drag_data_received = NULL;
+
klass->no_expose_event = NULL;
- klass->other_event = NULL;
klass->debug_msg = gtk_widget_debug_msg;
}
@@ -2071,24 +2106,6 @@ gtk_widget_event (GtkWidget *widget,
case GDK_PROXIMITY_OUT:
signal_num = PROXIMITY_OUT_EVENT;
break;
- case GDK_DRAG_BEGIN:
- signal_num = DRAG_BEGIN_EVENT;
- break;
- case GDK_DRAG_REQUEST:
- signal_num = DRAG_REQUEST_EVENT;
- break;
- case GDK_DROP_ENTER:
- signal_num = DROP_ENTER_EVENT;
- break;
- case GDK_DROP_LEAVE:
- signal_num = DROP_LEAVE_EVENT;
- break;
- case GDK_DROP_DATA_AVAIL:
- signal_num = DROP_DATA_AVAILABLE_EVENT;
- break;
- case GDK_OTHER_EVENT:
- signal_num = OTHER_EVENT;
- break;
case GDK_NO_EXPOSE:
signal_num = NO_EXPOSE_EVENT;
break;
@@ -3000,6 +3017,51 @@ gtk_widget_set_events (GtkWidget *widget,
}
/*****************************************
+ * gtk_widget_add_events:
+ *
+ * arguments:
+ *
+ * results:
+ *****************************************/
+
+void
+gtk_widget_add_events (GtkWidget *widget,
+ gint events)
+{
+ gint *eventp;
+
+ g_return_if_fail (widget != NULL);
+ g_return_if_fail (!GTK_WIDGET_NO_WINDOW (widget));
+
+ eventp = gtk_object_get_data_by_id (GTK_OBJECT (widget), event_key_id);
+
+ if (events)
+ {
+ if (!eventp)
+ {
+ eventp = g_new (gint, 1);
+ *eventp = 0;
+ }
+
+ *eventp |= events;
+ if (!event_key_id)
+ event_key_id = g_quark_from_static_string (event_key);
+ gtk_object_set_data_by_id (GTK_OBJECT (widget), event_key_id, eventp);
+ }
+ else if (eventp)
+ {
+ g_free (eventp);
+ gtk_object_remove_data_by_id (GTK_OBJECT (widget), event_key_id);
+ }
+
+ if (GTK_WIDGET_REALIZED (widget))
+ {
+ gdk_window_set_events (widget->window,
+ gdk_window_get_events (widget->window) | events);
+ }
+}
+
+/*****************************************
* gtk_widget_set_extension_events:
*
* arguments:
@@ -3949,96 +4011,6 @@ gtk_widget_shape_combine_mask (GtkWidget *widget,
}
}
-/*****************************************
- * gtk_widget_dnd_drag_add:
- * when you get a DRAG_ENTER event, you can use this
- * to tell Gtk ofother widgets that are to be dragged as well
- *
- * arguments:
- *
- * results:
- *****************************************/
-void
-gtk_widget_dnd_drag_add (GtkWidget *widget)
-{
-}
-
-/*****************************************
- * gtk_widget_dnd_drag_set:
- * these two functions enable drag and/or drop on a
- * widget and also let Gtk know what data types will be accepted
- * use MIME type naming,plus tacking "URL:" on the front for link
- * dragging
- *
- *
- * arguments:
- *
- * results:
- *****************************************/
-void
-gtk_widget_dnd_drag_set (GtkWidget *widget,
- guint8 drag_enable,
- gchar **type_accept_list,
- guint numtypes)
-{
- g_return_if_fail(widget != NULL);
-
- if (!widget->window)
- gtk_widget_realize (widget);
-
- g_return_if_fail (widget->window != NULL);
- gdk_window_dnd_drag_set (widget->window,
- drag_enable,
- type_accept_list,
- numtypes);
-}
-
-/*****************************************
- * gtk_widget_dnd_drop_set:
- *
- * arguments:
- *
- * results:
- *****************************************/
-void
-gtk_widget_dnd_drop_set (GtkWidget *widget,
- guint8 drop_enable,
- gchar **type_accept_list,
- guint numtypes,
- guint8 is_destructive_operation)
-{
- g_return_if_fail(widget != NULL);
-
- if (!widget->window)
- gtk_widget_realize (widget);
-
- g_return_if_fail (widget->window != NULL);
- gdk_window_dnd_drop_set (widget->window,
- drop_enable,
- type_accept_list,
- numtypes,
- is_destructive_operation);
-}
-
-/*****************************************
- * gtk_widget_dnd_data_set:
- *
- * arguments:
- *
- * results:
- *****************************************/
-void
-gtk_widget_dnd_data_set (GtkWidget *widget,
- GdkEvent *event,
- gpointer data,
- gulong data_numbytes)
-{
- g_return_if_fail (widget != NULL);
- g_return_if_fail (widget->window != NULL);
-
- gdk_window_dnd_data_set (widget->window, event, data, data_numbytes);
-}
-
void
gtk_widget_ref (GtkWidget *widget)
{
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index de0d954f1b..505b701759 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -136,7 +136,7 @@ struct _GtkAllocation
no fields should be modified directly, they should not be created
directly, and pointers to them should not be stored beyond the duration of
a callback. (If the last is changed, we'll need to add reference
- counting) */
+ counting.) The time field gives the timestamp at which the data was sent. */
struct _GtkSelectionData
{
@@ -314,31 +314,55 @@ struct _GtkWidgetClass
GdkEventProximity *event);
gint (* proximity_out_event) (GtkWidget *widget,
GdkEventProximity *event);
- gint (* drag_begin_event) (GtkWidget *widget,
- GdkEventDragBegin *event);
- gint (* drag_request_event) (GtkWidget *widget,
- GdkEventDragRequest *event);
- gint (* drag_end_event) (GtkWidget *widget,
- GdkEvent *event);
- gint (* drop_enter_event) (GtkWidget *widget,
- GdkEventDropEnter *event);
- gint (* drop_leave_event) (GtkWidget *widget,
- GdkEventDropLeave *event);
- gint (* drop_data_available_event)(GtkWidget *widget,
- GdkEventDropDataAvailable *event);
gint (* visibility_notify_event) (GtkWidget *widget,
GdkEventVisibility *event);
gint (* client_event) (GtkWidget *widget,
GdkEventClient *event);
gint (* no_expose_event) (GtkWidget *widget,
GdkEventAny *event);
- gint (* other_event) (GtkWidget *widget,
- GdkEventOther *event);
-
+
/* selection */
+ void (* selection_get) (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time);
void (* selection_received) (GtkWidget *widget,
- GtkSelectionData *selection_data);
-
+ GtkSelectionData *selection_data,
+ guint time);
+
+ /* Source side drag signals */
+ void (* drag_begin) (GtkWidget *widget,
+ GdkDragContext *context);
+ void (* drag_end) (GtkWidget *widget,
+ GdkDragContext *context);
+ void (* drag_data_get) (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time);
+ void (* drag_data_delete) (GtkWidget *widget,
+ GdkDragContext *context);
+
+ /* Target side drag signals */
+ void (* drag_leave) (GtkWidget *widget,
+ GdkDragContext *context,
+ guint time);
+ gboolean (* drag_motion) (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+ gboolean (* drag_drop) (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ guint time);
+ void (* drag_data_received) (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint32 time);
+
/* action signals */
void (* debug_msg) (GtkWidget *widget,
const gchar *string);
@@ -460,6 +484,8 @@ void gtk_widget_set_usize (GtkWidget *widget,
gint height);
void gtk_widget_set_events (GtkWidget *widget,
gint events);
+void gtk_widget_add_events (GtkWidget *widget,
+ gint events);
void gtk_widget_set_extension_events (GtkWidget *widget,
GdkExtensionMode mode);
@@ -536,33 +562,6 @@ void gtk_widget_class_path (GtkWidget *widget,
gchar **path,
gchar **path_reversed);
-/* When you get a drag_enter event, you can use this to tell Gtk of other
- * items that are to be dragged as well...
- */
-void gtk_widget_dnd_drag_add (GtkWidget *widget);
-
-/* These two functions enable drag and/or drop on a widget,
- * and also let Gtk know what data types will be accepted (use MIME
- * type naming, plus tacking "URL:" on the front for link dragging)
- */
-void gtk_widget_dnd_drag_set (GtkWidget *widget,
- guint8 drag_enable,
- gchar **type_accept_list,
- guint numtypes);
-void gtk_widget_dnd_drop_set (GtkWidget *widget,
- guint8 drop_enable,
- gchar **type_accept_list,
- guint numtypes,
- guint8 is_destructive_operation);
-
-/* Used to reply to a DRAG_REQUEST event - if you don't want to
- * give the data then pass in NULL for it
- */
-void gtk_widget_dnd_data_set (GtkWidget *widget,
- GdkEvent *event,
- gpointer data,
- gulong data_numbytes);
-
#if defined (GTK_TRACE_OBJECTS) && defined (__GNUC__)
# define gtk_widget_ref gtk_object_ref
# define gtk_widget_unref gtk_object_unref
diff --git a/gtk/testgtk.c b/gtk/testgtk.c
index 914725b21f..68ff79724d 100644
--- a/gtk/testgtk.c
+++ b/gtk/testgtk.c
@@ -6039,6 +6039,7 @@ create_panes (void)
* Drag -N- Drop
*/
+#if 0
gint
dnd_drop_destroy_popup (GtkWidget *widget, GtkWindow **window)
{
@@ -6263,6 +6264,7 @@ create_dnd (void)
else
gtk_widget_destroy (window);
}
+#endif
/*
* Shaped Windows
@@ -7908,7 +7910,7 @@ create_main_window (void)
{ "ctree", create_ctree },
{ "cursors", create_cursors },
{ "dialog", create_dialog },
- { "dnd", create_dnd },
+ /* { "dnd", create_dnd }, */
{ "entry", create_entry },
{ "file selection", create_file_selection },
{ "font selection", create_font_selection },
diff --git a/gtk/testselection.c b/gtk/testselection.c
index 2c12b8dec4..bcb6c57bb4 100644
--- a/gtk/testselection.c
+++ b/gtk/testselection.c
@@ -48,50 +48,49 @@ typedef struct _Target {
SelType type;
GdkAtom target;
gint format;
- GtkSelectionFunction *handler;
} Target;
/* The following is a list of all the selection targets defined
in the ICCCM */
static Target targets[] = {
- { "ADOBE_PORTABLE_DOCUMENT_FORMAT", STRING, 0, 8, NULL },
- { "APPLE_PICT", APPLE_PICT, 0, 8, NULL },
- { "BACKGROUND", PIXEL, 0, 32, NULL },
- { "BITMAP", BITMAP, 0, 32, NULL },
- { "CHARACTER_POSITION", SPAN, 0, 32, NULL },
- { "CLASS", TEXT, 0, 8, NULL },
- { "CLIENT_WINDOW", WINDOW, 0, 32, NULL },
- { "COLORMAP", COLORMAP, 0, 32, NULL },
- { "COLUMN_NUMBER", SPAN, 0, 32, NULL },
- { "COMPOUND_TEXT", COMPOUND_TEXT, 0, 8, NULL },
- /* { "DELETE", "NULL", 0, ?, NULL }, */
- { "DRAWABLE", DRAWABLE, 0, 32, NULL },
- { "ENCAPSULATED_POSTSCRIPT", STRING, 0, 8, NULL },
- { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE", STRING, 0, 8, NULL },
- { "FILE_NAME", TEXT, 0, 8, NULL },
- { "FOREGROUND", PIXEL, 0, 32, NULL },
- { "HOST_NAME", TEXT, 0, 8, NULL },
+ { "ADOBE_PORTABLE_DOCUMENT_FORMAT", STRING, 0, 8 },
+ { "APPLE_PICT", APPLE_PICT, 0, 8 },
+ { "BACKGROUND", PIXEL, 0, 32 },
+ { "BITMAP", BITMAP, 0, 32 },
+ { "CHARACTER_POSITION", SPAN, 0, 32 },
+ { "CLASS", TEXT, 0, 8 },
+ { "CLIENT_WINDOW", WINDOW, 0, 32 },
+ { "COLORMAP", COLORMAP, 0, 32 },
+ { "COLUMN_NUMBER", SPAN, 0, 32 },
+ { "COMPOUND_TEXT", COMPOUND_TEXT, 0, 8 },
+ /* { "DELETE", "NULL", 0, ? }, */
+ { "DRAWABLE", DRAWABLE, 0, 32 },
+ { "ENCAPSULATED_POSTSCRIPT", STRING, 0, 8 },
+ { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE", STRING, 0, 8 },
+ { "FILE_NAME", TEXT, 0, 8 },
+ { "FOREGROUND", PIXEL, 0, 32 },
+ { "HOST_NAME", TEXT, 0, 8 },
/* { "INSERT_PROPERTY", "NULL", 0, ? NULL }, */
/* { "INSERT_SELECTION", "NULL", 0, ? NULL }, */
- { "LENGTH", INTEGER, 0, 32, NULL },
- { "LINE_NUMBER", SPAN, 0, 32, NULL },
- { "LIST_LENGTH", INTEGER, 0, 32, NULL },
- { "MODULE", TEXT, 0, 8, NULL },
- /* { "MULTIPLE", "ATOM_PAIR", 0, 32, NULL }, */
- { "NAME", TEXT, 0, 8, NULL },
- { "ODIF", TEXT, 0, 8, NULL },
- { "OWNER_OS", TEXT, 0, 8, NULL },
- { "PIXMAP", PIXMAP, 0, 32, NULL },
- { "POSTSCRIPT", STRING, 0, 8, NULL },
- { "PROCEDURE", TEXT, 0, 8, NULL },
- { "PROCESS", INTEGER, 0, 32, NULL },
- { "STRING", STRING, 0, 8, NULL },
- { "TARGETS", ATOM, 0, 32, NULL },
- { "TASK", INTEGER, 0, 32, NULL },
- { "TEXT", TEXT, 0, 8 , NULL },
- { "TIMESTAMP", INTEGER, 0, 32, NULL },
- { "USER", TEXT, 0, 8, NULL },
+ { "LENGTH", INTEGER, 0, 32 },
+ { "LINE_NUMBER", SPAN, 0, 32 },
+ { "LIST_LENGTH", INTEGER, 0, 32 },
+ { "MODULE", TEXT, 0, 8 },
+ /* { "MULTIPLE", "ATOM_PAIR", 0, 32 }, */
+ { "NAME", TEXT, 0, 8 },
+ { "ODIF", TEXT, 0, 8 },
+ { "OWNER_OS", TEXT, 0, 8 },
+ { "PIXMAP", PIXMAP, 0, 32 },
+ { "POSTSCRIPT", STRING, 0, 8 },
+ { "PROCEDURE", TEXT, 0, 8 },
+ { "PROCESS", INTEGER, 0, 32 },
+ { "STRING", STRING, 0, 8 },
+ { "TARGETS", ATOM, 0, 32 },
+ { "TASK", INTEGER, 0, 32 },
+ { "TEXT", TEXT, 0, 8 },
+ { "TIMESTAMP", INTEGER, 0, 32 },
+ { "USER", TEXT, 0, 8 },
};
static int num_targets = sizeof(targets)/sizeof(Target);
@@ -152,11 +151,15 @@ selection_toggled (GtkWidget *widget)
}
void
-selection_handle (GtkWidget *widget,
- GtkSelectionData *selection_data, gpointer data)
+selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data)
{
guchar *buffer;
gint len;
+ GdkAtom type = GDK_NONE;
if (!selection_string)
{
@@ -168,11 +171,17 @@ selection_handle (GtkWidget *widget,
buffer = (guchar *)selection_string->str;
len = selection_string->len;
}
+
+ switch (info)
+ {
+ case COMPOUND_TEXT:
+ case TEXT:
+ type = seltypes[COMPOUND_TEXT];
+ case STRING:
+ type = seltypes[STRING];
+ }
- gtk_selection_data_set (selection_data,
- selection_data->target == seltypes[COMPOUND_TEXT] ?
- seltypes[COMPOUND_TEXT] : seltypes[STRING],
- 8, buffer, len);
+ gtk_selection_data_set (selection_data, type, 8, buffer, len);
}
gint
@@ -373,6 +382,13 @@ main (int argc, char *argv[])
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkWidget *hbox;
+
+ static GtkTargetEntry targetlist[] = {
+ { "STRING", STRING },
+ { "TEXT", TEXT },
+ { "COMPOUND_TEXT", COMPOUND_TEXT }
+ };
+ static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
gtk_init (&argc, &argv);
@@ -408,15 +424,11 @@ main (int argc, char *argv[])
gtk_signal_connect (GTK_OBJECT(selection_button), "selection_received",
GTK_SIGNAL_FUNC (selection_received), NULL);
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[STRING], selection_handle, NULL);
-
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[TEXT], selection_handle, NULL);
+ gtk_selection_add_targets (selection_button, GDK_SELECTION_PRIMARY,
+ targetlist, ntargets);
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[COMPOUND_TEXT],
- selection_handle, NULL);
+ gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get",
+ GTK_SIGNAL_FUNC (selection_get), NULL);
selection_text = gtk_text_new (NULL, NULL);
gtk_table_attach_defaults (GTK_TABLE (table), selection_text, 0, 1, 1, 2);
diff --git a/tests/testgtk.c b/tests/testgtk.c
index 914725b21f..68ff79724d 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -6039,6 +6039,7 @@ create_panes (void)
* Drag -N- Drop
*/
+#if 0
gint
dnd_drop_destroy_popup (GtkWidget *widget, GtkWindow **window)
{
@@ -6263,6 +6264,7 @@ create_dnd (void)
else
gtk_widget_destroy (window);
}
+#endif
/*
* Shaped Windows
@@ -7908,7 +7910,7 @@ create_main_window (void)
{ "ctree", create_ctree },
{ "cursors", create_cursors },
{ "dialog", create_dialog },
- { "dnd", create_dnd },
+ /* { "dnd", create_dnd }, */
{ "entry", create_entry },
{ "file selection", create_file_selection },
{ "font selection", create_font_selection },
diff --git a/tests/testselection.c b/tests/testselection.c
index 2c12b8dec4..bcb6c57bb4 100644
--- a/tests/testselection.c
+++ b/tests/testselection.c
@@ -48,50 +48,49 @@ typedef struct _Target {
SelType type;
GdkAtom target;
gint format;
- GtkSelectionFunction *handler;
} Target;
/* The following is a list of all the selection targets defined
in the ICCCM */
static Target targets[] = {
- { "ADOBE_PORTABLE_DOCUMENT_FORMAT", STRING, 0, 8, NULL },
- { "APPLE_PICT", APPLE_PICT, 0, 8, NULL },
- { "BACKGROUND", PIXEL, 0, 32, NULL },
- { "BITMAP", BITMAP, 0, 32, NULL },
- { "CHARACTER_POSITION", SPAN, 0, 32, NULL },
- { "CLASS", TEXT, 0, 8, NULL },
- { "CLIENT_WINDOW", WINDOW, 0, 32, NULL },
- { "COLORMAP", COLORMAP, 0, 32, NULL },
- { "COLUMN_NUMBER", SPAN, 0, 32, NULL },
- { "COMPOUND_TEXT", COMPOUND_TEXT, 0, 8, NULL },
- /* { "DELETE", "NULL", 0, ?, NULL }, */
- { "DRAWABLE", DRAWABLE, 0, 32, NULL },
- { "ENCAPSULATED_POSTSCRIPT", STRING, 0, 8, NULL },
- { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE", STRING, 0, 8, NULL },
- { "FILE_NAME", TEXT, 0, 8, NULL },
- { "FOREGROUND", PIXEL, 0, 32, NULL },
- { "HOST_NAME", TEXT, 0, 8, NULL },
+ { "ADOBE_PORTABLE_DOCUMENT_FORMAT", STRING, 0, 8 },
+ { "APPLE_PICT", APPLE_PICT, 0, 8 },
+ { "BACKGROUND", PIXEL, 0, 32 },
+ { "BITMAP", BITMAP, 0, 32 },
+ { "CHARACTER_POSITION", SPAN, 0, 32 },
+ { "CLASS", TEXT, 0, 8 },
+ { "CLIENT_WINDOW", WINDOW, 0, 32 },
+ { "COLORMAP", COLORMAP, 0, 32 },
+ { "COLUMN_NUMBER", SPAN, 0, 32 },
+ { "COMPOUND_TEXT", COMPOUND_TEXT, 0, 8 },
+ /* { "DELETE", "NULL", 0, ? }, */
+ { "DRAWABLE", DRAWABLE, 0, 32 },
+ { "ENCAPSULATED_POSTSCRIPT", STRING, 0, 8 },
+ { "ENCAPSULATED_POSTSCRIPT_INTERCHANGE", STRING, 0, 8 },
+ { "FILE_NAME", TEXT, 0, 8 },
+ { "FOREGROUND", PIXEL, 0, 32 },
+ { "HOST_NAME", TEXT, 0, 8 },
/* { "INSERT_PROPERTY", "NULL", 0, ? NULL }, */
/* { "INSERT_SELECTION", "NULL", 0, ? NULL }, */
- { "LENGTH", INTEGER, 0, 32, NULL },
- { "LINE_NUMBER", SPAN, 0, 32, NULL },
- { "LIST_LENGTH", INTEGER, 0, 32, NULL },
- { "MODULE", TEXT, 0, 8, NULL },
- /* { "MULTIPLE", "ATOM_PAIR", 0, 32, NULL }, */
- { "NAME", TEXT, 0, 8, NULL },
- { "ODIF", TEXT, 0, 8, NULL },
- { "OWNER_OS", TEXT, 0, 8, NULL },
- { "PIXMAP", PIXMAP, 0, 32, NULL },
- { "POSTSCRIPT", STRING, 0, 8, NULL },
- { "PROCEDURE", TEXT, 0, 8, NULL },
- { "PROCESS", INTEGER, 0, 32, NULL },
- { "STRING", STRING, 0, 8, NULL },
- { "TARGETS", ATOM, 0, 32, NULL },
- { "TASK", INTEGER, 0, 32, NULL },
- { "TEXT", TEXT, 0, 8 , NULL },
- { "TIMESTAMP", INTEGER, 0, 32, NULL },
- { "USER", TEXT, 0, 8, NULL },
+ { "LENGTH", INTEGER, 0, 32 },
+ { "LINE_NUMBER", SPAN, 0, 32 },
+ { "LIST_LENGTH", INTEGER, 0, 32 },
+ { "MODULE", TEXT, 0, 8 },
+ /* { "MULTIPLE", "ATOM_PAIR", 0, 32 }, */
+ { "NAME", TEXT, 0, 8 },
+ { "ODIF", TEXT, 0, 8 },
+ { "OWNER_OS", TEXT, 0, 8 },
+ { "PIXMAP", PIXMAP, 0, 32 },
+ { "POSTSCRIPT", STRING, 0, 8 },
+ { "PROCEDURE", TEXT, 0, 8 },
+ { "PROCESS", INTEGER, 0, 32 },
+ { "STRING", STRING, 0, 8 },
+ { "TARGETS", ATOM, 0, 32 },
+ { "TASK", INTEGER, 0, 32 },
+ { "TEXT", TEXT, 0, 8 },
+ { "TIMESTAMP", INTEGER, 0, 32 },
+ { "USER", TEXT, 0, 8 },
};
static int num_targets = sizeof(targets)/sizeof(Target);
@@ -152,11 +151,15 @@ selection_toggled (GtkWidget *widget)
}
void
-selection_handle (GtkWidget *widget,
- GtkSelectionData *selection_data, gpointer data)
+selection_get (GtkWidget *widget,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer data)
{
guchar *buffer;
gint len;
+ GdkAtom type = GDK_NONE;
if (!selection_string)
{
@@ -168,11 +171,17 @@ selection_handle (GtkWidget *widget,
buffer = (guchar *)selection_string->str;
len = selection_string->len;
}
+
+ switch (info)
+ {
+ case COMPOUND_TEXT:
+ case TEXT:
+ type = seltypes[COMPOUND_TEXT];
+ case STRING:
+ type = seltypes[STRING];
+ }
- gtk_selection_data_set (selection_data,
- selection_data->target == seltypes[COMPOUND_TEXT] ?
- seltypes[COMPOUND_TEXT] : seltypes[STRING],
- 8, buffer, len);
+ gtk_selection_data_set (selection_data, type, 8, buffer, len);
}
gint
@@ -373,6 +382,13 @@ main (int argc, char *argv[])
GtkWidget *hscrollbar;
GtkWidget *vscrollbar;
GtkWidget *hbox;
+
+ static GtkTargetEntry targetlist[] = {
+ { "STRING", STRING },
+ { "TEXT", TEXT },
+ { "COMPOUND_TEXT", COMPOUND_TEXT }
+ };
+ static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]);
gtk_init (&argc, &argv);
@@ -408,15 +424,11 @@ main (int argc, char *argv[])
gtk_signal_connect (GTK_OBJECT(selection_button), "selection_received",
GTK_SIGNAL_FUNC (selection_received), NULL);
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[STRING], selection_handle, NULL);
-
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[TEXT], selection_handle, NULL);
+ gtk_selection_add_targets (selection_button, GDK_SELECTION_PRIMARY,
+ targetlist, ntargets);
- gtk_selection_add_handler (selection_button, GDK_SELECTION_PRIMARY,
- seltypes[COMPOUND_TEXT],
- selection_handle, NULL);
+ gtk_signal_connect (GTK_OBJECT(selection_button), "selection_get",
+ GTK_SIGNAL_FUNC (selection_get), NULL);
selection_text = gtk_text_new (NULL, NULL);
gtk_table_attach_defaults (GTK_TABLE (table), selection_text, 0, 1, 1, 2);