[gnome-control-center] shell: Add GtkListBox/Row derived types that do single row activations



commit ddd2d5ce8b5797eb4ee4a6c4d12f9864dc5d8f83
Author: Rui Matos <tiagomatos gmail com>
Date:   Mon Aug 7 15:50:20 2017 +0200

    shell: Add GtkListBox/Row derived types that do single row activations
    
    We often use rows representing different things in the same list
    box. In these cases it's often desirable to have rows emitting their
    own activation signals instead of having a single handler for the
    whole list box that dispatches according to the activated row.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=785949

 shell/list-box-helper.c |   43 +++++++++++++++++++++++++++++++++++++++++++
 shell/list-box-helper.h |    6 ++++++
 2 files changed, 49 insertions(+), 0 deletions(-)
---
diff --git a/shell/list-box-helper.c b/shell/list-box-helper.c
index 6e4ac89..415cdde 100644
--- a/shell/list-box-helper.c
+++ b/shell/list-box-helper.c
@@ -20,6 +20,49 @@
 
 #define MAX_ROWS_VISIBLE 5
 
+struct _CcListBoxRow
+{
+  GtkListBoxRow parent_instance;
+};
+G_DEFINE_TYPE (CcListBoxRow, cc_list_box_row, GTK_TYPE_LIST_BOX_ROW)
+enum
+{
+  BOX_ROW_ACTIVATED,
+  LAST_BOX_ROW_SIGNAL
+};
+static guint cc_list_box_row_signals[LAST_BOX_ROW_SIGNAL] = { 0 };
+static void
+cc_list_box_row_class_init (CcListBoxRowClass *klass)
+{
+  cc_list_box_row_signals[BOX_ROW_ACTIVATED] =
+    g_signal_new ("activated",
+                  CC_TYPE_LIST_BOX_ROW,
+                  G_SIGNAL_RUN_LAST,
+                  0, NULL, NULL, NULL,
+                  G_TYPE_NONE, 0);
+}
+static void cc_list_box_row_init (CcListBoxRow *self) {}
+
+struct _CcListBox
+{
+  GtkListBox parent_instance;
+};
+G_DEFINE_TYPE (CcListBox, cc_list_box, GTK_TYPE_LIST_BOX)
+static void
+cc_list_box_row_activated (GtkListBox *box, GtkListBoxRow *row)
+{
+  if (CC_IS_LIST_BOX_ROW (row))
+    g_signal_emit (row, cc_list_box_row_signals[BOX_ROW_ACTIVATED], 0);
+}
+static void
+cc_list_box_class_init (CcListBoxClass *klass)
+{
+  GtkListBoxClass *parent_class = GTK_LIST_BOX_CLASS (klass);
+  parent_class->row_activated = cc_list_box_row_activated;
+}
+static void cc_list_box_init (CcListBox *self) {}
+
+
 void
 cc_list_box_update_header_func (GtkListBoxRow *row,
                                 GtkListBoxRow *before,
diff --git a/shell/list-box-helper.h b/shell/list-box-helper.h
index 8b480b8..c2a0acc 100644
--- a/shell/list-box-helper.h
+++ b/shell/list-box-helper.h
@@ -18,6 +18,12 @@
 
 #include <gtk/gtk.h>
 
+#define CC_TYPE_LIST_BOX_ROW (cc_list_box_row_get_type ())
+G_DECLARE_FINAL_TYPE (CcListBoxRow, cc_list_box_row, CC, LIST_BOX_ROW, GtkListBoxRow)
+
+#define CC_TYPE_LIST_BOX (cc_list_box_get_type ())
+G_DECLARE_FINAL_TYPE (CcListBox, cc_list_box, CC, LIST_BOX, GtkListBox)
+
 void
 cc_list_box_update_header_func (GtkListBoxRow *row,
                                 GtkListBoxRow *before,


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