WIP: Construction itérative de l'arbre. Préparation de la construction récursive.
This commit is contained in:
parent
0ed20386a7
commit
9da50fa49b
|
@ -23,6 +23,10 @@
|
|||
/* GtkTreeViewColumn, GtkTreeSelection, GtkTreeModel, GtkTreeView drag-and-drop, GtkTreeSortable, GtkTreeModelSort, GtkListStore, */
|
||||
/* GtkTreeStore, GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf, GtkCellRendererText, GtkCellRendererToggle */
|
||||
/* */
|
||||
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html#gtk-tree-view-get-path-at-pos */
|
||||
/* Finds the path at the point (x , y ), relative to bin_window coordinates. */
|
||||
/* Widget-relative coordinates must be converted using gtk_tree_view_convert_widget_to_bin_window_coords(). */
|
||||
/* */
|
||||
/* https://www.gnu.org/software/guile-gnome/docs/gtk/html/GtkCellRenderer.html */
|
||||
/* */
|
||||
/*************************************************************************************************************************************/
|
||||
|
@ -35,7 +39,6 @@
|
|||
/* */
|
||||
/* gtk_tree_view_set_show_expanders (GTK_TREE_VIEW (treeview), TRUE); */
|
||||
/* gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), TRUE); */
|
||||
/* GTK_TREE_VIEW (treeview) expanders are shown; */
|
||||
/* gtk_widget_set_vexpand (treeview, TRUE); */
|
||||
/* gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE); */
|
||||
/* */
|
||||
|
@ -69,8 +72,11 @@ 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[] = { NULL };
|
||||
static TreeItem J[] = {{ "L", L }, { NULL }};
|
||||
static TreeItem I[] = { NULL };
|
||||
static TreeItem H[] = { NULL };
|
||||
static TreeItem G[] = { NULL };
|
||||
|
@ -80,10 +86,10 @@ 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 }};
|
||||
static TreeItem R[] = {{ "A", A }, { "B", B }, { NULL }}; // ROOT
|
||||
static TreeItem O[] = {{ "R", R }, { NULL }}; // Artefact added for symmetry
|
||||
|
||||
static void iterate_node(GtkTreeStore *model,
|
||||
static void create_node(GtkTreeStore *model,
|
||||
GtkTreeIter *iter_children,
|
||||
TreeItem *item_children,
|
||||
GtkTreeIter *iter_parent)
|
||||
|
@ -95,8 +101,8 @@ static void iterate_node(GtkTreeStore *model,
|
|||
static GtkTreeModel *
|
||||
create_model (void)
|
||||
{
|
||||
TreeItem *item_0, *item_1, *item_2;
|
||||
GtkTreeIter iter_0, iter_1, iter_2;
|
||||
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);
|
||||
|
||||
|
@ -104,19 +110,37 @@ create_model (void)
|
|||
item_0 = O->children;
|
||||
|
||||
while (item_0->label) {
|
||||
iterate_node(model, &iter_0, item_0, NULL);
|
||||
create_node(model, &iter_0, item_0, NULL);
|
||||
|
||||
if (item_0->children) {
|
||||
item_1 = item_0->children;
|
||||
|
||||
while (item_1->label) {
|
||||
iterate_node(model, &iter_1, item_1, &iter_0);
|
||||
create_node(model, &iter_1, item_1, &iter_0);
|
||||
|
||||
if (item_1->children) {
|
||||
item_2 = item_1->children;
|
||||
|
||||
while (item_2->label) {
|
||||
iterate_node(model, &iter_2, item_2, &iter_1);
|
||||
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++;
|
||||
}
|
||||
}
|
||||
|
@ -130,21 +154,6 @@ create_model (void)
|
|||
return GTK_TREE_MODEL (model);
|
||||
}
|
||||
|
||||
static void
|
||||
add_columns (GtkTreeView *treeview)
|
||||
{
|
||||
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);
|
||||
|
||||
/* WE DON'T NEED A SECOND COLUMN UNTILL WE WANT TO REPRESENT LEAVES */
|
||||
/* 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 1", renderer, "text", COLUMN_1, NULL); */
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
do_tree_store (GtkWidget *do_widget)
|
||||
{
|
||||
|
@ -186,19 +195,23 @@ do_tree_store (GtkWidget *do_widget)
|
|||
/* create tree view */
|
||||
treeview = gtk_tree_view_new_with_model (model);
|
||||
gtk_widget_set_vexpand (treeview, TRUE);
|
||||
if (1) gtk_tree_view_set_reorderable (GTK_TREE_VIEW (treeview), TRUE);
|
||||
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (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));
|
||||
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);
|
||||
|
||||
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);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 200, 330);
|
||||
gtk_window_set_default_size (GTK_WINDOW (window), 200, 380);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
|
|
Loading…
Reference in New Issue