
/*
 * Build with:
 * gcc menuitems.c -o menuitems -Wall `pkg-config gtk+-3.0 --cflags --libs`
 */

#include <stdio.h>
#include <gtk/gtk.h>

int
main (int argc, char *argv[])
{
    GtkWidget *window;
    GtkWidget *vbox;
    GtkWidget *menu;
    GtkWidget *menu_bar;
    GtkWidget *root_menu;
    GtkWidget *menu_items;
    gint i;
    gchar buffer[32];

    gtk_init (&argc, &argv);

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    g_signal_connect (window, "delete-event", G_CALLBACK (gtk_main_quit), NULL);
    menu = gtk_menu_new ();
    for (i = 1; i < 1000; i++)
      {
        g_snprintf (buffer, sizeof(buffer), "Menu item #%i", i);
        menu_items = gtk_menu_item_new_with_label (buffer);
        g_signal_connect_swapped (menu_items, "activate", 
                                  G_CALLBACK (gtk_main_quit), NULL);
        gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
      }

    gtk_widget_show (menu_items);
    root_menu = gtk_menu_item_new_with_label ("File");
    gtk_widget_show (root_menu);
    gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);

    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
    gtk_container_add (GTK_CONTAINER (window), vbox);
    gtk_widget_show (vbox);

    menu_bar = gtk_menu_bar_new ();
    gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 1);
    gtk_widget_show (menu_bar);

    gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);

    gtk_widget_show_all (GTK_WIDGET (window));

    gtk_main ();

    return 0;
}
