
#include <gtk/gtk.h>

#define N_ITEMS 100

static void
text_combo_add_items (GtkComboBoxText *combo)
{
  guint i;
  GTimer *timer = g_timer_new ();
  
  for (i = 0; i < N_ITEMS; i++)
    {
      gchar *text = g_strdup_printf ("Item %u", i+1);
      gtk_combo_box_text_append_text (combo, text);
      g_free (text);
    }
  
  g_debug ("Adding %u items to combo box %p took %gs",
           i, (gpointer) combo, g_timer_elapsed (timer, NULL));
}

static void
add_combo_box (GtkContainer  *parent,
               gint           wrap_width)
{
  gchar *text;
  GtkWidget *box;
  GtkWidget *label;
  GtkWidget *combo;
  
  box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
  gtk_container_add (parent, box);
  
  text = g_strdup_printf ("wrap-width=%d:", wrap_width);
  label = gtk_label_new (text);
  g_free (text);
  gtk_box_pack_start (GTK_BOX (box), label, FALSE, FALSE, 0);
  
  combo = gtk_combo_box_text_new ();
  gtk_box_pack_start (GTK_BOX (box), combo, TRUE, TRUE, 0);
  
  gtk_combo_box_set_wrap_width (GTK_COMBO_BOX (combo), wrap_width);
  text_combo_add_items (GTK_COMBO_BOX_TEXT (combo));
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), 0);
}

int
main (int     argc,
      char  **argv)
{
  GtkWidget *dialog;
  GtkWidget *box;
  gint i;
  
  gtk_init (&argc, &argv);
  
  dialog = gtk_dialog_new ();
  gtk_dialog_add_button (GTK_DIALOG (dialog), "Close", GTK_RESPONSE_CLOSE);
  box = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
  
  for (i = 0; i < 5; i++)
    add_combo_box (GTK_CONTAINER (box), i);
  
  gtk_widget_show_all (dialog);
  gtk_dialog_run (GTK_DIALOG (dialog));
  
  return 0;
}
