From 04b9887c41506d308aac7b89858b3bd5a4bb9ec4 Mon Sep 17 00:00:00 2001 From: Ettore Perazzoli Date: Sun, 10 Sep 2000 16:30:36 +0000 Subject: Implemented a new `e_gtk_signal_connect_full_while_alive()' utility that does what `gtk_signal_connect_full()' does, but with additional destruction safety as provided by `gtk_signal_connect_while_alive()'. svn path=/trunk/; revision=5303 --- e-util/ChangeLog | 7 ++++ e-util/Makefile.am | 20 +++++----- e-util/e-gtk-utils.c | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-gtk-utils.h | 39 +++++++++++++++++++ 4 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 e-util/e-gtk-utils.c create mode 100644 e-util/e-gtk-utils.h (limited to 'e-util') diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 19aca4a76f..4ad4c0e6af 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,10 @@ +2000-09-10 Ettore Perazzoli + + * e-gtk-utils.c: New. + (e_gtk_signal_connect_full_while_alive): New. + + * e-gtk-utils.h: New. + 2000-09-08 Lauris Kaplinski * e-font.c: Use experimental 16-bit font stuff for EFonts diff --git a/e-util/Makefile.am b/e-util/Makefile.am index d0659bcd4a..063791c633 100644 --- a/e-util/Makefile.am +++ b/e-util/Makefile.am @@ -11,40 +11,42 @@ INCLUDES = \ noinst_LTLIBRARIES = libeutil.la libeutil-static.la libeutil_la_SOURCES = \ - e-canvas.c \ - e-canvas.h \ e-canvas-utils.c \ e-canvas-utils.h \ e-canvas-vbox.c \ e-canvas-vbox.h \ + e-canvas.c \ + e-canvas.h \ e-cursors.c \ e-cursors.h \ e-dialog-widgets.c \ e-dialog-widgets.h \ + e-font.c \ + e-font.h \ + e-gtk-utils.c \ + e-gtk-utils.h \ e-gui-utils.c \ e-gui-utils.h \ e-html-utils.c \ e-html-utils.h \ e-iterator.c \ e-iterator.h \ - e-list.c \ - e-list.h \ e-list-iterator.c \ e-list-iterator.h \ + e-list.c \ + e-list.h \ e-popup-menu.c \ e-popup-menu.h \ e-printable.c \ e-printable.h \ e-sexp.c \ e-sexp.h \ + e-unicode.c \ + e-unicode.h \ e-util.c \ e-util.h \ e-xml-utils.c \ - e-xml-utils.h \ - e-font.c \ - e-font.h \ - e-unicode.c \ - e-unicode.h + e-xml-utils.h libeutil_la_LIBADD = $(UNICODE_LIBS) diff --git a/e-util/e-gtk-utils.c b/e-util/e-gtk-utils.c new file mode 100644 index 0000000000..3cca1d0789 --- /dev/null +++ b/e-util/e-gtk-utils.c @@ -0,0 +1,106 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-gtk-utils.c + * + * Copyright (C) 2000 Helix Code, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "e-gtk-utils.h" + + +/* (Cut and pasted from Gtk.) */ + +typedef struct DisconnectInfo { + unsigned int signal_handler; + + GtkObject *object1; + unsigned int disconnect_handler1; + + GtkObject *object2; + unsigned int disconnect_handler2; +} DisconnectInfo; + +static unsigned int +alive_disconnecter (GtkObject *object, + DisconnectInfo *info) +{ + g_assert (info != NULL); + + gtk_signal_disconnect (info->object1, info->disconnect_handler1); + gtk_signal_disconnect (info->object1, info->signal_handler); + gtk_signal_disconnect (info->object2, info->disconnect_handler2); + + g_free (info); + + return 0; +} + +/** + * e_gtk_signal_connect_full_while_alive: + * @object: + * @name: + * @func: + * @marshal: + * @data: + * @destroy_func: + * @object_signal: + * @after: + * @alive_object: + * + * Connect a signal like `gtk_signal_connect_while_alive()', but with full + * params like `gtk_signal_connect_full()'. + **/ +void +e_gtk_signal_connect_full_while_alive (GtkObject *object, + const char *name, + GtkSignalFunc func, + GtkCallbackMarshal marshal, + void *data, + GtkDestroyNotify destroy_func, + gboolean object_signal, + gboolean after, + GtkObject *alive_object) +{ + DisconnectInfo *info; + + g_return_if_fail (GTK_IS_OBJECT (object)); + g_return_if_fail (name != NULL); + g_return_if_fail (func != NULL); + g_return_if_fail (GTK_IS_OBJECT (alive_object)); + + info = g_new (DisconnectInfo, 1); + + info->signal_handler = gtk_signal_connect_full (object, name, + func, marshal, data, + destroy_func, + object_signal, after); + + info->object1 = object; + info->disconnect_handler1 = gtk_signal_connect (object, "destroy", + GTK_SIGNAL_FUNC (alive_disconnecter), info); + + info->object2 = alive_object; + info->disconnect_handler2 = gtk_signal_connect (alive_object, "destroy", + GTK_SIGNAL_FUNC (alive_disconnecter), info); +} diff --git a/e-util/e-gtk-utils.h b/e-util/e-gtk-utils.h new file mode 100644 index 0000000000..0dc6b68512 --- /dev/null +++ b/e-util/e-gtk-utils.h @@ -0,0 +1,39 @@ +/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ +/* e-gtk-utils.c + * + * Copyright (C) 2000 Helix Code, Inc. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + * + * Author: Ettore Perazzoli + */ + +#ifndef E_GTK_UTILS_H +#define E_GTK_UTILS_H + +#include + +void e_gtk_signal_connect_full_while_alive (GtkObject *object, + const char *name, + GtkSignalFunc func, + GtkCallbackMarshal marshal, + void *data, + GtkDestroyNotify destroy_func, + gboolean object_signal, + gboolean after, + GtkObject *alive_object); + +#endif -- cgit v1.2.3