From 2706aaf7b245892b86f817a3972d2f8e542612b1 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 24 Sep 2024 22:29:39 +0200 Subject: [PATCH] const char *widget_get_btt_synth_label () {return synth;} < dans widget/topbar/left < mieux +++ --- include/widget.h | 8 +++--- src/signal.c | 55 +++++++++++++++++++--------------------- src/widget/topbar/left.c | 31 ++++++++++++---------- 3 files changed, 48 insertions(+), 46 deletions(-) diff --git a/include/widget.h b/include/widget.h index f208021..1676dac 100644 --- a/include/widget.h +++ b/include/widget.h @@ -77,10 +77,10 @@ void widget_design_text_window (GtkWindow *main_window, GtkWindow *text_window // called in widget / topbar / dispatch.c / widget_design_main_window() // defined in topbar / left.c -void *widget_get_btt_synth(); // {return btt_SYNTH;} -void *widget_get_btt_state(); // {return btt_STATE;} -void *widget_get_btt_rules(); // {return btt_RULES;} -void *widget_get_btt_data(); // {return btt_DATA;} +const char *widget_get_btt_synth_label(); +const char *widget_get_btt_state_label(); +const char *widget_get_btt_rules_label(); +const char *widget_get_btt_data_label(); // called in widget / topbar / dispatch.c / widget_design_main_window() // defined in widget / topbar / left.c diff --git a/src/signal.c b/src/signal.c index 33e2991..bfed126 100644 --- a/src/signal.c +++ b/src/signal.c @@ -244,13 +244,13 @@ void on_write_current_model (GtkWidget *btt_write_current_model, /******************************************************************************/ -/* T O P B A R W I D G E T S */ +/* T O P B A R L E F T W I D G E T S */ /******************************************************************************/ -// ----------------------- E X E C / E D I T -------------------------- // - static void switch_state_rules_data(); +// ----------------------- E X E C / E D I T -------------------------- // + void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data) { fsm_journal_event (INFO, BUTTON, "signal", "toggle exec edit()", @@ -270,7 +270,7 @@ void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data) // https://docs.gtk.org/gtk4/class.Window.html TODO 2024-06-30 // gtk_window_present (GTK_WINDOW (widget_get_dialog_window())); - // // works once only A window should be created each time + // // works onstrcmpce only A window should be created each time fsm_set_exec_edit (EDIT); // TODO set_btt_SYNTH_active (FALSE) @@ -283,6 +283,25 @@ 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) +{ + 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)); + 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); + if ( ! strcmp (toggled_button_name, widget_get_btt_state_label())) fsm_set_state_rules_data (STATE); + if ( ! strcmp (toggled_button_name, widget_get_btt_rules_label())) fsm_set_state_rules_data (RULES); + if ( ! strcmp (toggled_button_name, widget_get_btt_data_label())) fsm_set_state_rules_data (DATA); + + if (is_active) switch_state_rules_data(); +} + + +// ----------------------- S T A T I C S W I T C H -------------------- // + static void switch_state_rules_data() { int value = fsm_get_state_rules_data(); @@ -340,32 +359,10 @@ static void switch_state_rules_data() } } -// TODO Il doit y avoir plus élégant,... ET SURTOUT MOINS DANGEREUX !!! -// que d'utiliser: strcmp (toggled_button_name, "label_du_bouton") car: -// ces labels sont utilisés pour deux fonctions distinctes: -// (1) ici (just below): pour changer l'état de la fsm -// et là: src/widget/topbar/left.c: -// btt_SYNTH = GTK_BUTTON (gtk_check_button_new_with_label ("synth")); -// pour changer la page (le widget) affiché -// IL FAUT REGROUPER CES DEUX FONCTIONS - -void on_toggle_state_rules_data (GtkWidget *toggled_button, gpointer user_data) -{ - 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)); - int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (toggled_button)); - - if ( ! strcmp (toggled_button_name, "synth")) fsm_set_state_rules_data (SYNTH); - if ( ! strcmp (toggled_button_name, "state")) fsm_set_state_rules_data (STATE); - if ( ! strcmp (toggled_button_name, "rules")) fsm_set_state_rules_data (RULES); - if ( ! strcmp (toggled_button_name, "results")) fsm_set_state_rules_data (DATA); - - if (is_active) switch_state_rules_data(); -} - +/******************************************************************************/ +/* T O P B A R R I G H T W I D G E T S */ +/******************************************************************************/ // ------------ M E N U / S E A R C H / H O M E / E T C ----------- // diff --git a/src/widget/topbar/left.c b/src/widget/topbar/left.c index 4ce3641..df0febf 100644 --- a/src/widget/topbar/left.c +++ b/src/widget/topbar/left.c @@ -34,12 +34,17 @@ /* 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; -void *widget_get_btt_synth () {return btt_SYNTH;} -void *widget_get_btt_state () {return btt_STATE;} -void *widget_get_btt_rules () {return btt_RULES;} -void *widget_get_btt_data () {return btt_DATA;} +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";} void window_design_topbar_left (GtkWidget *header_bar) { @@ -56,20 +61,20 @@ void window_design_topbar_left (GtkWidget *header_bar) GtkCheckButton *group_state_rules_data = GTK_CHECK_BUTTON (gtk_check_button_new ()); - btt_SYNTH = GTK_BUTTON (gtk_check_button_new_with_label ("synth")); + 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 ("state")); + 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); - btt_RULES = GTK_BUTTON (gtk_check_button_new_with_label ("rules")); + 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); - btt_DATA = GTK_BUTTON (gtk_check_button_new_with_label ("results")); + btt_DATA = GTK_BUTTON (gtk_check_button_new_with_label (widget_get_btt_data_label())); g_signal_connect (btt_DATA, "toggled", G_CALLBACK (on_toggle_state_rules_data), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_DATA), group_state_rules_data); @@ -93,12 +98,12 @@ void window_design_topbar_left (GtkWidget *header_bar) /* THE LAST ONE IS THE WINNER (AND THE WINNER TAKES IT ALL !...) */ /******************************************************************************/ if (YOU_WANT_TO_START_ON_ANOTHER_PAGE) { // select one - gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_synth()), TRUE); - gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_rules()), TRUE); - gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_state()), TRUE); - gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_data()), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_SYNTH), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_STATE), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_RULES), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_DATA), TRUE); } else - gtk_check_button_set_active (GTK_CHECK_BUTTON (widget_get_btt_rules()), TRUE); + gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_RULES), TRUE); }