Ça y est: j'ai tout ce que je dois comprendre sur un seul écran

This commit is contained in:
Jean Sirmai 2024-05-17 10:06:06 +02:00
parent 2bd8febffc
commit 7d1bc83d56
Signed by: jean
GPG Key ID: FB3115C340E057E3
3 changed files with 48 additions and 30 deletions

78
hot.c
View File

@ -35,35 +35,6 @@ static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child)
} else parent->child = child;
}
static GListModel* ui_experimental_tree_get_children_model (struct TreeNode_t *parent){
GtkStringList *list = NULL;
if (parent) {
printf("[ui_experimental_tree_get_children_model] here is %s content : ", parent->text);
struct TreeNode_t *child = parent->child;
if (child) {list = gtk_string_list_new(NULL);}
while(child) {
gtk_string_list_append(list, child->text);
printf("%s ", child->text);
child = child->next;
}
}
printf("\n");
return G_LIST_MODEL(list);
}
static GListModel* ui_experimental_tree_create_model_func (GObject *item, gpointer root){
struct TreeNode_t *cur = (struct TreeNode_t *)root;
struct TreeNode_t *parent = root;
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
while (cur) {
if (strcmp(string, cur->text) == 0) break;
cur = cur->next;
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);
}
static void on_experimental_tree_bind_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
GtkListItem *list_item = GTK_LIST_ITEM (object);
GtkTreeListRow *row = gtk_list_item_get_item (list_item);
@ -86,6 +57,36 @@ void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
printf("[on_experimental_tree_setup_factory] here is an expander\n");
}
static GListModel* get_experimental_tree_children_model (struct TreeNode_t *parent){
GtkStringList *list = NULL;
if (parent) {
printf("[get_experimental_tree_children_model] here is %s content : ", parent->text);
struct TreeNode_t *child = parent->child;
if (child) {list = gtk_string_list_new(NULL);}
while(child) {
gtk_string_list_append(list, child->text);
printf("%s ", child->text);
child = child->next;
}
}
printf("\n");
return G_LIST_MODEL(list);
}
static GListModel* experimental_tree_create_model (GObject *item, gpointer root){
struct TreeNode_t *cur = (struct TreeNode_t *)root;
struct TreeNode_t *parent = root;
const gchar *string = gtk_string_object_get_string (GTK_STRING_OBJECT(item));
printf(">>> %s\n",string);
while (cur) {
if (strcmp(string, cur->text) == 0) break;
cur = cur->next;
if (cur == NULL) {cur = parent->child; parent = cur;}
}
printf("[experimental_tree_create_model] looked for %s in %s item\n", cur->text, string);
return get_experimental_tree_children_model (cur);
}
void create_experimental_tree (GtkBox *experimental_box){
struct TreeNode_t *tree_root = create_tree_node("hello");
struct TreeNode_t *it_s_me = create_tree_node("it's me"); add_child_node(tree_root, it_s_me);
@ -96,12 +97,13 @@ void create_experimental_tree (GtkBox *experimental_box){
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);
printf("> %s > %s > %s\n", tree_root->text, it_s_me->text, remember->text);
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
G_LIST_MODEL (model),
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
FALSE, // autoexpand
(GtkTreeListModelCreateModelFunc)ui_experimental_tree_create_model_func,
(GtkTreeListModelCreateModelFunc) experimental_tree_create_model,
tree_root,
NULL // (GDestroyNotify) free_tree_node
);
@ -119,3 +121,19 @@ void create_experimental_tree (GtkBox *experimental_box){
// gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
}
/*
[on_experimental_tree_setup_factory] here is an expander
[on_experimental_tree_bind_factory] row content is [hello] and expander is [0]
[on_tree_setup_factory] here is an expander
[on_tree_bind_factory] here is Root content and expander is 0
[ui_tree_create_model_func] looked for Root in Root item
[ui_tree_get_children_model] here is Root content : ATP ADP AMP
[on_tree_setup_factory] here is an expander
[on_tree_bind_factory] here is ATP content and expander is 0
[on_tree_setup_factory] here is an expander
[on_tree_bind_factory] here is ADP content and expander is 0
[on_tree_setup_factory] here is an expander
[on_tree_bind_factory] here is AMP content and expander is 0
*/

BIN
hot.o

Binary file not shown.

BIN
myprogram

Binary file not shown.