WIP: regroupement des fonctions callback

This commit is contained in:
Jean Sirmai 2024-06-02 22:14:24 +02:00
parent 59e6c779fd
commit 391941d200
Signed by: jean
GPG Key ID: FB3115C340E057E3
20 changed files with 95 additions and 65 deletions

View File

@ -6,13 +6,20 @@
#include "contain.h" #include "contain.h"
#include "texts.h" #include "texts.h"
void activate (GtkApplication *self, gpointer user_data) { /******************************************************************************/
/* W I N D O W (H E A D E R B A R & T W O N O T E B O O K S ) */
/******************************************************************************/
void activate (GtkApplication *self, gpointer user_data)
{
GtkWindow *window = GTK_WINDOW (gtk_application_window_new (self)); GtkWindow *window = GTK_WINDOW (gtk_application_window_new (self));
window_bar (window, "E coli (with permission from David S. Goodsell, 2009)"); window_header_bar (window, "E coli (with permission from David S. Goodsell, 2009)");
two_notebooks_in_two_panes (window); two_notebooks_in_two_panes (window);
gtk_window_present (GTK_WINDOW (window)); gtk_window_present (GTK_WINDOW (window));
} }
/******************************************************************************/
/* B U T T O N S */
/******************************************************************************/
void ui_toggle_run_edit (GtkWidget *btt_run_xor_edit, gpointer data) void ui_toggle_run_edit (GtkWidget *btt_run_xor_edit, gpointer data)
{ {
printf("window.ui_toggle_run_edit() >>> mode = %d", get_run_edit_mode ()); printf("window.ui_toggle_run_edit() >>> mode = %d", get_run_edit_mode ());
@ -26,3 +33,30 @@ void ui_toggle_run_edit (GtkWidget *btt_run_xor_edit, gpointer data)
printf(" > %d\n", get_run_edit_mode ()); printf(" > %d\n", get_run_edit_mode ());
} }
/******************************************************************************/
/* T R E E */
/******************************************************************************/
void on_user_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
{
// This is a conceptual callback for when an expander is toggled
GtkTreeListRow *row = GTK_TREE_LIST_ROW (user_data);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
gtk_tree_list_row_set_expanded (row, !is_expanded);
}
void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data)
{
GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item);
GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row);
// if (row != NULL) {
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
GtkWidget *expander = gtk_list_item_get_child (list_item);
gtk_expander_set_label (GTK_EXPANDER (expander), text);
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK (on_user_tree_expander_toggled), row);
g_signal_connect(expander, "activate", G_CALLBACK (on_user_tree_expander_toggled), row);
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
if (0) printf("[on_bind_user_tree_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
// } else if (0) printf("[on_bind_user_tree_factory] row == NULL\n");
}

3
callback.d Normal file
View File

@ -0,0 +1,3 @@
callback.o: callback.c hot.h \
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
display.h contain.h texts.h

View File

@ -53,3 +53,5 @@ static const GActionEntry app_actions[] = {
{ "toastclose", on_toast_close_action, NULL, NULL, NULL }, { "toastclose", on_toast_close_action, NULL, NULL, NULL },
}; };
void on_user_tree_expander_toggled(GtkExpander *expander, gpointer user_data);
void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data);

BIN
callback.o Normal file

Binary file not shown.

View File

