R E C U R S I V E T R E E (1st version) OK
This commit is contained in:
parent
6724424219
commit
4e616b6381
|
@ -89,22 +89,33 @@ 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 GtkTreeStore create_node_recursive (GtkTreeStore *model, TreeItem *current_item)
|
||||
static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
|
||||
TreeItem *current_item,
|
||||
GtkTreeIter *iter_parent,
|
||||
int depth)
|
||||
{
|
||||
TreeItem *item_children;
|
||||
GtkTreeIter iter_children, iter_parent;
|
||||
GtkTreeIter iter;
|
||||
|
||||
if (current_item->children) {
|
||||
item_children = current_item->children;
|
||||
if (model == NULL)
|
||||
model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING);
|
||||
|
||||
while (item_children->label) {
|
||||
gtk_tree_store_append (model, &iter_children, &iter_parent);
|
||||
gtk_tree_store_set (model, &iter_children, COLUMN_0, item_children->label, -1);
|
||||
item_children++;
|
||||
create_node_recursive (model, item_children);
|
||||
}
|
||||
while (current_item->label) {
|
||||
if (0) printf("[%d] Current label : %s\n", depth, current_item->label);
|
||||
gtk_tree_store_append (model, &iter, iter_parent);
|
||||
gtk_tree_store_set (model, &iter, COLUMN_0, current_item->label, -1);
|
||||
|
||||
if (current_item->children)
|
||||
create_node_recursive (model, current_item->children, &iter, depth+1);
|
||||
else
|
||||
break;
|
||||
|
||||
current_item++;
|
||||
}
|
||||
return *model;
|
||||
|
||||
if (depth == 0)
|
||||
return GTK_TREE_MODEL(model);
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void create_node (GtkTreeStore *model,
|
||||
|
@ -209,9 +220,7 @@ do_tree_store (GtkWidget *do_widget)
|
|||
gtk_box_append (GTK_BOX (vbox), sw);
|
||||
|
||||
/* create tree_model */
|
||||
tree_model = create_model (); // GtkTreeStore *model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING);
|
||||
/* tree_store = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); */
|
||||
/* tree_model = create_node_recursive (*tree_store, O); */
|
||||
tree_model = create_node_recursive (tree_store, R, NULL, 0);
|
||||
|
||||
/* create tree view */
|
||||
treeview = gtk_tree_view_new_with_model (tree_model);
|
||||
|
|
Loading…
Reference in New Issue