[egg-list-box/row-widget: 4/7] listbox: Use show/hide rather than signal to detect row being hidden
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [egg-list-box/row-widget: 4/7] listbox: Use show/hide rather than signal to detect row being hidden
- Date: Mon, 10 Jun 2013 08:43:35 +0000 (UTC)
commit c35a0aeb6b8b4452dceee6a78689fbfe0e322114
Author: Alexander Larsson <alexl redhat com>
Date: Fri Jun 7 12:26:59 2013 +0200
listbox: Use show/hide rather than signal to detect row being hidden
egg-list-box.c | 68 +++++++++++++++++++++++++++++++++++++-------------------
test-list.vala | 18 ++++++++++-----
2 files changed, 57 insertions(+), 29 deletions(-)
---
diff --git a/egg-list-box.c b/egg-list-box.c
index de0dfae..d2504be 100644
--- a/egg-list-box.c
+++ b/egg-list-box.c
@@ -311,8 +311,6 @@ egg_list_box_class_init (EggListBoxClass *klass)
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
GtkBindingSet *binding_set;
- egg_list_box_parent_class = g_type_class_peek_parent (klass);
-
g_type_class_add_private (klass, sizeof (EggListBoxPrivate));
gtk_widget_class_set_accessible_type (widget_class, EGG_TYPE_LIST_BOX_ACCESSIBLE);
@@ -998,7 +996,6 @@ egg_list_box_real_show (GtkWidget *widget)
GTK_WIDGET_CLASS (egg_list_box_parent_class)->show (widget);
}
-
static gboolean
egg_list_box_real_focus (GtkWidget* widget, GtkDirectionType direction)
{
@@ -1439,13 +1436,10 @@ egg_list_box_update_separator (EggListBox *list_box, GSequenceIter* iter)
}
static void
-child_visibility_changed (GObject* object, GParamSpec* pspec, EggListBox *list_box)
+egg_list_box_row_visibility_changed (EggListBox *list_box, EggListBoxRow *row)
{
- EggListBoxRow *row;
-
if (gtk_widget_get_visible (GTK_WIDGET (list_box)))
{
- row = EGG_LIST_BOX_ROW (object);
egg_list_box_update_separator (list_box, row->priv->iter);
egg_list_box_update_separator (list_box,
egg_list_box_get_next_visible (list_box, row->priv->iter));
@@ -1478,13 +1472,7 @@ egg_list_box_real_add (GtkContainer* container, GtkWidget *child)
row->priv->iter = iter;
gtk_widget_set_parent (GTK_WIDGET (row), GTK_WIDGET (list_box));
egg_list_box_apply_filter (list_box, row);
- if (gtk_widget_get_visible (GTK_WIDGET (list_box)))
- {
- egg_list_box_update_separator (list_box, iter);
- egg_list_box_update_separator (list_box, egg_list_box_get_next_visible (list_box, iter));
- }
- g_signal_connect_object (row, "notify::visible",
- (GCallback) child_visibility_changed, list_box, 0);
+ egg_list_box_row_visibility_changed (list_box, row);
}
static void
@@ -1499,8 +1487,6 @@ egg_list_box_real_remove (GtkContainer* container, GtkWidget* child)
g_return_if_fail (child != NULL);
was_visible = gtk_widget_get_visible (child);
- g_signal_handlers_disconnect_by_func (child, (GCallback) child_visibility_changed, list_box);
-
if (!EGG_IS_LIST_BOX_ROW (child))
{
row = g_hash_table_lookup (priv->separator_hash, child);
@@ -2133,14 +2119,51 @@ egg_list_box_row_set_property (GObject *obj,
}
}
-void
-egg_list_box_row_changed (EggListBoxRow *row)
+static EggListBox *
+egg_list_box_row_get_box (EggListBoxRow *row)
{
GtkWidget *parent;
parent = gtk_widget_get_parent (GTK_WIDGET (row));
if (parent && EGG_IS_LIST_BOX (parent))
- egg_list_box_got_row_changed (EGG_LIST_BOX (parent), row);
+ return EGG_LIST_BOX (parent);
+
+ return NULL;
+}
+
+static void
+egg_list_box_row_real_show (GtkWidget *widget)
+{
+ EggListBoxRow *row = EGG_LIST_BOX_ROW (widget);
+ EggListBox *list_box;;
+
+ GTK_WIDGET_CLASS (egg_list_box_row_parent_class)->show (widget);
+
+ list_box = egg_list_box_row_get_box (row);
+ if (list_box)
+ egg_list_box_row_visibility_changed (list_box, row);
+}
+
+static void
+egg_list_box_row_real_hide (GtkWidget *widget)
+{
+ EggListBoxRow *row = EGG_LIST_BOX_ROW (widget);
+ EggListBox *list_box;
+
+ GTK_WIDGET_CLASS (egg_list_box_row_parent_class)->hide (widget);
+
+ list_box = egg_list_box_row_get_box (row);
+ if (list_box)
+ egg_list_box_row_visibility_changed (list_box, row);
+}
+
+void
+egg_list_box_row_changed (EggListBoxRow *row)
+{
+ EggListBox *list_box = egg_list_box_row_get_box (row);
+
+ if (list_box)
+ egg_list_box_got_row_changed (EGG_LIST_BOX (list_box), row);
}
/**
@@ -2189,14 +2212,13 @@ egg_list_box_row_class_init (EggListBoxRowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
- GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
- GtkBindingSet *binding_set;
-
- egg_list_box_row_parent_class = g_type_class_peek_parent (klass);
g_type_class_add_private (klass, sizeof (EggListBoxRowPrivate));
object_class->get_property = egg_list_box_row_get_property;
object_class->set_property = egg_list_box_row_set_property;
object_class->finalize = egg_list_box_row_finalize;
+
+ widget_class->show = egg_list_box_row_real_show;
+ widget_class->hide = egg_list_box_row_real_hide;
}
diff --git a/test-list.vala b/test-list.vala
index 372035e..2c8291f 100644
--- a/test-list.vala
+++ b/test-list.vala
@@ -165,8 +165,8 @@ main (string[] args) {
b = new Button.with_label ("filter");
vbox.add (b);
b.clicked.connect ( () => {
- list.set_filter_func (filter);
- });
+ list.set_filter_func (filter);
+ });
b = new Button.with_label ("unfilter");
vbox.add (b);
@@ -187,14 +187,20 @@ main (string[] args) {
b = new Button.with_label ("separate");
vbox.add (b);
b.clicked.connect ( () => {
- list.set_separator_funcs (update_separator);
- });
+ list.set_separator_funcs (update_separator);
+ });
b = new Button.with_label ("unseparate");
vbox.add (b);
b.clicked.connect ( () => {
- list.set_separator_funcs (null);
- });
+ list.set_separator_funcs (null);
+ });
+
+ b = new Button.with_label ("visibility");
+ vbox.add (b);
+ b.clicked.connect ( () => {
+ row3.set_visible (!row3.get_visible());
+ });
w.show_all ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]