diff options
author | Matthias Clasen <matthiasc@src.gnome.org> | 2006-02-23 18:43:15 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2006-02-23 18:43:15 +0000 |
commit | e48a60ce81a587b9a9f55bd3f235cdde1a41356f (patch) | |
tree | fde332ed0ae2b226b4e61eece30063a2851a3ab1 /tests | |
parent | 2bec6c3f7ea0d9e04c17a9dded750f041a114ae8 (diff) | |
download | gtk+-e48a60ce81a587b9a9f55bd3f235cdde1a41356f.tar.gz |
Add tests
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/testnotebookdnd.c | 173 |
2 files changed, 176 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index 8471bc9a59..f82f6e5a43 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -51,6 +51,7 @@ noinst_PROGRAMS = \ testmenubars \ testmultidisplay \ testmultiscreen \ + testnotebookdnd \ testrgb \ testselection \ $(testsocket_programs) \ @@ -101,6 +102,7 @@ testmenus_DEPENDENCIES = $(TEST_DEPS) testmenubars_DEPENDENCIES = $(TEST_DEPS) testmultidisplay_DEPENDENCIES = $(TEST_DEPS) testmultiscreen_DEPENDENCIES = $(TEST_DEPS) +testnotebookdnd_DEPENDENCIES = $(TEST_DEPS) testrgb_DEPENDENCIES = $(TEST_DEPS) testselection_DEPENDENCIES = $(TEST_DEPS) testsocket_DEPENDENCIES = $(DEPS) @@ -145,6 +147,7 @@ testmenus_LDADD = $(LDADDS) testmenubars_LDADD = $(LDADDS) testmultidisplay_LDADD = $(LDADDS) testmultiscreen_LDADD = $(LDADDS) +testnotebookdnd_LDADD = $(LDADDS) testrgb_LDADD = $(LDADDS) testselection_LDADD = $(LDADDS) testsocket_LDADD = $(LDADDS) diff --git a/tests/testnotebookdnd.c b/tests/testnotebookdnd.c new file mode 100644 index 0000000000..23b6354378 --- /dev/null +++ b/tests/testnotebookdnd.c @@ -0,0 +1,173 @@ +/* + * GTK - The GIMP Toolkit + * Copyright (C) 2006 Carlos Garnacho Parro <carlosg@gnome.org> + * + * All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ +#include <gtk/gtk.h> + +enum { + PACK_START, + PACK_END, + PACK_ALTERNATE +}; + +enum { + GROUP_A, + GROUP_B +}; + +gchar *tabs1 [] = { + "a", + "b", + "c", + "d", + NULL +}; + +gchar *tabs2 [] = { + "1", + "2", + "3", + "4", + "5", + NULL +}; + +gchar *tabs3 [] = { + "foo", + "bar", + NULL +}; + +gchar *tabs4 [] = { + "beer", + "water", + "lemonade", + "coffee", + "tea", + NULL +}; + +static GtkNotebook* +window_creation_function (GtkNotebook *source_notebook, + GtkWidget *child, + gint x, + gint y, + gpointer data) +{ + GtkWidget *window, *notebook; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + notebook = gtk_notebook_new (); + + gtk_notebook_set_group_id (GTK_NOTEBOOK (notebook), + gtk_notebook_get_group_id (source_notebook)); + + gtk_container_add (GTK_CONTAINER (window), notebook); + + gtk_window_set_default_size (GTK_WINDOW (window), 300, 300); + gtk_window_move (GTK_WINDOW (window), x, y); + gtk_widget_show_all (window); + + return GTK_NOTEBOOK (notebook); +} + +static void +on_tab_reordered (GtkNotebook *notebook, GtkWidget *child, guint page_num, gpointer data) +{ + g_print ("tab %d reordered\n", page_num); +} + +static GtkWidget* +create_notebook (gchar **labels, + gint group_id, + gint packing, + GtkPositionType pos) +{ + GtkWidget *notebook, *title, *page; + gint count = 0; + + notebook = gtk_notebook_new (); + + gtk_notebook_set_tab_pos (GTK_NOTEBOOK (notebook), pos); + gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE); + gtk_container_set_border_width (GTK_CONTAINER (notebook), 6); + gtk_notebook_set_group_id (GTK_NOTEBOOK (notebook), group_id); + + while (*labels) + { + page = gtk_entry_new (); + gtk_entry_set_text (GTK_ENTRY (page), *labels); + + title = gtk_label_new (*labels); + + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), page, title); + gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook), page, TRUE); + gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook), page, TRUE); + + if (packing == PACK_END || + (packing == PACK_ALTERNATE && count % 2 == 1)) + gtk_container_child_set (GTK_CONTAINER (notebook), page, "tab-pack", GTK_PACK_END, NULL); + + count++; + labels++; + } + + g_signal_connect (GTK_NOTEBOOK (notebook), "tab-reordered", + G_CALLBACK (on_tab_reordered), NULL); + + return notebook; +} + +gint +main (gint argc, gchar *argv[]) +{ + GtkWidget *window, *table; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + table = gtk_table_new (2, 2, TRUE); + + gtk_notebook_set_window_creation_hook (window_creation_function, NULL); + + gtk_table_attach_defaults (GTK_TABLE (table), + create_notebook (tabs1, GROUP_A, PACK_START, GTK_POS_TOP), + 0, 1, 0, 1); + + gtk_table_attach_defaults (GTK_TABLE (table), + create_notebook (tabs2, GROUP_B, PACK_ALTERNATE, GTK_POS_BOTTOM), + 0, 1, 1, 2); + + gtk_table_attach_defaults (GTK_TABLE (table), + create_notebook (tabs3, GROUP_B, PACK_END, GTK_POS_LEFT), + 1, 2, 0, 1); + + gtk_table_attach_defaults (GTK_TABLE (table), + create_notebook (tabs4, GROUP_A, PACK_ALTERNATE, GTK_POS_RIGHT), + 1, 2, 1, 2); + + gtk_container_add (GTK_CONTAINER (window), table); + gtk_window_set_default_size (GTK_WINDOW (window), 400, 400); + gtk_widget_show_all (window); + + gtk_main (); + + return 0; +} |