From b05510e48214a4e1cafd8837a92904c798b87a5f Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Mon, 24 Jun 2024 23:09:22 +0200 Subject: [PATCH] on_toggle_STATE_RULES_DATA is OK <> to clean (merge ccb5f51 ?) --- callback.c | 23 +++++++++++------------ contain.c | 8 ++++---- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/callback.c b/callback.c index 3128135..c4d36e2 100644 --- a/callback.c +++ b/callback.c @@ -219,21 +219,20 @@ void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data) { void on_toggle_STATE_RULES_DATA (GtkWidget *btt, gpointer user_data) { // https://docs.gtk.org/gtk4/class.ToggleButton.html < f..k ! bad code ++ - // g_print ("Toggle button [%s] is active: %s\n", gtk_button_get_label (GTK_BUTTON (source)), gtk_toggle_button_get_active (source) ? "Yes" : "No"); - char *source = ""; - if (0) printf("gtk_check_button_get_active > %d, %d, %d < from callback : on_toggle_STATE_RULES_DATA()\n",\ - gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton (source))), - gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton (source))), - gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton (source)))); + const char *btt_name = gtk_check_button_get_label (GTK_CHECK_BUTTON (btt)); + int is_active = gtk_check_button_get_active (GTK_CHECK_BUTTON (btt)); + int is_state_active = ! strcmp (btt_name, "state"); + int is_rules_active = ! strcmp (btt_name, "rules"); + int is_data_active = ! strcmp (btt_name, "data analysis"); + if (0 && is_active) printf ("> [%d] %d, %d, %d %14s\n", + is_active, is_state_active, is_rules_active, is_data_active, btt_name); - int choice = 0; - switch (choice) { - case (STATE): get_GtkButton ("state"); break; // get_window_child_STATE (); - case (RULES): get_GtkButton ("rules"); break; // get_window_child_RULES (); break; - case (DATA): get_GtkButton ("data analysis"); break; // get_window_child_DATA (); break; - default : get_GtkButton ("state"); break; // get_window_child_STATE (); + if (is_active) { + if (is_state_active) gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_STATE())); + else if (is_rules_active) gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_RULES())); + else if (is_data_active) gtk_window_set_child (main_window, GTK_WIDGET (get_window_child_DATA())); } } diff --git a/contain.c b/contain.c index 7f41663..e0cf41a 100644 --- a/contain.c +++ b/contain.c @@ -197,17 +197,17 @@ void window_header_bar (GtkWindow *window, char *title){ GtkCheckButton *group_STATE_RULES_DATA = GTK_CHECK_BUTTON (gtk_check_button_new ()); btt_open_STATE = GTK_BUTTON (gtk_check_button_new_with_label ("state")); - g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_open_STATE), no_local_data); +// g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_open_STATE), no_local_data); g_signal_connect (btt_open_STATE, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_STATE), group_STATE_RULES_DATA); btt_open_RULES = GTK_BUTTON (gtk_check_button_new_with_label ("rules")); - g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_open_RULES), no_local_data); +// g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_open_RULES), no_local_data); g_signal_connect (btt_open_RULES, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_RULES), group_STATE_RULES_DATA); btt_open_DATA = GTK_BUTTON (gtk_check_button_new_with_label ("data analysis")); - g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_open_DATA), no_local_data); +// g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_open_DATA), no_local_data); g_signal_connect (btt_open_DATA, "toggled", G_CALLBACK (on_toggle_STATE_RULES_DATA), no_local_data); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_DATA), group_STATE_RULES_DATA); @@ -217,7 +217,7 @@ void window_header_bar (GtkWindow *window, char *title){ gtk_check_button_get_label (GTK_CHECK_BUTTON (btt_open_RULES)), gtk_check_button_get_label (GTK_CHECK_BUTTON (btt_open_DATA))); - if (1) printf("gtk_check_button_get_active > before = %d, %d, %d\n",\ + if (0) printf("gtk_check_button_get_active > before = %d, %d, %d\n",\ gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton ("state"))), gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton ("rules"))), gtk_check_button_get_active (GTK_CHECK_BUTTON (get_GtkButton ("data analysis"))));