Bringing gtkdnd.c into the pixbuf era



This patch:
 
 - Adds a new icon size GTK_ICON_SIZE_DND and two new stock
   ids: GTK_STOCK_DND, GTK_STOCK_DND_MULTIPLE.

 - Makes GTK+ uses GTK_STOCK_DND for the default drag icon

 - Adds some new functions for setting the drag icons from
   stock ids and pixbufs:

void gtk_drag_set_icon_pixbuf (GdkDragContext *context,
                               GdkPixbuf      *pixbuf,
                               gint            hot_x,
                               gint            hot_y);
void gtk_drag_set_icon_stock  (GdkDragContext *context,
                               const gchar    *stock_id,
                               gint            hot_x,
                               gint            hot_y);
void gtk_drag_source_set_icon_pixbuf (GtkWidget   *widget,
                                      GdkPixbuf   *pixbuf,
                                      gint         hot_x,
                                      gint         hot_y);
void gtk_drag_source_set_icon_stock  (GtkWidget   *widget,
                                      const gchar *stock_id,
                                      gint         hot_x,
                                      gint         hot_y);

 - Deprecates gtk_drag_source_set_icon(), gtk_drag_set_default_icon()

 - Fixes a couple of bugs

Regards,
                                        Owen

Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1896
diff -u -r1.1896 ChangeLog
--- ChangeLog	2001/04/13 23:56:17	1.1896
+++ ChangeLog	2001/04/15 19:06:04
@@ -1,3 +1,40 @@
+Sun Apr 15 14:38:41 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/gtkenums.h gtk/gtkiconfactory.c: Add a special size for
+	drag-and-drop GTK_ICON_SIZE_DND (Default to 32x32)
+
+	* gtk/gtkdnd.c (gtk_drag_dest_set_target_list): Fix problem
+	with un'reffing wrong list reported by Jeff Franks.
+
+	* gtk/gtkdnd.[ch] (_gtk_drag_{source,}dest_handle_event): _prefix.
+
+	* gtk/gtkdnd.c (gtk_drag_set_icon_default): Use GTK_STOCK_DND
+	for the default icon. Remove inline XPM.
+
+	* gtk/gtkstock.h gtk/gtkiconfactory.c:
+	Add GTK_STOCK_DND GTK_STOCK_DND_MULTIPLE (Currently, stock_new
+	is used for GTK_STOCK_DND, but it is a bit too small.)
+
+	* gtk/stock-icons/stock_dnd_multiple.png
+	gtk/stock-icons/Makefile.am: New stock icon moved from gnome-libs.
+
+	* gtk/gtkdnd.c (gtk_drag_source_event_cb): Only return
+	TRUE when starting a drag. In other cases, we are
+	just observing. (#52995)
+
+	* gtk/gtkdnd.[ch] (gtk_drag_set_icon_{stock,pixbuf}): Add 
+	function to set the icon for a drag from a GdkPixbuf
+	or stock ID.
+
+	* gtk/gtkdnd.[ch] (gtk_drag_source_set_icon_{stock,pixbuf}): 
+	Likewise, for drag sources.
+
+	* gtk/gtkdnd.h (gtk_drag_source_set_icon): Deprecate.
+	It's missing arguments and is painful to use anyways.
+
+	* gtk/gtkdnd.h: Deprecate gtk_drag_set_default_icon.
+	(Now should be done using the stock system.)
+
 2001-04-14  Hans Breuer  <hans breuer org>
 
 	* gdk/gdk.def :
Index: docs/reference/ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/ChangeLog,v
retrieving revision 1.62
diff -u -r1.62 ChangeLog
--- docs/reference/ChangeLog	2001/04/13 14:48:24	1.62
+++ docs/reference/ChangeLog	2001/04/15 19:06:07
@@ -1,3 +1,8 @@
+Sun Apr 15 15:04:12 2001  Owen Taylor  <otaylor redhat com>
+
+	* gtk/tmpl/gtkdnd.sgml: Move some of the function docs to the
+	C files.
+
 Fri Apr 13 10:41:10 2001  Owen Taylor  <otaylor redhat com>
 
 	* */Makefile.am: Add $(top_builddir) to includes as necessary,
Index: docs/reference/gtk/gtk-sections.txt
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/gtk-sections.txt,v
retrieving revision 1.16
diff -u -r1.16 gtk-sections.txt
--- docs/reference/gtk/gtk-sections.txt	2001/03/23 22:21:05	1.16
+++ docs/reference/gtk/gtk-sections.txt	2001/04/15 19:06:13
@@ -3496,9 +3496,6 @@
 gtk_drag_source_set
 gtk_drag_source_set_icon
 gtk_drag_source_unset
-<SUBSECTION Internals>
-gtk_drag_source_handle_event
-gtk_drag_dest_handle_event
 </SECTION>
 
 
Index: docs/reference/gtk/tmpl/gtkdnd.sgml
===================================================================
RCS file: /cvs/gnome/gtk+/docs/reference/gtk/tmpl/gtkdnd.sgml,v
retrieving revision 1.2
diff -u -r1.2 gtkdnd.sgml
--- docs/reference/gtk/tmpl/gtkdnd.sgml	1999/08/17 13:09:59	1.2
+++ docs/reference/gtk/tmpl/gtkdnd.sgml	2001/04/15 19:06:14
@@ -236,58 +236,33 @@
 
 <!-- ##### FUNCTION gtk_drag_set_icon_widget ##### -->
 <para>
-Change the icon for a widget to a given widget. GTK+
-will not destroy the icon, so if you don't want
-it to persist, you should connect to the "drag_end" 
-signal and destroy it yourself.
 </para>
 
- context: the context for a drag. (This must be called 
-          with a  context for the source side of a drag)
- widget: A toplevel window to use as an icon.
- hot_x: The X offset within @widget of the hotspot.
- hot_y: The Y offset within @widget of the hotspot.
+ context:
+ widget:
+ hot_x: 
+ hot_y: 
 
 
 <!-- ##### FUNCTION gtk_drag_set_icon_pixmap ##### -->
 <para>
-Sets a given pixmap as the icon for a given drag.
-GTK+ retains a reference count for the arguments, and 
-will release them when they are no longer needed.
 </para>
 
- context: the context for a drag. (This must be called 
-          with a  context for the source side of a drag)
- colormap: the colormap of the icon
- pixmap: the image data for the icon
- mask: the transparency mask for an image.
- hot_x: The X offset within @widget of the hotspot.
- hot_y: The Y offset within @widget of the hotspot.
+ context: 
+ colormap: 
+ pixmap:
+ mask:
+ hot_x:
+ hot_y:
 
 
 <!-- ##### FUNCTION gtk_drag_set_icon_default ##### -->
 <para>
-Set the icon for a particular drag to the default
-icon.
 </para>
 
- context: the context for a drag. (This must be called 
-          with a  context for the source side of a drag)
+ context: 
 
 
-<!-- ##### FUNCTION gtk_drag_set_default_icon ##### -->
-<para>
-Change the default drag icon. GTK+ retains a reference count for the
-arguments, and will release them when they are no longer needed.
-</para>
-
- colormap: the colormap of the icon
- pixmap: the image data for the icon
- mask: the transparency mask for an image.
- hot_x: The X offset within @widget of the hotspot.
- hot_y: The Y offset within @widget of the hotspot.
-
-
 <!-- ##### FUNCTION gtk_drag_source_set ##### -->
 <para>
 Sets up a widget so that GTK+ will start a drag
@@ -305,16 +280,12 @@
 
 <!-- ##### FUNCTION gtk_drag_source_set_icon ##### -->
 <para>
-Sets the icon that will be used for drags from a 
-particular widget. GTK+ retains a reference count
-for the arguments, and will release them when
-they are no longer needed.
 </para>
 
- widget: a #GtkWidget
- colormap: the colormap of the icon
- pixmap: the image data for the icon
- mask: the transparency mask for an image.
+ widget:
+ colormap:
+ pixmap:
+ mask:
 
 
 <!-- ##### FUNCTION gtk_drag_source_unset ##### -->
Index: gtk/gtkdnd.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdnd.c,v
retrieving revision 1.61
diff -u -r1.61 gtkdnd.c
--- gtk/gtkdnd.c	2001/04/03 18:48:42	1.61
+++ gtk/gtkdnd.c	2001/04/15 19:06:23
@@ -39,9 +39,11 @@
 #include "gdk/gdkkeysyms.h"
 
 #include "gtkdnd.h"
+#include "gtkimage.h"
 #include "gtkinvisible.h"
 #include "gtkmain.h"
 #include "gtksignal.h"
+#include "gtkstock.h"
 #include "gtkwindow.h"
 
 static GSList *drag_widgets = NULL;
@@ -67,9 +69,18 @@
   GdkModifierType    start_button_mask;
   GtkTargetList     *target_list;        /* Targets for drag data */
   GdkDragAction      actions;            /* Possible actions */
+
+  /* Drag icon */
+  GtkImageType icon_type;
+  union
+  {
+    GtkImagePixmapData pixmap;
+    GtkImagePixbufData pixbuf;
+    GtkImageStockData stock;
+  } icon_data;
+
   GdkColormap       *colormap;	         /* Colormap for drag icon */
-  GdkPixmap         *pixmap;             /* Icon for drag data */
-  GdkBitmap         *mask;
+  gint               hot_x, hot_y;
 
   /* Stored button press information to detect drag beginning */
   gint               state;
@@ -349,45 +360,6 @@
 
 static const gint n_drag_cursors = sizeof (drag_cursors) / sizeof (drag_cursors[0]);
 
-/* XPM */
-static const char *drag_default_xpm[] = {
-"32 32 3 1",
-" 	c None",
-".	c #000000",
-"+	c #FFFFFF",
-"                                ",
-"                                ",
-"                ..              ",
-"              ..+.              ",
-"             ..++..             ",
-"           ...++++.             ",
-"         ...++++++..            ",
-"       ...+++++++++.            ",
-"     ...+++++++++++..           ",
-"    ..+.++++++++++++..          ",
-"     .++.++++++++++++..         ",
-"     .+++.++++++++++++..        ",
-"     .++++.++++++++++++.        ",
-"     .+++.+++++++++++++..       ",
-"     .++.+++++++++++++++..      ",
-"     .+.+++++++++++++++++..     ",
-"     ..+++++++++++++++++++..    ",
-"     ..++++++++++++++++++++.    ",
-"     .++++++++++++++++++++..    ",
-"     ..+++++++++++++++++..      ",
-"      .++++++++++++++++..       ",
-"      ..+++++++++++++...        ",
-"       .++++++++++++..          ",
-"       ..+++++++++..            ",
-"        .++++++++..             ",
-"        ..++++++..              ",
-"         .+++++..               ",
-"          .++..                 ",
-"           ...                  ",
-"           ..                   ",
-"                                ",
-"                                "};
-
 /*********************
  * Utility functions *
  *********************/
@@ -983,7 +955,7 @@
     }
 
   if (target_list)
