
#include <gtk/gtk.h>

static gpointer entry1, entry2;

static void
button_clicked_cb (void)
{
  gtk_widget_set_tooltip_text (entry2, gtk_entry_get_text (entry1));
}

static void
checkbox_clicked_cb (gpointer checkbox)
{
  gtk_entry_set_enable_hint (entry2, gtk_toggle_button_get_active (checkbox));
}

int
main (int argc, char **argv)
{
  gpointer win, button, vbox, checkbox;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_set_border_width (win, 40);

  vbox = gtk_vbox_new (TRUE, 20);
  gtk_container_add (win, vbox);

  entry1 = gtk_entry_new ();
  gtk_box_pack_start (vbox, entry1, TRUE, TRUE, 0);

  button = gtk_button_new_with_label ("Update hint");
  gtk_box_pack_start (vbox, button, TRUE, TRUE, 0);

  checkbox = gtk_check_button_new_with_label ("Enable hint");
  gtk_box_pack_start (vbox, checkbox, TRUE, TRUE, 0);

  entry2 = gtk_entry_new ();
  gtk_widget_set_tooltip_markup (entry2, "This is a text entry");
  gtk_box_pack_start (vbox, entry2, TRUE, TRUE, 0);

  gtk_widget_show_all (win);

  g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), NULL);
  g_signal_connect (checkbox, "notify::active", G_CALLBACK (checkbox_clicked_cb), NULL);
  g_signal_connect (win, "destroy", G_CALLBACK (gtk_main_quit), NULL);

  gtk_toggle_button_set_active (checkbox, TRUE);

  gtk_main ();

  return 0;
}
