]> Pileus Git - ~andy/gtk/blob - gtk/gtkobject.h
Seal priv pointer in GtkPrinter.
[~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 #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
28 #error "Only <gtk/gtk.h> can be included directly."
29 #endif
30
31 #ifndef __GTK_OBJECT_H__
32 #define __GTK_OBJECT_H__
33
34
35 #include <gtk/gtkenums.h>
36 #include <gtk/gtktypeutils.h>
37 #include <gtk/gtkdebug.h>
38
39 G_BEGIN_DECLS
40
41 /* macros for casting a pointer to a GtkObject or GtkObjectClass pointer,
42  * and to test whether `object' and `klass' are of type GTK_TYPE_OBJECT.
43  * these are the standard macros for all GtkObject-derived classes.
44  */
45 #define GTK_TYPE_OBJECT              (gtk_object_get_type ())
46 #define GTK_OBJECT(object)           (G_TYPE_CHECK_INSTANCE_CAST ((object), GTK_TYPE_OBJECT, GtkObject))
47 #define GTK_OBJECT_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_OBJECT, GtkObjectClass))
48 #define GTK_IS_OBJECT(object)        (G_TYPE_CHECK_INSTANCE_TYPE ((object), GTK_TYPE_OBJECT))
49 #define GTK_IS_OBJECT_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_OBJECT))
50 #define GTK_OBJECT_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), GTK_TYPE_OBJECT, GtkObjectClass))
51
52 /* Macros for extracting various fields from GtkObject and GtkObjectClass.
53  */
54 #define GTK_OBJECT_TYPE(object)           (G_TYPE_FROM_INSTANCE (object))
55 #define GTK_OBJECT_TYPE_NAME(object)      (g_type_name (GTK_OBJECT_TYPE (object)))
56
57 /* GtkObject only uses the first 4 bits of the flags field.
58  * Derived objects may use the remaining bits. Though this
59  * is a kinda nasty break up, it does make the size of
60  * derived objects smaller.
61  */
62 typedef enum
63 {
64   GTK_IN_DESTRUCTION    = 1 << 0, /* Used internally during dispose */
65 #if !defined (GTK_DISABLE_DEPRECATED) || defined (GTK_COMPILATION)
66   GTK_FLOATING          = 1 << 1,
67 #endif
68   GTK_RESERVED_1        = 1 << 2,
69   GTK_RESERVED_2        = 1 << 3
70 } GtkObjectFlags;
71
72 /* Macros for extracting the object_flags from GtkObject.
73  */
74 #define GTK_OBJECT_FLAGS(obj)             (GTK_OBJECT (obj)->flags)
75 #ifndef GTK_DISABLE_DEPRECATED
76 #define GTK_OBJECT_FLOATING(obj)          (g_object_is_floating (obj))
77 #endif
78
79 /* Macros for setting and clearing bits in the object_flags field of GtkObject.
80  */
81 #define GTK_OBJECT_SET_FLAGS(obj,flag)    G_STMT_START{ (GTK_OBJECT_FLAGS (obj) |= (flag)); }G_STMT_END
82 #define GTK_OBJECT_UNSET_FLAGS(obj,flag)  G_STMT_START{ (GTK_OBJECT_FLAGS (obj) &= ~(flag)); }G_STMT_END
83
84 typedef struct _GtkObjectClass  GtkObjectClass;
85
86
87 struct _GtkObject
88 {
89   GInitiallyUnowned parent_instance;
90
91   /* 32 bits of flags. GtkObject only uses 4 of these bits and
92    *  GtkWidget uses the rest. This is done because structs are
93    *  aligned on 4 or 8 byte boundaries. If a new bitfield were
94    *  used in GtkWidget much space would be wasted.
95    */
96   guint32 flags;
97 };
98
99 struct _GtkObjectClass
100 {
101   GInitiallyUnownedClass parent_class;
102
103   /* Non overridable class methods to set and get per class arguments */
104   void (*set_arg) (GtkObject *object,
105                    GtkArg    *arg,
106                    guint      arg_id);
107   void (*get_arg) (GtkObject *object,
108                    GtkArg    *arg,
109                    guint      arg_id);
110
111   /* Default signal handler for the ::destroy signal, which is
112    *  invoked to request that references to the widget be dropped.
113    *  If an object class overrides destroy() in order to perform class
114    *  specific destruction then it must still invoke its superclass'
115    *  implementation of the method after it is finished with its
116    *  own cleanup. (See gtk_widget_real_destroy() for an example of
117    *  how to do this).
118    */
119   void (*destroy)  (GtkObject *object);
120 };
121
122
123
124 /* Application-level methods */
125
126 GType gtk_object_get_type (void) G_GNUC_CONST;
127
128 #ifndef GTK_DISABLE_DEPRECATED
129 void gtk_object_sink      (GtkObject *object);
130 #endif
131 void gtk_object_destroy   (GtkObject *object);
132
133 /****************************************************************/
134
135 #ifndef GTK_DISABLE_DEPRECATED
136
137 GtkObject*      gtk_object_new            (GtkType             type,
138                                            const gchar        *first_property_name,
139                                            ...);
140 GtkObject*      gtk_object_ref            (GtkObject          *object);
141 void            gtk_object_unref          (GtkObject          *object);
142 void gtk_object_weakref   (GtkObject        *object,
143                            GtkDestroyNotify  notify,
144                            gpointer          data);
145 void gtk_object_weakunref (GtkObject        *object,
146                            GtkDestroyNotify  notify,
147                            gpointer          data);
148
149 /* Set 'data' to the "object_data" field of the object. The
150  *  data is indexed by the "key". If there is already data
151  *  associated with "key" then the new data will replace it.
152  *  If 'data' is NULL then this call is equivalent to
153  *  'gtk_object_remove_data'.
154  *  The gtk_object_set_data_full variant acts just the same,
155  *  but takes an additional argument which is a function to
156  *  be called when the data is removed.
157  *  `gtk_object_remove_data' is equivalent to the above,
158  *  where 'data' is NULL
159  *  `gtk_object_get_data' gets the data associated with "key".
160  */
161 void     gtk_object_set_data         (GtkObject      *object,
162                                       const gchar    *key,
163                                       gpointer        data);
164 void     gtk_object_set_data_full    (GtkObject      *object,
165                                       const gchar    *key,
166                                       gpointer        data,
167                                       GtkDestroyNotify destroy);
168 void     gtk_object_remove_data      (GtkObject      *object,
169                                       const gchar    *key);
170 gpointer gtk_object_get_data         (GtkObject      *object,
171                                       const gchar    *key);
172 void     gtk_object_remove_no_notify (GtkObject      *object,
173                                       const gchar    *key);
174
175 /* Set/get the "user_data" object data field of "object". It should
176  *  be noted that these functions are no different than calling
177  *  `gtk_object_set_data'/`gtk_object_get_data' with a key of "user_data".
178  *  They are merely provided as a convenience.
179  */
180 void     gtk_object_set_user_data (GtkObject    *object,
181                                    gpointer      data);
182 gpointer gtk_object_get_user_data (GtkObject    *object);
183
184
185 /* Object-level methods */
186
187 /* Object data method variants that operate on key ids. */
188 void gtk_object_set_data_by_id          (GtkObject       *object,
189                                          GQuark           data_id,
190                                          gpointer         data);
191 void gtk_object_set_data_by_id_full     (GtkObject       *object,
192                                          GQuark           data_id,
193                                          gpointer         data,
194                                          GtkDestroyNotify destroy);
195 gpointer gtk_object_get_data_by_id      (GtkObject       *object,
196                                          GQuark           data_id);
197 void  gtk_object_remove_data_by_id      (GtkObject       *object,
198                                          GQuark           data_id);
199 void  gtk_object_remove_no_notify_by_id (GtkObject       *object,
200                                          GQuark           key_id);
201 #define gtk_object_data_try_key     g_quark_try_string
202 #define gtk_object_data_force_id    g_quark_from_string
203
204 /* GtkArg flag bits for gtk_object_add_arg_type
205  */
206 typedef enum
207 {
208   GTK_ARG_READABLE       = G_PARAM_READABLE,
209   GTK_ARG_WRITABLE       = G_PARAM_WRITABLE,
210   GTK_ARG_CONSTRUCT      = G_PARAM_CONSTRUCT,
211   GTK_ARG_CONSTRUCT_ONLY = G_PARAM_CONSTRUCT_ONLY,
212   GTK_ARG_CHILD_ARG      = 1 << 4
213 } GtkArgFlags;
214 #define GTK_ARG_READWRITE       (GTK_ARG_READABLE | GTK_ARG_WRITABLE)
215 void    gtk_object_get          (GtkObject      *object,
216                                  const gchar    *first_property_name,
217                                  ...) G_GNUC_NULL_TERMINATED;
218 void    gtk_object_set          (GtkObject      *object,
219                                  const gchar    *first_property_name,
220                                  ...) G_GNUC_NULL_TERMINATED;
221 void    gtk_object_add_arg_type         (const gchar    *arg_name,
222                                          GtkType         arg_type,
223                                          guint           arg_flags,
224                                          guint           arg_id);
225
226 #endif /* GTK_DISABLE_DEPRECATED */
227
228 G_END_DECLS
229
230 #endif /* __GTK_OBJECT_H__ */