summaryrefslogtreecommitdiff
path: root/src/gui/menus/view.c
blob: c6299a69b86bed00dcb650d838185e7a4b39cea6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279

/* Chrysalide - Outil d'analyse de fichiers binaires
 * view.c - gestion du menu 'Affichage'
 *
 * Copyright (C) 2012 Cyrille Bagard
 *
 *  This view 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 "view.h"


#include <i18n.h>


#include "../editem-int.h"
#include "../../analysis/project.h"
#include "../../gtkext/easygtk.h"
#include "../../gtkext/gtkdockstation.h"



/* Réagit avec le menu "Affichage -> Vue xxx". */
static void mcb_view_change_support(GtkRadioMenuItem *, GMenuBar *);

/* Réagit avec le menu "Affichage -> (colonne xxx)". */
static void mcb_view_display_column(GtkCheckMenuItem *, GMenuBar *);



/******************************************************************************
*                                                                             *
*  Paramètres  : ref      = espace de référencement global.                   *
*                accgroup = groupe d'accélérateurs pour les menus.            *
*                bar      = barre de menu parente.                            *
*                                                                             *
*  Description : Construit le menu "Affichage".                               *
*                                                                             *
*  Retour      : Panneau de menus mis en place.                               *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GtkWidget *build_menu_view(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *bar)
{
    GtkWidget *result;                      /* Support à retourner         */
    GtkWidget *menubar;                     /* Support pour éléments       */
    GtkWidget *submenuitem;                 /* Sous-élément de menu        */
    GSList *rgroup;                         /* Groupe des boutons radio    */

    result = gtk_menu_item_new_with_mnemonic(_("_View"));
    gtk_widget_show(result);

    menubar = gtk_menu_new();
    gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar);

    submenuitem = qck_create_radio_menu_item(ref, "textview", NULL, _("Text view"),
                                             G_CALLBACK(mcb_view_change_support), bar);
    add_accelerator_to_menu_item(submenuitem, "F2", accgroup);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_view", GUINT_TO_POINTER(BVW_BLOCK));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    rgroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(submenuitem));

    submenuitem = qck_create_radio_menu_item(ref, "graphview", rgroup, _("Graph view"),
                                             G_CALLBACK(mcb_view_change_support), bar);
    add_accelerator_to_menu_item(submenuitem, "F3", accgroup);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_view", GUINT_TO_POINTER(BVW_GRAPH));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    rgroup = gtk_radio_menu_item_get_group(GTK_RADIO_MENU_ITEM(submenuitem));

    submenuitem = qck_create_radio_menu_item(ref, "sourceview", rgroup, _("Source code"),
                                             G_CALLBACK(mcb_view_change_support), bar);
    add_accelerator_to_menu_item(submenuitem, "F4", accgroup);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_view", GUINT_TO_POINTER(BVW_SOURCE));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    submenuitem = qck_create_menu_separator();
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    submenuitem = qck_create_check_menu_item(G_OBJECT(result), "off", _("Physical offset"),
                                             G_CALLBACK(mcb_view_display_column), bar);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_col", GUINT_TO_POINTER(BLC_PHYSICAL));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    submenuitem = qck_create_check_menu_item(G_OBJECT(result), "addr", _("Virtual address"),
                                             G_CALLBACK(mcb_view_display_column), bar);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_col", GUINT_TO_POINTER(BLC_VIRTUAL));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    submenuitem = qck_create_check_menu_item(G_OBJECT(result), "code", _("Binary code"),
                                             G_CALLBACK(mcb_view_display_column), bar);
    g_object_set_data(G_OBJECT(submenuitem), "kind_of_col", GUINT_TO_POINTER(BLC_BINARY));
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    submenuitem = qck_create_menu_separator();
    gtk_container_add(GTK_CONTAINER(menubar), submenuitem);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : widget = menu principal à actualiser.                        *
