]> Pileus Git - ~andy/gtk/blob - gtk/gtkobject.c
Modify the gettext translation domain for the gtk3 rename
[~andy/gtk] / gtk / gtkobject.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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.
18  */
19
20 /*
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/. 
25  */
26
27 #include "config.h"
28
29 #include <stdarg.h>
30 #include <string.h>
31 #include <stdio.h>
32
33 #include "gtkobject.h"
34 #include "gtkintl.h"
35 #include "gtkmarshalers.h"
36 #include "gtkprivate.h"
37
38 #include "gtkalias.h"
39
40
41 enum {
42   DESTROY,
43   LAST_SIGNAL
44 };
45
46
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);
55
56 static gpointer    parent_class = NULL;
57 static guint       object_signals[LAST_SIGNAL] = { 0 };
58
59
60 /****************************************************
61  * GtkObject type, class and instance initialization
62  *
63  ****************************************************/
64
65 GType
66 gtk_object_get_type (void)
67 {
68   static GType object_type = 0;
69
70   if (!object_type)
71     {
72       const GTypeInfo object_info =
73       {
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 */
80         sizeof (GtkObject),
81         16,             /* n_preallocs */
82         (GInstanceInitFunc) gtk_object_init,
83         NULL,           /* value_table */
84       };
85       
86       object_type = g_type_register_static (G_TYPE_INITIALLY_UNOWNED, I_("GtkObject"), 
87                                             &object_info, G_TYPE_FLAG_ABSTRACT);
88     }
89
90   return object_type;
91 }
92
93 static void
94 gtk_object_base_class_init (GtkObjectClass *class)
95 {
96 }
97
98 static void
99 gtk_object_base_class_finalize (GtkObjectClass *class)
100 {
101 }
102
103 static void
104 gtk_object_class_init (GtkObjectClass *class)
105 {
106   GObjectClass *gobject_class = G_OBJECT_CLASS (class);
107
108   parent_class = g_type_class_ref (G_TYPE_OBJECT);
109
110   gobject_class->dispose = gtk_object_dispose;
111   gobject_class->finalize = gtk_object_finalize;
112
113   class->destroy = gtk_object_real_destroy;
114
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),
120                   NULL, NULL,
121                   _gtk_marshal_VOID__VOID,
122                   G_TYPE_NONE, 0);
123 }
124
125 static void
126 gtk_object_init (GtkObject      *object,
127                  GtkObjectClass *klass)
128 {
129 }
130
131 /********************************************
132  * Functions to end a GtkObject's life time
133  *
134  ********************************************/
135 void
136 gtk_object_destroy (GtkObject *object)
137 {
138   g_return_if_fail (GTK_IS_OBJECT (object));
139   
140   if (!(GTK_OBJECT_FLAGS (object) & GTK_IN_DESTRUCTION))
141     g_object_run_dispose (G_OBJECT (object));
142 }
143
144 static void
145 gtk_object_dispose (GObject *gobject)
146 {
147   GtkObject *object = GTK_OBJECT (gobject);
148
149   /* guard against reinvocations during
150    * destruction with the GTK_IN_DESTRUCTION flag.
151    */
152   if (!(GTK_OBJECT_FLAGS (object) & GTK_IN_DESTRUCTION))
153     {
154       GTK_OBJECT_SET_FLAGS (object, GTK_IN_DESTRUCTION);
155       
156       g_signal_emit (object, object_signals[DESTROY], 0);
157       
158       GTK_OBJECT_UNSET_FLAGS (object, GTK_IN_DESTRUCTION);
159     }
160
161   G_OBJECT_CLASS (parent_class)->dispose (gobject);
162 }
163
164 static void
165 gtk_object_real_destroy (GtkObject *object)
166 {
167   g_signal_handlers_destroy (object);
168 }
169
170 static void
171 gtk_object_finalize (GObject *gobject)
172 {
173   GtkObject *object = GTK_OBJECT (gobject);
174
175   if (g_object_is_floating (object))
176     {
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().");
181     }
182   
183   G_OBJECT_CLASS (parent_class)->finalize (gobject);
184 }
185
186 #define __GTK_OBJECT_C__
187 #include "gtkaliasdef.c"