/* Test program for GTK+ bug #311141 by Robert Ögren <gtk@roboros.com> */
#include <gtk/gtk.h>

static GtkListStore *store; /* yes this is ugly but I'm lazy today */

static void closepopup( GtkWidget *widget,
                        gpointer   data )
{
  gtk_list_store_clear (store);
  gtk_widget_destroy (GTK_WIDGET (data));
}

static void dopopup( GtkWidget *widget,
                     gpointer   data )
{
  GtkWidget *vbox, *popup, *button, *combobox;
  GtkCellRenderer *renderer;
  GtkTreeIter iter;

  store = gtk_list_store_new (1, G_TYPE_STRING);
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter, 0, "testing 1", -1);
  gtk_list_store_append (store, &iter);
  gtk_list_store_set (store, &iter, 0, "testing 2", -1);

  
  popup = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (popup), 10);

  vbox = gtk_vbox_new (TRUE, 10);
  combobox = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
  renderer = gtk_cell_renderer_text_new ();
  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combobox), renderer,
				  "text", 0, NULL);

  gtk_container_add (GTK_CONTAINER (vbox), combobox); 	  

  button = gtk_button_new_with_label ("Close me");
  g_signal_connect (G_OBJECT (button), "clicked",
		    G_CALLBACK (closepopup), popup);
  gtk_container_add (GTK_CONTAINER (vbox), button);
  
  gtk_container_add (GTK_CONTAINER (popup), vbox);
  
  gtk_widget_show_all (popup);
}

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

int main( int   argc,
          char *argv[] )
{
  GtkWidget *button, *window;
  
  gtk_rc_parse_string ("style \"foo\" { "
		       "   GtkComboBox::appears_as_list = 1\n"
		       "}\n"
		       "class \"GtkComboBox\" style \"foo\"");
  
  gtk_init (&argc, &argv);
  
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  
  g_signal_connect (G_OBJECT (window), "destroy",
		    G_CALLBACK (destroy), NULL);
  
  gtk_container_set_border_width (GTK_CONTAINER (window), 10);

  button = gtk_button_new_with_label ("Create popup");
  g_signal_connect (G_OBJECT (button), "clicked",
		    G_CALLBACK (dopopup), NULL);

  gtk_container_add (GTK_CONTAINER (window), button);
  
  gtk_widget_show_all (window);
  gtk_main ();
  return 0;
}
