I need to check data a user inputs on one of numerous GtkEntry's on window,
and I need to handle the situation when the entry loses focus (by TABing out
of the field, or by mouse control.  When I encouter bad input, I bring up a
dialog box.  The problem is I get an GtkWarning and GtkError:

the GtkWarning is:

    Gtk-WARING **: GtkEntry - did not receive focus-out-event. If you
    connect to a handler to this signal, it must return
    FALSE so the entry gets the event as well.

the Error is a message box:

    Gtk-ERROR **:  file gtkentry.c: line 4886 (blink_cb): assertion failed: 
(GTK_WIDGET_HAS_FOCUS(entry))
    aborting...

a sample C program which duplicates the error is below.  Is there anyway to 
bring up a dialog box
in a focus-out-event handler that wont trigger this error?
I am using  GTK version 2.6.4  on Windows XP.

Zvi

/* test2.c */

    #include <gtk/gtk.h>

    GtkWidget *frm_main, *entry1, *entry2, *box;

    void dstry()
    {
        gtk_main_quit();
    }

    int activate(GtkWidget *w, void *p)
    {
         g_print("in activate()\n");
         check_data(w);
         g_print("leaving activate()\n");
     return FALSE;
    }

    int focus_out(GtkWidget *w, void *p)
    {
     g_print("in focus_out()\n");
     check_data(w);
     g_print("leaving focus_out()\n");
     return FALSE;
    }

    int check_data(GtkWidget *w)
    {
     GtkWidget *dialog;
     int resp;
     char *data = gtk_entry_get_text(w);

     g_print("in check_data(), data = \"%s\"\n", data);

     if (!strcmp(data, "abcd"))
     {
      g_print("leaving check_data(1)\n");
      return 1;
     }

         dialog = gtk_message_dialog_new (GTK_WINDOW (frm_main),
               GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
               GTK_MESSAGE_INFO, GTK_BUTTONS_OK,
               "INVALID DATA");

         switch (resp = gtk_dialog_run (GTK_DIALOG (dialog))) {
         case GTK_RESPONSE_OK:
         default:
              gtk_widget_destroy (dialog);
              g_print("leaving check_data(0)\n");
              return 0;
         }
}

int main(int argc, char **argv)
{
 gtk_init(&argc, &argv);

 frm_main = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_window_set_position(GTK_WINDOW(frm_main),GTK_WIN_POS_CENTER);
 gtk_window_set_default_size(GTK_WINDOW(frm_main), 500, 500);
 g_signal_connect (G_OBJECT(frm_main), "destroy", G_CALLBACK (dstry), NULL);

 box = gtk_hbox_new(TRUE, 10);
 gtk_container_add(GTK_CONTAINER(frm_main), box);

 entry1 = gtk_entry_new_with_max_length(20);
 gtk_container_add(GTK_CONTAINER(box), entry1);
 g_signal_connect (G_OBJECT (entry1), "focus-out-event",
                    G_CALLBACK (focus_out), NULL);
 g_signal_connect (G_OBJECT (entry1), "activate",
                    G_CALLBACK (activate), NULL);

 entry2 = gtk_entry_new_with_max_length(20);
 gtk_container_add(GTK_CONTAINER(box), entry2);

 gtk_widget_show_all(frm_main);
 gtk_main();
 exit (0);
} 


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to