#include <glib/gprintf.h>
#include <glib-object.h>
#include <glib/gprintf.h>
#include <gtk/gtk.h>

GtkWidget*
create_notebook(int             n_children,
                int             current_page,
                GtkPositionType postype,
                gboolean        scrollable,
                GtkPackType     tab_pack)
{
    gint i;
    GtkWidget *notebook;
    GtkWidget *page;

    notebook = gtk_notebook_new ();
    gtk_container_set_border_width (GTK_CONTAINER (notebook), 4);

    for (i = 0; i < n_children; i++)
      {
        page = gtk_label_new ("test");

        gtk_widget_show (page);
        gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, NULL);
        gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", tab_pack, NULL);
      }

    gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), postype);
    gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), current_page);
    gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), scrollable);

    return notebook;
}

int
main (int argc,
      char *argv[])
{
    GtkWidget *window;
    GtkWidget *notebook;
    GtkTable  *table;
    gint pos;
    gint postype;
    gint tab_pack;
    
    gtk_init (&argc, &argv);
    
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "Ultimate GtkNotebook Test");
    gtk_window_maximize (GTK_WINDOW (window));
    g_signal_connect(window, "delete-event", gtk_main_quit, NULL);

    table = GTK_TABLE (gtk_table_new (7, 10, FALSE));
    gtk_table_set_col_spacings (table, 4);
    gtk_table_set_row_spacings (table, 4);
    gtk_container_set_border_width (GTK_CONTAINER (table), 4);
    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET (table));

    tab_pack = GTK_PACK_END;

    for (pos = 0; pos < 8; pos++)
      {
        if (tab_pack == GTK_PACK_END)
          tab_pack = GTK_PACK_START;
        else
          tab_pack = GTK_PACK_END;

        if (pos >= 4)
          postype = pos - 4;
        else
          postype = pos;

        notebook = create_notebook(1, 0, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 0, 1);

        notebook = create_notebook(2, 0, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 1, 2);

        notebook = create_notebook(2, 1, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 2, 3);

        notebook = create_notebook(3, 0, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 3, 4);

        notebook = create_notebook(3, 1, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 4, 5);

        notebook = create_notebook(3, 2, postype, FALSE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 5, 6);

        notebook = create_notebook(6, 0, postype, TRUE, tab_pack);
        gtk_table_attach_defaults (table, notebook, 0 + pos, 1 + pos, 6, 7);
      }

    gtk_widget_show_all(window);
    gtk_main ();

    return 0;
}

