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/.
27 #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
28 #error "Only <gtk/gtk.h> can be included directly."
31 #ifndef __GTK_OBJECT_H__
32 #define __GTK_OBJECT_H__
35 #include <gdkconfig.h>
36 #include <gtk/gtkenums.h>
37 #include <gtk/gtktypeutils.h>
38 #include <gtk/gtkdebug.h>
42 /* macros for casting a pointer to a GtkObject or GtkObjectClass pointer,
43 * and to test whether `object' and `klass' are of type GTK_TYPE_OBJECT.
44 * these are the standard macros for all GtkObject-derived classes.
46 #define GTK_TYPE_OBJECT (gtk_object_get_type ())
47 #define GTK_OBJECT(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_OBJECT, GtkObject))
48 #define GTK_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OBJECT, GtkObjectClass))
49 #define GTK_IS_OBJECT(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_OBJECT))
50 #define GTK_IS_OBJECT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OBJECT))
51 #define GTK_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), GTK_TYPE_OBJECT, GtkObjectClass))
53 /* Macros for extracting various fields from GtkObject and GtkObjectClass.
55 #define GTK_OBJECT_TYPE(object) (G_TYPE_FROM_INSTANCE (object))
56 #define GTK_OBJECT_TYPE_NAME(object) (g_type_name (GTK_OBJECT_TYPE (object)))
58 /* GtkObject only uses the first 4 bits of the flags field.
59 * Derived objects may use the remaining bits. Though this
60 * is a kinda nasty break up, it does make the size of
61 * derived objects smaller.
65 GTK_IN_DESTRUCTION = 1 << 0, /* Used internally during dispose */
66 #if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
67 GTK_FLOATING = 1 << 1,
69 GTK_RESERVED_1 = 1 << 2,
70 GTK_RESERVED_2 = 1 << 3
73 /* Macros for extracting the object_flags from GtkObject.
75 #define GTK_OBJECT_FLAGS(obj) (GTK_OBJECT (obj)->flags)
76 #ifndef GTK_DISABLE_DEPRECATED
77 #define GTK_OBJECT_FLOATING(obj) (g_object_is_floating (obj))
80 /* Macros for setting and clearing bits in the object_flags field of GtkObject.
82 #define GTK_OBJECT_SET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
83 #define GTK_OBJECT_UNSET_FLAGS(obj,flag) G_STMT_START{ (GTK_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
85 typedef struct _GtkObjectClass GtkObjectClass;
90 GInitiallyUnowned parent_instance;
92 /* 32 bits of flags. GtkObject only uses 4 of these bits and
93 * GtkWidget uses the rest. This is done because structs are
94 * aligned on 4 or 8 byte boundaries. If a new bitfield were
95 * used in GtkWidget much space would be wasted.
97 guint32 GSEAL (flags);
100 struct _GtkObjectClass
102 GInitiallyUnownedClass parent_class;
104 /* Non overridable class methods to set and get per class arguments */
105 void (*set_arg) (GtkObject *object,
108 void (*get_arg) (GtkObject *object,
112 /* Default signal handler for the ::destroy signal, which is
113 * invoked to request that references to the widget be dropped.
114 * If an object class overrides destroy() in order to perform class
115 * specific destruction then it must still invoke its superclass'
116 * implementation of the method after it is finished with its
117 * own cleanup. (See gtk_widget_real_destroy() for an example of
120 void (*destroy) (GtkObject *object);
125 /* Application-level methods */
127 GType gtk_object_get_type (void) G_GNUC_CONST;
129 #ifndef GTK_DISABLE_DEPRECATED
130 void gtk_object_sink (GtkObject *object);
132 void gtk_object_destroy (GtkObject *object);
134 /****************************************************************/
136 #ifndef GTK_DISABLE_DEPRECATED
138 GtkObject* gtk_object_new (GtkType type,
139 const gchar *first_property_name,
141 GtkObject* gtk_object_ref (GtkObject *object);
142 void gtk_object_unref (GtkObject *object);
143 void gtk_object_weakref (GtkObject *object,
144 GtkDestroyNotify notify,
146 void gtk_object_weakunref (GtkObject *object,
147 GtkDestroyNotify notify,
150 /* Set 'data' to the "object_data" field of the object. The
151 * data is indexed by the "key". If there is already data
152 * associated with "key" then the new data will replace it.
153 * If 'data' is NULL then this call is equivalent to
154 * 'gtk_object_remove_data'.
155 * The gtk_object_set_data_full variant acts just the same,
156 * but takes an additional argument which is a function to
157 * be called when the data is removed.
158 * `gtk_object_remove_data' is equivalent to the above,
159 * where 'data' is NULL
160 * `gtk_object_get_data' gets the data associated with "key".
162 void gtk_object_set_data (GtkObject *object,
165 void gtk_object_set_data_full (GtkObject *object,
168 GtkDestroyNotify destroy);
169 void gtk_object_remove_data (GtkObject *object,
171 gpointer gtk_object_get_data (GtkObject *object,
173 void gtk_object_remove_no_notify (GtkObject *object,
176 /* Set/get the "user_data" object data field of "object". It should
177 * be noted that these functions are no different than calling
178 * `gtk_object_set_data'/`gtk_object_get_data' with a key of "user_data".
179 * They are merely provided as a convenience.
181 void gtk_object_set_user_data (GtkObject *object,
183 gpointer gtk_object_get_user_data (GtkObject *object);
186 /* Object-level methods */
188 /* Object data method variants that operate on key ids. */
189 void gtk_object_set_data_by_id (GtkObject *object,
192 void gtk_object_set_data_by_id_full (GtkObject *object,
195 GtkDestroyNotify destroy);
196 gpointer gtk_object_get_data_by_id (GtkObject *object,
198 void gtk_object_remove_data_by_id (GtkObject *object,
200 void gtk_object_remove_no_notify_by_id (GtkObject *object,
202 #define gtk_object_data_try_key g_quark_try_string
203 #define gtk_object_data_force_id g_quark_from_string
205 /* GtkArg flag bits for gtk_object_add_arg_type
209 GTK_ARG_READABLE = G_PARAM_READABLE,
210 GTK_ARG_WRITABLE = G_PARAM_WRITABLE,
211 GTK_ARG_CONSTRUCT = G_PARAM_CONSTRUCT,
212 GTK_ARG_CONSTRUCT_ONLY = G_PARAM_CONSTRUCT_ONLY,
213 GTK_ARG_CHILD_ARG = 1 << 4
215 #define GTK_ARG_READWRITE (GTK_ARG_READABLE | GTK_ARG_WRITABLE)
216 void gtk_object_get (GtkObject *object,
217 const gchar *first_property_name,
218 ...) G_GNUC_NULL_TERMINATED;
219 void gtk_object_set (GtkObject *object,
220 const gchar *first_property_name,
221 ...) G_GNUC_NULL_TERMINATED;
222 void gtk_object_add_arg_type (const gchar *arg_name,
227 #endif /* GTK_DISABLE_DEPRECATED */
231 #endif /* __GTK_OBJECT_H__ */