[gtk/wip/matthiasc/listview-2: 116/168] Add GtkListBase



commit 4849a593a4663c03173ef049fd4de45b36aa5abf
Author: Benjamin Otte <otte redhat com>
Date:   Tue Oct 22 08:01:16 2019 +0200

    Add GtkListBase
    
    This is a base item for GTK's list widgets so they can share some (read:
    hopefully a lot of) code.

 docs/reference/gtk/meson.build |  1 +
 gtk/gtk-autocleanups.h         |  2 ++
 gtk/gtk.h                      |  1 +
 gtk/gtkgridview.c              | 14 ++++++++----
 gtk/gtkgridview.h              | 18 +++++++++++++--
 gtk/gtklistbase.c              | 36 +++++++++++++++++++++++++++++
 gtk/gtklistbase.h              | 52 ++++++++++++++++++++++++++++++++++++++++++
 gtk/gtklistbaseprivate.h       | 36 +++++++++++++++++++++++++++++
 gtk/gtklistview.c              | 12 ++++++----
 gtk/gtklistview.h              | 18 ++++++++++++---
 gtk/meson.build                |  2 ++
 11 files changed, 178 insertions(+), 14 deletions(-)
---
diff --git a/docs/reference/gtk/meson.build b/docs/reference/gtk/meson.build
index e2aa759385..b0e685f64a 100644
--- a/docs/reference/gtk/meson.build
+++ b/docs/reference/gtk/meson.build
@@ -132,6 +132,7 @@ private_headers = [
   'gtkimmoduleprivate.h',
   'gtkkineticscrollingprivate.h',
   'gtklabelprivate.h',
+  'gtklistbaseprivate.h',
   'gtklistitemprivate.h',
   'gtklistitemfactoryprivate.h',
   'gtklistitemmanagerprivate.h',
diff --git a/gtk/gtk-autocleanups.h b/gtk/gtk-autocleanups.h
index 59474fc967..f7bc1f30f1 100644
--- a/gtk/gtk-autocleanups.h
+++ b/gtk/gtk-autocleanups.h
@@ -91,6 +91,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureSingle, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureSwipe, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGestureZoom, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGrid, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGridView, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkHeaderBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkIMContext, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkIMContextSimple, g_object_unref)
@@ -103,6 +104,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkInfoBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLevelBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLinkButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListStore, g_object_unref)
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkListView, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLockButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenuButton, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMessageDialog, g_object_unref)
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 1a2f2111f4..31cd5c8138 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -154,6 +154,7 @@
 #include <gtk/gtklayoutmanager.h>
 #include <gtk/gtklayoutchild.h>
 #include <gtk/gtklevelbar.h>
+#include <gtk/gtklistbase.h>
 #include <gtk/gtklinkbutton.h>
 #include <gtk/gtklistbox.h>
 #include <gtk/gtklistitem.h>
diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c
index c5c6418f73..c8957519ec 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -23,6 +23,7 @@
 
 #include "gtkadjustment.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemfactory.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
@@ -58,7 +59,7 @@ typedef struct _CellAugment CellAugment;
 
 struct _GtkGridView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -83,6 +84,11 @@ struct _GtkGridView
   GtkListItemTracker *focus;
 };
 
