[gtk/wip/otte/listview: 990/1040] Add GtkListBase



commit 77dd0351a069b2f6e22116a8b432997d53f13e46
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 1461d20daf..5d92d47303 100644
--- a/docs/reference/gtk/meson.build
+++ b/docs/reference/gtk/meson.build
@@ -131,6 +131,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 70715cf0fc..0ff657e2f0 100644
--- a/gtk/gtk-autocleanups.h
+++ b/gtk/gtk-autocleanups.h
@@ -81,6 +81,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFontChooserWidget, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkFrame, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkGLArea, 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)
@@ -93,6 +94,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(GtkMenuToolButton, g_object_unref)
diff --git a/gtk/gtk.h b/gtk/gtk.h
index a9b57a5bfa..4b700e3f15 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 90a62c0467..5775b9ea1a 100644
--- a/gtk/gtkgridview.c
+++ b/gtk/gtkgridview.c
@@ -24,6 +24,7 @@
 #include "gtkadjustment.h"
 #include "gtkbindings.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemfactory.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
@@ -59,7 +60,7 @@ typedef struct _CellAugment CellAugment;
 
 struct _GtkGridView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -84,6 +85,11 @@ struct _GtkGridView
   GtkListItemTracker *focus;
 };
 
+struct _GtkGridViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _Cell
 {
   GtkListItemManagerItem parent;
@@ -117,7 +123,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))
 
@@ -1989,8 +1995,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);
 }
 
 /**
@@ -2024,7 +2028,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 d7886f957d..a5623d1ae2 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -24,6 +24,7 @@
 #include "gtkadjustment.h"
 #include "gtkbindings.h"
 #include "gtkintl.h"
+#include "gtklistbaseprivate.h"
 #include "gtklistitemmanagerprivate.h"
 #include "gtkmain.h"
 #include "gtkorientableprivate.h"
@@ -59,7 +60,7 @@ typedef struct _ListRowAugment ListRowAugment;
 
 struct _GtkListView
 {
-  GtkWidget parent_instance;
+  GtkListBase parent_instance;
 
   GListModel *model;
   GtkListItemManager *item_manager;
@@ -79,6 +80,11 @@ struct _GtkListView
   GtkListItemTracker *focus;
 };
 
+struct _GtkListViewClass
+{
+  GtkListBaseClass parent_class;
+};
+
 struct _ListRow
 {
   GtkListItemManagerItem parent;
@@ -111,7 +117,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))
 
@@ -1654,8 +1660,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 c8eb868f69..045874159b 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -276,6 +276,7 @@ gtk_public_sources = files([
   'gtklayoutchild.c',
   'gtklayoutmanager.c',
   'gtklevelbar.c',
+  'gtklistbase.c',
   'gtklinkbutton.c',
   'gtklistbox.c',
   'gtklistitem.c',
@@ -550,6 +551,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]