*                view   = nouveau panneau d'affichage actif.                  *
*                bar    = barre de menu parente.                              *
*                                                                             *
*  Description : Lance une actualisation du fait d'un changement de vue.      *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void update_menu_view_for_view(GtkWidget *widget, GtkViewPanel *view, GMenuBar *bar)
{
    GLoadedBinary *binary;                  /* Binaire courant             */
    BinaryView content;                     /* Type de vue active          */
    const bool *display;                    /* Règles d'affichage courantes*/
    GtkWidget *submenuitem;                 /* Sous-élément de menu        */
    bool status;                            /* Consigne d'affichage        */

    binary = g_editor_item_get_current_binary(G_EDITOR_ITEM(bar));

    content = gtk_view_panel_describe_content(view);

    display = g_loaded_binary_get_column_display(binary, content);

    /* Positions physiques */

    submenuitem = g_object_get_data(G_OBJECT(widget), "off");

    g_signal_handlers_disconnect_by_func(submenuitem, G_CALLBACK(mcb_view_display_column), bar);

    status = display[BLC_PHYSICAL];
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(submenuitem), status);

    g_signal_connect(submenuitem, "toggled", G_CALLBACK(mcb_view_display_column), bar);

    /* Adresses virtuelles */

    submenuitem = g_object_get_data(G_OBJECT(widget), "addr");

    g_signal_handlers_disconnect_by_func(submenuitem, G_CALLBACK(mcb_view_display_column), bar);

    status = display[BLC_VIRTUAL];
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(submenuitem), status);

    g_signal_connect(submenuitem, "toggled", G_CALLBACK(mcb_view_display_column), bar);

    /* Code binaire */

    submenuitem = g_object_get_data(G_OBJECT(widget), "code");

    g_signal_handlers_disconnect_by_func(submenuitem, G_CALLBACK(mcb_view_display_column), bar);

    status = display[BLC_BINARY];
    gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(submenuitem), status);

    g_signal_connect(submenuitem, "toggled", G_CALLBACK(mcb_view_display_column), bar);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : menuitem = élément de menu ayant basculé.                    *
*                bar      = barre de menu parente.                            *
*                                                                             *
*  Description : Réagit avec le menu "Affichage -> Vue xxx".                  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void mcb_view_change_support(GtkRadioMenuItem *menuitem, GMenuBar *bar)
{
    GSList *group;                          /* Liste de menus radio        */
    GSList *iter;                           /* Boucle de parcours          */
    BinaryView view;                        /* Nouvelle vue à présenter    */
    GtkViewPanel *vpanel;                   /* Afficheur effectif de code  */
    GtkWidget *station;                     /* Base du remplacement        */
    GLoadedBinary *binary;                  /* Edition courante            */
    GtkWidget *scroll;                      /* Nouveau support à utiliser  */

    /* On ne traite qu'une seule fois ! */
    if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menuitem))) return;

    group = gtk_radio_menu_item_get_group(menuitem);

    for (iter = group; iter != NULL; iter = g_slist_next(iter))
    {
        if (!gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(iter->data))) continue;

        view = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(iter->data), "kind_of_view"));

        /**
         * La hiérarchie des composants empilés est la suivante :
         *
         *  - GtkBlockView / GtkGraphView / GtkSourceView (avec GtkViewport intégré)
         *  - GtkScrolledWindow
         *  - GtkNotebook
         *  - GtkDockStation
         *
         */

        vpanel = g_editor_item_get_current_view(G_EDITOR_ITEM(bar));
        station = gtk_widget_get_parent(GTK_WIDGET(vpanel));   /* ScrollWindow */
        station = gtk_widget_get_parent(station);   /* NoteBook */
        station = gtk_widget_get_parent(station);   /* DockStation */

        binary = g_editor_item_get_current_binary(G_EDITOR_ITEM(bar));
        scroll = g_study_project_get_view_for_binary(get_current_project(),
                                                     binary, view, &vpanel);

        gtk_dock_panel_change_active_widget(GTK_DOCK_STATION(station), scroll);

        change_editor_items_current_view(G_EDITOR_ITEM(bar)->ref, vpanel);

    }

}


/******************************************************************************
*                                                                             *
*  Paramètres  : menuitem = élément de menu ayant basculé.                    *
*                bar      = barre de menu parente.                            *
*                                                                             *
*  Description : Réagit avec le menu "Affichage -> (colonne xxx)".            *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void mcb_view_display_column(GtkCheckMenuItem *menuitem, GMenuBar *bar)
{
    BufferLineColumn col;                   /* Colonne à traiter           */
    GLoadedBinary *binary;                  /* Binaire courant             */
    GtkViewPanel *panel;                    /* Affichage courant           */
    BinaryView view;                        /* Type de vue représentée     */
    gboolean active;                        /* Etat de sélection du menu   */

    col = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(menuitem), "kind_of_col"));

    binary = g_editor_item_get_current_binary(G_EDITOR_ITEM(bar));

    panel = g_editor_item_get_current_view(G_EDITOR_ITEM(bar));
    view = gtk_view_panel_describe_content(panel);

    active = gtk_check_menu_item_get_active(menuitem);

    g_loaded_binary_set_column_display(binary, view, col, active);

}