Compare commits

...

2 Commits

3 changed files with 136 additions and 167 deletions

View File

@ -0,0 +1,78 @@
/**************** 2024-01-06 À la chasse aux widgets ! ****************/
/* in > 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo */
/* */
/* tree_store() listview_words() editable_cells() search_entry2() */
/* dnd()(= drag and drop) entry_undo() expander() textundo() */
/* scale() (= scale entries from bars) font_features() hypertext() */
/* iconview_edit() (= drag and drop icons) image_scaling() infobar() */
/* links() listbox_controls() list_store() listview_colors() */
/* listview_selections() mask(NULL) and more... */
/* */
/******************************************************************************/
/*************** The basic ideas behind list views: *******************/
/* */
/* The data for items is provided in the form of a model containing objects */
/* Widgets are created just for the viewable range of items */
/* Widgets can be recycled by binding them to different items */
/* Avoid iterating over all items in the model as much as possible, and */
/* just deal with the items in the visible range which are bound to widgets */
/* from https://blog.gtk.org/2020/06/07/scalable-lists-in-gtk-4/ */
/* */
/******************************************************************************/
// GtkListItemFactory is the object that is tasked with creating widgets
// for the items in the model.
// One implementations of this factory, GtkBuilderListItemFactory,
// is using ui files as templates for the list item widgets.
/*************** A B O U T T R E E S **************************/
/* */
/* https://docs.gtk.org/gtk4/ */
/* https://docs.gtk.org/gtk4/getting_started.html */
/* https://toshiocp.github.io/Gtk4-tutorial/sec29.html <<< TODO (tuto) */
/* Keep the "comparison chart of equivalent functionalities" (link below) */
/* https://docs.gtk.org/gtk4/section-list-widget.html */
/* https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View */
/* https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html */
/* https://docs.gtk.org/gio/iface.ListModel.html < +++ */
/* */
/* https://docs.gtk.org/gtk4/class.TreeListModel.html (easy to find) */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html (vieux...) */
/* get-path-at-pos(x,y) finds the path at these window coordinates. */
/* https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */
/******************************************************************************/
/*..............................................................................
*
* >>> GtkStringList <<<
*
* GtkStringList is a list model that wraps an array of strings.
* The objects in the model are of type GtkStringObject
* and have a “string” property that can be used inside expressions.
* Use it where/when you would typically use a char*[], but need a list model.
*
* Every item in a model has a position (= unsigned integer)
* "factories" takes care of mapping the items of the model
* to widgets that can be shown in the view
* by creating a listitem for each item that is currently in use.
* List items are always GtkListItem instances. Widgets can be recycled.
*
* GtkStringList can only handle strings.
* It is backed by a dynamically allocated array.
* GListStore is backed by a balanced tree.
*
* GTK provides functionality to make lists look and behave like trees
* by using the GtkTreeListModel and the GtkTreeExpander widget.
*
* Widgets are styleable using GTK CSS. Use the .rich-list style class.
*
* GListModel is an interface that represents a mutable list of GObjects.
*
*............................................................................*/

View File

@ -21,136 +21,55 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*----------------------------------------------------------------------------*/
/**************** 2024-01-06 À la chasse aux widgets ! ****************/
/* in > 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo */
/* */
/* tree_store() listview_words() editable_cells() search_entry2() */
/* dnd()(= drag and drop) entry_undo() expander() textundo() */
/* scale() (= scale entries from bars) font_features() hypertext() */
/* iconview_edit() (= drag and drop icons) image_scaling() infobar() */
/* links() listbox_controls() list_store() listview_colors() */
/* listview_selections() mask(NULL) and more... */
/* */
/* (1) Je recopie les fragments de code qui me semblent utiles */
/* tirés de demos/gtk-demo/main.c et de la liste suivante */
/*----------------------------------------------------------------------------*/
// https://www.gtk.org/
/******************************************************************************/
/* */
/* W I N D O W = D O _ S O M E _ A P P L I C A T I O N _ E X A M P L E */
/* */
// window = do_tree_store(NULL);
// window = do_listview_words(NULL);
// window = do_editable_cells(NULL);
// window = do_dnd(NULL); // drag and drop
// window = do_drawingarea(NULL);
// window = do_entry_undo(NULL);
// window = do_expander(NULL);
// window = do_textundo(NULL);
// window = do_search_entry2(NULL);
// window = do_scale(NULL); // scale entries from bars
// window = do_font_features(NULL);
// window = do_hypertext(NULL);
// window = do_iconview_edit(NULL); // drag and drop
// window = do_image_scaling(NULL);
// window = do_infobar(NULL);
// window = do_links(NULL);
// window = do_listbox_controls(NULL);
// window = do_list_store(NULL);
// window = do_listview_colors(NULL);
// window = do_listview_selections(NULL);
// window = do_mask(NULL);
/*************** The basic ideas behind list views: *******************/
/* */
/* The data for items is provided in the form of a model containing objects */
/* Widgets are created just for the viewable range of items */
/* Widgets can be recycled by binding them to different items */
/* Avoid iterating over all items in the model as much as possible, and */
/* just deal with the items in the visible range which are bound to widgets */
/* from https://blog.gtk.org/2020/06/07/scalable-lists-in-gtk-4/ */
/* */
/******************************************************************************/
/* Old links ( deprec ? ) (To check before removing).
https://blog.gtk.org/2020/06/08/more-on-lists-in-gtk-4/
https://docs.gtk.org/gtk4/section-list-widget.html
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Tree_Models
https://stackoverflow.com/questions/74556059/how-to-build-a-tree-in-gtk4-4-10
https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer
*/
/******************************************** The basic ideas behind list views: ************************************************/
/* */
/* The data for items is provided in the form of a model (containing objects) */
/* Widgets are created just for the viewable range of items */
/* Widgets can be recycled by binding them to different items */
/* Avoid iterating over all items in the model as much as possible, */
/* and just deal with the items in the visible range which are bound to widgets */
/* from https://blog.gtk.org/2020/06/07/scalable-lists-in-gtk-4/ */
/* */
/****************************************************************************************************************************************/
// GtkListItemFactory is the object that is tasked with creating widgets for the items in the model.
// One implementations of this factory, GtkBuilderListItemFactory, is using ui files as templates for the list item widgets.
// https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_settings.ui
/* Lists/Application launcher #Keywords: GtkListItemFactory, GListModel
* This demo uses the GtkListView widget as a fancy application launcher. It is also a very small introduction to listviews.
* https://gitlab.gnome.org/GNOME/gtk/-/blob/main/demos/gtk-demo/listview_applauncher.c */
/************************************************** W I D G E T S ********************************************************/
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/* _ _ _ _ _ _ _ _ _ _ _ _ _ E D I T A B L E _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/* */
/* https://developer-old.gnome.org/gtk4/stable/ch03s02.html Which widget should I use ?... */
/* https://developer-old.gnome.org/gtk4/stable/GtkCellEditable.html#GtkCellEditable-struct */
/* The GtkCellEditable interface must be implemented for widgets to be usable to edit the contents of a GtkTreeView cell. */
/* It provides a way to specify how temporary widgets should be configured for editing, get the new value, etc. */
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/* _ _ _ _ _ _ _ _ _ _ _ _ _ _ T R E E _ _ _ _ _ _ _ _ _ _ _ _ _ _ */
/* */
/* https://toshiocp.github.io/Gtk4-tutorial/sec29.html <<< TODO */
/* 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/class.TreeListModel.html */
/* */
/* */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html */
/* https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Custom_Models */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeSelection.html#GtkTreeSelection-struct */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html#gtk-tree-view-get-path-at-pos << get-path-at-pos */
/* 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) https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */
/****************************************************************************************************************************************/
// ? utile ?
// gtk_tree_model_foreach (model, TRUE, my_user_data); https://developer-old.gnome.org/gtk4/stable/GtkTreeModel.html#GtkTreeModelForeachFunc
/* ... Finally heres a quick comparison chart of equivalent functionalitqy
to look for when transitioning code:
Old New
..................................................................
GtkTreeModel GListModel
GtkTreePath guint position, GtkTreeListRow
GtkTreeIter guint position
GtkTreeRowReference GObject item
GtkListStore GListStore
GtkTreeStore GtkTreeListModel, GtkTreeExpander
GtkTreeSelection GtkSelectionModel
GtkTreeViewColumn GtkColumnView
GtkTreeView GtkListView, GtkColumnView
GtkCellView GtkListItem
GtkComboBox GtkDropDown
GtkIconView GtkGridView
GtkTreeSortable GtkColumnView
GtkTreeModelSort GtkSortListModel
GtkTreeModelFilter GtkFilterListModel
GtkCellLayout GtkListItemFactory
GtkCellArea GtkWidget
GtkCellRenderer GtkWidget
..............................................................................*/
// GtkListItemFactory is the object that is tasked with creating widgets
// for the items in the model.
// One implementations of this factory, GtkBuilderListItemFactory,
// is using ui files as templates for the list item widgets.
/*************** A B O U T T R E E S **************************/
/* */
/* https://docs.gtk.org/gtk4/ */
/* https://docs.gtk.org/gtk4/getting_started.html */
/* https://toshiocp.github.io/Gtk4-tutorial/sec29.html <<< TODO (tuto) */
/* Keep the "comparison chart of equivalent functionalities" (link below) */
/* https://docs.gtk.org/gtk4/section-list-widget.html */
/* https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View */
/* https://gnome.pages.gitlab.gnome.org/libsoup/gio/GListModel.html */
/* https://docs.gtk.org/gio/iface.ListModel.html < +++ */
/* */
/* https://docs.gtk.org/gtk4/class.TreeListModel.html (easy to find) */
/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html (vieux...) */
/* get-path-at-pos(x,y) finds the path at these window coordinates. */
/* https://blog.gtk.org/2020/09/08/on-list-models/ */
/* */
/******************************************************************************/
/*..............................................................................
*
@ -161,24 +80,14 @@ https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer
* and have a string property that can be used inside expressions.
* Use it where/when you would typically use a char*[], but need a list model.
*
* implements GtkBuildable interface
* <item> are GObject instances; support translatable, context and comments
*
* <object class="GtkStringList">
* <items>
* <item translatable="yes">Factory</item>
* <item translatable="yes">Home</item>
* <item translatable="yes">Subway</item>
* </items>
* </object>
*
* Every item in a model has a position (= unsigned integer)
* "factories" takes care of mapping the items of the model
* to widgets that can be shown in the view
* by creating a listitem for each item that is currently in use.
* List items are always GtkListItem instances. Widgets can be recycled.
*
* GtkStringList can only handle strings. It is backed by a dynamically allocated array.
* GtkStringList can only handle strings.
* It is backed by a dynamically allocated array.
* GListStore is backed by a balanced tree.
*
* GTK provides functionality to make lists look and behave like trees
@ -186,11 +95,7 @@ https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer
*
* 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
* https://docs.gtk.org/gio/iface.ListModel.html < +++
* https://blog.gtk.org/2020/09/08/on-list-models/
*
*............................................................................*/
@ -204,8 +109,6 @@ https://en.wikibooks.org/wiki/GTK%2B_By_Example/Tree_View/Columns_and_Renderer
#include <gtk/gtk.h>
#include <stdio.h>
//#include "config.h"
//#include "custom-list.h"
#include <gio/gio.h>
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
@ -235,13 +138,15 @@ static TreeItem R[] = {{"A", A}, {"B", B}, {"C", C}, {NULL}};
static TreeItem O[] = {{"ROOT", R}, {NULL}}; // Artefact added for symmetry
// TODO GtkTreeListModel ? GtkTreeModel ? (lines 238 & 270)
static GListStore *create_node_recursive (GListStore *model, // GListStore* g_list_store_new (GType item_type)
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);
@ -258,18 +163,18 @@ static GListStore *create_node_recursive (GListStore *model, // GListStore* g_
}
if (depth == 0)
return G_LIST_STORE(model); // Should we cast to GtkTreeStore ?
return G_LIST_STORE(model); // Should we cast 'model' to GtkTreeStore ?
else
return NULL;
}
GtkWidget *create_my_list_model(GtkBox *runlib_objects)
{
GtkWidget *my_tree_box;
GtkWidget *my_scrolled_window;
GtkWidget *my_tree_box = NULL;
GtkWidget *my_scrolled_window = NULL;
GListStore *my_list_model = NULL;
GtkWidget *my_tree_view = NULL;
GtkCellRenderer *renderer;
GtkCellRenderer *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);
@ -324,10 +229,8 @@ GtkWidget *create_a_button(GtkBox *runlib_objects)
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
printf("------------------------------------------ tree.c line 327\n\
The speed makefile bug has been fixed in branch [devel]\n\
NB Here, we are in branch [origin/dev/ui-simple-tree]\n\
TODO : 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo\n");
printf("--------------------------------------------- tree.c line 232\n\
my widgets' tank : 01/GTK4/tree (learning)/The_Gnome_way/demos/gtk-demo\n");
return button;
}

