problem with grab_focus



Hi there,

I have a problem with using gtk_widget_grab_focus in a
focus_out_event hander, using gtk+-1.2.10.

The attached program has three GtkEntry's, vertically aligned,
and tries to grab focus on entry1 when I leave entry2.

If I press key `GDK_Down' in the second entry (i.e., entry2),
the default action of GTK+ moves cursor to entry3, while my
handler moves cursor to entry1.  Thus, two cursors appear
simultaneously.

How could I have only entry1 focused?

Thanks in advance.

Keisuke Nishida

#include <gtk/gtk.h>

guint handler;
GtkWidget *entry1;
GtkWidget *entry2;
GtkWidget *entry3;

static void
on_focus_out (GtkEntry *entry)
{
  gtk_signal_handler_block (GTK_OBJECT (entry), handler);
  gtk_widget_grab_focus (entry1);
  gtk_signal_handler_unblock (GTK_OBJECT (entry), handler);
}

static GtkWidget *
create_window1 ()
{
  GtkWidget *window1;
  GtkWidget *vbox1;

  entry1 = gtk_entry_new ();
  entry2 = gtk_entry_new ();
  entry3 = gtk_entry_new ();
  handler = gtk_signal_connect (GTK_OBJECT (entry2), "focus_out_event",
				GTK_SIGNAL_FUNC (on_focus_out),
				NULL);

  vbox1 = gtk_vbox_new (FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox1), entry1, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox1), entry2, FALSE, FALSE, 0);
  gtk_box_pack_start (GTK_BOX (vbox1), entry3, FALSE, FALSE, 0);

  window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_container_add (GTK_CONTAINER (window1), vbox1);
  return window1;
}

int
main (int argc, char **argv)
{
  gtk_init (&argc, &argv);
  gtk_widget_show_all (create_window1 ());
  gtk_main ();
  return 0;
}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]