]> Pileus Git - ~andy/gtk/blobdiff - tests/treestoretest.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / treestoretest.c
index 7d5b5b1e496a523c620b08f333702ab9e800a44c..a3ace607125dd1cb10ac217400ecd9f0b263a655 100644 (file)
  * 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
-#include <config.h>
+#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,
@@ -37,11 +36,10 @@ 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);
 
@@ -121,6 +119,46 @@ iter_change (GtkWidget *button, GtkTreeView *tree_view)
     }
 }
 
+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)
 {
@@ -263,7 +301,7 @@ make_window (gint view_type)
       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);
@@ -311,7 +349,7 @@ make_window (gint view_type)
   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);
@@ -322,7 +360,7 @@ make_window (gint view_type)
                     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);
@@ -331,6 +369,17 @@ make_window (gint view_type)
   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);