]> Pileus Git - ~andy/gtk/blob - tests/testdnd.c
Test for window == NULL in a number of cases.
[~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   GList *tmp_list;
307
308   if (!have_drag)
309     {
310       have_drag = TRUE;
311       gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_open, trashcan_open_mask);
312     }
313
314   source_widget = gtk_drag_get_source_widget (context);
315   g_print ("motion, source %s\n", source_widget ?
316            GTK_OBJECT_TYPE_NAME (source_widget) :
317            "NULL");
318
319   tmp_list = context->targets;
320   while (tmp_list)
321     {
322       char *name = gdk_atom_name (GPOINTER_TO_UINT (tmp_list->data));
323       g_print ("%s\n", name);
324       g_free (name);
325       
326       tmp_list = tmp_list->next;
327     }
328
329   gdk_drag_status (context, context->suggested_action, time);
330   return TRUE;
331 }
332
333 gboolean
334 target_drag_drop           (GtkWidget          *widget,
335                             GdkDragContext     *context,
336                             gint                x,
337                             gint                y,
338                             guint               time)
339 {
340   g_print("drop\n");
341   have_drag = FALSE;
342
343   gtk_pixmap_set (GTK_PIXMAP (widget), trashcan_closed, trashcan_closed_mask);
344
345   if (context->targets)
346     {
347       gtk_drag_get_data (widget, context, 
348                          GPOINTER_TO_INT (context->targets->data), 
349                          time);
350       return TRUE;
351     }
352   
353   return FALSE;
354 }
355
356 void  
357 target_drag_data_received  (GtkWidget          *widget,
358                             GdkDragContext     *context,
359                             gint                x,
360                             gint                y,
361                             GtkSelectionData   *data,
362                             guint               info,
363                             guint               time)
364 {
365   if ((data->length >= 0) && (data->format == 8))
366     {
367       g_print ("Received \"%s\" in trashcan\n", (gchar *)data->data);
368       gtk_drag_finish (context, TRUE, FALSE, time);
369       return;
370     }
371   
372   gtk_drag_finish (context, FALSE, FALSE, time);
373 }
374   
375 void  
376 label_drag_data_received  (GtkWidget          *widget,
377                             GdkDragContext     *context,
378                             gint                x,
379                             gint                y,
380                             GtkSelectionData   *data,
381                             guint               info,
382                             guint               time)
383 {
384   if ((data->length >= 0) && (data->format == 8))
385     {
386       g_print ("Received \"%s\" in label\n", (gchar *)data->data);
387       gtk_drag_finish (context, TRUE, FALSE, time);
388       return;
389     }
390   
391   gtk_drag_finish (context, FALSE, FALSE, time);
392 }
393
394 void  
395 source_drag_data_get  (GtkWidget          *widget,
396                        GdkDragContext     *context,
397                        GtkSelectionData   *selection_data,
398                        guint               info,
399                        guint               time,
400                        gpointer            data)
401 {
402   if (info == TARGET_ROOTWIN)
403     g_print ("I was dropped on the rootwin\n");
404   else
405     gtk_selection_data_set (selection_data,
406                             selection_data->target,
407                             8, "I'm Data!", 9);
408 }
409   
410 /* The following is a rather elaborate example demonstrating/testing
411  * changing of the window heirarchy during a drag - in this case,
412  * via a "spring-loaded" popup window.
413  */
414 static GtkWidget *popup_window = NULL;
415
416 static gboolean popped_up = FALSE;
417 static gboolean in_popup = FALSE;
418 static guint popdown_timer = 0;
419 static guint popup_timer = 0;
420
421 gint
422 popdown_cb (gpointer data)
423 {
424   popdown_timer = 0;
425
426   gtk_widget_hide (popup_window);
427   popped_up = FALSE;
428
429   return FALSE;
430 }
431
432 gboolean
433 popup_motion       (GtkWidget          *widget,
434                     GdkDragContext     *context,
435                     gint                x,
436                     gint                y,
437                     guint               time)
438 {
439   if (!in_popup)
440     {
441       in_popup = TRUE;
442       if (popdown_timer)
443         {
444           g_print ("removed popdown\n");
445           gtk_timeout_remove (popdown_timer);
446           popdown_timer = 0;
447         }
448     }
449
450   return TRUE;
451 }
452
453 void  
454 popup_leave        (GtkWidget          *widget,
455                     GdkDragContext     *context,
456                     guint               time)
457 {
458   if (in_popup)
459     {
460       in_popup = FALSE;
461       if (!popdown_timer)
462         {
463           g_print ("added popdown\n");
464           popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
465         }
466     }
467 }
468
469 gint
470 popup_cb (gpointer data)
471 {
472   if (!popped_up)
473     {
474       if (!popup_window)
475         {
476           GtkWidget *button;
477           GtkWidget *table;
478           int i, j;
479           
480           popup_window = gtk_window_new (GTK_WINDOW_POPUP);
481           gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
482
483           table = gtk_table_new (3,3, FALSE);
484
485           for (i=0; i<3; i++)
486             for (j=0; j<3; j++)
487               {
488                 char buffer[128];
489                 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
490                 button = gtk_button_new_with_label (buffer);
491                 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
492                                   GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
493                                   0, 0);
494
495                 gtk_drag_dest_set (button,
496                                    GTK_DEST_DEFAULT_ALL,
497                                    target_table, n_targets - 1, /* no rootwin */
498                                    GDK_ACTION_COPY | GDK_ACTION_MOVE);
499                 gtk_signal_connect (GTK_OBJECT (button), "drag_motion",
500                                     GTK_SIGNAL_FUNC (popup_motion), NULL);
501                 gtk_signal_connect (GTK_OBJECT (button), "drag_leave",
502                                     GTK_SIGNAL_FUNC (popup_leave), NULL);
503               }
504
505           gtk_widget_show_all (table);
506           gtk_container_add (GTK_CONTAINER (popup_window), table);
507
508         }
509       gtk_widget_show (popup_window);
510       popped_up = TRUE;
511     }
512
513   popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
514   g_print ("added popdown\n");
515
516   popup_timer = FALSE;
517
518   return FALSE;
519 }
520
521 gboolean
522 popsite_motion     (GtkWidget          *widget,
523                     GdkDragContext     *context,
524                     gint                x,
525                     gint                y,
526                     guint               time)
527 {
528   if (!popup_timer)
529     popup_timer = gtk_timeout_add (500, popup_cb, NULL);
530
531   return TRUE;
532 }
533
534 void  
535 popsite_leave      (GtkWidget          *widget,
536                     GdkDragContext     *context,
537                     guint               time)
538 {
539   if (popup_timer)
540     {
541       gtk_timeout_remove (popup_timer);
542       popup_timer = 0;
543     }
544 }
545
546 void  
547 source_drag_data_delete  (GtkWidget          *widget,
548                           GdkDragContext     *context,
549                           gpointer            data)
550 {
551   g_print ("Delete the data!\n");
552 }
553   
554 void
555 test_init ()
556 {
557   if (g_file_test ("../gdk-pixbuf/.libs/libpixbufloader-pnm.so",
558                    G_FILE_TEST_EXISTS))
559     {
560       putenv ("GDK_PIXBUF_MODULEDIR=../gdk-pixbuf/.libs");
561       putenv ("GTK_IM_MODULE_FILE=./gtk.immodules");
562     }
563 }
564
565 int 
566 main (int argc, char **argv)
567 {
568   GtkWidget *window;
569   GtkWidget *table;
570   GtkWidget *label;
571   GtkWidget *pixmap;
572   GtkWidget *button;
573   GdkPixmap *drag_icon;
574   GdkPixmap *drag_mask;
575
576   test_init ();
577   
578   gtk_init (&argc, &argv); 
579
580   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
581   gtk_signal_connect (GTK_OBJECT(window), "destroy",
582                       GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
583
584   
585   table = gtk_table_new (2, 2, FALSE);
586   gtk_container_add (GTK_CONTAINER (window), table);
587
588   drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL,
589                                                      gtk_widget_get_colormap (window),
590                                                      &drag_mask,
591                                                      NULL, drag_icon_xpm);
592
593   trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL,
594                                                          gtk_widget_get_colormap (window),
595                                                          &trashcan_open_mask,
596                                                          NULL, trashcan_open_xpm);
597   trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL,
598                                                            gtk_widget_get_colormap (window),
599                                                            &trashcan_closed_mask,
600                                                            NULL, trashcan_closed_xpm);
601   
602   label = gtk_label_new ("Drop Here\n");
603
604   gtk_drag_dest_set (label,
605                      GTK_DEST_DEFAULT_ALL,
606                      target_table, n_targets - 1, /* no rootwin */
607                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
608
609   gtk_signal_connect( GTK_OBJECT(label), "drag_data_received",
610                       GTK_SIGNAL_FUNC( label_drag_data_received), NULL);
611
612   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
613                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
614                     0, 0);
615
616   label = gtk_label_new ("Popup\n");
617
618   gtk_drag_dest_set (label,
619                      GTK_DEST_DEFAULT_ALL,
620                      target_table, n_targets - 1, /* no rootwin */
621                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
622
623   gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
624                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
625                     0, 0);
626
627   gtk_signal_connect (GTK_OBJECT (label), "drag_motion",
628                       GTK_SIGNAL_FUNC (popsite_motion), NULL);
629   gtk_signal_connect (GTK_OBJECT (label), "drag_leave",
630                       GTK_SIGNAL_FUNC (popsite_leave), NULL);
631   
632   pixmap = gtk_pixmap_new (trashcan_closed, trashcan_closed_mask);
633   gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
634   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
635                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
636                     0, 0);
637
638   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave",
639                       GTK_SIGNAL_FUNC (target_drag_leave), NULL);
640
641   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion",
642                       GTK_SIGNAL_FUNC (target_drag_motion), NULL);
643
644   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop",
645                       GTK_SIGNAL_FUNC (target_drag_drop), NULL);
646
647   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received",
648                       GTK_SIGNAL_FUNC (target_drag_data_received), NULL);
649
650   /* Drag site */
651
652   button = gtk_button_new_with_label ("Drag Here\n");
653
654   gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
655                        target_table, n_targets, 
656                        GDK_ACTION_COPY | GDK_ACTION_MOVE);
657   gtk_drag_source_set_icon (button, 
658                             gtk_widget_get_colormap (window),
659                             drag_icon, drag_mask);
660
661   gdk_pixmap_unref (drag_icon);
662   gdk_pixmap_unref (drag_mask);
663
664   gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
665                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
666                     0, 0);
667
668   gtk_signal_connect (GTK_OBJECT (button), "drag_data_get",
669                       GTK_SIGNAL_FUNC (source_drag_data_get), NULL);
670   gtk_signal_connect (GTK_OBJECT (button), "drag_data_delete",
671                       GTK_SIGNAL_FUNC (source_drag_data_delete), NULL);
672
673   gtk_widget_show_all (window);
674
675   gtk_main ();
676
677   return 0;
678 }