2024-04-27 16:16:21 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <gtk-4.0/gtk/gtk.h>
|
2024-05-08 07:50:04 +02:00
|
|
|
|
2024-04-29 23:43:04 +02:00
|
|
|
#include "warm.h"
|
|
|
|
#include "cold.h"
|
2024-05-10 06:19:20 +02:00
|
|
|
#include "display.h"
|
|
|
|
#include "contain.h"
|
2024-05-08 23:43:23 +02:00
|
|
|
#include "texts.h"
|
2024-04-29 23:43:04 +02:00
|
|
|
|
2024-04-30 18:59:44 +02:00
|
|
|
// https://docs.gtk.org/gtk4/visual_index.html < widgets gallery
|
2024-05-10 23:14:45 +02:00
|
|
|
// https://docs.gtk.org/gtk4/section-text-widget.html
|
2024-05-08 23:43:23 +02:00
|
|
|
// https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management
|
2024-05-06 23:29:54 +02:00
|
|
|
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
|
|
|
|
|
2024-05-08 23:43:23 +02:00
|
|
|
|
2024-05-16 17:20:44 +02:00
|
|
|
static struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
|
|
|
|
2024-05-17 09:05:46 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-05-17 10:06:06 +02:00
|
|
|
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);
|
|
|
|
if (row != NULL) {
|
|
|
|
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
|
|
|
|
GtkWidget *expander = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_expander_set_label (GTK_EXPANDER (expander), text);
|
|
|
|
// g_signal_handlers_disconnect_by_func(expander, G_CALLBACK(on_tree_expander_toggled), row);
|
|
|
|
// 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 content is [%s] and expander is [%d]\n", text, is_expanded);
|
|
|
|
} else printf("[on_experimental_tree_bind_factory] row == NULL\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void on_experimental_tree_setup_factory (GtkSignalListItemFactory *factory,
|
|
|
|
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 GListModel* get_experimental_tree_children_model (struct TreeNode_t *parent){
|
2024-05-16 17:20:44 +02:00
|
|
|
GtkStringList *list = NULL;
|
|
|
|
if (parent) {
|
2024-05-17 10:06:06 +02:00
|
|
|
printf("[get_experimental_tree_children_model] here is %s content : ", parent->text);
|
2024-05-16 17:20:44 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-05-17 10:06:06 +02:00
|
|
|
static GListModel* experimental_tree_create_model (GObject *item, gpointer root){
|
2024-05-16 17:20:44 +02:00
|
|
|
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));
|
2024-05-17 10:06:06 +02:00
|
|
|
printf(">>> %s\n",string);
|
2024-05-16 17:20:44 +02:00
|
|
|
while (cur) {
|
|
|
|
if (strcmp(string, cur->text) == 0) break;
|
|
|
|
cur = cur->next;
|
|
|
|
if (cur == NULL) {cur = parent->child; parent = cur;}
|
|
|
|
}
|
2024-05-17 10:06:06 +02:00
|
|
|
printf("[experimental_tree_create_model] looked for %s in %s item\n", cur->text, string);
|
|
|
|
return get_experimental_tree_children_model (cur);
|
2024-05-15 11:41:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void create_experimental_tree (GtkBox *experimental_box){
|
2024-05-16 17:29:11 +02:00
|
|
|
struct TreeNode_t *tree_root = create_tree_node("hello");
|
2024-05-17 09:05:46 +02:00
|
|
|
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);
|
2024-05-16 17:29:11 +02:00
|
|
|
|
|
|
|
GtkStringList *model = gtk_string_list_new(NULL);
|
|
|
|
gtk_string_list_append (model, tree_root->text);
|
2024-05-17 09:05:46 +02:00
|
|
|
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
2024-05-15 11:41:58 +02:00
|
|
|
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);
|
2024-05-17 10:06:06 +02:00
|
|
|
printf("> %s > %s > %s\n", tree_root->text, it_s_me->text, remember->text);
|
2024-05-15 06:46:11 +02:00
|
|
|
|
2024-05-16 17:29:11 +02:00
|
|
|
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
|
|
|
G_LIST_MODEL (model),
|
|
|
|
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
|
|
|
FALSE, // autoexpand
|
2024-05-17 10:06:06 +02:00
|
|
|
(GtkTreeListModelCreateModelFunc) experimental_tree_create_model,
|
2024-05-16 17:29:11 +02:00
|
|
|
tree_root,
|
|
|
|
NULL // (GDestroyNotify) free_tree_node
|
|
|
|
);
|
2024-05-17 09:05:46 +02:00
|
|
|
|
2024-05-16 17:29:11 +02:00
|
|
|
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);
|
2024-05-16 17:40:03 +02:00
|
|
|
|
|
|
|
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model),
|
2024-05-17 09:05:46 +02:00
|
|
|
GTK_LIST_ITEM_FACTORY (factory));
|
2024-05-16 17:40:03 +02:00
|
|
|
|
2024-05-17 09:05:46 +02:00
|
|
|
gtk_box_append(experimental_box, list_view);
|
2024-05-16 17:40:03 +02:00
|
|
|
|
2024-05-17 09:05:46 +02:00
|
|
|
// gtk_widget_set_visible(GTK_WIDGET(experimental_box), TRUE);
|
|
|
|
// gtk_widget_set_visible(GTK_WIDGET(list_view), TRUE);
|
2024-05-15 06:46:11 +02:00
|
|
|
}
|
|
|
|
|
2024-05-17 10:06:06 +02:00
|
|
|
/*
|
|
|
|
[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
|
|
|
|
*/
|