]> Pileus Git - ~andy/gtk/blob - tests/testdnd.c
Fix many sparse warnings.
[~andy/gtk] / tests / testdnd.c
1 #include <config.h>
2 #include "gtk/gtk.h"
3
4 /* Target side drag signals */
5
6 /* XPM */
7 static char * drag_icon_xpm[] = {
8 "36 48 9 1",
9 "       c None",
10 ".      c #020204",
11 "+      c #8F8F90",
12 "@      c #D3D3D2",
13 "#      c #AEAEAC",
14 "$      c #ECECEC",
15 "%      c #A2A2A4",
16 "&      c #FEFEFC",
17 "*      c #BEBEBC",
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
67 /* XPM */
68 static char * trashcan_closed_xpm[] = {
69 "64 80 17 1",
70 "       c None",
71 ".      c #030304",
72 "+      c #5A5A5C",
73 "@      c #323231",
74 "#      c #888888",
75 "$      c #1E1E1F",
76 "%      c #767677",
77 "&      c #494949",
78 "*      c #9E9E9C",
79 "=      c #111111",
80 "-      c #3C3C3D",
81 ";      c #6B6B6B",
82 ">      c #949494",
83 ",      c #282828",
84 "'      c #808080",
85 ")      c #545454",
86 "!      c #AEAEAC",
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
168 /* XPM */
169 static char * trashcan_open_xpm[] = {
170 "64 80 17 1",
171 "       c None",
172 ".      c #030304",
173 "+      c #5A5A5C",
174 "@      c #323231",
175 "#      c #888888",
176 "$      c #1E1E1F",
177 "%      c #767677",
178 "&      c #494949",
179 "*      c #9E9E9C",
180 "=      c #111111",
181 "-      c #3C3C3D",
182 ";      c #6B6B6B",
183 ">      c #949494",
184 ",      c #282828",
185 "'      c #808080",
186 ")      c #545454",
187 "!      c #AEAEAC",
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
269 GdkPixmap *trashcan_open;
270 GdkPixmap *trashcan_open_mask;
271 GdkPixmap *trashcan_closed;
272 GdkPixmap *trashcan_closed_mask;
273
274 gboolean have_drag;
275
276 enum {
277   TARGET_STRING,
278   TARGET_ROOTWIN
279 };
280
281 static GtkTargetEntry target_table[] = {
282   { "STRING",     0, TARGET_STRING },
283   { "text/plain", 0, TARGET_STRING },
284   { "application/x-rootwindow-drop", 0, TARGET_ROOTWIN }
285 };
286
287 static guint n_targets = sizeof(target_table) / sizeof(target_table[0]);
288
289 void  
290 target_drag_leave          (GtkWidget          *widget,
291                             GdkDragContext     *context,
292                             guint               time)
293 {
294   g_print("leave\n");
295   have_drag = FALSE;
296   gtk_image_set_from_pixmap (GTK_IMAGE (widget),
297                              trashcan_closed, trashcan_closed_mask);
298 }
299
300 gboolean
301 target_drag_motion         (GtkWidget          *widget,
302                             GdkDragContext     *context,
303                             gint                x,
304                             gint                y,
305                             guint               time)
306 {
307   GtkWidget *source_widget;
308   GList *tmp_list;
309
310   if (!have_drag)
311     {
312       have_drag = TRUE;
313       gtk_image_set_from_pixmap (GTK_IMAGE (widget),
314                                  trashcan_open, trashcan_open_mask);
315     }
316
317   source_widget = gtk_drag_get_source_widget (context);
318   g_print ("motion, source %s\n", source_widget ?
319            GTK_OBJECT_TYPE_NAME (source_widget) :
320            "NULL");
321
322   tmp_list = context->targets;
323   while (tmp_list)
324     {
325       char *name = gdk_atom_name (GDK_POINTER_TO_ATOM (tmp_list->data));
326       g_print ("%s\n", name);
327       g_free (name);
328       
329       tmp_list = tmp_list->next;
330     }
331
332   gdk_drag_status (context, context->suggested_action, time);
333   return TRUE;
334 }
335
336 gboolean
337 target_drag_drop           (GtkWidget          *widget,
338                             GdkDragContext     *context,
339                             gint                x,
340                             gint                y,
341                             guint               time)
342 {
343   g_print("drop\n");
344   have_drag = FALSE;
345
346   gtk_image_set_from_pixmap (GTK_IMAGE (widget),
347                              trashcan_closed, trashcan_closed_mask);
348
349   if (context->targets)
350     {
351       gtk_drag_get_data (widget, context, 
352                          GDK_POINTER_TO_ATOM (context->targets->data), 
353                          time);
354       return TRUE;
355     }
356   
357   return FALSE;
358 }
359
360 void  
361 target_drag_data_received  (GtkWidget          *widget,
362                             GdkDragContext     *context,
363                             gint                x,
364                             gint                y,
365                             GtkSelectionData   *data,
366                             guint               info,
367                             guint               time)
368 {
369   if ((data->length >= 0) && (data->format == 8))
370     {
371       g_print ("Received \"%s\" in trashcan\n", (gchar *)data->data);
372       gtk_drag_finish (context, TRUE, FALSE, time);
373       return;
374     }
375   
376   gtk_drag_finish (context, FALSE, FALSE, time);
377 }
378   
379 void  
380 label_drag_data_received  (GtkWidget          *widget,
381                             GdkDragContext     *context,
382                             gint                x,
383                             gint                y,
384                             GtkSelectionData   *data,
385                             guint               info,
386                             guint               time)
387 {
388   if ((data->length >= 0) && (data->format == 8))
389     {
390       g_print ("Received \"%s\" in label\n", (gchar *)data->data);
391       gtk_drag_finish (context, TRUE, FALSE, time);
392       return;
393     }
394   
395   gtk_drag_finish (context, FALSE, FALSE, time);
396 }
397
398 void  
399 source_drag_data_get  (GtkWidget          *widget,
400                        GdkDragContext     *context,
401                        GtkSelectionData   *selection_data,
402                        guint               info,
403                        guint               time,
404                        gpointer            data)
405 {
406   if (info == TARGET_ROOTWIN)
407     g_print ("I was dropped on the rootwin\n");
408   else
409     gtk_selection_data_set (selection_data,
410                             selection_data->target,
411                             8, "I'm Data!", 9);
412 }
413   
414 /* The following is a rather elaborate example demonstrating/testing
415  * changing of the window heirarchy during a drag - in this case,
416  * via a "spring-loaded" popup window.
417  */
418 static GtkWidget *popup_window = NULL;
419
420 static gboolean popped_up = FALSE;
421 static gboolean in_popup = FALSE;
422 static guint popdown_timer = 0;
423 static guint popup_timer = 0;
424
425 gint
426 popdown_cb (gpointer data)
427 {
428   popdown_timer = 0;
429
430   gtk_widget_hide (popup_window);
431   popped_up = FALSE;
432
433   return FALSE;
434 }
435
436 gboolean
437 popup_motion       (GtkWidget          *widget,
438                     GdkDragContext     *context,
439                     gint                x,
440                     gint                y,
441                     guint               time)
442 {
443   if (!in_popup)
444     {
445       in_popup = TRUE;
446       if (popdown_timer)
447         {
448           g_print ("removed popdown\n");
449           g_source_remove (popdown_timer);
450           popdown_timer = 0;
451         }
452     }
453
454   return TRUE;
455 }
456
457 void  
458 popup_leave        (GtkWidget          *widget,
459                     GdkDragContext     *context,
460                     guint               time)
461 {
462   if (in_popup)
463     {
464       in_popup = FALSE;
465       if (!popdown_timer)
466         {
467           g_print ("added popdown\n");
468           popdown_timer = g_timeout_add (500, popdown_cb, NULL);
469         }
470     }
471 }
472
473 gint
474 popup_cb (gpointer data)
475 {
476   if (!popped_up)
477     {
478       if (!popup_window)
479         {
480           GtkWidget *button;
481           GtkWidget *table;
482           int i, j;
483           
484           popup_window = gtk_window_new (GTK_WINDOW_POPUP);
485           gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
486
487           table = gtk_table_new (3,3, FALSE);
488
489           for (i=0; i<3; i++)
490             for (j=0; j<3; j++)
491               {
492                 char buffer[128];
493                 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
494                 button = gtk_button_new_with_label (buffer);
495                 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
496                                   GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
497                                   0, 0);
498
499                 gtk_drag_dest_set (button,
500                                    GTK_DEST_DEFAULT_ALL,
501                                    target_table, n_targets - 1, /* no rootwin */
502                                    GDK_ACTION_COPY | GDK_ACTION_MOVE);
503                 g_signal_connect (button, "drag_motion",
504                                   G_CALLBACK (popup_motion), NULL);
505                 g_signal_connect (button, "drag_leave",
506                                   G_CALLBACK (popup_leave), NULL);
507               }
508
509           gtk_widget_show_all (table);
510           gtk_container_add (GTK_CONTAINER (popup_window), table);
511
512         }
513       gtk_widget_show (popup_window);
514       popped_up = TRUE;
515     }
516
517   popdown_timer = g_timeout_add (500, popdown_cb, NULL);
518   g_print ("added popdown\n");
519
520   popup_timer = FALSE;
521
522   return FALSE;
523 }
524
525 gboolean
526 popsite_motion     (GtkWidget          *widget,
527                     GdkDragContext     *context,
528                     gint                x,
529                     gint                y,
530                     guint               time)
531 {
532   if (!popup_timer)
533     popup_timer = g_timeout_add (500, popup_cb, NULL);
534
535   return TRUE;
536 }
537
538 void  
539 popsite_leave      (GtkWidget          *widget,
540                     GdkDragContext     *context,
541                     guint               time)
542 {
543   if (popup_timer)
544     {
545       g_source_remove (popup_timer);
546       popup_timer = 0;
547     }
548 }
549
550 void  
551 source_drag_data_delete  (GtkWidget          *widget,
552                           GdkDragContext     *context,
553                           gpointer            data)
554 {
555   g_print ("Delete the data!\n");
556 }
557   
558 void
559 test_init (void)
560 {
561   if (g_file_test ("../gdk-pixbuf/libpixbufloader-pnm.la",
562                    G_FILE_TEST_EXISTS))
563     {
564       g_setenv ("GDK_PIXBUF_MODULE_FILE", "../gdk-pixbuf/gdk-pixbuf.loaders", TRUE);
565       g_setenv ("GTK_IM_MODULE_FILE", "../modules/input/gtk.immodules", TRUE);
566     }
567 }
568
569 int 
570 main (int argc, char **argv)
571 {
572   GtkWidget *window;
573   GtkWidget *table;
574   GtkWidget *label;
575   GtkWidget *pixmap;
576   GtkWidget *button;
577   GdkPixmap *drag_icon;
578   GdkPixmap *drag_mask;
579
580   test_init ();
581   
582   gtk_init (&argc, &argv); 
583
584   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
585   g_signal_connect (window, "destroy",
586                     G_CALLBACK (gtk_main_quit), NULL);
587
588   
589   table = gtk_table_new (2, 2, FALSE);
590   gtk_container_add (GTK_CONTAINER (window), table);
591
592   drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL,
593                                                      gtk_widget_get_colormap (window),
594                                                      &drag_mask,
595                                                      NULL, drag_icon_xpm);
596
597   trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL,
598                                                          gtk_widget_get_colormap (window),
599                                                          &trashcan_open_mask,
600                                                          NULL, trashcan_open_xpm);
601   trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL,
602                                                            gtk_widget_get_colormap (window),
603                                                            &trashcan_closed_mask,
604                                                            NULL, trashcan_closed_xpm);
605   
606   label = gtk_label_new ("Drop Here\n");
607
608   gtk_drag_dest_set (label,
609                      GTK_DEST_DEFAULT_ALL,
610                      target_table, n_targets - 1, /* no rootwin */
611                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
612
613   g_signal_connect (label, "drag_data_received",
614                     G_CALLBACK( label_drag_data_received), NULL);
615
616   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
617                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
618                     0, 0);
619
620   label = gtk_label_new ("Popup\n");
621
622   gtk_drag_dest_set (label,
623                      GTK_DEST_DEFAULT_ALL,
624                      target_table, n_targets - 1, /* no rootwin */
625                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
626
627   gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
628                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
629                     0, 0);
630
631   g_signal_connect (label, "drag_motion",
632                     G_CALLBACK (popsite_motion), NULL);
633   g_signal_connect (label, "drag_leave",
634                     G_CALLBACK (popsite_leave), NULL);
635   
636   pixmap = gtk_image_new_from_pixmap (trashcan_closed, trashcan_closed_mask);
637   gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
638   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
639                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
640                     0, 0);
641
642   g_signal_connect (pixmap, "drag_leave",
643                     G_CALLBACK (target_drag_leave), NULL);
644
645   g_signal_connect (pixmap, "drag_motion",
646                     G_CALLBACK (target_drag_motion), NULL);
647
648   g_signal_connect (pixmap, "drag_drop",
649                     G_CALLBACK (target_drag_drop), NULL);
650
651   g_signal_connect (pixmap, "drag_data_received",
652                     G_CALLBACK (target_drag_data_received), NULL);
653
654   /* Drag site */
655
656   button = gtk_button_new_with_label ("Drag Here\n");
657
658   gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
659                        target_table, n_targets, 
660                        GDK_ACTION_COPY | GDK_ACTION_MOVE);
661   gtk_drag_source_set_icon (button, 
662                             gtk_widget_get_colormap (window),
663                             drag_icon, drag_mask);
664
665   g_object_unref (drag_icon);
666   g_object_unref (drag_mask);
667
668   gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
669                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
670                     0, 0);
671
672   g_signal_connect (button, "drag_data_get",
673                     G_CALLBACK (source_drag_data_get), NULL);
674   g_signal_connect (button, "drag_data_delete",
675                     G_CALLBACK (source_drag_data_delete), NULL);
676
677   gtk_widget_show_all (window);
678
679   gtk_main ();
680
681   return 0;
682 }