WIP: cleaning

This commit is contained in:
Jean Sirmai 2024-01-24 11:53:58 +01:00
parent e9f147a60a
commit 22d127d1c0
Signed by: jean
GPG Key ID: FB3115C340E057E3
1 changed files with 27 additions and 128 deletions

View File

@ -29,7 +29,7 @@
static void on_destroy (GtkWidget *widget, gpointer data) {if (data) g_print (data); exit(0);}
static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
static void on_setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
{
GtkWidget *my_label = gtk_label_new (NULL);
gtk_list_item_set_child (my_list_item, my_label);
@ -37,7 +37,7 @@ static void setup_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item,
* releasing (unref) isn't necessary for my_label. */
}
static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
static void on_bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item, gpointer user_data)
{
GtkWidget *my_label = gtk_list_item_get_child (my_list_item);
/* my_string_object is owned by the instance. Caller mustn't change or destroy it. */
@ -46,10 +46,6 @@ static void bind_cb (GtkSignalListItemFactory *self, GtkListItem *my_list_item,
gtk_label_set_text (GTK_LABEL (my_label), gtk_string_object_get_string (my_string_object));
}
static void unbind_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {}
static void teardown_cb (GtkSignalListItemFactory *self, GtkListItem *listitem, gpointer user_data) {}
/* GtkListItem instance will be destroyed soon. You don't need to set the child to NULL. */
static void on_selection_change (GtkSelectionModel* my_selection_model, guint position, guint n_items, gpointer user_data)
{
printf("list size = %d item type = %d\
@ -62,87 +58,18 @@ static void on_selection_change (GtkSelectionModel* my_selection_model, guint p
n_items );
}
static void on_activating_this_expander (GtkExpander *my_expander, gpointer my_data) {printf("%s\n", gtk_expander_get_label (my_expander));}
static void populate_tree_model (store){};
//-------------------------------------------------------------------------------------------------------------------------------------------
// ------------- Begin Matthias Clasen ------------------------------------
enum
GListModel *item_create_func (gpointer item, gpointer user_data)
{
TITLE_COLUMN,
AUTHOR_COLUMN,
CHECKED_COLUMN,
N_COLUMNS
};
void
setup_tree (void)
{
GtkTreeStore *store;
GtkWidget *tree;
GtkTreeViewColumn *column;
GtkCellRenderer *renderer;
/* Create a model. We are using the store model for now, though we
* could use any other GtkTreeModel */
store = gtk_tree_store_new (N_COLUMNS,
G_TYPE_STRING,
G_TYPE_STRING,
G_TYPE_BOOLEAN);
/* custom function to fill the model with data */
populate_tree_model (store);
/* Create a view */
tree = gtk_tree_view_new_with_model (GTK_TREE_MODEL (store));
/* The view now holds a reference. We can get rid of our own
* reference */
g_object_unref (G_OBJECT (store));
/* Create a cell render and arbitrarily make it red for demonstration
* purposes */
renderer = gtk_cell_renderer_text_new ();
g_object_set (G_OBJECT (renderer),
"foreground", "red",
NULL);
/* Create a column, associating the "text" attribute of the
* cell_renderer to the first column of the model */
column = gtk_tree_view_column_new_with_attributes ("Author", renderer,
"text", AUTHOR_COLUMN,
NULL);
/* Add the column to the view. */
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
/* Second column.. title of the book. */
renderer = gtk_cell_renderer_text_new ();
column = gtk_tree_view_column_new_with_attributes ("Title",
renderer,
"text", TITLE_COLUMN,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
/* Last column.. whether a book is checked out. */
renderer = gtk_cell_renderer_toggle_new ();
column = gtk_tree_view_column_new_with_attributes ("Checked out",
renderer,
"active", CHECKED_COLUMN,
NULL);
gtk_tree_view_append_column (GTK_TREE_VIEW (tree), column);
/* Now we can manipulate the view just like any other GTK widget */
GtkWidget *my_expander = gtk_expander_new ("my_expander");
gtk_expander_set_child (my_expander, NULL); // *child); how to ?
if (0) on_activating_this_expander (my_expander, NULL); // gpointer user_data) The “activate” signal
return NULL;
}
static void on_activating_this_expander (GtkExpander *my_expander, gpointer my_data){}
// ------------- End Matthias Clasen --------------------------------------
enum { COLUMN_DESCRIPTION };
static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
{
const gchar *my_array[] = {"zero", "one", "two", "three", "four", "five",
@ -156,61 +83,32 @@ static void and_now_let_s_climb_that_tree (GtkWidget *in_that_box)
gtk_selection_model_selection_changed (my_selection_model, 0, 1);
GtkListItemFactory *my_list_item_factory = gtk_signal_list_item_factory_new ();
g_signal_connect (my_list_item_factory, "setup", G_CALLBACK (setup_cb), NULL);
g_signal_connect (my_list_item_factory, "bind", G_CALLBACK (bind_cb), NULL);
if (1) { g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL);
g_signal_connect (my_list_item_factory, "unbind", G_CALLBACK (unbind_cb), NULL);
g_signal_connect (my_list_item_factory, "teardown", G_CALLBACK (teardown_cb), NULL); }
g_signal_connect (my_list_item_factory, "setup", G_CALLBACK (on_setup_cb), NULL);
g_signal_connect (my_list_item_factory, "bind", G_CALLBACK (on_bind_cb), NULL);
if (1) { g_signal_connect (my_selection_model, "selection-changed", G_CALLBACK (on_selection_change), NULL);}
// GListModel *(* GtkTreeListModelCreateModelFunc) (GObject* item, gpointer user_data) // remplacerait gtk_string_list_new() ?
// https://docs.gtk.org/gtk4/callback.TreeListModelCreateModelFunc.html
GListModel *the_root = my_selection_model; // my_string_list; // < both can be compiled
gboolean passthrough = 1, autoexpand = 1;
GtkTreeListModelCreateModelFunc create_func = NULL; // devrait remplacer gtk_string_list_new() ?? s'appliquer à chaque nouvel item ?
gpointer user_data = NULL;
GDestroyNotify user_destroy = NULL; // < Function to call to free user_data
GtkTreeListModel *my_tree_list_model = gtk_tree_list_model_new (the_root, passthrough, autoexpand, create_func, user_data, user_destroy);
// https://docs.gtk.org/gtk4/section-tree-widget.html
GtkListStore *my_list_store = gtk_list_store_new (1, G_TYPE_STRING);
GtkTreeIter child_iter, parent_iter;
gtk_tree_store_set (my_list_store, &parent_iter, "root", -1); // equiv next line ?
gtk_tree_store_append (my_list_store, &parent_iter, "root"); // Acquire a top-level iterator
gtk_tree_store_append (my_list_store, &child_iter, &parent_iter); // Acquire an iterator
// The third argument to gtk_tree_store_append() is the parent iterator.
GtkWidget *my_tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (my_list_store));
GtkCellRenderer *my_renderer = gtk_cell_renderer_text_new ();
gtk_tree_store_set (G_OBJECT (my_renderer), "foreground", "green", NULL);
gtk_list_store_set (G_OBJECT (my_renderer), "foreground", "red", NULL);
GtkTreeViewColumn *my_column = gtk_tree_view_column_new_with_attributes ("column title", my_renderer, NULL);
// the example is : column = gtk_tree_view_column_new_with_attributes ("Author", renderer, "text", AUTHOR_COLUMN, NULL);
//
gtk_tree_view_append_column (GTK_TREE_VIEW (my_tree_view), my_column); gtk_tree_store_set (my_list_store, &child_iter, my_column, "zero", -1);
gtk_tree_view_append_column (GTK_TREE_VIEW (my_tree_view), my_column); gtk_tree_store_set (my_list_store, &child_iter, my_column, "one", -1);
gtk_tree_view_append_column (GTK_TREE_VIEW (my_tree_view), my_column); gtk_tree_store_set (my_list_store, &child_iter, my_column, "two", -1);
GtkWidget *my_expander = gtk_expander_new ("my_expander");
gtk_expander_set_child (my_expander, NULL); // *child); how to ?
on_activating_this_expander (my_expander, NULL); // gpointer user_data) The “activate” signal
printf("%s\n", gtk_expander_get_label (my_expander)); // < OK
// GtkWidget my_column = *gtk_column_view_new (my_selection_model);
/* GtkWidget *treeview; */
/* treeview = gtk_tree_view_new_with_model (my_selection_model); */
/* gtk_widget_set_vexpand (treeview, TRUE); */
/* gtk_tree_view_set_search_column (GTK_TREE_VIEW (treeview), */
/* COLUMN_DESCRIPTION); */
GtkTreeListModel *my_tree_list_model =
gtk_tree_list_model_new (my_selection_model,
1,
1,
item_create_func,
NULL,
NULL);
GtkWidget *my_list_view = gtk_list_view_new (GTK_SELECTION_MODEL (my_selection_model), my_list_item_factory);
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_tree_view); // use my_tree_view instead of my_list_view
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (in_that_box), my_list_view); // use my_tree_view instead of my_list_view
}
void on_activate_window_creation (GtkApplication *app, gpointer data) {
//-------------------------------------------------------------------------------------------------------------------------------------------
void on_activate_window_creation (GtkApplication *app, gpointer data)
{
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");
@ -236,7 +134,8 @@ void on_activate_window_creation (GtkApplication *app, gpointer data) {
//
// GtkColumnView
//
// https://toshiocp.github.io/Gtk4-tutorial/sec29.html https://docs.gtk.org/gtk4/section-tree-widget.html
// https://toshiocp.github.io/Gtk4-tutorial/sec29.html
// https://docs.gtk.org/gtk4/section-list-widget.html
// https://www.typeerror.org/docs/gtk~4.0/ https://www.typeerror.org/docs/gtk~4.0/gtktreemodel
// https://docs.gtk.org/#user-interface https://docs.gtk.org/gtk4/ https://docs.gtk.org/glib/ https://docs.gtk.org/gio/