A C T I O N S A C T I O N S A C T I O N S

This commit is contained in:
Jean Sirmai 2024-07-15 10:26:14 +02:00
parent d64691bf38
commit 0e1aeb293c
Signed by: jean
GPG Key ID: FB3115C340E057E3
6 changed files with 164 additions and 37 deletions

10
include/actions.h Normal file
View File

@ -0,0 +1,10 @@
// https://docs.gtk.org/gio/class.MenuItem.html
// https://docs.gtk.org/gio/ctor.MenuItem.new.html
//
// https://docs.gtk.org/gio/class.SimpleAction.html
// https://docs.gtk.org/gio/ctor.SimpleAction.new.html
//
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/include/ui.h
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/src/ui/events.c
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/src/ui/application.c

View File

@ -54,8 +54,6 @@ GtkWindow *widget_head_get_TEXT_WINDOW();
/* W I D G E T S */
/******************************************************************************/
GtkButton *widget_head_get_GtkButton (char *btt_name);
GtkWidget *get_STATE_page();
GtkWidget *get_RULES_page();
GtkWidget *get_STOCK_page();

79
src/actions.c Normal file
View File

@ -0,0 +1,79 @@
//
//
//
// https://docs.gtk.org/gio/class.MenuItem.html
// https://docs.gtk.org/gio/ctor.MenuItem.new.html
//
// https://docs.gtk.org/gio/class.SimpleAction.html
// https://docs.gtk.org/gio/ctor.SimpleAction.new.html
//
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/include/ui.h
/* static const GActionEntry app_actions [] = {
{ "quit", on_quit_action, NULL, NULL, NULL },
{ "about", on_about_action, NULL, NULL, NULL },
{ "preferences", on_preferences_action, NULL, NULL, NULL },
.... }; */
//
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/src/ui/events.c
/* void on_about_action(GSimpleAction *action,
GVariant *parameter,
gpointer user_data)
{
static const char *authors[] = { "Adrien Bourmault (neox@a-lec.org)",
"Jean Sirmai (jean@a-lec.org)",
"Arthur Menges (arthur.menges@a-lec.org)",
NULL};
GemGraphClientApplication *self = user_data;
GtkWindow *window = NULL;
g_assert (GEM_GRAPH_CLIENT_IS_APPLICATION(self));
window = gtk_application_get_active_window(GTK_APPLICATION (self));
gtk_show_about_dialog(window,
"program-name", "Gem-graph",
"logo-icon-name", "application-x-executable",
"authors", authors,
"version", "0.1.0",
"copyright", "Copyright © 2023 Libre en Communs",
NULL);
} */
//
// https://forge.a-lec.org/gem-graph/gem-graph-client/src/branch/devel/src/ui/application.c
/* void ui_enable_action(const char *name) {
g_simple_action_set_enabled(
(GSimpleAction *)g_action_map_lookup_action(
G_ACTION_MAP(application),
name),
true);
}
void ui_disable_action(const char *name) {
g_simple_action_set_enabled(
(GSimpleAction *)g_action_map_lookup_action(
G_ACTION_MAP(application),
name),
false);
}
*
* Window actual presentation on screen
*
*
static void gem_graph_client_application_activate(GApplication *app)
{
GtkWindow *window;
g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION(app));
window = gtk_application_get_active_window(GTK_APPLICATION (app));
if (window == NULL)
window = g_object_new(GEM_GRAPH_CLIENT_TYPE_WINDOW,
"application", app,
NULL);
ui_set_stack(HOME_MODE);
gtk_window_present(window);
}
*/

View File

@ -390,7 +390,10 @@ void on_clicked_HOME (GtkWidget *btt_reset, gpointer data)
void on_clicked_menu_experiment (GtkWidget *btt_menu, gpointer list_box) {
printf ("callback.on_clicked_MENU() button > %p < &list_box > children nb > 3\n", list_box);
// gpointer list_box = gtk_popover_get_child (GTK_POPOVER (pop));
/*
if (gtk_list_box_get_row_at_index (list_box, 3))
printf ("callback.on_clicked_MENU() button > %p < &list_box > children nb > 3\n", list_box);
else printf ("callback.on_clicked_MENU() button > in list_box are the three buttons : %s, %s, %s\n\
@ -401,6 +404,7 @@ void on_clicked_menu_experiment (GtkWidget *btt_menu, gpointer list_box) {
// learning_how_to_create_a_menu (menu_button);
// https://docs.gtk.org/gtk4/class.ListBox.html
*/
}

