aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/edje/src/lib/edje_var.c
diff options
context:
space:
mode:
authorDavid Walter Seikel2012-01-04 18:41:13 +1000
committerDavid Walter Seikel2012-01-04 18:41:13 +1000
commitdd7595a3475407a7fa96a97393bae8c5220e8762 (patch)
treee341e911d7eb911a51684a7412ef7f7c7605d28e /libraries/edje/src/lib/edje_var.c
parentAdd the skeleton. (diff)
downloadSledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.zip
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.gz
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.bz2
SledjHamr-dd7595a3475407a7fa96a97393bae8c5220e8762.tar.xz
Add the base Enlightenment Foundation Libraries - eina, eet, evas, ecore, embryo, and edje.
Note that embryo wont be used, but I'm not sure yet if you can build edje without it.
Diffstat (limited to '')
-rw-r--r--libraries/edje/src/lib/edje_var.c1093
1 files changed, 1093 insertions, 0 deletions
diff --git a/libraries/edje/src/lib/edje_var.c b/libraries/edje/src/lib/edje_var.c
new file mode 100644
index 0000000..c6c83b1
--- /dev/null
+++ b/libraries/edje/src/lib/edje_var.c
@@ -0,0 +1,1093 @@
1#include "edje_private.h"
2
3static Eina_Bool _edje_var_timer_cb(void *data);
4static Eina_Bool _edje_var_anim_cb(void *data);
5
6static Ecore_Animator *_edje_animator = NULL;
7static Eina_List *_edje_anim_list = NULL;
8
9static Eina_Bool
10_edje_var_timer_cb(void *data)
11{
12 Edje_Var_Timer *et;
13 Edje *ed;
14 Embryo_Function fn;
15
16 et = data;
17 if (!et) return ECORE_CALLBACK_CANCEL;
18 ed = et->edje;
19// _edje_embryo_script_reset(ed);
20 embryo_program_vm_push(ed->collection->script);
21 _edje_embryo_globals_init(ed);
22 embryo_parameter_cell_push(ed->collection->script, (Embryo_Cell)et->val);
23 ed->var_pool->timers = eina_list_remove(ed->var_pool->timers, et);
24 fn = et->func;
25 free(et);
26 {
27 void *pdata;
28 int ret;
29
30 pdata = embryo_program_data_get(ed->collection->script);
31 embryo_program_data_set(ed->collection->script, ed);
32 embryo_program_max_cycle_run_set(ed->collection->script, 5000000);
33 ret = embryo_program_run(ed->collection->script, fn);
34 if (ret == EMBRYO_PROGRAM_FAIL)
35 {
36 ERR("ERROR with embryo script (timer callback). "
37 "OBJECT NAME: '%s', "
38 "OBJECT FILE: '%s', "
39 "ERROR: '%s'",
40 ed->collection->part,
41 ed->file->path,
42 embryo_error_string_get(embryo_program_error_get(ed->collection->script)));
43 }
44 else if (ret == EMBRYO_PROGRAM_TOOLONG)
45 {
46 ERR("ERROR with embryo script (timer callback). "
47 "OBJECT NAME: '%s', "
48 "OBJECT FILE: '%s', "
49 "ERROR: 'Script exceeded maximum allowed cycle count of %i'",
50 ed->collection->part,
51 ed->file->path,
52 embryo_program_max_cycle_run_get(ed->collection->script));
53 }
54 embryo_program_data_set(ed->collection->script, pdata);
55 embryo_program_vm_pop(ed->collection->script);
56 _edje_recalc(ed);
57 }
58 return ECORE_CALLBACK_CANCEL;
59}
60
61static Eina_Bool
62_edje_var_anim_cb(void *data __UNUSED__)
63{
64 Eina_List *l, *tl = NULL;
65 double t;
66 const void *tmp;
67
68 t = ecore_loop_time_get();
69 EINA_LIST_FOREACH(_edje_anim_list, l, tmp)
70 tl = eina_list_append(tl, tmp);
71 while (tl)
72 {
73 Edje *ed;
74 Eina_List *tl2;
75 Edje_Var_Animator *ea;
76
77 ed = eina_list_data_get(tl);
78 _edje_ref(ed);
79 _edje_block(ed);
80 _edje_freeze(ed);
81 tl = eina_list_remove(tl, ed);
82 if (!ed->var_pool) continue;
83 tl2 = NULL;
84 EINA_LIST_FOREACH(ed->var_pool->animators, l, tmp)
85 tl2 = eina_list_append(tl2, tmp);
86 ed->var_pool->walking_list++;
87 while (tl2)
88 {
89 ea = eina_list_data_get(tl2);
90 if ((ed->var_pool) && (!ea->delete_me))
91 {
92 if ((!ed->paused) && (!ed->delete_me))
93 {
94 Embryo_Function fn;
95 float v;
96 int ret;
97
98 v = (t - ea->start) / ea->len;
99 if (v > 1.0) v= 1.0;
100// _edje_embryo_script_reset(ed);
101 embryo_program_vm_push(ed->collection->script);
102 _edje_embryo_globals_init(ed);
103 embryo_parameter_cell_push(ed->collection->script, (Embryo_Cell)ea->val);
104 embryo_parameter_cell_push(ed->collection->script, EMBRYO_FLOAT_TO_CELL(v));
105 fn = ea->func;
106 {
107 void *pdata;
108
109 pdata = embryo_program_data_get(ed->collection->script);
110 embryo_program_data_set(ed->collection->script, ed);
111 embryo_program_max_cycle_run_set(ed->collection->script, 5000000);
112 ret = embryo_program_run(ed->collection->script, fn);
113 if (ret == EMBRYO_PROGRAM_FAIL)
114 {
115 ERR("ERROR with embryo script (anim callback). "
116 "OBJECT NAME: '%s', "
117 "OBJECT FILE: '%s', "
118 "ERROR: '%s'",
119 ed->collection->part,
120 ed->file->path,
121 embryo_error_string_get(embryo_program_error_get(ed->collection->script)));
122 }
123 else if (ret == EMBRYO_PROGRAM_TOOLONG)
124 {
125 ERR("ERROR with embryo script (anim callback). "
126 "OBJECT NAME: '%s', "
127 "OBJECT FILE: '%s', "
128 "ERROR: 'Script exceeded maximum allowed cycle count of %i'",
129 ed->collection->part,
130 ed->file->path,
131 embryo_program_max_cycle_run_get(ed->collection->script));
132 }
133 embryo_program_data_set(ed->collection->script, pdata);
134 embryo_program_vm_pop(ed->collection->script);
135 _edje_recalc(ed);
136 }
137 if (v == 1.0) ea->delete_me = 1;
138 }
139 }
140 tl2 = eina_list_remove(tl2, ea);
141 if (ed->block_break)
142 {
143 eina_list_free(tl2);
144 break;
145 }
146 }
147 ed->var_pool->walking_list--;
148 EINA_LIST_FOREACH(ed->var_pool->animators, l, ea)
149 {
150 if (ea->delete_me)
151 {
152 l = eina_list_next(l);
153 ed->var_pool->animators = eina_list_remove(ed->var_pool->animators, ea);
154 free(ea);
155 }
156 else
157 l = eina_list_next(l);
158 }
159 if (!ed->var_pool->animators)
160 _edje_anim_list = eina_list_remove(_edje_anim_list, ed);
161 _edje_unblock(ed);
162 _edje_thaw(ed);
163 _edje_unref(ed);
164 }
165 if (!_edje_anim_list)
166 {
167 if (_edje_animator)
168 {
169 ecore_animator_del(_edje_animator);
170 _edje_animator = NULL;
171 }
172 }
173 return !!_edje_animator;
174}
175
176Edje_Var *
177_edje_var_new(void)
178{
179 return calloc(1, sizeof(Edje_Var));
180}
181
182void
183_edje_var_free(Edje_Var *var)
184{
185 if (var->type == EDJE_VAR_STRING)
186 {
187 if (var->data.s.v)
188 {
189 free(var->data.s.v);
190 }
191 }
192 free(var);
193}
194
195void
196_edje_var_init(Edje *ed)
197{
198 if (!ed) return;
199 if (!ed->collection) return;
200 if (!ed->collection->script) return;
201 if (ed->var_pool) return;
202 ed->var_pool = calloc(1, sizeof(Edje_Var_Pool));
203 if (!ed->var_pool) return;
204 embryo_program_vm_push(ed->collection->script);
205 ed->var_pool->size = embryo_program_variable_count_get(ed->collection->script);
206 embryo_program_vm_pop(ed->collection->script);
207 if (ed->var_pool->size > 0)
208 ed->var_pool->vars = calloc(1, sizeof(Edje_Var) * ed->var_pool->size);
209}
210
211void
212_edje_var_shutdown(Edje *ed)
213{
214 if (!ed->var_pool) return;
215 if (ed->var_pool->vars)
216 {
217 int i;
218
219 for (i = 0; i < ed->var_pool->size; i++)
220 {
221 if (ed->var_pool->vars[i].type == EDJE_VAR_STRING)
222 {
223 if (ed->var_pool->vars[i].data.s.v)
224 {
225 free(ed->var_pool->vars[i].data.s.v);
226 ed->var_pool->vars[i].data.s.v = NULL;
227 }
228 }
229 else if (ed->var_pool->vars[i].type == EDJE_VAR_LIST)
230 {
231 while (ed->var_pool->vars[i].data.l.v)
232 {
233 _edje_var_free(eina_list_data_get(ed->var_pool->vars[i].data.l.v));
234 ed->var_pool->vars[i].data.l.v = eina_list_remove_list(ed->var_pool->vars[i].data.l.v, ed->var_pool->vars[i].data.l.v);
235 }
236 }
237 }
238 free(ed->var_pool->vars);
239 }
240 while (ed->var_pool->timers)
241 {
242 Edje_Var_Timer *et;
243
244 et = eina_list_data_get(ed->var_pool->timers);
245 ecore_timer_del(et->timer);
246 free(et);
247 ed->var_pool->timers = eina_list_remove(ed->var_pool->timers, et);
248 }
249 if (ed->var_pool->animators)
250 {
251 _edje_anim_list = eina_list_remove(_edje_anim_list, ed);
252 if (!_edje_anim_list)
253 {
254 if (_edje_animator)
255 {
256 ecore_animator_del(_edje_animator);
257 _edje_animator = NULL;
258 }
259 }
260 }
261 while (ed->var_pool->animators)
262 {
263 Edje_Var_Animator *ea;
264
265 ea = eina_list_data_get(ed->var_pool->animators);
266 free(ea);
267 ed->var_pool->animators = eina_list_remove(ed->var_pool->animators, ea);
268 }
269 free(ed->var_pool);
270 ed->var_pool = NULL;
271}
272
273int
274_edje_var_string_id_get(Edje *ed, const char *string)
275{
276 Embryo_Cell cell, *cptr;
277
278 if (!ed) return 0;
279 if (!ed->collection) return 0;
280 if (!ed->collection->script) return 0;
281 if (!string) return 0;
282 cell = embryo_program_variable_find(ed->collection->script, (char *)string);
283 if (cell == EMBRYO_CELL_NONE) return 0;
284 cptr = embryo_data_address_get(ed->collection->script, cell);
285 if (!cptr) return 0;
286 return (int)(*cptr);
287}
288
289int
290_edje_var_var_int_get(Edje *ed __UNUSED__, Edje_Var *var)
291{
292 /* auto-cast */
293 if (var->type == EDJE_VAR_STRING)
294 {
295 if (var->data.s.v)
296 {
297 double f;
298
299 f = atof(var->data.s.v);
300 free(var->data.s.v);
301 var->data.s.v = NULL;
302 var->data.i.v = (int)f;
303 }
304 var->type = EDJE_VAR_INT;
305 }
306 else if (var->type == EDJE_VAR_FLOAT)
307 {
308 var->data.i.v = (int)(var->data.f.v);
309 var->type = EDJE_VAR_INT;
310 }
311 else if (var->type == EDJE_VAR_NONE)
312 {
313 var->type = EDJE_VAR_INT;
314 }
315 else if (var->type == EDJE_VAR_LIST)
316 {
317 return 0;
318 }
319 else if (var->type == EDJE_VAR_HASH)
320 {
321 return 0;
322 }
323 return var->data.i.v;
324}
325
326void
327_edje_var_var_int_set(Edje *ed __UNUSED__, Edje_Var *var, int v)
328{
329 /* auto-cast */
330 if (var->type == EDJE_VAR_STRING)
331 {
332 if (var->data.s.v)
333 {
334 free(var->data.s.v);
335 var->data.s.v = NULL;
336 }
337 var->type = EDJE_VAR_INT;
338 }
339 else if (var->type == EDJE_VAR_FLOAT)
340 {
341 var->type = EDJE_VAR_INT;
342 }
343 else if (var->type == EDJE_VAR_NONE)
344 {
345 var->type = EDJE_VAR_INT;
346 }
347 else if (var->type == EDJE_VAR_LIST)
348 {
349 return;
350 }
351 else if (var->type == EDJE_VAR_HASH)
352 {
353 return;
354 }
355 var->data.i.v = v;
356}
357
358double
359_edje_var_var_float_get(Edje *ed __UNUSED__, Edje_Var *var)
360{
361 /* auto-cast */
362 if (var->type == EDJE_VAR_STRING)
363 {
364 if (var->data.s.v)
365 {
366 double f;
367
368 f = atof(var->data.s.v);
369 free(var->data.s.v);
370 var->data.s.v = NULL;
371 var->data.f.v = f;
372 }
373 var->type = EDJE_VAR_FLOAT;
374 }
375 else if (var->type == EDJE_VAR_INT)
376 {
377 var->data.f.v = (double)(var->data.i.v);
378 var->type = EDJE_VAR_FLOAT;
379 }
380 else if (var->type == EDJE_VAR_NONE)
381 {
382 var->type = EDJE_VAR_FLOAT;
383 }
384 else if (var->type == EDJE_VAR_LIST)
385 {
386 return 0.0;
387 }
388 else if (var->type == EDJE_VAR_HASH)
389 {
390 return 0.0;
391 }
392 return var->data.f.v;
393}
394
395void
396_edje_var_var_float_set(Edje *ed __UNUSED__, Edje_Var *var, double v)
397{
398 /* auto-cast */
399 if (var->type == EDJE_VAR_STRING)
400 {
401 if (var->data.s.v)
402 {
403 free(var->data.s.v);
404 var->data.s.v = NULL;
405 }
406 var->type = EDJE_VAR_FLOAT;
407 }
408 else if (var->type == EDJE_VAR_INT)
409 {
410 var->data.f.v = 0;
411 var->type = EDJE_VAR_FLOAT;
412 }
413 else if (var->type == EDJE_VAR_NONE)
414 {
415 var->type = EDJE_VAR_FLOAT;
416 }
417 else if (var->type == EDJE_VAR_LIST)
418 {
419 return;
420 }
421 else if (var->type == EDJE_VAR_HASH)
422 {
423 return;
424 }
425 var->data.f.v = v;
426}
427
428const char *
429_edje_var_var_str_get(Edje *ed __UNUSED__, Edje_Var *var)
430{
431 /* auto-cast */
432 if (var->type == EDJE_VAR_INT)
433 {
434 char buf[64];
435
436 snprintf(buf, sizeof(buf), "%i", var->data.i.v);
437 var->data.s.v = strdup(buf);
438 var->type = EDJE_VAR_STRING;
439 }
440 else if (var->type == EDJE_VAR_FLOAT)
441 {
442 char buf[64];
443
444 snprintf(buf, sizeof(buf), "%f", var->data.f.v);
445 var->data.s.v = strdup(buf);
446 var->type = EDJE_VAR_STRING;
447 }
448 else if (var->type == EDJE_VAR_NONE)
449 {
450 var->data.s.v = strdup("");
451 var->type = EDJE_VAR_STRING;
452 }
453 else if (var->type == EDJE_VAR_LIST)
454 {
455 return NULL;
456 }
457 else if (var->type == EDJE_VAR_HASH)
458 {
459 return NULL;
460 }
461 return var->data.s.v;
462}
463
464void
465_edje_var_var_str_set(Edje *ed __UNUSED__, Edje_Var *var, const char *str)
466{
467 /* auto-cast */
468 if (var->type == EDJE_VAR_STRING)
469 {
470 if (var->data.s.v)
471 {
472 free(var->data.s.v);
473 var->data.s.v = NULL;
474 }
475 }
476 else if (var->type == EDJE_VAR_INT)
477 {
478 var->type = EDJE_VAR_STRING;
479 }
480 else if (var->type == EDJE_VAR_FLOAT)
481 {
482 var->type = EDJE_VAR_STRING;
483 }
484 else if (var->type == EDJE_VAR_NONE)
485 {
486 var->type = EDJE_VAR_STRING;
487 }
488 else if (var->type == EDJE_VAR_LIST)
489 {
490 return;
491 }
492 else if (var->type == EDJE_VAR_HASH)
493 {
494 return;
495 }
496 var->data.s.v = strdup(str);
497}
498
499int
500_edje_var_int_get(Edje *ed, int id)
501{
502 if (!ed) return 0;
503 if (!ed->var_pool) return 0;
504 id -= EDJE_VAR_MAGIC_BASE;
505 if ((id < 0) || (id >= ed->var_pool->size)) return 0;
506 return _edje_var_var_int_get(ed, &(ed->var_pool->vars[id]));
507}
508
509void
510_edje_var_int_set(Edje *ed, int id, int v)
511{
512 if (!ed) return;
513 if (!ed->var_pool) return;
514 id -= EDJE_VAR_MAGIC_BASE;
515 if ((id < 0) || (id >= ed->var_pool->size)) return;
516 _edje_var_var_int_set(ed, &(ed->var_pool->vars[id]), v);
517}
518
519double
520_edje_var_float_get(Edje *ed, int id)
521{
522 if (!ed) return 0;
523 if (!ed->var_pool) return 0;
524 id -= EDJE_VAR_MAGIC_BASE;
525 if ((id < 0) || (id >= ed->var_pool->size)) return 0;
526 return _edje_var_var_float_get(ed, &(ed->var_pool->vars[id]));
527}
528
529void
530_edje_var_float_set(Edje *ed, int id, double v)
531{
532 if (!ed) return;
533 if (!ed->var_pool) return;
534 id -= EDJE_VAR_MAGIC_BASE;
535 if ((id < 0) || (id >= ed->var_pool->size)) return;
536 _edje_var_var_float_set(ed, &(ed->var_pool->vars[id]), v);
537}
538
539const char *
540_edje_var_str_get(Edje *ed, int id)
541{
542 if (!ed) return NULL;
543 if (!ed->var_pool) return NULL;
544 id -= EDJE_VAR_MAGIC_BASE;
545 if ((id < 0) || (id >= ed->var_pool->size)) return NULL;
546 return _edje_var_var_str_get(ed, &(ed->var_pool->vars[id]));
547}
548
549void
550_edje_var_str_set(Edje *ed, int id, const char *str)
551{
552 if (!ed) return;
553 if (!ed->var_pool) return;
554 if (!str) return;
555 id -= EDJE_VAR_MAGIC_BASE;
556 if ((id < 0) || (id >= ed->var_pool->size)) return;
557 _edje_var_var_str_set(ed, &(ed->var_pool->vars[id]), str);
558}
559
560/* list stuff */
561
562void
563_edje_var_list_var_append(Edje *ed, int id, Edje_Var *var)
564{
565 if (!ed) return;
566 if (!ed->var_pool) return;
567 id -= EDJE_VAR_MAGIC_BASE;
568 if ((id < 0) || (id >= ed->var_pool->size)) return;
569 if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
570 ed->var_pool->vars[id].data.l.v = eina_list_append(ed->var_pool->vars[id].data.l.v, var);
571}
572
573void
574_edje_var_list_var_prepend(Edje *ed, int id, Edje_Var *var)
575{
576 if (!ed) return;
577 if (!ed->var_pool) return;
578 id -= EDJE_VAR_MAGIC_BASE;
579 if ((id < 0) || (id >= ed->var_pool->size)) return;
580 if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
581 ed->var_pool->vars[id].data.l.v = eina_list_prepend(ed->var_pool->vars[id].data.l.v, var);
582}
583
584void
585_edje_var_list_var_append_relative(Edje *ed, int id, Edje_Var *var, Edje_Var *relative)
586{
587 if (!ed) return;
588 if (!ed->var_pool) return;
589 id -= EDJE_VAR_MAGIC_BASE;
590 if ((id < 0) || (id >= ed->var_pool->size)) return;
591 if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
592 ed->var_pool->vars[id].data.l.v = eina_list_append_relative(ed->var_pool->vars[id].data.l.v, var, relative);
593}
594
595void
596_edje_var_list_var_prepend_relative(Edje *ed, int id, Edje_Var *var, Edje_Var *relative)
597{
598 if (!ed) return;
599 if (!ed->var_pool) return;
600 id -= EDJE_VAR_MAGIC_BASE;
601 if ((id < 0) || (id >= ed->var_pool->size)) return;
602 if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
603 ed->var_pool->vars[id].data.l.v = eina_list_prepend_relative(ed->var_pool->vars[id].data.l.v, var, relative);
604}
605
606Edje_Var *
607_edje_var_list_nth(Edje *ed, int id, int n)
608{
609 if (!ed) return NULL;
610 if (!ed->var_pool) return NULL;
611 id -= EDJE_VAR_MAGIC_BASE;
612 if ((id < 0) || (id >= ed->var_pool->size)) return NULL;
613 if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return NULL;
614 return eina_list_nth(ed->var_pool->vars[id].data.l.v, n);
615}
616
617int
618_edje_var_list_count_get(Edje *ed, int id)
619{
620 if (!ed) return 0;
621 if (!ed->var_pool) return 0;
622 id -= EDJE_VAR_MAGIC_BASE;
623 if ((id < 0) || (id >= ed->var_pool->size)) return 0;
624 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
625 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
626 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return 0;
627 return eina_list_count(ed->var_pool->vars[id].data.l.v);
628}
629
630void
631_edje_var_list_remove_nth(Edje *ed, int id, int n)
632{
633 if (!ed) return;
634 if (!ed->var_pool) return;
635 id -= EDJE_VAR_MAGIC_BASE;
636 if ((id < 0) || (id >= ed->var_pool->size)) return;
637 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
638 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
639 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
640 {
641 Eina_List *nth;
642
643 nth = eina_list_nth_list(ed->var_pool->vars[id].data.l.v, n);
644 if (nth)
645 {
646 _edje_var_free(eina_list_data_get(nth));
647 ed->var_pool->vars[id].data.l.v = eina_list_remove_list(ed->var_pool->vars[id].data.l.v, nth);
648 }
649 }
650}
651
652int
653_edje_var_list_nth_int_get(Edje *ed, int id, int n)
654{
655 if (!ed) return 0;
656 if (!ed->var_pool) return 0;
657 id -= EDJE_VAR_MAGIC_BASE;
658 if ((id < 0) || (id >= ed->var_pool->size)) return 0;
659 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
660 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
661 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return 0;
662 {
663 Edje_Var *var;
664
665 id += EDJE_VAR_MAGIC_BASE;
666 var = _edje_var_list_nth(ed, id, n);
667 if (!var) return 0;
668 return _edje_var_var_int_get(ed, var);
669 }
670}
671
672void
673_edje_var_list_nth_int_set(Edje *ed, int id, int n, int v)
674{
675 if (!ed) return;
676 if (!ed->var_pool) return;
677 id -= EDJE_VAR_MAGIC_BASE;
678 if ((id < 0) || (id >= ed->var_pool->size)) return;
679 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
680 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
681 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
682 {
683 Edje_Var *var;
684
685 id += EDJE_VAR_MAGIC_BASE;
686 var = _edje_var_list_nth(ed, id, n);
687 if (!var) return;
688 _edje_var_var_int_set(ed, var, v);
689 }
690}
691
692void
693_edje_var_list_int_append(Edje *ed, int id, int v)
694{
695 if (!ed) return;
696 if (!ed->var_pool) return;
697 id -= EDJE_VAR_MAGIC_BASE;
698 if ((id < 0) || (id >= ed->var_pool->size)) return;
699 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
700 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
701 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
702 {
703 Edje_Var *var;
704
705 var = _edje_var_new();
706 if (!var) return;
707 id += EDJE_VAR_MAGIC_BASE;
708 _edje_var_var_int_set(ed, var, v);
709 _edje_var_list_var_append(ed, id, var);
710 }
711}
712
713void
714_edje_var_list_int_prepend(Edje *ed, int id, int v)
715{
716 if (!ed) return;
717 if (!ed->var_pool) return;
718 id -= EDJE_VAR_MAGIC_BASE;
719 if ((id < 0) || (id >= ed->var_pool->size)) return;
720 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
721 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
722 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
723 {
724 Edje_Var *var;
725
726 var = _edje_var_new();
727 if (!var) return;
728 id += EDJE_VAR_MAGIC_BASE;
729 _edje_var_var_int_set(ed, var, v);
730 _edje_var_list_var_prepend(ed, id, var);
731 }
732}
733
734void
735_edje_var_list_int_insert(Edje *ed, int id, int n, int v)
736{
737 if (!ed) return;
738 if (!ed->var_pool) return;
739 id -= EDJE_VAR_MAGIC_BASE;
740 if ((id < 0) || (id >= ed->var_pool->size)) return;
741 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
742 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
743 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
744 {
745 Edje_Var *var, *var_rel;
746
747 var = _edje_var_new();
748 if (!var) return;
749 id += EDJE_VAR_MAGIC_BASE;
750 _edje_var_var_int_set(ed, var, v);
751 var_rel = _edje_var_list_nth(ed, id, n);
752 if (!var_rel)
753 _edje_var_list_var_append(ed, id, var);
754 else
755 _edje_var_list_var_prepend_relative(ed, id, var, var_rel);
756 }
757}
758
759double
760_edje_var_list_nth_float_get(Edje *ed, int id, int n)
761{
762 if (!ed) return 0;
763 if (!ed->var_pool) return 0;
764 id -= EDJE_VAR_MAGIC_BASE;
765 if ((id < 0) || (id >= ed->var_pool->size)) return 0;
766 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
767 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
768 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return 0;
769 {
770 Edje_Var *var;
771
772 id += EDJE_VAR_MAGIC_BASE;
773 var = _edje_var_list_nth(ed, id, n);
774 if (!var) return 0;
775 return _edje_var_var_float_get(ed, var);
776 }
777}
778
779void
780_edje_var_list_nth_float_set(Edje *ed, int id, int n, double v)
781{
782 if (!ed) return;
783 if (!ed->var_pool) return;
784 id -= EDJE_VAR_MAGIC_BASE;
785 if ((id < 0) || (id >= ed->var_pool->size)) return;
786 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
787 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
788 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
789 {
790 Edje_Var *var;
791
792 id += EDJE_VAR_MAGIC_BASE;
793 var = _edje_var_list_nth(ed, id, n);
794 if (!var) return;
795 _edje_var_var_float_set(ed, var, v);
796 }
797}
798
799void
800_edje_var_list_float_append(Edje *ed, int id, double v)
801{
802 if (!ed) return;
803 if (!ed->var_pool) return;
804 id -= EDJE_VAR_MAGIC_BASE;
805 if ((id < 0) || (id >= ed->var_pool->size)) return;
806 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
807 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
808 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
809 {
810 Edje_Var *var;
811
812 var = _edje_var_new();
813 if (!var) return;
814 id += EDJE_VAR_MAGIC_BASE;
815 _edje_var_var_float_set(ed, var, v);
816 _edje_var_list_var_append(ed, id, var);
817 }
818}
819
820void
821_edje_var_list_float_prepend(Edje *ed, int id, double v)
822{
823 if (!ed) return;
824 if (!ed->var_pool) return;
825 id -= EDJE_VAR_MAGIC_BASE;
826 if ((id < 0) || (id >= ed->var_pool->size)) return;
827 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
828 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
829 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
830 {
831 Edje_Var *var;
832
833 var = _edje_var_new();
834 if (!var) return;
835 id += EDJE_VAR_MAGIC_BASE;
836 _edje_var_var_float_set(ed, var, v);
837 _edje_var_list_var_prepend(ed, id, var);
838 }
839}
840
841void
842_edje_var_list_float_insert(Edje *ed, int id, int n, double v)
843{
844 if (!ed) return;
845 if (!ed->var_pool) return;
846 id -= EDJE_VAR_MAGIC_BASE;
847 if ((id < 0) || (id >= ed->var_pool->size)) return;
848 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
849 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
850 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
851 {
852 Edje_Var *var, *var_rel;
853
854 var = _edje_var_new();
855 if (!var) return;
856 id += EDJE_VAR_MAGIC_BASE;
857 _edje_var_var_float_set(ed, var, v);
858 var_rel = _edje_var_list_nth(ed, id, n);
859 if (!var_rel)
860 _edje_var_list_var_append(ed, id, var);
861 else
862 _edje_var_list_var_prepend_relative(ed, id, var, var_rel);
863 }
864}
865
866const char *
867_edje_var_list_nth_str_get(Edje *ed, int id, int n)
868{
869 if (!ed) return NULL;
870 if (!ed->var_pool) return NULL;
871 id -= EDJE_VAR_MAGIC_BASE;
872 if ((id < 0) || (id >= ed->var_pool->size)) return NULL;
873 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
874 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
875 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return NULL;
876 {
877 Edje_Var *var;
878
879 id += EDJE_VAR_MAGIC_BASE;
880 var = _edje_var_list_nth(ed, id, n);
881 if (!var) return NULL;
882 return _edje_var_var_str_get(ed, var);
883 }
884}
885
886void
887_edje_var_list_nth_str_set(Edje *ed, int id, int n, const char *v)
888{
889 if (!ed) return;
890 if (!ed->var_pool) return;
891 id -= EDJE_VAR_MAGIC_BASE;
892 if ((id < 0) || (id >= ed->var_pool->size)) return;
893 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
894 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
895 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
896 {
897 Edje_Var *var;
898
899 id += EDJE_VAR_MAGIC_BASE;
900 var = _edje_var_list_nth(ed, id, n);
901 if (!var) return;
902 _edje_var_var_str_set(ed, var, v);
903 }
904}
905
906void
907_edje_var_list_str_append(Edje *ed, int id, const char *v)
908{
909 if (!ed) return;
910 if (!ed->var_pool) return;
911 id -= EDJE_VAR_MAGIC_BASE;
912 if ((id < 0) || (id >= ed->var_pool->size)) return;
913 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
914 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
915 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
916 {
917 Edje_Var *var;
918
919 var = _edje_var_new();
920 if (!var) return;
921 id += EDJE_VAR_MAGIC_BASE;
922 _edje_var_var_str_set(ed, var, v);
923 _edje_var_list_var_append(ed, id, var);
924 }
925}
926
927void
928_edje_var_list_str_prepend(Edje *ed, int id, const char *v)
929{
930 if (!ed) return;
931 if (!ed->var_pool) return;
932 id -= EDJE_VAR_MAGIC_BASE;
933 if ((id < 0) || (id >= ed->var_pool->size)) return;
934 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
935 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
936 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
937 {
938 Edje_Var *var;
939
940 var = _edje_var_new();
941 if (!var) return;
942 id += EDJE_VAR_MAGIC_BASE;
943 _edje_var_var_str_set(ed, var, v);
944 _edje_var_list_var_prepend(ed, id, var);
945 }
946}
947
948void
949_edje_var_list_str_insert(Edje *ed, int id, int n, const char *v)
950{
951 if (!ed) return;
952 if (!ed->var_pool) return;
953 id -= EDJE_VAR_MAGIC_BASE;
954 if ((id < 0) || (id >= ed->var_pool->size)) return;
955 if (ed->var_pool->vars[id].type == EDJE_VAR_NONE)
956 ed->var_pool->vars[id].type = EDJE_VAR_LIST;
957 else if (ed->var_pool->vars[id].type != EDJE_VAR_LIST) return;
958 {
959 Edje_Var *var, *var_rel;
960
961 var = _edje_var_new();
962 if (!var) return;
963 id += EDJE_VAR_MAGIC_BASE;
964 _edje_var_var_str_set(ed, var, v);
965 var_rel = _edje_var_list_nth(ed, id, n);
966 if (!var_rel)
967 _edje_var_list_var_append(ed, id, var);
968 else
969 _edje_var_list_var_prepend_relative(ed, id, var, var_rel);
970 }
971}
972
973int
974_edje_var_timer_add(Edje *ed, double in, const char *fname, int val)
975{
976 Edje_Var_Timer *et;
977 Embryo_Function fn;
978
979 if (!ed->var_pool) return 0;
980 fn = embryo_program_function_find(ed->collection->script, (char *)fname);
981 if (fn == EMBRYO_FUNCTION_NONE) return 0;
982 et = calloc(1, sizeof(Edje_Var_Timer));
983 if (!et) return 0;
984 et->id = ++ed->var_pool->id_count;
985 et->edje = ed;
986 et->func = fn;
987 et->val = val;
988 et->timer = ecore_timer_add(in, _edje_var_timer_cb, et);
989 if (!et->timer)
990 {
991 free(et);
992 return 0;
993 }
994 ed->var_pool->timers = eina_list_prepend(ed->var_pool->timers, et);
995 return et->id;
996}
997
998static Edje_Var_Timer *
999_edje_var_timer_find(Edje *ed, int id)
1000{
1001 Eina_List *l;
1002 Edje_Var_Timer *et;
1003
1004 if (!ed->var_pool) return NULL;
1005
1006 EINA_LIST_FOREACH(ed->var_pool->timers, l, et)
1007 if (et->id == id) return et;
1008
1009 return NULL;
1010}
1011
1012void
1013_edje_var_timer_del(Edje *ed, int id)
1014{
1015 Edje_Var_Timer *et;
1016
1017 et = _edje_var_timer_find(ed, id);
1018 if (!et) return;
1019
1020 ed->var_pool->timers = eina_list_remove(ed->var_pool->timers, et);
1021 ecore_timer_del(et->timer);
1022 free(et);
1023}
1024
1025int
1026_edje_var_anim_add(Edje *ed, double len, const char *fname, int val)
1027{
1028 Edje_Var_Animator *ea;
1029 Embryo_Function fn;
1030
1031 if (!ed->var_pool) return 0;
1032 if (len <= 0.0) return 0;
1033 fn = embryo_program_function_find(ed->collection->script, (char *)fname);
1034 if (fn == EMBRYO_FUNCTION_NONE) return 0;
1035 ea = calloc(1, sizeof(Edje_Var_Animator));
1036 if (!ea) return 0;
1037 ea->start = ecore_loop_time_get();
1038 ea->len = len;
1039 ea->id = ++ed->var_pool->id_count;
1040 ea->edje = ed;
1041 ea->func = fn;
1042 ea->val = val;
1043 if (!ed->var_pool->animators)
1044 _edje_anim_list = eina_list_append(_edje_anim_list, ed);
1045 ed->var_pool->animators = eina_list_prepend(ed->var_pool->animators, ea);
1046 if (!_edje_animator)
1047 _edje_animator = ecore_animator_add(_edje_var_anim_cb, NULL);
1048 return ea->id;
1049}
1050
1051static Edje_Var_Animator *
1052_edje_var_anim_find(Edje *ed, int id)
1053{
1054 Eina_List *l;
1055 Edje_Var_Animator *ea;
1056
1057 if (!ed->var_pool) return NULL;
1058
1059 EINA_LIST_FOREACH(ed->var_pool->animators, l, ea)
1060 if (ea->id == id) return ea;
1061
1062 return NULL;
1063}
1064
1065void
1066_edje_var_anim_del(Edje *ed, int id)
1067{
1068 Edje_Var_Animator *ea;
1069
1070 ea = _edje_var_anim_find(ed, id);
1071 if (!ea) return;
1072
1073 if (ed->var_pool->walking_list)
1074 {
1075 ea->delete_me = 1;
1076 return;
1077 }
1078
1079 ed->var_pool->animators = eina_list_remove(ed->var_pool->animators, ea);
1080 free(ea);
1081
1082 if (ed->var_pool->animators) return;
1083
1084 _edje_anim_list = eina_list_remove(_edje_anim_list, ed);
1085 if (!_edje_anim_list)
1086 {
1087 if (_edje_animator)
1088 {
1089 ecore_animator_del(_edje_animator);
1090 _edje_animator = NULL;
1091 }
1092 }
1093}