WIP: on simplifie avant de repartir.
This commit is contained in:
parent
b8fa3b1704
commit
fde2d4594f
|
@ -25,6 +25,7 @@
|
||||||
/* It provides a way to specify how temporary widgets should be configured for editing, get the new value, etc. */
|
/* It provides a way to specify how temporary widgets should be configured for editing, get the new value, etc. */
|
||||||
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
|
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
|
||||||
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ T R E E _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
|
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ T R E E _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
|
||||||
|
/* https://toshiocp.github.io/Gtk4-tutorial/sec29.html <<< TODO */
|
||||||
/* https://docs.gtk.org/gtk4/ */
|
/* https://docs.gtk.org/gtk4/ */
|
||||||
/* https://docs.gtk.org/gtk4/section-list-widget.html << (see below the "quick comparison chart of equivalent functionalities") */
|
/* https://docs.gtk.org/gtk4/section-list-widget.html << (see below the "quick comparison chart of equivalent functionalities") */
|
||||||
/* https://docs.gtk.org/gtk4/class.TreeListModel.html */
|
/* https://docs.gtk.org/gtk4/class.TreeListModel.html */
|
||||||
|
@ -41,6 +42,9 @@
|
||||||
/* */
|
/* */
|
||||||
/****************************************************************************************************************************************/
|
/****************************************************************************************************************************************/
|
||||||
|
|
||||||
|
// ? utile ?
|
||||||
|
// gtk_tree_model_foreach (model, TRUE, my_user_data); https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreeModelForeachFunc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* ... Finally here’s a quick comparison chart of equivalent functionalitqy
|
/* ... Finally here’s a quick comparison chart of equivalent functionalitqy
|
||||||
|
@ -104,6 +108,10 @@
|
||||||
*
|
*
|
||||||
* Widgets are styleable using GTK CSS. Use the .rich-list style class.
|
* Widgets are styleable using GTK CSS. Use the .rich-list style class.
|
||||||
*
|
*
|
||||||
|
*
|
||||||
|
* GListModel is an interface that represents a mutable list of GObjects.
|
||||||
|
* https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html
|
||||||
|
*
|
||||||
*............................................................................*/
|
*............................................................................*/
|
||||||
|
|
||||||
|
|
||||||
|
@ -111,6 +119,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "custom-list.h"
|
#include "custom-list.h"
|
||||||
|
#include <gio/gio.h>
|
||||||
|
|
||||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||||
|
|
||||||
|
@ -120,104 +129,6 @@ enum
|
||||||
NUM_COLUMNS
|
NUM_COLUMNS
|
||||||
};
|
};
|
||||||
|
|
||||||
static GObjectClass *parent_class = NULL; /* GObject stuff - nothing to worry about */
|
|
||||||
static void custom_list_finalize (GObject *object);
|
|
||||||
|
|
||||||
static void
|
|
||||||
custom_list_class_init (CustomListClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class;
|
|
||||||
|
|
||||||
parent_class = (GObjectClass*) g_type_class_peek_parent (klass);
|
|
||||||
object_class = (GObjectClass*) klass;
|
|
||||||
|
|
||||||
|
|
||||||
object_class->finalize = custom_list_finalize;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
custom_list_tree_model_init (GtkTreeModelIface *iface)
|
|
||||||
{
|
|
||||||
/* Here we override the GtkTreeModel
|
|
||||||
* interface functions that we implement */
|
|
||||||
iface->get_flags = NULL; // custom_list_get_flags;
|
|
||||||
iface->get_n_columns = NULL; // custom_list_get_n_columns;
|
|
||||||
iface->get_column_type = NULL; // custom_list_get_column_type;
|
|
||||||
iface->get_iter = NULL; // custom_list_get_iter;
|
|
||||||
iface->get_path = NULL; // custom_list_get_path;
|
|
||||||
iface->get_value = NULL; // custom_list_get_value;
|
|
||||||
iface->iter_next = NULL; // custom_list_iter_next;
|
|
||||||
iface->iter_children = NULL; // custom_list_iter_children;
|
|
||||||
iface->iter_has_child = NULL; // custom_list_iter_has_child;
|
|
||||||
iface->iter_n_children = NULL; // custom_list_iter_n_children;
|
|
||||||
iface->iter_nth_child = NULL; // custom_list_iter_nth_child;
|
|
||||||
iface->iter_parent = NULL; // custom_list_iter_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
// gtk_tree_model_foreach (model, TRUE, my_user_data); https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreeModelForeachFunc
|
|
||||||
static void iterating_a_model_in_a_depth_first_fashion (GtkTreeModel *model)
|
|
||||||
{
|
|
||||||
// gboolean (*GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
|
|
||||||
GtkTreeIter iter, iter_parent;
|
|
||||||
char *str_data;
|
|
||||||
int row_count = 0;
|
|
||||||
|
|
||||||
gtk_tree_model_get_iter_first (model, &iter);
|
|
||||||
gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1);
|
|
||||||
g_print ("first row %d: (%s)\n", row_count, str_data);
|
|
||||||
|
|
||||||
/* gtk_tree_model_iter_children (model, &iter_parent, &iter); */
|
|
||||||
/* gtk_tree_model_iter_children (model, &iter, &iter_parent); // Sets iter to point to the first child of parent. */
|
|
||||||
/* //gtk_tree_model_iter_next (model, &iter); */
|
|
||||||
/* gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); */
|
|
||||||
/* g_print ("next row %d: (%s) < False (should be 'A' <-- line 104)\n", row_count, str_data); */
|
|
||||||
|
|
||||||
/* while (valid) first row 0: (ROOT) next row 0: (D)*/
|
|
||||||
/* { */
|
|
||||||
/* char *str_data; */
|
|
||||||
/* // Make sure you terminate calls to gtk_tree_model_get() with a “-1” value */
|
|
||||||
/* gtk_tree_model_get (model, &iter, STRING_COLUMN, &str_data, -1); */
|
|
||||||
/* g_print ("Row %d: (%s) <> gtk_tree_model_get_iter_first (model, &iter) &iter = [%s] (line 67) ", row_count, str_data, "xxx");//&iter); */
|
|
||||||
/* g_free (str_data); */
|
|
||||||
/* valid = gtk_tree_model_iter_next (model, &iter); */
|
|
||||||
/* // valid = gtk_tree_model_iter_children (model, &iter, parent); << how to get the parent ?? */
|
|
||||||
/* g_print ("valid = %d = gtk_tree_model_iter_next (model, &iter) %s (line 69)\n",\ */
|
|
||||||
/* valid, gtk_tree_model_get_string_from_iter (model, &iter)); */
|
|
||||||
/* row_count++; */
|
|
||||||
/* } */
|
|
||||||
}
|
|
||||||
|
|
||||||
static void /* https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreePath-struct and #gtk-tree-row-reference-new */
|
|
||||||
gtk_tree_model_get_data_from_iter (GtkTreeModel *my_tree_model,
|
|
||||||
GtkCellEditable *cell_editable,
|
|
||||||
GtkTreeIter *my_iter,
|
|
||||||
GdkEvent *event,
|
|
||||||
GtkTreePath *my_path)
|
|
||||||
{
|
|
||||||
char *str_data;
|
|
||||||
|
|
||||||
gtk_tree_model_get_iter (my_tree_model, &my_iter, my_path);
|
|
||||||
gtk_tree_model_get (my_tree_model, &my_iter, STRING_COLUMN, &str_data, -1);
|
|
||||||
g_print ("row from iter at [ %s ] = '%s'\n",\
|
|
||||||
gtk_tree_model_get_string_from_iter(my_tree_model, &my_iter), str_data);
|
|
||||||
gtk_tree_path_free (my_path);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void /* https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreePath-struct and #gtk-tree-row-reference-new */
|
|
||||||
gtk_tree_model_edit_a_cell (GtkTreeModel *my_tree_model,
|
|
||||||
GtkCellEditable *cell_editable,
|
|
||||||
GtkTreeIter *my_iter,
|
|
||||||
GdkEvent *event,
|
|
||||||
GtkTreePath *my_path)
|
|
||||||
{
|
|
||||||
gtk_tree_model_get (my_tree_model, my_iter); // Gets the value of one or more cells in the row referenced by iter
|
|
||||||
gtk_cell_editable_start_editing (cell_editable, event); // Begins editing on a cell_editable .
|
|
||||||
gtk_cell_editable_editing_done (cell_editable); // Emits the “editing-done” signal.
|
|
||||||
gtk_tree_model_row_deleted (my_tree_model, my_path); // Emits the “row-deleted” signal on tree_model .
|
|
||||||
gtk_tree_model_row_inserted (my_tree_model, my_path, my_iter); // Emits the “row-inserted” signal on tree_model .
|
|
||||||
}
|
|
||||||
|
|
||||||
/* TreeItem structure */
|
/* TreeItem structure */
|
||||||
typedef struct _TreeItem TreeItem;
|
typedef struct _TreeItem TreeItem;
|
||||||
|
@ -268,40 +179,6 @@ static GtkTreeModel *create_node_recursive (GtkTreeStore *model,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* static GListModel *create_node_recursive (GTreeListModel *model, */
|
|
||||||
/* guint current_position, */
|
|
||||||
/* TreeItem *current_item, */
|
|
||||||
/* guint parent_position, */
|
|
||||||
/* int depth) */
|
|
||||||
/* { */
|
|
||||||
/* if (model == NULL) */
|
|
||||||
/* model = gtk_tree_list_model_new (GListModel* root, */
|
|
||||||
/* gboolean passthrough, */
|
|
||||||
/* gboolean autoexpand, */
|
|
||||||
/* GtkTreeListModelCreateModelFunc create_func, */
|
|
||||||
/* gpointer user_data, */
|
|
||||||
/* GDestroyNotify user_destroy */
|
|
||||||
/* ); */
|
|
||||||
|
|
||||||
/* while (current_item->label) { */
|
|
||||||
/* if (0) printf("[%d] Current label : %s\n", depth, current_item->label); */
|
|
||||||
/* gtk_tree_store_append (model, &iter, iter_parent); */
|
|
||||||
/* gtk_tree_store_set (model, &iter, STRING_COLUMN, current_item->label, -1); */
|
|
||||||
|
|
||||||
/* if (current_item->children) */
|
|
||||||
/* create_node_recursive (model, current_item->children, &iter, depth + 1); */
|
|
||||||
/* else */
|
|
||||||
/* break; */
|
|
||||||
|
|
||||||
/* current_item++; */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
/* if (depth == 0) */
|
|
||||||
/* return GTK_TREE_MODEL(model); // cast from GtkTreeModel to GtkTreeStore */
|
|
||||||
/* else */
|
|
||||||
/* return NULL; */
|
|
||||||
/* } */
|
|
||||||
|
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
do_tree_store (GtkWidget *do_widget)
|
do_tree_store (GtkWidget *do_widget)
|
||||||
|
@ -313,19 +190,9 @@ do_tree_store (GtkWidget *do_widget)
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *sw; // sw : 'scrolled_window'
|
GtkWidget *sw; // sw : 'scrolled_window'
|
||||||
GtkWidget *treeview;
|
GtkWidget *treeview;
|
||||||
GtkTreeModel *my_tree_model; /////
|
GtkTreeModel *my_tree_model; // TODO replace by : GListModel *my_list_model;
|
||||||
GListModel *my_list_model;
|
GtkTreeStore *my_tree_store = NULL; // TODO replace by : GtkTreeListModel *my_tree_list_model;
|
||||||
GtkTreeStore *my_tree_store = NULL; /////
|
// https://docs.gtk.org/gio/property.ListStore.n-items.html
|
||||||
GtkTreeListModel *my_tree_list_model;
|
|
||||||
|
|
||||||
char *my_str_data = "A";
|
|
||||||
GListStore *my_g_list_store = g_list_store_new (my_str_data);
|
|
||||||
g_list_store_append (my_g_list_store, "C");
|
|
||||||
g_list_store_insert (my_g_list_store, "B", 1);
|
|
||||||
printf("Item : 'C' find in my_g_list_store at position 2 = %d\n",\
|
|
||||||
g_list_store_find (my_g_list_store, "C", 2));
|
|
||||||
g_list_store_remove (my_g_list_store, 0);
|
|
||||||
g_list_store_remove_all (my_g_list_store);
|
|
||||||
|
|
||||||
/* create window, etc */
|
/* create window, etc */
|
||||||
my_window = gtk_window_new ();
|
my_window = gtk_window_new ();
|
||||||
|
@ -350,12 +217,6 @@ do_tree_store (GtkWidget *do_widget)
|
||||||
|
|
||||||
/* create tree_model */
|
/* create tree_model */
|
||||||
my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0);
|
my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0);
|
||||||
// my_list_model = create_node_recursive (my_tree_list_model, O, NULL, 0);
|
|
||||||
iterating_a_model_in_a_depth_first_fashion (my_tree_model);
|
|
||||||
// GtkTreePath *my_path = gtk_tree_path_new_from_string ("0:0:1:0:1");
|
|
||||||
// acquiring_a_GtkTreeIter (my_tree_model, my_path);
|
|
||||||
// GtkTreeIter *my_iter;
|
|
||||||
// gtk_tree_model_get_data_from_iter (my_tree_model, NULL, my_iter, NULL, gtk_tree_path_new_from_string ("0:0:0:1:0:1"));
|
|
||||||
|
|
||||||
/* create tree view */
|
/* create tree view */
|
||||||
treeview = gtk_tree_view_new_with_model (my_tree_model);
|
treeview = gtk_tree_view_new_with_model (my_tree_model);
|
||||||
|
@ -387,3 +248,4 @@ do_tree_store (GtkWidget *do_widget)
|
||||||
|
|
||||||
return my_window;
|
return my_window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue