#include <gtk/gtk.h>

GtkListStore* selections;

void cell_data_func(GtkTreeViewColumn* tree_column, GtkCellRenderer* cell,
			GtkTreeModel* tree_model, GtkTreeIter* iter, gpointer data)
{
	g_object_set(cell, "text-column", 0, NULL);
	g_object_set(cell, "model", selections, NULL);
	g_object_set(cell, "editable", TRUE, NULL);
}

int main(int argc, char* argv[])
{
	GtkWidget* mainwin;
	GtkListStore* list_store;
	GtkTreeIter iter;
	GtkWidget* tree;
	GtkTreeViewColumn* column;
	GtkCellRenderer* renderer;
	int i;

	gtk_init(&argc, &argv);

	mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	g_signal_connect(mainwin, "delete_event", gtk_main_quit, NULL);

	list_store = gtk_list_store_new(1, G_TYPE_STRING);

	for (i=1; i<3; i++)
	{
		gchar buf[20];
		sprintf(buf, "item %d", i);

		gtk_list_store_append(list_store, &iter);
		gtk_list_store_set(list_store, &iter, 0, buf, -1);
	}

	selections = gtk_list_store_new(1, G_TYPE_STRING);

	for (i=1; i<3; i++)
	{
		gchar buf[20];
		sprintf(buf, "selection %d", i);

		gtk_list_store_append(selections, &iter);
		gtk_list_store_set(selections, &iter, 0, buf, -1);
	}

	tree = gtk_tree_view_new();

	/* First column.*/
	renderer = gtk_cell_renderer_combo_new();

	column = gtk_tree_view_column_new_with_attributes("Name",
		       renderer, "text", 0, NULL);	

	gtk_tree_view_column_set_cell_data_func(column, renderer, cell_data_func, NULL, NULL);

	g_object_set(renderer, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL);

	gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column);

	gtk_tree_view_set_model(GTK_TREE_VIEW(tree), list_store);

	/* Show code. */
	gtk_container_add (GTK_CONTAINER (mainwin), tree);

	gtk_widget_show_all(mainwin);

	gtk_main();

	return 0;
}
