Turn off GTK_DISABLE_DEPRECATED, since this test uses the

2003-09-27  Matthias Clasen  <maclas@gmx.de>

	* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
	this test uses the soon-to-be-deprecated GtkItemFactory.

	* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
	remove item_factory.c

	* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
	using GtkUIManager instead of GtkItemFactory.
This commit is contained in:
Matthias Clasen 2003-09-26 23:33:46 +00:00 committed by Matthias Clasen
parent eeed9d1890
commit e4507b6018
9 changed files with 274 additions and 122 deletions

View File

@ -1,5 +1,14 @@
2003-09-27 Matthias Clasen <maclas@gmx.de>
* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
this test uses the soon-to-be-deprecated GtkItemFactory.
* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
remove item_factory.c
* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
using GtkUIManager instead of GtkItemFactory.
* tests/testmerge.c: Demonstrate the use of the
connect-proxy signal.

View File

@ -1,5 +1,14 @@
2003-09-27 Matthias Clasen <maclas@gmx.de>
* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
this test uses the soon-to-be-deprecated GtkItemFactory.
* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
remove item_factory.c
* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
using GtkUIManager instead of GtkItemFactory.
* tests/testmerge.c: Demonstrate the use of the
connect-proxy signal.

View File

@ -1,5 +1,14 @@
2003-09-27 Matthias Clasen <maclas@gmx.de>
* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
this test uses the soon-to-be-deprecated GtkItemFactory.
* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
remove item_factory.c
* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
using GtkUIManager instead of GtkItemFactory.
* tests/testmerge.c: Demonstrate the use of the
connect-proxy signal.

View File

@ -1,5 +1,14 @@
2003-09-27 Matthias Clasen <maclas@gmx.de>
* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
this test uses the soon-to-be-deprecated GtkItemFactory.
* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
remove item_factory.c
* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
using GtkUIManager instead of GtkItemFactory.
* tests/testmerge.c: Demonstrate the use of the
connect-proxy signal.

View File

@ -1,5 +1,14 @@
2003-09-27 Matthias Clasen <maclas@gmx.de>
* tests/testtext.c: Turn off GTK_DISABLE_DEPRECATED, since
this test uses the soon-to-be-deprecated GtkItemFactory.
* demos/gtk-demo/Makefile.am (demos): Add ui_manager.c,
remove item_factory.c
* demos/gtk-demo/ui_manager.c: Duplicate of item_factory.c
using GtkUIManager instead of GtkItemFactory.
* tests/testmerge.c: Demonstrate the use of the
connect-proxy signal.

View File

@ -12,8 +12,8 @@ demos = \
dialog.c \
drawingarea.c \
editable_cells.c \
hypertext.c \
images.c \
item_factory.c \
list_store.c \
menus.c \
panes.c \
@ -22,7 +22,7 @@ demos = \
stock_browser.c \
textview.c \
tree_store.c \
hypertext.c
ui_manager.c
INCLUDES = \
-DDEMOCODEDIR="\"$(democodedir)\"" \

View File

