]> Pileus Git - ~andy/gtk/blob - tests/testdnd.c
use g_snprintf, eliminate need for string.h include string.h, for strlen
[~andy/gtk] / tests / testdnd.c
1 #include "gtk/gtk.h"
2
3 /* Target side drag signals */
4
5 /* XPM */
6 static char * drag_icon_xpm[] = {
7 "36 48 9 1",
8 "       c None",
9 ".      c #020204",
10 "+      c #8F8F90",
11 "@      c #D3D3D2",
12 "#      c #AEAEAC",
13 "$      c #ECECEC",
14 "%      c #A2A2A4",
15 "&      c #FEFEFC",
16 "*      c #BEBEBC",
17 "               .....................",
18 "              ..&&&&&&&&&&&&&&&&&&&.",
19 "             ...&&&&&&&&&&&&&&&&&&&.",
20 "            ..&.&&&&&&&&&&&&&&&&&&&.",
21 "           ..&&.&&&&&&&&&&&&&&&&&&&.",
22 "          ..&&&.&&&&&&&&&&&&&&&&&&&.",
23 "         ..&&&&.&&&&&&&&&&&&&&&&&&&.",
24 "        ..&&&&&.&&&@&&&&&&&&&&&&&&&.",
25 "       ..&&&&&&.*$%$+$&&&&&&&&&&&&&.",
26 "      ..&&&&&&&.%$%$+&&&&&&&&&&&&&&.",
27 "     ..&&&&&&&&.#&#@$&&&&&&&&&&&&&&.",
28 "    ..&&&&&&&&&.#$**#$&&&&&&&&&&&&&.",
29 "   ..&&&&&&&&&&.&@%&%$&&&&&&&&&&&&&.",
30 "  ..&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
31 " ..&&&&&&&&&&&&.&&&&&&&&&&&&&&&&&&&.",
32 "................&$@&&&@&&&&&&&&&&&&.",
33 ".&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&&&&&.",
34 ".&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&&&.",
35 ".&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&&&.",
36 ".&&&&&&@#@@$&*@&@#@#$**#$&&&&&&&&&&.",
37 ".&&&&&&&&&&&&&&&&&&&@%&%$&&&&&&&&&&.",
38 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
39 ".&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&&&.",
40 ".&&&&&&&&&+&$+&$&@&$@&&$@&&&&&&&&&&.",
41 ".&&&&&&&&&+&&#@%#+@#@*$%&+$&&&&&&&&.",
42 ".&&&&&&&&&+&&#@#@&&@*%$%$+&&&&&&&&&.",
43 ".&&&&&&&&&+&$%&#@&#@@#&#@$&&&&&&&&&.",
44 ".&&&&&&&&@#@@$&*@&@#@#$#*#$&&&&&&&&.",
45 ".&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&&&.",
46 ".&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&&&&&.",
47 ".&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&&&&&.",
48 ".&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&&&&&.",
49 ".&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&&&&&.",
50 ".&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&&&&&.",
51 ".&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&&&&&.",
52 ".&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&&&&&.",
53 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
54 ".&&&&&&&&&&&&&&$#@@$&&&&&&&&&&&&&&&.",
55 ".&&&&&&&&&&&&&&&+&$%&$$@&$@&&$@&&&&.",
56 ".&&&&&&&&&&&&&&&+&&#@%#+@#@*$%$+$&&.",
57 ".&&&&&&&&&&&&&&&+&&#@#@&&@*#$%$+&&&.",
58 ".&&&&&&&&&&&&&&&+&$+&*@&#@@#&#@$&&&.",
59 ".&&&&&&&&&&&&&&$%@@&&*@&@#@#$#*#&&&.",
60 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&$%&%$&&.",
61 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
62 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
63 ".&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&.",
64 "...................................."};
65
66 /* XPM */
67 static char * trashcan_closed_xpm[] = {
68 "64 80 17 1",
69 "       c None",
70 ".      c #030304",
71 "+      c #5A5A5C",
72 "@      c #323231",
73 "#      c #888888",
74 "$      c #1E1E1F",
75 "%      c #767677",
76 "&      c #494949",
77 "*      c #9E9E9C",
78 "=      c #111111",
79 "-      c #3C3C3D",
80 ";      c #6B6B6B",
81 ">      c #949494",
82 ",      c #282828",
83 "'      c #808080",
84 ")      c #545454",
85 "!      c #AEAEAC",
86 "                                                                ",
87 "                                                                ",
88 "                                                                ",
89 "                                                                ",
90 "                                                                ",
91 "                                                                ",
92 "                                                                ",
93 "                                                                ",
94 "                                                                ",
95 "                                                                ",
96 "                                                                ",
97 "                                                                ",
98 "                                                                ",
99 "                                                                ",
100 "                                                                ",
101 "                                                                ",
102 "                                                                ",
103 "                                                                ",
104 "                                                                ",
105 "                                                                ",
106 "                                                                ",
107 "                                                                ",
108 "                       ==......=$$...===                        ",
109 "                 ..$------)+++++++++++++@$$...                  ",
110 "             ..=@@-------&+++++++++++++++++++-....              ",
111 "          =.$$@@@-&&)++++)-,$$$$=@@&+++++++++++++,..$           ",
112 "         .$$$$@@&+++++++&$$$@@@@-&,$,-++++++++++;;;&..          ",
113 "        $$$$,@--&++++++&$$)++++++++-,$&++++++;%%'%%;;$@         ",
114 "       .-@@-@-&++++++++-@++++++++++++,-++++++;''%;;;%*-$        ",
115 "       +------++++++++++++++++++++++++++++++;;%%%;;##*!.        ",
116 "        =+----+++++++++++++++++++++++;;;;;;;;;;;;%'>>).         ",
117 "         .=)&+++++++++++++++++;;;;;;;;;;;;;;%''>>#>#@.          ",
118 "          =..=&++++++++++++;;;;;;;;;;;;;%###>>###+%==           ",
119 "           .&....=-+++++%;;####''''''''''##'%%%)..#.            ",
120 "           .+-++@....=,+%#####'%%%%%%%%%;@$-@-@*++!.            ",
121 "           .+-++-+++-&-@$$=$=......$,,,@;&)+!++!++!.            ",
122 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
123 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
124 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
125 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
126 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
127 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
128 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
129 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
130 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
131 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
132 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
133 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
134 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
135 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
136 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
137 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
138 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
139 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
140 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
141 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
142 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
143 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
144 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
145 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
146 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
147 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
148 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
149 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
150 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
151 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
152 "           =+-++-+++-+++++++++!++++!++++!+++!++!+++=            ",
153 "            $.++-+++-+++++++++!++++!++++!+++!++!+.$             ",
154 "              =.++++++++++++++!++++!++++!+++!++.=               ",
155 "                 $..+++++++++++++++!++++++...$                  ",
156 "                      $$=.............=$$                       ",
157 "                                                                ",
158 "                                                                ",
159 "                                                                ",
160 "                                                                ",
161 "                                                                ",
162 "                                                                ",
163 "                                                                ",
164 "                                                                ",
165 "                                                                "};
166
167 /* XPM */
168 static char * trashcan_open_xpm[] = {
169 "64 80 17 1",
170 "       c None",
171 ".      c #030304",
172 "+      c #5A5A5C",
173 "@      c #323231",
174 "#      c #888888",
175 "$      c #1E1E1F",
176 "%      c #767677",
177 "&      c #494949",
178 "*      c #9E9E9C",
179 "=      c #111111",
180 "-      c #3C3C3D",
181 ";      c #6B6B6B",
182 ">      c #949494",
183 ",      c #282828",
184 "'      c #808080",
185 ")      c #545454",
186 "!      c #AEAEAC",
187 "                                                                ",
188 "                                                                ",
189 "                                                                ",
190 "                                                                ",
191 "                                                                ",
192 "                                                                ",
193 "                                      .=.==.,@                  ",
194 "                                   ==.,@-&&&)-=                 ",
195 "                                 .$@,&++;;;%>*-                 ",
196 "                               $,-+)+++%%;;'#+.                 ",
197 "                            =---+++++;%%%;%##@.                 ",
198 "                           @)++++++++;%%%%'#%$                  ",
199 "                         $&++++++++++;%%;%##@=                  ",
200 "                       ,-++++)+++++++;;;'#%)                    ",
201 "                      @+++&&--&)++++;;%'#'-.                    ",
202 "                    ,&++-@@,,,,-)++;;;'>'+,                     ",
203 "                  =-++&@$@&&&&-&+;;;%##%+@                      ",
204 "                =,)+)-,@@&+++++;;;;%##%&@                       ",
205 "               @--&&,,@&)++++++;;;;'#)@                         ",
206 "              ---&)-,@)+++++++;;;%''+,                          ",
207 "            $--&)+&$-+++++++;;;%%'';-                           ",
208 "           .,-&+++-$&++++++;;;%''%&=                            ",
209 "          $,-&)++)-@++++++;;%''%),                              ",
210 "         =,@&)++++&&+++++;%'''+$@&++++++                        ",
211 "        .$@-++++++++++++;'#';,........=$@&++++                  ",
212 "       =$@@&)+++++++++++'##-.................=&++               ",
213 "      .$$@-&)+++++++++;%#+$.....................=)+             ",
214 "      $$,@-)+++++++++;%;@=........................,+            ",
215 "     .$$@@-++++++++)-)@=............................            ",
216 "     $,@---)++++&)@===............................,.            ",
217 "    $-@---&)))-$$=..............................=)!.            ",
218 "     --&-&&,,$=,==...........................=&+++!.            ",
219 "      =,=$..=$+)+++++&@$=.............=$@&+++++!++!.            ",
220 "           .)-++-+++++++++++++++++++++++++++!++!++!.            ",
221 "           .+-++-+++++++++++++++++++++++!+++!++!++!.            ",
222 "           .+-++-+++-+++++++++!+++!!++++!+++!++!++!.            ",
223 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
224 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
225 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
226 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
227 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
228 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
229 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
230 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
231 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
232 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
233 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
234 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
235 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
236 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
237 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
238 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
239 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
240 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
241 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
242 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
243 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
244 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
245 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
246 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
247 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
248 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
249 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
250 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
251 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
252 "           .+-++-+++-+++++++++!++++!++++!+++!++!++!.            ",
253 "           =+-++-+++-+++++++++!++++!++++!+++!++!+++=            ",
254 "            $.++-+++-+++++++++!++++!++++!+++!++!+.$             ",
255 "              =.++++++++++++++!++++!++++!+++!++.=               ",
256 "                 $..+++++++++++++++!++++++...$                  ",
257 "                      $$==...........==$$                       ",
258 "                                                                ",
259 "                                                                ",
260 "                                                                ",
261 "                                                                ",
262 "                                                                ",
263 "                                                                ",
264 "                                                                ",
265 "                                                                ",
266 "                                                                "};
267
268 GdkPixmap *trashcan_open;
269 GdkPixmap *trashcan_open_mask;
270 GdkPixmap *trashcan_closed;
271 GdkPixmap *trashcan_closed_mask;
272
273 gboolean have_drag;
274
275 enum {
276   TARGET_STRING,
277   TARGET_ROOTWIN
278 };
279
280 static GtkTargetEntry target_table[] = {
281   { "STRING",     0, TARGET_STRING },
282   { "text/plain", 0, TARGET_STRING },
283   { "application/x-rootwin-drop", 0, TARGET_ROOTWIN }
284 };
285
286 static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
287
288 void  
289 target_drag_leave          (GtkWidget          *widget,
290                             GdkDragContext     *context,
291                             guint               time)
292 {
293   g_print("leave\n");
294   have_drag = FALSE;
295   gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_closed, trashcan_closed_mask);
296 }
297
298 gboolean
299 target_drag_motion         (GtkWidget          *widget,
300                             GdkDragContext     *context,
301                             gint                x,
302                             gint                y,
303                             guint               time)
304 {
305   GtkWidget *source_widget;
306
307   if (!have_drag)
308     {
309       have_drag = TRUE;
310       gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_open, trashcan_open_mask);
311     }
312
313   source_widget = gtk_drag_get_source_widget (context);
314   g_print("motion, source %s\n", source_widget ?
315             gtk_type_name (GTK_OBJECT (source_widget)->klass->type) :
316             "unknown");
317
318   gdk_drag_status (context, context->suggested_action, time);
319   return TRUE;
320 }
321
322 gboolean
323 target_drag_drop           (GtkWidget          *widget,
324                             GdkDragContext     *context,
325                             gint                x,
326                             gint                y,
327                             guint               time)
328 {
329   g_print("drop\n");
330   have_drag = FALSE;
331
332   gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_closed, trashcan_closed_mask);
333
334   if (context->targets)
335     gtk_drag_get_data (widget, context, 
336                        GPOINTER_TO_INT (context->targets->data), 
337                        time);
338   
339   return FALSE;
340 }
341
342 void  
343 target_drag_data_received  (GtkWidget          *widget,
344                             GdkDragContext     *context,
345                             gint                x,
346                             gint                y,
347                             GtkSelectionData   *data,
348                             guint               info,
349                             guint               time)
350 {
351   if ((data->length >= 0) && (data->format == 8))
352     {
353       g_print ("Received %s\n", (gchar *)data->data);
354       gtk_drag_finish (context, TRUE, FALSE, time);
355       return;
356     }
357   
358   gtk_drag_finish (context, FALSE, FALSE, time);
359 }
360   
361 void  
362 source_drag_data_get  (GtkWidget          *widget,
363                        GdkDragContext     *context,
364                        GtkSelectionData   *selection_data,
365                        guint               info,
366                        guint               time,
367                        gpointer            data)
368 {
369   if (info == TARGET_ROOTWIN)
370     g_print ("I was dropped on the rootwin\n");
371   else
372     gtk_selection_data_set (selection_data,
373                             selection_data->target,
374                             8, "I'm Data!", 9);
375 }
376   
377 /* The following is a rather elaborate example demonstrating/testing
378  * changing of the window heirarchy during a drag - in this case,
379  * via a "spring-loaded" popup window.
380  */
381 static GtkWidget *popup_window = NULL;
382
383 static gboolean popped_up = FALSE;
384 static gboolean in_popup = FALSE;
385 static guint popdown_timer = 0;
386 static guint popup_timer = 0;
387
388 gint
389 popdown_cb (gpointer data)
390 {
391   popdown_timer = 0;
392
393   gtk_widget_hide (popup_window);
394   popped_up = FALSE;
395
396   return FALSE;
397 }
398
399 gboolean
400 popup_motion       (GtkWidget          *widget,
401                     GdkDragContext     *context,
402                     gint                x,
403                     gint                y,
404                     guint               time)
405 {
406   if (!in_popup)
407     {
408       in_popup = TRUE;
409       if (popdown_timer)
410         {
411           g_print ("removed popdown\n");
412           gtk_timeout_remove (popdown_timer);
413           popdown_timer = 0;
414         }
415     }
416
417   return TRUE;
418 }
419
420 void  
421 popup_leave        (GtkWidget          *widget,
422                     GdkDragContext     *context,
423                     guint               time)
424 {
425   if (in_popup)
426     {
427       in_popup = FALSE;
428       if (!popdown_timer)
429         {
430           g_print ("added popdown\n");
431           popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
432         }
433     }
434 }
435
436 gint
437 popup_cb (gpointer data)
438 {
439   if (!popped_up)
440     {
441       if (!popup_window)
442         {
443           GtkWidget *button;
444           GtkWidget *table;
445           int i, j;
446           
447           popup_window = gtk_window_new (GTK_WINDOW_POPUP);
448           gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
449
450           table = gtk_table_new (3,3, FALSE);
451
452           for (i=0; i<3; i++)
453             for (j=0; j<3; j++)
454               {
455                 char buffer[128];
456                 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
457                 button = gtk_button_new_with_label (buffer);
458                 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
459                                   GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
460                                   0, 0);
461
462                 gtk_drag_dest_set (button,
463                                    GTK_DEST_DEFAULT_ALL,
464                                    target_table, n_targets - 1, /* no rootwin */
465                                    GDK_ACTION_COPY | GDK_ACTION_MOVE);
466                 gtk_signal_connect (GTK_OBJECT (button), "drag_motion",
467                                     GTK_SIGNAL_FUNC (popup_motion), NULL);
468                 gtk_signal_connect (GTK_OBJECT (button), "drag_leave",
469                                     GTK_SIGNAL_FUNC (popup_leave), NULL);
470               }
471
472           gtk_widget_show_all (table);
473           gtk_container_add (GTK_CONTAINER (popup_window), table);
474
475         }
476       gtk_widget_show (popup_window);
477       popped_up = TRUE;
478     }
479
480   popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
481   g_print ("added popdown\n");
482
483   popup_timer = FALSE;
484
485   return FALSE;
486 }
487
488 gboolean
489 popsite_motion     (GtkWidget          *widget,
490                     GdkDragContext     *context,
491                     gint                x,
492                     gint                y,
493                     guint               time)
494 {
495   if (!popup_timer)
496     popup_timer = gtk_timeout_add (500, popup_cb, NULL);
497
498   return TRUE;
499 }
500
501 void  
502 popsite_leave      (GtkWidget          *widget,
503                     GdkDragContext     *context,
504                     guint               time)
505 {
506   if (popup_timer)
507     {
508       gtk_timeout_remove (popup_timer);
509       popup_timer = 0;
510     }
511 }
512
513 void  
514 source_drag_data_delete  (GtkWidget          *widget,
515                           GdkDragContext     *context,
516                           gpointer            data)
517 {
518   g_print ("Delete the data!\n");
519 }
520   
521 int 
522 main (int argc, char **argv)
523 {
524   GtkWidget *window;
525   GtkWidget *table;
526   GtkWidget *label;
527   GtkWidget *pixmap;
528   GtkWidget *button;
529   GdkPixmap *drag_icon;
530   GdkPixmap *drag_mask;
531
532   gtk_init (&argc, &argv); 
533
534   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
535   gtk_signal_connect (GTK_OBJECT(window), "destroy",
536                       GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
537
538   
539   table = gtk_table_new (2, 2, FALSE);
540   gtk_container_add (GTK_CONTAINER (window), table);
541
542   drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL,
543                                                      gtk_widget_get_colormap (window),
544                                                      &drag_mask,
545                                                      NULL, drag_icon_xpm);
546
547   trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL,
548                                                          gtk_widget_get_colormap (window),
549                                                          &trashcan_open_mask,
550                                                          NULL, trashcan_open_xpm);
551   trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL,
552                                                            gtk_widget_get_colormap (window),
553                                                            &trashcan_closed_mask,
554                                                            NULL, trashcan_closed_xpm);
555   
556   label = gtk_label_new ("Drop Here\n");
557
558   gtk_drag_dest_set (label,
559                      GTK_DEST_DEFAULT_ALL,
560                      target_table, n_targets - 1, /* no rootwin */
561                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
562
563   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
564                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
565                     0, 0);
566
567   label = gtk_label_new ("Popup\n");
568
569   gtk_drag_dest_set (label,
570                      GTK_DEST_DEFAULT_ALL,
571                      target_table, n_targets - 1, /* no rootwin */
572                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
573
574   gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
575                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
576                     0, 0);
577
578   gtk_signal_connect (GTK_OBJECT (label), "drag_motion",
579                       GTK_SIGNAL_FUNC (popsite_motion), NULL);
580   gtk_signal_connect (GTK_OBJECT (label), "drag_leave",
581                       GTK_SIGNAL_FUNC (popsite_leave), NULL);
582   
583   pixmap = gtk_pixmap_new (trashcan_closed, trashcan_closed_mask);
584   gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
585   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
586                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
587                     0, 0);
588
589   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave",
590                       GTK_SIGNAL_FUNC (target_drag_leave), NULL);
591
592   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion",
593                       GTK_SIGNAL_FUNC (target_drag_motion), NULL);
594
595   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop",
596                       GTK_SIGNAL_FUNC (target_drag_drop), NULL);
597
598   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received",
599                       GTK_SIGNAL_FUNC (target_drag_data_received), NULL);
600
601   /* Drag site */
602
603   button = gtk_button_new_with_label ("Drag Here\n");
604
605   gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
606                        target_table, n_targets, 
607                        GDK_ACTION_COPY | GDK_ACTION_MOVE);
608   gtk_drag_source_set_icon (button, 
609                             gtk_widget_get_colormap (window),
610                             drag_icon, drag_mask);
611
612   gdk_pixmap_unref (drag_icon);
613   gdk_pixmap_unref (drag_mask);
614
615   gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
616                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
617                     0, 0);
618
619   gtk_signal_connect (GTK_OBJECT (button), "drag_data_get",
620                       GTK_SIGNAL_FUNC (source_drag_data_get), NULL);
621   gtk_signal_connect (GTK_OBJECT (button), "drag_data_delete",
622                       GTK_SIGNAL_FUNC (source_drag_data_delete), NULL);
623
624   gtk_widget_show_all (window);
625
626   gtk_main ();
627
628   return 0;
629 }