diff --git a/include/widgets.h b/include/widgets.h index 1721447..1925a56 100644 --- a/include/widgets.h +++ b/include/widgets.h @@ -70,8 +70,6 @@ GtkWidget *get_STOCK_text (gchar *text_name); struct MenuNode_t {gchar *text; struct MenuNode_t *child, *next;}; struct MenuNode_t *create_user_menu_node (const gchar* text); -void add_menu_item (struct MenuNode_t *parent, struct MenuNode_t *child); - GtkWidget *get_menu_anchor(); @@ -83,7 +81,7 @@ struct TreeNode_t {gchar *text; struct TreeNode_t *child, *next;}; struct TreeNode_t *create_user_tree_node (const gchar* text); 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 labo_let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root); GtkScrolledWindow *get_user_rules_tree (); @@ -115,4 +113,5 @@ gchar *get_text_address_ANY (); /******************************************************************************/ void learning_how_to_create_a_menu (GtkMenuButton* menu_button); +void labo_create_a_simple_gtk_string_list (); diff --git a/src/calls.c b/src/calls.c index 4dd62d6..513df21 100644 --- a/src/calls.c +++ b/src/calls.c @@ -75,55 +75,6 @@ void on_windows_activation (GtkApplication *app, } -/******************************************************************************/ -/* M E N U */ -/******************************************************************************/ - -static void on_user_menu_expander_toggled (GtkExpander *expander, - gpointer user_data) -{ - 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); - const gchar *text = gtk_string_object_get_string ( - GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row))); - if (1) printf("[on_user_menu_expander_toggled] > %s\n", text); -} - - -void on_bind_user_menu_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) {...} do something ? TODO Check ! - - 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_menu_expander_toggled), - row); - g_signal_connect (expander, - "activate", - G_CALLBACK (on_user_menu_expander_toggled), - row); - gtk_widget_set_margin_start (expander, - gtk_tree_list_row_get_depth(row) * 20); -} - -void on_setup_user_menu_factory (GtkSignalListItemFactory *factory, - GObject* object, gpointer user_data){ - GtkWidget* expander = gtk_expander_new (NULL); - gtk_list_item_set_child (GTK_LIST_ITEM (object), expander); - if (0) printf("[on_setup_user_menu_factory] here is an expander\n"); -} - - /******************************************************************************/ /* T R E E */ /******************************************************************************/ @@ -397,13 +348,19 @@ void on_SITUATIONS_box_DO_RESET (GtkWidget *btt_reset, gpointer data) /******************************************************************************/ -void on_clicked_MENU (GtkWidget *btt_reset, gpointer menu_button) +void on_clicked_MENU (GtkWidget *btt_reset, gpointer list_box) { - printf ("callback.on_clicked_MENU() button\n"); - // presents the text_window and works only once.\nIt should present a menu.\n"); // TODO - learning_how_to_create_a_menu (menu_button); + printf ("callback.on_clicked_MENU() button > %p < &list_box > %p, %p, %p \n",\ + list_box, + gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 0)), + gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 1)), + gtk_list_box_row_get_child (gtk_list_box_get_row_at_index (list_box, 2))); + + // learning_how_to_create_a_menu (menu_button); // https://docs.gtk.org/gtk4/class.ListBox.html - gtk_window_present (GTK_WINDOW (widget_head_get_TEXT_WINDOW())); + + // next line presents the text_window and works only once.\nIt should present a menu.\n"); // TODO + // gtk_window_present (GTK_WINDOW (widget_head_get_TEXT_WINDOW())); } void on_clicked_HOME (GtkWidget *btt_reset, gpointer data) @@ -414,6 +371,55 @@ void on_clicked_HOME (GtkWidget *btt_reset, gpointer data) } +/******************************************************************************/ +/* M E N U */ +/******************************************************************************/ + +static void on_user_menu_expander_toggled (GtkExpander *expander, + gpointer user_data) +{ + 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); + const gchar *text = gtk_string_object_get_string ( + GTK_STRING_OBJECT (gtk_tree_list_row_get_item (row))); + if (1) printf("[on_user_menu_expander_toggled] > %s\n", text); +} + + +void on_bind_user_menu_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) {...} do something ? TODO Check ! + + 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_menu_expander_toggled), + row); + g_signal_connect (expander, + "activate", + G_CALLBACK (on_user_menu_expander_toggled), + row); + gtk_widget_set_margin_start (expander, + gtk_tree_list_row_get_depth(row) * 20); +} + +void on_setup_user_menu_factory (GtkSignalListItemFactory *factory, + GObject* object, gpointer user_data){ + GtkWidget* expander = gtk_expander_new (NULL); + gtk_list_item_set_child (GTK_LIST_ITEM (object), expander); + if (0) printf("[on_setup_user_menu_factory] here is an expander\n"); +} + + // GTK itself does not support event sounds, << A GREAT WAY TO DEBUG ! TODO diff --git a/src/widget.c/heads.c b/src/widget.c/heads.c index 6ad53bc..6e9aac8 100644 --- a/src/widget.c/heads.c +++ b/src/widget.c/heads.c @@ -171,16 +171,18 @@ static void window_header_bar (GtkWindow *window, char *title) gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (search)); + GtkWidget* list_box = gtk_list_box_new(); +// GtkButton *menu_item_A = GTK_BUTTON (gtk_button_new_with_label ("item_A")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_A); +// GtkButton *menu_item_B = GTK_BUTTON (gtk_button_new_with_label ("item_B")); gtk_list_box_append (GTK_LIST_BOX (list_box), menu_item_B); + gtk_list_box_append (GTK_LIST_BOX (list_box), gtk_label_new ("menu_item_A")); + gtk_list_box_append (GTK_LIST_BOX (list_box), gtk_label_new ("menu_item_B")); + gtk_list_box_append (GTK_LIST_BOX (list_box), gtk_label_new ("menu_item_C")); + GtkButton *open_menu = GTK_BUTTON (gtk_button_new ()); // gtk_button_new or gtk_menu_button_new ? gtk_button_set_icon_name (GTK_BUTTON (open_menu), "open-menu-symbolic"); // gtk_menu_button_set_label (open_menu, "open-menu-symbolic"); - char *array[] = {"one", "two", "three", "four", NULL}; - GtkStringList *list = gtk_string_list_new ((const char * const *) array); - if (0) printf ("heads.window_header_bar() > list [2] = %s\n", - gtk_string_list_get_string (list, 1)); - // gtk_menu_button_set_child (open_menu, list); - g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU), open_menu); + g_signal_connect (open_menu, "clicked", G_CALLBACK (on_clicked_MENU), list_box); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (open_menu)); gtk_header_bar_pack_end (GTK_HEADER_BAR (header_bar), GTK_WIDGET (get_menu_anchor())); @@ -199,3 +201,4 @@ void widget_head_MAIN_WINDOW_design (GtkWindow *main_window){ gtk_window_present (GTK_WINDOW (main_window)); } + diff --git a/src/widget.c/labo.c b/src/widget.c/labo.c index 951ef9f..e599c2b 100644 --- a/src/widget.c/labo.c +++ b/src/widget.c/labo.c @@ -61,12 +61,8 @@ void learning_how_to_create_a_menu (GtkMenuButton* menu_button) { // Je veux qu // GtkWidget ex = *gtk_menu_bar_new(); - char *array[] = {"one", "two", "three", "four", NULL}; - GtkStringList *list = gtk_string_list_new ((const char * const *) array); - printf ("labo.learning_how_to_create_a_menu () > list [3] = %s\n", gtk_string_list_get_string (list, 2)); - GtkWidget* list_box = gtk_list_box_new (); - gtk_list_box_append (GTK_LIST_BOX (list_box), GTK_WIDGET (list)); + gtk_list_box_append (GTK_LIST_BOX (menu_button), GTK_WIDGET (list_box)); gtk_list_box_bind_model (GTK_LIST_BOX (list_box), NULL, // GListModel* model, NULL, // GtkListBoxCreateWidgetFunc create_widget_func, @@ -106,7 +102,7 @@ void learning_how_to_create_a_menu (GtkMenuButton* menu_button) { // Je veux qu -void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root) { +void labo_let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree_root) { struct TreeNode_t *a = create_user_tree_node("We, the people");add_child_node(tree_root, a); struct TreeNode_t *b = create_user_tree_node("in Order to"); add_child_node(tree_root, b); struct TreeNode_t *c = create_user_tree_node("do establish"); add_child_node(tree_root, c); @@ -138,6 +134,14 @@ void let_us_create_a_complex_useless_and_expensive_tree (struct TreeNode_t *tree struct TreeNode_t *cc = create_user_tree_node("access"); add_child_node(c, cc); } +void labo_create_a_simple_gtk_string_list () { + char *array[] = {"one", "two", "three", "four", NULL}; + GtkStringList *list = gtk_string_list_new ((const char * const *) array); + for (int i = 0; i < 4; i++) + printf ("in labo.a_simple_gtk_string_list() > list [%d + 1] = %s\n",\ + i, + gtk_string_list_get_string (list, i)); +} /* "rule effect" diff --git a/src/widget.c/menu.c b/src/widget.c/menu.c index 8e3ffe6..c8e257c 100644 --- a/src/widget.c/menu.c +++ b/src/widget.c/menu.c @@ -34,7 +34,7 @@ // GTK_ORIENTATION_VERTICAL GTK_ORIENTATION_HORIZONTAL -void add_menu_item (struct MenuNode_t *parent, struct MenuNode_t *child){ +static void add_menu_item (struct MenuNode_t *parent, struct MenuNode_t *child){ if (parent->child) { struct MenuNode_t *cur = parent->child; while (cur && cur->next) {cur = cur->next;} @@ -81,12 +81,14 @@ static GListModel* get_user_menu_model (GObject *item, gpointer root){ GtkWidget *get_menu_anchor() { + if (0) labo_create_a_simple_gtk_string_list (); struct MenuNode_t *menu_root = create_user_menu_node("menu"); struct MenuNode_t *item_a = create_user_menu_node("item_a");add_menu_item (menu_root, item_a); struct MenuNode_t *item_b = create_user_menu_node("item_b");add_menu_item (menu_root, item_b); struct MenuNode_t *item_c = create_user_menu_node("item_c");add_menu_item (menu_root, item_c); - GtkWidget* list_box = gtk_list_box_new(); +// GtkWidget* list_box = gtk_list_box_new(); + GtkStringList *model = gtk_string_list_new (NULL); gtk_string_list_append (model, menu_root->text); GtkSignalListItemFactory *factory = GTK_SIGNAL_LIST_ITEM_FACTORY (gtk_signal_list_item_factory_new()); diff --git a/src/widget.c/tree.c b/src/widget.c/tree.c index eec6b1a..e76aa87 100644 --- a/src/widget.c/tree.c +++ b/src/widget.c/tree.c @@ -82,7 +82,7 @@ static GListModel* get_user_tree_model (GObject *item, gpointer 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); + labo_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);