R E C U R S I V E T R E E (cleaning)

This commit is contained in:
Jean Sirmai 2023-12-18 18:48:14 +01:00
parent 4e616b6381
commit 705af8c187
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 14 additions and 89 deletions

View File

@ -72,22 +72,14 @@ enum
};
/* tree data */
static TreeItem N[] = { NULL };
static TreeItem M[] = { NULL };
static TreeItem L[] = {{ "M", M }, { "N", N }, { NULL }};
static TreeItem K[] = { NULL };
static TreeItem J[] = {{ "L", L }, { NULL }};
static TreeItem I[] = { NULL };
static TreeItem H[] = { NULL };
static TreeItem G[] = { NULL };
static TreeItem F[] = { NULL };
static TreeItem E[] = { NULL };
static TreeItem D[] = {{ "I", I }, { "J", J }, { "K", K }, { NULL }};
static TreeItem C[] = {{ "H", H }, { NULL }};
static TreeItem B[] = {{ "E", E }, { "F", F }, { "G", G }, { NULL }};
static TreeItem A[] = {{ "C", C }, { "D", D }, { NULL }};
static TreeItem R[] = {{ "A", A }, { "B", B }, { NULL }}; // ROOT
static TreeItem O[] = {{ "R", R }, { NULL }}; // Artefact added for symmetry
static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {NULL};
static TreeItem I[] = {NULL}, K[] = {NULL}, N[] = {NULL}, M[] = {NULL};
static TreeItem L[] = {{"M", M}, {"N", N}, {NULL }}, J[] = {{"L", L}, {NULL}};
static TreeItem D[] = {{"I", I}, {"J", J}, {"K", K}, {NULL}};
static TreeItem C[] = {{"F", F}, {"G", G}, {"H", H}, {NULL}};
static TreeItem A[] = {{"D", D}, {NULL}}, B[] = {{"E", E}, {NULL}};
static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}};
static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
TreeItem *current_item,
@ -118,71 +110,6 @@ static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
return NULL;
}
static void create_node (GtkTreeStore *model,
GtkTreeIter *iter_children,
TreeItem *item_children,
GtkTreeIter *iter_parent)
{
gtk_tree_store_append (model, iter_children, iter_parent);
gtk_tree_store_set (model, iter_children, COLUMN_0, item_children->label, -1);
}
static GtkTreeModel *
create_model (void)
{
TreeItem *item_0, *item_1, *item_2, *item_3, *item_4;
GtkTreeIter iter_0, iter_1, iter_2, iter_3, iter_4;
GtkTreeStore *model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING);
if (O->children) {
item_0 = O->children;
while (item_0->label) {
create_node(model, &iter_0, item_0, NULL);
if (item_0->children) {
item_1 = item_0->children;
while (item_1->label) {
create_node(model, &iter_1, item_1, &iter_0);
if (item_1->children) {
item_2 = item_1->children;
while (item_2->label) {
create_node(model, &iter_2, item_2, &iter_1);
if (item_2->children) {
item_3 = item_2->children;
while (item_3->label) {
create_node(model, &iter_3, item_3, &iter_2);
if (item_3->children) {
item_4 = item_3->children;
while (item_4->label) {
create_node(model, &iter_4, item_4, &iter_3);
item_4++;
}
}
item_3++;
}
}
item_2++;
}
}
item_1++;
}
}
item_0++;
}
}
return GTK_TREE_MODEL (model);
}
GtkWidget *
do_tree_store (GtkWidget *do_widget)
{
@ -194,12 +121,10 @@ do_tree_store (GtkWidget *do_widget)
GtkWidget *sw;
GtkWidget *treeview;
GtkTreeModel *tree_model;
GtkTreeStore *tree_store;
GtkTreeStore *tree_store = NULL;
/* create window, etc */
window = gtk_window_new ();
//gtk_window_set_display (GTK_WINDOW (window),
// gtk_widget_get_display (do_widget));
gtk_window_set_title (GTK_WINDOW (window), "Tree Store");
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
@ -220,18 +145,18 @@ do_tree_store (GtkWidget *do_widget)
gtk_box_append (GTK_BOX (vbox), sw);
/* create tree_model */
tree_model = create_node_recursive (tree_store, R, NULL, 0);
tree_model = create_node_recursive (tree_store, O, NULL, 0);
/* create tree view */
treeview = gtk_tree_view_new_with_model (tree_model);
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE);
gtk_widget_set_vexpand (treeview, TRUE);
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
g_object_unref (tree_model);
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
GTK_SELECTION_MULTIPLE);
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
g_object_unref (tree_model);
GtkCellRenderer *renderer;
renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL);
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1,
"Col 0", renderer, "text", COLUMN_0, NULL);
@ -241,7 +166,7 @@ do_tree_store (GtkWidget *do_widget)
/* expand all rows after the treeview widget has been realized */
g_signal_connect (treeview, "realize",
G_CALLBACK (gtk_tree_view_expand_all), NULL);
gtk_window_set_default_size (GTK_WINDOW (window), 200, 380);
gtk_window_set_default_size (GTK_WINDOW (window), 200, 400);
}
if (!gtk_widget_get_visible (window))