[gtk+] Add a list box selection testcase
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Add a list box selection testcase
- Date: Sun, 6 Apr 2014 05:46:23 +0000 (UTC)
commit 92eab67a4919be3d9303b3a88d97bc482459be1e
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Mar 28 21:48:54 2014 -0400
Add a list box selection testcase
tests/Makefile.am | 1 +
tests/testlist3.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 7afc58b..a416ed1 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -78,6 +78,7 @@ noinst_PROGRAMS = $(TEST_PROGS) \
testkineticscrolling \
testlist \
testlist2 \
+ testlist3 \
testlevelbar \
testlockbutton \
testmenubutton \
diff --git a/tests/testlist3.c b/tests/testlist3.c
new file mode 100644
index 0000000..3b11055
--- /dev/null
+++ b/tests/testlist3.c
@@ -0,0 +1,80 @@
+#include <gtk/gtk.h>
+
+static GtkWidget *
+create_row (const gchar *text)
+{
+ GtkWidget *row, *box, *label;
+
+ row = gtk_list_box_row_new ();
+ box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
+ label = gtk_label_new (text);
+ gtk_container_add (GTK_CONTAINER (row), box);
+ gtk_container_add (GTK_CONTAINER (box), label);
+
+ return row;
+}
+
+static void
+selection_mode_changed (GtkComboBox *combo, gpointer data)
+{
+ GtkListBox *list = data;
+
+ gtk_list_box_set_selection_mode (list, gtk_combo_box_get_active (combo));
+}
+
+int
+main (int argc, char *argv[])
+{
+ GtkWidget *window, *list, *sw, *row;
+ GtkWidget *hbox, *vbox, *combo, *button;
+ gint i;
+ gchar *text;
+
+ gtk_init (NULL, NULL);
+
+ window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_default_size (GTK_WINDOW (window), -1, 300);
+
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
+ gtk_container_add (GTK_CONTAINER (window), hbox);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+ g_object_set (vbox, "margin", 12, NULL);
+ gtk_container_add (GTK_CONTAINER (hbox), vbox);
+
+ list = gtk_list_box_new ();
+ gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
+
+ sw = gtk_scrolled_window_new (NULL, NULL);
+ gtk_widget_set_hexpand (sw, TRUE);
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+ gtk_container_add (GTK_CONTAINER (hbox), sw);
+ gtk_container_add (GTK_CONTAINER (sw), list);
+
+ button = gtk_check_button_new_with_label ("Activate on single click");
+ g_object_bind_property (list, "activate-on-single-click",
+ button, "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+ gtk_container_add (GTK_CONTAINER (vbox), button);
+
+ combo = gtk_combo_box_text_new ();
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "None");
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Single");
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Browse");
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), "Multiple");
+ g_signal_connect (combo, "changed", G_CALLBACK (selection_mode_changed), list);
+ gtk_container_add (GTK_CONTAINER (vbox), combo);
+ gtk_combo_box_set_active (GTK_COMBO_BOX (combo), gtk_list_box_get_selection_mode (GTK_LIST_BOX (list)));
+
+ for (i = 0; i < 20; i++)
+ {
+ text = g_strdup_printf ("Row %d", i);
+ row = create_row (text);
+ gtk_list_box_insert (GTK_LIST_BOX (list), row, -1);
+ }
+
+ gtk_widget_show_all (window);
+
+ gtk_main ();
+
+ return 0;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]