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