2001-10-02 18:54:05 +00:00
|
|
|
/* Tree View/Editable Cells
|
2002-01-19 20:15:56 +00:00
|
|
|
*
|
2001-11-28 21:19:40 +00:00
|
|
|
* This demo demonstrates the use of editable cells in a GtkTreeView. If
|
2001-10-02 18:54:05 +00:00
|
|
|
* you're new to the GtkTreeView widgets and associates, look into
|
2005-03-16 07:16:29 +00:00
|
|
|
* the GtkListStore example first. It also shows how to use the
|
|
|
|
* GtkCellRenderer::editing-started signal to do custom setup of the
|
|
|
|
* editable widget.
|
2001-10-02 18:54:05 +00:00
|
|
|
*
|
2011-09-02 03:55:47 +00:00
|
|
|
* The cell renderers used in this demo are GtkCellRendererText,
|
2005-05-25 06:28:30 +00:00
|
|
|
* GtkCellRendererCombo and GtkCellRendererProgress.
|
2001-10-02 18:54:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2005-03-08 16:10:28 +00:00
|
|
|
gint number;
|
|
|
|
gchar *product;
|
2005-05-25 06:28:30 +00:00
|
|
|
gint yummy;
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
Item;
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
2005-03-08 16:10:28 +00:00
|
|
|
COLUMN_ITEM_NUMBER,
|
|
|
|
COLUMN_ITEM_PRODUCT,
|
2005-05-25 06:28:30 +00:00
|
|
|
COLUMN_ITEM_YUMMY,
|
2005-03-08 16:10:28 +00:00
|
|
|
NUM_ITEM_COLUMNS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
COLUMN_NUMBER_TEXT,
|
|
|
|
NUM_NUMBER_COLUMNS
|
2001-10-02 18:54:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static GArray *articles = NULL;
|
|
|
|
|
|
|
|
static void
|
|
|
|
add_items (void)
|
|
|
|
{
|
|
|
|
Item foo;
|
|
|
|
|
|
|
|
g_return_if_fail (articles != NULL);
|
|
|
|
|
|
|
|
foo.number = 3;
|
2011-11-22 22:27:40 +00:00
|
|
|
foo.product = g_strdup ("bottles of coke");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 20;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
|
|
|
|
foo.number = 5;
|
2011-11-22 22:27:40 +00:00
|
|
|
foo.product = g_strdup ("packages of noodles");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 50;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
|
|
|
|
foo.number = 2;
|
2011-11-22 22:27:40 +00:00
|
|
|
foo.product = g_strdup ("packages of chocolate chip cookies");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 90;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
|
|
|
|
foo.number = 1;
|
2011-11-22 22:27:40 +00:00
|
|
|
foo.product = g_strdup ("can vanilla ice cream");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 60;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
|
|
|
|
foo.number = 6;
|
2011-11-22 22:27:40 +00:00
|
|
|
foo.product = g_strdup ("eggs");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 10;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeModel *
|
2005-03-08 16:10:28 +00:00
|
|
|
create_items_model (void)
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
|
|
|
gint i = 0;
|
|
|
|
GtkListStore *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
/* create array */
|
|
|
|
articles = g_array_sized_new (FALSE, FALSE, sizeof (Item), 1);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
add_items ();
|
|
|
|
|
|
|
|
/* create list store */
|
2005-03-08 16:10:28 +00:00
|
|
|
model = gtk_list_store_new (NUM_ITEM_COLUMNS, G_TYPE_INT, G_TYPE_STRING,
|
2005-05-25 06:28:30 +00:00
|
|
|
G_TYPE_INT, G_TYPE_BOOLEAN);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
/* add items */
|
|
|
|
for (i = 0; i < articles->len; i++)
|
|
|
|
{
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
|
|
|
|
|
|
gtk_list_store_set (model, &iter,
|
2005-05-25 06:28:30 +00:00
|
|
|
COLUMN_ITEM_NUMBER,
|
|
|
|
g_array_index (articles, Item, i).number,
|
|
|
|
COLUMN_ITEM_PRODUCT,
|
|
|
|
g_array_index (articles, Item, i).product,
|
|
|
|
COLUMN_ITEM_YUMMY,
|
|
|
|
g_array_index (articles, Item, i).yummy,
|
|
|
|
-1);
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (model);
|
|
|
|
}
|
|
|
|
|
2005-03-08 16:10:28 +00:00
|
|
|
static GtkTreeModel *
|
|
|
|
create_numbers_model (void)
|
|
|
|
{
|
|
|
|
#define N_NUMBERS 10
|
|
|
|
gint i = 0;
|
|
|
|
GtkListStore *model;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
/* create list store */
|
|
|
|
model = gtk_list_store_new (NUM_NUMBER_COLUMNS, G_TYPE_STRING, G_TYPE_INT);
|
|
|
|
|
|
|
|
/* add numbers */
|
|
|
|
for (i = 0; i < N_NUMBERS; i++)
|
|
|
|
{
|
2006-07-02 15:05:14 +00:00
|
|
|
char str[2];
|
|
|
|
|
|
|
|
str[0] = '0' + i;
|
|
|
|
str[1] = '\0';
|
2005-03-08 16:10:28 +00:00
|
|
|
|
|
|
|
gtk_list_store_append (model, &iter);
|
|
|
|
|
|
|
|
gtk_list_store_set (model, &iter,
|
2005-05-25 06:28:30 +00:00
|
|
|
COLUMN_NUMBER_TEXT, str,
|
|
|
|
-1);
|
2005-03-08 16:10:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return GTK_TREE_MODEL (model);
|
|
|
|
|
|
|
|
#undef N_NUMBERS
|
|
|
|
}
|
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
static void
|
|
|
|
add_item (GtkWidget *button, gpointer data)
|
|
|
|
{
|
|
|
|
Item foo;
|
2013-12-22 18:17:32 +00:00
|
|
|
GtkTreeIter current, iter;
|
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GtkTreeViewColumn *column;
|
|
|
|
GtkTreeView *treeview = (GtkTreeView *)data;
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
g_return_if_fail (articles != NULL);
|
|
|
|
|
|
|
|
foo.number = 0;
|
|
|
|
foo.product = g_strdup ("Description here");
|
2005-05-25 06:28:30 +00:00
|
|
|
foo.yummy = 50;
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_append_vals (articles, &foo, 1);
|
|
|
|
|
2013-12-22 18:17:32 +00:00
|
|
|
/* Insert a new row below the current one */
|
|
|
|
gtk_tree_view_get_cursor (treeview, &path, NULL);
|
|
|
|
model = gtk_tree_view_get_model (treeview);
|
2015-01-19 12:32:31 +00:00
|
|
|
if (path)
|
|
|
|
{
|
|
|
|
gtk_tree_model_get_iter (model, ¤t, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
gtk_list_store_insert_after (GTK_LIST_STORE (model), &iter, ¤t);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_list_store_insert (GTK_LIST_STORE (model), &iter, -1);
|
|
|
|
}
|
2013-12-22 18:17:32 +00:00
|
|
|
|
|
|
|
/* Set the data for the new row */
|
2001-10-02 18:54:05 +00:00
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
2005-05-25 06:28:30 +00:00
|
|
|
COLUMN_ITEM_NUMBER, foo.number,
|
|
|
|
COLUMN_ITEM_PRODUCT, foo.product,
|
|
|
|
COLUMN_ITEM_YUMMY, foo.yummy,
|
|
|
|
-1);
|
2013-12-22 18:17:32 +00:00
|
|
|
|
|
|
|
/* Move focus to the new row */
|
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
column = gtk_tree_view_get_column (treeview, 0);
|
|
|
|
gtk_tree_view_set_cursor (treeview, path, column, FALSE);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_item (GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeView *treeview = (GtkTreeView *)data;
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (treeview);
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (treeview);
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
|
|
|
|
{
|
|
|
|
gint i;
|
|
|
|
GtkTreePath *path;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
path = gtk_tree_model_get_path (model, &iter);
|
|
|
|
i = gtk_tree_path_get_indices (path)[0];
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
g_array_remove_index (articles, i);
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-16 07:16:29 +00:00
|
|
|
static gboolean
|
|
|
|
separator_row (GtkTreeModel *model,
|
2005-05-25 06:28:30 +00:00
|
|
|
GtkTreeIter *iter,
|
|
|
|
gpointer data)
|
2005-03-16 07:16:29 +00:00
|
|
|
{
|
|
|
|
GtkTreePath *path;
|
|
|
|
gint idx;
|
|
|
|
|
|
|
|
path = gtk_tree_model_get_path (model, iter);
|
|
|
|
idx = gtk_tree_path_get_indices (path)[0];
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
|
|
|
return idx == 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
editing_started (GtkCellRenderer *cell,
|
2005-05-25 06:28:30 +00:00
|
|
|
GtkCellEditable *editable,
|
|
|
|
const gchar *path,
|
|
|
|
gpointer data)
|
2005-03-16 07:16:29 +00:00
|
|
|
{
|
2011-09-02 03:55:47 +00:00
|
|
|
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (editable),
|
2005-05-25 06:28:30 +00:00
|
|
|
separator_row, NULL, NULL);
|
2005-03-16 07:16:29 +00:00
|
|
|
}
|
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
static void
|
|
|
|
cell_edited (GtkCellRendererText *cell,
|
2005-05-25 06:28:30 +00:00
|
|
|
const gchar *path_string,
|
|
|
|
const gchar *new_text,
|
|
|
|
gpointer data)
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
|
|
|
GtkTreeModel *model = (GtkTreeModel *)data;
|
|
|
|
GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
|
|
|
|
GtkTreeIter iter;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2003-07-12 14:10:31 +00:00
|
|
|
gint column = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (cell), "column"));
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
|
2003-07-12 14:10:31 +00:00
|
|
|
switch (column)
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
2005-03-08 16:10:28 +00:00
|
|
|
case COLUMN_ITEM_NUMBER:
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
2005-05-25 06:28:30 +00:00
|
|
|
gint i;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2005-05-25 06:28:30 +00:00
|
|
|
i = gtk_tree_path_get_indices (path)[0];
|
|
|
|
g_array_index (articles, Item, i).number = atoi (new_text);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2005-05-25 06:28:30 +00:00
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
|
|
|
|
g_array_index (articles, Item, i).number, -1);
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2005-03-08 16:10:28 +00:00
|
|
|
case COLUMN_ITEM_PRODUCT:
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
2005-05-25 06:28:30 +00:00
|
|
|
gint i;
|
|
|
|
gchar *old_text;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
|
|
|
gtk_tree_model_get (model, &iter, column, &old_text, -1);
|
2005-05-25 06:28:30 +00:00
|
|
|
g_free (old_text);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2005-05-25 06:28:30 +00:00
|
|
|
i = gtk_tree_path_get_indices (path)[0];
|
|
|
|
g_free (g_array_index (articles, Item, i).product);
|
|
|
|
g_array_index (articles, Item, i).product = g_strdup (new_text);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2005-05-25 06:28:30 +00:00
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter, column,
|
2002-01-19 20:15:56 +00:00
|
|
|
g_array_index (articles, Item, i).product, -1);
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
break;
|
2020-03-07 14:01:21 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-09-02 03:55:47 +00:00
|
|
|
add_columns (GtkTreeView *treeview,
|
2005-05-25 06:28:30 +00:00
|
|
|
GtkTreeModel *items_model,
|
|
|
|
GtkTreeModel *numbers_model)
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
|
|
|
GtkCellRenderer *renderer;
|
|
|
|
|
|
|
|
/* number column */
|
2005-03-08 16:10:28 +00:00
|
|
|
renderer = gtk_cell_renderer_combo_new ();
|
|
|
|
g_object_set (renderer,
|
2005-05-25 06:28:30 +00:00
|
|
|
"model", numbers_model,
|
|
|
|
"text-column", COLUMN_NUMBER_TEXT,
|
|
|
|
"has-entry", FALSE,
|
|
|
|
"editable", TRUE,
|
|
|
|
NULL);
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (renderer, "edited",
|
2005-05-25 06:28:30 +00:00
|
|
|
G_CALLBACK (cell_edited), items_model);
|
2005-03-16 07:16:29 +00:00
|
|
|
g_signal_connect (renderer, "editing-started",
|
2005-05-25 06:28:30 +00:00
|
|
|
G_CALLBACK (editing_started), NULL);
|
2005-03-08 16:10:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_NUMBER));
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
2005-05-25 06:28:30 +00:00
|
|
|
-1, "Number", renderer,
|
|
|
|
"text", COLUMN_ITEM_NUMBER,
|
|
|
|
NULL);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
/* product column */
|
|
|
|
renderer = gtk_cell_renderer_text_new ();
|
2005-03-08 16:10:28 +00:00
|
|
|
g_object_set (renderer,
|
2005-05-25 06:28:30 +00:00
|
|
|
"editable", TRUE,
|
|
|
|
NULL);
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (renderer, "edited",
|
2005-05-25 06:28:30 +00:00
|
|
|
G_CALLBACK (cell_edited), items_model);
|
2005-03-08 16:10:28 +00:00
|
|
|
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_PRODUCT));
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
2005-05-25 06:28:30 +00:00
|
|
|
-1, "Product", renderer,
|
|
|
|
"text", COLUMN_ITEM_PRODUCT,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
/* yummy column */
|
|
|
|
renderer = gtk_cell_renderer_progress_new ();
|
|
|
|
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_ITEM_YUMMY));
|
|
|
|
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (treeview),
|
|
|
|
-1, "Yummy", renderer,
|
|
|
|
"value", COLUMN_ITEM_YUMMY,
|
|
|
|
NULL);
|
2001-10-02 18:54:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GtkWidget *
|
2003-11-08 22:08:05 +00:00
|
|
|
do_editable_cells (GtkWidget *do_widget)
|
2001-10-02 18:54:05 +00:00
|
|
|
{
|
2015-06-28 13:23:28 +00:00
|
|
|
static GtkWidget *window = NULL;
|
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
if (!window)
|
|
|
|
{
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *sw;
|
|
|
|
GtkWidget *treeview;
|
|
|
|
GtkWidget *button;
|
2005-03-08 16:10:28 +00:00
|
|
|
GtkTreeModel *items_model;
|
|
|
|
GtkTreeModel *numbers_model;
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2017-10-31 06:41:15 +00:00
|
|
|
gtk_window_set_display (GTK_WINDOW (window),
|
|
|
|
gtk_widget_get_display (do_widget));
|
2015-06-20 01:59:15 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Editable Cells");
|
2020-05-09 16:03:11 +00:00
|
|
|
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
|
2020-02-26 01:57:20 +00:00
|
|
|
gtk_widget_set_margin_start (vbox, 5);
|
|
|
|
gtk_widget_set_margin_end (vbox, 5);
|
|
|
|
gtk_widget_set_margin_top (vbox, 5);
|
|
|
|
gtk_widget_set_margin_bottom (vbox, 5);
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox),
|
2017-04-21 20:34:36 +00:00
|
|
|
gtk_label_new ("Shopping list (you can edit the cells!)"));
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
sw = gtk_scrolled_window_new (NULL, NULL);
|
2020-04-17 03:25:06 +00:00
|
|
|
gtk_scrolled_window_set_has_frame (GTK_SCROLLED_WINDOW (sw), TRUE);
|
2001-10-02 18:54:05 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
|
2005-05-25 06:28:30 +00:00
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), sw);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
2005-03-08 16:10:28 +00:00
|
|
|
/* create models */
|
|
|
|
items_model = create_items_model ();
|
|
|
|
numbers_model = create_numbers_model ();
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
/* create tree view */
|
2005-03-08 16:10:28 +00:00
|
|
|
treeview = gtk_tree_view_new_with_model (items_model);
|
2017-10-06 18:21:19 +00:00
|
|
|
gtk_widget_set_vexpand (treeview, TRUE);
|
2001-10-02 18:54:05 +00:00
|
|
|
gtk_tree_selection_set_mode (gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)),
|
2005-05-25 06:28:30 +00:00
|
|
|
GTK_SELECTION_SINGLE);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2005-03-08 16:10:28 +00:00
|
|
|
add_columns (GTK_TREE_VIEW (treeview), items_model, numbers_model);
|
|
|
|
|
|
|
|
g_object_unref (numbers_model);
|
|
|
|
g_object_unref (items_model);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), treeview);
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2001-10-02 18:54:05 +00:00
|
|
|
/* some buttons */
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 4);
|
|
|
|
gtk_box_set_homogeneous (GTK_BOX (hbox), TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Add item");
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2013-12-22 18:17:32 +00:00
|
|
|
G_CALLBACK (add_item), treeview);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("Remove item");
|
2002-09-29 21:24:24 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
2005-05-25 06:28:30 +00:00
|
|
|
G_CALLBACK (remove_item), treeview);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 320, 200);
|
|
|
|
}
|
2002-01-19 20:15:56 +00:00
|
|
|
|
2010-03-01 06:47:38 +00:00
|
|
|
if (!gtk_widget_get_visible (window))
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2001-10-02 18:54:05 +00:00
|
|
|
else
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (window));
|
2001-10-02 18:54:05 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|