Re: Intelligent focus_out event trapping




Shevek <shevek@plaice.valhalla.net> writes:

> In writing a network database client in GTK (Similar to Oracle, Filemaker,
> et al) it is convenient to send an update query to the database server
> whenever a field is modified, and the cursor leaves the field (ie the user
> commits the alterations).
> 
> I have found two signals possibly appropriate for this, but they both
> have problems.
> 245      gtk_signal_connect_object (GTK_OBJECT (entry), "focus_out_event",
> 246                      GTK_SIGNAL_FUNC (dv_temp1), NULL);
> This is called whenever the focus leaves the widget. This is very good
> indeed for most of the widgets on the form, but if you drag the window, or
> move the mouse in or out of the window, this is called, even when the
> contents of the entry have not actually changed, or the user has not
> 'committed' the changes.

Yes. That occurs because the "focus_out_event" is emitted exactly
when keystrokes will no longer go to that widget - so also
when the toplevel loses the focus.

I think you may be able to get the effect you want by attaching
to "set_focus" on the toplevel window.

gtk_signal_connect(GTK_OBJECT(window), "set_focus",
                   GTK_SIGNAL_FUNC(my_focus_callback), form_data)
{
}

static void
my_focus_callback (GtkWindow *window,
		   GtkWidget *focus.
                   FormData *form_data)
{
  if (window->focus_widget == form_data->entry_a)
    /* Commit the changes to form_data->entry_a */
}

[...]

> If anyone has any neat solutions to this, I would be very grateful for
> some information. Otherwise, I will probably write a function to implement
> the second of the methods mentioned above. It's made a little trickier
> because in this app absolutely everything has to be a pointer on the
> stack, I can't instantiate a form as a static object as in testgtk.c
> 
> Thanks in advance for your help.

I haven't actually tried the above, but I think it should work.

Regards,
                                        Owen



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