/src/wrappers/gtk/examples/gtk-demo/ui_manager.e
Specman e | 262 lines | 21 code | 35 blank | 206 comment | 2 complexity | acca099d04cdcbaac4e5795ea2624c32 MD5 | raw file
1indexing 2 description: "." 3 copyright: "[ 4 Copyright (C) 2006 Paolo Redaelli, GTK+ team 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public License 8 as published by the Free Software Foundation; either version 2.1 of 9 the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, but 12 WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19 02110-1301 USA 20 ]" 21 22class UI_MANAGER 23 24creation make, from_external_pointer 25 26feature {} -- Creation 27 28-- /* UI Manager 29-- * 30-- * The GtkUIManager object allows the easy creation of menus 31-- * from an array of actions and a description of the menu hierarchy. 32-- */ 33 34-- #include <gtk/gtk.h> 35 36-- static void 37-- activate_action (GtkAction *action) 38-- { 39-- g_message ("Action \"%s\" activated", gtk_action_get_name (action)); 40-- } 41 42-- static void 43-- activate_radio_action (GtkAction *action, GtkRadioAction *current) 44-- { 45-- g_message ("Radio action \"%s\" selected", 46-- gtk_action_get_name (GTK_ACTION (current))); 47-- } 48 49-- static GtkActionEntry entries[] = { 50-- { "FileMenu", NULL, "_File" }, /* name, stock id, label */ 51-- { "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */ 52-- { "ColorMenu", NULL, "_Color" }, /* name, stock id, label */ 53-- { "ShapeMenu", NULL, "_Shape" }, /* name, stock id, label */ 54-- { "HelpMenu", NULL, "_Help" }, /* name, stock id, label */ 55-- { "New", GTK_STOCK_NEW, /* name, stock id */ 56-- "_New", "<control>N", /* label, accelerator */ 57-- "Create a new file", /* tooltip */ 58-- G_CALLBACK (activate_action) }, 59-- { "Open", GTK_STOCK_OPEN, /* name, stock id */ 60-- "_Open","<control>O", /* label, accelerator */ 61-- "Open a file", /* tooltip */ 62-- G_CALLBACK (activate_action) }, 63-- { "Save", GTK_STOCK_SAVE, /* name, stock id */ 64-- "_Save","<control>S", /* label, accelerator */ 65-- "Save current file", /* tooltip */ 66-- G_CALLBACK (activate_action) }, 67-- { "SaveAs", GTK_STOCK_SAVE, /* name, stock id */ 68-- "Save _As...", NULL, /* label, accelerator */ 69-- "Save to a file", /* tooltip */ 70-- G_CALLBACK (activate_action) }, 71-- { "Quit", GTK_STOCK_QUIT, /* name, stock id */ 72-- "_Quit", "<control>Q", /* label, accelerator */ 73-- "Quit", /* tooltip */ 74-- G_CALLBACK (activate_action) }, 75-- { "About", NULL, /* name, stock id */ 76-- "_About", "<control>A", /* label, accelerator */ 77-- "About", /* tooltip */ 78-- G_CALLBACK (activate_action) }, 79-- { "Logo", "demo-gtk-logo", /* name, stock id */ 80-- NULL, NULL, /* label, accelerator */ 81-- "GTK+", /* tooltip */ 82-- G_CALLBACK (activate_action) }, 83-- }; 84-- static guint n_entries = G_N_ELEMENTS (entries); 85 86 87-- static GtkToggleActionEntry toggle_entries[] = { 88-- { "Bold", GTK_STOCK_BOLD, /* name, stock id */ 89-- "_Bold", "<control>B", /* label, accelerator */ 90-- "Bold", /* tooltip */ 91-- G_CALLBACK (activate_action), 92-- TRUE }, /* is_active */ 93-- }; 94-- static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries); 95 96-- enum { 97-- COLOR_RED, 98-- COLOR_GREEN, 99-- COLOR_BLUE 100-- }; 101 102-- static GtkRadioActionEntry color_entries[] = { 103-- { "Red", NULL, /* name, stock id */ 104-- "_Red", "<control>R", /* label, accelerator */ 105-- "Blood", COLOR_RED }, /* tooltip, value */ 106-- { "Green", NULL, /* name, stock id */ 107-- "_Green", "<control>G", /* label, accelerator */ 108-- "Grass", COLOR_GREEN }, /* tooltip, value */ 109-- { "Blue", NULL, /* name, stock id */ 110-- "_Blue", "<control>B", /* label, accelerator */ 111-- "Sky", COLOR_BLUE }, /* tooltip, value */ 112-- }; 113-- static guint n_color_entries = G_N_ELEMENTS (color_entries); 114 115-- enum { 116-- SHAPE_SQUARE, 117-- SHAPE_RECTANGLE, 118-- SHAPE_OVAL 119-- }; 120 121-- static GtkRadioActionEntry shape_entries[] = { 122-- { "Square", NULL, /* name, stock id */ 123-- "_Square", "<control>S", /* label, accelerator */ 124-- "Square", SHAPE_SQUARE }, /* tooltip, value */ 125-- { "Rectangle", NULL, /* name, stock id */ 126-- "_Rectangle", "<control>R", /* label, accelerator */ 127-- "Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */ 128-- { "Oval", NULL, /* name, stock id */ 129-- "_Oval", "<control>O", /* label, accelerator */ 130-- "Egg", SHAPE_OVAL }, /* tooltip, value */ 131-- }; 132-- static guint n_shape_entries = G_N_ELEMENTS (shape_entries); 133 134-- static const gchar *ui_info = 135-- "<ui>" 136-- " <menubar name='MenuBar'>" 137-- " <menu action='FileMenu'>" 138-- " <menuitem action='New'/>" 139-- " <menuitem action='Open'/>" 140-- " <menuitem action='Save'/>" 141-- " <menuitem action='SaveAs'/>" 142-- " <separator/>" 143-- " <menuitem action='Quit'/>" 144-- " </menu>" 145-- " <menu action='PreferencesMenu'>" 146-- " <menu action='ColorMenu'>" 147-- " <menuitem action='Red'/>" 148-- " <menuitem action='Green'/>" 149-- " <menuitem action='Blue'/>" 150-- " </menu>" 151-- " <menu action='ShapeMenu'>" 152-- " <menuitem action='Square'/>" 153-- " <menuitem action='Rectangle'/>" 154-- " <menuitem action='Oval'/>" 155-- " </menu>" 156-- " <menuitem action='Bold'/>" 157-- " </menu>" 158-- " <menu action='HelpMenu'>" 159-- " <menuitem action='About'/>" 160-- " </menu>" 161-- " </menubar>" 162-- " <toolbar name='ToolBar'>" 163-- " <toolitem action='Open'/>" 164-- " <toolitem action='Quit'/>" 165-- " <separator action='Sep1'/>" 166-- " <toolitem action='Logo'/>" 167-- " </toolbar>" 168-- "</ui>"; 169 170-- GtkWidget * 171-- do_ui_manager (GtkWidget *do_widget) 172-- { 173-- static GtkWidget *window = NULL; 174 175-- if (!window) 176-- { 177-- GtkWidget *box1; 178-- GtkWidget *box2; 179-- GtkWidget *separator; 180-- GtkWidget *label; 181-- GtkWidget *button; 182-- GtkUIManager *ui; 183-- GtkActionGroup *actions; 184-- GError *error = NULL; 185 186-- window = gtk_window_new (GTK_WINDOW_TOPLEVEL); 187-- gtk_window_set_screen (GTK_WINDOW (window), 188-- gtk_widget_get_screen (do_widget)); 189 190-- g_signal_connect (window, "destroy", 191-- G_CALLBACK (gtk_widget_destroyed), &window); 192-- g_signal_connect (window, "delete-event", 193-- G_CALLBACK (gtk_true), NULL); 194 195-- actions = gtk_action_group_new ("Actions"); 196-- gtk_action_group_add_actions (actions, entries, n_entries, NULL); 197-- gtk_action_group_add_toggle_actions (actions, 198-- toggle_entries, n_toggle_entries, 199-- NULL); 200-- gtk_action_group_add_radio_actions (actions, 201-- color_entries, n_color_entries, 202-- COLOR_RED, 203-- G_CALLBACK (activate_radio_action), 204-- NULL); 205-- gtk_action_group_add_radio_actions (actions, 206-- shape_entries, n_shape_entries, 207-- SHAPE_OVAL, 208-- G_CALLBACK (activate_radio_action), 209-- NULL); 210 211-- ui = gtk_ui_manager_new (); 212-- gtk_ui_manager_insert_action_group (ui, actions, 0); 213-- gtk_window_add_accel_group (GTK_WINDOW (window), 214-- gtk_ui_manager_get_accel_group (ui)); 215-- gtk_window_set_title (GTK_WINDOW (window), "UI Manager"); 216-- gtk_container_set_border_width (GTK_CONTAINER (window), 0); 217 218-- if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error)) 219-- { 220-- g_message ("building menus failed: %s", error->message); 221-- g_error_free (error); 222-- } 223 224-- box1 = gtk_vbox_new (FALSE, 0); 225-- gtk_container_add (GTK_CONTAINER (window), box1); 226 227-- gtk_box_pack_start (GTK_BOX (box1), 228-- gtk_ui_manager_get_widget (ui, "/MenuBar"), 229-- FALSE, FALSE, 0); 230 231-- label = gtk_label_new ("Type\n<alt>\nto start"); 232-- gtk_widget_set_size_request (label, 200, 200); 233-- gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5); 234-- gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0); 235 236 237-- separator = gtk_hseparator_new (); 238-- gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0); 239 240 241-- box2 = gtk_vbox_new (FALSE, 10); 242-- gtk_container_set_border_width (GTK_CONTAINER (box2), 10); 243-- gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0); 244 245-- button = gtk_button_new_with_label ("close"); 246-- g_signal_connect_swapped (button, "clicked", 247-- G_CALLBACK (gtk_widget_destroy), window); 248-- gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0); 249-- GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT); 250-- gtk_widget_grab_default (button); 251 252-- gtk_widget_show_all (window); 253-- } 254-- else 255-- { 256-- gtk_widget_destroy (window); 257-- window = NULL; 258-- } 259 260-- return window; 261-- } 262end