summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2024-06-04 10:34:24 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2024-06-04 10:36:13 (GMT)
commit4218b6e8f87893a31c292dbb32c328b81e18ec61 (patch)
treeaa2e56259aef63dde37fa93e80dc02eb0b512906
parent20e004389791cce24682a426a183a665247e2920 (diff)
Define rendering options for content views.
-rw-r--r--configure.ac1
-rw-r--r--src/glibext/options-int.h60
-rw-r--r--src/glibext/options.c125
-rw-r--r--src/glibext/options.h31
-rw-r--r--src/glibext/options/Makefile.am13
-rw-r--r--src/glibext/options/hex-int.h49
-rw-r--r--src/glibext/options/hex.c169
-rw-r--r--src/glibext/options/hex.h42
-rw-r--r--src/gtkext/contentview-int.h1
-rw-r--r--src/gtkext/contentview.c2
-rw-r--r--src/gtkext/contentview.h1
11 files changed, 370 insertions, 124 deletions
diff --git a/configure.ac b/configure.ac
index a0d1e53..749812c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -803,6 +803,7 @@ AC_CONFIG_FILES([Makefile
src/format/Makefile
src/glibext/Makefile
src/glibext/generators/Makefile
+ src/glibext/options/Makefile
src/gtkext/Makefile
src/gtkext/graph/Makefile
src/gui/Makefile
diff --git a/src/glibext/options-int.h b/src/glibext/options-int.h
new file mode 100644
index 0000000..8db247b
--- /dev/null
+++ b/src/glibext/options-int.h
@@ -0,0 +1,60 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * options-int.h - prototypes pour les définitions internes d'options de rendus des lignes de code
+ *
+ * Copyright (C) 2018-2024 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GLIBEXT_OPTIONS_INT_H
+#define _GLIBEXT_OPTIONS_INT_H
+
+
+#include "options.h"
+
+
+
+/* Options de représentation (instance) */
+struct _GDisplayOptions
+{
+ GObject parent; /* A laisser en premier */
+
+ char **names; /* Désignations des options */
+ bool *values; /* Valeurs des options */
+ size_t count; /* Nombre de ces options */
+
+};
+
+/* Options de représentation (classe) */
+struct _GDisplayOptionsClass
+{
+ GObjectClass parent; /* A laisser en premier */
+
+ /* Signaux */
+
+ void (* state_changed) (const GDisplayOptions *);
+
+};
+
+
+/* Met en place un groupe d'options pour le rendu des lignes. */
+bool g_display_options_create(GDisplayOptions *, const char **, const bool *, size_t);
+
+
+
+#endif /* _GLIBEXT_OPTIONS_INT_H */
diff --git a/src/glibext/options.c b/src/glibext/options.c
index a8f835b..4739ea4 100644
--- a/src/glibext/options.c
+++ b/src/glibext/options.c
@@ -1,8 +1,8 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
- * gdisplayoptions.h - options de rendus des lignes de code
+ * options.c - options de rendus des lignes de code
*
- * Copyright (C) 2018 Cyrille Bagard
+ * Copyright (C) 2018-2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -21,7 +21,7 @@
*/
-#include "gdisplayoptions.h"
+#include "options.h"
#include <assert.h>
@@ -29,33 +29,10 @@
#include <string.h>
-#include "chrysamarshal.h"
+#include "options-int.h"
-/* Options de représentation (instance) */
-struct _GDisplayOptions
-{
- GObject parent; /* A laisser en premier */
-
- char **names; /* Désignations des options */
- bool *values; /* Valeurs des options */
- size_t count; /* Nombre de ces options */
-
-};
-
-/* Options de représentation (classe) */
-struct _GDisplayOptionsClass
-{
- GObjectClass parent; /* A laisser en premier */
-
- /* Signaux */
-
- void (* value_changed) (const GDisplayOptions *, gsize, gboolean);
-
-};
-
-
/* Initialise la classe des options pour le rendu des lignes. */
static void g_display_options_class_init(GDisplayOptionsClass *);
@@ -95,22 +72,13 @@ static void g_display_options_class_init(GDisplayOptionsClass *klass)
object->dispose = (GObjectFinalizeFunc/* ! */)g_display_options_dispose;
object->finalize = (GObjectFinalizeFunc)g_display_options_finalize;
- /**
- * Note : il n'existe pas de G_TYPE_GSIZE.
- *
- * Or la documentation précise :
- *
- * typedef unsigned long gsize;
- *
- */
-
- g_signal_new("value-changed",
+ g_signal_new("state-changed",
G_TYPE_DISPLAY_OPTIONS,
G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET(GDisplayOptionsClass, value_changed),
+ G_STRUCT_OFFSET(GDisplayOptionsClass, state_changed),
NULL, NULL,
- g_cclosure_user_marshal_VOID__ULONG_BOOLEAN,
- G_TYPE_NONE, 2, G_TYPE_ULONG, G_TYPE_BOOLEAN);
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
}
@@ -187,51 +155,35 @@ static void g_display_options_finalize(GDisplayOptions *options)
/******************************************************************************
* *
-* Paramètres : - *
+* Paramètres : options = ensemble d'options à initialiser pleinement. *
+* names = désignation humaine de chaque option d'affichage. *
+* values = valeur initiale de chacune de ces options. *
+* count = quantité d'options prises en compte. *
* *
-* Description : Crée un groupe d'options pour le rendu des lignes. *
+* Description : Met en place un groupe d'options pour le rendu des lignes. *
* *
-* Retour : Adresse de la structure mise en place. *
+* Retour : Bilan de l'opération. *
* *
* Remarques : - *
* *
******************************************************************************/
-GDisplayOptions *g_display_options_new(void)
+bool g_display_options_create(GDisplayOptions *options, const char **names, const bool *values, size_t count)
{
- GDisplayOptions *result; /* Structure à retourner */
-
- result = g_object_new(G_TYPE_DISPLAY_OPTIONS, NULL);
-
- return result;
-
-}
-
-
-/******************************************************************************
-* *
-* Paramètres : template = modèle de groupe à copier. *
-* *
-* Description : Copie un groupe d'options pour le rendu des lignes. *
-* *
-* Retour : Adresse de la structure mise en place. *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-GDisplayOptions *g_display_options_dup(const GDisplayOptions *template)
-{
- GDisplayOptions *result; /* Structure à retourner */
- size_t count; /* Nombre d'options à copier */
+ bool result; /* Bilan à retourner */
size_t i; /* Boucle de parcours */
- result = g_display_options_new();
+ result = true;
- count = g_display_options_count(template);
+ options->names = malloc(count * sizeof(char *));
+ options->values = malloc(count * sizeof(bool));
+ options->count = count;
for (i = 0; i < count; i++)
- g_display_options_add(result, template->names[i], template->values[i]);
+ {
+ options->names[i] = strdup(names[i]);
+ options->values[i] = values[i];
+ }
return result;
@@ -263,33 +215,6 @@ size_t g_display_options_count(const GDisplayOptions *options)
/******************************************************************************
* *
-* Paramètres : options = options à compléter. *
-* name = désignation humaine de la nouvelle option. *
-* value = valeur initiale de l'option à ajouter. *
-* *
-* Description : Ajoute une nouvelle option à l'ensemble. *
-* *
-* Retour : - *
-* *
-* Remarques : - *
-* *
-******************************************************************************/
-
-void g_display_options_add(GDisplayOptions *options, const char *name, bool value)
-{
- options->count++;
-
- options->names = (char **)realloc(options->names, options->count * sizeof(char *));
- options->values = (bool *)realloc(options->values, options->count * sizeof(bool));
-
- options->names[options->count - 1] = strdup(name);
- options->values[options->count - 1] = value;
-
-}
-
-
-/******************************************************************************
-* *
* Paramètres : options = options à consulter. *
* index = indice de l'option concernée. *
* *
@@ -378,6 +303,6 @@ void g_display_options_set(GDisplayOptions *options, size_t index, bool value)
changed = false;
if (changed)
- g_signal_emit_by_name(options, "value-changed", index, value);
+ g_signal_emit_by_name(options, "state-changed");
}
diff --git a/src/glibext/options.h b/src/glibext/options.h
index 1a30e81..3d2db97 100644
--- a/src/glibext/options.h
+++ b/src/glibext/options.h
@@ -2,7 +2,7 @@
/* Chrysalide - Outil d'analyse de fichiers binaires
* gdisplayoptions.h - prototypes pour les options de rendus des lignes de code
*
- * Copyright (C) 2018 Cyrille Bagard
+ * Copyright (C) 2018-2024 Cyrille Bagard
*
* This file is part of Chrysalide.
*
@@ -21,45 +21,28 @@
*/
-#ifndef _GLIBEXT_GDISPLAYOPTIONS_H
-#define _GLIBEXT_GDISPLAYOPTIONS_H
+#ifndef _GLIBEXT_OPTIONS_H
+#define _GLIBEXT_OPTIONS_H
-#include <glib-object.h>
#include <stdbool.h>
+#include "helpers.h"
-#define G_TYPE_DISPLAY_OPTIONS g_display_options_get_type()
-#define G_DISPLAY_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), G_TYPE_DISPLAY_OPTIONS, GDisplayOptions))
-#define G_IS_DISPLAY_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), G_TYPE_DISPLAY_OPTIONS))
-#define G_DISPLAY_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), G_TYPE_DISPLAY_OPTIONS, GDisplayOptionsClass))
-#define G_IS_DISPLAY_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), G_TYPE_DISPLAY_OPTIONS))
-#define G_DISPLAY_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DISPLAY_OPTIONS, GDisplayOptionsClass))
-/* Options de représentation (instance) */
-typedef struct _GDisplayOptions GDisplayOptions;
+#define G_TYPE_DISPLAY_OPTIONS (g_display_options_get_type())
-/* Options de représentation (classe) */
-typedef struct _GDisplayOptionsClass GDisplayOptionsClass;
+DECLARE_GTYPE(GDisplayOptions, g_display_options, G, DISPLAY_OPTIONS);
-/* Indique le type défini pour des options de représentation. */
-GType g_display_options_get_type(void);
-
-/* Crée un groupe d'options pour le rendu des lignes. */
-GDisplayOptions *g_display_options_new(void);
-
/* Copie un groupe d'options pour le rendu des lignes. */
GDisplayOptions *g_display_options_dup(const GDisplayOptions *);
/* Dénombre la quantité d'options représentées. */
size_t g_display_options_count(const GDisplayOptions *);
-/* Ajoute une nouvelle option à l'ensemble. */
-void g_display_options_add(GDisplayOptions *, const char *, bool);
-
/* Fournit la désignation d'une option donnée. */
const char *g_display_options_get_name(const GDisplayOptions *, size_t);
@@ -71,4 +54,4 @@ void g_display_options_set(GDisplayOptions *, size_t, bool);
-#endif /* _GLIBEXT_GDISPLAYOPTIONS_H */
+#endif /* _GLIBEXT_OPTIONS_H */
diff --git a/src/glibext/options/Makefile.am b/src/glibext/options/Makefile.am
new file mode 100644
index 0000000..448de7b
--- /dev/null
+++ b/src/glibext/options/Makefile.am
@@ -0,0 +1,13 @@
+
+noinst_LTLIBRARIES = libglibextoptions.la
+
+
+libglibextoptions_la_SOURCES = \
+ hex.h hex.c
+
+libglibextoptions_la_CFLAGS = $(TOOLKIT_CFLAGS)
+
+
+devdir = $(includedir)/chrysalide/$(subdir:src/%=core/%)
+
+dev_HEADERS = $(libglibextoptions_la_SOURCES:%c=)
diff --git a/src/glibext/options/hex-int.h b/src/glibext/options/hex-int.h
new file mode 100644
index 0000000..45c822b
--- /dev/null
+++ b/src/glibext/options/hex-int.h
@@ -0,0 +1,49 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex-int.h - prototypes pour les définitions internes d'options de rendus de code héxadécimal
+ *
+ * Copyright (C) 2024 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GLIBEXT_OPTIONS_HEX_INT_H
+#define _GLIBEXT_OPTIONS_HEX_INT_H
+
+
+#include "hex.h"
+#include "../options-int.h"
+
+
+
+/* Options de représentation pour contenu hexadécimal (instance) */
+struct _GHexOptions
+{
+ GDisplayOptions parent; /* A laisser en premier */
+
+};
+
+/* Options de représentation pour contenu hexadécimal (classe) */
+struct _GHexOptionsClass
+{
+ GDisplayOptionsClass parent; /* A laisser en premier */
+
+};
+
+
+
+#endif /* _GLIBEXT_OPTIONS_HEX_INT_H */
diff --git a/src/glibext/options/hex.c b/src/glibext/options/hex.c
new file mode 100644
index 0000000..5804a57
--- /dev/null
+++ b/src/glibext/options/hex.c
@@ -0,0 +1,169 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.c - options de rendus de code héxadécimal
+ *
+ * Copyright (C) 2024 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "hex.h"
+
+
+#include <assert.h>
+
+
+#include <i18n.h>
+
+
+#include "hex-int.h"
+
+
+
+/* Initialise la classe des options pour le rendu d'hexadécimal. */
+static void g_hex_options_class_init(GHexOptionsClass *);
+
+/* Initialise une instance d'options pour le rendu d'hexa. */
+static void g_hex_options_init(GHexOptions *);
+
+/* Supprime toutes les références externes. */
+static void g_hex_options_dispose(GHexOptions *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_hex_options_finalize(GHexOptions *);
+
+
+
+/* Indique le type défini pour une ligne de représentation. */
+G_DEFINE_TYPE(GHexOptions, g_hex_options, G_TYPE_DISPLAY_OPTIONS);
+
+
+/******************************************************************************
+* *
+* Paramètres : klass = classe à initialiser. *
+* *
+* Description : Initialise la classe des options pour le rendu d'hexadécimal.*
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hex_options_class_init(GHexOptionsClass *klass)
+{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_hex_options_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_hex_options_finalize;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : options = instance à initialiser. *
+* *
+* Description : Initialise une instance d'options pour le rendu d'hexa. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hex_options_init(GHexOptions *options)
+{
+#ifndef NDEBUG
+ bool status; /* Bilan d'un appel */
+#endif
+
+#ifndef NDEBUG
+ status = g_display_options_create(G_DISPLAY_OPTIONS(options),
+#else
+ g_display_options_create(G_DISPLAY_OPTIONS(options),
+#endif
+ (const char *[]) { _("Offset") },
+ (const bool []) { true },
+ 1);
+
+ assert(status);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : options = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hex_options_dispose(GHexOptions *options)
+{
+ G_OBJECT_CLASS(g_hex_options_parent_class)->dispose(G_OBJECT(options));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : options = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_hex_options_finalize(GHexOptions *options)
+{
+ G_OBJECT_CLASS(g_hex_options_parent_class)->finalize(G_OBJECT(options));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Crée un groupe d'options pour le rendu d'hexadécimal. *
+* *
+* Retour : Adresse de la structure mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GHexOptions *g_hex_options_new(void)
+{
+ GHexOptions *result; /* Structure à retourner */
+
+ result = g_object_new(G_TYPE_HEX_OPTIONS, NULL);
+
+ return result;
+
+}
diff --git a/src/glibext/options/hex.h b/src/glibext/options/hex.h
new file mode 100644
index 0000000..48ce942
--- /dev/null
+++ b/src/glibext/options/hex.h
@@ -0,0 +1,42 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * hex.h - prototypes pour les options de rendus de code héxadécimal
+ *
+ * Copyright (C) 2024 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 Chrysalide. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef _GLIBEXT_OPTIONS_HEX_H
+#define _GLIBEXT_OPTIONS_HEX_H
+
+
+#include "../helpers.h"
+
+
+
+#define G_TYPE_HEX_OPTIONS (g_hex_options_get_type())
+
+DECLARE_GTYPE(GHexOptions, g_hex_options, G, HEX_OPTIONS);
+
+
+/* Crée un groupe d'options pour le rendu d'hexadécimal. */
+GHexOptions *g_hex_options_new(void);
+
+
+
+#endif /* _GLIBEXT_OPTIONS_HEX_H */
diff --git a/src/gtkext/contentview-int.h b/src/gtkext/contentview-int.h
index ba1f17c..25c9ddb 100644
--- a/src/gtkext/contentview-int.h
+++ b/src/gtkext/contentview-int.h
@@ -94,6 +94,7 @@ struct _GtkContentView
{
GtkWidget parent; /* A laisser en premier */
+ GDisplayOptions *options; /* Options de rendu */
GTokenStyle *style; /* Centralisation des styles */
#if 0
diff --git a/src/gtkext/contentview.c b/src/gtkext/contentview.c
index e79d13c..4b7f79d 100644
--- a/src/gtkext/contentview.c
+++ b/src/gtkext/contentview.c
@@ -214,6 +214,7 @@ static void gtk_content_view_class_init(GtkContentViewClass *class)
static void gtk_content_view_init(GtkContentView *view)
{
+ view->options = NULL;
view->style = g_token_style_new(GTK_WIDGET(view));
@@ -271,6 +272,7 @@ static void gtk_display_panel_loaded_interface_init(GLoadedPanelInterface *iface
static void gtk_content_view_dispose(GtkContentView *view)
{
+ g_clear_object(&view->options);
g_clear_object(&view->style);
diff --git a/src/gtkext/contentview.h b/src/gtkext/contentview.h
index e0660ff..3c0dacd 100644
--- a/src/gtkext/contentview.h
+++ b/src/gtkext/contentview.h
@@ -29,6 +29,7 @@
#include "../glibext/helpers.h"
+#include "../glibext/options.h"