[gtk/wip/otte/listview: 2/47] Add GtkListBase



commit 521e5af0a34c2cec960a80c3e48699273cf864d6
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 fe12b62d0d..fdc609057c 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 a5df67db17..7eb7e359d5 100644
--- a/gtk/gtk-autocleanups.h
+++ b/gtk/gtk-autocleanups.h
@@ -82,6 +82,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)
@@ -94,6 +95,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(GtkMenuBar, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkMenuButton, g_object_unref)
diff --git a/gtk/gtk.h b/gtk/gtk.h
index 1d4f5e14e7..0725db7528 100644
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
@@ -155,6 +155,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 36944a1159..9d7cefe92d 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))
 
@@ -1986,8 +1992,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);
 }
 
 /**
@@ -2021,7 +2025,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 58ca522d30..8ec3a8f648 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -282,6 +282,7 @@ gtk_public_sources = files([
   'gtklayoutchild.c',
   'gtklayoutmanager.c',
   'gtklevelbar.c',
+  'gtklistbase.c',
   'gtklinkbutton.c',
   'gtklistbox.c',
   'gtklistitem.c',
@@ -566,6 +567,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]