From 3635308cf584dabe3d1346fdb8c801c8d69c437d Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Tue, 2 Jan 2024 19:50:42 +0100 Subject: [PATCH] WIP: removing deprec : in gtk/gtk.h line 93 --- demos/gtk-demo/tree_store.c | 62 ++++++++++++++++++------------------- gtk/gtk.h | 2 +- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/demos/gtk-demo/tree_store.c b/demos/gtk-demo/tree_store.c index 36f6dba..3b383e4 100644 --- a/demos/gtk-demo/tree_store.c +++ b/demos/gtk-demo/tree_store.c @@ -38,7 +38,7 @@ /* Finds the path at the point (x , y ), relative to bin_window coordinates. Use gtk_tree_view_convert_widget_to_bin_window_coords(). */ /* https://www.gnu.org/software/guile-gnome/docs/gtk/html/GtkCellRenderer.html */ /* GtkTreeSelection, GtkTreeView drag-and-drop, GtkTreeSortable, GtkTreeModelSort, GtkCellEditable, GtkCellRendererText,... */ -/* gtk_tree_view_get_search_entry (treeview) */ +/* gtk_tree_view_get_search_entry (treeview) https://blog.gtk.org/2020/09/08/on-list-models/ */ /* */ /****************************************************************************************************************************************/ @@ -149,7 +149,7 @@ static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}}; static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry -static GtkTreeModel *create_node_recursive (GtkTreeStore *model, +static GListModel *create_node_recursive (GtkTreeStore *model, TreeItem *current_item, GtkTreeIter *iter_parent, int depth) @@ -173,7 +173,7 @@ static GtkTreeModel *create_node_recursive (GtkTreeStore *model, } if (depth == 0) - return GTK_TREE_MODEL(model); // cast from GtkTreeModel to GtkTreeStore + return G_LIST_MODEL(model); // cast from GtkTreeModel to GListModel or GtkTreeStore else return NULL; } @@ -187,56 +187,54 @@ do_tree_store (GtkWidget *do_widget) if (! my_window) { - GtkWidget *vbox; - GtkWidget *sw; // sw : 'scrolled_window' - GtkWidget *treeview; - GtkTreeModel *my_tree_model; // TODO replace by : GListModel *my_list_model; - GtkTreeStore *my_tree_store = NULL; // TODO replace by : GtkTreeListModel *my_tree_list_model; - // https://docs.gtk.org/gio/property.ListStore.n-items.html + GtkWidget *my_tree_box; + GtkWidget *my_scrolled_window; + GtkWidget *my_tree_view; + GListModel *my_list_model = NULL; /* create window, etc */ my_window = gtk_window_new (); gtk_window_set_title (GTK_WINDOW (my_window), "Tree Store"); g_object_add_weak_pointer (G_OBJECT (my_window), (gpointer *)&my_window); - vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); - gtk_widget_set_margin_start (vbox, 8); - gtk_widget_set_margin_end (vbox, 8); - gtk_widget_set_margin_top (vbox, 8); - gtk_widget_set_margin_bottom (vbox, 8); - gtk_window_set_child (GTK_WINDOW (my_window), vbox); + my_tree_box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8); + gtk_widget_set_margin_start (my_tree_box, 8); + gtk_widget_set_margin_end (my_tree_box, 8); + gtk_widget_set_margin_top (my_tree_box, 8); + gtk_widget_set_margin_bottom (my_tree_box, 8); + gtk_window_set_child (GTK_WINDOW (my_window), my_tree_box); - gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Learning GTK trees")); + gtk_box_append (GTK_BOX (my_tree_box), gtk_label_new ("Learning GTK trees")); - sw = gtk_scrolled_window_new (); - gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), + 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 (GTK_BOX (vbox), sw); + gtk_box_append (GTK_BOX (my_tree_box), my_scrolled_window); /* create tree_model */ - my_tree_model = create_node_recursive (my_tree_store, O, NULL, 0); + my_list_model = create_node_recursive (my_list_model, O, NULL, 0); /* create tree view */ - treeview = gtk_tree_view_new_with_model (my_tree_model); - gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (treeview), FALSE); - gtk_tree_view_set_enable_tree_lines (GTK_TREE_VIEW (treeview), TRUE); - gtk_widget_set_vexpand (treeview, TRUE); - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)), + my_tree_view = gtk_tree_view_new_with_model (my_list_model); + 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 (treeview), TRUE); - g_object_unref (my_tree_model); + gtk_tree_view_set_reorderable (GTK_TREE_VIEW (my_tree_view), TRUE); + g_object_unref (my_list_model); GtkCellRenderer *renderer; renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL); - gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (my_tree_view), -1, "Col 0", renderer, "text", STRING_COLUMN, NULL); - gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), treeview); + gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (my_scrolled_window), my_tree_view); - /* expand all rows after the treeview widget has been realized */ - g_signal_connect (treeview, "realize", + /* 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); gtk_window_set_default_size (GTK_WINDOW (my_window), 200, 400); } diff --git a/gtk/gtk.h b/gtk/gtk.h index 6e20f7b..bc29028 100644 --- a/gtk/gtk.h +++ b/gtk/gtk.h @@ -90,7 +90,7 @@ #include #include #include -#include +//#include #include #include #include