2 * Copyright (C) 2001 Red Hat, Inc
3 * Author: Jonathan Blandford
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
24 GtkTreeModel *model = NULL;
25 static GRand *grand = NULL;
26 GtkTreeSelection *selection = NULL;
33 static char *words[] =
49 initialize_model (void)
54 model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING);
55 grand = g_rand_new ();
56 for (i = 0; i < NUM_ROWS; i++)
58 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
59 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
60 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
73 i = g_rand_int_range (grand, 0,
74 gtk_tree_model_iter_n_children (model, NULL));
75 path = gtk_tree_path_new ();
76 gtk_tree_path_append_index (path, i);
77 gtk_tree_model_get_iter (model, &iter, path);
78 gtk_tree_path_free (path);
80 if (gtk_tree_selection_iter_is_selected (selection, &iter))
82 switch (g_rand_int_range (grand, 0, 3))
86 gtk_list_store_insert_after (GTK_LIST_STORE (model),
88 gtk_list_store_set (GTK_LIST_STORE (model), &iter2,
89 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
94 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
96 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
101 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
103 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
104 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
115 for (i = 0; i < 15; i++)
117 g_print ("Number of rows: %d\n", gtk_tree_model_iter_n_children (model, NULL));
122 main (int argc, char *argv[])
126 GtkWidget *scrolled_window;
127 GtkWidget *tree_view;
132 gtk_init (&argc, &argv);
134 path = gtk_tree_path_new_from_string ("80");
135 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
136 gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
137 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
138 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 8);
139 gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
140 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"), FALSE, FALSE, 0);
141 gtk_container_add (GTK_CONTAINER (window), vbox);
142 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
143 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
144 GTK_POLICY_AUTOMATIC,
145 GTK_POLICY_AUTOMATIC);
146 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
149 tree_view = gtk_tree_view_new_with_model (model);
150 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0);
151 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
152 gtk_tree_selection_select_path (selection, path);
153 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
154 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
155 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
158 gtk_cell_renderer_text_new (),
161 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
162 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, FALSE, FALSE);
163 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
164 button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
165 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
166 gtk_label_set_use_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), TRUE);
167 g_signal_connect (button, "clicked", G_CALLBACK (futz), NULL);
168 g_signal_connect (button, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
169 gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
170 gtk_widget_show_all (window);
171 gdk_threads_add_timeout (1000, (GSourceFunc) futz, NULL);