/* gcc -Wall -O2 -ggdb `pkg-config gtk+-2.0 --cflags --libs` -o test test.c */
/* command:
   $ test [0123456]
*/

#include <stdlib.h>
#include <gtk/gtk.h>

static void
cb_destroy (GtkWidget * widget, gpointer data)
{
  gtk_main_quit ();
}

int
main (int argc, char *argv[])
{
  GtkWidget *window, *container = NULL, *entry;
  gint num;

  putenv("GTK_IM_MODULE=xim");

  gtk_set_locale ();
  gtk_init (&argc, &argv);

  if (argc > 1)
    num = atoi (argv[1]);
  else
    num = 0;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_widget_show (window);
  g_signal_connect (G_OBJECT (window), "destroy",
		    G_CALLBACK (cb_destroy), NULL);

  entry = gtk_entry_new ();
  gtk_widget_show (entry);

  switch (num)
    {
    case 1:			/* GtkButton */
      container = gtk_button_new ();
      gtk_container_add (GTK_CONTAINER (container), entry);
      g_print ("GtkViewport: The bug doesn't appear on my environment.\n");
      break;
    case 2:			/* GtkViewport */
      container = gtk_viewport_new (NULL, NULL);
      gtk_container_add (GTK_CONTAINER (container), entry);
      g_print ("GtkViewport\n");
      break;
    case 3:			/* GtkNotebook */
      container = gtk_notebook_new ();
      gtk_notebook_append_page (GTK_NOTEBOOK (container), entry, NULL);
      g_print ("GtkTextView (GTK_TEXT_WINDOW_WIDGET): "
	       "The bug doesn't appear on my environment.\n");
      break;
    case 4:			/* GtkTextView (GTK_TEXT_WINDOW_TEXT) */
      container = gtk_text_view_new ();
      gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container), entry,
					 GTK_TEXT_WINDOW_TEXT, 0, 0);
      break;
    case 5:			/* GtkTextView (GTK_TEXT_WINDOW_WIDGET) */
      container = gtk_text_view_new ();
      gtk_text_view_add_child_in_window (GTK_TEXT_VIEW (container), entry,
					 GTK_TEXT_WINDOW_WIDGET, 0, 0);
      g_print ("GtkTextView (GTK_TEXT_WINDOW_WIDGET): "
	       "The bug doesn't appear on my environment.\n");
      break;
    case 6:
      {
	GtkListStore *store =
	  gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
	GtkTreeIter iter;
	GtkCellRenderer *cell;

	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
			    0,
			    "Please edit me, and destroy the window "
			    "while editing",
			    1, TRUE, -1);

	container = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
	cell = gtk_cell_renderer_text_new ();
	gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW
						     (container), 0,
						     "column1", cell, "text",
						     0, "editable", 1, NULL);
	g_print ("GtkTreeView: Please destroy the window while editing.");
	break;
      }
    case 0:			/* GtkHandleBox */
    default:
      container = gtk_handle_box_new ();
      gtk_container_add (GTK_CONTAINER (container), entry);
      g_print ("GtkHandleBox\n");
      break;
    }

  if (container)
    {
      gtk_widget_show (container);
      gtk_container_add (GTK_CONTAINER (window), container);
    }

  gtk_main ();

  return 0;
}
