2005-07-13 05:44:22 +00:00
|
|
|
/* treestoretest.c
|
|
|
|
* Copyright (C) 2001 Red Hat, Inc
|
|
|
|
* Author: Jonathan Blandford
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2000-10-05 01:04:57 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <stdlib.h>
|
2000-11-21 09:07:45 +00:00
|
|
|
#include <string.h>
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
GtkTreeStore *base_model;
|
2006-01-15 20:13:25 +00:00
|
|
|
static gint node_count = 0;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
static void
|
2000-10-06 00:06:39 +00:00
|
|
|
selection_changed (GtkTreeSelection *selection,
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkWidget *button)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-11-09 16:52:17 +00:00
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, NULL))
|
2000-10-06 00:06:39 +00:00
|
|
|
gtk_widget_set_sensitive (button, TRUE);
|
|
|
|
else
|
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2000-10-26 00:36:47 +00:00
|
|
|
static void
|
|
|
|
node_set (GtkTreeIter *iter)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-12-21 05:27:06 +00:00
|
|
|
gint n;
|
2000-10-05 01:04:57 +00:00
|
|
|
gchar *str;
|
|
|
|
|
2006-01-15 20:13:25 +00:00
|
|
|
str = g_strdup_printf ("Row (<span color=\"red\">%d</span>)", node_count++);
|
2000-11-21 09:07:45 +00:00
|
|
|
gtk_tree_store_set (base_model, iter, 0, str, -1);
|
2000-10-05 01:04:57 +00:00
|
|
|
g_free (str);
|
|
|
|
|
2001-06-15 23:03:27 +00:00
|
|
|
n = g_random_int_range (10000,99999);
|
2000-12-21 05:27:06 +00:00
|
|
|
if (n < 0)
|
|
|
|
n *= -1;
|
|
|
|
str = g_strdup_printf ("%d", n);
|
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
gtk_tree_store_set (base_model, iter, 1, str, -1);
|
|
|
|
g_free (str);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_remove (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter selected;
|
2000-11-21 09:07:45 +00:00
|
|
|
GtkTreeModel *model;
|
|
|
|
|
|
|
|
model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (tree_view),
|
2000-11-09 16:52:17 +00:00
|
|
|
NULL,
|
2000-10-26 00:36:47 +00:00
|
|
|
&selected))
|
|
|
|
{
|
2000-11-21 09:07:45 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
|
|
|
gtk_tree_store_remove (GTK_TREE_STORE (model), &selected);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_insert (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
2001-08-19 11:48:32 +00:00
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
entry = g_object_get_data (G_OBJECT (button), "user_data");
|
2000-10-26 00:36:47 +00:00
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
2000-11-09 16:52:17 +00:00
|
|
|
NULL,
|
2000-10-26 00:36:47 +00:00
|
|
|
&selected))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert (GTK_TREE_STORE (model),
|
2000-10-27 23:34:58 +00:00
|
|
|
&iter,
|
|
|
|
&selected,
|
2019-02-28 19:31:36 +00:00
|
|
|
atoi (gtk_editable_get_text (GTK_EDITABLE (entry))));
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert (GTK_TREE_STORE (model),
|
2000-10-27 23:34:58 +00:00
|
|
|
&iter,
|
|
|
|
NULL,
|
2019-02-28 19:31:36 +00:00
|
|
|
atoi (gtk_editable_get_text (GTK_EDITABLE (entry))));
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node_set (&iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
static void
|
|
|
|
iter_change (GtkWidget *button, GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkTreeIter selected;
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
|
|
|
|
2002-10-13 23:22:33 +00:00
|
|
|
entry = g_object_get_data (G_OBJECT (button), "user_data");
|
2001-10-24 18:36:50 +00:00
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
|
|
|
NULL, &selected))
|
|
|
|
{
|
|
|
|
gtk_tree_store_set (GTK_TREE_STORE (model),
|
|
|
|
&selected,
|
|
|
|
1,
|
2019-02-28 19:31:36 +00:00
|
|
|
gtk_editable_get_text (GTK_EDITABLE (entry)),
|
2001-10-24 18:36:50 +00:00
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-15 20:13:25 +00:00
|
|
|
static void
|
|
|
|
iter_insert_with_values (GtkWidget *button, GtkTreeView *tree_view)
|
|
|
|
{
|
|
|
|
GtkWidget *entry;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
|
|
|
gchar *str1, *str2;
|
|
|
|
|
|
|
|
entry = g_object_get_data (G_OBJECT (button), "user_data");
|
|
|
|
str1 = g_strdup_printf ("Row (<span color=\"red\">%d</span>)", node_count++);
|
2019-02-28 19:31:36 +00:00
|
|
|
str2 = g_strdup_printf ("%d", atoi (gtk_editable_get_text (GTK_EDITABLE (entry))));
|
2006-01-15 20:13:25 +00:00
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
|
|
|
NULL,
|
|
|
|
&selected))
|
|
|
|
{
|
|
|
|
gtk_tree_store_insert_with_values (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
&selected,
|
|
|
|
-1,
|
|
|
|
0, str1,
|
|
|
|
1, str2,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gtk_tree_store_insert_with_values (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
NULL,
|
|
|
|
-1,
|
|
|
|
0, str1,
|
|
|
|
1, str2,
|
|
|
|
-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (str1);
|
|
|
|
g_free (str2);
|
|
|
|
}
|
|
|
|
|
2000-10-05 01:04:57 +00:00
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_insert_before (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
2001-08-19 11:48:32 +00:00
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
2000-11-09 16:52:17 +00:00
|
|
|
NULL,
|
2000-10-26 00:36:47 +00:00
|
|
|
&selected))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert_before (GTK_TREE_STORE (model),
|
2000-10-27 23:34:58 +00:00
|
|
|
&iter,
|
|
|
|
NULL,
|
|
|
|
&selected);
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert_before (GTK_TREE_STORE (model),
|
2000-10-27 23:34:58 +00:00
|
|
|
&iter,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
node_set (&iter);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_insert_after (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
2001-08-19 11:48:32 +00:00
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
2000-11-09 16:52:17 +00:00
|
|
|
NULL,
|
2000-10-26 00:36:47 +00:00
|
|
|
&selected))
|
|
|
|
{
|
2000-11-22 05:16:37 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert_after (GTK_TREE_STORE (model),
|
2000-11-22 05:16:37 +00:00
|
|
|
&iter,
|
|
|
|
NULL,
|
|
|
|
&selected);
|
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-22 05:16:37 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_insert_after (GTK_TREE_STORE (model),
|
2000-11-22 05:16:37 +00:00
|
|
|
&iter,
|
|
|
|
NULL,
|
2000-12-21 05:27:06 +00:00
|
|
|
NULL);
|
2000-11-22 05:16:37 +00:00
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_prepend (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
2000-11-21 09:07:45 +00:00
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
|
|
|
GtkTreeSelection *selection = gtk_tree_view_get_selection (tree_view);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
if (gtk_tree_selection_get_selected (selection, NULL, &selected))
|
2000-10-26 00:36:47 +00:00
|
|
|
{
|
2000-11-21 09:07:45 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
|
|
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
&selected);
|
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-21 09:07:45 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
|
|
|
gtk_tree_store_prepend (GTK_TREE_STORE (model),
|
|
|
|
&iter,
|
|
|
|
NULL);
|
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-26 00:36:47 +00:00
|
|
|
iter_append (GtkWidget *button, GtkTreeView *tree_view)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
2000-10-26 00:36:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter selected;
|
2001-08-19 11:48:32 +00:00
|
|
|
GtkTreeModel *model = gtk_tree_view_get_model (tree_view);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
|
2000-11-09 16:52:17 +00:00
|
|
|
NULL,
|
2000-10-26 00:36:47 +00:00
|
|
|
&selected))
|
|
|
|
{
|
2000-11-21 09:07:45 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &selected);
|
2000-11-21 09:07:45 +00:00
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-11-21 09:07:45 +00:00
|
|
|
if (GTK_IS_TREE_STORE (model))
|
|
|
|
{
|
2001-08-19 11:48:32 +00:00
|
|
|
gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);
|
2000-11-21 09:07:45 +00:00
|
|
|
node_set (&iter);
|
|
|
|
}
|
2000-10-26 00:36:47 +00:00
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static gboolean done = FALSE;
|
|
|
|
|
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2001-02-16 18:16:14 +00:00
|
|
|
static void
|
|
|
|
make_window (gint view_type)
|
2000-10-05 01:04:57 +00:00
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *hbox, *entry;
|
|
|
|
GtkWidget *button;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *tree_view;
|
2000-11-09 16:52:17 +00:00
|
|
|
GtkTreeViewColumn *column;
|
2000-10-05 01:04:57 +00:00
|
|
|
GtkCellRenderer *cell;
|
2001-06-14 23:25:52 +00:00
|
|
|
GObject *selection;
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* Make the Widgets/Objects */
|
|
|
|
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
2001-02-16 18:16:14 +00:00
|
|
|
switch (view_type)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Unsorted list");
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Sorted list");
|
|
|
|
break;
|
|
|
|
}
|
2000-11-21 09:07:45 +00:00
|
|
|
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
|
|
|
|
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
|
2001-02-16 18:16:14 +00:00
|
|
|
switch (view_type)
|
2000-11-21 09:07:45 +00:00
|
|
|
{
|
2001-02-16 18:16:14 +00:00
|
|
|
case 0:
|
2000-11-21 09:07:45 +00:00
|
|
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (base_model));
|
2001-02-16 18:16:14 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
GtkTreeModel *sort_model;
|
|
|
|
|
2001-06-14 23:25:52 +00:00
|
|
|
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (base_model));
|
2001-02-16 18:16:14 +00:00
|
|
|
tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (sort_model));
|
|
|
|
}
|
|
|
|
break;
|
2001-06-14 23:25:52 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2001-07-18 04:31:11 +00:00
|
|
|
tree_view = NULL; /* Quiet compiler */
|
2001-06-14 23:25:52 +00:00
|
|
|
break;
|
2000-11-21 09:07:45 +00:00
|
|
|
}
|
|
|
|
|
2001-06-14 23:25:52 +00:00
|
|
|
selection = G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)));
|
2001-08-27 19:42:08 +00:00
|
|
|
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), GTK_SELECTION_SINGLE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* Put them together */
|
|
|
|
gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_vexpand (scrolled_window, TRUE);
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), scrolled_window);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (window), vbox);
|
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* buttons */
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_remove");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (selection, "changed",
|
2001-08-19 11:48:32 +00:00
|
|
|
G_CALLBACK (selection_changed),
|
2001-06-29 16:30:25 +00:00
|
|
|
button);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_remove),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_insert");
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2000-10-05 01:04:57 +00:00
|
|
|
entry = gtk_entry_new ();
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), entry);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "user_data", entry);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_insert),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2001-10-24 18:36:50 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_set");
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2001-10-24 18:36:50 +00:00
|
|
|
entry = gtk_entry_new ();
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), entry);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "user_data", entry);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_change),
|
|
|
|
tree_view);
|
2006-01-15 20:13:25 +00:00
|
|
|
|
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_insert_with_values");
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
|
2006-01-15 20:13:25 +00:00
|
|
|
entry = gtk_entry_new ();
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), hbox);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), button);
|
|
|
|
gtk_container_add (GTK_CONTAINER (hbox), entry);
|
2006-01-15 20:13:25 +00:00
|
|
|
g_object_set_data (G_OBJECT (button), "user_data", entry);
|
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_insert_with_values),
|
|
|
|
tree_view);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_insert_before");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_insert_before),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
|
|
|
g_signal_connect (selection, "changed",
|
2001-08-19 11:48:32 +00:00
|
|
|
G_CALLBACK (selection_changed),
|
2001-06-29 16:30:25 +00:00
|
|
|
button);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_insert_after");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_insert_after),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
|
|
|
g_signal_connect (selection, "changed",
|
2001-08-19 11:48:32 +00:00
|
|
|
G_CALLBACK (selection_changed),
|
2001-06-29 16:30:25 +00:00
|
|
|
button);
|
2000-10-05 01:04:57 +00:00
|
|
|
gtk_widget_set_sensitive (button, FALSE);
|
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_prepend");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_prepend),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-10-27 23:34:58 +00:00
|
|
|
button = gtk_button_new_with_label ("gtk_tree_store_append");
|
2018-12-26 07:20:34 +00:00
|
|
|
gtk_container_add (GTK_CONTAINER (vbox), button);
|
2016-10-02 15:37:22 +00:00
|
|
|
g_signal_connect (button, "clicked",
|
|
|
|
G_CALLBACK (iter_append),
|
2002-10-13 23:22:33 +00:00
|
|
|
tree_view);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
/* The selected column */
|
|
|
|
cell = gtk_cell_renderer_text_new ();
|
2001-02-20 16:16:22 +00:00
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Node ID", cell, "markup", 0, NULL);
|
2001-06-14 23:25:52 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id (column, 0);
|
2000-11-09 16:52:17 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
cell = gtk_cell_renderer_text_new ();
|
|
|
|
column = gtk_tree_view_column_new_with_attributes ("Random Number", cell, "text", 1, NULL);
|
2001-06-14 23:25:52 +00:00
|
|
|
gtk_tree_view_column_set_sort_column_id (column, 1);
|
2000-11-21 09:07:45 +00:00
|
|
|
gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column);
|
2000-10-26 00:36:47 +00:00
|
|
|
|
2000-11-21 09:07:45 +00:00
|
|
|
/* A few to start */
|
2001-02-16 18:16:14 +00:00
|
|
|
if (view_type == 0)
|
2000-11-21 09:07:45 +00:00
|
|
|
{
|
2000-12-21 05:27:06 +00:00
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
|
|
|
iter_append (NULL, GTK_TREE_VIEW (tree_view));
|
2000-11-21 09:07:45 +00:00
|
|
|
}
|
2000-10-05 01:04:57 +00:00
|
|
|
/* Show it all */
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2000-10-05 01:04:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2001-06-30 02:38:17 +00:00
|
|
|
base_model = gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
|
2000-11-21 09:07:45 +00:00
|
|
|
|
|
|
|
/* FIXME: reverse this */
|
2001-02-16 18:16:14 +00:00
|
|
|
make_window (0);
|
2001-06-18 23:44:41 +00:00
|
|
|
make_window (1);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2000-10-05 01:04:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2001-02-16 18:16:14 +00:00
|
|
|
|