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