/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 8; tab-width: 8 -*- */
/*
   Copyright (C) 2004 William Jon McCann <mccann@jhu.edu>
  
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License as
   published by the Free Software Foundation; either version 2 of the
   License, or (at your option) any later version.
  
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.
  
   You should have received a copy of the GNU General Public
   License along with this program; if not, write to the
   Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Build with:
   gcc -o popup-test `pkg-config --cflags --libs libglade-2.0` popup-test.c

*/

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

void
on_button_clicked (GtkWidget      *widget,
                   gpointer        data)
{
        GtkWidget *menu = NULL;

	menu = glade_xml_get_widget ((GladeXML *)data, "menu1");

        gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL,
                        0, gtk_get_current_event_time ());
}

int
main (int argc, char **argv)
{
        GtkWidget       *win2;
        GtkWidget       *button1;
        GtkWidget       *button2;
        GladeXML        *xml1;
        GladeXML        *xml2;

	gtk_init (&argc, &argv);

        xml1 = glade_xml_new ("popup-test.glade", NULL, NULL);
        glade_xml_signal_autoconnect (xml1);
        xml2 = glade_xml_new ("popup-test.glade", "menu1", NULL);
        glade_xml_signal_autoconnect (xml2);

	button1 = glade_xml_get_widget (xml1, "button1");
        g_signal_connect (button1, "clicked", G_CALLBACK (on_button_clicked), xml1);

	win2 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        button2 = gtk_button_new_with_label ("Button2");
        g_signal_connect (button2, "clicked", G_CALLBACK (on_button_clicked), xml2);
        gtk_container_add (GTK_CONTAINER (win2), button2);

        gtk_widget_show_all (win2);

        gtk_main ();

        return 0;
}
