summaryrefslogtreecommitdiff
path: root/tests/testgtk.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>1998-08-12 16:49:13 +0000
committerOwen Taylor <otaylor@src.gnome.org>1998-08-12 16:49:13 +0000
commit4af7480f8f64bd7709500bc27af91e2243898969 (patch)
tree1045a3d1e843fdbb3a0390ee591e9d84257ec8ee /tests/testgtk.c
parent5d270c2f450000cea208443142e7284c23e7af9d (diff)
downloadgtk+-4af7480f8f64bd7709500bc27af91e2243898969.tar.gz
Added gdk_text/string_extents() - too calculate all the metrics at once of
Tue Jul 21 12:42:01 1998 Owen Taylor <otaylor@redhat.com> * gdk/gdk.h gdk/gdkfont.c: Added gdk_text/string_extents() - too calculate all the metrics at once of a string, including things which weren't calculated before. * gtk/Makefile.am gtk/gtk.h gtk/gtktearoffmenu.[ch]: New MenuItem type, that when put as the first thing in a menu, makes the menu tearoff. Currently drawn as a dashed line. * gtk/gtkmenuitem.h gtk/gtkcheckmenuitem.c: Added a flag "hide_on_activate" to the MenuItem class structure to allow check and radio buttons to be changed with <Space> without hiding the menu. * gtk/gtkaccellabel.[ch]: Added new capabilities to set a underline_group and underline_mods for the label - accelerators added in the underline group matching underline_mods will be displayed as an underline character. This doesn't work - Save As needs to be underlined as Save _As. * gtk/gtkitemfactory.c: - Create a AccelGroup for each MenuShell we create. - If an '&' appears before a character 'c' in the path, then make 'c' an accelerator in the menu's accel group, and if the menuitem is menubar <alt>C an accelerator in the itemfactory's accel group. * gtk/gtklabel.[ch]: Add support for a pattern arg - which is a string. If an '_' appears in this string, the corresponding position in the label is underlined. Add gtk_label_parse_uline() convenience function which takes a string with embedded underlines, sets the pattern and label, and returns the accelerator keyval. * gtk/gtkmenu.[ch]: Make menus no longer a toplevel widget. Instead, they create a GtkWindow and add themselves to that. (When torn off, another new feature, they create another GtkWindow to hold the torn off menu) New function gtk_menu_set_tearoff_state() * gtk/gtkenums.h gtk/gtkmenushell.[ch] gtk/gtkenums.h: Added action signals for keyboard navigation of menus. * gtk/gtkmenushell.c: Key press handler which activates bindings for navigation, and accelerators, for handling underline accelerators. Exported functions to select and activate menu items in a menushell. * gtk/testgtk.c: Added a new "Item Factory" test which tests GtkItemFactory and the new keyboard navigation of menus.
Diffstat (limited to 'tests/testgtk.c')
-rw-r--r--tests/testgtk.c120
1 files changed, 112 insertions, 8 deletions
diff --git a/tests/testgtk.c b/tests/testgtk.c
index dec2fa2d9b..6962c27a29 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -1949,7 +1949,7 @@ create_tooltips (void)
*/
static GtkWidget*
-create_menu (int depth)
+create_menu (gint depth, gboolean tearoff)
{
GtkWidget *menu;
GtkWidget *menuitem;
@@ -1963,6 +1963,13 @@ create_menu (int depth)
menu = gtk_menu_new ();
group = NULL;
+ if (tearoff)
+ {
+ menuitem = gtk_tearoff_menu_item_new ();
+ gtk_menu_append (GTK_MENU (menu), menuitem);
+ gtk_widget_show (menuitem);
+ }
+
for (i = 0, j = 1; i < 5; i++, j++)
{
sprintf (buf, "item %2d - %d", depth, j);
@@ -1975,7 +1982,7 @@ create_menu (int depth)
if (i == 3)
gtk_widget_set_sensitive (menuitem, FALSE);
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1));
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (depth - 1, TRUE));
}
return menu;
@@ -2007,6 +2014,9 @@ create_menus (void)
GTK_SIGNAL_FUNC (gtk_true),
NULL);
+ accel_group = gtk_accel_group_new ();
+ gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
+
gtk_window_set_title (GTK_WINDOW (window), "menus");
gtk_container_border_width (GTK_CONTAINER (window), 0);
@@ -2019,7 +2029,7 @@ create_menus (void)
gtk_box_pack_start (GTK_BOX (box1), menubar, FALSE, TRUE, 0);
gtk_widget_show (menubar);
- menu = create_menu (2);
+ menu = create_menu (2, TRUE);
menuitem = gtk_menu_item_new_with_label ("test\nline2");
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), menu);
@@ -2027,12 +2037,12 @@ create_menus (void)
gtk_widget_show (menuitem);
menuitem = gtk_menu_item_new_with_label ("foo");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3));
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (3, TRUE));
gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
gtk_widget_show (menuitem);
-
+
menuitem = gtk_menu_item_new_with_label ("bar");
- gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4));
+ gtk_menu_item_set_submenu (GTK_MENU_ITEM (menuitem), create_menu (4, TRUE));
gtk_menu_item_right_justify (GTK_MENU_ITEM (menuitem));
gtk_menu_bar_append (GTK_MENU_BAR (menubar), menuitem);
gtk_widget_show (menuitem);
@@ -2042,8 +2052,7 @@ create_menus (void)
gtk_box_pack_start (GTK_BOX (box1), box2, TRUE, TRUE, 0);
gtk_widget_show (box2);
- menu = create_menu (1);
- accel_group = gtk_accel_group_get_default ();
+ menu = create_menu (1, FALSE);
gtk_menu_set_accel_group (GTK_MENU (menu), accel_group);
menuitem = gtk_check_menu_item_new_with_label ("Accelerate Me");
@@ -2112,6 +2121,99 @@ create_menus (void)
gtk_widget_destroy (window);
}
+static GtkItemFactoryEntry menu_items[] =
+{
+ { "/_File", NULL, NULL, 0, "<Branch>" },
+ { "/File/tearoff1", NULL, NULL, 0, "<Tearoff>" },
+ { "/File/_New", "<control>N", NULL, 0 },
+ { "/File/_Open", "<control>O", NULL, 0 },
+ { "/File/_Save", "<control>S", NULL, 0 },
+ { "/File/Save _As...", NULL, NULL, 0 },
+ { "/File/sep1", NULL, NULL, 0, "<Separator>" },
+ { "/File/_Quit", "<control>Q", NULL, 0 },
+
+ { "/_Preferences", NULL, NULL, 0, "<Branch>" },
+ { "/_Preferences/_Color", NULL, NULL, 0, "<Branch>" },
+ { "/_Preferences/Color/_Red", NULL, NULL, 0, "<RadioItem>" },
+ { "/_Preferences/Color/_Green", NULL, NULL, 0, "<RadioItem>" },
+ { "/_Preferences/Color/_Blue", NULL, NULL, 0, "<RadioItem>" },
+ { "/_Preferences/_Shape", NULL, NULL, 0, "<Branch>" },
+ { "/_Preferences/Shape/_Square", NULL, NULL, 0, "<RadioItem>" },
+ { "/_Preferences/Shape/_Rectangle", NULL, NULL, 0, "<RadioItem>" },
+ { "/_Preferences/Shape/_Oval", NULL, NULL, 0, "<RadioItem>" },
+
+ { "/_Help", NULL, NULL, 0, "<LastBranch>" },
+ { "/Help/_About", NULL, NULL, 0 },
+};
+
+static int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
+
+static void
+create_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);
+
+ gtk_signal_connect (GTK_OBJECT (window), "destroy",
+ GTK_SIGNAL_FUNC(gtk_widget_destroyed),
+ &window);
+ gtk_signal_connect (GTK_OBJECT (window), "delete-event",
+ GTK_SIGNAL_FUNC (gtk_true),
+ NULL);
+
+ accel_group = gtk_accel_group_new ();
+ item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", accel_group);
+ gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
+ gtk_accel_group_attach (accel_group, GTK_OBJECT (window));
+ gtk_window_set_title (GTK_WINDOW (window), "Item Factory");
+ gtk_container_border_width (GTK_CONTAINER (window), 0);
+
+ 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_usize (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_border_width (GTK_CONTAINER (box2), 10);
+ gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
+
+ button = gtk_button_new_with_label ("close");
+ gtk_signal_connect_object (GTK_OBJECT (button), "clicked",
+ GTK_SIGNAL_FUNC(gtk_widget_destroy),
+ GTK_OBJECT (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);
+}
+
/*
* GtkScrolledWindow
*/
@@ -3145,6 +3247,7 @@ create_list (void)
separator = gtk_hseparator_new ();
gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 0);
+
box2 = gtk_vbox_new (FALSE, 10);
gtk_container_border_width (GTK_CONTAINER (box2), 10);
gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, TRUE, 0);
@@ -7291,6 +7394,7 @@ create_main_window (void)
{ "font selection", create_font_selection },
{ "gamma curve", create_gamma_curve },
{ "handle box", create_handle_box },
+ { "item factory", create_item_factory },
{ "list", create_list },
{ "menus", create_menus },
{ "modal window", create_modal_window },