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

static void
on_button_activate (GtkToggleButton *button,
                    GtkLabel        *label)
{
  if (gtk_toggle_button_get_active (button))
    gtk_label_set_text (label, "other text");
  else
    gtk_label_set_text (label, "PRIMARY selection");
}

int
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *grid;
  GtkWidget *label;
  GtkWidget *button;
  GtkWidget *entry;
  GtkWidget *scrolled_window;
  GtkWidget *text_view;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (window), 500, 500);
  g_signal_connect (window, "destroy", gtk_main_quit, NULL);

  grid = gtk_grid_new ();
  gtk_orientable_set_orientation (GTK_ORIENTABLE (grid), GTK_ORIENTATION_VERTICAL);
  gtk_container_add (GTK_CONTAINER (window), grid);

  label = gtk_label_new ("PRIMARY selection");
  gtk_label_set_selectable (GTK_LABEL (label), TRUE);
  gtk_container_add (GTK_CONTAINER (grid), label);

  button = gtk_toggle_button_new_with_label ("Change label");
  gtk_container_add (GTK_CONTAINER (grid), button);

  g_signal_connect (button,
                    "toggled",
                    G_CALLBACK (on_button_activate),
                    label);

  entry = gtk_entry_new ();
  gtk_container_add (GTK_CONTAINER (grid), entry);

  scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  gtk_container_add (GTK_CONTAINER (grid), scrolled_window);

  text_view = gtk_text_view_new ();
  gtk_container_add (GTK_CONTAINER (scrolled_window), text_view);

  gtk_widget_show_all (window);

  gtk_main ();
  return EXIT_SUCCESS;
}
