gem-graph-client/src/ui/tree.c

113 lines
3.8 KiB
C
Raw Normal View History

/*
* Gem-graph OpenGL experiments
*
* Desc: User interface functions
*
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
*
* This file is part of Gem-graph.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <unistd.h>
#include <gtk-4.0/gtk/gtk.h>
#include <glib-2.0/glib.h>
#include "../../include/base.h"
#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 *
* *
*************************************************************/
/*************************************************************
* *
* onTreeViewRowActivated: a row has been double-clicked *
* *
*************************************************************/
void
onTreeViewRowActivated (GtkTreeView *view, GtkTreePath *path,
GtkTreeViewColumn *col, gpointer userdata)
{
GtkTreeIter iter;
GtkTreeModel *model;
model = gtk_tree_view_get_model(view);
if (gtk_tree_model_get_iter(model, &iter, path))
{
gchar *name;
gtk_tree_model_get(model, &iter, "ANY_COLUMN_NAME", &name, -1);
g_print ("The row containing the name '%s' has been double-clicked.\n", name);
g_free(name);
}
}
void
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 : 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\
Three empty lines have been added to the model - (cf. line 100).\n");
}