From 6f463326f94c37a826559a1e42a03ec0d149c94f Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Thu, 20 Jun 2024 05:37:06 +0200 Subject: [PATCH] WIP: the switch is in the callback, now (a first sketch, only) --- callback.c | 22 ++++++++++++++++++---- callback.h | 2 +- contain.c | 37 +++++++++---------------------------- contain.h | 4 ++-- 4 files changed, 30 insertions(+), 35 deletions(-) diff --git a/callback.c b/callback.c index 5bb61c7..3598ab5 100644 --- a/callback.c +++ b/callback.c @@ -185,10 +185,24 @@ void on_toggle_EXEC_EDIT (GtkWidget *btt_XOR_EXEC_EDIT, GtkWidget *btt_MODEL_RUN } } - -void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data) {window_main_child (main_window, STATE); SWITCH_TO (STATE);} -void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data) {window_main_child (main_window, RULES); SWITCH_TO (RULES);} -void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data) {window_main_child (main_window, DATA); SWITCH_TO (DATA);} +void on_STATE_RULES_DATA_selection (GtkToggleButton *source, gpointer user_data) { +// g_print ("Toggle button [%s] is active: %s", gtk_button_get_label (GTK_BUTTON (source)), gtk_toggle_button_get_active (source) ? "Yes" : "No"); + int choice = 0; + switch (choice) { + case (STATE): get_window_child_STATE (); break; + case (RULES): get_window_child_STATE (); break; + case (DATA): get_window_child_STATE (); break; + default : get_window_child_STATE (); + } +} +/* +GtkToggleButton *source +g_print ("Toggle button "%s" is active: %s", + gtk_button_get_label (GTK_BUTTON (source)), + gtk_toggle_button_get_active (source) ? "Yes" : "No");*/ +void on_open_STATE (GtkWidget *btt_open_STATE, gpointer data) {get_window_child_STATE (main_window); SWITCH_TO (STATE);} +void on_open_RULES (GtkWidget *btt_open_RULES, gpointer data) {get_window_child_STATE (main_window); SWITCH_TO (RULES);} +void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data) {get_window_child_STATE (main_window); SWITCH_TO (DATA);} void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data) { gtk_widget_set_sensitive (GTK_WIDGET (data), TRUE); diff --git a/callback.h b/callback.h index ac26745..b7bab90 100644 --- a/callback.h +++ b/callback.h @@ -24,4 +24,4 @@ void on_open_DATA (GtkWidget *btt_open_DATA, gpointer data); void on_SAVE_CURRENT_MODEL_BEFORE_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data); void on_DISCARD_CURRENT_MODEL_AND_START_EDITING (GtkWidget *btt_SAVE_CURRENT_MODEL, gpointer data); void on_WRITE_CURRENT_MODEL (GtkWidget *btt_WRITE_CURRENT_MODEL, gpointer data); - +void on_STATE_RULES_DATA_selection (GtkToggleButton *source, gpointer user_data); diff --git a/contain.c b/contain.c index 61098dc..05e3950 100644 --- a/contain.c +++ b/contain.c @@ -154,7 +154,7 @@ void window_main_child_bottom (GtkBox *page_box){ static void icons_for_fun (GtkHeaderBar *header_bar); -void window_header_bar (GtkWindow *window, char *title){ +void window_header_bar (GtkWindow *window, char *title) { // https://docs.gtk.org/gtk4/class.ToggleButton.html GtkWidget *header_bar = GTK_WIDGET (gtk_header_bar_new ()); gtk_header_bar_set_title_widget (GTK_HEADER_BAR (header_bar), gtk_label_new (title)); gtk_window_set_titlebar (window, header_bar); @@ -179,15 +179,15 @@ void window_header_bar (GtkWindow *window, char *title){ GtkCheckButton *group_STATE_RULES_DATA = GTK_CHECK_BUTTON (gtk_check_button_new ()); GtkButton *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_STATE_RULES_DATA_selection), NULL); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_STATE), group_STATE_RULES_DATA); GtkButton *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_STATE_RULES_DATA_selection), NULL); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_RULES), group_STATE_RULES_DATA); GtkButton *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_STATE_RULES_DATA_selection), NULL); gtk_check_button_set_group (GTK_CHECK_BUTTON (btt_open_DATA), group_STATE_RULES_DATA); gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_open_STATE), TRUE); @@ -202,39 +202,20 @@ void window_header_bar (GtkWindow *window, char *title){ icons_for_fun (GTK_HEADER_BAR (header_bar)); // https://iconduck.com/sets/adwaita-icon-theme } -void window_main_child (GtkWindow *main_window, int selected_page){ -// in automaton.h : enum { INTER, STATE, RULES, DATA } - switch (selected_page) { - case (INTER) : //SWITCH_TO (INTER); - break; - case (STATE) : +GtkWidget *get_window_child_STATE () { GtkBox *page_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_VERTICAL, 2)); gtk_box_append (page_box, GTK_WIDGET (get_OBJECTS_and_SITUATIONS())); gtk_box_append (page_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL))); gtk_box_append (page_box, GTK_WIDGET (get_SPACE_VIEW_box())); gtk_box_append (page_box, GTK_WIDGET (gtk_separator_new (GTK_ORIENTATION_HORIZONTAL))); -// window_main_child_bottom (page_box); -// if (!get_mode ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); -// else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); - gtk_window_set_child (main_window, GTK_WIDGET (page_box)); + if (!get_mode ()) gtk_box_append (page_box, GTK_WIDGET (get_TIME_EXEC_controls_box())); + else gtk_box_append (page_box, GTK_WIDGET (get_SPACE_EDIT_controls_box())); //SWITCH_TO (STATE); - break; - case (RULES) : gtk_window_set_child (main_window, GTK_WIDGET (get_rules_page_new())); - //SWITCH_TO (RULES); - break; - case (DATA) : gtk_window_set_child (main_window, GTK_WIDGET (get_measures_page_new())); - //SWITCH_TO (DATA); - break; - case (4) : gtk_window_set_child (main_window, GTK_WIDGET (get_results_page_new())); break; - case (5) : gtk_window_set_child (main_window, GTK_WIDGET (get_discuss_page_new())); break; - case (6) : gtk_window_set_child (main_window, GTK_WIDGET (get_help_page_new())); break; - default : gtk_window_set_child (main_window, GTK_WIDGET (get_SPACE_VIEW_box())); // + un "help message" - } - // printf ("%d\n", get_status()); + return GTK_WIDGET (page_box); } void main_window_design (GtkWindow *main_window){ - window_main_child (main_window, STATE); + gtk_window_set_child (main_window, get_window_child_STATE ()); window_header_bar (main_window, "E coli (with permission from David S. Goodsell, 2009)"); gtk_window_present (GTK_WINDOW (main_window)); diff --git a/contain.h b/contain.h index 3121b99..ac12b63 100644 --- a/contain.h +++ b/contain.h @@ -35,5 +35,5 @@ void two_notebooks_in_two_panes (GtkWindow *window); GtkWidget *get_selected_rules_vpaned_new(); GtkFrame *get_frame_with_label(); void window_main_child_bottom (GtkBox *page_box); -void window_main_child (GtkWindow *main_window, int selected_page); - +//void window_main_child (GtkWindow *main_window, int selected_page); +GtkWidget *get_window_child_STATE ();