#include <gtk/gtk.h>

static GtkWidget *
create_label (guint    index,
              gboolean use_underline,
              gboolean use_markup)
{
  char *str;

  str = g_strdup_printf ("%sPage %s%s%c%s",
                         use_markup ? "<i>" : "",
                         use_markup ? "<span color='#00FF00'>" : "",
                         use_underline ? "_" : "",
                         (char)('A' + index),
                         use_markup ? "</span></i>" : "");
  GtkWidget *label = gtk_label_new (str);
  g_free (str);

  gtk_label_set_use_underline (GTK_LABEL (label), use_underline);
  gtk_label_set_use_markup (GTK_LABEL (label), use_markup);

  str = g_strdup_printf ("index == %u\n"
                           "use_underline == %i\n"
                           "use_markup == %i",
                         index, use_underline, use_markup);
  gtk_widget_set_tooltip_text (label, str);
  g_free (str);

  return label;
}

static void
on_activate (GApplication *application,
             void         *user_data)
{
  GtkWidget *notebook;
  GtkWidget *window;
  guint i;

  notebook = gtk_notebook_new ();
  gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook));

  for (i = 0; i < 8; ++i)
    {
      gboolean use_underline = i / 2 % 2;
      gboolean use_markup = i / 4;

      GtkWidget *child = create_label (i, use_underline, use_markup);
      GtkWidget *tab_label = create_label (i, use_underline, use_markup);
      GtkWidget *menu_label = i % 2 == 0 ? NULL : create_label (i, use_underline, use_markup);

      gtk_notebook_append_page_menu (GTK_NOTEBOOK (notebook), child,
                                     tab_label, menu_label);
    }

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_add (GTK_CONTAINER (window), notebook);
  gtk_widget_show_all (window);
  gtk_application_add_window (GTK_APPLICATION (application),
                              GTK_WINDOW (window));
}

int
main (int   argc,
      char *argv[])
{
  GtkApplication *application;
  int result;

  application = gtk_application_new ("org.gtk.test.notebook",
                                     G_APPLICATION_FLAGS_NONE);
  g_signal_connect (application, "activate", G_CALLBACK (on_activate), NULL);

  result = g_application_run (G_APPLICATION (application), argc, argv);
  g_object_unref (application);
  return result;
}
