From a54454556afea17fcea619abc4e59cc05a4760f3 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 23 Jan 2024 12:10:37 +0100 Subject: [PATCH] WIP: unbind_cb() and teardown_cb() seems to have no effect. Why ? --- src/ui/sand_box.c | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/src/ui/sand_box.c b/src/ui/sand_box.c index 0d8db4f..1bfee44 100644 --- a/src/ui/sand_box.c +++ b/src/ui/sand_box.c @@ -45,15 +45,20 @@ static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gtk_label_set_text (GTK_LABEL (my_label), gtk_string_object_get_string (my_string_object)); } -static void on_selection_change (GtkSelectionModel* self, guint position, guint n_items, gpointer user_data) +static void unbind_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, GtkSelectionModel *my_selection_model) + {printf("list size = %d\n", g_list_model_get_n_items (my_selection_model));} +static void teardown_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {} + /* GtkListItem instance will be destroyed soon. You don't need to set the child to NULL. */ + +static void on_selection_change (GtkSelectionModel* my_selection_model, guint position, guint n_items, gpointer user_data) { printf("list size = %d item type = %d\ position (premier élement ayant changé d'état) = %2d %7s\ nombre d'éléments ayant changé d'état = %2d\n", - g_list_model_get_n_items (self), - g_list_model_get_item_type(self), + g_list_model_get_n_items (my_selection_model), + g_list_model_get_item_type(my_selection_model), position, - gtk_string_object_get_string(g_list_model_get_item(self, position)), + gtk_string_object_get_string(g_list_model_get_item(my_selection_model, position)), n_items ); } @@ -74,7 +79,15 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box) GtkListItemFactory *my_factory = gtk_signal_list_item_factory_new (); g_signal_connect (my_factory, "setup", G_CALLBACK (setup_cb), NULL); g_signal_connect (my_factory, "bind", G_CALLBACK (bind_cb), NULL); - g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL); + if (0) g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL); + g_signal_connect (my_factory, "unbind", G_CALLBACK (unbind_cb), my_selection_model); + g_signal_connect (my_factory, "teardown", G_CALLBACK (teardown_cb), NULL); + + /* GtkWidget *treeview; */ + /* treeview = gtk_tree_view_new_with_model (my_selection_model); */ + /* gtk_widget_set_vexpand (treeview, TRUE); */ + /* gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), */ + /* COLUMN_DESCRIPTION); */ GtkWidget *my_list_view = gtk_list_view_new (GTK_SELECTION_MODEL (my_selection_model), my_factory); gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_list_view); @@ -96,10 +109,16 @@ void on_activate_window_creation (GtkApplication *app, gpointer data) { if (data) {g_print (data); g_print (" and is displayed by [sand_box.c / on_activate_window_creation()]\n");} } -//-------------------------------------------------------------------- notes +//----------------------------------------------------------------| mes notes. // guix shell -m manifest.scm && pkg-config --libs gtk4 make clean && clear && time make run // my local widgets examples are in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo -// https://toshiocp.github.io/Gtk4-tutorial/sec29.html -// factory = GtkSignalListItemFactory(setup_cb, bind_cb) +// +// tout ce qui commence par gtk... est un widget ex: "my_selection_model" est un widget ?? +// factory = GtkSignalListItemFactory(setup_cb, bind_cb) <<< +// gtk_widget_set_visible(...) <<< +// +// GtkColumnView +// +// https://toshiocp.github.io/Gtk4-tutorial/sec29.html