#include <gtk/gtk.h>

void
renderer_activated_cb (GtkCellRendererToggle *cell_renderer,
                       gchar                 *path,
                       gpointer               user_data)
{
  g_print ("activated\n");

  gtk_widget_show (GTK_WIDGET (user_data));
}

int main (int argc, char **argv)
{
  GtkBuilder *builder;
  GtkWidget *main_window;
  GtkListStore *liststore;
  GtkCellRenderer *renderer;
  GtkPopover *popover;

  gtk_init (&argc, &argv);

  builder = gtk_builder_new_from_string ("\
<?xml version='1.0' encoding='UTF-8'?>\
<interface>\
  <requires lib='gtk+' version='3.20'/>\
  <object class='GtkListStore' id='store'>\
    <columns>\
      <!-- column-name name -->\
      <column type='gchararray'/>\
    </columns>\
  </object>\
  <object class='GtkPopover' id='popover'>\
    <property name='relative_to'>treeview</property>\
    <child>\
      <object class='GtkSpinButton'>\
        <property name='visible'>True</property>\
      </object>\
    </child>\
  </object>\
  <object class='GtkWindow' id='main_window'>\
    <child>\
      <object class='GtkScrolledWindow'>\
        <property name='visible'>True</property>\
        <child>\
          <object class='GtkTreeView' id='treeview'>\
            <property name='model'>store</property>\
            <child>\
              <object class='GtkTreeViewColumn' id='column'>\
                <child>\
                  <object class='GtkCellRendererToggle' id='renderer'/>\
                </child>\
              </object>\
            </child>\
          </object>\
        </child>\
      </object>\
    </child>\
  </object>\
</interface>\
", -1);

  main_window = GTK_WIDGET (gtk_builder_get_object (builder, "main_window"));
  g_signal_connect(G_OBJECT (main_window), "destroy", G_CALLBACK (gtk_main_quit), NULL);

  renderer = GTK_CELL_RENDERER (gtk_builder_get_object (builder, "renderer"));
  popover = GTK_POPOVER (gtk_builder_get_object (builder, "popover"));

  g_signal_connect (G_OBJECT (renderer),
      "toggled", G_CALLBACK (renderer_activated_cb), popover);

  liststore = GTK_LIST_STORE (gtk_builder_get_object (builder, "store"));
  gtk_list_store_insert_with_values (liststore, NULL, -1, 0, "Foo", -1);
  gtk_list_store_insert_with_values (liststore, NULL, -1, 0, "Bar", -1);

  gtk_builder_connect_signals (builder, NULL);

  gtk_widget_show_all (GTK_WIDGET (main_window));

  gtk_main ();

  return 0;
}
