diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2017-01-27 22:51:43 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2017-01-27 22:51:43 (GMT) |
commit | 7640b28691817aea89fc5a5dd5e74fd0b40c516f (patch) | |
tree | 5b8dc6b6746575fb4bbfcefff36fc9af5f6a2c17 /src/gui | |
parent | 56b84c3624c59c8a1796bf411b7ba950d12ddfc5 (diff) |
Made the menu bar appear and disappear in the same way Firefox does.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/editor.c | 169 | ||||
-rw-r--r-- | src/gui/menus/binary.c | 3 | ||||
-rw-r--r-- | src/gui/menus/debug.c | 3 | ||||
-rw-r--r-- | src/gui/menus/edition.c | 12 | ||||
-rw-r--r-- | src/gui/menus/file.c | 5 | ||||
-rw-r--r-- | src/gui/menus/help.c | 3 | ||||
-rw-r--r-- | src/gui/menus/plugins.c | 3 | ||||
-rw-r--r-- | src/gui/menus/project.c | 9 | ||||
-rw-r--r-- | src/gui/menus/view.c | 6 | ||||
-rw-r--r-- | src/gui/panels/bookmarks.c | 2 | ||||
-rw-r--r-- | src/gui/panels/regedit.c | 2 | ||||
-rw-r--r-- | src/gui/panels/strings.c | 2 | ||||
-rw-r--r-- | src/gui/panels/welcome.c | 6 |
13 files changed, 182 insertions, 43 deletions
diff --git a/src/gui/editor.c b/src/gui/editor.c index 7084980..b856971 100644 --- a/src/gui/editor.c +++ b/src/gui/editor.c @@ -71,9 +71,16 @@ GtkWidget *create_editor(void); 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); +static void on_destroy_editor(GtkWidget *, GObject *); +/* Réagit à un changement de focus pour l'éditeur. */ +static gboolean on_focus_out(GtkWidget *, GdkEventFocus *, GObject *); +/* Permet la disparition de la barre de menus avec le clavier. */ +static void track_root_menubars(GtkContainer *, bool); + +/* Suit la frappe de touches sur la fenêtre principale. */ +static gboolean on_key_event(GtkWidget *, GdkEventKey *, GObject *); @@ -282,11 +289,17 @@ GtkWidget *create_editor(void) 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); + g_signal_connect(ref, "delete-event", G_CALLBACK(on_delete_editor), NULL); + g_signal_connect(ref, "destroy", G_CALLBACK(on_destroy_editor), ref); + + g_signal_connect(ref, "focus-out-event", G_CALLBACK(on_focus_out), ref); + g_signal_connect(ref, "key-press-event", G_CALLBACK(on_key_event), ref); + g_signal_connect(ref, "key-release-event", G_CALLBACK(on_key_event), ref); + + + _accgroup = gtk_accel_group_new(); gtk_window_add_accel_group(GTK_WINDOW(result), _accgroup); @@ -307,13 +320,14 @@ GtkWidget *create_editor(void) + g_object_set_data(ref, "menuboard", menuboard); - + gtk_widget_hide(menuboard); /* Barre d'outils */ - toolbar = build_editor_toolbar(G_OBJECT(result)); + toolbar = build_editor_toolbar(ref); gtk_box_pack_start(GTK_BOX(vbox1), toolbar, FALSE, FALSE, 0); do @@ -425,8 +439,7 @@ static gboolean on_delete_editor(GtkWidget *widget, GdkEvent *event, gpointer da /****************************************************************************** * * * 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. * +* ref = espace de référencement global. * * * * Description : Quitte le programme en sortie de la boucle de GTK. * * * @@ -436,7 +449,7 @@ static gboolean on_delete_editor(GtkWidget *widget, GdkEvent *event, gpointer da * * ******************************************************************************/ -static void on_destroy_editor(GtkWidget *widget, gpointer data) +static void on_destroy_editor(GtkWidget *widget, GObject *ref) { GStudyProject *project; /* Projet courant */ @@ -447,11 +460,147 @@ static void on_destroy_editor(GtkWidget *widget, gpointer data) /* ... */ + on_focus_out(widget, NULL, ref); + gtk_main_quit(); } +/****************************************************************************** +* * +* Paramètres : widget = fenêtre de l'éditeur de préférences. * +* event = informations liées à l'événement. * +* ref = espace de référencement global. * +* * +* Description : Réagit à un changement de focus pour l'éditeur. * +* * +* Retour : TRUE pour arrêter la propagation du signal, FALSE sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static gboolean on_focus_out(GtkWidget *widget, GdkEventFocus *event, GObject *ref) +{ + GtkWidget *menuboard; /* Planche de menu à traiter */ + + menuboard = GTK_WIDGET(g_object_get_data(ref, "menuboard")); + + if (gtk_widget_get_visible(menuboard)) + { + track_root_menubars(GTK_CONTAINER(menuboard), false); + gtk_widget_hide(menuboard); + } + + return FALSE; + +} + + +/****************************************************************************** +* * +* Paramètres : menubar = barre de menu principale à traiter. * +* set = indique si la surveillance est à activer ou non. * +* * +* Description : Permet la disparition de la barre de menus avec le clavier. * +* * +* Retour : - * +* * +* Remarques : - * +* * +******************************************************************************/ + +static void track_root_menubars(GtkContainer *menubar, bool set) +{ + gboolean track_espace_on_main_submenu(GtkWidget *menu, GdkEventKey *event, GtkWidget *item) + { + GtkWidget *mbar; /* Barre de menus principale */ + + if (event->keyval == GDK_KEY_Escape) + { + mbar = gtk_widget_get_parent(item); + track_root_menubars(GTK_CONTAINER(mbar), false); + gtk_widget_hide(mbar); + } + + return FALSE; + + } + + void browse_all_main_items(GtkWidget *item, bool *track) + { + GtkWidget *menu; /* Menu à traiter */ + + menu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(item)); + + if (*track) + g_signal_connect(menu, "key-press-event", G_CALLBACK(track_espace_on_main_submenu), item); + else + g_signal_handlers_disconnect_by_func(menu, G_CALLBACK(track_espace_on_main_submenu), item); + + } + + gtk_container_foreach(menubar, (GtkCallback)browse_all_main_items, &set); + +} + + +/****************************************************************************** +* * +* Paramètres : widget = fenêtre de l'éditeur de préférences. * +* event = informations liées à l'événement. * +* ref = espace de référencement global. * +* * +* Description : Suit la frappe de touches sur la fenêtre principale. * +* * +* Retour : FALSE pour poursuivre la propagation de l'événement. * +* * +* Remarques : - * +* * +******************************************************************************/ + +static gboolean on_key_event(GtkWidget *widget, GdkEventKey *event, GObject *ref) +{ + GtkWidget *menuboard; /* Planche de menu à traiter */ + + static bool skip_event = false; + + menuboard = GTK_WIDGET(g_object_get_data(ref, "menuboard")); + + if (gtk_widget_get_visible(menuboard)) + { + if (event->type == GDK_KEY_PRESS && event->keyval == GDK_KEY_Alt_L) + { + skip_event = true; + track_root_menubars(GTK_CONTAINER(menuboard), false); + gtk_widget_hide(menuboard); + } + } + else + { + if (event->type == GDK_KEY_PRESS && event->state == GDK_MOD1_MASK) + { + track_root_menubars(GTK_CONTAINER(menuboard), true); + gtk_widget_show(menuboard); + } + + else if (event->type == GDK_KEY_RELEASE && event->keyval == GDK_KEY_Alt_L) + { + if (skip_event) + skip_event = false; + else + { + track_root_menubars(GTK_CONTAINER(menuboard), true); + gtk_widget_show(menuboard); + } + } + } + + return FALSE; + +} + /* ---------------------------------------------------------------------------------- */ /* INTEGRATION DE LA BARRE D'OUTILS */ @@ -1242,7 +1391,7 @@ static void on_dock_menu_request(GtkDockStation *station, GtkWidget *button, GOb GList *children; /* Composants mis en place */ GtkWidget *nopanel; /* Sous-élément de menu */ - menu = GTK_CONTAINER(gtk_menu_new()); + menu = GTK_CONTAINER(qck_create_menu(NULL)); active = gtk_notebook_get_nth_page(GTK_NOTEBOOK(station), 0); diff --git a/src/gui/menus/binary.c b/src/gui/menus/binary.c index af6e8c4..0eb28fe 100644 --- a/src/gui/menus/binary.c +++ b/src/gui/menus/binary.c @@ -73,8 +73,7 @@ GtkWidget *build_menu_binary(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *ba result = gtk_menu_item_new_with_mnemonic(_("_Binary")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(ref, "mnu_binary_epoints", _("Entry points"), G_CALLBACK(mcb_binary_entry_points), bar); diff --git a/src/gui/menus/debug.c b/src/gui/menus/debug.c index 79b5ff8..cb270ff 100644 --- a/src/gui/menus/debug.c +++ b/src/gui/menus/debug.c @@ -93,8 +93,7 @@ GtkWidget *build_menu_debug(GObject *ref, GtkAccelGroup *accgroup) result = gtk_menu_item_new_with_mnemonic(_("_Debug")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(ref, "mnu_debug_continue", _("Continue"), G_CALLBACK(mcb_debug_continue), ref); diff --git a/src/gui/menus/edition.c b/src/gui/menus/edition.c index 31fbc0d..f41111d 100644 --- a/src/gui/menus/edition.c +++ b/src/gui/menus/edition.c @@ -100,8 +100,7 @@ GtkWidget *build_menu_edition(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b result = gtk_menu_item_new_with_mnemonic(_("_Edition")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(NULL, NULL, _("Go to address..."), G_CALLBACK(mcb_edition_goto), bar); @@ -114,8 +113,7 @@ GtkWidget *build_menu_edition(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b submenuitem = qck_create_menu_item(NULL, NULL, _("Numeric operand"), NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); deepmenuitem = qck_create_menu_item(ref, "mnu_edit_switch_hex", _("Hexadecimal"), G_CALLBACK(mcb_edition_switch_numeric_operand), bar); @@ -181,8 +179,7 @@ GtkWidget *build_menu_edition(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b submenuitem = qck_create_menu_item(NULL, NULL, _("Bookmarks"), NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); deepmenuitem = qck_create_menu_item(NULL, NULL, _("Toggle at current location"), G_CALLBACK(mcb_edition_bookmarks_toggle), bar); @@ -198,8 +195,7 @@ GtkWidget *build_menu_edition(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b submenuitem = qck_create_menu_item(NULL, NULL, _("Comments"), NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); deepmenuitem = qck_create_menu_item(NULL, NULL, _("Enter a comment..."), G_CALLBACK(mcb_edition_comment_enter), bar); diff --git a/src/gui/menus/file.c b/src/gui/menus/file.c index cb69957..c3865b6 100644 --- a/src/gui/menus/file.c +++ b/src/gui/menus/file.c @@ -74,8 +74,7 @@ GtkWidget *build_menu_file(GObject *ref, GtkAccelGroup *accgroup) result = gtk_menu_item_new_with_mnemonic(_("_File")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(NULL, NULL, _("New project"), G_CALLBACK(mcb_file_new_project), ref); @@ -299,6 +298,6 @@ static void mcb_file_save_project_as(GtkMenuItem *menuitem, gpointer data) static void mcb_file_quit(GtkMenuItem *menuitem, GObject *ref) { - gtk_main_quit(); + gtk_widget_destroy(GTK_WIDGET(ref)); } diff --git a/src/gui/menus/help.c b/src/gui/menus/help.c index 9293540..922fa31 100644 --- a/src/gui/menus/help.c +++ b/src/gui/menus/help.c @@ -60,8 +60,7 @@ GtkWidget *build_menu_help(GObject *ref, GtkAccelGroup *accgroup) result = gtk_menu_item_new_with_mnemonic(_("_Help")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(NULL, NULL, _("About"), G_CALLBACK(mcb_help_about), ref); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); diff --git a/src/gui/menus/plugins.c b/src/gui/menus/plugins.c index cba6b69..c1b0fc7 100644 --- a/src/gui/menus/plugins.c +++ b/src/gui/menus/plugins.c @@ -56,9 +56,8 @@ GtkWidget *build_menu_plugins(GObject *ref, GtkAccelGroup *accgroup) result = gtk_menu_item_new_with_mnemonic(_("_Plugins")); gtk_widget_show(result); - menubar = gtk_menu_new(); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); g_object_set_data(ref, "menubar_plugins", G_OBJECT(menubar)); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); return result; diff --git a/src/gui/menus/project.c b/src/gui/menus/project.c index 58ef244..18c7aaa 100644 --- a/src/gui/menus/project.c +++ b/src/gui/menus/project.c @@ -74,14 +74,12 @@ GtkWidget *build_menu_project(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b result = gtk_menu_item_new_with_mnemonic(_("_Project")); gtk_widget_show(result); - menubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(result), menubar); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); submenuitem = qck_create_menu_item(NULL, NULL, _("Add a binary..."), NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); deepmenuitem = qck_create_menu_item(NULL, NULL, _("Shellcode"), G_CALLBACK(mcb_project_add_shellcode), bar); @@ -95,8 +93,7 @@ GtkWidget *build_menu_project(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *b NULL, NULL); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); return result; diff --git a/src/gui/menus/view.c b/src/gui/menus/view.c index 9f29ba3..70cd42e 100644 --- a/src/gui/menus/view.c +++ b/src/gui/menus/view.c @@ -82,8 +82,7 @@ GtkWidget *build_menu_view(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *bar) 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); + menubar = qck_create_menu(GTK_MENU_ITEM(result)); /* Affichage -> Panneaux latéraux */ @@ -91,8 +90,7 @@ GtkWidget *build_menu_view(GObject *ref, GtkAccelGroup *accgroup, GMenuBar *bar) g_signal_connect(submenuitem, "select", G_CALLBACK(mcb_view_update_side_panels_list), bar); gtk_container_add(GTK_CONTAINER(menubar), submenuitem); - deepmenubar = gtk_menu_new(); - gtk_menu_item_set_submenu(GTK_MENU_ITEM(submenuitem), deepmenubar); + deepmenubar = qck_create_menu(GTK_MENU_ITEM(submenuitem)); /* - */ diff --git a/src/gui/panels/bookmarks.c b/src/gui/panels/bookmarks.c index b58fbc5..5eb018b 100644 --- a/src/gui/panels/bookmarks.c +++ b/src/gui/panels/bookmarks.c @@ -1098,7 +1098,7 @@ static GtkMenu *build_bookmarks_panel_menu(GBookmarksPanel *panel) GtkWidget *result; /* Support à retourner */ GtkWidget *submenuitem; /* Sous-élément de menu */ - result = gtk_menu_new(); + result = qck_create_menu(NULL); submenuitem = qck_create_menu_item(NULL, NULL, _("Edit"), G_CALLBACK(mcb_bookmarks_panel_edit), panel); gtk_container_add(GTK_CONTAINER(result), submenuitem); diff --git a/src/gui/panels/regedit.c b/src/gui/panels/regedit.c index 65b268e..579c60b 100644 --- a/src/gui/panels/regedit.c +++ b/src/gui/panels/regedit.c @@ -913,7 +913,7 @@ GtkMenu *build_param_panel_menu(GRegeditPanel *panel) GtkWidget *result; /* Support à retourner */ GtkWidget *submenuitem; /* Sous-élément de menu */ - result = gtk_menu_new(); + result = qck_create_menu(NULL); submenuitem = qck_create_menu_item(NULL, NULL, _("Copy the name"), G_CALLBACK(mcb_param_panel_copy), panel); gtk_container_add(GTK_CONTAINER(result), submenuitem); diff --git a/src/gui/panels/strings.c b/src/gui/panels/strings.c index da7f539..60c53f4 100644 --- a/src/gui/panels/strings.c +++ b/src/gui/panels/strings.c @@ -873,7 +873,7 @@ static GtkMenu *build_strings_panel_menu(GStringsPanel *panel) GtkWidget *result; /* Support à retourner */ GtkWidget *submenuitem; /* Sous-élément de menu */ - result = gtk_menu_new(); + result = qck_create_menu(NULL); submenuitem = qck_create_menu_item(NULL, NULL, _("_Edit name"), NULL, NULL); gtk_container_add(GTK_CONTAINER(result), submenuitem); diff --git a/src/gui/panels/welcome.c b/src/gui/panels/welcome.c index a007f38..a831a6c 100644 --- a/src/gui/panels/welcome.c +++ b/src/gui/panels/welcome.c @@ -378,7 +378,11 @@ static void g_welcome_panel_load_tips(GWelcomePanel *panel) "Then run the interpreter suitable to your configuration (debug or release):\n\n" " python3-dbg -c 'import pychrysalide ; print(pychrysalide.mod_version())'"), - _("All the configuration files for Chrysalide are located in $HOME/.config/chrysalide/.") + _("All the configuration files for Chrysalide are located in $HOME/.config/chrysalide/."), + + _("The behavior of the main menu bar is copied from the one of a well known browser " + "with a fox mascot.\n\n" + "To make the menu bar appear and disappear, juste press and release the Alt key.") }; |