]> Pileus Git - ~andy/gtk/blob - gtk/gtkobject.h
db6dc5bfdbcbd15b576b9731454026a5ccf6da5f
[~andy/gtk] / gtk / gtkobject.h
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 #ifndef __GTK_OBJECT_H__
28 #define __GTK_OBJECT_H__
29
30
31 #include <gtk/gtkenums.h>
32 #include <gtk/gtktypeutils.h>
33 #include <gtk/gtkdebug.h>
34
35 G_BEGIN_DECLS
36
37 /* macros for casting a pointer to a GtkObject or GtkObjectClass pointer,
38  * and to test whether `object' and `klass' are of type GTK_TYPE_OBJECT.
39  * these are the standard macros for all GtkObject-derived classes.
40  */
41 #define GTK_TYPE_OBJECT                 (gtk_object_get_type ())
42 #define GTK_OBJECT(object)              (GTK_CHECK_CAST ((object), GTK_TYPE_OBJECT, GtkObject))
43 #define GTK_OBJECT_CLASS(klass)         (GTK_CHECK_CLASS_CAST ((klass), GTK_TYPE_OBJECT, GtkObjectClass))
44 #define GTK_IS_OBJECT(object)           (GTK_CHECK_TYPE ((object), GTK_TYPE_OBJECT))
45 #define GTK_IS_OBJECT_CLASS(klass)      (GTK_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OBJECT))
46 #define GTK_OBJECT_GET_CLASS(object)    (GTK_CHECK_GET_CLASS ((object), GTK_TYPE_OBJECT, GtkObjectClass))
47
48 /* Macros for extracting various fields from GtkObject and GtkObjectClass.
49  */
50 #define GTK_OBJECT_TYPE(object)           (G_TYPE_FROM_INSTANCE (object))
51 #define GTK_OBJECT_TYPE_NAME(object)      (g_type_name (GTK_OBJECT_TYPE (object)))
52
53 /* GtkObject only uses the first 4 bits of the flags field.
54  * Derived objects may use the remaining bits. Though this
55  * is a kinda nasty break up, it does make the size of
56  * derived objects smaller.
57  */
58 typedef enum
59 {
60   GTK_IN_DESTRUCTION    = 1 << 0, /* Used internally during dispose */
61   GTK_FLOATING          = 1 << 1,
62   GTK_RESERVED_1        = 1 << 2,
63   GTK_RESERVED_2        = 1 << 3
64 } GtkObjectFlags;
65
66 /* Macros for extracting the object_flags from GtkObject.
67  */
68 #define GTK_OBJECT_FLAGS(obj)             (GTK_OBJECT (obj)->flags)
69 #define GTK_OBJECT_FLOATING(obj)          ((GTK_OBJECT_FLAGS (obj) & GTK_FLOATING) != 0)
70
71 /* Macros for setting and clearing bits in the object_flags field of GtkObject.
72  */
73 #define GTK_OBJECT_SET_FLAGS(obj,flag)    G_STMT_START{ (GTK_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
74 #define GTK_OBJECT_UNSET_FLAGS(obj,flag)  G_STMT_START{ (GTK_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
75
76 typedef struct _GtkObjectClass  GtkObjectClass;
77
78
79 /* The GtkObject structure is the base of the Gtk+ objects hierarchy,
80  * it ``inherits'' from the GtkTypeObject by mirroring its fields,
81  * which must always be kept in sync completely. The GtkObject defines
82  * the few basic items that all derived classes contain.
83  */
84 struct _GtkObject
85 {
86   GObject parent_instance;
87   
88   /* 32 bits of flags. GtkObject only uses 4 of these bits and
89    *  GtkWidget uses the rest. This is done because structs are
90    *  aligned on 4 or 8 byte boundaries. If a new bitfield were
91    *  used in GtkWidget much space would be wasted.
92    */
93   guint32 flags;
94 };
95
96 /* The GtkObjectClass is the base of the Gtk+ objects classes hierarchy,
97  * it ``inherits'' from the GtkTypeClass by mirroring its fields, which
98  * must always be kept in sync completely. The GtkObjectClass defines
99  * the basic necessities for the object inheritance mechanism to work.
100  */
101 struct _GtkObjectClass
102 {
103   GObjectClass parent_class;
104   
105   /* Non overridable class methods to set and get per class arguments */
106   void (*set_arg) (GtkObject *object,
107                    GtkArg    *arg,
108                    guint      arg_id);
109   void (*get_arg) (GtkObject *object,
110                    GtkArg    *arg,
111                    guint      arg_id);
112   
113   /* The function that will end an objects life time. In one way ore
114    *  another all three of them are defined for all objects. If an
115    *  object class overrides one of the methods in order to perform class
116    *  specific destruction then it must still invoke its superclass'
117    *  implementation of the method after it is finished with its
118    *  own cleanup. (See the destroy function for GtkWidget for
119    *  an example of how to do this).
120    */
121   void (*destroy)  (GtkObject *object);
122 };
123
124
125
126 /* Application-level methods */
127
128 GtkType gtk_object_get_type             (void) G_GNUC_CONST;
129
130 GtkObject*      gtk_object_new            (GtkType             type,
131                                            const gchar        *first_property_name,
132                                            ...);
133
134 void gtk_object_sink      (GtkObject *object);
135 void gtk_object_destroy   (GtkObject *object);
136
137 /****************************************************************/
138
139 #ifndef GTK_DISABLE_DEPRECATED 
140
141 GtkObject*      gtk_object_ref            (GtkObject          *object);
142 void            gtk_object_unref          (GtkObject          *object);
143 void gtk_object_weakref   (GtkObject        *object,
144                            GtkDestroyNotify  notify,
145                            gpointer          data);
146 void gtk_object_weakunref (GtkObject        *object,
147                            GtkDestroyNotify  notify,
148                            gpointer          data);
149
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".
161  */
162 void     gtk_object_set_data         (GtkObject      *object,
163                                       const gchar    *key,
164                                       gpointer        data);
165 void     gtk_object_set_data_full    (GtkObject      *object,
166                                       const gchar    *key,
167                                       gpointer        data,
168                                       GtkDestroyNotify destroy);
169 void     gtk_object_remove_data      (GtkObject      *object,
170                                       const gchar    *key);
171 gpointer gtk_object_get_data         (GtkObject      *object,
172                                       const gchar    *key);
173 void     gtk_object_remove_no_notify (GtkObject      *object,
174                                       const gchar    *key);
175
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.
180  */
181 void     gtk_object_set_user_data (GtkObject    *object,
182                                    gpointer      data);
183 gpointer gtk_object_get_user_data (GtkObject    *object);
184
185
186 /* Object-level methods */
187
188 /* Object data method variants that operate on key ids. */
189 void gtk_object_set_data_by_id          (GtkObject       *object,
190                                          GQuark           data_id,
191                                          gpointer         data);
192 void gtk_object_set_data_by_id_full     (GtkObject       *object,
193                                          GQuark           data_id,
194                                          gpointer         data,
195                                          GtkDestroyNotify destroy);
196 gpointer gtk_object_get_data_by_id      (GtkObject       *object,
197                                          GQuark           data_id);
198 void  gtk_object_remove_data_by_id      (GtkObject       *object,
199                                          GQuark           data_id);
200 void  gtk_object_remove_no_notify_by_id (GtkObject       *object,
201                                          GQuark           key_id);
202 #define gtk_object_data_try_key     g_quark_try_string
203 #define gtk_object_data_force_id    g_quark_from_string
204
205 /* GtkArg flag bits for gtk_object_add_arg_type
206  */
207 typedef enum
208 {
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
214 } GtkArgFlags;
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                                  ...);
219 void    gtk_object_set          (GtkObject      *object,
220                                  const gchar    *first_property_name,
221                                  ...);
222 void    gtk_object_add_arg_type         (const gchar    *arg_name,
223                                          GtkType         arg_type,
224                                          guint           arg_flags,
225                                          guint           arg_id);
226
227 #endif /* GTK_DISABLE_DEPRECATED */
228
229 G_END_DECLS
230
231 #endif /* __GTK_OBJECT_H__ */