[gtk+] Improve list selection example



commit ccc4fb8512c4582016d6b4f418ccec81c0b57c47
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 29 00:59:05 2014 -0400

    Improve list selection example
    
    Print out signals, so we see how often they are emitted.

 tests/testlist3.c |   25 +++++++++++++++++++++++++
 1 files changed, 25 insertions(+), 0 deletions(-)
---
diff --git a/tests/testlist3.c b/tests/testlist3.c
index 3b11055..9ebd1c1 100644
--- a/tests/testlist3.c
+++ b/tests/testlist3.c
@@ -15,6 +15,27 @@ create_row (const gchar *text)
 }
 
 static void
+on_row_activated (GtkListBox *self,
+                  GtkWidget  *child)
+{
+  const char *id;
+  id = g_object_get_data (G_OBJECT (gtk_bin_get_child (GTK_BIN (child))), "id");
+  g_message ("Row activated %p: %s", child, id);
+}
+
+static void
+on_selected_children_changed (GtkListBox *self)
+{
+  g_message ("Selection changed");
+}
+
+static void
+a11y_selection_changed (AtkObject *obj)
+{
+  g_message ("Accessible selection changed");
+}
+
+static void
 selection_mode_changed (GtkComboBox *combo, gpointer data)
 {
   GtkListBox *list = data;
@@ -44,6 +65,10 @@ main (int argc, char *argv[])
   list = gtk_list_box_new ();
   gtk_list_box_set_selection_mode (GTK_LIST_BOX (list), GTK_SELECTION_NONE);
 
+  g_signal_connect (list, "row-activated", G_CALLBACK (on_row_activated), NULL);
+  g_signal_connect (list, "selected-rows-changed", G_CALLBACK (on_selected_children_changed), NULL);
+  g_signal_connect (gtk_widget_get_accessible (list), "selection-changed", G_CALLBACK 
(a11y_selection_changed), NULL);
+
   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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]