diff options
author | Havoc Pennington <hp@pobox.com> | 2010-09-04 23:40:32 -0400 |
---|---|---|
committer | Havoc Pennington <hp@pobox.com> | 2010-09-12 21:47:10 -0400 |
commit | dc1940e99e5abdc76f978ed0febc751ea3223f8d (patch) | |
tree | 8adfcee101d7cfad2785df3c6be3dd9f543ddbd1 /tests | |
parent | cd2a19a68dbd646ae120f110ef9a051fef7f49bf (diff) | |
download | gtk+-dc1940e99e5abdc76f978ed0febc751ea3223f8d.tar.gz |
Add testadjustsize test, to test new adjust size methods and related features
This will test size adjust, and interactions with other padding and border
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/testadjustsize.c | 252 |
2 files changed, 255 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am index b7bc39508c..ccec905d78 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -30,6 +30,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \ flicker \ print-editor \ testaccel \ + testadjustsize \ testassistant \ testbbox \ testbuttons \ @@ -117,6 +118,7 @@ testicontheme_DEPENDENCIES = $(TEST_DEPS) testiconview_DEPENDENCIES = $(TEST_DEPS) testaccel_DEPENDENCIES = $(TEST_DEPS) testapplication_DEPENDENCIES = $(TEST_DEPS) +testadjustsize_DEPENDENCIES = $(TEST_DEPS) testassistant_DEPENDENCIES = $(TEST_DEPS) testbbox_DEPENDENCIES = $(TEST_DEPS) testbuttons_DEPENDENCIES = $(TEST_DEPS) @@ -179,6 +181,7 @@ flicker_LDADD = $(LDADDS) simple_LDADD = $(LDADDS) print_editor_LDADD = $(LDADDS) testaccel_LDADD = $(LDADDS) +testadjustsize_LDADD = $(LDADDS) testapplication_LDADD = $(LDADDS) testassistant_LDADD = $(LDADDS) testbbox_LDADD = $(LDADDS) diff --git a/tests/testadjustsize.c b/tests/testadjustsize.c new file mode 100644 index 0000000000..4ecc6c97e1 --- /dev/null +++ b/tests/testadjustsize.c @@ -0,0 +1,252 @@ +/* testadjustsize.c + * Copyright (C) 2010 Havoc Pennington + * + * Author: + * Havoc Pennington <hp@pobox.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library 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 + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library 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> + +static GtkWidget *test_window; + +enum { + TEST_WIDGET_LABEL, + TEST_WIDGET_VERTICAL_LABEL, + TEST_WIDGET_WRAP_LABEL, + TEST_WIDGET_ALIGNMENT, + TEST_WIDGET_IMAGE, + TEST_WIDGET_BUTTON, + TEST_WIDGET_LAST +}; + +static GtkWidget *test_widgets[TEST_WIDGET_LAST]; + +static GtkWidget* +create_image (void) +{ + return gtk_image_new_from_stock (GTK_STOCK_OPEN, + GTK_ICON_SIZE_BUTTON); +} + +static GtkWidget* +create_label (gboolean vertical, + gboolean wrap) +{ + GtkWidget *widget; + + widget = gtk_label_new ("This is a label, label label label"); + + if (vertical) + gtk_label_set_angle (GTK_LABEL (widget), 90); + + if (wrap) + gtk_label_set_line_wrap (GTK_LABEL (widget), TRUE); + + return widget; +} + +static GtkWidget* +create_button (void) +{ + return gtk_button_new_with_label ("BUTTON!"); +} + +static gboolean +on_expose_alignment (GtkWidget *widget, + GdkEventExpose *event, + void *data) +{ + cairo_t *cr; + GtkAllocation allocation; + + cr = gdk_cairo_create (event->window); + + cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); + gtk_widget_get_allocation (widget, &allocation); + cairo_rectangle (cr, + allocation.x, + allocation.y, + allocation.width, + allocation.height); + cairo_fill (cr); + + cairo_destroy (cr); + + return FALSE; +} + +static GtkWidget* +create_alignment (void) +{ + GtkWidget *alignment; + + alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0); + + /* make the alignment visible */ + gtk_widget_set_redraw_on_allocate (alignment, TRUE); + g_signal_connect (G_OBJECT (alignment), + "expose-event", + G_CALLBACK (on_expose_alignment), + NULL); + + return alignment; +} + +static void +open_test_window (void) +{ + GtkWidget *table; + int i; + + test_window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + g_signal_connect (test_window, "delete-event", + G_CALLBACK (gtk_main_quit), test_window); + + gtk_window_set_resizable (GTK_WINDOW (test_window), FALSE); + + test_widgets[TEST_WIDGET_IMAGE] = create_image (); + test_widgets[TEST_WIDGET_LABEL] = create_label (FALSE, FALSE); + test_widgets[TEST_WIDGET_VERTICAL_LABEL] = create_label (TRUE, FALSE); + test_widgets[TEST_WIDGET_WRAP_LABEL] = create_label (FALSE, TRUE); + test_widgets[TEST_WIDGET_BUTTON] = create_button (); + test_widgets[TEST_WIDGET_ALIGNMENT] = create_alignment (); + + table = gtk_table_new (2, 3, FALSE); + + gtk_container_add (GTK_CONTAINER (test_window), table); + + for (i = 0; i < TEST_WIDGET_LAST; ++i) + { + gtk_table_attach (GTK_TABLE (table), + test_widgets[i], + i % 3, + i % 3 + 1, + i / 3, + i / 3 + 1, + 0, 0, 0, 0); + } + + gtk_widget_show_all (test_window); +} + +static void +on_toggle_border_widths (GtkToggleButton *button, + void *data) +{ + gboolean has_border; + int i; + + has_border = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); + + for (i = 0; i < TEST_WIDGET_LAST; ++i) + { + if (GTK_IS_CONTAINER (test_widgets[i])) + { + gtk_container_set_border_width (GTK_CONTAINER (test_widgets[i]), + has_border ? 50 : 0); + } + } +} + +static void +on_set_small_size_requests (GtkToggleButton *button, + void *data) +{ + gboolean has_small_size_requests; + int i; + + has_small_size_requests = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); + + for (i = 0; i < TEST_WIDGET_LAST; ++i) + { + gtk_widget_set_size_request (test_widgets[i], + has_small_size_requests ? 5 : -1, + has_small_size_requests ? 5 : -1); + } +} + +static void +on_set_large_size_requests (GtkToggleButton *button, + void *data) +{ + gboolean has_large_size_requests; + int i; + + has_large_size_requests = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)); + + for (i = 0; i < TEST_WIDGET_LAST; ++i) + { + gtk_widget_set_size_request (test_widgets[i], + has_large_size_requests ? 200 : -1, + has_large_size_requests ? 200 : -1); + } +} + +static void +open_control_window (void) +{ + GtkWidget *window; + GtkWidget *box; + GtkWidget *toggle; + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + + g_signal_connect (window, "delete-event", + G_CALLBACK (gtk_main_quit), window); + + box = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0); + gtk_container_add (GTK_CONTAINER (window), box); + + toggle = + gtk_toggle_button_new_with_label ("Containers have borders"); + g_signal_connect (G_OBJECT (toggle), + "toggled", G_CALLBACK (on_toggle_border_widths), + NULL); + gtk_container_add (GTK_CONTAINER (box), toggle); + + toggle = + gtk_toggle_button_new_with_label ("Set small size requests"); + g_signal_connect (G_OBJECT (toggle), + "toggled", G_CALLBACK (on_set_small_size_requests), + NULL); + gtk_container_add (GTK_CONTAINER (box), toggle); + + toggle = + gtk_toggle_button_new_with_label ("Set large size requests"); + g_signal_connect (G_OBJECT (toggle), + "toggled", G_CALLBACK (on_set_large_size_requests), + NULL); + gtk_container_add (GTK_CONTAINER (box), toggle); + + + gtk_widget_show_all (window); +} + +int +main (int argc, char *argv[]) +{ + gtk_init (&argc, &argv); + + open_test_window (); + open_control_window (); + + gtk_main (); + + return 0; +} |