2000-10-18 15:50:13 +00:00
|
|
|
/* 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
|
2001-05-18 16:28:30 +00:00
|
|
|
gtk_ifactory_cb (gpointer callback_data,
|
|
|
|
guint callback_action,
|
|
|
|
GtkWidget *widget)
|
2000-10-18 15:50:13 +00:00
|
|
|
{
|
2001-05-18 16:28:30 +00:00
|
|
|
g_message ("ItemFactory: activated \"%s\"",
|
|
|
|
gtk_item_factory_path_from_widget (widget));
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GtkItemFactoryEntry menu_items[] =
|
|
|
|
{
|
2001-05-18 16:28:30 +00:00
|
|
|
{ "/_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 },
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2001-05-18 16:28:30 +00:00
|
|
|
{ "/_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" },
|
2000-10-18 15:50:13 +00:00
|
|
|
|
2001-05-18 16:28:30 +00:00
|
|
|
{ "/_Help", NULL, 0, 0, "<LastBranch>" },
|
|
|
|
{ "/Help/_About", NULL, gtk_ifactory_cb, 0 },
|
2000-10-18 15:50:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
|
|
|
|
|
2000-11-18 23:59:30 +00:00
|
|
|
GtkWidget *
|
2000-10-18 15:50:13 +00:00
|
|
|
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);
|
|
|
|
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect (window, "destroy",
|
|
|
|
G_CALLBACK (gtk_widget_destroyed), &window);
|
|
|
|
g_signal_connect (window, "delete-event",
|
|
|
|
G_CALLBACK (gtk_true), NULL);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
accel_group = gtk_accel_group_new ();
|
|
|
|
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
|
2001-10-20 23:39:32 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (window), "<main>",
|
|
|
|
item_factory, (GDestroyNotify) g_object_unref);
|
added gtkaccelmap.sgml. other updates.
Mon Nov 12 23:06:38 2001 Tim Janik <timj@gtk.org>
* added gtkaccelmap.sgml. other updates.
Mon Nov 12 23:08:37 2001 Tim Janik <timj@gtk.org>
* gtk/maketypes.awk: fix type utils generation on unix.
* gtk/gtkaccelmap.[hc]: new files, implementing a global accelerator
registry.
* gtk/gtkaccelgroup.[hc]: major API/implementation revamp:
removed GTK_ACCEL_SIGNAL_VISIBLE, gtk_accel_group_get_default,
gtk_accel_group_get_entry, gtk_accel_group_(un)lock_entry,
gtk_accel_group_add/remove, gtk_accel_group_handle_add/remove,
gtk_accel_group_create_add/remove, gtk_accel_group_entries_from_object.
introduced ::accel_changed signal for change notification, and
gtk_accel_group_connect/disconnect to connect closures to accel groups.
made gtk_accel_group_attach/detach and gtk_accel_group_activate private
functions.
deprecated gtk_accel_group_ref/unref.
* gtk/gtkaccellabel.[hc]: changes to make accellabels pay attention
to accel group changed notification and basically operate on closures.
removed gtk_accel_label_get_accel_object and
gtk_accel_label_set_accel_object.
introduced gtk_accel_label_set_accel_closure, and for convenience,
gtk_accel_label_set_accel_widget.
* gtk/gtkitemfactory.[hc]: removed accelerator propagation code
which mostly moved into gtkaccelmap.[hc].
removed gtk_item_factory_parse_rc*, gtk_item_factory_dump_*
and gtk_item_factory_print_func.
* gtk/gtkmain.c: call _gtk_accel_map_init().
* gtk/gtkmenuitem.[hc]: introduced gtk_menu_item_set_accel_path(),
that associates an accelerator path with menu items, through which
persistent accelerator settings on menu items are enabled.
* gtk/gtkmenu.[hc]: added gtk_menu_set_accel_path() so accelerator
paths of menu item can be default constructed to allow installation
of accelerators on menu items that don't come with an accelerator
binding by default.
* gtk/gtksettings.c: fix STRING type rc settings by special casing
them appropriately in the parser.
* gtk/gtksignal.[hc]: allow a class function offset of 0 for
gtk_signal_newv().
* gtk/gtkwidget.[hc]: accelerator API revamp.
removed ::accelerator_add/remove signals, gtk_widget_accelerator_signal,
gtk_widget_accelerators_locked, gtk_widget_remove_accelerators and
gtk_widget_(un)lock_accelerators.
accelerators maintained through gtk_widget_add/remove_accelerator()
are not runtime changable now, the correct sequence to setup a
widget for runtime changable accelerators is now:
gtk_accel_map_add_entry(accel_path, key, mods);
_gtk_widget_set_accel_path(widget, accel_path, accel_group);
* gtk/gtkwindow.[hc]: accelerator changes, proxy and coalesce accel
group changes (as well as mnemonic changes) through the new signal
::accels_changed.
Sat Nov 10 12:08:56 2001 Tim Janik <timj@gtk.org>
* gtk/gtksettings.c (_gtk_settings_parse_convert): properly handle
GString->string conversions.
2001-11-13 00:53:47 +00:00
|
|
|
gtk_window_add_accel_group (window, accel_group);
|
2000-10-18 15:50:13 +00:00
|
|
|
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
|
|
|
|
*/
|
2001-05-18 16:28:30 +00:00
|
|
|
gtk_check_menu_item_set_active
|
|
|
|
(GTK_CHECK_MENU_ITEM (gtk_item_factory_get_item (item_factory,
|
|
|
|
"/Preferences/Shape/Oval")),
|
|
|
|
TRUE);
|
2000-10-18 15:50:13 +00:00
|
|
|
|
|
|
|
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");
|
fix a typo.
2001-08-07 Havoc Pennington <hp@pobox.com>
* gtk/gtkfilesel.c (open_ref_dir): fix a typo.
* gtk/gtkplug.c (gtk_plug_init): remove setting of auto_shrink;
some fixage is needed here, but nothing simple. Owen understands
it. ;-)
* gtk/gtkwindow.h, gtk/gtkwindow.c: Rework code and API for window
sizing and positioning. Also, fix bug in compute_geometry_hints
(width/height confusion for setting min size).
(gtk_window_move): new function
(gtk_window_resize): new function
(gtk_window_get_size): new function
(gtk_window_get_position): new function
(gtk_window_parse_geometry): new function
* gtk/gtkwidget.c (gtk_widget_set_size_request): new function
(gtk_widget_get_size_request): new function
(gtk_widget_get_usize): delete, that was a short-lived function
;-)
(gtk_widget_set_usize): deprecate
(gtk_widget_set_uposition): deprecate, make it a trivial
gtk_window_move() wrapper
(gtk_widget_class_init): remove x/y/width/height properties,
add width_request height_request
* demos/*: update to avoid deprecated functions
* gtk/gtklayout.c: add x/y child properties
* gtk/gtkfixed.c: add x/y child properties, and get rid of
uses of "gint16"
* tests/testgtk.c (create_window_sizing): lots of tweaks to window
sizing test
* gdk/x11/gdkevents-x11.c (gdk_event_translate): Ensure that
configure events on toplevel windows are always in root window
coordinates, following ICCCM spec that all synthetic events
are in root window coords already, while real events are
in parent window coords. Previously the code assumed that
coords of 0,0 were parent window coords, which was
really broken.
* gtk/gtkcontainer.c (gtk_container_get_focus_chain): fix
warning
* gdk/gdkwindow.h (GdkWindowHints): add GDK_HINT_USER_POS
and GDK_HINT_USER_SIZE so we can set USSize and USPosition
hints in gtk_window_parse_geometry()
* gdk/x11/gdkwindow-x11.c (gdk_window_set_geometry_hints): support
new USER_POS USER_SIZE hints
2001-08-10 03:46:08 +00:00
|
|
|
gtk_widget_set_size_request (label, 200, 200);
|
2000-10-18 15:50:13 +00:00
|
|
|
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");
|
2001-10-20 23:39:32 +00:00
|
|
|
g_signal_connect_swapped (button, "clicked",
|
|
|
|
G_CALLBACK (gtk_widget_destroy), window);
|
2000-10-18 15:50:13 +00:00
|
|
|
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
|
2000-11-18 23:59:30 +00:00
|
|
|
{
|
|
|
|
gtk_widget_destroy (window);
|
|
|
|
window = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window;
|
2000-10-18 15:50:13 +00:00
|
|
|
}
|