diff --git a/demos/gtk-demo/tree_store.c b/demos/gtk-demo/tree_store.c index 944bc2c..65cecec 100644 --- a/demos/gtk-demo/tree_store.c +++ b/demos/gtk-demo/tree_store.c @@ -13,6 +13,17 @@ /* */ /*************************************************************************************************************************************/ +// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // + +/************************************************** <> *****************************************************/ +/* */ +/* https://developer-old.gnome.org/gtk4/stable/GtkTreeView.html */ +/* GtkTreeViewColumn, GtkTreeSelection, GtkTreeModel, GtkTreeView drag-and-drop, GtkTreeSortable, GtkTreeModelSort, GtkListStore, */ +/* GtkTreeStore, GtkCellRenderer, GtkCellEditable, GtkCellRendererPixbuf, GtkCellRendererText, GtkCellRendererToggle */ +/* */ +/* https://www.gnu.org/software/guile-gnome/docs/gtk/html/GtkCellRenderer.html */ +/* */ +/*************************************************************************************************************************************/ /* The GtkTreeStore is used to store data in tree form, to be used later on by a GtkTreeView to display it. @@ -59,7 +70,7 @@ static TreeItem item_name_0[] = static TreeItem item_name_1[] = { { "A", FALSE, TRUE, NULL }, - { "B", FALSE, FALSE, NULL }, + { "B", TRUE, FALSE, NULL }, { "C", FALSE, TRUE, NULL }, { "D", FALSE, TRUE, NULL }, { NULL } @@ -131,70 +142,25 @@ create_model (void) return GTK_TREE_MODEL (model); } -static void // https://www.gnu.org/software/guile-gnome/docs/gtk/html/GtkCellRendererToggle.html -item_toggled (GtkCellRendererToggle *cell, - char *path_str, - gpointer data) -{ - GtkTreeModel *model = (GtkTreeModel *)data; - GtkTreePath *path = gtk_tree_path_new_from_string (path_str); - GtkTreeIter iter; - gboolean toggle_item; - - int *column; - - column = g_object_get_data (G_OBJECT (cell), "column"); - - /* get toggled iter */ - gtk_tree_model_get_iter (model, &iter, path); - gtk_tree_model_get (model, &iter, column, &toggle_item, -1); - - /* do something with the value */ - toggle_item ^= 1; - - /* set new value */ - gtk_tree_store_set (GTK_TREE_STORE (model), &iter, column, - toggle_item, -1); - - /* clean up */ - gtk_tree_path_free (path); -} - static void add_columns (GtkTreeView *treeview) { - int col_offset; GtkCellRenderer *renderer; -// GtkTreeViewColumn *column; - GtkTreeModel *model = gtk_tree_view_get_model (treeview); /* column for item_1 names */ renderer = gtk_cell_renderer_text_new (); g_object_set (renderer, "xalign", 0.0, NULL); - col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Col 0", renderer, "text", - COLUMN_0, NULL); -/* column = */ gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1); -// gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, + "Col 0", renderer, "text", COLUMN_0, NULL); /* AA column */ renderer = gtk_cell_renderer_toggle_new (); g_object_set (renderer, "xalign", 0.0, NULL); g_object_set_data (G_OBJECT (renderer), "column", (int *)COLUMN_1); - // g_signal_connect (renderer, "toggled", G_CALLBACK (item_toggled), model); - - col_offset = gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, "Col 1", renderer, "active", - COLUMN_1, "visible", VISIBLE_COLUMN, "activatable", WORLD_COLUMN, NULL); - -/* column = */ gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1); -// gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED); -// gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); - -/* column = */ gtk_tree_view_get_column (GTK_TREE_VIEW (treeview), col_offset - 1); -// gtk_tree_view_column_set_sizing (GTK_TREE_VIEW_COLUMN (column), GTK_TREE_VIEW_COLUMN_FIXED); -// gtk_tree_view_column_set_clickable (GTK_TREE_VIEW_COLUMN (column), TRUE); - + gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview), -1, + "Col 1", renderer, "active", COLUMN_1, "visible", VISIBLE_COLUMN, "activatable", WORLD_COLUMN, NULL); } GtkWidget * @@ -223,8 +189,7 @@ do_tree_store (GtkWidget *do_widget) gtk_widget_set_margin_bottom (vbox, 8); gtk_window_set_child (GTK_WINDOW (window), vbox); - gtk_box_append (GTK_BOX (vbox), - gtk_label_new ("Learning GTK trees")); + gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Learning GTK trees")); sw = gtk_scrolled_window_new (); gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);