#include <gtk/gtk.h>

static gint
focus_out_event (GtkEntry	*entry,
		 GdkEventFocus  *event)

{
  static gboolean flip = TRUE;

  if (flip)
    { 
      GtkWidget *msg_dialog;
      msg_dialog = gtk_message_dialog_new(NULL,
					  GTK_DIALOG_MODAL,
					  GTK_MESSAGE_WARNING,
					  GTK_BUTTONS_OK,
					  "Click Ok and then click again in the textview");

      gtk_dialog_run (GTK_DIALOG(msg_dialog));
      gtk_widget_destroy (msg_dialog);
      gtk_widget_grab_focus (GTK_WIDGET (entry));
      flip = FALSE;
      return FALSE;
    }
  flip = TRUE;
  return FALSE;
}

void main (int argc, char **argv)
{
  GtkWidget *window, *entry, *textview, *vbox;
  GtkTextBuffer *buffer;

  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  g_signal_connect (G_OBJECT (window),
		    "delete_event",
		    G_CALLBACK (gtk_main_quit),
		    NULL);


  entry = gtk_entry_new ();

  g_signal_connect_after (entry,
			  "focus_out_event",
			  G_CALLBACK (focus_out_event),
			  NULL);


  textview = gtk_text_view_new ();

  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textview));

  gtk_text_buffer_set_text (buffer, "\n\tClick\n\tHere\n\n", -1);

  vbox = gtk_vbox_new (FALSE, 10);

  gtk_container_add (GTK_CONTAINER (vbox), entry);
  gtk_container_add (GTK_CONTAINER (vbox), textview);

  gtk_container_add (GTK_CONTAINER (window), vbox);

  gtk_widget_show_all (window);

  gtk_main ();
}