-    gtk_target_list_ref (site->target_list);
+    gtk_target_list_ref (target_list);
   
   if (site->target_list)
     gtk_target_list_unref (site->target_list);
@@ -993,7 +965,7 @@
 
 
 /*************************************************************
- * gtk_drag_dest_handle_event:
+ * _gtk_drag_dest_handle_event:
  *     Called from widget event handling code on Drag events
  *     for destinations.
  *
@@ -1004,7 +976,7 @@
  *************************************************************/
 
 void
-gtk_drag_dest_handle_event (GtkWidget *toplevel,
+_gtk_drag_dest_handle_event (GtkWidget *toplevel,
 			    GdkEvent  *event)
 {
   GtkDragDestInfo *info;
@@ -1894,6 +1866,8 @@
   else
     {
       site = g_new0 (GtkDragSourceSite, 1);
+
+      site->icon_type = GTK_IMAGE_EMPTY;
       
       gtk_signal_connect (GTK_OBJECT (widget), "button_press_event",
 			  GTK_SIGNAL_FUNC (gtk_drag_source_event_cb),
@@ -1942,16 +1916,48 @@
     }
 }
 
-/*************************************************************
- * gtk_drag_source_set_icon:
- *     Set an icon for drags from this source.
- *   arguments:
- *     colormap: Colormap for this icon
- *     pixmap:
- *     mask
- *   results:
- *************************************************************/
+static void
+gtk_drag_source_unset_icon (GtkDragSourceSite *site)
+{
+  switch (site->icon_type)
+    {
+    case GTK_IMAGE_EMPTY:
+      break;
+    case GTK_IMAGE_PIXMAP:
+      if (site->icon_data.pixmap.pixmap)
+	gdk_pixmap_unref (site->icon_data.pixmap.pixmap);
+      if (site->icon_data.pixmap.mask)
+	gdk_pixmap_unref (site->icon_data.pixmap.mask);
+      break;
+    case GTK_IMAGE_PIXBUF:
+      g_object_unref (G_OBJECT (site->icon_data.pixbuf.pixbuf));
+      break;
+    case GTK_IMAGE_STOCK:
+      g_free (G_OBJECT (site->icon_data.stock.stock_id));
+      break;
+    default:
+      g_assert_not_reached();
+      break;
+    }
+  site->icon_type = GTK_IMAGE_EMPTY;
+  
+  if (site->colormap)
+    gdk_colormap_unref (site->colormap);
+  site->colormap = NULL;
+}
 
+/**
+ * gtk_drag_source_set_icon:
+ * @widget: a #GtkWidget
+ * @colormap: the colormap of the icon
+ * @pixmap: the image data for the icon
+ * @mask: the transparency mask for an image.
+ * 
+ * Sets the icon that will be used for drags from a particular widget
+ * from a pixmap/mask. GTK+ retains a reference count for the
+ * arguments, and will release them when they are no longer needed.
+ * Use gtk_drag_source_set_icon_pixbuf() instead.
+ **/
 void 
 gtk_drag_source_set_icon (GtkWidget     *widget,
 			  GdkColormap   *colormap,
@@ -1961,41 +1967,96 @@
   GtkDragSourceSite *site;
 
   g_return_if_fail (widget != NULL);
+  g_return_if_fail (GDK_IS_COLORMAP (colormap));
+  g_return_if_fail (GDK_IS_PIXMAP (pixmap));
+  g_return_if_fail (!mask || GDK_IS_PIXMAP (mask));
 
   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);
+  gdk_colormap_ref (colormap);
+  gdk_pixmap_ref (pixmap);
+  if (mask)
+    gdk_pixmap_ref (mask);
 
+  gtk_drag_source_unset_icon (site);
+
+  site->icon_type = GTK_IMAGE_PIXMAP;
+  
+  site->icon_data.pixmap.pixmap = pixmap;
+  site->icon_data.pixmap.mask = mask;
   site->colormap = colormap;
-  if (colormap)
-    gdk_colormap_ref (colormap);
+  site->hot_x = -2;
+  site->hot_y = -2;
+}
 
-  site->pixmap = pixmap;
-  if (pixmap)
-    gdk_pixmap_ref (pixmap);
+/**
+ * gtk_drag_source_set_icon_pixbuf:
+ * @widget: a #GtkWidget
+ * @pixbuf: the #GdkPixbuf for the drag icon
+ * @hot_x: the X offset within @pixbuf of the hotspot.
+ * @hot_y: the Y offset within @pixbuf of the hotspot.
+ * 
+ * Sets the icon that will be used for drags from a particular widget
+ * from a #GdkPixbuf. GTK+ retains a reference count @pixbuf.
+ * and will release it when they are no longer needed.
+ **/
+void 
+gtk_drag_source_set_icon_pixbuf (GtkWidget   *widget,
+				 GdkPixbuf   *pixbuf,
+				 gint         hot_x,
+				 gint         hot_y)
+{
+  GtkDragSourceSite *site;
 
-  site->mask = mask;
-  if (mask)
-    gdk_pixmap_ref (mask);
+  g_return_if_fail (widget != NULL);
+  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+
+  site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-site-data");
+  g_return_if_fail (site != NULL);
+  
+  gdk_pixbuf_ref (pixbuf);
+
+  gtk_drag_source_unset_icon (site);
+
+  site->icon_type = GTK_IMAGE_PIXBUF;
+  site->icon_data.pixbuf.pixbuf = pixbuf;
+  site->hot_x = hot_x;
+  site->hot_y = hot_y;
 }
 
-/*************************************************************
- * gtk_drag_set_icon_window:
- *     Set a widget as the icon for a drag.
- *   arguments:
- *     context:
- *     widget:
- *     hot_x:    Hot spot
- *     hot_y:
- *   results:
- *************************************************************/
+/**
+ * gtk_drag_source_set_icon_stock:
+ * @widget: a #GtkWidget
+ * @stock: the ID of the stock icon to use..
+ * @size: size at which to render the stock icon
+ * @hot_x: the X offset within @pixbuf of the hotspot.
+ * @hot_y: the Y offset within @pixbuf of the hotspot.
+ *
+ * Sets the icon that will be used for drags from a particular to
+ * a stock icon. 
+ **/
+void 
+gtk_drag_source_set_icon_stock (GtkWidget   *widget,
+				const gchar *stock_id,
+				gint         hot_x,
+				gint         hot_y)
+{
+  GtkDragSourceSite *site;
+
+  g_return_if_fail (widget != NULL);
+  g_return_if_fail (stock_id != NULL);
+
+  site = gtk_object_get_data (GTK_OBJECT (widget), "gtk-site-data");
+  g_return_if_fail (site != NULL);
+  
+  gtk_drag_source_unset_icon (site);
 
+  site->icon_data.stock.stock_id = g_strdup (stock_id);
+  site->hot_x = hot_x;
+  site->hot_y = hot_y;
+}
+
 static void 
 gtk_drag_set_icon_window (GdkDragContext *context,
 			  GtkWidget      *widget,
@@ -2028,17 +2089,19 @@
   info->destroy_icon = destroy_on_release;
 }
 
-/*************************************************************
+/**
  * gtk_drag_set_icon_widget:
- *     Set a widget as the icon for a drag.
- *   arguments:
- *     context:
- *     widget:
- *     hot_x:    Hot spot
- *     hot_y:
- *   results:
- *************************************************************/
-
+ * @context: the context for a drag. (This must be called 
+          with a  context for the source side of a drag)
+ * @widget: a toplevel window to use as an icon.
+ * @hot_x: the X offset within @widget of the hotspot.
+ * @hot_y: the Y offset within @widget of the hotspot.
+ * 
+ * Changes the icon for a widget to a given widget. GTK+
+ * will not destroy the icon, so if you don't want
+ * it to persist, you should connect to the "drag_end" 
+ * signal and destroy it yourself.
+ **/
 void 
 gtk_drag_set_icon_widget (GdkDragContext    *context,
 			  GtkWidget         *widget,
@@ -2051,20 +2114,124 @@
   gtk_drag_set_icon_window (context, widget, hot_x, hot_y, FALSE);
 }
 
-/*************************************************************
- * 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:
- *************************************************************/
+static void
+set_icon_stock_pixbuf (GdkDragContext    *context,
+		       const gchar       *stock_id,
+		       GdkPixbuf         *pixbuf,
+		       gint               hot_x,
+		       gint               hot_y)
+{
+  GtkWidget *window;
+  gint width, height;
+  GdkPixmap *pixmap;
+  GdkPixmap *mask;
+  
+  g_return_if_fail (context != NULL);
+  g_return_if_fail (pixbuf != NULL || stock_id != NULL);
+  g_return_if_fail (pixbuf == NULL || stock_id == NULL);
+
+  gtk_widget_push_colormap (gdk_rgb_get_colormap ());
+  window = gtk_window_new (GTK_WINDOW_POPUP);
+  gtk_widget_pop_colormap ();
+
+  gtk_widget_set_events (window, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
+  gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
+  
+  if (stock_id)
+    {
+      pixbuf = gtk_widget_render_icon (window, stock_id,
+				       GTK_ICON_SIZE_DND, NULL);
 
+      if (!pixbuf)
+	{
+	  g_warning ("Cannot load drag icon from stock_id %s", stock_id);
+	  gtk_widget_destroy (window);
+	  return;
+	}
+
+    }
+  
+  width = gdk_pixbuf_get_width (pixbuf);
+  height = gdk_pixbuf_get_width (pixbuf);
+
+  gtk_widget_set_usize (window,
+			gdk_pixbuf_get_width (pixbuf),
+			gdk_pixbuf_get_height (pixbuf));
+  gtk_widget_realize (window);
+
+  gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap, &mask, 128);
+  
+  gdk_window_set_back_pixmap (window->window, pixmap, FALSE);
+  
+  if (mask)
+    gtk_widget_shape_combine_mask (window, mask, 0, 0);
+
+  g_object_unref (G_OBJECT (pixmap));
+  g_object_unref (G_OBJECT (mask));
+
+  gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
+}
+
+/**
+ * gtk_drag_set_icon_pixbuf:
+ * @context: the context for a drag. (This must be called 
+ *            with a  context for the source side of a drag)
+ * @pixbuf: the #GdkPixbuf to use as the drag icon.
+ * @hot_x: the X offset within @widget of the hotspot.
+ * @hot_y: the Y offset within @widget of the hotspot.
+ * 
+ * Sets @pixbuf as the icon for a given drag.
+ **/
 void 
+gtk_drag_set_icon_pixbuf  (GdkDragContext *context,
+			   GdkPixbuf      *pixbuf,
+			   gint            hot_x,
+			   gint            hot_y)
+{
+  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+  g_return_if_fail (GDK_IS_PIXBUF (pixbuf));
+  
+  set_icon_stock_pixbuf (context, NULL, pixbuf, hot_x, hot_y);
+}
+
+/**
+ * gtk_drag_set_icon_pixbuf:
+ * @context: the context for a drag. (This must be called 
+ *            with a  context for the source side of a drag)
+ * @stock: the ID of the stock icon to use for the drag.
+ * @hot_x: the X offset within the icon of the hotspot.
+ * @hot_y: the Y offset within the icon of the hotspot.
+ * 
+ * Sets the the icon for a given drag from a stock ID.
+ **/
+void 
+gtk_drag_set_icon_stock  (GdkDragContext *context,
+			  const gchar    *stock_id,
+			  gint            hot_x,
+			  gint            hot_y)
+{
+  g_return_if_fail (GDK_IS_DRAG_CONTEXT (context));
+  g_return_if_fail (stock_id != NULL);
+  
+  set_icon_stock_pixbuf (context, stock_id, NULL, hot_x, hot_y);
+}
+
+/**
+ * gtk_drag_set_icon_pixmap:
+ * @context: the context for a drag. (This must be called 
+ *            with a  context for the source side of a drag)
+ * @colormap: the colormap of the icon 
+ * @pixmap: the image data for the icon 
+ * @mask: the transparency mask for the icon
+ * @hot_x: the X offset within @pixmap of the hotspot.
+ * @hot_y: the Y offset within @pixmap of the hotspot.
+ * 
+ * Sets @pixmap as the icon for a given drag. GTK+ retains a
+ * reference count for the arguments, and will release them when
+ * they are no longer needed. In general, gtk_drag_set_icon_pixbuf()
+ * will be more convenient to use.
+ **/
+void 
 gtk_drag_set_icon_pixmap (GdkDragContext    *context,
 			  GdkColormap       *colormap,
 			  GdkPixmap         *pixmap,
@@ -2100,51 +2267,43 @@
   gtk_drag_set_icon_window (context, window, hot_x, hot_y, TRUE);
 }
 
-/*************************************************************
+/**
  * gtk_drag_set_icon_default:
- *     Set the icon for a drag to the default icon.
- *   arguments:
- *     context:
- *   results:
- *************************************************************/
-
+ * @context: the context for a drag. (This must be called 
+             with a  context for the source side of a drag)
+ * 
+ * Sets the icon for a particular drag to the default
+ * icon.
+ **/
 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, (gchar **)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_icon_stock (context, GTK_STOCK_DND, -2, -2);
+  else
+    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:
- *************************************************************/
-
+ * @colormap: the colormap of the icon
+ * @pixmap: the image data for the icon
+ * @mask: the transparency mask for an image.
+ * @hot_x: The X offset within @widget of the hotspot.
+ * @hot_y: The Y offset within @widget of the hotspot.
+ * 
+ * Changes the default drag icon. GTK+ retains a reference count for the
+ * arguments, and will release them when they are no longer needed.
+ * This function is obsolete. The default icon should now be changed
+ * via the stock system by changing the stock pixbuf for GTK_STOCK_DND.
+ **/
 void 
 gtk_drag_set_default_icon (GdkColormap   *colormap,
 			   GdkPixmap     *pixmap,
@@ -2178,7 +2337,7 @@
 
 
 /*************************************************************
- * gtk_drag_source_handle_event:
+ * _gtk_drag_source_handle_event:
  *     Called from widget event handling code on Drag events
  *     for drag sources.
  *
@@ -2189,8 +2348,8 @@
  *************************************************************/
 
 void
-gtk_drag_source_handle_event (GtkWidget *widget,
-			      GdkEvent  *event)
+_gtk_drag_source_handle_event (GtkWidget *widget,
+			       GdkEvent  *event)
 {
   GtkDragSourceInfo *info;
   GdkDragContext *context;
@@ -2477,16 +2636,12 @@
 	  site->state |= (GDK_BUTTON1_MASK << (event->button.button - 1));
 	  site->x = event->button.x;
 	  site->y = event->button.y;
-	  retval = TRUE;
 	}
       break;
       
     case GDK_BUTTON_RELEASE:
       if ((GDK_BUTTON1_MASK << (event->button.button - 1)) & site->start_button_mask)
-	{
-	  site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1));
-	  retval = TRUE;
-	}
+	site->state &= ~(GDK_BUTTON1_MASK << (event->button.button - 1));
       break;
       
     case GDK_MOTION_NOTIFY:
