From 5c4811a65eedda9dd95137337dc6304eb8cd051d Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 29 Dec 2017 15:46:46 +0100
Subject: Fixed compilation warnings by replacing GTK deprecated functions in
 display panels.

---
 ChangeLog                         | 11 +++++
 src/glibext/gbufferview.c         | 12 ++---
 src/glibext/gbufferview.h         |  4 +-
 src/gtkext/gtkbufferdisplay-int.h |  2 +-
 src/gtkext/gtkbufferdisplay.c     | 98 ++++++++-------------------------------
 src/gtkext/gtkdisplaypanel.c      |  4 +-
 6 files changed, 43 insertions(+), 88 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5bbfb9c..6f7643b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+17-12-29  Cyrille Bagard <nocbos@gmail.com>
+
+	* src/glibext/gbufferview.c:
+	* src/glibext/gbufferview.h:
+	Update code.
+
+	* src/gtkext/gtkbufferdisplay-int.h:
+	* src/gtkext/gtkbufferdisplay.c:
+	* src/gtkext/gtkdisplaypanel.c:
+	Fix compilation warnings by replacing GTK deprecated functions in display panels.
+
 17-12-27  Cyrille Bagard <nocbos@gmail.com>
 
 	* src/gui/panels/errors.c:
diff --git a/src/glibext/gbufferview.c b/src/glibext/gbufferview.c
index e2aa194..9ef088a 100644
--- a/src/glibext/gbufferview.c
+++ b/src/glibext/gbufferview.c
@@ -82,10 +82,10 @@ static void g_buffer_view_finalize(GBufferView *);
 static void on_buffer_cache_size_changed(const GBufferCache *, bool, size_t, size_t, GBufferView *);
 
 /* Calcule la position idéale de curseur pour un point donné. */
-bool _g_buffer_view_compute_caret_full(GBufferView *, gint, GBufferLine *, size_t, const bool *, GdkRectangle *, vmpa2t *);
+bool _g_buffer_view_compute_caret_full(GBufferView *, gint, GBufferLine *, size_t, const bool *, cairo_rectangle_int_t *, vmpa2t *);
 
 /* Déplace le curseur au sein d'une vue de tampon. */
-static bool _g_buffer_view_move_caret(GBufferView *, const GBufferLine *, size_t, GdkRectangle *, bool, GdkScrollDirection, const bool *);
+static bool _g_buffer_view_move_caret(GBufferView *, const GBufferLine *, size_t, cairo_rectangle_int_t *, bool, GdkScrollDirection, const bool *);
 
 
 /* Fournit la ligne présente à une ordonnée donnée. */
@@ -579,7 +579,7 @@ gint g_buffer_view_get_height(const GBufferView *view)
 *                                                                             *
 ******************************************************************************/
 
