+/* 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
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
#include <gtk/gtk.h>
#include <stdlib.h>
#include <string.h>
GtkTreeStore *base_model;
+static gint node_count = 0;
static void
selection_changed (GtkTreeSelection *selection,
static void
node_set (GtkTreeIter *iter)
{
- static gint i = 0;
gint n;
gchar *str;
- str = g_strdup_printf ("Row (<span color=\"red\">%d</span>)", i++);
+ str = g_strdup_printf ("Row (<span color=\"red\">%d</span>)", node_count++);
gtk_tree_store_set (base_model, iter, 0, str, -1);
g_free (str);
}
}
+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++);
+ str2 = g_strdup_printf ("%d", atoi (gtk_entry_get_text (GTK_ENTRY (entry))));
+
+ 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);
+}
+
static void
iter_insert_before (GtkWidget *button, GtkTreeView *tree_view)
{
break;
}
- vbox = gtk_vbox_new (FALSE, 8);
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
gtk_window_set_default_size (GTK_WINDOW (window), 300, 350);
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_set_sensitive (button, FALSE);
button = gtk_button_new_with_label ("gtk_tree_store_insert");
- hbox = gtk_hbox_new (FALSE, 8);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
tree_view);
button = gtk_button_new_with_label ("gtk_tree_store_set");
- hbox = gtk_hbox_new (FALSE, 8);
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
entry = gtk_entry_new ();
gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
g_signal_connect (button, "clicked",
G_CALLBACK (iter_change),
tree_view);
+
+ button = gtk_button_new_with_label ("gtk_tree_store_insert_with_values");
+ hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 8);
+ entry = gtk_entry_new ();
+ gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 0);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, FALSE, FALSE, 0);
+ g_object_set_data (G_OBJECT (button), "user_data", entry);
+ g_signal_connect (button, "clicked",
+ G_CALLBACK (iter_insert_with_values),
+ tree_view);
button = gtk_button_new_with_label ("gtk_tree_store_insert_before");
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);