@@ -2518,13 +2673,35 @@
 
 	      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);
+		  switch (site->icon_type)
+		    {
+		    case GTK_IMAGE_EMPTY:
+		      gtk_drag_set_icon_default (context);
+		      break;
+		    case GTK_IMAGE_PIXMAP:
+		      gtk_drag_set_icon_pixmap (context,
+						site->colormap,
+						site->icon_data.pixmap.pixmap,
+						site->icon_data.pixmap.mask,
+						site->hot_x,
+						site->hot_y);
+		      break;
+		    case GTK_IMAGE_PIXBUF:
+		      gtk_drag_set_icon_pixbuf (context,
+						site->icon_data.pixbuf.pixbuf,
+						site->hot_x,
+						site->hot_y);
+		      break;
+		    case GTK_IMAGE_STOCK:
+		      gtk_drag_set_icon_stock (context,
+					       site->icon_data.stock.stock_id,
+					       site->hot_x,
+					       site->hot_y);
+		      break;
+		    default:
+		      g_assert_not_reached();
+		      break;
+		    }
 		}
 
 	      retval = TRUE;
@@ -2547,12 +2724,7 @@
   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);
-  
+  gtk_drag_source_unset_icon (site);
   g_free (site);
 }
 
Index: gtk/gtkdnd.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkdnd.h,v
retrieving revision 1.10
diff -u -r1.10 gtkdnd.h
--- gtk/gtkdnd.h	2001/01/19 22:39:18	1.10
+++ gtk/gtkdnd.h	2001/04/15 19:06:24
@@ -96,10 +96,14 @@
 
 void gtk_drag_source_unset (GtkWidget        *widget);
 
