1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
33 #include "gtkobject.h"
35 #include "gtkmarshalers.h"
36 #include "gtkprivate.h"
47 static void gtk_object_base_class_init (GtkObjectClass *class);
48 static void gtk_object_base_class_finalize (GtkObjectClass *class);
49 static void gtk_object_class_init (GtkObjectClass *klass);
50 static void gtk_object_init (GtkObject *object,
51 GtkObjectClass *klass);
52 static void gtk_object_dispose (GObject *object);
53 static void gtk_object_real_destroy (GtkObject *object);
54 static void gtk_object_finalize (GObject *object);
56 static gpointer parent_class = NULL;
57 static guint object_signals[LAST_SIGNAL] = { 0 };
60 /****************************************************
61 * GtkObject type, class and instance initialization
63 ****************************************************/
66 gtk_object_get_type (void)
68 static GType object_type = 0;
72 const GTypeInfo object_info =
74 sizeof (GtkObjectClass),
75 (GBaseInitFunc) gtk_object_base_class_init,
76 (GBaseFinalizeFunc) gtk_object_base_class_finalize,
77 (GClassInitFunc) gtk_object_class_init,
78 NULL, /* class_finalize */
79 NULL, /* class_data */
82 (GInstanceInitFunc) gtk_object_init,
83 NULL, /* value_table */
86 object_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, I_("GtkObject"),
87 &object_info, G_TYPE_FLAG_ABSTRACT);
94 gtk_object_base_class_init (GtkObjectClass *class)
99 gtk_object_base_class_finalize (GtkObjectClass *class)
104 gtk_object_class_init (GtkObjectClass *class)
106 GObjectClass *gobject_class = G_OBJECT_CLASS (class);
108 parent_class = g_type_class_ref (G_TYPE_OBJECT);
110 gobject_class->dispose = gtk_object_dispose;
111 gobject_class->finalize = gtk_object_finalize;
113 class->destroy = gtk_object_real_destroy;
115 object_signals[DESTROY] =
116 g_signal_new (I_("destroy"),
117 G_TYPE_FROM_CLASS (gobject_class),
118 G_SIGNAL_RUN_CLEANUP | G_SIGNAL_NO_RECURSE | G_SIGNAL_NO_HOOKS,
119 G_STRUCT_OFFSET (GtkObjectClass, destroy),
121 _gtk_marshal_VOID__VOID,
126 gtk_object_init (GtkObject *object,
127 GtkObjectClass *klass)
131 /********************************************
132 * Functions to end a GtkObject's life time
134 ********************************************/
136 gtk_object_destroy (GtkObject *object)
138 g_return_if_fail (GTK_IS_OBJECT (object));
140 if (!(GTK_OBJECT_FLAGS (object) & GTK_IN_DESTRUCTION))
141 g_object_run_dispose (G_OBJECT (object));
145 gtk_object_dispose (GObject *gobject)
147 GtkObject *object = GTK_OBJECT (gobject);
149 /* guard against reinvocations during
150 * destruction with the GTK_IN_DESTRUCTION flag.
152 if (!(GTK_OBJECT_FLAGS (object) & GTK_IN_DESTRUCTION))
154 GTK_OBJECT_SET_FLAGS (object, GTK_IN_DESTRUCTION);
156 g_signal_emit (object, object_signals[DESTROY], 0);
158 GTK_OBJECT_UNSET_FLAGS (object, GTK_IN_DESTRUCTION);
161 G_OBJECT_CLASS (parent_class)->dispose (gobject);
165 gtk_object_real_destroy (GtkObject *object)
167 g_signal_handlers_destroy (object);
171 gtk_object_finalize (GObject *gobject)
173 GtkObject *object = GTK_OBJECT (gobject);
175 if (g_object_is_floating (object))
177 g_warning ("A floating object was finalized. This means that someone\n"
178 "called g_object_unref() on an object that had only a floating\n"
179 "reference; the initial floating reference is not owned by anyone\n"
180 "and must be removed with g_object_ref_sink().");
183 G_OBJECT_CLASS (parent_class)->finalize (gobject);
186 #define __GTK_OBJECT_C__
187 #include "gtkaliasdef.c"