[gtk/wip/otte/lottie] xxx ottie
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/lottie] xxx ottie
- Date: Thu, 31 Dec 2020 05:23:33 +0000 (UTC)
commit 910a1b041c8b2df89ae1790a2437f68444873a32
Author: Benjamin Otte <otte redhat com>
Date: Thu Dec 31 06:20:49 2020 +0100
xxx ottie
ottie/meson.build | 1 +
ottie/ottieobject.c | 113 ++++++++++++-----------
ottie/ottieparamspec.c | 202 ++++++++++++++++++++++++++++++++++++++++++
ottie/ottieparamspecprivate.h | 85 ++++++++++++++++++
4 files changed, 343 insertions(+), 58 deletions(-)
---
diff --git a/ottie/meson.build b/ottie/meson.build
index 6dc8d1d6fa..a26de725a5 100644
--- a/ottie/meson.build
+++ b/ottie/meson.build
@@ -15,6 +15,7 @@ ottie_private_sources = files([
'ottielayer.c',
'ottienulllayer.c',
'ottieobject.c',
+ 'ottieparamspec.c',
'ottieparser.c',
'ottiepathshape.c',
'ottiepathvalue.c',
diff --git a/ottie/ottieobject.c b/ottie/ottieobject.c
index 5720555b77..fa0ac57749 100644
--- a/ottie/ottieobject.c
+++ b/ottie/ottieobject.c
@@ -22,6 +22,7 @@
#include "ottieobjectprivate.h"
#include "ottieintl.h"
+#include "ottieparamspecprivate.h"
enum {
PROP_0,
@@ -33,56 +34,52 @@ enum {
static GParamSpec *properties[N_PROPS] = { NULL, };
-G_DEFINE_TYPE (OttieObject, ottie_object, G_TYPE_OBJECT)
-
-static void
-ottie_object_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-
+static GType
+ottie_type_register_static_simple (GType parent_type,
+ const gchar *type_name,
+ guint class_size,
+ GClassInitFunc class_init,
+ GBaseInitFunc base_init,
+ guint instance_size,
+ GInstanceInitFunc instance_init,
+ GTypeFlags flags)
{
- OttieObject *self = OTTIE_OBJECT (object);
-
- switch (prop_id)
- {
- case PROP_MATCH_NAME:
- ottie_object_set_match_name (self, g_value_get_string (value));
- break;
-
- case PROP_NAME:
- ottie_object_set_name (self, g_value_get_string (value));
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
+ GTypeInfo info;
+
+ /* Instances are not allowed to be larger than this. If you have a big
+ * fixed-length array or something, point to it instead.
+ */
+ g_return_val_if_fail (class_size <= G_MAXUINT16, G_TYPE_INVALID);
+ g_return_val_if_fail (instance_size <= G_MAXUINT16, G_TYPE_INVALID);
+
+ info.class_size = class_size;
+ info.base_init = base_init;
+ info.base_finalize = NULL;
+ info.class_init = class_init;
+ info.class_finalize = NULL;
+ info.class_data = NULL;
+ info.instance_size = instance_size;
+ info.n_preallocs = 0;
+ info.instance_init = instance_init;
+ info.value_table = NULL;
+
+ return g_type_register_static (parent_type, type_name, &info, flags);
}
static void
-ottie_object_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ottie_object_base_init (gpointer g_class)
{
- OttieObject *self = OTTIE_OBJECT (object);
+ OttieObjectClass *klass = OTTIE_OBJECT_CLASS (g_class);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- switch (prop_id)
- {
- case PROP_MATCH_NAME:
- g_value_set_string (value, self->match_name);
- break;
+ object_class->get_property = ottie_param_spec_get_property;
+ object_class->set_property = ottie_param_spec_set_property;
+}
- case PROP_NAME:
- g_value_set_string (value, self->name);
- break;
+#define g_type_register_static_simple(parent_type, type_name, class_size, class_init, instance_size,
instance_init, flags) \
+ ottie_type_register_static_simple (parent_type, type_name, class_size, class_init, ottie_object_base_init,
instance_size, instance_init, flags)
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
+G_DEFINE_TYPE (OttieObject, ottie_object, G_TYPE_OBJECT)
static void
ottie_object_dispose (GObject *object)
@@ -96,29 +93,29 @@ ottie_object_dispose (GObject *object)
}
static void
-ottie_object_class_init (OttieObjectClass *class)
+ottie_object_class_init (OttieObjectClass *klass)
{
- GObjectClass *gobject_class = G_OBJECT_CLASS (class);
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
- gobject_class->set_property = ottie_object_set_property;
- gobject_class->get_property = ottie_object_get_property;
gobject_class->dispose = ottie_object_dispose;
properties[PROP_NAME] =
- g_param_spec_string ("name",
- P_("Name"),
- P_("User-given name"),
- NULL,
- G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
+ ottie_param_spec_string (gobject_class,
+ "name",
+ P_("Name"),
+ P_("User-given name"),
+ NULL,
+ (void *) ottie_object_get_name,
+ (void *) ottie_object_set_name);
properties[PROP_MATCH_NAME] =
- g_param_spec_string ("match-name",
- P_("Match name"),
- P_("Name for matching in scripts"),
- NULL,
- G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
-
- g_object_class_install_properties (gobject_class, N_PROPS, properties);
+ ottie_param_spec_string (gobject_class,
+ "match-name",
+ P_("Match name"),
+ P_("Name for matching in scripts"),
+ NULL,
+ (void *) ottie_object_get_match_name,
+ (void *) ottie_object_set_match_name);
}
static void
diff --git a/ottie/ottieparamspec.c b/ottie/ottieparamspec.c
new file mode 100644
index 0000000000..ed09a40cc0
--- /dev/null
+++ b/ottie/ottieparamspec.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright © 2020 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 "ottieparamspecprivate.h"
+
+G_DEFINE_TYPE (OttieParamSpec, ottie_param_spec, G_TYPE_PARAM);
+
+static void
+ottie_param_spec_class_init (OttieParamSpecClass *klass)
+{
+}
+
+static void
+ottie_param_spec_init (OttieParamSpec *self)
+{
+}
+
+void
+ottie_param_spec_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ OttieParamSpec *ospec = OTTIE_PARAM_SPEC (pspec);
+ OttieParamSpecClass *ospec_class = OTTIE_PARAM_SPEC_GET_CLASS (ospec);
+
+ ospec_class->set_property (ospec, object, value);
+}
+
+void
+ottie_param_spec_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ OttieParamSpec *ospec = OTTIE_PARAM_SPEC (pspec);
+ OttieParamSpecClass *ospec_class = OTTIE_PARAM_SPEC_GET_CLASS (ospec);
+
+ ospec_class->get_property (ospec, object, value);
+}
+
+static void
+ottie_param_install_pspec (GObjectClass *oclass,
+ GParamSpec *pspec)
+{
+ guint n_properties;
+
+ g_free (g_object_class_list_properties (oclass, &n_properties));
+
+ g_object_class_install_property (oclass, n_properties + 1, pspec);
+}
+
+/*** STRING ***/
+
+typedef struct _OttieParamSpecString OttieParamSpecString;
+typedef struct _OttieParamSpecStringClass OttieParamSpecStringClass;
+
+struct _OttieParamSpecString
+{
+ OttieParamSpec parent_instance;
+
+ gchar *default_value;
+ const char *(* getter) (gpointer);
+ void (* setter) (gpointer, const char *);
+};
+
+struct _OttieParamSpecStringClass
+{
+ OttieParamSpecClass parent_class;
+};
+
+G_DEFINE_TYPE (OttieParamSpecString, ottie_param_spec_string, OTTIE_TYPE_PARAM_SPEC);
+
+static void
+ottie_param_spec_string_get_property (OttieParamSpec *pspec,
+ GObject *object,
+ GValue *value)
+{
+ OttieParamSpecString *self = OTTIE_PARAM_SPEC_STRING (pspec);
+
+ g_value_set_string (value, self->getter (object));
+}
+
+static void
+ottie_param_spec_string_set_property (OttieParamSpec *pspec,
+ GObject *object,
+ const GValue *value)
+{
+ OttieParamSpecString *self = OTTIE_PARAM_SPEC_STRING (pspec);
+
+ self->setter (object, g_value_get_string (value));
+}
+
+static void
+ottie_param_spec_string_finalize (GParamSpec *pspec)
+{
+ GParamSpecString *sspec = G_PARAM_SPEC_STRING (pspec);
+ GParamSpecClass *parent_class = g_type_class_peek (g_type_parent (G_TYPE_PARAM_STRING));
+
+ g_clear_pointer (&sspec->default_value, g_free);
+
+ parent_class->finalize (pspec);
+}
+
+static void
+ottie_param_spec_string_set_default (GParamSpec *pspec,
+ GValue *value)
+{
+ g_value_set_string (value, G_PARAM_SPEC_STRING (pspec)->default_value);
+}
+
+static gboolean
+ottie_param_spec_string_validate (GParamSpec *pspec,
+ GValue *value)
+{
+ return FALSE;
+}
+
+static int
+ottie_param_spec_string_values_cmp (GParamSpec *pspec,
+ const GValue *value1,
+ const GValue *value2)
+{
+ return g_strcmp0 (g_value_get_string (value1),
+ g_value_get_string (value2));
+}
+
+static void
+ottie_param_spec_string_class_init (OttieParamSpecStringClass *klass)
+{
+ GParamSpecClass *gparam_class = G_PARAM_SPEC_CLASS (klass);
+ OttieParamSpecClass *oparam_class = OTTIE_PARAM_SPEC_CLASS (klass);
+
+ oparam_class->get_property = ottie_param_spec_string_get_property;
+ oparam_class->set_property = ottie_param_spec_string_set_property;
+
+ gparam_class->value_type = G_TYPE_STRING;
+ gparam_class->finalize = ottie_param_spec_string_finalize;
+ gparam_class->value_set_default = ottie_param_spec_string_set_default;
+ gparam_class->value_validate = ottie_param_spec_string_validate;
+ gparam_class->values_cmp = ottie_param_spec_string_values_cmp;
+}
+
+static void
+ottie_param_spec_string_init (OttieParamSpecString *self)
+{
+ self->default_value = NULL;
+}
+
+GParamSpec *
+ottie_param_spec_string (GObjectClass *klass,
+ const char *name,
+ const char *nick,
+ const char *blurb,
+ const char *default_value,
+ const char *(* getter) (gpointer),
+ void (* setter) (gpointer, const char *))
+{
+ OttieParamSpecString *self;
+ GParamFlags flags;
+
+ flags = G_PARAM_STATIC_STRINGS | G_PARAM_EXPLICIT_NOTIFY;
+ if (getter)
+ flags |= G_PARAM_READABLE;
+ if (setter)
+ flags |= G_PARAM_WRITABLE;
+
+ self = g_param_spec_internal (OTTIE_TYPE_PARAM_SPEC_STRING,
+ name,
+ nick,
+ blurb,
+ flags);
+ if (self == NULL)
+ return NULL;
+
+ g_free (self->default_value);
+ self->default_value = g_strdup (default_value);
+ self->getter = getter;
+ self->setter = setter;
+
+ ottie_param_install_pspec (klass, G_PARAM_SPEC (self));
+
+ return G_PARAM_SPEC (self);
+}
diff --git a/ottie/ottieparamspecprivate.h b/ottie/ottieparamspecprivate.h
new file mode 100644
index 0000000000..2122a13bde
--- /dev/null
+++ b/ottie/ottieparamspecprivate.h
@@ -0,0 +1,85 @@
+/*
+ * Copyright © 2020 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 __OTTIE_PARAM_SPEC_PRIVATE_H__
+#define __OTTIE_PARAM_SPEC_PRIVATE_H__
+
+#include <gsk/gsk.h>
+
+#include "ottietypesprivate.h"
+
+G_BEGIN_DECLS
+
+#define OTTIE_TYPE_PARAM_SPEC (ottie_param_spec_get_type())
+#define OTTIE_PARAM_SPEC(self) (G_TYPE_CHECK_INSTANCE_CAST ((self), OTTIE_TYPE_PARAM_SPEC,
OttieParamSpec))
+#define OTTIE_PARAM_SPEC_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), OTTIE_TYPE_PARAM_SPEC,
OttieParamSpecClass))
+#define OTTIE_IS_PARAM_SPEC(self) (G_TYPE_CHECK_INSTANCE_TYPE ((self), OTTIE_TYPE_PARAM_SPEC))
+#define OTTIE_IS_PARAM_SPEC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), OTTIE_TYPE_PARAM_SPEC))
+#define OTTIE_PARAM_SPEC_GET_CLASS(self) (G_TYPE_INSTANCE_GET_CLASS ((self), OTTIE_TYPE_PARAM_SPEC,
OttieParamSpecClass))
+
+typedef struct _OttieParamSpec OttieParamSpec;
+typedef struct _OttieParamSpecClass OttieParamSpecClass;
+
+struct _OttieParamSpec
+{
+ GParamSpec parent;
+};
+
+struct _OttieParamSpecClass
+{
+ GParamSpecClass parent_class;
+
+ void (* get_property) (OttieParamSpec *pspec,
+ GObject *object,
+ GValue *value);
+ void (* set_property) (OttieParamSpec *pspec,
+ GObject *object,
+ const GValue *value);
+};
+
+GType ottie_param_spec_get_type (void) G_GNUC_CONST;
+
+void ottie_param_spec_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec);
+void ottie_param_spec_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec);
+
+#define OTTIE_TYPE_PARAM_SPEC_STRING (ottie_param_spec_string_get_type())
+#define OTTIE_PARAM_SPEC_STRING(self) (G_TYPE_CHECK_INSTANCE_CAST ((self),
OTTIE_TYPE_PARAM_SPEC_STRING, OttieParamSpecString))
+#define OTTIE_PARAM_SPEC_STRING_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
OTTIE_TYPE_PARAM_SPEC_STRING, OttieParamSpecStringClass))
+#define OTTIE_IS_PARAM_SPEC_STRING(self) (G_TYPE_CHECK_INSTANCE_TYPE ((self),
OTTIE_TYPE_PARAM_SPEC_STRING))
+#define OTTIE_IS_PARAM_SPEC_STRING_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
OTTIE_TYPE_PARAM_SPEC_STRING))
+#define OTTIE_PARAM_SPEC_STRING_GET_CLASS(self) (G_TYPE_INSTANCE_GET_CLASS ((self),
OTTIE_TYPE_PARAM_SPEC_STRING, OttieParamSpecStringClass))
+GType ottie_param_spec_string_get_type (void) G_GNUC_CONST;
+
+GParamSpec * ottie_param_spec_string (GObjectClass *klass,
+ const char *name,
+ const char *nick,
+ const char *blurb,
+ const char *default_value,
+ const char *(* getter)
(gpointer),
+ void (* setter)
(gpointer, const char *));
+
+G_END_DECLS
+
+#endif /* __OTTIE_PARAM_SPEC_PRIVATE_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]