@ -259,7 +259,7 @@ static void icons_for_fun (GtkHeaderBar *header_bar)
gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_low)); gtk_header_bar_pack_end (header_bar, GTK_WIDGET (power_low));
} }
void window_bar (GtkWindow *window, char *title){ void window_header_bar (GtkWindow *window, char *title){
GtkWidget *header_bar = GTK_WIDGET (gtk_header_bar_new()); GtkWidget *header_bar = GTK_WIDGET (gtk_header_bar_new());
gtk_window_set_titlebar (window, header_bar); gtk_window_set_titlebar (window, header_bar);

3
contain.d Normal file
View File

@ -0,0 +1,3 @@
contain.o: contain.c hot.h \
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
display.h contain.h texts.h callback.h

View File

@ -28,6 +28,7 @@ MyApplication *my_application_new (const char *application_id, GApplicationFlags
G_END_DECLS G_END_DECLS
*/ */
void window_header_bar (GtkWindow *window, char *title);
void two_notebooks_in_two_panes (GtkWindow *window); void two_notebooks_in_two_panes (GtkWindow *window);
GtkWidget *get_selected_rules_vpaned_new(); GtkWidget *get_selected_rules_vpaned_new();
GtkFrame *get_frame_with_label(); GtkFrame *get_frame_with_label();

BIN
contain.o Normal file

Binary file not shown.

3
display.d Normal file
View File

@ -0,0 +1,3 @@
display.o: display.c hot.h \
/gnu/store/fkmpkdav2zmz1k72989bdgpdrfac7rz1-glib-2.78.0/include/glib-2.0/glib.h \
display.h contain.h texts.h

BIN
display.o Normal file

Binary file not shown.

29
hot.c
View File

@ -5,6 +5,7 @@
#include "contain.h" #include "contain.h"
#include "texts.h" #include "texts.h"
#include "callback.h"
// https://docs.gtk.org/gtk4/visual_index.html < widgets gallery // https://docs.gtk.org/gtk4/visual_index.html < widgets gallery
// https://docs.gtk.org/gtk4/section-text-widget.html // https://docs.gtk.org/gtk4/section-text-widget.html
@ -17,6 +18,7 @@ void set_run_edit_mode(int prescribed_mode) {run_edit_mode_val = prescribed_mode
int get_run_edit_mode () {return run_edit_mode_val;} int get_run_edit_mode () {return run_edit_mode_val;}
struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;}; struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){ static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){
if (parent->child) { if (parent->child) {
struct TreeNode_t *cur = parent->child; struct TreeNode_t *cur = parent->child;
@ -64,29 +66,6 @@ static void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_
struct TreeNode_t *cc = create_user_tree_node("access"); add_child_node(c, cc); struct TreeNode_t *cc = create_user_tree_node("access"); add_child_node(c, cc);
} }
void on_user_tree_expander_toggled(GtkExpander *expander, gpointer user_data)
{
// This is a conceptual callback for when an expander is toggled
GtkTreeListRow *row = GTK_TREE_LIST_ROW (user_data);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
gtk_tree_list_row_set_expanded (row, !is_expanded);
}
static void on_bind_user_tree_factory (GtkSignalListItemFactory *factory, GObject* object, gpointer user_data){
GtkListItem *list_item = GTK_LIST_ITEM (object); assert (list_item);
GtkTreeListRow *row = gtk_list_item_get_item (list_item); assert (row);
// if (row != NULL) {
const gchar *text = gtk_string_object_get_string (GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row)));
GtkWidget *expander = gtk_list_item_get_child (list_item);
gtk_expander_set_label (GTK_EXPANDER (expander), text);
g_signal_handlers_disconnect_by_func(expander, G_CALLBACK (on_user_tree_expander_toggled), row);
g_signal_connect(expander, "activate", G_CALLBACK (on_user_tree_expander_toggled), row);
gtk_widget_set_margin_start(expander, gtk_tree_list_row_get_depth(row)*20);
gboolean is_expanded = gtk_tree_list_row_get_expanded(row);
if (0) printf("[on_bind_user_tree_factory] row content is [%s] and expander is [%d]\n", text, is_expanded);
// } else if (0) printf("[on_bind_user_tree_factory] row == NULL\n");
}
void on_setup_user_tree_factory (GtkSignalListItemFactory *factory, void on_setup_user_tree_factory (GtkSignalListItemFactory *factory,
GObject* object, gpointer user_data){ GObject* object, gpointer user_data){
GtkWidget* expander = gtk_expander_new (NULL); GtkWidget* expander = gtk_expander_new (NULL);
@ -124,7 +103,8 @@ GListModel* get_user_tree_model (GObject *item, gpointer root){
return get_user_tree_model_child (cur); return get_user_tree_model_child (cur);
} }
GtkScrolledWindow *get_user_rules_tree (){ GtkScrolledWindow *get_user_rules_tree ()
{
struct TreeNode_t *tree_root = create_user_tree_node("root"); struct TreeNode_t *tree_root = create_user_tree_node("root");
let_us_create_a_complex_useless_and_expensive_tree (tree_root); let_us_create_a_complex_useless_and_expensive_tree (tree_root);
@ -158,4 +138,3 @@ GtkScrolledWindow *get_user_rules_tree (){
return scrolled_window; return scrolled_window;
} }

1
hot.d Normal file
View File

@ -0,0 +1 @@
hot.o: hot.c contain.h texts.h callback.h

4
hot.h
View File

@ -31,8 +31,10 @@
// https://blog.gtk.org/2020/09/08/on-list-models/ < TODO // https://blog.gtk.org/2020/09/08/on-list-models/ < TODO
GtkScrolledWindow *get_user_rules_tree (); GtkScrolledWindow *get_user_rules_tree ();
void set_run_edit_mode(int prescribed_mode); void set_run_edit_mode(int prescribed_mode);
int get_run_edit_mode(); int get_run_edit_mode();
GListModel* get_user_tree_model (GObject *item, gpointer root);
void on_setup_user_tree_factory (GtkSignalListItemFactory *factory,
GObject* object, gpointer user_data);

BIN
hot.o Normal file

Binary file not shown.

0
junk
View File

1
main.d Normal file
View File

@ -0,0 +1 @@
main.o: main.c callback.h

BIN
main.o Normal file

Binary file not shown.

BIN
myprogram Executable file

Binary file not shown.

1
texts.d Normal file
View File

@ -0,0 +1 @@
texts.o: texts.c

BIN
texts.o Normal file

Binary file not shown.