F I R S T L I S T I N G T K 4
This commit is contained in:
parent
e9c1146b55
commit
f44c7d1f1e
|
@ -122,12 +122,4 @@ void ui_toggle_sidebar ();
|
|||
|
||||
// Tree primitives
|
||||
|
||||
void print_test_in_tree_dot_c(void);
|
||||
|
||||
GtkWidget *create_my_deprec_tree_model(GtkBox *runlib_objects);
|
||||
GtkWidget *create_my_button_test(GtkBox *runlib_objects);
|
||||
GtkWidget *create_my_list_view_test(GtkBox *runlib_objects);
|
||||
GtkWidget *create_my_editable_cells (GtkBox *my_box);
|
||||
|
||||
GtkWidget *hello_it_s_me();
|
||||
void on_activate_window_creation (GtkApplication *app, gpointer data);
|
||||
|
|
18
src/main.c
18
src/main.c
|
@ -58,23 +58,29 @@
|
|||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
g_log_set_debug_enabled (TRUE);
|
||||
GtkDebugFlags my_flags = 1;
|
||||
gtk_set_debug_flags (my_flags);
|
||||
|
||||
g_autoptr(GemGraphClientApplication) app = NULL;
|
||||
int res;
|
||||
|
||||
app = gem_graph_client_application_new("org.alec.gemgraph",
|
||||
G_APPLICATION_DEFAULT_FLAGS);
|
||||
|
||||
g_signal_connect (app, "activate", G_CALLBACK (on_activate_window_creation),
|
||||
"This signal comes from main.c");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Jean 2024-01-20 Je désactive la visualisation de la fenêtre principale
|
||||
// dans : application.c > gem_graph_client_application_activate()
|
||||
// pour ne travailler que dans la fenêtre de sand_box.c
|
||||
|
||||
g_signal_connect (app, "activate", G_CALLBACK (on_activate_window_creation),
|
||||
"This signal comes from main.c");
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
res = g_application_run(G_APPLICATION(app), argc, argv);
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -112,12 +112,15 @@ static void gem_graph_client_application_activate(GApplication *app)
|
|||
ui_enable_action("togglesidebar");
|
||||
ui_set_stack("run");
|
||||
|
||||
|
||||
|
||||
|
||||
// XXX
|
||||
//
|
||||
// v
|
||||
//
|
||||
// Jean 2024-01-20 Je désactive la visualisation de cette fenêtre
|
||||
// pour travailler dans une fenêtre minimale (cf. sand_box)
|
||||
// pour travailler seulement dans sand_box.c
|
||||
//
|
||||
// gtk_window_present(window);
|
||||
}
|
||||
|
|
|
@ -14,340 +14,340 @@
|
|||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
/* G_GNUC_BEGIN_IGNORE_DEPRECATIONS */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int number;
|
||||
char *product;
|
||||
int yummy;
|
||||
}
|
||||
Item;
|
||||
/* typedef struct */
|
||||
/* { */
|
||||
/* int number; */
|
||||
/* char *product; */
|
||||
/* int yummy; */
|
||||
/* } */
|
||||
/* Item; */
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_ITEM_NUMBER,
|
||||
COLUMN_ITEM_PRODUCT,
|
||||
COLUMN_ITEM_YUMMY,
|
||||
NUM_ITEM_COLUMNS
|
||||
};
|
||||
/* enum */
|
||||
/* { */
|
||||
/* COLUMN_ITEM_NUMBER, */
|
||||
/* COLUMN_ITEM_PRODUCT, */
|
||||
/* COLUMN_ITEM_YUMMY, */
|
||||
/* NUM_ITEM_COLUMNS */
|
||||
/* }; */
|
||||
|
||||
enum
|
||||
{
|
||||
COLUMN_NUMBER_TEXT,
|
||||
NUM_NUMBER_COLUMNS
|
||||
};
|
||||
/* enum */
|
||||
/* { */
|
||||
/* COLUMN_NUMBER_TEXT, */
|
||||
/* NUM_NUMBER_COLUMNS */
|
||||
/* }; */
|
||||
|
||||
static GArray *articles = NULL;
|
||||
/* static GArray *articles = NULL; */
|
||||
|
||||
static void
|
||||
add_items (void)
|
||||
{
|
||||
Item foo;
|
||||
/* static void */
|
||||
/* add_items (void) */
|
||||
/* { */
|
||||
/* Item foo; */
|
||||
|
||||
g_return_if_fail (articles != NULL);
|
||||
/* g_return_if_fail (articles != NULL); */
|
||||
|
||||
foo.number = 3;
|
||||
foo.product = g_strdup ("bottles of coke");
|
||||
foo.yummy = 20;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
/* foo.number = 3; */
|
||||
/* foo.product = g_strdup ("bottles of coke"); */
|
||||
/* foo.yummy = 20; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
|
||||
foo.number = 5;
|
||||
foo.product = g_strdup ("packages of noodles");
|
||||
foo.yummy = 50;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
/* foo.number = 5; */
|
||||
/* foo.product = g_strdup ("packages of noodles"); */
|
||||
/* foo.yummy = 50; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
|
||||
foo.number = 2;
|
||||
foo.product = g_strdup ("packages of chocolate chip cookies");
|
||||
foo.yummy = 90;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
/* foo.number = 2; */
|
||||
/* foo.product = g_strdup ("packages of chocolate chip cookies"); */
|
||||
/* foo.yummy = 90; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
|
||||
foo.number = 1;
|
||||
foo.product = g_strdup ("can vanilla ice cream");
|
||||
foo.yummy = 60;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
/* foo.number = 1; */
|
||||
/* foo.product = g_strdup ("can vanilla ice cream"); */
|
||||
/* foo.yummy = 60; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
|
||||
foo.number = 6;
|
||||
foo.product = g_strdup ("eggs");
|
||||
foo.yummy = 10;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
}
|
||||
/* foo.number = 6; */
|
||||
/* foo.product = g_strdup ("eggs"); */
|
||||
/* foo.yummy = 10; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
/* } */
|
||||
|
||||
static GtkTreeModel *
|
||||
create_items_model (void)
|
||||
{
|
||||
int i = 0;
|
||||
GtkListStore *model;
|
||||
GtkTreeIter iter;
|
||||
/* static GtkTreeModel * */
|
||||
/* create_items_model (void) */
|
||||
/* { */
|
||||
/* int i = 0; */
|
||||
/* GtkListStore *model; */
|
||||
/* GtkTreeIter iter; */
|
||||
|
||||
/* create array */
|
||||
articles = g_array_sized_new (FALSE, FALSE, sizeof (Item), 1);
|
||||
/* articles = g_array_sized_new (FALSE, FALSE, sizeof (Item), 1); */
|
||||
|
||||
add_items ();
|
||||
/* add_items (); */
|
||||
|
||||
/* create list store */
|
||||
model = gtk_list_store_new (NUM_ITEM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
|
||||
G_TYPE_INT, G_TYPE_BOOLEAN);
|
||||
/* model = gtk_list_store_new (NUM_ITEM_COLUMNS, G_TYPE_INT, G_TYPE_STRING, */
|
||||
/* G_TYPE_INT, G_TYPE_BOOLEAN); */
|
||||
|
||||
/* add items */
|
||||
for (i = 0; i < articles->len; i++)
|
||||
{
|
||||
gtk_list_store_append (model, &iter);
|
||||
/* for (i = 0; i < articles->len; i++) */
|
||||
/* { */
|
||||
/* gtk_list_store_append (model, &iter); */
|
||||
|
||||
gtk_list_store_set (model, &iter,
|
||||
COLUMN_ITEM_NUMBER,
|
||||
g_array_index (articles, Item, i).number,
|
||||
COLUMN_ITEM_PRODUCT,
|
||||
g_array_index (articles, Item, i).product,
|
||||
COLUMN_ITEM_YUMMY,
|
||||
g_array_index (articles, Item, i).yummy,
|
||||
-1);
|
||||
}
|
||||
/* gtk_list_store_set (model, &iter, */
|
||||
/* COLUMN_ITEM_NUMBER, */
|
||||
/* g_array_index (articles, Item, i).number, */
|
||||
/* COLUMN_ITEM_PRODUCT, */
|
||||
/* g_array_index (articles, Item, i).product, */
|
||||
/* COLUMN_ITEM_YUMMY, */
|
||||
/* g_array_index (articles, Item, i).yummy, */
|
||||
/* -1); */
|
||||
/* } */
|
||||
|
||||
return GTK_TREE_MODEL (model);
|
||||
}
|
||||
/* return GTK_TREE_MODEL (model); */
|
||||
/* } */
|
||||
|
||||
static GtkTreeModel *
|
||||
create_numbers_model (void)
|
||||
{
|
||||
#define N_NUMBERS 10
|
||||
int i = 0;
|
||||
GtkListStore *model;
|
||||
GtkTreeIter iter;
|
||||
/* static GtkTreeModel * */
|
||||
/* create_numbers_model (void) */
|
||||
/* { */
|
||||
/* #define N_NUMBERS 10 */
|
||||
/* int i = 0; */
|
||||
/* GtkListStore *model; */
|
||||
/* GtkTreeIter iter; */
|
||||
|
||||
/* create list store */
|
||||
model = gtk_list_store_new (NUM_NUMBER_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
|
||||
/* model = gtk_list_store_new (NUM_NUMBER_COLUMNS, G_TYPE_STRING, G_TYPE_INT); */
|
||||
|
||||
/* add numbers */
|
||||
for (i = 0; i < N_NUMBERS; i++)
|
||||
{
|
||||
char str[2];
|
||||
/* for (i = 0; i < N_NUMBERS; i++) */
|
||||
/* { */
|
||||
/* char str[2]; */
|
||||
|
||||
str[0] = '0' + i;
|
||||
str[1] = '\0';
|
||||
/* str[0] = '0' + i; */
|
||||
/* str[1] = '\0'; */
|
||||
|
||||
gtk_list_store_append (model, &iter);
|
||||
/* gtk_list_store_append (model, &iter); */
|
||||
|
||||
gtk_list_store_set (model, &iter,
|
||||
COLUMN_NUMBER_TEXT, str,
|
||||
-1);
|
||||
}
|
||||
/* gtk_list_store_set (model, &iter, */
|
||||
/* COLUMN_NUMBER_TEXT, str, */
|
||||
/* -1); */
|
||||
/* } */
|
||||
|
||||
return GTK_TREE_MODEL (model);
|
||||
/* return GTK_TREE_MODEL (model); */
|
||||
|
||||
#undef N_NUMBERS
|
||||
}
|
||||
/* #undef N_NUMBERS */
|
||||
/* } */
|
||||
|
||||
static void
|
||||
add_item (GtkWidget *button, gpointer data)
|
||||
{
|
||||
Item foo;
|
||||
GtkTreeIter current, iter;
|
||||
GtkTreePath *path;
|
||||
GtkTreeModel *model;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeView *treeview = (GtkTreeView *)data;
|
||||
/* static void */
|
||||
/* add_item (GtkWidget *button, gpointer data) */
|
||||
/* { */
|
||||
/* Item foo; */
|
||||
/* GtkTreeIter current, iter; */
|
||||
/* GtkTreePath *path; */
|
||||
/* GtkTreeModel *model; */
|
||||
/* GtkTreeViewColumn *column; */
|
||||
/* GtkTreeView *treeview = (GtkTreeView *)data; */
|
||||
|
||||
g_return_if_fail (articles != NULL);
|
||||
/* g_return_if_fail (articles != NULL); */
|
||||
|
||||
foo.number = 0;
|
||||
foo.product = g_strdup ("Description here");
|
||||
foo.yummy = 50;
|
||||
g_array_append_vals (articles, &foo, 1);
|
||||
/* foo.number = 0; */
|
||||
/* foo.product = g_strdup ("Description here"); */
|
||||
/* foo.yummy = 50; */
|
||||
/* g_array_append_vals (articles, &foo, 1); */
|
||||
|
||||
/* Insert a new row below the current one */
|
||||
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
||||
model = gtk_tree_view_get_model (treeview);
|
||||
if (path)
|
||||
{
|
||||
gtk_tree_model_get_iter (model, ¤t, path);
|
||||
gtk_tree_path_free (path);
|
||||
gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, ¤t);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_list_store_insert (GTK_LIST_STORE (model), &iter, -1);
|
||||
}
|
||||
/* gtk_tree_view_get_cursor (treeview, &path, NULL); */
|
||||
/* model = gtk_tree_view_get_model (treeview); */
|
||||
/* if (path) */
|
||||
/* { */
|
||||
/* gtk_tree_model_get_iter (model, ¤t, path); */
|
||||
/* gtk_tree_path_free (path); */
|
||||
/* gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, ¤t); */
|
||||
/* } */
|
||||
/* else */
|
||||
/* { */
|
||||
/* gtk_list_store_insert (GTK_LIST_STORE (model), &iter, -1); */
|
||||
/* } */
|
||||
|
||||
/* Set the data for the new row */
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
||||
COLUMN_ITEM_NUMBER, foo.number,
|
||||
COLUMN_ITEM_PRODUCT, foo.product,
|
||||
COLUMN_ITEM_YUMMY, foo.yummy,
|
||||
-1);
|
||||
/* gtk_list_store_set (GTK_LIST_STORE (model), &iter, */
|
||||
/* COLUMN_ITEM_NUMBER, foo.number, */
|
||||
/* COLUMN_ITEM_PRODUCT, foo.product, */
|
||||
/* COLUMN_ITEM_YUMMY, foo.yummy, */
|
||||
/* -1); */
|
||||
|
||||
/* Move focus to the new row */
|
||||
path = gtk_tree_model_get_path (model, &iter);
|
||||
column = gtk_tree_view_get_column (treeview, 0);
|
||||
gtk_tree_view_set_cursor (treeview, path, column, FALSE);
|
||||
/* path = gtk_tree_model_get_path (model, &iter); */
|
||||
/* column = gtk_tree_view_get_column (treeview, 0); */
|
||||
/* gtk_tree_view_set_cursor (treeview, path, column, FALSE); */
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
/* gtk_tree_path_free (path); */
|
||||
/* } */
|
||||
|
||||
static void
|
||||
remove_item (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
GtkTreeView *treeview = (GtkTreeView *)data;
|
||||
GtkTreeModel *model = gtk_tree_view_get_model (treeview);
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
|
||||
/* static void */
|
||||
/* remove_item (GtkWidget *widget, gpointer data) */
|
||||
/* { */
|
||||
/* GtkTreeIter iter; */
|
||||
/* GtkTreeView *treeview = (GtkTreeView *)data; */
|
||||
/* GtkTreeModel *model = gtk_tree_view_get_model (treeview); */
|
||||
/* GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview); */
|
||||
|
||||
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
||||
{
|
||||
int i;
|
||||
GtkTreePath *path;
|
||||
/* if (gtk_tree_selection_get_selected (selection, NULL, &iter)) */
|
||||
/* { */
|
||||
/* int i; */
|
||||
/* GtkTreePath *path; */
|
||||
|
||||
path = gtk_tree_model_get_path (model, &iter);
|
||||
i = gtk_tree_path_get_indices (path)[0];
|
||||
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
||||
/* path = gtk_tree_model_get_path (model, &iter); */
|
||||
/* i = gtk_tree_path_get_indices (path)[0]; */
|
||||
/* gtk_list_store_remove (GTK_LIST_STORE (model), &iter); */
|
||||
|
||||
g_array_remove_index (articles, i);
|
||||
/* g_array_remove_index (articles, i); */
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
}
|
||||
/* gtk_tree_path_free (path); */
|
||||
/* } */
|
||||
/* } */
|
||||
|
||||
static gboolean
|
||||
separator_row (GtkTreeModel *model,
|
||||
GtkTreeIter *iter,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreePath *path;
|
||||
int idx;
|
||||
/* static gboolean */
|
||||
/* separator_row (GtkTreeModel *model, */
|
||||
/* GtkTreeIter *iter, */
|
||||
/* gpointer data) */
|
||||
/* { */
|
||||
/* GtkTreePath *path; */
|
||||
/* int idx; */
|
||||
|
||||
path = gtk_tree_model_get_path (model, iter);
|
||||
idx = gtk_tree_path_get_indices (path)[0];
|
||||
/* path = gtk_tree_model_get_path (model, iter); */
|
||||
/* idx = gtk_tree_path_get_indices (path)[0]; */
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
/* gtk_tree_path_free (path); */
|
||||
|
||||
return idx == 5;
|
||||
}
|
||||
/* return idx == 5; */
|
||||
/* } */
|
||||
|
||||
static void
|
||||
editing_started (GtkCellRenderer *cell,
|
||||
GtkCellEditable *editable,
|
||||
const char *path,
|
||||
gpointer data)
|
||||
{
|
||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (editable),
|
||||
separator_row, NULL, NULL);
|
||||
}
|
||||
/* static void */
|
||||
/* editing_started (GtkCellRenderer *cell, */
|
||||
/* GtkCellEditable *editable, */
|
||||
/* const char *path, */
|
||||
/* gpointer data) */
|
||||
/* { */
|
||||
/* gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (editable), */
|
||||
/* separator_row, NULL, NULL); */
|
||||
/* } */
|
||||
|
||||
static void
|
||||
cell_edited (GtkCellRendererText *cell,
|
||||
const char *path_string,
|
||||
const char *new_text,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = (GtkTreeModel *)data;
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
||||
GtkTreeIter iter;
|
||||
/* static void */
|
||||
/* cell_edited (GtkCellRendererText *cell, */
|
||||
/* const char *path_string, */
|
||||
/* const char *new_text, */
|
||||
/* gpointer data) */
|
||||
/* { */
|
||||
/* GtkTreeModel *model = (GtkTreeModel *)data; */
|
||||
/* GtkTreePath *path = gtk_tree_path_new_from_string (path_string); */
|
||||
/* GtkTreeIter iter; */
|
||||
|
||||
int column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column"));
|
||||
/* int column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column")); */
|
||||
|
||||
gtk_tree_model_get_iter (model, &iter, path);
|
||||
/* gtk_tree_model_get_iter (model, &iter, path); */
|
||||
|
||||
switch (column)
|
||||
{
|
||||
case COLUMN_ITEM_NUMBER:
|
||||
{
|
||||
int i;
|
||||
/* switch (column) */
|
||||
/* { */
|
||||
/* case COLUMN_ITEM_NUMBER: */
|
||||
/* { */
|
||||
/* int i; */
|
||||
|
||||
i = gtk_tree_path_get_indices (path)[0];
|
||||
g_array_index (articles, Item, i).number = atoi (new_text);
|
||||
/* i = gtk_tree_path_get_indices (path)[0]; */
|
||||
/* g_array_index (articles, Item, i).number = atoi (new_text); */
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
|
||||
g_array_index (articles, Item, i).number, -1);
|
||||
}
|
||||
break;
|
||||
/* gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, */
|
||||
/* g_array_index (articles, Item, i).number, -1); */
|
||||
/* } */
|
||||
/* break; */
|
||||
|
||||
case COLUMN_ITEM_PRODUCT:
|
||||
{
|
||||
int i;
|
||||
char *old_text;
|
||||
/* case COLUMN_ITEM_PRODUCT: */
|
||||
/* { */
|
||||
/* int i; */
|
||||
/* char *old_text; */
|
||||
|
||||
gtk_tree_model_get (model, &iter, column, &old_text, -1);
|
||||
g_free (old_text);
|
||||
/* gtk_tree_model_get (model, &iter, column, &old_text, -1); */
|
||||
/* g_free (old_text); */
|
||||
|
||||
i = gtk_tree_path_get_indices (path)[0];
|
||||
g_free (g_array_index (articles, Item, i).product);
|
||||
g_array_index (articles, Item, i).product = g_strdup (new_text);
|
||||
/* i = gtk_tree_path_get_indices (path)[0]; */
|
||||
/* g_free (g_array_index (articles, Item, i).product); */
|
||||
/* g_array_index (articles, Item, i).product = g_strdup (new_text); */
|
||||
|
||||
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
|
||||
g_array_index (articles, Item, i).product, -1);
|
||||
}
|
||||
break;
|
||||
/* gtk_list_store_set (GTK_LIST_STORE (model), &iter, column, */
|
||||
/* g_array_index (articles, Item, i).product, -1); */
|
||||
/* } */
|
||||
/* break; */
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
/* default: */
|
||||
/* g_assert_not_reached (); */
|
||||
/* } */
|
||||
|
||||
gtk_tree_path_free (path);
|
||||
}
|
||||
/* gtk_tree_path_free (path); */
|
||||
/* } */
|
||||
|
||||
static void
|
||||
add_columns (GtkTreeView *treeview,
|
||||
GtkTreeModel *items_model,
|
||||
GtkTreeModel *numbers_model)
|
||||
{
|
||||
GtkCellRenderer *renderer;
|
||||
/* static void */
|
||||
/* add_columns (GtkTreeView *treeview, */
|
||||
/* GtkTreeModel *items_model, */
|
||||
/* GtkTreeModel *numbers_model) */
|
||||
/* { */
|
||||
/* GtkCellRenderer *renderer; */
|
||||
|
||||
/* number column */
|
||||
renderer = gtk_cell_renderer_combo_new ();
|
||||
g_object_set (renderer,
|
||||
"model", numbers_model,
|
||||
"text-column", COLUMN_NUMBER_TEXT,
|
||||
"has-entry", FALSE,
|
||||
"editable", TRUE,
|
||||
NULL);
|
||||
g_signal_connect (renderer, "edited",
|
||||
G_CALLBACK (cell_edited), items_model);
|
||||
g_signal_connect (renderer, "editing-started",
|
||||
G_CALLBACK (editing_started), NULL);
|
||||
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_NUMBER));
|
||||
/* renderer = gtk_cell_renderer_combo_new (); */
|
||||
/* g_object_set (renderer, */
|
||||
/* "model", numbers_model, */
|
||||
/* "text-column", COLUMN_NUMBER_TEXT, */
|
||||
/* "has-entry", FALSE, */
|
||||
/* "editable", TRUE, */
|
||||
/* NULL); */
|
||||
/* g_signal_connect (renderer, "edited", */
|
||||
/* G_CALLBACK (cell_edited), items_model); */
|
||||
/* g_signal_connect (renderer, "editing-started", */
|
||||
/* G_CALLBACK (editing_started), NULL); */
|
||||
/* g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_NUMBER)); */
|
||||
|
||||
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Number", renderer,
|
||||
"text", COLUMN_ITEM_NUMBER,
|
||||
NULL);
|
||||
/* gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), */
|
||||
/* -1, "Number", renderer, */
|
||||
/* "text", COLUMN_ITEM_NUMBER, */
|
||||
/* NULL); */
|
||||
|
||||
/* product column */
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
g_object_set (renderer,
|
||||
"editable", TRUE,
|
||||
NULL);
|
||||
g_signal_connect (renderer, "edited",
|
||||
G_CALLBACK (cell_edited), items_model);
|
||||
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_PRODUCT));
|
||||
/* renderer = gtk_cell_renderer_text_new (); */
|
||||
/* g_object_set (renderer, */
|
||||
/* "editable", TRUE, */
|
||||
/* NULL); */
|
||||
/* g_signal_connect (renderer, "edited", */
|
||||
/* G_CALLBACK (cell_edited), items_model); */
|
||||
/* g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_PRODUCT)); */
|
||||
|
||||
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Product", renderer,
|
||||
"text", COLUMN_ITEM_PRODUCT,
|
||||
NULL);
|
||||
/* gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), */
|
||||
/* -1, "Product", renderer, */
|
||||
/* "text", COLUMN_ITEM_PRODUCT, */
|
||||
/* NULL); */
|
||||
|
||||
/* yummy column */
|
||||
renderer = gtk_cell_renderer_progress_new ();
|
||||
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_YUMMY));
|
||||
/* renderer = gtk_cell_renderer_progress_new (); */
|
||||
/* g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_YUMMY)); */
|
||||
|
||||
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
||||
-1, "Yummy", renderer,
|
||||
"value", COLUMN_ITEM_YUMMY,
|
||||
NULL);
|
||||
}
|
||||
/* gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), */
|
||||
/* -1, "Yummy", renderer, */
|
||||
/* "value", COLUMN_ITEM_YUMMY, */
|
||||
/* NULL); */
|
||||
/* } */
|
||||
|
||||
GtkWidget *create_my_editable_cells (GtkBox *my_box)
|
||||
{
|
||||
// static GtkWidget *window = NULL;
|
||||
/* GtkWidget *create_my_editable_cells (GtkBox *my_box) */
|
||||
/* { */
|
||||
/* // static GtkWidget *window = NULL; */
|
||||
|
||||
// if (!window)
|
||||
{
|
||||
GtkWidget *vbox;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *sw;
|
||||
GtkWidget *treeview;
|
||||
GtkWidget *button;
|
||||
GtkTreeModel *items_model;
|
||||
GtkTreeModel *numbers_model;
|
||||
/* // if (!window) */
|
||||
/* { */
|
||||
/* GtkWidget *vbox; */
|
||||
/* GtkWidget *hbox; */
|
||||
/* GtkWidget *sw; */
|
||||
/* GtkWidget *treeview; */
|
||||
/* GtkWidget *button; */
|
||||
/* GtkTreeModel *items_model; */
|
||||
/* GtkTreeModel *numbers_model; */
|
||||
|
||||
/* window = gtk_window_new (); */
|
||||
/* gtk_window_set_display (GTK_WINDOW (window), */
|
||||
|
@ -373,45 +373,45 @@ GtkWidget *create_my_editable_cells (GtkBox *my_box)
|
|||
/* gtk_box_append (GTK_BOX (vbox), sw); */
|
||||
|
||||
/* create models */
|
||||
items_model = create_items_model ();
|
||||
numbers_model = create_numbers_model ();
|
||||
/* items_model = create_items_model (); */
|
||||
/* numbers_model = create_numbers_model (); */
|
||||
|
||||
/* create tree view */
|
||||
treeview = gtk_tree_view_new_with_model (items_model);
|
||||
gtk_widget_set_vexpand (treeview, TRUE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
||||
GTK_SELECTION_SINGLE);
|
||||
/* treeview = gtk_tree_view_new_with_model (items_model); */
|
||||
/* gtk_widget_set_vexpand (treeview, TRUE); */
|
||||
/* gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)), */
|
||||
/* GTK_SELECTION_SINGLE); */
|
||||
|
||||
add_columns (GTK_TREE_VIEW (treeview), items_model, numbers_model);
|
||||
/* add_columns (GTK_TREE_VIEW (treeview), items_model, numbers_model); */
|
||||
|
||||
g_object_unref (numbers_model);
|
||||
g_object_unref (items_model);
|
||||
/* g_object_unref (numbers_model); */
|
||||
/* g_object_unref (items_model); */
|
||||
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), treeview);
|
||||
/* gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), treeview); */
|
||||
|
||||
/* some buttons */
|
||||
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
||||
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
|
||||
gtk_box_append (GTK_BOX (vbox), hbox);
|
||||
/* hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4); */
|
||||
/* gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE); */
|
||||
/* gtk_box_append (GTK_BOX (vbox), hbox); */
|
||||
|
||||
button = gtk_button_new_with_label ("Add item");
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (add_item), treeview);
|
||||
gtk_box_append (GTK_BOX (hbox), button);
|
||||
/* button = gtk_button_new_with_label ("Add item"); */
|
||||
/* g_signal_connect (button, "clicked", */
|
||||
/* G_CALLBACK (add_item), treeview); */
|
||||
/* gtk_box_append (GTK_BOX (hbox), button); */
|
||||
|
||||
button = gtk_button_new_with_label ("Remove item");
|
||||
g_signal_connect (button, "clicked",
|
||||
G_CALLBACK (remove_item), treeview);
|
||||
gtk_box_append (GTK_BOX (hbox), button);
|
||||
/* button = gtk_button_new_with_label ("Remove item"); */
|
||||
/* g_signal_connect (button, "clicked", */
|
||||
/* G_CALLBACK (remove_item), treeview); */
|
||||
/* gtk_box_append (GTK_BOX (hbox), button); */
|
||||
|
||||
gtk_box_append(my_box, treeview);
|
||||
/* gtk_box_append(my_box, treeview); */
|
||||
/* gtk_window_set_default_size (GTK_WINDOW (window), 320, 200); */
|
||||
}
|
||||
/* } */
|
||||
|
||||
/* if (!gtk_widget_get_visible (window)) */
|
||||
/* gtk_widget_set_visible (window, TRUE); */
|
||||
/* else */
|
||||
/* gtk_window_destroy (GTK_WINDOW (window)); */
|
||||
|
||||
return my_box;
|
||||
}
|
||||
/* return my_box; */
|
||||
/* } */
|
||||
|
|
|
@ -28,33 +28,36 @@
|
|||
#include "../../include/base.h"
|
||||
#include "../../include/ui.h"
|
||||
|
||||
int n = 0;
|
||||
static void on_button_action (GtkWidget *widget, gpointer data){n++; g_print (data, n);}
|
||||
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit(0);}
|
||||
|
||||
|
||||
static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {
|
||||
GtkWidget *lb = gtk_label_new (NULL);
|
||||
gtk_list_item_set_child (listitem, lb);
|
||||
/* Because gtk_list_item_set_child sunk the floating reference of lb, releasing (unref) isn't necessary for lb. */
|
||||
GtkWidget *my_label = gtk_label_new (NULL);
|
||||
gtk_list_item_set_child (listitem, my_label);
|
||||
/* Because gtk_list_item_set_child sunk the floating reference of my_label, releasing (unref) isn't necessary for my_label. */
|
||||
}
|
||||
|
||||
static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {
|
||||
GtkWidget *lb = gtk_list_item_get_child (listitem);
|
||||
GtkWidget *my_label = gtk_list_item_get_child (listitem);
|
||||
/* Strobj is owned by the instance. Caller mustn't change or destroy it. */
|
||||
GtkStringObject *strobj = gtk_list_item_get_item (listitem);
|
||||
/* The string returned by gtk_string_object_get_string is owned by the instance. */
|
||||
gtk_label_set_text (GTK_LABEL (lb), gtk_string_object_get_string (strobj));
|
||||
gtk_label_set_text (GTK_LABEL (my_label), gtk_string_object_get_string (strobj));
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
||||
{
|
||||
const gchar *my_array[] = {"zero", "one", "two", "three", "four", NULL};
|
||||
const gchar *my_array[] = {"zero", "one", "two", "three", "four", "five",
|
||||
"six", "seven", "eight", "nine", "ten", "eleven", "twelve", NULL};
|
||||
// https://toshiocp.github.io/Gtk4-tutorial/sec29.html
|
||||
|
||||
GtkStringList *my_string_list = gtk_string_list_new ((const char * const *) my_array);
|
||||
if (1) printf(strcat(gtk_string_list_get_string (my_string_list, 3), "\n"));
|
||||
|
||||
gint selected = 3;
|
||||
if (1) printf("The item n°%d of my array is the string \"%s\"\n",\
|
||||
selected, gtk_string_list_get_string (my_string_list, selected));
|
||||
|
||||
GtkNoSelection *my_selection = gtk_no_selection_new (G_LIST_MODEL (my_string_list));
|
||||
|
||||
GtkListItemFactory *my_factory = gtk_signal_list_item_factory_new ();
|
||||
|
@ -66,32 +69,8 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void on_activate_window_creation (GtkApplication *app, gpointer data) {
|
||||
|
||||
GtkWidget *my_window;
|
||||
GtkWidget *my_box;
|
||||
GtkWidget *my_button;
|
||||
char *my_window_title = "Hello folks !";
|
||||
char *my_button_title = "Yep ! I'm the button.";
|
||||
|
||||
my_window = gtk_window_new ();
|
||||
gtk_window_set_title (GTK_WINDOW(my_window), my_window_title);
|
||||
gtk_window_set_default_size (GTK_WINDOW(my_window), 400, 34);
|
||||
|
||||
my_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
|
||||
gtk_window_set_child(GTK_WINDOW(my_window), GTK_WIDGET(my_box));
|
||||
// gtk_widget_show (my_window); // L E A R N > !!! show() != present() !!!
|
||||
|
||||
my_button = gtk_button_new_with_label (my_button_title);
|
||||
g_signal_connect (G_OBJECT (my_button), "clicked", G_CALLBACK(on_button_action), "button clicked (n = %d)\n");
|
||||
// g_signal_connect_swapped (my_button, "clicked", G_CALLBACK (gtk_window_close), my_window); // < Then my_button closes my_window
|
||||
g_signal_connect (G_OBJECT (my_window), "destroy", G_CALLBACK(on_destroy), "closes window using exit(0)\n");
|
||||
|
||||
gtk_box_append(GTK_BOX (my_box), GTK_WIDGET(my_button)); // else : gtk_window_set_child (GTK_WINDOW (my_window), my_button);
|
||||
|
||||
// or just do it using : gtk_application_window_new(); -------------------------------------------------------------------------
|
||||
GtkWidget *that_window = gtk_application_window_new (gtk_application_new ("org.gtk.test", 0));
|
||||
g_signal_connect (G_OBJECT (that_window), "destroy", G_CALLBACK(on_destroy), "exit(0) closes window\n");
|
||||
gtk_window_set_title (GTK_WINDOW(that_window), "Gloups ! Who am I ? Oooh...");
|
||||
|
@ -100,59 +79,14 @@ void on_activate_window_creation (GtkApplication *app, gpointer data) {
|
|||
gtk_window_set_child (GTK_WINDOW (that_window), my_scrolling_thing);
|
||||
gtk_widget_show (that_window);
|
||||
|
||||
/* GtkWidget *my_box_in_that_window = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0); */
|
||||
/* gtk_window_set_child(GTK_WINDOW(that_window), GTK_WIDGET(my_box_in_that_window)); */
|
||||
and_now_let_s_climb_that_tree (my_scrolling_thing);
|
||||
|
||||
/* GtkWidget *my_other_button = gtk_button_new_with_label ("Sure ! I'm a button."); */
|
||||
/* g_signal_connect (G_OBJECT (my_other_button), "clicked", G_CALLBACK(on_button_action), "button clicked (n = %d)\n"); */
|
||||
/* gtk_box_append(GTK_BOX (my_box_in_that_window), GTK_WIDGET(my_other_button)); */
|
||||
|
||||
and_now_let_s_climb_that_tree (my_scrolling_thing); // (my_box_in_that_window);
|
||||
|
||||
if (data) {g_print (data); g_print (" and is displayed by [sand_box.c > on_activate_window_creation()] NB ? #define G_DEBUG_HERE (void) added\n");}
|
||||
printf("-------------------------------------------------------------------------------------------------------------------------------------------\n\
|
||||
[sand_box.c > on_activate_window_creation()] > widgets examples are in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo <\n");
|
||||
if (data) {g_print (data); g_print (" and is displayed by [sand_box.c > on_activate_window_creation()]\n");}
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// guix shell -m manifest.scm && pkg-config --libs gtk4
|
||||
// make clean && clear && time make run
|
||||
// GOBJECT_DEBUG=instance_count GIO = Gnome Input Output
|
||||
|
||||
// https://docs.gtk.org/
|
||||
// https://docs.gtk.org/gtk4/
|
||||
// https://docs.gtk.org/gobject/
|
||||
// https://docs.gtk.org/glib/
|
||||
// https://docs.gtk.org/gio/
|
||||
//
|
||||
// https://docs.gtk.org/gtk4/question_index.html
|
||||
// https://docs.gtk.org/gtk4/running.html
|
||||
//
|
||||
// https://blog.gtk.org/2020/09/05/a-primer-on-gtklistview/ <<< Factory mechanism
|
||||
// https://docs.gtk.org/gtk4/class.ListItemFactory.html <<<
|
||||
// https://www.typeerror.org/docs/gtk~4.0/gtksignallistitemfactory
|
||||
// https://docs.gtk.org/gtk4/section-list-widget.html < les listes old/new et la discussion
|
||||
// https://developer-old.gnome.org/gtk4/stable/GtkListView.html <<< copy that !
|
||||
// https://docs.gtk.org/gtk4/ctor.TreeListModel.new.html ***
|
||||
// https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ ***
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
|
||||
/*
|
||||
https://gnome.pages.gitlab.gnome.org/gtk/gtk4/
|
||||
|
||||
Gtk – 4.0
|
||||
|
||||
Build Dependencies Related libraries Additional documentation
|
||||
Classes Interfaces Structs Aliases
|
||||
Enumerations Bitfields Error Domains Callbacks
|
||||
Functions Function Macros Constants
|
||||
|
||||
*/
|
||||
// guix shell -m manifest.scm && pkg-config --libs gtk4 make clean && clear && time make run
|
||||
// my local widgets examples are in user/jean/01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo
|
||||
|
||||
|
||||
|
|
|
@ -1,204 +0,0 @@
|
|||
/*
|
||||
* Gem-graph OpenGL experiments
|
||||
*
|
||||
* Desc: User interface functions
|
||||
*
|
||||
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
|
||||
*
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include <glib-2.0/glib.h>
|
||||
|
||||
#include "../../include/base.h"
|
||||
#include "../../include/ui.h"
|
||||
|
||||
// #define G_DEBUG_HERE (void) < attention: « G_DEBUG_HERE » redéfini
|
||||
|
||||
enum
|
||||
{
|
||||
STRING_COLUMN,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
/* TreeItem structure */
|
||||
typedef struct _TreeItem TreeItem;
|
||||
struct _TreeItem
|
||||
{
|
||||
const char *label;
|
||||
TreeItem *children;
|
||||
};
|
||||
|
||||
// tree data
|
||||
static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {NULL};
|
||||
static TreeItem I[] = {NULL}, K[] = {NULL}, N[] = {NULL}, M[] = {NULL};
|
||||
static TreeItem L[] = {{"M", M}, {"N", N}, {NULL }}, J[] = {{"L", L}, {NULL}};
|
||||
static TreeItem D[] = {{"I", I}, {"J", J}, {"K", K}, {NULL}};
|
||||
static TreeItem C[] = {{"F", F}, {"G", G}, {"H", H}, {NULL}};
|
||||
static TreeItem A[] = {{"D", D}, {NULL}}, B[] = {{"E", E}, {NULL}};
|
||||
static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}};
|
||||
static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
|
||||
|
||||
static GtkWidget *my_tree_view; // = NULL;
|
||||
static GListStore *my_list_model = NULL;
|
||||
|
||||
static void
|
||||
add_item () //(GtkWidget *button, gpointer data)
|
||||
{
|
||||
TreeItem foo;
|
||||
GtkTreeView *treeview = my_tree_view; // (GtkTreeView *)data; attention:
|
||||
// initialisation de « GtkTreeView * » depuis le type pointeur « GtkWidget * » qui est incompatible
|
||||
GtkTreeModel *model = my_list_model; // gtk_tree_view_get_model (treeview); attention:
|
||||
// initialisation de « GtkTreeModel * » depuis le type pointeur « GListStore * » qui est incompatible
|
||||
GtkTreePath *path;
|
||||
GtkTreeViewColumn *column;
|
||||
GtkTreeIter current, iter;
|
||||
|
||||
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
||||
//model = gtk_tree_view_get_model (treeview);
|
||||
if (path)
|
||||
{
|
||||
gtk_tree_model_get_iter (my_list_model, ¤t, path); // attention:
|
||||
// passage de l'argument 1 de « gtk_tree_model_get_iter » depuis un type pointeur incompatible
|
||||
// « GtkTreeModel * » attendu mais l'argument est de type « GListStore *
|
||||
printf("In 'tree.c' (line 73) add_item() path = %s depth = %d\n",
|
||||
gtk_tree_path_to_string (path),
|
||||
gtk_tree_path_get_depth (path)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
remove_item (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
printf("In 'tree-deprec.c' (line 83) remove item() > no item selected (or can't get it ?)\n");
|
||||
|
||||
GtkTreeView *treeview = my_tree_view; // (GtkTreeView *)data; attention:
|
||||
// initialisation de « GtkTreeView * » depuis le type pointeur « GtkWidget * » qui est incompatible
|
||||
GtkTreeModel *model = my_list_model; // gtk_tree_view_get_model (treeview); attention:
|
||||
// initialisation de « GtkTreeModel * » depuis le type pointeur « GListStore * » qui est incompatible
|
||||
GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
|
||||
GtkTreeIter iter;
|
||||
}
|
||||
|
||||
static void
|
||||
cell_edited (GtkCellRendererText *cell,
|
||||
const char *path_string,
|
||||
const char *new_text,
|
||||
gpointer data)
|
||||
{
|
||||
GtkTreeModel *model = my_list_model; // gtk_tree_view_get_model (treeview); attention:
|
||||
// initialisation de « GtkTreeModel * » depuis le type pointeur « GListStore * » qui est incompatible
|
||||
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
||||
GtkTreeIter iter;
|
||||
}
|
||||
|
||||
// TODO GtkTreeListModel ? GtkTreeModel ? (lines 238 & 270)
|
||||
static GListStore *create_node_recursive (GListStore *model,
|
||||
// ? GListStore* g_list_store_new (GType item_type)
|
||||
TreeItem *current_item,
|
||||
GtkTreeIter *iter_parent,
|
||||
int depth)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
|
||||
// warning: assignment to 'GListStore *' from incompatible pointer type 'GtkTreeStore *'
|
||||
if (model == NULL)
|
||||
model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); // attention:
|
||||
// affectation à « GListStore * » depuis le type pointeur « GtkTreeStore * » qui est incompatible
|
||||
|
||||
while (current_item->label) {
|
||||
gtk_tree_store_append (model, &iter, iter_parent); // attention:
|
||||
// passage de l'argument 1 de « gtk_tree_store_append » depuis un type pointeur incompatible
|
||||
// « GtkTreeStore * » attendu mais l'argument est de type « GListStore * »
|
||||
gtk_tree_store_set (model, &iter, STRING_COLUMN, current_item->label, -1); // attention:
|
||||
// passage de l'argument 1 de « gtk_tree_store_set » depuis un type pointeur incompatible
|
||||
// « GtkTreeStore * » attendu mais l'argument est de type « GListStore * »
|
||||
|
||||
if (current_item->children)
|
||||
create_node_recursive (model, current_item->children, &iter, depth + 1);
|
||||
else
|
||||
break;
|
||||
|
||||
current_item++;
|
||||
}
|
||||
|
||||
if (depth == 0)
|
||||
return G_LIST_STORE(model); // GLib-GObject-WARNING invalid cast from 'GtkTreeStore' to 'GListStore'
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
GtkWidget *create_my_deprec_tree_model(GtkBox *runlib_objects)
|
||||
{
|
||||
GtkWidget *my_scrolled_window = NULL;
|
||||
GtkCellRenderer *my_renderer = NULL;
|
||||
|
||||
my_list_model = create_node_recursive (my_list_model, O, NULL, 0);
|
||||
my_tree_view = gtk_tree_view_new_with_model (my_list_model); // attention:
|
||||
// passage de l'argument 1 de « gtk_tree_view_new_with_model » depuis un type pointeur incompatible
|
||||
// « GtkTreeModel * » attendu mais l'argument est de type « GListStore * »
|
||||
|
||||
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (my_tree_view), FALSE);
|
||||
gtk_tree_view_set_enable_tree_lines (GTK_TREE_VIEW (my_tree_view), TRUE);
|
||||
gtk_widget_set_vexpand (my_tree_view, TRUE);
|
||||
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (my_tree_view)),
|
||||
GTK_SELECTION_MULTIPLE);
|
||||
gtk_tree_view_set_reorderable (GTK_TREE_VIEW (my_tree_view), TRUE);
|
||||
g_object_unref (my_list_model);
|
||||
|
||||
my_renderer = gtk_cell_renderer_text_new (); g_object_set (my_renderer, "xalign", 0.0, NULL);
|
||||
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (my_tree_view), -1,
|
||||
"Col 0", my_renderer, "text", STRING_COLUMN, NULL);
|
||||
|
||||
my_scrolled_window = gtk_scrolled_window_new ();
|
||||
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (my_scrolled_window), TRUE);
|
||||
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (my_scrolled_window),
|
||||
GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
|
||||
gtk_box_append (runlib_objects, my_scrolled_window);
|
||||
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (my_scrolled_window), my_tree_view);
|
||||
|
||||
/* expand all rows after the my_tree_view widget has been realized */
|
||||
g_signal_connect (my_tree_view, "realize",
|
||||
G_CALLBACK (gtk_tree_view_expand_all), NULL);
|
||||
|
||||
return my_tree_view;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
GtkWidget *create_my_button_test(GtkBox *runlib_objects)
|
||||
{
|
||||
GtkWidget *button;
|
||||
const char *text = "Show properties of the selected item";
|
||||
|
||||
button = gtk_button_new_with_label(text);
|
||||
gtk_box_append(runlib_objects, button);
|
||||
gtk_widget_show(button);
|
||||
|
||||
g_signal_connect (button, "clicked", G_CALLBACK (add_item), NULL);
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// guix shell -m manifest.scm make clean && clear && time make run
|
||||
// TODO https://docs.gtk.org/gtk4/section-list-widget.html
|
265
src/ui/tree.c
265
src/ui/tree.c
|
@ -1,265 +0,0 @@
|
|||
/*
|
||||
* Gem-graph OpenGL experiments
|
||||
*
|
||||
* Desc: User interface functions
|
||||
*
|
||||
* Copyright (C) 2023 Jean Sirmai <jean@a-lec.org>
|
||||
*
|
||||
* This file is part of Gem-graph.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include <glib-2.0/glib.h>
|
||||
|
||||
#include "../../include/base.h"
|
||||
#include "../../include/ui.h"
|
||||
|
||||
// TODO use GTK_DEBUG
|
||||
GTK_DEBUG;
|
||||
|
||||
enum
|
||||
{
|
||||
STRING_COLUMN,
|
||||
NUM_COLUMNS
|
||||
};
|
||||
|
||||
/* TreeItem structure */
|
||||
typedef struct _TreeItem TreeItem;
|
||||
struct _TreeItem
|
||||
{
|
||||
const char *label;
|
||||
TreeItem *children;
|
||||
};
|
||||
|
||||
// tree data
|
||||
static TreeItem E[] = {NULL}, F[] = {NULL}, G[] = {NULL}, H[] = {NULL};
|
||||
static TreeItem I[] = {NULL}, K[] = {NULL}, N[] = {NULL}, M[] = {NULL};
|
||||
static TreeItem L[] = {{"M", M}, {"N", N}, {NULL }}, J[] = {{"L", L}, {NULL}};
|
||||
static TreeItem D[] = {{"I", I}, {"J", J}, {"K", K}, {NULL}};
|
||||
static TreeItem C[] = {{"F", F}, {"G", G}, {"H", H}, {NULL}};
|
||||
static TreeItem A[] = {{"D", D}, {NULL}}, B[] = {{"E", E}, {NULL}};
|
||||
static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}};
|
||||
static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
|
||||
|
||||
void gtk_string_list_take (GtkStringList* self, char* string){}
|
||||
|
||||
static void bind_listitem_cb_complex (GtkListItemFactory *factory,
|
||||
GtkListItem *list_item)
|
||||
{
|
||||
GtkWidget *label;
|
||||
TreeItem *obj;
|
||||
|
||||
label = gtk_list_item_get_child (list_item);
|
||||
obj = gtk_list_item_get_item (list_item);
|
||||
gtk_label_set_label (GTK_LABEL (label),
|
||||
my_object_get_string (obj));
|
||||
}
|
||||
|
||||
static GtkWidget *my_tree_view;
|
||||
static GListModel *my_Glist_model = NULL;
|
||||
|
||||
// erreur: un élément de l'initialisation n'est pas une constante
|
||||
// model = create_application_list (); g_list_model_get_item_type()
|
||||
|
||||
|
||||
typedef struct _GtkListView GtkListView;
|
||||
GtkListView my_view();
|
||||
|
||||
typedef struct _GtkModel GtkModel;
|
||||
GtkModel my_model();
|
||||
|
||||
typedef struct _GListModel GListModel;
|
||||
GListModel my_list_model();
|
||||
|
||||
typedef struct _GtkSelectionModel GtkSelectionModel;
|
||||
GtkSelectionModel my_selection_model();
|
||||
|
||||
typedef struct _GtkSignalListItemFactory GtkSignalListItemFactory;
|
||||
GtkSignalListItemFactory my_factory(int a);
|
||||
|
||||
GtkListItemFactory *gtk_signal_list_item_factory_new (void);
|
||||
GtkListItemFactory *gtk_list_view_get_factory (GtkListView *self);
|
||||
GtkWidget *gtk_list_view_new (GtkSelectionModel *my_selection_model, GtkListItemFactory *my_factory);
|
||||
void gtk_list_view_set_model (GtkListView *self, GtkSelectionModel *my_selection_model);
|
||||
GtkSelectionModel *gtk_list_view_get_model (GtkListView *self);
|
||||
void gtk_list_view_set_show_separators (GtkListView *self, gboolean show_separators);
|
||||
// Sets whether the list box should show separators between rows. See also the "get" function
|
||||
void gtk_list_view_set_single_click_activate (GtkListView *self, gboolean single_click_activate);
|
||||
// Sets whether rows should be activated on single click and selected on hover. See also the "get" function
|
||||
void gtk_list_view_set_enable_rubberband (GtkListView *self, gboolean enable_rubberband);
|
||||
// Sets whether selections can be changed by dragging with the mouse. See also the "get" function
|
||||
|
||||
|
||||
static void setup_listitem_cb (GtkListItemFactory *my_factory,
|
||||
GtkListItem *my_list_item,
|
||||
GtkLabel *my_label,
|
||||
GtkImage *my_image)
|
||||
{
|
||||
// If not provided : GtkWidget *my_label = gtk_label_new ("");
|
||||
gtk_list_item_set_child (my_list_item, my_label);
|
||||
|
||||
// If not provided : GtkWidget *my_image = gtk_image_new ();
|
||||
gtk_image_set_icon_size (GTK_IMAGE (my_image), GTK_ICON_SIZE_LARGE);
|
||||
gtk_list_item_set_child (my_list_item, my_image);
|
||||
}
|
||||
|
||||
static void bind_listitem_cb (GtkListItemFactory *factory,
|
||||
GtkListItem *list_item)
|
||||
{
|
||||
GtkWidget *image;
|
||||
GAppInfo *app_info;
|
||||
|
||||
image = gtk_list_item_get_child (list_item);
|
||||
app_info = gtk_list_item_get_item (list_item);
|
||||
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
|
||||
}
|
||||
|
||||
static void activate_cb (GtkListView *list,
|
||||
guint position, gpointer unused)
|
||||
{
|
||||
GAppInfo *app_info;
|
||||
|
||||
app_info = g_list_model_get_item (G_LIST_MODEL (gtk_list_view_get_model (list)), position);
|
||||
g_app_info_launch (app_info, NULL, NULL, NULL);
|
||||
g_object_unref (app_info);
|
||||
}
|
||||
|
||||
|
||||
// Parameters : self : the GtkSignalListItemFactory,
|
||||
// listitem : the GtkListItem to bind,
|
||||
// user_data : the user data set when the signal handler was connected.
|
||||
// Flags: Run First
|
||||
static void any_user_function (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {
|
||||
// my_factory = gtk_signal_list_item_factory_new ();
|
||||
g_signal_connect (my_factory, "setup", setup_listitem_cb, NULL);
|
||||
g_signal_connect (my_factory, "bind", bind_listitem_cb, NULL);
|
||||
}
|
||||
|
||||
// user_function can be : setup, bind, unbind or teardown
|
||||
//
|
||||
// The “setup” signal is emitted when the factory needs to create a new row widget.
|
||||
// g_signal_connect (factory, "setup", setup_listitem_cb, NULL);
|
||||
//
|
||||
// The “bind” signal is emitted when a row widget needs to be connected to an item from the model.
|
||||
// g_signal_connect (factory, "bind", bind_listitem_cb, NULL);
|
||||
//
|
||||
// Both of these signals take a GtkListItem as argument,
|
||||
// which is a wrapper object that lets you get at the model item (with gtk_list_item_get_item())
|
||||
// and also lets you deliver the new row widget (with gtk_list_item_set_child()).
|
||||
//
|
||||
// If your “bind” handler connects to signals on the item or does other things that require cleanup,
|
||||
// you can use the “unbind” signal to do that cleanup. The “setup” signal has a similar counterpart called “teardown”.
|
||||
|
||||
|
||||
static GListModel *create_settings_model (gpointer item,
|
||||
gpointer unused)
|
||||
{
|
||||
GSettings *settings = item;
|
||||
char **schemas;
|
||||
GListStore *result;
|
||||
guint i;
|
||||
|
||||
schemas = g_settings_list_children (settings);
|
||||
|
||||
if (schemas == NULL || schemas[0] == NULL)
|
||||
{
|
||||
g_free (schemas);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
result = g_list_store_new (G_TYPE_SETTINGS); // G_TYPE_STRING
|
||||
for (i = 0; schemas[i] != NULL; i++)
|
||||
{
|
||||
GSettings *child = g_settings_get_child (settings, schemas[i]);
|
||||
g_list_store_append (result, child);
|
||||
g_object_unref (child);
|
||||
}
|
||||
|
||||
g_strfreev (schemas);
|
||||
|
||||
return G_LIST_MODEL (result);
|
||||
}
|
||||
|
||||
GtkTreeListModel*
|
||||
gtk_tree_list_model_new (
|
||||
GListModel* root,
|
||||
gboolean passthrough,
|
||||
gboolean autoexpand,
|
||||
GtkTreeListModelCreateModelFunc create_func,
|
||||
gpointer user_data,
|
||||
GDestroyNotify user_destroy
|
||||
)
|
||||
{}
|
||||
|
||||
// GListModel truc; gtk_tree_list_model_new(&truc)
|
||||
// GListModel *truc; gtk_tree_list_model_new(truc,0,0,NULL,NULL,NULL);
|
||||
|
||||
typedef struct _GListModel GListModel;
|
||||
|
||||
struct GListModelInterface {
|
||||
GTypeInterface g_iface;
|
||||
GType (* get_item_type) (GListModel *list);
|
||||
guint (* get_n_items) (GListModel *list);
|
||||
gpointer (* get_item) (GListModel *list,
|
||||
guint position);
|
||||
};
|
||||
|
||||
/*
|
||||
* Parameters :
|
||||
* list the GListModel that changed
|
||||
* position the position at which list changed
|
||||
* removed the number of items removed
|
||||
* added the number of items added
|
||||
* user_data user data set when the signal handler was connected.
|
||||
* Flags: Run Last
|
||||
*/
|
||||
void
|
||||
user_function (GListModel *list,
|
||||
guint position,
|
||||
guint removed,
|
||||
guint added,
|
||||
gpointer user_data)
|
||||
{}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// guix shell -m manifest.scm make clean && clear && time make run
|
||||
// GOBJECT_DEBUG=instance_count Gio Gnome input output
|
||||
|
||||
// https://docs.gtk.org/gtk4/
|
||||
// https://docs.gtk.org/gtk4/question_index.html
|
||||
// https://docs.gtk.org/gtk4/running.html
|
||||
//
|
||||
// https://docs.gtk.org/gtk4/section-list-widget.html
|
||||
// https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html
|
||||
// https://blog.gtk.org/2020/09/05/a-primer-on-gtklistview/ <<< Factory mechanism
|
||||
// https://docs.gtk.org/gtk4/class.ListItemFactory.html <<<
|
||||
// https://www.typeerror.org/docs/gtk~4.0/gtksignallistitemfactory
|
||||
// https://developer-old.gnome.org/gtk4/stable/GtkListView.html <<< copy that !
|
||||
// https://docs.gtk.org/gtk4/class.ListItem.html
|
||||
// https://docs.gtk.org/gtk4/section-list-widget.html < ici, la double liste : old / new
|
||||
// https://docs.gtk.org/gtk4/ctor.TreeListModel.new.html ***
|
||||
// https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/ ***
|
||||
// https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_settings.c GtkBuilder *builder; (line 216)
|
||||
// https://discourse.gnome.org/t/how-can-i-get-the-expanded-collapsed-items-in-the-new-gtktreelistmodel-implementation/16824
|
||||
// https://developer-old.gnome.org/gtk4/stable/GtkSignalListItemFactory.html
|
||||
// https://docs.gtk.org/gtk4/method.StringList.take.html
|
||||
|
||||
// https://developer-old.gnome.org/gtk4/stable/gtk-running.html
|
||||
|
||||
// https://fr.wikibooks.org/wiki/Programmation_GTK // mars 2022
|
||||
// https://fr.wikibooks.org/wiki/Programmation_GTK/Bonjour_tout_le_monde
|
|
@ -146,8 +146,8 @@ void ui_set_stack(const char *mode)
|
|||
break;
|
||||
case 'r':
|
||||
gtk_menu_button_set_icon_name(window->main_button_mode, "system-run-symbolic");
|
||||
if (! my_tree) my_tree = create_my_deprec_tree_model(window->runlib_objects); // in tree.c
|
||||
if (! my_button) my_button = create_my_button_test(window->runlib_objects); // in tree.c
|
||||
// if (! my_tree) my_tree = create_my_deprec_tree_model(window->runlib_objects); // in tree.c
|
||||
// if (! my_button) my_button = create_my_button_test(window->runlib_objects); // in tree.c
|
||||
// if (! my_list) my_list = create_my_list_view_test(window->runlib_objects); // in "bac-a-sable.c"
|
||||
// if (! my_editable_cells) my_editable_cells = create_my_editable_cells(window->runlib_objects); // in editable_cell.c
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue