Commit 71f589c0 authored by Matthias Clasen's avatar Matthias Clasen

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.
parent 880c6678
......@@ -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
<SUBSECTION Standard>
GTK_IS_LIST_BOX
......
......@@ -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);
}
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment