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