/* gcc test-notebook-action-area `pkg-config --cflags --libs gtk+-2.0` test-notebook-action-area.c */

#include <gtk/gtk.h>

static GtkWidget *
create_button (const gchar *stock_id)
{
  GtkWidget *button;
  GtkRcStyle *style;

  button = gtk_button_new ();
  gtk_container_add (GTK_CONTAINER (button),
                     gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU));

  style = gtk_widget_get_modifier_style (button);
  style->xthickness = style->ythickness = 0;

  gtk_widget_modify_style (button, style);

  return button;
}

static void
add_tab (GtkNotebook *notebook)
{
  GtkWidget *label;

  label = gtk_label_new ("Hello");
  gtk_widget_show (label);
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), label, NULL);
}

static void
delete_tab (GtkNotebook *notebook)
{
  gint current_page;

  current_page = gtk_notebook_get_current_page (notebook);

  if (current_page != -1)
    gtk_notebook_remove_page (notebook, current_page);
}

int
main (int argc, gchar *argv[])
{
  GtkWidget *window, *notebook, *button;
  gint i;

  gtk_init (&argc, &argv);

  notebook = gtk_notebook_new ();
  gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
  gtk_container_set_border_width (GTK_CONTAINER (notebook), 0);

  /* Add button */
  button = create_button ("gtk-new");
  g_signal_connect_swapped (button, "clicked",
                            G_CALLBACK (add_tab), notebook);
  gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), button, GTK_PACK_START);

  /* Close button */
  button = create_button ("gtk-close");
  g_signal_connect_swapped (button, "clicked",
                            G_CALLBACK (delete_tab), notebook);
  gtk_notebook_set_action_widget (GTK_NOTEBOOK (notebook), button, GTK_PACK_END);

  for (i = 0; i < 10; i++)
    add_tab (GTK_NOTEBOOK (notebook));

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (GTK_CONTAINER (window), 2);
  g_signal_connect (window, "destroyed",
                    G_CALLBACK (gtk_main_quit), NULL);

  gtk_container_add (GTK_CONTAINER (window), notebook);
  gtk_widget_show_all (window);

  gtk_main ();

  return 0;
}
