From 34f295d8ccb821f17ed63c8676cb51c4819cf459 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sun, 14 Jul 2024 06:57:32 +0200 Subject: [PATCH] WIP: How to make this popover popup ? (see heads.c 183 & calls.c 351 --- include/calls.h | 3 ++- src/calls.c | 8 ++++---- src/widget.c/heads.c | 13 ++++++++----- src/widget.c/menu.c | 3 +++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/include/calls.h b/include/calls.h index 687a9bb..e2c6cd4 100644 --- a/include/calls.h +++ b/include/calls.h @@ -71,7 +71,8 @@ void on_SITUATIONS_box_RESET_VALUE (GtkAdjustment *adjustment, gpointer data); void on_SITUATIONS_box_DO_RESET (GtkWidget *btt_reset, gpointer data); void on_clicked_HOME (GtkWidget *btt_reset, gpointer data); -void on_clicked_MENU (GtkWidget *btt_reset, gpointer data); +//void on_clicked_MENU_list_box (GtkWidget *btt_reset, gpointer data); +void on_clicked_MENU_pop (GtkWidget *btt_reset, gpointer data); diff --git a/src/calls.c b/src/calls.c index 1be19f3..1f99405 100644 --- a/src/calls.c +++ b/src/calls.c @@ -348,11 +348,11 @@ void on_SITUATIONS_box_DO_RESET (GtkWidget *btt_reset, gpointer data) /******************************************************************************/ -void on_clicked_MENU (GtkWidget *btt_reset, gpointer list_box) -{ +void on_clicked_MENU_pop (GtkWidget *btt_reset, gpointer pop) { + 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\ + 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\ and now : how to display these three buttons (and make use of them) ? 2024-07-13 (20h)\n",\ gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 0)))), gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 1)))), diff --git a/src/widget.c/heads.c b/src/widget.c/heads.c index a6c2349..77be46d 100644 --- a/src/widget.c/heads.c +++ b/src/widget.c/heads.c @@ -178,20 +178,23 @@ static void window_header_bar (GtkWindow *window, char *title) // GtkWidget *menu_item_D = GTK_WIDGET (gtk_button_new_with_label ("button_D")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_D); // gtk_list_box_append (GTK_LIST_BOX (list_box), gtk_label_new ("any text")); - GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); // gtk_button_new or gtk_menu_button_new ? + GtkWidget *pop = gtk_popover_new (); + gtk_popover_set_child (GTK_POPOVER (pop), list_box); + if (0) gtk_popover_popup (GTK_POPOVER (pop)); + GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); // gtk_button_new or gtk_menu_button_new ? gtk_button_set_icon_name (GTK_BUTTON (open_menu), "open-menu-symbolic"); -// gtk_menu_button_set_label (open_menu, "open-menu-symbolic"); -// gtk_menu_button_set_child (open_menu, list); - g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU), list_box); +// g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_list_box), list_box); + g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu)); +/* gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (get_menu_anchor())); - GtkWidget *menu_btt = gtk_menu_button_new (); gtk_menu_button_set_child (GTK_MENU_BUTTON (menu_btt), NULL); gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (menu_btt), NULL); // GMenuModel* menu_model gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (menu_btt)); +*/ } void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){ diff --git a/src/widget.c/menu.c b/src/widget.c/menu.c index c8e257c..a8bdfa9 100644 --- a/src/widget.c/menu.c +++ b/src/widget.c/menu.c @@ -81,6 +81,9 @@ static GListModel* get_user_menu_model (GObject *item, gpointer root){ GtkWidget *get_menu_anchor() { + // https://docs.gtk.org/gio/class.MenuModel.html + // https://www.geany.org/manual/gtk/gobject/index.html + if (0) labo_create_a_simple_gtk_string_list (); struct MenuNode_t *menu_root = create_user_menu_node("menu"); struct MenuNode_t *item_a = create_user_menu_node("item_a");add_menu_item (menu_root, item_a);