2023-12-12 19:49:20 +01:00
|
|
|
/************************************************** R E M E M B E R ! *****************************************************/
|
|
|
|
/* */
|
|
|
|
/* jean@Project:~/Gem-Graph/gem-graph-client/tree (learning)/The_Gnome_way/gtk$ guix shell -m manifest.scm --check */
|
|
|
|
/* guix shell: vérification des variables d'environnement visibles depuis le shell « /gnu/store/ --- (a commit) --- /bin/bash »… */
|
|
|
|
/* guix shell: Tout va bien ! Le shell a les bonnes variables d'environnement. */
|
|
|
|
/* jean@Project:~/Gem-Graph/gem-graph-client/tree (learning)/The_Gnome_way/gtk [env] $ cd builddir/ */
|
|
|
|
/* jean@Project:~/Gem-Graph/gem-graph-client/tree (learning)/The_Gnome_way/gtk/builddir [env] $ */
|
|
|
|
/* jean@Project:~/Gem-Graph/gem-graph-client/tree...way/gtk/builddir [env] $ clear && meson compile && demos/gtk-demo/gtk4-demo */
|
|
|
|
/* */
|
|
|
|
/* -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- A Session -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- */
|
|
|
|
/* */
|
|
|
|
/* jean@Project:~/Gem-Graph/gem-graph-client/tree (learning)/The_Gnome_way/gtk/builddir [env] $ ctrl D (avant de fermer builder) */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************************************************************************/
|
|
|
|
|
2023-12-15 10:12:13 +01:00
|
|
|
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
|
|
|
|
|
|
|
|
/************************************************** <> *****************************************************/
|
|
|
|
/* */
|
|
|
|
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html */
|
|
|
|
/* GtkTreeViewColumn, GtkTreeSelection, GtkTreeModel, GtkTreeView drag-and-drop, GtkTreeSortable, GtkTreeModelSort, GtkListStore, */
|
|
|
|
/* GtkTreeStore, GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf, GtkCellRendererText, GtkCellRendererToggle */
|
|
|
|
/* */
|
|
|
|
/* https://www.gnu.org/software/guile-gnome/docs/gtk/html/GtkCellRenderer.html */
|
|
|
|
/* */
|
|
|
|
/*************************************************************************************************************************************/
|
2023-12-12 19:49:20 +01:00
|
|
|
|
|
|
|
|
2023-12-13 09:30:00 +01:00
|
|
|
/* The GtkTreeStore is used to store data in tree form, to be used later on by a GtkTreeView to display it.
|
|
|
|
* This demo builds a simple GtkTreeStore and displays it.
|
|
|
|
* If you're new to the GtkTreeView widgets and associates, look into the GtkListStore example first. */
|
|
|
|
|
2023-12-12 11:36:42 +01:00
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
2023-12-12 18:40:36 +01:00
|
|
|
#include <stdio.h>
|
2023-12-12 11:36:42 +01:00
|
|
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
2023-12-12 12:47:28 +01:00
|
|
|
|
2023-12-12 11:36:42 +01:00
|
|
|
/* TreeItem structure */
|
|
|
|
typedef struct _TreeItem TreeItem;
|
|
|
|
struct _TreeItem
|
|
|
|
{
|
|
|
|
const char *label;
|
2023-12-15 11:02:53 +01:00
|
|
|
// gboolean AA;
|
2023-12-12 11:36:42 +01:00
|
|
|
TreeItem *children;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* columns */
|
|
|
|
enum
|
|
|
|
{
|
2023-12-13 11:53:11 +01:00
|
|
|
COLUMN_0,
|
|
|
|
COLUMN_1,
|
2023-12-12 11:36:42 +01:00
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
/* tree data */
|
2023-12-13 11:53:11 +01:00
|
|
|
static TreeItem item_name_0[] =
|
2023-12-12 11:36:42 +01:00
|
|
|
{
|
2023-12-15 11:02:53 +01:00
|
|
|
{ "A", NULL },
|
|
|
|
{ "B", NULL },
|
2023-12-12 11:36:42 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2023-12-13 11:53:11 +01:00
|
|
|
static TreeItem item_name_1[] =
|
2023-12-12 11:36:42 +01:00
|
|
|
{
|
2023-12-15 11:02:53 +01:00
|
|
|
{ "A", NULL },
|
|
|
|
{ "B", NULL },
|
|
|
|
{ "C", NULL },
|
2023-12-12 11:36:42 +01:00
|
|
|
{ NULL }
|
|
|
|
};
|
|
|
|
|
2023-12-14 12:15:49 +01:00
|
|
|
static TreeItem root[] =
|
2023-12-12 11:36:42 +01:00
|
|
|
{
|
2023-12-15 11:02:53 +01:00
|
|
|
{ "IT-0", item_name_0 },
|
|
|
|
{ "IT-1", item_name_1 },
|
2023-12-13 11:53:11 +01:00
|
|
|
{ NULL }
|
2023-12-12 11:36:42 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
|
|
|
create_model (void)
|
|
|
|
{
|
|
|
|
GtkTreeStore *model;
|
|
|
|
GtkTreeIter iter;
|
2023-12-14 12:15:49 +01:00
|
|
|
TreeItem *item_0 = root;
|
2023-12-12 11:36:42 +01:00
|
|
|
|
|
|
|
/* create tree store */
|
|
|
|
model = gtk_tree_store_new (NUM_COLUMNS,
|
|
|
|
G_TYPE_STRING,
|
|
|
|
G_TYPE_BOOLEAN);
|
|
|
|
|
|
|
|
/* add data to the tree store */
|
2023-12-13 11:53:11 +01:00
|
|
|
while (item_0->label)
|
2023-12-12 11:36:42 +01:00
|
|
|
{
|
2023-12-13 11:53:11 +01:00
|
|
|
TreeItem *item_1 = item_0->children;
|
2023-12-12 11:36:42 +01:00
|
|
|
|
|
|
|
gtk_tree_store_append (model, &iter, NULL);
|
|
|
|
gtk_tree_store_set (model, &iter,
|
2023-12-13 11:53:11 +01:00
|
|
|
COLUMN_0, item_0->label,
|
|
|
|
COLUMN_1, FALSE,
|
2023-12-12 11:36:42 +01:00
|
|
|
-1);
|
|
|
|
|
|
|
|
/* add children */
|
2023-12-13 11:53:11 +01:00
|
|
|
while (item_1->label)
|
2023-12-12 11:36:42 +01:00
|
|
|
{
|
|
|
|
GtkTreeIter child_iter;
|
|
|
|
|
|
|
|
gtk_tree_store_append (model, &child_iter, &iter);
|
|
|
|
gtk_tree_store_set (model, &child_iter,
|
2023-12-13 11:53:11 +01:00
|
|
|
COLUMN_0, item_1->label,
|
2023-12-15 11:02:53 +01:00
|
|
|
COLUMN_1, item_1->label, // AA,
|
2023-12-12 11:36:42 +01:00
|
|
|
-1);
|
|
|
|
|
2023-12-13 11:53:11 +01:00
|
|
|
item_1++;
|
2023-12-12 11:36:42 +01:00
|
|
|
}
|
|
|
|
|
2023-12-13 11:53:11 +01:00
|
|
|
item_0++;
|
2023-12-12 11:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (model);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_columns (GtkTreeView *treeview)
|
|
|
|
{
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
2023-12-15 10:18:09 +01:00
|
|
|
renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL);
|
2023-12-15 10:12:13 +01:00
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1,
|
|
|
|
"Col 0", renderer, "text", COLUMN_0, NULL);
|
2023-12-12 11:36:42 +01:00
|
|
|
|
2023-12-15 10:18:09 +01:00
|
|
|
renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL);
|
2023-12-15 10:12:13 +01:00
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1,
|
2023-12-15 10:23:47 +01:00
|
|
|
"Col 1", renderer, "text", COLUMN_1, NULL);
|
2023-12-12 11:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
|
|
|
do_tree_store (GtkWidget *do_widget)
|
|
|
|
{
|
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *treeview;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
/* create window, etc */
|
|
|
|
window = gtk_window_new ();
|
2023-12-12 18:40:36 +01:00
|
|
|
//gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
// gtk_widget_get_display (do_widget));
|
2023-12-12 11:36:42 +01:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Tree Store");
|
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
|
|
|
|
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
|
|
|
gtk_widget_set_margin_start (vbox, 8);
|
|
|
|
gtk_widget_set_margin_end (vbox, 8);
|
|
|
|
gtk_widget_set_margin_top (vbox, 8);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 8);
|
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
|
|
|
|
2023-12-15 10:12:13 +01:00
|
|
|
gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Learning GTK trees"));
|
2023-12-12 11:36:42 +01:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new ();
|
|
|
|
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
|
|
|
gtk_box_append (GTK_BOX (vbox), sw);
|
|
|
|
|
|
|
|
/* create model */
|
|
|
|
model = create_model ();
|
|
|
|
|
|
|
|
/* create tree view */
|
|
|
|
treeview = gtk_tree_view_new_with_model (model);
|
|
|
|
gtk_widget_set_vexpand (treeview, TRUE);
|
|
|
|
g_object_unref (model);
|
|
|
|
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
|
|
|
GTK_SELECTION_MULTIPLE);
|
|
|
|
|
|
|
|
add_columns (GTK_TREE_VIEW (treeview));
|
|
|
|
|
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), treeview);
|
|
|
|
|
|
|
|
/* expand all rows after the treeview widget has been realized */
|
|
|
|
g_signal_connect (treeview, "realize",
|
|
|
|
G_CALLBACK (gtk_tree_view_expand_all), NULL);
|
2023-12-15 10:54:05 +01:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 200, 250);
|
2023-12-12 11:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_widget_get_visible (window))
|
|
|
|
gtk_widget_set_visible (window, TRUE);
|
|
|
|
else
|
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2023-12-12 18:40:36 +01:00
|
|
|
|
2023-12-12 11:36:42 +01:00
|
|
|
return window;
|
|
|
|
}
|