// Compile me with:
// gcc -W -Wall -o main main.c $(pkg-config --cflags --libs gtk+-2.0)

#include <stdlib.h>
#include <gtk/gtk.h>

static GtkWidget * create_icon_view (GtkListStore *store);

enum
{
	COL_TEXT,
	COL_PIXBUF,
	N_COLS
};

static GtkWidget *
create_icon_view (GtkListStore *store)
{
	GtkWidget *icon_view = gtk_icon_view_new_with_model (
			GTK_TREE_MODEL (store));
	gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
			GTK_SELECTION_SINGLE);

	// this line is problematic
	gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), COL_TEXT);

	gtk_icon_view_set_pixbuf_column (GTK_ICON_VIEW (icon_view), COL_PIXBUF);

	return icon_view;
}

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

	GtkWidget *window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (G_OBJECT (window), "destroy",
			G_CALLBACK (gtk_main_quit), NULL);

	/* create and fill the list store */
	GtkListStore *store = gtk_list_store_new (N_COLS,
			G_TYPE_STRING, GDK_TYPE_PIXBUF);

	GdkPixbuf *pixbuf = gtk_widget_render_icon (window, GTK_STOCK_ABOUT,
			GTK_ICON_SIZE_BUTTON, NULL);

	GtkTreeIter iter;
	gtk_list_store_append (store, &iter);
	gtk_list_store_set (store, &iter,
			COL_TEXT, "test",
			COL_PIXBUF, pixbuf,
			-1);

	g_object_unref (pixbuf);

	/* create icon view */
	GtkWidget *icon_view = create_icon_view (store);

	// we want to display only icons (no text)
	gtk_icon_view_set_text_column (GTK_ICON_VIEW (icon_view), -1);

	gtk_container_add (GTK_CONTAINER (window), icon_view);

	gtk_widget_show_all (window);
	gtk_main ();
	return EXIT_SUCCESS;
}