-void gtk_drag_source_set_icon (GtkWidget     *widget,
-			       GdkColormap   *colormap,
-			       GdkPixmap     *pixmap,
-			       GdkBitmap     *mask);
+void gtk_drag_source_set_icon_pixbuf (GtkWidget   *widget,
+				      GdkPixbuf   *pixbuf,
+				      gint         hot_x,
+				      gint         hot_y);
+void gtk_drag_source_set_icon_stock  (GtkWidget   *widget,
+				      const gchar *stock_id,
+				      gint         hot_x,
+				      gint         hot_y);
 
 /* There probably should be functions for setting the targets
  * as a GtkTargetList
@@ -113,27 +117,27 @@
 
 /* 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_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_pixbuf (GdkDragContext *context,
+			       GdkPixbuf      *pixbuf,
+			       gint            hot_x,
+			       gint            hot_y);
+void gtk_drag_set_icon_stock  (GdkDragContext *context,
+			       const gchar    *stock_id,
+			       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);
-
-
 gboolean gtk_drag_check_threshold (GtkWidget *widget,
 				   gint       start_x,
 				   gint       start_y,
@@ -141,10 +145,22 @@
 				   gint       current_y);
 
 /* Internal functions */
-void gtk_drag_source_handle_event (GtkWidget *widget,
-				   GdkEvent  *event);
-void gtk_drag_dest_handle_event (GtkWidget *toplevel,
-				 GdkEvent  *event);
+void _gtk_drag_source_handle_event (GtkWidget *widget,
+				    GdkEvent  *event);
+void _gtk_drag_dest_handle_event (GtkWidget *toplevel,
+				  GdkEvent  *event);
+
+#ifndef GTK_DISABLE_DEPRECATED
+void gtk_drag_set_default_icon (GdkColormap   *colormap,
+				GdkPixmap     *pixmap,
+				GdkBitmap     *mask,
+			        gint           hot_x,
+			        gint           hot_y);
+void gtk_drag_source_set_icon        (GtkWidget   *widget,
+				      GdkColormap *colormap,
+				      GdkPixmap   *pixmap,
+				      GdkBitmap   *mask);
+#endif /* !GTK_DISABLE_DEPRECATED */
 
 #ifdef __cplusplus
 }
