WIP: failure of: gtk_menu_item_new_with_label (heads.c 176) How to connect ?

This commit is contained in:
Jean Sirmai 2024-07-14 12:39:07 +02:00
parent 3d42cd041a
commit f47014b4e6
Signed by: jean
GPG Key ID: FB3115C340E057E3
2 changed files with 14 additions and 8 deletions

View File

@ -348,8 +348,9 @@ void on_SITUATIONS_box_DO_RESET (GtkWidget *btt_reset, gpointer data)
/******************************************************************************/ /******************************************************************************/
void on_clicked_MENU_pop (GtkWidget *btt_reset, gpointer pop) { void on_clicked_MENU_pop (GtkWidget *btt_menu, gpointer list_box) {
gpointer list_box = gtk_popover_get_child (GTK_POPOVER (pop)); 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)) 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); 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\ else printf ("callback.on_clicked_MENU() button > in list_box are the three buttons : %s, %s, %s\n\
@ -358,8 +359,6 @@ void on_clicked_MENU_pop (GtkWidget *btt_reset, gpointer pop) {
gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 1)))), gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 1)))),
gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 2))))); gtk_button_get_label (GTK_BUTTON (gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 2)))));
if (0) gtk_popover_popup (GTK_POPOVER (pop));
// learning_how_to_create_a_menu (menu_button); // learning_how_to_create_a_menu (menu_button);
// https://docs.gtk.org/gtk4/class.ListBox.html // https://docs.gtk.org/gtk4/class.ListBox.html

View File

@ -172,20 +172,27 @@ static void window_header_bar (GtkWindow *window, char *title)
GtkWidget* list_box = gtk_list_box_new(); GtkWidget* list_box = gtk_list_box_new();
GtkWidget *menu_item_A = GTK_WIDGET (gtk_label_new ("A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A); // 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_label_new ("B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B); // 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_C = GTK_WIDGET (gtk_label_new("C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C); GtkWidget *menu_item_C = GTK_WIDGET (gtk_label_new("C")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_C);
GtkWidget *pop = gtk_popover_new (); GtkWidget *pop = gtk_popover_new ();
gtk_popover_set_child (GTK_POPOVER (pop), list_box); gtk_popover_set_child (GTK_POPOVER (pop), list_box);
gtk_popover_present (GTK_POPOVER (pop)); gtk_popover_present (GTK_POPOVER (pop));
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_button_new or gtk_menu_button_new ?
gtk_menu_button_set_icon_name (open_menu, "open-menu-symbolic"); gtk_menu_button_set_icon_name (open_menu, "open-menu-symbolic");
gtk_menu_button_set_popover (open_menu, GTK_WIDGET (pop)); gtk_menu_button_set_popover (open_menu, GTK_WIDGET (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 (open_menu));
// g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU_pop), pop); 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 (menu_item_C, "clicked", G_CALLBACK (on_clicked_HOME), no_local_data);
// 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 // 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
} }