From 96bb8346158b8405f21129c95cd32bd16ed09d03 Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Fri, 24 Nov 2023 17:57:44 +0100 Subject: [PATCH] WIP: (micro) Three empty lines have been added to the model. --- include/ui.h | 6 ++++++ src/ui/tree.c | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/include/ui.h b/include/ui.h index d595d32..283da49 100644 --- a/include/ui.h +++ b/include/ui.h @@ -118,7 +118,13 @@ void ui_send_internal_notification (const char *message); void ui_close_internal_notification (void); void ui_toggle_sidebar (); +/* -------------------------------------------------------------------------- */ + +// Tree primitives + +void traverse_list_store (GtkListStore *liststore); void onTreeViewRowActivated (GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer userdata); + void tree_c_printing_test(void); diff --git a/src/ui/tree.c b/src/ui/tree.c index 20f174b..4d8f243 100644 --- a/src/ui/tree.c +++ b/src/ui/tree.c @@ -29,7 +29,35 @@ #include "../../include/ui.h" GtkListStore *list_store; +GtkTreeIter iter; + /*********************************************************** + * * + * Going through every row in a list store * + * * + ***********************************************************/ + + void + traverse_list_store (GtkListStore *liststore) + { + GtkTreeIter iter; + gboolean valid; + + g_return_if_fail ( liststore != NULL ); + + /* Get first row in list store */ + valid = gtk_tree_model_get_iter_first(GTK_TREE_MODEL(liststore), &iter); + + while (valid) + { + /* ... do something with that row using the iter ... */ + /* (Here column 0 of the list store is of type G_TYPE_STRING) */ + gtk_list_store_set(liststore, &iter, 0, "Joe", -1); + + /* Make iter point to the next row in the list store */ + valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(liststore), &iter); + } + } /************************************************************* * * * Converting a GtkTreePath into a GtkTreeIter * @@ -68,11 +96,17 @@ tree_c_printing_test(void) { list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT); + /* Append empty rows to the list store. Iter will point to the new row */ + gtk_list_store_append(list_store, &iter); + gtk_list_store_append(list_store, &iter); + gtk_list_store_append(list_store, &iter); + printf("tree_c_printing_test() \ ---------------------------------------------------------\n\n\ (https://en.wikibooks.org/wiki/GTK (modulo) 2B_By_Example/Tree_View/Tree_Models)\n\n\ -cf. tuto : This creates a new list store with two columns.\n\ +cf. tuto : gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT) - (cf. line 69)\n\ + creates a new list store with two columns.\n\ Column 0 stores a string and column 1 stores an unsigned integer for each row.\n\ -At this point the model has no rows yet of course.\n"); +Three empty lines have been added to the model - (cf. line 100).\n"); }