From 5417534eda7f116df77161b391dcea0f73a6abdf Mon Sep 17 00:00:00 2001 From: Mathias Hasselmann Date: Sun, 27 May 2007 17:52:13 +0000 Subject: [PATCH] Creating testing framework, starting with natural size testing. svn path=/branches/extended-layout/; revision=17951 --- ChangeLog.gtk-extended-layout | 6 ++ tests/Makefile.am | 4 + tests/testextendedlayout.c | 186 ++++++++++++++++++++++++++++++++++ 3 files changed, 196 insertions(+) create mode 100644 ChangeLog.gtk-extended-layout create mode 100644 tests/testextendedlayout.c diff --git a/ChangeLog.gtk-extended-layout b/ChangeLog.gtk-extended-layout new file mode 100644 index 0000000000..235e0f20ee --- /dev/null +++ b/ChangeLog.gtk-extended-layout @@ -0,0 +1,6 @@ +2007-05-27 Mathias Hasselmann + + * tests/testextendedlayout.c, tests/Makefile.am, + ChangeLog.gtk-extended-layout: Creating testing framework, + starting with natural size testing. + diff --git a/tests/Makefile.am b/tests/Makefile.am index 0f2a739eba..f06b9ceabc 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -42,6 +42,7 @@ noinst_PROGRAMS = \ testdnd \ testellipsise \ testentrycompletion \ + testextendedlayout \ testfilechooser \ testfilechooserbutton \ testgtk \ @@ -212,6 +213,9 @@ testentrycompletion_SOURCES = \ prop-editor.c \ testentrycompletion.c +testextendedlayout_SOURCES = \ + testextendedlayout.c + testfilechooser_SOURCES = \ prop-editor.c \ testfilechooser.c diff --git a/tests/testextendedlayout.c b/tests/testextendedlayout.c new file mode 100644 index 0000000000..7945928fb8 --- /dev/null +++ b/tests/testextendedlayout.c @@ -0,0 +1,186 @@ +/* testextendedlayout.c + * Copyright (C) 2007 Mathias Hasselmann + * + * 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 +#include + +GList *allocation_guides = NULL; + +static void +append_natural_size_box (GtkWidget *vbox, + const gchar *caption, + PangoEllipsizeMode ellipsize) +{ + GtkWidget *hbox; + GtkWidget *button; + GtkWidget *label; + + hbox = gtk_hbox_new (FALSE, 12); + + label = gtk_label_new ("The small Button"); + gtk_label_set_ellipsize (GTK_LABEL (label), ellipsize); + + button = gtk_button_new (); + gtk_container_add (GTK_CONTAINER (button), label); + gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, TRUE, 0); + + if (PANGO_ELLIPSIZE_NONE == ellipsize) + allocation_guides = g_list_append (allocation_guides, button); + + button = gtk_button_new_with_label ("The large Button"); + gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0); + + label = gtk_label_new (NULL); + gtk_label_set_markup (GTK_LABEL (label), caption); + gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); + + gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 0); +} + +static GtkWidget* +create_natural_size () +{ + GtkWidget *vbox = gtk_vbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); + append_natural_size_box (vbox, "No ellipsizing", PANGO_ELLIPSIZE_NONE); + append_natural_size_box (vbox, "Ellipsizing at start", PANGO_ELLIPSIZE_START); + append_natural_size_box (vbox, "Ellipsizing in the middle", PANGO_ELLIPSIZE_MIDDLE); + append_natural_size_box (vbox, "Ellipsizing at end", PANGO_ELLIPSIZE_END); + + return vbox; +} + +static GtkWidget* +create_height_for_width () +{ + GtkWidget *vbox; + + vbox = gtk_vbox_new (FALSE, 12); + gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); + + return vbox; +} + +static GtkWidget* +create_baseline () +{ + GtkWidget *table; + + table = gtk_table_new (4, 3, FALSE); + gtk_container_set_border_width (GTK_CONTAINER (table), 12); + + return table; +} + +static gboolean +expose_page (GtkWidget *page, + GdkEventExpose *event __attribute__((unused)), + gpointer user_data) +{ + cairo_t *cr = gdk_cairo_create (page->window); + GList *guides = user_data; + GList *iter; + +/* cairo_rectangle (cr, event->area.x, event->area.y, + event->area.width, event->area.height); + cairo_clip (cr);*/ + + cairo_translate (cr, page->allocation.x - 0.5, + page->allocation.y - 0.5); + + cairo_set_line_width (cr, 1); + cairo_set_source_rgba (cr, 1.0, 0.0, 0.0, 0.5); + + for (iter = guides; iter; iter = iter->next) + { + GtkWidget *child = iter->data; + gint x0, y0, x1, y1; + + if (GTK_WIDGET_VISIBLE (child) && + gtk_widget_translate_coordinates (child, page, 0, 0, &x0, &y0)) + { + x1 = x0 + child->allocation.width; + y1 = y0 + child->allocation.height; + + cairo_move_to (cr, x0, 0); + cairo_line_to (cr, x0, page->allocation.height - 1); + + cairo_move_to (cr, x1, 0); + cairo_line_to (cr, x1, page->allocation.height - 1); + + cairo_move_to (cr, 0, y0); + cairo_line_to (cr, page->allocation.width - 1, y0); + + cairo_move_to (cr, 0, y1); + cairo_line_to (cr, page->allocation.width - 1, y1); + + cairo_stroke (cr); + } + } + + cairo_destroy (cr); + return FALSE; +} + +static void +append_testcase(GtkWidget *notebook, + GtkWidget *testcase, + const gchar *caption) +{ + GtkWidget *alignment; + + alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); + gtk_container_add (GTK_CONTAINER (alignment), testcase); + gtk_notebook_append_page (GTK_NOTEBOOK (notebook), alignment, + gtk_label_new (caption)); + + g_signal_connect_after (testcase, "expose-event", + G_CALLBACK (expose_page), + allocation_guides); + + allocation_guides = NULL; +} + +int +main (int argc, char *argv[]) +{ + GtkWidget *window; + GtkWidget *notebook; + + gtk_init (&argc, &argv); + + notebook = gtk_notebook_new (); + + append_testcase (notebook, create_natural_size (), "Natural Size"); + append_testcase (notebook, create_height_for_width (), "Height for Width"); + append_testcase (notebook, create_baseline (), "Baseline Alignment"); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + gtk_window_set_title (GTK_WINDOW (window), "Testing GtkExtendedLayout"); + gtk_container_add (GTK_CONTAINER (window), notebook); + gtk_widget_show_all (window); + + gtk_main (); + + return 0; +} + +/* vim: set sw=2 sta et: */