Index: gtk/gtkenums.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkenums.h,v
retrieving revision 1.36
diff -u -r1.36 gtkenums.h
--- gtk/gtkenums.h	2001/03/12 18:46:52	1.36
+++ gtk/gtkenums.h	2001/04/15 19:06:25
@@ -100,6 +100,7 @@
   GTK_ICON_SIZE_SMALL_TOOLBAR,
   GTK_ICON_SIZE_LARGE_TOOLBAR,
   GTK_ICON_SIZE_BUTTON,
+  GTK_ICON_SIZE_DND,
   GTK_ICON_SIZE_DIALOG
 } GtkIconSize;
 
Index: gtk/gtkiconfactory.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkiconfactory.c,v
retrieving revision 1.11
diff -u -r1.11 gtkiconfactory.c
--- gtk/gtkiconfactory.c	2001/03/19 22:40:35	1.11
+++ gtk/gtkiconfactory.c	2001/04/15 19:06:29
@@ -410,6 +410,9 @@
   add_unsized (factory, stock_open, GTK_STOCK_OPEN);
   add_unsized (factory, stock_save, GTK_STOCK_SAVE);
 
+  add_sized (factory, stock_new, GTK_ICON_SIZE_DND, GTK_STOCK_DND);
+  add_sized (factory, stock_dnd_multiple, GTK_ICON_SIZE_DND, GTK_STOCK_DND_MULTIPLE);
+
   add_unsized (factory, MISSING_IMAGE_INLINE, GTK_STOCK_MISSING_IMAGE);
 }
 
