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