summaryrefslogtreecommitdiff
path: root/examples/menu
diff options
context:
space:
mode:
authorGMT 1999 Tony Gale <gale@gtk.org>1999-11-13 23:06:46 +0000
committerTony Gale <gale@src.gnome.org>1999-11-13 23:06:46 +0000
commitee3d13766031e30653d82764aef92ae444015c5e (patch)
treec0d025531a52bee6a44d65babd111b6d3f04bed7 /examples/menu
parente4df9fa95b83ce233c2129c3098e2727316e982b (diff)
downloadgtk+-ee3d13766031e30653d82764aef92ae444015c5e.tar.gz
threads example from Erik Mouw. New question on GtkLabel background
Sat Nov 13 22:30:29 GMT 1999 Tony Gale <gale@gtk.org> * docs/gtkfaq.sgml: threads example from Erik Mouw. New question on GtkLabel background colors. * docs/gtk_tut.sgml: - Correct the example code callback function definitions. - Update the gtkdial example code, from Frans van Schaik. - Update setselection.c to current API. * examples/Makefile examples/*/*.c: Update to code listed in tutorial.
Diffstat (limited to 'examples/menu')
-rw-r--r--examples/menu/itemfactory.c82
-rw-r--r--examples/menu/menu.c72
2 files changed, 81 insertions, 73 deletions
diff --git a/examples/menu/itemfactory.c b/examples/menu/itemfactory.c
index b47e3dfe85..d1239baff2 100644
--- a/examples/menu/itemfactory.c
+++ b/examples/menu/itemfactory.c
@@ -4,8 +4,10 @@
#include <strings.h>
/* Obligatory basic callback */
-static void print_hello(GtkWidget *w, gpointer data) {
- g_message("Hello, World!\n");
+static void print_hello( GtkWidget *w,
+ gpointer data )
+{
+ g_message ("Hello, World!\n");
}
/* This is the GtkItemFactoryEntry structure used to generate new menus.
@@ -27,31 +29,33 @@ static void print_hello(GtkWidget *w, gpointer data) {
"<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
+ "<Branch>" -> create an item to hold sub items (optional)
"<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},
+ { "/_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]);
+void get_main_menu( GtkWidget *window,
+ GtkWidget **menubar )
+{
GtkItemFactory *item_factory;
GtkAccelGroup *accel_group;
+ gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
- accel_group = gtk_accel_group_new();
+ 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,
@@ -61,47 +65,49 @@ void get_main_menu(GtkWidget *window, GtkWidget ** menubar) {
the accelerator table while generating menus.
*/
- item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "<main>",
+ 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);
+ 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));
+ gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
if (menubar)
/* Finally, return the actual menu bar created by the item factory. */
- *menubar = gtk_item_factory_get_widget(item_factory, "<main>");
+ *menubar = gtk_item_factory_get_widget (item_factory, "<main>");
}
-int main(int argc, char *argv[]) {
+int main( int argc,
+ char *argv[] )
+{
GtkWidget *window;
GtkWidget *main_vbox;
GtkWidget *menubar;
- gtk_init(&argc, &argv);
+ 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);
+ 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);
+ 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);
+ 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();
+ gtk_widget_show (window);
+ gtk_main ();
return(0);
}
diff --git a/examples/menu/menu.c b/examples/menu/menu.c
index a53019b02e..e1420e80aa 100644
--- a/examples/menu/menu.c
+++ b/examples/menu/menu.c
@@ -5,7 +5,8 @@
static gint button_press (GtkWidget *, GdkEvent *);
static void menuitem_response (gchar *);
-int main (int argc, char *argv[])
+int main( int argc,
+ char *argv[] )
{
GtkWidget *window;
@@ -21,17 +22,17 @@ int main (int argc, char *argv[])
gtk_init (&argc, &argv);
/* create a new window */
- window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
- gtk_widget_set_usize( GTK_WIDGET (window), 200, 100);
- gtk_window_set_title(GTK_WINDOW (window), "GTK Menu Test");
- gtk_signal_connect(GTK_OBJECT (window), "delete_event",
- (GtkSignalFunc) gtk_main_quit, NULL);
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_usize (GTK_WIDGET (window), 200, 100);
+ gtk_window_set_title (GTK_WINDOW (window), "GTK Menu Test");
+ gtk_signal_connect (GTK_OBJECT (window), "delete_event",
+ (GtkSignalFunc) gtk_main_quit, NULL);
/* Init the menu-widget, and remember -- never
* gtk_show_widget() the menu widget!!
* This is the menu that holds the menu items, the one that
* will pop up when you click on the "Root Menu" in the app */
- menu = gtk_menu_new();
+ menu = gtk_menu_new ();
/* Next we make a little loop that makes three menu-entries for "test-menu".
* Notice the call to gtk_menu_append. Here we are adding a list of
@@ -39,64 +40,64 @@ int main (int argc, char *argv[])
* signal on each of the menu items and setup a callback for it,
* but it's omitted here to save space. */
- for(i = 0; i < 3; i++)
+ for (i = 0; i < 3; i++)
{
/* Copy the names to the buf. */
- sprintf(buf, "Test-undermenu - %d", i);
+ sprintf (buf, "Test-undermenu - %d", i);
/* Create a new menu-item with a name... */
- menu_items = gtk_menu_item_new_with_label(buf);
+ menu_items = gtk_menu_item_new_with_label (buf);
/* ...and add it to the menu. */
- gtk_menu_append(GTK_MENU (menu), menu_items);
+ gtk_menu_append (GTK_MENU (menu), menu_items);
/* Do something interesting when the menuitem is selected */
- gtk_signal_connect_object(GTK_OBJECT(menu_items), "activate",
- GTK_SIGNAL_FUNC(menuitem_response), (gpointer) g_strdup(buf));
+ gtk_signal_connect_object (GTK_OBJECT (menu_items), "activate",
+ GTK_SIGNAL_FUNC (menuitem_response), (gpointer) g_strdup (buf));
/* Show the widget */
- gtk_widget_show(menu_items);
+ gtk_widget_show (menu_items);
}
/* This is the root menu, and will be the label
* displayed on the menu bar. There won't be a signal handler attached,
* as it only pops up the rest of the menu when pressed. */
- root_menu = gtk_menu_item_new_with_label("Root Menu");
+ root_menu = gtk_menu_item_new_with_label ("Root Menu");
- gtk_widget_show(root_menu);
+ gtk_widget_show (root_menu);
/* Now we specify that we want our newly created "menu" to be the menu
* for the "root menu" */
- gtk_menu_item_set_submenu(GTK_MENU_ITEM (root_menu), menu);
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (root_menu), menu);
/* A vbox to put a menu and a button in: */
- vbox = gtk_vbox_new(FALSE, 0);
- gtk_container_add(GTK_CONTAINER(window), vbox);
- gtk_widget_show(vbox);
+ vbox = gtk_vbox_new (FALSE, 0);
+ gtk_container_add (GTK_CONTAINER (window), vbox);
+ gtk_widget_show (vbox);
/* Create a menu-bar to hold the menus and add it to our main window */
- menu_bar = gtk_menu_bar_new();
- gtk_box_pack_start(GTK_BOX(vbox), menu_bar, FALSE, FALSE, 2);
- gtk_widget_show(menu_bar);
+ menu_bar = gtk_menu_bar_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), menu_bar, FALSE, FALSE, 2);
+ gtk_widget_show (menu_bar);
/* Create a button to which to attach menu as a popup */
- button = gtk_button_new_with_label("press me");
- gtk_signal_connect_object(GTK_OBJECT(button), "event",
- GTK_SIGNAL_FUNC (button_press), GTK_OBJECT(menu));
- gtk_box_pack_end(GTK_BOX(vbox), button, TRUE, TRUE, 2);
- gtk_widget_show(button);
+ button = gtk_button_new_with_label ("press me");
+ gtk_signal_connect_object (GTK_OBJECT (button), "event",
+ GTK_SIGNAL_FUNC (button_press), GTK_OBJECT (menu));
+ gtk_box_pack_end (GTK_BOX (vbox), button, TRUE, TRUE, 2);
+ gtk_widget_show (button);
/* And finally we append the menu-item to the menu-bar -- this is the
* "root" menu-item I have been raving about =) */
- gtk_menu_bar_append(GTK_MENU_BAR (menu_bar), root_menu);
+ gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), root_menu);
/* always display the window as the last step so it all splashes on
* the screen at once. */
- gtk_widget_show(window);
+ gtk_widget_show (window);
gtk_main ();
- return 0;
+ return(0);
}
/* Respond to a button-press by posting a menu passed in as widget.
@@ -105,12 +106,13 @@ int main (int argc, char *argv[])
* the button that was pressed.
*/
-static gint button_press (GtkWidget *widget, GdkEvent *event)
+static gint button_press( GtkWidget *widget,
+ GdkEvent *event )
{
if (event->type == GDK_BUTTON_PRESS) {
GdkEventButton *bevent = (GdkEventButton *) event;
- gtk_menu_popup (GTK_MENU(widget), NULL, NULL, NULL, NULL,
+ gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL,
bevent->button, bevent->time);
/* Tell calling code that we have handled this event; the buck
* stops here. */
@@ -124,8 +126,8 @@ static gint button_press (GtkWidget *widget, GdkEvent *event)
/* Print a string when a menu item is selected */
-static void menuitem_response (gchar *string)
+static void menuitem_response( gchar *string )
{
- printf("%s\n", string);
+ printf ("%s\n", string);
}
/* example-end */