@@ -444,7 +447,7 @@
 {
   if (icon_sizes == NULL)
     {
-#define NUM_BUILTIN_SIZES 6
+#define NUM_BUILTIN_SIZES 7
       gint i;
 
       icon_aliases = g_hash_table_new (g_str_hash, g_str_equal);
@@ -483,6 +486,11 @@
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].name = "gtk-large-toolbar";
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].width = 24;
       icon_sizes[GTK_ICON_SIZE_LARGE_TOOLBAR].height = 24;
+
+      icon_sizes[GTK_ICON_SIZE_DND].size = GTK_ICON_SIZE_DND;
+      icon_sizes[GTK_ICON_SIZE_DND].name = "gtk-dnd";
+      icon_sizes[GTK_ICON_SIZE_DND].width = 32;
+      icon_sizes[GTK_ICON_SIZE_DND].height = 32;
 
       icon_sizes[GTK_ICON_SIZE_DIALOG].size = GTK_ICON_SIZE_DIALOG;
       icon_sizes[GTK_ICON_SIZE_DIALOG].name = "gtk-dialog";
Index: gtk/gtkmain.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkmain.c,v
retrieving revision 1.157
diff -u -r1.157 gtkmain.c
--- gtk/gtkmain.c	2001/04/03 04:29:57	1.157
+++ gtk/gtkmain.c	2001/04/15 19:06:34
@@ -940,13 +940,13 @@
       
     case GDK_DRAG_STATUS:
     case GDK_DROP_FINISHED:
