[gtksourceview/wip/chergert/gsv-gtk4: 27/125] mark: modernize GtkSourceMark
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/chergert/gsv-gtk4: 27/125] mark: modernize GtkSourceMark
- Date: Wed, 15 Jan 2020 23:48:36 +0000 (UTC)
commit cd3bf262042c7638a9a26543ae4e4546a60567af
Author: Christian Hergert <chergert redhat com>
Date: Thu Jan 9 09:32:32 2020 -0800
mark: modernize GtkSourceMark
- Use G_DECLARE_ macros
- Fix spacing style for multi-line functions
- Use get_instance_private()
gtksourceview/gtksourceautocleanups.h | 1 -
gtksourceview/gtksourcemark.c | 43 ++++++++++++++++-------------------
gtksourceview/gtksourcemark.h | 24 ++++---------------
3 files changed, 23 insertions(+), 45 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index fe3d5e0a..a7cb538b 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
#ifndef __GI_SCANNER__
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceMark, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceMap, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourcePrintCompositor, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceSearchContext, g_object_unref)
diff --git a/gtksourceview/gtksourcemark.c b/gtksourceview/gtksourcemark.c
index a3b3b8e4..5e32123e 100644
--- a/gtksourceview/gtksourcemark.c
+++ b/gtksourceview/gtksourcemark.c
@@ -49,24 +49,21 @@ enum
PROP_CATEGORY
};
-struct _GtkSourceMarkPrivate
+typedef struct
{
gchar *category;
-};
+} GtkSourceMarkPrivate;
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK);
+G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceMark, gtk_source_mark, GTK_TYPE_TEXT_MARK)
static void
gtk_source_mark_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceMarkPrivate *priv;
-
- g_return_if_fail (GTK_SOURCE_IS_MARK (object));
-
- priv = GTK_SOURCE_MARK (object)->priv;
+ GtkSourceMark *mark = GTK_SOURCE_MARK (object);
+ GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
switch (prop_id)
{
@@ -84,15 +81,11 @@ gtk_source_mark_set_property (GObject *object,
static void
gtk_source_mark_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GtkSourceMark *mark;
-
- g_return_if_fail (GTK_SOURCE_IS_MARK (object));
-
- mark = GTK_SOURCE_MARK (object);
+ GtkSourceMark *mark = GTK_SOURCE_MARK (object);
switch (prop_id)
{
@@ -111,8 +104,9 @@ static void
gtk_source_mark_finalize (GObject *object)
{
GtkSourceMark *mark = GTK_SOURCE_MARK (object);
+ GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
- g_free (mark->priv->category);
+ g_clear_pointer (&priv->category, g_free);
G_OBJECT_CLASS (gtk_source_mark_parent_class)->finalize (object);
}
@@ -148,7 +142,6 @@ gtk_source_mark_class_init (GtkSourceMarkClass *klass)
static void
gtk_source_mark_init (GtkSourceMark *mark)
{
- mark->priv = gtk_source_mark_get_instance_private (mark);
}
/**
@@ -195,9 +188,11 @@ gtk_source_mark_new (const gchar *name,
const gchar *
gtk_source_mark_get_category (GtkSourceMark *mark)
{
+ GtkSourceMarkPrivate *priv = gtk_source_mark_get_instance_private (mark);
+
g_return_val_if_fail (GTK_SOURCE_IS_MARK (mark), NULL);
- return mark->priv->category;
+ return priv->category;
}
/**
@@ -216,7 +211,7 @@ gtk_source_mark_get_category (GtkSourceMark *mark)
*/
GtkSourceMark *
gtk_source_mark_next (GtkSourceMark *mark,
- const gchar *category)
+ const gchar *category)
{
GtkTextBuffer *buffer;
@@ -250,7 +245,7 @@ gtk_source_mark_next (GtkSourceMark *mark,
*/
GtkSourceMark *
gtk_source_mark_prev (GtkSourceMark *mark,
- const gchar *category)
+ const gchar *category)
{
GtkTextBuffer *buffer;
diff --git a/gtksourceview/gtksourcemark.h b/gtksourceview/gtksourcemark.h
index d3a17273..426be867 100644
--- a/gtksourceview/gtksourcemark.h
+++ b/gtksourceview/gtksourcemark.h
@@ -29,35 +29,19 @@
G_BEGIN_DECLS
-#define GTK_SOURCE_TYPE_MARK (gtk_source_mark_get_type ())
-#define GTK_SOURCE_MARK(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_SOURCE_TYPE_MARK,
GtkSourceMark))
-#define GTK_SOURCE_MARK_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_SOURCE_TYPE_MARK,
GtkSourceMarkClass))
-#define GTK_SOURCE_IS_MARK(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_SOURCE_TYPE_MARK))
-#define GTK_SOURCE_IS_MARK_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_SOURCE_TYPE_MARK))
-#define GTK_SOURCE_MARK_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_SOURCE_TYPE_MARK,
GtkSourceMarkClass))
+#define GTK_SOURCE_TYPE_MARK (gtk_source_mark_get_type())
-typedef struct _GtkSourceMarkClass GtkSourceMarkClass;
-
-typedef struct _GtkSourceMarkPrivate GtkSourceMarkPrivate;
-
-struct _GtkSourceMark
-{
- GtkTextMark parent_instance;
-
- GtkSourceMarkPrivate *priv;
-};
+GTK_SOURCE_AVAILABLE_IN_ALL
+G_DECLARE_DERIVABLE_TYPE (GtkSourceMark, gtk_source_mark, GTK_SOURCE, MARK, GtkTextMark)
struct _GtkSourceMarkClass
{
GtkTextMarkClass parent_class;
/* Padding for future expansion */
- gpointer padding[10];
+ gpointer _reserved[10];
};
-GTK_SOURCE_AVAILABLE_IN_ALL
-GType gtk_source_mark_get_type (void) G_GNUC_CONST;
-
GTK_SOURCE_AVAILABLE_IN_ALL
GtkSourceMark *gtk_source_mark_new (const gchar *name,
const gchar *category);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]