diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-12-26 23:52:44 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-12-26 23:52:44 (GMT) |
commit | 2c28d59fb3671c0fdd1987784076d4968c58b651 (patch) | |
tree | a301f6cd9c1fd9f92191fba7fe7b59a7e3a01b5a /src/analysis/loaded.c | |
parent | 67b4887317b7394d63b543aa48cb368406374103 (diff) |
Created the GLoadedContent interface to load all kinds of content.
Diffstat (limited to 'src/analysis/loaded.c')
-rw-r--r-- | src/analysis/loaded.c | 362 |
1 files changed, 362 insertions, 0 deletions
diff --git a/src/analysis/loaded.c b/src/analysis/loaded.c new file mode 100644 index 0000000..5ce16c1 --- /dev/null +++ b/src/analysis/loaded.c @@ -0,0 +1,362 @@ + +/* Chrysalide - Outil d'analyse de fichiers binaires + * loaded.c - intégration des contenus chargés + * + * Copyright (C) 2017 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 "loaded.h" + + +#include <assert.h> + + +#include "loaded-int.h" +#include "../glibext/chrysamarshal.h" +#include "../glibext/gloadedpanel.h" + + + +/* ---------------------- GESTION SOUS FORME DE CONTENU CHARGE ---------------------- */ + + +/* Procède à l'initialisation de l'interface de contenu chargé. */ +static void g_loaded_content_default_init(GLoadedContentInterface *); + + + +/* ---------------------------------------------------------------------------------- */ +/* GESTION SOUS FORME DE CONTENU CHARGE */ +/* ---------------------------------------------------------------------------------- */ + + +/* Détermine le type d'une interface pour l'intégration de contenu chargé. */ +G_DEFINE_INTERFACE(GLoadedContent, g_loaded_content, G_TYPE_OBJECT) + + +/****************************************************************************** +* * +* Paramètres : iface = interface GLib à initialiser. * +* * +* Description : Procède à l'initialisation de l'interface de contenu chargé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void g_loaded_content_default_init(GLoadedContentInterface *iface) +{ + g_signal_new("display-changed", + G_TYPE_LOADED_CONTENT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GLoadedContentIface, display_changed), + NULL, NULL, + g_cclosure_user_marshal_VOID__ENUM_ENUM, + G_TYPE_NONE, 2, G_TYPE_UINT, G_TYPE_UINT); + +} + + +/****************************************************************************** +* * +* Paramètres : content = élément chargé à consulter. * +* long = précise s'il s'agit d'une version longue ou non. * +* * +* Description : Fournit le désignation associée à l'élément chargé. * +* * +* Retour : Description courante. * +* * +* Remarques : - * +* * +******************************************************************************/ + +const char *g_loaded_content_describe(const GLoadedContent *content, bool full) +{ + GLoadedContentIface *iface; /* Interface utilisée */ + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + return iface->describe(content, full); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu chargé à consulter. * +* * +* Description : Détermine le nombre de vues disponibles pour un contenu. * +* * +* Retour : Quantité strictement positive. * +* * +* Remarques : - * +* * +******************************************************************************/ + +unsigned int g_loaded_content_count_views(const GLoadedContent *content) +{ + GLoadedContentIface *iface; /* Interface utilisée */ + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + return iface->count_views(content); + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu chargé à consulter. * +* index = indice de la vue ciblée. * +* * +* Description : Met en place la vue demandée pour un contenu chargé. * +* * +* Retour : Composant graphique nouveau. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *g_loaded_content_build_view(GLoadedContent *content, unsigned int index) +{ + GtkWidget *result; /* Support à retourner */ + GLoadedContentIface *iface; /* Interface utilisée */ + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + assert(index <= g_loaded_content_count_views(content)); + + result = iface->build_view(content, index); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu chargé à consulter. * +* index = composant graphique en place. * +* * +* Description : Retrouve l'indice correspondant à la vue donnée d'un contenu.* +* * +* Retour : Indice de la vue représentée, ou -1 en cas d'erreur. * +* * +* Remarques : - * +* * +******************************************************************************/ + +unsigned int g_loaded_content_get_view_index(GLoadedContent *content, GtkWidget *view) +{ + unsigned int result; /* Indice à retourner */ + GLoadedContentIface *iface; /* Interface utilisée */ + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + result = iface->get_view_index(content, view); + + assert(result == -1 || result <= g_loaded_content_count_views(content)); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu chargé à consulter. * +* index = composant graphique à cibler. * +* * +* Description : Fournit toutes les options d'affichage pour un contenu. * +* * +* Retour : Tableau de paramètres en accès libre. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool * const g_loaded_content_get_all_display_options(const GLoadedContent *content, unsigned int index) +{ + bool const *result; /* Accès aux options à renvoyer*/ + GLoadedContentIface *iface; /* Interface utilisée */ + + assert(index <= g_loaded_content_count_views(content)); + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + result = iface->get_all_options(content, index); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : content = contenu chargé à consulter. * +* index = composant graphique à cibler. * +* option = type de paramètre à manipuler. * +* state = valeur dudit paramètre. * +* * +* Description : Définit une option d'affichage pour un contenu chargé. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +void g_loaded_content_set_display_option(GLoadedContent *content, unsigned int index, unsigned int option, bool state) +{ + GLoadedContentIface *iface; /* Interface utilisée */ + bool changed; /* Note un changement */ + + assert(index <= g_loaded_content_count_views(content)); + + iface = G_LOADED_CONTENT_GET_IFACE(content); + + changed = iface->set_option(content, index, option, state); + + if (changed) + g_signal_emit_by_name(content, "display-changed", index, option); + +} + + + +/* ---------------------------------------------------------------------------------- */ +/* VUES ET BASCULEMENT ENTRE LES VUES */ +/* ---------------------------------------------------------------------------------- */ + + +/****************************************************************************** +* * +* Paramètres : panel = panneau affichant un contenu binaire. * +* * +* Description : Fournit la station d'accueil d'un panneau d'affichage. * +* * +* Retour : Composant GTK fourni sans transfert de propriété. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkDockStation *get_dock_station_for_view_panel(GtkWidget *panel) +{ + GtkWidget *result; /* Support trouvé à retourner */ + + /** + * La hiérarchie des composants empilés est la suivante : + * + * - GtkBlockView / GtkGraphView / GtkSourceView (avec GtkViewport intégré) + * - GtkScrolledWindow + * - GtkDockStation + * + */ + + result = gtk_widget_get_parent(panel); /* ScrolledWindow */ + result = gtk_widget_get_parent(result); /* DockStation */ + + return GTK_DOCK_STATION(result); + +} + + +/****************************************************************************** +* * +* Paramètres : panel = panneau affichant un contenu binaire. * +* * +* Description : Fournit le support défilant d'un panneau d'affichage. * +* * +* Retour : Composant GTK fourni sans transfert de propriété. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *get_scroll_window_for_view_panel(GtkWidget *panel) +{ + GtkWidget *result; /* Support trouvé à retourner */ + + /** + * La hiérarchie des composants empilés est la suivante : + * + * - GtkBlockView / GtkGraphView / GtkSourceView (avec GtkViewport intégré) + * - GtkScrolledWindow + * - GtkDockStation + * + */ + + result = gtk_widget_get_parent(panel); /* ScrolledWindow */ + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : view = composant retourné par un contenu chargé. * +* * +* Description : Fournit le panneau chargé inclus dans un affichage. * +* * +* Retour : Composant GTK fourni sans transfert de propriété. * +* * +* Remarques : - * +* * +******************************************************************************/ + +GtkWidget *get_loaded_panel_from_built_view(GtkWidget *view) +{ + GtkWidget *result; /* Support trouvé à retourner */ + + if (G_IS_LOADED_PANEL(view)) + result = view; + + else + { + assert(GTK_IS_CONTAINER(view)); + + result = NULL; + + void track_loaded_panel(GtkWidget *widget, GtkWidget **found) + { + if (*found == NULL) + { + if (G_IS_LOADED_PANEL(widget)) + *found = widget; + + else if (GTK_IS_CONTAINER(widget)) + gtk_container_foreach(GTK_CONTAINER(widget), (GtkCallback)track_loaded_panel, found); + + } + + } + + gtk_container_foreach(GTK_CONTAINER(view), (GtkCallback)track_loaded_panel, &result); + + assert(result != NULL); + + } + + return result; + +} |