
/*
  gcc -o test-case test-case.c `pkg-config --cflags --libs gtk+-2.0`
 */

#include                                        <gtk/gtk.h>

static gboolean
remove_rows                                     (gpointer user_data)
{
  GtkTreeIter iter;
  GtkListStore *store = GTK_LIST_STORE (user_data);
  gint i, max;

  max = gtk_tree_model_iter_n_children (GTK_TREE_MODEL (store), NULL) / 2;
  gtk_tree_model_get_iter_first (GTK_TREE_MODEL (store), &iter);
  g_print ("Removing %d rows ...", max);
  for (i = 0; i < max; i++)
    {
      gtk_list_store_set (store, &iter, 1, FALSE, -1);
      gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
      gtk_tree_model_iter_next (GTK_TREE_MODEL (store), &iter);
    }
  g_print (" done\n");
  return FALSE;
}

static void
on_button_clicked                               (GtkButton *button,
                                                 gpointer   data)
{
  GtkWidget *dialog, *sw, *treeview;
  GtkCellRenderer *renderer;
  GtkTreeModel *filter;
  GtkListStore *store;
  gint i;

  /* Create list store */
  store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_BOOLEAN);
  for (i = 0; i < 15000; i++)
    {
      GtkTreeIter iter;
      gchar text[10];
      sprintf (text, "%d", i);
      gtk_list_store_append (store, &iter);
      gtk_list_store_set (store, &iter, 0, text, 1, TRUE, -1);
    }


  /* Create tree model filter */
  filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (store), NULL);
  gtk_tree_model_filter_set_visible_column (GTK_TREE_MODEL_FILTER (filter), 1);

  /* Create tree view */
  treeview = gtk_tree_view_new_with_model (filter);
  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_renderer_set_fixed_size (renderer, -1, 100);
  gtk_tree_view_append_column
    (GTK_TREE_VIEW (treeview),
     gtk_tree_view_column_new_with_attributes ("title", renderer, "text", 0, NULL));

  /* Create dialog */
  dialog = gtk_dialog_new ();
  gtk_window_set_default_size (GTK_WINDOW (dialog), -1, 380);

  sw = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (sw), treeview);

  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), sw, TRUE, TRUE, 0);
  gtk_widget_show_all (dialog);

  /* Add timeout */
  gdk_threads_add_timeout (1000, remove_rows, store);

  g_object_unref (store);
  g_object_unref (filter);
}

int
main                                            (int    argc,
                                                 char **argv)
{
  GtkWidget *window, *button;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 100);
  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), window);

  button = gtk_button_new_with_label ("Click me");
  gtk_container_add (GTK_CONTAINER (window), button);

  g_signal_connect (button, "clicked", G_CALLBACK (on_button_clicked), NULL);

  gtk_widget_show_all (window);
  gtk_main ();

  return 0;
}
