1999-02-01 14:47:05 +00:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <strings.h>
|
|
|
|
|
|
|
|
/* Obligatory basic callback */
|
1999-11-13 23:06:46 +00:00
|
|
|
static void print_hello( GtkWidget *w,
|
|
|
|
gpointer data )
|
|
|
|
{
|
|
|
|
g_message ("Hello, World!\n");
|
1999-02-01 14:47:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 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 -> "<Item>"
|
|
|
|
"" -> "<Item>"
|
|
|
|
"<Title>" -> 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
|
1999-11-13 23:06:46 +00:00
|
|
|
"<Branch>" -> create an item to hold sub items (optional)
|
1999-02-01 14:47:05 +00:00
|
|
|
"<LastBranch>" -> create a right justified branch
|
|
|
|
*/
|
|
|
|
|
|
|
|
static GtkItemFactoryEntry menu_items[] = {
|
1999-11-13 23:06:46 +00:00
|
|
|
{ "/_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 },
|
1999-02-01 14:47:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
void get_main_menu( GtkWidget *window,
|
|
|
|
GtkWidget **menubar )
|
|
|
|
{
|
1999-02-01 14:47:05 +00:00
|
|
|
GtkItemFactory *item_factory;
|
|
|
|
GtkAccelGroup *accel_group;
|
1999-11-13 23:06:46 +00:00
|
|
|
gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
accel_group = gtk_accel_group_new ();
|
1999-02-01 14:47:05 +00:00
|
|
|
|
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
|
1999-02-01 14:47:05 +00:00
|
|
|
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. */
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
|
|
|
/* Attach the new accelerator group to the window. */
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
|
|
|
if (menubar)
|
|
|
|
/* Finally, return the actual menu bar created by the item factory. */
|
1999-11-13 23:06:46 +00:00
|
|
|
*menubar = gtk_item_factory_get_widget (item_factory, "<main>");
|
1999-02-01 14:47:05 +00:00
|
|
|
}
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
int main( int argc,
|
|
|
|
char *argv[] )
|
|
|
|
{
|
1999-02-01 14:47:05 +00:00
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *main_vbox;
|
|
|
|
GtkWidget *menubar;
|
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_init (&argc, &argv);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2002-02-16 23:52:30 +00:00
|
|
|
g_signal_connect (GTK_OBJECT (window), "destroy",
|
1999-11-13 23:06:46 +00:00
|
|
|
GTK_SIGNAL_FUNC (gtk_main_quit),
|
|
|
|
"WM destroy");
|
|
|
|
gtk_window_set_title (GTK_WINDOW(window), "Item Factory");
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_widget_set_size_request (GTK_WIDGET (window), 300, 200);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
main_vbox = gtk_vbox_new (FALSE, 1);
|
2002-02-16 23:52:30 +00:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 1);
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), main_vbox);
|
|
|
|
gtk_widget_show (main_vbox);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
get_main_menu (window, &menubar);
|
|
|
|
gtk_box_pack_start (GTK_BOX (main_vbox), menubar, FALSE, TRUE, 0);
|
|
|
|
gtk_widget_show (menubar);
|
1999-02-01 14:47:05 +00:00
|
|
|
|
1999-11-13 23:06:46 +00:00
|
|
|
gtk_widget_show (window);
|
|
|
|
gtk_main ();
|
1999-02-01 14:47:05 +00:00
|
|
|
|
2002-02-16 23:52:30 +00:00
|
|
|
return 0;
|
1999-02-01 14:47:05 +00:00
|
|
|
}
|