diff --git a/include/callbacks.h b/include/calls.h similarity index 100% rename from include/callbacks.h rename to include/calls.h diff --git a/include/widgets.h b/include/widgets.h index 3e1207d..017adc8 100644 --- a/include/widgets.h +++ b/include/widgets.h @@ -35,9 +35,9 @@ /* W I N D O W S */ /******************************************************************************/ -void set_main_window (GtkApplication *app); -void set_dialog_window (GtkApplication *app); -void set_text_window (GtkApplication *app); +void head_set_MAIN_WINDOW (GtkApplication *app); +void head_set_DIALOG_WINDOW (GtkApplication *app); +void head_set_TEXT_WINDOW (GtkApplication *app); void widget_MAIN_WINDOW_design (GtkWindow *main_window); void widget_DIALOG_WINDOW_design (GtkWindow *main_window, @@ -45,9 +45,9 @@ void widget_DIALOG_WINDOW_design (GtkWindow *main_window, void widget_TEXT_WINDOW_design (GtkWindow *main_window, GtkWindow *text_window); -GtkWindow *get_main_window(); -GtkWindow *get_dialog_window(); -GtkWindow *get_text_window(); +GtkWindow *head_get_MAIN_WINDOW(); +GtkWindow *head_get_DIALOG_WINDOW(); +GtkWindow *head_get_TEXT_WINDOW(); /******************************************************************************/ diff --git a/src/callbacks.c b/src/calls.c similarity index 93% rename from src/callbacks.c rename to src/calls.c index 04abff8..2fec924 100644 --- a/src/callbacks.c +++ b/src/calls.c @@ -30,7 +30,7 @@ #include "../include/automat.h" -#include "../include/callbacks.h" +#include "../include/calls.h" #include "../include/widgets.h" #include "../include/graph.h" @@ -64,14 +64,14 @@ static void on_auto_notification (const char *message) void on_windows_activation (GtkApplication *app, gpointer no_user_data) { - set_main_window (app); - widget_MAIN_WINDOW_design (get_main_window()); + head_set_MAIN_WINDOW (app); + widget_MAIN_WINDOW_design (head_get_MAIN_WINDOW()); - set_dialog_window (app); - widget_DIALOG_WINDOW_design (get_main_window(), get_dialog_window()); + head_set_DIALOG_WINDOW (app); + widget_DIALOG_WINDOW_design (head_get_MAIN_WINDOW(), head_get_DIALOG_WINDOW()); - set_text_window (app); - widget_TEXT_WINDOW_design (get_main_window(), get_text_window()); + head_set_TEXT_WINDOW (app); + widget_TEXT_WINDOW_design (head_get_MAIN_WINDOW(), head_get_TEXT_WINDOW()); } @@ -251,17 +251,17 @@ static void switch_STATE_RULES_DATA() switch (get_STATE_RULES_DATA()) { case (STATE) : - gtk_window_set_child (get_main_window(), + gtk_window_set_child (head_get_MAIN_WINDOW(), GTK_WIDGET (get_STATE_page())); break; case (RULES) : - gtk_window_set_child (get_main_window(), + gtk_window_set_child (head_get_MAIN_WINDOW(), GTK_WIDGET (get_RULES_page())); break; case (DATA) : - gtk_window_set_child (get_main_window(), + gtk_window_set_child (head_get_MAIN_WINDOW(), GTK_WIDGET (get_STOCK_page())); break; @@ -284,7 +284,7 @@ void on_toggle_EXEC_EDIT (GtkWidget *toggled_button, gpointer user_data) "text-editor-symbolic"); // https://docs.gtk.org/gtk4/class.Window.html TODO 2024-06-30 - // gtk_window_present (GTK_WINDOW (get_dialog_window())); // works once only ! + // gtk_window_present (GTK_WINDOW (head_get_DIALOG_WINDOW())); // works once only ! set_EXEC_EDIT (EDIT); } @@ -344,22 +344,23 @@ void on_SITUATIONS_box_DO_RESET (GtkWidget *btt_reset, gpointer data) /******************************************************************************/ -/* M A I N W I N D O W H E A D E R W I D E T S */ +/* M A I N W I N D O W H E A D E R W I D G E T S */ /******************************************************************************/ void on_clicked_MENU (GtkWidget *btt_reset, gpointer menu_button) { - printf ("callback.on_clicked_MENU() button presents the text_window\ - and works only once.\nIt should present a menu.\n"); // TODO + printf ("callback.on_clicked_MENU() button\n"); + // presents the text_window and works only once.\nIt should present a menu.\n"); // TODO learning_how_to_create_a_menu (menu_button); + gtk_window_present (GTK_WINDOW (head_get_TEXT_WINDOW())); } void on_clicked_HOME (GtkWidget *btt_reset, gpointer data) { printf ("callback.on_clicked_HOME() button presents the dialog_window\ ( :- ) but it works only once.\n"); // TODO - gtk_window_present (GTK_WINDOW (get_dialog_window())); + gtk_window_present (GTK_WINDOW (head_get_DIALOG_WINDOW())); } diff --git a/src/graph.c/area.c b/src/graph.c/area.c index f83dc79..172f8a3 100644 --- a/src/graph.c/area.c +++ b/src/graph.c/area.c @@ -26,7 +26,7 @@ #include "../../include/graph.h" -#include "../../include/callbacks.h" +#include "../../include/calls.h" struct stack_index_t { long stack_id; diff --git a/src/main.c b/src/main.c index 72fc76e..915ae63 100644 --- a/src/main.c +++ b/src/main.c @@ -30,7 +30,7 @@ -#include "../include/callbacks.h" +#include "../include/calls.h" /* Comment renommer les fonctions ? * Cette question dépend de plusieurs choix diff --git a/src/widget.c/heads.c b/src/widget.c/heads.c index 758dbbf..810c9e2 100644 --- a/src/widget.c/heads.c +++ b/src/widget.c/heads.c @@ -29,7 +29,7 @@ #include "../../include/base.h" -#include "../../include/callbacks.h" +#include "../../include/calls.h" #include "../../include/widgets.h" #define W_TEXT_WINDOW 700 @@ -38,21 +38,21 @@ static GtkWindow *main_window, *dialog_window, *text_window; static GtkButton *btt_STATE, *btt_RULES, *btt_DATA; -GtkWindow *get_main_window() {return main_window;} -GtkWindow *get_dialog_window() {return dialog_window;} -GtkWindow *get_text_window() {return text_window;} +GtkWindow *head_get_MAIN_WINDOW() {return main_window;} +GtkWindow *head_get_DIALOG_WINDOW() {return dialog_window;} +GtkWindow *head_get_TEXT_WINDOW() {return text_window;} -void set_main_window (GtkApplication *app) +void head_set_MAIN_WINDOW (GtkApplication *app) { main_window = GTK_WINDOW (gtk_application_window_new (app)); } -void set_dialog_window (GtkApplication *app) +void head_set_DIALOG_WINDOW (GtkApplication *app) { dialog_window = GTK_WINDOW (gtk_application_window_new (app)); } -void set_text_window (GtkApplication *app) +void head_set_TEXT_WINDOW (GtkApplication *app) { text_window = GTK_WINDOW (gtk_application_window_new (app)); } @@ -170,10 +170,25 @@ static void window_header_bar (GtkWindow *window, char *title) gtk_button_set_icon_name (search, "folder-saved-search-symbolic"); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (search)); + GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); // gtk_button_new or gtk_menu_button_new ? - gtk_button_set_icon_name (open_menu, "open-menu-symbolic"); + gtk_button_set_icon_name (GTK_BUTTON (open_menu), "open-menu-symbolic"); +// gtk_menu_button_set_label (open_menu, "open-menu-symbolic"); + char *array[] = {"one", "two", "three", "four", NULL}; + GtkStringList *list = gtk_string_list_new ((const char * const *) array); + if (0) printf ("heads.window_header_bar() > list [2] = %s\n", + gtk_string_list_get_string (list, 1)); + +// gtk_menu_button_set_child (open_menu, list); g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU), open_menu); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu)); + + + + GtkWidget *menu_btt = gtk_menu_button_new (); + gtk_menu_button_set_child (GTK_MENU_BUTTON (menu_btt), NULL); + gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_btt), NULL); // GMenuModel* menu_model + gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (menu_btt)); } void widget_MAIN_WINDOW_design (GtkWindow *main_window){ diff --git a/src/widget.c/labo.c b/src/widget.c/labo.c index 86583df..951ef9f 100644 --- a/src/widget.c/labo.c +++ b/src/widget.c/labo.c @@ -55,24 +55,40 @@ /******************************************************************************/ +static void *user_data_free_func() {return NULL;} void learning_how_to_create_a_menu (GtkMenuButton* menu_button) { // Je veux que ce bouton ouvre un menu. - gtk_window_present (GTK_WINDOW (get_text_window())); +// GtkWidget ex = *gtk_menu_bar_new(); char *array[] = {"one", "two", "three", "four", NULL}; GtkStringList *list = gtk_string_list_new ((const char * const *) array); printf ("labo.learning_how_to_create_a_menu () > list [3] = %s\n", gtk_string_list_get_string (list, 2)); + GtkWidget* list_box = gtk_list_box_new (); + gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (list)); + gtk_list_box_bind_model (GTK_LIST_BOX (list_box), + NULL, // GListModel* model, + NULL, // GtkListBoxCreateWidgetFunc create_widget_func, + NULL, // gpointer user_data, + (*user_data_free_func) (NULL) // GDestroyNotify user_data_free_func + ); + + gtk_menu_button_set_child (menu_button, list_box); + // https://docs.gtk.org/gtk4/class.ListView.html // https://toshiocp.github.io/Gtk4-tutorial/sec29.html +// https://blog.gtk.org/2020/06/07/scalable-lists-in-gtk-4/ +// https://docs.gtk.org/gtk4/class.ListBox.html +// https://docs.gtk.org/gtk4/class.MenuButton.html +// https://web.mit.edu/barnowl/share/gtk-doc/html/gobject/gobject-Signals.html +// https://docs.gtk.org/gio/class.MenuModel.html#a-menu-example } - /******************************************************************************/ /* C O N T A I N E R S */ /******************************************************************************/ diff --git a/src/widget.c/state.c b/src/widget.c/state.c index 39c74f2..4b4dca8 100644 --- a/src/widget.c/state.c +++ b/src/widget.c/state.c @@ -29,7 +29,7 @@ #include "../../include/automat.h" #include "../../include/widgets.h" -#include "../../include/callbacks.h" +#include "../../include/calls.h" #define W 1920 // TODO 2024-06-30 (Ad hoc pour mon écran) #define H 960 @@ -92,12 +92,12 @@ static GtkBox *get_OBJECTS_box() GtkBox *objects_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0)); GtkAdjustment *reset_value = gtk_adjustment_new (0, 0, 127, 1, 0, 0); GtkScrollbar *reset_scrollbar = GTK_SCROLLBAR (gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, reset_value)); - printf("\nin state.get_OBJECTS_box() g_signal_connect (reset_scrollbar,...) déclenche:\n\ +/* printf("\nin state.get_OBJECTS_box() g_signal_connect (reset_scrollbar,...) déclenche:\n\ Gtk-CRITICAL **:... assertion 'GTK_IS_SIGNAL_ACTION (self)' failed (Quel est le nom de ce signal ?)\n\ GLib-GObject-CRITICAL **:... g_signal_connect_data: assertion 'detailed_signal != NULL' failed\n"); g_signal_connect (reset_scrollbar, gtk_signal_action_get_signal_name (GTK_SIGNAL_ACTION (reset_scrollbar)), - G_CALLBACK (on_OBJECTS_box_RESET_VALUE), NULL); + G_CALLBACK (on_OBJECTS_box_RESET_VALUE), NULL);*/ gtk_box_append (objects_box, gtk_label_new (" ")); // AD HOC (pour "centrer") gtk_box_append (objects_box, GTK_WIDGET (reset_scrollbar)); GtkWidget *btt_reset = gtk_check_button_new_with_label ("reset"); diff --git a/src/widget.c/stock.c b/src/widget.c/stock.c index 761cd47..dcee76c 100644 --- a/src/widget.c/stock.c +++ b/src/widget.c/stock.c @@ -28,7 +28,7 @@ #include "../../include/base.h" -#include "../../include/callbacks.h" +#include "../../include/calls.h" #include "../../include/widgets.h" GtkWidget *get_STOCK_page () { diff --git a/src/widget.c/tree.c b/src/widget.c/tree.c index 3a053d0..eec6b1a 100644 --- a/src/widget.c/tree.c +++ b/src/widget.c/tree.c @@ -28,7 +28,7 @@ * * * * * * * * * * * * * * * * * * * * * * * * * * */ -#include "../../include/callbacks.h" +#include "../../include/calls.h" #include "../../include/widgets.h" // GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL