]> Pileus Git - ~andy/gtk/blob - gtk/testdnd.c
Add a drag_data_received handler for the label.
[~andy/gtk] / gtk / 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\" in trashcan\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 label_drag_data_received  (GtkWidget          *widget,
363                             GdkDragContext     *context,
364                             gint                x,
365                             gint                y,
366                             GtkSelectionData   *data,
367                             guint               info,
368                             guint               time)
369 {
370   if ((data->length >= 0) && (data->format == 8))
371     {
372       g_print ("Received \"%s\" in label\n", (gchar *)data->data);
373       gtk_drag_finish (context, TRUE, FALSE, time);
374       return;
375     }
376   
377   gtk_drag_finish (context, FALSE, FALSE, time);
378 }
379
380 void  
381 source_drag_data_get  (GtkWidget          *widget,
382                        GdkDragContext     *context,
383                        GtkSelectionData   *selection_data,
384                        guint               info,
385                        guint               time,
386                        gpointer            data)
387 {
388   if (info == TARGET_ROOTWIN)
389     g_print ("I was dropped on the rootwin\n");
390   else
391     gtk_selection_data_set (selection_data,
392                             selection_data->target,
393                             8, "I'm Data!", 9);
394 }
395   
396 /* The following is a rather elaborate example demonstrating/testing
397  * changing of the window heirarchy during a drag - in this case,
398  * via a "spring-loaded" popup window.
399  */
400 static GtkWidget *popup_window = NULL;
401
402 static gboolean popped_up = FALSE;
403 static gboolean in_popup = FALSE;
404 static guint popdown_timer = 0;
405 static guint popup_timer = 0;
406
407 gint
408 popdown_cb (gpointer data)
409 {
410   popdown_timer = 0;
411
412   gtk_widget_hide (popup_window);
413   popped_up = FALSE;
414
415   return FALSE;
416 }
417
418 gboolean
419 popup_motion       (GtkWidget          *widget,
420                     GdkDragContext     *context,
421                     gint                x,
422                     gint                y,
423                     guint               time)
424 {
425   if (!in_popup)
426     {
427       in_popup = TRUE;
428       if (popdown_timer)
429         {
430           g_print ("removed popdown\n");
431           gtk_timeout_remove (popdown_timer);
432           popdown_timer = 0;
433         }
434     }
435
436   return TRUE;
437 }
438
439 void  
440 popup_leave        (GtkWidget          *widget,
441                     GdkDragContext     *context,
442                     guint               time)
443 {
444   if (in_popup)
445     {
446       in_popup = FALSE;
447       if (!popdown_timer)
448         {
449           g_print ("added popdown\n");
450           popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
451         }
452     }
453 }
454
455 gint
456 popup_cb (gpointer data)
457 {
458   if (!popped_up)
459     {
460       if (!popup_window)
461         {
462           GtkWidget *button;
463           GtkWidget *table;
464           int i, j;
465           
466           popup_window = gtk_window_new (GTK_WINDOW_POPUP);
467           gtk_window_set_position (GTK_WINDOW (popup_window), GTK_WIN_POS_MOUSE);
468
469           table = gtk_table_new (3,3, FALSE);
470
471           for (i=0; i<3; i++)
472             for (j=0; j<3; j++)
473               {
474                 char buffer[128];
475                 g_snprintf(buffer, sizeof(buffer), "%d,%d", i, j);
476                 button = gtk_button_new_with_label (buffer);
477                 gtk_table_attach (GTK_TABLE (table), button, i, i+1, j, j+1,
478                                   GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
479                                   0, 0);
480
481                 gtk_drag_dest_set (button,
482                                    GTK_DEST_DEFAULT_ALL,
483                                    target_table, n_targets - 1, /* no rootwin */
484                                    GDK_ACTION_COPY | GDK_ACTION_MOVE);
485                 gtk_signal_connect (GTK_OBJECT (button), "drag_motion",
486                                     GTK_SIGNAL_FUNC (popup_motion), NULL);
487                 gtk_signal_connect (GTK_OBJECT (button), "drag_leave",
488                                     GTK_SIGNAL_FUNC (popup_leave), NULL);
489               }
490
491           gtk_widget_show_all (table);
492           gtk_container_add (GTK_CONTAINER (popup_window), table);
493
494         }
495       gtk_widget_show (popup_window);
496       popped_up = TRUE;
497     }
498
499   popdown_timer = gtk_timeout_add (500, popdown_cb, NULL);
500   g_print ("added popdown\n");
501
502   popup_timer = FALSE;
503
504   return FALSE;
505 }
506
507 gboolean
508 popsite_motion     (GtkWidget          *widget,
509                     GdkDragContext     *context,
510                     gint                x,
511                     gint                y,
512                     guint               time)
513 {
514   if (!popup_timer)
515     popup_timer = gtk_timeout_add (500, popup_cb, NULL);
516
517   return TRUE;
518 }
519
520 void  
521 popsite_leave      (GtkWidget          *widget,
522                     GdkDragContext     *context,
523                     guint               time)
524 {
525   if (popup_timer)
526     {
527       gtk_timeout_remove (popup_timer);
528       popup_timer = 0;
529     }
530 }
531
532 void  
533 source_drag_data_delete  (GtkWidget          *widget,
534                           GdkDragContext     *context,
535                           gpointer            data)
536 {
537   g_print ("Delete the data!\n");
538 }
539   
540 int 
541 main (int argc, char **argv)
542 {
543   GtkWidget *window;
544   GtkWidget *table;
545   GtkWidget *label;
546   GtkWidget *pixmap;
547   GtkWidget *button;
548   GdkPixmap *drag_icon;
549   GdkPixmap *drag_mask;
550
551   gtk_init (&argc, &argv); 
552
553   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
554   gtk_signal_connect (GTK_OBJECT(window), "destroy",
555                       GTK_SIGNAL_FUNC (gtk_main_quit), NULL);
556
557   
558   table = gtk_table_new (2, 2, FALSE);
559   gtk_container_add (GTK_CONTAINER (window), table);
560
561   drag_icon = gdk_pixmap_colormap_create_from_xpm_d (NULL,
562                                                      gtk_widget_get_colormap (window),
563                                                      &drag_mask,
564                                                      NULL, drag_icon_xpm);
565
566   trashcan_open = gdk_pixmap_colormap_create_from_xpm_d (NULL,
567                                                          gtk_widget_get_colormap (window),
568                                                          &trashcan_open_mask,
569                                                          NULL, trashcan_open_xpm);
570   trashcan_closed = gdk_pixmap_colormap_create_from_xpm_d (NULL,
571                                                            gtk_widget_get_colormap (window),
572                                                            &trashcan_closed_mask,
573                                                            NULL, trashcan_closed_xpm);
574   
575   label = gtk_label_new ("Drop Here\n");
576
577   gtk_drag_dest_set (label,
578                      GTK_DEST_DEFAULT_ALL,
579                      target_table, n_targets - 1, /* no rootwin */
580                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
581
582   gtk_signal_connect( GTK_OBJECT(label), "drag_data_received",
583                       GTK_SIGNAL_FUNC( label_drag_data_received), NULL);
584
585   gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
586                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
587                     0, 0);
588
589   label = gtk_label_new ("Popup\n");
590
591   gtk_drag_dest_set (label,
592                      GTK_DEST_DEFAULT_ALL,
593                      target_table, n_targets - 1, /* no rootwin */
594                      GDK_ACTION_COPY | GDK_ACTION_MOVE);
595
596   gtk_table_attach (GTK_TABLE (table), label, 1, 2, 1, 2,
597                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
598                     0, 0);
599
600   gtk_signal_connect (GTK_OBJECT (label), "drag_motion",
601                       GTK_SIGNAL_FUNC (popsite_motion), NULL);
602   gtk_signal_connect (GTK_OBJECT (label), "drag_leave",
603                       GTK_SIGNAL_FUNC (popsite_leave), NULL);
604   
605   pixmap = gtk_pixmap_new (trashcan_closed, trashcan_closed_mask);
606   gtk_drag_dest_set (pixmap, 0, NULL, 0, 0);
607   gtk_table_attach (GTK_TABLE (table), pixmap, 1, 2, 0, 1,
608                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
609                     0, 0);
610
611   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_leave",
612                       GTK_SIGNAL_FUNC (target_drag_leave), NULL);
613
614   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_motion",
615                       GTK_SIGNAL_FUNC (target_drag_motion), NULL);
616
617   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_drop",
618                       GTK_SIGNAL_FUNC (target_drag_drop), NULL);
619
620   gtk_signal_connect (GTK_OBJECT (pixmap), "drag_data_received",
621                       GTK_SIGNAL_FUNC (target_drag_data_received), NULL);
622
623   /* Drag site */
624
625   button = gtk_button_new_with_label ("Drag Here\n");
626
627   gtk_drag_source_set (button, GDK_BUTTON1_MASK | GDK_BUTTON3_MASK,
628                        target_table, n_targets, 
629                        GDK_ACTION_COPY | GDK_ACTION_MOVE);
630   gtk_drag_source_set_icon (button, 
631                             gtk_widget_get_colormap (window),
632                             drag_icon, drag_mask);
633
634   gdk_pixmap_unref (drag_icon);
635   gdk_pixmap_unref (drag_mask);
636
637   gtk_table_attach (GTK_TABLE (table), button, 0, 1, 1, 2,
638                     GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL,
639                     0, 0);
640
641   gtk_signal_connect (GTK_OBJECT (button), "drag_data_get",
642                       GTK_SIGNAL_FUNC (source_drag_data_get), NULL);
643   gtk_signal_connect (GTK_OBJECT (button), "drag_data_delete",
644                       GTK_SIGNAL_FUNC (source_drag_data_delete), NULL);
645
646   gtk_widget_show_all (window);
647
648   gtk_main ();
649
650   return 0;
651 }