[gtksourceview/wip/chergert/gsv-gtk4: 24/125] gutter: modernize GtkSourceGutterRendererText



commit acc8c5b115bbaf6de19e9510e86812c3ff51c363
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 8 20:49:44 2020 -0800

    gutter: modernize GtkSourceGutterRendererText
    
     - Use G_DECLARE_ macros
     - Use get_instance_private
     - Fix spacing style for multi-line functions

 gtksourceview/gtksourceautocleanups.h       |  1 -
 gtksourceview/gtksourcegutterrenderertext.c | 75 +++++++++++++++--------------
 gtksourceview/gtksourcegutterrenderertext.h | 61 ++++++++---------------
 3 files changed, 59 insertions(+), 78 deletions(-)
---
diff --git a/gtksourceview/gtksourceautocleanups.h b/gtksourceview/gtksourceautocleanups.h
index c1a35a70..eccb6f8e 100644
--- a/gtksourceview/gtksourceautocleanups.h
+++ b/gtksourceview/gtksourceautocleanups.h
@@ -28,7 +28,6 @@ G_BEGIN_DECLS
 
 #ifndef __GI_SCANNER__
 
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceGutterRendererText, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceLanguage, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceLanguageManager, g_object_unref)
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkSourceMark, g_object_unref)
diff --git a/gtksourceview/gtksourcegutterrenderertext.c b/gtksourceview/gtksourcegutterrenderertext.c
index 2c413289..c8085afe 100644
--- a/gtksourceview/gtksourcegutterrenderertext.c
+++ b/gtksourceview/gtksourcegutterrenderertext.c
@@ -32,14 +32,14 @@
  * #GtkSourceGutter.
  */
 
-struct _GtkSourceGutterRendererTextPrivate
+typedef struct
 {
        gchar *text;
 
        PangoLayout *cached_layout;
 
        guint is_markup : 1;
-};
+} GtkSourceGutterRendererTextPrivate;
 
 G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text, 
GTK_SOURCE_TYPE_GUTTER_RENDERER)
 
