[gtk+/wip/combo: 2/11] Add a test for the new combo box
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/combo: 2/11] Add a test for the new combo box
- Date: Fri, 26 Dec 2014 05:20:36 +0000 (UTC)
commit 08b571f214206abcc255dcdf7956c1a8ed407da4
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Dec 25 07:02:57 2014 -0500
Add a test for the new combo box
Add a some simple test app for GtkCombo.
tests/Makefile.am | 2 +
tests/testnewcombo.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 108 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c94448c..a981d8f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -92,6 +92,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testmenubutton \
testmountoperation \
testmultidisplay \
+ testnewcombo \
testnotebookdnd \
testnumerableicon \
testnouiprint \
@@ -234,6 +235,7 @@ testlockbutton_DEPENDENCIES = $(TEST_DEPS)
testmenubutton_DEPENDENCIES = $(TEST_DEPS)
testmountoperation_DEPENDENCIES = $(TEST_DEPS)
testmultidisplay_DEPENDENCIES = $(TEST_DEPS)
+testnewcombo_DEPENDENCIES = $(TEST_DEPS)
testnotebookdnd_DEPENDENCIES = $(TEST_DEPS)
testnouiprint_DEPENDENCIES = $(TEST_DEPS)
testnumerableicon_DEPENDENCIES = $(TEST_DEPS)
diff --git a/tests/testnewcombo.c b/tests/testnewcombo.c
new file mode 100644
index 0000000..33872b4
--- /dev/null
+++ b/tests/testnewcombo.c
@@ -0,0 +1,106 @@
+#include <gtk/gtk.h>
+
+static void
+add_one (GtkButton *button, gpointer data)
+{
+ static gint count = 3;
+ gchar *text;
+ gchar *sort;
+ gchar *id;
+
+ count++;
+
+ id = g_strdup_printf ("%d", count);
+ sort = g_strdup_printf ("Value %03d", count);
+ text = g_strdup_printf ("Value %d", count);
+ gtk_combo_add (GTK_COMBO (data), id, sort, text);
+ gtk_combo_set_active (GTK_COMBO (data), id);
+ g_free (id);
+ g_free (sort);
+ g_free (text);
+}
+
+static void
+remove_active (GtkButton *button, gpointer data)
+{
+ const gchar *id;
+
+ id = gtk_combo_get_active (GTK_COMBO (data));
+ gtk_combo_remove (GTK_COMBO (data), id);
+}
+
+static void
+select_a (GtkButton *button, gpointer data)
+{
+ gtk_combo_set_active (GTK_COMBO (data), "1");
+}
+
+const gchar data[] =
+ "<interface>"
+ " <object class='GtkCombo' id='combo'>"
+ " <property name='visible'>True</property>"
+ " <property name='halign'>center</property>"
+ " <property name='placeholder'>None</property>"
+ " <property name='active'>1</property>"
+ " <items>"
+ " <item translatable='yes' id='1' sort='Value 001'>Value 1</item>"
+ " <item translatable='yes' id='2' sort='Value 002'>Value 2</item>"
+ " <item translatable='yes' id='3' sort='Value 003'>Value 3</item>"
+ " </items>"
+ " </object>"
+ "</interface>";
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window, *box, *box2, *button;
+ GtkWidget *combo;
+ GtkWidget *label;
+ GtkBuilder *builder;
+
+ gtk_init (NULL, NULL);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), 400, 600);
+
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 10);
+ gtk_container_add (GTK_CONTAINER (window), box);
+
+ builder = gtk_builder_new_from_string (data, -1);
+ combo = (GtkWidget *)gtk_builder_get_object (builder, "combo");
+ gtk_container_add (GTK_CONTAINER (box), combo);
+ g_object_unref (builder);
+
+ box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_container_add (GTK_CONTAINER (box), box2);
+ button = gtk_button_new_with_label ("Add value");
+ g_signal_connect (button, "clicked", G_CALLBACK (add_one), combo);
+ gtk_container_add (GTK_CONTAINER (box2), button);
+ button = gtk_button_new_with_label ("Select 1");
+ g_signal_connect (button, "clicked", G_CALLBACK (select_a), combo);
+ gtk_container_add (GTK_CONTAINER (box2), button);
+ button = gtk_button_new_with_label ("Remove active");
+ g_signal_connect (button, "clicked", G_CALLBACK (remove_active), combo);
+ gtk_container_add (GTK_CONTAINER (box2), button);
+ button = gtk_check_button_new_with_label ("Allow custom");
+ g_object_bind_property (button, "active",
+ combo, "allow-custom",
+ 0);
+ gtk_container_add (GTK_CONTAINER (box), button);
+
+ box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ gtk_container_add (GTK_CONTAINER (box), box2);
+ label = gtk_label_new ("Active:");
+ gtk_container_add (GTK_CONTAINER (box2), label);
+ label = gtk_label_new ("");
+ g_object_bind_property (combo, "active",
+ label, "label",
+ G_BINDING_SYNC_CREATE);
+ gtk_container_add (GTK_CONTAINER (box2), label);
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]