[gtksourceview] gutter renderers: chain-up more correctly



commit 6b8fbfcd450cf2d2e001fc720769ab29450f3b9e
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Sep 15 18:15:17 2014 +0200

    gutter renderers: chain-up more correctly
    
    So the code is more robust to changes in the GutterRenderer.

 gtksourceview/gtksourcegutterrendererlines.c  |   18 ++++++---
 gtksourceview/gtksourcegutterrenderermarks.c  |   16 +++++----
 gtksourceview/gtksourcegutterrendererpixbuf.c |   21 ++++++-----
 gtksourceview/gtksourcegutterrenderertext.c   |   46 +++++++++++++++---------
 4 files changed, 61 insertions(+), 40 deletions(-)
---
diff --git a/gtksourceview/gtksourcegutterrendererlines.c b/gtksourceview/gtksourcegutterrendererlines.c
index 1608c45..4dac5ef 100644
--- a/gtksourceview/gtksourcegutterrendererlines.c
+++ b/gtksourceview/gtksourcegutterrendererlines.c
@@ -94,11 +94,9 @@ static void
 gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
                                GtkTextBuffer           *old_buffer)
 {
-       GtkSourceGutterRendererLines *lines;
+       GtkSourceGutterRendererLines *lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
        GtkTextBuffer *buffer;
 
-       lines = GTK_SOURCE_GUTTER_RENDERER_LINES (renderer);
-
        if (old_buffer != NULL)
        {
                g_signal_handlers_disconnect_by_func (old_buffer,
@@ -120,6 +118,12 @@ gutter_renderer_change_buffer (GtkSourceGutterRenderer *renderer,
        }
 
        lines->priv->prev_line_num = 0;
+
+       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);
+       }
 }
 
 static void
@@ -135,7 +139,6 @@ static void
 gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                             GtkTextView             *old_view)
 {
-       GtkSourceGutterRendererClass *parent_class;
        GtkTextView *new_view;
 
        if (old_view != NULL)
@@ -156,8 +159,11 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                                         0);
        }
 
-       parent_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_lines_parent_class);
-       parent_class->change_view (renderer, old_view);
+       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);
+       }
 }
 
 static void
diff --git a/gtksourceview/gtksourcegutterrenderermarks.c b/gtksourceview/gtksourcegutterrenderermarks.c
index a2f580f..6c1ae5c 100644
--- a/gtksourceview/gtksourcegutterrenderermarks.c
+++ b/gtksourceview/gtksourcegutterrenderermarks.c
@@ -173,10 +173,10 @@ composite_marks (GtkSourceView *view,
 }
 
 static void
-gutter_renderer_query_data (GtkSourceGutterRenderer *renderer,
-                            GtkTextIter             *start,
-                            GtkTextIter             *end,
-                            GtkSourceGutterRendererState state)
+gutter_renderer_query_data (GtkSourceGutterRenderer      *renderer,
+                           GtkTextIter                  *start,
+                           GtkTextIter                  *end,
+                           GtkSourceGutterRendererState  state)
 {
        GSList *marks;
        GdkPixbuf *pixbuf = NULL;
@@ -377,7 +377,6 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                              GtkTextView             *old_view)
 {
        GtkSourceView *view;
-       GtkSourceGutterRendererClass *parent_class;
 
        view = GTK_SOURCE_VIEW (gtk_source_gutter_renderer_get_view (renderer));
 
@@ -387,8 +386,11 @@ gutter_renderer_change_view (GtkSourceGutterRenderer *renderer,
                                                     measure_line_height (view));
        }
 
-       parent_class = GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_marks_parent_class);
-       parent_class->change_view (renderer, old_view);
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_marks_parent_class)->change_view != 
NULL)
+       {
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_marks_parent_class)->change_view 
(renderer,
+                                                                                                             
 old_view);
+       }
 }
 
 static void
