Re: [gtk-list] Re: default signals Q
- From: Federico Mena Quintero <federico nuclecu unam mx>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: default signals Q
- Date: Thu, 13 May 1999 11:00:42 -0400
> 1. For some reason, when I do what you suggest with "delete_event"
> the gpointer *is not* passed to the callback. Is this a bug or
> the intended behavior?
The delete_event is an event signal, so make sure your callback has
the correct prototype:
gint my_callback (GtkWidget *widget, GdkEventAny *event, gpointer data);
> 2. If "delete_event" is a distinct event, how come binding the callback to
> the "destroy" event also works for the "delete_event"? (Or is "destroy"
> the default for "delete_event" unless you specify a callback for destroy.)
When a toplevel window gets a delete_event, it means the window
manager has sent a request to it asking to close itself. It is up to
the program to decide what to do. You could make your delete_event
handler prompt the user if he wants to close a window for an unsaved
file, for example. Returning FALSE specifies that the delete_event
"was not handled" and so Gtk can take the default action, which is to
destroy the window. If you return TRUE instead, it means the event
"was handled" and Gtk will do nothing else.
Now, the destroy signal is completely orthogonal. It is sent to
objects when they are destroyed. For a toplevel window widget, if
nobody handles a delete_event sent to it, the window will be
destroyed and the destroy signal will of course be emitted for it.
> In any case what I'm trying to accomplish is to have a toggle button which
> opens and closes a certain window. Of course, if the user tries to close
> the window by clicking on the WM's delete button I want the effect to be
> the same as if the toggle button was pressed. Since I have to untoggle the
> button when that happens, I have to pass something to the "delete_event"
> callback.
So pass a pointer to the button as your closure data.
gtk_signal_connect (GTK_OBJECT (my_window), "delete_event",
GTK_SIGNAL_FUNC (delete_event_cb),
my_toggle_button);
static gint
delete_event_cb (GtkWidget *widget, GdkEventAny *event, gpointer data)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data), FALSE);
gtk_widget_hide (widget);
return TRUE;
}
This assumes you will be only hiding/showing the window instead of
destroying and re-creating it every time. If you want to do the
latter, you can do away with simply connecting to the destroy signal
and un-toggling the button there.
gtk_signal_connect (GTK_OBJECT (my_window), "destroy",
GTK_SIGNAL_FUNC (destroy_cb),
my_toggle_button);
static void
destroy_cb (GtkObject *object, gpointer data)
{
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (data), FALSE);
}
Good luck,
Federico
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]