/* OpenIDA - Outil d'analyse de fichiers binaires * editor.c - fenêtre principale de l'interface graphique * * Copyright (C) 2008-2012 Cyrille Bagard * * This file is part of OpenIDA. * * 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 #include "project.h" #include "gtkext/easygtk.h" #include "gtkext/gtkdockstation.h" #include "gtkext/gtkextstatusbar.h" #include "gtkext/support.h" #include "gui/menus/menubar.h" #include "gui/panels/panel.h" #include "gui/tb/source.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 */ 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; GtkWidget *statusbar; GtkAccelGroup *accgroup; result = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_widget_set_size_request(result, 800, 600); 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")); 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_vbox_new(FALSE, 0); 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); statusbar = gtk_extended_status_bar_new(); g_object_set_data(ref, "statusbar", statusbar); gtk_widget_show(statusbar); gtk_box_pack_start(GTK_BOX(vbox1), statusbar, 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 (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), GTK_STOCK_YES, GTK_RESPONSE_YES); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_NO, GTK_RESPONSE_NO); gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_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); } 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) { g_object_unref(G_OBJECT(get_current_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); return result; }