[gtk/listview-for-merge: 67/181] listview: Add gtk_list_view_set_show_separators()



commit d1228f08c426c932bc6ca8868fe2e7bb9a71546d
Author: Benjamin Otte <otte redhat com>
Date:   Tue Jun 4 03:01:15 2019 +0200

    listview: Add gtk_list_view_set_show_separators()
    
    Do the same thing that GtkListBox does in commit
    0249bd4f8a03ec473f3ca9d4324a3a8b75bd3f44

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtklistview.c                    | 66 ++++++++++++++++++++++++++++++++++++
 gtk/gtklistview.h                    |  6 ++++
 3 files changed, 74 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 3b7cc1e87e..cb0a87b207 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -436,6 +436,8 @@ GtkListView
 gtk_list_view_new
 gtk_list_view_set_model
 gtk_list_view_get_model
+gtk_list_view_set_show_separators
+gtk_list_view_get_show_separators
 <SUBSECTION Standard>
 GTK_LIST_VIEW
 GTK_LIST_VIEW_CLASS
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;
+}
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index 4d1a0a5d77..77d8d502ab 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -49,6 +49,12 @@ void            gtk_list_view_set_functions                     (GtkListView
                                                                  gpointer                user_data,
                                                                  GDestroyNotify          user_destroy);
 
+GDK_AVAILABLE_IN_ALL
+void            gtk_list_view_set_show_separators               (GtkListView            *self,
+                                                                 gboolean                show_separators);
+GDK_AVAILABLE_IN_ALL
+gboolean        gtk_list_view_get_show_separators               (GtkListView            *self);
+
 G_END_DECLS
 
 #endif  /* __GTK_LIST_VIEW_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]