diff options
author | Benjamin Otte <otte@redhat.com> | 2019-06-04 03:01:15 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-05-30 19:26:45 -0400 |
commit | 0174bf434573ee7b7e49505f72f26cdb4bd15f3d (patch) | |
tree | efb62e4b99ae056181b6137c04eca90a84ad00a4 /gtk/gtklistview.c | |
parent | 1acfae8df285e516eb8245fb999b2481714bc448 (diff) | |
download | gtk+-0174bf434573ee7b7e49505f72f26cdb4bd15f3d.tar.gz |
listview: Add gtk_list_view_set_show_separators()
Do the same thing that GtkListBox does in commit
0249bd4f8a03ec473f3ca9d4324a3a8b75bd3f44
Diffstat (limited to 'gtk/gtklistview.c')
-rw-r--r-- | gtk/gtklistview.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c index f2363d9661..42cbc07ebd 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -29,6 +29,7 @@ #include "gtkscrollable.h" #include "gtkselectionmodel.h" #include "gtksingleselection.h" +#include "gtkstylecontext.h" #include "gtkwidgetprivate.h" /* Maximum number of list items created by the listview. @@ -60,6 +61,7 @@ struct _GtkListView GtkListItemManager *item_manager; GtkAdjustment *adjustment[2]; GtkScrollablePolicy scroll_policy[2]; + gboolean show_separators; int list_width; @@ -85,6 +87,7 @@ enum PROP_HADJUSTMENT, PROP_HSCROLL_POLICY, PROP_MODEL, + PROP_SHOW_SEPARATORS, PROP_VADJUSTMENT, PROP_VSCROLL_POLICY, @@ -600,6 +603,10 @@ gtk_list_view_get_property (GObject *object, g_value_set_object (value, self->model); break; + case PROP_SHOW_SEPARATORS: + g_value_set_boolean (value, self->show_separators); + break; + case PROP_VADJUSTMENT: g_value_set_object (value, self->adjustment[GTK_ORIENTATION_VERTICAL]); break; @@ -677,6 +684,10 @@ gtk_list_view_set_property (GObject *object, gtk_list_view_set_model (self, g_value_get_object (value)); break; + case PROP_SHOW_SEPARATORS: + gtk_list_view_set_show_separators (self, g_value_get_boolean (value)); + break; + case PROP_VADJUSTMENT: gtk_list_view_set_adjustment (self, GTK_ORIENTATION_VERTICAL, g_value_get_object (value)); break; @@ -761,6 +772,18 @@ gtk_list_view_class_init (GtkListViewClass *klass) G_TYPE_LIST_MODEL, G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS); + /** + * GtkListView:show-separators: + * + * Show separators between rows + */ + 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 (gobject_class, N_PROPS, properties); /** @@ -897,3 +920,46 @@ gtk_list_view_set_functions (GtkListView *self, g_object_unref (factory); } +/** + * gtk_list_view_set_show_separators: + * @self: a #GtkListView + * @show_separators: %TRUE to show separators + * + * Sets whether the list box should show separators + * between rows. + */ +void +gtk_list_view_set_show_separators (GtkListView *self, + gboolean show_separators) +{ + g_return_if_fail (GTK_IS_LIST_VIEW (self)); + + if (self->show_separators == show_separators) + return; + + self->show_separators = show_separators; + + if (show_separators) + gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "separators"); + else + gtk_style_context_remove_class (gtk_widget_get_style_context (GTK_WIDGET (self)), "separators"); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SHOW_SEPARATORS]); +} + +/** + * gtk_list_view_get_show_separators: + * @self: a #GtkListView + * + * Returns whether the list box should show separators + * between rows. + * + * Returns: %TRUE if the list box shows separators + */ +gboolean +gtk_list_view_get_show_separators (GtkListView *self) +{ + g_return_val_if_fail (GTK_IS_LIST_VIEW (self), FALSE); + + return self->show_separators; +} |