2023-11-09 06:58:48 +01:00
|
|
|
|
/*
|
|
|
|
|
* 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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/**************** 2024-01-06 À la chasse aux widgets ! ****************/
|
|
|
|
|
/* */
|
|
|
|
|
/* (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);
|
|
|
|
|
|
|
|
|
|
/* */
|
|
|
|
|
/******************************************************************************/
|
2023-11-09 06:58:48 +01:00
|
|
|
|
|
2023-11-25 08:59:48 +01:00
|
|
|
|
|
2023-11-30 19:50:18 +01:00
|
|
|
|
/*
|
2024-01-07 21:52:17 +01:00
|
|
|
|
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
|
|
|
|
|
*/
|
2024-01-05 17:46:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
/******************************************** 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 here’s 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
|
|
|
|
|
..............................................................................*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*..............................................................................
|
|
|
|
|
*
|
|
|
|
|
* >>> 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.
|
|
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
* 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.
|
|
|
|
|
* 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/
|
|
|
|
|
*
|
|
|
|
|
*............................................................................*/
|
2023-11-24 16:34:06 +01:00
|
|
|
|
|
2024-01-05 17:46:14 +01:00
|
|
|
|
|
2024-01-07 23:33:47 +01:00
|
|
|
|
/* M A N I F E S T <<< J'AI TOUT VIRÉ SAUF "make" */
|
|
|
|
|
/* ;; */
|
|
|
|
|
/* ;; Dépendances sous GNU Guix */
|
|
|
|
|
/* ;; */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* (specifications->manifest */
|
|
|
|
|
/* (list */
|
|
|
|
|
/* "bash" */
|
|
|
|
|
/* "coreutils" */
|
|
|
|
|
/* "gcc-toolchain" */
|
|
|
|
|
/* "pkg-config" */
|
|
|
|
|
/* "valgrind" */
|
|
|
|
|
/* "findutils" */
|
|
|
|
|
/* "gdb" */
|
|
|
|
|
/* "make" <<<<<<<<<<<< */
|
|
|
|
|
/* "gtk" */
|
|
|
|
|
/* "libxml2" */
|
|
|
|
|
/* "glew" */
|
|
|
|
|
/* "glfw" */
|
|
|
|
|
/* "libepoxy" */
|
|
|
|
|
/* "pango@1.90.0" */
|
|
|
|
|
/* "xorgproto" */
|
|
|
|
|
/* "glib" */
|
|
|
|
|
/* "mesa-headers" */
|
|
|
|
|
/* "mesa" */
|
|
|
|
|
/* "libadwaita" */
|
|
|
|
|
/* ) */
|
|
|
|
|
/* ) */
|
2024-01-05 17:46:14 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <gtk-4.0/gtk/gtk.h>
|
|
|
|
|
#include <glib-2.0/glib.h>
|
2023-11-24 17:57:44 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
#include "../../include/base.h"
|
|
|
|
|
#include "../../include/ui.h"
|
2023-11-24 18:18:32 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
//#include "config.h"
|
|
|
|
|
//#include "custom-list.h"
|
|
|
|
|
#include <gio/gio.h>
|
2023-11-24 18:18:32 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
2023-11-24 18:18:32 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
enum
|
|
|
|
|
{
|
|
|
|
|
STRING_COLUMN,
|
|
|
|
|
NUM_COLUMNS
|
|
|
|
|
};
|
2023-11-24 18:18:32 +01:00
|
|
|
|
|
2023-11-25 08:14:39 +01:00
|
|
|
|
|
2024-01-07 21:52:17 +01:00
|
|
|
|
/* 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 GListStore *create_node_recursive (GListModel *model, // GListStore* g_list_store_new (GType item_type) */
|
|
|
|
|
/* TreeItem *current_item, */
|
|
|
|
|
/* GtkTreeIter *iter_parent, */
|
|
|
|
|
/* int depth) */
|
|
|
|
|
/* { */
|
|
|
|
|
/* GtkTreeIter iter; */
|
|
|
|
|
|
|
|
|
|
/* if (model == NULL) */
|
|
|
|
|
/* model = gtk_tree_store_new (NUM_COLUMNS, G_TYPE_STRING); */
|
|
|
|
|
|
|
|
|
|
/* 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 G_LIST_MODEL(model); // can cast to GListModel or to GtkTreeStore ? */
|
|
|
|
|
/* else */
|
|
|
|
|
/* return NULL; */
|
|
|
|
|
/* } */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-01-07 23:33:47 +01:00
|
|
|
|
static void
|
|
|
|
|
print_hello (GtkWidget *widget,
|
|
|
|
|
gpointer data)
|
|
|
|
|
{
|
|
|
|
|
static int nb;
|
|
|
|
|
nb++;
|
|
|
|
|
printf("Button clicked (n = %d)\n", nb);
|
|
|
|
|
}
|
2024-01-07 21:52:17 +01:00
|
|
|
|
|
2024-01-07 23:33:47 +01:00
|
|
|
|
GtkWidget *create_a_button_to_click_on(GemGraphClientWindow *my_window)
|
|
|
|
|
{
|
|
|
|
|
GtkWidget *button;
|
|
|
|
|
const char *text = "Hello ! I'm the new button. Click me !";
|
2024-01-07 21:52:17 +01:00
|
|
|
|
|
2024-01-07 23:33:47 +01:00
|
|
|
|
button = gtk_button_new_with_label(text);
|
|
|
|
|
gtk_box_append(GTK_BOX(my_window->runlib_objects), button);
|
|
|
|
|
gtk_widget_show(button);
|
2024-01-07 21:52:17 +01:00
|
|
|
|
|
2024-01-07 23:33:47 +01:00
|
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (print_hello), NULL);
|
2024-01-07 21:52:17 +01:00
|
|
|
|
|
2024-01-05 17:46:14 +01:00
|
|
|
|
printf("tree.c > print test() \
|
2024-01-07 21:52:17 +01:00
|
|
|
|
------------------------------------\nClick the 'new button' in the GtkBox.\n");
|
2024-01-07 23:33:47 +01:00
|
|
|
|
|
|
|
|
|
return button;
|
2023-11-24 18:18:32 +01:00
|
|
|
|
}
|
|
|
|
|
|