WIP: TODO GListModel *create_node_recursive () and all that...

This commit is contained in:
Jean Sirmai 2023-12-25 23:55:28 +01:00
parent b734ab99d4
commit e9ef7fbeae
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 86 additions and 10 deletions

View File

@ -70,6 +70,44 @@
..............................................................................*/ ..............................................................................*/
/*..............................................................................
*
* >>> GtkStringList <<<
*
* GtkStringList is a list model that wraps an array of strings.
* The objects in the model are of type GtkStringObject
* and have a string property that can be used inside expressions.
* Use it where/when you would typically use a char*[], but need a list model.
*
* implements GtkBuildable interface
* <item> are GObject instances; support translatable, context and comments
*
* <object class="GtkStringList">
* <items>
* <item translatable="yes">Factory</item>
* <item translatable="yes">Home</item>
* <item translatable="yes">Subway</item>
* </items>
* </object>
*
* Every item in a model has a position (= unsigned integer)
* "factories" takes care of mapping the items of the model
* to widgets that can be shown in the view
* by creating a listitem for each item that is currently in use.
* List items are always GtkListItem instances. Widgets can be recycled.
*
* GtkStringList can only handle strings. It is backed by a dynamically allocated array.
* GListStore is backed by a balanced tree.
*
* GTK provides functionality to make lists look and behave like trees
* by using the GtkTreeListModel and the GtkTreeExpander widget.
*
* Widgets are styleable using GTK CSS. Use the .rich-list style class.
*
*............................................................................*/
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <stdio.h> #include <stdio.h>
#include "config.h" #include "config.h"
@ -130,11 +168,11 @@ static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1);
g_print ("first row %d: (%s)\n", row_count, str_data); g_print ("first row %d: (%s)\n", row_count, str_data);
gtk_tree_model_iter_children (model, &iter_parent, &iter); /* gtk_tree_model_iter_children (model, &iter_parent, &iter); */
gtk_tree_model_iter_children (model, &iter, &iter_parent); // Sets iter to point to the first child of parent. /* gtk_tree_model_iter_children (model, &iter, &iter_parent); // Sets iter to point to the first child of parent. */
//gtk_tree_model_iter_next (model, &iter); /* //gtk_tree_model_iter_next (model, &iter); */
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); /* gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); */
g_print ("next row %d: (%s) < False (should be 'A' <-- line 104)\n", row_count, str_data); /* g_print ("next row %d: (%s) < False (should be 'A' <-- line 104)\n", row_count, str_data); */
/* while (valid) first row 0: (ROOT) next row 0: (D)*/ /* while (valid) first row 0: (ROOT) next row 0: (D)*/
/* { */ /* { */
@ -231,6 +269,41 @@ static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
} }
/* static GListModel *create_node_recursive (GTreeListModel *model, */
/* guint current_position, */
/* TreeItem *current_item, */
/* guint parent_position, */
/* int depth) */
/* { */
/* if (model == NULL) */
/* model = gtk_tree_list_model_new (GListModel* root, */
/* gboolean passthrough, */
/* gboolean autoexpand, */
/* GtkTreeListModelCreateModelFunc create_func, */
/* gpointer user_data, */
/* GDestroyNotify user_destroy */
/* ); */
/* while (current_item->label) { */
/* if (0) printf("[%d] Current label : %s\n", depth, current_item->label); */
/* gtk_tree_store_append (model, &iter, iter_parent); */
/* gtk_tree_store_set (model, &iter, STRING_COLUMN, current_item->label, -1); */
/* if (current_item->children) */
/* create_node_recursive (model, current_item->children, &iter, depth + 1); */
/* else */
/* break; */
/* current_item++; */
/* } */
/* if (depth == 0) */
/* return GTK_TREE_MODEL(model); // cast from GtkTreeModel to GtkTreeStore */
/* else */
/* return NULL; */
/* } */
GtkWidget * GtkWidget *
do_tree_store (GtkWidget *do_widget) do_tree_store (GtkWidget *do_widget)
{ {
@ -241,9 +314,11 @@ do_tree_store (GtkWidget *do_widget)
GtkWidget *vbox; GtkWidget *vbox;
GtkWidget *sw; // sw : 'scrolled_window' GtkWidget *sw; // sw : 'scrolled_window'
GtkWidget *treeview; GtkWidget *treeview;
GtkTreeModel *my_tree_model; GtkTreeModel *my_tree_model; /////
GtkTreeStore *my_tree_store = NULL; // The GtkTreeStore is used to store data in tree form, GListModel *my_list_model;
// to be used later on by a GtkTreeView to display it. GtkTreeStore *my_tree_store = NULL; /////
GtkTreeListModel *my_tree_list_model;
/* create window, etc */ /* create window, etc */
my_window = gtk_window_new (); my_window = gtk_window_new ();
gtk_window_set_title (GTK_WINDOW (my_window), "Tree Store"); gtk_window_set_title (GTK_WINDOW (my_window), "Tree Store");
@ -267,11 +342,12 @@ do_tree_store (GtkWidget *do_widget)
/* create tree_model */ /* create tree_model */
my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0); my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0);
// my_list_model = create_node_recursive (my_tree_list_model, O, NULL, 0);
iterating_a_model_in_a_depth_first_fashion (my_tree_model); iterating_a_model_in_a_depth_first_fashion (my_tree_model);
// GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1"); // GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1");
// acquiring_a_GtkTreeIter (my_tree_model, my_path); // acquiring_a_GtkTreeIter (my_tree_model, my_path);
GtkTreeIter *my_iter; // GtkTreeIter *my_iter;
gtk_tree_model_get_data_from_iter (my_tree_model, NULL, my_iter, NULL, gtk_tree_path_new_from_string ("0:0:0:1:0:1")); // gtk_tree_model_get_data_from_iter (my_tree_model, NULL, my_iter, NULL, gtk_tree_path_new_from_string ("0:0:0:1:0:1"));
/* create tree view */ /* create tree view */
treeview = gtk_tree_view_new_with_model (my_tree_model); treeview = gtk_tree_view_new_with_model (my_tree_model);