From 2158a831ddc22ccffecc85cc623d882089dff709 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 26 Sep 2024 10:27:45 +0200 Subject: [PATCH] =?UTF-8?q?fonction:=20widget=5Fget=5Fall=5Frules=5Fleft?= =?UTF-8?q?=5Fpane()=20=20d=C3=A9plac=C3=A9e=20vers=20all=5Frules/dispatch?= =?UTF-8?q?/?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/fsm/dispatch.c | 4 +-- src/fsm/preferences/manager.c | 5 ++-- src/main.c | 22 ++++++++++++++++ src/signal.c | 32 +++++++++++------------ src/widget/all_rules/dispatch.c | 36 +++++++++++++++++++++++++- src/widget/all_rules/tree/dispatch.c | 19 -------------- src/widget/topbar/left.c | 38 ++++++++++++++++++++++------ 7 files changed, 107 insertions(+), 49 deletions(-) diff --git a/src/fsm/dispatch.c b/src/fsm/dispatch.c index 469bd00..7ddfcc8 100644 --- a/src/fsm/dispatch.c +++ b/src/fsm/dispatch.c @@ -125,7 +125,7 @@ static int preferences_have_been_modified = FALSE; void fsm_set_preferences_modified (bool value) { const char *str_value; - if (value) str_value = "FALSE"; else str_value = "TRUE"; // maladroit... TODO + if (! value) str_value = "FALSE"; else str_value = "TRUE"; // maladroit... TODO fsm_journal_event (INFO, FSM, "fsm/dispatch", @@ -156,7 +156,7 @@ int fsm_get_state_rules_data() {return choice_STATE_RULES_DATA;} /******************************************************************************/ static char *tab_0 [] = { "EXEC", "EDIT" }; -static char *tab_1 [] = { "SYNTH", "STATE", "RULES", "DATA" }; +static char *tab_1 [] = { "SYNTH", "STATE", "RULES", "RESULTS" }; void fsm_set_exec_edit (int choice) { diff --git a/src/fsm/preferences/manager.c b/src/fsm/preferences/manager.c index fe37e89..11d078b 100644 --- a/src/fsm/preferences/manager.c +++ b/src/fsm/preferences/manager.c @@ -93,7 +93,7 @@ void fsm_store_restore_reset (int choice, int value) fsm_journal_event (MESSAGE, PREFER, "fsm/prefer", "store restore reset(): switch (default)", ""); } - fsm_set_preferences_modified (TRUE); + // fsm_set_preferences_modified (TRUE); << inutile ici ! C'est fait dans 'signal' } @@ -106,7 +106,8 @@ static int reset_situations_to_value = -1; void fsm_reset_all_situations_transparencies_at_value (int value) { char string_value [12]; sprintf(string_value, "(%d)", value); - fsm_journal_event (INFO, PREFER, "fsm/prefer", "reset all situations transparencies at value", string_value); + printf("fsm/preferences/manager fsm_reset_all_situations_transparencies_at_value() %d\n", value); + fsm_journal_event (INFO, PREFER, "fsm/preferences/manager", "reset all situations transparencies at value() ", "TODO value > string_value"); reset_situations_to_value = value; widget_reset_all_situations_transparencies_at_value (value); } diff --git a/src/main.c b/src/main.c index 685d5da..ff3b9c8 100644 --- a/src/main.c +++ b/src/main.c @@ -155,6 +155,28 @@ int main (int argc, char **argv) fsm_journal_event (INFO, MAIN, "main", "That'all folks !", "👋️😄️"); fsm_journal_publication_request(); + + + + printf("voir à la fin de 'main: étude des limites de la fonction 'snprintf()'\n"); + + long num = 1234567891234567891; + char str[20]; + + sprintf(str, "%ld", num); // integer to string + printf("sprintf %ld > str %s\n", num, str); + + snprintf(str, sizeof(str), "%ld", num); + printf("snprintf %ld > str %s\n", num, str); + + strtol(str, NULL, 0); // The strtol() function takes a char pointer as its first argument, followed by two ints. + // The first int specifies the base of the number, + // and the second int specifies the maximum number of characters to be converted. + printf("strtol %ld > str %s\n", num, str); + + + + return status; } diff --git a/src/signal.c b/src/signal.c index bfed126..bb8e4af 100644 --- a/src/signal.c +++ b/src/signal.c @@ -283,12 +283,12 @@ void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data) // ------------------ S T A T E / R U L E S / D A T A --------------- // -void on_toggle_state_rules_data (GtkWidget *toggled_button, gpointer user_data) +void on_toggle_state_rules_data (GtkWidget *toggled_button, gpointer widget_all_vs_selected_one) { const char *toggled_button_name = gtk_check_button_get_label (GTK_CHECK_BUTTON (toggled_button)); fsm_journal_event (DEBUG, BUTTON, "signal", "toggle_state_rules_data()", - concat ("change of status requested", ": [", toggled_button_name, "]", NULL)); + concat ("[", toggled_button_name, "]", NULL)); int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (toggled_button)); if ( ! strcmp (toggled_button_name, widget_get_btt_synth_label())) fsm_set_state_rules_data (SYNTH); @@ -304,14 +304,7 @@ void on_toggle_state_rules_data (GtkWidget *toggled_button, gpointer user_data) static void switch_state_rules_data() { - int value = fsm_get_state_rules_data(); - /* - * pas sûr que ça ait un intérêt... en tout cas, pas comme ça ! - * - char string_value [12]; sprintf(string_value, "%d", value); - fsm_journal_event (DEBUG, SWITCH_STATE_RULES_DATA, "signal", "(switch) value = ", string_value); - */ - switch (value) { + switch (fsm_get_state_rules_data()) { case (SYNTH) : gtk_window_set_child (GTK_WINDOW (widget_get_main_window ()), @@ -324,15 +317,17 @@ static void switch_state_rules_data() break; case (RULES) : - /* The rules page consists of two half-pages in a GtkPaned widget : + /* + * The rules page consists of two half-pages in a GtkPaned widget : * - on the left, widgets for controlling or editing all the rules. * - on the right, widgets for controlling or editing the selected rule. - * This distribution is therefore moved to this file - * instead of having a "widget_get_rules_page()" function. + * + * Instead of having a: "widget_get_rules_page()" function, + * this distribution is moved here. (see also widget/topbar/left design) + * window_design_topbar_left() */ GtkPaned *widget_all_vs_selected_one = - GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL)); - + GTK_PANED (gtk_paned_new (GTK_ORIENTATION_HORIZONTAL)); gtk_paned_set_start_child (widget_all_vs_selected_one, GTK_WIDGET (widget_get_all_rules_left_pane())); gtk_paned_set_end_child (widget_all_vs_selected_one, @@ -393,9 +388,11 @@ void on_clicked_topbar_right_home (GtkWidget *btt_reset, gpointer data) void on_updating_objects_transparencies (GtkWidget *btt_source, GtkScrollbar *scrollbar) { - fsm_journal_event (DEBUG, BUTTON, "signal", "updating objects transparencies()", ""); const char *btt_name = gtk_button_get_icon_name (GTK_BUTTON (btt_source)); int value = gtk_adjustment_get_value (gtk_scrollbar_get_adjustment (scrollbar)); + char string_value [12]; sprintf(string_value, "%d", value); + printf(string_value); + fsm_journal_event (DEBUG, BUTTON, "signal", "updating objects transparencies()", string_value); // TODO TODO (je suis fatigué) if ( ! strcmp (btt_name, "document-revert-rtl-symbolic")) fsm_store_restore_reset (STORE, value); if ( ! strcmp (btt_name, "edit-undo-symbolic")) fsm_store_restore_reset (RESTORE, value); @@ -414,9 +411,10 @@ void on_resetting_XYZ_in_state_page () void on_situations_box_do_reset (GtkWidget *btt_reset, GtkScrollbar *reset_scrollbar) { - fsm_journal_event (DEBUG, BUTTON, "signal", "situations box do reset()", ""); GtkAdjustment *adj_situ = gtk_scrollbar_get_adjustment (reset_scrollbar); fsm_reset_all_situations_transparencies_at_value (gtk_adjustment_get_value (adj_situ)); + char string_value [319]; sprintf(string_value, "(%f)", gtk_adjustment_get_value (adj_situ)); // TODO (marche pas...)) + fsm_journal_event (DEBUG, BUTTON, "signal", "situations box do reset()", string_value); } diff --git a/src/widget/all_rules/dispatch.c b/src/widget/all_rules/dispatch.c index e056c3f..0712308 100644 --- a/src/widget/all_rules/dispatch.c +++ b/src/widget/all_rules/dispatch.c @@ -30,8 +30,42 @@ -/* The rules page consists of two half-pages: +/* + * The rules page consists of two half-pages in a GtkPaned widget : * - on the left, widgets for controlling or editing all the rules. * - on the right, widgets for controlling or editing the selected rule. + * + * Instead of having a: "widget_get_rules_page()" function, + * this distribution is moved in signal switch_state_rules_data() + * see also widget/topbar/left window_design_topbar_left() */ + +// pilot_box +// users_tree +// rules_use (frequencies) +// comparator + +// GTK possède un espace mémoire où les widgets sont alloués/désalloués +// Un widget ne conserve pas son pointeur. Son adresse peut donc changer. +// Créer une stack de widget avec un outil hors GTK n'est pas faisable. Donc : +// TODO (voir le détail dans : compare.c) +// Pour obtenir une GIcon à partir d'une GtkImage, je peux la sérialiser : +// https://docs.gtk.org/gio/method.Icon.serialize.html 🤔️ +// https://docs.gtk.org/gio/method.Icon.hash.html +// A #guint containing a hash for the icon, suitable for use in a GHashTable... + + + +void *widget_get_all_rules_left_pane () +{ + fsm_journal_event (INFO, TOPBAR_LEFT, "widget/all_rules/", "all_rules_left_pane design", + "pilot box + tree tools "); + GtkBox *rules_tree_and_pilot_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); + gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (widget_get_rules_pilot_box ())); + gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL))); + gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (widget_get_rules_tree_tools ())); + return rules_tree_and_pilot_box; +} + + diff --git a/src/widget/all_rules/tree/dispatch.c b/src/widget/all_rules/tree/dispatch.c index b1807d3..85ad040 100644 --- a/src/widget/all_rules/tree/dispatch.c +++ b/src/widget/all_rules/tree/dispatch.c @@ -29,23 +29,4 @@ #include "../../../../include/signal.h" -void *widget_get_all_rules_left_pane () -{ - fsm_journal_event (INFO, TOPBAR_LEFT, "widget/all_rules/tree", "design", - "pilot box + tree tools <<< TODO"); - GtkBox *rules_tree_and_pilot_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); - gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (widget_get_rules_pilot_box ())); - gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL))); - gtk_box_append (rules_tree_and_pilot_box, GTK_WIDGET (widget_get_rules_tree_tools ())); - return rules_tree_and_pilot_box; -} - -// GTK possède un espace mémoire où les widgets sont alloués/désalloués -// Un widget ne conserve pas son pointeur. Son adresse peut donc changer. -// Créer une stack de widget avec un outil hors GTK n'est pas faisable. Donc : -// TODO (voir le détail dans : compare.c) -// Pour obtenir une GIcon à partir d'une GtkImage, je peux la sérialiser : -// https://docs.gtk.org/gio/method.Icon.serialize.html 🤔️ -// https://docs.gtk.org/gio/method.Icon.hash.html -// A #guint containing a hash for the icon, suitable for use in a GHashTable... diff --git a/src/widget/topbar/left.c b/src/widget/topbar/left.c index df0febf..a8ca27a 100644 --- a/src/widget/topbar/left.c +++ b/src/widget/topbar/left.c @@ -34,18 +34,38 @@ /* M A I N W I N D O W T O P B A R ( L E F T ) */ /******************************************************************************/ -// ! WARNING ! IL SERAIT DANGEREUX DE REDEFINIR LE LABEL D'UN BOUTON -// DANS LE PROGRAMME AILLEURS QU'ICI (OU PLUS D'UNE FOIS) -// -// par exemple: grep -r '"synth"' < ne doit renvoyer q'UNE SEULE ligne - static GtkButton *btt_SYNTH, *btt_STATE, *btt_RULES, *btt_DATA; +// ! WARNING ! LE LABEL D'UN BOUTON NE DOIT ÊTRE DÉFINI QU'UNE FOIS (ICI) ET +// EN UTILISANT LA FONCTION: widget_get_btt__label() + const char *widget_get_btt_synth_label () {return "synth";} const char *widget_get_btt_state_label () {return "state";} const char *widget_get_btt_rules_label () {return "rules";} const char *widget_get_btt_data_label () {return "results";} + +/* The rules page consists of two half-pages in a GtkPaned widget : + * - on the left, widgets for controlling or editing all the rules. + * - on the right, widgets for controlling or editing the selected rule. + * + * As this division is clear and constant, it is simpler to place these two + * half-pages at the same hierarchical level as the other full pages + * like "synth", "state" or "results". + * + * So there is no: "widget_get_rules_page()" function. + * Instead, the distribution: "all rules" versus "the selected one" + * is moved to the file: "signal". + * + * It is in the function: + * static void switch_state_rules_data() { + * switch (fsm_get_state_rules_data()) { + * ... + * case (RULES) : GtkPaned *widget_all_vs_selected_one = ... + * break; + * ... + * } + */ void window_design_topbar_left (GtkWidget *header_bar) { fsm_journal_event (INFO, TOPBAR_LEFT, "widget/topbar/left", "design (topbar left)", @@ -57,19 +77,21 @@ void window_design_topbar_left (GtkWidget *header_bar) gtk_button_set_icon_name (btt_XOR_EXEC_EDIT, "power-profile-balanced-rtl-symbolic"); g_signal_connect (btt_XOR_EXEC_EDIT, "clicked", G_CALLBACK (on_toggle_exec_edit), no_local_data); - GtkWidget *any_Label = GTK_WIDGET (gtk_label_new (" | ")); + GtkWidget *any_label = GTK_WIDGET (gtk_label_new (" | ")); // ad hoc GtkCheckButton *group_state_rules_data = GTK_CHECK_BUTTON (gtk_check_button_new ()); btt_SYNTH = GTK_BUTTON (gtk_check_button_new_with_label (widget_get_btt_synth_label())); g_signal_connect (btt_SYNTH, "toggled", G_CALLBACK (on_toggle_state_rules_data), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_SYNTH), group_state_rules_data); - gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_SYNTH), FALSE); // << TODO btt_STATE = GTK_BUTTON (gtk_check_button_new_with_label (widget_get_btt_state_label())); g_signal_connect (btt_STATE, "toggled", G_CALLBACK (on_toggle_state_rules_data), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_STATE), group_state_rules_data); + // see signal switch_state_rules_data() + // case (RULES): GtkPaned *widget_all_vs_selected_one = ... + // and the full comment above. btt_RULES = GTK_BUTTON (gtk_check_button_new_with_label (widget_get_btt_rules_label())); g_signal_connect (btt_RULES, "toggled", G_CALLBACK (on_toggle_state_rules_data), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_RULES), group_state_rules_data); @@ -79,7 +101,7 @@ void window_design_topbar_left (GtkWidget *header_bar) gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_DATA), group_state_rules_data); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_XOR_EXEC_EDIT)); - gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (any_Label)); + gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (any_label)); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_SYNTH)); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_STATE)); gtk_header_bar_pack_start (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_RULES));