From e0b05189c3230b41ab5070805c35d897c377479c Mon Sep 17 00:00:00 2001 From: Jean Sirmai Date: Sat, 25 May 2024 08:58:30 +0200 Subject: [PATCH] WIP: cleaning ... --- include/contain.h | 2 +- include/hot.h | 9 +++++ include/ui.h | 8 ++++- src/ui/application.c | 78 +++++++++++++++++++++----------------------- src/ui/contain.c | 4 +-- src/ui/hot.c | 6 ++-- src/ui/views.c | 66 ------------------------------------- 7 files changed, 59 insertions(+), 114 deletions(-) diff --git a/include/contain.h b/include/contain.h index f19141e..a082e55 100644 --- a/include/contain.h +++ b/include/contain.h @@ -18,5 +18,5 @@ #define H_IMAGE_LOCAL H / 16 GtkWidget *get_selected_rules_vpaned_new(); -void experimental_activate (GtkApplication *app, gpointer user_data); +void experimental_activate_00 (GtkApplication *app, GtkWindow *window); void window_bar(GtkWindow *window, char *title); diff --git a/include/hot.h b/include/hot.h index 102ff4a..ba38ca0 100644 --- a/include/hot.h +++ b/include/hot.h @@ -11,5 +11,14 @@ #include "contain.h" #include +// Simplified TreeNode structure for demonstration purposes +struct TreeNode_t +{ + gchar *text; + struct TreeNode_t *child; + struct TreeNode_t *next; +}; +struct TreeNode_t *create_tree_node (const gchar* text); +void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child); GtkScrolledWindow *get_user_rules_tree (); void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root); diff --git a/include/ui.h b/include/ui.h index ffa33d8..3d7d740 100644 --- a/include/ui.h +++ b/include/ui.h @@ -28,7 +28,13 @@ #include "../include/base.h" -#define COMMUTE 0 +// Gem-graph successive realizations +enum +{ + GG_2023, + GG_2024_05, + GG_2024_06 +}; #define W 1920 #define H 960 diff --git a/src/ui/application.c b/src/ui/application.c index 4a9cef2..37d9465 100644 --- a/src/ui/application.c +++ b/src/ui/application.c @@ -22,23 +22,53 @@ * along with this program. If not, see . */ -#include "../../include/base.h" #include "../../include/ui.h" -struct _GemGraphClientApplication +#define COMMUTE 0 // 0 first design (2023) based on XML data + // 1 2024 May design, free of the XML encryption mechanism + +/* Window actual presentation on screen */ +static void gem_graph_client_application_activate (GApplication *app) { - GtkApplication parent_instance; -}; + GtkWindow *window; + + g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION (app)); + + window = GTK_WINDOW (gtk_application_get_active_window (GTK_APPLICATION (app))); + if (window == NULL) + window = GTK_WINDOW (g_object_new (GEM_GRAPH_CLIENT_TYPE_WINDOW, + "application", app, + NULL)); + + switch(COMMUTE) { // enum {...} in ui.h + case GG_2023: + // Launch with sidebar of gtk_notebook_append_pagef + ui_toggle_sidebar(); + ui_set_stack (HOME_MODE); + ui_debug_model_loading (window, "data/models/dimers random walk.xml"); + // XXX the window closes when a leaf expander is clicked (Erreur de segmentation) + break; + case GG_2024_05: + // see > in contain.c + experimental_activate_00 (app, window); + break; + default: + break; + } + + gtk_window_present (GTK_WINDOW (window)); +} + +/* -------------------------------------------------------------------------- */ + +struct _GemGraphClientApplication {GtkApplication parent_instance;}; G_DEFINE_TYPE (GemGraphClientApplication, gem_graph_client_application, GTK_TYPE_APPLICATION) - static GemGraphClientApplication *application; -/* -------------------------------------------------------------------------- */ - void ui_enable_action(const char *name) { g_simple_action_set_enabled( (GSimpleAction *)g_action_map_lookup_action( @@ -55,38 +85,6 @@ void ui_disable_action(const char *name) { false); } -/* - * Window actual presentation on screen - * - */ -static void gem_graph_client_application_activate(GApplication *app) -{ - if (COMMUTE) { - - GtkWindow *window; - - g_assert(GEM_GRAPH_CLIENT_IS_APPLICATION (app)); - - window = gtk_application_get_active_window (GTK_APPLICATION (app)); - if (window == NULL) - window = g_object_new (GEM_GRAPH_CLIENT_TYPE_WINDOW, - "application", app, - NULL); - - // Launch with sidebar off - ui_toggle_sidebar(); - ui_set_stack (HOME_MODE); - ui_debug_model_loading (window, "data/models/dimers random walk.xml"); - - gtk_window_present (window); - - } else { - - char *user_data = NULL; - experimental_activate (app, user_data); // see > contain.c - } -} - /* * Action records are registered here * @@ -121,7 +119,7 @@ static void gem_graph_client_application_init(GemGraphClientApplication *self) void ui_send_notification(const char *message) { g_print("NOTIFICATION: %s\n", message); - g_application_send_notification(G_APPLICATION(application), "notification", g_notification_new(message)); + g_application_send_notification (G_APPLICATION (application), "notification", g_notification_new(message)); } /* -------------------------------------------------------------------------- */ diff --git a/src/ui/contain.c b/src/ui/contain.c index 55764a0..b4cbd61 100644 --- a/src/ui/contain.c +++ b/src/ui/contain.c @@ -177,8 +177,7 @@ void window_bar(GtkWindow *window, char *title){ // gtk_window_controls_set_decoration_layout (GTK_WINDOW_CONTROLS(my_window_controls), NULL); // const char* layout); } -void experimental_activate (GtkApplication *app, gpointer user_data) { - GtkWindow *window = GTK_WINDOW (gtk_application_window_new (app)); +void experimental_activate_00 (GtkApplication *app, GtkWindow *window) { window_bar (window, "E coli (with permission from David S. Goodsell, 2009)"); GtkNotebook *run_notebook = GTK_NOTEBOOK(gtk_notebook_new()); @@ -207,7 +206,6 @@ void experimental_activate (GtkApplication *app, gpointer user_data) { gtk_paned_set_end_child (GTK_PANED(run_xor_edit_horizontal_pane), GTK_WIDGET (edit_notebook)); gtk_paned_set_position (GTK_PANED (run_xor_edit_horizontal_pane), W_IMAGE + 350); // '350' : AD HOC gtk_window_set_child (window, GTK_WIDGET(run_xor_edit_horizontal_pane)); - gtk_window_present (GTK_WINDOW (window)); gtk_notebook_set_current_page (run_notebook, 1); // @see hot.c 2024-05-11 (line 68) gtk_notebook_set_current_page (edit_notebook, 1); // @see hot.c 2024-05-11 (line 68) diff --git a/src/ui/hot.c b/src/ui/hot.c index 43da9e8..5956ece 100644 --- a/src/ui/hot.c +++ b/src/ui/hot.c @@ -20,7 +20,7 @@ static struct TreeNode_t *create_user_tree_node (const gchar* text){ return node; } -static struct TreeNode_t *create_tree_node (const gchar* text) +struct TreeNode_t *create_tree_node (const gchar* text) { struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); node->text = g_strdup(text); @@ -29,7 +29,7 @@ static struct TreeNode_t *create_tree_node (const gchar* text) } // Function to add a child node to a parent node -static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child) +void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child) { struct TreeNode_t *cur; @@ -44,7 +44,7 @@ static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child) } } -void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root){ +void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root) { struct TreeNode_t *a = create_tree_node("We, the people");add_child_node(tree_root, a); struct TreeNode_t *b = create_tree_node("in Order to"); add_child_node(tree_root, b); struct TreeNode_t *c = create_tree_node("do establish"); add_child_node(tree_root, c); diff --git a/src/ui/views.c b/src/ui/views.c index e5fd1f0..3819c53 100644 --- a/src/ui/views.c +++ b/src/ui/views.c @@ -32,69 +32,6 @@ #include "../../include/ui.h" #include "../../include/hot.h" -// Simplified TreeNode structure for demonstration purposes -struct TreeNode_t -{ - gchar *text; - struct TreeNode_t *child; - struct TreeNode_t *next; -}; - -// Function to create a new TreeNode instance -static struct TreeNode_t *create_tree_node (const gchar* text) -{ - struct TreeNode_t *node = g_malloc0 (sizeof(struct TreeNode_t)); - node->text = g_strdup(text); - node->child = NULL; - return node; -} - -// Function to add a child node to a parent node -static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child) -{ - struct TreeNode_t *cur; - - if (parent->child) { - cur = parent->child; - while (cur && cur->next) { - cur = cur->next; - } - cur->next = child; - } else { - parent->child = child; - } -} - -void create_experimental_tree (struct TreeNode_t *tree_root) // AD HOC XXX & no free() -{ - struct TreeNode_t *a = create_tree_node("We, the people");add_child_node(tree_root, a); - struct TreeNode_t *b = create_tree_node("in Order to"); add_child_node(tree_root, b); - struct TreeNode_t *c = create_tree_node("do establish"); add_child_node(tree_root, c); - struct TreeNode_t *aa = create_tree_node("aware of"); add_child_node(a, aa); - struct TreeNode_t *aaa = create_tree_node("our rights"); add_child_node(aa, aaa); - struct TreeNode_t *aab = create_tree_node("our duties"); add_child_node(aa, aab); - struct TreeNode_t *aaaa = create_tree_node("read"); add_child_node(aaa, aaaa); - struct TreeNode_t *aaab = create_tree_node("write"); add_child_node(aaa, aaab); - struct TreeNode_t *aaac = create_tree_node("copy"); add_child_node(aaa, aaac); - struct TreeNode_t *aaad = create_tree_node("edit"); add_child_node(aaa, aaad); - struct TreeNode_t *aaada= create_tree_node("create"); add_child_node(aaad, aaada); - struct TreeNode_t *aaadb= create_tree_node("publish"); add_child_node(aaad, aaadb); - struct TreeNode_t *aaba = create_tree_node("learn"); add_child_node(aab, aaba); - struct TreeNode_t *aabb = create_tree_node("help"); add_child_node(aab, aabb); - struct TreeNode_t *ba = create_tree_node("promote"); add_child_node(b, ba); - struct TreeNode_t *bb = create_tree_node("individual"); add_child_node(b, bb); - struct TreeNode_t *bc = create_tree_node("and common"); add_child_node(b, bc); - struct TreeNode_t *bca = create_tree_node("education"); add_child_node(bc, bca); - struct TreeNode_t *bcb = create_tree_node("mutual"); add_child_node(bc, bcb); - struct TreeNode_t *bcc = create_tree_node("support"); add_child_node(bc, bcc); - struct TreeNode_t *bcd = create_tree_node("health"); add_child_node(bc, bcd); - struct TreeNode_t *bcda = create_tree_node("mental"); add_child_node(bcd, bcda); - struct TreeNode_t *bcdb = create_tree_node("physical"); add_child_node(bcd, bcdb); - struct TreeNode_t *ca = create_tree_node("free"); add_child_node(c, ca); - struct TreeNode_t *cb = create_tree_node("code"); add_child_node(c, cb); - struct TreeNode_t *cc = create_tree_node("access"); add_child_node(c, cc); -} - // Recursive function to free a TreeNode and its children static void free_tree_node (struct TreeNode_t *node) { @@ -197,9 +134,6 @@ void ui_create_tree (GtkWidget *target_widget) struct TreeNode_t *tree_root = create_tree_node("Declaration"); let_us_create_a_complex_useless_and_expensive_tree (tree_root); -// struct TreeNode_t *tree_root = create_tree_node ("Declaration"); - // create_experimental_tree (tree_root); -// get_user_rules_tree (tree_root); model = gtk_string_list_new(NULL); gtk_string_list_append(model, tree_root->text);