[gtk+/widget-expand: 3/3] add tests/testexpand.c used to test the expand props on GtkWidget
- From: Havoc Pennington <hp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/widget-expand: 3/3] add tests/testexpand.c used to test the expand props on GtkWidget
- Date: Wed, 8 Sep 2010 02:10:40 +0000 (UTC)
commit bdd4d59e2fe84de39985a8f53e7e421fa8dc292a
Author: Havoc Pennington <hp pobox com>
Date: Mon Sep 6 12:31:54 2010 -0400
add tests/testexpand.c used to test the expand props on GtkWidget
There are two colored boxes with toggle buttons nested
inside several GtkBox. Toggling these to expand mode
should automatically propagate expansion up through
the several GtkBox such that resizing the window
results in resizing the colored boxes.
https://bugzilla.gnome.org/show_bug.cgi?id=628902
tests/Makefile.am | 5 ++
tests/testexpand.c | 152 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 157 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index ccec905..896980b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -89,6 +89,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testactions \
testgrouping \
testtooltips \
+ testexpand \
testexpander \
testvolumebutton \
testwrapbox
@@ -175,6 +176,7 @@ testtooltips_DEPENDENCIES = $(TEST_DEPS)
testvolumebutton_DEPENDENCIES = $(TEST_DEPS)
testwrapbox_DEPENDENCIES = $(TEST_DEPS)
testwindows_DEPENDENCIES = $(TEST_DEPS)
+testexpand_DEPENDENCIES = $(TEST_DEPS)
testexpander_DEPENDENCIES = $(TEST_DEPS)
flicker_LDADD = $(LDADDS)
@@ -245,6 +247,7 @@ testtooltips_LDADD = $(LDADDS)
testvolumebutton_LDADD = $(LDADDS)
testwrapbox_LDADD = $(LDADDS)
testwindows_LDADD = $(LDADDS)
+testexpand_LDADD = $(LDADDS)
testexpander_LDADD = $(LDADDS)
testentrycompletion_SOURCES = \
@@ -357,6 +360,8 @@ testoffscreenwindow_SOURCES = \
testwindows_SOURCES = \
testwindows.c
+testexpand_SOURCES = testexpand.c
+
testexpander_SOURCES = testexpander.c
EXTRA_DIST += \
diff --git a/tests/testexpand.c b/tests/testexpand.c
new file mode 100644
index 0000000..c899ce0
--- /dev/null
+++ b/tests/testexpand.c
@@ -0,0 +1,152 @@
+/* testexpand.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 void
+on_toggle_h_expand (GtkToggleButton *toggle,
+ void *data)
+{
+ GtkWidget *parent;
+
+ /* get the event box with color set on it */
+ parent = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (toggle)));
+
+ g_object_set (toggle,
+ "h-expand", gtk_toggle_button_get_active (toggle),
+ NULL);
+}
+
+static void
+on_toggle_v_expand (GtkToggleButton *toggle,
+ void *data)
+{
+ GtkWidget *parent;
+
+ /* get the event box with color set on it */
+ parent = gtk_widget_get_parent (gtk_widget_get_parent (GTK_WIDGET (toggle)));
+
+ g_object_set (toggle,
+ "v-expand", gtk_toggle_button_get_active (toggle),
+ NULL);
+}
+
+static GtkWidget*
+create_window (void)
+{
+ GtkWidget *window;
+ GtkWidget *box1, *box2, *box3;
+ GtkWidget *toggle;
+ GtkWidget *alignment;
+ GtkWidget *colorbox;
+ GdkColor red, blue;
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+ box1 = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
+ box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, 0);
+ box3 = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (box1),
+ gtk_label_new ("VBox 1 Top"),
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box1),
+ box2,
+ FALSE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (box1),
+ gtk_label_new ("VBox 1 Bottom"),
+ FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (box2),
+ gtk_label_new ("HBox 2 Left"),
+ FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (box2),
+ box3,
+ FALSE, TRUE, 0);
+ gtk_box_pack_end (GTK_BOX (box2),
+ gtk_label_new ("HBox 2 Right"),
+ FALSE, FALSE, 0);
+
+ gtk_box_pack_start (GTK_BOX (box3),
+ gtk_label_new ("VBox 3 Top"),
+ FALSE, FALSE, 0);
+ gtk_box_pack_end (GTK_BOX (box3),
+ gtk_label_new ("VBox 3 Bottom"),
+ FALSE, FALSE, 0);
+
+ gdk_color_parse ("red", &red);
+ gdk_color_parse ("blue", &blue);
+
+ colorbox = gtk_event_box_new ();
+ gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &red);
+
+ alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_container_add (GTK_CONTAINER (colorbox), alignment);
+
+ toggle = gtk_toggle_button_new_with_label ("H Expand");
+ g_signal_connect (G_OBJECT (toggle), "toggled",
+ G_CALLBACK (on_toggle_h_expand), NULL);
+ gtk_container_add (GTK_CONTAINER (alignment), toggle);
+
+ gtk_box_pack_start (GTK_BOX (box3),
+ colorbox,
+ FALSE, TRUE, 0);
+
+ colorbox = gtk_event_box_new ();
+ gtk_widget_modify_bg (colorbox, GTK_STATE_NORMAL, &blue);
+
+ alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
+ gtk_container_add (GTK_CONTAINER (colorbox), alignment);
+
+ toggle = gtk_toggle_button_new_with_label ("V Expand");
+ g_signal_connect (G_OBJECT (toggle), "toggled",
+ G_CALLBACK (on_toggle_v_expand), NULL);
+ gtk_container_add (GTK_CONTAINER (alignment), toggle);
+ gtk_box_pack_start (GTK_BOX (box3),
+ colorbox,
+ FALSE, TRUE, 0);
+
+ gtk_container_add (GTK_CONTAINER (window),
+ box1);
+ gtk_widget_show_all (box1);
+
+ return window;
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window;
+
+ gtk_init (&argc, &argv);
+
+ window = create_window ();
+
+ g_signal_connect (window, "delete-event",
+ G_CALLBACK (gtk_main_quit), window);
+
+ gtk_widget_show (window);
+
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]