/* vim: set ai ts=4 sw=4: */ /* * Copyright 2004 Keith Sharp * * 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. */ #include #define UI_FILENAME "ui_manager.xml" /* Filename for XML file with menus and buttons */ void destroy_callback (GtkWidget *widget, gpointer data) { gtk_main_quit (); return; } void activate_action (GtkAction *action, gpointer data) { guint cid = gtk_statusbar_get_context_id (GTK_STATUSBAR(data), "Context Description"); gtk_statusbar_push (GTK_STATUSBAR(data), cid, g_strconcat ("Action \"", gtk_action_get_name (action), "\" activated", NULL)); } gint main (gint argc, gchar *argv[]) { GtkWidget *window, *vbox, *status; GtkUIManager *ui; GtkActionGroup *actions; GtkAction *remove; GError *error = NULL; static GtkActionEntry entries[] = { { "FileMenu", NULL, "_File" }, { "New", GTK_STOCK_NEW, "_New", "N", "Create a new file", G_CALLBACK (activate_action) }, { "Open", GTK_STOCK_OPEN, "_Open", "O", "Open a file", G_CALLBACK (activate_action) }, { "Save", GTK_STOCK_SAVE, "_Save", "S", "Save a file", G_CALLBACK (activate_action) }, { "Quit", GTK_STOCK_QUIT, "_Quit", "Q", "Quit application", G_CALLBACK (destroy_callback) }, { "Add", GTK_STOCK_ADD, "_Add", "A", "Add an item", G_CALLBACK (activate_action) } }; guint n_entries = G_N_ELEMENTS (entries); gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); g_signal_connect (G_OBJECT(window), "destroy", G_CALLBACK(destroy_callback), NULL); gtk_window_set_default_size (GTK_WINDOW(window), 200, 50); status = gtk_statusbar_new (); actions = gtk_action_group_new ("Actions"); gtk_action_group_add_actions (actions, entries, n_entries, status); ui = gtk_ui_manager_new (); if (!gtk_ui_manager_add_ui_from_file (ui, UI_FILENAME, &error)) { g_error ("Could not merge UI from %s, error was: %s\n", UI_FILENAME, error->message); } gtk_ui_manager_insert_action_group (ui, actions, 0); vbox = gtk_vbox_new (FALSE, 0); gtk_container_add (GTK_CONTAINER (window), vbox); gtk_box_pack_start (GTK_BOX (vbox), gtk_ui_manager_get_widget (ui, "/MenuBar"), FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (vbox), gtk_ui_manager_get_widget (ui, "/ToolBar"), TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox), status, FALSE, FALSE, 0); gtk_widget_show_all (window); gtk_main (); return 1; }