GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

delete_event vs. destroy?

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
TriKri
Familiar Face


Joined: 19 Mar 2008
Posts: 14

PostPosted: Thu Mar 20, 2008 5:07 pm    Post subject: delete_event vs. destroy? Reply with quote

What's the different between delete_event and destroy for a windows? Also, what is the difference between g_signal_connect and g_signal_connect_swap? Thanks in advance.
Back to top
dreblen
Familiar Face


Joined: 14 Jun 2007
Posts: 35

PostPosted: Sat Mar 22, 2008 8:22 pm    Post subject: Reply with quote

I can't seem to find the delete-event anywhere, so I can't help with that,
but for the difference between g_signal_connect and g_signal_connect_swapped, you can look at these pages:
http://library.gnome.org/devel/gobject/stable/gobject-Signals.html#g-signal-connect
http://library.gnome.org/devel/gobject/stable/gobject-Signals.html#g-signal-connect-swapped
Hope that these help
Back to top
TriKri
Familiar Face


Joined: 19 Mar 2008
Posts: 14

PostPosted: Sat Mar 22, 2008 8:48 pm    Post subject: Reply with quote

Thanks! But I didn't understand what they ment with their explanaition of g_signal_connect_swapped(). By the way, I found the delete event in their tutorial: http://library.gnome.org/devel/gtk-tutorial/stable/c39.html. It seems that the delete_event is something that is triggered by the user, while the destroy_event is triggered by something the program itself has done, like trying to destroy the window from within the program, or allowing the program to shut down from within the handel of delete_event.
Back to top
dreblen
Familiar Face


Joined: 14 Jun 2007
Posts: 35

PostPosted: Sun Mar 23, 2008 8:16 pm    Post subject: Reply with quote

my understanding of of g_signal_connect_swapped() is that the object that is calling it is passed as the argument to the callback function instead of the data argument.

as far as finding the delete_event, what I meant was something like this:
http://library.gnome.org/devel/gtk/stable/GtkWidget.html#GtkWidget-destroy-event
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 420
Location: Portland, OR USA

PostPosted: Mon Mar 24, 2008 1:26 pm    Post subject: Reply with quote

The swapped function allows you to swap the order of the arguments that are passed to the callback function. For example, if you have a GtkButton which will destroy the GtkWindow you would attach a callback function to the "clicked" signal. The callback for the "clicked" callback function is defined in the manual as:

Code: (C)
1
2
void                user_function                      (GtkButton *button,
                                                        gpointer   user_data)


This tells us that when the GtkButton is clicked, the callback function we connect will recieve the GtkButton object first, and our user_data second. This is what would happen if we used g_signal_connect ().

However, if we want to attach a callback function in which the FIRST argument is the user_data, then we use g_signal_connect_swapped (). This allows us to use some already written functions as callbacks such as gtk_widget_destroy ().

Example 1: Without using swapped

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void my_destroy_callback (GtkButton *button, gpointer user_data)
{
    /* destroy the window */
   
   
gtk_widget_destroy (GTK_WIDGET (user_data));
}

int main()
{
    GtkWidget *button;
    GtkWidget *window;

    /* create and pack widgets here ... */

   
g_signal_connect (G_OBJECT (button), "clicked",
                      G_CALLBACK (my_destroy_callback), (gpointer)window);
                     
    gtk_main();
   
    return 0;
}


Example 2: Swapping Arguments

Code: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
int main()
{
    GtkWidget *button;
    GtkWidget *window;

    /* create and pack widgets here ... */

   
g_signal_connect_swapped (G_OBJECT (button), "clicked",
                              G_CALLBACK (gtk_widget_destroy), (gpointer)window);
                     
    gtk_main();
   
    return 0;
}






As for the delete-event and destroy events, they have different uses. The delete event occurs when the GtkObject is destroyed. You might use this to cleanup other objects. The delete-event occurs when the GtkWindow is requested to be deleted (user clicks the 'x' for example) and you can stop the delete event from propagating based on your return value. This is often used to prompt people to save their work or confirm they really want to quit. Check out this example: Confirm Quit Dialog on "delete-event" signal
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP