Compare commits
2 Commits
59e6c779fd
...
4ba96fbe23
Author | SHA1 | Date |
---|---|---|
Jean Sirmai | 4ba96fbe23 | |
Jean Sirmai | 391941d200 |
66
callback.c
66
callback.c
|
@ -1,28 +1,64 @@
|
|||
#include <stdio.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
#include "hot.h"
|
||||
#include "tree.h"
|
||||
#include "display.h"
|
||||
#include "contain.h"
|
||||
#include "texts.h"
|
||||
#include "in_depth.h"
|
||||
|
||||
void activate (GtkApplication *self, gpointer user_data) {
|
||||
GtkWindow *window = GTK_WINDOW (gtk_application_window_new (self));
|
||||
window_bar (window, "E coli (with permission from David S. Goodsell, 2009)");
|
||||
two_notebooks_in_two_panes (window);
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
/******************************************************************************/
|
||||
/* M A I N W I N D O W A C T I V A T I O N */
|
||||
/******************************************************************************/
|
||||
void ui_main_window (GtkApplication *self, gpointer user_data)
|
||||
{
|
||||
GtkWindow *main_window = GTK_WINDOW (gtk_application_window_new (self));
|
||||
window_header_bar (main_window,
|
||||
"E coli (with permission from David S. Goodsell, 2009)");
|
||||
two_notebooks_in_two_panes (main_window);
|
||||
gtk_window_present (GTK_WINDOW (main_window));
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* 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");
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
/* B U T T O N S */
|
||||
/******************************************************************************/
|
||||
void ui_toggle_run_edit (GtkWidget *btt_run_xor_edit, gpointer data)
|
||||
{
|
||||
printf("window.ui_toggle_run_edit() >>> mode = %d", get_run_edit_mode ());
|
||||
if (get_run_edit_mode()) {
|
||||
gtk_button_set_icon_name (GTK_BUTTON (btt_run_xor_edit), "system-run-symbolic");
|
||||
set_run_edit_mode (0);
|
||||
} else {
|
||||
gtk_button_set_icon_name (GTK_BUTTON (btt_run_xor_edit), "document-edit-symbolic");
|
||||
set_run_edit_mode (1);
|
||||
}
|
||||
printf(" > %d\n", get_run_edit_mode ());
|
||||
printf("window.ui_toggle_run_edit() >>> mode = %d", get_run_edit_mode ());
|
||||
if (get_run_edit_mode()) {
|
||||
gtk_button_set_icon_name (GTK_BUTTON (btt_run_xor_edit), "system-run-symbolic");
|
||||
set_run_edit_mode (0);
|
||||
} else {
|
||||
gtk_button_set_icon_name (GTK_BUTTON (btt_run_xor_edit), "document-edit-symbolic");
|
||||
set_run_edit_mode (1);
|
||||
}
|
||||
printf(" > %d\n", get_run_edit_mode ());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
//#include <stdio.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
void activate (GtkApplication *app, gpointer user_data);
|
||||
void ui_main_window (GtkApplication *app, gpointer user_data);
|
||||
|
||||
void ui_enable_action (const char *name);
|
||||
void ui_disable_action (const char *name);
|
||||
|
@ -53,3 +53,5 @@ static const GActionEntry app_actions[] = {
|
|||
{ "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);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
#include "hot.h"
|
||||
#include "tree.h"
|
||||
#include "display.h"
|
||||
#include "contain.h"
|
||||
#include "texts.h"
|
||||
|
@ -259,7 +259,7 @@ static void icons_for_fun (GtkHeaderBar *header_bar)
|
|||
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());
|
||||
gtk_window_set_titlebar (window, header_bar);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ MyApplication *my_application_new (const char *application_id, GApplicationFlags
|
|||
G_END_DECLS
|
||||
*/
|
||||
|
||||
void window_header_bar (GtkWindow *window, char *title);
|
||||
void two_notebooks_in_two_panes (GtkWindow *window);
|
||||
GtkWidget *get_selected_rules_vpaned_new();
|
||||
GtkFrame *get_frame_with_label();
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <gtk-4.0/gtk/gtk.h>
|
||||
|
||||
#include "hot.h"
|
||||
#include "tree.h"
|
||||
#include "display.h"
|
||||
#include "contain.h"
|
||||
#include "texts.h"
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include <assert.h>
|
||||
|
||||
static int run_edit_mode_val = 0;
|
||||
|
||||
void set_run_edit_mode (int prescribed_mode) {run_edit_mode_val = prescribed_mode;}
|
||||
int get_run_edit_mode () {return run_edit_mode_val;}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
#include <gtk-4.0/gtk/gtk.h>
|
||||
#include <assert.h>
|
||||
|
||||
void set_run_edit_mode (int prescribed_mode);
|
||||
int get_run_edit_mode ();
|
||||
|
2
main.c
2
main.c
|
@ -15,7 +15,7 @@ int main (int argc, char **argv)
|
|||
int status;
|
||||
|
||||
app = gtk_application_new ("org.jean.GTK4_GG_hack", G_APPLICATION_DEFAULT_FLAGS);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
|
||||
g_signal_connect (app, "activate", G_CALLBACK (ui_main_window), NULL);
|
||||
status = g_application_run (G_APPLICATION (app), argc, argv);
|
||||
g_object_unref (app);
|
||||
|
||||
|
|
|
@ -5,18 +5,15 @@
|
|||
|
||||
#include "contain.h"
|
||||
#include "texts.h"
|
||||
#include "callback.h"
|
||||
|
||||
// https://docs.gtk.org/gtk4/visual_index.html < widgets gallery
|
||||
// https://docs.gtk.org/gtk4/section-text-widget.html
|
||||
// https://docs.gtk.org/gtk4/class.Widget.html#height-for-width-geometry-management
|
||||
// GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL
|
||||
|
||||
static int run_edit_mode_val = 0;
|
||||
|
||||
void set_run_edit_mode(int prescribed_mode) {run_edit_mode_val = prescribed_mode;}
|
||||
int get_run_edit_mode () {return run_edit_mode_val;}
|
||||
|
||||
struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;};
|
||||
|
||||
static void add_child_node (struct TreeNode_t *parent, struct TreeNode_t *child){
|
||||
if (parent->child) {
|
||||
struct TreeNode_t *cur = parent->child;
|
||||
|
@ -64,29 +61,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);
|
||||
}
|
||||
|
||||
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,
|
||||
GObject* object, gpointer user_data){
|
||||
GtkWidget* expander = gtk_expander_new (NULL);
|
||||
|
@ -124,38 +98,38 @@ GListModel* get_user_tree_model (GObject *item, gpointer root){
|
|||
return get_user_tree_model_child (cur);
|
||||
}
|
||||
|
||||
GtkScrolledWindow *get_user_rules_tree (){
|
||||
struct TreeNode_t *tree_root = create_user_tree_node("root");
|
||||
let_us_create_a_complex_useless_and_expensive_tree (tree_root);
|
||||
GtkScrolledWindow *get_user_rules_tree ()
|
||||
{
|
||||
struct TreeNode_t *tree_root = create_user_tree_node("root");
|
||||
let_us_create_a_complex_useless_and_expensive_tree (tree_root);
|
||||
|
||||
GtkStringList *model = gtk_string_list_new(NULL);
|
||||
gtk_string_list_append (model, tree_root->text);
|
||||
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
||||
g_signal_connect (factory, "setup", G_CALLBACK(on_setup_user_tree_factory), NULL);
|
||||
g_signal_connect (factory, "bind", G_CALLBACK(on_bind_user_tree_factory), NULL);
|
||||
GtkStringList *model = gtk_string_list_new(NULL);
|
||||
gtk_string_list_append (model, tree_root->text);
|
||||
GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new());
|
||||
g_signal_connect (factory, "setup", G_CALLBACK(on_setup_user_tree_factory), NULL);
|
||||
g_signal_connect (factory, "bind", G_CALLBACK(on_bind_user_tree_factory), NULL);
|
||||
|
||||
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
||||
G_LIST_MODEL (model),
|
||||
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
||||
TRUE, // FALSE, // autoexpand
|
||||
(GtkTreeListModelCreateModelFunc) &get_user_tree_model,
|
||||
tree_root,
|
||||
NULL // (GDestroyNotify) free_user_tree_node
|
||||
);
|
||||
GtkTreeListModel *tree_model = gtk_tree_list_model_new(
|
||||
G_LIST_MODEL (model),
|
||||
FALSE, // Passthrough - False in actual usage with dynamic children retrieval
|
||||
TRUE, // FALSE, // autoexpand
|
||||
(GtkTreeListModelCreateModelFunc) &get_user_tree_model,
|
||||
tree_root,
|
||||
NULL // (GDestroyNotify) free_user_tree_node
|
||||
);
|
||||
|
||||
GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model));
|
||||
gtk_single_selection_set_autoselect (selection_model, FALSE);
|
||||
gtk_single_selection_set_can_unselect (selection_model, TRUE);
|
||||
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model), GTK_LIST_ITEM_FACTORY (factory));
|
||||
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new());
|
||||
// Allocation height too small. Tried to allocate 1922x1030, but GtkNotebook 0x25cd4c0 needs at least 1922x1064.
|
||||
// even if I remove (comment) the next line :
|
||||
gtk_scrolled_window_set_child (scrolled_window, list_view);
|
||||
gtk_scrolled_window_set_policy (scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_widget_set_vexpand (GTK_WIDGET (scrolled_window), TRUE);
|
||||
gtk_widget_set_visible (GTK_WIDGET (scrolled_window), TRUE);
|
||||
gtk_widget_set_visible (GTK_WIDGET (list_view), TRUE);
|
||||
GtkSingleSelection *selection_model = gtk_single_selection_new (G_LIST_MODEL (tree_model));
|
||||
gtk_single_selection_set_autoselect (selection_model, FALSE);
|
||||
gtk_single_selection_set_can_unselect (selection_model, TRUE);
|
||||
GtkWidget *list_view = gtk_list_view_new (GTK_SELECTION_MODEL (selection_model), GTK_LIST_ITEM_FACTORY (factory));
|
||||
GtkScrolledWindow *scrolled_window = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new());
|
||||
// Allocation height too small. Tried to allocate 1922x1030, but GtkNotebook 0x25cd4c0 needs at least 1922x1064.
|
||||
// even if I remove (comment) the next line :
|
||||
gtk_scrolled_window_set_child (scrolled_window, list_view);
|
||||
gtk_scrolled_window_set_policy (scrolled_window, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
|
||||
gtk_widget_set_vexpand (GTK_WIDGET (scrolled_window), TRUE);
|
||||
gtk_widget_set_visible (GTK_WIDGET (scrolled_window), TRUE);
|
||||
gtk_widget_set_visible (GTK_WIDGET (list_view), TRUE);
|
||||
return scrolled_window;
|
||||
}
|
||||
|
||||
|
|
@ -31,8 +31,10 @@
|
|||
|
||||
// https://blog.gtk.org/2020/09/08/on-list-models/ < TODO
|
||||
|
||||
|
||||
GtkScrolledWindow *get_user_rules_tree ();
|
||||
void set_run_edit_mode(int prescribed_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);
|
||||
|
Loading…
Reference in New Issue