Re: [gtk-list] Re: DND problem



Owen Taylor wrote:

> Can you reproduce this with the testdnd application in GTK+?
> (That is, dragging from Netscape to the "trash can")
> 
> I can't seem to do that here.

Test application works fine, but I think that's because top level window
is not a drop target. Here is the stripped down version which exibits
described behaviour. To save bandwidth, XPMs are not included. Take
them from testdnd.c (or anywhere you like) and create files Trash_open.xpm
and Trash_close.xpm. Perhaps it has something to do with shaped pixmap
window, so I left that in.


BTW, are GTK functions async-signal-safe? After a drop I'd like to change
icon to indicate the drop was successful, and then after a small amount
of time to change it back to inactive default. I don't know if GTK provides
callouts (or however is that called in toolkits), so in case it doesn't
I'd set a SIGALRM handler. I don't know if I can change pixmap from
handler or I have to set a variable and do it outside of signal handler.



#include "gtk/gtk.h"

GdkPixmap *hole, *hand_reach;
GdkBitmap *hole_mask, *hand_reach_mask;
GtkWidget *pixmapw;
volatile int gotcha;

enum {
   TARGET_STRING
};

GtkTargetEntry target[] = {
   { "STRING",	   0, TARGET_STRING },
   { "text/plain", 0, TARGET_STRING }
};

void mydrop(GtkWidget *w, GdkDragContext *context, gint x, gint y,
            GtkSelectionData *data, guint info, guint time)
{
   char *url;

   g_print("Drop\n");
   if((data->length < 0) || (data->format != 8))
      gtk_drag_finish(context, FALSE, FALSE, time); 
   url = (char *)data->data;
   g_print("%s\n", url);
   gtk_drag_finish(context, TRUE, FALSE, time);
}

gboolean at_site(GtkWidget *w, GdkDragContext *c, gint x, gint y, guint t)
{
   g_print("x = %d, y = %d\n", x, y);
   if(!gotcha)
   {
      gotcha = 1;
      gtk_widget_reset_shapes(w);
      gtk_pixmap_set(GTK_PIXMAP(pixmapw), hand_reach, hand_reach_mask);
      gtk_widget_shape_combine_mask(w, hand_reach_mask, 0, 0);
      g_print("In\n");
   }
   return TRUE;
}

void leaving_site(GtkWidget *w, GdkDragContext *c, guint t)
{
   gotcha = 0;
   gtk_widget_reset_shapes(w);
   gtk_pixmap_set(GTK_PIXMAP(pixmapw), hole, hole_mask);
   gtk_widget_shape_combine_mask(w, hole_mask, 0, 0);
   g_print("Out\n");
}


main(int argc, char **argv)
{

   GtkWidget *window;

   gtk_init(&argc, &argv);

   window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
   gtk_widget_realize(window);
   hole = gdk_pixmap_create_from_xpm(window->window, &hole_mask, NULL,
				     "Trash_close.xpm");
   hand_reach = gdk_pixmap_create_from_xpm(window->window, &hand_reach_mask,
	 				   NULL, "Trash_open.xpm");

   pixmapw = gtk_pixmap_new(hole, hole_mask);
   gtk_container_add(GTK_CONTAINER(window), pixmapw);
   gtk_widget_shape_combine_mask(window, hole_mask, 0, 0);

   gtk_signal_connect(GTK_OBJECT(window), "drag_data_received",
		      GTK_SIGNAL_FUNC(mydrop), NULL);
   gtk_drag_dest_set(window, GTK_DEST_DEFAULT_ALL, target, 1,
		     GDK_ACTION_COPY);
   gtk_signal_connect(GTK_OBJECT(window), "drag_leave",
	 	      GTK_SIGNAL_FUNC(leaving_site), NULL);
   gtk_signal_connect(GTK_OBJECT(window), "drag_motion",
	 	      GTK_SIGNAL_FUNC(at_site), NULL);

   gtk_widget_show_all(window);

   gtk_main();
}

-- 
 .-.   .-.    Life is a sexually transmitted disease.
(_  \ /  _)
     |        dave@srce.hr
     |        dave@fly.cc.fer.hr



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