#include <gtk/gtk.h>

void
user_function (GtkCellRenderer *renderer,
               GtkCellEditable *editable,
               gchar           *path,
               gpointer         user_data)
{
  g_print ("editing started\n");
  if (GTK_IS_ENTRY (editable) && g_getenv ("GTK_FIT_SMALL_CELL") != NULL)
    gtk_entry_set_width_chars(GTK_ENTRY (editable), 0);
}

int
main (int argc, char **argv)
{
  GtkWindow *main_window;
  GtkTreeViewColumn *big_column;
  GtkTreeViewColumn *big_column2;
  GtkTreeViewColumn *small_column;
  GtkCellRenderer *small_renderer;
  GtkCellRenderer *big_renderer;
  GtkCellRenderer *big_renderer2;
  GtkListStore *store;
  GtkTreeView *tree;
  GtkBox *mainbox;
  GtkLabel *somelabel;

  gtk_init (&argc, &argv);

  main_window = GTK_WINDOW (gtk_window_new (GTK_WINDOW_TOPLEVEL));

  tree = GTK_TREE_VIEW (gtk_tree_view_new ());

  mainbox = GTK_BOX (gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0));

  gtk_container_add (GTK_CONTAINER (main_window), GTK_WIDGET (mainbox));

  store = gtk_list_store_new (3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
  gtk_list_store_insert_with_values (store, NULL, -1, 0, "فثءف هى فاهس ؤثمم", 1, "ب", 2, "تبصنتثبى ", -1);
  gtk_list_store_insert_with_values (store, NULL, -1, 0, "",                  1, "ئ", 2, "ن ", -1);
  gtk_tree_view_set_model (tree, GTK_TREE_MODEL (store));

  gtk_box_pack_start (mainbox,
                      GTK_WIDGET (tree),
                      TRUE,
                      TRUE,
                      0);

  big_column = gtk_tree_view_column_new ();
  big_renderer = gtk_cell_renderer_text_new ();
  g_object_set (G_OBJECT (big_renderer), "editable", TRUE, NULL);
  gtk_tree_view_column_pack_start (big_column, big_renderer, TRUE);
  gtk_tree_view_column_add_attribute (big_column, big_renderer, "text", 0);
  gtk_tree_view_append_column (tree, big_column);

  small_column = gtk_tree_view_column_new ();
  small_renderer = gtk_cell_renderer_text_new ();
  g_signal_connect(G_OBJECT (small_renderer), "editing-started", G_CALLBACK(user_function), NULL);
  g_object_set (G_OBJECT (small_renderer), "editable", TRUE, NULL);
  gtk_tree_view_column_pack_start (small_column, small_renderer, FALSE);
  gtk_tree_view_column_add_attribute (small_column, small_renderer, "text", 1);
  gtk_tree_view_append_column (tree, small_column);

  big_column2 = gtk_tree_view_column_new ();
  big_renderer2 = gtk_cell_renderer_text_new ();
  g_object_set (G_OBJECT (big_renderer2), "editable", TRUE, NULL);
  gtk_tree_view_column_pack_start (big_column2, big_renderer2, FALSE);
  gtk_tree_view_column_add_attribute (big_column2, big_renderer2, "text", 2);
  gtk_tree_view_append_column (tree, big_column2);

  somelabel = GTK_LABEL (gtk_label_new ("foobar"));

  gtk_box_pack_start (mainbox,
                      GTK_WIDGET (somelabel),
                      FALSE,
                      TRUE,
                      0);

  g_signal_connect(G_OBJECT (main_window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
  gtk_widget_show_all (GTK_WIDGET (main_window));

  gtk_main ();

  return 0;
}
