calling a function on "destroy" signal
- From: John C Atkeson <jcatkeson juno com>
- To: gtk-list redhat com
- Subject: calling a function on "destroy" signal
- Date: Wed, 13 Oct 1999 18:24:08 EDT
I'm trying to catch the event when a particular widget is destroyed, so
I can free some user_data along with it.
But, even though I've tried a lot of different combinations, the
free_luggage function is never called.
The code is below, is there something obvious that I'm missing?
Thanks in advance,
John
/* derived from scribble.c */
#include <gtk/gtk.h>
#include <stdlib.h>
#include <stdio.h>
GtkWidget *window;
typedef unsigned char byte;
typedef struct MyLuggageType{
char MyString[256];
long MyData;
}MyLuggageT;
gint free_luggage(GtkWidget *dummy, MyLuggageT *MyLuggage)
/**************************************************************
* *Supposed* to be called when this widget is destroyed.
**************************************************************/
{
long cnt;
free(MyLuggage);
g_print("Luggage freed!\n");
getchar(); /* wait for user to acknowledge */
return (FALSE);
}
GtkWidget *my_window_create(gdouble wdt,gdouble hgt)
/**************************************************************
**************************************************************/
{
GtkWidget *drawing_area = gtk_drawing_area_new ();
MyLuggageT *MyLuggage=malloc(sizeof(MyLuggageT));
MyLuggage->MyData=20;
gtk_object_set_user_data (GTK_OBJECT(drawing_area), MyLuggage);
gtk_drawing_area_size (GTK_DRAWING_AREA (drawing_area), wdt, hgt);
gtk_widget_show (drawing_area);
/* this doesn't work */
gtk_signal_connect (GTK_OBJECT (drawing_area), "destroy_event",
GTK_SIGNAL_FUNC (free_luggage), MyLuggage);
/* nor this either */
gtk_signal_connect (GTK_OBJECT (drawing_area), "destroy",
GTK_SIGNAL_FUNC (free_luggage), MyLuggage);
return (drawing_area);
}/* my_window_create */
void quit ()
/**************************************************************
**************************************************************/
{
gtk_exit (0);
}
int main (int argc, char *argv[])
/**************************************************************
**************************************************************/
{
GtkWidget *drawing_area;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_widget_set_name (window, "Test Input");
gtk_signal_connect (GTK_OBJECT (window), "destroy",
GTK_SIGNAL_FUNC (quit), NULL);
/* Create the drawing area */
drawing_area = my_window_create(200, 200);
gtk_container_add (GTK_CONTAINER (window), drawing_area);
gtk_widget_set_events (drawing_area, GDK_EXPOSURE_MASK
| GDK_LEAVE_NOTIFY_MASK
| GDK_DESTROY
| GDK_DELETE);
gtk_widget_show (window);
gtk_main ();
return 0;
}
/* example-end */
___________________________________________________________________
Get the Internet just the way you want it.
Free software, free e-mail, and free Internet access for a month!
Try Juno Web: http://dl.www.juno.com/dynoget/tagj.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]