#include <gtk/gtk.h>

static GtkWidget *
create_box ()
{
  GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
  GtkWidget *label = gtk_label_new ("What is the deal with GtkListBox?");
  gtk_container_add ((GtkContainer *)box, label);
  gtk_widget_show_all (box);
  return box;
}

static void
add_box (GtkListBox *list)
{
  gtk_container_add ((GtkContainer *)list, create_box ());
}

int
main (int argc, char **argv)
{
  gtk_init (&argc, &argv);

  GtkCssProvider *css = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (css,
"list > :not(:last-child) { margin-bottom: 1em; }"
    , -1, NULL);
  gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                             (GtkStyleProvider *)css,
                                             GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);

  GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  GtkWidget *list   = gtk_list_box_new ();

  gtk_container_add ((GtkContainer *)list, create_box ());

  g_signal_connect (list, "button-press-event", (GCallback) add_box, NULL);

  gtk_widget_show (list);
  gtk_container_add ((GtkContainer *)window, list);
  gtk_widget_show (window);

  gtk_main ();
}
