WIP: Ok (cleaned) mais erreur de segmentation à la fermeture de la fenêtre
This commit is contained in:
parent
9e1d54d469
commit
a8477025fe
Binary file not shown.
28
main.c
28
main.c
|
@ -12,6 +12,8 @@
|
|||
#include <glib-2.0/glib.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
#define verb 0
|
||||
|
||||
// Simplified TreeNode structure for demonstration purposes
|
||||
struct TreeNode_t
|
||||
{
|
||||
|
@ -48,7 +50,7 @@ void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child)
|
|||
}
|
||||
}
|
||||
|
||||
static insert_data() // (TreeNode_t *root)
|
||||
static void insert_data (struct TreeNode_t *root)
|
||||
{
|
||||
struct TreeNode_t *A = create_tree_node("A"); add_child_node(root, A);
|
||||
struct TreeNode_t *B = create_tree_node("B"); add_child_node(A, B);
|
||||
|
@ -89,7 +91,7 @@ GListModel* get_children_model (struct TreeNode_t *parent)
|
|||
GtkStringList *list = NULL;
|
||||
|
||||
if (parent) {
|
||||
printf("[get_children_model] here is %s content : ", parent->text);
|
||||
if (verb) printf("[get_children_model] here is %s content : ", parent->text);
|
||||
|
||||
child = parent->child;
|
||||
|
||||
|
@ -98,11 +100,11 @@ GListModel* get_children_model (struct TreeNode_t *parent)
|
|||
}
|
||||
while(child) {
|
||||
gtk_string_list_append(list, child->text);
|
||||
printf("%s ", child->text);
|
||||
if (verb) printf("%s ", child->text);
|
||||
child = child->next;
|
||||
}
|
||||
}
|
||||
printf("\n");
|
||||
if (verb) printf("\n");
|
||||
|
||||
return G_LIST_MODEL(list);
|
||||
}
|
||||
|
@ -114,11 +116,11 @@ GListModel* create_model_func(GObject *item, gpointer user_data)
|
|||
struct TreeNode_t *parent = NULL;
|
||||
struct TreeNode_t *res = NULL;
|
||||
|
||||
gchar *string = gtk_string_object_get_string(GTK_STRING_OBJECT(item));
|
||||
const char* string = gtk_string_object_get_string(GTK_STRING_OBJECT(item));
|
||||
|
||||
parent = root;
|
||||
while (cur) {
|
||||
if (strcmp(string, cur->text) == NULL) {
|
||||
if (! strcmp(string, cur->text)) {
|
||||
res = cur;
|
||||
break;
|
||||
}
|
||||
|
@ -130,7 +132,7 @@ GListModel* create_model_func(GObject *item, gpointer user_data)
|
|||
}
|
||||
}
|
||||
|
||||
printf("[create_model_func] here is %s item\n", string);
|
||||
if (verb) printf("[create_model_func] here is %s item\n", string);
|
||||
|
||||
return get_children_model(cur);
|
||||
}
|
||||
|
@ -148,7 +150,7 @@ void on_setup_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpoi
|
|||
{
|
||||
GtkWidget* expander = gtk_expander_new (NULL);
|
||||
gtk_list_item_set_child (list_item, expander);
|
||||
printf("[on_setup_factory] here is an expander\n");
|
||||
if (verb) printf("[on_setup_factory] here is an expander\n");
|
||||
}
|
||||
|
||||
void on_bind_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpointer user_data)
|
||||
|
@ -172,14 +174,14 @@ void on_bind_factory (GtkListItemFactory *factory, GtkListItem *list_item, gpoin
|
|||
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
|
||||
//gtk_tree_list_row_set_expanded(row, !is_expanded);
|
||||
} else {
|
||||
printf("[on_bind_factory] here is NON %s content\n", text);
|
||||
if (verb) printf("[on_bind_factory] here is NON %s content\n", text);
|
||||
}
|
||||
}
|
||||
|
||||
void on_selection_changed (GtkSelectionModel* self, guint position,
|
||||
guint n_items, gpointer user_data)
|
||||
{
|
||||
printf("Cc\n");
|
||||
if (verb) printf("Cc\n");
|
||||
}
|
||||
|
||||
// Application activation callback
|
||||
|
@ -207,7 +209,7 @@ void app_activate (GApplication *app, gpointer user_data)
|
|||
(GDestroyNotify)g_object_unref //(GDestroyNotify)free_tree_node
|
||||
);
|
||||
|
||||
GtkSingleSelection *selection_model = gtk_single_selection_new (
|
||||
GtkSingleSelection *selection_model = gtk_single_selection_new ( // GtkSelectionModel
|
||||
G_LIST_MODEL (tree_model));
|
||||
|
||||
gtk_single_selection_set_autoselect(selection_model, FALSE);
|
||||
|
@ -215,7 +217,7 @@ void app_activate (GApplication *app, gpointer user_data)
|
|||
g_signal_connect (selection_model, "selection-changed",
|
||||
G_CALLBACK(on_selection_changed), NULL);
|
||||
|
||||
GtkWidget *list_view = gtk_list_view_new (selection_model, factory);
|
||||
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL(selection_model), factory);
|
||||
|
||||
gtk_window_set_child(GTK_WINDOW(window), list_view);
|
||||
|
||||
|
@ -226,7 +228,7 @@ int main (int argc, char **argv)
|
|||
{
|
||||
// Create a simple tree structure
|
||||
root = create_tree_node("Root");
|
||||
insert_data();
|
||||
insert_data(root);
|
||||
|
||||
GtkApplication *app = gtk_application_new("org.gtk.example", G_APPLICATION_FLAGS_NONE);
|
||||
g_signal_connect(app, "activate", G_CALLBACK(app_activate), NULL);
|
||||
|
|
Loading…
Reference in New Issue