From 71f589c0b0c0f824f2c1101fb4142e23e794bbf9 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 15 Jul 2014 23:10:51 -0400 Subject: [PATCH] GtkListBox: Add a GtkListBoxRow:selectable property Having an explicit property for this will make it easier to have a hover style only for rows which are activatable or selectable. Rows are selectable by default, to preserve compatibility. --- docs/reference/gtk/gtk3-sections.txt | 2 + gtk/gtklistbox.c | 71 ++++++++++++++++++++++++++++ gtk/gtklistbox.h | 7 +++ 3 files changed, 80 insertions(+) diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt index 4fd0b069a3..daada859e4 100644 --- a/docs/reference/gtk/gtk3-sections.txt +++ b/docs/reference/gtk/gtk3-sections.txt @@ -560,6 +560,8 @@ gtk_list_box_row_set_header gtk_list_box_row_get_index gtk_list_box_row_set_activatable gtk_list_box_row_get_activatable +gtk_list_box_row_set_selectable +gtk_list_box_row_get_selectable GTK_IS_LIST_BOX diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index 0e65aff699..b07898c77c 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -104,6 +104,7 @@ typedef struct guint visible :1; guint selected :1; guint activatable :1; + guint selectable :1; } GtkListBoxRowPrivate; enum { @@ -133,6 +134,7 @@ enum { enum { ROW_PROP_0, ROW_PROP_ACTIVATABLE, + ROW_PROP_SELECTABLE, LAST_ROW_PROPERTY }; @@ -2830,6 +2832,7 @@ gtk_list_box_row_init (GtkListBoxRow *row) gtk_widget_set_redraw_on_allocate (GTK_WIDGET (row), TRUE); ROW_PRIV (row)->activatable = TRUE; + ROW_PRIV (row)->selectable = TRUE; context = gtk_widget_get_style_context (GTK_WIDGET (row)); gtk_style_context_add_class (context, GTK_STYLE_CLASS_LIST_ROW); @@ -3282,6 +3285,54 @@ gtk_list_box_row_get_activatable (GtkListBoxRow *row) return ROW_PRIV (row)->activatable; } +/** + * gtk_list_box_row_set_selectable: + * @row: a #GTkListBoxrow + * @selectable: %TRUE to mark the row as selectable + * + * Set the #GtkListBoxRow:selectable property for this row. + * + * Since: 3.14 + */ +void +gtk_list_box_row_set_selectable (GtkListBoxRow *row, + gboolean selectable) +{ + g_return_if_fail (GTK_IS_LIST_BOX_ROW (row)); + + selectable = selectable != FALSE; + + if (ROW_PRIV (row)->selectable != selectable) + { + if (!selectable) + gtk_list_box_row_set_selected (row, FALSE); + + ROW_PRIV (row)->selectable = selectable; + + update_row_style (row); + g_object_notify (G_OBJECT (row), "selectable"); + } +} + +/** + * gtk_list_box_row_get_selectable: + * @row: a #GtkListBoxRow + * + * Gets the value of the #GtkListBoxRow:selectable property + * for this row. + * + * Returns: %TRUE if the row is selectable + * + * Since: 3.14 + */ +gboolean +gtk_list_box_row_get_selectable (GtkListBoxRow *row) +{ + g_return_val_if_fail (GTK_IS_LIST_BOX_ROW (row), TRUE); + + return ROW_PRIV (row)->selectable; +} + static void gtk_list_box_row_get_property (GObject *obj, guint property_id, @@ -3295,6 +3346,9 @@ gtk_list_box_row_get_property (GObject *obj, case ROW_PROP_ACTIVATABLE: g_value_set_boolean (value, gtk_list_box_row_get_activatable (row)); break; + case ROW_PROP_SELECTABLE: + g_value_set_boolean (value, gtk_list_box_row_get_selectable (row)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -3314,6 +3368,9 @@ gtk_list_box_row_set_property (GObject *obj, case ROW_PROP_ACTIVATABLE: gtk_list_box_row_set_activatable (row, g_value_get_boolean (value)); break; + case ROW_PROP_SELECTABLE: + gtk_list_box_row_set_selectable (row, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -3378,6 +3435,20 @@ gtk_list_box_row_class_init (GtkListBoxRowClass *klass) TRUE, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + /** + * GtkListBoxRow:selectable + * + * The property determines whether this row can be selected. + * + * Since: 3.14 + */ + row_properties[ROW_PROP_SELECTABLE] = + g_param_spec_boolean ("selectable", + P_("Selectable"), + P_("Whether this row can be selected"), + TRUE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + g_object_class_install_properties (object_class, LAST_ROW_PROPERTY, row_properties); } diff --git a/gtk/gtklistbox.h b/gtk/gtklistbox.h index d6e103e62c..9f5aa6fd32 100644 --- a/gtk/gtklistbox.h +++ b/gtk/gtklistbox.h @@ -183,6 +183,13 @@ void gtk_list_box_row_changed (GtkListBoxRow *row); GDK_AVAILABLE_IN_3_14 gboolean gtk_list_box_row_is_selected (GtkListBoxRow *row); +GDK_AVAILABLE_IN_3_14 +void gtk_list_box_row_set_selectable (GtkListBoxRow *row, + gboolean selectable); +GDK_AVAILABLE_IN_3_14 +gboolean gtk_list_box_row_get_selectable (GtkListBoxRow *row); + + GDK_AVAILABLE_IN_3_14 void gtk_list_box_row_set_activatable (GtkListBoxRow *row, gboolean activatable);