-bool g_buffer_view_compute_caret_full(GBufferView *view, gint x, gint y, const bool *display, GdkRectangle *caret, vmpa2t *addr)
+bool g_buffer_view_compute_caret_full(GBufferView *view, gint x, gint y, const bool *display, cairo_rectangle_int_t *caret, vmpa2t *addr)
 {
     bool result;                            /* Bilan à retourner           */
     gint lheight;                           /* Hauteur d'une ligne         */
@@ -633,7 +633,7 @@ bool g_buffer_view_compute_caret_full(GBufferView *view, gint x, gint y, const b
 *                                                                             *
 ******************************************************************************/
 
-bool _g_buffer_view_compute_caret_full(GBufferView *view, gint x, GBufferLine *line, size_t index, const bool *display, GdkRectangle *caret, vmpa2t *addr)
+bool _g_buffer_view_compute_caret_full(GBufferView *view, gint x, GBufferLine *line, size_t index, const bool *display, cairo_rectangle_int_t *caret, vmpa2t *addr)
 {
     bool result;                            /* Bilan à retourner           */
     gint text_pos;                          /* Abscisse de départ du texte */
@@ -703,7 +703,7 @@ bool _g_buffer_view_compute_caret_full(GBufferView *view, gint x, GBufferLine *l
 *                                                                             *
 ******************************************************************************/
 
-static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line, size_t index, GdkRectangle *caret, bool ctrl, GdkScrollDirection dir, const bool *display)
+static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line, size_t index, cairo_rectangle_int_t *caret, bool ctrl, GdkScrollDirection dir, const bool *display)
 {
     bool result;                            /* Bilan à retourner           */
     gint text_pos;                          /* Abscisse de départ du texte */
@@ -778,7 +778,7 @@ static bool _g_buffer_view_move_caret(GBufferView *view, const GBufferLine *line
 *                                                                             *
 ******************************************************************************/
 
-bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection dir, const bool *display, GdkRectangle *caret, vmpa2t *addr)
+bool g_buffer_view_move_caret(GBufferView *view, bool ctrl, GdkScrollDirection dir, const bool *display, cairo_rectangle_int_t *caret, vmpa2t *addr)
 {
     bool result;                            /* Bilan à retourner           */
     size_t index;                           /* Indice de ligne de tampon   */
diff --git a/src/glibext/gbufferview.h b/src/glibext/gbufferview.h
index 6336fb4..b934821 100644
--- a/src/glibext/gbufferview.h
+++ b/src/glibext/gbufferview.h
@@ -78,10 +78,10 @@ gint g_buffer_view_get_height(const GBufferView *);
 
 
 /* Calcule la position idéale de curseur pour un point donné. */
-bool g_buffer_view_compute_caret_full(GBufferView *, gint, gint, const bool *, GdkRectangle *, vmpa2t *);
+bool g_buffer_view_compute_caret_full(GBufferView *, gint, gint, const bool *, cairo_rectangle_int_t *, vmpa2t *);
 
 /* Déplace le curseur au sein d'une vue de tampon. */
-bool g_buffer_view_move_caret(GBufferView *, bool, GdkScrollDirection, const bool *, GdkRectangle *, vmpa2t *);
+bool g_buffer_view_move_caret(GBufferView *, bool, GdkScrollDirection, const bool *, cairo_rectangle_int_t *, vmpa2t *);
 
 
 
diff --git a/src/gtkext/gtkbufferdisplay-int.h b/src/gtkext/gtkbufferdisplay-int.h
index d77452a..d4084af 100644
--- a/src/gtkext/gtkbufferdisplay-int.h
+++ b/src/gtkext/gtkbufferdisplay-int.h
@@ -43,7 +43,7 @@ struct _GtkBufferDisplay
 
     GBufferView *view;                      /* Vue sur le contenu affiché  */
 
-    GdkRectangle caret;                     /* Emplacement du curseur      */
+    cairo_rectangle_int_t caret;            /* Emplacement du curseur      */
     vmpa2t caret_addr;                      /* Position mémoire du curseur */
     guint caret_timer;                      /* Identifiant du chronomètre  */
     bool show_caret;                        /* Bascule entre les affichages*/
diff --git a/src/gtkext/gtkbufferdisplay.c b/src/gtkext/gtkbufferdisplay.c
index c1311c5..fca0360 100644
--- a/src/gtkext/gtkbufferdisplay.c
+++ b/src/gtkext/gtkbufferdisplay.c
@@ -85,7 +85,7 @@ static void gtk_buffer_display_cache_glance(GtkBufferDisplay *, cairo_t *, const
 static bool _gtk_buffer_display_move_caret_to(GtkBufferDisplay *, gint, gint);
 
 /* Déplace le curseur en effaçant son éventuelle position. */
-static void gtk_buffer_display_relocate_caret(GtkBufferDisplay *, const GdkRectangle *, const vmpa2t *);
+static void gtk_buffer_display_relocate_caret(GtkBufferDisplay *, const cairo_rectangle_int_t *, const vmpa2t *);
 
 /* Redémarre l'affichage du curseur à l'emplacement courant. */
 static void gtk_buffer_display_restart_caret_blinking(GtkBufferDisplay *);
@@ -329,46 +329,9 @@ static gboolean gtk_buffer_display_draw(GtkWidget *widget, cairo_t *cr)
     gint virt_y;                            /* Ordonnée virtuelle          */
     GBufferCache *cache;                    /* Contenu représenté          */
     gint left_margin;                       /* Marge gauche + espace       */
-    GdkRGBA color;                          /* Couleur de thème récupérée  */
     bool sel_line;                          /* Souslignage de la sélection */
     gint *selected;                         /* Ordonnée d'une sélection    */
 
-
-    //gboolean status;
-
-
-    GtkStyleContext *other;
-    GtkWidgetPath *path;
-
-
-    other = gtk_style_context_new();
-
-
-    path = gtk_widget_path_new ();
-    gtk_widget_path_append_type (path, GTK_TYPE_SCALE);
-    //gtk_widget_path_iter_add_class (path, 0, "slider");
-    //gtk_widget_path_iter_add_class (path, 0, "scale");
-    gtk_style_context_set_path (other, path);
-    gtk_widget_path_free (path);
-
-
-
-
-    //context = gtk_widget_get_style_context(widget);
-
-
-    //gtk_render_background(context, cr, 0, 0, 1000, 1000);
-
-
-    //status = GTK_WIDGET_CLASS(gtk_buffer_display_parent_class)->draw(widget, cr);
-
-    //printf("status: %d\n", status);
-
-    //return TRUE;
-
-
-
-
     display = GTK_BUFFER_DISPLAY(widget);
     parent = GTK_DISPLAY_PANEL(widget);
 
@@ -389,12 +352,6 @@ static gboolean gtk_buffer_display_draw(GtkWidget *widget, cairo_t *cr)
         cairo_clip(cr);
     }
 
-
-
-    gtk_render_background(context, cr, area.x, area.y, area.width, area.height);
-
-
-
     /* Décallage pour le défilement horizontal */
 
     virt_x = 0;
@@ -413,39 +370,25 @@ static gboolean gtk_buffer_display_draw(GtkWidget *widget, cairo_t *cr)
 
     g_object_unref(G_OBJECT(cache));
 
-
     /* Dessin de la marge gauche */
 
     gtk_style_context_save(context);
 
-    gtk_style_context_add_class(other, GTK_STYLE_CLASS_TOOLBAR);
+    gtk_style_context_add_class(context, GTK_STYLE_CLASS_SIDEBAR);
 
-    gtk_style_context_get_background_color(other, GTK_STATE_FLAG_ACTIVE, &color);
-
-    cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
-    //cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 1.0);
-
-    cairo_rectangle(cr, 0, area.y, left_margin, area.height);
-    cairo_fill(cr);
+    gtk_render_background(context, cr, 0, area.y, left_margin, area.height);
 
     gtk_style_context_restore(context);
 
     /* Fond de la zone de texte */
 
-#if 1
     gtk_style_context_save(context);
 
     gtk_style_context_add_class(context, GTK_STYLE_CLASS_VIEW);
 
-    gtk_style_context_get_background_color(context, GTK_STATE_FLAG_ACTIVE, &color);
-
-    cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha * 0.7);
-
-    cairo_rectangle(cr, left_margin, area.y, area.width, area.height);
-    cairo_fill(cr);
+    gtk_render_background(context, cr, left_margin, area.y, area.width, area.height);
 
     gtk_style_context_restore(context);
-#endif
 
     /* Ligne de séparation */
 
@@ -453,15 +396,7 @@ static gboolean gtk_buffer_display_draw(GtkWidget *widget, cairo_t *cr)
 
     gtk_style_context_add_class(context, GTK_STYLE_CLASS_FRAME);
 
-    gtk_style_context_get_border_color(context, GTK_STATE_FLAG_ACTIVE, &color);
-
-    cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
-
-    cairo_set_line_width(cr, 1.0);
-
-    cairo_move_to(cr, left_margin + 0.5, area.y - 0.5);
-    cairo_line_to(cr, left_margin + 0.5, area.y + area.height + 0.5);
-    cairo_stroke(cr);
+    gtk_render_frame(context, cr, - 0.5, area.y - 1, left_margin + 0.5, area.height + 2);
 
     gtk_style_context_restore(context);
 
@@ -500,7 +435,7 @@ static gboolean gtk_buffer_display_draw(GtkWidget *widget, cairo_t *cr)
     if (gtk_widget_is_focus(widget))
     {
         view->show_caret = !view->show_caret;
-        gtk_buffer_view_refresh_caret(view);
+        gtk_buffer_display_refresh_caret(view);
     }
     */
 
@@ -531,7 +466,7 @@ static gboolean gtk_buffer_display_key_press(GtkWidget *widget, GdkEventKey *eve
     GtkBufferDisplay *display;              /* Autre version du composant  */
     GtkDisplayPanel *panel;                 /* Autre version du composant  */
     bool ctrl;                              /* Statut de la touche Contrôle*/
-    GdkRectangle area;                      /* Emplacement de curseur      */
+    cairo_rectangle_int_t area;             /* Emplacement de curseur      */
     vmpa2t addr;                            /* Adresse du nouveau curseur  */
     bool status;                            /* Validité d'un déplacement   */
 
@@ -870,7 +805,7 @@ static bool _gtk_buffer_display_move_caret_to(GtkBufferDisplay *display, gint x,
     bool result;                            /* Bilan à retourner           */
     GtkDisplayPanel *panel;                 /* Autre version du composant  */
     vmpa2t addr;                            /* Position mémoire associée   */
-    GdkRectangle new;                       /* Nouvel emplacement calculé  */
+    cairo_rectangle_int_t new;              /* Nouvel emplacement calculé  */
 
     panel = GTK_DISPLAY_PANEL(display);
 
@@ -951,10 +886,10 @@ bool gtk_buffer_display_move_caret_to(GtkBufferDisplay *display, bool beginning,
 *                                                                             *
 ******************************************************************************/
 
-static void gtk_buffer_display_relocate_caret(GtkBufferDisplay *display, const GdkRectangle *area, const vmpa2t *addr)
+static void gtk_buffer_display_relocate_caret(GtkBufferDisplay *display, const cairo_rectangle_int_t *area, const vmpa2t *addr)
 {
     bool clear_old;                         /* Effacement chirurgical      */
-    GdkRectangle old_area;                  /* Mémorisation de l'ancien    */
+    cairo_rectangle_int_t old_area;         /* Mémorisation de l'ancien    */
     bool need_redraw;                       /* Besoin de rafraîchissement ?*/
 
     if (!is_invalid_vmpa(&display->caret_addr))
@@ -1052,7 +987,9 @@ static gboolean gtk_buffer_display_refresh_caret(GtkBufferDisplay *display)
 {
     GtkWidget *widget;                      /* Autre version du composant  */
     GdkWindow *window;                      /* Fenêtre de support associée */
-    GdkRectangle area;                      /* Région adaptée à traiter    */
+    cairo_rectangle_int_t area;             /* Zone adaptée à traiter      */
+    cairo_region_t *region;                 /* Région définie associée     */
+    GdkDrawingContext *drawing;             /* Mécanisme de dessins        */
     cairo_t *cr;                            /* Contexte graphique          */
     GdkRGBA *color;                         /* Couleur du curseur          */
 
@@ -1085,7 +1022,10 @@ static gboolean gtk_buffer_display_refresh_caret(GtkBufferDisplay *display)
     {
         display->show_caret = true;
 
-        cr = gdk_cairo_create(gtk_widget_get_window(widget));
+        region = cairo_region_create_rectangle(&area);
+
+        drawing = gdk_window_begin_draw_frame(window, region);
+        cr = gdk_drawing_context_get_cairo_context(drawing);
 
         gtk_style_context_get(gtk_widget_get_style_context(widget),
                               gtk_widget_get_state_flags(widget),
@@ -1096,7 +1036,9 @@ static gboolean gtk_buffer_display_refresh_caret(GtkBufferDisplay *display)
         cairo_rectangle(cr, area.x, area.y, area.width, area.height);
         cairo_fill(cr);
 
-        cairo_destroy(cr);
+        gdk_window_end_draw_frame(window, drawing);
+
+        cairo_region_destroy(region);
 
     }
 
diff --git a/src/gtkext/gtkdisplaypanel.c b/src/gtkext/gtkdisplaypanel.c
index 620a1b1..e6efba6 100644
--- a/src/gtkext/gtkdisplaypanel.c
+++ b/src/gtkext/gtkdisplaypanel.c
@@ -791,7 +791,9 @@ void gtk_display_panel_draw_border(GtkDisplayPanel *panel, cairo_t *cr)
 
         gtk_style_context_add_class(context, GTK_STYLE_CLASS_FRAME);
 
-        gtk_style_context_get_border_color(context, GTK_STATE_FLAG_ACTIVE, &color);
+        gtk_style_context_get(gtk_widget_get_style_context(widget),
+                              gtk_widget_get_state_flags(widget),
+                              GTK_STYLE_PROPERTY_COLOR, &color, NULL);
 
         cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha);
 
-- 
cgit v0.11.2-87-g4458