View File

@ -33,11 +33,6 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
#include "../../include/base.h"
#include "../../include/ui.h"
/* https://docs.gtk.org/gtk4/getting_started.html
https://docs.gtk.org/gobject/#functions
https://docs.gtk.org/gtk4/class.Label.html?q=
https://docs.gtk.org/gtk4/ctor.Button.new_with_label.html
*/
/*
* window.c décrit tout ce qui concerne les différents widgets disposés dans la fenêtre
* et qui ne peut être décrit dans le fichier XML (statique) gemgraph.ui
@ -53,11 +48,11 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
float rotation_angles[N_AXIS] = { 0.0 }; // Rotation angles on each axis
GtkWidget *gl_area = NULL;
GtkWidget *my_tree = NULL;
GtkWidget *my_button = NULL;
GemGraphClientWindow *window;
/* -------------------------------------------------------------------------- */
struct _GemGraphClientWindow
{
GtkApplicationWindow parent_instance;
@ -126,19 +121,12 @@ static void gem_graph_client_window_init(GemGraphClientWindow *self)
//XXX TEMP ui_setup_glarea(window->run_glarea, window->run_controls);
}
/*
Is this useful ? (Does it 'FREE' something ?)
if (!gtk_widget_get_visible (my_window))
gtk_widget_set_visible (my_window, TRUE);
else
gtk_window_destroy (GTK_WINDOW (my_window));
*/
/* -------------------------------------------------------------------------- */
GtkWidget *my_tree = NULL;
GtkWidget *my_button = NULL;
/* Is this used to 'FREE' something and must be preserved ? */
/* */
/* if (!gtk_widget_get_visible (my_window)) */
/* gtk_widget_set_visible (my_window, TRUE); */
/* else */
/* gtk_window_destroy (GTK_WINDOW (my_window)); */
void ui_set_stack(const char *mode)
{