2002-11-08 00:02:15 -08:00
|
|
|
#include "evas_common.h"
|
|
|
|
#include "evas_private.h"
|
|
|
|
|
2004-08-23 16:04:34 -07:00
|
|
|
/**
|
2008-11-01 15:21:10 -07:00
|
|
|
* @addtogroup Evas_Object_Group
|
2008-11-01 14:50:36 -07:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2003-03-04 18:30:20 -08:00
|
|
|
/**
|
2004-02-19 23:06:39 -08:00
|
|
|
* Set an attached data pointer to an object with a given string key.
|
|
|
|
* @param obj The object to attach the data pointer to
|
|
|
|
* @param key The string key for the data to access it
|
|
|
|
* @param data The ponter to the data to be attached
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* This attaches the pointer @p data to the object @p obj given the string
|
|
|
|
* @p key. This pointer will stay "hooked" to the object until a new pointer
|
|
|
|
* with the same string key is attached with evas_object_data_set() or it is
|
|
|
|
* deleted with evas_object_data_del(). On deletion of the object @p obj, the
|
|
|
|
* pointers will not be accessible from the object anymore.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
|
|
|
* You can find the pointer attached under a string key using
|
2004-02-19 23:06:39 -08:00
|
|
|
* evas_object_data_get(). It is the job of the calling application to free
|
|
|
|
* any data pointed to by @p data when it is no longer required.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* If @p data is NULL, the old value stored at @p key will be removed but no
|
2005-05-21 19:49:50 -07:00
|
|
|
* new value will be stored. This is synonymous with calling
|
2004-02-19 23:06:39 -08:00
|
|
|
* evas_object_data_del() with @p obj and @p key.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* Example:
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* @code
|
|
|
|
* int *my_data;
|
|
|
|
* extern Evas_Object *obj;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* my_data = malloc(500);
|
|
|
|
* evas_object_data_set(obj, "name_of_data", my_data);
|
|
|
|
* printf("The data that was attached was %p\n", evas_object_data_get(obj, "name_of_data"));
|
|
|
|
* @endcode
|
2003-03-04 18:30:20 -08:00
|
|
|
*/
|
2006-01-06 15:05:17 -08:00
|
|
|
EAPI void
|
2003-01-09 20:58:51 -08:00
|
|
|
evas_object_data_set(Evas_Object *obj, const char *key, const void *data)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
Evas_Data_Node *node;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
|
|
|
|
return;
|
2005-05-21 19:49:50 -07:00
|
|
|
MAGIC_CHECK_END();
|
2002-11-08 00:02:15 -08:00
|
|
|
if (!key) return;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
evas_object_data_del(obj, key);
|
2004-02-19 23:06:39 -08:00
|
|
|
if (data == NULL) return;
|
2005-11-04 11:33:08 -08:00
|
|
|
node = malloc(sizeof(Evas_Data_Node) + strlen(key) + 1);
|
|
|
|
node->key = (char *)node + sizeof(Evas_Data_Node);
|
|
|
|
strcpy(node->key, key);
|
2003-01-09 20:58:51 -08:00
|
|
|
node->data = (void *)data;
|
2008-10-21 09:31:05 -07:00
|
|
|
obj->data.elements = eina_list_prepend(obj->data.elements, node);
|
2002-11-08 00:02:15 -08:00
|
|
|
}
|
|
|
|
|
2003-03-04 18:30:20 -08:00
|
|
|
/**
|
2004-02-19 23:06:39 -08:00
|
|
|
* Return an attached data pointer by its given string key.
|
|
|
|
* @param obj The object to which the data was attached
|
|
|
|
* @param key The string key the data was stored under
|
|
|
|
* @return The data pointer stored, or NULL if none was stored
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* This function will return the data pointer attached to the object @p obj
|
|
|
|
* stored using the string key @p key. If the object is valid and data was
|
|
|
|
* stored under the given key, the pointer that was stored will be reuturned.
|
|
|
|
* If this is not the case, NULL will be returned, signifying an invalid object
|
|
|
|
* or non-existent key. It is possible a NULL pointer was stored given that
|
|
|
|
* key, but this situation is non-sensical and thus can be considered an error
|
|
|
|
* as well. NULL pointers are never stored as this is the return value if an
|
|
|
|
* error occurs.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* Example:
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* @code
|
|
|
|
* int *my_data;
|
|
|
|
* extern Evas_Object *obj;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* my_data = evas_object_data_get(obj, "name_of_my_data");
|
|
|
|
* if (my_data) printf("Data stored was %p\n", my_data);
|
|
|
|
* else printf("No data was stored on the object\n");
|
2004-08-23 16:04:34 -07:00
|
|
|
* @endcode
|
2003-03-04 18:30:20 -08:00
|
|
|
*/
|
2006-01-06 15:05:17 -08:00
|
|
|
EAPI void *
|
2008-02-08 14:35:19 -08:00
|
|
|
evas_object_data_get(const Evas_Object *obj, const char *key)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evas_Data_Node *node;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
|
|
|
|
return NULL;
|
|
|
|
MAGIC_CHECK_END();
|
|
|
|
if (!key) return NULL;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2008-10-21 09:31:05 -07:00
|
|
|
EINA_LIST_FOREACH(obj->data.elements, l, node)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
if (!strcmp(node->key, key))
|
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *lst;
|
2008-02-08 14:35:19 -08:00
|
|
|
lst = obj->data.elements;
|
2008-10-21 09:31:05 -07:00
|
|
|
lst = eina_list_promote_list(lst, l);
|
2008-02-08 14:35:19 -08:00
|
|
|
((Evas_Object *)obj)->data.elements = lst;
|
2002-11-08 00:02:15 -08:00
|
|
|
return node->data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2003-03-04 18:30:20 -08:00
|
|
|
/**
|
2004-02-19 23:06:39 -08:00
|
|
|
* Delete at attached data pointer from an object.
|
|
|
|
* @param obj The object to delete the data pointer from
|
|
|
|
* @param key The string key the data was stored under
|
|
|
|
* @return The original data pointer stored at @p key on @p obj
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* This will remove thee stored data pointer from @p obj stored under @p key,
|
|
|
|
* and return the original pointer stored under @p key, if any, nor NULL if
|
|
|
|
* nothing was stored under that key.
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* Example:
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* @code
|
|
|
|
* int *my_data;
|
|
|
|
* extern Evas_Object *obj;
|
2005-05-21 19:49:50 -07:00
|
|
|
*
|
2004-02-19 23:06:39 -08:00
|
|
|
* my_data = evas_object_data_del(obj, "name_of_my_data");
|
|
|
|
* @endcode
|
2003-03-04 18:30:20 -08:00
|
|
|
*/
|
2006-01-06 15:05:17 -08:00
|
|
|
EAPI void *
|
2002-11-08 00:02:15 -08:00
|
|
|
evas_object_data_del(Evas_Object *obj, const char *key)
|
|
|
|
{
|
2008-10-21 09:31:05 -07:00
|
|
|
Eina_List *l;
|
|
|
|
Evas_Data_Node *node;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ);
|
|
|
|
return NULL;
|
|
|
|
MAGIC_CHECK_END();
|
|
|
|
if (!key) return NULL;
|
2008-10-21 09:31:05 -07:00
|
|
|
EINA_LIST_FOREACH(obj->data.elements, l, node)
|
2002-11-08 00:02:15 -08:00
|
|
|
{
|
|
|
|
if (!strcmp(node->key, key))
|
|
|
|
{
|
|
|
|
void *data;
|
2005-05-21 19:49:50 -07:00
|
|
|
|
2002-11-08 00:02:15 -08:00
|
|
|
data = node->data;
|
2008-10-21 09:31:05 -07:00
|
|
|
obj->data.elements = eina_list_remove_list(obj->data.elements, l);
|
2002-11-08 00:02:15 -08:00
|
|
|
free(node);
|
|
|
|
return data;
|
|
|
|
}
|
2005-05-21 19:49:50 -07:00
|
|
|
}
|
2002-11-08 00:02:15 -08:00
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-01 14:50:36 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|