#include <gtk/gtk.h>

static void
filenames_dropped (GtkWidget        *widget,
		   GdkDragContext   *context,
		   gint              x,
		   gint              y,
		   GtkSelectionData *selection_data,
		   guint             info,
		   guint             time)
{
  if (!selection_data->data)
    return;

  g_message ("dropped %s\n", (char *)selection_data->data);
}

int 
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *vbox;
  GtkWidget *button;
  GtkWidget *entry;
  GtkWidget *textview;
  GtkWidget *colorsel;
  GtkWidget *colorsel2;
  GtkTextBuffer *buffer;
  GtkTextIter iter;
  GtkTextChildAnchor *anchor;
  GtkTargetEntry targets[] = {
    { "text/uri-list", 0, 0},
  };
  gint n_targets = sizeof (targets)/sizeof (targets[0]);

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  vbox = gtk_vbox_new (FALSE, 5);
  textview = gtk_text_view_new ();
  button = gtk_button_new_with_label ("Try here"); 
  entry = gtk_entry_new (); 
  colorsel = gtk_color_selection_new ();
  colorsel2 = gtk_color_selection_new ();
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_container_add (GTK_CONTAINER (vbox), textview);
  gtk_container_add (GTK_CONTAINER (vbox), button);
  gtk_container_add (GTK_CONTAINER (vbox), entry);
  gtk_container_add (GTK_CONTAINER (vbox), colorsel2);
  
  gtk_drag_dest_set (window, GTK_DEST_DEFAULT_ALL, targets, n_targets, GDK_ACTION_COPY);
  g_signal_connect (window, "drag_data_received",
		    G_CALLBACK (filenames_dropped), NULL);

  gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD); 
  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));
  gtk_text_buffer_set_text (buffer, 
			    "some text around a widget to get some background where to drop text and "
			    " see if dropping files/colors/whatever works too. I bet it does. It really "
			    " should.\n"
			    "And if it doesn't if will totally destroy the bug and make it work as "
			    "good as it never has before. I really will.\n", -1);  
  gtk_text_buffer_get_iter_at_offset (buffer, &iter, 50);
  anchor = gtk_text_buffer_create_child_anchor (buffer, &iter);
  gtk_text_view_add_child_at_anchor (GTK_TEXT_VIEW (textview), colorsel, anchor);

  gtk_widget_show_all (window);

  gtk_main ();
  return 0;
}
