summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorAndrii Kroitor <an.kroitor@samsung.com>2013-12-19 15:47:25 +0900
committerCedric BAIL <cedric.bail@samsung.com>2013-12-19 15:53:38 +0900
commit287d63c016fbc8ef18a685cced62561dbb5d26fa (patch)
tree90af15ed1104214bdc18e262cfb6bc0a6ac6ff85 /src/lib
parentbf3f0f2f4a61fc1a0ffd04c16053caeebd9dc30d (diff)
edje: edje_edit - image api modification
Changed edje_edit_image_del logic: image can't be deleted if it's in use, after deletion last image in list is moved to freed position so there are no "holes" in image list. Following functions added to api: edje_edit_image_replace edje_edit_image_usage_list_get edje_edit_image_usage_list_free Reviewers: cedric, seoz, raster Reviewed By: cedric CC: reutskiy.v.v, cedric Differential Revision: https://phab.enlightenment.org/D392 Signed-off-by: Cedric BAIL <cedric.bail@samsung.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/edje/Edje_Edit.h44
-rw-r--r--src/lib/edje/edje_edit.c229
2 files changed, 255 insertions, 18 deletions
diff --git a/src/lib/edje/Edje_Edit.h b/src/lib/edje/Edje_Edit.h
index a264260a35..d5c3d43f2e 100644
--- a/src/lib/edje/Edje_Edit.h
+++ b/src/lib/edje/Edje_Edit.h
@@ -50,6 +50,17 @@ struct _Edje_Edit_Script_Error
50}; 50};
51typedef struct _Edje_Edit_Script_Error Edje_Edit_Script_Error; 51typedef struct _Edje_Edit_Script_Error Edje_Edit_Script_Error;
52 52
53struct _Edje_Part_Image_Use
54{
55 const char *group;
56 const char *part;
57 struct {
58 const char *name;
59 double value;
60 } state;
61};
62typedef struct _Edje_Part_Image_Use Edje_Part_Image_Use;
63
53/** 64/**
54 * @file 65 * @file
55 * @brief Functions to deal with edje internal object. Don't use in standard 66 * @brief Functions to deal with edje internal object. Don't use in standard
@@ -2830,15 +2841,46 @@ EAPI Eina_Bool edje_edit_image_add(Evas_Object *obj, const char *path);
2830/** Delete an image from the image collection 2841/** Delete an image from the image collection
2831 * 2842 *
2832 * It actually write directly to the file so you don't have to save. 2843 * It actually write directly to the file so you don't have to save.
2844 * Can't delete image if it is used by any part.
2833 * 2845 *
2834 * @param obj Object being edited. 2846 * @param obj Object being edited.
2835 * @param name The name of the image file to include in the edje. 2847 * @param name The name of the image file to include in the edje.
2836 * 2848 *
2837 * @return EINA_TRUE if successful, EINA_FALSE otherwise (including the 2849 * @return EINA_TRUE if successful, EINA_FALSE otherwise (including the
2838 * case when the name is not valid). 2850 * case when the name is not valid or image is in use).
2839 */ 2851 */
2840EAPI Eina_Bool edje_edit_image_del(Evas_Object *obj, const char *name); 2852EAPI Eina_Bool edje_edit_image_del(Evas_Object *obj, const char *name);
2841 2853
2854/** Replace one image in all descriptions
2855 *
2856 * @param obj Object being edited.
2857 * @param name The name of the image to replace.
2858 * @param name The new_name of the image to replace with.
2859 *
2860 * @return EINA_TRUE if successful, EINA_FALSE otherwise (including the
2861 * case when one of the names is not valid)
2862 */
2863EAPI Eina_Bool edje_edit_image_replace(Evas_Object *obj, const char *name, const char *new_name);
2864
2865/** Get list of (Edje_Part_Image_Use *) - group-part-state triplets where given
2866 * image is used
2867 *
2868 * Use edje_edit_image_usage_list_free() when you don't need it anymore.
2869 *
2870 * @param obj Object being edited.
2871 * @param name The name of the image.
2872 * @param first_only If EINA_TRUE, return only one triplete.
2873 *
2874 * @return Eina_List containing Edje_Part_Image_Use if successful, NULL otherwise
2875 */
2876EAPI Eina_List* edje_edit_image_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only);
2877
2878/** Free an Eina_List of (Edje_Part_Image_Use *) allocated by an edje_edit_image_usage_list_get() function.
2879 *
2880 * @param lst List of strings to free.
2881 */
2882EAPI void edje_edit_image_usage_list_free(Eina_List *lst);
2883
2842/** Add an image entry to the image collection 2884/** Add an image entry to the image collection
2843 * 2885 *
2844 * This function adds the given image entry to the edje image collection. The 2886 * This function adds the given image entry to the edje image collection. The
diff --git a/src/lib/edje/edje_edit.c b/src/lib/edje/edje_edit.c
index f38cf44b1a..214381fa1a 100644
--- a/src/lib/edje/edje_edit.c
+++ b/src/lib/edje/edje_edit.c
@@ -4812,10 +4812,148 @@ edje_edit_image_add(Evas_Object *obj, const char* path)
4812} 4812}
4813 4813
4814EAPI Eina_Bool 4814EAPI Eina_Bool
4815edje_edit_image_replace(Evas_Object *obj, const char *name, const char *new_name)
4816{
4817 Eina_Iterator *it;
4818 Edje_Part_Collection_Directory_Entry *pce;
4819 Edje_Part *part;
4820 Edje_Part_Description_Image *part_desc_image;
4821 unsigned int i, j, k;
4822 int image_id, new_image_id;
4823
4824 GET_ED_OR_RETURN(EINA_FALSE);
4825
4826 image_id = edje_edit_image_id_get(obj, name);
4827 new_image_id = edje_edit_image_id_get(obj, new_name);
4828 if ((image_id < 0) || (new_image_id < 0))
4829 return EINA_FALSE;
4830
4831 it = eina_hash_iterator_data_new(ed->file->collection);
4832
4833 EINA_ITERATOR_FOREACH(it, pce)
4834 {
4835 for (i = 0; i < pce->ref->parts_count; i++)
4836 {
4837 part = pce->ref->parts[i];
4838 if (part->type == EDJE_PART_TYPE_IMAGE)
4839 {
4840 part_desc_image = (Edje_Part_Description_Image *)part->default_desc;
4841 if (part_desc_image->image.id == image_id)
4842 part_desc_image->image.id = new_image_id;
4843 for (k = 0; k < part_desc_image->image.tweens_count; k++)
4844 if (part_desc_image->image.tweens[k]->id == image_id)
4845 part_desc_image->image.id = new_image_id;
4846 for (j = 0; j < part->other.desc_count; j++)
4847 {
4848 part_desc_image = (Edje_Part_Description_Image *)part->other.desc[j];
4849 if (part_desc_image->image.id == image_id)
4850 part_desc_image->image.id = new_image_id;
4851 for (k = 0; k < part_desc_image->image.tweens_count; k++)
4852 if (part_desc_image->image.tweens[k]->id == image_id)
4853 part_desc_image->image.id = new_image_id;
4854 }
4855 }
4856 }
4857 }
4858 eina_iterator_free(it);
4859
4860 return EINA_TRUE;
4861}
4862
4863EAPI Eina_List*
4864edje_edit_image_usage_list_get(Evas_Object *obj, const char *name, Eina_Bool first_only)
4865{
4866 Eina_List *result = NULL;
4867 Eina_Iterator *it;
4868 Edje_Part_Collection_Directory_Entry *pce;
4869 Edje_Part_Image_Use *item;
4870 Edje_Part *part;
4871 Edje_Part_Description_Image *part_desc_image;
4872 unsigned int i, j, k;
4873 int image_id;
4874
4875 GET_ED_OR_RETURN(NULL);
4876
4877 image_id = edje_edit_image_id_get(obj, name);
4878 if (image_id < 0)
4879 return NULL;
4880
4881 it = eina_hash_iterator_data_new(ed->file->collection);
4882
4883 #define ITEM_ADD() \
4884 item = (Edje_Part_Image_Use *) calloc(1, sizeof(Edje_Part_Image_Use)); \
4885 item->group = eina_stringshare_add(pce->entry); \
4886 item->part = eina_stringshare_add(part->name); \
4887 item->state.name = eina_stringshare_add(part_desc_image->common.state.name); \
4888 item->state.value = part_desc_image->common.state.value; \
4889 result = eina_list_append(result, item);
4890
4891 #define FIND_IN_PART_DESCRIPTION() \
4892 if (part_desc_image->image.id == image_id) \
4893 { \
4894 ITEM_ADD(); \
4895 if (first_only) \
4896 return result; \
4897 else \
4898 continue; \
4899 } \
4900 for (k = 0; k < part_desc_image->image.tweens_count; k++) \
4901 { \
4902 if (part_desc_image->image.tweens[k]->id == image_id) \
4903 { \
4904 ITEM_ADD(); \
4905 if (first_only) \
4906 return result; \
4907 else \
4908 continue; \
4909 } \
4910 }
4911
4912 EINA_ITERATOR_FOREACH(it, pce)
4913 {
4914 for (i = 0; i < pce->ref->parts_count; i++)
4915 {
4916 part = pce->ref->parts[i];
4917 if (part->type == EDJE_PART_TYPE_IMAGE)
4918 {
4919 part_desc_image = (Edje_Part_Description_Image *)part->default_desc;
4920 FIND_IN_PART_DESCRIPTION();
4921 for (j = 0; j < part->other.desc_count; j++)
4922 {
4923 part_desc_image = (Edje_Part_Description_Image *)part->other.desc[j];
4924 FIND_IN_PART_DESCRIPTION();
4925 }
4926 }
4927 }
4928 }
4929 #undef ITEM_ADD
4930 #undef FIND_IN_PART_DESCRIPTION
4931 eina_iterator_free(it);
4932
4933 return result;
4934}
4935
4936EAPI void
4937edje_edit_image_usage_list_free(Eina_List *list)
4938{
4939 Edje_Part_Image_Use *item;
4940 EINA_LIST_FREE(list, item)
4941 {
4942 eina_stringshare_del(item->group);
4943 eina_stringshare_del(item->part);
4944 eina_stringshare_del(item->state.name);
4945 free(item);
4946 }
4947}
4948
4949EAPI Eina_Bool
4815edje_edit_image_del(Evas_Object *obj, const char* name) 4950edje_edit_image_del(Evas_Object *obj, const char* name)
4816{ 4951{
4817 Edje_Image_Directory_Entry *de; 4952 Edje_Image_Directory_Entry *de, *de_last;
4818 unsigned int i; 4953 unsigned int i, j, k;
4954 Eina_List *used;
4955 Eina_Iterator *it;
4956 Edje_Part_Collection_Directory_Entry *pce;
4819 4957
4820 GET_EED_OR_RETURN(EINA_FALSE); 4958 GET_EED_OR_RETURN(EINA_FALSE);
4821 GET_ED_OR_RETURN(EINA_FALSE); 4959 GET_ED_OR_RETURN(EINA_FALSE);
@@ -4824,33 +4962,45 @@ edje_edit_image_del(Evas_Object *obj, const char* name)
4824 if (!ed->file) return EINA_FALSE; 4962 if (!ed->file) return EINA_FALSE;
4825 if (!ed->path) return EINA_FALSE; 4963 if (!ed->path) return EINA_FALSE;
4826 4964
4965 used = edje_edit_image_usage_list_get(obj, name, EINA_TRUE);
4966 if (used)
4967 {
4968 edje_edit_image_usage_list_free(used);
4969 WRN("Image \"%s\" is used", name);
4970 return EINA_FALSE;
4971 }
4972 edje_edit_image_usage_list_free(used);
4973
4827 /* Create Image_Directory if not exist */ 4974 /* Create Image_Directory if not exist */
4828 if (!ed->file->image_dir) 4975 if (!ed->file->image_dir)
4829 goto invalid_image; 4976 goto invalid_image;
4830 4977
4831 for (i = 0; i < ed->file->image_dir->entries_count; ++i) 4978 for (i = 0; i < ed->file->image_dir->entries_count; ++i)
4832 { 4979 {
4833 de = ed->file->image_dir->entries + i; 4980 de = ed->file->image_dir->entries + i;
4834 4981
4835 if (de->entry 4982 if ((de->entry) && (!strcmp(name, de->entry)))
4836 && !strcmp(name, de->entry)) 4983 break;
4837 break;
4838 } 4984 }
4839
4840 if (i == ed->file->image_dir->entries_count) 4985 if (i == ed->file->image_dir->entries_count)
4841 goto invalid_image; 4986 goto invalid_image;
4842 4987
4988 de_last = ed->file->image_dir->entries + ed->file->image_dir->entries_count - 1;
4989
4843 { 4990 {
4844 char entry[PATH_MAX]; 4991 char entry[PATH_MAX];
4992 char last_entry[PATH_MAX];
4845 Eet_File *eetf; 4993 Eet_File *eetf;
4994 void *data;
4995 int size = 0;
4846 4996
4847 /* open the eet file */ 4997 /* open the eet file */
4848 eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE); 4998 eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE);
4849 if (!eetf) 4999 if (!eetf)
4850 { 5000 {
4851 ERR("Unable to open \"%s\" for writing output", ed->path); 5001 ERR("Unable to open \"%s\" for writing output", ed->path);
4852 return EINA_FALSE; 5002 return EINA_FALSE;
4853 } 5003 }
4854 5004
4855 snprintf(entry, sizeof(entry), "edje/images/%i", de->id); 5005 snprintf(entry, sizeof(entry), "edje/images/%i", de->id);
4856 5006
@@ -4860,20 +5010,65 @@ edje_edit_image_del(Evas_Object *obj, const char* name)
4860 eet_close(eetf); 5010 eet_close(eetf);
4861 return EINA_FALSE; 5011 return EINA_FALSE;
4862 } 5012 }
4863 5013 if (de_last->id != de->id)
5014 {
5015 snprintf(last_entry, sizeof(last_entry), "edje/images/%i", de_last->id);
5016 data = eet_read(eetf, last_entry, &size);
5017 eet_delete(eetf, last_entry);
5018 eet_write(eetf, entry, data, size, 0);
5019 }
4864 /* write the edje_file */ 5020 /* write the edje_file */
4865 if (!_edje_edit_edje_file_save(eetf, ed->file)) 5021 if (!_edje_edit_edje_file_save(eetf, ed->file))
4866 { 5022 {
4867 eet_close(eetf); 5023 eet_close(eetf);
4868 return EINA_FALSE; 5024 return EINA_FALSE;
4869 } 5025 }
4870 5026
4871 eet_close(eetf); 5027 eet_close(eetf);
4872 } 5028 }
4873 5029
5030
4874 _edje_if_string_free(ed, de->entry); 5031 _edje_if_string_free(ed, de->entry);
4875 de->entry = NULL; 5032 --ed->file->image_dir->entries_count;
4876 5033
5034 if (de_last->id != de->id)
5035 {
5036 Edje_Part *part;
5037 Edje_Part_Description_Image *part_desc_image;
5038
5039 de->entry = de_last->entry;
5040 it = eina_hash_iterator_data_new(ed->file->collection);
5041 EINA_ITERATOR_FOREACH(it, pce)
5042 {
5043 for (i = 0; i < pce->ref->parts_count; i++)
5044 {
5045 part = pce->ref->parts[i];
5046 if (part->type == EDJE_PART_TYPE_IMAGE)
5047 {
5048 part_desc_image = (Edje_Part_Description_Image *)part->default_desc;
5049 if (part_desc_image->image.id == de_last->id)
5050 part_desc_image->image.id = de->id;
5051 for (k = 0; k < part_desc_image->image.tweens_count; k++)
5052 if (part_desc_image->image.id == de_last->id)
5053 part_desc_image->image.id = de->id;
5054
5055 for (j = 0; j < part->other.desc_count; j++)
5056 {
5057 part_desc_image = (Edje_Part_Description_Image *)part->other.desc[j];
5058 if (part_desc_image->image.id == de_last->id)
5059 part_desc_image->image.id = de->id;
5060 for (k = 0; k < part_desc_image->image.tweens_count; k++)
5061 if (part_desc_image->image.id == de_last->id)
5062 part_desc_image->image.id = de->id;
5063 }
5064 }
5065 }
5066 }
5067 eina_iterator_free(it);
5068 }
5069 ed->file->image_dir->entries = realloc(ed->file->image_dir->entries,
5070 sizeof(Edje_Image_Directory_Entry) *
5071 ed->file->image_dir->entries_count);
4877 _edje_edit_flag_script_dirty(eed, EINA_TRUE); 5072 _edje_edit_flag_script_dirty(eed, EINA_TRUE);
4878 5073
4879 return EINA_TRUE; 5074 return EINA_TRUE;