* Add top level data editing functions

* Also change edje_cache.c to don\'t free the data list when creating the data_cache 

SVN revision: 35987
This commit is contained in:
Davide Andreoli 2008-09-14 22:30:15 +00:00
parent 161ab7a975
commit bae73a2b60
3 changed files with 172 additions and 3 deletions

View File

@ -216,6 +216,53 @@ edje_edit_group_max_h_set(
int h ///< The new group maximum height in pixel
);
//@}
/******************************************************************************/
/************************** DATA API **************************************/
/******************************************************************************/
/** @name Data API
* Functions to deal with data embedded in the edje (see @ref edcref).
*/ //@{
/** Retrieves a list with the item names inside the data block **/
EAPI Evas_List * ///@return An Evas_List* of string (char *)containing all the data names.
edje_edit_data_list_get(
Evas_Object *obj ///< The edje object
);
/**Create a new data object in the given edje
* If another data with the same name exists nothing is created and FALSE is returned.
*/
EAPI unsigned char ///@return TRUE on success
edje_edit_data_add(
Evas_Object *obj, ///< The edje object
const char *itemname, ///< The name for the new data
const char *value ///< The value for the new data
);
/**Delete the given data object from edje */
EAPI unsigned char ///@return TRUE on success
edje_edit_data_del(
Evas_Object *obj, ///< The edje object
const char *itemname ///< The name of the data to remove
);
/** Get the data associated with the given itemname **/
EAPI const char * ///@return The data value
edje_edit_data_value_get(
Evas_Object * obj, ///< The edje object
char *itemname ///< The name of the data item
);
/** Set the data associated with the given itemname **/
EAPI unsigned char ///@return TRUE on success
edje_edit_data_value_set(
Evas_Object * obj, ///< The edje object
const char *itemname, ///< The name of the data item
const char *value ///< The new value to set
);
//@}
/******************************************************************************/
/************************** PARTS API *************************************/

View File

@ -133,13 +133,11 @@ _edje_file_open(const char *file, const char *coll, int *error_ret, Edje_Part_Co
_edje_textblock_style_parse_and_fix(edf);
for (l = edf->data; l; l = evas_list_remove(l, l->data))
for (l = edf->data; l; l = l->next)
{
Edje_Data *di = l->data;
edf->data_cache = evas_hash_add(edf->data_cache, evas_stringshare_add(di->key), di->value);
free(di);
}
edf->data = NULL;
if (coll)
{

View File

@ -895,6 +895,130 @@ edje_edit_group_max_h_set(Evas_Object *obj, int h)
ed->collection->prop.max.h = h;
}
/***************/
/* DATA API */
/***************/
EAPI Evas_List *
edje_edit_data_list_get(Evas_Object * obj)
{
Evas_List *datas, *l;
GET_ED_OR_RETURN(NULL);
if (!ed->file || !ed->file->data)
return NULL;
datas = NULL;
for (l = ed->file->data; l; l = l->next)
{
Edje_Data *d = l->data;
datas = evas_list_append(datas, evas_stringshare_add(d->key));
}
return datas;
}
EAPI unsigned char
edje_edit_data_add(Evas_Object *obj, const char *itemname, const char *value)
{
Evas_List *l;
Edje_Data *d;
GET_ED_OR_RETURN(0);
if (!itemname || !ed->file)
return 0;
for (l = ed->file->data; l; l = l->next)
{
Edje_Data *dd = l->data;
if (strcmp(dd->key, itemname) == 0)
return 0;
}
d = mem_alloc(sizeof(Edje_Data));
if (!d) return 0;
d->key = (char*)evas_stringshare_add(itemname);
if (value) d->value = (char*)evas_stringshare_add(value);
else d->value = NULL;
ed->file->data = evas_list_append(ed->file->data, d);
return 1;
}
EAPI unsigned char
edje_edit_data_del(Evas_Object *obj, const char *itemname)
{
Evas_List *l;
GET_ED_OR_RETURN(0);
if (!itemname || !ed->file || !ed->file->data)
return 0;
for (l = ed->file->data; l; l = l->next)
{
Edje_Data *d = l->data;
if (strcmp(d->key, itemname) == 0)
{
_edje_if_string_free(ed, d->key);
_edje_if_string_free(ed, d->value);
ed->file->data = evas_list_remove(ed->file->data, d);
free(d);
return 1;
}
}
return 0;
}
EAPI const char *
edje_edit_data_value_get(Evas_Object * obj, char *itemname)
{
Evas_List *l;
GET_ED_OR_RETURN(NULL);
if (!itemname || !ed->file || !ed->file->data)
return NULL;
for (l = ed->file->data; l; l = l->next)
{
Edje_Data *d = l->data;
if (strcmp(d->key, itemname) == 0)
return evas_stringshare_add(d->value);
}
return NULL;
}
EAPI unsigned char
edje_edit_data_value_set( Evas_Object * obj, const char *itemname, const char *value)
{
Evas_List *l;
GET_ED_OR_RETURN(0);
if (!itemname || !value || !ed->file || !ed->file->data)
return 0;
for (l = ed->file->data; l; l = l->next)
{
Edje_Data *d = l->data;
if (strcmp(d->key, itemname) == 0)
{
_edje_if_string_free(ed, d->value);
d->value = (char*)evas_stringshare_add(value);
return 1;
}
}
return 0;
}
/***************/
/* PARTS API */
/***************/