[gtksourceview/wip/chergert/gsv-gtk4: 32/84] lines: modernize GtkSourceGutterRendererLines



commit bb149c0490b16072297a9c815ffa8769c65788d6
Author: Christian Hergert <chergert redhat com>
Date:   Thu Jan 9 14:00:15 2020 -0800

    lines: modernize GtkSourceGutterRendererLines
    
     - Use G_DECLARE_
     - Make final

 docs/reference/meson.build                         |  2 +-
 .../gtksourcegutterrendererlines-private.h         | 38 +++++++++++++
 gtksourceview/gtksourcegutterrendererlines.c       | 46 ++++++++-------
 gtksourceview/gtksourcegutterrendererlines.h       | 65 ----------------------
 gtksourceview/gtksourceview.c                      |  4 +-
 5 files changed, 63 insertions(+), 92 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index b97f6e00..ea2822c0 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -26,7 +26,7 @@ reference_private_h = [
   'gtksourcefile-private.h',
   'gtksourcegutter-private.h',
   'gtksourcegutterrenderer-private.h',
-  'gtksourcegutterrendererlines.h',
+  'gtksourcegutterrendererlines-private.h',
   'gtksourcegutterrenderermarks-private.h',
   'gtksourceiter-private.h',
   'gtksourcelanguage-private.h',
diff --git a/gtksourceview/gtksourcegutterrendererlines-private.h 
b/gtksourceview/gtksourcegutterrendererlines-private.h
new file mode 100644
index 00000000..89eebbe4
--- /dev/null
+++ b/gtksourceview/gtksourcegutterrendererlines-private.h
@@ -0,0 +1,38 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8; coding: utf-8 -*-
+ *
+ * This file is part of GtkSourceView
+ *
+ * Copyright 2010 - Jesse van den Kieboom
+ *
+ * GtkSourceView 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.
+ *
+ * GtkSourceView 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/>.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+#include "gtksourcetypes.h"
+#include "gtksourcetypes-private.h"
+#include "gtksourcegutterrenderertext.h"
+
+G_BEGIN_DECLS
+
+#define GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES (_gtk_source_gutter_renderer_lines_get_type())
+
+G_GNUC_INTERNAL
+G_DECLARE_FINAL_TYPE (GtkSourceGutterRendererLines, _gtk_source_gutter_renderer_lines, GTK_SOURCE, 
GUTTER_RENDERER_LINES, GtkSourceGutterRendererText)
+
+G_GNUC_INTERNAL
+GtkSourceGutterRenderer *_gtk_source_gutter_renderer_lines_new (void);
+
+G_END_DECLS
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index e2f23b0a..6f508ce1 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -20,18 +20,19 @@
 
 #include "config.h"
 
-#include "gtksourcegutterrendererlines.h"
+#include "gtksourcegutterrendererlines-private.h"
 #include "gtksourceutils-private.h"
 #include "gtksourceview.h"
 
-struct _GtkSourceGutterRendererLinesPrivate
+struct _GtkSourceGutterRendererLines
 {
+       GtkSourceGutterRendererText parent_instance;
        gint num_line_digits;
        gint prev_line_num;
        guint cursor_visible : 1;
 };
 
-G_DEFINE_TYPE_WITH_PRIVATE (GtkSourceGutterRendererLines, gtk_source_gutter_renderer_lines, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
+G_DEFINE_TYPE (GtkSourceGutterRendererLines, _gtk_source_gutter_renderer_lines, 
GTK_SOURCE_TYPE_GUTTER_RENDERER_TEXT)
 
 static GtkTextBuffer *
 get_buffer (GtkSourceGutterRendererLines *renderer)
@@ -85,12 +86,12 @@ recalculate_size (GtkSourceGutterRendererLines *renderer)
 
        num_digits = count_num_digits (num_lines);
 
-       if (num_digits != renderer->priv->num_line_digits)
+       if (num_digits != renderer->num_line_digits)
        {
                gchar markup[24];
                gint size;
 
-               renderer->priv->num_line_digits = num_digits;
+               renderer->num_line_digits = num_digits;
 
                num_lines = MAX (num_lines, 99);
 
@@ -139,12 +140,11 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
                recalculate_size (lines);
        }
 
-       lines->priv->prev_line_num = 0;
+       lines->prev_line_num = 0;
 
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_buffer 
!= NULL)
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_buffer 
!= NULL)
        {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS 
(gtk_source_gutter_renderer_lines_parent_class)->change_buffer (renderer,
-                                                                                                             
   old_buffer);
+               GTK_SOURCE_GUTTER_RENDERER_CLASS 
(_gtk_source_gutter_renderer_lines_parent_class)->change_buffer (renderer, old_buffer);
        }
 }
 
