From bb7ed43eac13fb5271dc2a6a61142228317d041b Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Mon, 5 Jun 2023 13:17:53 +0200 Subject: [PATCH] app: make the GimpResource dummy class the parent of GimpData It does absolutely nothing except sitting there, providing an is-a relation (both ways because GimpData is its only subclass). This will simplify having more libgimp API on GimpResource, without having to add different PDB code for app and libgimp. --- app/core/core-types.h | 1 + app/core/gimpdata.c | 2 +- app/core/gimpdata.h | 6 +++--- app/core/gimpresource.c | 20 ++++---------------- app/core/gimpresource.h | 29 +++++++++++++++++++++++------ app/plug-in/gimpgpparams.c | 11 +++-------- libgimp/gimpparamspecs-body.c | 4 ---- 7 files changed, 35 insertions(+), 38 deletions(-) diff --git a/app/core/core-types.h b/app/core/core-types.h index 43b1a2f687..a3a934c7c0 100644 --- a/app/core/core-types.h +++ b/app/core/core-types.h @@ -139,6 +139,7 @@ typedef struct _GimpToolItem GimpToolItem; typedef struct _GimpDataFactory GimpDataFactory; typedef struct _GimpDataLoaderFactory GimpDataLoaderFactory; +typedef struct _GimpResource GimpResource; typedef struct _GimpData GimpData; typedef struct _GimpBrush GimpBrush; typedef struct _GimpBrushCache GimpBrushCache; diff --git a/app/core/gimpdata.c b/app/core/gimpdata.c index 648d8362ec..7dc15fccbd 100644 --- a/app/core/gimpdata.c +++ b/app/core/gimpdata.c @@ -109,7 +109,7 @@ static gchar * gimp_data_get_identifier (GimpTagged *tagged); static gchar * gimp_data_get_checksum (GimpTagged *tagged); -G_DEFINE_TYPE_WITH_CODE (GimpData, gimp_data, GIMP_TYPE_VIEWABLE, +G_DEFINE_TYPE_WITH_CODE (GimpData, gimp_data, GIMP_TYPE_RESOURCE, G_ADD_PRIVATE (GimpData) G_IMPLEMENT_INTERFACE (GIMP_TYPE_TAGGED, gimp_data_tagged_iface_init)) diff --git a/app/core/gimpdata.h b/app/core/gimpdata.h index 980cf7d6a2..fa8f05191d 100644 --- a/app/core/gimpdata.h +++ b/app/core/gimpdata.h @@ -22,7 +22,7 @@ #define __GIMP_DATA_H__ -#include "gimpviewable.h" +#include "gimpresource.h" typedef enum @@ -47,14 +47,14 @@ typedef struct _GimpDataClass GimpDataClass; struct _GimpData { - GimpViewable parent_instance; + GimpResource parent_instance; GimpDataPrivate *priv; }; struct _GimpDataClass { - GimpViewableClass parent_class; + GimpResourceClass parent_class; /* signals */ void (* dirty) (GimpData *data); diff --git a/app/core/gimpresource.c b/app/core/gimpresource.c index 19a709a1db..c0caba915c 100644 --- a/app/core/gimpresource.c +++ b/app/core/gimpresource.c @@ -22,32 +22,20 @@ #include #include +#include "core-types.h" + #include "gimpresource.h" - /* This class exists to support gimp_param_spec_resource, - * which is needed to communicate with libgimp. - * So that gimp_param_spec_resource has a GIMP_TYPE_RESOURCE on the app side. - * - * This class on libgimp side is a superclass. - * On app side of wire, it is not a superclass (e.g. GimpBrush does not inherit.) - * On app side, the class is never inherited and never instantiated. - * - * The code is derived from libgimp/gimpresource.c - */ + +G_DEFINE_TYPE (GimpResource, gimp_resource, GIMP_TYPE_VIEWABLE) -G_DEFINE_TYPE (GimpResource, gimp_resource, G_TYPE_OBJECT) - -/* Class construction */ static void gimp_resource_class_init (GimpResourceClass *klass) { - g_debug("gimp_resource_class_init"); } -/* Instance construction. */ static void gimp_resource_init (GimpResource *self) { - g_debug("gimp_resource_init"); } diff --git a/app/core/gimpresource.h b/app/core/gimpresource.h index 5e593f4769..d5c96f2b40 100644 --- a/app/core/gimpresource.h +++ b/app/core/gimpresource.h @@ -18,15 +18,32 @@ #ifndef __GIMP_RESOURCE_H__ #define __GIMP_RESOURCE_H__ -#define GIMP_TYPE_RESOURCE (gimp_resource_get_type ()) -G_DECLARE_DERIVABLE_TYPE (GimpResource, gimp_resource, GIMP, RESOURCE, GObject) + +#include "gimpviewable.h" + + +#define GIMP_TYPE_RESOURCE (gimp_resource_get_type ()) +#define GIMP_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_RESOURCE, GimpResource)) +#define GIMP_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_RESOURCE, GimpResourceClass)) +#define GIMP_IS_RESOURCE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_RESOURCE)) +#define GIMP_IS_RESOURCE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_RESOURCE)) +#define GIMP_RESOURCE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_RESOURCE, GimpResourceClass)) + + +typedef struct _GimpResourceClass GimpResourceClass; + +struct _GimpResource +{ + GimpViewable parent_instance; +}; struct _GimpResourceClass { - GObjectClass parent_class; - - /* Padding for future expansion */ - gpointer padding[8]; + GimpViewableClass parent_class; }; + +GType gimp_resource_get_type (void) G_GNUC_CONST; + + #endif /* __GIMP_RESOURCE_H__ */ diff --git a/app/plug-in/gimpgpparams.c b/app/plug-in/gimpgpparams.c index e6b416cfc4..90aa21721f 100644 --- a/app/plug-in/gimpgpparams.c +++ b/app/plug-in/gimpgpparams.c @@ -31,16 +31,15 @@ #include "plug-in-types.h" #include "core/gimp.h" +#include "core/gimpbrush.h" #include "core/gimpdisplay.h" +#include "core/gimpgradient.h" #include "core/gimpimage.h" #include "core/gimplayer.h" #include "core/gimplayermask.h" -#include "core/gimpselection.h" -/* resource types. */ -#include "core/gimpbrush.h" -#include "core/gimpgradient.h" #include "core/gimppalette.h" #include "core/gimppattern.h" +#include "core/gimpselection.h" #include "text/gimpfont.h" #include "core/gimpparamspecs.h" @@ -52,10 +51,6 @@ #include "libgimp/gimpgpparams.h" -#undef GIMP_VALUE_HOLDS_RESOURCE -#define GIMP_VALUE_HOLDS_RESOURCE(value) (G_TYPE_CHECK_VALUE_TYPE ((value), \ - GIMP_TYPE_DATA)) - /* include the implementation, they are shared between app/ and * libgimp/ but need different headers. */ diff --git a/libgimp/gimpparamspecs-body.c b/libgimp/gimpparamspecs-body.c index ac86abafb3..04b0df83dc 100644 --- a/libgimp/gimpparamspecs-body.c +++ b/libgimp/gimpparamspecs-body.c @@ -942,11 +942,7 @@ gimp_param_spec_display (const gchar *name, static void gimp_param_resource_class_init (GParamSpecClass *klass) { -#ifdef LIBGIMP_COMPILATION klass->value_type = GIMP_TYPE_RESOURCE; -#else - klass->value_type = GIMP_TYPE_DATA; -#endif klass->value_validate = gimp_param_resource_validate; }