diff --git a/gtksourceview/gtksourcegutterrendererpixbuf.c b/gtksourceview/gtksourcegutterrendererpixbuf.c
index 57a9620..bb3cce1 100644
--- a/gtksourceview/gtksourcegutterrendererpixbuf.c
+++ b/gtksourceview/gtksourcegutterrendererpixbuf.c
@@ -80,7 +80,7 @@ gutter_renderer_pixbuf_draw (GtkSourceGutterRenderer      *renderer,
                              GtkTextIter                  *end,
                              GtkSourceGutterRendererState  state)
 {
-       GtkSourceGutterRendererPixbuf *pix;
+       GtkSourceGutterRendererPixbuf *pix = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (renderer);
        gint width;
        gint height;
        gfloat xalign;
@@ -92,16 +92,17 @@ gutter_renderer_pixbuf_draw (GtkSourceGutterRenderer      *renderer,
        GdkPixbuf *pixbuf;
 
        /* Chain up to draw background */
-       GTK_SOURCE_GUTTER_RENDERER_CLASS (
-               gtk_source_gutter_renderer_pixbuf_parent_class)->draw (renderer,
-                                                                      cr,
-                                                                      background_area,
-                                                                      cell_area,
-                                                                      start,
-                                                                      end,
-                                                                      state);
-
-       pix = GTK_SOURCE_GUTTER_RENDERER_PIXBUF (renderer);
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw != NULL)
+       {
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_pixbuf_parent_class)->draw 
(renderer,
+                                                                                                        cr,
+                                                                                                        
background_area,
+                                                                                                        
cell_area,
+                                                                                                        
start,
+                                                                                                        end,
+                                                                                                        
state);
+       }
+
        view = gtk_source_gutter_renderer_get_view (renderer);
 
        pixbuf = gtk_source_pixbuf_helper_render (pix->priv->helper,
diff --git a/gtksourceview/gtksourcegutterrenderertext.c b/gtksourceview/gtksourcegutterrenderertext.c
index 43b889c..cb155c7 100644
--- a/gtksourceview/gtksourcegutterrenderertext.c
+++ b/gtksourceview/gtksourcegutterrenderertext.c
@@ -90,11 +90,19 @@ gutter_renderer_text_begin (GtkSourceGutterRenderer      *renderer,
                             GtkTextIter                  *start,
                             GtkTextIter                  *end)
 {
-       GtkSourceGutterRendererText *text;
-
-       text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
 
        create_layout (text, GTK_WIDGET (gtk_source_gutter_renderer_get_view (renderer)));
+
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin != NULL)
+       {
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->begin 
(renderer,
+                                                                                                       cr,
+                                                                                                       
background_area,
+                                                                                                       
cell_area,
+                                                                                                       start,
+                                                                                                       end);
+       }
 }
 
 static void
@@ -128,7 +136,7 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
                            GtkTextIter                  *end,
                            GtkSourceGutterRendererState  state)
 {
-       GtkSourceGutterRendererText *text;
+       GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
        gint width;
        gint height;
        PangoAttrList *attr_list;
@@ -141,16 +149,17 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
        GtkStyleContext *context;
 
        /* Chain up to draw background */
-       GTK_SOURCE_GUTTER_RENDERER_CLASS (
-               gtk_source_gutter_renderer_text_parent_class)->draw (renderer,
-                                                                    cr,
-                                                                    background_area,
-                                                                    cell_area,
-                                                                    start,
-                                                                    end,
-                                                                    state);
-
-       text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw != NULL)
+       {
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw 
(renderer,
+                                                                                                      cr,
+                                                                                                      
background_area,
+                                                                                                      
cell_area,
+                                                                                                      start,
+                                                                                                      end,
+                                                                                                      state);
+       }
+
        view = gtk_source_gutter_renderer_get_view (renderer);
 
        if (text->priv->is_markup)
@@ -227,9 +236,7 @@ gutter_renderer_text_draw (GtkSourceGutterRenderer      *renderer,
 static void
 gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
 {
-       GtkSourceGutterRendererText *text;
-
-       text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
+       GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer);
 
        g_object_unref (text->priv->cached_layout);
        text->priv->cached_layout = NULL;
@@ -238,6 +245,11 @@ gutter_renderer_text_end (GtkSourceGutterRenderer *renderer)
        text->priv->cached_attr_list = NULL;
 
        text->priv->fg_attr = NULL;
+
+       if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end != NULL)
+       {
+               GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->end 
(renderer);
+       }
 }
 
 static void


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