@ -1,120 +0,0 @@
/* Item Factory
*
* The GtkItemFactory object allows the easy creation of menus
* from an array of descriptions of menu items.
*/
#include <gtk/gtk.h>
static void
gtk_ifactory_cb (gpointer callback_data,
guint callback_action,
GtkWidget *widget)
{
g_message ("ItemFactory: activated \"%s\"",
gtk_item_factory_path_from_widget (widget));
}
static GtkItemFactoryEntry menu_items[] =
{
{ "/_File", NULL, 0, 0, "<Branch>" },
{ "/File/tearoff1", NULL, gtk_ifactory_cb, 0, "<Tearoff>" },
{ "/File/_New", "<control>N", gtk_ifactory_cb, 0 },
{ "/File/_Open", "<control>O", gtk_ifactory_cb, 0 },
{ "/File/_Save", "<control>S", gtk_ifactory_cb, 0 },
{ "/File/Save _As...", NULL, gtk_ifactory_cb, 0 },
{ "/File/sep1", NULL, gtk_ifactory_cb, 0, "<Separator>" },
{ "/File/_Quit", "<control>Q", gtk_ifactory_cb, 0 },
{ "/_Preferences", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/_Color", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Color/_Red", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
{ "/_Preferences/Color/_Green", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/Color/_Blue", NULL, gtk_ifactory_cb, 0, "/Preferences/Color/Red" },
{ "/_Preferences/_Shape", NULL, 0, 0, "<Branch>" },
{ "/_Preferences/Shape/_Square", NULL, gtk_ifactory_cb, 0, "<RadioItem>" },
{ "/_Preferences/Shape/_Rectangle", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Square" },
{ "/_Preferences/Shape/_Oval", NULL, gtk_ifactory_cb, 0, "/Preferences/Shape/Rectangle" },
{ "/_Help", NULL, 0, 0, "<LastBranch>" },
{ "/Help/_About", NULL, gtk_ifactory_cb, 0 },
};
static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
GtkWidget *
do_item_factory (void)
{
static GtkWidget *window = NULL;
if (!window)
{
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *separator;
GtkWidget *label;
GtkWidget *button;
GtkAccelGroup *accel_group;
GtkItemFactory *item_factory;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_signal_connect (window, "delete-event",
G_CALLBACK (gtk_true), NULL);
accel_group = gtk_accel_group_new ();
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
g_object_set_data_full (G_OBJECT (window), "<main>",
item_factory, (GDestroyNotify) g_object_unref);
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
gtk_window_set_title (GTK_WINDOW (window), "Item Factory");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
/* preselect /Preferences/Shape/Oval over the other radios
*/
gtk_check_menu_item_set_active
(GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory,
"/Preferences/Shape/Oval")),
TRUE);
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_box_pack_start (GTK_BOX (box1),
gtk_item_factory_get_widget (item_factory, "<main>"),
FALSE, FALSE, 0);
label = gtk_label_new ("Type\n<alt>\nto start");
gtk_widget_set_size_request (label, 200, 200);
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
button = gtk_button_new_with_label ("close");
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show_all (window);
}
else
{
gtk_widget_destroy (window);
window = NULL;
}
return window;
}

225
demos/gtk-demo/ui_manager.c Normal file
View File

@ -0,0 +1,225 @@
/* UI Manager
*
* The GtkUIManager object allows the easy creation of menus
* from an array of actions and a description of the menu hierarchy.
*/
#include <gtk/gtk.h>
static void
activate_action (GtkAction *action)
{
g_message ("Action \"%s\" activated", gtk_action_get_name (action));
}
static GtkActionEntry entries[] = {
{ "FileMenu", NULL, "_File" }, /* name, stock id, label */
{ "PreferencesMenu", NULL, "_Preferences" }, /* name, stock id, label */
{ "ColorMenu", NULL, "_Color" }, /* name, stock id, label */
{ "ShapeMenu", NULL, "_Shape" }, /* name, stock id, label */
{ "HelpMenu", NULL, "_Help" }, /* name, stock id, label */
{ "New", GTK_STOCK_NEW, /* name, stock id */
"_New", "<control>N", /* label, accelerator */
"Create a new file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Open", GTK_STOCK_OPEN, /* name, stock id */
"_Open","<control>O", /* label, accelerator */
"Open a file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Save", GTK_STOCK_SAVE, /* name, stock id */
"_Save","<control>S", /* label, accelerator */
"Save current file", /* tooltip */
G_CALLBACK (activate_action) },
{ "SaveAs", GTK_STOCK_SAVE, /* name, stock id */
"Save _As...", NULL, /* label, accelerator */
"Save to a file", /* tooltip */
G_CALLBACK (activate_action) },
{ "Quit", GTK_STOCK_QUIT, /* name, stock id */
"_Quit", "<control>Q", /* label, accelerator */
"Quit", /* tooltip */
G_CALLBACK (activate_action) },
{ "About", NULL, /* name, stock id */
"_About", "<control>A", /* label, accelerator */
"About", /* tooltip */
G_CALLBACK (activate_action) },
{ "Logo", "demo-gtk-logo", /* name, stock id */
NULL, NULL, /* label, accelerator */
"GTK+", /* tooltip */
G_CALLBACK (activate_action) },
};
static guint n_entries = G_N_ELEMENTS (entries);
static GtkToggleActionEntry toggle_entries[] = {
{ "Bold", GTK_STOCK_BOLD, /* name, stock id */
"_Bold", "<control>B", /* label, accelerator */
"Bold", /* tooltip */
G_CALLBACK (activate_action),
TRUE }, /* is_active */
};
static guint n_toggle_entries = G_N_ELEMENTS (toggle_entries);
enum {
COLOR_RED,
COLOR_GREEN,
COLOR_BLUE
};
static GtkRadioActionEntry color_entries[] = {
{ "Red", NULL, /* name, stock id */
"_Red", "<control>R", /* label, accelerator */
"Blood", COLOR_RED }, /* tooltip, value */
{ "Green", NULL, /* name, stock id */
"_Green", "<control>G", /* label, accelerator */
"Grass", COLOR_GREEN }, /* tooltip, value */
{ "Blue", NULL, /* name, stock id */
"_Blue", "<control>B", /* label, accelerator */
"Sky", COLOR_BLUE }, /* tooltip, value */
};
static guint n_color_entries = G_N_ELEMENTS (color_entries);
enum {
SHAPE_SQUARE,
SHAPE_RECTANGLE,
SHAPE_OVAL,
};
static GtkRadioActionEntry shape_entries[] = {
{ "Square", NULL, /* name, stock id */
"_Square", "<control>S", /* label, accelerator */
"Square", SHAPE_SQUARE }, /* tooltip, value */
{ "Rectangle", NULL, /* name, stock id */
"_Rectangle", "<control>R", /* label, accelerator */
"Rectangle", SHAPE_RECTANGLE }, /* tooltip, value */
{ "Oval", NULL, /* name, stock id */
"_Oval", "<control>O", /* label, accelerator */
"Egg", SHAPE_OVAL }, /* tooltip, value */
};
static guint n_shape_entries = G_N_ELEMENTS (shape_entries);
static const gchar *ui_info =
"<ui>"
" <menubar name='MenuBar'>"
" <menu action='FileMenu'>"
" <menuitem action='New'/>"
" <menuitem action='Open'/>"
" <menuitem action='Save'/>"
" <menuitem action='SaveAs'/>"
" <separator/>"
" <menuitem action='Quit'/>"
" </menu>"
" <menu action='PreferencesMenu'>"
" <menu action='ColorMenu'>"
" <menuitem action='Red'/>"
" <menuitem action='Green'/>"
" <menuitem action='Blue'/>"
" </menu>"
" <menu action='ShapeMenu'>"
" <menuitem action='Square'/>"
" <menuitem action='Rectangle'/>"
" <menuitem action='Oval'/>"
" </menu>"
" <menuitem action='Bold'/>"
" </menu>"
" <menu action='HelpMenu'>"
" <menuitem action='About'/>"
" </menu>"
" </menubar>"
" <toolbar name='ToolBar'>"
" <toolitem action='Open'/>"
" <toolitem action='Quit'/>"
" <separator action='Sep1'/>"
" <toolitem action='Logo'/>"
" </toolbar>"
"</ui>";
GtkWidget *
do_ui_manager (void)
{
static GtkWidget *window = NULL;
if (!window)
{
GtkWidget *box1;
GtkWidget *box2;
GtkWidget *separator;
GtkWidget *label;
GtkWidget *button;
GtkUIManager *ui;
GtkActionGroup *actions;
GError *error = NULL;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_widget_destroyed), &window);
g_signal_connect (window, "delete-event",
G_CALLBACK (gtk_true), NULL);
actions = gtk_action_group_new ("Actions");
gtk_action_group_add_actions (actions, entries, n_entries, NULL);
gtk_action_group_add_toggle_actions (actions,
toggle_entries, n_toggle_entries,
NULL);
gtk_action_group_add_radio_actions (actions,
color_entries, n_color_entries,
COLOR_RED,
G_CALLBACK (activate_action),
NULL);
gtk_action_group_add_radio_actions (actions,
shape_entries, n_shape_entries,
SHAPE_OVAL,
G_CALLBACK (activate_action),
NULL);
ui = gtk_ui_manager_new ();
gtk_ui_manager_insert_action_group (ui, actions, 0);
gtk_window_add_accel_group (GTK_WINDOW (window),
gtk_ui_manager_get_accel_group (ui));
gtk_window_set_title (GTK_WINDOW (window), "UI Manager");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
if (!gtk_ui_manager_add_ui_from_string (ui, ui_info, -1, &error))
{
g_message ("building menus failed: %s", error->message);
g_error_free (error);
}
box1 = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box1);
gtk_box_pack_start (GTK_BOX (box1),
gtk_ui_manager_get_widget (ui, "/MenuBar"),
FALSE, FALSE, 0);
label = gtk_label_new ("Type\n<alt>\nto start");
gtk_widget_set_size_request (label, 200, 200);
gtk_misc_set_alignment (GTK_MISC (label), 0.5, 0.5);
gtk_box_pack_start (GTK_BOX (box1), label, TRUE, TRUE, 0);
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_set_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
button = gtk_button_new_with_label ("close");
g_signal_connect_swapped (button, "clicked",
G_CALLBACK (gtk_widget_destroy), window);
gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
gtk_widget_grab_default (button);
gtk_widget_show_all (window);
}
else
{
gtk_widget_destroy (window);
window = NULL;
}
return window;
}

View File

@ -4,6 +4,8 @@
#include <stdlib.h>
#include <string.h>
#undef GTK_DISABLE_DEPRECATED
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>