@@ -153,7 +153,7 @@ on_view_style_updated (GtkTextView                  *view,
                       GtkSourceGutterRendererLines *renderer)
 {
        /* Force to recalculate the size. */
-       renderer->priv->num_line_digits = -1;
+       renderer->num_line_digits = -1;
        recalculate_size (renderer);
 }
 
@@ -162,7 +162,7 @@ on_view_notify_cursor_visible (GtkTextView                  *view,
                                GParamSpec                   *pspec,
                                GtkSourceGutterRendererLines *renderer)
 {
-       renderer->priv->cursor_visible = gtk_text_view_get_cursor_visible (view);
+       renderer->cursor_visible = gtk_text_view_get_cursor_visible (view);
 }
 
 static void
@@ -197,13 +197,12 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                                         renderer,
                                         0);
 
-               GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->priv->cursor_visible = 
gtk_text_view_get_cursor_visible (new_view);
+               GTK_SOURCE_GUTTER_RENDERER_LINES (renderer)->cursor_visible = 
gtk_text_view_get_cursor_visible (new_view);
        }
 
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_view != 
NULL)
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->change_view != 
NULL)
        {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->change_view 
(renderer,
-                                                                                                             
 old_view);
+               GTK_SOURCE_GUTTER_RENDERER_CLASS 
(_gtk_source_gutter_renderer_lines_parent_class)->change_view (renderer, old_view);
        }
 }
 
@@ -223,7 +222,7 @@ gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
        line = gtk_text_iter_get_line (start) + 1;
 
        current_line = (state & GTK_SOURCE_GUTTER_RENDERER_STATE_CURSOR) &&
-                      lines->priv->cursor_visible;
+                      lines->cursor_visible;
 
        if G_LIKELY (!current_line)
        {
@@ -297,16 +296,16 @@ gutter_renderer_end (GtkSourceGutterRenderer *renderer)
                 * have padding for future expansion, so it must wait for
                 * GtkSourceView 4.
                 */
-               if (lines->priv->prev_line_num != line_num)
+               if (lines->prev_line_num != line_num)
                {
-                       lines->priv->prev_line_num = line_num;
+                       lines->prev_line_num = line_num;
                        gtk_source_gutter_renderer_queue_draw (renderer);
                }
        }
 
-       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->end != NULL)
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end != NULL)
        {
-               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class)->end 
(renderer);
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (_gtk_source_gutter_renderer_lines_parent_class)->end 
(renderer);
        }
 }
 
@@ -422,7 +421,7 @@ gutter_renderer_query_activatable (GtkSourceGutterRenderer *renderer,
 }
 
 static void
-gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
+_gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *klass)
 {
        GtkSourceGutterRendererClass *renderer_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (klass);
 
@@ -435,13 +434,12 @@ gtk_source_gutter_renderer_lines_class_init (GtkSourceGutterRendererLinesClass *
 }
 
 static void
-gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
+_gtk_source_gutter_renderer_lines_init (GtkSourceGutterRendererLines *self)
 {
-       self->priv = gtk_source_gutter_renderer_lines_get_instance_private (self);
 }
 
 GtkSourceGutterRenderer *
-gtk_source_gutter_renderer_lines_new (void)
+_gtk_source_gutter_renderer_lines_new (void)
 {
        return g_object_new (GTK_SOURCE_TYPE_GUTTER_RENDERER_LINES, NULL);
 }
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index b33f7692..f7ac6d17 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -45,7 +45,7 @@
 #include "gtksourcecompletionprovider.h"
 #include "gtksourcegutter.h"
 #include "gtksourcegutter-private.h"
-#include "gtksourcegutterrendererlines.h"
+#include "gtksourcegutterrendererlines-private.h"
 #include "gtksourcegutterrenderermarks-private.h"
 #include "gtksourceiter-private.h"
 #include "gtksourcesearchcontext-private.h"
@@ -2953,7 +2953,7 @@ gtk_source_view_set_show_line_numbers (GtkSourceView *view,
 
                gutter = gtk_source_view_get_gutter (view, GTK_TEXT_WINDOW_LEFT);
 
-               priv->line_renderer = gtk_source_gutter_renderer_lines_new ();
+               priv->line_renderer = _gtk_source_gutter_renderer_lines_new ();
                g_object_set (priv->line_renderer,
                              "alignment-mode", GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST,
                              "yalign", 0.5,


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