added gtk_object_set_data_destroy and gtk_object_set_data_destroy_by_id

Thu Sep 17 05:12:48 1998  Tim Janik  <timj@gtk.org>

        * gtk/gtkobject.h: added gtk_object_set_data_destroy and
        gtk_object_set_data_destroy_by_id functions to set the destroy
        function pointer for an existing data portion.

        * gtk/gtkobject.c: removed the GtkObjectData implementation and
        made all gtk_object_*data* functions use the GLib equivalents.
This commit is contained in:
Tim Janik 1998-09-17 05:00:30 +00:00 committed by Tim Janik
parent 0b54ffa9d6
commit ee1b96185f
9 changed files with 142 additions and 168 deletions

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -1,3 +1,12 @@
Thu Sep 17 05:12:48 1998 Tim Janik <timj@gtk.org>
* gtk/gtkobject.h: added gtk_object_set_data_destroy and
gtk_object_set_data_destroy_by_id functions to set the destroy
function pointer for an existing data portion.
* gtk/gtkobject.c: removed the GtkObjectData implementation and
made all gtk_object_*data* functions use the GLib equivalents.
1998-09-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gtk/gtktoolbar.c (gtk_toolbar_insert_element): Test whether type

View File

@ -23,9 +23,6 @@
#include "gtksignal.h"
#define GTK_OBJECT_DATA_ID_BLOCK_SIZE (1024)
#define GTK_OBJECT_DATA_BLOCK_SIZE (1024)
enum {
DESTROY,
LAST_SIGNAL
@ -40,17 +37,6 @@ enum {
};
typedef struct _GtkObjectData GtkObjectData;
struct _GtkObjectData
{
guint id;
gpointer data;
GtkDestroyNotify destroy;
GtkObjectData *next;
};
void gtk_object_init_type (void);
static void gtk_object_base_class_init (GtkObjectClass *klass);
static void gtk_object_class_init (GtkObjectClass *klass);
@ -75,15 +61,6 @@ static guint user_data_key_id = 0;
static const gchar *weakrefs_key = "gtk-weakrefs";
static guint weakrefs_key_id = 0;
static GtkObjectData *gtk_object_data_free_list = NULL;
#define GTK_OBJECT_DATA_DESTROY( odata ) { \
if (odata->destroy) \
odata->destroy (odata->data); \
odata->next = gtk_object_data_free_list; \
gtk_object_data_free_list = odata; \
}
#ifdef G_ENABLE_DEBUG
static guint obj_count = 0;
@ -207,7 +184,7 @@ gtk_object_init (GtkObject *object)
GTK_OBJECT_FLAGS (object) = GTK_FLOATING;
object->ref_count = 1;
object->object_data = NULL;
g_datalist_init (&object->object_data);
#ifdef G_ENABLE_DEBUG
if (gtk_debug_flags & GTK_DEBUG_OBJECTS)
@ -263,14 +240,7 @@ gtk_object_finalize (GtkObject *object)
{
gtk_object_notify_weaks (object);
while (object->object_data)
{
GtkObjectData *odata;
odata = object->object_data;
object->object_data = odata->next;
GTK_OBJECT_DATA_DESTROY (odata);
}
g_datalist_clear (&object->object_data);
gtk_type_free (GTK_OBJECT_TYPE (object), object);
}
@ -926,9 +896,10 @@ gtk_object_set_data_by_id (GtkObject *object,
GQuark data_id,
gpointer data)
{
g_return_if_fail (data_id > 0);
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
gtk_object_set_data_by_id_full (object, data_id, data, NULL);
g_datalist_id_set_data (&object->object_data, data_id, data);
}
void
@ -936,9 +907,11 @@ gtk_object_set_data (GtkObject *object,
const gchar *key,
gpointer data)
{
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (key != NULL);
gtk_object_set_data_by_id_full (object, gtk_object_data_force_id (key), data, NULL);
g_datalist_set_data (&object->object_data, key, data);
}
void
@ -947,89 +920,10 @@ gtk_object_set_data_by_id_full (GtkObject *object,
gpointer data,
GtkDestroyNotify destroy)
{
GtkObjectData *odata;
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (data_id > 0);
odata = object->object_data;
if (!data)
{
GtkObjectData *prev;
prev = NULL;
while (odata)
{
if (odata->id == data_id)
{
if (prev)
prev->next = odata->next;
else
object->object_data = odata->next;
GTK_OBJECT_DATA_DESTROY (odata);
return;
}
prev = odata;
odata = odata->next;
}
}
else
{
while (odata)
{
if (odata->id == data_id)
{
register GtkDestroyNotify dfunc;
register gpointer ddata;
dfunc = odata->destroy;
ddata = odata->data;
odata->destroy = destroy;
odata->data = data;
/* we need to have updated all structures prior to
* invokation of the destroy function
*/
if (dfunc)
dfunc (ddata);
return;
}
odata = odata->next;
}
if (gtk_object_data_free_list)
{
odata = gtk_object_data_free_list;
gtk_object_data_free_list = odata->next;
}
else
{
GtkObjectData *odata_block;
guint i;
odata_block = g_new0 (GtkObjectData, GTK_OBJECT_DATA_BLOCK_SIZE);
for (i = 1; i < GTK_OBJECT_DATA_BLOCK_SIZE; i++)
{
(odata_block + i)->next = gtk_object_data_free_list;
gtk_object_data_free_list = (odata_block + i);
}
odata = odata_block;
}
odata->id = data_id;
odata->data = data;
odata->destroy = destroy;
odata->next = object->object_data;
object->object_data = odata;
}
g_datalist_id_set_data_full (&object->object_data, data_id, data, destroy);
}
void
@ -1038,87 +932,98 @@ gtk_object_set_data_full (GtkObject *object,
gpointer data,
GtkDestroyNotify destroy)
{
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (key != NULL);
gtk_object_set_data_by_id_full (object, gtk_object_data_force_id (key), data, destroy);
g_datalist_set_data_full (&object->object_data, key, data, destroy);
}
gpointer
gtk_object_get_data_by_id (GtkObject *object,
GQuark data_id)
{
GtkObjectData *odata;
g_return_val_if_fail (object != NULL, NULL);
g_return_val_if_fail (GTK_IS_OBJECT (object), NULL);
if (data_id)
{
odata = object->object_data;
while (odata)
{
if (odata->id == data_id)
return odata->data;
odata = odata->next;
}
}
return NULL;
return g_datalist_id_get_data (&object->object_data, data_id);
}
gpointer
gtk_object_get_data (GtkObject *object,
const gchar *key)
{
guint id;
g_return_val_if_fail (object != NULL, NULL);
g_return_val_if_fail (GTK_IS_OBJECT (object), NULL);
g_return_val_if_fail (key != NULL, NULL);
id = gtk_object_data_try_key (key);
if (id)
return gtk_object_get_data_by_id (object, id);
return NULL;
return g_datalist_get_data (&object->object_data, key);
}
void
gtk_object_remove_data_by_id (GtkObject *object,
GQuark data_id)
{
if (data_id)
gtk_object_set_data_by_id_full (object, data_id, NULL, NULL);
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_datalist_id_remove_data (&object->object_data, data_id);
}
void
gtk_object_remove_data (GtkObject *object,
const gchar *key)
{
gint id;
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (key != NULL);
id = gtk_object_data_try_key (key);
if (id)
gtk_object_set_data_by_id_full (object, id, NULL, NULL);
g_datalist_remove_data (&object->object_data, key);
}
void
gtk_object_set_data_destroy_by_id (GtkObject *object,
GQuark key_id,
GDestroyNotify destroy_func)
{
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_datalist_id_set_destroy (&object->object_data, key_id, destroy_func);
}
void
gtk_object_set_data_destroy (GtkObject *object,
const gchar *key,
GDestroyNotify destroy_func)
{
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
g_return_if_fail (key != NULL);
g_datalist_set_destroy (&object->object_data, key, destroy_func);
}
void
gtk_object_set_user_data (GtkObject *object,
gpointer data)
{
g_return_if_fail (object != NULL);
g_return_if_fail (GTK_IS_OBJECT (object));
if (!user_data_key_id)
user_data_key_id = g_quark_from_static_string (user_data_key);
gtk_object_set_data_by_id_full (object, user_data_key_id, data, NULL);
g_datalist_id_set_data (&object->object_data, user_data_key_id, data);
}
gpointer
gtk_object_get_user_data (GtkObject *object)
{
if (user_data_key_id)
return gtk_object_get_data_by_id (object, user_data_key_id);
g_return_val_if_fail (object != NULL, NULL);
g_return_val_if_fail (GTK_IS_OBJECT (object), NULL);
return NULL;
return g_datalist_id_get_data (&object->object_data, user_data_key_id);
}
/*******************************************

View File

@ -118,8 +118,8 @@ struct _GtkObject
{
/* GtkTypeObject related fields: */
GtkObjectClass *klass;
/* 32 bits of flags. GtkObject only uses 4 of these bits and
* GtkWidget uses the rest. This is done because structs are
* aligned on 4 or 8 byte boundaries. If a new bitfield were
@ -150,7 +150,7 @@ struct _GtkObjectClass
/* GtkTypeClass fields: */
GtkType type;
/* The signals this object class handles. "signals" is an
* array of signal ID's.
*/
@ -239,7 +239,7 @@ void gtk_object_getv (GtkObject *object,
* more than one c-function argument.
*/
void gtk_object_set (GtkObject *object,
const gchar *first_arg_name,
const gchar *first_arg_name,
...);
void gtk_object_setv (GtkObject *object,
guint n_args,
@ -280,6 +280,9 @@ void gtk_object_remove_data (GtkObject *object,
const gchar *key);
gpointer gtk_object_get_data (GtkObject *object,
const gchar *key);
void gtk_object_set_data_destroy(GtkObject *object,
const gchar *key,
GDestroyNotify destroy_func);
/* Set/get the "user_data" object data field of "object". It should
* be noted that these functions are no different than calling
@ -298,23 +301,26 @@ void gtk_object_class_add_signals (GtkObjectClass *klass,
guint *signals,
guint nsignals);
/* the `arg_name' argument needs to be a const static string */
void gtk_object_add_arg_type (const gchar *arg_name,
GtkType arg_type,
guint arg_flags,
guint arg_id);
void gtk_object_add_arg_type (const gchar *arg_name,
GtkType arg_type,
guint arg_flags,
guint arg_id);
/* Object data method variants that operate on key ids. */
void gtk_object_set_data_by_id (GtkObject *object,
GQuark data_id,
gpointer data);
void gtk_object_set_data_by_id_full (GtkObject *object,
GQuark data_id,
gpointer data,
GtkDestroyNotify destroy);
gpointer gtk_object_get_data_by_id (GtkObject *object,
GQuark data_id);
void gtk_object_remove_data_by_id (GtkObject *object,
GQuark data_id);
void gtk_object_set_data_by_id (GtkObject *object,
GQuark data_id,
gpointer data);
void gtk_object_set_data_by_id_full (GtkObject *object,
GQuark data_id,
gpointer data,
GtkDestroyNotify destroy);
gpointer gtk_object_get_data_by_id (GtkObject *object,
GQuark data_id);
void gtk_object_remove_data_by_id (GtkObject *object,
GQuark data_id);
void gtk_object_set_data_destroy_by_id (GtkObject *object,
GQuark key_id,
GDestroyNotify destroy_func);
#define gtk_object_data_try_key g_quark_try_string
#define gtk_object_data_force_id g_quark_from_string
@ -332,7 +338,7 @@ gchar* gtk_object_args_collect (GtkType object_type,
GSList **info_list_p,
const gchar *first_arg_name,
va_list var_args);
gchar* gtk_object_arg_get_info (GtkType object_type,
gchar* gtk_object_arg_get_info (GtkType object_type,
const gchar *arg_name,
GtkArgInfo **info_p);
void gtk_trace_referencing (GtkObject *object,