#include <gtk/gtk.h>

enum
{
    COLUMN_NAME,
    NUM_COLUMNS
};

    static GtkTreeModel *
create_model (void)
{
    GtkListStore * store = gtk_list_store_new (NUM_COLUMNS,
                                               G_TYPE_STRING);
    GtkTreeIter iter;

    for (gint i = 0; i < 3; i++)
    {
        gtk_list_store_append (store, &iter);
        gtk_list_store_set (store, &iter,
                            COLUMN_NAME, "test",
                            -1);
    }

    return GTK_TREE_MODEL (store);
}

    static void
add_columns (GtkTreeView *treeview)
{
    GtkCellRenderer *renderer = gtk_cell_renderer_text_new ();
    GtkTreeViewColumn *column = gtk_tree_view_column_new_with_attributes ("Name",
                                                                          renderer,
                                                                          "text",
                                                                          COLUMN_NAME,
                                                                          NULL);
    gtk_tree_view_append_column (treeview, column);

}

    static void
do_list_store (void)
{
    GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title (GTK_WINDOW (window), "List Store");

    g_signal_connect (window, "destroy",
                      G_CALLBACK (gtk_widget_destroyed), &window);
    gtk_container_set_border_width (GTK_CONTAINER (window), 8);

    GtkWidget *vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
    gtk_container_add (GTK_CONTAINER (window), vbox);

    GtkWidget *label = gtk_label_new (
                                      "To trigger the bug start rubberbanding below the last row,\n then move the mouse up to select the last row\n and go below the last row again while still holding the mouse button.\n The application should then abort.");
    gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);

    GtkWidget *sw = gtk_scrolled_window_new (NULL, NULL);
    gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (sw),
                                         GTK_SHADOW_ETCHED_IN);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
                                    GTK_POLICY_NEVER,
                                    GTK_POLICY_AUTOMATIC);
    gtk_box_pack_start (GTK_BOX (vbox), sw, TRUE, TRUE, 0);

    GtkTreeModel *model = create_model ();
    GtkWidget *treeview = gtk_tree_view_new_with_model (model);

    // NOTE: important to trigger that bug
    gtk_tree_view_set_rubber_banding (GTK_TREE_VIEW (treeview), TRUE);
    GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview));
    gtk_tree_selection_set_mode (sel, GTK_SELECTION_MULTIPLE);

    g_object_unref (model);

    gtk_container_add (GTK_CONTAINER (sw), treeview);

    add_columns (GTK_TREE_VIEW (treeview));

    gtk_window_set_default_size (GTK_WINDOW (window), 280, 250);
    gtk_widget_show_all (window);
}

    int
main(int argc, char **argv)
{
    gtk_init(&argc, &argv);

    do_list_store();

    gtk_main();
    return 0;
}
