2023-11-09 06:58:48 +01:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2023-11-24 16:34:06 +01:00
|
|
|
GtkListStore *list_store;
|
2023-11-24 17:57:44 +01:00
|
|
|
GtkTreeIter iter;
|
2023-11-24 16:34:06 +01:00
|
|
|
|
2023-11-24 17:57:44 +01:00
|
|
|
/***********************************************************
|
|
|
|
* *
|
|
|
|
* 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);
|
|
|
|
}
|
|
|
|
}
|
2023-11-24 16:50:51 +01:00
|
|
|
/*************************************************************
|
|
|
|
* *
|
|
|
|
* Converting a GtkTreePath into a GtkTreeIter *
|
|
|
|
* *
|
|
|
|
*************************************************************/
|
2023-11-24 16:34:06 +01:00
|
|
|
|
2023-11-24 16:50:51 +01:00
|
|
|
/*************************************************************
|
|
|
|
* *
|
|
|
|
* 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)
|
2023-11-24 16:25:56 +01:00
|
|
|
{
|
2023-11-24 16:34:06 +01:00
|
|
|
list_store = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_UINT);
|
|
|
|
|
2023-11-24 17:57:44 +01:00
|
|
|
/* 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);
|
|
|
|
|
2023-11-24 16:25:56 +01:00
|
|
|
printf("tree_c_printing_test() \
|
2023-11-24 16:50:51 +01:00
|
|
|
---------------------------------------------------------\n\n\
|
|
|
|
(https://en.wikibooks.org/wiki/GTK (modulo) 2B_By_Example/Tree_View/Tree_Models)\n\n\
|
2023-11-24 17:57:44 +01:00
|
|
|
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\
|
2023-11-24 16:34:06 +01:00
|
|
|
Column 0 stores a string and column 1 stores an unsigned integer for each row.\n\
|
2023-11-24 17:57:44 +01:00
|
|
|
Three empty lines have been added to the model - (cf. line 100).\n");
|
2023-11-24 16:25:56 +01:00
|
|
|
}
|
2023-11-09 06:58:48 +01:00
|
|
|
|