@@ -52,19 +52,20 @@ enum
 
 static void
 gutter_renderer_text_begin (GtkSourceGutterRenderer *renderer,
-                           cairo_t                 *cr,
-                           GdkRectangle            *background_area,
-                           GdkRectangle            *cell_area,
-                           GtkTextIter             *start,
-                           GtkTextIter             *end)
+                            cairo_t                 *cr,
+                            GdkRectangle            *background_area,
+                            GdkRectangle            *cell_area,
+                            GtkTextIter             *start,
+                            GtkTextIter             *end)
 {
        GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
        GtkTextView *view;
 
        view = gtk_source_gutter_renderer_get_view (renderer);
 
-       g_clear_object (&text->priv->cached_layout);
-       text->priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
+       g_clear_object (&priv->cached_layout);
+       priv->cached_layout = gtk_widget_create_pango_layout (GTK_WIDGET (view), NULL);
 
        if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin != NULL)
        {
@@ -98,14 +99,15 @@ center_on (GtkTextView  *view,
 
 static void
 gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
-                          cairo_t                      *cr,
-                          GdkRectangle                 *background_area,
-                          GdkRectangle                 *cell_area,
-                          GtkTextIter                  *start,
-                          GtkTextIter                  *end,
-                          GtkSourceGutterRendererState  state)
+                           cairo_t                      *cr,
+                           GdkRectangle                 *background_area,
+                           GdkRectangle                 *cell_area,
+                           GtkTextIter                  *start,
+                           GtkTextIter                  *end,
+                           GtkSourceGutterRendererState  state)
 {
        GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
        GtkTextView *view;
        gint width;
        gint height;
@@ -130,20 +132,20 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
 
        view = gtk_source_gutter_renderer_get_view (renderer);
 
-       if (text->priv->is_markup)
+       if (priv->is_markup)
        {
-               pango_layout_set_markup (text->priv->cached_layout,
-                                        text->priv->text,
+               pango_layout_set_markup (priv->cached_layout,
+                                        priv->text,
                                         -1);
        }
        else
        {
-               pango_layout_set_text (text->priv->cached_layout,
-                                      text->priv->text,
+               pango_layout_set_text (priv->cached_layout,
+                                      priv->text,
                                       -1);
        }
 
-       pango_layout_get_pixel_size (text->priv->cached_layout, &width, &height);
+       pango_layout_get_pixel_size (priv->cached_layout, &width, &height);
 
        gtk_source_gutter_renderer_get_alignment (renderer,
                                                  &xalign,
@@ -195,15 +197,16 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
        }
 
        context = gtk_widget_get_style_context (GTK_WIDGET (view));
-       gtk_render_layout (context, cr, x, y, text->priv->cached_layout);
+       gtk_render_layout (context, cr, x, y, priv->cached_layout);
 }
 
 static void
 gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
 {
        GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(text);
 
-       g_clear_object (&text->priv->cached_layout);
+       g_clear_object (&priv->cached_layout);
 
        if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end != NULL)
        {
@@ -291,9 +294,10 @@ static void
 gtk_source_gutter_renderer_text_finalize (GObject *object)
 {
        GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
 
-       g_free (renderer->priv->text);
-       g_clear_object (&renderer->priv->cached_layout);
+       g_free (priv->text);
+       g_clear_object (&priv->cached_layout);
 
        G_OBJECT_CLASS (gtk_source_gutter_renderer_text_parent_class)->finalize (object);
 }
@@ -304,10 +308,12 @@ set_text (GtkSourceGutterRendererText *renderer,
           gint                         length,
           gboolean                     is_markup)
 {
-       g_free (renderer->priv->text);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
+
+       g_free (priv->text);
 
-       renderer->priv->text = length >= 0 ? g_strndup (text, length) : g_strdup (text);
-       renderer->priv->is_markup = is_markup;
+       priv->text = length >= 0 ? g_strndup (text, length) : g_strdup (text);
+       priv->is_markup = is_markup;
 }
 
 static void
@@ -340,17 +346,16 @@ gtk_source_gutter_renderer_text_get_property (GObject    *object,
                                               GValue     *value,
                                               GParamSpec *pspec)
 {
-       GtkSourceGutterRendererText *renderer;
-
-       renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
+       GtkSourceGutterRendererText *renderer = GTK_SOURCE_GUTTER_RENDERER_TEXT (object);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(renderer);
 
        switch (prop_id)
        {
                case PROP_MARKUP:
-                       g_value_set_string (value, renderer->priv->is_markup ? renderer->priv->text : NULL);
+                       g_value_set_string (value, priv->is_markup ? priv->text : NULL);
                        break;
                case PROP_TEXT:
-                       g_value_set_string (value, !renderer->priv->is_markup ? renderer->priv->text : NULL);
+                       g_value_set_string (value, !priv->is_markup ? priv->text : NULL);
                        break;
                default:
                        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -393,9 +398,9 @@ gtk_source_gutter_renderer_text_class_init (GtkSourceGutterRendererTextClass *kl
 static void
 gtk_source_gutter_renderer_text_init (GtkSourceGutterRendererText *self)
 {
-       self->priv = gtk_source_gutter_renderer_text_get_instance_private (self);
+       GtkSourceGutterRendererTextPrivate *priv = gtk_source_gutter_renderer_text_get_instance_private 
(self);
 
-       self->priv->is_markup = TRUE;
+       priv->is_markup = TRUE;
 }
 
 /**
diff --git a/gtksourceview/gtksourcegutterrenderertext.h b/gtksourceview/gtksourcegutterrenderertext.h
index c9c91812..59efe60f 100644
--- a/gtksourceview/gtksourcegutterrenderertext.h
+++ b/gtksourceview/gtksourcegutterrenderertext.h
@@ -29,61 +29,38 @@
 
 G_BEGIN_DECLS
 
-#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT           (gtk_source_gutter_renderer_text_get_type ())
-#define GTK_SOURCE_GUTTER_RENDERER_TEXT(obj)           (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText))
-#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CONST(obj)     (G_TYPE_CHECK_INSTANCE_CAST ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererText const))
-#define GTK_SOURCE_GUTTER_RENDERER_TEXT_CLASS(klass)   (G_TYPE_CHECK_CLASS_CAST ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
-#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT(obj)                (G_TYPE_CHECK_INSTANCE_TYPE ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
-#define GTK_SOURCE_IS_GUTTER_RENDERER_TEXT_CLASS(klass)        (G_TYPE_CHECK_CLASS_TYPE ((klass), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT))
-#define GTK_SOURCE_GUTTER_RENDERER_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT, GtkSourceGutterRendererTextClass))
-
-typedef struct _GtkSourceGutterRendererTextClass       GtkSourceGutterRendererTextClass;
-typedef struct _GtkSourceGutterRendererTextPrivate     GtkSourceGutterRendererTextPrivate;
-
-struct _GtkSourceGutterRendererText
-{
-       /*< private >*/
-       GtkSourceGutterRenderer parent;
-
-       GtkSourceGutterRendererTextPrivate *priv;
-
-       /*< public >*/
-};
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT (gtk_source_gutter_renderer_text_get_type())
 
 struct _GtkSourceGutterRendererTextClass
 {
-       /*< private >*/
        GtkSourceGutterRendererClass parent_class;
 
-       gpointer padding[10];
+       /*< private >*/
+       gpointer _reserved[10];
 };
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GType gtk_source_gutter_renderer_text_get_type (void) G_GNUC_CONST;
+G_DECLARE_DERIVABLE_TYPE (GtkSourceGutterRendererText, gtk_source_gutter_renderer_text, GTK_SOURCE, 
GUTTER_RENDERER_TEXT, GtkSourceGutterRenderer)
 
 GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new (void);
-
+GtkSourceGutterRenderer *gtk_source_gutter_renderer_text_new            (void);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_set_markup (GtkSourceGutterRendererText *renderer,
-                                                 const gchar                 *markup,
-                                                 gint                         length);
-
+void                     gtk_source_gutter_renderer_text_set_markup     (GtkSourceGutterRendererText 
*renderer,
+                                                                         const gchar                 *markup,
+                                                                         gint                         
length);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_set_text (GtkSourceGutterRendererText *renderer,
-                                               const gchar                 *text,
-                                               gint                         length);
-
+void                     gtk_source_gutter_renderer_text_set_text       (GtkSourceGutterRendererText 
*renderer,
+                                                                         const gchar                 *text,
+                                                                         gint                         
length);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_measure (GtkSourceGutterRendererText *renderer,
-                                              const gchar                 *text,
-                                              gint                        *width,
-                                              gint                        *height);
-
+void                     gtk_source_gutter_renderer_text_measure        (GtkSourceGutterRendererText 
*renderer,
+                                                                         const gchar                 *text,
+                                                                         gint                        *width,
+                                                                         gint                        
*height);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText *renderer,
-                                                     const gchar                 *markup,
-                                                     gint                        *width,
-                                                     gint                        *height);
+void                     gtk_source_gutter_renderer_text_measure_markup (GtkSourceGutterRendererText 
*renderer,
+                                                                         const gchar                 *markup,
+                                                                         gint                        *width,
+                                                                         gint                        
*height);
 
 G_END_DECLS


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]