
/*
 * Simple reproducer for bug #748892
 * Build with:
 * gcc menu.c -o menu -Wall -DWINDOW_GROUP=1 `pkg-config gtk+-3.0 --cflags --libs`
 */

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

#ifndef WINDOW_GROUP
#define WINDOW_GROUP 1
#endif

static void
create_new_window (void)
{
    GtkWidget *window;
    GtkWidget *scrolled;
    GtkWidget *view;
    GtkWidget *overlay;
    GtkWidget *menu;
    GtkWidget *menu_bar;
    GtkWidget *root_menu;
    GtkWidget *menu_items;
    GtkWidget *vbox;
#if WINDOW_GROUP
    GtkWindowGroup *window_group;
#endif

    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request (GTK_WIDGET (window), 400, 300);

    menu = gtk_menu_new ();
    menu_items = gtk_menu_item_new_with_label ("New window");
    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_items);
    g_signal_connect_swapped (menu_items, "activate",
        G_CALLBACK (create_new_window), NULL);

    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);

    overlay = gtk_overlay_new ();
    scrolled = gtk_scrolled_window_new (NULL, NULL);
    gtk_widget_set_hexpand (scrolled, TRUE);
    gtk_widget_set_vexpand (scrolled, TRUE);
    view = gtk_text_view_new ();

    gtk_container_add (GTK_CONTAINER (scrolled), view);
    gtk_container_add (GTK_CONTAINER (overlay), scrolled);
    gtk_box_pack_end (GTK_BOX (vbox), overlay, TRUE, TRUE, 2);

    gtk_menu_shell_append (GTK_MENU_SHELL (menu_bar), root_menu);

#if WINDOW_GROUP
    window_group = gtk_window_group_new ();
    gtk_window_group_add_window (window_group, GTK_WINDOW (window));
    g_object_unref (window_group);
#endif

    gtk_widget_show_all (GTK_WIDGET (window));
}

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

    create_new_window ();
    gtk_main ();

    return 0;
}
