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, see <http://www.gnu.org/licenses/>.
22 GtkTreeModel *model = NULL;
23 static GRand *grand = NULL;
24 GtkTreeSelection *selection = NULL;
31 static char *words[] =
47 initialize_model (void)
52 model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING);
53 grand = g_rand_new ();
54 for (i = 0; i < NUM_ROWS; i++)
56 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
57 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
58 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
71 i = g_rand_int_range (grand, 0,
72 gtk_tree_model_iter_n_children (model, NULL));
73 path = gtk_tree_path_new ();
74 gtk_tree_path_append_index (path, i);
75 gtk_tree_model_get_iter (model, &iter, path);
76 gtk_tree_path_free (path);
78 if (gtk_tree_selection_iter_is_selected (selection, &iter))
80 switch (g_rand_int_range (grand, 0, 3))
84 gtk_list_store_insert_after (GTK_LIST_STORE (model),
86 gtk_list_store_set (GTK_LIST_STORE (model), &iter2,
87 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
92 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
94 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
99 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
101 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
102 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
113 for (i = 0; i < 15; i++)
115 g_print ("Number of rows: %d\n", gtk_tree_model_iter_n_children (model, NULL));
120 main (int argc, char *argv[])
124 GtkWidget *scrolled_window;
125 GtkWidget *tree_view;
130 gtk_init (&argc, &argv);
132 path = gtk_tree_path_new_from_string ("80");
133 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
134 gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
135 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
136 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
137 gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
138 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"), FALSE, FALSE, 0);
139 gtk_container_add (GTK_CONTAINER (window), vbox);
140 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
141 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
142 GTK_POLICY_AUTOMATIC,
143 GTK_POLICY_AUTOMATIC);
144 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
147 tree_view = gtk_tree_view_new_with_model (model);
148 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0);
149 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
150 gtk_tree_selection_select_path (selection, path);
151 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
152 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
153 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
156 gtk_cell_renderer_text_new (),
159 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
160 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
161 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
162 button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
163 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
164 gtk_label_set_use_markup (GTK_LABEL (gtk_bin_get_child (GTK_BIN (button))), TRUE);
165 g_signal_connect (button, "clicked", G_CALLBACK (futz), NULL);
166 g_signal_connect (button, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
167 gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
168 gtk_widget_show_all (window);
169 gdk_threads_add_timeout (1000, (GSourceFunc) futz, NULL);