From 7402d68c8ff04b1f09b32dab5ee601919b16fe54 Mon Sep 17 00:00:00 2001 From: GMT 1999 Tony Gale Date: Mon, 1 Feb 1999 14:47:05 +0000 Subject: [PATCH] update to new examples Mon Feb 1 13:35:14 GMT 1999 Tony Gale * examples/Makefile: update to new examples * examples/menu/itemfactory.c: I must have forgotten to 'cvs add' this file --- ChangeLog | 7 +++ ChangeLog.pre-2-0 | 7 +++ ChangeLog.pre-2-10 | 7 +++ ChangeLog.pre-2-2 | 7 +++ ChangeLog.pre-2-4 | 7 +++ ChangeLog.pre-2-6 | 7 +++ ChangeLog.pre-2-8 | 7 +++ examples/Makefile | 41 ++++++++++++-- examples/menu/itemfactory.c | 108 ++++++++++++++++++++++++++++++++++++ 9 files changed, 193 insertions(+), 5 deletions(-) create mode 100644 examples/menu/itemfactory.c diff --git a/ChangeLog b/ChangeLog index 51dfc37278..dcb8610954 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 51dfc37278..dcb8610954 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,10 @@ +Mon Feb 1 13:35:14 GMT 1999 Tony Gale + + * examples/Makefile: update to new examples + + * examples/menu/itemfactory.c: I must have forgotten to + 'cvs add' this file + Mon Feb 1 09:16:03 GMT 1999 Tony Gale * docs/gtk_tut.sgml: diff --git a/examples/Makefile b/examples/Makefile index a5396d2aab..f669019c92 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -1,9 +1,40 @@ -SUBDIRS = aspectframe eventbox gtkdial notebook progressbar scrolledwin tictactoe \ - clist filesel list paned rulers table \ - entry menu pixmap scribble-simple text \ - base helloworld packbox radiobuttons selection tree \ - buttons helloworld2 packer rangewidgets statusbar wheelbarrow +SUBDIRS = arrow \ + aspectframe \ + base \ + buttonbox \ + buttons \ + calendar \ + clist \ + entry \ + eventbox \ + filesel \ + fixed \ + frame \ + gtkdial \ + helloworld \ + helloworld2 \ + label \ + list \ + menu \ + notebook \ + packbox \ + packer \ + paned \ + pixmap \ + progressbar \ + radiobuttons \ + rangewidgets \ + rulers \ + scribble-simple \ + scrolledwin \ + selection \ + statusbar \ + table \ + text \ + tictactoe \ + tree \ + wheelbarrow all: list='$(SUBDIRS)'; \ diff --git a/examples/menu/itemfactory.c b/examples/menu/itemfactory.c new file mode 100644 index 0000000000..b47e3dfe85 --- /dev/null +++ b/examples/menu/itemfactory.c @@ -0,0 +1,108 @@ +/* example-start menu itemfactory.c */ + +#include +#include + +/* Obligatory basic callback */ +static void print_hello(GtkWidget *w, gpointer data) { + g_message("Hello, World!\n"); +} + +/* This is the GtkItemFactoryEntry structure used to generate new menus. + Item 1: The menu path. The letter after the underscore indicates an + accelerator key once the menu is open. + Item 2: The accelerator key for the entry + Item 3: The callback function. + Item 4: The callback action. This changes the parameters with + which the function is called. The default is 0. + Item 5: The item type, used to define what kind of an item it is. + Here are the possible values: + + NULL -> "" + "" -> "" + "" -> create a title item + "<Item>" -> create a simple item + "<CheckItem>" -> create a check item + "<ToggleItem>" -> create a toggle item + "<RadioItem>" -> create a radio item + <path> -> path of a radio item to link against + "<Separator>" -> create a separator + "<Branch>" -> create an item to hold sub items + "<LastBranch>" -> create a right justified branch +*/ + +static GtkItemFactoryEntry menu_items[] = { + {"/_File", NULL, NULL, 0, "<Branch>"}, + {"/File/_New", "<control>N", print_hello, 0, NULL}, + {"/File/_Open", "<control>O", print_hello, 0, NULL}, + {"/File/_Save", "<control>S", print_hello, 0, NULL}, + {"/File/Save _As", NULL, NULL, 0, NULL}, + {"/File/sep1", NULL, NULL, 0, "<Separator>"}, + {"/File/Quit", "<control>Q", gtk_main_quit, 0, NULL}, + {"/_Options", NULL, NULL, 0, "<Branch>"}, + {"/Options/Test", NULL, NULL, 0, NULL}, + {"/_Help", NULL, NULL, 0, "<LastBranch>"}, + {"/_Help/About", NULL, NULL, 0, NULL}, +}; + + +void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { + int nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group; + + accel_group = gtk_accel_group_new(); + + /* This function initializes the item factory. + Param 1: The type of menu - can be GTK_TYPE_MENU_BAR, GTK_TYPE_MENU, + or GTK_TYPE_OPTION_MENU. + Param 2: The path of the menu. + Param 3: A pointer to a gtk_accel_group. The item factory sets up + the accelerator table while generating menus. + */ + + item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>", + accel_group); + + /* This function generates the menu items. Pass the item factory, + the number of items in the array, the array itself, and any + callback data for the the menu items. */ + gtk_item_factory_create_items(item_factory, nmenu_items, menu_items, NULL); + + /* Attach the new accelerator group to the window. */ + gtk_accel_group_attach (accel_group, GTK_OBJECT (window)); + + if (menubar) + /* Finally, return the actual menu bar created by the item factory. */ + *menubar = gtk_item_factory_get_widget(item_factory, "<main>"); +} + +int main(int argc, char *argv[]) { + GtkWidget *window; + GtkWidget *main_vbox; + GtkWidget *menubar; + + gtk_init(&argc, &argv); + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_signal_connect(GTK_OBJECT(window), "destroy", + GTK_SIGNAL_FUNC(gtk_main_quit), + "WM destroy"); + gtk_window_set_title(GTK_WINDOW(window), "Item Factory"); + gtk_widget_set_usize(GTK_WIDGET(window), 300, 200); + + main_vbox = gtk_vbox_new(FALSE, 1); + gtk_container_border_width(GTK_CONTAINER(main_vbox), 1); + gtk_container_add(GTK_CONTAINER(window), main_vbox); + gtk_widget_show(main_vbox); + + get_main_menu(window, &menubar); + gtk_box_pack_start(GTK_BOX(main_vbox), menubar, FALSE, TRUE, 0); + gtk_widget_show(menubar); + + gtk_widget_show(window); + gtk_main(); + + return(0); +} +/* example-end */