mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 23:10:22 +00:00
GtkListBox: Style selectable rows differently
We now apply the .button style class to rows that are either activatable or selectable. Selectable rows only get the .button if the listbox allows selection. This implies that we need to update row styles when the selection mode changes, or when the row gets added to a listbox.
This commit is contained in:
parent
71f589c0b0
commit
7932370ef8
@ -244,6 +244,9 @@ static void gtk_list_box_multipress_gesture_released (GtkGestureMultiPress *gest
|
||||
gdouble y,
|
||||
GtkListBox *box);
|
||||
|
||||
static void gtk_list_box_update_row_styles (GtkListBox *box);
|
||||
static void gtk_list_box_update_row_style (GtkListBox *box,
|
||||
GtkListBoxRow *row);
|
||||
|
||||
static GParamSpec *properties[LAST_PROPERTY] = { NULL, };
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
@ -974,6 +977,8 @@ gtk_list_box_set_selection_mode (GtkListBox *box,
|
||||
|
||||
priv->selection_mode = mode;
|
||||
|
||||
gtk_list_box_update_row_styles (box);
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_SELECTION_MODE]);
|
||||
|
||||
if (dirty)
|
||||
@ -2587,6 +2592,7 @@ gtk_list_box_insert (GtkListBox *box,
|
||||
if (ROW_PRIV (row)->visible)
|
||||
list_box_add_visible_rows (box, 1);
|
||||
gtk_list_box_apply_filter (box, row);
|
||||
gtk_list_box_update_row_style (box, row);
|
||||
if (gtk_widget_get_visible (GTK_WIDGET (box)))
|
||||
{
|
||||
gtk_list_box_update_header (box, ROW_PRIV (row)->iter);
|
||||
@ -3229,17 +3235,40 @@ gtk_list_box_row_is_selected (GtkListBoxRow *row)
|
||||
}
|
||||
|
||||
static void
|
||||
update_row_style (GtkListBoxRow *row)
|
||||
gtk_list_box_update_row_style (GtkListBox *box,
|
||||
GtkListBoxRow *row)
|
||||
{
|
||||
GtkStyleContext *context;
|
||||
gboolean can_select;
|
||||
|
||||
if (box && BOX_PRIV (box)->selection_mode != GTK_SELECTION_NONE)
|
||||
can_select = TRUE;
|
||||
else
|
||||
can_select = FALSE;
|
||||
|
||||
context = gtk_widget_get_style_context (GTK_WIDGET (row));
|
||||
if (ROW_PRIV (row)->activatable)
|
||||
if (ROW_PRIV (row)->activatable ||
|
||||
(ROW_PRIV (row)->selectable && can_select))
|
||||
gtk_style_context_add_class (context, GTK_STYLE_CLASS_BUTTON);
|
||||
else
|
||||
gtk_style_context_remove_class (context, GTK_STYLE_CLASS_BUTTON);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_list_box_update_row_styles (GtkListBox *box)
|
||||
{
|
||||
GSequenceIter *iter;
|
||||
GtkListBoxRow *row;
|
||||
|
||||
for (iter = g_sequence_get_begin_iter (BOX_PRIV (box)->children);
|
||||
!g_sequence_iter_is_end (iter);
|
||||
iter = g_sequence_iter_next (iter))
|
||||
{
|
||||
row = g_sequence_get (iter);
|
||||
gtk_list_box_update_row_style (box, row);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_list_box_row_set_activatable:
|
||||
* @row: a #GTkListBoxrow
|
||||
@ -3261,7 +3290,7 @@ gtk_list_box_row_set_activatable (GtkListBoxRow *row,
|
||||
{
|
||||
ROW_PRIV (row)->activatable = activatable;
|
||||
|
||||
update_row_style (row);
|
||||
gtk_list_box_update_row_style (gtk_list_box_row_get_box (row), row);
|
||||
g_object_notify (G_OBJECT (row), "activatable");
|
||||
}
|
||||
}
|
||||
@ -3309,7 +3338,7 @@ gtk_list_box_row_set_selectable (GtkListBoxRow *row,
|
||||
|
||||
ROW_PRIV (row)->selectable = selectable;
|
||||
|
||||
update_row_style (row);
|
||||
gtk_list_box_update_row_style (gtk_list_box_row_get_box (row), row);
|
||||
g_object_notify (G_OBJECT (row), "selectable");
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user