From 3c183ee3be9cd5756bbefe688936fbab370e3840 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Fri, 21 Dec 2018 10:36:52 +0100
Subject: Used only abstract cursors in views high API.

---
 src/gtkext/gtkblockdisplay.c      | 29 ------------------
 src/gtkext/gtkbufferdisplay-int.h |  1 -
 src/gtkext/gtkbufferdisplay.c     | 63 +++++++++++++++++++++------------------
 src/gtkext/gtkdisplaypanel-int.h  |  4 ---
 src/gtkext/gtkdisplaypanel.c      | 23 --------------
 src/gtkext/gtkdisplaypanel.h      |  3 --
 src/gtkext/gtkgraphdisplay.c      | 23 --------------
 src/gui/menus/edition.c           | 32 ++++++++++++--------
 8 files changed, 53 insertions(+), 125 deletions(-)

diff --git a/src/gtkext/gtkblockdisplay.c b/src/gtkext/gtkblockdisplay.c
index bbba06c..92c445b 100644
--- a/src/gtkext/gtkblockdisplay.c
+++ b/src/gtkext/gtkblockdisplay.c
@@ -72,9 +72,6 @@ static gboolean gtk_block_display_query_tooltip(GtkWidget *, gint, gint, gboolea
 /* Redessine l'affichage suite à un changement visuel. */
 static gboolean gtk_block_display_need_redraw(GtkBlockDisplay *, GBufferView *);
 
-/* Fournit le position courante dans un panneau de chargement. */
-static GLineCursor *gtk_block_display_get_cursor(const GtkBlockDisplay *);
-
 /* Définit le position courante dans un panneau de chargement. */
 static void gtk_block_display_set_cursor(GtkBlockDisplay *, const GLineCursor *);
 
@@ -118,7 +115,6 @@ static void gtk_block_display_class_init(GtkBlockDisplayClass *class)
 
     panel_class = GTK_DISPLAY_PANEL_CLASS(class);
 
-    panel_class->get_cursor = (get_cursor_fc)gtk_block_display_get_cursor;
     panel_class->set_cursor = (set_cursor_fc)gtk_block_display_set_cursor;
 
     buffer_class = GTK_BUFFER_DISPLAY_CLASS(class);
@@ -370,31 +366,6 @@ static gboolean gtk_block_display_need_redraw(GtkBlockDisplay *display, GBufferV
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : display = composant GTK à consulter.                         *
-*                                                                             *
-*  Description : Fournit le position courante dans un panneau de chargement.  *
-*                                                                             *
-*  Retour      : Informations relatives à la position du curseur.             *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static GLineCursor *gtk_block_display_get_cursor(const GtkBlockDisplay *display)
-{
-    GLineCursor *result;                    /* Contenu à retourner         */
-
-    result = g_binary_cursor_new();
-
-    g_binary_cursor_update(G_BINARY_CURSOR(result), &GTK_BUFFER_DISPLAY(display)->caret_addr);
-
-    return result;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
 *  Paramètres  : display = composant GTK à mettre à jour.                     *
 *                cursor  = informations relatives à la position du curseur.   *
 *                                                                             *
diff --git a/src/gtkext/gtkbufferdisplay-int.h b/src/gtkext/gtkbufferdisplay-int.h
index 2d78b1d..c84f6d5 100644
--- a/src/gtkext/gtkbufferdisplay-int.h
+++ b/src/gtkext/gtkbufferdisplay-int.h
@@ -45,7 +45,6 @@ struct _GtkBufferDisplay
     line_width_summary offsets;             /* Décalages supplémentaires   */
 
     cairo_rectangle_int_t caret;            /* Emplacement du curseur #1   */
-    vmpa2t caret_addr;                      /* Position mémoire du curseur */
     GLineCursor *cursor;                    /* Emplacement du curseur #2   */
     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 a748cf2..1b452f1 100644
--- a/src/gtkext/gtkbufferdisplay.c
+++ b/src/gtkext/gtkbufferdisplay.c
@@ -71,9 +71,6 @@ static void gtk_buffer_display_compute_scroll_inc(GtkBufferDisplay *, gint, GtkO
 /* Réagit à un défilement chez une barre associée au composant. */
 static void gtk_buffer_display_adjust_scroll_value(GtkBufferDisplay *, GtkAdjustment *, GtkOrientation);
 
-/* Indique la position courante du curseur. */
-static const vmpa2t *gtk_buffer_display_get_caret_location(const GtkBufferDisplay *);
-
 /* Indique la position d'affichage d'un emplacement donné. */
 static bool gtk_buffer_display_get_cursor_coordinates(const GtkBufferDisplay *, const GLineCursor *, gint *, gint *, ScrollPositionTweak);
 
@@ -83,6 +80,9 @@ GObject *gtk_buffer_display_get_active_object(const GtkBufferDisplay *);
 /* Place en cache un rendu destiné à l'aperçu graphique rapide. */
 static void gtk_buffer_display_cache_glance(GtkBufferDisplay *, cairo_t *, const GtkAllocation *, double);
 
+/* Fournit le position courante dans un panneau de chargement. */
+static GLineCursor *gtk_buffer_display_get_cursor(const GtkBufferDisplay *);
+
 
 
 /* ------------------------------ ANIMATION DU CURSEUR ------------------------------ */
@@ -153,12 +153,13 @@ static void gtk_buffer_display_class_init(GtkBufferDisplayClass *class)
     panel_class->compute_size = (compute_requested_size_fc)gtk_buffer_display_compute_requested_size;
     panel_class->compute_inc = (compute_scroll_inc_fc)gtk_buffer_display_compute_scroll_inc;
     panel_class->adjust = (adjust_scroll_value_fc)gtk_buffer_display_adjust_scroll_value;
-    panel_class->get_caret_loc = (get_caret_location_fc)gtk_buffer_display_get_caret_location;
     panel_class->get_coordinates = (get_coordinates_fc)gtk_buffer_display_get_cursor_coordinates;
     panel_class->get_active = (get_active_object_fc)gtk_buffer_display_get_active_object;
     panel_class->move_caret_to = (move_caret_to_fc)_gtk_buffer_display_move_caret_to;
     panel_class->cache_glance = (cache_glance_fc)gtk_buffer_display_cache_glance;
 
+    panel_class->get_cursor = (get_cursor_fc)gtk_buffer_display_get_cursor;
+
     /* Signaux */
 
     g_signal_new("reach-limit",
@@ -649,25 +650,6 @@ static void gtk_buffer_display_adjust_scroll_value(GtkBufferDisplay *display, Gt
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : display = composant GTK à manipuler.                         *
-*                                                                             *
-*  Description : Indique la position courante du curseur.                     *
-*                                                                             *
-*  Retour      : Emplacement courant du curseur ou NULL si aucun.             *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static const vmpa2t *gtk_buffer_display_get_caret_location(const GtkBufferDisplay *display)
-{
-    return &display->caret_addr;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
 *  Paramètres  : display = composant GTK à consulter.                         *
 *                cursor  = emplacement à présenter à l'écran.                 *
 *                x       = position horizontale au sein du composant. [OUT]   *
@@ -791,6 +773,35 @@ static void gtk_buffer_display_cache_glance(GtkBufferDisplay *display, cairo_t *
 *                                                                             *
 *  Paramètres  : display = composant GTK à consulter.                         *
 *                                                                             *
+*  Description : Fournit le position courante dans un panneau de chargement.  *
+*                                                                             *
+*  Retour      : Informations relatives à la position du curseur.             *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static GLineCursor *gtk_buffer_display_get_cursor(const GtkBufferDisplay *display)
+{
+    GLineCursor *result;                    /* Contenu à retourner         */
+
+    if (display->cursor != NULL)
+    {
+        result = display->cursor;
+        g_object_ref(G_OBJECT(result));
+    }
+    else
+        result = g_binary_cursor_new();
+
+    return result;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display = composant GTK à consulter.                         *
+*                                                                             *
 *  Description : Fournit la vue associée au tampon de lignes courant.         *
 *                                                                             *
 *  Retour      : Vue mise en place.                                           *
@@ -989,12 +1000,6 @@ static void gtk_buffer_display_relocate_caret(GtkBufferDisplay *display, const c
     display->caret = *area;
     display->cursor = cursor;
 
-    /////////////////
-    if (cursor != NULL)
-        g_binary_cursor_get_info(G_BINARY_CURSOR(cursor), &display->caret_addr);
-    /////////////////
-
-
     if (GTK_BUFFER_DISPLAY_GET_CLASS(display)->notify_caret != NULL)
         need_redraw = GTK_BUFFER_DISPLAY_GET_CLASS(display)->notify_caret(display, area);
     else
diff --git a/src/gtkext/gtkdisplaypanel-int.h b/src/gtkext/gtkdisplaypanel-int.h
index b1a96e9..90b146c 100644
--- a/src/gtkext/gtkdisplaypanel-int.h
+++ b/src/gtkext/gtkdisplaypanel-int.h
@@ -49,9 +49,6 @@ typedef void (* adjust_scroll_value_fc) (GtkDisplayPanel *, GtkAdjustment *, Gtk
 /* Réagit à la sélection externe d'une adresse. */
 typedef void (* define_address_fc) (GtkDisplayPanel *, const vmpa2t *);
 
-/* Indique la position courante du curseur. */
-typedef const vmpa2t * (* get_caret_location_fc) (const GtkDisplayPanel *);
-
 /* Indique la position d'affichage d'une adresse donnée. */
 typedef bool (* get_coordinates_fc) (const GtkDisplayPanel *, const GLineCursor *, gint *, gint *, ScrollPositionTweak);
 
@@ -102,7 +99,6 @@ struct _GtkDisplayPanelClass
     compute_scroll_inc_fc compute_inc;      /* Calcul des bonds            */
     adjust_scroll_value_fc adjust;          /* Réaction à un défilement    */
     define_address_fc define;               /* Centrage sur une partie     */
-    get_caret_location_fc get_caret_loc;    /* Adresse du curseur          */
     get_coordinates_fc get_coordinates;     /* Conversion adresse <-> pos. */
     get_active_object_fc get_active;        /* Infos sur l'objet actif     */
     move_caret_to_fc move_caret_to;         /* Déplacement du curseur      */
diff --git a/src/gtkext/gtkdisplaypanel.c b/src/gtkext/gtkdisplaypanel.c
index 93e47e7..b937e2e 100644
--- a/src/gtkext/gtkdisplaypanel.c
+++ b/src/gtkext/gtkdisplaypanel.c
@@ -864,29 +864,6 @@ void gtk_display_panel_draw_border(GtkDisplayPanel *panel, cairo_t *cr)
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : panel = composant GTK à consulter.                           *
-*                                                                             *
-*  Description : Indique la position courante du curseur.                     *
-*                                                                             *
-*  Retour      : Emplacement courant du curseur ou NULL si aucun.             *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-const vmpa2t *gtk_display_panel_get_caret_location(const GtkDisplayPanel *panel)
-{
-    const vmpa2t *result;                   /* Adresse à retourner         */
-
-    result = GTK_DISPLAY_PANEL_GET_CLASS(panel)->get_caret_loc(panel);
-
-    return result;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
 *  Paramètres  : panel  = composant GTK à consulter.                          *
 *                cursor = emplacement à présenter à l'écran.                  *
 *                x      = position horizontale au sein du composant. [OUT]    *
diff --git a/src/gtkext/gtkdisplaypanel.h b/src/gtkext/gtkdisplaypanel.h
index 6baac64..954991c 100644
--- a/src/gtkext/gtkdisplaypanel.h
+++ b/src/gtkext/gtkdisplaypanel.h
@@ -61,9 +61,6 @@ void gtk_display_panel_set_addresses_display(GtkDisplayPanel *, bool);
 /* Définit si le code doit apparaître dans le rendu. */
 void gtk_display_panel_set_code_display(GtkDisplayPanel *, bool);
 
-/* Indique la position courante du curseur. */
-const vmpa2t *gtk_display_panel_get_caret_location(const GtkDisplayPanel *);
-
 /* Indique la position d'affichage d'un emplacement donné. */
 bool gtk_display_panel_get_cursor_coordinates(const GtkDisplayPanel *, const GLineCursor *, gint *, gint *, ScrollPositionTweak);
 
diff --git a/src/gtkext/gtkgraphdisplay.c b/src/gtkext/gtkgraphdisplay.c
index 6187677..fdd48ce 100644
--- a/src/gtkext/gtkgraphdisplay.c
+++ b/src/gtkext/gtkgraphdisplay.c
@@ -117,9 +117,6 @@ static gboolean gtk_graph_display_motion_notify(GtkWidget *, GdkEventMotion *, G
 /* Réagit à la sélection externe d'une adresse. */
 static void gtk_graph_display_define_main_address(GtkGraphDisplay *, const vmpa2t *);
 
-/* Indique la position courante du curseur. */
-static const vmpa2t *gtk_graph_display_get_caret_location(const GtkGraphDisplay *);
-
 /* Indique la position d'affichage d'un emplacement donné. */
 static bool gtk_graph_display_get_cursor_coordinates(const GtkGraphDisplay *, const GLineCursor *, gint *, gint *, ScrollPositionTweak);
 
@@ -183,7 +180,6 @@ static void gtk_graph_display_class_init(GtkGraphDisplayClass *class)
     panel_class->adjust = (adjust_scroll_value_fc)gtk_graph_display_adjust_scroll_value;
     panel_class->define = (define_address_fc)gtk_graph_display_define_main_address;
 
-    panel_class->get_caret_loc = (get_caret_location_fc)gtk_graph_display_get_caret_location;
     panel_class->get_coordinates = (get_coordinates_fc)gtk_graph_display_get_cursor_coordinates;
     panel_class->move_caret_to = (move_caret_to_fc)gtk_graph_display_move_caret_to;
     panel_class->get_cursor = (get_cursor_fc)gtk_graph_display_get_cursor;
@@ -722,25 +718,6 @@ static void gtk_graph_display_define_main_address(GtkGraphDisplay *display, cons
 
 /******************************************************************************
 *                                                                             *
-*  Paramètres  : display = composant GTK à manipuler.                         *
-*                                                                             *
-*  Description : Indique la position courante du curseur.                     *
-*                                                                             *
-*  Retour      : Emplacement courant du curseur ou NULL si aucun.             *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static const vmpa2t *gtk_graph_display_get_caret_location(const GtkGraphDisplay *display)
-{
-    return NULL;    /* FIXME */
-
-}
-
-
-/******************************************************************************
-*                                                                             *
 *  Paramètres  : display = composant GTK à consulter.                         *
 *                cursor  = emplacement à présenter à l'écran.                 *
 *                x       = position horizontale au sein du composant. [OUT]   *
diff --git a/src/gui/menus/edition.c b/src/gui/menus/edition.c
index 1742616..b1ac0ad 100644
--- a/src/gui/menus/edition.c
+++ b/src/gui/menus/edition.c
@@ -464,7 +464,8 @@ static void mcb_edition_switch_numeric_operand(GtkMenuItem *menuitem, gpointer u
     ImmOperandDisplay display;              /* Type de basculement         */
     GLoadedPanel *panel;                    /* Afficheur effectif de code  */
     GObject *creator;                       /* Créateur à l'orgine du seg. */
-    const vmpa2t *addr;                     /* Position courante           */
+    GLineCursor *cursor;                    /* Position courante           */
+    vmpa2t addr;                            /* Adresse courante            */
     GLoadedBinary *binary;                  /* Binaire en cours d'étude    */
     GArchProcessor *proc;                   /* Propriétaire d'instructions */
     GArchInstruction *instr;                /* Instruction liée à la ligne */
@@ -478,12 +479,14 @@ static void mcb_edition_switch_numeric_operand(GtkMenuItem *menuitem, gpointer u
     creator = gtk_display_panel_get_active_object(GTK_DISPLAY_PANEL(panel));
     assert(G_IS_IMM_OPERAND(creator));
 
-    addr = gtk_display_panel_get_caret_location(GTK_DISPLAY_PANEL(panel));
+    cursor = g_loaded_panel_get_cursor(panel);
+    g_binary_cursor_get_info(G_BINARY_CURSOR(cursor), &addr);
+    g_object_unref(G_OBJECT(cursor));
 
     binary = G_LOADED_BINARY(get_current_content());
     proc = g_loaded_binary_get_processor(binary);
 
-    instr = g_arch_processor_find_instr_by_address(proc, addr);
+    instr = g_arch_processor_find_instr_by_address(proc, &addr);
     assert(instr != NULL);
 
     switcher = g_db_switcher_new(instr, G_IMM_OPERAND(creator), display);
@@ -601,7 +604,8 @@ static void mcb_edition_follow_ref(GtkMenuItem *menuitem, gpointer unused)
 static void mcb_edition_list_xrefs(GtkMenuItem *menuitem, GMenuBar *bar)
 {
     GLoadedPanel *panel;                    /* Afficheur effectif de code  */
-    const vmpa2t *addr;                     /* Position courante           */
+    GLineCursor *cursor;                    /* Position courante           */
+    vmpa2t addr;                            /* Adresse courante            */
     GLoadedBinary *binary;                  /* Représentation binaire      */
     GArchProcessor *proc;                   /* Processeur de l'architecture*/
     GArchInstruction *instr;                /* Point de croisements        */
@@ -612,7 +616,9 @@ static void mcb_edition_list_xrefs(GtkMenuItem *menuitem, GMenuBar *bar)
     panel = get_current_view();
     assert(GTK_IS_BLOCK_DISPLAY(panel) || GTK_IS_GRAPH_DISPLAY(panel));
 
-    addr = gtk_display_panel_get_caret_location(GTK_DISPLAY_PANEL(panel));
+    cursor = g_loaded_panel_get_cursor(panel);
+    g_binary_cursor_get_info(G_BINARY_CURSOR(cursor), &addr);
+    g_object_unref(G_OBJECT(cursor));
 
     binary = G_LOADED_BINARY(get_current_content());
     proc = g_loaded_binary_get_processor(binary);
@@ -625,7 +631,7 @@ static void mcb_edition_list_xrefs(GtkMenuItem *menuitem, GMenuBar *bar)
      * Il faut ainsi être plus souple, et se baser sur l'espace couvert par
      * une ligne mais sur l'adresse uniquement.
      */
-    instr = g_arch_processor_find_instr_by_address(proc, addr);
+    instr = g_arch_processor_find_instr_by_address(proc, &addr);
 
     if (instr != NULL)
     {
@@ -673,7 +679,8 @@ static void mcb_edition_list_xrefs(GtkMenuItem *menuitem, GMenuBar *bar)
 static void mcb_edition_bookmarks_toggle(GtkMenuItem *menuitem, GMenuBar *bar)
 {
     GLoadedPanel *panel;                    /* Vue offrant l'affichage     */
-    const vmpa2t *curloc;                   /* Localisation d'un curseur   */
+    GLineCursor *cursor;                    /* Position courante           */
+    vmpa2t addr;                            /* Adresse courante            */
     GLoadedBinary *binary;                  /* Binaire en cours d'étude    */
     GDbCollection *collec;                  /* Collection à manipuler      */
     GDbItem *exist;                         /* Sens du basculement courant */
@@ -688,7 +695,9 @@ static void mcb_edition_bookmarks_toggle(GtkMenuItem *menuitem, GMenuBar *bar)
     panel = get_current_view();
     assert(GTK_IS_BLOCK_DISPLAY(panel) || GTK_IS_GRAPH_DISPLAY(panel));
 
-    curloc = gtk_display_panel_get_caret_location(GTK_DISPLAY_PANEL(panel));
+    cursor = g_loaded_panel_get_cursor(panel);
+    g_binary_cursor_get_info(G_BINARY_CURSOR(cursor), &addr);
+    g_object_unref(G_OBJECT(cursor));
 
     /* Accès à la collection */
 
@@ -704,10 +713,7 @@ static void mcb_edition_bookmarks_toggle(GtkMenuItem *menuitem, GMenuBar *bar)
      *    peut de plus modifier la position pendant la définition.
      */
 
-    if (curloc == NULL)
-        exist = NULL;
-    else
-        exist = NULL;//g_db_collection_has_key(collec, curloc);
+    exist = NULL;//g_db_collection_has_key(collec, &addr);
 
     if (exist != NULL)
         g_loaded_binary_remove_from_collection(binary, DBF_BOOKMARKS, exist);
@@ -722,7 +728,7 @@ static void mcb_edition_bookmarks_toggle(GtkMenuItem *menuitem, GMenuBar *bar)
 
         if (ret == GTK_RESPONSE_OK)
         {
-            bookmark = get_item_from_bookmark_dialog(builder, curloc);
+            bookmark = get_item_from_bookmark_dialog(builder, &addr);
 
             g_db_collection_wlock(G_DB_COLLECTION(collec));
 
-- 
cgit v0.11.2-87-g4458