-      gtk_drag_source_handle_event (event_widget, event);
+      _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);
+      _gtk_drag_dest_handle_event (event_widget, event);
       break;
     }
   
Index: gtk/gtkstock.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkstock.h,v
retrieving revision 1.5
diff -u -r1.5 gtkstock.h
--- gtk/gtkstock.h	2001/03/07 21:10:44	1.5
+++ gtk/gtkstock.h	2001/04/15 19:06:35
@@ -64,6 +64,9 @@
 /* Stock IDs */
 #define GTK_STOCK_MISSING_IMAGE    "gtk-missing-image"
 
+#define GTK_STOCK_DND              "gtk-dnd"
+#define GTK_STOCK_DND_MULTIPLE     "gtk-dnd-multiple"
+
 #define GTK_STOCK_DIALOG_INFO      "gtk-dialog-info"
 #define GTK_STOCK_DIALOG_WARNING   "gtk-dialog-warning"
 #define GTK_STOCK_DIALOG_ERROR     "gtk-dialog-error"
Index: gtk/stock-icons/Makefile.am
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/stock-icons/Makefile.am,v
retrieving revision 1.5
diff -u -r1.5 Makefile.am
--- gtk/stock-icons/Makefile.am	2001/04/04 07:20:26	1.5
+++ gtk/stock-icons/Makefile.am	2001/04/15 19:06:35
@@ -11,6 +11,7 @@
 	stock_button_ok.png	\
 	stock_button_yes.png	\
 	stock_close.png		\
+	stock_dnd_multiple.png	\
 	stock_exit.png		\
 	stock_help.png		\
 	stock_new.png		\
@@ -30,6 +31,7 @@
 		stock_button_ok     	$(srcdir)/stock_button_ok.png  	\
 		stock_button_yes	$(srcdir)/stock_button_yes.png  	\
 		stock_close 		$(srcdir)/stock_close.png  	\
+		stock_dnd_multiple      $(srcdir)/stock_dnd_multiple.png \
 		stock_exit		$(srcdir)/stock_exit.png 		\
 		stock_help		$(srcdir)/stock_help.png  	\
 		stock_new		$(srcdir)/stock_new.png		\


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]