summaryrefslogtreecommitdiff
path: root/src/gui/editor.c
diff options
context:
space:
mode:
authorCyrille Bagard <nocbos@gmail.com>2015-12-04 19:05:58 (GMT)
committerCyrille Bagard <nocbos@gmail.com>2015-12-04 19:05:58 (GMT)
commitc476dae9b50d6ff218e903e3f8d40ad51003fa40 (patch)
tree5f3f53037c88c1f5762fef54dc21ac4be7b324ce /src/gui/editor.c
parent3b4cdd10d6adf9155054989f41bb32759a9541c5 (diff)
Moved all files related to the GUI into the 'gui' directory.
Diffstat (limited to 'src/gui/editor.c')
-rw-r--r--src/gui/editor.c446
1 files changed, 446 insertions, 0 deletions
diff --git a/src/gui/editor.c b/src/gui/editor.c
new file mode 100644
index 0000000..1742596
--- /dev/null
+++ b/src/gui/editor.c
@@ -0,0 +1,446 @@
+
+/* Chrysalide - Outil d'analyse de fichiers binaires
+ * editor.c - fenêtre principale de l'interface graphique
+ *
+ * Copyright (C) 2008-2013 Cyrille Bagard
+ *
+ * This file is part of Chrysalide.
+ *
+ * OpenIDA 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.
+ *
+ * OpenIDA 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+
+#include "editor.h"
+
+
+#include <i18n.h>
+
+
+#include "status.h"
+#include "menus/menubar.h"
+#include "panels/panel.h"
+#include "tb/portions.h"
+#include "tb/source.h"
+#include "../analysis/project.h"
+#include "../core/params.h"
+#include "../gtkext/easygtk.h"
+#include "../gtkext/gtkdockstation.h"
+#include "../gtkext/support.h"
+
+
+
+
+
+/* Met en place la liste des icônes de l'éditeur. */
+static GList *build_editor_icons_list(void);
+
+
+/* Construit la fenêtre de l'éditeur. */
+GtkWidget *create_editor(void);
+
+/* Quitte le programme en sortie de la boucle de GTK. */
+static gboolean on_delete_editor(GtkWidget *, GdkEvent *, gpointer);
+
+/* Quitte le programme en sortie de la boucle de GTK. */
+static void on_destroy_editor(GtkWidget *, gpointer);
+
+
+
+
+
+
+/* Réagit au changement d'onglet d'un panneau quelconque. */
+static void on_dock_item_switch(GtkDockStation *, GtkWidget *, GObject *);
+
+
+
+
+
+
+/* ------------------------ INTEGRATION DE LA BARRE D'OUTILS ------------------------ */
+
+
+/* Construit la barre d'outils de l'éditeur. */
+static GtkWidget *build_editor_toolbar(GObject *);
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Met en place la liste des icônes de l'éditeur. *
+* *
+* Retour : Liste d'images dimensionnées. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GList *build_editor_icons_list(void)
+{
+ GList *result; /* Liste à retourner */
+ GdkPixbuf *pixbuf; /* Image chargée en mémoire */
+
+ result = NULL;
+
+ pixbuf = get_pixbuf_from_file("chrysalide-32.png");
+ if (pixbuf != NULL)
+ result = g_list_append(result, pixbuf);
+
+ pixbuf = get_pixbuf_from_file("chrysalide-64.png");
+ if (pixbuf != NULL)
+ result = g_list_append(result, pixbuf);
+
+ pixbuf = get_pixbuf_from_file("chrysalide-128.png");
+ if (pixbuf != NULL)
+ result = g_list_append(result, pixbuf);
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : - *
+* *
+* Description : Construit la fenêtre de l'éditeur. *
+* *
+* Retour : Adresse de la fenêtre mise en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+GtkWidget *create_editor(void)
+{
+ GtkWidget *result; /* Fenêtre à renvoyer */
+ bool hide; /* Cachette de la barre ? */
+ bool maximized; /* Affichage en plein écran ? */
+ GList *icons; /* Liste d'images dimensionnées*/
+ GObject *ref; /* Version de référence */
+ GEditorItem *editem; /* Menus réactifs principaux */
+ GtkWidget *menuboard; /* Barre de menus principale */
+
+ GtkWidget *toolbar; /* Barre d'outils */
+
+ GtkWidget *vbox1;
+
+
+ GtkAccelGroup *accgroup;
+
+
+ GtkWidget *widget; /* Composant à intégrer */
+
+
+
+
+ result = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_widget_set_size_request(result, 1024, 800);
+ gtk_window_set_position(GTK_WINDOW(result), GTK_WIN_POS_CENTER);
+ gtk_container_set_border_width(GTK_CONTAINER(result), 4);
+ gtk_window_set_title(GTK_WINDOW(result), _("Chrysalide"));
+
+ g_generic_config_get_value(get_main_configuration(), MPK_TITLE_BAR, &hide);
+ gtk_window_set_hide_titlebar_when_maximized(GTK_WINDOW(result), hide);
+
+ g_generic_config_get_value(get_main_configuration(), MPK_MAXIMIZED, &maximized);
+ gtk_window_maximize(GTK_WINDOW(result));
+
+ icons = build_editor_icons_list();
+ gtk_window_set_icon_list(GTK_WINDOW(result), icons);
+ g_list_free_full(icons, (GDestroyNotify)g_object_unref);
+
+ g_signal_connect(G_OBJECT(result), "delete-event", G_CALLBACK(on_delete_editor), NULL);
+ g_signal_connect(G_OBJECT(result), "destroy", G_CALLBACK(on_destroy_editor), NULL);
+
+ ref = G_OBJECT(result);
+
+ accgroup = gtk_accel_group_new();
+ gtk_window_add_accel_group(GTK_WINDOW(result), accgroup);
+
+
+
+ vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
+ gtk_widget_show(vbox1);
+ gtk_container_add(GTK_CONTAINER(result), vbox1);
+
+
+ /* Intégration des menus */
+
+ editem = g_menu_bar_new(ref, accgroup);
+ register_editor_item(editem);
+
+ menuboard = g_editor_item_get_widget(editem);
+ gtk_box_pack_start(GTK_BOX(vbox1), menuboard, FALSE, FALSE, 0);
+
+
+
+
+
+
+
+ /* Barre d'outils */
+
+ toolbar = build_editor_toolbar(G_OBJECT(result));
+ gtk_box_pack_start(GTK_BOX(vbox1), toolbar, FALSE, FALSE, 0);
+
+ do
+ {
+ GtkWidget *support;
+
+ support = init_panels2(G_CALLBACK(on_dock_item_switch), ref);
+ gtk_box_pack_start(GTK_BOX(vbox1), support, TRUE, TRUE, 0);
+
+ load_main_panels(ref);
+
+
+ } while(0);
+
+
+
+
+ /* Barre de statut générale */
+
+ editem = g_status_info_new(ref);
+ register_editor_item(editem);
+
+ widget = g_editor_item_get_widget(editem);
+ gtk_box_pack_start(GTK_BOX(vbox1), widget, FALSE, FALSE, 0);
+
+
+
+
+
+
+
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : widget = fenêtre de l'éditeur de préférences. *
+* event = informations liées à l'événement. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Quitte le programme en sortie de la boucle de GTK. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static gboolean on_delete_editor(GtkWidget *widget, GdkEvent *event, gpointer data)
+{
+ gboolean result; /* Continuation à retourner */
+ GStudyProject *project; /* Projet courant */
+ GtkWidget *dialog; /* Boîte à afficher */
+
+ result = FALSE;
+
+ project = get_current_project();
+ if (project == NULL) goto ode_no_project;
+
+ if (g_study_project_get_filename(project) == NULL)
+ {
+ dialog = gtk_message_dialog_new(GTK_WINDOW(widget),
+ GTK_DIALOG_DESTROY_WITH_PARENT,
+ GTK_MESSAGE_QUESTION,
+ GTK_BUTTONS_NONE,
+ _("The current project will be lost. Do you you want to save it ?"));
+
+ gtk_dialog_add_button(GTK_DIALOG(dialog), _("_Yes"), GTK_RESPONSE_YES);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), _("_No"), GTK_RESPONSE_NO);
+ gtk_dialog_add_button(GTK_DIALOG(dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
+
+ switch (gtk_dialog_run(GTK_DIALOG(dialog)))
+ {
+ case GTK_RESPONSE_YES:
+ //mcb_file_save_project_as(NULL, widget); /* FIXME */
+ break;
+
+ case GTK_RESPONSE_NO:
+ break;
+
+ case GTK_RESPONSE_CANCEL:
+ result = TRUE;
+ break;
+
+ }
+
+ gtk_widget_destroy(dialog);
+
+ }
+
+ ode_no_project:
+
+ return result;
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : widget = fenêtre de l'éditeur de préférences. *
+* event = informations liées à l'événement. *
+* data = adresse non utilisée ici. *
+* *
+* Description : Quitte le programme en sortie de la boucle de GTK. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void on_destroy_editor(GtkWidget *widget, gpointer data)
+{
+ GStudyProject *project; /* Projet courant */
+
+ project = get_current_project();
+ if (project != NULL) g_object_unref(G_OBJECT(project));
+
+ /* Fermeture propre */
+
+ /* ... */
+
+ gtk_main_quit();
+
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/******************************************************************************
+* *
+* Paramètres : station = panneau de support des éléments concerné. *
+* item = nouvel élément présenté à l'affichage. *
+* ref = adresse de l'espace de référencement global. *
+* *
+* Description : Réagit au changement d'onglet d'un panneau quelconque. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void on_dock_item_switch(GtkDockStation *station, GtkWidget *widget, GObject *ref)
+{
+ GLoadedBinary *old_binary; /* Ancien binaire édité */
+ GLoadedBinary *binary; /* Binaire en cours d'édition */
+
+ if (GTK_IS_SCROLLED_WINDOW(widget))
+ widget = gtk_bin_get_child(GTK_BIN(widget));
+
+ if (GTK_IS_VIEWPORT(widget))
+ widget = gtk_bin_get_child(GTK_BIN(widget));
+
+ if (GTK_IS_VIEW_PANEL(widget))
+ {
+ /* Changement de binaire ? */
+
+ old_binary = G_LOADED_BINARY(g_object_get_data(ref, "current_binary"));
+ binary = gtk_view_panel_get_binary(GTK_VIEW_PANEL(widget));
+
+ if (old_binary != binary)
+ {
+ //notify_panels_of_binary_change(binary);
+ change_editor_items_current_binary(ref, binary);
+ }
+
+ change_editor_items_current_view(ref, GTK_VIEW_PANEL(widget));
+
+ //notify_panels_of_view_change(GTK_VIEW_PANEL(widget), false);
+
+ }
+
+}
+
+
+
+
+
+
+
+
+
+
+/* ---------------------------------------------------------------------------------- */
+/* INTEGRATION DE LA BARRE D'OUTILS */
+/* ---------------------------------------------------------------------------------- */
+
+
+/******************************************************************************
+* *
+* Paramètres : ref = espace de référencement global. *
+* *
+* Description : Construit la barre d'outils de l'éditeur. *
+* *
+* Retour : Adresse du composant mis en place. *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static GtkWidget *build_editor_toolbar(GObject *ref)
+{
+ GtkWidget *result; /* Support à retourner */
+ GEditorItem *item; /* Elément de barre d'outils */
+
+ result = gtk_toolbar_new();
+ gtk_widget_show(result);
+ g_object_set_data(ref, "toolbar", result);
+
+
+ item = create_source_tb_item(ref);
+ register_editor_item(item);
+
+ item = create_portions_tb_item(ref);
+ register_editor_item(item);
+
+
+ return result;
+
+}