diff options
Diffstat (limited to 'libraries/edje/src/lib/edje_edit.c')
-rw-r--r-- | libraries/edje/src/lib/edje_edit.c | 7829 |
1 files changed, 7829 insertions, 0 deletions
diff --git a/libraries/edje/src/lib/edje_edit.c b/libraries/edje/src/lib/edje_edit.c new file mode 100644 index 0000000..901a1b1 --- /dev/null +++ b/libraries/edje/src/lib/edje_edit.c | |||
@@ -0,0 +1,7829 @@ | |||
1 | /* | ||
2 | * TODO | ||
3 | * ----------------------------------------------------------------- | ||
4 | * Add LUA Support :) | ||
5 | * Remove images/fonts | ||
6 | * Clean the saving routines | ||
7 | * | ||
8 | */ | ||
9 | |||
10 | #include "edje_private.h" | ||
11 | |||
12 | #define EDJE_EDIT_IS_UNSTABLE_AND_I_KNOW_ABOUT_IT | ||
13 | #include "Edje_Edit.h" | ||
14 | |||
15 | static const char EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED_STR[] = "Current group cannot be deleted"; | ||
16 | static const char EDJE_EDIT_ERROR_GROUP_REFERENCED_STR[] = "Group still in use"; | ||
17 | static const char EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST_STR[] = "Group does not exist"; | ||
18 | |||
19 | EAPI Eina_Error EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED = 0 ; | ||
20 | EAPI Eina_Error EDJE_EDIT_ERROR_GROUP_REFERENCED = 0; | ||
21 | EAPI Eina_Error EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST = 0; | ||
22 | |||
23 | /* Get ed(Edje*) from obj(Evas_Object*) */ | ||
24 | #define GET_ED_OR_RETURN(RET) \ | ||
25 | Edje *ed; \ | ||
26 | Edje_Edit *eed; \ | ||
27 | if (!evas_object_smart_type_check_ptr(obj, _edje_edit_type)) \ | ||
28 | return RET; \ | ||
29 | eed = evas_object_smart_data_get(obj); \ | ||
30 | if (!eed) return RET; \ | ||
31 | ed = (Edje *)eed; | ||
32 | |||
33 | /* Get rp(Edje_Real_Part*) from obj(Evas_Object*) and part(char*) */ | ||
34 | #define GET_RP_OR_RETURN(RET) \ | ||
35 | Edje *ed; \ | ||
36 | Edje_Edit *eed; \ | ||
37 | Edje_Real_Part *rp; \ | ||
38 | if (!evas_object_smart_type_check_ptr(obj, _edje_edit_type)) \ | ||
39 | return RET; \ | ||
40 | eed = evas_object_smart_data_get(obj); \ | ||
41 | if (!eed) return RET; \ | ||
42 | ed = (Edje *)eed; \ | ||
43 | rp = _edje_real_part_get(ed, part); \ | ||
44 | if (!rp) return RET; | ||
45 | |||
46 | /* Get pd(Edje_Part_Description*) from obj(Evas_Object*), part(char*) and state (char*) */ | ||
47 | #define GET_PD_OR_RETURN(RET) \ | ||
48 | Edje *ed; \ | ||
49 | Edje_Edit *eed; \ | ||
50 | Edje_Real_Part *rp; \ | ||
51 | Edje_Part_Description_Common *pd; \ | ||
52 | if (!evas_object_smart_type_check_ptr(obj, _edje_edit_type)) \ | ||
53 | return RET; \ | ||
54 | eed = evas_object_smart_data_get(obj); \ | ||
55 | if (!eed) return RET; \ | ||
56 | ed = (Edje *)eed; \ | ||
57 | rp = _edje_real_part_get(ed, part); \ | ||
58 | if (!rp) return RET; \ | ||
59 | pd = _edje_part_description_find_byname(eed, part, state, value); \ | ||
60 | if (!pd) return RET; | ||
61 | |||
62 | /* Get epr(Edje_Program*) from obj(Evas_Object*) and prog(char*)*/ | ||
63 | #define GET_EPR_OR_RETURN(RET) \ | ||
64 | Edje_Program *epr; \ | ||
65 | if (!evas_object_smart_type_check_ptr(obj, _edje_edit_type)) \ | ||
66 | return RET; \ | ||
67 | epr = _edje_program_get_byname(obj, prog); \ | ||
68 | if (!epr) return RET; | ||
69 | |||
70 | static void * | ||
71 | _alloc(size_t size) | ||
72 | { | ||
73 | void *mem; | ||
74 | |||
75 | mem = calloc(1, size); | ||
76 | if (mem) return mem; | ||
77 | ERR("Edje_Edit: Error. memory allocation of %i bytes failed. %s", | ||
78 | (int)size, strerror(errno)); | ||
79 | return NULL; | ||
80 | } | ||
81 | |||
82 | /*************/ | ||
83 | /* INTERNALS */ | ||
84 | /*************/ | ||
85 | |||
86 | /* Edje_Edit smart! Overloads the edje one adding some more control stuff */ | ||
87 | static const char _edje_edit_type[] = "edje_edit"; | ||
88 | |||
89 | typedef struct _Edje_Edit Edje_Edit; | ||
90 | struct _Edje_Edit | ||
91 | { | ||
92 | Edje base; | ||
93 | |||
94 | void *bytecode; | ||
95 | int bytecode_size; | ||
96 | |||
97 | char *embryo_source; | ||
98 | char *embryo_processed; | ||
99 | Eina_Hash *program_scripts; | ||
100 | |||
101 | Eina_List *errors; | ||
102 | |||
103 | Eina_Bool bytecode_dirty:1; | ||
104 | Eina_Bool embryo_source_dirty:1; | ||
105 | Eina_Bool all_dirty:1; | ||
106 | Eina_Bool script_need_recompile:1; | ||
107 | }; | ||
108 | |||
109 | typedef struct _Program_Script Program_Script; | ||
110 | struct _Program_Script | ||
111 | { | ||
112 | int id; | ||
113 | char *code; | ||
114 | char *processed; | ||
115 | Eina_Bool dirty:1; | ||
116 | Eina_Bool delete_me:1; | ||
117 | }; | ||
118 | |||
119 | static void _edje_edit_smart_add(Evas_Object *obj); | ||
120 | static void _edje_edit_smart_del(Evas_Object *obj); | ||
121 | |||
122 | static Eina_Bool _edje_edit_smart_file_set(Evas_Object *obj, const char *file, const char *group); | ||
123 | static Eina_Bool _edje_edit_edje_file_save(Eet_File *eetf, Edje_File *ef); | ||
124 | |||
125 | EVAS_SMART_SUBCLASS_NEW(_edje_edit_type, _edje_edit, Edje_Smart_Api, | ||
126 | Edje_Smart_Api, _edje_object_smart_class_get, NULL) | ||
127 | |||
128 | static void | ||
129 | _edje_edit_smart_set_user(Edje_Smart_Api *sc) | ||
130 | { | ||
131 | sc->base.add = _edje_edit_smart_add; | ||
132 | sc->base.del = _edje_edit_smart_del; | ||
133 | sc->file_set = _edje_edit_smart_file_set; | ||
134 | } | ||
135 | |||
136 | static void | ||
137 | _edje_edit_smart_add(Evas_Object *obj) | ||
138 | { | ||
139 | Edje_Edit *eed; | ||
140 | |||
141 | eed = evas_object_smart_data_get(obj); | ||
142 | if (!eed) | ||
143 | { | ||
144 | const Evas_Smart *smart; | ||
145 | const Evas_Smart_Class *sc; | ||
146 | |||
147 | eed = calloc(1, sizeof(Edje_Edit)); | ||
148 | if (!eed) return; | ||
149 | |||
150 | smart = evas_object_smart_smart_get(obj); | ||
151 | sc = evas_smart_class_get(smart); | ||
152 | eed->base.api = (const Edje_Smart_Api *)sc; | ||
153 | |||
154 | evas_object_smart_data_set(obj, eed); | ||
155 | } | ||
156 | |||
157 | _edje_edit_parent_sc->base.add(obj); | ||
158 | } | ||
159 | |||
160 | static void | ||
161 | _edje_edit_data_clean(Edje_Edit *eed) | ||
162 | { | ||
163 | Edje_Edit_Script_Error *se; | ||
164 | |||
165 | free(eed->bytecode); | ||
166 | free(eed->embryo_source); | ||
167 | free(eed->embryo_processed); | ||
168 | |||
169 | if (eed->program_scripts) | ||
170 | eina_hash_free(eed->program_scripts); | ||
171 | |||
172 | EINA_LIST_FREE(eed->errors, se) | ||
173 | { | ||
174 | eina_stringshare_del(se->program_name); | ||
175 | eina_stringshare_del(se->error_str); | ||
176 | free(se); | ||
177 | } | ||
178 | |||
179 | eed->bytecode = NULL; | ||
180 | eed->embryo_source = NULL; | ||
181 | eed->embryo_processed = NULL; | ||
182 | eed->program_scripts = NULL; | ||
183 | eed->bytecode_size = 0; | ||
184 | eed->bytecode_dirty = EINA_FALSE; | ||
185 | eed->embryo_source_dirty = EINA_FALSE; | ||
186 | eed->all_dirty = EINA_FALSE; | ||
187 | eed->script_need_recompile = EINA_FALSE; | ||
188 | } | ||
189 | |||
190 | static void | ||
191 | _edje_edit_smart_del(Evas_Object *obj) | ||
192 | { | ||
193 | Edje_Edit *eed; | ||
194 | |||
195 | eed = evas_object_smart_data_get(obj); | ||
196 | |||
197 | _edje_edit_data_clean(eed); | ||
198 | |||
199 | _edje_edit_parent_sc->base.del(obj); | ||
200 | } | ||
201 | |||
202 | static void | ||
203 | _edje_edit_program_script_free(Program_Script *ps) | ||
204 | { | ||
205 | free(ps->code); | ||
206 | free(ps->processed); | ||
207 | free(ps); | ||
208 | } | ||
209 | |||
210 | static Eina_Bool | ||
211 | _edje_edit_smart_file_set(Evas_Object *obj, const char *file, const char *group) | ||
212 | { | ||
213 | Edje_Edit *eed; | ||
214 | Eet_File *ef; | ||
215 | char **keys, buf[64]; | ||
216 | int count, i; | ||
217 | int len = strlen("edje/scripts/embryo/source/"); | ||
218 | |||
219 | eed = evas_object_smart_data_get(obj); | ||
220 | |||
221 | _edje_edit_data_clean(eed); | ||
222 | |||
223 | /* TODO and maybes: | ||
224 | * * The whole point of this thing is keep track of stuff such as | ||
225 | * strings to free and who knows what, so we need to take care | ||
226 | * of those if the file/group changes. | ||
227 | * * Maybe have the possibility to open just files, not always with | ||
228 | * a group given. | ||
229 | * * A way to skip the cache? Could help avoid some issues when editing | ||
230 | * a group being used by the application in some other way, or multiple | ||
231 | * opens of the same file. | ||
232 | * * Here we probably want to allow opening groups with broken references | ||
233 | * (GROUP parts or BOX/TABLE items pointing to non-existent/renamed | ||
234 | * groups). | ||
235 | */ | ||
236 | if (!_edje_edit_parent_sc->file_set(obj, file, group)) | ||
237 | return EINA_FALSE; | ||
238 | |||
239 | eed->program_scripts = eina_hash_int32_new((Eina_Free_Cb)_edje_edit_program_script_free); | ||
240 | |||
241 | ef = eet_open(file, EET_FILE_MODE_READ); | ||
242 | |||
243 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i", | ||
244 | eed->base.collection->id); | ||
245 | eed->embryo_source = eet_read(ef, buf, &count); | ||
246 | |||
247 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i/*", | ||
248 | eed->base.collection->id); | ||
249 | keys = eet_list(ef, buf, &count); | ||
250 | for (i = 0; i < count; i++) | ||
251 | { | ||
252 | Program_Script *ps; | ||
253 | int size; | ||
254 | |||
255 | ps = calloc(1, sizeof(Program_Script)); | ||
256 | |||
257 | sscanf(keys[i] + len, "%*i/%i", &ps->id); | ||
258 | ps->code = eet_read(ef, keys[i], &size); | ||
259 | eina_hash_add(eed->program_scripts, &ps->id, ps); | ||
260 | } | ||
261 | if (keys) free(keys); | ||
262 | return EINA_TRUE; | ||
263 | } | ||
264 | |||
265 | static void | ||
266 | _edje_edit_error_register(void) | ||
267 | { | ||
268 | EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST = | ||
269 | eina_error_msg_static_register(EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST_STR); | ||
270 | EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED = | ||
271 | eina_error_msg_static_register(EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED_STR); | ||
272 | EDJE_EDIT_ERROR_GROUP_REFERENCED = | ||
273 | eina_error_msg_static_register(EDJE_EDIT_ERROR_GROUP_REFERENCED_STR); | ||
274 | } | ||
275 | |||
276 | EAPI Evas_Object * | ||
277 | edje_edit_object_add(Evas *e) | ||
278 | { | ||
279 | eina_error_set(0); | ||
280 | |||
281 | if (!EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST) | ||
282 | _edje_edit_error_register(); | ||
283 | |||
284 | return evas_object_smart_add(e, _edje_edit_smart_class_new()); | ||
285 | } | ||
286 | /* End of Edje_Edit smart stuff */ | ||
287 | |||
288 | static Edje_Part_Description_Common * | ||
289 | _edje_part_description_find_byname(Edje_Edit *eed, const char *part, const char *state, double value) | ||
290 | { | ||
291 | Edje_Real_Part *rp; | ||
292 | Edje_Part_Description_Common *pd; | ||
293 | |||
294 | if (!eed || !part || !state) return NULL; | ||
295 | |||
296 | rp = _edje_real_part_get((Edje *)eed, part); | ||
297 | if (!rp) return NULL; | ||
298 | |||
299 | pd = _edje_part_description_find((Edje *)eed, rp, state, value); | ||
300 | |||
301 | return pd; | ||
302 | } | ||
303 | |||
304 | static int | ||
305 | _edje_image_id_find(Edje_Edit *eed, const char *image_name) | ||
306 | { | ||
307 | unsigned int i; | ||
308 | |||
309 | if (!eed->base.file) return -1; | ||
310 | if (!eed->base.file->image_dir) return -1; | ||
311 | |||
312 | //printf("SEARCH IMAGE %s\n", image_name); | ||
313 | |||
314 | for (i = 0; i < eed->base.file->image_dir->entries_count; ++i) | ||
315 | if (eed->base.file->image_dir->entries[i].entry | ||
316 | && !strcmp(image_name, eed->base.file->image_dir->entries[i].entry)) | ||
317 | return i; | ||
318 | |||
319 | return -1; | ||
320 | } | ||
321 | |||
322 | static const char * | ||
323 | _edje_image_name_find(Edje_Edit *eed, int image_id) | ||
324 | { | ||
325 | if (!eed->base.file) return NULL; | ||
326 | if (!eed->base.file->image_dir) return NULL; | ||
327 | |||
328 | /* Special case for external image */ | ||
329 | if (image_id < 0) image_id = -image_id - 1; | ||
330 | |||
331 | //printf("SEARCH IMAGE ID %d\n", image_id); | ||
332 | if ((unsigned int) image_id >= eed->base.file->image_dir->entries_count) | ||
333 | return NULL; | ||
334 | return eed->base.file->image_dir->entries[image_id].entry; | ||
335 | } | ||
336 | |||
337 | static void | ||
338 | _edje_real_part_free(Edje_Real_Part *rp) | ||
339 | { | ||
340 | if (!rp) return; | ||
341 | |||
342 | if (rp->object) | ||
343 | { | ||
344 | _edje_callbacks_del(rp->object, rp->edje); | ||
345 | evas_object_del(rp->object); | ||
346 | } | ||
347 | |||
348 | if (rp->swallowed_object) | ||
349 | { | ||
350 | evas_object_smart_member_del(rp->swallowed_object); | ||
351 | evas_object_event_callback_del(rp->swallowed_object, | ||
352 | EVAS_CALLBACK_FREE, | ||
353 | _edje_object_part_swallow_free_cb); | ||
354 | evas_object_clip_unset(rp->swallowed_object); | ||
355 | evas_object_data_del(rp->swallowed_object, "\377 edje.swallowing_part"); | ||
356 | if (rp->part->mouse_events) | ||
357 | _edje_callbacks_del(rp->swallowed_object, rp->edje); | ||
358 | |||
359 | if (rp->part->type == EDJE_PART_TYPE_GROUP || | ||
360 | rp->part->type == EDJE_PART_TYPE_EXTERNAL) | ||
361 | evas_object_del(rp->swallowed_object); | ||
362 | |||
363 | rp->swallowed_object = NULL; | ||
364 | } | ||
365 | |||
366 | if (rp->text.text) eina_stringshare_del(rp->text.text); | ||
367 | if (rp->text.font) eina_stringshare_del(rp->text.font); | ||
368 | if (rp->text.cache.in_str) eina_stringshare_del(rp->text.cache.in_str); | ||
369 | if (rp->text.cache.out_str) eina_stringshare_del(rp->text.cache.out_str); | ||
370 | |||
371 | if (rp->custom) | ||
372 | { | ||
373 | _edje_collection_free_part_description_clean(rp->part->type, rp->custom->description, 0); | ||
374 | if (rp->custom) free(rp->custom->set); | ||
375 | eina_mempool_free(_edje_real_part_state_mp, rp->custom); | ||
376 | rp->custom = NULL; | ||
377 | } | ||
378 | |||
379 | free(rp->drag); | ||
380 | |||
381 | if (rp->param2) free(rp->param2->set); | ||
382 | eina_mempool_free(_edje_real_part_state_mp, rp->param2); | ||
383 | |||
384 | _edje_unref(rp->edje); | ||
385 | eina_mempool_free(_edje_real_part_mp, rp); | ||
386 | } | ||
387 | |||
388 | static Eina_Bool | ||
389 | _edje_import_font_file(Edje *ed, const char *path, const char *entry) | ||
390 | { | ||
391 | void *fdata = NULL; | ||
392 | long fsize = 0; | ||
393 | |||
394 | /* Read font data from file */ | ||
395 | { | ||
396 | FILE *f = fopen(path, "rb"); | ||
397 | if (!f) | ||
398 | { | ||
399 | ERR("Unable to open font file \"%s\"", path); | ||
400 | return EINA_FALSE; | ||
401 | } | ||
402 | |||
403 | fseek(f, 0, SEEK_END); | ||
404 | fsize = ftell(f); | ||
405 | rewind(f); | ||
406 | fdata = malloc(fsize); | ||
407 | if (!fdata) | ||
408 | { | ||
409 | ERR("Unable to alloc font file \"%s\"", path); | ||
410 | fclose(f); | ||
411 | return EINA_FALSE; | ||
412 | } | ||
413 | if (fread(fdata, fsize, 1, f) != 1) | ||
414 | { | ||
415 | free(fdata); | ||
416 | fclose(f); | ||
417 | ERR("Unable to read all of font file \"%s\"", path); | ||
418 | return EINA_FALSE; | ||
419 | } | ||
420 | fclose(f); | ||
421 | } | ||
422 | |||
423 | /* Write font to edje file */ | ||
424 | { | ||
425 | /* open the eet file */ | ||
426 | Eet_File *eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE); | ||
427 | if (!eetf) | ||
428 | { | ||
429 | ERR("Unable to open \"%s\" for writing output", ed->path); | ||
430 | free(fdata); | ||
431 | return EINA_FALSE; | ||
432 | } | ||
433 | |||
434 | if (eet_write(eetf, entry, fdata, fsize, 1) <= 0) | ||
435 | { | ||
436 | ERR("Unable to write font part \"%s\" as \"%s\" part entry", | ||
437 | path, entry); | ||
438 | eet_close(eetf); | ||
439 | free(fdata); | ||
440 | return EINA_FALSE; | ||
441 | } | ||
442 | |||
443 | free(fdata); | ||
444 | |||
445 | /* write the edje_file */ | ||
446 | if (!_edje_edit_edje_file_save(eetf, ed->file)) | ||
447 | { | ||
448 | eet_delete(eetf, entry); | ||
449 | eet_close(eetf); | ||
450 | return EINA_FALSE; | ||
451 | } | ||
452 | |||
453 | eet_close(eetf); | ||
454 | } | ||
455 | |||
456 | return EINA_TRUE; | ||
457 | } | ||
458 | |||
459 | |||
460 | static Eina_Bool | ||
461 | _edje_import_image_file(Edje *ed, const char *path, int id) | ||
462 | { | ||
463 | char entry[PATH_MAX]; | ||
464 | Evas_Object *im; | ||
465 | Eet_File *eetf; | ||
466 | void *im_data; | ||
467 | int im_w, im_h; | ||
468 | int im_alpha; | ||
469 | int bytes; | ||
470 | |||
471 | /* Try to load the file */ | ||
472 | im = evas_object_image_add(ed->base.evas); | ||
473 | if (!im) return EINA_FALSE; | ||
474 | |||
475 | evas_object_image_file_set(im, path, NULL); | ||
476 | if (evas_object_image_load_error_get(im) != EVAS_LOAD_ERROR_NONE) | ||
477 | { | ||
478 | ERR("Edje_Edit: unable to load image \"%s\"." | ||
479 | "Missing PNG or JPEG loader modules for Evas or " | ||
480 | "file does not exist, or is not readable.", path); | ||
481 | evas_object_del(im); | ||
482 | im = NULL; | ||
483 | return EINA_FALSE; | ||
484 | } | ||
485 | |||
486 | /* Write the loaded image to the edje file */ | ||
487 | |||
488 | evas_object_image_size_get(im, &im_w, &im_h); | ||
489 | im_alpha = evas_object_image_alpha_get(im); | ||
490 | im_data = evas_object_image_data_get(im, 0); | ||
491 | if ((!im_data) || !(im_w > 0) || !(im_h > 0)) | ||
492 | { | ||
493 | evas_object_del(im); | ||
494 | return EINA_FALSE; | ||
495 | } | ||
496 | |||
497 | /* open the eet file */ | ||
498 | eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE); | ||
499 | if (!eetf) | ||
500 | { | ||
501 | ERR("Unable to open \"%s\" for writing output", ed->path); | ||
502 | evas_object_del(im); | ||
503 | return EINA_FALSE; | ||
504 | } | ||
505 | |||
506 | snprintf(entry, sizeof(entry), "edje/images/%i", id); | ||
507 | |||
508 | /* write the image data */ | ||
509 | bytes = eet_data_image_write(eetf, entry, | ||
510 | im_data, im_w, im_h, | ||
511 | im_alpha, | ||
512 | 0, 100, 1); | ||
513 | if (bytes <= 0) | ||
514 | { | ||
515 | ERR("Unable to write image part \"%s\" part entry to %s", | ||
516 | entry, ed->path); | ||
517 | eet_close(eetf); | ||
518 | evas_object_del(im); | ||
519 | return EINA_FALSE; | ||
520 | } | ||
521 | |||
522 | evas_object_del(im); | ||
523 | |||
524 | /* write the edje_file */ | ||
525 | if (!_edje_edit_edje_file_save(eetf, ed->file)) | ||
526 | { | ||
527 | eet_delete(eetf, entry); | ||
528 | eet_close(eetf); | ||
529 | return EINA_FALSE; | ||
530 | } | ||
531 | |||
532 | eet_close(eetf); | ||
533 | return EINA_TRUE; | ||
534 | } | ||
535 | |||
536 | static int | ||
537 | _edje_part_id_find(Edje *ed, const char *part) | ||
538 | { | ||
539 | unsigned int id; | ||
540 | |||
541 | for (id = 0; id < ed->table_parts_size; id++) | ||
542 | { | ||
543 | Edje_Real_Part *rp = ed->table_parts[id]; | ||
544 | |||
545 | if (!strcmp(rp->part->name, part)) | ||
546 | return id; | ||
547 | } | ||
548 | return -1; | ||
549 | } | ||
550 | |||
551 | static void | ||
552 | _edje_part_description_id_set(int type, Edje_Part_Description_Common *c, int old_id, int new_id) | ||
553 | { | ||
554 | if (c->rel1.id_x == old_id) c->rel1.id_x = new_id; | ||
555 | if (c->rel1.id_y == old_id) c->rel1.id_y = new_id; | ||
556 | if (c->rel2.id_x == old_id) c->rel2.id_x = new_id; | ||
557 | if (c->rel2.id_y == old_id) c->rel2.id_y = new_id; | ||
558 | |||
559 | if (type == EDJE_PART_TYPE_TEXT | ||
560 | || type == EDJE_PART_TYPE_TEXTBLOCK) | ||
561 | { | ||
562 | Edje_Part_Description_Text *t; | ||
563 | |||
564 | t = (Edje_Part_Description_Text *) c; | ||
565 | |||
566 | if (t->text.id_source == old_id) t->text.id_source = new_id; | ||
567 | if (t->text.id_text_source == old_id) t->text.id_text_source = new_id; | ||
568 | } | ||
569 | } | ||
570 | |||
571 | static void | ||
572 | _edje_part_program_id_set(Edje_Program *epr, int old_id, int new_id) | ||
573 | { | ||
574 | Edje_Program_Target *pt; | ||
575 | Eina_List *ll, *l_next; | ||
576 | |||
577 | if (epr->action != EDJE_ACTION_TYPE_STATE_SET) | ||
578 | return; | ||
579 | |||
580 | EINA_LIST_FOREACH_SAFE(epr->targets, ll, l_next, pt) | ||
581 | { | ||
582 | if (pt->id == old_id) | ||
583 | { | ||
584 | if (new_id == -1) | ||
585 | epr->targets = eina_list_remove_list(epr->targets, ll); | ||
586 | else | ||
587 | pt->id = new_id; | ||
588 | } | ||
589 | } | ||
590 | } | ||
591 | |||
592 | static void | ||
593 | _edje_part_id_set(Edje *ed, Edje_Real_Part *rp, int new_id) | ||
594 | { | ||
595 | /* This function change the id of a given real_part. | ||
596 | * All the depedency will be updated too. | ||
597 | * Also the table_parts is updated, and the current *rp in the table | ||
598 | * is lost. | ||
599 | * If new Id = -1 then all the depencies will be deleted | ||
600 | */ | ||
601 | Edje_Part *part; | ||
602 | unsigned int j; | ||
603 | int old_id; | ||
604 | |||
605 | part = rp->part; | ||
606 | |||
607 | if (!part) return; | ||
608 | //printf("CHANGE ID OF PART %s TO %d\n", part->name, new_id); | ||
609 | |||
610 | if (!ed || new_id < -1) return; | ||
611 | |||
612 | if (part->id == new_id) return; | ||
613 | |||
614 | old_id = part->id; | ||
615 | part->id = new_id; | ||
616 | |||
617 | /* Fix all the dependecies in all parts... */ | ||
618 | for (j = 0; j < ed->collection->parts_count; ++j) | ||
619 | { | ||
620 | Edje_Part *p; | ||
621 | unsigned int k; | ||
622 | |||
623 | p = ed->collection->parts[j]; | ||
624 | |||
625 | //printf(" search id: %d in %s\n", old_id, p->name); | ||
626 | if (p->clip_to_id == old_id) p->clip_to_id = new_id; | ||
627 | if (p->dragable.confine_id == old_id) p->dragable.confine_id = new_id; | ||
628 | |||
629 | /* ...in default description */ | ||
630 | _edje_part_description_id_set(p->type, p->default_desc, old_id, new_id); | ||
631 | |||
632 | /* ...and in all other descriptions */ | ||
633 | for (k = 0; k < p->other.desc_count; ++k) | ||
634 | _edje_part_description_id_set(p->type, p->other.desc[k], old_id, new_id); | ||
635 | } | ||
636 | |||
637 | /*...and also in programs targets */ | ||
638 | #define EDJE_EDIT_PROGRAM_ID_SET(Array, Ed, It, Old, New) \ | ||
639 | for (It = 0; It < Ed->collection->programs.Array##_count; ++It) \ | ||
640 | _edje_part_program_id_set(Ed->collection->programs.Array[It], Old, New); | ||
641 | |||
642 | EDJE_EDIT_PROGRAM_ID_SET(fnmatch, ed, j, old_id, new_id); | ||
643 | EDJE_EDIT_PROGRAM_ID_SET(strcmp, ed, j, old_id, new_id); | ||
644 | EDJE_EDIT_PROGRAM_ID_SET(strncmp, ed, j, old_id, new_id); | ||
645 | EDJE_EDIT_PROGRAM_ID_SET(strrncmp, ed, j, old_id, new_id); | ||
646 | EDJE_EDIT_PROGRAM_ID_SET(nocmp, ed, j, old_id, new_id); | ||
647 | |||
648 | /* Adjust table_parts */ | ||
649 | if (new_id >= 0) | ||
650 | ed->table_parts[new_id] = rp; | ||
651 | } | ||
652 | |||
653 | static void | ||
654 | _edje_part_description_id_switch(int type, Edje_Part_Description_Common *c, int id1, int id2) | ||
655 | { | ||
656 | if (c->rel1.id_x == id1) c->rel1.id_x = id2; | ||
657 | else if (c->rel1.id_x == id2) c->rel1.id_x = id1; | ||
658 | if (c->rel1.id_y == id1) c->rel1.id_y = id2; | ||
659 | else if (c->rel1.id_y == id2) c->rel1.id_y = id1; | ||
660 | if (c->rel2.id_x == id1) c->rel2.id_x = id2; | ||
661 | else if (c->rel2.id_x == id2) c->rel2.id_x = id1; | ||
662 | if (c->rel2.id_y == id1) c->rel2.id_y = id2; | ||
663 | else if (c->rel2.id_y == id2) c->rel2.id_y = id1; | ||
664 | |||
665 | if (type == EDJE_PART_TYPE_TEXT | ||
666 | || type == EDJE_PART_TYPE_TEXTBLOCK) | ||
667 | { | ||
668 | Edje_Part_Description_Text *t; | ||
669 | |||
670 | t = (Edje_Part_Description_Text *) c; | ||
671 | |||
672 | if (t->text.id_source == id1) t->text.id_source = id2; | ||
673 | else if (t->text.id_source == id2) t->text.id_source = id1; | ||
674 | if (t->text.id_text_source == id1) t->text.id_text_source = id2; | ||
675 | else if (t->text.id_text_source == id2) t->text.id_text_source = id2; | ||
676 | } | ||
677 | } | ||
678 | |||
679 | static void | ||
680 | _edje_part_program_id_switch(Edje_Program *epr, int id1, int id2) | ||
681 | { | ||
682 | Edje_Program_Target *pt; | ||
683 | Eina_List *ll; | ||
684 | |||
685 | if (epr->action != EDJE_ACTION_TYPE_STATE_SET) | ||
686 | return; | ||
687 | |||
688 | EINA_LIST_FOREACH(epr->targets, ll, pt) | ||
689 | { | ||
690 | if (pt->id == id1) pt->id = id2; | ||
691 | else if (pt->id == id2) pt->id = id1; | ||
692 | } | ||
693 | } | ||
694 | |||
695 | static void | ||
696 | _edje_parts_id_switch(Edje *ed, Edje_Real_Part *rp1, Edje_Real_Part *rp2) | ||
697 | { | ||
698 | /* This function switch the id of two parts. | ||
699 | * All the depedency will be updated too. | ||
700 | * Also the table_parts is updated, | ||
701 | * The parts list isn't touched | ||
702 | */ | ||
703 | int id1; | ||
704 | int id2; | ||
705 | unsigned int i; | ||
706 | |||
707 | //printf("SWITCH ID OF PART %d AND %d\n", rp1->part->id, rp2->part->id); | ||
708 | |||
709 | if (!ed || !rp1 || !rp2) return; | ||
710 | if (rp1 == rp2) return; | ||
711 | |||
712 | id1 = rp1->part->id; | ||
713 | id2 = rp2->part->id; | ||
714 | |||
715 | /* Switch ids */ | ||
716 | rp1->part->id = id2; | ||
717 | rp2->part->id = id1; | ||
718 | |||
719 | /* adjust table_parts */ | ||
720 | ed->table_parts[id1] = rp2; | ||
721 | ed->table_parts[id2] = rp1; | ||
722 | |||
723 | // Fix all the dependecies in all parts... | ||
724 | for (i = 0; i < ed->collection->parts_count; ++i) | ||
725 | { | ||
726 | unsigned int j; | ||
727 | Edje_Part *p; | ||
728 | |||
729 | p = ed->collection->parts[i]; | ||
730 | |||
731 | //printf(" search id: %d in %s\n", old_id, p->name); | ||
732 | if (p->clip_to_id == id1) p->clip_to_id = id2; | ||
733 | else if (p->clip_to_id == id2) p->clip_to_id = id1; | ||
734 | if (p->dragable.confine_id == id1) p->dragable.confine_id = id2; | ||
735 | else if (p->dragable.confine_id == id2) p->dragable.confine_id = id1; | ||
736 | |||
737 | // ...in default description | ||
738 | _edje_part_description_id_switch(p->type, p->default_desc, id1, id2); | ||
739 | |||
740 | // ...and in all other descriptions | ||
741 | for (j = 0; j < p->other.desc_count; ++j) | ||
742 | _edje_part_description_id_switch(p->type, p->other.desc[j], id1, id2); | ||
743 | } | ||
744 | |||
745 | //...and also in programs targets | ||
746 | #define EDJE_EDIT_PROGRAM_SWITCH(Array, Ed, It, Id1, Id2) \ | ||
747 | for (It = 0; It < Ed->collection->programs.Array##_count; ++It) \ | ||
748 | _edje_part_program_id_switch(Ed->collection->programs.Array[i], Id1, Id2); | ||
749 | |||
750 | EDJE_EDIT_PROGRAM_SWITCH(fnmatch, ed, i, id1, id2); | ||
751 | EDJE_EDIT_PROGRAM_SWITCH(strcmp, ed, i, id1, id2); | ||
752 | EDJE_EDIT_PROGRAM_SWITCH(strncmp, ed, i, id1, id2); | ||
753 | EDJE_EDIT_PROGRAM_SWITCH(strrncmp, ed, i, id1, id2); | ||
754 | EDJE_EDIT_PROGRAM_SWITCH(nocmp, ed, i, id1, id2); | ||
755 | //TODO Real part dependencies are ok? | ||
756 | } | ||
757 | |||
758 | static void | ||
759 | _edje_fix_parts_id(Edje *ed) | ||
760 | { | ||
761 | /* We use this to clear the id hole leaved when a part is removed. | ||
762 | * After the execution of this function all parts will have a right | ||
763 | * (uniqe & ordered) id. The table_parts is also updated. | ||
764 | */ | ||
765 | unsigned int i; | ||
766 | int correct_id; | ||
767 | unsigned int count; | ||
768 | |||
769 | //printf("FIXING PARTS ID \n"); | ||
770 | |||
771 | //TODO order the list first to be more robust | ||
772 | |||
773 | /* Give a correct id to all the parts */ | ||
774 | correct_id = 0; | ||
775 | for (i = 0; i < ed->collection->parts_count; ++i) | ||
776 | { | ||
777 | Edje_Part *p; | ||
778 | |||
779 | p = ed->collection->parts[i]; | ||
780 | |||
781 | //printf(" [%d]Checking part: %s id: %d\n", correct_id, p->name, p->id); | ||
782 | if (p->id != correct_id) | ||
783 | if (ed->table_parts[p->id]) | ||
784 | _edje_part_id_set(ed, ed->table_parts[p->id], correct_id); | ||
785 | |||
786 | correct_id++; | ||
787 | } | ||
788 | |||
789 | /* If we have removed some parts realloc table_parts */ | ||
790 | count = ed->collection->parts_count; | ||
791 | if (count != ed->table_parts_size) | ||
792 | { | ||
793 | ed->table_parts = realloc(ed->table_parts, sizeof(Edje_Real_Part *) * count); | ||
794 | ed->table_parts_size = count; | ||
795 | } | ||
796 | |||
797 | //printf("\n"); | ||
798 | } | ||
799 | |||
800 | static void | ||
801 | _edje_if_string_free(Edje *ed, const char *str) | ||
802 | { | ||
803 | Eet_Dictionary *dict; | ||
804 | |||
805 | if (!ed || !str) return; | ||
806 | |||
807 | dict = eet_dictionary_get(ed->file->ef); | ||
808 | if (eet_dictionary_string_check(dict, str)) return; | ||
809 | eina_stringshare_del(str); | ||
810 | str = NULL; | ||
811 | } | ||
812 | |||
813 | static Edje_Style * | ||
814 | _edje_edit_style_get(Edje *ed, const char *name) | ||
815 | { | ||
816 | Eina_List *l; | ||
817 | Edje_Style *s; | ||
818 | |||
819 | if (!ed || !ed->file || !ed->file->styles || !name) | ||
820 | return NULL; | ||
821 | |||
822 | EINA_LIST_FOREACH(ed->file->styles, l, s) | ||
823 | if (s->name && !strcmp(s->name, name)) | ||
824 | return s; | ||
825 | |||
826 | return NULL; | ||
827 | } | ||
828 | |||
829 | static Edje_Style_Tag * | ||
830 | _edje_edit_style_tag_get(Edje *ed, const char *style, const char *name) | ||
831 | { | ||
832 | Eina_List *l; | ||
833 | Edje_Style *s; | ||
834 | Edje_Style_Tag *t; | ||
835 | |||
836 | if (!ed || !ed->file || !ed->file->styles || !name) | ||
837 | return NULL; | ||
838 | |||
839 | s = _edje_edit_style_get(ed, style); | ||
840 | |||
841 | EINA_LIST_FOREACH(s->tags, l, t) | ||
842 | if (t->key && !strcmp(t->key, name)) | ||
843 | return t; | ||
844 | |||
845 | return NULL; | ||
846 | } | ||
847 | |||
848 | static Edje_External_Directory_Entry * | ||
849 | _edje_edit_external_get(Edje *ed, const char *name) | ||
850 | { | ||
851 | unsigned int i; | ||
852 | |||
853 | if (!ed || !ed->file || !ed->file->external_dir || !name) | ||
854 | return NULL; | ||
855 | |||
856 | for (i = 0; i < ed->file->external_dir->entries_count; ++i) | ||
857 | if (ed->file->external_dir->entries[i].entry | ||
858 | && !strcmp(ed->file->external_dir->entries[i].entry, name)) | ||
859 | return ed->file->external_dir->entries + i; | ||
860 | |||
861 | return NULL; | ||
862 | } | ||
863 | |||
864 | static void | ||
865 | _edje_edit_group_references_update(Evas_Object *obj, const char *old_group_name, const char *new_group_name) | ||
866 | { | ||
867 | Eina_Iterator *i; | ||
868 | Eina_List *pll, *pl; | ||
869 | // Edje_Part_Collection *pc; | ||
870 | Edje_Part_Collection_Directory_Entry *pce; | ||
871 | char *part_name; | ||
872 | const char *source, *old; | ||
873 | Edje_Part_Type type; | ||
874 | Evas_Object *part_obj; | ||
875 | |||
876 | GET_ED_OR_RETURN(); | ||
877 | |||
878 | // pc = ed->collection; | ||
879 | |||
880 | part_obj = edje_edit_object_add(ed->base.evas); | ||
881 | |||
882 | old = eina_stringshare_add(old_group_name); | ||
883 | |||
884 | i = eina_hash_iterator_data_new(ed->file->collection); | ||
885 | |||
886 | EINA_ITERATOR_FOREACH(i, pce) | ||
887 | { | ||
888 | edje_object_file_set(part_obj, ed->file->path, pce->entry); | ||
889 | |||
890 | pl = edje_edit_parts_list_get(part_obj); | ||
891 | |||
892 | EINA_LIST_FOREACH(pl, pll, part_name) | ||
893 | { | ||
894 | source = edje_edit_part_source_get(part_obj, part_name); | ||
895 | type = edje_edit_part_type_get(part_obj, part_name); | ||
896 | |||
897 | if (type == EDJE_PART_TYPE_GROUP && source == old) | ||
898 | edje_edit_part_source_set(part_obj, part_name, new_group_name); | ||
899 | |||
900 | if (source) | ||
901 | eina_stringshare_del(source); | ||
902 | } | ||
903 | } | ||
904 | |||
905 | eina_iterator_free(i); | ||
906 | |||
907 | eina_stringshare_del(old); | ||
908 | |||
909 | evas_object_del(part_obj); | ||
910 | } | ||
911 | |||
912 | static void | ||
913 | _edje_edit_flag_script_dirty(Edje_Edit *eed, Eina_Bool all) | ||
914 | { | ||
915 | eed->script_need_recompile = EINA_TRUE; | ||
916 | if (all) | ||
917 | eed->all_dirty = EINA_TRUE; | ||
918 | } | ||
919 | |||
920 | /*****************/ | ||
921 | /* GENERAL API */ | ||
922 | /*****************/ | ||
923 | |||
924 | EAPI void | ||
925 | edje_edit_string_list_free(Eina_List *lst) | ||
926 | { | ||
927 | eina_error_set(0); | ||
928 | //printf("FREE LIST: \n"); | ||
929 | while (lst) | ||
930 | { | ||
931 | if (eina_list_data_get(lst)) eina_stringshare_del(eina_list_data_get(lst)); | ||
932 | //printf("FREE: %s\n", eina_list_data_get(lst)); | ||
933 | lst = eina_list_remove(lst, eina_list_data_get(lst)); | ||
934 | } | ||
935 | } | ||
936 | |||
937 | EAPI void | ||
938 | edje_edit_string_free(const char *str) | ||
939 | { | ||
940 | eina_error_set(0); | ||
941 | |||
942 | if (str) eina_stringshare_del(str); | ||
943 | } | ||
944 | |||
945 | EAPI const char* | ||
946 | edje_edit_compiler_get(Evas_Object *obj) | ||
947 | { | ||
948 | eina_error_set(0); | ||
949 | |||
950 | GET_ED_OR_RETURN(0); | ||
951 | return eina_stringshare_add(ed->file->compiler); | ||
952 | } | ||
953 | |||
954 | /****************/ | ||
955 | /* GROUPS API */ | ||
956 | /****************/ | ||
957 | |||
958 | EAPI Eina_Bool | ||
959 | edje_edit_group_add(Evas_Object *obj, const char *name) | ||
960 | { | ||
961 | Edje_Part_Collection_Directory_Entry *de; | ||
962 | Edje_Part_Collection_Directory_Entry *d; | ||
963 | Edje_Part_Collection *pc; | ||
964 | int id; | ||
965 | int search; | ||
966 | //Code *cd; | ||
967 | |||
968 | eina_error_set(0); | ||
969 | |||
970 | GET_ED_OR_RETURN(EINA_FALSE); | ||
971 | |||
972 | //printf("ADD GROUP: %s \n", name); | ||
973 | |||
974 | /* check if a group with the same name already exists */ | ||
975 | if (eina_hash_find(ed->file->collection, name)) | ||
976 | return EINA_FALSE; | ||
977 | |||
978 | /* Create structs */ | ||
979 | de = _alloc(sizeof(Edje_Part_Collection_Directory_Entry)); | ||
980 | if (!de) return EINA_FALSE; | ||
981 | |||
982 | pc = _alloc(sizeof(Edje_Part_Collection)); | ||
983 | if (!pc) | ||
984 | { | ||
985 | free(de); | ||
986 | return EINA_FALSE; | ||
987 | } | ||
988 | |||
989 | /* Search first free id */ | ||
990 | id = -1; | ||
991 | search = 0; | ||
992 | while (id == -1) | ||
993 | { | ||
994 | Eina_Iterator *i; | ||
995 | Eina_Bool found = 0; | ||
996 | |||
997 | i = eina_hash_iterator_data_new(ed->file->collection); | ||
998 | |||
999 | EINA_ITERATOR_FOREACH(i, d) | ||
1000 | { | ||
1001 | // printf("search if %d is free [id %d]\n", search, d->id); | ||
1002 | if (search == d->id) | ||
1003 | { | ||
1004 | found = 1; | ||
1005 | break; | ||
1006 | } | ||
1007 | } | ||
1008 | |||
1009 | eina_iterator_free(i); | ||
1010 | |||
1011 | if (!found) id = search; | ||
1012 | else search++; | ||
1013 | } | ||
1014 | |||
1015 | /* Init Edje_Part_Collection_Directory_Entry */ | ||
1016 | //printf(" new id: %d\n", id); | ||
1017 | de->id = id; | ||
1018 | de->entry = eina_stringshare_add(name); | ||
1019 | eina_hash_direct_add(ed->file->collection, de->entry, de); | ||
1020 | |||
1021 | /* Init Edje_Part_Collection */ | ||
1022 | pc->id = id; | ||
1023 | pc->references = 0; | ||
1024 | memset(&pc->programs, 0, sizeof (pc->programs)); | ||
1025 | pc->parts = NULL; | ||
1026 | pc->data = NULL; | ||
1027 | pc->script = NULL; | ||
1028 | pc->part = eina_stringshare_add(name); | ||
1029 | |||
1030 | //cd = _alloc(sizeof(Code)); | ||
1031 | //codes = eina_list_append(codes, cd); | ||
1032 | #define EDIT_EMN(Tp, Sz, Ce) \ | ||
1033 | Ce->mp.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 10); | ||
1034 | |||
1035 | EDIT_EMN(RECTANGLE, Edje_Part_Description_Common, de); | ||
1036 | EDIT_EMN(TEXT, Edje_Part_Description_Text, de); | ||
1037 | EDIT_EMN(IMAGE, Edje_Part_Description_Image, de); | ||
1038 | EDIT_EMN(SWALLOW, Edje_Part_Description_Common, de); | ||
1039 | EDIT_EMN(TEXTBLOCK, Edje_Part_Description_Text, de); | ||
1040 | EDIT_EMN(GROUP, Edje_Part_Description_Common, de); | ||
1041 | EDIT_EMN(BOX, Edje_Part_Description_Box, de); | ||
1042 | EDIT_EMN(TABLE, Edje_Part_Description_Table, de); | ||
1043 | EDIT_EMN(EXTERNAL, Edje_Part_Description_External, de); | ||
1044 | EDIT_EMN(part, Edje_Part, de); | ||
1045 | |||
1046 | ed->file->collection_cache = eina_list_prepend(ed->file->collection_cache, pc); | ||
1047 | _edje_cache_coll_clean(ed->file); | ||
1048 | |||
1049 | return EINA_TRUE; | ||
1050 | } | ||
1051 | |||
1052 | EAPI Eina_Bool | ||
1053 | edje_edit_group_del(Evas_Object *obj, const char *group_name) | ||
1054 | { | ||
1055 | Edje_Part_Collection_Directory_Entry *e; | ||
1056 | Edje_Part_Collection *die = NULL; | ||
1057 | Edje_Part_Collection *g; | ||
1058 | Eina_List *l; | ||
1059 | Eet_File *eetf; | ||
1060 | char buf[64], **keys; | ||
1061 | int count; | ||
1062 | |||
1063 | eina_error_set(0); | ||
1064 | |||
1065 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1066 | |||
1067 | /* if (eina_hash_find(ed->file->collection_hash, group_name)) */ | ||
1068 | /* return EINA_FALSE; */ | ||
1069 | |||
1070 | if (strcmp(ed->group, group_name) == 0) | ||
1071 | { | ||
1072 | eina_error_set(EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED); | ||
1073 | return EINA_FALSE; | ||
1074 | } | ||
1075 | |||
1076 | e = eina_hash_find(ed->file->collection, group_name); | ||
1077 | if (!e) | ||
1078 | { | ||
1079 | eina_error_set(EDJE_EDIT_ERROR_GROUP_DOES_NOT_EXIST); | ||
1080 | return EINA_FALSE; | ||
1081 | } | ||
1082 | |||
1083 | if (e->id == ed->collection->id) | ||
1084 | { | ||
1085 | eina_error_set(EDJE_EDIT_ERROR_GROUP_CURRENTLY_USED); | ||
1086 | return EINA_FALSE; | ||
1087 | } | ||
1088 | |||
1089 | if (e->ref) | ||
1090 | { | ||
1091 | eina_error_set(EDJE_EDIT_ERROR_GROUP_REFERENCED); | ||
1092 | return EINA_FALSE; | ||
1093 | } | ||
1094 | |||
1095 | _edje_edit_group_references_update(obj, group_name, NULL); | ||
1096 | |||
1097 | EINA_LIST_FOREACH(ed->file->collection_cache, l, g) | ||
1098 | if (g->id == e->id) | ||
1099 | { | ||
1100 | ed->file->collection_cache = | ||
1101 | eina_list_remove_list(ed->file->collection_cache, l); | ||
1102 | die = g; | ||
1103 | break; | ||
1104 | } | ||
1105 | |||
1106 | /* Remove collection/id from eet file */ | ||
1107 | eetf = eet_open(ed->file->path, EET_FILE_MODE_READ_WRITE); | ||
1108 | if (!eetf) | ||
1109 | { | ||
1110 | ERR("Edje_Edit: Error. unable to open \"%s\" " | ||
1111 | "for writing output", ed->file->path); | ||
1112 | return EINA_FALSE; | ||
1113 | } | ||
1114 | snprintf(buf, sizeof(buf), "edje/collections/%d", e->id); | ||
1115 | eet_delete(eetf, buf); | ||
1116 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%d", e->id); | ||
1117 | eet_delete(eetf, buf); | ||
1118 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d", e->id); | ||
1119 | eet_delete(eetf, buf); | ||
1120 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%d/*", e->id); | ||
1121 | keys = eet_list(eetf, buf, &count); | ||
1122 | if (keys) | ||
1123 | { | ||
1124 | do | ||
1125 | { | ||
1126 | count--; | ||
1127 | eet_delete(eetf, keys[count]); | ||
1128 | } | ||
1129 | while(count); | ||
1130 | free(keys); | ||
1131 | } | ||
1132 | eet_close(eetf); | ||
1133 | |||
1134 | /* Free Group */ | ||
1135 | if (die) _edje_collection_free(ed->file, die, e); | ||
1136 | eina_hash_del(ed->file->collection, group_name, e); | ||
1137 | |||
1138 | /* we need to save everything to make sure the file won't have broken | ||
1139 | * references the next time is loaded */ | ||
1140 | edje_edit_save_all(obj); | ||
1141 | |||
1142 | return EINA_TRUE; | ||
1143 | } | ||
1144 | |||
1145 | EAPI Eina_Bool | ||
1146 | edje_edit_group_exist(Evas_Object *obj, const char *group) | ||
1147 | { | ||
1148 | eina_error_set(0); | ||
1149 | |||
1150 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1151 | |||
1152 | if (eina_hash_find(ed->file->collection, group)) | ||
1153 | return EINA_TRUE; | ||
1154 | return EINA_FALSE; | ||
1155 | } | ||
1156 | |||
1157 | EAPI Eina_Bool | ||
1158 | edje_edit_group_name_set(Evas_Object *obj, const char *new_name) | ||
1159 | { | ||
1160 | Edje_Part_Collection_Directory_Entry *pce; | ||
1161 | Edje_Part_Collection *pc; | ||
1162 | |||
1163 | eina_error_set(0); | ||
1164 | |||
1165 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1166 | |||
1167 | if (!new_name) return EINA_FALSE; | ||
1168 | |||
1169 | pc = ed->collection; | ||
1170 | |||
1171 | if (!strcmp(pc->part, new_name)) return EINA_TRUE; | ||
1172 | |||
1173 | if (edje_edit_group_exist(obj, new_name)) return EINA_FALSE; | ||
1174 | |||
1175 | _edje_edit_group_references_update(obj, pc->part, new_name); | ||
1176 | |||
1177 | //printf("Set name of current group: %s [id: %d][new name: %s]\n", | ||
1178 | // pc->part, pc->id, new_name); | ||
1179 | |||
1180 | //if (pc->part && ed->file->free_strings) eina_stringshare_del(pc->part); TODO FIXME | ||
1181 | pce = eina_hash_find(ed->file->collection, pc->part); | ||
1182 | |||
1183 | eina_hash_move(ed->file->collection, pce->entry, new_name); | ||
1184 | |||
1185 | pce->entry = eina_stringshare_add(new_name); | ||
1186 | pc->part = pce->entry; | ||
1187 | eina_stringshare_replace(&ed->group, new_name); | ||
1188 | |||
1189 | return EINA_TRUE; | ||
1190 | } | ||
1191 | |||
1192 | #define FUNC_GROUP_ACCESSOR(Class, Value) \ | ||
1193 | EAPI int \ | ||
1194 | edje_edit_group_##Class##_##Value##_get(Evas_Object *obj) \ | ||
1195 | { \ | ||
1196 | eina_error_set(0); \ | ||
1197 | GET_ED_OR_RETURN(-1); \ | ||
1198 | if (!ed->collection) return -1; \ | ||
1199 | return ed->collection->prop.Class.Value; \ | ||
1200 | } \ | ||
1201 | EAPI void \ | ||
1202 | edje_edit_group_##Class##_##Value##_set(Evas_Object *obj, int v) \ | ||
1203 | { \ | ||
1204 | eina_error_set(0); \ | ||
1205 | GET_ED_OR_RETURN(); \ | ||
1206 | ed->collection->prop.Class.Value = v; \ | ||
1207 | } | ||
1208 | |||
1209 | FUNC_GROUP_ACCESSOR(min, w); | ||
1210 | FUNC_GROUP_ACCESSOR(min, h); | ||
1211 | FUNC_GROUP_ACCESSOR(max, w); | ||
1212 | FUNC_GROUP_ACCESSOR(max, h); | ||
1213 | |||
1214 | /***************/ | ||
1215 | /* DATA API */ | ||
1216 | /***************/ | ||
1217 | |||
1218 | EAPI Eina_List * | ||
1219 | edje_edit_group_data_list_get(Evas_Object * obj) | ||
1220 | { | ||
1221 | Eina_Iterator *it; | ||
1222 | Eina_List *datas = NULL; | ||
1223 | const char *key; | ||
1224 | |||
1225 | eina_error_set(0); | ||
1226 | |||
1227 | GET_ED_OR_RETURN(NULL); | ||
1228 | |||
1229 | if (!ed->file || !ed->collection || !ed->collection->data) | ||
1230 | return NULL; | ||
1231 | |||
1232 | it = eina_hash_iterator_key_new(ed->collection->data); | ||
1233 | if (!it) return NULL; | ||
1234 | |||
1235 | EINA_ITERATOR_FOREACH(it, key) | ||
1236 | datas = eina_list_append(datas, eina_stringshare_add(key)); | ||
1237 | |||
1238 | eina_iterator_free(it); | ||
1239 | |||
1240 | return datas; | ||
1241 | } | ||
1242 | |||
1243 | EAPI Eina_List * | ||
1244 | edje_edit_data_list_get(Evas_Object * obj) | ||
1245 | { | ||
1246 | Eina_Iterator *i; | ||
1247 | Eina_List *datas = NULL; | ||
1248 | const char *key; | ||
1249 | |||
1250 | eina_error_set(0); | ||
1251 | |||
1252 | GET_ED_OR_RETURN(NULL); | ||
1253 | |||
1254 | if (!ed->file || !ed->file->data) | ||
1255 | return NULL; | ||
1256 | |||
1257 | i = eina_hash_iterator_key_new(ed->file->data); | ||
1258 | |||
1259 | EINA_ITERATOR_FOREACH(i, key) | ||
1260 | datas = eina_list_append(datas, eina_stringshare_add(key)); | ||
1261 | |||
1262 | eina_iterator_free(i); | ||
1263 | |||
1264 | return datas; | ||
1265 | } | ||
1266 | |||
1267 | EAPI Eina_Bool | ||
1268 | edje_edit_group_data_add(Evas_Object *obj, const char *key, const char *value) | ||
1269 | { | ||
1270 | Edje_String *es; | ||
1271 | |||
1272 | eina_error_set(0); | ||
1273 | |||
1274 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1275 | |||
1276 | if (!key || !ed->file || !ed->collection) | ||
1277 | return EINA_FALSE; | ||
1278 | |||
1279 | if (!ed->collection->data) | ||
1280 | ed->collection->data = eina_hash_string_small_new(NULL); | ||
1281 | |||
1282 | if (eina_hash_find(ed->collection->data, key)) | ||
1283 | return EINA_FALSE; | ||
1284 | |||
1285 | es = calloc(1, sizeof(Edje_String)); | ||
1286 | if (!es) | ||
1287 | return EINA_FALSE; | ||
1288 | es->str = eina_stringshare_add(value); | ||
1289 | |||
1290 | if (!eina_hash_add(ed->collection->data, key, es)) | ||
1291 | { | ||
1292 | eina_stringshare_del(es->str); | ||
1293 | free(es); | ||
1294 | return EINA_FALSE; | ||
1295 | } | ||
1296 | return EINA_TRUE; | ||
1297 | } | ||
1298 | |||
1299 | EAPI Eina_Bool | ||
1300 | edje_edit_data_add(Evas_Object *obj, const char *itemname, const char *value) | ||
1301 | { | ||
1302 | Edje_String *es; | ||
1303 | |||
1304 | eina_error_set(0); | ||
1305 | |||
1306 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1307 | |||
1308 | if (!itemname || !ed->file) | ||
1309 | return EINA_FALSE; | ||
1310 | |||
1311 | if (eina_hash_find(ed->file->data, itemname)) | ||
1312 | return EINA_FALSE; | ||
1313 | |||
1314 | es = calloc(1, sizeof(Edje_String)); | ||
1315 | if (!es) | ||
1316 | return EINA_FALSE; | ||
1317 | es->str = eina_stringshare_add(value); | ||
1318 | |||
1319 | if (!eina_hash_add(ed->file->data, itemname, es)) | ||
1320 | { | ||
1321 | eina_stringshare_del(es->str); | ||
1322 | free(es); | ||
1323 | return EINA_FALSE; | ||
1324 | } | ||
1325 | return EINA_TRUE; | ||
1326 | } | ||
1327 | |||
1328 | EAPI Eina_Bool | ||
1329 | edje_edit_group_data_del(Evas_Object *obj, const char *key) | ||
1330 | { | ||
1331 | Edje_String *value; | ||
1332 | |||
1333 | eina_error_set(0); | ||
1334 | |||
1335 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1336 | |||
1337 | if (!key || !ed->file || !ed->collection) | ||
1338 | return EINA_FALSE; | ||
1339 | |||
1340 | value = eina_hash_find(ed->collection->data, key); | ||
1341 | if (!value) return EINA_FALSE; | ||
1342 | |||
1343 | eina_hash_del(ed->collection->data, key, value); | ||
1344 | _edje_if_string_free(ed, value->str); | ||
1345 | free(value); | ||
1346 | |||
1347 | return EINA_TRUE; | ||
1348 | } | ||
1349 | |||
1350 | EAPI Eina_Bool | ||
1351 | edje_edit_data_del(Evas_Object *obj, const char *itemname) | ||
1352 | { | ||
1353 | Edje_String *value; | ||
1354 | |||
1355 | eina_error_set(0); | ||
1356 | |||
1357 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1358 | |||
1359 | if (!itemname || !ed->file || !ed->file->data) | ||
1360 | return 0; | ||
1361 | |||
1362 | value = eina_hash_find(ed->file->data, itemname); | ||
1363 | if (!value) | ||
1364 | return EINA_FALSE; | ||
1365 | |||
1366 | eina_hash_del(ed->file->data, itemname, value); | ||
1367 | _edje_if_string_free(ed, value->str); | ||
1368 | free(value); | ||
1369 | |||
1370 | return EINA_TRUE; | ||
1371 | } | ||
1372 | |||
1373 | EAPI const char * | ||
1374 | edje_edit_group_data_value_get(Evas_Object * obj, const char *key) | ||
1375 | { | ||
1376 | Edje_String *value; | ||
1377 | |||
1378 | eina_error_set(0); | ||
1379 | |||
1380 | GET_ED_OR_RETURN(NULL); | ||
1381 | |||
1382 | if (!key || !ed->file || !ed->collection) | ||
1383 | return NULL; | ||
1384 | |||
1385 | value = eina_hash_find(ed->collection->data, key); | ||
1386 | if (!value) | ||
1387 | return NULL; | ||
1388 | |||
1389 | return eina_stringshare_add(edje_string_get(value)); | ||
1390 | } | ||
1391 | |||
1392 | EAPI const char * | ||
1393 | edje_edit_data_value_get(Evas_Object * obj, const char *itemname) | ||
1394 | { | ||
1395 | Edje_String *value; | ||
1396 | |||
1397 | eina_error_set(0); | ||
1398 | |||
1399 | GET_ED_OR_RETURN(NULL); | ||
1400 | |||
1401 | if (!itemname || !ed->file || !ed->file->data) | ||
1402 | return NULL; | ||
1403 | |||
1404 | value = eina_hash_find(ed->file->data, itemname); | ||
1405 | if (!value) | ||
1406 | return NULL; | ||
1407 | |||
1408 | return eina_stringshare_add(edje_string_get(value)); | ||
1409 | } | ||
1410 | |||
1411 | EAPI Eina_Bool | ||
1412 | edje_edit_group_data_value_set(Evas_Object *obj, const char *key, const char *value) | ||
1413 | { | ||
1414 | Edje_String *es; | ||
1415 | |||
1416 | eina_error_set(0); | ||
1417 | |||
1418 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1419 | |||
1420 | if (!key || !value || !ed->file || !ed->collection) | ||
1421 | return EINA_FALSE; | ||
1422 | |||
1423 | es = eina_hash_find(ed->collection->data, key); | ||
1424 | if (es) | ||
1425 | { | ||
1426 | _edje_if_string_free(ed, es->str); | ||
1427 | es->str = eina_stringshare_add(value); | ||
1428 | es->id = 0; | ||
1429 | return EINA_TRUE; | ||
1430 | } | ||
1431 | |||
1432 | return EINA_FALSE; | ||
1433 | } | ||
1434 | |||
1435 | EAPI Eina_Bool | ||
1436 | edje_edit_data_value_set(Evas_Object *obj, const char *itemname, const char *value) | ||
1437 | { | ||
1438 | Edje_String *es; | ||
1439 | |||
1440 | eina_error_set(0); | ||
1441 | |||
1442 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1443 | |||
1444 | if (!itemname || !value || !ed->file || !ed->file->data) | ||
1445 | return EINA_FALSE; | ||
1446 | |||
1447 | es = eina_hash_find(ed->file->data, itemname); | ||
1448 | if (es) | ||
1449 | { | ||
1450 | _edje_if_string_free(ed, es->str); | ||
1451 | es->str = eina_stringshare_add(value); | ||
1452 | es->id = 0; | ||
1453 | return EINA_TRUE; | ||
1454 | } | ||
1455 | return EINA_FALSE; | ||
1456 | } | ||
1457 | |||
1458 | EAPI Eina_Bool | ||
1459 | edje_edit_group_data_name_set(Evas_Object *obj, const char *key, const char *new_key) | ||
1460 | { | ||
1461 | |||
1462 | eina_error_set(0); | ||
1463 | |||
1464 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1465 | |||
1466 | if (!key || !new_key || !ed->file || !ed->collection) { | ||
1467 | return EINA_FALSE; | ||
1468 | } | ||
1469 | |||
1470 | return eina_hash_move(ed->collection->data, key, new_key); | ||
1471 | } | ||
1472 | |||
1473 | EAPI Eina_Bool | ||
1474 | edje_edit_data_name_set(Evas_Object *obj, const char *itemname, const char *newname) | ||
1475 | { | ||
1476 | |||
1477 | eina_error_set(0); | ||
1478 | |||
1479 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1480 | |||
1481 | if (!itemname || !newname || !ed->file || !ed->file->data) | ||
1482 | return EINA_FALSE; | ||
1483 | |||
1484 | return eina_hash_move(ed->file->data, itemname, newname); | ||
1485 | } | ||
1486 | |||
1487 | /***********************/ | ||
1488 | /* COLOR CLASSES API */ | ||
1489 | /***********************/ | ||
1490 | |||
1491 | EAPI Eina_List * | ||
1492 | edje_edit_color_classes_list_get(Evas_Object * obj) | ||
1493 | { | ||
1494 | Eina_List *classes = NULL; | ||
1495 | Eina_List *l; | ||
1496 | Edje_Color_Class *cc; | ||
1497 | |||
1498 | eina_error_set(0); | ||
1499 | |||
1500 | GET_ED_OR_RETURN(NULL); | ||
1501 | |||
1502 | if (!ed->file || !ed->file->color_classes) | ||
1503 | return NULL; | ||
1504 | //printf("GET CLASSES LIST %d %d\n", eina_list_count(ed->color_classes), eina_list_count(ed->file->color_classes)); | ||
1505 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1506 | classes = eina_list_append(classes, eina_stringshare_add(cc->name)); | ||
1507 | |||
1508 | return classes; | ||
1509 | } | ||
1510 | |||
1511 | EAPI Eina_Bool | ||
1512 | edje_edit_color_class_colors_get(Evas_Object *obj, const char *class_name, int *r, int *g, int *b, int *a, int *r2, int *g2, int *b2, int *a2, int *r3, int *g3, int *b3, int *a3) | ||
1513 | { | ||
1514 | Eina_List *l; | ||
1515 | Edje_Color_Class *cc; | ||
1516 | |||
1517 | eina_error_set(0); | ||
1518 | |||
1519 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1520 | |||
1521 | if (!ed->file || !ed->file->color_classes) | ||
1522 | return EINA_FALSE; | ||
1523 | |||
1524 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1525 | if (!strcmp(cc->name, class_name)) | ||
1526 | { | ||
1527 | if (r) *r = cc->r; | ||
1528 | if (g) *g = cc->g; | ||
1529 | if (b) *b = cc->b; | ||
1530 | if (a) *a = cc->a; | ||
1531 | |||
1532 | if (r2) *r2 = cc->r2; | ||
1533 | if (g2) *g2 = cc->g2; | ||
1534 | if (b2) *b2 = cc->b2; | ||
1535 | if (a2) *a2 = cc->a2; | ||
1536 | |||
1537 | if (r3) *r3 = cc->r3; | ||
1538 | if (g3) *g3 = cc->g3; | ||
1539 | if (b3) *b3 = cc->b3; | ||
1540 | if (a3) *a3 = cc->a3; | ||
1541 | |||
1542 | return EINA_TRUE; | ||
1543 | } | ||
1544 | return EINA_FALSE; | ||
1545 | } | ||
1546 | |||
1547 | EAPI Eina_Bool | ||
1548 | edje_edit_color_class_colors_set(Evas_Object *obj, const char *class_name, int r, int g, int b, int a, int r2, int g2, int b2, int a2, int r3, int g3, int b3, int a3) | ||
1549 | { | ||
1550 | Eina_List *l; | ||
1551 | Edje_Color_Class *cc; | ||
1552 | |||
1553 | eina_error_set(0); | ||
1554 | |||
1555 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1556 | |||
1557 | if (!ed->file || !ed->file->color_classes) | ||
1558 | return EINA_FALSE; | ||
1559 | |||
1560 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1561 | if (!strcmp(cc->name, class_name)) | ||
1562 | { | ||
1563 | if (r > -1) cc->r = r; | ||
1564 | if (g > -1) cc->g = g; | ||
1565 | if (b > -1) cc->b = b; | ||
1566 | if (a > -1) cc->a = a; | ||
1567 | |||
1568 | if (r2 > -1) cc->r2 = r2; | ||
1569 | if (g2 > -1) cc->g2 = g2; | ||
1570 | if (b2 > -1) cc->b2 = b2; | ||
1571 | if (a2 > -1) cc->a2 = a2; | ||
1572 | |||
1573 | if (r3 > -1) cc->r3 = r3; | ||
1574 | if (g3 > -1) cc->g3 = g3; | ||
1575 | if (b3 > -1) cc->b3 = b3; | ||
1576 | if (a3 > -1) cc->a3 = a3; | ||
1577 | |||
1578 | return EINA_TRUE; | ||
1579 | } | ||
1580 | return EINA_FALSE; | ||
1581 | } | ||
1582 | |||
1583 | EAPI Eina_Bool | ||
1584 | edje_edit_color_class_add(Evas_Object *obj, const char *name) | ||
1585 | { | ||
1586 | Eina_List *l; | ||
1587 | Edje_Color_Class *c; | ||
1588 | Edje_Color_Class *cc; | ||
1589 | |||
1590 | eina_error_set(0); | ||
1591 | |||
1592 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1593 | |||
1594 | if (!name || !ed->file) | ||
1595 | return EINA_FALSE; | ||
1596 | |||
1597 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1598 | if (strcmp(cc->name, name) == 0) | ||
1599 | return EINA_FALSE; | ||
1600 | |||
1601 | c = _alloc(sizeof(Edje_Color_Class)); | ||
1602 | if (!c) return EINA_FALSE; | ||
1603 | |||
1604 | c->name = (char*)eina_stringshare_add(name); | ||
1605 | c->r = c->g = c->b = c->a = 255; | ||
1606 | c->r2 = c->g2 = c->b2 = c->a2 = 255; | ||
1607 | c->r3 = c->g3 = c->b3 = c->a3 = 255; | ||
1608 | |||
1609 | ed->file->color_classes = eina_list_append(ed->file->color_classes, c); | ||
1610 | |||
1611 | return EINA_TRUE; | ||
1612 | } | ||
1613 | |||
1614 | EAPI Eina_Bool | ||
1615 | edje_edit_color_class_del(Evas_Object *obj, const char *name) | ||
1616 | { | ||
1617 | Eina_List *l; | ||
1618 | Edje_Color_Class *cc; | ||
1619 | |||
1620 | eina_error_set(0); | ||
1621 | |||
1622 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1623 | |||
1624 | if (!name || !ed->file || !ed->file->color_classes) | ||
1625 | return EINA_FALSE; | ||
1626 | |||
1627 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1628 | if (strcmp(cc->name, name) == 0) | ||
1629 | { | ||
1630 | _edje_if_string_free(ed, cc->name); | ||
1631 | ed->file->color_classes = eina_list_remove(ed->file->color_classes, cc); | ||
1632 | free(cc); | ||
1633 | return EINA_TRUE; | ||
1634 | } | ||
1635 | return EINA_FALSE; | ||
1636 | } | ||
1637 | |||
1638 | EAPI Eina_Bool | ||
1639 | edje_edit_color_class_name_set(Evas_Object *obj, const char *name, const char *newname) | ||
1640 | { | ||
1641 | Eina_List *l; | ||
1642 | Edje_Color_Class *cc; | ||
1643 | |||
1644 | eina_error_set(0); | ||
1645 | |||
1646 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1647 | |||
1648 | if (!ed->file || !ed->file->color_classes) | ||
1649 | return EINA_FALSE; | ||
1650 | |||
1651 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
1652 | if (!strcmp(cc->name, name)) | ||
1653 | { | ||
1654 | _edje_if_string_free(ed, cc->name); | ||
1655 | cc->name = (char*)eina_stringshare_add(newname); | ||
1656 | return EINA_TRUE; | ||
1657 | } | ||
1658 | |||
1659 | return EINA_FALSE; | ||
1660 | } | ||
1661 | |||
1662 | |||
1663 | |||
1664 | /*********************/ | ||
1665 | /* TEXT STYLES API */ | ||
1666 | /*********************/ | ||
1667 | |||
1668 | EAPI Eina_List * | ||
1669 | edje_edit_styles_list_get(Evas_Object * obj) | ||
1670 | { | ||
1671 | Eina_List *styles = NULL; | ||
1672 | Eina_List *l; | ||
1673 | Edje_Style *s; | ||
1674 | |||
1675 | eina_error_set(0); | ||
1676 | |||
1677 | GET_ED_OR_RETURN(NULL); | ||
1678 | |||
1679 | if (!ed->file || !ed->file->styles) | ||
1680 | return NULL; | ||
1681 | //printf("GET STYLES LIST %d\n", eina_list_count(ed->file->styles)); | ||
1682 | EINA_LIST_FOREACH(ed->file->styles, l, s) | ||
1683 | styles = eina_list_append(styles, eina_stringshare_add(s->name)); | ||
1684 | |||
1685 | return styles; | ||
1686 | } | ||
1687 | |||
1688 | EAPI Eina_Bool | ||
1689 | edje_edit_style_add(Evas_Object * obj, const char* style) | ||
1690 | { | ||
1691 | Edje_Style *s; | ||
1692 | |||
1693 | eina_error_set(0); | ||
1694 | |||
1695 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1696 | //printf("ADD STYLE '%s'\n", style); | ||
1697 | |||
1698 | s = _edje_edit_style_get(ed, style); | ||
1699 | if (s) return EINA_FALSE; | ||
1700 | |||
1701 | s = _alloc(sizeof(Edje_Style)); | ||
1702 | if (!s) return EINA_FALSE; | ||
1703 | s->name = (char*)eina_stringshare_add(style); | ||
1704 | s->tags = NULL; | ||
1705 | s->style = NULL; | ||
1706 | |||
1707 | ed->file->styles = eina_list_append(ed->file->styles, s); | ||
1708 | return EINA_TRUE; | ||
1709 | } | ||
1710 | |||
1711 | EAPI void | ||
1712 | edje_edit_style_del(Evas_Object * obj, const char* style) | ||
1713 | { | ||
1714 | Edje_Style *s; | ||
1715 | |||
1716 | eina_error_set(0); | ||
1717 | |||
1718 | GET_ED_OR_RETURN(); | ||
1719 | //printf("DEL STYLE '%s'\n", style); | ||
1720 | |||
1721 | s = _edje_edit_style_get(ed, style); | ||
1722 | if (!s) return; | ||
1723 | |||
1724 | ed->file->styles = eina_list_remove(ed->file->styles, s); | ||
1725 | |||
1726 | _edje_if_string_free(ed, s->name); | ||
1727 | //~ //s->style HOWTO FREE ??? | ||
1728 | while (s->tags) | ||
1729 | { | ||
1730 | Edje_Style_Tag *t; | ||
1731 | |||
1732 | t = s->tags->data; | ||
1733 | |||
1734 | s->tags = eina_list_remove(s->tags, t); | ||
1735 | _edje_if_string_free(ed, t->key); | ||
1736 | _edje_if_string_free(ed, t->value); | ||
1737 | _edje_if_string_free(ed, t->font); | ||
1738 | _edje_if_string_free(ed, t->text_class); | ||
1739 | free(t); | ||
1740 | t = NULL; | ||
1741 | } | ||
1742 | free(s); | ||
1743 | s = NULL; | ||
1744 | s = NULL; | ||
1745 | } | ||
1746 | |||
1747 | |||
1748 | EAPI Eina_List * | ||
1749 | edje_edit_style_tags_list_get(Evas_Object * obj, const char* style) | ||
1750 | { | ||
1751 | Eina_List *tags = NULL; | ||
1752 | Eina_List *l; | ||
1753 | Edje_Style *s; | ||
1754 | Edje_Style_Tag *t; | ||
1755 | |||
1756 | eina_error_set(0); | ||
1757 | |||
1758 | GET_ED_OR_RETURN(NULL); | ||
1759 | if (!ed->file || !ed->file->styles || !style) | ||
1760 | return NULL; | ||
1761 | |||
1762 | s = _edje_edit_style_get(ed, style); | ||
1763 | |||
1764 | //printf("GET STYLE TAG LIST %d\n", eina_list_count(s->tags)); | ||
1765 | EINA_LIST_FOREACH(s->tags, l, t) | ||
1766 | tags = eina_list_append(tags, eina_stringshare_add(t->key)); | ||
1767 | |||
1768 | return tags; | ||
1769 | } | ||
1770 | |||
1771 | EAPI void | ||
1772 | edje_edit_style_tag_name_set(Evas_Object * obj, const char* style, const char* tag, const char*new_name) | ||
1773 | { | ||
1774 | Edje_Style_Tag *t; | ||
1775 | |||
1776 | eina_error_set(0); | ||
1777 | |||
1778 | GET_ED_OR_RETURN(); | ||
1779 | //printf("SET TAG NAME for '%s' FOR STYLE '%s'\n", tag, style); | ||
1780 | |||
1781 | if (!ed->file || !ed->file->styles || !style || !tag) | ||
1782 | return; | ||
1783 | |||
1784 | t = _edje_edit_style_tag_get(ed, style, tag); | ||
1785 | if (!t) return; | ||
1786 | _edje_if_string_free(ed, t->key); | ||
1787 | t->key = eina_stringshare_add(new_name); | ||
1788 | } | ||
1789 | |||
1790 | EAPI const char* | ||
1791 | edje_edit_style_tag_value_get(Evas_Object * obj, const char* style, const char* tag) | ||
1792 | { | ||
1793 | Edje_Style_Tag *t; | ||
1794 | |||
1795 | eina_error_set(0); | ||
1796 | |||
1797 | GET_ED_OR_RETURN(NULL); | ||
1798 | //printf("GET TAG '%s' FOR STYLE '%s'\n", tag, style); | ||
1799 | |||
1800 | if (!ed->file || !ed->file->styles || !style || !tag) | ||
1801 | return NULL; | ||
1802 | |||
1803 | t = _edje_edit_style_tag_get(ed, style, tag); | ||
1804 | if (t && t->value) | ||
1805 | return eina_stringshare_add(t->value); | ||
1806 | |||
1807 | return NULL; | ||
1808 | } | ||
1809 | |||
1810 | EAPI void | ||
1811 | edje_edit_style_tag_value_set(Evas_Object * obj, const char* style, const char* tag, const char*new_value) | ||
1812 | { | ||
1813 | Edje_Style_Tag *t; | ||
1814 | |||
1815 | eina_error_set(0); | ||
1816 | |||
1817 | GET_ED_OR_RETURN(); | ||
1818 | //printf("SET TAG VALUE for '%s' FOR STYLE '%s'\n", tag, style); | ||
1819 | |||
1820 | if (!ed->file || !ed->file->styles || !style || !tag) | ||
1821 | return; | ||
1822 | |||
1823 | t = _edje_edit_style_tag_get(ed, style, tag); | ||
1824 | if (!t) return; | ||
1825 | _edje_if_string_free(ed, t->value); | ||
1826 | t->value = eina_stringshare_add(new_value); | ||
1827 | } | ||
1828 | |||
1829 | EAPI Eina_Bool | ||
1830 | edje_edit_style_tag_add(Evas_Object * obj, const char* style, const char* tag_name) | ||
1831 | { | ||
1832 | Edje_Style *s; | ||
1833 | Edje_Style_Tag *t; | ||
1834 | |||
1835 | eina_error_set(0); | ||
1836 | |||
1837 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1838 | //printf("ADD TAG '%s' IN STYLE '%s'\n", tag_name, style); | ||
1839 | |||
1840 | t = _edje_edit_style_tag_get(ed, style, tag_name); | ||
1841 | if (t) return EINA_FALSE; | ||
1842 | s = _edje_edit_style_get(ed, style); | ||
1843 | if (!s) return EINA_FALSE; | ||
1844 | |||
1845 | t = _alloc(sizeof(Edje_Style_Tag)); | ||
1846 | if (!t) return EINA_FALSE; | ||
1847 | t->key = eina_stringshare_add(tag_name); | ||
1848 | t->value = NULL; | ||
1849 | t->font = NULL; | ||
1850 | t->text_class = NULL; | ||
1851 | |||
1852 | s->tags = eina_list_append(s->tags, t); | ||
1853 | return EINA_TRUE; | ||
1854 | } | ||
1855 | |||
1856 | EAPI void | ||
1857 | edje_edit_style_tag_del(Evas_Object * obj, const char* style, const char* tag) | ||
1858 | { | ||
1859 | Edje_Style *s; | ||
1860 | Edje_Style_Tag *t; | ||
1861 | |||
1862 | eina_error_set(0); | ||
1863 | |||
1864 | GET_ED_OR_RETURN(); | ||
1865 | //printf("DEL TAG '%s' IN STYLE '%s'\n", tag, style); | ||
1866 | |||
1867 | s = _edje_edit_style_get(ed, style); | ||
1868 | t = _edje_edit_style_tag_get(ed, style, tag); | ||
1869 | |||
1870 | s->tags = eina_list_remove(s->tags, t); | ||
1871 | _edje_if_string_free(ed, t->key); | ||
1872 | _edje_if_string_free(ed, t->value); | ||
1873 | _edje_if_string_free(ed, t->font); | ||
1874 | _edje_if_string_free(ed, t->text_class); | ||
1875 | free(t); | ||
1876 | t = NULL; | ||
1877 | } | ||
1878 | |||
1879 | /*******************/ | ||
1880 | /* EXTERNALS API */ | ||
1881 | /*******************/ | ||
1882 | |||
1883 | EAPI Eina_List * | ||
1884 | edje_edit_externals_list_get(Evas_Object *obj) | ||
1885 | { | ||
1886 | Eina_List *externals = NULL; | ||
1887 | unsigned int i; | ||
1888 | |||
1889 | eina_error_set(0); | ||
1890 | |||
1891 | GET_ED_OR_RETURN(NULL); | ||
1892 | |||
1893 | if (!ed->file || !ed->file->external_dir) | ||
1894 | return NULL; | ||
1895 | //printf("GET STYLES LIST %d\n", eina_list_count(ed->file->styles)); | ||
1896 | for (i = 0; i < ed->file->external_dir->entries_count; ++i) | ||
1897 | externals = eina_list_append(externals, | ||
1898 | eina_stringshare_add(ed->file->external_dir->entries[i].entry)); | ||
1899 | |||
1900 | return externals; | ||
1901 | } | ||
1902 | |||
1903 | EAPI Eina_Bool | ||
1904 | edje_edit_external_add(Evas_Object *obj, const char *external) | ||
1905 | { | ||
1906 | Edje_External_Directory_Entry *e; | ||
1907 | unsigned int freeid; | ||
1908 | unsigned int i; | ||
1909 | |||
1910 | eina_error_set(0); | ||
1911 | |||
1912 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1913 | |||
1914 | e = _edje_edit_external_get(ed, external); | ||
1915 | if (e) return EINA_FALSE; | ||
1916 | |||
1917 | if (!ed->file->external_dir) | ||
1918 | ed->file->external_dir = _alloc(sizeof(Edje_External_Directory)); | ||
1919 | |||
1920 | for (i = 0; i < ed->file->external_dir->entries_count; ++i) | ||
1921 | if (!ed->file->external_dir->entries[i].entry) | ||
1922 | break ; | ||
1923 | |||
1924 | if (i == ed->file->external_dir->entries_count) | ||
1925 | { | ||
1926 | Edje_External_Directory_Entry *tmp; | ||
1927 | unsigned int max; | ||
1928 | |||
1929 | max = ed->file->external_dir->entries_count + 1; | ||
1930 | tmp = realloc(ed->file->external_dir->entries, | ||
1931 | sizeof (Edje_External_Directory_Entry) * max); | ||
1932 | |||
1933 | if (!tmp) return EINA_FALSE; | ||
1934 | |||
1935 | ed->file->external_dir->entries = tmp; | ||
1936 | freeid = ed->file->external_dir->entries_count; | ||
1937 | ed->file->external_dir->entries_count = max; | ||
1938 | } | ||
1939 | else | ||
1940 | freeid = i; | ||
1941 | |||
1942 | ed->file->external_dir->entries[freeid].entry = (char*)eina_stringshare_add(external); | ||
1943 | |||
1944 | return EINA_TRUE; | ||
1945 | } | ||
1946 | |||
1947 | EAPI Eina_Bool | ||
1948 | edje_edit_external_del(Evas_Object *obj, const char *external) | ||
1949 | { | ||
1950 | Edje_External_Directory_Entry *e; | ||
1951 | |||
1952 | eina_error_set(0); | ||
1953 | |||
1954 | GET_ED_OR_RETURN(EINA_FALSE); | ||
1955 | |||
1956 | e = _edje_edit_external_get(ed, external); | ||
1957 | if (!e) return EINA_FALSE; | ||
1958 | |||
1959 | _edje_if_string_free(ed, e->entry); | ||
1960 | e->entry = NULL; | ||
1961 | |||
1962 | return EINA_TRUE; | ||
1963 | } | ||
1964 | |||
1965 | /***************/ | ||
1966 | /* PARTS API */ | ||
1967 | /***************/ | ||
1968 | |||
1969 | EAPI Eina_List * | ||
1970 | edje_edit_parts_list_get(Evas_Object *obj) | ||
1971 | { | ||
1972 | Eina_List *parts = NULL; | ||
1973 | unsigned int i; | ||
1974 | |||
1975 | eina_error_set(0); | ||
1976 | |||
1977 | GET_ED_OR_RETURN(NULL); | ||
1978 | |||
1979 | //printf("EE: Found %d parts\n", ed->table_parts_size); | ||
1980 | |||
1981 | parts = NULL; | ||
1982 | for (i = 0; i < ed->table_parts_size; i++) | ||
1983 | { | ||
1984 | Edje_Real_Part *rp; | ||
1985 | |||
1986 | rp = ed->table_parts[i]; | ||
1987 | parts = eina_list_append(parts, eina_stringshare_add(rp->part->name)); | ||
1988 | } | ||
1989 | |||
1990 | return parts; | ||
1991 | } | ||
1992 | |||
1993 | EAPI Eina_Bool | ||
1994 | edje_edit_part_name_set(Evas_Object *obj, const char* part, const char* new_name) | ||
1995 | { | ||
1996 | eina_error_set(0); | ||
1997 | |||
1998 | GET_RP_OR_RETURN(EINA_FALSE); | ||
1999 | |||
2000 | if (!new_name) return EINA_FALSE; | ||
2001 | if (!strcmp(part, new_name)) return EINA_TRUE; | ||
2002 | if (_edje_real_part_get(ed, new_name)) return EINA_FALSE; | ||
2003 | |||
2004 | //printf("Set name of part: %s [new name: %s]\n", part, new_name); | ||
2005 | |||
2006 | _edje_if_string_free(ed, rp->part->name); | ||
2007 | rp->part->name = (char *)eina_stringshare_add(new_name); | ||
2008 | |||
2009 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
2010 | |||
2011 | return EINA_TRUE; | ||
2012 | } | ||
2013 | |||
2014 | #define FUNC_PART_API_STRING(Value) \ | ||
2015 | EAPI const char * \ | ||
2016 | edje_edit_part_api_##Value##_get(Evas_Object *obj, const char *part) \ | ||
2017 | { \ | ||
2018 | eina_error_set(0); \ | ||
2019 | GET_RP_OR_RETURN(NULL); \ | ||
2020 | return eina_stringshare_add(rp->part->api.Value); \ | ||
2021 | } \ | ||
2022 | EAPI Eina_Bool \ | ||
2023 | edje_edit_part_api_##Value##_set(Evas_Object *obj, const char *part, const char *s) \ | ||
2024 | { \ | ||
2025 | eina_error_set(0); \ | ||
2026 | GET_RP_OR_RETURN(EINA_FALSE); \ | ||
2027 | _edje_if_string_free(ed, rp->part->api.Value); \ | ||
2028 | rp->part->api.Value = eina_stringshare_add(s); \ | ||
2029 | return EINA_TRUE; \ | ||
2030 | } | ||
2031 | |||
2032 | FUNC_PART_API_STRING(name); | ||
2033 | FUNC_PART_API_STRING(description); | ||
2034 | |||
2035 | static Eina_Bool | ||
2036 | _edje_edit_real_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type, const char *source) | ||
2037 | { | ||
2038 | Edje_Part_Collection_Directory_Entry *ce; | ||
2039 | Edje_Part_Collection *pc; | ||
2040 | Edje_Part **tmp; | ||
2041 | Edje_Part *ep; | ||
2042 | Edje_Real_Part *rp; | ||
2043 | int id; | ||
2044 | |||
2045 | GET_ED_OR_RETURN(EINA_FALSE); | ||
2046 | |||
2047 | //printf("ADD PART: %s [type: %d]\n", name, type); | ||
2048 | |||
2049 | /* Check if part already exists */ | ||
2050 | if (_edje_real_part_get(ed, name)) | ||
2051 | return EINA_FALSE; | ||
2052 | |||
2053 | ce = eina_hash_find(ed->file->collection, ed->group); | ||
2054 | |||
2055 | /* Alloc Edje_Part or return */ | ||
2056 | ep = eina_mempool_malloc(ce->mp.part, sizeof(Edje_Part)); | ||
2057 | if (!ep) return EINA_FALSE; | ||
2058 | memset(ep, 0, sizeof(Edje_Part)); | ||
2059 | |||
2060 | /* Alloc Edje_Real_Part or return */ | ||
2061 | rp = eina_mempool_malloc(_edje_real_part_mp, sizeof(Edje_Real_Part)); | ||
2062 | if (!rp) | ||
2063 | { | ||
2064 | eina_mempool_free(ce->mp.part, ep); | ||
2065 | return EINA_FALSE; | ||
2066 | } | ||
2067 | memset(rp, 0, sizeof(Edje_Real_Part)); | ||
2068 | |||
2069 | /* Init Edje_Part */ | ||
2070 | pc = ed->collection; | ||
2071 | |||
2072 | tmp = realloc(pc->parts, (pc->parts_count + 1) * sizeof (Edje_Part *)); | ||
2073 | if (!tmp) | ||
2074 | { | ||
2075 | eina_mempool_free(ce->mp.part, ep); | ||
2076 | eina_mempool_free(_edje_real_part_mp, rp); | ||
2077 | return EINA_FALSE; | ||
2078 | } | ||
2079 | |||
2080 | id = pc->parts_count++; | ||
2081 | |||
2082 | pc->parts = tmp; | ||
2083 | pc->parts[id] = ep; | ||
2084 | |||
2085 | ep->id = id; | ||
2086 | ep->type = type; | ||
2087 | ep->name = eina_stringshare_add(name); | ||
2088 | ep->mouse_events = 1; | ||
2089 | ep->repeat_events = 0; | ||
2090 | ep->ignore_flags = EVAS_EVENT_FLAG_NONE; | ||
2091 | ep->pointer_mode = EVAS_OBJECT_POINTER_MODE_AUTOGRAB; | ||
2092 | ep->precise_is_inside = 0; | ||
2093 | ep->use_alternate_font_metrics = 0; | ||
2094 | ep->clip_to_id = -1; | ||
2095 | ep->dragable.confine_id = -1; | ||
2096 | ep->dragable.event_id = -1; | ||
2097 | if (source) | ||
2098 | ep->source = eina_stringshare_add(source); | ||
2099 | |||
2100 | ep->default_desc = NULL; | ||
2101 | ep->other.desc = NULL; | ||
2102 | ep->other.desc_count = 0; | ||
2103 | |||
2104 | /* Init Edje_Real_Part */ | ||
2105 | rp->edje = ed; | ||
2106 | _edje_ref(rp->edje); | ||
2107 | rp->part = ep; | ||
2108 | |||
2109 | if (ep->type == EDJE_PART_TYPE_RECTANGLE) | ||
2110 | rp->object = evas_object_rectangle_add(ed->base.evas); | ||
2111 | else if (ep->type == EDJE_PART_TYPE_IMAGE || ep->type == EDJE_PART_TYPE_PROXY) | ||
2112 | rp->object = evas_object_image_add(ed->base.evas); | ||
2113 | else if (ep->type == EDJE_PART_TYPE_TEXT) | ||
2114 | { | ||
2115 | _edje_text_part_on_add(ed, rp); | ||
2116 | rp->object = evas_object_text_add(ed->base.evas); | ||
2117 | evas_object_text_font_source_set(rp->object, ed->path); | ||
2118 | } | ||
2119 | else if (ep->type == EDJE_PART_TYPE_SWALLOW || | ||
2120 | ep->type == EDJE_PART_TYPE_GROUP || | ||
2121 | ep->type == EDJE_PART_TYPE_EXTERNAL) | ||
2122 | { | ||
2123 | rp->object = evas_object_rectangle_add(ed->base.evas); | ||
2124 | evas_object_color_set(rp->object, 0, 0, 0, 0); | ||
2125 | evas_object_pass_events_set(rp->object, 1); | ||
2126 | evas_object_pointer_mode_set(rp->object, EVAS_OBJECT_POINTER_MODE_NOGRAB); | ||
2127 | } | ||
2128 | else if (ep->type == EDJE_PART_TYPE_TEXTBLOCK) | ||
2129 | rp->object = evas_object_textblock_add(ed->base.evas); | ||
2130 | else | ||
2131 | ERR("wrong part type %i!", ep->type); | ||
2132 | if (rp->object) | ||
2133 | { | ||
2134 | evas_object_show(rp->object); | ||
2135 | evas_object_smart_member_add(rp->object, ed->obj); | ||
2136 | evas_object_layer_set(rp->object, evas_object_layer_get(ed->obj)); | ||
2137 | if (ep->type != EDJE_PART_TYPE_SWALLOW && ep->type != EDJE_PART_TYPE_GROUP) | ||
2138 | { | ||
2139 | if (ep->mouse_events) | ||
2140 | { | ||
2141 | _edje_callbacks_add(rp->object, ed, rp); | ||
2142 | if (ep->repeat_events) | ||
2143 | evas_object_repeat_events_set(rp->object, 1); | ||
2144 | |||
2145 | if (ep->pointer_mode != EVAS_OBJECT_POINTER_MODE_AUTOGRAB) | ||
2146 | evas_object_pointer_mode_set(rp->object, ep->pointer_mode); | ||
2147 | } | ||
2148 | else | ||
2149 | { | ||
2150 | evas_object_pass_events_set(rp->object, 1); | ||
2151 | evas_object_pointer_mode_set(rp->object, | ||
2152 | EVAS_OBJECT_POINTER_MODE_NOGRAB); | ||
2153 | } | ||
2154 | if (ep->precise_is_inside) | ||
2155 | evas_object_precise_is_inside_set(rp->object, 1); | ||
2156 | } | ||
2157 | if (ep->type == EDJE_PART_TYPE_EXTERNAL) | ||
2158 | { | ||
2159 | Evas_Object *child; | ||
2160 | child = _edje_external_type_add(source, evas_object_evas_get(ed->obj), ed->obj, NULL, name); | ||
2161 | if (child) | ||
2162 | _edje_real_part_swallow(rp, child, EINA_TRUE); | ||
2163 | } | ||
2164 | evas_object_clip_set(rp->object, ed->base.clipper); | ||
2165 | evas_object_show(ed->base.clipper); | ||
2166 | } | ||
2167 | |||
2168 | /* Update table_parts */ | ||
2169 | ed->table_parts_size++; | ||
2170 | ed->table_parts = realloc(ed->table_parts, | ||
2171 | sizeof(Edje_Real_Part *) * ed->table_parts_size); | ||
2172 | |||
2173 | ed->table_parts[ep->id % ed->table_parts_size] = rp; | ||
2174 | |||
2175 | /* Create default description */ | ||
2176 | if (!edje_edit_state_add(obj, name, "default", 0.0)) | ||
2177 | { | ||
2178 | _edje_if_string_free(ed, ep->name); | ||
2179 | if (source) | ||
2180 | _edje_if_string_free(ed, ep->source); | ||
2181 | eina_mempool_free(ce->mp.part, ep); | ||
2182 | eina_mempool_free(_edje_real_part_mp, rp); | ||
2183 | return EINA_FALSE; | ||
2184 | } | ||
2185 | edje_edit_part_selected_state_set(obj, name, "default", 0.0); | ||
2186 | |||
2187 | ce->count.part++; | ||
2188 | |||
2189 | return EINA_TRUE; | ||
2190 | } | ||
2191 | |||
2192 | EAPI Eina_Bool | ||
2193 | edje_edit_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type) | ||
2194 | { | ||
2195 | eina_error_set(0); | ||
2196 | |||
2197 | if (type == EDJE_PART_TYPE_EXTERNAL) | ||
2198 | return EINA_FALSE; | ||
2199 | return _edje_edit_real_part_add(obj, name, type, NULL); | ||
2200 | } | ||
2201 | |||
2202 | EAPI Eina_Bool | ||
2203 | edje_edit_part_external_add(Evas_Object *obj, const char *name, const char *source) | ||
2204 | { | ||
2205 | eina_error_set(0); | ||
2206 | |||
2207 | if (!source) | ||
2208 | return EINA_FALSE; | ||
2209 | return _edje_edit_real_part_add(obj, name, EDJE_PART_TYPE_EXTERNAL, source); | ||
2210 | } | ||
2211 | |||
2212 | EAPI Eina_Bool | ||
2213 | edje_edit_part_del(Evas_Object *obj, const char* part) | ||
2214 | { | ||
2215 | Edje_Part_Collection_Directory_Entry *ce; | ||
2216 | Edje_Part_Collection *pc; | ||
2217 | Edje_Part *ep; | ||
2218 | unsigned int k; | ||
2219 | unsigned int id; | ||
2220 | unsigned int i; | ||
2221 | |||
2222 | eina_error_set(0); | ||
2223 | |||
2224 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2225 | |||
2226 | //printf("REMOVE PART: %s\n", part); | ||
2227 | |||
2228 | ep = rp->part; | ||
2229 | id = ep->id; | ||
2230 | |||
2231 | /* Unlik Edje_Real_Parts that link to the removed one */ | ||
2232 | for (i = 0; i < ed->table_parts_size; i++) | ||
2233 | { | ||
2234 | Edje_Real_Part *real; | ||
2235 | |||
2236 | if (i == id) continue; //don't check the deleted id | ||
2237 | real = ed->table_parts[i]; | ||
2238 | |||
2239 | if (real->text.source == rp) real->text.source = NULL; | ||
2240 | if (real->text.text_source == rp) real->text.text_source = NULL; | ||
2241 | |||
2242 | if (real->param1.rel1_to_x == rp) real->param1.rel1_to_x = NULL; | ||
2243 | if (real->param1.rel1_to_y == rp) real->param1.rel1_to_y = NULL; | ||
2244 | if (real->param1.rel2_to_x == rp) real->param1.rel2_to_x = NULL; | ||
2245 | if (real->param1.rel2_to_y == rp) real->param1.rel2_to_y = NULL; | ||
2246 | |||
2247 | if (real->param2) | ||
2248 | { | ||
2249 | if (real->param2->rel1_to_x == rp) real->param2->rel1_to_x = NULL; | ||
2250 | if (real->param2->rel1_to_y == rp) real->param2->rel1_to_y = NULL; | ||
2251 | if (real->param2->rel2_to_x == rp) real->param2->rel2_to_x = NULL; | ||
2252 | if (real->param2->rel2_to_y == rp) real->param2->rel2_to_y = NULL; | ||
2253 | } | ||
2254 | |||
2255 | if (real->custom) | ||
2256 | { | ||
2257 | if (real->custom->rel1_to_x == rp) real->custom->rel1_to_x = NULL; | ||
2258 | if (real->custom->rel1_to_y == rp) real->custom->rel1_to_y = NULL; | ||
2259 | if (real->custom->rel2_to_x == rp) real->custom->rel2_to_x = NULL; | ||
2260 | if (real->custom->rel2_to_y == rp) real->custom->rel2_to_y = NULL; | ||
2261 | } | ||
2262 | |||
2263 | if (real->clip_to == rp) | ||
2264 | { | ||
2265 | evas_object_clip_set(real->object, ed->base.clipper); | ||
2266 | real->clip_to = NULL; | ||
2267 | } | ||
2268 | if (real->drag && real->drag->confine_to == rp) | ||
2269 | real->drag->confine_to = NULL; | ||
2270 | } | ||
2271 | |||
2272 | /* Unlink all the parts and descriptions that refer to id */ | ||
2273 | _edje_part_id_set(ed, rp, -1); | ||
2274 | |||
2275 | /* Remove part from parts list */ | ||
2276 | pc = ed->collection; | ||
2277 | pc->parts_count--; | ||
2278 | if (id < pc->parts_count) /* Forward parts */ | ||
2279 | { | ||
2280 | int mcount = (pc->parts_count - id) * sizeof(Edje_Part *); | ||
2281 | memmove(&pc->parts[id], &pc->parts[id+1], mcount); | ||
2282 | } | ||
2283 | pc->parts[pc->parts_count] = NULL; | ||
2284 | _edje_fix_parts_id(ed); | ||
2285 | |||
2286 | /* Free Edje_Part and all descriptions */ | ||
2287 | ce = eina_hash_find(ed->file->collection, ed->group); | ||
2288 | |||
2289 | _edje_if_string_free(ed, ep->name); | ||
2290 | if (ep->default_desc) | ||
2291 | { | ||
2292 | _edje_collection_free_part_description_free(ep->type, ep->default_desc, ce, 0); | ||
2293 | ep->default_desc = NULL; | ||
2294 | } | ||
2295 | |||
2296 | for (k = 0; k < ep->other.desc_count; ++k) | ||
2297 | _edje_collection_free_part_description_free(ep->type, ep->other.desc[k], ce, 0); | ||
2298 | |||
2299 | free(ep->other.desc); | ||
2300 | eina_mempool_free(ce->mp.part, ep); | ||
2301 | |||
2302 | /* Free Edje_Real_Part */ | ||
2303 | _edje_real_part_free(rp); | ||
2304 | |||
2305 | /* if all parts are gone, hide the clipper */ | ||
2306 | if (ed->table_parts_size == 0) | ||
2307 | evas_object_hide(ed->base.clipper); | ||
2308 | |||
2309 | edje_object_calc_force(obj); | ||
2310 | |||
2311 | ce->count.part--; | ||
2312 | |||
2313 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
2314 | |||
2315 | return EINA_TRUE; | ||
2316 | } | ||
2317 | |||
2318 | EAPI Eina_Bool | ||
2319 | edje_edit_part_exist(Evas_Object *obj, const char *part) | ||
2320 | { | ||
2321 | eina_error_set(0); | ||
2322 | |||
2323 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2324 | return EINA_TRUE; | ||
2325 | } | ||
2326 | |||
2327 | EAPI const char* | ||
2328 | edje_edit_part_below_get(Evas_Object *obj, const char* part) | ||
2329 | { | ||
2330 | Edje_Real_Part *prev; | ||
2331 | |||
2332 | eina_error_set(0); | ||
2333 | |||
2334 | GET_RP_OR_RETURN(0); | ||
2335 | |||
2336 | if (rp->part->id < 1) return NULL; | ||
2337 | |||
2338 | prev = ed->table_parts[(rp->part->id - 1) % ed->table_parts_size]; | ||
2339 | |||
2340 | return eina_stringshare_add(prev->part->name); | ||
2341 | } | ||
2342 | |||
2343 | EAPI const char* | ||
2344 | edje_edit_part_above_get(Evas_Object *obj, const char* part) | ||
2345 | { | ||
2346 | Edje_Real_Part *next; | ||
2347 | |||
2348 | eina_error_set(0); | ||
2349 | |||
2350 | GET_RP_OR_RETURN(0); | ||
2351 | |||
2352 | if ((unsigned int) rp->part->id >= ed->table_parts_size - 1) return 0; | ||
2353 | |||
2354 | next = ed->table_parts[(rp->part->id + 1) % ed->table_parts_size]; | ||
2355 | |||
2356 | return eina_stringshare_add(next->part->name); | ||
2357 | } | ||
2358 | |||
2359 | EAPI Eina_Bool | ||
2360 | edje_edit_part_restack_below(Evas_Object *obj, const char* part) | ||
2361 | { | ||
2362 | Edje_Part_Collection *group; | ||
2363 | Edje_Real_Part *prev; | ||
2364 | Edje_Part *swap; | ||
2365 | |||
2366 | eina_error_set(0); | ||
2367 | |||
2368 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2369 | |||
2370 | //printf("RESTACK PART: %s BELOW\n", part); | ||
2371 | |||
2372 | if (rp->part->id < 1) return EINA_FALSE; | ||
2373 | group = ed->collection; | ||
2374 | |||
2375 | /* update parts list */ | ||
2376 | prev = ed->table_parts[(rp->part->id - 1) % ed->table_parts_size]; | ||
2377 | |||
2378 | swap = group->parts[rp->part->id]; | ||
2379 | group->parts[rp->part->id] = group->parts[prev->part->id]; | ||
2380 | group->parts[prev->part->id] = swap; | ||
2381 | |||
2382 | _edje_parts_id_switch(ed, rp, prev); | ||
2383 | |||
2384 | evas_object_stack_below(rp->object, prev->object); | ||
2385 | if (rp->swallowed_object) | ||
2386 | evas_object_stack_above(rp->swallowed_object, rp->object); | ||
2387 | |||
2388 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
2389 | |||
2390 | return EINA_TRUE; | ||
2391 | } | ||
2392 | |||
2393 | EAPI Eina_Bool | ||
2394 | edje_edit_part_restack_above(Evas_Object *obj, const char* part) | ||
2395 | { | ||
2396 | Edje_Part_Collection *group; | ||
2397 | Edje_Real_Part *next; | ||
2398 | Edje_Part *swap; | ||
2399 | |||
2400 | eina_error_set(0); | ||
2401 | |||
2402 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2403 | |||
2404 | //printf("RESTACK PART: %s ABOVE\n", part); | ||
2405 | |||
2406 | if ((unsigned int) rp->part->id >= ed->table_parts_size - 1) return EINA_FALSE; | ||
2407 | |||
2408 | group = ed->collection; | ||
2409 | |||
2410 | /* update parts list */ | ||
2411 | next = ed->table_parts[(rp->part->id + 1) % ed->table_parts_size]; | ||
2412 | |||
2413 | swap = group->parts[rp->part->id]; | ||
2414 | group->parts[rp->part->id] = group->parts[next->part->id]; | ||
2415 | group->parts[next->part->id] = swap; | ||
2416 | |||
2417 | /* update ids */ | ||
2418 | _edje_parts_id_switch(ed, rp, next); | ||
2419 | |||
2420 | evas_object_stack_above(rp->object, next->object); | ||
2421 | if (rp->swallowed_object) | ||
2422 | evas_object_stack_above(rp->swallowed_object, rp->object); | ||
2423 | |||
2424 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
2425 | |||
2426 | return EINA_TRUE; | ||
2427 | } | ||
2428 | |||
2429 | EAPI Edje_Part_Type | ||
2430 | edje_edit_part_type_get(Evas_Object *obj, const char *part) | ||
2431 | { | ||
2432 | |||
2433 | eina_error_set(0); | ||
2434 | |||
2435 | GET_RP_OR_RETURN(0); | ||
2436 | |||
2437 | return rp->part->type; | ||
2438 | } | ||
2439 | |||
2440 | EAPI const char * | ||
2441 | edje_edit_part_selected_state_get(Evas_Object *obj, const char *part, double *value) | ||
2442 | { | ||
2443 | eina_error_set(0); | ||
2444 | |||
2445 | GET_RP_OR_RETURN(NULL); | ||
2446 | |||
2447 | if (!rp->chosen_description) | ||
2448 | { | ||
2449 | if (value) *value = 0.0; // FIXME: Make sure edje_edit supports correctly the default having any value | ||
2450 | return eina_stringshare_add("default"); | ||
2451 | } | ||
2452 | |||
2453 | if (value) *value = rp->chosen_description->state.value; | ||
2454 | return eina_stringshare_add(rp->chosen_description->state.name); | ||
2455 | } | ||
2456 | |||
2457 | EAPI Eina_Bool | ||
2458 | edje_edit_part_selected_state_set(Evas_Object *obj, const char *part, const char *state, double value) | ||
2459 | { | ||
2460 | Edje_Part_Description_Common *pd; | ||
2461 | |||
2462 | eina_error_set(0); | ||
2463 | |||
2464 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2465 | |||
2466 | pd = _edje_part_description_find_byname(eed, part, state, value); | ||
2467 | if (!pd) return EINA_FALSE; | ||
2468 | |||
2469 | //printf("EDJE: Set state: %s %f\n", pd->state.name, pd->state.value); | ||
2470 | _edje_part_description_apply(ed, rp, pd->state.name, pd->state.value, NULL, 0.0); | ||
2471 | |||
2472 | edje_object_calc_force(obj); | ||
2473 | return EINA_TRUE; | ||
2474 | } | ||
2475 | |||
2476 | EAPI const char * | ||
2477 | edje_edit_part_clip_to_get(Evas_Object *obj, const char *part) | ||
2478 | { | ||
2479 | Edje_Real_Part *clip = NULL; | ||
2480 | |||
2481 | eina_error_set(0); | ||
2482 | |||
2483 | GET_RP_OR_RETURN(NULL); | ||
2484 | |||
2485 | //printf("Get clip_to for part: %s [to_id: %d]\n", part, rp->part->clip_to_id); | ||
2486 | if (rp->part->clip_to_id < 0) return NULL; | ||
2487 | |||
2488 | clip = ed->table_parts[rp->part->clip_to_id % ed->table_parts_size]; | ||
2489 | if (!clip || !clip->part || !clip->part->name) return NULL; | ||
2490 | |||
2491 | return eina_stringshare_add(clip->part->name); | ||
2492 | } | ||
2493 | |||
2494 | EAPI Eina_Bool | ||
2495 | edje_edit_part_clip_to_set(Evas_Object *obj, const char *part, const char *clip_to) | ||
2496 | { | ||
2497 | Edje_Real_Part *clip; | ||
2498 | Evas_Object *o, *oo; | ||
2499 | |||
2500 | eina_error_set(0); | ||
2501 | |||
2502 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2503 | |||
2504 | /* unset clipping */ | ||
2505 | if (!clip_to) | ||
2506 | { | ||
2507 | //printf("UnSet clip_to for part: %s\n", part); | ||
2508 | |||
2509 | if (rp->clip_to && rp->clip_to->object) | ||
2510 | { | ||
2511 | evas_object_pointer_mode_set(rp->clip_to->object, | ||
2512 | EVAS_OBJECT_POINTER_MODE_AUTOGRAB); | ||
2513 | evas_object_clip_unset(rp->object); | ||
2514 | } | ||
2515 | |||
2516 | evas_object_clip_set(rp->object, ed->base.clipper); | ||
2517 | if (rp->swallowed_object) | ||
2518 | evas_object_clip_set(rp->swallowed_object, ed->base.clipper); | ||
2519 | |||
2520 | rp->part->clip_to_id = -1; | ||
2521 | rp->clip_to = NULL; | ||
2522 | |||
2523 | edje_object_calc_force(obj); | ||
2524 | |||
2525 | return EINA_TRUE; | ||
2526 | } | ||
2527 | |||
2528 | /* set clipping */ | ||
2529 | //printf("Set clip_to for part: %s [to: %s]\n", part, clip_to); | ||
2530 | clip = _edje_real_part_get(ed, clip_to); | ||
2531 | if (!clip || !clip->part) return EINA_FALSE; | ||
2532 | o = clip->object; | ||
2533 | while ((oo = evas_object_clip_get(o))) | ||
2534 | { | ||
2535 | if (o == rp->object) | ||
2536 | return EINA_FALSE; | ||
2537 | o = oo; | ||
2538 | } | ||
2539 | |||
2540 | rp->part->clip_to_id = clip->part->id; | ||
2541 | rp->clip_to = clip; | ||
2542 | |||
2543 | evas_object_pass_events_set(rp->clip_to->object, 1); | ||
2544 | evas_object_pointer_mode_set(rp->clip_to->object, EVAS_OBJECT_POINTER_MODE_NOGRAB); | ||
2545 | evas_object_clip_set(rp->object, rp->clip_to->object); | ||
2546 | if (rp->swallowed_object) | ||
2547 | evas_object_clip_set(rp->swallowed_object, rp->clip_to->object); | ||
2548 | |||
2549 | edje_object_calc_force(obj); | ||
2550 | |||
2551 | return EINA_TRUE; | ||
2552 | } | ||
2553 | |||
2554 | EAPI Eina_Bool | ||
2555 | edje_edit_part_mouse_events_get(Evas_Object *obj, const char *part) | ||
2556 | { | ||
2557 | eina_error_set(0); | ||
2558 | |||
2559 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2560 | //printf("Get mouse_events for part: %s [%d]\n", part, rp->part->mouse_events); | ||
2561 | return rp->part->mouse_events; | ||
2562 | } | ||
2563 | |||
2564 | EAPI void | ||
2565 | edje_edit_part_mouse_events_set(Evas_Object *obj, const char *part, Eina_Bool mouse_events) | ||
2566 | { | ||
2567 | eina_error_set(0); | ||
2568 | |||
2569 | GET_RP_OR_RETURN(); | ||
2570 | |||
2571 | if (!rp->object) return; | ||
2572 | |||
2573 | //printf("Set mouse_events for part: %s [%d]\n", part, mouse_events); | ||
2574 | |||
2575 | rp->part->mouse_events = mouse_events ? 1 : 0; | ||
2576 | |||
2577 | if (mouse_events) | ||
2578 | { | ||
2579 | evas_object_pass_events_set(rp->object, 0); | ||
2580 | _edje_callbacks_add(rp->object, ed, rp); | ||
2581 | } | ||
2582 | else | ||
2583 | { | ||
2584 | evas_object_pass_events_set(rp->object, 1); | ||
2585 | _edje_callbacks_del(rp->object, ed); | ||
2586 | } | ||
2587 | } | ||
2588 | |||
2589 | EAPI Eina_Bool | ||
2590 | edje_edit_part_repeat_events_get(Evas_Object *obj, const char *part) | ||
2591 | { | ||
2592 | eina_error_set(0); | ||
2593 | |||
2594 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2595 | |||
2596 | //printf("Get repeat_events for part: %s [%d]\n", part, rp->part->repeat_events); | ||
2597 | return rp->part->repeat_events; | ||
2598 | } | ||
2599 | |||
2600 | EAPI void | ||
2601 | edje_edit_part_repeat_events_set(Evas_Object *obj, const char *part, Eina_Bool repeat_events) | ||
2602 | { | ||
2603 | eina_error_set(0); | ||
2604 | |||
2605 | GET_RP_OR_RETURN(); | ||
2606 | |||
2607 | if (!rp->object) return; | ||
2608 | |||
2609 | //printf("Set repeat_events for part: %s [%d]\n", part, repeat_events); | ||
2610 | |||
2611 | rp->part->repeat_events = repeat_events ? 1 : 0; | ||
2612 | |||
2613 | if (repeat_events) | ||
2614 | evas_object_repeat_events_set(rp->object, 1); | ||
2615 | else | ||
2616 | evas_object_repeat_events_set(rp->object, 0); | ||
2617 | } | ||
2618 | |||
2619 | EAPI Evas_Event_Flags | ||
2620 | edje_edit_part_ignore_flags_get(Evas_Object *obj, const char *part) | ||
2621 | { | ||
2622 | eina_error_set(0); | ||
2623 | |||
2624 | GET_RP_OR_RETURN(0); | ||
2625 | |||
2626 | return rp->part->ignore_flags; | ||
2627 | } | ||
2628 | |||
2629 | EAPI void | ||
2630 | edje_edit_part_ignore_flags_set(Evas_Object *obj, const char *part, Evas_Event_Flags ignore_flags) | ||
2631 | { | ||
2632 | eina_error_set(0); | ||
2633 | |||
2634 | GET_RP_OR_RETURN(); | ||
2635 | |||
2636 | if (!rp->object) return; | ||
2637 | //printf("Set ignore_flags for part: %s [%#x]\n", part, ignore_flags); | ||
2638 | |||
2639 | rp->part->ignore_flags = ignore_flags; | ||
2640 | } | ||
2641 | |||
2642 | EAPI void | ||
2643 | edje_edit_part_scale_set(Evas_Object *obj, const char *part, Eina_Bool scale) | ||
2644 | { | ||
2645 | eina_error_set(0); | ||
2646 | |||
2647 | GET_RP_OR_RETURN(); | ||
2648 | |||
2649 | rp->part->scale = scale; | ||
2650 | edje_object_calc_force(obj); | ||
2651 | } | ||
2652 | |||
2653 | EAPI Eina_Bool | ||
2654 | edje_edit_part_scale_get(Evas_Object *obj, const char *part) | ||
2655 | { | ||
2656 | eina_error_set(0); | ||
2657 | |||
2658 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2659 | |||
2660 | return rp->part->scale; | ||
2661 | } | ||
2662 | |||
2663 | EAPI const char * | ||
2664 | edje_edit_part_source_get(Evas_Object *obj, const char *part) | ||
2665 | { | ||
2666 | //Edje_Real_Part *clip = NULL; | ||
2667 | eina_error_set(0); | ||
2668 | |||
2669 | GET_RP_OR_RETURN(NULL); | ||
2670 | |||
2671 | //printf("Get source for part: %s\n", part); | ||
2672 | if (!rp->part->source) return NULL; | ||
2673 | |||
2674 | return eina_stringshare_add(rp->part->source); | ||
2675 | } | ||
2676 | |||
2677 | EAPI Eina_Bool | ||
2678 | edje_edit_part_source_set(Evas_Object *obj, const char *part, const char *source) | ||
2679 | { | ||
2680 | eina_error_set(0); | ||
2681 | |||
2682 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2683 | |||
2684 | Evas_Object *child_obj; | ||
2685 | //printf("Set source for part: %s [source: %s]\n", part, source); | ||
2686 | |||
2687 | if (rp->part->type == EDJE_PART_TYPE_EXTERNAL) | ||
2688 | return EINA_FALSE; | ||
2689 | |||
2690 | _edje_if_string_free(ed, rp->part->source); | ||
2691 | |||
2692 | if (rp->swallowed_object) | ||
2693 | { | ||
2694 | _edje_real_part_swallow_clear(rp); | ||
2695 | evas_object_del(rp->swallowed_object); | ||
2696 | rp->swallowed_object = NULL; | ||
2697 | } | ||
2698 | if (source) | ||
2699 | { | ||
2700 | rp->part->source = eina_stringshare_add(source); | ||
2701 | child_obj = edje_object_add(ed->base.evas); | ||
2702 | edje_object_file_set(child_obj, ed->file->path, source); | ||
2703 | _edje_real_part_swallow(rp, child_obj, EINA_TRUE); | ||
2704 | } | ||
2705 | else | ||
2706 | rp->part->source = NULL; | ||
2707 | return EINA_TRUE; | ||
2708 | } | ||
2709 | |||
2710 | EAPI int | ||
2711 | edje_edit_part_drag_x_get(Evas_Object *obj, const char *part) | ||
2712 | { | ||
2713 | eina_error_set(0); | ||
2714 | |||
2715 | GET_RP_OR_RETURN(0); | ||
2716 | //printf("Get dragX for part: %s\n", part); | ||
2717 | return rp->part->dragable.x; | ||
2718 | } | ||
2719 | |||
2720 | EAPI void | ||
2721 | edje_edit_part_drag_x_set(Evas_Object *obj, const char *part, int drag) | ||
2722 | { | ||
2723 | eina_error_set(0); | ||
2724 | |||
2725 | GET_RP_OR_RETURN(); | ||
2726 | //printf("Set dragX for part: %s\n", part); | ||
2727 | rp->part->dragable.x = drag; | ||
2728 | |||
2729 | if (!drag && !rp->part->dragable.y) | ||
2730 | { | ||
2731 | free(rp->drag); | ||
2732 | rp->drag = NULL; | ||
2733 | return ; | ||
2734 | } | ||
2735 | |||
2736 | if (rp->drag) return; | ||
2737 | |||
2738 | rp->drag = _alloc(sizeof (Edje_Real_Part_Drag)); | ||
2739 | if (!rp->drag) return; | ||
2740 | |||
2741 | rp->drag->step.x = rp->part->dragable.step_x; | ||
2742 | rp->drag->step.y = rp->part->dragable.step_y; | ||
2743 | } | ||
2744 | |||
2745 | EAPI int | ||
2746 | edje_edit_part_drag_y_get(Evas_Object *obj, const char *part) | ||
2747 | { | ||
2748 | eina_error_set(0); | ||
2749 | |||
2750 | GET_RP_OR_RETURN(0); | ||
2751 | //printf("Get dragY for part: %s\n", part); | ||
2752 | return rp->part->dragable.y; | ||
2753 | } | ||
2754 | |||
2755 | EAPI void | ||
2756 | edje_edit_part_drag_y_set(Evas_Object *obj, const char *part, int drag) | ||
2757 | { | ||
2758 | eina_error_set(0); | ||
2759 | |||
2760 | GET_RP_OR_RETURN(); | ||
2761 | //printf("Set dragY for part: %s\n", part); | ||
2762 | rp->part->dragable.y = drag; | ||
2763 | |||
2764 | if (!drag && !rp->part->dragable.x) | ||
2765 | { | ||
2766 | free(rp->drag); | ||
2767 | rp->drag = NULL; | ||
2768 | return ; | ||
2769 | } | ||
2770 | |||
2771 | if (rp->drag) return; | ||
2772 | |||
2773 | rp->drag = _alloc(sizeof (Edje_Real_Part_Drag)); | ||
2774 | if (!rp->drag) return; | ||
2775 | |||
2776 | rp->drag->step.x = rp->part->dragable.step_x; | ||
2777 | rp->drag->step.y = rp->part->dragable.step_y; | ||
2778 | } | ||
2779 | |||
2780 | #define FUNC_PART_DRAG_INT(Class, Value) \ | ||
2781 | EAPI int \ | ||
2782 | edje_edit_part_drag_##Class##_##Value##_get(Evas_Object *obj, const char *part) \ | ||
2783 | { \ | ||
2784 | eina_error_set(0); \ | ||
2785 | GET_RP_OR_RETURN(0); \ | ||
2786 | return rp->part->dragable.Class##_##Value; \ | ||
2787 | } \ | ||
2788 | EAPI void \ | ||
2789 | edje_edit_part_drag_##Class##_##Value##_set(Evas_Object *obj, const char *part, int v) \ | ||
2790 | { \ | ||
2791 | eina_error_set(0); \ | ||
2792 | GET_RP_OR_RETURN(); \ | ||
2793 | rp->part->dragable.Class##_##Value = v; \ | ||
2794 | } | ||
2795 | |||
2796 | FUNC_PART_DRAG_INT(step, x); | ||
2797 | FUNC_PART_DRAG_INT(step, y); | ||
2798 | FUNC_PART_DRAG_INT(count, x); | ||
2799 | FUNC_PART_DRAG_INT(count, y); | ||
2800 | |||
2801 | #define FUNC_PART_DRAG_ID(Id) \ | ||
2802 | EAPI const char* \ | ||
2803 | edje_edit_part_drag_##Id##_get(Evas_Object *obj, const char *part) \ | ||
2804 | { \ | ||
2805 | Edje_Real_Part *p; \ | ||
2806 | \ | ||
2807 | eina_error_set(0); \ | ||
2808 | \ | ||
2809 | GET_RP_OR_RETURN(NULL); \ | ||
2810 | \ | ||
2811 | if (rp->part->dragable.Id##_id < 0) \ | ||
2812 | return NULL; \ | ||
2813 | \ | ||
2814 | p = ed->table_parts[rp->part->dragable.Id##_id]; \ | ||
2815 | return eina_stringshare_add(p->part->name); \ | ||
2816 | } \ | ||
2817 | EAPI void \ | ||
2818 | edje_edit_part_drag_##Id##_set(Evas_Object *obj, const char *part, const char *e) \ | ||
2819 | { \ | ||
2820 | Edje_Real_Part *e_part; \ | ||
2821 | \ | ||
2822 | eina_error_set(0); \ | ||
2823 | \ | ||
2824 | GET_RP_OR_RETURN(); \ | ||
2825 | if (!e) \ | ||
2826 | { \ | ||
2827 | rp->part->dragable.Id##_id = -1; \ | ||
2828 | return ; \ | ||
2829 | } \ | ||
2830 | \ | ||
2831 | e_part = _edje_real_part_get(ed, e); \ | ||
2832 | rp->part->dragable.Id##_id = e_part->part->id; \ | ||
2833 | } | ||
2834 | |||
2835 | FUNC_PART_DRAG_ID(confine); | ||
2836 | FUNC_PART_DRAG_ID(event); | ||
2837 | |||
2838 | /*********************/ | ||
2839 | /* PART STATES API */ | ||
2840 | /*********************/ | ||
2841 | EAPI Eina_List * | ||
2842 | edje_edit_part_states_list_get(Evas_Object *obj, const char *part) | ||
2843 | { | ||
2844 | char state_name[PATH_MAX]; | ||
2845 | Eina_List *states = NULL; | ||
2846 | unsigned int i; | ||
2847 | |||
2848 | eina_error_set(0); | ||
2849 | |||
2850 | GET_RP_OR_RETURN(NULL); | ||
2851 | |||
2852 | //Is there a better place to put this? maybe edje_edit_init() ? | ||
2853 | #ifdef HAVE_LOCALE_H | ||
2854 | setlocale(LC_NUMERIC, "C"); | ||
2855 | #endif | ||
2856 | |||
2857 | states = NULL; | ||
2858 | |||
2859 | //append default state | ||
2860 | snprintf(state_name, PATH_MAX, | ||
2861 | "%s %.2f", | ||
2862 | rp->part->default_desc->state.name, | ||
2863 | rp->part->default_desc->state.value); | ||
2864 | states = eina_list_append(states, eina_stringshare_add(state_name)); | ||
2865 | //printf("NEW STATE def: %s\n", state->state.name); | ||
2866 | |||
2867 | //append other states | ||
2868 | for (i = 0; i < rp->part->other.desc_count; ++i) | ||
2869 | { | ||
2870 | snprintf(state_name, sizeof(state_name), | ||
2871 | "%s %.2f", | ||
2872 | rp->part->other.desc[i]->state.name, | ||
2873 | rp->part->other.desc[i]->state.value); | ||
2874 | states = eina_list_append(states, eina_stringshare_add(state_name)); | ||
2875 | //printf("NEW STATE: %s\n", state_name); | ||
2876 | } | ||
2877 | return states; | ||
2878 | } | ||
2879 | |||
2880 | EAPI Eina_Bool | ||
2881 | edje_edit_state_name_set(Evas_Object *obj, const char *part, const char *state, double value, const char *new_name, double new_value) | ||
2882 | { | ||
2883 | int part_id; | ||
2884 | int i; | ||
2885 | |||
2886 | eina_error_set(0); | ||
2887 | |||
2888 | GET_PD_OR_RETURN(EINA_FALSE); | ||
2889 | //printf("Set name of state: %s in part: %s [new name: %s]\n", | ||
2890 | // part, state, new_name); | ||
2891 | |||
2892 | if (!new_name) return EINA_FALSE; | ||
2893 | |||
2894 | /* update programs */ | ||
2895 | /* update the 'state' field in all programs. update only if program has | ||
2896 | a single target */ | ||
2897 | part_id = _edje_part_id_find(ed, part); | ||
2898 | for (i = 0; i < ed->table_programs_size; i++) | ||
2899 | { | ||
2900 | Edje_Program *epr = ed->table_programs[i]; | ||
2901 | |||
2902 | if (eina_list_count(epr->targets) == 1) | ||
2903 | { | ||
2904 | Edje_Program_Target *t = eina_list_data_get(epr->targets); | ||
2905 | |||
2906 | if (t->id == part_id && | ||
2907 | !strcmp(epr->state, pd->state.name) && | ||
2908 | pd->state.value == epr->value) | ||
2909 | { | ||
2910 | _edje_if_string_free(ed, epr->state); | ||
2911 | epr->state = eina_stringshare_add(new_name); | ||
2912 | epr->value = value; | ||
2913 | } | ||
2914 | } | ||
2915 | } | ||
2916 | |||
2917 | /* set name */ | ||
2918 | _edje_if_string_free(ed, pd->state.name); | ||
2919 | pd->state.name = (char *)eina_stringshare_add(new_name); | ||
2920 | /* set value */ | ||
2921 | pd->state.value = new_value; | ||
2922 | |||
2923 | return EINA_TRUE; | ||
2924 | } | ||
2925 | |||
2926 | EAPI Eina_Bool | ||
2927 | edje_edit_state_del(Evas_Object *obj, const char *part, const char *state, double value) | ||
2928 | { | ||
2929 | Edje_Part_Collection_Directory_Entry *ce; | ||
2930 | Edje_Part_Description_Common *pd; | ||
2931 | unsigned int i; | ||
2932 | |||
2933 | eina_error_set(0); | ||
2934 | |||
2935 | GET_RP_OR_RETURN(EINA_FALSE); | ||
2936 | |||
2937 | if (!edje_edit_state_exist(obj, part, state, value)) | ||
2938 | return EINA_FALSE; | ||
2939 | |||
2940 | pd = _edje_part_description_find_byname(eed, part, state, value); | ||
2941 | if (!pd) return EINA_FALSE; | ||
2942 | |||
2943 | /* Don't allow to delete default state, for now at least; */ | ||
2944 | if (pd == rp->part->default_desc) | ||
2945 | return EINA_FALSE; | ||
2946 | |||
2947 | /* And if we are deleting the current state, go back to default first */ | ||
2948 | if (pd == rp->chosen_description) | ||
2949 | _edje_part_description_apply(ed, rp, "default", 0.0, NULL, 0.0); | ||
2950 | |||
2951 | ce = eina_hash_find(ed->file->collection, ed->group); | ||
2952 | |||
2953 | for (i = 0; i < rp->part->other.desc_count; ++i) | ||
2954 | if (pd == rp->part->other.desc[i]) | ||
2955 | { | ||
2956 | memmove(rp->part->other.desc + i, | ||
2957 | rp->part->other.desc + i + 1, | ||
2958 | sizeof (Edje_Part_Description_Common*) * (rp->part->other.desc_count - i - 1)); | ||
2959 | rp->part->other.desc_count--; | ||
2960 | break; | ||
2961 | } | ||
2962 | |||
2963 | _edje_collection_free_part_description_free(rp->part->type, pd, ce, 0); | ||
2964 | return EINA_TRUE; | ||
2965 | } | ||
2966 | |||
2967 | static Edje_Part_Description_Common * | ||
2968 | _edje_edit_state_alloc(int type, Edje *ed) | ||
2969 | { | ||
2970 | Edje_Part_Collection_Directory_Entry *ce; | ||
2971 | Edje_Part_Description_Common *pd = NULL; | ||
2972 | |||
2973 | ce = eina_hash_find(ed->file->collection, ed->group); | ||
2974 | |||
2975 | switch (type) | ||
2976 | { | ||
2977 | case EDJE_PART_TYPE_RECTANGLE: | ||
2978 | pd = eina_mempool_malloc(ce->mp.RECTANGLE, sizeof (Edje_Part_Description_Common)); | ||
2979 | ce->count.RECTANGLE++; | ||
2980 | break; | ||
2981 | case EDJE_PART_TYPE_SWALLOW: | ||
2982 | pd = eina_mempool_malloc(ce->mp.SWALLOW, sizeof (Edje_Part_Description_Common)); | ||
2983 | ce->count.SWALLOW++; | ||
2984 | break; | ||
2985 | case EDJE_PART_TYPE_GROUP: | ||
2986 | pd = eina_mempool_malloc(ce->mp.GROUP, sizeof (Edje_Part_Description_Common)); | ||
2987 | ce->count.GROUP++; | ||
2988 | break; | ||
2989 | |||
2990 | #define EDIT_ALLOC_POOL(Short, Type, Name) \ | ||
2991 | case EDJE_PART_TYPE_##Short: \ | ||
2992 | { \ | ||
2993 | Edje_Part_Description_##Type *Name; \ | ||
2994 | \ | ||
2995 | Name = eina_mempool_malloc(ce->mp.Short, \ | ||
2996 | sizeof (Edje_Part_Description_##Type)); \ | ||
2997 | memset(Name, 0, sizeof(Edje_Part_Description_##Type)); \ | ||
2998 | pd = &Name->common; \ | ||
2999 | ce->count.Short++; \ | ||
3000 | break; \ | ||
3001 | } | ||
3002 | |||
3003 | EDIT_ALLOC_POOL(IMAGE, Image, image); | ||
3004 | EDIT_ALLOC_POOL(TEXT, Text, text); | ||
3005 | EDIT_ALLOC_POOL(TEXTBLOCK, Text, text); | ||
3006 | EDIT_ALLOC_POOL(BOX, Box, box); | ||
3007 | EDIT_ALLOC_POOL(TABLE, Table, table); | ||
3008 | EDIT_ALLOC_POOL(EXTERNAL, External, external_params); | ||
3009 | } | ||
3010 | |||
3011 | return pd; | ||
3012 | } | ||
3013 | |||
3014 | EAPI Eina_Bool | ||
3015 | edje_edit_state_add(Evas_Object *obj, const char *part, const char *name, double value) | ||
3016 | { | ||
3017 | Edje_Part_Description_Common *pd; | ||
3018 | |||
3019 | GET_RP_OR_RETURN(EINA_FALSE); | ||
3020 | |||
3021 | if (edje_edit_state_exist(obj, part, name, value)) | ||
3022 | return EINA_FALSE; | ||
3023 | |||
3024 | //printf("ADD STATE: %s TO PART: %s\n", name , part); | ||
3025 | pd = _edje_edit_state_alloc(rp->part->type, ed); | ||
3026 | if (!pd) return EINA_FALSE; | ||
3027 | |||
3028 | if (!rp->part->default_desc) | ||
3029 | { | ||
3030 | rp->part->default_desc = pd; | ||
3031 | } | ||
3032 | else | ||
3033 | { | ||
3034 | Edje_Part_Description_Common **tmp; | ||
3035 | |||
3036 | tmp = realloc(rp->part->other.desc, | ||
3037 | sizeof (Edje_Part_Description_Common *) * (rp->part->other.desc_count + 1)); | ||
3038 | if (!tmp) | ||
3039 | { | ||
3040 | free(pd); | ||
3041 | return EINA_FALSE; | ||
3042 | } | ||
3043 | rp->part->other.desc = tmp; | ||
3044 | rp->part->other.desc[rp->part->other.desc_count++] = pd; | ||
3045 | } | ||
3046 | |||
3047 | memset(pd, 0, sizeof (*pd)); | ||
3048 | |||
3049 | pd->state.name = eina_stringshare_add(name); | ||
3050 | pd->state.value = value; | ||
3051 | pd->visible = 1; | ||
3052 | pd->align.x = 0.5; | ||
3053 | pd->align.y = 0.5; | ||
3054 | pd->min.w = 0; | ||
3055 | pd->min.h = 0; | ||
3056 | pd->fixed.w = 0; | ||
3057 | pd->fixed.h = 0; | ||
3058 | pd->max.w = -1; | ||
3059 | pd->max.h = -1; | ||
3060 | pd->rel1.relative_x = 0.0; | ||
3061 | pd->rel1.relative_y = 0.0; | ||
3062 | pd->rel1.offset_x = 0; | ||
3063 | pd->rel1.offset_y = 0; | ||
3064 | pd->rel1.id_x = -1; | ||
3065 | pd->rel1.id_y = -1; | ||
3066 | pd->rel2.relative_x = 1.0; | ||
3067 | pd->rel2.relative_y = 1.0; | ||
3068 | pd->rel2.offset_x = -1; | ||
3069 | pd->rel2.offset_y = -1; | ||
3070 | pd->rel2.id_x = -1; | ||
3071 | pd->rel2.id_y = -1; | ||
3072 | pd->color_class = NULL; | ||
3073 | pd->color.r = 255; | ||
3074 | pd->color.g = 255; | ||
3075 | pd->color.b = 255; | ||
3076 | pd->color.a = 255; | ||
3077 | pd->color2.r = 0; | ||
3078 | pd->color2.g = 0; | ||
3079 | pd->color2.b = 0; | ||
3080 | pd->color2.a = 255; | ||
3081 | pd->map.id_persp = -1; | ||
3082 | pd->map.id_light = -1; | ||
3083 | pd->map.rot.id_center = -1; | ||
3084 | pd->map.rot.x = FROM_DOUBLE(0.0); | ||
3085 | pd->map.rot.y = FROM_DOUBLE(0.0); | ||
3086 | pd->map.rot.z = FROM_DOUBLE(0.0); | ||
3087 | pd->map.on = 0; | ||
3088 | pd->map.smooth = 1; | ||
3089 | pd->map.alpha = 1; | ||
3090 | pd->map.backcull = 0; | ||
3091 | pd->map.persp_on = 0; | ||
3092 | pd->persp.zplane = 0; | ||
3093 | pd->persp.focal = 1000; | ||
3094 | |||
3095 | if (rp->part->type == EDJE_PART_TYPE_TEXT | ||
3096 | || rp->part->type == EDJE_PART_TYPE_TEXTBLOCK) | ||
3097 | { | ||
3098 | Edje_Part_Description_Text *text; | ||
3099 | |||
3100 | text = (Edje_Part_Description_Text*) pd; | ||
3101 | |||
3102 | memset(&text->text, 0, sizeof (text->text)); | ||
3103 | |||
3104 | text->text.color3.r = 0; | ||
3105 | text->text.color3.g = 0; | ||
3106 | text->text.color3.b = 0; | ||
3107 | text->text.color3.a = 128; | ||
3108 | text->text.align.x = 0.5; | ||
3109 | text->text.align.y = 0.5; | ||
3110 | text->text.id_source = -1; | ||
3111 | text->text.id_text_source = -1; | ||
3112 | } | ||
3113 | else if (rp->part->type == EDJE_PART_TYPE_IMAGE) | ||
3114 | { | ||
3115 | Edje_Part_Description_Image *img; | ||
3116 | |||
3117 | img = (Edje_Part_Description_Image*) pd; | ||
3118 | |||
3119 | memset(&img->image, 0, sizeof (img->image)); | ||
3120 | |||
3121 | img->image.id = -1; | ||
3122 | img->image.fill.smooth = 1; | ||
3123 | img->image.fill.pos_rel_x = 0.0; | ||
3124 | img->image.fill.pos_abs_x = 0; | ||
3125 | img->image.fill.rel_x = 1.0; | ||
3126 | img->image.fill.abs_x = 0; | ||
3127 | img->image.fill.pos_rel_y = 0.0; | ||
3128 | img->image.fill.pos_abs_y = 0; | ||
3129 | img->image.fill.rel_y = 1.0; | ||
3130 | img->image.fill.abs_y = 0; | ||
3131 | img->image.fill.angle = 0; | ||
3132 | img->image.fill.spread = 0; | ||
3133 | img->image.fill.type = EDJE_FILL_TYPE_SCALE; | ||
3134 | } | ||
3135 | else if (rp->part->type == EDJE_PART_TYPE_PROXY) | ||
3136 | { | ||
3137 | Edje_Part_Description_Proxy *pro; | ||
3138 | |||
3139 | pro = (Edje_Part_Description_Proxy*) pd; | ||
3140 | |||
3141 | memset(&pro->proxy, 0, sizeof (pro->proxy)); | ||
3142 | |||
3143 | pro->proxy.id = -1; | ||
3144 | pro->proxy.fill.smooth = 1; | ||
3145 | pro->proxy.fill.pos_rel_x = 0.0; | ||
3146 | pro->proxy.fill.pos_abs_x = 0; | ||
3147 | pro->proxy.fill.rel_x = 1.0; | ||
3148 | pro->proxy.fill.abs_x = 0; | ||
3149 | pro->proxy.fill.pos_rel_y = 0.0; | ||
3150 | pro->proxy.fill.pos_abs_y = 0; | ||
3151 | pro->proxy.fill.rel_y = 1.0; | ||
3152 | pro->proxy.fill.abs_y = 0; | ||
3153 | pro->proxy.fill.angle = 0; | ||
3154 | pro->proxy.fill.spread = 0; | ||
3155 | pro->proxy.fill.type = EDJE_FILL_TYPE_SCALE; | ||
3156 | } | ||
3157 | else if (rp->part->type == EDJE_PART_TYPE_EXTERNAL) | ||
3158 | { | ||
3159 | Edje_Part_Description_External *external; | ||
3160 | Edje_External_Param_Info *pi; | ||
3161 | |||
3162 | external = (Edje_Part_Description_External*) pd; | ||
3163 | |||
3164 | external->external_params = NULL; | ||
3165 | |||
3166 | if (rp->part->source) | ||
3167 | { | ||
3168 | pi = (Edje_External_Param_Info *)edje_external_param_info_get(rp->part->source); | ||
3169 | while (pi && pi->name) | ||
3170 | { | ||
3171 | Edje_External_Param *p; | ||
3172 | p = _alloc(sizeof(Edje_External_Param)); | ||
3173 | /* error checking.. meh */ | ||
3174 | p->name = eina_stringshare_add(pi->name); | ||
3175 | p->type = pi->type; | ||
3176 | switch(p->type) | ||
3177 | { | ||
3178 | case EDJE_EXTERNAL_PARAM_TYPE_INT: | ||
3179 | case EDJE_EXTERNAL_PARAM_TYPE_BOOL: | ||
3180 | if (pi->info.i.def != EDJE_EXTERNAL_INT_UNSET) | ||
3181 | p->i = pi->info.i.def; | ||
3182 | break; | ||
3183 | case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: | ||
3184 | if (pi->info.d.def != EDJE_EXTERNAL_DOUBLE_UNSET) | ||
3185 | p->d = pi->info.d.def; | ||
3186 | break; | ||
3187 | case EDJE_EXTERNAL_PARAM_TYPE_CHOICE: | ||
3188 | if (pi->info.c.def) | ||
3189 | p->s = eina_stringshare_add(pi->info.c.def); | ||
3190 | break; | ||
3191 | case EDJE_EXTERNAL_PARAM_TYPE_STRING: | ||
3192 | if (pi->info.s.def) | ||
3193 | p->s = eina_stringshare_add(pi->info.s.def); | ||
3194 | break; | ||
3195 | default: | ||
3196 | ERR("unknown external parameter type '%d'", p->type); | ||
3197 | } | ||
3198 | external->external_params = eina_list_append(external->external_params, p); | ||
3199 | pi++; | ||
3200 | } | ||
3201 | if (external->external_params) | ||
3202 | rp->param1.external_params = _edje_external_params_parse(rp->swallowed_object, external->external_params); | ||
3203 | } | ||
3204 | } | ||
3205 | else if (rp->part->type == EDJE_PART_TYPE_BOX) | ||
3206 | { | ||
3207 | Edje_Part_Description_Box *box; | ||
3208 | |||
3209 | box = (Edje_Part_Description_Box*) pd; | ||
3210 | memset(&box->box, 0, sizeof (box->box)); | ||
3211 | } | ||
3212 | else if (rp->part->type == EDJE_PART_TYPE_TABLE) | ||
3213 | { | ||
3214 | Edje_Part_Description_Table *table; | ||
3215 | |||
3216 | table = (Edje_Part_Description_Table*) pd; | ||
3217 | memset(&table->table, 0, sizeof (table->table)); | ||
3218 | } | ||
3219 | |||
3220 | return EINA_TRUE; | ||
3221 | } | ||
3222 | |||
3223 | EAPI Eina_Bool | ||
3224 | edje_edit_state_exist(Evas_Object *obj, const char *part, const char *state, double value) | ||
3225 | { | ||
3226 | eina_error_set(0); | ||
3227 | |||
3228 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3229 | return EINA_TRUE; | ||
3230 | } | ||
3231 | |||
3232 | EAPI Eina_Bool | ||
3233 | edje_edit_state_copy(Evas_Object *obj, const char *part, const char *from, double val_from, const char *to, double val_to) | ||
3234 | { | ||
3235 | Edje_Part_Description_Common *pdfrom, *pdto; | ||
3236 | Edje_External_Param *p; | ||
3237 | |||
3238 | eina_error_set(0); | ||
3239 | |||
3240 | GET_RP_OR_RETURN(EINA_FALSE); | ||
3241 | |||
3242 | pdfrom = _edje_part_description_find_byname(eed, part, from, val_from); | ||
3243 | if (!pdfrom) | ||
3244 | return EINA_FALSE; | ||
3245 | |||
3246 | pdto = _edje_part_description_find_byname(eed, part, to, val_to); | ||
3247 | if (!pdto) | ||
3248 | { | ||
3249 | Edje_Part_Description_Common **tmp; | ||
3250 | |||
3251 | pdto = _edje_edit_state_alloc(rp->part->type, ed); | ||
3252 | if (!pdto) return EINA_FALSE; | ||
3253 | /* No need to check for default desc, at this point it must exist */ | ||
3254 | |||
3255 | tmp = realloc(rp->part->other.desc, | ||
3256 | sizeof (Edje_Part_Description_Common *) * (rp->part->other.desc_count + 1)); | ||
3257 | if (!tmp) | ||
3258 | { | ||
3259 | free(pdto); | ||
3260 | return EINA_FALSE; | ||
3261 | } | ||
3262 | rp->part->other.desc = tmp; | ||
3263 | rp->part->other.desc[rp->part->other.desc_count++] = pdto; | ||
3264 | } | ||
3265 | |||
3266 | #define PD_STRING_COPY(To, From, _x) \ | ||
3267 | _edje_if_string_free(ed, To->_x); \ | ||
3268 | To->_x = (char *)eina_stringshare_add(From->_x); | ||
3269 | |||
3270 | /* Copy all value */ | ||
3271 | *pdto = *pdfrom; | ||
3272 | /* Keeping the pdto state name and value */ | ||
3273 | pdto->state.name = eina_stringshare_add(to); | ||
3274 | pdto->state.value = val_to; | ||
3275 | /* Update pointer. */ | ||
3276 | PD_STRING_COPY(pdto, pdfrom, color_class); | ||
3277 | |||
3278 | switch (rp->part->type) | ||
3279 | { | ||
3280 | case EDJE_PART_TYPE_PROXY: | ||
3281 | { | ||
3282 | Edje_Part_Description_Proxy *pro_to = (Edje_Part_Description_Proxy*) pdto; | ||
3283 | Edje_Part_Description_Proxy *pro_from = (Edje_Part_Description_Proxy*) pdfrom; | ||
3284 | |||
3285 | pro_to->proxy = pro_from->proxy; | ||
3286 | |||
3287 | break; | ||
3288 | } | ||
3289 | case EDJE_PART_TYPE_IMAGE: | ||
3290 | { | ||
3291 | Edje_Part_Description_Image *img_to = (Edje_Part_Description_Image*) pdto; | ||
3292 | Edje_Part_Description_Image *img_from = (Edje_Part_Description_Image*) pdfrom; | ||
3293 | unsigned int i; | ||
3294 | |||
3295 | img_to->image = img_from->image; | ||
3296 | |||
3297 | /* Update pointers. */ | ||
3298 | for (i = 0; i < img_to->image.tweens_count; ++i) | ||
3299 | free(img_to->image.tweens[i]); | ||
3300 | if (img_to->image.tweens_count > 0) | ||
3301 | free(img_to->image.tweens); | ||
3302 | |||
3303 | img_to->image.tweens_count = img_from->image.tweens_count; | ||
3304 | img_to->image.tweens = calloc(img_to->image.tweens_count, | ||
3305 | sizeof (Edje_Part_Image_Id*)); | ||
3306 | if (!img_to->image.tweens) | ||
3307 | break; | ||
3308 | |||
3309 | for (i = 0; i < img_to->image.tweens_count; ++i) | ||
3310 | { | ||
3311 | Edje_Part_Image_Id *new_i; | ||
3312 | new_i = _alloc(sizeof(Edje_Part_Image_Id)); | ||
3313 | if (!new_i) continue ; | ||
3314 | |||
3315 | *new_i = *img_from->image.tweens[i]; | ||
3316 | |||
3317 | img_to->image.tweens[i] = new_i; | ||
3318 | } | ||
3319 | break; | ||
3320 | } | ||
3321 | case EDJE_PART_TYPE_TEXT: | ||
3322 | case EDJE_PART_TYPE_TEXTBLOCK: | ||
3323 | { | ||
3324 | Edje_Part_Description_Text *text_to = (Edje_Part_Description_Text*) pdto; | ||
3325 | Edje_Part_Description_Text *text_from = (Edje_Part_Description_Text*) pdfrom; | ||
3326 | |||
3327 | text_to->text = text_from->text; | ||
3328 | |||
3329 | /* Update pointers. */ | ||
3330 | PD_STRING_COPY(text_to, text_from, text.text.str); | ||
3331 | PD_STRING_COPY(text_to, text_from, text.text_class); | ||
3332 | PD_STRING_COPY(text_to, text_from, text.style.str); | ||
3333 | PD_STRING_COPY(text_to, text_from, text.font.str); | ||
3334 | PD_STRING_COPY(text_to, text_from, text.repch.str); | ||
3335 | break; | ||
3336 | } | ||
3337 | case EDJE_PART_TYPE_BOX: | ||
3338 | { | ||
3339 | Edje_Part_Description_Box *box_to = (Edje_Part_Description_Box*) pdto; | ||
3340 | Edje_Part_Description_Box *box_from = (Edje_Part_Description_Box*) pdfrom; | ||
3341 | |||
3342 | box_to->box = box_from->box; | ||
3343 | |||
3344 | PD_STRING_COPY(box_to, box_from, box.layout); | ||
3345 | PD_STRING_COPY(box_to, box_from, box.alt_layout); | ||
3346 | break; | ||
3347 | } | ||
3348 | case EDJE_PART_TYPE_TABLE: | ||
3349 | { | ||
3350 | Edje_Part_Description_Table *table_to = (Edje_Part_Description_Table*) pdto; | ||
3351 | Edje_Part_Description_Table *table_from = (Edje_Part_Description_Table*) pdfrom; | ||
3352 | |||
3353 | table_to->table = table_from->table; | ||
3354 | break; | ||
3355 | } | ||
3356 | case EDJE_PART_TYPE_EXTERNAL: | ||
3357 | { | ||
3358 | Edje_Part_Description_External *ext_to = (Edje_Part_Description_External*) pdto; | ||
3359 | Edje_Part_Description_External *ext_from = (Edje_Part_Description_External*) pdfrom; | ||
3360 | Eina_List *l; | ||
3361 | |||
3362 | /* XXX: optimize this, most likely we don't need to remove and add */ | ||
3363 | EINA_LIST_FREE(ext_to->external_params, p) | ||
3364 | { | ||
3365 | _edje_if_string_free(ed, p->name); | ||
3366 | if (p->s) | ||
3367 | _edje_if_string_free(ed, p->s); | ||
3368 | free(p); | ||
3369 | } | ||
3370 | EINA_LIST_FOREACH(ext_from->external_params, l, p) | ||
3371 | { | ||
3372 | Edje_External_Param *new_p; | ||
3373 | new_p = _alloc(sizeof(Edje_External_Param)); | ||
3374 | new_p->name = eina_stringshare_add(p->name); | ||
3375 | new_p->type = p->type; | ||
3376 | switch (p->type) | ||
3377 | { | ||
3378 | case EDJE_EXTERNAL_PARAM_TYPE_INT: | ||
3379 | new_p->i = p->i; | ||
3380 | break; | ||
3381 | case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: | ||
3382 | new_p->d = p->d; | ||
3383 | break; | ||
3384 | case EDJE_EXTERNAL_PARAM_TYPE_CHOICE: | ||
3385 | case EDJE_EXTERNAL_PARAM_TYPE_STRING: | ||
3386 | new_p->s = eina_stringshare_add(p->s); | ||
3387 | break; | ||
3388 | default: | ||
3389 | break; | ||
3390 | } | ||
3391 | ext_to->external_params = eina_list_append(ext_to->external_params, new_p); | ||
3392 | } | ||
3393 | break; | ||
3394 | } | ||
3395 | } | ||
3396 | |||
3397 | #undef PD_STRING_COPY | ||
3398 | |||
3399 | return EINA_TRUE; | ||
3400 | } | ||
3401 | |||
3402 | #define FUNC_STATE_RELATIVE_DOUBLE(Sub, Value) \ | ||
3403 | EAPI double \ | ||
3404 | edje_edit_state_##Sub##_relative_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3405 | { \ | ||
3406 | eina_error_set(0); \ | ||
3407 | GET_PD_OR_RETURN(0); \ | ||
3408 | return TO_DOUBLE(pd->Sub.relative_##Value); \ | ||
3409 | } \ | ||
3410 | EAPI void \ | ||
3411 | edje_edit_state_##Sub##_relative_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
3412 | { \ | ||
3413 | eina_error_set(0); \ | ||
3414 | GET_PD_OR_RETURN(); \ | ||
3415 | pd->Sub.relative_##Value = FROM_DOUBLE(v); \ | ||
3416 | edje_object_calc_force(obj); \ | ||
3417 | } | ||
3418 | |||
3419 | FUNC_STATE_RELATIVE_DOUBLE(rel1, x); | ||
3420 | FUNC_STATE_RELATIVE_DOUBLE(rel1, y); | ||
3421 | FUNC_STATE_RELATIVE_DOUBLE(rel2, x); | ||
3422 | FUNC_STATE_RELATIVE_DOUBLE(rel2, y); | ||
3423 | |||
3424 | #define FUNC_STATE_OFFSET_INT(Sub, Value) \ | ||
3425 | EAPI int \ | ||
3426 | edje_edit_state_##Sub##_offset_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3427 | { \ | ||
3428 | eina_error_set(0); \ | ||
3429 | GET_PD_OR_RETURN(0); \ | ||
3430 | return pd->Sub.offset_##Value; \ | ||
3431 | } \ | ||
3432 | EAPI void \ | ||
3433 | edje_edit_state_##Sub##_offset_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
3434 | { \ | ||
3435 | eina_error_set(0); \ | ||
3436 | GET_PD_OR_RETURN(); \ | ||
3437 | pd->Sub.offset_##Value = TO_INT(FROM_DOUBLE(v)); \ | ||
3438 | edje_object_calc_force(obj); \ | ||
3439 | } | ||
3440 | |||
3441 | FUNC_STATE_OFFSET_INT(rel1, x); | ||
3442 | FUNC_STATE_OFFSET_INT(rel1, y); | ||
3443 | FUNC_STATE_OFFSET_INT(rel2, x); | ||
3444 | FUNC_STATE_OFFSET_INT(rel2, y); | ||
3445 | |||
3446 | #define FUNC_STATE_REL(Sub, Value) \ | ||
3447 | EAPI const char * \ | ||
3448 | edje_edit_state_##Sub##_to_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3449 | { \ | ||
3450 | Edje_Real_Part *rel; \ | ||
3451 | \ | ||
3452 | eina_error_set(0); \ | ||
3453 | \ | ||
3454 | GET_PD_OR_RETURN(NULL); \ | ||
3455 | \ | ||
3456 | if (pd->Sub.id_##Value == -1) return NULL; \ | ||
3457 | \ | ||
3458 | rel = ed->table_parts[pd->Sub.id_##Value % ed->table_parts_size]; \ | ||
3459 | \ | ||
3460 | if (rel->part->name) return eina_stringshare_add(rel->part->name); \ | ||
3461 | return NULL; \ | ||
3462 | } \ | ||
3463 | EAPI void \ | ||
3464 | edje_edit_state_##Sub##_to_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, const char *to) \ | ||
3465 | { \ | ||
3466 | Edje_Real_Part *relp; \ | ||
3467 | \ | ||
3468 | eina_error_set(0); \ | ||
3469 | \ | ||
3470 | GET_PD_OR_RETURN(); \ | ||
3471 | \ | ||
3472 | if (to) \ | ||
3473 | { \ | ||
3474 | relp = _edje_real_part_get(ed, to); \ | ||
3475 | if (!relp) return; \ | ||
3476 | pd->Sub.id_##Value = relp->part->id; \ | ||
3477 | } \ | ||
3478 | else \ | ||
3479 | pd->Sub.id_##Value = -1; \ | ||
3480 | \ | ||
3481 | } | ||
3482 | //note after this call edje_edit_part_selected_state_set() to update !! need to fix this | ||
3483 | //_edje_part_description_apply(ed, rp, pd->state.name, pd->state.value, "state", 0.1); //Why segfault?? | ||
3484 | // edje_object_calc_force(obj);//don't work for redraw | ||
3485 | |||
3486 | FUNC_STATE_REL(rel1, x); | ||
3487 | FUNC_STATE_REL(rel1, y); | ||
3488 | FUNC_STATE_REL(rel2, x); | ||
3489 | FUNC_STATE_REL(rel2, y); | ||
3490 | |||
3491 | //colors | ||
3492 | #define FUNC_COLOR(Code) \ | ||
3493 | EAPI void \ | ||
3494 | edje_edit_state_##Code##_get(Evas_Object *obj, const char *part, const char *state, double value, int *r, int *g, int *b, int *a) \ | ||
3495 | { \ | ||
3496 | eina_error_set(0); \ | ||
3497 | GET_PD_OR_RETURN(); \ | ||
3498 | \ | ||
3499 | if (r) *r = pd->Code.r; \ | ||
3500 | if (g) *g = pd->Code.g; \ | ||
3501 | if (b) *b = pd->Code.b; \ | ||
3502 | if (a) *a = pd->Code.a; \ | ||
3503 | } \ | ||
3504 | EAPI void \ | ||
3505 | edje_edit_state_##Code##_set(Evas_Object *obj, const char *part, const char *state, double value, int r, int g, int b, int a) \ | ||
3506 | { \ | ||
3507 | eina_error_set(0); \ | ||
3508 | GET_PD_OR_RETURN(); \ | ||
3509 | \ | ||
3510 | if (r > -1 && r < 256) pd->Code.r = r; \ | ||
3511 | if (g > -1 && g < 256) pd->Code.g = g; \ | ||
3512 | if (b > -1 && b < 256) pd->Code.b = b; \ | ||
3513 | if (a > -1 && a < 256) pd->Code.a = a; \ | ||
3514 | \ | ||
3515 | edje_object_calc_force(obj); \ | ||
3516 | } | ||
3517 | |||
3518 | FUNC_COLOR(color); | ||
3519 | FUNC_COLOR(color2); | ||
3520 | |||
3521 | EAPI void | ||
3522 | edje_edit_state_color3_get(Evas_Object *obj, const char *part, const char *state, double value, int *r, int *g, int *b, int *a) | ||
3523 | { | ||
3524 | Edje_Part_Description_Text *txt; | ||
3525 | |||
3526 | eina_error_set(0); | ||
3527 | |||
3528 | GET_PD_OR_RETURN(); | ||
3529 | |||
3530 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
3531 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
3532 | { | ||
3533 | if (r) *r = 0; | ||
3534 | if (g) *g = 0; | ||
3535 | if (b) *b = 0; | ||
3536 | if (a) *a = 0; | ||
3537 | return; | ||
3538 | } | ||
3539 | |||
3540 | txt = (Edje_Part_Description_Text*) pd; | ||
3541 | |||
3542 | if (r) *r = txt->text.color3.r; | ||
3543 | if (g) *g = txt->text.color3.g; | ||
3544 | if (b) *b = txt->text.color3.b; | ||
3545 | if (a) *a = txt->text.color3.a; | ||
3546 | } | ||
3547 | |||
3548 | EAPI void | ||
3549 | edje_edit_state_color3_set(Evas_Object *obj, const char *part, const char *state, double value, int r, int g, int b, int a) | ||
3550 | { | ||
3551 | Edje_Part_Description_Text *txt; | ||
3552 | |||
3553 | eina_error_set(0); | ||
3554 | |||
3555 | GET_PD_OR_RETURN(); | ||
3556 | |||
3557 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
3558 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
3559 | return; | ||
3560 | |||
3561 | txt = (Edje_Part_Description_Text*) pd; | ||
3562 | |||
3563 | if (r > -1 && r < 256) txt->text.color3.r = r; | ||
3564 | if (g > -1 && g < 256) txt->text.color3.g = g; | ||
3565 | if (b > -1 && b < 256) txt->text.color3.b = b; | ||
3566 | if (a > -1 && a < 256) txt->text.color3.a = a; | ||
3567 | |||
3568 | edje_object_calc_force(obj); | ||
3569 | } | ||
3570 | |||
3571 | #define FUNC_STATE_DOUBLE(Class, Value) \ | ||
3572 | EAPI double \ | ||
3573 | edje_edit_state_##Class##_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3574 | { \ | ||
3575 | eina_error_set(0); \ | ||
3576 | GET_PD_OR_RETURN(0); \ | ||
3577 | return TO_DOUBLE(pd->Class.Value); \ | ||
3578 | } \ | ||
3579 | EAPI void \ | ||
3580 | edje_edit_state_##Class##_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
3581 | { \ | ||
3582 | eina_error_set(0); \ | ||
3583 | GET_PD_OR_RETURN(); \ | ||
3584 | pd->Class.Value = FROM_DOUBLE(v); \ | ||
3585 | edje_object_calc_force(obj); \ | ||
3586 | } | ||
3587 | |||
3588 | #define FUNC_STATE_INT(Class, Value) \ | ||
3589 | EAPI int \ | ||
3590 | edje_edit_state_##Class##_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3591 | { \ | ||
3592 | eina_error_set(0); \ | ||
3593 | GET_PD_OR_RETURN(0); \ | ||
3594 | return pd->Class.Value; \ | ||
3595 | } \ | ||
3596 | EAPI void \ | ||
3597 | edje_edit_state_##Class##_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, int v) \ | ||
3598 | { \ | ||
3599 | eina_error_set(0); \ | ||
3600 | GET_PD_OR_RETURN(); \ | ||
3601 | pd->Class.Value = v; \ | ||
3602 | edje_object_calc_force(obj); \ | ||
3603 | } | ||
3604 | |||
3605 | FUNC_STATE_DOUBLE(align, x); | ||
3606 | FUNC_STATE_DOUBLE(align, y); | ||
3607 | FUNC_STATE_INT(min, w); | ||
3608 | FUNC_STATE_INT(min, h); | ||
3609 | FUNC_STATE_INT(max, w); | ||
3610 | FUNC_STATE_INT(max, h); | ||
3611 | FUNC_STATE_DOUBLE(aspect, min); | ||
3612 | FUNC_STATE_DOUBLE(aspect, max); | ||
3613 | |||
3614 | #define FUNC_STATE_DOUBLE_FILL(Class, Type, Value) \ | ||
3615 | EAPI double \ | ||
3616 | edje_edit_state_fill_##Type##_relative_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3617 | { \ | ||
3618 | eina_error_set(0); \ | ||
3619 | \ | ||
3620 | GET_PD_OR_RETURN(0); \ | ||
3621 | \ | ||
3622 | switch (rp->part->type) \ | ||
3623 | { \ | ||
3624 | case EDJE_PART_TYPE_IMAGE: \ | ||
3625 | { \ | ||
3626 | Edje_Part_Description_Image *img; \ | ||
3627 | \ | ||
3628 | img = (Edje_Part_Description_Image*) pd; \ | ||
3629 | \ | ||
3630 | return TO_DOUBLE(img->image.fill.Class##rel_##Value); \ | ||
3631 | } \ | ||
3632 | case EDJE_PART_TYPE_PROXY: \ | ||
3633 | { \ | ||
3634 | Edje_Part_Description_Proxy *pro; \ | ||
3635 | \ | ||
3636 | pro = (Edje_Part_Description_Proxy*) pd; \ | ||
3637 | \ | ||
3638 | return TO_DOUBLE(pro->proxy.fill.Class##rel_##Value); \ | ||
3639 | } \ | ||
3640 | } \ | ||
3641 | \ | ||
3642 | return 0; \ | ||
3643 | } \ | ||
3644 | EAPI void \ | ||
3645 | edje_edit_state_fill_##Type##_relative_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
3646 | { \ | ||
3647 | eina_error_set(0); \ | ||
3648 | \ | ||
3649 | GET_PD_OR_RETURN(); \ | ||
3650 | \ | ||
3651 | switch (rp->part->type) \ | ||
3652 | { \ | ||
3653 | case EDJE_PART_TYPE_IMAGE: \ | ||
3654 | { \ | ||
3655 | Edje_Part_Description_Image *img; \ | ||
3656 | \ | ||
3657 | img = (Edje_Part_Description_Image*) pd; \ | ||
3658 | \ | ||
3659 | img->image.fill.Class##rel_##Value = FROM_DOUBLE(v); \ | ||
3660 | \ | ||
3661 | break; \ | ||
3662 | } \ | ||
3663 | case EDJE_PART_TYPE_PROXY: \ | ||
3664 | { \ | ||
3665 | Edje_Part_Description_Proxy *pro; \ | ||
3666 | \ | ||
3667 | pro = (Edje_Part_Description_Proxy*) pd; \ | ||
3668 | \ | ||
3669 | pro->proxy.fill.Class##rel_##Value = FROM_DOUBLE(v); \ | ||
3670 | \ | ||
3671 | break; \ | ||
3672 | } \ | ||
3673 | default: \ | ||
3674 | return; \ | ||
3675 | } \ | ||
3676 | \ | ||
3677 | edje_object_calc_force(obj); \ | ||
3678 | } | ||
3679 | |||
3680 | #define FUNC_STATE_INT_FILL(Class, Type, Value) \ | ||
3681 | EAPI int \ | ||
3682 | edje_edit_state_fill_##Type##_offset_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
3683 | { \ | ||
3684 | eina_error_set(0); \ | ||
3685 | \ | ||
3686 | GET_PD_OR_RETURN(0); \ | ||
3687 | \ | ||
3688 | switch (rp->part->type) \ | ||
3689 | { \ | ||
3690 | case EDJE_PART_TYPE_IMAGE: \ | ||
3691 | { \ | ||
3692 | Edje_Part_Description_Image *img; \ | ||
3693 | \ | ||
3694 | img = (Edje_Part_Description_Image*) pd; \ | ||
3695 | \ | ||
3696 | return img->image.fill.Class##abs_##Value; \ | ||
3697 | } \ | ||
3698 | case EDJE_PART_TYPE_PROXY: \ | ||
3699 | { \ | ||
3700 | Edje_Part_Description_Proxy *pro; \ | ||
3701 | \ | ||
3702 | pro = (Edje_Part_Description_Proxy*) pd; \ | ||
3703 | \ | ||
3704 | return pro->proxy.fill.Class##abs_##Value; \ | ||
3705 | } \ | ||
3706 | } \ | ||
3707 | return 0; \ | ||
3708 | } \ | ||
3709 | EAPI void \ | ||
3710 | edje_edit_state_fill_##Type##_offset_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
3711 | { \ | ||
3712 | eina_error_set(0); \ | ||
3713 | \ | ||
3714 | GET_PD_OR_RETURN(); \ | ||
3715 | \ | ||
3716 | switch (rp->part->type) \ | ||
3717 | { \ | ||
3718 | case EDJE_PART_TYPE_IMAGE: \ | ||
3719 | { \ | ||
3720 | Edje_Part_Description_Image *img; \ | ||
3721 | \ | ||
3722 | img = (Edje_Part_Description_Image*) pd; \ | ||
3723 | \ | ||
3724 | img->image.fill.Class##abs_##Value = FROM_DOUBLE(v); \ | ||
3725 | return; \ | ||
3726 | } \ | ||
3727 | case EDJE_PART_TYPE_PROXY: \ | ||
3728 | { \ | ||
3729 | Edje_Part_Description_Proxy *pro; \ | ||
3730 | \ | ||
3731 | pro = (Edje_Part_Description_Proxy*) pd; \ | ||
3732 | \ | ||
3733 | pro->proxy.fill.Class##abs_##Value = FROM_DOUBLE(v); \ | ||
3734 | return; \ | ||
3735 | } \ | ||
3736 | default: \ | ||
3737 | return; \ | ||
3738 | } \ | ||
3739 | \ | ||
3740 | edje_object_calc_force(obj); \ | ||
3741 | } | ||
3742 | |||
3743 | FUNC_STATE_DOUBLE_FILL(pos_, origin, x); | ||
3744 | FUNC_STATE_DOUBLE_FILL(pos_, origin, y); | ||
3745 | FUNC_STATE_INT_FILL(pos_, origin, x); | ||
3746 | FUNC_STATE_INT_FILL(pos_, origin, y); | ||
3747 | |||
3748 | FUNC_STATE_DOUBLE_FILL(, size, x); | ||
3749 | FUNC_STATE_DOUBLE_FILL(, size, y); | ||
3750 | FUNC_STATE_INT_FILL(, size, x); | ||
3751 | FUNC_STATE_INT_FILL(, size, y); | ||
3752 | |||
3753 | EAPI Eina_Bool | ||
3754 | edje_edit_state_visible_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
3755 | { | ||
3756 | eina_error_set(0); | ||
3757 | |||
3758 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3759 | |||
3760 | //printf("Get state visible flag of part: %s state: %s\n", part, state); | ||
3761 | return pd->visible; | ||
3762 | } | ||
3763 | |||
3764 | EAPI void | ||
3765 | edje_edit_state_visible_set(Evas_Object *obj, const char *part, const char *state, double value, Eina_Bool visible) | ||
3766 | { | ||
3767 | eina_error_set(0); | ||
3768 | |||
3769 | GET_PD_OR_RETURN(); | ||
3770 | //printf("Set state visible flag of part: %s state: %s to: %d\n", part, state, visible); | ||
3771 | if (visible) pd->visible = 1; | ||
3772 | else pd->visible = 0; | ||
3773 | edje_object_calc_force(obj); | ||
3774 | } | ||
3775 | |||
3776 | EAPI unsigned char | ||
3777 | edje_edit_state_aspect_pref_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
3778 | { | ||
3779 | eina_error_set(0); | ||
3780 | |||
3781 | GET_PD_OR_RETURN(0); | ||
3782 | |||
3783 | //printf("GET ASPECT_PREF of state '%s' [%d]\n", state, pd->aspect.prefer); | ||
3784 | return pd->aspect.prefer; | ||
3785 | } | ||
3786 | |||
3787 | EAPI void | ||
3788 | edje_edit_state_aspect_pref_set(Evas_Object *obj, const char *part, const char *state, double value, unsigned char pref) | ||
3789 | { | ||
3790 | eina_error_set(0); | ||
3791 | |||
3792 | GET_PD_OR_RETURN(); | ||
3793 | |||
3794 | //printf("SET ASPECT_PREF of state '%s' [to: %d]\n", state, pref); | ||
3795 | pd->aspect.prefer = pref; | ||
3796 | } | ||
3797 | |||
3798 | EAPI const char* | ||
3799 | edje_edit_state_color_class_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
3800 | { | ||
3801 | eina_error_set(0); | ||
3802 | |||
3803 | GET_PD_OR_RETURN(NULL); | ||
3804 | //printf("Get ColorClass of part: %s state: %s\n", part, state); | ||
3805 | return eina_stringshare_add(pd->color_class); | ||
3806 | } | ||
3807 | |||
3808 | EAPI void | ||
3809 | edje_edit_state_color_class_set(Evas_Object *obj, const char *part, const char *state, double value, const char *color_class) | ||
3810 | { | ||
3811 | eina_error_set(0); | ||
3812 | |||
3813 | GET_PD_OR_RETURN(); | ||
3814 | //printf("Set ColorClass of part: %s state: %s [to: %s]\n", part, state, color_class); | ||
3815 | _edje_if_string_free(ed, pd->color_class); | ||
3816 | pd->color_class = (char*)eina_stringshare_add(color_class); | ||
3817 | } | ||
3818 | |||
3819 | EAPI const Eina_List * | ||
3820 | edje_edit_state_external_params_list_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
3821 | { | ||
3822 | Edje_Part_Description_External *external; | ||
3823 | |||
3824 | eina_error_set(0); | ||
3825 | |||
3826 | GET_PD_OR_RETURN(NULL); | ||
3827 | |||
3828 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3829 | return NULL; | ||
3830 | |||
3831 | external = (Edje_Part_Description_External *) pd; | ||
3832 | |||
3833 | return external->external_params; | ||
3834 | } | ||
3835 | |||
3836 | EAPI Eina_Bool | ||
3837 | edje_edit_state_external_param_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, Edje_External_Param_Type *type, void **val) | ||
3838 | { | ||
3839 | Edje_Part_Description_External *external; | ||
3840 | Edje_External_Param *p; | ||
3841 | Eina_List *l; | ||
3842 | |||
3843 | eina_error_set(0); | ||
3844 | |||
3845 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3846 | |||
3847 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3848 | return EINA_FALSE; | ||
3849 | |||
3850 | external = (Edje_Part_Description_External *) pd; | ||
3851 | |||
3852 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
3853 | if (!strcmp(p->name, param)) | ||
3854 | { | ||
3855 | if (type) *type = p->type; | ||
3856 | if (val) | ||
3857 | switch (p->type) | ||
3858 | { | ||
3859 | case EDJE_EXTERNAL_PARAM_TYPE_INT: | ||
3860 | case EDJE_EXTERNAL_PARAM_TYPE_BOOL: | ||
3861 | *val = &p->i; | ||
3862 | break; | ||
3863 | case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: | ||
3864 | *val = &p->d; | ||
3865 | break; | ||
3866 | case EDJE_EXTERNAL_PARAM_TYPE_CHOICE: | ||
3867 | case EDJE_EXTERNAL_PARAM_TYPE_STRING: | ||
3868 | *val = (void *)p->s; | ||
3869 | break; | ||
3870 | default: | ||
3871 | ERR("unknown external parameter type '%d'", p->type); | ||
3872 | } | ||
3873 | return EINA_TRUE; | ||
3874 | } | ||
3875 | |||
3876 | return EINA_FALSE; | ||
3877 | } | ||
3878 | |||
3879 | EAPI Eina_Bool | ||
3880 | edje_edit_state_external_param_int_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, int *val) | ||
3881 | { | ||
3882 | Edje_Part_Description_External *external; | ||
3883 | Edje_External_Param *p; | ||
3884 | Eina_List *l; | ||
3885 | |||
3886 | eina_error_set(0); | ||
3887 | |||
3888 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3889 | |||
3890 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3891 | { | ||
3892 | if (val) *val = 0; | ||
3893 | return EINA_FALSE; | ||
3894 | } | ||
3895 | |||
3896 | external = (Edje_Part_Description_External *) pd; | ||
3897 | |||
3898 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
3899 | if (!strcmp(p->name, param)) | ||
3900 | { | ||
3901 | if (p->type != EDJE_EXTERNAL_PARAM_TYPE_INT) | ||
3902 | return EINA_FALSE; | ||
3903 | if (val) | ||
3904 | *val = p->i; | ||
3905 | return EINA_TRUE; | ||
3906 | } | ||
3907 | |||
3908 | return EINA_FALSE; | ||
3909 | } | ||
3910 | |||
3911 | EAPI Eina_Bool | ||
3912 | edje_edit_state_external_param_bool_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, Eina_Bool *val) | ||
3913 | { | ||
3914 | Edje_Part_Description_External *external; | ||
3915 | Edje_External_Param *p; | ||
3916 | Eina_List *l; | ||
3917 | |||
3918 | eina_error_set(0); | ||
3919 | |||
3920 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3921 | |||
3922 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3923 | { | ||
3924 | if (val) *val = 0; | ||
3925 | return EINA_FALSE; | ||
3926 | } | ||
3927 | |||
3928 | external = (Edje_Part_Description_External *) pd; | ||
3929 | |||
3930 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
3931 | if (!strcmp(p->name, param)) | ||
3932 | { | ||
3933 | if (p->type != EDJE_EXTERNAL_PARAM_TYPE_BOOL) | ||
3934 | return EINA_FALSE; | ||
3935 | if (val) | ||
3936 | *val = p->i; | ||
3937 | return EINA_TRUE; | ||
3938 | } | ||
3939 | |||
3940 | return EINA_FALSE; | ||
3941 | } | ||
3942 | |||
3943 | EAPI Eina_Bool | ||
3944 | edje_edit_state_external_param_double_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, double *val) | ||
3945 | { | ||
3946 | Edje_Part_Description_External *external; | ||
3947 | Edje_External_Param *p; | ||
3948 | Eina_List *l; | ||
3949 | |||
3950 | eina_error_set(0); | ||
3951 | |||
3952 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3953 | |||
3954 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3955 | { | ||
3956 | if (val) *val = 0; | ||
3957 | return EINA_FALSE; | ||
3958 | } | ||
3959 | |||
3960 | external = (Edje_Part_Description_External *) pd; | ||
3961 | |||
3962 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
3963 | if (!strcmp(p->name, param)) | ||
3964 | { | ||
3965 | if (p->type != EDJE_EXTERNAL_PARAM_TYPE_DOUBLE) | ||
3966 | return EINA_FALSE; | ||
3967 | if (val) | ||
3968 | *val = p->d; | ||
3969 | return EINA_TRUE; | ||
3970 | } | ||
3971 | |||
3972 | return EINA_FALSE; | ||
3973 | } | ||
3974 | |||
3975 | EAPI Eina_Bool | ||
3976 | edje_edit_state_external_param_string_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, const char **val) | ||
3977 | { | ||
3978 | Edje_Part_Description_External *external; | ||
3979 | Edje_External_Param *p; | ||
3980 | Eina_List *l; | ||
3981 | |||
3982 | eina_error_set(0); | ||
3983 | |||
3984 | GET_PD_OR_RETURN(EINA_FALSE); | ||
3985 | |||
3986 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
3987 | { | ||
3988 | if (val) *val = NULL; | ||
3989 | return EINA_FALSE; | ||
3990 | } | ||
3991 | |||
3992 | external = (Edje_Part_Description_External *) pd; | ||
3993 | |||
3994 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
3995 | if (!strcmp(p->name, param)) | ||
3996 | { | ||
3997 | if (p->type != EDJE_EXTERNAL_PARAM_TYPE_STRING) | ||
3998 | return EINA_FALSE; | ||
3999 | if (val) | ||
4000 | *val = p->s; | ||
4001 | return EINA_TRUE; | ||
4002 | } | ||
4003 | |||
4004 | return EINA_FALSE; | ||
4005 | } | ||
4006 | |||
4007 | EAPI Eina_Bool | ||
4008 | edje_edit_state_external_param_choice_get(Evas_Object *obj, const char *part, const char *state, double value, const char *param, const char **val) | ||
4009 | { | ||
4010 | Edje_Part_Description_External *external; | ||
4011 | Edje_External_Param *p; | ||
4012 | Eina_List *l; | ||
4013 | |||
4014 | eina_error_set(0); | ||
4015 | |||
4016 | GET_PD_OR_RETURN(EINA_FALSE); | ||
4017 | |||
4018 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
4019 | { | ||
4020 | if (val) *val = NULL; | ||
4021 | return EINA_FALSE; | ||
4022 | } | ||
4023 | |||
4024 | external = (Edje_Part_Description_External *) pd; | ||
4025 | |||
4026 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
4027 | if (!strcmp(p->name, param)) | ||
4028 | { | ||
4029 | if (p->type != EDJE_EXTERNAL_PARAM_TYPE_CHOICE) | ||
4030 | return EINA_FALSE; | ||
4031 | if (val) | ||
4032 | *val = p->s; | ||
4033 | return EINA_TRUE; | ||
4034 | } | ||
4035 | |||
4036 | return EINA_FALSE; | ||
4037 | } | ||
4038 | |||
4039 | EAPI Eina_Bool | ||
4040 | edje_edit_state_external_param_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, Edje_External_Param_Type type, ...) | ||
4041 | { | ||
4042 | va_list ap; | ||
4043 | Eina_List *l; | ||
4044 | Edje_Part_Description_External *external; | ||
4045 | Edje_External_Param *p = NULL, old_p = { 0, 0, 0, 0, 0 }; | ||
4046 | int found = 0; | ||
4047 | |||
4048 | eina_error_set(0); | ||
4049 | |||
4050 | GET_PD_OR_RETURN(EINA_FALSE); | ||
4051 | |||
4052 | if (rp->part->type != EDJE_PART_TYPE_EXTERNAL) | ||
4053 | return EINA_FALSE; | ||
4054 | |||
4055 | external = (Edje_Part_Description_External *) pd; | ||
4056 | |||
4057 | va_start(ap, type); | ||
4058 | |||
4059 | EINA_LIST_FOREACH(external->external_params, l, p) | ||
4060 | if (!strcmp(p->name, param)) | ||
4061 | { | ||
4062 | found = 1; | ||
4063 | old_p = *p; | ||
4064 | break; | ||
4065 | } | ||
4066 | |||
4067 | if (!found) | ||
4068 | { | ||
4069 | p = _alloc(sizeof(Edje_External_Param)); | ||
4070 | if (!p) | ||
4071 | { | ||
4072 | va_end(ap); | ||
4073 | return EINA_FALSE; | ||
4074 | } | ||
4075 | p->name = eina_stringshare_add(param); | ||
4076 | } | ||
4077 | |||
4078 | p->type = type; | ||
4079 | p->i = 0; | ||
4080 | p->d = 0; | ||
4081 | _edje_if_string_free(ed, p->s); | ||
4082 | p->s = NULL; | ||
4083 | |||
4084 | switch (type) | ||
4085 | { | ||
4086 | case EDJE_EXTERNAL_PARAM_TYPE_INT: | ||
4087 | case EDJE_EXTERNAL_PARAM_TYPE_BOOL: | ||
4088 | p->i = (int)va_arg(ap, int); | ||
4089 | break; | ||
4090 | case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: | ||
4091 | p->d = (double)va_arg(ap, double); | ||
4092 | break; | ||
4093 | case EDJE_EXTERNAL_PARAM_TYPE_CHOICE: | ||
4094 | case EDJE_EXTERNAL_PARAM_TYPE_STRING: | ||
4095 | p->s = eina_stringshare_add((const char *)va_arg(ap, char *)); | ||
4096 | break; | ||
4097 | default: | ||
4098 | ERR("unknown external parameter type '%d'", type); | ||
4099 | va_end(ap); | ||
4100 | if (!found) free(p); | ||
4101 | else *p = old_p; | ||
4102 | return EINA_FALSE; | ||
4103 | } | ||
4104 | |||
4105 | va_end(ap); | ||
4106 | |||
4107 | //FIXME: | ||
4108 | //For now, we're just setting the value if the state is the selected state. | ||
4109 | //This is a conceptual error and is incoherent with the rest of the API! | ||
4110 | { | ||
4111 | const char *sname; | ||
4112 | double svalue; | ||
4113 | sname = edje_edit_part_selected_state_get(obj, part, &svalue); | ||
4114 | if (!strcmp(state, sname) && svalue == value) | ||
4115 | if (!edje_object_part_external_param_set(obj, part, p)) | ||
4116 | if ((type == EDJE_EXTERNAL_PARAM_TYPE_CHOICE) || | ||
4117 | (type == EDJE_EXTERNAL_PARAM_TYPE_STRING)) | ||
4118 | { | ||
4119 | _edje_if_string_free(ed, p->s); | ||
4120 | if (!found) free(p); | ||
4121 | else *p = old_p; | ||
4122 | eina_stringshare_del(sname); | ||
4123 | return EINA_FALSE; | ||
4124 | } | ||
4125 | eina_stringshare_del(sname); | ||
4126 | } | ||
4127 | |||
4128 | if (!found) | ||
4129 | external->external_params = eina_list_append(external->external_params, p); | ||
4130 | |||
4131 | _edje_external_parsed_params_free(rp->swallowed_object, | ||
4132 | rp->param1.external_params); | ||
4133 | rp->param1.external_params = \ | ||
4134 | _edje_external_params_parse(rp->swallowed_object, | ||
4135 | external->external_params); | ||
4136 | |||
4137 | |||
4138 | return EINA_TRUE; | ||
4139 | } | ||
4140 | |||
4141 | EAPI Eina_Bool | ||
4142 | edje_edit_state_external_param_int_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, int val) | ||
4143 | { | ||
4144 | eina_error_set(0); | ||
4145 | return edje_edit_state_external_param_set(obj, part, state, value, param, EDJE_EXTERNAL_PARAM_TYPE_INT, val); | ||
4146 | } | ||
4147 | |||
4148 | EAPI Eina_Bool | ||
4149 | edje_edit_state_external_param_bool_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, Eina_Bool val) | ||
4150 | { | ||
4151 | eina_error_set(0); | ||
4152 | return edje_edit_state_external_param_set(obj, part, state, value, param, EDJE_EXTERNAL_PARAM_TYPE_BOOL, (int)val); | ||
4153 | } | ||
4154 | |||
4155 | EAPI Eina_Bool | ||
4156 | edje_edit_state_external_param_double_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, double val) | ||
4157 | { | ||
4158 | eina_error_set(0); | ||
4159 | return edje_edit_state_external_param_set(obj, part, state, value, param, EDJE_EXTERNAL_PARAM_TYPE_DOUBLE, val); | ||
4160 | } | ||
4161 | |||
4162 | EAPI Eina_Bool | ||
4163 | edje_edit_state_external_param_string_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, const char *val) | ||
4164 | { | ||
4165 | eina_error_set(0); | ||
4166 | return edje_edit_state_external_param_set(obj, part, state, value, param, EDJE_EXTERNAL_PARAM_TYPE_STRING, val); | ||
4167 | } | ||
4168 | |||
4169 | EAPI Eina_Bool | ||
4170 | edje_edit_state_external_param_choice_set(Evas_Object *obj, const char *part, const char *state, double value, const char *param, const char *val) | ||
4171 | { | ||
4172 | eina_error_set(0); | ||
4173 | return edje_edit_state_external_param_set(obj, part, state, value, param, EDJE_EXTERNAL_PARAM_TYPE_CHOICE, val); | ||
4174 | } | ||
4175 | |||
4176 | /**************/ | ||
4177 | /* TEXT API */ | ||
4178 | /**************/ | ||
4179 | |||
4180 | EAPI const char * | ||
4181 | edje_edit_state_text_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
4182 | { | ||
4183 | Edje_Part_Description_Text *txt; | ||
4184 | |||
4185 | eina_error_set(0); | ||
4186 | |||
4187 | GET_PD_OR_RETURN(NULL); | ||
4188 | |||
4189 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4190 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4191 | return NULL; | ||
4192 | |||
4193 | txt = (Edje_Part_Description_Text *) pd; | ||
4194 | //printf("GET TEXT of state: %s\n", state); | ||
4195 | |||
4196 | return eina_stringshare_add(edje_string_get(&txt->text.text)); | ||
4197 | } | ||
4198 | |||
4199 | EAPI void | ||
4200 | edje_edit_state_text_set(Evas_Object *obj, const char *part, const char *state, double value, const char *text) | ||
4201 | { | ||
4202 | Edje_Part_Description_Text *txt; | ||
4203 | |||
4204 | eina_error_set(0); | ||
4205 | |||
4206 | GET_PD_OR_RETURN(); | ||
4207 | |||
4208 | //printf("SET TEXT of state: %s\n", state); | ||
4209 | |||
4210 | if (!text) return; | ||
4211 | |||
4212 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4213 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4214 | return; | ||
4215 | |||
4216 | txt = (Edje_Part_Description_Text *) pd; | ||
4217 | |||
4218 | _edje_if_string_free(ed, txt->text.text.str); | ||
4219 | txt->text.text.str = (char *)eina_stringshare_add(text); | ||
4220 | txt->text.text.id = 0; | ||
4221 | |||
4222 | edje_object_calc_force(obj); | ||
4223 | } | ||
4224 | |||
4225 | EAPI int | ||
4226 | edje_edit_state_text_size_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
4227 | { | ||
4228 | Edje_Part_Description_Text *txt; | ||
4229 | |||
4230 | eina_error_set(0); | ||
4231 | |||
4232 | GET_PD_OR_RETURN(-1); | ||
4233 | |||
4234 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4235 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4236 | return -1; | ||
4237 | |||
4238 | txt = (Edje_Part_Description_Text *) pd; | ||
4239 | //printf("GET TEXT_SIZE of state: %s [%d]\n", state, pd->text.size); | ||
4240 | return txt->text.size; | ||
4241 | } | ||
4242 | |||
4243 | EAPI void | ||
4244 | edje_edit_state_text_size_set(Evas_Object *obj, const char *part, const char *state, double value, int size) | ||
4245 | { | ||
4246 | Edje_Part_Description_Text *txt; | ||
4247 | |||
4248 | eina_error_set(0); | ||
4249 | |||
4250 | GET_PD_OR_RETURN(); | ||
4251 | |||
4252 | //printf("SET TEXT_SIZE of state: %s [%d]\n", state, size); | ||
4253 | |||
4254 | if (size < 0) return; | ||
4255 | |||
4256 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4257 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4258 | return; | ||
4259 | |||
4260 | txt = (Edje_Part_Description_Text *) pd; | ||
4261 | |||
4262 | txt->text.size = size; | ||
4263 | |||
4264 | edje_object_calc_force(obj); | ||
4265 | } | ||
4266 | |||
4267 | #define FUNC_TEXT_DOUBLE(Name, Value) \ | ||
4268 | EAPI double \ | ||
4269 | edje_edit_state_text_##Name##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
4270 | { \ | ||
4271 | Edje_Part_Description_Text *txt; \ | ||
4272 | \ | ||
4273 | eina_error_set(0); \ | ||
4274 | \ | ||
4275 | GET_PD_OR_RETURN(0); \ | ||
4276 | \ | ||
4277 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && \ | ||
4278 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) \ | ||
4279 | return 0; \ | ||
4280 | \ | ||
4281 | txt = (Edje_Part_Description_Text *) pd; \ | ||
4282 | return TO_DOUBLE(txt->text.Value); \ | ||
4283 | } \ | ||
4284 | EAPI void \ | ||
4285 | edje_edit_state_text_##Name##_set(Evas_Object *obj, const char *part, const char *state, double value, double v) \ | ||
4286 | { \ | ||
4287 | Edje_Part_Description_Text *txt; \ | ||
4288 | \ | ||
4289 | eina_error_set(0); \ | ||
4290 | \ | ||
4291 | GET_PD_OR_RETURN(); \ | ||
4292 | \ | ||
4293 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && \ | ||
4294 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) \ | ||
4295 | return; \ | ||
4296 | \ | ||
4297 | txt = (Edje_Part_Description_Text *) pd; \ | ||
4298 | txt->text.Value = FROM_DOUBLE(v); \ | ||
4299 | edje_object_calc_force(obj); \ | ||
4300 | } \ | ||
4301 | |||
4302 | FUNC_TEXT_DOUBLE(align_x, align.x); | ||
4303 | FUNC_TEXT_DOUBLE(align_y, align.y); | ||
4304 | FUNC_TEXT_DOUBLE(elipsis, elipsis); | ||
4305 | |||
4306 | #define FUNC_TEXT_BOOL_FIT(Value) \ | ||
4307 | EAPI Eina_Bool \ | ||
4308 | edje_edit_state_text_fit_##Value##_get(Evas_Object *obj, const char *part, const char *state, double value) \ | ||
4309 | { \ | ||
4310 | Edje_Part_Description_Text *txt; \ | ||
4311 | \ | ||
4312 | eina_error_set(0); \ | ||
4313 | \ | ||
4314 | GET_PD_OR_RETURN(EINA_FALSE); \ | ||
4315 | \ | ||
4316 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && \ | ||
4317 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) \ | ||
4318 | return EINA_FALSE; \ | ||
4319 | \ | ||
4320 | txt = (Edje_Part_Description_Text *) pd; \ | ||
4321 | return txt->text.fit_##Value; \ | ||
4322 | } \ | ||
4323 | EAPI void \ | ||
4324 | edje_edit_state_text_fit_##Value##_set(Evas_Object *obj, const char *part, const char *state, double value, Eina_Bool fit) \ | ||
4325 | { \ | ||
4326 | Edje_Part_Description_Text *txt; \ | ||
4327 | \ | ||
4328 | GET_PD_OR_RETURN(); \ | ||
4329 | \ | ||
4330 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && \ | ||
4331 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) \ | ||
4332 | return; \ | ||
4333 | \ | ||
4334 | txt = (Edje_Part_Description_Text *) pd; \ | ||
4335 | txt->text.fit_##Value = fit ? 1 : 0; \ | ||
4336 | edje_object_calc_force(obj); \ | ||
4337 | } | ||
4338 | |||
4339 | FUNC_TEXT_BOOL_FIT(x); | ||
4340 | FUNC_TEXT_BOOL_FIT(y); | ||
4341 | |||
4342 | EAPI Eina_List * | ||
4343 | edje_edit_fonts_list_get(Evas_Object *obj) | ||
4344 | { | ||
4345 | Eina_Iterator *it; | ||
4346 | Eina_List *fonts = NULL; | ||
4347 | Edje_Font_Directory_Entry *f; | ||
4348 | |||
4349 | eina_error_set(0); | ||
4350 | |||
4351 | GET_ED_OR_RETURN(NULL); | ||
4352 | |||
4353 | if (!ed->file || !ed->file->fonts) return NULL; | ||
4354 | |||
4355 | it = eina_hash_iterator_data_new(ed->file->fonts); | ||
4356 | if (!it) return NULL; | ||
4357 | |||
4358 | EINA_ITERATOR_FOREACH(it, f) | ||
4359 | fonts = eina_list_append(fonts, eina_stringshare_add(f->entry)); | ||
4360 | |||
4361 | eina_iterator_free(it); | ||
4362 | |||
4363 | return fonts; | ||
4364 | } | ||
4365 | |||
4366 | EAPI Eina_Bool | ||
4367 | edje_edit_font_add(Evas_Object *obj, const char* path, const char* alias) | ||
4368 | { | ||
4369 | char entry[PATH_MAX]; | ||
4370 | char *new_path; | ||
4371 | struct stat st; | ||
4372 | Edje_Font_Directory_Entry *fnt; | ||
4373 | |||
4374 | eina_error_set(0); | ||
4375 | |||
4376 | GET_ED_OR_RETURN(EINA_FALSE); | ||
4377 | |||
4378 | INF("ADD FONT: %s", path); | ||
4379 | |||
4380 | if (!path) return EINA_FALSE; | ||
4381 | if (stat(path, &st) || !S_ISREG(st.st_mode)) return EINA_FALSE; | ||
4382 | if (!ed->file) return EINA_FALSE; | ||
4383 | if (!ed->path) return EINA_FALSE; | ||
4384 | |||
4385 | /* Alias */ | ||
4386 | if (alias) | ||
4387 | { | ||
4388 | if ((new_path = strrchr(path, '/'))) new_path ++; | ||
4389 | else new_path = (char *)path; | ||
4390 | } | ||
4391 | else | ||
4392 | { | ||
4393 | if ((alias = strrchr(path, '/'))) alias ++; | ||
4394 | else alias = (char *)path; | ||
4395 | new_path = (char *)alias; | ||
4396 | } | ||
4397 | snprintf(entry, sizeof(entry), "edje/fonts/%s", alias); | ||
4398 | |||
4399 | /* Initializing a new font hash, if no exist */ | ||
4400 | if (!ed->file->fonts) | ||
4401 | { | ||
4402 | ed->file->fonts = eina_hash_string_small_new(NULL); | ||
4403 | if (!ed->file->fonts) return EINA_FALSE; | ||
4404 | } | ||
4405 | |||
4406 | /* Check if exists */ | ||
4407 | fnt = eina_hash_find(ed->file->fonts, alias); | ||
4408 | if (fnt) | ||
4409 | return EINA_FALSE; | ||
4410 | |||
4411 | /* Create Edje_Font_Directory_Entry */ | ||
4412 | fnt = _alloc(sizeof(Edje_Font_Directory_Entry)); | ||
4413 | if (!fnt) | ||
4414 | { | ||
4415 | ERR("Unable to alloc font entry part \"%s\"", alias); | ||
4416 | return EINA_FALSE; | ||
4417 | } | ||
4418 | fnt->file = eina_stringshare_add(new_path); | ||
4419 | fnt->entry = eina_stringshare_add(alias); | ||
4420 | |||
4421 | eina_hash_direct_add(ed->file->fonts, fnt->entry, fnt); | ||
4422 | |||
4423 | /* Import font */ | ||
4424 | if (!_edje_import_font_file(ed, path, entry)) | ||
4425 | { | ||
4426 | eina_hash_del(ed->file->fonts, fnt->entry, fnt); | ||
4427 | eina_stringshare_del(fnt->file); | ||
4428 | eina_stringshare_del(fnt->entry); | ||
4429 | return EINA_FALSE; | ||
4430 | } | ||
4431 | |||
4432 | return EINA_TRUE; | ||
4433 | } | ||
4434 | |||
4435 | EAPI Eina_Bool | ||
4436 | edje_edit_font_del(Evas_Object *obj, const char* alias) | ||
4437 | { | ||
4438 | Edje_Font_Directory_Entry *fnt; | ||
4439 | |||
4440 | eina_error_set(0); | ||
4441 | |||
4442 | GET_ED_OR_RETURN(EINA_FALSE); | ||
4443 | |||
4444 | INF("DEL FONT: %s", alias); | ||
4445 | |||
4446 | if (!alias) return EINA_FALSE; | ||
4447 | if (!ed->file) return EINA_FALSE; | ||
4448 | if (!ed->path) return EINA_FALSE; | ||
4449 | |||
4450 | fnt = eina_hash_find(ed->file->fonts, alias); | ||
4451 | if (!fnt) | ||
4452 | { | ||
4453 | WRN("Unable to find font entry part \"%s\"", alias); | ||
4454 | return EINA_FALSE; | ||
4455 | } | ||
4456 | |||
4457 | /* Erase font to edje file */ | ||
4458 | { | ||
4459 | char entry[PATH_MAX]; | ||
4460 | Eet_File *eetf; | ||
4461 | |||
4462 | /* open the eet file */ | ||
4463 | eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE); | ||
4464 | if (!eetf) | ||
4465 | { | ||
4466 | ERR("Unable to open \"%s\" for writing output", ed->path); | ||
4467 | return EINA_FALSE; | ||
4468 | } | ||
4469 | |||
4470 | snprintf(entry, sizeof(entry), "edje/fonts/%s", alias); | ||
4471 | |||
4472 | if (eet_delete(eetf, entry) <= 0) | ||
4473 | { | ||
4474 | ERR("Unable to delete \"%s\" font entry", entry); | ||
4475 | eet_close(eetf); | ||
4476 | return EINA_FALSE; | ||
4477 | } | ||
4478 | |||
4479 | /* write the edje_file */ | ||
4480 | if (!_edje_edit_edje_file_save(eetf, ed->file)) | ||
4481 | { | ||
4482 | eet_close(eetf); | ||
4483 | return EINA_FALSE; | ||
4484 | } | ||
4485 | eet_close(eetf); | ||
4486 | } | ||
4487 | |||
4488 | eina_hash_del(ed->file->fonts, alias, fnt); | ||
4489 | |||
4490 | return EINA_TRUE; | ||
4491 | } | ||
4492 | |||
4493 | EAPI const char * | ||
4494 | edje_edit_font_path_get(Evas_Object *obj, const char *alias) | ||
4495 | { | ||
4496 | Eina_Iterator *it; | ||
4497 | Edje_Font_Directory_Entry *f; | ||
4498 | const char *str = NULL; | ||
4499 | |||
4500 | eina_error_set(0); | ||
4501 | |||
4502 | if (!alias) return NULL; | ||
4503 | GET_ED_OR_RETURN(NULL); | ||
4504 | |||
4505 | if (!ed->file || !ed->file->fonts) return NULL; | ||
4506 | |||
4507 | it = eina_hash_iterator_data_new(ed->file->fonts); | ||
4508 | if (!it) return NULL; | ||
4509 | |||
4510 | EINA_ITERATOR_FOREACH(it, f) | ||
4511 | if (!strcmp(f->entry, alias)) | ||
4512 | { | ||
4513 | str = f->file; | ||
4514 | break; | ||
4515 | } | ||
4516 | |||
4517 | eina_iterator_free(it); | ||
4518 | return eina_stringshare_add(str); | ||
4519 | } | ||
4520 | |||
4521 | EAPI const char * | ||
4522 | edje_edit_state_font_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
4523 | { | ||
4524 | Edje_Part_Description_Text *txt; | ||
4525 | |||
4526 | eina_error_set(0); | ||
4527 | |||
4528 | GET_PD_OR_RETURN(NULL); | ||
4529 | |||
4530 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4531 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4532 | return NULL; | ||
4533 | |||
4534 | txt = (Edje_Part_Description_Text*) pd; | ||
4535 | |||
4536 | return eina_stringshare_add(edje_string_get(&txt->text.font)); | ||
4537 | } | ||
4538 | |||
4539 | EAPI void | ||
4540 | edje_edit_state_font_set(Evas_Object *obj, const char *part, const char *state, double value, const char *font) | ||
4541 | { | ||
4542 | Edje_Part_Description_Text *txt; | ||
4543 | |||
4544 | eina_error_set(0); | ||
4545 | |||
4546 | GET_PD_OR_RETURN(); | ||
4547 | |||
4548 | if ((rp->part->type != EDJE_PART_TYPE_TEXT) && | ||
4549 | (rp->part->type != EDJE_PART_TYPE_TEXTBLOCK)) | ||
4550 | return; | ||
4551 | |||
4552 | txt = (Edje_Part_Description_Text*) pd; | ||
4553 | |||
4554 | _edje_if_string_free(ed, txt->text.font.str); | ||
4555 | txt->text.font.str = (char *)eina_stringshare_add(font); | ||
4556 | txt->text.font.id = 0; | ||
4557 | |||
4558 | edje_object_calc_force(obj); | ||
4559 | } | ||
4560 | |||
4561 | EAPI Edje_Text_Effect | ||
4562 | edje_edit_part_effect_get(Evas_Object *obj, const char *part) | ||
4563 | { | ||
4564 | eina_error_set(0); | ||
4565 | |||
4566 | GET_RP_OR_RETURN(0); | ||
4567 | |||
4568 | //printf("GET EFFECT of part: %s\n", part); | ||
4569 | return rp->part->effect; | ||
4570 | } | ||
4571 | |||
4572 | EAPI void | ||
4573 | edje_edit_part_effect_set(Evas_Object *obj, const char *part, Edje_Text_Effect effect) | ||
4574 | { | ||
4575 | eina_error_set(0); | ||
4576 | |||
4577 | GET_RP_OR_RETURN(); | ||
4578 | |||
4579 | //printf("SET EFFECT of part: %s [%d]\n", part, effect); | ||
4580 | rp->part->effect = effect; | ||
4581 | |||
4582 | edje_object_calc_force(obj); | ||
4583 | } | ||
4584 | |||
4585 | /****************/ | ||
4586 | /* IMAGES API */ | ||
4587 | /****************/ | ||
4588 | |||
4589 | EAPI Eina_List * | ||
4590 | edje_edit_images_list_get(Evas_Object *obj) | ||
4591 | { | ||
4592 | Eina_List *images = NULL; | ||
4593 | unsigned int i; | ||
4594 | |||
4595 | eina_error_set(0); | ||
4596 | |||
4597 | GET_ED_OR_RETURN(NULL); | ||
4598 | |||
4599 | if (!ed->file) return NULL; | ||
4600 | if (!ed->file->image_dir) return NULL; | ||
4601 | |||
4602 | //printf("GET IMAGES LIST for %s\n", ed->file->path); | ||
4603 | for (i = 0; i < ed->file->image_dir->entries_count; ++i) | ||
4604 | images = eina_list_append(images, | ||
4605 | eina_stringshare_add(ed->file->image_dir->entries[i].entry)); | ||
4606 | |||
4607 | return images; | ||
4608 | } | ||
4609 | |||
4610 | EAPI Eina_Bool | ||
4611 | edje_edit_image_add(Evas_Object *obj, const char* path) | ||
4612 | { | ||
4613 | Edje_Image_Directory_Entry *de; | ||
4614 | unsigned int i; | ||
4615 | int free_id = -1; | ||
4616 | char *name; | ||
4617 | |||
4618 | eina_error_set(0); | ||
4619 | |||
4620 | GET_ED_OR_RETURN(EINA_FALSE); | ||
4621 | |||
4622 | if (!path) return EINA_FALSE; | ||
4623 | if (!ed->file) return EINA_FALSE; | ||
4624 | if (!ed->path) return EINA_FALSE; | ||
4625 | |||
4626 | /* Create Image_Directory if not exist */ | ||
4627 | if (!ed->file->image_dir) | ||
4628 | { | ||
4629 | ed->file->image_dir = _alloc(sizeof(Edje_Image_Directory)); | ||
4630 | if (!ed->file->image_dir) return EINA_FALSE; | ||
4631 | } | ||
4632 | |||
4633 | /* Image name */ | ||
4634 | if ((name = strrchr(path, '/'))) name++; | ||
4635 | else name = (char *)path; | ||
4636 | |||
4637 | /* Loop trough image directory to find if image exist */ | ||
4638 | for (i = 0; i < ed->file->image_dir->entries_count; ++i) | ||
4639 | { | ||
4640 | de = ed->file->image_dir->entries + i; | ||
4641 | |||
4642 | if (!de->entry) | ||
4643 | free_id = i; | ||
4644 | else if (!strcmp(name, de->entry)) | ||
4645 | return EINA_FALSE; | ||
4646 | } | ||
4647 | |||
4648 | if (free_id == -1) | ||
4649 | { | ||
4650 | Edje_Image_Directory_Entry *tmp; | ||
4651 | unsigned int count; | ||
4652 | |||
4653 | count = ed->file->image_dir->entries_count + 1; | ||
4654 | |||
4655 | tmp = realloc(ed->file->image_dir->entries, | ||
4656 | sizeof (Edje_Image_Directory_Entry) * count); | ||
4657 | if (!tmp) return EINA_FALSE; | ||
4658 | |||
4659 | ed->file->image_dir->entries = tmp; | ||
4660 | free_id = ed->file->image_dir->entries_count; | ||
4661 | ed->file->image_dir->entries_count = count; | ||
4662 | } | ||
4663 | |||
4664 | /* Set Image Entry */ | ||
4665 | de = ed->file->image_dir->entries + free_id; | ||
4666 | de->entry = eina_stringshare_add(name); | ||
4667 | de->id = free_id; | ||
4668 | de->source_type = 1; | ||
4669 | de->source_param = 1; | ||
4670 | |||
4671 | /* Import image */ | ||
4672 | if (!_edje_import_image_file(ed, path, free_id)) | ||
4673 | { | ||
4674 | eina_stringshare_del(de->entry); | ||
4675 | de->entry = NULL; | ||
4676 | return EINA_FALSE; | ||
4677 | } | ||
4678 | |||
4679 | return EINA_TRUE; | ||
4680 | } | ||
4681 | |||
4682 | EAPI Eina_Bool | ||
4683 | edje_edit_image_del(Evas_Object *obj, const char* name) | ||
4684 | { | ||
4685 | Edje_Image_Directory_Entry *de; | ||
4686 | unsigned int i; | ||
4687 | |||
4688 | eina_error_set(0); | ||
4689 | |||
4690 | GET_ED_OR_RETURN(EINA_FALSE); | ||
4691 | |||
4692 | if (!name) return EINA_FALSE; | ||
4693 | if (!ed->file) return EINA_FALSE; | ||
4694 | if (!ed->path) return EINA_FALSE; | ||
4695 | |||
4696 | /* Create Image_Directory if not exist */ | ||
4697 | if (!ed->file->image_dir) | ||
4698 | goto invalid_image; | ||
4699 | |||
4700 | return EINA_TRUE; | ||
4701 | |||
4702 | for (i = 0; i < ed->file->image_dir->entries_count; ++i) | ||
4703 | { | ||
4704 | de = ed->file->image_dir->entries + i; | ||
4705 | |||
4706 | if (de->entry | ||
4707 | && !strcmp(name, de->entry)) | ||
4708 | break; | ||
4709 | } | ||
4710 | |||
4711 | if (i == ed->file->image_dir->entries_count) | ||
4712 | goto invalid_image; | ||
4713 | |||
4714 | { | ||
4715 | char entry[PATH_MAX]; | ||
4716 | Eet_File *eetf; | ||
4717 | |||
4718 | /* open the eet file */ | ||
4719 | eetf = eet_open(ed->path, EET_FILE_MODE_READ_WRITE); | ||
4720 | if (!eetf) | ||
4721 | { | ||
4722 | ERR("Unable to open \"%s\" for writing output", ed->path); | ||
4723 | return EINA_FALSE; | ||
4724 | } | ||
4725 | |||
4726 | snprintf(entry, sizeof(entry), "edje/images/%i", de->id); | ||
4727 | |||
4728 | if (eet_delete(eetf, entry) <= 0) | ||
4729 | { | ||
4730 | ERR("Unable to delete \"%s\" font entry", entry); | ||
4731 | eet_close(eetf); | ||
4732 | return EINA_FALSE; | ||
4733 | } | ||
4734 | |||
4735 | /* write the edje_file */ | ||
4736 | if (!_edje_edit_edje_file_save(eetf, ed->file)) | ||
4737 | { | ||
4738 | eet_close(eetf); | ||
4739 | return EINA_FALSE; | ||
4740 | } | ||
4741 | |||
4742 | eet_close(eetf); | ||
4743 | } | ||
4744 | |||
4745 | _edje_if_string_free(ed, de->entry); | ||
4746 | de->entry = NULL; | ||
4747 | |||
4748 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
4749 | |||
4750 | return EINA_TRUE; | ||
4751 | |||
4752 | invalid_image: | ||
4753 | WRN("Unable to find image entry part \"%s\"", name); | ||
4754 | return EINA_FALSE; | ||
4755 | } | ||
4756 | |||
4757 | EAPI Eina_Bool | ||
4758 | edje_edit_image_data_add(Evas_Object *obj, const char *name, int id) | ||
4759 | { | ||
4760 | Edje_Image_Directory_Entry *de; | ||
4761 | |||
4762 | eina_error_set(0); | ||
4763 | |||
4764 | GET_ED_OR_RETURN(EINA_FALSE); | ||
4765 | |||
4766 | if (!name) return EINA_FALSE; | ||
4767 | if (!ed->file) return EINA_FALSE; | ||
4768 | if (!ed->path) return EINA_FALSE; | ||
4769 | |||
4770 | /* Create Image_Directory if not exist */ | ||
4771 | if (!ed->file->image_dir) | ||
4772 | { | ||
4773 | ed->file->image_dir = _alloc(sizeof(Edje_Image_Directory)); | ||
4774 | if (!ed->file->image_dir) return EINA_FALSE; | ||
4775 | } | ||
4776 | |||
4777 | /* Loop trough image directory to find if image exist */ | ||
4778 | if (id < 0) id = - id - 1; | ||
4779 | if ((unsigned int) id >= ed->file->image_dir->entries_count) return EINA_FALSE; | ||
4780 | |||
4781 | de = ed->file->image_dir->entries + id; | ||
4782 | eina_stringshare_replace(&de->entry, name); | ||
4783 | de->source_type = 1; | ||
4784 | de->source_param = 1; | ||
4785 | |||
4786 | return EINA_TRUE; | ||
4787 | } | ||
4788 | |||
4789 | EAPI int | ||
4790 | edje_edit_image_id_get(Evas_Object *obj, const char *image_name) | ||
4791 | { | ||
4792 | eina_error_set(0); | ||
4793 | |||
4794 | GET_ED_OR_RETURN(-1); | ||
4795 | |||
4796 | return _edje_image_id_find(eed, image_name); | ||
4797 | } | ||
4798 | |||
4799 | EAPI Edje_Edit_Image_Comp | ||
4800 | edje_edit_image_compression_type_get(Evas_Object *obj, const char *image) | ||
4801 | { | ||
4802 | Edje_Image_Directory_Entry *de = NULL; | ||
4803 | unsigned int i; | ||
4804 | |||
4805 | eina_error_set(0); | ||
4806 | |||
4807 | GET_ED_OR_RETURN(-1); | ||
4808 | |||
4809 | if (!ed->file) return -1; | ||
4810 | if (!ed->file->image_dir) return -1; | ||
4811 | |||
4812 | for (i = 0; i < ed->file->image_dir->entries_count; ++i) | ||
4813 | { | ||
4814 | de = ed->file->image_dir->entries + i; | ||
4815 | |||
4816 | if (de->entry | ||
4817 | && !strcmp(image, de->entry)) | ||
4818 | break; | ||
4819 | } | ||
4820 | |||
4821 | if (i == ed->file->image_dir->entries_count) return -1; | ||
4822 | |||
4823 | switch(de->source_type) | ||
4824 | { | ||
4825 | case EDJE_IMAGE_SOURCE_TYPE_INLINE_PERFECT: | ||
4826 | if (de->source_param == 0) // RAW | ||
4827 | return EDJE_EDIT_IMAGE_COMP_RAW; | ||
4828 | else // COMP | ||
4829 | return EDJE_EDIT_IMAGE_COMP_COMP; | ||
4830 | break; | ||
4831 | case EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY: // LOSSY | ||
4832 | return EDJE_EDIT_IMAGE_COMP_LOSSY; | ||
4833 | break; | ||
4834 | case EDJE_IMAGE_SOURCE_TYPE_EXTERNAL: // USER | ||
4835 | return EDJE_EDIT_IMAGE_COMP_USER; | ||
4836 | break; | ||
4837 | } | ||
4838 | |||
4839 | return -1; | ||
4840 | } | ||
4841 | |||
4842 | EAPI int | ||
4843 | edje_edit_image_compression_rate_get(Evas_Object *obj, const char *image) | ||
4844 | { | ||
4845 | Edje_Image_Directory_Entry *de; | ||
4846 | unsigned int i; | ||
4847 | |||
4848 | eina_error_set(0); | ||
4849 | |||
4850 | GET_ED_OR_RETURN(-1); | ||
4851 | |||
4852 | // Gets the Image Entry | ||
4853 | for (i = 0; i < ed->file->image_dir->entries_count; ++i) | ||
4854 | { | ||
4855 | de = ed->file->image_dir->entries + i; | ||
4856 | if (de->entry | ||
4857 | && !strcmp(de->entry, image)) | ||
4858 | break; | ||
4859 | } | ||
4860 | |||
4861 | if (i == ed->file->image_dir->entries_count) return -1; | ||
4862 | if (de->source_type != EDJE_IMAGE_SOURCE_TYPE_INLINE_LOSSY) return -2; | ||
4863 | |||
4864 | return de->source_param; | ||
4865 | } | ||
4866 | |||
4867 | EAPI const char * | ||
4868 | edje_edit_state_image_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
4869 | { | ||
4870 | Edje_Part_Description_Image *img; | ||
4871 | const char *image; | ||
4872 | |||
4873 | eina_error_set(0); | ||
4874 | |||
4875 | GET_PD_OR_RETURN(NULL); | ||
4876 | |||
4877 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
4878 | return NULL; | ||
4879 | |||
4880 | img = (Edje_Part_Description_Image *) pd; | ||
4881 | |||
4882 | image = _edje_image_name_find(eed, img->image.id); | ||
4883 | if (!image) return NULL; | ||
4884 | |||
4885 | //printf("GET IMAGE for %s [%s]\n", state, image); | ||
4886 | return eina_stringshare_add(image); | ||
4887 | } | ||
4888 | |||
4889 | EAPI void | ||
4890 | edje_edit_state_image_set(Evas_Object *obj, const char *part, const char *state, double value, const char *image) | ||
4891 | { | ||
4892 | Edje_Part_Description_Image *img; | ||
4893 | int id; | ||
4894 | |||
4895 | eina_error_set(0); | ||
4896 | |||
4897 | GET_PD_OR_RETURN(); | ||
4898 | |||
4899 | if (!image) return; | ||
4900 | |||
4901 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
4902 | return; | ||
4903 | |||
4904 | id = _edje_image_id_find(eed, image); | ||
4905 | //printf("SET IMAGE for %s [%s]\n", state, image); | ||
4906 | |||
4907 | img = (Edje_Part_Description_Image *) pd; | ||
4908 | |||
4909 | if (id > -1) img->image.id = id; | ||
4910 | |||
4911 | edje_object_calc_force(obj); | ||
4912 | } | ||
4913 | |||
4914 | EAPI Eina_List * | ||
4915 | edje_edit_state_tweens_list_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
4916 | { | ||
4917 | Edje_Part_Description_Image *img; | ||
4918 | Eina_List *tweens = NULL; | ||
4919 | const char *name; | ||
4920 | unsigned int i; | ||
4921 | |||
4922 | eina_error_set(0); | ||
4923 | |||
4924 | GET_PD_OR_RETURN(NULL); | ||
4925 | |||
4926 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
4927 | return NULL; | ||
4928 | |||
4929 | img = (Edje_Part_Description_Image *) pd; | ||
4930 | |||
4931 | for (i = 0; i < img->image.tweens_count; ++i) | ||
4932 | { | ||
4933 | name = _edje_image_name_find(eed, img->image.tweens[i]->id); | ||
4934 | //printf(" t: %s\n", name); | ||
4935 | tweens = eina_list_append(tweens, eina_stringshare_add(name)); | ||
4936 | } | ||
4937 | |||
4938 | return tweens; | ||
4939 | } | ||
4940 | |||
4941 | EAPI Eina_Bool | ||
4942 | edje_edit_state_tween_add(Evas_Object *obj, const char *part, const char *state, double value, const char *tween) | ||
4943 | { | ||
4944 | Edje_Part_Description_Image *img; | ||
4945 | Edje_Part_Image_Id **tmp; | ||
4946 | Edje_Part_Image_Id *i; | ||
4947 | int id; | ||
4948 | |||
4949 | eina_error_set(0); | ||
4950 | |||
4951 | GET_PD_OR_RETURN(EINA_FALSE); | ||
4952 | |||
4953 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
4954 | return EINA_FALSE; | ||
4955 | |||
4956 | id = _edje_image_id_find(eed, tween); | ||
4957 | if (id < EINA_FALSE) return 0; | ||
4958 | |||
4959 | /* alloc Edje_Part_Image_Id */ | ||
4960 | i = _alloc(sizeof(Edje_Part_Image_Id)); | ||
4961 | if (!i) return EINA_FALSE; | ||
4962 | i->id = id; | ||
4963 | |||
4964 | img = (Edje_Part_Description_Image *) pd; | ||
4965 | |||
4966 | /* add to tween list */ | ||
4967 | tmp = realloc(img->image.tweens, | ||
4968 | sizeof (Edje_Part_Image_Id*) * img->image.tweens_count); | ||
4969 | if (!tmp) | ||
4970 | { | ||
4971 | free(i); | ||
4972 | return EINA_FALSE; | ||
4973 | } | ||
4974 | |||
4975 | tmp[img->image.tweens_count++] = i; | ||
4976 | img->image.tweens = tmp; | ||
4977 | |||
4978 | return EINA_TRUE; | ||
4979 | } | ||
4980 | |||
4981 | EAPI Eina_Bool | ||
4982 | edje_edit_state_tween_del(Evas_Object *obj, const char *part, const char *state, double value, const char *tween) | ||
4983 | { | ||
4984 | Edje_Part_Description_Image *img; | ||
4985 | unsigned int i; | ||
4986 | int search; | ||
4987 | |||
4988 | eina_error_set(0); | ||
4989 | |||
4990 | GET_PD_OR_RETURN(EINA_FALSE); | ||
4991 | |||
4992 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
4993 | return EINA_FALSE; | ||
4994 | |||
4995 | img = (Edje_Part_Description_Image *) pd; | ||
4996 | |||
4997 | if (!img->image.tweens_count) return EINA_FALSE; | ||
4998 | |||
4999 | search = _edje_image_id_find(eed, tween); | ||
5000 | if (search < 0) return EINA_FALSE; | ||
5001 | |||
5002 | for (i = 0; i < img->image.tweens_count; ++i) | ||
5003 | { | ||
5004 | if (img->image.tweens[i]->id == search) | ||
5005 | { | ||
5006 | img->image.tweens_count--; | ||
5007 | free(img->image.tweens[i]); | ||
5008 | memmove(img->image.tweens + i, | ||
5009 | img->image.tweens + i + 1, | ||
5010 | sizeof (Edje_Part_Description_Image*) * (img->image.tweens_count - i)); | ||
5011 | return EINA_TRUE; | ||
5012 | } | ||
5013 | } | ||
5014 | return EINA_FALSE; | ||
5015 | } | ||
5016 | |||
5017 | EAPI void | ||
5018 | edje_edit_state_image_border_get(Evas_Object *obj, const char *part, const char *state, double value, int *l, int *r, int *t, int *b) | ||
5019 | { | ||
5020 | Edje_Part_Description_Image *img; | ||
5021 | |||
5022 | eina_error_set(0); | ||
5023 | |||
5024 | GET_PD_OR_RETURN(); | ||
5025 | |||
5026 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
5027 | { | ||
5028 | if (l) *l = 0; | ||
5029 | if (r) *r = 0; | ||
5030 | if (t) *t = 0; | ||
5031 | if (b) *b = 0; | ||
5032 | return; | ||
5033 | } | ||
5034 | |||
5035 | img = (Edje_Part_Description_Image *) pd; | ||
5036 | |||
5037 | //printf("GET IMAGE_BORDER of state '%s'\n", state); | ||
5038 | |||
5039 | if (l) *l = img->image.border.l; | ||
5040 | if (r) *r = img->image.border.r; | ||
5041 | if (t) *t = img->image.border.t; | ||
5042 | if (b) *b = img->image.border.b; | ||
5043 | } | ||
5044 | |||
5045 | EAPI void | ||
5046 | edje_edit_state_image_border_set(Evas_Object *obj, const char *part, const char *state, double value, int l, int r, int t, int b) | ||
5047 | { | ||
5048 | Edje_Part_Description_Image *img; | ||
5049 | |||
5050 | eina_error_set(0); | ||
5051 | |||
5052 | GET_PD_OR_RETURN(); | ||
5053 | |||
5054 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
5055 | return; | ||
5056 | |||
5057 | img = (Edje_Part_Description_Image *) pd; | ||
5058 | |||
5059 | //printf("SET IMAGE_BORDER of state '%s'\n", state); | ||
5060 | |||
5061 | if (l > -1) img->image.border.l = l; | ||
5062 | if (r > -1) img->image.border.r = r; | ||
5063 | if (t > -1) img->image.border.t = t; | ||
5064 | if (b > -1) img->image.border.b = b; | ||
5065 | |||
5066 | edje_object_calc_force(obj); | ||
5067 | } | ||
5068 | |||
5069 | EAPI unsigned char | ||
5070 | edje_edit_state_image_border_fill_get(Evas_Object *obj, const char *part, const char *state, double value) | ||
5071 | { | ||
5072 | Edje_Part_Description_Image *img; | ||
5073 | |||
5074 | eina_error_set(0); | ||
5075 | |||
5076 | GET_PD_OR_RETURN(0); | ||
5077 | |||
5078 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
5079 | return 0; | ||
5080 | |||
5081 | img = (Edje_Part_Description_Image *) pd; | ||
5082 | |||
5083 | if (img->image.border.no_fill == 0) return 1; | ||
5084 | else if (img->image.border.no_fill == 1) return 0; | ||
5085 | else if (img->image.border.no_fill == 2) return 2; | ||
5086 | return 0; | ||
5087 | } | ||
5088 | |||
5089 | EAPI void | ||
5090 | edje_edit_state_image_border_fill_set(Evas_Object *obj, const char *part, const char *state, double value, unsigned char fill) | ||
5091 | { | ||
5092 | Edje_Part_Description_Image *img; | ||
5093 | |||
5094 | eina_error_set(0); | ||
5095 | |||
5096 | GET_PD_OR_RETURN(); | ||
5097 | |||
5098 | if (rp->part->type != EDJE_PART_TYPE_IMAGE) | ||
5099 | return; | ||
5100 | |||
5101 | img = (Edje_Part_Description_Image *) pd; | ||
5102 | |||
5103 | if (fill == 0) img->image.border.no_fill = 1; | ||
5104 | else if (fill == 1) img->image.border.no_fill = 0; | ||
5105 | else if (fill == 2) img->image.border.no_fill = 2; | ||
5106 | |||
5107 | edje_object_calc_force(obj); | ||
5108 | } | ||
5109 | |||
5110 | /******************/ | ||
5111 | /* PROGRAMS API */ | ||
5112 | /******************/ | ||
5113 | static int | ||
5114 | _edje_program_id_find(Edje_Edit *eed, const char *program) | ||
5115 | { | ||
5116 | Edje_Program *epr; | ||
5117 | int i; | ||
5118 | |||
5119 | for (i = 0; i < eed->base.table_programs_size; i++) | ||
5120 | { | ||
5121 | epr = eed->base.table_programs[i]; | ||
5122 | if (epr->name && !strcmp(epr->name, program)) | ||
5123 | return epr->id; | ||
5124 | } | ||
5125 | return -1; | ||
5126 | } | ||
5127 | |||
5128 | static Edje_Program * | ||
5129 | _edje_program_get_byname(Evas_Object *obj, const char *prog_name) | ||
5130 | { | ||
5131 | Edje_Program *epr; | ||
5132 | int i; | ||
5133 | |||
5134 | GET_ED_OR_RETURN(NULL); | ||
5135 | |||
5136 | if (!prog_name) return NULL; | ||
5137 | |||
5138 | for (i = 0; i < ed->table_programs_size; i++) | ||
5139 | { | ||
5140 | epr = ed->table_programs[i]; | ||
5141 | if ((epr->name) && (strcmp(epr->name, prog_name) == 0)) | ||
5142 | return epr; | ||
5143 | } | ||
5144 | return NULL; | ||
5145 | } | ||
5146 | |||
5147 | EAPI Eina_List * | ||
5148 | edje_edit_programs_list_get(Evas_Object *obj) | ||
5149 | { | ||
5150 | Eina_List *progs = NULL; | ||
5151 | int i; | ||
5152 | |||
5153 | eina_error_set(0); | ||
5154 | |||
5155 | GET_ED_OR_RETURN(NULL); | ||
5156 | |||
5157 | //printf("EE: Found %d programs\n", ed->table_programs_size); | ||
5158 | |||
5159 | for (i = 0; i < ed->table_programs_size; i++) | ||
5160 | { | ||
5161 | Edje_Program *epr; | ||
5162 | |||
5163 | epr = ed->table_programs[i]; | ||
5164 | /* XXX: bad, we miss programs this way, but since you can't access | ||
5165 | * them in any way without a name, better ignore them. */ | ||
5166 | if (!epr->name) continue; | ||
5167 | progs = eina_list_append(progs, eina_stringshare_add(epr->name)); | ||
5168 | } | ||
5169 | |||
5170 | return progs; | ||
5171 | } | ||
5172 | |||
5173 | EAPI Eina_Bool | ||
5174 | edje_edit_program_add(Evas_Object *obj, const char *name) | ||
5175 | { | ||
5176 | Edje_Program *epr; | ||
5177 | Edje_Part_Collection *pc; | ||
5178 | |||
5179 | eina_error_set(0); | ||
5180 | |||
5181 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5182 | |||
5183 | //printf("ADD PROGRAM [new name: %s]\n", name); | ||
5184 | |||
5185 | //Check if program already exists | ||
5186 | if (_edje_program_get_byname(obj, name)) | ||
5187 | return EINA_FALSE; | ||
5188 | |||
5189 | //Alloc Edje_Program or return | ||
5190 | epr = _alloc(sizeof(Edje_Program)); | ||
5191 | if (!epr) return EINA_FALSE; | ||
5192 | |||
5193 | //Add program to group | ||
5194 | pc = ed->collection; | ||
5195 | |||
5196 | /* By default, source and signal are empty, so they fill in nocmp category */ | ||
5197 | ed->collection->programs.nocmp = realloc(ed->collection->programs.nocmp, | ||
5198 | sizeof (Edje_Program*) * (ed->collection->programs.nocmp_count + 1)); | ||
5199 | ed->collection->programs.nocmp[ed->collection->programs.nocmp_count++] = epr; | ||
5200 | |||
5201 | //Init Edje_Program | ||
5202 | epr->id = ed->table_programs_size; | ||
5203 | epr->name = eina_stringshare_add(name); | ||
5204 | epr->signal = NULL; | ||
5205 | epr->source = NULL; | ||
5206 | epr->filter.part = NULL; | ||
5207 | epr->filter.state = NULL; | ||
5208 | epr->in.from = 0.0; | ||
5209 | epr->in.range = 0.0; | ||
5210 | epr->action = 0; | ||
5211 | epr->state = NULL; | ||
5212 | epr->value = 0.0; | ||
5213 | epr->state2 = NULL; | ||
5214 | epr->value2 = 0.0; | ||
5215 | epr->tween.mode = 1; | ||
5216 | epr->tween.time = ZERO; | ||
5217 | epr->targets = NULL; | ||
5218 | epr->after = NULL; | ||
5219 | |||
5220 | |||
5221 | //Update table_programs | ||
5222 | ed->table_programs_size++; | ||
5223 | ed->table_programs = realloc(ed->table_programs, | ||
5224 | sizeof(Edje_Program *) * ed->table_programs_size); | ||
5225 | ed->table_programs[epr->id % ed->table_programs_size] = epr; | ||
5226 | |||
5227 | //Update patterns | ||
5228 | _edje_programs_patterns_clean(ed); | ||
5229 | _edje_programs_patterns_init(ed); | ||
5230 | |||
5231 | return EINA_TRUE; | ||
5232 | } | ||
5233 | |||
5234 | EAPI Eina_Bool | ||
5235 | edje_edit_program_del(Evas_Object *obj, const char *prog) | ||
5236 | { | ||
5237 | Eina_List *l, *l_next; | ||
5238 | Edje_Program_Target *prt; | ||
5239 | Edje_Program_After *pa; | ||
5240 | Edje_Part_Collection *pc; | ||
5241 | Edje_Program *p; | ||
5242 | Program_Script *ps, *old_ps; | ||
5243 | int id, i; | ||
5244 | int old_id = -1; | ||
5245 | |||
5246 | eina_error_set(0); | ||
5247 | |||
5248 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5249 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5250 | |||
5251 | pc = ed->collection; | ||
5252 | |||
5253 | //Remove program from programs list | ||
5254 | id = epr->id; | ||
5255 | _edje_program_remove(ed->collection, epr); | ||
5256 | |||
5257 | /* fix table program */ | ||
5258 | if (epr->id != ed->table_programs_size - 1) | ||
5259 | { | ||
5260 | /* If the removed program is not the last in the list/table, | ||
5261 | * put the last one in its place and update references to it later */ | ||
5262 | ed->table_programs[epr->id] = ed->table_programs[ed->table_programs_size - 1]; | ||
5263 | old_id = ed->table_programs_size - 1; | ||
5264 | ed->table_programs[epr->id]->id = epr->id; | ||
5265 | } | ||
5266 | |||
5267 | ps = eina_hash_find(eed->program_scripts, &id); | ||
5268 | old_ps = eina_hash_find(eed->program_scripts, &old_id); | ||
5269 | if (old_ps) | ||
5270 | { | ||
5271 | if (!ps) | ||
5272 | { | ||
5273 | ps = _alloc(sizeof(Program_Script)); | ||
5274 | ps->id = id; | ||
5275 | eina_hash_add(eed->program_scripts, &id, ps); | ||
5276 | } | ||
5277 | else | ||
5278 | { | ||
5279 | free(ps->code); | ||
5280 | free(ps->processed); | ||
5281 | ps->processed = NULL; | ||
5282 | ps->delete_me = EINA_FALSE; | ||
5283 | } | ||
5284 | ps->code = old_ps->code; | ||
5285 | old_ps->code = NULL; | ||
5286 | free(old_ps->processed); | ||
5287 | old_ps->processed = NULL; | ||
5288 | ps->dirty = EINA_TRUE; | ||
5289 | old_ps->dirty = EINA_FALSE; | ||
5290 | old_ps->delete_me = EINA_TRUE; | ||
5291 | } | ||
5292 | else if (ps) | ||
5293 | { | ||
5294 | ps->dirty = EINA_FALSE; | ||
5295 | ps->delete_me = EINA_TRUE; | ||
5296 | } | ||
5297 | |||
5298 | //Free Edje_Program | ||
5299 | _edje_if_string_free(ed, epr->name); | ||
5300 | _edje_if_string_free(ed, epr->signal); | ||
5301 | _edje_if_string_free(ed, epr->source); | ||
5302 | _edje_if_string_free(ed, epr->filter.part); | ||
5303 | _edje_if_string_free(ed, epr->filter.state); | ||
5304 | _edje_if_string_free(ed, epr->state); | ||
5305 | _edje_if_string_free(ed, epr->state2); | ||
5306 | |||
5307 | EINA_LIST_FREE(epr->targets, prt) | ||
5308 | free(prt); | ||
5309 | EINA_LIST_FREE(epr->after, pa) | ||
5310 | free(pa); | ||
5311 | free(epr); | ||
5312 | |||
5313 | ed->table_programs_size--; | ||
5314 | ed->table_programs = realloc(ed->table_programs, | ||
5315 | sizeof(Edje_Program *) * ed->table_programs_size); | ||
5316 | |||
5317 | //We also update all other programs that point to old_id and id | ||
5318 | for (i = 0; i < ed->table_programs_size; i++) | ||
5319 | { | ||
5320 | p = ed->table_programs[i]; | ||
5321 | |||
5322 | /* check in afters */ | ||
5323 | EINA_LIST_FOREACH_SAFE(p->after, l, l_next, pa) | ||
5324 | { | ||
5325 | if (pa->id == old_id) | ||
5326 | pa->id = id; | ||
5327 | else if (pa->id == id) | ||
5328 | { | ||
5329 | p->after = eina_list_remove_list(p->after, l); | ||
5330 | free(pa); | ||
5331 | } | ||
5332 | } | ||
5333 | /* check in targets */ | ||
5334 | if (p->action == EDJE_ACTION_TYPE_ACTION_STOP) | ||
5335 | { | ||
5336 | Edje_Program_Target *pt; | ||
5337 | |||
5338 | EINA_LIST_FOREACH_SAFE(p->targets, l, l_next, pt) | ||
5339 | { | ||
5340 | if (pt->id == old_id) | ||
5341 | pt->id = id; | ||
5342 | else if (pt->id == id) | ||
5343 | { | ||
5344 | p->targets = eina_list_remove_list(p->targets, l); | ||
5345 | free(pt); | ||
5346 | } | ||
5347 | } | ||
5348 | } | ||
5349 | } | ||
5350 | |||
5351 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
5352 | |||
5353 | return EINA_TRUE; | ||
5354 | } | ||
5355 | |||
5356 | EAPI Eina_Bool | ||
5357 | edje_edit_program_exist(Evas_Object *obj, const char *prog) | ||
5358 | { | ||
5359 | eina_error_set(0); | ||
5360 | |||
5361 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5362 | |||
5363 | return EINA_TRUE; | ||
5364 | } | ||
5365 | |||
5366 | EAPI Eina_Bool | ||
5367 | edje_edit_program_run(Evas_Object *obj, const char *prog) | ||
5368 | { | ||
5369 | eina_error_set(0); | ||
5370 | |||
5371 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5372 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5373 | |||
5374 | _edje_program_run(ed, epr, 0, "", ""); | ||
5375 | return EINA_TRUE; | ||
5376 | } | ||
5377 | |||
5378 | EAPI Eina_Bool | ||
5379 | edje_edit_program_name_set(Evas_Object *obj, const char *prog, const char* new_name) | ||
5380 | { | ||
5381 | eina_error_set(0); | ||
5382 | |||
5383 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5384 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5385 | |||
5386 | if (!new_name) return EINA_FALSE; | ||
5387 | |||
5388 | if (_edje_program_get_byname(obj, new_name)) return EINA_FALSE; | ||
5389 | |||
5390 | //printf("SET NAME for program: %s [new name: %s]\n", prog, new_name); | ||
5391 | |||
5392 | _edje_if_string_free(ed, epr->name); | ||
5393 | epr->name = eina_stringshare_add(new_name); | ||
5394 | |||
5395 | _edje_edit_flag_script_dirty(eed, EINA_TRUE); | ||
5396 | |||
5397 | return EINA_TRUE; | ||
5398 | } | ||
5399 | |||
5400 | EAPI const char * | ||
5401 | edje_edit_program_source_get(Evas_Object *obj, const char *prog) | ||
5402 | { | ||
5403 | eina_error_set(0); | ||
5404 | |||
5405 | GET_EPR_OR_RETURN(NULL); | ||
5406 | |||
5407 | if (!epr->source) return NULL; | ||
5408 | //printf("GET SOURCE for program: %s [%s]\n", prog, epr->source); | ||
5409 | return eina_stringshare_add(epr->source); | ||
5410 | } | ||
5411 | |||
5412 | EAPI Eina_Bool | ||
5413 | edje_edit_program_source_set(Evas_Object *obj, const char *prog, const char *source) | ||
5414 | { | ||
5415 | eina_error_set(0); | ||
5416 | |||
5417 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5418 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5419 | |||
5420 | if (!source) return EINA_FALSE; | ||
5421 | |||
5422 | /* Remove from program array */ | ||
5423 | _edje_program_remove(ed->collection, epr); | ||
5424 | _edje_if_string_free(ed, epr->source); | ||
5425 | |||
5426 | /* Insert it back */ | ||
5427 | epr->source = eina_stringshare_add(source); | ||
5428 | _edje_program_insert(ed->collection, epr); | ||
5429 | |||
5430 | //Update patterns | ||
5431 | _edje_programs_patterns_clean(ed); | ||
5432 | _edje_programs_patterns_init(ed); | ||
5433 | |||
5434 | return EINA_TRUE; | ||
5435 | } | ||
5436 | |||
5437 | EAPI const char * | ||
5438 | edje_edit_program_filter_part_get(Evas_Object *obj, const char *prog) | ||
5439 | { | ||
5440 | eina_error_set(0); | ||
5441 | |||
5442 | GET_EPR_OR_RETURN(NULL); | ||
5443 | |||
5444 | if (!epr->filter.part) return NULL; | ||
5445 | return eina_stringshare_add(epr->filter.part); | ||
5446 | } | ||
5447 | |||
5448 | EAPI Eina_Bool | ||
5449 | edje_edit_program_filter_part_set(Evas_Object *obj, const char *prog, const char *filter_part) | ||
5450 | { | ||
5451 | eina_error_set(0); | ||
5452 | |||
5453 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5454 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5455 | |||
5456 | if (!filter_part) return EINA_FALSE; | ||
5457 | |||
5458 | _edje_if_string_free(ed, epr->filter.part); | ||
5459 | epr->filter.part = eina_stringshare_add(filter_part); | ||
5460 | |||
5461 | return EINA_TRUE; | ||
5462 | } | ||
5463 | |||
5464 | EAPI const char * | ||
5465 | edje_edit_program_filter_state_get(Evas_Object *obj, const char *prog) | ||
5466 | { | ||
5467 | eina_error_set(0); | ||
5468 | |||
5469 | GET_EPR_OR_RETURN(NULL); | ||
5470 | |||
5471 | if (!epr->filter.state) return NULL; | ||
5472 | return eina_stringshare_add(epr->filter.state); | ||
5473 | } | ||
5474 | |||
5475 | EAPI Eina_Bool | ||
5476 | edje_edit_program_filter_state_set(Evas_Object *obj, const char *prog, const char *filter_state) | ||
5477 | { | ||
5478 | eina_error_set(0); | ||
5479 | |||
5480 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5481 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5482 | |||
5483 | if (!filter_state) return EINA_FALSE; | ||
5484 | |||
5485 | _edje_if_string_free(ed, epr->filter.state); | ||
5486 | epr->filter.state = eina_stringshare_add(filter_state); | ||
5487 | |||
5488 | return EINA_TRUE; | ||
5489 | } | ||
5490 | |||
5491 | EAPI const char * | ||
5492 | edje_edit_program_signal_get(Evas_Object *obj, const char *prog) | ||
5493 | { | ||
5494 | eina_error_set(0); | ||
5495 | |||
5496 | GET_EPR_OR_RETURN(NULL); | ||
5497 | |||
5498 | if (!epr->signal) return NULL; | ||
5499 | //printf("GET SIGNAL for program: %s [%s]\n", prog, epr->signal); | ||
5500 | return eina_stringshare_add(epr->signal); | ||
5501 | } | ||
5502 | |||
5503 | EAPI Eina_Bool | ||
5504 | edje_edit_program_signal_set(Evas_Object *obj, const char *prog, const char *sig) | ||
5505 | { | ||
5506 | eina_error_set(0); | ||
5507 | |||
5508 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5509 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5510 | |||
5511 | if (!sig) return EINA_FALSE; | ||
5512 | |||
5513 | /* Remove from program array */ | ||
5514 | _edje_program_remove(ed->collection, epr); | ||
5515 | _edje_if_string_free(ed, epr->signal); | ||
5516 | |||
5517 | /* Insert it back */ | ||
5518 | epr->signal = eina_stringshare_add(sig); | ||
5519 | _edje_program_insert(ed->collection, epr); | ||
5520 | |||
5521 | //Update patterns | ||
5522 | _edje_programs_patterns_clean(ed); | ||
5523 | _edje_programs_patterns_init(ed); | ||
5524 | |||
5525 | return EINA_TRUE; | ||
5526 | } | ||
5527 | |||
5528 | EAPI const char * | ||
5529 | edje_edit_program_state_get(Evas_Object *obj, const char *prog) | ||
5530 | { | ||
5531 | eina_error_set(0); | ||
5532 | |||
5533 | GET_EPR_OR_RETURN(NULL); | ||
5534 | |||
5535 | if (!epr->state) return NULL; | ||
5536 | //printf("GET STATE for program: %s [%s %.2f]\n", prog, epr->state, epr->value); | ||
5537 | return eina_stringshare_add(epr->state); | ||
5538 | } | ||
5539 | |||
5540 | EAPI Eina_Bool | ||
5541 | edje_edit_program_state_set(Evas_Object *obj, const char *prog, const char *state) | ||
5542 | { | ||
5543 | eina_error_set(0); | ||
5544 | |||
5545 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5546 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5547 | |||
5548 | //printf("SET STATE for program: %s\n", prog); | ||
5549 | |||
5550 | _edje_if_string_free(ed, epr->state); | ||
5551 | epr->state = eina_stringshare_add(state); | ||
5552 | |||
5553 | return EINA_TRUE; | ||
5554 | } | ||
5555 | |||
5556 | EAPI const char * | ||
5557 | edje_edit_program_state2_get(Evas_Object *obj, const char *prog) | ||
5558 | { | ||
5559 | eina_error_set(0); | ||
5560 | |||
5561 | GET_EPR_OR_RETURN(NULL); | ||
5562 | |||
5563 | if (!epr->state2) return NULL; | ||
5564 | //printf("GET STATE2 for program: %s [%s %.2f]\n", prog, epr->state2, epr->value2); | ||
5565 | return eina_stringshare_add(epr->state2); | ||
5566 | } | ||
5567 | |||
5568 | EAPI Eina_Bool | ||
5569 | edje_edit_program_state2_set(Evas_Object *obj, const char *prog, const char *state2) | ||
5570 | { | ||
5571 | eina_error_set(0); | ||
5572 | |||
5573 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5574 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5575 | |||
5576 | //printf("SET STATE2 for program: %s\n", prog); | ||
5577 | |||
5578 | _edje_if_string_free(ed, epr->state2); | ||
5579 | epr->state2 = eina_stringshare_add(state2); | ||
5580 | |||
5581 | return EINA_TRUE; | ||
5582 | } | ||
5583 | |||
5584 | EAPI double | ||
5585 | edje_edit_program_value_get(Evas_Object *obj, const char *prog) | ||
5586 | { | ||
5587 | eina_error_set(0); | ||
5588 | |||
5589 | GET_EPR_OR_RETURN(-1); | ||
5590 | |||
5591 | //printf("GET VALUE for program: %s [%s %.2f]\n", prog, epr->state, epr->value); | ||
5592 | return epr->value; | ||
5593 | } | ||
5594 | |||
5595 | EAPI Eina_Bool | ||
5596 | edje_edit_program_value_set(Evas_Object *obj, const char *prog, double value) | ||
5597 | { | ||
5598 | eina_error_set(0); | ||
5599 | |||
5600 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5601 | |||
5602 | //printf("SET VALUE for program: %s [%.2f]\n", prog, value); | ||
5603 | epr->value = value; | ||
5604 | return EINA_TRUE; | ||
5605 | } | ||
5606 | |||
5607 | EAPI double | ||
5608 | edje_edit_program_value2_get(Evas_Object *obj, const char *prog) | ||
5609 | { | ||
5610 | eina_error_set(0); | ||
5611 | |||
5612 | GET_EPR_OR_RETURN(-1); | ||
5613 | |||
5614 | //printf("GET VALUE2 for program: %s [%s %.2f]\n", prog, epr->state2, epr->value2); | ||
5615 | return epr->value2; | ||
5616 | } | ||
5617 | |||
5618 | EAPI Eina_Bool | ||
5619 | edje_edit_program_value2_set(Evas_Object *obj, const char *prog, double value) | ||
5620 | { | ||
5621 | eina_error_set(0); | ||
5622 | |||
5623 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5624 | |||
5625 | //printf("SET VALUE for program: %s [%.2f]\n", prog, value); | ||
5626 | epr->value2 = value; | ||
5627 | return EINA_TRUE; | ||
5628 | } | ||
5629 | |||
5630 | EAPI double | ||
5631 | edje_edit_program_in_from_get(Evas_Object *obj, const char *prog) | ||
5632 | { | ||
5633 | eina_error_set(0); | ||
5634 | |||
5635 | GET_EPR_OR_RETURN(0); | ||
5636 | |||
5637 | //printf("GET IN.FROM for program: %s [%f]\n", prog, epr->in.from); | ||
5638 | return epr->in.from; | ||
5639 | } | ||
5640 | |||
5641 | EAPI Eina_Bool | ||
5642 | edje_edit_program_in_from_set(Evas_Object *obj, const char *prog, double seconds) | ||
5643 | { | ||
5644 | eina_error_set(0); | ||
5645 | |||
5646 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5647 | |||
5648 | //printf("SET IN.FROM for program: %s [%f]\n", prog, epr->in.from); | ||
5649 | epr->in.from = seconds; | ||
5650 | return EINA_TRUE; | ||
5651 | } | ||
5652 | |||
5653 | EAPI double | ||
5654 | edje_edit_program_in_range_get(Evas_Object *obj, const char *prog) | ||
5655 | { | ||
5656 | eina_error_set(0); | ||
5657 | |||
5658 | GET_EPR_OR_RETURN(0); | ||
5659 | |||
5660 | //printf("GET IN.RANGE for program: %s [%f]\n", prog, epr->in.range); | ||
5661 | return epr->in.range; | ||
5662 | } | ||
5663 | |||
5664 | EAPI Eina_Bool | ||
5665 | edje_edit_program_in_range_set(Evas_Object *obj, const char *prog, double seconds) | ||
5666 | { | ||
5667 | eina_error_set(0); | ||
5668 | |||
5669 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5670 | |||
5671 | //printf("SET IN.RANGE for program: %s [%f]\n", prog, epr->in.range); | ||
5672 | epr->in.range = seconds; | ||
5673 | return EINA_TRUE; | ||
5674 | } | ||
5675 | |||
5676 | EAPI Edje_Tween_Mode | ||
5677 | edje_edit_program_transition_get(Evas_Object *obj, const char *prog) | ||
5678 | { | ||
5679 | eina_error_set(0); | ||
5680 | |||
5681 | GET_EPR_OR_RETURN(-1); | ||
5682 | |||
5683 | //printf("GET TRANSITION for program: %s [%d]\n", prog, epr->tween.mode); | ||
5684 | return epr->tween.mode; | ||
5685 | } | ||
5686 | |||
5687 | EAPI Eina_Bool | ||
5688 | edje_edit_program_transition_set(Evas_Object *obj, const char *prog, Edje_Tween_Mode transition) | ||
5689 | { | ||
5690 | eina_error_set(0); | ||
5691 | |||
5692 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5693 | |||
5694 | //printf("GET TRANSITION for program: %s [%d]\n", prog, epr->tween.mode); | ||
5695 | epr->tween.mode = transition; | ||
5696 | return EINA_TRUE; | ||
5697 | } | ||
5698 | |||
5699 | EAPI double | ||
5700 | edje_edit_program_transition_time_get(Evas_Object *obj, const char *prog) | ||
5701 | { | ||
5702 | eina_error_set(0); | ||
5703 | |||
5704 | GET_EPR_OR_RETURN(-1); | ||
5705 | |||
5706 | //printf("GET TRANSITION_TIME for program: %s [%.4f]\n", prog, epr->tween.time); | ||
5707 | return TO_DOUBLE(epr->tween.time); | ||
5708 | } | ||
5709 | |||
5710 | EAPI Eina_Bool | ||
5711 | edje_edit_program_transition_time_set(Evas_Object *obj, const char *prog, double seconds) | ||
5712 | { | ||
5713 | eina_error_set(0); | ||
5714 | |||
5715 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5716 | |||
5717 | //printf("GET TRANSITION_TIME for program: %s [%.4f]\n", prog, epr->tween.time); | ||
5718 | epr->tween.time = FROM_DOUBLE(seconds); | ||
5719 | return EINA_TRUE; | ||
5720 | } | ||
5721 | |||
5722 | EAPI Edje_Action_Type | ||
5723 | edje_edit_program_action_get(Evas_Object *obj, const char *prog) | ||
5724 | { | ||
5725 | eina_error_set(0); | ||
5726 | |||
5727 | GET_EPR_OR_RETURN(-1); | ||
5728 | |||
5729 | //printf("GET ACTION for program: %s [%d]\n", prog, epr->action); | ||
5730 | return epr->action; | ||
5731 | } | ||
5732 | |||
5733 | EAPI Eina_Bool | ||
5734 | edje_edit_program_action_set(Evas_Object *obj, const char *prog, Edje_Action_Type action) | ||
5735 | { | ||
5736 | Program_Script *ps; | ||
5737 | |||
5738 | eina_error_set(0); | ||
5739 | |||
5740 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5741 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5742 | |||
5743 | //printf("SET ACTION for program: %s [%d]\n", prog, action); | ||
5744 | if (action >= EDJE_ACTION_TYPE_LAST) return EINA_FALSE; | ||
5745 | |||
5746 | if ((Edje_Action_Type)epr->action == action) | ||
5747 | return EINA_TRUE; | ||
5748 | |||
5749 | if (action == EDJE_ACTION_TYPE_SCRIPT) | ||
5750 | { | ||
5751 | ps = eina_hash_find(eed->program_scripts, &epr->id); | ||
5752 | if (!ps) | ||
5753 | { | ||
5754 | ps = _alloc(sizeof(Program_Script)); | ||
5755 | if (!ps) | ||
5756 | return EINA_FALSE; | ||
5757 | } | ||
5758 | ps->id = epr->id; | ||
5759 | ps->code = strdup(""); | ||
5760 | ps->dirty = EINA_TRUE; | ||
5761 | ps->delete_me = EINA_FALSE; | ||
5762 | eina_hash_set(eed->program_scripts, &ps->id, ps); | ||
5763 | _edje_edit_flag_script_dirty(eed, EINA_FALSE); | ||
5764 | } | ||
5765 | if (epr->action == EDJE_ACTION_TYPE_SCRIPT) | ||
5766 | { | ||
5767 | ps = eina_hash_find(eed->program_scripts, &epr->id); | ||
5768 | if (ps) | ||
5769 | { | ||
5770 | free(ps->code); | ||
5771 | free(ps->processed); | ||
5772 | ps->code = ps->processed = NULL; | ||
5773 | ps->dirty = EINA_FALSE; | ||
5774 | ps->delete_me = EINA_TRUE; | ||
5775 | _edje_edit_flag_script_dirty(eed, EINA_FALSE); | ||
5776 | } | ||
5777 | } | ||
5778 | |||
5779 | epr->action = action; | ||
5780 | return EINA_TRUE; | ||
5781 | } | ||
5782 | |||
5783 | EAPI Eina_List * | ||
5784 | edje_edit_program_targets_get(Evas_Object *obj, const char *prog) | ||
5785 | { | ||
5786 | Eina_List *l, *targets = NULL; | ||
5787 | Edje_Program_Target *t; | ||
5788 | |||
5789 | eina_error_set(0); | ||
5790 | |||
5791 | GET_ED_OR_RETURN(NULL); | ||
5792 | GET_EPR_OR_RETURN(NULL); | ||
5793 | |||
5794 | //printf("GET TARGETS for program: %s [count: %d]\n", prog, eina_list_count(epr->targets)); | ||
5795 | EINA_LIST_FOREACH(epr->targets, l, t) | ||
5796 | { | ||
5797 | if (epr->action == EDJE_ACTION_TYPE_STATE_SET) | ||
5798 | { | ||
5799 | /* the target is a part */ | ||
5800 | Edje_Real_Part *p = NULL; | ||
5801 | |||
5802 | p = ed->table_parts[t->id % ed->table_parts_size]; | ||
5803 | if (p && p->part && p->part->name) | ||
5804 | targets = eina_list_append(targets, | ||
5805 | eina_stringshare_add(p->part->name)); | ||
5806 | } | ||
5807 | else if (epr->action == EDJE_ACTION_TYPE_ACTION_STOP) | ||
5808 | { | ||
5809 | /* the target is a program */ | ||
5810 | Edje_Program *p; | ||
5811 | |||
5812 | p = ed->table_programs[t->id % ed->table_programs_size]; | ||
5813 | if (p && p->name) | ||
5814 | targets = eina_list_append(targets, | ||
5815 | eina_stringshare_add(p->name)); | ||
5816 | } | ||
5817 | } | ||
5818 | return targets; | ||
5819 | } | ||
5820 | |||
5821 | EAPI Eina_Bool | ||
5822 | edje_edit_program_targets_clear(Evas_Object *obj, const char *prog) | ||
5823 | { | ||
5824 | eina_error_set(0); | ||
5825 | |||
5826 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5827 | |||
5828 | while (epr->targets) | ||
5829 | { | ||
5830 | Edje_Program_Target *prt; | ||
5831 | |||
5832 | prt = eina_list_data_get(epr->targets); | ||
5833 | epr->targets = eina_list_remove_list(epr->targets, epr->targets); | ||
5834 | free(prt); | ||
5835 | } | ||
5836 | |||
5837 | return EINA_TRUE; | ||
5838 | } | ||
5839 | |||
5840 | EAPI Eina_Bool | ||
5841 | edje_edit_program_target_add(Evas_Object *obj, const char *prog, const char *target) | ||
5842 | { | ||
5843 | int id; | ||
5844 | Edje_Program_Target *t; | ||
5845 | |||
5846 | eina_error_set(0); | ||
5847 | |||
5848 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5849 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5850 | |||
5851 | if (epr->action == EDJE_ACTION_TYPE_STATE_SET) | ||
5852 | { | ||
5853 | /* the target is a part */ | ||
5854 | Edje_Real_Part *rp; | ||
5855 | |||
5856 | rp = _edje_real_part_get(ed, target); | ||
5857 | if (!rp) return EINA_FALSE; | ||
5858 | id = rp->part->id; | ||
5859 | } | ||
5860 | else if (epr->action == EDJE_ACTION_TYPE_ACTION_STOP) | ||
5861 | { | ||
5862 | /* the target is a program */ | ||
5863 | Edje_Program *tar; | ||
5864 | |||
5865 | tar = _edje_program_get_byname(obj, target); | ||
5866 | if (!tar) return EINA_FALSE; | ||
5867 | id = tar->id; | ||
5868 | } | ||
5869 | else | ||
5870 | return EINA_FALSE; | ||
5871 | |||
5872 | t = _alloc(sizeof(Edje_Program_Target)); | ||
5873 | if (!t) return EINA_FALSE; | ||
5874 | |||
5875 | t->id = id; | ||
5876 | epr->targets = eina_list_append(epr->targets, t); | ||
5877 | |||
5878 | return EINA_TRUE; | ||
5879 | } | ||
5880 | |||
5881 | EAPI Eina_Bool | ||
5882 | edje_edit_program_target_del(Evas_Object *obj, const char *prog, const char *target) | ||
5883 | { | ||
5884 | int id; | ||
5885 | Eina_List *l; | ||
5886 | Edje_Program_Target *t; | ||
5887 | |||
5888 | eina_error_set(0); | ||
5889 | |||
5890 | GET_ED_OR_RETURN(EINA_FALSE); | ||
5891 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5892 | |||
5893 | if (epr->action == EDJE_ACTION_TYPE_STATE_SET) | ||
5894 | { | ||
5895 | /* the target is a part */ | ||
5896 | Edje_Real_Part *rp; | ||
5897 | |||
5898 | rp = _edje_real_part_get(ed, target); | ||
5899 | if (!rp) return EINA_FALSE; | ||
5900 | id = rp->part->id; | ||
5901 | } | ||
5902 | else if (epr->action == EDJE_ACTION_TYPE_ACTION_STOP) | ||
5903 | { | ||
5904 | /* the target is a program */ | ||
5905 | Edje_Program *tar; | ||
5906 | |||
5907 | tar = _edje_program_get_byname(obj, target); | ||
5908 | if (!tar) return EINA_FALSE; | ||
5909 | id = tar->id; | ||
5910 | } | ||
5911 | else | ||
5912 | return EINA_FALSE; | ||
5913 | |||
5914 | EINA_LIST_FOREACH(epr->targets, l, t) | ||
5915 | if (t->id == id) | ||
5916 | break; | ||
5917 | epr->targets = eina_list_remove_list(epr->targets, l); | ||
5918 | free(t); | ||
5919 | |||
5920 | return EINA_TRUE; | ||
5921 | } | ||
5922 | |||
5923 | EAPI Eina_List * | ||
5924 | edje_edit_program_afters_get(Evas_Object *obj, const char *prog) | ||
5925 | { | ||
5926 | Eina_List *l, *afters = NULL; | ||
5927 | Edje_Program_After *a; | ||
5928 | |||
5929 | eina_error_set(0); | ||
5930 | |||
5931 | GET_ED_OR_RETURN(NULL); | ||
5932 | GET_EPR_OR_RETURN(NULL); | ||
5933 | |||
5934 | // printf("GET AFTERS for program: %s [count: %d]\n", prog, eina_list_count(epr->after)); | ||
5935 | EINA_LIST_FOREACH(epr->after, l, a) | ||
5936 | { | ||
5937 | Edje_Program *p = NULL; | ||
5938 | |||
5939 | p = ed->table_programs[a->id % ed->table_programs_size]; | ||
5940 | if (p && p->name) | ||
5941 | { | ||
5942 | //printf(" a: %d name: %s\n", a->id, p->name); | ||
5943 | afters = eina_list_append(afters, eina_stringshare_add(p->name)); | ||
5944 | } | ||
5945 | } | ||
5946 | return afters; | ||
5947 | } | ||
5948 | |||
5949 | EAPI Eina_Bool | ||
5950 | edje_edit_program_afters_clear(Evas_Object *obj, const char *prog) | ||
5951 | { | ||
5952 | eina_error_set(0); | ||
5953 | |||
5954 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5955 | |||
5956 | while (epr->after) | ||
5957 | { | ||
5958 | Edje_Program_After *pa; | ||
5959 | |||
5960 | pa = eina_list_data_get(epr->after); | ||
5961 | epr->after = eina_list_remove_list(epr->after, epr->after); | ||
5962 | free(pa); | ||
5963 | } | ||
5964 | |||
5965 | return EINA_TRUE; | ||
5966 | } | ||
5967 | |||
5968 | EAPI Eina_Bool | ||
5969 | edje_edit_program_after_add(Evas_Object *obj, const char *prog, const char *after) | ||
5970 | { | ||
5971 | Edje_Program *af; | ||
5972 | Edje_Program_After *a; | ||
5973 | |||
5974 | eina_error_set(0); | ||
5975 | |||
5976 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
5977 | |||
5978 | af = _edje_program_get_byname(obj, after); | ||
5979 | if (!af) return EINA_FALSE; | ||
5980 | |||
5981 | a = _alloc(sizeof(Edje_Program_After)); | ||
5982 | if (!a) return EINA_FALSE; | ||
5983 | |||
5984 | a->id = af->id; | ||
5985 | |||
5986 | epr->after = eina_list_append(epr->after, a); | ||
5987 | |||
5988 | return EINA_TRUE; | ||
5989 | } | ||
5990 | |||
5991 | EAPI Eina_Bool | ||
5992 | edje_edit_program_after_del(Evas_Object *obj, const char *prog, const char *after) | ||
5993 | { | ||
5994 | Edje_Program *af; | ||
5995 | Edje_Program_After *a; | ||
5996 | Eina_List *l; | ||
5997 | |||
5998 | eina_error_set(0); | ||
5999 | |||
6000 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
6001 | |||
6002 | af = _edje_program_get_byname(obj, after); | ||
6003 | if (!af) return EINA_FALSE; | ||
6004 | |||
6005 | EINA_LIST_FOREACH(epr->after, l, a) | ||
6006 | if (a->id == af->id) | ||
6007 | { | ||
6008 | epr->after = eina_list_remove_list(epr->after, l); | ||
6009 | break; | ||
6010 | } | ||
6011 | |||
6012 | return EINA_TRUE; | ||
6013 | } | ||
6014 | |||
6015 | EAPI const char * | ||
6016 | edje_edit_program_api_name_get(Evas_Object *obj, const char *prog) | ||
6017 | { | ||
6018 | eina_error_set(0); | ||
6019 | |||
6020 | GET_EPR_OR_RETURN(NULL); | ||
6021 | |||
6022 | return eina_stringshare_add(epr->api.name); | ||
6023 | } | ||
6024 | |||
6025 | EAPI const char * | ||
6026 | edje_edit_program_api_description_get(Evas_Object *obj, const char *prog) | ||
6027 | { | ||
6028 | eina_error_set(0); | ||
6029 | |||
6030 | GET_EPR_OR_RETURN(NULL); | ||
6031 | |||
6032 | return eina_stringshare_add(epr->api.description); | ||
6033 | } | ||
6034 | |||
6035 | EAPI Eina_Bool | ||
6036 | edje_edit_program_api_name_set(Evas_Object *obj, const char *prog, const char* name) | ||
6037 | { | ||
6038 | eina_error_set(0); | ||
6039 | |||
6040 | GET_ED_OR_RETURN(EINA_FALSE); | ||
6041 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
6042 | |||
6043 | _edje_if_string_free(ed, epr->api.name); | ||
6044 | epr->api.name = eina_stringshare_add(name); | ||
6045 | |||
6046 | return EINA_TRUE; | ||
6047 | } | ||
6048 | |||
6049 | EAPI Eina_Bool | ||
6050 | edje_edit_program_api_description_set(Evas_Object *obj, const char *prog, const char *description) | ||
6051 | { | ||
6052 | eina_error_set(0); | ||
6053 | |||
6054 | GET_ED_OR_RETURN(EINA_FALSE); | ||
6055 | GET_EPR_OR_RETURN(EINA_FALSE); | ||
6056 | |||
6057 | _edje_if_string_free(ed, epr->api.description); | ||
6058 | epr->api.description = eina_stringshare_add(description); | ||
6059 | |||
6060 | return EINA_TRUE; | ||
6061 | } | ||
6062 | |||
6063 | /*************************/ | ||
6064 | /* EMBRYO SCRIPTS API */ | ||
6065 | /*************************/ | ||
6066 | EAPI char * | ||
6067 | edje_edit_script_get(Evas_Object *obj) | ||
6068 | { | ||
6069 | eina_error_set(0); | ||
6070 | |||
6071 | GET_ED_OR_RETURN(NULL); | ||
6072 | |||
6073 | if (!ed->collection) return NULL; | ||
6074 | if (!eed->embryo_source) return NULL; | ||
6075 | |||
6076 | return strdup(eed->embryo_source); | ||
6077 | } | ||
6078 | |||
6079 | EAPI void | ||
6080 | edje_edit_script_set(Evas_Object *obj, const char *code) | ||
6081 | { | ||
6082 | eina_error_set(0); | ||
6083 | |||
6084 | GET_ED_OR_RETURN(); | ||
6085 | |||
6086 | free(eed->embryo_source); | ||
6087 | free(eed->embryo_processed); | ||
6088 | |||
6089 | if (code) | ||
6090 | eed->embryo_source = strdup(code); | ||
6091 | else | ||
6092 | eed->embryo_source = NULL; | ||
6093 | eed->embryo_processed = NULL; | ||
6094 | |||
6095 | eed->embryo_source_dirty = EINA_TRUE; | ||
6096 | |||
6097 | _edje_edit_flag_script_dirty(eed, EINA_FALSE); | ||
6098 | } | ||
6099 | |||
6100 | EAPI char * | ||
6101 | edje_edit_script_program_get(Evas_Object *obj, const char *prog) | ||
6102 | { | ||
6103 | Program_Script *ps; | ||
6104 | |||
6105 | eina_error_set(0); | ||
6106 | |||
6107 | GET_ED_OR_RETURN(NULL); | ||
6108 | GET_EPR_OR_RETURN(NULL); | ||
6109 | |||
6110 | if (epr->action != EDJE_ACTION_TYPE_SCRIPT) | ||
6111 | return NULL; | ||
6112 | |||
6113 | ps = eina_hash_find(eed->program_scripts, prog); | ||
6114 | if (!ps) /* mmm? it should be there, even if empty */ | ||
6115 | return NULL; | ||
6116 | |||
6117 | return ps->code ? strdup(ps->code) : NULL; | ||
6118 | } | ||
6119 | |||
6120 | EAPI void | ||
6121 | edje_edit_script_program_set(Evas_Object *obj, const char *prog, const char *code) | ||
6122 | { | ||
6123 | Program_Script *ps; | ||
6124 | |||
6125 | eina_error_set(0); | ||
6126 | |||
6127 | GET_ED_OR_RETURN(); | ||
6128 | GET_EPR_OR_RETURN(); | ||
6129 | |||
6130 | if (epr->action != EDJE_ACTION_TYPE_SCRIPT) | ||
6131 | return; | ||
6132 | |||
6133 | ps = eina_hash_find(eed->program_scripts, prog); | ||
6134 | if (!ps) /* ???? how so? */ | ||
6135 | return; | ||
6136 | |||
6137 | free(ps->code); | ||
6138 | free(ps->processed); | ||
6139 | |||
6140 | if (code) | ||
6141 | ps->code = strdup(code); | ||
6142 | else | ||
6143 | ps->code = NULL; | ||
6144 | ps->processed = NULL; | ||
6145 | ps->dirty = EINA_TRUE; | ||
6146 | |||
6147 | _edje_edit_flag_script_dirty(eed, EINA_FALSE); | ||
6148 | } | ||
6149 | |||
6150 | static int | ||
6151 | __part_replace(Edje_Edit *eed, char *pcode, char *name) | ||
6152 | { | ||
6153 | int id; | ||
6154 | |||
6155 | id = _edje_part_id_find((Edje *)eed, name); | ||
6156 | if (id < 0) | ||
6157 | return 0; | ||
6158 | return eina_convert_itoa(id, pcode); | ||
6159 | } | ||
6160 | |||
6161 | static int | ||
6162 | __program_replace(Edje_Edit *eed, char *pcode, char *name) | ||
6163 | { | ||
6164 | int id; | ||
6165 | |||
6166 | id = _edje_program_id_find(eed, name); | ||
6167 | if (id < 0) | ||
6168 | return 0; | ||
6169 | return eina_convert_itoa(id, pcode); | ||
6170 | } | ||
6171 | |||
6172 | static int | ||
6173 | __group_replace(Edje_Edit *eed __UNUSED__, char *pcode, char *name) | ||
6174 | { | ||
6175 | strcpy(pcode, name); | ||
6176 | return strlen(name) + 1; | ||
6177 | } | ||
6178 | |||
6179 | static int | ||
6180 | __image_replace(Edje_Edit *eed, char *pcode, char *name) | ||
6181 | { | ||
6182 | int id; | ||
6183 | |||
6184 | id = _edje_image_id_find(eed, name); | ||
6185 | if (id < 0) | ||
6186 | return 0; | ||
6187 | return eina_convert_itoa(id, pcode); | ||
6188 | } | ||
6189 | |||
6190 | static char * | ||
6191 | _edje_edit_script_process(Edje_Edit *eed, const char *progname, char *code) | ||
6192 | { | ||
6193 | char *pcode, *psrc, *pdst; | ||
6194 | int codesize, pcodesize; | ||
6195 | int quoted = 0, escaped = 0; | ||
6196 | int line = 1; | ||
6197 | Eina_Bool success = EINA_TRUE; | ||
6198 | |||
6199 | codesize = strlen(code); | ||
6200 | pcode = malloc(codesize + 1); | ||
6201 | if (!pcode) | ||
6202 | return NULL; | ||
6203 | |||
6204 | pcodesize = 0; | ||
6205 | psrc = code; | ||
6206 | pdst = pcode; | ||
6207 | while (*psrc) | ||
6208 | { | ||
6209 | if (!quoted) | ||
6210 | { | ||
6211 | char *ptr = NULL; | ||
6212 | const char *what = NULL; | ||
6213 | int (*func)(Edje_Edit *, char *, char *); | ||
6214 | |||
6215 | if (*psrc == 'P') | ||
6216 | { | ||
6217 | if (!strncmp(psrc, "PART:\"", 6)) | ||
6218 | { | ||
6219 | psrc += 6; | ||
6220 | ptr = psrc; | ||
6221 | func = __part_replace; | ||
6222 | what = "part"; | ||
6223 | } | ||
6224 | else if (!strncmp(psrc, "PROGRAM:\"", 9)) | ||
6225 | { | ||
6226 | psrc += 9; | ||
6227 | ptr = psrc; | ||
6228 | func = __program_replace; | ||
6229 | what = "program"; | ||
6230 | } | ||
6231 | } | ||
6232 | else if (*psrc == 'G') | ||
6233 | { | ||
6234 | if (!strncmp(psrc, "GROUP:\"", 7)) | ||
6235 | { | ||
6236 | psrc += 7; | ||
6237 | ptr = psrc; | ||
6238 | func = __group_replace; | ||
6239 | what = "group"; | ||
6240 | } | ||
6241 | } | ||
6242 | else if (*psrc == 'I') | ||
6243 | { | ||
6244 | if (!strncmp(psrc, "IMAGE:\"", 7)) | ||
6245 | { | ||
6246 | psrc += 7; | ||
6247 | ptr = psrc; | ||
6248 | func = __image_replace; | ||
6249 | what = "image"; | ||
6250 | } | ||
6251 | } | ||
6252 | else if (*psrc == '#') | ||
6253 | { | ||
6254 | while (*psrc) | ||
6255 | if (*psrc == '\n') | ||
6256 | break; | ||
6257 | line++; | ||
6258 | continue; | ||
6259 | } | ||
6260 | else if (*psrc == '\"') | ||
6261 | quoted = 1; | ||
6262 | else if (*psrc == '\n') | ||
6263 | line++; | ||
6264 | |||
6265 | if (ptr) | ||
6266 | { | ||
6267 | int i = 0, inesc = 0; | ||
6268 | char *name; | ||
6269 | while (*psrc) | ||
6270 | { | ||
6271 | if (!inesc) | ||
6272 | { | ||
6273 | if (*psrc == '\\') | ||
6274 | inesc = 1; | ||
6275 | else if (*psrc == '\"') | ||
6276 | { | ||
6277 | /* string concatenation as in "foo""bar" */ | ||
6278 | if (*(psrc + 1) != '\"') | ||
6279 | { | ||
6280 | psrc++; | ||
6281 | break; | ||
6282 | } | ||
6283 | else | ||
6284 | psrc++; | ||
6285 | } | ||
6286 | } | ||
6287 | else | ||
6288 | inesc = 0; | ||
6289 | psrc++; | ||
6290 | } | ||
6291 | name = alloca(psrc - ptr); | ||
6292 | inesc = 0; | ||
6293 | while (*ptr) | ||
6294 | { | ||
6295 | if (!inesc) | ||
6296 | { | ||
6297 | if (*ptr == '\\') | ||
6298 | inesc = 1; | ||
6299 | else if (*ptr == '\"') | ||
6300 | { | ||
6301 | if (*(ptr + 1) == '\"') | ||
6302 | ptr++; | ||
6303 | else | ||
6304 | { | ||
6305 | name[i] = 0; | ||
6306 | break; | ||
6307 | } | ||
6308 | } | ||
6309 | else | ||
6310 | { | ||
6311 | name[i] = *ptr; | ||
6312 | name[i + 1] = 0; | ||
6313 | i++; | ||
6314 | } | ||
6315 | } | ||
6316 | else | ||
6317 | inesc = 0; | ||
6318 | ptr++; | ||
6319 | } | ||
6320 | i = func(eed, pdst, name); | ||
6321 | if (!i) | ||
6322 | { | ||
6323 | Edje_Edit_Script_Error *se; | ||
6324 | se = malloc(sizeof(Edje_Edit_Script_Error)); | ||
6325 | se->program_name = progname ? | ||
6326 | eina_stringshare_add(progname) : NULL; | ||
6327 | se->line = line; | ||
6328 | se->error_str = eina_stringshare_printf( | ||
6329 | "Referenced %s '%s' could not be found in object.", | ||
6330 | what, name); | ||
6331 | eed->errors = eina_list_append(eed->errors, se); | ||
6332 | success = EINA_FALSE; | ||
6333 | } | ||
6334 | else | ||
6335 | { | ||
6336 | pcodesize += i; | ||
6337 | pdst += i; | ||
6338 | } | ||
6339 | /* replaced reference for the right value, now go | ||
6340 | * to the next iteration */ | ||
6341 | continue; | ||
6342 | } | ||
6343 | } | ||
6344 | else | ||
6345 | { | ||
6346 | if (!escaped) | ||
6347 | { | ||
6348 | if (*psrc == '\"') | ||
6349 | quoted = 0; | ||
6350 | else if (*psrc == '\\') | ||
6351 | escaped = 1; | ||
6352 | } | ||
6353 | else if (escaped) | ||
6354 | escaped = 0; | ||
6355 | } | ||
6356 | *pdst = *psrc; | ||
6357 | pdst++; | ||
6358 | psrc++; | ||
6359 | pcodesize++; | ||
6360 | } | ||
6361 | |||
6362 | if (!success) | ||
6363 | { | ||
6364 | free(pcode); | ||
6365 | return NULL; | ||
6366 | } | ||
6367 | |||
6368 | if (pcodesize < codesize) | ||
6369 | pcode = realloc(pcode, pcodesize + 1); | ||
6370 | pcode[pcodesize] = 0; | ||
6371 | |||
6372 | return pcode; | ||
6373 | } | ||
6374 | |||
6375 | static Eina_Bool | ||
6376 | _edje_edit_embryo_rebuild(Edje_Edit *eed) | ||
6377 | { | ||
6378 | FILE *f; | ||
6379 | int fd, size, ret; | ||
6380 | const char *tmp_dir; | ||
6381 | char tmp_in[PATH_MAX]; | ||
6382 | char tmp_out[PATH_MAX]; | ||
6383 | char buf[4096]; | ||
6384 | Eina_Iterator *it; | ||
6385 | Program_Script *ps; | ||
6386 | Edje_Part_Collection *edc; | ||
6387 | Eina_Bool success = EINA_TRUE; /* we are optimists! */ | ||
6388 | Edje_Edit_Script_Error *se; | ||
6389 | |||
6390 | EINA_LIST_FREE(eed->errors, se) | ||
6391 | { | ||
6392 | eina_stringshare_del(se->program_name); | ||
6393 | eina_stringshare_del(se->error_str); | ||
6394 | free(se); | ||
6395 | } | ||
6396 | |||
6397 | #ifdef HAVE_EVIL | ||
6398 | tmp_dir = evil_tmpdir_get(); | ||
6399 | #else | ||
6400 | tmp_dir = "/tmp"; | ||
6401 | #endif | ||
6402 | |||
6403 | snprintf(tmp_in, sizeof(tmp_in), "%s/edje_edit.sma-tmp-XXXXXX", tmp_dir); | ||
6404 | snprintf(tmp_out, sizeof(tmp_out), "%s/edje_edit.amx-tmp-XXXXXX", tmp_dir); | ||
6405 | |||
6406 | fd = mkstemp(tmp_in); | ||
6407 | if (fd < 0) | ||
6408 | return EINA_FALSE; /* FIXME: report something */ | ||
6409 | |||
6410 | f = fdopen(fd, "w"); | ||
6411 | if (!f) | ||
6412 | { | ||
6413 | close(fd); | ||
6414 | unlink(tmp_in); | ||
6415 | return EINA_FALSE; | ||
6416 | } | ||
6417 | |||
6418 | fprintf(f, "#include <edje>\n"); | ||
6419 | if (eed->embryo_source) | ||
6420 | { | ||
6421 | if (eed->all_dirty) | ||
6422 | { | ||
6423 | free(eed->embryo_processed); | ||
6424 | eed->embryo_processed = NULL; | ||
6425 | } | ||
6426 | if (!eed->embryo_processed) | ||
6427 | eed->embryo_processed = _edje_edit_script_process(eed, NULL, | ||
6428 | eed->embryo_source); | ||
6429 | if (!eed->embryo_processed) | ||
6430 | { | ||
6431 | /* oops.. an error finding references parts or something. | ||
6432 | * we could flag it and do some lighter processing of the | ||
6433 | * rest of the scripts, in order to find all the errors of | ||
6434 | * this kind and report them at once, but knowing already | ||
6435 | * that the script will not compile we can avoid some work | ||
6436 | */ | ||
6437 | success = EINA_FALSE; | ||
6438 | } | ||
6439 | else | ||
6440 | fprintf(f, "%s", eed->embryo_processed); | ||
6441 | } | ||
6442 | |||
6443 | it = eina_hash_iterator_data_new(eed->program_scripts); | ||
6444 | EINA_ITERATOR_FOREACH(it, ps) | ||
6445 | { | ||
6446 | Edje_Program *epr; | ||
6447 | |||
6448 | if (ps->delete_me) | ||
6449 | continue; | ||
6450 | if (eed->all_dirty) | ||
6451 | { | ||
6452 | free(ps->processed); | ||
6453 | ps->processed = NULL; | ||
6454 | } | ||
6455 | epr = eed->base.table_programs[ps->id]; | ||
6456 | if (!ps->processed) | ||
6457 | ps->processed = _edje_edit_script_process(eed, epr->name, ps->code); | ||
6458 | if (!ps->processed) | ||
6459 | { | ||
6460 | /* oops.. an error finding references parts or something. | ||
6461 | * we could flag it and do some lighter processing of the | ||
6462 | * rest of the scripts, in order to find all the errors of | ||
6463 | * this kind and report them at once, but knowing already | ||
6464 | * that the script will not compile we can avoid some work | ||
6465 | */ | ||
6466 | success = EINA_FALSE; | ||
6467 | continue; | ||
6468 | } | ||
6469 | fprintf(f, "public _p%i(sig[], src[]) {\n", ps->id); | ||
6470 | fprintf(f, "%s", ps->processed); | ||
6471 | fprintf(f, "}\n"); | ||
6472 | } | ||
6473 | eina_iterator_free(it); | ||
6474 | |||
6475 | fclose(f); | ||
6476 | |||
6477 | if (!success) | ||
6478 | goto almost_out; | ||
6479 | |||
6480 | fd = mkstemp(tmp_out); | ||
6481 | if (fd < 0) | ||
6482 | { | ||
6483 | success = EINA_FALSE; | ||
6484 | goto almost_out; | ||
6485 | } | ||
6486 | |||
6487 | snprintf(buf, sizeof(buf), "embryo_cc -i %s/include -o %s %s", | ||
6488 | PACKAGE_DATA_DIR, tmp_out, tmp_in); | ||
6489 | ret = system(buf); | ||
6490 | |||
6491 | if ((ret < 0) || (ret > 1)) | ||
6492 | { | ||
6493 | success = EINA_FALSE; | ||
6494 | close(fd); | ||
6495 | goto the_doorway; | ||
6496 | } | ||
6497 | |||
6498 | f = fdopen(fd, "rb"); | ||
6499 | if (!f) | ||
6500 | { | ||
6501 | success = EINA_FALSE; | ||
6502 | close(fd); | ||
6503 | goto the_doorway; | ||
6504 | } | ||
6505 | |||
6506 | fseek(f, 0, SEEK_END); | ||
6507 | size = ftell(f); | ||
6508 | rewind(f); | ||
6509 | |||
6510 | free(eed->bytecode); | ||
6511 | if (size > 0) | ||
6512 | { | ||
6513 | eed->bytecode = malloc(size); | ||
6514 | if (!eed->bytecode) | ||
6515 | { | ||
6516 | success = EINA_FALSE; | ||
6517 | goto the_way_out; | ||
6518 | } | ||
6519 | if (fread(eed->bytecode, size, 1, f) != 1) | ||
6520 | { | ||
6521 | success = EINA_FALSE; | ||
6522 | goto the_way_out; | ||
6523 | } | ||
6524 | } | ||
6525 | else | ||
6526 | eed->bytecode = NULL; /* correctness mostly, I don't see why we | ||
6527 | would get a 0 sized program */ | ||
6528 | |||
6529 | eed->bytecode_size = size; | ||
6530 | eed->bytecode_dirty = EINA_TRUE; | ||
6531 | eed->script_need_recompile = EINA_FALSE; | ||
6532 | eed->all_dirty = EINA_FALSE; | ||
6533 | |||
6534 | edc = eed->base.collection; | ||
6535 | embryo_program_free(edc->script); | ||
6536 | edc->script = embryo_program_new(eed->bytecode, eed->bytecode_size); | ||
6537 | _edje_embryo_script_init(edc); | ||
6538 | _edje_var_init((Edje *)eed); | ||
6539 | |||
6540 | the_way_out: | ||
6541 | fclose(f); | ||
6542 | the_doorway: | ||
6543 | unlink(tmp_out); | ||
6544 | almost_out: | ||
6545 | unlink(tmp_in); | ||
6546 | |||
6547 | return success; | ||
6548 | } | ||
6549 | |||
6550 | EAPI Eina_Bool | ||
6551 | edje_edit_script_compile(Evas_Object *obj) | ||
6552 | { | ||
6553 | GET_ED_OR_RETURN(EINA_FALSE); | ||
6554 | |||
6555 | if (!eed->script_need_recompile) | ||
6556 | return EINA_TRUE; | ||
6557 | |||
6558 | return _edje_edit_embryo_rebuild(eed); | ||
6559 | } | ||
6560 | |||
6561 | EAPI const Eina_List * | ||
6562 | edje_edit_script_error_list_get(Evas_Object *obj) | ||
6563 | { | ||
6564 | GET_ED_OR_RETURN(NULL); | ||
6565 | return eed->errors; | ||
6566 | } | ||
6567 | |||
6568 | /***************************/ | ||
6569 | /* EDC SOURCE GENERATION */ | ||
6570 | /***************************/ | ||
6571 | #define I0 "" | ||
6572 | #define I1 " " | ||
6573 | #define I2 " " | ||
6574 | #define I3 " " | ||
6575 | #define I4 " " | ||
6576 | #define I5 " " | ||
6577 | #define I6 " " | ||
6578 | #define I7 " " | ||
6579 | |||
6580 | #define BUF_APPEND(STR) \ | ||
6581 | ret &= eina_strbuf_append(buf, STR) | ||
6582 | |||
6583 | #define BUF_APPENDF(FMT, ...) \ | ||
6584 | ret &= eina_strbuf_append_printf(buf, FMT, ##__VA_ARGS__) | ||
6585 | |||
6586 | static const char *types[] = {"NONE", "RECT", "TEXT", "IMAGE", "SWALLOW", "TEXTBLOCK", "GRADIENT", "GROUP", "BOX", "TABLE", "EXTERNAL"}; | ||
6587 | static const char *effects[] = {"NONE", "PLAIN", "OUTLINE", "SOFT_OUTLINE", "SHADOW", "SOFT_SHADOW", "OUTLINE_SHADOW", "OUTLINE_SOFT_SHADOW ", "FAR_SHADOW ", "FAR_SOFT_SHADOW", "GLOW"}; | ||
6588 | static const char *prefers[] = {"NONE", "VERTICAL", "HORIZONTAL", "BOTH"}; | ||
6589 | |||
6590 | static Eina_Bool | ||
6591 | _edje_generate_source_of_colorclass(Edje * ed, const char *name, Eina_Strbuf *buf) | ||
6592 | { | ||
6593 | Eina_List *l; | ||
6594 | Edje_Color_Class *cc; | ||
6595 | Eina_Bool ret = EINA_TRUE; | ||
6596 | |||
6597 | EINA_LIST_FOREACH(ed->file->color_classes, l, cc) | ||
6598 | if (!strcmp(cc->name, name)) | ||
6599 | { | ||
6600 | BUF_APPENDF(I1 "color_class { name: \"%s\";\n", cc->name); | ||
6601 | BUF_APPENDF(I2 "color: %d %d %d %d;\n", cc->r, cc->g, cc->b, cc->a); | ||
6602 | BUF_APPENDF(I2 "color2: %d %d %d %d;\n", cc->r2, cc->g2, cc->b2, cc->a2); | ||
6603 | BUF_APPENDF(I2 "color3: %d %d %d %d;\n", cc->r3, cc->g3, cc->b3, cc->a3); | ||
6604 | BUF_APPEND(I1 "}\n"); | ||
6605 | } | ||
6606 | return ret; | ||
6607 | } | ||
6608 | |||
6609 | static Eina_Bool | ||
6610 | _edje_generate_source_of_style(Edje * ed, const char *name, Eina_Strbuf *buf) | ||
6611 | { | ||
6612 | Eina_List *l, *ll; | ||
6613 | Edje_Style *s; | ||
6614 | Edje_Style_Tag *t; | ||
6615 | Eina_Bool ret = EINA_TRUE; | ||
6616 | |||
6617 | EINA_LIST_FOREACH(ed->file->styles, l, s) | ||
6618 | if (!strcmp(s->name, name)) | ||
6619 | { | ||
6620 | t = s->tags ? s->tags->data : NULL; | ||
6621 | BUF_APPENDF(I1 "style { name:\"%s\";\n", s->name); | ||
6622 | if (t && t->value) | ||
6623 | BUF_APPENDF(I2 "base: \"%s\";\n", t->value); | ||
6624 | |||
6625 | EINA_LIST_FOREACH(s->tags, ll, t) | ||
6626 | if (ll->prev && t && t->value) | ||
6627 | BUF_APPENDF(I2 "tag: \"%s\" \"%s\";\n", t->key, | ||
6628 | t->value); | ||
6629 | BUF_APPEND(I1 "}\n"); | ||
6630 | return ret; | ||
6631 | } | ||
6632 | return EINA_FALSE; | ||
6633 | } | ||
6634 | |||
6635 | static Eina_Bool | ||
6636 | _edje_generate_source_of_program(Evas_Object *obj, const char *program, Eina_Strbuf *buf) | ||
6637 | { | ||
6638 | Eina_List *l, *ll; | ||
6639 | const char *s, *s2; | ||
6640 | double db, db2; | ||
6641 | char *data; | ||
6642 | Eina_Bool ret = EINA_TRUE; | ||
6643 | const char *api_name, *api_description; | ||
6644 | Edje_Program *epr; | ||
6645 | |||
6646 | GET_ED_OR_RETURN(EINA_FALSE); | ||
6647 | |||
6648 | epr = _edje_program_get_byname(obj, program); | ||
6649 | |||
6650 | BUF_APPENDF(I3"program { name: \"%s\";\n", program); | ||
6651 | |||
6652 | /* Signal */ | ||
6653 | if ((s = edje_edit_program_signal_get(obj, program))) | ||
6654 | { | ||
6655 | BUF_APPENDF(I4"signal: \"%s\";\n", s); | ||
6656 | edje_edit_string_free(s); | ||
6657 | } | ||
6658 | |||
6659 | /* Source */ | ||
6660 | if ((s = edje_edit_program_source_get(obj, program))) | ||
6661 | { | ||
6662 | BUF_APPENDF(I4"source: \"%s\";\n", s); | ||
6663 | edje_edit_string_free(s); | ||
6664 | } | ||
6665 | |||
6666 | /* Action */ | ||
6667 | switch (edje_edit_program_action_get(obj, program)) | ||
6668 | { | ||
6669 | case EDJE_ACTION_TYPE_ACTION_STOP: | ||
6670 | BUF_APPEND(I4"action: ACTION_STOP;\n"); | ||
6671 | break; | ||
6672 | case EDJE_ACTION_TYPE_STATE_SET: | ||
6673 | if ((s = edje_edit_program_state_get(obj, program))) | ||
6674 | { | ||
6675 | BUF_APPENDF(I4"action: STATE_SET \"%s\" %.2f;\n", s, | ||
6676 | edje_edit_program_value_get(obj, program)); | ||
6677 | edje_edit_string_free(s); | ||
6678 | } | ||
6679 | break; | ||
6680 | case EDJE_ACTION_TYPE_SIGNAL_EMIT: | ||
6681 | s = edje_edit_program_state_get(obj, program); | ||
6682 | s2 = edje_edit_program_state2_get(obj, program); | ||
6683 | if (s && s2) | ||
6684 | { | ||
6685 | BUF_APPENDF(I4"action: SIGNAL_EMIT \"%s\" \"%s\";\n", s, s2); | ||
6686 | edje_edit_string_free(s); | ||
6687 | edje_edit_string_free(s2); | ||
6688 | } | ||
6689 | break; | ||
6690 | case EDJE_ACTION_TYPE_SCRIPT: | ||
6691 | { | ||
6692 | Program_Script *ps; | ||
6693 | |||
6694 | ps = eina_hash_find(eed->program_scripts, &epr->id); | ||
6695 | if (ps && !ps->delete_me) | ||
6696 | { | ||
6697 | BUF_APPEND(I4"script {\n"); | ||
6698 | BUF_APPEND(ps->code); | ||
6699 | BUF_APPEND(I4"}\n"); | ||
6700 | } | ||
6701 | } | ||
6702 | break; | ||
6703 | //TODO Support Drag | ||
6704 | //~ case EDJE_ACTION_TYPE_DRAG_VAL_SET: | ||
6705 | //~ eina_strbuf_append(buf, I4"action: DRAG_VAL_SET TODO;\n"); | ||
6706 | //~ break; | ||
6707 | //~ case EDJE_ACTION_TYPE_DRAG_VAL_STEP: | ||
6708 | //~ eina_strbuf_append(buf, I4"action: DRAG_VAL_STEP TODO;\n"); | ||
6709 | //~ break; | ||
6710 | //~ case EDJE_ACTION_TYPE_DRAG_VAL_PAGE: | ||
6711 | //~ eina_strbuf_append(buf, I4"action: DRAG_VAL_PAGE TODO;\n"); | ||
6712 | //~ break; | ||
6713 | default: | ||
6714 | break; | ||
6715 | } | ||
6716 | |||
6717 | /* Transition */ | ||
6718 | db = edje_edit_program_transition_time_get(obj, program); | ||
6719 | switch (edje_edit_program_transition_get(obj, program)) | ||
6720 | { | ||
6721 | case EDJE_TWEEN_MODE_LINEAR: | ||
6722 | if (db) | ||
6723 | BUF_APPENDF(I4"transition: LINEAR %.5f;\n", db); | ||
6724 | break; | ||
6725 | case EDJE_TWEEN_MODE_ACCELERATE: | ||
6726 | BUF_APPENDF(I4"transition: ACCELERATE %.5f;\n", db); | ||
6727 | break; | ||
6728 | case EDJE_TWEEN_MODE_DECELERATE: | ||
6729 | BUF_APPENDF(I4"transition: DECELERATE %.5f;\n", db); | ||
6730 | break; | ||
6731 | case EDJE_TWEEN_MODE_SINUSOIDAL: | ||
6732 | BUF_APPENDF(I4"transition: SINUSOIDAL %.5f;\n", db); | ||
6733 | break; | ||
6734 | default: | ||
6735 | break; | ||
6736 | } | ||
6737 | |||
6738 | /* In */ | ||
6739 | db = edje_edit_program_in_from_get(obj, program); | ||
6740 | db2 = edje_edit_program_in_range_get(obj, program); | ||
6741 | if (db || db2) | ||
6742 | BUF_APPENDF(I4"in: %.5f %.5f;\n", db, db2); | ||
6743 | |||
6744 | /* Targets */ | ||
6745 | if ((ll = edje_edit_program_targets_get(obj, program))) | ||
6746 | { | ||
6747 | EINA_LIST_FOREACH(ll, l, data) | ||
6748 | BUF_APPENDF(I4"target: \"%s\";\n", data); | ||
6749 | edje_edit_string_list_free(ll); | ||
6750 | } | ||
6751 | |||
6752 | /* Afters */ | ||
6753 | if ((ll = edje_edit_program_afters_get(obj, program))) | ||
6754 | { | ||
6755 | EINA_LIST_FOREACH(ll, l, data) | ||
6756 | BUF_APPENDF(I4"after: \"%s\";\n", data); | ||
6757 | edje_edit_string_list_free(ll); | ||
6758 | } | ||
6759 | |||
6760 | // TODO Support script {} | ||
6761 | /* api */ | ||
6762 | api_name = edje_edit_program_api_name_get(obj, program); | ||
6763 | api_description = edje_edit_program_api_description_get(obj, program); | ||
6764 | |||
6765 | if (api_name || api_description) | ||
6766 | { | ||
6767 | if (api_name && api_description) | ||
6768 | { | ||
6769 | BUF_APPENDF(I4"api: \"%s\" \"%s\";\n", api_name, api_description); | ||
6770 | edje_edit_string_free(api_name); | ||
6771 | edje_edit_string_free(api_description); | ||
6772 | } | ||
6773 | else | ||
6774 | if (api_name) | ||
6775 | { | ||
6776 | BUF_APPENDF(I4"api: \"%s\" \"\";\n", api_name); | ||
6777 | edje_edit_string_free(api_name); | ||
6778 | } | ||
6779 | else | ||
6780 | { | ||
6781 | BUF_APPENDF(I4"api: \"\" \"%s\";\n", api_description); | ||
6782 | edje_edit_string_free(api_description); | ||
6783 | } | ||
6784 | } | ||
6785 | |||
6786 | BUF_APPEND(I3 "}\n"); | ||
6787 | return ret; | ||
6788 | } | ||
6789 | |||
6790 | static Eina_Bool | ||
6791 | _edje_generate_source_of_state(Evas_Object *obj, const char *part, const char *state, double value, Eina_Strbuf *buf) | ||
6792 | { | ||
6793 | Eina_List *l, *ll; | ||
6794 | Eina_Bool ret = EINA_TRUE; | ||
6795 | |||
6796 | GET_PD_OR_RETURN(EINA_FALSE); | ||
6797 | |||
6798 | BUF_APPENDF(I4"description { state: \"%s\" %g;\n", pd->state.name, pd->state.value); | ||
6799 | //TODO Support inherit | ||
6800 | |||
6801 | if (!pd->visible) | ||
6802 | BUF_APPEND(I5"visible: 0;\n"); | ||
6803 | |||
6804 | if (pd->align.x != 0.5 || pd->align.y != 0.5) | ||
6805 | BUF_APPENDF(I5"align: %g %g;\n", TO_DOUBLE(pd->align.x), TO_DOUBLE(pd->align.y)); | ||
6806 | |||
6807 | //TODO Support fixed | ||
6808 | |||
6809 | if (pd->min.w || pd->min.h) | ||
6810 | BUF_APPENDF(I5"min: %d %d;\n", pd->min.w, pd->min.h); | ||
6811 | if (pd->max.w != -1 || pd->max.h != -1) | ||
6812 | BUF_APPENDF(I5"max: %d %d;\n", pd->max.w, pd->max.h); | ||
6813 | |||
6814 | //TODO Support step | ||
6815 | |||
6816 | if (pd->aspect.min || pd->aspect.max) | ||
6817 | BUF_APPENDF(I5"aspect: %g %g;\n", TO_DOUBLE(pd->aspect.min), TO_DOUBLE(pd->aspect.max)); | ||
6818 | if (pd->aspect.prefer) | ||
6819 | BUF_APPENDF(I5"aspect_preference: %s;\n", prefers[pd->aspect.prefer]); | ||
6820 | |||
6821 | if (pd->color_class) | ||
6822 | BUF_APPENDF(I5"color_class: \"%s\";\n", pd->color_class); | ||
6823 | |||
6824 | if (pd->color.r != 255 || pd->color.g != 255 || | ||
6825 | pd->color.b != 255 || pd->color.a != 255) | ||
6826 | BUF_APPENDF(I5"color: %d %d %d %d;\n", | ||
6827 | pd->color.r, pd->color.g, pd->color.b, pd->color.a); | ||
6828 | if (pd->color2.r != 0 || pd->color2.g != 0 || | ||
6829 | pd->color2.b != 0 || pd->color2.a != 255) | ||
6830 | BUF_APPENDF(I5"color2: %d %d %d %d;\n", | ||
6831 | pd->color2.r, pd->color2.g, pd->color2.b, pd->color2.a); | ||
6832 | |||
6833 | if (rp->part->type == EDJE_PART_TYPE_TEXT | ||
6834 | || rp->part->type == EDJE_PART_TYPE_TEXTBLOCK) | ||
6835 | { | ||
6836 | Edje_Part_Description_Text *txt; | ||
6837 | |||
6838 | txt = (Edje_Part_Description_Text *) pd; | ||
6839 | |||
6840 | if (txt->text.color3.r != 0 || txt->text.color3.g != 0 || | ||
6841 | txt->text.color3.b != 0 || txt->text.color3.a != 128) | ||
6842 | BUF_APPENDF(I5"color3: %d %d %d %d;\n", | ||
6843 | txt->text.color3.r, txt->text.color3.g, txt->text.color3.b, txt->text.color3.a); | ||
6844 | } | ||
6845 | |||
6846 | //Rel1 | ||
6847 | if (pd->rel1.relative_x || pd->rel1.relative_y || pd->rel1.offset_x || | ||
6848 | pd->rel1.offset_y || pd->rel1.id_x != -1 || pd->rel1.id_y != -1) | ||
6849 | { | ||
6850 | BUF_APPEND(I5"rel1 {\n"); | ||
6851 | if (pd->rel1.relative_x || pd->rel1.relative_y) | ||
6852 | BUF_APPENDF(I6"relative: %g %g;\n", TO_DOUBLE(pd->rel1.relative_x), TO_DOUBLE(pd->rel1.relative_y)); | ||
6853 | if (pd->rel1.offset_x || pd->rel1.offset_y) | ||
6854 | BUF_APPENDF(I6"offset: %d %d;\n", pd->rel1.offset_x, pd->rel1.offset_y); | ||
6855 | if (pd->rel1.id_x != -1 && pd->rel1.id_x == pd->rel1.id_y) | ||
6856 | BUF_APPENDF(I6"to: \"%s\";\n", ed->table_parts[pd->rel1.id_x]->part->name); | ||
6857 | else | ||
6858 | { | ||
6859 | if (pd->rel1.id_x != -1) | ||
6860 | BUF_APPENDF(I6"to_x: \"%s\";\n", ed->table_parts[pd->rel1.id_x]->part->name); | ||
6861 | if (pd->rel1.id_y != -1) | ||
6862 | BUF_APPENDF(I6"to_y: \"%s\";\n", ed->table_parts[pd->rel1.id_y]->part->name); | ||
6863 | } | ||
6864 | BUF_APPEND(I5"}\n");//rel1 | ||
6865 | } | ||
6866 | |||
6867 | //Rel2 | ||
6868 | if (pd->rel2.relative_x != 1.0 || pd->rel2.relative_y != 1.0 || | ||
6869 | pd->rel2.offset_x != -1 || pd->rel2.offset_y != -1 || | ||
6870 | pd->rel2.id_x != -1 || pd->rel2.id_y != -1) | ||
6871 | { | ||
6872 | BUF_APPEND(I5"rel2 {\n"); | ||
6873 | if (TO_DOUBLE(pd->rel2.relative_x) != 1.0 || TO_DOUBLE(pd->rel2.relative_y) != 1.0) | ||
6874 | BUF_APPENDF(I6"relative: %g %g;\n", TO_DOUBLE(pd->rel2.relative_x), TO_DOUBLE(pd->rel2.relative_y)); | ||
6875 | if (pd->rel2.offset_x != -1 || pd->rel2.offset_y != -1) | ||
6876 | BUF_APPENDF(I6"offset: %d %d;\n", pd->rel2.offset_x, pd->rel2.offset_y); | ||
6877 | if (pd->rel2.id_x != -1 && pd->rel2.id_x == pd->rel2.id_y) | ||
6878 | BUF_APPENDF(I6"to: \"%s\";\n", ed->table_parts[pd->rel2.id_x]->part->name); | ||
6879 | else | ||
6880 | { | ||
6881 | if (pd->rel2.id_x != -1) | ||
6882 | BUF_APPENDF(I6"to_x: \"%s\";\n", ed->table_parts[pd->rel2.id_x]->part->name); | ||
6883 | if (pd->rel2.id_y != -1) | ||
6884 | BUF_APPENDF(I6"to_y: \"%s\";\n", ed->table_parts[pd->rel2.id_y]->part->name); | ||
6885 | } | ||
6886 | BUF_APPEND(I5"}\n");//rel2 | ||
6887 | } | ||
6888 | |||
6889 | //Image | ||
6890 | if (rp->part->type == EDJE_PART_TYPE_IMAGE) | ||
6891 | { | ||
6892 | char *data; | ||
6893 | const char *image_name; | ||
6894 | |||
6895 | Edje_Part_Description_Image *img; | ||
6896 | |||
6897 | img = (Edje_Part_Description_Image *) pd; | ||
6898 | |||
6899 | BUF_APPEND(I5"image {\n"); | ||
6900 | |||
6901 | image_name = _edje_image_name_find(eed, img->image.id); | ||
6902 | if (image_name) | ||
6903 | BUF_APPENDF(I6"normal: \"%s\";\n", image_name); | ||
6904 | |||
6905 | ll = edje_edit_state_tweens_list_get(obj, part, state, value); | ||
6906 | EINA_LIST_FOREACH(ll, l, data) | ||
6907 | BUF_APPENDF(I6"tween: \"%s\";\n", data); | ||
6908 | edje_edit_string_list_free(ll); | ||
6909 | |||
6910 | if (img->image.border.l || img->image.border.r || img->image.border.t || img->image.border.b) | ||
6911 | BUF_APPENDF(I6"border: %d %d %d %d;\n", img->image.border.l, img->image.border.r, img->image.border.t, img->image.border.b); | ||
6912 | if (img->image.border.no_fill == 1) | ||
6913 | BUF_APPEND(I6"middle: NONE;\n"); | ||
6914 | else if (img->image.border.no_fill == 0) | ||
6915 | BUF_APPEND(I6"middle: DEFAULT;\n"); | ||
6916 | else if (img->image.border.no_fill == 2) | ||
6917 | BUF_APPEND(I6"middle: SOLID;\n"); | ||
6918 | |||
6919 | BUF_APPEND(I5"}\n");//image | ||
6920 | |||
6921 | //Fill | ||
6922 | |||
6923 | BUF_APPEND(I5"fill {\n"); | ||
6924 | if (!img->image.fill.smooth) | ||
6925 | BUF_APPEND(I6"smooth: 0;\n"); | ||
6926 | //TODO Support spread | ||
6927 | |||
6928 | if (img->image.fill.pos_rel_x || img->image.fill.pos_rel_y || | ||
6929 | img->image.fill.pos_abs_x || img->image.fill.pos_abs_y) | ||
6930 | { | ||
6931 | BUF_APPEND(I6"origin {\n"); | ||
6932 | if (img->image.fill.pos_rel_x || img->image.fill.pos_rel_y) | ||
6933 | BUF_APPENDF(I7"relative: %g %g;\n", TO_DOUBLE(img->image.fill.pos_rel_x), TO_DOUBLE(img->image.fill.pos_rel_y)); | ||
6934 | if (img->image.fill.pos_abs_x || img->image.fill.pos_abs_y) | ||
6935 | BUF_APPENDF(I7"offset: %d %d;\n", img->image.fill.pos_abs_x, img->image.fill.pos_abs_y); | ||
6936 | BUF_APPEND(I6"}\n"); | ||
6937 | } | ||
6938 | |||
6939 | if (TO_DOUBLE(img->image.fill.rel_x) != 1.0 || TO_DOUBLE(img->image.fill.rel_y) != 1.0 || | ||
6940 | img->image.fill.abs_x || img->image.fill.abs_y) | ||
6941 | { | ||
6942 | BUF_APPEND(I6"size {\n"); | ||
6943 | if (img->image.fill.rel_x != 1.0 || img->image.fill.rel_y != 1.0) | ||
6944 | BUF_APPENDF(I7"relative: %g %g;\n", TO_DOUBLE(img->image.fill.rel_x), TO_DOUBLE(img->image.fill.rel_y)); | ||
6945 | if (img->image.fill.abs_x || img->image.fill.abs_y) | ||
6946 | BUF_APPENDF(I7"offset: %d %d;\n", img->image.fill.abs_x, img->image.fill.abs_y); | ||
6947 | BUF_APPEND(I6"}\n"); | ||
6948 | } | ||
6949 | |||
6950 | BUF_APPEND(I5"}\n"); | ||
6951 | } | ||
6952 | |||
6953 | if (rp->part->type == EDJE_PART_TYPE_PROXY) | ||
6954 | { | ||
6955 | Edje_Part_Description_Proxy *pro; | ||
6956 | |||
6957 | pro = (Edje_Part_Description_Proxy *) pd; | ||
6958 | |||
6959 | //Fill | ||
6960 | |||
6961 | BUF_APPEND(I5"fill {\n"); | ||
6962 | if (!pro->proxy.fill.smooth) | ||
6963 | BUF_APPEND(I6"smooth: 0;\n"); | ||
6964 | //TODO Support spread | ||
6965 | //TODO Support source | ||
6966 | |||
6967 | if (pro->proxy.fill.pos_rel_x || pro->proxy.fill.pos_rel_y || | ||
6968 | pro->proxy.fill.pos_abs_x || pro->proxy.fill.pos_abs_y) | ||
6969 | { | ||
6970 | BUF_APPEND(I6"origin {\n"); | ||
6971 | if (pro->proxy.fill.pos_rel_x || pro->proxy.fill.pos_rel_y) | ||
6972 | BUF_APPENDF(I7"relative: %g %g;\n", TO_DOUBLE(pro->proxy.fill.pos_rel_x), TO_DOUBLE(pro->proxy.fill.pos_rel_y)); | ||
6973 | if (pro->proxy.fill.pos_abs_x || pro->proxy.fill.pos_abs_y) | ||
6974 | BUF_APPENDF(I7"offset: %d %d;\n", pro->proxy.fill.pos_abs_x, pro->proxy.fill.pos_abs_y); | ||
6975 | BUF_APPEND(I6"}\n"); | ||
6976 | } | ||
6977 | |||
6978 | if (TO_DOUBLE(pro->proxy.fill.rel_x) != 1.0 || TO_DOUBLE(pro->proxy.fill.rel_y) != 1.0 || | ||
6979 | pro->proxy.fill.abs_x || pro->proxy.fill.abs_y) | ||
6980 | { | ||
6981 | BUF_APPEND(I6"size {\n"); | ||
6982 | if (pro->proxy.fill.rel_x != 1.0 || pro->proxy.fill.rel_y != 1.0) | ||
6983 | BUF_APPENDF(I7"relative: %g %g;\n", TO_DOUBLE(pro->proxy.fill.rel_x), TO_DOUBLE(pro->proxy.fill.rel_y)); | ||
6984 | if (pro->proxy.fill.abs_x || pro->proxy.fill.abs_y) | ||
6985 | BUF_APPENDF(I7"offset: %d %d;\n", pro->proxy.fill.abs_x, pro->proxy.fill.abs_y); | ||
6986 | BUF_APPEND(I6"}\n"); | ||
6987 | } | ||
6988 | |||
6989 | BUF_APPEND(I5"}\n"); | ||
6990 | } | ||
6991 | |||
6992 | //Text | ||
6993 | if (rp->part->type == EDJE_PART_TYPE_TEXT) | ||
6994 | { | ||
6995 | Edje_Part_Description_Text *txt; | ||
6996 | |||
6997 | txt = (Edje_Part_Description_Text *) pd; | ||
6998 | |||
6999 | BUF_APPEND(I5"text {\n"); | ||
7000 | if (edje_string_get(&txt->text.text)) | ||
7001 | { | ||
7002 | if (txt->text.text.id) | ||
7003 | BUF_APPENDF(I6"text: _(\"%s\");\n", edje_string_id_get(&txt->text.text)); | ||
7004 | else | ||
7005 | BUF_APPENDF(I6"text: \"%s\";\n", edje_string_get(&txt->text.text)); | ||
7006 | } | ||
7007 | if (edje_string_get(&txt->text.font)) | ||
7008 | { | ||
7009 | if (txt->text.font.id) | ||
7010 | BUF_APPENDF(I6"font: _(\"%s\");\n", edje_string_id_get(&txt->text.font)); | ||
7011 | else | ||
7012 | BUF_APPENDF(I6"font: \"%s\";\n", edje_string_get(&txt->text.font)); | ||
7013 | } | ||
7014 | if (txt->text.size) | ||
7015 | BUF_APPENDF(I6"size: %d;\n", txt->text.size); | ||
7016 | if (txt->text.text_class) | ||
7017 | BUF_APPENDF(I6"text_class: \"%s\";\n", txt->text.text_class); | ||
7018 | if (txt->text.fit_x || txt->text.fit_y) | ||
7019 | BUF_APPENDF(I6"fit: %d %d;\n", txt->text.fit_x, txt->text.fit_y); | ||
7020 | //TODO Support min & max | ||
7021 | if (TO_DOUBLE(txt->text.align.x) != 0.5 || TO_DOUBLE(txt->text.align.y) != 0.5) | ||
7022 | BUF_APPENDF(I6"align: %g %g;\n", TO_DOUBLE(txt->text.align.x), TO_DOUBLE(txt->text.align.y)); | ||
7023 | //TODO Support source | ||
7024 | //TODO Support text_source | ||
7025 | if (txt->text.elipsis) | ||
7026 | BUF_APPENDF(I6"elipsis: %g;\n", txt->text.elipsis); | ||
7027 | BUF_APPEND(I5"}\n"); | ||
7028 | } | ||
7029 | |||
7030 | //External | ||
7031 | if (rp->part->type == EDJE_PART_TYPE_EXTERNAL) | ||
7032 | { | ||
7033 | if ((ll = (Eina_List *)edje_edit_state_external_params_list_get(obj, part, state, value))) | ||
7034 | { | ||
7035 | Edje_External_Param *p; | ||
7036 | |||
7037 | BUF_APPEND(I5"params {\n"); | ||
7038 | EINA_LIST_FOREACH(ll, l, p) | ||
7039 | { | ||
7040 | switch (p->type) | ||
7041 | { | ||
7042 | case EDJE_EXTERNAL_PARAM_TYPE_INT: | ||
7043 | BUF_APPENDF(I6"int: \"%s\" \"%d\";\n", p->name, p->i); | ||
7044 | break; | ||
7045 | case EDJE_EXTERNAL_PARAM_TYPE_DOUBLE: | ||
7046 | BUF_APPENDF(I6"double: \"%s\" \"%g\";\n", p->name, p->d); | ||
7047 | break; | ||
7048 | case EDJE_EXTERNAL_PARAM_TYPE_STRING: | ||
7049 | if (p->s) | ||
7050 | BUF_APPENDF(I6"string: \"%s\" \"%s\";\n", p->name, | ||
7051 | p->s); | ||
7052 | break; | ||
7053 | case EDJE_EXTERNAL_PARAM_TYPE_BOOL: | ||
7054 | BUF_APPENDF(I6"bool: \"%s\" \"%d\";\n", p->name, p->i); | ||
7055 | break; | ||
7056 | case EDJE_EXTERNAL_PARAM_TYPE_CHOICE: | ||
7057 | if (p->s) | ||
7058 | BUF_APPENDF(I6"choice: \"%s\" \"%s\";\n", p->name, | ||
7059 | p->s); | ||
7060 | break; | ||
7061 | default: | ||
7062 | break; | ||
7063 | } | ||
7064 | } | ||
7065 | BUF_APPEND(I5"}\n"); | ||
7066 | } | ||
7067 | } | ||
7068 | |||
7069 | BUF_APPEND(I4"}\n");//description | ||
7070 | return ret; | ||
7071 | } | ||
7072 | |||
7073 | static Eina_Bool | ||
7074 | _edje_generate_source_of_part(Evas_Object *obj, Edje_Part *ep, Eina_Strbuf *buf) | ||
7075 | { | ||
7076 | const char *part = ep->name; | ||
7077 | const char *str; | ||
7078 | Eina_List *l, *ll; | ||
7079 | char *data; | ||
7080 | Eina_Bool ret = EINA_TRUE; | ||
7081 | const char *api_name, *api_description; | ||
7082 | |||
7083 | BUF_APPENDF(I3"part { name: \"%s\";\n", part); | ||
7084 | BUF_APPENDF(I4"type: %s;\n", types[edje_edit_part_type_get(obj, part)]); | ||
7085 | if (!edje_edit_part_mouse_events_get(obj, part)) | ||
7086 | BUF_APPEND(I4"mouse_events: 0;\n"); | ||
7087 | if (edje_edit_part_repeat_events_get(obj, part)) | ||
7088 | BUF_APPEND(I4"repeat_events: 1;\n"); | ||
7089 | if (edje_edit_part_scale_get(obj, part)) | ||
7090 | BUF_APPEND(I4"scale: 1;\n"); | ||
7091 | //TODO Support ignore_flags | ||
7092 | //TODO Support pointer_mode | ||
7093 | //TODO Support precise_is_inside | ||
7094 | //TODO Support use_alternate_font_metrics | ||
7095 | if ((str = edje_edit_part_clip_to_get(obj, part))) | ||
7096 | { | ||
7097 | BUF_APPENDF(I4"clip_to: \"%s\";\n", str); | ||
7098 | edje_edit_string_free(str); | ||
7099 | } | ||
7100 | if ((str = edje_edit_part_source_get(obj, part))) | ||
7101 | { | ||
7102 | BUF_APPENDF(I4"source: \"%s\";\n", str); | ||
7103 | edje_edit_string_free(str); | ||
7104 | } | ||
7105 | if (edje_edit_part_effect_get(obj, part)) | ||
7106 | BUF_APPENDF(I4"effect: %s;\n", | ||
7107 | effects[edje_edit_part_effect_get(obj, part)]); | ||
7108 | |||
7109 | //Dragable | ||
7110 | if (edje_edit_part_drag_x_get(obj, part) || | ||
7111 | edje_edit_part_drag_y_get(obj, part)) | ||
7112 | { | ||
7113 | BUF_APPEND(I4"dragable {\n"); | ||
7114 | BUF_APPENDF(I5"x: %d %d %d;\n", | ||
7115 | edje_edit_part_drag_x_get(obj, part), | ||
7116 | edje_edit_part_drag_step_x_get(obj, part), | ||
7117 | edje_edit_part_drag_count_x_get(obj, part)); | ||
7118 | BUF_APPENDF(I5"y: %d %d %d;\n", | ||
7119 | edje_edit_part_drag_y_get(obj, part), | ||
7120 | edje_edit_part_drag_step_y_get(obj, part), | ||
7121 | edje_edit_part_drag_count_y_get(obj, part)); | ||
7122 | if ((str = edje_edit_part_drag_confine_get(obj, part))) | ||
7123 | { | ||
7124 | BUF_APPENDF(I5"confine: \"%s\";\n", str); | ||
7125 | edje_edit_string_free(str); | ||
7126 | } | ||
7127 | if ((str = edje_edit_part_drag_event_get(obj, part))) | ||
7128 | { | ||
7129 | BUF_APPENDF(I5"events: \"%s\";\n", str); | ||
7130 | edje_edit_string_free(str); | ||
7131 | } | ||
7132 | BUF_APPEND(I4"}\n"); | ||
7133 | } | ||
7134 | |||
7135 | //Descriptions | ||
7136 | ll = edje_edit_part_states_list_get(obj, part); | ||
7137 | EINA_LIST_FOREACH(ll, l, data) | ||
7138 | { | ||
7139 | char state[512], *delim; | ||
7140 | double value; | ||
7141 | strncpy(state, data, sizeof(state) - 1); /* if we go over it, too bad.. the list of states may need to change to provide name and value separated */ | ||
7142 | delim = strchr(state, ' '); | ||
7143 | *delim = '\0'; | ||
7144 | delim++; | ||
7145 | value = strtod(delim, NULL); | ||
7146 | ret &= _edje_generate_source_of_state(obj, part, state, value, buf); | ||
7147 | } | ||
7148 | edje_edit_string_list_free(ll); | ||
7149 | |||
7150 | api_name = edje_edit_part_api_name_get(obj, part); | ||
7151 | api_description = edje_edit_part_api_description_get(obj, part); | ||
7152 | |||
7153 | if (api_name || api_description) | ||
7154 | { | ||
7155 | if (api_name && api_description) | ||
7156 | { | ||
7157 | BUF_APPENDF(I4"api: \"%s\" \"%s\";\n", api_name, api_description); | ||
7158 | edje_edit_string_free(api_name); | ||
7159 | edje_edit_string_free(api_description); | ||
7160 | } | ||
7161 | else | ||
7162 | if (api_name) | ||
7163 | { | ||
7164 | BUF_APPENDF(I4"api: \"%s\" \"\";\n", api_name); | ||
7165 | edje_edit_string_free(api_name); | ||
7166 | } | ||
7167 | else | ||
7168 | { | ||
7169 | BUF_APPENDF(I4"api: \"\" \"%s\";\n", api_description); | ||
7170 | edje_edit_string_free(api_description); | ||
7171 | } | ||
7172 | } | ||
7173 | |||
7174 | BUF_APPEND(I3"}\n");//part | ||
7175 | return ret; | ||
7176 | } | ||
7177 | |||
7178 | static Eina_Bool | ||
7179 | _edje_generate_source_of_group(Edje *ed, Edje_Part_Collection_Directory_Entry *pce, Eina_Strbuf *buf) | ||
7180 | { | ||
7181 | Edje_Edit *eed; | ||
7182 | Eet_File *ef; | ||
7183 | Evas_Object *obj; | ||
7184 | Eina_List *l, *ll; | ||
7185 | unsigned int i; | ||
7186 | int w, h; | ||
7187 | char *data; | ||
7188 | const char *group = pce->entry; | ||
7189 | Edje_Part_Collection *pc; | ||
7190 | Eina_Bool ret = EINA_TRUE; | ||
7191 | |||
7192 | obj = edje_edit_object_add(ed->base.evas); | ||
7193 | if (!edje_object_file_set(obj, ed->file->path, group)) return EINA_FALSE; | ||
7194 | |||
7195 | ef = eet_open(ed->file->path, EET_FILE_MODE_READ); | ||
7196 | if (!ef) | ||
7197 | { | ||
7198 | evas_object_del(obj); | ||
7199 | return EINA_FALSE; | ||
7200 | } | ||
7201 | |||
7202 | eed = evas_object_smart_data_get(obj); | ||
7203 | pc = eed->base.collection; | ||
7204 | |||
7205 | BUF_APPENDF(I1"group { name: \"%s\";\n", group); | ||
7206 | //TODO Support alias: | ||
7207 | w = edje_edit_group_min_w_get(obj); | ||
7208 | h = edje_edit_group_min_h_get(obj); | ||
7209 | if ((w > 0) || (h > 0)) | ||
7210 | BUF_APPENDF(I2"min: %d %d;\n", w, h); | ||
7211 | w = edje_edit_group_max_w_get(obj); | ||
7212 | h = edje_edit_group_max_h_get(obj); | ||
7213 | if ((w > 0) || (h > 0)) | ||
7214 | BUF_APPENDF(I2"max: %d %d;\n", w, h); | ||
7215 | |||
7216 | /* Data */ | ||
7217 | if (pc->data) | ||
7218 | { | ||
7219 | Eina_Iterator *it; | ||
7220 | Eina_Hash_Tuple *tuple; | ||
7221 | BUF_APPEND(I2"data {\n"); | ||
7222 | |||
7223 | it = eina_hash_iterator_tuple_new(pc->data); | ||
7224 | |||
7225 | if (!it) | ||
7226 | { | ||
7227 | ERR("Generating EDC for Group[%s] data.", group); | ||
7228 | return EINA_FALSE; | ||
7229 | } | ||
7230 | |||
7231 | EINA_ITERATOR_FOREACH(it, tuple) | ||
7232 | BUF_APPENDF(I3"item: \"%s\" \"%s\";\n", (char *)tuple->key, | ||
7233 | edje_string_get(tuple->data)); | ||
7234 | |||
7235 | eina_iterator_free(it); | ||
7236 | BUF_APPEND(I2"}\n"); | ||
7237 | } | ||
7238 | |||
7239 | if (eed->embryo_source) | ||
7240 | { | ||
7241 | BUF_APPEND(I2"script {\n"); | ||
7242 | BUF_APPEND(eed->embryo_source); | ||
7243 | BUF_APPEND(I2"}\n"); | ||
7244 | } | ||
7245 | |||
7246 | /* Parts */ | ||
7247 | BUF_APPEND(I2"parts {\n"); | ||
7248 | for (i = 0; i < pc->parts_count; i++) | ||
7249 | { | ||
7250 | Edje_Part *ep; | ||
7251 | ep = pc->parts[i]; | ||
7252 | ret &= _edje_generate_source_of_part(obj, ep, buf); | ||
7253 | } | ||
7254 | BUF_APPEND(I2"}\n");//parts | ||
7255 | |||
7256 | if (!ret) | ||
7257 | { | ||
7258 | ERR("Generating EDC for Group[%s] Parts.", group); | ||
7259 | return EINA_FALSE; | ||
7260 | } | ||
7261 | |||
7262 | /* Programs */ | ||
7263 | if ((ll = edje_edit_programs_list_get(obj))) | ||
7264 | { | ||
7265 | BUF_APPEND(I2 "programs {\n"); | ||
7266 | EINA_LIST_FOREACH(ll, l, data) | ||
7267 | ret &= _edje_generate_source_of_program(obj, data, buf); | ||
7268 | BUF_APPEND(I2 "}\n"); | ||
7269 | edje_edit_string_list_free(ll); | ||
7270 | } | ||
7271 | BUF_APPEND(I1"}\n");//group | ||
7272 | |||
7273 | if (!ret) | ||
7274 | { | ||
7275 | ERR("Generating EDC for Group[%s] Programs.", group); | ||
7276 | evas_object_del(obj); | ||
7277 | return EINA_FALSE; | ||
7278 | } | ||
7279 | |||
7280 | eet_close(ef); | ||
7281 | evas_object_del(obj); | ||
7282 | return ret; | ||
7283 | } | ||
7284 | |||
7285 | static Eina_Strbuf* | ||
7286 | _edje_generate_source(Evas_Object *obj) | ||
7287 | { | ||
7288 | Eina_Strbuf *buf; | ||
7289 | |||
7290 | Eina_List *l, *ll; | ||
7291 | Edje_Font_Directory_Entry *fnt; | ||
7292 | |||
7293 | char *entry; | ||
7294 | Eina_Bool ret = EINA_TRUE; | ||
7295 | |||
7296 | GET_ED_OR_RETURN(NULL); | ||
7297 | |||
7298 | /* Open a str buffer */ | ||
7299 | |||
7300 | buf = eina_strbuf_new(); | ||
7301 | if (!buf) return NULL; | ||
7302 | |||
7303 | /* Write edc into file */ | ||
7304 | //TODO Probably we need to save the file before generation | ||
7305 | |||
7306 | /* Images */ | ||
7307 | if ((ll = edje_edit_images_list_get(obj))) | ||
7308 | { | ||
7309 | BUF_APPEND(I0"images {\n"); | ||
7310 | |||
7311 | EINA_LIST_FOREACH(ll, l, entry) | ||
7312 | { | ||
7313 | int comp = edje_edit_image_compression_type_get(obj, entry); | ||
7314 | if (comp < 0) continue; | ||
7315 | |||
7316 | BUF_APPENDF(I1"image: \"%s\" ", entry); | ||
7317 | |||
7318 | if (comp == EDJE_EDIT_IMAGE_COMP_LOSSY) | ||
7319 | BUF_APPENDF("LOSSY %d;\n", | ||
7320 | edje_edit_image_compression_rate_get(obj, entry)); | ||
7321 | else if (comp == EDJE_EDIT_IMAGE_COMP_RAW) | ||
7322 | BUF_APPEND("RAW;\n"); | ||
7323 | else if (comp == EDJE_EDIT_IMAGE_COMP_USER) | ||
7324 | BUF_APPEND("USER;\n"); | ||
7325 | else | ||
7326 | BUF_APPEND("COMP;\n"); | ||
7327 | } | ||
7328 | BUF_APPEND(I0"}\n\n"); | ||
7329 | edje_edit_string_list_free(ll); | ||
7330 | |||
7331 | if (!ret) | ||
7332 | { | ||
7333 | ERR("Generating EDC for Images"); | ||
7334 | eina_strbuf_free(buf); | ||
7335 | return NULL; | ||
7336 | } | ||
7337 | } | ||
7338 | |||
7339 | /* Fonts */ | ||
7340 | if (ed->file->fonts) | ||
7341 | { | ||
7342 | Eina_Iterator *it; | ||
7343 | |||
7344 | it = eina_hash_iterator_data_new(ed->file->fonts); | ||
7345 | if (it) | ||
7346 | { | ||
7347 | BUF_APPEND(I0"fonts {\n"); | ||
7348 | |||
7349 | EINA_ITERATOR_FOREACH(it, fnt) | ||
7350 | BUF_APPENDF(I1"font: \"%s\" \"%s\";\n", fnt->file, | ||
7351 | fnt->entry); | ||
7352 | |||
7353 | BUF_APPEND(I0"}\n\n"); | ||
7354 | eina_iterator_free(it); | ||
7355 | |||
7356 | if (!ret) | ||
7357 | { | ||
7358 | ERR("Generating EDC for Fonts"); | ||
7359 | eina_strbuf_free(buf); | ||
7360 | return NULL; | ||
7361 | } | ||
7362 | } | ||
7363 | } | ||
7364 | |||
7365 | /* Data */ | ||
7366 | if ((ll = edje_edit_data_list_get(obj))) | ||
7367 | { | ||
7368 | BUF_APPEND(I0 "data {\n"); | ||
7369 | |||
7370 | EINA_LIST_FOREACH(ll, l, entry) | ||
7371 | BUF_APPENDF(I1 "item: \"%s\" \"%s\";\n", entry, | ||
7372 | edje_edit_data_value_get(obj, entry)); | ||
7373 | |||
7374 | BUF_APPEND(I0 "}\n\n"); | ||
7375 | edje_edit_string_list_free(ll); | ||
7376 | |||
7377 | if (!ret) | ||
7378 | { | ||
7379 | ERR("Generating EDC for Data"); | ||
7380 | eina_strbuf_free(buf); | ||
7381 | return NULL; | ||
7382 | } | ||
7383 | } | ||
7384 | |||
7385 | /* Color Classes */ | ||
7386 | if ((ll = edje_edit_color_classes_list_get(obj))) | ||
7387 | { | ||
7388 | BUF_APPEND(I0 "color_classes {\n"); | ||
7389 | |||
7390 | EINA_LIST_FOREACH(ll, l, entry) | ||
7391 | _edje_generate_source_of_colorclass(ed, entry, buf); | ||
7392 | |||
7393 | BUF_APPEND(I0 "}\n\n"); | ||
7394 | edje_edit_string_list_free(ll); | ||
7395 | |||
7396 | if (!ret) | ||
7397 | { | ||
7398 | ERR("Generating EDC for Color Classes"); | ||
7399 | eina_strbuf_free(buf); | ||
7400 | return NULL; | ||
7401 | } | ||
7402 | } | ||
7403 | |||
7404 | /* Styles */ | ||
7405 | if ((ll = edje_edit_styles_list_get(obj))) | ||
7406 | { | ||
7407 | BUF_APPEND(I0 "styles {\n"); | ||
7408 | EINA_LIST_FOREACH(ll, l, entry) | ||
7409 | _edje_generate_source_of_style(ed, entry, buf); | ||
7410 | BUF_APPEND(I0 "}\n\n"); | ||
7411 | edje_edit_string_list_free(ll); | ||
7412 | |||
7413 | if (!ret) | ||
7414 | { | ||
7415 | ERR("Generating EDC for Styles"); | ||
7416 | eina_strbuf_free(buf); | ||
7417 | return NULL; | ||
7418 | } | ||
7419 | } | ||
7420 | |||
7421 | /* Externals */ | ||
7422 | if ((ll = edje_edit_externals_list_get(obj))) | ||
7423 | { | ||
7424 | BUF_APPEND(I0 "externals {\n"); | ||
7425 | EINA_LIST_FOREACH(ll, l, entry) | ||
7426 | BUF_APPENDF(I1 "external: \"%s\";\n", entry); | ||
7427 | |||
7428 | BUF_APPEND(I0 "}\n\n"); | ||
7429 | edje_edit_string_list_free(ll); | ||
7430 | |||
7431 | if (!ret) | ||
7432 | { | ||
7433 | ERR("Generating EDC for Externals"); | ||
7434 | eina_strbuf_free(buf); | ||
7435 | return NULL; | ||
7436 | } | ||
7437 | } | ||
7438 | |||
7439 | /* Collections */ | ||
7440 | if (ed->file->collection) | ||
7441 | { | ||
7442 | Eina_Iterator *it; | ||
7443 | Edje_Part_Collection_Directory_Entry *pce; | ||
7444 | BUF_APPEND("collections {\n"); | ||
7445 | |||
7446 | it = eina_hash_iterator_data_new(ed->file->collection); | ||
7447 | |||
7448 | if (!it) | ||
7449 | { | ||
7450 | ERR("Generating EDC for Collections"); | ||
7451 | eina_strbuf_free(buf); | ||
7452 | return NULL; | ||
7453 | } | ||
7454 | |||
7455 | EINA_ITERATOR_FOREACH(it, pce) | ||
7456 | { | ||
7457 | ret &= _edje_generate_source_of_group(ed, pce, buf); | ||
7458 | } | ||
7459 | |||
7460 | eina_iterator_free(it); | ||
7461 | BUF_APPEND("}\n\n"); | ||
7462 | } | ||
7463 | |||
7464 | return buf; | ||
7465 | } | ||
7466 | |||
7467 | |||
7468 | |||
7469 | /*********************/ | ||
7470 | /* SAVING ROUTINES */ | ||
7471 | /*********************/ | ||
7472 | //////////////////////////////////////// | ||
7473 | typedef struct _SrcFile SrcFile; | ||
7474 | typedef struct _SrcFile_List SrcFile_List; | ||
7475 | |||
7476 | struct _SrcFile | ||
7477 | { | ||
7478 | char *name; | ||
7479 | const char *file; | ||
7480 | }; | ||
7481 | |||
7482 | struct _SrcFile_List | ||
7483 | { | ||
7484 | Eina_List *list; | ||
7485 | }; | ||
7486 | |||
7487 | static Eet_Data_Descriptor *_srcfile_edd = NULL; | ||
7488 | static Eet_Data_Descriptor *_srcfile_list_edd = NULL; | ||
7489 | |||
7490 | static void | ||
7491 | source_edd(void) | ||
7492 | { | ||
7493 | Eet_Data_Descriptor_Class eddc; | ||
7494 | |||
7495 | if (_srcfile_edd) return; | ||
7496 | |||
7497 | eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "srcfile", sizeof(SrcFile)); | ||
7498 | _srcfile_edd = eet_data_descriptor_stream_new(&eddc); | ||
7499 | EET_DATA_DESCRIPTOR_ADD_BASIC(_srcfile_edd, SrcFile, "name", name, EET_T_INLINED_STRING); | ||
7500 | EET_DATA_DESCRIPTOR_ADD_BASIC(_srcfile_edd, SrcFile, "file", file, EET_T_INLINED_STRING); | ||
7501 | |||
7502 | eet_eina_stream_data_descriptor_class_set(&eddc, sizeof (eddc), "srcfile_list", sizeof(SrcFile_List)); | ||
7503 | _srcfile_list_edd = eet_data_descriptor_stream_new(&eddc); | ||
7504 | EET_DATA_DESCRIPTOR_ADD_LIST(_srcfile_list_edd, SrcFile_List, "list", list, _srcfile_edd); | ||
7505 | } | ||
7506 | ///////////////////////////////////////// | ||
7507 | |||
7508 | static Eina_Bool | ||
7509 | _edje_edit_edje_file_save(Eet_File *eetf, Edje_File *ef) | ||
7510 | { | ||
7511 | /* Write Edje_File structure */ | ||
7512 | INF("** Writing Edje_File* ed->file"); | ||
7513 | if (eet_data_write(eetf, _edje_edd_edje_file, "edje/file", ef, 1) <= 0) | ||
7514 | { | ||
7515 | ERR("Error. unable to write \"edje_file\" entry to \"%s\"", ef->path); | ||
7516 | return EINA_FALSE; | ||
7517 | } | ||
7518 | return EINA_TRUE; | ||
7519 | } | ||
7520 | |||
7521 | static Eina_Bool | ||
7522 | _edje_edit_collection_save(Eet_File *eetf, Edje_Part_Collection *epc) | ||
7523 | { | ||
7524 | char buf[256]; | ||
7525 | |||
7526 | snprintf(buf, sizeof(buf), "edje/collections/%i", epc->id); | ||
7527 | |||
7528 | if (eet_data_write(eetf, _edje_edd_edje_part_collection, buf, epc, 1) > 0) | ||
7529 | return EINA_TRUE; | ||
7530 | |||
7531 | ERR("Error. unable to write \"%s\" part entry", buf); | ||
7532 | return EINA_FALSE; | ||
7533 | } | ||
7534 | |||
7535 | static Eina_Bool | ||
7536 | _edje_edit_source_save(Eet_File *eetf, Evas_Object *obj) | ||
7537 | { | ||
7538 | SrcFile *sf; | ||
7539 | SrcFile_List *sfl; | ||
7540 | Eina_Strbuf *source_file; | ||
7541 | Eina_Bool ret = EINA_TRUE; | ||
7542 | |||
7543 | source_file = _edje_generate_source(obj); | ||
7544 | if (!source_file) | ||
7545 | { | ||
7546 | ERR("Can't create edc source"); | ||
7547 | return EINA_FALSE; | ||
7548 | } | ||
7549 | |||
7550 | //open the temp file and put the contents in SrcFile | ||
7551 | sf = _alloc(sizeof(SrcFile)); | ||
7552 | if (!sf) | ||
7553 | { | ||
7554 | ERR("Unable to create source file struct"); | ||
7555 | ret = EINA_FALSE; | ||
7556 | goto save_free_source; | ||
7557 | } | ||
7558 | sf->name = strdup("generated_source.edc"); | ||
7559 | if (!sf->name) | ||
7560 | { | ||
7561 | ERR("Unable to alloc filename"); | ||
7562 | ret = EINA_FALSE; | ||
7563 | goto save_free_sf; | ||
7564 | } | ||
7565 | |||
7566 | sf->file = eina_strbuf_string_get(source_file); | ||
7567 | |||
7568 | //create the needed list of source files (only one) | ||
7569 | sfl = _alloc(sizeof(SrcFile_List)); | ||
7570 | if (!sfl) | ||
7571 | { | ||
7572 | ERR("Unable to create file list"); | ||
7573 | ret = EINA_FALSE; | ||
7574 | goto save_free_filename; | ||
7575 | } | ||
7576 | sfl->list = NULL; | ||
7577 | sfl->list = eina_list_append(sfl->list, sf); | ||
7578 | if (!sfl->list) | ||
7579 | { | ||
7580 | ERR("Error. unable to append file in list"); | ||
7581 | ret = EINA_FALSE; | ||
7582 | goto save_free_sfl; | ||
7583 | } | ||
7584 | |||
7585 | // write the sources list to the eet file | ||
7586 | source_edd(); | ||
7587 | if (eet_data_write(eetf, _srcfile_list_edd, "edje_sources", sfl, 1) <= 0) | ||
7588 | { | ||
7589 | ERR("Unable to write edc source"); | ||
7590 | ret = EINA_FALSE; | ||
7591 | } | ||
7592 | |||
7593 | /* Clear stuff */ | ||
7594 | eina_list_free(sfl->list); | ||
7595 | save_free_sfl: | ||
7596 | free(sfl); | ||
7597 | save_free_filename: | ||
7598 | free(sf->name); | ||
7599 | save_free_sf: | ||
7600 | free(sf); | ||
7601 | save_free_source: | ||
7602 | eina_strbuf_free(source_file); | ||
7603 | return ret; | ||
7604 | } | ||
7605 | |||
7606 | Eina_Bool | ||
7607 | _edje_edit_internal_save(Evas_Object *obj, int current_only) | ||
7608 | { | ||
7609 | Edje_File *ef; | ||
7610 | Eet_File *eetf; | ||
7611 | |||
7612 | GET_ED_OR_RETURN(EINA_FALSE); | ||
7613 | |||
7614 | ef = ed->file; | ||
7615 | if (!ef) return EINA_FALSE; | ||
7616 | |||
7617 | INF("*********** Saving file ******************"); | ||
7618 | INF("** path: %s", ef->path); | ||
7619 | |||
7620 | /* Open the eet file */ | ||
7621 | eetf = eet_open(ef->path, EET_FILE_MODE_READ_WRITE); | ||
7622 | if (!eetf) | ||
7623 | { | ||
7624 | ERR("Error. unable to open \"%s\" for writing output", | ||
7625 | ef->path); | ||
7626 | return EINA_FALSE; | ||
7627 | } | ||
7628 | |||
7629 | /* Set compiler name */ | ||
7630 | if (strcmp(ef->compiler, "edje_edit")) | ||
7631 | { | ||
7632 | _edje_if_string_free(ed, ef->compiler); | ||
7633 | ef->compiler = (char *)eina_stringshare_add("edje_edit"); | ||
7634 | } | ||
7635 | |||
7636 | if (!_edje_edit_edje_file_save(eetf, ef)) | ||
7637 | { | ||
7638 | eet_close(eetf); | ||
7639 | return EINA_FALSE; | ||
7640 | } | ||
7641 | |||
7642 | if (current_only) | ||
7643 | { | ||
7644 | if (ed->collection) | ||
7645 | { | ||
7646 | INF("** Writing Edje_Part_Collection* ed->collection " | ||
7647 | "[id: %d]", ed->collection->id); | ||
7648 | if (!_edje_edit_collection_save(eetf, ed->collection)) | ||
7649 | { | ||
7650 | eet_close(eetf); | ||
7651 | return EINA_FALSE; | ||
7652 | } | ||
7653 | } | ||
7654 | } | ||
7655 | else | ||
7656 | { | ||
7657 | Eina_List *l; | ||
7658 | Edje_Part_Collection *edc; | ||
7659 | Edje_Part_Collection_Directory_Entry *ce; | ||
7660 | Eina_Iterator *it; | ||
7661 | |||
7662 | INF("** Writing all collections"); | ||
7663 | |||
7664 | it = eina_hash_iterator_data_new(ef->collection); | ||
7665 | while (eina_iterator_next(it, (void **)&ce)) | ||
7666 | { | ||
7667 | if (ce->ref) | ||
7668 | { | ||
7669 | INF("** Writing hash Edje_Part_Collection* ed->collection " | ||
7670 | "[id: %d]", ce->id); | ||
7671 | if(!_edje_edit_collection_save(eetf, ce->ref)) | ||
7672 | { | ||
7673 | eet_close(eetf); | ||
7674 | return EINA_FALSE; | ||
7675 | } | ||
7676 | } | ||
7677 | } | ||
7678 | eina_iterator_free(it); | ||
7679 | |||
7680 | EINA_LIST_FOREACH(ef->collection_cache, l, edc) | ||
7681 | { | ||
7682 | INF("** Writing cache Edje_Part_Collection* ed->collection " | ||
7683 | "[id: %d]", edc->id); | ||
7684 | if(!_edje_edit_collection_save(eetf, edc)) | ||
7685 | { | ||
7686 | eet_close(eetf); | ||
7687 | return EINA_FALSE; | ||
7688 | } | ||
7689 | } | ||
7690 | } | ||
7691 | |||
7692 | if (eed->bytecode_dirty || eed->script_need_recompile) | ||
7693 | { | ||
7694 | char buf[64]; | ||
7695 | Eina_Iterator *it; | ||
7696 | Program_Script *ps; | ||
7697 | Eina_List *deathnote = NULL; | ||
7698 | |||
7699 | if (eed->bytecode_dirty) | ||
7700 | { | ||
7701 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/compiled/%i", | ||
7702 | ed->collection->id); | ||
7703 | eet_write(eetf, buf, eed->bytecode, eed->bytecode_size, 1); | ||
7704 | free(eed->bytecode); | ||
7705 | eed->bytecode = NULL; | ||
7706 | eed->bytecode_size = 0; | ||
7707 | eed->bytecode_dirty = EINA_FALSE; | ||
7708 | } | ||
7709 | |||
7710 | if (eed->embryo_source_dirty) | ||
7711 | { | ||
7712 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i", | ||
7713 | ed->collection->id); | ||
7714 | eet_write(eetf, buf, eed->embryo_source, | ||
7715 | strlen(eed->embryo_source) +1, 1); | ||
7716 | eed->embryo_source_dirty = EINA_FALSE; | ||
7717 | } | ||
7718 | |||
7719 | it = eina_hash_iterator_data_new(eed->program_scripts); | ||
7720 | EINA_ITERATOR_FOREACH(it, ps) | ||
7721 | { | ||
7722 | if (ps->dirty) | ||
7723 | { | ||
7724 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i/%i", | ||
7725 | ed->collection->id, ps->id); | ||
7726 | eet_write(eetf, buf, ps->code, strlen(ps->code) + 1, 1); | ||
7727 | ps->dirty = EINA_FALSE; | ||
7728 | } | ||
7729 | else if (ps->delete_me) | ||
7730 | { | ||
7731 | snprintf(buf, sizeof(buf), "edje/scripts/embryo/source/%i/%i", | ||
7732 | ed->collection->id, ps->id); | ||
7733 | eet_delete(eetf, buf); | ||
7734 | deathnote = eina_list_append(deathnote, ps); | ||
7735 | } | ||
7736 | } | ||
7737 | eina_iterator_free(it); | ||
7738 | |||
7739 | EINA_LIST_FREE(deathnote, ps) | ||
7740 | eina_hash_del(eed->program_scripts, &ps->id, ps); | ||
7741 | } | ||
7742 | |||
7743 | if (!_edje_edit_source_save(eetf, obj)) | ||
7744 | { | ||
7745 | eet_close(eetf); | ||
7746 | return EINA_FALSE; | ||
7747 | } | ||
7748 | |||
7749 | eet_close(eetf); | ||
7750 | |||
7751 | /* Update mtime */ | ||
7752 | { | ||
7753 | struct stat st; | ||
7754 | if (stat(ed->path, &st) != 0) | ||
7755 | return EINA_FALSE; | ||
7756 | ef->mtime = st.st_mtime; | ||
7757 | } | ||
7758 | |||
7759 | INF("*********** Saving DONE ******************"); | ||
7760 | return EINA_TRUE; | ||
7761 | } | ||
7762 | |||
7763 | EAPI Eina_Bool | ||
7764 | edje_edit_save(Evas_Object *obj) | ||
7765 | { | ||
7766 | eina_error_set(0); | ||
7767 | |||
7768 | return _edje_edit_internal_save(obj, 1); | ||
7769 | } | ||
7770 | |||
7771 | EAPI Eina_Bool | ||
7772 | edje_edit_save_all(Evas_Object *obj) | ||
7773 | { | ||
7774 | eina_error_set(0); | ||
7775 | |||
7776 | return _edje_edit_internal_save(obj, 0); | ||
7777 | } | ||
7778 | |||
7779 | EAPI void | ||
7780 | edje_edit_print_internal_status(Evas_Object *obj) | ||
7781 | { | ||
7782 | /* | ||
7783 | Edje_Program *epr; | ||
7784 | unsigned int i; | ||
7785 | int j; | ||
7786 | */ | ||
7787 | eina_error_set(0); | ||
7788 | |||
7789 | GET_ED_OR_RETURN(); | ||
7790 | |||
7791 | _edje_generate_source(obj); | ||
7792 | /* | ||
7793 | INF("****** CHECKIN' INTERNAL STRUCTS STATUS *********"); | ||
7794 | |||
7795 | INF("path: '%s', group: '%s', parent: '%s'", | ||
7796 | ed->path, ed->group, ed->parent); | ||
7797 | |||
7798 | INF("Parts [table:%d list:%d]", ed->table_parts_size, | ||
7799 | ed->collection->parts_count); | ||
7800 | for (i = 0; i < ed->collection->parts_count; ++i) | ||
7801 | { | ||
7802 | Edje_Real_Part *rp; | ||
7803 | Edje_Part *p; | ||
7804 | |||
7805 | p = ed->collection->parts[i]; | ||
7806 | |||
7807 | rp = ed->table_parts[p->id % ed->table_parts_size]; | ||
7808 | printf("part[%d]: '%s' ", p->id, p->name); | ||
7809 | if (p == rp->part) | ||
7810 | printf("OK!\n"); | ||
7811 | else | ||
7812 | printf("WRONG (table[%d]->name = '%s')\n", p->id, rp->part->name); | ||
7813 | } | ||
7814 | |||
7815 | INF("Programs [table:%d list:%d,%d,%d,%d,%d]", ed->table_programs_size, | ||
7816 | ed->collection->programs.fnmatch_count, | ||
7817 | ed->collection->programs.strcmp_count, | ||
7818 | ed->collection->programs.strncmp_count, | ||
7819 | ed->collection->programs.strrncmp_count, | ||
7820 | ed->collection->programs.nocmp_count); | ||
7821 | for(j = 0; j < ed->table_programs_size; ++j) | ||
7822 | { | ||
7823 | epr = ed->table_programs[i % ed->table_programs_size]; | ||
7824 | printf("program[%d]: '%s'\n", epr->id, epr->name); | ||
7825 | } | ||
7826 | |||
7827 | INF("****************** END ************************"); | ||
7828 | */ | ||
7829 | } | ||