2005-07-13 05:44:22 +00:00
|
|
|
/* testtreeflow.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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2005-07-13 05:44:22 +00:00
|
|
|
*/
|
|
|
|
|
2008-06-22 14:28:52 +00:00
|
|
|
#include "config.h"
|
2001-10-18 18:58:47 +00:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
GtkTreeModel *model = NULL;
|
2005-02-03 23:29:02 +00:00
|
|
|
static GRand *grand = NULL;
|
2002-02-23 21:53:04 +00:00
|
|
|
GtkTreeSelection *selection = NULL;
|
2001-10-18 18:58:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
TEXT_COLUMN,
|
|
|
|
NUM_COLUMNS
|
|
|
|
};
|
|
|
|
|
2020-03-06 17:05:43 +00:00
|
|
|
static const char *words[] =
|
2001-10-18 18:58:47 +00:00
|
|
|
{
|
|
|
|
"Boom",
|
|
|
|
"Borp",
|
|
|
|
"Multiline\ntext",
|
|
|
|
"Bingo",
|
|
|
|
"Veni\nVedi\nVici",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define NUM_WORDS 5
|
|
|
|
#define NUM_ROWS 100
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
initialize_model (void)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2001-10-18 18:58:47 +00:00
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
model = (GtkTreeModel *) gtk_list_store_new (NUM_COLUMNS, G_TYPE_STRING);
|
2005-02-03 23:29:02 +00:00
|
|
|
grand = g_rand_new ();
|
2001-10-18 18:58:47 +00:00
|
|
|
for (i = 0; i < NUM_ROWS; i++)
|
|
|
|
{
|
|
|
|
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
2005-02-03 23:29:02 +00:00
|
|
|
TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
|
2001-10-18 18:58:47 +00:00
|
|
|
-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
futz_row (void)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2001-10-18 18:58:47 +00:00
|
|
|
GtkTreePath *path;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeIter iter2;
|
|
|
|
|
2005-02-03 23:29:02 +00:00
|
|
|
i = g_rand_int_range (grand, 0,
|
2001-10-18 18:58:47 +00:00
|
|
|
gtk_tree_model_iter_n_children (model, NULL));
|
|
|
|
path = gtk_tree_path_new ();
|
|
|
|
gtk_tree_path_append_index (path, i);
|
|
|
|
gtk_tree_model_get_iter (model, &iter, path);
|
|
|
|
gtk_tree_path_free (path);
|
|
|
|
|
2002-02-23 21:53:04 +00:00
|
|
|
if (gtk_tree_selection_iter_is_selected (selection, &iter))
|
|
|
|
return;
|
2005-02-03 23:29:02 +00:00
|
|
|
switch (g_rand_int_range (grand, 0, 3))
|
2001-10-18 18:58:47 +00:00
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
/* insert */
|
2001-12-08 01:10:52 +00:00
|
|
|
gtk_list_store_insert_after (GTK_LIST_STORE (model),
|
|
|
|
&iter2, &iter);
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter2,
|
2005-02-03 23:29:02 +00:00
|
|
|
TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
|
2001-12-08 01:10:52 +00:00
|
|
|
-1);
|
2001-10-18 18:58:47 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
/* delete */
|
|
|
|
if (gtk_tree_model_iter_n_children (model, NULL) == 0)
|
|
|
|
return;
|
|
|
|
gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/* modify */
|
2002-02-23 21:53:04 +00:00
|
|
|
return;
|
2001-10-18 18:58:47 +00:00
|
|
|
if (gtk_tree_model_iter_n_children (model, NULL) == 0)
|
|
|
|
return;
|
|
|
|
gtk_list_store_set (GTK_LIST_STORE (model), &iter,
|
2005-02-03 23:29:02 +00:00
|
|
|
TEXT_COLUMN, words[g_rand_int_range (grand, 0, NUM_WORDS)],
|
2001-12-08 01:10:52 +00:00
|
|
|
-1);
|
2001-10-18 18:58:47 +00:00
|
|
|
break;
|
2020-03-06 17:05:43 +00:00
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
2001-10-18 18:58:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
futz (void)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2001-10-18 18:58:47 +00:00
|
|
|
|
|
|
|
for (i = 0; i < 15; i++)
|
|
|
|
futz_row ();
|
|
|
|
g_print ("Number of rows: %d\n", gtk_tree_model_iter_n_children (model, NULL));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2020-02-10 03:24:47 +00:00
|
|
|
static void
|
|
|
|
quit_cb (GtkWidget *widget,
|
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
gboolean *done = data;
|
|
|
|
|
|
|
|
*done = TRUE;
|
|
|
|
|
|
|
|
g_main_context_wakeup (NULL);
|
|
|
|
}
|
|
|
|
|
2001-10-18 18:58:47 +00:00
|
|
|
int
|
|
|
|
main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
GtkWidget *window;
|
|
|
|
GtkWidget *vbox;
|
|
|
|
GtkWidget *scrolled_window;
|
|
|
|
GtkWidget *tree_view;
|
|
|
|
GtkWidget *hbox;
|
|
|
|
GtkWidget *button;
|
2002-02-23 21:53:04 +00:00
|
|
|
GtkTreePath *path;
|
2020-02-10 03:24:47 +00:00
|
|
|
gboolean done = FALSE;
|
2001-10-18 18:58:47 +00:00
|
|
|
|
2016-12-28 13:53:22 +00:00
|
|
|
gtk_init ();
|
2001-10-18 18:58:47 +00:00
|
|
|
|
2002-02-23 21:53:04 +00:00
|
|
|
path = gtk_tree_path_new_from_string ("80");
|
2020-02-14 19:55:36 +00:00
|
|
|
window = gtk_window_new ();
|
2001-10-18 18:58:47 +00:00
|
|
|
gtk_window_set_title (GTK_WINDOW (window), "Reflow test");
|
2020-02-10 03:24:47 +00:00
|
|
|
g_signal_connect (window, "destroy", G_CALLBACK (quit_cb), &done);
|
2010-10-31 17:07:20 +00:00
|
|
|
vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), gtk_label_new ("Incremental Reflow Test"));
|
2020-05-02 21:26:54 +00:00
|
|
|
gtk_window_set_child (GTK_WINDOW (window), vbox);
|
2020-06-24 15:25:09 +00:00
|
|
|
scrolled_window = gtk_scrolled_window_new ();
|
2001-10-18 18:58:47 +00:00
|
|
|
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
|
|
|
|
GTK_POLICY_AUTOMATIC,
|
|
|
|
GTK_POLICY_AUTOMATIC);
|
2017-04-21 16:59:59 +00:00
|
|
|
gtk_widget_set_vexpand (scrolled_window, TRUE);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), scrolled_window);
|
2016-10-02 15:37:22 +00:00
|
|
|
|
2001-10-18 18:58:47 +00:00
|
|
|
initialize_model ();
|
|
|
|
tree_view = gtk_tree_view_new_with_model (model);
|
2002-02-23 21:53:04 +00:00
|
|
|
gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (tree_view), path, NULL, TRUE, 0.5, 0.0);
|
|
|
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view));
|
2002-03-07 08:03:09 +00:00
|
|
|
gtk_tree_selection_select_path (selection, path);
|
2001-10-18 18:58:47 +00:00
|
|
|
gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE);
|
|
|
|
gtk_tree_view_insert_column_with_attributes (GTK_TREE_VIEW (tree_view),
|
|
|
|
-1,
|
|
|
|
NULL,
|
|
|
|
gtk_cell_renderer_text_new (),
|
|
|
|
"text", TEXT_COLUMN,
|
|
|
|
NULL);
|
2020-05-02 04:51:20 +00:00
|
|
|
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (scrolled_window), tree_view);
|
2010-10-31 17:07:20 +00:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (vbox), hbox);
|
2001-10-18 18:58:47 +00:00
|
|
|
button = gtk_button_new_with_mnemonic ("<b>_Futz!!</b>");
|
2020-05-09 12:26:52 +00:00
|
|
|
gtk_box_append (GTK_BOX (hbox), button);
|
2020-05-02 07:05:19 +00:00
|
|
|
gtk_label_set_use_markup (GTK_LABEL (gtk_button_get_child (GTK_BUTTON (button))), TRUE);
|
2002-10-13 23:22:33 +00:00
|
|
|
g_signal_connect (button, "clicked", G_CALLBACK (futz), NULL);
|
|
|
|
g_signal_connect (button, "realize", G_CALLBACK (gtk_widget_grab_focus), NULL);
|
2001-10-18 18:58:47 +00:00
|
|
|
gtk_window_set_default_size (GTK_WINDOW (window), 300, 400);
|
2017-01-19 09:02:04 +00:00
|
|
|
gtk_widget_show (window);
|
2018-02-02 14:51:47 +00:00
|
|
|
g_timeout_add (1000, (GSourceFunc) futz, NULL);
|
2020-02-10 03:24:47 +00:00
|
|
|
while (!done)
|
|
|
|
g_main_context_iteration (NULL, TRUE);
|
2001-10-18 18:58:47 +00:00
|
|
|
return 0;
|
|
|
|
}
|