From 071572b0df281cfa04442a636e84fbabd2acfe57 Mon Sep 17 00:00:00 2001
From: Cyrille Bagard <nocbos@gmail.com>
Date: Wed, 8 May 2024 22:24:06 +0200
Subject: Prepare the update of the widget providing a hex view.

---
 configure.ac            |   3 +
 src/Makefile.am         |  27 +++-
 src/gtkext/Makefile.am  |  10 +-
 src/gtkext/hexdisplay.c | 347 ------------------------------------------------
 src/gtkext/hexdisplay.h |  59 --------
 src/gtkext/hexview.c    | 347 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/gtkext/hexview.h    |  59 ++++++++
 7 files changed, 439 insertions(+), 413 deletions(-)
 delete mode 100644 src/gtkext/hexdisplay.c
 delete mode 100644 src/gtkext/hexdisplay.h
 create mode 100644 src/gtkext/hexview.c
 create mode 100644 src/gtkext/hexview.h

diff --git a/configure.ac b/configure.ac
index 790ff74..a0d1e53 100644
--- a/configure.ac
+++ b/configure.ac
@@ -420,6 +420,9 @@ if test "x$enable_gtk_support" = "xyes"; then
     AC_SUBST(TOOLKIT4_CFLAGS)
     AC_SUBST(TOOLKIT4_LIBS)
 
+    AC_SUBST(LIBGTK4_CFLAGS)
+    AC_SUBST(LIBGTK4_LIBS)
+
 else
 
     TOOLKIT_CFLAGS="$LIBGOBJ_CFLAGS $LIBGTHREAD_CFLAGS $LIBGMOD_CFLAGS"
diff --git a/src/Makefile.am b/src/Makefile.am
index a1912b0..89721b9 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
 
-lib_LTLIBRARIES = libchrysacore.la
+lib_LTLIBRARIES = libchrysacoreui.la # libchrysacore.la
 
-bin_PROGRAMS = chrysalide chrysalide-hub rost framework
+bin_PROGRAMS = framework # chrysalide chrysalide-hub rost
 
 
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/intl
@@ -9,7 +9,7 @@ AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/intl
 
 
 ############################################################
-# Bibliothèque dynamique
+# Bibliothèques dynamiques
 ############################################################
 
 #--- libchrysacore
@@ -74,6 +74,21 @@ libchrysacore_la_LDFLAGS += $(LIBMAGIC_LIBS)
 endif
 
 
+#--- libchrysacoreui
+
+if BUILD_GTK_SUPPORT
+
+libchrysacoreui_la_SOURCES =
+
+libchrysacoreui_la_LIBADD =					\
+	gtkext/libgtkext4.la
+
+libchrysacoreui_la_LDFLAGS =				\
+	$(LIBGTK4_CFLAGS)
+
+endif
+
+
 
 ############################################################
 # Programme principal
@@ -95,13 +110,15 @@ chrysalide_LDADD = $(LIBINTL)
 
 
 
+EXTRA_framework_DEPENDENCIES = libchrysacoreui.la
+
 framework_SOURCES = 						\
 	framework.h framework.c
 
-
 framework_CFLAGS = $(TOOLKIT4_CFLAGS)
 
-framework_LDFLAGS = $(TOOLKIT4_LIBS)
+framework_LDFLAGS = $(TOOLKIT4_LIBS) \
+	-L.libs -lchrysacoreui
 
 framework_LDADD =
 
diff --git a/src/gtkext/Makefile.am b/src/gtkext/Makefile.am
index 5bfc55f..a037fb8 100644
--- a/src/gtkext/Makefile.am
+++ b/src/gtkext/Makefile.am
@@ -1,7 +1,7 @@
 
 BUILT_SOURCES = resources.h resources.c
 
-noinst_LTLIBRARIES = libgtkext.la
+noinst_LTLIBRARIES = libgtkext4.la # libgtkext.la
 
 UI_FILES =								\
 	blockbar.ui
@@ -29,12 +29,18 @@ libgtkext_la_SOURCES =						\
 	tiledgrid.h tiledgrid.c					\
 	tmgt.h tmgt.c
 
