diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt index 32a1ad59f7..91aad5becd 100644 --- a/docs/reference/gtk/gtk4-sections.txt +++ b/docs/reference/gtk/gtk4-sections.txt @@ -362,6 +362,8 @@ gtk_list_box_get_selected_row GtkListBoxForeachFunc gtk_list_box_selected_foreach gtk_list_box_get_selected_rows +gtk_list_box_set_show_separators +gtk_list_box_get_show_separators gtk_list_box_set_selection_mode gtk_list_box_get_selection_mode diff --git a/gtk/gtklistbox.c b/gtk/gtklistbox.c index f6ccfb1931..bde8540dc7 100644 --- a/gtk/gtklistbox.c +++ b/gtk/gtklistbox.c @@ -73,11 +73,12 @@ * # CSS nodes * * |[ - * list + * list[.separators] * ╰── row[.activatable] * ]| * - * GtkListBox uses a single CSS node named list. Each GtkListBoxRow uses + * GtkListBox uses a single CSS node named list. It may carry the .separators style + * class, when the #GtkListBox::show-separators property is set. Each GtkListBoxRow uses * a single CSS node named row. The row nodes get the .activatable * style class added when appropriate. */ @@ -113,6 +114,7 @@ typedef struct GtkAdjustment *adjustment; gboolean activate_single_click; gboolean accept_unpaired_release; + gboolean show_separators; /* DnD */ GtkListBoxRow *drag_highlighted_row; @@ -160,6 +162,7 @@ enum { PROP_SELECTION_MODE, PROP_ACTIVATE_ON_SINGLE_CLICK, PROP_ACCEPT_UNPAIRED_RELEASE, + PROP_SHOW_SEPARATORS, LAST_PROPERTY }; @@ -332,6 +335,9 @@ gtk_list_box_get_property (GObject *obj, case PROP_ACCEPT_UNPAIRED_RELEASE: g_value_set_boolean (value, priv->accept_unpaired_release); break; + case PROP_SHOW_SEPARATORS: + g_value_set_boolean (value, priv->show_separators); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -357,6 +363,9 @@ gtk_list_box_set_property (GObject *obj, case PROP_ACCEPT_UNPAIRED_RELEASE: gtk_list_box_set_accept_unpaired_release (box, g_value_get_boolean (value)); break; + case PROP_SHOW_SEPARATORS: + gtk_list_box_set_show_separators (box, g_value_get_boolean (value)); + break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); break; @@ -446,6 +455,13 @@ gtk_list_box_class_init (GtkListBoxClass *klass) FALSE, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + properties[PROP_SHOW_SEPARATORS] = + g_param_spec_boolean ("show-separators", + P_("Show separators"), + P_("Show separators between rows"), + FALSE, + G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY); + g_object_class_install_properties (object_class, LAST_PROPERTY, properties); /** @@ -3599,3 +3615,51 @@ gtk_list_box_bind_model (GtkListBox *box, g_signal_connect (priv->bound_model, "items-changed", G_CALLBACK (gtk_list_box_bound_model_changed), box); gtk_list_box_bound_model_changed (model, 0, 0, g_list_model_get_n_items (model), box); } + +/** + * gtk_list_box_set_show_separators: + * @box: a #GtkListBox + * @show_separators: %TRUE to show separators + * + * Sets whether the list box should show separators + * between rows. + */ +void +gtk_list_box_set_show_separators (GtkListBox *box, + gboolean show_separators) +{ + GtkListBoxPrivate *priv = BOX_PRIV (box); + + g_return_if_fail (GTK_IS_LIST_BOX (box)); + + if (priv->show_separators == show_separators) + return; + + priv->show_separators = show_separators; + + if (show_separators) + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (box)), "separators"); + else + gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (box)), "separators"); + + g_object_notify_by_pspec (G_OBJECT (box), properties[PROP_SHOW_SEPARATORS]); +} + +/** + * gtk_list_box_get_show_separators: + * @box: a #GtkListBox + * + * Returns whether the list box should show separators + * between rows. + * + * Returns: %TRUE if the list box shows separators + */ +gboolean +gtk_list_box_get_show_separators (GtkListBox *box) +{ + GtkListBoxPrivate *priv = BOX_PRIV (box); + + g_return_if_fail (GTK_IS_LIST_BOX (box)); + + return priv->show_separators; +} diff --git a/gtk/gtklistbox.h b/gtk/gtklistbox.h index 4640f6a4f9..9ad9e5cf18 100644 --- a/gtk/gtklistbox.h +++ b/gtk/gtklistbox.h @@ -300,6 +300,12 @@ void gtk_list_box_bind_model (GtkListBox gpointer user_data, GDestroyNotify user_data_free_func); +GDK_AVAILABLE_IN_ALL +void gtk_list_box_set_show_separators (GtkListBox *box, + gboolean show_separators); +GDK_AVAILABLE_IN_ALL +gboolean gtk_list_box_get_show_separators (GtkListBox *box); + G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBox, g_object_unref) G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListBoxRow, g_object_unref)