summaryrefslogtreecommitdiff
path: root/src/editor.c
blob: 63b467be3e65737b9070dfa1b05fc5fd287b4713 (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
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
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 "analysis/project.h"
#include "core/params.h"
#include "gtkext/easygtk.h"
#include "gtkext/gtkdockstation.h"
#include "gtkext/support.h"
#include "gui/status.h"
#include "gui/menus/menubar.h"
#include "gui/panels/panel.h"
#include "gui/tb/portions.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          */
    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;

}