0
src/widget.c/action.c Normal file
View File

View File

@ -56,18 +56,10 @@ void widget_head_set_DIALOG_WINDOW (GtkApplication *app)
void widget_head_set_TEXT_WINDOW (GtkApplication *app)
{ text_window = GTK_WINDOW (gtk_application_window_new (app)); }
GtkButton *widget_head_get_GtkButton (char *btt_name)
{
if (strcmp (btt_name, "state")) return btt_STATE;
if (strcmp (btt_name, "rules")) return btt_RULES;
if (strcmp (btt_name, "data analysis")) return btt_DATA;
return NULL;
}
/******************************************************************************/
/* D I A L O G & T E X T W I N D O W S */
/* T E X T W I N D O W */
/******************************************************************************/
void widget_head_TEXT_WINDOW_design (GtkWindow *main_window, GtkWindow *text_window)
@ -87,6 +79,12 @@ void widget_head_TEXT_WINDOW_design (GtkWindow *main_window, GtkWindow *text_win
gtk_window_set_destroy_with_parent (GTK_WINDOW (text_window), TRUE);
}
/******************************************************************************/
/* D I A L O G W I N D O W */
/******************************************************************************/
void widget_head_DIALOG_WINDOW_design (GtkWindow *main_window, GtkWindow *dialog_window)
{
char *title = " Save the current model before modifying it? ";
@ -124,33 +122,38 @@ void widget_head_DIALOG_WINDOW_design (GtkWindow *main_window, GtkWindow *dialog
/******************************************************************************/
/* M A I N W I N D O W */
/* M A I N W I N D O W C E N T E R */
/******************************************************************************/
static GtkWidget *window_header_bar (GtkWindow *window, char *title);
static void window_left (GtkWidget *header_bar);
static void window_right (GtkWidget *header_bar);
static GtkWidget *window_header_bar (GtkWindow *window);
static void window_header_bar_left (GtkWidget *header_bar);
static void window_header_bar_right (GtkWidget *header_bar);
void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){
GtkWidget *header_bar = window_header_bar (main_window,
"E coli (with permission from David S. Goodsell, 2009)");
window_left (header_bar);
window_right (header_bar);
GtkWidget *header_bar = window_header_bar (main_window);
window_header_bar_left (header_bar);
window_header_bar_right (header_bar);
// next line <=> calls.on_toggle_STATE_RULES_DATA (btt_STATE)
gtk_check_button_set_active (GTK_CHECK_BUTTON (btt_STATE), TRUE);
gtk_window_present (GTK_WINDOW (main_window));
}
static GtkWidget *window_header_bar (GtkWindow *window, char *title)
static GtkWidget *window_header_bar (GtkWindow *window)
{
char *title = "E coli (with permission from David S. Goodsell, 2009)";
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);
return header_bar;
}
static void window_left (GtkWidget *header_bar)
/******************************************************************************/
/* M A I N W I N D O W L E F T */
/******************************************************************************/
static void window_header_bar_left (GtkWidget *header_bar)
{
gpointer no_local_data = NULL;
@ -183,22 +186,24 @@ static void window_left (GtkWidget *header_bar)
}
static void window_right (GtkWidget *header_bar)
/******************************************************************************/
/* M A I N W I N D O W R I G H T */
/******************************************************************************/
static void connect(GApplication *app, gpointer *data) { puts("Connect menu item clicked.\n"); }
static void window_header_bar_right (GtkWidget *header_bar)
{
gpointer no_local_data = NULL;
// https://iconduck.com/sets/adwaita-icon-theme https://iconduck.com/sets/carbon-icons
GtkButton *btt_go_home = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (btt_go_home, "go-home-symbolic");
g_signal_connect (btt_go_home, "clicked", G_CALLBACK (on_clicked_HOME), no_local_data);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (btt_go_home));
GtkButton *search = GTK_BUTTON (gtk_button_new ());
gtk_button_set_icon_name (search, "user-trash-symbolic");
gtk_button_set_icon_name (search, "emblem-documents-symbolic");
gtk_button_set_icon_name (search, "preferences-desktop-appearance-symbolic");
gtk_button_set_icon_name (search, "applications-utilities-symbolic");
gtk_button_set_icon_name (search, "folder-saved-search-symbolic");
g_signal_connect (search, "clicked", G_CALLBACK (on_clicked_search), no_local_data);
gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (search));
@ -209,10 +214,11 @@ static void window_right (GtkWidget *header_bar)
GtkWidget* list_box = gtk_list_box_new();
// GtkWidget *menu_item_A = GTK_WIDGET (gtk_menu_item_new ("A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A);
// GtkWidget *menu_item_B = GTK_WIDGET (gtk_menu_item_new_with_label("B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B);
GtkWidget *menu_item_A;
if (0) menu_item_A = GTK_WIDGET (g_menu_item_new ("A", "activate"));
else menu_item_A = GTK_WIDGET (gtk_label_new("A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A);
GtkWidget *menu_item_B = GTK_WIDGET (gtk_label_new("B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B);
GtkWidget *menu_item_C = GTK_WIDGET (gtk_label_new("C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C);
GtkWidget *menu_item_D = GTK_WIDGET (gtk_label_new("D")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_D);
// gtk_menu_item_activate (menu_item_C);
// https://discourse.gnome.org/t/when-do-we-really-have-to-use-gtk-popover-present-to-show-a-popover-at-a-given-widget/17566/5
@ -222,16 +228,33 @@ static void window_right (GtkWidget *header_bar)
gtk_popover_set_autohide (GTK_POPOVER (pop), FALSE);
gtk_popover_set_cascade_popdown (GTK_POPOVER (pop), TRUE);
GtkMenuButton *open_menu = GTK_MENU_BUTTON (gtk_menu_button_new ()); // gtk_button_new or gtk_menu_button_new ?
GtkMenuButton *open_menu = GTK_MENU_BUTTON (gtk_menu_button_new ());
// gtk_menu_button_popup (open_menu); gtk_menu_button_popdown (open_menu);
gtk_menu_button_set_icon_name (open_menu, "open-menu-symbolic");
gtk_menu_button_set_always_show_arrow (open_menu, TRUE);
gtk_menu_button_set_popover (open_menu, GTK_WIDGET (pop));
gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu));
// https://stackoverflow.com/questions/69135934/creating-a-simple-menubar-menu-and-menu-item-in-c-using-gtk4
GSimpleAction *act_connect = g_simple_action_new("connect", NULL);
// g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(act_connect));
g_signal_connect(act_connect, "activate", G_CALLBACK(connect), NULL);
// GMenuItem *menu_item_E = g_menu_item_new("connect", "app.connect");
// gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (menu_item_E));
g_signal_connect (open_menu, "activate", G_CALLBACK (on_clicked_menu_experiment), list_box);
// signal 'clicked' is invalid for instance '0xbcb2900' of type 'GtkMenuButton'
// signal 'clicked' is invalid for instance '0x2812f80' of type 'GtkListBox'
// signal 'clicked' is invalid for instance '0x2a15120' of type 'GtkLabel'
// signal 'activate' is invalid for instance '0x17fb93d0' of type 'GtkLabel'
// signal 'clicked' is invalid for instance '0xbcb2900' of type 'GtkMenuButton'
// signal 'clicked' is invalid for instance '0x2c992b9' of type 'GtkPopover'
// signal 'clicked' is invalid for instance '0x2812f80' of type 'GtkListBox'
// signal 'clicked' is invalid for instance '0x2a15120' of type 'GtkLabel'
//
// signal 'activate' is invalid for instance '0x3c3de7a' of type 'GtkPopover'
// signal 'activate' is invalid for instance '0x3d62f80' of type 'GtkListBox'
// signal 'activate' is invalid for instance '0x17fb93d' of type 'GtkLabel'
@ -274,3 +297,16 @@ static void window_right (GtkWidget *header_bar)
}
/******************************************************************************/
/* L O C A L L A B ( I C O N S ) */
/******************************************************************************/
// https://iconduck.com/sets/adwaita-icon-theme
// https://iconduck.com/sets/carbon-icons
//
// gtk_button_set_icon_name (search, "user-trash-symbolic");
// gtk_button_set_icon_name (search, "emblem-documents-symbolic");
// gtk_button_set_icon_name (search, "preferences-desktop-appearance-symbolic");
// gtk_button_set_icon_name (search, "applications-utilities-symbolic");