-libgtkext_la_LIBADD = 					\
+libgtkext_la_LIBADD = 						\
 	graph/libgtkextgraph.la
 
 libgtkext_la_CFLAGS = $(LIBGTK_CFLAGS) $(LIBXML_CFLAGS)
 
 
+libgtkext4_la_SOURCES =						\
+	hexview.h hexview.c
+
+libgtkext4_la_CFLAGS = $(LIBGTK4_CFLAGS)
+
+
 devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
 
 dev_HEADERS = $(libgtkext_la_SOURCES:%c=)
diff --git a/src/gtkext/hexdisplay.c b/src/gtkext/hexdisplay.c
deleted file mode 100644
index 32bd69b..0000000
--- a/src/gtkext/hexdisplay.c
+++ /dev/null
@@ -1,347 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * hexdisplay.c - affichage d'un contenu binaire sous forme hexadécimale
- *
- * Copyright (C) 2019 Cyrille Bagard
- *
- *  This file is part of Chrysalide.
- *
- *  Chrysalide is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  Chrysalide 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#include "hexdisplay.h"
-
-
-#include "gtkbufferdisplay-int.h"
-#include "../core/columns.h"
-#include "../core/params.h"
-#include "../format/format.h"
-#include "../glibext/generators/hex.h"
-
-
-
-/* Composant d'affichage de contenu sous forme hexadécimale (instance) */
-struct _GtkHexDisplay
-{
-    GtkBufferDisplay parent;                /* A laisser en premier        */
-
-    GBufferCache *cache;                    /* Cache pour l'affichage      */
-    GHexGenerator *generator;               /* Générateur à la volée       */
-
-};
-
-/* Composant d'affichage de contenu sous forme hexadécimale (classe) */
-struct _GtkHexDisplayClass
-{
-    GtkBufferDisplayClass parent;           /* A laisser en premier        */
-
-};
-
-
-/* Procède à l'initialisation des afficheurs sous forme hexa. */
-static void gtk_hex_display_class_init(GtkHexDisplayClass *);
-
-/* Procède à l'initialisation de l'afficheur sous forme hexa. */
-static void gtk_hex_display_init(GtkHexDisplay *);
-
-/* Supprime toutes les références externes. */
-static void g_hex_display_dispose(GtkHexDisplay *);
-
-/* Procède à la libération totale de la mémoire. */
-static void g_hex_display_finalize(GtkHexDisplay *);
-
-/* S'adapte à la surface concédée par le composant parent. */
-static void gtk_hex_display_size_allocate(GtkWidget *, GtkAllocation *);
-
-/* Indique les dimensions de travail du composant d'affichage. */
-static void gtk_hex_display_compute_requested_size(GtkHexDisplay *, gint *, gint *);
-
-/* Adapte le cache de lignes hexadécimales à la taille courante. */
-static void gtk_hex_display_populate_cache(GtkHexDisplay *);
-
-
-
-/* Détermine le type du composant d'affichage sous forme hexadécimale. */
-G_DEFINE_TYPE(GtkHexDisplay, gtk_hex_display, GTK_TYPE_BUFFER_DISPLAY)
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : class = classe GTK à initialiser.                            *
-*                                                                             *
-*  Description : Procède à l'initialisation des afficheurs sous forme hexa.   *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void gtk_hex_display_class_init(GtkHexDisplayClass *class)
-{
-    GObjectClass *object;                   /* Autre version de la classe  */
-    GtkWidgetClass *widget_class;           /* Classe de haut niveau       */
-    GtkDisplayPanelClass *panel_class;      /* Classe parente              */
-
-    object = G_OBJECT_CLASS(class);
-
-    object->dispose = (GObjectFinalizeFunc/* ! */)g_hex_display_dispose;
-    object->finalize = (GObjectFinalizeFunc)g_hex_display_finalize;
-
-    widget_class = GTK_WIDGET_CLASS(class);
-
-    widget_class->size_allocate = gtk_hex_display_size_allocate;
-
-    panel_class = GTK_DISPLAY_PANEL_CLASS(class);
-
-    panel_class->compute_size = (compute_requested_size_fc)gtk_hex_display_compute_requested_size;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : view = composant GTK à initialiser.                          *
-*                                                                             *
-*  Description : Procède à l'initialisation de l'afficheur sous forme hexa.   *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void gtk_hex_display_init(GtkHexDisplay *view)
-{
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : display = instance d'objet GLib à traiter.                   *
-*                                                                             *
-*  Description : Supprime toutes les références externes.                     *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void g_hex_display_dispose(GtkHexDisplay *display)
-{
-    g_clear_object(&display->cache);
-
-    g_clear_object(&display->generator);
-
-    G_OBJECT_CLASS(gtk_hex_display_parent_class)->dispose(G_OBJECT(display));
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : display = instance d'objet GLib à traiter.                   *
-*                                                                             *
-*  Description : Procède à la libération totale de la mémoire.                *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void g_hex_display_finalize(GtkHexDisplay *display)
-{
-    G_OBJECT_CLASS(gtk_hex_display_parent_class)->finalize(G_OBJECT(display));
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : content = contenu brut à représenter.                        *
-*                                                                             *
-*  Description : Crée un nouveau composant pour l'affichage sous forme hexa.  *
-*                                                                             *
-*  Retour      : Composant GTK créé.                                          *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-GtkWidget *gtk_hex_display_new(GBinContent *content)
-{
-    GtkHexDisplay *result;                  /* Composant à retourner       */
-    GBufferView *view;                      /* Vue pointée sur un tampon   */
-    int padding;                            /* Bourrage entre colonnes     */
-    GWidthTracker *tracker;                 /* Gestionnaire de largeurs    */
-
-    result = g_object_new(GTK_TYPE_HEX_DISPLAY, NULL);
-
-    result->cache = g_buffer_cache_new(content, HLC_COUNT, HLC_BINARY);
-    g_object_ref_sink(G_OBJECT(result->cache));
-
-    g_generic_config_get_value(get_main_configuration(), MPK_HEX_PADDING, &padding);
-
-    tracker = g_buffer_cache_get_width_tracker(result->cache);
-    g_width_tracker_set_column_min_width(tracker, HLC_PADDING, padding);
-    g_object_unref(G_OBJECT(tracker));
-
-    result->generator = g_hex_generator_new(content);
-
-    gtk_hex_display_populate_cache(result);
-
-    view = g_buffer_view_new(result->cache, NULL);
-
-    GTK_BUFFER_DISPLAY(result)->view = view;
-
-    return GTK_WIDGET(result);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : widget     = composant GTK à mettre à jour.                  *
-*                allocation = étendue accordée à la vue.                      *
-*                                                                             *
-*  Description : S'adapte à la surface concédée par le composant parent.      *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void gtk_hex_display_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
-{
-    GtkHexDisplay *display;                 /* Autre version du composant  */
-    GBufferCache *cache;                    /* Contenu représenté          */
-    gint text_pos;                          /* Abscisse minimale du texte  */
-    bool show_pos;                          /* Affichage des positions ?   */
-    GWidthTracker *tracker;                 /* Gestionnaire de largeurs    */
-    gint padding;                           /* Bourrage supplémentaire     */
-    bool changed;                           /* Note toute variation        */
-
-    display = GTK_HEX_DISPLAY(widget);
-
-    cache = g_buffer_view_get_cache(GTK_BUFFER_DISPLAY(display)->view);
-    text_pos = g_buffer_cache_get_text_position(cache);
-    g_object_unref(G_OBJECT(cache));
-
-    show_pos = g_display_options_get(GTK_DISPLAY_PANEL(widget)->options, 0);
-
-    tracker = g_buffer_cache_get_width_tracker(display->cache);
-    padding = g_width_tracker_get_column_min_width(tracker, HLC_PADDING);
-    g_object_unref(G_OBJECT(tracker));
-
-    changed = g_hex_generator_auto_fit(display->generator, text_pos, show_pos, padding, allocation->width);
-
-    if (changed)
-        gtk_hex_display_populate_cache(display);
-
-    /**
-     * On fait appel au parent en dernier pour bénéficier des besoins
-     * en espace actualisés avec les nouvelles dispositions.
-     */
-
-    GTK_WIDGET_CLASS(gtk_hex_display_parent_class)->size_allocate(widget, allocation);
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : display = composant GTK à consulter.                         *
-*                width   = largeur requise à renseigner ou NULL. [OUT]        *
-*                height  = hauteur requise à renseigner ou NULL. [OUT]        *
-*                                                                             *
-*  Description : Indique les dimensions de travail du composant d'affichage.  *
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void gtk_hex_display_compute_requested_size(GtkHexDisplay *display, gint *width, gint *height)
-{
-    GtkDisplayPanel *pdisplay;              /* Version parente             */
-
-    pdisplay = GTK_DISPLAY_PANEL(display);
-
-    GTK_DISPLAY_PANEL_CLASS(gtk_hex_display_parent_class)->compute_size(pdisplay, width, height);
-
-    if (width != NULL && *width != 0)
-        *width = 1;
-
-}
-
-
-/******************************************************************************
-*                                                                             *
-*  Paramètres  : display = composant GTK à mettre à jour.                     *
-*                                                                             *
-*  Description : Adapte le cache de lignes hexadécimales à la taille courante.*
-*                                                                             *
-*  Retour      : -                                                            *
-*                                                                             *
-*  Remarques   : -                                                            *
-*                                                                             *
-******************************************************************************/
-
-static void gtk_hex_display_populate_cache(GtkHexDisplay *display)
-{
-    GBinContent *content;                   /* Contenu binaire affiché     */
-    phys_t full;                            /* Taille totale à représenter */
-    phys_t line;                            /* Taille représentée par ligne*/
-    size_t needed;                          /* Nombre de lignes nécessaires*/
-    size_t count;                           /* Nombre actuel de lignes     */
-
-    /* Détermination du besoin */
-
-    content = g_hex_generator_get_content(display->generator);
-
-    full = g_binary_content_compute_size(content);
-
-    g_object_unref(G_OBJECT(content));
-
-    line = g_hex_generator_get_bytes_per_line(display->generator);
-
-    needed = full / line;
-
-    if (full % line > 0)
-        needed++;
-
-    /* Adaptation du tampon interne */
-
-    g_buffer_cache_wlock(display->cache);
-
-    count = g_buffer_cache_count_lines(display->cache);
-
-    if (needed < count)
-        g_buffer_cache_truncate(display->cache, needed);
-
-    else if (needed > count)
-        g_buffer_cache_extend_with(display->cache, needed, G_LINE_GENERATOR(display->generator));
-
-    g_buffer_cache_wunlock(display->cache);
-
-    if (needed != count)
-        gtk_widget_queue_resize(GTK_WIDGET(display));
-
-}
diff --git a/src/gtkext/hexdisplay.h b/src/gtkext/hexdisplay.h
deleted file mode 100644
index 9190548..0000000
--- a/src/gtkext/hexdisplay.h
+++ /dev/null
@@ -1,59 +0,0 @@
-
-/* Chrysalide - Outil d'analyse de fichiers binaires
- * hexdisplay.h - prototypes pour l'affichage d'un contenu binaire sous forme hexadécimale
- *
- * Copyright (C) 2019 Cyrille Bagard
- *
- *  This file is part of Chrysalide.
- *
- *  Chrysalide is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 3 of the License, or
- *  (at your option) any later version.
- *
- *  Chrysalide 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-
-#ifndef _GTKEXT_HEXDISPLAY_H
-#define _GTKEXT_HEXDISPLAY_H
-
-
-#include <glib-object.h>
-#include <gtk/gtk.h>
-
-
-#include "../analysis/content.h"
-
-
-
-#define GTK_TYPE_HEX_DISPLAY            (gtk_hex_display_get_type())
-#define GTK_HEX_DISPLAY(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_HEX_DISPLAY, GtkHexDisplay))
-#define GTK_HEX_DISPLAY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_HEX_DISPLAY, GtkHexDisplayClass))
-#define GTK_IS_HEX_DISPLAY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_HEX_DISPLAY))
-#define GTK_IS_HEX_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_HEX_DISPLAY))
-#define GTK_HEX_DISPLAY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_HEX_DISPLAY, GtkHexDisplayClass))
-
-
-/* Composant d'affichage de contenu sous forme hexadécimale (instance) */
-typedef struct _GtkHexDisplay GtkHexDisplay;
-
-/* Composant d'affichage de contenu sous forme hexadécimale (classe) */
-typedef struct _GtkHexDisplayClass GtkHexDisplayClass;
-
-
-/* Détermine le type du composant d'affichage sous forme hexadécimale. */
-GType gtk_hex_display_get_type(void);
-
-/* Crée un nouveau composant pour l'affichage sous forme hexa. */
-GtkWidget *gtk_hex_display_new(GBinContent *);
-
-
-
-#endif  /* _GTKEXT_HEXDISPLAY_H */
diff --git a/src/gtkext/hexview.c b/src/gtkext/hexview.c
new file mode 100644
index 0000000..32bd69b
--- /dev/null
+++ b/src/gtkext/hexview.c
@@ -0,0 +1,347 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hexdisplay.c - affichage d'un contenu binaire sous forme hexadécimale
+ *
+ * Copyright (C) 2019 Cyrille Bagard
+ *
+ *  This file is part of Chrysalide.
+ *
+ *  Chrysalide is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Chrysalide 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "hexdisplay.h"
+
+
+#include "gtkbufferdisplay-int.h"
+#include "../core/columns.h"
+#include "../core/params.h"
+#include "../format/format.h"
+#include "../glibext/generators/hex.h"
+
+
+
+/* Composant d'affichage de contenu sous forme hexadécimale (instance) */
+struct _GtkHexDisplay
+{
+    GtkBufferDisplay parent;                /* A laisser en premier        */
+
+    GBufferCache *cache;                    /* Cache pour l'affichage      */
+    GHexGenerator *generator;               /* Générateur à la volée       */
+
+};
+
+/* Composant d'affichage de contenu sous forme hexadécimale (classe) */
+struct _GtkHexDisplayClass
+{
+    GtkBufferDisplayClass parent;           /* A laisser en premier        */
+
+};
+
+
+/* Procède à l'initialisation des afficheurs sous forme hexa. */
+static void gtk_hex_display_class_init(GtkHexDisplayClass *);
+
+/* Procède à l'initialisation de l'afficheur sous forme hexa. */
+static void gtk_hex_display_init(GtkHexDisplay *);
+
+/* Supprime toutes les références externes. */
+static void g_hex_display_dispose(GtkHexDisplay *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_hex_display_finalize(GtkHexDisplay *);
+
+/* S'adapte à la surface concédée par le composant parent. */
+static void gtk_hex_display_size_allocate(GtkWidget *, GtkAllocation *);
+
+/* Indique les dimensions de travail du composant d'affichage. */
+static void gtk_hex_display_compute_requested_size(GtkHexDisplay *, gint *, gint *);
+
+/* Adapte le cache de lignes hexadécimales à la taille courante. */
+static void gtk_hex_display_populate_cache(GtkHexDisplay *);
+
+
+
+/* Détermine le type du composant d'affichage sous forme hexadécimale. */
+G_DEFINE_TYPE(GtkHexDisplay, gtk_hex_display, GTK_TYPE_BUFFER_DISPLAY)
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : class = classe GTK à initialiser.                            *
+*                                                                             *
+*  Description : Procède à l'initialisation des afficheurs sous forme hexa.   *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_hex_display_class_init(GtkHexDisplayClass *class)
+{
+    GObjectClass *object;                   /* Autre version de la classe  */
+    GtkWidgetClass *widget_class;           /* Classe de haut niveau       */
+    GtkDisplayPanelClass *panel_class;      /* Classe parente              */
+
+    object = G_OBJECT_CLASS(class);
+
+    object->dispose = (GObjectFinalizeFunc/* ! */)g_hex_display_dispose;
+    object->finalize = (GObjectFinalizeFunc)g_hex_display_finalize;
+
+    widget_class = GTK_WIDGET_CLASS(class);
+
+    widget_class->size_allocate = gtk_hex_display_size_allocate;
+
+    panel_class = GTK_DISPLAY_PANEL_CLASS(class);
+
+    panel_class->compute_size = (compute_requested_size_fc)gtk_hex_display_compute_requested_size;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : view = composant GTK à initialiser.                          *
+*                                                                             *
+*  Description : Procède à l'initialisation de l'afficheur sous forme hexa.   *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_hex_display_init(GtkHexDisplay *view)
+{
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display = instance d'objet GLib à traiter.                   *
+*                                                                             *
+*  Description : Supprime toutes les références externes.                     *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void g_hex_display_dispose(GtkHexDisplay *display)
+{
+    g_clear_object(&display->cache);
+
+    g_clear_object(&display->generator);
+
+    G_OBJECT_CLASS(gtk_hex_display_parent_class)->dispose(G_OBJECT(display));
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display = instance d'objet GLib à traiter.                   *
+*                                                                             *
+*  Description : Procède à la libération totale de la mémoire.                *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void g_hex_display_finalize(GtkHexDisplay *display)
+{
+    G_OBJECT_CLASS(gtk_hex_display_parent_class)->finalize(G_OBJECT(display));
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : content = contenu brut à représenter.                        *
+*                                                                             *
+*  Description : Crée un nouveau composant pour l'affichage sous forme hexa.  *
+*                                                                             *
+*  Retour      : Composant GTK créé.                                          *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+GtkWidget *gtk_hex_display_new(GBinContent *content)
+{
+    GtkHexDisplay *result;                  /* Composant à retourner       */
+    GBufferView *view;                      /* Vue pointée sur un tampon   */
+    int padding;                            /* Bourrage entre colonnes     */
+    GWidthTracker *tracker;                 /* Gestionnaire de largeurs    */
+
+    result = g_object_new(GTK_TYPE_HEX_DISPLAY, NULL);
+
+    result->cache = g_buffer_cache_new(content, HLC_COUNT, HLC_BINARY);
+    g_object_ref_sink(G_OBJECT(result->cache));
+
+    g_generic_config_get_value(get_main_configuration(), MPK_HEX_PADDING, &padding);
+
+    tracker = g_buffer_cache_get_width_tracker(result->cache);
+    g_width_tracker_set_column_min_width(tracker, HLC_PADDING, padding);
+    g_object_unref(G_OBJECT(tracker));
+
+    result->generator = g_hex_generator_new(content);
+
+    gtk_hex_display_populate_cache(result);
+
+    view = g_buffer_view_new(result->cache, NULL);
+
+    GTK_BUFFER_DISPLAY(result)->view = view;
+
+    return GTK_WIDGET(result);
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : widget     = composant GTK à mettre à jour.                  *
+*                allocation = étendue accordée à la vue.                      *
+*                                                                             *
+*  Description : S'adapte à la surface concédée par le composant parent.      *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_hex_display_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
+{
+    GtkHexDisplay *display;                 /* Autre version du composant  */
+    GBufferCache *cache;                    /* Contenu représenté          */
+    gint text_pos;                          /* Abscisse minimale du texte  */
+    bool show_pos;                          /* Affichage des positions ?   */
+    GWidthTracker *tracker;                 /* Gestionnaire de largeurs    */
+    gint padding;                           /* Bourrage supplémentaire     */
+    bool changed;                           /* Note toute variation        */
+
+    display = GTK_HEX_DISPLAY(widget);
+
+    cache = g_buffer_view_get_cache(GTK_BUFFER_DISPLAY(display)->view);
+    text_pos = g_buffer_cache_get_text_position(cache);
+    g_object_unref(G_OBJECT(cache));
+
+    show_pos = g_display_options_get(GTK_DISPLAY_PANEL(widget)->options, 0);
+
+    tracker = g_buffer_cache_get_width_tracker(display->cache);
+    padding = g_width_tracker_get_column_min_width(tracker, HLC_PADDING);
+    g_object_unref(G_OBJECT(tracker));
+
+    changed = g_hex_generator_auto_fit(display->generator, text_pos, show_pos, padding, allocation->width);
+
+    if (changed)
+        gtk_hex_display_populate_cache(display);
+
+    /**
+     * On fait appel au parent en dernier pour bénéficier des besoins
+     * en espace actualisés avec les nouvelles dispositions.
+     */
+
+    GTK_WIDGET_CLASS(gtk_hex_display_parent_class)->size_allocate(widget, allocation);
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display = composant GTK à consulter.                         *
+*                width   = largeur requise à renseigner ou NULL. [OUT]        *
+*                height  = hauteur requise à renseigner ou NULL. [OUT]        *
+*                                                                             *
+*  Description : Indique les dimensions de travail du composant d'affichage.  *
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_hex_display_compute_requested_size(GtkHexDisplay *display, gint *width, gint *height)
+{
+    GtkDisplayPanel *pdisplay;              /* Version parente             */
+
+    pdisplay = GTK_DISPLAY_PANEL(display);
+
+    GTK_DISPLAY_PANEL_CLASS(gtk_hex_display_parent_class)->compute_size(pdisplay, width, height);
+
+    if (width != NULL && *width != 0)
+        *width = 1;
+
+}
+
+
+/******************************************************************************
+*                                                                             *
+*  Paramètres  : display = composant GTK à mettre à jour.                     *
+*                                                                             *
+*  Description : Adapte le cache de lignes hexadécimales à la taille courante.*
+*                                                                             *
+*  Retour      : -                                                            *
+*                                                                             *
+*  Remarques   : -                                                            *
+*                                                                             *
+******************************************************************************/
+
+static void gtk_hex_display_populate_cache(GtkHexDisplay *display)
+{
+    GBinContent *content;                   /* Contenu binaire affiché     */
+    phys_t full;                            /* Taille totale à représenter */
+    phys_t line;                            /* Taille représentée par ligne*/
+    size_t needed;                          /* Nombre de lignes nécessaires*/
+    size_t count;                           /* Nombre actuel de lignes     */
+
+    /* Détermination du besoin */
+
+    content = g_hex_generator_get_content(display->generator);
+
+    full = g_binary_content_compute_size(content);
+
+    g_object_unref(G_OBJECT(content));
+
+    line = g_hex_generator_get_bytes_per_line(display->generator);
+
+    needed = full / line;
+
+    if (full % line > 0)
+        needed++;
+
+    /* Adaptation du tampon interne */
+
+    g_buffer_cache_wlock(display->cache);
+
+    count = g_buffer_cache_count_lines(display->cache);
+
+    if (needed < count)
+        g_buffer_cache_truncate(display->cache, needed);
+
+    else if (needed > count)
+        g_buffer_cache_extend_with(display->cache, needed, G_LINE_GENERATOR(display->generator));
+
+    g_buffer_cache_wunlock(display->cache);
+
+    if (needed != count)
+        gtk_widget_queue_resize(GTK_WIDGET(display));
+
+}
diff --git a/src/gtkext/hexview.h b/src/gtkext/hexview.h
new file mode 100644
index 0000000..9190548
--- /dev/null
+++ b/src/gtkext/hexview.h
@@ -0,0 +1,59 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hexdisplay.h - prototypes pour l'affichage d'un contenu binaire sous forme hexadécimale
+ *
+ * Copyright (C) 2019 Cyrille Bagard
+ *
+ *  This file is part of Chrysalide.
+ *
+ *  Chrysalide is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  Chrysalide 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GTKEXT_HEXDISPLAY_H
+#define _GTKEXT_HEXDISPLAY_H
+
+
+#include <glib-object.h>
+#include <gtk/gtk.h>
+
+
+#include "../analysis/content.h"
+
+
+
+#define GTK_TYPE_HEX_DISPLAY            (gtk_hex_display_get_type())
+#define GTK_HEX_DISPLAY(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj), GTK_TYPE_HEX_DISPLAY, GtkHexDisplay))
+#define GTK_HEX_DISPLAY_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass), GTK_TYPE_HEX_DISPLAY, GtkHexDisplayClass))
+#define GTK_IS_HEX_DISPLAY(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj), GTK_TYPE_HEX_DISPLAY))
+#define GTK_IS_HEX_DISPLAY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GTK_TYPE_HEX_DISPLAY))
+#define GTK_HEX_DISPLAY_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj), GTK_TYPE_HEX_DISPLAY, GtkHexDisplayClass))
+
+
+/* Composant d'affichage de contenu sous forme hexadécimale (instance) */
+typedef struct _GtkHexDisplay GtkHexDisplay;
+
+/* Composant d'affichage de contenu sous forme hexadécimale (classe) */
+typedef struct _GtkHexDisplayClass GtkHexDisplayClass;
+
+
+/* Détermine le type du composant d'affichage sous forme hexadécimale. */
+GType gtk_hex_display_get_type(void);
+
+/* Crée un nouveau composant pour l'affichage sous forme hexa. */
+GtkWidget *gtk_hex_display_new(GBinContent *);
+
+
+
+#endif  /* _GTKEXT_HEXDISPLAY_H */
-- 
cgit v0.11.2-87-g4458