diff --git a/hot.c b/hot.c index 47eb512..29a873b 100644 --- a/hot.c +++ b/hot.c @@ -15,6 +15,26 @@ static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;}; +static struct TreeNode_t *create_tree_node (const gchar* text){ + struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); + node->text = g_strdup(text); + node->child = NULL; // printf("create_tree_node %s\n", text); + return node; +} + +/*static void on_experimental_expander_toggled(GtkExpander *expander, gpointer user_data){ + gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander)); + printf("> %s\n", gtk_expander_get_label (user_data)); +}*/ + +static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){ + if (parent->child) { + struct TreeNode_t *cur = parent->child; + while (cur && cur->next) {cur = cur->next;} + cur->next = child; + } else parent->child = child; +} + static GListModel* ui_experimental_tree_get_children_model (struct TreeNode_t *parent){ GtkStringList *list = NULL; if (parent) { @@ -41,7 +61,7 @@ static GListModel* ui_experimental_tree_create_model_func (GObject *item, gpoint if (cur == NULL) {cur = parent->child; parent = cur;} } printf("[ui_experimental_tree_create_model_func] looked for %s in %s item\n", cur->text, string); - return ui_experimental_tree_get_children_model(cur); + return ui_experimental_tree_get_children_model (cur); } static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){ @@ -55,49 +75,25 @@ static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory // g_signal_connect(expander, "activate", G_CALLBACK(on_tree_expander_toggled), row); gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20); gboolean is_expanded = gtk_tree_list_row_get_expanded(row); - printf("[on_experimental_tree_bind_factory] row != NULL here is %s content and expander is %d\n", text, is_expanded); + printf("[on_experimental_tree_bind_factory] row content is [%s] and expander is [%d]\n", text, is_expanded); } else printf("[on_experimental_tree_bind_factory] row == NULL\n"); } -static void on_experimental_expander_toggled(GtkExpander *expander, gpointer user_data){ - gtk_expander_set_expanded (expander, gtk_expander_get_expanded (expander)); - printf("> %s\n", gtk_expander_get_label (user_data)); -} - void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory, - GObject* object, - gpointer user_data) -{ + GObject* object, gpointer user_data){ GtkWidget* expander = gtk_expander_new (NULL); gtk_list_item_set_child (GTK_LIST_ITEM(object), expander); printf("[on_experimental_tree_setup_factory] here is an expander\n"); } -static struct TreeNode_t *create_tree_node (const gchar* text){ - struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); - node->text = g_strdup(text); - node->child = NULL; - return node; -} - -static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){ - if (parent->child) { - struct TreeNode_t *cur = parent->child; - while (cur && cur->next) { - cur = cur->next; - } - cur->next = child; - } else parent->child = child; -} - void create_experimental_tree (GtkBox *experimental_box){ struct TreeNode_t *tree_root = create_tree_node("hello"); - struct TreeNode_t *child = create_tree_node("it's me"); - add_child_node(tree_root, child); + struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me); + struct TreeNode_t *remember = create_tree_node("remember"); add_child_node(it_s_me, remember); GtkStringList *model = gtk_string_list_new(NULL); gtk_string_list_append (model, tree_root->text); - GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new ()); + GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new()); g_signal_connect (factory, "setup", G_CALLBACK(on_experimental_tree_setup_factory), NULL); g_signal_connect (factory, "bind", G_CALLBACK(on_experimental_tree_bind_factory), NULL); @@ -109,15 +105,17 @@ void create_experimental_tree (GtkBox *experimental_box){ tree_root, NULL // (GDestroyNotify) free_tree_node ); + GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model)); gtk_single_selection_set_autoselect (selection_model, FALSE); gtk_single_selection_set_can_unselect (selection_model, TRUE); GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model), - GTK_LIST_ITEM_FACTORY (factory)); + GTK_LIST_ITEM_FACTORY (factory)); - gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE); - gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE); + gtk_box_append(experimental_box, list_view); +// gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE); +// gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE); } diff --git a/hot.o b/hot.o index c12e329..db54b64 100644 Binary files a/hot.o and b/hot.o differ diff --git a/myprogram b/myprogram index ad81fae..be6efbc 100755 Binary files a/myprogram and b/myprogram differ diff --git a/tree.c b/tree.c index 634a731..89730da 100644 --- a/tree.c +++ b/tree.c @@ -199,25 +199,15 @@ void ui_create_tree (GtkWidget *target_widget) assert(target_widget); - // AD HOC XXX & no free() - struct TreeNode_t *tree_root = create_tree_node("Root"); - struct TreeNode_t *ATP = create_tree_node("ATP"); - struct TreeNode_t *ADP = create_tree_node("ADP"); - struct TreeNode_t *AMP = create_tree_node("AMP"); - struct TreeNode_t *adenine = create_tree_node("adénine"); - struct TreeNode_t *ribose = create_tree_node("ribose"); - struct TreeNode_t *PO4H3_1 = create_tree_node("phosphate 1"); - struct TreeNode_t *PO4H3_2 = create_tree_node("phosphate 2"); - struct TreeNode_t *PO4H3_3 = create_tree_node("phosphate 3"); - - add_child_node(tree_root, ATP); - add_child_node(tree_root, ADP); - add_child_node(tree_root, AMP); - add_child_node(ATP, adenine); - add_child_node(adenine, ribose); - add_child_node(ribose, PO4H3_1); - add_child_node(PO4H3_1, PO4H3_2); - add_child_node(PO4H3_3, PO4H3_3); + struct TreeNode_t *tree_root = create_tree_node("Root"); // AD HOC XXX & no free() + struct TreeNode_t *ATP = create_tree_node("ATP"); add_child_node(tree_root, ATP); + struct TreeNode_t *ADP = create_tree_node("ADP"); add_child_node(tree_root, ADP); + struct TreeNode_t *AMP = create_tree_node("AMP"); add_child_node(tree_root, AMP); + struct TreeNode_t *adenine = create_tree_node("adénine"); add_child_node(ATP, adenine); + struct TreeNode_t *ribose = create_tree_node("ribose"); add_child_node(adenine, ribose); + struct TreeNode_t *PO4H3_1 = create_tree_node("phosphate 1"); add_child_node(ribose, PO4H3_1); + struct TreeNode_t *PO4H3_2 = create_tree_node("phosphate 2"); add_child_node(PO4H3_1, PO4H3_2); + struct TreeNode_t *PO4H3_3 = create_tree_node("phosphate 3"); add_child_node(PO4H3_2, PO4H3_3); model = gtk_string_list_new(NULL); gtk_string_list_append(model, tree_root->text); diff --git a/tree.o b/tree.o index 67e6b4b..d82b4db 100644 Binary files a/tree.o and b/tree.o differ