4 GtkTreeModel *model = NULL;
5 static GRand *grand = NULL;
6 GtkTreeSelection *selection = NULL;
13 static char *words[] =
29 initialize_model (void)
34 model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING);
35 grand = g_rand_new ();
36 for (i = 0; i < NUM_ROWS; i++)
38 gtk_list_store_append (GTK_LIST_STORE (model), &iter);
39 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
40 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
53 i = g_rand_int_range (grand, 0,
54 gtk_tree_model_iter_n_children (model, NULL));
55 path = gtk_tree_path_new ();
56 gtk_tree_path_append_index (path, i);
57 gtk_tree_model_get_iter (model, &iter, path);
58 gtk_tree_path_free (path);
60 if (gtk_tree_selection_iter_is_selected (selection, &iter))
62 switch (g_rand_int_range (grand, 0, 3))
66 gtk_list_store_insert_after (GTK_LIST_STORE (model),
68 gtk_list_store_set (GTK_LIST_STORE (model), &iter2,
69 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
74 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
76 gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
81 if (gtk_tree_model_iter_n_children (model, NULL) == 0)
83 gtk_list_store_set (GTK_LIST_STORE (model), &iter,
84 TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
95 for (i = 0; i < 15; i++)
97 g_print ("Number of rows: %d\n", gtk_tree_model_iter_n_children (model, NULL));
102 main (int argc, char *argv[])
106 GtkWidget *scrolled_window;
107 GtkWidget *tree_view;
112 gtk_init (&argc, &argv);
114 path = gtk_tree_path_new_from_string ("80");
115 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
116 gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
117 g_signal_connect (window, "destroy", gtk_main_quit, NULL);
118 vbox = gtk_vbox_new (FALSE, 8);
119 gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
120 gtk_box_pack_start (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"), FALSE, FALSE, 0);
121 gtk_container_add (GTK_CONTAINER (window), vbox);
122 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
123 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
124 GTK_POLICY_AUTOMATIC,
125 GTK_POLICY_AUTOMATIC);
126 gtk_box_pack_start (GTK_BOX (vbox), scrolled_window, TRUE, TRUE, 0);
129 tree_view = gtk_tree_view_new_with_model (model);
130 gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0);
131 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
132 gtk_tree_selection_select_path (selection, path);
133 gtk_tree_view_set_rules_hint (GTK_TREE_VIEW (tree_view), TRUE);
134 gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
135 gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
138 gtk_cell_renderer_text_new (),
141 gtk_container_add (GTK_CONTAINER (scrolled_window), tree_view);
142 hbox = gtk_hbox_new (FALSE, FALSE);
143 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
144 button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
145 gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 0);
146 gtk_label_set_use_markup (GTK_LABEL (GTK_BIN (button)->child), TRUE);
147 g_signal_connect (button, "clicked", G_CALLBACK (futz), NULL);
148 g_signal_connect (button, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
149 gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
150 gtk_widget_show_all (window);
151 g_timeout_add (1000, (GSourceFunc) futz, NULL);