[gtk/wip/otte/listview: 212/309] listitemfactory: Split implementation out
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/listview: 212/309] listitemfactory: Split implementation out
- Date: Fri, 29 May 2020 20:30:21 +0000 (UTC)
commit 8b73507cf4a64c70abb5adcc33a7b0c89a23a697
Author: Benjamin Otte <otte redhat com>
Date: Mon Jun 10 03:43:52 2019 +0200
listitemfactory: Split implementation out
.. into gtkfunctionslistitemfactory.c
Now we can add a different implmenetation.
gtk/gtkfunctionslistitemfactory.c | 134 +++++++++++++++++++++++++++++++
gtk/gtkfunctionslistitemfactoryprivate.h | 48 +++++++++++
gtk/gtklistitemfactory.c | 44 ----------
gtk/gtklistitemfactoryprivate.h | 10 ---
gtk/gtklistview.c | 6 +-
gtk/meson.build | 1 +
6 files changed, 186 insertions(+), 57 deletions(-)
---
diff --git a/gtk/gtkfunctionslistitemfactory.c b/gtk/gtkfunctionslistitemfactory.c
new file mode 100644
index 0000000000..6841a2a36b
--- /dev/null
+++ b/gtk/gtkfunctionslistitemfactory.c
@@ -0,0 +1,134 @@
+/*
+ * 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 "gtkfunctionslistitemfactoryprivate.h"
+
+#include "gtklistitemprivate.h"
+
+struct _GtkFunctionsListItemFactory
+{
+ GtkListItemFactory parent_instance;
+
+ GtkListItemSetupFunc setup_func;
+ GtkListItemBindFunc bind_func;
+ gpointer user_data;
+ GDestroyNotify user_destroy;
+};
+
+struct _GtkFunctionsListItemFactoryClass
+{
+ GtkListItemFactoryClass parent_class;
+};
+
+G_DEFINE_TYPE (GtkFunctionsListItemFactory, gtk_functions_list_item_factory, GTK_TYPE_LIST_ITEM_FACTORY)
+
+static void
+gtk_functions_list_item_factory_setup (GtkListItemFactory *factory,
+ GtkListItem *list_item)
+{
+ GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
+
+ GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->setup (factory, list_item);
+
+ if (self->setup_func)
+ self->setup_func (list_item, self->user_data);
+}
+
+static void
+gtk_functions_list_item_factory_bind (GtkListItemFactory *factory,
+ GtkListItem *list_item,
+ guint position,
+ gpointer item,
+ gboolean selected)
+{
+ GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
+
+ GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item,
position, item, selected);
+
+ if (self->bind_func)
+ self->bind_func (list_item, self->user_data);
+}
+
+static void
+gtk_functions_list_item_factory_rebind (GtkListItemFactory *factory,
+ GtkListItem *list_item,
+ guint position,
+ gpointer item,
+ gboolean selected)
+{
+ GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (factory);
+
+ GTK_LIST_ITEM_FACTORY_CLASS (gtk_functions_list_item_factory_parent_class)->bind (factory, list_item,
position, item, selected);
+
+ if (self->bind_func)
+ self->bind_func (list_item, self->user_data);
+}
+
+static void
+gtk_functions_list_item_factory_finalize (GObject *object)
+{
+ GtkFunctionsListItemFactory *self = GTK_FUNCTIONS_LIST_ITEM_FACTORY (object);
+
+ if (self->user_destroy)
+ self->user_destroy (self->user_data);
+
+ G_OBJECT_CLASS (gtk_functions_list_item_factory_parent_class)->finalize (object);
+}
+
+static void
+gtk_functions_list_item_factory_class_init (GtkFunctionsListItemFactoryClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkListItemFactoryClass *factory_class = GTK_LIST_ITEM_FACTORY_CLASS (klass);
+
+ object_class->finalize = gtk_functions_list_item_factory_finalize;
+
+ factory_class->setup = gtk_functions_list_item_factory_setup;
+ factory_class->bind = gtk_functions_list_item_factory_bind;
+ factory_class->rebind = gtk_functions_list_item_factory_rebind;
+}
+
+static void
+gtk_functions_list_item_factory_init (GtkFunctionsListItemFactory *self)
+{
+}
+
+GtkListItemFactory *
+gtk_functions_list_item_factory_new (GtkListItemSetupFunc setup_func,
+ GtkListItemBindFunc bind_func,
+ gpointer user_data,
+ GDestroyNotify user_destroy)
+{
+ GtkFunctionsListItemFactory *self;
+
+ g_return_val_if_fail (setup_func || bind_func, NULL);
+ g_return_val_if_fail (user_data != NULL || user_destroy == NULL, NULL);
+
+ self = g_object_new (GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY, NULL);
+
+ self->setup_func = setup_func;
+ self->bind_func = bind_func;
+ self->user_data = user_data;
+ self->user_destroy = user_destroy;
+
+ return GTK_LIST_ITEM_FACTORY (self);
+}
+
diff --git a/gtk/gtkfunctionslistitemfactoryprivate.h b/gtk/gtkfunctionslistitemfactoryprivate.h
new file mode 100644
index 0000000000..aeac050a28
--- /dev/null
+++ b/gtk/gtkfunctionslistitemfactoryprivate.h
@@ -0,0 +1,48 @@
+/*
+ * 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_FUNCTIONS_LIST_ITEM_FACTORY_H__
+#define __GTK_FUNCTIONS_LIST_ITEM_FACTORY_H__
+
+#include "gtklistitemfactoryprivate.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY (gtk_functions_list_item_factory_get_type ())
+#define GTK_FUNCTIONS_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_CAST ((o),
GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY, GtkFunctionsListItemFactory))
+#define GTK_FUNCTIONS_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k),
GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY, GtkFunctionsListItemFactoryClass))
+#define GTK_IS_FUNCTIONS_LIST_ITEM_FACTORY(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o),
GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY))
+#define GTK_IS_FUNCTIONS_LIST_ITEM_FACTORY_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k),
GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY))
+#define GTK_FUNCTIONS_LIST_ITEM_FACTORY_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o),
GTK_TYPE_FUNCTIONS_LIST_ITEM_FACTORY, GtkFunctionsListItemFactoryClass))
+
+typedef struct _GtkFunctionsListItemFactory GtkFunctionsListItemFactory;
+typedef struct _GtkFunctionsListItemFactoryClass GtkFunctionsListItemFactoryClass;
+
+GType gtk_functions_list_item_factory_get_type (void) G_GNUC_CONST;
+
+GtkListItemFactory * gtk_functions_list_item_factory_new (GtkListItemSetupFunc setup_func,
+ GtkListItemBindFunc bind_func,
+ gpointer user_data,
+ GDestroyNotify user_destroy);
+
+
+G_END_DECLS
+
+#endif /* __GTK_FUNCTIONS_LIST_ITEM_FACTORY_H__ */
diff --git a/gtk/gtklistitemfactory.c b/gtk/gtklistitemfactory.c
index 1025173bd8..a6012a9285 100644
--- a/gtk/gtklistitemfactory.c
+++ b/gtk/gtklistitemfactory.c
@@ -77,8 +77,6 @@ static void
gtk_list_item_factory_default_setup (GtkListItemFactory *self,
GtkListItem *list_item)
{
- if (self->setup_func)
- self->setup_func (list_item, self->user_data);
}
static void
@@ -100,9 +98,6 @@ gtk_list_item_factory_default_bind (GtkListItemFactory *self,
gtk_list_item_set_item (list_item, item);
gtk_list_item_set_position (list_item, position);
gtk_list_item_set_selected (list_item, selected);
-
- if (self->bind_func)
- self->bind_func (list_item, self->user_data);
}
static void
@@ -115,9 +110,6 @@ gtk_list_item_factory_default_rebind (GtkListItemFactory *self,
gtk_list_item_set_item (list_item, item);
gtk_list_item_set_position (list_item, position);
gtk_list_item_set_selected (list_item, selected);
-
- if (self->bind_func)
- self->bind_func (list_item, self->user_data);
}
static void
@@ -139,24 +131,9 @@ gtk_list_item_factory_default_unbind (GtkListItemFactory *self,
gtk_list_item_set_selected (list_item, FALSE);
}
-static void
-gtk_list_item_factory_finalize (GObject *object)
-{
- GtkListItemFactory *self = GTK_LIST_ITEM_FACTORY (object);
-
- if (self->user_destroy)
- self->user_destroy (self->user_data);
-
- G_OBJECT_CLASS (gtk_list_item_factory_parent_class)->finalize (object);
-}
-
static void
gtk_list_item_factory_class_init (GtkListItemFactoryClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
-
- object_class->finalize = gtk_list_item_factory_finalize;
-
klass->setup = gtk_list_item_factory_default_setup;
klass->teardown = gtk_list_item_factory_default_teardown;
klass->bind = gtk_list_item_factory_default_bind;
@@ -170,27 +147,6 @@ gtk_list_item_factory_init (GtkListItemFactory *self)
{
}
-GtkListItemFactory *
-gtk_list_item_factory_new (GtkListItemSetupFunc setup_func,
- GtkListItemBindFunc bind_func,
- gpointer user_data,
- GDestroyNotify user_destroy)
-{
- GtkListItemFactory *self;
-
- g_return_val_if_fail (setup_func || bind_func, NULL);
- g_return_val_if_fail (user_data != NULL || user_destroy == NULL, NULL);
-
- self = g_object_new (GTK_TYPE_LIST_ITEM_FACTORY, NULL);
-
- self->setup_func = setup_func;
- self->bind_func = bind_func;
- self->user_data = user_data;
- self->user_destroy = user_destroy;
-
- return self;
-}
-
void
gtk_list_item_factory_setup (GtkListItemFactory *self,
GtkListItem *list_item)
diff --git a/gtk/gtklistitemfactoryprivate.h b/gtk/gtklistitemfactoryprivate.h
index 98ca4b350e..dc32429dd2 100644
--- a/gtk/gtklistitemfactoryprivate.h
+++ b/gtk/gtklistitemfactoryprivate.h
@@ -39,11 +39,6 @@ typedef struct _GtkListItemFactoryClass GtkListItemFactoryClass;
struct _GtkListItemFactory
{
GObject parent_instance;
-
- GtkListItemSetupFunc setup_func;
- GtkListItemBindFunc bind_func;
- gpointer user_data;
- GDestroyNotify user_destroy;
};
struct _GtkListItemFactoryClass
@@ -81,11 +76,6 @@ struct _GtkListItemFactoryClass
GType gtk_list_item_factory_get_type (void) G_GNUC_CONST;
-GtkListItemFactory * gtk_list_item_factory_new (GtkListItemSetupFunc setup_func,
- GtkListItemBindFunc bind_func,
- gpointer user_data,
- GDestroyNotify user_destroy);
-
void gtk_list_item_factory_setup (GtkListItemFactory *self,
GtkListItem *list_item);
void gtk_list_item_factory_teardown (GtkListItemFactory *self,
diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c
index 42cbc07ebd..589acc8239 100644
--- a/gtk/gtklistview.c
+++ b/gtk/gtklistview.c
@@ -23,9 +23,9 @@
#include "gtkadjustment.h"
#include "gtkintl.h"
-#include "gtkrbtreeprivate.h"
-#include "gtklistitemfactoryprivate.h"
+#include "gtkfunctionslistitemfactoryprivate.h"
#include "gtklistitemmanagerprivate.h"
+#include "gtkrbtreeprivate.h"
#include "gtkscrollable.h"
#include "gtkselectionmodel.h"
#include "gtksingleselection.h"
@@ -915,7 +915,7 @@ gtk_list_view_set_functions (GtkListView *self,
g_return_if_fail (setup_func || bind_func);
g_return_if_fail (user_data != NULL || user_destroy == NULL);
- factory = gtk_list_item_factory_new (setup_func, bind_func, user_data, user_destroy);
+ factory = gtk_functions_list_item_factory_new (setup_func, bind_func, user_data, user_destroy);
gtk_list_item_manager_set_factory (self->item_manager, factory);
g_object_unref (factory);
}
diff --git a/gtk/meson.build b/gtk/meson.build
index f45cca1cdd..befe9e92a1 100644
--- a/gtk/meson.build
+++ b/gtk/meson.build
@@ -242,6 +242,7 @@ gtk_public_sources = files([
'gtkfontchooserutils.c',
'gtkfontchooserwidget.c',
'gtkframe.c',
+ 'gtkfunctionslistitemfactory.c',
'gtkgesture.c',
'gtkgesturedrag.c',
'gtkgesturelongpress.c',
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]