WIP: GListStore is a simple implementation of GListModel that stores all items in memory. <<< Diego C Sampaio passe par là...

This commit is contained in:
Jean Sirmai 2024-02-08 12:01:39 +01:00
parent 01ab47fc1c
commit 13cb8099aa
Signed by: jean
GPG Key ID: FB3115C340E057E3
2 changed files with 31 additions and 12 deletions

View File

@ -375,7 +375,8 @@ if(1)
}
if (VRB4) printf ("VRB4 model_get_state_arrows_nb = %ld end at line %ld\n",\
arrows_nb, xmlGetLineNo(node));
if (VRB4) for(int k = 0; k < c; k++) printf("%d ", *(t + k)); printf("\n");
if (VRB4) for(int k = 0; k < c; k++) printf("%d ", *(t + k));
printf("\n");
return arrows_nb;
}

View File

@ -45,9 +45,15 @@ void on_activate_window_creation (GtkApplication *app, gpointer data)
}
//-------------------------------------------------------------------------------------------------------------------------------------------
//void on_activating_this_expander (GtkExpander *my_expander, gpointer my_data) {}
//void gtk_expander_set_child (GtkExpander* expander, GtkWidget* child) {}
GListModel *my_item_create_func (gpointer item, gpointer user_data) {return NULL;}
static void on_setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
/* Setup the widget to show in the Gtk.Listview << adapted from the kriptolix example */
{
// printf("...\n", gtk_string_list_get_string (GTK_STRING_LIST(user_data), 0));
GtkWidget *my_label = gtk_label_new (NULL), *my_child_label = gtk_label_new (NULL);
GtkWidget *my_expander = gtk_expander_new (NULL); // ? = gtk_expander_new (GTK_LABEL(my_list_item));
gtk_list_item_set_child (my_list_item, my_label);
@ -62,7 +68,17 @@ static void on_bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_ite
gtk_expander_set_child (GTK_EXPANDER(my_expander), gtk_list_item_get_child (my_list_item));
GtkWidget *my_label = gtk_list_item_get_child (my_list_item); // GtkWidget *my_label = gtk_expander_get_child(my_expander);
// >>> row = item.get_item() <<< How to 'translate' that, now ?
// >>> row = item.get_item() <<< GtkTreeListRow instances are created by a GtkTreeListModel ----------------------------
// https://docs.gtk.org/gtk4/class.TreeListRow.html GtkTreeListRow is used by GtkTreeListModel to represent items.
// It allows navigating the model as a tree and modify the state of rows.
// GtkTreeListRow instances are created by a GtkTreeListModel
// The GtkTreeExpander widget can make use of GtkTreeListRow objects
// https://docs.gtk.org/gtk4/method.TreeExpander.set_list_row.html
// >>> void gtk_tree_expander_set_list_row (GtkTreeExpander *self, GtkTreeListRow *list_row);
// https://docs.gtk.org/gtk4/callback.TreeListModelCreateModelFunc.html
// in add_tree_node(item){} >>> if (type(item) == Gtk.TreeListRow) item = item.get_item(); <<< à 'traduire' +++
// --------------------------------------------------------------------------------------------------------------------------
// GObject *my_object = gtk_tree_list_row_get_item (GTK_TREE_LIST_ROW(self)); // GListModel *gtk_tree_list_row_get_children(GtkTreeListRow *self)
// GtkStringObject *my_string_object = gtk_list_item_get_item (my_list_item);
@ -88,32 +104,30 @@ static void on_selection_change (GtkStringList *my_selection_model, guint posit
//-------------------------------------------------------------------------------------------------------------------------------------------
void on_activating_this_expander (GtkExpander *my_expander, gpointer my_data) {}
void gtk_expander_set_child (GtkExpander* expander, GtkWidget* child) {}
GListModel *my_item_create_func (gpointer item, gpointer user_data) {return NULL;}
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
{
const gchar *my_array[] = {"zero", "one", "two", "three", "four", NULL};
GtkStringList *my_string_list = gtk_string_list_new ((const char * const *) my_array);
gtk_string_list_append (my_string_list, "five");
// GType *my_item_type = g_list_model_get_item_type (G_LIST_MODEL (my_string_list));
GListStore *my_list_store = g_list_store_new (80); // = g_list_store_new (my_item_type);
GtkMultiSelection *my_selection_model = gtk_multi_selection_new (G_LIST_MODEL (my_string_list));
GtkListItemFactory *my_list_item_factory = gtk_signal_list_item_factory_new ();
g_signal_connect (my_list_item_factory, "setup", G_CALLBACK (on_setup_cb), NULL);
g_signal_connect (my_list_item_factory, "bind", G_CALLBACK (on_bind_cb), NULL);
GtkTreeListModel *my_tree_list_model =
gtk_tree_list_model_new (G_LIST_MODEL (my_string_list), 0, 0, my_item_create_func, NULL, NULL);
g_signal_connect (my_list_item_factory, "setup", G_CALLBACK (on_setup_cb), my_tree_list_model);
g_signal_connect (my_list_item_factory, "bind", G_CALLBACK (on_bind_cb), my_tree_list_model);
g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL);
GtkWidget *my_list_view = gtk_list_view_new (GTK_SELECTION_MODEL (my_selection_model), my_list_item_factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_list_view);
GtkTreeListModel *my_tree_list_model =
gtk_tree_list_model_new (G_LIST_MODEL (my_string_list), 1, 0, my_item_create_func, NULL, NULL);
srand(time(NULL)); int rank = rand() % g_list_model_get_n_items (G_LIST_MODEL (my_selection_model));
printf("in : GListModel *item_create_func (gpointer item,...) (line 80) (item n°%d is %s)\n",
rank, gtk_string_list_get_string (my_string_list, rank));
}
//-----------------------------------------| mes notes. |------------------------------------------
/* trying to copy : https://github.com/kriptolix/gtk4_python3_exemples/blob/main/ListView/tree_view.py
@ -153,6 +167,10 @@ def add_tree_node(item):
store.append(child)
return store
GListStore is a simple implementation of GListModel that stores all items in memory.
It provides insertions, deletions, and lookups in logarithmic time
with a fast path for the common case of iterating the list linearly.
def setup(widget, item):
"""Setup the widget to show in the Gtk.Listview"""