From 1183c0ea697c34888cc68d3f8c01087fcb8cf923 Mon Sep 17 00:00:00 2001 From: Tim Janik Date: Wed, 10 Feb 1999 16:37:09 +0000 Subject: [PATCH] applied patch from Paolo Molaro to fix GTK_TYPE_POINTER args of Wed Feb 10 15:49:16 1999 Tim Janik * gtk/gtkwindow.c (gtk_window_class_init): * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and ::set_focus signals. * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups to the item factory example. --- ChangeLog | 11 +- ChangeLog.pre-2-0 | 11 +- ChangeLog.pre-2-10 | 11 +- ChangeLog.pre-2-2 | 11 +- ChangeLog.pre-2-4 | 11 +- ChangeLog.pre-2-6 | 11 +- ChangeLog.pre-2-8 | 11 +- docs/gtk_tut.sgml | 220 +++++++++++++++++++------------------ docs/tutorial/gtk_tut.sgml | 220 +++++++++++++++++++------------------ gtk/gtkctree.c | 2 +- gtk/gtkwindow.c | 2 +- 11 files changed, 298 insertions(+), 223 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-0 b/ChangeLog.pre-2-0 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-0 +++ b/ChangeLog.pre-2-0 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-2 b/ChangeLog.pre-2-2 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-2 +++ b/ChangeLog.pre-2-2 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-4 b/ChangeLog.pre-2-4 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-4 +++ b/ChangeLog.pre-2-4 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-6 b/ChangeLog.pre-2-6 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-6 +++ b/ChangeLog.pre-2-6 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index 8e603a7fd4..a011b0db6a 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,13 @@ +Wed Feb 10 15:49:16 1999 Tim Janik + + * gtk/gtkwindow.c (gtk_window_class_init): + * gtk/gtkctree.c (gtk_ctree_class_init): applied patch from Paolo + Molaro to fix GTK_TYPE_POINTER args of ::tree_collapse and + ::set_focus signals. + + * docs/gtk_tut.sgml: s/menufactory/itemfactory, minor fixups + to the item factory example. + Wed Feb 10 11:05:53 1999 Owen Taylor * gtk/gtkdnd.c: Reverted coding style "fixups" @@ -130,7 +140,6 @@ Mon Feb 8 12:50:06 GMT 1999 Tony Gale * Makefile.am: update to include the latest Tutorial examples. ->>>>>>> 1.1009 Sat Feb 6 11:20:16 1999 Owen Taylor * gtk/gtkwidget.c (gtk_widget_idle_draw): Add the diff --git a/docs/gtk_tut.sgml b/docs/gtk_tut.sgml index 656334f65b..e8879bd4a2 100644 --- a/docs/gtk_tut.sgml +++ b/docs/gtk_tut.sgml @@ -9154,7 +9154,7 @@ disadvantages to each approach. The itemfactory is much easier to use, and to add new menus to, although writing a few wrapper functions to create menus using the manual method could go a long way towards usability. With the -menufactory, it is not possible to add images or the character '/' to +itemfactory, it is not possible to add images or the character '/' to the menus. @@ -9181,7 +9181,7 @@ menubars. This first function is used to create a new menubar. -GtkWidget *gtk_menu_bar_new( void ); +GtkWidget* gtk_menu_bar_new (void); @@ -9190,7 +9190,7 @@ gtk_container_add to pack this into a window, or the box_pack functions to pack it into a box - the same as buttons. -GtkWidget *gtk_menu_new( void ); +GtkWidget* gtk_menu_new (void); This function returns a pointer to a new menu, it is never actually @@ -9202,13 +9202,13 @@ The next two calls are used to create menu items that are packed into the menu (and menubar). -GtkWidget *gtk_menu_item_new( void ); +GtkWidget* gtk_menu_item_new (void); and -GtkWidget *gtk_menu_item_new_with_label( const char *label ); +GtkWidget* gtk_menu_item_new_with_label (const char *label); These calls are used to create the menu items that are to be @@ -9230,35 +9230,35 @@ standard - file_menu = gtk_menu_new(); /* Don't need to show menus */ + file_menu = gtk_menu_new (); /* Don't need to show menus */ /* Create the menu items */ - open_item = gtk_menu_item_new_with_label("Open"); - save_item = gtk_menu_item_new_with_label("Save"); - quit_item = gtk_menu_item_new_with_label("Quit"); + open_item = gtk_menu_item_new_with_label ("Open"); + save_item = gtk_menu_item_new_with_label ("Save"); + quit_item = gtk_menu_item_new_with_label ("Quit"); /* Add them to the menu */ - gtk_menu_append( GTK_MENU(file_menu), open_item); - gtk_menu_append( GTK_MENU(file_menu), save_item); - gtk_menu_append( GTK_MENU(file_menu), quit_item); + gtk_menu_append (GTK_MENU (file_menu), open_item); + gtk_menu_append (GTK_MENU (file_menu), save_item); + gtk_menu_append (GTK_MENU (file_menu), quit_item); /* Attach the callback functions to the activate signal */ - gtk_signal_connect_object( GTK_OBJECT(open_items), "activate", - GTK_SIGNAL_FUNC(menuitem_response), + gtk_signal_connect_object (GTK_OBJECT (open_items), "activate", + GTK_SIGNAL_FUNC (menuitem_response), (gpointer) "file.open"); - gtk_signal_connect_object( GTK_OBJECT(save_items), "activate", - GTK_SIGNAL_FUNC(menuitem_response), + gtk_signal_connect_object (GTK_OBJECT (save_items), "activate", + GTK_SIGNAL_FUNC (menuitem_response), (gpointer) "file.save"); /* We can attach the Quit menu item to our exit function */ - gtk_signal_connect_object( GTK_OBJECT(quit_items), "activate", - GTK_SIGNAL_FUNC(destroy), + gtk_signal_connect_object (GTK_OBJECT (quit_items), "activate", + GTK_SIGNAL_FUNC (destroy), (gpointer) "file.quit"); /* We do need to show menu items */ - gtk_widget_show( open_item ); - gtk_widget_show( save_item ); - gtk_widget_show( quit_item ); + gtk_widget_show (open_item); + gtk_widget_show (save_item); + gtk_widget_show (quit_item); At this point we have our menu. Now we need to create a menubar and a @@ -9266,39 +9266,39 @@ menu item for the - menu_bar = gtk_menu_bar_new(); - gtk_container_add( GTK_CONTAINER(window), menu_bar); - gtk_widget_show( menu_bar ); + menu_bar = gtk_menu_bar_new (); + gtk_container_add (GTK_CONTAINER (window), menu_bar); + gtk_widget_show (menu_bar); - file_item = gtk_menu_item_new_with_label("File"); - gtk_widget_show(file_item); + file_item = gtk_menu_item_new_with_label ("File"); + gtk_widget_show (file_item); Now we need to associate the menu with -void gtk_menu_item_set_submenu( GtkMenuItem *menu_item, - GtkWidget *submenu ); +void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, + GtkWidget *submenu); So, our example would continue with - gtk_menu_item_set_submenu( GTK_MENU_ITEM(file_item), file_menu ); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item), file_menu); All that is left to do is to add the menu to the menubar, which is accomplished using the function -void gtk_menu_bar_append( GtkMenuBar *menu_bar, GtkWidget *menu_item); +void gtk_menu_bar_append (GtkMenuBar *menu_bar, GtkWidget *menu_item); which in our case looks like this: - gtk_menu_bar_append( GTK_MENU_BAR (menu_bar), file_item ); + gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), file_item); If we wanted the menu right justified on the menubar, such as help @@ -9307,7 +9307,7 @@ menus often are, we can use the following function (again on menubar. -void gtk_menu_item_right_justify( GtkMenuItem *menu_item ); +void gtk_menu_item_right_justify (GtkMenuItem *menu_item); Here is a summary of the steps needed to create a menu bar with menus @@ -9325,7 +9325,7 @@ itself. menu item (the one created in the above step). Create a new menubar using gtk_menu_bar_new. This step only needs to be done once when creating a series of menus on one menu bar. - Use gtk_menu_bar_append to put the root menu onto the menubar. + Use gtk_menu_bar_append() to put the root menu onto the menubar. Creating a popup menu is nearly the same. The difference is that the @@ -9337,8 +9337,8 @@ example. Take these steps: Create an event handling function. It needs to have the prototype -static gint handler( GtkWidget *widget, - GdkEvent *event ); +static gint handler (GtkWidget *widget, + GdkEvent *event); and it will use the event to find out where to pop up the menu. In the event handler, if the event is a mouse button press, @@ -9346,9 +9346,9 @@ treat event as a button event (which it is) and use it as shown in the sample code to pass information to gtk_menu_popup(). Bind that event handler to a widget with - gtk_signal_connect_object(GTK_OBJECT(widget), "event", - GTK_SIGNAL_FUNC (handler), - GTK_OBJECT(menu)); + gtk_signal_connect_object (GTK_OBJECT (widget), "event", + GTK_SIGNAL_FUNC (handler), + GTK_OBJECT (menu)); where widget is the widget you are binding to, handler is the handling function, and menu is a menu @@ -9385,17 +9385,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 @@ -9403,60 +9403,60 @@ 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 (); @@ -9474,7 +9474,7 @@ 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. */ @@ -9490,7 +9490,7 @@ static gint button_press (GtkWidget *widget, GdkEvent *event) static void menuitem_response (gchar *string) { - printf("%s\n", string); + printf ("%s\n", string); } /* example-end */ @@ -9516,8 +9516,10 @@ Here is an example using the GTK item factory. #include /* 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. @@ -9539,31 +9541,33 @@ static void print_hello(GtkWidget *w, gpointer data) { "" -> create a radio item -> path of a radio item to link against "" -> create a separator - "" -> create an item to hold sub items + "" -> create an item to hold sub items (optional) "" -> create a right justified branch */ static GtkItemFactoryEntry menu_items[] = { - {"/_File", NULL, NULL, 0, ""}, - {"/File/_New", "N", print_hello, 0, NULL}, - {"/File/_Open", "O", print_hello, 0, NULL}, - {"/File/_Save", "S", print_hello, 0, NULL}, - {"/File/Save _As", NULL, NULL, 0, NULL}, - {"/File/sep1", NULL, NULL, 0, ""}, - {"/File/Quit", "Q", gtk_main_quit, 0, NULL}, - {"/_Options", NULL, NULL, 0, ""}, - {"/Options/Test", NULL, NULL, 0, NULL}, - {"/_Help", NULL, NULL, 0, ""}, - {"/_Help/About", NULL, NULL, 0, NULL}, + { "/_File", NULL, NULL, 0, "" }, + { "/File/_New", "N", print_hello, 0, NULL }, + { "/File/_Open", "O", print_hello, 0, NULL }, + { "/File/_Save", "S", print_hello, 0, NULL }, + { "/File/Save _As", NULL, NULL, 0, NULL }, + { "/File/sep1", NULL, NULL, 0, "" }, + { "/File/Quit", "Q", gtk_main_quit, 0, NULL }, + { "/_Options", NULL, NULL, 0, "" }, + { "/Options/Test", NULL, NULL, 0, NULL }, + { "/_Help", NULL, NULL, 0, "" }, + { "/_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, @@ -9573,49 +9577,51 @@ void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { the accelerator table while generating menus. */ - item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "
", + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", 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)); if (menubar) /* Finally, return the actual menu bar created by the item factory. */ - *menubar = gtk_item_factory_get_widget(item_factory, "
"); + *menubar = gtk_item_factory_get_widget (item_factory, "
"); } -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); + return 0; } /* example-end */ diff --git a/docs/tutorial/gtk_tut.sgml b/docs/tutorial/gtk_tut.sgml index 656334f65b..e8879bd4a2 100644 --- a/docs/tutorial/gtk_tut.sgml +++ b/docs/tutorial/gtk_tut.sgml @@ -9154,7 +9154,7 @@ disadvantages to each approach. The itemfactory is much easier to use, and to add new menus to, although writing a few wrapper functions to create menus using the manual method could go a long way towards usability. With the -menufactory, it is not possible to add images or the character '/' to +itemfactory, it is not possible to add images or the character '/' to the menus. @@ -9181,7 +9181,7 @@ menubars. This first function is used to create a new menubar. -GtkWidget *gtk_menu_bar_new( void ); +GtkWidget* gtk_menu_bar_new (void); @@ -9190,7 +9190,7 @@ gtk_container_add to pack this into a window, or the box_pack functions to pack it into a box - the same as buttons. -GtkWidget *gtk_menu_new( void ); +GtkWidget* gtk_menu_new (void); This function returns a pointer to a new menu, it is never actually @@ -9202,13 +9202,13 @@ The next two calls are used to create menu items that are packed into the menu (and menubar). -GtkWidget *gtk_menu_item_new( void ); +GtkWidget* gtk_menu_item_new (void); and -GtkWidget *gtk_menu_item_new_with_label( const char *label ); +GtkWidget* gtk_menu_item_new_with_label (const char *label); These calls are used to create the menu items that are to be @@ -9230,35 +9230,35 @@ standard - file_menu = gtk_menu_new(); /* Don't need to show menus */ + file_menu = gtk_menu_new (); /* Don't need to show menus */ /* Create the menu items */ - open_item = gtk_menu_item_new_with_label("Open"); - save_item = gtk_menu_item_new_with_label("Save"); - quit_item = gtk_menu_item_new_with_label("Quit"); + open_item = gtk_menu_item_new_with_label ("Open"); + save_item = gtk_menu_item_new_with_label ("Save"); + quit_item = gtk_menu_item_new_with_label ("Quit"); /* Add them to the menu */ - gtk_menu_append( GTK_MENU(file_menu), open_item); - gtk_menu_append( GTK_MENU(file_menu), save_item); - gtk_menu_append( GTK_MENU(file_menu), quit_item); + gtk_menu_append (GTK_MENU (file_menu), open_item); + gtk_menu_append (GTK_MENU (file_menu), save_item); + gtk_menu_append (GTK_MENU (file_menu), quit_item); /* Attach the callback functions to the activate signal */ - gtk_signal_connect_object( GTK_OBJECT(open_items), "activate", - GTK_SIGNAL_FUNC(menuitem_response), + gtk_signal_connect_object (GTK_OBJECT (open_items), "activate", + GTK_SIGNAL_FUNC (menuitem_response), (gpointer) "file.open"); - gtk_signal_connect_object( GTK_OBJECT(save_items), "activate", - GTK_SIGNAL_FUNC(menuitem_response), + gtk_signal_connect_object (GTK_OBJECT (save_items), "activate", + GTK_SIGNAL_FUNC (menuitem_response), (gpointer) "file.save"); /* We can attach the Quit menu item to our exit function */ - gtk_signal_connect_object( GTK_OBJECT(quit_items), "activate", - GTK_SIGNAL_FUNC(destroy), + gtk_signal_connect_object (GTK_OBJECT (quit_items), "activate", + GTK_SIGNAL_FUNC (destroy), (gpointer) "file.quit"); /* We do need to show menu items */ - gtk_widget_show( open_item ); - gtk_widget_show( save_item ); - gtk_widget_show( quit_item ); + gtk_widget_show (open_item); + gtk_widget_show (save_item); + gtk_widget_show (quit_item); At this point we have our menu. Now we need to create a menubar and a @@ -9266,39 +9266,39 @@ menu item for the - menu_bar = gtk_menu_bar_new(); - gtk_container_add( GTK_CONTAINER(window), menu_bar); - gtk_widget_show( menu_bar ); + menu_bar = gtk_menu_bar_new (); + gtk_container_add (GTK_CONTAINER (window), menu_bar); + gtk_widget_show (menu_bar); - file_item = gtk_menu_item_new_with_label("File"); - gtk_widget_show(file_item); + file_item = gtk_menu_item_new_with_label ("File"); + gtk_widget_show (file_item); Now we need to associate the menu with -void gtk_menu_item_set_submenu( GtkMenuItem *menu_item, - GtkWidget *submenu ); +void gtk_menu_item_set_submenu (GtkMenuItem *menu_item, + GtkWidget *submenu); So, our example would continue with - gtk_menu_item_set_submenu( GTK_MENU_ITEM(file_item), file_menu ); + gtk_menu_item_set_submenu (GTK_MENU_ITEM (file_item), file_menu); All that is left to do is to add the menu to the menubar, which is accomplished using the function -void gtk_menu_bar_append( GtkMenuBar *menu_bar, GtkWidget *menu_item); +void gtk_menu_bar_append (GtkMenuBar *menu_bar, GtkWidget *menu_item); which in our case looks like this: - gtk_menu_bar_append( GTK_MENU_BAR (menu_bar), file_item ); + gtk_menu_bar_append (GTK_MENU_BAR (menu_bar), file_item); If we wanted the menu right justified on the menubar, such as help @@ -9307,7 +9307,7 @@ menus often are, we can use the following function (again on menubar. -void gtk_menu_item_right_justify( GtkMenuItem *menu_item ); +void gtk_menu_item_right_justify (GtkMenuItem *menu_item); Here is a summary of the steps needed to create a menu bar with menus @@ -9325,7 +9325,7 @@ itself. menu item (the one created in the above step). Create a new menubar using gtk_menu_bar_new. This step only needs to be done once when creating a series of menus on one menu bar. - Use gtk_menu_bar_append to put the root menu onto the menubar. + Use gtk_menu_bar_append() to put the root menu onto the menubar. Creating a popup menu is nearly the same. The difference is that the @@ -9337,8 +9337,8 @@ example. Take these steps: Create an event handling function. It needs to have the prototype -static gint handler( GtkWidget *widget, - GdkEvent *event ); +static gint handler (GtkWidget *widget, + GdkEvent *event); and it will use the event to find out where to pop up the menu. In the event handler, if the event is a mouse button press, @@ -9346,9 +9346,9 @@ treat event as a button event (which it is) and use it as shown in the sample code to pass information to gtk_menu_popup(). Bind that event handler to a widget with - gtk_signal_connect_object(GTK_OBJECT(widget), "event", - GTK_SIGNAL_FUNC (handler), - GTK_OBJECT(menu)); + gtk_signal_connect_object (GTK_OBJECT (widget), "event", + GTK_SIGNAL_FUNC (handler), + GTK_OBJECT (menu)); where widget is the widget you are binding to, handler is the handling function, and menu is a menu @@ -9385,17 +9385,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 @@ -9403,60 +9403,60 @@ 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 (); @@ -9474,7 +9474,7 @@ 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. */ @@ -9490,7 +9490,7 @@ static gint button_press (GtkWidget *widget, GdkEvent *event) static void menuitem_response (gchar *string) { - printf("%s\n", string); + printf ("%s\n", string); } /* example-end */ @@ -9516,8 +9516,10 @@ Here is an example using the GTK item factory. #include /* 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. @@ -9539,31 +9541,33 @@ static void print_hello(GtkWidget *w, gpointer data) { "" -> create a radio item -> path of a radio item to link against "" -> create a separator - "" -> create an item to hold sub items + "" -> create an item to hold sub items (optional) "" -> create a right justified branch */ static GtkItemFactoryEntry menu_items[] = { - {"/_File", NULL, NULL, 0, ""}, - {"/File/_New", "N", print_hello, 0, NULL}, - {"/File/_Open", "O", print_hello, 0, NULL}, - {"/File/_Save", "S", print_hello, 0, NULL}, - {"/File/Save _As", NULL, NULL, 0, NULL}, - {"/File/sep1", NULL, NULL, 0, ""}, - {"/File/Quit", "Q", gtk_main_quit, 0, NULL}, - {"/_Options", NULL, NULL, 0, ""}, - {"/Options/Test", NULL, NULL, 0, NULL}, - {"/_Help", NULL, NULL, 0, ""}, - {"/_Help/About", NULL, NULL, 0, NULL}, + { "/_File", NULL, NULL, 0, "" }, + { "/File/_New", "N", print_hello, 0, NULL }, + { "/File/_Open", "O", print_hello, 0, NULL }, + { "/File/_Save", "S", print_hello, 0, NULL }, + { "/File/Save _As", NULL, NULL, 0, NULL }, + { "/File/sep1", NULL, NULL, 0, "" }, + { "/File/Quit", "Q", gtk_main_quit, 0, NULL }, + { "/_Options", NULL, NULL, 0, "" }, + { "/Options/Test", NULL, NULL, 0, NULL }, + { "/_Help", NULL, NULL, 0, "" }, + { "/_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, @@ -9573,49 +9577,51 @@ void get_main_menu(GtkWidget *window, GtkWidget ** menubar) { the accelerator table while generating menus. */ - item_factory = gtk_item_factory_new(GTK_TYPE_MENU_BAR, "
", + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", 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)); if (menubar) /* Finally, return the actual menu bar created by the item factory. */ - *menubar = gtk_item_factory_get_widget(item_factory, "
"); + *menubar = gtk_item_factory_get_widget (item_factory, "
"); } -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); + return 0; } /* example-end */ diff --git a/gtk/gtkctree.c b/gtk/gtkctree.c index e97893d2b0..c8ddf7a135 100644 --- a/gtk/gtkctree.c +++ b/gtk/gtkctree.c @@ -403,7 +403,7 @@ gtk_ctree_class_init (GtkCTreeClass *klass) object_class->type, GTK_SIGNAL_OFFSET (GtkCTreeClass, tree_collapse), gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, GTK_TYPE_POINTER); + GTK_TYPE_NONE, 1, GTK_TYPE_CTREE_NODE); ctree_signals[TREE_MOVE] = gtk_signal_new ("tree_move", GTK_RUN_LAST, diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c index 8715ff1aee..706783c29a 100644 --- a/gtk/gtkwindow.c +++ b/gtk/gtkwindow.c @@ -171,7 +171,7 @@ gtk_window_class_init (GtkWindowClass *klass) GTK_SIGNAL_OFFSET (GtkWindowClass, set_focus), gtk_marshal_NONE__POINTER, GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); + GTK_TYPE_WIDGET); gtk_object_class_add_signals (object_class, window_signals, LAST_SIGNAL);