Bus failure using focus events



Hi,

I'm trying to generate some code that checks the input a user has provided into a text entry field, and appends a trailing character if needed. I'd like to do it as soon as the user switches away from the widget, and is presumably done editing.

If I use an "activate" signal, things work fine - it does exactly what I expect, with no complaints.

However, if I use a "focus-out-event", the program eventually terminates and I get, simply, a "Bus error" message.

This happens using GTK+1.2.10, 2.0.6, as well as 2.2.1.

Can anyone point me to what I'm doing wrong?

Here's some of the code:

Here's where I connect the signal and generate the widget:

#if GTK_MAJOR_VERSION < 2

#define SIGNAL_CONNECT(widget, name, callback, arg) \
gtk_signal_connect(GTK_OBJECT(widget), name, GTK_SIGNAL_FUNC(callback), \
(gpointer)(arg))

#else /* GTK_MAJOR_VERSION >= 2 */


#define SIGNAL_CONNECT(widget, name, callback, arg) \
g_signal_connect(G_OBJECT(widget), name, G_CALLBACK(callback), \
(gpointer)(arg))


fileopen_dir_te = create_preference_entry(main_tb, 9, "Directory:", NULL, prefs.gui_fileopen_dir);
OBJECT_SET_DATA(main_vb, GUI_FILEOPEN_DIR_KEY, fileopen_dir_te);
SIGNAL_CONNECT(fileopen_dir_te, "focus-out-event", fileopen_dir_changed_cb, NULL);

Again, if I replace "focus-out-event" with "activate", things work fine if I just hit enter in the text entry field.

static void
fileopen_dir_changed_cb(GtkWidget *fileopen_entry _U_, gpointer parent_w)
{
char *lastchar;
gint fileopen_dir_te_length;


fileopen_dir_te = (GtkWidget *)OBJECT_GET_DATA(parent_w, GUI_FILEOPEN_DIR_KEY);
fileopen_dir_te_length = strlen(gtk_entry_get_text (GTK_ENTRY(fileopen_entry)));
lastchar = gtk_editable_get_chars(GTK_EDITABLE(fileopen_entry), fileopen_dir_te_length-1, -1);
if (strcmp(lastchar, "/") != 0)
gtk_entry_append_text(GTK_ENTRY(fileopen_entry), "/");
return;
}

Is there a stupid mistake I made here?

Thanks,
Ian


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