+struct _GtkGridViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _Cell
 {
   GtkListItemManagerItem parent;
@@ -116,7 +122,7 @@ enum {
   LAST_SIGNAL
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_WIDGET,
+G_DEFINE_TYPE_WITH_CODE (GtkGridView, gtk_grid_view, GTK_TYPE_LIST_BASE,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
 
@@ -1991,8 +1997,6 @@ gtk_grid_view_init (GtkGridView *self)
 
   self->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   self->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-
-  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
 }
 
 /**
@@ -2026,7 +2030,7 @@ gtk_grid_view_new (void)
  * argument, so you can write code like
  * ```
  *   grid_view = gtk_grid_view_new_with_factory (
- *     gtk_builder_list_item_factory_new_from_resource ("/resource.ui"));
+ *     gtk_builder_list_item_factory_newfrom_resource ("/resource.ui"));
  * ```
  *
  * Returns: a new #GtkGridView using the given @factory
diff --git a/gtk/gtkgridview.h b/gtk/gtkgridview.h
index 5c42776dbe..cba7769401 100644
--- a/gtk/gtkgridview.h
+++ b/gtk/gtkgridview.h
@@ -24,14 +24,28 @@
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkwidget.h>
+#include <gtk/gtklistbase.h>
 
 G_BEGIN_DECLS
 
 #define GTK_TYPE_GRID_VIEW         (gtk_grid_view_get_type ())
+#define GTK_GRID_VIEW(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_GRID_VIEW, GtkGridView))
+#define GTK_GRID_VIEW_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_GRID_VIEW, GtkGridViewClass))
+#define GTK_IS_GRID_VIEW(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_GRID_VIEW))
+#define GTK_IS_GRID_VIEW_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_GRID_VIEW))
+#define GTK_GRID_VIEW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_GRID_VIEW, GtkGridViewClass))
+
+/**
+ * GtkGridView:
+ *
+ * GtkGridView is a list widget implementation that arranges its items in
+ * a grid.
+ */
+typedef struct _GtkGridView GtkGridView;
+typedef struct _GtkGridViewClass GtkGridViewClass;
 
 GDK_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkGridView, gtk_grid_view, GTK, GRID_VIEW, GtkWidget)
+GType           gtk_grid_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_grid_view_new                               (void);
diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c
new file mode 100644
index 0000000000..e46b4f29d0
--- /dev/null
+++ b/gtk/gtklistbase.c
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#include "config.h"
+
+#include "gtklistbaseprivate.h"
+
+G_DEFINE_ABSTRACT_TYPE (GtkListBase, gtk_list_base, GTK_TYPE_WIDGET)
+
+static void
+gtk_list_base_class_init (GtkListBaseClass *klass)
+{
+}
+
+static void
+gtk_list_base_init (GtkListBase *self)
+{
+  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
+}
+
diff --git a/gtk/gtklistbase.h b/gtk/gtklistbase.h
new file mode 100644
index 0000000000..7b33edeec7
--- /dev/null
+++ b/gtk/gtklistbase.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_LIST_BASE_H__
+#define __GTK_LIST_BASE_H__
+
+#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
+#error "Only <gtk/gtk.h> can be included directly."
+#endif
+
+#include <gtk/gtkwidget.h>
+#include <gtk/gtklistitem.h>
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_LIST_BASE         (gtk_list_base_get_type ())
+#define GTK_LIST_BASE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_BASE, GtkListBase))
+#define GTK_LIST_BASE_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_BASE, GtkListBaseClass))
+#define GTK_IS_LIST_BASE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_BASE))
+#define GTK_IS_LIST_BASE_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_BASE))
+#define GTK_LIST_BASE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_BASE, GtkListBaseClass))
+
+/**
+ * GtkListBase:
+ *
+ * GtkListBase is the abstract base class for GTK's list widgets.
+ */
+typedef struct _GtkListBase GtkListBase;
+typedef struct _GtkListBaseClass GtkListBaseClass;
+
+GDK_AVAILABLE_IN_ALL
+GType                   gtk_list_base_get_type                  (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif  /* __GTK_LIST_BASE_H__ */
diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h
new file mode 100644
index 0000000000..cfd704f611
--- /dev/null
+++ b/gtk/gtklistbaseprivate.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright © 2019 Benjamin Otte
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Benjamin Otte <otte gnome org>
+ */
+
+#ifndef __GTK_LIST_BASE_PRIVATE_H__
+#define __GTK_LIST_BASE_PRIVATE_H__
+
+#include "gtklistbase.h"
+
+struct _GtkListBase
+{
+  GtkWidget parent_instance;
+};
+
+struct _GtkListBaseClass
+{
+  GtkWidgetClass parent_class;
+};
+
+
+#endif /* __GTK_LIST_BASE_PRIVATE_H__ */
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 828f442258..3a9e67dfc7 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -23,6 +23,7 @@
 
 #include "gtkadjustment.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
 #include "gtkorientableprivate.h"
@@ -58,7 +59,7 @@ typedef struct _ListRowAugment ListRowAugment;
 
 struct _GtkListView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -78,6 +79,11 @@ struct _GtkListView
   GtkListItemTracker *focus;
 };
 
+struct _GtkListViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _ListRow
 {
   GtkListItemManagerItem parent;
@@ -110,7 +116,7 @@ enum {
   LAST_SIGNAL
 };
 
-G_DEFINE_TYPE_WITH_CODE (GtkListView, gtk_list_view, GTK_TYPE_WIDGET,
+G_DEFINE_TYPE_WITH_CODE (GtkListView, gtk_list_view, GTK_TYPE_LIST_BASE,
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)
                          G_IMPLEMENT_INTERFACE (GTK_TYPE_SCROLLABLE, NULL))
 
@@ -1657,8 +1663,6 @@ gtk_list_view_init (GtkListView *self)
 
   self->adjustment[GTK_ORIENTATION_HORIZONTAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
   self->adjustment[GTK_ORIENTATION_VERTICAL] = gtk_adjustment_new (0.0, 0.0, 0.0, 0.0, 0.0, 0.0);
-
-  gtk_widget_set_overflow (GTK_WIDGET (self), GTK_OVERFLOW_HIDDEN);
 }
 
 /**
diff --git a/gtk/gtklistview.h b/gtk/gtklistview.h
index 205cf8e9aa..3d5f6a8a56 100644
--- a/gtk/gtklistview.h
+++ b/gtk/gtklistview.h
@@ -24,15 +24,27 @@
 #error "Only <gtk/gtk.h> can be included directly."
 #endif
 
-#include <gtk/gtkwidget.h>
-#include <gtk/gtklistitem.h>
+#include <gtk/gtklistbase.h>
 
 G_BEGIN_DECLS
 
 #define GTK_TYPE_LIST_VIEW         (gtk_list_view_get_type ())
+#define GTK_LIST_VIEW(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_LIST_VIEW, GtkListView))
+#define GTK_LIST_VIEW_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST ((k), GTK_TYPE_LIST_VIEW, GtkListViewClass))
+#define GTK_IS_LIST_VIEW(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_LIST_VIEW))
+#define GTK_IS_LIST_VIEW_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), GTK_TYPE_LIST_VIEW))
+#define GTK_LIST_VIEW_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GTK_TYPE_LIST_VIEW, GtkListViewClass))
+
+/**
+ * GtkListView:
+ *
+ * GtkListView is the simple list implementation for GTK's list widgets.
+ */
+typedef struct _GtkListView GtkListView;
+typedef struct _GtkListViewClass GtkListViewClass;
 
 GDK_AVAILABLE_IN_ALL
-G_DECLARE_FINAL_TYPE (GtkListView, gtk_list_view, GTK, LIST_VIEW, GtkWidget)
+GType           gtk_list_view_get_type                          (void) G_GNUC_CONST;
 
 GDK_AVAILABLE_IN_ALL
 GtkWidget *     gtk_list_view_new                               (void);
diff --git a/gtk/meson.build b/gtk/meson.build
index c52e78ea6f..f89b8bf7d9 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -272,6 +272,7 @@ gtk_public_sources = files([
   'gtklayoutchild.c',
   'gtklayoutmanager.c',
   'gtklevelbar.c',
+  'gtklistbase.c',
   'gtklinkbutton.c',
   'gtklistbox.c',
   'gtklistitem.c',
@@ -544,6 +545,7 @@ gtk_public_headers = files([
   'gtklayoutmanager.h',
   'gtklevelbar.h',
   'gtklinkbutton.h',
+  'gtklistbase.h',
   'gtklistbox.h',
   'gtklistitem.h',
   'gtklistitemfactory.h',


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