#include <gtk/gtk.h>

/* unlike the editing the second column values of "friend" and "hat", when editing (by double clicking) the last entry "log", the entry box is displayed vertically above the "log" entry, as opposed to on-top of the entry.

This behaviour disappers if the tree view is placed directly in the window, rather than in the vertical box

This behaviour also disappears if box orientation is changed from GTK_ORIENTATION_VERTICAL to GTK_ORIENTATION_HORIZONTAL

*/

int main (void){
	gtk_init();

	GtkWidget * window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

	GtkTreeStore * tree_store =  gtk_tree_store_new (2, G_TYPE_STRING, G_TYPE_STRING);
	GtkTreeIter iter;
	gtk_tree_store_append(tree_store,&iter,NULL);
	gtk_tree_store_set (tree_store, &iter, 0, "bear", 1 , "friend",-1);
	gtk_tree_store_append(tree_store,&iter,NULL);
	gtk_tree_store_set (tree_store, &iter, 0, "monkey", 1 , "hat",-1);
	gtk_tree_store_append(tree_store,&iter,NULL);
	gtk_tree_store_set (tree_store, &iter, 0, "crow", 1 , "log",-1);

	GtkWidget * tree = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));

	GtkCellRenderer * renderer = gtk_cell_renderer_text_new();
	GtkTreeViewColumn * column = gtk_tree_view_column_new_with_attributes("the name",renderer,"text",0,NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);

	renderer = gtk_cell_renderer_text_new ();

	g_object_set(G_OBJECT(renderer),"editable",TRUE,NULL);
	column = gtk_tree_view_column_new_with_attributes("the value",renderer,"text",1,NULL);
	gtk_tree_view_append_column(GTK_TREE_VIEW(tree),column);

	GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL,10);
	gtk_container_add(GTK_CONTAINER(window),box);
	gtk_box_pack_start(GTK_BOX(box),tree);

	gtk_widget_show(window);

	gtk_main();

	return 0;
}
