From 147cefce6dd3ba7f3350dae9e711d8099832a082 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 8 Sep 2024 22:34:50 +0200 Subject: [PATCH] =?UTF-8?q?WIP:=20pr=C3=A9paration=20chantier=20menu=20dan?= =?UTF-8?q?s=20widget/rules/selected/wip=5Fmenu.c=20=20*widget=5Fget=5Fbtt?= =?UTF-8?q?=5Fconditions=5Flist()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/widget.h | 1 + src/widget/rules/selected/text.c | 7 +- src/widget/rules/selected/wip_menu.c | 105 +++++++++++++++++++++++++++ src/widget/topbar/left.c | 3 +- src/widget/topbar/right.c | 58 --------------- 5 files changed, 112 insertions(+), 62 deletions(-) create mode 100644 src/widget/rules/selected/wip_menu.c diff --git a/include/widget.h b/include/widget.h index 9406d4f..6031572 100644 --- a/include/widget.h +++ b/include/widget.h @@ -197,6 +197,7 @@ void *widget_get_rule_analyse(); // analyse.c void *widget_get_selected_rule_texts(); void *widget_get_selected_rule_images(); +void *widget_get_btt_conditions_list(); /******************************************************************************/ diff --git a/src/widget/rules/selected/text.c b/src/widget/rules/selected/text.c index 3f96bf7..43a7d93 100644 --- a/src/widget/rules/selected/text.c +++ b/src/widget/rules/selected/text.c @@ -31,7 +31,7 @@ #include "../../../../include/widget.h" #include "../../../../include/signal.h" - +/* static void *get_btt_conditions_list() { GtkWidget* list_box = gtk_list_box_new(); @@ -56,6 +56,7 @@ static void *get_btt_conditions_list() return conditions; } +*/ static void *get_btt_assign_list() { @@ -108,7 +109,7 @@ static void *get_btt_rule_identity() void *widget_get_selected_rule_texts() { GtkWidget *label_ad_hoc = GTK_WIDGET (gtk_label_new (\ - " ")); + " ")); // ad hoc (provisoire) GtkBox *conditions_actions_names_box = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2)); GtkLayoutManager *conditions_actions_identity_layout = gtk_box_layout_new (GTK_ORIENTATION_HORIZONTAL); gtk_widget_set_layout_manager (GTK_WIDGET (conditions_actions_names_box), @@ -116,7 +117,7 @@ void *widget_get_selected_rule_texts() gtk_box_layout_set_spacing (GTK_BOX_LAYOUT (conditions_actions_identity_layout), 180); // allocate (GTK_LAYOUT_MANAGER (conditions_actions_identity_layout), get_btt_conditions_list (), 100, 20,100); TODO gtk_box_append (conditions_actions_names_box, GTK_WIDGET (label_ad_hoc)); - gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_conditions_list ())); + gtk_box_append (conditions_actions_names_box, GTK_WIDGET (widget_get_btt_conditions_list ())); gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_assign_list())); gtk_box_append (conditions_actions_names_box, GTK_WIDGET (get_btt_rule_identity())); diff --git a/src/widget/rules/selected/wip_menu.c b/src/widget/rules/selected/wip_menu.c new file mode 100644 index 0000000..119f950 --- /dev/null +++ b/src/widget/rules/selected/wip_menu.c @@ -0,0 +1,105 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * +* * +* Gem-graph client * +* * +* Rules * +* * +* Copyright © 2021 Libre en Communs * +* Copyright © 2021 Jean Sirmai * +* * +* This file is part of Gem-graph. * +* * +* This program is free software: you can redistribute it and/or modify it * +* under the terms of the GNU Affero General Public License * +* as published by the Free Software Foundation, * +* either version 3 of the License, * +* or (at your option) any later version. * +* * +* This program is distributed in the hope that it will be useful, * +* but WITHOUT ANY WARRANTY; * +* without even the implied warranty of MERCHANTABILITY * +* or FITNESS FOR A PARTICULAR PURPOSE. * +* See the GNU Affero General Public License for more details. * +* * +* You should have received a copy of the GNU Affero General Public License * +* along with this program. If not, see . * +* * +* * * * * * * * * * * * * * * * * * * * * * * * * * */ + + +#include "../../../../include/fsm.h" +#include "../../../../include/widget.h" +#include "../../../../include/signal.h" + + +void *widget_get_btt_conditions_list() +{ + GtkWidget* list_box = gtk_list_box_new(); + GtkWidget *label_A = GTK_WIDGET (gtk_label_new("if (value (0,0,1,3) == 2)")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_A); + GtkWidget *label_B = GTK_WIDGET (gtk_label_new("if (value (0,1,1,0) == 0)")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_B); + GtkWidget *label_C = GTK_WIDGET (gtk_label_new("if (value (0,1,1,2) == 0)")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_C); + GtkWidget *label_D = GTK_WIDGET (gtk_label_new("if (value (1,0,1,2) == 1)")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_D); + GtkWidget *label_E = GTK_WIDGET (gtk_label_new("if (value (1,1,1,0) == 0)")); gtk_list_box_append (GTK_LIST_BOX (list_box), label_E); + + + GtkWidget *pop = gtk_popover_new (); + gtk_popover_set_child (GTK_POPOVER (pop), list_box); + gtk_popover_present (GTK_POPOVER (pop)); + gtk_popover_set_autohide (GTK_POPOVER (pop), FALSE); + gtk_popover_set_cascade_popdown (GTK_POPOVER (pop), TRUE); + + GtkMenuButton *conditions = GTK_MENU_BUTTON (gtk_menu_button_new ()); + gtk_menu_button_set_label (GTK_MENU_BUTTON (conditions), "conditions"); + gtk_menu_button_set_always_show_arrow (conditions, TRUE); + gtk_menu_button_set_popover (conditions, GTK_WIDGET (pop)); +// gtk_widget_set_halign (GTK_WIDGET (conditions), GTK_ALIGN_START); + + return conditions; +} + +/* + GSimpleActionGroup *ga = g_simple_action_group_new (); + GtkShortcutAction *aa = gtk_named_action_new ("aa"); + gtk_widget_insert_action_group (btt_A, "aa", G_ACTION_GROUP (ga)); // GActionGroup* group +// GtkShortcutAction *act_aa = gtk_callback_action_new (callback_aa, NULL, NULL); + + + GSimpleAction *act_connect = g_simple_action_new("connect", NULL); + g_signal_connect(act_connect, "activate", G_CALLBACK(connect), NULL); + + + GSimpleAction *act_a = g_simple_action_new ("do_a", NULL); + g_action_map_add_action (G_ACTION_MAP (app), G_ACTION (act_a)); + g_signal_connect (act_a, "activate", G_CALLBACK (action_a), app); +// GMenuItem *menu_item_do_a = g_menu_item_new ("do_a", "app.do_a"); + + // gtk_menu_button_popup (open_menu); gtk_menu_button_popdown (open_menu); + // gtk_menu_item_activate (btt_C); + // g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(act_connect)); + // GMenuItem *label_E = g_menu_item_new("connect", "app.do_a"); +// gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (menu_item_do_a)); + + + / + https://docs.gtk.org/gtk4/class.ListView.html + GtkStringList *model = gtk_string_list_new (NULL); // model = create_application_list (); + + GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new()); + g_signal_connect (factory, "setup", G_CALLBACK (setup_listitem_cb), NULL); + g_signal_connect (factory, "bind", G_CALLBACK (bind_listitem_cb), NULL); + + GtkStringList *list = gtk_list_view_new (GTK_SELECTION_MODEL (gtk_single_selection_new (model)), factory); + + g_signal_connect (list, "activate", G_CALLBACK (activate_cb), NULL); + + gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list); + / + + // ce qui suit ira dans le callback + GtkListBoxRow *selected_row = gtk_list_box_get_selected_row (GTK_LIST_BOX (list_box)); + if (selected_row != NULL) + printf("selected_row = %s\n", + gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (selected_row)))); + + // g_signal_connect (btt_C, "clicked", G_CALLBACK (on_clicked_HOME), no_local_data); +*/ diff --git a/src/widget/topbar/left.c b/src/widget/topbar/left.c index bff4d08..421c7b7 100644 --- a/src/widget/topbar/left.c +++ b/src/widget/topbar/left.c @@ -92,8 +92,9 @@ void window_design_topbar_left (GtkWidget *header_bar) /* the last one is the winner (and the winner takes it all !...) */ /* THE LAST ONE IS THE WINNER (AND THE WINNER TAKES IT ALL !...) */ /******************************************************************************/ - 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); 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); diff --git a/src/widget/topbar/right.c b/src/widget/topbar/right.c index 514cd59..cb6a85a 100644 --- a/src/widget/topbar/right.c +++ b/src/widget/topbar/right.c @@ -85,14 +85,6 @@ static void display_widgets_at_the_right_side (GtkWidget *header_bar) // https://stackoverflow.com/questions/69135934/creating-a-simple-menubar-menu-and-menu-item-in-c-using-gtk4 - - - - - - - - static void callback_aa () {puts("callback_aa() > menu item A clicked.\n");} static void action_a (GSimpleAction *action, GVariant *parameter, gpointer app) {puts("menu item A clicked.\n");} static void connect(GApplication *app, gpointer *data) { puts("Connect menu item clicked.\n"); } @@ -107,39 +99,6 @@ void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app) // GtkShortcutAction *act_aa = gtk_callback_action_new (callback_aa, NULL, NULL); - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - GSimpleAction *act_connect = g_simple_action_new("connect", NULL); g_signal_connect(act_connect, "activate", G_CALLBACK(connect), NULL); @@ -156,14 +115,6 @@ void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app) // gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (menu_item_do_a)); - - - - - - - - /* https://docs.gtk.org/gtk4/class.ListView.html GtkStringList *model = gtk_string_list_new (NULL); // model = create_application_list (); @@ -179,14 +130,6 @@ void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app) gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), list); */ - - - - - - - - // ce qui suit ira dans le callback GtkListBoxRow *selected_row = gtk_list_box_get_selected_row (GTK_LIST_BOX (list_box)); if (selected_row != NULL) @@ -194,7 +137,6 @@ void window_design_topbar_right (GtkWidget *header_bar, GtkApplication *app) gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (selected_row)))); // g_signal_connect (btt_C, "clicked", G_CALLBACK (on_clicked_HOME), no_local_data); - }